diff --git a/packages/runtime/src/themeRuntime.ts b/packages/runtime/src/themeRuntime.ts index c8e3932..c938b5a 100644 --- a/packages/runtime/src/themeRuntime.ts +++ b/packages/runtime/src/themeRuntime.ts @@ -5,6 +5,7 @@ // the site adapter (`ThemeRuntimeSite`): X re-declares its own stylesheet rules with the theme's // colors (`buildThemeCss`) and adds type/shape/layout rules over its selectors. +import { domRoots } from './domHub.ts'; import { FONT_ROLE_NAMES, themeKey, themeVarsCss, type ResolvedFonts, type ResolvedTheme } from './themeApi.ts'; import type { ThemeCatalog, ThemeChoice } from './themeChoice.ts'; import { bundledFontsUsed, isNeutral, resolveFontRoles, type FontSpec, type ThemeSpec } from './themeSpec.ts'; @@ -61,8 +62,22 @@ function effectiveRule(rule: RuleNode, supported: (condition: string) => boolean */ export function collectRules(doc: Document, own: HTMLStyleElement | null | ReadonlyArray): RuleLike[] { const ours = (Array.isArray(own) ? own : [own]).filter(Boolean) as HTMLStyleElement[]; + const sheets = Array.from(doc.styleSheets).filter(sheet => !ours.includes(sheet.ownerNode as HTMLStyleElement)); + return rulesOf(sheets, (doc.defaultView as (Window & typeof globalThis) | null)?.CSS); +} + +type SheetLike = { cssRules: CSSRuleList | ArrayLike }; +/** + * The same for an open shadow root the site renders a part of itself in (X's chat embed): its adopted + * sheets and its `