@tenphi/tasty 0.0.0-snapshot.b3fbcbb → 0.0.0-snapshot.b478bc9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +297 -208
- 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 +149 -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 +15 -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 +256 -31
- package/dist/injector/injector.js.map +1 -1
- package/dist/injector/sheet-manager.d.ts +10 -13
- package/dist/injector/sheet-manager.js +42 -71
- package/dist/injector/sheet-manager.js.map +1 -1
- package/dist/injector/types.d.ts +112 -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 +1 -1
- package/dist/pipeline/conditions.js.map +1 -1
- package/dist/pipeline/exclusive.js +163 -5
- package/dist/pipeline/exclusive.js.map +1 -1
- package/dist/pipeline/index.d.ts +3 -1
- package/dist/pipeline/index.js +172 -83
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/materialize-contradictions.js +125 -0
- package/dist/pipeline/materialize-contradictions.js.map +1 -0
- package/dist/pipeline/materialize.js +437 -243
- package/dist/pipeline/materialize.js.map +1 -1
- package/dist/pipeline/parseStateKey.d.ts +1 -1
- package/dist/pipeline/parseStateKey.js +21 -13
- package/dist/pipeline/parseStateKey.js.map +1 -1
- package/dist/pipeline/simplify.js +181 -7
- package/dist/pipeline/simplify.js.map +1 -1
- package/dist/pipeline/warnings.js +1 -1
- 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 +15 -30
- package/dist/properties/index.js.map +1 -1
- package/dist/properties/property-type-resolver.js +13 -2
- package/dist/properties/property-type-resolver.js.map +1 -1
- 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 +1 -1
- package/dist/styles/border.js +30 -24
- package/dist/styles/border.js.map +1 -1
- package/dist/styles/color.d.ts +1 -1
- 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 +28 -26
- 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 +1 -1
- package/dist/styles/fade.js +9 -5
- package/dist/styles/fade.js.map +1 -1
- package/dist/styles/fill.d.ts +2 -2
- package/dist/styles/fill.js +3 -4
- package/dist/styles/fill.js.map +1 -1
- package/dist/styles/flow.js +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 +1 -3
- 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 -92
- package/dist/styles/scrollbar.js.map +1 -1
- package/dist/styles/shadow.d.ts +1 -1
- 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 +1 -1
- 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 +101 -59
- package/dist/tasty.js.map +1 -1
- package/dist/types.d.ts +1 -1
- 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.js +3 -2
- package/dist/utils/colors.js.map +1 -1
- package/dist/utils/deps-equal.js +15 -0
- package/dist/utils/deps-equal.js.map +1 -0
- 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/styles.d.ts +3 -82
- package/dist/utils/styles.js +29 -560
- 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 -89
- package/dist/zero/babel.js +214 -40
- 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 +54 -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/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 +320 -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/pipeline.md +673 -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 +68 -36
- 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
package/dist/pipeline/index.js
CHANGED
|
@@ -1,33 +1,47 @@
|
|
|
1
1
|
import { Lru } from "../parser/lru.js";
|
|
2
|
-
import { createStateParserContext, extractLocalPredefinedStates } from "../states/index.js";
|
|
3
2
|
import { stringifyStyles } from "../utils/styles.js";
|
|
4
3
|
import { createStyle } from "../styles/createStyle.js";
|
|
5
4
|
import { STYLE_HANDLER_MAP } from "../styles/index.js";
|
|
6
|
-
import {
|
|
5
|
+
import { createStateParserContext, extractLocalPredefinedStates } from "../states/index.js";
|
|
6
|
+
import { and, or, trueCondition } from "./conditions.js";
|
|
7
7
|
import { simplifyCondition } from "./simplify.js";
|
|
8
|
-
import { buildExclusiveConditions, expandExclusiveOrs, expandOrConditions, isValueMapping, parseStyleEntries } from "./exclusive.js";
|
|
9
|
-
import { buildAtRulesFromVariant, conditionToCSS,
|
|
8
|
+
import { buildExclusiveConditions, expandExclusiveOrs, expandOrConditions, extractCompoundStates, isValueMapping, mergeEntriesByValue, parseStyleEntries } from "./exclusive.js";
|
|
9
|
+
import { branchToCSS, buildAtRulesFromVariant, conditionToCSS, mergeVariantsIntoSelectorGroups, optimizeGroups, parentGroupsToCSS, rootGroupsToCSS, selectorGroupToCSS } from "./materialize.js";
|
|
10
10
|
import { emitWarning } from "./warnings.js";
|
|
11
11
|
import { parseStateKey } from "./parseStateKey.js";
|
|
12
|
-
|
|
13
12
|
//#region src/pipeline/index.ts
|
|
14
13
|
/**
|
|
15
14
|
* Tasty Style Rendering Pipeline
|
|
16
15
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
16
|
+
* Main entrypoint for the style rendering pipeline. Transforms a `Styles`
|
|
17
|
+
* object into an array of `CSSRule` objects ready for DOM injection.
|
|
18
|
+
*
|
|
19
|
+
* Per-handler stages (see docs/pipeline.md for full detail):
|
|
20
|
+
* 0. PRE-PARSE NORMALIZATION - extractCompoundStates (exclusive.ts)
|
|
21
|
+
* 1. PARSE CONDITIONS - parseStyleEntries + parseStateKey
|
|
22
|
+
* 1b. MERGE ENTRIES BY VALUE - mergeEntriesByValue (exclusive.ts)
|
|
23
|
+
* 2a. EXPAND USER OR BRANCHES - expandOrConditions (exclusive.ts)
|
|
24
|
+
* 2b. BUILD EXCLUSIVE CONDITIONS - buildExclusiveConditions
|
|
25
|
+
* 3. EXPAND DE MORGAN ORs - expandExclusiveOrs (exclusive.ts)
|
|
26
|
+
* 4. COMPUTE STATE COMBINATIONS - computeStateCombinations
|
|
27
|
+
* 5. CALL HANDLERS - run style handlers for each snapshot
|
|
28
|
+
* 6. MERGE BY VALUE - mergeByValue (index.ts)
|
|
29
|
+
* 7. MATERIALIZE CSS - conditionToCSS + materializeComputedRule
|
|
30
|
+
*
|
|
31
|
+
* Simplification (`simplifyCondition`) runs inside most stages; calls are
|
|
32
|
+
* memoized by condition unique-id. The post-pass in `runPipeline` dedupes
|
|
33
|
+
* identical rules and emits all `@starting-style` rules last so they win
|
|
34
|
+
* the cascade over their equal-specificity normal counterparts.
|
|
28
35
|
*/
|
|
29
36
|
const pipelineCache = new Lru(5e3);
|
|
30
37
|
/**
|
|
38
|
+
* Check if a cache key exists in the pipeline cache.
|
|
39
|
+
* Used by renderStylesForChunk to avoid building filtered styles on cache hit.
|
|
40
|
+
*/
|
|
41
|
+
function hasPipelineCacheEntry(cacheKey) {
|
|
42
|
+
return pipelineCache.get(cacheKey) !== void 0;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
31
45
|
* Clear the pipeline cache (for testing)
|
|
32
46
|
*/
|
|
33
47
|
function clearPipelineCache() {
|
|
@@ -37,20 +51,38 @@ function runPipeline(styles, parserContext) {
|
|
|
37
51
|
const allRules = [];
|
|
38
52
|
processStyles(styles, "", parserContext, allRules);
|
|
39
53
|
const seen = /* @__PURE__ */ new Set();
|
|
40
|
-
|
|
41
|
-
const key = `${rule.selector}|${rule.declarations}|${
|
|
54
|
+
const dedupedRules = allRules.filter((rule) => {
|
|
55
|
+
const key = `${rule.selector}|${rule.declarations}|${rule.atRules?.join("|") ?? ""}|${rule.rootPrefix || ""}|${rule.startingStyle ? "1" : "0"}`;
|
|
42
56
|
if (seen.has(key)) return false;
|
|
43
57
|
seen.add(key);
|
|
44
58
|
return true;
|
|
45
59
|
});
|
|
60
|
+
const normal = [];
|
|
61
|
+
const starting = [];
|
|
62
|
+
for (const rule of dedupedRules) if (rule.startingStyle) starting.push(rule);
|
|
63
|
+
else normal.push(rule);
|
|
64
|
+
return normal.concat(starting);
|
|
46
65
|
}
|
|
47
66
|
/**
|
|
48
|
-
* Process styles at a given nesting level
|
|
67
|
+
* Process styles at a given nesting level.
|
|
68
|
+
*
|
|
69
|
+
* Splits keys into nested-selector keys and style-handler keys, recurses
|
|
70
|
+
* into nested selectors, then runs the per-handler stages 1–7 over the
|
|
71
|
+
* style keys.
|
|
49
72
|
*/
|
|
50
73
|
function processStyles(styles, selectorSuffix, parserContext, allRules) {
|
|
51
74
|
const keys = Object.keys(styles);
|
|
52
75
|
const selectorKeys = keys.filter((key) => isSelector(key));
|
|
53
76
|
const styleKeys = keys.filter((key) => !isSelector(key) && !key.startsWith("@"));
|
|
77
|
+
processNestedSelectors(styles, selectorKeys, selectorSuffix, parserContext, allRules);
|
|
78
|
+
processHandlerQueue(buildHandlerQueue(styleKeys, styles), selectorSuffix, parserContext, allRules);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Recurse into nested selector keys. Each nested key may expand into multiple
|
|
82
|
+
* suffixes (comma-separated patterns); each suffix is processed independently
|
|
83
|
+
* with the parent's parser context augmented for sub-element scope.
|
|
84
|
+
*/
|
|
85
|
+
function processNestedSelectors(styles, selectorKeys, selectorSuffix, parserContext, allRules) {
|
|
54
86
|
for (const key of selectorKeys) {
|
|
55
87
|
const nestedStyles = styles[key];
|
|
56
88
|
if (!nestedStyles || typeof nestedStyles !== "object") continue;
|
|
@@ -69,46 +101,15 @@ function processStyles(styles, selectorSuffix, parserContext, allRules) {
|
|
|
69
101
|
};
|
|
70
102
|
for (const suffix of suffixes) processStyles(cleanedStyles, selectorSuffix + suffix, subContext, allRules);
|
|
71
103
|
}
|
|
72
|
-
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Run the per-handler pipeline (stages 1–7) over a handler queue and append
|
|
107
|
+
* the resulting CSS rules to `allRules`.
|
|
108
|
+
*/
|
|
109
|
+
function processHandlerQueue(handlerQueue, selectorSuffix, parserContext, allRules) {
|
|
73
110
|
for (const { handler, styleMap } of handlerQueue) {
|
|
74
111
|
const lookupStyles = handler.__lookupStyles;
|
|
75
|
-
const
|
|
76
|
-
for (const styleName of lookupStyles) {
|
|
77
|
-
const value = styleMap[styleName];
|
|
78
|
-
if (value === void 0) continue;
|
|
79
|
-
if (isValueMapping(value)) {
|
|
80
|
-
const fullyExpanded = expandExclusiveOrs(buildExclusiveConditions(expandOrConditions(parseStyleEntries(styleName, value, (stateKey) => parseStateKey(stateKey, { context: parserContext })))));
|
|
81
|
-
exclusiveByStyle.set(styleName, fullyExpanded);
|
|
82
|
-
} else exclusiveByStyle.set(styleName, [{
|
|
83
|
-
styleKey: styleName,
|
|
84
|
-
stateKey: "",
|
|
85
|
-
value,
|
|
86
|
-
condition: trueCondition(),
|
|
87
|
-
priority: 0,
|
|
88
|
-
exclusiveCondition: trueCondition()
|
|
89
|
-
}]);
|
|
90
|
-
}
|
|
91
|
-
const stateSnapshots = computeStateCombinations(exclusiveByStyle, lookupStyles);
|
|
92
|
-
const computedRules = [];
|
|
93
|
-
for (const snapshot of stateSnapshots) {
|
|
94
|
-
const result = handler(snapshot.values);
|
|
95
|
-
if (!result) continue;
|
|
96
|
-
const results = Array.isArray(result) ? result : [result];
|
|
97
|
-
for (const r of results) {
|
|
98
|
-
if (!r || typeof r !== "object") continue;
|
|
99
|
-
const { $, ...styleProps } = r;
|
|
100
|
-
const declarations = {};
|
|
101
|
-
for (const [prop, val] of Object.entries(styleProps)) if (val != null && val !== "") declarations[prop] = String(val);
|
|
102
|
-
if (Object.keys(declarations).length === 0) continue;
|
|
103
|
-
const suffixes = $ ? (Array.isArray($) ? $ : [$]).map((s) => selectorSuffix + normalizeSelectorSuffix(String(s))) : [selectorSuffix];
|
|
104
|
-
for (const suffix of suffixes) computedRules.push({
|
|
105
|
-
condition: snapshot.condition,
|
|
106
|
-
declarations,
|
|
107
|
-
selectorSuffix: suffix
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
const mergedRules = mergeByValue(computedRules);
|
|
112
|
+
const mergedRules = mergeByValue(invokeHandler(handler, computeStateCombinations(buildExclusivesForHandler(lookupStyles, styleMap, parserContext), lookupStyles), selectorSuffix));
|
|
112
113
|
for (const rule of mergedRules) {
|
|
113
114
|
const cssRules = materializeComputedRule(rule);
|
|
114
115
|
allRules.push(...cssRules);
|
|
@@ -116,6 +117,57 @@ function processStyles(styles, selectorSuffix, parserContext, allRules) {
|
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
119
|
/**
|
|
120
|
+
* Stages 0–3 for a single handler: take the handler's looked-up style names,
|
|
121
|
+
* resolve each style's value map into a list of mutually-exclusive entries.
|
|
122
|
+
* Simple non-mapping values produce a single TRUE-conditioned entry.
|
|
123
|
+
*/
|
|
124
|
+
function buildExclusivesForHandler(lookupStyles, styleMap, parserContext) {
|
|
125
|
+
const exclusiveByStyle = /* @__PURE__ */ new Map();
|
|
126
|
+
for (const styleName of lookupStyles) {
|
|
127
|
+
const value = styleMap[styleName];
|
|
128
|
+
if (value === void 0) continue;
|
|
129
|
+
if (isValueMapping(value)) {
|
|
130
|
+
const fullyExpanded = expandExclusiveOrs(buildExclusiveConditions(expandOrConditions(mergeEntriesByValue(parseStyleEntries(styleName, extractCompoundStates(value), (stateKey) => parseStateKey(stateKey, { context: parserContext }))))));
|
|
131
|
+
exclusiveByStyle.set(styleName, fullyExpanded);
|
|
132
|
+
} else exclusiveByStyle.set(styleName, [{
|
|
133
|
+
styleKey: styleName,
|
|
134
|
+
stateKey: "",
|
|
135
|
+
value,
|
|
136
|
+
condition: trueCondition(),
|
|
137
|
+
priority: 0,
|
|
138
|
+
exclusiveCondition: trueCondition()
|
|
139
|
+
}]);
|
|
140
|
+
}
|
|
141
|
+
return exclusiveByStyle;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Stage 5: invoke the handler for each state snapshot and translate its
|
|
145
|
+
* return value into ComputedRule entries (one per declaration set, fanned
|
|
146
|
+
* out across any `$` selector suffixes the handler returns).
|
|
147
|
+
*/
|
|
148
|
+
function invokeHandler(handler, stateSnapshots, selectorSuffix) {
|
|
149
|
+
const computedRules = [];
|
|
150
|
+
for (const snapshot of stateSnapshots) {
|
|
151
|
+
const result = handler(snapshot.values);
|
|
152
|
+
if (!result) continue;
|
|
153
|
+
const results = Array.isArray(result) ? result : [result];
|
|
154
|
+
for (const r of results) {
|
|
155
|
+
if (!r || typeof r !== "object") continue;
|
|
156
|
+
const { $, ...styleProps } = r;
|
|
157
|
+
const declarations = {};
|
|
158
|
+
for (const [prop, val] of Object.entries(styleProps)) if (val != null && val !== "") declarations[prop] = String(val);
|
|
159
|
+
if (Object.keys(declarations).length === 0) continue;
|
|
160
|
+
const suffixes = $ ? (Array.isArray($) ? $ : [$]).map((s) => selectorSuffix + normalizeSelectorSuffix(String(s))) : [selectorSuffix];
|
|
161
|
+
for (const suffix of suffixes) computedRules.push({
|
|
162
|
+
condition: snapshot.condition,
|
|
163
|
+
declarations,
|
|
164
|
+
selectorSuffix: suffix
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return computedRules;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
119
171
|
* Check if a key is a CSS selector
|
|
120
172
|
*/
|
|
121
173
|
function isSelector(key) {
|
|
@@ -163,7 +215,8 @@ function getAllSelectors(key, styles) {
|
|
|
163
215
|
* Supports:
|
|
164
216
|
* - Direct child: '>'
|
|
165
217
|
* - Chained elements: '>Body>Row>'
|
|
166
|
-
* - HTML tags: '
|
|
218
|
+
* - HTML tags (no key injection): 'h1', '>ul>li', 'button:hover'
|
|
219
|
+
* - Universal selector: '*', 'h1 *'
|
|
167
220
|
* - Pseudo-elements on root: '::before'
|
|
168
221
|
* - Pseudo on sub-element: '@::before', '>@:hover'
|
|
169
222
|
* - Classes: '.active', '>@.active'
|
|
@@ -200,6 +253,7 @@ function processAffix(affix, key) {
|
|
|
200
253
|
*/
|
|
201
254
|
const VALID_TOKEN_PATTERNS = [
|
|
202
255
|
/^[>+~]/,
|
|
256
|
+
/^\*/,
|
|
203
257
|
/^[A-Z][a-zA-Z0-9]*/,
|
|
204
258
|
/^@/,
|
|
205
259
|
/^::?[a-z][a-z0-9-]*(?:\([^)]*\))?/,
|
|
@@ -334,12 +388,13 @@ function processSinglePattern(pattern, key) {
|
|
|
334
388
|
* The tokenizer handles these token types in order:
|
|
335
389
|
* 1. Whitespace (skipped)
|
|
336
390
|
* 2. Combinators: >, +, ~ (add surrounding spaces)
|
|
337
|
-
* 3.
|
|
338
|
-
* 4.
|
|
339
|
-
* 5.
|
|
340
|
-
* 6.
|
|
341
|
-
* 7.
|
|
342
|
-
* 8.
|
|
391
|
+
* 3. Universal selector: * (keep as-is with spacing)
|
|
392
|
+
* 4. Uppercase names: Body, Row (convert to [data-element="..."])
|
|
393
|
+
* 5. @ placeholder (keep for later replacement)
|
|
394
|
+
* 6. Pseudo: :hover, ::before (attach to previous token)
|
|
395
|
+
* 7. Tags: a, div, button (keep as-is with spacing)
|
|
396
|
+
* 8. Classes: .active (attach to previous element/tag/placeholder)
|
|
397
|
+
* 9. Attributes: [type="text"] (keep as-is)
|
|
343
398
|
*
|
|
344
399
|
* @param pattern - The raw selector pattern to transform
|
|
345
400
|
* @returns Transformed pattern with proper CSS selector syntax
|
|
@@ -368,6 +423,13 @@ function transformPattern(pattern) {
|
|
|
368
423
|
i++;
|
|
369
424
|
continue;
|
|
370
425
|
}
|
|
426
|
+
if (char === "*") {
|
|
427
|
+
if (result && lastCh !== " ") result += " ";
|
|
428
|
+
result += "*";
|
|
429
|
+
lastCh = "*";
|
|
430
|
+
i++;
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
371
433
|
if (/[A-Z]/.test(char)) {
|
|
372
434
|
const nameStart = i;
|
|
373
435
|
while (i < pattern.length && /[a-zA-Z0-9]/.test(pattern[i])) i++;
|
|
@@ -442,7 +504,8 @@ function transformPattern(pattern) {
|
|
|
442
504
|
* |----------------|-------------|---------|--------|
|
|
443
505
|
* | Combinator (>, +, ~) | Yes | `'>Body>'` | `> [data-element="Body"] > [el]` |
|
|
444
506
|
* | Uppercase element | Yes | `'>Body>Row'` | `> [el1] > [el2] [key]` |
|
|
445
|
-
* | Lowercase tag |
|
|
507
|
+
* | Lowercase tag | No | `'h1'` | ` h1` |
|
|
508
|
+
* | Universal (*) | No | `'h1 *'` | ` h1 *` |
|
|
446
509
|
* | Pseudo (:hover, ::before) | No | `'::before'` | `::before` |
|
|
447
510
|
* | Class (.active) | No | `'.active'` | `.active` |
|
|
448
511
|
* | Attribute ([type]) | No | `'[type="text"]'` | `[type="text"]` |
|
|
@@ -453,7 +516,8 @@ function transformPattern(pattern) {
|
|
|
453
516
|
* @example
|
|
454
517
|
* shouldInjectKey('>') // → true (trailing combinator)
|
|
455
518
|
* shouldInjectKey('>Body>Row') // → true (ends with element)
|
|
456
|
-
* shouldInjectKey('
|
|
519
|
+
* shouldInjectKey('h1') // → false (ends with tag)
|
|
520
|
+
* shouldInjectKey('*') // → false (universal selector)
|
|
457
521
|
* shouldInjectKey('::before') // → false (ends with pseudo)
|
|
458
522
|
* shouldInjectKey('.active') // → false (ends with class)
|
|
459
523
|
* shouldInjectKey('a:hover') // → false (ends with pseudo)
|
|
@@ -463,7 +527,6 @@ function shouldInjectKey(pattern) {
|
|
|
463
527
|
const trimmed = pattern.trim();
|
|
464
528
|
if (/[>+~]$/.test(trimmed)) return true;
|
|
465
529
|
if (/(?:^|[\s>+~\]:])[A-Z][a-zA-Z0-9]*$/.test(trimmed)) return true;
|
|
466
|
-
if (/(?<![:.])(?:^|[\s>+~])[a-z][a-z0-9-]*$/.test(trimmed)) return true;
|
|
467
530
|
return false;
|
|
468
531
|
}
|
|
469
532
|
/**
|
|
@@ -573,11 +636,12 @@ function mergeByValue(rules) {
|
|
|
573
636
|
*/
|
|
574
637
|
function buildSelectorFromVariant(variant, selectorSuffix) {
|
|
575
638
|
let selector = "";
|
|
576
|
-
|
|
577
|
-
for (const
|
|
639
|
+
selector += branchToCSS([...variant.modifierConditions, ...variant.pseudoConditions]);
|
|
640
|
+
for (const group of variant.selectorGroups) selector += selectorGroupToCSS(group);
|
|
578
641
|
if (variant.parentGroups.length > 0) selector += parentGroupsToCSS(variant.parentGroups);
|
|
579
642
|
selector += selectorSuffix;
|
|
580
|
-
|
|
643
|
+
const ownOptimized = optimizeGroups(variant.ownGroups);
|
|
644
|
+
for (const group of ownOptimized) selector += selectorGroupToCSS(group);
|
|
581
645
|
return selector;
|
|
582
646
|
}
|
|
583
647
|
/**
|
|
@@ -591,45 +655,68 @@ function materializeComputedRule(rule) {
|
|
|
591
655
|
if (components.isImpossible || components.variants.length === 0) return [];
|
|
592
656
|
const declarations = Object.entries(rule.declarations).map(([prop, value]) => `${prop}: ${value};`).join(" ");
|
|
593
657
|
const getRootPrefixKey = (variant) => {
|
|
594
|
-
return variant.
|
|
658
|
+
return rootGroupsToCSS(variant.rootGroups) || "";
|
|
595
659
|
};
|
|
596
660
|
const byAtRules = /* @__PURE__ */ new Map();
|
|
597
661
|
for (const variant of components.variants) {
|
|
598
662
|
const atRules = buildAtRulesFromVariant(variant);
|
|
599
|
-
const
|
|
663
|
+
const startingStyle = variant.startingStyle;
|
|
664
|
+
const key = atRules.sort().join("|||") + "###" + getRootPrefixKey(variant) + "###" + (startingStyle ? "1" : "0");
|
|
600
665
|
const group = byAtRules.get(key);
|
|
601
666
|
if (group) group.variants.push(variant);
|
|
602
667
|
else byAtRules.set(key, {
|
|
603
668
|
variants: [variant],
|
|
604
669
|
atRules,
|
|
605
|
-
rootPrefix:
|
|
670
|
+
rootPrefix: rootGroupsToCSS(variant.rootGroups),
|
|
671
|
+
startingStyle: startingStyle || void 0
|
|
606
672
|
});
|
|
607
673
|
}
|
|
608
674
|
const rules = [];
|
|
609
675
|
for (const [, group] of byAtRules) {
|
|
610
|
-
const selectorFragments = group.variants.map((v) => buildSelectorFromVariant(v, rule.selectorSuffix));
|
|
676
|
+
const selectorFragments = mergeVariantsIntoSelectorGroups(group.variants).map((v) => buildSelectorFromVariant(v, rule.selectorSuffix));
|
|
611
677
|
const cssRule = {
|
|
612
678
|
selector: selectorFragments.length === 1 ? selectorFragments[0] : selectorFragments,
|
|
613
679
|
declarations
|
|
614
680
|
};
|
|
615
681
|
if (group.atRules.length > 0) cssRule.atRules = group.atRules;
|
|
616
682
|
if (group.rootPrefix) cssRule.rootPrefix = group.rootPrefix;
|
|
683
|
+
if (group.startingStyle) cssRule.startingStyle = true;
|
|
617
684
|
rules.push(cssRule);
|
|
618
685
|
}
|
|
619
686
|
return rules;
|
|
620
687
|
}
|
|
621
|
-
|
|
688
|
+
/**
|
|
689
|
+
* Merge StyleResult entries that share the same selector and at-rules,
|
|
690
|
+
* concatenating their declarations into a single rule.
|
|
691
|
+
*
|
|
692
|
+
* This reduces CSS output size when many style keys (e.g. design tokens)
|
|
693
|
+
* resolve to the same selector/state combination.
|
|
694
|
+
*/
|
|
695
|
+
function mergeStyleResults(results) {
|
|
696
|
+
if (results.length <= 1) return results;
|
|
697
|
+
const groups = /* @__PURE__ */ new Map();
|
|
698
|
+
for (const result of results) {
|
|
699
|
+
const key = `${result.atRules?.join("|") ?? ""}||${result.selector}||${result.startingStyle ? "1" : "0"}`;
|
|
700
|
+
const existing = groups.get(key);
|
|
701
|
+
if (existing) existing.declarations = existing.declarations ? `${existing.declarations} ${result.declarations}` : result.declarations;
|
|
702
|
+
else groups.set(key, { ...result });
|
|
703
|
+
}
|
|
704
|
+
return Array.from(groups.values());
|
|
705
|
+
}
|
|
706
|
+
function renderStyles(styles, classNameOrSelector, options, pipelineCacheKey) {
|
|
622
707
|
const directSelector = !!classNameOrSelector;
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
708
|
+
let rules;
|
|
709
|
+
if (pipelineCacheKey) rules = pipelineCache.get(pipelineCacheKey);
|
|
710
|
+
if (!rules && !styles) return directSelector ? [] : { rules: [] };
|
|
711
|
+
const cacheKey = pipelineCacheKey || stringifyStyles(styles);
|
|
712
|
+
if (!rules) rules = pipelineCache.get(cacheKey);
|
|
626
713
|
if (!rules) {
|
|
627
714
|
rules = runPipeline(styles, createStateParserContext(styles));
|
|
628
715
|
pipelineCache.set(cacheKey, rules);
|
|
629
716
|
}
|
|
630
717
|
if (directSelector) {
|
|
631
718
|
const shouldDouble = options?.doubleSelector ?? false;
|
|
632
|
-
return rules.map((rule) => {
|
|
719
|
+
return mergeStyleResults(rules.map((rule) => {
|
|
633
720
|
const result = {
|
|
634
721
|
selector: (Array.isArray(rule.selector) ? rule.selector : rule.selector ? [rule.selector] : [""]).map((part) => {
|
|
635
722
|
let sel = part ? `${classNameOrSelector}${part}` : classNameOrSelector;
|
|
@@ -643,18 +730,20 @@ function renderStyles(styles, classNameOrSelector, options) {
|
|
|
643
730
|
declarations: rule.declarations
|
|
644
731
|
};
|
|
645
732
|
if (rule.atRules && rule.atRules.length > 0) result.atRules = rule.atRules;
|
|
733
|
+
if (rule.startingStyle) result.startingStyle = true;
|
|
646
734
|
return result;
|
|
647
|
-
});
|
|
735
|
+
}));
|
|
648
736
|
}
|
|
649
737
|
return { rules: rules.map((r) => ({
|
|
650
738
|
selector: Array.isArray(r.selector) ? r.selector.join("|||") : r.selector,
|
|
651
739
|
declarations: r.declarations,
|
|
652
740
|
atRules: r.atRules,
|
|
653
741
|
needsClassName: true,
|
|
654
|
-
rootPrefix: r.rootPrefix
|
|
742
|
+
rootPrefix: r.rootPrefix,
|
|
743
|
+
startingStyle: r.startingStyle
|
|
655
744
|
})) };
|
|
656
745
|
}
|
|
657
|
-
|
|
658
746
|
//#endregion
|
|
659
|
-
export { clearPipelineCache, isSelector, renderStyles };
|
|
747
|
+
export { clearPipelineCache, hasPipelineCacheEntry, isSelector, renderStyles };
|
|
748
|
+
|
|
660
749
|
//# sourceMappingURL=index.js.map
|