@tenphi/tasty 2.0.4 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/{collector-DXqvGOb1.js → collector-DrgDE7QB.js} +3 -3
  2. package/dist/{collector-DXqvGOb1.js.map → collector-DrgDE7QB.js.map} +1 -1
  3. package/dist/{collector-CkZ517g4.d.ts → collector-LuU1vZ68.d.ts} +2 -2
  4. package/dist/{config-5jzS6k6B.js → config-_aQ_PZ-P.js} +158 -32
  5. package/dist/{config-5jzS6k6B.js.map → config-_aQ_PZ-P.js.map} +1 -1
  6. package/dist/{config-DknGsfMo.d.ts → config-vuCRkBWX.d.ts} +31 -4
  7. package/dist/core/index.d.ts +5 -5
  8. package/dist/core/index.js +6 -6
  9. package/dist/{core-CtU6-9OC.js → core-BqO8pplb.js} +108 -23
  10. package/dist/core-BqO8pplb.js.map +1 -0
  11. package/dist/{css-writer-DHkX0JuE.js → css-writer-D--REwtp.js} +3 -3
  12. package/dist/{css-writer-DHkX0JuE.js.map → css-writer-D--REwtp.js.map} +1 -1
  13. package/dist/{format-rules-DH13ewDu.js → format-rules-xwteB7a1.js} +2 -2
  14. package/dist/{format-rules-DH13ewDu.js.map → format-rules-xwteB7a1.js.map} +1 -1
  15. package/dist/{hydrate-C1Gv-DoS.js → hydrate-BvPT4ndL.js} +2 -2
  16. package/dist/{hydrate-C1Gv-DoS.js.map → hydrate-BvPT4ndL.js.map} +1 -1
  17. package/dist/{index-o7zV2yCr.d.ts → index-ZRxZWzlj.d.ts} +47 -6
  18. package/dist/{index-PzENbpAq.d.ts → index-dUtwpOux.d.ts} +9 -3
  19. package/dist/index.d.ts +5 -5
  20. package/dist/index.js +13 -10
  21. package/dist/index.js.map +1 -1
  22. package/dist/{keyframes-b7X3UxDV.js → keyframes-ClPFWy33.js} +2 -2
  23. package/dist/{keyframes-b7X3UxDV.js.map → keyframes-ClPFWy33.js.map} +1 -1
  24. package/dist/{merge-styles-Tgo3BbL2.js → merge-styles-BUQsEpbv.js} +2 -2
  25. package/dist/{merge-styles-Tgo3BbL2.js.map → merge-styles-BUQsEpbv.js.map} +1 -1
  26. package/dist/{merge-styles-C7KTy7MY.d.ts → merge-styles-CtDJMhpJ.d.ts} +2 -2
  27. package/dist/{resolve-recipes-Ca2-5CxM.js → resolve-recipes-C0-AMzCz.js} +3 -3
  28. package/dist/{resolve-recipes-Ca2-5CxM.js.map → resolve-recipes-C0-AMzCz.js.map} +1 -1
  29. package/dist/ssr/astro-client.js +1 -1
  30. package/dist/ssr/astro.js +3 -3
  31. package/dist/ssr/index.d.ts +1 -1
  32. package/dist/ssr/index.js +3 -3
  33. package/dist/ssr/next.d.ts +1 -1
  34. package/dist/ssr/next.js +4 -4
  35. package/dist/static/index.d.ts +2 -2
  36. package/dist/static/index.js +1 -1
  37. package/dist/zero/babel.d.ts +1 -1
  38. package/dist/zero/babel.js +4 -4
  39. package/dist/zero/index.d.ts +1 -1
  40. package/dist/zero/index.js +1 -1
  41. package/docs/injector.md +2 -2
  42. package/package.json +8 -7
  43. package/dist/core-CtU6-9OC.js.map +0 -1
@@ -1,5 +1,5 @@
1
- import { F as formatFontFaceRule, P as fontFaceContentHash, a as getGlobalCounterStyle, ct as hashString, i as getGlobalConfigTokens, j as formatCounterStyleRule, o as getGlobalFontFace, r as getEffectiveProperties, u as getGlobalStyles, x as renderStyles } from "./config-5jzS6k6B.js";
2
- import { n as formatPropertyCSS, t as formatRules } from "./format-rules-DH13ewDu.js";
1
+ import { F as formatFontFaceRule, P as fontFaceContentHash, a as getGlobalCounterStyle, ct as hashString, i as getGlobalConfigTokens, j as formatCounterStyleRule, o as getGlobalFontFace, r as getEffectiveProperties, u as getGlobalStyles, x as renderStyles } from "./config-_aQ_PZ-P.js";
2
+ import { n as formatPropertyCSS, t as formatRules } from "./format-rules-xwteB7a1.js";
3
3
  import { t as formatGlobalRules } from "./format-global-rules-Dbc_1tc3.js";
4
4
  //#region src/ssr/collector.ts
5
5
  /**
@@ -227,4 +227,4 @@ var ServerStyleCollector = class {
227
227
  //#endregion
228
228
  export { ServerStyleCollector as t };
229
229
 
230
- //# sourceMappingURL=collector-DXqvGOb1.js.map
230
+ //# sourceMappingURL=collector-DrgDE7QB.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"collector-DXqvGOb1.js","names":[],"sources":["../src/ssr/collector.ts"],"sourcesContent":["/**\n * ServerStyleCollector — server-safe style collector for SSR.\n *\n * Accumulates CSS rules and cache metadata during server rendering.\n * This is the server-side counterpart to StyleInjector: it allocates\n * hash-based class names (`t${hash}`), formats CSS rules into text,\n * and tracks rendered class names for lightweight client transfer.\n *\n * One instance is created per HTTP request. Concurrent requests\n * each get their own collector (via AsyncLocalStorage or React context).\n */\n\nimport {\n getEffectiveProperties,\n getGlobalStyles,\n getGlobalCounterStyle,\n getGlobalFontFace,\n getGlobalConfigTokens,\n} from '../config';\nimport { formatCounterStyleRule } from '../counter-style';\nimport { fontFaceContentHash, formatFontFaceRule } from '../font-face';\nimport { renderStyles } from '../pipeline';\nimport type { StyleResult } from '../pipeline';\nimport { hashString } from '../utils/hash';\nimport { formatPropertyCSS } from './format-property';\nimport { formatGlobalRules } from './format-global-rules';\nimport { formatRules } from './format-rules';\n\nfunction generateClassName(cacheKey: string): string {\n return `t${hashString(cacheKey)}`;\n}\n\nexport class ServerStyleCollector {\n private chunks = new Map<string, string>();\n private cacheKeyToClassName = new Map<string, string>();\n private flushedKeys = new Set<string>();\n private propertyRules = new Map<string, string>();\n private flushedPropertyKeys = new Set<string>();\n private keyframeRules = new Map<string, string>();\n private flushedKeyframeKeys = new Set<string>();\n private globalStyles = new Map<string, string>();\n private flushedGlobalKeys = new Set<string>();\n private rawCSS = new Map<string, string>();\n private flushedRawKeys = new Set<string>();\n private fontFaceRules = new Map<string, string>();\n private flushedFontFaceKeys = new Set<string>();\n private counterStyleRules = new Map<string, string>();\n private flushedCounterStyleKeys = new Set<string>();\n private keyframesCounter = 0;\n private counterStyleCounter = 0;\n private internalsCollected = false;\n\n /**\n * Collect internal @property rules and :root token defaults.\n * Mirrors markStylesGenerated() from the client-side injector.\n * Called automatically on first chunk collection; idempotent.\n *\n * Internals are always emitted here — the RSC path deliberately\n * defers to SSR so that tokens appear exactly once per page in\n * <style data-tasty-ssr> (avoiding duplication of large token sets).\n */\n collectInternals(): void {\n if (this.internalsCollected) return;\n this.internalsCollected = true;\n\n for (const [token, definition] of Object.entries(\n getEffectiveProperties(),\n )) {\n const css = formatPropertyCSS(token, definition);\n if (css) {\n this.collectProperty(`__prop:${token}`, css);\n }\n }\n\n const tokenStyles = getGlobalConfigTokens();\n if (tokenStyles && Object.keys(tokenStyles).length > 0) {\n const tokenRules = renderStyles(tokenStyles, ':root') as StyleResult[];\n if (tokenRules.length > 0) {\n const css = formatGlobalRules(tokenRules);\n if (css) {\n this.collectGlobalStyles('__global:tokens', css);\n }\n }\n }\n\n const globalFF = getGlobalFontFace();\n if (globalFF) {\n for (const [family, input] of Object.entries(globalFF)) {\n const descriptors = Array.isArray(input) ? input : [input];\n for (const desc of descriptors) {\n const hash = fontFaceContentHash(family, desc);\n const css = formatFontFaceRule(family, desc);\n this.collectFontFace(hash, css);\n }\n }\n }\n\n const globalCS = getGlobalCounterStyle();\n if (globalCS) {\n for (const [name, descriptors] of Object.entries(globalCS)) {\n const css = formatCounterStyleRule(name, descriptors);\n this.collectCounterStyle(name, css);\n }\n }\n\n const globalStyles = getGlobalStyles();\n if (globalStyles) {\n for (const [selector, styles] of Object.entries(globalStyles)) {\n if (Object.keys(styles).length > 0) {\n const rules = renderStyles(styles, selector) as StyleResult[];\n if (rules.length > 0) {\n const css = formatGlobalRules(rules);\n if (css) {\n this.collectGlobalStyles(`__global:styles:${selector}`, css);\n }\n }\n }\n }\n }\n }\n\n /**\n * Allocate a className for a cache key, server-side.\n * Mirrors StyleInjector.allocateClassName but without DOM access.\n */\n allocateClassName(cacheKey: string): {\n className: string;\n isNewAllocation: boolean;\n } {\n const existing = this.cacheKeyToClassName.get(cacheKey);\n if (existing) {\n return { className: existing, isNewAllocation: false };\n }\n\n const className = generateClassName(cacheKey);\n this.cacheKeyToClassName.set(cacheKey, className);\n\n return { className, isNewAllocation: true };\n }\n\n /**\n * Record CSS rules for a chunk.\n * Called by useStyles during server render.\n */\n collectChunk(\n cacheKey: string,\n className: string,\n rules: StyleResult[],\n ): void {\n if (this.chunks.has(cacheKey)) return;\n const css = formatRules(rules, className);\n if (css) {\n this.chunks.set(cacheKey, css);\n }\n }\n\n /**\n * Record a @property rule. Deduplicated by name.\n */\n collectProperty(name: string, css: string): void {\n if (!this.propertyRules.has(name)) {\n this.propertyRules.set(name, css);\n }\n }\n\n /**\n * Record a @keyframes rule. Deduplicated by name.\n */\n collectKeyframes(name: string, css: string): void {\n if (!this.keyframeRules.has(name)) {\n this.keyframeRules.set(name, css);\n }\n }\n\n /**\n * Allocate a keyframe name for SSR. Uses provided name or generates one.\n */\n allocateKeyframeName(providedName?: string): string {\n return providedName ?? `k${this.keyframesCounter++}`;\n }\n\n /**\n * Record a @font-face rule. Deduplicated by key (content hash).\n */\n collectFontFace(key: string, css: string): void {\n if (!this.fontFaceRules.has(key)) {\n this.fontFaceRules.set(key, css);\n }\n }\n\n /**\n * Record a @counter-style rule. Deduplicated by name.\n */\n collectCounterStyle(name: string, css: string): void {\n if (!this.counterStyleRules.has(name)) {\n this.counterStyleRules.set(name, css);\n }\n }\n\n /**\n * Allocate a counter-style name for SSR. Uses provided name or generates one.\n */\n allocateCounterStyleName(providedName?: string): string {\n return providedName ?? `cs${this.counterStyleCounter++}`;\n }\n\n /**\n * Record global styles (from useGlobalStyles). Deduplicated by key.\n */\n collectGlobalStyles(key: string, css: string): void {\n if (!this.globalStyles.has(key)) {\n this.globalStyles.set(key, css);\n }\n }\n\n /**\n * Record raw CSS text (from useRawCSS). Deduplicated by key.\n */\n collectRawCSS(key: string, css: string): void {\n if (!this.rawCSS.has(key)) {\n this.rawCSS.set(key, css);\n }\n }\n\n /**\n * Extract all CSS collected so far as a single string.\n * Includes @property and @keyframes rules.\n * Used for non-streaming SSR (renderToString).\n */\n getCSS(): string {\n const parts: string[] = [];\n\n for (const css of this.propertyRules.values()) {\n parts.push(css);\n }\n\n for (const css of this.fontFaceRules.values()) {\n parts.push(css);\n }\n\n for (const css of this.counterStyleRules.values()) {\n parts.push(css);\n }\n\n for (const css of this.rawCSS.values()) {\n parts.push(css);\n }\n\n for (const css of this.globalStyles.values()) {\n parts.push(css);\n }\n\n for (const css of this.chunks.values()) {\n parts.push(css);\n }\n\n for (const css of this.keyframeRules.values()) {\n parts.push(css);\n }\n\n return parts.join('\\n');\n }\n\n /**\n * Flush only newly collected CSS since the last flush.\n * Used for streaming SSR (renderToPipeableStream + useServerInsertedHTML).\n */\n flushCSS(): string {\n const parts: string[] = [];\n\n for (const [name, css] of this.propertyRules) {\n if (!this.flushedPropertyKeys.has(name)) {\n parts.push(css);\n this.flushedPropertyKeys.add(name);\n }\n }\n\n for (const [key, css] of this.fontFaceRules) {\n if (!this.flushedFontFaceKeys.has(key)) {\n parts.push(css);\n this.flushedFontFaceKeys.add(key);\n }\n }\n\n for (const [key, css] of this.counterStyleRules) {\n if (!this.flushedCounterStyleKeys.has(key)) {\n parts.push(css);\n this.flushedCounterStyleKeys.add(key);\n }\n }\n\n for (const [key, css] of this.rawCSS) {\n if (!this.flushedRawKeys.has(key)) {\n parts.push(css);\n this.flushedRawKeys.add(key);\n }\n }\n\n for (const [key, css] of this.globalStyles) {\n if (!this.flushedGlobalKeys.has(key)) {\n parts.push(css);\n this.flushedGlobalKeys.add(key);\n }\n }\n\n for (const [key, css] of this.chunks) {\n if (!this.flushedKeys.has(key)) {\n parts.push(css);\n this.flushedKeys.add(key);\n }\n }\n\n for (const [name, css] of this.keyframeRules) {\n if (!this.flushedKeyframeKeys.has(name)) {\n parts.push(css);\n this.flushedKeyframeKeys.add(name);\n }\n }\n\n return parts.join('\\n');\n }\n\n private flushedClassNames = new Set<string>();\n\n /**\n * Return class names rendered since the last call (for streaming).\n * Used to emit lightweight class-list scripts for client hydration.\n */\n getRenderedClassNames(): string[] {\n const names: string[] = [];\n for (const className of this.cacheKeyToClassName.values()) {\n if (!this.flushedClassNames.has(className)) {\n this.flushedClassNames.add(className);\n names.push(className);\n }\n }\n return names;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA4BA,SAAS,kBAAkB,UAA0B;AACnD,QAAO,IAAI,WAAW,SAAS;;AAGjC,IAAa,uBAAb,MAAkC;CAChC,yBAAiB,IAAI,KAAqB;CAC1C,sCAA8B,IAAI,KAAqB;CACvD,8BAAsB,IAAI,KAAa;CACvC,gCAAwB,IAAI,KAAqB;CACjD,sCAA8B,IAAI,KAAa;CAC/C,gCAAwB,IAAI,KAAqB;CACjD,sCAA8B,IAAI,KAAa;CAC/C,+BAAuB,IAAI,KAAqB;CAChD,oCAA4B,IAAI,KAAa;CAC7C,yBAAiB,IAAI,KAAqB;CAC1C,iCAAyB,IAAI,KAAa;CAC1C,gCAAwB,IAAI,KAAqB;CACjD,sCAA8B,IAAI,KAAa;CAC/C,oCAA4B,IAAI,KAAqB;CACrD,0CAAkC,IAAI,KAAa;CACnD,mBAA2B;CAC3B,sBAA8B;CAC9B,qBAA6B;;;;;;;;;;CAW7B,mBAAyB;AACvB,MAAI,KAAK,mBAAoB;AAC7B,OAAK,qBAAqB;AAE1B,OAAK,MAAM,CAAC,OAAO,eAAe,OAAO,QACvC,wBAAwB,CACzB,EAAE;GACD,MAAM,MAAM,kBAAkB,OAAO,WAAW;AAChD,OAAI,IACF,MAAK,gBAAgB,UAAU,SAAS,IAAI;;EAIhD,MAAM,cAAc,uBAAuB;AAC3C,MAAI,eAAe,OAAO,KAAK,YAAY,CAAC,SAAS,GAAG;GACtD,MAAM,aAAa,aAAa,aAAa,QAAQ;AACrD,OAAI,WAAW,SAAS,GAAG;IACzB,MAAM,MAAM,kBAAkB,WAAW;AACzC,QAAI,IACF,MAAK,oBAAoB,mBAAmB,IAA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GzB,oCAA4B,IAAI,KAAa;;;;;CAM7C,wBAAkC;EAChC,MAAM,QAAkB,EAAE;AAC1B,OAAK,MAAM,aAAa,KAAK,oBAAoB,QAAQ,CACvD,KAAI,CAAC,KAAK,kBAAkB,IAAI,UAAU,EAAE;AAC1C,QAAK,kBAAkB,IAAI,UAAU;AACrC,SAAM,KAAK,UAAU;;AAGzB,SAAO"}
1
+ {"version":3,"file":"collector-DrgDE7QB.js","names":[],"sources":["../src/ssr/collector.ts"],"sourcesContent":["/**\n * ServerStyleCollector — server-safe style collector for SSR.\n *\n * Accumulates CSS rules and cache metadata during server rendering.\n * This is the server-side counterpart to StyleInjector: it allocates\n * hash-based class names (`t${hash}`), formats CSS rules into text,\n * and tracks rendered class names for lightweight client transfer.\n *\n * One instance is created per HTTP request. Concurrent requests\n * each get their own collector (via AsyncLocalStorage or React context).\n */\n\nimport {\n getEffectiveProperties,\n getGlobalStyles,\n getGlobalCounterStyle,\n getGlobalFontFace,\n getGlobalConfigTokens,\n} from '../config';\nimport { formatCounterStyleRule } from '../counter-style';\nimport { fontFaceContentHash, formatFontFaceRule } from '../font-face';\nimport { renderStyles } from '../pipeline';\nimport type { StyleResult } from '../pipeline';\nimport { hashString } from '../utils/hash';\nimport { formatPropertyCSS } from './format-property';\nimport { formatGlobalRules } from './format-global-rules';\nimport { formatRules } from './format-rules';\n\nfunction generateClassName(cacheKey: string): string {\n return `t${hashString(cacheKey)}`;\n}\n\nexport class ServerStyleCollector {\n private chunks = new Map<string, string>();\n private cacheKeyToClassName = new Map<string, string>();\n private flushedKeys = new Set<string>();\n private propertyRules = new Map<string, string>();\n private flushedPropertyKeys = new Set<string>();\n private keyframeRules = new Map<string, string>();\n private flushedKeyframeKeys = new Set<string>();\n private globalStyles = new Map<string, string>();\n private flushedGlobalKeys = new Set<string>();\n private rawCSS = new Map<string, string>();\n private flushedRawKeys = new Set<string>();\n private fontFaceRules = new Map<string, string>();\n private flushedFontFaceKeys = new Set<string>();\n private counterStyleRules = new Map<string, string>();\n private flushedCounterStyleKeys = new Set<string>();\n private keyframesCounter = 0;\n private counterStyleCounter = 0;\n private internalsCollected = false;\n\n /**\n * Collect internal @property rules and :root token defaults.\n * Mirrors markStylesGenerated() from the client-side injector.\n * Called automatically on first chunk collection; idempotent.\n *\n * Internals are always emitted here — the RSC path deliberately\n * defers to SSR so that tokens appear exactly once per page in\n * <style data-tasty-ssr> (avoiding duplication of large token sets).\n */\n collectInternals(): void {\n if (this.internalsCollected) return;\n this.internalsCollected = true;\n\n for (const [token, definition] of Object.entries(\n getEffectiveProperties(),\n )) {\n const css = formatPropertyCSS(token, definition);\n if (css) {\n this.collectProperty(`__prop:${token}`, css);\n }\n }\n\n const tokenStyles = getGlobalConfigTokens();\n if (tokenStyles && Object.keys(tokenStyles).length > 0) {\n const tokenRules = renderStyles(tokenStyles, ':root') as StyleResult[];\n if (tokenRules.length > 0) {\n const css = formatGlobalRules(tokenRules);\n if (css) {\n this.collectGlobalStyles('__global:tokens', css);\n }\n }\n }\n\n const globalFF = getGlobalFontFace();\n if (globalFF) {\n for (const [family, input] of Object.entries(globalFF)) {\n const descriptors = Array.isArray(input) ? input : [input];\n for (const desc of descriptors) {\n const hash = fontFaceContentHash(family, desc);\n const css = formatFontFaceRule(family, desc);\n this.collectFontFace(hash, css);\n }\n }\n }\n\n const globalCS = getGlobalCounterStyle();\n if (globalCS) {\n for (const [name, descriptors] of Object.entries(globalCS)) {\n const css = formatCounterStyleRule(name, descriptors);\n this.collectCounterStyle(name, css);\n }\n }\n\n const globalStyles = getGlobalStyles();\n if (globalStyles) {\n for (const [selector, styles] of Object.entries(globalStyles)) {\n if (Object.keys(styles).length > 0) {\n const rules = renderStyles(styles, selector) as StyleResult[];\n if (rules.length > 0) {\n const css = formatGlobalRules(rules);\n if (css) {\n this.collectGlobalStyles(`__global:styles:${selector}`, css);\n }\n }\n }\n }\n }\n }\n\n /**\n * Allocate a className for a cache key, server-side.\n * Mirrors StyleInjector.allocateClassName but without DOM access.\n */\n allocateClassName(cacheKey: string): {\n className: string;\n isNewAllocation: boolean;\n } {\n const existing = this.cacheKeyToClassName.get(cacheKey);\n if (existing) {\n return { className: existing, isNewAllocation: false };\n }\n\n const className = generateClassName(cacheKey);\n this.cacheKeyToClassName.set(cacheKey, className);\n\n return { className, isNewAllocation: true };\n }\n\n /**\n * Record CSS rules for a chunk.\n * Called by useStyles during server render.\n */\n collectChunk(\n cacheKey: string,\n className: string,\n rules: StyleResult[],\n ): void {\n if (this.chunks.has(cacheKey)) return;\n const css = formatRules(rules, className);\n if (css) {\n this.chunks.set(cacheKey, css);\n }\n }\n\n /**\n * Record a @property rule. Deduplicated by name.\n */\n collectProperty(name: string, css: string): void {\n if (!this.propertyRules.has(name)) {\n this.propertyRules.set(name, css);\n }\n }\n\n /**\n * Record a @keyframes rule. Deduplicated by name.\n */\n collectKeyframes(name: string, css: string): void {\n if (!this.keyframeRules.has(name)) {\n this.keyframeRules.set(name, css);\n }\n }\n\n /**\n * Allocate a keyframe name for SSR. Uses provided name or generates one.\n */\n allocateKeyframeName(providedName?: string): string {\n return providedName ?? `k${this.keyframesCounter++}`;\n }\n\n /**\n * Record a @font-face rule. Deduplicated by key (content hash).\n */\n collectFontFace(key: string, css: string): void {\n if (!this.fontFaceRules.has(key)) {\n this.fontFaceRules.set(key, css);\n }\n }\n\n /**\n * Record a @counter-style rule. Deduplicated by name.\n */\n collectCounterStyle(name: string, css: string): void {\n if (!this.counterStyleRules.has(name)) {\n this.counterStyleRules.set(name, css);\n }\n }\n\n /**\n * Allocate a counter-style name for SSR. Uses provided name or generates one.\n */\n allocateCounterStyleName(providedName?: string): string {\n return providedName ?? `cs${this.counterStyleCounter++}`;\n }\n\n /**\n * Record global styles (from useGlobalStyles). Deduplicated by key.\n */\n collectGlobalStyles(key: string, css: string): void {\n if (!this.globalStyles.has(key)) {\n this.globalStyles.set(key, css);\n }\n }\n\n /**\n * Record raw CSS text (from useRawCSS). Deduplicated by key.\n */\n collectRawCSS(key: string, css: string): void {\n if (!this.rawCSS.has(key)) {\n this.rawCSS.set(key, css);\n }\n }\n\n /**\n * Extract all CSS collected so far as a single string.\n * Includes @property and @keyframes rules.\n * Used for non-streaming SSR (renderToString).\n */\n getCSS(): string {\n const parts: string[] = [];\n\n for (const css of this.propertyRules.values()) {\n parts.push(css);\n }\n\n for (const css of this.fontFaceRules.values()) {\n parts.push(css);\n }\n\n for (const css of this.counterStyleRules.values()) {\n parts.push(css);\n }\n\n for (const css of this.rawCSS.values()) {\n parts.push(css);\n }\n\n for (const css of this.globalStyles.values()) {\n parts.push(css);\n }\n\n for (const css of this.chunks.values()) {\n parts.push(css);\n }\n\n for (const css of this.keyframeRules.values()) {\n parts.push(css);\n }\n\n return parts.join('\\n');\n }\n\n /**\n * Flush only newly collected CSS since the last flush.\n * Used for streaming SSR (renderToPipeableStream + useServerInsertedHTML).\n */\n flushCSS(): string {\n const parts: string[] = [];\n\n for (const [name, css] of this.propertyRules) {\n if (!this.flushedPropertyKeys.has(name)) {\n parts.push(css);\n this.flushedPropertyKeys.add(name);\n }\n }\n\n for (const [key, css] of this.fontFaceRules) {\n if (!this.flushedFontFaceKeys.has(key)) {\n parts.push(css);\n this.flushedFontFaceKeys.add(key);\n }\n }\n\n for (const [key, css] of this.counterStyleRules) {\n if (!this.flushedCounterStyleKeys.has(key)) {\n parts.push(css);\n this.flushedCounterStyleKeys.add(key);\n }\n }\n\n for (const [key, css] of this.rawCSS) {\n if (!this.flushedRawKeys.has(key)) {\n parts.push(css);\n this.flushedRawKeys.add(key);\n }\n }\n\n for (const [key, css] of this.globalStyles) {\n if (!this.flushedGlobalKeys.has(key)) {\n parts.push(css);\n this.flushedGlobalKeys.add(key);\n }\n }\n\n for (const [key, css] of this.chunks) {\n if (!this.flushedKeys.has(key)) {\n parts.push(css);\n this.flushedKeys.add(key);\n }\n }\n\n for (const [name, css] of this.keyframeRules) {\n if (!this.flushedKeyframeKeys.has(name)) {\n parts.push(css);\n this.flushedKeyframeKeys.add(name);\n }\n }\n\n return parts.join('\\n');\n }\n\n private flushedClassNames = new Set<string>();\n\n /**\n * Return class names rendered since the last call (for streaming).\n * Used to emit lightweight class-list scripts for client hydration.\n */\n getRenderedClassNames(): string[] {\n const names: string[] = [];\n for (const className of this.cacheKeyToClassName.values()) {\n if (!this.flushedClassNames.has(className)) {\n this.flushedClassNames.add(className);\n names.push(className);\n }\n }\n return names;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA4BA,SAAS,kBAAkB,UAA0B;AACnD,QAAO,IAAI,WAAW,SAAS;;AAGjC,IAAa,uBAAb,MAAkC;CAChC,yBAAiB,IAAI,KAAqB;CAC1C,sCAA8B,IAAI,KAAqB;CACvD,8BAAsB,IAAI,KAAa;CACvC,gCAAwB,IAAI,KAAqB;CACjD,sCAA8B,IAAI,KAAa;CAC/C,gCAAwB,IAAI,KAAqB;CACjD,sCAA8B,IAAI,KAAa;CAC/C,+BAAuB,IAAI,KAAqB;CAChD,oCAA4B,IAAI,KAAa;CAC7C,yBAAiB,IAAI,KAAqB;CAC1C,iCAAyB,IAAI,KAAa;CAC1C,gCAAwB,IAAI,KAAqB;CACjD,sCAA8B,IAAI,KAAa;CAC/C,oCAA4B,IAAI,KAAqB;CACrD,0CAAkC,IAAI,KAAa;CACnD,mBAA2B;CAC3B,sBAA8B;CAC9B,qBAA6B;;;;;;;;;;CAW7B,mBAAyB;AACvB,MAAI,KAAK,mBAAoB;AAC7B,OAAK,qBAAqB;AAE1B,OAAK,MAAM,CAAC,OAAO,eAAe,OAAO,QACvC,wBAAwB,CACzB,EAAE;GACD,MAAM,MAAM,kBAAkB,OAAO,WAAW;AAChD,OAAI,IACF,MAAK,gBAAgB,UAAU,SAAS,IAAI;;EAIhD,MAAM,cAAc,uBAAuB;AAC3C,MAAI,eAAe,OAAO,KAAK,YAAY,CAAC,SAAS,GAAG;GACtD,MAAM,aAAa,aAAa,aAAa,QAAQ;AACrD,OAAI,WAAW,SAAS,GAAG;IACzB,MAAM,MAAM,kB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oBAAoB,IAAI,KAAK;;AAItC,SAAO,MAAM,KAAK,KAAK;;CAGzB,oCAA4B,IAAI,KAAa;;;;;CAM7C,wBAAkC;EAChC,MAAM,QAAkB,EAAE;AAC1B,OAAK,MAAM,aAAa,KAAK,oBAAoB,QAAQ,CACvD,KAAI,CAAC,KAAK,kBAAkB,IAAI,UAAU,EAAE;AAC1C,QAAK,kBAAkB,IAAI,UAAU;AACrC,SAAM,KAAK,UAAU;;AAGzB,SAAO"}
@@ -1,4 +1,4 @@
1
- import { n as StyleResult } from "./index-PzENbpAq.js";
1
+ import { n as StyleResult } from "./index-dUtwpOux.js";
2
2
 
3
3
  //#region src/ssr/collector.d.ts
4
4
  declare class ServerStyleCollector {
@@ -95,4 +95,4 @@ declare class ServerStyleCollector {
95
95
  }
96
96
  //#endregion
97
97
  export { ServerStyleCollector as t };
98
- //# sourceMappingURL=collector-CkZ517g4.d.ts.map
98
+ //# sourceMappingURL=collector-LuU1vZ68.d.ts.map
@@ -3885,6 +3885,14 @@ const styleHandlers = {
3885
3885
  const { STYLE_HANDLER_MAP, defineCustomStyle, defineStyleAlias } = predefine();
3886
3886
  //#endregion
3887
3887
  //#region src/injector/sheet-manager.ts
3888
+ const supportsConstructableSheets = typeof CSSStyleSheet !== "undefined" && (() => {
3889
+ try {
3890
+ new CSSStyleSheet();
3891
+ return true;
3892
+ } catch {
3893
+ return false;
3894
+ }
3895
+ })();
3888
3896
  var SheetManager = class {
3889
3897
  rootRegistries = /* @__PURE__ */ new WeakMap();
3890
3898
  /** Strong set of active roots so background GC can iterate them all */
@@ -3892,6 +3900,8 @@ var SheetManager = class {
3892
3900
  config;
3893
3901
  /** Dedicated style elements for raw CSS per root */
3894
3902
  rawStyleElements = /* @__PURE__ */ new WeakMap();
3903
+ /** Constructable sheets for raw CSS in adopted mode */
3904
+ rawConstructableSheets = /* @__PURE__ */ new WeakMap();
3895
3905
  /** Tracking for raw CSS blocks per root */
3896
3906
  rawCSSBlocks = /* @__PURE__ */ new WeakMap();
3897
3907
  /** Counter for generating unique raw CSS IDs */
@@ -3900,6 +3910,22 @@ var SheetManager = class {
3900
3910
  this.config = config;
3901
3911
  }
3902
3912
  /**
3913
+ * Resolve the underlying CSSStyleSheet from a SheetInfo,
3914
+ * abstracting away adopted vs style-element modes.
3915
+ */
3916
+ getCSSSheet(sheetInfo) {
3917
+ if (sheetInfo.constructableSheet) return sheetInfo.constructableSheet;
3918
+ return sheetInfo.sheet?.sheet ?? null;
3919
+ }
3920
+ /**
3921
+ * Determine the injection mode for a root.
3922
+ * ShadowRoot uses adopted stylesheets when supported; Document uses <style> elements.
3923
+ */
3924
+ detectInjectionMode(root) {
3925
+ if (root instanceof ShadowRoot && supportsConstructableSheets && !this.config.forceTextInjection) return "adopted";
3926
+ return "style-element";
3927
+ }
3928
+ /**
3903
3929
  * Get or create registry for a root (Document or ShadowRoot)
3904
3930
  */
3905
3931
  getRegistry(root) {
@@ -3933,7 +3959,8 @@ var SheetManager = class {
3933
3959
  usageMap: /* @__PURE__ */ new Map(),
3934
3960
  touchCount: 0,
3935
3961
  serverClassSyncIndex: 0,
3936
- rscStylesScanned: false
3962
+ rscStylesScanned: false,
3963
+ injectionMode: this.detectInjectionMode(root)
3937
3964
  };
3938
3965
  this.rootRegistries.set(root, registry);
3939
3966
  this.activeRoots.add(root);
@@ -3955,9 +3982,23 @@ var SheetManager = class {
3955
3982
  for (const root of toPrune) this.cleanup(root);
3956
3983
  }
3957
3984
  /**
3958
- * Create a new stylesheet for the registry
3985
+ * Create a new stylesheet for the registry.
3986
+ * In adopted mode (ShadowRoot), creates a constructable CSSStyleSheet and
3987
+ * pushes it to adoptedStyleSheets. Otherwise creates a <style> element.
3959
3988
  */
3960
3989
  createSheet(registry, root) {
3990
+ if (registry.injectionMode === "adopted") {
3991
+ const constructableSheet = new CSSStyleSheet();
3992
+ root.adoptedStyleSheets = [...root.adoptedStyleSheets, constructableSheet];
3993
+ const sheetInfo = {
3994
+ sheet: null,
3995
+ constructableSheet,
3996
+ ruleCount: 0,
3997
+ holes: []
3998
+ };
3999
+ registry.sheets.push(sheetInfo);
4000
+ return sheetInfo;
4001
+ }
3961
4002
  const sheetInfo = {
3962
4003
  sheet: this.createStyleElement(root),
3963
4004
  ruleCount: 0,
@@ -4028,7 +4069,7 @@ var SheetManager = class {
4028
4069
  let fullRule = baseRule;
4029
4070
  if (rule.atRules && rule.atRules.length > 0) fullRule = rule.atRules.reduce((css, atRule) => `${atRule} { ${css} }`, baseRule);
4030
4071
  const styleElement = targetSheet.sheet;
4031
- const styleSheet = styleElement.sheet;
4072
+ const styleSheet = this.getCSSSheet(targetSheet);
4032
4073
  if (styleSheet && !this.config.forceTextInjection) {
4033
4074
  const maxIndex = styleSheet.cssRules.length;
4034
4075
  const atomicRuleIndex = this.findAvailableRuleIndex(targetSheet);
@@ -4098,7 +4139,7 @@ var SheetManager = class {
4098
4139
  if (!anyInserted) {}
4099
4140
  } else console.warn("[tasty] Browser rejected CSS rule:", fullRule, e);
4100
4141
  }
4101
- } else {
4142
+ } else if (styleElement) {
4102
4143
  const atomicRuleIndex = this.findAvailableRuleIndex(targetSheet);
4103
4144
  styleElement.textContent = (styleElement.textContent || "") + "\n" + fullRule;
4104
4145
  targetSheet.ruleCount++;
@@ -4107,7 +4148,7 @@ var SheetManager = class {
4107
4148
  lastInsertedIndex = atomicRuleIndex;
4108
4149
  currentRuleIndex = atomicRuleIndex + 1;
4109
4150
  }
4110
- if (!styleElement.parentNode && !this.config.forceTextInjection) console.error("SheetManager: Style element is NOT in DOM! This is the problem!", {
4151
+ if (styleElement && !styleElement.parentNode && !this.config.forceTextInjection) console.error("SheetManager: Style element is NOT in DOM! This is the problem!", {
4111
4152
  className,
4112
4153
  ruleIndex: currentRuleIndex
4113
4154
  });
@@ -4197,7 +4238,7 @@ var SheetManager = class {
4197
4238
  if (!sheet) return;
4198
4239
  try {
4199
4240
  const texts = this.config.devMode && Array.isArray(ruleInfo.cssText) ? ruleInfo.cssText.slice() : [];
4200
- const styleSheet = sheet.sheet.sheet;
4241
+ const styleSheet = this.getCSSSheet(sheet);
4201
4242
  if (styleSheet) {
4202
4243
  const rules = styleSheet.cssRules;
4203
4244
  if (ruleInfo.indices && ruleInfo.indices.length > 0) {
@@ -4290,8 +4331,8 @@ var SheetManager = class {
4290
4331
  if ((registry.refCounts.get(className) || 0) > 0) continue;
4291
4332
  if (registry.rules.get(className) !== ruleInfo) continue;
4292
4333
  const sheetInfo = registry.sheets[ruleInfo.sheetIndex];
4293
- if (!sheetInfo || !sheetInfo.sheet) continue;
4294
- const styleSheet = sheetInfo.sheet.sheet;
4334
+ if (!sheetInfo || !sheetInfo.sheet && !sheetInfo.constructableSheet) continue;
4335
+ const styleSheet = this.getCSSSheet(sheetInfo);
4295
4336
  if (!styleSheet) continue;
4296
4337
  const maxRuleIndex = styleSheet.cssRules.length - 1;
4297
4338
  const startIdx = ruleInfo.ruleIndex;
@@ -4328,12 +4369,17 @@ var SheetManager = class {
4328
4369
  */
4329
4370
  getCssText(registry) {
4330
4371
  const cssChunks = [];
4331
- for (const sheet of registry.sheets) try {
4332
- const styleElement = sheet.sheet;
4333
- if (styleElement.textContent) cssChunks.push(styleElement.textContent);
4334
- else if (styleElement.sheet) {
4335
- const rules = Array.from(styleElement.sheet.cssRules);
4372
+ for (const sheetInfo of registry.sheets) try {
4373
+ if (sheetInfo.constructableSheet) {
4374
+ const rules = Array.from(sheetInfo.constructableSheet.cssRules);
4336
4375
  cssChunks.push(rules.map((rule) => rule.cssText).join("\n"));
4376
+ } else if (sheetInfo.sheet) {
4377
+ const styleElement = sheetInfo.sheet;
4378
+ if (styleElement.textContent) cssChunks.push(styleElement.textContent);
4379
+ else if (styleElement.sheet) {
4380
+ const rules = Array.from(styleElement.sheet.cssRules);
4381
+ cssChunks.push(rules.map((rule) => rule.cssText).join("\n"));
4382
+ }
4337
4383
  }
4338
4384
  } catch (error) {
4339
4385
  console.warn("Failed to read CSS from sheet:", error);
@@ -4441,12 +4487,11 @@ var SheetManager = class {
4441
4487
  try {
4442
4488
  const { css: cssSteps, declarations } = this.stepsToCSS(steps);
4443
4489
  const fullRule = `@keyframes ${name} { ${cssSteps} }`;
4444
- const styleElement = targetSheet.sheet;
4445
- const styleSheet = styleElement.sheet;
4490
+ const styleSheet = this.getCSSSheet(targetSheet);
4446
4491
  if (styleSheet && !this.config.forceTextInjection) {
4447
4492
  const safeIndex = Math.min(Math.max(0, ruleIndex), styleSheet.cssRules.length);
4448
4493
  styleSheet.insertRule(fullRule, safeIndex);
4449
- } else styleElement.textContent = (styleElement.textContent || "") + "\n" + fullRule;
4494
+ } else if (targetSheet.sheet) targetSheet.sheet.textContent = (targetSheet.sheet.textContent || "") + "\n" + fullRule;
4450
4495
  targetSheet.ruleCount++;
4451
4496
  return {
4452
4497
  info: {
@@ -4469,7 +4514,7 @@ var SheetManager = class {
4469
4514
  const sheet = registry.sheets[info.sheetIndex];
4470
4515
  if (!sheet) return;
4471
4516
  try {
4472
- const styleSheet = sheet.sheet.sheet;
4517
+ const styleSheet = this.getCSSSheet(sheet);
4473
4518
  if (styleSheet) {
4474
4519
  if (info.ruleIndex >= 0 && info.ruleIndex < styleSheet.cssRules.length) {
4475
4520
  styleSheet.deleteRule(info.ruleIndex);
@@ -4491,20 +4536,54 @@ var SheetManager = class {
4491
4536
  cleanup(root) {
4492
4537
  const registry = this.rootRegistries.get(root);
4493
4538
  if (!registry) return;
4494
- for (const sheet of registry.sheets) try {
4495
- const styleElement = sheet.sheet;
4496
- if (styleElement.parentNode) styleElement.parentNode.removeChild(styleElement);
4497
- } catch (error) {
4498
- console.warn("Failed to cleanup sheet:", error);
4539
+ if (registry.injectionMode === "adopted") {
4540
+ const shadowRoot = root;
4541
+ const ownedSheets = /* @__PURE__ */ new Set();
4542
+ for (const sheetInfo of registry.sheets) if (sheetInfo.constructableSheet) ownedSheets.add(sheetInfo.constructableSheet);
4543
+ const rawSheet = this.rawConstructableSheets.get(shadowRoot);
4544
+ if (rawSheet) {
4545
+ ownedSheets.add(rawSheet);
4546
+ this.rawConstructableSheets.delete(shadowRoot);
4547
+ }
4548
+ if (ownedSheets.size > 0) shadowRoot.adoptedStyleSheets = shadowRoot.adoptedStyleSheets.filter((s) => !ownedSheets.has(s));
4549
+ } else {
4550
+ for (const sheet of registry.sheets) try {
4551
+ const styleElement = sheet.sheet;
4552
+ if (styleElement?.parentNode) styleElement.parentNode.removeChild(styleElement);
4553
+ } catch (error) {
4554
+ console.warn("Failed to cleanup sheet:", error);
4555
+ }
4556
+ const rawStyleElement = this.rawStyleElements.get(root);
4557
+ if (rawStyleElement?.parentNode) rawStyleElement.parentNode.removeChild(rawStyleElement);
4558
+ this.rawStyleElements.delete(root);
4499
4559
  }
4500
4560
  this.rootRegistries.delete(root);
4501
4561
  this.activeRoots.delete(root);
4502
- const rawStyleElement = this.rawStyleElements.get(root);
4503
- if (rawStyleElement?.parentNode) rawStyleElement.parentNode.removeChild(rawStyleElement);
4504
- this.rawStyleElements.delete(root);
4505
4562
  this.rawCSSBlocks.delete(root);
4506
4563
  }
4507
4564
  /**
4565
+ * Check if a root uses adopted injection mode.
4566
+ */
4567
+ isAdoptedMode(root) {
4568
+ const registry = this.rootRegistries.get(root);
4569
+ if (registry) return registry.injectionMode === "adopted";
4570
+ return this.detectInjectionMode(root) === "adopted";
4571
+ }
4572
+ /**
4573
+ * Get or create a constructable CSSStyleSheet for raw CSS in adopted mode.
4574
+ * The raw sheet is prepended to adoptedStyleSheets so it precedes tasty rules.
4575
+ */
4576
+ getOrCreateRawAdoptedSheet(root) {
4577
+ let sheet = this.rawConstructableSheets.get(root);
4578
+ if (!sheet) {
4579
+ sheet = new CSSStyleSheet();
4580
+ root.adoptedStyleSheets = [sheet, ...root.adoptedStyleSheets];
4581
+ this.rawConstructableSheets.set(root, sheet);
4582
+ if (!this.rawCSSBlocks.has(root)) this.rawCSSBlocks.set(root, /* @__PURE__ */ new Map());
4583
+ }
4584
+ return sheet;
4585
+ }
4586
+ /**
4508
4587
  * Get or create a dedicated style element for raw CSS
4509
4588
  * Raw CSS is kept separate from tasty-managed sheets to avoid index conflicts
4510
4589
  */
@@ -4528,9 +4607,24 @@ var SheetManager = class {
4528
4607
  */
4529
4608
  injectRawCSS(css, root) {
4530
4609
  if (!css.trim()) return { dispose: () => {} };
4610
+ const id = `raw_${this.rawCSSCounter++}`;
4611
+ if (this.isAdoptedMode(root)) {
4612
+ this.getOrCreateRawAdoptedSheet(root);
4613
+ const blocksMap = this.rawCSSBlocks.get(root);
4614
+ const info = {
4615
+ id,
4616
+ css,
4617
+ startOffset: 0,
4618
+ endOffset: css.length
4619
+ };
4620
+ blocksMap.set(id, info);
4621
+ this.rebuildRawAdoptedSheet(root);
4622
+ return { dispose: () => {
4623
+ this.disposeRawCSS(id, root);
4624
+ } };
4625
+ }
4531
4626
  const styleElement = this.getOrCreateRawStyleElement(root);
4532
4627
  const blocksMap = this.rawCSSBlocks.get(root);
4533
- const id = `raw_${this.rawCSSCounter++}`;
4534
4628
  const currentContent = styleElement.textContent || "";
4535
4629
  const startOffset = currentContent.length;
4536
4630
  const cssWithNewline = (currentContent ? "\n" : "") + css;
@@ -4548,14 +4642,35 @@ var SheetManager = class {
4548
4642
  } };
4549
4643
  }
4550
4644
  /**
4645
+ * Rebuild the raw CSS constructable sheet from all tracked blocks.
4646
+ */
4647
+ rebuildRawAdoptedSheet(root) {
4648
+ const sheet = this.rawConstructableSheets.get(root);
4649
+ const blocksMap = this.rawCSSBlocks.get(root);
4650
+ if (!sheet || !blocksMap) return;
4651
+ if (blocksMap.size === 0) {
4652
+ sheet.replaceSync("");
4653
+ return;
4654
+ }
4655
+ const blocks = Array.from(blocksMap.values());
4656
+ blocks.sort((a, b) => a.startOffset - b.startOffset);
4657
+ const allCSS = blocks.map((b) => b.css).join("\n");
4658
+ sheet.replaceSync(allCSS);
4659
+ }
4660
+ /**
4551
4661
  * Remove a raw CSS block by ID
4552
4662
  */
4553
4663
  disposeRawCSS(id, root) {
4554
- const styleElement = this.rawStyleElements.get(root);
4555
4664
  const blocksMap = this.rawCSSBlocks.get(root);
4556
- if (!styleElement || !blocksMap) return;
4665
+ if (!blocksMap) return;
4557
4666
  if (!blocksMap.get(id)) return;
4558
4667
  blocksMap.delete(id);
4668
+ if (this.isAdoptedMode(root)) {
4669
+ this.rebuildRawAdoptedSheet(root);
4670
+ return;
4671
+ }
4672
+ const styleElement = this.rawStyleElements.get(root);
4673
+ if (!styleElement) return;
4559
4674
  const remainingBlocks = Array.from(blocksMap.values());
4560
4675
  if (remainingBlocks.length === 0) styleElement.textContent = "";
4561
4676
  else {
@@ -4570,9 +4685,16 @@ var SheetManager = class {
4570
4685
  }
4571
4686
  }
4572
4687
  /**
4573
- * Get the raw CSS content for SSR
4688
+ * Get the raw CSS content
4574
4689
  */
4575
4690
  getRawCSSText(root) {
4691
+ if (this.isAdoptedMode(root)) {
4692
+ const blocksMap = this.rawCSSBlocks.get(root);
4693
+ if (!blocksMap || blocksMap.size === 0) return "";
4694
+ const blocks = Array.from(blocksMap.values());
4695
+ blocks.sort((a, b) => a.startOffset - b.startOffset);
4696
+ return blocks.map((b) => b.css).join("\n");
4697
+ }
4576
4698
  return this.rawStyleElements.get(root)?.textContent || "";
4577
4699
  }
4578
4700
  };
@@ -4999,7 +5121,8 @@ var StyleInjector = class StyleInjector {
4999
5121
  for (const cls of classNames) {
5000
5122
  const info = registry.rules.get(cls);
5001
5123
  if (info) {
5002
- const styleSheet = registry.sheets[info.sheetIndex]?.sheet?.sheet;
5124
+ const sheet = registry.sheets[info.sheetIndex];
5125
+ const styleSheet = sheet ? this.sheetManager.getCSSSheet(sheet) : null;
5003
5126
  if (styleSheet) {
5004
5127
  const start = Math.max(0, info.ruleIndex);
5005
5128
  const end = Math.min(styleSheet.cssRules.length - 1, info.endRuleIndex ?? info.ruleIndex);
@@ -9560,7 +9683,10 @@ function isTestEnvironment() {
9560
9683
  const g = global;
9561
9684
  if (g.vi || g.jest || g.expect || g.describe || g.it) return true;
9562
9685
  }
9563
- if (typeof window !== "undefined" && window.navigator?.userAgent?.includes("jsdom")) return true;
9686
+ if (typeof window !== "undefined") {
9687
+ const ua = window.navigator?.userAgent;
9688
+ if (ua?.includes("jsdom") || ua?.includes("HappyDOM")) return true;
9689
+ }
9564
9690
  if (typeof globalThis !== "undefined") {
9565
9691
  const gt = globalThis;
9566
9692
  if (gt.vitest || gt.mocha) return true;
@@ -10002,4 +10128,4 @@ function resetConfig() {
10002
10128
  //#endregion
10003
10129
  export { parseStyle as $, extractLocalCounterStyle as A, deprecationWarning as B, camelToKebab as C, Lru as Ct, getGlobalPredefinedStates as D, extractPredefinedStateRefs as E, formatFontFaceRule as F, DIRECTIONS as G, createStyle as H, hasLocalFontFace as I, getGlobalFuncs as J, customFunc as K, SheetManager as L, hasLocalCounterStyle as M, extractLocalFontFace as N, setGlobalPredefinedStates as O, fontFaceContentHash as P, parseColor as Q, STYLE_HANDLER_MAP as R, parseStateKey as S, strToRgb as St, extractLocalPredefinedStates as T, PropertyTypeResolver as U, warn as V, CUSTOM_UNITS as W, getGlobalPredefinedTokens as X, getGlobalParser as Y, normalizeColorTokenValue as Z, resetConfig as _, getComponentPropertySyntax as _t, getGlobalCounterStyle as a, StyleParser as at, isSelector as b, hexToRgb as bt, getGlobalKeyframes as c, hashString as ct, hasGlobalKeyframes as d, hasLocalProperties as dt, resetGlobalPredefinedTokens as et, hasGlobalRecipes as f, parsePropertyToken as ft, markStylesGenerated as g, getColorSpaceSuffix as gt, isTestEnvironment as h, getColorSpaceFunc as ht, getGlobalConfigTokens as i, okhslPlugin as it, formatCounterStyleRule as j, StyleInjector as k, getGlobalRecipes as l, extractLocalProperties as lt, isConfigLocked as m, getColorSpaceComponents as mt, getConfig as n, stringifyStyles as nt, getGlobalFontFace as o, Bucket as ot, hasStylesGenerated as p, colorInitialValueToComponents as pt, filterMods as q, getEffectiveProperties as r, okhslFunc as rt, getGlobalInjector as s, isDevEnv as st, configure as t, setGlobalPredefinedTokens as tt, getGlobalStyles as u, getEffectiveDefinition as ut, generateTypographyTokens as v, getNamedColorHex as vt, createStateParserContext as w, renderStyles as x, hslToRgbValues as xt, hasPipelineCacheEntry as y, getRgbValuesFromRgbaString as yt, styleHandlers as z };
10004
10130
 
10005
- //# sourceMappingURL=config-5jzS6k6B.js.map
10131
+ //# sourceMappingURL=config-_aQ_PZ-P.js.map