@tenphi/tasty 0.0.0-snapshot.fafcbfe → 0.0.0-snapshot.fde7ec8

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 (325) hide show
  1. package/README.md +322 -160
  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 +157 -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 +23 -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 +293 -46
  57. package/dist/injector/injector.js.map +1 -1
  58. package/dist/injector/sheet-manager.d.ts +22 -17
  59. package/dist/injector/sheet-manager.js +64 -79
  60. package/dist/injector/sheet-manager.js.map +1 -1
  61. package/dist/injector/types.d.ts +121 -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 +15 -9
  76. package/dist/pipeline/conditions.js.map +1 -1
  77. package/dist/pipeline/exclusive.js +58 -4
  78. package/dist/pipeline/exclusive.js.map +1 -1
  79. package/dist/pipeline/index.d.ts +3 -1
  80. package/dist/pipeline/index.js +141 -74
  81. package/dist/pipeline/index.js.map +1 -1
  82. package/dist/pipeline/materialize.js +460 -211
  83. package/dist/pipeline/materialize.js.map +1 -1
  84. package/dist/pipeline/parseStateKey.d.ts +1 -1
  85. package/dist/pipeline/parseStateKey.js +38 -22
  86. package/dist/pipeline/parseStateKey.js.map +1 -1
  87. package/dist/pipeline/simplify.js +289 -156
  88. package/dist/pipeline/simplify.js.map +1 -1
  89. package/dist/pipeline/warnings.js +18 -0
  90. package/dist/pipeline/warnings.js.map +1 -0
  91. package/dist/plugins/index.d.ts +2 -0
  92. package/dist/plugins/okhsl-plugin.js +3 -277
  93. package/dist/plugins/okhsl-plugin.js.map +1 -1
  94. package/dist/plugins/types.d.ts +20 -2
  95. package/dist/properties/index.js +83 -19
  96. package/dist/properties/index.js.map +1 -1
  97. package/dist/properties/property-type-resolver.d.ts +24 -0
  98. package/dist/properties/property-type-resolver.js +90 -0
  99. package/dist/properties/property-type-resolver.js.map +1 -0
  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 +2 -2
  150. package/dist/styles/border.js +30 -24
  151. package/dist/styles/border.js.map +1 -1
  152. package/dist/styles/color.d.ts +3 -3
  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 +29 -27
  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 +2 -2
  167. package/dist/styles/fade.js +9 -5
  168. package/dist/styles/fade.js.map +1 -1
  169. package/dist/styles/fill.d.ts +15 -17
  170. package/dist/styles/fill.js +9 -9
  171. package/dist/styles/fill.js.map +1 -1
  172. package/dist/styles/flow.d.ts +3 -3
  173. package/dist/styles/flow.js +1 -1
  174. package/dist/styles/flow.js.map +1 -1
  175. package/dist/styles/gap.d.ts +1 -1
  176. package/dist/styles/gap.js +4 -3
  177. package/dist/styles/gap.js.map +1 -1
  178. package/dist/styles/height.d.ts +1 -1
  179. package/dist/styles/height.js +1 -2
  180. package/dist/styles/height.js.map +1 -1
  181. package/dist/styles/index.d.ts +0 -1
  182. package/dist/styles/index.js +3 -4
  183. package/dist/styles/index.js.map +1 -1
  184. package/dist/styles/inset.d.ts +1 -29
  185. package/dist/styles/inset.js +19 -135
  186. package/dist/styles/inset.js.map +1 -1
  187. package/dist/styles/list.d.ts +5 -5
  188. package/dist/styles/list.js +4 -2
  189. package/dist/styles/list.js.map +1 -1
  190. package/dist/styles/margin.d.ts +1 -1
  191. package/dist/styles/margin.js +17 -89
  192. package/dist/styles/margin.js.map +1 -1
  193. package/dist/styles/outline.d.ts +1 -1
  194. package/dist/styles/outline.js +6 -16
  195. package/dist/styles/outline.js.map +1 -1
  196. package/dist/styles/padding.d.ts +1 -1
  197. package/dist/styles/padding.js +17 -89
  198. package/dist/styles/padding.js.map +1 -1
  199. package/dist/styles/placement.d.ts +37 -0
  200. package/dist/styles/placement.js +74 -0
  201. package/dist/styles/placement.js.map +1 -0
  202. package/dist/styles/predefined.d.ts +4 -6
  203. package/dist/styles/predefined.js +9 -13
  204. package/dist/styles/predefined.js.map +1 -1
  205. package/dist/styles/preset.d.ts +6 -1
  206. package/dist/styles/preset.js +54 -53
  207. package/dist/styles/preset.js.map +1 -1
  208. package/dist/styles/radius.d.ts +2 -4
  209. package/dist/styles/radius.js +38 -6
  210. package/dist/styles/radius.js.map +1 -1
  211. package/dist/styles/scrollMargin.d.ts +24 -0
  212. package/dist/styles/scrollMargin.js +32 -0
  213. package/dist/styles/scrollMargin.js.map +1 -0
  214. package/dist/styles/scrollbar.d.ts +9 -5
  215. package/dist/styles/scrollbar.js +31 -85
  216. package/dist/styles/scrollbar.js.map +1 -1
  217. package/dist/styles/shadow.d.ts +3 -3
  218. package/dist/styles/shadow.js +4 -3
  219. package/dist/styles/shadow.js.map +1 -1
  220. package/dist/styles/shared.js +17 -0
  221. package/dist/styles/shared.js.map +1 -0
  222. package/dist/styles/transition.d.ts +2 -2
  223. package/dist/styles/transition.js +6 -5
  224. package/dist/styles/transition.js.map +1 -1
  225. package/dist/styles/types.d.ts +94 -28
  226. package/dist/styles/width.d.ts +1 -1
  227. package/dist/styles/width.js +1 -2
  228. package/dist/styles/width.js.map +1 -1
  229. package/dist/tasty.d.ts +46 -894
  230. package/dist/tasty.js +117 -60
  231. package/dist/tasty.js.map +1 -1
  232. package/dist/types.d.ts +3 -3
  233. package/dist/utils/cache-wrapper.js +4 -9
  234. package/dist/utils/cache-wrapper.js.map +1 -1
  235. package/dist/utils/case-converter.js +1 -1
  236. package/dist/utils/color-math.d.ts +46 -0
  237. package/dist/utils/color-math.js +749 -0
  238. package/dist/utils/color-math.js.map +1 -0
  239. package/dist/utils/color-space.d.ts +5 -0
  240. package/dist/utils/color-space.js +228 -0
  241. package/dist/utils/color-space.js.map +1 -0
  242. package/dist/utils/colors.d.ts +1 -1
  243. package/dist/utils/colors.js +3 -2
  244. package/dist/utils/colors.js.map +1 -1
  245. package/dist/utils/css-types.d.ts +1 -1
  246. package/dist/utils/deps-equal.js +15 -0
  247. package/dist/utils/deps-equal.js.map +1 -0
  248. package/dist/utils/dotize.d.ts +1 -1
  249. package/dist/utils/dotize.js +1 -1
  250. package/dist/utils/dotize.js.map +1 -1
  251. package/dist/utils/filter-base-props.d.ts +1 -1
  252. package/dist/utils/filter-base-props.js +1 -1
  253. package/dist/utils/filter-base-props.js.map +1 -1
  254. package/dist/utils/get-display-name.js +1 -1
  255. package/dist/utils/has-keys.js +13 -0
  256. package/dist/utils/has-keys.js.map +1 -0
  257. package/dist/utils/hash.js +14 -0
  258. package/dist/utils/hash.js.map +1 -0
  259. package/dist/utils/is-dev-env.js +1 -1
  260. package/dist/utils/is-dev-env.js.map +1 -1
  261. package/dist/utils/is-valid-element-type.js +1 -1
  262. package/dist/utils/merge-styles.js +1 -2
  263. package/dist/utils/merge-styles.js.map +1 -1
  264. package/dist/utils/mod-attrs.d.ts +0 -2
  265. package/dist/utils/mod-attrs.js +3 -4
  266. package/dist/utils/mod-attrs.js.map +1 -1
  267. package/dist/utils/process-tokens.d.ts +3 -17
  268. package/dist/utils/process-tokens.js +19 -107
  269. package/dist/utils/process-tokens.js.map +1 -1
  270. package/dist/utils/resolve-recipes.js +1 -2
  271. package/dist/utils/resolve-recipes.js.map +1 -1
  272. package/dist/utils/selector-transform.js +32 -0
  273. package/dist/utils/selector-transform.js.map +1 -0
  274. package/dist/utils/string.js +1 -1
  275. package/dist/utils/string.js.map +1 -1
  276. package/dist/utils/styles.d.ts +5 -89
  277. package/dist/utils/styles.js +35 -400
  278. package/dist/utils/styles.js.map +1 -1
  279. package/dist/utils/typography.d.ts +35 -13
  280. package/dist/utils/typography.js +16 -18
  281. package/dist/utils/typography.js.map +1 -1
  282. package/dist/utils/warnings.js +1 -1
  283. package/dist/zero/babel.d.ts +57 -84
  284. package/dist/zero/babel.js +217 -37
  285. package/dist/zero/babel.js.map +1 -1
  286. package/dist/zero/css-writer.js +1 -2
  287. package/dist/zero/css-writer.js.map +1 -1
  288. package/dist/zero/extractor.js +119 -3
  289. package/dist/zero/extractor.js.map +1 -1
  290. package/dist/zero/index.js +1 -2
  291. package/dist/zero/next.d.ts +56 -30
  292. package/dist/zero/next.js +105 -40
  293. package/dist/zero/next.js.map +1 -1
  294. package/docs/PIPELINE.md +519 -0
  295. package/docs/README.md +31 -0
  296. package/docs/adoption.md +298 -0
  297. package/docs/comparison.md +419 -0
  298. package/docs/configuration.md +394 -0
  299. package/docs/debug.md +318 -0
  300. package/docs/design-system.md +436 -0
  301. package/docs/dsl.md +688 -0
  302. package/docs/getting-started.md +217 -0
  303. package/docs/injector.md +544 -0
  304. package/docs/methodology.md +616 -0
  305. package/docs/react-api.md +557 -0
  306. package/docs/ssr.md +442 -0
  307. package/docs/styles.md +596 -0
  308. package/docs/tasty-static.md +532 -0
  309. package/package.json +112 -31
  310. package/dist/styles/align.d.ts +0 -15
  311. package/dist/styles/align.js +0 -14
  312. package/dist/styles/align.js.map +0 -1
  313. package/dist/styles/justify.d.ts +0 -15
  314. package/dist/styles/justify.js +0 -14
  315. package/dist/styles/justify.js.map +0 -1
  316. package/dist/styles/styledScrollbar.d.ts +0 -47
  317. package/dist/styles/styledScrollbar.js +0 -38
  318. package/dist/styles/styledScrollbar.js.map +0 -1
  319. package/dist/tokens/typography.d.ts +0 -19
  320. package/dist/tokens/typography.js +0 -237
  321. package/dist/tokens/typography.js.map +0 -1
  322. package/dist/utils/hsl-to-rgb.js +0 -38
  323. package/dist/utils/hsl-to-rgb.js.map +0 -1
  324. package/dist/utils/okhsl-to-rgb.js +0 -296
  325. package/dist/utils/okhsl-to-rgb.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"exclusive.js","names":[],"sources":["../../src/pipeline/exclusive.ts"],"sourcesContent":["/**\n * Exclusive Condition Builder\n *\n * Transforms parsed style entries into exclusive conditions.\n * Each entry's condition is ANDed with the negation of all higher-priority conditions,\n * ensuring exactly one condition matches at any given time.\n */\n\nimport type { StyleValue } from '../utils/styles';\n\nimport type { ConditionNode } from './conditions';\nimport { and, isCompoundCondition, not, trueCondition } from './conditions';\nimport { simplifyCondition } from './simplify';\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Parsed style entry with condition\n */\nexport interface ParsedStyleEntry {\n styleKey: string; // e.g., 'padding', 'fill'\n stateKey: string; // Original key: '', 'compact', '@media(w < 768px)'\n value: StyleValue; // The style value (before handler processing)\n condition: ConditionNode; // Parsed condition tree\n priority: number; // Order in original object (higher = higher priority)\n}\n\n/**\n * Style entry with exclusive condition\n */\nexport interface ExclusiveStyleEntry extends ParsedStyleEntry {\n exclusiveCondition: ConditionNode; // condition & !higherPriorityConditions\n}\n\n// ============================================================================\n// Main Function\n// ============================================================================\n\n/**\n * Build exclusive conditions for a list of parsed style entries.\n *\n * The entries should be ordered by priority (highest priority first).\n *\n * For each entry, we compute:\n * exclusiveCondition = condition & !prior[0] & !prior[1] & ...\n *\n * This ensures exactly one condition matches at any time.\n *\n * Example:\n * Input (ordered highest to lowest priority):\n * A: value1 (priority 2)\n * B: value2 (priority 1)\n * C: value3 (priority 0)\n *\n * Output:\n * A: A\n * B: B & !A\n * C: C & !A & !B\n *\n * @param entries Parsed style entries ordered by priority (highest first)\n * @returns Entries with exclusive conditions, filtered to remove impossible ones\n */\nexport function buildExclusiveConditions(\n entries: ParsedStyleEntry[],\n): ExclusiveStyleEntry[] {\n const result: ExclusiveStyleEntry[] = [];\n const priorConditions: ConditionNode[] = [];\n\n for (const entry of entries) {\n // Build: condition & !prior[0] & !prior[1] & ...\n let exclusive: ConditionNode = entry.condition;\n\n for (const prior of priorConditions) {\n // Skip negating \"always true\" (default state) - it would become \"always false\"\n if (prior.kind !== 'true') {\n exclusive = and(exclusive, not(prior));\n }\n }\n\n // Simplify the exclusive condition\n const simplified = simplifyCondition(exclusive);\n\n // Skip impossible conditions (simplified to FALSE)\n if (simplified.kind === 'false') {\n continue;\n }\n\n result.push({\n ...entry,\n exclusiveCondition: simplified,\n });\n\n // Add non-default conditions to prior list for subsequent entries\n if (entry.condition.kind !== 'true') {\n priorConditions.push(entry.condition);\n }\n }\n\n return result;\n}\n\n/**\n * Parse style entries from a value mapping object.\n *\n * @param styleKey The style key (e.g., 'padding')\n * @param valueMap The value mapping { '': '2x', 'compact': '1x', '@media(w < 768px)': '0.5x' }\n * @param parseCondition Function to parse state keys into conditions\n * @returns Parsed entries ordered by priority (highest first)\n */\nexport function parseStyleEntries(\n styleKey: string,\n valueMap: Record<string, StyleValue>,\n parseCondition: (stateKey: string) => ConditionNode,\n): ParsedStyleEntry[] {\n const entries: ParsedStyleEntry[] = [];\n const keys = Object.keys(valueMap);\n\n keys.forEach((stateKey, index) => {\n const value = valueMap[stateKey];\n const condition =\n stateKey === '' ? trueCondition() : parseCondition(stateKey);\n\n entries.push({\n styleKey,\n stateKey,\n value,\n condition,\n priority: index,\n });\n });\n\n // Reverse so highest priority (last in object) comes first for exclusive building\n // buildExclusiveConditions expects highest priority first\n entries.reverse();\n\n return entries;\n}\n\n/**\n * Check if a value is a style value mapping (object with state keys)\n */\nexport function isValueMapping(\n value: StyleValue | Record<string, StyleValue>,\n): value is Record<string, StyleValue> {\n return (\n value !== null &&\n typeof value === 'object' &&\n !Array.isArray(value) &&\n !(value instanceof Date)\n );\n}\n\n// ============================================================================\n// OR Expansion\n// ============================================================================\n\n/**\n * Expand OR conditions in parsed entries into multiple exclusive entries.\n *\n * For an entry with condition `A | B | C`, this creates 3 entries:\n * - condition: A\n * - condition: B & !A\n * - condition: C & !A & !B\n *\n * This ensures OR branches are mutually exclusive BEFORE the main\n * exclusive condition building pass.\n *\n * @param entries Parsed entries (may contain OR conditions)\n * @returns Expanded entries with OR branches made exclusive\n */\nexport function expandOrConditions(\n entries: ParsedStyleEntry[],\n): ParsedStyleEntry[] {\n const result: ParsedStyleEntry[] = [];\n\n for (const entry of entries) {\n const expanded = expandSingleEntry(entry);\n result.push(...expanded);\n }\n\n return result;\n}\n\n/**\n * Expand a single entry's OR condition into multiple exclusive entries\n */\nfunction expandSingleEntry(entry: ParsedStyleEntry): ParsedStyleEntry[] {\n const orBranches = collectOrBranches(entry.condition);\n\n // If no OR (single branch), return as-is\n if (orBranches.length <= 1) {\n return [entry];\n }\n\n // Make each OR branch exclusive from prior branches\n const result: ParsedStyleEntry[] = [];\n const priorBranches: ConditionNode[] = [];\n\n for (let i = 0; i < orBranches.length; i++) {\n const branch = orBranches[i];\n\n // Build: branch & !prior[0] & !prior[1] & ...\n let exclusiveBranch: ConditionNode = branch;\n for (const prior of priorBranches) {\n exclusiveBranch = and(exclusiveBranch, not(prior));\n }\n\n // Simplify to detect impossible combinations\n const simplified = simplifyCondition(exclusiveBranch);\n\n // Skip impossible branches\n if (simplified.kind === 'false') {\n priorBranches.push(branch);\n continue;\n }\n\n result.push({\n ...entry,\n stateKey: `${entry.stateKey}[${i}]`, // Mark as expanded branch\n condition: simplified,\n // Keep same priority - all branches from same entry have same priority\n });\n\n priorBranches.push(branch);\n }\n\n return result;\n}\n\n/**\n * Collect top-level OR branches from a condition.\n *\n * For `A | B | C`, returns [A, B, C]\n * For `A & B`, returns [A & B] (single branch)\n * For `A | (B & C)`, returns [A, B & C]\n */\nfunction collectOrBranches(condition: ConditionNode): ConditionNode[] {\n if (condition.kind === 'true' || condition.kind === 'false') {\n return [condition];\n }\n\n if (isCompoundCondition(condition) && condition.operator === 'OR') {\n // Flatten nested ORs\n const branches: ConditionNode[] = [];\n for (const child of condition.children) {\n branches.push(...collectOrBranches(child));\n }\n return branches;\n }\n\n // Not an OR - return as single branch\n return [condition];\n}\n\n// ============================================================================\n// Post-Build OR Expansion (for De Morgan ORs)\n// ============================================================================\n\n/**\n * Expand OR conditions in exclusive entries AFTER buildExclusiveConditions.\n *\n * This handles ORs that arise from De Morgan expansion during negation:\n * !(A & B) = !A | !B\n *\n * These ORs need to be made exclusive to avoid overlapping CSS rules:\n * !A | !B → !A | (A & !B)\n *\n * This is logically equivalent but ensures each branch has proper context.\n *\n * Example:\n * Input: { \"\": V1, \"@supports(...) & :has()\": V2 }\n * V2's exclusive = @supports & :has\n * V1's exclusive = !(@supports & :has) = !@supports | !:has\n *\n * Without this fix: V1 gets two rules:\n * - @supports (not ...) → V1 ✓\n * - :not(:has()) → V1 ✗ (missing @supports context!)\n *\n * With this fix: V1 gets two exclusive rules:\n * - @supports (not ...) → V1 ✓\n * - @supports (...) { :not(:has()) } → V1 ✓ (proper context!)\n */\nexport function expandExclusiveOrs(\n entries: ExclusiveStyleEntry[],\n): ExclusiveStyleEntry[] {\n const result: ExclusiveStyleEntry[] = [];\n\n for (const entry of entries) {\n const expanded = expandExclusiveConditionOrs(entry);\n result.push(...expanded);\n }\n\n return result;\n}\n\n/**\n * Check if a condition involves at-rules (media, container, supports, starting)\n */\nfunction hasAtRuleContext(node: ConditionNode): boolean {\n if (node.kind === 'true' || node.kind === 'false') {\n return false;\n }\n\n if (node.kind === 'state') {\n // These condition types generate at-rules\n return (\n node.type === 'media' ||\n node.type === 'container' ||\n node.type === 'supports' ||\n node.type === 'starting'\n );\n }\n\n if (node.kind === 'compound') {\n return node.children.some(hasAtRuleContext);\n }\n\n return false;\n}\n\n/**\n * Sort OR branches to prioritize at-rule conditions first.\n *\n * This is critical for correct CSS generation. For `!A | !B` where A is at-rule\n * and B is modifier, we want:\n * - Branch 0: !A (at-rule negation - covers \"no @supports/media\" case)\n * - Branch 1: A & !B (modifier negation with at-rule context)\n *\n * If we process in wrong order (!B first), we'd get:\n * - Branch 0: !B (modifier negation WITHOUT at-rule context - WRONG!)\n * - Branch 1: B & !A (at-rule negation with modifier - incomplete coverage)\n */\nfunction sortOrBranchesForExpansion(\n branches: ConditionNode[],\n): ConditionNode[] {\n return [...branches].sort((a, b) => {\n const aHasAtRule = hasAtRuleContext(a);\n const bHasAtRule = hasAtRuleContext(b);\n\n // At-rule conditions come first\n if (aHasAtRule && !bHasAtRule) return -1;\n if (!aHasAtRule && bHasAtRule) return 1;\n\n // Same type - keep original order (stable sort)\n return 0;\n });\n}\n\n/**\n * Expand ORs in a single entry's exclusive condition\n */\nfunction expandExclusiveConditionOrs(\n entry: ExclusiveStyleEntry,\n): ExclusiveStyleEntry[] {\n let orBranches = collectOrBranches(entry.exclusiveCondition);\n\n // If no OR (single branch), return as-is\n if (orBranches.length <= 1) {\n return [entry];\n }\n\n // Sort branches so at-rule conditions come first\n // This ensures proper context inheritance during expansion\n orBranches = sortOrBranchesForExpansion(orBranches);\n\n // Make each OR branch exclusive from prior branches\n const result: ExclusiveStyleEntry[] = [];\n const priorBranches: ConditionNode[] = [];\n\n for (let i = 0; i < orBranches.length; i++) {\n const branch = orBranches[i];\n\n // Build: branch & !prior[0] & !prior[1] & ...\n // This transforms: !A | !B → !A, !B & !!A = !A, (A & !B)\n let exclusiveBranch: ConditionNode = branch;\n for (const prior of priorBranches) {\n exclusiveBranch = and(exclusiveBranch, not(prior));\n }\n\n // Simplify to detect impossible combinations and clean up double negations\n const simplified = simplifyCondition(exclusiveBranch);\n\n // Skip impossible branches\n if (simplified.kind === 'false') {\n priorBranches.push(branch);\n continue;\n }\n\n result.push({\n ...entry,\n stateKey: `${entry.stateKey}[or:${i}]`, // Mark as expanded OR branch\n exclusiveCondition: simplified,\n });\n\n priorBranches.push(branch);\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,SAAgB,yBACd,SACuB;CACvB,MAAM,SAAgC,EAAE;CACxC,MAAM,kBAAmC,EAAE;AAE3C,MAAK,MAAM,SAAS,SAAS;EAE3B,IAAI,YAA2B,MAAM;AAErC,OAAK,MAAM,SAAS,gBAElB,KAAI,MAAM,SAAS,OACjB,aAAY,IAAI,WAAW,IAAI,MAAM,CAAC;EAK1C,MAAM,aAAa,kBAAkB,UAAU;AAG/C,MAAI,WAAW,SAAS,QACtB;AAGF,SAAO,KAAK;GACV,GAAG;GACH,oBAAoB;GACrB,CAAC;AAGF,MAAI,MAAM,UAAU,SAAS,OAC3B,iBAAgB,KAAK,MAAM,UAAU;;AAIzC,QAAO;;;;;;;;;;AAWT,SAAgB,kBACd,UACA,UACA,gBACoB;CACpB,MAAM,UAA8B,EAAE;AAGtC,CAFa,OAAO,KAAK,SAAS,CAE7B,SAAS,UAAU,UAAU;EAChC,MAAM,QAAQ,SAAS;EACvB,MAAM,YACJ,aAAa,KAAK,eAAe,GAAG,eAAe,SAAS;AAE9D,UAAQ,KAAK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GACH,UAAU,GAAG,MAAM,SAAS,MAAM,EAAE;GACpC,oBAAoB;GACrB,CAAC;AAEF,gBAAc,KAAK,OAAO;;AAG5B,QAAO"}
1
+ {"version":3,"file":"exclusive.js","names":[],"sources":["../../src/pipeline/exclusive.ts"],"sourcesContent":["/**\n * Exclusive Condition Builder\n *\n * Transforms parsed style entries into exclusive conditions.\n * Each entry's condition is ANDed with the negation of all higher-priority conditions,\n * ensuring exactly one condition matches at any given time.\n */\n\nimport type { StyleValue } from '../utils/styles';\n\nimport type { ConditionNode } from './conditions';\nimport { and, isCompoundCondition, not, or, trueCondition } from './conditions';\nimport { simplifyCondition } from './simplify';\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Parsed style entry with condition\n */\nexport interface ParsedStyleEntry {\n styleKey: string; // e.g., 'padding', 'fill'\n stateKey: string; // Original key: '', 'compact', '@media(w < 768px)'\n value: StyleValue; // The style value (before handler processing)\n condition: ConditionNode; // Parsed condition tree\n priority: number; // Order in original object (higher = higher priority)\n}\n\n/**\n * Style entry with exclusive condition\n */\nexport interface ExclusiveStyleEntry extends ParsedStyleEntry {\n exclusiveCondition: ConditionNode; // condition & !higherPriorityConditions\n}\n\n// ============================================================================\n// Main Function\n// ============================================================================\n\n/**\n * Build exclusive conditions for a list of parsed style entries.\n *\n * The entries should be ordered by priority (highest priority first).\n *\n * For each entry, we compute:\n * exclusiveCondition = condition & !prior[0] & !prior[1] & ...\n *\n * This ensures exactly one condition matches at any time.\n *\n * Example:\n * Input (ordered highest to lowest priority):\n * A: value1 (priority 2)\n * B: value2 (priority 1)\n * C: value3 (priority 0)\n *\n * Output:\n * A: A\n * B: B & !A\n * C: C & !A & !B\n *\n * @param entries Parsed style entries ordered by priority (highest first)\n * @returns Entries with exclusive conditions, filtered to remove impossible ones\n */\nexport function buildExclusiveConditions(\n entries: ParsedStyleEntry[],\n): ExclusiveStyleEntry[] {\n const result: ExclusiveStyleEntry[] = [];\n const priorConditions: ConditionNode[] = [];\n\n for (const entry of entries) {\n // Build: condition & !prior[0] & !prior[1] & ...\n let exclusive: ConditionNode = entry.condition;\n\n for (const prior of priorConditions) {\n // Skip negating \"always true\" (default state) - it would become \"always false\"\n if (prior.kind !== 'true') {\n exclusive = and(exclusive, not(prior));\n }\n }\n\n // Simplify the exclusive condition\n const simplified = simplifyCondition(exclusive);\n\n // Skip impossible conditions (simplified to FALSE)\n if (simplified.kind === 'false') {\n continue;\n }\n\n result.push({\n ...entry,\n exclusiveCondition: simplified,\n });\n\n // Add non-default conditions to prior list for subsequent entries\n if (entry.condition.kind !== 'true') {\n priorConditions.push(entry.condition);\n }\n }\n\n return result;\n}\n\n/**\n * Parse style entries from a value mapping object.\n *\n * @param styleKey The style key (e.g., 'padding')\n * @param valueMap The value mapping { '': '2x', 'compact': '1x', '@media(w < 768px)': '0.5x' }\n * @param parseCondition Function to parse state keys into conditions\n * @returns Parsed entries ordered by priority (highest first)\n */\nexport function parseStyleEntries(\n styleKey: string,\n valueMap: Record<string, StyleValue>,\n parseCondition: (stateKey: string) => ConditionNode,\n): ParsedStyleEntry[] {\n const entries: ParsedStyleEntry[] = [];\n const keys = Object.keys(valueMap);\n\n keys.forEach((stateKey, index) => {\n const value = valueMap[stateKey];\n const condition =\n stateKey === '' ? trueCondition() : parseCondition(stateKey);\n\n entries.push({\n styleKey,\n stateKey,\n value,\n condition,\n priority: index,\n });\n });\n\n // Reverse so highest priority (last in object) comes first for exclusive building\n // buildExclusiveConditions expects highest priority first\n entries.reverse();\n\n return entries;\n}\n\n/**\n * Merge parsed entries that share the same value.\n *\n * When multiple state keys map to the same value, their conditions can\n * be combined with OR and treated as a single entry. This must happen\n * **before** exclusive expansion and OR branch splitting to avoid\n * combinatorial explosion and duplicate CSS output.\n *\n * Example: `{ '@dark': 'red', '@dark & @hc': 'red' }` merges into a\n * single entry with condition `@dark | (@dark & @hc)` = `@dark`.\n *\n * Entries are ordered highest-priority-first. The merged entry keeps the\n * highest priority of the group.\n */\nexport function mergeEntriesByValue(\n entries: ParsedStyleEntry[],\n): ParsedStyleEntry[] {\n if (entries.length <= 1) return entries;\n\n const groups = new Map<\n string,\n { entries: ParsedStyleEntry[]; maxPriority: number }\n >();\n\n for (const entry of entries) {\n const valueKey = serializeValue(entry.value);\n const group = groups.get(valueKey);\n if (group) {\n group.entries.push(entry);\n group.maxPriority = Math.max(group.maxPriority, entry.priority);\n } else {\n groups.set(valueKey, { entries: [entry], maxPriority: entry.priority });\n }\n }\n\n // If no merges possible, return as-is\n if (groups.size === entries.length) return entries;\n\n const merged: ParsedStyleEntry[] = [];\n for (const [, group] of groups) {\n if (group.entries.length === 1) {\n merged.push(group.entries[0]);\n continue;\n }\n\n // Combine conditions with OR, then simplify\n const combinedCondition = simplifyCondition(\n or(...group.entries.map((e) => e.condition)),\n );\n\n // Combine state keys for debugging\n const combinedStateKey = group.entries.map((e) => e.stateKey).join(' | ');\n\n // When a group contains the default (true) entry, use minPriority.\n // true|X = true, so the merged condition is unconditional; at elevated\n // priority it would shadow entries between the default and the\n // highest-priority member, breaking exclusivity.\n const hasDefault = group.entries.some((e) => e.condition.kind === 'true');\n const minPriority = Math.min(...group.entries.map((e) => e.priority));\n\n merged.push({\n styleKey: group.entries[0].styleKey,\n stateKey: combinedStateKey,\n value: group.entries[0].value,\n condition: combinedCondition,\n priority: hasDefault ? minPriority : group.maxPriority,\n });\n }\n\n // Re-sort by priority (highest first)\n merged.sort((a, b) => b.priority - a.priority);\n\n return merged;\n}\n\nfunction serializeValue(value: StyleValue): string {\n if (value === null || value === undefined) return 'null';\n if (typeof value === 'string' || typeof value === 'number') {\n return String(value);\n }\n return JSON.stringify(value);\n}\n\n/**\n * Check if a value is a style value mapping (object with state keys)\n */\nexport function isValueMapping(\n value: StyleValue | Record<string, StyleValue>,\n): value is Record<string, StyleValue> {\n return (\n value !== null &&\n typeof value === 'object' &&\n !Array.isArray(value) &&\n !(value instanceof Date)\n );\n}\n\n// ============================================================================\n// OR Expansion\n// ============================================================================\n\n/**\n * Expand OR conditions in parsed entries into multiple exclusive entries.\n *\n * For an entry with condition `A | B | C`, this creates 3 entries:\n * - condition: A\n * - condition: B & !A\n * - condition: C & !A & !B\n *\n * This ensures OR branches are mutually exclusive BEFORE the main\n * exclusive condition building pass.\n *\n * @param entries Parsed entries (may contain OR conditions)\n * @returns Expanded entries with OR branches made exclusive\n */\nexport function expandOrConditions(\n entries: ParsedStyleEntry[],\n): ParsedStyleEntry[] {\n const result: ParsedStyleEntry[] = [];\n\n for (const entry of entries) {\n const expanded = expandSingleEntry(entry);\n result.push(...expanded);\n }\n\n return result;\n}\n\n/**\n * Expand a single entry's OR condition into multiple exclusive entries\n */\nfunction expandSingleEntry(entry: ParsedStyleEntry): ParsedStyleEntry[] {\n const orBranches = collectOrBranches(entry.condition);\n\n // If no OR (single branch), return as-is\n if (orBranches.length <= 1) {\n return [entry];\n }\n\n // Make each OR branch exclusive from prior branches\n const result: ParsedStyleEntry[] = [];\n const priorBranches: ConditionNode[] = [];\n\n for (let i = 0; i < orBranches.length; i++) {\n const branch = orBranches[i];\n\n // Build: branch & !prior[0] & !prior[1] & ...\n let exclusiveBranch: ConditionNode = branch;\n for (const prior of priorBranches) {\n exclusiveBranch = and(exclusiveBranch, not(prior));\n }\n\n // Simplify to detect impossible combinations\n const simplified = simplifyCondition(exclusiveBranch);\n\n // Skip impossible branches\n if (simplified.kind === 'false') {\n priorBranches.push(branch);\n continue;\n }\n\n result.push({\n ...entry,\n stateKey: `${entry.stateKey}[${i}]`, // Mark as expanded branch\n condition: simplified,\n // Keep same priority - all branches from same entry have same priority\n });\n\n priorBranches.push(branch);\n }\n\n return result;\n}\n\n/**\n * Collect top-level OR branches from a condition.\n *\n * For `A | B | C`, returns [A, B, C]\n * For `A & B`, returns [A & B] (single branch)\n * For `A | (B & C)`, returns [A, B & C]\n */\nfunction collectOrBranches(condition: ConditionNode): ConditionNode[] {\n if (condition.kind === 'true' || condition.kind === 'false') {\n return [condition];\n }\n\n if (isCompoundCondition(condition) && condition.operator === 'OR') {\n // Flatten nested ORs\n const branches: ConditionNode[] = [];\n for (const child of condition.children) {\n branches.push(...collectOrBranches(child));\n }\n return branches;\n }\n\n // Not an OR - return as single branch\n return [condition];\n}\n\n// ============================================================================\n// Post-Build OR Expansion (for De Morgan ORs)\n// ============================================================================\n\n/**\n * Expand OR conditions in exclusive entries AFTER buildExclusiveConditions.\n *\n * This handles ORs that arise from De Morgan expansion during negation:\n * !(A & B) = !A | !B\n *\n * These ORs need to be made exclusive to avoid overlapping CSS rules:\n * !A | !B → !A | (A & !B)\n *\n * This is logically equivalent but ensures each branch has proper context.\n *\n * Example:\n * Input: { \"\": V1, \"@supports(...) & :has()\": V2 }\n * V2's exclusive = @supports & :has\n * V1's exclusive = !(@supports & :has) = !@supports | !:has\n *\n * Without this fix: V1 gets two rules:\n * - @supports (not ...) → V1 ✓\n * - :not(:has()) → V1 ✗ (missing @supports context!)\n *\n * With this fix: V1 gets two exclusive rules:\n * - @supports (not ...) → V1 ✓\n * - @supports (...) { :not(:has()) } → V1 ✓ (proper context!)\n */\nexport function expandExclusiveOrs(\n entries: ExclusiveStyleEntry[],\n): ExclusiveStyleEntry[] {\n const result: ExclusiveStyleEntry[] = [];\n\n for (const entry of entries) {\n const expanded = expandExclusiveConditionOrs(entry);\n result.push(...expanded);\n }\n\n return result;\n}\n\n/**\n * Check if a condition involves at-rules (media, container, supports, starting)\n */\nfunction hasAtRuleContext(node: ConditionNode): boolean {\n if (node.kind === 'true' || node.kind === 'false') {\n return false;\n }\n\n if (node.kind === 'state') {\n // These condition types generate at-rules\n return (\n node.type === 'media' ||\n node.type === 'container' ||\n node.type === 'supports' ||\n node.type === 'starting'\n );\n }\n\n if (node.kind === 'compound') {\n return node.children.some(hasAtRuleContext);\n }\n\n return false;\n}\n\n/**\n * Sort OR branches to prioritize at-rule conditions first.\n *\n * This is critical for correct CSS generation. For `!A | !B` where A is at-rule\n * and B is modifier, we want:\n * - Branch 0: !A (at-rule negation - covers \"no @supports/media\" case)\n * - Branch 1: A & !B (modifier negation with at-rule context)\n *\n * If we process in wrong order (!B first), we'd get:\n * - Branch 0: !B (modifier negation WITHOUT at-rule context - WRONG!)\n * - Branch 1: B & !A (at-rule negation with modifier - incomplete coverage)\n */\nfunction sortOrBranchesForExpansion(\n branches: ConditionNode[],\n): ConditionNode[] {\n return [...branches].sort((a, b) => {\n const aHasAtRule = hasAtRuleContext(a);\n const bHasAtRule = hasAtRuleContext(b);\n\n // At-rule conditions come first\n if (aHasAtRule && !bHasAtRule) return -1;\n if (!aHasAtRule && bHasAtRule) return 1;\n\n // Same type - keep original order (stable sort)\n return 0;\n });\n}\n\n/**\n * Expand ORs in a single entry's exclusive condition\n */\nfunction expandExclusiveConditionOrs(\n entry: ExclusiveStyleEntry,\n): ExclusiveStyleEntry[] {\n let orBranches = collectOrBranches(entry.exclusiveCondition);\n\n // If no OR (single branch), return as-is\n if (orBranches.length <= 1) {\n return [entry];\n }\n\n // Sort branches so at-rule conditions come first\n // This ensures proper context inheritance during expansion\n orBranches = sortOrBranchesForExpansion(orBranches);\n\n // Make each OR branch exclusive from prior branches\n const result: ExclusiveStyleEntry[] = [];\n const priorBranches: ConditionNode[] = [];\n\n for (let i = 0; i < orBranches.length; i++) {\n const branch = orBranches[i];\n\n // Build: branch & !prior[0] & !prior[1] & ...\n // This transforms: !A | !B → !A, !B & !!A = !A, (A & !B)\n let exclusiveBranch: ConditionNode = branch;\n for (const prior of priorBranches) {\n exclusiveBranch = and(exclusiveBranch, not(prior));\n }\n\n // Simplify to detect impossible combinations and clean up double negations\n const simplified = simplifyCondition(exclusiveBranch);\n\n // Skip impossible branches\n if (simplified.kind === 'false') {\n priorBranches.push(branch);\n continue;\n }\n\n result.push({\n ...entry,\n stateKey: `${entry.stateKey}[or:${i}]`, // Mark as expanded OR branch\n exclusiveCondition: simplified,\n });\n\n priorBranches.push(branch);\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,SAAgB,yBACd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AG,SAAS,CAAC,MAAM,GAAG,MAAM;EAClC,MAAM,aAAa,iBAAiB,EAAE;EACtC,MAAM,aAAa,iBAAiB,EAAE;AAGtC,MAAI,cAAc,CAAC,WAAY,QAAO;AACtC,MAAI,CAAC,cAAc,WAAY,QAAO;AAGtC,SAAO;GACP;;;;;AAMJ,SAAS,4BACP,OACuB;CACvB,IAAI,aAAa,kBAAkB,MAAM,mBAAmB;AAG5D,KAAI,WAAW,UAAU,EACvB,QAAO,CAAC,MAAM;AAKhB,cAAa,2BAA2B,WAAW;CAGnD,MAAM,SAAgC,EAAE;CACxC,MAAM,gBAAiC,EAAE;AAEzC,MAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;EAC1C,MAAM,SAAS,WAAW;EAI1B,IAAI,kBAAiC;AACrC,OAAK,MAAM,SAAS,cAClB,mBAAkB,IAAI,iBAAiB,IAAI,MAAM,CAAC;EAIpD,MAAM,aAAa,kBAAkB,gBAAgB;AAGrD,MAAI,WAAW,SAAS,SAAS;AAC/B,iBAAc,KAAK,OAAO;AAC1B;;AAGF,SAAO,KAAK;GACV,GAAG;GACH,UAAU,GAAG,MAAM,SAAS,MAAM,EAAE;GACpC,oBAAoB;GACrB,CAAC;AAEF,gBAAc,KAAK,OAAO;;AAG5B,QAAO"}
@@ -12,6 +12,8 @@ interface StyleResult {
12
12
  atRules?: string[];
13
13
  needsClassName?: boolean;
14
14
  rootPrefix?: string;
15
+ /** When true, declarations are wrapped in @starting-style { ... } inside the selector rule */
16
+ startingStyle?: boolean;
15
17
  }
16
18
  /**
17
19
  * Matches the old RenderResult interface for backward compatibility
@@ -46,7 +48,7 @@ interface RenderStylesOptions {
46
48
  * When called without classNameOrSelector, returns RenderResult with needsClassName=true.
47
49
  * When called with a selector/className string, returns StyleResult[] for direct injection.
48
50
  */
49
- declare function renderStyles(styles?: Styles): RenderResult;
51
+ declare function renderStyles(styles?: Styles, classNameOrSelector?: undefined, options?: undefined, pipelineCacheKey?: string): RenderResult;
50
52
  declare function renderStyles(styles: Styles | undefined, classNameOrSelector: string, options?: RenderStylesOptions): StyleResult[];
51
53
  //#endregion
52
54
  export { RenderResult, StyleResult, isSelector, renderStyles };
@@ -1,14 +1,14 @@
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, isValueMapping, mergeEntriesByValue, parseStyleEntries } from "./exclusive.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
  //#region src/pipeline/index.ts
13
13
  /**
14
14
  * Tasty Style Rendering Pipeline
@@ -27,6 +27,13 @@ import { parseStateKey } from "./parseStateKey.js";
27
27
  */
28
28
  const pipelineCache = new Lru(5e3);
29
29
  /**
30
+ * Check if a cache key exists in the pipeline cache.
31
+ * Used by renderStylesForChunk to avoid building filtered styles on cache hit.
32
+ */
33
+ function hasPipelineCacheEntry(cacheKey) {
34
+ return pipelineCache.get(cacheKey) !== void 0;
35
+ }
36
+ /**
30
37
  * Clear the pipeline cache (for testing)
31
38
  */
32
39
  function clearPipelineCache() {
@@ -36,12 +43,17 @@ function runPipeline(styles, parserContext) {
36
43
  const allRules = [];
37
44
  processStyles(styles, "", parserContext, allRules);
38
45
  const seen = /* @__PURE__ */ new Set();
39
- return allRules.filter((rule) => {
40
- const key = `${rule.selector}|${rule.declarations}|${JSON.stringify(rule.atRules || [])}|${rule.rootPrefix || ""}`;
46
+ const dedupedRules = allRules.filter((rule) => {
47
+ const key = `${rule.selector}|${rule.declarations}|${rule.atRules?.join("|") ?? ""}|${rule.rootPrefix || ""}|${rule.startingStyle ? "1" : "0"}`;
41
48
  if (seen.has(key)) return false;
42
49
  seen.add(key);
43
50
  return true;
44
51
  });
52
+ const normal = [];
53
+ const starting = [];
54
+ for (const rule of dedupedRules) if (rule.startingStyle) starting.push(rule);
55
+ else normal.push(rule);
56
+ return normal.concat(starting);
45
57
  }
46
58
  /**
47
59
  * Process styles at a given nesting level
@@ -76,7 +88,7 @@ function processStyles(styles, selectorSuffix, parserContext, allRules) {
76
88
  const value = styleMap[styleName];
77
89
  if (value === void 0) continue;
78
90
  if (isValueMapping(value)) {
79
- const fullyExpanded = expandExclusiveOrs(buildExclusiveConditions(expandOrConditions(parseStyleEntries(styleName, value, (stateKey) => parseStateKey(stateKey, { context: parserContext })))));
91
+ const fullyExpanded = expandExclusiveOrs(buildExclusiveConditions(expandOrConditions(mergeEntriesByValue(parseStyleEntries(styleName, value, (stateKey) => parseStateKey(stateKey, { context: parserContext }))))));
80
92
  exclusiveByStyle.set(styleName, fullyExpanded);
81
93
  } else exclusiveByStyle.set(styleName, [{
82
94
  styleKey: styleName,
@@ -147,7 +159,7 @@ function getAllSelectors(key, styles) {
147
159
  if (affix !== void 0) {
148
160
  const result = processAffix(String(affix), key);
149
161
  if (!result.valid) {
150
- console.warn(`[Tasty] ${result.reason}`);
162
+ emitWarning("INVALID_SELECTOR_AFFIX", result.reason);
151
163
  return null;
152
164
  }
153
165
  return result.selectors;
@@ -162,7 +174,8 @@ function getAllSelectors(key, styles) {
162
174
  * Supports:
163
175
  * - Direct child: '>'
164
176
  * - Chained elements: '>Body>Row>'
165
- * - HTML tags: 'a', '>ul>li', 'button:hover'
177
+ * - HTML tags (no key injection): 'h1', '>ul>li', 'button:hover'
178
+ * - Universal selector: '*', 'h1 *'
166
179
  * - Pseudo-elements on root: '::before'
167
180
  * - Pseudo on sub-element: '@::before', '>@:hover'
168
181
  * - Classes: '.active', '>@.active'
@@ -199,6 +212,7 @@ function processAffix(affix, key) {
199
212
  */
200
213
  const VALID_TOKEN_PATTERNS = [
201
214
  /^[>+~]/,
215
+ /^\*/,
202
216
  /^[A-Z][a-zA-Z0-9]*/,
203
217
  /^@/,
204
218
  /^::?[a-z][a-z0-9-]*(?:\([^)]*\))?/,
@@ -333,12 +347,13 @@ function processSinglePattern(pattern, key) {
333
347
  * The tokenizer handles these token types in order:
334
348
  * 1. Whitespace (skipped)
335
349
  * 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)
350
+ * 3. Universal selector: * (keep as-is with spacing)
351
+ * 4. Uppercase names: Body, Row (convert to [data-element="..."])
352
+ * 5. @ placeholder (keep for later replacement)
353
+ * 6. Pseudo: :hover, ::before (attach to previous token)
354
+ * 7. Tags: a, div, button (keep as-is with spacing)
355
+ * 8. Classes: .active (attach to previous element/tag/placeholder)
356
+ * 9. Attributes: [type="text"] (keep as-is)
342
357
  *
343
358
  * @param pattern - The raw selector pattern to transform
344
359
  * @returns Transformed pattern with proper CSS selector syntax
@@ -352,6 +367,7 @@ function processSinglePattern(pattern, key) {
352
367
  */
353
368
  function transformPattern(pattern) {
354
369
  let result = "";
370
+ let lastCh = "";
355
371
  let i = 0;
356
372
  while (i < pattern.length) {
357
373
  const char = pattern[i];
@@ -360,76 +376,80 @@ function transformPattern(pattern) {
360
376
  continue;
361
377
  }
362
378
  if (/[>+~]/.test(char)) {
363
- if (result && !result.endsWith(" ")) result += " ";
379
+ if (result && lastCh !== " ") result += " ";
364
380
  result += char;
381
+ lastCh = char;
382
+ i++;
383
+ continue;
384
+ }
385
+ if (char === "*") {
386
+ if (result && lastCh !== " ") result += " ";
387
+ result += "*";
388
+ lastCh = "*";
365
389
  i++;
366
390
  continue;
367
391
  }
368
392
  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}"]`;
393
+ const nameStart = i;
394
+ while (i < pattern.length && /[a-zA-Z0-9]/.test(pattern[i])) i++;
395
+ if (result && lastCh !== " ") result += " ";
396
+ const segment = `[data-element="${pattern.slice(nameStart, i)}"]`;
397
+ result += segment;
398
+ lastCh = "]";
376
399
  continue;
377
400
  }
378
401
  if (char === "@") {
379
- if (result && !result.endsWith(" ")) result += " ";
402
+ if (result && lastCh !== " ") result += " ";
380
403
  result += "@";
404
+ lastCh = "@";
381
405
  i++;
382
406
  continue;
383
407
  }
384
408
  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;
409
+ const pseudoStart = i;
410
+ while (i < pattern.length && !/[\s>+~,@]/.test(pattern[i]) && !/[A-Z]/.test(pattern[i])) i++;
411
+ const segment = pattern.slice(pseudoStart, i);
412
+ result += segment;
413
+ lastCh = segment[segment.length - 1] || lastCh;
391
414
  continue;
392
415
  }
393
416
  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;
417
+ const tagStart = i;
418
+ while (i < pattern.length && /[a-z0-9-]/.test(pattern[i])) i++;
419
+ if (result && lastCh !== " ") result += " ";
420
+ const segment = pattern.slice(tagStart, i);
421
+ result += segment;
422
+ lastCh = segment[segment.length - 1] || lastCh;
401
423
  continue;
402
424
  }
403
425
  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 = ".";
426
+ const attachToLast = lastCh === "]" || lastCh === "@" || /[a-zA-Z0-9-]/.test(lastCh);
427
+ if (result && !attachToLast && lastCh !== " ") result += " ";
428
+ const clsStart = i;
408
429
  i++;
409
- while (i < pattern.length && /[a-zA-Z0-9_-]/.test(pattern[i])) {
410
- cls += pattern[i];
411
- i++;
412
- }
413
- result += cls;
430
+ while (i < pattern.length && /[a-zA-Z0-9_-]/.test(pattern[i])) i++;
431
+ const segment = pattern.slice(clsStart, i);
432
+ result += segment;
433
+ lastCh = segment[segment.length - 1] || lastCh;
414
434
  continue;
415
435
  }
416
436
  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 = "";
437
+ const attachToLast = lastCh === "]" || lastCh === "@" || /[a-zA-Z0-9-]/.test(lastCh);
438
+ if (result && !attachToLast && lastCh !== " ") result += " ";
439
+ const attrStart = i;
421
440
  let depth = 0;
422
441
  while (i < pattern.length) {
423
- attr += pattern[i];
424
442
  if (pattern[i] === "[") depth++;
425
443
  if (pattern[i] === "]") depth--;
426
444
  i++;
427
445
  if (depth === 0) break;
428
446
  }
429
- result += attr;
447
+ result += pattern.slice(attrStart, i);
448
+ lastCh = "]";
430
449
  continue;
431
450
  }
432
451
  result += char;
452
+ lastCh = char;
433
453
  i++;
434
454
  }
435
455
  return result;
@@ -443,7 +463,8 @@ function transformPattern(pattern) {
443
463
  * |----------------|-------------|---------|--------|
444
464
  * | Combinator (>, +, ~) | Yes | `'>Body>'` | `> [data-element="Body"] > [el]` |
445
465
  * | Uppercase element | Yes | `'>Body>Row'` | `> [el1] > [el2] [key]` |
446
- * | Lowercase tag | Yes | `'>ul>li'` | `> ul > li [key]` |
466
+ * | Lowercase tag | No | `'h1'` | ` h1` |
467
+ * | Universal (*) | No | `'h1 *'` | ` h1 *` |
447
468
  * | Pseudo (:hover, ::before) | No | `'::before'` | `::before` |
448
469
  * | Class (.active) | No | `'.active'` | `.active` |
449
470
  * | Attribute ([type]) | No | `'[type="text"]'` | `[type="text"]` |
@@ -454,7 +475,8 @@ function transformPattern(pattern) {
454
475
  * @example
455
476
  * shouldInjectKey('>') // → true (trailing combinator)
456
477
  * shouldInjectKey('>Body>Row') // → true (ends with element)
457
- * shouldInjectKey('>ul>li') // → true (ends with tag)
478
+ * shouldInjectKey('h1') // → false (ends with tag)
479
+ * shouldInjectKey('*') // → false (universal selector)
458
480
  * shouldInjectKey('::before') // → false (ends with pseudo)
459
481
  * shouldInjectKey('.active') // → false (ends with class)
460
482
  * shouldInjectKey('a:hover') // → false (ends with pseudo)
@@ -464,7 +486,6 @@ function shouldInjectKey(pattern) {
464
486
  const trimmed = pattern.trim();
465
487
  if (/[>+~]$/.test(trimmed)) return true;
466
488
  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
489
  return false;
469
490
  }
470
491
  /**
@@ -525,7 +546,27 @@ function cartesianProduct(arrays) {
525
546
  if (arrays.length === 0) return [[]];
526
547
  const nonEmpty = arrays.filter((a) => a.length > 0);
527
548
  if (nonEmpty.length === 0) return [[]];
528
- return nonEmpty.reduce((acc, arr) => acc.flatMap((combo) => arr.map((item) => [...combo, item])), [[]]);
549
+ let result = [[]];
550
+ for (const arr of nonEmpty) {
551
+ const next = [];
552
+ for (const combo of result) for (const item of arr) {
553
+ const newCombo = new Array(combo.length + 1);
554
+ for (let i = 0; i < combo.length; i++) newCombo[i] = combo[i];
555
+ newCombo[combo.length] = item;
556
+ next.push(newCombo);
557
+ }
558
+ result = next;
559
+ }
560
+ return result;
561
+ }
562
+ const declStringCache = /* @__PURE__ */ new WeakMap();
563
+ function stringifyDeclarations(decl) {
564
+ let cached = declStringCache.get(decl);
565
+ if (cached === void 0) {
566
+ cached = JSON.stringify(decl);
567
+ declStringCache.set(decl, cached);
568
+ }
569
+ return cached;
529
570
  }
530
571
  /**
531
572
  * Merge rules with identical CSS output
@@ -533,7 +574,7 @@ function cartesianProduct(arrays) {
533
574
  function mergeByValue(rules) {
534
575
  const groups = /* @__PURE__ */ new Map();
535
576
  for (const rule of rules) {
536
- const key = `${rule.selectorSuffix}|${JSON.stringify(rule.declarations)}`;
577
+ const key = `${rule.selectorSuffix}|${stringifyDeclarations(rule.declarations)}`;
537
578
  if (!groups.has(key)) groups.set(key, []);
538
579
  groups.get(key).push(rule);
539
580
  }
@@ -554,11 +595,12 @@ function mergeByValue(rules) {
554
595
  */
555
596
  function buildSelectorFromVariant(variant, selectorSuffix) {
556
597
  let selector = "";
557
- for (const mod of variant.modifierConditions) selector += modifierToCSS(mod);
558
- for (const pseudo of variant.pseudoConditions) selector += pseudoToCSS(pseudo);
598
+ selector += branchToCSS([...variant.modifierConditions, ...variant.pseudoConditions]);
599
+ for (const group of variant.selectorGroups) selector += selectorGroupToCSS(group);
559
600
  if (variant.parentGroups.length > 0) selector += parentGroupsToCSS(variant.parentGroups);
560
601
  selector += selectorSuffix;
561
- for (const own of variant.ownConditions) selector += selectorConditionToCSS(own);
602
+ const ownOptimized = optimizeGroups(variant.ownGroups);
603
+ for (const group of ownOptimized) selector += selectorGroupToCSS(group);
562
604
  return selector;
563
605
  }
564
606
  /**
@@ -572,45 +614,68 @@ function materializeComputedRule(rule) {
572
614
  if (components.isImpossible || components.variants.length === 0) return [];
573
615
  const declarations = Object.entries(rule.declarations).map(([prop, value]) => `${prop}: ${value};`).join(" ");
574
616
  const getRootPrefixKey = (variant) => {
575
- return variant.rootConditions.map((r) => selectorConditionToCSS(r)).sort().join("|");
617
+ return rootGroupsToCSS(variant.rootGroups) || "";
576
618
  };
577
619
  const byAtRules = /* @__PURE__ */ new Map();
578
620
  for (const variant of components.variants) {
579
621
  const atRules = buildAtRulesFromVariant(variant);
580
- const key = atRules.sort().join("|||") + "###" + getRootPrefixKey(variant);
622
+ const startingStyle = variant.startingStyle;
623
+ const key = atRules.sort().join("|||") + "###" + getRootPrefixKey(variant) + "###" + (startingStyle ? "1" : "0");
581
624
  const group = byAtRules.get(key);
582
625
  if (group) group.variants.push(variant);
583
626
  else byAtRules.set(key, {
584
627
  variants: [variant],
585
628
  atRules,
586
- rootPrefix: rootConditionsToCSS(variant.rootConditions)
629
+ rootPrefix: rootGroupsToCSS(variant.rootGroups),
630
+ startingStyle: startingStyle || void 0
587
631
  });
588
632
  }
589
633
  const rules = [];
590
634
  for (const [, group] of byAtRules) {
591
- const selectorFragments = group.variants.map((v) => buildSelectorFromVariant(v, rule.selectorSuffix));
635
+ const selectorFragments = mergeVariantsIntoSelectorGroups(group.variants).map((v) => buildSelectorFromVariant(v, rule.selectorSuffix));
592
636
  const cssRule = {
593
637
  selector: selectorFragments.length === 1 ? selectorFragments[0] : selectorFragments,
594
638
  declarations
595
639
  };
596
640
  if (group.atRules.length > 0) cssRule.atRules = group.atRules;
597
641
  if (group.rootPrefix) cssRule.rootPrefix = group.rootPrefix;
642
+ if (group.startingStyle) cssRule.startingStyle = true;
598
643
  rules.push(cssRule);
599
644
  }
600
645
  return rules;
601
646
  }
602
- function renderStyles(styles, classNameOrSelector, options) {
647
+ /**
648
+ * Merge StyleResult entries that share the same selector and at-rules,
649
+ * concatenating their declarations into a single rule.
650
+ *
651
+ * This reduces CSS output size when many style keys (e.g. design tokens)
652
+ * resolve to the same selector/state combination.
653
+ */
654
+ function mergeStyleResults(results) {
655
+ if (results.length <= 1) return results;
656
+ const groups = /* @__PURE__ */ new Map();
657
+ for (const result of results) {
658
+ const key = `${result.atRules?.join("|") ?? ""}||${result.selector}||${result.startingStyle ? "1" : "0"}`;
659
+ const existing = groups.get(key);
660
+ if (existing) existing.declarations = existing.declarations ? `${existing.declarations} ${result.declarations}` : result.declarations;
661
+ else groups.set(key, { ...result });
662
+ }
663
+ return Array.from(groups.values());
664
+ }
665
+ function renderStyles(styles, classNameOrSelector, options, pipelineCacheKey) {
603
666
  const directSelector = !!classNameOrSelector;
604
- if (!styles) return directSelector ? [] : { rules: [] };
605
- const cacheKey = stringifyStyles(styles);
606
- let rules = pipelineCache.get(cacheKey);
667
+ let rules;
668
+ if (pipelineCacheKey) rules = pipelineCache.get(pipelineCacheKey);
669
+ if (!rules && !styles) return directSelector ? [] : { rules: [] };
670
+ const cacheKey = pipelineCacheKey || stringifyStyles(styles);
671
+ if (!rules) rules = pipelineCache.get(cacheKey);
607
672
  if (!rules) {
608
673
  rules = runPipeline(styles, createStateParserContext(styles));
609
674
  pipelineCache.set(cacheKey, rules);
610
675
  }
611
676
  if (directSelector) {
612
677
  const shouldDouble = options?.doubleSelector ?? false;
613
- return rules.map((rule) => {
678
+ return mergeStyleResults(rules.map((rule) => {
614
679
  const result = {
615
680
  selector: (Array.isArray(rule.selector) ? rule.selector : rule.selector ? [rule.selector] : [""]).map((part) => {
616
681
  let sel = part ? `${classNameOrSelector}${part}` : classNameOrSelector;
@@ -624,18 +689,20 @@ function renderStyles(styles, classNameOrSelector, options) {
624
689
  declarations: rule.declarations
625
690
  };
626
691
  if (rule.atRules && rule.atRules.length > 0) result.atRules = rule.atRules;
692
+ if (rule.startingStyle) result.startingStyle = true;
627
693
  return result;
628
- });
694
+ }));
629
695
  }
630
696
  return { rules: rules.map((r) => ({
631
697
  selector: Array.isArray(r.selector) ? r.selector.join("|||") : r.selector,
632
698
  declarations: r.declarations,
633
699
  atRules: r.atRules,
634
700
  needsClassName: true,
635
- rootPrefix: r.rootPrefix
701
+ rootPrefix: r.rootPrefix,
702
+ startingStyle: r.startingStyle
636
703
  })) };
637
704
  }
638
-
639
705
  //#endregion
640
- export { clearPipelineCache, isSelector, renderStyles };
706
+ export { clearPipelineCache, hasPipelineCacheEntry, isSelector, renderStyles };
707
+
641
708
  //# sourceMappingURL=index.js.map