@tenphi/tasty 0.0.0-snapshot.f0e2124 → 0.0.0-snapshot.f144f3c

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 (328) hide show
  1. package/README.md +372 -233
  2. package/dist/babel-Zs1Q03qt.d.ts +83 -0
  3. package/dist/chunks/async-storage-DKK-wTD4.js +44 -0
  4. package/dist/chunks/async-storage-DKK-wTD4.js.map +1 -0
  5. package/dist/chunks/build-config-fM2Tf2dv.js +45 -0
  6. package/dist/chunks/build-config-fM2Tf2dv.js.map +1 -0
  7. package/dist/chunks/collector-HR9noXq_.js +318 -0
  8. package/dist/chunks/collector-HR9noXq_.js.map +1 -0
  9. package/dist/chunks/config-engine-DabuZ55f.js +331 -0
  10. package/dist/chunks/config-engine-DabuZ55f.js.map +1 -0
  11. package/dist/chunks/css-definitions-z79zG4t4.js +1229 -0
  12. package/dist/chunks/css-definitions-z79zG4t4.js.map +1 -0
  13. package/dist/chunks/css-resources-Cyl_axbI.js +149 -0
  14. package/dist/chunks/css-resources-Cyl_axbI.js.map +1 -0
  15. package/dist/chunks/debug-FLjTrfFW.js +576 -0
  16. package/dist/chunks/debug-FLjTrfFW.js.map +1 -0
  17. package/dist/chunks/dsl-BVhxBy6V.js +1915 -0
  18. package/dist/chunks/dsl-BVhxBy6V.js.map +1 -0
  19. package/dist/chunks/hydration-CLdVKcH2.js +59 -0
  20. package/dist/chunks/hydration-CLdVKcH2.js.map +1 -0
  21. package/dist/chunks/react-runtime-v7wWFkFD.js +882 -0
  22. package/dist/chunks/react-runtime-v7wWFkFD.js.map +1 -0
  23. package/dist/chunks/runtime-engine-BYEGKOF1.js +3452 -0
  24. package/dist/chunks/runtime-engine-BYEGKOF1.js.map +1 -0
  25. package/dist/chunks/runtime-state-icjb9GAD.js +138 -0
  26. package/dist/chunks/runtime-state-icjb9GAD.js.map +1 -0
  27. package/dist/{utils/merge-styles.js → chunks/shared-utils-OIg0N_dp.js} +43 -6
  28. package/dist/chunks/shared-utils-OIg0N_dp.js.map +1 -0
  29. package/dist/chunks/style-engine-C34heV9d.js +6920 -0
  30. package/dist/chunks/style-engine-C34heV9d.js.map +1 -0
  31. package/dist/{zero/extractor.js → chunks/zero-engine-DkyjChVU.js} +188 -13
  32. package/dist/chunks/zero-engine-DkyjChVU.js.map +1 -0
  33. package/dist/collector-hl5KNH7k.d.ts +165 -0
  34. package/dist/config-DWL1ZYue.d.ts +1358 -0
  35. package/dist/core/index.d.ts +5 -33
  36. package/dist/core/index.js +9 -26
  37. package/dist/index-CYLgmbWy.d.ts +1971 -0
  38. package/dist/index.d.ts +5 -48
  39. package/dist/index.js +11 -33
  40. package/dist/{utils/merge-styles.d.ts → merge-styles-C_oMoJVd.d.ts} +3 -3
  41. package/dist/ssr/astro-client.d.ts +1 -0
  42. package/dist/ssr/astro-client.js +19 -0
  43. package/dist/ssr/astro-client.js.map +1 -0
  44. package/dist/ssr/astro-middleware-extract-static.d.ts +11 -0
  45. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  46. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  47. package/dist/ssr/astro-middleware-extract.d.ts +11 -0
  48. package/dist/ssr/astro-middleware-extract.js +9 -0
  49. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  50. package/dist/ssr/astro-middleware-static.d.ts +18 -0
  51. package/dist/ssr/astro-middleware-static.js +18 -0
  52. package/dist/ssr/astro-middleware-static.js.map +1 -0
  53. package/dist/ssr/astro-middleware.d.ts +19 -0
  54. package/dist/ssr/astro-middleware.js +19 -0
  55. package/dist/ssr/astro-middleware.js.map +1 -0
  56. package/dist/ssr/astro.d.ts +135 -0
  57. package/dist/ssr/astro.js +300 -0
  58. package/dist/ssr/astro.js.map +1 -0
  59. package/dist/ssr/index.d.ts +37 -0
  60. package/dist/ssr/index.js +10 -0
  61. package/dist/ssr/index.js.map +1 -0
  62. package/dist/ssr/next-config.d.ts +66 -0
  63. package/dist/ssr/next-config.js +135 -0
  64. package/dist/ssr/next-config.js.map +1 -0
  65. package/dist/ssr/next.d.ts +52 -0
  66. package/dist/ssr/next.js +90 -0
  67. package/dist/ssr/next.js.map +1 -0
  68. package/dist/static/index.d.ts +91 -5
  69. package/dist/static/index.js +49 -4
  70. package/dist/static/index.js.map +1 -0
  71. package/dist/static/inject.d.ts +5 -0
  72. package/dist/static/inject.js +17 -0
  73. package/dist/static/inject.js.map +1 -0
  74. package/dist/types-jKZNpias.d.ts +1616 -0
  75. package/dist/zero/babel.d.ts +2 -113
  76. package/dist/zero/babel.js +237 -46
  77. package/dist/zero/babel.js.map +1 -1
  78. package/dist/zero/index.d.ts +81 -3
  79. package/dist/zero/index.js +2 -4
  80. package/dist/zero/next.d.ts +56 -30
  81. package/dist/zero/next.js +106 -41
  82. package/dist/zero/next.js.map +1 -1
  83. package/docs/README.md +39 -0
  84. package/docs/adoption.md +323 -0
  85. package/docs/ai-agents.md +229 -0
  86. package/docs/comparison.md +448 -0
  87. package/docs/configuration.md +823 -0
  88. package/docs/debug.md +332 -0
  89. package/docs/design-system.md +455 -0
  90. package/docs/dsl.md +1021 -0
  91. package/docs/getting-started.md +238 -0
  92. package/docs/injector.md +634 -0
  93. package/docs/methodology.md +648 -0
  94. package/docs/migration-v3.md +285 -0
  95. package/docs/pipeline.md +741 -0
  96. package/docs/plugins.md +353 -0
  97. package/docs/react-api.md +681 -0
  98. package/docs/runtime-benchmarks.md +351 -0
  99. package/docs/ssr.md +610 -0
  100. package/docs/styles.md +677 -0
  101. package/docs/tasty-static.md +582 -0
  102. package/package.json +171 -47
  103. package/tasty.config.ts +6 -0
  104. package/dist/_virtual/_rolldown/runtime.js +0 -8
  105. package/dist/chunks/cacheKey.js +0 -70
  106. package/dist/chunks/cacheKey.js.map +0 -1
  107. package/dist/chunks/definitions.d.ts +0 -37
  108. package/dist/chunks/definitions.js +0 -260
  109. package/dist/chunks/definitions.js.map +0 -1
  110. package/dist/chunks/renderChunk.js +0 -61
  111. package/dist/chunks/renderChunk.js.map +0 -1
  112. package/dist/config.d.ts +0 -288
  113. package/dist/config.js +0 -403
  114. package/dist/config.js.map +0 -1
  115. package/dist/debug.d.ts +0 -204
  116. package/dist/debug.js +0 -733
  117. package/dist/debug.js.map +0 -1
  118. package/dist/hooks/useGlobalStyles.d.ts +0 -27
  119. package/dist/hooks/useGlobalStyles.js +0 -56
  120. package/dist/hooks/useGlobalStyles.js.map +0 -1
  121. package/dist/hooks/useKeyframes.d.ts +0 -56
  122. package/dist/hooks/useKeyframes.js +0 -54
  123. package/dist/hooks/useKeyframes.js.map +0 -1
  124. package/dist/hooks/useProperty.d.ts +0 -79
  125. package/dist/hooks/useProperty.js +0 -91
  126. package/dist/hooks/useProperty.js.map +0 -1
  127. package/dist/hooks/useRawCSS.d.ts +0 -53
  128. package/dist/hooks/useRawCSS.js +0 -28
  129. package/dist/hooks/useRawCSS.js.map +0 -1
  130. package/dist/hooks/useStyles.d.ts +0 -40
  131. package/dist/hooks/useStyles.js +0 -169
  132. package/dist/hooks/useStyles.js.map +0 -1
  133. package/dist/injector/index.d.ts +0 -157
  134. package/dist/injector/index.js +0 -154
  135. package/dist/injector/index.js.map +0 -1
  136. package/dist/injector/injector.d.ts +0 -139
  137. package/dist/injector/injector.js +0 -426
  138. package/dist/injector/injector.js.map +0 -1
  139. package/dist/injector/sheet-manager.d.ts +0 -135
  140. package/dist/injector/sheet-manager.js +0 -728
  141. package/dist/injector/sheet-manager.js.map +0 -1
  142. package/dist/injector/types.d.ts +0 -144
  143. package/dist/keyframes/index.js +0 -206
  144. package/dist/keyframes/index.js.map +0 -1
  145. package/dist/parser/classify.js +0 -319
  146. package/dist/parser/classify.js.map +0 -1
  147. package/dist/parser/const.js +0 -33
  148. package/dist/parser/const.js.map +0 -1
  149. package/dist/parser/lru.js +0 -109
  150. package/dist/parser/lru.js.map +0 -1
  151. package/dist/parser/parser.d.ts +0 -25
  152. package/dist/parser/parser.js +0 -116
  153. package/dist/parser/parser.js.map +0 -1
  154. package/dist/parser/tokenizer.js +0 -69
  155. package/dist/parser/tokenizer.js.map +0 -1
  156. package/dist/parser/types.d.ts +0 -51
  157. package/dist/parser/types.js +0 -46
  158. package/dist/parser/types.js.map +0 -1
  159. package/dist/pipeline/conditions.d.ts +0 -134
  160. package/dist/pipeline/conditions.js +0 -406
  161. package/dist/pipeline/conditions.js.map +0 -1
  162. package/dist/pipeline/exclusive.js +0 -231
  163. package/dist/pipeline/exclusive.js.map +0 -1
  164. package/dist/pipeline/index.d.ts +0 -53
  165. package/dist/pipeline/index.js +0 -660
  166. package/dist/pipeline/index.js.map +0 -1
  167. package/dist/pipeline/materialize.js +0 -844
  168. package/dist/pipeline/materialize.js.map +0 -1
  169. package/dist/pipeline/parseStateKey.d.ts +0 -15
  170. package/dist/pipeline/parseStateKey.js +0 -438
  171. package/dist/pipeline/parseStateKey.js.map +0 -1
  172. package/dist/pipeline/simplify.js +0 -516
  173. package/dist/pipeline/simplify.js.map +0 -1
  174. package/dist/pipeline/warnings.js +0 -18
  175. package/dist/pipeline/warnings.js.map +0 -1
  176. package/dist/plugins/okhsl-plugin.d.ts +0 -35
  177. package/dist/plugins/okhsl-plugin.js +0 -371
  178. package/dist/plugins/okhsl-plugin.js.map +0 -1
  179. package/dist/plugins/types.d.ts +0 -69
  180. package/dist/properties/index.js +0 -237
  181. package/dist/properties/index.js.map +0 -1
  182. package/dist/properties/property-type-resolver.d.ts +0 -24
  183. package/dist/properties/property-type-resolver.js +0 -83
  184. package/dist/properties/property-type-resolver.js.map +0 -1
  185. package/dist/states/index.d.ts +0 -49
  186. package/dist/states/index.js +0 -416
  187. package/dist/states/index.js.map +0 -1
  188. package/dist/static/tastyStatic.d.ts +0 -46
  189. package/dist/static/tastyStatic.js +0 -31
  190. package/dist/static/tastyStatic.js.map +0 -1
  191. package/dist/static/types.d.ts +0 -49
  192. package/dist/static/types.js +0 -24
  193. package/dist/static/types.js.map +0 -1
  194. package/dist/styles/align.d.ts +0 -15
  195. package/dist/styles/align.js +0 -14
  196. package/dist/styles/align.js.map +0 -1
  197. package/dist/styles/border.d.ts +0 -25
  198. package/dist/styles/border.js +0 -114
  199. package/dist/styles/border.js.map +0 -1
  200. package/dist/styles/color.d.ts +0 -14
  201. package/dist/styles/color.js +0 -23
  202. package/dist/styles/color.js.map +0 -1
  203. package/dist/styles/createStyle.js +0 -77
  204. package/dist/styles/createStyle.js.map +0 -1
  205. package/dist/styles/dimension.js +0 -97
  206. package/dist/styles/dimension.js.map +0 -1
  207. package/dist/styles/display.d.ts +0 -37
  208. package/dist/styles/display.js +0 -67
  209. package/dist/styles/display.js.map +0 -1
  210. package/dist/styles/fade.d.ts +0 -15
  211. package/dist/styles/fade.js +0 -58
  212. package/dist/styles/fade.js.map +0 -1
  213. package/dist/styles/fill.d.ts +0 -42
  214. package/dist/styles/fill.js +0 -52
  215. package/dist/styles/fill.js.map +0 -1
  216. package/dist/styles/flow.d.ts +0 -16
  217. package/dist/styles/flow.js +0 -12
  218. package/dist/styles/flow.js.map +0 -1
  219. package/dist/styles/gap.d.ts +0 -31
  220. package/dist/styles/gap.js +0 -37
  221. package/dist/styles/gap.js.map +0 -1
  222. package/dist/styles/height.d.ts +0 -17
  223. package/dist/styles/height.js +0 -20
  224. package/dist/styles/height.js.map +0 -1
  225. package/dist/styles/index.d.ts +0 -2
  226. package/dist/styles/index.js +0 -9
  227. package/dist/styles/index.js.map +0 -1
  228. package/dist/styles/inset.d.ts +0 -52
  229. package/dist/styles/inset.js +0 -150
  230. package/dist/styles/inset.js.map +0 -1
  231. package/dist/styles/justify.d.ts +0 -15
  232. package/dist/styles/justify.js +0 -14
  233. package/dist/styles/justify.js.map +0 -1
  234. package/dist/styles/list.d.ts +0 -16
  235. package/dist/styles/list.js +0 -98
  236. package/dist/styles/list.js.map +0 -1
  237. package/dist/styles/margin.d.ts +0 -24
  238. package/dist/styles/margin.js +0 -104
  239. package/dist/styles/margin.js.map +0 -1
  240. package/dist/styles/outline.d.ts +0 -29
  241. package/dist/styles/outline.js +0 -65
  242. package/dist/styles/outline.js.map +0 -1
  243. package/dist/styles/padding.d.ts +0 -24
  244. package/dist/styles/padding.js +0 -104
  245. package/dist/styles/padding.js.map +0 -1
  246. package/dist/styles/predefined.d.ts +0 -73
  247. package/dist/styles/predefined.js +0 -241
  248. package/dist/styles/predefined.js.map +0 -1
  249. package/dist/styles/preset.d.ts +0 -47
  250. package/dist/styles/preset.js +0 -126
  251. package/dist/styles/preset.js.map +0 -1
  252. package/dist/styles/radius.d.ts +0 -14
  253. package/dist/styles/radius.js +0 -51
  254. package/dist/styles/radius.js.map +0 -1
  255. package/dist/styles/scrollbar.d.ts +0 -21
  256. package/dist/styles/scrollbar.js +0 -112
  257. package/dist/styles/scrollbar.js.map +0 -1
  258. package/dist/styles/shadow.d.ts +0 -14
  259. package/dist/styles/shadow.js +0 -24
  260. package/dist/styles/shadow.js.map +0 -1
  261. package/dist/styles/styledScrollbar.d.ts +0 -47
  262. package/dist/styles/styledScrollbar.js +0 -38
  263. package/dist/styles/styledScrollbar.js.map +0 -1
  264. package/dist/styles/transition.d.ts +0 -14
  265. package/dist/styles/transition.js +0 -158
  266. package/dist/styles/transition.js.map +0 -1
  267. package/dist/styles/types.d.ts +0 -498
  268. package/dist/styles/width.d.ts +0 -17
  269. package/dist/styles/width.js +0 -20
  270. package/dist/styles/width.js.map +0 -1
  271. package/dist/tasty.d.ts +0 -982
  272. package/dist/tasty.js +0 -206
  273. package/dist/tasty.js.map +0 -1
  274. package/dist/tokens/typography.d.ts +0 -19
  275. package/dist/tokens/typography.js +0 -237
  276. package/dist/tokens/typography.js.map +0 -1
  277. package/dist/types.d.ts +0 -184
  278. package/dist/utils/cache-wrapper.js +0 -26
  279. package/dist/utils/cache-wrapper.js.map +0 -1
  280. package/dist/utils/case-converter.js +0 -8
  281. package/dist/utils/case-converter.js.map +0 -1
  282. package/dist/utils/colors.d.ts +0 -5
  283. package/dist/utils/colors.js +0 -9
  284. package/dist/utils/colors.js.map +0 -1
  285. package/dist/utils/css-types.d.ts +0 -7
  286. package/dist/utils/dotize.d.ts +0 -26
  287. package/dist/utils/dotize.js +0 -122
  288. package/dist/utils/dotize.js.map +0 -1
  289. package/dist/utils/filter-base-props.d.ts +0 -15
  290. package/dist/utils/filter-base-props.js +0 -45
  291. package/dist/utils/filter-base-props.js.map +0 -1
  292. package/dist/utils/get-display-name.d.ts +0 -7
  293. package/dist/utils/get-display-name.js +0 -10
  294. package/dist/utils/get-display-name.js.map +0 -1
  295. package/dist/utils/hsl-to-rgb.js +0 -38
  296. package/dist/utils/hsl-to-rgb.js.map +0 -1
  297. package/dist/utils/is-dev-env.js +0 -19
  298. package/dist/utils/is-dev-env.js.map +0 -1
  299. package/dist/utils/is-valid-element-type.js +0 -15
  300. package/dist/utils/is-valid-element-type.js.map +0 -1
  301. package/dist/utils/merge-styles.js.map +0 -1
  302. package/dist/utils/mod-attrs.d.ts +0 -8
  303. package/dist/utils/mod-attrs.js +0 -21
  304. package/dist/utils/mod-attrs.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
  307. package/dist/utils/process-tokens.d.ts +0 -31
  308. package/dist/utils/process-tokens.js +0 -171
  309. package/dist/utils/process-tokens.js.map +0 -1
  310. package/dist/utils/resolve-recipes.d.ts +0 -17
  311. package/dist/utils/resolve-recipes.js +0 -147
  312. package/dist/utils/resolve-recipes.js.map +0 -1
  313. package/dist/utils/string.js +0 -8
  314. package/dist/utils/string.js.map +0 -1
  315. package/dist/utils/styles.d.ts +0 -178
  316. package/dist/utils/styles.js +0 -751
  317. package/dist/utils/styles.js.map +0 -1
  318. package/dist/utils/typography.d.ts +0 -36
  319. package/dist/utils/typography.js +0 -53
  320. package/dist/utils/typography.js.map +0 -1
  321. package/dist/utils/warnings.d.ts +0 -16
  322. package/dist/utils/warnings.js +0 -16
  323. package/dist/utils/warnings.js.map +0 -1
  324. package/dist/zero/css-writer.d.ts +0 -45
  325. package/dist/zero/css-writer.js +0 -74
  326. package/dist/zero/css-writer.js.map +0 -1
  327. package/dist/zero/extractor.d.ts +0 -24
  328. package/dist/zero/extractor.js.map +0 -1
@@ -1,751 +0,0 @@
1
- import { StyleParser } from "../parser/parser.js";
2
- import { okhslFunc } from "../plugins/okhsl-plugin.js";
3
- import { createStateParserContext, parseAdvancedState } from "../states/index.js";
4
- import { cacheWrapper } from "./cache-wrapper.js";
5
- import { camelToKebab } from "./case-converter.js";
6
- import { okhslToRgb } from "./okhsl-to-rgb.js";
7
- import { hslToRgb } from "./hsl-to-rgb.js";
8
-
9
- //#region src/utils/styles.ts
10
- /**
11
- * Normalize a color token value.
12
- * - Boolean `true` is converted to `'transparent'`
13
- * - Boolean `false` returns `null` (signals the token should be skipped)
14
- * - Other values are returned as-is
15
- *
16
- * @param value - The raw token value
17
- * @returns Normalized value or null if the token should be skipped
18
- */
19
- function normalizeColorTokenValue(value) {
20
- if (value === true) return "transparent";
21
- if (value === false) return null;
22
- return value;
23
- }
24
- const COLOR_VAR_PATTERN = /var\(--([a-z0-9-]+)-color/;
25
- const COLOR_VAR_RGB_PATTERN = /var\(--([a-z0-9-]+)-color-rgb/;
26
- const RGB_ALPHA_PATTERN = /\/\s*([0-9.]+)\)/;
27
- const SIMPLE_COLOR_PATTERNS = [
28
- /^#[0-9a-fA-F]{3,8}$/,
29
- /^rgb\(/,
30
- /^hsl\(/,
31
- /^lch\(/,
32
- /^oklch\(/,
33
- /^okhsl\(/,
34
- /^var\(--[a-z0-9-]+-color/,
35
- /^currentColor$/,
36
- /^transparent$/
37
- ];
38
- let colorWarningCount = 0;
39
- const MAX_COLOR_WARNINGS = 10;
40
- const CUSTOM_UNITS = {
41
- r: "6px",
42
- cr: "10px",
43
- bw: "1px",
44
- ow: "3px",
45
- x: "8px",
46
- fs: "var(--font-size)",
47
- lh: "var(--line-height)",
48
- sf: function sf(num) {
49
- return `minmax(0, ${num}fr)`;
50
- }
51
- };
52
- const DIRECTIONS = [
53
- "top",
54
- "right",
55
- "bottom",
56
- "left"
57
- ];
58
- const MOD_NAME_CACHE = /* @__PURE__ */ new Map();
59
- function getModSelector(modName) {
60
- if (!MOD_NAME_CACHE.has(modName)) {
61
- let selector;
62
- const valueModMatch = modName.match(/^([a-z][a-z0-9-]*)(\^=|\$=|\*=|=)(.+)$/i);
63
- if (valueModMatch) {
64
- const key = valueModMatch[1];
65
- const operator = valueModMatch[2];
66
- let value = valueModMatch[3];
67
- if (value.startsWith("\"") && value.endsWith("\"") || value.startsWith("'") && value.endsWith("'")) value = value.slice(1, -1);
68
- selector = `[data-${camelToKebab(key)}${operator}"${value}"]`;
69
- } else if (modName.match(/^[a-z]/)) selector = `[data-${camelToKebab(modName)}]`;
70
- else if (modName.includes(":has(")) selector = modName.replace(/:has\(([^)]+)\)/g, (match, content) => {
71
- if (/[A-Z][a-z]*[>+~]|[>+~][A-Z][a-z]*/.test(content)) console.error(`[Tasty] Invalid :has() selector syntax: "${modName}"\nCombinators (>, +, ~) must have spaces around them when used with element names.\nExample: Use ":has(Body > Row)" instead of ":has(Body>Row)"\nThis is a design choice: the parser uses simple whitespace splitting for performance.`);
72
- return `:has(${content.split(/\s+/).map((token) => /^[A-Z]/.test(token) ? `[data-element="${token}"]` : token).join(" ")})`;
73
- });
74
- else selector = modName;
75
- MOD_NAME_CACHE.set(modName, selector);
76
- }
77
- return MOD_NAME_CACHE.get(modName);
78
- }
79
- let __tastyParser = null;
80
- function getOrCreateParser() {
81
- if (!__tastyParser) {
82
- __tastyParser = new StyleParser({ units: CUSTOM_UNITS });
83
- __tastyParser.setFuncs(__tastyFuncs);
84
- }
85
- return __tastyParser;
86
- }
87
- const __tastyFuncs = { okhsl: okhslFunc };
88
- function customFunc(name, fn) {
89
- __tastyFuncs[name] = fn;
90
- getOrCreateParser().setFuncs(__tastyFuncs);
91
- }
92
- /**
93
- * Get the global StyleParser instance.
94
- * Used by configure() to apply parser configuration.
95
- */
96
- function getGlobalParser() {
97
- return getOrCreateParser();
98
- }
99
- /**
100
- * Get the current custom functions registry.
101
- * Used by configure() to merge with new functions.
102
- */
103
- function getGlobalFuncs() {
104
- return __tastyFuncs;
105
- }
106
- /**
107
- * Storage for predefined tokens that are replaced during style parsing.
108
- * Keys are token names (with $ or # prefix), values are pre-processed CSS values.
109
- */
110
- let __globalPredefinedTokens = null;
111
- /**
112
- * Set global predefined tokens.
113
- * Called from configure() after processing token values.
114
- * Merges with existing tokens (new tokens override existing ones with same key).
115
- * Keys are normalized to lowercase (parser lowercases input before classification).
116
- * @internal
117
- */
118
- function setGlobalPredefinedTokens(tokens) {
119
- const normalizedTokens = {};
120
- for (const [key, value] of Object.entries(tokens)) {
121
- const lowerKey = key.toLowerCase();
122
- const lowerValue = value.toLowerCase();
123
- if (lowerKey.startsWith("#") && lowerValue === "#current") {
124
- 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.`);
125
- continue;
126
- }
127
- normalizedTokens[lowerKey] = value;
128
- }
129
- __globalPredefinedTokens = __globalPredefinedTokens ? {
130
- ...__globalPredefinedTokens,
131
- ...normalizedTokens
132
- } : normalizedTokens;
133
- getOrCreateParser().clearCache();
134
- }
135
- /**
136
- * Get the current global predefined tokens.
137
- * Returns null if no tokens are configured.
138
- */
139
- function getGlobalPredefinedTokens() {
140
- return __globalPredefinedTokens;
141
- }
142
- /**
143
- * Reset global predefined tokens.
144
- * Used for testing.
145
- * @internal
146
- */
147
- function resetGlobalPredefinedTokens() {
148
- __globalPredefinedTokens = null;
149
- getOrCreateParser().clearCache();
150
- }
151
- /**
152
- *
153
- * @param {String} value
154
- * @param {Number} mode
155
- * @returns {Object<String,String|Array>}
156
- */
157
- function parseStyle(value) {
158
- let str;
159
- if (typeof value === "string") str = value;
160
- else if (typeof value === "number") str = String(value);
161
- else str = "";
162
- return getOrCreateParser().process(str);
163
- }
164
- /**
165
- * Parse color. Find it value, name and opacity.
166
- * Optimized to avoid heavy parseStyle calls for simple color patterns.
167
- */
168
- function parseColor(val, ignoreError = false) {
169
- if (typeof val !== "string") val = String(val ?? "");
170
- val = val.trim();
171
- if (!val) return {};
172
- const isSimpleColor = SIMPLE_COLOR_PATTERNS.some((pattern) => pattern.test(val));
173
- let firstColor;
174
- if (isSimpleColor) firstColor = val;
175
- else {
176
- const extractedColor = parseStyle(val).groups.find((g) => g.colors.length)?.colors[0];
177
- if (!extractedColor) {
178
- if (!ignoreError && colorWarningCount < MAX_COLOR_WARNINGS) {
179
- console.warn("CubeUIKit: unable to parse color:", val);
180
- colorWarningCount++;
181
- if (colorWarningCount === MAX_COLOR_WARNINGS) console.warn("CubeUIKit: color parsing warnings will be suppressed from now on");
182
- }
183
- return {};
184
- }
185
- firstColor = extractedColor;
186
- }
187
- let nameMatch = firstColor.match(COLOR_VAR_PATTERN);
188
- if (!nameMatch) nameMatch = firstColor.match(COLOR_VAR_RGB_PATTERN);
189
- let opacity;
190
- if (firstColor.startsWith("rgb") || firstColor.startsWith("hsl") || firstColor.startsWith("lch") || firstColor.startsWith("oklch") || firstColor.startsWith("okhsl")) {
191
- const alphaMatch = firstColor.match(RGB_ALPHA_PATTERN);
192
- if (alphaMatch) {
193
- const v = parseFloat(alphaMatch[1]);
194
- if (!isNaN(v)) opacity = v * 100;
195
- }
196
- }
197
- return {
198
- color: firstColor,
199
- name: nameMatch ? nameMatch[1] : void 0,
200
- opacity
201
- };
202
- }
203
- /**
204
- * CSS named color keywords → hex values.
205
- * Lazy-initialized on first use to avoid up-front cost.
206
- */
207
- let _namedColorHex = null;
208
- function getNamedColorHex() {
209
- if (_namedColorHex) return _namedColorHex;
210
- _namedColorHex = new Map([
211
- ["aliceblue", "#f0f8ff"],
212
- ["antiquewhite", "#faebd7"],
213
- ["aqua", "#00ffff"],
214
- ["aquamarine", "#7fffd4"],
215
- ["azure", "#f0ffff"],
216
- ["beige", "#f5f5dc"],
217
- ["bisque", "#ffe4c4"],
218
- ["black", "#000000"],
219
- ["blanchedalmond", "#ffebcd"],
220
- ["blue", "#0000ff"],
221
- ["blueviolet", "#8a2be2"],
222
- ["brown", "#a52a2a"],
223
- ["burlywood", "#deb887"],
224
- ["cadetblue", "#5f9ea0"],
225
- ["chartreuse", "#7fff00"],
226
- ["chocolate", "#d2691e"],
227
- ["coral", "#ff7f50"],
228
- ["cornflowerblue", "#6495ed"],
229
- ["cornsilk", "#fff8dc"],
230
- ["crimson", "#dc143c"],
231
- ["cyan", "#00ffff"],
232
- ["darkblue", "#00008b"],
233
- ["darkcyan", "#008b8b"],
234
- ["darkgoldenrod", "#b8860b"],
235
- ["darkgray", "#a9a9a9"],
236
- ["darkgreen", "#006400"],
237
- ["darkgrey", "#a9a9a9"],
238
- ["darkkhaki", "#bdb76b"],
239
- ["darkmagenta", "#8b008b"],
240
- ["darkolivegreen", "#556b2f"],
241
- ["darkorange", "#ff8c00"],
242
- ["darkorchid", "#9932cc"],
243
- ["darkred", "#8b0000"],
244
- ["darksalmon", "#e9967a"],
245
- ["darkseagreen", "#8fbc8f"],
246
- ["darkslateblue", "#483d8b"],
247
- ["darkslategray", "#2f4f4f"],
248
- ["darkslategrey", "#2f4f4f"],
249
- ["darkturquoise", "#00ced1"],
250
- ["darkviolet", "#9400d3"],
251
- ["deeppink", "#ff1493"],
252
- ["deepskyblue", "#00bfff"],
253
- ["dimgray", "#696969"],
254
- ["dimgrey", "#696969"],
255
- ["dodgerblue", "#1e90ff"],
256
- ["firebrick", "#b22222"],
257
- ["floralwhite", "#fffaf0"],
258
- ["forestgreen", "#228b22"],
259
- ["fuchsia", "#ff00ff"],
260
- ["gainsboro", "#dcdcdc"],
261
- ["ghostwhite", "#f8f8ff"],
262
- ["gold", "#ffd700"],
263
- ["goldenrod", "#daa520"],
264
- ["gray", "#808080"],
265
- ["green", "#008000"],
266
- ["greenyellow", "#adff2f"],
267
- ["grey", "#808080"],
268
- ["honeydew", "#f0fff0"],
269
- ["hotpink", "#ff69b4"],
270
- ["indianred", "#cd5c5c"],
271
- ["indigo", "#4b0082"],
272
- ["ivory", "#fffff0"],
273
- ["khaki", "#f0e68c"],
274
- ["lavender", "#e6e6fa"],
275
- ["lavenderblush", "#fff0f5"],
276
- ["lawngreen", "#7cfc00"],
277
- ["lemonchiffon", "#fffacd"],
278
- ["lightblue", "#add8e6"],
279
- ["lightcoral", "#f08080"],
280
- ["lightcyan", "#e0ffff"],
281
- ["lightgoldenrodyellow", "#fafad2"],
282
- ["lightgray", "#d3d3d3"],
283
- ["lightgreen", "#90ee90"],
284
- ["lightgrey", "#d3d3d3"],
285
- ["lightpink", "#ffb6c1"],
286
- ["lightsalmon", "#ffa07a"],
287
- ["lightseagreen", "#20b2aa"],
288
- ["lightskyblue", "#87cefa"],
289
- ["lightslategray", "#778899"],
290
- ["lightslategrey", "#778899"],
291
- ["lightsteelblue", "#b0c4de"],
292
- ["lightyellow", "#ffffe0"],
293
- ["lime", "#00ff00"],
294
- ["limegreen", "#32cd32"],
295
- ["linen", "#faf0e6"],
296
- ["magenta", "#ff00ff"],
297
- ["maroon", "#800000"],
298
- ["mediumaquamarine", "#66cdaa"],
299
- ["mediumblue", "#0000cd"],
300
- ["mediumorchid", "#ba55d3"],
301
- ["mediumpurple", "#9370db"],
302
- ["mediumseagreen", "#3cb371"],
303
- ["mediumslateblue", "#7b68ee"],
304
- ["mediumspringgreen", "#00fa9a"],
305
- ["mediumturquoise", "#48d1cc"],
306
- ["mediumvioletred", "#c71585"],
307
- ["midnightblue", "#191970"],
308
- ["mintcream", "#f5fffa"],
309
- ["mistyrose", "#ffe4e1"],
310
- ["moccasin", "#ffe4b5"],
311
- ["navajowhite", "#ffdead"],
312
- ["navy", "#000080"],
313
- ["oldlace", "#fdf5e6"],
314
- ["olive", "#808000"],
315
- ["olivedrab", "#6b8e23"],
316
- ["orange", "#ffa500"],
317
- ["orangered", "#ff4500"],
318
- ["orchid", "#da70d6"],
319
- ["palegoldenrod", "#eee8aa"],
320
- ["palegreen", "#98fb98"],
321
- ["paleturquoise", "#afeeee"],
322
- ["palevioletred", "#db7093"],
323
- ["papayawhip", "#ffefd5"],
324
- ["peachpuff", "#ffdab9"],
325
- ["peru", "#cd853f"],
326
- ["pink", "#ffc0cb"],
327
- ["plum", "#dda0dd"],
328
- ["powderblue", "#b0e0e6"],
329
- ["purple", "#800080"],
330
- ["rebeccapurple", "#663399"],
331
- ["red", "#ff0000"],
332
- ["rosybrown", "#bc8f8f"],
333
- ["royalblue", "#4169e1"],
334
- ["saddlebrown", "#8b4513"],
335
- ["salmon", "#fa8072"],
336
- ["sandybrown", "#f4a460"],
337
- ["seagreen", "#2e8b57"],
338
- ["seashell", "#fff5ee"],
339
- ["sienna", "#a0522d"],
340
- ["silver", "#c0c0c0"],
341
- ["skyblue", "#87ceeb"],
342
- ["slateblue", "#6a5acd"],
343
- ["slategray", "#708090"],
344
- ["slategrey", "#708090"],
345
- ["snow", "#fffafa"],
346
- ["springgreen", "#00ff7f"],
347
- ["steelblue", "#4682b4"],
348
- ["tan", "#d2b48c"],
349
- ["teal", "#008080"],
350
- ["thistle", "#d8bfd8"],
351
- ["tomato", "#ff6347"],
352
- ["turquoise", "#40e0d0"],
353
- ["violet", "#ee82ee"],
354
- ["wheat", "#f5deb3"],
355
- ["white", "#ffffff"],
356
- ["whitesmoke", "#f5f5f5"],
357
- ["yellow", "#ffff00"],
358
- ["yellowgreen", "#9acd32"]
359
- ]);
360
- return _namedColorHex;
361
- }
362
- function strToRgb(color, _ignoreAlpha = false) {
363
- if (!color) return void 0;
364
- if (color.startsWith("rgb")) return color;
365
- if (color.startsWith("#")) return hexToRgb(color);
366
- if (color.startsWith("okhsl(")) return okhslToRgb(color);
367
- if (color.startsWith("hsl")) return hslToRgb(color);
368
- const namedHex = getNamedColorHex().get(color.toLowerCase());
369
- if (namedHex) return hexToRgb(namedHex);
370
- return null;
371
- }
372
- /**
373
- * Extract RGB values from an rgb()/rgba() string.
374
- * Supports all modern CSS syntax variations:
375
- * - Comma-separated: rgb(255, 128, 0)
376
- * - Space-separated: rgb(255 128 0)
377
- * - Fractional: rgb(128.5, 64.3, 32.1)
378
- * - Percentages: rgb(50%, 25%, 75%)
379
- * - Slash alpha notation: rgb(255 128 0 / 0.5)
380
- *
381
- * Returns array of RGB values (0-255 range), converting percentages as needed.
382
- */
383
- function getRgbValuesFromRgbaString(str) {
384
- const match = str.match(/rgba?\(([^)]+)\)/i);
385
- if (!match) return [];
386
- const [colorPart] = match[1].trim().split("/");
387
- return colorPart.trim().split(/[,\s]+/).filter(Boolean).slice(0, 3).map((part) => {
388
- part = part.trim();
389
- if (part.endsWith("%")) return parseFloat(part) / 100 * 255;
390
- return parseFloat(part);
391
- });
392
- }
393
- function hexToRgb(hex) {
394
- const matched = hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (_m, r, g, b) => "#" + r + r + g + g + b + b).substring(1).match(/.{2}/g);
395
- if (!matched) return null;
396
- const rgba = matched.map((x, i) => parseInt(x, 16) * (i === 3 ? 1 / 255 : 1));
397
- if (rgba.some((v) => Number.isNaN(v))) return null;
398
- if (rgba.length >= 3) return `rgb(${rgba.slice(0, 3).join(" ")}${rgba.length > 3 ? ` / ${rgba[3]}` : ""})`;
399
- return null;
400
- }
401
- function filterMods(mods, allowedMods) {
402
- return mods.filter((mod) => allowedMods.includes(mod));
403
- }
404
- function extendStyles(defaultStyles, newStyles) {
405
- let styles = {};
406
- if (!defaultStyles) {
407
- if (!newStyles) return styles;
408
- } else styles = Object.assign({}, defaultStyles);
409
- if (newStyles) Object.keys(newStyles).forEach((key) => {
410
- if (newStyles[key] != null) styles[key] = newStyles[key];
411
- });
412
- return styles;
413
- }
414
- /**
415
- * Split properties into style and non-style properties.
416
- * @param props - Component prop map.
417
- * @param [styleList] - List of all style properties.
418
- * @param [defaultStyles] - Default style map of the component.
419
- * @param [propMap] - Props to style alias map.
420
- * @param [ignoreList] - A list of properties to ignore.
421
- */
422
- function extractStyles(props, styleList = [], defaultStyles, propMap, ignoreList = []) {
423
- const styles = {
424
- ...defaultStyles,
425
- ...ignoreList.includes("styles") ? void 0 : props.styles && typeof props.styles === "object" ? props.styles : void 0
426
- };
427
- Object.keys(props).forEach((prop) => {
428
- const propName = propMap ? propMap[prop] || prop : prop;
429
- const value = props[prop];
430
- if (ignoreList && ignoreList.includes(prop)) {} else if (styleList.includes(propName)) styles[propName] = value;
431
- }, {});
432
- return styles;
433
- }
434
- const STATES_REGEXP = /([&|!^])|([()])|(@media:[a-z]+)|(@media\([^)]+\))|(@root\([^)]+\))|(@own\([^)]+\))|(@\([^)]+\))|(@starting)|(@[A-Za-z][A-Za-z0-9-]*)|([a-z][a-z0-9-]+=(?:"[^"]*"|'[^']*'|[^\s&|!^()]+))|([a-z][a-z0-9-]+)|(:[a-z][a-z0-9-]+\([^)]+\)|:[a-z][a-z0-9-]+)|(\.[a-z][a-z0-9-]+)|(\[[^\]]+])/gi;
435
- /**
436
- * Check if a token is an advanced state (starts with @)
437
- */
438
- function isAdvancedStateToken(token) {
439
- return token.startsWith("@") || token.startsWith("!@");
440
- }
441
- const STATE_OPERATORS = {
442
- NOT: "!",
443
- AND: "&",
444
- OR: "|",
445
- XOR: "^"
446
- };
447
- const STATE_OPERATOR_LIST = [
448
- "!",
449
- "&",
450
- "|",
451
- "^"
452
- ];
453
- /**
454
- * Convert state notation tokens to a compute model (string, or nested [op, lhs, rhs]).
455
- */
456
- function convertTokensToComputeUnits(tokens) {
457
- if (tokens.length === 1) return tokens[0];
458
- const hasLength = (x) => typeof x === "string" || Array.isArray(x);
459
- STATE_OPERATOR_LIST.forEach((operator) => {
460
- let i;
461
- while ((i = tokens.indexOf(operator)) !== -1) {
462
- const token = tokens[i];
463
- if (token === "!") {
464
- const next = tokens[i + 1];
465
- if (next !== void 0 && hasLength(next) && next.length !== 1) tokens.splice(i, 2, ["!", next]);
466
- else tokens.splice(i, 1);
467
- } else {
468
- const prev = tokens[i - 1];
469
- const next = tokens[i + 1];
470
- if (prev !== void 0 && next !== void 0 && hasLength(prev) && hasLength(next) && prev.length !== 1 && next.length !== 1) tokens.splice(i - 1, 3, [
471
- token,
472
- prev,
473
- next
474
- ]);
475
- else tokens.splice(i, 1);
476
- }
477
- }
478
- });
479
- return tokens.length === 1 ? tokens[0] : tokens;
480
- }
481
- /**
482
- * Replace commas with | only outside of parentheses.
483
- * This preserves commas in advanced states like @(card, w < 600px)
484
- */
485
- function replaceCommasOutsideParens(str) {
486
- let result = "";
487
- let depth = 0;
488
- for (const char of str) if (char === "(") {
489
- depth++;
490
- result += char;
491
- } else if (char === ")") {
492
- depth--;
493
- result += char;
494
- } else if (char === "," && depth === 0) result += "|";
495
- else result += char;
496
- return result;
497
- }
498
- /**
499
- * Parse state notation and return tokens, modifiers and compute model.
500
- */
501
- function parseStateNotationInner(notation, value) {
502
- const tokens = replaceCommasOutsideParens(notation).match(STATES_REGEXP);
503
- if (!tokens || !tokens.length) return {
504
- model: void 0,
505
- mods: [],
506
- notMods: [],
507
- tokens: [],
508
- value
509
- };
510
- else if (tokens.length === 1) return {
511
- model: tokens[0],
512
- mods: tokens.slice(0),
513
- notMods: [],
514
- tokens,
515
- value
516
- };
517
- const mods = [];
518
- const operations = [[]];
519
- let list = operations[0];
520
- let position = 0;
521
- let operation;
522
- tokens.forEach((token) => {
523
- switch (token) {
524
- case "(":
525
- operation = [];
526
- position++;
527
- list = operations[position] = operation;
528
- break;
529
- case ")":
530
- position--;
531
- operations[position].push(convertTokensToComputeUnits(list));
532
- list = operations[position];
533
- break;
534
- default:
535
- if (token.length > 1) {
536
- if (!mods.includes(token)) mods.push(token);
537
- }
538
- list.push(token);
539
- }
540
- });
541
- while (position) {
542
- position--;
543
- operations[position].push(convertTokensToComputeUnits(list));
544
- list = operations[position];
545
- }
546
- return {
547
- tokens,
548
- mods,
549
- notMods: [],
550
- model: convertTokensToComputeUnits(operations[0]),
551
- value
552
- };
553
- }
554
- const parseStateNotation = cacheWrapper(parseStateNotationInner);
555
- /**
556
- * Build an AtRuleContext from parsed advanced states
557
- */
558
- function buildAtRuleContext(advancedStates, negatedStates) {
559
- if (advancedStates.length === 0) return void 0;
560
- const ctx = {};
561
- for (const state of advancedStates) {
562
- const isNegated = negatedStates.has(state.raw);
563
- switch (state.type) {
564
- case "media": {
565
- if (!ctx.media) ctx.media = [];
566
- let mediaCondition = "";
567
- if (state.mediaType) mediaCondition = state.mediaType;
568
- else if (state.condition) mediaCondition = `(${state.condition})`;
569
- if (mediaCondition) if (isNegated) ctx.media.push(`not ${mediaCondition}`);
570
- else ctx.media.push(mediaCondition);
571
- break;
572
- }
573
- case "container": {
574
- if (!ctx.container) ctx.container = [];
575
- let condition = state.condition;
576
- if (isNegated) condition = `not (${condition})`;
577
- ctx.container.push({
578
- name: state.containerName,
579
- condition
580
- });
581
- break;
582
- }
583
- case "root": {
584
- if (!ctx.rootStates) ctx.rootStates = [];
585
- const rootSelector = buildRootSelector(state.condition, isNegated);
586
- ctx.rootStates.push(rootSelector);
587
- break;
588
- }
589
- case "starting":
590
- if (!isNegated) ctx.startingStyle = true;
591
- break;
592
- }
593
- }
594
- if (!ctx.media?.length && !ctx.container?.length && !ctx.rootStates?.length && !ctx.startingStyle) return;
595
- return ctx;
596
- }
597
- /**
598
- * Build a root state selector from a condition
599
- */
600
- function buildRootSelector(condition, isNegated) {
601
- let selector;
602
- if (condition.startsWith(".")) selector = condition;
603
- else if (condition.startsWith("[")) selector = condition;
604
- else if (condition.includes("=")) {
605
- const [key, value] = condition.split("=");
606
- selector = `[data-${camelToKebab(key.trim())}="${value.trim()}"]`;
607
- } else selector = `[data-${camelToKebab(condition)}]`;
608
- if (isNegated) return `:not(${selector})`;
609
- return selector;
610
- }
611
- /**
612
- * Parse state notation and return tokens, modifiers and compute model.
613
- * Enhanced to detect and extract advanced states.
614
- */
615
- function styleStateMapToStyleStateDataList(styleStateMap, parserContext) {
616
- if (typeof styleStateMap !== "object" || !styleStateMap) return {
617
- states: [{
618
- model: void 0,
619
- mods: [],
620
- notMods: [],
621
- value: styleStateMap
622
- }],
623
- mods: [],
624
- hasAdvancedStates: false
625
- };
626
- const stateDataList = [];
627
- let hasAdvancedStates = false;
628
- Object.keys(styleStateMap).forEach((stateNotation) => {
629
- const state = parseStateNotation(stateNotation, styleStateMap[stateNotation]);
630
- const advancedStates = [];
631
- const negatedAdvancedStates = /* @__PURE__ */ new Set();
632
- const regularMods = [];
633
- const ownMods = [];
634
- const negatedOwnMods = [];
635
- if (state.tokens) {
636
- let isNegated = false;
637
- for (const token of state.tokens) {
638
- if (token === "!") {
639
- isNegated = true;
640
- continue;
641
- }
642
- if (isAdvancedStateToken(token)) {
643
- hasAdvancedStates = true;
644
- const parsed = parseAdvancedState(token, parserContext || createStateParserContext(void 0));
645
- advancedStates.push(parsed);
646
- if (parsed.type === "own" && parsed.condition) if (isNegated) negatedOwnMods.push(parsed.condition);
647
- else ownMods.push(parsed.condition);
648
- else if (isNegated) negatedAdvancedStates.add(token);
649
- isNegated = false;
650
- } else if (token.length > 1 && ![
651
- "&",
652
- "|",
653
- "^",
654
- "(",
655
- ")"
656
- ].includes(token)) {
657
- regularMods.push(token);
658
- isNegated = false;
659
- } else isNegated = false;
660
- }
661
- }
662
- if (advancedStates.length > 0) {
663
- state.advancedStates = advancedStates;
664
- state.atRuleContext = buildAtRuleContext(advancedStates, negatedAdvancedStates);
665
- state.mods = regularMods;
666
- }
667
- if (ownMods.length > 0) state.ownMods = ownMods;
668
- if (negatedOwnMods.length > 0) state.negatedOwnMods = negatedOwnMods;
669
- stateDataList.push(state);
670
- });
671
- stateDataList.reverse();
672
- let initialState;
673
- const allMods = stateDataList.reduce((all, state) => {
674
- if (!state.mods.length && !state.advancedStates?.length) initialState = state;
675
- else state.mods.forEach((mod) => {
676
- if (!all.includes(mod)) all.push(mod);
677
- });
678
- return all;
679
- }, []);
680
- if (!initialState) stateDataList.push({
681
- mods: [],
682
- notMods: allMods,
683
- value: true
684
- });
685
- return {
686
- states: stateDataList,
687
- mods: allMods,
688
- hasAdvancedStates
689
- };
690
- }
691
- const COMPUTE_FUNC_MAP = {
692
- "!": (a) => !a,
693
- "^": (a, b) => a && !b || !a && b,
694
- "|": (a, b) => a || b,
695
- "&": (a, b) => a && b
696
- };
697
- /**
698
- * Compute a result based on a model and incoming map.
699
- */
700
- function computeState(computeModel, valueMap) {
701
- if (!computeModel) return true;
702
- const map = valueMap;
703
- if (!Array.isArray(computeModel)) if (typeof valueMap === "function") return !!valueMap(computeModel);
704
- else return !!map[computeModel];
705
- const func = COMPUTE_FUNC_MAP[computeModel[0]];
706
- if (!func) console.warn("CubeUIKit: unexpected compute method in the model", computeModel);
707
- let a = computeModel[1];
708
- if (typeof a === "object") a = !!computeState(a, valueMap);
709
- else if (typeof valueMap === "function") a = !!valueMap(a);
710
- else a = !!map[a];
711
- if (computeModel.length === 2) return func(a);
712
- let b = computeModel[2];
713
- if (typeof b === "object") b = !!computeState(b, valueMap);
714
- else if (typeof valueMap === "function") b = !!valueMap(b);
715
- else b = !!map[b];
716
- return !!func(a, b);
717
- }
718
- const _innerCache = /* @__PURE__ */ new WeakMap();
719
- function stringifyStyles(styles) {
720
- if (styles == null || typeof styles !== "object") return "";
721
- const obj = styles;
722
- const keys = Object.keys(obj).sort();
723
- const parts = [];
724
- for (const k of keys) {
725
- const v = obj[k];
726
- if (v === void 0 || typeof v === "function" || typeof v === "symbol") continue;
727
- const c0 = k.charCodeAt(0);
728
- const needsInnerSort = (c0 >= 65 && c0 <= 90 || c0 === 38) && v && typeof v === "object" && !Array.isArray(v);
729
- let sv;
730
- if (needsInnerSort) {
731
- sv = _innerCache.get(v);
732
- if (sv === void 0) {
733
- const innerObj = v;
734
- const innerKeys = Object.keys(innerObj).sort();
735
- const innerParts = [];
736
- for (const ik of innerKeys) {
737
- const ivs = JSON.stringify(innerObj[ik]);
738
- if (ivs !== void 0) innerParts.push(JSON.stringify(ik) + ":" + ivs);
739
- }
740
- sv = "{" + innerParts.join(",") + "}";
741
- _innerCache.set(v, sv);
742
- }
743
- } else sv = JSON.stringify(v);
744
- parts.push(JSON.stringify(k) + ":" + sv);
745
- }
746
- return "{" + parts.join(",") + "}";
747
- }
748
-
749
- //#endregion
750
- export { COMPUTE_FUNC_MAP, CUSTOM_UNITS, DIRECTIONS, STATE_OPERATORS, STATE_OPERATOR_LIST, buildAtRuleContext, computeState, customFunc, extendStyles, extractStyles, filterMods, getGlobalFuncs, getGlobalParser, getGlobalPredefinedTokens, getModSelector, getRgbValuesFromRgbaString, hexToRgb, isAdvancedStateToken, normalizeColorTokenValue, parseColor, parseStateNotation, parseStyle, resetGlobalPredefinedTokens, setGlobalPredefinedTokens, strToRgb, stringifyStyles, styleStateMapToStyleStateDataList };
751
- //# sourceMappingURL=styles.js.map