@symbo.ls/scratch 3.14.0 → 3.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +2 -2
- package/src/utils/sprite.js +29 -12
- package/dist/cjs/defaultConfig/animation.js +0 -24
- package/dist/cjs/defaultConfig/cases.js +0 -24
- package/dist/cjs/defaultConfig/class.js +0 -24
- package/dist/cjs/defaultConfig/color.js +0 -31
- package/dist/cjs/defaultConfig/document.js +0 -24
- package/dist/cjs/defaultConfig/font-family.js +0 -38
- package/dist/cjs/defaultConfig/font.js +0 -33
- package/dist/cjs/defaultConfig/grid.js +0 -25
- package/dist/cjs/defaultConfig/icons.js +0 -26
- package/dist/cjs/defaultConfig/index.js +0 -46
- package/dist/cjs/defaultConfig/media.js +0 -29
- package/dist/cjs/defaultConfig/responsive.js +0 -50
- package/dist/cjs/defaultConfig/sequence.js +0 -49
- package/dist/cjs/defaultConfig/shadow.js +0 -24
- package/dist/cjs/defaultConfig/spacing.js +0 -38
- package/dist/cjs/defaultConfig/svg.js +0 -26
- package/dist/cjs/defaultConfig/templates.js +0 -24
- package/dist/cjs/defaultConfig/theme.js +0 -36
- package/dist/cjs/defaultConfig/timing.js +0 -37
- package/dist/cjs/defaultConfig/typography.js +0 -41
- package/dist/cjs/defaultConfig/unit.js +0 -26
- package/dist/cjs/factory.js +0 -145
- package/dist/cjs/index.js +0 -45
- package/dist/cjs/set.js +0 -286
- package/dist/cjs/system/color.js +0 -268
- package/dist/cjs/system/document.js +0 -36
- package/dist/cjs/system/font.js +0 -71
- package/dist/cjs/system/index.js +0 -27
- package/dist/cjs/system/reset.js +0 -114
- package/dist/cjs/system/shadow.js +0 -108
- package/dist/cjs/system/spacing.js +0 -134
- package/dist/cjs/system/svg.js +0 -133
- package/dist/cjs/system/theme.js +0 -496
- package/dist/cjs/system/timing.js +0 -48
- package/dist/cjs/system/typography.js +0 -108
- package/dist/cjs/tests/index.js +0 -28
- package/dist/cjs/transforms/index.js +0 -219
- package/dist/cjs/utils/color.js +0 -206
- package/dist/cjs/utils/font.js +0 -114
- package/dist/cjs/utils/index.js +0 -24
- package/dist/cjs/utils/sequence.js +0 -342
- package/dist/cjs/utils/sprite.js +0 -92
- package/dist/cjs/utils/theme.js +0 -29
- package/dist/cjs/utils/unit.js +0 -79
- package/dist/cjs/utils/var.js +0 -116
- package/dist/esm/defaultConfig/animation.js +0 -4
- package/dist/esm/defaultConfig/cases.js +0 -4
- package/dist/esm/defaultConfig/class.js +0 -4
- package/dist/esm/defaultConfig/color.js +0 -11
- package/dist/esm/defaultConfig/document.js +0 -4
- package/dist/esm/defaultConfig/font-family.js +0 -18
- package/dist/esm/defaultConfig/font.js +0 -13
- package/dist/esm/defaultConfig/grid.js +0 -5
- package/dist/esm/defaultConfig/icons.js +0 -6
- package/dist/esm/defaultConfig/index.js +0 -25
- package/dist/esm/defaultConfig/media.js +0 -9
- package/dist/esm/defaultConfig/responsive.js +0 -30
- package/dist/esm/defaultConfig/sequence.js +0 -29
- package/dist/esm/defaultConfig/shadow.js +0 -4
- package/dist/esm/defaultConfig/spacing.js +0 -18
- package/dist/esm/defaultConfig/svg.js +0 -6
- package/dist/esm/defaultConfig/templates.js +0 -4
- package/dist/esm/defaultConfig/theme.js +0 -16
- package/dist/esm/defaultConfig/timing.js +0 -17
- package/dist/esm/defaultConfig/typography.js +0 -21
- package/dist/esm/defaultConfig/unit.js +0 -6
- package/dist/esm/factory.js +0 -120
- package/dist/esm/index.js +0 -14
- package/dist/esm/set.js +0 -280
- package/dist/esm/system/color.js +0 -253
- package/dist/esm/system/document.js +0 -16
- package/dist/esm/system/font.js +0 -58
- package/dist/esm/system/index.js +0 -10
- package/dist/esm/system/reset.js +0 -94
- package/dist/esm/system/shadow.js +0 -92
- package/dist/esm/system/spacing.js +0 -121
- package/dist/esm/system/svg.js +0 -113
- package/dist/esm/system/theme.js +0 -481
- package/dist/esm/system/timing.js +0 -32
- package/dist/esm/system/typography.js +0 -94
- package/dist/esm/tests/index.js +0 -8
- package/dist/esm/transforms/index.js +0 -216
- package/dist/esm/utils/color.js +0 -192
- package/dist/esm/utils/font.js +0 -94
- package/dist/esm/utils/index.js +0 -7
- package/dist/esm/utils/sequence.js +0 -322
- package/dist/esm/utils/sprite.js +0 -72
- package/dist/esm/utils/theme.js +0 -9
- package/dist/esm/utils/unit.js +0 -59
- package/dist/esm/utils/var.js +0 -96
- package/dist/iife/index.js +0 -3630
package/dist/esm/system/svg.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { document } from "@symbo.ls/utils";
|
|
2
|
-
import { generateSprite, convertSvgToSymbol } from "../utils/index.js";
|
|
3
|
-
import { getActiveConfig } from "../factory.js";
|
|
4
|
-
const DEF_OPTIONS = {
|
|
5
|
-
document
|
|
6
|
-
};
|
|
7
|
-
const setSVG = (val, key) => {
|
|
8
|
-
const CONFIG = getActiveConfig();
|
|
9
|
-
if (!val) {
|
|
10
|
-
if (CONFIG.verbose) console.warn("setSVG: val is not defined", key);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
if (CONFIG.useSvgSprite) {
|
|
14
|
-
return convertSvgToSymbol(key, val);
|
|
15
|
-
}
|
|
16
|
-
return val;
|
|
17
|
-
};
|
|
18
|
-
const appendSVGSprite = (LIBRARY, options = DEF_OPTIONS) => {
|
|
19
|
-
const CONFIG = getActiveConfig();
|
|
20
|
-
const lib = Object.keys(LIBRARY).length ? {} : CONFIG.svg;
|
|
21
|
-
for (const key in LIBRARY) lib[key] = LIBRARY[key];
|
|
22
|
-
appendSVG(lib, options);
|
|
23
|
-
};
|
|
24
|
-
const setSvgIcon = (val, key) => {
|
|
25
|
-
const CONFIG = getActiveConfig();
|
|
26
|
-
if (CONFIG.useIconSprite && !CONFIG.semanticIcons?.[key]) {
|
|
27
|
-
return setSVG(val, key);
|
|
28
|
-
}
|
|
29
|
-
return val;
|
|
30
|
-
};
|
|
31
|
-
const appendSvgIconsSprite = (LIBRARY, options = DEF_OPTIONS) => {
|
|
32
|
-
const CONFIG = getActiveConfig();
|
|
33
|
-
const lib = Object.keys(LIBRARY).length ? {} : CONFIG.icons;
|
|
34
|
-
for (const key in LIBRARY) lib[key] = LIBRARY[key];
|
|
35
|
-
appendSVG(lib, options);
|
|
36
|
-
};
|
|
37
|
-
const createSVGSpriteElement = (doc, options = { isRoot: true }) => {
|
|
38
|
-
if (!doc || !doc.createElementNS) return;
|
|
39
|
-
const svgElem = doc.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
40
|
-
if (options.isRoot) {
|
|
41
|
-
svgElem.setAttribute("aria-hidden", "true");
|
|
42
|
-
svgElem.setAttribute("width", "0");
|
|
43
|
-
svgElem.setAttribute("height", "0");
|
|
44
|
-
svgElem.setAttribute("style", "position:absolute");
|
|
45
|
-
svgElem.setAttribute("id", "svgSprite");
|
|
46
|
-
}
|
|
47
|
-
return svgElem;
|
|
48
|
-
};
|
|
49
|
-
const parseSVGSprite = (doc, svgString) => {
|
|
50
|
-
const DOMParserCtor = typeof DOMParser !== "undefined" ? DOMParser : null;
|
|
51
|
-
if (DOMParserCtor) {
|
|
52
|
-
const wrapped = `<svg xmlns="http://www.w3.org/2000/svg">${svgString}</svg>`;
|
|
53
|
-
const parser = new DOMParserCtor();
|
|
54
|
-
const parsed = parser.parseFromString(wrapped, "image/svg+xml");
|
|
55
|
-
if (parsed.querySelector("parsererror")) return null;
|
|
56
|
-
return parsed.documentElement;
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
59
|
-
};
|
|
60
|
-
const moveChildren = (doc, from, to) => {
|
|
61
|
-
while (from.firstChild) {
|
|
62
|
-
const child = from.firstChild;
|
|
63
|
-
to.appendChild(doc.importNode(child, true));
|
|
64
|
-
child.remove();
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
const appendSVG = (lib, options = DEF_OPTIONS) => {
|
|
68
|
-
const CONFIG = getActiveConfig();
|
|
69
|
-
const doc = options.document || document;
|
|
70
|
-
if (!doc || !doc.documentElement) {
|
|
71
|
-
if (CONFIG.verbose) {
|
|
72
|
-
console.warn("To append SVG sprites it should be run in browser environment");
|
|
73
|
-
}
|
|
74
|
-
return generateSprite(lib);
|
|
75
|
-
}
|
|
76
|
-
const exists = doc.querySelector("#svgSprite");
|
|
77
|
-
const SVGsprite = generateSprite(lib);
|
|
78
|
-
const spriteHtml = `<svg aria-hidden="true" width="0" height="0" style="position:absolute" id="svgSprite">${SVGsprite}</svg>`;
|
|
79
|
-
const parsed = parseSVGSprite(doc, SVGsprite);
|
|
80
|
-
if (exists) {
|
|
81
|
-
if (parsed) {
|
|
82
|
-
moveChildren(doc, parsed, exists);
|
|
83
|
-
} else if (doc.body.insertAdjacentHTML) {
|
|
84
|
-
exists.insertAdjacentHTML("beforeend", SVGsprite);
|
|
85
|
-
} else {
|
|
86
|
-
const tempSVG = createSVGSpriteElement(doc, { isRoot: false });
|
|
87
|
-
tempSVG.innerHTML = SVGsprite;
|
|
88
|
-
exists.append(...tempSVG.children);
|
|
89
|
-
}
|
|
90
|
-
} else {
|
|
91
|
-
if (parsed) {
|
|
92
|
-
const svgSpriteDOM = createSVGSpriteElement(doc);
|
|
93
|
-
if (svgSpriteDOM && svgSpriteDOM.nodeType) {
|
|
94
|
-
moveChildren(doc, parsed, svgSpriteDOM);
|
|
95
|
-
doc.body.prepend(svgSpriteDOM);
|
|
96
|
-
}
|
|
97
|
-
} else if (doc.body.insertAdjacentHTML) {
|
|
98
|
-
doc.body.insertAdjacentHTML("afterbegin", spriteHtml);
|
|
99
|
-
} else {
|
|
100
|
-
const svgSpriteDOM = createSVGSpriteElement(doc);
|
|
101
|
-
if (svgSpriteDOM && svgSpriteDOM.nodeType) {
|
|
102
|
-
svgSpriteDOM.innerHTML = SVGsprite;
|
|
103
|
-
doc.body.prepend(svgSpriteDOM);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
export {
|
|
109
|
-
appendSVGSprite,
|
|
110
|
-
appendSvgIconsSprite,
|
|
111
|
-
setSVG,
|
|
112
|
-
setSvgIcon
|
|
113
|
-
};
|
package/dist/esm/system/theme.js
DELETED
|
@@ -1,481 +0,0 @@
|
|
|
1
|
-
import { getColor } from "./color.js";
|
|
2
|
-
import { getActiveConfig } from "../factory.js";
|
|
3
|
-
import { isCSSVar } from "../utils/color.js";
|
|
4
|
-
import {
|
|
5
|
-
isObject,
|
|
6
|
-
isString,
|
|
7
|
-
isObjectLike,
|
|
8
|
-
isArray
|
|
9
|
-
} from "@symbo.ls/utils";
|
|
10
|
-
const CSS_NAMED_COLORS = /* @__PURE__ */ new Set([
|
|
11
|
-
"black",
|
|
12
|
-
"white",
|
|
13
|
-
"red",
|
|
14
|
-
"green",
|
|
15
|
-
"blue",
|
|
16
|
-
"yellow",
|
|
17
|
-
"orange",
|
|
18
|
-
"purple",
|
|
19
|
-
"pink",
|
|
20
|
-
"brown",
|
|
21
|
-
"gray",
|
|
22
|
-
"grey",
|
|
23
|
-
"cyan",
|
|
24
|
-
"magenta",
|
|
25
|
-
"lime",
|
|
26
|
-
"olive",
|
|
27
|
-
"navy",
|
|
28
|
-
"teal",
|
|
29
|
-
"aqua",
|
|
30
|
-
"maroon",
|
|
31
|
-
"silver",
|
|
32
|
-
"fuchsia",
|
|
33
|
-
"transparent",
|
|
34
|
-
"currentColor",
|
|
35
|
-
"currentcolor",
|
|
36
|
-
"inherit",
|
|
37
|
-
"initial",
|
|
38
|
-
"unset",
|
|
39
|
-
"none",
|
|
40
|
-
"aliceblue",
|
|
41
|
-
"antiquewhite",
|
|
42
|
-
"aquamarine",
|
|
43
|
-
"azure",
|
|
44
|
-
"beige",
|
|
45
|
-
"bisque",
|
|
46
|
-
"blanchedalmond",
|
|
47
|
-
"blueviolet",
|
|
48
|
-
"burlywood",
|
|
49
|
-
"cadetblue",
|
|
50
|
-
"chartreuse",
|
|
51
|
-
"chocolate",
|
|
52
|
-
"coral",
|
|
53
|
-
"cornflowerblue",
|
|
54
|
-
"cornsilk",
|
|
55
|
-
"crimson",
|
|
56
|
-
"darkblue",
|
|
57
|
-
"darkcyan",
|
|
58
|
-
"darkgoldenrod",
|
|
59
|
-
"darkgray",
|
|
60
|
-
"darkgreen",
|
|
61
|
-
"darkgrey",
|
|
62
|
-
"darkkhaki",
|
|
63
|
-
"darkmagenta",
|
|
64
|
-
"darkolivegreen",
|
|
65
|
-
"darkorange",
|
|
66
|
-
"darkorchid",
|
|
67
|
-
"darkred",
|
|
68
|
-
"darksalmon",
|
|
69
|
-
"darkseagreen",
|
|
70
|
-
"darkslateblue",
|
|
71
|
-
"darkslategray",
|
|
72
|
-
"darkslategrey",
|
|
73
|
-
"darkturquoise",
|
|
74
|
-
"darkviolet",
|
|
75
|
-
"deeppink",
|
|
76
|
-
"deepskyblue",
|
|
77
|
-
"dimgray",
|
|
78
|
-
"dimgrey",
|
|
79
|
-
"dodgerblue",
|
|
80
|
-
"firebrick",
|
|
81
|
-
"floralwhite",
|
|
82
|
-
"forestgreen",
|
|
83
|
-
"gainsboro",
|
|
84
|
-
"ghostwhite",
|
|
85
|
-
"gold",
|
|
86
|
-
"goldenrod",
|
|
87
|
-
"greenyellow",
|
|
88
|
-
"honeydew",
|
|
89
|
-
"hotpink",
|
|
90
|
-
"indianred",
|
|
91
|
-
"indigo",
|
|
92
|
-
"ivory",
|
|
93
|
-
"khaki",
|
|
94
|
-
"lavender",
|
|
95
|
-
"lavenderblush",
|
|
96
|
-
"lawngreen",
|
|
97
|
-
"lemonchiffon",
|
|
98
|
-
"lightblue",
|
|
99
|
-
"lightcoral",
|
|
100
|
-
"lightcyan",
|
|
101
|
-
"lightgoldenrodyellow",
|
|
102
|
-
"lightgray",
|
|
103
|
-
"lightgreen",
|
|
104
|
-
"lightgrey",
|
|
105
|
-
"lightpink",
|
|
106
|
-
"lightsalmon",
|
|
107
|
-
"lightseagreen",
|
|
108
|
-
"lightskyblue",
|
|
109
|
-
"lightslategray",
|
|
110
|
-
"lightslategrey",
|
|
111
|
-
"lightsteelblue",
|
|
112
|
-
"lightyellow",
|
|
113
|
-
"limegreen",
|
|
114
|
-
"linen",
|
|
115
|
-
"mediumaquamarine",
|
|
116
|
-
"mediumblue",
|
|
117
|
-
"mediumorchid",
|
|
118
|
-
"mediumpurple",
|
|
119
|
-
"mediumseagreen",
|
|
120
|
-
"mediumslateblue",
|
|
121
|
-
"mediumspringgreen",
|
|
122
|
-
"mediumturquoise",
|
|
123
|
-
"mediumvioletred",
|
|
124
|
-
"midnightblue",
|
|
125
|
-
"mintcream",
|
|
126
|
-
"mistyrose",
|
|
127
|
-
"moccasin",
|
|
128
|
-
"navajowhite",
|
|
129
|
-
"oldlace",
|
|
130
|
-
"olivedrab",
|
|
131
|
-
"orangered",
|
|
132
|
-
"orchid",
|
|
133
|
-
"palegoldenrod",
|
|
134
|
-
"palegreen",
|
|
135
|
-
"paleturquoise",
|
|
136
|
-
"palevioletred",
|
|
137
|
-
"papayawhip",
|
|
138
|
-
"peachpuff",
|
|
139
|
-
"peru",
|
|
140
|
-
"plum",
|
|
141
|
-
"powderblue",
|
|
142
|
-
"rosybrown",
|
|
143
|
-
"royalblue",
|
|
144
|
-
"saddlebrown",
|
|
145
|
-
"salmon",
|
|
146
|
-
"sandybrown",
|
|
147
|
-
"seagreen",
|
|
148
|
-
"seashell",
|
|
149
|
-
"sienna",
|
|
150
|
-
"skyblue",
|
|
151
|
-
"slateblue",
|
|
152
|
-
"slategray",
|
|
153
|
-
"slategrey",
|
|
154
|
-
"snow",
|
|
155
|
-
"springgreen",
|
|
156
|
-
"steelblue",
|
|
157
|
-
"tan",
|
|
158
|
-
"thistle",
|
|
159
|
-
"tomato",
|
|
160
|
-
"turquoise",
|
|
161
|
-
"violet",
|
|
162
|
-
"wheat",
|
|
163
|
-
"whitesmoke",
|
|
164
|
-
"yellowgreen",
|
|
165
|
-
"rebeccapurple"
|
|
166
|
-
]);
|
|
167
|
-
const COLOR_PARAM_TOKENS = ["color", "Color", "background", "Background", "fill", "Fill", "stroke", "Stroke"];
|
|
168
|
-
const isColorParam = (param) => {
|
|
169
|
-
for (let i = 0; i < COLOR_PARAM_TOKENS.length; i++) {
|
|
170
|
-
if (param.includes(COLOR_PARAM_TOKENS[i])) return true;
|
|
171
|
-
}
|
|
172
|
-
return false;
|
|
173
|
-
};
|
|
174
|
-
const setThemeValue = (theme) => {
|
|
175
|
-
const value = {};
|
|
176
|
-
const { state, media, helpers, ...rest } = theme;
|
|
177
|
-
const keys = Object.keys(rest);
|
|
178
|
-
keys.map((key) => {
|
|
179
|
-
const conditions = ["color", "Color", "background", "border"];
|
|
180
|
-
const isColor = conditions.some((k) => key.includes(k));
|
|
181
|
-
return value[key] = isColor ? getColor(theme[key]) : theme[key];
|
|
182
|
-
});
|
|
183
|
-
return value;
|
|
184
|
-
};
|
|
185
|
-
const getThemeValue = (theme) => {
|
|
186
|
-
if (theme.value) return theme.value;
|
|
187
|
-
theme.value = setThemeValue(theme);
|
|
188
|
-
return theme.value;
|
|
189
|
-
};
|
|
190
|
-
const getTheme = (value, modifier) => {
|
|
191
|
-
const CONFIG = getActiveConfig();
|
|
192
|
-
if (CONFIG.useVariable) return getMediaTheme(value, modifier);
|
|
193
|
-
const THEME = CONFIG.theme;
|
|
194
|
-
if (isString(value)) {
|
|
195
|
-
const [theme, subtheme] = value.split(" ");
|
|
196
|
-
const isOurTheme = THEME[theme];
|
|
197
|
-
if (isOurTheme) {
|
|
198
|
-
if (!subtheme && !modifier) return getThemeValue(isOurTheme);
|
|
199
|
-
value = [theme, subtheme || modifier];
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
if (isObjectLike(value) && value[1]) {
|
|
203
|
-
const themeName = value[0];
|
|
204
|
-
const subThemeName = value[1];
|
|
205
|
-
const { helpers, media, state } = THEME[themeName];
|
|
206
|
-
if (media && media[subThemeName]) return getThemeValue(media[subThemeName]);
|
|
207
|
-
if (helpers && helpers[subThemeName]) return getThemeValue(helpers[subThemeName]);
|
|
208
|
-
if (state && state[subThemeName]) return getThemeValue(state[subThemeName]);
|
|
209
|
-
} else if (isObject(value)) return setThemeValue(value);
|
|
210
|
-
};
|
|
211
|
-
const setInverseTheme = (theme, variant, value) => {
|
|
212
|
-
if (isObject(variant)) {
|
|
213
|
-
theme.variants.inverse.value = setThemeValue(variant);
|
|
214
|
-
} else if (variant === true) {
|
|
215
|
-
const { color, background } = value;
|
|
216
|
-
theme.variants.inverse = {
|
|
217
|
-
value: {
|
|
218
|
-
color: background,
|
|
219
|
-
background: color
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
const setPseudo = (theme, key, variant, themeValue) => {
|
|
225
|
-
const result = getTheme(variant);
|
|
226
|
-
themeValue[`&:${key}`] = result;
|
|
227
|
-
if (isObject(variant) && !variant.value) variant.value = result;
|
|
228
|
-
};
|
|
229
|
-
const setSelectors = (theme, value) => {
|
|
230
|
-
const { state } = theme;
|
|
231
|
-
if (!state) return;
|
|
232
|
-
const keys = Object.keys(state);
|
|
233
|
-
keys.map((key) => {
|
|
234
|
-
const variant = state[key];
|
|
235
|
-
setPseudo(theme, key, variant, value);
|
|
236
|
-
return theme;
|
|
237
|
-
});
|
|
238
|
-
return theme;
|
|
239
|
-
};
|
|
240
|
-
const setPrefersScheme = (theme, key, variant, themeValue) => {
|
|
241
|
-
const result = getTheme(variant);
|
|
242
|
-
themeValue[`@media (prefers-color-scheme: ${key})`] = result;
|
|
243
|
-
if (isObject(variant) && !variant.value) variant.value = result;
|
|
244
|
-
};
|
|
245
|
-
const setMedia = (theme, value) => {
|
|
246
|
-
const { media } = theme;
|
|
247
|
-
if (!media) return;
|
|
248
|
-
const keys = Object.keys(media);
|
|
249
|
-
keys.map((key) => {
|
|
250
|
-
const variant = media[key];
|
|
251
|
-
if (key === "dark" || key === "light") setPrefersScheme(theme, key, variant, value);
|
|
252
|
-
if (key === "inverse") setInverseTheme(theme, variant, value);
|
|
253
|
-
return theme;
|
|
254
|
-
});
|
|
255
|
-
return theme;
|
|
256
|
-
};
|
|
257
|
-
const setHelpers = (theme, value) => {
|
|
258
|
-
const CONFIG = getActiveConfig();
|
|
259
|
-
const { helpers } = theme;
|
|
260
|
-
if (!helpers) return;
|
|
261
|
-
const keys = Object.keys(helpers);
|
|
262
|
-
keys.map((key) => {
|
|
263
|
-
const helper = helpers[key];
|
|
264
|
-
if (isString(helper)) helpers[key] = CONFIG.theme[helper];
|
|
265
|
-
else getThemeValue(helpers[key]);
|
|
266
|
-
return theme;
|
|
267
|
-
});
|
|
268
|
-
return theme;
|
|
269
|
-
};
|
|
270
|
-
const setTheme = (val, key) => {
|
|
271
|
-
const CONFIG = getActiveConfig();
|
|
272
|
-
if (CONFIG.useVariable) return setMediaTheme(val, key);
|
|
273
|
-
const { state, media, helpers } = val;
|
|
274
|
-
const value = setThemeValue(val, key);
|
|
275
|
-
const vp = CONFIG.varPrefix ? CONFIG.varPrefix + "-" : "";
|
|
276
|
-
const CSSvar = `--${vp}theme-${key}`;
|
|
277
|
-
setSelectors(val, value);
|
|
278
|
-
setMedia(val, value);
|
|
279
|
-
setHelpers(val, value);
|
|
280
|
-
return { var: CSSvar, value, state, media, helpers };
|
|
281
|
-
};
|
|
282
|
-
const keySetters = {
|
|
283
|
-
// eslint-disable-line
|
|
284
|
-
"@": (theme, value) => setMedia(theme, value),
|
|
285
|
-
":": (theme, value) => setSelectors(theme, value),
|
|
286
|
-
".": (theme, value) => setHelpers(theme, value)
|
|
287
|
-
};
|
|
288
|
-
const generateAutoVars = (schemes, varPrefix, CONFIG) => {
|
|
289
|
-
const { cssVars: CSS_VARS } = CONFIG;
|
|
290
|
-
if (!CONFIG.cssMediaVars) CONFIG.cssMediaVars = {};
|
|
291
|
-
const MEDIA_VARS = CONFIG.cssMediaVars;
|
|
292
|
-
const globalTheme = CONFIG.globalTheme !== void 0 ? CONFIG.globalTheme : "auto";
|
|
293
|
-
const result = {};
|
|
294
|
-
const allKeys = /* @__PURE__ */ new Set();
|
|
295
|
-
for (const scheme in schemes) {
|
|
296
|
-
if (schemes[scheme]) for (const k of Object.keys(schemes[scheme])) allKeys.add(k);
|
|
297
|
-
}
|
|
298
|
-
const brokenSchemes = /* @__PURE__ */ new Set();
|
|
299
|
-
for (const param of allKeys) {
|
|
300
|
-
const symb = param.slice(0, 1);
|
|
301
|
-
if (symb === "@" || symb === "." || symb === ":") continue;
|
|
302
|
-
if (!isColorParam(param)) continue;
|
|
303
|
-
for (const scheme in schemes) {
|
|
304
|
-
if (brokenSchemes.has(scheme)) continue;
|
|
305
|
-
const val = schemes[scheme]?.[param];
|
|
306
|
-
if (val === void 0) continue;
|
|
307
|
-
const color = getColor(val, `@${scheme}`);
|
|
308
|
-
if (color === void 0) continue;
|
|
309
|
-
if (isString(color) && /^[a-z][a-zA-Z]+$/.test(color) && !CSS_NAMED_COLORS.has(color)) {
|
|
310
|
-
brokenSchemes.add(scheme);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
for (const param of allKeys) {
|
|
315
|
-
const symb = param.slice(0, 1);
|
|
316
|
-
const hasObject = Object.values(schemes).some((s) => isObjectLike(s?.[param]));
|
|
317
|
-
if (symb === "." && hasObject) {
|
|
318
|
-
const helperName = param.slice(1);
|
|
319
|
-
const subSchemes = {};
|
|
320
|
-
for (const scheme in schemes) {
|
|
321
|
-
if (isObjectLike(schemes[scheme]?.[param])) subSchemes[scheme] = schemes[scheme][param];
|
|
322
|
-
}
|
|
323
|
-
result[param] = generateAutoVars(subSchemes, `${varPrefix}-${helperName}`, CONFIG);
|
|
324
|
-
} else if (symb === ":" && hasObject) {
|
|
325
|
-
const pseudoName = param.replace(/^:+/, "");
|
|
326
|
-
const subSchemes = {};
|
|
327
|
-
for (const scheme in schemes) {
|
|
328
|
-
if (isObjectLike(schemes[scheme]?.[param])) subSchemes[scheme] = schemes[scheme][param];
|
|
329
|
-
}
|
|
330
|
-
result[param] = generateAutoVars(subSchemes, `${varPrefix}-${pseudoName}`, CONFIG);
|
|
331
|
-
} else if (symb !== "@" && symb !== "." && symb !== ":") {
|
|
332
|
-
const vp = CONFIG.varPrefix ? CONFIG.varPrefix + "-" : "";
|
|
333
|
-
const autoVar = `--${vp}theme-${varPrefix}-${param}`;
|
|
334
|
-
const forced = globalTheme && globalTheme !== "auto" ? String(globalTheme).replace(/^'|'$/g, "") : null;
|
|
335
|
-
let fallbackColor;
|
|
336
|
-
for (const scheme in schemes) {
|
|
337
|
-
if (brokenSchemes.has(scheme)) continue;
|
|
338
|
-
const val = schemes[scheme]?.[param];
|
|
339
|
-
if (val === void 0) continue;
|
|
340
|
-
const color = getColor(val, `@${scheme}`);
|
|
341
|
-
if (color === void 0) continue;
|
|
342
|
-
if (forced && scheme === forced || !forced && (scheme === "light" || fallbackColor === void 0)) {
|
|
343
|
-
fallbackColor = color;
|
|
344
|
-
}
|
|
345
|
-
const selector = `[data-theme="${scheme}"]`;
|
|
346
|
-
if (!MEDIA_VARS[selector]) MEDIA_VARS[selector] = {};
|
|
347
|
-
MEDIA_VARS[selector][autoVar] = color;
|
|
348
|
-
if (scheme === "dark" || scheme === "light") {
|
|
349
|
-
const mq = `@media (prefers-color-scheme: ${scheme})`;
|
|
350
|
-
if (!MEDIA_VARS[mq]) MEDIA_VARS[mq] = {};
|
|
351
|
-
MEDIA_VARS[mq][autoVar] = color;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
if (fallbackColor !== void 0) {
|
|
355
|
-
CSS_VARS[autoVar] = fallbackColor;
|
|
356
|
-
}
|
|
357
|
-
result[param] = `var(${autoVar})`;
|
|
358
|
-
result[`.${param}`] = { [param]: result[param] };
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
if (result.background || result.color || result.backgroundColor) {
|
|
362
|
-
result[".inversed"] = {
|
|
363
|
-
color: result.background || result.backgroundColor,
|
|
364
|
-
background: result.color
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
return result;
|
|
368
|
-
};
|
|
369
|
-
const setMediaTheme = (val, key, suffix, prefers) => {
|
|
370
|
-
const CONFIG = getActiveConfig();
|
|
371
|
-
const { cssVars: CSS_VARS } = CONFIG;
|
|
372
|
-
const theme = { value: val };
|
|
373
|
-
const isTopLevel = !suffix && !prefers;
|
|
374
|
-
if (isObjectLike(val)) {
|
|
375
|
-
if (isTopLevel && CONFIG.useVariable) {
|
|
376
|
-
const schemes = {};
|
|
377
|
-
for (const param in val) {
|
|
378
|
-
if (param.startsWith("@") && isObjectLike(val[param])) {
|
|
379
|
-
schemes[param.slice(1)] = val[param];
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
if (Object.keys(schemes).length) {
|
|
383
|
-
const autoResult = generateAutoVars(schemes, key, CONFIG);
|
|
384
|
-
Object.assign(theme, autoResult);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
for (const param in val) {
|
|
388
|
-
const symb = param.slice(0, 1);
|
|
389
|
-
const value = val[param];
|
|
390
|
-
if (symb === "@" || symb === ":" || symb === ".") {
|
|
391
|
-
const hasPrefers = symb === "@" && param;
|
|
392
|
-
theme[param] = setMediaTheme(value, key, param, prefers || hasPrefers);
|
|
393
|
-
} else if (!isTopLevel) {
|
|
394
|
-
const color = getColor(value, prefers);
|
|
395
|
-
const metaSuffixes = [...new Set([prefers, suffix].filter((v) => v).map((v) => v.slice(1)))];
|
|
396
|
-
const varmetaSuffixName = metaSuffixes.length ? "-" + metaSuffixes.join("-") : "";
|
|
397
|
-
const vp = CONFIG.varPrefix ? CONFIG.varPrefix + "-" : "";
|
|
398
|
-
const CSSVar = `--${vp}theme-${key}${varmetaSuffixName}-${param}`;
|
|
399
|
-
if (CONFIG.useVariable) {
|
|
400
|
-
if (CONFIG.useThemeSuffixedVars) CSS_VARS[CSSVar] = color;
|
|
401
|
-
theme[param] = `var(${CSSVar})`;
|
|
402
|
-
} else {
|
|
403
|
-
theme[param] = color;
|
|
404
|
-
}
|
|
405
|
-
theme[`.${param}`] = { [param]: theme[param] };
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
if (!theme[".inversed"] && (theme.background || theme.color || theme.backgroundColor)) {
|
|
409
|
-
theme[".inversed"] = {
|
|
410
|
-
color: theme.background || theme.backgroundColor,
|
|
411
|
-
background: theme.color
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
if (isString(val) && isCSSVar(val)) {
|
|
416
|
-
const THEME = CONFIG.theme;
|
|
417
|
-
const value = THEME[val.slice(2)];
|
|
418
|
-
const getReferenced = getMediaTheme(value, prefers);
|
|
419
|
-
return getReferenced;
|
|
420
|
-
}
|
|
421
|
-
return theme;
|
|
422
|
-
};
|
|
423
|
-
const recursiveTheme = (val) => {
|
|
424
|
-
const CONFIG = getActiveConfig();
|
|
425
|
-
const obj = {};
|
|
426
|
-
for (const param in val) {
|
|
427
|
-
const symb = param.slice(0, 1);
|
|
428
|
-
if (isObjectLike(val[param])) {
|
|
429
|
-
if (symb === "@") {
|
|
430
|
-
continue;
|
|
431
|
-
} else if (symb === ":") {
|
|
432
|
-
obj[`&${param}`] = recursiveTheme(val[param]);
|
|
433
|
-
} else if (symb === ".") {
|
|
434
|
-
obj[`&${param}`] = recursiveTheme(val[param]);
|
|
435
|
-
}
|
|
436
|
-
} else obj[param] = val[param];
|
|
437
|
-
}
|
|
438
|
-
return obj;
|
|
439
|
-
};
|
|
440
|
-
const findModifierFromArray = (val, modifierArray) => {
|
|
441
|
-
const currentMod = modifierArray.shift();
|
|
442
|
-
if (val[currentMod]) return findModifierFromArray(val[currentMod], modifierArray);
|
|
443
|
-
return val;
|
|
444
|
-
};
|
|
445
|
-
const findModifier = (val, modifier) => {
|
|
446
|
-
if (isArray(modifier)) return findModifierFromArray(val, modifier);
|
|
447
|
-
else if (isString(modifier) && val[modifier]) return val[modifier];
|
|
448
|
-
else return val;
|
|
449
|
-
};
|
|
450
|
-
const checkForReference = (val, callback) => {
|
|
451
|
-
if (isString(val) && isCSSVar(val)) return getMediaTheme(val.slice(2));
|
|
452
|
-
return val;
|
|
453
|
-
};
|
|
454
|
-
const checkThemeReference = (val) => checkForReference(val, checkThemeReference);
|
|
455
|
-
const getMediaTheme = (value, modifier) => {
|
|
456
|
-
const activeConfig = getActiveConfig();
|
|
457
|
-
if (isString(value) && isCSSVar(value)) {
|
|
458
|
-
value = getMediaTheme(value.slice(2));
|
|
459
|
-
}
|
|
460
|
-
if (!value || !isString(value)) {
|
|
461
|
-
if (activeConfig.verbose) {
|
|
462
|
-
console.warn(`${value} - Theme is not a string`);
|
|
463
|
-
}
|
|
464
|
-
return;
|
|
465
|
-
}
|
|
466
|
-
const [themeName, ...themeModifiers] = isArray(value) ? value : value.split(" ");
|
|
467
|
-
let themeValue = activeConfig.theme[themeName];
|
|
468
|
-
if (themeValue && themeModifiers.length) {
|
|
469
|
-
themeValue = findModifier(themeValue, themeModifiers);
|
|
470
|
-
} else if (themeValue && modifier) {
|
|
471
|
-
themeValue = findModifier(themeValue, modifier);
|
|
472
|
-
}
|
|
473
|
-
const resolvedTheme = recursiveTheme(themeValue);
|
|
474
|
-
return resolvedTheme;
|
|
475
|
-
};
|
|
476
|
-
export {
|
|
477
|
-
getMediaTheme,
|
|
478
|
-
getTheme,
|
|
479
|
-
setMediaTheme,
|
|
480
|
-
setTheme
|
|
481
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { toCamelCase } from "@symbo.ls/utils";
|
|
2
|
-
import { getActiveConfig } from "../factory.js";
|
|
3
|
-
import {
|
|
4
|
-
applySequenceVars,
|
|
5
|
-
generateSequence,
|
|
6
|
-
getSequenceValuePropertyPair
|
|
7
|
-
} from "../utils/index.js";
|
|
8
|
-
const applyTimingSequence = () => {
|
|
9
|
-
const CONFIG = getActiveConfig();
|
|
10
|
-
const { timing: TIMING } = CONFIG;
|
|
11
|
-
generateSequence(TIMING);
|
|
12
|
-
applySequenceVars(TIMING);
|
|
13
|
-
};
|
|
14
|
-
const getTimingFunction = (value) => {
|
|
15
|
-
const CONFIG = getActiveConfig();
|
|
16
|
-
const { timing: TIMING } = CONFIG;
|
|
17
|
-
return TIMING[value] || TIMING[toCamelCase(value)] || value;
|
|
18
|
-
};
|
|
19
|
-
const getTimingByKey = (value, property = "timing") => {
|
|
20
|
-
const CONFIG = getActiveConfig();
|
|
21
|
-
const { timing: TIMING } = CONFIG;
|
|
22
|
-
return getSequenceValuePropertyPair(
|
|
23
|
-
value,
|
|
24
|
-
property,
|
|
25
|
-
TIMING
|
|
26
|
-
);
|
|
27
|
-
};
|
|
28
|
-
export {
|
|
29
|
-
applyTimingSequence,
|
|
30
|
-
getTimingByKey,
|
|
31
|
-
getTimingFunction
|
|
32
|
-
};
|