@tenphi/tasty 0.0.0-snapshot.01d8a9e → 0.0.0-snapshot.03d34b4

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 (367) hide show
  1. package/README.md +181 -131
  2. package/dist/astro-DXccD0VE.js +368 -0
  3. package/dist/astro-DXccD0VE.js.map +1 -0
  4. package/dist/{ssr/async-storage.js → async-storage-DKK-wTD4.js} +2 -2
  5. package/dist/async-storage-DKK-wTD4.js.map +1 -0
  6. package/dist/babel-BUQGeOXA.d.ts +83 -0
  7. package/dist/collector-71FBDO0H.js +327 -0
  8. package/dist/collector-71FBDO0H.js.map +1 -0
  9. package/dist/collector-CLVr5_p3.d.ts +163 -0
  10. package/dist/config-B5kHzuNz.js +12269 -0
  11. package/dist/config-B5kHzuNz.js.map +1 -0
  12. package/dist/config-YsxGv4tq.d.ts +1263 -0
  13. package/dist/{ssr/context.js → context-CA8YKeMn.js} +11 -3
  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-Dr4u1NVD.js +1566 -0
  18. package/dist/core-Dr4u1NVD.js.map +1 -0
  19. package/dist/{zero/extractor.js → css-writer-B-J87ncv.js} +148 -24
  20. package/dist/css-writer-B-J87ncv.js.map +1 -0
  21. package/dist/{ssr/format-global-rules.js → format-global-rules-DklyaXv-.js} +2 -2
  22. package/dist/format-global-rules-DklyaXv-.js.map +1 -0
  23. package/dist/{ssr/format-rules.js → format-rules-DKOA-6qu.js} +59 -2
  24. package/dist/format-rules-DKOA-6qu.js.map +1 -0
  25. package/dist/{ssr/hydrate.js → hydrate-OeMX99We.js} +3 -11
  26. package/dist/hydrate-OeMX99We.js.map +1 -0
  27. package/dist/index-CBK778ne.d.ts +1911 -0
  28. package/dist/index-Cd45t5NM.d.ts +1521 -0
  29. package/dist/index.d.ts +5 -51
  30. package/dist/index.js +922 -36
  31. package/dist/index.js.map +1 -0
  32. package/dist/keyframes-CV8azJf3.js +493 -0
  33. package/dist/keyframes-CV8azJf3.js.map +1 -0
  34. package/dist/{utils/merge-styles.d.ts → merge-styles-CU7JbEwg.d.ts} +3 -3
  35. package/dist/{utils/merge-styles.js → merge-styles-oklji0KB.js} +3 -4
  36. package/dist/merge-styles-oklji0KB.js.map +1 -0
  37. package/dist/{utils/resolve-recipes.js → resolve-recipes-DTG81rzl.js} +4 -6
  38. package/dist/resolve-recipes-DTG81rzl.js.map +1 -0
  39. package/dist/ssr/astro-client.js +1 -1
  40. package/dist/ssr/astro-client.js.map +1 -1
  41. package/dist/ssr/astro-middleware-extract-static.d.ts +11 -0
  42. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  43. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  44. package/dist/ssr/astro-middleware-extract.d.ts +11 -0
  45. package/dist/ssr/astro-middleware-extract.js +9 -0
  46. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  47. package/dist/ssr/astro-middleware-static.d.ts +18 -0
  48. package/dist/ssr/astro-middleware-static.js +18 -0
  49. package/dist/ssr/astro-middleware-static.js.map +1 -0
  50. package/dist/ssr/astro-middleware.d.ts +11 -7
  51. package/dist/ssr/astro-middleware.js +10 -10
  52. package/dist/ssr/astro-middleware.js.map +1 -1
  53. package/dist/ssr/astro.d.ts +34 -16
  54. package/dist/ssr/astro.js +2 -149
  55. package/dist/ssr/index.d.ts +37 -4
  56. package/dist/ssr/index.js +5 -5
  57. package/dist/ssr/index.js.map +1 -1
  58. package/dist/ssr/next.d.ts +2 -3
  59. package/dist/ssr/next.js +7 -8
  60. package/dist/ssr/next.js.map +1 -1
  61. package/dist/static/index.d.ts +91 -5
  62. package/dist/static/index.js +49 -3
  63. package/dist/static/index.js.map +1 -0
  64. package/dist/static/inject.js.map +1 -1
  65. package/dist/zero/babel.d.ts +2 -81
  66. package/dist/zero/babel.js +45 -29
  67. package/dist/zero/babel.js.map +1 -1
  68. package/dist/zero/index.d.ts +81 -3
  69. package/dist/zero/index.js +2 -3
  70. package/dist/zero/next.d.ts +1 -1
  71. package/dist/zero/next.js +1 -1
  72. package/dist/zero/next.js.map +1 -1
  73. package/docs/README.md +18 -10
  74. package/docs/adoption.md +56 -31
  75. package/docs/ai-agents.md +224 -0
  76. package/docs/comparison.md +69 -40
  77. package/docs/configuration.md +501 -72
  78. package/docs/debug.md +18 -16
  79. package/docs/design-system.md +43 -24
  80. package/docs/dsl.md +512 -179
  81. package/docs/getting-started.md +60 -39
  82. package/docs/injector.md +60 -7
  83. package/docs/methodology.md +68 -36
  84. package/docs/migration-v3.md +285 -0
  85. package/docs/pipeline.md +741 -0
  86. package/docs/plugins.md +353 -0
  87. package/docs/react-api.md +164 -40
  88. package/docs/runtime-benchmarks.md +216 -0
  89. package/docs/ssr.md +138 -83
  90. package/docs/styles.md +65 -16
  91. package/docs/tasty-static.md +149 -99
  92. package/package.json +63 -21
  93. package/tasty.config.ts +6 -0
  94. package/dist/_virtual/_rolldown/runtime.js +0 -7
  95. package/dist/chunks/cacheKey.d.ts +0 -1
  96. package/dist/chunks/cacheKey.js +0 -77
  97. package/dist/chunks/cacheKey.js.map +0 -1
  98. package/dist/chunks/definitions.d.ts +0 -37
  99. package/dist/chunks/definitions.js +0 -258
  100. package/dist/chunks/definitions.js.map +0 -1
  101. package/dist/chunks/index.d.ts +0 -1
  102. package/dist/chunks/renderChunk.d.ts +0 -1
  103. package/dist/chunks/renderChunk.js +0 -59
  104. package/dist/chunks/renderChunk.js.map +0 -1
  105. package/dist/compute-styles.d.ts +0 -31
  106. package/dist/compute-styles.js +0 -336
  107. package/dist/compute-styles.js.map +0 -1
  108. package/dist/config.d.ts +0 -407
  109. package/dist/config.js +0 -591
  110. package/dist/config.js.map +0 -1
  111. package/dist/counter-style/index.js +0 -51
  112. package/dist/counter-style/index.js.map +0 -1
  113. package/dist/debug.d.ts +0 -89
  114. package/dist/debug.js +0 -453
  115. package/dist/debug.js.map +0 -1
  116. package/dist/font-face/index.js +0 -63
  117. package/dist/font-face/index.js.map +0 -1
  118. package/dist/hooks/index.d.ts +0 -7
  119. package/dist/hooks/useCounterStyle.d.ts +0 -36
  120. package/dist/hooks/useCounterStyle.js +0 -65
  121. package/dist/hooks/useCounterStyle.js.map +0 -1
  122. package/dist/hooks/useFontFace.d.ts +0 -45
  123. package/dist/hooks/useFontFace.js +0 -66
  124. package/dist/hooks/useFontFace.js.map +0 -1
  125. package/dist/hooks/useGlobalStyles.d.ts +0 -46
  126. package/dist/hooks/useGlobalStyles.js +0 -88
  127. package/dist/hooks/useGlobalStyles.js.map +0 -1
  128. package/dist/hooks/useKeyframes.d.ts +0 -58
  129. package/dist/hooks/useKeyframes.js +0 -55
  130. package/dist/hooks/useKeyframes.js.map +0 -1
  131. package/dist/hooks/useProperty.d.ts +0 -81
  132. package/dist/hooks/useProperty.js +0 -96
  133. package/dist/hooks/useProperty.js.map +0 -1
  134. package/dist/hooks/useRawCSS.d.ts +0 -22
  135. package/dist/hooks/useRawCSS.js +0 -103
  136. package/dist/hooks/useRawCSS.js.map +0 -1
  137. package/dist/hooks/useStyles.d.ts +0 -40
  138. package/dist/hooks/useStyles.js +0 -31
  139. package/dist/hooks/useStyles.js.map +0 -1
  140. package/dist/injector/index.d.ts +0 -182
  141. package/dist/injector/index.js +0 -185
  142. package/dist/injector/index.js.map +0 -1
  143. package/dist/injector/injector.d.ts +0 -198
  144. package/dist/injector/injector.js +0 -651
  145. package/dist/injector/injector.js.map +0 -1
  146. package/dist/injector/sheet-manager.d.ts +0 -132
  147. package/dist/injector/sheet-manager.js +0 -699
  148. package/dist/injector/sheet-manager.js.map +0 -1
  149. package/dist/injector/types.d.ts +0 -235
  150. package/dist/keyframes/index.js +0 -206
  151. package/dist/keyframes/index.js.map +0 -1
  152. package/dist/parser/classify.js +0 -319
  153. package/dist/parser/classify.js.map +0 -1
  154. package/dist/parser/const.js +0 -60
  155. package/dist/parser/const.js.map +0 -1
  156. package/dist/parser/lru.js +0 -109
  157. package/dist/parser/lru.js.map +0 -1
  158. package/dist/parser/parser.d.ts +0 -25
  159. package/dist/parser/parser.js +0 -115
  160. package/dist/parser/parser.js.map +0 -1
  161. package/dist/parser/tokenizer.js +0 -69
  162. package/dist/parser/tokenizer.js.map +0 -1
  163. package/dist/parser/types.d.ts +0 -51
  164. package/dist/parser/types.js +0 -46
  165. package/dist/parser/types.js.map +0 -1
  166. package/dist/pipeline/conditions.d.ts +0 -134
  167. package/dist/pipeline/conditions.js +0 -406
  168. package/dist/pipeline/conditions.js.map +0 -1
  169. package/dist/pipeline/exclusive.js +0 -283
  170. package/dist/pipeline/exclusive.js.map +0 -1
  171. package/dist/pipeline/index.d.ts +0 -55
  172. package/dist/pipeline/index.js +0 -708
  173. package/dist/pipeline/index.js.map +0 -1
  174. package/dist/pipeline/materialize.js +0 -1157
  175. package/dist/pipeline/materialize.js.map +0 -1
  176. package/dist/pipeline/parseStateKey.d.ts +0 -15
  177. package/dist/pipeline/parseStateKey.js +0 -446
  178. package/dist/pipeline/parseStateKey.js.map +0 -1
  179. package/dist/pipeline/simplify.js +0 -690
  180. package/dist/pipeline/simplify.js.map +0 -1
  181. package/dist/pipeline/warnings.js +0 -18
  182. package/dist/pipeline/warnings.js.map +0 -1
  183. package/dist/plugins/index.d.ts +0 -2
  184. package/dist/plugins/okhsl-plugin.d.ts +0 -35
  185. package/dist/plugins/okhsl-plugin.js +0 -97
  186. package/dist/plugins/okhsl-plugin.js.map +0 -1
  187. package/dist/plugins/types.d.ts +0 -87
  188. package/dist/properties/index.js +0 -222
  189. package/dist/properties/index.js.map +0 -1
  190. package/dist/properties/property-type-resolver.d.ts +0 -24
  191. package/dist/properties/property-type-resolver.js +0 -90
  192. package/dist/properties/property-type-resolver.js.map +0 -1
  193. package/dist/rsc-cache.js +0 -79
  194. package/dist/rsc-cache.js.map +0 -1
  195. package/dist/ssr/astro.js.map +0 -1
  196. package/dist/ssr/async-storage.d.ts +0 -17
  197. package/dist/ssr/async-storage.js.map +0 -1
  198. package/dist/ssr/collect-auto-properties.js +0 -58
  199. package/dist/ssr/collect-auto-properties.js.map +0 -1
  200. package/dist/ssr/collector.d.ts +0 -94
  201. package/dist/ssr/collector.js +0 -233
  202. package/dist/ssr/collector.js.map +0 -1
  203. package/dist/ssr/context.js.map +0 -1
  204. package/dist/ssr/format-global-rules.js.map +0 -1
  205. package/dist/ssr/format-keyframes.js +0 -69
  206. package/dist/ssr/format-keyframes.js.map +0 -1
  207. package/dist/ssr/format-property.js +0 -49
  208. package/dist/ssr/format-property.js.map +0 -1
  209. package/dist/ssr/format-rules.js.map +0 -1
  210. package/dist/ssr/hydrate.d.ts +0 -29
  211. package/dist/ssr/hydrate.js.map +0 -1
  212. package/dist/ssr/ssr-collector-ref.js +0 -29
  213. package/dist/ssr/ssr-collector-ref.js.map +0 -1
  214. package/dist/states/index.d.ts +0 -49
  215. package/dist/states/index.js +0 -170
  216. package/dist/states/index.js.map +0 -1
  217. package/dist/static/tastyStatic.d.ts +0 -46
  218. package/dist/static/tastyStatic.js +0 -30
  219. package/dist/static/tastyStatic.js.map +0 -1
  220. package/dist/static/types.d.ts +0 -49
  221. package/dist/static/types.js +0 -24
  222. package/dist/static/types.js.map +0 -1
  223. package/dist/styles/border.d.ts +0 -25
  224. package/dist/styles/border.js +0 -120
  225. package/dist/styles/border.js.map +0 -1
  226. package/dist/styles/color.d.ts +0 -14
  227. package/dist/styles/color.js +0 -26
  228. package/dist/styles/color.js.map +0 -1
  229. package/dist/styles/const.js +0 -17
  230. package/dist/styles/const.js.map +0 -1
  231. package/dist/styles/createStyle.js +0 -79
  232. package/dist/styles/createStyle.js.map +0 -1
  233. package/dist/styles/dimension.js +0 -109
  234. package/dist/styles/dimension.js.map +0 -1
  235. package/dist/styles/directional.js +0 -133
  236. package/dist/styles/directional.js.map +0 -1
  237. package/dist/styles/display.d.ts +0 -30
  238. package/dist/styles/display.js +0 -73
  239. package/dist/styles/display.js.map +0 -1
  240. package/dist/styles/fade.d.ts +0 -15
  241. package/dist/styles/fade.js +0 -62
  242. package/dist/styles/fade.js.map +0 -1
  243. package/dist/styles/fill.d.ts +0 -42
  244. package/dist/styles/fill.js +0 -51
  245. package/dist/styles/fill.js.map +0 -1
  246. package/dist/styles/flow.d.ts +0 -16
  247. package/dist/styles/flow.js +0 -12
  248. package/dist/styles/flow.js.map +0 -1
  249. package/dist/styles/gap.d.ts +0 -31
  250. package/dist/styles/gap.js +0 -38
  251. package/dist/styles/gap.js.map +0 -1
  252. package/dist/styles/height.d.ts +0 -17
  253. package/dist/styles/height.js +0 -19
  254. package/dist/styles/height.js.map +0 -1
  255. package/dist/styles/index.d.ts +0 -1
  256. package/dist/styles/index.js +0 -8
  257. package/dist/styles/index.js.map +0 -1
  258. package/dist/styles/inset.d.ts +0 -24
  259. package/dist/styles/inset.js +0 -34
  260. package/dist/styles/inset.js.map +0 -1
  261. package/dist/styles/list.d.ts +0 -16
  262. package/dist/styles/list.js +0 -100
  263. package/dist/styles/list.js.map +0 -1
  264. package/dist/styles/margin.d.ts +0 -24
  265. package/dist/styles/margin.js +0 -32
  266. package/dist/styles/margin.js.map +0 -1
  267. package/dist/styles/outline.d.ts +0 -29
  268. package/dist/styles/outline.js +0 -55
  269. package/dist/styles/outline.js.map +0 -1
  270. package/dist/styles/padding.d.ts +0 -24
  271. package/dist/styles/padding.js +0 -32
  272. package/dist/styles/padding.js.map +0 -1
  273. package/dist/styles/placement.d.ts +0 -37
  274. package/dist/styles/placement.js +0 -74
  275. package/dist/styles/placement.js.map +0 -1
  276. package/dist/styles/predefined.d.ts +0 -71
  277. package/dist/styles/predefined.js +0 -237
  278. package/dist/styles/predefined.js.map +0 -1
  279. package/dist/styles/preset.d.ts +0 -52
  280. package/dist/styles/preset.js +0 -127
  281. package/dist/styles/preset.js.map +0 -1
  282. package/dist/styles/radius.d.ts +0 -12
  283. package/dist/styles/radius.js +0 -83
  284. package/dist/styles/radius.js.map +0 -1
  285. package/dist/styles/scrollMargin.d.ts +0 -24
  286. package/dist/styles/scrollMargin.js +0 -32
  287. package/dist/styles/scrollMargin.js.map +0 -1
  288. package/dist/styles/scrollbar.d.ts +0 -25
  289. package/dist/styles/scrollbar.js +0 -51
  290. package/dist/styles/scrollbar.js.map +0 -1
  291. package/dist/styles/shadow.d.ts +0 -14
  292. package/dist/styles/shadow.js +0 -25
  293. package/dist/styles/shadow.js.map +0 -1
  294. package/dist/styles/shared.js +0 -17
  295. package/dist/styles/shared.js.map +0 -1
  296. package/dist/styles/transition.d.ts +0 -14
  297. package/dist/styles/transition.js +0 -159
  298. package/dist/styles/transition.js.map +0 -1
  299. package/dist/styles/types.d.ts +0 -564
  300. package/dist/styles/width.d.ts +0 -17
  301. package/dist/styles/width.js +0 -19
  302. package/dist/styles/width.js.map +0 -1
  303. package/dist/tasty.d.ts +0 -134
  304. package/dist/tasty.js +0 -248
  305. package/dist/tasty.js.map +0 -1
  306. package/dist/types.d.ts +0 -184
  307. package/dist/utils/cache-wrapper.js +0 -21
  308. package/dist/utils/cache-wrapper.js.map +0 -1
  309. package/dist/utils/case-converter.js +0 -8
  310. package/dist/utils/case-converter.js.map +0 -1
  311. package/dist/utils/color-math.d.ts +0 -46
  312. package/dist/utils/color-math.js +0 -749
  313. package/dist/utils/color-math.js.map +0 -1
  314. package/dist/utils/color-space.d.ts +0 -5
  315. package/dist/utils/color-space.js +0 -228
  316. package/dist/utils/color-space.js.map +0 -1
  317. package/dist/utils/colors.d.ts +0 -5
  318. package/dist/utils/colors.js +0 -10
  319. package/dist/utils/colors.js.map +0 -1
  320. package/dist/utils/css-types.d.ts +0 -7
  321. package/dist/utils/deps-equal.js +0 -15
  322. package/dist/utils/deps-equal.js.map +0 -1
  323. package/dist/utils/dotize.d.ts +0 -26
  324. package/dist/utils/dotize.js +0 -122
  325. package/dist/utils/dotize.js.map +0 -1
  326. package/dist/utils/filter-base-props.d.ts +0 -15
  327. package/dist/utils/filter-base-props.js +0 -45
  328. package/dist/utils/filter-base-props.js.map +0 -1
  329. package/dist/utils/get-display-name.d.ts +0 -7
  330. package/dist/utils/get-display-name.js +0 -10
  331. package/dist/utils/get-display-name.js.map +0 -1
  332. package/dist/utils/has-keys.js +0 -13
  333. package/dist/utils/has-keys.js.map +0 -1
  334. package/dist/utils/hash.js +0 -14
  335. package/dist/utils/hash.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 -58
  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
@@ -0,0 +1,368 @@
1
+ import { n as getConfig } from "./config-B5kHzuNz.js";
2
+ import { a as registerSSRCollectorGetterGlobal } from "./format-rules-DKOA-6qu.js";
3
+ import { t as ServerStyleCollector } from "./collector-71FBDO0H.js";
4
+ import { n as runWithCollector, t as getSSRCollector } from "./async-storage-DKK-wTD4.js";
5
+ import { createHash } from "node:crypto";
6
+ import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
7
+ import { join } from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+ //#region src/ssr/astro-extraction.ts
10
+ const METADATA_START = "<template data-tasty-extract>";
11
+ const METADATA_END = "</template>";
12
+ function createExtractionMetadata(artifacts) {
13
+ return `${METADATA_START}${Buffer.from(JSON.stringify(artifacts), "utf8").toString("base64")}${METADATA_END}`;
14
+ }
15
+ function parseExtractablePage(path, html) {
16
+ const metadataStart = html.indexOf(METADATA_START);
17
+ if (metadataStart === -1) return null;
18
+ const metadataContentStart = metadataStart + 29;
19
+ const metadataEnd = html.indexOf(METADATA_END, metadataContentStart);
20
+ if (metadataEnd === -1) return null;
21
+ const encoded = html.slice(metadataContentStart, metadataEnd);
22
+ let artifacts;
23
+ try {
24
+ artifacts = JSON.parse(Buffer.from(encoded, "base64").toString("utf8"));
25
+ } catch {
26
+ return null;
27
+ }
28
+ const styleStart = html.lastIndexOf("<style data-tasty-ssr", metadataStart);
29
+ if (styleStart === -1) return null;
30
+ const styleOpenEnd = html.indexOf(">", styleStart);
31
+ const styleEnd = html.indexOf("</style>", styleOpenEnd + 1);
32
+ if (styleOpenEnd === -1 || styleEnd === -1 || styleEnd + 8 !== metadataStart) return null;
33
+ return {
34
+ path,
35
+ html,
36
+ artifacts,
37
+ styleStart,
38
+ replacementEnd: metadataEnd + 11,
39
+ styleOpen: html.slice(styleStart, styleOpenEnd + 1)
40
+ };
41
+ }
42
+ async function findHTMLFiles(dir) {
43
+ const paths = [];
44
+ const entries = await readdir(dir, { withFileTypes: true });
45
+ entries.sort((a, b) => a.name.localeCompare(b.name));
46
+ for (const entry of entries) {
47
+ const path = join(dir, entry.name);
48
+ if (entry.isDirectory()) paths.push(...await findHTMLFiles(path));
49
+ else if (entry.isFile() && entry.name.endsWith(".html")) paths.push(path);
50
+ }
51
+ return paths;
52
+ }
53
+ function findSequence(haystack, needle) {
54
+ if (needle.length === 0) return -1;
55
+ outer: for (let i = 0; i <= haystack.length - needle.length; i++) {
56
+ for (let j = 0; j < needle.length; j++) if (haystack[i + j] !== needle[j]) continue outer;
57
+ return i;
58
+ }
59
+ return -1;
60
+ }
61
+ /** Find the largest byte-sized artifact block that is contiguous on every page. */
62
+ function selectSharedArtifacts(pages) {
63
+ if (pages.length < 2) return [];
64
+ const source = pages.reduce((shortest, page) => page.artifacts.length < shortest.artifacts.length ? page : shortest);
65
+ const otherIds = pages.filter((page) => page !== source).map((page) => page.artifacts.map(({ id }) => id));
66
+ const sourceIds = source.artifacts.map(({ id }) => id);
67
+ let best = [];
68
+ let bestBytes = 0;
69
+ for (let start = 0; start < source.artifacts.length; start++) {
70
+ let length = source.artifacts.length - start;
71
+ for (const pageIds of otherIds) {
72
+ let pageLength = 0;
73
+ for (let pageStart = 0; pageStart < pageIds.length; pageStart++) {
74
+ if (pageIds[pageStart] !== sourceIds[start]) continue;
75
+ let matchLength = 1;
76
+ while (start + matchLength < sourceIds.length && pageStart + matchLength < pageIds.length && sourceIds[start + matchLength] === pageIds[pageStart + matchLength]) matchLength++;
77
+ pageLength = Math.max(pageLength, matchLength);
78
+ }
79
+ length = Math.min(length, pageLength);
80
+ if (length === 0) break;
81
+ }
82
+ const candidate = source.artifacts.slice(start, start + length);
83
+ const bytes = candidate.reduce((total, item) => total + item.css.length, 0);
84
+ if (bytes > bestBytes) {
85
+ best = candidate;
86
+ bestBytes = bytes;
87
+ }
88
+ }
89
+ return best;
90
+ }
91
+ /** Topologically order the safe union while preserving every page's chunk order. */
92
+ function selectSingleArtifacts(pages) {
93
+ const artifacts = /* @__PURE__ */ new Map();
94
+ const edges = /* @__PURE__ */ new Map();
95
+ const indegree = /* @__PURE__ */ new Map();
96
+ const rank = /* @__PURE__ */ new Map();
97
+ for (const page of pages) {
98
+ const chunks = page.artifacts.filter(({ kind }) => kind === "chunk");
99
+ for (const artifact of chunks) if (!artifacts.has(artifact.id)) {
100
+ rank.set(artifact.id, rank.size);
101
+ artifacts.set(artifact.id, artifact);
102
+ edges.set(artifact.id, /* @__PURE__ */ new Set());
103
+ indegree.set(artifact.id, 0);
104
+ }
105
+ for (let i = 1; i < chunks.length; i++) {
106
+ const before = chunks[i - 1].id;
107
+ const after = chunks[i].id;
108
+ if (before === after || edges.get(before).has(after)) continue;
109
+ edges.get(before).add(after);
110
+ indegree.set(after, indegree.get(after) + 1);
111
+ }
112
+ }
113
+ const ready = [...artifacts.keys()].filter((id) => indegree.get(id) === 0).sort((a, b) => rank.get(a) - rank.get(b));
114
+ const ordered = [];
115
+ while (ready.length > 0) {
116
+ const id = ready.shift();
117
+ ordered.push(artifacts.get(id));
118
+ for (const after of edges.get(id)) {
119
+ indegree.set(after, indegree.get(after) - 1);
120
+ if (indegree.get(after) === 0) {
121
+ ready.push(after);
122
+ ready.sort((a, b) => rank.get(a) - rank.get(b));
123
+ }
124
+ }
125
+ }
126
+ return ordered.length === artifacts.size ? ordered : [];
127
+ }
128
+ function stylesheetHref(base, assets, filename) {
129
+ return `${base === "/" ? "" : `/${base.replace(/^\/+|\/+$/g, "")}`}/${assets.replace(/^\/+|\/+$/g, "")}/${filename}`;
130
+ }
131
+ function styleTag(styleOpen, artifacts) {
132
+ if (artifacts.length === 0) return "";
133
+ return `${styleOpen}${artifacts.map(({ css }) => css).join("\n")}</style>`;
134
+ }
135
+ function transformPage(page, selected, href) {
136
+ const selectedIds = selected.map(({ id }) => id);
137
+ const first = findSequence(page.artifacts.map(({ id }) => id), selectedIds);
138
+ if (first === -1) {
139
+ const metadataStart = page.html.indexOf(METADATA_START, page.styleStart);
140
+ return page.html.slice(0, metadataStart) + page.html.slice(page.replacementEnd);
141
+ }
142
+ const before = page.artifacts.slice(0, first);
143
+ const after = page.artifacts.slice(first + selected.length);
144
+ const link = `<link rel="stylesheet" href="${href}" data-tasty-ssr>`;
145
+ const replacement = styleTag(page.styleOpen, before) + link + styleTag(page.styleOpen, after);
146
+ return page.html.slice(0, page.styleStart) + replacement + page.html.slice(page.replacementEnd);
147
+ }
148
+ function transformSinglePage(page, selectedIds, href) {
149
+ const indexes = page.artifacts.map((artifact, index) => selectedIds.has(artifact.id) ? index : -1).filter((index) => index !== -1);
150
+ if (indexes.length === 0) {
151
+ const metadataStart = page.html.indexOf(METADATA_START, page.styleStart);
152
+ return page.html.slice(0, metadataStart) + page.html.slice(page.replacementEnd);
153
+ }
154
+ const first = indexes[0];
155
+ const last = indexes[indexes.length - 1];
156
+ if (page.artifacts.slice(first, last + 1).some(({ id }) => !selectedIds.has(id))) {
157
+ const metadataStart = page.html.indexOf(METADATA_START, page.styleStart);
158
+ return page.html.slice(0, metadataStart) + page.html.slice(page.replacementEnd);
159
+ }
160
+ const before = page.artifacts.slice(0, first);
161
+ const after = page.artifacts.slice(last + 1);
162
+ const link = `<link rel="stylesheet" href="${href}" data-tasty-ssr>`;
163
+ const replacement = styleTag(page.styleOpen, before) + link + styleTag(page.styleOpen, after);
164
+ return page.html.slice(0, page.styleStart) + replacement + page.html.slice(page.replacementEnd);
165
+ }
166
+ async function extractAstroCSS(options) {
167
+ const outputDir = fileURLToPath(options.dir);
168
+ const paths = await findHTMLFiles(outputDir);
169
+ const pages = (await Promise.all(paths.map(async (path) => parseExtractablePage(path, await readFile(path, "utf8"))))).filter((page) => page !== null);
170
+ if (pages.length === 0) return;
171
+ const selected = options.strategy === "single" ? selectSingleArtifacts(pages) : selectSharedArtifacts(pages);
172
+ if (selected.length === 0) {
173
+ for (const page of pages) {
174
+ const metadataStart = page.html.indexOf(METADATA_START, page.styleStart);
175
+ await writeFile(page.path, page.html.slice(0, metadataStart) + page.html.slice(page.replacementEnd));
176
+ }
177
+ return;
178
+ }
179
+ const css = selected.map(({ css }) => css).join("\n");
180
+ const filename = `tasty.${createHash("sha256").update(css).digest("hex").slice(0, 12)}.css`;
181
+ const assetDir = join(outputDir, options.assets);
182
+ await mkdir(assetDir, { recursive: true });
183
+ await writeFile(join(assetDir, filename), css);
184
+ const href = stylesheetHref(options.base, options.assets, filename);
185
+ const selectedIds = new Set(selected.map(({ id }) => id));
186
+ for (const page of pages) {
187
+ const html = options.strategy === "single" ? transformSinglePage(page, selectedIds, href) : transformPage(page, selected, href);
188
+ await writeFile(page.path, html);
189
+ }
190
+ }
191
+ //#endregion
192
+ //#region src/ssr/astro.ts
193
+ /**
194
+ * Astro integration for Tasty SSR.
195
+ *
196
+ * Provides:
197
+ * - tastyIntegration() — Astro Integration API (recommended)
198
+ * - tastyMiddleware() — manual middleware for advanced composition
199
+ *
200
+ * Import from '@tenphi/tasty/ssr/astro'.
201
+ */
202
+ registerSSRCollectorGetterGlobal(getSSRCollector);
203
+ /**
204
+ * Create an Astro middleware that collects Tasty styles during SSR.
205
+ *
206
+ * All React components rendered during the request will have their
207
+ * computeStyles() calls captured by the collector via AsyncLocalStorage.
208
+ * After rendering, the middleware injects the collected CSS into </head>.
209
+ *
210
+ * @example Manual middleware setup
211
+ * ```ts
212
+ * // src/middleware.ts
213
+ * import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
214
+ * export const onRequest = tastyMiddleware();
215
+ * ```
216
+ *
217
+ * @example Composing with other middleware
218
+ * ```ts
219
+ * // src/middleware.ts
220
+ * import { sequence } from 'astro:middleware';
221
+ * import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
222
+ *
223
+ * export const onRequest = sequence(
224
+ * tastyMiddleware(),
225
+ * myOtherMiddleware,
226
+ * );
227
+ * ```
228
+ */
229
+ function tastyMiddleware(options) {
230
+ const internalOptions = options;
231
+ return async (context, next) => {
232
+ const transferCache = options?.transferCache ?? true;
233
+ const extractionMetadata = internalOptions?.extractionMetadata === true && context.isPrerendered === true;
234
+ const collector = new ServerStyleCollector();
235
+ const rendered = await runWithCollector(collector, async () => {
236
+ const response = await next();
237
+ const body = response.body;
238
+ const contentType = response.headers.get("content-type") ?? "";
239
+ if (!body || !contentType.includes("text/html")) return { response };
240
+ const reader = body.pipeThrough(new TextDecoderStream()).getReader();
241
+ const parts = [];
242
+ for (;;) {
243
+ const { done, value } = await reader.read();
244
+ if (done) break;
245
+ parts.push(value);
246
+ }
247
+ return {
248
+ html: parts.join(""),
249
+ status: response.status,
250
+ headers: response.headers
251
+ };
252
+ });
253
+ if ("response" in rendered) return rendered.response;
254
+ if (!rendered.html) return new Response(null, {
255
+ status: rendered.status,
256
+ headers: rendered.headers
257
+ });
258
+ let { html } = rendered;
259
+ const css = collector.getCSS();
260
+ if (!css) return new Response(html, {
261
+ status: rendered.status,
262
+ headers: rendered.headers
263
+ });
264
+ const nonce = getConfig().nonce;
265
+ const nonceAttr = nonce ? ` nonce="${nonce}"` : "";
266
+ const styleTag = `<style data-tasty-ssr${nonceAttr}>${css}</style>`;
267
+ const metadataTag = extractionMetadata ? createExtractionMetadata(collector.getArtifacts()) : "";
268
+ let cacheTag = "";
269
+ if (transferCache) {
270
+ const classNames = collector.getRenderedClassNames();
271
+ if (classNames.length > 0) cacheTag = `<script${nonceAttr}>(window.__TASTY__=window.__TASTY__||[]).push(${classNames.map((n) => `"${n}"`).join(",")})<\/script>`;
272
+ }
273
+ const injection = styleTag + metadataTag + cacheTag;
274
+ const idx = html.indexOf("</head>");
275
+ if (idx !== -1) html = html.slice(0, idx) + injection + html.slice(idx);
276
+ else html = injection + html;
277
+ const headers = new Headers(rendered.headers);
278
+ headers.delete("content-length");
279
+ return new Response(html, {
280
+ status: rendered.status,
281
+ headers
282
+ });
283
+ };
284
+ }
285
+ /**
286
+ * Package subpaths of the middleware entrypoints registered by
287
+ * `tastyIntegration()`.
288
+ *
289
+ * These must be bare specifiers rather than
290
+ * `new URL('./astro-middleware.js', import.meta.url)`. The bundler is free to
291
+ * hoist `tastyIntegration` into a shared chunk at a different directory depth
292
+ * than `dist/ssr/`, which makes a relative URL resolve to a file that does not
293
+ * exist and breaks the build for every consumer. A package subpath is resolved
294
+ * by the consumer through our `exports` map, so it never depends on the
295
+ * chunk layout.
296
+ *
297
+ * There are separate entrypoints instead of one parameterised entrypoint because
298
+ * `addMiddleware()` cannot pass options: the integration runs when the Astro
299
+ * config is loaded, while the middleware module is evaluated in the server
300
+ * runtime — a different process for built output — so module-level state set
301
+ * by the integration is not visible to the middleware.
302
+ */
303
+ const MIDDLEWARE_ENTRYPOINT = "@tenphi/tasty/ssr/astro-middleware";
304
+ const MIDDLEWARE_ENTRYPOINT_STATIC = "@tenphi/tasty/ssr/astro-middleware-static";
305
+ const MIDDLEWARE_ENTRYPOINT_EXTRACT = "@tenphi/tasty/ssr/astro-middleware-extract";
306
+ const MIDDLEWARE_ENTRYPOINT_EXTRACT_STATIC = "@tenphi/tasty/ssr/astro-middleware-extract-static";
307
+ /**
308
+ * Astro integration that automatically sets up Tasty SSR.
309
+ *
310
+ * Registers middleware for cross-component CSS deduplication and
311
+ * optionally injects a client hydration script for island support.
312
+ *
313
+ * @example Basic setup (with islands)
314
+ * ```ts
315
+ * // astro.config.mjs
316
+ * import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
317
+ *
318
+ * export default defineConfig({
319
+ * integrations: [tastyIntegration()],
320
+ * });
321
+ * ```
322
+ *
323
+ * @example Static-only (no client JS)
324
+ * ```ts
325
+ * // astro.config.mjs
326
+ * import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
327
+ *
328
+ * export default defineConfig({
329
+ * integrations: [tastyIntegration({ islands: false })],
330
+ * });
331
+ * ```
332
+ */
333
+ function tastyIntegration(options) {
334
+ const { islands = true } = options ?? {};
335
+ const cssMode = options?.css?.mode ?? "inline";
336
+ const cssStrategy = options?.css?.strategy ?? "shared";
337
+ let base = "/";
338
+ let assets = "_astro";
339
+ return {
340
+ name: "@tenphi/tasty",
341
+ hooks: {
342
+ "astro:config:setup": ({ addMiddleware, injectScript }) => {
343
+ addMiddleware({
344
+ entrypoint: cssMode === "extract" ? islands ? MIDDLEWARE_ENTRYPOINT_EXTRACT : MIDDLEWARE_ENTRYPOINT_EXTRACT_STATIC : islands ? MIDDLEWARE_ENTRYPOINT : MIDDLEWARE_ENTRYPOINT_STATIC,
345
+ order: "pre"
346
+ });
347
+ if (islands) injectScript("before-hydration", `import "@tenphi/tasty/ssr/astro-client";`);
348
+ },
349
+ "astro:config:done": ({ config }) => {
350
+ base = config.base ?? "/";
351
+ assets = config.build?.assets ?? "_astro";
352
+ },
353
+ "astro:build:done": async ({ dir }) => {
354
+ if (cssMode !== "extract") return;
355
+ await extractAstroCSS({
356
+ dir,
357
+ base,
358
+ assets,
359
+ strategy: cssStrategy
360
+ });
361
+ }
362
+ }
363
+ };
364
+ }
365
+ //#endregion
366
+ export { tastyMiddleware as n, tastyIntegration as t };
367
+
368
+ //# sourceMappingURL=astro-DXccD0VE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-DXccD0VE.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';\n\nexport type AstroCSSStrategy = 'shared' | 'single';\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 findSequence(haystack: string[], needle: string[]): number {\n if (needle.length === 0) return -1;\n outer: for (let i = 0; i <= haystack.length - needle.length; i++) {\n for (let j = 0; j < needle.length; j++) {\n if (haystack[i + j] !== needle[j]) continue outer;\n }\n return i;\n }\n return -1;\n}\n\n/** Find the largest byte-sized artifact block that is contiguous on every page. */\nfunction selectSharedArtifacts(\n pages: ExtractablePage[],\n): ServerStyleArtifact[] {\n if (pages.length < 2) return [];\n\n const source = pages.reduce((shortest, page) =>\n page.artifacts.length < shortest.artifacts.length ? page : shortest,\n );\n const otherIds = pages\n .filter((page) => page !== source)\n .map((page) => page.artifacts.map(({ id }) => id));\n const sourceIds = source.artifacts.map(({ id }) => id);\n\n let best: ServerStyleArtifact[] = [];\n let bestBytes = 0;\n for (let start = 0; start < source.artifacts.length; start++) {\n let length = source.artifacts.length - start;\n for (const pageIds of otherIds) {\n let pageLength = 0;\n for (let pageStart = 0; pageStart < pageIds.length; pageStart++) {\n if (pageIds[pageStart] !== sourceIds[start]) continue;\n let matchLength = 1;\n while (\n start + matchLength < sourceIds.length &&\n pageStart + matchLength < pageIds.length &&\n sourceIds[start + matchLength] === pageIds[pageStart + matchLength]\n ) {\n matchLength++;\n }\n pageLength = Math.max(pageLength, matchLength);\n }\n length = Math.min(length, pageLength);\n if (length === 0) break;\n }\n\n const candidate = source.artifacts.slice(start, start + length);\n const bytes = candidate.reduce((total, item) => total + item.css.length, 0);\n if (bytes > bestBytes) {\n best = candidate;\n bestBytes = bytes;\n }\n }\n\n return best;\n}\n\n/** Topologically order the safe union while preserving every page's chunk order. */\nfunction selectSingleArtifacts(\n pages: ExtractablePage[],\n): ServerStyleArtifact[] {\n const artifacts = new Map<string, ServerStyleArtifact>();\n const edges = new Map<string, Set<string>>();\n const indegree = new Map<string, number>();\n const rank = new Map<string, number>();\n\n for (const page of pages) {\n const chunks = page.artifacts.filter(({ kind }) => kind === 'chunk');\n for (const artifact of chunks) {\n if (!artifacts.has(artifact.id)) {\n rank.set(artifact.id, rank.size);\n artifacts.set(artifact.id, artifact);\n edges.set(artifact.id, new Set());\n indegree.set(artifact.id, 0);\n }\n }\n for (let i = 1; i < chunks.length; i++) {\n const before = chunks[i - 1].id;\n const after = chunks[i].id;\n if (before === after || edges.get(before)!.has(after)) continue;\n edges.get(before)!.add(after);\n indegree.set(after, indegree.get(after)! + 1);\n }\n }\n\n const ready = [...artifacts.keys()]\n .filter((id) => indegree.get(id) === 0)\n .sort((a, b) => rank.get(a)! - rank.get(b)!);\n const ordered: ServerStyleArtifact[] = [];\n while (ready.length > 0) {\n const id = ready.shift()!;\n ordered.push(artifacts.get(id)!);\n for (const after of edges.get(id)!) {\n indegree.set(after, indegree.get(after)! - 1);\n if (indegree.get(after) === 0) {\n ready.push(after);\n ready.sort((a, b) => rank.get(a)! - rank.get(b)!);\n }\n }\n }\n\n // A cycle means no single order can preserve every page's cascade.\n return ordered.length === artifacts.size ? ordered : [];\n}\n\nfunction stylesheetHref(\n base: string,\n assets: string,\n filename: string,\n): string {\n const basePath = base === '/' ? '' : `/${base.replace(/^\\/+|\\/+$/g, '')}`;\n const assetsPath = assets.replace(/^\\/+|\\/+$/g, '');\n return `${basePath}/${assetsPath}/${filename}`;\n}\n\nfunction styleTag(styleOpen: string, artifacts: ServerStyleArtifact[]): string {\n if (artifacts.length === 0) return '';\n return `${styleOpen}${artifacts.map(({ css }) => css).join('\\n')}</style>`;\n}\n\nfunction transformPage(\n page: ExtractablePage,\n selected: ServerStyleArtifact[],\n href: string,\n): string {\n const selectedIds = selected.map(({ id }) => id);\n const pageIds = page.artifacts.map(({ id }) => id);\n const first = findSequence(pageIds, selectedIds);\n if (first === -1) {\n const metadataStart = page.html.indexOf(METADATA_START, page.styleStart);\n return (\n page.html.slice(0, metadataStart) + page.html.slice(page.replacementEnd)\n );\n }\n\n const before = page.artifacts.slice(0, first);\n const after = page.artifacts.slice(first + selected.length);\n const link = `<link rel=\"stylesheet\" href=\"${href}\" data-tasty-ssr>`;\n const replacement =\n styleTag(page.styleOpen, before) + link + styleTag(page.styleOpen, after);\n\n return (\n page.html.slice(0, page.styleStart) +\n replacement +\n page.html.slice(page.replacementEnd)\n );\n}\n\nfunction transformSinglePage(\n page: ExtractablePage,\n selectedIds: Set<string>,\n href: string,\n): string {\n const indexes = page.artifacts\n .map((artifact, index) => (selectedIds.has(artifact.id) ? index : -1))\n .filter((index) => index !== -1);\n if (indexes.length === 0) {\n const metadataStart = page.html.indexOf(METADATA_START, page.styleStart);\n return (\n page.html.slice(0, metadataStart) + page.html.slice(page.replacementEnd)\n );\n }\n\n const first = indexes[0];\n const last = indexes[indexes.length - 1];\n const middle = page.artifacts.slice(first, last + 1);\n if (middle.some(({ id }) => !selectedIds.has(id))) {\n const metadataStart = page.html.indexOf(METADATA_START, page.styleStart);\n return (\n page.html.slice(0, metadataStart) + page.html.slice(page.replacementEnd)\n );\n }\n\n const before = page.artifacts.slice(0, first);\n const after = page.artifacts.slice(last + 1);\n const link = `<link rel=\"stylesheet\" href=\"${href}\" data-tasty-ssr>`;\n const replacement =\n styleTag(page.styleOpen, before) + link + styleTag(page.styleOpen, after);\n return (\n page.html.slice(0, page.styleStart) +\n replacement +\n page.html.slice(page.replacementEnd)\n );\n}\n\nexport async function extractAstroCSS(options: {\n dir: URL;\n base: string;\n assets: string;\n strategy: AstroCSSStrategy;\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\n const selected =\n options.strategy === 'single'\n ? selectSingleArtifacts(pages)\n : selectSharedArtifacts(pages);\n if (selected.length === 0) {\n for (const page of pages) {\n const metadataStart = page.html.indexOf(METADATA_START, page.styleStart);\n await writeFile(\n page.path,\n page.html.slice(0, metadataStart) +\n page.html.slice(page.replacementEnd),\n );\n }\n return;\n }\n\n const css = selected.map(({ css }) => css).join('\\n');\n const hash = createHash('sha256').update(css).digest('hex').slice(0, 12);\n const filename = `tasty.${hash}.css`;\n const assetDir = join(outputDir, options.assets);\n await mkdir(assetDir, { recursive: true });\n await writeFile(join(assetDir, filename), css);\n\n const href = stylesheetHref(options.base, options.assets, filename);\n const selectedIds = new Set(selected.map(({ id }) => id));\n for (const page of pages) {\n const html =\n options.strategy === 'single'\n ? transformSinglePage(page, selectedIds, href)\n : transformPage(page, selected, href);\n await writeFile(page.path, html);\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 type { AstroCSSStrategy } 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 /** CSS delivery mode. Extraction only applies to prerendered builds. */\n mode?: 'inline' | 'extract';\n /**\n * `shared` extracts the largest common cascade-safe block. `single` emits\n * the safe union of generated component classes. Default: `shared`.\n */\n strategy?: AstroCSSStrategy;\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 const cssStrategy = options?.css?.strategy ?? 'shared';\n let base = '/';\n let assets = '_astro';\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: { base?: string; build?: { assets?: string } };\n }) => {\n base = config.base ?? '/';\n assets = config.build?.assets ?? '_astro';\n },\n 'astro:build:done': async ({ dir }: { dir: URL }) => {\n if (cssMode !== 'extract') return;\n await extractAstroCSS({ dir, base, assets, strategy: cssStrategy });\n },\n },\n };\n}\n"],"mappings":";;;;;;;;;AASA,MAAM,iBAAiB;AACvB,MAAM,eAAe;AAWrB,SAAgB,yBACd,WAC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,EAAE,EAAE,CAAC,CAAC,KAAK,GACgC,EAAE;EAEjG;EAEA,MAAM,YAAY,WAAW,cAAc;EAC3C,MAAM,MAAM,KAAK,QAAQ,SAAS;EAClC,IAAI,QAAQ,IACV,OAAO,KAAK,MAAM,GAAG,GAAG,IAAI,YAAY,KAAK,MAAM,GAAG;OAEtD,OAAO,YAAY;EAGrB,MAAM,UAAU,IAAI,QAAQ,SAAS,OAAO;EAC5C,QAAQ,OAAO,gBAAgB;EAE/B,OAAO,IAAI,SAAS,MAAM;GACxB,QAAQ,SAAS;GACjB;EACF,CAAC;CACH;AACF;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,wBAAwB;AAC9B,MAAM,+BACJ;AACF,MAAM,gCACJ;AACF,MAAM,uCACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDF,SAAgB,iBAAiB,SAAmC;CAClE,MAAM,EAAE,UAAU,SAAS,WAAW,CAAC;CACvC,MAAM,UAAU,SAAS,KAAK,QAAQ;CACtC,MAAM,cAAc,SAAS,KAAK,YAAY;CAC9C,IAAI,OAAO;CACX,IAAI,SAAS;CAEb,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,aAGI;IACJ,OAAO,OAAO,QAAQ;IACtB,SAAS,OAAO,OAAO,UAAU;GACnC;GACA,oBAAoB,OAAO,EAAE,UAAwB;IACnD,IAAI,YAAY,WAAW;IAC3B,MAAM,gBAAgB;KAAE;KAAK;KAAM;KAAQ,UAAU;IAAY,CAAC;GACpE;EACF;CACF;AACF"}
@@ -39,6 +39,6 @@ function getSSRCollector() {
39
39
  return storage.getStore() ?? null;
40
40
  }
41
41
  //#endregion
42
- export { getSSRCollector, runWithCollector };
42
+ export { runWithCollector as n, getSSRCollector as t };
43
43
 
44
- //# 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-YsxGv4tq.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-BUQGeOXA.d.ts.map