css-in-props 3.14.0 → 3.14.3
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/CHANGELOG.md +25 -0
- package/README.md +1 -1
- package/dist/cjs/index.js +1 -21
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/src/index.js +1 -0
- package/dist/cjs/src/props/animation.js +1 -0
- package/dist/cjs/src/props/block.js +1 -0
- package/dist/cjs/src/props/defaults.js +1 -0
- package/dist/cjs/src/props/flex.js +1 -0
- package/dist/cjs/src/props/font.js +1 -0
- package/dist/cjs/src/props/grid.js +1 -0
- package/dist/cjs/src/props/index.js +1 -0
- package/dist/cjs/src/props/misc.js +1 -0
- package/dist/cjs/src/props/position.js +1 -0
- package/dist/cjs/src/props/theme.js +1 -0
- package/dist/cjs/src/props/timing.js +1 -0
- package/dist/cjs/src/set.js +1 -0
- package/dist/cjs/src/transform/executors.js +1 -0
- package/dist/cjs/src/transform/index.js +1 -0
- package/dist/cjs/src/transform/transformers.js +1 -0
- package/dist/esm/index.js +1 -4
- package/dist/esm/src/index.js +1 -0
- package/dist/esm/src/props/animation.js +1 -0
- package/dist/esm/src/props/block.js +1 -0
- package/dist/esm/src/props/defaults.js +1 -0
- package/dist/esm/src/props/flex.js +1 -0
- package/dist/esm/src/props/font.js +1 -0
- package/dist/esm/src/props/grid.js +1 -0
- package/dist/esm/src/props/index.js +1 -0
- package/dist/esm/src/props/misc.js +1 -0
- package/dist/esm/src/props/position.js +1 -0
- package/dist/esm/src/props/theme.js +1 -0
- package/dist/esm/src/props/timing.js +1 -0
- package/dist/esm/src/set.js +1 -0
- package/dist/esm/src/transform/executors.js +1 -0
- package/dist/esm/src/transform/index.js +1 -0
- package/dist/esm/src/transform/transformers.js +1 -0
- package/package.json +19 -20
- package/dist/cjs/props/animation.js +0 -126
- package/dist/cjs/props/block.js +0 -173
- package/dist/cjs/props/defaults.js +0 -340
- package/dist/cjs/props/flex.js +0 -44
- package/dist/cjs/props/font.js +0 -36
- package/dist/cjs/props/grid.js +0 -39
- package/dist/cjs/props/index.js +0 -55
- package/dist/cjs/props/misc.js +0 -42
- package/dist/cjs/props/position.js +0 -51
- package/dist/cjs/props/theme.js +0 -147
- package/dist/cjs/props/timing.js +0 -42
- package/dist/cjs/set.js +0 -36
- package/dist/cjs/transform/executors.js +0 -131
- package/dist/cjs/transform/index.js +0 -19
- package/dist/cjs/transform/transformers.js +0 -156
- package/dist/esm/props/animation.js +0 -106
- package/dist/esm/props/block.js +0 -159
- package/dist/esm/props/defaults.js +0 -321
- package/dist/esm/props/flex.js +0 -24
- package/dist/esm/props/font.js +0 -16
- package/dist/esm/props/grid.js +0 -19
- package/dist/esm/props/index.js +0 -34
- package/dist/esm/props/misc.js +0 -22
- package/dist/esm/props/position.js +0 -31
- package/dist/esm/props/theme.js +0 -137
- package/dist/esm/props/timing.js +0 -26
- package/dist/esm/set.js +0 -16
- package/dist/esm/transform/executors.js +0 -111
- package/dist/esm/transform/index.js +0 -2
- package/dist/esm/transform/transformers.js +0 -136
- package/dist/iife/index.js +0 -1147
- package/index.js +0 -1
- package/src/index.js +0 -6
- package/src/props/animation.js +0 -119
- package/src/props/block.js +0 -183
- package/src/props/defaults.js +0 -318
- package/src/props/flex.js +0 -30
- package/src/props/font.js +0 -16
- package/src/props/grid.js +0 -21
- package/src/props/index.js +0 -35
- package/src/props/misc.js +0 -23
- package/src/props/position.js +0 -34
- package/src/props/theme.js +0 -155
- package/src/props/timing.js +0 -26
- package/src/set.js +0 -16
- package/src/transform/executors.js +0 -123
- package/src/transform/index.js +0 -4
- package/src/transform/transformers.js +0 -178
package/dist/esm/props/misc.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const MISC_PROPS = {
|
|
2
|
-
overflow: (value) => ({
|
|
3
|
-
overflow: value,
|
|
4
|
-
scrollBehavior: "smooth"
|
|
5
|
-
}),
|
|
6
|
-
cursor: (value, el, s, ctx) => {
|
|
7
|
-
if (!value) return;
|
|
8
|
-
const asset = ctx.assets && ctx.assets[value];
|
|
9
|
-
if (asset && asset.content) value = `url(${asset.content.src})`;
|
|
10
|
-
else {
|
|
11
|
-
const file = ctx.files && ctx.files[value];
|
|
12
|
-
if (file && file.content) value = `url(${file.content.src})`;
|
|
13
|
-
}
|
|
14
|
-
return { cursor: value };
|
|
15
|
-
},
|
|
16
|
-
opacity: (value) => value != null ? { opacity: String(value) } : void 0,
|
|
17
|
-
visibility: (value) => value != null ? { visibility: value } : void 0,
|
|
18
|
-
pointerEvents: (value) => value != null ? { pointerEvents: value } : void 0
|
|
19
|
-
};
|
|
20
|
-
export {
|
|
21
|
-
MISC_PROPS
|
|
22
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { getSpacingByKey } from "@symbo.ls/scratch";
|
|
2
|
-
const POSITION_PROPS = {
|
|
3
|
-
inset: (val, el) => {
|
|
4
|
-
if (el.call("isNumber", val)) return { inset: val };
|
|
5
|
-
if (!el.call("isString", val)) return;
|
|
6
|
-
return { inset: val.split(" ").map((v) => getSpacingByKey(v, "k").k).join(" ") };
|
|
7
|
-
},
|
|
8
|
-
left: (val) => getSpacingByKey(val, "left"),
|
|
9
|
-
top: (val) => getSpacingByKey(val, "top"),
|
|
10
|
-
right: (val) => getSpacingByKey(val, "right"),
|
|
11
|
-
bottom: (val) => getSpacingByKey(val, "bottom"),
|
|
12
|
-
verticalInset: (val) => {
|
|
13
|
-
if (typeof val !== "string") return;
|
|
14
|
-
const vi = val.split(" ").map((v) => getSpacingByKey(v, "k").k);
|
|
15
|
-
return {
|
|
16
|
-
top: vi[0],
|
|
17
|
-
bottom: vi[1] || vi[0]
|
|
18
|
-
};
|
|
19
|
-
},
|
|
20
|
-
horizontalInset: (val) => {
|
|
21
|
-
if (typeof val !== "string") return;
|
|
22
|
-
const vi = val.split(" ").map((v) => getSpacingByKey(v, "k").k);
|
|
23
|
-
return {
|
|
24
|
-
left: vi[0],
|
|
25
|
-
right: vi[1] || vi[0]
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
export {
|
|
30
|
-
POSITION_PROPS
|
|
31
|
-
};
|
package/dist/esm/props/theme.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getMediaTheme,
|
|
3
|
-
getMediaColor,
|
|
4
|
-
transformTextStroke,
|
|
5
|
-
transformShadow,
|
|
6
|
-
transformBoxShadow,
|
|
7
|
-
transformBorder,
|
|
8
|
-
transformBackgroundImage,
|
|
9
|
-
resolveColorsInGradient,
|
|
10
|
-
transformSizeRatio
|
|
11
|
-
} from "@symbo.ls/scratch";
|
|
12
|
-
import { isDefined, isString } from "@symbo.ls/utils";
|
|
13
|
-
const getSystemGlobalTheme = ({ context, state }) => {
|
|
14
|
-
const theme = state?.root?.globalTheme || context.designSystem?.globalTheme;
|
|
15
|
-
return theme === "auto" ? null : theme;
|
|
16
|
-
};
|
|
17
|
-
const THEME_PROPS = {
|
|
18
|
-
theme: (val, element) => {
|
|
19
|
-
if (!val) return;
|
|
20
|
-
if (element.themeModifier) {
|
|
21
|
-
return getMediaTheme(val, `@${element.themeModifier}`);
|
|
22
|
-
}
|
|
23
|
-
return getMediaTheme(val);
|
|
24
|
-
},
|
|
25
|
-
color: (val, element) => {
|
|
26
|
-
const globalTheme = getSystemGlobalTheme(element);
|
|
27
|
-
if (!val) return;
|
|
28
|
-
return {
|
|
29
|
-
color: getMediaColor(val, globalTheme)
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
background: (val, element) => {
|
|
33
|
-
const globalTheme = getSystemGlobalTheme(element);
|
|
34
|
-
if (!val) return;
|
|
35
|
-
if (isString(val) && val.includes("gradient")) {
|
|
36
|
-
return { background: resolveColorsInGradient(val, globalTheme) };
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
background: getMediaColor(val, globalTheme)
|
|
40
|
-
};
|
|
41
|
-
},
|
|
42
|
-
backgroundColor: (val, element) => {
|
|
43
|
-
const globalTheme = getSystemGlobalTheme(element);
|
|
44
|
-
if (!val) return;
|
|
45
|
-
return {
|
|
46
|
-
backgroundColor: getMediaColor(val, globalTheme)
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
backgroundImage: (val, element, s, ctx) => {
|
|
50
|
-
const globalTheme = getSystemGlobalTheme(element);
|
|
51
|
-
if (!val) return;
|
|
52
|
-
const asset = ctx.assets && ctx.assets[val];
|
|
53
|
-
if (asset && asset.content) val = asset.content.src;
|
|
54
|
-
else {
|
|
55
|
-
const file = ctx.files && ctx.files[val];
|
|
56
|
-
if (file && file.content) val = file.content.src;
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
backgroundImage: transformBackgroundImage(val, globalTheme)
|
|
60
|
-
};
|
|
61
|
-
},
|
|
62
|
-
textStroke: (val) => ({
|
|
63
|
-
WebkitTextStroke: transformTextStroke(val)
|
|
64
|
-
}),
|
|
65
|
-
outline: (val) => ({
|
|
66
|
-
outline: transformBorder(val)
|
|
67
|
-
}),
|
|
68
|
-
outlineOffset: (val, el) => transformSizeRatio("outlineOffset", val, el),
|
|
69
|
-
border: (val) => ({
|
|
70
|
-
border: transformBorder(val)
|
|
71
|
-
}),
|
|
72
|
-
borderColor: (val, element) => {
|
|
73
|
-
const globalTheme = getSystemGlobalTheme(element);
|
|
74
|
-
if (!val) return;
|
|
75
|
-
return {
|
|
76
|
-
borderColor: getMediaColor(val, globalTheme)
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
borderTopColor: (val, element) => {
|
|
80
|
-
const globalTheme = getSystemGlobalTheme(element);
|
|
81
|
-
if (!val) return;
|
|
82
|
-
return { borderTopColor: getMediaColor(val, globalTheme) };
|
|
83
|
-
},
|
|
84
|
-
borderBottomColor: (val, element) => {
|
|
85
|
-
const globalTheme = getSystemGlobalTheme(element);
|
|
86
|
-
if (!val) return;
|
|
87
|
-
return { borderBottomColor: getMediaColor(val, globalTheme) };
|
|
88
|
-
},
|
|
89
|
-
borderLeftColor: (val, element) => {
|
|
90
|
-
const globalTheme = getSystemGlobalTheme(element);
|
|
91
|
-
if (!val) return;
|
|
92
|
-
return { borderLeftColor: getMediaColor(val, globalTheme) };
|
|
93
|
-
},
|
|
94
|
-
borderRightColor: (val, element) => {
|
|
95
|
-
const globalTheme = getSystemGlobalTheme(element);
|
|
96
|
-
if (!val) return;
|
|
97
|
-
return { borderRightColor: getMediaColor(val, globalTheme) };
|
|
98
|
-
},
|
|
99
|
-
borderLeft: (val) => ({
|
|
100
|
-
borderLeft: transformBorder(val)
|
|
101
|
-
}),
|
|
102
|
-
borderTop: (val) => ({
|
|
103
|
-
borderTop: transformBorder(val)
|
|
104
|
-
}),
|
|
105
|
-
borderRight: (val) => ({
|
|
106
|
-
borderRight: transformBorder(val)
|
|
107
|
-
}),
|
|
108
|
-
borderBottom: (val) => ({
|
|
109
|
-
borderBottom: transformBorder(val)
|
|
110
|
-
}),
|
|
111
|
-
shadow: (val, element) => {
|
|
112
|
-
const globalTheme = getSystemGlobalTheme(element);
|
|
113
|
-
if (!val) return;
|
|
114
|
-
return {
|
|
115
|
-
boxShadow: transformShadow(val, globalTheme)
|
|
116
|
-
};
|
|
117
|
-
},
|
|
118
|
-
boxShadow: (val, element) => {
|
|
119
|
-
if (!isString(val)) return;
|
|
120
|
-
const [value, hasImportant] = val.split("!importan");
|
|
121
|
-
const globalTheme = getSystemGlobalTheme(element);
|
|
122
|
-
const important = hasImportant ? " !important" : "";
|
|
123
|
-
return {
|
|
124
|
-
boxShadow: transformBoxShadow(value.trim(), globalTheme) + important
|
|
125
|
-
};
|
|
126
|
-
},
|
|
127
|
-
textShadow: (val, { context }) => ({
|
|
128
|
-
textShadow: transformBoxShadow(val, context.designSystem.globalTheme)
|
|
129
|
-
}),
|
|
130
|
-
columnRule: (val) => ({
|
|
131
|
-
columnRule: transformBorder(val)
|
|
132
|
-
})
|
|
133
|
-
};
|
|
134
|
-
export {
|
|
135
|
-
THEME_PROPS,
|
|
136
|
-
getSystemGlobalTheme
|
|
137
|
-
};
|
package/dist/esm/props/timing.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getTimingFunction,
|
|
3
|
-
splitTransition,
|
|
4
|
-
transformDuration
|
|
5
|
-
} from "@symbo.ls/scratch";
|
|
6
|
-
const TIMING_PROPS = {
|
|
7
|
-
transition: (val) => ({
|
|
8
|
-
transition: splitTransition(val)
|
|
9
|
-
}),
|
|
10
|
-
transitionDuration: (val) => ({
|
|
11
|
-
transitionDuration: transformDuration(val)
|
|
12
|
-
}),
|
|
13
|
-
transitionDelay: (val) => ({
|
|
14
|
-
transitionDelay: transformDuration(val)
|
|
15
|
-
}),
|
|
16
|
-
transitionTimingFunction: (val) => ({
|
|
17
|
-
transitionTimingFunction: getTimingFunction(val)
|
|
18
|
-
}),
|
|
19
|
-
transitionProperty: (val) => ({
|
|
20
|
-
transitionProperty: val,
|
|
21
|
-
willChange: val
|
|
22
|
-
})
|
|
23
|
-
};
|
|
24
|
-
export {
|
|
25
|
-
TIMING_PROPS
|
|
26
|
-
};
|
package/dist/esm/set.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { isObject } from "@symbo.ls/utils";
|
|
2
|
-
import { useCssInProps } from "./transform/index.js";
|
|
3
|
-
import { css } from "@symbo.ls/css";
|
|
4
|
-
const transformClassname = (element) => {
|
|
5
|
-
if (!isObject(element)) return;
|
|
6
|
-
return useCssInProps(element, element);
|
|
7
|
-
};
|
|
8
|
-
const setClassname = (props, cssEngine) => {
|
|
9
|
-
const transform = transformClassname(props);
|
|
10
|
-
if (typeof cssEngine === "function") return cssEngine(transform);
|
|
11
|
-
return css(transform);
|
|
12
|
-
};
|
|
13
|
-
export {
|
|
14
|
-
setClassname,
|
|
15
|
-
transformClassname
|
|
16
|
-
};
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { exec, isArray, isFunction, isObject, isProduction, merge, overwrite, overwriteDeep } from "@symbo.ls/utils";
|
|
2
|
-
import { pushConfig, popConfig } from "@symbo.ls/scratch";
|
|
3
|
-
import { CSS_PROPS_REGISTRY } from "../props/index.js";
|
|
4
|
-
import { DEFAULT_CSS_PROPERTIES_LIST } from "../props/defaults.js";
|
|
5
|
-
import { applyTrueProps, transformersByPrefix } from "./transformers.js";
|
|
6
|
-
const isProd = isProduction();
|
|
7
|
-
const usePropsAsCSS = (sourceObj, element, opts) => {
|
|
8
|
-
const ds = element?.context?.designSystem;
|
|
9
|
-
if (ds) pushConfig(ds);
|
|
10
|
-
try {
|
|
11
|
-
let obj = {};
|
|
12
|
-
const rest = {};
|
|
13
|
-
const setToObj = (key, val) => {
|
|
14
|
-
if (opts.unpack) {
|
|
15
|
-
obj = { ...obj, ...val };
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
obj[key] = val;
|
|
19
|
-
};
|
|
20
|
-
for (const key in sourceObj) {
|
|
21
|
-
const value = sourceObj[key];
|
|
22
|
-
if (key === "class" && element.call("isString", sourceObj.class)) {
|
|
23
|
-
const val = value.split(" ");
|
|
24
|
-
if (val.length) {
|
|
25
|
-
const CLASS = element.context.designSystem.class;
|
|
26
|
-
const result = val.reduce((acc, curr) => merge(acc, CLASS[curr]), {});
|
|
27
|
-
obj.designSystemClass = result;
|
|
28
|
-
}
|
|
29
|
-
} else if (key === "true") {
|
|
30
|
-
const val = exec(value, element);
|
|
31
|
-
merge(obj, applyTrueProps(val, element));
|
|
32
|
-
} else if (element.classlist[key]) {
|
|
33
|
-
const originalFromClass = element.classlist[key];
|
|
34
|
-
const result = isFunction(originalFromClass) ? originalFromClass(element, element.state, element.context) : originalFromClass;
|
|
35
|
-
if (result) setToObj(key, result);
|
|
36
|
-
if (!isProd && isObject(obj[key])) obj[key].label = key;
|
|
37
|
-
} else if (CSS_PROPS_REGISTRY[key]) {
|
|
38
|
-
let val = exec(value, element);
|
|
39
|
-
if (isArray(val)) {
|
|
40
|
-
val = val.reduce((a, c) => merge(a, c), {});
|
|
41
|
-
}
|
|
42
|
-
let result = CSS_PROPS_REGISTRY[key](val, element, element.state, element.context);
|
|
43
|
-
if (isArray(result)) result = result.reduce((a, c) => merge(a, c), {});
|
|
44
|
-
if (result) setToObj(key, result);
|
|
45
|
-
if (!isProd && isObject(obj[key])) obj[key].label = key;
|
|
46
|
-
} else if (DEFAULT_CSS_PROPERTIES_LIST.has(key)) {
|
|
47
|
-
let result = exec(value, element);
|
|
48
|
-
if (typeof result === "string" && result.charCodeAt(0) === 45 && result.charCodeAt(1) === 45) {
|
|
49
|
-
result = `var(${result})`;
|
|
50
|
-
}
|
|
51
|
-
setToObj(key, { [key]: result });
|
|
52
|
-
if (!isProd && isObject(obj[key])) obj[key].label = key;
|
|
53
|
-
} else {
|
|
54
|
-
rest[key] = value;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return [obj, rest];
|
|
58
|
-
} finally {
|
|
59
|
-
if (ds) popConfig();
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
const useSelectorsAsCSS = (sourceObj, element) => {
|
|
63
|
-
const obj = {};
|
|
64
|
-
for (const key in sourceObj) {
|
|
65
|
-
const selectroSetter = transformersByPrefix[key.slice(0, 1)];
|
|
66
|
-
if (selectroSetter) {
|
|
67
|
-
const result = selectroSetter(key, sourceObj[key], element);
|
|
68
|
-
if (result) {
|
|
69
|
-
for (const k in result) {
|
|
70
|
-
if (Object.prototype.hasOwnProperty.call(result, k)) {
|
|
71
|
-
if (obj[k] && typeof obj[k] === "object" && typeof result[k] === "object") {
|
|
72
|
-
overwriteDeep(obj[k], result[k]);
|
|
73
|
-
} else {
|
|
74
|
-
obj[k] = result[k];
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return obj;
|
|
82
|
-
};
|
|
83
|
-
const useCssInProps = (selectorProps, element, opts = { unpack: true }) => {
|
|
84
|
-
const [cssObj, restProps] = usePropsAsCSS(selectorProps, element, opts);
|
|
85
|
-
const selectorsObj = useSelectorsAsCSS(restProps, element);
|
|
86
|
-
let hasSelectors = false;
|
|
87
|
-
for (const _k in selectorsObj) {
|
|
88
|
-
hasSelectors = true;
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
if (hasSelectors) {
|
|
92
|
-
if (opts.unpack) return overwrite(cssObj, selectorsObj);
|
|
93
|
-
cssObj._selectors = selectorsObj;
|
|
94
|
-
}
|
|
95
|
-
return cssObj;
|
|
96
|
-
};
|
|
97
|
-
const exetuteClassPerComponent = (component, element) => {
|
|
98
|
-
const classObj = {};
|
|
99
|
-
if (component.class) {
|
|
100
|
-
for (const classProp in component.class) {
|
|
101
|
-
classObj[classProp] = component.class[classProp](element);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return classObj;
|
|
105
|
-
};
|
|
106
|
-
export {
|
|
107
|
-
exetuteClassPerComponent,
|
|
108
|
-
useCssInProps,
|
|
109
|
-
usePropsAsCSS,
|
|
110
|
-
useSelectorsAsCSS
|
|
111
|
-
};
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { isFunction } from "@symbo.ls/utils";
|
|
2
|
-
import { useCssInProps } from "./executors.js";
|
|
3
|
-
const DATA_THEME_RE = /^\[data-theme=(?:"([^"]+)"|'([^']+)')\]$/;
|
|
4
|
-
const applyMediaProps = (key, selectorProps, element) => {
|
|
5
|
-
const { context } = element;
|
|
6
|
-
if (!context.designSystem?.media) return;
|
|
7
|
-
const schemeKey = key.slice(1);
|
|
8
|
-
const mediaValue = context.designSystem.media[schemeKey];
|
|
9
|
-
const generatedClass = useCssInProps(selectorProps, element);
|
|
10
|
-
if (!mediaValue) {
|
|
11
|
-
return { [key]: generatedClass };
|
|
12
|
-
}
|
|
13
|
-
if (mediaValue === "print") {
|
|
14
|
-
return { "@media print": generatedClass };
|
|
15
|
-
}
|
|
16
|
-
if (mediaValue[0] === "(") {
|
|
17
|
-
return { [`@media screen and ${mediaValue}`]: generatedClass };
|
|
18
|
-
}
|
|
19
|
-
const match = mediaValue.match(DATA_THEME_RE);
|
|
20
|
-
const scheme = match ? match[1] || match[2] : schemeKey;
|
|
21
|
-
const result = { [`${mediaValue} &`]: generatedClass };
|
|
22
|
-
if (scheme === "dark" || scheme === "light") {
|
|
23
|
-
const scopeSelector = context.designSystem?.scopeSelector || ":root";
|
|
24
|
-
const guard = scopeSelector === ":root" ? ":root:not([data-theme])" : `${scopeSelector}:not([data-theme])`;
|
|
25
|
-
result[`@media (prefers-color-scheme: ${scheme})`] = {
|
|
26
|
-
[`${guard} &`]: generatedClass
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
};
|
|
31
|
-
const applyAndProps = (key, selectorProps, element) => {
|
|
32
|
-
return { [key]: useCssInProps(selectorProps, element) };
|
|
33
|
-
};
|
|
34
|
-
const applySelectorProps = (key, selectorProps, element) => {
|
|
35
|
-
const selectorKey = `&${key}`;
|
|
36
|
-
const resolved = useCssInProps(selectorProps, element);
|
|
37
|
-
if (key.includes(",") && resolved) {
|
|
38
|
-
const flat = {};
|
|
39
|
-
const nested = {};
|
|
40
|
-
for (const k in resolved) {
|
|
41
|
-
if (typeof resolved[k] === "object" && resolved[k] !== null) {
|
|
42
|
-
nested[k] = resolved[k];
|
|
43
|
-
} else {
|
|
44
|
-
flat[k] = resolved[k];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (Object.keys(nested).length) {
|
|
48
|
-
const parts = selectorKey.split(",").map((p) => p.trim());
|
|
49
|
-
const result = {};
|
|
50
|
-
if (Object.keys(flat).length) {
|
|
51
|
-
result[selectorKey] = flat;
|
|
52
|
-
}
|
|
53
|
-
for (const nestedKey in nested) {
|
|
54
|
-
const distributed = parts.map((p) => `${p} ${nestedKey}`).join(", ");
|
|
55
|
-
result[distributed] = nested[nestedKey];
|
|
56
|
-
}
|
|
57
|
-
return result;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return { [selectorKey]: resolved };
|
|
61
|
-
};
|
|
62
|
-
const resolveCase = (caseKey, element) => {
|
|
63
|
-
const caseFn = element.context?.cases?.[caseKey];
|
|
64
|
-
if (caseFn === void 0) return void 0;
|
|
65
|
-
if (isFunction(caseFn)) return caseFn.call(element, element);
|
|
66
|
-
return !!caseFn;
|
|
67
|
-
};
|
|
68
|
-
const applyCaseProps = (key, selectorProps, element) => {
|
|
69
|
-
const caseKey = key.slice(1);
|
|
70
|
-
let isCaseTrue = resolveCase(caseKey, element);
|
|
71
|
-
if (isCaseTrue === void 0) {
|
|
72
|
-
isCaseTrue = !!element[caseKey];
|
|
73
|
-
}
|
|
74
|
-
if (!isCaseTrue) return;
|
|
75
|
-
return useCssInProps(selectorProps, element);
|
|
76
|
-
};
|
|
77
|
-
const applyVariableProps = (key, selectorVal, element) => {
|
|
78
|
-
return { [key]: selectorVal };
|
|
79
|
-
};
|
|
80
|
-
const applyConditionalCaseProps = (key, selectorProps, element) => {
|
|
81
|
-
const caseKey = key.slice(1);
|
|
82
|
-
let isCaseTrue = element[caseKey] === true || element.state?.[caseKey];
|
|
83
|
-
if (!isCaseTrue) {
|
|
84
|
-
if (typeof element[caseKey] === "function") {
|
|
85
|
-
try {
|
|
86
|
-
isCaseTrue = element[caseKey](element, element.state, element.context);
|
|
87
|
-
} catch (e) {
|
|
88
|
-
}
|
|
89
|
-
} else {
|
|
90
|
-
const caseResult = resolveCase(caseKey, element);
|
|
91
|
-
if (caseResult !== void 0) isCaseTrue = caseResult;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (!isCaseTrue) return;
|
|
95
|
-
return useCssInProps(selectorProps, element);
|
|
96
|
-
};
|
|
97
|
-
const applyConditionalFalsyProps = (key, selectorProps, element) => {
|
|
98
|
-
const caseKey = key.slice(1);
|
|
99
|
-
let isCaseTrue = element[caseKey] === true || element.state?.[caseKey];
|
|
100
|
-
if (!isCaseTrue) {
|
|
101
|
-
if (typeof element[caseKey] === "function") {
|
|
102
|
-
try {
|
|
103
|
-
isCaseTrue = element[caseKey](element, element.state, element.context);
|
|
104
|
-
} catch (e) {
|
|
105
|
-
}
|
|
106
|
-
} else {
|
|
107
|
-
const caseResult = resolveCase(caseKey, element);
|
|
108
|
-
if (caseResult !== void 0) isCaseTrue = caseResult;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (isCaseTrue) return;
|
|
112
|
-
return useCssInProps(selectorProps, element);
|
|
113
|
-
};
|
|
114
|
-
const applyTrueProps = (selectorProps, element) => {
|
|
115
|
-
return useCssInProps(selectorProps, element);
|
|
116
|
-
};
|
|
117
|
-
const transformersByPrefix = {
|
|
118
|
-
"@": applyMediaProps,
|
|
119
|
-
// Selector handlers
|
|
120
|
-
":": applySelectorProps,
|
|
121
|
-
"[": applySelectorProps,
|
|
122
|
-
"*": applySelectorProps,
|
|
123
|
-
"+": applySelectorProps,
|
|
124
|
-
"~": applySelectorProps,
|
|
125
|
-
"&": applyAndProps,
|
|
126
|
-
">": applyAndProps,
|
|
127
|
-
// Conditional and variable handlers
|
|
128
|
-
$: applyCaseProps,
|
|
129
|
-
"-": applyVariableProps,
|
|
130
|
-
".": applyConditionalCaseProps,
|
|
131
|
-
"!": applyConditionalFalsyProps
|
|
132
|
-
};
|
|
133
|
-
export {
|
|
134
|
-
applyTrueProps,
|
|
135
|
-
transformersByPrefix
|
|
136
|
-
};
|