diff --git a/packages/runtime/src/themeRuntime.ts b/packages/runtime/src/themeRuntime.ts index ce7c927..fa7cb3e 100644 --- a/packages/runtime/src/themeRuntime.ts +++ b/packages/runtime/src/themeRuntime.ts @@ -55,10 +55,12 @@ function effectiveRule(rule: RuleNode, supported: (condition: string) => boolean } /** - * Every style rule of `doc`'s stylesheets (inside media/supports groups too), except `own`'s, each as - * it takes effect (`effectiveRule`). A `@supports` group the browser does not pass is left out. + * Every style rule of `doc`'s stylesheets (inside media/supports groups too), except `own`'s (the + * engine's own sheets: read as the site's, their radii and colors would be re-declared), each as it + * takes effect (`effectiveRule`). A `@supports` group the browser does not pass is left out. */ -export function collectRules(doc: Document, own: HTMLStyleElement | null): RuleLike[] { +export function collectRules(doc: Document, own: HTMLStyleElement | null | ReadonlyArray): RuleLike[] { + const ours = (Array.isArray(own) ? own : [own]).filter(Boolean) as HTMLStyleElement[]; const rules: RuleLike[] = []; const css = (doc.defaultView as (Window & typeof globalThis) | null)?.CSS; const verdicts = new Map(); @@ -75,7 +77,7 @@ export function collectRules(doc: Document, own: HTMLStyleElement | null): RuleL } }; for (const sheet of Array.from(doc.styleSheets)) { - if (own && sheet.ownerNode === own) continue; + if (ours.includes(sheet.ownerNode as HTMLStyleElement)) continue; try { walk(sheet.cssRules as unknown as ArrayLike); } catch { /* Cross-origin sheet. */ } } return rules; @@ -140,6 +142,15 @@ export type ThemeRuntimeSite = { resolved(choice: ThemeChoice, mode: Mode): ResolvedTheme; /** Custom properties of the site's root read with the theme's sheet disabled (their unthemed values). */ siteVars?: readonly string[]; + /** + * The theme's CSS that does not depend on the site's stylesheet: components, variants, decoration, + * icons. It lives in its own sheet (`staticId`), so the site inserting rules never rebuilds it; it is + * rebuilt when the theme or the site's mode changes and on `refresh()` (the owner's switches, the + * icon choice, the language). + */ + staticCss?(choice: ThemeChoice, mode: Mode): string; + /** Id of that sheet's `