@tenphi/tasty 0.1.0
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/LICENSE +21 -0
- package/README.md +236 -0
- package/dist/_virtual/_rolldown/runtime.mjs +7 -0
- package/dist/chunks/cacheKey.d.ts +1 -0
- package/dist/chunks/cacheKey.js +70 -0
- package/dist/chunks/cacheKey.js.map +1 -0
- package/dist/chunks/cacheKey.mjs +70 -0
- package/dist/chunks/cacheKey.mjs.map +1 -0
- package/dist/chunks/definitions.d.ts +37 -0
- package/dist/chunks/definitions.js +260 -0
- package/dist/chunks/definitions.js.map +1 -0
- package/dist/chunks/definitions.mjs +260 -0
- package/dist/chunks/definitions.mjs.map +1 -0
- package/dist/chunks/index.d.ts +3 -0
- package/dist/chunks/renderChunk.d.ts +2 -0
- package/dist/chunks/renderChunk.js +61 -0
- package/dist/chunks/renderChunk.js.map +1 -0
- package/dist/chunks/renderChunk.mjs +61 -0
- package/dist/chunks/renderChunk.mjs.map +1 -0
- package/dist/config.d.ts +279 -0
- package/dist/config.js +400 -0
- package/dist/config.js.map +1 -0
- package/dist/config.mjs +231 -0
- package/dist/config.mjs.map +1 -0
- package/dist/css-writer.d.mts +45 -0
- package/dist/css-writer.mjs +74 -0
- package/dist/css-writer.mjs.map +1 -0
- package/dist/debug.d.ts +204 -0
- package/dist/debug.js +733 -0
- package/dist/debug.js.map +1 -0
- package/dist/extractor.d.mts +24 -0
- package/dist/extractor.mjs +150 -0
- package/dist/extractor.mjs.map +1 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/useGlobalStyles.d.ts +27 -0
- package/dist/hooks/useGlobalStyles.js +56 -0
- package/dist/hooks/useGlobalStyles.js.map +1 -0
- package/dist/hooks/useKeyframes.d.ts +56 -0
- package/dist/hooks/useKeyframes.js +54 -0
- package/dist/hooks/useKeyframes.js.map +1 -0
- package/dist/hooks/useProperty.d.ts +79 -0
- package/dist/hooks/useProperty.js +91 -0
- package/dist/hooks/useProperty.js.map +1 -0
- package/dist/hooks/useRawCSS.d.ts +53 -0
- package/dist/hooks/useRawCSS.js +28 -0
- package/dist/hooks/useRawCSS.js.map +1 -0
- package/dist/hooks/useStyles.d.ts +40 -0
- package/dist/hooks/useStyles.js +169 -0
- package/dist/hooks/useStyles.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +30 -0
- package/dist/injector/index.d.ts +157 -0
- package/dist/injector/index.js +154 -0
- package/dist/injector/index.js.map +1 -0
- package/dist/injector/injector.d.ts +139 -0
- package/dist/injector/injector.js +404 -0
- package/dist/injector/injector.js.map +1 -0
- package/dist/injector/injector.mjs +404 -0
- package/dist/injector/injector.mjs.map +1 -0
- package/dist/injector/sheet-manager.d.ts +127 -0
- package/dist/injector/sheet-manager.js +714 -0
- package/dist/injector/sheet-manager.js.map +1 -0
- package/dist/injector/sheet-manager.mjs +714 -0
- package/dist/injector/sheet-manager.mjs.map +1 -0
- package/dist/injector/types.d.mts +18 -0
- package/dist/injector/types.d.ts +135 -0
- package/dist/keyframes/index.js +206 -0
- package/dist/keyframes/index.js.map +1 -0
- package/dist/keyframes/index.mjs +156 -0
- package/dist/keyframes/index.mjs.map +1 -0
- package/dist/parser/classify.js +319 -0
- package/dist/parser/classify.js.map +1 -0
- package/dist/parser/classify.mjs +319 -0
- package/dist/parser/classify.mjs.map +1 -0
- package/dist/parser/const.js +33 -0
- package/dist/parser/const.js.map +1 -0
- package/dist/parser/const.mjs +33 -0
- package/dist/parser/const.mjs.map +1 -0
- package/dist/parser/lru.js +109 -0
- package/dist/parser/lru.js.map +1 -0
- package/dist/parser/lru.mjs +109 -0
- package/dist/parser/lru.mjs.map +1 -0
- package/dist/parser/parser.d.ts +25 -0
- package/dist/parser/parser.js +116 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/parser.mjs +116 -0
- package/dist/parser/parser.mjs.map +1 -0
- package/dist/parser/tokenizer.js +69 -0
- package/dist/parser/tokenizer.js.map +1 -0
- package/dist/parser/tokenizer.mjs +69 -0
- package/dist/parser/tokenizer.mjs.map +1 -0
- package/dist/parser/types.d.mts +37 -0
- package/dist/parser/types.d.ts +46 -0
- package/dist/parser/types.js +46 -0
- package/dist/parser/types.js.map +1 -0
- package/dist/parser/types.mjs +46 -0
- package/dist/parser/types.mjs.map +1 -0
- package/dist/pipeline/conditions.js +377 -0
- package/dist/pipeline/conditions.js.map +1 -0
- package/dist/pipeline/conditions.mjs +377 -0
- package/dist/pipeline/conditions.mjs.map +1 -0
- package/dist/pipeline/exclusive.d.ts +1 -0
- package/dist/pipeline/exclusive.js +231 -0
- package/dist/pipeline/exclusive.js.map +1 -0
- package/dist/pipeline/exclusive.mjs +231 -0
- package/dist/pipeline/exclusive.mjs.map +1 -0
- package/dist/pipeline/index.d.ts +53 -0
- package/dist/pipeline/index.js +641 -0
- package/dist/pipeline/index.js.map +1 -0
- package/dist/pipeline/index.mjs +635 -0
- package/dist/pipeline/index.mjs.map +1 -0
- package/dist/pipeline/materialize.js +821 -0
- package/dist/pipeline/materialize.js.map +1 -0
- package/dist/pipeline/materialize.mjs +821 -0
- package/dist/pipeline/materialize.mjs.map +1 -0
- package/dist/pipeline/parseStateKey.d.ts +1 -0
- package/dist/pipeline/parseStateKey.js +418 -0
- package/dist/pipeline/parseStateKey.js.map +1 -0
- package/dist/pipeline/parseStateKey.mjs +418 -0
- package/dist/pipeline/parseStateKey.mjs.map +1 -0
- package/dist/pipeline/simplify.js +557 -0
- package/dist/pipeline/simplify.js.map +1 -0
- package/dist/pipeline/simplify.mjs +557 -0
- package/dist/pipeline/simplify.mjs.map +1 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/okhsl-plugin.d.ts +35 -0
- package/dist/plugins/okhsl-plugin.js +371 -0
- package/dist/plugins/okhsl-plugin.js.map +1 -0
- package/dist/plugins/okhsl-plugin.mjs +345 -0
- package/dist/plugins/okhsl-plugin.mjs.map +1 -0
- package/dist/plugins/types.d.mts +49 -0
- package/dist/plugins/types.d.ts +69 -0
- package/dist/properties/index.js +158 -0
- package/dist/properties/index.js.map +1 -0
- package/dist/properties/index.mjs +141 -0
- package/dist/properties/index.mjs.map +1 -0
- package/dist/states/index.d.ts +45 -0
- package/dist/states/index.js +389 -0
- package/dist/states/index.js.map +1 -0
- package/dist/states/index.mjs +161 -0
- package/dist/states/index.mjs.map +1 -0
- package/dist/static/index.d.ts +5 -0
- package/dist/static/index.js +5 -0
- package/dist/static/tastyStatic.d.ts +46 -0
- package/dist/static/tastyStatic.js +31 -0
- package/dist/static/tastyStatic.js.map +1 -0
- package/dist/static/types.d.ts +49 -0
- package/dist/static/types.js +24 -0
- package/dist/static/types.js.map +1 -0
- package/dist/styles/align.d.ts +15 -0
- package/dist/styles/align.js +14 -0
- package/dist/styles/align.js.map +1 -0
- package/dist/styles/align.mjs +14 -0
- package/dist/styles/align.mjs.map +1 -0
- package/dist/styles/border.d.ts +25 -0
- package/dist/styles/border.js +114 -0
- package/dist/styles/border.js.map +1 -0
- package/dist/styles/border.mjs +114 -0
- package/dist/styles/border.mjs.map +1 -0
- package/dist/styles/color.d.ts +14 -0
- package/dist/styles/color.js +23 -0
- package/dist/styles/color.js.map +1 -0
- package/dist/styles/color.mjs +23 -0
- package/dist/styles/color.mjs.map +1 -0
- package/dist/styles/createStyle.js +77 -0
- package/dist/styles/createStyle.js.map +1 -0
- package/dist/styles/createStyle.mjs +77 -0
- package/dist/styles/createStyle.mjs.map +1 -0
- package/dist/styles/dimension.js +97 -0
- package/dist/styles/dimension.js.map +1 -0
- package/dist/styles/dimension.mjs +97 -0
- package/dist/styles/dimension.mjs.map +1 -0
- package/dist/styles/display.d.ts +37 -0
- package/dist/styles/display.js +67 -0
- package/dist/styles/display.js.map +1 -0
- package/dist/styles/display.mjs +67 -0
- package/dist/styles/display.mjs.map +1 -0
- package/dist/styles/fade.d.ts +15 -0
- package/dist/styles/fade.js +58 -0
- package/dist/styles/fade.js.map +1 -0
- package/dist/styles/fade.mjs +58 -0
- package/dist/styles/fade.mjs.map +1 -0
- package/dist/styles/fill.d.ts +44 -0
- package/dist/styles/fill.js +51 -0
- package/dist/styles/fill.js.map +1 -0
- package/dist/styles/fill.mjs +51 -0
- package/dist/styles/fill.mjs.map +1 -0
- package/dist/styles/flow.d.ts +16 -0
- package/dist/styles/flow.js +12 -0
- package/dist/styles/flow.js.map +1 -0
- package/dist/styles/flow.mjs +12 -0
- package/dist/styles/flow.mjs.map +1 -0
- package/dist/styles/gap.d.ts +31 -0
- package/dist/styles/gap.js +37 -0
- package/dist/styles/gap.js.map +1 -0
- package/dist/styles/gap.mjs +37 -0
- package/dist/styles/gap.mjs.map +1 -0
- package/dist/styles/height.d.ts +17 -0
- package/dist/styles/height.js +20 -0
- package/dist/styles/height.js.map +1 -0
- package/dist/styles/height.mjs +20 -0
- package/dist/styles/height.mjs.map +1 -0
- package/dist/styles/index.d.ts +2 -0
- package/dist/styles/index.js +9 -0
- package/dist/styles/index.js.map +1 -0
- package/dist/styles/index.mjs +9 -0
- package/dist/styles/index.mjs.map +1 -0
- package/dist/styles/inset.d.ts +50 -0
- package/dist/styles/inset.js +142 -0
- package/dist/styles/inset.js.map +1 -0
- package/dist/styles/inset.mjs +142 -0
- package/dist/styles/inset.mjs.map +1 -0
- package/dist/styles/justify.d.ts +15 -0
- package/dist/styles/justify.js +14 -0
- package/dist/styles/justify.js.map +1 -0
- package/dist/styles/justify.mjs +14 -0
- package/dist/styles/justify.mjs.map +1 -0
- package/dist/styles/list.d.ts +16 -0
- package/dist/styles/list.js +98 -0
- package/dist/styles/list.js.map +1 -0
- package/dist/styles/margin.d.ts +28 -0
- package/dist/styles/margin.js +96 -0
- package/dist/styles/margin.js.map +1 -0
- package/dist/styles/margin.mjs +96 -0
- package/dist/styles/margin.mjs.map +1 -0
- package/dist/styles/outline.d.ts +29 -0
- package/dist/styles/outline.js +65 -0
- package/dist/styles/outline.js.map +1 -0
- package/dist/styles/outline.mjs +65 -0
- package/dist/styles/outline.mjs.map +1 -0
- package/dist/styles/padding.d.ts +28 -0
- package/dist/styles/padding.js +96 -0
- package/dist/styles/padding.js.map +1 -0
- package/dist/styles/padding.mjs +96 -0
- package/dist/styles/padding.mjs.map +1 -0
- package/dist/styles/predefined.d.ts +74 -0
- package/dist/styles/predefined.js +241 -0
- package/dist/styles/predefined.js.map +1 -0
- package/dist/styles/predefined.mjs +232 -0
- package/dist/styles/predefined.mjs.map +1 -0
- package/dist/styles/preset.d.ts +47 -0
- package/dist/styles/preset.js +126 -0
- package/dist/styles/preset.js.map +1 -0
- package/dist/styles/preset.mjs +126 -0
- package/dist/styles/preset.mjs.map +1 -0
- package/dist/styles/radius.d.ts +14 -0
- package/dist/styles/radius.js +51 -0
- package/dist/styles/radius.js.map +1 -0
- package/dist/styles/radius.mjs +51 -0
- package/dist/styles/radius.mjs.map +1 -0
- package/dist/styles/scrollbar.d.ts +21 -0
- package/dist/styles/scrollbar.js +105 -0
- package/dist/styles/scrollbar.js.map +1 -0
- package/dist/styles/scrollbar.mjs +105 -0
- package/dist/styles/scrollbar.mjs.map +1 -0
- package/dist/styles/shadow.d.ts +14 -0
- package/dist/styles/shadow.js +24 -0
- package/dist/styles/shadow.js.map +1 -0
- package/dist/styles/shadow.mjs +24 -0
- package/dist/styles/shadow.mjs.map +1 -0
- package/dist/styles/styledScrollbar.d.ts +47 -0
- package/dist/styles/styledScrollbar.js +38 -0
- package/dist/styles/styledScrollbar.js.map +1 -0
- package/dist/styles/styledScrollbar.mjs +38 -0
- package/dist/styles/styledScrollbar.mjs.map +1 -0
- package/dist/styles/transition.d.ts +14 -0
- package/dist/styles/transition.js +138 -0
- package/dist/styles/transition.js.map +1 -0
- package/dist/styles/transition.mjs +138 -0
- package/dist/styles/transition.mjs.map +1 -0
- package/dist/styles/types.d.mts +492 -0
- package/dist/styles/types.d.ts +496 -0
- package/dist/styles/width.d.ts +17 -0
- package/dist/styles/width.js +20 -0
- package/dist/styles/width.js.map +1 -0
- package/dist/styles/width.mjs +20 -0
- package/dist/styles/width.mjs.map +1 -0
- package/dist/tasty.d.ts +983 -0
- package/dist/tasty.js +191 -0
- package/dist/tasty.js.map +1 -0
- package/dist/tokens/typography.d.ts +19 -0
- package/dist/tokens/typography.js +237 -0
- package/dist/tokens/typography.js.map +1 -0
- package/dist/types.d.ts +182 -0
- package/dist/utils/cache-wrapper.js +26 -0
- package/dist/utils/cache-wrapper.js.map +1 -0
- package/dist/utils/cache-wrapper.mjs +26 -0
- package/dist/utils/cache-wrapper.mjs.map +1 -0
- package/dist/utils/case-converter.js +8 -0
- package/dist/utils/case-converter.js.map +1 -0
- package/dist/utils/case-converter.mjs +8 -0
- package/dist/utils/case-converter.mjs.map +1 -0
- package/dist/utils/colors.d.ts +5 -0
- package/dist/utils/colors.js +9 -0
- package/dist/utils/colors.js.map +1 -0
- package/dist/utils/dotize.d.ts +26 -0
- package/dist/utils/dotize.js +122 -0
- package/dist/utils/dotize.js.map +1 -0
- package/dist/utils/filter-base-props.d.ts +15 -0
- package/dist/utils/filter-base-props.js +45 -0
- package/dist/utils/filter-base-props.js.map +1 -0
- package/dist/utils/get-display-name.d.ts +7 -0
- package/dist/utils/get-display-name.js +10 -0
- package/dist/utils/get-display-name.js.map +1 -0
- package/dist/utils/hsl-to-rgb.js +38 -0
- package/dist/utils/hsl-to-rgb.js.map +1 -0
- package/dist/utils/hsl-to-rgb.mjs +38 -0
- package/dist/utils/hsl-to-rgb.mjs.map +1 -0
- package/dist/utils/is-dev-env.js +19 -0
- package/dist/utils/is-dev-env.js.map +1 -0
- package/dist/utils/is-dev-env.mjs +19 -0
- package/dist/utils/is-dev-env.mjs.map +1 -0
- package/dist/utils/merge-styles.d.ts +7 -0
- package/dist/utils/merge-styles.js +146 -0
- package/dist/utils/merge-styles.js.map +1 -0
- package/dist/utils/merge-styles.mjs +146 -0
- package/dist/utils/merge-styles.mjs.map +1 -0
- package/dist/utils/mod-attrs.d.ts +8 -0
- package/dist/utils/mod-attrs.js +21 -0
- package/dist/utils/mod-attrs.js.map +1 -0
- package/dist/utils/okhsl-to-rgb.js +296 -0
- package/dist/utils/okhsl-to-rgb.js.map +1 -0
- package/dist/utils/okhsl-to-rgb.mjs +296 -0
- package/dist/utils/okhsl-to-rgb.mjs.map +1 -0
- package/dist/utils/process-tokens.d.ts +31 -0
- package/dist/utils/process-tokens.js +171 -0
- package/dist/utils/process-tokens.js.map +1 -0
- package/dist/utils/process-tokens.mjs +28 -0
- package/dist/utils/process-tokens.mjs.map +1 -0
- package/dist/utils/resolve-recipes.d.ts +17 -0
- package/dist/utils/resolve-recipes.js +143 -0
- package/dist/utils/resolve-recipes.js.map +1 -0
- package/dist/utils/resolve-recipes.mjs +143 -0
- package/dist/utils/resolve-recipes.mjs.map +1 -0
- package/dist/utils/string.js +8 -0
- package/dist/utils/string.js.map +1 -0
- package/dist/utils/string.mjs +8 -0
- package/dist/utils/string.mjs.map +1 -0
- package/dist/utils/styles.d.mts +18 -0
- package/dist/utils/styles.d.ts +183 -0
- package/dist/utils/styles.js +585 -0
- package/dist/utils/styles.js.map +1 -0
- package/dist/utils/styles.mjs +346 -0
- package/dist/utils/styles.mjs.map +1 -0
- package/dist/utils/typography.d.ts +36 -0
- package/dist/utils/typography.js +53 -0
- package/dist/utils/typography.js.map +1 -0
- package/dist/utils/warnings.d.ts +16 -0
- package/dist/utils/warnings.js +16 -0
- package/dist/utils/warnings.js.map +1 -0
- package/dist/zero/babel.d.mts +108 -0
- package/dist/zero/babel.mjs +282 -0
- package/dist/zero/babel.mjs.map +1 -0
- package/dist/zero/index.d.mts +3 -0
- package/dist/zero/index.mjs +4 -0
- package/dist/zero/next.d.mts +60 -0
- package/dist/zero/next.mjs +78 -0
- package/dist/zero/next.mjs.map +1 -0
- package/package.json +127 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { DIRECTIONS, filterMods, parseStyle } from "../utils/styles.js";
|
|
2
|
+
|
|
3
|
+
//#region src/styles/border.ts
|
|
4
|
+
const BORDER_STYLES = [
|
|
5
|
+
"none",
|
|
6
|
+
"hidden",
|
|
7
|
+
"dotted",
|
|
8
|
+
"dashed",
|
|
9
|
+
"solid",
|
|
10
|
+
"double",
|
|
11
|
+
"groove",
|
|
12
|
+
"ridge",
|
|
13
|
+
"inset",
|
|
14
|
+
"outset"
|
|
15
|
+
];
|
|
16
|
+
/**
|
|
17
|
+
* Process a single group and return border values for its directions.
|
|
18
|
+
* @returns Object with directions as keys and border values, or null for "all directions"
|
|
19
|
+
*/
|
|
20
|
+
function processGroup(group) {
|
|
21
|
+
const { values, mods, colors } = group;
|
|
22
|
+
const directions = filterMods(mods, DIRECTIONS);
|
|
23
|
+
const typeMods = filterMods(mods, BORDER_STYLES);
|
|
24
|
+
return {
|
|
25
|
+
directions,
|
|
26
|
+
borderValue: {
|
|
27
|
+
width: values[0] || "var(--border-width)",
|
|
28
|
+
style: typeMods[0] || "solid",
|
|
29
|
+
color: colors?.[0] || "var(--border-color)"
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Format a border value to CSS string.
|
|
35
|
+
*/
|
|
36
|
+
function formatBorderValue(value) {
|
|
37
|
+
return `${value.width} ${value.style} ${value.color}`;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Border style handler with multi-group support.
|
|
41
|
+
*
|
|
42
|
+
* Single group (backward compatible):
|
|
43
|
+
* - `border="1bw solid #red"` - all sides
|
|
44
|
+
* - `border="1bw solid #red top left"` - only top and left
|
|
45
|
+
*
|
|
46
|
+
* Multi-group (new):
|
|
47
|
+
* - `border="1bw #red, 2bw #blue top"` - all sides red 1bw, then top overridden to blue 2bw
|
|
48
|
+
* - `border="1bw, dashed top bottom, #purple left right"` - base 1bw, dashed on top/bottom, purple on left/right
|
|
49
|
+
*
|
|
50
|
+
* Later groups override earlier groups for conflicting directions.
|
|
51
|
+
*/
|
|
52
|
+
function borderStyle({ border }) {
|
|
53
|
+
if (!border && border !== 0) return;
|
|
54
|
+
if (border === true) border = "1bw";
|
|
55
|
+
const groups = parseStyle(String(border)).groups ?? [];
|
|
56
|
+
if (!groups.length) return;
|
|
57
|
+
if (groups.length === 1) {
|
|
58
|
+
const { directions, borderValue } = processGroup({
|
|
59
|
+
values: groups[0].values ?? [],
|
|
60
|
+
mods: groups[0].mods ?? [],
|
|
61
|
+
colors: groups[0].colors ?? []
|
|
62
|
+
});
|
|
63
|
+
const styleValue = formatBorderValue(borderValue);
|
|
64
|
+
if (!directions.length) return { border: styleValue };
|
|
65
|
+
const zeroValue = `0 ${borderValue.style} ${borderValue.color}`;
|
|
66
|
+
return DIRECTIONS.reduce((styles, dir) => {
|
|
67
|
+
if (directions.includes(dir)) styles[`border-${dir}`] = styleValue;
|
|
68
|
+
else styles[`border-${dir}`] = zeroValue;
|
|
69
|
+
return styles;
|
|
70
|
+
}, {});
|
|
71
|
+
}
|
|
72
|
+
let hasAnyDirections = false;
|
|
73
|
+
const directionMap = {
|
|
74
|
+
top: null,
|
|
75
|
+
right: null,
|
|
76
|
+
bottom: null,
|
|
77
|
+
left: null
|
|
78
|
+
};
|
|
79
|
+
let allDirectionsValue = null;
|
|
80
|
+
for (const group of groups) {
|
|
81
|
+
const { directions, borderValue } = processGroup({
|
|
82
|
+
values: group.values ?? [],
|
|
83
|
+
mods: group.mods ?? [],
|
|
84
|
+
colors: group.colors ?? []
|
|
85
|
+
});
|
|
86
|
+
if (directions.length === 0) {
|
|
87
|
+
allDirectionsValue = borderValue;
|
|
88
|
+
for (const dir of DIRECTIONS) directionMap[dir] = borderValue;
|
|
89
|
+
} else {
|
|
90
|
+
hasAnyDirections = true;
|
|
91
|
+
for (const dir of directions) directionMap[dir] = borderValue;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (!hasAnyDirections && allDirectionsValue) return { border: formatBorderValue(allDirectionsValue) };
|
|
95
|
+
const result = {};
|
|
96
|
+
for (const dir of DIRECTIONS) {
|
|
97
|
+
const value = directionMap[dir];
|
|
98
|
+
if (value) result[`border-${dir}`] = formatBorderValue(value);
|
|
99
|
+
else {
|
|
100
|
+
const fallback = allDirectionsValue || {
|
|
101
|
+
width: "0",
|
|
102
|
+
style: "solid",
|
|
103
|
+
color: "var(--border-color)"
|
|
104
|
+
};
|
|
105
|
+
result[`border-${dir}`] = `0 ${fallback.style} ${fallback.color}`;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
borderStyle.__lookupStyles = ["border"];
|
|
111
|
+
|
|
112
|
+
//#endregion
|
|
113
|
+
export { borderStyle };
|
|
114
|
+
//# sourceMappingURL=border.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"border.js","names":[],"sources":["../../src/styles/border.ts"],"sourcesContent":["import { DIRECTIONS, filterMods, parseStyle } from '../utils/styles';\n\nconst BORDER_STYLES = [\n 'none',\n 'hidden',\n 'dotted',\n 'dashed',\n 'solid',\n 'double',\n 'groove',\n 'ridge',\n 'inset',\n 'outset',\n] as const;\n\ntype Direction = (typeof DIRECTIONS)[number];\n\ninterface GroupData {\n values: string[];\n mods: string[];\n colors: string[];\n}\n\ninterface BorderValue {\n width: string;\n style: string;\n color: string;\n}\n\n/**\n * Process a single group and return border values for its directions.\n * @returns Object with directions as keys and border values, or null for \"all directions\"\n */\nfunction processGroup(group: GroupData): {\n directions: Direction[];\n borderValue: BorderValue;\n} {\n const { values, mods, colors } = group;\n\n const directions = filterMods(mods, DIRECTIONS) as Direction[];\n const typeMods = filterMods(mods, BORDER_STYLES);\n\n const width = values[0] || 'var(--border-width)';\n const style = typeMods[0] || 'solid';\n const color = colors?.[0] || 'var(--border-color)';\n\n return {\n directions,\n borderValue: { width, style, color },\n };\n}\n\n/**\n * Format a border value to CSS string.\n */\nfunction formatBorderValue(value: BorderValue): string {\n return `${value.width} ${value.style} ${value.color}`;\n}\n\n/**\n * Border style handler with multi-group support.\n *\n * Single group (backward compatible):\n * - `border=\"1bw solid #red\"` - all sides\n * - `border=\"1bw solid #red top left\"` - only top and left\n *\n * Multi-group (new):\n * - `border=\"1bw #red, 2bw #blue top\"` - all sides red 1bw, then top overridden to blue 2bw\n * - `border=\"1bw, dashed top bottom, #purple left right\"` - base 1bw, dashed on top/bottom, purple on left/right\n *\n * Later groups override earlier groups for conflicting directions.\n */\nexport function borderStyle({ border }) {\n if (!border && border !== 0) return;\n\n if (border === true) border = '1bw';\n\n const processed = parseStyle(String(border));\n const groups: GroupData[] = processed.groups ?? [];\n\n if (!groups.length) return;\n\n // Single group - use original logic for backward compatibility\n if (groups.length === 1) {\n const { directions, borderValue } = processGroup({\n values: groups[0].values ?? [],\n mods: groups[0].mods ?? [],\n colors: groups[0].colors ?? [],\n });\n\n const styleValue = formatBorderValue(borderValue);\n\n if (!directions.length) {\n return { border: styleValue };\n }\n\n const zeroValue = `0 ${borderValue.style} ${borderValue.color}`;\n\n return DIRECTIONS.reduce(\n (styles, dir) => {\n if (directions.includes(dir)) {\n styles[`border-${dir}`] = styleValue;\n } else {\n styles[`border-${dir}`] = zeroValue;\n }\n return styles;\n },\n {} as Record<string, string>,\n );\n }\n\n // Multi-group - process groups in order, later groups override earlier\n // Track whether any group specifies directions\n let hasAnyDirections = false;\n\n // Build a map of direction -> border value\n // Start with undefined (no border set)\n const directionMap: Record<Direction, BorderValue | null> = {\n top: null,\n right: null,\n bottom: null,\n left: null,\n };\n\n // Track the last \"all directions\" value for fallback\n let allDirectionsValue: BorderValue | null = null;\n\n // Process groups in order (first to last)\n for (const group of groups) {\n const { directions, borderValue } = processGroup({\n values: group.values ?? [],\n mods: group.mods ?? [],\n colors: group.colors ?? [],\n });\n\n if (directions.length === 0) {\n // No specific directions - applies to all\n allDirectionsValue = borderValue;\n // Set all directions\n for (const dir of DIRECTIONS) {\n directionMap[dir] = borderValue;\n }\n } else {\n // Specific directions - override only those\n hasAnyDirections = true;\n for (const dir of directions) {\n directionMap[dir] = borderValue;\n }\n }\n }\n\n // If no group specified any directions and we have an all-directions value,\n // return the simple `border` shorthand\n if (!hasAnyDirections && allDirectionsValue) {\n return { border: formatBorderValue(allDirectionsValue) };\n }\n\n // Otherwise, output individual border-* properties\n const result: Record<string, string> = {};\n\n for (const dir of DIRECTIONS) {\n const value = directionMap[dir];\n if (value) {\n result[`border-${dir}`] = formatBorderValue(value);\n } else {\n // No border for this direction - set to 0\n // Use the last all-directions value for style/color consistency, or defaults\n const fallback = allDirectionsValue || {\n width: '0',\n style: 'solid',\n color: 'var(--border-color)',\n };\n result[`border-${dir}`] = `0 ${fallback.style} ${fallback.color}`;\n }\n }\n\n return result;\n}\n\nborderStyle.__lookupStyles = ['border'];\n"],"mappings":";;;AAEA,MAAM,gBAAgB;CACpB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;AAoBD,SAAS,aAAa,OAGpB;CACA,MAAM,EAAE,QAAQ,MAAM,WAAW;CAEjC,MAAM,aAAa,WAAW,MAAM,WAAW;CAC/C,MAAM,WAAW,WAAW,MAAM,cAAc;AAMhD,QAAO;EACL;EACA,aAAa;GAAE,OANH,OAAO,MAAM;GAMH,OALV,SAAS,MAAM;GAKE,OAJjB,SAAS,MAAM;GAIS;EACrC;;;;;AAMH,SAAS,kBAAkB,OAA4B;AACrD,QAAO,GAAG,MAAM,MAAM,GAAG,MAAM,MAAM,GAAG,MAAM;;;;;;;;;;;;;;;AAgBhD,SAAgB,YAAY,EAAE,UAAU;AACtC,KAAI,CAAC,UAAU,WAAW,EAAG;AAE7B,KAAI,WAAW,KAAM,UAAS;CAG9B,MAAM,SADY,WAAW,OAAO,OAAO,CAAC,CACN,UAAU,EAAE;AAElD,KAAI,CAAC,OAAO,OAAQ;AAGpB,KAAI,OAAO,WAAW,GAAG;EACvB,MAAM,EAAE,YAAY,gBAAgB,aAAa;GAC/C,QAAQ,OAAO,GAAG,UAAU,EAAE;GAC9B,MAAM,OAAO,GAAG,QAAQ,EAAE;GAC1B,QAAQ,OAAO,GAAG,UAAU,EAAE;GAC/B,CAAC;EAEF,MAAM,aAAa,kBAAkB,YAAY;AAEjD,MAAI,CAAC,WAAW,OACd,QAAO,EAAE,QAAQ,YAAY;EAG/B,MAAM,YAAY,KAAK,YAAY,MAAM,GAAG,YAAY;AAExD,SAAO,WAAW,QACf,QAAQ,QAAQ;AACf,OAAI,WAAW,SAAS,IAAI,CAC1B,QAAO,UAAU,SAAS;OAE1B,QAAO,UAAU,SAAS;AAE5B,UAAO;KAET,EAAE,CACH;;CAKH,IAAI,mBAAmB;CAIvB,MAAM,eAAsD;EAC1D,KAAK;EACL,OAAO;EACP,QAAQ;EACR,MAAM;EACP;CAGD,IAAI,qBAAyC;AAG7C,MAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,EAAE,YAAY,gBAAgB,aAAa;GAC/C,QAAQ,MAAM,UAAU,EAAE;GAC1B,MAAM,MAAM,QAAQ,EAAE;GACtB,QAAQ,MAAM,UAAU,EAAE;GAC3B,CAAC;AAEF,MAAI,WAAW,WAAW,GAAG;AAE3B,wBAAqB;AAErB,QAAK,MAAM,OAAO,WAChB,cAAa,OAAO;SAEjB;AAEL,sBAAmB;AACnB,QAAK,MAAM,OAAO,WAChB,cAAa,OAAO;;;AAO1B,KAAI,CAAC,oBAAoB,mBACvB,QAAO,EAAE,QAAQ,kBAAkB,mBAAmB,EAAE;CAI1D,MAAM,SAAiC,EAAE;AAEzC,MAAK,MAAM,OAAO,YAAY;EAC5B,MAAM,QAAQ,aAAa;AAC3B,MAAI,MACF,QAAO,UAAU,SAAS,kBAAkB,MAAM;OAC7C;GAGL,MAAM,WAAW,sBAAsB;IACrC,OAAO;IACP,OAAO;IACP,OAAO;IACR;AACD,UAAO,UAAU,SAAS,KAAK,SAAS,MAAM,GAAG,SAAS;;;AAI9D,QAAO;;AAGT,YAAY,iBAAiB,CAAC,SAAS"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { DIRECTIONS, filterMods, parseStyle } from "../utils/styles.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/styles/border.ts
|
|
4
|
+
const BORDER_STYLES = [
|
|
5
|
+
"none",
|
|
6
|
+
"hidden",
|
|
7
|
+
"dotted",
|
|
8
|
+
"dashed",
|
|
9
|
+
"solid",
|
|
10
|
+
"double",
|
|
11
|
+
"groove",
|
|
12
|
+
"ridge",
|
|
13
|
+
"inset",
|
|
14
|
+
"outset"
|
|
15
|
+
];
|
|
16
|
+
/**
|
|
17
|
+
* Process a single group and return border values for its directions.
|
|
18
|
+
* @returns Object with directions as keys and border values, or null for "all directions"
|
|
19
|
+
*/
|
|
20
|
+
function processGroup(group) {
|
|
21
|
+
const { values, mods, colors } = group;
|
|
22
|
+
const directions = filterMods(mods, DIRECTIONS);
|
|
23
|
+
const typeMods = filterMods(mods, BORDER_STYLES);
|
|
24
|
+
return {
|
|
25
|
+
directions,
|
|
26
|
+
borderValue: {
|
|
27
|
+
width: values[0] || "var(--border-width)",
|
|
28
|
+
style: typeMods[0] || "solid",
|
|
29
|
+
color: colors?.[0] || "var(--border-color)"
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Format a border value to CSS string.
|
|
35
|
+
*/
|
|
36
|
+
function formatBorderValue(value) {
|
|
37
|
+
return `${value.width} ${value.style} ${value.color}`;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Border style handler with multi-group support.
|
|
41
|
+
*
|
|
42
|
+
* Single group (backward compatible):
|
|
43
|
+
* - `border="1bw solid #red"` - all sides
|
|
44
|
+
* - `border="1bw solid #red top left"` - only top and left
|
|
45
|
+
*
|
|
46
|
+
* Multi-group (new):
|
|
47
|
+
* - `border="1bw #red, 2bw #blue top"` - all sides red 1bw, then top overridden to blue 2bw
|
|
48
|
+
* - `border="1bw, dashed top bottom, #purple left right"` - base 1bw, dashed on top/bottom, purple on left/right
|
|
49
|
+
*
|
|
50
|
+
* Later groups override earlier groups for conflicting directions.
|
|
51
|
+
*/
|
|
52
|
+
function borderStyle({ border }) {
|
|
53
|
+
if (!border && border !== 0) return;
|
|
54
|
+
if (border === true) border = "1bw";
|
|
55
|
+
const groups = parseStyle(String(border)).groups ?? [];
|
|
56
|
+
if (!groups.length) return;
|
|
57
|
+
if (groups.length === 1) {
|
|
58
|
+
const { directions, borderValue } = processGroup({
|
|
59
|
+
values: groups[0].values ?? [],
|
|
60
|
+
mods: groups[0].mods ?? [],
|
|
61
|
+
colors: groups[0].colors ?? []
|
|
62
|
+
});
|
|
63
|
+
const styleValue = formatBorderValue(borderValue);
|
|
64
|
+
if (!directions.length) return { border: styleValue };
|
|
65
|
+
const zeroValue = `0 ${borderValue.style} ${borderValue.color}`;
|
|
66
|
+
return DIRECTIONS.reduce((styles, dir) => {
|
|
67
|
+
if (directions.includes(dir)) styles[`border-${dir}`] = styleValue;
|
|
68
|
+
else styles[`border-${dir}`] = zeroValue;
|
|
69
|
+
return styles;
|
|
70
|
+
}, {});
|
|
71
|
+
}
|
|
72
|
+
let hasAnyDirections = false;
|
|
73
|
+
const directionMap = {
|
|
74
|
+
top: null,
|
|
75
|
+
right: null,
|
|
76
|
+
bottom: null,
|
|
77
|
+
left: null
|
|
78
|
+
};
|
|
79
|
+
let allDirectionsValue = null;
|
|
80
|
+
for (const group of groups) {
|
|
81
|
+
const { directions, borderValue } = processGroup({
|
|
82
|
+
values: group.values ?? [],
|
|
83
|
+
mods: group.mods ?? [],
|
|
84
|
+
colors: group.colors ?? []
|
|
85
|
+
});
|
|
86
|
+
if (directions.length === 0) {
|
|
87
|
+
allDirectionsValue = borderValue;
|
|
88
|
+
for (const dir of DIRECTIONS) directionMap[dir] = borderValue;
|
|
89
|
+
} else {
|
|
90
|
+
hasAnyDirections = true;
|
|
91
|
+
for (const dir of directions) directionMap[dir] = borderValue;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (!hasAnyDirections && allDirectionsValue) return { border: formatBorderValue(allDirectionsValue) };
|
|
95
|
+
const result = {};
|
|
96
|
+
for (const dir of DIRECTIONS) {
|
|
97
|
+
const value = directionMap[dir];
|
|
98
|
+
if (value) result[`border-${dir}`] = formatBorderValue(value);
|
|
99
|
+
else {
|
|
100
|
+
const fallback = allDirectionsValue || {
|
|
101
|
+
width: "0",
|
|
102
|
+
style: "solid",
|
|
103
|
+
color: "var(--border-color)"
|
|
104
|
+
};
|
|
105
|
+
result[`border-${dir}`] = `0 ${fallback.style} ${fallback.color}`;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
borderStyle.__lookupStyles = ["border"];
|
|
111
|
+
|
|
112
|
+
//#endregion
|
|
113
|
+
export { borderStyle };
|
|
114
|
+
//# sourceMappingURL=border.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"border.mjs","names":[],"sources":["../../src/styles/border.ts"],"sourcesContent":["import { DIRECTIONS, filterMods, parseStyle } from '../utils/styles';\n\nconst BORDER_STYLES = [\n 'none',\n 'hidden',\n 'dotted',\n 'dashed',\n 'solid',\n 'double',\n 'groove',\n 'ridge',\n 'inset',\n 'outset',\n] as const;\n\ntype Direction = (typeof DIRECTIONS)[number];\n\ninterface GroupData {\n values: string[];\n mods: string[];\n colors: string[];\n}\n\ninterface BorderValue {\n width: string;\n style: string;\n color: string;\n}\n\n/**\n * Process a single group and return border values for its directions.\n * @returns Object with directions as keys and border values, or null for \"all directions\"\n */\nfunction processGroup(group: GroupData): {\n directions: Direction[];\n borderValue: BorderValue;\n} {\n const { values, mods, colors } = group;\n\n const directions = filterMods(mods, DIRECTIONS) as Direction[];\n const typeMods = filterMods(mods, BORDER_STYLES);\n\n const width = values[0] || 'var(--border-width)';\n const style = typeMods[0] || 'solid';\n const color = colors?.[0] || 'var(--border-color)';\n\n return {\n directions,\n borderValue: { width, style, color },\n };\n}\n\n/**\n * Format a border value to CSS string.\n */\nfunction formatBorderValue(value: BorderValue): string {\n return `${value.width} ${value.style} ${value.color}`;\n}\n\n/**\n * Border style handler with multi-group support.\n *\n * Single group (backward compatible):\n * - `border=\"1bw solid #red\"` - all sides\n * - `border=\"1bw solid #red top left\"` - only top and left\n *\n * Multi-group (new):\n * - `border=\"1bw #red, 2bw #blue top\"` - all sides red 1bw, then top overridden to blue 2bw\n * - `border=\"1bw, dashed top bottom, #purple left right\"` - base 1bw, dashed on top/bottom, purple on left/right\n *\n * Later groups override earlier groups for conflicting directions.\n */\nexport function borderStyle({ border }) {\n if (!border && border !== 0) return;\n\n if (border === true) border = '1bw';\n\n const processed = parseStyle(String(border));\n const groups: GroupData[] = processed.groups ?? [];\n\n if (!groups.length) return;\n\n // Single group - use original logic for backward compatibility\n if (groups.length === 1) {\n const { directions, borderValue } = processGroup({\n values: groups[0].values ?? [],\n mods: groups[0].mods ?? [],\n colors: groups[0].colors ?? [],\n });\n\n const styleValue = formatBorderValue(borderValue);\n\n if (!directions.length) {\n return { border: styleValue };\n }\n\n const zeroValue = `0 ${borderValue.style} ${borderValue.color}`;\n\n return DIRECTIONS.reduce(\n (styles, dir) => {\n if (directions.includes(dir)) {\n styles[`border-${dir}`] = styleValue;\n } else {\n styles[`border-${dir}`] = zeroValue;\n }\n return styles;\n },\n {} as Record<string, string>,\n );\n }\n\n // Multi-group - process groups in order, later groups override earlier\n // Track whether any group specifies directions\n let hasAnyDirections = false;\n\n // Build a map of direction -> border value\n // Start with undefined (no border set)\n const directionMap: Record<Direction, BorderValue | null> = {\n top: null,\n right: null,\n bottom: null,\n left: null,\n };\n\n // Track the last \"all directions\" value for fallback\n let allDirectionsValue: BorderValue | null = null;\n\n // Process groups in order (first to last)\n for (const group of groups) {\n const { directions, borderValue } = processGroup({\n values: group.values ?? [],\n mods: group.mods ?? [],\n colors: group.colors ?? [],\n });\n\n if (directions.length === 0) {\n // No specific directions - applies to all\n allDirectionsValue = borderValue;\n // Set all directions\n for (const dir of DIRECTIONS) {\n directionMap[dir] = borderValue;\n }\n } else {\n // Specific directions - override only those\n hasAnyDirections = true;\n for (const dir of directions) {\n directionMap[dir] = borderValue;\n }\n }\n }\n\n // If no group specified any directions and we have an all-directions value,\n // return the simple `border` shorthand\n if (!hasAnyDirections && allDirectionsValue) {\n return { border: formatBorderValue(allDirectionsValue) };\n }\n\n // Otherwise, output individual border-* properties\n const result: Record<string, string> = {};\n\n for (const dir of DIRECTIONS) {\n const value = directionMap[dir];\n if (value) {\n result[`border-${dir}`] = formatBorderValue(value);\n } else {\n // No border for this direction - set to 0\n // Use the last all-directions value for style/color consistency, or defaults\n const fallback = allDirectionsValue || {\n width: '0',\n style: 'solid',\n color: 'var(--border-color)',\n };\n result[`border-${dir}`] = `0 ${fallback.style} ${fallback.color}`;\n }\n }\n\n return result;\n}\n\nborderStyle.__lookupStyles = ['border'];\n"],"mappings":";;;AAEA,MAAM,gBAAgB;CACpB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;AAoBD,SAAS,aAAa,OAGpB;CACA,MAAM,EAAE,QAAQ,MAAM,WAAW;CAEjC,MAAM,aAAa,WAAW,MAAM,WAAW;CAC/C,MAAM,WAAW,WAAW,MAAM,cAAc;AAMhD,QAAO;EACL;EACA,aAAa;GAAE,OANH,OAAO,MAAM;GAMH,OALV,SAAS,MAAM;GAKE,OAJjB,SAAS,MAAM;GAIS;EACrC;;;;;AAMH,SAAS,kBAAkB,OAA4B;AACrD,QAAO,GAAG,MAAM,MAAM,GAAG,MAAM,MAAM,GAAG,MAAM;;;;;;;;;;;;;;;AAgBhD,SAAgB,YAAY,EAAE,UAAU;AACtC,KAAI,CAAC,UAAU,WAAW,EAAG;AAE7B,KAAI,WAAW,KAAM,UAAS;CAG9B,MAAM,SADY,WAAW,OAAO,OAAO,CAAC,CACN,UAAU,EAAE;AAElD,KAAI,CAAC,OAAO,OAAQ;AAGpB,KAAI,OAAO,WAAW,GAAG;EACvB,MAAM,EAAE,YAAY,gBAAgB,aAAa;GAC/C,QAAQ,OAAO,GAAG,UAAU,EAAE;GAC9B,MAAM,OAAO,GAAG,QAAQ,EAAE;GAC1B,QAAQ,OAAO,GAAG,UAAU,EAAE;GAC/B,CAAC;EAEF,MAAM,aAAa,kBAAkB,YAAY;AAEjD,MAAI,CAAC,WAAW,OACd,QAAO,EAAE,QAAQ,YAAY;EAG/B,MAAM,YAAY,KAAK,YAAY,MAAM,GAAG,YAAY;AAExD,SAAO,WAAW,QACf,QAAQ,QAAQ;AACf,OAAI,WAAW,SAAS,IAAI,CAC1B,QAAO,UAAU,SAAS;OAE1B,QAAO,UAAU,SAAS;AAE5B,UAAO;KAET,EAAE,CACH;;CAKH,IAAI,mBAAmB;CAIvB,MAAM,eAAsD;EAC1D,KAAK;EACL,OAAO;EACP,QAAQ;EACR,MAAM;EACP;CAGD,IAAI,qBAAyC;AAG7C,MAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,EAAE,YAAY,gBAAgB,aAAa;GAC/C,QAAQ,MAAM,UAAU,EAAE;GAC1B,MAAM,MAAM,QAAQ,EAAE;GACtB,QAAQ,MAAM,UAAU,EAAE;GAC3B,CAAC;AAEF,MAAI,WAAW,WAAW,GAAG;AAE3B,wBAAqB;AAErB,QAAK,MAAM,OAAO,WAChB,cAAa,OAAO;SAEjB;AAEL,sBAAmB;AACnB,QAAK,MAAM,OAAO,WAChB,cAAa,OAAO;;;AAO1B,KAAI,CAAC,oBAAoB,mBACvB,QAAO,EAAE,QAAQ,kBAAkB,mBAAmB,EAAE;CAI1D,MAAM,SAAiC,EAAE;AAEzC,MAAK,MAAM,OAAO,YAAY;EAC5B,MAAM,QAAQ,aAAa;AAC3B,MAAI,MACF,QAAO,UAAU,SAAS,kBAAkB,MAAM;OAC7C;GAGL,MAAM,WAAW,sBAAsB;IACrC,OAAO;IACP,OAAO;IACP,OAAO;IACR;AACD,UAAO,UAAU,SAAS,KAAK,SAAS,MAAM,GAAG,SAAS;;;AAI9D,QAAO;;AAGT,YAAY,iBAAiB,CAAC,SAAS"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/styles/color.d.ts
|
|
2
|
+
declare function colorStyle({
|
|
3
|
+
color
|
|
4
|
+
}: {
|
|
5
|
+
color: any;
|
|
6
|
+
}): {
|
|
7
|
+
color: any;
|
|
8
|
+
} | undefined;
|
|
9
|
+
declare namespace colorStyle {
|
|
10
|
+
var __lookupStyles: string[];
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { colorStyle };
|
|
14
|
+
//# sourceMappingURL=color.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { parseColor } from "../utils/styles.js";
|
|
2
|
+
import { convertColorChainToRgbChain } from "./createStyle.js";
|
|
3
|
+
|
|
4
|
+
//#region src/styles/color.ts
|
|
5
|
+
function colorStyle({ color }) {
|
|
6
|
+
if (!color) return;
|
|
7
|
+
if (color === true) color = "currentColor";
|
|
8
|
+
if (typeof color === "string" && (color.startsWith("#") || color.startsWith("(#"))) color = parseColor(color).color || color;
|
|
9
|
+
const match = color.match(/var\(--(.+?)-color/);
|
|
10
|
+
let name = "";
|
|
11
|
+
if (match) name = match[1];
|
|
12
|
+
const styles = { color };
|
|
13
|
+
if (name && name !== "current") Object.assign(styles, {
|
|
14
|
+
"--current-color": color,
|
|
15
|
+
"--current-color-rgb": convertColorChainToRgbChain(color)
|
|
16
|
+
});
|
|
17
|
+
return styles;
|
|
18
|
+
}
|
|
19
|
+
colorStyle.__lookupStyles = ["color"];
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { colorStyle };
|
|
23
|
+
//# sourceMappingURL=color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.js","names":[],"sources":["../../src/styles/color.ts"],"sourcesContent":["import { parseColor } from '../utils/styles';\n\nimport { convertColorChainToRgbChain } from './createStyle';\n\nexport function colorStyle({ color }) {\n if (!color) return;\n\n if (color === true) color = 'currentColor';\n\n // Handle color values that need parsing:\n // - Simple color tokens: #placeholder\n // - Color fallback syntax: (#placeholder, #dark-04)\n if (\n typeof color === 'string' &&\n (color.startsWith('#') || color.startsWith('(#'))\n ) {\n color = parseColor(color).color || color;\n }\n\n const match = color.match(/var\\(--(.+?)-color/);\n let name = '';\n\n if (match) {\n name = match[1];\n }\n\n const styles = {\n color: color,\n };\n\n if (name && name !== 'current') {\n Object.assign(styles, {\n '--current-color': color,\n '--current-color-rgb': convertColorChainToRgbChain(color),\n });\n }\n\n return styles;\n}\n\ncolorStyle.__lookupStyles = ['color'];\n"],"mappings":";;;;AAIA,SAAgB,WAAW,EAAE,SAAS;AACpC,KAAI,CAAC,MAAO;AAEZ,KAAI,UAAU,KAAM,SAAQ;AAK5B,KACE,OAAO,UAAU,aAChB,MAAM,WAAW,IAAI,IAAI,MAAM,WAAW,KAAK,EAEhD,SAAQ,WAAW,MAAM,CAAC,SAAS;CAGrC,MAAM,QAAQ,MAAM,MAAM,qBAAqB;CAC/C,IAAI,OAAO;AAEX,KAAI,MACF,QAAO,MAAM;CAGf,MAAM,SAAS,EACN,OACR;AAED,KAAI,QAAQ,SAAS,UACnB,QAAO,OAAO,QAAQ;EACpB,mBAAmB;EACnB,uBAAuB,4BAA4B,MAAM;EAC1D,CAAC;AAGJ,QAAO;;AAGT,WAAW,iBAAiB,CAAC,QAAQ"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { parseColor } from "../utils/styles.mjs";
|
|
2
|
+
import { convertColorChainToRgbChain } from "./createStyle.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/styles/color.ts
|
|
5
|
+
function colorStyle({ color }) {
|
|
6
|
+
if (!color) return;
|
|
7
|
+
if (color === true) color = "currentColor";
|
|
8
|
+
if (typeof color === "string" && (color.startsWith("#") || color.startsWith("(#"))) color = parseColor(color).color || color;
|
|
9
|
+
const match = color.match(/var\(--(.+?)-color/);
|
|
10
|
+
let name = "";
|
|
11
|
+
if (match) name = match[1];
|
|
12
|
+
const styles = { color };
|
|
13
|
+
if (name && name !== "current") Object.assign(styles, {
|
|
14
|
+
"--current-color": color,
|
|
15
|
+
"--current-color-rgb": convertColorChainToRgbChain(color)
|
|
16
|
+
});
|
|
17
|
+
return styles;
|
|
18
|
+
}
|
|
19
|
+
colorStyle.__lookupStyles = ["color"];
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { colorStyle };
|
|
23
|
+
//# sourceMappingURL=color.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.mjs","names":[],"sources":["../../src/styles/color.ts"],"sourcesContent":["import { parseColor } from '../utils/styles';\n\nimport { convertColorChainToRgbChain } from './createStyle';\n\nexport function colorStyle({ color }) {\n if (!color) return;\n\n if (color === true) color = 'currentColor';\n\n // Handle color values that need parsing:\n // - Simple color tokens: #placeholder\n // - Color fallback syntax: (#placeholder, #dark-04)\n if (\n typeof color === 'string' &&\n (color.startsWith('#') || color.startsWith('(#'))\n ) {\n color = parseColor(color).color || color;\n }\n\n const match = color.match(/var\\(--(.+?)-color/);\n let name = '';\n\n if (match) {\n name = match[1];\n }\n\n const styles = {\n color: color,\n };\n\n if (name && name !== 'current') {\n Object.assign(styles, {\n '--current-color': color,\n '--current-color-rgb': convertColorChainToRgbChain(color),\n });\n }\n\n return styles;\n}\n\ncolorStyle.__lookupStyles = ['color'];\n"],"mappings":";;;;AAIA,SAAgB,WAAW,EAAE,SAAS;AACpC,KAAI,CAAC,MAAO;AAEZ,KAAI,UAAU,KAAM,SAAQ;AAK5B,KACE,OAAO,UAAU,aAChB,MAAM,WAAW,IAAI,IAAI,MAAM,WAAW,KAAK,EAEhD,SAAQ,WAAW,MAAM,CAAC,SAAS;CAGrC,MAAM,QAAQ,MAAM,MAAM,qBAAqB;CAC/C,IAAI,OAAO;AAEX,KAAI,MACF,QAAO,MAAM;CAGf,MAAM,SAAS,EACN,OACR;AAED,KAAI,QAAQ,SAAS,UACnB,QAAO,OAAO,QAAQ;EACpB,mBAAmB;EACnB,uBAAuB,4BAA4B,MAAM;EAC1D,CAAC;AAGJ,QAAO;;AAGT,WAAW,iBAAiB,CAAC,QAAQ"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { getRgbValuesFromRgbaString, normalizeColorTokenValue, parseColor, parseStyle, strToRgb } from "../utils/styles.js";
|
|
2
|
+
import { toSnakeCase } from "../utils/string.js";
|
|
3
|
+
|
|
4
|
+
//#region src/styles/createStyle.ts
|
|
5
|
+
const CACHE = {};
|
|
6
|
+
/**
|
|
7
|
+
* Convert color fallback chain to RGB fallback chain.
|
|
8
|
+
* Example: var(--primary-color, var(--secondary-color)) → var(--primary-color-rgb, var(--secondary-color-rgb))
|
|
9
|
+
*/
|
|
10
|
+
function convertColorChainToRgbChain(colorValue) {
|
|
11
|
+
const rgbVarMatch = colorValue.match(/^rgba?\(\s*(var\(--[a-z0-9-]+-color-rgb\))\s*\//);
|
|
12
|
+
if (rgbVarMatch) return rgbVarMatch[1];
|
|
13
|
+
const match = colorValue.match(/var\(--([a-z0-9-]+)-color\s*(?:,\s*(.+))?\)/);
|
|
14
|
+
if (!match) {
|
|
15
|
+
if (colorValue.startsWith("rgb(") || colorValue.startsWith("rgba(")) return colorValue;
|
|
16
|
+
const rgba = strToRgb(colorValue);
|
|
17
|
+
if (rgba) return getRgbValuesFromRgbaString(rgba).join(" ");
|
|
18
|
+
return colorValue;
|
|
19
|
+
}
|
|
20
|
+
const [, name, fallback] = match;
|
|
21
|
+
if (!fallback) return `var(--${name}-color-rgb)`;
|
|
22
|
+
return `var(--${name}-color-rgb, ${convertColorChainToRgbChain(fallback.trim())})`;
|
|
23
|
+
}
|
|
24
|
+
function createStyle(styleName, cssStyle, converter) {
|
|
25
|
+
const key = `${styleName}.${cssStyle ?? ""}`;
|
|
26
|
+
if (!CACHE[key]) {
|
|
27
|
+
const styleHandler = (styleMap) => {
|
|
28
|
+
let styleValue = styleMap[styleName];
|
|
29
|
+
if (styleValue == null || styleValue === false) return;
|
|
30
|
+
let finalCssStyle;
|
|
31
|
+
const isColorToken = !cssStyle && typeof styleName === "string" && styleName.startsWith("#");
|
|
32
|
+
if (isColorToken) finalCssStyle = `--${toSnakeCase(styleName.slice(1)).replace(/^-+/, "")}-color`;
|
|
33
|
+
else finalCssStyle = cssStyle || toSnakeCase(styleName).replace(/^\$/, "--");
|
|
34
|
+
if (isColorToken) {
|
|
35
|
+
const normalized = normalizeColorTokenValue(styleValue);
|
|
36
|
+
if (normalized === null) return;
|
|
37
|
+
styleValue = normalized;
|
|
38
|
+
}
|
|
39
|
+
if (converter && typeof styleValue !== "string") {
|
|
40
|
+
styleValue = converter(styleValue);
|
|
41
|
+
if (!styleValue) return;
|
|
42
|
+
}
|
|
43
|
+
if (typeof styleValue === "string" && finalCssStyle.startsWith("--") && finalCssStyle.endsWith("-color")) {
|
|
44
|
+
styleValue = styleValue.trim();
|
|
45
|
+
const rgba = strToRgb(styleValue);
|
|
46
|
+
const { color, name } = parseColor(styleValue);
|
|
47
|
+
if (name && rgba) return {
|
|
48
|
+
[finalCssStyle]: `var(--${name}-color, ${rgba})`,
|
|
49
|
+
[`${finalCssStyle}-rgb`]: `var(--${name}-color-rgb, ${getRgbValuesFromRgbaString(rgba).join(" ")})`
|
|
50
|
+
};
|
|
51
|
+
else if (name) {
|
|
52
|
+
if (color) return {
|
|
53
|
+
[finalCssStyle]: color,
|
|
54
|
+
[`${finalCssStyle}-rgb`]: convertColorChainToRgbChain(color)
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
[finalCssStyle]: `var(--${name}-color)`,
|
|
58
|
+
[`${finalCssStyle}-rgb`]: `var(--${name}-color-rgb)`
|
|
59
|
+
};
|
|
60
|
+
} else if (rgba) return {
|
|
61
|
+
[finalCssStyle]: rgba,
|
|
62
|
+
[`${finalCssStyle}-rgb`]: getRgbValuesFromRgbaString(rgba).join(" ")
|
|
63
|
+
};
|
|
64
|
+
return { [finalCssStyle]: color };
|
|
65
|
+
}
|
|
66
|
+
const processed = parseStyle(styleValue);
|
|
67
|
+
return { [finalCssStyle]: processed.output };
|
|
68
|
+
};
|
|
69
|
+
styleHandler.__lookupStyles = [styleName];
|
|
70
|
+
CACHE[key] = styleHandler;
|
|
71
|
+
}
|
|
72
|
+
return CACHE[key];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
export { convertColorChainToRgbChain, createStyle };
|
|
77
|
+
//# sourceMappingURL=createStyle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createStyle.js","names":[],"sources":["../../src/styles/createStyle.ts"],"sourcesContent":["import { toSnakeCase } from '../utils/string';\nimport {\n getRgbValuesFromRgbaString,\n normalizeColorTokenValue,\n parseColor,\n parseStyle,\n strToRgb,\n} from '../utils/styles';\nimport type { StyleValue } from '../utils/styles';\n\nconst CACHE = {};\n\n/**\n * Convert color fallback chain to RGB fallback chain.\n * Example: var(--primary-color, var(--secondary-color)) → var(--primary-color-rgb, var(--secondary-color-rgb))\n */\nexport function convertColorChainToRgbChain(colorValue: string): string {\n // Handle rgb(var(--name-color-rgb) / alpha) pattern.\n // When #name.opacity is parsed, the classifier produces rgb(var(--name-color-rgb) / .opacity).\n // The RGB chain should be just the inner var() reference, without the rgb() wrapper and opacity.\n const rgbVarMatch = colorValue.match(\n /^rgba?\\(\\s*(var\\(--[a-z0-9-]+-color-rgb\\))\\s*\\//,\n );\n if (rgbVarMatch) {\n return rgbVarMatch[1];\n }\n\n // Match var(--name-color, ...) pattern\n const varPattern = /var\\(--([a-z0-9-]+)-color\\s*(?:,\\s*(.+))?\\)/;\n const match = colorValue.match(varPattern);\n\n if (!match) {\n // Not a color variable, check if it's a color function or literal\n if (colorValue.startsWith('rgb(') || colorValue.startsWith('rgba(')) {\n return colorValue;\n }\n // Try to convert to RGB if possible\n const rgba = strToRgb(colorValue);\n if (rgba) {\n const rgbValues = getRgbValuesFromRgbaString(rgba);\n return rgbValues.join(' ');\n }\n return colorValue;\n }\n\n const [, name, fallback] = match;\n\n if (!fallback) {\n // Simple var without fallback\n return `var(--${name}-color-rgb)`;\n }\n\n // Recursively process the fallback\n const processedFallback = convertColorChainToRgbChain(fallback.trim());\n return `var(--${name}-color-rgb, ${processedFallback})`;\n}\n\nexport function createStyle(\n styleName: string,\n cssStyle?: string,\n converter?: (styleValue: string | number | true) => string | undefined,\n) {\n const key = `${styleName}.${cssStyle ?? ''}`;\n\n if (!CACHE[key]) {\n const styleHandler = (styleMap) => {\n let styleValue = styleMap[styleName];\n\n if (styleValue == null || styleValue === false) return;\n\n // Map style name to final CSS property.\n // - \"$foo\" → \"--foo\"\n // - \"#name\" → \"--name-color\" (alternative color definition syntax)\n let finalCssStyle: string;\n const isColorToken =\n !cssStyle && typeof styleName === 'string' && styleName.startsWith('#');\n\n if (isColorToken) {\n const raw = styleName.slice(1);\n // Convert camelCase to kebab and remove possible leading dash from uppercase start\n const name = toSnakeCase(raw).replace(/^-+/, '');\n finalCssStyle = `--${name}-color`;\n } else {\n finalCssStyle = cssStyle || toSnakeCase(styleName).replace(/^\\$/, '--');\n }\n\n // For color tokens, normalize boolean values (true → 'transparent', false → skip)\n if (isColorToken) {\n const normalized = normalizeColorTokenValue(styleValue);\n if (normalized === null) return; // Skip false values\n styleValue = normalized;\n }\n\n // convert non-string values\n if (converter && typeof styleValue !== 'string') {\n styleValue = converter(styleValue);\n\n if (!styleValue) return;\n }\n\n if (\n typeof styleValue === 'string' &&\n finalCssStyle.startsWith('--') &&\n finalCssStyle.endsWith('-color')\n ) {\n styleValue = styleValue.trim();\n\n const rgba = strToRgb(styleValue);\n\n const { color, name } = parseColor(styleValue);\n\n if (name && rgba) {\n return {\n [finalCssStyle]: `var(--${name}-color, ${rgba})`,\n [`${finalCssStyle}-rgb`]: `var(--${name}-color-rgb, ${getRgbValuesFromRgbaString(\n rgba,\n ).join(' ')})`,\n };\n } else if (name) {\n if (color) {\n return {\n [finalCssStyle]: color,\n [`${finalCssStyle}-rgb`]: convertColorChainToRgbChain(color),\n };\n }\n\n return {\n [finalCssStyle]: `var(--${name}-color)`,\n [`${finalCssStyle}-rgb`]: `var(--${name}-color-rgb)`,\n };\n } else if (rgba) {\n return {\n [finalCssStyle]: rgba,\n [`${finalCssStyle}-rgb`]:\n getRgbValuesFromRgbaString(rgba).join(' '),\n };\n }\n\n return {\n [finalCssStyle]: color,\n };\n }\n\n const processed = parseStyle(styleValue as StyleValue);\n return { [finalCssStyle]: processed.output };\n };\n\n styleHandler.__lookupStyles = [styleName];\n\n CACHE[key] = styleHandler;\n }\n\n return CACHE[key];\n}\n"],"mappings":";;;;AAUA,MAAM,QAAQ,EAAE;;;;;AAMhB,SAAgB,4BAA4B,YAA4B;CAItE,MAAM,cAAc,WAAW,MAC7B,kDACD;AACD,KAAI,YACF,QAAO,YAAY;CAKrB,MAAM,QAAQ,WAAW,MADN,8CACuB;AAE1C,KAAI,CAAC,OAAO;AAEV,MAAI,WAAW,WAAW,OAAO,IAAI,WAAW,WAAW,QAAQ,CACjE,QAAO;EAGT,MAAM,OAAO,SAAS,WAAW;AACjC,MAAI,KAEF,QADkB,2BAA2B,KAAK,CACjC,KAAK,IAAI;AAE5B,SAAO;;CAGT,MAAM,GAAG,MAAM,YAAY;AAE3B,KAAI,CAAC,SAEH,QAAO,SAAS,KAAK;AAKvB,QAAO,SAAS,KAAK,cADK,4BAA4B,SAAS,MAAM,CAAC,CACjB;;AAGvD,SAAgB,YACd,WACA,UACA,WACA;CACA,MAAM,MAAM,GAAG,UAAU,GAAG,YAAY;AAExC,KAAI,CAAC,MAAM,MAAM;EACf,MAAM,gBAAgB,aAAa;GACjC,IAAI,aAAa,SAAS;AAE1B,OAAI,cAAc,QAAQ,eAAe,MAAO;GAKhD,IAAI;GACJ,MAAM,eACJ,CAAC,YAAY,OAAO,cAAc,YAAY,UAAU,WAAW,IAAI;AAEzE,OAAI,aAIF,iBAAgB,KADH,YAFD,UAAU,MAAM,EAAE,CAED,CAAC,QAAQ,OAAO,GAAG,CACtB;OAE1B,iBAAgB,YAAY,YAAY,UAAU,CAAC,QAAQ,OAAO,KAAK;AAIzE,OAAI,cAAc;IAChB,MAAM,aAAa,yBAAyB,WAAW;AACvD,QAAI,eAAe,KAAM;AACzB,iBAAa;;AAIf,OAAI,aAAa,OAAO,eAAe,UAAU;AAC/C,iBAAa,UAAU,WAAW;AAElC,QAAI,CAAC,WAAY;;AAGnB,OACE,OAAO,eAAe,YACtB,cAAc,WAAW,KAAK,IAC9B,cAAc,SAAS,SAAS,EAChC;AACA,iBAAa,WAAW,MAAM;IAE9B,MAAM,OAAO,SAAS,WAAW;IAEjC,MAAM,EAAE,OAAO,SAAS,WAAW,WAAW;AAE9C,QAAI,QAAQ,KACV,QAAO;MACJ,gBAAgB,SAAS,KAAK,UAAU,KAAK;MAC7C,GAAG,cAAc,QAAQ,SAAS,KAAK,cAAc,2BACpD,KACD,CAAC,KAAK,IAAI,CAAC;KACb;aACQ,MAAM;AACf,SAAI,MACF,QAAO;OACJ,gBAAgB;OAChB,GAAG,cAAc,QAAQ,4BAA4B,MAAM;MAC7D;AAGH,YAAO;OACJ,gBAAgB,SAAS,KAAK;OAC9B,GAAG,cAAc,QAAQ,SAAS,KAAK;MACzC;eACQ,KACT,QAAO;MACJ,gBAAgB;MAChB,GAAG,cAAc,QAChB,2BAA2B,KAAK,CAAC,KAAK,IAAI;KAC7C;AAGH,WAAO,GACJ,gBAAgB,OAClB;;GAGH,MAAM,YAAY,WAAW,WAAyB;AACtD,UAAO,GAAG,gBAAgB,UAAU,QAAQ;;AAG9C,eAAa,iBAAiB,CAAC,UAAU;AAEzC,QAAM,OAAO;;AAGf,QAAO,MAAM"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { getRgbValuesFromRgbaString, normalizeColorTokenValue, parseColor, parseStyle, strToRgb } from "../utils/styles.mjs";
|
|
2
|
+
import { toSnakeCase } from "../utils/string.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/styles/createStyle.ts
|
|
5
|
+
const CACHE = {};
|
|
6
|
+
/**
|
|
7
|
+
* Convert color fallback chain to RGB fallback chain.
|
|
8
|
+
* Example: var(--primary-color, var(--secondary-color)) → var(--primary-color-rgb, var(--secondary-color-rgb))
|
|
9
|
+
*/
|
|
10
|
+
function convertColorChainToRgbChain(colorValue) {
|
|
11
|
+
const rgbVarMatch = colorValue.match(/^rgba?\(\s*(var\(--[a-z0-9-]+-color-rgb\))\s*\//);
|
|
12
|
+
if (rgbVarMatch) return rgbVarMatch[1];
|
|
13
|
+
const match = colorValue.match(/var\(--([a-z0-9-]+)-color\s*(?:,\s*(.+))?\)/);
|
|
14
|
+
if (!match) {
|
|
15
|
+
if (colorValue.startsWith("rgb(") || colorValue.startsWith("rgba(")) return colorValue;
|
|
16
|
+
const rgba = strToRgb(colorValue);
|
|
17
|
+
if (rgba) return getRgbValuesFromRgbaString(rgba).join(" ");
|
|
18
|
+
return colorValue;
|
|
19
|
+
}
|
|
20
|
+
const [, name, fallback] = match;
|
|
21
|
+
if (!fallback) return `var(--${name}-color-rgb)`;
|
|
22
|
+
return `var(--${name}-color-rgb, ${convertColorChainToRgbChain(fallback.trim())})`;
|
|
23
|
+
}
|
|
24
|
+
function createStyle(styleName, cssStyle, converter) {
|
|
25
|
+
const key = `${styleName}.${cssStyle ?? ""}`;
|
|
26
|
+
if (!CACHE[key]) {
|
|
27
|
+
const styleHandler = (styleMap) => {
|
|
28
|
+
let styleValue = styleMap[styleName];
|
|
29
|
+
if (styleValue == null || styleValue === false) return;
|
|
30
|
+
let finalCssStyle;
|
|
31
|
+
const isColorToken = !cssStyle && typeof styleName === "string" && styleName.startsWith("#");
|
|
32
|
+
if (isColorToken) finalCssStyle = `--${toSnakeCase(styleName.slice(1)).replace(/^-+/, "")}-color`;
|
|
33
|
+
else finalCssStyle = cssStyle || toSnakeCase(styleName).replace(/^\$/, "--");
|
|
34
|
+
if (isColorToken) {
|
|
35
|
+
const normalized = normalizeColorTokenValue(styleValue);
|
|
36
|
+
if (normalized === null) return;
|
|
37
|
+
styleValue = normalized;
|
|
38
|
+
}
|
|
39
|
+
if (converter && typeof styleValue !== "string") {
|
|
40
|
+
styleValue = converter(styleValue);
|
|
41
|
+
if (!styleValue) return;
|
|
42
|
+
}
|
|
43
|
+
if (typeof styleValue === "string" && finalCssStyle.startsWith("--") && finalCssStyle.endsWith("-color")) {
|
|
44
|
+
styleValue = styleValue.trim();
|
|
45
|
+
const rgba = strToRgb(styleValue);
|
|
46
|
+
const { color, name } = parseColor(styleValue);
|
|
47
|
+
if (name && rgba) return {
|
|
48
|
+
[finalCssStyle]: `var(--${name}-color, ${rgba})`,
|
|
49
|
+
[`${finalCssStyle}-rgb`]: `var(--${name}-color-rgb, ${getRgbValuesFromRgbaString(rgba).join(" ")})`
|
|
50
|
+
};
|
|
51
|
+
else if (name) {
|
|
52
|
+
if (color) return {
|
|
53
|
+
[finalCssStyle]: color,
|
|
54
|
+
[`${finalCssStyle}-rgb`]: convertColorChainToRgbChain(color)
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
[finalCssStyle]: `var(--${name}-color)`,
|
|
58
|
+
[`${finalCssStyle}-rgb`]: `var(--${name}-color-rgb)`
|
|
59
|
+
};
|
|
60
|
+
} else if (rgba) return {
|
|
61
|
+
[finalCssStyle]: rgba,
|
|
62
|
+
[`${finalCssStyle}-rgb`]: getRgbValuesFromRgbaString(rgba).join(" ")
|
|
63
|
+
};
|
|
64
|
+
return { [finalCssStyle]: color };
|
|
65
|
+
}
|
|
66
|
+
const processed = parseStyle(styleValue);
|
|
67
|
+
return { [finalCssStyle]: processed.output };
|
|
68
|
+
};
|
|
69
|
+
styleHandler.__lookupStyles = [styleName];
|
|
70
|
+
CACHE[key] = styleHandler;
|
|
71
|
+
}
|
|
72
|
+
return CACHE[key];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
export { convertColorChainToRgbChain, createStyle };
|
|
77
|
+
//# sourceMappingURL=createStyle.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createStyle.mjs","names":[],"sources":["../../src/styles/createStyle.ts"],"sourcesContent":["import { toSnakeCase } from '../utils/string';\nimport {\n getRgbValuesFromRgbaString,\n normalizeColorTokenValue,\n parseColor,\n parseStyle,\n strToRgb,\n} from '../utils/styles';\nimport type { StyleValue } from '../utils/styles';\n\nconst CACHE = {};\n\n/**\n * Convert color fallback chain to RGB fallback chain.\n * Example: var(--primary-color, var(--secondary-color)) → var(--primary-color-rgb, var(--secondary-color-rgb))\n */\nexport function convertColorChainToRgbChain(colorValue: string): string {\n // Handle rgb(var(--name-color-rgb) / alpha) pattern.\n // When #name.opacity is parsed, the classifier produces rgb(var(--name-color-rgb) / .opacity).\n // The RGB chain should be just the inner var() reference, without the rgb() wrapper and opacity.\n const rgbVarMatch = colorValue.match(\n /^rgba?\\(\\s*(var\\(--[a-z0-9-]+-color-rgb\\))\\s*\\//,\n );\n if (rgbVarMatch) {\n return rgbVarMatch[1];\n }\n\n // Match var(--name-color, ...) pattern\n const varPattern = /var\\(--([a-z0-9-]+)-color\\s*(?:,\\s*(.+))?\\)/;\n const match = colorValue.match(varPattern);\n\n if (!match) {\n // Not a color variable, check if it's a color function or literal\n if (colorValue.startsWith('rgb(') || colorValue.startsWith('rgba(')) {\n return colorValue;\n }\n // Try to convert to RGB if possible\n const rgba = strToRgb(colorValue);\n if (rgba) {\n const rgbValues = getRgbValuesFromRgbaString(rgba);\n return rgbValues.join(' ');\n }\n return colorValue;\n }\n\n const [, name, fallback] = match;\n\n if (!fallback) {\n // Simple var without fallback\n return `var(--${name}-color-rgb)`;\n }\n\n // Recursively process the fallback\n const processedFallback = convertColorChainToRgbChain(fallback.trim());\n return `var(--${name}-color-rgb, ${processedFallback})`;\n}\n\nexport function createStyle(\n styleName: string,\n cssStyle?: string,\n converter?: (styleValue: string | number | true) => string | undefined,\n) {\n const key = `${styleName}.${cssStyle ?? ''}`;\n\n if (!CACHE[key]) {\n const styleHandler = (styleMap) => {\n let styleValue = styleMap[styleName];\n\n if (styleValue == null || styleValue === false) return;\n\n // Map style name to final CSS property.\n // - \"$foo\" → \"--foo\"\n // - \"#name\" → \"--name-color\" (alternative color definition syntax)\n let finalCssStyle: string;\n const isColorToken =\n !cssStyle && typeof styleName === 'string' && styleName.startsWith('#');\n\n if (isColorToken) {\n const raw = styleName.slice(1);\n // Convert camelCase to kebab and remove possible leading dash from uppercase start\n const name = toSnakeCase(raw).replace(/^-+/, '');\n finalCssStyle = `--${name}-color`;\n } else {\n finalCssStyle = cssStyle || toSnakeCase(styleName).replace(/^\\$/, '--');\n }\n\n // For color tokens, normalize boolean values (true → 'transparent', false → skip)\n if (isColorToken) {\n const normalized = normalizeColorTokenValue(styleValue);\n if (normalized === null) return; // Skip false values\n styleValue = normalized;\n }\n\n // convert non-string values\n if (converter && typeof styleValue !== 'string') {\n styleValue = converter(styleValue);\n\n if (!styleValue) return;\n }\n\n if (\n typeof styleValue === 'string' &&\n finalCssStyle.startsWith('--') &&\n finalCssStyle.endsWith('-color')\n ) {\n styleValue = styleValue.trim();\n\n const rgba = strToRgb(styleValue);\n\n const { color, name } = parseColor(styleValue);\n\n if (name && rgba) {\n return {\n [finalCssStyle]: `var(--${name}-color, ${rgba})`,\n [`${finalCssStyle}-rgb`]: `var(--${name}-color-rgb, ${getRgbValuesFromRgbaString(\n rgba,\n ).join(' ')})`,\n };\n } else if (name) {\n if (color) {\n return {\n [finalCssStyle]: color,\n [`${finalCssStyle}-rgb`]: convertColorChainToRgbChain(color),\n };\n }\n\n return {\n [finalCssStyle]: `var(--${name}-color)`,\n [`${finalCssStyle}-rgb`]: `var(--${name}-color-rgb)`,\n };\n } else if (rgba) {\n return {\n [finalCssStyle]: rgba,\n [`${finalCssStyle}-rgb`]:\n getRgbValuesFromRgbaString(rgba).join(' '),\n };\n }\n\n return {\n [finalCssStyle]: color,\n };\n }\n\n const processed = parseStyle(styleValue as StyleValue);\n return { [finalCssStyle]: processed.output };\n };\n\n styleHandler.__lookupStyles = [styleName];\n\n CACHE[key] = styleHandler;\n }\n\n return CACHE[key];\n}\n"],"mappings":";;;;AAUA,MAAM,QAAQ,EAAE;;;;;AAMhB,SAAgB,4BAA4B,YAA4B;CAItE,MAAM,cAAc,WAAW,MAC7B,kDACD;AACD,KAAI,YACF,QAAO,YAAY;CAKrB,MAAM,QAAQ,WAAW,MADN,8CACuB;AAE1C,KAAI,CAAC,OAAO;AAEV,MAAI,WAAW,WAAW,OAAO,IAAI,WAAW,WAAW,QAAQ,CACjE,QAAO;EAGT,MAAM,OAAO,SAAS,WAAW;AACjC,MAAI,KAEF,QADkB,2BAA2B,KAAK,CACjC,KAAK,IAAI;AAE5B,SAAO;;CAGT,MAAM,GAAG,MAAM,YAAY;AAE3B,KAAI,CAAC,SAEH,QAAO,SAAS,KAAK;AAKvB,QAAO,SAAS,KAAK,cADK,4BAA4B,SAAS,MAAM,CAAC,CACjB;;AAGvD,SAAgB,YACd,WACA,UACA,WACA;CACA,MAAM,MAAM,GAAG,UAAU,GAAG,YAAY;AAExC,KAAI,CAAC,MAAM,MAAM;EACf,MAAM,gBAAgB,aAAa;GACjC,IAAI,aAAa,SAAS;AAE1B,OAAI,cAAc,QAAQ,eAAe,MAAO;GAKhD,IAAI;GACJ,MAAM,eACJ,CAAC,YAAY,OAAO,cAAc,YAAY,UAAU,WAAW,IAAI;AAEzE,OAAI,aAIF,iBAAgB,KADH,YAFD,UAAU,MAAM,EAAE,CAED,CAAC,QAAQ,OAAO,GAAG,CACtB;OAE1B,iBAAgB,YAAY,YAAY,UAAU,CAAC,QAAQ,OAAO,KAAK;AAIzE,OAAI,cAAc;IAChB,MAAM,aAAa,yBAAyB,WAAW;AACvD,QAAI,eAAe,KAAM;AACzB,iBAAa;;AAIf,OAAI,aAAa,OAAO,eAAe,UAAU;AAC/C,iBAAa,UAAU,WAAW;AAElC,QAAI,CAAC,WAAY;;AAGnB,OACE,OAAO,eAAe,YACtB,cAAc,WAAW,KAAK,IAC9B,cAAc,SAAS,SAAS,EAChC;AACA,iBAAa,WAAW,MAAM;IAE9B,MAAM,OAAO,SAAS,WAAW;IAEjC,MAAM,EAAE,OAAO,SAAS,WAAW,WAAW;AAE9C,QAAI,QAAQ,KACV,QAAO;MACJ,gBAAgB,SAAS,KAAK,UAAU,KAAK;MAC7C,GAAG,cAAc,QAAQ,SAAS,KAAK,cAAc,2BACpD,KACD,CAAC,KAAK,IAAI,CAAC;KACb;aACQ,MAAM;AACf,SAAI,MACF,QAAO;OACJ,gBAAgB;OAChB,GAAG,cAAc,QAAQ,4BAA4B,MAAM;MAC7D;AAGH,YAAO;OACJ,gBAAgB,SAAS,KAAK;OAC9B,GAAG,cAAc,QAAQ,SAAS,KAAK;MACzC;eACQ,KACT,QAAO;MACJ,gBAAgB;MAChB,GAAG,cAAc,QAChB,2BAA2B,KAAK,CAAC,KAAK,IAAI;KAC7C;AAGH,WAAO,GACJ,gBAAgB,OAClB;;GAGH,MAAM,YAAY,WAAW,WAAyB;AACtD,UAAO,GAAG,gBAAgB,UAAU,QAAQ;;AAG9C,eAAa,iBAAiB,CAAC,UAAU;AAEzC,QAAM,OAAO;;AAGf,QAAO,MAAM"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { makeEmptyDetails } from "../parser/types.js";
|
|
2
|
+
import { parseStyle } from "../utils/styles.js";
|
|
3
|
+
|
|
4
|
+
//#region src/styles/dimension.ts
|
|
5
|
+
const DEFAULT_MIN_SIZE = "var(--gap)";
|
|
6
|
+
const DEFAULT_MAX_SIZE = "100%";
|
|
7
|
+
/**
|
|
8
|
+
* Parse a dimension value (string, number, or boolean) into a CSS value
|
|
9
|
+
*/
|
|
10
|
+
function parseDimensionValue(val) {
|
|
11
|
+
if (val == null) return null;
|
|
12
|
+
if (typeof val === "number") return `${val}px`;
|
|
13
|
+
if (val === true) return "initial";
|
|
14
|
+
return parseStyle(String(val)).groups[0]?.values[0] || null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Creates a dimension style handler for width or height.
|
|
18
|
+
*
|
|
19
|
+
* Supports:
|
|
20
|
+
* - Main dimension prop (width/height) with syntax for min/max
|
|
21
|
+
* - Separate min/max props (minWidth/maxWidth or minHeight/maxHeight)
|
|
22
|
+
*
|
|
23
|
+
* Priority: Individual min/max props override values from main prop syntax
|
|
24
|
+
*/
|
|
25
|
+
function dimensionStyle(name) {
|
|
26
|
+
const minStyle = `min-${name}`;
|
|
27
|
+
const maxStyle = `max-${name}`;
|
|
28
|
+
return ({ value, min, max }) => {
|
|
29
|
+
if (value == null && min == null && max == null) return;
|
|
30
|
+
if (value === true) {
|
|
31
|
+
const styles = {
|
|
32
|
+
[name]: "auto",
|
|
33
|
+
[minStyle]: "initial",
|
|
34
|
+
[maxStyle]: "initial"
|
|
35
|
+
};
|
|
36
|
+
const minVal = parseDimensionValue(min);
|
|
37
|
+
const maxVal = parseDimensionValue(max);
|
|
38
|
+
if (minVal) styles[minStyle] = minVal;
|
|
39
|
+
if (maxVal) styles[maxStyle] = maxVal;
|
|
40
|
+
return styles;
|
|
41
|
+
}
|
|
42
|
+
const styles = {
|
|
43
|
+
[name]: "auto",
|
|
44
|
+
[minStyle]: "initial",
|
|
45
|
+
[maxStyle]: "initial"
|
|
46
|
+
};
|
|
47
|
+
if (value != null) {
|
|
48
|
+
let val = value;
|
|
49
|
+
if (typeof val === "number") val = `${val}px`;
|
|
50
|
+
val = String(val);
|
|
51
|
+
const { mods, values } = parseStyle(val).groups[0] ?? makeEmptyDetails();
|
|
52
|
+
let flag = false;
|
|
53
|
+
for (const mod of mods) switch (mod) {
|
|
54
|
+
case "min":
|
|
55
|
+
styles[minStyle] = values[0] || DEFAULT_MIN_SIZE;
|
|
56
|
+
flag = true;
|
|
57
|
+
break;
|
|
58
|
+
case "max":
|
|
59
|
+
styles[maxStyle] = values[0] || DEFAULT_MAX_SIZE;
|
|
60
|
+
flag = true;
|
|
61
|
+
break;
|
|
62
|
+
case "fixed": {
|
|
63
|
+
const fixedValue = values[0] || "max-content";
|
|
64
|
+
styles[minStyle] = fixedValue;
|
|
65
|
+
styles[name] = fixedValue;
|
|
66
|
+
styles[maxStyle] = fixedValue;
|
|
67
|
+
flag = true;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
default: break;
|
|
71
|
+
}
|
|
72
|
+
if (!flag || !mods.length) if (values.length === 2) {
|
|
73
|
+
styles[minStyle] = values[0];
|
|
74
|
+
styles[maxStyle] = values[1];
|
|
75
|
+
} else if (values.length === 3) {
|
|
76
|
+
styles[minStyle] = values[0];
|
|
77
|
+
styles[name] = values[1];
|
|
78
|
+
styles[maxStyle] = values[2];
|
|
79
|
+
} else styles[name] = values[0] || "auto";
|
|
80
|
+
if (styles[name] === "stretch") if (name === "width") styles[name] = [
|
|
81
|
+
"stretch",
|
|
82
|
+
"-webkit-fill-available",
|
|
83
|
+
"-moz-available"
|
|
84
|
+
];
|
|
85
|
+
else styles[name] = "auto";
|
|
86
|
+
}
|
|
87
|
+
const minVal = parseDimensionValue(min);
|
|
88
|
+
const maxVal = parseDimensionValue(max);
|
|
89
|
+
if (minVal) styles[minStyle] = minVal;
|
|
90
|
+
if (maxVal) styles[maxStyle] = maxVal;
|
|
91
|
+
return styles;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
export { dimensionStyle };
|
|
97
|
+
//# sourceMappingURL=dimension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dimension.js","names":[],"sources":["../../src/styles/dimension.ts"],"sourcesContent":["import { makeEmptyDetails } from '../parser/types';\nimport { parseStyle } from '../utils/styles';\n\nconst DEFAULT_MIN_SIZE = 'var(--gap)';\nconst DEFAULT_MAX_SIZE = '100%';\n\n/**\n * Parse a dimension value (string, number, or boolean) into a CSS value\n */\nfunction parseDimensionValue(\n val: string | number | boolean | undefined,\n): string | null {\n if (val == null) return null;\n if (typeof val === 'number') return `${val}px`;\n if (val === true) return 'initial';\n\n const processed = parseStyle(String(val));\n return processed.groups[0]?.values[0] || null;\n}\n\ninterface DimensionProps {\n value?: string | number | boolean;\n min?: string | number | boolean;\n max?: string | number | boolean;\n}\n\n/**\n * Creates a dimension style handler for width or height.\n *\n * Supports:\n * - Main dimension prop (width/height) with syntax for min/max\n * - Separate min/max props (minWidth/maxWidth or minHeight/maxHeight)\n *\n * Priority: Individual min/max props override values from main prop syntax\n */\nexport function dimensionStyle(name: 'width' | 'height') {\n const minStyle = `min-${name}`;\n const maxStyle = `max-${name}`;\n\n return ({ value, min, max }: DimensionProps) => {\n // If nothing is defined, return undefined\n if (value == null && min == null && max == null) return;\n\n // Handle boolean true on main value - reset all to initial\n if (value === true) {\n const styles: Record<string, string | string[]> = {\n [name]: 'auto',\n [minStyle]: 'initial',\n [maxStyle]: 'initial',\n };\n\n // Apply individual min/max overrides\n const minVal = parseDimensionValue(min);\n const maxVal = parseDimensionValue(max);\n if (minVal) styles[minStyle] = minVal;\n if (maxVal) styles[maxStyle] = maxVal;\n\n return styles;\n }\n\n const styles: Record<string, string | string[]> = {\n [name]: 'auto',\n [minStyle]: 'initial',\n [maxStyle]: 'initial',\n };\n\n // Process main dimension value\n if (value != null) {\n let val = value;\n if (typeof val === 'number') {\n val = `${val}px`;\n }\n\n val = String(val);\n\n const processed = parseStyle(val);\n const { mods, values } =\n processed.groups[0] ?? makeEmptyDetails();\n\n let flag = false;\n\n for (const mod of mods) {\n switch (mod) {\n case 'min':\n styles[minStyle] = values[0] || DEFAULT_MIN_SIZE;\n flag = true;\n break;\n case 'max':\n styles[maxStyle] = values[0] || DEFAULT_MAX_SIZE;\n flag = true;\n break;\n case 'fixed': {\n // Fixed modifier: set all three dimensions to the same value\n const fixedValue = values[0] || 'max-content';\n styles[minStyle] = fixedValue;\n styles[name] = fixedValue;\n styles[maxStyle] = fixedValue;\n flag = true;\n break;\n }\n default:\n break;\n }\n }\n\n if (!flag || !mods.length) {\n if (values.length === 2) {\n styles[minStyle] = values[0];\n styles[maxStyle] = values[1];\n } else if (values.length === 3) {\n styles[minStyle] = values[0];\n styles[name] = values[1];\n styles[maxStyle] = values[2];\n } else {\n styles[name] = values[0] || 'auto';\n }\n }\n\n if (styles[name] === 'stretch') {\n if (name === 'width') {\n styles[name] = [\n 'stretch',\n '-webkit-fill-available',\n '-moz-available',\n ];\n } else {\n styles[name] = 'auto';\n }\n }\n }\n\n // Apply individual min/max props (higher priority, override main prop syntax)\n const minVal = parseDimensionValue(min);\n const maxVal = parseDimensionValue(max);\n if (minVal) styles[minStyle] = minVal;\n if (maxVal) styles[maxStyle] = maxVal;\n\n return styles;\n };\n}\n"],"mappings":";;;;AAGA,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;;;;AAKzB,SAAS,oBACP,KACe;AACf,KAAI,OAAO,KAAM,QAAO;AACxB,KAAI,OAAO,QAAQ,SAAU,QAAO,GAAG,IAAI;AAC3C,KAAI,QAAQ,KAAM,QAAO;AAGzB,QADkB,WAAW,OAAO,IAAI,CAAC,CACxB,OAAO,IAAI,OAAO,MAAM;;;;;;;;;;;AAkB3C,SAAgB,eAAe,MAA0B;CACvD,MAAM,WAAW,OAAO;CACxB,MAAM,WAAW,OAAO;AAExB,SAAQ,EAAE,OAAO,KAAK,UAA0B;AAE9C,MAAI,SAAS,QAAQ,OAAO,QAAQ,OAAO,KAAM;AAGjD,MAAI,UAAU,MAAM;GAClB,MAAM,SAA4C;KAC/C,OAAO;KACP,WAAW;KACX,WAAW;IACb;GAGD,MAAM,SAAS,oBAAoB,IAAI;GACvC,MAAM,SAAS,oBAAoB,IAAI;AACvC,OAAI,OAAQ,QAAO,YAAY;AAC/B,OAAI,OAAQ,QAAO,YAAY;AAE/B,UAAO;;EAGT,MAAM,SAA4C;IAC/C,OAAO;IACP,WAAW;IACX,WAAW;GACb;AAGD,MAAI,SAAS,MAAM;GACjB,IAAI,MAAM;AACV,OAAI,OAAO,QAAQ,SACjB,OAAM,GAAG,IAAI;AAGf,SAAM,OAAO,IAAI;GAGjB,MAAM,EAAE,MAAM,WADI,WAAW,IAAI,CAErB,OAAO,MAAM,kBAAkB;GAE3C,IAAI,OAAO;AAEX,QAAK,MAAM,OAAO,KAChB,SAAQ,KAAR;IACE,KAAK;AACH,YAAO,YAAY,OAAO,MAAM;AAChC,YAAO;AACP;IACF,KAAK;AACH,YAAO,YAAY,OAAO,MAAM;AAChC,YAAO;AACP;IACF,KAAK,SAAS;KAEZ,MAAM,aAAa,OAAO,MAAM;AAChC,YAAO,YAAY;AACnB,YAAO,QAAQ;AACf,YAAO,YAAY;AACnB,YAAO;AACP;;IAEF,QACE;;AAIN,OAAI,CAAC,QAAQ,CAAC,KAAK,OACjB,KAAI,OAAO,WAAW,GAAG;AACvB,WAAO,YAAY,OAAO;AAC1B,WAAO,YAAY,OAAO;cACjB,OAAO,WAAW,GAAG;AAC9B,WAAO,YAAY,OAAO;AAC1B,WAAO,QAAQ,OAAO;AACtB,WAAO,YAAY,OAAO;SAE1B,QAAO,QAAQ,OAAO,MAAM;AAIhC,OAAI,OAAO,UAAU,UACnB,KAAI,SAAS,QACX,QAAO,QAAQ;IACb;IACA;IACA;IACD;OAED,QAAO,QAAQ;;EAMrB,MAAM,SAAS,oBAAoB,IAAI;EACvC,MAAM,SAAS,oBAAoB,IAAI;AACvC,MAAI,OAAQ,QAAO,YAAY;AAC/B,MAAI,OAAQ,QAAO,YAAY;AAE/B,SAAO"}
|