diff --git a/packages/runtime/src/pluginApi.ts b/packages/runtime/src/pluginApi.ts index 4c7ae7b..4183d58 100644 --- a/packages/runtime/src/pluginApi.ts +++ b/packages/runtime/src/pluginApi.ts @@ -8,9 +8,10 @@ import { createThemeApi, type ThemeApi, type ThemeSource } from './themeApi.ts'; import { createUiKit, type UiKit } from './ui.ts'; +import { adoptStyles, type RootStyles } from './styles.ts'; import { createCommandRegistry, type CommandDefinition, type CommandInfo, type CommandRegistry } from './commands.ts'; -export type { ThemeApi, ThemeSource, UiKit, CommandDefinition, CommandInfo, CommandRegistry }; +export type { ThemeApi, ThemeSource, UiKit, CommandDefinition, CommandInfo, CommandRegistry, RootStyles }; export type Dispose = () => void; @@ -25,6 +26,8 @@ export type PluginStorage = { /** Collects disposers so a plugin's `stop()` is a single `scope.dispose()`. */ export type PluginScope = { css(id: string, css: string): void; + /** `api.adoptCSS`, taken off the root on dispose. */ + adoptCSS(root: ShadowRoot | Document, css: string): RootStyles; on(target: EventTarget, type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; observe(selector: string, callback: (element: Element) => void): void; onRouteChange(callback: (href: string, previous: string) => void): void; @@ -45,6 +48,12 @@ export type PluginScope = { export type CorePluginApi = { injectCSS(id: string, css: string): void; clearCSS(id: string): void; + /** + * Styles a shadow root the plugin created (or the document) with a constructable stylesheet: + * the page's Content-Security-Policy cannot refuse it, it is parsed once, and it stays with the + * root wherever its host is moved. Falls back to a `