@tenphi/tasty 0.0.0-snapshot.bae20d4 → 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 (351) hide show
  1. package/README.md +309 -293
  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} +17 -8
  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} +188 -13
  22. package/dist/css-writer-Bgowobbx.js.map +1 -0
  23. package/dist/{ssr/format-global-rules.js → format-global-rules-DklyaXv-.js} +3 -3
  24. package/dist/format-global-rules-DklyaXv-.js.map +1 -0
  25. package/dist/{ssr/format-rules.js → format-rules-XRw9u7d4.js} +41 -7
  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 -49
  32. package/dist/index.js +921 -33
  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} +4 -6
  38. package/dist/merge-styles-DuoZEsm9.js.map +1 -0
  39. package/dist/{utils/resolve-recipes.js → resolve-recipes-H9NqOQuP.js} +5 -8
  40. package/dist/resolve-recipes-H9NqOQuP.js.map +1 -0
  41. package/dist/ssr/astro-client.d.ts +1 -0
  42. package/dist/ssr/astro-client.js +19 -0
  43. package/dist/ssr/astro-client.js.map +1 -0
  44. package/dist/ssr/astro-middleware-extract-static.d.ts +11 -0
  45. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  46. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  47. package/dist/ssr/astro-middleware-extract.d.ts +11 -0
  48. package/dist/ssr/astro-middleware-extract.js +9 -0
  49. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  50. package/dist/ssr/astro-middleware-static.d.ts +18 -0
  51. package/dist/ssr/astro-middleware-static.js +18 -0
  52. package/dist/ssr/astro-middleware-static.js.map +1 -0
  53. package/dist/ssr/astro-middleware.d.ts +19 -0
  54. package/dist/ssr/astro-middleware.js +19 -0
  55. package/dist/ssr/astro-middleware.js.map +1 -0
  56. package/dist/ssr/astro.d.ts +117 -11
  57. package/dist/ssr/astro.js +2 -65
  58. package/dist/ssr/index.d.ts +37 -5
  59. package/dist/ssr/index.js +7 -9
  60. package/dist/ssr/index.js.map +1 -1
  61. package/dist/ssr/next-config.d.ts +66 -0
  62. package/dist/ssr/next-config.js +115 -0
  63. package/dist/ssr/next-config.js.map +1 -0
  64. package/dist/ssr/next.d.ts +14 -7
  65. package/dist/ssr/next.js +40 -20
  66. package/dist/ssr/next.js.map +1 -1
  67. package/dist/ssr-collector-ref-COs_ioWl.js +29 -0
  68. package/dist/ssr-collector-ref-COs_ioWl.js.map +1 -0
  69. package/dist/static/index.d.ts +91 -5
  70. package/dist/static/index.js +49 -4
  71. package/dist/static/index.js.map +1 -0
  72. package/dist/static/inject.d.ts +5 -0
  73. package/dist/static/inject.js +17 -0
  74. package/dist/static/inject.js.map +1 -0
  75. package/dist/zero/babel.d.ts +2 -155
  76. package/dist/zero/babel.js +183 -51
  77. package/dist/zero/babel.js.map +1 -1
  78. package/dist/zero/index.d.ts +81 -3
  79. package/dist/zero/index.js +2 -4
  80. package/dist/zero/next.d.ts +13 -1
  81. package/dist/zero/next.js +6 -5
  82. package/dist/zero/next.js.map +1 -1
  83. package/docs/README.md +39 -0
  84. package/docs/adoption.md +72 -35
  85. package/docs/ai-agents.md +224 -0
  86. package/docs/comparison.md +88 -53
  87. package/docs/configuration.md +623 -63
  88. package/docs/debug.md +172 -342
  89. package/docs/design-system.md +83 -29
  90. package/docs/dsl.md +614 -133
  91. package/docs/getting-started.md +80 -43
  92. package/docs/injector.md +159 -53
  93. package/docs/methodology.md +178 -31
  94. package/docs/migration-v3.md +285 -0
  95. package/docs/pipeline.md +741 -0
  96. package/docs/plugins.md +353 -0
  97. package/docs/react-api.md +681 -0
  98. package/docs/runtime-benchmarks.md +351 -0
  99. package/docs/ssr.md +356 -128
  100. package/docs/styles.md +103 -32
  101. package/docs/tasty-static.md +227 -65
  102. package/package.json +83 -22
  103. package/tasty.config.ts +6 -0
  104. package/dist/_virtual/_rolldown/runtime.js +0 -8
  105. package/dist/chunks/cacheKey.js +0 -78
  106. package/dist/chunks/cacheKey.js.map +0 -1
  107. package/dist/chunks/definitions.d.ts +0 -37
  108. package/dist/chunks/definitions.js +0 -259
  109. package/dist/chunks/definitions.js.map +0 -1
  110. package/dist/chunks/renderChunk.js +0 -60
  111. package/dist/chunks/renderChunk.js.map +0 -1
  112. package/dist/config.d.ts +0 -323
  113. package/dist/config.js +0 -465
  114. package/dist/config.js.map +0 -1
  115. package/dist/debug.d.ts +0 -204
  116. package/dist/debug.js +0 -733
  117. package/dist/debug.js.map +0 -1
  118. package/dist/hooks/useGlobalStyles.d.ts +0 -30
  119. package/dist/hooks/useGlobalStyles.js +0 -83
  120. package/dist/hooks/useGlobalStyles.js.map +0 -1
  121. package/dist/hooks/useKeyframes.d.ts +0 -56
  122. package/dist/hooks/useKeyframes.js +0 -69
  123. package/dist/hooks/useKeyframes.js.map +0 -1
  124. package/dist/hooks/useProperty.d.ts +0 -79
  125. package/dist/hooks/useProperty.js +0 -114
  126. package/dist/hooks/useProperty.js.map +0 -1
  127. package/dist/hooks/useRawCSS.d.ts +0 -53
  128. package/dist/hooks/useRawCSS.js +0 -40
  129. package/dist/hooks/useRawCSS.js.map +0 -1
  130. package/dist/hooks/useStyles.d.ts +0 -45
  131. package/dist/hooks/useStyles.js +0 -249
  132. package/dist/hooks/useStyles.js.map +0 -1
  133. package/dist/injector/index.d.ts +0 -165
  134. package/dist/injector/index.js +0 -162
  135. package/dist/injector/index.js.map +0 -1
  136. package/dist/injector/injector.d.ts +0 -148
  137. package/dist/injector/injector.js +0 -430
  138. package/dist/injector/injector.js.map +0 -1
  139. package/dist/injector/sheet-manager.d.ts +0 -136
  140. package/dist/injector/sheet-manager.js +0 -729
  141. package/dist/injector/sheet-manager.js.map +0 -1
  142. package/dist/injector/types.d.ts +0 -144
  143. package/dist/keyframes/index.js +0 -206
  144. package/dist/keyframes/index.js.map +0 -1
  145. package/dist/parser/classify.js +0 -320
  146. package/dist/parser/classify.js.map +0 -1
  147. package/dist/parser/const.js +0 -33
  148. package/dist/parser/const.js.map +0 -1
  149. package/dist/parser/lru.js +0 -109
  150. package/dist/parser/lru.js.map +0 -1
  151. package/dist/parser/parser.d.ts +0 -25
  152. package/dist/parser/parser.js +0 -116
  153. package/dist/parser/parser.js.map +0 -1
  154. package/dist/parser/tokenizer.js +0 -69
  155. package/dist/parser/tokenizer.js.map +0 -1
  156. package/dist/parser/types.d.ts +0 -51
  157. package/dist/parser/types.js +0 -46
  158. package/dist/parser/types.js.map +0 -1
  159. package/dist/pipeline/conditions.d.ts +0 -134
  160. package/dist/pipeline/conditions.js +0 -406
  161. package/dist/pipeline/conditions.js.map +0 -1
  162. package/dist/pipeline/exclusive.js +0 -231
  163. package/dist/pipeline/exclusive.js.map +0 -1
  164. package/dist/pipeline/index.d.ts +0 -53
  165. package/dist/pipeline/index.js +0 -670
  166. package/dist/pipeline/index.js.map +0 -1
  167. package/dist/pipeline/materialize.js +0 -1105
  168. package/dist/pipeline/materialize.js.map +0 -1
  169. package/dist/pipeline/parseStateKey.d.ts +0 -15
  170. package/dist/pipeline/parseStateKey.js +0 -447
  171. package/dist/pipeline/parseStateKey.js.map +0 -1
  172. package/dist/pipeline/simplify.js +0 -516
  173. package/dist/pipeline/simplify.js.map +0 -1
  174. package/dist/pipeline/warnings.js +0 -18
  175. package/dist/pipeline/warnings.js.map +0 -1
  176. package/dist/plugins/okhsl-plugin.d.ts +0 -35
  177. package/dist/plugins/okhsl-plugin.js +0 -98
  178. package/dist/plugins/okhsl-plugin.js.map +0 -1
  179. package/dist/plugins/types.d.ts +0 -76
  180. package/dist/properties/index.js +0 -223
  181. package/dist/properties/index.js.map +0 -1
  182. package/dist/properties/property-type-resolver.d.ts +0 -24
  183. package/dist/properties/property-type-resolver.js +0 -91
  184. package/dist/properties/property-type-resolver.js.map +0 -1
  185. package/dist/ssr/astro.js.map +0 -1
  186. package/dist/ssr/async-storage.d.ts +0 -17
  187. package/dist/ssr/async-storage.js.map +0 -1
  188. package/dist/ssr/collect-auto-properties.js +0 -40
  189. package/dist/ssr/collect-auto-properties.js.map +0 -1
  190. package/dist/ssr/collector.d.ts +0 -85
  191. package/dist/ssr/collector.js +0 -183
  192. package/dist/ssr/collector.js.map +0 -1
  193. package/dist/ssr/context.d.ts +0 -8
  194. package/dist/ssr/context.js +0 -14
  195. package/dist/ssr/context.js.map +0 -1
  196. package/dist/ssr/format-global-rules.js.map +0 -1
  197. package/dist/ssr/format-keyframes.js +0 -70
  198. package/dist/ssr/format-keyframes.js.map +0 -1
  199. package/dist/ssr/format-property.js +0 -50
  200. package/dist/ssr/format-property.js.map +0 -1
  201. package/dist/ssr/format-rules.js.map +0 -1
  202. package/dist/ssr/hydrate.d.ts +0 -22
  203. package/dist/ssr/hydrate.js +0 -50
  204. package/dist/ssr/hydrate.js.map +0 -1
  205. package/dist/ssr/ssr-collector-ref.js +0 -12
  206. package/dist/ssr/ssr-collector-ref.js.map +0 -1
  207. package/dist/states/index.d.ts +0 -49
  208. package/dist/states/index.js +0 -169
  209. package/dist/states/index.js.map +0 -1
  210. package/dist/static/tastyStatic.d.ts +0 -46
  211. package/dist/static/tastyStatic.js +0 -31
  212. package/dist/static/tastyStatic.js.map +0 -1
  213. package/dist/static/types.d.ts +0 -49
  214. package/dist/static/types.js +0 -24
  215. package/dist/static/types.js.map +0 -1
  216. package/dist/styles/align.d.ts +0 -15
  217. package/dist/styles/align.js +0 -14
  218. package/dist/styles/align.js.map +0 -1
  219. package/dist/styles/border.d.ts +0 -25
  220. package/dist/styles/border.js +0 -114
  221. package/dist/styles/border.js.map +0 -1
  222. package/dist/styles/color.d.ts +0 -14
  223. package/dist/styles/color.js +0 -27
  224. package/dist/styles/color.js.map +0 -1
  225. package/dist/styles/createStyle.js +0 -80
  226. package/dist/styles/createStyle.js.map +0 -1
  227. package/dist/styles/dimension.js +0 -97
  228. package/dist/styles/dimension.js.map +0 -1
  229. package/dist/styles/display.d.ts +0 -37
  230. package/dist/styles/display.js +0 -67
  231. package/dist/styles/display.js.map +0 -1
  232. package/dist/styles/fade.d.ts +0 -15
  233. package/dist/styles/fade.js +0 -58
  234. package/dist/styles/fade.js.map +0 -1
  235. package/dist/styles/fill.d.ts +0 -42
  236. package/dist/styles/fill.js +0 -52
  237. package/dist/styles/fill.js.map +0 -1
  238. package/dist/styles/flow.d.ts +0 -16
  239. package/dist/styles/flow.js +0 -12
  240. package/dist/styles/flow.js.map +0 -1
  241. package/dist/styles/gap.d.ts +0 -31
  242. package/dist/styles/gap.js +0 -37
  243. package/dist/styles/gap.js.map +0 -1
  244. package/dist/styles/height.d.ts +0 -17
  245. package/dist/styles/height.js +0 -20
  246. package/dist/styles/height.js.map +0 -1
  247. package/dist/styles/index.d.ts +0 -2
  248. package/dist/styles/index.js +0 -9
  249. package/dist/styles/index.js.map +0 -1
  250. package/dist/styles/inset.d.ts +0 -52
  251. package/dist/styles/inset.js +0 -150
  252. package/dist/styles/inset.js.map +0 -1
  253. package/dist/styles/justify.d.ts +0 -15
  254. package/dist/styles/justify.js +0 -14
  255. package/dist/styles/justify.js.map +0 -1
  256. package/dist/styles/list.d.ts +0 -16
  257. package/dist/styles/list.js +0 -98
  258. package/dist/styles/list.js.map +0 -1
  259. package/dist/styles/margin.d.ts +0 -24
  260. package/dist/styles/margin.js +0 -104
  261. package/dist/styles/margin.js.map +0 -1
  262. package/dist/styles/outline.d.ts +0 -29
  263. package/dist/styles/outline.js +0 -65
  264. package/dist/styles/outline.js.map +0 -1
  265. package/dist/styles/padding.d.ts +0 -24
  266. package/dist/styles/padding.js +0 -104
  267. package/dist/styles/padding.js.map +0 -1
  268. package/dist/styles/predefined.d.ts +0 -71
  269. package/dist/styles/predefined.js +0 -238
  270. package/dist/styles/predefined.js.map +0 -1
  271. package/dist/styles/preset.d.ts +0 -47
  272. package/dist/styles/preset.js +0 -126
  273. package/dist/styles/preset.js.map +0 -1
  274. package/dist/styles/radius.d.ts +0 -14
  275. package/dist/styles/radius.js +0 -51
  276. package/dist/styles/radius.js.map +0 -1
  277. package/dist/styles/scrollbar.d.ts +0 -25
  278. package/dist/styles/scrollbar.js +0 -48
  279. package/dist/styles/scrollbar.js.map +0 -1
  280. package/dist/styles/shadow.d.ts +0 -14
  281. package/dist/styles/shadow.js +0 -24
  282. package/dist/styles/shadow.js.map +0 -1
  283. package/dist/styles/transition.d.ts +0 -14
  284. package/dist/styles/transition.js +0 -158
  285. package/dist/styles/transition.js.map +0 -1
  286. package/dist/styles/types.d.ts +0 -508
  287. package/dist/styles/width.d.ts +0 -17
  288. package/dist/styles/width.js +0 -20
  289. package/dist/styles/width.js.map +0 -1
  290. package/dist/tasty.d.ts +0 -981
  291. package/dist/tasty.js +0 -219
  292. package/dist/tasty.js.map +0 -1
  293. package/dist/types.d.ts +0 -184
  294. package/dist/utils/cache-wrapper.js +0 -22
  295. package/dist/utils/cache-wrapper.js.map +0 -1
  296. package/dist/utils/case-converter.js +0 -8
  297. package/dist/utils/case-converter.js.map +0 -1
  298. package/dist/utils/color-math.d.ts +0 -45
  299. package/dist/utils/color-math.js +0 -749
  300. package/dist/utils/color-math.js.map +0 -1
  301. package/dist/utils/color-space.d.ts +0 -5
  302. package/dist/utils/color-space.js +0 -228
  303. package/dist/utils/color-space.js.map +0 -1
  304. package/dist/utils/colors.d.ts +0 -5
  305. package/dist/utils/colors.js +0 -11
  306. package/dist/utils/colors.js.map +0 -1
  307. package/dist/utils/css-types.d.ts +0 -7
  308. package/dist/utils/dotize.d.ts +0 -26
  309. package/dist/utils/dotize.js +0 -122
  310. package/dist/utils/dotize.js.map +0 -1
  311. package/dist/utils/filter-base-props.d.ts +0 -15
  312. package/dist/utils/filter-base-props.js +0 -45
  313. package/dist/utils/filter-base-props.js.map +0 -1
  314. package/dist/utils/get-display-name.d.ts +0 -7
  315. package/dist/utils/get-display-name.js +0 -10
  316. package/dist/utils/get-display-name.js.map +0 -1
  317. package/dist/utils/has-keys.js +0 -13
  318. package/dist/utils/has-keys.js.map +0 -1
  319. package/dist/utils/is-dev-env.js +0 -19
  320. package/dist/utils/is-dev-env.js.map +0 -1
  321. package/dist/utils/is-valid-element-type.js +0 -15
  322. package/dist/utils/is-valid-element-type.js.map +0 -1
  323. package/dist/utils/merge-styles.js.map +0 -1
  324. package/dist/utils/mod-attrs.d.ts +0 -8
  325. package/dist/utils/mod-attrs.js +0 -21
  326. package/dist/utils/mod-attrs.js.map +0 -1
  327. package/dist/utils/process-tokens.d.ts +0 -21
  328. package/dist/utils/process-tokens.js +0 -91
  329. package/dist/utils/process-tokens.js.map +0 -1
  330. package/dist/utils/resolve-recipes.d.ts +0 -17
  331. package/dist/utils/resolve-recipes.js.map +0 -1
  332. package/dist/utils/selector-transform.js +0 -32
  333. package/dist/utils/selector-transform.js.map +0 -1
  334. package/dist/utils/string.js +0 -8
  335. package/dist/utils/string.js.map +0 -1
  336. package/dist/utils/styles.d.ts +0 -101
  337. package/dist/utils/styles.js +0 -223
  338. package/dist/utils/styles.js.map +0 -1
  339. package/dist/utils/typography.d.ts +0 -47
  340. package/dist/utils/typography.js +0 -43
  341. package/dist/utils/typography.js.map +0 -1
  342. package/dist/utils/warnings.d.ts +0 -16
  343. package/dist/utils/warnings.js +0 -16
  344. package/dist/utils/warnings.js.map +0 -1
  345. package/dist/zero/css-writer.d.ts +0 -45
  346. package/dist/zero/css-writer.js +0 -74
  347. package/dist/zero/css-writer.js.map +0 -1
  348. package/dist/zero/extractor.d.ts +0 -24
  349. package/dist/zero/extractor.js.map +0 -1
  350. package/docs/PIPELINE.md +0 -519
  351. package/docs/runtime.md +0 -291
@@ -1,20 +1,34 @@
1
- import { extractLocalProperties, hasLocalProperties } from "../properties/index.js";
2
- import { PropertyTypeResolver } from "../properties/property-type-resolver.js";
3
- import { renderStyles } from "../pipeline/index.js";
4
- import { categorizeStyleKeys } from "../chunks/definitions.js";
5
- import { generateChunkCacheKey } from "../chunks/cacheKey.js";
6
- import { renderStylesForChunk } from "../chunks/renderChunk.js";
7
- import { extractAnimationNamesFromStyles, extractLocalKeyframes, filterUsedKeyframes, hasLocalKeyframes, mergeKeyframes } from "../keyframes/index.js";
1
+ import { Ft as registerFunctionPolyfill, It as registerLocalFunctionPolyfills, J as hasLocalCounterStyle, K as extractLocalCounterStyle, L as renderStyles, Mt as formatFunctionRule, Nt as hasLocalFunctions, Pt as parseFunctionName, Q as hasLocalFontFace, Y as extractLocalFontFace, Z as formatFontFaceRule, _ as isFunctionsPolyfillEnabled, bt as hasLocalProperties, ft as makeClassName, gt as validateNamePrefix, it as PropertyTypeResolver, jt as extractLocalFunctions, mt as makeKeyframeName, q as formatCounterStyleRule, vt as extractLocalProperties } from "./config-B3gPdCqd.js";
2
+ import { a as mergeKeyframes, d as categorizeStyleKeys, i as hasLocalKeyframes, l as renderStylesForChunk, n as extractLocalKeyframes, r as filterUsedKeyframes, t as extractAnimationNamesFromStyles, u as generateChunkCacheKey } from "./keyframes-DE-OE76F.js";
8
3
  import { createHash } from "crypto";
9
-
4
+ import * as fs from "fs";
5
+ import * as path from "path";
10
6
  //#region src/zero/extractor.ts
11
7
  /**
8
+ * Module-level prefix used by the zero-runtime extractor.
9
+ * Defaults to `'ts'` so static classes never collide with the runtime
10
+ * `'t'` classes when both are loaded on the same page. Override via
11
+ * `setExtractorNamePrefix()` from the Babel plugin so user config flows
12
+ * into the extractor.
13
+ */
14
+ let currentNamePrefix = "ts";
15
+ /**
16
+ * Set the prefix used by the zero-runtime extractor.
17
+ * Called by the Babel plugin after resolving user config so that
18
+ * generated class and keyframe names match the user's configuration.
19
+ */
20
+ function setExtractorNamePrefix(prefix) {
21
+ validateNamePrefix(prefix);
22
+ currentNamePrefix = prefix;
23
+ }
24
+ /**
12
25
  * Generate a deterministic className from a cache key using content hash.
13
26
  * This ensures the same styles always produce the same className,
14
27
  * regardless of build order or incremental compilation.
15
28
  */
16
29
  function generateClassName(cacheKey) {
17
- return `ts${createHash("md5").update(cacheKey).digest("hex").slice(0, 6)}`;
30
+ const hash = createHash("md5").update(cacheKey).digest("hex").slice(0, 6);
31
+ return makeClassName(currentNamePrefix, hash);
18
32
  }
19
33
  /**
20
34
  * Extract styles using chunking (for className mode).
@@ -83,10 +97,14 @@ function formatRulesDirectly(rules) {
83
97
  * Generate a deterministic keyframes name from content hash.
84
98
  * This ensures the same keyframes content always produces the same name,
85
99
  * enabling automatic deduplication across elements and files.
100
+ *
101
+ * Uses the configured prefix with a `k` discriminator so keyframe names
102
+ * stay visually distinct from class names sharing the same prefix.
86
103
  */
87
104
  function generateKeyframesName(steps) {
88
105
  const content = JSON.stringify(steps);
89
- return `kf${createHash("md5").update(content).digest("hex").slice(0, 6)}`;
106
+ const hash = createHash("md5").update(content).digest("hex").slice(0, 6);
107
+ return makeKeyframeName(currentNamePrefix, hash);
90
108
  }
91
109
  /**
92
110
  * Extract keyframes that are used in styles.
@@ -209,7 +227,164 @@ function scanKeyframeSteps(steps, resolver, isPropertyDefined, registerProperty)
209
227
  resolver.scanDeclarations(declarations, isPropertyDefined, registerProperty);
210
228
  }
211
229
  }
212
-
230
+ /**
231
+ * Extract @font-face rules from styles, merging with global config.
232
+ * Deduplicates by content hash.
233
+ */
234
+ function extractFontFaceFromStyles(styles, globalFontFace) {
235
+ const results = [];
236
+ const seenHashes = /* @__PURE__ */ new Set();
237
+ function addFontFace(family, input) {
238
+ const descriptors = Array.isArray(input) ? input : [input];
239
+ for (const desc of descriptors) {
240
+ const hash = createHash("md5").update(JSON.stringify({
241
+ family,
242
+ ...desc
243
+ })).digest("hex").slice(0, 8);
244
+ if (!seenHashes.has(hash)) {
245
+ seenHashes.add(hash);
246
+ results.push({ css: formatFontFaceRule(family, desc) });
247
+ }
248
+ }
249
+ }
250
+ if (globalFontFace) for (const [family, input] of Object.entries(globalFontFace)) addFontFace(family, input);
251
+ if (hasLocalFontFace(styles)) {
252
+ const local = extractLocalFontFace(styles);
253
+ if (local) for (const [family, input] of Object.entries(local)) addFontFace(family, input);
254
+ }
255
+ return results;
256
+ }
257
+ /**
258
+ * Extract @counter-style rules from styles, merging with global config.
259
+ * Deduplicates by name; component-local definitions override global ones with
260
+ * the same name (local wins).
261
+ */
262
+ function extractCounterStyleFromStyles(styles, globalCounterStyle) {
263
+ const byName = /* @__PURE__ */ new Map();
264
+ function addCounterStyle(name, descriptors) {
265
+ byName.set(name, {
266
+ name,
267
+ css: formatCounterStyleRule(name, descriptors)
268
+ });
269
+ }
270
+ if (globalCounterStyle) for (const [name, descriptors] of Object.entries(globalCounterStyle)) addCounterStyle(name, descriptors);
271
+ if (hasLocalCounterStyle(styles)) {
272
+ const local = extractLocalCounterStyle(styles);
273
+ if (local) for (const [name, descriptors] of Object.entries(local)) addCounterStyle(name, descriptors);
274
+ }
275
+ return [...byName.values()];
276
+ }
277
+ /**
278
+ * Extract @function rules from styles, merging with global config.
279
+ * Deduplicates by CSS function name; component-local definitions override
280
+ * global ones with the same name (local wins).
281
+ */
282
+ function extractFunctionsFromStyles(styles, globalFunction) {
283
+ if (isFunctionsPolyfillEnabled()) {
284
+ if (globalFunction) for (const [name, definition] of Object.entries(globalFunction)) registerFunctionPolyfill(name, definition);
285
+ registerLocalFunctionPolyfills(styles);
286
+ return [];
287
+ }
288
+ const byName = /* @__PURE__ */ new Map();
289
+ function addFunction(name, definition) {
290
+ const cssName = parseFunctionName(name);
291
+ byName.set(cssName, {
292
+ name: cssName,
293
+ css: formatFunctionRule(name, definition)
294
+ });
295
+ }
296
+ if (globalFunction) for (const [name, definition] of Object.entries(globalFunction)) addFunction(name, definition);
297
+ if (hasLocalFunctions(styles)) {
298
+ const local = extractLocalFunctions(styles);
299
+ if (local) for (const [name, definition] of Object.entries(local)) addFunction(name, definition);
300
+ }
301
+ return [...byName.values()];
302
+ }
303
+ //#endregion
304
+ //#region src/zero/css-writer.ts
305
+ var CSSWriter = class {
306
+ cssBlocks = /* @__PURE__ */ new Map();
307
+ outputPath;
308
+ devMode;
309
+ constructor(outputPath, options = {}) {
310
+ this.outputPath = outputPath;
311
+ this.devMode = options.devMode ?? false;
312
+ }
313
+ /**
314
+ * Add CSS block with deduplication key
315
+ * @param key - Unique key for deduplication
316
+ * @param css - CSS content
317
+ * @param source - Optional source file path (used in devMode)
318
+ */
319
+ add(key, css, source) {
320
+ this.cssBlocks.set(key, {
321
+ css,
322
+ source
323
+ });
324
+ }
325
+ /**
326
+ * Check if a key already exists
327
+ */
328
+ has(key) {
329
+ return this.cssBlocks.has(key);
330
+ }
331
+ /**
332
+ * Get the number of CSS blocks
333
+ */
334
+ get size() {
335
+ return this.cssBlocks.size;
336
+ }
337
+ /**
338
+ * Write all collected CSS to the output file
339
+ */
340
+ write() {
341
+ const outputDir = path.dirname(this.outputPath);
342
+ if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
343
+ const cssBlocks = [];
344
+ for (const block of this.cssBlocks.values()) if (this.devMode && block.source) cssBlocks.push(`/* from: ${block.source} */\n${block.css}`);
345
+ else cssBlocks.push(block.css);
346
+ const css = cssBlocks.join("\n\n");
347
+ fs.writeFileSync(this.outputPath, `/* Generated by @tenphi/tasty/zero - DO NOT EDIT */\n\n` + css);
348
+ }
349
+ /**
350
+ * Get all CSS as string (for testing or in-memory use)
351
+ */
352
+ getCSS() {
353
+ const cssBlocks = [];
354
+ for (const block of this.cssBlocks.values()) if (this.devMode && block.source) cssBlocks.push(`/* from: ${block.source} */\n${block.css}`);
355
+ else cssBlocks.push(block.css);
356
+ return cssBlocks.join("\n\n");
357
+ }
358
+ /**
359
+ * Clear all collected CSS
360
+ */
361
+ clear() {
362
+ this.cssBlocks.clear();
363
+ }
364
+ /**
365
+ * Get the output path
366
+ */
367
+ getOutputPath() {
368
+ return this.outputPath;
369
+ }
370
+ };
371
+ /**
372
+ * Factory for creating a {@link CSSWriter} instance.
373
+ *
374
+ * Canonical functional entry point; the `CSSWriter` class remains exported
375
+ * for advanced/internal use.
376
+ *
377
+ * @example
378
+ * ```ts
379
+ * import { createCSSWriter } from '@tenphi/tasty/zero';
380
+ *
381
+ * const writer = createCSSWriter('output.css', { devMode: true });
382
+ * ```
383
+ */
384
+ function createCSSWriter(outputPath, options) {
385
+ return new CSSWriter(outputPath, options);
386
+ }
213
387
  //#endregion
214
- export { extractKeyframesFromStyles, extractPropertiesFromStyles, extractStylesForSelector, extractStylesWithChunks };
215
- //# sourceMappingURL=extractor.js.map
388
+ export { extractFunctionsFromStyles as a, extractStylesForSelector as c, extractFontFaceFromStyles as i, extractStylesWithChunks as l, createCSSWriter as n, extractKeyframesFromStyles as o, extractCounterStyleFromStyles as r, extractPropertiesFromStyles as s, CSSWriter as t, setExtractorNamePrefix as u };
389
+
390
+ //# sourceMappingURL=css-writer-Bgowobbx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"css-writer-Bgowobbx.js","names":[],"sources":["../src/zero/extractor.ts","../src/zero/css-writer.ts"],"sourcesContent":["import { createHash } from 'crypto';\n\nimport {\n categorizeStyleKeys,\n generateChunkCacheKey,\n renderStylesForChunk,\n} from '../chunks';\nimport type {\n CounterStyleDescriptors,\n FontFaceDescriptors,\n FontFaceInput,\n FunctionDefinition,\n KeyframesSteps,\n} from '../injector/types';\nimport {\n extractLocalCounterStyle,\n formatCounterStyleRule,\n hasLocalCounterStyle,\n} from '../counter-style';\nimport {\n extractLocalFontFace,\n formatFontFaceRule,\n hasLocalFontFace,\n} from '../font-face';\nimport { isFunctionsPolyfillEnabled } from '../config';\nimport {\n extractLocalFunctions,\n formatFunctionRule,\n hasLocalFunctions,\n parseFunctionName,\n registerFunctionPolyfill,\n registerLocalFunctionPolyfills,\n} from '../functions';\nimport {\n extractAnimationNamesFromStyles,\n extractLocalKeyframes,\n filterUsedKeyframes,\n hasLocalKeyframes,\n mergeKeyframes,\n} from '../keyframes';\nimport type { StyleResult } from '../pipeline';\nimport { renderStyles } from '../pipeline';\nimport { extractLocalProperties, hasLocalProperties } from '../properties';\nimport { PropertyTypeResolver } from '../properties/property-type-resolver';\nimport type { Styles } from '../styles/types';\nimport {\n DEFAULT_ZERO_NAME_PREFIX,\n makeClassName,\n makeKeyframeName,\n validateNamePrefix,\n} from '../utils/name-prefix';\n\nexport interface ExtractedChunk {\n className: string;\n css: string;\n}\n\nexport interface ExtractedSelector {\n selector: string;\n css: string;\n}\n\nexport interface ExtractedKeyframes {\n name: string;\n css: string;\n}\n\ninterface KeyframesExtractionResult {\n /** Keyframes to inject (deduplicated by content) */\n keyframes: ExtractedKeyframes[];\n /** Map from original animation name to canonical name (for replacement) */\n nameMap: Map<string, string>;\n}\n\n/**\n * Module-level prefix used by the zero-runtime extractor.\n * Defaults to `'ts'` so static classes never collide with the runtime\n * `'t'` classes when both are loaded on the same page. Override via\n * `setExtractorNamePrefix()` from the Babel plugin so user config flows\n * into the extractor.\n */\nlet currentNamePrefix: string = DEFAULT_ZERO_NAME_PREFIX;\n\n/**\n * Set the prefix used by the zero-runtime extractor.\n * Called by the Babel plugin after resolving user config so that\n * generated class and keyframe names match the user's configuration.\n */\nexport function setExtractorNamePrefix(prefix: string): void {\n validateNamePrefix(prefix);\n currentNamePrefix = prefix;\n}\n\n/**\n * Get the prefix currently used by the zero-runtime extractor.\n * Exposed primarily for tests.\n */\nexport function getExtractorNamePrefix(): string {\n return currentNamePrefix;\n}\n\n/**\n * Generate a deterministic className from a cache key using content hash.\n * This ensures the same styles always produce the same className,\n * regardless of build order or incremental compilation.\n */\nfunction generateClassName(cacheKey: string): string {\n const hash = createHash('md5').update(cacheKey).digest('hex').slice(0, 6);\n return makeClassName(currentNamePrefix, hash);\n}\n\n/**\n * Extract styles using chunking (for className mode).\n * Returns multiple classes, one per chunk.\n */\nexport function extractStylesWithChunks(styles: Styles): ExtractedChunk[] {\n const chunks: ExtractedChunk[] = [];\n\n // Categorize style keys into chunks\n const chunkMap = categorizeStyleKeys(styles as Record<string, unknown>);\n\n for (const [chunkName, chunkStyleKeys] of chunkMap) {\n if (chunkStyleKeys.length === 0) continue;\n\n // Generate cache key for this chunk (used for className hash)\n const cacheKey = generateChunkCacheKey(styles, chunkName, chunkStyleKeys);\n\n // Render styles for this chunk\n const renderResult = renderStylesForChunk(\n styles,\n chunkName,\n chunkStyleKeys,\n );\n\n if (renderResult.rules.length === 0) continue;\n\n // Generate deterministic className from content hash\n const className = generateClassName(cacheKey);\n const selector = `.${className}.${className}`;\n\n // Format CSS\n const css = formatRulesToCSS(renderResult.rules, selector);\n\n chunks.push({ className, css });\n }\n\n return chunks;\n}\n\n/**\n * Extract styles for a specific selector (for global/selector mode).\n * Returns a single CSS block.\n */\nexport function extractStylesForSelector(\n selector: string,\n styles: Styles,\n): ExtractedSelector {\n // renderStyles with selector returns StyleResult[] with selectors already applied\n const rules = renderStyles(styles, selector);\n // Format without re-prefixing - rules already have the full selector\n const css = formatRulesDirectly(rules);\n\n return { selector, css };\n}\n\n/**\n * Format StyleResult[] to CSS string.\n * Prefixes each rule's selector with the base selector.\n * Used for chunked styles where rules have relative selectors.\n */\nfunction formatRulesToCSS(rules: StyleResult[], baseSelector: string): string {\n return rules\n .map((rule) => {\n // Handle selector as array (OR conditions) or string\n // Note: renderStyles without className joins array selectors with '|||' placeholder\n const selectorParts = Array.isArray(rule.selector)\n ? rule.selector\n : rule.selector\n ? rule.selector.split('|||')\n : [''];\n\n // Prefix each selector part with the base selector\n const fullSelector = selectorParts\n .map((part) => {\n // Build selector: [rootPrefix] baseSelector[part]\n let selector: string;\n\n // If part is empty, just use base selector\n if (!part) {\n selector = baseSelector;\n } else if (part.startsWith(':') || part.startsWith('[')) {\n // If part starts with a pseudo-class or pseudo-element, append to base\n selector = `${baseSelector}${part}`;\n } else if (\n part.startsWith('>') ||\n part.startsWith('+') ||\n part.startsWith('~')\n ) {\n // If part starts with >, +, ~ combinator, append with space\n selector = `${baseSelector}${part}`;\n } else {\n // Otherwise, combine base with part\n selector = `${baseSelector}${part}`;\n }\n\n // Prepend rootPrefix if present (for @root() states)\n if (rule.rootPrefix) {\n selector = `${rule.rootPrefix} ${selector}`;\n }\n\n return selector;\n })\n .join(', ');\n\n let css = `${fullSelector} { ${rule.declarations} }`;\n\n // Wrap in at-rules (in reverse order for proper nesting)\n if (rule.atRules && rule.atRules.length > 0) {\n for (const atRule of [...rule.atRules].reverse()) {\n css = `${atRule} {\\n ${css}\\n}`;\n }\n }\n\n return css;\n })\n .join('\\n\\n');\n}\n\n/**\n * Format StyleResult[] to CSS string directly without prefixing.\n * Used for global styles where rules already have the full selector.\n */\nfunction formatRulesDirectly(rules: StyleResult[]): string {\n return rules\n .map((rule) => {\n // Prepend rootPrefix if present (for @root() states)\n const selector = rule.rootPrefix\n ? `${rule.rootPrefix} ${rule.selector}`\n : rule.selector;\n\n let css = `${selector} { ${rule.declarations} }`;\n\n // Wrap in at-rules (in reverse order for proper nesting)\n if (rule.atRules && rule.atRules.length > 0) {\n for (const atRule of [...rule.atRules].reverse()) {\n css = `${atRule} {\\n ${css}\\n}`;\n }\n }\n\n return css;\n })\n .join('\\n\\n');\n}\n\n// Note: With hash-based className generation, counter management functions\n// are no longer needed. ClassNames are deterministic based on content.\n\n/**\n * Generate a deterministic keyframes name from content hash.\n * This ensures the same keyframes content always produces the same name,\n * enabling automatic deduplication across elements and files.\n *\n * Uses the configured prefix with a `k` discriminator so keyframe names\n * stay visually distinct from class names sharing the same prefix.\n */\nfunction generateKeyframesName(steps: KeyframesSteps): string {\n const content = JSON.stringify(steps);\n const hash = createHash('md5').update(content).digest('hex').slice(0, 6);\n return makeKeyframeName(currentNamePrefix, hash);\n}\n\n/**\n * Extract keyframes that are used in styles.\n * Merges local @keyframes with global keyframes, filters to only used ones.\n * Generates hash-based names from content for automatic deduplication.\n *\n * @param styles - The styles object (may contain @keyframes and animation properties)\n * @param globalKeyframes - Optional global keyframes from config\n * @returns Keyframes to inject and name mapping for replacement\n */\nexport function extractKeyframesFromStyles(\n styles: Styles,\n globalKeyframes?: Record<string, KeyframesSteps> | null,\n): KeyframesExtractionResult {\n const emptyResult: KeyframesExtractionResult = {\n keyframes: [],\n nameMap: new Map(),\n };\n\n // Extract animation names from styles\n const usedNames = extractAnimationNamesFromStyles(styles);\n if (usedNames.size === 0) return emptyResult;\n\n // Merge local and global keyframes\n const local = hasLocalKeyframes(styles)\n ? extractLocalKeyframes(styles)\n : null;\n const allKeyframes = mergeKeyframes(local, globalKeyframes ?? null);\n\n // Filter to only used keyframes\n const usedKeyframes = filterUsedKeyframes(allKeyframes, usedNames);\n if (!usedKeyframes) return emptyResult;\n\n // Generate hash-based names and collect unique keyframes\n const seenHashes = new Set<string>();\n const nameMap = new Map<string, string>();\n const keyframesToEmit: ExtractedKeyframes[] = [];\n\n for (const [originalName, steps] of Object.entries(usedKeyframes)) {\n const hashedName = generateKeyframesName(steps);\n\n // Always map original name to hashed name (for CSS replacement)\n nameMap.set(originalName, hashedName);\n\n // Only emit each unique keyframe once\n if (!seenHashes.has(hashedName)) {\n seenHashes.add(hashedName);\n const css = keyframesToCSS(hashedName, steps);\n keyframesToEmit.push({ name: hashedName, css });\n }\n }\n\n return { keyframes: keyframesToEmit, nameMap };\n}\n\n/**\n * Convert keyframes steps to CSS string.\n */\nfunction keyframesToCSS(name: string, steps: KeyframesSteps): string {\n const stepRules: string[] = [];\n\n for (const [key, value] of Object.entries(steps)) {\n if (typeof value === 'string') {\n // Raw CSS string\n stepRules.push(`${key} { ${value.trim()} }`);\n } else if (value && typeof value === 'object') {\n // Style map - convert to CSS declarations\n const declarations = Object.entries(value)\n .map(([prop, val]) => {\n const cssProperty = camelToKebab(prop);\n return `${cssProperty}: ${val}`;\n })\n .join('; ');\n stepRules.push(`${key} { ${declarations} }`);\n }\n }\n\n return `@keyframes ${name} { ${stepRules.join(' ')} }`;\n}\n\n/**\n * Convert camelCase to kebab-case.\n */\nfunction camelToKebab(str: string): string {\n return str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n}\n\n// ============================================================================\n// Property Extraction (auto-infer @property types for zero-runtime)\n// ============================================================================\n\nexport interface ExtractedProperty {\n name: string;\n css: string;\n}\n\n/**\n * Extract auto-inferred @property declarations from styles.\n * Scans rendered style declarations and keyframe declarations for custom properties\n * whose types can be inferred from their values.\n *\n * @param styles - The styles object\n * @param options - Options including autoPropertyTypes flag\n * @returns Array of @property CSS rules to inject\n */\nexport function extractPropertiesFromStyles(\n styles: Styles,\n options?: { autoPropertyTypes?: boolean },\n): ExtractedProperty[] {\n if (options?.autoPropertyTypes === false) return [];\n\n const registered = new Set<string>();\n const results: ExtractedProperty[] = [];\n\n // Collect explicitly declared properties (they take precedence)\n if (hasLocalProperties(styles)) {\n const localProps = extractLocalProperties(styles);\n if (localProps) {\n for (const token of Object.keys(localProps)) {\n // Normalize token to CSS name\n let cssName: string;\n if (token.startsWith('#')) {\n cssName = `--${token.slice(1)}-color`;\n } else if (token.startsWith('$')) {\n cssName = `--${token.slice(1)}`;\n } else if (token.startsWith('--')) {\n cssName = token;\n } else {\n cssName = `--${token}`;\n }\n registered.add(cssName);\n }\n }\n }\n\n const resolver = new PropertyTypeResolver();\n\n const registerProperty = (\n name: string,\n syntax: string,\n initialValue: string,\n ) => {\n if (registered.has(name)) return;\n registered.add(name);\n\n const parts: string[] = [];\n parts.push(`syntax: \"${syntax}\";`);\n parts.push(`inherits: true;`);\n parts.push(`initial-value: ${initialValue};`);\n\n const css = `@property ${name} { ${parts.join(' ')} }`;\n results.push({ name, css });\n };\n\n const isPropertyDefined = (name: string) => registered.has(name);\n\n // Scan rendered style declarations\n const chunkMap = categorizeStyleKeys(styles as Record<string, unknown>);\n for (const [chunkName, chunkStyleKeys] of chunkMap) {\n if (chunkStyleKeys.length === 0) continue;\n const renderResult = renderStylesForChunk(\n styles,\n chunkName,\n chunkStyleKeys,\n );\n for (const rule of renderResult.rules) {\n if (!rule.declarations) continue;\n resolver.scanDeclarations(\n rule.declarations,\n isPropertyDefined,\n registerProperty,\n );\n }\n }\n\n // Scan keyframe declarations\n if (hasLocalKeyframes(styles)) {\n const localKf = extractLocalKeyframes(styles);\n if (localKf) {\n for (const steps of Object.values(localKf)) {\n scanKeyframeSteps(steps, resolver, isPropertyDefined, registerProperty);\n }\n }\n }\n\n return results;\n}\n\nfunction scanKeyframeSteps(\n steps: KeyframesSteps,\n resolver: PropertyTypeResolver,\n isPropertyDefined: (name: string) => boolean,\n registerProperty: (\n name: string,\n syntax: string,\n initialValue: string,\n ) => void,\n): void {\n for (const value of Object.values(steps)) {\n if (typeof value === 'string') {\n resolver.scanDeclarations(value, isPropertyDefined, registerProperty);\n } else if (value && typeof value === 'object') {\n const declarations = Object.entries(value)\n .map(([prop, val]) => {\n const cssProperty = camelToKebab(prop);\n return `${cssProperty}: ${val}`;\n })\n .join('; ');\n resolver.scanDeclarations(\n declarations,\n isPropertyDefined,\n registerProperty,\n );\n }\n }\n}\n\n// ============================================================================\n// Font Face Extraction (zero-runtime)\n// ============================================================================\n\nexport interface ExtractedFontFace {\n css: string;\n}\n\n/**\n * Extract @font-face rules from styles, merging with global config.\n * Deduplicates by content hash.\n */\nexport function extractFontFaceFromStyles(\n styles: Styles,\n globalFontFace?: Record<string, FontFaceInput> | null,\n): ExtractedFontFace[] {\n const results: ExtractedFontFace[] = [];\n const seenHashes = new Set<string>();\n\n function addFontFace(family: string, input: FontFaceInput) {\n const descriptors: FontFaceDescriptors[] = Array.isArray(input)\n ? input\n : [input];\n for (const desc of descriptors) {\n const hash = createHash('md5')\n .update(JSON.stringify({ family, ...desc }))\n .digest('hex')\n .slice(0, 8);\n if (!seenHashes.has(hash)) {\n seenHashes.add(hash);\n results.push({ css: formatFontFaceRule(family, desc) });\n }\n }\n }\n\n // Global font faces first\n if (globalFontFace) {\n for (const [family, input] of Object.entries(globalFontFace)) {\n addFontFace(family, input);\n }\n }\n\n // Local font faces. @font-face is keyed by content hash, not family name, so\n // distinct definitions all emit and byte-identical ones collapse — there is\n // no \"winner\" to pick between a global and a local definition.\n if (hasLocalFontFace(styles)) {\n const local = extractLocalFontFace(styles);\n if (local) {\n for (const [family, input] of Object.entries(local)) {\n addFontFace(family, input);\n }\n }\n }\n\n return results;\n}\n\n// ============================================================================\n// Counter Style Extraction (zero-runtime)\n// ============================================================================\n\nexport interface ExtractedCounterStyle {\n name: string;\n css: string;\n}\n\n/**\n * Extract @counter-style rules from styles, merging with global config.\n * Deduplicates by name; component-local definitions override global ones with\n * the same name (local wins).\n */\nexport function extractCounterStyleFromStyles(\n styles: Styles,\n globalCounterStyle?: Record<string, CounterStyleDescriptors> | null,\n): ExtractedCounterStyle[] {\n const byName = new Map<string, ExtractedCounterStyle>();\n\n function addCounterStyle(name: string, descriptors: CounterStyleDescriptors) {\n byName.set(name, { name, css: formatCounterStyleRule(name, descriptors) });\n }\n\n // Global counter styles first, then local — local replaces global on conflict.\n if (globalCounterStyle) {\n for (const [name, descriptors] of Object.entries(globalCounterStyle)) {\n addCounterStyle(name, descriptors);\n }\n }\n\n if (hasLocalCounterStyle(styles)) {\n const local = extractLocalCounterStyle(styles);\n if (local) {\n for (const [name, descriptors] of Object.entries(local)) {\n addCounterStyle(name, descriptors);\n }\n }\n }\n\n return [...byName.values()];\n}\n\n// ============================================================================\n// Function Extraction (zero-runtime)\n// ============================================================================\n\nexport interface ExtractedFunction {\n name: string;\n css: string;\n}\n\n/**\n * Extract @function rules from styles, merging with global config.\n * Deduplicates by CSS function name; component-local definitions override\n * global ones with the same name (local wins).\n */\nexport function extractFunctionsFromStyles(\n styles: Styles,\n globalFunction?: Record<string, FunctionDefinition> | null,\n): ExtractedFunction[] {\n // @function polyfill: register definitions as inline closures so call sites\n // are expanded to plain CSS during chunk rendering. No native @function rules\n // are emitted. Global definitions are also registered here as a safety net in\n // case configure() ran in a separate module scope.\n if (isFunctionsPolyfillEnabled()) {\n if (globalFunction) {\n for (const [name, definition] of Object.entries(globalFunction)) {\n registerFunctionPolyfill(name, definition);\n }\n }\n registerLocalFunctionPolyfills(styles);\n return [];\n }\n\n const byName = new Map<string, ExtractedFunction>();\n\n function addFunction(name: string, definition: FunctionDefinition) {\n const cssName = parseFunctionName(name);\n byName.set(cssName, {\n name: cssName,\n css: formatFunctionRule(name, definition),\n });\n }\n\n // Global functions first, then local — local replaces global on conflict.\n if (globalFunction) {\n for (const [name, definition] of Object.entries(globalFunction)) {\n addFunction(name, definition);\n }\n }\n\n if (hasLocalFunctions(styles)) {\n const local = extractLocalFunctions(styles);\n if (local) {\n for (const [name, definition] of Object.entries(local)) {\n addFunction(name, definition);\n }\n }\n }\n\n return [...byName.values()];\n}\n","import * as fs from 'fs';\nimport * as path from 'path';\n\nexport interface CSSWriterOptions {\n /** Enable source comments in output (e.g., \"from: Button.tsx\") */\n devMode?: boolean;\n}\n\ninterface CSSBlock {\n css: string;\n source?: string;\n}\n\nexport class CSSWriter {\n private cssBlocks = new Map<string, CSSBlock>();\n private outputPath: string;\n private devMode: boolean;\n\n constructor(outputPath: string, options: CSSWriterOptions = {}) {\n this.outputPath = outputPath;\n this.devMode = options.devMode ?? false;\n }\n\n /**\n * Add CSS block with deduplication key\n * @param key - Unique key for deduplication\n * @param css - CSS content\n * @param source - Optional source file path (used in devMode)\n */\n add(key: string, css: string, source?: string): void {\n this.cssBlocks.set(key, { css, source });\n }\n\n /**\n * Check if a key already exists\n */\n has(key: string): boolean {\n return this.cssBlocks.has(key);\n }\n\n /**\n * Get the number of CSS blocks\n */\n get size(): number {\n return this.cssBlocks.size;\n }\n\n /**\n * Write all collected CSS to the output file\n */\n write(): void {\n const outputDir = path.dirname(this.outputPath);\n\n // Ensure directory exists\n if (!fs.existsSync(outputDir)) {\n fs.mkdirSync(outputDir, { recursive: true });\n }\n\n // Combine all CSS blocks with optional source comments\n const cssBlocks: string[] = [];\n for (const block of this.cssBlocks.values()) {\n if (this.devMode && block.source) {\n cssBlocks.push(`/* from: ${block.source} */\\n${block.css}`);\n } else {\n cssBlocks.push(block.css);\n }\n }\n const css = cssBlocks.join('\\n\\n');\n\n // Add header comment\n const header = `/* Generated by @tenphi/tasty/zero - DO NOT EDIT */\\n\\n`;\n\n fs.writeFileSync(this.outputPath, header + css);\n }\n\n /**\n * Get all CSS as string (for testing or in-memory use)\n */\n getCSS(): string {\n const cssBlocks: string[] = [];\n for (const block of this.cssBlocks.values()) {\n if (this.devMode && block.source) {\n cssBlocks.push(`/* from: ${block.source} */\\n${block.css}`);\n } else {\n cssBlocks.push(block.css);\n }\n }\n return cssBlocks.join('\\n\\n');\n }\n\n /**\n * Clear all collected CSS\n */\n clear(): void {\n this.cssBlocks.clear();\n }\n\n /**\n * Get the output path\n */\n getOutputPath(): string {\n return this.outputPath;\n }\n}\n\n/**\n * Factory for creating a {@link CSSWriter} instance.\n *\n * Canonical functional entry point; the `CSSWriter` class remains exported\n * for advanced/internal use.\n *\n * @example\n * ```ts\n * import { createCSSWriter } from '@tenphi/tasty/zero';\n *\n * const writer = createCSSWriter('output.css', { devMode: true });\n * ```\n */\nexport function createCSSWriter(\n outputPath: string,\n options?: CSSWriterOptions,\n): CSSWriter {\n return new CSSWriter(outputPath, options);\n}\n"],"mappings":";;;;;;;;;;;;;AAiFA,IAAI,oBAAA;;;;;;AAOJ,SAAgB,uBAAuB,QAAsB;CAC3D,mBAAmB,MAAM;CACzB,oBAAoB;AACtB;;;;;;AAeA,SAAS,kBAAkB,UAA0B;CACnD,MAAM,OAAO,WAAW,KAAK,CAAC,CAAC,OAAO,QAAQ,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC;CACxE,OAAO,cAAc,mBAAmB,IAAI;AAC9C;;;;;AAMA,SAAgB,wBAAwB,QAAkC;CACxE,MAAM,SAA2B,CAAC;CAGlC,MAAM,WAAW,oBAAoB,MAAiC;CAEtE,KAAK,MAAM,CAAC,WAAW,mBAAmB,UAAU;EAClD,IAAI,eAAe,WAAW,GAAG;EAGjC,MAAM,WAAW,sBAAsB,QAAQ,WAAW,cAAc;EAGxE,MAAM,eAAe,qBACnB,QACA,WACA,cACF;EAEA,IAAI,aAAa,MAAM,WAAW,GAAG;EAGrC,MAAM,YAAY,kBAAkB,QAAQ;EAC5C,MAAM,WAAW,IAAI,UAAU,GAAG;EAGlC,MAAM,MAAM,iBAAiB,aAAa,OAAO,QAAQ;EAEzD,OAAO,KAAK;GAAE;GAAW;EAAI,CAAC;CAChC;CAEA,OAAO;AACT;;;;;AAMA,SAAgB,yBACd,UACA,QACmB;CAMnB,OAAO;EAAE;EAAU,KAFP,oBAFE,aAAa,QAAQ,QAEC,CAEf;CAAE;AACzB;;;;;;AAOA,SAAS,iBAAiB,OAAsB,cAA8B;CAC5E,OAAO,MACJ,KAAK,SAAS;EA0Cb,IAAI,MAAM,IAvCY,MAAM,QAAQ,KAAK,QAAQ,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GAAG;EAG5B,OAAO,UAAU,KAAK,MAAM;CAC9B;;;;CAKA,QAAc;EACZ,KAAK,UAAU,MAAM;CACvB;;;;CAKA,gBAAwB;EACtB,OAAO,KAAK;CACd;AACF;;;;;;;;;;;;;;AAeA,SAAgB,gBACd,YACA,SACW;CACX,OAAO,IAAI,UAAU,YAAY,OAAO;AAC1C"}
@@ -16,7 +16,7 @@ function formatGlobalRules(rules) {
16
16
  }
17
17
  return cssRules.join("\n");
18
18
  }
19
-
20
19
  //#endregion
21
- export { formatGlobalRules };
22
- //# sourceMappingURL=format-global-rules.js.map
20
+ export { formatGlobalRules as t };
21
+
22
+ //# sourceMappingURL=format-global-rules-DklyaXv-.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-global-rules-DklyaXv-.js","names":[],"sources":["../src/ssr/format-global-rules.ts"],"sourcesContent":["/**\n * Format global CSS rules for SSR output.\n *\n * Unlike formatRules() which applies className-based specificity doubling,\n * this function formats rules that already have their full selectors\n * (from renderStyles called with a selector string).\n */\n\nimport type { StyleResult } from '../pipeline';\n\n/**\n * Format an array of global StyleResult rules into a CSS text string.\n *\n * Rules already have their full selectors applied by renderStyles().\n * Handles rootPrefix prepending and at-rule wrapping.\n */\nexport function formatGlobalRules(rules: StyleResult[]): string {\n if (rules.length === 0) return '';\n\n const cssRules: string[] = [];\n\n for (const rule of rules) {\n const selector = rule.rootPrefix\n ? `${rule.rootPrefix} ${rule.selector}`\n : rule.selector;\n\n const baseRule = `${selector} { ${rule.declarations} }`;\n\n let fullRule = baseRule;\n if (rule.atRules && rule.atRules.length > 0) {\n fullRule = rule.atRules.reduce(\n (css, atRule) => `${atRule} { ${css} }`,\n baseRule,\n );\n }\n\n cssRules.push(fullRule);\n }\n\n return cssRules.join('\\n');\n}\n"],"mappings":";;;;;;;AAgBA,SAAgB,kBAAkB,OAA8B;CAC9D,IAAI,MAAM,WAAW,GAAG,OAAO;CAE/B,MAAM,WAAqB,CAAC;CAE5B,KAAK,MAAM,QAAQ,OAAO;EAKxB,MAAM,WAAW,GAJA,KAAK,aAClB,GAAG,KAAK,WAAW,GAAG,KAAK,aAC3B,KAAK,SAEoB,KAAK,KAAK,aAAa;EAEpD,IAAI,WAAW;EACf,IAAI,KAAK,WAAW,KAAK,QAAQ,SAAS,GACxC,WAAW,KAAK,QAAQ,QACrB,KAAK,WAAW,GAAG,OAAO,KAAK,IAAI,KACpC,QACF;EAGF,SAAS,KAAK,QAAQ;CACxB;CAEA,OAAO,SAAS,KAAK,IAAI;AAC3B"}
@@ -1,3 +1,34 @@
1
+ import { Gt as parseStyle, yt as getEffectiveDefinition } from "./config-B3gPdCqd.js";
2
+ //#region src/ssr/format-property.ts
3
+ /**
4
+ * Format a single @property rule as a CSS string.
5
+ *
6
+ * Returns the full `@property --name { ... }` text, or empty string
7
+ * if the token is invalid.
8
+ */
9
+ function formatPropertyCSS(token, definition) {
10
+ const result = getEffectiveDefinition(token, definition);
11
+ if (!result.isValid) return "";
12
+ return buildPropertyRule(result.cssName, result.definition);
13
+ }
14
+ function buildPropertyRule(cssName, definition) {
15
+ const parts = [];
16
+ if (definition.syntax != null) {
17
+ let syntax = String(definition.syntax).trim();
18
+ if (!/^['"]/u.test(syntax)) syntax = `"${syntax}"`;
19
+ parts.push(`syntax: ${syntax};`);
20
+ }
21
+ const inherits = definition.inherits ?? true;
22
+ parts.push(`inherits: ${inherits ? "true" : "false"};`);
23
+ if (definition.initialValue != null) {
24
+ let initialValueStr;
25
+ if (typeof definition.initialValue === "number") initialValueStr = String(definition.initialValue);
26
+ else initialValueStr = parseStyle(definition.initialValue).output;
27
+ parts.push(`initial-value: ${initialValueStr};`);
28
+ }
29
+ return `@property ${cssName} { ${parts.join(" ").trim()} }`;
30
+ }
31
+ //#endregion
1
32
  //#region src/ssr/format-rules.ts
2
33
  /**
3
34
  * Resolve selectors for a rule, applying className-based specificity doubling
@@ -17,7 +48,7 @@ function resolveSelector(rule, className) {
17
48
  return selector;
18
49
  }
19
50
  /**
20
- * Group rules by selector + at-rules and merge their declarations.
51
+ * Group rules by selector + at-rules + startingStyle and merge their declarations.
21
52
  * Mirrors the grouping logic in SheetManager.insertRule().
22
53
  */
23
54
  function groupRules(rules) {
@@ -25,13 +56,14 @@ function groupRules(rules) {
25
56
  const order = [];
26
57
  const atKey = (at) => at && at.length ? at.join("|") : "";
27
58
  for (const r of rules) {
28
- const key = `${atKey(r.atRules)}||${r.selector}`;
59
+ const key = `${atKey(r.atRules)}||${r.selector}||${r.startingStyle ? "1" : "0"}`;
29
60
  const existing = groupMap.get(key);
30
61
  if (existing) existing.declarations = existing.declarations ? `${existing.declarations} ${r.declarations}` : r.declarations;
31
62
  else {
32
63
  groupMap.set(key, {
33
64
  selector: r.selector,
34
65
  atRules: r.atRules,
66
+ startingStyle: r.startingStyle,
35
67
  declarations: r.declarations
36
68
  });
37
69
  order.push(key);
@@ -53,18 +85,20 @@ function formatRules(rules, className) {
53
85
  const grouped = groupRules(rules.map((rule) => ({
54
86
  selector: resolveSelector(rule, className),
55
87
  declarations: rule.declarations,
56
- atRules: rule.atRules
88
+ atRules: rule.atRules,
89
+ startingStyle: rule.startingStyle
57
90
  })));
58
91
  const cssRules = [];
59
92
  for (const rule of grouped) {
60
- const baseRule = `${rule.selector} { ${rule.declarations} }`;
93
+ const innerContent = rule.startingStyle ? `@starting-style { ${rule.declarations} }` : rule.declarations;
94
+ const baseRule = `${rule.selector} { ${innerContent} }`;
61
95
  let fullRule = baseRule;
62
96
  if (rule.atRules && rule.atRules.length > 0) fullRule = rule.atRules.reduce((css, atRule) => `${atRule} { ${css} }`, baseRule);
63
97
  cssRules.push(fullRule);
64
98
  }
65
99
  return cssRules.join("\n");
66
100
  }
67
-
68
101
  //#endregion
69
- export { formatRules };
70
- //# sourceMappingURL=format-rules.js.map
102
+ export { formatPropertyCSS as n, formatRules as t };
103
+
104
+ //# sourceMappingURL=format-rules-XRw9u7d4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-rules-XRw9u7d4.js","names":[],"sources":["../src/ssr/format-property.ts","../src/ssr/format-rules.ts"],"sourcesContent":["/**\n * Format @property CSS rules for SSR output.\n *\n * Replicates the CSS construction from StyleInjector.property()\n * but returns a CSS string instead of inserting into the DOM.\n */\n\nimport type { PropertyDefinition } from '../injector/types';\nimport { getEffectiveDefinition } from '../properties';\nimport type { StyleValue } from '../utils/styles';\nimport { parseStyle } from '../utils/styles';\n\n/**\n * Format a single @property rule as a CSS string.\n *\n * Returns the full `@property --name { ... }` text, or empty string\n * if the token is invalid.\n */\nexport function formatPropertyCSS(\n token: string,\n definition: PropertyDefinition,\n): string {\n const result = getEffectiveDefinition(token, definition);\n if (!result.isValid) return '';\n\n return buildPropertyRule(result.cssName, result.definition);\n}\n\nfunction buildPropertyRule(\n cssName: string,\n definition: PropertyDefinition,\n): string {\n const parts: string[] = [];\n\n if (definition.syntax != null) {\n let syntax = String(definition.syntax).trim();\n if (!/^['\"]/u.test(syntax)) syntax = `\"${syntax}\"`;\n parts.push(`syntax: ${syntax};`);\n }\n\n const inherits = definition.inherits ?? true;\n parts.push(`inherits: ${inherits ? 'true' : 'false'};`);\n\n if (definition.initialValue != null) {\n let initialValueStr: string;\n if (typeof definition.initialValue === 'number') {\n initialValueStr = String(definition.initialValue);\n } else {\n initialValueStr = parseStyle(\n definition.initialValue as StyleValue,\n ).output;\n }\n parts.push(`initial-value: ${initialValueStr};`);\n }\n\n const declarations = parts.join(' ').trim();\n return `@property ${cssName} { ${declarations} }`;\n}\n","/**\n * Shared CSS rule formatting utility.\n *\n * Extracted from SheetManager to allow both the DOM-based injector (client)\n * and the ServerStyleCollector (server) to produce identical CSS text\n * from StyleResult arrays.\n */\n\nimport type { StyleResult } from '../pipeline';\n\n/**\n * Resolve selectors for a rule, applying className-based specificity doubling\n * and rootPrefix handling. Mirrors the logic in StyleInjector.inject().\n */\nfunction resolveSelector(rule: StyleResult, className: string): string {\n let selector = rule.selector;\n\n if (rule.needsClassName) {\n const selectorParts = selector ? selector.split('|||') : [''];\n const classPrefix = `.${className}.${className}`;\n\n selector = selectorParts\n .map((part) => {\n const classSelector = part ? `${classPrefix}${part}` : classPrefix;\n\n if (rule.rootPrefix) {\n return `${rule.rootPrefix} ${classSelector}`;\n }\n return classSelector;\n })\n .join(', ');\n }\n\n return selector;\n}\n\ninterface GroupedRule {\n selector: string;\n declarations: string;\n atRules?: string[];\n startingStyle?: boolean;\n}\n\n/**\n * Group rules by selector + at-rules + startingStyle and merge their declarations.\n * Mirrors the grouping logic in SheetManager.insertRule().\n */\nfunction groupRules(rules: GroupedRule[]): GroupedRule[] {\n const groupMap = new Map<string, GroupedRule>();\n const order: string[] = [];\n\n const atKey = (at?: string[]) => (at && at.length ? at.join('|') : '');\n\n for (const r of rules) {\n const key = `${atKey(r.atRules)}||${r.selector}||${r.startingStyle ? '1' : '0'}`;\n const existing = groupMap.get(key);\n if (existing) {\n existing.declarations = existing.declarations\n ? `${existing.declarations} ${r.declarations}`\n : r.declarations;\n } else {\n groupMap.set(key, {\n selector: r.selector,\n atRules: r.atRules,\n startingStyle: r.startingStyle,\n declarations: r.declarations,\n });\n order.push(key);\n }\n }\n\n return order.map((key) => groupMap.get(key)!);\n}\n\n/**\n * Format an array of StyleResult rules into a CSS text string.\n *\n * Applies className-based specificity doubling (.cls.cls),\n * groups rules by selector + at-rules, and wraps with at-rule blocks.\n *\n * Produces the same CSS text as SheetManager.insertRule() would insert\n * into the DOM, but as a plain string suitable for SSR output.\n */\nexport function formatRules(rules: StyleResult[], className: string): string {\n if (rules.length === 0) return '';\n\n const resolvedRules = rules.map((rule) => ({\n selector: resolveSelector(rule, className),\n declarations: rule.declarations,\n atRules: rule.atRules,\n startingStyle: rule.startingStyle,\n }));\n\n const grouped = groupRules(resolvedRules);\n const cssRules: string[] = [];\n\n for (const rule of grouped) {\n const innerContent = rule.startingStyle\n ? `@starting-style { ${rule.declarations} }`\n : rule.declarations;\n const baseRule = `${rule.selector} { ${innerContent} }`;\n\n let fullRule = baseRule;\n if (rule.atRules && rule.atRules.length > 0) {\n fullRule = rule.atRules.reduce(\n (css, atRule) => `${atRule} { ${css} }`,\n baseRule,\n );\n }\n\n cssRules.push(fullRule);\n }\n\n return cssRules.join('\\n');\n}\n"],"mappings":";;;;;;;;AAkBA,SAAgB,kBACd,OACA,YACQ;CACR,MAAM,SAAS,uBAAuB,OAAO,UAAU;CACvD,IAAI,CAAC,OAAO,SAAS,OAAO;CAE5B,OAAO,kBAAkB,OAAO,SAAS,OAAO,UAAU;AAC5D;AAEA,SAAS,kBACP,SACA,YACQ;CACR,MAAM,QAAkB,CAAC;CAEzB,IAAI,WAAW,UAAU,MAAM;EAC7B,IAAI,SAAS,OAAO,WAAW,MAAM,CAAC,CAAC,KAAK;EAC5C,IAAI,CAAC,SAAS,KAAK,MAAM,GAAG,SAAS,IAAI,OAAO;EAChD,MAAM,KAAK,WAAW,OAAO,EAAE;CACjC;CAEA,MAAM,WAAW,WAAW,YAAY;CACxC,MAAM,KAAK,aAAa,WAAW,SAAS,QAAQ,EAAE;CAEtD,IAAI,WAAW,gBAAgB,MAAM;EACnC,IAAI;EACJ,IAAI,OAAO,WAAW,iBAAiB,UACrC,kBAAkB,OAAO,WAAW,YAAY;OAEhD,kBAAkB,WAChB,WAAW,YACb,CAAC,CAAC;EAEJ,MAAM,KAAK,kBAAkB,gBAAgB,EAAE;CACjD;CAGA,OAAO,aAAa,QAAQ,KADP,MAAM,KAAK,GAAG,CAAC,CAAC,KACO,EAAE;AAChD;;;;;;;AC3CA,SAAS,gBAAgB,MAAmB,WAA2B;CACrE,IAAI,WAAW,KAAK;CAEpB,IAAI,KAAK,gBAAgB;EACvB,MAAM,gBAAgB,WAAW,SAAS,MAAM,KAAK,IAAI,CAAC,EAAE;EAC5D,MAAM,cAAc,IAAI,UAAU,GAAG;EAErC,WAAW,cACR,KAAK,SAAS;GACb,MAAM,gBAAgB,OAAO,GAAG,cAAc,SAAS;GAEvD,IAAI,KAAK,YACP,OAAO,GAAG,KAAK,WAAW,GAAG;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KAAK,QAAQ;CACxB;CAEA,OAAO,SAAS,KAAK,IAAI;AAC3B"}
@@ -0,0 +1,37 @@
1
+ import { c as getGlobalInjector } from "./config-B3gPdCqd.js";
2
+ //#region src/ssr/hydrate.ts
3
+ /**
4
+ * Client-side cache hydration for SSR/RSC.
5
+ *
6
+ * Pre-populates the client injector's rules map with class names
7
+ * rendered on the server. With hash-based naming, the client derives
8
+ * the same class name from the same cache key, so only the class name
9
+ * list needs to cross the wire — no cache keys or counters.
10
+ */
11
+ /**
12
+ * Pre-populate the client-side style registry from the server's class name list.
13
+ *
14
+ * Call this before ReactDOM.hydrateRoot() or ensure it runs before
15
+ * any tasty() component renders on the client.
16
+ *
17
+ * When called without arguments, reads the class list from `window.__TASTY__`
18
+ * (populated by inline scripts emitted during SSR/RSC streaming).
19
+ */
20
+ function hydrateTastyClasses(classes) {
21
+ if (typeof document === "undefined") return;
22
+ if (!classes) classes = typeof window !== "undefined" ? window.__TASTY__ : void 0;
23
+ if (!classes?.length) return;
24
+ const registry = getGlobalInjector()._sheetManager.getRegistry(document);
25
+ for (const cls of classes) if (!registry.rules.has(cls)) {
26
+ registry.rules.set(cls, {
27
+ className: cls,
28
+ ruleIndex: -2,
29
+ sheetIndex: -2
30
+ });
31
+ registry.pinCounts.set(cls, 0);
32
+ }
33
+ }
34
+ //#endregion
35
+ export { hydrateTastyClasses as t };
36
+
37
+ //# sourceMappingURL=hydrate-CNOmZprz.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hydrate-CNOmZprz.js","names":[],"sources":["../src/ssr/hydrate.ts"],"sourcesContent":["/**\n * Client-side cache hydration for SSR/RSC.\n *\n * Pre-populates the client injector's rules map with class names\n * rendered on the server. With hash-based naming, the client derives\n * the same class name from the same cache key, so only the class name\n * list needs to cross the wire — no cache keys or counters.\n */\n\nimport { getGlobalInjector } from '../config';\nimport { HYDRATED_RULE_INDEX } from '../injector/types';\n\n/**\n * Pre-populate the client-side style registry from the server's class name list.\n *\n * Call this before ReactDOM.hydrateRoot() or ensure it runs before\n * any tasty() component renders on the client.\n *\n * When called without arguments, reads the class list from `window.__TASTY__`\n * (populated by inline scripts emitted during SSR/RSC streaming).\n */\nexport function hydrateTastyClasses(classes?: string[]): void {\n if (typeof document === 'undefined') return;\n\n if (!classes) {\n classes = typeof window !== 'undefined' ? window.__TASTY__ : undefined;\n }\n\n if (!classes?.length) return;\n\n const injector = getGlobalInjector();\n const registry = injector._sheetManager.getRegistry(document);\n\n for (const cls of classes) {\n if (!registry.rules.has(cls)) {\n registry.rules.set(cls, {\n className: cls,\n ruleIndex: HYDRATED_RULE_INDEX,\n sheetIndex: HYDRATED_RULE_INDEX,\n });\n registry.pinCounts.set(cls, 0);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,oBAAoB,SAA0B;CAC5D,IAAI,OAAO,aAAa,aAAa;CAErC,IAAI,CAAC,SACH,UAAU,OAAO,WAAW,cAAc,OAAO,YAAY,KAAA;CAG/D,IAAI,CAAC,SAAS,QAAQ;CAGtB,MAAM,WADW,kBACO,CAAC,CAAC,cAAc,YAAY,QAAQ;CAE5D,KAAK,MAAM,OAAO,SAChB,IAAI,CAAC,SAAS,MAAM,IAAI,GAAG,GAAG;EAC5B,SAAS,MAAM,IAAI,KAAK;GACtB,WAAW;GACX,WAAA;GACA,YAAA;EACF,CAAC;EACD,SAAS,UAAU,IAAI,KAAK,CAAC;CAC/B;AAEJ"}