@tenphi/tasty 0.0.0-snapshot.056b911

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 (332) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +635 -0
  3. package/dist/_virtual/_rolldown/runtime.js +7 -0
  4. package/dist/chunks/cacheKey.d.ts +1 -0
  5. package/dist/chunks/cacheKey.js +77 -0
  6. package/dist/chunks/cacheKey.js.map +1 -0
  7. package/dist/chunks/definitions.d.ts +37 -0
  8. package/dist/chunks/definitions.js +258 -0
  9. package/dist/chunks/definitions.js.map +1 -0
  10. package/dist/chunks/index.d.ts +1 -0
  11. package/dist/chunks/renderChunk.d.ts +1 -0
  12. package/dist/chunks/renderChunk.js +59 -0
  13. package/dist/chunks/renderChunk.js.map +1 -0
  14. package/dist/compute-styles.d.ts +31 -0
  15. package/dist/compute-styles.js +335 -0
  16. package/dist/compute-styles.js.map +1 -0
  17. package/dist/config.d.ts +409 -0
  18. package/dist/config.js +584 -0
  19. package/dist/config.js.map +1 -0
  20. package/dist/core/index.d.ts +34 -0
  21. package/dist/core/index.js +27 -0
  22. package/dist/counter-style/index.js +51 -0
  23. package/dist/counter-style/index.js.map +1 -0
  24. package/dist/debug.d.ts +89 -0
  25. package/dist/debug.js +453 -0
  26. package/dist/debug.js.map +1 -0
  27. package/dist/font-face/index.js +63 -0
  28. package/dist/font-face/index.js.map +1 -0
  29. package/dist/hooks/index.d.ts +7 -0
  30. package/dist/hooks/useCounterStyle.d.ts +36 -0
  31. package/dist/hooks/useCounterStyle.js +64 -0
  32. package/dist/hooks/useCounterStyle.js.map +1 -0
  33. package/dist/hooks/useFontFace.d.ts +45 -0
  34. package/dist/hooks/useFontFace.js +66 -0
  35. package/dist/hooks/useFontFace.js.map +1 -0
  36. package/dist/hooks/useGlobalStyles.d.ts +46 -0
  37. package/dist/hooks/useGlobalStyles.js +88 -0
  38. package/dist/hooks/useGlobalStyles.js.map +1 -0
  39. package/dist/hooks/useKeyframes.d.ts +58 -0
  40. package/dist/hooks/useKeyframes.js +54 -0
  41. package/dist/hooks/useKeyframes.js.map +1 -0
  42. package/dist/hooks/useProperty.d.ts +81 -0
  43. package/dist/hooks/useProperty.js +96 -0
  44. package/dist/hooks/useProperty.js.map +1 -0
  45. package/dist/hooks/useRawCSS.d.ts +22 -0
  46. package/dist/hooks/useRawCSS.js +103 -0
  47. package/dist/hooks/useRawCSS.js.map +1 -0
  48. package/dist/hooks/useStyles.d.ts +40 -0
  49. package/dist/hooks/useStyles.js +31 -0
  50. package/dist/hooks/useStyles.js.map +1 -0
  51. package/dist/index.d.ts +51 -0
  52. package/dist/index.js +36 -0
  53. package/dist/injector/index.d.ts +182 -0
  54. package/dist/injector/index.js +185 -0
  55. package/dist/injector/index.js.map +1 -0
  56. package/dist/injector/injector.d.ts +193 -0
  57. package/dist/injector/injector.js +564 -0
  58. package/dist/injector/injector.js.map +1 -0
  59. package/dist/injector/sheet-manager.d.ts +132 -0
  60. package/dist/injector/sheet-manager.js +698 -0
  61. package/dist/injector/sheet-manager.js.map +1 -0
  62. package/dist/injector/types.d.ts +228 -0
  63. package/dist/keyframes/index.js +206 -0
  64. package/dist/keyframes/index.js.map +1 -0
  65. package/dist/parser/classify.js +319 -0
  66. package/dist/parser/classify.js.map +1 -0
  67. package/dist/parser/const.js +60 -0
  68. package/dist/parser/const.js.map +1 -0
  69. package/dist/parser/lru.js +109 -0
  70. package/dist/parser/lru.js.map +1 -0
  71. package/dist/parser/parser.d.ts +25 -0
  72. package/dist/parser/parser.js +115 -0
  73. package/dist/parser/parser.js.map +1 -0
  74. package/dist/parser/tokenizer.js +69 -0
  75. package/dist/parser/tokenizer.js.map +1 -0
  76. package/dist/parser/types.d.ts +51 -0
  77. package/dist/parser/types.js +46 -0
  78. package/dist/parser/types.js.map +1 -0
  79. package/dist/pipeline/conditions.d.ts +134 -0
  80. package/dist/pipeline/conditions.js +406 -0
  81. package/dist/pipeline/conditions.js.map +1 -0
  82. package/dist/pipeline/exclusive.js +230 -0
  83. package/dist/pipeline/exclusive.js.map +1 -0
  84. package/dist/pipeline/index.d.ts +55 -0
  85. package/dist/pipeline/index.js +708 -0
  86. package/dist/pipeline/index.js.map +1 -0
  87. package/dist/pipeline/materialize.js +1103 -0
  88. package/dist/pipeline/materialize.js.map +1 -0
  89. package/dist/pipeline/parseStateKey.d.ts +15 -0
  90. package/dist/pipeline/parseStateKey.js +446 -0
  91. package/dist/pipeline/parseStateKey.js.map +1 -0
  92. package/dist/pipeline/simplify.js +515 -0
  93. package/dist/pipeline/simplify.js.map +1 -0
  94. package/dist/pipeline/warnings.js +18 -0
  95. package/dist/pipeline/warnings.js.map +1 -0
  96. package/dist/plugins/index.d.ts +2 -0
  97. package/dist/plugins/okhsl-plugin.d.ts +35 -0
  98. package/dist/plugins/okhsl-plugin.js +97 -0
  99. package/dist/plugins/okhsl-plugin.js.map +1 -0
  100. package/dist/plugins/types.d.ts +87 -0
  101. package/dist/properties/index.js +222 -0
  102. package/dist/properties/index.js.map +1 -0
  103. package/dist/properties/property-type-resolver.d.ts +24 -0
  104. package/dist/properties/property-type-resolver.js +90 -0
  105. package/dist/properties/property-type-resolver.js.map +1 -0
  106. package/dist/rsc-cache.js +81 -0
  107. package/dist/rsc-cache.js.map +1 -0
  108. package/dist/ssr/astro-client.d.ts +1 -0
  109. package/dist/ssr/astro-client.js +24 -0
  110. package/dist/ssr/astro-client.js.map +1 -0
  111. package/dist/ssr/astro-middleware.d.ts +15 -0
  112. package/dist/ssr/astro-middleware.js +19 -0
  113. package/dist/ssr/astro-middleware.js.map +1 -0
  114. package/dist/ssr/astro.d.ts +106 -0
  115. package/dist/ssr/astro.js +149 -0
  116. package/dist/ssr/astro.js.map +1 -0
  117. package/dist/ssr/async-storage.d.ts +17 -0
  118. package/dist/ssr/async-storage.js +44 -0
  119. package/dist/ssr/async-storage.js.map +1 -0
  120. package/dist/ssr/collect-auto-properties.js +58 -0
  121. package/dist/ssr/collect-auto-properties.js.map +1 -0
  122. package/dist/ssr/collector.d.ts +102 -0
  123. package/dist/ssr/collector.js +227 -0
  124. package/dist/ssr/collector.js.map +1 -0
  125. package/dist/ssr/context.js +16 -0
  126. package/dist/ssr/context.js.map +1 -0
  127. package/dist/ssr/format-global-rules.js +22 -0
  128. package/dist/ssr/format-global-rules.js.map +1 -0
  129. package/dist/ssr/format-keyframes.js +69 -0
  130. package/dist/ssr/format-keyframes.js.map +1 -0
  131. package/dist/ssr/format-property.js +49 -0
  132. package/dist/ssr/format-property.js.map +1 -0
  133. package/dist/ssr/format-rules.js +73 -0
  134. package/dist/ssr/format-rules.js.map +1 -0
  135. package/dist/ssr/hydrate.d.ts +22 -0
  136. package/dist/ssr/hydrate.js +49 -0
  137. package/dist/ssr/hydrate.js.map +1 -0
  138. package/dist/ssr/index.d.ts +4 -0
  139. package/dist/ssr/index.js +10 -0
  140. package/dist/ssr/index.js.map +1 -0
  141. package/dist/ssr/next.d.ts +45 -0
  142. package/dist/ssr/next.js +75 -0
  143. package/dist/ssr/next.js.map +1 -0
  144. package/dist/ssr/ssr-collector-ref.js +29 -0
  145. package/dist/ssr/ssr-collector-ref.js.map +1 -0
  146. package/dist/states/index.d.ts +49 -0
  147. package/dist/states/index.js +170 -0
  148. package/dist/states/index.js.map +1 -0
  149. package/dist/static/index.d.ts +5 -0
  150. package/dist/static/index.js +4 -0
  151. package/dist/static/inject.d.ts +5 -0
  152. package/dist/static/inject.js +17 -0
  153. package/dist/static/inject.js.map +1 -0
  154. package/dist/static/tastyStatic.d.ts +46 -0
  155. package/dist/static/tastyStatic.js +30 -0
  156. package/dist/static/tastyStatic.js.map +1 -0
  157. package/dist/static/types.d.ts +49 -0
  158. package/dist/static/types.js +24 -0
  159. package/dist/static/types.js.map +1 -0
  160. package/dist/styles/border.d.ts +25 -0
  161. package/dist/styles/border.js +120 -0
  162. package/dist/styles/border.js.map +1 -0
  163. package/dist/styles/color.d.ts +14 -0
  164. package/dist/styles/color.js +26 -0
  165. package/dist/styles/color.js.map +1 -0
  166. package/dist/styles/const.js +17 -0
  167. package/dist/styles/const.js.map +1 -0
  168. package/dist/styles/createStyle.js +79 -0
  169. package/dist/styles/createStyle.js.map +1 -0
  170. package/dist/styles/dimension.js +109 -0
  171. package/dist/styles/dimension.js.map +1 -0
  172. package/dist/styles/directional.js +133 -0
  173. package/dist/styles/directional.js.map +1 -0
  174. package/dist/styles/display.d.ts +30 -0
  175. package/dist/styles/display.js +73 -0
  176. package/dist/styles/display.js.map +1 -0
  177. package/dist/styles/fade.d.ts +15 -0
  178. package/dist/styles/fade.js +62 -0
  179. package/dist/styles/fade.js.map +1 -0
  180. package/dist/styles/fill.d.ts +42 -0
  181. package/dist/styles/fill.js +51 -0
  182. package/dist/styles/fill.js.map +1 -0
  183. package/dist/styles/flow.d.ts +16 -0
  184. package/dist/styles/flow.js +12 -0
  185. package/dist/styles/flow.js.map +1 -0
  186. package/dist/styles/gap.d.ts +31 -0
  187. package/dist/styles/gap.js +38 -0
  188. package/dist/styles/gap.js.map +1 -0
  189. package/dist/styles/height.d.ts +17 -0
  190. package/dist/styles/height.js +19 -0
  191. package/dist/styles/height.js.map +1 -0
  192. package/dist/styles/index.d.ts +1 -0
  193. package/dist/styles/index.js +8 -0
  194. package/dist/styles/index.js.map +1 -0
  195. package/dist/styles/inset.d.ts +24 -0
  196. package/dist/styles/inset.js +34 -0
  197. package/dist/styles/inset.js.map +1 -0
  198. package/dist/styles/list.d.ts +16 -0
  199. package/dist/styles/list.js +100 -0
  200. package/dist/styles/list.js.map +1 -0
  201. package/dist/styles/margin.d.ts +24 -0
  202. package/dist/styles/margin.js +32 -0
  203. package/dist/styles/margin.js.map +1 -0
  204. package/dist/styles/outline.d.ts +29 -0
  205. package/dist/styles/outline.js +55 -0
  206. package/dist/styles/outline.js.map +1 -0
  207. package/dist/styles/padding.d.ts +24 -0
  208. package/dist/styles/padding.js +32 -0
  209. package/dist/styles/padding.js.map +1 -0
  210. package/dist/styles/placement.d.ts +37 -0
  211. package/dist/styles/placement.js +74 -0
  212. package/dist/styles/placement.js.map +1 -0
  213. package/dist/styles/predefined.d.ts +71 -0
  214. package/dist/styles/predefined.js +237 -0
  215. package/dist/styles/predefined.js.map +1 -0
  216. package/dist/styles/preset.d.ts +52 -0
  217. package/dist/styles/preset.js +127 -0
  218. package/dist/styles/preset.js.map +1 -0
  219. package/dist/styles/radius.d.ts +12 -0
  220. package/dist/styles/radius.js +83 -0
  221. package/dist/styles/radius.js.map +1 -0
  222. package/dist/styles/scrollMargin.d.ts +24 -0
  223. package/dist/styles/scrollMargin.js +32 -0
  224. package/dist/styles/scrollMargin.js.map +1 -0
  225. package/dist/styles/scrollbar.d.ts +25 -0
  226. package/dist/styles/scrollbar.js +51 -0
  227. package/dist/styles/scrollbar.js.map +1 -0
  228. package/dist/styles/shadow.d.ts +14 -0
  229. package/dist/styles/shadow.js +25 -0
  230. package/dist/styles/shadow.js.map +1 -0
  231. package/dist/styles/shared.js +17 -0
  232. package/dist/styles/shared.js.map +1 -0
  233. package/dist/styles/transition.d.ts +14 -0
  234. package/dist/styles/transition.js +159 -0
  235. package/dist/styles/transition.js.map +1 -0
  236. package/dist/styles/types.d.ts +564 -0
  237. package/dist/styles/width.d.ts +17 -0
  238. package/dist/styles/width.js +19 -0
  239. package/dist/styles/width.js.map +1 -0
  240. package/dist/tasty.d.ts +134 -0
  241. package/dist/tasty.js +243 -0
  242. package/dist/tasty.js.map +1 -0
  243. package/dist/types.d.ts +184 -0
  244. package/dist/utils/cache-wrapper.js +21 -0
  245. package/dist/utils/cache-wrapper.js.map +1 -0
  246. package/dist/utils/case-converter.js +8 -0
  247. package/dist/utils/case-converter.js.map +1 -0
  248. package/dist/utils/color-math.d.ts +46 -0
  249. package/dist/utils/color-math.js +749 -0
  250. package/dist/utils/color-math.js.map +1 -0
  251. package/dist/utils/color-space.d.ts +5 -0
  252. package/dist/utils/color-space.js +228 -0
  253. package/dist/utils/color-space.js.map +1 -0
  254. package/dist/utils/colors.d.ts +5 -0
  255. package/dist/utils/colors.js +10 -0
  256. package/dist/utils/colors.js.map +1 -0
  257. package/dist/utils/css-types.d.ts +7 -0
  258. package/dist/utils/deps-equal.js +15 -0
  259. package/dist/utils/deps-equal.js.map +1 -0
  260. package/dist/utils/dotize.d.ts +26 -0
  261. package/dist/utils/dotize.js +122 -0
  262. package/dist/utils/dotize.js.map +1 -0
  263. package/dist/utils/filter-base-props.d.ts +15 -0
  264. package/dist/utils/filter-base-props.js +45 -0
  265. package/dist/utils/filter-base-props.js.map +1 -0
  266. package/dist/utils/get-display-name.d.ts +7 -0
  267. package/dist/utils/get-display-name.js +10 -0
  268. package/dist/utils/get-display-name.js.map +1 -0
  269. package/dist/utils/has-keys.js +13 -0
  270. package/dist/utils/has-keys.js.map +1 -0
  271. package/dist/utils/hash.js +14 -0
  272. package/dist/utils/hash.js.map +1 -0
  273. package/dist/utils/is-dev-env.js +19 -0
  274. package/dist/utils/is-dev-env.js.map +1 -0
  275. package/dist/utils/is-valid-element-type.js +15 -0
  276. package/dist/utils/is-valid-element-type.js.map +1 -0
  277. package/dist/utils/merge-styles.d.ts +7 -0
  278. package/dist/utils/merge-styles.js +145 -0
  279. package/dist/utils/merge-styles.js.map +1 -0
  280. package/dist/utils/mod-attrs.d.ts +6 -0
  281. package/dist/utils/mod-attrs.js +20 -0
  282. package/dist/utils/mod-attrs.js.map +1 -0
  283. package/dist/utils/process-tokens.d.ts +17 -0
  284. package/dist/utils/process-tokens.js +83 -0
  285. package/dist/utils/process-tokens.js.map +1 -0
  286. package/dist/utils/resolve-recipes.d.ts +17 -0
  287. package/dist/utils/resolve-recipes.js +146 -0
  288. package/dist/utils/resolve-recipes.js.map +1 -0
  289. package/dist/utils/selector-transform.js +32 -0
  290. package/dist/utils/selector-transform.js.map +1 -0
  291. package/dist/utils/string.js +8 -0
  292. package/dist/utils/string.js.map +1 -0
  293. package/dist/utils/styles.d.ts +99 -0
  294. package/dist/utils/styles.js +220 -0
  295. package/dist/utils/styles.js.map +1 -0
  296. package/dist/utils/typography.d.ts +58 -0
  297. package/dist/utils/typography.js +51 -0
  298. package/dist/utils/typography.js.map +1 -0
  299. package/dist/utils/warnings.d.ts +16 -0
  300. package/dist/utils/warnings.js +16 -0
  301. package/dist/utils/warnings.js.map +1 -0
  302. package/dist/zero/babel.d.ts +195 -0
  303. package/dist/zero/babel.js +456 -0
  304. package/dist/zero/babel.js.map +1 -0
  305. package/dist/zero/css-writer.d.ts +45 -0
  306. package/dist/zero/css-writer.js +73 -0
  307. package/dist/zero/css-writer.js.map +1 -0
  308. package/dist/zero/extractor.d.ts +24 -0
  309. package/dist/zero/extractor.js +266 -0
  310. package/dist/zero/extractor.js.map +1 -0
  311. package/dist/zero/index.d.ts +3 -0
  312. package/dist/zero/index.js +3 -0
  313. package/dist/zero/next.d.ts +86 -0
  314. package/dist/zero/next.js +143 -0
  315. package/dist/zero/next.js.map +1 -0
  316. package/docs/PIPELINE.md +519 -0
  317. package/docs/README.md +31 -0
  318. package/docs/adoption.md +298 -0
  319. package/docs/comparison.md +419 -0
  320. package/docs/configuration.md +389 -0
  321. package/docs/debug.md +318 -0
  322. package/docs/design-system.md +436 -0
  323. package/docs/dsl.md +688 -0
  324. package/docs/getting-started.md +217 -0
  325. package/docs/injector.md +544 -0
  326. package/docs/methodology.md +616 -0
  327. package/docs/react-api.md +557 -0
  328. package/docs/ssr.md +440 -0
  329. package/docs/styles.md +596 -0
  330. package/docs/tasty-static.md +532 -0
  331. package/package.json +221 -0
  332. package/tasty.config.ts +14 -0
@@ -0,0 +1,146 @@
1
+ import { isDevEnv } from "./is-dev-env.js";
2
+ import { isSelector } from "../pipeline/index.js";
3
+ import { getGlobalRecipes } from "../config.js";
4
+ import { mergeStyles } from "./merge-styles.js";
5
+ //#region src/utils/resolve-recipes.ts
6
+ /**
7
+ * Recipe resolution utility.
8
+ *
9
+ * Resolves `recipe` style properties by looking up predefined recipe styles
10
+ * from global configuration and merging them with the component's own styles.
11
+ *
12
+ * Resolution order per level (top-level and each sub-element independently):
13
+ * base_recipe_1 base_recipe_2 → component styles → post_recipe_1 post_recipe_2
14
+ *
15
+ * The `/` separator splits base recipes (before component styles)
16
+ * from post recipes (after component styles). All merges use mergeStyles
17
+ * semantics: primitives and state maps with '' key fully replace;
18
+ * state maps without '' key extend the existing value.
19
+ *
20
+ * Returns the same object reference if no recipes are present (zero overhead).
21
+ */
22
+ const devMode = isDevEnv();
23
+ /**
24
+ * Parse a recipe string into base and post recipe name groups.
25
+ *
26
+ * Syntax: `'base1 base2 / post1 post2'`
27
+ * - Names are space-separated within each group
28
+ * - `/` separates base (before component) from post (after component) groups
29
+ * - `/` is optional; if absent, all names are base
30
+ * - `none` as the sole base value means "no base recipes"
31
+ *
32
+ * Returns `{ base: null, post: null }` if the string is empty or invalid.
33
+ */
34
+ function parseRecipeNames(value) {
35
+ const empty = {
36
+ base: null,
37
+ post: null
38
+ };
39
+ if (typeof value !== "string") return empty;
40
+ const trimmed = value.trim();
41
+ if (trimmed === "") return empty;
42
+ const slashIndex = trimmed.indexOf("/");
43
+ if (slashIndex === -1) {
44
+ if (trimmed === "none") return empty;
45
+ return {
46
+ base: splitNames(trimmed),
47
+ post: null
48
+ };
49
+ }
50
+ const basePart = trimmed.slice(0, slashIndex);
51
+ const postPart = trimmed.slice(slashIndex + 1);
52
+ return {
53
+ base: basePart.trim() === "none" ? null : splitNames(basePart),
54
+ post: splitNames(postPart)
55
+ };
56
+ }
57
+ function splitNames(s) {
58
+ const names = s.split(/\s+/).filter(Boolean);
59
+ return names.length > 0 ? names : null;
60
+ }
61
+ /**
62
+ * Collect merged styles for a list of recipe names.
63
+ * Each recipe is flat-spread on top of the previous.
64
+ */
65
+ function collectRecipeStyles(names, recipes) {
66
+ let merged = {};
67
+ for (const name of names) {
68
+ const recipeStyles = recipes[name];
69
+ if (!recipeStyles) {
70
+ if (devMode) console.warn(`[Tasty] Recipe "${name}" not found. Make sure it is defined in configure({ recipes: { ... } }).`);
71
+ continue;
72
+ }
73
+ merged = {
74
+ ...merged,
75
+ ...recipeStyles
76
+ };
77
+ }
78
+ return merged;
79
+ }
80
+ /**
81
+ * Resolve recipe references in a flat styles object (no sub-elements).
82
+ * Returns null if no `recipe` key is present.
83
+ *
84
+ * Resolution: base recipes → component styles → post recipes (all via mergeStyles)
85
+ */
86
+ function resolveRecipesForLevel(styles, recipes) {
87
+ if (!("recipe" in styles)) return null;
88
+ const { base, post } = parseRecipeNames(styles.recipe);
89
+ const { recipe: _recipe, ...allRest } = styles;
90
+ const flatStyles = {};
91
+ const selectorStyles = {};
92
+ for (const key of Object.keys(allRest)) if (isSelector(key)) selectorStyles[key] = allRest[key];
93
+ else flatStyles[key] = allRest[key];
94
+ if (!base && !post) return allRest;
95
+ let result;
96
+ if (base) result = mergeStyles(collectRecipeStyles(base, recipes), flatStyles);
97
+ else result = { ...flatStyles };
98
+ if (post) {
99
+ const postStyles = collectRecipeStyles(post, recipes);
100
+ result = mergeStyles(result, postStyles);
101
+ }
102
+ for (const key of Object.keys(selectorStyles)) result[key] = selectorStyles[key];
103
+ return result;
104
+ }
105
+ /**
106
+ * Resolve all `recipe` style properties in a styles object.
107
+ *
108
+ * Handles both top-level and sub-element recipe references.
109
+ * Returns the same object reference if no recipes are present anywhere
110
+ * (zero overhead for the common case).
111
+ *
112
+ * @param styles - The styles object potentially containing `recipe` keys
113
+ * @returns Resolved styles with recipe values merged in, or the original object if unchanged
114
+ */
115
+ function resolveRecipes(styles) {
116
+ const recipes = getGlobalRecipes();
117
+ if (!recipes) return styles;
118
+ let changed = false;
119
+ const topResolved = resolveRecipesForLevel(styles, recipes);
120
+ let result;
121
+ if (topResolved) {
122
+ changed = true;
123
+ result = topResolved;
124
+ } else result = styles;
125
+ const keys = Object.keys(result);
126
+ for (const key of keys) {
127
+ if (!isSelector(key)) continue;
128
+ const subStyles = result[key];
129
+ if (!subStyles || typeof subStyles !== "object" || Array.isArray(subStyles)) continue;
130
+ const subRecord = subStyles;
131
+ if (!("recipe" in subRecord)) continue;
132
+ const subResolved = resolveRecipesForLevel(subRecord, recipes);
133
+ if (subResolved) {
134
+ if (!changed) {
135
+ changed = true;
136
+ result = { ...styles };
137
+ }
138
+ result[key] = subResolved;
139
+ }
140
+ }
141
+ return changed ? result : styles;
142
+ }
143
+ //#endregion
144
+ export { resolveRecipes };
145
+
146
+ //# sourceMappingURL=resolve-recipes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-recipes.js","names":[],"sources":["../../src/utils/resolve-recipes.ts"],"sourcesContent":["/**\n * Recipe resolution utility.\n *\n * Resolves `recipe` style properties by looking up predefined recipe styles\n * from global configuration and merging them with the component's own styles.\n *\n * Resolution order per level (top-level and each sub-element independently):\n * base_recipe_1 base_recipe_2 → component styles → post_recipe_1 post_recipe_2\n *\n * The `/` separator splits base recipes (before component styles)\n * from post recipes (after component styles). All merges use mergeStyles\n * semantics: primitives and state maps with '' key fully replace;\n * state maps without '' key extend the existing value.\n *\n * Returns the same object reference if no recipes are present (zero overhead).\n */\n\nimport { getGlobalRecipes } from '../config';\nimport { isSelector } from '../pipeline';\nimport type { RecipeStyles, Styles } from '../styles/types';\n\nimport { isDevEnv } from './is-dev-env';\nimport { mergeStyles } from './merge-styles';\n\nconst devMode = isDevEnv();\n\ninterface ParsedRecipeGroups {\n base: string[] | null;\n post: string[] | null;\n}\n\n/**\n * Parse a recipe string into base and post recipe name groups.\n *\n * Syntax: `'base1 base2 / post1 post2'`\n * - Names are space-separated within each group\n * - `/` separates base (before component) from post (after component) groups\n * - `/` is optional; if absent, all names are base\n * - `none` as the sole base value means \"no base recipes\"\n *\n * Returns `{ base: null, post: null }` if the string is empty or invalid.\n */\nfunction parseRecipeNames(value: unknown): ParsedRecipeGroups {\n const empty: ParsedRecipeGroups = { base: null, post: null };\n\n if (typeof value !== 'string') return empty;\n const trimmed = value.trim();\n if (trimmed === '') return empty;\n\n const slashIndex = trimmed.indexOf('/');\n\n if (slashIndex === -1) {\n if (trimmed === 'none') return empty;\n const names = splitNames(trimmed);\n return { base: names, post: null };\n }\n\n const basePart = trimmed.slice(0, slashIndex);\n const postPart = trimmed.slice(slashIndex + 1);\n\n return {\n base: basePart.trim() === 'none' ? null : splitNames(basePart),\n post: splitNames(postPart),\n };\n}\n\nfunction splitNames(s: string): string[] | null {\n const names = s.split(/\\s+/).filter(Boolean);\n return names.length > 0 ? names : null;\n}\n\n/**\n * Collect merged styles for a list of recipe names.\n * Each recipe is flat-spread on top of the previous.\n */\nfunction collectRecipeStyles(\n names: string[],\n recipes: Record<string, RecipeStyles>,\n): Record<string, unknown> {\n let merged: Record<string, unknown> = {};\n\n for (const name of names) {\n const recipeStyles = recipes[name];\n\n if (!recipeStyles) {\n if (devMode) {\n console.warn(\n `[Tasty] Recipe \"${name}\" not found. ` +\n `Make sure it is defined in configure({ recipes: { ... } }).`,\n );\n }\n continue;\n }\n\n merged = { ...merged, ...(recipeStyles as Record<string, unknown>) };\n }\n\n return merged;\n}\n\n/**\n * Resolve recipe references in a flat styles object (no sub-elements).\n * Returns null if no `recipe` key is present.\n *\n * Resolution: base recipes → component styles → post recipes (all via mergeStyles)\n */\nfunction resolveRecipesForLevel(\n styles: Record<string, unknown>,\n recipes: Record<string, RecipeStyles>,\n): Record<string, unknown> | null {\n if (!('recipe' in styles)) return null;\n\n const { base, post } = parseRecipeNames(styles.recipe);\n\n // Separate selector keys (sub-elements) from flat style properties.\n // mergeStyles handles selectors with its own semantics (e.g. false = delete),\n // but at this level we only want recipe merging on flat properties.\n\n const { recipe: _recipe, ...allRest } = styles;\n const flatStyles: Record<string, unknown> = {};\n const selectorStyles: Record<string, unknown> = {};\n\n for (const key of Object.keys(allRest)) {\n if (isSelector(key)) {\n selectorStyles[key] = allRest[key];\n } else {\n flatStyles[key] = allRest[key];\n }\n }\n\n if (!base && !post) {\n return allRest;\n }\n\n // 1. Merge base recipes, then component styles on top (via mergeStyles)\n let result: Record<string, unknown>;\n\n if (base) {\n const baseStyles = collectRecipeStyles(base, recipes);\n result = mergeStyles(baseStyles as Styles, flatStyles as Styles) as Record<\n string,\n unknown\n >;\n } else {\n result = { ...flatStyles };\n }\n\n // 2. Apply post recipes via mergeStyles (state map extend semantics)\n if (post) {\n const postStyles = collectRecipeStyles(post, recipes);\n result = mergeStyles(result as Styles, postStyles as Styles) as Record<\n string,\n unknown\n >;\n }\n\n // Re-attach selector keys unchanged\n for (const key of Object.keys(selectorStyles)) {\n result[key] = selectorStyles[key];\n }\n\n return result;\n}\n\n/**\n * Resolve all `recipe` style properties in a styles object.\n *\n * Handles both top-level and sub-element recipe references.\n * Returns the same object reference if no recipes are present anywhere\n * (zero overhead for the common case).\n *\n * @param styles - The styles object potentially containing `recipe` keys\n * @returns Resolved styles with recipe values merged in, or the original object if unchanged\n */\nexport function resolveRecipes(styles: Styles): Styles {\n const recipes = getGlobalRecipes();\n\n // Fast path: no recipes configured globally\n if (!recipes) return styles;\n\n let changed = false;\n\n // Resolve top-level recipe\n const topResolved = resolveRecipesForLevel(\n styles as Record<string, unknown>,\n recipes,\n );\n\n let result: Record<string, unknown>;\n\n if (topResolved) {\n changed = true;\n result = topResolved;\n } else {\n // Keep reference; a shallow copy is deferred until a sub-element actually changes\n result = styles as Record<string, unknown>;\n }\n\n // Resolve sub-element recipes\n const keys = Object.keys(result);\n\n for (const key of keys) {\n if (!isSelector(key)) continue;\n\n const subStyles = result[key];\n\n if (\n !subStyles ||\n typeof subStyles !== 'object' ||\n Array.isArray(subStyles)\n ) {\n continue;\n }\n\n const subRecord = subStyles as Record<string, unknown>;\n\n if (!('recipe' in subRecord)) continue;\n\n const subResolved = resolveRecipesForLevel(subRecord, recipes);\n\n if (subResolved) {\n if (!changed) {\n // First change in sub-elements -- need to shallow-copy the top level\n changed = true;\n result = { ...(styles as Record<string, unknown>) };\n }\n result[key] = subResolved;\n }\n }\n\n return changed ? (result as Styles) : styles;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,UAAU,UAAU;;;;;;;;;;;;AAkB1B,SAAS,iBA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KAAI,CAAC,QAAQ,CAAC,KACZ,QAAO;CAIT,IAAI;AAEJ,KAAI,KAEF,UAAS,YADU,oBAAoB,MAAM,QAAQ,EACV,WAAqB;KAKhE,UAAS,EAAE,GAAG,YAAY;AAI5B,KAAI,MAAM;EACR,MAAM,aAAa,oBAAoB,MAAM,QAAQ;AACrD,WAAS,YAAY,QAAkB,WAAqB;;AAO9D,MAAK,MAAM,OAAO,OAAO,KAAK,eAAe,CAC3C,QAAO,OAAO,eAAe;AAG/B,QAAO;;;;;;;;;;;;AAaT,SAAgB,eAAe,QAAwB;CACrD,MAAM,UAAU,kBAAkB;AAGlC,KAAI,CAAC,QAAS,QAAO;CAErB,IAAI,UAAU;CAGd,MAAM,cAAc,uBAClB,QACA,QACD;CAED,IAAI;AAEJ,KAAI,aAAa;AACf,YAAU;AACV,WAAS;OAGT,UAAS;CAIX,MAAM,OAAO,OAAO,KAAK,OAAO;AAEhC,MAAK,MAAM,OAAO,MAAM;AACtB,MAAI,CAAC,WAAW,IAAI,CAAE;EAEtB,MAAM,YAAY,OAAO;AAEzB,MACE,CAAC,aACD,OAAO,cAAc,YACrB,MAAM,QAAQ,UAAU,CAExB;EAGF,MAAM,YAAY;AAElB,MAAI,EAAE,YAAY,WAAY;EAE9B,MAAM,cAAc,uBAAuB,WAAW,QAAQ;AAE9D,MAAI,aAAa;AACf,OAAI,CAAC,SAAS;AAEZ,cAAU;AACV,aAAS,EAAE,GAAI,QAAoC;;AAErD,UAAO,OAAO;;;AAIlB,QAAO,UAAW,SAAoB"}
@@ -0,0 +1,32 @@
1
+ //#region src/utils/selector-transform.ts
2
+ /**
3
+ * Shared utility for transforming capitalized PascalCase element names
4
+ * in CSS selector content to `[data-element="..."]` attribute selectors.
5
+ *
6
+ * Lowercase words are treated as HTML tags and left unchanged.
7
+ */
8
+ /**
9
+ * Matches a capitalized PascalCase word at the start of the string
10
+ * or after a CSS combinator/separator character.
11
+ */
12
+ const ELEMENT_NAME_RE = /(^|[\s>+~,(])([A-Z][a-zA-Z0-9]*)/g;
13
+ /**
14
+ * Replace capitalized PascalCase words with `[data-element="Name"]` selectors.
15
+ *
16
+ * @example
17
+ * transformSelectorContent('> Field + input:checked')
18
+ * // → '> [data-element="Field"] + input:checked'
19
+ *
20
+ * transformSelectorContent('Body > Row')
21
+ * // → '[data-element="Body"] > [data-element="Row"]'
22
+ *
23
+ * transformSelectorContent('button')
24
+ * // → 'button' (lowercase = HTML tag, unchanged)
25
+ */
26
+ function transformSelectorContent(content) {
27
+ return content.replace(ELEMENT_NAME_RE, (_, prefix, name) => `${prefix}[data-element="${name}"]`);
28
+ }
29
+ //#endregion
30
+ export { transformSelectorContent };
31
+
32
+ //# sourceMappingURL=selector-transform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selector-transform.js","names":[],"sources":["../../src/utils/selector-transform.ts"],"sourcesContent":["/**\n * Shared utility for transforming capitalized PascalCase element names\n * in CSS selector content to `[data-element=\"...\"]` attribute selectors.\n *\n * Lowercase words are treated as HTML tags and left unchanged.\n */\n\n/**\n * Matches a capitalized PascalCase word at the start of the string\n * or after a CSS combinator/separator character.\n */\nconst ELEMENT_NAME_RE = /(^|[\\s>+~,(])([A-Z][a-zA-Z0-9]*)/g;\n\n/**\n * Replace capitalized PascalCase words with `[data-element=\"Name\"]` selectors.\n *\n * @example\n * transformSelectorContent('> Field + input:checked')\n * // → '> [data-element=\"Field\"] + input:checked'\n *\n * transformSelectorContent('Body > Row')\n * // → '[data-element=\"Body\"] > [data-element=\"Row\"]'\n *\n * transformSelectorContent('button')\n * // → 'button' (lowercase = HTML tag, unchanged)\n */\nexport function transformSelectorContent(content: string): string {\n return content.replace(\n ELEMENT_NAME_RE,\n (_, prefix, name) => `${prefix}[data-element=\"${name}\"]`,\n );\n}\n"],"mappings":";;;;;;;;;;;AAWA,MAAM,kBAAkB;;;;;;;;;;;;;;AAexB,SAAgB,yBAAyB,SAAyB;AAChE,QAAO,QAAQ,QACb,kBACC,GAAG,QAAQ,SAAS,GAAG,OAAO,iBAAiB,KAAK,IACtD"}
@@ -0,0 +1,8 @@
1
+ //#region src/utils/string.ts
2
+ function toSnakeCase(str) {
3
+ return str.replace(/[A-Z]/g, (s) => `-${s.toLowerCase()}`);
4
+ }
5
+ //#endregion
6
+ export { toSnakeCase };
7
+
8
+ //# sourceMappingURL=string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.js","names":[],"sources":["../../src/utils/string.ts"],"sourcesContent":["export function toSnakeCase(str: string): string {\n return str.replace(/[A-Z]/g, (s) => `-${s.toLowerCase()}`);\n}\n"],"mappings":";AAAA,SAAgB,YAAY,KAAqB;AAC/C,QAAO,IAAI,QAAQ,WAAW,MAAM,IAAI,EAAE,aAAa,GAAG"}
@@ -0,0 +1,99 @@
1
+ import { ProcessedStyle, StyleDetails } from "../parser/types.js";
2
+ import { StyleParser } from "../parser/parser.js";
3
+ import { getNamedColorHex, getRgbValuesFromRgbaString, hexToRgb, strToRgb } from "./color-math.js";
4
+
5
+ //#region src/utils/styles.d.ts
6
+ type StyleValue<T = string> = T | boolean | number | null | undefined;
7
+ /**
8
+ * Normalize a color token value.
9
+ * - Boolean `true` is converted to `'transparent'`
10
+ * - Boolean `false` returns `null` (signals the token should be skipped)
11
+ * - Other values are returned as-is
12
+ *
13
+ * @param value - The raw token value
14
+ * @returns Normalized value or null if the token should be skipped
15
+ */
16
+ declare function normalizeColorTokenValue<T>(value: T | boolean): T | 'transparent' | null;
17
+ type StyleValueStateMap<T = string> = Record<string, StyleValue<T> | '@inherit'>;
18
+ /**
19
+ * Combined type for style values that can be either a direct value or a state map.
20
+ * Use this for component props that accept style values.
21
+ */
22
+ type StylePropValue<T = string> = StyleValue<T> | StyleValueStateMap<T>;
23
+ type CSSMap = {
24
+ $?: string | string[];
25
+ } & Record<string, string | string[]>;
26
+ type StyleHandlerResult = CSSMap | CSSMap[] | null | void;
27
+ type RawStyleHandler = (value: StyleValueStateMap) => StyleHandlerResult;
28
+ type StyleHandler = RawStyleHandler & {
29
+ __lookupStyles: string[];
30
+ };
31
+ /**
32
+ * Handler definition forms for configure() and plugins.
33
+ * - Function only: lookup styles inferred from key name
34
+ * - Single property tuple: ['styleName', handler]
35
+ * - Multi-property tuple: [['style1', 'style2'], handler]
36
+ */
37
+ type StyleHandlerDefinition = RawStyleHandler | [string, RawStyleHandler] | [string[], RawStyleHandler];
38
+ interface ParsedColor {
39
+ color?: string;
40
+ name?: string;
41
+ opacity?: number;
42
+ }
43
+ type StyleMap = Record<string, StyleValue | StyleValueStateMap>;
44
+ declare const CUSTOM_UNITS: {
45
+ r: string;
46
+ cr: string;
47
+ bw: string;
48
+ ow: string;
49
+ x: string;
50
+ sf: (num: number) => string;
51
+ };
52
+ declare const DIRECTIONS: string[];
53
+ declare function customFunc(name: string, fn: (groups: StyleDetails[]) => string): void;
54
+ /**
55
+ * Get the global StyleParser instance.
56
+ * Used by configure() to apply parser configuration.
57
+ */
58
+ declare function getGlobalParser(): StyleParser;
59
+ /**
60
+ * Get the current custom functions registry.
61
+ * Used by configure() to merge with new functions.
62
+ */
63
+ declare function getGlobalFuncs(): Record<string, (groups: StyleDetails[]) => string>;
64
+ /**
65
+ * Set global predefined tokens.
66
+ * Called from configure() after processing token values.
67
+ * Merges with existing tokens (new tokens override existing ones with same key).
68
+ * Keys are normalized to lowercase (parser lowercases input before classification).
69
+ * @internal
70
+ */
71
+ declare function setGlobalPredefinedTokens(tokens: Record<string, string>): void;
72
+ /**
73
+ * Get the current global predefined tokens.
74
+ * Returns null if no tokens are configured.
75
+ */
76
+ declare function getGlobalPredefinedTokens(): Record<string, string> | null;
77
+ /**
78
+ * Reset global predefined tokens.
79
+ * Used for testing.
80
+ * @internal
81
+ */
82
+ declare function resetGlobalPredefinedTokens(): void;
83
+ /**
84
+ *
85
+ * @param {String} value
86
+ * @param {Number} mode
87
+ * @returns {Object<String,String|Array>}
88
+ */
89
+ declare function parseStyle(value: StyleValue): ProcessedStyle;
90
+ /**
91
+ * Parse color. Find it value, name and opacity.
92
+ * Optimized to avoid heavy parseStyle calls for simple color patterns.
93
+ */
94
+ declare function parseColor(val: string, ignoreError?: boolean): ParsedColor;
95
+ declare function filterMods(mods: string[], allowedMods: string[]): string[];
96
+ declare function stringifyStyles(styles: unknown): string;
97
+ //#endregion
98
+ export { CSSMap, CUSTOM_UNITS, DIRECTIONS, ParsedColor, RawStyleHandler, StyleHandler, StyleHandlerDefinition, StyleHandlerResult, StyleMap, StylePropValue, StyleValue, StyleValueStateMap, customFunc, filterMods, getGlobalFuncs, getGlobalParser, getGlobalPredefinedTokens, normalizeColorTokenValue, parseColor, parseStyle, resetGlobalPredefinedTokens, setGlobalPredefinedTokens, stringifyStyles };
99
+ //# sourceMappingURL=styles.d.ts.map
@@ -0,0 +1,220 @@
1
+ import { getNamedColorHex } from "./color-math.js";
2
+ import { StyleParser } from "../parser/parser.js";
3
+ import { okhslFunc } from "../plugins/okhsl-plugin.js";
4
+ //#region src/utils/styles.ts
5
+ /**
6
+ * Normalize a color token value.
7
+ * - Boolean `true` is converted to `'transparent'`
8
+ * - Boolean `false` returns `null` (signals the token should be skipped)
9
+ * - Other values are returned as-is
10
+ *
11
+ * @param value - The raw token value
12
+ * @returns Normalized value or null if the token should be skipped
13
+ */
14
+ function normalizeColorTokenValue(value) {
15
+ if (value === true) return "transparent";
16
+ if (value === false) return null;
17
+ return value;
18
+ }
19
+ const COLOR_VAR_PATTERN = /var\(--([a-z0-9-]+)-color/;
20
+ const COLOR_VAR_COMPONENTS_PATTERN = /var\(--([a-z0-9-]+)-color-(?:rgb|hsl|oklch)/;
21
+ const RGB_ALPHA_PATTERN = /\/\s*([0-9.]+)\)/;
22
+ const RE_HEX_COLOR = /^#[0-9a-fA-F]{3,8}$/;
23
+ const RE_VAR_COLOR = /^var\(--[a-z0-9-]+-color/;
24
+ function isSimpleColorFast(val) {
25
+ switch (val.charCodeAt(0)) {
26
+ case 35: return RE_HEX_COLOR.test(val);
27
+ case 114: return val.charCodeAt(1) === 103 && val.charCodeAt(2) === 98;
28
+ case 104: return val.charCodeAt(1) === 115 && val.charCodeAt(2) === 108;
29
+ case 108: return val.charCodeAt(1) === 99 && val.charCodeAt(2) === 104;
30
+ case 111: return val.startsWith("oklch(") || val.startsWith("okhsl(");
31
+ case 118: return RE_VAR_COLOR.test(val);
32
+ case 99: return val === "currentColor" || val === "currentcolor";
33
+ case 116: return val === "transparent";
34
+ default: return getNamedColorHex().has(val.toLowerCase());
35
+ }
36
+ }
37
+ let colorWarningCount = 0;
38
+ const MAX_COLOR_WARNINGS = 10;
39
+ const CUSTOM_UNITS = {
40
+ r: "6px",
41
+ cr: "10px",
42
+ bw: "1px",
43
+ ow: "3px",
44
+ x: "8px",
45
+ sf: function sf(num) {
46
+ return `minmax(0, ${num}fr)`;
47
+ }
48
+ };
49
+ const DIRECTIONS = [
50
+ "top",
51
+ "right",
52
+ "bottom",
53
+ "left"
54
+ ];
55
+ let __tastyParser = null;
56
+ function getOrCreateParser() {
57
+ if (!__tastyParser) {
58
+ __tastyParser = new StyleParser({ units: CUSTOM_UNITS });
59
+ __tastyParser.setFuncs(__tastyFuncs);
60
+ }
61
+ return __tastyParser;
62
+ }
63
+ const __tastyFuncs = { okhsl: okhslFunc };
64
+ function customFunc(name, fn) {
65
+ __tastyFuncs[name] = fn;
66
+ getOrCreateParser().setFuncs(__tastyFuncs);
67
+ }
68
+ /**
69
+ * Get the global StyleParser instance.
70
+ * Used by configure() to apply parser configuration.
71
+ */
72
+ function getGlobalParser() {
73
+ return getOrCreateParser();
74
+ }
75
+ /**
76
+ * Get the current custom functions registry.
77
+ * Used by configure() to merge with new functions.
78
+ */
79
+ function getGlobalFuncs() {
80
+ return __tastyFuncs;
81
+ }
82
+ /**
83
+ * Storage for predefined tokens that are replaced during style parsing.
84
+ * Keys are token names (with $ or # prefix), values are pre-processed CSS values.
85
+ */
86
+ let __globalPredefinedTokens = null;
87
+ /**
88
+ * Set global predefined tokens.
89
+ * Called from configure() after processing token values.
90
+ * Merges with existing tokens (new tokens override existing ones with same key).
91
+ * Keys are normalized to lowercase (parser lowercases input before classification).
92
+ * @internal
93
+ */
94
+ function setGlobalPredefinedTokens(tokens) {
95
+ const normalizedTokens = {};
96
+ for (const [key, value] of Object.entries(tokens)) {
97
+ const lowerKey = key.toLowerCase();
98
+ const lowerValue = value.toLowerCase();
99
+ if (lowerKey.startsWith("#") && lowerValue === "#current") {
100
+ console.warn(`Tasty: Using #current to define color token "${key}" is not supported. The #current token represents currentcolor which cannot be used as a base for other tokens.`);
101
+ continue;
102
+ }
103
+ normalizedTokens[lowerKey] = value;
104
+ }
105
+ __globalPredefinedTokens = __globalPredefinedTokens ? {
106
+ ...__globalPredefinedTokens,
107
+ ...normalizedTokens
108
+ } : normalizedTokens;
109
+ getOrCreateParser().clearCache();
110
+ }
111
+ /**
112
+ * Get the current global predefined tokens.
113
+ * Returns null if no tokens are configured.
114
+ */
115
+ function getGlobalPredefinedTokens() {
116
+ return __globalPredefinedTokens;
117
+ }
118
+ /**
119
+ * Reset global predefined tokens.
120
+ * Used for testing.
121
+ * @internal
122
+ */
123
+ function resetGlobalPredefinedTokens() {
124
+ __globalPredefinedTokens = null;
125
+ getOrCreateParser().clearCache();
126
+ }
127
+ /**
128
+ *
129
+ * @param {String} value
130
+ * @param {Number} mode
131
+ * @returns {Object<String,String|Array>}
132
+ */
133
+ function parseStyle(value) {
134
+ let str;
135
+ if (typeof value === "string") str = value;
136
+ else if (typeof value === "number") str = String(value);
137
+ else str = "";
138
+ return getOrCreateParser().process(str);
139
+ }
140
+ /**
141
+ * Parse color. Find it value, name and opacity.
142
+ * Optimized to avoid heavy parseStyle calls for simple color patterns.
143
+ */
144
+ function parseColor(val, ignoreError = false) {
145
+ if (typeof val !== "string") val = String(val ?? "");
146
+ val = val.trim();
147
+ if (!val) return {};
148
+ const isSimpleColor = isSimpleColorFast(val);
149
+ let firstColor;
150
+ if (isSimpleColor) firstColor = val;
151
+ else {
152
+ const extractedColor = parseStyle(val).groups.find((g) => g.colors.length)?.colors[0];
153
+ if (!extractedColor) {
154
+ if (!ignoreError && colorWarningCount < MAX_COLOR_WARNINGS) {
155
+ console.warn("Tasty: unable to parse color:", val);
156
+ colorWarningCount++;
157
+ if (colorWarningCount === MAX_COLOR_WARNINGS) console.warn("Tasty: color parsing warnings will be suppressed from now on");
158
+ }
159
+ return {};
160
+ }
161
+ firstColor = extractedColor;
162
+ }
163
+ let nameMatch = firstColor.match(COLOR_VAR_PATTERN);
164
+ if (!nameMatch) nameMatch = firstColor.match(COLOR_VAR_COMPONENTS_PATTERN);
165
+ let opacity;
166
+ if (firstColor.startsWith("rgb") || firstColor.startsWith("hsl") || firstColor.startsWith("lch") || firstColor.startsWith("oklch") || firstColor.startsWith("okhsl")) {
167
+ const alphaMatch = firstColor.match(RGB_ALPHA_PATTERN);
168
+ if (alphaMatch) {
169
+ const v = parseFloat(alphaMatch[1]);
170
+ if (!isNaN(v)) opacity = v * 100;
171
+ }
172
+ }
173
+ return {
174
+ color: firstColor,
175
+ name: nameMatch ? nameMatch[1] : void 0,
176
+ opacity
177
+ };
178
+ }
179
+ function filterMods(mods, allowedMods) {
180
+ return mods.filter((mod) => allowedMods.includes(mod));
181
+ }
182
+ const _innerCache = /* @__PURE__ */ new WeakMap();
183
+ const _topLevelCache = /* @__PURE__ */ new WeakMap();
184
+ function stringifyStyles(styles) {
185
+ if (styles == null || typeof styles !== "object") return "";
186
+ const cached = _topLevelCache.get(styles);
187
+ if (cached !== void 0) return cached;
188
+ const obj = styles;
189
+ const keys = Object.keys(obj).sort();
190
+ const parts = [];
191
+ for (const k of keys) {
192
+ const v = obj[k];
193
+ if (v === void 0 || typeof v === "function" || typeof v === "symbol") continue;
194
+ const c0 = k.charCodeAt(0);
195
+ const needsInnerSort = (c0 >= 65 && c0 <= 90 || c0 === 38) && v && typeof v === "object" && !Array.isArray(v);
196
+ let sv;
197
+ if (needsInnerSort) {
198
+ sv = _innerCache.get(v);
199
+ if (sv === void 0) {
200
+ const innerObj = v;
201
+ const innerKeys = Object.keys(innerObj).sort();
202
+ const innerParts = [];
203
+ for (const ik of innerKeys) {
204
+ const ivs = JSON.stringify(innerObj[ik]);
205
+ if (ivs !== void 0) innerParts.push(JSON.stringify(ik) + ":" + ivs);
206
+ }
207
+ sv = "{" + innerParts.join(",") + "}";
208
+ _innerCache.set(v, sv);
209
+ }
210
+ } else sv = JSON.stringify(v);
211
+ parts.push(JSON.stringify(k) + ":" + sv);
212
+ }
213
+ const result = "{" + parts.join(",") + "}";
214
+ _topLevelCache.set(styles, result);
215
+ return result;
216
+ }
217
+ //#endregion
218
+ export { CUSTOM_UNITS, DIRECTIONS, customFunc, filterMods, getGlobalFuncs, getGlobalParser, getGlobalPredefinedTokens, normalizeColorTokenValue, parseColor, parseStyle, resetGlobalPredefinedTokens, setGlobalPredefinedTokens, stringifyStyles };
219
+
220
+ //# sourceMappingURL=styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.js","names":[],"sources":["../../src/utils/styles.ts"],"sourcesContent":["import { StyleParser } from '../parser/parser';\nimport { okhslFunc } from '../plugins/okhsl-plugin';\n\nimport type { ProcessedStyle, StyleDetails } from '../parser/types';\n\nimport { getNamedColorHex } from './color-math';\n\nexport {\n getNamedColorHex,\n getRgbValuesFromRgbaString,\n hexToRgb,\n strToRgb,\n} from './color-math';\n\nexport type StyleValue<T = string> = T | boolean | number | null | undefined;\n\n/**\n * Normalize a color token value.\n * - Boolean `true` is converted to `'transparent'`\n * - Boolean `false` returns `null` (signals the token should be skipped)\n * - Other values are returned as-is\n *\n * @param value - The raw token value\n * @returns Normalized value or null if the token should be skipped\n */\nexport function normalizeColorTokenValue<T>(\n value: T | boolean,\n): T | 'transparent' | null {\n if (value === true) {\n return 'transparent';\n }\n if (value === false) {\n return null;\n }\n return value as T;\n}\n\nexport type StyleValueStateMap<T = string> = Record<\n string,\n StyleValue<T> | '@inherit'\n>;\n\n/**\n * Combined type for style values that can be either a direct value or a state map.\n * Use this for component props that accept style values.\n */\nexport type StylePropValue<T = string> = StyleValue<T> | StyleValueStateMap<T>;\n\nexport type CSSMap = { $?: string | string[] } & Record<\n string,\n string | string[]\n>;\n\nexport type StyleHandlerResult = CSSMap | CSSMap[] | null | void;\n\nexport type RawStyleHandler = (value: StyleValueStateMap) => StyleHandlerResult;\n\nexport type StyleHandler = RawStyleHandler & {\n __lookupStyles: string[];\n};\n\n/**\n * Handler definition forms for configure() and plugins.\n * - Function only: lookup styles inferred from key name\n * - Single property tuple: ['styleName', handler]\n * - Multi-property tuple: [['style1', 'style2'], handler]\n */\nexport type StyleHandlerDefinition =\n | RawStyleHandler\n | [string, RawStyleHandler]\n | [string[], RawStyleHandler];\n\nexport interface ParsedColor {\n color?: string;\n name?: string;\n opacity?: number;\n}\n\nexport type StyleMap = Record<string, StyleValue | StyleValueStateMap>;\n\nconst devMode = process.env.NODE_ENV !== 'production';\n\n// Precompiled regex patterns for parseColor optimization\n// Match var(--name-color...) and extract the name, regardless of fallbacks\nconst COLOR_VAR_PATTERN = /var\\(--([a-z0-9-]+)-color/;\nconst COLOR_VAR_COMPONENTS_PATTERN =\n /var\\(--([a-z0-9-]+)-color-(?:rgb|hsl|oklch)/;\nconst RGB_ALPHA_PATTERN = /\\/\\s*([0-9.]+)\\)/;\nconst RE_HEX_COLOR = /^#[0-9a-fA-F]{3,8}$/;\nconst RE_VAR_COLOR = /^var\\(--[a-z0-9-]+-color/;\n\nfunction isSimpleColorFast(val: string): boolean {\n const c0 = val.charCodeAt(0);\n\n switch (c0) {\n case 35: // '#'\n return RE_HEX_COLOR.test(val);\n case 114: // 'r'\n return val.charCodeAt(1) === 103 && val.charCodeAt(2) === 98; // 'rgb'\n case 104: // 'h'\n return val.charCodeAt(1) === 115 && val.charCodeAt(2) === 108; // 'hsl'\n case 108: // 'l'\n return val.charCodeAt(1) === 99 && val.charCodeAt(2) === 104; // 'lch'\n case 111: // 'o'\n return val.startsWith('oklch(') || val.startsWith('okhsl(');\n case 118: // 'v'\n return RE_VAR_COLOR.test(val);\n case 99: // 'c'\n return val === 'currentColor' || val === 'currentcolor';\n case 116: // 't'\n return val === 'transparent';\n default:\n return getNamedColorHex().has(val.toLowerCase());\n }\n}\n\n// Rate limiting for dev warnings to avoid spam\nlet colorWarningCount = 0;\nconst MAX_COLOR_WARNINGS = 10;\n\nexport const CUSTOM_UNITS = {\n r: '6px',\n cr: '10px',\n bw: '1px',\n ow: '3px',\n x: '8px',\n sf: function sf(num: number) {\n return `minmax(0, ${num}fr)`;\n },\n};\n\nexport const DIRECTIONS = ['top', 'right', 'bottom', 'left'];\n\n// Lazy-initialized to break the circular dependency:\n// parser.ts → classify.ts → utils/styles.ts → parser.ts\nlet __tastyParser: StyleParser | null = null;\n\nfunction getOrCreateParser(): StyleParser {\n if (!__tastyParser) {\n __tastyParser = new StyleParser({ units: CUSTOM_UNITS });\n __tastyParser.setFuncs(__tastyFuncs);\n }\n return __tastyParser;\n}\n\n// Registry for user-provided custom functions that the parser can call.\n// It is updated through the `customFunc` helper exported below.\n// okhsl is registered as a built-in function so it works regardless of\n// tree-shaking or module initialization order.\nconst __tastyFuncs: Record<string, (groups: StyleDetails[]) => string> = {\n okhsl: okhslFunc,\n};\n\nexport function customFunc(\n name: string,\n fn: (groups: StyleDetails[]) => string,\n) {\n __tastyFuncs[name] = fn;\n getOrCreateParser().setFuncs(__tastyFuncs);\n}\n\n/**\n * Get the global StyleParser instance.\n * Used by configure() to apply parser configuration.\n */\nexport function getGlobalParser(): StyleParser {\n return getOrCreateParser();\n}\n\n/**\n * Get the current custom functions registry.\n * Used by configure() to merge with new functions.\n */\nexport function getGlobalFuncs(): Record<\n string,\n (groups: StyleDetails[]) => string\n> {\n return __tastyFuncs;\n}\n\n// ============================================================================\n// Global Predefined Tokens\n// ============================================================================\n\n/**\n * Storage for predefined tokens that are replaced during style parsing.\n * Keys are token names (with $ or # prefix), values are pre-processed CSS values.\n */\nlet __globalPredefinedTokens: Record<string, string> | null = null;\n\n/**\n * Set global predefined tokens.\n * Called from configure() after processing token values.\n * Merges with existing tokens (new tokens override existing ones with same key).\n * Keys are normalized to lowercase (parser lowercases input before classification).\n * @internal\n */\nexport function setGlobalPredefinedTokens(\n tokens: Record<string, string>,\n): void {\n // Normalize keys to lowercase for case-insensitive matching\n const normalizedTokens: Record<string, string> = {};\n for (const [key, value] of Object.entries(tokens)) {\n const lowerKey = key.toLowerCase();\n const lowerValue = value.toLowerCase();\n\n // Warn if trying to use bare #current to define other color tokens\n // #current represents currentcolor which cannot be used as a base for recursive token resolution\n // Note: #current.5 (with opacity) is allowed since it resolves to a concrete color-mix value\n if (lowerKey.startsWith('#') && lowerValue === '#current') {\n console.warn(\n `Tasty: Using #current to define color token \"${key}\" is not supported. ` +\n `The #current token represents currentcolor which cannot be used as a base for other tokens.`,\n );\n continue; // Skip this token\n }\n\n normalizedTokens[lowerKey] = value;\n }\n // Merge with existing tokens (consistent with how states, units, funcs are handled)\n __globalPredefinedTokens = __globalPredefinedTokens\n ? { ...__globalPredefinedTokens, ...normalizedTokens }\n : normalizedTokens;\n // Clear parser cache since token values affect parsing\n getOrCreateParser().clearCache();\n}\n\n/**\n * Get the current global predefined tokens.\n * Returns null if no tokens are configured.\n */\nexport function getGlobalPredefinedTokens(): Record<string, string> | null {\n return __globalPredefinedTokens;\n}\n\n/**\n * Reset global predefined tokens.\n * Used for testing.\n * @internal\n */\nexport function resetGlobalPredefinedTokens(): void {\n __globalPredefinedTokens = null;\n // Clear parser cache since token availability affects parsing\n getOrCreateParser().clearCache();\n}\n\n/**\n *\n * @param {String} value\n * @param {Number} mode\n * @returns {Object<String,String|Array>}\n */\nexport function parseStyle(value: StyleValue): ProcessedStyle {\n let str: string;\n\n if (typeof value === 'string') {\n str = value;\n } else if (typeof value === 'number') {\n str = String(value);\n } else {\n // boolean, null, undefined, objects etc. → empty string\n str = '';\n }\n\n return getOrCreateParser().process(str);\n}\n\n/**\n * Parse color. Find it value, name and opacity.\n * Optimized to avoid heavy parseStyle calls for simple color patterns.\n */\nexport function parseColor(val: string, ignoreError = false): ParsedColor {\n // Early return for non-strings or empty values\n if (typeof val !== 'string') {\n val = String(val ?? '');\n }\n\n val = val.trim();\n if (!val) return {};\n\n // Fast path: Check if it's a simple color pattern that doesn't need full parsing\n const isSimpleColor = isSimpleColorFast(val);\n\n let firstColor: string;\n if (isSimpleColor) {\n // For simple colors, use the value directly without parsing\n firstColor = val;\n } else {\n const processed = parseStyle(val);\n const extractedColor = processed.groups.find((g) => g.colors.length)\n ?.colors[0];\n\n if (!extractedColor) {\n // Rate-limited warning to avoid spam\n if (!ignoreError && devMode && colorWarningCount < MAX_COLOR_WARNINGS) {\n console.warn('Tasty: unable to parse color:', val);\n colorWarningCount++;\n if (colorWarningCount === MAX_COLOR_WARNINGS) {\n console.warn(\n 'Tasty: color parsing warnings will be suppressed from now on',\n );\n }\n }\n return {};\n }\n\n firstColor = extractedColor;\n }\n\n // Extract color name (if present) from variable pattern using precompiled regex\n let nameMatch = firstColor.match(COLOR_VAR_PATTERN);\n if (!nameMatch) {\n nameMatch = firstColor.match(COLOR_VAR_COMPONENTS_PATTERN);\n }\n\n let opacity: number | undefined;\n if (\n firstColor.startsWith('rgb') ||\n firstColor.startsWith('hsl') ||\n firstColor.startsWith('lch') ||\n firstColor.startsWith('oklch') ||\n firstColor.startsWith('okhsl')\n ) {\n const alphaMatch = firstColor.match(RGB_ALPHA_PATTERN);\n if (alphaMatch) {\n const v = parseFloat(alphaMatch[1]);\n if (!isNaN(v)) opacity = v * 100;\n }\n }\n\n return {\n color: firstColor,\n name: nameMatch ? nameMatch[1] : undefined,\n opacity,\n };\n}\n\nexport function filterMods(mods: string[], allowedMods: string[]): string[] {\n return mods.filter((mod) => allowedMods.includes(mod));\n}\n\n// ============================================================================\n// Style Stringification\n// ============================================================================\n\nconst _innerCache = new WeakMap();\nconst _topLevelCache = new WeakMap<object, string>();\n\nexport function stringifyStyles(styles: unknown): string {\n if (styles == null || typeof styles !== 'object') return '';\n\n const cached = _topLevelCache.get(styles as object);\n if (cached !== undefined) return cached;\n\n const obj = styles as Record<string, unknown>;\n const keys = Object.keys(obj).sort();\n const parts: string[] = [];\n for (const k of keys) {\n const v = obj[k];\n if (v === undefined || typeof v === 'function' || typeof v === 'symbol')\n continue;\n\n const c0 = k.charCodeAt(0);\n const needsInnerSort =\n ((c0 >= 65 && c0 <= 90) || c0 === 38) &&\n v &&\n typeof v === 'object' &&\n !Array.isArray(v);\n\n let sv: string;\n if (needsInnerSort) {\n sv = _innerCache.get(v);\n if (sv === undefined) {\n const innerObj = v as Record<string, unknown>;\n const innerKeys = Object.keys(innerObj).sort();\n const innerParts: string[] = [];\n for (const ik of innerKeys) {\n const ivs = JSON.stringify(innerObj[ik]);\n if (ivs !== undefined)\n innerParts.push(JSON.stringify(ik) + ':' + ivs);\n }\n sv = '{' + innerParts.join(',') + '}';\n _innerCache.set(v, sv);\n }\n } else {\n sv = JSON.stringify(v);\n }\n parts.push(JSON.stringify(k) + ':' + sv);\n }\n const result = '{' + parts.join(',') + '}';\n _topLevelCache.set(styles as object, result);\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;AAyBA,SAAgB,yBACd,OAC0B;AAC1B,KAAI,UAAU,KACZ,QAAO;AAET,KAAI,UAAU,MACZ,QAAO;AAET,QAAO;;AAkDT,MAAM,oBAAoB;AAC1B,MAAM,+BACJ;AACF,MAAM,oBAAoB;AAC1B,MAAM,eAAe;AACrB,MAAM,eAAe;AAErB,SAAS,kBAAkB,KAAsB;AAG/C,SAFW,IAAI,WAAW,EAAE,EAE5B;EACE,KAAK,GACH,QAAO,aAAa,KAAK,IAAI;EAC/B,KAAK,IACH,QAAO,IAAI,WAAW,EAAE,KAAK,OAAO,IAAI,WAAW,EAAE,KAAK;EAC5D,KAAK,IACH,QAAO,IAAI,WAAW,EAAE,KAAK,OAAO,IAAI,WAAW,EAAE,KAAK;EAC5D,KAAK,IACH,QAAO,IAAI,WAAW,EAAE,KAAK,MAAM,IAAI,WAAW,EAAE,KAAK;EAC3D,KAAK,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,IAAI,GAAG;AACvC,gBAAe,IAAI,QAAkB,OAAO;AAC5C,QAAO"}
@@ -0,0 +1,58 @@
1
+ import { ConfigTokens } from "../styles/types.js";
2
+
3
+ //#region src/utils/typography.d.ts
4
+ /**
5
+ * A typography token value: plain value or a state map for responsive/theme-aware presets.
6
+ *
7
+ * @example
8
+ * // Plain value
9
+ * fontWeight: '400'
10
+ * // State map
11
+ * fontWeight: { '': '400', '@dark': '300' }
12
+ */
13
+ type TypographyTokenValue = string | number | Record<string, string | number | undefined | null | '@inherit'>;
14
+ /**
15
+ * Typography preset configuration.
16
+ * Each preset defines font properties that get expanded into CSS custom properties.
17
+ * All fields accept plain values or state maps for responsive/theme-aware tokens.
18
+ *
19
+ * Use with `generateTypographyTokens()` to create typography tokens for your design system.
20
+ */
21
+ interface TypographyPreset {
22
+ fontSize: TypographyTokenValue;
23
+ lineHeight: TypographyTokenValue;
24
+ letterSpacing?: TypographyTokenValue;
25
+ fontWeight: TypographyTokenValue;
26
+ boldFontWeight?: TypographyTokenValue;
27
+ iconSize?: TypographyTokenValue;
28
+ textTransform?: TypographyTokenValue;
29
+ fontFamily?: TypographyTokenValue;
30
+ fontStyle?: TypographyTokenValue;
31
+ }
32
+ /**
33
+ * Generate typography tokens with $ prefix for CSS custom properties.
34
+ *
35
+ * Each preset generates the following CSS custom properties:
36
+ * - `${name}-font-size`
37
+ * - `${name}-line-height`
38
+ * - `${name}-letter-spacing`
39
+ * - `${name}-font-weight`
40
+ * - `${name}-bold-font-weight` (if defined)
41
+ * - `${name}-icon-size` (if defined)
42
+ * - `${name}-text-transform` (if defined)
43
+ * - `${name}-font-family` (if defined)
44
+ * - `${name}-font-style` (if defined)
45
+ *
46
+ * @param presets - Typography presets object
47
+ * @returns ConfigTokens object with $ prefixed keys
48
+ *
49
+ * @example
50
+ * const customTokens = generateTypographyTokens({
51
+ * myHeading: { fontSize: '24px', lineHeight: '32px', fontWeight: '700' },
52
+ * body: { fontSize: '16px', lineHeight: '24px', fontWeight: '400' },
53
+ * });
54
+ */
55
+ declare function generateTypographyTokens(presets: Record<string, TypographyPreset>): ConfigTokens;
56
+ //#endregion
57
+ export { TypographyPreset, TypographyTokenValue, generateTypographyTokens };
58
+ //# sourceMappingURL=typography.d.ts.map