@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/utils/styles.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
+
import { getNamedColorHex } from "./color-math.js";
|
|
1
2
|
import { StyleParser } from "../parser/parser.js";
|
|
2
3
|
import { okhslFunc } from "../plugins/okhsl-plugin.js";
|
|
3
|
-
import { createStateParserContext, parseAdvancedState } from "../states/index.js";
|
|
4
|
-
import { cacheWrapper } from "./cache-wrapper.js";
|
|
5
|
-
import { camelToKebab } from "./case-converter.js";
|
|
6
|
-
import { okhslToRgb } from "./okhsl-to-rgb.js";
|
|
7
|
-
import { hslToRgb } from "./hsl-to-rgb.js";
|
|
8
|
-
|
|
9
4
|
//#region src/utils/styles.ts
|
|
10
5
|
/**
|
|
11
6
|
* Normalize a color token value.
|
|
@@ -22,19 +17,23 @@ function normalizeColorTokenValue(value) {
|
|
|
22
17
|
return value;
|
|
23
18
|
}
|
|
24
19
|
const COLOR_VAR_PATTERN = /var\(--([a-z0-9-]+)-color/;
|
|
25
|
-
const
|
|
20
|
+
const COLOR_VAR_COMPONENTS_PATTERN = /var\(--([a-z0-9-]+)-color-(?:rgb|hsl|oklch)/;
|
|
26
21
|
const RGB_ALPHA_PATTERN = /\/\s*([0-9.]+)\)/;
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
22
|
+
const RE_HEX_COLOR = /^#[0-9a-fA-F]{3,8}$/;
|
|
23
|
+
const RE_VAR_COLOR = /^var\(--[a-z0-9-]+-color/;
|
|
24
|
+
function isSimpleColorFast(val) {
|
|
25
|
+
switch (val.charCodeAt(0)) {
|
|
26
|
+
case 35: return RE_HEX_COLOR.test(val);
|
|
27
|
+
case 114: return val.charCodeAt(1) === 103 && val.charCodeAt(2) === 98;
|
|
28
|
+
case 104: return val.charCodeAt(1) === 115 && val.charCodeAt(2) === 108;
|
|
29
|
+
case 108: return val.charCodeAt(1) === 99 && val.charCodeAt(2) === 104;
|
|
30
|
+
case 111: return val.startsWith("oklch(") || val.startsWith("okhsl(");
|
|
31
|
+
case 118: return RE_VAR_COLOR.test(val);
|
|
32
|
+
case 99: return val === "currentColor" || val === "currentcolor";
|
|
33
|
+
case 116: return val === "transparent";
|
|
34
|
+
default: return getNamedColorHex().has(val.toLowerCase());
|
|
35
|
+
}
|
|
36
|
+
}
|
|
38
37
|
let colorWarningCount = 0;
|
|
39
38
|
const MAX_COLOR_WARNINGS = 10;
|
|
40
39
|
const CUSTOM_UNITS = {
|
|
@@ -43,8 +42,6 @@ const CUSTOM_UNITS = {
|
|
|
43
42
|
bw: "1px",
|
|
44
43
|
ow: "3px",
|
|
45
44
|
x: "8px",
|
|
46
|
-
fs: "var(--font-size)",
|
|
47
|
-
lh: "var(--line-height)",
|
|
48
45
|
sf: function sf(num) {
|
|
49
46
|
return `minmax(0, ${num}fr)`;
|
|
50
47
|
}
|
|
@@ -55,27 +52,6 @@ const DIRECTIONS = [
|
|
|
55
52
|
"bottom",
|
|
56
53
|
"left"
|
|
57
54
|
];
|
|
58
|
-
const MOD_NAME_CACHE = /* @__PURE__ */ new Map();
|
|
59
|
-
function getModSelector(modName) {
|
|
60
|
-
if (!MOD_NAME_CACHE.has(modName)) {
|
|
61
|
-
let selector;
|
|
62
|
-
const valueModMatch = modName.match(/^([a-z][a-z0-9-]*)(\^=|\$=|\*=|=)(.+)$/i);
|
|
63
|
-
if (valueModMatch) {
|
|
64
|
-
const key = valueModMatch[1];
|
|
65
|
-
const operator = valueModMatch[2];
|
|
66
|
-
let value = valueModMatch[3];
|
|
67
|
-
if (value.startsWith("\"") && value.endsWith("\"") || value.startsWith("'") && value.endsWith("'")) value = value.slice(1, -1);
|
|
68
|
-
selector = `[data-${camelToKebab(key)}${operator}"${value}"]`;
|
|
69
|
-
} else if (modName.match(/^[a-z]/)) selector = `[data-${camelToKebab(modName)}]`;
|
|
70
|
-
else if (modName.includes(":has(")) selector = modName.replace(/:has\(([^)]+)\)/g, (match, content) => {
|
|
71
|
-
if (/[A-Z][a-z]*[>+~]|[>+~][A-Z][a-z]*/.test(content)) console.error(`[Tasty] Invalid :has() selector syntax: "${modName}"\nCombinators (>, +, ~) must have spaces around them when used with element names.\nExample: Use ":has(Body > Row)" instead of ":has(Body>Row)"\nThis is a design choice: the parser uses simple whitespace splitting for performance.`);
|
|
72
|
-
return `:has(${content.split(/\s+/).map((token) => /^[A-Z]/.test(token) ? `[data-element="${token}"]` : token).join(" ")})`;
|
|
73
|
-
});
|
|
74
|
-
else selector = modName;
|
|
75
|
-
MOD_NAME_CACHE.set(modName, selector);
|
|
76
|
-
}
|
|
77
|
-
return MOD_NAME_CACHE.get(modName);
|
|
78
|
-
}
|
|
79
55
|
let __tastyParser = null;
|
|
80
56
|
function getOrCreateParser() {
|
|
81
57
|
if (!__tastyParser) {
|
|
@@ -169,23 +145,23 @@ function parseColor(val, ignoreError = false) {
|
|
|
169
145
|
if (typeof val !== "string") val = String(val ?? "");
|
|
170
146
|
val = val.trim();
|
|
171
147
|
if (!val) return {};
|
|
172
|
-
const isSimpleColor =
|
|
148
|
+
const isSimpleColor = isSimpleColorFast(val);
|
|
173
149
|
let firstColor;
|
|
174
150
|
if (isSimpleColor) firstColor = val;
|
|
175
151
|
else {
|
|
176
152
|
const extractedColor = parseStyle(val).groups.find((g) => g.colors.length)?.colors[0];
|
|
177
153
|
if (!extractedColor) {
|
|
178
154
|
if (!ignoreError && colorWarningCount < MAX_COLOR_WARNINGS) {
|
|
179
|
-
console.warn("
|
|
155
|
+
console.warn("Tasty: unable to parse color:", val);
|
|
180
156
|
colorWarningCount++;
|
|
181
|
-
if (colorWarningCount === MAX_COLOR_WARNINGS) console.warn("
|
|
157
|
+
if (colorWarningCount === MAX_COLOR_WARNINGS) console.warn("Tasty: color parsing warnings will be suppressed from now on");
|
|
182
158
|
}
|
|
183
159
|
return {};
|
|
184
160
|
}
|
|
185
161
|
firstColor = extractedColor;
|
|
186
162
|
}
|
|
187
163
|
let nameMatch = firstColor.match(COLOR_VAR_PATTERN);
|
|
188
|
-
if (!nameMatch) nameMatch = firstColor.match(
|
|
164
|
+
if (!nameMatch) nameMatch = firstColor.match(COLOR_VAR_COMPONENTS_PATTERN);
|
|
189
165
|
let opacity;
|
|
190
166
|
if (firstColor.startsWith("rgb") || firstColor.startsWith("hsl") || firstColor.startsWith("lch") || firstColor.startsWith("oklch") || firstColor.startsWith("okhsl")) {
|
|
191
167
|
const alphaMatch = firstColor.match(RGB_ALPHA_PATTERN);
|
|
@@ -200,524 +176,15 @@ function parseColor(val, ignoreError = false) {
|
|
|
200
176
|
opacity
|
|
201
177
|
};
|
|
202
178
|
}
|
|
203
|
-
/**
|
|
204
|
-
* CSS named color keywords → hex values.
|
|
205
|
-
* Lazy-initialized on first use to avoid up-front cost.
|
|
206
|
-
*/
|
|
207
|
-
let _namedColorHex = null;
|
|
208
|
-
function getNamedColorHex() {
|
|
209
|
-
if (_namedColorHex) return _namedColorHex;
|
|
210
|
-
_namedColorHex = new Map([
|
|
211
|
-
["aliceblue", "#f0f8ff"],
|
|
212
|
-
["antiquewhite", "#faebd7"],
|
|
213
|
-
["aqua", "#00ffff"],
|
|
214
|
-
["aquamarine", "#7fffd4"],
|
|
215
|
-
["azure", "#f0ffff"],
|
|
216
|
-
["beige", "#f5f5dc"],
|
|
217
|
-
["bisque", "#ffe4c4"],
|
|
218
|
-
["black", "#000000"],
|
|
219
|
-
["blanchedalmond", "#ffebcd"],
|
|
220
|
-
["blue", "#0000ff"],
|
|
221
|
-
["blueviolet", "#8a2be2"],
|
|
222
|
-
["brown", "#a52a2a"],
|
|
223
|
-
["burlywood", "#deb887"],
|
|
224
|
-
["cadetblue", "#5f9ea0"],
|
|
225
|
-
["chartreuse", "#7fff00"],
|
|
226
|
-
["chocolate", "#d2691e"],
|
|
227
|
-
["coral", "#ff7f50"],
|
|
228
|
-
["cornflowerblue", "#6495ed"],
|
|
229
|
-
["cornsilk", "#fff8dc"],
|
|
230
|
-
["crimson", "#dc143c"],
|
|
231
|
-
["cyan", "#00ffff"],
|
|
232
|
-
["darkblue", "#00008b"],
|
|
233
|
-
["darkcyan", "#008b8b"],
|
|
234
|
-
["darkgoldenrod", "#b8860b"],
|
|
235
|
-
["darkgray", "#a9a9a9"],
|
|
236
|
-
["darkgreen", "#006400"],
|
|
237
|
-
["darkgrey", "#a9a9a9"],
|
|
238
|
-
["darkkhaki", "#bdb76b"],
|
|
239
|
-
["darkmagenta", "#8b008b"],
|
|
240
|
-
["darkolivegreen", "#556b2f"],
|
|
241
|
-
["darkorange", "#ff8c00"],
|
|
242
|
-
["darkorchid", "#9932cc"],
|
|
243
|
-
["darkred", "#8b0000"],
|
|
244
|
-
["darksalmon", "#e9967a"],
|
|
245
|
-
["darkseagreen", "#8fbc8f"],
|
|
246
|
-
["darkslateblue", "#483d8b"],
|
|
247
|
-
["darkslategray", "#2f4f4f"],
|
|
248
|
-
["darkslategrey", "#2f4f4f"],
|
|
249
|
-
["darkturquoise", "#00ced1"],
|
|
250
|
-
["darkviolet", "#9400d3"],
|
|
251
|
-
["deeppink", "#ff1493"],
|
|
252
|
-
["deepskyblue", "#00bfff"],
|
|
253
|
-
["dimgray", "#696969"],
|
|
254
|
-
["dimgrey", "#696969"],
|
|
255
|
-
["dodgerblue", "#1e90ff"],
|
|
256
|
-
["firebrick", "#b22222"],
|
|
257
|
-
["floralwhite", "#fffaf0"],
|
|
258
|
-
["forestgreen", "#228b22"],
|
|
259
|
-
["fuchsia", "#ff00ff"],
|
|
260
|
-
["gainsboro", "#dcdcdc"],
|
|
261
|
-
["ghostwhite", "#f8f8ff"],
|
|
262
|
-
["gold", "#ffd700"],
|
|
263
|
-
["goldenrod", "#daa520"],
|
|
264
|
-
["gray", "#808080"],
|
|
265
|
-
["green", "#008000"],
|
|
266
|
-
["greenyellow", "#adff2f"],
|
|
267
|
-
["grey", "#808080"],
|
|
268
|
-
["honeydew", "#f0fff0"],
|
|
269
|
-
["hotpink", "#ff69b4"],
|
|
270
|
-
["indianred", "#cd5c5c"],
|
|
271
|
-
["indigo", "#4b0082"],
|
|
272
|
-
["ivory", "#fffff0"],
|
|
273
|
-
["khaki", "#f0e68c"],
|
|
274
|
-
["lavender", "#e6e6fa"],
|
|
275
|
-
["lavenderblush", "#fff0f5"],
|
|
276
|
-
["lawngreen", "#7cfc00"],
|
|
277
|
-
["lemonchiffon", "#fffacd"],
|
|
278
|
-
["lightblue", "#add8e6"],
|
|
279
|
-
["lightcoral", "#f08080"],
|
|
280
|
-
["lightcyan", "#e0ffff"],
|
|
281
|
-
["lightgoldenrodyellow", "#fafad2"],
|
|
282
|
-
["lightgray", "#d3d3d3"],
|
|
283
|
-
["lightgreen", "#90ee90"],
|
|
284
|
-
["lightgrey", "#d3d3d3"],
|
|
285
|
-
["lightpink", "#ffb6c1"],
|
|
286
|
-
["lightsalmon", "#ffa07a"],
|
|
287
|
-
["lightseagreen", "#20b2aa"],
|
|
288
|
-
["lightskyblue", "#87cefa"],
|
|
289
|
-
["lightslategray", "#778899"],
|
|
290
|
-
["lightslategrey", "#778899"],
|
|
291
|
-
["lightsteelblue", "#b0c4de"],
|
|
292
|
-
["lightyellow", "#ffffe0"],
|
|
293
|
-
["lime", "#00ff00"],
|
|
294
|
-
["limegreen", "#32cd32"],
|
|
295
|
-
["linen", "#faf0e6"],
|
|
296
|
-
["magenta", "#ff00ff"],
|
|
297
|
-
["maroon", "#800000"],
|
|
298
|
-
["mediumaquamarine", "#66cdaa"],
|
|
299
|
-
["mediumblue", "#0000cd"],
|
|
300
|
-
["mediumorchid", "#ba55d3"],
|
|
301
|
-
["mediumpurple", "#9370db"],
|
|
302
|
-
["mediumseagreen", "#3cb371"],
|
|
303
|
-
["mediumslateblue", "#7b68ee"],
|
|
304
|
-
["mediumspringgreen", "#00fa9a"],
|
|
305
|
-
["mediumturquoise", "#48d1cc"],
|
|
306
|
-
["mediumvioletred", "#c71585"],
|
|
307
|
-
["midnightblue", "#191970"],
|
|
308
|
-
["mintcream", "#f5fffa"],
|
|
309
|
-
["mistyrose", "#ffe4e1"],
|
|
310
|
-
["moccasin", "#ffe4b5"],
|
|
311
|
-
["navajowhite", "#ffdead"],
|
|
312
|
-
["navy", "#000080"],
|
|
313
|
-
["oldlace", "#fdf5e6"],
|
|
314
|
-
["olive", "#808000"],
|
|
315
|
-
["olivedrab", "#6b8e23"],
|
|
316
|
-
["orange", "#ffa500"],
|
|
317
|
-
["orangered", "#ff4500"],
|
|
318
|
-
["orchid", "#da70d6"],
|
|
319
|
-
["palegoldenrod", "#eee8aa"],
|
|
320
|
-
["palegreen", "#98fb98"],
|
|
321
|
-
["paleturquoise", "#afeeee"],
|
|
322
|
-
["palevioletred", "#db7093"],
|
|
323
|
-
["papayawhip", "#ffefd5"],
|
|
324
|
-
["peachpuff", "#ffdab9"],
|
|
325
|
-
["peru", "#cd853f"],
|
|
326
|
-
["pink", "#ffc0cb"],
|
|
327
|
-
["plum", "#dda0dd"],
|
|
328
|
-
["powderblue", "#b0e0e6"],
|
|
329
|
-
["purple", "#800080"],
|
|
330
|
-
["rebeccapurple", "#663399"],
|
|
331
|
-
["red", "#ff0000"],
|
|
332
|
-
["rosybrown", "#bc8f8f"],
|
|
333
|
-
["royalblue", "#4169e1"],
|
|
334
|
-
["saddlebrown", "#8b4513"],
|
|
335
|
-
["salmon", "#fa8072"],
|
|
336
|
-
["sandybrown", "#f4a460"],
|
|
337
|
-
["seagreen", "#2e8b57"],
|
|
338
|
-
["seashell", "#fff5ee"],
|
|
339
|
-
["sienna", "#a0522d"],
|
|
340
|
-
["silver", "#c0c0c0"],
|
|
341
|
-
["skyblue", "#87ceeb"],
|
|
342
|
-
["slateblue", "#6a5acd"],
|
|
343
|
-
["slategray", "#708090"],
|
|
344
|
-
["slategrey", "#708090"],
|
|
345
|
-
["snow", "#fffafa"],
|
|
346
|
-
["springgreen", "#00ff7f"],
|
|
347
|
-
["steelblue", "#4682b4"],
|
|
348
|
-
["tan", "#d2b48c"],
|
|
349
|
-
["teal", "#008080"],
|
|
350
|
-
["thistle", "#d8bfd8"],
|
|
351
|
-
["tomato", "#ff6347"],
|
|
352
|
-
["turquoise", "#40e0d0"],
|
|
353
|
-
["violet", "#ee82ee"],
|
|
354
|
-
["wheat", "#f5deb3"],
|
|
355
|
-
["white", "#ffffff"],
|
|
356
|
-
["whitesmoke", "#f5f5f5"],
|
|
357
|
-
["yellow", "#ffff00"],
|
|
358
|
-
["yellowgreen", "#9acd32"]
|
|
359
|
-
]);
|
|
360
|
-
return _namedColorHex;
|
|
361
|
-
}
|
|
362
|
-
function strToRgb(color, _ignoreAlpha = false) {
|
|
363
|
-
if (!color) return void 0;
|
|
364
|
-
if (color.startsWith("rgb")) return color;
|
|
365
|
-
if (color.startsWith("#")) return hexToRgb(color);
|
|
366
|
-
if (color.startsWith("okhsl(")) return okhslToRgb(color);
|
|
367
|
-
if (color.startsWith("hsl")) return hslToRgb(color);
|
|
368
|
-
const namedHex = getNamedColorHex().get(color.toLowerCase());
|
|
369
|
-
if (namedHex) return hexToRgb(namedHex);
|
|
370
|
-
return null;
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* Extract RGB values from an rgb()/rgba() string.
|
|
374
|
-
* Supports all modern CSS syntax variations:
|
|
375
|
-
* - Comma-separated: rgb(255, 128, 0)
|
|
376
|
-
* - Space-separated: rgb(255 128 0)
|
|
377
|
-
* - Fractional: rgb(128.5, 64.3, 32.1)
|
|
378
|
-
* - Percentages: rgb(50%, 25%, 75%)
|
|
379
|
-
* - Slash alpha notation: rgb(255 128 0 / 0.5)
|
|
380
|
-
*
|
|
381
|
-
* Returns array of RGB values (0-255 range), converting percentages as needed.
|
|
382
|
-
*/
|
|
383
|
-
function getRgbValuesFromRgbaString(str) {
|
|
384
|
-
const match = str.match(/rgba?\(([^)]+)\)/i);
|
|
385
|
-
if (!match) return [];
|
|
386
|
-
const [colorPart] = match[1].trim().split("/");
|
|
387
|
-
return colorPart.trim().split(/[,\s]+/).filter(Boolean).slice(0, 3).map((part) => {
|
|
388
|
-
part = part.trim();
|
|
389
|
-
if (part.endsWith("%")) return parseFloat(part) / 100 * 255;
|
|
390
|
-
return parseFloat(part);
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
function hexToRgb(hex) {
|
|
394
|
-
const matched = hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (_m, r, g, b) => "#" + r + r + g + g + b + b).substring(1).match(/.{2}/g);
|
|
395
|
-
if (!matched) return null;
|
|
396
|
-
const rgba = matched.map((x, i) => parseInt(x, 16) * (i === 3 ? 1 / 255 : 1));
|
|
397
|
-
if (rgba.some((v) => Number.isNaN(v))) return null;
|
|
398
|
-
if (rgba.length >= 3) return `rgb(${rgba.slice(0, 3).join(" ")}${rgba.length > 3 ? ` / ${rgba[3]}` : ""})`;
|
|
399
|
-
return null;
|
|
400
|
-
}
|
|
401
179
|
function filterMods(mods, allowedMods) {
|
|
402
180
|
return mods.filter((mod) => allowedMods.includes(mod));
|
|
403
181
|
}
|
|
404
|
-
function extendStyles(defaultStyles, newStyles) {
|
|
405
|
-
let styles = {};
|
|
406
|
-
if (!defaultStyles) {
|
|
407
|
-
if (!newStyles) return styles;
|
|
408
|
-
} else styles = Object.assign({}, defaultStyles);
|
|
409
|
-
if (newStyles) Object.keys(newStyles).forEach((key) => {
|
|
410
|
-
if (newStyles[key] != null) styles[key] = newStyles[key];
|
|
411
|
-
});
|
|
412
|
-
return styles;
|
|
413
|
-
}
|
|
414
|
-
/**
|
|
415
|
-
* Split properties into style and non-style properties.
|
|
416
|
-
* @param props - Component prop map.
|
|
417
|
-
* @param [styleList] - List of all style properties.
|
|
418
|
-
* @param [defaultStyles] - Default style map of the component.
|
|
419
|
-
* @param [propMap] - Props to style alias map.
|
|
420
|
-
* @param [ignoreList] - A list of properties to ignore.
|
|
421
|
-
*/
|
|
422
|
-
function extractStyles(props, styleList = [], defaultStyles, propMap, ignoreList = []) {
|
|
423
|
-
const styles = {
|
|
424
|
-
...defaultStyles,
|
|
425
|
-
...ignoreList.includes("styles") ? void 0 : props.styles && typeof props.styles === "object" ? props.styles : void 0
|
|
426
|
-
};
|
|
427
|
-
Object.keys(props).forEach((prop) => {
|
|
428
|
-
const propName = propMap ? propMap[prop] || prop : prop;
|
|
429
|
-
const value = props[prop];
|
|
430
|
-
if (ignoreList && ignoreList.includes(prop)) {} else if (styleList.includes(propName)) styles[propName] = value;
|
|
431
|
-
}, {});
|
|
432
|
-
return styles;
|
|
433
|
-
}
|
|
434
|
-
const STATES_REGEXP = /([&|!^])|([()])|(@media:[a-z]+)|(@media\([^)]+\))|(@root\([^)]+\))|(@own\([^)]+\))|(@\([^)]+\))|(@starting)|(@[A-Za-z][A-Za-z0-9-]*)|([a-z][a-z0-9-]+=(?:"[^"]*"|'[^']*'|[^\s&|!^()]+))|([a-z][a-z0-9-]+)|(:[a-z][a-z0-9-]+\([^)]+\)|:[a-z][a-z0-9-]+)|(\.[a-z][a-z0-9-]+)|(\[[^\]]+])/gi;
|
|
435
|
-
/**
|
|
436
|
-
* Check if a token is an advanced state (starts with @)
|
|
437
|
-
*/
|
|
438
|
-
function isAdvancedStateToken(token) {
|
|
439
|
-
return token.startsWith("@") || token.startsWith("!@");
|
|
440
|
-
}
|
|
441
|
-
const STATE_OPERATORS = {
|
|
442
|
-
NOT: "!",
|
|
443
|
-
AND: "&",
|
|
444
|
-
OR: "|",
|
|
445
|
-
XOR: "^"
|
|
446
|
-
};
|
|
447
|
-
const STATE_OPERATOR_LIST = [
|
|
448
|
-
"!",
|
|
449
|
-
"&",
|
|
450
|
-
"|",
|
|
451
|
-
"^"
|
|
452
|
-
];
|
|
453
|
-
/**
|
|
454
|
-
* Convert state notation tokens to a compute model (string, or nested [op, lhs, rhs]).
|
|
455
|
-
*/
|
|
456
|
-
function convertTokensToComputeUnits(tokens) {
|
|
457
|
-
if (tokens.length === 1) return tokens[0];
|
|
458
|
-
const hasLength = (x) => typeof x === "string" || Array.isArray(x);
|
|
459
|
-
STATE_OPERATOR_LIST.forEach((operator) => {
|
|
460
|
-
let i;
|
|
461
|
-
while ((i = tokens.indexOf(operator)) !== -1) {
|
|
462
|
-
const token = tokens[i];
|
|
463
|
-
if (token === "!") {
|
|
464
|
-
const next = tokens[i + 1];
|
|
465
|
-
if (next !== void 0 && hasLength(next) && next.length !== 1) tokens.splice(i, 2, ["!", next]);
|
|
466
|
-
else tokens.splice(i, 1);
|
|
467
|
-
} else {
|
|
468
|
-
const prev = tokens[i - 1];
|
|
469
|
-
const next = tokens[i + 1];
|
|
470
|
-
if (prev !== void 0 && next !== void 0 && hasLength(prev) && hasLength(next) && prev.length !== 1 && next.length !== 1) tokens.splice(i - 1, 3, [
|
|
471
|
-
token,
|
|
472
|
-
prev,
|
|
473
|
-
next
|
|
474
|
-
]);
|
|
475
|
-
else tokens.splice(i, 1);
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
});
|
|
479
|
-
return tokens.length === 1 ? tokens[0] : tokens;
|
|
480
|
-
}
|
|
481
|
-
/**
|
|
482
|
-
* Replace commas with | only outside of parentheses.
|
|
483
|
-
* This preserves commas in advanced states like @(card, w < 600px)
|
|
484
|
-
*/
|
|
485
|
-
function replaceCommasOutsideParens(str) {
|
|
486
|
-
let result = "";
|
|
487
|
-
let depth = 0;
|
|
488
|
-
for (const char of str) if (char === "(") {
|
|
489
|
-
depth++;
|
|
490
|
-
result += char;
|
|
491
|
-
} else if (char === ")") {
|
|
492
|
-
depth--;
|
|
493
|
-
result += char;
|
|
494
|
-
} else if (char === "," && depth === 0) result += "|";
|
|
495
|
-
else result += char;
|
|
496
|
-
return result;
|
|
497
|
-
}
|
|
498
|
-
/**
|
|
499
|
-
* Parse state notation and return tokens, modifiers and compute model.
|
|
500
|
-
*/
|
|
501
|
-
function parseStateNotationInner(notation, value) {
|
|
502
|
-
const tokens = replaceCommasOutsideParens(notation).match(STATES_REGEXP);
|
|
503
|
-
if (!tokens || !tokens.length) return {
|
|
504
|
-
model: void 0,
|
|
505
|
-
mods: [],
|
|
506
|
-
notMods: [],
|
|
507
|
-
tokens: [],
|
|
508
|
-
value
|
|
509
|
-
};
|
|
510
|
-
else if (tokens.length === 1) return {
|
|
511
|
-
model: tokens[0],
|
|
512
|
-
mods: tokens.slice(0),
|
|
513
|
-
notMods: [],
|
|
514
|
-
tokens,
|
|
515
|
-
value
|
|
516
|
-
};
|
|
517
|
-
const mods = [];
|
|
518
|
-
const operations = [[]];
|
|
519
|
-
let list = operations[0];
|
|
520
|
-
let position = 0;
|
|
521
|
-
let operation;
|
|
522
|
-
tokens.forEach((token) => {
|
|
523
|
-
switch (token) {
|
|
524
|
-
case "(":
|
|
525
|
-
operation = [];
|
|
526
|
-
position++;
|
|
527
|
-
list = operations[position] = operation;
|
|
528
|
-
break;
|
|
529
|
-
case ")":
|
|
530
|
-
position--;
|
|
531
|
-
operations[position].push(convertTokensToComputeUnits(list));
|
|
532
|
-
list = operations[position];
|
|
533
|
-
break;
|
|
534
|
-
default:
|
|
535
|
-
if (token.length > 1) {
|
|
536
|
-
if (!mods.includes(token)) mods.push(token);
|
|
537
|
-
}
|
|
538
|
-
list.push(token);
|
|
539
|
-
}
|
|
540
|
-
});
|
|
541
|
-
while (position) {
|
|
542
|
-
position--;
|
|
543
|
-
operations[position].push(convertTokensToComputeUnits(list));
|
|
544
|
-
list = operations[position];
|
|
545
|
-
}
|
|
546
|
-
return {
|
|
547
|
-
tokens,
|
|
548
|
-
mods,
|
|
549
|
-
notMods: [],
|
|
550
|
-
model: convertTokensToComputeUnits(operations[0]),
|
|
551
|
-
value
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
const parseStateNotation = cacheWrapper(parseStateNotationInner);
|
|
555
|
-
/**
|
|
556
|
-
* Build an AtRuleContext from parsed advanced states
|
|
557
|
-
*/
|
|
558
|
-
function buildAtRuleContext(advancedStates, negatedStates) {
|
|
559
|
-
if (advancedStates.length === 0) return void 0;
|
|
560
|
-
const ctx = {};
|
|
561
|
-
for (const state of advancedStates) {
|
|
562
|
-
const isNegated = negatedStates.has(state.raw);
|
|
563
|
-
switch (state.type) {
|
|
564
|
-
case "media": {
|
|
565
|
-
if (!ctx.media) ctx.media = [];
|
|
566
|
-
let mediaCondition = "";
|
|
567
|
-
if (state.mediaType) mediaCondition = state.mediaType;
|
|
568
|
-
else if (state.condition) mediaCondition = `(${state.condition})`;
|
|
569
|
-
if (mediaCondition) if (isNegated) ctx.media.push(`not ${mediaCondition}`);
|
|
570
|
-
else ctx.media.push(mediaCondition);
|
|
571
|
-
break;
|
|
572
|
-
}
|
|
573
|
-
case "container": {
|
|
574
|
-
if (!ctx.container) ctx.container = [];
|
|
575
|
-
let condition = state.condition;
|
|
576
|
-
if (isNegated) condition = `not (${condition})`;
|
|
577
|
-
ctx.container.push({
|
|
578
|
-
name: state.containerName,
|
|
579
|
-
condition
|
|
580
|
-
});
|
|
581
|
-
break;
|
|
582
|
-
}
|
|
583
|
-
case "root": {
|
|
584
|
-
if (!ctx.rootStates) ctx.rootStates = [];
|
|
585
|
-
const rootSelector = buildRootSelector(state.condition, isNegated);
|
|
586
|
-
ctx.rootStates.push(rootSelector);
|
|
587
|
-
break;
|
|
588
|
-
}
|
|
589
|
-
case "starting":
|
|
590
|
-
if (!isNegated) ctx.startingStyle = true;
|
|
591
|
-
break;
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
if (!ctx.media?.length && !ctx.container?.length && !ctx.rootStates?.length && !ctx.startingStyle) return;
|
|
595
|
-
return ctx;
|
|
596
|
-
}
|
|
597
|
-
/**
|
|
598
|
-
* Build a root state selector from a condition
|
|
599
|
-
*/
|
|
600
|
-
function buildRootSelector(condition, isNegated) {
|
|
601
|
-
let selector;
|
|
602
|
-
if (condition.startsWith(".")) selector = condition;
|
|
603
|
-
else if (condition.startsWith("[")) selector = condition;
|
|
604
|
-
else if (condition.includes("=")) {
|
|
605
|
-
const [key, value] = condition.split("=");
|
|
606
|
-
selector = `[data-${camelToKebab(key.trim())}="${value.trim()}"]`;
|
|
607
|
-
} else selector = `[data-${camelToKebab(condition)}]`;
|
|
608
|
-
if (isNegated) return `:not(${selector})`;
|
|
609
|
-
return selector;
|
|
610
|
-
}
|
|
611
|
-
/**
|
|
612
|
-
* Parse state notation and return tokens, modifiers and compute model.
|
|
613
|
-
* Enhanced to detect and extract advanced states.
|
|
614
|
-
*/
|
|
615
|
-
function styleStateMapToStyleStateDataList(styleStateMap, parserContext) {
|
|
616
|
-
if (typeof styleStateMap !== "object" || !styleStateMap) return {
|
|
617
|
-
states: [{
|
|
618
|
-
model: void 0,
|
|
619
|
-
mods: [],
|
|
620
|
-
notMods: [],
|
|
621
|
-
value: styleStateMap
|
|
622
|
-
}],
|
|
623
|
-
mods: [],
|
|
624
|
-
hasAdvancedStates: false
|
|
625
|
-
};
|
|
626
|
-
const stateDataList = [];
|
|
627
|
-
let hasAdvancedStates = false;
|
|
628
|
-
Object.keys(styleStateMap).forEach((stateNotation) => {
|
|
629
|
-
const state = parseStateNotation(stateNotation, styleStateMap[stateNotation]);
|
|
630
|
-
const advancedStates = [];
|
|
631
|
-
const negatedAdvancedStates = /* @__PURE__ */ new Set();
|
|
632
|
-
const regularMods = [];
|
|
633
|
-
const ownMods = [];
|
|
634
|
-
const negatedOwnMods = [];
|
|
635
|
-
if (state.tokens) {
|
|
636
|
-
let isNegated = false;
|
|
637
|
-
for (const token of state.tokens) {
|
|
638
|
-
if (token === "!") {
|
|
639
|
-
isNegated = true;
|
|
640
|
-
continue;
|
|
641
|
-
}
|
|
642
|
-
if (isAdvancedStateToken(token)) {
|
|
643
|
-
hasAdvancedStates = true;
|
|
644
|
-
const parsed = parseAdvancedState(token, parserContext || createStateParserContext(void 0));
|
|
645
|
-
advancedStates.push(parsed);
|
|
646
|
-
if (parsed.type === "own" && parsed.condition) if (isNegated) negatedOwnMods.push(parsed.condition);
|
|
647
|
-
else ownMods.push(parsed.condition);
|
|
648
|
-
else if (isNegated) negatedAdvancedStates.add(token);
|
|
649
|
-
isNegated = false;
|
|
650
|
-
} else if (token.length > 1 && ![
|
|
651
|
-
"&",
|
|
652
|
-
"|",
|
|
653
|
-
"^",
|
|
654
|
-
"(",
|
|
655
|
-
")"
|
|
656
|
-
].includes(token)) {
|
|
657
|
-
regularMods.push(token);
|
|
658
|
-
isNegated = false;
|
|
659
|
-
} else isNegated = false;
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
if (advancedStates.length > 0) {
|
|
663
|
-
state.advancedStates = advancedStates;
|
|
664
|
-
state.atRuleContext = buildAtRuleContext(advancedStates, negatedAdvancedStates);
|
|
665
|
-
state.mods = regularMods;
|
|
666
|
-
}
|
|
667
|
-
if (ownMods.length > 0) state.ownMods = ownMods;
|
|
668
|
-
if (negatedOwnMods.length > 0) state.negatedOwnMods = negatedOwnMods;
|
|
669
|
-
stateDataList.push(state);
|
|
670
|
-
});
|
|
671
|
-
stateDataList.reverse();
|
|
672
|
-
let initialState;
|
|
673
|
-
const allMods = stateDataList.reduce((all, state) => {
|
|
674
|
-
if (!state.mods.length && !state.advancedStates?.length) initialState = state;
|
|
675
|
-
else state.mods.forEach((mod) => {
|
|
676
|
-
if (!all.includes(mod)) all.push(mod);
|
|
677
|
-
});
|
|
678
|
-
return all;
|
|
679
|
-
}, []);
|
|
680
|
-
if (!initialState) stateDataList.push({
|
|
681
|
-
mods: [],
|
|
682
|
-
notMods: allMods,
|
|
683
|
-
value: true
|
|
684
|
-
});
|
|
685
|
-
return {
|
|
686
|
-
states: stateDataList,
|
|
687
|
-
mods: allMods,
|
|
688
|
-
hasAdvancedStates
|
|
689
|
-
};
|
|
690
|
-
}
|
|
691
|
-
const COMPUTE_FUNC_MAP = {
|
|
692
|
-
"!": (a) => !a,
|
|
693
|
-
"^": (a, b) => a && !b || !a && b,
|
|
694
|
-
"|": (a, b) => a || b,
|
|
695
|
-
"&": (a, b) => a && b
|
|
696
|
-
};
|
|
697
|
-
/**
|
|
698
|
-
* Compute a result based on a model and incoming map.
|
|
699
|
-
*/
|
|
700
|
-
function computeState(computeModel, valueMap) {
|
|
701
|
-
if (!computeModel) return true;
|
|
702
|
-
const map = valueMap;
|
|
703
|
-
if (!Array.isArray(computeModel)) if (typeof valueMap === "function") return !!valueMap(computeModel);
|
|
704
|
-
else return !!map[computeModel];
|
|
705
|
-
const func = COMPUTE_FUNC_MAP[computeModel[0]];
|
|
706
|
-
if (!func) console.warn("CubeUIKit: unexpected compute method in the model", computeModel);
|
|
707
|
-
let a = computeModel[1];
|
|
708
|
-
if (typeof a === "object") a = !!computeState(a, valueMap);
|
|
709
|
-
else if (typeof valueMap === "function") a = !!valueMap(a);
|
|
710
|
-
else a = !!map[a];
|
|
711
|
-
if (computeModel.length === 2) return func(a);
|
|
712
|
-
let b = computeModel[2];
|
|
713
|
-
if (typeof b === "object") b = !!computeState(b, valueMap);
|
|
714
|
-
else if (typeof valueMap === "function") b = !!valueMap(b);
|
|
715
|
-
else b = !!map[b];
|
|
716
|
-
return !!func(a, b);
|
|
717
|
-
}
|
|
718
182
|
const _innerCache = /* @__PURE__ */ new WeakMap();
|
|
183
|
+
const _topLevelCache = /* @__PURE__ */ new WeakMap();
|
|
719
184
|
function stringifyStyles(styles) {
|
|
720
185
|
if (styles == null || typeof styles !== "object") return "";
|
|
186
|
+
const cached = _topLevelCache.get(styles);
|
|
187
|
+
if (cached !== void 0) return cached;
|
|
721
188
|
const obj = styles;
|
|
722
189
|
const keys = Object.keys(obj).sort();
|
|
723
190
|
const parts = [];
|
|
@@ -743,9 +210,11 @@ function stringifyStyles(styles) {
|
|
|
743
210
|
} else sv = JSON.stringify(v);
|
|
744
211
|
parts.push(JSON.stringify(k) + ":" + sv);
|
|
745
212
|
}
|
|
746
|
-
|
|
213
|
+
const result = "{" + parts.join(",") + "}";
|
|
214
|
+
_topLevelCache.set(styles, result);
|
|
215
|
+
return result;
|
|
747
216
|
}
|
|
748
|
-
|
|
749
217
|
//#endregion
|
|
750
|
-
export {
|
|
218
|
+
export { CUSTOM_UNITS, DIRECTIONS, customFunc, filterMods, getGlobalFuncs, getGlobalParser, getGlobalPredefinedTokens, normalizeColorTokenValue, parseColor, parseStyle, resetGlobalPredefinedTokens, setGlobalPredefinedTokens, stringifyStyles };
|
|
219
|
+
|
|
751
220
|
//# sourceMappingURL=styles.js.map
|