@symbo.ls/scratch 2.27.0 → 2.27.11
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/factory.js +5 -8
- package/dist/cjs/index.js +177 -345
- package/dist/cjs/set.js +126 -240
- package/dist/cjs/system/color.js +54 -87
- package/dist/cjs/system/document.js +26 -29
- package/dist/cjs/system/font.js +30 -37
- package/dist/cjs/system/index.js +126 -243
- package/dist/cjs/system/reset.js +33 -43
- package/dist/cjs/system/shadow.js +69 -117
- package/dist/cjs/system/spacing.js +41 -59
- package/dist/cjs/system/svg.js +31 -41
- package/dist/cjs/system/theme.js +67 -113
- package/dist/cjs/system/timing.js +34 -45
- package/dist/cjs/system/typography.js +43 -73
- package/dist/cjs/transforms/index.js +92 -163
- package/dist/cjs/utils/color.js +21 -35
- package/dist/cjs/utils/font.js +3 -6
- package/dist/cjs/utils/index.js +62 -108
- package/dist/cjs/utils/sequence.js +25 -45
- package/dist/cjs/utils/sprite.js +15 -12
- package/dist/cjs/utils/theme.js +3 -6
- package/dist/cjs/utils/var.js +19 -33
- package/package.json +7 -7
- package/src/system/typography.js +12 -20
- package/src/utils/color.js +42 -30
- package/src/utils/sprite.js +12 -7
package/dist/cjs/utils/theme.js
CHANGED
|
@@ -24,11 +24,8 @@ __export(theme_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(theme_exports);
|
|
26
26
|
var returnSubThemeOrDefault = (orig, theme) => {
|
|
27
|
-
if (!orig)
|
|
28
|
-
|
|
29
|
-
if (orig
|
|
30
|
-
return orig.themes[theme];
|
|
31
|
-
if (orig[theme])
|
|
32
|
-
return [orig, orig[theme]];
|
|
27
|
+
if (!orig) return;
|
|
28
|
+
if (orig.themes && orig.themes[theme]) return orig.themes[theme];
|
|
29
|
+
if (orig[theme]) return [orig, orig[theme]];
|
|
33
30
|
return orig;
|
|
34
31
|
};
|
package/dist/cjs/utils/var.js
CHANGED
|
@@ -51,8 +51,8 @@ var require_cjs = __commonJS({
|
|
|
51
51
|
return to;
|
|
52
52
|
};
|
|
53
53
|
var __toCommonJS2 = (mod) => __copyProps2(__defProp3({}, "__esModule", { value: true }), mod);
|
|
54
|
-
var
|
|
55
|
-
__export2(
|
|
54
|
+
var index_exports = {};
|
|
55
|
+
__export2(index_exports, {
|
|
56
56
|
arrayzeValue: () => arrayzeValue,
|
|
57
57
|
copyJavaScriptToClipboard: () => copyJavaScriptToClipboard,
|
|
58
58
|
copyStringToClipboard: () => copyStringToClipboard,
|
|
@@ -73,12 +73,11 @@ var require_cjs = __commonJS({
|
|
|
73
73
|
toTitleCase: () => toTitleCase,
|
|
74
74
|
toggleFullscreen: () => toggleFullscreen
|
|
75
75
|
});
|
|
76
|
-
module2.exports = __toCommonJS2(
|
|
76
|
+
module2.exports = __toCommonJS2(index_exports);
|
|
77
77
|
var window22 = globalThis;
|
|
78
78
|
var document22 = window22.document;
|
|
79
79
|
var isObject2 = (arg) => {
|
|
80
|
-
if (arg === null)
|
|
81
|
-
return false;
|
|
80
|
+
if (arg === null) return false;
|
|
82
81
|
return typeof arg === "object" && arg.constructor === Object;
|
|
83
82
|
};
|
|
84
83
|
var isString2 = (arg) => typeof arg === "string";
|
|
@@ -103,13 +102,11 @@ var require_cjs = __commonJS({
|
|
|
103
102
|
};
|
|
104
103
|
var findClosestNumberInFactory = (val, factory) => {
|
|
105
104
|
val = parseFloat(val);
|
|
106
|
-
if (isObject2(factory))
|
|
107
|
-
factory = Object.values(factory);
|
|
105
|
+
if (isObject2(factory)) factory = Object.values(factory);
|
|
108
106
|
return findClosestNumber(val, factory);
|
|
109
107
|
};
|
|
110
108
|
var formatDate = (timestamp) => {
|
|
111
|
-
if (!timestamp)
|
|
112
|
-
return "";
|
|
109
|
+
if (!timestamp) return "";
|
|
113
110
|
const d = new Date(timestamp);
|
|
114
111
|
const ye = new Intl.DateTimeFormat("en", { year: "numeric" }).format(d);
|
|
115
112
|
const mo = new Intl.DateTimeFormat("en", { month: "short" }).format(d);
|
|
@@ -176,8 +173,7 @@ var require_cjs = __commonJS({
|
|
|
176
173
|
scriptEle.type = type;
|
|
177
174
|
scriptEle.text = xhr.responseText;
|
|
178
175
|
doc.body.appendChild(scriptEle);
|
|
179
|
-
if (typeof fallback === "function")
|
|
180
|
-
fallback();
|
|
176
|
+
if (typeof fallback === "function") fallback();
|
|
181
177
|
} else {
|
|
182
178
|
throw new Error(`Failed to load the script ${FILE_URL}`);
|
|
183
179
|
}
|
|
@@ -245,20 +241,15 @@ var require_cjs = __commonJS({
|
|
|
245
241
|
);
|
|
246
242
|
var toDashCase2 = (val) => val.replace(/[^a-zA-Z0-9]/g, " ").trim().toLowerCase().replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
247
243
|
var toDescriptionCase = (str = "") => {
|
|
248
|
-
if (typeof str !== "string")
|
|
249
|
-
return;
|
|
244
|
+
if (typeof str !== "string") return;
|
|
250
245
|
const result = str.replace(/([A-Z])/g, " $1");
|
|
251
246
|
return result.charAt(0).toUpperCase() + result.slice(1);
|
|
252
247
|
};
|
|
253
248
|
var arrayzeValue = (val) => {
|
|
254
|
-
if (isArray2(val))
|
|
255
|
-
|
|
256
|
-
if (
|
|
257
|
-
|
|
258
|
-
if (isObject2(val))
|
|
259
|
-
return Object.values(val);
|
|
260
|
-
if (isNumber2(val))
|
|
261
|
-
return [val];
|
|
249
|
+
if (isArray2(val)) return val;
|
|
250
|
+
if (isString2(val)) return val.split(" ");
|
|
251
|
+
if (isObject2(val)) return Object.values(val);
|
|
252
|
+
if (isNumber2(val)) return [val];
|
|
262
253
|
};
|
|
263
254
|
}
|
|
264
255
|
});
|
|
@@ -287,8 +278,7 @@ var isFunction = (arg) => typeof arg === "function";
|
|
|
287
278
|
var isNull = (arg) => arg === null;
|
|
288
279
|
var isArray = (arg) => Array.isArray(arg);
|
|
289
280
|
var isObjectLike = (arg) => {
|
|
290
|
-
if (arg === null)
|
|
291
|
-
return false;
|
|
281
|
+
if (arg === null) return false;
|
|
292
282
|
return typeof arg === "object";
|
|
293
283
|
};
|
|
294
284
|
var isUndefined = (arg) => {
|
|
@@ -356,8 +346,7 @@ var deepClone = (obj, options = {}) => {
|
|
|
356
346
|
const clone2 = targetWindow ? isArray(obj) ? new targetWindow.Array() : new targetWindow.Object() : isArray(obj) ? [] : {};
|
|
357
347
|
visited.set(obj, clone2);
|
|
358
348
|
for (const key in obj) {
|
|
359
|
-
if (!Object.prototype.hasOwnProperty.call(obj, key))
|
|
360
|
-
continue;
|
|
349
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
361
350
|
if (exclude.includes(key) || key.startsWith("__") || key === "__proto__")
|
|
362
351
|
continue;
|
|
363
352
|
const value = obj[key];
|
|
@@ -687,24 +676,21 @@ var applyMediaSequenceVars = (FACTORY2, media, options = {}) => {
|
|
|
687
676
|
const { mediaRegenerate } = FACTORY2;
|
|
688
677
|
const { sequence, scales } = FACTORY2[media];
|
|
689
678
|
const query = MEDIA2[mediaName];
|
|
690
|
-
if (!query && CONFIG2.verbose)
|
|
691
|
-
console.warn("Can't find media query ", query);
|
|
679
|
+
if (!query && CONFIG2.verbose) console.warn("Can't find media query ", query);
|
|
692
680
|
if (!mediaRegenerate) {
|
|
693
681
|
let underMediaQuery = CSS_VARS2[`@media ${query}`];
|
|
694
|
-
if (!underMediaQuery)
|
|
695
|
-
underMediaQuery = CSS_VARS2[`@media ${query}`] = {};
|
|
682
|
+
if (!underMediaQuery) underMediaQuery = CSS_VARS2[`@media ${query}`] = {};
|
|
696
683
|
applySequenceGlobalVars(underMediaQuery, FACTORY2[media], options);
|
|
697
684
|
return;
|
|
698
685
|
}
|
|
699
686
|
for (const key in sequence) {
|
|
700
687
|
const item = sequence[key];
|
|
701
688
|
const value = (isScalingUnit(unit) ? scales[key] : sequence[key].val) + unit;
|
|
702
|
-
if (!query && CONFIG2.verbose)
|
|
703
|
-
console.warn("Can't find query ", query);
|
|
689
|
+
if (!query && CONFIG2.verbose) console.warn("Can't find query ", query);
|
|
704
690
|
let underMediaQuery = CSS_VARS2[`@media ${query}`];
|
|
705
|
-
if (!underMediaQuery)
|
|
706
|
-
underMediaQuery = CSS_VARS2[`@media ${query}`] = {};
|
|
691
|
+
if (!underMediaQuery) underMediaQuery = CSS_VARS2[`@media ${query}`] = {};
|
|
707
692
|
underMediaQuery[item.variable] = `var(${item.variable + "_" + mediaName})`;
|
|
708
693
|
CSS_VARS2[item.variable + "_" + mediaName] = value;
|
|
709
694
|
}
|
|
710
695
|
};
|
|
696
|
+
// @preserve-env
|
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": "2.27.
|
|
5
|
+
"version": "2.27.11",
|
|
6
6
|
"files": [
|
|
7
7
|
"src",
|
|
8
8
|
"dist"
|
|
@@ -18,16 +18,16 @@
|
|
|
18
18
|
"publishConfig": {},
|
|
19
19
|
"scripts": {
|
|
20
20
|
"copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
|
|
21
|
-
"build:esm": "npx esbuild ./src/*.js ./src/**/*.js --target=es2017 --format=esm --outdir=dist/esm",
|
|
22
|
-
"build:cjs": "npx esbuild ./src/*.js ./src/**/*.js --target=node16 --format=cjs --outdir=dist/cjs --bundle",
|
|
23
|
-
"build:iife": "npx esbuild ./src/index.js --target=es2017 --format=iife --outdir=dist/iife --bundle --minify",
|
|
21
|
+
"build:esm": "cross-env NODE_ENV=$NODE_ENV npx esbuild ./src/*.js ./src/**/*.js --target=es2017 --format=esm --outdir=dist/esm",
|
|
22
|
+
"build:cjs": "cross-env NODE_ENV=$NODE_ENV npx esbuild ./src/*.js ./src/**/*.js --target=node16 --format=cjs --outdir=dist/cjs --bundle",
|
|
23
|
+
"build:iife": "cross-env NODE_ENV=$NODE_ENV npx esbuild ./src/index.js --target=es2017 --format=iife --outdir=dist/iife --bundle --minify",
|
|
24
24
|
"build": "npm run build:cjs",
|
|
25
25
|
"prepublish": "rimraf -I dist && npm run build && npm run copy:package:cjs"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@domql/utils": "^2.27.
|
|
29
|
-
"@symbo.ls/utils": "^2.27.
|
|
28
|
+
"@domql/utils": "^2.27.11",
|
|
29
|
+
"@symbo.ls/utils": "^2.27.11",
|
|
30
30
|
"color-contrast-checker": "^1.5.0"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "0189e4620f901c763754d06de65bcf6075c05618"
|
|
33
33
|
}
|
package/src/system/typography.js
CHANGED
|
@@ -23,15 +23,7 @@ export const runThroughMedia = FACTORY => {
|
|
|
23
23
|
const { mediaRegenerate } = FACTORY
|
|
24
24
|
const mediaName = prop.slice(1)
|
|
25
25
|
|
|
26
|
-
const {
|
|
27
|
-
type,
|
|
28
|
-
base,
|
|
29
|
-
ratio,
|
|
30
|
-
range,
|
|
31
|
-
subSequence,
|
|
32
|
-
h1Matches,
|
|
33
|
-
unit
|
|
34
|
-
} = FACTORY
|
|
26
|
+
const { type, base, ratio, range, subSequence, h1Matches, unit } = FACTORY
|
|
35
27
|
|
|
36
28
|
merge(mediaValue, {
|
|
37
29
|
type,
|
|
@@ -44,7 +36,8 @@ export const runThroughMedia = FACTORY => {
|
|
|
44
36
|
})
|
|
45
37
|
|
|
46
38
|
const query = MEDIA[mediaName]
|
|
47
|
-
const media =
|
|
39
|
+
const media =
|
|
40
|
+
'@media ' + (query === 'print' ? `${query}` : `screen and ${query}`)
|
|
48
41
|
TYPOGRAPHY.templates[media] = {
|
|
49
42
|
fontSize: mediaValue.base / TYPOGRAPHY.browserDefault + unit
|
|
50
43
|
}
|
|
@@ -67,7 +60,7 @@ export const runThroughMedia = FACTORY => {
|
|
|
67
60
|
}
|
|
68
61
|
}
|
|
69
62
|
|
|
70
|
-
export const applyHeadings =
|
|
63
|
+
export const applyHeadings = props => {
|
|
71
64
|
const CONFIG = getActiveConfig()
|
|
72
65
|
if (props.h1Matches) {
|
|
73
66
|
const unit = props.unit
|
|
@@ -76,13 +69,16 @@ export const applyHeadings = (props) => {
|
|
|
76
69
|
for (const k in HEADINGS) {
|
|
77
70
|
const headerName = `h${parseInt(k) + 1}`
|
|
78
71
|
const headerStyle = templates[headerName]
|
|
79
|
-
if (!HEADINGS[k]) continue
|
|
80
72
|
templates[headerName] = {
|
|
81
|
-
fontSize: CONFIG.useVariable
|
|
73
|
+
fontSize: CONFIG.useVariable
|
|
74
|
+
? `var(${HEADINGS[k]?.variable})`
|
|
75
|
+
: `${HEADINGS[k]?.scaling}${unit}`,
|
|
82
76
|
margin: headerStyle ? headerStyle.margin : 0,
|
|
83
77
|
lineHeight: headerStyle ? headerStyle.lineHeight : props.lineHeight,
|
|
84
|
-
letterSpacing: headerStyle
|
|
85
|
-
|
|
78
|
+
letterSpacing: headerStyle
|
|
79
|
+
? headerStyle.letterSpacing
|
|
80
|
+
: props.letterSpacing,
|
|
81
|
+
fontWeight: headerStyle ? headerStyle.fontWeight : 900 - k * 100
|
|
86
82
|
}
|
|
87
83
|
}
|
|
88
84
|
}
|
|
@@ -101,9 +97,5 @@ export const applyTypographySequence = () => {
|
|
|
101
97
|
export const getFontSizeByKey = value => {
|
|
102
98
|
const CONFIG = getActiveConfig()
|
|
103
99
|
const { TYPOGRAPHY } = CONFIG
|
|
104
|
-
return getSequenceValuePropertyPair(
|
|
105
|
-
value,
|
|
106
|
-
'fontSize',
|
|
107
|
-
TYPOGRAPHY
|
|
108
|
-
)
|
|
100
|
+
return getSequenceValuePropertyPair(value, 'fontSize', TYPOGRAPHY)
|
|
109
101
|
}
|
package/src/utils/color.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
document,
|
|
5
|
+
window,
|
|
6
|
+
isString,
|
|
7
|
+
isNumber,
|
|
8
|
+
isNotProduction
|
|
9
|
+
} from '@domql/utils'
|
|
4
10
|
const ENV = process.env.NODE_ENV
|
|
5
11
|
|
|
6
12
|
export const colorStringToRgbaArray = color => {
|
|
@@ -10,11 +16,22 @@ export const colorStringToRgbaArray = color => {
|
|
|
10
16
|
// convert #RGB and #RGBA to #RRGGBB and #RRGGBBAA
|
|
11
17
|
if (color[0] === '#') {
|
|
12
18
|
if (color.length < 7) {
|
|
13
|
-
color =
|
|
14
|
-
|
|
19
|
+
color =
|
|
20
|
+
'#' +
|
|
21
|
+
color[1] +
|
|
22
|
+
color[1] +
|
|
23
|
+
color[2] +
|
|
24
|
+
color[2] +
|
|
25
|
+
color[3] +
|
|
26
|
+
color[3] +
|
|
27
|
+
(color.length > 4 ? color[4] + color[4] : '')
|
|
28
|
+
}
|
|
29
|
+
return [
|
|
30
|
+
parseInt(color.substr(1, 2), 16),
|
|
15
31
|
parseInt(color.substr(3, 2), 16),
|
|
16
32
|
parseInt(color.substr(5, 2), 16),
|
|
17
|
-
color.length > 7 ? parseInt(color.substr(7, 2), 16) / 255 : 1
|
|
33
|
+
color.length > 7 ? parseInt(color.substr(7, 2), 16) / 255 : 1
|
|
34
|
+
]
|
|
18
35
|
}
|
|
19
36
|
|
|
20
37
|
// convert named colors
|
|
@@ -81,11 +98,7 @@ export const hexToRgba = (hex, alpha = 1) => {
|
|
|
81
98
|
export const mixTwoRgb = (colorA, colorB, range = 0.5) => {
|
|
82
99
|
const arr = []
|
|
83
100
|
for (let i = 0; i < 3; i++) {
|
|
84
|
-
arr[i] = ~~(
|
|
85
|
-
colorA[i] + (
|
|
86
|
-
(colorB[i] - colorA[i]) * range
|
|
87
|
-
)
|
|
88
|
-
)
|
|
101
|
+
arr[i] = ~~(colorA[i] + (colorB[i] - colorA[i]) * range)
|
|
89
102
|
}
|
|
90
103
|
return `rgb(${arr})`
|
|
91
104
|
}
|
|
@@ -93,25 +106,27 @@ export const mixTwoRgb = (colorA, colorB, range = 0.5) => {
|
|
|
93
106
|
export const changeLightness = (delta, hsl) => {
|
|
94
107
|
const [hue, saturation, lightness] = hsl
|
|
95
108
|
|
|
96
|
-
const newLightness = Math.max(
|
|
97
|
-
0,
|
|
98
|
-
Math.min(100, lightness + parseFloat(delta))
|
|
99
|
-
)
|
|
109
|
+
const newLightness = Math.max(0, Math.min(100, lightness + parseFloat(delta)))
|
|
100
110
|
|
|
101
111
|
return [hue, saturation, newLightness]
|
|
102
112
|
}
|
|
103
113
|
|
|
104
114
|
export const rgbToHSL = (r, g, b) => {
|
|
105
|
-
const a = Math.max(r, g, b)
|
|
106
|
-
const
|
|
115
|
+
const a = Math.max(r, g, b)
|
|
116
|
+
const n = a - Math.min(r, g, b)
|
|
117
|
+
const f = 1 - Math.abs(a + a - n - 1)
|
|
118
|
+
const h =
|
|
119
|
+
n && (a == r ? (g - b) / n : a == g ? 2 + (b - r) / n : 4 + (r - g) / n) //eslint-disable-line
|
|
107
120
|
return [60 * (h < 0 ? h + 6 : h), f ? n / f : 0, (a + a - n) / 2]
|
|
108
121
|
}
|
|
109
122
|
|
|
110
|
-
export const hslToRgb = (
|
|
123
|
+
export const hslToRgb = (
|
|
124
|
+
h,
|
|
125
|
+
s,
|
|
126
|
+
l,
|
|
111
127
|
a = s * Math.min(l, 1 - l),
|
|
112
|
-
f = (n, k = (n + h / 30) % 12) =>
|
|
113
|
-
Math.min(k - 3, 9 - k, 1), -1
|
|
114
|
-
)
|
|
128
|
+
f = (n, k = (n + h / 30) % 12) =>
|
|
129
|
+
l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1)
|
|
115
130
|
) => [f(0), f(8), f(4)]
|
|
116
131
|
|
|
117
132
|
export const getColorShade = (col, amt) => {
|
|
@@ -122,12 +137,12 @@ export const getColorShade = (col, amt) => {
|
|
|
122
137
|
if (r > 255) r = 255
|
|
123
138
|
else if (r < 0) r = 0
|
|
124
139
|
|
|
125
|
-
let b = ((num >> 8) &
|
|
140
|
+
let b = ((num >> 8) & 0x00ff) + amt
|
|
126
141
|
|
|
127
142
|
if (b > 255) b = 255
|
|
128
143
|
else if (b < 0) b = 0
|
|
129
144
|
|
|
130
|
-
let g = (num &
|
|
145
|
+
let g = (num & 0x0000ff) + amt
|
|
131
146
|
|
|
132
147
|
if (g > 255) g = 255
|
|
133
148
|
else if (g < 0) g = 0
|
|
@@ -138,12 +153,8 @@ export const getColorShade = (col, amt) => {
|
|
|
138
153
|
export const mixTwoRgba = (colorA, colorB, range = 0.5) => {
|
|
139
154
|
const arr = []
|
|
140
155
|
for (let i = 0; i < 4; i++) {
|
|
141
|
-
const round =
|
|
142
|
-
arr[i] = round(
|
|
143
|
-
(colorA[i] + (
|
|
144
|
-
(colorB[i] - colorA[i]) * range
|
|
145
|
-
))
|
|
146
|
-
)
|
|
156
|
+
const round = i === 3 ? x => x : Math.round
|
|
157
|
+
arr[i] = round(colorA[i] + (colorB[i] - colorA[i]) * range)
|
|
147
158
|
}
|
|
148
159
|
return `rgba(${arr})`
|
|
149
160
|
}
|
|
@@ -151,7 +162,7 @@ export const mixTwoRgba = (colorA, colorB, range = 0.5) => {
|
|
|
151
162
|
export const opacify = (color, opacity) => {
|
|
152
163
|
const arr = colorStringToRgbaArray(color)
|
|
153
164
|
if (!arr) {
|
|
154
|
-
if (ENV
|
|
165
|
+
if (isNotProduction(ENV)) console.warn(color + ' color is not rgba')
|
|
155
166
|
return
|
|
156
167
|
}
|
|
157
168
|
arr[3] = opacity
|
|
@@ -159,7 +170,8 @@ export const opacify = (color, opacity) => {
|
|
|
159
170
|
}
|
|
160
171
|
|
|
161
172
|
export const getRgbTone = (rgb, tone) => {
|
|
162
|
-
if (isString(rgb) && rgb.includes('rgb'))
|
|
173
|
+
if (isString(rgb) && rgb.includes('rgb'))
|
|
174
|
+
rgb = colorStringToRgbaArray(rgb).join(', ')
|
|
163
175
|
if (isString(rgb)) rgb = rgb.split(',').map(v => parseFloat(v.trim()))
|
|
164
176
|
if (isNumber(tone)) tone += ''
|
|
165
177
|
const toHex = rgbArrayToHex(rgb)
|
|
@@ -172,7 +184,7 @@ export const getRgbTone = (rgb, tone) => {
|
|
|
172
184
|
const [r, g, b] = rgb
|
|
173
185
|
const hsl = rgbToHSL(r, g, b)
|
|
174
186
|
const [h, s, l] = hsl // eslint-disable-line
|
|
175
|
-
const newRgb = hslToRgb(h, s, parseFloat(tone) / 100 * 255)
|
|
187
|
+
const newRgb = hslToRgb(h, s, (parseFloat(tone) / 100) * 255)
|
|
176
188
|
return newRgb
|
|
177
189
|
}
|
|
178
190
|
}
|
package/src/utils/sprite.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { isArray, isString } from '@domql/utils'
|
|
3
|
+
import { isArray, isNotProduction, isString } from '@domql/utils'
|
|
4
4
|
import { getActiveConfig } from '../factory'
|
|
5
5
|
|
|
6
6
|
const ENV = process.env.NODE_ENV || 'development'
|
|
7
|
-
const isDev = ENV
|
|
7
|
+
const isDev = isNotProduction(ENV)
|
|
8
8
|
|
|
9
|
-
export const generateSprite =
|
|
9
|
+
export const generateSprite = icons => {
|
|
10
10
|
const CONFIG = getActiveConfig()
|
|
11
11
|
|
|
12
12
|
let sprite = ''
|
|
@@ -20,7 +20,7 @@ export const generateSprite = (icons) => {
|
|
|
20
20
|
return sprite
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
const parseRootAttributes =
|
|
23
|
+
const parseRootAttributes = htmlString => {
|
|
24
24
|
const val = htmlString.default || htmlString
|
|
25
25
|
if (!isString(val)) {
|
|
26
26
|
if (isDev) console.warn('parseRootAttributes:', val, 'is not a string')
|
|
@@ -33,7 +33,9 @@ const parseRootAttributes = (htmlString) => {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
const attrString = match[1]
|
|
36
|
-
const attrs = attrString.match(
|
|
36
|
+
const attrs = attrString.match(
|
|
37
|
+
/(\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|\s*\/?[>"']))+.)["']?/gm
|
|
38
|
+
)
|
|
37
39
|
return attrs.reduce((acc, attr) => {
|
|
38
40
|
const [key, value] = attr.split('=')
|
|
39
41
|
acc[key] = value.replace(/['"]/g, '')
|
|
@@ -49,7 +51,9 @@ const replaceIdsAndUrls = (code, key) => {
|
|
|
49
51
|
if (isArray(matches)) {
|
|
50
52
|
matches.forEach(() => {
|
|
51
53
|
const randomKey = Math.floor(Math.random() * 100000)
|
|
52
|
-
replacedCode = code
|
|
54
|
+
replacedCode = code
|
|
55
|
+
.replace(idRegex, `id="${key}-${randomKey}"`)
|
|
56
|
+
.replace(urlRegex, `url(#${key}-${randomKey})`)
|
|
53
57
|
})
|
|
54
58
|
}
|
|
55
59
|
return replacedCode
|
|
@@ -64,7 +68,8 @@ export const convertSvgToSymbol = (key, code) => {
|
|
|
64
68
|
|
|
65
69
|
const replacedCode = replaceIdsAndUrls(code, key)
|
|
66
70
|
|
|
67
|
-
let symbol = replacedCode.replace(
|
|
71
|
+
let symbol = replacedCode.replace(
|
|
72
|
+
'<svg',
|
|
68
73
|
`<symbol id="${key}" xmlns="${xmlns}" viewBox="${viewBox}"`
|
|
69
74
|
)
|
|
70
75
|
|