diff --git a/README.md b/README.md index 7dcf9ea..3d3ed3b 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,9 @@ crates/waybetter-host/ Rust: security policy, profiles, plugin store, hotfi packages/runtime/src/ page runtime core (TypeScript, no dependencies) site.ts SiteAdapter (the page half of the adapter) + configureRuntime domHub.ts netHub.ts one MutationObserver/frame, one fetch/XHR hook per page - pluginApi.ts core of window..api for plugins + pluginApi.ts core of window..api for plugins (incl. ui and theme) + ui.ts plugin UI kit: toasts, alert/confirm/prompt, dialogs (shadow DOM, themed) + themeApi.ts the active theme as values + --wb-* CSS variables (api.theme) themeTokens.ts OKLab color model: maps the site's palette onto a theme's axis paneNav.ts split view: park the site's navigation rail in redundant panes linkRouting.ts divert in-page clicks to a pane/tab/browser per setting diff --git a/packages/runtime/src/pluginApi.ts b/packages/runtime/src/pluginApi.ts index 388f1ad..b722f36 100644 --- a/packages/runtime/src/pluginApi.ts +++ b/packages/runtime/src/pluginApi.ts @@ -2,6 +2,14 @@ // 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'; + +export type { ThemeApi, ThemeSource, UiKit }; export type Dispose = () => void; @@ -24,6 +32,10 @@ export type PluginScope = { 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; dispose(): void; }; @@ -43,10 +55,20 @@ export type CorePluginApi = { */ onKey(callback: (event: KeyboardEvent, item: Element | null) => void): Dispose; copyText(text: string): Promise; + /** A short status message (the UI kit's toast; `ms` is how long it stays). */ toast(message: string, ms?: number): void; + /** Toasts, alerts, confirmations, prompts and dialogs in the active theme (see ui.ts). */ + ui: UiKit; + /** The active theme as values: `current()` and `onChange(fn)` (see themeApi.ts). */ + theme: ThemeApi; scope(): PluginScope; }; +/** What the site adapter adds to the core: its theme engine, when it has one. */ +export type CorePluginExtras = { + theme?: ThemeSource; +}; + export type PluginApiSite = { /** The runtime global, for error messages (`.waitFor timed out`). */ name: string; @@ -56,7 +78,9 @@ export type PluginApiSite = { storagePrefix: string; /** `data-*` key (camelCase) marking plugin `