@tenphi/tasty 0.0.0-snapshot.fafcbfe → 0.0.0-snapshot.ffe00e9

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 (306) hide show
  1. package/README.md +315 -159
  2. package/dist/_virtual/_rolldown/runtime.js +1 -2
  3. package/dist/chunks/cacheKey.d.ts +1 -0
  4. package/dist/chunks/cacheKey.js +17 -10
  5. package/dist/chunks/cacheKey.js.map +1 -1
  6. package/dist/chunks/definitions.d.ts +1 -1
  7. package/dist/chunks/definitions.js +3 -5
  8. package/dist/chunks/definitions.js.map +1 -1
  9. package/dist/chunks/index.d.ts +1 -0
  10. package/dist/chunks/renderChunk.d.ts +1 -0
  11. package/dist/chunks/renderChunk.js +32 -34
  12. package/dist/chunks/renderChunk.js.map +1 -1
  13. package/dist/compute-styles.d.ts +31 -0
  14. package/dist/compute-styles.js +357 -0
  15. package/dist/compute-styles.js.map +1 -0
  16. package/dist/config.d.ts +116 -30
  17. package/dist/config.js +144 -45
  18. package/dist/config.js.map +1 -1
  19. package/dist/core/index.d.ts +12 -11
  20. package/dist/core/index.js +11 -10
  21. package/dist/counter-style/index.js +51 -0
  22. package/dist/counter-style/index.js.map +1 -0
  23. package/dist/debug.d.ts +26 -141
  24. package/dist/debug.js +357 -637
  25. package/dist/debug.js.map +1 -1
  26. package/dist/font-face/index.js +63 -0
  27. package/dist/font-face/index.js.map +1 -0
  28. package/dist/hooks/index.d.ts +7 -0
  29. package/dist/hooks/useCounterStyle.d.ts +50 -0
  30. package/dist/hooks/useCounterStyle.js +45 -0
  31. package/dist/hooks/useCounterStyle.js.map +1 -0
  32. package/dist/hooks/useFontFace.d.ts +43 -0
  33. package/dist/hooks/useFontFace.js +69 -0
  34. package/dist/hooks/useFontFace.js.map +1 -0
  35. package/dist/hooks/useGlobalStyles.d.ts +3 -0
  36. package/dist/hooks/useGlobalStyles.js +23 -2
  37. package/dist/hooks/useGlobalStyles.js.map +1 -1
  38. package/dist/hooks/useKeyframes.js +13 -4
  39. package/dist/hooks/useKeyframes.js.map +1 -1
  40. package/dist/hooks/useProperty.js +31 -14
  41. package/dist/hooks/useProperty.js.map +1 -1
  42. package/dist/hooks/useRawCSS.js +8 -2
  43. package/dist/hooks/useRawCSS.js.map +1 -1
  44. package/dist/hooks/useStyles.d.ts +4 -4
  45. package/dist/hooks/useStyles.js +7 -147
  46. package/dist/hooks/useStyles.js.map +1 -1
  47. package/dist/index.d.ts +23 -12
  48. package/dist/index.js +14 -11
  49. package/dist/injector/index.d.ts +41 -11
  50. package/dist/injector/index.js +48 -11
  51. package/dist/injector/index.js.map +1 -1
  52. package/dist/injector/injector.d.ts +58 -3
  53. package/dist/injector/injector.js +204 -41
  54. package/dist/injector/injector.js.map +1 -1
  55. package/dist/injector/sheet-manager.d.ts +18 -17
  56. package/dist/injector/sheet-manager.js +45 -73
  57. package/dist/injector/sheet-manager.js.map +1 -1
  58. package/dist/injector/types.d.ts +119 -19
  59. package/dist/keyframes/index.js +1 -1
  60. package/dist/parser/classify.js +6 -6
  61. package/dist/parser/classify.js.map +1 -1
  62. package/dist/parser/const.js +30 -3
  63. package/dist/parser/const.js.map +1 -1
  64. package/dist/parser/lru.js +1 -1
  65. package/dist/parser/lru.js.map +1 -1
  66. package/dist/parser/parser.js +2 -3
  67. package/dist/parser/parser.js.map +1 -1
  68. package/dist/parser/tokenizer.js +1 -1
  69. package/dist/parser/tokenizer.js.map +1 -1
  70. package/dist/parser/types.js +1 -1
  71. package/dist/parser/types.js.map +1 -1
  72. package/dist/pipeline/conditions.js +15 -9
  73. package/dist/pipeline/conditions.js.map +1 -1
  74. package/dist/pipeline/exclusive.js +1 -2
  75. package/dist/pipeline/exclusive.js.map +1 -1
  76. package/dist/pipeline/index.d.ts +3 -1
  77. package/dist/pipeline/index.js +139 -72
  78. package/dist/pipeline/index.js.map +1 -1
  79. package/dist/pipeline/materialize.js +405 -210
  80. package/dist/pipeline/materialize.js.map +1 -1
  81. package/dist/pipeline/parseStateKey.d.ts +1 -1
  82. package/dist/pipeline/parseStateKey.js +38 -22
  83. package/dist/pipeline/parseStateKey.js.map +1 -1
  84. package/dist/pipeline/simplify.js +112 -154
  85. package/dist/pipeline/simplify.js.map +1 -1
  86. package/dist/pipeline/warnings.js +18 -0
  87. package/dist/pipeline/warnings.js.map +1 -0
  88. package/dist/plugins/index.d.ts +2 -0
  89. package/dist/plugins/okhsl-plugin.js +3 -277
  90. package/dist/plugins/okhsl-plugin.js.map +1 -1
  91. package/dist/plugins/types.d.ts +9 -2
  92. package/dist/properties/index.js +83 -19
  93. package/dist/properties/index.js.map +1 -1
  94. package/dist/properties/property-type-resolver.d.ts +24 -0
  95. package/dist/properties/property-type-resolver.js +90 -0
  96. package/dist/properties/property-type-resolver.js.map +1 -0
  97. package/dist/ssr/astro.d.ts +29 -0
  98. package/dist/ssr/astro.js +64 -0
  99. package/dist/ssr/astro.js.map +1 -0
  100. package/dist/ssr/async-storage.d.ts +17 -0
  101. package/dist/ssr/async-storage.js +34 -0
  102. package/dist/ssr/async-storage.js.map +1 -0
  103. package/dist/ssr/collect-auto-properties.js +39 -0
  104. package/dist/ssr/collect-auto-properties.js.map +1 -0
  105. package/dist/ssr/collector.d.ts +102 -0
  106. package/dist/ssr/collector.js +219 -0
  107. package/dist/ssr/collector.js.map +1 -0
  108. package/dist/ssr/format-global-rules.js +22 -0
  109. package/dist/ssr/format-global-rules.js.map +1 -0
  110. package/dist/ssr/format-keyframes.js +69 -0
  111. package/dist/ssr/format-keyframes.js.map +1 -0
  112. package/dist/ssr/format-property.js +49 -0
  113. package/dist/ssr/format-property.js.map +1 -0
  114. package/dist/ssr/format-rules.js +73 -0
  115. package/dist/ssr/format-rules.js.map +1 -0
  116. package/dist/ssr/hydrate.d.ts +22 -0
  117. package/dist/ssr/hydrate.js +49 -0
  118. package/dist/ssr/hydrate.js.map +1 -0
  119. package/dist/ssr/index.d.ts +4 -0
  120. package/dist/ssr/index.js +10 -0
  121. package/dist/ssr/index.js.map +1 -0
  122. package/dist/ssr/next.d.ts +43 -0
  123. package/dist/ssr/next.js +74 -0
  124. package/dist/ssr/next.js.map +1 -0
  125. package/dist/ssr/ssr-collector-ref.js +12 -0
  126. package/dist/ssr/ssr-collector-ref.js.map +1 -0
  127. package/dist/states/index.js +13 -259
  128. package/dist/states/index.js.map +1 -1
  129. package/dist/static/index.js +1 -2
  130. package/dist/static/inject.d.ts +5 -0
  131. package/dist/static/inject.js +17 -0
  132. package/dist/static/inject.js.map +1 -0
  133. package/dist/static/tastyStatic.js +1 -2
  134. package/dist/static/tastyStatic.js.map +1 -1
  135. package/dist/static/types.js +1 -1
  136. package/dist/styles/border.d.ts +2 -2
  137. package/dist/styles/border.js +30 -24
  138. package/dist/styles/border.js.map +1 -1
  139. package/dist/styles/color.d.ts +3 -3
  140. package/dist/styles/color.js +11 -8
  141. package/dist/styles/color.js.map +1 -1
  142. package/dist/styles/const.js +17 -0
  143. package/dist/styles/const.js.map +1 -0
  144. package/dist/styles/createStyle.js +29 -27
  145. package/dist/styles/createStyle.js.map +1 -1
  146. package/dist/styles/dimension.js +15 -3
  147. package/dist/styles/dimension.js.map +1 -1
  148. package/dist/styles/directional.js +133 -0
  149. package/dist/styles/directional.js.map +1 -0
  150. package/dist/styles/display.d.ts +3 -10
  151. package/dist/styles/display.js +45 -39
  152. package/dist/styles/display.js.map +1 -1
  153. package/dist/styles/fade.d.ts +2 -2
  154. package/dist/styles/fade.js +9 -5
  155. package/dist/styles/fade.js.map +1 -1
  156. package/dist/styles/fill.d.ts +15 -17
  157. package/dist/styles/fill.js +9 -9
  158. package/dist/styles/fill.js.map +1 -1
  159. package/dist/styles/flow.d.ts +3 -3
  160. package/dist/styles/flow.js +1 -1
  161. package/dist/styles/flow.js.map +1 -1
  162. package/dist/styles/gap.d.ts +1 -1
  163. package/dist/styles/gap.js +4 -3
  164. package/dist/styles/gap.js.map +1 -1
  165. package/dist/styles/height.d.ts +1 -1
  166. package/dist/styles/height.js +1 -2
  167. package/dist/styles/height.js.map +1 -1
  168. package/dist/styles/index.d.ts +0 -1
  169. package/dist/styles/index.js +3 -4
  170. package/dist/styles/index.js.map +1 -1
  171. package/dist/styles/inset.d.ts +1 -29
  172. package/dist/styles/inset.js +19 -135
  173. package/dist/styles/inset.js.map +1 -1
  174. package/dist/styles/list.d.ts +5 -5
  175. package/dist/styles/list.js +4 -2
  176. package/dist/styles/list.js.map +1 -1
  177. package/dist/styles/margin.d.ts +1 -1
  178. package/dist/styles/margin.js +17 -89
  179. package/dist/styles/margin.js.map +1 -1
  180. package/dist/styles/outline.d.ts +1 -1
  181. package/dist/styles/outline.js +6 -16
  182. package/dist/styles/outline.js.map +1 -1
  183. package/dist/styles/padding.d.ts +1 -1
  184. package/dist/styles/padding.js +17 -89
  185. package/dist/styles/padding.js.map +1 -1
  186. package/dist/styles/placement.d.ts +37 -0
  187. package/dist/styles/placement.js +74 -0
  188. package/dist/styles/placement.js.map +1 -0
  189. package/dist/styles/predefined.d.ts +4 -6
  190. package/dist/styles/predefined.js +9 -13
  191. package/dist/styles/predefined.js.map +1 -1
  192. package/dist/styles/preset.d.ts +6 -1
  193. package/dist/styles/preset.js +54 -53
  194. package/dist/styles/preset.js.map +1 -1
  195. package/dist/styles/radius.d.ts +2 -4
  196. package/dist/styles/radius.js +38 -6
  197. package/dist/styles/radius.js.map +1 -1
  198. package/dist/styles/scrollMargin.d.ts +24 -0
  199. package/dist/styles/scrollMargin.js +32 -0
  200. package/dist/styles/scrollMargin.js.map +1 -0
  201. package/dist/styles/scrollbar.d.ts +9 -5
  202. package/dist/styles/scrollbar.js +31 -85
  203. package/dist/styles/scrollbar.js.map +1 -1
  204. package/dist/styles/shadow.d.ts +3 -3
  205. package/dist/styles/shadow.js +4 -3
  206. package/dist/styles/shadow.js.map +1 -1
  207. package/dist/styles/shared.js +17 -0
  208. package/dist/styles/shared.js.map +1 -0
  209. package/dist/styles/transition.d.ts +2 -2
  210. package/dist/styles/transition.js +6 -5
  211. package/dist/styles/transition.js.map +1 -1
  212. package/dist/styles/types.d.ts +94 -28
  213. package/dist/styles/width.d.ts +1 -1
  214. package/dist/styles/width.js +1 -2
  215. package/dist/styles/width.js.map +1 -1
  216. package/dist/tasty.d.ts +46 -894
  217. package/dist/tasty.js +112 -60
  218. package/dist/tasty.js.map +1 -1
  219. package/dist/types.d.ts +3 -3
  220. package/dist/utils/cache-wrapper.js +4 -9
  221. package/dist/utils/cache-wrapper.js.map +1 -1
  222. package/dist/utils/case-converter.js +1 -1
  223. package/dist/utils/color-math.d.ts +46 -0
  224. package/dist/utils/color-math.js +749 -0
  225. package/dist/utils/color-math.js.map +1 -0
  226. package/dist/utils/color-space.d.ts +5 -0
  227. package/dist/utils/color-space.js +228 -0
  228. package/dist/utils/color-space.js.map +1 -0
  229. package/dist/utils/colors.d.ts +1 -1
  230. package/dist/utils/colors.js +3 -2
  231. package/dist/utils/colors.js.map +1 -1
  232. package/dist/utils/css-types.d.ts +1 -1
  233. package/dist/utils/dotize.d.ts +1 -1
  234. package/dist/utils/dotize.js +1 -1
  235. package/dist/utils/dotize.js.map +1 -1
  236. package/dist/utils/filter-base-props.js +1 -1
  237. package/dist/utils/get-display-name.js +1 -1
  238. package/dist/utils/has-keys.js +13 -0
  239. package/dist/utils/has-keys.js.map +1 -0
  240. package/dist/utils/is-dev-env.js +1 -1
  241. package/dist/utils/is-dev-env.js.map +1 -1
  242. package/dist/utils/is-valid-element-type.js +1 -1
  243. package/dist/utils/merge-styles.js +1 -2
  244. package/dist/utils/merge-styles.js.map +1 -1
  245. package/dist/utils/mod-attrs.d.ts +0 -2
  246. package/dist/utils/mod-attrs.js +3 -4
  247. package/dist/utils/mod-attrs.js.map +1 -1
  248. package/dist/utils/process-tokens.d.ts +3 -17
  249. package/dist/utils/process-tokens.js +19 -107
  250. package/dist/utils/process-tokens.js.map +1 -1
  251. package/dist/utils/resolve-recipes.js +1 -2
  252. package/dist/utils/resolve-recipes.js.map +1 -1
  253. package/dist/utils/selector-transform.js +32 -0
  254. package/dist/utils/selector-transform.js.map +1 -0
  255. package/dist/utils/string.js +1 -1
  256. package/dist/utils/string.js.map +1 -1
  257. package/dist/utils/styles.d.ts +5 -89
  258. package/dist/utils/styles.js +35 -400
  259. package/dist/utils/styles.js.map +1 -1
  260. package/dist/utils/typography.d.ts +24 -13
  261. package/dist/utils/typography.js +15 -17
  262. package/dist/utils/typography.js.map +1 -1
  263. package/dist/utils/warnings.js +1 -1
  264. package/dist/zero/babel.d.ts +84 -10
  265. package/dist/zero/babel.js +193 -37
  266. package/dist/zero/babel.js.map +1 -1
  267. package/dist/zero/css-writer.js +1 -2
  268. package/dist/zero/css-writer.js.map +1 -1
  269. package/dist/zero/extractor.js +119 -3
  270. package/dist/zero/extractor.js.map +1 -1
  271. package/dist/zero/index.js +1 -2
  272. package/dist/zero/next.d.ts +56 -30
  273. package/dist/zero/next.js +105 -40
  274. package/dist/zero/next.js.map +1 -1
  275. package/docs/PIPELINE.md +519 -0
  276. package/docs/README.md +31 -0
  277. package/docs/adoption.md +296 -0
  278. package/docs/comparison.md +420 -0
  279. package/docs/configuration.md +326 -0
  280. package/docs/debug.md +318 -0
  281. package/docs/design-system.md +424 -0
  282. package/docs/dsl.md +673 -0
  283. package/docs/getting-started.md +217 -0
  284. package/docs/injector.md +543 -0
  285. package/docs/methodology.md +616 -0
  286. package/docs/runtime.md +572 -0
  287. package/docs/ssr.md +354 -0
  288. package/docs/styles.md +596 -0
  289. package/docs/tasty-static.md +520 -0
  290. package/package.json +106 -31
  291. package/dist/styles/align.d.ts +0 -15
  292. package/dist/styles/align.js +0 -14
  293. package/dist/styles/align.js.map +0 -1
  294. package/dist/styles/justify.d.ts +0 -15
  295. package/dist/styles/justify.js +0 -14
  296. package/dist/styles/justify.js.map +0 -1
  297. package/dist/styles/styledScrollbar.d.ts +0 -47
  298. package/dist/styles/styledScrollbar.js +0 -38
  299. package/dist/styles/styledScrollbar.js.map +0 -1
  300. package/dist/tokens/typography.d.ts +0 -19
  301. package/dist/tokens/typography.js +0 -237
  302. package/dist/tokens/typography.js.map +0 -1
  303. package/dist/utils/hsl-to-rgb.js +0 -38
  304. package/dist/utils/hsl-to-rgb.js.map +0 -1
  305. package/dist/utils/okhsl-to-rgb.js +0 -296
  306. package/dist/utils/okhsl-to-rgb.js.map +0 -1
@@ -0,0 +1,357 @@
1
+ import { extractLocalProperties, hasLocalProperties } from "./properties/index.js";
2
+ import { extractLocalFontFace, fontFaceContentHash, formatFontFaceRule, hasLocalFontFace } from "./font-face/index.js";
3
+ import { extractLocalCounterStyle, formatCounterStyleRule, hasLocalCounterStyle } from "./counter-style/index.js";
4
+ import { renderStyles } from "./pipeline/index.js";
5
+ import { getConfig, getEffectiveProperties, getGlobalConfigTokens, getGlobalCounterStyle, getGlobalFontFace, getGlobalKeyframes, hasGlobalKeyframes } from "./config.js";
6
+ import { categorizeStyleKeys } from "./chunks/definitions.js";
7
+ import { generateChunkCacheKey } from "./chunks/cacheKey.js";
8
+ import { renderStylesForChunk } from "./chunks/renderChunk.js";
9
+ import { counterStyle, fontFace, inject, keyframes, property, touch } from "./injector/index.js";
10
+ import { extractAnimationNamesFromStyles, extractLocalKeyframes, filterUsedKeyframes, hasLocalKeyframes, mergeKeyframes, replaceAnimationNames } from "./keyframes/index.js";
11
+ import { formatPropertyCSS } from "./ssr/format-property.js";
12
+ import { collectAutoInferredProperties } from "./ssr/collect-auto-properties.js";
13
+ import { formatGlobalRules } from "./ssr/format-global-rules.js";
14
+ import { formatKeyframesCSS } from "./ssr/format-keyframes.js";
15
+ import { formatRules } from "./ssr/format-rules.js";
16
+ import { getRegisteredSSRCollector } from "./ssr/ssr-collector-ref.js";
17
+ import { hasKeys } from "./utils/has-keys.js";
18
+ import { resolveRecipes } from "./utils/resolve-recipes.js";
19
+ import { cache } from "react";
20
+ //#region src/compute-styles.ts
21
+ /**
22
+ * Hook-free, synchronous style computation.
23
+ *
24
+ * Extracts the core logic from useStyles() into a plain function that can
25
+ * be called during React render without any hooks. Three code paths:
26
+ *
27
+ * 1. SSR collector — styles collected via ServerStyleCollector
28
+ * 2. Client inject — styles injected synchronously into the DOM
29
+ * 3. RSC inline — styles returned as CSS strings for inline <style> emission
30
+ *
31
+ * This enables tasty() components to work as React Server Components.
32
+ */
33
+ const EMPTY_RESULT = { className: "" };
34
+ /**
35
+ * Per-request RSC style cache using React.cache.
36
+ * React.cache provides per-request memoization in Server Components,
37
+ * so each request gets its own isolated cache.
38
+ */
39
+ const getRSCCache = cache(() => ({
40
+ cacheKeyToClassName: /* @__PURE__ */ new Map(),
41
+ classCounter: 0,
42
+ emittedKeys: /* @__PURE__ */ new Set(),
43
+ internalsEmitted: false
44
+ }));
45
+ function rscAllocateClassName(rscCache, cacheKey) {
46
+ const existing = rscCache.cacheKeyToClassName.get(cacheKey);
47
+ if (existing) return {
48
+ className: existing,
49
+ isNew: false
50
+ };
51
+ const className = `r${rscCache.classCounter++}`;
52
+ rscCache.cacheKeyToClassName.set(cacheKey, className);
53
+ return {
54
+ className,
55
+ isNew: true
56
+ };
57
+ }
58
+ /**
59
+ * Collect internals CSS for RSC — mirrors ServerStyleCollector.collectInternals().
60
+ * Emitted once per request (tracked via rscCache.internalsEmitted).
61
+ */
62
+ function collectInternalsRSC(rscCache) {
63
+ if (rscCache.internalsEmitted) return "";
64
+ rscCache.internalsEmitted = true;
65
+ const parts = [];
66
+ for (const [token, definition] of Object.entries(getEffectiveProperties())) {
67
+ const css = formatPropertyCSS(token, definition);
68
+ if (css) parts.push(css);
69
+ }
70
+ const tokenStyles = getGlobalConfigTokens();
71
+ if (tokenStyles && Object.keys(tokenStyles).length > 0) {
72
+ const tokenRules = renderStyles(tokenStyles, ":root");
73
+ if (tokenRules.length > 0) {
74
+ const css = formatGlobalRules(tokenRules);
75
+ if (css) parts.push(css);
76
+ }
77
+ }
78
+ const globalFF = getGlobalFontFace();
79
+ if (globalFF) for (const [family, input] of Object.entries(globalFF)) {
80
+ const descriptors = Array.isArray(input) ? input : [input];
81
+ for (const desc of descriptors) parts.push(formatFontFaceRule(family, desc));
82
+ }
83
+ const globalCS = getGlobalCounterStyle();
84
+ if (globalCS) for (const [name, descriptors] of Object.entries(globalCS)) parts.push(formatCounterStyleRule(name, descriptors));
85
+ return parts.join("\n");
86
+ }
87
+ /**
88
+ * Collect per-component ancillary CSS (keyframes, @property, font-face,
89
+ * counter-style) for RSC mode.
90
+ */
91
+ function collectAncillaryRSC(rscCache, styles) {
92
+ const parts = [];
93
+ const usedKf = getUsedKeyframes(styles);
94
+ if (usedKf) for (const [name, steps] of Object.entries(usedKf)) {
95
+ const key = `__kf:${name}`;
96
+ if (!rscCache.emittedKeys.has(key)) {
97
+ rscCache.emittedKeys.add(key);
98
+ parts.push(formatKeyframesCSS(name, steps));
99
+ }
100
+ }
101
+ if (hasLocalProperties(styles)) {
102
+ const localProperties = extractLocalProperties(styles);
103
+ if (localProperties) for (const [token, definition] of Object.entries(localProperties)) {
104
+ const key = `__prop:${token}`;
105
+ if (!rscCache.emittedKeys.has(key)) {
106
+ rscCache.emittedKeys.add(key);
107
+ const css = formatPropertyCSS(token, definition);
108
+ if (css) parts.push(css);
109
+ }
110
+ }
111
+ }
112
+ if (hasLocalFontFace(styles)) {
113
+ const localFontFace = extractLocalFontFace(styles);
114
+ if (localFontFace) for (const [family, input] of Object.entries(localFontFace)) {
115
+ const descriptors = Array.isArray(input) ? input : [input];
116
+ for (const desc of descriptors) {
117
+ const key = `__ff:${fontFaceContentHash(family, desc)}`;
118
+ if (!rscCache.emittedKeys.has(key)) {
119
+ rscCache.emittedKeys.add(key);
120
+ parts.push(formatFontFaceRule(family, desc));
121
+ }
122
+ }
123
+ }
124
+ }
125
+ if (hasLocalCounterStyle(styles)) {
126
+ const localCounterStyle = extractLocalCounterStyle(styles);
127
+ if (localCounterStyle) for (const [name, descriptors] of Object.entries(localCounterStyle)) {
128
+ const key = `__cs:${name}`;
129
+ if (!rscCache.emittedKeys.has(key)) {
130
+ rscCache.emittedKeys.add(key);
131
+ parts.push(formatCounterStyleRule(name, descriptors));
132
+ }
133
+ }
134
+ }
135
+ return parts.join("\n");
136
+ }
137
+ /**
138
+ * Process all chunks in RSC mode: render CSS to strings, allocate classNames,
139
+ * and return combined { className, css }.
140
+ */
141
+ function computeStylesRSC(styles, chunkMap) {
142
+ const rscCache = getRSCCache();
143
+ const cssParts = [];
144
+ const classNames = [];
145
+ const internalsCSS = collectInternalsRSC(rscCache);
146
+ if (internalsCSS) cssParts.push(internalsCSS);
147
+ for (const [chunkName, chunkStyleKeys] of chunkMap) {
148
+ if (chunkStyleKeys.length === 0) continue;
149
+ const { className, isNew } = rscAllocateClassName(rscCache, generateChunkCacheKey(styles, chunkName, chunkStyleKeys));
150
+ classNames.push(className);
151
+ if (isNew) {
152
+ const renderResult = renderStylesForChunk(styles, chunkName, chunkStyleKeys);
153
+ if (renderResult.rules.length > 0) {
154
+ const css = formatRules(renderResult.rules, className);
155
+ if (css) cssParts.push(css);
156
+ }
157
+ }
158
+ }
159
+ const ancillaryCSS = collectAncillaryRSC(rscCache, styles);
160
+ if (ancillaryCSS) cssParts.push(ancillaryCSS);
161
+ if (classNames.length === 0) return EMPTY_RESULT;
162
+ const css = cssParts.join("\n");
163
+ return {
164
+ className: classNames.join(" "),
165
+ css: css || void 0
166
+ };
167
+ }
168
+ /**
169
+ * Get keyframes that are actually used in styles.
170
+ * Returns null if no keyframes are used (fast path for zero overhead).
171
+ */
172
+ function getUsedKeyframes(styles) {
173
+ const hasLocal = hasLocalKeyframes(styles);
174
+ const hasGlobal = hasGlobalKeyframes();
175
+ if (!hasLocal && !hasGlobal) return null;
176
+ const usedNames = extractAnimationNamesFromStyles(styles);
177
+ if (usedNames.size === 0) return null;
178
+ return filterUsedKeyframes(mergeKeyframes(hasLocal ? extractLocalKeyframes(styles) : null, hasGlobal ? getGlobalKeyframes() : null), usedNames);
179
+ }
180
+ /**
181
+ * Process a chunk on the SSR path: allocate via collector, render, collect CSS.
182
+ */
183
+ function processChunkSSR(collector, styles, chunkName, styleKeys) {
184
+ if (styleKeys.length === 0) return null;
185
+ const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);
186
+ const { className, isNewAllocation } = collector.allocateClassName(cacheKey);
187
+ if (isNewAllocation) {
188
+ const renderResult = renderStylesForChunk(styles, chunkName, styleKeys);
189
+ if (renderResult.rules.length > 0) {
190
+ collector.collectChunk(cacheKey, className, renderResult.rules);
191
+ return {
192
+ name: chunkName,
193
+ styleKeys,
194
+ cacheKey,
195
+ renderResult,
196
+ className
197
+ };
198
+ }
199
+ return null;
200
+ }
201
+ return {
202
+ name: chunkName,
203
+ styleKeys,
204
+ cacheKey,
205
+ renderResult: { rules: [] },
206
+ className
207
+ };
208
+ }
209
+ /**
210
+ * Process a chunk on the client: render, allocate className, and inject
211
+ * CSS synchronously. The injector's cache makes this idempotent.
212
+ */
213
+ function processChunkSync(styles, chunkName, styleKeys) {
214
+ if (styleKeys.length === 0) return null;
215
+ const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);
216
+ const renderResult = renderStylesForChunk(styles, chunkName, styleKeys, cacheKey);
217
+ if (renderResult.rules.length === 0) return null;
218
+ const { className } = inject(renderResult.rules, { cacheKey });
219
+ return {
220
+ name: chunkName,
221
+ styleKeys,
222
+ cacheKey,
223
+ renderResult,
224
+ className
225
+ };
226
+ }
227
+ /**
228
+ * Inject keyframes synchronously and return a name replacement map.
229
+ * On the client, keyframes are injected into the DOM.
230
+ */
231
+ function injectKeyframesSync(usedKeyframes) {
232
+ let nameMap = null;
233
+ for (const [name, steps] of Object.entries(usedKeyframes)) {
234
+ const injectedName = keyframes(steps, { name }).toString();
235
+ if (injectedName !== name) {
236
+ if (!nameMap) nameMap = /* @__PURE__ */ new Map();
237
+ nameMap.set(name, injectedName);
238
+ }
239
+ }
240
+ return nameMap;
241
+ }
242
+ /**
243
+ * Inject chunk rules synchronously, replacing animation names if needed.
244
+ */
245
+ function injectChunkRulesSync(chunks, nameMap) {
246
+ for (const chunk of chunks) if (chunk.renderResult.rules.length > 0) inject(nameMap ? chunk.renderResult.rules.map((rule) => ({
247
+ ...rule,
248
+ declarations: replaceAnimationNames(rule.declarations, nameMap)
249
+ })) : chunk.renderResult.rules, { cacheKey: chunk.cacheKey });
250
+ }
251
+ /**
252
+ * Inject all ancillary rules (properties, font-faces, counter-styles) synchronously.
253
+ */
254
+ function injectAncillarySync(styles) {
255
+ if (hasLocalProperties(styles)) {
256
+ const localProperties = extractLocalProperties(styles);
257
+ if (localProperties) for (const [token, definition] of Object.entries(localProperties)) property(token, definition);
258
+ }
259
+ if (hasLocalFontFace(styles)) {
260
+ const localFontFace = extractLocalFontFace(styles);
261
+ if (localFontFace) for (const [family, input] of Object.entries(localFontFace)) {
262
+ const descriptors = Array.isArray(input) ? input : [input];
263
+ for (const desc of descriptors) fontFace(family, desc);
264
+ }
265
+ }
266
+ if (hasLocalCounterStyle(styles)) {
267
+ const localCounterStyle = extractLocalCounterStyle(styles);
268
+ if (localCounterStyle) for (const [name, descriptors] of Object.entries(localCounterStyle)) counterStyle(name, descriptors);
269
+ }
270
+ }
271
+ /**
272
+ * Collect all ancillary rules into the SSR collector.
273
+ */
274
+ function collectAncillarySSR(collector, styles, chunks) {
275
+ const usedKf = getUsedKeyframes(styles);
276
+ if (usedKf) for (const [name, steps] of Object.entries(usedKf)) {
277
+ const css = formatKeyframesCSS(name, steps);
278
+ collector.collectKeyframes(name, css);
279
+ }
280
+ if (hasLocalProperties(styles)) {
281
+ const localProperties = extractLocalProperties(styles);
282
+ if (localProperties) for (const [token, definition] of Object.entries(localProperties)) {
283
+ const css = formatPropertyCSS(token, definition);
284
+ if (css) collector.collectProperty(token, css);
285
+ }
286
+ }
287
+ if (hasLocalFontFace(styles)) {
288
+ const localFontFace = extractLocalFontFace(styles);
289
+ if (localFontFace) for (const [family, input] of Object.entries(localFontFace)) {
290
+ const descriptors = Array.isArray(input) ? input : [input];
291
+ for (const desc of descriptors) {
292
+ const hash = fontFaceContentHash(family, desc);
293
+ const css = formatFontFaceRule(family, desc);
294
+ collector.collectFontFace(hash, css);
295
+ }
296
+ }
297
+ }
298
+ if (hasLocalCounterStyle(styles)) {
299
+ const localCounterStyle = extractLocalCounterStyle(styles);
300
+ if (localCounterStyle) for (const [name, descriptors] of Object.entries(localCounterStyle)) {
301
+ const css = formatCounterStyleRule(name, descriptors);
302
+ collector.collectCounterStyle(name, css);
303
+ }
304
+ }
305
+ if (getConfig().autoPropertyTypes !== false) {
306
+ const allRules = chunks.flatMap((c) => c.renderResult.rules);
307
+ if (allRules.length > 0) collectAutoInferredProperties(allRules, collector, styles);
308
+ }
309
+ }
310
+ /**
311
+ * Synchronous, hook-free style computation.
312
+ *
313
+ * Resolves recipes, categorizes style keys into chunks, renders CSS rules,
314
+ * allocates class names, and injects / collects / returns the CSS.
315
+ *
316
+ * Three code paths:
317
+ * 1. SSR collector — discovered via ALS or passed explicitly; CSS collected
318
+ * 2. RSC inline — no collector and no `document`; CSS returned as `result.css`
319
+ * for the caller to emit as an inline `<style>` tag
320
+ * 3. Client inject — CSS injected synchronously into the DOM (idempotent)
321
+ *
322
+ * @param styles - Tasty styles object (or undefined for no styles)
323
+ * @param options - Optional SSR collector override
324
+ */
325
+ function computeStyles(styles, options) {
326
+ if (!styles || !hasKeys(styles)) return EMPTY_RESULT;
327
+ const resolved = resolveRecipes(styles);
328
+ const chunkMap = categorizeStyleKeys(resolved);
329
+ const collector = options?.ssrCollector !== void 0 ? options.ssrCollector : getRegisteredSSRCollector();
330
+ const chunks = [];
331
+ if (collector) {
332
+ collector.collectInternals();
333
+ for (const [chunkName, chunkStyleKeys] of chunkMap) {
334
+ const chunk = processChunkSSR(collector, resolved, chunkName, chunkStyleKeys);
335
+ if (chunk) chunks.push(chunk);
336
+ }
337
+ collectAncillarySSR(collector, resolved, chunks);
338
+ } else if (typeof document === "undefined") return computeStylesRSC(resolved, chunkMap);
339
+ else {
340
+ injectAncillarySync(resolved);
341
+ const usedKf = getUsedKeyframes(resolved);
342
+ const nameMap = usedKf ? injectKeyframesSync(usedKf) : null;
343
+ for (const [chunkName, chunkStyleKeys] of chunkMap) {
344
+ const chunk = processChunkSync(resolved, chunkName, chunkStyleKeys);
345
+ if (chunk) chunks.push(chunk);
346
+ }
347
+ if (nameMap) injectChunkRulesSync(chunks, nameMap);
348
+ for (const chunk of chunks) touch(chunk.className);
349
+ }
350
+ if (chunks.length === 0) return EMPTY_RESULT;
351
+ if (chunks.length === 1) return { className: chunks[0].className };
352
+ return { className: chunks.map((c) => c.className).join(" ") };
353
+ }
354
+ //#endregion
355
+ export { computeStyles };
356
+
357
+ //# sourceMappingURL=compute-styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compute-styles.js","names":[],"sources":["../src/compute-styles.ts"],"sourcesContent":["/**\n * Hook-free, synchronous style computation.\n *\n * Extracts the core logic from useStyles() into a plain function that can\n * be called during React render without any hooks. Three code paths:\n *\n * 1. SSR collector — styles collected via ServerStyleCollector\n * 2. Client inject — styles injected synchronously into the DOM\n * 3. RSC inline — styles returned as CSS strings for inline <style> emission\n *\n * This enables tasty() components to work as React Server Components.\n */\n\nimport { cache } from 'react';\n\nimport {\n categorizeStyleKeys,\n generateChunkCacheKey,\n renderStylesForChunk,\n} from './chunks';\nimport {\n getConfig,\n getGlobalConfigTokens,\n getGlobalCounterStyle,\n getEffectiveProperties,\n getGlobalFontFace,\n getGlobalKeyframes,\n hasGlobalKeyframes,\n} from './config';\nimport {\n counterStyle,\n fontFace,\n inject,\n keyframes,\n property,\n touch,\n} from './injector';\nimport type { FontFaceDescriptors, KeyframesSteps } from './injector/types';\nimport {\n extractLocalCounterStyle,\n formatCounterStyleRule,\n hasLocalCounterStyle,\n} from './counter-style';\nimport {\n extractLocalFontFace,\n fontFaceContentHash,\n formatFontFaceRule,\n hasLocalFontFace,\n} from './font-face';\nimport {\n extractAnimationNamesFromStyles,\n extractLocalKeyframes,\n filterUsedKeyframes,\n hasLocalKeyframes,\n mergeKeyframes,\n replaceAnimationNames,\n} from './keyframes';\nimport type { RenderResult, StyleResult } from './pipeline';\nimport { renderStyles } from './pipeline';\nimport { extractLocalProperties, hasLocalProperties } from './properties';\nimport { collectAutoInferredProperties } from './ssr/collect-auto-properties';\nimport type { ServerStyleCollector } from './ssr/collector';\nimport { formatGlobalRules } from './ssr/format-global-rules';\nimport { formatKeyframesCSS } from './ssr/format-keyframes';\nimport { formatPropertyCSS } from './ssr/format-property';\nimport { formatRules } from './ssr/format-rules';\nimport { getRegisteredSSRCollector } from './ssr/ssr-collector-ref';\nimport type { Styles } from './styles/types';\nimport { hasKeys } from './utils/has-keys';\nimport { resolveRecipes } from './utils/resolve-recipes';\n\nexport interface ComputeStylesResult {\n className: string;\n /** CSS text to emit as an inline <style> tag (RSC mode only). */\n css?: string;\n}\n\nexport interface ComputeStylesOptions {\n ssrCollector?: ServerStyleCollector | null;\n}\n\ninterface ProcessedChunk {\n name: string;\n styleKeys: string[];\n cacheKey: string;\n renderResult: RenderResult;\n className: string;\n}\n\nconst EMPTY_RESULT: ComputeStylesResult = { className: '' };\n\n// ---------------------------------------------------------------------------\n// RSC (React Server Components) inline style support\n// ---------------------------------------------------------------------------\n\ninterface RSCStyleCache {\n cacheKeyToClassName: Map<string, string>;\n classCounter: number;\n emittedKeys: Set<string>;\n internalsEmitted: boolean;\n}\n\n/**\n * Per-request RSC style cache using React.cache.\n * React.cache provides per-request memoization in Server Components,\n * so each request gets its own isolated cache.\n */\nconst getRSCCache = cache(\n (): RSCStyleCache => ({\n cacheKeyToClassName: new Map(),\n classCounter: 0,\n emittedKeys: new Set(),\n internalsEmitted: false,\n }),\n);\n\nfunction rscAllocateClassName(\n rscCache: RSCStyleCache,\n cacheKey: string,\n): { className: string; isNew: boolean } {\n const existing = rscCache.cacheKeyToClassName.get(cacheKey);\n if (existing) return { className: existing, isNew: false };\n\n // Use 'r' prefix to avoid collisions with SSR collector's 't' prefix\n const className = `r${rscCache.classCounter++}`;\n rscCache.cacheKeyToClassName.set(cacheKey, className);\n return { className, isNew: true };\n}\n\n/**\n * Collect internals CSS for RSC — mirrors ServerStyleCollector.collectInternals().\n * Emitted once per request (tracked via rscCache.internalsEmitted).\n */\nfunction collectInternalsRSC(rscCache: RSCStyleCache): string {\n if (rscCache.internalsEmitted) return '';\n rscCache.internalsEmitted = true;\n\n const parts: string[] = [];\n\n for (const [token, definition] of Object.entries(getEffectiveProperties())) {\n const css = formatPropertyCSS(token, definition);\n if (css) parts.push(css);\n }\n\n const tokenStyles = getGlobalConfigTokens();\n if (tokenStyles && Object.keys(tokenStyles).length > 0) {\n const tokenRules = renderStyles(tokenStyles, ':root') as StyleResult[];\n if (tokenRules.length > 0) {\n const css = formatGlobalRules(tokenRules);\n if (css) parts.push(css);\n }\n }\n\n const globalFF = getGlobalFontFace();\n if (globalFF) {\n for (const [family, input] of Object.entries(globalFF)) {\n const descriptors: FontFaceDescriptors[] = Array.isArray(input)\n ? input\n : [input];\n for (const desc of descriptors) {\n parts.push(formatFontFaceRule(family, desc));\n }\n }\n }\n\n const globalCS = getGlobalCounterStyle();\n if (globalCS) {\n for (const [name, descriptors] of Object.entries(globalCS)) {\n parts.push(formatCounterStyleRule(name, descriptors));\n }\n }\n\n return parts.join('\\n');\n}\n\n/**\n * Collect per-component ancillary CSS (keyframes, @property, font-face,\n * counter-style) for RSC mode.\n */\nfunction collectAncillaryRSC(rscCache: RSCStyleCache, styles: Styles): string {\n const parts: string[] = [];\n\n const usedKf = getUsedKeyframes(styles);\n if (usedKf) {\n for (const [name, steps] of Object.entries(usedKf)) {\n const key = `__kf:${name}`;\n if (!rscCache.emittedKeys.has(key)) {\n rscCache.emittedKeys.add(key);\n parts.push(formatKeyframesCSS(name, steps));\n }\n }\n }\n\n if (hasLocalProperties(styles)) {\n const localProperties = extractLocalProperties(styles);\n if (localProperties) {\n for (const [token, definition] of Object.entries(localProperties)) {\n const key = `__prop:${token}`;\n if (!rscCache.emittedKeys.has(key)) {\n rscCache.emittedKeys.add(key);\n const css = formatPropertyCSS(token, definition);\n if (css) parts.push(css);\n }\n }\n }\n }\n\n if (hasLocalFontFace(styles)) {\n const localFontFace = extractLocalFontFace(styles);\n if (localFontFace) {\n for (const [family, input] of Object.entries(localFontFace)) {\n const descriptors: FontFaceDescriptors[] = Array.isArray(input)\n ? input\n : [input];\n for (const desc of descriptors) {\n const hash = fontFaceContentHash(family, desc);\n const key = `__ff:${hash}`;\n if (!rscCache.emittedKeys.has(key)) {\n rscCache.emittedKeys.add(key);\n parts.push(formatFontFaceRule(family, desc));\n }\n }\n }\n }\n }\n\n if (hasLocalCounterStyle(styles)) {\n const localCounterStyle = extractLocalCounterStyle(styles);\n if (localCounterStyle) {\n for (const [name, descriptors] of Object.entries(localCounterStyle)) {\n const key = `__cs:${name}`;\n if (!rscCache.emittedKeys.has(key)) {\n rscCache.emittedKeys.add(key);\n parts.push(formatCounterStyleRule(name, descriptors));\n }\n }\n }\n }\n\n return parts.join('\\n');\n}\n\n/**\n * Process all chunks in RSC mode: render CSS to strings, allocate classNames,\n * and return combined { className, css }.\n */\nfunction computeStylesRSC(\n styles: Styles,\n chunkMap: Map<string, string[]>,\n): ComputeStylesResult {\n const rscCache = getRSCCache();\n const cssParts: string[] = [];\n const classNames: string[] = [];\n\n const internalsCSS = collectInternalsRSC(rscCache);\n if (internalsCSS) cssParts.push(internalsCSS);\n\n for (const [chunkName, chunkStyleKeys] of chunkMap) {\n if (chunkStyleKeys.length === 0) continue;\n\n const cacheKey = generateChunkCacheKey(styles, chunkName, chunkStyleKeys);\n const { className, isNew } = rscAllocateClassName(rscCache, cacheKey);\n classNames.push(className);\n\n if (isNew) {\n const renderResult = renderStylesForChunk(\n styles,\n chunkName,\n chunkStyleKeys,\n );\n if (renderResult.rules.length > 0) {\n const css = formatRules(renderResult.rules, className);\n if (css) cssParts.push(css);\n }\n }\n }\n\n const ancillaryCSS = collectAncillaryRSC(rscCache, styles);\n if (ancillaryCSS) cssParts.push(ancillaryCSS);\n\n if (classNames.length === 0) return EMPTY_RESULT;\n\n const css = cssParts.join('\\n');\n\n return {\n className: classNames.join(' '),\n css: css || undefined,\n };\n}\n\n/**\n * Get keyframes that are actually used in styles.\n * Returns null if no keyframes are used (fast path for zero overhead).\n */\nfunction getUsedKeyframes(\n styles: Styles,\n): Record<string, KeyframesSteps> | null {\n const hasLocal = hasLocalKeyframes(styles);\n const hasGlobal = hasGlobalKeyframes();\n if (!hasLocal && !hasGlobal) return null;\n\n const usedNames = extractAnimationNamesFromStyles(styles);\n if (usedNames.size === 0) return null;\n\n const local = hasLocal ? extractLocalKeyframes(styles) : null;\n const global = hasGlobal ? getGlobalKeyframes() : null;\n const allKeyframes = mergeKeyframes(local, global);\n\n return filterUsedKeyframes(allKeyframes, usedNames);\n}\n\n/**\n * Process a chunk on the SSR path: allocate via collector, render, collect CSS.\n */\nfunction processChunkSSR(\n collector: ServerStyleCollector,\n styles: Styles,\n chunkName: string,\n styleKeys: string[],\n): ProcessedChunk | null {\n if (styleKeys.length === 0) return null;\n\n const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);\n const { className, isNewAllocation } = collector.allocateClassName(cacheKey);\n\n if (isNewAllocation) {\n const renderResult = renderStylesForChunk(styles, chunkName, styleKeys);\n if (renderResult.rules.length > 0) {\n collector.collectChunk(cacheKey, className, renderResult.rules);\n return { name: chunkName, styleKeys, cacheKey, renderResult, className };\n }\n return null;\n }\n\n return {\n name: chunkName,\n styleKeys,\n cacheKey,\n renderResult: { rules: [] },\n className,\n };\n}\n\n/**\n * Process a chunk on the client: render, allocate className, and inject\n * CSS synchronously. The injector's cache makes this idempotent.\n */\nfunction processChunkSync(\n styles: Styles,\n chunkName: string,\n styleKeys: string[],\n): ProcessedChunk | null {\n if (styleKeys.length === 0) return null;\n\n const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);\n const renderResult = renderStylesForChunk(\n styles,\n chunkName,\n styleKeys,\n cacheKey,\n );\n if (renderResult.rules.length === 0) return null;\n\n const { className } = inject(renderResult.rules, { cacheKey });\n\n return { name: chunkName, styleKeys, cacheKey, renderResult, className };\n}\n\n/**\n * Inject keyframes synchronously and return a name replacement map.\n * On the client, keyframes are injected into the DOM.\n */\nfunction injectKeyframesSync(\n usedKeyframes: Record<string, KeyframesSteps>,\n): Map<string, string> | null {\n let nameMap: Map<string, string> | null = null;\n\n for (const [name, steps] of Object.entries(usedKeyframes)) {\n const result = keyframes(steps, { name });\n const injectedName = result.toString();\n if (injectedName !== name) {\n if (!nameMap) nameMap = new Map();\n nameMap.set(name, injectedName);\n }\n }\n\n return nameMap;\n}\n\n/**\n * Inject chunk rules synchronously, replacing animation names if needed.\n */\nfunction injectChunkRulesSync(\n chunks: ProcessedChunk[],\n nameMap: Map<string, string> | null,\n): void {\n for (const chunk of chunks) {\n if (chunk.renderResult.rules.length > 0) {\n const rulesToInject: StyleResult[] = nameMap\n ? chunk.renderResult.rules.map((rule) => ({\n ...rule,\n declarations: replaceAnimationNames(rule.declarations, nameMap!),\n }))\n : chunk.renderResult.rules;\n\n inject(rulesToInject, { cacheKey: chunk.cacheKey });\n }\n }\n}\n\n/**\n * Inject all ancillary rules (properties, font-faces, counter-styles) synchronously.\n */\nfunction injectAncillarySync(styles: Styles): void {\n if (hasLocalProperties(styles)) {\n const localProperties = extractLocalProperties(styles);\n if (localProperties) {\n for (const [token, definition] of Object.entries(localProperties)) {\n property(token, definition);\n }\n }\n }\n\n if (hasLocalFontFace(styles)) {\n const localFontFace = extractLocalFontFace(styles);\n if (localFontFace) {\n for (const [family, input] of Object.entries(localFontFace)) {\n const descriptors: FontFaceDescriptors[] = Array.isArray(input)\n ? input\n : [input];\n for (const desc of descriptors) {\n fontFace(family, desc);\n }\n }\n }\n }\n\n if (hasLocalCounterStyle(styles)) {\n const localCounterStyle = extractLocalCounterStyle(styles);\n if (localCounterStyle) {\n for (const [name, descriptors] of Object.entries(localCounterStyle)) {\n counterStyle(name, descriptors);\n }\n }\n }\n}\n\n/**\n * Collect all ancillary rules into the SSR collector.\n */\nfunction collectAncillarySSR(\n collector: ServerStyleCollector,\n styles: Styles,\n chunks: ProcessedChunk[],\n): void {\n const usedKf = getUsedKeyframes(styles);\n if (usedKf) {\n for (const [name, steps] of Object.entries(usedKf)) {\n const css = formatKeyframesCSS(name, steps);\n collector.collectKeyframes(name, css);\n }\n }\n\n if (hasLocalProperties(styles)) {\n const localProperties = extractLocalProperties(styles);\n if (localProperties) {\n for (const [token, definition] of Object.entries(localProperties)) {\n const css = formatPropertyCSS(token, definition);\n if (css) {\n collector.collectProperty(token, css);\n }\n }\n }\n }\n\n if (hasLocalFontFace(styles)) {\n const localFontFace = extractLocalFontFace(styles);\n if (localFontFace) {\n for (const [family, input] of Object.entries(localFontFace)) {\n const descriptors: FontFaceDescriptors[] = Array.isArray(input)\n ? input\n : [input];\n for (const desc of descriptors) {\n const hash = fontFaceContentHash(family, desc);\n const css = formatFontFaceRule(family, desc);\n collector.collectFontFace(hash, css);\n }\n }\n }\n }\n\n if (hasLocalCounterStyle(styles)) {\n const localCounterStyle = extractLocalCounterStyle(styles);\n if (localCounterStyle) {\n for (const [name, descriptors] of Object.entries(localCounterStyle)) {\n const css = formatCounterStyleRule(name, descriptors);\n collector.collectCounterStyle(name, css);\n }\n }\n }\n\n if (getConfig().autoPropertyTypes !== false) {\n const allRules = chunks.flatMap((c) => c.renderResult.rules);\n if (allRules.length > 0) {\n collectAutoInferredProperties(allRules, collector, styles);\n }\n }\n}\n\n/**\n * Synchronous, hook-free style computation.\n *\n * Resolves recipes, categorizes style keys into chunks, renders CSS rules,\n * allocates class names, and injects / collects / returns the CSS.\n *\n * Three code paths:\n * 1. SSR collector — discovered via ALS or passed explicitly; CSS collected\n * 2. RSC inline — no collector and no `document`; CSS returned as `result.css`\n * for the caller to emit as an inline `<style>` tag\n * 3. Client inject — CSS injected synchronously into the DOM (idempotent)\n *\n * @param styles - Tasty styles object (or undefined for no styles)\n * @param options - Optional SSR collector override\n */\nexport function computeStyles(\n styles: Styles | undefined,\n options?: ComputeStylesOptions,\n): ComputeStylesResult {\n if (!styles || !hasKeys(styles as Record<string, unknown>)) {\n return EMPTY_RESULT;\n }\n\n const resolved = resolveRecipes(styles);\n const chunkMap = categorizeStyleKeys(resolved as Record<string, unknown>);\n\n const collector =\n options?.ssrCollector !== undefined\n ? options.ssrCollector\n : getRegisteredSSRCollector();\n\n const chunks: ProcessedChunk[] = [];\n\n if (collector) {\n collector.collectInternals();\n\n for (const [chunkName, chunkStyleKeys] of chunkMap) {\n const chunk = processChunkSSR(\n collector,\n resolved,\n chunkName,\n chunkStyleKeys,\n );\n if (chunk) chunks.push(chunk);\n }\n\n collectAncillarySSR(collector, resolved, chunks);\n } else if (typeof document === 'undefined') {\n // RSC path: render CSS to strings for inline <style> emission\n return computeStylesRSC(resolved, chunkMap);\n } else {\n injectAncillarySync(resolved);\n\n const usedKf = getUsedKeyframes(resolved);\n const nameMap = usedKf ? injectKeyframesSync(usedKf) : null;\n\n for (const [chunkName, chunkStyleKeys] of chunkMap) {\n const chunk = processChunkSync(resolved, chunkName, chunkStyleKeys);\n if (chunk) chunks.push(chunk);\n }\n\n if (nameMap) {\n injectChunkRulesSync(chunks, nameMap);\n }\n\n for (const chunk of chunks) {\n touch(chunk.className);\n }\n }\n\n if (chunks.length === 0) return EMPTY_RESULT;\n if (chunks.length === 1) return { className: chunks[0].className };\n\n return { className: chunks.map((c) => c.className).join(' ') };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,MAAM,eAAoC,EAAE,WAAW,IAAI;;;;;;AAkB3D,MAAM,cAAc,aACI;CACpB,qCAAqB,IAAI,KAAK;CAC9B,cAAc;CACd,6BAAa,IAAI,KAAK;CACtB,kBAAkB;CACnB,EACF;AAED,SAAS,qBACP,UACA,UACuC;CACvC,MAAM,WAAW,SAAS,oBAAoB,IAAI,SAAS;AAC3D,KAAI,SAAU,QAAO;EAAE,WAAW;EAAU,OAAO;EAAO;CAG1D,MAAM,YAAY,IAAI,SAAS;AAC/B,UAAS,oBAAoB,IAAI,UAAU,UAAU;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AW,EAAG,QAAO;AAChC,KAAI,OAAO,WAAW,EAAG,QAAO,EAAE,WAAW,OAAO,GAAG,WAAW;AAElE,QAAO,EAAE,WAAW,OAAO,KAAK,MAAM,EAAE,UAAU,CAAC,KAAK,IAAI,EAAE"}
package/dist/config.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { KeyframesSteps, PropertyDefinition } from "./injector/types.js";
1
+ import { CounterStyleDescriptors, FontFaceInput, GCConfig, KeyframesSteps, PropertyDefinition } from "./injector/types.js";
2
2
  import { StyleDetails, UnitHandler } from "./parser/types.js";
3
3
  import { StyleHandlerDefinition } from "./utils/styles.js";
4
- import { RecipeStyles } from "./styles/types.js";
4
+ import { ConfigTokens, RecipeStyles } from "./styles/types.js";
5
5
  import { StyleInjector } from "./injector/injector.js";
6
+ import { ColorSpace } from "./utils/color-space.js";
6
7
  import { TastyPlugin } from "./plugins/types.js";
7
8
 
8
9
  //#region src/config.d.ts
@@ -14,27 +15,10 @@ interface TastyConfig {
14
15
  nonce?: string;
15
16
  /** Maximum rules per stylesheet (default: 8192) */
16
17
  maxRulesPerSheet?: number;
17
- /** Threshold for bulk cleanup of unused styles (default: 500) */
18
- unusedStylesThreshold?: number;
19
- /** Delay before bulk cleanup in ms, ignored if idleCleanup is true (default: 5000) */
20
- bulkCleanupDelay?: number;
21
- /** Use requestIdleCallback for cleanup when available (default: true) */
22
- idleCleanup?: boolean;
23
18
  /** Force text injection mode, auto-detected in test environments (default: auto) */
24
19
  forceTextInjection?: boolean;
25
20
  /** Enable development mode features: performance metrics and debug info (default: auto) */
26
21
  devMode?: boolean;
27
- /**
28
- * Ratio of unused styles to delete per bulk cleanup run (0..1).
29
- * Defaults to 0.5 (oldest half) to reduce risk of removing styles
30
- * that may be restored shortly after being marked unused.
31
- */
32
- bulkCleanupBatchRatio?: number;
33
- /**
34
- * Minimum age (in ms) a style must remain unused before eligible for deletion.
35
- * Helps avoid races during rapid mount/unmount cycles. Default: 10000ms.
36
- */
37
- unusedStylesMinAgeMs?: number;
38
22
  /**
39
23
  * Global predefined states for advanced state mapping.
40
24
  * These are state aliases that can be used in any component.
@@ -58,6 +42,36 @@ interface TastyConfig {
58
42
  * @example { myFunc: (groups) => groups.map(g => g.output).join(' ') }
59
43
  */
60
44
  funcs?: Record<string, (groups: StyleDetails[]) => string>;
45
+ /**
46
+ * Color space used for decomposed color token companion variables.
47
+ * Controls the CSS function and suffix for alpha composition.
48
+ *
49
+ * - `'rgb'` — suffix `-rgb`, e.g. `rgb(var(--name-color-rgb) / .5)`
50
+ * - `'hsl'` — suffix `-hsl`, e.g. `hsl(var(--name-color-hsl) / .5)`
51
+ * - `'oklch'` — suffix `-oklch`, e.g. `oklch(var(--name-color-oklch) / .5)`
52
+ *
53
+ * @default 'oklch'
54
+ */
55
+ colorSpace?: ColorSpace;
56
+ /**
57
+ * Automatically infer and register CSS @property declarations
58
+ * from custom property values found in styles, keyframes, and global config.
59
+ * Covers all types: \<color\>, \<number\>, \<length\>, \<angle\>, \<percentage\>, \<time\>.
60
+ * When false, only explicitly declared @properties are registered.
61
+ * @default true
62
+ */
63
+ autoPropertyTypes?: boolean;
64
+ /**
65
+ * Garbage collection configuration for unused styles.
66
+ * Controls popularity-aware style eviction with DOM safety guard.
67
+ * @example
68
+ * ```ts
69
+ * configure({
70
+ * gc: { auto: true, baseMaxAge: 60000, cooldown: 30000 },
71
+ * });
72
+ * ```
73
+ */
74
+ gc?: GCConfig;
61
75
  /**
62
76
  * Plugins that extend tasty with custom functions, units, or states.
63
77
  * Plugins are processed in order, with later plugins overriding earlier ones.
@@ -89,7 +103,11 @@ interface TastyConfig {
89
103
  /**
90
104
  * Global CSS @property definitions for custom properties.
91
105
  * Keys use tasty token syntax ($name for properties, #name for colors).
92
- * Properties are only injected when the component using them is rendered.
106
+ *
107
+ * Tasty ships with `DEFAULT_PROPERTIES` (e.g. `$gap`, `$radius`, `#white`,
108
+ * `#black`, `#clear`, `#border`, etc.) that are always included.
109
+ * Properties you specify here are merged on top, so you can override any
110
+ * default by using the same key.
93
111
  *
94
112
  * For color tokens (#name), `syntax: '<color>'` is auto-set and
95
113
  * `initialValue` defaults to `'transparent'` if not specified.
@@ -101,6 +119,8 @@ interface TastyConfig {
101
119
  * '$rotation': { syntax: '<angle>', initialValue: '0deg' },
102
120
  * '$scale': { syntax: '<number>', inherits: false, initialValue: 1 },
103
121
  * '#accent': { initialValue: 'purple' }, // syntax: '<color>' auto-set
122
+ * // Override a default property:
123
+ * '$gap': { syntax: '<length>', inherits: true, initialValue: '8px' },
104
124
  * },
105
125
  * });
106
126
  *
@@ -114,6 +134,39 @@ interface TastyConfig {
114
134
  * ```
115
135
  */
116
136
  properties?: Record<string, PropertyDefinition>;
137
+ /**
138
+ * Global @font-face definitions.
139
+ * Keys are font-family names, values are descriptors or arrays of descriptors
140
+ * (for multiple weights/styles of the same family).
141
+ * Injected eagerly when styles are first generated.
142
+ * @example
143
+ * ```ts
144
+ * configure({
145
+ * fontFace: {
146
+ * 'Brand Sans': [
147
+ * { src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
148
+ * { src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
149
+ * ],
150
+ * Icons: { src: 'url("/fonts/icons.woff2") format("woff2")', fontDisplay: 'block' },
151
+ * },
152
+ * });
153
+ * ```
154
+ */
155
+ fontFace?: Record<string, FontFaceInput>;
156
+ /**
157
+ * Global @counter-style definitions.
158
+ * Keys are counter-style names, values are descriptor objects.
159
+ * Injected eagerly when styles are first generated.
160
+ * @example
161
+ * ```ts
162
+ * configure({
163
+ * counterStyle: {
164
+ * thumbs: { system: 'cyclic', symbols: '"👍"', suffix: '" "' },
165
+ * },
166
+ * });
167
+ * ```
168
+ */
169
+ counterStyle?: Record<string, CounterStyleDescriptors>;
117
170
  /**
118
171
  * Custom style handlers that transform style properties into CSS declarations.
119
172
  * Handlers replace built-in handlers for the same style name.
@@ -144,20 +197,43 @@ interface TastyConfig {
144
197
  */
145
198
  handlers?: Record<string, StyleHandlerDefinition>;
146
199
  /**
147
- * Predefined tokens that are replaced during style parsing.
148
- * Token values are processed through the parser (like component tokens).
200
+ * Design tokens injected as CSS custom properties on `:root`.
201
+ * Values are parsed through the Tasty DSL. Supports state maps
202
+ * for responsive/theme-aware tokens.
203
+ *
204
+ * - `$name` keys become `--name` CSS custom properties
205
+ * - `#name` keys become `--name-color` and `--name-color-{colorSpace}` properties
206
+ *
207
+ * Tokens are injected once when the first style is rendered.
208
+ *
209
+ * @example
210
+ * ```ts
211
+ * configure({
212
+ * tokens: {
213
+ * '$gap': '4px',
214
+ * '#primary': {
215
+ * '': '#purple',
216
+ * '@dark': '#light-purple',
217
+ * },
218
+ * },
219
+ * });
220
+ * ```
221
+ */
222
+ tokens?: ConfigTokens;
223
+ /**
224
+ * Predefined tokens that are replaced during style parsing (parse-time substitution).
149
225
  * Use `$name` for custom properties and `#name` for color tokens.
226
+ * Values are substituted inline before CSS generation, unlike `tokens` which
227
+ * inject CSS custom properties on `:root`.
150
228
  *
151
229
  * For color tokens (#name), boolean `true` is converted to `transparent`.
152
230
  *
153
231
  * @example
154
232
  * ```ts
155
233
  * configure({
156
- * tokens: {
234
+ * replaceTokens: {
157
235
  * $spacing: '2x',
158
- * '$card-padding': '4x',
159
236
  * '#accent': '#purple',
160
- * '#surface': '#white',
161
237
  * '#overlay': true, // → transparent
162
238
  * },
163
239
  * });
@@ -165,13 +241,13 @@ interface TastyConfig {
165
241
  * // Now use in styles - tokens are replaced at parse time:
166
242
  * const Card = tasty({
167
243
  * styles: {
168
- * padding: '$card-padding', // → calc(4 * var(--gap))
169
- * fill: '#surface', // → var(--white-color)
244
+ * padding: '$spacing', // → calc(2 * var(--gap))
245
+ * fill: '#accent', // → var(--purple-color)
170
246
  * },
171
247
  * });
172
248
  * ```
173
249
  */
174
- tokens?: Record<`$${string}`, string | number | boolean> & Record<`#${string}`, string | number | boolean>;
250
+ replaceTokens?: Record<`$${string}`, string | number | boolean> & Record<`#${string}`, string | number | boolean>;
175
251
  /**
176
252
  * Predefined style recipes -- named style bundles that can be applied via `recipe` style property.
177
253
  * Recipe values are flat tasty styles (no sub-element keys). They may contain base styles,
@@ -221,7 +297,7 @@ declare function isTestEnvironment(): boolean;
221
297
  declare function hasStylesGenerated(): boolean;
222
298
  /**
223
299
  * Check if any global keyframes are configured.
224
- * Fast path: returns false if no keyframes were ever set.
300
+ * Uses a pre-computed flag to avoid Object.keys() allocation on every call.
225
301
  */
226
302
  declare function hasGlobalKeyframes(): boolean;
227
303
  /**
@@ -229,6 +305,16 @@ declare function hasGlobalKeyframes(): boolean;
229
305
  * Returns null if no keyframes configured (fast path for zero-overhead).
230
306
  */
231
307
  declare function getGlobalKeyframes(): Record<string, KeyframesSteps> | null;
308
+ /**
309
+ * Get global font-face configuration.
310
+ * Returns null if no font faces configured.
311
+ */
312
+ declare function getGlobalFontFace(): Record<string, FontFaceInput> | null;
313
+ /**
314
+ * Get global counter-style configuration.
315
+ * Returns null if no counter styles configured.
316
+ */
317
+ declare function getGlobalCounterStyle(): Record<string, CounterStyleDescriptors> | null;
232
318
  /**
233
319
  * Check if any global recipes are configured.
234
320
  * Fast path: returns false if no recipes were ever set.
@@ -276,5 +362,5 @@ declare function getConfig(): TastyConfig;
276
362
  */
277
363
  declare function resetConfig(): void;
278
364
  //#endregion
279
- export { TastyConfig, configure, getConfig, getGlobalKeyframes, getGlobalRecipes, hasGlobalKeyframes, hasGlobalRecipes, hasStylesGenerated, isConfigLocked, isTestEnvironment, resetConfig };
365
+ export { TastyConfig, configure, getConfig, getGlobalCounterStyle, getGlobalFontFace, getGlobalKeyframes, getGlobalRecipes, hasGlobalKeyframes, hasGlobalRecipes, hasStylesGenerated, isConfigLocked, isTestEnvironment, resetConfig };
280
366
  //# sourceMappingURL=config.d.ts.map