@tenphi/tasty 0.13.0 → 0.13.1

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 (40) hide show
  1. package/dist/chunks/cacheKey.js +16 -8
  2. package/dist/chunks/cacheKey.js.map +1 -1
  3. package/dist/chunks/renderChunk.js +31 -32
  4. package/dist/chunks/renderChunk.js.map +1 -1
  5. package/dist/config.d.ts +1 -1
  6. package/dist/config.js +6 -3
  7. package/dist/config.js.map +1 -1
  8. package/dist/core/index.d.ts +3 -3
  9. package/dist/core/index.js +3 -3
  10. package/dist/hooks/useStyles.js +4 -3
  11. package/dist/hooks/useStyles.js.map +1 -1
  12. package/dist/index.d.ts +3 -3
  13. package/dist/index.js +3 -3
  14. package/dist/pipeline/index.d.ts +1 -1
  15. package/dist/pipeline/index.js +24 -14
  16. package/dist/pipeline/index.js.map +1 -1
  17. package/dist/pipeline/materialize.js +328 -79
  18. package/dist/pipeline/materialize.js.map +1 -1
  19. package/dist/pipeline/parseStateKey.d.ts +1 -1
  20. package/dist/pipeline/parseStateKey.js +2 -6
  21. package/dist/pipeline/parseStateKey.js.map +1 -1
  22. package/dist/states/index.js +10 -257
  23. package/dist/states/index.js.map +1 -1
  24. package/dist/tasty.js +23 -10
  25. package/dist/tasty.js.map +1 -1
  26. package/dist/utils/cache-wrapper.js +4 -8
  27. package/dist/utils/cache-wrapper.js.map +1 -1
  28. package/dist/utils/has-keys.js +13 -0
  29. package/dist/utils/has-keys.js.map +1 -0
  30. package/dist/utils/mod-attrs.js +1 -1
  31. package/dist/utils/styles.d.ts +1 -64
  32. package/dist/utils/styles.js +7 -319
  33. package/dist/utils/styles.js.map +1 -1
  34. package/dist/zero/babel.d.ts +8 -0
  35. package/dist/zero/babel.js +18 -3
  36. package/dist/zero/babel.js.map +1 -1
  37. package/dist/zero/next.js +9 -1
  38. package/dist/zero/next.js.map +1 -1
  39. package/docs/tasty-static.md +6 -7
  40. package/package.json +1 -1
@@ -1,19 +1,15 @@
1
+ import { Lru } from "../parser/lru.js";
2
+
1
3
  //#region src/utils/cache-wrapper.ts
2
4
  /**
3
- * Create a function that caches the result up to the limit.
5
+ * Create a function that caches the result with LRU eviction.
4
6
  */
5
7
  function cacheWrapper(handler, limit = 1e3) {
6
- const cache = /* @__PURE__ */ new Map();
7
- let count = 0;
8
+ const cache = new Lru(limit);
8
9
  return (firstArg, secondArg) => {
9
10
  const key = typeof firstArg === "string" && secondArg == null ? firstArg : JSON.stringify([firstArg, secondArg]);
10
11
  let result = cache.get(key);
11
12
  if (result === void 0) {
12
- if (count > limit) {
13
- cache.clear();
14
- count = 0;
15
- }
16
- count++;
17
13
  result = secondArg == null ? handler(firstArg) : handler(firstArg, secondArg);
18
14
  cache.set(key, result);
19
15
  }
@@ -1 +1 @@
1
- {"version":3,"file":"cache-wrapper.js","names":[],"sources":["../../src/utils/cache-wrapper.ts"],"sourcesContent":["/**\n * Create a function that caches the result up to the limit.\n */\nexport function cacheWrapper<A, B, R>(\n handler: (firstArg: A, secondArg?: B) => R,\n limit = 1000,\n): (firstArg: A, secondArg?: B) => R {\n const cache = new Map<string, R>();\n let count = 0;\n\n return (firstArg: A, secondArg?: B) => {\n const key =\n typeof firstArg === 'string' && secondArg == null\n ? firstArg\n : JSON.stringify([firstArg, secondArg]);\n\n let result = cache.get(key);\n if (result === undefined) {\n if (count > limit) {\n cache.clear();\n count = 0;\n }\n count++;\n result =\n secondArg == null ? handler(firstArg) : handler(firstArg, secondArg);\n cache.set(key, result);\n }\n return result;\n };\n}\n"],"mappings":";;;;AAGA,SAAgB,aACd,SACA,QAAQ,KAC2B;CACnC,MAAM,wBAAQ,IAAI,KAAgB;CAClC,IAAI,QAAQ;AAEZ,SAAQ,UAAa,cAAkB;EACrC,MAAM,MACJ,OAAO,aAAa,YAAY,aAAa,OACzC,WACA,KAAK,UAAU,CAAC,UAAU,UAAU,CAAC;EAE3C,IAAI,SAAS,MAAM,IAAI,IAAI;AAC3B,MAAI,WAAW,QAAW;AACxB,OAAI,QAAQ,OAAO;AACjB,UAAM,OAAO;AACb,YAAQ;;AAEV;AACA,YACE,aAAa,OAAO,QAAQ,SAAS,GAAG,QAAQ,UAAU,UAAU;AACtE,SAAM,IAAI,KAAK,OAAO;;AAExB,SAAO"}
1
+ {"version":3,"file":"cache-wrapper.js","names":[],"sources":["../../src/utils/cache-wrapper.ts"],"sourcesContent":["import { Lru } from '../parser/lru';\n\n/**\n * Create a function that caches the result with LRU eviction.\n */\nexport function cacheWrapper<A, B, R>(\n handler: (firstArg: A, secondArg?: B) => R,\n limit = 1000,\n): (firstArg: A, secondArg?: B) => R {\n const cache = new Lru<string, R>(limit);\n\n return (firstArg: A, secondArg?: B) => {\n const key =\n typeof firstArg === 'string' && secondArg == null\n ? firstArg\n : JSON.stringify([firstArg, secondArg]);\n\n let result = cache.get(key);\n if (result === undefined) {\n result =\n secondArg == null ? handler(firstArg) : handler(firstArg, secondArg);\n cache.set(key, result);\n }\n return result;\n };\n}\n"],"mappings":";;;;;;AAKA,SAAgB,aACd,SACA,QAAQ,KAC2B;CACnC,MAAM,QAAQ,IAAI,IAAe,MAAM;AAEvC,SAAQ,UAAa,cAAkB;EACrC,MAAM,MACJ,OAAO,aAAa,YAAY,aAAa,OACzC,WACA,KAAK,UAAU,CAAC,UAAU,UAAU,CAAC;EAE3C,IAAI,SAAS,MAAM,IAAI,IAAI;AAC3B,MAAI,WAAW,QAAW;AACxB,YACE,aAAa,OAAO,QAAQ,SAAS,GAAG,QAAQ,UAAU,UAAU;AACtE,SAAM,IAAI,KAAK,OAAO;;AAExB,SAAO"}
@@ -0,0 +1,13 @@
1
+ //#region src/utils/has-keys.ts
2
+ /**
3
+ * Check if an object has any own enumerable keys.
4
+ * Avoids the array allocation of Object.keys(obj).length > 0.
5
+ */
6
+ function hasKeys(obj) {
7
+ for (const _ in obj) return true;
8
+ return false;
9
+ }
10
+
11
+ //#endregion
12
+ export { hasKeys };
13
+ //# sourceMappingURL=has-keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-keys.js","names":[],"sources":["../../src/utils/has-keys.ts"],"sourcesContent":["/**\n * Check if an object has any own enumerable keys.\n * Avoids the array allocation of Object.keys(obj).length > 0.\n */\nexport function hasKeys(obj: object): boolean {\n for (const _ in obj) return true;\n return false;\n}\n"],"mappings":";;;;;AAIA,SAAgB,QAAQ,KAAsB;AAC5C,MAAK,MAAM,KAAK,IAAK,QAAO;AAC5B,QAAO"}
@@ -1,5 +1,5 @@
1
- import { cacheWrapper } from "./cache-wrapper.js";
2
1
  import { camelToKebab } from "./case-converter.js";
2
+ import { cacheWrapper } from "./cache-wrapper.js";
3
3
 
4
4
  //#region src/utils/mod-attrs.ts
5
5
  function modAttrs(map) {
@@ -1,7 +1,5 @@
1
1
  import { ProcessedStyle, StyleDetails } from "../parser/types.js";
2
2
  import { StyleParser } from "../parser/parser.js";
3
- import { AtRuleContext, ParsedAdvancedState, StateParserContext } from "../states/index.js";
4
- import { Styles } from "../styles/types.js";
5
3
 
6
4
  //#region src/utils/styles.d.ts
7
5
  type StyleValue<T = string> = T | boolean | number | null | undefined;
@@ -21,7 +19,6 @@ type StyleValueStateMap<T = string> = Record<string, StyleValue<T> | '@inherit'>
21
19
  * Use this for component props that accept style values.
22
20
  */
23
21
  type StylePropValue<T = string> = StyleValue<T> | StyleValueStateMap<T>;
24
- type ComputeModel = string | number;
25
22
  type CSSMap = {
26
23
  $?: string | string[];
27
24
  } & Record<string, string | string[]>;
@@ -37,32 +34,12 @@ type StyleHandler = RawStyleHandler & {
37
34
  * - Multi-property tuple: [['style1', 'style2'], handler]
38
35
  */
39
36
  type StyleHandlerDefinition = RawStyleHandler | [string, RawStyleHandler] | [string[], RawStyleHandler];
40
- interface StyleStateData {
41
- model?: ComputeModel;
42
- tokens?: string[];
43
- value: StyleValue | StyleValueStateMap | StyleStateData;
44
- /** The list of mods to apply */
45
- mods: string[];
46
- /** The list of **not** mods to apply (e.g. `:not(:hover)`) */
47
- notMods: string[];
48
- /** Advanced states (media queries, container queries, etc.) */
49
- advancedStates?: ParsedAdvancedState[];
50
- /** At-rule context for CSS generation */
51
- atRuleContext?: AtRuleContext;
52
- /** Own mods for sub-element states (from @own()) - applied to sub-element selector */
53
- ownMods?: string[];
54
- /** Negated own mods for sub-element states */
55
- negatedOwnMods?: string[];
56
- }
57
37
  interface ParsedColor {
58
38
  color?: string;
59
39
  name?: string;
60
40
  opacity?: number;
61
41
  }
62
- type StyleStateDataList = StyleStateData[];
63
- type StyleStateDataListMap = Record<string, StyleStateDataList>;
64
42
  type StyleMap = Record<string, StyleValue | StyleValueStateMap>;
65
- type StyleStateMap = Record<string, StyleStateData>;
66
43
  declare const CUSTOM_UNITS: {
67
44
  r: string;
68
45
  cr: string;
@@ -131,47 +108,7 @@ declare function strToRgb(color: string, _ignoreAlpha?: boolean): string | null
131
108
  declare function getRgbValuesFromRgbaString(str: string): number[];
132
109
  declare function hexToRgb(hex: string): string | null;
133
110
  declare function filterMods(mods: string[], allowedMods: string[]): string[];
134
- declare function extendStyles(defaultStyles?: Record<string, unknown> | null, newStyles?: Record<string, unknown> | null): Record<string, unknown>;
135
- /**
136
- * Split properties into style and non-style properties.
137
- * @param props - Component prop map.
138
- * @param [styleList] - List of all style properties.
139
- * @param [defaultStyles] - Default style map of the component.
140
- * @param [propMap] - Props to style alias map.
141
- * @param [ignoreList] - A list of properties to ignore.
142
- */
143
- declare function extractStyles(props: Record<string, unknown>, styleList?: readonly string[], defaultStyles?: Styles, propMap?: Record<string, string>, ignoreList?: readonly string[]): Styles;
144
- /**
145
- * Check if a token is an advanced state (starts with @)
146
- */
147
- declare function isAdvancedStateToken(token: string): boolean;
148
- declare const STATE_OPERATORS: {
149
- NOT: string;
150
- AND: string;
151
- OR: string;
152
- XOR: string;
153
- };
154
- declare const STATE_OPERATOR_LIST: string[];
155
- declare const parseStateNotation: (firstArg: string, secondArg?: string | number | boolean | StyleValueStateMap<string> | StyleStateData | null | undefined) => StyleStateData;
156
- /**
157
- * Build an AtRuleContext from parsed advanced states
158
- */
159
- declare function buildAtRuleContext(advancedStates: ParsedAdvancedState[], negatedStates: Set<string>): AtRuleContext | undefined;
160
- /**
161
- * Parse state notation and return tokens, modifiers and compute model.
162
- * Enhanced to detect and extract advanced states.
163
- */
164
- declare function styleStateMapToStyleStateDataList(styleStateMap: StyleStateMap | StyleValue | StyleValueStateMap, parserContext?: StateParserContext): {
165
- states: StyleStateDataList;
166
- mods: string[];
167
- hasAdvancedStates: boolean;
168
- };
169
- declare const COMPUTE_FUNC_MAP: Record<string, (a: unknown, b?: unknown) => unknown>;
170
- /**
171
- * Compute a result based on a model and incoming map.
172
- */
173
- declare function computeState(computeModel: ComputeModel, valueMap: (number | boolean)[] | Record<string, boolean> | ((...args: unknown[]) => unknown)): unknown;
174
111
  declare function stringifyStyles(styles: unknown): string;
175
112
  //#endregion
176
- export { COMPUTE_FUNC_MAP, CSSMap, CUSTOM_UNITS, ComputeModel, DIRECTIONS, ParsedColor, RawStyleHandler, STATE_OPERATORS, STATE_OPERATOR_LIST, StyleHandler, StyleHandlerDefinition, StyleHandlerResult, StyleMap, StylePropValue, StyleStateData, StyleStateDataList, StyleStateDataListMap, StyleStateMap, StyleValue, StyleValueStateMap, buildAtRuleContext, computeState, customFunc, extendStyles, extractStyles, filterMods, getGlobalFuncs, getGlobalParser, getGlobalPredefinedTokens, getRgbValuesFromRgbaString, hexToRgb, isAdvancedStateToken, normalizeColorTokenValue, parseColor, parseStateNotation, parseStyle, resetGlobalPredefinedTokens, setGlobalPredefinedTokens, strToRgb, stringifyStyles, styleStateMapToStyleStateDataList };
113
+ export { CSSMap, CUSTOM_UNITS, DIRECTIONS, ParsedColor, RawStyleHandler, StyleHandler, StyleHandlerDefinition, StyleHandlerResult, StyleMap, StylePropValue, StyleValue, StyleValueStateMap, customFunc, filterMods, getGlobalFuncs, getGlobalParser, getGlobalPredefinedTokens, getRgbValuesFromRgbaString, hexToRgb, normalizeColorTokenValue, parseColor, parseStyle, resetGlobalPredefinedTokens, setGlobalPredefinedTokens, strToRgb, stringifyStyles };
177
114
  //# sourceMappingURL=styles.d.ts.map
@@ -1,8 +1,5 @@
1
1
  import { StyleParser } from "../parser/parser.js";
2
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
3
  import { okhslToRgb } from "./okhsl-to-rgb.js";
7
4
  import { hslToRgb } from "./hsl-to-rgb.js";
8
5
 
@@ -380,323 +377,12 @@ function hexToRgb(hex) {
380
377
  function filterMods(mods, allowedMods) {
381
378
  return mods.filter((mod) => allowedMods.includes(mod));
382
379
  }
383
- function extendStyles(defaultStyles, newStyles) {
384
- let styles = {};
385
- if (!defaultStyles) {
386
- if (!newStyles) return styles;
387
- } else styles = Object.assign({}, defaultStyles);
388
- if (newStyles) Object.keys(newStyles).forEach((key) => {
389
- if (newStyles[key] != null) styles[key] = newStyles[key];
390
- });
391
- return styles;
392
- }
393
- /**
394
- * Split properties into style and non-style properties.
395
- * @param props - Component prop map.
396
- * @param [styleList] - List of all style properties.
397
- * @param [defaultStyles] - Default style map of the component.
398
- * @param [propMap] - Props to style alias map.
399
- * @param [ignoreList] - A list of properties to ignore.
400
- */
401
- function extractStyles(props, styleList = [], defaultStyles, propMap, ignoreList = []) {
402
- const styles = {
403
- ...defaultStyles,
404
- ...ignoreList.includes("styles") ? void 0 : props.styles && typeof props.styles === "object" ? props.styles : void 0
405
- };
406
- Object.keys(props).forEach((prop) => {
407
- const propName = propMap ? propMap[prop] || prop : prop;
408
- const value = props[prop];
409
- if (ignoreList && ignoreList.includes(prop)) {} else if (styleList.includes(propName)) styles[propName] = value;
410
- }, {});
411
- return styles;
412
- }
413
- 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;
414
- /**
415
- * Check if a token is an advanced state (starts with @)
416
- */
417
- function isAdvancedStateToken(token) {
418
- return token.startsWith("@") || token.startsWith("!@");
419
- }
420
- const STATE_OPERATORS = {
421
- NOT: "!",
422
- AND: "&",
423
- OR: "|",
424
- XOR: "^"
425
- };
426
- const STATE_OPERATOR_LIST = [
427
- "!",
428
- "&",
429
- "|",
430
- "^"
431
- ];
432
- /**
433
- * Convert state notation tokens to a compute model (string, or nested [op, lhs, rhs]).
434
- */
435
- function convertTokensToComputeUnits(tokens) {
436
- if (tokens.length === 1) return tokens[0];
437
- const hasLength = (x) => typeof x === "string" || Array.isArray(x);
438
- STATE_OPERATOR_LIST.forEach((operator) => {
439
- let i;
440
- while ((i = tokens.indexOf(operator)) !== -1) {
441
- const token = tokens[i];
442
- if (token === "!") {
443
- const next = tokens[i + 1];
444
- if (next !== void 0 && hasLength(next) && next.length !== 1) tokens.splice(i, 2, ["!", next]);
445
- else tokens.splice(i, 1);
446
- } else {
447
- const prev = tokens[i - 1];
448
- const next = tokens[i + 1];
449
- if (prev !== void 0 && next !== void 0 && hasLength(prev) && hasLength(next) && prev.length !== 1 && next.length !== 1) tokens.splice(i - 1, 3, [
450
- token,
451
- prev,
452
- next
453
- ]);
454
- else tokens.splice(i, 1);
455
- }
456
- }
457
- });
458
- return tokens.length === 1 ? tokens[0] : tokens;
459
- }
460
- /**
461
- * Replace commas with | only outside of parentheses.
462
- * This preserves commas in advanced states like @(card, w < 600px)
463
- */
464
- function replaceCommasOutsideParens(str) {
465
- let result = "";
466
- let depth = 0;
467
- for (const char of str) if (char === "(") {
468
- depth++;
469
- result += char;
470
- } else if (char === ")") {
471
- depth--;
472
- result += char;
473
- } else if (char === "," && depth === 0) result += "|";
474
- else result += char;
475
- return result;
476
- }
477
- /**
478
- * Parse state notation and return tokens, modifiers and compute model.
479
- */
480
- function parseStateNotationInner(notation, value) {
481
- const tokens = replaceCommasOutsideParens(notation).match(STATES_REGEXP);
482
- if (!tokens || !tokens.length) return {
483
- model: void 0,
484
- mods: [],
485
- notMods: [],
486
- tokens: [],
487
- value
488
- };
489
- else if (tokens.length === 1) return {
490
- model: tokens[0],
491
- mods: tokens.slice(0),
492
- notMods: [],
493
- tokens,
494
- value
495
- };
496
- const mods = [];
497
- const operations = [[]];
498
- let list = operations[0];
499
- let position = 0;
500
- let operation;
501
- tokens.forEach((token) => {
502
- switch (token) {
503
- case "(":
504
- operation = [];
505
- position++;
506
- list = operations[position] = operation;
507
- break;
508
- case ")":
509
- position--;
510
- operations[position].push(convertTokensToComputeUnits(list));
511
- list = operations[position];
512
- break;
513
- default:
514
- if (token.length > 1) {
515
- if (!mods.includes(token)) mods.push(token);
516
- }
517
- list.push(token);
518
- }
519
- });
520
- while (position) {
521
- position--;
522
- operations[position].push(convertTokensToComputeUnits(list));
523
- list = operations[position];
524
- }
525
- return {
526
- tokens,
527
- mods,
528
- notMods: [],
529
- model: convertTokensToComputeUnits(operations[0]),
530
- value
531
- };
532
- }
533
- const parseStateNotation = cacheWrapper(parseStateNotationInner);
534
- /**
535
- * Build an AtRuleContext from parsed advanced states
536
- */
537
- function buildAtRuleContext(advancedStates, negatedStates) {
538
- if (advancedStates.length === 0) return void 0;
539
- const ctx = {};
540
- for (const state of advancedStates) {
541
- const isNegated = negatedStates.has(state.raw);
542
- switch (state.type) {
543
- case "media": {
544
- if (!ctx.media) ctx.media = [];
545
- let mediaCondition = "";
546
- if (state.mediaType) mediaCondition = state.mediaType;
547
- else if (state.condition) mediaCondition = `(${state.condition})`;
548
- if (mediaCondition) if (isNegated) ctx.media.push(`not ${mediaCondition}`);
549
- else ctx.media.push(mediaCondition);
550
- break;
551
- }
552
- case "container": {
553
- if (!ctx.container) ctx.container = [];
554
- let condition = state.condition;
555
- if (isNegated) condition = `not (${condition})`;
556
- ctx.container.push({
557
- name: state.containerName,
558
- condition
559
- });
560
- break;
561
- }
562
- case "root": {
563
- if (!ctx.rootStates) ctx.rootStates = [];
564
- const rootSelector = buildRootSelector(state.condition, isNegated);
565
- ctx.rootStates.push(rootSelector);
566
- break;
567
- }
568
- case "starting":
569
- if (!isNegated) ctx.startingStyle = true;
570
- break;
571
- }
572
- }
573
- if (!ctx.media?.length && !ctx.container?.length && !ctx.rootStates?.length && !ctx.startingStyle) return;
574
- return ctx;
575
- }
576
- /**
577
- * Build a root state selector from a condition
578
- */
579
- function buildRootSelector(condition, isNegated) {
580
- let selector;
581
- if (condition.startsWith(".")) selector = condition;
582
- else if (condition.startsWith("[")) selector = condition;
583
- else if (condition.includes("=")) {
584
- const [key, value] = condition.split("=");
585
- selector = `[data-${camelToKebab(key.trim())}="${value.trim()}"]`;
586
- } else selector = `[data-${camelToKebab(condition)}]`;
587
- if (isNegated) return `:not(${selector})`;
588
- return selector;
589
- }
590
- /**
591
- * Parse state notation and return tokens, modifiers and compute model.
592
- * Enhanced to detect and extract advanced states.
593
- */
594
- function styleStateMapToStyleStateDataList(styleStateMap, parserContext) {
595
- if (typeof styleStateMap !== "object" || !styleStateMap) return {
596
- states: [{
597
- model: void 0,
598
- mods: [],
599
- notMods: [],
600
- value: styleStateMap
601
- }],
602
- mods: [],
603
- hasAdvancedStates: false
604
- };
605
- const stateDataList = [];
606
- let hasAdvancedStates = false;
607
- Object.keys(styleStateMap).forEach((stateNotation) => {
608
- const state = parseStateNotation(stateNotation, styleStateMap[stateNotation]);
609
- const advancedStates = [];
610
- const negatedAdvancedStates = /* @__PURE__ */ new Set();
611
- const regularMods = [];
612
- const ownMods = [];
613
- const negatedOwnMods = [];
614
- if (state.tokens) {
615
- let isNegated = false;
616
- for (const token of state.tokens) {
617
- if (token === "!") {
618
- isNegated = true;
619
- continue;
620
- }
621
- if (isAdvancedStateToken(token)) {
622
- hasAdvancedStates = true;
623
- const parsed = parseAdvancedState(token, parserContext || createStateParserContext(void 0));
624
- advancedStates.push(parsed);
625
- if (parsed.type === "own" && parsed.condition) if (isNegated) negatedOwnMods.push(parsed.condition);
626
- else ownMods.push(parsed.condition);
627
- else if (isNegated) negatedAdvancedStates.add(token);
628
- isNegated = false;
629
- } else if (token.length > 1 && ![
630
- "&",
631
- "|",
632
- "^",
633
- "(",
634
- ")"
635
- ].includes(token)) {
636
- regularMods.push(token);
637
- isNegated = false;
638
- } else isNegated = false;
639
- }
640
- }
641
- if (advancedStates.length > 0) {
642
- state.advancedStates = advancedStates;
643
- state.atRuleContext = buildAtRuleContext(advancedStates, negatedAdvancedStates);
644
- state.mods = regularMods;
645
- }
646
- if (ownMods.length > 0) state.ownMods = ownMods;
647
- if (negatedOwnMods.length > 0) state.negatedOwnMods = negatedOwnMods;
648
- stateDataList.push(state);
649
- });
650
- stateDataList.reverse();
651
- let initialState;
652
- const allMods = stateDataList.reduce((all, state) => {
653
- if (!state.mods.length && !state.advancedStates?.length) initialState = state;
654
- else state.mods.forEach((mod) => {
655
- if (!all.includes(mod)) all.push(mod);
656
- });
657
- return all;
658
- }, []);
659
- if (!initialState) stateDataList.push({
660
- mods: [],
661
- notMods: allMods,
662
- value: true
663
- });
664
- return {
665
- states: stateDataList,
666
- mods: allMods,
667
- hasAdvancedStates
668
- };
669
- }
670
- const COMPUTE_FUNC_MAP = {
671
- "!": (a) => !a,
672
- "^": (a, b) => a && !b || !a && b,
673
- "|": (a, b) => a || b,
674
- "&": (a, b) => a && b
675
- };
676
- /**
677
- * Compute a result based on a model and incoming map.
678
- */
679
- function computeState(computeModel, valueMap) {
680
- if (!computeModel) return true;
681
- const map = valueMap;
682
- if (!Array.isArray(computeModel)) if (typeof valueMap === "function") return !!valueMap(computeModel);
683
- else return !!map[computeModel];
684
- const func = COMPUTE_FUNC_MAP[computeModel[0]];
685
- if (!func) console.warn("CubeUIKit: unexpected compute method in the model", computeModel);
686
- let a = computeModel[1];
687
- if (typeof a === "object") a = !!computeState(a, valueMap);
688
- else if (typeof valueMap === "function") a = !!valueMap(a);
689
- else a = !!map[a];
690
- if (computeModel.length === 2) return func(a);
691
- let b = computeModel[2];
692
- if (typeof b === "object") b = !!computeState(b, valueMap);
693
- else if (typeof valueMap === "function") b = !!valueMap(b);
694
- else b = !!map[b];
695
- return !!func(a, b);
696
- }
697
380
  const _innerCache = /* @__PURE__ */ new WeakMap();
381
+ const _topLevelCache = /* @__PURE__ */ new WeakMap();
698
382
  function stringifyStyles(styles) {
699
383
  if (styles == null || typeof styles !== "object") return "";
384
+ const cached = _topLevelCache.get(styles);
385
+ if (cached !== void 0) return cached;
700
386
  const obj = styles;
701
387
  const keys = Object.keys(obj).sort();
702
388
  const parts = [];
@@ -722,9 +408,11 @@ function stringifyStyles(styles) {
722
408
  } else sv = JSON.stringify(v);
723
409
  parts.push(JSON.stringify(k) + ":" + sv);
724
410
  }
725
- return "{" + parts.join(",") + "}";
411
+ const result = "{" + parts.join(",") + "}";
412
+ _topLevelCache.set(styles, result);
413
+ return result;
726
414
  }
727
415
 
728
416
  //#endregion
729
- export { COMPUTE_FUNC_MAP, CUSTOM_UNITS, DIRECTIONS, STATE_OPERATORS, STATE_OPERATOR_LIST, buildAtRuleContext, computeState, customFunc, extendStyles, extractStyles, filterMods, getGlobalFuncs, getGlobalParser, getGlobalPredefinedTokens, getRgbValuesFromRgbaString, hexToRgb, isAdvancedStateToken, normalizeColorTokenValue, parseColor, parseStateNotation, parseStyle, resetGlobalPredefinedTokens, setGlobalPredefinedTokens, strToRgb, stringifyStyles, styleStateMapToStyleStateDataList };
417
+ export { CUSTOM_UNITS, DIRECTIONS, customFunc, filterMods, getGlobalFuncs, getGlobalParser, getGlobalPredefinedTokens, getRgbValuesFromRgbaString, hexToRgb, normalizeColorTokenValue, parseColor, parseStyle, resetGlobalPredefinedTokens, setGlobalPredefinedTokens, strToRgb, stringifyStyles };
730
418
  //# sourceMappingURL=styles.js.map