@tenphi/tasty 2.0.2 → 2.0.4

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 (321) hide show
  1. package/dist/{ssr/async-storage.js → async-storage-B7_o6FKt.js} +2 -2
  2. package/dist/async-storage-B7_o6FKt.js.map +1 -0
  3. package/dist/{ssr/collector.d.ts → collector-CkZ517g4.d.ts} +3 -3
  4. package/dist/{ssr/collector.js → collector-DXqvGOb1.js} +5 -10
  5. package/dist/collector-DXqvGOb1.js.map +1 -0
  6. package/dist/config-5jzS6k6B.js +10005 -0
  7. package/dist/config-5jzS6k6B.js.map +1 -0
  8. package/dist/config-DknGsfMo.d.ts +857 -0
  9. package/dist/{ssr/context.js → context-CkSg-kDT.js} +11 -3
  10. package/dist/context-CkSg-kDT.js.map +1 -0
  11. package/dist/core/index.d.ts +5 -34
  12. package/dist/core/index.js +5 -26
  13. package/dist/core-CtU6-9OC.js +1507 -0
  14. package/dist/core-CtU6-9OC.js.map +1 -0
  15. package/dist/{zero/extractor.js → css-writer-DHkX0JuE.js} +74 -11
  16. package/dist/css-writer-DHkX0JuE.js.map +1 -0
  17. package/dist/{ssr/format-global-rules.js → format-global-rules-Dbc_1tc3.js} +2 -2
  18. package/dist/format-global-rules-Dbc_1tc3.js.map +1 -0
  19. package/dist/format-rules-DH13ewDu.js +143 -0
  20. package/dist/format-rules-DH13ewDu.js.map +1 -0
  21. package/dist/{ssr/hydrate.js → hydrate-C1Gv-DoS.js} +3 -3
  22. package/dist/hydrate-C1Gv-DoS.js.map +1 -0
  23. package/dist/{styles/types.d.ts → index-PzENbpAq.d.ts} +701 -5
  24. package/dist/index-o7zV2yCr.d.ts +1561 -0
  25. package/dist/index.d.ts +5 -51
  26. package/dist/index.js +728 -35
  27. package/dist/index.js.map +1 -0
  28. package/dist/keyframes-b7X3UxDV.js +587 -0
  29. package/dist/keyframes-b7X3UxDV.js.map +1 -0
  30. package/dist/{utils/merge-styles.d.ts → merge-styles-C7KTy7MY.d.ts} +3 -3
  31. package/dist/{utils/merge-styles.js → merge-styles-Tgo3BbL2.js} +3 -4
  32. package/dist/merge-styles-Tgo3BbL2.js.map +1 -0
  33. package/dist/{utils/resolve-recipes.js → resolve-recipes-Ca2-5CxM.js} +4 -6
  34. package/dist/resolve-recipes-Ca2-5CxM.js.map +1 -0
  35. package/dist/ssr/astro-client.js +1 -1
  36. package/dist/ssr/astro.js +4 -4
  37. package/dist/ssr/index.d.ts +44 -4
  38. package/dist/ssr/index.js +4 -4
  39. package/dist/ssr/next.d.ts +1 -1
  40. package/dist/ssr/next.js +6 -6
  41. package/dist/ssr/next.js.map +1 -1
  42. package/dist/static/index.d.ts +91 -5
  43. package/dist/static/index.js +49 -3
  44. package/dist/static/index.js.map +1 -0
  45. package/dist/zero/babel.d.ts +1 -1
  46. package/dist/zero/babel.js +10 -6
  47. package/dist/zero/babel.js.map +1 -1
  48. package/dist/zero/index.d.ts +67 -3
  49. package/dist/zero/index.js +1 -2
  50. package/docs/pipeline.md +204 -50
  51. package/package.json +3 -3
  52. package/dist/_virtual/_rolldown/runtime.js +0 -7
  53. package/dist/chunks/cacheKey.d.ts +0 -1
  54. package/dist/chunks/cacheKey.js +0 -77
  55. package/dist/chunks/cacheKey.js.map +0 -1
  56. package/dist/chunks/definitions.d.ts +0 -37
  57. package/dist/chunks/definitions.js +0 -258
  58. package/dist/chunks/definitions.js.map +0 -1
  59. package/dist/chunks/index.d.ts +0 -1
  60. package/dist/chunks/renderChunk.d.ts +0 -1
  61. package/dist/chunks/renderChunk.js +0 -59
  62. package/dist/chunks/renderChunk.js.map +0 -1
  63. package/dist/compute-styles.d.ts +0 -31
  64. package/dist/compute-styles.js +0 -322
  65. package/dist/compute-styles.js.map +0 -1
  66. package/dist/config.d.ts +0 -407
  67. package/dist/config.js +0 -591
  68. package/dist/config.js.map +0 -1
  69. package/dist/counter-style/index.js +0 -51
  70. package/dist/counter-style/index.js.map +0 -1
  71. package/dist/debug.d.ts +0 -89
  72. package/dist/debug.js +0 -453
  73. package/dist/debug.js.map +0 -1
  74. package/dist/font-face/index.js +0 -63
  75. package/dist/font-face/index.js.map +0 -1
  76. package/dist/hooks/index.d.ts +0 -7
  77. package/dist/hooks/useCounterStyle.d.ts +0 -36
  78. package/dist/hooks/useCounterStyle.js +0 -65
  79. package/dist/hooks/useCounterStyle.js.map +0 -1
  80. package/dist/hooks/useFontFace.d.ts +0 -45
  81. package/dist/hooks/useFontFace.js +0 -66
  82. package/dist/hooks/useFontFace.js.map +0 -1
  83. package/dist/hooks/useGlobalStyles.d.ts +0 -46
  84. package/dist/hooks/useGlobalStyles.js +0 -88
  85. package/dist/hooks/useGlobalStyles.js.map +0 -1
  86. package/dist/hooks/useKeyframes.d.ts +0 -58
  87. package/dist/hooks/useKeyframes.js +0 -55
  88. package/dist/hooks/useKeyframes.js.map +0 -1
  89. package/dist/hooks/useProperty.d.ts +0 -81
  90. package/dist/hooks/useProperty.js +0 -96
  91. package/dist/hooks/useProperty.js.map +0 -1
  92. package/dist/hooks/useRawCSS.d.ts +0 -22
  93. package/dist/hooks/useRawCSS.js +0 -103
  94. package/dist/hooks/useRawCSS.js.map +0 -1
  95. package/dist/hooks/useStyles.d.ts +0 -40
  96. package/dist/hooks/useStyles.js +0 -31
  97. package/dist/hooks/useStyles.js.map +0 -1
  98. package/dist/injector/index.d.ts +0 -182
  99. package/dist/injector/index.js +0 -185
  100. package/dist/injector/index.js.map +0 -1
  101. package/dist/injector/injector.d.ts +0 -198
  102. package/dist/injector/injector.js +0 -651
  103. package/dist/injector/injector.js.map +0 -1
  104. package/dist/injector/sheet-manager.d.ts +0 -132
  105. package/dist/injector/sheet-manager.js +0 -699
  106. package/dist/injector/sheet-manager.js.map +0 -1
  107. package/dist/injector/types.d.ts +0 -235
  108. package/dist/keyframes/index.js +0 -206
  109. package/dist/keyframes/index.js.map +0 -1
  110. package/dist/parser/classify.js +0 -319
  111. package/dist/parser/classify.js.map +0 -1
  112. package/dist/parser/const.js +0 -60
  113. package/dist/parser/const.js.map +0 -1
  114. package/dist/parser/lru.js +0 -109
  115. package/dist/parser/lru.js.map +0 -1
  116. package/dist/parser/parser.d.ts +0 -25
  117. package/dist/parser/parser.js +0 -115
  118. package/dist/parser/parser.js.map +0 -1
  119. package/dist/parser/tokenizer.js +0 -69
  120. package/dist/parser/tokenizer.js.map +0 -1
  121. package/dist/parser/types.d.ts +0 -51
  122. package/dist/parser/types.js +0 -46
  123. package/dist/parser/types.js.map +0 -1
  124. package/dist/pipeline/conditions.d.ts +0 -134
  125. package/dist/pipeline/conditions.js +0 -406
  126. package/dist/pipeline/conditions.js.map +0 -1
  127. package/dist/pipeline/exclusive.js +0 -382
  128. package/dist/pipeline/exclusive.js.map +0 -1
  129. package/dist/pipeline/index.d.ts +0 -55
  130. package/dist/pipeline/index.js +0 -708
  131. package/dist/pipeline/index.js.map +0 -1
  132. package/dist/pipeline/materialize.js +0 -1157
  133. package/dist/pipeline/materialize.js.map +0 -1
  134. package/dist/pipeline/parseStateKey.d.ts +0 -15
  135. package/dist/pipeline/parseStateKey.js +0 -446
  136. package/dist/pipeline/parseStateKey.js.map +0 -1
  137. package/dist/pipeline/simplify.js +0 -690
  138. package/dist/pipeline/simplify.js.map +0 -1
  139. package/dist/pipeline/warnings.js +0 -18
  140. package/dist/pipeline/warnings.js.map +0 -1
  141. package/dist/plugins/index.d.ts +0 -2
  142. package/dist/plugins/okhsl-plugin.d.ts +0 -35
  143. package/dist/plugins/okhsl-plugin.js +0 -97
  144. package/dist/plugins/okhsl-plugin.js.map +0 -1
  145. package/dist/plugins/types.d.ts +0 -87
  146. package/dist/properties/index.js +0 -222
  147. package/dist/properties/index.js.map +0 -1
  148. package/dist/properties/property-type-resolver.d.ts +0 -24
  149. package/dist/properties/property-type-resolver.js +0 -90
  150. package/dist/properties/property-type-resolver.js.map +0 -1
  151. package/dist/rsc-cache.js +0 -79
  152. package/dist/rsc-cache.js.map +0 -1
  153. package/dist/ssr/async-storage.d.ts +0 -17
  154. package/dist/ssr/async-storage.js.map +0 -1
  155. package/dist/ssr/collect-auto-properties.js +0 -58
  156. package/dist/ssr/collect-auto-properties.js.map +0 -1
  157. package/dist/ssr/collector.js.map +0 -1
  158. package/dist/ssr/context.js.map +0 -1
  159. package/dist/ssr/format-global-rules.js.map +0 -1
  160. package/dist/ssr/format-keyframes.js +0 -69
  161. package/dist/ssr/format-keyframes.js.map +0 -1
  162. package/dist/ssr/format-property.js +0 -49
  163. package/dist/ssr/format-property.js.map +0 -1
  164. package/dist/ssr/format-rules.js +0 -73
  165. package/dist/ssr/format-rules.js.map +0 -1
  166. package/dist/ssr/hydrate.d.ts +0 -29
  167. package/dist/ssr/hydrate.js.map +0 -1
  168. package/dist/ssr/ssr-collector-ref.js +0 -29
  169. package/dist/ssr/ssr-collector-ref.js.map +0 -1
  170. package/dist/states/index.d.ts +0 -49
  171. package/dist/states/index.js +0 -170
  172. package/dist/states/index.js.map +0 -1
  173. package/dist/static/tastyStatic.d.ts +0 -46
  174. package/dist/static/tastyStatic.js +0 -30
  175. package/dist/static/tastyStatic.js.map +0 -1
  176. package/dist/static/types.d.ts +0 -49
  177. package/dist/static/types.js +0 -24
  178. package/dist/static/types.js.map +0 -1
  179. package/dist/styles/border.d.ts +0 -25
  180. package/dist/styles/border.js +0 -120
  181. package/dist/styles/border.js.map +0 -1
  182. package/dist/styles/color.d.ts +0 -14
  183. package/dist/styles/color.js +0 -26
  184. package/dist/styles/color.js.map +0 -1
  185. package/dist/styles/const.js +0 -17
  186. package/dist/styles/const.js.map +0 -1
  187. package/dist/styles/createStyle.js +0 -79
  188. package/dist/styles/createStyle.js.map +0 -1
  189. package/dist/styles/dimension.js +0 -109
  190. package/dist/styles/dimension.js.map +0 -1
  191. package/dist/styles/directional.js +0 -133
  192. package/dist/styles/directional.js.map +0 -1
  193. package/dist/styles/display.d.ts +0 -30
  194. package/dist/styles/display.js +0 -73
  195. package/dist/styles/display.js.map +0 -1
  196. package/dist/styles/fade.d.ts +0 -15
  197. package/dist/styles/fade.js +0 -62
  198. package/dist/styles/fade.js.map +0 -1
  199. package/dist/styles/fill.d.ts +0 -42
  200. package/dist/styles/fill.js +0 -51
  201. package/dist/styles/fill.js.map +0 -1
  202. package/dist/styles/flow.d.ts +0 -16
  203. package/dist/styles/flow.js +0 -12
  204. package/dist/styles/flow.js.map +0 -1
  205. package/dist/styles/gap.d.ts +0 -31
  206. package/dist/styles/gap.js +0 -38
  207. package/dist/styles/gap.js.map +0 -1
  208. package/dist/styles/height.d.ts +0 -17
  209. package/dist/styles/height.js +0 -19
  210. package/dist/styles/height.js.map +0 -1
  211. package/dist/styles/index.d.ts +0 -1
  212. package/dist/styles/index.js +0 -8
  213. package/dist/styles/index.js.map +0 -1
  214. package/dist/styles/inset.d.ts +0 -24
  215. package/dist/styles/inset.js +0 -34
  216. package/dist/styles/inset.js.map +0 -1
  217. package/dist/styles/list.d.ts +0 -16
  218. package/dist/styles/list.js +0 -100
  219. package/dist/styles/list.js.map +0 -1
  220. package/dist/styles/margin.d.ts +0 -24
  221. package/dist/styles/margin.js +0 -32
  222. package/dist/styles/margin.js.map +0 -1
  223. package/dist/styles/outline.d.ts +0 -29
  224. package/dist/styles/outline.js +0 -55
  225. package/dist/styles/outline.js.map +0 -1
  226. package/dist/styles/padding.d.ts +0 -24
  227. package/dist/styles/padding.js +0 -32
  228. package/dist/styles/padding.js.map +0 -1
  229. package/dist/styles/placement.d.ts +0 -37
  230. package/dist/styles/placement.js +0 -74
  231. package/dist/styles/placement.js.map +0 -1
  232. package/dist/styles/predefined.d.ts +0 -71
  233. package/dist/styles/predefined.js +0 -237
  234. package/dist/styles/predefined.js.map +0 -1
  235. package/dist/styles/preset.d.ts +0 -52
  236. package/dist/styles/preset.js +0 -127
  237. package/dist/styles/preset.js.map +0 -1
  238. package/dist/styles/radius.d.ts +0 -12
  239. package/dist/styles/radius.js +0 -83
  240. package/dist/styles/radius.js.map +0 -1
  241. package/dist/styles/scrollMargin.d.ts +0 -24
  242. package/dist/styles/scrollMargin.js +0 -32
  243. package/dist/styles/scrollMargin.js.map +0 -1
  244. package/dist/styles/scrollbar.d.ts +0 -25
  245. package/dist/styles/scrollbar.js +0 -51
  246. package/dist/styles/scrollbar.js.map +0 -1
  247. package/dist/styles/shadow.d.ts +0 -14
  248. package/dist/styles/shadow.js +0 -25
  249. package/dist/styles/shadow.js.map +0 -1
  250. package/dist/styles/shared.js +0 -17
  251. package/dist/styles/shared.js.map +0 -1
  252. package/dist/styles/transition.d.ts +0 -14
  253. package/dist/styles/transition.js +0 -159
  254. package/dist/styles/transition.js.map +0 -1
  255. package/dist/styles/width.d.ts +0 -17
  256. package/dist/styles/width.js +0 -19
  257. package/dist/styles/width.js.map +0 -1
  258. package/dist/tasty.d.ts +0 -134
  259. package/dist/tasty.js +0 -248
  260. package/dist/tasty.js.map +0 -1
  261. package/dist/types.d.ts +0 -184
  262. package/dist/utils/cache-wrapper.js +0 -21
  263. package/dist/utils/cache-wrapper.js.map +0 -1
  264. package/dist/utils/case-converter.js +0 -8
  265. package/dist/utils/case-converter.js.map +0 -1
  266. package/dist/utils/color-math.d.ts +0 -46
  267. package/dist/utils/color-math.js +0 -749
  268. package/dist/utils/color-math.js.map +0 -1
  269. package/dist/utils/color-space.d.ts +0 -5
  270. package/dist/utils/color-space.js +0 -228
  271. package/dist/utils/color-space.js.map +0 -1
  272. package/dist/utils/colors.d.ts +0 -5
  273. package/dist/utils/colors.js +0 -10
  274. package/dist/utils/colors.js.map +0 -1
  275. package/dist/utils/css-types.d.ts +0 -7
  276. package/dist/utils/deps-equal.js +0 -15
  277. package/dist/utils/deps-equal.js.map +0 -1
  278. package/dist/utils/dotize.d.ts +0 -26
  279. package/dist/utils/dotize.js +0 -122
  280. package/dist/utils/dotize.js.map +0 -1
  281. package/dist/utils/filter-base-props.d.ts +0 -15
  282. package/dist/utils/filter-base-props.js +0 -45
  283. package/dist/utils/filter-base-props.js.map +0 -1
  284. package/dist/utils/get-display-name.d.ts +0 -7
  285. package/dist/utils/get-display-name.js +0 -10
  286. package/dist/utils/get-display-name.js.map +0 -1
  287. package/dist/utils/has-keys.js +0 -13
  288. package/dist/utils/has-keys.js.map +0 -1
  289. package/dist/utils/hash.js +0 -14
  290. package/dist/utils/hash.js.map +0 -1
  291. package/dist/utils/is-dev-env.js +0 -19
  292. package/dist/utils/is-dev-env.js.map +0 -1
  293. package/dist/utils/is-valid-element-type.js +0 -15
  294. package/dist/utils/is-valid-element-type.js.map +0 -1
  295. package/dist/utils/merge-styles.js.map +0 -1
  296. package/dist/utils/mod-attrs.d.ts +0 -6
  297. package/dist/utils/mod-attrs.js +0 -20
  298. package/dist/utils/mod-attrs.js.map +0 -1
  299. package/dist/utils/process-tokens.d.ts +0 -17
  300. package/dist/utils/process-tokens.js +0 -83
  301. package/dist/utils/process-tokens.js.map +0 -1
  302. package/dist/utils/resolve-recipes.d.ts +0 -17
  303. package/dist/utils/resolve-recipes.js.map +0 -1
  304. package/dist/utils/selector-transform.js +0 -32
  305. package/dist/utils/selector-transform.js.map +0 -1
  306. package/dist/utils/string.js +0 -8
  307. package/dist/utils/string.js.map +0 -1
  308. package/dist/utils/styles.d.ts +0 -99
  309. package/dist/utils/styles.js +0 -220
  310. package/dist/utils/styles.js.map +0 -1
  311. package/dist/utils/typography.d.ts +0 -58
  312. package/dist/utils/typography.js +0 -51
  313. package/dist/utils/typography.js.map +0 -1
  314. package/dist/utils/warnings.d.ts +0 -16
  315. package/dist/utils/warnings.js +0 -16
  316. package/dist/utils/warnings.js.map +0 -1
  317. package/dist/zero/css-writer.d.ts +0 -45
  318. package/dist/zero/css-writer.js +0 -73
  319. package/dist/zero/css-writer.js.map +0 -1
  320. package/dist/zero/extractor.d.ts +0 -24
  321. package/dist/zero/extractor.js.map +0 -1
@@ -0,0 +1,1507 @@
1
+ import { $ as parseStyle, A as extractLocalCounterStyle, C as camelToKebab, Ct as Lru, F as formatFontFaceRule, H as createStyle, I as hasLocalFontFace, M as hasLocalCounterStyle, N as extractLocalFontFace, P as fontFaceContentHash, R as STYLE_HANDLER_MAP, U as PropertyTypeResolver, Z as normalizeColorTokenValue, c as getGlobalKeyframes, ct as hashString, d as hasGlobalKeyframes, dt as hasLocalProperties, ft as parsePropertyToken, g as markStylesGenerated, gt as getColorSpaceSuffix, h as isTestEnvironment, ht as getColorSpaceFunc, j as formatCounterStyleRule, k as StyleInjector, lt as extractLocalProperties, mt as getColorSpaceComponents, n as getConfig, s as getGlobalInjector, st as isDevEnv } from "./config-5jzS6k6B.js";
2
+ import { a as mergeKeyframes, c as generateChunkCacheKey, d as categorizeStyleKeys, i as hasLocalKeyframes, l as CHUNK_NAMES, n as extractLocalKeyframes, o as replaceAnimationNames, r as filterUsedKeyframes, s as renderStylesForChunk, t as extractAnimationNamesFromStyles } from "./keyframes-b7X3UxDV.js";
3
+ import { n as formatPropertyCSS, r as getRegisteredSSRCollector, t as formatRules } from "./format-rules-DH13ewDu.js";
4
+ import { t as resolveRecipes } from "./resolve-recipes-Ca2-5CxM.js";
5
+ import { cache } from "react";
6
+ //#region src/styles/list.ts
7
+ const BASE_STYLES = [
8
+ "display",
9
+ "font",
10
+ "preset",
11
+ "hide",
12
+ "whiteSpace",
13
+ "opacity",
14
+ "transition"
15
+ ];
16
+ const POSITION_STYLES = [
17
+ "gridArea",
18
+ "order",
19
+ "gridColumn",
20
+ "gridRow",
21
+ "placeSelf",
22
+ "alignSelf",
23
+ "justifySelf",
24
+ "zIndex",
25
+ "margin",
26
+ "inset",
27
+ "position",
28
+ "scrollMargin"
29
+ ];
30
+ const BLOCK_INNER_STYLES = [
31
+ "padding",
32
+ "paddingInline",
33
+ "paddingBlock",
34
+ "overflow",
35
+ "scrollbar",
36
+ "textAlign"
37
+ ];
38
+ const BLOCK_OUTER_STYLES = [
39
+ "border",
40
+ "radius",
41
+ "shadow",
42
+ "outline"
43
+ ];
44
+ const BLOCK_STYLES = [...BLOCK_INNER_STYLES, ...BLOCK_OUTER_STYLES];
45
+ const COLOR_STYLES = [
46
+ "color",
47
+ "fill",
48
+ "fade",
49
+ "image"
50
+ ];
51
+ const TEXT_STYLES = [
52
+ "textTransform",
53
+ "fontWeight",
54
+ "fontStyle"
55
+ ];
56
+ const DIMENSION_STYLES = [
57
+ "width",
58
+ "height",
59
+ "flexBasis",
60
+ "flexGrow",
61
+ "flexShrink",
62
+ "flex"
63
+ ];
64
+ const FLOW_STYLES = [
65
+ "flow",
66
+ "place",
67
+ "placeItems",
68
+ "placeContent",
69
+ "alignItems",
70
+ "alignContent",
71
+ "justifyItems",
72
+ "justifyContent",
73
+ "align",
74
+ "justify",
75
+ "gap",
76
+ "columnGap",
77
+ "rowGap",
78
+ "gridColumns",
79
+ "gridRows",
80
+ "gridTemplate",
81
+ "gridAreas"
82
+ ];
83
+ const CONTAINER_STYLES = [
84
+ ...BASE_STYLES,
85
+ ...COLOR_STYLES,
86
+ ...DIMENSION_STYLES,
87
+ ...POSITION_STYLES,
88
+ ...BLOCK_STYLES,
89
+ ...FLOW_STYLES
90
+ ];
91
+ const OUTER_STYLES = [
92
+ ...POSITION_STYLES,
93
+ ...DIMENSION_STYLES,
94
+ ...BLOCK_OUTER_STYLES
95
+ ];
96
+ const INNER_STYLES = [
97
+ ...BASE_STYLES,
98
+ ...COLOR_STYLES,
99
+ ...BLOCK_INNER_STYLES,
100
+ ...FLOW_STYLES
101
+ ];
102
+ //#endregion
103
+ //#region src/injector/index.ts
104
+ /**
105
+ * Inject styles and return className with dispose function
106
+ */
107
+ function inject(rules, options) {
108
+ const injector = getGlobalInjector();
109
+ markStylesGenerated();
110
+ return injector.inject(rules, options);
111
+ }
112
+ /**
113
+ * Inject global rules that should not reserve tasty class names
114
+ */
115
+ function injectGlobal(rules, options) {
116
+ return getGlobalInjector().injectGlobal(rules, options);
117
+ }
118
+ /**
119
+ * Inject raw CSS text directly without parsing
120
+ * This is a low-overhead method for injecting raw CSS that doesn't need tasty processing.
121
+ * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking.
122
+ *
123
+ * @example
124
+ * ```tsx
125
+ * // Inject raw CSS
126
+ * const { dispose } = injectRawCSS(`
127
+ * body { margin: 0; padding: 0; }
128
+ * .my-class { color: red; }
129
+ * `);
130
+ *
131
+ * // Later, remove the injected CSS
132
+ * dispose();
133
+ * ```
134
+ */
135
+ function injectRawCSS(css, options) {
136
+ return getGlobalInjector().injectRawCSS(css, options);
137
+ }
138
+ /**
139
+ * Get raw CSS text for SSR
140
+ */
141
+ function getRawCSSText(options) {
142
+ return getGlobalInjector().getRawCSSText(options);
143
+ }
144
+ /**
145
+ * Inject keyframes and return object with toString() and dispose()
146
+ */
147
+ function keyframes(steps, nameOrOptions) {
148
+ return getGlobalInjector().keyframes(steps, nameOrOptions);
149
+ }
150
+ /**
151
+ * Define a CSS @property custom property.
152
+ * This enables advanced features like animating custom properties.
153
+ *
154
+ * Note: @property rules are global and persistent once defined.
155
+ * Re-registering the same property name is a no-op.
156
+ *
157
+ * @param name - The custom property name (must start with --)
158
+ * @param options - Property configuration
159
+ *
160
+ * @example
161
+ * ```ts
162
+ * // Define a color property that can be animated
163
+ * property('--my-color', {
164
+ * syntax: '<color>',
165
+ * initialValue: 'red',
166
+ * });
167
+ *
168
+ * // Define an angle property
169
+ * property('--rotation', {
170
+ * syntax: '<angle>',
171
+ * inherits: false,
172
+ * initialValue: '0deg',
173
+ * });
174
+ * ```
175
+ */
176
+ function property(name, options) {
177
+ return getGlobalInjector().property(name, options);
178
+ }
179
+ /**
180
+ * Check if a CSS @property has already been defined
181
+ *
182
+ * @param name - The custom property name to check
183
+ * @param options - Options including root
184
+ */
185
+ function isPropertyDefined(name, options) {
186
+ return getGlobalInjector().isPropertyDefined(name, options);
187
+ }
188
+ /**
189
+ * Inject a CSS @font-face rule.
190
+ *
191
+ * Permanent and global — no dispose or ref-counting.
192
+ * Deduplicates by content hash (family + descriptors).
193
+ */
194
+ function fontFace(family, descriptors, options) {
195
+ return getGlobalInjector().fontFace(family, descriptors, options);
196
+ }
197
+ /**
198
+ * Inject a CSS @counter-style rule.
199
+ *
200
+ * Permanent and global — no dispose or ref-counting.
201
+ * Deduplicates by name (first definition wins).
202
+ */
203
+ function counterStyle(name, descriptors, options) {
204
+ return getGlobalInjector().counterStyle(name, descriptors, options);
205
+ }
206
+ /**
207
+ * Get CSS text from all sheets (for SSR)
208
+ */
209
+ function getCssText(options) {
210
+ return getGlobalInjector().getCssText(options);
211
+ }
212
+ /**
213
+ * Collect only CSS used by a rendered subtree (like jest-styled-components).
214
+ * Pass the container returned by render(...).
215
+ */
216
+ function getCssTextForNode(node, options) {
217
+ const classSet = /* @__PURE__ */ new Set();
218
+ const readClasses = (el) => {
219
+ const cls = el.getAttribute("class");
220
+ if (!cls) return;
221
+ for (const token of cls.split(/\s+/)) if (/^t[a-z0-9]+$/.test(token)) classSet.add(token);
222
+ };
223
+ if (node.getAttribute) readClasses(node);
224
+ const elements = node.querySelectorAll ? node.querySelectorAll("[class]") : [];
225
+ if (elements) elements.forEach(readClasses);
226
+ return getGlobalInjector().getCssTextForClasses(classSet, options);
227
+ }
228
+ /**
229
+ * Force cleanup of unused rules
230
+ */
231
+ function cleanup(root) {
232
+ return getGlobalInjector().cleanup(root);
233
+ }
234
+ /**
235
+ * Record a render-time usage hit for one or more classNames.
236
+ * Used internally by computeStyles and tasty() to track usage for GC.
237
+ * When the global touch counter reaches `touchInterval`, schedules GC.
238
+ */
239
+ function touch(className, options) {
240
+ if (!getConfig().gc) return;
241
+ getGlobalInjector().touch(className, options);
242
+ }
243
+ /**
244
+ * Synchronous garbage collection of unused styles.
245
+ * Evicts the oldest unused styles when usageMap exceeds capacity.
246
+ * With `{ force: true }`, removes ALL unused styles regardless of capacity.
247
+ *
248
+ * @returns Number of styles evicted.
249
+ */
250
+ function gc(options) {
251
+ return getGlobalInjector().gc(options);
252
+ }
253
+ /**
254
+ * Check if we're currently running in a test environment
255
+ */
256
+ function getIsTestEnvironment() {
257
+ return isTestEnvironment();
258
+ }
259
+ /**
260
+ * Get the global injector instance for debugging
261
+ */
262
+ const injector = { get instance() {
263
+ return getGlobalInjector();
264
+ } };
265
+ /**
266
+ * Destroy all resources and clean up
267
+ */
268
+ function destroy(root) {
269
+ return getGlobalInjector().destroy(root);
270
+ }
271
+ /**
272
+ * Create a new isolated injector instance
273
+ */
274
+ function createInjector(config = {}) {
275
+ return new StyleInjector({
276
+ ...getConfig(),
277
+ forceTextInjection: config.forceTextInjection ?? isTestEnvironment(),
278
+ ...config
279
+ });
280
+ }
281
+ //#endregion
282
+ //#region src/rsc-cache.ts
283
+ /**
284
+ * Shared RSC (React Server Components) inline style cache.
285
+ *
286
+ * Uses React.cache for per-request memoization in Server Components.
287
+ * Both computeStyles() and standalone style functions (useGlobalStyles,
288
+ * useRawCSS, useKeyframes, useProperty, useFontFace, useCounterStyle)
289
+ * share this cache so that CSS accumulated by standalone functions is
290
+ * flushed into inline <style> tags by the next tasty() component.
291
+ */
292
+ /**
293
+ * Per-request RSC style cache using React.cache.
294
+ * React.cache provides per-request memoization in Server Components,
295
+ * so each request gets its own isolated cache.
296
+ */
297
+ const getRSCCache = cache(() => ({
298
+ cacheKeyToClassName: /* @__PURE__ */ new Map(),
299
+ emittedKeys: /* @__PURE__ */ new Set(),
300
+ internalsEmitted: false,
301
+ pendingCSS: [],
302
+ generatedNames: /* @__PURE__ */ new Map()
303
+ }));
304
+ function rscAllocateClassName(rscCache, cacheKey) {
305
+ const existing = rscCache.cacheKeyToClassName.get(cacheKey);
306
+ if (existing) return {
307
+ className: existing,
308
+ isNew: false
309
+ };
310
+ const className = `t${hashString(cacheKey)}`;
311
+ rscCache.cacheKeyToClassName.set(cacheKey, className);
312
+ return {
313
+ className,
314
+ isNew: true
315
+ };
316
+ }
317
+ /**
318
+ * Flush any pending CSS accumulated by standalone functions.
319
+ * Returns the CSS string and clears the buffer.
320
+ */
321
+ function flushPendingCSS(rscCache) {
322
+ if (rscCache.pendingCSS.length === 0) return "";
323
+ const css = rscCache.pendingCSS.join("\n");
324
+ rscCache.pendingCSS.length = 0;
325
+ return css;
326
+ }
327
+ /**
328
+ * Push CSS into the RSC pending buffer with dedup via emittedKeys.
329
+ * Returns true if the CSS was added, false if it was already emitted.
330
+ */
331
+ function pushRSCCSS(rscCache, key, css) {
332
+ if (rscCache.emittedKeys.has(key)) return false;
333
+ rscCache.emittedKeys.add(key);
334
+ rscCache.pendingCSS.push(css);
335
+ return true;
336
+ }
337
+ /**
338
+ * Determine the current style injection target.
339
+ * Centralizes the three-way detection (SSR collector / RSC cache / client DOM)
340
+ * used by all style functions.
341
+ */
342
+ function getStyleTarget() {
343
+ const collector = getRegisteredSSRCollector();
344
+ if (collector) return {
345
+ mode: "ssr",
346
+ collector
347
+ };
348
+ if (typeof document === "undefined") return {
349
+ mode: "rsc",
350
+ cache: getRSCCache()
351
+ };
352
+ return { mode: "client" };
353
+ }
354
+ //#endregion
355
+ //#region src/ssr/collect-auto-properties.ts
356
+ /**
357
+ * Scan rendered rules for auto-inferable custom properties and emit
358
+ * @property CSS via the provided callback.
359
+ */
360
+ function scanAndEmitAutoProperties(rules, styles, emit) {
361
+ const registered = /* @__PURE__ */ new Set();
362
+ if (styles) {
363
+ const localProps = styles["@properties"];
364
+ if (localProps && typeof localProps === "object") for (const token of Object.keys(localProps)) {
365
+ const parsed = parsePropertyToken(token);
366
+ if (parsed.isValid) registered.add(parsed.cssName);
367
+ }
368
+ }
369
+ const resolver = new PropertyTypeResolver();
370
+ for (const rule of rules) {
371
+ if (!rule.declarations) continue;
372
+ resolver.scanDeclarations(rule.declarations, (name) => registered.has(name), (name, syntax, initialValue) => {
373
+ registered.add(name);
374
+ const css = formatPropertyCSS(name, {
375
+ syntax,
376
+ inherits: true,
377
+ initialValue
378
+ });
379
+ if (css) emit(name, css);
380
+ });
381
+ }
382
+ }
383
+ /**
384
+ * Scan rendered rules for custom property declarations and collect
385
+ * auto-inferred @property rules via the SSR collector.
386
+ *
387
+ * @param rules - Rendered style rules containing CSS declarations
388
+ * @param collector - SSR collector to emit @property CSS into
389
+ * @param styles - Original styles object (used to skip explicit @properties)
390
+ */
391
+ function collectAutoInferredProperties(rules, collector, styles) {
392
+ scanAndEmitAutoProperties(rules, styles, (name, css) => {
393
+ collector.collectProperty(`__auto:${name}`, css);
394
+ });
395
+ }
396
+ /**
397
+ * RSC variant: scan rendered rules and push auto-inferred @property CSS
398
+ * into the RSC pending buffer.
399
+ */
400
+ function collectAutoInferredPropertiesRSC(rules, rscCache, styles) {
401
+ scanAndEmitAutoProperties(rules, styles, (name, css) => {
402
+ pushRSCCSS(rscCache, `__auto:${name}`, css);
403
+ });
404
+ }
405
+ //#endregion
406
+ //#region src/ssr/format-keyframes.ts
407
+ /**
408
+ * Convert keyframes steps to a CSS string.
409
+ * Replicates SheetManager.stepsToCSS() without the class instance.
410
+ */
411
+ function stepsToCSS(steps) {
412
+ const rules = [];
413
+ for (const [key, value] of Object.entries(steps)) {
414
+ if (typeof value === "string") {
415
+ rules.push(`${key} { ${value.trim()} }`);
416
+ continue;
417
+ }
418
+ const styleMap = value || {};
419
+ const styleNames = Object.keys(styleMap).sort();
420
+ const handlerQueue = [];
421
+ const seenHandlers = /* @__PURE__ */ new Set();
422
+ styleNames.forEach((styleName) => {
423
+ let handlers = STYLE_HANDLER_MAP[styleName];
424
+ if (!handlers) handlers = STYLE_HANDLER_MAP[styleName] = [createStyle(styleName)];
425
+ handlers.forEach((handler) => {
426
+ if (!seenHandlers.has(handler)) {
427
+ seenHandlers.add(handler);
428
+ handlerQueue.push(handler);
429
+ }
430
+ });
431
+ });
432
+ const declarationPairs = [];
433
+ handlerQueue.forEach((handler) => {
434
+ const result = handler(handler.__lookupStyles.reduce((acc, name) => {
435
+ const v = styleMap[name];
436
+ if (v !== void 0) acc[name] = v;
437
+ return acc;
438
+ }, {}));
439
+ if (!result) return;
440
+ (Array.isArray(result) ? result : [result]).forEach((cssMap) => {
441
+ if (!cssMap || typeof cssMap !== "object") return;
442
+ const { $: _$, ...props } = cssMap;
443
+ Object.entries(props).forEach(([prop, val]) => {
444
+ if (val == null || val === "") return;
445
+ if (Array.isArray(val)) val.forEach((v) => {
446
+ if (v != null && v !== "") declarationPairs.push({
447
+ prop,
448
+ value: String(v)
449
+ });
450
+ });
451
+ else declarationPairs.push({
452
+ prop,
453
+ value: String(val)
454
+ });
455
+ });
456
+ });
457
+ });
458
+ const declarations = declarationPairs.map((d) => `${d.prop}: ${d.value}`).join("; ");
459
+ rules.push(`${key} { ${declarations.trim()} }`);
460
+ }
461
+ return rules.join(" ");
462
+ }
463
+ /**
464
+ * Format a @keyframes rule as a CSS string.
465
+ */
466
+ function formatKeyframesCSS(name, steps) {
467
+ return `@keyframes ${name} { ${stepsToCSS(steps)} }`;
468
+ }
469
+ //#endregion
470
+ //#region src/utils/has-keys.ts
471
+ /**
472
+ * Check if an object has any own enumerable keys.
473
+ * Avoids the array allocation of Object.keys(obj).length > 0.
474
+ */
475
+ function hasKeys(obj) {
476
+ for (const _ in obj) return true;
477
+ return false;
478
+ }
479
+ //#endregion
480
+ //#region src/compute-styles.ts
481
+ /**
482
+ * Hook-free, synchronous style computation.
483
+ *
484
+ * Extracts the core logic from useStyles() into a plain function that can
485
+ * be called during React render without any hooks. Three code paths:
486
+ *
487
+ * 1. SSR collector — styles collected via ServerStyleCollector
488
+ * 2. Client inject — styles injected synchronously into the DOM
489
+ * 3. RSC inline — styles returned as CSS strings for inline <style> emission
490
+ *
491
+ * This enables tasty() components to work as React Server Components.
492
+ */
493
+ const EMPTY_RESULT = { className: "" };
494
+ /**
495
+ * Mark internals as emitted for this RSC request.
496
+ *
497
+ * Internals (tokens, @property, @font-face, @counter-style) are emitted
498
+ * exclusively by the SSR collector via ServerStyleCollector.collectInternals().
499
+ * The SSR path is reliable because TastyRegistry is always present as a
500
+ * client component in the root layout, guaranteeing SSR runs for every page.
501
+ *
502
+ * Previously this function also emitted internals and coordinated with SSR
503
+ * via a globalThis flag, but that flag leaked across requests in the same
504
+ * Node.js process, causing pages without RSC-rendered tasty components
505
+ * (e.g. the playground route) to lose all token CSS.
506
+ */
507
+ function collectInternalsRSC(rscCache) {
508
+ if (rscCache.internalsEmitted) return "";
509
+ rscCache.internalsEmitted = true;
510
+ return "";
511
+ }
512
+ /**
513
+ * Collect per-component ancillary CSS (keyframes, @property, font-face,
514
+ * counter-style) for RSC mode.
515
+ */
516
+ function collectAncillaryRSC(rscCache, styles) {
517
+ const parts = [];
518
+ const usedKf = getUsedKeyframes(styles);
519
+ if (usedKf) for (const [name, steps] of Object.entries(usedKf)) {
520
+ const key = `__kf:${name}:${JSON.stringify(steps)}`;
521
+ if (!rscCache.emittedKeys.has(key)) {
522
+ rscCache.emittedKeys.add(key);
523
+ parts.push(formatKeyframesCSS(name, steps));
524
+ }
525
+ }
526
+ if (hasLocalProperties(styles)) {
527
+ const localProperties = extractLocalProperties(styles);
528
+ if (localProperties) for (const [token, definition] of Object.entries(localProperties)) {
529
+ const key = `__prop:${token}`;
530
+ if (!rscCache.emittedKeys.has(key)) {
531
+ rscCache.emittedKeys.add(key);
532
+ const css = formatPropertyCSS(token, definition);
533
+ if (css) parts.push(css);
534
+ }
535
+ }
536
+ }
537
+ if (hasLocalFontFace(styles)) {
538
+ const localFontFace = extractLocalFontFace(styles);
539
+ if (localFontFace) for (const [family, input] of Object.entries(localFontFace)) {
540
+ const descriptors = Array.isArray(input) ? input : [input];
541
+ for (const desc of descriptors) {
542
+ const key = `__ff:${fontFaceContentHash(family, desc)}`;
543
+ if (!rscCache.emittedKeys.has(key)) {
544
+ rscCache.emittedKeys.add(key);
545
+ parts.push(formatFontFaceRule(family, desc));
546
+ }
547
+ }
548
+ }
549
+ }
550
+ if (hasLocalCounterStyle(styles)) {
551
+ const localCounterStyle = extractLocalCounterStyle(styles);
552
+ if (localCounterStyle) for (const [name, descriptors] of Object.entries(localCounterStyle)) {
553
+ const key = `__cs:${name}:${JSON.stringify(descriptors)}`;
554
+ if (!rscCache.emittedKeys.has(key)) {
555
+ rscCache.emittedKeys.add(key);
556
+ parts.push(formatCounterStyleRule(name, descriptors));
557
+ }
558
+ }
559
+ }
560
+ return parts.join("\n");
561
+ }
562
+ /**
563
+ * Process all chunks in RSC mode: render CSS to strings, allocate classNames,
564
+ * and return combined { className, css }.
565
+ */
566
+ function computeStylesRSC(styles, chunkMap) {
567
+ const rscCache = getRSCCache();
568
+ const cssParts = [];
569
+ const classNames = [];
570
+ const pendingCSS = flushPendingCSS(rscCache);
571
+ if (pendingCSS) cssParts.push(pendingCSS);
572
+ const internalsCSS = collectInternalsRSC(rscCache);
573
+ if (internalsCSS) cssParts.push(internalsCSS);
574
+ for (const [chunkName, chunkStyleKeys] of chunkMap) {
575
+ if (chunkStyleKeys.length === 0) continue;
576
+ const { className, isNew } = rscAllocateClassName(rscCache, generateChunkCacheKey(styles, chunkName, chunkStyleKeys));
577
+ classNames.push(className);
578
+ if (isNew) {
579
+ const renderResult = renderStylesForChunk(styles, chunkName, chunkStyleKeys);
580
+ if (renderResult.rules.length > 0) {
581
+ const css = formatRules(renderResult.rules, className);
582
+ if (css) cssParts.push(css);
583
+ }
584
+ }
585
+ }
586
+ const ancillaryCSS = collectAncillaryRSC(rscCache, styles);
587
+ if (ancillaryCSS) cssParts.push(ancillaryCSS);
588
+ if (classNames.length === 0) return EMPTY_RESULT;
589
+ const css = cssParts.join("\n");
590
+ return {
591
+ className: classNames.join(" "),
592
+ css: css || void 0
593
+ };
594
+ }
595
+ /**
596
+ * Get keyframes that are actually used in styles.
597
+ * Returns null if no keyframes are used (fast path for zero overhead).
598
+ */
599
+ function getUsedKeyframes(styles) {
600
+ const hasLocal = hasLocalKeyframes(styles);
601
+ const hasGlobal = hasGlobalKeyframes();
602
+ if (!hasLocal && !hasGlobal) return null;
603
+ const usedNames = extractAnimationNamesFromStyles(styles);
604
+ if (usedNames.size === 0) return null;
605
+ return filterUsedKeyframes(mergeKeyframes(hasLocal ? extractLocalKeyframes(styles) : null, hasGlobal ? getGlobalKeyframes() : null), usedNames);
606
+ }
607
+ /**
608
+ * Process a chunk on the SSR path: allocate via collector, render, collect CSS.
609
+ */
610
+ function processChunkSSR(collector, styles, chunkName, styleKeys) {
611
+ if (styleKeys.length === 0) return null;
612
+ const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);
613
+ const { className, isNewAllocation } = collector.allocateClassName(cacheKey);
614
+ if (isNewAllocation) {
615
+ const renderResult = renderStylesForChunk(styles, chunkName, styleKeys);
616
+ if (renderResult.rules.length > 0) {
617
+ collector.collectChunk(cacheKey, className, renderResult.rules);
618
+ return {
619
+ name: chunkName,
620
+ styleKeys,
621
+ cacheKey,
622
+ renderResult,
623
+ className
624
+ };
625
+ }
626
+ return null;
627
+ }
628
+ return {
629
+ name: chunkName,
630
+ styleKeys,
631
+ cacheKey,
632
+ renderResult: { rules: [] },
633
+ className
634
+ };
635
+ }
636
+ /**
637
+ * Process a chunk on the client: render, allocate className, and inject
638
+ * CSS synchronously. The injector's cache makes this idempotent.
639
+ */
640
+ function processChunkSync(styles, chunkName, styleKeys) {
641
+ if (styleKeys.length === 0) return null;
642
+ const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);
643
+ const renderResult = renderStylesForChunk(styles, chunkName, styleKeys, cacheKey);
644
+ if (renderResult.rules.length === 0) return null;
645
+ const { className } = inject(renderResult.rules, { cacheKey });
646
+ return {
647
+ name: chunkName,
648
+ styleKeys,
649
+ cacheKey,
650
+ renderResult,
651
+ className
652
+ };
653
+ }
654
+ /**
655
+ * Inject keyframes synchronously and return a name replacement map.
656
+ * On the client, keyframes are injected into the DOM.
657
+ */
658
+ function injectKeyframesSync(usedKeyframes) {
659
+ let nameMap = null;
660
+ for (const [name, steps] of Object.entries(usedKeyframes)) {
661
+ const injectedName = keyframes(steps, { name }).toString();
662
+ if (injectedName !== name) {
663
+ if (!nameMap) nameMap = /* @__PURE__ */ new Map();
664
+ nameMap.set(name, injectedName);
665
+ }
666
+ }
667
+ return nameMap;
668
+ }
669
+ /**
670
+ * Inject chunk rules synchronously, replacing animation names if needed.
671
+ */
672
+ function injectChunkRulesSync(chunks, nameMap) {
673
+ for (const chunk of chunks) if (chunk.renderResult.rules.length > 0) inject(nameMap ? chunk.renderResult.rules.map((rule) => ({
674
+ ...rule,
675
+ declarations: replaceAnimationNames(rule.declarations, nameMap)
676
+ })) : chunk.renderResult.rules, { cacheKey: chunk.cacheKey });
677
+ }
678
+ /**
679
+ * Inject all ancillary rules (properties, font-faces, counter-styles) synchronously.
680
+ */
681
+ function injectAncillarySync(styles) {
682
+ if (hasLocalProperties(styles)) {
683
+ const localProperties = extractLocalProperties(styles);
684
+ if (localProperties) for (const [token, definition] of Object.entries(localProperties)) property(token, definition);
685
+ }
686
+ if (hasLocalFontFace(styles)) {
687
+ const localFontFace = extractLocalFontFace(styles);
688
+ if (localFontFace) for (const [family, input] of Object.entries(localFontFace)) {
689
+ const descriptors = Array.isArray(input) ? input : [input];
690
+ for (const desc of descriptors) fontFace(family, desc);
691
+ }
692
+ }
693
+ if (hasLocalCounterStyle(styles)) {
694
+ const localCounterStyle = extractLocalCounterStyle(styles);
695
+ if (localCounterStyle) for (const [name, descriptors] of Object.entries(localCounterStyle)) counterStyle(name, descriptors);
696
+ }
697
+ }
698
+ /**
699
+ * Collect all ancillary rules into the SSR collector.
700
+ */
701
+ function collectAncillarySSR(collector, styles, chunks) {
702
+ const usedKf = getUsedKeyframes(styles);
703
+ if (usedKf) for (const [name, steps] of Object.entries(usedKf)) {
704
+ const css = formatKeyframesCSS(name, steps);
705
+ collector.collectKeyframes(name, css);
706
+ }
707
+ if (hasLocalProperties(styles)) {
708
+ const localProperties = extractLocalProperties(styles);
709
+ if (localProperties) for (const [token, definition] of Object.entries(localProperties)) {
710
+ const css = formatPropertyCSS(token, definition);
711
+ if (css) collector.collectProperty(token, css);
712
+ }
713
+ }
714
+ if (hasLocalFontFace(styles)) {
715
+ const localFontFace = extractLocalFontFace(styles);
716
+ if (localFontFace) for (const [family, input] of Object.entries(localFontFace)) {
717
+ const descriptors = Array.isArray(input) ? input : [input];
718
+ for (const desc of descriptors) {
719
+ const hash = fontFaceContentHash(family, desc);
720
+ const css = formatFontFaceRule(family, desc);
721
+ collector.collectFontFace(hash, css);
722
+ }
723
+ }
724
+ }
725
+ if (hasLocalCounterStyle(styles)) {
726
+ const localCounterStyle = extractLocalCounterStyle(styles);
727
+ if (localCounterStyle) for (const [name, descriptors] of Object.entries(localCounterStyle)) {
728
+ const css = formatCounterStyleRule(name, descriptors);
729
+ collector.collectCounterStyle(name, css);
730
+ }
731
+ }
732
+ if (getConfig().autoPropertyTypes !== false) {
733
+ const allRules = chunks.flatMap((c) => c.renderResult.rules);
734
+ if (allRules.length > 0) collectAutoInferredProperties(allRules, collector, styles);
735
+ }
736
+ }
737
+ /**
738
+ * Synchronous, hook-free style computation.
739
+ *
740
+ * Resolves recipes, categorizes style keys into chunks, renders CSS rules,
741
+ * allocates class names, and injects / collects / returns the CSS.
742
+ *
743
+ * Three code paths:
744
+ * 1. SSR collector — discovered via ALS or passed explicitly; CSS collected
745
+ * 2. RSC inline — no collector and no `document`; CSS returned as `result.css`
746
+ * for the caller to emit as an inline `<style>` tag
747
+ * 3. Client inject — CSS injected synchronously into the DOM (idempotent)
748
+ *
749
+ * @param styles - Tasty styles object (or undefined for no styles)
750
+ * @param options - Optional SSR collector override
751
+ */
752
+ function computeStyles(styles, options) {
753
+ if (!styles || !hasKeys(styles)) return EMPTY_RESULT;
754
+ const resolved = resolveRecipes(styles);
755
+ const chunkMap = categorizeStyleKeys(resolved);
756
+ const collector = options?.ssrCollector !== void 0 ? options.ssrCollector : getRegisteredSSRCollector();
757
+ const chunks = [];
758
+ if (collector) {
759
+ collector.collectInternals();
760
+ for (const [chunkName, chunkStyleKeys] of chunkMap) {
761
+ const chunk = processChunkSSR(collector, resolved, chunkName, chunkStyleKeys);
762
+ if (chunk) chunks.push(chunk);
763
+ }
764
+ collectAncillarySSR(collector, resolved, chunks);
765
+ } else if (typeof document === "undefined") return computeStylesRSC(resolved, chunkMap);
766
+ else {
767
+ injectAncillarySync(resolved);
768
+ const usedKf = getUsedKeyframes(resolved);
769
+ const nameMap = usedKf ? injectKeyframesSync(usedKf) : null;
770
+ for (const [chunkName, chunkStyleKeys] of chunkMap) {
771
+ const chunk = processChunkSync(resolved, chunkName, chunkStyleKeys);
772
+ if (chunk) chunks.push(chunk);
773
+ }
774
+ if (nameMap) injectChunkRulesSync(chunks, nameMap);
775
+ for (const chunk of chunks) touch(chunk.className);
776
+ }
777
+ if (chunks.length === 0) return EMPTY_RESULT;
778
+ if (chunks.length === 1) return { className: chunks[0].className };
779
+ return { className: chunks.map((c) => c.className).join(" ") };
780
+ }
781
+ //#endregion
782
+ //#region src/utils/filter-base-props.ts
783
+ const DOMPropNames = new Set(["id"]);
784
+ const BasePropNames = new Set([
785
+ "role",
786
+ "as",
787
+ "element",
788
+ "css",
789
+ "qa",
790
+ "mods",
791
+ "qaVal",
792
+ "hidden",
793
+ "isHidden",
794
+ "disabled",
795
+ "isDisabled",
796
+ "children",
797
+ "style",
798
+ "className",
799
+ "href",
800
+ "target",
801
+ "tabIndex"
802
+ ]);
803
+ const ignoreEventPropsNames = new Set([
804
+ "onPress",
805
+ "onHoverStart",
806
+ "onHoverEnd",
807
+ "onPressStart",
808
+ "onPressEnd"
809
+ ]);
810
+ const propRe = /^((data-).*)$/;
811
+ const eventRe = /^on[A-Z].+$/;
812
+ /**
813
+ * Filters out all props that aren't valid DOM props or defined via override prop obj.
814
+ * @param props - The component props to be filtered.
815
+ * @param opts - Props to override.
816
+ */
817
+ function filterBaseProps(props, opts = {}) {
818
+ const { propNames, eventProps } = opts;
819
+ const filteredProps = {};
820
+ for (const prop in props) if (Object.prototype.hasOwnProperty.call(props, prop) && (DOMPropNames.has(prop) || BasePropNames.has(prop) || prop.startsWith("aria-") || eventProps && eventRe.test(prop) && !ignoreEventPropsNames.has(prop) || propNames?.has(prop) || propRe.test(prop))) filteredProps[prop] = props[prop];
821
+ return filteredProps;
822
+ }
823
+ //#endregion
824
+ //#region src/utils/colors.ts
825
+ function color(name, opacity = 1) {
826
+ if (opacity !== 1) return `${getColorSpaceFunc()}(var(--${name}-color-${getColorSpaceSuffix()}) / ${opacity})`;
827
+ return `var(--${name}-color)`;
828
+ }
829
+ //#endregion
830
+ //#region src/utils/cache-wrapper.ts
831
+ /**
832
+ * Create a function that caches the result with LRU eviction.
833
+ */
834
+ function cacheWrapper(handler, limit = 1e3) {
835
+ const cache = new Lru(limit);
836
+ return (firstArg, secondArg) => {
837
+ const key = typeof firstArg === "string" && secondArg == null ? firstArg : JSON.stringify([firstArg, secondArg]);
838
+ let result = cache.get(key);
839
+ if (result === void 0) {
840
+ result = secondArg == null ? handler(firstArg) : handler(firstArg, secondArg);
841
+ cache.set(key, result);
842
+ }
843
+ return result;
844
+ };
845
+ }
846
+ //#endregion
847
+ //#region src/utils/mod-attrs.ts
848
+ function modAttrs(map) {
849
+ return map ? Object.keys(map).reduce((attrs, key) => {
850
+ const value = map[key];
851
+ if (value == null || value === false) return attrs;
852
+ const attrName = `data-${camelToKebab(key)}`;
853
+ if (value === true) attrs[attrName] = "";
854
+ else if (typeof value === "string") attrs[attrName] = value;
855
+ else if (typeof value === "number") attrs[attrName] = String(value);
856
+ else console.warn(`Tasty: Invalid mod value for "${key}". Expected boolean, string, or number, got ${typeof value}`);
857
+ return attrs;
858
+ }, {}) : null;
859
+ }
860
+ const _modAttrs = cacheWrapper(modAttrs);
861
+ //#endregion
862
+ //#region src/utils/dotize.ts
863
+ const dotize = {
864
+ valTypes: {
865
+ none: "NONE",
866
+ primitive: "PRIM",
867
+ object: "OBJECT",
868
+ array: "ARRAY"
869
+ },
870
+ getValType: function(val) {
871
+ if (!val || typeof val != "object" || Array.isArray(val)) return dotize.valTypes.primitive;
872
+ if (typeof val == "object") return dotize.valTypes.object;
873
+ },
874
+ getPathType: function(arrPath) {
875
+ const arrPathTypes = [];
876
+ for (const path in arrPath) {
877
+ const pathVal = arrPath[path];
878
+ if (!pathVal) arrPathTypes.push(dotize.valTypes.none);
879
+ else if (dotize.isNumber(pathVal)) arrPathTypes.push(dotize.valTypes.array);
880
+ else arrPathTypes.push(dotize.valTypes.object);
881
+ }
882
+ return arrPathTypes;
883
+ },
884
+ isUndefined: function(obj) {
885
+ return typeof obj == "undefined";
886
+ },
887
+ isNumber: function(f) {
888
+ return !isNaN(parseInt(f));
889
+ },
890
+ isEmptyObj: function(obj) {
891
+ for (const prop in obj) if (Object.hasOwnProperty.call(obj, prop)) return false;
892
+ return JSON.stringify(obj) === JSON.stringify({});
893
+ },
894
+ isPlainObject: function(obj) {
895
+ if (typeof obj !== "object" || obj === null) return false;
896
+ return Object.getPrototypeOf(obj) === Object.prototype;
897
+ },
898
+ isNotObject: function(obj) {
899
+ return !obj || !this.isPlainObject(obj);
900
+ },
901
+ isEmptyArray: function(arr) {
902
+ return Array.isArray(arr) && arr.length == 0;
903
+ },
904
+ isNotArray: function(arr) {
905
+ return Array.isArray(arr) == false;
906
+ },
907
+ removeEmptyArrayItem: function(arr) {
908
+ return arr.filter(function(el) {
909
+ return el != null && el != "";
910
+ });
911
+ },
912
+ getFieldName: function(field, prefix, isRoot, isArrayItem, isArray) {
913
+ if (isArray) return (prefix ? prefix : "") + (dotize.isNumber(field) ? "[" + field + "]" : (isRoot && !prefix ? "" : ".") + field);
914
+ else if (isArrayItem) return (prefix ? prefix : "") + "[" + field + "]";
915
+ else return (prefix ? prefix + "." : "") + field;
916
+ },
917
+ startsWith: function(val, valToSearch) {
918
+ return val.indexOf(valToSearch) == 0;
919
+ },
920
+ convert: function(obj, prefix = "") {
921
+ let newObj = {};
922
+ if (dotize.isNotObject(obj)) if (prefix) {
923
+ newObj[prefix] = obj;
924
+ return newObj;
925
+ } else return obj;
926
+ return (function recurse(o, p, isRoot) {
927
+ const isArrayItem = Array.isArray(o);
928
+ for (const f in o) {
929
+ const currentProp = o[f];
930
+ if (currentProp && typeof currentProp === "object" && !Array.isArray(currentProp) && dotize.isPlainObject(currentProp)) {
931
+ if (isArrayItem && dotize.isEmptyObj(currentProp) == false) newObj = recurse(currentProp, dotize.getFieldName(f, p, isRoot, true));
932
+ else if (dotize.isEmptyObj(currentProp) == false) newObj = recurse(currentProp, dotize.getFieldName(f, p, isRoot));
933
+ else if (dotize.isEmptyObj(currentProp)) newObj[dotize.getFieldName(f, p, isRoot, isArrayItem)] = currentProp;
934
+ } else if (isArrayItem || dotize.isNumber(f)) newObj[dotize.getFieldName(f, p, isRoot, true)] = currentProp;
935
+ else newObj[dotize.getFieldName(f, p, isRoot)] = currentProp;
936
+ }
937
+ return newObj;
938
+ })(obj, prefix, true);
939
+ },
940
+ backward: function(obj, prefix) {
941
+ let newObj = {};
942
+ const arStartRegex = /\[(\d+)\]/g;
943
+ if (dotize.isNotObject(obj) && dotize.isNotArray(obj)) if (prefix) return obj[prefix];
944
+ else return obj;
945
+ for (let tProp in obj) {
946
+ const tPropVal = obj[tProp];
947
+ if (prefix) {
948
+ const prefixRegex = new RegExp("^" + prefix);
949
+ tProp = tProp.replace(prefixRegex, "");
950
+ }
951
+ tProp = tProp.replace(arStartRegex, ".$1");
952
+ if (dotize.startsWith(tProp, ".")) tProp = tProp.replace(/^\./, "");
953
+ const arrPath = tProp.split(".");
954
+ const arrPathTypes = dotize.getPathType(arrPath);
955
+ if (!dotize.isUndefined(arrPathTypes) && arrPathTypes[0] == dotize.valTypes.array && Array.isArray(newObj) == false) newObj = [];
956
+ (function recurse(rPropVal, rObj, rPropValPrev, rObjPrev) {
957
+ let currentPath = arrPath.shift();
958
+ const currentPathType = arrPathTypes.shift();
959
+ if (typeof currentPath == "undefined" || currentPath == "") {
960
+ newObj = rPropVal;
961
+ return;
962
+ }
963
+ const isArray = currentPathType == dotize.valTypes.array;
964
+ if (dotize.isNumber(currentPath)) currentPath = parseInt(currentPath);
965
+ if (arrPath.length > 0) {
966
+ if (typeof rObj[currentPath] == "undefined") if (isArray) rObj[currentPath] = [];
967
+ else rObj[currentPath] = {};
968
+ recurse(rPropVal, rObj[currentPath], currentPath, rObj);
969
+ return;
970
+ }
971
+ if (currentPathType == dotize.valTypes.array && rPropValPrev && rObjPrev) {
972
+ if (Array.isArray(rObjPrev[rPropValPrev]) == false) rObjPrev[rPropValPrev] = [];
973
+ rObjPrev[rPropValPrev].push(rPropVal);
974
+ } else rObj[currentPath] = rPropVal;
975
+ })(tPropVal, newObj);
976
+ }
977
+ return newObj;
978
+ }
979
+ };
980
+ //#endregion
981
+ //#region src/utils/process-tokens.ts
982
+ /**
983
+ * Extract color components in the configured color space.
984
+ * Returns a CSS variable reference for token colors, or decomposed
985
+ * components as a space-separated string.
986
+ */
987
+ function extractColorSpaceValue(colorValue, parsedOutput) {
988
+ const suffix = getColorSpaceSuffix();
989
+ const varMatch = parsedOutput.match(/var\(--([a-z0-9-]+)-color\)/);
990
+ if (varMatch) return `var(--${varMatch[1]}-color-${suffix})`;
991
+ const components = getColorSpaceComponents(colorValue);
992
+ if (components !== colorValue) return components;
993
+ const componentsFromParsed = getColorSpaceComponents(parsedOutput);
994
+ if (componentsFromParsed !== parsedOutput) return componentsFromParsed;
995
+ return parsedOutput;
996
+ }
997
+ /**
998
+ * Check if a value is a valid token value (string, number, or boolean - not object).
999
+ * Returns false for `false` values (they mean "skip this token").
1000
+ */
1001
+ function isValidTokenValue(value) {
1002
+ if (value === void 0 || value === null || value === false) return false;
1003
+ if (typeof value === "object") {
1004
+ console.warn("Tasty: Object values are not allowed in tokens prop. Tokens do not support state-based styling. Use a primitive value instead.");
1005
+ return false;
1006
+ }
1007
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
1008
+ }
1009
+ /**
1010
+ * Process a single token value through the tasty parser.
1011
+ * Numbers are converted to strings; 0 stays as "0".
1012
+ */
1013
+ function processTokenValue(value) {
1014
+ if (typeof value === "number") {
1015
+ if (value === 0) return "0";
1016
+ return parseStyle(String(value)).output;
1017
+ }
1018
+ return parseStyle(value).output;
1019
+ }
1020
+ /**
1021
+ * Process tokens object into inline style properties.
1022
+ * - $name -> --name with parsed value
1023
+ * - #name -> --name-color AND --name-color-{colorSpace} with parsed values
1024
+ *
1025
+ * @param tokens - The tokens object to process
1026
+ * @returns CSSProperties object or undefined if no tokens to process
1027
+ */
1028
+ function processTokens(tokens) {
1029
+ if (!tokens) return;
1030
+ const keys = Object.keys(tokens);
1031
+ if (keys.length === 0) return;
1032
+ let result;
1033
+ for (const key of keys) {
1034
+ const value = tokens[key];
1035
+ if (!isValidTokenValue(value)) continue;
1036
+ if (key.startsWith("$")) {
1037
+ const propName = `--${key.slice(1)}`;
1038
+ const processedValue = processTokenValue(value === true ? "" : value);
1039
+ if (!result) result = {};
1040
+ result[propName] = processedValue;
1041
+ } else if (key.startsWith("#")) {
1042
+ const colorName = key.slice(1);
1043
+ const suffix = getColorSpaceSuffix();
1044
+ const effectiveValue = normalizeColorTokenValue(value);
1045
+ if (effectiveValue === null) continue;
1046
+ const originalValue = typeof effectiveValue === "number" ? String(effectiveValue) : effectiveValue;
1047
+ const lowerValue = originalValue.toLowerCase();
1048
+ const processedValue = processTokenValue(effectiveValue);
1049
+ if (!result) result = {};
1050
+ result[`--${colorName}-color`] = processedValue;
1051
+ if (/^#current(?:\.|$)/i.test(lowerValue)) continue;
1052
+ result[`--${colorName}-color-${suffix}`] = extractColorSpaceValue(originalValue, processedValue);
1053
+ }
1054
+ }
1055
+ return result;
1056
+ }
1057
+ //#endregion
1058
+ //#region src/debug.ts
1059
+ function fmtSize(bytes) {
1060
+ return bytes > 1024 ? `${(bytes / 1024).toFixed(1)}KB` : `${bytes}B`;
1061
+ }
1062
+ function countRules(css) {
1063
+ return (css.match(/\{[^}]*\}/g) || []).length;
1064
+ }
1065
+ function sortTastyClasses(classes) {
1066
+ return Array.from(classes).sort((a, b) => a.localeCompare(b));
1067
+ }
1068
+ function getRegistry(root = document) {
1069
+ return injector.instance._sheetManager?.getRegistry(root);
1070
+ }
1071
+ function getUnusedClasses(root = document) {
1072
+ const registry = getRegistry(root);
1073
+ if (!registry) return [];
1074
+ const result = [];
1075
+ for (const [cls, rc] of registry.refCounts) if (rc === 0) result.push(cls);
1076
+ return sortTastyClasses(result);
1077
+ }
1078
+ function findDomTastyClasses(root = document) {
1079
+ const classes = /* @__PURE__ */ new Set();
1080
+ (root.querySelectorAll?.("[class]") || []).forEach((el) => {
1081
+ const attr = el.getAttribute("class");
1082
+ if (attr) {
1083
+ for (const cls of attr.split(/\s+/)) if (/^t[a-z0-9]+$/.test(cls)) classes.add(cls);
1084
+ }
1085
+ });
1086
+ return sortTastyClasses(classes);
1087
+ }
1088
+ function prettifyCSS(css) {
1089
+ if (!css || !css.trim()) return "";
1090
+ const out = [];
1091
+ let depth = 0;
1092
+ const indent = () => " ".repeat(depth);
1093
+ let normalized = css.replace(/\s+/g, " ").trim();
1094
+ normalized = normalized.replace(/\s*\{\s*/g, " { ");
1095
+ normalized = normalized.replace(/\s*\}\s*/g, " } ");
1096
+ normalized = normalized.replace(/;\s*/g, "; ");
1097
+ const tokens = normalized.split(/\s+/);
1098
+ let buf = "";
1099
+ for (const t of tokens) if (t === "{") {
1100
+ const header = buf.trim();
1101
+ if (header) {
1102
+ const parts = splitOutsideParens(header, ",");
1103
+ if (parts.length > 1) out.push(parts.map((p, idx) => idx === 0 ? `${indent()}${p.trim()},` : `${indent()}${p.trim()}${idx < parts.length - 1 ? "," : ""}`).join("\n") + " {");
1104
+ else out.push(`${indent()}${header} {`);
1105
+ } else out.push(`${indent()}{`);
1106
+ depth++;
1107
+ buf = "";
1108
+ } else if (t === "}") {
1109
+ if (buf.trim()) {
1110
+ for (const decl of buf.split(";").filter((s) => s.trim())) out.push(`${indent()}${decl.trim()};`);
1111
+ buf = "";
1112
+ }
1113
+ depth = Math.max(0, depth - 1);
1114
+ out.push(`${indent()}}`);
1115
+ } else if (t.endsWith(";")) {
1116
+ buf += ` ${t}`;
1117
+ const full = buf.trim();
1118
+ if (full) out.push(`${indent()}${full}`);
1119
+ buf = "";
1120
+ } else buf += ` ${t}`;
1121
+ if (buf.trim()) out.push(buf.trim());
1122
+ return out.filter((l) => l.trim()).join("\n").replace(/\n{3,}/g, "\n\n").trim();
1123
+ }
1124
+ /** Split `str` by `sep` only when not inside parentheses */
1125
+ function splitOutsideParens(str, sep) {
1126
+ const parts = [];
1127
+ let depth = 0;
1128
+ let start = 0;
1129
+ for (let i = 0; i < str.length; i++) {
1130
+ const ch = str[i];
1131
+ if (ch === "(") depth++;
1132
+ else if (ch === ")") depth--;
1133
+ else if (depth === 0 && str.startsWith(sep, i)) {
1134
+ parts.push(str.slice(start, i));
1135
+ start = i + sep.length;
1136
+ }
1137
+ }
1138
+ parts.push(str.slice(start));
1139
+ return parts;
1140
+ }
1141
+ function extractChunkName(cacheKey) {
1142
+ for (const part of cacheKey.split("\0")) {
1143
+ if (part.startsWith("[states:")) continue;
1144
+ if (!part.includes(":") && part.length > 0) return part;
1145
+ }
1146
+ return null;
1147
+ }
1148
+ function getChunkForClass(className, root = document) {
1149
+ const registry = getRegistry(root);
1150
+ if (!registry) return null;
1151
+ for (const [key, cn] of registry.cacheKeyToClassName) if (cn === className) return extractChunkName(key);
1152
+ return null;
1153
+ }
1154
+ function buildChunkBreakdown(root = document) {
1155
+ const registry = getRegistry(root);
1156
+ if (!registry) return {
1157
+ byChunk: {},
1158
+ totalChunkTypes: 0,
1159
+ totalClasses: 0
1160
+ };
1161
+ const byChunk = {};
1162
+ for (const [cacheKey, className] of registry.cacheKeyToClassName) {
1163
+ const chunk = extractChunkName(cacheKey) || "unknown";
1164
+ if (!byChunk[chunk]) byChunk[chunk] = {
1165
+ classes: [],
1166
+ cssSize: 0,
1167
+ ruleCount: 0
1168
+ };
1169
+ byChunk[chunk].classes.push(className);
1170
+ const css = injector.instance.getCssTextForClasses([className], { root });
1171
+ byChunk[chunk].cssSize += css.length;
1172
+ byChunk[chunk].ruleCount += countRules(css);
1173
+ }
1174
+ for (const entry of Object.values(byChunk)) entry.classes = sortTastyClasses(entry.classes);
1175
+ const totalClasses = Object.values(byChunk).reduce((s, e) => s + e.classes.length, 0);
1176
+ return {
1177
+ byChunk,
1178
+ totalChunkTypes: Object.keys(byChunk).length,
1179
+ totalClasses
1180
+ };
1181
+ }
1182
+ function getGlobalTypeCSS(type, root = document) {
1183
+ const registry = getRegistry(root);
1184
+ if (!registry) return {
1185
+ css: "",
1186
+ ruleCount: 0,
1187
+ size: 0
1188
+ };
1189
+ const chunks = [];
1190
+ let rc = 0;
1191
+ if (type === "keyframes") for (const [, entry] of registry.keyframesCache) {
1192
+ const info = entry.info;
1193
+ const ss = registry.sheets[info.sheetIndex]?.sheet?.sheet;
1194
+ if (ss && info.ruleIndex < ss.cssRules.length) {
1195
+ const rule = ss.cssRules[info.ruleIndex];
1196
+ if (rule) {
1197
+ chunks.push(rule.cssText);
1198
+ rc++;
1199
+ }
1200
+ } else if (info.cssText) {
1201
+ chunks.push(info.cssText);
1202
+ rc++;
1203
+ }
1204
+ }
1205
+ else {
1206
+ const prefix = type === "global" ? "global:" : type === "raw" ? "raw:" : "property:";
1207
+ for (const [key, ri] of registry.globalRules) {
1208
+ if (!key.startsWith(prefix)) continue;
1209
+ const ss = registry.sheets[ri.sheetIndex]?.sheet?.sheet;
1210
+ if (ss) {
1211
+ const start = Math.max(0, ri.ruleIndex);
1212
+ const end = Math.min(ss.cssRules.length - 1, ri.endRuleIndex ?? ri.ruleIndex);
1213
+ if (start >= 0 && end >= start && start < ss.cssRules.length) for (let i = start; i <= end; i++) {
1214
+ const rule = ss.cssRules[i];
1215
+ if (rule) {
1216
+ chunks.push(rule.cssText);
1217
+ rc++;
1218
+ }
1219
+ }
1220
+ } else if (ri.cssText?.length) {
1221
+ chunks.push(...ri.cssText);
1222
+ rc += ri.cssText.length;
1223
+ }
1224
+ }
1225
+ }
1226
+ const raw = chunks.join("\n");
1227
+ return {
1228
+ css: prettifyCSS(raw),
1229
+ ruleCount: rc,
1230
+ size: raw.length
1231
+ };
1232
+ }
1233
+ function getSourceCssForClasses(classNames, root = document) {
1234
+ const registry = getRegistry(root);
1235
+ if (!registry) return null;
1236
+ const chunks = [];
1237
+ let found = false;
1238
+ for (const cls of classNames) {
1239
+ const info = registry.rules.get(cls);
1240
+ if (info?.cssText?.length) {
1241
+ chunks.push(...info.cssText);
1242
+ found = true;
1243
+ }
1244
+ }
1245
+ return found ? chunks.join("\n") : null;
1246
+ }
1247
+ function getDefs(root = document) {
1248
+ const registry = getRegistry(root);
1249
+ let properties = [];
1250
+ if (registry?.injectedProperties) properties = Array.from(registry.injectedProperties.keys()).sort();
1251
+ const keyframes = [];
1252
+ if (registry) {
1253
+ for (const entry of registry.keyframesCache.values()) keyframes.push({
1254
+ name: entry.name,
1255
+ refCount: entry.refCount
1256
+ });
1257
+ keyframes.sort((a, b) => a.name.localeCompare(b.name));
1258
+ }
1259
+ return {
1260
+ properties,
1261
+ keyframes
1262
+ };
1263
+ }
1264
+ const CHUNK_ORDER = [
1265
+ CHUNK_NAMES.COMBINED,
1266
+ CHUNK_NAMES.APPEARANCE,
1267
+ CHUNK_NAMES.FONT,
1268
+ CHUNK_NAMES.DIMENSION,
1269
+ CHUNK_NAMES.DISPLAY,
1270
+ CHUNK_NAMES.LAYOUT,
1271
+ CHUNK_NAMES.POSITION,
1272
+ CHUNK_NAMES.MISC,
1273
+ CHUNK_NAMES.SUBCOMPONENTS
1274
+ ];
1275
+ const tastyDebug = {
1276
+ css(target, opts) {
1277
+ const { root = document, prettify = true, raw = false, source = false } = opts || {};
1278
+ let css = "";
1279
+ if (source && typeof target === "string" && /^t[a-z0-9]+$/.test(target)) {
1280
+ const src = getSourceCssForClasses([target], root);
1281
+ if (src) css = src;
1282
+ else {
1283
+ if (!raw) console.warn("tastyDebug: source CSS not available (requires dev mode or TASTY_DEBUG=true). Falling back to live CSSOM.");
1284
+ css = injector.instance.getCssTextForClasses([target], { root });
1285
+ }
1286
+ } else if (source && Array.isArray(target)) {
1287
+ const src = getSourceCssForClasses(target, root);
1288
+ if (src) css = src;
1289
+ else {
1290
+ if (!raw) console.warn("tastyDebug: source CSS not available. Falling back to live CSSOM.");
1291
+ css = injector.instance.getCssTextForClasses(target, { root });
1292
+ }
1293
+ } else if (typeof target === "string") if (target === "all") css = injector.instance.getCssText({ root });
1294
+ else if (target === "global") {
1295
+ css = getGlobalTypeCSS("global", root).css;
1296
+ return css;
1297
+ } else if (target === "active") {
1298
+ const active = findDomTastyClasses(root);
1299
+ css = injector.instance.getCssTextForClasses(active, { root });
1300
+ } else if (target === "unused") {
1301
+ const unused = getUnusedClasses(root);
1302
+ css = injector.instance.getCssTextForClasses(unused, { root });
1303
+ } else if (target === "page") css = getPageCSS(root);
1304
+ else if (/^t[a-z0-9]+$/.test(target)) css = injector.instance.getCssTextForClasses([target], { root });
1305
+ else {
1306
+ const el = root.querySelector?.(target);
1307
+ if (el) css = getCssTextForNode(el, { root });
1308
+ }
1309
+ else if (Array.isArray(target)) css = injector.instance.getCssTextForClasses(target, { root });
1310
+ else if (target instanceof Element) css = getCssTextForNode(target, { root });
1311
+ const result = prettify ? prettifyCSS(css) : css;
1312
+ if (!raw) {
1313
+ const label = Array.isArray(target) ? `[${target.join(", ")}]` : target;
1314
+ const rc = countRules(css);
1315
+ console.group(`CSS for ${label} (${rc} rules, ${fmtSize(css.length)})`);
1316
+ console.log(result || "(empty)");
1317
+ console.groupEnd();
1318
+ }
1319
+ return result;
1320
+ },
1321
+ inspect(target, opts) {
1322
+ const { root = document, raw = false } = opts || {};
1323
+ const element = typeof target === "string" ? root.querySelector?.(target) : target;
1324
+ if (!element) {
1325
+ const empty = {
1326
+ element: null,
1327
+ classes: [],
1328
+ chunks: [],
1329
+ css: "",
1330
+ size: 0,
1331
+ rules: 0
1332
+ };
1333
+ if (!raw) console.warn("tastyDebug.inspect: element not found");
1334
+ return empty;
1335
+ }
1336
+ const tastyClasses = (element.getAttribute("class") || "").split(/\s+/).filter((cls) => /^t[a-z0-9]+$/.test(cls));
1337
+ const chunks = tastyClasses.map((className) => ({
1338
+ className,
1339
+ chunkName: getChunkForClass(className, root)
1340
+ }));
1341
+ const css = getCssTextForNode(element, { root });
1342
+ const rules = countRules(css);
1343
+ const result = {
1344
+ element,
1345
+ classes: tastyClasses,
1346
+ chunks,
1347
+ css: prettifyCSS(css),
1348
+ size: css.length,
1349
+ rules
1350
+ };
1351
+ if (!raw) {
1352
+ const tag = element.tagName.toLowerCase();
1353
+ const id = element.id ? `#${element.id}` : "";
1354
+ console.group(`inspect ${tag}${id} — ${tastyClasses.length} classes, ${rules} rules, ${fmtSize(css.length)}`);
1355
+ if (chunks.length) console.log("Chunks:", chunks.map((c) => `${c.className}→${c.chunkName || "?"}`).join(", "));
1356
+ console.groupCollapsed("CSS");
1357
+ console.log(result.css || "(empty)");
1358
+ console.groupEnd();
1359
+ console.groupEnd();
1360
+ }
1361
+ return result;
1362
+ },
1363
+ summary(opts) {
1364
+ const { root = document, raw = false } = opts || {};
1365
+ const activeClasses = findDomTastyClasses(root);
1366
+ const unusedClasses = getUnusedClasses(root);
1367
+ const totalStyledClasses = [...activeClasses, ...unusedClasses];
1368
+ const activeCSS = injector.instance.getCssTextForClasses(activeClasses, { root });
1369
+ const unusedCSS = injector.instance.getCssTextForClasses(unusedClasses, { root });
1370
+ const allCSS = injector.instance.getCssText({ root });
1371
+ const activeRuleCount = countRules(activeCSS);
1372
+ const unusedRuleCount = countRules(unusedCSS);
1373
+ const globalData = getGlobalTypeCSS("global", root);
1374
+ const rawData = getGlobalTypeCSS("raw", root);
1375
+ const kfData = getGlobalTypeCSS("keyframes", root);
1376
+ const propData = getGlobalTypeCSS("property", root);
1377
+ const totalRuleCount = activeRuleCount + unusedRuleCount + globalData.ruleCount + rawData.ruleCount + kfData.ruleCount + propData.ruleCount;
1378
+ const metrics = injector.instance.getMetrics({ root });
1379
+ const defs = getDefs(root);
1380
+ const chunkBreakdown = buildChunkBreakdown(root);
1381
+ const summary = {
1382
+ activeClasses,
1383
+ unusedClasses,
1384
+ totalStyledClasses,
1385
+ activeCSSSize: activeCSS.length,
1386
+ unusedCSSSize: unusedCSS.length,
1387
+ globalCSSSize: globalData.size,
1388
+ rawCSSSize: rawData.size,
1389
+ keyframesCSSSize: kfData.size,
1390
+ propertyCSSSize: propData.size,
1391
+ totalCSSSize: allCSS.length,
1392
+ activeRuleCount,
1393
+ unusedRuleCount,
1394
+ globalRuleCount: globalData.ruleCount,
1395
+ rawRuleCount: rawData.ruleCount,
1396
+ keyframesRuleCount: kfData.ruleCount,
1397
+ propertyRuleCount: propData.ruleCount,
1398
+ totalRuleCount,
1399
+ metrics,
1400
+ definedProperties: defs.properties,
1401
+ definedKeyframes: defs.keyframes,
1402
+ chunkBreakdown
1403
+ };
1404
+ if (!raw) {
1405
+ console.group("Tasty Summary");
1406
+ console.log(`Active: ${activeClasses.length} classes, ${activeRuleCount} rules, ${fmtSize(activeCSS.length)}`);
1407
+ console.log(`Unused: ${unusedClasses.length} classes, ${unusedRuleCount} rules, ${fmtSize(unusedCSS.length)}`);
1408
+ console.log(`Global: ${globalData.ruleCount} rules, ${fmtSize(globalData.size)}`);
1409
+ if (rawData.ruleCount) console.log(`Raw: ${rawData.ruleCount} rules, ${fmtSize(rawData.size)}`);
1410
+ if (kfData.ruleCount) console.log(`Keyframes: ${kfData.ruleCount} rules, ${fmtSize(kfData.size)}`);
1411
+ if (propData.ruleCount) console.log(`@property: ${propData.ruleCount} rules, ${fmtSize(propData.size)}`);
1412
+ console.log(`Total: ${totalStyledClasses.length} classes, ${totalRuleCount} rules, ${fmtSize(allCSS.length)}`);
1413
+ if (metrics) {
1414
+ const total = metrics.hits + metrics.misses;
1415
+ const rate = total > 0 ? (metrics.hits / total * 100).toFixed(1) : 0;
1416
+ console.log(`Cache: ${rate}% hit rate (${total} lookups)`);
1417
+ }
1418
+ if (chunkBreakdown.totalChunkTypes > 0) {
1419
+ console.groupCollapsed(`Chunks (${chunkBreakdown.totalChunkTypes} types, ${chunkBreakdown.totalClasses} classes)`);
1420
+ for (const name of CHUNK_ORDER) {
1421
+ const d = chunkBreakdown.byChunk[name];
1422
+ if (d) console.log(` ${name}: ${d.classes.length} cls, ${d.ruleCount} rules, ${fmtSize(d.cssSize)}`);
1423
+ }
1424
+ for (const [name, d] of Object.entries(chunkBreakdown.byChunk)) if (!CHUNK_ORDER.includes(name)) console.log(` ${name}: ${d.classes.length} cls, ${d.ruleCount} rules, ${fmtSize(d.cssSize)}`);
1425
+ console.groupEnd();
1426
+ }
1427
+ if (defs.properties.length || defs.keyframes.length) console.log(`Defs: ${defs.properties.length} @property, ${defs.keyframes.length} @keyframes`);
1428
+ console.groupEnd();
1429
+ }
1430
+ return summary;
1431
+ },
1432
+ chunks(opts) {
1433
+ const { root = document, raw = false } = opts || {};
1434
+ const breakdown = buildChunkBreakdown(root);
1435
+ if (!raw) {
1436
+ console.group(`Chunks (${breakdown.totalChunkTypes} types, ${breakdown.totalClasses} classes)`);
1437
+ for (const name of CHUNK_ORDER) {
1438
+ const d = breakdown.byChunk[name];
1439
+ if (d) console.log(` ${name}: ${d.classes.length} cls, ${d.ruleCount} rules, ${fmtSize(d.cssSize)}`);
1440
+ }
1441
+ for (const [name, d] of Object.entries(breakdown.byChunk)) if (!CHUNK_ORDER.includes(name)) console.log(` ${name}: ${d.classes.length} cls, ${d.ruleCount} rules, ${fmtSize(d.cssSize)}`);
1442
+ console.groupEnd();
1443
+ }
1444
+ return breakdown;
1445
+ },
1446
+ cache(opts) {
1447
+ const { root = document, raw = false } = opts || {};
1448
+ const active = findDomTastyClasses(root);
1449
+ const unused = getUnusedClasses(root);
1450
+ const metrics = injector.instance.getMetrics({ root });
1451
+ const status = {
1452
+ classes: {
1453
+ active,
1454
+ unused,
1455
+ all: [...active, ...unused]
1456
+ },
1457
+ metrics
1458
+ };
1459
+ if (!raw) {
1460
+ console.group("Cache");
1461
+ console.log(`Active: ${active.length}, Unused: ${unused.length}`);
1462
+ if (metrics) {
1463
+ const total = metrics.hits + metrics.misses;
1464
+ const rate = total > 0 ? (metrics.hits / total * 100).toFixed(1) : 0;
1465
+ console.log(`Hits: ${metrics.hits}, Misses: ${metrics.misses}, Rate: ${rate}%`);
1466
+ }
1467
+ console.groupEnd();
1468
+ }
1469
+ return status;
1470
+ },
1471
+ cleanup(opts) {
1472
+ injector.instance.cleanup(opts?.root);
1473
+ },
1474
+ help() {
1475
+ console.log(`tastyDebug API:
1476
+ .summary() — overview (classes, rules, sizes)
1477
+ .css("active") — CSS for classes in DOM
1478
+ .css("t42") — CSS for a specific class
1479
+ .css("t42",{source:1})— original CSS before browser parsing (dev only)
1480
+ .css(".selector") — CSS for a DOM element
1481
+ .inspect(".selector") — element details (classes, chunks, rules)
1482
+ .chunks() — style chunk breakdown
1483
+ .cache() — cache status and metrics
1484
+ .cleanup() — force unused style cleanup
1485
+ Options: { raw: true } suppresses logging, { root: shadowRoot } targets Shadow DOM`);
1486
+ },
1487
+ install() {
1488
+ if (typeof window !== "undefined" && window.tastyDebug !== tastyDebug) {
1489
+ window.tastyDebug = tastyDebug;
1490
+ console.log("tastyDebug installed. Run tastyDebug.help() for commands.");
1491
+ }
1492
+ }
1493
+ };
1494
+ function getPageCSS(root = document) {
1495
+ const chunks = [];
1496
+ try {
1497
+ if ("styleSheets" in root) for (const sheet of Array.from(root.styleSheets)) try {
1498
+ if (sheet.cssRules) chunks.push(Array.from(sheet.cssRules).map((r) => r.cssText).join("\n"));
1499
+ } catch {}
1500
+ } catch {}
1501
+ return chunks.join("\n");
1502
+ }
1503
+ if (typeof window !== "undefined" && isDevEnv()) tastyDebug.install();
1504
+ //#endregion
1505
+ export { property as A, INNER_STYLES as B, getRawCSSText as C, injector as D, injectRawCSS as E, BLOCK_STYLES as F, POSITION_STYLES as H, COLOR_STYLES as I, CONTAINER_STYLES as L, BASE_STYLES as M, BLOCK_INNER_STYLES as N, isPropertyDefined as O, BLOCK_OUTER_STYLES as P, DIMENSION_STYLES as R, getIsTestEnvironment as S, injectGlobal as T, TEXT_STYLES as U, OUTER_STYLES as V, destroy as _, color as a, getCssText as b, hasKeys as c, collectAutoInferredPropertiesRSC as d, getStyleTarget as f, createInjector as g, counterStyle as h, _modAttrs as i, touch as j, keyframes as k, formatKeyframesCSS as l, cleanup as m, processTokens as n, filterBaseProps as o, pushRSCCSS as p, dotize as r, computeStyles as s, tastyDebug as t, collectAutoInferredProperties as u, fontFace as v, inject as w, getCssTextForNode as x, gc as y, FLOW_STYLES as z };
1506
+
1507
+ //# sourceMappingURL=core-CtU6-9OC.js.map