@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.
- package/README.md +322 -160
- package/dist/_virtual/_rolldown/runtime.js +1 -2
- package/dist/chunks/cacheKey.d.ts +1 -0
- package/dist/chunks/cacheKey.js +17 -10
- package/dist/chunks/cacheKey.js.map +1 -1
- package/dist/chunks/definitions.d.ts +1 -1
- package/dist/chunks/definitions.js +3 -5
- package/dist/chunks/definitions.js.map +1 -1
- package/dist/chunks/index.d.ts +1 -0
- package/dist/chunks/renderChunk.d.ts +1 -0
- package/dist/chunks/renderChunk.js +32 -34
- package/dist/chunks/renderChunk.js.map +1 -1
- package/dist/compute-styles.d.ts +31 -0
- package/dist/compute-styles.js +322 -0
- package/dist/compute-styles.js.map +1 -0
- package/dist/config.d.ts +157 -30
- package/dist/config.js +233 -45
- package/dist/config.js.map +1 -1
- package/dist/core/index.d.ts +12 -11
- package/dist/core/index.js +12 -11
- package/dist/counter-style/index.js +51 -0
- package/dist/counter-style/index.js.map +1 -0
- package/dist/debug.d.ts +26 -141
- package/dist/debug.js +359 -639
- package/dist/debug.js.map +1 -1
- package/dist/font-face/index.js +63 -0
- package/dist/font-face/index.js.map +1 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/useCounterStyle.d.ts +36 -0
- package/dist/hooks/useCounterStyle.js +65 -0
- package/dist/hooks/useCounterStyle.js.map +1 -0
- package/dist/hooks/useFontFace.d.ts +45 -0
- package/dist/hooks/useFontFace.js +66 -0
- package/dist/hooks/useFontFace.js.map +1 -0
- package/dist/hooks/useGlobalStyles.d.ts +21 -2
- package/dist/hooks/useGlobalStyles.js +60 -28
- package/dist/hooks/useGlobalStyles.js.map +1 -1
- package/dist/hooks/useKeyframes.d.ts +4 -2
- package/dist/hooks/useKeyframes.js +44 -43
- package/dist/hooks/useKeyframes.js.map +1 -1
- package/dist/hooks/useProperty.d.ts +4 -2
- package/dist/hooks/useProperty.js +36 -31
- package/dist/hooks/useProperty.js.map +1 -1
- package/dist/hooks/useRawCSS.d.ts +13 -44
- package/dist/hooks/useRawCSS.js +91 -16
- package/dist/hooks/useRawCSS.js.map +1 -1
- package/dist/hooks/useStyles.d.ts +3 -3
- package/dist/hooks/useStyles.js +8 -146
- package/dist/hooks/useStyles.js.map +1 -1
- package/dist/index.d.ts +23 -12
- package/dist/index.js +15 -12
- package/dist/injector/index.d.ts +36 -11
- package/dist/injector/index.js +43 -12
- package/dist/injector/index.js.map +1 -1
- package/dist/injector/injector.d.ts +62 -3
- package/dist/injector/injector.js +293 -46
- package/dist/injector/injector.js.map +1 -1
- package/dist/injector/sheet-manager.d.ts +22 -17
- package/dist/injector/sheet-manager.js +64 -79
- package/dist/injector/sheet-manager.js.map +1 -1
- package/dist/injector/types.d.ts +121 -21
- package/dist/keyframes/index.js +1 -1
- package/dist/parser/classify.js +6 -6
- package/dist/parser/classify.js.map +1 -1
- package/dist/parser/const.js +30 -3
- package/dist/parser/const.js.map +1 -1
- package/dist/parser/lru.js +1 -1
- package/dist/parser/lru.js.map +1 -1
- package/dist/parser/parser.js +2 -3
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.js +1 -1
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/types.js +1 -1
- package/dist/parser/types.js.map +1 -1
- package/dist/pipeline/conditions.js +15 -9
- package/dist/pipeline/conditions.js.map +1 -1
- package/dist/pipeline/exclusive.js +58 -4
- package/dist/pipeline/exclusive.js.map +1 -1
- package/dist/pipeline/index.d.ts +3 -1
- package/dist/pipeline/index.js +141 -74
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/materialize.js +460 -211
- package/dist/pipeline/materialize.js.map +1 -1
- package/dist/pipeline/parseStateKey.d.ts +1 -1
- package/dist/pipeline/parseStateKey.js +38 -22
- package/dist/pipeline/parseStateKey.js.map +1 -1
- package/dist/pipeline/simplify.js +289 -156
- package/dist/pipeline/simplify.js.map +1 -1
- package/dist/pipeline/warnings.js +18 -0
- package/dist/pipeline/warnings.js.map +1 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/okhsl-plugin.js +3 -277
- package/dist/plugins/okhsl-plugin.js.map +1 -1
- package/dist/plugins/types.d.ts +20 -2
- package/dist/properties/index.js +83 -19
- package/dist/properties/index.js.map +1 -1
- package/dist/properties/property-type-resolver.d.ts +24 -0
- package/dist/properties/property-type-resolver.js +90 -0
- package/dist/properties/property-type-resolver.js.map +1 -0
- package/dist/rsc-cache.js +79 -0
- package/dist/rsc-cache.js.map +1 -0
- package/dist/ssr/astro-client.d.ts +1 -0
- package/dist/ssr/astro-client.js +19 -0
- package/dist/ssr/astro-client.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +15 -0
- package/dist/ssr/astro-middleware.js +19 -0
- package/dist/ssr/astro-middleware.js.map +1 -0
- package/dist/ssr/astro.d.ts +108 -0
- package/dist/ssr/astro.js +149 -0
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/async-storage.d.ts +17 -0
- package/dist/ssr/async-storage.js +44 -0
- package/dist/ssr/async-storage.js.map +1 -0
- package/dist/ssr/collect-auto-properties.js +58 -0
- package/dist/ssr/collect-auto-properties.js.map +1 -0
- package/dist/ssr/collector.d.ts +98 -0
- package/dist/ssr/collector.js +235 -0
- package/dist/ssr/collector.js.map +1 -0
- package/dist/ssr/context.js +16 -0
- package/dist/ssr/context.js.map +1 -0
- package/dist/ssr/format-global-rules.js +22 -0
- package/dist/ssr/format-global-rules.js.map +1 -0
- package/dist/ssr/format-keyframes.js +69 -0
- package/dist/ssr/format-keyframes.js.map +1 -0
- package/dist/ssr/format-property.js +49 -0
- package/dist/ssr/format-property.js.map +1 -0
- package/dist/ssr/format-rules.js +73 -0
- package/dist/ssr/format-rules.js.map +1 -0
- package/dist/ssr/hydrate.d.ts +29 -0
- package/dist/ssr/hydrate.js +45 -0
- package/dist/ssr/hydrate.js.map +1 -0
- package/dist/ssr/index.d.ts +4 -0
- package/dist/ssr/index.js +10 -0
- package/dist/ssr/index.js.map +1 -0
- package/dist/ssr/next.d.ts +46 -0
- package/dist/ssr/next.js +75 -0
- package/dist/ssr/next.js.map +1 -0
- package/dist/ssr/ssr-collector-ref.js +29 -0
- package/dist/ssr/ssr-collector-ref.js.map +1 -0
- package/dist/states/index.js +13 -259
- package/dist/states/index.js.map +1 -1
- package/dist/static/index.js +1 -2
- package/dist/static/inject.d.ts +5 -0
- package/dist/static/inject.js +17 -0
- package/dist/static/inject.js.map +1 -0
- package/dist/static/tastyStatic.js +1 -2
- package/dist/static/tastyStatic.js.map +1 -1
- package/dist/static/types.js +1 -1
- package/dist/styles/border.d.ts +2 -2
- package/dist/styles/border.js +30 -24
- package/dist/styles/border.js.map +1 -1
- package/dist/styles/color.d.ts +3 -3
- package/dist/styles/color.js +11 -8
- package/dist/styles/color.js.map +1 -1
- package/dist/styles/const.js +17 -0
- package/dist/styles/const.js.map +1 -0
- package/dist/styles/createStyle.js +29 -27
- package/dist/styles/createStyle.js.map +1 -1
- package/dist/styles/dimension.js +15 -3
- package/dist/styles/dimension.js.map +1 -1
- package/dist/styles/directional.js +133 -0
- package/dist/styles/directional.js.map +1 -0
- package/dist/styles/display.d.ts +3 -10
- package/dist/styles/display.js +45 -39
- package/dist/styles/display.js.map +1 -1
- package/dist/styles/fade.d.ts +2 -2
- package/dist/styles/fade.js +9 -5
- package/dist/styles/fade.js.map +1 -1
- package/dist/styles/fill.d.ts +15 -17
- package/dist/styles/fill.js +9 -9
- package/dist/styles/fill.js.map +1 -1
- package/dist/styles/flow.d.ts +3 -3
- package/dist/styles/flow.js +1 -1
- package/dist/styles/flow.js.map +1 -1
- package/dist/styles/gap.d.ts +1 -1
- package/dist/styles/gap.js +4 -3
- package/dist/styles/gap.js.map +1 -1
- package/dist/styles/height.d.ts +1 -1
- package/dist/styles/height.js +1 -2
- package/dist/styles/height.js.map +1 -1
- package/dist/styles/index.d.ts +0 -1
- package/dist/styles/index.js +3 -4
- package/dist/styles/index.js.map +1 -1
- package/dist/styles/inset.d.ts +1 -29
- package/dist/styles/inset.js +19 -135
- package/dist/styles/inset.js.map +1 -1
- package/dist/styles/list.d.ts +5 -5
- package/dist/styles/list.js +4 -2
- package/dist/styles/list.js.map +1 -1
- package/dist/styles/margin.d.ts +1 -1
- package/dist/styles/margin.js +17 -89
- package/dist/styles/margin.js.map +1 -1
- package/dist/styles/outline.d.ts +1 -1
- package/dist/styles/outline.js +6 -16
- package/dist/styles/outline.js.map +1 -1
- package/dist/styles/padding.d.ts +1 -1
- package/dist/styles/padding.js +17 -89
- package/dist/styles/padding.js.map +1 -1
- package/dist/styles/placement.d.ts +37 -0
- package/dist/styles/placement.js +74 -0
- package/dist/styles/placement.js.map +1 -0
- package/dist/styles/predefined.d.ts +4 -6
- package/dist/styles/predefined.js +9 -13
- package/dist/styles/predefined.js.map +1 -1
- package/dist/styles/preset.d.ts +6 -1
- package/dist/styles/preset.js +54 -53
- package/dist/styles/preset.js.map +1 -1
- package/dist/styles/radius.d.ts +2 -4
- package/dist/styles/radius.js +38 -6
- package/dist/styles/radius.js.map +1 -1
- package/dist/styles/scrollMargin.d.ts +24 -0
- package/dist/styles/scrollMargin.js +32 -0
- package/dist/styles/scrollMargin.js.map +1 -0
- package/dist/styles/scrollbar.d.ts +9 -5
- package/dist/styles/scrollbar.js +31 -85
- package/dist/styles/scrollbar.js.map +1 -1
- package/dist/styles/shadow.d.ts +3 -3
- package/dist/styles/shadow.js +4 -3
- package/dist/styles/shadow.js.map +1 -1
- package/dist/styles/shared.js +17 -0
- package/dist/styles/shared.js.map +1 -0
- package/dist/styles/transition.d.ts +2 -2
- package/dist/styles/transition.js +6 -5
- package/dist/styles/transition.js.map +1 -1
- package/dist/styles/types.d.ts +94 -28
- package/dist/styles/width.d.ts +1 -1
- package/dist/styles/width.js +1 -2
- package/dist/styles/width.js.map +1 -1
- package/dist/tasty.d.ts +46 -894
- package/dist/tasty.js +117 -60
- package/dist/tasty.js.map +1 -1
- package/dist/types.d.ts +3 -3
- package/dist/utils/cache-wrapper.js +4 -9
- package/dist/utils/cache-wrapper.js.map +1 -1
- package/dist/utils/case-converter.js +1 -1
- package/dist/utils/color-math.d.ts +46 -0
- package/dist/utils/color-math.js +749 -0
- package/dist/utils/color-math.js.map +1 -0
- package/dist/utils/color-space.d.ts +5 -0
- package/dist/utils/color-space.js +228 -0
- package/dist/utils/color-space.js.map +1 -0
- package/dist/utils/colors.d.ts +1 -1
- package/dist/utils/colors.js +3 -2
- package/dist/utils/colors.js.map +1 -1
- package/dist/utils/css-types.d.ts +1 -1
- package/dist/utils/deps-equal.js +15 -0
- package/dist/utils/deps-equal.js.map +1 -0
- package/dist/utils/dotize.d.ts +1 -1
- package/dist/utils/dotize.js +1 -1
- package/dist/utils/dotize.js.map +1 -1
- package/dist/utils/filter-base-props.d.ts +1 -1
- package/dist/utils/filter-base-props.js +1 -1
- package/dist/utils/filter-base-props.js.map +1 -1
- package/dist/utils/get-display-name.js +1 -1
- package/dist/utils/has-keys.js +13 -0
- package/dist/utils/has-keys.js.map +1 -0
- package/dist/utils/hash.js +14 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/is-dev-env.js +1 -1
- package/dist/utils/is-dev-env.js.map +1 -1
- package/dist/utils/is-valid-element-type.js +1 -1
- package/dist/utils/merge-styles.js +1 -2
- package/dist/utils/merge-styles.js.map +1 -1
- package/dist/utils/mod-attrs.d.ts +0 -2
- package/dist/utils/mod-attrs.js +3 -4
- package/dist/utils/mod-attrs.js.map +1 -1
- package/dist/utils/process-tokens.d.ts +3 -17
- package/dist/utils/process-tokens.js +19 -107
- package/dist/utils/process-tokens.js.map +1 -1
- package/dist/utils/resolve-recipes.js +1 -2
- package/dist/utils/resolve-recipes.js.map +1 -1
- package/dist/utils/selector-transform.js +32 -0
- package/dist/utils/selector-transform.js.map +1 -0
- package/dist/utils/string.js +1 -1
- package/dist/utils/string.js.map +1 -1
- package/dist/utils/styles.d.ts +5 -89
- package/dist/utils/styles.js +35 -400
- package/dist/utils/styles.js.map +1 -1
- package/dist/utils/typography.d.ts +35 -13
- package/dist/utils/typography.js +16 -18
- package/dist/utils/typography.js.map +1 -1
- package/dist/utils/warnings.js +1 -1
- package/dist/zero/babel.d.ts +57 -84
- package/dist/zero/babel.js +217 -37
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/css-writer.js +1 -2
- package/dist/zero/css-writer.js.map +1 -1
- package/dist/zero/extractor.js +119 -3
- package/dist/zero/extractor.js.map +1 -1
- package/dist/zero/index.js +1 -2
- package/dist/zero/next.d.ts +56 -30
- package/dist/zero/next.js +105 -40
- package/dist/zero/next.js.map +1 -1
- package/docs/PIPELINE.md +519 -0
- package/docs/README.md +31 -0
- package/docs/adoption.md +298 -0
- package/docs/comparison.md +419 -0
- package/docs/configuration.md +394 -0
- package/docs/debug.md +318 -0
- package/docs/design-system.md +436 -0
- package/docs/dsl.md +688 -0
- package/docs/getting-started.md +217 -0
- package/docs/injector.md +544 -0
- package/docs/methodology.md +616 -0
- package/docs/react-api.md +557 -0
- package/docs/ssr.md +442 -0
- package/docs/styles.md +596 -0
- package/docs/tasty-static.md +532 -0
- package/package.json +112 -31
- package/dist/styles/align.d.ts +0 -15
- package/dist/styles/align.js +0 -14
- package/dist/styles/align.js.map +0 -1
- package/dist/styles/justify.d.ts +0 -15
- package/dist/styles/justify.js +0 -14
- package/dist/styles/justify.js.map +0 -1
- package/dist/styles/styledScrollbar.d.ts +0 -47
- package/dist/styles/styledScrollbar.js +0 -38
- package/dist/styles/styledScrollbar.js.map +0 -1
- package/dist/tokens/typography.d.ts +0 -19
- package/dist/tokens/typography.js +0 -237
- package/dist/tokens/typography.js.map +0 -1
- package/dist/utils/hsl-to-rgb.js +0 -38
- package/dist/utils/hsl-to-rgb.js.map +0 -1
- package/dist/utils/okhsl-to-rgb.js +0 -296
- 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
|
|
97
|
-
|
|
98
|
-
|
|
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
|
|
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
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
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
|
|
296
|
-
const
|
|
264
|
+
function hasGroupedValueConflict(terms, match, groupKey, getValue) {
|
|
265
|
+
const groups = /* @__PURE__ */ new Map();
|
|
297
266
|
for (const term of terms) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
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
|
|
309
|
-
const positiveValues = group.positive.filter((
|
|
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 =
|
|
312
|
-
const hasNegatedExistence = group.negated.some((
|
|
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)
|
|
315
|
-
|
|
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
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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
|
-
|
|
342
|
-
|
|
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
|
|
347
|
-
if (term.kind !== "state" || !term.negated) return
|
|
332
|
+
return (term) => {
|
|
333
|
+
if (term.kind !== "state" || !term.negated) return false;
|
|
348
334
|
if (term.type === "container" && term.subtype === "style") {
|
|
349
|
-
|
|
350
|
-
const
|
|
351
|
-
|
|
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
|
|
358
|
-
|
|
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
|
|
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
|
-
|
|
431
|
-
|
|
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
|
-
|
|
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
|
-
|
|
455
|
-
|
|
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
|
|
445
|
+
function mergeDimensionRanges(conditions, idPrefix) {
|
|
471
446
|
if (conditions.length === 0) return null;
|
|
472
|
-
|
|
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
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
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
|
-
|
|
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
|
-
|
|
499
|
-
|
|
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
|
-
|
|
523
|
-
|
|
524
|
-
|
|
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
|
|
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
|
|
532
|
-
const
|
|
533
|
-
for (const term of terms)
|
|
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 ===
|
|
536
|
-
for (const child of term.children) if (
|
|
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
|
|
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
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
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
|
-
|
|
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
|