@tenphi/tasty 0.0.0-snapshot.c8bdaeb → 0.0.0-snapshot.cae4fee

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