@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
|
@@ -34,8 +34,8 @@ __export(sequence_exports, {
|
|
|
34
34
|
setSubScalingVar: () => setSubScalingVar
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(sequence_exports);
|
|
37
|
-
var import_utils = require("@
|
|
38
|
-
var
|
|
37
|
+
var import_utils = require("@symbo.ls/utils");
|
|
38
|
+
var import_utils2 = require("@symbo.ls/utils");
|
|
39
39
|
var import_factory = require("../factory.js");
|
|
40
40
|
var import_unit = require("./unit.js");
|
|
41
41
|
var import_color = require("./color.js");
|
|
@@ -79,7 +79,8 @@ const setSequenceValue = (props, sequenceProps) => {
|
|
|
79
79
|
variable
|
|
80
80
|
};
|
|
81
81
|
sequenceProps.scales[key] = scaling;
|
|
82
|
-
sequenceProps.
|
|
82
|
+
const varUnit = VIEWPORT_UNITS.has(sequenceProps.unit) ? "rem" : sequenceProps.unit;
|
|
83
|
+
sequenceProps.vars[variable] = scaling + varUnit;
|
|
83
84
|
};
|
|
84
85
|
const getFnPrefixAndValue = (val) => {
|
|
85
86
|
if (!val.includes("(")) return val;
|
|
@@ -87,11 +88,14 @@ const getFnPrefixAndValue = (val) => {
|
|
|
87
88
|
const value = val.slice(val.indexOf("(") + 1, val.lastIndexOf(")"));
|
|
88
89
|
return [prefix, value];
|
|
89
90
|
};
|
|
91
|
+
const VIEWPORT_UNITS = /* @__PURE__ */ new Set(["vw", "vh", "vmin", "vmax", "svw", "svh", "lvw", "lvh", "dvw", "dvh"]);
|
|
90
92
|
const setScalingVar = (key, sequenceProps) => {
|
|
91
|
-
const { base, type, unit } = sequenceProps;
|
|
93
|
+
const { base, type, unit: rawUnit } = sequenceProps;
|
|
94
|
+
const unit = VIEWPORT_UNITS.has(rawUnit) ? "rem" : rawUnit;
|
|
92
95
|
const defaultVal = ((0, import_unit.isScalingUnit)(unit) ? 1 : base) + unit;
|
|
93
96
|
if (key === 0) return defaultVal;
|
|
94
|
-
const
|
|
97
|
+
const vp = sequenceProps.varPrefix ? sequenceProps.varPrefix + "-" : "";
|
|
98
|
+
const prefix = "--" + vp + (type && type.replace(".", "-"));
|
|
95
99
|
const ratioVar = `${prefix}-ratio`;
|
|
96
100
|
if (key > 0) {
|
|
97
101
|
const prevLetterKey = numToLetterMap[key - 1];
|
|
@@ -99,6 +103,12 @@ const setScalingVar = (key, sequenceProps) => {
|
|
|
99
103
|
}
|
|
100
104
|
if (key < 0) {
|
|
101
105
|
const nextLetterKey = numToLetterMap[key + 1];
|
|
106
|
+
const absKey = Math.abs(key);
|
|
107
|
+
const phiPow = Math.pow(PHI, 2 * absKey);
|
|
108
|
+
const prevAscKey = numToLetterMap[absKey];
|
|
109
|
+
if (prevAscKey) {
|
|
110
|
+
return `max(calc(var(${prefix}-${nextLetterKey}) / var(${ratioVar})), calc(var(${prefix}-${prevAscKey}) / ${phiPow.toFixed(4)}))`;
|
|
111
|
+
}
|
|
102
112
|
return `calc(var(${prefix}-${nextLetterKey}) / var(${ratioVar}))`;
|
|
103
113
|
}
|
|
104
114
|
};
|
|
@@ -106,7 +116,8 @@ const setSubScalingVar = (index, arr, variable, sequenceProps) => {
|
|
|
106
116
|
const { type } = sequenceProps;
|
|
107
117
|
const skipMiddle = index === 2 && arr.length === 2;
|
|
108
118
|
const indexMapWithLength = skipMiddle ? index + 1 : index;
|
|
109
|
-
const
|
|
119
|
+
const vp = sequenceProps.varPrefix ? sequenceProps.varPrefix + "-" : "";
|
|
120
|
+
const prefix = "--" + vp + (type && type.replace(".", "-"));
|
|
110
121
|
const subRatioVarPrefix = `${prefix}-sub-ratio-`;
|
|
111
122
|
return `calc(var(${variable}) * var(${subRatioVarPrefix + indexMapWithLength}))`;
|
|
112
123
|
};
|
|
@@ -150,13 +161,19 @@ const generateSubSequence = (props, sequenceProps) => {
|
|
|
150
161
|
setSequenceValue(props2, sequenceProps);
|
|
151
162
|
});
|
|
152
163
|
};
|
|
164
|
+
const PHI = 1.618;
|
|
153
165
|
const switchSequenceOnNegative = (key, base, ratio) => {
|
|
154
|
-
return base * Math.pow(ratio, key);
|
|
166
|
+
if (key >= 0) return base * Math.pow(ratio, key);
|
|
167
|
+
const absKey = Math.abs(key);
|
|
168
|
+
const current = base * Math.pow(ratio, key);
|
|
169
|
+
const normalized = base * Math.pow(ratio, absKey) / Math.pow(PHI, 2 * absKey);
|
|
170
|
+
return Math.max(current, normalized);
|
|
155
171
|
};
|
|
156
172
|
const generateSequence = (sequenceProps) => {
|
|
157
173
|
const { type, base, ratio, range, subSequence } = sequenceProps;
|
|
158
174
|
const n = Math.abs(range[0]) + Math.abs(range[1]);
|
|
159
|
-
const
|
|
175
|
+
const vp = sequenceProps.varPrefix ? sequenceProps.varPrefix + "-" : "";
|
|
176
|
+
const prefix = "--" + vp + (type && type.replace(".", "-")) + "-";
|
|
160
177
|
for (let i = 0; i <= n; i++) {
|
|
161
178
|
const key = range[1] - i;
|
|
162
179
|
const letterKey = numToLetterMap[key];
|
|
@@ -197,7 +214,8 @@ const generateSequencePosition = (sequenceProps, position = 0) => {
|
|
|
197
214
|
};
|
|
198
215
|
const value = base * Math.pow(ratio, index);
|
|
199
216
|
const scaling = ~~(value / base * 100) / 100;
|
|
200
|
-
const
|
|
217
|
+
const vp = sequenceProps.varPrefix ? sequenceProps.varPrefix + "-" : "";
|
|
218
|
+
const prefix = "--" + vp + (type && type.replace(".", "-")) + "-";
|
|
201
219
|
const variable = prefix + letterKey;
|
|
202
220
|
const scalingVariable = setScalingVar(index, sequenceProps);
|
|
203
221
|
const props = {
|
|
@@ -238,7 +256,8 @@ const getSequenceValue = (value = "A", sequenceProps) => {
|
|
|
238
256
|
"revert-layer"
|
|
239
257
|
];
|
|
240
258
|
if (skipArr.includes(value)) return value;
|
|
241
|
-
const
|
|
259
|
+
const vp = sequenceProps.varPrefix ? sequenceProps.varPrefix + "-" : "";
|
|
260
|
+
const prefix = `--${vp}${(0, import_utils2.toDashCase)(sequenceProps.type.replace(".", "-"))}-`;
|
|
242
261
|
const letterVal = value.toUpperCase();
|
|
243
262
|
const isNegative = letterVal.slice(0, 1) === "-" ? "-" : "";
|
|
244
263
|
let absValue = isNegative ? letterVal.slice(1) : letterVal;
|
|
@@ -285,12 +304,12 @@ const getSequenceValueBySymbols = (value, sequenceProps) => {
|
|
|
285
304
|
(v) => value.includes(v + " ")
|
|
286
305
|
);
|
|
287
306
|
if (!mathArr.length) return value;
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
return
|
|
307
|
+
const symbolRegex = /(\s*[+\-*/,]\s*)/;
|
|
308
|
+
const tokens = value.split(symbolRegex);
|
|
309
|
+
return tokens.map((token) => {
|
|
310
|
+
const trimmed = token.trim();
|
|
311
|
+
if (!trimmed || ["+", "-", "*", "/", ","].includes(trimmed)) return token;
|
|
312
|
+
return getSequenceValue(trimmed, sequenceProps);
|
|
294
313
|
}).join("");
|
|
295
314
|
};
|
|
296
315
|
const getSequenceValuePropertyPair = (value, propertyName, sequenceProps, fnPrefix) => {
|
package/dist/cjs/utils/sprite.js
CHANGED
|
@@ -22,15 +22,15 @@ __export(sprite_exports, {
|
|
|
22
22
|
generateSprite: () => generateSprite
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(sprite_exports);
|
|
25
|
-
var import_utils = require("@
|
|
26
|
-
var import_factory = require("../factory");
|
|
25
|
+
var import_utils = require("@symbo.ls/utils");
|
|
26
|
+
var import_factory = require("../factory.js");
|
|
27
27
|
const isDev = (0, import_utils.isNotProduction)();
|
|
28
28
|
const generateSprite = (icons) => {
|
|
29
29
|
const CONFIG = (0, import_factory.getActiveConfig)();
|
|
30
30
|
let sprite = "";
|
|
31
31
|
for (const key in icons) {
|
|
32
|
-
if (CONFIG.
|
|
33
|
-
else CONFIG.
|
|
32
|
+
if (CONFIG.__svgCache[key]) continue;
|
|
33
|
+
else CONFIG.__svgCache[key] = true;
|
|
34
34
|
sprite += icons[key];
|
|
35
35
|
}
|
|
36
36
|
return sprite;
|
|
@@ -81,5 +81,12 @@ const convertSvgToSymbol = (key, code) => {
|
|
|
81
81
|
symbol = symbol.replace(/width="[^"]*"/, "");
|
|
82
82
|
symbol = symbol.replace(/height="[^"]*"/, "");
|
|
83
83
|
symbol = symbol.replace("</svg", "</symbol");
|
|
84
|
+
symbol = expandSvgSelfClosing(symbol);
|
|
84
85
|
return symbol;
|
|
85
86
|
};
|
|
87
|
+
const SVG_VOID_TAGS = "line|circle|ellipse|rect|polyline|polygon|path|stop|use|image";
|
|
88
|
+
const SVG_SELF_CLOSING_RE = new RegExp(
|
|
89
|
+
`<(${SVG_VOID_TAGS})\\b([^>]*?)\\s*/>`,
|
|
90
|
+
"g"
|
|
91
|
+
);
|
|
92
|
+
const expandSvgSelfClosing = (str) => str.replace(SVG_SELF_CLOSING_RE, "<$1$2></$1>");
|
package/dist/cjs/utils/var.js
CHANGED
|
@@ -24,13 +24,13 @@ __export(var_exports, {
|
|
|
24
24
|
setVariables: () => setVariables
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(var_exports);
|
|
27
|
-
var import_utils = require("@
|
|
27
|
+
var import_utils = require("@symbo.ls/utils");
|
|
28
28
|
var import_factory = require("../factory.js");
|
|
29
29
|
var import_sequence = require("./sequence.js");
|
|
30
30
|
var import_unit = require("./unit.js");
|
|
31
31
|
const setVariables = (result, key) => {
|
|
32
32
|
const CONFIG = (0, import_factory.getActiveConfig)();
|
|
33
|
-
const { CSS_VARS } = CONFIG;
|
|
33
|
+
const { cssVars: CSS_VARS } = CONFIG;
|
|
34
34
|
if ((0, import_utils.isObjectLike)(result.value)) {
|
|
35
35
|
} else {
|
|
36
36
|
CSS_VARS[result.var] = result.value;
|
|
@@ -41,7 +41,8 @@ const applySequenceGlobalVars = (vars, obj, options) => {
|
|
|
41
41
|
const { unit: UNIT } = CONFIG;
|
|
42
42
|
const unit = obj.unit || UNIT.default;
|
|
43
43
|
const { base, ratio, type } = obj;
|
|
44
|
-
const
|
|
44
|
+
const vp = obj.varPrefix ? obj.varPrefix + "-" : "";
|
|
45
|
+
const prefix = "--" + vp + (type && type.replace(".", "-"));
|
|
45
46
|
vars[`${prefix}-base`] = base;
|
|
46
47
|
vars[`${prefix}-unit`] = unit;
|
|
47
48
|
const ratioVar = `${prefix}-ratio`;
|
|
@@ -51,10 +52,12 @@ const applySequenceGlobalVars = (vars, obj, options) => {
|
|
|
51
52
|
vars[`${prefix}-sub-ratio-2`] = `calc(var(${prefix}-ratio) * ${middle / ratio})`;
|
|
52
53
|
vars[`${prefix}-sub-ratio-3`] = `calc(var(${prefix}-ratio) * ${second / ratio})`;
|
|
53
54
|
};
|
|
55
|
+
const VIEWPORT_UNITS = /* @__PURE__ */ new Set(["vw", "vh", "vmin", "vmax", "svw", "svh", "lvw", "lvh", "dvw", "dvh"]);
|
|
54
56
|
const applySequenceVars = (FACTORY, options = {}) => {
|
|
55
57
|
const CONFIG = (0, import_factory.getActiveConfig)();
|
|
56
|
-
const { unit: UNIT, timing: TIMING, CSS_VARS } = CONFIG;
|
|
57
|
-
const
|
|
58
|
+
const { unit: UNIT, timing: TIMING, cssVars: CSS_VARS } = CONFIG;
|
|
59
|
+
const rawUnit = FACTORY.unit || UNIT.default;
|
|
60
|
+
const unit = VIEWPORT_UNITS.has(rawUnit) ? "rem" : rawUnit;
|
|
58
61
|
const { mediaRegenerate, sequence, scales } = FACTORY;
|
|
59
62
|
if (!mediaRegenerate) {
|
|
60
63
|
applySequenceGlobalVars(CSS_VARS, FACTORY, options);
|
|
@@ -77,17 +80,28 @@ const applySequenceVars = (FACTORY, options = {}) => {
|
|
|
77
80
|
};
|
|
78
81
|
const applyMediaSequenceVars = (FACTORY, media, options = {}) => {
|
|
79
82
|
const CONFIG = (0, import_factory.getActiveConfig)();
|
|
80
|
-
const { unit: UNIT, media: MEDIA, CSS_VARS } = CONFIG;
|
|
83
|
+
const { unit: UNIT, media: MEDIA, cssVars: CSS_VARS } = CONFIG;
|
|
81
84
|
const mediaName = media.slice(1);
|
|
82
|
-
const
|
|
85
|
+
const mediaConfig = FACTORY[media];
|
|
86
|
+
const rawMediaUnit = mediaConfig.unit || FACTORY.unit || UNIT.default;
|
|
87
|
+
const unit = VIEWPORT_UNITS.has(rawMediaUnit) ? "rem" : rawMediaUnit;
|
|
83
88
|
const { mediaRegenerate } = FACTORY;
|
|
84
|
-
const { sequence, scales } =
|
|
89
|
+
const { sequence, scales } = mediaConfig;
|
|
85
90
|
const query = MEDIA[mediaName];
|
|
86
91
|
if (!query && CONFIG.verbose) console.warn("Can't find media query ", query);
|
|
87
92
|
if (!mediaRegenerate) {
|
|
88
93
|
let underMediaQuery = CSS_VARS[`@media ${query}`];
|
|
89
94
|
if (!underMediaQuery) underMediaQuery = CSS_VARS[`@media ${query}`] = {};
|
|
90
|
-
applySequenceGlobalVars(underMediaQuery,
|
|
95
|
+
applySequenceGlobalVars(underMediaQuery, mediaConfig, options);
|
|
96
|
+
const parentUnit = FACTORY.unit || UNIT.default;
|
|
97
|
+
if (unit !== parentUnit && sequence) {
|
|
98
|
+
for (const key in sequence) {
|
|
99
|
+
const item = sequence[key];
|
|
100
|
+
const value = scales[key] + unit;
|
|
101
|
+
underMediaQuery[item.variable + "_default"] = value;
|
|
102
|
+
underMediaQuery[item.variable] = value;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
91
105
|
return;
|
|
92
106
|
}
|
|
93
107
|
for (const key in sequence) {
|
|
@@ -4,15 +4,15 @@ var defaultFont = {
|
|
|
4
4
|
family: "",
|
|
5
5
|
type: ""
|
|
6
6
|
};
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const fontFamily = {};
|
|
8
|
+
const fontFamilyTypes = {
|
|
9
9
|
"sans-serif": "Helvetica, Arial, sans-serif, --system-default",
|
|
10
10
|
serif: "Times New Roman, Georgia, serif, --system-default",
|
|
11
11
|
monospace: "Courier New, monospace, --system-default"
|
|
12
12
|
};
|
|
13
|
-
const
|
|
13
|
+
const fontFace = {};
|
|
14
14
|
export {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
fontFace,
|
|
16
|
+
fontFamily,
|
|
17
|
+
fontFamilyTypes
|
|
18
18
|
};
|
package/dist/esm/factory.js
CHANGED
|
@@ -3,30 +3,30 @@ import {
|
|
|
3
3
|
deepMerge,
|
|
4
4
|
isDefined,
|
|
5
5
|
isObject
|
|
6
|
-
} from "@
|
|
7
|
-
import * as CONF from "./defaultConfig";
|
|
8
|
-
const
|
|
9
|
-
const
|
|
6
|
+
} from "@symbo.ls/utils";
|
|
7
|
+
import * as CONF from "./defaultConfig/index.js";
|
|
8
|
+
const cssVars = {};
|
|
9
|
+
const cssMediaVars = {};
|
|
10
10
|
const _CONF = CONF;
|
|
11
11
|
const _confLower = {};
|
|
12
12
|
const toCamel = (s) => s.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
13
|
-
const toUpper = (s) => s.replace(/([A-Z])/g, "_$1").toUpperCase();
|
|
14
13
|
for (const key in _CONF) {
|
|
15
14
|
const lower = key.toLowerCase();
|
|
16
15
|
_confLower[lower] = _CONF[key];
|
|
17
16
|
const camel = toCamel(lower);
|
|
18
17
|
if (camel !== lower) _confLower[camel] = _CONF[key];
|
|
19
18
|
if (lower !== key) _confLower[key] = _CONF[key];
|
|
20
|
-
const upper = toUpper(key);
|
|
21
|
-
if (upper !== key) _confLower[upper] = _CONF[key];
|
|
22
19
|
}
|
|
23
20
|
const CONFIG = {
|
|
24
21
|
verbose: false,
|
|
25
22
|
useVariable: true,
|
|
26
23
|
useReset: true,
|
|
27
24
|
globalTheme: "auto",
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
cssVars,
|
|
26
|
+
cssMediaVars,
|
|
27
|
+
CSS_VARS: cssVars,
|
|
28
|
+
CSS_MEDIA_VARS: cssMediaVars,
|
|
29
|
+
_scratchConfig: true,
|
|
30
30
|
..._confLower
|
|
31
31
|
};
|
|
32
32
|
const cachedConfig = deepClone(CONFIG);
|
|
@@ -40,7 +40,15 @@ const activateConfig = (def) => {
|
|
|
40
40
|
}
|
|
41
41
|
return FACTORY[def || FACTORY.active];
|
|
42
42
|
};
|
|
43
|
+
const configStack = [];
|
|
44
|
+
const pushConfig = (config) => {
|
|
45
|
+
if (config && config._scratchConfig) configStack.push(config);
|
|
46
|
+
};
|
|
47
|
+
const popConfig = () => {
|
|
48
|
+
configStack.pop();
|
|
49
|
+
};
|
|
43
50
|
const getActiveConfig = (def) => {
|
|
51
|
+
if (configStack.length) return configStack[configStack.length - 1];
|
|
44
52
|
return FACTORY[def || FACTORY.active] || CONFIG;
|
|
45
53
|
};
|
|
46
54
|
const setActiveConfig = (newConfig) => {
|
|
@@ -49,12 +57,64 @@ const setActiveConfig = (newConfig) => {
|
|
|
49
57
|
FACTORY["1"] = deepMerge(newConfig, deepClone(cachedConfig));
|
|
50
58
|
return newConfig;
|
|
51
59
|
};
|
|
60
|
+
const APP_FLAGS = [
|
|
61
|
+
"useReset",
|
|
62
|
+
"useVariable",
|
|
63
|
+
"useFontImport",
|
|
64
|
+
"useIconSprite",
|
|
65
|
+
"useSvgSprite",
|
|
66
|
+
"useDocumentTheme",
|
|
67
|
+
"useDefaultIcons",
|
|
68
|
+
"useDefaultConfig",
|
|
69
|
+
"verbose",
|
|
70
|
+
"globalTheme"
|
|
71
|
+
];
|
|
72
|
+
const ALIAS_GROUPS = [
|
|
73
|
+
["fontfamily", "fontFamily", "font_family"],
|
|
74
|
+
["fontfamilytypes", "fontFamilyTypes"],
|
|
75
|
+
["semanticicons", "semanticIcons"],
|
|
76
|
+
["svgdata", "svgData"]
|
|
77
|
+
];
|
|
78
|
+
const aliasCaseVariants = (cfg) => {
|
|
79
|
+
for (const vs of ALIAS_GROUPS) {
|
|
80
|
+
let merged;
|
|
81
|
+
for (const v of vs) {
|
|
82
|
+
const val = cfg[v];
|
|
83
|
+
if (!isObject(val)) continue;
|
|
84
|
+
merged = merged ? deepMerge(val, merged) : val;
|
|
85
|
+
}
|
|
86
|
+
if (!merged) continue;
|
|
87
|
+
for (const v of vs) if (isObject(cfg[v])) cfg[v] = merged;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const createConfig = (name, overrides, { cleanBase = false } = {}) => {
|
|
91
|
+
const activeBase = cleanBase ? null : getActiveConfig();
|
|
92
|
+
const base = deepClone(
|
|
93
|
+
!cleanBase && activeBase && activeBase._scratchConfig ? activeBase : cachedConfig
|
|
94
|
+
);
|
|
95
|
+
for (const flag of APP_FLAGS) {
|
|
96
|
+
delete base[flag];
|
|
97
|
+
}
|
|
98
|
+
const cfg = deepMerge(overrides || {}, base);
|
|
99
|
+
cfg.cssVars = {};
|
|
100
|
+
cfg.cssMediaVars = {};
|
|
101
|
+
cfg.CSS_VARS = cfg.cssVars;
|
|
102
|
+
cfg.CSS_MEDIA_VARS = cfg.cssMediaVars;
|
|
103
|
+
cfg._scratchConfig = true;
|
|
104
|
+
aliasCaseVariants(cfg);
|
|
105
|
+
if (name) FACTORY[name] = cfg;
|
|
106
|
+
return cfg;
|
|
107
|
+
};
|
|
52
108
|
export {
|
|
53
109
|
CONFIG,
|
|
54
|
-
CSS_MEDIA_VARS,
|
|
55
|
-
CSS_VARS,
|
|
56
110
|
FACTORY,
|
|
57
111
|
activateConfig,
|
|
112
|
+
createConfig,
|
|
113
|
+
cssMediaVars,
|
|
114
|
+
cssVars,
|
|
58
115
|
getActiveConfig,
|
|
59
|
-
|
|
116
|
+
popConfig,
|
|
117
|
+
pushConfig,
|
|
118
|
+
setActiveConfig,
|
|
119
|
+
toCamel
|
|
60
120
|
};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import * as scratchUtils from "./utils/index.js";
|
|
2
2
|
import * as scratchSystem from "./system/index.js";
|
|
3
|
+
import * as scratchDefaultConfig from "./defaultConfig/index.js";
|
|
3
4
|
export * from "./factory.js";
|
|
4
|
-
export * from "./defaultConfig";
|
|
5
|
-
export * from "./system";
|
|
6
|
-
export * from "./utils";
|
|
7
|
-
export * from "./transforms";
|
|
5
|
+
export * from "./defaultConfig/index.js";
|
|
6
|
+
export * from "./system/index.js";
|
|
7
|
+
export * from "./utils/index.js";
|
|
8
|
+
export * from "./transforms/index.js";
|
|
8
9
|
export * from "./set.js";
|
|
9
10
|
export {
|
|
11
|
+
scratchDefaultConfig,
|
|
10
12
|
scratchSystem,
|
|
11
13
|
scratchUtils
|
|
12
14
|
};
|