@symbo.ls/scratch 3.4.5 → 3.4.9
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/dist/cjs/defaultConfig/animation.js +24 -0
- package/dist/cjs/defaultConfig/cases.js +24 -0
- package/dist/cjs/defaultConfig/class.js +25 -0
- package/dist/cjs/defaultConfig/color.js +31 -0
- package/dist/cjs/defaultConfig/document.js +24 -0
- package/dist/cjs/defaultConfig/font-family.js +38 -0
- package/dist/cjs/defaultConfig/font.js +33 -0
- package/dist/cjs/defaultConfig/grid.js +25 -0
- package/dist/cjs/defaultConfig/icons.js +26 -0
- package/dist/cjs/defaultConfig/index.js +45 -0
- package/dist/cjs/defaultConfig/media.js +29 -0
- package/dist/cjs/defaultConfig/responsive.js +50 -0
- package/dist/cjs/defaultConfig/sequence.js +49 -0
- package/dist/cjs/defaultConfig/shadow.js +29 -0
- package/dist/cjs/defaultConfig/spacing.js +38 -0
- package/dist/cjs/defaultConfig/svg.js +26 -0
- package/dist/cjs/defaultConfig/templates.js +24 -0
- package/dist/cjs/defaultConfig/theme.js +36 -0
- package/dist/cjs/defaultConfig/timing.js +37 -0
- package/dist/cjs/defaultConfig/typography.js +41 -0
- package/dist/cjs/defaultConfig/unit.js +26 -0
- package/dist/cjs/system/color.js +203 -0
- package/dist/cjs/system/document.js +36 -0
- package/dist/cjs/system/font.js +64 -0
- package/dist/cjs/system/index.js +27 -0
- package/dist/cjs/system/reset.js +87 -0
- package/dist/cjs/system/shadow.js +107 -0
- package/dist/cjs/system/spacing.js +134 -0
- package/dist/cjs/system/svg.js +97 -0
- package/dist/cjs/system/theme.js +234 -0
- package/dist/cjs/system/timing.js +48 -0
- package/dist/cjs/system/typography.js +99 -0
- package/dist/cjs/tests/index.js +28 -0
- package/dist/cjs/transforms/index.js +219 -0
- package/dist/cjs/utils/color.js +206 -0
- package/dist/cjs/utils/font.js +89 -0
- package/dist/cjs/utils/index.js +24 -0
- package/dist/cjs/utils/sequence.js +323 -0
- package/dist/cjs/utils/sprite.js +85 -0
- package/dist/cjs/utils/theme.js +29 -0
- package/dist/cjs/utils/unit.js +79 -0
- package/dist/cjs/utils/var.js +102 -0
- package/dist/esm/defaultConfig/animation.js +4 -0
- package/dist/esm/defaultConfig/cases.js +4 -0
- package/dist/esm/defaultConfig/class.js +5 -0
- package/dist/esm/defaultConfig/color.js +11 -0
- package/dist/esm/defaultConfig/document.js +4 -0
- package/dist/esm/defaultConfig/font-family.js +18 -0
- package/dist/esm/defaultConfig/font.js +13 -0
- package/dist/esm/defaultConfig/grid.js +5 -0
- package/dist/esm/defaultConfig/icons.js +6 -0
- package/dist/esm/defaultConfig/index.js +24 -0
- package/dist/esm/defaultConfig/media.js +9 -0
- package/dist/esm/defaultConfig/responsive.js +30 -0
- package/dist/esm/defaultConfig/sequence.js +29 -0
- package/dist/esm/defaultConfig/shadow.js +9 -0
- package/dist/esm/defaultConfig/spacing.js +18 -0
- package/dist/esm/defaultConfig/svg.js +6 -0
- package/dist/esm/defaultConfig/templates.js +4 -0
- package/dist/esm/defaultConfig/theme.js +16 -0
- package/dist/esm/defaultConfig/timing.js +17 -0
- package/dist/esm/defaultConfig/typography.js +21 -0
- package/dist/esm/defaultConfig/unit.js +6 -0
- package/dist/esm/system/color.js +188 -0
- package/dist/esm/system/document.js +16 -0
- package/dist/esm/system/font.js +50 -0
- package/dist/esm/system/index.js +10 -0
- package/dist/esm/system/reset.js +67 -0
- package/dist/esm/system/shadow.js +91 -0
- package/dist/esm/system/spacing.js +121 -0
- package/dist/esm/system/svg.js +77 -0
- package/dist/esm/system/theme.js +219 -0
- package/dist/esm/system/timing.js +32 -0
- package/dist/esm/system/typography.js +85 -0
- package/dist/esm/tests/index.js +8 -0
- package/dist/esm/transforms/index.js +216 -0
- package/dist/esm/utils/color.js +192 -0
- package/dist/esm/utils/font.js +69 -0
- package/dist/esm/utils/index.js +7 -0
- package/dist/esm/utils/sequence.js +303 -0
- package/dist/esm/utils/sprite.js +65 -0
- package/dist/esm/utils/theme.js +9 -0
- package/dist/esm/utils/unit.js +59 -0
- package/dist/esm/utils/var.js +82 -0
- package/package.json +7 -7
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { isString } from "@domql/utils";
|
|
2
|
+
import { toDashCase } from "@symbo.ls/smbls-utils";
|
|
3
|
+
import { getActiveConfig } from "../factory.js";
|
|
4
|
+
import { CSS_UNITS, isScalingUnit } from "./unit.js";
|
|
5
|
+
import { isCSSVar } from "./color.js";
|
|
6
|
+
const numToLetterMap = {
|
|
7
|
+
"-6": "U",
|
|
8
|
+
"-5": "V",
|
|
9
|
+
"-4": "W",
|
|
10
|
+
"-3": "X",
|
|
11
|
+
"-2": "Y",
|
|
12
|
+
"-1": "Z",
|
|
13
|
+
0: "A",
|
|
14
|
+
1: "B",
|
|
15
|
+
2: "C",
|
|
16
|
+
3: "D",
|
|
17
|
+
4: "E",
|
|
18
|
+
5: "F",
|
|
19
|
+
6: "G",
|
|
20
|
+
7: "H",
|
|
21
|
+
8: "I",
|
|
22
|
+
9: "J",
|
|
23
|
+
10: "K",
|
|
24
|
+
11: "L",
|
|
25
|
+
12: "M",
|
|
26
|
+
13: "N",
|
|
27
|
+
14: "O",
|
|
28
|
+
15: "P",
|
|
29
|
+
16: "Q",
|
|
30
|
+
17: "R",
|
|
31
|
+
18: "S",
|
|
32
|
+
19: "T"
|
|
33
|
+
};
|
|
34
|
+
const setSequenceValue = (props, sequenceProps) => {
|
|
35
|
+
const { key, variable, value, scaling, index, scalingVariable } = props;
|
|
36
|
+
sequenceProps.sequence[key] = {
|
|
37
|
+
key,
|
|
38
|
+
decimal: ~~(value * 100) / 100,
|
|
39
|
+
val: ~~value,
|
|
40
|
+
scaling,
|
|
41
|
+
index,
|
|
42
|
+
scalingVariable,
|
|
43
|
+
variable
|
|
44
|
+
};
|
|
45
|
+
sequenceProps.scales[key] = scaling;
|
|
46
|
+
sequenceProps.vars[variable] = scaling + sequenceProps.unit;
|
|
47
|
+
};
|
|
48
|
+
const getFnPrefixAndValue = (val) => {
|
|
49
|
+
if (!val.includes("(")) return val;
|
|
50
|
+
const prefix = val.split("(")[0];
|
|
51
|
+
const value = val.slice(val.indexOf("(") + 1, val.lastIndexOf(")"));
|
|
52
|
+
return [prefix, value];
|
|
53
|
+
};
|
|
54
|
+
const setScalingVar = (key, sequenceProps) => {
|
|
55
|
+
const { base, type, unit } = sequenceProps;
|
|
56
|
+
const defaultVal = (isScalingUnit(unit) ? 1 : base) + unit;
|
|
57
|
+
if (key === 0) return defaultVal;
|
|
58
|
+
const prefix = "--" + (type && type.replace(".", "-"));
|
|
59
|
+
const ratioVar = `${prefix}-ratio`;
|
|
60
|
+
if (key > 0) {
|
|
61
|
+
const prevLetterKey = numToLetterMap[key - 1];
|
|
62
|
+
return `calc(var(${prefix}-${prevLetterKey}) * var(${ratioVar}))`;
|
|
63
|
+
}
|
|
64
|
+
if (key < 0) {
|
|
65
|
+
const nextLetterKey = numToLetterMap[key + 1];
|
|
66
|
+
return `calc(var(${prefix}-${nextLetterKey}) / var(${ratioVar}))`;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const setSubScalingVar = (index, arr, variable, sequenceProps) => {
|
|
70
|
+
const { type } = sequenceProps;
|
|
71
|
+
const skipMiddle = index === 2 && arr.length === 2;
|
|
72
|
+
const indexMapWithLength = skipMiddle ? index + 1 : index;
|
|
73
|
+
const prefix = "--" + (type && type.replace(".", "-"));
|
|
74
|
+
const subRatioVarPrefix = `${prefix}-sub-ratio-`;
|
|
75
|
+
return `calc(var(${variable}) * var(${subRatioVarPrefix + indexMapWithLength}))`;
|
|
76
|
+
};
|
|
77
|
+
const getSubratioDifference = (base, ratio) => {
|
|
78
|
+
const diff = base * ratio - base;
|
|
79
|
+
const subRatio = diff / 1.618;
|
|
80
|
+
const first = base * ratio - subRatio;
|
|
81
|
+
const second = base + subRatio;
|
|
82
|
+
const middle = (first + second) / 2;
|
|
83
|
+
return [first, middle, second];
|
|
84
|
+
};
|
|
85
|
+
const getSubratio = (base, ratio) => {
|
|
86
|
+
return getSubratioDifference(base, ratio).map((v) => v / base);
|
|
87
|
+
};
|
|
88
|
+
const generateSubSequence = (props, sequenceProps) => {
|
|
89
|
+
const { key, base, value, ratio, variable, index } = props;
|
|
90
|
+
const next = value * ratio;
|
|
91
|
+
const diffRounded = ~~next - ~~value;
|
|
92
|
+
let arr;
|
|
93
|
+
const [first, middle, second] = getSubratioDifference(value, ratio);
|
|
94
|
+
if (diffRounded > 16) arr = [first, middle, second];
|
|
95
|
+
else arr = [first, second];
|
|
96
|
+
arr.forEach((v, k) => {
|
|
97
|
+
const scaling = ~~(v / base * 1e3) / 1e3;
|
|
98
|
+
const newVar = variable + (k + 1);
|
|
99
|
+
const newIndex = index + (k + 1) / 10;
|
|
100
|
+
const scalingVariable = setSubScalingVar(
|
|
101
|
+
k + 1,
|
|
102
|
+
arr,
|
|
103
|
+
variable,
|
|
104
|
+
sequenceProps
|
|
105
|
+
);
|
|
106
|
+
const props2 = {
|
|
107
|
+
key: key + (k + 1),
|
|
108
|
+
variable: newVar,
|
|
109
|
+
value: v,
|
|
110
|
+
scaling,
|
|
111
|
+
scalingVariable,
|
|
112
|
+
index: newIndex
|
|
113
|
+
};
|
|
114
|
+
setSequenceValue(props2, sequenceProps);
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
const switchSequenceOnNegative = (key, base, ratio) => {
|
|
118
|
+
return base * Math.pow(ratio, key);
|
|
119
|
+
};
|
|
120
|
+
const generateSequence = (sequenceProps) => {
|
|
121
|
+
const { type, base, ratio, range, subSequence } = sequenceProps;
|
|
122
|
+
const n = Math.abs(range[0]) + Math.abs(range[1]);
|
|
123
|
+
const prefix = "--" + (type && type.replace(".", "-")) + "-";
|
|
124
|
+
for (let i = 0; i <= n; i++) {
|
|
125
|
+
const key = range[1] - i;
|
|
126
|
+
const letterKey = numToLetterMap[key];
|
|
127
|
+
const value = switchSequenceOnNegative(key, base, ratio);
|
|
128
|
+
const scaling = ~~(value / base * 100) / 100;
|
|
129
|
+
const variable = prefix + letterKey;
|
|
130
|
+
const scalingVariable = setScalingVar(key, sequenceProps);
|
|
131
|
+
const props = {
|
|
132
|
+
key: letterKey,
|
|
133
|
+
variable,
|
|
134
|
+
value,
|
|
135
|
+
base,
|
|
136
|
+
scaling,
|
|
137
|
+
scalingVariable,
|
|
138
|
+
ratio,
|
|
139
|
+
index: key
|
|
140
|
+
};
|
|
141
|
+
setSequenceValue(props, sequenceProps);
|
|
142
|
+
if (subSequence) generateSubSequence(props, sequenceProps);
|
|
143
|
+
}
|
|
144
|
+
return sequenceProps;
|
|
145
|
+
};
|
|
146
|
+
const generateSequencePosition = (sequenceProps, position = 0) => {
|
|
147
|
+
const { type, base, ratio, subSequence } = sequenceProps;
|
|
148
|
+
const letterKey = isString(position) ? position : numToLetterMap[position];
|
|
149
|
+
const index = isString(position) ? Object.entries(numToLetterMap).find(
|
|
150
|
+
([, value2]) => value2 === position
|
|
151
|
+
)?.[0] : position;
|
|
152
|
+
if (!letterKey) {
|
|
153
|
+
console.warn(`Position ${position} is out of range in numToLetterMap`);
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
const result = {
|
|
157
|
+
sequence: {},
|
|
158
|
+
scales: {},
|
|
159
|
+
vars: {},
|
|
160
|
+
...sequenceProps
|
|
161
|
+
};
|
|
162
|
+
const value = base * Math.pow(ratio, index);
|
|
163
|
+
const scaling = ~~(value / base * 100) / 100;
|
|
164
|
+
const prefix = "--" + (type && type.replace(".", "-")) + "-";
|
|
165
|
+
const variable = prefix + letterKey;
|
|
166
|
+
const scalingVariable = setScalingVar(index, sequenceProps);
|
|
167
|
+
const props = {
|
|
168
|
+
key: letterKey,
|
|
169
|
+
variable,
|
|
170
|
+
value,
|
|
171
|
+
base,
|
|
172
|
+
scaling,
|
|
173
|
+
scalingVariable,
|
|
174
|
+
ratio,
|
|
175
|
+
index
|
|
176
|
+
};
|
|
177
|
+
setSequenceValue(props, result);
|
|
178
|
+
if (subSequence) {
|
|
179
|
+
generateSubSequence(props, result);
|
|
180
|
+
}
|
|
181
|
+
return result;
|
|
182
|
+
};
|
|
183
|
+
const getSequenceValue = (value = "A", sequenceProps) => {
|
|
184
|
+
const CONFIG = getActiveConfig();
|
|
185
|
+
const { UNIT } = CONFIG;
|
|
186
|
+
if (isString(value) && isCSSVar(value)) return `var(${value})`;
|
|
187
|
+
const { sequence, unit = UNIT.default, useVariable } = sequenceProps;
|
|
188
|
+
const startsWithDashOrLetterRegex = /^-?[a-zA-Z]/i;
|
|
189
|
+
const startsWithDashOrLetter = startsWithDashOrLetterRegex.test(value);
|
|
190
|
+
const hasUnits = CSS_UNITS.some((unit2) => value.includes(unit2));
|
|
191
|
+
if (hasUnits || !startsWithDashOrLetter) return value;
|
|
192
|
+
const skipArr = [
|
|
193
|
+
"none",
|
|
194
|
+
"auto",
|
|
195
|
+
"max-content",
|
|
196
|
+
"min-content",
|
|
197
|
+
"fit-content",
|
|
198
|
+
"inherit",
|
|
199
|
+
"initial",
|
|
200
|
+
"unset",
|
|
201
|
+
"revert",
|
|
202
|
+
"revert-layer"
|
|
203
|
+
];
|
|
204
|
+
if (skipArr.includes(value)) return value;
|
|
205
|
+
const prefix = `--${toDashCase(sequenceProps.type.replace(".", "-"))}-`;
|
|
206
|
+
const letterVal = value.toUpperCase();
|
|
207
|
+
const isNegative = letterVal.slice(0, 1) === "-" ? "-" : "";
|
|
208
|
+
let absValue = isNegative ? letterVal.slice(1) : letterVal;
|
|
209
|
+
let mediaName = "";
|
|
210
|
+
if (absValue.includes("_")) {
|
|
211
|
+
mediaName = "_" + absValue.split("_")[1].toLowerCase();
|
|
212
|
+
absValue = absValue.split("_")[0];
|
|
213
|
+
}
|
|
214
|
+
const varValue = (v) => startsWithDashOrLetterRegex.test(v) ? `var(${prefix}${v}${mediaName})` : v;
|
|
215
|
+
if (absValue.includes("+")) {
|
|
216
|
+
const [first, second] = absValue.split("+");
|
|
217
|
+
const joint = `${varValue(first)} + ${varValue(second)}`;
|
|
218
|
+
return isNegative ? `calc((${joint}) * -1)` : `calc(${joint})`;
|
|
219
|
+
} else if (absValue.includes("*")) {
|
|
220
|
+
const [first, second] = absValue.split("*");
|
|
221
|
+
const joint = `${varValue(first)} * ${varValue(second)}`;
|
|
222
|
+
return isNegative ? `calc((${joint}) * -1)` : `calc(${joint})`;
|
|
223
|
+
} else if (absValue.includes("-")) {
|
|
224
|
+
const [first, second] = absValue.split("-");
|
|
225
|
+
const joint = `${varValue(first)} - ${varValue(second)}`;
|
|
226
|
+
return isNegative ? `calc((${joint}) * -1)` : `calc(${joint})`;
|
|
227
|
+
}
|
|
228
|
+
if (!sequence[absValue] && absValue.length === 2) {
|
|
229
|
+
if (CONFIG.verbose)
|
|
230
|
+
console.warn(
|
|
231
|
+
absValue,
|
|
232
|
+
"- value is not found because `subSequence` is set to false"
|
|
233
|
+
);
|
|
234
|
+
absValue = absValue.slice(0, 1);
|
|
235
|
+
}
|
|
236
|
+
if (useVariable || CONFIG.useVariable) {
|
|
237
|
+
const varValue2 = `var(${prefix}${absValue}${mediaName})`;
|
|
238
|
+
return isNegative ? `calc(${varValue2} * -1)` : varValue2;
|
|
239
|
+
}
|
|
240
|
+
const sequenceItem = sequence ? sequence[absValue] : null;
|
|
241
|
+
if (!sequenceItem) return console.warn("can't find", sequence, absValue);
|
|
242
|
+
if (unit === "ms" || unit === "s") {
|
|
243
|
+
return isNegative + sequenceItem.val + unit;
|
|
244
|
+
}
|
|
245
|
+
return isNegative + sequenceItem.scaling + unit;
|
|
246
|
+
};
|
|
247
|
+
const getSequenceValueBySymbols = (value, sequenceProps) => {
|
|
248
|
+
const mathArr = ["+", "-", "*", "/", ","].filter(
|
|
249
|
+
(v) => value.includes(v + " ")
|
|
250
|
+
);
|
|
251
|
+
if (!mathArr.length) return value;
|
|
252
|
+
return mathArr.map((symbol) => {
|
|
253
|
+
const valuesArr = value.split(symbol + " ").map((v) => v.trim());
|
|
254
|
+
const transformedValues = valuesArr.map((v) => {
|
|
255
|
+
return getSequenceValue(v, sequenceProps);
|
|
256
|
+
});
|
|
257
|
+
return transformedValues.join(" " + symbol + " ");
|
|
258
|
+
}).join("");
|
|
259
|
+
};
|
|
260
|
+
const getSequenceValuePropertyPair = (value, propertyName, sequenceProps, fnPrefix) => {
|
|
261
|
+
if (typeof value !== "string") {
|
|
262
|
+
const CONFIG = getActiveConfig();
|
|
263
|
+
if (CONFIG.verbose) console.warn(propertyName, value, "is not a string");
|
|
264
|
+
return { [propertyName]: value };
|
|
265
|
+
}
|
|
266
|
+
if (value === "-" || value === "") return {};
|
|
267
|
+
if (!fnPrefix && value.includes("(")) {
|
|
268
|
+
const fnArr = getFnPrefixAndValue(value);
|
|
269
|
+
fnPrefix = fnArr[0];
|
|
270
|
+
value = fnArr[1];
|
|
271
|
+
}
|
|
272
|
+
const mathArr = ["+", "-", "*", "/", ","].filter(
|
|
273
|
+
(v) => value.includes(v + " ")
|
|
274
|
+
);
|
|
275
|
+
if (mathArr.length) {
|
|
276
|
+
value = getSequenceValueBySymbols(value, sequenceProps);
|
|
277
|
+
} else value = getSequenceValue(value, sequenceProps);
|
|
278
|
+
return { [propertyName]: fnPrefix ? `${fnPrefix}(${value})` : value };
|
|
279
|
+
};
|
|
280
|
+
const findHeadingLetter = (h1Matches, index) => numToLetterMap[h1Matches - index];
|
|
281
|
+
const findHeadings = (propertyNames) => {
|
|
282
|
+
const { h1Matches, sequence } = propertyNames;
|
|
283
|
+
return new Array(6).fill(null).map((_, i) => {
|
|
284
|
+
const findLetter = findHeadingLetter(h1Matches, i);
|
|
285
|
+
return sequence[findLetter];
|
|
286
|
+
});
|
|
287
|
+
};
|
|
288
|
+
export {
|
|
289
|
+
findHeadingLetter,
|
|
290
|
+
findHeadings,
|
|
291
|
+
generateSequence,
|
|
292
|
+
generateSequencePosition,
|
|
293
|
+
generateSubSequence,
|
|
294
|
+
getFnPrefixAndValue,
|
|
295
|
+
getSequenceValue,
|
|
296
|
+
getSequenceValueBySymbols,
|
|
297
|
+
getSequenceValuePropertyPair,
|
|
298
|
+
getSubratio,
|
|
299
|
+
getSubratioDifference,
|
|
300
|
+
numToLetterMap,
|
|
301
|
+
setScalingVar,
|
|
302
|
+
setSubScalingVar
|
|
303
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { isArray, isNotProduction, isString } from "@domql/utils";
|
|
2
|
+
import { getActiveConfig } from "../factory";
|
|
3
|
+
const isDev = isNotProduction();
|
|
4
|
+
const generateSprite = (icons) => {
|
|
5
|
+
const CONFIG = getActiveConfig();
|
|
6
|
+
let sprite = "";
|
|
7
|
+
for (const key in icons) {
|
|
8
|
+
if (CONFIG.__svg_cache[key]) continue;
|
|
9
|
+
else CONFIG.__svg_cache[key] = true;
|
|
10
|
+
sprite += icons[key];
|
|
11
|
+
}
|
|
12
|
+
return sprite;
|
|
13
|
+
};
|
|
14
|
+
const parseRootAttributes = (htmlString) => {
|
|
15
|
+
const val = htmlString.default || htmlString;
|
|
16
|
+
if (!isString(val)) {
|
|
17
|
+
if (isDev) console.warn("parseRootAttributes:", val, "is not a string");
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const match = val.match(/<svg\s+(.*?)>/);
|
|
21
|
+
if (!match || !match[1]) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
const attrString = match[1];
|
|
25
|
+
const attrs = attrString.match(
|
|
26
|
+
/(\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|\s*\/?[>"']))+.)["']?/gm
|
|
27
|
+
);
|
|
28
|
+
return attrs.reduce((acc, attr) => {
|
|
29
|
+
const [key, value] = attr.split("=");
|
|
30
|
+
acc[key] = value.replace(/['"]/g, "");
|
|
31
|
+
return acc;
|
|
32
|
+
}, {});
|
|
33
|
+
};
|
|
34
|
+
const replaceIdsAndUrls = (code, key) => {
|
|
35
|
+
const idRegex = /id="([^"]*)"/;
|
|
36
|
+
const urlRegex = /url\(#([^)]*)\)/g;
|
|
37
|
+
const matches = code.match(/id="([^"]*)"/g);
|
|
38
|
+
let replacedCode = code;
|
|
39
|
+
if (isArray(matches)) {
|
|
40
|
+
matches.forEach(() => {
|
|
41
|
+
const randomKey = Math.floor(Math.random() * 1e5);
|
|
42
|
+
replacedCode = code.replace(idRegex, `id="${key}-${randomKey}"`).replace(urlRegex, `url(#${key}-${randomKey})`);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return replacedCode;
|
|
46
|
+
};
|
|
47
|
+
const convertSvgToSymbol = (key, code) => {
|
|
48
|
+
const extractAttrs = parseRootAttributes(code);
|
|
49
|
+
const { width, height } = extractAttrs;
|
|
50
|
+
const viewBox = extractAttrs.viewBox || `0 0 ${width || 24} ${height || 24}`;
|
|
51
|
+
const xmlns = "http://www.w3.org/2000/svg";
|
|
52
|
+
const replacedCode = replaceIdsAndUrls(code, key);
|
|
53
|
+
let symbol = replacedCode.replace(
|
|
54
|
+
"<svg",
|
|
55
|
+
`<symbol id="${key}" xmlns="${xmlns}" viewBox="${viewBox}"`
|
|
56
|
+
);
|
|
57
|
+
symbol = symbol.replace(/width="[^"]*"/, "");
|
|
58
|
+
symbol = symbol.replace(/height="[^"]*"/, "");
|
|
59
|
+
symbol = symbol.replace("</svg", "</symbol");
|
|
60
|
+
return symbol;
|
|
61
|
+
};
|
|
62
|
+
export {
|
|
63
|
+
convertSvgToSymbol,
|
|
64
|
+
generateSprite
|
|
65
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const isScalingUnit = (unit) => {
|
|
2
|
+
return unit === "em" || unit === "rem" || unit === "vw" || unit === "vh" || unit === "vmax" || unit === "vmin";
|
|
3
|
+
};
|
|
4
|
+
const CSS_UNITS = [
|
|
5
|
+
// Absolute
|
|
6
|
+
"px",
|
|
7
|
+
"cm",
|
|
8
|
+
"mm",
|
|
9
|
+
"in",
|
|
10
|
+
"pt",
|
|
11
|
+
"pc",
|
|
12
|
+
// Font-relative
|
|
13
|
+
"em",
|
|
14
|
+
"rem",
|
|
15
|
+
"ex",
|
|
16
|
+
"cap",
|
|
17
|
+
"ch",
|
|
18
|
+
"ic",
|
|
19
|
+
"lh",
|
|
20
|
+
"rlh",
|
|
21
|
+
// Viewport-relative
|
|
22
|
+
"%",
|
|
23
|
+
"vw",
|
|
24
|
+
"vh",
|
|
25
|
+
"vmin",
|
|
26
|
+
"vmax",
|
|
27
|
+
"svw",
|
|
28
|
+
"svh",
|
|
29
|
+
"lvw",
|
|
30
|
+
"lvh",
|
|
31
|
+
"dvw",
|
|
32
|
+
"dvh",
|
|
33
|
+
// Container query units
|
|
34
|
+
"cqw",
|
|
35
|
+
"cqh",
|
|
36
|
+
"cqi",
|
|
37
|
+
"cqb",
|
|
38
|
+
"cqmin",
|
|
39
|
+
"cqmax",
|
|
40
|
+
// Angle
|
|
41
|
+
"deg",
|
|
42
|
+
"rad",
|
|
43
|
+
"grad",
|
|
44
|
+
"turn",
|
|
45
|
+
// Time
|
|
46
|
+
"s",
|
|
47
|
+
"ms",
|
|
48
|
+
// Resolution
|
|
49
|
+
"dpi",
|
|
50
|
+
"dpcm",
|
|
51
|
+
"dppx",
|
|
52
|
+
// Grid fractional
|
|
53
|
+
"fr",
|
|
54
|
+
"auto"
|
|
55
|
+
];
|
|
56
|
+
export {
|
|
57
|
+
CSS_UNITS,
|
|
58
|
+
isScalingUnit
|
|
59
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { isObjectLike } from "@domql/utils";
|
|
2
|
+
import { getActiveConfig } from "../factory.js";
|
|
3
|
+
import { getSubratio } from "./sequence.js";
|
|
4
|
+
import { isScalingUnit } from "./unit.js";
|
|
5
|
+
const setVariables = (result, key) => {
|
|
6
|
+
const CONFIG = getActiveConfig();
|
|
7
|
+
const { CSS_VARS } = CONFIG;
|
|
8
|
+
if (isObjectLike(result.value)) {
|
|
9
|
+
} else {
|
|
10
|
+
CSS_VARS[result.var] = result.value;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const applySequenceGlobalVars = (vars, obj, options) => {
|
|
14
|
+
const CONFIG = getActiveConfig();
|
|
15
|
+
const { UNIT } = CONFIG;
|
|
16
|
+
const unit = obj.unit || UNIT.default;
|
|
17
|
+
const { base, ratio, type } = obj;
|
|
18
|
+
const prefix = "--" + (type && type.replace(".", "-"));
|
|
19
|
+
vars[`${prefix}-base`] = base;
|
|
20
|
+
vars[`${prefix}-unit`] = unit;
|
|
21
|
+
const ratioVar = `${prefix}-ratio`;
|
|
22
|
+
vars[ratioVar] = ratio;
|
|
23
|
+
const [first, middle, second] = getSubratio(base, ratio);
|
|
24
|
+
vars[`${prefix}-sub-ratio-1`] = `calc(var(${prefix}-ratio) * ${first / ratio})`;
|
|
25
|
+
vars[`${prefix}-sub-ratio-2`] = `calc(var(${prefix}-ratio) * ${middle / ratio})`;
|
|
26
|
+
vars[`${prefix}-sub-ratio-3`] = `calc(var(${prefix}-ratio) * ${second / ratio})`;
|
|
27
|
+
};
|
|
28
|
+
const applySequenceVars = (FACTORY, options = {}) => {
|
|
29
|
+
const CONFIG = getActiveConfig();
|
|
30
|
+
const { UNIT, TIMING, CSS_VARS } = CONFIG;
|
|
31
|
+
const unit = FACTORY.unit || UNIT.default;
|
|
32
|
+
const { mediaRegenerate, sequence, scales } = FACTORY;
|
|
33
|
+
if (!mediaRegenerate) {
|
|
34
|
+
applySequenceGlobalVars(CSS_VARS, FACTORY, options);
|
|
35
|
+
}
|
|
36
|
+
for (const key in sequence) {
|
|
37
|
+
const item = sequence[key];
|
|
38
|
+
const value = (FACTORY.type === TIMING.type ? sequence[key].val : scales[key]) + unit;
|
|
39
|
+
if (!mediaRegenerate) {
|
|
40
|
+
CSS_VARS[item.variable + "_default"] = value;
|
|
41
|
+
CSS_VARS[item.variable] = item.scalingVariable;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (options.useDefault === false) {
|
|
45
|
+
CSS_VARS[item.variable] = value;
|
|
46
|
+
} else {
|
|
47
|
+
CSS_VARS[item.variable + "_default"] = value;
|
|
48
|
+
CSS_VARS[item.variable] = `var(${item.variable + "_default"})`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const applyMediaSequenceVars = (FACTORY, media, options = {}) => {
|
|
53
|
+
const CONFIG = getActiveConfig();
|
|
54
|
+
const { UNIT, MEDIA, CSS_VARS } = CONFIG;
|
|
55
|
+
const mediaName = media.slice(1);
|
|
56
|
+
const unit = FACTORY.unit || UNIT.default;
|
|
57
|
+
const { mediaRegenerate } = FACTORY;
|
|
58
|
+
const { sequence, scales } = FACTORY[media];
|
|
59
|
+
const query = MEDIA[mediaName];
|
|
60
|
+
if (!query && CONFIG.verbose) console.warn("Can't find media query ", query);
|
|
61
|
+
if (!mediaRegenerate) {
|
|
62
|
+
let underMediaQuery = CSS_VARS[`@media ${query}`];
|
|
63
|
+
if (!underMediaQuery) underMediaQuery = CSS_VARS[`@media ${query}`] = {};
|
|
64
|
+
applySequenceGlobalVars(underMediaQuery, FACTORY[media], options);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
for (const key in sequence) {
|
|
68
|
+
const item = sequence[key];
|
|
69
|
+
const value = (isScalingUnit(unit) ? scales[key] : sequence[key].val) + unit;
|
|
70
|
+
if (!query && CONFIG.verbose) console.warn("Can't find query ", query);
|
|
71
|
+
let underMediaQuery = CSS_VARS[`@media ${query}`];
|
|
72
|
+
if (!underMediaQuery) underMediaQuery = CSS_VARS[`@media ${query}`] = {};
|
|
73
|
+
underMediaQuery[item.variable] = `var(${item.variable + "_" + mediaName})`;
|
|
74
|
+
CSS_VARS[item.variable + "_" + mediaName] = value;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
export {
|
|
78
|
+
applyMediaSequenceVars,
|
|
79
|
+
applySequenceGlobalVars,
|
|
80
|
+
applySequenceVars,
|
|
81
|
+
setVariables
|
|
82
|
+
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@symbo.ls/scratch",
|
|
3
3
|
"description": "Φ / CSS framework and methodology.",
|
|
4
4
|
"author": "symbo.ls",
|
|
5
|
-
"version": "3.4.
|
|
5
|
+
"version": "3.4.9",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
8
8
|
"*.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
".": {
|
|
19
19
|
"import": "./dist/esm/index.js",
|
|
20
20
|
"require": "./dist/cjs/index.js",
|
|
21
|
-
"browser": "./dist/
|
|
21
|
+
"browser": "./dist/esm/index.js",
|
|
22
22
|
"default": "./dist/esm/index.js"
|
|
23
23
|
}
|
|
24
24
|
},
|
|
@@ -26,18 +26,18 @@
|
|
|
26
26
|
"publishConfig": {},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
|
|
29
|
-
"build:esm": "cross-env NODE_ENV=$NODE_ENV esbuild src
|
|
30
|
-
"build:cjs": "cross-env NODE_ENV=$NODE_ENV esbuild src
|
|
29
|
+
"build:esm": "cross-env NODE_ENV=$NODE_ENV esbuild $(find src -name '*.js') --target=es2020 --format=esm --outdir=dist/esm --define:process.env.NODE_ENV=process.env.NODE_ENV",
|
|
30
|
+
"build:cjs": "cross-env NODE_ENV=$NODE_ENV esbuild $(find src -name '*.js') --target=node18 --format=cjs --outdir=dist/cjs --define:process.env.NODE_ENV=process.env.NODE_ENV",
|
|
31
31
|
"build:iife": "cross-env NODE_ENV=$NODE_ENV esbuild src/index.js --bundle --target=es2020 --format=iife --global-name=SmblsScratch --outfile=dist/iife/index.js --define:process.env.NODE_ENV=process.env.NODE_ENV",
|
|
32
32
|
"build": "node ../../build/build.js",
|
|
33
33
|
"prepublish": "npm run build && npm run copy:package:cjs"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@domql/utils": "^3.4.
|
|
37
|
-
"@symbo.ls/smbls-utils": "^3.4.
|
|
36
|
+
"@domql/utils": "^3.4.9",
|
|
37
|
+
"@symbo.ls/smbls-utils": "^3.4.9",
|
|
38
38
|
"color-contrast-checker": "^1.5.0"
|
|
39
39
|
},
|
|
40
40
|
"gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
|
|
41
|
-
"browser": "./dist/
|
|
41
|
+
"browser": "./dist/esm/index.js",
|
|
42
42
|
"sideEffects": false
|
|
43
43
|
}
|