@tenphi/tasty 0.0.0-snapshot.fa94a5a → 0.0.0-snapshot.fc19da9

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 (372) hide show
  1. package/README.md +437 -362
  2. package/dist/babel-types-DpUCD2L_.d.ts +18 -0
  3. package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
  4. package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
  5. package/dist/chunks/build-config-BDLYGmKn.js +60 -0
  6. package/dist/chunks/build-config-BDLYGmKn.js.map +1 -0
  7. package/dist/chunks/collector-DqcB0UUT.js +210 -0
  8. package/dist/chunks/collector-DqcB0UUT.js.map +1 -0
  9. package/dist/chunks/config-engine-CGIMO2PV.js +272 -0
  10. package/dist/chunks/config-engine-CGIMO2PV.js.map +1 -0
  11. package/dist/chunks/config-file-DlZXJMj8.js +25 -0
  12. package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
  13. package/dist/chunks/css-definitions-BibU6ZnP.js +904 -0
  14. package/dist/chunks/css-definitions-BibU6ZnP.js.map +1 -0
  15. package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
  16. package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
  17. package/dist/{debug.js → chunks/debug-BzYPQ0H2.js} +197 -149
  18. package/dist/chunks/debug-BzYPQ0H2.js.map +1 -0
  19. package/dist/chunks/dsl-DRhFWQzo.js +1378 -0
  20. package/dist/chunks/dsl-DRhFWQzo.js.map +1 -0
  21. package/dist/chunks/hydration-TRcz5vnk.js +41 -0
  22. package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
  23. package/dist/chunks/react-runtime-B2e-Wha-.js +689 -0
  24. package/dist/chunks/react-runtime-B2e-Wha-.js.map +1 -0
  25. package/dist/chunks/runtime-engine-yeyCAx2e.js +2431 -0
  26. package/dist/chunks/runtime-engine-yeyCAx2e.js.map +1 -0
  27. package/dist/chunks/runtime-state-C0u1jp-Q.js +141 -0
  28. package/dist/chunks/runtime-state-C0u1jp-Q.js.map +1 -0
  29. package/dist/{utils/merge-styles.js → chunks/shared-utils-y-HjvPN4.js} +61 -58
  30. package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
  31. package/dist/chunks/style-engine-D35rvcdB.js +5420 -0
  32. package/dist/chunks/style-engine-D35rvcdB.js.map +1 -0
  33. package/dist/chunks/zero-engine-DpkieEPZ.js +310 -0
  34. package/dist/chunks/zero-engine-DpkieEPZ.js.map +1 -0
  35. package/dist/collector-D4POJ53X.d.ts +164 -0
  36. package/dist/config-DvPUj4cw.d.ts +1364 -0
  37. package/dist/core/index.d.ts +5 -34
  38. package/dist/core/index.js +9 -27
  39. package/dist/hydrate-CRyjjAyl.d.ts +22 -0
  40. package/dist/index-DC4q-xDq.d.ts +1946 -0
  41. package/dist/index.d.ts +5 -51
  42. package/dist/index.js +11 -36
  43. package/dist/{utils/merge-styles.d.ts → merge-styles-Jb5iZ-Jf.d.ts} +3 -4
  44. package/dist/ssr/astro-client.d.ts +1 -0
  45. package/dist/ssr/astro-client.js +6 -0
  46. package/dist/ssr/astro-client.js.map +1 -0
  47. package/dist/ssr/astro-middleware-extract-static.d.ts +10 -0
  48. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  49. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  50. package/dist/ssr/astro-middleware-extract.d.ts +10 -0
  51. package/dist/ssr/astro-middleware-extract.js +9 -0
  52. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  53. package/dist/ssr/astro-middleware-static.d.ts +17 -0
  54. package/dist/ssr/astro-middleware-static.js +7 -0
  55. package/dist/ssr/astro-middleware-static.js.map +1 -0
  56. package/dist/ssr/astro-middleware.d.ts +18 -0
  57. package/dist/ssr/astro-middleware.js +7 -0
  58. package/dist/ssr/astro-middleware.js.map +1 -0
  59. package/dist/ssr/astro.d.ts +110 -12
  60. package/dist/ssr/astro.js +206 -50
  61. package/dist/ssr/astro.js.map +1 -1
  62. package/dist/ssr/client.d.ts +2 -0
  63. package/dist/ssr/client.js +2 -0
  64. package/dist/ssr/index.d.ts +17 -5
  65. package/dist/ssr/index.js +7 -9
  66. package/dist/ssr/index.js.map +1 -1
  67. package/dist/ssr/next-config.d.ts +64 -0
  68. package/dist/ssr/next-config.js +123 -0
  69. package/dist/ssr/next-config.js.map +1 -0
  70. package/dist/ssr/next.d.ts +13 -12
  71. package/dist/ssr/next.js +40 -51
  72. package/dist/ssr/next.js.map +1 -1
  73. package/dist/static/index.d.ts +90 -5
  74. package/dist/static/index.js +31 -4
  75. package/dist/static/index.js.map +1 -0
  76. package/dist/static/inject.d.ts +4 -0
  77. package/dist/static/inject.js +17 -0
  78. package/dist/static/inject.js.map +1 -0
  79. package/dist/types-ZbF2_6LV.d.ts +1567 -0
  80. package/dist/zero/babel.d.ts +20 -120
  81. package/dist/zero/babel.js +189 -148
  82. package/dist/zero/babel.js.map +1 -1
  83. package/dist/zero/index.d.ts +117 -3
  84. package/dist/zero/index.js +23 -3
  85. package/dist/zero/index.js.map +1 -0
  86. package/dist/zero/next.d.ts +16 -5
  87. package/dist/zero/next.js +8 -42
  88. package/dist/zero/next.js.map +1 -1
  89. package/docs/README.md +23 -12
  90. package/docs/adoption.md +72 -37
  91. package/docs/ai-agents.md +252 -0
  92. package/docs/comparison.md +83 -54
  93. package/docs/configuration.md +698 -81
  94. package/docs/debug.md +39 -24
  95. package/docs/design-system.md +174 -41
  96. package/docs/dsl.md +615 -197
  97. package/docs/getting-started.md +132 -52
  98. package/docs/injector.md +195 -90
  99. package/docs/methodology.md +153 -47
  100. package/docs/migration-v3.md +285 -0
  101. package/docs/pipeline.md +768 -0
  102. package/docs/plugins.md +333 -0
  103. package/docs/react-api.md +703 -0
  104. package/docs/runtime-benchmarks.md +388 -0
  105. package/docs/ssr.md +395 -149
  106. package/docs/styles.md +194 -45
  107. package/docs/tasty-static.md +327 -101
  108. package/package.json +153 -35
  109. package/tasty.config.ts +6 -0
  110. package/dist/_virtual/_rolldown/runtime.js +0 -8
  111. package/dist/chunks/cacheKey.js +0 -78
  112. package/dist/chunks/cacheKey.js.map +0 -1
  113. package/dist/chunks/definitions.d.ts +0 -37
  114. package/dist/chunks/definitions.js +0 -259
  115. package/dist/chunks/definitions.js.map +0 -1
  116. package/dist/chunks/renderChunk.js +0 -60
  117. package/dist/chunks/renderChunk.js.map +0 -1
  118. package/dist/config.d.ts +0 -366
  119. package/dist/config.js +0 -504
  120. package/dist/config.js.map +0 -1
  121. package/dist/counter-style/index.js +0 -51
  122. package/dist/counter-style/index.js.map +0 -1
  123. package/dist/debug.d.ts +0 -89
  124. package/dist/debug.js.map +0 -1
  125. package/dist/font-face/index.js +0 -63
  126. package/dist/font-face/index.js.map +0 -1
  127. package/dist/hooks/resolve-ssr-collector.js +0 -15
  128. package/dist/hooks/resolve-ssr-collector.js.map +0 -1
  129. package/dist/hooks/useCounterStyle.d.ts +0 -50
  130. package/dist/hooks/useCounterStyle.js +0 -47
  131. package/dist/hooks/useCounterStyle.js.map +0 -1
  132. package/dist/hooks/useFontFace.d.ts +0 -43
  133. package/dist/hooks/useFontFace.js +0 -71
  134. package/dist/hooks/useFontFace.js.map +0 -1
  135. package/dist/hooks/useGlobalStyles.d.ts +0 -30
  136. package/dist/hooks/useGlobalStyles.js +0 -79
  137. package/dist/hooks/useGlobalStyles.js.map +0 -1
  138. package/dist/hooks/useKeyframes.d.ts +0 -56
  139. package/dist/hooks/useKeyframes.js +0 -65
  140. package/dist/hooks/useKeyframes.js.map +0 -1
  141. package/dist/hooks/useProperty.d.ts +0 -79
  142. package/dist/hooks/useProperty.js +0 -110
  143. package/dist/hooks/useProperty.js.map +0 -1
  144. package/dist/hooks/useRawCSS.d.ts +0 -53
  145. package/dist/hooks/useRawCSS.js +0 -36
  146. package/dist/hooks/useRawCSS.js.map +0 -1
  147. package/dist/hooks/useStyles.d.ts +0 -45
  148. package/dist/hooks/useStyles.js +0 -270
  149. package/dist/hooks/useStyles.js.map +0 -1
  150. package/dist/injector/index.d.ts +0 -183
  151. package/dist/injector/index.js +0 -180
  152. package/dist/injector/index.js.map +0 -1
  153. package/dist/injector/injector.d.ts +0 -166
  154. package/dist/injector/injector.js +0 -465
  155. package/dist/injector/injector.js.map +0 -1
  156. package/dist/injector/sheet-manager.d.ts +0 -136
  157. package/dist/injector/sheet-manager.js +0 -731
  158. package/dist/injector/sheet-manager.js.map +0 -1
  159. package/dist/injector/types.d.ts +0 -204
  160. package/dist/keyframes/index.js +0 -206
  161. package/dist/keyframes/index.js.map +0 -1
  162. package/dist/parser/classify.js +0 -320
  163. package/dist/parser/classify.js.map +0 -1
  164. package/dist/parser/const.js +0 -33
  165. package/dist/parser/const.js.map +0 -1
  166. package/dist/parser/lru.js +0 -109
  167. package/dist/parser/lru.js.map +0 -1
  168. package/dist/parser/parser.d.ts +0 -25
  169. package/dist/parser/parser.js +0 -116
  170. package/dist/parser/parser.js.map +0 -1
  171. package/dist/parser/tokenizer.js +0 -69
  172. package/dist/parser/tokenizer.js.map +0 -1
  173. package/dist/parser/types.d.ts +0 -51
  174. package/dist/parser/types.js +0 -46
  175. package/dist/parser/types.js.map +0 -1
  176. package/dist/pipeline/conditions.d.ts +0 -134
  177. package/dist/pipeline/conditions.js +0 -406
  178. package/dist/pipeline/conditions.js.map +0 -1
  179. package/dist/pipeline/exclusive.js +0 -231
  180. package/dist/pipeline/exclusive.js.map +0 -1
  181. package/dist/pipeline/index.d.ts +0 -53
  182. package/dist/pipeline/index.js +0 -699
  183. package/dist/pipeline/index.js.map +0 -1
  184. package/dist/pipeline/materialize.js +0 -1105
  185. package/dist/pipeline/materialize.js.map +0 -1
  186. package/dist/pipeline/parseStateKey.d.ts +0 -15
  187. package/dist/pipeline/parseStateKey.js +0 -447
  188. package/dist/pipeline/parseStateKey.js.map +0 -1
  189. package/dist/pipeline/simplify.js +0 -516
  190. package/dist/pipeline/simplify.js.map +0 -1
  191. package/dist/pipeline/warnings.js +0 -18
  192. package/dist/pipeline/warnings.js.map +0 -1
  193. package/dist/plugins/okhsl-plugin.d.ts +0 -35
  194. package/dist/plugins/okhsl-plugin.js +0 -98
  195. package/dist/plugins/okhsl-plugin.js.map +0 -1
  196. package/dist/plugins/types.d.ts +0 -76
  197. package/dist/properties/index.js +0 -223
  198. package/dist/properties/index.js.map +0 -1
  199. package/dist/properties/property-type-resolver.d.ts +0 -24
  200. package/dist/properties/property-type-resolver.js +0 -91
  201. package/dist/properties/property-type-resolver.js.map +0 -1
  202. package/dist/ssr/async-storage.d.ts +0 -17
  203. package/dist/ssr/async-storage.js +0 -35
  204. package/dist/ssr/async-storage.js.map +0 -1
  205. package/dist/ssr/collect-auto-properties.js +0 -40
  206. package/dist/ssr/collect-auto-properties.js.map +0 -1
  207. package/dist/ssr/collector.d.ts +0 -102
  208. package/dist/ssr/collector.js +0 -227
  209. package/dist/ssr/collector.js.map +0 -1
  210. package/dist/ssr/context.d.ts +0 -8
  211. package/dist/ssr/context.js +0 -14
  212. package/dist/ssr/context.js.map +0 -1
  213. package/dist/ssr/format-global-rules.js +0 -22
  214. package/dist/ssr/format-global-rules.js.map +0 -1
  215. package/dist/ssr/format-keyframes.js +0 -70
  216. package/dist/ssr/format-keyframes.js.map +0 -1
  217. package/dist/ssr/format-property.js +0 -50
  218. package/dist/ssr/format-property.js.map +0 -1
  219. package/dist/ssr/format-rules.js +0 -70
  220. package/dist/ssr/format-rules.js.map +0 -1
  221. package/dist/ssr/hydrate.d.ts +0 -22
  222. package/dist/ssr/hydrate.js +0 -50
  223. package/dist/ssr/hydrate.js.map +0 -1
  224. package/dist/ssr/ssr-collector-ref.js +0 -12
  225. package/dist/ssr/ssr-collector-ref.js.map +0 -1
  226. package/dist/states/index.d.ts +0 -49
  227. package/dist/states/index.js +0 -171
  228. package/dist/states/index.js.map +0 -1
  229. package/dist/static/tastyStatic.d.ts +0 -46
  230. package/dist/static/tastyStatic.js +0 -31
  231. package/dist/static/tastyStatic.js.map +0 -1
  232. package/dist/static/types.d.ts +0 -49
  233. package/dist/static/types.js +0 -24
  234. package/dist/static/types.js.map +0 -1
  235. package/dist/styles/align.d.ts +0 -15
  236. package/dist/styles/align.js +0 -14
  237. package/dist/styles/align.js.map +0 -1
  238. package/dist/styles/border.d.ts +0 -25
  239. package/dist/styles/border.js +0 -114
  240. package/dist/styles/border.js.map +0 -1
  241. package/dist/styles/color.d.ts +0 -14
  242. package/dist/styles/color.js +0 -27
  243. package/dist/styles/color.js.map +0 -1
  244. package/dist/styles/createStyle.js +0 -80
  245. package/dist/styles/createStyle.js.map +0 -1
  246. package/dist/styles/dimension.js +0 -97
  247. package/dist/styles/dimension.js.map +0 -1
  248. package/dist/styles/display.d.ts +0 -37
  249. package/dist/styles/display.js +0 -67
  250. package/dist/styles/display.js.map +0 -1
  251. package/dist/styles/fade.d.ts +0 -15
  252. package/dist/styles/fade.js +0 -58
  253. package/dist/styles/fade.js.map +0 -1
  254. package/dist/styles/fill.d.ts +0 -42
  255. package/dist/styles/fill.js +0 -52
  256. package/dist/styles/fill.js.map +0 -1
  257. package/dist/styles/flow.d.ts +0 -16
  258. package/dist/styles/flow.js +0 -12
  259. package/dist/styles/flow.js.map +0 -1
  260. package/dist/styles/gap.d.ts +0 -31
  261. package/dist/styles/gap.js +0 -37
  262. package/dist/styles/gap.js.map +0 -1
  263. package/dist/styles/height.d.ts +0 -17
  264. package/dist/styles/height.js +0 -20
  265. package/dist/styles/height.js.map +0 -1
  266. package/dist/styles/index.d.ts +0 -2
  267. package/dist/styles/index.js +0 -9
  268. package/dist/styles/index.js.map +0 -1
  269. package/dist/styles/inset.d.ts +0 -52
  270. package/dist/styles/inset.js +0 -150
  271. package/dist/styles/inset.js.map +0 -1
  272. package/dist/styles/justify.d.ts +0 -15
  273. package/dist/styles/justify.js +0 -14
  274. package/dist/styles/justify.js.map +0 -1
  275. package/dist/styles/list.d.ts +0 -16
  276. package/dist/styles/list.js +0 -98
  277. package/dist/styles/list.js.map +0 -1
  278. package/dist/styles/margin.d.ts +0 -24
  279. package/dist/styles/margin.js +0 -104
  280. package/dist/styles/margin.js.map +0 -1
  281. package/dist/styles/outline.d.ts +0 -29
  282. package/dist/styles/outline.js +0 -65
  283. package/dist/styles/outline.js.map +0 -1
  284. package/dist/styles/padding.d.ts +0 -24
  285. package/dist/styles/padding.js +0 -104
  286. package/dist/styles/padding.js.map +0 -1
  287. package/dist/styles/predefined.d.ts +0 -71
  288. package/dist/styles/predefined.js +0 -238
  289. package/dist/styles/predefined.js.map +0 -1
  290. package/dist/styles/preset.d.ts +0 -47
  291. package/dist/styles/preset.js +0 -112
  292. package/dist/styles/preset.js.map +0 -1
  293. package/dist/styles/radius.d.ts +0 -14
  294. package/dist/styles/radius.js +0 -51
  295. package/dist/styles/radius.js.map +0 -1
  296. package/dist/styles/scrollbar.d.ts +0 -25
  297. package/dist/styles/scrollbar.js +0 -48
  298. package/dist/styles/scrollbar.js.map +0 -1
  299. package/dist/styles/shadow.d.ts +0 -14
  300. package/dist/styles/shadow.js +0 -24
  301. package/dist/styles/shadow.js.map +0 -1
  302. package/dist/styles/transition.d.ts +0 -14
  303. package/dist/styles/transition.js +0 -158
  304. package/dist/styles/transition.js.map +0 -1
  305. package/dist/styles/types.d.ts +0 -545
  306. package/dist/styles/width.d.ts +0 -17
  307. package/dist/styles/width.js +0 -20
  308. package/dist/styles/width.js.map +0 -1
  309. package/dist/tasty.d.ts +0 -119
  310. package/dist/tasty.js +0 -232
  311. package/dist/tasty.js.map +0 -1
  312. package/dist/types.d.ts +0 -184
  313. package/dist/utils/cache-wrapper.js +0 -22
  314. package/dist/utils/cache-wrapper.js.map +0 -1
  315. package/dist/utils/case-converter.js +0 -8
  316. package/dist/utils/case-converter.js.map +0 -1
  317. package/dist/utils/color-math.d.ts +0 -46
  318. package/dist/utils/color-math.js +0 -749
  319. package/dist/utils/color-math.js.map +0 -1
  320. package/dist/utils/color-space.d.ts +0 -5
  321. package/dist/utils/color-space.js +0 -229
  322. package/dist/utils/color-space.js.map +0 -1
  323. package/dist/utils/colors.d.ts +0 -5
  324. package/dist/utils/colors.js +0 -11
  325. package/dist/utils/colors.js.map +0 -1
  326. package/dist/utils/css-types.d.ts +0 -7
  327. package/dist/utils/dotize.d.ts +0 -26
  328. package/dist/utils/dotize.js +0 -122
  329. package/dist/utils/dotize.js.map +0 -1
  330. package/dist/utils/filter-base-props.d.ts +0 -15
  331. package/dist/utils/filter-base-props.js +0 -45
  332. package/dist/utils/filter-base-props.js.map +0 -1
  333. package/dist/utils/get-display-name.d.ts +0 -7
  334. package/dist/utils/get-display-name.js +0 -10
  335. package/dist/utils/get-display-name.js.map +0 -1
  336. package/dist/utils/has-keys.js +0 -13
  337. package/dist/utils/has-keys.js.map +0 -1
  338. package/dist/utils/is-dev-env.js +0 -19
  339. package/dist/utils/is-dev-env.js.map +0 -1
  340. package/dist/utils/is-valid-element-type.js +0 -15
  341. package/dist/utils/is-valid-element-type.js.map +0 -1
  342. package/dist/utils/merge-styles.js.map +0 -1
  343. package/dist/utils/mod-attrs.d.ts +0 -8
  344. package/dist/utils/mod-attrs.js +0 -21
  345. package/dist/utils/mod-attrs.js.map +0 -1
  346. package/dist/utils/process-tokens.d.ts +0 -21
  347. package/dist/utils/process-tokens.js +0 -91
  348. package/dist/utils/process-tokens.js.map +0 -1
  349. package/dist/utils/resolve-recipes.d.ts +0 -17
  350. package/dist/utils/resolve-recipes.js +0 -147
  351. package/dist/utils/resolve-recipes.js.map +0 -1
  352. package/dist/utils/selector-transform.js +0 -32
  353. package/dist/utils/selector-transform.js.map +0 -1
  354. package/dist/utils/string.js +0 -8
  355. package/dist/utils/string.js.map +0 -1
  356. package/dist/utils/styles.d.ts +0 -101
  357. package/dist/utils/styles.js +0 -223
  358. package/dist/utils/styles.js.map +0 -1
  359. package/dist/utils/typography.d.ts +0 -47
  360. package/dist/utils/typography.js +0 -43
  361. package/dist/utils/typography.js.map +0 -1
  362. package/dist/utils/warnings.d.ts +0 -16
  363. package/dist/utils/warnings.js +0 -16
  364. package/dist/utils/warnings.js.map +0 -1
  365. package/dist/zero/css-writer.d.ts +0 -45
  366. package/dist/zero/css-writer.js +0 -74
  367. package/dist/zero/css-writer.js.map +0 -1
  368. package/dist/zero/extractor.d.ts +0 -24
  369. package/dist/zero/extractor.js +0 -267
  370. package/dist/zero/extractor.js.map +0 -1
  371. package/docs/PIPELINE.md +0 -519
  372. package/docs/runtime.md +0 -485
package/docs/ssr.md CHANGED
@@ -1,35 +1,41 @@
1
1
  # Server-Side Rendering (SSR)
2
2
 
3
- Tasty supports server-side rendering with zero-cost client hydration. This does **not** introduce a separate styling engine: SSR uses the same runtime `tasty()` pipeline you already use on the client, then adds server-side CSS collection and client-side cache hydration. Your existing `tasty()` components work unchanged, and SSR remains opt-in with no per-component modifications. For the broader docs map, see the [Docs Hub](README.md).
3
+ Tasty supports server-side rendering with zero-cost client hydration. This does **not** introduce a separate styling engine: `tasty()` uses the same rendering pipeline on the server and in the browser, while the SSR integrations add server-side CSS collection and client-side cache hydration. Your existing `tasty()` components work unchanged, and SSR remains opt-in with no per-component modifications. For the broader docs map, see the [Docs Hub](README.md).
4
+
5
+ ## Zero-runtime terminology
6
+
7
+ Zero-runtime delivery is an outcome, not an alias for `tastyStatic()`. When `tasty()` components render only on the server, their CSS is delivered with the HTML and no Tasty styling runtime is shipped to the browser. Astro's `tastyIntegration({ islands: false })` is the explicit integration for this setup. Server-only Next.js React Server Components follow the same architecture, although you should verify the generated output for your deployment.
8
+
9
+ `tastyStatic()` reaches the same client-side outcome by extracting CSS during the build instead of during React rendering. Use it when extraction must happen before rendering or when the consumer is not React; see [Build-Time Extraction](tasty-static.md).
4
10
 
5
11
  ---
6
12
 
7
13
  ## Requirements
8
14
 
9
- | Dependency | Version | Required for |
10
- |---|---|---|
11
- | `react` | >= 18 | All SSR entry points (matches the current peer dependency of `@tenphi/tasty`) |
12
- | `next` | >= 13 | Next.js integration (`@tenphi/tasty/ssr/next`) — App Router with `useServerInsertedHTML` |
13
- | Node.js | >= 20 | Generic / streaming SSR (`@tenphi/tasty/ssr`) — uses `node:async_hooks` for `AsyncLocalStorage` |
15
+ | Dependency | Version | Required for |
16
+ | ---------- | ------- | ----------------------------------------------------------------------------------------------- |
17
+ | `react` | >= 18 | All SSR entry points (matches the current peer dependency of `@tenphi/tasty`) |
18
+ | `next` | >= 14 | Next.js integration (`@tenphi/tasty/ssr/next`) — App Router with `useServerInsertedHTML` |
19
+ | Node.js | >= 20 | Generic / streaming SSR (`@tenphi/tasty/ssr`) — uses `node:async_hooks` for `AsyncLocalStorage` |
14
20
 
15
- The Astro integration (`@tenphi/tasty/ssr/astro`) has no additional dependencies beyond `react`.
21
+ The Astro integration (`@tenphi/tasty/ssr/astro`) needs `@astrojs/react`. Like `@tenphi/tasty/ssr`, it imports `node:async_hooks`, so the server runtime must provide it. `css: { mode: 'extract' }` requires Astro 5 or newer.
16
22
 
17
23
  ---
18
24
 
19
25
  ## How It Works
20
26
 
21
- When the environment can execute runtime React code during server rendering, the same `tasty()` and `useStyles()` calls can run there too. In Next.js, generic React SSR, and Astro islands, Tasty simply changes where that runtime-generated CSS goes: `useStyles()` detects a `ServerStyleCollector` and collects CSS into it instead of trying to access the DOM. The collector accumulates all styles, serializes them as `<style>` tags and a cache state script in the HTML. On the client, `hydrateTastyCache()` pre-populates the injector cache so that `useStyles()` skips the rendering pipeline entirely during hydration.
27
+ `tasty()` components are hook-free and use `computeStyles()` internally — a synchronous, framework-agnostic function. On the server, `computeStyles()` discovers a `ServerStyleCollector` via a registered getter (module-level for Next.js, `globalThis` for Astro/generic frameworks using `AsyncLocalStorage`) and collects CSS into it instead of trying to access the DOM. On the client, CSS is injected synchronously into the DOM during render; the injector's content-based cache makes this idempotent. The collector accumulates all styles and serializes them as `<style>` tags plus a class-list script in the HTML. On the client, `hydrateTastyClasses()` pre-populates the injector's rules map with the rendered class names so that `computeStyles()` skips the rendering pipeline entirely during hydration.
22
28
 
23
29
  ```
24
30
  Server Client
25
31
  ────── ──────
26
- tasty() renders hydrateTastyCache() pre-populates cache
27
- └─ useStyles() └─ cacheKey → className map ready
32
+ tasty() renders hydrateTastyClasses() reads window.__TASTY__
33
+ └─ computeStyles() └─ marks rendered class names as already-in-DOM
28
34
  └─ collector.collect()
29
35
  tasty() renders
30
- After render: └─ useStyles()
31
- <style data-tasty-ssr> └─ cache hit → skip pipeline
32
- <script data-tasty-cache> └─ no CSS re-injection
36
+ After render: └─ computeStyles()
37
+ <style data-tasty-ssr> └─ class name known → skip pipeline
38
+ <script> (pushes to __TASTY__) └─ no CSS re-injection
33
39
  ```
34
40
 
35
41
  ---
@@ -80,17 +86,115 @@ export default function RootLayout({
80
86
 
81
87
  That's it. All `tasty()` components inside the tree automatically get SSR support. No per-component changes needed.
82
88
 
89
+ ### Optional shared globals stylesheet
90
+
91
+ By default, configured global CSS is included in the streamed Tasty style tag
92
+ for every route. `withTastyNext()` can move that stable CSS into one
93
+ content-hashed stylesheet shared by all routes while leaving component and hook
94
+ styles in the normal streaming path.
95
+
96
+ Keep the Tasty config in a side-effect-free module:
97
+
98
+ ```ts
99
+ // app/tasty.config.ts
100
+ import type { TastyConfig } from '@tenphi/tasty';
101
+
102
+ const config: TastyConfig = {
103
+ tokens: { $gap: '8px', '#brand': 'rebeccapurple' },
104
+ globalStyles: { body: { margin: '0', color: '#brand' } },
105
+ fontFaces: {
106
+ Brand: { src: 'url("/fonts/brand.woff2") format("woff2")' },
107
+ },
108
+ };
109
+
110
+ export default config;
111
+ ```
112
+
113
+ Use it from the Next config:
114
+
115
+ ```ts
116
+ // next.config.ts
117
+ import { withTastyNext } from '@tenphi/tasty/ssr/next-config';
118
+ import config from './app/tasty.config';
119
+
120
+ export default withTastyNext({
121
+ config,
122
+ })({
123
+ // your Next.js config
124
+ });
125
+ ```
126
+
127
+ The runtime must receive the same config. Import and configure it before the
128
+ registry renders:
129
+
130
+ ```tsx
131
+ // app/tasty-registry.tsx
132
+ 'use client';
133
+
134
+ import { configure } from '@tenphi/tasty';
135
+ import { TastyRegistry } from '@tenphi/tasty/ssr/next';
136
+ import config from './tasty.config';
137
+
138
+ configure(config);
139
+
140
+ export default function TastyStyleRegistry({
141
+ children,
142
+ }: {
143
+ children: React.ReactNode;
144
+ }) {
145
+ return <TastyRegistry>{children}</TastyRegistry>;
146
+ }
147
+ ```
148
+
149
+ The generated file contains eager configuration artifacts: built-in and custom
150
+ `@property` rules, tokens and presets, `@font-face`, `@counter-style`, native
151
+ CSS `@function` definitions, and `globalStyles`. Route-dependent component
152
+ rules and calls to `useGlobalStyles`, `useRawCSS`, `useKeyframes`,
153
+ `useProperty`, `useFontFace`, `useCounterStyle`, and `useFunction` remain
154
+ route-specific. Configured keyframes referenced by `globalStyles` are included in the file; all
155
+ other configured keyframes stay lazy and stream only when a route references
156
+ them.
157
+
158
+ The default output directory is `public/_tasty`. The wrapper adds the generated
159
+ URL to `TastyRegistry`, respects `basePath`, preserves existing `env` and
160
+ `headers` config, and serves the content-hashed file with an immutable one-year
161
+ cache header on Next server deployments. Static exports keep the content-hashed
162
+ URL and leave cache headers to the hosting provider. Older hashes are not
163
+ deleted automatically, so rolling deployments cannot break pages from the
164
+ previous build; clean the generated directory as part of a clean deployment if
165
+ needed. Page-relative CSS resources such as
166
+ `url(../fonts/brand.woff2)` are rejected because moving them would change their
167
+ meaning; use root-relative, absolute, or data URLs.
168
+
169
+ `withTastyNext()` options:
170
+
171
+ | Option | Type | Default | Description |
172
+ | ------------ | ------------- | ------------------------- | ---------------------------------------------------------------------- |
173
+ | `config` | `TastyConfig` | — | Config object; takes precedence over `configFile` |
174
+ | `configFile` | `string` | — | Project-relative config module path; requires the optional `jiti` peer |
175
+ | `rootDir` | `string` | current directory | Next app root when the build runs from a monorepo root |
176
+ | `outputDir` | `string` | `public/_tasty` | Filesystem output directory |
177
+ | `publicPath` | `string` | inferred from `outputDir` | Root-relative URL; required when output is outside `public` |
178
+ | `enabled` | `boolean` | `true` | Disable generation without changing wrapper composition |
179
+
83
180
  ### How it works
84
181
 
85
- - `TastyRegistry` is a `'use client'` component, but Next.js still server-renders it on initial page load.
86
- - During SSR, `useStyles()` finds the collector via React context and pushes CSS rules to it.
87
- - `TastyRegistry` uses `useServerInsertedHTML` to flush collected CSS into the HTML stream as `<style data-tasty-ssr>` tags. This is fully streaming-compatible -- styles are injected alongside each Suspense boundary as it resolves.
88
- - A companion `<script>` tag transfers the `cacheKey → className` mapping to the client.
89
- - When the module loads on the client, `hydrateTastyCache()` runs automatically and pre-populates the injector cache. During hydration, `useStyles()` hits the cache and skips the entire pipeline.
182
+ - `TastyRegistry` is a `'use client'` component, but Next.js still server-renders it on initial page load. The `'use client'` boundary is required solely to access `useServerInsertedHTML` — **not** because `tasty()` components need the client.
183
+ - During SSR, `TastyRegistry` creates a `ServerStyleCollector` and registers it via a module-level getter (not `globalThis` — this avoids leaking between Next.js's separate RSC and SSR module graphs). It also wraps children in a React context provider so that hooks inside the SSR tree can discover the collector. All style functions — `tasty()` components, `computeStyles()`, `useStyles()`, `useGlobalStyles()`, `useRawCSS()`, `useKeyframes()`, `useProperty()`, `useFontFace()`, `useCounterStyle()`, and `useFunction()` — discover the collector through the module-level getter or context provider.
184
+ - `TastyRegistry` uses `useServerInsertedHTML` to flush collected CSS into the HTML stream as `<style data-tasty-ssr>` tags. This is fully streaming-compatible — styles are injected alongside each Suspense boundary as it resolves.
185
+ - A companion inline `<script>` tag pushes the rendered class names into `window.__TASTY__` for each flush. This streaming-friendly approach accumulates the class list incrementally as Suspense boundaries resolve.
186
+ - When the `@tenphi/tasty/ssr/next` module loads on the client, `hydrateTastyClasses()` runs automatically from `window.__TASTY__` and pre-populates the injector's rules map. During hydration, `computeStyles()` sees the class name is already registered and skips the entire pipeline.
187
+
188
+ ### Using Tasty in Server Components
189
+
190
+ Every Tasty style function except `useStyles()` is hook-free and needs no `'use client'`, so it can be used directly in React Server Components:
90
191
 
91
- ### Using tasty() in Server Components
192
+ - `tasty()` components — dynamic `styleProps` like `<Grid flow="column">` work normally
193
+ - `computeStyles()` — the hook-free equivalent of `useStyles()`, which reads React context and cannot run in a Server Component
194
+ - `useGlobalStyles()`, `useRawCSS()` — inject styles by selector
195
+ - `useKeyframes()`, `useProperty()`, `useFontFace()`, `useCounterStyle()`, `useFunction()` — inject ancillary CSS rules
92
196
 
93
- `tasty()` components use React hooks internally, so they require `'use client'`. However, this does **not** prevent them from being used in Server Component pages. In Next.js, `'use client'` components are still server-rendered on initial load. Dynamic `styleProps` like `<Grid flow="column">` work normally when a `tasty()` component is imported into a Server Component page.
197
+ Next.js renders Server Components in a separate module graph that cannot see the collector `TastyRegistry` registers, so their CSS takes the RSC inline path: it is accumulated in a per-request `React.cache` and emitted as an inline `<style>` tag by the next `tasty()` component in the tree. Standalone style functions cannot emit CSS on their own, so make sure a `tasty()` component renders after them in every RSC tree. The RSC path does not emit configured globals (tokens, `@property`, `globalStyles`); those come from `TastyRegistry`'s collector or the `withTastyNext()` shared stylesheet. For the same reason, import the module that calls `configure()` from `app/layout.tsx` as well as from the registry module, so the RSC graph sees the same states, recipes, and units.
94
198
 
95
199
  ### Options
96
200
 
@@ -104,30 +208,31 @@ That's it. All `tasty()` components inside the tree automatically get SSR suppor
104
208
  If your app uses Content Security Policy with nonces, configure it before rendering:
105
209
 
106
210
  ```tsx
107
- // app/layout.tsx or a server-side init file
211
+ // app/tasty-registry.tsx: the 'use client' module that renders TastyRegistry
108
212
  import { configure } from '@tenphi/tasty';
109
213
 
110
214
  configure({ nonce: 'your-nonce-value' });
111
215
  ```
112
216
 
113
- The nonce is automatically applied to all `<style>` and `<script>` tags injected by `TastyRegistry`.
217
+ The nonce is automatically applied to all `<style>` and `<script>` tags injected by `TastyRegistry`. Call it in the module that renders `TastyRegistry`; `app/layout.tsx` is a Server Component and configures a separate module instance.
114
218
 
115
219
  ---
116
220
 
117
221
  ## Astro
118
222
 
119
- ### 1. Add the middleware
223
+ Tasty offers several levels of Astro integration. Choose the one that matches your needs:
120
224
 
121
- Create or update your Astro middleware:
122
-
123
- ```ts
124
- // src/middleware.ts
125
- import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
225
+ | Setup | Config needed | Deduplication | Hooks work | Client JS |
226
+ | ---------------------------------------------------------------- | ------------- | ----------------------------------- | --------------------------------- | -------------- |
227
+ | Zero setup | None | None (each element inlines its CSS) | No (style functions emit nothing) | None |
228
+ | `tastyIntegration({ islands: false })` | One line | Cross-tree | Yes | None |
229
+ | `tastyIntegration()` | One line | Cross-tree | Yes | Auto-hydration |
230
+ | `tastyIntegration({ css: { mode: 'extract' } })` | One line | Cross-tree and cross-page | Yes | Auto-hydration |
231
+ | `tastyIntegration({ islands: false, css: { mode: 'extract' } })` | One line | Cross-tree and cross-page | Yes | None |
126
232
 
127
- export const onRequest = tastyMiddleware();
128
- ```
233
+ ### Zero setup (static pages)
129
234
 
130
- ### 2. Use tasty() components as normal
235
+ `tasty()` components work in Astro with **no configuration**. Each component emits its own inline `<style>` tag during server rendering via the RSC inline path. Just import and use:
131
236
 
132
237
  ```tsx
133
238
  // src/components/Card.tsx
@@ -153,146 +258,257 @@ import Card from '../components/Card.tsx';
153
258
 
154
259
  <html>
155
260
  <body>
156
- <Card>Static card — styles collected by middleware</Card>
157
- <Card client:load>Island card — styles hydrated on client</Card>
261
+ <Card>Styled with zero setup</Card>
158
262
  </body>
159
263
  </html>
160
264
  ```
161
265
 
162
- ### How it works
266
+ **Trade-offs**: Astro renders React with the standard `react` build, where `React.cache` does nothing, so there is no per-request style cache. Every `tasty()` element inlines the full CSS for its classes, even when the same component renders twice. Configured globals (`:root` tokens, `@property` defaults, `globalStyles`, `@font-face`) are never emitted, because only the SSR collector emits them, and CSS from `useGlobalStyles`, `useRawCSS`, `useKeyframes`, `useProperty`, `useFontFace`, `useCounterStyle`, and `useFunction` is dropped.
163
267
 
164
- Astro's `@astrojs/react` renderer calls `renderToString()` for each React component without wrapping the tree in a provider. The middleware uses `AsyncLocalStorage` to make the collector available to all `useStyles()` calls within the request.
268
+ Best for trying Tasty out with unconfigured styles. Use `tastyIntegration()` for anything that relies on `configure()`.
165
269
 
166
- - **Static components** (no `client:*`): Styles are collected during `renderToString` and injected into `</head>`. No JavaScript is shipped for these components.
167
- - **Islands** (`client:load`, `client:visible`, etc.): Styles are collected during SSR the same way. On the client, importing `@tenphi/tasty/ssr/astro` auto-hydrates the cache from `<script data-tasty-cache>`. The island's `useStyles()` calls hit the cache during hydration.
270
+ ### Astro Integration (recommended)
168
271
 
169
- ### Client-side hydration for islands
272
+ For production use, add `tastyIntegration()` to your Astro config. This registers middleware automatically and, by default, injects client-side hydration for islands.
170
273
 
171
- The `@tenphi/tasty/ssr/astro` module auto-hydrates when imported on the client. To ensure the cache is warm before any island renders, import it in a shared entry point or in each island component:
274
+ #### With islands (default)
172
275
 
173
- ```tsx
174
- // src/components/MyIsland.tsx
175
- import '@tenphi/tasty/ssr/astro'; // auto-hydrates cache on import
176
- import { tasty } from '@tenphi/tasty';
276
+ ```ts
277
+ // astro.config.mjs
278
+ import { defineConfig } from 'astro/config';
279
+ import react from '@astrojs/react';
280
+ import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
177
281
 
178
- const MyIsland = tasty({
179
- styles: { padding: '2x', fill: '#blue' },
282
+ export default defineConfig({
283
+ integrations: [react(), tastyIntegration()],
180
284
  });
285
+ ```
286
+
287
+ This gives you:
288
+
289
+ - A `ServerStyleCollector` per request via `AsyncLocalStorage`, deduplicating CSS across all React trees on the page
290
+ - A single consolidated `<style data-tasty-ssr>` injected into `</head>`
291
+ - A `<script>` tag pushing the rendered class names into `window.__TASTY__` for client hydration
292
+ - Auto-injected client hydration script (via `injectScript('before-hydration')`) so islands skip the style pipeline during hydration -- no need to import anything manually in each island component
181
293
 
182
- export default MyIsland;
294
+ All style functions (`useGlobalStyles`, `useRawCSS`, `useKeyframes`, `useProperty`, `useFontFace`, `useCounterStyle`) work on the server.
295
+
296
+ ```astro
297
+ ---
298
+ // src/pages/index.astro
299
+ import Card from '../components/Card.tsx';
300
+ import Interactive from '../components/Interactive.tsx';
301
+ ---
302
+
303
+ <html>
304
+ <body>
305
+ <Card>Static -- styles are inlined into the page head</Card>
306
+ <Interactive client:load>Island -- cache hydrated automatically</Interactive>
307
+ </body>
308
+ </html>
183
309
  ```
184
310
 
185
- ### Options
311
+ #### Static only (no client JS)
312
+
313
+ If your site has no `client:*` islands, skip the hydration script and cache transfer:
186
314
 
187
315
  ```ts
188
- // Skip cache state transfer
316
+ // astro.config.mjs
317
+ import { defineConfig } from 'astro/config';
318
+ import react from '@astrojs/react';
319
+ import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
320
+
321
+ export default defineConfig({
322
+ integrations: [react(), tastyIntegration({ islands: false })],
323
+ });
324
+ ```
325
+
326
+ This gives the same middleware deduplication and hook support, but ships zero client-side JavaScript. No class-list `<script>` is emitted.
327
+
328
+ #### Build-wide CSS extraction
329
+
330
+ Static Astro builds can move Tasty CSS into content-hashed, browser-cacheable
331
+ shared and page assets:
332
+
333
+ ```ts
334
+ export default defineConfig({
335
+ integrations: [
336
+ react(),
337
+ tastyIntegration({
338
+ islands: false,
339
+ css: {
340
+ mode: 'extract',
341
+ },
342
+ }),
343
+ ],
344
+ });
345
+ ```
346
+
347
+ `css.mode` defaults to `'inline'`, so existing projects keep their current
348
+ output. Extraction requires Astro 5 or newer and only applies to prerendered
349
+ production pages. Development, preview-time SSR, and on-demand routes continue
350
+ to receive the normal inline `<style data-tasty-ssr>` output.
351
+
352
+ Extraction writes every artifact emitted by all styled pages to a shared
353
+ stylesheet. Each page's strict set difference is written to a separate page
354
+ stylesheet. The shared link comes first and the page link follows, so shared
355
+ styles form the base cascade and page-only styles can override them. A fully
356
+ shared page omits the empty page stylesheet. If generated pages have no common
357
+ artifacts, each page receives only its page stylesheet.
358
+
359
+ The shared-base/page-override order is the extraction-mode cascade contract.
360
+ It does not preserve an inline artifact order where a page-only rule originally
361
+ appeared before a shared rule. Use shared styles for defaults and page-only
362
+ styles for overrides.
363
+
364
+ Extracted CSS preserves resource URLs verbatim. Relative URLs in an inline
365
+ style resolve from the page, but in an extracted stylesheet they resolve from
366
+ the asset directory. Use absolute URLs or data URLs when extraction is enabled.
367
+ Root-relative URLs such as `url(/fonts/brand.woff2)` are also safe while the
368
+ stylesheet stays on the page's origin. The build fails with a clear error if an
369
+ artifact contains a page-relative or fragment-only URL, including URL strings
370
+ in `image-set()`, `image()`, `src()`, and `@import`.
371
+
372
+ Assets are written under Astro's configured `build.assets` directory (for
373
+ example, `/_astro/tasty.shared.a1b2c3.css` and
374
+ `/_astro/tasty.page.d4e5f6.css`). Links include the configured Astro `base`, so
375
+ nested routes do not need relative-path handling. Content hashes and output are
376
+ deterministic for identical builds. If `build.assetsPrefix` is configured,
377
+ Tasty uses its CSS-specific prefix (or `fallback`) just like Astro-generated
378
+ stylesheets. When that prefix points to a different origin, root-relative
379
+ resources would resolve against the asset origin rather than the page's origin,
380
+ so the build rejects them as well. Tasty compares the prefix with Astro's `site`
381
+ when it is configured; without `site`, an absolute or protocol-relative prefix
382
+ is treated conservatively as cross-origin. Use a fully absolute resource URL in
383
+ that configuration.
384
+
385
+ ### Manual middleware (advanced)
386
+
387
+ If you need to compose Tasty's middleware with other middleware (e.g., via `sequence()`), use `tastyMiddleware()` directly:
388
+
389
+ ```ts
390
+ // src/middleware.ts
391
+ import { sequence } from 'astro:middleware';
392
+ import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
393
+
394
+ export const onRequest = sequence(tastyMiddleware(), myOtherMiddleware);
395
+ ```
396
+
397
+ For island hydration with manual middleware, import the client module in a shared entry point or in each island:
398
+
399
+ ```tsx
400
+ import '@tenphi/tasty/ssr/astro-client';
401
+ ```
402
+
403
+ #### Options
404
+
405
+ ```ts
406
+ // Skip cache state transfer (static-only, no islands)
189
407
  export const onRequest = tastyMiddleware({ transferCache: false });
190
408
  ```
191
409
 
410
+ Build-wide extraction (`css: { mode: 'extract' }`) is available only through `tastyIntegration()`; `tastyMiddleware()` always inlines CSS.
411
+
412
+ ### How it works
413
+
414
+ Astro's `@astrojs/react` renderer calls `renderToString()` for each React component without wrapping the tree in a provider. The middleware creates a `ServerStyleCollector` and binds it via `AsyncLocalStorage`. All `computeStyles()` calls within the request discover this collector automatically.
415
+
416
+ - **Static components** (no `client:*`): Styles are collected during `renderToString` and injected into `</head>` as a single `<style>` tag. No JavaScript is shipped.
417
+ - **Islands** (`client:load`, `client:visible`, etc.): Styles are collected during SSR the same way. On the client, the hydration script (auto-injected by `tastyIntegration()` or manually via `@tenphi/tasty/ssr/astro-client`) reads the class list from `window.__TASTY__` and pre-populates the injector's rules map. The island's `computeStyles()` calls see the class names as already registered and skip the pipeline during hydration.
418
+ - The middleware reads the full response body, then injects the collected CSS into `</head>` before sending the final HTML.
419
+ - In extraction mode, prerendered responses also carry temporary structured
420
+ artifact metadata. `astro:build:done` uses those collector-provided
421
+ boundaries to write shared and page assets and rewrite generated HTML, then
422
+ removes the metadata. Artifact boundaries are never inferred by splitting or
423
+ reparsing the generated CSS.
424
+
192
425
  ### CSP nonce
193
426
 
194
- Same as Next.js -- call `configure({ nonce: '...' })` before any rendering happens. The middleware reads the nonce and applies it to injected tags.
427
+ Call `configure({ nonce: '...' })` before any rendering happens. The middleware reads the nonce and applies it to injected `<style>` and `<script>` tags. In extraction mode, the external stylesheet links retain the nonce.
195
428
 
196
429
  ---
197
430
 
198
431
  ## Generic Framework Integration
199
432
 
200
- Any React-based framework can integrate using the core SSR API:
433
+ Any React-based framework can integrate using `runWithCollector`, which binds a `ServerStyleCollector` to the current async context via `AsyncLocalStorage`. All style function calls within the render automatically discover the collector.
201
434
 
202
435
  ```tsx
436
+ // ── Server ──────────────────────────────────────────────
203
437
  import {
204
- ServerStyleCollector,
205
- TastySSRContext,
206
- hydrateTastyCache,
438
+ createServerStyleCollector,
439
+ runWithCollector,
207
440
  } from '@tenphi/tasty/ssr';
208
441
  import { renderToString } from 'react-dom/server';
209
- import { hydrateRoot } from 'react-dom/client';
210
-
211
- // ── Server ──────────────────────────────────────────────
212
442
 
213
- const collector = new ServerStyleCollector();
443
+ const collector = createServerStyleCollector();
214
444
 
215
- const html = renderToString(
216
- <TastySSRContext.Provider value={collector}>
217
- <App />
218
- </TastySSRContext.Provider>
219
- );
445
+ const html = runWithCollector(collector, () => renderToString(<App />));
220
446
 
221
447
  const css = collector.getCSS();
222
- const cacheState = collector.getCacheState();
448
+ const classNames = collector.getRenderedClassNames();
223
449
 
224
450
  // Embed in your HTML template:
225
451
  const fullHtml = `
226
452
  <html>
227
453
  <head>
228
454
  <style data-tasty-ssr>${css}</style>
229
- <script data-tasty-cache type="application/json">
230
- ${JSON.stringify(cacheState)}
231
- </script>
455
+ <script>(window.__TASTY__=window.__TASTY__||[]).push(${JSON.stringify(classNames)})</script>
232
456
  </head>
233
457
  <body>
234
458
  <div id="root">${html}</div>
235
459
  </body>
236
460
  </html>
237
461
  `;
462
+ ```
238
463
 
464
+ ```tsx
239
465
  // ── Client ──────────────────────────────────────────────
240
-
241
- // Before hydration:
242
- hydrateTastyCache(); // reads from <script data-tasty-cache>
466
+ // Browser-safe: runs hydrateTastyClasses() with window.__TASTY__ on import
467
+ import '@tenphi/tasty/ssr/astro-client';
468
+ import { hydrateRoot } from 'react-dom/client';
243
469
 
244
470
  hydrateRoot(document.getElementById('root'), <App />);
245
471
  ```
246
472
 
473
+ `@tenphi/tasty/ssr` is server-only: it imports `node:async_hooks`, and in a browser bundle rendering throws `AsyncLocalStorage is not a constructor`. Despite its name, `@tenphi/tasty/ssr/astro-client` works with any framework.
474
+
247
475
  ### Streaming SSR
248
476
 
249
477
  For streaming with `renderToPipeableStream`, use `flushCSS()` instead of `getCSS()`:
250
478
 
251
479
  ```tsx
252
- const collector = new ServerStyleCollector();
480
+ import { PassThrough } from 'node:stream';
481
+ import { renderToPipeableStream } from 'react-dom/server';
482
+
483
+ const collector = createServerStyleCollector();
484
+
485
+ // React ends the stream it pipes into, so pipe into a PassThrough and
486
+ // append the remaining styles and the class list after it ends.
487
+ const body = new PassThrough();
488
+ body.pipe(res, { end: false });
489
+ body.on('end', () => {
490
+ // Styles collected after the shell (Suspense boundaries) + class list
491
+ const css = collector.flushCSS();
492
+ if (css) res.write(`<style data-tasty-ssr>${css}</style>`);
493
+
494
+ const classNames = collector.getRenderedClassNames();
495
+ res.end(
496
+ `</div><script>(window.__TASTY__=window.__TASTY__||[]).push(${JSON.stringify(classNames)})</script></body></html>`,
497
+ );
498
+ });
253
499
 
254
- const stream = renderToPipeableStream(
255
- <TastySSRContext.Provider value={collector}>
256
- <App />
257
- </TastySSRContext.Provider>,
258
- {
500
+ runWithCollector(collector, () => {
501
+ const { pipe } = renderToPipeableStream(<App />, {
259
502
  onShellReady() {
260
- // Flush styles collected so far
261
- const css = collector.flushCSS();
262
- res.write(`<style data-tasty-ssr>${css}</style>`);
263
- stream.pipe(res);
264
- },
265
- onAllReady() {
266
- // Flush any remaining styles + cache state
503
+ // Styles collected for the shell
267
504
  const css = collector.flushCSS();
268
- if (css) res.write(`<style data-tasty-ssr>${css}</style>`);
269
-
270
- const state = collector.getCacheState();
271
- res.write(`<script data-tasty-cache type="application/json">${JSON.stringify(state)}</script>`);
505
+ res.write(
506
+ `<!DOCTYPE html><html><head><style data-tasty-ssr>${css}</style></head><body><div id="root">`,
507
+ );
508
+ pipe(body);
272
509
  },
273
- }
274
- );
275
- ```
276
-
277
- ### AsyncLocalStorage (no React context)
278
-
279
- If your framework doesn't support wrapping the React tree with a provider, use `runWithCollector`:
280
-
281
- ```tsx
282
- import {
283
- ServerStyleCollector,
284
- runWithCollector,
285
- hydrateTastyCache,
286
- } from '@tenphi/tasty/ssr';
287
-
288
- const collector = new ServerStyleCollector();
289
-
290
- const html = await runWithCollector(collector, () =>
291
- renderToString(<App />)
292
- );
293
-
294
- const css = collector.getCSS();
295
- // ... inject into HTML as above
510
+ });
511
+ });
296
512
  ```
297
513
 
298
514
  ---
@@ -301,56 +517,81 @@ const css = collector.getCSS();
301
517
 
302
518
  ### Entry points
303
519
 
304
- | Import path | Description |
305
- |---|---|
306
- | `@tenphi/tasty/ssr` | Core SSR API: `ServerStyleCollector`, `TastySSRContext`, `runWithCollector`, `hydrateTastyCache` |
307
- | `@tenphi/tasty/ssr/next` | Next.js App Router: `TastyRegistry` component |
308
- | `@tenphi/tasty/ssr/astro` | Astro: `tastyMiddleware`, auto-hydration on import |
520
+ | Import path | Description |
521
+ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
522
+ | `@tenphi/tasty/ssr` | Core SSR API (server-only): `ServerStyleCollector`, `createServerStyleCollector`, `runWithCollector`, `getSSRCollector`, `hydrateTastyClasses`; types `ServerStyleArtifact`, `ServerStyleArtifactKind` |
523
+ | `@tenphi/tasty/ssr/next` | Next.js App Router: `TastyRegistry` component |
524
+ | `@tenphi/tasty/ssr/next-config` | Next.js config wrapper: shared, content-hashed global stylesheet |
525
+ | `@tenphi/tasty/ssr/astro` | Astro: `tastyIntegration`, `tastyMiddleware` |
526
+ | `@tenphi/tasty/ssr/astro-client` | Astro: client-side cache hydration (auto-injected by integration, or import manually) |
527
+ | `@tenphi/tasty/ssr/astro-middleware`<br />`@tenphi/tasty/ssr/astro-middleware-static`<br />`@tenphi/tasty/ssr/astro-middleware-extract`<br />`@tenphi/tasty/ssr/astro-middleware-extract-static` | Astro: the middleware entrypoints `tastyIntegration()` registers via `addMiddleware()`. Exported so Astro can resolve them by specifier; you should not import them. For manual setups use `tastyMiddleware()`. |
309
528
 
310
529
  ### `ServerStyleCollector`
311
530
 
312
531
  Server-safe style collector. One instance per request.
313
532
 
314
- | Method | Description |
315
- |---|---|
316
- | `allocateClassName(cacheKey)` | Allocate a sequential class name (`t0`, `t1`, ...) for a cache key. Returns `{ className, isNewAllocation }`. |
317
- | `collectChunk(cacheKey, className, rules)` | Record CSS rules for a chunk. Deduplicated by `cacheKey`. |
318
- | `collectKeyframes(name, css)` | Record a `@keyframes` rule. Deduplicated by name. |
319
- | `collectProperty(name, css)` | Record a `@property` rule. Deduplicated by name. |
320
- | `collectFontFace(key, css)` | Record a `@font-face` rule. Deduplicated by content hash. |
321
- | `collectCounterStyle(name, css)` | Record a `@counter-style` rule. Deduplicated by name. |
322
- | `getCSS()` | Get all collected CSS as a single string. For non-streaming SSR. |
323
- | `flushCSS()` | Get only CSS collected since the last flush. For streaming SSR. |
324
- | `getCacheState()` | Serialize `{ entries: Record<cacheKey, className>, classCounter }` for client hydration. |
325
-
326
- ### `TastySSRContext`
327
-
328
- React context (`createContext<ServerStyleCollector | null>(null)`). Used by `useStyles()` to find the collector during SSR.
533
+ Constructor: `new ServerStyleCollector(namePrefix?)`, or use the `createServerStyleCollector(namePrefix?)` factory. The optional `namePrefix` overrides the value from `configure({ namePrefix })`; in normal usage you pass nothing and let the global config drive it. See [Configuration: Name prefix](configuration.md#name-prefix).
534
+
535
+ | Method | Description |
536
+ | ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
537
+ | `allocateClassName(cacheKey)` | Allocate a deterministic, content-hashed class name for a cache key (e.g. `t1a2b3` with the default prefix). The same `cacheKey` always produces the same class name on server and client when both share the same `namePrefix`. Returns `{ className, isNewAllocation }`. |
538
+ | `collectChunk(cacheKey, className, rules)` | Record CSS rules for a chunk. Deduplicated by `cacheKey`. |
539
+ | `collectKeyframes(name, css)` | Record a `@keyframes` rule. Deduplicated by name. |
540
+ | `allocateKeyframeName(providedName?)` | Allocate a keyframe name. Returns `providedName` if given, otherwise generates one using `${namePrefix}k${counter}` (e.g. `tk0`, `tk1`, ...). |
541
+ | `collectProperty(name, css)` | Record a `@property` rule. Deduplicated by name. |
542
+ | `collectFontFace(key, css)` | Record a `@font-face` rule. Deduplicated by content hash. |
543
+ | `collectCounterStyle(name, css, options?)` | Record a `@counter-style` rule, keyed by name. A different rule under the same name replaces the earlier one (and is re-flushed when streaming); `{ weak: true }`, used for `configure()` definitions, never replaces. |
544
+ | `collectFunction(name, css, options?)` | Record a CSS `@function` rule (from `useFunction` or `@function` styles). Same replace/`weak` semantics as `collectCounterStyle`. |
545
+ | `allocateCounterStyleName(providedName?)` | Allocate a counter-style name. Returns `providedName` if given, otherwise generates one using `${namePrefix}c${counter}` (e.g. `tc0`, `tc1`, ...). |
546
+ | `collectGlobalStyles(key, css)` | Record global styles (from `useGlobalStyles`). Deduplicated by key. |
547
+ | `collectRawCSS(key, css)` | Record raw CSS text (from `useRawCSS`). Deduplicated by key. |
548
+ | `collectInternals()` | Collect eager configured globals: `@property`, `:root` tokens and presets, `@font-face`, `@counter-style`, `@function`, and `globalStyles`. Called automatically on first chunk collection; idempotent. |
549
+ | `getCSS()` | Get all collected CSS as a single string. For non-streaming SSR. |
550
+ | `flushCSS()` | Get only CSS collected since the last flush. For streaming SSR. |
551
+ | `getRenderedClassNames()` | Get the class names allocated since the previous call (the first call returns all so far). Push each batch to `window.__TASTY__` for hydration via `hydrateTastyClasses()`. |
552
+ | `getArtifacts()` | Return the collected CSS as ordered, typed artifacts (`property`, `font-face`, `counter-style`, `function`, `raw`, `global`, `chunk`, `keyframes`). |
329
553
 
330
554
  ### `TastyRegistry`
331
555
 
332
556
  Next.js App Router component. Props:
333
557
 
334
- | Prop | Type | Default | Description |
335
- |---|---|---|---|
336
- | `children` | `ReactNode` | required | Application tree |
337
- | `transferCache` | `boolean` | `true` | Embed cache state script for zero-cost hydration |
558
+ | Prop | Type | Default | Description |
559
+ | ------------------ | ----------------- | --------- | ------------------------------------------------------------------------- |
560
+ | `children` | `ReactNode` | required | Application tree |
561
+ | `transferCache` | `boolean` | `true` | Embed cache state script for zero-cost hydration |
562
+ | `sharedStylesheet` | `string \| false` | generated | Override the shared URL, or disable generated shared CSS for the registry |
563
+
564
+ ### `withTastyNext(options)`
565
+
566
+ Next.js configuration wrapper exported from
567
+ `@tenphi/tasty/ssr/next-config`. It generates a shared stylesheet from eager
568
+ Tasty configuration artifacts and wires its URL and immutable cache header
569
+ into the Next config. Route-specific CSS continues through `TastyRegistry`.
570
+
571
+ ### `tastyIntegration(options?)`
572
+
573
+ Astro integration factory. Registers middleware and optionally injects client hydration.
574
+
575
+ | Option | Type | Default | Description |
576
+ | --------- | ---------------------------------- | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
577
+ | `islands` | `boolean` | `true` | When `true`, injects client hydration script and enables `transferCache`. When `false`, no client JS is shipped. |
578
+ | `css` | `{ mode?: 'inline' \| 'extract' }` | `{ mode: 'inline' }` | `'extract'` writes content-hashed shared and per-page stylesheets for prerendered pages (Astro 5+). See [Build-wide CSS extraction](#build-wide-css-extraction). |
338
579
 
339
580
  ### `tastyMiddleware(options?)`
340
581
 
341
- Astro middleware factory. Options:
582
+ Astro middleware factory. Use for manual middleware composition.
342
583
 
343
- | Option | Type | Default | Description |
344
- |---|---|---|---|
345
- | `transferCache` | `boolean` | `true` | Embed cache state script for island hydration |
584
+ | Option | Type | Default | Description |
585
+ | --------------- | --------- | ------- | --------------------------------------------- |
586
+ | `transferCache` | `boolean` | `true` | Embed cache state script for island hydration |
346
587
 
347
- ### `hydrateTastyCache(state?)`
588
+ ### `hydrateTastyClasses(classes?)`
348
589
 
349
- Pre-populate the client injector cache. When called without arguments, reads from `window.__TASTY_SSR_CACHE__` (streaming) or `<script data-tasty-cache>` (non-streaming).
590
+ Pre-populate the client injector's rules map with class names rendered on the server, marking them as already present in the DOM so `computeStyles()` skips re-injection during hydration. When called without arguments, reads the class list from `window.__TASTY__` (populated by the streaming `<script>` tags emitted during SSR).
350
591
 
351
592
  ### `runWithCollector(collector, fn)`
352
593
 
353
- Run a function with a `ServerStyleCollector` bound to the current async context via `AsyncLocalStorage`. All `useStyles()` calls within `fn` (and async continuations) will find this collector.
594
+ Run a function with a `ServerStyleCollector` bound to the current async context via `AsyncLocalStorage`. All style function calls within `fn` (and async continuations) — including `computeStyles()`, `useStyles()`, `useGlobalStyles()`, `useRawCSS()`, `useKeyframes()`, `useProperty()`, `useFontFace()`, `useCounterStyle()`, and `useFunction()` — will find this collector. Returns `fn`'s return value, synchronously unless `fn` returns a promise.
354
595
 
355
596
  ---
356
597
 
@@ -358,27 +599,32 @@ Run a function with a `ServerStyleCollector` bound to the current async context
358
599
 
359
600
  ### Styles flash on page load (FOUC)
360
601
 
361
- The `TastyRegistry` or `tastyMiddleware` is missing. Ensure your layout wraps the app with `TastyRegistry` (Next.js) or the middleware is registered (Astro).
602
+ The `TastyRegistry` or `tastyIntegration` is missing. Ensure your layout wraps the app with `TastyRegistry` (Next.js) or that `tastyIntegration()` is in your Astro config (or `tastyMiddleware()` is registered manually).
362
603
 
363
604
  ### Hydration mismatch warnings
364
605
 
365
- Class names are deterministic for the same render order. If you see mismatches, ensure `hydrateTastyCache()` runs before React hydration. For Next.js, this is automatic. For Astro, import `@tenphi/tasty/ssr/astro` in your island components. For custom setups, call `hydrateTastyCache()` before `hydrateRoot()`.
606
+ Class names are content hashes of the resolved styles, so render order does not affect them. Unnamed `useKeyframes()` and `useCounterStyle()` names are counters (`tk0`, `tc0`) on both server and client; pass `name` if the two sides can call them in a different order. If you see mismatches, ensure `hydrateTastyClasses()` runs before React hydration. For Next.js, this is automatic. For Astro with `tastyIntegration()`, this is also automatic. For manual Astro middleware setups, import `@tenphi/tasty/ssr/astro-client` in your island components. For custom setups, import `@tenphi/tasty/ssr/astro-client` before `hydrateRoot()`.
607
+
608
+ Class names are also derived from the _resolved_ styles, so the server and the client must configure Tasty identically. Anything that changes what a component's styles resolve to will produce a mismatch if it is registered on only one side — `namePrefix`, `recipes`, `handlers`, and the `propHandlers` / `baseStyleProps` extension points described in [Plugins](plugins.md). Call the same `configure()` on both; global CSS is deduplicated automatically, so no `typeof window` guard is needed.
366
609
 
367
610
  ### Styles duplicated after hydration
368
611
 
369
- This is expected and harmless. SSR `<style data-tasty-ssr>` tags remain in the DOM. The client injector creates separate `<style>` elements for any new styles. SSR styles are never modified or removed by the client. If this is a concern for very large apps, call `cleanupSSRStyles()` after hydration:
612
+ **Global CSS** (`:root` tokens, `@property`, `globalStyles`, `@font-face`, `@counter-style`, `@function`) configured via `configure()` is automatically deduplicated. When Tasty detects an inline or extracted `[data-tasty-ssr]` stylesheet in the document, it skips client-side injection of globals that were already rendered by the SSR collector. This means `configure()` can be called with the full config on both server and client — no `typeof window === 'undefined'` guard is needed.
613
+
614
+ **Component CSS**: SSR `<style data-tasty-ssr>` tags remain in the DOM. The client injector creates separate `<style>` elements for any new styles. SSR styles are never modified or removed by the client. If this is a concern for very large apps, you can remove the SSR style tags and hydration scripts manually after hydration:
370
615
 
371
616
  ```tsx
372
- import { hydrateTastyCache } from '@tenphi/tasty/ssr';
617
+ import '@tenphi/tasty/ssr/astro-client'; // runs hydrateTastyClasses()
373
618
 
374
- hydrateTastyCache();
375
619
  hydrateRoot(root, <App />);
376
620
 
377
- // Optional: remove SSR style tags after hydration
378
- document.querySelectorAll('style[data-tasty-ssr]').forEach(el => el.remove());
379
- document.querySelectorAll('script[data-tasty-cache]').forEach(el => el.remove());
621
+ // Optional: remove SSR style tags and class-list scripts after hydration
622
+ document.querySelectorAll('style[data-tasty-ssr]').forEach((el) => el.remove());
623
+ document.querySelectorAll('script').forEach((el) => {
624
+ if (el.textContent?.includes('__TASTY__')) el.remove();
625
+ });
380
626
  ```
381
627
 
382
628
  ### `AsyncLocalStorage` not available
383
629
 
384
- The `@tenphi/tasty/ssr` entry point imports from `node:async_hooks`. This is excluded from client bundles by the build configuration. If you see import errors on the client, ensure your bundler treats `node:async_hooks` as external or use the `@tenphi/tasty/ssr/next` entry point (which does not use ALS).
630
+ `@tenphi/tasty/ssr` imports `node:async_hooks` and is server-only. In a browser bundle the module is stubbed and rendering throws `AsyncLocalStorage is not a constructor`. On the client, import `@tenphi/tasty/ssr/astro-client` (it works with any framework) or use `@tenphi/tasty/ssr/next`, which hydrates automatically.