@tenphi/tasty 0.0.0-snapshot.26b4630 → 0.0.0-snapshot.2705ab9

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 (218) hide show
  1. package/README.md +315 -159
  2. package/dist/chunks/cacheKey.js +16 -8
  3. package/dist/chunks/cacheKey.js.map +1 -1
  4. package/dist/chunks/definitions.d.ts +1 -1
  5. package/dist/chunks/definitions.js +2 -3
  6. package/dist/chunks/definitions.js.map +1 -1
  7. package/dist/chunks/renderChunk.js +31 -32
  8. package/dist/chunks/renderChunk.js.map +1 -1
  9. package/dist/config.d.ts +98 -12
  10. package/dist/config.js +134 -33
  11. package/dist/config.js.map +1 -1
  12. package/dist/core/index.d.ts +11 -10
  13. package/dist/core/index.js +8 -7
  14. package/dist/counter-style/index.js +51 -0
  15. package/dist/counter-style/index.js.map +1 -0
  16. package/dist/debug.d.ts +26 -141
  17. package/dist/debug.js +356 -635
  18. package/dist/debug.js.map +1 -1
  19. package/dist/font-face/index.js +63 -0
  20. package/dist/font-face/index.js.map +1 -0
  21. package/dist/hooks/resolve-ssr-collector.js +15 -0
  22. package/dist/hooks/resolve-ssr-collector.js.map +1 -0
  23. package/dist/hooks/useCounterStyle.d.ts +50 -0
  24. package/dist/hooks/useCounterStyle.js +47 -0
  25. package/dist/hooks/useCounterStyle.js.map +1 -0
  26. package/dist/hooks/useFontFace.d.ts +43 -0
  27. package/dist/hooks/useFontFace.js +71 -0
  28. package/dist/hooks/useFontFace.js.map +1 -0
  29. package/dist/hooks/useGlobalStyles.d.ts +3 -0
  30. package/dist/hooks/useGlobalStyles.js +24 -1
  31. package/dist/hooks/useGlobalStyles.js.map +1 -1
  32. package/dist/hooks/useKeyframes.js +14 -3
  33. package/dist/hooks/useKeyframes.js.map +1 -1
  34. package/dist/hooks/useProperty.js +32 -13
  35. package/dist/hooks/useProperty.js.map +1 -1
  36. package/dist/hooks/useRawCSS.js +9 -1
  37. package/dist/hooks/useRawCSS.js.map +1 -1
  38. package/dist/hooks/useStyles.d.ts +5 -0
  39. package/dist/hooks/useStyles.js +115 -46
  40. package/dist/hooks/useStyles.js.map +1 -1
  41. package/dist/index.d.ts +22 -11
  42. package/dist/index.js +10 -7
  43. package/dist/injector/index.d.ts +28 -2
  44. package/dist/injector/index.js +27 -1
  45. package/dist/injector/index.js.map +1 -1
  46. package/dist/injector/injector.d.ts +28 -1
  47. package/dist/injector/injector.js +93 -32
  48. package/dist/injector/injector.js.map +1 -1
  49. package/dist/injector/sheet-manager.d.ts +16 -7
  50. package/dist/injector/sheet-manager.js +31 -11
  51. package/dist/injector/sheet-manager.js.map +1 -1
  52. package/dist/injector/types.d.ts +70 -1
  53. package/dist/parser/classify.js +5 -4
  54. package/dist/parser/classify.js.map +1 -1
  55. package/dist/parser/const.js +17 -1
  56. package/dist/parser/const.js.map +1 -1
  57. package/dist/parser/parser.js +1 -1
  58. package/dist/pipeline/conditions.js +14 -8
  59. package/dist/pipeline/conditions.js.map +1 -1
  60. package/dist/pipeline/index.d.ts +3 -1
  61. package/dist/pipeline/index.js +137 -69
  62. package/dist/pipeline/index.js.map +1 -1
  63. package/dist/pipeline/materialize.js +404 -208
  64. package/dist/pipeline/materialize.js.map +1 -1
  65. package/dist/pipeline/parseStateKey.d.ts +1 -1
  66. package/dist/pipeline/parseStateKey.js +37 -20
  67. package/dist/pipeline/parseStateKey.js.map +1 -1
  68. package/dist/pipeline/simplify.js +111 -152
  69. package/dist/pipeline/simplify.js.map +1 -1
  70. package/dist/pipeline/warnings.js +18 -0
  71. package/dist/pipeline/warnings.js.map +1 -0
  72. package/dist/plugins/okhsl-plugin.js +2 -275
  73. package/dist/plugins/okhsl-plugin.js.map +1 -1
  74. package/dist/plugins/types.d.ts +9 -2
  75. package/dist/properties/index.js +82 -17
  76. package/dist/properties/index.js.map +1 -1
  77. package/dist/properties/property-type-resolver.d.ts +24 -0
  78. package/dist/properties/property-type-resolver.js +91 -0
  79. package/dist/properties/property-type-resolver.js.map +1 -0
  80. package/dist/ssr/astro.d.ts +29 -0
  81. package/dist/ssr/astro.js +65 -0
  82. package/dist/ssr/astro.js.map +1 -0
  83. package/dist/ssr/async-storage.d.ts +17 -0
  84. package/dist/ssr/async-storage.js +35 -0
  85. package/dist/ssr/async-storage.js.map +1 -0
  86. package/dist/ssr/collect-auto-properties.js +40 -0
  87. package/dist/ssr/collect-auto-properties.js.map +1 -0
  88. package/dist/ssr/collector.d.ts +102 -0
  89. package/dist/ssr/collector.js +227 -0
  90. package/dist/ssr/collector.js.map +1 -0
  91. package/dist/ssr/context.d.ts +8 -0
  92. package/dist/ssr/context.js +14 -0
  93. package/dist/ssr/context.js.map +1 -0
  94. package/dist/ssr/format-global-rules.js +22 -0
  95. package/dist/ssr/format-global-rules.js.map +1 -0
  96. package/dist/ssr/format-keyframes.js +70 -0
  97. package/dist/ssr/format-keyframes.js.map +1 -0
  98. package/dist/ssr/format-property.js +50 -0
  99. package/dist/ssr/format-property.js.map +1 -0
  100. package/dist/ssr/format-rules.js +73 -0
  101. package/dist/ssr/format-rules.js.map +1 -0
  102. package/dist/ssr/hydrate.d.ts +22 -0
  103. package/dist/ssr/hydrate.js +50 -0
  104. package/dist/ssr/hydrate.js.map +1 -0
  105. package/dist/ssr/index.d.ts +5 -0
  106. package/dist/ssr/index.js +12 -0
  107. package/dist/ssr/index.js.map +1 -0
  108. package/dist/ssr/next.d.ts +45 -0
  109. package/dist/ssr/next.js +71 -0
  110. package/dist/ssr/next.js.map +1 -0
  111. package/dist/ssr/ssr-collector-ref.js +12 -0
  112. package/dist/ssr/ssr-collector-ref.js.map +1 -0
  113. package/dist/states/index.js +12 -257
  114. package/dist/states/index.js.map +1 -1
  115. package/dist/styles/align.d.ts +1 -1
  116. package/dist/styles/align.js.map +1 -1
  117. package/dist/styles/border.d.ts +1 -1
  118. package/dist/styles/border.js +2 -2
  119. package/dist/styles/border.js.map +1 -1
  120. package/dist/styles/color.d.ts +2 -2
  121. package/dist/styles/color.js +9 -5
  122. package/dist/styles/color.js.map +1 -1
  123. package/dist/styles/createStyle.js +25 -22
  124. package/dist/styles/createStyle.js.map +1 -1
  125. package/dist/styles/fade.d.ts +1 -1
  126. package/dist/styles/fade.js.map +1 -1
  127. package/dist/styles/fill.d.ts +14 -16
  128. package/dist/styles/fill.js +6 -5
  129. package/dist/styles/fill.js.map +1 -1
  130. package/dist/styles/flow.d.ts +3 -3
  131. package/dist/styles/flow.js.map +1 -1
  132. package/dist/styles/index.js +1 -1
  133. package/dist/styles/justify.d.ts +1 -1
  134. package/dist/styles/justify.js.map +1 -1
  135. package/dist/styles/predefined.d.ts +0 -2
  136. package/dist/styles/predefined.js +1 -4
  137. package/dist/styles/predefined.js.map +1 -1
  138. package/dist/styles/preset.d.ts +5 -0
  139. package/dist/styles/preset.js +48 -47
  140. package/dist/styles/preset.js.map +1 -1
  141. package/dist/styles/radius.d.ts +1 -1
  142. package/dist/styles/radius.js.map +1 -1
  143. package/dist/styles/scrollbar.d.ts +9 -5
  144. package/dist/styles/scrollbar.js +25 -82
  145. package/dist/styles/scrollbar.js.map +1 -1
  146. package/dist/styles/shadow.d.ts +2 -2
  147. package/dist/styles/shadow.js.map +1 -1
  148. package/dist/styles/transition.d.ts +1 -1
  149. package/dist/styles/transition.js +1 -1
  150. package/dist/styles/transition.js.map +1 -1
  151. package/dist/styles/types.d.ts +70 -21
  152. package/dist/tasty.d.ts +30 -893
  153. package/dist/tasty.js +60 -19
  154. package/dist/tasty.js.map +1 -1
  155. package/dist/types.d.ts +3 -3
  156. package/dist/utils/cache-wrapper.js +4 -8
  157. package/dist/utils/cache-wrapper.js.map +1 -1
  158. package/dist/utils/color-math.d.ts +46 -0
  159. package/dist/utils/color-math.js +749 -0
  160. package/dist/utils/color-math.js.map +1 -0
  161. package/dist/utils/color-space.d.ts +5 -0
  162. package/dist/utils/color-space.js +229 -0
  163. package/dist/utils/color-space.js.map +1 -0
  164. package/dist/utils/colors.d.ts +1 -1
  165. package/dist/utils/colors.js +3 -1
  166. package/dist/utils/colors.js.map +1 -1
  167. package/dist/utils/css-types.d.ts +1 -1
  168. package/dist/utils/dotize.d.ts +1 -1
  169. package/dist/utils/has-keys.js +13 -0
  170. package/dist/utils/has-keys.js.map +1 -0
  171. package/dist/utils/mod-attrs.js +2 -2
  172. package/dist/utils/mod-attrs.js.map +1 -1
  173. package/dist/utils/process-tokens.d.ts +3 -13
  174. package/dist/utils/process-tokens.js +18 -98
  175. package/dist/utils/process-tokens.js.map +1 -1
  176. package/dist/utils/selector-transform.js +32 -0
  177. package/dist/utils/selector-transform.js.map +1 -0
  178. package/dist/utils/string.js.map +1 -1
  179. package/dist/utils/styles.d.ts +4 -88
  180. package/dist/utils/styles.js +34 -398
  181. package/dist/utils/styles.js.map +1 -1
  182. package/dist/utils/typography.d.ts +24 -13
  183. package/dist/utils/typography.js +14 -16
  184. package/dist/utils/typography.js.map +1 -1
  185. package/dist/zero/babel.d.ts +67 -8
  186. package/dist/zero/babel.js +109 -17
  187. package/dist/zero/babel.js.map +1 -1
  188. package/dist/zero/extractor.js +118 -1
  189. package/dist/zero/extractor.js.map +1 -1
  190. package/dist/zero/next.d.ts +44 -30
  191. package/dist/zero/next.js +102 -38
  192. package/dist/zero/next.js.map +1 -1
  193. package/docs/PIPELINE.md +519 -0
  194. package/docs/README.md +31 -0
  195. package/docs/adoption.md +296 -0
  196. package/docs/comparison.md +420 -0
  197. package/docs/configuration.md +326 -0
  198. package/docs/debug.md +318 -0
  199. package/docs/design-system.md +424 -0
  200. package/docs/dsl.md +673 -0
  201. package/docs/getting-started.md +217 -0
  202. package/docs/injector.md +528 -0
  203. package/docs/methodology.md +567 -0
  204. package/docs/runtime.md +485 -0
  205. package/docs/ssr.md +384 -0
  206. package/docs/styles.md +579 -0
  207. package/docs/tasty-static.md +433 -0
  208. package/package.json +98 -28
  209. package/dist/styles/styledScrollbar.d.ts +0 -47
  210. package/dist/styles/styledScrollbar.js +0 -38
  211. package/dist/styles/styledScrollbar.js.map +0 -1
  212. package/dist/tokens/typography.d.ts +0 -19
  213. package/dist/tokens/typography.js +0 -237
  214. package/dist/tokens/typography.js.map +0 -1
  215. package/dist/utils/hsl-to-rgb.js +0 -38
  216. package/dist/utils/hsl-to-rgb.js.map +0 -1
  217. package/dist/utils/okhsl-to-rgb.js +0 -296
  218. package/dist/utils/okhsl-to-rgb.js.map +0 -1
@@ -1,12 +1,13 @@
1
1
  import { Lru } from "../parser/lru.js";
2
- import { createStateParserContext, extractLocalPredefinedStates } from "../states/index.js";
3
2
  import { stringifyStyles } from "../utils/styles.js";
4
3
  import { createStyle } from "../styles/createStyle.js";
5
4
  import { STYLE_HANDLER_MAP } from "../styles/index.js";
5
+ import { createStateParserContext, extractLocalPredefinedStates } from "../states/index.js";
6
6
  import { and, falseCondition, not, or, trueCondition } from "./conditions.js";
7
7
  import { simplifyCondition } from "./simplify.js";
8
8
  import { buildExclusiveConditions, expandExclusiveOrs, expandOrConditions, isValueMapping, parseStyleEntries } from "./exclusive.js";
9
- import { buildAtRulesFromVariant, conditionToCSS, modifierToCSS, parentGroupsToCSS, pseudoToCSS, rootConditionsToCSS, selectorConditionToCSS } from "./materialize.js";
9
+ import { branchToCSS, buildAtRulesFromVariant, conditionToCSS, mergeVariantsIntoSelectorGroups, optimizeGroups, parentGroupsToCSS, rootGroupsToCSS, selectorGroupToCSS } from "./materialize.js";
10
+ import { emitWarning } from "./warnings.js";
10
11
  import { parseStateKey } from "./parseStateKey.js";
11
12
 
12
13
  //#region src/pipeline/index.ts
@@ -27,6 +28,13 @@ import { parseStateKey } from "./parseStateKey.js";
27
28
  */
28
29
  const pipelineCache = new Lru(5e3);
29
30
  /**
31
+ * Check if a cache key exists in the pipeline cache.
32
+ * Used by renderStylesForChunk to avoid building filtered styles on cache hit.
33
+ */
34
+ function hasPipelineCacheEntry(cacheKey) {
35
+ return pipelineCache.get(cacheKey) !== void 0;
36
+ }
37
+ /**
30
38
  * Clear the pipeline cache (for testing)
31
39
  */
32
40
  function clearPipelineCache() {
@@ -36,12 +44,17 @@ function runPipeline(styles, parserContext) {
36
44
  const allRules = [];
37
45
  processStyles(styles, "", parserContext, allRules);
38
46
  const seen = /* @__PURE__ */ new Set();
39
- return allRules.filter((rule) => {
40
- const key = `${rule.selector}|${rule.declarations}|${JSON.stringify(rule.atRules || [])}|${rule.rootPrefix || ""}`;
47
+ const dedupedRules = allRules.filter((rule) => {
48
+ const key = `${rule.selector}|${rule.declarations}|${rule.atRules?.join("|") ?? ""}|${rule.rootPrefix || ""}|${rule.startingStyle ? "1" : "0"}`;
41
49
  if (seen.has(key)) return false;
42
50
  seen.add(key);
43
51
  return true;
44
52
  });
53
+ const normal = [];
54
+ const starting = [];
55
+ for (const rule of dedupedRules) if (rule.startingStyle) starting.push(rule);
56
+ else normal.push(rule);
57
+ return normal.concat(starting);
45
58
  }
46
59
  /**
47
60
  * Process styles at a given nesting level
@@ -147,7 +160,7 @@ function getAllSelectors(key, styles) {
147
160
  if (affix !== void 0) {
148
161
  const result = processAffix(String(affix), key);
149
162
  if (!result.valid) {
150
- console.warn(`[Tasty] ${result.reason}`);
163
+ emitWarning("INVALID_SELECTOR_AFFIX", result.reason);
151
164
  return null;
152
165
  }
153
166
  return result.selectors;
@@ -162,7 +175,8 @@ function getAllSelectors(key, styles) {
162
175
  * Supports:
163
176
  * - Direct child: '>'
164
177
  * - Chained elements: '>Body>Row>'
165
- * - HTML tags: 'a', '>ul>li', 'button:hover'
178
+ * - HTML tags (no key injection): 'h1', '>ul>li', 'button:hover'
179
+ * - Universal selector: '*', 'h1 *'
166
180
  * - Pseudo-elements on root: '::before'
167
181
  * - Pseudo on sub-element: '@::before', '>@:hover'
168
182
  * - Classes: '.active', '>@.active'
@@ -199,6 +213,7 @@ function processAffix(affix, key) {
199
213
  */
200
214
  const VALID_TOKEN_PATTERNS = [
201
215
  /^[>+~]/,
216
+ /^\*/,
202
217
  /^[A-Z][a-zA-Z0-9]*/,
203
218
  /^@/,
204
219
  /^::?[a-z][a-z0-9-]*(?:\([^)]*\))?/,
@@ -333,12 +348,13 @@ function processSinglePattern(pattern, key) {
333
348
  * The tokenizer handles these token types in order:
334
349
  * 1. Whitespace (skipped)
335
350
  * 2. Combinators: >, +, ~ (add surrounding spaces)
336
- * 3. Uppercase names: Body, Row (convert to [data-element="..."])
337
- * 4. @ placeholder (keep for later replacement)
338
- * 5. Pseudo: :hover, ::before (attach to previous token)
339
- * 6. Tags: a, div, button (keep as-is with spacing)
340
- * 7. Classes: .active (attach to previous element/tag/placeholder)
341
- * 8. Attributes: [type="text"] (keep as-is)
351
+ * 3. Universal selector: * (keep as-is with spacing)
352
+ * 4. Uppercase names: Body, Row (convert to [data-element="..."])
353
+ * 5. @ placeholder (keep for later replacement)
354
+ * 6. Pseudo: :hover, ::before (attach to previous token)
355
+ * 7. Tags: a, div, button (keep as-is with spacing)
356
+ * 8. Classes: .active (attach to previous element/tag/placeholder)
357
+ * 9. Attributes: [type="text"] (keep as-is)
342
358
  *
343
359
  * @param pattern - The raw selector pattern to transform
344
360
  * @returns Transformed pattern with proper CSS selector syntax
@@ -352,6 +368,7 @@ function processSinglePattern(pattern, key) {
352
368
  */
353
369
  function transformPattern(pattern) {
354
370
  let result = "";
371
+ let lastCh = "";
355
372
  let i = 0;
356
373
  while (i < pattern.length) {
357
374
  const char = pattern[i];
@@ -360,76 +377,80 @@ function transformPattern(pattern) {
360
377
  continue;
361
378
  }
362
379
  if (/[>+~]/.test(char)) {
363
- if (result && !result.endsWith(" ")) result += " ";
380
+ if (result && lastCh !== " ") result += " ";
364
381
  result += char;
382
+ lastCh = char;
383
+ i++;
384
+ continue;
385
+ }
386
+ if (char === "*") {
387
+ if (result && lastCh !== " ") result += " ";
388
+ result += "*";
389
+ lastCh = "*";
365
390
  i++;
366
391
  continue;
367
392
  }
368
393
  if (/[A-Z]/.test(char)) {
369
- let name = "";
370
- while (i < pattern.length && /[a-zA-Z0-9]/.test(pattern[i])) {
371
- name += pattern[i];
372
- i++;
373
- }
374
- if (result && !result.endsWith(" ")) result += " ";
375
- result += `[data-element="${name}"]`;
394
+ const nameStart = i;
395
+ while (i < pattern.length && /[a-zA-Z0-9]/.test(pattern[i])) i++;
396
+ if (result && lastCh !== " ") result += " ";
397
+ const segment = `[data-element="${pattern.slice(nameStart, i)}"]`;
398
+ result += segment;
399
+ lastCh = "]";
376
400
  continue;
377
401
  }
378
402
  if (char === "@") {
379
- if (result && !result.endsWith(" ")) result += " ";
403
+ if (result && lastCh !== " ") result += " ";
380
404
  result += "@";
405
+ lastCh = "@";
381
406
  i++;
382
407
  continue;
383
408
  }
384
409
  if (char === ":") {
385
- let pseudo = "";
386
- while (i < pattern.length && !/[\s>+~,@]/.test(pattern[i]) && !/[A-Z]/.test(pattern[i])) {
387
- pseudo += pattern[i];
388
- i++;
389
- }
390
- result += pseudo;
410
+ const pseudoStart = i;
411
+ while (i < pattern.length && !/[\s>+~,@]/.test(pattern[i]) && !/[A-Z]/.test(pattern[i])) i++;
412
+ const segment = pattern.slice(pseudoStart, i);
413
+ result += segment;
414
+ lastCh = segment[segment.length - 1] || lastCh;
391
415
  continue;
392
416
  }
393
417
  if (/[a-z]/.test(char)) {
394
- let tag = "";
395
- while (i < pattern.length && /[a-z0-9-]/.test(pattern[i])) {
396
- tag += pattern[i];
397
- i++;
398
- }
399
- if (result && !result.endsWith(" ")) result += " ";
400
- result += tag;
418
+ const tagStart = i;
419
+ while (i < pattern.length && /[a-z0-9-]/.test(pattern[i])) i++;
420
+ if (result && lastCh !== " ") result += " ";
421
+ const segment = pattern.slice(tagStart, i);
422
+ result += segment;
423
+ lastCh = segment[segment.length - 1] || lastCh;
401
424
  continue;
402
425
  }
403
426
  if (char === ".") {
404
- const lastNonSpace = result.replace(/\s+$/, "").slice(-1);
405
- const attachToLast = lastNonSpace === "]" || lastNonSpace === "@" || /[a-zA-Z0-9-]/.test(lastNonSpace);
406
- if (result && !attachToLast && !result.endsWith(" ")) result += " ";
407
- let cls = ".";
427
+ const attachToLast = lastCh === "]" || lastCh === "@" || /[a-zA-Z0-9-]/.test(lastCh);
428
+ if (result && !attachToLast && lastCh !== " ") result += " ";
429
+ const clsStart = i;
408
430
  i++;
409
- while (i < pattern.length && /[a-zA-Z0-9_-]/.test(pattern[i])) {
410
- cls += pattern[i];
411
- i++;
412
- }
413
- result += cls;
431
+ while (i < pattern.length && /[a-zA-Z0-9_-]/.test(pattern[i])) i++;
432
+ const segment = pattern.slice(clsStart, i);
433
+ result += segment;
434
+ lastCh = segment[segment.length - 1] || lastCh;
414
435
  continue;
415
436
  }
416
437
  if (char === "[") {
417
- const lastNonSpace = result.replace(/\s+$/, "").slice(-1);
418
- const attachToLast = lastNonSpace === "]" || lastNonSpace === "@" || /[a-zA-Z0-9-]/.test(lastNonSpace);
419
- if (result && !attachToLast && !result.endsWith(" ")) result += " ";
420
- let attr = "";
438
+ const attachToLast = lastCh === "]" || lastCh === "@" || /[a-zA-Z0-9-]/.test(lastCh);
439
+ if (result && !attachToLast && lastCh !== " ") result += " ";
440
+ const attrStart = i;
421
441
  let depth = 0;
422
442
  while (i < pattern.length) {
423
- attr += pattern[i];
424
443
  if (pattern[i] === "[") depth++;
425
444
  if (pattern[i] === "]") depth--;
426
445
  i++;
427
446
  if (depth === 0) break;
428
447
  }
429
- result += attr;
448
+ result += pattern.slice(attrStart, i);
449
+ lastCh = "]";
430
450
  continue;
431
451
  }
432
452
  result += char;
453
+ lastCh = char;
433
454
  i++;
434
455
  }
435
456
  return result;
@@ -443,7 +464,8 @@ function transformPattern(pattern) {
443
464
  * |----------------|-------------|---------|--------|
444
465
  * | Combinator (>, +, ~) | Yes | `'>Body>'` | `> [data-element="Body"] > [el]` |
445
466
  * | Uppercase element | Yes | `'>Body>Row'` | `> [el1] > [el2] [key]` |
446
- * | Lowercase tag | Yes | `'>ul>li'` | `> ul > li [key]` |
467
+ * | Lowercase tag | No | `'h1'` | ` h1` |
468
+ * | Universal (*) | No | `'h1 *'` | ` h1 *` |
447
469
  * | Pseudo (:hover, ::before) | No | `'::before'` | `::before` |
448
470
  * | Class (.active) | No | `'.active'` | `.active` |
449
471
  * | Attribute ([type]) | No | `'[type="text"]'` | `[type="text"]` |
@@ -454,7 +476,8 @@ function transformPattern(pattern) {
454
476
  * @example
455
477
  * shouldInjectKey('>') // → true (trailing combinator)
456
478
  * shouldInjectKey('>Body>Row') // → true (ends with element)
457
- * shouldInjectKey('>ul>li') // → true (ends with tag)
479
+ * shouldInjectKey('h1') // → false (ends with tag)
480
+ * shouldInjectKey('*') // → false (universal selector)
458
481
  * shouldInjectKey('::before') // → false (ends with pseudo)
459
482
  * shouldInjectKey('.active') // → false (ends with class)
460
483
  * shouldInjectKey('a:hover') // → false (ends with pseudo)
@@ -464,7 +487,6 @@ function shouldInjectKey(pattern) {
464
487
  const trimmed = pattern.trim();
465
488
  if (/[>+~]$/.test(trimmed)) return true;
466
489
  if (/(?:^|[\s>+~\]:])[A-Z][a-zA-Z0-9]*$/.test(trimmed)) return true;
467
- if (/(?<![:.])(?:^|[\s>+~])[a-z][a-z0-9-]*$/.test(trimmed)) return true;
468
490
  return false;
469
491
  }
470
492
  /**
@@ -525,7 +547,27 @@ function cartesianProduct(arrays) {
525
547
  if (arrays.length === 0) return [[]];
526
548
  const nonEmpty = arrays.filter((a) => a.length > 0);
527
549
  if (nonEmpty.length === 0) return [[]];
528
- return nonEmpty.reduce((acc, arr) => acc.flatMap((combo) => arr.map((item) => [...combo, item])), [[]]);
550
+ let result = [[]];
551
+ for (const arr of nonEmpty) {
552
+ const next = [];
553
+ for (const combo of result) for (const item of arr) {
554
+ const newCombo = new Array(combo.length + 1);
555
+ for (let i = 0; i < combo.length; i++) newCombo[i] = combo[i];
556
+ newCombo[combo.length] = item;
557
+ next.push(newCombo);
558
+ }
559
+ result = next;
560
+ }
561
+ return result;
562
+ }
563
+ const declStringCache = /* @__PURE__ */ new WeakMap();
564
+ function stringifyDeclarations(decl) {
565
+ let cached = declStringCache.get(decl);
566
+ if (cached === void 0) {
567
+ cached = JSON.stringify(decl);
568
+ declStringCache.set(decl, cached);
569
+ }
570
+ return cached;
529
571
  }
530
572
  /**
531
573
  * Merge rules with identical CSS output
@@ -533,7 +575,7 @@ function cartesianProduct(arrays) {
533
575
  function mergeByValue(rules) {
534
576
  const groups = /* @__PURE__ */ new Map();
535
577
  for (const rule of rules) {
536
- const key = `${rule.selectorSuffix}|${JSON.stringify(rule.declarations)}`;
578
+ const key = `${rule.selectorSuffix}|${stringifyDeclarations(rule.declarations)}`;
537
579
  if (!groups.has(key)) groups.set(key, []);
538
580
  groups.get(key).push(rule);
539
581
  }
@@ -554,11 +596,12 @@ function mergeByValue(rules) {
554
596
  */
555
597
  function buildSelectorFromVariant(variant, selectorSuffix) {
556
598
  let selector = "";
557
- for (const mod of variant.modifierConditions) selector += modifierToCSS(mod);
558
- for (const pseudo of variant.pseudoConditions) selector += pseudoToCSS(pseudo);
599
+ selector += branchToCSS([...variant.modifierConditions, ...variant.pseudoConditions]);
600
+ for (const group of variant.selectorGroups) selector += selectorGroupToCSS(group);
559
601
  if (variant.parentGroups.length > 0) selector += parentGroupsToCSS(variant.parentGroups);
560
602
  selector += selectorSuffix;
561
- for (const own of variant.ownConditions) selector += selectorConditionToCSS(own);
603
+ const ownOptimized = optimizeGroups(variant.ownGroups);
604
+ for (const group of ownOptimized) selector += selectorGroupToCSS(group);
562
605
  return selector;
563
606
  }
564
607
  /**
@@ -572,45 +615,68 @@ function materializeComputedRule(rule) {
572
615
  if (components.isImpossible || components.variants.length === 0) return [];
573
616
  const declarations = Object.entries(rule.declarations).map(([prop, value]) => `${prop}: ${value};`).join(" ");
574
617
  const getRootPrefixKey = (variant) => {
575
- return variant.rootConditions.map((r) => selectorConditionToCSS(r)).sort().join("|");
618
+ return rootGroupsToCSS(variant.rootGroups) || "";
576
619
  };
577
620
  const byAtRules = /* @__PURE__ */ new Map();
578
621
  for (const variant of components.variants) {
579
622
  const atRules = buildAtRulesFromVariant(variant);
580
- const key = atRules.sort().join("|||") + "###" + getRootPrefixKey(variant);
623
+ const startingStyle = variant.startingStyle;
624
+ const key = atRules.sort().join("|||") + "###" + getRootPrefixKey(variant) + "###" + (startingStyle ? "1" : "0");
581
625
  const group = byAtRules.get(key);
582
626
  if (group) group.variants.push(variant);
583
627
  else byAtRules.set(key, {
584
628
  variants: [variant],
585
629
  atRules,
586
- rootPrefix: rootConditionsToCSS(variant.rootConditions)
630
+ rootPrefix: rootGroupsToCSS(variant.rootGroups),
631
+ startingStyle: startingStyle || void 0
587
632
  });
588
633
  }
589
634
  const rules = [];
590
635
  for (const [, group] of byAtRules) {
591
- const selectorFragments = group.variants.map((v) => buildSelectorFromVariant(v, rule.selectorSuffix));
636
+ const selectorFragments = mergeVariantsIntoSelectorGroups(group.variants).map((v) => buildSelectorFromVariant(v, rule.selectorSuffix));
592
637
  const cssRule = {
593
638
  selector: selectorFragments.length === 1 ? selectorFragments[0] : selectorFragments,
594
639
  declarations
595
640
  };
596
641
  if (group.atRules.length > 0) cssRule.atRules = group.atRules;
597
642
  if (group.rootPrefix) cssRule.rootPrefix = group.rootPrefix;
643
+ if (group.startingStyle) cssRule.startingStyle = true;
598
644
  rules.push(cssRule);
599
645
  }
600
646
  return rules;
601
647
  }
602
- function renderStyles(styles, classNameOrSelector, options) {
648
+ /**
649
+ * Merge StyleResult entries that share the same selector and at-rules,
650
+ * concatenating their declarations into a single rule.
651
+ *
652
+ * This reduces CSS output size when many style keys (e.g. design tokens)
653
+ * resolve to the same selector/state combination.
654
+ */
655
+ function mergeStyleResults(results) {
656
+ if (results.length <= 1) return results;
657
+ const groups = /* @__PURE__ */ new Map();
658
+ for (const result of results) {
659
+ const key = `${result.atRules?.join("|") ?? ""}||${result.selector}||${result.startingStyle ? "1" : "0"}`;
660
+ const existing = groups.get(key);
661
+ if (existing) existing.declarations = existing.declarations ? `${existing.declarations} ${result.declarations}` : result.declarations;
662
+ else groups.set(key, { ...result });
663
+ }
664
+ return Array.from(groups.values());
665
+ }
666
+ function renderStyles(styles, classNameOrSelector, options, pipelineCacheKey) {
603
667
  const directSelector = !!classNameOrSelector;
604
- if (!styles) return directSelector ? [] : { rules: [] };
605
- const cacheKey = stringifyStyles(styles);
606
- let rules = pipelineCache.get(cacheKey);
668
+ let rules;
669
+ if (pipelineCacheKey) rules = pipelineCache.get(pipelineCacheKey);
670
+ if (!rules && !styles) return directSelector ? [] : { rules: [] };
671
+ const cacheKey = pipelineCacheKey || stringifyStyles(styles);
672
+ if (!rules) rules = pipelineCache.get(cacheKey);
607
673
  if (!rules) {
608
674
  rules = runPipeline(styles, createStateParserContext(styles));
609
675
  pipelineCache.set(cacheKey, rules);
610
676
  }
611
677
  if (directSelector) {
612
678
  const shouldDouble = options?.doubleSelector ?? false;
613
- return rules.map((rule) => {
679
+ return mergeStyleResults(rules.map((rule) => {
614
680
  const result = {
615
681
  selector: (Array.isArray(rule.selector) ? rule.selector : rule.selector ? [rule.selector] : [""]).map((part) => {
616
682
  let sel = part ? `${classNameOrSelector}${part}` : classNameOrSelector;
@@ -624,18 +690,20 @@ function renderStyles(styles, classNameOrSelector, options) {
624
690
  declarations: rule.declarations
625
691
  };
626
692
  if (rule.atRules && rule.atRules.length > 0) result.atRules = rule.atRules;
693
+ if (rule.startingStyle) result.startingStyle = true;
627
694
  return result;
628
- });
695
+ }));
629
696
  }
630
697
  return { rules: rules.map((r) => ({
631
698
  selector: Array.isArray(r.selector) ? r.selector.join("|||") : r.selector,
632
699
  declarations: r.declarations,
633
700
  atRules: r.atRules,
634
701
  needsClassName: true,
635
- rootPrefix: r.rootPrefix
702
+ rootPrefix: r.rootPrefix,
703
+ startingStyle: r.startingStyle
636
704
  })) };
637
705
  }
638
706
 
639
707
  //#endregion
640
- export { clearPipelineCache, isSelector, renderStyles };
708
+ export { clearPipelineCache, hasPipelineCacheEntry, isSelector, renderStyles };
641
709
  //# sourceMappingURL=index.js.map