@tenphi/tasty 0.0.0-snapshot.bbd10c7 → 0.0.0-snapshot.bbd36bd

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 (368) hide show
  1. package/README.md +196 -140
  2. package/dist/astro-CeYENy2x.js +301 -0
  3. package/dist/astro-CeYENy2x.js.map +1 -0
  4. package/dist/{ssr/async-storage.js → async-storage-DKK-wTD4.js} +16 -6
  5. package/dist/async-storage-DKK-wTD4.js.map +1 -0
  6. package/dist/babel-DWCsafYw.d.ts +83 -0
  7. package/dist/collector-B3OsM252.js +327 -0
  8. package/dist/collector-B3OsM252.js.map +1 -0
  9. package/dist/collector-BTVXj2hS.d.ts +163 -0
  10. package/dist/config-B3gPdCqd.js +12421 -0
  11. package/dist/config-B3gPdCqd.js.map +1 -0
  12. package/dist/config-LfIDmVHx.d.ts +1363 -0
  13. package/dist/context-CA8YKeMn.js +24 -0
  14. package/dist/context-CA8YKeMn.js.map +1 -0
  15. package/dist/core/index.d.ts +5 -34
  16. package/dist/core/index.js +6 -27
  17. package/dist/core-DGm0CFHP.js +1732 -0
  18. package/dist/core-DGm0CFHP.js.map +1 -0
  19. package/dist/css-resources-Cyl_axbI.js +149 -0
  20. package/dist/css-resources-Cyl_axbI.js.map +1 -0
  21. package/dist/{zero/extractor.js → css-writer-Bgowobbx.js} +148 -24
  22. package/dist/css-writer-Bgowobbx.js.map +1 -0
  23. package/dist/{ssr/format-global-rules.js → format-global-rules-DklyaXv-.js} +2 -2
  24. package/dist/format-global-rules-DklyaXv-.js.map +1 -0
  25. package/dist/{ssr/format-rules.js → format-rules-XRw9u7d4.js} +33 -2
  26. package/dist/format-rules-XRw9u7d4.js.map +1 -0
  27. package/dist/hydrate-CNOmZprz.js +37 -0
  28. package/dist/hydrate-CNOmZprz.js.map +1 -0
  29. package/dist/index-Bm9ltvdH.d.ts +1933 -0
  30. package/dist/index-BmogEzTo.d.ts +1575 -0
  31. package/dist/index.d.ts +5 -51
  32. package/dist/index.js +922 -36
  33. package/dist/index.js.map +1 -0
  34. package/dist/keyframes-DE-OE76F.js +535 -0
  35. package/dist/keyframes-DE-OE76F.js.map +1 -0
  36. package/dist/{utils/merge-styles.d.ts → merge-styles-BcLl1u_d.d.ts} +3 -3
  37. package/dist/{utils/merge-styles.js → merge-styles-DuoZEsm9.js} +3 -4
  38. package/dist/merge-styles-DuoZEsm9.js.map +1 -0
  39. package/dist/{utils/resolve-recipes.js → resolve-recipes-H9NqOQuP.js} +4 -6
  40. package/dist/resolve-recipes-H9NqOQuP.js.map +1 -0
  41. package/dist/ssr/astro-client.js +19 -0
  42. package/dist/ssr/astro-client.js.map +1 -0
  43. package/dist/ssr/astro-middleware-extract-static.d.ts +11 -0
  44. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  45. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  46. package/dist/ssr/astro-middleware-extract.d.ts +11 -0
  47. package/dist/ssr/astro-middleware-extract.js +9 -0
  48. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  49. package/dist/ssr/astro-middleware-static.d.ts +18 -0
  50. package/dist/ssr/astro-middleware-static.js +18 -0
  51. package/dist/ssr/astro-middleware-static.js.map +1 -0
  52. package/dist/ssr/astro-middleware.d.ts +19 -0
  53. package/dist/ssr/astro-middleware.js +19 -0
  54. package/dist/ssr/astro-middleware.js.map +1 -0
  55. package/dist/ssr/astro.d.ts +117 -11
  56. package/dist/ssr/astro.js +2 -64
  57. package/dist/ssr/index.d.ts +37 -4
  58. package/dist/ssr/index.js +6 -6
  59. package/dist/ssr/index.js.map +1 -1
  60. package/dist/ssr/next-config.d.ts +66 -0
  61. package/dist/ssr/next-config.js +115 -0
  62. package/dist/ssr/next-config.js.map +1 -0
  63. package/dist/ssr/next.d.ts +14 -5
  64. package/dist/ssr/next.js +32 -15
  65. package/dist/ssr/next.js.map +1 -1
  66. package/dist/ssr-collector-ref-COs_ioWl.js +29 -0
  67. package/dist/ssr-collector-ref-COs_ioWl.js.map +1 -0
  68. package/dist/static/index.d.ts +91 -5
  69. package/dist/static/index.js +49 -3
  70. package/dist/static/index.js.map +1 -0
  71. package/dist/static/inject.js.map +1 -1
  72. package/dist/zero/babel.d.ts +2 -182
  73. package/dist/zero/babel.js +80 -40
  74. package/dist/zero/babel.js.map +1 -1
  75. package/dist/zero/index.d.ts +81 -3
  76. package/dist/zero/index.js +2 -3
  77. package/dist/zero/next.d.ts +1 -1
  78. package/dist/zero/next.js +1 -1
  79. package/dist/zero/next.js.map +1 -1
  80. package/docs/README.md +20 -12
  81. package/docs/adoption.md +59 -32
  82. package/docs/ai-agents.md +224 -0
  83. package/docs/comparison.md +76 -48
  84. package/docs/configuration.md +566 -69
  85. package/docs/debug.md +35 -18
  86. package/docs/design-system.md +63 -32
  87. package/docs/dsl.md +527 -179
  88. package/docs/getting-started.md +62 -41
  89. package/docs/injector.md +157 -51
  90. package/docs/methodology.md +69 -37
  91. package/docs/migration-v3.md +285 -0
  92. package/docs/pipeline.md +741 -0
  93. package/docs/plugins.md +353 -0
  94. package/docs/{runtime.md → react-api.md} +176 -67
  95. package/docs/runtime-benchmarks.md +351 -0
  96. package/docs/ssr.md +350 -94
  97. package/docs/styles.md +65 -16
  98. package/docs/tasty-static.md +149 -87
  99. package/package.json +78 -23
  100. package/tasty.config.ts +6 -0
  101. package/dist/_virtual/_rolldown/runtime.js +0 -7
  102. package/dist/chunks/cacheKey.js +0 -77
  103. package/dist/chunks/cacheKey.js.map +0 -1
  104. package/dist/chunks/definitions.d.ts +0 -37
  105. package/dist/chunks/definitions.js +0 -258
  106. package/dist/chunks/definitions.js.map +0 -1
  107. package/dist/chunks/index.d.ts +0 -1
  108. package/dist/chunks/renderChunk.d.ts +0 -1
  109. package/dist/chunks/renderChunk.js +0 -59
  110. package/dist/chunks/renderChunk.js.map +0 -1
  111. package/dist/compute-styles.d.ts +0 -31
  112. package/dist/compute-styles.js +0 -356
  113. package/dist/compute-styles.js.map +0 -1
  114. package/dist/config.d.ts +0 -372
  115. package/dist/config.js +0 -507
  116. package/dist/config.js.map +0 -1
  117. package/dist/counter-style/index.js +0 -51
  118. package/dist/counter-style/index.js.map +0 -1
  119. package/dist/debug.d.ts +0 -89
  120. package/dist/debug.js +0 -453
  121. package/dist/debug.js.map +0 -1
  122. package/dist/font-face/index.js +0 -63
  123. package/dist/font-face/index.js.map +0 -1
  124. package/dist/hooks/index.d.ts +0 -7
  125. package/dist/hooks/useCounterStyle.d.ts +0 -50
  126. package/dist/hooks/useCounterStyle.js +0 -45
  127. package/dist/hooks/useCounterStyle.js.map +0 -1
  128. package/dist/hooks/useFontFace.d.ts +0 -43
  129. package/dist/hooks/useFontFace.js +0 -69
  130. package/dist/hooks/useFontFace.js.map +0 -1
  131. package/dist/hooks/useGlobalStyles.d.ts +0 -30
  132. package/dist/hooks/useGlobalStyles.js +0 -77
  133. package/dist/hooks/useGlobalStyles.js.map +0 -1
  134. package/dist/hooks/useKeyframes.d.ts +0 -56
  135. package/dist/hooks/useKeyframes.js +0 -63
  136. package/dist/hooks/useKeyframes.js.map +0 -1
  137. package/dist/hooks/useProperty.d.ts +0 -79
  138. package/dist/hooks/useProperty.js +0 -108
  139. package/dist/hooks/useProperty.js.map +0 -1
  140. package/dist/hooks/useRawCSS.d.ts +0 -53
  141. package/dist/hooks/useRawCSS.js +0 -34
  142. package/dist/hooks/useRawCSS.js.map +0 -1
  143. package/dist/hooks/useStyles.d.ts +0 -40
  144. package/dist/hooks/useStyles.js +0 -29
  145. package/dist/hooks/useStyles.js.map +0 -1
  146. package/dist/injector/index.d.ts +0 -166
  147. package/dist/injector/index.js +0 -166
  148. package/dist/injector/index.js.map +0 -1
  149. package/dist/injector/injector.d.ts +0 -166
  150. package/dist/injector/injector.js +0 -464
  151. package/dist/injector/injector.js.map +0 -1
  152. package/dist/injector/sheet-manager.d.ts +0 -136
  153. package/dist/injector/sheet-manager.js +0 -733
  154. package/dist/injector/sheet-manager.js.map +0 -1
  155. package/dist/injector/types.d.ts +0 -204
  156. package/dist/keyframes/index.js +0 -206
  157. package/dist/keyframes/index.js.map +0 -1
  158. package/dist/parser/classify.js +0 -319
  159. package/dist/parser/classify.js.map +0 -1
  160. package/dist/parser/const.js +0 -60
  161. package/dist/parser/const.js.map +0 -1
  162. package/dist/parser/lru.js +0 -109
  163. package/dist/parser/lru.js.map +0 -1
  164. package/dist/parser/parser.d.ts +0 -25
  165. package/dist/parser/parser.js +0 -115
  166. package/dist/parser/parser.js.map +0 -1
  167. package/dist/parser/tokenizer.js +0 -69
  168. package/dist/parser/tokenizer.js.map +0 -1
  169. package/dist/parser/types.d.ts +0 -51
  170. package/dist/parser/types.js +0 -46
  171. package/dist/parser/types.js.map +0 -1
  172. package/dist/pipeline/conditions.d.ts +0 -134
  173. package/dist/pipeline/conditions.js +0 -406
  174. package/dist/pipeline/conditions.js.map +0 -1
  175. package/dist/pipeline/exclusive.js +0 -230
  176. package/dist/pipeline/exclusive.js.map +0 -1
  177. package/dist/pipeline/index.d.ts +0 -55
  178. package/dist/pipeline/index.js +0 -708
  179. package/dist/pipeline/index.js.map +0 -1
  180. package/dist/pipeline/materialize.js +0 -1103
  181. package/dist/pipeline/materialize.js.map +0 -1
  182. package/dist/pipeline/parseStateKey.d.ts +0 -15
  183. package/dist/pipeline/parseStateKey.js +0 -446
  184. package/dist/pipeline/parseStateKey.js.map +0 -1
  185. package/dist/pipeline/simplify.js +0 -515
  186. package/dist/pipeline/simplify.js.map +0 -1
  187. package/dist/pipeline/warnings.js +0 -18
  188. package/dist/pipeline/warnings.js.map +0 -1
  189. package/dist/plugins/index.d.ts +0 -2
  190. package/dist/plugins/okhsl-plugin.d.ts +0 -35
  191. package/dist/plugins/okhsl-plugin.js +0 -97
  192. package/dist/plugins/okhsl-plugin.js.map +0 -1
  193. package/dist/plugins/types.d.ts +0 -76
  194. package/dist/properties/index.js +0 -222
  195. package/dist/properties/index.js.map +0 -1
  196. package/dist/properties/property-type-resolver.d.ts +0 -24
  197. package/dist/properties/property-type-resolver.js +0 -90
  198. package/dist/properties/property-type-resolver.js.map +0 -1
  199. package/dist/ssr/astro.js.map +0 -1
  200. package/dist/ssr/async-storage.d.ts +0 -17
  201. package/dist/ssr/async-storage.js.map +0 -1
  202. package/dist/ssr/collect-auto-properties.js +0 -39
  203. package/dist/ssr/collect-auto-properties.js.map +0 -1
  204. package/dist/ssr/collector.d.ts +0 -102
  205. package/dist/ssr/collector.js +0 -219
  206. package/dist/ssr/collector.js.map +0 -1
  207. package/dist/ssr/format-global-rules.js.map +0 -1
  208. package/dist/ssr/format-keyframes.js +0 -69
  209. package/dist/ssr/format-keyframes.js.map +0 -1
  210. package/dist/ssr/format-property.js +0 -49
  211. package/dist/ssr/format-property.js.map +0 -1
  212. package/dist/ssr/format-rules.js.map +0 -1
  213. package/dist/ssr/hydrate.d.ts +0 -22
  214. package/dist/ssr/hydrate.js +0 -49
  215. package/dist/ssr/hydrate.js.map +0 -1
  216. package/dist/ssr/ssr-collector-ref.js +0 -12
  217. package/dist/ssr/ssr-collector-ref.js.map +0 -1
  218. package/dist/states/index.d.ts +0 -49
  219. package/dist/states/index.js +0 -170
  220. package/dist/states/index.js.map +0 -1
  221. package/dist/static/tastyStatic.d.ts +0 -46
  222. package/dist/static/tastyStatic.js +0 -30
  223. package/dist/static/tastyStatic.js.map +0 -1
  224. package/dist/static/types.d.ts +0 -49
  225. package/dist/static/types.js +0 -24
  226. package/dist/static/types.js.map +0 -1
  227. package/dist/styles/border.d.ts +0 -25
  228. package/dist/styles/border.js +0 -120
  229. package/dist/styles/border.js.map +0 -1
  230. package/dist/styles/color.d.ts +0 -14
  231. package/dist/styles/color.js +0 -26
  232. package/dist/styles/color.js.map +0 -1
  233. package/dist/styles/const.js +0 -17
  234. package/dist/styles/const.js.map +0 -1
  235. package/dist/styles/createStyle.js +0 -79
  236. package/dist/styles/createStyle.js.map +0 -1
  237. package/dist/styles/dimension.js +0 -109
  238. package/dist/styles/dimension.js.map +0 -1
  239. package/dist/styles/directional.js +0 -133
  240. package/dist/styles/directional.js.map +0 -1
  241. package/dist/styles/display.d.ts +0 -30
  242. package/dist/styles/display.js +0 -73
  243. package/dist/styles/display.js.map +0 -1
  244. package/dist/styles/fade.d.ts +0 -15
  245. package/dist/styles/fade.js +0 -62
  246. package/dist/styles/fade.js.map +0 -1
  247. package/dist/styles/fill.d.ts +0 -42
  248. package/dist/styles/fill.js +0 -51
  249. package/dist/styles/fill.js.map +0 -1
  250. package/dist/styles/flow.d.ts +0 -16
  251. package/dist/styles/flow.js +0 -12
  252. package/dist/styles/flow.js.map +0 -1
  253. package/dist/styles/gap.d.ts +0 -31
  254. package/dist/styles/gap.js +0 -38
  255. package/dist/styles/gap.js.map +0 -1
  256. package/dist/styles/height.d.ts +0 -17
  257. package/dist/styles/height.js +0 -19
  258. package/dist/styles/height.js.map +0 -1
  259. package/dist/styles/index.d.ts +0 -1
  260. package/dist/styles/index.js +0 -8
  261. package/dist/styles/index.js.map +0 -1
  262. package/dist/styles/inset.d.ts +0 -24
  263. package/dist/styles/inset.js +0 -34
  264. package/dist/styles/inset.js.map +0 -1
  265. package/dist/styles/list.d.ts +0 -16
  266. package/dist/styles/list.js +0 -100
  267. package/dist/styles/list.js.map +0 -1
  268. package/dist/styles/margin.d.ts +0 -24
  269. package/dist/styles/margin.js +0 -32
  270. package/dist/styles/margin.js.map +0 -1
  271. package/dist/styles/outline.d.ts +0 -29
  272. package/dist/styles/outline.js +0 -55
  273. package/dist/styles/outline.js.map +0 -1
  274. package/dist/styles/padding.d.ts +0 -24
  275. package/dist/styles/padding.js +0 -32
  276. package/dist/styles/padding.js.map +0 -1
  277. package/dist/styles/placement.d.ts +0 -37
  278. package/dist/styles/placement.js +0 -74
  279. package/dist/styles/placement.js.map +0 -1
  280. package/dist/styles/predefined.d.ts +0 -71
  281. package/dist/styles/predefined.js +0 -237
  282. package/dist/styles/predefined.js.map +0 -1
  283. package/dist/styles/preset.d.ts +0 -52
  284. package/dist/styles/preset.js +0 -127
  285. package/dist/styles/preset.js.map +0 -1
  286. package/dist/styles/radius.d.ts +0 -12
  287. package/dist/styles/radius.js +0 -83
  288. package/dist/styles/radius.js.map +0 -1
  289. package/dist/styles/scrollMargin.d.ts +0 -24
  290. package/dist/styles/scrollMargin.js +0 -32
  291. package/dist/styles/scrollMargin.js.map +0 -1
  292. package/dist/styles/scrollbar.d.ts +0 -25
  293. package/dist/styles/scrollbar.js +0 -51
  294. package/dist/styles/scrollbar.js.map +0 -1
  295. package/dist/styles/shadow.d.ts +0 -14
  296. package/dist/styles/shadow.js +0 -25
  297. package/dist/styles/shadow.js.map +0 -1
  298. package/dist/styles/shared.js +0 -17
  299. package/dist/styles/shared.js.map +0 -1
  300. package/dist/styles/transition.d.ts +0 -14
  301. package/dist/styles/transition.js +0 -159
  302. package/dist/styles/transition.js.map +0 -1
  303. package/dist/styles/types.d.ts +0 -564
  304. package/dist/styles/width.d.ts +0 -17
  305. package/dist/styles/width.js +0 -19
  306. package/dist/styles/width.js.map +0 -1
  307. package/dist/tasty.d.ts +0 -134
  308. package/dist/tasty.js +0 -240
  309. package/dist/tasty.js.map +0 -1
  310. package/dist/types.d.ts +0 -184
  311. package/dist/utils/cache-wrapper.js +0 -21
  312. package/dist/utils/cache-wrapper.js.map +0 -1
  313. package/dist/utils/case-converter.js +0 -8
  314. package/dist/utils/case-converter.js.map +0 -1
  315. package/dist/utils/color-math.d.ts +0 -46
  316. package/dist/utils/color-math.js +0 -749
  317. package/dist/utils/color-math.js.map +0 -1
  318. package/dist/utils/color-space.d.ts +0 -5
  319. package/dist/utils/color-space.js +0 -228
  320. package/dist/utils/color-space.js.map +0 -1
  321. package/dist/utils/colors.d.ts +0 -5
  322. package/dist/utils/colors.js +0 -10
  323. package/dist/utils/colors.js.map +0 -1
  324. package/dist/utils/css-types.d.ts +0 -7
  325. package/dist/utils/dotize.d.ts +0 -26
  326. package/dist/utils/dotize.js +0 -122
  327. package/dist/utils/dotize.js.map +0 -1
  328. package/dist/utils/filter-base-props.d.ts +0 -15
  329. package/dist/utils/filter-base-props.js +0 -45
  330. package/dist/utils/filter-base-props.js.map +0 -1
  331. package/dist/utils/get-display-name.d.ts +0 -7
  332. package/dist/utils/get-display-name.js +0 -10
  333. package/dist/utils/get-display-name.js.map +0 -1
  334. package/dist/utils/has-keys.js +0 -13
  335. package/dist/utils/has-keys.js.map +0 -1
  336. package/dist/utils/is-dev-env.js +0 -19
  337. package/dist/utils/is-dev-env.js.map +0 -1
  338. package/dist/utils/is-valid-element-type.js +0 -15
  339. package/dist/utils/is-valid-element-type.js.map +0 -1
  340. package/dist/utils/merge-styles.js.map +0 -1
  341. package/dist/utils/mod-attrs.d.ts +0 -6
  342. package/dist/utils/mod-attrs.js +0 -20
  343. package/dist/utils/mod-attrs.js.map +0 -1
  344. package/dist/utils/process-tokens.d.ts +0 -17
  345. package/dist/utils/process-tokens.js +0 -83
  346. package/dist/utils/process-tokens.js.map +0 -1
  347. package/dist/utils/resolve-recipes.d.ts +0 -17
  348. package/dist/utils/resolve-recipes.js.map +0 -1
  349. package/dist/utils/selector-transform.js +0 -32
  350. package/dist/utils/selector-transform.js.map +0 -1
  351. package/dist/utils/string.js +0 -8
  352. package/dist/utils/string.js.map +0 -1
  353. package/dist/utils/styles.d.ts +0 -99
  354. package/dist/utils/styles.js +0 -220
  355. package/dist/utils/styles.js.map +0 -1
  356. package/dist/utils/typography.d.ts +0 -47
  357. package/dist/utils/typography.js +0 -51
  358. package/dist/utils/typography.js.map +0 -1
  359. package/dist/utils/warnings.d.ts +0 -16
  360. package/dist/utils/warnings.js +0 -16
  361. package/dist/utils/warnings.js.map +0 -1
  362. package/dist/zero/css-writer.d.ts +0 -45
  363. package/dist/zero/css-writer.js +0 -73
  364. package/dist/zero/css-writer.js.map +0 -1
  365. package/dist/zero/extractor.d.ts +0 -24
  366. package/dist/zero/extractor.js.map +0 -1
  367. package/docs/PIPELINE.md +0 -519
  368. /package/dist/{chunks/cacheKey.d.ts → ssr/astro-client.d.ts} +0 -0
@@ -0,0 +1,301 @@
1
+ import { n as getConfig } from "./config-B3gPdCqd.js";
2
+ import { r as registerSSRCollectorGetterGlobal } from "./ssr-collector-ref-COs_ioWl.js";
3
+ import { t as ServerStyleCollector } from "./collector-B3OsM252.js";
4
+ import { n as runWithCollector, t as getSSRCollector } from "./async-storage-DKK-wTD4.js";
5
+ import { t as findUnsafeCSSResource } from "./css-resources-Cyl_axbI.js";
6
+ import { createHash } from "node:crypto";
7
+ import { join } from "node:path";
8
+ import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
9
+ import { fileURLToPath } from "node:url";
10
+ //#region src/ssr/astro-extraction.ts
11
+ const METADATA_START = "<template data-tasty-extract>";
12
+ const METADATA_END = "</template>";
13
+ function createExtractionMetadata(artifacts) {
14
+ return `${METADATA_START}${Buffer.from(JSON.stringify(artifacts), "utf8").toString("base64")}${METADATA_END}`;
15
+ }
16
+ function parseExtractablePage(path, html) {
17
+ const metadataStart = html.indexOf(METADATA_START);
18
+ if (metadataStart === -1) return null;
19
+ const metadataContentStart = metadataStart + 29;
20
+ const metadataEnd = html.indexOf(METADATA_END, metadataContentStart);
21
+ if (metadataEnd === -1) return null;
22
+ const encoded = html.slice(metadataContentStart, metadataEnd);
23
+ let artifacts;
24
+ try {
25
+ artifacts = JSON.parse(Buffer.from(encoded, "base64").toString("utf8"));
26
+ } catch {
27
+ return null;
28
+ }
29
+ const styleStart = html.lastIndexOf("<style data-tasty-ssr", metadataStart);
30
+ if (styleStart === -1) return null;
31
+ const styleOpenEnd = html.indexOf(">", styleStart);
32
+ const styleEnd = html.indexOf("</style>", styleOpenEnd + 1);
33
+ if (styleOpenEnd === -1 || styleEnd === -1 || styleEnd + 8 !== metadataStart) return null;
34
+ return {
35
+ path,
36
+ html,
37
+ artifacts,
38
+ styleStart,
39
+ replacementEnd: metadataEnd + 11,
40
+ styleOpen: html.slice(styleStart, styleOpenEnd + 1)
41
+ };
42
+ }
43
+ async function findHTMLFiles(dir) {
44
+ const paths = [];
45
+ const entries = await readdir(dir, { withFileTypes: true });
46
+ entries.sort((a, b) => a.name.localeCompare(b.name));
47
+ for (const entry of entries) {
48
+ const path = join(dir, entry.name);
49
+ if (entry.isDirectory()) paths.push(...await findHTMLFiles(path));
50
+ else if (entry.isFile() && entry.name.endsWith(".html")) paths.push(path);
51
+ }
52
+ return paths;
53
+ }
54
+ function crossOriginAssetsPrefix(assetsPrefix, site) {
55
+ if (!assetsPrefix) return null;
56
+ const prefix = typeof assetsPrefix === "string" ? assetsPrefix : assetsPrefix.css || assetsPrefix.fallback;
57
+ if (!/^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(prefix)) return null;
58
+ if (!site) return prefix;
59
+ try {
60
+ return (prefix.startsWith("//") ? new URL(`${site.protocol}${prefix}`) : new URL(prefix)).origin === site.origin ? null : prefix;
61
+ } catch {
62
+ return prefix;
63
+ }
64
+ }
65
+ function validateExtractedURLs(pages, assetsPrefix, site) {
66
+ const externalPrefix = crossOriginAssetsPrefix(assetsPrefix, site);
67
+ for (const page of pages) for (const artifact of page.artifacts) {
68
+ const unsafe = findUnsafeCSSResource(artifact.css, externalPrefix !== null);
69
+ if (unsafe) {
70
+ const reason = unsafe.rootRelative ? `root-relative CSS URL "${unsafe.url}" would resolve against the external assetsPrefix "${externalPrefix}" instead of the page origin` : `page-relative CSS URL "${unsafe.url}" cannot preserve its target`;
71
+ throw new Error(`[Tasty] Astro CSS extraction cannot preserve ${reason} in ${page.path} (${artifact.kind} artifact ${artifact.id}). Use an absolute URL or a data URL${externalPrefix ? "" : ", or a root-relative URL such as url(/path/to/asset)"}.`);
72
+ }
73
+ }
74
+ }
75
+ /** Find artifacts emitted by every styled page, in the first page's order. */
76
+ function selectSharedArtifacts(pages) {
77
+ if (pages.length < 2) return [];
78
+ const source = pages[0].artifacts;
79
+ const otherIds = pages.slice(1).map((page) => new Set(page.artifacts.map(({ id }) => id)));
80
+ return source.filter(({ id }) => otherIds.every((ids) => ids.has(id)));
81
+ }
82
+ function stylesheetHref(base, assets, filename, assetsPrefix) {
83
+ const assetsPath = assets.replace(/^\/+|\/+$/g, "");
84
+ if (assetsPrefix) return `${(typeof assetsPrefix === "string" ? assetsPrefix : assetsPrefix.css || assetsPrefix.fallback).replace(/\/+$/g, "")}/${assetsPath}/${filename}`;
85
+ return `${base === "/" ? "" : `/${base.replace(/^\/+|\/+$/g, "")}`}/${assetsPath}/${filename}`;
86
+ }
87
+ function stylesheetLink(page, href) {
88
+ return `<link rel="stylesheet" href="${href}" data-tasty-ssr${page.styleOpen.match(/\snonce="[^"]*"/)?.[0] ?? ""}>`;
89
+ }
90
+ function transformPage(page, hrefs) {
91
+ const replacement = hrefs.map((href) => stylesheetLink(page, href)).join("");
92
+ return page.html.slice(0, page.styleStart) + replacement + page.html.slice(page.replacementEnd);
93
+ }
94
+ async function writeStylesheet(assetDir, scope, artifacts) {
95
+ if (artifacts.length === 0) return null;
96
+ const css = artifacts.map(({ css }) => css).join("\n");
97
+ const filename = `tasty.${scope}.${createHash("sha256").update(css).digest("hex").slice(0, 12)}.css`;
98
+ await writeFile(join(assetDir, filename), css);
99
+ return filename;
100
+ }
101
+ async function extractAstroCSS(options) {
102
+ const outputDir = fileURLToPath(options.dir);
103
+ const paths = await findHTMLFiles(outputDir);
104
+ const pages = (await Promise.all(paths.map(async (path) => parseExtractablePage(path, await readFile(path, "utf8"))))).filter((page) => page !== null);
105
+ if (pages.length === 0) return;
106
+ validateExtractedURLs(pages, options.assetsPrefix, options.site);
107
+ const shared = selectSharedArtifacts(pages);
108
+ const assetDir = join(outputDir, options.assets);
109
+ await mkdir(assetDir, { recursive: true });
110
+ const sharedFilename = await writeStylesheet(assetDir, "shared", shared);
111
+ const sharedHref = sharedFilename ? stylesheetHref(options.base, options.assets, sharedFilename, options.assetsPrefix) : null;
112
+ const sharedIds = new Set(shared.map(({ id }) => id));
113
+ for (const page of pages) {
114
+ const pageFilename = await writeStylesheet(assetDir, "page", page.artifacts.filter(({ id }) => !sharedIds.has(id)));
115
+ const hrefs = sharedHref ? [sharedHref] : [];
116
+ if (pageFilename) hrefs.push(stylesheetHref(options.base, options.assets, pageFilename, options.assetsPrefix));
117
+ await writeFile(page.path, transformPage(page, hrefs));
118
+ }
119
+ }
120
+ //#endregion
121
+ //#region src/ssr/astro.ts
122
+ /**
123
+ * Astro integration for Tasty SSR.
124
+ *
125
+ * Provides:
126
+ * - tastyIntegration() — Astro Integration API (recommended)
127
+ * - tastyMiddleware() — manual middleware for advanced composition
128
+ *
129
+ * Import from '@tenphi/tasty/ssr/astro'.
130
+ */
131
+ registerSSRCollectorGetterGlobal(getSSRCollector);
132
+ /**
133
+ * Create an Astro middleware that collects Tasty styles during SSR.
134
+ *
135
+ * All React components rendered during the request will have their
136
+ * computeStyles() calls captured by the collector via AsyncLocalStorage.
137
+ * After rendering, the middleware injects the collected CSS into </head>.
138
+ *
139
+ * @example Manual middleware setup
140
+ * ```ts
141
+ * // src/middleware.ts
142
+ * import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
143
+ * export const onRequest = tastyMiddleware();
144
+ * ```
145
+ *
146
+ * @example Composing with other middleware
147
+ * ```ts
148
+ * // src/middleware.ts
149
+ * import { sequence } from 'astro:middleware';
150
+ * import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
151
+ *
152
+ * export const onRequest = sequence(
153
+ * tastyMiddleware(),
154
+ * myOtherMiddleware,
155
+ * );
156
+ * ```
157
+ */
158
+ function tastyMiddleware(options) {
159
+ const internalOptions = options;
160
+ return async (context, next) => {
161
+ const transferCache = options?.transferCache ?? true;
162
+ const extractionMetadata = internalOptions?.extractionMetadata === true && context.isPrerendered === true;
163
+ const collector = new ServerStyleCollector();
164
+ const rendered = await runWithCollector(collector, async () => {
165
+ const response = await next();
166
+ const body = response.body;
167
+ const contentType = response.headers.get("content-type") ?? "";
168
+ if (!body || !contentType.includes("text/html")) return { response };
169
+ const reader = body.pipeThrough(new TextDecoderStream()).getReader();
170
+ const parts = [];
171
+ for (;;) {
172
+ const { done, value } = await reader.read();
173
+ if (done) break;
174
+ parts.push(value);
175
+ }
176
+ return {
177
+ html: parts.join(""),
178
+ status: response.status,
179
+ headers: response.headers
180
+ };
181
+ });
182
+ if ("response" in rendered) return rendered.response;
183
+ if (!rendered.html) return new Response(null, {
184
+ status: rendered.status,
185
+ headers: rendered.headers
186
+ });
187
+ let { html } = rendered;
188
+ const css = collector.getCSS();
189
+ if (!css) return new Response(html, {
190
+ status: rendered.status,
191
+ headers: rendered.headers
192
+ });
193
+ const nonce = getConfig().nonce;
194
+ const nonceAttr = nonce ? ` nonce="${nonce}"` : "";
195
+ const styleTag = `<style data-tasty-ssr${nonceAttr}>${css}</style>`;
196
+ const metadataTag = extractionMetadata ? createExtractionMetadata(collector.getArtifacts()) : "";
197
+ let cacheTag = "";
198
+ if (transferCache) {
199
+ const classNames = collector.getRenderedClassNames();
200
+ if (classNames.length > 0) cacheTag = `<script${nonceAttr}>(window.__TASTY__=window.__TASTY__||[]).push(${classNames.map((n) => `"${n}"`).join(",")})<\/script>`;
201
+ }
202
+ const injection = styleTag + metadataTag + cacheTag;
203
+ const idx = html.indexOf("</head>");
204
+ if (idx !== -1) html = html.slice(0, idx) + injection + html.slice(idx);
205
+ else html = injection + html;
206
+ const headers = new Headers(rendered.headers);
207
+ headers.delete("content-length");
208
+ return new Response(html, {
209
+ status: rendered.status,
210
+ headers
211
+ });
212
+ };
213
+ }
214
+ /**
215
+ * Package subpaths of the middleware entrypoints registered by
216
+ * `tastyIntegration()`.
217
+ *
218
+ * These must be bare specifiers rather than
219
+ * `new URL('./astro-middleware.js', import.meta.url)`. The bundler is free to
220
+ * hoist `tastyIntegration` into a shared chunk at a different directory depth
221
+ * than `dist/ssr/`, which makes a relative URL resolve to a file that does not
222
+ * exist and breaks the build for every consumer. A package subpath is resolved
223
+ * by the consumer through our `exports` map, so it never depends on the
224
+ * chunk layout.
225
+ *
226
+ * There are separate entrypoints instead of one parameterised entrypoint because
227
+ * `addMiddleware()` cannot pass options: the integration runs when the Astro
228
+ * config is loaded, while the middleware module is evaluated in the server
229
+ * runtime — a different process for built output — so module-level state set
230
+ * by the integration is not visible to the middleware.
231
+ */
232
+ const MIDDLEWARE_ENTRYPOINT = "@tenphi/tasty/ssr/astro-middleware";
233
+ const MIDDLEWARE_ENTRYPOINT_STATIC = "@tenphi/tasty/ssr/astro-middleware-static";
234
+ const MIDDLEWARE_ENTRYPOINT_EXTRACT = "@tenphi/tasty/ssr/astro-middleware-extract";
235
+ const MIDDLEWARE_ENTRYPOINT_EXTRACT_STATIC = "@tenphi/tasty/ssr/astro-middleware-extract-static";
236
+ /**
237
+ * Astro integration that automatically sets up Tasty SSR.
238
+ *
239
+ * Registers middleware for cross-component CSS deduplication and
240
+ * optionally injects a client hydration script for island support.
241
+ *
242
+ * @example Basic setup (with islands)
243
+ * ```ts
244
+ * // astro.config.mjs
245
+ * import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
246
+ *
247
+ * export default defineConfig({
248
+ * integrations: [tastyIntegration()],
249
+ * });
250
+ * ```
251
+ *
252
+ * @example Static-only (no client JS)
253
+ * ```ts
254
+ * // astro.config.mjs
255
+ * import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
256
+ *
257
+ * export default defineConfig({
258
+ * integrations: [tastyIntegration({ islands: false })],
259
+ * });
260
+ * ```
261
+ */
262
+ function tastyIntegration(options) {
263
+ const { islands = true } = options ?? {};
264
+ const cssMode = options?.css?.mode ?? "inline";
265
+ let base = "/";
266
+ let assets = "_astro";
267
+ let assetsPrefix;
268
+ let site;
269
+ return {
270
+ name: "@tenphi/tasty",
271
+ hooks: {
272
+ "astro:config:setup": ({ addMiddleware, injectScript }) => {
273
+ addMiddleware({
274
+ entrypoint: cssMode === "extract" ? islands ? MIDDLEWARE_ENTRYPOINT_EXTRACT : MIDDLEWARE_ENTRYPOINT_EXTRACT_STATIC : islands ? MIDDLEWARE_ENTRYPOINT : MIDDLEWARE_ENTRYPOINT_STATIC,
275
+ order: "pre"
276
+ });
277
+ if (islands) injectScript("before-hydration", `import "@tenphi/tasty/ssr/astro-client";`);
278
+ },
279
+ "astro:config:done": ({ config }) => {
280
+ base = config.base ?? "/";
281
+ assets = config.build?.assets ?? "_astro";
282
+ assetsPrefix = config.build?.assetsPrefix;
283
+ site = config.site;
284
+ },
285
+ "astro:build:done": async ({ dir }) => {
286
+ if (cssMode !== "extract") return;
287
+ await extractAstroCSS({
288
+ dir,
289
+ base,
290
+ assets,
291
+ assetsPrefix,
292
+ site
293
+ });
294
+ }
295
+ }
296
+ };
297
+ }
298
+ //#endregion
299
+ export { tastyMiddleware as n, tastyIntegration as t };
300
+
301
+ //# sourceMappingURL=astro-CeYENy2x.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-CeYENy2x.js","names":[],"sources":["../src/ssr/astro-extraction.ts","../src/ssr/astro.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport { readdir, readFile, writeFile, mkdir } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type { ServerStyleArtifact } from './collector';\nimport { findUnsafeCSSResource } from './css-resources';\n\nconst METADATA_START = '<template data-tasty-extract>';\nconst METADATA_END = '</template>';\n\ninterface ExtractablePage {\n path: string;\n html: string;\n artifacts: ServerStyleArtifact[];\n styleStart: number;\n replacementEnd: number;\n styleOpen: string;\n}\n\nexport function createExtractionMetadata(\n artifacts: ServerStyleArtifact[],\n): string {\n const encoded = Buffer.from(JSON.stringify(artifacts), 'utf8').toString(\n 'base64',\n );\n return `${METADATA_START}${encoded}${METADATA_END}`;\n}\n\nfunction parseExtractablePage(\n path: string,\n html: string,\n): ExtractablePage | null {\n const metadataStart = html.indexOf(METADATA_START);\n if (metadataStart === -1) return null;\n\n const metadataContentStart = metadataStart + METADATA_START.length;\n const metadataEnd = html.indexOf(METADATA_END, metadataContentStart);\n if (metadataEnd === -1) return null;\n\n const encoded = html.slice(metadataContentStart, metadataEnd);\n let artifacts: ServerStyleArtifact[];\n try {\n artifacts = JSON.parse(\n Buffer.from(encoded, 'base64').toString('utf8'),\n ) as ServerStyleArtifact[];\n } catch {\n return null;\n }\n\n const styleStart = html.lastIndexOf('<style data-tasty-ssr', metadataStart);\n if (styleStart === -1) return null;\n const styleOpenEnd = html.indexOf('>', styleStart);\n const styleEnd = html.indexOf('</style>', styleOpenEnd + 1);\n if (\n styleOpenEnd === -1 ||\n styleEnd === -1 ||\n styleEnd + '</style>'.length !== metadataStart\n ) {\n return null;\n }\n\n return {\n path,\n html,\n artifacts,\n styleStart,\n replacementEnd: metadataEnd + METADATA_END.length,\n styleOpen: html.slice(styleStart, styleOpenEnd + 1),\n };\n}\n\nasync function findHTMLFiles(dir: string): Promise<string[]> {\n const paths: string[] = [];\n const entries = await readdir(dir, { withFileTypes: true });\n entries.sort((a, b) => a.name.localeCompare(b.name));\n for (const entry of entries) {\n const path = join(dir, entry.name);\n if (entry.isDirectory()) {\n paths.push(...(await findHTMLFiles(path)));\n } else if (entry.isFile() && entry.name.endsWith('.html')) {\n paths.push(path);\n }\n }\n return paths;\n}\n\nfunction crossOriginAssetsPrefix(\n assetsPrefix?: string | Record<string, string>,\n site?: URL,\n): string | null {\n if (!assetsPrefix) return null;\n const prefix =\n typeof assetsPrefix === 'string'\n ? assetsPrefix\n : assetsPrefix.css || assetsPrefix.fallback;\n if (!/^(?:[a-z][a-z\\d+.-]*:|\\/\\/)/i.test(prefix)) return null;\n if (!site) return prefix;\n\n try {\n const prefixURL = prefix.startsWith('//')\n ? new URL(`${site.protocol}${prefix}`)\n : new URL(prefix);\n return prefixURL.origin === site.origin ? null : prefix;\n } catch {\n return prefix;\n }\n}\n\nfunction validateExtractedURLs(\n pages: ExtractablePage[],\n assetsPrefix?: string | Record<string, string>,\n site?: URL,\n): void {\n const externalPrefix = crossOriginAssetsPrefix(assetsPrefix, site);\n for (const page of pages) {\n for (const artifact of page.artifacts) {\n const unsafe = findUnsafeCSSResource(\n artifact.css,\n externalPrefix !== null,\n );\n if (unsafe) {\n const reason = unsafe.rootRelative\n ? `root-relative CSS URL \"${unsafe.url}\" would resolve against the external assetsPrefix \"${externalPrefix}\" instead of the page origin`\n : `page-relative CSS URL \"${unsafe.url}\" cannot preserve its target`;\n throw new Error(\n `[Tasty] Astro CSS extraction cannot preserve ${reason} in ${page.path} (${artifact.kind} artifact ${artifact.id}). Use an absolute URL or a data URL${externalPrefix ? '' : ', or a root-relative URL such as url(/path/to/asset)'}.`,\n );\n }\n }\n }\n}\n\n/** Find artifacts emitted by every styled page, in the first page's order. */\nfunction selectSharedArtifacts(\n pages: ExtractablePage[],\n): ServerStyleArtifact[] {\n if (pages.length < 2) return [];\n\n const source = pages[0].artifacts;\n const otherIds = pages\n .slice(1)\n .map((page) => new Set(page.artifacts.map(({ id }) => id)));\n\n return source.filter(({ id }) => otherIds.every((ids) => ids.has(id)));\n}\n\nfunction stylesheetHref(\n base: string,\n assets: string,\n filename: string,\n assetsPrefix?: string | Record<string, string>,\n): string {\n const assetsPath = assets.replace(/^\\/+|\\/+$/g, '');\n if (assetsPrefix) {\n const prefix =\n typeof assetsPrefix === 'string'\n ? assetsPrefix\n : assetsPrefix.css || assetsPrefix.fallback;\n return `${prefix.replace(/\\/+$/g, '')}/${assetsPath}/${filename}`;\n }\n\n const basePath = base === '/' ? '' : `/${base.replace(/^\\/+|\\/+$/g, '')}`;\n return `${basePath}/${assetsPath}/${filename}`;\n}\n\nfunction stylesheetLink(page: ExtractablePage, href: string): string {\n const nonceAttr = page.styleOpen.match(/\\snonce=\"[^\"]*\"/)?.[0] ?? '';\n return `<link rel=\"stylesheet\" href=\"${href}\" data-tasty-ssr${nonceAttr}>`;\n}\n\nfunction transformPage(page: ExtractablePage, hrefs: string[]): string {\n const replacement = hrefs.map((href) => stylesheetLink(page, href)).join('');\n\n return (\n page.html.slice(0, page.styleStart) +\n replacement +\n page.html.slice(page.replacementEnd)\n );\n}\n\nasync function writeStylesheet(\n assetDir: string,\n scope: 'shared' | 'page',\n artifacts: ServerStyleArtifact[],\n): Promise<string | null> {\n if (artifacts.length === 0) return null;\n\n const css = artifacts.map(({ css }) => css).join('\\n');\n const hash = createHash('sha256').update(css).digest('hex').slice(0, 12);\n const filename = `tasty.${scope}.${hash}.css`;\n await writeFile(join(assetDir, filename), css);\n return filename;\n}\n\nexport async function extractAstroCSS(options: {\n dir: URL;\n base: string;\n assets: string;\n assetsPrefix?: string | Record<string, string>;\n site?: URL;\n}): Promise<void> {\n const outputDir = fileURLToPath(options.dir);\n const paths = await findHTMLFiles(outputDir);\n const pages = (\n await Promise.all(\n paths.map(async (path) =>\n parseExtractablePage(path, await readFile(path, 'utf8')),\n ),\n )\n ).filter((page): page is ExtractablePage => page !== null);\n if (pages.length === 0) return;\n validateExtractedURLs(pages, options.assetsPrefix, options.site);\n\n const shared = selectSharedArtifacts(pages);\n const assetDir = join(outputDir, options.assets);\n await mkdir(assetDir, { recursive: true });\n const sharedFilename = await writeStylesheet(assetDir, 'shared', shared);\n const sharedHref = sharedFilename\n ? stylesheetHref(\n options.base,\n options.assets,\n sharedFilename,\n options.assetsPrefix,\n )\n : null;\n const sharedIds = new Set(shared.map(({ id }) => id));\n\n for (const page of pages) {\n const remainder = page.artifacts.filter(({ id }) => !sharedIds.has(id));\n const pageFilename = await writeStylesheet(assetDir, 'page', remainder);\n const hrefs = sharedHref ? [sharedHref] : [];\n if (pageFilename) {\n hrefs.push(\n stylesheetHref(\n options.base,\n options.assets,\n pageFilename,\n options.assetsPrefix,\n ),\n );\n }\n await writeFile(page.path, transformPage(page, hrefs));\n }\n}\n","/**\n * Astro integration for Tasty SSR.\n *\n * Provides:\n * - tastyIntegration() — Astro Integration API (recommended)\n * - tastyMiddleware() — manual middleware for advanced composition\n *\n * Import from '@tenphi/tasty/ssr/astro'.\n */\n\nimport { getConfig } from '../config';\nimport { getSSRCollector, runWithCollector } from './async-storage';\nimport { createExtractionMetadata, extractAstroCSS } from './astro-extraction';\nimport { ServerStyleCollector } from './collector';\nimport { registerSSRCollectorGetterGlobal } from './ssr-collector-ref';\n\n// Wire up ALS-based collector discovery so computeStyles() can find\n// the collector set by tastyMiddleware's runWithCollector().\n// Uses globalThis so the getter is visible across Astro's separate\n// module graphs (middleware vs page components).\nregisterSSRCollectorGetterGlobal(getSSRCollector);\n\nexport interface TastyMiddlewareOptions {\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\ninterface InternalTastyMiddlewareOptions extends TastyMiddlewareOptions {\n extractionMetadata?: boolean;\n}\n\n/**\n * Create an Astro middleware that collects Tasty styles during SSR.\n *\n * All React components rendered during the request will have their\n * computeStyles() calls captured by the collector via AsyncLocalStorage.\n * After rendering, the middleware injects the collected CSS into </head>.\n *\n * @example Manual middleware setup\n * ```ts\n * // src/middleware.ts\n * import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';\n * export const onRequest = tastyMiddleware();\n * ```\n *\n * @example Composing with other middleware\n * ```ts\n * // src/middleware.ts\n * import { sequence } from 'astro:middleware';\n * import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';\n *\n * export const onRequest = sequence(\n * tastyMiddleware(),\n * myOtherMiddleware,\n * );\n * ```\n */\nexport function tastyMiddleware(options?: TastyMiddlewareOptions) {\n const internalOptions = options as InternalTastyMiddlewareOptions | undefined;\n return async (\n context: { isPrerendered?: boolean },\n next: () => Promise<Response>,\n ): Promise<Response> => {\n const transferCache = options?.transferCache ?? true;\n const extractionMetadata =\n internalOptions?.extractionMetadata === true &&\n context.isPrerendered === true;\n const collector = new ServerStyleCollector();\n\n // Run the entire request — including body stream consumption — inside\n // the ALS context so that components rendering lazily during stream\n // reads can still find the collector via getSSRCollector().\n type Rendered =\n | { response: Response }\n | { html: string | null; status: number; headers: Headers };\n\n const rendered = await runWithCollector<Promise<Rendered>>(\n collector,\n async (): Promise<Rendered> => {\n const response = await next();\n const body = response.body;\n\n // Only process HTML responses. Reading a non-HTML body (e.g. an\n // image, font, or JSON endpoint) as UTF-8 text corrupts binary\n // payloads: every byte >= 0x80 is decoded to U+FFFD and re-encoded\n // as EF BF BD. Pass anything that isn't HTML straight through.\n const contentType = response.headers.get('content-type') ?? '';\n if (!body || !contentType.includes('text/html')) {\n return { response };\n }\n\n const reader = body.pipeThrough(new TextDecoderStream()).getReader();\n const parts: string[] = [];\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n parts.push(value);\n }\n return {\n html: parts.join(''),\n status: response.status,\n headers: response.headers,\n };\n },\n );\n\n // Non-HTML responses are returned untouched to avoid corrupting\n // binary payloads.\n if ('response' in rendered) {\n return rendered.response;\n }\n\n if (!rendered.html) {\n return new Response(null, {\n status: rendered.status,\n headers: rendered.headers,\n });\n }\n\n let { html } = rendered;\n\n const css = collector.getCSS();\n if (!css) {\n return new Response(html, {\n status: rendered.status,\n headers: rendered.headers,\n });\n }\n\n const nonce = getConfig().nonce;\n const nonceAttr = nonce ? ` nonce=\"${nonce}\"` : '';\n const styleTag = `<style data-tasty-ssr${nonceAttr}>${css}</style>`;\n const metadataTag = extractionMetadata\n ? createExtractionMetadata(collector.getArtifacts())\n : '';\n\n let cacheTag = '';\n if (transferCache) {\n const classNames = collector.getRenderedClassNames();\n if (classNames.length > 0) {\n const classListJSON = classNames.map((n) => `\"${n}\"`).join(',');\n cacheTag = `<script${nonceAttr}>(window.__TASTY__=window.__TASTY__||[]).push(${classListJSON})</script>`;\n }\n }\n\n const injection = styleTag + metadataTag + cacheTag;\n const idx = html.indexOf('</head>');\n if (idx !== -1) {\n html = html.slice(0, idx) + injection + html.slice(idx);\n } else {\n html = injection + html;\n }\n\n const headers = new Headers(rendered.headers);\n headers.delete('content-length');\n\n return new Response(html, {\n status: rendered.status,\n headers,\n });\n };\n}\n\n// ============================================================================\n// Astro Integration API\n// ============================================================================\n\n/**\n * Package subpaths of the middleware entrypoints registered by\n * `tastyIntegration()`.\n *\n * These must be bare specifiers rather than\n * `new URL('./astro-middleware.js', import.meta.url)`. The bundler is free to\n * hoist `tastyIntegration` into a shared chunk at a different directory depth\n * than `dist/ssr/`, which makes a relative URL resolve to a file that does not\n * exist and breaks the build for every consumer. A package subpath is resolved\n * by the consumer through our `exports` map, so it never depends on the\n * chunk layout.\n *\n * There are separate entrypoints instead of one parameterised entrypoint because\n * `addMiddleware()` cannot pass options: the integration runs when the Astro\n * config is loaded, while the middleware module is evaluated in the server\n * runtime — a different process for built output — so module-level state set\n * by the integration is not visible to the middleware.\n */\nconst MIDDLEWARE_ENTRYPOINT = '@tenphi/tasty/ssr/astro-middleware';\nconst MIDDLEWARE_ENTRYPOINT_STATIC =\n '@tenphi/tasty/ssr/astro-middleware-static';\nconst MIDDLEWARE_ENTRYPOINT_EXTRACT =\n '@tenphi/tasty/ssr/astro-middleware-extract';\nconst MIDDLEWARE_ENTRYPOINT_EXTRACT_STATIC =\n '@tenphi/tasty/ssr/astro-middleware-extract-static';\n\nexport interface TastyIntegrationCSSOptions {\n /**\n * CSS delivery mode. Extraction only applies to prerendered builds.\n * Extracted CSS preserves resource URLs verbatim, so use absolute URLs or\n * data URLs. Root-relative URLs are also supported unless `assetsPrefix`\n * sends CSS to an external origin. The build rejects resource URLs whose\n * targets would change after extraction.\n */\n mode?: 'inline' | 'extract';\n}\n\nexport interface TastyIntegrationOptions {\n /**\n * Enable island hydration support.\n *\n * When `true` (default): injects a client hydration script via\n * `injectScript('before-hydration')` and sets `transferCache: true`\n * on the middleware. Islands skip the style pipeline during hydration.\n *\n * When `false`: no client JS is shipped and `transferCache` is set\n * to `false`. Use this for fully static sites without `client:*`\n * directives.\n */\n islands?: boolean;\n /** Configure inline or build-wide extracted CSS delivery. */\n css?: TastyIntegrationCSSOptions;\n}\n\n/**\n * Astro integration that automatically sets up Tasty SSR.\n *\n * Registers middleware for cross-component CSS deduplication and\n * optionally injects a client hydration script for island support.\n *\n * @example Basic setup (with islands)\n * ```ts\n * // astro.config.mjs\n * import { tastyIntegration } from '@tenphi/tasty/ssr/astro';\n *\n * export default defineConfig({\n * integrations: [tastyIntegration()],\n * });\n * ```\n *\n * @example Static-only (no client JS)\n * ```ts\n * // astro.config.mjs\n * import { tastyIntegration } from '@tenphi/tasty/ssr/astro';\n *\n * export default defineConfig({\n * integrations: [tastyIntegration({ islands: false })],\n * });\n * ```\n */\nexport function tastyIntegration(options?: TastyIntegrationOptions) {\n const { islands = true } = options ?? {};\n const cssMode = options?.css?.mode ?? 'inline';\n let base = '/';\n let assets = '_astro';\n let assetsPrefix: string | Record<string, string> | undefined;\n let site: URL | undefined;\n\n return {\n name: '@tenphi/tasty',\n hooks: {\n 'astro:config:setup': ({\n addMiddleware,\n injectScript,\n }: {\n addMiddleware: (middleware: {\n entrypoint: string | URL;\n order: 'pre' | 'post';\n }) => void;\n injectScript: (\n stage: 'head-inline' | 'before-hydration' | 'page' | 'page-ssr',\n content: string,\n ) => void;\n }) => {\n addMiddleware({\n entrypoint:\n cssMode === 'extract'\n ? islands\n ? MIDDLEWARE_ENTRYPOINT_EXTRACT\n : MIDDLEWARE_ENTRYPOINT_EXTRACT_STATIC\n : islands\n ? MIDDLEWARE_ENTRYPOINT\n : MIDDLEWARE_ENTRYPOINT_STATIC,\n order: 'pre',\n });\n\n if (islands) {\n injectScript(\n 'before-hydration',\n `import \"@tenphi/tasty/ssr/astro-client\";`,\n );\n }\n },\n 'astro:config:done': ({\n config,\n }: {\n config: {\n base?: string;\n site?: URL;\n build?: {\n assets?: string;\n assetsPrefix?: string | Record<string, string>;\n };\n };\n }) => {\n base = config.base ?? '/';\n assets = config.build?.assets ?? '_astro';\n assetsPrefix = config.build?.assetsPrefix;\n site = config.site;\n },\n 'astro:build:done': async ({ dir }: { dir: URL }) => {\n if (cssMode !== 'extract') return;\n await extractAstroCSS({ dir, base, assets, assetsPrefix, site });\n },\n },\n };\n}\n"],"mappings":";;;;;;;;;;AAQA,MAAM,iBAAiB;AACvB,MAAM,eAAe;AAWrB,SAAgB,yBACd,WACQ;CAIR,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;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,wBAAwB;AAC9B,MAAM,+BACJ;AACF,MAAM,gCACJ;AACF,MAAM,uCACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDF,SAAgB,iBAAiB,SAAmC;CAClE,MAAM,EAAE,UAAU,SAAS,WAAW,CAAC;CACvC,MAAM,UAAU,SAAS,KAAK,QAAQ;CACtC,IAAI,OAAO;CACX,IAAI,SAAS;CACb,IAAI;CACJ,IAAI;CAEJ,OAAO;EACL,MAAM;EACN,OAAO;GACL,uBAAuB,EACrB,eACA,mBAUI;IACJ,cAAc;KACZ,YACE,YAAY,YACR,UACE,gCACA,uCACF,UACE,wBACA;KACR,OAAO;IACT,CAAC;IAED,IAAI,SACF,aACE,oBACA,0CACF;GAEJ;GACA,sBAAsB,EACpB,aAUI;IACJ,OAAO,OAAO,QAAQ;IACtB,SAAS,OAAO,OAAO,UAAU;IACjC,eAAe,OAAO,OAAO;IAC7B,OAAO,OAAO;GAChB;GACA,oBAAoB,OAAO,EAAE,UAAwB;IACnD,IAAI,YAAY,WAAW;IAC3B,MAAM,gBAAgB;KAAE;KAAK;KAAM;KAAQ;KAAc;IAAK,CAAC;GACjE;EACF;CACF;AACF"}
@@ -8,27 +8,37 @@ import { AsyncLocalStorage } from "node:async_hooks";
8
8
  * The middleware calls runWithCollector() around the render, and
9
9
  * useStyles() calls getSSRCollector() to find it.
10
10
  *
11
+ * Uses globalThis to ensure the AsyncLocalStorage instance is shared
12
+ * across module instances — frameworks like Astro may load middleware
13
+ * and page components from separate module graphs.
14
+ *
11
15
  * This module imports from 'node:async_hooks' — it must be excluded
12
16
  * from client bundles via the build configuration.
13
17
  */
14
- const tastySSRStorage = new AsyncLocalStorage();
18
+ const ALS_KEY = "__tasty_ssr_als__";
19
+ function getSharedStorage() {
20
+ const g = globalThis;
21
+ if (!g[ALS_KEY]) g[ALS_KEY] = new AsyncLocalStorage();
22
+ return g[ALS_KEY];
23
+ }
15
24
  /**
16
25
  * Run a function with a ServerStyleCollector bound to the current
17
26
  * async context. All useStyles() calls within `fn` (and any async
18
27
  * continuations) will find this collector via getSSRCollector().
19
28
  */
20
29
  function runWithCollector(collector, fn) {
21
- return tastySSRStorage.run(collector, fn);
30
+ return getSharedStorage().run(collector, fn);
22
31
  }
23
32
  /**
24
33
  * Retrieve the ServerStyleCollector bound to the current async context.
25
34
  * Returns null when called outside of runWithCollector() or on the client.
26
35
  */
27
36
  function getSSRCollector() {
28
- if (typeof tastySSRStorage?.getStore !== "function") return null;
29
- return tastySSRStorage.getStore() ?? null;
37
+ const storage = getSharedStorage();
38
+ if (typeof storage?.getStore !== "function") return null;
39
+ return storage.getStore() ?? null;
30
40
  }
31
41
  //#endregion
32
- export { getSSRCollector, runWithCollector };
42
+ export { runWithCollector as n, getSSRCollector as t };
33
43
 
34
- //# sourceMappingURL=async-storage.js.map
44
+ //# sourceMappingURL=async-storage-DKK-wTD4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-storage-DKK-wTD4.js","names":[],"sources":["../src/ssr/async-storage.ts"],"sourcesContent":["/**\n * AsyncLocalStorage integration for SSR collector discovery.\n *\n * Used by Astro middleware and generic framework integrations where\n * the library cannot wrap the React tree with a context provider.\n * The middleware calls runWithCollector() around the render, and\n * useStyles() calls getSSRCollector() to find it.\n *\n * Uses globalThis to ensure the AsyncLocalStorage instance is shared\n * across module instances — frameworks like Astro may load middleware\n * and page components from separate module graphs.\n *\n * This module imports from 'node:async_hooks' — it must be excluded\n * from client bundles via the build configuration.\n */\n\nimport { AsyncLocalStorage } from 'node:async_hooks';\n\nimport type { ServerStyleCollector } from './collector';\n\nconst ALS_KEY = '__tasty_ssr_als__';\n\nfunction getSharedStorage(): AsyncLocalStorage<ServerStyleCollector> {\n const g = globalThis as Record<string, unknown>;\n if (!g[ALS_KEY]) {\n g[ALS_KEY] = new AsyncLocalStorage<ServerStyleCollector>();\n }\n return g[ALS_KEY] as AsyncLocalStorage<ServerStyleCollector>;\n}\n\n/**\n * Run a function with a ServerStyleCollector bound to the current\n * async context. All useStyles() calls within `fn` (and any async\n * continuations) will find this collector via getSSRCollector().\n */\nexport function runWithCollector<T>(\n collector: ServerStyleCollector,\n fn: () => T,\n): T {\n return getSharedStorage().run(collector, fn);\n}\n\n/**\n * Retrieve the ServerStyleCollector bound to the current async context.\n * Returns null when called outside of runWithCollector() or on the client.\n */\nexport function getSSRCollector(): ServerStyleCollector | null {\n const storage = getSharedStorage();\n if (typeof storage?.getStore !== 'function') return null;\n return storage.getStore() ?? null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,MAAM,UAAU;AAEhB,SAAS,mBAA4D;CACnE,MAAM,IAAI;CACV,IAAI,CAAC,EAAE,UACL,EAAE,WAAW,IAAI,kBAAwC;CAE3D,OAAO,EAAE;AACX;;;;;;AAOA,SAAgB,iBACd,WACA,IACG;CACH,OAAO,iBAAiB,CAAC,CAAC,IAAI,WAAW,EAAE;AAC7C;;;;;AAMA,SAAgB,kBAA+C;CAC7D,MAAM,UAAU,iBAAiB;CACjC,IAAI,OAAO,SAAS,aAAa,YAAY,OAAO;CACpD,OAAO,QAAQ,SAAS,KAAK;AAC/B"}
@@ -0,0 +1,83 @@
1
+ import { t as TastyConfig } from "./config-LfIDmVHx.js";
2
+ import { PluginPass } from "@babel/core";
3
+
4
+ //#region src/zero/babel-types.d.ts
5
+ /**
6
+ * Build-time configuration for zero-runtime mode.
7
+ * Subset of TastyConfig excluding runtime-only DOM options
8
+ * (`nonce`, `maxRulesPerSheet`, `forceTextInjection`, `gc`)
9
+ * and overriding `devMode` default to `false`.
10
+ */
11
+ type TastyZeroConfig = Omit<TastyConfig, 'nonce' | 'maxRulesPerSheet' | 'forceTextInjection' | 'gc' | 'devMode'> & {
12
+ /**
13
+ * Enable development mode features: source comments in generated CSS.
14
+ * @default false
15
+ */
16
+ devMode?: boolean;
17
+ };
18
+ //#endregion
19
+ //#region src/zero/babel.d.ts
20
+ /**
21
+ * Options for the `@tenphi/tasty/babel-plugin` Babel plugin.
22
+ */
23
+ interface TastyZeroBabelOptions {
24
+ /** Output path for generated CSS (default: 'tasty.css') */
25
+ output?: string;
26
+ /**
27
+ * Tasty configuration for build-time processing.
28
+ * Can be a static object or a factory function that returns fresh config.
29
+ * A factory is called on each plugin invocation, enabling hot reload
30
+ * of config values that depend on external files (e.g. theme tokens).
31
+ */
32
+ config?: TastyZeroConfig | (() => TastyZeroConfig);
33
+ /**
34
+ * Absolute path to a TypeScript/JavaScript module that default-exports
35
+ * a `TastyZeroConfig` object. The module is loaded via jiti on each
36
+ * plugin invocation, enabling hot reload when the file changes.
37
+ *
38
+ * This option is JSON-serializable and is the primary way Turbopack
39
+ * passes config to the Babel plugin (since Turbopack loader options
40
+ * must be plain primitives/objects/arrays).
41
+ *
42
+ * When both `config` and `configFile` are set, `config` takes precedence.
43
+ *
44
+ * @example '/absolute/path/to/tasty-zero.config.ts'
45
+ */
46
+ configFile?: string;
47
+ /**
48
+ * Absolute file paths whose content affects the generated CSS.
49
+ * When any of these files change, babel-loader invalidates its cache
50
+ * and re-runs the plugin with fresh config values.
51
+ *
52
+ * Typically includes theme files that define Glaze palettes or token values.
53
+ * Paths must be absolute (resolved by the Next.js wrapper).
54
+ */
55
+ configDeps?: string[];
56
+ /**
57
+ * Automatically replace `@tenphi/tasty/static` imports with an import
58
+ * of the generated CSS file. This eliminates the need for users to
59
+ * manually import the CSS in their app entry point.
60
+ *
61
+ * @default true
62
+ */
63
+ injectImport?: boolean;
64
+ /**
65
+ * Output mode for extracted CSS.
66
+ *
67
+ * - `'file'` (default): CSS is written to a single output file and
68
+ * the `@tenphi/tasty/static` import is rewritten to import that file.
69
+ * - `'inject'`: CSS is embedded inline in the JS output and injected
70
+ * at runtime via a tiny injector from `@tenphi/tasty/static/inject`.
71
+ * No CSS file is written. Each `tastyStatic` call becomes
72
+ * self-contained. Best for reusable components and extensions.
73
+ *
74
+ * When `mode` is `'inject'`, `output` and `injectImport` are ignored.
75
+ *
76
+ * @default 'file'
77
+ */
78
+ mode?: 'file' | 'inject';
79
+ }
80
+ declare const _default: (api: object, options: TastyZeroBabelOptions | null | undefined, dirname: string) => import("@babel/core").PluginObj<PluginPass>;
81
+ //#endregion
82
+ export { _default as n, TastyZeroConfig as r, TastyZeroBabelOptions as t };
83
+ //# sourceMappingURL=babel-DWCsafYw.d.ts.map