@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,6 +1,5 @@
1
1
  import { Lru } from "../parser/lru.js";
2
- import { falseCondition, getConditionUniqueId, trueCondition } from "./conditions.js";
3
-
2
+ import { and, falseCondition, getConditionUniqueId, not, or, trueCondition } from "./conditions.js";
4
3
  //#region src/pipeline/simplify.ts
5
4
  /**
6
5
  * Condition Simplification Engine
@@ -62,6 +61,7 @@ function simplifyAnd(children) {
62
61
  terms = mergeRanges(terms);
63
62
  terms = sortTerms(terms);
64
63
  terms = applyAbsorptionAnd(terms);
64
+ terms = applyConsensusAnd(terms);
65
65
  if (terms.length === 0) return trueCondition();
66
66
  if (terms.length === 1) return terms[0];
67
67
  return {
@@ -84,6 +84,7 @@ function simplifyOr(children) {
84
84
  terms = deduplicateTerms(terms);
85
85
  terms = sortTerms(terms);
86
86
  terms = applyAbsorptionOr(terms);
87
+ terms = applyComplementaryFactoring(terms);
87
88
  if (terms.length === 0) return falseCondition();
88
89
  if (terms.length === 1) return terms[0];
89
90
  return {
@@ -93,23 +94,11 @@ function simplifyOr(children) {
93
94
  };
94
95
  }
95
96
  /**
96
- * Check if any term contradicts another (A & !A)
97
- */
98
- function hasContradiction(terms) {
99
- const uniqueIds = /* @__PURE__ */ new Set();
100
- for (const term of terms) {
101
- if (term.kind !== "state") continue;
102
- const id = term.uniqueId;
103
- const negatedId = term.negated ? id.slice(1) : `!${id}`;
104
- if (uniqueIds.has(negatedId)) return true;
105
- uniqueIds.add(id);
106
- }
107
- return false;
108
- }
109
- /**
110
- * Check for tautologies (A | !A)
97
+ * Check if any pair of terms has complementary negation (A and !A).
98
+ * Used for both contradiction detection (in AND) and tautology detection (in OR),
99
+ * since the underlying check is identical: the context determines the semantics.
111
100
  */
112
- function hasTautology(terms) {
101
+ function hasComplementaryPair(terms) {
113
102
  const uniqueIds = /* @__PURE__ */ new Set();
114
103
  for (const term of terms) {
115
104
  if (term.kind !== "state") continue;
@@ -120,6 +109,8 @@ function hasTautology(terms) {
120
109
  }
121
110
  return false;
122
111
  }
112
+ const hasContradiction = hasComplementaryPair;
113
+ const hasTautology = hasComplementaryPair;
123
114
  /**
124
115
  * Check for range contradictions in media/container queries
125
116
  * e.g., @media(w < 400px) & @media(w > 800px) → FALSE
@@ -262,61 +253,52 @@ function boundsWithinExcludedRange(bounds, excluded) {
262
253
  * e.g., [data-theme="dark"] & [data-theme="light"] → FALSE
263
254
  * e.g., [data-theme="dark"] & ![data-theme] → FALSE
264
255
  */
265
- function hasAttributeConflict(terms) {
266
- const modifiersByAttr = /* @__PURE__ */ new Map();
267
- for (const term of terms) {
268
- if (term.kind !== "state" || term.type !== "modifier") continue;
269
- const attr = term.attribute;
270
- if (!modifiersByAttr.has(attr)) modifiersByAttr.set(attr, {
271
- positive: [],
272
- negated: []
273
- });
274
- const group = modifiersByAttr.get(attr);
275
- if (term.negated) group.negated.push(term);
276
- else group.positive.push(term);
277
- }
278
- for (const [_attr, group] of modifiersByAttr) {
279
- const positiveValues = group.positive.filter((m) => m.value !== void 0).map((m) => m.value);
280
- if (new Set(positiveValues).size > 1) return true;
281
- const hasPositiveValue = group.positive.some((m) => m.value !== void 0);
282
- const hasNegatedBoolean = group.negated.some((m) => m.value === void 0);
283
- if (hasPositiveValue && hasNegatedBoolean) return true;
284
- for (const pos of group.positive) if (pos.value !== void 0) {
285
- for (const neg of group.negated) if (neg.value === pos.value) return true;
286
- }
287
- }
288
- return false;
289
- }
290
256
  /**
291
- * Check for container style query conflicts
292
- * e.g., style(--variant: danger) & style(--variant: success) → FALSE
293
- * e.g., style(--variant: danger) & not style(--variant) → FALSE
257
+ * Generic value-conflict checker for grouped conditions.
258
+ *
259
+ * Groups terms by a key, splits into positive/negated, then checks:
260
+ * 1. Multiple distinct positive values → conflict
261
+ * 2. Positive value + negated existence (value === undefined) → conflict
262
+ * 3. Positive value + negated same value → conflict
294
263
  */
295
- function hasContainerStyleConflict(terms) {
296
- const styleByProp = /* @__PURE__ */ new Map();
264
+ function hasGroupedValueConflict(terms, match, groupKey, getValue) {
265
+ const groups = /* @__PURE__ */ new Map();
297
266
  for (const term of terms) {
298
- if (term.kind !== "state" || term.type !== "container" || term.subtype !== "style") continue;
299
- const key = `${term.containerName || "_"}:${term.property}`;
300
- if (!styleByProp.has(key)) styleByProp.set(key, {
301
- positive: [],
302
- negated: []
303
- });
304
- const group = styleByProp.get(key);
305
- if (term.negated) group.negated.push(term);
306
- else group.positive.push(term);
267
+ const matched = match(term);
268
+ if (!matched) continue;
269
+ const key = groupKey(matched);
270
+ let group = groups.get(key);
271
+ if (!group) {
272
+ group = {
273
+ positive: [],
274
+ negated: []
275
+ };
276
+ groups.set(key, group);
277
+ }
278
+ if (matched.negated) group.negated.push(matched);
279
+ else group.positive.push(matched);
307
280
  }
308
- for (const [, group] of styleByProp) {
309
- const positiveValues = group.positive.filter((c) => c.propertyValue !== void 0).map((c) => c.propertyValue);
281
+ for (const [, group] of groups) {
282
+ const positiveValues = group.positive.map(getValue).filter((v) => v !== void 0);
310
283
  if (new Set(positiveValues).size > 1) return true;
311
- const hasPositiveValue = group.positive.some((c) => c.propertyValue !== void 0);
312
- const hasNegatedExistence = group.negated.some((c) => c.propertyValue === void 0);
284
+ const hasPositiveValue = positiveValues.length > 0;
285
+ const hasNegatedExistence = group.negated.some((t) => getValue(t) === void 0);
313
286
  if (hasPositiveValue && hasNegatedExistence) return true;
314
- for (const pos of group.positive) if (pos.propertyValue !== void 0) {
315
- for (const neg of group.negated) if (neg.propertyValue === pos.propertyValue) return true;
287
+ for (const pos of group.positive) {
288
+ const posVal = getValue(pos);
289
+ if (posVal !== void 0) {
290
+ for (const neg of group.negated) if (getValue(neg) === posVal) return true;
291
+ }
316
292
  }
317
293
  }
318
294
  return false;
319
295
  }
296
+ function hasAttributeConflict(terms) {
297
+ return hasGroupedValueConflict(terms, (t) => t.kind === "state" && t.type === "modifier" ? t : null, (t) => t.attribute, (t) => t.value);
298
+ }
299
+ function hasContainerStyleConflict(terms) {
300
+ return hasGroupedValueConflict(terms, (t) => t.kind === "state" && t.type === "container" && t.subtype === "style" ? t : null, (t) => `${t.containerName || "_"}:${t.property}`, (t) => t.propertyValue);
301
+ }
320
302
  /**
321
303
  * Remove negations that are implied by positive terms.
322
304
  *
@@ -332,35 +314,38 @@ function hasContainerStyleConflict(terms) {
332
314
  * Before: @container style(--variant: danger) and (not style(--variant: success))
333
315
  * After: @container style(--variant: danger)
334
316
  */
335
- function removeImpliedNegations(terms) {
336
- const positiveContainerStyles = /* @__PURE__ */ new Map();
337
- const positiveModifiers = /* @__PURE__ */ new Map();
317
+ /**
318
+ * Collect positive values from terms and build a "is this negation implied?" check.
319
+ *
320
+ * A negation is implied (redundant) when a positive term for the same group
321
+ * already pins a specific value, making "NOT other-value" obvious.
322
+ * e.g. style(--variant: danger) implies NOT style(--variant: success).
323
+ */
324
+ function buildImpliedNegationCheck(terms) {
325
+ const positiveValues = /* @__PURE__ */ new Map();
338
326
  for (const term of terms) {
339
327
  if (term.kind !== "state" || term.negated) continue;
340
328
  if (term.type === "container" && term.subtype === "style") {
341
- const key = `${term.containerName || "_"}:${term.property}`;
342
- if (term.propertyValue !== void 0) positiveContainerStyles.set(key, term.propertyValue);
343
- }
344
- if (term.type === "modifier" && term.value !== void 0) positiveModifiers.set(term.attribute, term.value);
329
+ if (term.propertyValue !== void 0) positiveValues.set(`c:${term.containerName || "_"}:${term.property}`, term.propertyValue);
330
+ } else if (term.type === "modifier" && term.value !== void 0) positiveValues.set(`m:${term.attribute}`, term.value);
345
331
  }
346
- return terms.filter((term) => {
347
- if (term.kind !== "state" || !term.negated) return true;
332
+ return (term) => {
333
+ if (term.kind !== "state" || !term.negated) return false;
348
334
  if (term.type === "container" && term.subtype === "style") {
349
- const key = `${term.containerName || "_"}:${term.property}`;
350
- const positiveValue = positiveContainerStyles.get(key);
351
- if (positiveValue !== void 0) {
352
- if (term.propertyValue === void 0) return true;
353
- if (term.propertyValue !== positiveValue) return false;
354
- }
335
+ if (term.propertyValue === void 0) return false;
336
+ const pos = positiveValues.get(`c:${term.containerName || "_"}:${term.property}`);
337
+ return pos !== void 0 && term.propertyValue !== pos;
355
338
  }
356
- if (term.type === "modifier") {
357
- const positiveValue = positiveModifiers.get(term.attribute);
358
- if (positiveValue !== void 0 && term.value !== void 0) {
359
- if (term.value !== positiveValue) return false;
360
- }
339
+ if (term.type === "modifier" && term.value !== void 0) {
340
+ const pos = positiveValues.get(`m:${term.attribute}`);
341
+ return pos !== void 0 && term.value !== pos;
361
342
  }
362
- return true;
363
- });
343
+ return false;
344
+ };
345
+ }
346
+ function removeImpliedNegations(terms) {
347
+ const isImplied = buildImpliedNegationCheck(terms);
348
+ return terms.filter((t) => !isImplied(t));
364
349
  }
365
350
  function deduplicateTerms(terms) {
366
351
  const seen = /* @__PURE__ */ new Set();
@@ -427,8 +412,11 @@ function mergeRanges(terms) {
427
412
  result.push(...mergedTerms);
428
413
  return result;
429
414
  }
430
- function mergeMediaRanges(conditions) {
431
- if (conditions.length === 0) return null;
415
+ /**
416
+ * Tighten bounds by picking the most restrictive lower and upper bounds
417
+ * from a set of conditions that have lowerBound/upperBound fields.
418
+ */
419
+ function tightenBounds(conditions) {
432
420
  let lowerBound;
433
421
  let upperBound;
434
422
  for (const cond of conditions) {
@@ -439,23 +427,12 @@ function mergeMediaRanges(conditions) {
439
427
  if (!upperBound || (cond.upperBound.valueNumeric ?? Infinity) < (upperBound.valueNumeric ?? Infinity)) upperBound = cond.upperBound;
440
428
  }
441
429
  }
442
- const base = conditions[0];
443
- const merged = {
444
- kind: "state",
445
- type: "media",
446
- subtype: "dimension",
447
- negated: false,
448
- raw: buildMergedRaw(base.dimension || "width", lowerBound, upperBound),
449
- uniqueId: "",
450
- dimension: base.dimension,
430
+ return {
451
431
  lowerBound,
452
432
  upperBound
453
433
  };
454
- const parts = [
455
- "media",
456
- "dim",
457
- merged.dimension
458
- ];
434
+ }
435
+ function appendBoundsToUniqueId(parts, lowerBound, upperBound) {
459
436
  if (lowerBound) {
460
437
  parts.push(lowerBound.inclusive ? ">=" : ">");
461
438
  parts.push(lowerBound.value);
@@ -464,50 +441,38 @@ function mergeMediaRanges(conditions) {
464
441
  parts.push(upperBound.inclusive ? "<=" : "<");
465
442
  parts.push(upperBound.value);
466
443
  }
467
- merged.uniqueId = parts.join(":");
468
- return merged;
469
444
  }
470
- function mergeContainerRanges(conditions) {
445
+ function mergeDimensionRanges(conditions, idPrefix) {
471
446
  if (conditions.length === 0) return null;
472
- let lowerBound;
473
- let upperBound;
474
- for (const cond of conditions) {
475
- if (cond.lowerBound) {
476
- if (!lowerBound || (cond.lowerBound.valueNumeric ?? -Infinity) > (lowerBound.valueNumeric ?? -Infinity)) lowerBound = cond.lowerBound;
477
- }
478
- if (cond.upperBound) {
479
- if (!upperBound || (cond.upperBound.valueNumeric ?? Infinity) < (upperBound.valueNumeric ?? Infinity)) upperBound = cond.upperBound;
480
- }
481
- }
447
+ const { lowerBound, upperBound } = tightenBounds(conditions);
482
448
  const base = conditions[0];
483
- const merged = {
484
- kind: "state",
485
- type: "container",
486
- subtype: "dimension",
449
+ const parts = [...idPrefix];
450
+ appendBoundsToUniqueId(parts, lowerBound, upperBound);
451
+ return {
452
+ ...base,
487
453
  negated: false,
488
454
  raw: buildMergedRaw(base.dimension || "width", lowerBound, upperBound),
489
- uniqueId: "",
490
- containerName: base.containerName,
491
- dimension: base.dimension,
455
+ uniqueId: parts.join(":"),
492
456
  lowerBound,
493
457
  upperBound
494
458
  };
495
- const parts = [
459
+ }
460
+ function mergeMediaRanges(conditions) {
461
+ return mergeDimensionRanges(conditions, [
462
+ "media",
463
+ "dim",
464
+ conditions[0]?.dimension ?? "width"
465
+ ]);
466
+ }
467
+ function mergeContainerRanges(conditions) {
468
+ const base = conditions[0];
469
+ if (!base) return null;
470
+ return mergeDimensionRanges(conditions, [
496
471
  "container",
497
472
  "dim",
498
- merged.containerName || "_",
499
- merged.dimension
500
- ];
501
- if (lowerBound) {
502
- parts.push(lowerBound.inclusive ? ">=" : ">");
503
- parts.push(lowerBound.value);
504
- }
505
- if (upperBound) {
506
- parts.push(upperBound.inclusive ? "<=" : "<");
507
- parts.push(upperBound.value);
508
- }
509
- merged.uniqueId = parts.join(":");
510
- return merged;
473
+ base.containerName || "_",
474
+ base.dimension ?? "width"
475
+ ]);
511
476
  }
512
477
  function buildMergedRaw(dimension, lowerBound, upperBound) {
513
478
  if (lowerBound && upperBound) {
@@ -518,40 +483,208 @@ function buildMergedRaw(dimension, lowerBound, upperBound) {
518
483
  else if (lowerBound) return `@media(${dimension} ${lowerBound.inclusive ? ">=" : ">"} ${lowerBound.value})`;
519
484
  return "@media()";
520
485
  }
486
+ /**
487
+ * Apply complementary factoring: (A & B) | (A & !B) → A
488
+ *
489
+ * Finds pairs of AND compounds that share all children except one,
490
+ * where the differing child is complementary (X vs !X).
491
+ * Replaces the pair with the common terms.
492
+ *
493
+ * This is applied iteratively until no more reductions are possible,
494
+ * since factoring can expose further simplification opportunities.
495
+ */
496
+ function applyComplementaryFactoring(terms) {
497
+ let changed = true;
498
+ while (changed) {
499
+ changed = false;
500
+ for (let i = 0; i < terms.length; i++) {
501
+ const a = terms[i];
502
+ if (a.kind !== "compound" || a.operator !== "AND") continue;
503
+ for (let j = i + 1; j < terms.length; j++) {
504
+ const b = terms[j];
505
+ if (b.kind !== "compound" || b.operator !== "AND") continue;
506
+ const factored = tryFactorPair(a.children, b.children);
507
+ if (factored) {
508
+ const replacement = simplifyInner(factored);
509
+ terms = [
510
+ ...terms.slice(0, i),
511
+ ...terms.slice(i + 1, j),
512
+ ...terms.slice(j + 1),
513
+ replacement
514
+ ];
515
+ changed = true;
516
+ break;
517
+ }
518
+ }
519
+ if (changed) break;
520
+ }
521
+ }
522
+ return terms;
523
+ }
524
+ /**
525
+ * Try to factor two AND children lists.
526
+ *
527
+ * Extracts the common children (by uniqueId). If the remaining
528
+ * (non-common) parts of each side OR to TRUE, the common part alone
529
+ * is sufficient: `(common & restA) | (common & restB) → common`
530
+ * when `restA | restB → TRUE`.
531
+ *
532
+ * Also handles the simpler case where exactly one child is
533
+ * complementary: `[A, B, C]` and `[A, !B, C]` → `AND(A, C)`.
534
+ */
535
+ function tryFactorPair(aChildren, bChildren) {
536
+ const aIds = aChildren.map((c) => getConditionUniqueId(c));
537
+ const bIds = bChildren.map((c) => getConditionUniqueId(c));
538
+ const bIdSet = new Set(bIds);
539
+ const aIdSet = new Set(aIds);
540
+ const commonIndicesA = [];
541
+ const restIndicesA = [];
542
+ for (let i = 0; i < aIds.length; i++) if (bIdSet.has(aIds[i])) commonIndicesA.push(i);
543
+ else restIndicesA.push(i);
544
+ const restIndicesB = [];
545
+ for (let i = 0; i < bIds.length; i++) if (!aIdSet.has(bIds[i])) restIndicesB.push(i);
546
+ if (commonIndicesA.length === 0) return null;
547
+ if (restIndicesA.length === 0 && restIndicesB.length === 0) return null;
548
+ const restA = restIndicesA.length === 0 ? trueCondition() : restIndicesA.length === 1 ? aChildren[restIndicesA[0]] : and(...restIndicesA.map((i) => aChildren[i]));
549
+ const restB = restIndicesB.length === 0 ? trueCondition() : restIndicesB.length === 1 ? bChildren[restIndicesB[0]] : and(...restIndicesB.map((i) => bChildren[i]));
550
+ if (simplifyInner({
551
+ kind: "compound",
552
+ operator: "OR",
553
+ children: [restA, restB]
554
+ }).kind !== "true") {
555
+ const simplifiedRestB = simplifyInner(restB);
556
+ if (getConditionUniqueId(simplifyInner(not(restA))) !== getConditionUniqueId(simplifiedRestB)) return null;
557
+ }
558
+ const common = commonIndicesA.map((i) => aChildren[i]);
559
+ if (common.length === 0) return trueCondition();
560
+ if (common.length === 1) return common[0];
561
+ return and(...common);
562
+ }
521
563
  function sortTerms(terms) {
522
- return [...terms].sort((a, b) => {
523
- const idA = getConditionUniqueId(a);
524
- const idB = getConditionUniqueId(b);
525
- return idA.localeCompare(idB);
526
- });
564
+ const withIds = terms.map((t) => [getConditionUniqueId(t), t]);
565
+ withIds.sort((a, b) => a[0].localeCompare(b[0]));
566
+ return withIds.map(([, t]) => t);
527
567
  }
528
568
  /**
529
- * Apply absorption law for AND: A & (A | B) → A
569
+ * Apply the absorption law: removes compound terms that are absorbed by
570
+ * another term already present (simple or compound).
571
+ *
572
+ * For AND context: A & (A | B) → A (absorbs OR compounds)
573
+ * For OR context: A | (A & B) → A (absorbs AND compounds)
574
+ *
575
+ * After flattening, a compound A = OR(X, Y) becomes [X, Y, ...] in the
576
+ * outer OR. A child AND(A, B) = AND(OR(X, Y), B) still references the
577
+ * original un-flattened compound. We reconstruct possible compound
578
+ * absorbers from the flattened terms so absorption works across nesting.
530
579
  */
531
- function applyAbsorptionAnd(terms) {
532
- const simpleIds = /* @__PURE__ */ new Set();
533
- for (const term of terms) if (term.kind !== "compound") simpleIds.add(getConditionUniqueId(term));
580
+ function applyAbsorption(terms, absorbedOperator) {
581
+ const absorberIds = /* @__PURE__ */ new Set();
582
+ for (const term of terms) absorberIds.add(getConditionUniqueId(term));
583
+ let changed = true;
584
+ while (changed) {
585
+ changed = false;
586
+ for (const term of terms) {
587
+ if (term.kind !== "compound" || term.operator !== absorbedOperator) continue;
588
+ for (const child of term.children) {
589
+ if (child.kind !== "compound") continue;
590
+ const childId = getConditionUniqueId(child);
591
+ if (absorberIds.has(childId)) continue;
592
+ if (child.children.every((c) => absorberIds.has(getConditionUniqueId(c)))) {
593
+ absorberIds.add(childId);
594
+ changed = true;
595
+ }
596
+ }
597
+ }
598
+ }
534
599
  return terms.filter((term) => {
535
- if (term.kind === "compound" && term.operator === "OR") {
536
- for (const child of term.children) if (simpleIds.has(getConditionUniqueId(child))) return false;
600
+ if (term.kind === "compound" && term.operator === absorbedOperator) {
601
+ for (const child of term.children) if (absorberIds.has(getConditionUniqueId(child))) return false;
537
602
  }
538
603
  return true;
539
604
  });
540
605
  }
606
+ function applyAbsorptionAnd(terms) {
607
+ return applyAbsorption(terms, "OR");
608
+ }
609
+ function applyAbsorptionOr(terms) {
610
+ return applyAbsorption(terms, "AND");
611
+ }
541
612
  /**
542
- * Apply absorption law for OR: A | (A & B) → A
613
+ * Apply the consensus/resolution rule for AND:
614
+ * (A | B) & (A | !B) → A
615
+ *
616
+ * This is the dual of complementary factoring in OR context:
617
+ * (A & B) | (A & !B) → A
618
+ *
619
+ * Extracts common children from two OR terms. If the remaining
620
+ * parts of each side AND to FALSE, the common part alone is
621
+ * sufficient.
543
622
  */
544
- function applyAbsorptionOr(terms) {
545
- const simpleIds = /* @__PURE__ */ new Set();
546
- for (const term of terms) if (term.kind !== "compound") simpleIds.add(getConditionUniqueId(term));
547
- return terms.filter((term) => {
548
- if (term.kind === "compound" && term.operator === "AND") {
549
- for (const child of term.children) if (simpleIds.has(getConditionUniqueId(child))) return false;
623
+ function applyConsensusAnd(terms) {
624
+ let changed = true;
625
+ while (changed) {
626
+ changed = false;
627
+ for (let i = 0; i < terms.length; i++) {
628
+ const a = terms[i];
629
+ if (a.kind !== "compound" || a.operator !== "OR") continue;
630
+ for (let j = i + 1; j < terms.length; j++) {
631
+ const b = terms[j];
632
+ if (b.kind !== "compound" || b.operator !== "OR") continue;
633
+ const resolved = tryResolvePair(a.children, b.children);
634
+ if (resolved) {
635
+ const replacement = simplifyInner(resolved);
636
+ terms = [
637
+ ...terms.slice(0, i),
638
+ ...terms.slice(i + 1, j),
639
+ ...terms.slice(j + 1),
640
+ replacement
641
+ ];
642
+ changed = true;
643
+ break;
644
+ }
645
+ }
646
+ if (changed) break;
550
647
  }
551
- return true;
552
- });
648
+ }
649
+ return terms;
650
+ }
651
+ /**
652
+ * Try to resolve two OR children lists.
653
+ *
654
+ * Extracts common children (by uniqueId). If the remaining
655
+ * (non-common) parts AND to FALSE, the common part alone
656
+ * is sufficient: `(common | restA) & (common | restB) → common`
657
+ * when `restA & restB → FALSE`.
658
+ */
659
+ function tryResolvePair(aChildren, bChildren) {
660
+ const aIds = aChildren.map((c) => getConditionUniqueId(c));
661
+ const bIds = bChildren.map((c) => getConditionUniqueId(c));
662
+ const bIdSet = new Set(bIds);
663
+ const aIdSet = new Set(aIds);
664
+ const commonIndicesA = [];
665
+ const restIndicesA = [];
666
+ for (let i = 0; i < aIds.length; i++) if (bIdSet.has(aIds[i])) commonIndicesA.push(i);
667
+ else restIndicesA.push(i);
668
+ const restIndicesB = [];
669
+ for (let i = 0; i < bIds.length; i++) if (!aIdSet.has(bIds[i])) restIndicesB.push(i);
670
+ if (commonIndicesA.length === 0) return null;
671
+ if (restIndicesA.length === 0 && restIndicesB.length === 0) return null;
672
+ const restA = restIndicesA.length === 0 ? falseCondition() : restIndicesA.length === 1 ? aChildren[restIndicesA[0]] : or(...restIndicesA.map((i) => aChildren[i]));
673
+ const restB = restIndicesB.length === 0 ? falseCondition() : restIndicesB.length === 1 ? bChildren[restIndicesB[0]] : or(...restIndicesB.map((i) => bChildren[i]));
674
+ if (simplifyInner({
675
+ kind: "compound",
676
+ operator: "AND",
677
+ children: [restA, restB]
678
+ }).kind !== "false") {
679
+ const simplifiedRestB = simplifyInner(restB);
680
+ if (getConditionUniqueId(simplifyInner(not(restA))) !== getConditionUniqueId(simplifiedRestB)) return null;
681
+ }
682
+ const common = commonIndicesA.map((i) => aChildren[i]);
683
+ if (common.length === 0) return falseCondition();
684
+ if (common.length === 1) return common[0];
685
+ return or(...common);
553
686
  }
554
-
555
687
  //#endregion
556
688
  export { simplifyCondition };
689
+
557
690
  //# sourceMappingURL=simplify.js.map