@tenphi/tasty 0.0.0-snapshot.fafcbfe → 0.0.0-snapshot.fde7ec8

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 (325) hide show
  1. package/README.md +322 -160
  2. package/dist/_virtual/_rolldown/runtime.js +1 -2
  3. package/dist/chunks/cacheKey.d.ts +1 -0
  4. package/dist/chunks/cacheKey.js +17 -10
  5. package/dist/chunks/cacheKey.js.map +1 -1
  6. package/dist/chunks/definitions.d.ts +1 -1
  7. package/dist/chunks/definitions.js +3 -5
  8. package/dist/chunks/definitions.js.map +1 -1
  9. package/dist/chunks/index.d.ts +1 -0
  10. package/dist/chunks/renderChunk.d.ts +1 -0
  11. package/dist/chunks/renderChunk.js +32 -34
  12. package/dist/chunks/renderChunk.js.map +1 -1
  13. package/dist/compute-styles.d.ts +31 -0
  14. package/dist/compute-styles.js +322 -0
  15. package/dist/compute-styles.js.map +1 -0
  16. package/dist/config.d.ts +157 -30
  17. package/dist/config.js +233 -45
  18. package/dist/config.js.map +1 -1
  19. package/dist/core/index.d.ts +12 -11
  20. package/dist/core/index.js +12 -11
  21. package/dist/counter-style/index.js +51 -0
  22. package/dist/counter-style/index.js.map +1 -0
  23. package/dist/debug.d.ts +26 -141
  24. package/dist/debug.js +359 -639
  25. package/dist/debug.js.map +1 -1
  26. package/dist/font-face/index.js +63 -0
  27. package/dist/font-face/index.js.map +1 -0
  28. package/dist/hooks/index.d.ts +7 -0
  29. package/dist/hooks/useCounterStyle.d.ts +36 -0
  30. package/dist/hooks/useCounterStyle.js +65 -0
  31. package/dist/hooks/useCounterStyle.js.map +1 -0
  32. package/dist/hooks/useFontFace.d.ts +45 -0
  33. package/dist/hooks/useFontFace.js +66 -0
  34. package/dist/hooks/useFontFace.js.map +1 -0
  35. package/dist/hooks/useGlobalStyles.d.ts +21 -2
  36. package/dist/hooks/useGlobalStyles.js +60 -28
  37. package/dist/hooks/useGlobalStyles.js.map +1 -1
  38. package/dist/hooks/useKeyframes.d.ts +4 -2
  39. package/dist/hooks/useKeyframes.js +44 -43
  40. package/dist/hooks/useKeyframes.js.map +1 -1
  41. package/dist/hooks/useProperty.d.ts +4 -2
  42. package/dist/hooks/useProperty.js +36 -31
  43. package/dist/hooks/useProperty.js.map +1 -1
  44. package/dist/hooks/useRawCSS.d.ts +13 -44
  45. package/dist/hooks/useRawCSS.js +91 -16
  46. package/dist/hooks/useRawCSS.js.map +1 -1
  47. package/dist/hooks/useStyles.d.ts +3 -3
  48. package/dist/hooks/useStyles.js +8 -146
  49. package/dist/hooks/useStyles.js.map +1 -1
  50. package/dist/index.d.ts +23 -12
  51. package/dist/index.js +15 -12
  52. package/dist/injector/index.d.ts +36 -11
  53. package/dist/injector/index.js +43 -12
  54. package/dist/injector/index.js.map +1 -1
  55. package/dist/injector/injector.d.ts +62 -3
  56. package/dist/injector/injector.js +293 -46
  57. package/dist/injector/injector.js.map +1 -1
  58. package/dist/injector/sheet-manager.d.ts +22 -17
  59. package/dist/injector/sheet-manager.js +64 -79
  60. package/dist/injector/sheet-manager.js.map +1 -1
  61. package/dist/injector/types.d.ts +121 -21
  62. package/dist/keyframes/index.js +1 -1
  63. package/dist/parser/classify.js +6 -6
  64. package/dist/parser/classify.js.map +1 -1
  65. package/dist/parser/const.js +30 -3
  66. package/dist/parser/const.js.map +1 -1
  67. package/dist/parser/lru.js +1 -1
  68. package/dist/parser/lru.js.map +1 -1
  69. package/dist/parser/parser.js +2 -3
  70. package/dist/parser/parser.js.map +1 -1
  71. package/dist/parser/tokenizer.js +1 -1
  72. package/dist/parser/tokenizer.js.map +1 -1
  73. package/dist/parser/types.js +1 -1
  74. package/dist/parser/types.js.map +1 -1
  75. package/dist/pipeline/conditions.js +15 -9
  76. package/dist/pipeline/conditions.js.map +1 -1
  77. package/dist/pipeline/exclusive.js +58 -4
  78. package/dist/pipeline/exclusive.js.map +1 -1
  79. package/dist/pipeline/index.d.ts +3 -1
  80. package/dist/pipeline/index.js +141 -74
  81. package/dist/pipeline/index.js.map +1 -1
  82. package/dist/pipeline/materialize.js +460 -211
  83. package/dist/pipeline/materialize.js.map +1 -1
  84. package/dist/pipeline/parseStateKey.d.ts +1 -1
  85. package/dist/pipeline/parseStateKey.js +38 -22
  86. package/dist/pipeline/parseStateKey.js.map +1 -1
  87. package/dist/pipeline/simplify.js +289 -156
  88. package/dist/pipeline/simplify.js.map +1 -1
  89. package/dist/pipeline/warnings.js +18 -0
  90. package/dist/pipeline/warnings.js.map +1 -0
  91. package/dist/plugins/index.d.ts +2 -0
  92. package/dist/plugins/okhsl-plugin.js +3 -277
  93. package/dist/plugins/okhsl-plugin.js.map +1 -1
  94. package/dist/plugins/types.d.ts +20 -2
  95. package/dist/properties/index.js +83 -19
  96. package/dist/properties/index.js.map +1 -1
  97. package/dist/properties/property-type-resolver.d.ts +24 -0
  98. package/dist/properties/property-type-resolver.js +90 -0
  99. package/dist/properties/property-type-resolver.js.map +1 -0
  100. package/dist/rsc-cache.js +79 -0
  101. package/dist/rsc-cache.js.map +1 -0
  102. package/dist/ssr/astro-client.d.ts +1 -0
  103. package/dist/ssr/astro-client.js +19 -0
  104. package/dist/ssr/astro-client.js.map +1 -0
  105. package/dist/ssr/astro-middleware.d.ts +15 -0
  106. package/dist/ssr/astro-middleware.js +19 -0
  107. package/dist/ssr/astro-middleware.js.map +1 -0
  108. package/dist/ssr/astro.d.ts +108 -0
  109. package/dist/ssr/astro.js +149 -0
  110. package/dist/ssr/astro.js.map +1 -0
  111. package/dist/ssr/async-storage.d.ts +17 -0
  112. package/dist/ssr/async-storage.js +44 -0
  113. package/dist/ssr/async-storage.js.map +1 -0
  114. package/dist/ssr/collect-auto-properties.js +58 -0
  115. package/dist/ssr/collect-auto-properties.js.map +1 -0
  116. package/dist/ssr/collector.d.ts +98 -0
  117. package/dist/ssr/collector.js +235 -0
  118. package/dist/ssr/collector.js.map +1 -0
  119. package/dist/ssr/context.js +16 -0
  120. package/dist/ssr/context.js.map +1 -0
  121. package/dist/ssr/format-global-rules.js +22 -0
  122. package/dist/ssr/format-global-rules.js.map +1 -0
  123. package/dist/ssr/format-keyframes.js +69 -0
  124. package/dist/ssr/format-keyframes.js.map +1 -0
  125. package/dist/ssr/format-property.js +49 -0
  126. package/dist/ssr/format-property.js.map +1 -0
  127. package/dist/ssr/format-rules.js +73 -0
  128. package/dist/ssr/format-rules.js.map +1 -0
  129. package/dist/ssr/hydrate.d.ts +29 -0
  130. package/dist/ssr/hydrate.js +45 -0
  131. package/dist/ssr/hydrate.js.map +1 -0
  132. package/dist/ssr/index.d.ts +4 -0
  133. package/dist/ssr/index.js +10 -0
  134. package/dist/ssr/index.js.map +1 -0
  135. package/dist/ssr/next.d.ts +46 -0
  136. package/dist/ssr/next.js +75 -0
  137. package/dist/ssr/next.js.map +1 -0
  138. package/dist/ssr/ssr-collector-ref.js +29 -0
  139. package/dist/ssr/ssr-collector-ref.js.map +1 -0
  140. package/dist/states/index.js +13 -259
  141. package/dist/states/index.js.map +1 -1
  142. package/dist/static/index.js +1 -2
  143. package/dist/static/inject.d.ts +5 -0
  144. package/dist/static/inject.js +17 -0
  145. package/dist/static/inject.js.map +1 -0
  146. package/dist/static/tastyStatic.js +1 -2
  147. package/dist/static/tastyStatic.js.map +1 -1
  148. package/dist/static/types.js +1 -1
  149. package/dist/styles/border.d.ts +2 -2
  150. package/dist/styles/border.js +30 -24
  151. package/dist/styles/border.js.map +1 -1
  152. package/dist/styles/color.d.ts +3 -3
  153. package/dist/styles/color.js +11 -8
  154. package/dist/styles/color.js.map +1 -1
  155. package/dist/styles/const.js +17 -0
  156. package/dist/styles/const.js.map +1 -0
  157. package/dist/styles/createStyle.js +29 -27
  158. package/dist/styles/createStyle.js.map +1 -1
  159. package/dist/styles/dimension.js +15 -3
  160. package/dist/styles/dimension.js.map +1 -1
  161. package/dist/styles/directional.js +133 -0
  162. package/dist/styles/directional.js.map +1 -0
  163. package/dist/styles/display.d.ts +3 -10
  164. package/dist/styles/display.js +45 -39
  165. package/dist/styles/display.js.map +1 -1
  166. package/dist/styles/fade.d.ts +2 -2
  167. package/dist/styles/fade.js +9 -5
  168. package/dist/styles/fade.js.map +1 -1
  169. package/dist/styles/fill.d.ts +15 -17
  170. package/dist/styles/fill.js +9 -9
  171. package/dist/styles/fill.js.map +1 -1
  172. package/dist/styles/flow.d.ts +3 -3
  173. package/dist/styles/flow.js +1 -1
  174. package/dist/styles/flow.js.map +1 -1
  175. package/dist/styles/gap.d.ts +1 -1
  176. package/dist/styles/gap.js +4 -3
  177. package/dist/styles/gap.js.map +1 -1
  178. package/dist/styles/height.d.ts +1 -1
  179. package/dist/styles/height.js +1 -2
  180. package/dist/styles/height.js.map +1 -1
  181. package/dist/styles/index.d.ts +0 -1
  182. package/dist/styles/index.js +3 -4
  183. package/dist/styles/index.js.map +1 -1
  184. package/dist/styles/inset.d.ts +1 -29
  185. package/dist/styles/inset.js +19 -135
  186. package/dist/styles/inset.js.map +1 -1
  187. package/dist/styles/list.d.ts +5 -5
  188. package/dist/styles/list.js +4 -2
  189. package/dist/styles/list.js.map +1 -1
  190. package/dist/styles/margin.d.ts +1 -1
  191. package/dist/styles/margin.js +17 -89
  192. package/dist/styles/margin.js.map +1 -1
  193. package/dist/styles/outline.d.ts +1 -1
  194. package/dist/styles/outline.js +6 -16
  195. package/dist/styles/outline.js.map +1 -1
  196. package/dist/styles/padding.d.ts +1 -1
  197. package/dist/styles/padding.js +17 -89
  198. package/dist/styles/padding.js.map +1 -1
  199. package/dist/styles/placement.d.ts +37 -0
  200. package/dist/styles/placement.js +74 -0
  201. package/dist/styles/placement.js.map +1 -0
  202. package/dist/styles/predefined.d.ts +4 -6
  203. package/dist/styles/predefined.js +9 -13
  204. package/dist/styles/predefined.js.map +1 -1
  205. package/dist/styles/preset.d.ts +6 -1
  206. package/dist/styles/preset.js +54 -53
  207. package/dist/styles/preset.js.map +1 -1
  208. package/dist/styles/radius.d.ts +2 -4
  209. package/dist/styles/radius.js +38 -6
  210. package/dist/styles/radius.js.map +1 -1
  211. package/dist/styles/scrollMargin.d.ts +24 -0
  212. package/dist/styles/scrollMargin.js +32 -0
  213. package/dist/styles/scrollMargin.js.map +1 -0
  214. package/dist/styles/scrollbar.d.ts +9 -5
  215. package/dist/styles/scrollbar.js +31 -85
  216. package/dist/styles/scrollbar.js.map +1 -1
  217. package/dist/styles/shadow.d.ts +3 -3
  218. package/dist/styles/shadow.js +4 -3
  219. package/dist/styles/shadow.js.map +1 -1
  220. package/dist/styles/shared.js +17 -0
  221. package/dist/styles/shared.js.map +1 -0
  222. package/dist/styles/transition.d.ts +2 -2
  223. package/dist/styles/transition.js +6 -5
  224. package/dist/styles/transition.js.map +1 -1
  225. package/dist/styles/types.d.ts +94 -28
  226. package/dist/styles/width.d.ts +1 -1
  227. package/dist/styles/width.js +1 -2
  228. package/dist/styles/width.js.map +1 -1
  229. package/dist/tasty.d.ts +46 -894
  230. package/dist/tasty.js +117 -60
  231. package/dist/tasty.js.map +1 -1
  232. package/dist/types.d.ts +3 -3
  233. package/dist/utils/cache-wrapper.js +4 -9
  234. package/dist/utils/cache-wrapper.js.map +1 -1
  235. package/dist/utils/case-converter.js +1 -1
  236. package/dist/utils/color-math.d.ts +46 -0
  237. package/dist/utils/color-math.js +749 -0
  238. package/dist/utils/color-math.js.map +1 -0
  239. package/dist/utils/color-space.d.ts +5 -0
  240. package/dist/utils/color-space.js +228 -0
  241. package/dist/utils/color-space.js.map +1 -0
  242. package/dist/utils/colors.d.ts +1 -1
  243. package/dist/utils/colors.js +3 -2
  244. package/dist/utils/colors.js.map +1 -1
  245. package/dist/utils/css-types.d.ts +1 -1
  246. package/dist/utils/deps-equal.js +15 -0
  247. package/dist/utils/deps-equal.js.map +1 -0
  248. package/dist/utils/dotize.d.ts +1 -1
  249. package/dist/utils/dotize.js +1 -1
  250. package/dist/utils/dotize.js.map +1 -1
  251. package/dist/utils/filter-base-props.d.ts +1 -1
  252. package/dist/utils/filter-base-props.js +1 -1
  253. package/dist/utils/filter-base-props.js.map +1 -1
  254. package/dist/utils/get-display-name.js +1 -1
  255. package/dist/utils/has-keys.js +13 -0
  256. package/dist/utils/has-keys.js.map +1 -0
  257. package/dist/utils/hash.js +14 -0
  258. package/dist/utils/hash.js.map +1 -0
  259. package/dist/utils/is-dev-env.js +1 -1
  260. package/dist/utils/is-dev-env.js.map +1 -1
  261. package/dist/utils/is-valid-element-type.js +1 -1
  262. package/dist/utils/merge-styles.js +1 -2
  263. package/dist/utils/merge-styles.js.map +1 -1
  264. package/dist/utils/mod-attrs.d.ts +0 -2
  265. package/dist/utils/mod-attrs.js +3 -4
  266. package/dist/utils/mod-attrs.js.map +1 -1
  267. package/dist/utils/process-tokens.d.ts +3 -17
  268. package/dist/utils/process-tokens.js +19 -107
  269. package/dist/utils/process-tokens.js.map +1 -1
  270. package/dist/utils/resolve-recipes.js +1 -2
  271. package/dist/utils/resolve-recipes.js.map +1 -1
  272. package/dist/utils/selector-transform.js +32 -0
  273. package/dist/utils/selector-transform.js.map +1 -0
  274. package/dist/utils/string.js +1 -1
  275. package/dist/utils/string.js.map +1 -1
  276. package/dist/utils/styles.d.ts +5 -89
  277. package/dist/utils/styles.js +35 -400
  278. package/dist/utils/styles.js.map +1 -1
  279. package/dist/utils/typography.d.ts +35 -13
  280. package/dist/utils/typography.js +16 -18
  281. package/dist/utils/typography.js.map +1 -1
  282. package/dist/utils/warnings.js +1 -1
  283. package/dist/zero/babel.d.ts +57 -84
  284. package/dist/zero/babel.js +217 -37
  285. package/dist/zero/babel.js.map +1 -1
  286. package/dist/zero/css-writer.js +1 -2
  287. package/dist/zero/css-writer.js.map +1 -1
  288. package/dist/zero/extractor.js +119 -3
  289. package/dist/zero/extractor.js.map +1 -1
  290. package/dist/zero/index.js +1 -2
  291. package/dist/zero/next.d.ts +56 -30
  292. package/dist/zero/next.js +105 -40
  293. package/dist/zero/next.js.map +1 -1
  294. package/docs/PIPELINE.md +519 -0
  295. package/docs/README.md +31 -0
  296. package/docs/adoption.md +298 -0
  297. package/docs/comparison.md +419 -0
  298. package/docs/configuration.md +394 -0
  299. package/docs/debug.md +318 -0
  300. package/docs/design-system.md +436 -0
  301. package/docs/dsl.md +688 -0
  302. package/docs/getting-started.md +217 -0
  303. package/docs/injector.md +544 -0
  304. package/docs/methodology.md +616 -0
  305. package/docs/react-api.md +557 -0
  306. package/docs/ssr.md +442 -0
  307. package/docs/styles.md +596 -0
  308. package/docs/tasty-static.md +532 -0
  309. package/package.json +112 -31
  310. package/dist/styles/align.d.ts +0 -15
  311. package/dist/styles/align.js +0 -14
  312. package/dist/styles/align.js.map +0 -1
  313. package/dist/styles/justify.d.ts +0 -15
  314. package/dist/styles/justify.js +0 -14
  315. package/dist/styles/justify.js.map +0 -1
  316. package/dist/styles/styledScrollbar.d.ts +0 -47
  317. package/dist/styles/styledScrollbar.js +0 -38
  318. package/dist/styles/styledScrollbar.js.map +0 -1
  319. package/dist/tokens/typography.d.ts +0 -19
  320. package/dist/tokens/typography.js +0 -237
  321. package/dist/tokens/typography.js.map +0 -1
  322. package/dist/utils/hsl-to-rgb.js +0 -38
  323. package/dist/utils/hsl-to-rgb.js.map +0 -1
  324. package/dist/utils/okhsl-to-rgb.js +0 -296
  325. package/dist/utils/okhsl-to-rgb.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collector.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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Q,KAAK,OAC5B,KAAI,CAAC,KAAK,eAAe,IAAI,IAAI,EAAE;AACjC,SAAM,KAAK,IAAI;AACf,QAAK,eAAe,IAAI,IAAI;;AAIhC,OAAK,MAAM,CAAC,KAAK,QAAQ,KAAK,aAC5B,KAAI,CAAC,KAAK,kBAAkB,IAAI,IAAI,EAAE;AACpC,SAAM,KAAK,IAAI;AACf,QAAK,kBAAkB,IAAI,IAAI;;AAInC,OAAK,MAAM,CAAC,KAAK,QAAQ,KAAK,OAC5B,KAAI,CAAC,KAAK,YAAY,IAAI,IAAI,EAAE;AAC9B,SAAM,KAAK,IAAI;AACf,QAAK,YAAY,IAAI,IAAI;;AAI7B,OAAK,MAAM,CAAC,MAAM,QAAQ,KAAK,cAC7B,KAAI,CAAC,KAAK,oBAAoB,IAAI,KAAK,EAAE;AACvC,SAAM,KAAK,IAAI;AACf,QAAK,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"}
@@ -0,0 +1,16 @@
1
+ import { createContext } from "react";
2
+ //#region src/ssr/context.ts
3
+ /**
4
+ * React context for SSR collector discovery.
5
+ *
6
+ * Used by Next.js TastyRegistry to provide the ServerStyleCollector
7
+ * to useStyles() via React context (the streaming-compatible path).
8
+ *
9
+ * This avoids relying on globalThis for cross-layer communication,
10
+ * which leaks between RSC and SSR module graphs in Next.js App Router.
11
+ */
12
+ const TastySSRContext = createContext(null);
13
+ //#endregion
14
+ export { TastySSRContext };
15
+
16
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","names":[],"sources":["../../src/ssr/context.ts"],"sourcesContent":["/**\n * React context for SSR collector discovery.\n *\n * Used by Next.js TastyRegistry to provide the ServerStyleCollector\n * to useStyles() via React context (the streaming-compatible path).\n *\n * This avoids relying on globalThis for cross-layer communication,\n * which leaks between RSC and SSR module graphs in Next.js App Router.\n */\n\nimport { createContext } from 'react';\n\nimport type { ServerStyleCollector } from './collector';\n\nexport const TastySSRContext = createContext<ServerStyleCollector | null>(null);\n"],"mappings":";;;;;;;;;;;AAcA,MAAa,kBAAkB,cAA2C,KAAK"}
@@ -0,0 +1,22 @@
1
+ //#region src/ssr/format-global-rules.ts
2
+ /**
3
+ * Format an array of global StyleResult rules into a CSS text string.
4
+ *
5
+ * Rules already have their full selectors applied by renderStyles().
6
+ * Handles rootPrefix prepending and at-rule wrapping.
7
+ */
8
+ function formatGlobalRules(rules) {
9
+ if (rules.length === 0) return "";
10
+ const cssRules = [];
11
+ for (const rule of rules) {
12
+ const baseRule = `${rule.rootPrefix ? `${rule.rootPrefix} ${rule.selector}` : rule.selector} { ${rule.declarations} }`;
13
+ let fullRule = baseRule;
14
+ if (rule.atRules && rule.atRules.length > 0) fullRule = rule.atRules.reduce((css, atRule) => `${atRule} { ${css} }`, baseRule);
15
+ cssRules.push(fullRule);
16
+ }
17
+ return cssRules.join("\n");
18
+ }
19
+ //#endregion
20
+ export { formatGlobalRules };
21
+
22
+ //# sourceMappingURL=format-global-rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-global-rules.js","names":[],"sources":["../../src/ssr/format-global-rules.ts"],"sourcesContent":["/**\n * Format global CSS rules for SSR output.\n *\n * Unlike formatRules() which applies className-based specificity doubling,\n * this function formats rules that already have their full selectors\n * (from renderStyles called with a selector string).\n */\n\nimport type { StyleResult } from '../pipeline';\n\n/**\n * Format an array of global StyleResult rules into a CSS text string.\n *\n * Rules already have their full selectors applied by renderStyles().\n * Handles rootPrefix prepending and at-rule wrapping.\n */\nexport function formatGlobalRules(rules: StyleResult[]): string {\n if (rules.length === 0) return '';\n\n const cssRules: string[] = [];\n\n for (const rule of rules) {\n const selector = rule.rootPrefix\n ? `${rule.rootPrefix} ${rule.selector}`\n : rule.selector;\n\n const baseRule = `${selector} { ${rule.declarations} }`;\n\n let fullRule = baseRule;\n if (rule.atRules && rule.atRules.length > 0) {\n fullRule = rule.atRules.reduce(\n (css, atRule) => `${atRule} { ${css} }`,\n baseRule,\n );\n }\n\n cssRules.push(fullRule);\n }\n\n return cssRules.join('\\n');\n}\n"],"mappings":";;;;;;;AAgBA,SAAgB,kBAAkB,OAA8B;AAC9D,KAAI,MAAM,WAAW,EAAG,QAAO;CAE/B,MAAM,WAAqB,EAAE;AAE7B,MAAK,MAAM,QAAQ,OAAO;EAKxB,MAAM,WAAW,GAJA,KAAK,aAClB,GAAG,KAAK,WAAW,GAAG,KAAK,aAC3B,KAAK,SAEoB,KAAK,KAAK,aAAa;EAEpD,IAAI,WAAW;AACf,MAAI,KAAK,WAAW,KAAK,QAAQ,SAAS,EACxC,YAAW,KAAK,QAAQ,QACrB,KAAK,WAAW,GAAG,OAAO,KAAK,IAAI,KACpC,SACD;AAGH,WAAS,KAAK,SAAS;;AAGzB,QAAO,SAAS,KAAK,KAAK"}
@@ -0,0 +1,69 @@
1
+ import { createStyle } from "../styles/createStyle.js";
2
+ import { STYLE_HANDLER_MAP } from "../styles/index.js";
3
+ //#region src/ssr/format-keyframes.ts
4
+ /**
5
+ * Convert keyframes steps to a CSS string.
6
+ * Replicates SheetManager.stepsToCSS() without the class instance.
7
+ */
8
+ function stepsToCSS(steps) {
9
+ const rules = [];
10
+ for (const [key, value] of Object.entries(steps)) {
11
+ if (typeof value === "string") {
12
+ rules.push(`${key} { ${value.trim()} }`);
13
+ continue;
14
+ }
15
+ const styleMap = value || {};
16
+ const styleNames = Object.keys(styleMap).sort();
17
+ const handlerQueue = [];
18
+ const seenHandlers = /* @__PURE__ */ new Set();
19
+ styleNames.forEach((styleName) => {
20
+ let handlers = STYLE_HANDLER_MAP[styleName];
21
+ if (!handlers) handlers = STYLE_HANDLER_MAP[styleName] = [createStyle(styleName)];
22
+ handlers.forEach((handler) => {
23
+ if (!seenHandlers.has(handler)) {
24
+ seenHandlers.add(handler);
25
+ handlerQueue.push(handler);
26
+ }
27
+ });
28
+ });
29
+ const declarationPairs = [];
30
+ handlerQueue.forEach((handler) => {
31
+ const result = handler(handler.__lookupStyles.reduce((acc, name) => {
32
+ const v = styleMap[name];
33
+ if (v !== void 0) acc[name] = v;
34
+ return acc;
35
+ }, {}));
36
+ if (!result) return;
37
+ (Array.isArray(result) ? result : [result]).forEach((cssMap) => {
38
+ if (!cssMap || typeof cssMap !== "object") return;
39
+ const { $: _$, ...props } = cssMap;
40
+ Object.entries(props).forEach(([prop, val]) => {
41
+ if (val == null || val === "") return;
42
+ if (Array.isArray(val)) val.forEach((v) => {
43
+ if (v != null && v !== "") declarationPairs.push({
44
+ prop,
45
+ value: String(v)
46
+ });
47
+ });
48
+ else declarationPairs.push({
49
+ prop,
50
+ value: String(val)
51
+ });
52
+ });
53
+ });
54
+ });
55
+ const declarations = declarationPairs.map((d) => `${d.prop}: ${d.value}`).join("; ");
56
+ rules.push(`${key} { ${declarations.trim()} }`);
57
+ }
58
+ return rules.join(" ");
59
+ }
60
+ /**
61
+ * Format a @keyframes rule as a CSS string.
62
+ */
63
+ function formatKeyframesCSS(name, steps) {
64
+ return `@keyframes ${name} { ${stepsToCSS(steps)} }`;
65
+ }
66
+ //#endregion
67
+ export { formatKeyframesCSS };
68
+
69
+ //# sourceMappingURL=format-keyframes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-keyframes.js","names":[],"sources":["../../src/ssr/format-keyframes.ts"],"sourcesContent":["/**\n * Format @keyframes CSS rules for SSR output.\n *\n * Replicates the stepsToCSS logic from SheetManager but as a\n * standalone function that doesn't need DOM access.\n */\n\nimport type { KeyframesSteps } from '../injector/types';\nimport { createStyle, STYLE_HANDLER_MAP } from '../styles';\nimport type { CSSMap, StyleHandler, StyleValueStateMap } from '../utils/styles';\n\n/**\n * Convert keyframes steps to a CSS string.\n * Replicates SheetManager.stepsToCSS() without the class instance.\n */\nfunction stepsToCSS(steps: KeyframesSteps): string {\n const rules: string[] = [];\n\n for (const [key, value] of Object.entries(steps)) {\n if (typeof value === 'string') {\n rules.push(`${key} { ${value.trim()} }`);\n continue;\n }\n\n const styleMap = (value || {}) as StyleValueStateMap;\n const styleNames = Object.keys(styleMap).sort();\n const handlerQueue: StyleHandler[] = [];\n const seenHandlers = new Set<StyleHandler>();\n\n styleNames.forEach((styleName) => {\n let handlers = STYLE_HANDLER_MAP[styleName];\n if (!handlers) {\n handlers = STYLE_HANDLER_MAP[styleName] = [createStyle(styleName)];\n }\n\n handlers.forEach((handler) => {\n if (!seenHandlers.has(handler)) {\n seenHandlers.add(handler);\n handlerQueue.push(handler);\n }\n });\n });\n\n const declarationPairs: { prop: string; value: string }[] = [];\n\n handlerQueue.forEach((handler) => {\n const lookup = handler.__lookupStyles;\n const filteredMap = lookup.reduce<StyleValueStateMap>((acc, name) => {\n const v = styleMap[name];\n if (v !== undefined) acc[name] = v;\n return acc;\n }, {});\n\n const result = handler(filteredMap);\n if (!result) return;\n\n const results = Array.isArray(result) ? result : [result];\n results.forEach((cssMap) => {\n if (!cssMap || typeof cssMap !== 'object') return;\n const { $: _$, ...props } = cssMap as CSSMap;\n\n Object.entries(props).forEach(([prop, val]) => {\n if (val == null || val === '') return;\n\n if (Array.isArray(val)) {\n val.forEach((v) => {\n if (v != null && v !== '') {\n declarationPairs.push({ prop, value: String(v) });\n }\n });\n } else {\n declarationPairs.push({ prop, value: String(val) });\n }\n });\n });\n });\n\n const declarations = declarationPairs\n .map((d) => `${d.prop}: ${d.value}`)\n .join('; ');\n\n rules.push(`${key} { ${declarations.trim()} }`);\n }\n\n return rules.join(' ');\n}\n\n/**\n * Format a @keyframes rule as a CSS string.\n */\nexport function formatKeyframesCSS(\n name: string,\n steps: KeyframesSteps,\n): string {\n const cssSteps = stepsToCSS(steps);\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,MAAM,GACrB,kBAAiB,KAAK;OAAE;OAAM,OAAO,OAAO,EAAE;OAAE,CAAC;OAEnD;SAEF,kBAAiB,KAAK;MAAE;MAAM,OAAO,OAAO,IAAI;MAAE,CAAC;MAErD;KACF;IACF;EAEF,MAAM,eAAe,iBAClB,KAAK,MAAM,GAAG,EAAE,KAAK,IAAI,EAAE,QAAQ,CACnC,KAAK,KAAK;AAEb,QAAM,KAAK,GAAG,IAAI,KAAK,aAAa,MAAM,CAAC,IAAI;;AAGjD,QAAO,MAAM,KAAK,IAAI;;;;;AAMxB,SAAgB,mBACd,MACA,OACQ;AAER,QAAO,cAAc,KAAK,KADT,WAAW,MAAM,CACM"}
@@ -0,0 +1,49 @@
1
+ import { colorInitialValueToComponents, getColorSpaceSuffix, getComponentPropertySyntax } from "../utils/color-space.js";
2
+ import { getEffectiveDefinition } from "../properties/index.js";
3
+ import { parseStyle } from "../utils/styles.js";
4
+ //#region src/ssr/format-property.ts
5
+ /**
6
+ * Format a single @property rule as a CSS string.
7
+ *
8
+ * Returns the full `@property --name { ... }` text, or empty string
9
+ * if the token is invalid. For color properties, also returns
10
+ * the companion component property.
11
+ */
12
+ function formatPropertyCSS(token, definition) {
13
+ const result = getEffectiveDefinition(token, definition);
14
+ if (!result.isValid) return "";
15
+ const rules = [];
16
+ rules.push(buildPropertyRule(result.cssName, result.definition));
17
+ if (result.isColor) {
18
+ const suffix = getColorSpaceSuffix();
19
+ const componentCssName = `${result.cssName}-${suffix}`;
20
+ const componentInitial = colorInitialValueToComponents(result.definition.initialValue);
21
+ rules.push(buildPropertyRule(componentCssName, {
22
+ syntax: getComponentPropertySyntax(),
23
+ inherits: result.definition.inherits,
24
+ initialValue: componentInitial
25
+ }));
26
+ }
27
+ return rules.join("\n");
28
+ }
29
+ function buildPropertyRule(cssName, definition) {
30
+ const parts = [];
31
+ if (definition.syntax != null) {
32
+ let syntax = String(definition.syntax).trim();
33
+ if (!/^['"]/u.test(syntax)) syntax = `"${syntax}"`;
34
+ parts.push(`syntax: ${syntax};`);
35
+ }
36
+ const inherits = definition.inherits ?? true;
37
+ parts.push(`inherits: ${inherits ? "true" : "false"};`);
38
+ if (definition.initialValue != null) {
39
+ let initialValueStr;
40
+ if (typeof definition.initialValue === "number") initialValueStr = String(definition.initialValue);
41
+ else initialValueStr = parseStyle(definition.initialValue).output;
42
+ parts.push(`initial-value: ${initialValueStr};`);
43
+ }
44
+ return `@property ${cssName} { ${parts.join(" ").trim()} }`;
45
+ }
46
+ //#endregion
47
+ export { formatPropertyCSS };
48
+
49
+ //# sourceMappingURL=format-property.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-property.js","names":[],"sources":["../../src/ssr/format-property.ts"],"sourcesContent":["/**\n * Format @property CSS rules for SSR output.\n *\n * Replicates the CSS construction from StyleInjector.property()\n * but returns a CSS string instead of inserting into the DOM.\n */\n\nimport type { PropertyDefinition } from '../injector/types';\nimport { getEffectiveDefinition } from '../properties';\nimport {\n colorInitialValueToComponents,\n getColorSpaceSuffix,\n getComponentPropertySyntax,\n} from '../utils/color-space';\nimport type { StyleValue } from '../utils/styles';\nimport { parseStyle } from '../utils/styles';\n\n/**\n * Format a single @property rule as a CSS string.\n *\n * Returns the full `@property --name { ... }` text, or empty string\n * if the token is invalid. For color properties, also returns\n * the companion component property.\n */\nexport function formatPropertyCSS(\n token: string,\n definition: PropertyDefinition,\n): string {\n const result = getEffectiveDefinition(token, definition);\n if (!result.isValid) return '';\n\n const rules: string[] = [];\n\n rules.push(buildPropertyRule(result.cssName, result.definition));\n\n if (result.isColor) {\n const suffix = getColorSpaceSuffix();\n const componentCssName = `${result.cssName}-${suffix}`;\n const componentInitial = colorInitialValueToComponents(\n result.definition.initialValue,\n );\n rules.push(\n buildPropertyRule(componentCssName, {\n syntax: getComponentPropertySyntax(),\n inherits: result.definition.inherits,\n initialValue: componentInitial,\n }),\n );\n }\n\n return rules.join('\\n');\n}\n\nfunction buildPropertyRule(\n cssName: string,\n definition: PropertyDefinition,\n): string {\n const parts: string[] = [];\n\n if (definition.syntax != null) {\n let syntax = String(definition.syntax).trim();\n if (!/^['\"]/u.test(syntax)) syntax = `\"${syntax}\"`;\n parts.push(`syntax: ${syntax};`);\n }\n\n const inherits = definition.inherits ?? true;\n parts.push(`inherits: ${inherits ? 'true' : 'false'};`);\n\n if (definition.initialValue != null) {\n let initialValueStr: string;\n if (typeof definition.initialValue === 'number') {\n initialValueStr = String(definition.initialValue);\n } else {\n initialValueStr = parseStyle(\n definition.initialValue as StyleValue,\n ).output;\n }\n parts.push(`initial-value: ${initialValueStr};`);\n }\n\n const declarations = parts.join(' ').trim();\n return `@property ${cssName} { ${declarations} }`;\n}\n"],"mappings":";;;;;;;;;;;AAwBA,SAAgB,kBACd,OACA,YACQ;CACR,MAAM,SAAS,uBAAuB,OAAO,WAAW;AACxD,KAAI,CAAC,OAAO,QAAS,QAAO;CAE5B,MAAM,QAAkB,EAAE;AAE1B,OAAM,KAAK,kBAAkB,OAAO,SAAS,OAAO,WAAW,CAAC;AAEhE,KAAI,OAAO,SAAS;EAClB,MAAM,SAAS,qBAAqB;EACpC,MAAM,mBAAmB,GAAG,OAAO,QAAQ,GAAG;EAC9C,MAAM,mBAAmB,8BACvB,OAAO,WAAW,aACnB;AACD,QAAM,KACJ,kBAAkB,kBAAkB;GAClC,QAAQ,4BAA4B;GACpC,UAAU,OAAO,WAAW;GAC5B,cAAc;GACf,CAAC,CACH;;AAGH,QAAO,MAAM,KAAK,KAAK;;AAGzB,SAAS,kBACP,SACA,YACQ;CACR,MAAM,QAAkB,EAAE;AAE1B,KAAI,WAAW,UAAU,MAAM;EAC7B,IAAI,SAAS,OAAO,WAAW,OAAO,CAAC,MAAM;AAC7C,MAAI,CAAC,SAAS,KAAK,OAAO,CAAE,UAAS,IAAI,OAAO;AAChD,QAAM,KAAK,WAAW,OAAO,GAAG;;CAGlC,MAAM,WAAW,WAAW,YAAY;AACxC,OAAM,KAAK,aAAa,WAAW,SAAS,QAAQ,GAAG;AAEvD,KAAI,WAAW,gBAAgB,MAAM;EACnC,IAAI;AACJ,MAAI,OAAO,WAAW,iBAAiB,SACrC,mBAAkB,OAAO,WAAW,aAAa;MAEjD,mBAAkB,WAChB,WAAW,aACZ,CAAC;AAEJ,QAAM,KAAK,kBAAkB,gBAAgB,GAAG;;AAIlD,QAAO,aAAa,QAAQ,KADP,MAAM,KAAK,IAAI,CAAC,MAAM,CACG"}
@@ -0,0 +1,73 @@
1
+ //#region src/ssr/format-rules.ts
2
+ /**
3
+ * Resolve selectors for a rule, applying className-based specificity doubling
4
+ * and rootPrefix handling. Mirrors the logic in StyleInjector.inject().
5
+ */
6
+ function resolveSelector(rule, className) {
7
+ let selector = rule.selector;
8
+ if (rule.needsClassName) {
9
+ const selectorParts = selector ? selector.split("|||") : [""];
10
+ const classPrefix = `.${className}.${className}`;
11
+ selector = selectorParts.map((part) => {
12
+ const classSelector = part ? `${classPrefix}${part}` : classPrefix;
13
+ if (rule.rootPrefix) return `${rule.rootPrefix} ${classSelector}`;
14
+ return classSelector;
15
+ }).join(", ");
16
+ }
17
+ return selector;
18
+ }
19
+ /**
20
+ * Group rules by selector + at-rules + startingStyle and merge their declarations.
21
+ * Mirrors the grouping logic in SheetManager.insertRule().
22
+ */
23
+ function groupRules(rules) {
24
+ const groupMap = /* @__PURE__ */ new Map();
25
+ const order = [];
26
+ const atKey = (at) => at && at.length ? at.join("|") : "";
27
+ for (const r of rules) {
28
+ const key = `${atKey(r.atRules)}||${r.selector}||${r.startingStyle ? "1" : "0"}`;
29
+ const existing = groupMap.get(key);
30
+ if (existing) existing.declarations = existing.declarations ? `${existing.declarations} ${r.declarations}` : r.declarations;
31
+ else {
32
+ groupMap.set(key, {
33
+ selector: r.selector,
34
+ atRules: r.atRules,
35
+ startingStyle: r.startingStyle,
36
+ declarations: r.declarations
37
+ });
38
+ order.push(key);
39
+ }
40
+ }
41
+ return order.map((key) => groupMap.get(key));
42
+ }
43
+ /**
44
+ * Format an array of StyleResult rules into a CSS text string.
45
+ *
46
+ * Applies className-based specificity doubling (.cls.cls),
47
+ * groups rules by selector + at-rules, and wraps with at-rule blocks.
48
+ *
49
+ * Produces the same CSS text as SheetManager.insertRule() would insert
50
+ * into the DOM, but as a plain string suitable for SSR output.
51
+ */
52
+ function formatRules(rules, className) {
53
+ if (rules.length === 0) return "";
54
+ const grouped = groupRules(rules.map((rule) => ({
55
+ selector: resolveSelector(rule, className),
56
+ declarations: rule.declarations,
57
+ atRules: rule.atRules,
58
+ startingStyle: rule.startingStyle
59
+ })));
60
+ const cssRules = [];
61
+ for (const rule of grouped) {
62
+ const innerContent = rule.startingStyle ? `@starting-style { ${rule.declarations} }` : rule.declarations;
63
+ const baseRule = `${rule.selector} { ${innerContent} }`;
64
+ let fullRule = baseRule;
65
+ if (rule.atRules && rule.atRules.length > 0) fullRule = rule.atRules.reduce((css, atRule) => `${atRule} { ${css} }`, baseRule);
66
+ cssRules.push(fullRule);
67
+ }
68
+ return cssRules.join("\n");
69
+ }
70
+ //#endregion
71
+ export { formatRules };
72
+
73
+ //# sourceMappingURL=format-rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-rules.js","names":[],"sources":["../../src/ssr/format-rules.ts"],"sourcesContent":["/**\n * Shared CSS rule formatting utility.\n *\n * Extracted from SheetManager to allow both the DOM-based injector (client)\n * and the ServerStyleCollector (server) to produce identical CSS text\n * from StyleResult arrays.\n */\n\nimport type { StyleResult } from '../pipeline';\n\n/**\n * Resolve selectors for a rule, applying className-based specificity doubling\n * and rootPrefix handling. Mirrors the logic in StyleInjector.inject().\n */\nfunction resolveSelector(rule: StyleResult, className: string): string {\n let selector = rule.selector;\n\n if (rule.needsClassName) {\n const selectorParts = selector ? selector.split('|||') : [''];\n const classPrefix = `.${className}.${className}`;\n\n selector = selectorParts\n .map((part) => {\n const classSelector = part ? `${classPrefix}${part}` : classPrefix;\n\n if (rule.rootPrefix) {\n return `${rule.rootPrefix} ${classSelector}`;\n }\n return classSelector;\n })\n .join(', ');\n }\n\n return selector;\n}\n\ninterface GroupedRule {\n selector: string;\n declarations: string;\n atRules?: string[];\n startingStyle?: boolean;\n}\n\n/**\n * Group rules by selector + at-rules + startingStyle and merge their declarations.\n * Mirrors the grouping logic in SheetManager.insertRule().\n */\nfunction groupRules(rules: GroupedRule[]): GroupedRule[] {\n const groupMap = new Map<string, GroupedRule>();\n const order: string[] = [];\n\n const atKey = (at?: string[]) => (at && at.length ? at.join('|') : '');\n\n for (const r of rules) {\n const key = `${atKey(r.atRules)}||${r.selector}||${r.startingStyle ? '1' : '0'}`;\n const existing = groupMap.get(key);\n if (existing) {\n existing.declarations = existing.declarations\n ? `${existing.declarations} ${r.declarations}`\n : r.declarations;\n } else {\n groupMap.set(key, {\n selector: r.selector,\n atRules: r.atRules,\n startingStyle: r.startingStyle,\n declarations: r.declarations,\n });\n order.push(key);\n }\n }\n\n return order.map((key) => groupMap.get(key)!);\n}\n\n/**\n * Format an array of StyleResult rules into a CSS text string.\n *\n * Applies className-based specificity doubling (.cls.cls),\n * groups rules by selector + at-rules, and wraps with at-rule blocks.\n *\n * Produces the same CSS text as SheetManager.insertRule() would insert\n * into the DOM, but as a plain string suitable for SSR output.\n */\nexport function formatRules(rules: StyleResult[], className: string): string {\n if (rules.length === 0) return '';\n\n const resolvedRules = rules.map((rule) => ({\n selector: resolveSelector(rule, className),\n declarations: rule.declarations,\n atRules: rule.atRules,\n startingStyle: rule.startingStyle,\n }));\n\n const grouped = groupRules(resolvedRules);\n const cssRules: string[] = [];\n\n for (const rule of grouped) {\n const innerContent = rule.startingStyle\n ? `@starting-style { ${rule.declarations} }`\n : rule.declarations;\n const baseRule = `${rule.selector} { ${innerContent} }`;\n\n let fullRule = baseRule;\n if (rule.atRules && rule.atRules.length > 0) {\n fullRule = rule.atRules.reduce(\n (css, atRule) => `${atRule} { ${css} }`,\n baseRule,\n );\n }\n\n cssRules.push(fullRule);\n }\n\n return cssRules.join('\\n');\n}\n"],"mappings":";;;;;AAcA,SAAS,gBAA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S;EAC1B,MAAM,eAAe,KAAK,gBACtB,qBAAqB,KAAK,aAAa,MACvC,KAAK;EACT,MAAM,WAAW,GAAG,KAAK,SAAS,KAAK,aAAa;EAEpD,IAAI,WAAW;AACf,MAAI,KAAK,WAAW,KAAK,QAAQ,SAAS,EACxC,YAAW,KAAK,QAAQ,QACrB,KAAK,WAAW,GAAG,OAAO,KAAK,IAAI,KACpC,SACD;AAGH,WAAS,KAAK,SAAS;;AAGzB,QAAO,SAAS,KAAK,KAAK"}
@@ -0,0 +1,29 @@
1
+ //#region src/ssr/hydrate.d.ts
2
+ /**
3
+ * Client-side cache hydration for SSR/RSC.
4
+ *
5
+ * Pre-populates the client injector's rules map with class names
6
+ * rendered on the server. With hash-based naming, the client derives
7
+ * the same class name from the same cache key, so only the class name
8
+ * list needs to cross the wire — no cache keys or counters.
9
+ */
10
+ /**
11
+ * Pre-populate the client-side style registry from the server's class name list.
12
+ *
13
+ * Call this before ReactDOM.hydrateRoot() or ensure it runs before
14
+ * any tasty() component renders on the client.
15
+ *
16
+ * When called without arguments, reads the class list from `window.__TASTY__`
17
+ * (populated by inline scripts emitted during SSR/RSC streaming).
18
+ */
19
+ declare function hydrateTastyClasses(classes?: string[]): void;
20
+ /**
21
+ * @deprecated Use `hydrateTastyClasses()` instead. This alias exists
22
+ * for backwards compatibility and will be removed in a future major version.
23
+ */
24
+ declare function hydrateTastyCache(state?: {
25
+ entries?: Record<string, string>;
26
+ }): void;
27
+ //#endregion
28
+ export { hydrateTastyCache, hydrateTastyClasses };
29
+ //# sourceMappingURL=hydrate.d.ts.map
@@ -0,0 +1,45 @@
1
+ import { getGlobalInjector } from "../config.js";
2
+ //#region src/ssr/hydrate.ts
3
+ /**
4
+ * Client-side cache hydration for SSR/RSC.
5
+ *
6
+ * Pre-populates the client injector's rules map with class names
7
+ * rendered on the server. With hash-based naming, the client derives
8
+ * the same class name from the same cache key, so only the class name
9
+ * list needs to cross the wire — no cache keys or counters.
10
+ */
11
+ /**
12
+ * Pre-populate the client-side style registry from the server's class name list.
13
+ *
14
+ * Call this before ReactDOM.hydrateRoot() or ensure it runs before
15
+ * any tasty() component renders on the client.
16
+ *
17
+ * When called without arguments, reads the class list from `window.__TASTY__`
18
+ * (populated by inline scripts emitted during SSR/RSC streaming).
19
+ */
20
+ function hydrateTastyClasses(classes) {
21
+ if (typeof document === "undefined") return;
22
+ if (!classes) classes = typeof window !== "undefined" ? window.__TASTY__ : void 0;
23
+ if (!classes?.length) return;
24
+ const registry = getGlobalInjector()._sheetManager.getRegistry(document);
25
+ for (const cls of classes) if (!registry.rules.has(cls)) {
26
+ registry.rules.set(cls, {
27
+ className: cls,
28
+ ruleIndex: -2,
29
+ sheetIndex: -2
30
+ });
31
+ registry.refCounts.set(cls, 0);
32
+ }
33
+ }
34
+ /**
35
+ * @deprecated Use `hydrateTastyClasses()` instead. This alias exists
36
+ * for backwards compatibility and will be removed in a future major version.
37
+ */
38
+ function hydrateTastyCache(state) {
39
+ if (state?.entries) hydrateTastyClasses(Object.values(state.entries));
40
+ else hydrateTastyClasses();
41
+ }
42
+ //#endregion
43
+ export { hydrateTastyCache, hydrateTastyClasses };
44
+
45
+ //# sourceMappingURL=hydrate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hydrate.js","names":[],"sources":["../../src/ssr/hydrate.ts"],"sourcesContent":["/**\n * Client-side cache hydration for SSR/RSC.\n *\n * Pre-populates the client injector's rules map with class names\n * rendered on the server. With hash-based naming, the client derives\n * the same class name from the same cache key, so only the class name\n * list needs to cross the wire — no cache keys or counters.\n */\n\nimport { getGlobalInjector } from '../config';\nimport { HYDRATED_RULE_INDEX } from '../injector/types';\n\n/**\n * Pre-populate the client-side style registry from the server's class name list.\n *\n * Call this before ReactDOM.hydrateRoot() or ensure it runs before\n * any tasty() component renders on the client.\n *\n * When called without arguments, reads the class list from `window.__TASTY__`\n * (populated by inline scripts emitted during SSR/RSC streaming).\n */\nexport function hydrateTastyClasses(classes?: string[]): void {\n if (typeof document === 'undefined') return;\n\n if (!classes) {\n classes = typeof window !== 'undefined' ? window.__TASTY__ : undefined;\n }\n\n if (!classes?.length) return;\n\n const injector = getGlobalInjector();\n const registry = injector._sheetManager.getRegistry(document);\n\n for (const cls of classes) {\n if (!registry.rules.has(cls)) {\n registry.rules.set(cls, {\n className: cls,\n ruleIndex: HYDRATED_RULE_INDEX,\n sheetIndex: HYDRATED_RULE_INDEX,\n });\n registry.refCounts.set(cls, 0);\n }\n }\n}\n\n/**\n * @deprecated Use `hydrateTastyClasses()` instead. This alias exists\n * for backwards compatibility and will be removed in a future major version.\n */\nexport function hydrateTastyCache(state?: {\n entries?: Record<string, string>;\n}): void {\n if (state?.entries) {\n hydrateTastyClasses(Object.values(state.entries));\n } else {\n hydrateTastyClasses();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,oBAAoB,SAA0B;AAC5D,KAAI,OAAO,aAAa,YAAa;AAErC,KAAI,CAAC,QACH,WAAU,OAAO,WAAW,cAAc,OAAO,YAAY,KAAA;AAG/D,KAAI,CAAC,SAAS,OAAQ;CAGtB,MAAM,WADW,mBAAmB,CACV,cAAc,YAAY,SAAS;AAE7D,MAAK,MAAM,OAAO,QAChB,KAAI,CAAC,SAAS,MAAM,IAAI,IAAI,EAAE;AAC5B,WAAS,MAAM,IAAI,KAAK;GACtB,WAAW;GACX,WAAA;GACA,YAAA;GACD,CAAC;AACF,WAAS,UAAU,IAAI,KAAK,EAAE;;;;;;;AASpC,SAAgB,kBAAkB,OAEzB;AACP,KAAI,OAAO,QACT,qBAAoB,OAAO,OAAO,MAAM,QAAQ,CAAC;KAEjD,sBAAqB"}
@@ -0,0 +1,4 @@
1
+ import { ServerStyleCollector } from "./collector.js";
2
+ import { getSSRCollector, runWithCollector } from "./async-storage.js";
3
+ import { hydrateTastyCache, hydrateTastyClasses } from "./hydrate.js";
4
+ export { ServerStyleCollector, getSSRCollector, hydrateTastyCache, hydrateTastyClasses, runWithCollector };
@@ -0,0 +1,10 @@
1
+ import { registerSSRCollectorGetterGlobal } from "./ssr-collector-ref.js";
2
+ import { ServerStyleCollector } from "./collector.js";
3
+ import { getSSRCollector, runWithCollector } from "./async-storage.js";
4
+ import { hydrateTastyCache, hydrateTastyClasses } from "./hydrate.js";
5
+ //#region src/ssr/index.ts
6
+ registerSSRCollectorGetterGlobal(getSSRCollector);
7
+ //#endregion
8
+ export { ServerStyleCollector, getSSRCollector, hydrateTastyCache, hydrateTastyClasses, runWithCollector };
9
+
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/ssr/index.ts"],"sourcesContent":["/**\n * SSR entry point for @tenphi/tasty.\n *\n * Provides the core SSR infrastructure: ServerStyleCollector,\n * AsyncLocalStorage integration, and cache hydration.\n *\n * Import from '@tenphi/tasty/ssr'.\n */\n\n// Core collector\nexport { ServerStyleCollector } from './collector';\n\n// AsyncLocalStorage integration for Astro / generic frameworks\nexport { runWithCollector, getSSRCollector } from './async-storage';\n\n// Client-side cache hydration\nexport { hydrateTastyClasses, hydrateTastyCache } from './hydrate';\n\n// Register the ALS getter so hooks can find the collector\n// without importing 'node:async_hooks' in the browser bundle.\n// Uses globalThis so the getter is visible across separate module graphs.\nimport { getSSRCollector } from './async-storage';\nimport { registerSSRCollectorGetterGlobal } from './ssr-collector-ref';\n\nregisterSSRCollectorGetterGlobal(getSSRCollector);\n"],"mappings":";;;;;AAwBA,iCAAiC,gBAAgB"}
@@ -0,0 +1,46 @@
1
+ import { ServerStyleCollector } from "./collector.js";
2
+ import * as _$react from "react";
3
+ import { ReactNode } from "react";
4
+
5
+ //#region src/ssr/next.d.ts
6
+ interface TastyRegistryProps {
7
+ children: ReactNode;
8
+ /**
9
+ * Whether to embed the class-list script for client hydration.
10
+ * Set to false to skip class transfer (e.g. for CSP restrictions).
11
+ * Without it, client components may re-inject CSS that already exists
12
+ * in server-rendered `<style>` tags. Default: true.
13
+ */
14
+ transferCache?: boolean;
15
+ }
16
+ /**
17
+ * Next.js App Router registry for Tasty SSR.
18
+ *
19
+ * Wraps the component tree with a ServerStyleCollector and flushes
20
+ * collected CSS into the HTML stream via useServerInsertedHTML.
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * // app/tasty-registry.tsx
25
+ * 'use client';
26
+ * import { TastyRegistry } from '@tenphi/tasty/ssr/next';
27
+ * export default function TastyStyleRegistry({ children }) {
28
+ * return <TastyRegistry>{children}</TastyRegistry>;
29
+ * }
30
+ *
31
+ * // app/layout.tsx
32
+ * import TastyStyleRegistry from './tasty-registry';
33
+ * export default function RootLayout({ children }) {
34
+ * return <html><body>
35
+ * <TastyStyleRegistry>{children}</TastyStyleRegistry>
36
+ * </body></html>;
37
+ * }
38
+ * ```
39
+ */
40
+ declare function TastyRegistry({
41
+ children,
42
+ transferCache
43
+ }: TastyRegistryProps): _$react.FunctionComponentElement<_$react.ProviderProps<ServerStyleCollector | null>>;
44
+ //#endregion
45
+ export { TastyRegistry, TastyRegistryProps };
46
+ //# sourceMappingURL=next.d.ts.map
@@ -0,0 +1,75 @@
1
+ "use client";
2
+ import { getConfig } from "../config.js";
3
+ import { registerSSRCollectorGetter } from "./ssr-collector-ref.js";
4
+ import { TastySSRContext } from "./context.js";
5
+ import { ServerStyleCollector } from "./collector.js";
6
+ import { hydrateTastyClasses } from "./hydrate.js";
7
+ import { Fragment, createElement, useState } from "react";
8
+ import { useServerInsertedHTML } from "next/navigation";
9
+ //#region src/ssr/next.ts
10
+ /**
11
+ * Next.js integration for Tasty SSR.
12
+ *
13
+ * Provides TastyRegistry for App Router (streaming via useServerInsertedHTML)
14
+ * and createTastySSRDocument for Pages Router (non-streaming).
15
+ *
16
+ * Import from '@tenphi/tasty/ssr/next'.
17
+ */
18
+ if (typeof window !== "undefined") hydrateTastyClasses();
19
+ /**
20
+ * Next.js App Router registry for Tasty SSR.
21
+ *
22
+ * Wraps the component tree with a ServerStyleCollector and flushes
23
+ * collected CSS into the HTML stream via useServerInsertedHTML.
24
+ *
25
+ * @example
26
+ * ```tsx
27
+ * // app/tasty-registry.tsx
28
+ * 'use client';
29
+ * import { TastyRegistry } from '@tenphi/tasty/ssr/next';
30
+ * export default function TastyStyleRegistry({ children }) {
31
+ * return <TastyRegistry>{children}</TastyRegistry>;
32
+ * }
33
+ *
34
+ * // app/layout.tsx
35
+ * import TastyStyleRegistry from './tasty-registry';
36
+ * export default function RootLayout({ children }) {
37
+ * return <html><body>
38
+ * <TastyStyleRegistry>{children}</TastyStyleRegistry>
39
+ * </body></html>;
40
+ * }
41
+ * ```
42
+ */
43
+ function TastyRegistry({ children, transferCache = true }) {
44
+ const isClient = typeof window !== "undefined";
45
+ const [collector] = useState(() => {
46
+ if (isClient) return null;
47
+ const instance = new ServerStyleCollector();
48
+ registerSSRCollectorGetter(() => instance);
49
+ return instance;
50
+ });
51
+ const nonce = getConfig().nonce;
52
+ useServerInsertedHTML(() => {
53
+ if (!collector) return null;
54
+ const css = collector.flushCSS();
55
+ const classNames = collector.getRenderedClassNames();
56
+ if (!css) return null;
57
+ const styleEl = createElement("style", {
58
+ key: "tasty-ssr-styles",
59
+ "data-tasty-ssr": "",
60
+ nonce,
61
+ dangerouslySetInnerHTML: { __html: css }
62
+ });
63
+ if (!transferCache || classNames.length === 0) return styleEl;
64
+ return createElement(Fragment, null, styleEl, createElement("script", {
65
+ key: "tasty-ssr-cache",
66
+ nonce,
67
+ dangerouslySetInnerHTML: { __html: `(window.__TASTY__=window.__TASTY__||[]).push(${classNames.map((n) => `"${n}"`).join(",")})` }
68
+ }));
69
+ });
70
+ return createElement(TastySSRContext.Provider, { value: collector }, children);
71
+ }
72
+ //#endregion
73
+ export { TastyRegistry };
74
+
75
+ //# sourceMappingURL=next.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next.js","names":[],"sources":["../../src/ssr/next.ts"],"sourcesContent":["/**\n * Next.js integration for Tasty SSR.\n *\n * Provides TastyRegistry for App Router (streaming via useServerInsertedHTML)\n * and createTastySSRDocument for Pages Router (non-streaming).\n *\n * Import from '@tenphi/tasty/ssr/next'.\n */\n\n'use client';\n\n/// <reference path=\"./next-navigation.d.ts\" />\n\nimport { createElement, Fragment, useState, type ReactNode } from 'react';\nimport { useServerInsertedHTML } from 'next/navigation';\n\nimport { getConfig } from '../config';\nimport { ServerStyleCollector } from './collector';\nimport { TastySSRContext } from './context';\nimport { hydrateTastyClasses } from './hydrate';\nimport { registerSSRCollectorGetter } from './ssr-collector-ref';\n\n// Auto-hydrate on module load (client only).\n// Reads the class name list from `window.__TASTY__` populated by streaming scripts.\nif (typeof window !== 'undefined') {\n hydrateTastyClasses();\n}\n\nexport interface TastyRegistryProps {\n children: ReactNode;\n /**\n * Whether to embed the class-list script for client hydration.\n * Set to false to skip class transfer (e.g. for CSP restrictions).\n * Without it, client components may re-inject CSS that already exists\n * in server-rendered `<style>` tags. Default: true.\n */\n transferCache?: boolean;\n}\n\n/**\n * Next.js App Router registry for Tasty SSR.\n *\n * Wraps the component tree with a ServerStyleCollector and flushes\n * collected CSS into the HTML stream via useServerInsertedHTML.\n *\n * @example\n * ```tsx\n * // app/tasty-registry.tsx\n * 'use client';\n * import { TastyRegistry } from '@tenphi/tasty/ssr/next';\n * export default function TastyStyleRegistry({ children }) {\n * return <TastyRegistry>{children}</TastyRegistry>;\n * }\n *\n * // app/layout.tsx\n * import TastyStyleRegistry from './tasty-registry';\n * export default function RootLayout({ children }) {\n * return <html><body>\n * <TastyStyleRegistry>{children}</TastyStyleRegistry>\n * </body></html>;\n * }\n * ```\n */\nexport function TastyRegistry({\n children,\n transferCache = true,\n}: TastyRegistryProps) {\n const isClient = typeof window !== 'undefined';\n\n const [collector] = useState(() => {\n if (isClient) return null;\n\n const instance = new ServerStyleCollector();\n\n registerSSRCollectorGetter(() => instance);\n\n return instance;\n });\n const nonce = getConfig().nonce;\n\n useServerInsertedHTML(() => {\n if (!collector) return null;\n\n const css = collector.flushCSS();\n const classNames = collector.getRenderedClassNames();\n\n if (!css) return null;\n\n const styleEl = createElement('style', {\n key: 'tasty-ssr-styles',\n 'data-tasty-ssr': '',\n nonce,\n dangerouslySetInnerHTML: { __html: css },\n });\n\n if (!transferCache || classNames.length === 0) return styleEl;\n\n const classListJSON = classNames.map((n) => `\"${n}\"`).join(',');\n\n const scriptEl = createElement('script', {\n key: 'tasty-ssr-cache',\n nonce,\n dangerouslySetInnerHTML: {\n __html: `(window.__TASTY__=window.__TASTY__||[]).push(${classListJSON})`,\n },\n });\n\n return createElement(Fragment, null, styleEl, scriptEl);\n });\n\n return createElement(\n TastySSRContext.Provider,\n { value: collector },\n children,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwBA,IAAI,OAAO,WAAW,YACpB,sBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;AAsCvB,SAAgB,cAAc,EAC5B,UACA,gBAAgB,QACK;CACrB,MAAM,WAAW,OAAO,WAAW;CAEnC,MAAM,CAAC,aAAa,eAAe;AACjC,MAAI,SAAU,QAAO;EAErB,MAAM,WAAW,IAAI,sBAAsB;AAE3C,mCAAiC,SAAS;AAE1C,SAAO;GACP;CACF,MAAM,QAAQ,WAAW,CAAC;AAE1B,6BAA4B;AAC1B,MAAI,CAAC,UAAW,QAAO;EAEvB,MAAM,MAAM,UAAU,UAAU;EAChC,MAAM,aAAa,UAAU,uBAAuB;AAEpD,MAAI,CAAC,IAAK,QAAO;EAEjB,MAAM,UAAU,cAAc,SAAS;GACrC,KAAK;GACL,kBAAkB;GAClB;GACA,yBAAyB,EAAE,QAAQ,KAAK;GACzC,CAAC;AAEF,MAAI,CAAC,iBAAiB,WAAW,WAAW,EAAG,QAAO;AAYtD,SAAO,cAAc,UAAU,MAAM,SARpB,cAAc,UAAU;GACvC,KAAK;GACL;GACA,yBAAyB,EACvB,QAAQ,gDANU,WAAW,KAAK,MAAM,IAAI,EAAE,GAAG,CAAC,KAAK,IAAI,CAMW,IACvE;GACF,CAAC,CAEqD;GACvD;AAEF,QAAO,cACL,gBAAgB,UAChB,EAAE,OAAO,WAAW,EACpB,SACD"}
@@ -0,0 +1,29 @@
1
+ //#region src/ssr/ssr-collector-ref.ts
2
+ const GETTER_KEY = "__tasty_ssr_collector_getter__";
3
+ let _getSSRCollector = null;
4
+ /**
5
+ * Register the collector getter in the current module graph only.
6
+ * Used by Next.js TastyRegistry.
7
+ */
8
+ function registerSSRCollectorGetter(fn) {
9
+ _getSSRCollector = fn;
10
+ }
11
+ /**
12
+ * Register the collector getter on globalThis so it is visible across
13
+ * separate module graphs (e.g. Astro middleware ↔ page components).
14
+ */
15
+ function registerSSRCollectorGetterGlobal(fn) {
16
+ globalThis[GETTER_KEY] = fn;
17
+ }
18
+ /**
19
+ * Retrieve the SSR collector: module-level first, globalThis fallback.
20
+ */
21
+ function getRegisteredSSRCollector() {
22
+ if (_getSSRCollector) return _getSSRCollector();
23
+ const getter = globalThis[GETTER_KEY];
24
+ return getter ? getter() : null;
25
+ }
26
+ //#endregion
27
+ export { getRegisteredSSRCollector, registerSSRCollectorGetter, registerSSRCollectorGetterGlobal };
28
+
29
+ //# sourceMappingURL=ssr-collector-ref.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssr-collector-ref.js","names":[],"sources":["../../src/ssr/ssr-collector-ref.ts"],"sourcesContent":["/**\n * Global reference to the SSR collector getter function.\n *\n * This indirection avoids importing 'node:async_hooks' in the browser bundle.\n * The SSR entry point sets this ref when loaded on the server. The useStyles\n * hook calls it if set; on the client it stays null and is never called.\n *\n * Uses a module-level variable as the primary mechanism. In Next.js App\n * Router the RSC and SSR module graphs load separate copies of this module,\n * so the getter registered by TastyRegistry (SSR layer) is invisible to\n * server components (RSC layer) — which correctly fall through to inline\n * RSC styles.\n *\n * A globalThis fallback (`registerSSRCollectorGetterGlobal`) is provided\n * for frameworks like Astro where middleware and page components live in\n * different module graphs and must share the getter across them.\n */\n\nimport type { ServerStyleCollector } from './collector';\n\ntype SSRCollectorGetter = () => ServerStyleCollector | null;\n\nconst GETTER_KEY = '__tasty_ssr_collector_getter__';\n\nlet _getSSRCollector: SSRCollectorGetter | null = null;\n\n/**\n * Register the collector getter in the current module graph only.\n * Used by Next.js TastyRegistry.\n */\nexport function registerSSRCollectorGetter(fn: SSRCollectorGetter): void {\n _getSSRCollector = fn;\n}\n\n/**\n * Register the collector getter on globalThis so it is visible across\n * separate module graphs (e.g. Astro middleware ↔ page components).\n */\nexport function registerSSRCollectorGetterGlobal(fn: SSRCollectorGetter): void {\n (globalThis as Record<string, unknown>)[GETTER_KEY] = fn;\n}\n\n/**\n * Retrieve the SSR collector: module-level first, globalThis fallback.\n */\nexport function getRegisteredSSRCollector(): ServerStyleCollector | null {\n if (_getSSRCollector) return _getSSRCollector();\n const getter = (globalThis as Record<string, unknown>)[GETTER_KEY] as\n | SSRCollectorGetter\n | undefined;\n return getter ? getter() : null;\n}\n"],"mappings":";AAsBA,MAAM,aAAa;AAEnB,IAAI,mBAA8C;;;;;AAMlD,SAAgB,2BAA2B,IAA8B;AACvE,oBAAmB;;;;;;AAOrB,SAAgB,iCAAiC,IAA8B;AAC5E,YAAuC,cAAc;;;;;AAMxD,SAAgB,4BAAyD;AACvE,KAAI,iBAAkB,QAAO,kBAAkB;CAC/C,MAAM,SAAU,WAAuC;AAGvD,QAAO,SAAS,QAAQ,GAAG"}