@symbo.ls/scratch 3.8.8 → 3.14.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/README.md +2 -2
- package/dist/cjs/defaultConfig/class.js +1 -2
- package/dist/cjs/defaultConfig/font-family.js +6 -6
- package/dist/cjs/defaultConfig/icons.js +2 -2
- package/dist/cjs/defaultConfig/svg.js +2 -2
- package/dist/cjs/defaultConfig/timing.js +1 -1
- package/dist/cjs/factory.js +72 -12
- package/dist/cjs/index.js +6 -4
- package/dist/cjs/set.js +113 -52
- package/dist/cjs/system/color.js +72 -12
- package/dist/cjs/system/document.js +3 -3
- package/dist/cjs/system/font.js +14 -14
- package/dist/cjs/system/reset.js +34 -7
- package/dist/cjs/system/shadow.js +4 -3
- package/dist/cjs/system/spacing.js +18 -18
- package/dist/cjs/system/svg.js +34 -7
- package/dist/cjs/system/theme.js +51 -50
- package/dist/cjs/system/timing.js +6 -6
- package/dist/cjs/system/typography.js +12 -3
- package/dist/cjs/transforms/index.js +4 -4
- package/dist/cjs/utils/color.js +1 -1
- package/dist/cjs/utils/font.js +3 -1
- package/dist/cjs/utils/sequence.js +35 -16
- package/dist/cjs/utils/sprite.js +11 -4
- package/dist/cjs/utils/var.js +23 -9
- package/dist/esm/defaultConfig/class.js +1 -2
- package/dist/esm/defaultConfig/font-family.js +6 -6
- package/dist/esm/defaultConfig/icons.js +2 -2
- package/dist/esm/defaultConfig/svg.js +2 -2
- package/dist/esm/defaultConfig/timing.js +1 -1
- package/dist/esm/factory.js +72 -12
- package/dist/esm/index.js +6 -4
- package/dist/esm/set.js +114 -53
- package/dist/esm/system/color.js +72 -12
- package/dist/esm/system/document.js +3 -3
- package/dist/esm/system/font.js +5 -5
- package/dist/esm/system/reset.js +34 -7
- package/dist/esm/system/shadow.js +4 -3
- package/dist/esm/system/spacing.js +3 -3
- package/dist/esm/system/svg.js +34 -7
- package/dist/esm/system/theme.js +51 -50
- package/dist/esm/system/timing.js +2 -2
- package/dist/esm/system/typography.js +12 -3
- package/dist/esm/transforms/index.js +4 -4
- package/dist/esm/utils/color.js +1 -1
- package/dist/esm/utils/font.js +3 -1
- package/dist/esm/utils/sequence.js +35 -16
- package/dist/esm/utils/sprite.js +11 -4
- package/dist/esm/utils/var.js +23 -9
- package/dist/iife/index.js +728 -302
- package/index.js +1 -0
- package/package.json +11 -14
- package/src/defaultConfig/class.js +2 -1
- package/src/defaultConfig/font-family.js +3 -3
- package/src/defaultConfig/icons.js +1 -1
- package/src/defaultConfig/svg.js +1 -1
- package/src/defaultConfig/timing.js +1 -1
- package/src/factory.js +85 -13
- package/src/index.js +16 -5
- package/src/set.js +156 -63
- package/src/system/color.js +113 -12
- package/src/system/document.js +3 -3
- package/src/system/font.js +5 -5
- package/src/system/reset.js +41 -8
- package/src/system/shadow.js +4 -3
- package/src/system/spacing.js +3 -3
- package/src/system/svg.js +44 -7
- package/src/system/theme.js +87 -64
- package/src/system/timing.js +2 -2
- package/src/system/typography.js +12 -3
- package/src/transforms/index.js +4 -4
- package/src/utils/color.js +2 -1
- package/src/utils/font.js +7 -1
- package/src/utils/sequence.js +46 -29
- package/src/utils/sprite.js +15 -4
- package/src/utils/var.js +27 -9
package/dist/esm/set.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FACTORY, getActiveConfig, setActiveConfig } from "./factory.js";
|
|
1
|
+
import { FACTORY, getActiveConfig, setActiveConfig, toCamel } from "./factory.js";
|
|
2
2
|
import {
|
|
3
3
|
setColor,
|
|
4
4
|
setGradient,
|
|
@@ -13,13 +13,13 @@ import {
|
|
|
13
13
|
applyTimingSequence,
|
|
14
14
|
applyDocument,
|
|
15
15
|
setShadow
|
|
16
|
-
} from "./system";
|
|
17
|
-
import { deepMerge } from "@
|
|
16
|
+
} from "./system/index.js";
|
|
17
|
+
import { deepMerge, isObject, isArray } from "@symbo.ls/utils";
|
|
18
18
|
const setVars = (val, key) => {
|
|
19
19
|
const CONFIG = getActiveConfig();
|
|
20
|
-
const {
|
|
20
|
+
const { cssVars } = CONFIG;
|
|
21
21
|
const varName = key.startsWith("--") ? key : `--${key}`;
|
|
22
|
-
|
|
22
|
+
cssVars[varName] = val;
|
|
23
23
|
return val;
|
|
24
24
|
};
|
|
25
25
|
const asIs = (val) => val;
|
|
@@ -27,14 +27,14 @@ const VALUE_TRANSFORMERS = {
|
|
|
27
27
|
color: setColor,
|
|
28
28
|
gradient: setGradient,
|
|
29
29
|
font: setFont,
|
|
30
|
-
|
|
30
|
+
fontFamily: setFontFamily,
|
|
31
31
|
fontfamily: setFontFamily,
|
|
32
32
|
theme: setTheme,
|
|
33
33
|
icons: setSvgIcon,
|
|
34
|
-
|
|
34
|
+
semanticIcons: asIs,
|
|
35
35
|
semanticicons: asIs,
|
|
36
36
|
svg: setSVG,
|
|
37
|
-
|
|
37
|
+
svgData: asIs,
|
|
38
38
|
typography: asIs,
|
|
39
39
|
shadow: setShadow,
|
|
40
40
|
spacing: asIs,
|
|
@@ -49,12 +49,14 @@ const VALUE_TRANSFORMERS = {
|
|
|
49
49
|
};
|
|
50
50
|
const setValue = (factoryName, value, key) => {
|
|
51
51
|
const CONFIG = getActiveConfig();
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
|
|
52
|
+
const camelName = toCamel(factoryName);
|
|
53
|
+
const lowerName = camelName.toLowerCase();
|
|
54
|
+
const FACTORY2 = CONFIG[camelName] || CONFIG[lowerName] || CONFIG[factoryName];
|
|
55
|
+
const transformer = VALUE_TRANSFORMERS[camelName] || VALUE_TRANSFORMERS[lowerName];
|
|
56
|
+
if (transformer) {
|
|
55
57
|
try {
|
|
56
|
-
const result =
|
|
57
|
-
FACTORY2[key] = result;
|
|
58
|
+
const result = transformer(value, key);
|
|
59
|
+
if (FACTORY2) FACTORY2[key] = result;
|
|
58
60
|
return FACTORY2;
|
|
59
61
|
} catch (error) {
|
|
60
62
|
if (CONFIG.verbose)
|
|
@@ -67,7 +69,11 @@ const setValue = (factoryName, value, key) => {
|
|
|
67
69
|
const setEach = (factoryName, props) => {
|
|
68
70
|
const CONFIG = getActiveConfig();
|
|
69
71
|
const lowerName = factoryName.toLowerCase();
|
|
70
|
-
const keys = Object.keys(props)
|
|
72
|
+
const keys = Object.keys(props).sort((a, b) => {
|
|
73
|
+
const aComposite = isObject(props[a]) || isArray(props[a]) ? 1 : 0;
|
|
74
|
+
const bComposite = isObject(props[b]) || isArray(props[b]) ? 1 : 0;
|
|
75
|
+
return aComposite - bComposite;
|
|
76
|
+
});
|
|
71
77
|
keys.forEach((key) => {
|
|
72
78
|
try {
|
|
73
79
|
return setValue(lowerName, props[key], key);
|
|
@@ -85,33 +91,59 @@ const setEach = (factoryName, props) => {
|
|
|
85
91
|
});
|
|
86
92
|
return CONFIG[lowerName] || CONFIG[factoryName];
|
|
87
93
|
};
|
|
88
|
-
const changeGlobalTheme = (newTheme) => {
|
|
89
|
-
const CONFIG = getActiveConfig();
|
|
94
|
+
const changeGlobalTheme = (newTheme, targetConfig) => {
|
|
95
|
+
const CONFIG = targetConfig || getActiveConfig();
|
|
90
96
|
CONFIG.globalTheme = newTheme;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
const configDoc = CONFIG.document && CONFIG.document.documentElement ? CONFIG.document : null;
|
|
98
|
+
const targetDoc = configDoc || (typeof document !== "undefined" ? document : null);
|
|
99
|
+
const targetWin = targetDoc && targetDoc.defaultView || (typeof window !== "undefined" ? window : null);
|
|
100
|
+
if (targetDoc) {
|
|
101
|
+
const root = CONFIG.themeRoot || targetDoc.documentElement;
|
|
102
|
+
const forced = newTheme && newTheme !== "auto";
|
|
103
|
+
if (forced) {
|
|
104
|
+
root.setAttribute("data-theme", newTheme);
|
|
105
|
+
if (newTheme === "dark" || newTheme === "light") {
|
|
106
|
+
root.style.colorScheme = newTheme;
|
|
107
|
+
} else {
|
|
108
|
+
root.style.colorScheme = "light dark";
|
|
109
|
+
}
|
|
110
|
+
} else if (targetWin && targetWin.matchMedia) {
|
|
111
|
+
const apply = (mq2) => {
|
|
112
|
+
root.setAttribute("data-theme", mq2.matches ? "dark" : "light");
|
|
113
|
+
};
|
|
114
|
+
const mq = targetWin.matchMedia("(prefers-color-scheme: dark)");
|
|
115
|
+
apply(mq);
|
|
116
|
+
root.style.colorScheme = "light dark";
|
|
117
|
+
if (!CONFIG.__prefersListener) {
|
|
118
|
+
CONFIG.__prefersListener = apply;
|
|
119
|
+
try {
|
|
120
|
+
mq.addEventListener("change", apply);
|
|
121
|
+
} catch (e) {
|
|
122
|
+
mq.addListener(apply);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
root.setAttribute("data-theme", "light");
|
|
127
|
+
root.style.colorScheme = "light";
|
|
128
|
+
}
|
|
96
129
|
}
|
|
97
|
-
|
|
98
|
-
|
|
130
|
+
const themeVarPrefix = CONFIG.varPrefix ? `--${CONFIG.varPrefix}-theme-` : "--theme-";
|
|
131
|
+
for (const key in CONFIG.cssVars) {
|
|
132
|
+
if (key.startsWith(themeVarPrefix)) delete CONFIG.cssVars[key];
|
|
99
133
|
}
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
const fresh = JSON.parse(JSON.stringify(source));
|
|
103
|
-
CONFIG.theme = fresh;
|
|
104
|
-
setEach("theme", fresh);
|
|
134
|
+
for (const key in CONFIG.cssMediaVars) {
|
|
135
|
+
delete CONFIG.cssMediaVars[key];
|
|
105
136
|
}
|
|
106
|
-
if (
|
|
107
|
-
const
|
|
137
|
+
if (targetDoc && CONFIG.cssVars) {
|
|
138
|
+
const targetSelector = CONFIG.scopeSelector || ":root";
|
|
139
|
+
const sheets = targetDoc.styleSheets;
|
|
108
140
|
for (let i = 0; i < sheets.length; i++) {
|
|
109
141
|
try {
|
|
110
142
|
const rules = sheets[i].cssRules;
|
|
111
143
|
for (let j = 0; j < rules.length; j++) {
|
|
112
|
-
if (rules[j].selectorText ===
|
|
113
|
-
for (const key in CONFIG.
|
|
114
|
-
rules[j].style.setProperty(key, CONFIG.
|
|
144
|
+
if (rules[j].selectorText === targetSelector) {
|
|
145
|
+
for (const key in CONFIG.cssVars) {
|
|
146
|
+
rules[j].style.setProperty(key, CONFIG.cssVars[key]);
|
|
115
147
|
}
|
|
116
148
|
return CONFIG;
|
|
117
149
|
}
|
|
@@ -124,7 +156,7 @@ const changeGlobalTheme = (newTheme) => {
|
|
|
124
156
|
};
|
|
125
157
|
const SET_OPTIONS = {};
|
|
126
158
|
const set = (recivedConfig, options = SET_OPTIONS) => {
|
|
127
|
-
let CONFIG = getActiveConfig();
|
|
159
|
+
let CONFIG = options.config || getActiveConfig();
|
|
128
160
|
const {
|
|
129
161
|
version,
|
|
130
162
|
verbose,
|
|
@@ -134,19 +166,19 @@ const set = (recivedConfig, options = SET_OPTIONS) => {
|
|
|
134
166
|
useFontImport,
|
|
135
167
|
useIconSprite,
|
|
136
168
|
globalTheme,
|
|
169
|
+
themeRoot,
|
|
137
170
|
useDocumentTheme,
|
|
138
171
|
useDefaultConfig,
|
|
139
172
|
semanticIcons,
|
|
140
|
-
SEMANTIC_ICONS,
|
|
141
|
-
// deprecated
|
|
142
|
-
semantic_icons,
|
|
143
173
|
files,
|
|
174
|
+
assets,
|
|
144
175
|
...config
|
|
145
176
|
} = recivedConfig;
|
|
146
177
|
if (options.newConfig) {
|
|
147
178
|
CONFIG = setActiveConfig(options.newConfig);
|
|
148
179
|
}
|
|
149
180
|
if (files !== void 0) CONFIG.files = files;
|
|
181
|
+
if (assets !== void 0) CONFIG.assets = assets;
|
|
150
182
|
if (verbose !== void 0) CONFIG.verbose = verbose;
|
|
151
183
|
if (useVariable !== void 0) CONFIG.useVariable = useVariable;
|
|
152
184
|
if (useReset !== void 0) CONFIG.useReset = useReset;
|
|
@@ -155,20 +187,46 @@ const set = (recivedConfig, options = SET_OPTIONS) => {
|
|
|
155
187
|
if (useIconSprite !== void 0) CONFIG.useIconSprite = useIconSprite;
|
|
156
188
|
if (useDocumentTheme !== void 0) CONFIG.useDocumentTheme = useDocumentTheme;
|
|
157
189
|
if (globalTheme !== void 0) CONFIG.globalTheme = globalTheme;
|
|
190
|
+
if (themeRoot !== void 0) CONFIG.themeRoot = themeRoot;
|
|
158
191
|
if (recivedConfig.useThemeSuffixedVars !== void 0)
|
|
159
192
|
CONFIG.useThemeSuffixedVars = recivedConfig.useThemeSuffixedVars;
|
|
160
193
|
if (useDefaultConfig !== void 0) CONFIG.useDefaultConfig = useDefaultConfig;
|
|
161
|
-
|
|
162
|
-
if (_semanticIcons !== void 0) {
|
|
163
|
-
CONFIG.semantic_icons = _semanticIcons;
|
|
164
|
-
CONFIG.semanticIcons = CONFIG.semantic_icons;
|
|
165
|
-
CONFIG.SEMANTIC_ICONS = CONFIG.semantic_icons;
|
|
166
|
-
}
|
|
194
|
+
if (semanticIcons !== void 0) CONFIG.semanticIcons = semanticIcons;
|
|
167
195
|
if (CONFIG.verbose) console.log(CONFIG);
|
|
168
|
-
|
|
169
|
-
|
|
196
|
+
const setConfigDoc = CONFIG.document && CONFIG.document.documentElement ? CONFIG.document : null;
|
|
197
|
+
const setTargetDoc = setConfigDoc || (typeof document !== "undefined" ? document : null);
|
|
198
|
+
const setTargetWin = setTargetDoc && setTargetDoc.defaultView || (typeof window !== "undefined" ? window : null);
|
|
199
|
+
const setRoot = setTargetDoc && (CONFIG.themeRoot || setTargetDoc.documentElement);
|
|
200
|
+
if (setRoot && typeof setRoot.setAttribute === "function") {
|
|
201
|
+
const forced = CONFIG.globalTheme && CONFIG.globalTheme !== "auto";
|
|
202
|
+
if (forced) {
|
|
203
|
+
setRoot.setAttribute("data-theme", CONFIG.globalTheme);
|
|
204
|
+
if (CONFIG.globalTheme === "dark" || CONFIG.globalTheme === "light") {
|
|
205
|
+
setRoot.style.colorScheme = CONFIG.globalTheme;
|
|
206
|
+
} else {
|
|
207
|
+
setRoot.style.colorScheme = "light dark";
|
|
208
|
+
}
|
|
209
|
+
} else if (setTargetWin && setTargetWin.matchMedia) {
|
|
210
|
+
const apply = (mq2) => {
|
|
211
|
+
setRoot.setAttribute("data-theme", mq2.matches ? "dark" : "light");
|
|
212
|
+
};
|
|
213
|
+
const mq = setTargetWin.matchMedia("(prefers-color-scheme: dark)");
|
|
214
|
+
apply(mq);
|
|
215
|
+
setRoot.style.colorScheme = "light dark";
|
|
216
|
+
if (!CONFIG.__prefersListener) {
|
|
217
|
+
CONFIG.__prefersListener = apply;
|
|
218
|
+
try {
|
|
219
|
+
mq.addEventListener("change", apply);
|
|
220
|
+
} catch (e) {
|
|
221
|
+
mq.addListener(apply);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
setRoot.setAttribute("data-theme", "light");
|
|
226
|
+
setRoot.style.colorScheme = "light";
|
|
227
|
+
}
|
|
170
228
|
}
|
|
171
|
-
if (!CONFIG.
|
|
229
|
+
if (!CONFIG.__svgCache) CONFIG.__svgCache = {};
|
|
172
230
|
const keys = Object.keys(config);
|
|
173
231
|
const keySet = new Set(keys);
|
|
174
232
|
keys.forEach((key) => {
|
|
@@ -177,29 +235,31 @@ const set = (recivedConfig, options = SET_OPTIONS) => {
|
|
|
177
235
|
deepMerge(config[lower], config[key]);
|
|
178
236
|
}
|
|
179
237
|
});
|
|
180
|
-
if (config.theme && !CONFIG._originalTheme) {
|
|
181
|
-
CONFIG._originalTheme = JSON.parse(JSON.stringify(config.theme));
|
|
182
|
-
}
|
|
183
238
|
keys.map((key) => {
|
|
184
239
|
const lower = key.toLowerCase();
|
|
185
240
|
if (lower !== key && keySet.has(lower)) return;
|
|
186
241
|
return setEach(key, config[key]);
|
|
187
242
|
});
|
|
188
|
-
if (
|
|
243
|
+
if (CONFIG.varPrefix) {
|
|
244
|
+
if (CONFIG.typography) CONFIG.typography.varPrefix = CONFIG.varPrefix;
|
|
245
|
+
if (CONFIG.spacing) CONFIG.spacing.varPrefix = CONFIG.varPrefix;
|
|
246
|
+
if (CONFIG.timing) CONFIG.timing.varPrefix = CONFIG.varPrefix;
|
|
247
|
+
}
|
|
248
|
+
if (config.typography) {
|
|
189
249
|
try {
|
|
190
250
|
applyTypographySequence();
|
|
191
251
|
} catch (e) {
|
|
192
252
|
if (CONFIG.verbose) console.warn("Error applying typography sequence", e);
|
|
193
253
|
}
|
|
194
254
|
}
|
|
195
|
-
if (config.spacing
|
|
255
|
+
if (config.spacing) {
|
|
196
256
|
try {
|
|
197
257
|
applySpacingSequence();
|
|
198
258
|
} catch (e) {
|
|
199
259
|
if (CONFIG.verbose) console.warn("Error applying spacing sequence", e);
|
|
200
260
|
}
|
|
201
261
|
}
|
|
202
|
-
if (config.timing
|
|
262
|
+
if (config.timing) {
|
|
203
263
|
try {
|
|
204
264
|
applyTimingSequence();
|
|
205
265
|
} catch (e) {
|
|
@@ -207,7 +267,8 @@ const set = (recivedConfig, options = SET_OPTIONS) => {
|
|
|
207
267
|
}
|
|
208
268
|
}
|
|
209
269
|
applyDocument();
|
|
210
|
-
applyReset();
|
|
270
|
+
const computedReset = applyReset();
|
|
271
|
+
if (computedReset) CONFIG.reset = computedReset;
|
|
211
272
|
return CONFIG;
|
|
212
273
|
};
|
|
213
274
|
export {
|
package/dist/esm/system/color.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { isObject, isArray, isString } from "@
|
|
1
|
+
import { isObject, isArray, isString } from "@symbo.ls/utils";
|
|
2
2
|
import { getActiveConfig } from "../factory.js";
|
|
3
3
|
import {
|
|
4
4
|
colorStringToRgbaArray,
|
|
5
5
|
getRgbTone,
|
|
6
6
|
isCSSVar,
|
|
7
7
|
parseColorToken
|
|
8
|
-
} from "../utils";
|
|
8
|
+
} from "../utils/index.js";
|
|
9
9
|
const getColor = (value, key, config) => {
|
|
10
10
|
const CONFIG = config || getActiveConfig();
|
|
11
11
|
if (!isString(value)) {
|
|
@@ -77,11 +77,14 @@ const getMediaColor = (value, globalTheme, config) => {
|
|
|
77
77
|
const isObj = isObject(val);
|
|
78
78
|
if (isObj && val.value) return getColor(value, `@${globalTheme}`, config);
|
|
79
79
|
else if (isObj) {
|
|
80
|
+
if (CONFIG.useVariable && val.var) return `var(${val.var})`;
|
|
80
81
|
if (globalTheme) return getColor(value, `@${globalTheme}`, config);
|
|
81
82
|
else {
|
|
82
83
|
const obj = {};
|
|
83
84
|
for (const mediaName in val) {
|
|
85
|
+
if (mediaName.charCodeAt(0) !== 64) continue;
|
|
84
86
|
const query = CONFIG.media[mediaName.slice(1)];
|
|
87
|
+
if (!query) continue;
|
|
85
88
|
const media = "@media " + (query === "print" ? `${query}` : `screen and ${query}`);
|
|
86
89
|
obj[media] = getColor(value, mediaName, config);
|
|
87
90
|
}
|
|
@@ -99,7 +102,11 @@ const setColor = (val, key, suffix) => {
|
|
|
99
102
|
val = getColor(rawRef);
|
|
100
103
|
if (!(val.includes("rgb") || val.includes("var") || val.includes("#"))) {
|
|
101
104
|
const parts = rawRef.split(" ");
|
|
102
|
-
|
|
105
|
+
let refColor = CONFIG.color[parts[0]];
|
|
106
|
+
if (refColor && !refColor.value && !refColor.rgb && (isString(refColor) || isArray(refColor) || isObject(refColor))) {
|
|
107
|
+
CONFIG.color[parts[0]] = setColor(refColor, parts[0]);
|
|
108
|
+
refColor = CONFIG.color[parts[0]];
|
|
109
|
+
}
|
|
103
110
|
if (refColor && refColor.value) {
|
|
104
111
|
let rgb2 = refColor.rgb;
|
|
105
112
|
const alpha2 = parts[1] !== void 0 ? parts[1] : "1";
|
|
@@ -130,10 +137,7 @@ const setColor = (val, key, suffix) => {
|
|
|
130
137
|
}
|
|
131
138
|
}
|
|
132
139
|
if (isArray(val)) {
|
|
133
|
-
|
|
134
|
-
"@light": setColor(val[0], key, "light"),
|
|
135
|
-
"@dark": setColor(val[1], key, "dark")
|
|
136
|
-
};
|
|
140
|
+
val = { "@light": val[0], "@dark": val[1] };
|
|
137
141
|
}
|
|
138
142
|
if (isObject(val)) {
|
|
139
143
|
const obj = {};
|
|
@@ -144,16 +148,71 @@ const setColor = (val, key, suffix) => {
|
|
|
144
148
|
variant.slice(0, 1) === "@" ? variant.slice(1) : variant
|
|
145
149
|
);
|
|
146
150
|
}
|
|
151
|
+
if (CONFIG.useVariable) {
|
|
152
|
+
const vp2 = CONFIG.varPrefix ? CONFIG.varPrefix + "-" : "";
|
|
153
|
+
const adaptiveVar = `--${vp2}color-${key}`;
|
|
154
|
+
let fallbackValue;
|
|
155
|
+
const schemeValues = {};
|
|
156
|
+
for (const variant in obj) {
|
|
157
|
+
if (variant.charCodeAt(0) !== 64) continue;
|
|
158
|
+
const scheme = variant.slice(1);
|
|
159
|
+
const entry = obj[variant];
|
|
160
|
+
const value2 = entry && (entry.value || entry);
|
|
161
|
+
if (!value2 || typeof value2 !== "string") continue;
|
|
162
|
+
schemeValues[scheme] = value2;
|
|
163
|
+
if (scheme === "light" || fallbackValue === void 0) fallbackValue = value2;
|
|
164
|
+
}
|
|
165
|
+
if (fallbackValue !== void 0) {
|
|
166
|
+
CONFIG.cssVars[adaptiveVar] = fallbackValue;
|
|
167
|
+
if (!CONFIG.cssMediaVars) CONFIG.cssMediaVars = {};
|
|
168
|
+
for (const scheme in schemeValues) {
|
|
169
|
+
const sel = `[data-theme="${scheme}"]`;
|
|
170
|
+
if (!CONFIG.cssMediaVars[sel]) CONFIG.cssMediaVars[sel] = {};
|
|
171
|
+
CONFIG.cssMediaVars[sel][adaptiveVar] = schemeValues[scheme];
|
|
172
|
+
if (scheme === "light" || scheme === "dark") {
|
|
173
|
+
const mq = `@media (prefers-color-scheme: ${scheme})`;
|
|
174
|
+
if (!CONFIG.cssMediaVars[mq]) CONFIG.cssMediaVars[mq] = {};
|
|
175
|
+
CONFIG.cssMediaVars[mq][adaptiveVar] = schemeValues[scheme];
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
obj.var = adaptiveVar;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
147
181
|
return obj;
|
|
148
182
|
}
|
|
149
|
-
const
|
|
150
|
-
const
|
|
183
|
+
const vp = CONFIG.varPrefix ? CONFIG.varPrefix + "-" : "";
|
|
184
|
+
const CSSVar = `--${vp}color-${key}` + (suffix ? `-${suffix}` : "");
|
|
185
|
+
let resolvedVal = val.value || val;
|
|
186
|
+
if (isString(resolvedVal) && resolvedVal.includes(".") && !resolvedVal.includes("(")) {
|
|
187
|
+
const [colorRef, alphaStr] = resolvedVal.split(".");
|
|
188
|
+
const refColor = CONFIG.color[colorRef];
|
|
189
|
+
if (refColor && refColor.rgb) {
|
|
190
|
+
resolvedVal = `rgba(${refColor.rgb}, ${parseFloat("0." + alphaStr) || 1})`;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (isString(resolvedVal) && !resolvedVal.includes("(") && !resolvedVal.startsWith("#")) {
|
|
194
|
+
const parsed = parseColorToken(resolvedVal);
|
|
195
|
+
if (parsed && parsed.name && !parsed.passthrough && !parsed.cssVar) {
|
|
196
|
+
const refColor = CONFIG.color[parsed.name];
|
|
197
|
+
if (refColor && !refColor.value && !refColor.rgb && (isString(refColor) || isArray(refColor) || isObject(refColor))) {
|
|
198
|
+
CONFIG.color[parsed.name] = setColor(refColor, parsed.name);
|
|
199
|
+
}
|
|
200
|
+
const baseColor = CONFIG.color[parsed.name];
|
|
201
|
+
if (baseColor && baseColor.rgb) {
|
|
202
|
+
let rgb2 = baseColor.rgb;
|
|
203
|
+
if (parsed.tone) rgb2 = getRgbTone(rgb2, parsed.tone);
|
|
204
|
+
const alphaVal = parsed.alpha ? parseFloat(parsed.alpha) : 1;
|
|
205
|
+
resolvedVal = `rgba(${rgb2}, ${alphaVal})`;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const colorArr = colorStringToRgbaArray(resolvedVal);
|
|
151
210
|
const [r, g, b, a = 1] = colorArr;
|
|
152
211
|
const alpha = parseFloat(a.toFixed(2));
|
|
153
212
|
const rgb = `${r}, ${g}, ${b}`;
|
|
154
213
|
const value = `rgba(${rgb}, ${alpha})`;
|
|
155
214
|
if (CONFIG.useVariable) {
|
|
156
|
-
CONFIG.
|
|
215
|
+
CONFIG.cssVars[CSSVar] = value;
|
|
157
216
|
}
|
|
158
217
|
return {
|
|
159
218
|
var: CSSVar,
|
|
@@ -176,9 +235,10 @@ const setGradient = (val, key, suffix) => {
|
|
|
176
235
|
for (const variant in val) obj[variant] = setGradient(val[variant], key, variant.slice(0, 1) === "@" ? variant.slice(1) : variant);
|
|
177
236
|
return obj;
|
|
178
237
|
}
|
|
179
|
-
const
|
|
238
|
+
const vp = CONFIG.varPrefix ? CONFIG.varPrefix + "-" : "";
|
|
239
|
+
const CSSVar = `--${vp}gradient-${key}` + (suffix ? `-${suffix}` : "");
|
|
180
240
|
if (CONFIG.useVariable) {
|
|
181
|
-
CONFIG.
|
|
241
|
+
CONFIG.cssVars[CSSVar] = val.value || val;
|
|
182
242
|
}
|
|
183
243
|
return {
|
|
184
244
|
var: CSSVar,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { merge } from "@
|
|
1
|
+
import { merge } from "@symbo.ls/utils";
|
|
2
2
|
import { getActiveConfig } from "../factory.js";
|
|
3
|
-
import { getDefaultOrFirstKey } from "../utils";
|
|
3
|
+
import { getDefaultOrFirstKey } from "../utils/index.js";
|
|
4
4
|
const applyDocument = () => {
|
|
5
5
|
const CONFIG = getActiveConfig();
|
|
6
|
-
const { document: DOCUMENT,
|
|
6
|
+
const { document: DOCUMENT, fontFamily: FONT_FAMILY, theme: THEME, typography: TYPOGRAPHY } = CONFIG;
|
|
7
7
|
return merge(DOCUMENT, {
|
|
8
8
|
theme: THEME.document,
|
|
9
9
|
fontFamily: getDefaultOrFirstKey(FONT_FAMILY),
|
package/dist/esm/system/font.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isObject, isArray } from "@
|
|
2
|
-
import { arrayzeValue } from "@symbo.ls/
|
|
1
|
+
import { isObject, isArray } from "@symbo.ls/utils";
|
|
2
|
+
import { arrayzeValue } from "@symbo.ls/utils";
|
|
3
3
|
import { getActiveConfig } from "../factory.js";
|
|
4
4
|
import {
|
|
5
5
|
getDefaultOrFirstKey,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
setCustomFontMedia,
|
|
9
9
|
setFontImport,
|
|
10
10
|
resolveFileUrl
|
|
11
|
-
} from "../utils";
|
|
11
|
+
} from "../utils/index.js";
|
|
12
12
|
const setFont = (val, key) => {
|
|
13
13
|
const CONFIG = getActiveConfig();
|
|
14
14
|
const CSSvar = `--font-${key}`;
|
|
@@ -38,12 +38,12 @@ const setFont = (val, key) => {
|
|
|
38
38
|
};
|
|
39
39
|
const getFontFamily = (key, factory) => {
|
|
40
40
|
const CONFIG = getActiveConfig();
|
|
41
|
-
const {
|
|
41
|
+
const { fontFamily: FONT_FAMILY } = CONFIG;
|
|
42
42
|
return getDefaultOrFirstKey(factory || FONT_FAMILY, key);
|
|
43
43
|
};
|
|
44
44
|
const setFontFamily = (val, key) => {
|
|
45
45
|
const CONFIG = getActiveConfig();
|
|
46
|
-
const {
|
|
46
|
+
const { fontFamily: FONT_FAMILY, fontFamilyTypes: FONT_FAMILY_TYPES } = CONFIG;
|
|
47
47
|
let { value, type } = val;
|
|
48
48
|
if (val.isDefault) FONT_FAMILY.default = key;
|
|
49
49
|
if (isObject(value)) value = arrayzeValue(value);
|
package/dist/esm/system/reset.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { deepMerge, merge, overwriteDeep } from "@
|
|
1
|
+
import { deepMerge, merge, overwriteDeep } from "@symbo.ls/utils";
|
|
2
2
|
import { getActiveConfig } from "../factory.js";
|
|
3
3
|
import { getMediaTheme } from "./theme.js";
|
|
4
4
|
const applyReset = (reset = {}) => {
|
|
@@ -22,10 +22,28 @@ const applyReset = (reset = {}) => {
|
|
|
22
22
|
const { body, ...templates } = TYPOGRAPHY.templates;
|
|
23
23
|
const globalTheme = CONFIG.useDocumentTheme ? getMediaTheme("document") : {};
|
|
24
24
|
if (RESET.html) overwriteDeep(RESET.html, globalTheme);
|
|
25
|
+
if (TYPOGRAPHY.unit) {
|
|
26
|
+
const { media: MEDIA } = CONFIG;
|
|
27
|
+
for (const key in TYPOGRAPHY) {
|
|
28
|
+
if (key.charAt(0) !== "@") continue;
|
|
29
|
+
const mediaTypo = TYPOGRAPHY[key];
|
|
30
|
+
if (!mediaTypo) continue;
|
|
31
|
+
if (mediaTypo.unit === TYPOGRAPHY.unit || !mediaTypo.unit) continue;
|
|
32
|
+
const mediaUnit = mediaTypo.unit;
|
|
33
|
+
const mediaBase = mediaTypo.base || TYPOGRAPHY.base;
|
|
34
|
+
const mediaBrowserDefault = mediaTypo.browserDefault || TYPOGRAPHY.browserDefault;
|
|
35
|
+
const mediaName = key.slice(1);
|
|
36
|
+
const query = MEDIA[mediaName];
|
|
37
|
+
if (!query) continue;
|
|
38
|
+
const mediaKey = "@media " + (query === "print" ? query : "screen and " + query);
|
|
39
|
+
if (!RESET[mediaKey]) RESET[mediaKey] = {};
|
|
40
|
+
if (!RESET[mediaKey].html) RESET[mediaKey].html = {};
|
|
41
|
+
RESET[mediaKey].html.fontSize = mediaBase / mediaBrowserDefault + mediaUnit;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
25
44
|
return deepMerge(merge(RESET, reset), {
|
|
26
45
|
html: {
|
|
27
46
|
position: "absolute",
|
|
28
|
-
// overflow: 'hidden',
|
|
29
47
|
width: "100%",
|
|
30
48
|
height: "100%",
|
|
31
49
|
top: "0",
|
|
@@ -34,7 +52,7 @@ const applyReset = (reset = {}) => {
|
|
|
34
52
|
WebkitFontSmoothing: "subpixel-antialiased",
|
|
35
53
|
scrollBehavior: "smooth",
|
|
36
54
|
...globalTheme,
|
|
37
|
-
fontSize: TYPOGRAPHY.browserDefault + "px",
|
|
55
|
+
fontSize: TYPOGRAPHY.unit ? TYPOGRAPHY.base / TYPOGRAPHY.browserDefault + TYPOGRAPHY.unit : TYPOGRAPHY.browserDefault + "px",
|
|
38
56
|
fontFamily: DOCUMENT.fontFamily,
|
|
39
57
|
lineHeight: DOCUMENT.lineHeight
|
|
40
58
|
},
|
|
@@ -50,14 +68,23 @@ const applyReset = (reset = {}) => {
|
|
|
50
68
|
a: {
|
|
51
69
|
color: "currentColor"
|
|
52
70
|
},
|
|
53
|
-
|
|
71
|
+
button: {
|
|
72
|
+
color: "inherit",
|
|
73
|
+
font: "inherit",
|
|
74
|
+
background: "transparent",
|
|
75
|
+
border: "none",
|
|
76
|
+
cursor: "pointer",
|
|
77
|
+
appearance: "none",
|
|
78
|
+
WebkitAppearance: "none"
|
|
79
|
+
},
|
|
80
|
+
"input, select, textarea": {
|
|
81
|
+
color: "inherit",
|
|
82
|
+
font: "inherit"
|
|
83
|
+
},
|
|
54
84
|
fieldset: {
|
|
55
85
|
border: 0,
|
|
56
86
|
padding: 0,
|
|
57
87
|
margin: 0
|
|
58
|
-
},
|
|
59
|
-
"select, input": {
|
|
60
|
-
fontFamily: DOCUMENT.fontFamily
|
|
61
88
|
}
|
|
62
89
|
});
|
|
63
90
|
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
isObject,
|
|
7
7
|
isString,
|
|
8
8
|
isArray
|
|
9
|
-
} from "@
|
|
9
|
+
} from "@symbo.ls/utils";
|
|
10
10
|
const setShadow = (value, key, suffix, prefers) => {
|
|
11
11
|
const CONFIG = getActiveConfig();
|
|
12
12
|
if (isArray(value)) {
|
|
@@ -43,9 +43,10 @@ const setShadow = (value, key, suffix, prefers) => {
|
|
|
43
43
|
}).join(" ");
|
|
44
44
|
}).join(", ");
|
|
45
45
|
}
|
|
46
|
-
const
|
|
46
|
+
const vp = CONFIG.varPrefix ? CONFIG.varPrefix + "-" : "";
|
|
47
|
+
const CSSVar = `--${vp}shadow-${key}` + (suffix ? `-${suffix}` : "");
|
|
47
48
|
if (CONFIG.useVariable) {
|
|
48
|
-
CONFIG.
|
|
49
|
+
CONFIG.cssVars[CSSVar] = value;
|
|
49
50
|
}
|
|
50
51
|
return {
|
|
51
52
|
var: CSSVar,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { arrayzeValue } from "@symbo.ls/
|
|
2
|
-
import { isArray, isString, merge } from "@
|
|
1
|
+
import { arrayzeValue } from "@symbo.ls/utils";
|
|
2
|
+
import { isArray, isString, merge } from "@symbo.ls/utils";
|
|
3
3
|
import { getActiveConfig } from "../factory.js";
|
|
4
4
|
import {
|
|
5
5
|
CSS_UNITS,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
generateSequence,
|
|
9
9
|
getFnPrefixAndValue,
|
|
10
10
|
getSequenceValuePropertyPair
|
|
11
|
-
} from "../utils";
|
|
11
|
+
} from "../utils/index.js";
|
|
12
12
|
const runThroughMedia = (FACTORY) => {
|
|
13
13
|
for (const prop in FACTORY) {
|
|
14
14
|
const mediaProps = FACTORY[prop];
|
package/dist/esm/system/svg.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { document } from "@
|
|
2
|
-
import { generateSprite, convertSvgToSymbol } from "../utils";
|
|
1
|
+
import { document } from "@symbo.ls/utils";
|
|
2
|
+
import { generateSprite, convertSvgToSymbol } from "../utils/index.js";
|
|
3
3
|
import { getActiveConfig } from "../factory.js";
|
|
4
4
|
const DEF_OPTIONS = {
|
|
5
5
|
document
|
|
@@ -18,12 +18,12 @@ const setSVG = (val, key) => {
|
|
|
18
18
|
const appendSVGSprite = (LIBRARY, options = DEF_OPTIONS) => {
|
|
19
19
|
const CONFIG = getActiveConfig();
|
|
20
20
|
const lib = Object.keys(LIBRARY).length ? {} : CONFIG.svg;
|
|
21
|
-
for (const key in LIBRARY) lib[key] =
|
|
21
|
+
for (const key in LIBRARY) lib[key] = LIBRARY[key];
|
|
22
22
|
appendSVG(lib, options);
|
|
23
23
|
};
|
|
24
24
|
const setSvgIcon = (val, key) => {
|
|
25
25
|
const CONFIG = getActiveConfig();
|
|
26
|
-
if (CONFIG.useIconSprite && !CONFIG.
|
|
26
|
+
if (CONFIG.useIconSprite && !CONFIG.semanticIcons?.[key]) {
|
|
27
27
|
return setSVG(val, key);
|
|
28
28
|
}
|
|
29
29
|
return val;
|
|
@@ -31,7 +31,7 @@ const setSvgIcon = (val, key) => {
|
|
|
31
31
|
const appendSvgIconsSprite = (LIBRARY, options = DEF_OPTIONS) => {
|
|
32
32
|
const CONFIG = getActiveConfig();
|
|
33
33
|
const lib = Object.keys(LIBRARY).length ? {} : CONFIG.icons;
|
|
34
|
-
for (const key in LIBRARY) lib[key] =
|
|
34
|
+
for (const key in LIBRARY) lib[key] = LIBRARY[key];
|
|
35
35
|
appendSVG(lib, options);
|
|
36
36
|
};
|
|
37
37
|
const createSVGSpriteElement = (doc, options = { isRoot: true }) => {
|
|
@@ -46,6 +46,24 @@ const createSVGSpriteElement = (doc, options = { isRoot: true }) => {
|
|
|
46
46
|
}
|
|
47
47
|
return svgElem;
|
|
48
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
|
+
};
|
|
49
67
|
const appendSVG = (lib, options = DEF_OPTIONS) => {
|
|
50
68
|
const CONFIG = getActiveConfig();
|
|
51
69
|
const doc = options.document || document;
|
|
@@ -58,8 +76,11 @@ const appendSVG = (lib, options = DEF_OPTIONS) => {
|
|
|
58
76
|
const exists = doc.querySelector("#svgSprite");
|
|
59
77
|
const SVGsprite = generateSprite(lib);
|
|
60
78
|
const spriteHtml = `<svg aria-hidden="true" width="0" height="0" style="position:absolute" id="svgSprite">${SVGsprite}</svg>`;
|
|
79
|
+
const parsed = parseSVGSprite(doc, SVGsprite);
|
|
61
80
|
if (exists) {
|
|
62
|
-
if (
|
|
81
|
+
if (parsed) {
|
|
82
|
+
moveChildren(doc, parsed, exists);
|
|
83
|
+
} else if (doc.body.insertAdjacentHTML) {
|
|
63
84
|
exists.insertAdjacentHTML("beforeend", SVGsprite);
|
|
64
85
|
} else {
|
|
65
86
|
const tempSVG = createSVGSpriteElement(doc, { isRoot: false });
|
|
@@ -67,7 +88,13 @@ const appendSVG = (lib, options = DEF_OPTIONS) => {
|
|
|
67
88
|
exists.append(...tempSVG.children);
|
|
68
89
|
}
|
|
69
90
|
} else {
|
|
70
|
-
if (
|
|
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) {
|
|
71
98
|
doc.body.insertAdjacentHTML("afterbegin", spriteHtml);
|
|
72
99
|
} else {
|
|
73
100
|
const svgSpriteDOM = createSVGSpriteElement(doc);
|