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

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 (163) hide show
  1. package/README.md +130 -7
  2. package/dist/chunks/cacheKey.js +16 -8
  3. package/dist/chunks/cacheKey.js.map +1 -1
  4. package/dist/chunks/definitions.js +1 -2
  5. package/dist/chunks/definitions.js.map +1 -1
  6. package/dist/chunks/renderChunk.js +31 -32
  7. package/dist/chunks/renderChunk.js.map +1 -1
  8. package/dist/config.d.ts +45 -10
  9. package/dist/config.js +75 -13
  10. package/dist/config.js.map +1 -1
  11. package/dist/core/index.d.ts +9 -8
  12. package/dist/core/index.js +7 -6
  13. package/dist/hooks/useGlobalStyles.d.ts +3 -0
  14. package/dist/hooks/useGlobalStyles.js +28 -1
  15. package/dist/hooks/useGlobalStyles.js.map +1 -1
  16. package/dist/hooks/useKeyframes.js +18 -3
  17. package/dist/hooks/useKeyframes.js.map +1 -1
  18. package/dist/hooks/useProperty.js +36 -13
  19. package/dist/hooks/useProperty.js.map +1 -1
  20. package/dist/hooks/useRawCSS.js +13 -1
  21. package/dist/hooks/useRawCSS.js.map +1 -1
  22. package/dist/hooks/useStyles.d.ts +5 -0
  23. package/dist/hooks/useStyles.js +87 -7
  24. package/dist/hooks/useStyles.js.map +1 -1
  25. package/dist/index.d.ts +9 -8
  26. package/dist/index.js +7 -6
  27. package/dist/injector/index.d.ts +9 -1
  28. package/dist/injector/index.js +9 -1
  29. package/dist/injector/index.js.map +1 -1
  30. package/dist/injector/injector.d.ts +9 -0
  31. package/dist/injector/injector.js +21 -17
  32. package/dist/injector/injector.js.map +1 -1
  33. package/dist/injector/sheet-manager.d.ts +1 -0
  34. package/dist/injector/sheet-manager.js +1 -0
  35. package/dist/injector/sheet-manager.js.map +1 -1
  36. package/dist/parser/classify.js +2 -1
  37. package/dist/parser/classify.js.map +1 -1
  38. package/dist/parser/parser.js +1 -1
  39. package/dist/pipeline/index.d.ts +1 -1
  40. package/dist/pipeline/index.js +24 -14
  41. package/dist/pipeline/index.js.map +1 -1
  42. package/dist/pipeline/materialize.js +380 -119
  43. package/dist/pipeline/materialize.js.map +1 -1
  44. package/dist/pipeline/parseStateKey.d.ts +1 -1
  45. package/dist/pipeline/parseStateKey.js +20 -11
  46. package/dist/pipeline/parseStateKey.js.map +1 -1
  47. package/dist/plugins/okhsl-plugin.js +2 -275
  48. package/dist/plugins/okhsl-plugin.js.map +1 -1
  49. package/dist/plugins/types.d.ts +9 -2
  50. package/dist/properties/index.js +14 -28
  51. package/dist/properties/index.js.map +1 -1
  52. package/dist/properties/property-type-resolver.js +12 -0
  53. package/dist/properties/property-type-resolver.js.map +1 -1
  54. package/dist/ssr/astro.d.ts +29 -0
  55. package/dist/ssr/astro.js +65 -0
  56. package/dist/ssr/astro.js.map +1 -0
  57. package/dist/ssr/async-storage.d.ts +17 -0
  58. package/dist/ssr/async-storage.js +35 -0
  59. package/dist/ssr/async-storage.js.map +1 -0
  60. package/dist/ssr/collect-auto-properties.js +40 -0
  61. package/dist/ssr/collect-auto-properties.js.map +1 -0
  62. package/dist/ssr/collector.d.ts +85 -0
  63. package/dist/ssr/collector.js +183 -0
  64. package/dist/ssr/collector.js.map +1 -0
  65. package/dist/ssr/context.d.ts +8 -0
  66. package/dist/ssr/context.js +14 -0
  67. package/dist/ssr/context.js.map +1 -0
  68. package/dist/ssr/format-global-rules.js +22 -0
  69. package/dist/ssr/format-global-rules.js.map +1 -0
  70. package/dist/ssr/format-keyframes.js +70 -0
  71. package/dist/ssr/format-keyframes.js.map +1 -0
  72. package/dist/ssr/format-property.js +50 -0
  73. package/dist/ssr/format-property.js.map +1 -0
  74. package/dist/ssr/format-rules.js +70 -0
  75. package/dist/ssr/format-rules.js.map +1 -0
  76. package/dist/ssr/hydrate.d.ts +22 -0
  77. package/dist/ssr/hydrate.js +50 -0
  78. package/dist/ssr/hydrate.js.map +1 -0
  79. package/dist/ssr/index.d.ts +5 -0
  80. package/dist/ssr/index.js +12 -0
  81. package/dist/ssr/index.js.map +1 -0
  82. package/dist/ssr/next.d.ts +45 -0
  83. package/dist/ssr/next.js +71 -0
  84. package/dist/ssr/next.js.map +1 -0
  85. package/dist/ssr/ssr-collector-ref.js +12 -0
  86. package/dist/ssr/ssr-collector-ref.js.map +1 -0
  87. package/dist/states/index.js +10 -257
  88. package/dist/states/index.js.map +1 -1
  89. package/dist/styles/color.js +9 -5
  90. package/dist/styles/color.js.map +1 -1
  91. package/dist/styles/createStyle.js +24 -21
  92. package/dist/styles/createStyle.js.map +1 -1
  93. package/dist/styles/index.js +1 -1
  94. package/dist/styles/predefined.d.ts +0 -2
  95. package/dist/styles/predefined.js +0 -3
  96. package/dist/styles/predefined.js.map +1 -1
  97. package/dist/styles/preset.js +1 -1
  98. package/dist/styles/preset.js.map +1 -1
  99. package/dist/styles/scrollbar.d.ts +9 -5
  100. package/dist/styles/scrollbar.js +25 -89
  101. package/dist/styles/scrollbar.js.map +1 -1
  102. package/dist/styles/transition.js +1 -1
  103. package/dist/styles/transition.js.map +1 -1
  104. package/dist/styles/types.d.ts +24 -14
  105. package/dist/tasty.d.ts +20 -21
  106. package/dist/tasty.js +24 -11
  107. package/dist/tasty.js.map +1 -1
  108. package/dist/types.d.ts +1 -1
  109. package/dist/utils/cache-wrapper.js +4 -8
  110. package/dist/utils/cache-wrapper.js.map +1 -1
  111. package/dist/utils/color-math.d.ts +45 -0
  112. package/dist/utils/color-math.js +749 -0
  113. package/dist/utils/color-math.js.map +1 -0
  114. package/dist/utils/color-space.d.ts +5 -0
  115. package/dist/utils/color-space.js +228 -0
  116. package/dist/utils/color-space.js.map +1 -0
  117. package/dist/utils/colors.js +3 -1
  118. package/dist/utils/colors.js.map +1 -1
  119. package/dist/utils/has-keys.js +13 -0
  120. package/dist/utils/has-keys.js.map +1 -0
  121. package/dist/utils/mod-attrs.js +1 -1
  122. package/dist/utils/process-tokens.d.ts +3 -13
  123. package/dist/utils/process-tokens.js +17 -97
  124. package/dist/utils/process-tokens.js.map +1 -1
  125. package/dist/utils/selector-transform.js +32 -0
  126. package/dist/utils/selector-transform.js.map +1 -0
  127. package/dist/utils/styles.d.ts +2 -79
  128. package/dist/utils/styles.js +26 -554
  129. package/dist/utils/styles.js.map +1 -1
  130. package/dist/utils/typography.d.ts +24 -13
  131. package/dist/utils/typography.js +6 -16
  132. package/dist/utils/typography.js.map +1 -1
  133. package/dist/zero/babel.d.ts +48 -6
  134. package/dist/zero/babel.js +63 -5
  135. package/dist/zero/babel.js.map +1 -1
  136. package/dist/zero/next.d.ts +44 -30
  137. package/dist/zero/next.js +102 -38
  138. package/dist/zero/next.js.map +1 -1
  139. package/docs/PIPELINE.md +519 -0
  140. package/docs/adoption.md +286 -0
  141. package/docs/comparison.md +413 -0
  142. package/docs/configuration.md +263 -0
  143. package/docs/debug.md +505 -0
  144. package/docs/design-system.md +401 -0
  145. package/docs/dsl.md +540 -0
  146. package/docs/getting-started.md +201 -0
  147. package/docs/injector.md +528 -0
  148. package/docs/methodology.md +501 -0
  149. package/docs/runtime.md +291 -0
  150. package/docs/ssr.md +382 -0
  151. package/docs/styles.md +574 -0
  152. package/docs/tasty-static.md +420 -0
  153. package/package.json +50 -30
  154. package/dist/styles/styledScrollbar.d.ts +0 -47
  155. package/dist/styles/styledScrollbar.js +0 -38
  156. package/dist/styles/styledScrollbar.js.map +0 -1
  157. package/dist/tokens/typography.d.ts +0 -19
  158. package/dist/tokens/typography.js +0 -237
  159. package/dist/tokens/typography.js.map +0 -1
  160. package/dist/utils/hsl-to-rgb.js +0 -38
  161. package/dist/utils/hsl-to-rgb.js.map +0 -1
  162. package/dist/utils/okhsl-to-rgb.js +0 -296
  163. package/dist/utils/okhsl-to-rgb.js.map +0 -1
@@ -1,10 +1,6 @@
1
+ import { getRgbValuesFromRgbaString, hexToRgb, strToRgb } from "./color-math.js";
1
2
  import { StyleParser } from "../parser/parser.js";
2
3
  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
4
 
9
5
  //#region src/utils/styles.ts
10
6
  /**
@@ -22,19 +18,23 @@ function normalizeColorTokenValue(value) {
22
18
  return value;
23
19
  }
24
20
  const COLOR_VAR_PATTERN = /var\(--([a-z0-9-]+)-color/;
25
- const COLOR_VAR_RGB_PATTERN = /var\(--([a-z0-9-]+)-color-rgb/;
21
+ const COLOR_VAR_COMPONENTS_PATTERN = /var\(--([a-z0-9-]+)-color-(?:rgb|hsl|oklch)/;
26
22
  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
- ];
23
+ const RE_HEX_COLOR = /^#[0-9a-fA-F]{3,8}$/;
24
+ const RE_VAR_COLOR = /^var\(--[a-z0-9-]+-color/;
25
+ function isSimpleColorFast(val) {
26
+ switch (val.charCodeAt(0)) {
27
+ case 35: return RE_HEX_COLOR.test(val);
28
+ case 114: return val.charCodeAt(1) === 103 && val.charCodeAt(2) === 98;
29
+ case 104: return val.charCodeAt(1) === 115 && val.charCodeAt(2) === 108;
30
+ case 108: return val.charCodeAt(1) === 99 && val.charCodeAt(2) === 104;
31
+ case 111: return val.startsWith("oklch(") || val.startsWith("okhsl(");
32
+ case 118: return RE_VAR_COLOR.test(val);
33
+ case 99: return val === "currentColor" || val === "currentcolor";
34
+ case 116: return val === "transparent";
35
+ default: return false;
36
+ }
37
+ }
38
38
  let colorWarningCount = 0;
39
39
  const MAX_COLOR_WARNINGS = 10;
40
40
  const CUSTOM_UNITS = {
@@ -55,27 +55,6 @@ const DIRECTIONS = [
55
55
  "bottom",
56
56
  "left"
57
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
58
  let __tastyParser = null;
80
59
  function getOrCreateParser() {
81
60
  if (!__tastyParser) {
@@ -169,7 +148,7 @@ function parseColor(val, ignoreError = false) {
169
148
  if (typeof val !== "string") val = String(val ?? "");
170
149
  val = val.trim();
171
150
  if (!val) return {};
172
- const isSimpleColor = SIMPLE_COLOR_PATTERNS.some((pattern) => pattern.test(val));
151
+ const isSimpleColor = isSimpleColorFast(val);
173
152
  let firstColor;
174
153
  if (isSimpleColor) firstColor = val;
175
154
  else {
@@ -185,7 +164,7 @@ function parseColor(val, ignoreError = false) {
185
164
  firstColor = extractedColor;
186
165
  }
187
166
  let nameMatch = firstColor.match(COLOR_VAR_PATTERN);
188
- if (!nameMatch) nameMatch = firstColor.match(COLOR_VAR_RGB_PATTERN);
167
+ if (!nameMatch) nameMatch = firstColor.match(COLOR_VAR_COMPONENTS_PATTERN);
189
168
  let opacity;
190
169
  if (firstColor.startsWith("rgb") || firstColor.startsWith("hsl") || firstColor.startsWith("lch") || firstColor.startsWith("oklch") || firstColor.startsWith("okhsl")) {
191
170
  const alphaMatch = firstColor.match(RGB_ALPHA_PATTERN);
@@ -200,524 +179,15 @@ function parseColor(val, ignoreError = false) {
200
179
  opacity
201
180
  };
202
181
  }
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
182
  function filterMods(mods, allowedMods) {
402
183
  return mods.filter((mod) => allowedMods.includes(mod));
403
184
  }
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
185
  const _innerCache = /* @__PURE__ */ new WeakMap();
186
+ const _topLevelCache = /* @__PURE__ */ new WeakMap();
719
187
  function stringifyStyles(styles) {
720
188
  if (styles == null || typeof styles !== "object") return "";
189
+ const cached = _topLevelCache.get(styles);
190
+ if (cached !== void 0) return cached;
721
191
  const obj = styles;
722
192
  const keys = Object.keys(obj).sort();
723
193
  const parts = [];
@@ -743,9 +213,11 @@ function stringifyStyles(styles) {
743
213
  } else sv = JSON.stringify(v);
744
214
  parts.push(JSON.stringify(k) + ":" + sv);
745
215
  }
746
- return "{" + parts.join(",") + "}";
216
+ const result = "{" + parts.join(",") + "}";
217
+ _topLevelCache.set(styles, result);
218
+ return result;
747
219
  }
748
220
 
749
221
  //#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 };
222
+ export { CUSTOM_UNITS, DIRECTIONS, customFunc, filterMods, getGlobalFuncs, getGlobalParser, getGlobalPredefinedTokens, normalizeColorTokenValue, parseColor, parseStyle, resetGlobalPredefinedTokens, setGlobalPredefinedTokens, stringifyStyles };
751
223
  //# sourceMappingURL=styles.js.map