// `window..api`: small helpers shared by `*.plugin.js` files so each plugin does not // re-implement DOM watching, route tracking, local storage and cleanup. Everything here is local to // the page: no network requests, no account actions. A site adapter adds its own readers (e.g. a // post/message parser) on top of this core. // // `ui` (toasts, alerts, confirmations, prompts, dialogs; ui.ts) and `theme` (the active theme as // values; themeApi.ts) are part of the core: the site adapter only supplies its theme source. import { createThemeApi, type ThemeApi, type ThemeSource } from './themeApi.ts'; import { createUiKit, type UiKit } from './ui.ts'; import { adoptStyles, type RootStyles } from './styles.ts'; import { observeSelector } from './domHub.ts'; import { createCommandRegistry, type CommandDefinition, type CommandInfo, type CommandRegistry } from './commands.ts'; import { createPluginI18n, type I18nSource, type PluginI18n, type PluginMessages } from './pluginI18n.ts'; export type { ThemeApi, ThemeSource, UiKit, CommandDefinition, CommandInfo, CommandRegistry, RootStyles, I18nSource, PluginI18n, PluginMessages }; export type Dispose = () => void; export type PluginStorage = { get(key: string, fallback: T): T; /** Returns false when the value could not be stored (quota, storage disabled). */ set(key: string, value: unknown): boolean; remove(key: string): void; keys(): string[]; }; /** 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; onKey(callback: (event: KeyboardEvent, item: Element | null) => void): void; /** Tracks a node the plugin inserted; it is removed on dispose. */ add(node: T): T; /** Runs `fn` on dispose (restore attributes, clear timers, ...). */ defer(fn: Dispose): void; /** Calls `callback(theme)` after the theme changes, until dispose. */ onThemeChange(callback: Parameters[0]): void; /** The UI kit, scoped: dialogs and toasts it opened are closed on dispose. */ readonly ui: UiKit; /** Command palette entries of the plugin that created this scope, removed on dispose. */ readonly commands: { register(definition: CommandDefinition): Dispose }; dispose(): void; }; 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 `