@tenphi/tasty 0.0.0-snapshot.bbd10c7 → 0.0.0-snapshot.bbfcd75

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 (370) hide show
  1. package/README.md +196 -140
  2. package/dist/babel-Zs1Q03qt.d.ts +83 -0
  3. package/dist/chunks/async-storage-CG5HnUT5.js +20 -0
  4. package/dist/chunks/async-storage-CG5HnUT5.js.map +1 -0
  5. package/dist/chunks/build-config-CUQVwdWF.js +42 -0
  6. package/dist/chunks/build-config-CUQVwdWF.js.map +1 -0
  7. package/dist/chunks/collector-B0LTHw6Z.js +208 -0
  8. package/dist/chunks/collector-B0LTHw6Z.js.map +1 -0
  9. package/dist/chunks/config-engine-C3pF9EK9.js +267 -0
  10. package/dist/chunks/config-engine-C3pF9EK9.js.map +1 -0
  11. package/dist/chunks/css-definitions-D_it4XZH.js +875 -0
  12. package/dist/chunks/css-definitions-D_it4XZH.js.map +1 -0
  13. package/dist/chunks/css-resources-BN8apgxt.js +142 -0
  14. package/dist/chunks/css-resources-BN8apgxt.js.map +1 -0
  15. package/dist/{debug.js → chunks/debug-C9LeNVoJ.js} +187 -139
  16. package/dist/chunks/debug-C9LeNVoJ.js.map +1 -0
  17. package/dist/chunks/dsl-C5yuAn41.js +1373 -0
  18. package/dist/chunks/dsl-C5yuAn41.js.map +1 -0
  19. package/dist/chunks/hydration-TRcz5vnk.js +41 -0
  20. package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
  21. package/dist/chunks/react-runtime-O-OUrKLH.js +557 -0
  22. package/dist/chunks/react-runtime-O-OUrKLH.js.map +1 -0
  23. package/dist/chunks/runtime-engine-DvnE2g-E.js +2437 -0
  24. package/dist/chunks/runtime-engine-DvnE2g-E.js.map +1 -0
  25. package/dist/chunks/runtime-state-BTDqSYBk.js +127 -0
  26. package/dist/chunks/runtime-state-BTDqSYBk.js.map +1 -0
  27. package/dist/{utils/merge-styles.js → chunks/shared-utils-DWA4LjIa.js} +55 -55
  28. package/dist/chunks/shared-utils-DWA4LjIa.js.map +1 -0
  29. package/dist/chunks/style-engine-C1ECBZxR.js +5131 -0
  30. package/dist/chunks/style-engine-C1ECBZxR.js.map +1 -0
  31. package/dist/{zero/extractor.js → chunks/zero-engine-B6EnYcXY.js} +89 -82
  32. package/dist/chunks/zero-engine-B6EnYcXY.js.map +1 -0
  33. package/dist/collector-hl5KNH7k.d.ts +165 -0
  34. package/dist/config-DWL1ZYue.d.ts +1358 -0
  35. package/dist/core/index.d.ts +5 -34
  36. package/dist/core/index.js +9 -27
  37. package/dist/index-D9N9GV24.d.ts +1947 -0
  38. package/dist/index.d.ts +5 -51
  39. package/dist/index.js +11 -36
  40. package/dist/{utils/merge-styles.d.ts → merge-styles-C_oMoJVd.d.ts} +3 -3
  41. package/dist/ssr/astro-client.js +6 -0
  42. package/dist/ssr/astro-client.js.map +1 -0
  43. package/dist/ssr/astro-middleware-extract-static.d.ts +11 -0
  44. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  45. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  46. package/dist/ssr/astro-middleware-extract.d.ts +11 -0
  47. package/dist/ssr/astro-middleware-extract.js +9 -0
  48. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  49. package/dist/ssr/astro-middleware-static.d.ts +18 -0
  50. package/dist/ssr/astro-middleware-static.js +7 -0
  51. package/dist/ssr/astro-middleware-static.js.map +1 -0
  52. package/dist/ssr/astro-middleware.d.ts +19 -0
  53. package/dist/ssr/astro-middleware.js +7 -0
  54. package/dist/ssr/astro-middleware.js.map +1 -0
  55. package/dist/ssr/astro.d.ts +117 -11
  56. package/dist/ssr/astro.js +204 -48
  57. package/dist/ssr/astro.js.map +1 -1
  58. package/dist/ssr/index.d.ts +37 -4
  59. package/dist/ssr/index.js +6 -6
  60. package/dist/ssr/index.js.map +1 -1
  61. package/dist/ssr/next-config.d.ts +66 -0
  62. package/dist/ssr/next-config.js +124 -0
  63. package/dist/ssr/next-config.js.map +1 -0
  64. package/dist/ssr/next.d.ts +14 -5
  65. package/dist/ssr/next.js +31 -46
  66. package/dist/ssr/next.js.map +1 -1
  67. package/dist/static/index.d.ts +91 -5
  68. package/dist/static/index.js +31 -3
  69. package/dist/static/index.js.map +1 -0
  70. package/dist/static/inject.js.map +1 -1
  71. package/dist/types-jKZNpias.d.ts +1616 -0
  72. package/dist/zero/babel.d.ts +2 -182
  73. package/dist/zero/babel.js +82 -113
  74. package/dist/zero/babel.js.map +1 -1
  75. package/dist/zero/index.d.ts +81 -3
  76. package/dist/zero/index.js +2 -3
  77. package/dist/zero/next.d.ts +1 -1
  78. package/dist/zero/next.js +0 -31
  79. package/dist/zero/next.js.map +1 -1
  80. package/docs/README.md +20 -12
  81. package/docs/adoption.md +59 -32
  82. package/docs/ai-agents.md +229 -0
  83. package/docs/comparison.md +76 -48
  84. package/docs/configuration.md +566 -69
  85. package/docs/debug.md +37 -23
  86. package/docs/design-system.md +63 -32
  87. package/docs/dsl.md +527 -179
  88. package/docs/getting-started.md +62 -41
  89. package/docs/injector.md +157 -51
  90. package/docs/methodology.md +69 -37
  91. package/docs/migration-v3.md +285 -0
  92. package/docs/pipeline.md +744 -0
  93. package/docs/plugins.md +353 -0
  94. package/docs/{runtime.md → react-api.md} +176 -67
  95. package/docs/runtime-benchmarks.md +377 -0
  96. package/docs/ssr.md +350 -94
  97. package/docs/styles.md +108 -27
  98. package/docs/tasty-static.md +149 -87
  99. package/package.json +121 -23
  100. package/tasty.config.ts +6 -0
  101. package/dist/_virtual/_rolldown/runtime.js +0 -7
  102. package/dist/chunks/cacheKey.js +0 -77
  103. package/dist/chunks/cacheKey.js.map +0 -1
  104. package/dist/chunks/definitions.d.ts +0 -37
  105. package/dist/chunks/definitions.js +0 -258
  106. package/dist/chunks/definitions.js.map +0 -1
  107. package/dist/chunks/index.d.ts +0 -1
  108. package/dist/chunks/renderChunk.d.ts +0 -1
  109. package/dist/chunks/renderChunk.js +0 -59
  110. package/dist/chunks/renderChunk.js.map +0 -1
  111. package/dist/compute-styles.d.ts +0 -31
  112. package/dist/compute-styles.js +0 -356
  113. package/dist/compute-styles.js.map +0 -1
  114. package/dist/config.d.ts +0 -372
  115. package/dist/config.js +0 -507
  116. package/dist/config.js.map +0 -1
  117. package/dist/counter-style/index.js +0 -51
  118. package/dist/counter-style/index.js.map +0 -1
  119. package/dist/debug.d.ts +0 -89
  120. package/dist/debug.js.map +0 -1
  121. package/dist/font-face/index.js +0 -63
  122. package/dist/font-face/index.js.map +0 -1
  123. package/dist/hooks/index.d.ts +0 -7
  124. package/dist/hooks/useCounterStyle.d.ts +0 -50
  125. package/dist/hooks/useCounterStyle.js +0 -45
  126. package/dist/hooks/useCounterStyle.js.map +0 -1
  127. package/dist/hooks/useFontFace.d.ts +0 -43
  128. package/dist/hooks/useFontFace.js +0 -69
  129. package/dist/hooks/useFontFace.js.map +0 -1
  130. package/dist/hooks/useGlobalStyles.d.ts +0 -30
  131. package/dist/hooks/useGlobalStyles.js +0 -77
  132. package/dist/hooks/useGlobalStyles.js.map +0 -1
  133. package/dist/hooks/useKeyframes.d.ts +0 -56
  134. package/dist/hooks/useKeyframes.js +0 -63
  135. package/dist/hooks/useKeyframes.js.map +0 -1
  136. package/dist/hooks/useProperty.d.ts +0 -79
  137. package/dist/hooks/useProperty.js +0 -108
  138. package/dist/hooks/useProperty.js.map +0 -1
  139. package/dist/hooks/useRawCSS.d.ts +0 -53
  140. package/dist/hooks/useRawCSS.js +0 -34
  141. package/dist/hooks/useRawCSS.js.map +0 -1
  142. package/dist/hooks/useStyles.d.ts +0 -40
  143. package/dist/hooks/useStyles.js +0 -29
  144. package/dist/hooks/useStyles.js.map +0 -1
  145. package/dist/injector/index.d.ts +0 -166
  146. package/dist/injector/index.js +0 -166
  147. package/dist/injector/index.js.map +0 -1
  148. package/dist/injector/injector.d.ts +0 -166
  149. package/dist/injector/injector.js +0 -464
  150. package/dist/injector/injector.js.map +0 -1
  151. package/dist/injector/sheet-manager.d.ts +0 -136
  152. package/dist/injector/sheet-manager.js +0 -733
  153. package/dist/injector/sheet-manager.js.map +0 -1
  154. package/dist/injector/types.d.ts +0 -204
  155. package/dist/keyframes/index.js +0 -206
  156. package/dist/keyframes/index.js.map +0 -1
  157. package/dist/parser/classify.js +0 -319
  158. package/dist/parser/classify.js.map +0 -1
  159. package/dist/parser/const.js +0 -60
  160. package/dist/parser/const.js.map +0 -1
  161. package/dist/parser/lru.js +0 -109
  162. package/dist/parser/lru.js.map +0 -1
  163. package/dist/parser/parser.d.ts +0 -25
  164. package/dist/parser/parser.js +0 -115
  165. package/dist/parser/parser.js.map +0 -1
  166. package/dist/parser/tokenizer.js +0 -69
  167. package/dist/parser/tokenizer.js.map +0 -1
  168. package/dist/parser/types.d.ts +0 -51
  169. package/dist/parser/types.js +0 -46
  170. package/dist/parser/types.js.map +0 -1
  171. package/dist/pipeline/conditions.d.ts +0 -134
  172. package/dist/pipeline/conditions.js +0 -406
  173. package/dist/pipeline/conditions.js.map +0 -1
  174. package/dist/pipeline/exclusive.js +0 -230
  175. package/dist/pipeline/exclusive.js.map +0 -1
  176. package/dist/pipeline/index.d.ts +0 -55
  177. package/dist/pipeline/index.js +0 -708
  178. package/dist/pipeline/index.js.map +0 -1
  179. package/dist/pipeline/materialize.js +0 -1103
  180. package/dist/pipeline/materialize.js.map +0 -1
  181. package/dist/pipeline/parseStateKey.d.ts +0 -15
  182. package/dist/pipeline/parseStateKey.js +0 -446
  183. package/dist/pipeline/parseStateKey.js.map +0 -1
  184. package/dist/pipeline/simplify.js +0 -515
  185. package/dist/pipeline/simplify.js.map +0 -1
  186. package/dist/pipeline/warnings.js +0 -18
  187. package/dist/pipeline/warnings.js.map +0 -1
  188. package/dist/plugins/index.d.ts +0 -2
  189. package/dist/plugins/okhsl-plugin.d.ts +0 -35
  190. package/dist/plugins/okhsl-plugin.js +0 -97
  191. package/dist/plugins/okhsl-plugin.js.map +0 -1
  192. package/dist/plugins/types.d.ts +0 -76
  193. package/dist/properties/index.js +0 -222
  194. package/dist/properties/index.js.map +0 -1
  195. package/dist/properties/property-type-resolver.d.ts +0 -24
  196. package/dist/properties/property-type-resolver.js +0 -90
  197. package/dist/properties/property-type-resolver.js.map +0 -1
  198. package/dist/ssr/async-storage.d.ts +0 -17
  199. package/dist/ssr/async-storage.js +0 -34
  200. package/dist/ssr/async-storage.js.map +0 -1
  201. package/dist/ssr/collect-auto-properties.js +0 -39
  202. package/dist/ssr/collect-auto-properties.js.map +0 -1
  203. package/dist/ssr/collector.d.ts +0 -102
  204. package/dist/ssr/collector.js +0 -219
  205. package/dist/ssr/collector.js.map +0 -1
  206. package/dist/ssr/format-global-rules.js +0 -22
  207. package/dist/ssr/format-global-rules.js.map +0 -1
  208. package/dist/ssr/format-keyframes.js +0 -69
  209. package/dist/ssr/format-keyframes.js.map +0 -1
  210. package/dist/ssr/format-property.js +0 -49
  211. package/dist/ssr/format-property.js.map +0 -1
  212. package/dist/ssr/format-rules.js +0 -73
  213. package/dist/ssr/format-rules.js.map +0 -1
  214. package/dist/ssr/hydrate.d.ts +0 -22
  215. package/dist/ssr/hydrate.js +0 -49
  216. package/dist/ssr/hydrate.js.map +0 -1
  217. package/dist/ssr/ssr-collector-ref.js +0 -12
  218. package/dist/ssr/ssr-collector-ref.js.map +0 -1
  219. package/dist/states/index.d.ts +0 -49
  220. package/dist/states/index.js +0 -170
  221. package/dist/states/index.js.map +0 -1
  222. package/dist/static/tastyStatic.d.ts +0 -46
  223. package/dist/static/tastyStatic.js +0 -30
  224. package/dist/static/tastyStatic.js.map +0 -1
  225. package/dist/static/types.d.ts +0 -49
  226. package/dist/static/types.js +0 -24
  227. package/dist/static/types.js.map +0 -1
  228. package/dist/styles/border.d.ts +0 -25
  229. package/dist/styles/border.js +0 -120
  230. package/dist/styles/border.js.map +0 -1
  231. package/dist/styles/color.d.ts +0 -14
  232. package/dist/styles/color.js +0 -26
  233. package/dist/styles/color.js.map +0 -1
  234. package/dist/styles/const.js +0 -17
  235. package/dist/styles/const.js.map +0 -1
  236. package/dist/styles/createStyle.js +0 -79
  237. package/dist/styles/createStyle.js.map +0 -1
  238. package/dist/styles/dimension.js +0 -109
  239. package/dist/styles/dimension.js.map +0 -1
  240. package/dist/styles/directional.js +0 -133
  241. package/dist/styles/directional.js.map +0 -1
  242. package/dist/styles/display.d.ts +0 -30
  243. package/dist/styles/display.js +0 -73
  244. package/dist/styles/display.js.map +0 -1
  245. package/dist/styles/fade.d.ts +0 -15
  246. package/dist/styles/fade.js +0 -62
  247. package/dist/styles/fade.js.map +0 -1
  248. package/dist/styles/fill.d.ts +0 -42
  249. package/dist/styles/fill.js +0 -51
  250. package/dist/styles/fill.js.map +0 -1
  251. package/dist/styles/flow.d.ts +0 -16
  252. package/dist/styles/flow.js +0 -12
  253. package/dist/styles/flow.js.map +0 -1
  254. package/dist/styles/gap.d.ts +0 -31
  255. package/dist/styles/gap.js +0 -38
  256. package/dist/styles/gap.js.map +0 -1
  257. package/dist/styles/height.d.ts +0 -17
  258. package/dist/styles/height.js +0 -19
  259. package/dist/styles/height.js.map +0 -1
  260. package/dist/styles/index.d.ts +0 -1
  261. package/dist/styles/index.js +0 -8
  262. package/dist/styles/index.js.map +0 -1
  263. package/dist/styles/inset.d.ts +0 -24
  264. package/dist/styles/inset.js +0 -34
  265. package/dist/styles/inset.js.map +0 -1
  266. package/dist/styles/list.d.ts +0 -16
  267. package/dist/styles/list.js +0 -100
  268. package/dist/styles/list.js.map +0 -1
  269. package/dist/styles/margin.d.ts +0 -24
  270. package/dist/styles/margin.js +0 -32
  271. package/dist/styles/margin.js.map +0 -1
  272. package/dist/styles/outline.d.ts +0 -29
  273. package/dist/styles/outline.js +0 -55
  274. package/dist/styles/outline.js.map +0 -1
  275. package/dist/styles/padding.d.ts +0 -24
  276. package/dist/styles/padding.js +0 -32
  277. package/dist/styles/padding.js.map +0 -1
  278. package/dist/styles/placement.d.ts +0 -37
  279. package/dist/styles/placement.js +0 -74
  280. package/dist/styles/placement.js.map +0 -1
  281. package/dist/styles/predefined.d.ts +0 -71
  282. package/dist/styles/predefined.js +0 -237
  283. package/dist/styles/predefined.js.map +0 -1
  284. package/dist/styles/preset.d.ts +0 -52
  285. package/dist/styles/preset.js +0 -127
  286. package/dist/styles/preset.js.map +0 -1
  287. package/dist/styles/radius.d.ts +0 -12
  288. package/dist/styles/radius.js +0 -83
  289. package/dist/styles/radius.js.map +0 -1
  290. package/dist/styles/scrollMargin.d.ts +0 -24
  291. package/dist/styles/scrollMargin.js +0 -32
  292. package/dist/styles/scrollMargin.js.map +0 -1
  293. package/dist/styles/scrollbar.d.ts +0 -25
  294. package/dist/styles/scrollbar.js +0 -51
  295. package/dist/styles/scrollbar.js.map +0 -1
  296. package/dist/styles/shadow.d.ts +0 -14
  297. package/dist/styles/shadow.js +0 -25
  298. package/dist/styles/shadow.js.map +0 -1
  299. package/dist/styles/shared.js +0 -17
  300. package/dist/styles/shared.js.map +0 -1
  301. package/dist/styles/transition.d.ts +0 -14
  302. package/dist/styles/transition.js +0 -159
  303. package/dist/styles/transition.js.map +0 -1
  304. package/dist/styles/types.d.ts +0 -564
  305. package/dist/styles/width.d.ts +0 -17
  306. package/dist/styles/width.js +0 -19
  307. package/dist/styles/width.js.map +0 -1
  308. package/dist/tasty.d.ts +0 -134
  309. package/dist/tasty.js +0 -240
  310. package/dist/tasty.js.map +0 -1
  311. package/dist/types.d.ts +0 -184
  312. package/dist/utils/cache-wrapper.js +0 -21
  313. package/dist/utils/cache-wrapper.js.map +0 -1
  314. package/dist/utils/case-converter.js +0 -8
  315. package/dist/utils/case-converter.js.map +0 -1
  316. package/dist/utils/color-math.d.ts +0 -46
  317. package/dist/utils/color-math.js +0 -749
  318. package/dist/utils/color-math.js.map +0 -1
  319. package/dist/utils/color-space.d.ts +0 -5
  320. package/dist/utils/color-space.js +0 -228
  321. package/dist/utils/color-space.js.map +0 -1
  322. package/dist/utils/colors.d.ts +0 -5
  323. package/dist/utils/colors.js +0 -10
  324. package/dist/utils/colors.js.map +0 -1
  325. package/dist/utils/css-types.d.ts +0 -7
  326. package/dist/utils/dotize.d.ts +0 -26
  327. package/dist/utils/dotize.js +0 -122
  328. package/dist/utils/dotize.js.map +0 -1
  329. package/dist/utils/filter-base-props.d.ts +0 -15
  330. package/dist/utils/filter-base-props.js +0 -45
  331. package/dist/utils/filter-base-props.js.map +0 -1
  332. package/dist/utils/get-display-name.d.ts +0 -7
  333. package/dist/utils/get-display-name.js +0 -10
  334. package/dist/utils/get-display-name.js.map +0 -1
  335. package/dist/utils/has-keys.js +0 -13
  336. package/dist/utils/has-keys.js.map +0 -1
  337. package/dist/utils/is-dev-env.js +0 -19
  338. package/dist/utils/is-dev-env.js.map +0 -1
  339. package/dist/utils/is-valid-element-type.js +0 -15
  340. package/dist/utils/is-valid-element-type.js.map +0 -1
  341. package/dist/utils/merge-styles.js.map +0 -1
  342. package/dist/utils/mod-attrs.d.ts +0 -6
  343. package/dist/utils/mod-attrs.js +0 -20
  344. package/dist/utils/mod-attrs.js.map +0 -1
  345. package/dist/utils/process-tokens.d.ts +0 -17
  346. package/dist/utils/process-tokens.js +0 -83
  347. package/dist/utils/process-tokens.js.map +0 -1
  348. package/dist/utils/resolve-recipes.d.ts +0 -17
  349. package/dist/utils/resolve-recipes.js +0 -146
  350. package/dist/utils/resolve-recipes.js.map +0 -1
  351. package/dist/utils/selector-transform.js +0 -32
  352. package/dist/utils/selector-transform.js.map +0 -1
  353. package/dist/utils/string.js +0 -8
  354. package/dist/utils/string.js.map +0 -1
  355. package/dist/utils/styles.d.ts +0 -99
  356. package/dist/utils/styles.js +0 -220
  357. package/dist/utils/styles.js.map +0 -1
  358. package/dist/utils/typography.d.ts +0 -47
  359. package/dist/utils/typography.js +0 -51
  360. package/dist/utils/typography.js.map +0 -1
  361. package/dist/utils/warnings.d.ts +0 -16
  362. package/dist/utils/warnings.js +0 -16
  363. package/dist/utils/warnings.js.map +0 -1
  364. package/dist/zero/css-writer.d.ts +0 -45
  365. package/dist/zero/css-writer.js +0 -73
  366. package/dist/zero/css-writer.js.map +0 -1
  367. package/dist/zero/extractor.d.ts +0 -24
  368. package/dist/zero/extractor.js.map +0 -1
  369. package/docs/PIPELINE.md +0 -519
  370. /package/dist/{chunks/cacheKey.d.ts → ssr/astro-client.d.ts} +0 -0
@@ -1,406 +0,0 @@
1
- //#region src/pipeline/conditions.ts
2
- /**
3
- * Create a TRUE condition (matches everything)
4
- */
5
- function trueCondition() {
6
- return { kind: "true" };
7
- }
8
- /**
9
- * Create a FALSE condition (matches nothing)
10
- */
11
- function falseCondition() {
12
- return { kind: "false" };
13
- }
14
- /**
15
- * Create an AND compound condition
16
- */
17
- function and(...children) {
18
- const filtered = [];
19
- for (const child of children) {
20
- if (child.kind === "false") return falseCondition();
21
- if (child.kind === "true") continue;
22
- if (child.kind === "compound" && child.operator === "AND") filtered.push(...child.children);
23
- else filtered.push(child);
24
- }
25
- if (filtered.length === 0) return trueCondition();
26
- if (filtered.length === 1) return filtered[0];
27
- return {
28
- kind: "compound",
29
- operator: "AND",
30
- children: filtered
31
- };
32
- }
33
- /**
34
- * Create an OR compound condition
35
- */
36
- function or(...children) {
37
- const filtered = [];
38
- for (const child of children) {
39
- if (child.kind === "true") return trueCondition();
40
- if (child.kind === "false") continue;
41
- if (child.kind === "compound" && child.operator === "OR") filtered.push(...child.children);
42
- else filtered.push(child);
43
- }
44
- if (filtered.length === 0) return falseCondition();
45
- if (filtered.length === 1) return filtered[0];
46
- return {
47
- kind: "compound",
48
- operator: "OR",
49
- children: filtered
50
- };
51
- }
52
- /**
53
- * Negate a condition
54
- */
55
- function not(node) {
56
- if (node.kind === "true") return falseCondition();
57
- if (node.kind === "false") return trueCondition();
58
- if (node.kind === "state") return {
59
- ...node,
60
- negated: !node.negated,
61
- uniqueId: node.negated ? node.uniqueId.replace(/^!/, "") : `!${node.uniqueId}`
62
- };
63
- if (node.kind === "compound" && node.operator === "AND") return or(...node.children.map((c) => not(c)));
64
- if (node.kind === "compound" && node.operator === "OR") return and(...node.children.map((c) => not(c)));
65
- return node;
66
- }
67
- /**
68
- * Check if a condition is a compound condition
69
- */
70
- function isCompoundCondition(node) {
71
- return node.kind === "compound";
72
- }
73
- /**
74
- * Generate a normalized unique ID for a modifier condition
75
- */
76
- function modifierUniqueId(attribute, value, operator = "=", negated = false) {
77
- const base = value ? `mod:${attribute}${operator}${value}` : `mod:${attribute}`;
78
- return negated ? `!${base}` : base;
79
- }
80
- /**
81
- * Generate a normalized unique ID for a pseudo condition
82
- */
83
- function pseudoUniqueId(pseudo, negated = false) {
84
- const base = `pseudo:${pseudo}`;
85
- return negated ? `!${base}` : base;
86
- }
87
- /**
88
- * Generate a normalized unique ID for a media condition
89
- */
90
- function mediaUniqueId(subtype, props, negated = false) {
91
- let base;
92
- if (subtype === "dimension") {
93
- const parts = [
94
- "media",
95
- "dim",
96
- props.dimension
97
- ];
98
- if (props.lowerBound) {
99
- parts.push(props.lowerBound.inclusive ? ">=" : ">");
100
- parts.push(props.lowerBound.value);
101
- }
102
- if (props.upperBound) {
103
- parts.push(props.upperBound.inclusive ? "<=" : "<");
104
- parts.push(props.upperBound.value);
105
- }
106
- base = parts.join(":");
107
- } else if (subtype === "feature") base = props.featureValue ? `media:feat:${props.feature}:${props.featureValue}` : `media:feat:${props.feature}`;
108
- else base = `media:type:${props.mediaType}`;
109
- return negated ? `!${base}` : base;
110
- }
111
- /**
112
- * Generate a normalized unique ID for a container condition
113
- */
114
- function containerUniqueId(subtype, props, negated = false) {
115
- let base;
116
- const name = props.containerName || "_";
117
- if (subtype === "dimension") {
118
- const parts = [
119
- "container",
120
- "dim",
121
- name,
122
- props.dimension
123
- ];
124
- if (props.lowerBound) {
125
- parts.push(props.lowerBound.inclusive ? ">=" : ">");
126
- parts.push(props.lowerBound.value);
127
- }
128
- if (props.upperBound) {
129
- parts.push(props.upperBound.inclusive ? "<=" : "<");
130
- parts.push(props.upperBound.value);
131
- }
132
- base = parts.join(":");
133
- } else if (subtype === "raw") base = `container:raw:${name}:${props.rawCondition}`;
134
- else base = props.propertyValue ? `container:style:${name}:--${props.property}:${props.propertyValue}` : `container:style:${name}:--${props.property}`;
135
- return negated ? `!${base}` : base;
136
- }
137
- /**
138
- * Generate a normalized unique ID for a root condition
139
- */
140
- function rootUniqueId(innerUniqueId, negated = false) {
141
- const base = `root:${innerUniqueId}`;
142
- return negated ? `!${base}` : base;
143
- }
144
- /**
145
- * Generate a normalized unique ID for a parent condition
146
- */
147
- function parentUniqueId(innerUniqueId, direct, negated = false) {
148
- const base = `parent:${direct ? ">" : ""}${innerUniqueId}`;
149
- return negated ? `!${base}` : base;
150
- }
151
- /**
152
- * Generate a normalized unique ID for an own condition
153
- */
154
- function ownUniqueId(innerUniqueId, negated = false) {
155
- const base = `own:${innerUniqueId}`;
156
- return negated ? `!${base}` : base;
157
- }
158
- /**
159
- * Generate a normalized unique ID for a starting condition
160
- */
161
- function startingUniqueId(negated = false) {
162
- return negated ? "!starting" : "starting";
163
- }
164
- /**
165
- * Generate a normalized unique ID for a supports condition
166
- */
167
- function supportsUniqueId(subtype, condition, negated = false) {
168
- const base = `supports:${subtype}:${condition}`;
169
- return negated ? `!${base}` : base;
170
- }
171
- /**
172
- * Create a modifier condition
173
- */
174
- function createModifierCondition(attribute, value, operator = "=", negated = false, raw) {
175
- return {
176
- kind: "state",
177
- type: "modifier",
178
- negated,
179
- raw: raw || (value ? `${attribute}${operator}${value}` : attribute),
180
- uniqueId: modifierUniqueId(attribute, value, operator, negated),
181
- attribute,
182
- value,
183
- operator: value ? operator : void 0
184
- };
185
- }
186
- /**
187
- * Create a pseudo condition
188
- */
189
- function createPseudoCondition(pseudo, negated = false, raw) {
190
- return {
191
- kind: "state",
192
- type: "pseudo",
193
- negated,
194
- raw: raw || pseudo,
195
- uniqueId: pseudoUniqueId(pseudo, negated),
196
- pseudo
197
- };
198
- }
199
- /**
200
- * Create a media dimension condition
201
- */
202
- function createMediaDimensionCondition(dimension, lowerBound, upperBound, negated = false, raw) {
203
- return {
204
- kind: "state",
205
- type: "media",
206
- subtype: "dimension",
207
- negated,
208
- raw: raw || `@media(${dimension})`,
209
- uniqueId: mediaUniqueId("dimension", {
210
- dimension,
211
- lowerBound,
212
- upperBound
213
- }, negated),
214
- dimension,
215
- lowerBound,
216
- upperBound
217
- };
218
- }
219
- /**
220
- * Create a media feature condition
221
- */
222
- function createMediaFeatureCondition(feature, featureValue, negated = false, raw) {
223
- return {
224
- kind: "state",
225
- type: "media",
226
- subtype: "feature",
227
- negated,
228
- raw: raw || `@media(${feature}${featureValue ? `: ${featureValue}` : ""})`,
229
- uniqueId: mediaUniqueId("feature", {
230
- feature,
231
- featureValue
232
- }, negated),
233
- feature,
234
- featureValue
235
- };
236
- }
237
- /**
238
- * Create a media type condition
239
- */
240
- function createMediaTypeCondition(mediaType, negated = false, raw) {
241
- return {
242
- kind: "state",
243
- type: "media",
244
- subtype: "type",
245
- negated,
246
- raw: raw || `@media:${mediaType}`,
247
- uniqueId: mediaUniqueId("type", { mediaType }, negated),
248
- mediaType
249
- };
250
- }
251
- /**
252
- * Create a container dimension condition
253
- */
254
- function createContainerDimensionCondition(dimension, lowerBound, upperBound, containerName, negated = false, raw) {
255
- return {
256
- kind: "state",
257
- type: "container",
258
- subtype: "dimension",
259
- negated,
260
- raw: raw || `@(${containerName ? containerName + ", " : ""}${dimension})`,
261
- uniqueId: containerUniqueId("dimension", {
262
- containerName,
263
- dimension,
264
- lowerBound,
265
- upperBound
266
- }, negated),
267
- containerName,
268
- dimension,
269
- lowerBound,
270
- upperBound
271
- };
272
- }
273
- /**
274
- * Create a container style condition
275
- */
276
- function createContainerStyleCondition(property, propertyValue, containerName, negated = false, raw) {
277
- return {
278
- kind: "state",
279
- type: "container",
280
- subtype: "style",
281
- negated,
282
- raw: raw || `@(${containerName ? containerName + ", " : ""}$${property}${propertyValue ? "=" + propertyValue : ""})`,
283
- uniqueId: containerUniqueId("style", {
284
- containerName,
285
- property,
286
- propertyValue
287
- }, negated),
288
- containerName,
289
- property,
290
- propertyValue
291
- };
292
- }
293
- /**
294
- * Create a container raw function condition (e.g., scroll-state(), style(), etc.)
295
- * The condition string is passed through to CSS verbatim.
296
- */
297
- function createContainerRawCondition(rawCondition, containerName, negated = false, raw) {
298
- return {
299
- kind: "state",
300
- type: "container",
301
- subtype: "raw",
302
- negated,
303
- raw: raw || `@(${containerName ? containerName + ", " : ""}${rawCondition})`,
304
- uniqueId: containerUniqueId("raw", {
305
- containerName,
306
- rawCondition
307
- }, negated),
308
- containerName,
309
- rawCondition
310
- };
311
- }
312
- /**
313
- * Create a root condition
314
- */
315
- function createRootCondition(innerCondition, negated = false, raw) {
316
- const innerUniqueId = getConditionUniqueId(innerCondition);
317
- return {
318
- kind: "state",
319
- type: "root",
320
- negated,
321
- raw: raw || `@root(${innerUniqueId})`,
322
- uniqueId: rootUniqueId(innerUniqueId, negated),
323
- innerCondition
324
- };
325
- }
326
- /**
327
- * Create a parent condition
328
- */
329
- function createParentCondition(innerCondition, direct, negated = false, raw) {
330
- const innerUniqueId = getConditionUniqueId(innerCondition);
331
- return {
332
- kind: "state",
333
- type: "parent",
334
- negated,
335
- raw: raw || `@parent(${innerUniqueId})`,
336
- uniqueId: parentUniqueId(innerUniqueId, direct, negated),
337
- innerCondition,
338
- direct
339
- };
340
- }
341
- /**
342
- * Create an own condition
343
- */
344
- function createOwnCondition(innerCondition, negated = false, raw) {
345
- const innerUniqueId = getConditionUniqueId(innerCondition);
346
- return {
347
- kind: "state",
348
- type: "own",
349
- negated,
350
- raw: raw || `@own(...)`,
351
- uniqueId: ownUniqueId(innerUniqueId, negated),
352
- innerCondition
353
- };
354
- }
355
- /**
356
- * Create a starting condition
357
- */
358
- function createStartingCondition(negated = false, raw) {
359
- return {
360
- kind: "state",
361
- type: "starting",
362
- negated,
363
- raw: raw || "@starting",
364
- uniqueId: startingUniqueId(negated)
365
- };
366
- }
367
- /**
368
- * Create a supports condition
369
- *
370
- * @param subtype 'feature' for @supports(display: grid), 'selector' for @supports($, :has(*))
371
- * @param condition The condition string (e.g., "display: grid" or ":has(*)")
372
- */
373
- function createSupportsCondition(subtype, condition, negated = false, raw) {
374
- return {
375
- kind: "state",
376
- type: "supports",
377
- subtype,
378
- negated,
379
- raw: raw || `@supports(${condition})`,
380
- uniqueId: supportsUniqueId(subtype, condition, negated),
381
- condition
382
- };
383
- }
384
- const uniqueIdCache = /* @__PURE__ */ new WeakMap();
385
- /**
386
- * Get the unique ID for any condition node.
387
- * Results are memoized via WeakMap since condition nodes are immutable.
388
- */
389
- function getConditionUniqueId(node) {
390
- const cached = uniqueIdCache.get(node);
391
- if (cached !== void 0) return cached;
392
- let id;
393
- if (node.kind === "true") id = "TRUE";
394
- else if (node.kind === "false") id = "FALSE";
395
- else if (node.kind === "state") id = node.uniqueId;
396
- else if (node.kind === "compound") {
397
- const childIds = node.children.map(getConditionUniqueId).sort();
398
- id = `${node.operator}(${childIds.join(",")})`;
399
- } else id = "UNKNOWN";
400
- uniqueIdCache.set(node, id);
401
- return id;
402
- }
403
- //#endregion
404
- export { and, createContainerDimensionCondition, createContainerRawCondition, createContainerStyleCondition, createMediaDimensionCondition, createMediaFeatureCondition, createMediaTypeCondition, createModifierCondition, createOwnCondition, createParentCondition, createPseudoCondition, createRootCondition, createStartingCondition, createSupportsCondition, falseCondition, getConditionUniqueId, isCompoundCondition, not, or, trueCondition };
405
-
406
- //# sourceMappingURL=conditions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"conditions.js","names":[],"sources":["../../src/pipeline/conditions.ts"],"sourcesContent":["/**\n * ConditionNode Types and Helpers\n *\n * Core data structures for representing style conditions as an abstract syntax tree.\n * Used throughout the pipeline for parsing, simplification, and CSS generation.\n */\n\n// ============================================================================\n// Core ConditionNode Types\n// ============================================================================\n\n/**\n * Base interface for all state conditions (leaf nodes)\n */\ninterface BaseStateCondition {\n kind: 'state';\n negated: boolean;\n raw: string; // Original string for debugging/caching\n uniqueId: string; // Normalized ID for comparison (built from props)\n}\n\n/**\n * Modifier condition: [data-attr] or [data-attr=\"value\"]\n */\nexport interface ModifierCondition extends BaseStateCondition {\n type: 'modifier';\n attribute: string; // e.g., 'data-theme', 'data-size'\n value?: string; // e.g., 'danger', 'large' (undefined = boolean attr)\n operator?: '=' | '^=' | '$=' | '*='; // Attribute match operator\n}\n\n/**\n * Pseudo-class condition: :hover, :focus-visible\n */\nexport interface PseudoCondition extends BaseStateCondition {\n type: 'pseudo';\n pseudo: string; // e.g., ':hover', ':focus-visible', ':nth-child(2n)'\n}\n\n/**\n * Numeric bound for dimension queries\n */\nexport interface NumericBound {\n value: string; // e.g., '768px', 'calc(var(--gap) * 40)'\n valueNumeric: number | null; // Parsed numeric value for comparison\n inclusive: boolean; // true for >=/<= , false for >/<\n}\n\n/**\n * Media query condition\n */\nexport interface MediaCondition extends BaseStateCondition {\n type: 'media';\n subtype: 'dimension' | 'feature' | 'type';\n\n // For dimension queries: @media(w < 768px), @media(600px <= w < 1200px)\n dimension?: 'width' | 'height' | 'inline-size' | 'block-size';\n lowerBound?: NumericBound; // >= or >\n upperBound?: NumericBound; // <= or <\n\n // For feature queries: @media(prefers-contrast: high)\n feature?: string; // e.g., 'prefers-contrast', 'prefers-color-scheme'\n featureValue?: string; // e.g., 'high', 'dark' (undefined = boolean feature)\n\n // For type queries: @media:print\n mediaType?: 'print' | 'screen' | 'all' | 'speech';\n}\n\n/**\n * Container query condition\n */\nexport interface ContainerCondition extends BaseStateCondition {\n type: 'container';\n subtype: 'dimension' | 'style' | 'raw';\n containerName?: string; // e.g., 'layout', 'sidebar' (undefined = nearest)\n\n // For dimension queries: @(w < 600px), @(layout, w < 600px)\n dimension?: 'width' | 'height' | 'inline-size' | 'block-size';\n lowerBound?: NumericBound;\n upperBound?: NumericBound;\n\n // For style queries: @(layout, $variant=danger), @($theme)\n property?: string; // CSS custom property name (without --)\n propertyValue?: string; // e.g., 'danger' (undefined = existence check)\n\n // For raw function queries: @(scroll-state(stuck: top)), @(style(display: flex))\n rawCondition?: string; // Verbatim CSS condition string\n}\n\n/**\n * Root state condition: @root(theme=dark)\n */\nexport interface RootCondition extends BaseStateCondition {\n type: 'root';\n innerCondition: ConditionNode;\n}\n\n/**\n * Parent state condition: @parent(hovered), @parent(theme=dark, >)\n */\nexport interface ParentCondition extends BaseStateCondition {\n type: 'parent';\n innerCondition: ConditionNode;\n direct: boolean; // true for @parent(..., >) — direct parent only\n}\n\n/**\n * Own state condition: @own(hovered)\n */\nexport interface OwnCondition extends BaseStateCondition {\n type: 'own';\n innerCondition: ConditionNode; // The parsed inner condition\n}\n\n/**\n * Starting style condition: @starting\n */\nexport interface StartingCondition extends BaseStateCondition {\n type: 'starting';\n}\n\n/**\n * Supports query condition: @supports(display: grid), @supports($, :has(*))\n */\nexport interface SupportsCondition extends BaseStateCondition {\n type: 'supports';\n subtype: 'feature' | 'selector';\n // The raw condition string (e.g., \"display: grid\" or \":has(*)\")\n condition: string;\n}\n\n/**\n * Union of all state condition types\n */\nexport type StateCondition =\n | ModifierCondition\n | PseudoCondition\n | MediaCondition\n | ContainerCondition\n | RootCondition\n | ParentCondition\n | OwnCondition\n | StartingCondition\n | SupportsCondition;\n\n/**\n * Compound node: combines conditions with AND/OR\n */\nexport interface CompoundCondition {\n kind: 'compound';\n operator: 'AND' | 'OR';\n children: ConditionNode[];\n}\n\n/**\n * True condition (matches everything)\n */\nexport interface TrueCondition {\n kind: 'true';\n}\n\n/**\n * False condition (matches nothing - skip this rule)\n */\nexport interface FalseCondition {\n kind: 'false';\n}\n\n/**\n * Union of all condition node types\n */\nexport type ConditionNode =\n | StateCondition\n | CompoundCondition\n | TrueCondition\n | FalseCondition;\n\n// ============================================================================\n// Constructor Functions\n// ============================================================================\n\n/**\n * Create a TRUE condition (matches everything)\n */\nexport function trueCondition(): TrueCondition {\n return { kind: 'true' };\n}\n\n/**\n * Create a FALSE condition (matches nothing)\n */\nexport function falseCondition(): FalseCondition {\n return { kind: 'false' };\n}\n\n/**\n * Create an AND compound condition\n */\nexport function and(...children: ConditionNode[]): ConditionNode {\n const filtered: ConditionNode[] = [];\n\n for (const child of children) {\n // Short-circuit on FALSE\n if (child.kind === 'false') {\n return falseCondition();\n }\n // Skip TRUE (identity for AND)\n if (child.kind === 'true') {\n continue;\n }\n // Flatten nested ANDs\n if (child.kind === 'compound' && child.operator === 'AND') {\n filtered.push(...child.children);\n } else {\n filtered.push(child);\n }\n }\n\n if (filtered.length === 0) {\n return trueCondition();\n }\n if (filtered.length === 1) {\n return filtered[0];\n }\n\n return {\n kind: 'compound',\n operator: 'AND',\n children: filtered,\n };\n}\n\n/**\n * Create an OR compound condition\n */\nexport function or(...children: ConditionNode[]): ConditionNode {\n const filtered: ConditionNode[] = [];\n\n for (const child of children) {\n // Short-circuit on TRUE\n if (child.kind === 'true') {\n return trueCondition();\n }\n // Skip FALSE (identity for OR)\n if (child.kind === 'false') {\n continue;\n }\n // Flatten nested ORs\n if (child.kind === 'compound' && child.operator === 'OR') {\n filtered.push(...child.children);\n } else {\n filtered.push(child);\n }\n }\n\n if (filtered.length === 0) {\n return falseCondition();\n }\n if (filtered.length === 1) {\n return filtered[0];\n }\n\n return {\n kind: 'compound',\n operator: 'OR',\n children: filtered,\n };\n}\n\n/**\n * Negate a condition\n */\nexport function not(node: ConditionNode): ConditionNode {\n // NOT(TRUE) = FALSE\n if (node.kind === 'true') {\n return falseCondition();\n }\n\n // NOT(FALSE) = TRUE\n if (node.kind === 'false') {\n return trueCondition();\n }\n\n // NOT(state) = toggle negated flag\n if (node.kind === 'state') {\n return {\n ...node,\n negated: !node.negated,\n uniqueId: node.negated\n ? node.uniqueId.replace(/^!/, '')\n : `!${node.uniqueId}`,\n };\n }\n\n // NOT(AND(a, b, ...)) = OR(NOT(a), NOT(b), ...) - De Morgan's law\n if (node.kind === 'compound' && node.operator === 'AND') {\n return or(...node.children.map((c) => not(c)));\n }\n\n // NOT(OR(a, b, ...)) = AND(NOT(a), NOT(b), ...) - De Morgan's law\n if (node.kind === 'compound' && node.operator === 'OR') {\n return and(...node.children.map((c) => not(c)));\n }\n\n // Fallback - should not reach here\n return node;\n}\n\n// ============================================================================\n// Condition Type Checking\n// ============================================================================\n\n/**\n * Check if a condition is a compound condition\n */\nexport function isCompoundCondition(\n node: ConditionNode,\n): node is CompoundCondition {\n return node.kind === 'compound';\n}\n\n// ============================================================================\n// UniqueId Generation\n// ============================================================================\n\n/**\n * Generate a normalized unique ID for a modifier condition\n */\nexport function modifierUniqueId(\n attribute: string,\n value?: string,\n operator = '=',\n negated = false,\n): string {\n const base = value\n ? `mod:${attribute}${operator}${value}`\n : `mod:${attribute}`;\n return negated ? `!${base}` : base;\n}\n\n/**\n * Generate a normalized unique ID for a pseudo condition\n */\nexport function pseudoUniqueId(pseudo: string, negated = false): string {\n const base = `pseudo:${pseudo}`;\n return negated ? `!${base}` : base;\n}\n\n/**\n * Generate a normalized unique ID for a media condition\n */\nexport function mediaUniqueId(\n subtype: 'dimension' | 'feature' | 'type',\n props: {\n dimension?: string;\n lowerBound?: NumericBound;\n upperBound?: NumericBound;\n feature?: string;\n featureValue?: string;\n mediaType?: string;\n },\n negated = false,\n): string {\n let base: string;\n\n if (subtype === 'dimension') {\n const parts = ['media', 'dim', props.dimension];\n if (props.lowerBound) {\n parts.push(props.lowerBound.inclusive ? '>=' : '>');\n parts.push(props.lowerBound.value);\n }\n if (props.upperBound) {\n parts.push(props.upperBound.inclusive ? '<=' : '<');\n parts.push(props.upperBound.value);\n }\n base = parts.join(':');\n } else if (subtype === 'feature') {\n base = props.featureValue\n ? `media:feat:${props.feature}:${props.featureValue}`\n : `media:feat:${props.feature}`;\n } else {\n base = `media:type:${props.mediaType}`;\n }\n\n return negated ? `!${base}` : base;\n}\n\n/**\n * Generate a normalized unique ID for a container condition\n */\nexport function containerUniqueId(\n subtype: 'dimension' | 'style' | 'raw',\n props: {\n containerName?: string;\n dimension?: string;\n lowerBound?: NumericBound;\n upperBound?: NumericBound;\n property?: string;\n propertyValue?: string;\n rawCondition?: string;\n },\n negated = false,\n): string {\n let base: string;\n const name = props.containerName || '_';\n\n if (subtype === 'dimension') {\n const parts = ['container', 'dim', name, props.dimension];\n if (props.lowerBound) {\n parts.push(props.lowerBound.inclusive ? '>=' : '>');\n parts.push(props.lowerBound.value);\n }\n if (props.upperBound) {\n parts.push(props.upperBound.inclusive ? '<=' : '<');\n parts.push(props.upperBound.value);\n }\n base = parts.join(':');\n } else if (subtype === 'raw') {\n base = `container:raw:${name}:${props.rawCondition}`;\n } else {\n base = props.propertyValue\n ? `container:style:${name}:--${props.property}:${props.propertyValue}`\n : `container:style:${name}:--${props.property}`;\n }\n\n return negated ? `!${base}` : base;\n}\n\n/**\n * Generate a normalized unique ID for a root condition\n */\nexport function rootUniqueId(innerUniqueId: string, negated = false): string {\n const base = `root:${innerUniqueId}`;\n return negated ? `!${base}` : base;\n}\n\n/**\n * Generate a normalized unique ID for a parent condition\n */\nexport function parentUniqueId(\n innerUniqueId: string,\n direct: boolean,\n negated = false,\n): string {\n const base = `parent:${direct ? '>' : ''}${innerUniqueId}`;\n return negated ? `!${base}` : base;\n}\n\n/**\n * Generate a normalized unique ID for an own condition\n */\nexport function ownUniqueId(innerUniqueId: string, negated = false): string {\n const base = `own:${innerUniqueId}`;\n return negated ? `!${base}` : base;\n}\n\n/**\n * Generate a normalized unique ID for a starting condition\n */\nexport function startingUniqueId(negated = false): string {\n return negated ? '!starting' : 'starting';\n}\n\n/**\n * Generate a normalized unique ID for a supports condition\n */\nexport function supportsUniqueId(\n subtype: 'feature' | 'selector',\n condition: string,\n negated = false,\n): string {\n const base = `supports:${subtype}:${condition}`;\n return negated ? `!${base}` : base;\n}\n\n// ============================================================================\n// Condition Creation Helpers\n// ============================================================================\n\n/**\n * Create a modifier condition\n */\nexport function createModifierCondition(\n attribute: string,\n value?: string,\n operator: '=' | '^=' | '$=' | '*=' = '=',\n negated = false,\n raw?: string,\n): ModifierCondition {\n return {\n kind: 'state',\n type: 'modifier',\n negated,\n raw: raw || (value ? `${attribute}${operator}${value}` : attribute),\n uniqueId: modifierUniqueId(attribute, value, operator, negated),\n attribute,\n value,\n operator: value ? operator : undefined,\n };\n}\n\n/**\n * Create a pseudo condition\n */\nexport function createPseudoCondition(\n pseudo: string,\n negated = false,\n raw?: string,\n): PseudoCondition {\n return {\n kind: 'state',\n type: 'pseudo',\n negated,\n raw: raw || pseudo,\n uniqueId: pseudoUniqueId(pseudo, negated),\n pseudo,\n };\n}\n\n/**\n * Create a media dimension condition\n */\nexport function createMediaDimensionCondition(\n dimension: 'width' | 'height' | 'inline-size' | 'block-size',\n lowerBound?: NumericBound,\n upperBound?: NumericBound,\n negated = false,\n raw?: string,\n): MediaCondition {\n return {\n kind: 'state',\n type: 'media',\n subtype: 'dimension',\n negated,\n raw: raw || `@media(${dimension})`,\n uniqueId: mediaUniqueId(\n 'dimension',\n { dimension, lowerBound, upperBound },\n negated,\n ),\n dimension,\n lowerBound,\n upperBound,\n };\n}\n\n/**\n * Create a media feature condition\n */\nexport function createMediaFeatureCondition(\n feature: string,\n featureValue?: string,\n negated = false,\n raw?: string,\n): MediaCondition {\n return {\n kind: 'state',\n type: 'media',\n subtype: 'feature',\n negated,\n raw: raw || `@media(${feature}${featureValue ? `: ${featureValue}` : ''})`,\n uniqueId: mediaUniqueId('feature', { feature, featureValue }, negated),\n feature,\n featureValue,\n };\n}\n\n/**\n * Create a media type condition\n */\nexport function createMediaTypeCondition(\n mediaType: 'print' | 'screen' | 'all' | 'speech',\n negated = false,\n raw?: string,\n): MediaCondition {\n return {\n kind: 'state',\n type: 'media',\n subtype: 'type',\n negated,\n raw: raw || `@media:${mediaType}`,\n uniqueId: mediaUniqueId('type', { mediaType }, negated),\n mediaType,\n };\n}\n\n/**\n * Create a container dimension condition\n */\nexport function createContainerDimensionCondition(\n dimension: 'width' | 'height' | 'inline-size' | 'block-size',\n lowerBound?: NumericBound,\n upperBound?: NumericBound,\n containerName?: string,\n negated = false,\n raw?: string,\n): ContainerCondition {\n return {\n kind: 'state',\n type: 'container',\n subtype: 'dimension',\n negated,\n raw: raw || `@(${containerName ? containerName + ', ' : ''}${dimension})`,\n uniqueId: containerUniqueId(\n 'dimension',\n { containerName, dimension, lowerBound, upperBound },\n negated,\n ),\n containerName,\n dimension,\n lowerBound,\n upperBound,\n };\n}\n\n/**\n * Create a container style condition\n */\nexport function createContainerStyleCondition(\n property: string,\n propertyValue?: string,\n containerName?: string,\n negated = false,\n raw?: string,\n): ContainerCondition {\n return {\n kind: 'state',\n type: 'container',\n subtype: 'style',\n negated,\n raw:\n raw ||\n `@(${containerName ? containerName + ', ' : ''}$${property}${propertyValue ? '=' + propertyValue : ''})`,\n uniqueId: containerUniqueId(\n 'style',\n { containerName, property, propertyValue },\n negated,\n ),\n containerName,\n property,\n propertyValue,\n };\n}\n\n/**\n * Create a container raw function condition (e.g., scroll-state(), style(), etc.)\n * The condition string is passed through to CSS verbatim.\n */\nexport function createContainerRawCondition(\n rawCondition: string,\n containerName?: string,\n negated = false,\n raw?: string,\n): ContainerCondition {\n return {\n kind: 'state',\n type: 'container',\n subtype: 'raw',\n negated,\n raw:\n raw || `@(${containerName ? containerName + ', ' : ''}${rawCondition})`,\n uniqueId: containerUniqueId(\n 'raw',\n { containerName, rawCondition },\n negated,\n ),\n containerName,\n rawCondition,\n };\n}\n\n/**\n * Create a root condition\n */\nexport function createRootCondition(\n innerCondition: ConditionNode,\n negated = false,\n raw?: string,\n): RootCondition {\n const innerUniqueId = getConditionUniqueId(innerCondition);\n return {\n kind: 'state',\n type: 'root',\n negated,\n raw: raw || `@root(${innerUniqueId})`,\n uniqueId: rootUniqueId(innerUniqueId, negated),\n innerCondition,\n };\n}\n\n/**\n * Create a parent condition\n */\nexport function createParentCondition(\n innerCondition: ConditionNode,\n direct: boolean,\n negated = false,\n raw?: string,\n): ParentCondition {\n const innerUniqueId = getConditionUniqueId(innerCondition);\n return {\n kind: 'state',\n type: 'parent',\n negated,\n raw: raw || `@parent(${innerUniqueId})`,\n uniqueId: parentUniqueId(innerUniqueId, direct, negated),\n innerCondition,\n direct,\n };\n}\n\n/**\n * Create an own condition\n */\nexport function createOwnCondition(\n innerCondition: ConditionNode,\n negated = false,\n raw?: string,\n): OwnCondition {\n const innerUniqueId = getConditionUniqueId(innerCondition);\n return {\n kind: 'state',\n type: 'own',\n negated,\n raw: raw || `@own(...)`,\n uniqueId: ownUniqueId(innerUniqueId, negated),\n innerCondition,\n };\n}\n\n/**\n * Create a starting condition\n */\nexport function createStartingCondition(\n negated = false,\n raw?: string,\n): StartingCondition {\n return {\n kind: 'state',\n type: 'starting',\n negated,\n raw: raw || '@starting',\n uniqueId: startingUniqueId(negated),\n };\n}\n\n/**\n * Create a supports condition\n *\n * @param subtype 'feature' for @supports(display: grid), 'selector' for @supports($, :has(*))\n * @param condition The condition string (e.g., \"display: grid\" or \":has(*)\")\n */\nexport function createSupportsCondition(\n subtype: 'feature' | 'selector',\n condition: string,\n negated = false,\n raw?: string,\n): SupportsCondition {\n return {\n kind: 'state',\n type: 'supports',\n subtype,\n negated,\n raw: raw || `@supports(${condition})`,\n uniqueId: supportsUniqueId(subtype, condition, negated),\n condition,\n };\n}\n\n// ============================================================================\n// Utility Functions\n// ============================================================================\n\nconst uniqueIdCache = new WeakMap<ConditionNode, string>();\n\n/**\n * Get the unique ID for any condition node.\n * Results are memoized via WeakMap since condition nodes are immutable.\n */\nexport function getConditionUniqueId(node: ConditionNode): string {\n const cached = uniqueIdCache.get(node);\n if (cached !== undefined) return cached;\n\n let id: string;\n if (node.kind === 'true') {\n id = 'TRUE';\n } else if (node.kind === 'false') {\n id = 'FALSE';\n } else if (node.kind === 'state') {\n id = node.uniqueId;\n } else if (node.kind === 'compound') {\n const childIds = node.children.map(getConditionUniqueId).sort();\n id = `${node.operator}(${childIds.join(',')})`;\n } else {\n id = 'UNKNOWN';\n }\n\n uniqueIdCache.set(node, id);\n return id;\n}\n"],"mappings":";;;;AAwLA,SAAgB,gBAA+B;AAC7C,QAAO,EAAE,MAAM,QAAQ;;;;;AAMzB,SAAgB,iBAAiC;AAC/C,Q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S,QACvB,MAAK,KAAK;UACD,KAAK,SAAS,YAAY;EACnC,MAAM,WAAW,KAAK,SAAS,IAAI,qBAAqB,CAAC,MAAM;AAC/D,OAAK,GAAG,KAAK,SAAS,GAAG,SAAS,KAAK,IAAI,CAAC;OAE5C,MAAK;AAGP,eAAc,IAAI,MAAM,GAAG;AAC3B,QAAO"}
@@ -1,230 +0,0 @@
1
- import { and, isCompoundCondition, not, trueCondition } from "./conditions.js";
2
- import { simplifyCondition } from "./simplify.js";
3
- //#region src/pipeline/exclusive.ts
4
- /**
5
- * Build exclusive conditions for a list of parsed style entries.
6
- *
7
- * The entries should be ordered by priority (highest priority first).
8
- *
9
- * For each entry, we compute:
10
- * exclusiveCondition = condition & !prior[0] & !prior[1] & ...
11
- *
12
- * This ensures exactly one condition matches at any time.
13
- *
14
- * Example:
15
- * Input (ordered highest to lowest priority):
16
- * A: value1 (priority 2)
17
- * B: value2 (priority 1)
18
- * C: value3 (priority 0)
19
- *
20
- * Output:
21
- * A: A
22
- * B: B & !A
23
- * C: C & !A & !B
24
- *
25
- * @param entries Parsed style entries ordered by priority (highest first)
26
- * @returns Entries with exclusive conditions, filtered to remove impossible ones
27
- */
28
- function buildExclusiveConditions(entries) {
29
- const result = [];
30
- const priorConditions = [];
31
- for (const entry of entries) {
32
- let exclusive = entry.condition;
33
- for (const prior of priorConditions) if (prior.kind !== "true") exclusive = and(exclusive, not(prior));
34
- const simplified = simplifyCondition(exclusive);
35
- if (simplified.kind === "false") continue;
36
- result.push({
37
- ...entry,
38
- exclusiveCondition: simplified
39
- });
40
- if (entry.condition.kind !== "true") priorConditions.push(entry.condition);
41
- }
42
- return result;
43
- }
44
- /**
45
- * Parse style entries from a value mapping object.
46
- *
47
- * @param styleKey The style key (e.g., 'padding')
48
- * @param valueMap The value mapping { '': '2x', 'compact': '1x', '@media(w < 768px)': '0.5x' }
49
- * @param parseCondition Function to parse state keys into conditions
50
- * @returns Parsed entries ordered by priority (highest first)
51
- */
52
- function parseStyleEntries(styleKey, valueMap, parseCondition) {
53
- const entries = [];
54
- Object.keys(valueMap).forEach((stateKey, index) => {
55
- const value = valueMap[stateKey];
56
- const condition = stateKey === "" ? trueCondition() : parseCondition(stateKey);
57
- entries.push({
58
- styleKey,
59
- stateKey,
60
- value,
61
- condition,
62
- priority: index
63
- });
64
- });
65
- entries.reverse();
66
- return entries;
67
- }
68
- /**
69
- * Check if a value is a style value mapping (object with state keys)
70
- */
71
- function isValueMapping(value) {
72
- return value !== null && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
73
- }
74
- /**
75
- * Expand OR conditions in parsed entries into multiple exclusive entries.
76
- *
77
- * For an entry with condition `A | B | C`, this creates 3 entries:
78
- * - condition: A
79
- * - condition: B & !A
80
- * - condition: C & !A & !B
81
- *
82
- * This ensures OR branches are mutually exclusive BEFORE the main
83
- * exclusive condition building pass.
84
- *
85
- * @param entries Parsed entries (may contain OR conditions)
86
- * @returns Expanded entries with OR branches made exclusive
87
- */
88
- function expandOrConditions(entries) {
89
- const result = [];
90
- for (const entry of entries) {
91
- const expanded = expandSingleEntry(entry);
92
- result.push(...expanded);
93
- }
94
- return result;
95
- }
96
- /**
97
- * Expand a single entry's OR condition into multiple exclusive entries
98
- */
99
- function expandSingleEntry(entry) {
100
- const orBranches = collectOrBranches(entry.condition);
101
- if (orBranches.length <= 1) return [entry];
102
- const result = [];
103
- const priorBranches = [];
104
- for (let i = 0; i < orBranches.length; i++) {
105
- const branch = orBranches[i];
106
- let exclusiveBranch = branch;
107
- for (const prior of priorBranches) exclusiveBranch = and(exclusiveBranch, not(prior));
108
- const simplified = simplifyCondition(exclusiveBranch);
109
- if (simplified.kind === "false") {
110
- priorBranches.push(branch);
111
- continue;
112
- }
113
- result.push({
114
- ...entry,
115
- stateKey: `${entry.stateKey}[${i}]`,
116
- condition: simplified
117
- });
118
- priorBranches.push(branch);
119
- }
120
- return result;
121
- }
122
- /**
123
- * Collect top-level OR branches from a condition.
124
- *
125
- * For `A | B | C`, returns [A, B, C]
126
- * For `A & B`, returns [A & B] (single branch)
127
- * For `A | (B & C)`, returns [A, B & C]
128
- */
129
- function collectOrBranches(condition) {
130
- if (condition.kind === "true" || condition.kind === "false") return [condition];
131
- if (isCompoundCondition(condition) && condition.operator === "OR") {
132
- const branches = [];
133
- for (const child of condition.children) branches.push(...collectOrBranches(child));
134
- return branches;
135
- }
136
- return [condition];
137
- }
138
- /**
139
- * Expand OR conditions in exclusive entries AFTER buildExclusiveConditions.
140
- *
141
- * This handles ORs that arise from De Morgan expansion during negation:
142
- * !(A & B) = !A | !B
143
- *
144
- * These ORs need to be made exclusive to avoid overlapping CSS rules:
145
- * !A | !B → !A | (A & !B)
146
- *
147
- * This is logically equivalent but ensures each branch has proper context.
148
- *
149
- * Example:
150
- * Input: { "": V1, "@supports(...) & :has()": V2 }
151
- * V2's exclusive = @supports & :has
152
- * V1's exclusive = !(@supports & :has) = !@supports | !:has
153
- *
154
- * Without this fix: V1 gets two rules:
155
- * - @supports (not ...) → V1 ✓
156
- * - :not(:has()) → V1 ✗ (missing @supports context!)
157
- *
158
- * With this fix: V1 gets two exclusive rules:
159
- * - @supports (not ...) → V1 ✓
160
- * - @supports (...) { :not(:has()) } → V1 ✓ (proper context!)
161
- */
162
- function expandExclusiveOrs(entries) {
163
- const result = [];
164
- for (const entry of entries) {
165
- const expanded = expandExclusiveConditionOrs(entry);
166
- result.push(...expanded);
167
- }
168
- return result;
169
- }
170
- /**
171
- * Check if a condition involves at-rules (media, container, supports, starting)
172
- */
173
- function hasAtRuleContext(node) {
174
- if (node.kind === "true" || node.kind === "false") return false;
175
- if (node.kind === "state") return node.type === "media" || node.type === "container" || node.type === "supports" || node.type === "starting";
176
- if (node.kind === "compound") return node.children.some(hasAtRuleContext);
177
- return false;
178
- }
179
- /**
180
- * Sort OR branches to prioritize at-rule conditions first.
181
- *
182
- * This is critical for correct CSS generation. For `!A | !B` where A is at-rule
183
- * and B is modifier, we want:
184
- * - Branch 0: !A (at-rule negation - covers "no @supports/media" case)
185
- * - Branch 1: A & !B (modifier negation with at-rule context)
186
- *
187
- * If we process in wrong order (!B first), we'd get:
188
- * - Branch 0: !B (modifier negation WITHOUT at-rule context - WRONG!)
189
- * - Branch 1: B & !A (at-rule negation with modifier - incomplete coverage)
190
- */
191
- function sortOrBranchesForExpansion(branches) {
192
- return [...branches].sort((a, b) => {
193
- const aHasAtRule = hasAtRuleContext(a);
194
- const bHasAtRule = hasAtRuleContext(b);
195
- if (aHasAtRule && !bHasAtRule) return -1;
196
- if (!aHasAtRule && bHasAtRule) return 1;
197
- return 0;
198
- });
199
- }
200
- /**
201
- * Expand ORs in a single entry's exclusive condition
202
- */
203
- function expandExclusiveConditionOrs(entry) {
204
- let orBranches = collectOrBranches(entry.exclusiveCondition);
205
- if (orBranches.length <= 1) return [entry];
206
- orBranches = sortOrBranchesForExpansion(orBranches);
207
- const result = [];
208
- const priorBranches = [];
209
- for (let i = 0; i < orBranches.length; i++) {
210
- const branch = orBranches[i];
211
- let exclusiveBranch = branch;
212
- for (const prior of priorBranches) exclusiveBranch = and(exclusiveBranch, not(prior));
213
- const simplified = simplifyCondition(exclusiveBranch);
214
- if (simplified.kind === "false") {
215
- priorBranches.push(branch);
216
- continue;
217
- }
218
- result.push({
219
- ...entry,
220
- stateKey: `${entry.stateKey}[or:${i}]`,
221
- exclusiveCondition: simplified
222
- });
223
- priorBranches.push(branch);
224
- }
225
- return result;
226
- }
227
- //#endregion
228
- export { buildExclusiveConditions, expandExclusiveOrs, expandOrConditions, isValueMapping, parseStyleEntries };
229
-
230
- //# sourceMappingURL=exclusive.js.map