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

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 (319) hide show
  1. package/README.md +297 -208
  2. package/dist/_virtual/_rolldown/runtime.js +1 -2
  3. package/dist/chunks/cacheKey.d.ts +1 -0
  4. package/dist/chunks/cacheKey.js +17 -10
  5. package/dist/chunks/cacheKey.js.map +1 -1
  6. package/dist/chunks/definitions.d.ts +1 -1
  7. package/dist/chunks/definitions.js +3 -5
  8. package/dist/chunks/definitions.js.map +1 -1
  9. package/dist/chunks/index.d.ts +1 -0
  10. package/dist/chunks/renderChunk.d.ts +1 -0
  11. package/dist/chunks/renderChunk.js +32 -34
  12. package/dist/chunks/renderChunk.js.map +1 -1
  13. package/dist/compute-styles.d.ts +31 -0
  14. package/dist/compute-styles.js +322 -0
  15. package/dist/compute-styles.js.map +1 -0
  16. package/dist/config.d.ts +149 -30
  17. package/dist/config.js +233 -45
  18. package/dist/config.js.map +1 -1
  19. package/dist/core/index.d.ts +12 -11
  20. package/dist/core/index.js +12 -11
  21. package/dist/counter-style/index.js +51 -0
  22. package/dist/counter-style/index.js.map +1 -0
  23. package/dist/debug.d.ts +26 -141
  24. package/dist/debug.js +359 -639
  25. package/dist/debug.js.map +1 -1
  26. package/dist/font-face/index.js +63 -0
  27. package/dist/font-face/index.js.map +1 -0
  28. package/dist/hooks/index.d.ts +7 -0
  29. package/dist/hooks/useCounterStyle.d.ts +36 -0
  30. package/dist/hooks/useCounterStyle.js +65 -0
  31. package/dist/hooks/useCounterStyle.js.map +1 -0
  32. package/dist/hooks/useFontFace.d.ts +45 -0
  33. package/dist/hooks/useFontFace.js +66 -0
  34. package/dist/hooks/useFontFace.js.map +1 -0
  35. package/dist/hooks/useGlobalStyles.d.ts +21 -2
  36. package/dist/hooks/useGlobalStyles.js +60 -28
  37. package/dist/hooks/useGlobalStyles.js.map +1 -1
  38. package/dist/hooks/useKeyframes.d.ts +4 -2
  39. package/dist/hooks/useKeyframes.js +44 -43
  40. package/dist/hooks/useKeyframes.js.map +1 -1
  41. package/dist/hooks/useProperty.d.ts +4 -2
  42. package/dist/hooks/useProperty.js +36 -31
  43. package/dist/hooks/useProperty.js.map +1 -1
  44. package/dist/hooks/useRawCSS.d.ts +13 -44
  45. package/dist/hooks/useRawCSS.js +91 -16
  46. package/dist/hooks/useRawCSS.js.map +1 -1
  47. package/dist/hooks/useStyles.d.ts +3 -3
  48. package/dist/hooks/useStyles.js +8 -146
  49. package/dist/hooks/useStyles.js.map +1 -1
  50. package/dist/index.d.ts +15 -12
  51. package/dist/index.js +15 -12
  52. package/dist/injector/index.d.ts +36 -11
  53. package/dist/injector/index.js +43 -12
  54. package/dist/injector/index.js.map +1 -1
  55. package/dist/injector/injector.d.ts +62 -3
  56. package/dist/injector/injector.js +256 -31
  57. package/dist/injector/injector.js.map +1 -1
  58. package/dist/injector/sheet-manager.d.ts +10 -13
  59. package/dist/injector/sheet-manager.js +42 -71
  60. package/dist/injector/sheet-manager.js.map +1 -1
  61. package/dist/injector/types.d.ts +112 -21
  62. package/dist/keyframes/index.js +1 -1
  63. package/dist/parser/classify.js +6 -6
  64. package/dist/parser/classify.js.map +1 -1
  65. package/dist/parser/const.js +30 -3
  66. package/dist/parser/const.js.map +1 -1
  67. package/dist/parser/lru.js +1 -1
  68. package/dist/parser/lru.js.map +1 -1
  69. package/dist/parser/parser.js +2 -3
  70. package/dist/parser/parser.js.map +1 -1
  71. package/dist/parser/tokenizer.js +1 -1
  72. package/dist/parser/tokenizer.js.map +1 -1
  73. package/dist/parser/types.js +1 -1
  74. package/dist/parser/types.js.map +1 -1
  75. package/dist/pipeline/conditions.js +1 -1
  76. package/dist/pipeline/conditions.js.map +1 -1
  77. package/dist/pipeline/exclusive.js +163 -5
  78. package/dist/pipeline/exclusive.js.map +1 -1
  79. package/dist/pipeline/index.d.ts +3 -1
  80. package/dist/pipeline/index.js +172 -83
  81. package/dist/pipeline/index.js.map +1 -1
  82. package/dist/pipeline/materialize-contradictions.js +125 -0
  83. package/dist/pipeline/materialize-contradictions.js.map +1 -0
  84. package/dist/pipeline/materialize.js +437 -243
  85. package/dist/pipeline/materialize.js.map +1 -1
  86. package/dist/pipeline/parseStateKey.d.ts +1 -1
  87. package/dist/pipeline/parseStateKey.js +21 -13
  88. package/dist/pipeline/parseStateKey.js.map +1 -1
  89. package/dist/pipeline/simplify.js +181 -7
  90. package/dist/pipeline/simplify.js.map +1 -1
  91. package/dist/pipeline/warnings.js +1 -1
  92. package/dist/plugins/index.d.ts +2 -0
  93. package/dist/plugins/okhsl-plugin.js +3 -277
  94. package/dist/plugins/okhsl-plugin.js.map +1 -1
  95. package/dist/plugins/types.d.ts +20 -2
  96. package/dist/properties/index.js +15 -30
  97. package/dist/properties/index.js.map +1 -1
  98. package/dist/properties/property-type-resolver.js +13 -2
  99. package/dist/properties/property-type-resolver.js.map +1 -1
  100. package/dist/rsc-cache.js +79 -0
  101. package/dist/rsc-cache.js.map +1 -0
  102. package/dist/ssr/astro-client.d.ts +1 -0
  103. package/dist/ssr/astro-client.js +19 -0
  104. package/dist/ssr/astro-client.js.map +1 -0
  105. package/dist/ssr/astro-middleware.d.ts +15 -0
  106. package/dist/ssr/astro-middleware.js +19 -0
  107. package/dist/ssr/astro-middleware.js.map +1 -0
  108. package/dist/ssr/astro.d.ts +108 -0
  109. package/dist/ssr/astro.js +149 -0
  110. package/dist/ssr/astro.js.map +1 -0
  111. package/dist/ssr/async-storage.d.ts +17 -0
  112. package/dist/ssr/async-storage.js +44 -0
  113. package/dist/ssr/async-storage.js.map +1 -0
  114. package/dist/ssr/collect-auto-properties.js +58 -0
  115. package/dist/ssr/collect-auto-properties.js.map +1 -0
  116. package/dist/ssr/collector.d.ts +98 -0
  117. package/dist/ssr/collector.js +235 -0
  118. package/dist/ssr/collector.js.map +1 -0
  119. package/dist/ssr/context.js +16 -0
  120. package/dist/ssr/context.js.map +1 -0
  121. package/dist/ssr/format-global-rules.js +22 -0
  122. package/dist/ssr/format-global-rules.js.map +1 -0
  123. package/dist/ssr/format-keyframes.js +69 -0
  124. package/dist/ssr/format-keyframes.js.map +1 -0
  125. package/dist/ssr/format-property.js +49 -0
  126. package/dist/ssr/format-property.js.map +1 -0
  127. package/dist/ssr/format-rules.js +73 -0
  128. package/dist/ssr/format-rules.js.map +1 -0
  129. package/dist/ssr/hydrate.d.ts +29 -0
  130. package/dist/ssr/hydrate.js +45 -0
  131. package/dist/ssr/hydrate.js.map +1 -0
  132. package/dist/ssr/index.d.ts +4 -0
  133. package/dist/ssr/index.js +10 -0
  134. package/dist/ssr/index.js.map +1 -0
  135. package/dist/ssr/next.d.ts +46 -0
  136. package/dist/ssr/next.js +75 -0
  137. package/dist/ssr/next.js.map +1 -0
  138. package/dist/ssr/ssr-collector-ref.js +29 -0
  139. package/dist/ssr/ssr-collector-ref.js.map +1 -0
  140. package/dist/states/index.js +13 -259
  141. package/dist/states/index.js.map +1 -1
  142. package/dist/static/index.js +1 -2
  143. package/dist/static/inject.d.ts +5 -0
  144. package/dist/static/inject.js +17 -0
  145. package/dist/static/inject.js.map +1 -0
  146. package/dist/static/tastyStatic.js +1 -2
  147. package/dist/static/tastyStatic.js.map +1 -1
  148. package/dist/static/types.js +1 -1
  149. package/dist/styles/border.d.ts +1 -1
  150. package/dist/styles/border.js +30 -24
  151. package/dist/styles/border.js.map +1 -1
  152. package/dist/styles/color.d.ts +1 -1
  153. package/dist/styles/color.js +11 -8
  154. package/dist/styles/color.js.map +1 -1
  155. package/dist/styles/const.js +17 -0
  156. package/dist/styles/const.js.map +1 -0
  157. package/dist/styles/createStyle.js +28 -26
  158. package/dist/styles/createStyle.js.map +1 -1
  159. package/dist/styles/dimension.js +15 -3
  160. package/dist/styles/dimension.js.map +1 -1
  161. package/dist/styles/directional.js +133 -0
  162. package/dist/styles/directional.js.map +1 -0
  163. package/dist/styles/display.d.ts +3 -10
  164. package/dist/styles/display.js +45 -39
  165. package/dist/styles/display.js.map +1 -1
  166. package/dist/styles/fade.d.ts +1 -1
  167. package/dist/styles/fade.js +9 -5
  168. package/dist/styles/fade.js.map +1 -1
  169. package/dist/styles/fill.d.ts +2 -2
  170. package/dist/styles/fill.js +3 -4
  171. package/dist/styles/fill.js.map +1 -1
  172. package/dist/styles/flow.js +1 -1
  173. package/dist/styles/gap.d.ts +1 -1
  174. package/dist/styles/gap.js +4 -3
  175. package/dist/styles/gap.js.map +1 -1
  176. package/dist/styles/height.d.ts +1 -1
  177. package/dist/styles/height.js +1 -2
  178. package/dist/styles/height.js.map +1 -1
  179. package/dist/styles/index.d.ts +0 -1
  180. package/dist/styles/index.js +3 -4
  181. package/dist/styles/index.js.map +1 -1
  182. package/dist/styles/inset.d.ts +1 -29
  183. package/dist/styles/inset.js +19 -135
  184. package/dist/styles/inset.js.map +1 -1
  185. package/dist/styles/list.d.ts +5 -5
  186. package/dist/styles/list.js +4 -2
  187. package/dist/styles/list.js.map +1 -1
  188. package/dist/styles/margin.d.ts +1 -1
  189. package/dist/styles/margin.js +17 -89
  190. package/dist/styles/margin.js.map +1 -1
  191. package/dist/styles/outline.d.ts +1 -1
  192. package/dist/styles/outline.js +6 -16
  193. package/dist/styles/outline.js.map +1 -1
  194. package/dist/styles/padding.d.ts +1 -1
  195. package/dist/styles/padding.js +17 -89
  196. package/dist/styles/padding.js.map +1 -1
  197. package/dist/styles/placement.d.ts +37 -0
  198. package/dist/styles/placement.js +74 -0
  199. package/dist/styles/placement.js.map +1 -0
  200. package/dist/styles/predefined.d.ts +4 -6
  201. package/dist/styles/predefined.js +9 -13
  202. package/dist/styles/predefined.js.map +1 -1
  203. package/dist/styles/preset.d.ts +6 -1
  204. package/dist/styles/preset.js +54 -53
  205. package/dist/styles/preset.js.map +1 -1
  206. package/dist/styles/radius.d.ts +1 -3
  207. package/dist/styles/radius.js +38 -6
  208. package/dist/styles/radius.js.map +1 -1
  209. package/dist/styles/scrollMargin.d.ts +24 -0
  210. package/dist/styles/scrollMargin.js +32 -0
  211. package/dist/styles/scrollMargin.js.map +1 -0
  212. package/dist/styles/scrollbar.d.ts +9 -5
  213. package/dist/styles/scrollbar.js +31 -92
  214. package/dist/styles/scrollbar.js.map +1 -1
  215. package/dist/styles/shadow.d.ts +1 -1
  216. package/dist/styles/shadow.js +4 -3
  217. package/dist/styles/shadow.js.map +1 -1
  218. package/dist/styles/shared.js +17 -0
  219. package/dist/styles/shared.js.map +1 -0
  220. package/dist/styles/transition.d.ts +1 -1
  221. package/dist/styles/transition.js +6 -5
  222. package/dist/styles/transition.js.map +1 -1
  223. package/dist/styles/types.d.ts +94 -28
  224. package/dist/styles/width.d.ts +1 -1
  225. package/dist/styles/width.js +1 -2
  226. package/dist/styles/width.js.map +1 -1
  227. package/dist/tasty.d.ts +46 -894
  228. package/dist/tasty.js +101 -59
  229. package/dist/tasty.js.map +1 -1
  230. package/dist/types.d.ts +1 -1
  231. package/dist/utils/cache-wrapper.js +4 -9
  232. package/dist/utils/cache-wrapper.js.map +1 -1
  233. package/dist/utils/case-converter.js +1 -1
  234. package/dist/utils/color-math.d.ts +46 -0
  235. package/dist/utils/color-math.js +749 -0
  236. package/dist/utils/color-math.js.map +1 -0
  237. package/dist/utils/color-space.d.ts +5 -0
  238. package/dist/utils/color-space.js +228 -0
  239. package/dist/utils/color-space.js.map +1 -0
  240. package/dist/utils/colors.js +3 -2
  241. package/dist/utils/colors.js.map +1 -1
  242. package/dist/utils/deps-equal.js +15 -0
  243. package/dist/utils/deps-equal.js.map +1 -0
  244. package/dist/utils/dotize.js +1 -1
  245. package/dist/utils/dotize.js.map +1 -1
  246. package/dist/utils/filter-base-props.d.ts +1 -1
  247. package/dist/utils/filter-base-props.js +1 -1
  248. package/dist/utils/filter-base-props.js.map +1 -1
  249. package/dist/utils/get-display-name.js +1 -1
  250. package/dist/utils/has-keys.js +13 -0
  251. package/dist/utils/has-keys.js.map +1 -0
  252. package/dist/utils/hash.js +14 -0
  253. package/dist/utils/hash.js.map +1 -0
  254. package/dist/utils/is-dev-env.js +1 -1
  255. package/dist/utils/is-dev-env.js.map +1 -1
  256. package/dist/utils/is-valid-element-type.js +1 -1
  257. package/dist/utils/merge-styles.js +1 -2
  258. package/dist/utils/merge-styles.js.map +1 -1
  259. package/dist/utils/mod-attrs.d.ts +0 -2
  260. package/dist/utils/mod-attrs.js +3 -4
  261. package/dist/utils/mod-attrs.js.map +1 -1
  262. package/dist/utils/process-tokens.d.ts +3 -17
  263. package/dist/utils/process-tokens.js +19 -107
  264. package/dist/utils/process-tokens.js.map +1 -1
  265. package/dist/utils/resolve-recipes.js +1 -2
  266. package/dist/utils/resolve-recipes.js.map +1 -1
  267. package/dist/utils/selector-transform.js +32 -0
  268. package/dist/utils/selector-transform.js.map +1 -0
  269. package/dist/utils/string.js +1 -1
  270. package/dist/utils/styles.d.ts +3 -82
  271. package/dist/utils/styles.js +29 -560
  272. package/dist/utils/styles.js.map +1 -1
  273. package/dist/utils/typography.d.ts +35 -13
  274. package/dist/utils/typography.js +16 -18
  275. package/dist/utils/typography.js.map +1 -1
  276. package/dist/utils/warnings.js +1 -1
  277. package/dist/zero/babel.d.ts +57 -89
  278. package/dist/zero/babel.js +214 -40
  279. package/dist/zero/babel.js.map +1 -1
  280. package/dist/zero/css-writer.js +1 -2
  281. package/dist/zero/css-writer.js.map +1 -1
  282. package/dist/zero/extractor.js +54 -3
  283. package/dist/zero/extractor.js.map +1 -1
  284. package/dist/zero/index.js +1 -2
  285. package/dist/zero/next.d.ts +56 -30
  286. package/dist/zero/next.js +105 -40
  287. package/dist/zero/next.js.map +1 -1
  288. package/docs/README.md +31 -0
  289. package/docs/adoption.md +298 -0
  290. package/docs/comparison.md +419 -0
  291. package/docs/configuration.md +394 -0
  292. package/docs/debug.md +320 -0
  293. package/docs/design-system.md +436 -0
  294. package/docs/dsl.md +688 -0
  295. package/docs/getting-started.md +217 -0
  296. package/docs/injector.md +544 -0
  297. package/docs/methodology.md +616 -0
  298. package/docs/pipeline.md +673 -0
  299. package/docs/react-api.md +557 -0
  300. package/docs/ssr.md +442 -0
  301. package/docs/styles.md +596 -0
  302. package/docs/tasty-static.md +532 -0
  303. package/package.json +68 -36
  304. package/dist/styles/align.d.ts +0 -15
  305. package/dist/styles/align.js +0 -14
  306. package/dist/styles/align.js.map +0 -1
  307. package/dist/styles/justify.d.ts +0 -15
  308. package/dist/styles/justify.js +0 -14
  309. package/dist/styles/justify.js.map +0 -1
  310. package/dist/styles/styledScrollbar.d.ts +0 -47
  311. package/dist/styles/styledScrollbar.js +0 -38
  312. package/dist/styles/styledScrollbar.js.map +0 -1
  313. package/dist/tokens/typography.d.ts +0 -19
  314. package/dist/tokens/typography.js +0 -237
  315. package/dist/tokens/typography.js.map +0 -1
  316. package/dist/utils/hsl-to-rgb.js +0 -38
  317. package/dist/utils/hsl-to-rgb.js.map +0 -1
  318. package/dist/utils/okhsl-to-rgb.js +0 -296
  319. package/dist/utils/okhsl-to-rgb.js.map +0 -1
@@ -1,33 +1,47 @@
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";
6
- import { and, falseCondition, not, or, trueCondition } from "./conditions.js";
5
+ import { createStateParserContext, extractLocalPredefinedStates } from "../states/index.js";
6
+ import { and, or, trueCondition } from "./conditions.js";
7
7
  import { simplifyCondition } from "./simplify.js";
8
- import { buildExclusiveConditions, expandExclusiveOrs, expandOrConditions, isValueMapping, parseStyleEntries } from "./exclusive.js";
9
- import { buildAtRulesFromVariant, conditionToCSS, modifierToCSS, parentGroupsToCSS, pseudoToCSS, rootConditionsToCSS, selectorConditionToCSS } from "./materialize.js";
8
+ import { buildExclusiveConditions, expandExclusiveOrs, expandOrConditions, extractCompoundStates, isValueMapping, mergeEntriesByValue, parseStyleEntries } from "./exclusive.js";
9
+ import { branchToCSS, buildAtRulesFromVariant, conditionToCSS, mergeVariantsIntoSelectorGroups, optimizeGroups, parentGroupsToCSS, rootGroupsToCSS, selectorGroupToCSS } from "./materialize.js";
10
10
  import { emitWarning } from "./warnings.js";
11
11
  import { parseStateKey } from "./parseStateKey.js";
12
-
13
12
  //#region src/pipeline/index.ts
14
13
  /**
15
14
  * Tasty Style Rendering Pipeline
16
15
  *
17
- * This is the main entrypoint for the new pipeline implementation.
18
- * It implements the complete flow from style objects to CSS rules.
19
- *
20
- * Pipeline stages:
21
- * 1. PARSE CONDITIONS - Parse state keys into ConditionNode trees
22
- * 2. BUILD EXCLUSIVE CONDITIONS - AND with negation of higher-priority conditions
23
- * 3. SIMPLIFY CONDITIONS - Apply boolean algebra, detect contradictions
24
- * 4. GROUP BY HANDLER - Collect styles per handler, compute combinations
25
- * 5. COMPUTE CSS VALUES - Call handlers to get CSS declarations
26
- * 6. MERGE BY VALUE - Merge rules with identical CSS output
27
- * 7. MATERIALIZE CSS - Convert conditions to CSS selectors + at-rules
16
+ * Main entrypoint for the style rendering pipeline. Transforms a `Styles`
17
+ * object into an array of `CSSRule` objects ready for DOM injection.
18
+ *
19
+ * Per-handler stages (see docs/pipeline.md for full detail):
20
+ * 0. PRE-PARSE NORMALIZATION - extractCompoundStates (exclusive.ts)
21
+ * 1. PARSE CONDITIONS - parseStyleEntries + parseStateKey
22
+ * 1b. MERGE ENTRIES BY VALUE - mergeEntriesByValue (exclusive.ts)
23
+ * 2a. EXPAND USER OR BRANCHES - expandOrConditions (exclusive.ts)
24
+ * 2b. BUILD EXCLUSIVE CONDITIONS - buildExclusiveConditions
25
+ * 3. EXPAND DE MORGAN ORs - expandExclusiveOrs (exclusive.ts)
26
+ * 4. COMPUTE STATE COMBINATIONS - computeStateCombinations
27
+ * 5. CALL HANDLERS - run style handlers for each snapshot
28
+ * 6. MERGE BY VALUE - mergeByValue (index.ts)
29
+ * 7. MATERIALIZE CSS - conditionToCSS + materializeComputedRule
30
+ *
31
+ * Simplification (`simplifyCondition`) runs inside most stages; calls are
32
+ * memoized by condition unique-id. The post-pass in `runPipeline` dedupes
33
+ * identical rules and emits all `@starting-style` rules last so they win
34
+ * the cascade over their equal-specificity normal counterparts.
28
35
  */
29
36
  const pipelineCache = new Lru(5e3);
30
37
  /**
38
+ * Check if a cache key exists in the pipeline cache.
39
+ * Used by renderStylesForChunk to avoid building filtered styles on cache hit.
40
+ */
41
+ function hasPipelineCacheEntry(cacheKey) {
42
+ return pipelineCache.get(cacheKey) !== void 0;
43
+ }
44
+ /**
31
45
  * Clear the pipeline cache (for testing)
32
46
  */
33
47
  function clearPipelineCache() {
@@ -37,20 +51,38 @@ function runPipeline(styles, parserContext) {
37
51
  const allRules = [];
38
52
  processStyles(styles, "", parserContext, allRules);
39
53
  const seen = /* @__PURE__ */ new Set();
40
- return allRules.filter((rule) => {
41
- const key = `${rule.selector}|${rule.declarations}|${JSON.stringify(rule.atRules || [])}|${rule.rootPrefix || ""}`;
54
+ const dedupedRules = allRules.filter((rule) => {
55
+ const key = `${rule.selector}|${rule.declarations}|${rule.atRules?.join("|") ?? ""}|${rule.rootPrefix || ""}|${rule.startingStyle ? "1" : "0"}`;
42
56
  if (seen.has(key)) return false;
43
57
  seen.add(key);
44
58
  return true;
45
59
  });
60
+ const normal = [];
61
+ const starting = [];
62
+ for (const rule of dedupedRules) if (rule.startingStyle) starting.push(rule);
63
+ else normal.push(rule);
64
+ return normal.concat(starting);
46
65
  }
47
66
  /**
48
- * Process styles at a given nesting level
67
+ * Process styles at a given nesting level.
68
+ *
69
+ * Splits keys into nested-selector keys and style-handler keys, recurses
70
+ * into nested selectors, then runs the per-handler stages 1–7 over the
71
+ * style keys.
49
72
  */
50
73
  function processStyles(styles, selectorSuffix, parserContext, allRules) {
51
74
  const keys = Object.keys(styles);
52
75
  const selectorKeys = keys.filter((key) => isSelector(key));
53
76
  const styleKeys = keys.filter((key) => !isSelector(key) && !key.startsWith("@"));
77
+ processNestedSelectors(styles, selectorKeys, selectorSuffix, parserContext, allRules);
78
+ processHandlerQueue(buildHandlerQueue(styleKeys, styles), selectorSuffix, parserContext, allRules);
79
+ }
80
+ /**
81
+ * Recurse into nested selector keys. Each nested key may expand into multiple
82
+ * suffixes (comma-separated patterns); each suffix is processed independently
83
+ * with the parent's parser context augmented for sub-element scope.
84
+ */
85
+ function processNestedSelectors(styles, selectorKeys, selectorSuffix, parserContext, allRules) {
54
86
  for (const key of selectorKeys) {
55
87
  const nestedStyles = styles[key];
56
88
  if (!nestedStyles || typeof nestedStyles !== "object") continue;
@@ -69,46 +101,15 @@ function processStyles(styles, selectorSuffix, parserContext, allRules) {
69
101
  };
70
102
  for (const suffix of suffixes) processStyles(cleanedStyles, selectorSuffix + suffix, subContext, allRules);
71
103
  }
72
- const handlerQueue = buildHandlerQueue(styleKeys, styles);
104
+ }
105
+ /**
106
+ * Run the per-handler pipeline (stages 1–7) over a handler queue and append
107
+ * the resulting CSS rules to `allRules`.
108
+ */
109
+ function processHandlerQueue(handlerQueue, selectorSuffix, parserContext, allRules) {
73
110
  for (const { handler, styleMap } of handlerQueue) {
74
111
  const lookupStyles = handler.__lookupStyles;
75
- const exclusiveByStyle = /* @__PURE__ */ new Map();
76
- for (const styleName of lookupStyles) {
77
- const value = styleMap[styleName];
78
- if (value === void 0) continue;
79
- if (isValueMapping(value)) {
80
- const fullyExpanded = expandExclusiveOrs(buildExclusiveConditions(expandOrConditions(parseStyleEntries(styleName, value, (stateKey) => parseStateKey(stateKey, { context: parserContext })))));
81
- exclusiveByStyle.set(styleName, fullyExpanded);
82
- } else exclusiveByStyle.set(styleName, [{
83
- styleKey: styleName,
84
- stateKey: "",
85
- value,
86
- condition: trueCondition(),
87
- priority: 0,
88
- exclusiveCondition: trueCondition()
89
- }]);
90
- }
91
- const stateSnapshots = computeStateCombinations(exclusiveByStyle, lookupStyles);
92
- const computedRules = [];
93
- for (const snapshot of stateSnapshots) {
94
- const result = handler(snapshot.values);
95
- if (!result) continue;
96
- const results = Array.isArray(result) ? result : [result];
97
- for (const r of results) {
98
- if (!r || typeof r !== "object") continue;
99
- const { $, ...styleProps } = r;
100
- const declarations = {};
101
- for (const [prop, val] of Object.entries(styleProps)) if (val != null && val !== "") declarations[prop] = String(val);
102
- if (Object.keys(declarations).length === 0) continue;
103
- const suffixes = $ ? (Array.isArray($) ? $ : [$]).map((s) => selectorSuffix + normalizeSelectorSuffix(String(s))) : [selectorSuffix];
104
- for (const suffix of suffixes) computedRules.push({
105
- condition: snapshot.condition,
106
- declarations,
107
- selectorSuffix: suffix
108
- });
109
- }
110
- }
111
- const mergedRules = mergeByValue(computedRules);
112
+ const mergedRules = mergeByValue(invokeHandler(handler, computeStateCombinations(buildExclusivesForHandler(lookupStyles, styleMap, parserContext), lookupStyles), selectorSuffix));
112
113
  for (const rule of mergedRules) {
113
114
  const cssRules = materializeComputedRule(rule);
114
115
  allRules.push(...cssRules);
@@ -116,6 +117,57 @@ function processStyles(styles, selectorSuffix, parserContext, allRules) {
116
117
  }
117
118
  }
118
119
  /**
120
+ * Stages 0–3 for a single handler: take the handler's looked-up style names,
121
+ * resolve each style's value map into a list of mutually-exclusive entries.
122
+ * Simple non-mapping values produce a single TRUE-conditioned entry.
123
+ */
124
+ function buildExclusivesForHandler(lookupStyles, styleMap, parserContext) {
125
+ const exclusiveByStyle = /* @__PURE__ */ new Map();
126
+ for (const styleName of lookupStyles) {
127
+ const value = styleMap[styleName];
128
+ if (value === void 0) continue;
129
+ if (isValueMapping(value)) {
130
+ const fullyExpanded = expandExclusiveOrs(buildExclusiveConditions(expandOrConditions(mergeEntriesByValue(parseStyleEntries(styleName, extractCompoundStates(value), (stateKey) => parseStateKey(stateKey, { context: parserContext }))))));
131
+ exclusiveByStyle.set(styleName, fullyExpanded);
132
+ } else exclusiveByStyle.set(styleName, [{
133
+ styleKey: styleName,
134
+ stateKey: "",
135
+ value,
136
+ condition: trueCondition(),
137
+ priority: 0,
138
+ exclusiveCondition: trueCondition()
139
+ }]);
140
+ }
141
+ return exclusiveByStyle;
142
+ }
143
+ /**
144
+ * Stage 5: invoke the handler for each state snapshot and translate its
145
+ * return value into ComputedRule entries (one per declaration set, fanned
146
+ * out across any `$` selector suffixes the handler returns).
147
+ */
148
+ function invokeHandler(handler, stateSnapshots, selectorSuffix) {
149
+ const computedRules = [];
150
+ for (const snapshot of stateSnapshots) {
151
+ const result = handler(snapshot.values);
152
+ if (!result) continue;
153
+ const results = Array.isArray(result) ? result : [result];
154
+ for (const r of results) {
155
+ if (!r || typeof r !== "object") continue;
156
+ const { $, ...styleProps } = r;
157
+ const declarations = {};
158
+ for (const [prop, val] of Object.entries(styleProps)) if (val != null && val !== "") declarations[prop] = String(val);
159
+ if (Object.keys(declarations).length === 0) continue;
160
+ const suffixes = $ ? (Array.isArray($) ? $ : [$]).map((s) => selectorSuffix + normalizeSelectorSuffix(String(s))) : [selectorSuffix];
161
+ for (const suffix of suffixes) computedRules.push({
162
+ condition: snapshot.condition,
163
+ declarations,
164
+ selectorSuffix: suffix
165
+ });
166
+ }
167
+ }
168
+ return computedRules;
169
+ }
170
+ /**
119
171
  * Check if a key is a CSS selector
120
172
  */
121
173
  function isSelector(key) {
@@ -163,7 +215,8 @@ function getAllSelectors(key, styles) {
163
215
  * Supports:
164
216
  * - Direct child: '>'
165
217
  * - Chained elements: '>Body>Row>'
166
- * - HTML tags: 'a', '>ul>li', 'button:hover'
218
+ * - HTML tags (no key injection): 'h1', '>ul>li', 'button:hover'
219
+ * - Universal selector: '*', 'h1 *'
167
220
  * - Pseudo-elements on root: '::before'
168
221
  * - Pseudo on sub-element: '@::before', '>@:hover'
169
222
  * - Classes: '.active', '>@.active'
@@ -200,6 +253,7 @@ function processAffix(affix, key) {
200
253
  */
201
254
  const VALID_TOKEN_PATTERNS = [
202
255
  /^[>+~]/,
256
+ /^\*/,
203
257
  /^[A-Z][a-zA-Z0-9]*/,
204
258
  /^@/,
205
259
  /^::?[a-z][a-z0-9-]*(?:\([^)]*\))?/,
@@ -334,12 +388,13 @@ function processSinglePattern(pattern, key) {
334
388
  * The tokenizer handles these token types in order:
335
389
  * 1. Whitespace (skipped)
336
390
  * 2. Combinators: >, +, ~ (add surrounding spaces)
337
- * 3. Uppercase names: Body, Row (convert to [data-element="..."])
338
- * 4. @ placeholder (keep for later replacement)
339
- * 5. Pseudo: :hover, ::before (attach to previous token)
340
- * 6. Tags: a, div, button (keep as-is with spacing)
341
- * 7. Classes: .active (attach to previous element/tag/placeholder)
342
- * 8. Attributes: [type="text"] (keep as-is)
391
+ * 3. Universal selector: * (keep as-is with spacing)
392
+ * 4. Uppercase names: Body, Row (convert to [data-element="..."])
393
+ * 5. @ placeholder (keep for later replacement)
394
+ * 6. Pseudo: :hover, ::before (attach to previous token)
395
+ * 7. Tags: a, div, button (keep as-is with spacing)
396
+ * 8. Classes: .active (attach to previous element/tag/placeholder)
397
+ * 9. Attributes: [type="text"] (keep as-is)
343
398
  *
344
399
  * @param pattern - The raw selector pattern to transform
345
400
  * @returns Transformed pattern with proper CSS selector syntax
@@ -368,6 +423,13 @@ function transformPattern(pattern) {
368
423
  i++;
369
424
  continue;
370
425
  }
426
+ if (char === "*") {
427
+ if (result && lastCh !== " ") result += " ";
428
+ result += "*";
429
+ lastCh = "*";
430
+ i++;
431
+ continue;
432
+ }
371
433
  if (/[A-Z]/.test(char)) {
372
434
  const nameStart = i;
373
435
  while (i < pattern.length && /[a-zA-Z0-9]/.test(pattern[i])) i++;
@@ -442,7 +504,8 @@ function transformPattern(pattern) {
442
504
  * |----------------|-------------|---------|--------|
443
505
  * | Combinator (>, +, ~) | Yes | `'>Body>'` | `> [data-element="Body"] > [el]` |
444
506
  * | Uppercase element | Yes | `'>Body>Row'` | `> [el1] > [el2] [key]` |
445
- * | Lowercase tag | Yes | `'>ul>li'` | `> ul > li [key]` |
507
+ * | Lowercase tag | No | `'h1'` | ` h1` |
508
+ * | Universal (*) | No | `'h1 *'` | ` h1 *` |
446
509
  * | Pseudo (:hover, ::before) | No | `'::before'` | `::before` |
447
510
  * | Class (.active) | No | `'.active'` | `.active` |
448
511
  * | Attribute ([type]) | No | `'[type="text"]'` | `[type="text"]` |
@@ -453,7 +516,8 @@ function transformPattern(pattern) {
453
516
  * @example
454
517
  * shouldInjectKey('>') // → true (trailing combinator)
455
518
  * shouldInjectKey('>Body>Row') // → true (ends with element)
456
- * shouldInjectKey('>ul>li') // → true (ends with tag)
519
+ * shouldInjectKey('h1') // → false (ends with tag)
520
+ * shouldInjectKey('*') // → false (universal selector)
457
521
  * shouldInjectKey('::before') // → false (ends with pseudo)
458
522
  * shouldInjectKey('.active') // → false (ends with class)
459
523
  * shouldInjectKey('a:hover') // → false (ends with pseudo)
@@ -463,7 +527,6 @@ function shouldInjectKey(pattern) {
463
527
  const trimmed = pattern.trim();
464
528
  if (/[>+~]$/.test(trimmed)) return true;
465
529
  if (/(?:^|[\s>+~\]:])[A-Z][a-zA-Z0-9]*$/.test(trimmed)) return true;
466
- if (/(?<![:.])(?:^|[\s>+~])[a-z][a-z0-9-]*$/.test(trimmed)) return true;
467
530
  return false;
468
531
  }
469
532
  /**
@@ -573,11 +636,12 @@ function mergeByValue(rules) {
573
636
  */
574
637
  function buildSelectorFromVariant(variant, selectorSuffix) {
575
638
  let selector = "";
576
- for (const mod of variant.modifierConditions) selector += modifierToCSS(mod);
577
- for (const pseudo of variant.pseudoConditions) selector += pseudoToCSS(pseudo);
639
+ selector += branchToCSS([...variant.modifierConditions, ...variant.pseudoConditions]);
640
+ for (const group of variant.selectorGroups) selector += selectorGroupToCSS(group);
578
641
  if (variant.parentGroups.length > 0) selector += parentGroupsToCSS(variant.parentGroups);
579
642
  selector += selectorSuffix;
580
- for (const own of variant.ownConditions) selector += selectorConditionToCSS(own);
643
+ const ownOptimized = optimizeGroups(variant.ownGroups);
644
+ for (const group of ownOptimized) selector += selectorGroupToCSS(group);
581
645
  return selector;
582
646
  }
583
647
  /**
@@ -591,45 +655,68 @@ function materializeComputedRule(rule) {
591
655
  if (components.isImpossible || components.variants.length === 0) return [];
592
656
  const declarations = Object.entries(rule.declarations).map(([prop, value]) => `${prop}: ${value};`).join(" ");
593
657
  const getRootPrefixKey = (variant) => {
594
- return variant.rootConditions.map((r) => selectorConditionToCSS(r)).sort().join("|");
658
+ return rootGroupsToCSS(variant.rootGroups) || "";
595
659
  };
596
660
  const byAtRules = /* @__PURE__ */ new Map();
597
661
  for (const variant of components.variants) {
598
662
  const atRules = buildAtRulesFromVariant(variant);
599
- const key = atRules.sort().join("|||") + "###" + getRootPrefixKey(variant);
663
+ const startingStyle = variant.startingStyle;
664
+ const key = atRules.sort().join("|||") + "###" + getRootPrefixKey(variant) + "###" + (startingStyle ? "1" : "0");
600
665
  const group = byAtRules.get(key);
601
666
  if (group) group.variants.push(variant);
602
667
  else byAtRules.set(key, {
603
668
  variants: [variant],
604
669
  atRules,
605
- rootPrefix: rootConditionsToCSS(variant.rootConditions)
670
+ rootPrefix: rootGroupsToCSS(variant.rootGroups),
671
+ startingStyle: startingStyle || void 0
606
672
  });
607
673
  }
608
674
  const rules = [];
609
675
  for (const [, group] of byAtRules) {
610
- const selectorFragments = group.variants.map((v) => buildSelectorFromVariant(v, rule.selectorSuffix));
676
+ const selectorFragments = mergeVariantsIntoSelectorGroups(group.variants).map((v) => buildSelectorFromVariant(v, rule.selectorSuffix));
611
677
  const cssRule = {
612
678
  selector: selectorFragments.length === 1 ? selectorFragments[0] : selectorFragments,
613
679
  declarations
614
680
  };
615
681
  if (group.atRules.length > 0) cssRule.atRules = group.atRules;
616
682
  if (group.rootPrefix) cssRule.rootPrefix = group.rootPrefix;
683
+ if (group.startingStyle) cssRule.startingStyle = true;
617
684
  rules.push(cssRule);
618
685
  }
619
686
  return rules;
620
687
  }
621
- function renderStyles(styles, classNameOrSelector, options) {
688
+ /**
689
+ * Merge StyleResult entries that share the same selector and at-rules,
690
+ * concatenating their declarations into a single rule.
691
+ *
692
+ * This reduces CSS output size when many style keys (e.g. design tokens)
693
+ * resolve to the same selector/state combination.
694
+ */
695
+ function mergeStyleResults(results) {
696
+ if (results.length <= 1) return results;
697
+ const groups = /* @__PURE__ */ new Map();
698
+ for (const result of results) {
699
+ const key = `${result.atRules?.join("|") ?? ""}||${result.selector}||${result.startingStyle ? "1" : "0"}`;
700
+ const existing = groups.get(key);
701
+ if (existing) existing.declarations = existing.declarations ? `${existing.declarations} ${result.declarations}` : result.declarations;
702
+ else groups.set(key, { ...result });
703
+ }
704
+ return Array.from(groups.values());
705
+ }
706
+ function renderStyles(styles, classNameOrSelector, options, pipelineCacheKey) {
622
707
  const directSelector = !!classNameOrSelector;
623
- if (!styles) return directSelector ? [] : { rules: [] };
624
- const cacheKey = stringifyStyles(styles);
625
- let rules = pipelineCache.get(cacheKey);
708
+ let rules;
709
+ if (pipelineCacheKey) rules = pipelineCache.get(pipelineCacheKey);
710
+ if (!rules && !styles) return directSelector ? [] : { rules: [] };
711
+ const cacheKey = pipelineCacheKey || stringifyStyles(styles);
712
+ if (!rules) rules = pipelineCache.get(cacheKey);
626
713
  if (!rules) {
627
714
  rules = runPipeline(styles, createStateParserContext(styles));
628
715
  pipelineCache.set(cacheKey, rules);
629
716
  }
630
717
  if (directSelector) {
631
718
  const shouldDouble = options?.doubleSelector ?? false;
632
- return rules.map((rule) => {
719
+ return mergeStyleResults(rules.map((rule) => {
633
720
  const result = {
634
721
  selector: (Array.isArray(rule.selector) ? rule.selector : rule.selector ? [rule.selector] : [""]).map((part) => {
635
722
  let sel = part ? `${classNameOrSelector}${part}` : classNameOrSelector;
@@ -643,18 +730,20 @@ function renderStyles(styles, classNameOrSelector, options) {
643
730
  declarations: rule.declarations
644
731
  };
645
732
  if (rule.atRules && rule.atRules.length > 0) result.atRules = rule.atRules;
733
+ if (rule.startingStyle) result.startingStyle = true;
646
734
  return result;
647
- });
735
+ }));
648
736
  }
649
737
  return { rules: rules.map((r) => ({
650
738
  selector: Array.isArray(r.selector) ? r.selector.join("|||") : r.selector,
651
739
  declarations: r.declarations,
652
740
  atRules: r.atRules,
653
741
  needsClassName: true,
654
- rootPrefix: r.rootPrefix
742
+ rootPrefix: r.rootPrefix,
743
+ startingStyle: r.startingStyle
655
744
  })) };
656
745
  }
657
-
658
746
  //#endregion
659
- export { clearPipelineCache, isSelector, renderStyles };
747
+ export { clearPipelineCache, hasPipelineCacheEntry, isSelector, renderStyles };
748
+
660
749
  //# sourceMappingURL=index.js.map