@tenphi/tasty 0.0.0-snapshot.b3fbcbb → 0.0.0-snapshot.b3fc70b

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