@symbo.ls/scratch 3.14.0 → 3.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cjs/defaultConfig/animation.js +4 -2
- package/dist/cjs/defaultConfig/cases.js +4 -2
- package/dist/cjs/defaultConfig/class.js +5 -2
- package/dist/cjs/defaultConfig/color.js +6 -9
- package/dist/cjs/defaultConfig/document.js +4 -2
- package/dist/cjs/defaultConfig/font-family.js +8 -12
- package/dist/cjs/defaultConfig/font.js +4 -11
- package/dist/cjs/defaultConfig/grid.js +5 -3
- package/dist/cjs/defaultConfig/icons.js +6 -4
- package/dist/cjs/defaultConfig/index.js +200 -24
- package/dist/cjs/defaultConfig/media.js +4 -2
- package/dist/cjs/defaultConfig/responsive.js +6 -4
- package/dist/cjs/defaultConfig/sequence.js +4 -2
- package/dist/cjs/defaultConfig/shadow.js +4 -2
- package/dist/cjs/defaultConfig/spacing.js +56 -7
- package/dist/cjs/defaultConfig/svg.js +6 -4
- package/dist/cjs/defaultConfig/templates.js +4 -2
- package/dist/cjs/defaultConfig/theme.js +4 -14
- package/dist/cjs/defaultConfig/timing.js +36 -5
- package/dist/cjs/defaultConfig/typography.js +36 -5
- package/dist/cjs/defaultConfig/unit.js +4 -2
- package/dist/cjs/factory.js +345 -104
- package/dist/cjs/index.js +6333 -13
- package/dist/cjs/package.json +4 -0
- package/dist/cjs/set.js +5609 -214
- package/dist/cjs/system/color.js +4487 -170
- package/dist/cjs/system/document.js +4371 -11
- package/dist/cjs/system/font.js +4401 -28
- package/dist/cjs/system/index.js +5748 -11
- package/dist/cjs/system/reset.js +4449 -52
- package/dist/cjs/system/shadow.js +4834 -44
- package/dist/cjs/system/spacing.js +4752 -39
- package/dist/cjs/system/svg.js +4437 -74
- package/dist/cjs/system/theme.js +4526 -336
- package/dist/cjs/system/timing.js +4695 -19
- package/dist/cjs/system/typography.js +4755 -42
- package/dist/cjs/tests/index.js +4 -2
- package/dist/cjs/transforms/index.js +5019 -134
- package/dist/cjs/utils/color.js +47 -66
- package/dist/cjs/utils/font.js +25 -48
- package/dist/cjs/utils/index.js +5068 -8
- package/dist/cjs/utils/sequence.js +4436 -67
- package/dist/cjs/utils/sprite.js +353 -19
- package/dist/cjs/utils/theme.js +3 -1
- package/dist/cjs/utils/unit.js +4 -2
- package/dist/cjs/utils/var.js +4391 -57
- package/package.json +1 -1
- package/src/utils/sprite.js +29 -12
- package/dist/esm/defaultConfig/animation.js +0 -4
- package/dist/esm/defaultConfig/cases.js +0 -4
- package/dist/esm/defaultConfig/class.js +0 -4
- package/dist/esm/defaultConfig/color.js +0 -11
- package/dist/esm/defaultConfig/document.js +0 -4
- package/dist/esm/defaultConfig/font-family.js +0 -18
- package/dist/esm/defaultConfig/font.js +0 -13
- package/dist/esm/defaultConfig/grid.js +0 -5
- package/dist/esm/defaultConfig/icons.js +0 -6
- package/dist/esm/defaultConfig/index.js +0 -25
- package/dist/esm/defaultConfig/media.js +0 -9
- package/dist/esm/defaultConfig/responsive.js +0 -30
- package/dist/esm/defaultConfig/sequence.js +0 -29
- package/dist/esm/defaultConfig/shadow.js +0 -4
- package/dist/esm/defaultConfig/spacing.js +0 -18
- package/dist/esm/defaultConfig/svg.js +0 -6
- package/dist/esm/defaultConfig/templates.js +0 -4
- package/dist/esm/defaultConfig/theme.js +0 -16
- package/dist/esm/defaultConfig/timing.js +0 -17
- package/dist/esm/defaultConfig/typography.js +0 -21
- package/dist/esm/defaultConfig/unit.js +0 -6
- package/dist/esm/factory.js +0 -120
- package/dist/esm/index.js +0 -14
- package/dist/esm/set.js +0 -280
- package/dist/esm/system/color.js +0 -253
- package/dist/esm/system/document.js +0 -16
- package/dist/esm/system/font.js +0 -58
- package/dist/esm/system/index.js +0 -10
- package/dist/esm/system/reset.js +0 -94
- package/dist/esm/system/shadow.js +0 -92
- package/dist/esm/system/spacing.js +0 -121
- package/dist/esm/system/svg.js +0 -113
- package/dist/esm/system/theme.js +0 -481
- package/dist/esm/system/timing.js +0 -32
- package/dist/esm/system/typography.js +0 -94
- package/dist/esm/tests/index.js +0 -8
- package/dist/esm/transforms/index.js +0 -216
- package/dist/esm/utils/color.js +0 -192
- package/dist/esm/utils/font.js +0 -94
- package/dist/esm/utils/index.js +0 -7
- package/dist/esm/utils/sequence.js +0 -322
- package/dist/esm/utils/sprite.js +0 -72
- package/dist/esm/utils/theme.js +0 -9
- package/dist/esm/utils/unit.js +0 -59
- package/dist/esm/utils/var.js +0 -96
- package/dist/iife/index.js +0 -3630
package/dist/esm/system/reset.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { deepMerge, merge, overwriteDeep } from "@symbo.ls/utils";
|
|
2
|
-
import { getActiveConfig } from "../factory.js";
|
|
3
|
-
import { getMediaTheme } from "./theme.js";
|
|
4
|
-
const applyReset = (reset = {}) => {
|
|
5
|
-
const CONFIG = getActiveConfig();
|
|
6
|
-
const { reset: RESET, typography: TYPOGRAPHY, document: DOCUMENT } = CONFIG;
|
|
7
|
-
if (RESET) {
|
|
8
|
-
if (RESET[":root"]) {
|
|
9
|
-
const configReset = RESET;
|
|
10
|
-
const configTemplates = TYPOGRAPHY.templates;
|
|
11
|
-
configReset.body = {
|
|
12
|
-
...CONFIG.useDocumentTheme ? getMediaTheme("document") : {},
|
|
13
|
-
...configTemplates.body
|
|
14
|
-
};
|
|
15
|
-
configReset.h1 = configTemplates.h1;
|
|
16
|
-
configReset.h2 = configTemplates.h2;
|
|
17
|
-
configReset.h3 = configTemplates.h3;
|
|
18
|
-
configReset.h4 = configTemplates.h4;
|
|
19
|
-
configReset.h5 = configTemplates.h5;
|
|
20
|
-
configReset.h6 = configTemplates.h6;
|
|
21
|
-
}
|
|
22
|
-
const { body, ...templates } = TYPOGRAPHY.templates;
|
|
23
|
-
const globalTheme = CONFIG.useDocumentTheme ? getMediaTheme("document") : {};
|
|
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
|
-
}
|
|
44
|
-
return deepMerge(merge(RESET, reset), {
|
|
45
|
-
html: {
|
|
46
|
-
position: "absolute",
|
|
47
|
-
width: "100%",
|
|
48
|
-
height: "100%",
|
|
49
|
-
top: "0",
|
|
50
|
-
left: "0",
|
|
51
|
-
margin: "0",
|
|
52
|
-
WebkitFontSmoothing: "subpixel-antialiased",
|
|
53
|
-
scrollBehavior: "smooth",
|
|
54
|
-
...globalTheme,
|
|
55
|
-
fontSize: TYPOGRAPHY.unit ? TYPOGRAPHY.base / TYPOGRAPHY.browserDefault + TYPOGRAPHY.unit : TYPOGRAPHY.browserDefault + "px",
|
|
56
|
-
fontFamily: DOCUMENT.fontFamily,
|
|
57
|
-
lineHeight: DOCUMENT.lineHeight
|
|
58
|
-
},
|
|
59
|
-
body: {
|
|
60
|
-
boxSizing: "border-box",
|
|
61
|
-
height: "100%",
|
|
62
|
-
margin: 0,
|
|
63
|
-
fontFamily: DOCUMENT.fontFamily,
|
|
64
|
-
fontSize: TYPOGRAPHY.base / TYPOGRAPHY.browserDefault + CONFIG.unit.default,
|
|
65
|
-
...templates,
|
|
66
|
-
...body
|
|
67
|
-
},
|
|
68
|
-
a: {
|
|
69
|
-
color: "currentColor"
|
|
70
|
-
},
|
|
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
|
-
},
|
|
84
|
-
fieldset: {
|
|
85
|
-
border: 0,
|
|
86
|
-
padding: 0,
|
|
87
|
-
margin: 0
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
export {
|
|
93
|
-
applyReset
|
|
94
|
-
};
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { getActiveConfig } from "../factory.js";
|
|
2
|
-
import { getColor } from "./color.js";
|
|
3
|
-
import { getSpacingByKey } from "./spacing.js";
|
|
4
|
-
import { isResolvedColor, isCSSVar, splitTopLevelCommas, CSS_NATIVE_COLOR_REGEX } from "../utils/color.js";
|
|
5
|
-
import {
|
|
6
|
-
isObject,
|
|
7
|
-
isString,
|
|
8
|
-
isArray
|
|
9
|
-
} from "@symbo.ls/utils";
|
|
10
|
-
const setShadow = (value, key, suffix, prefers) => {
|
|
11
|
-
const CONFIG = getActiveConfig();
|
|
12
|
-
if (isArray(value)) {
|
|
13
|
-
return {
|
|
14
|
-
"@light": setShadow(value[0], key, "light"),
|
|
15
|
-
"@dark": setShadow(value[1], key, "dark")
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
if (isObject(value)) {
|
|
19
|
-
const obj = {};
|
|
20
|
-
for (const variant in value) {
|
|
21
|
-
obj[variant] = setShadow(
|
|
22
|
-
value[variant],
|
|
23
|
-
key,
|
|
24
|
-
variant.startsWith("@") ? variant.slice(1) : variant
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
return obj;
|
|
28
|
-
}
|
|
29
|
-
if (isString(value) && !CSS_NATIVE_COLOR_REGEX.test(value)) {
|
|
30
|
-
value = splitTopLevelCommas(value).map((shadow) => {
|
|
31
|
-
shadow = shadow.trim();
|
|
32
|
-
return shadow.split(/\s+/).map((v) => {
|
|
33
|
-
v = v.trim();
|
|
34
|
-
if (!v) return "";
|
|
35
|
-
if (v.startsWith("--")) return `var(${v})`;
|
|
36
|
-
const color = getColor(v);
|
|
37
|
-
if (isResolvedColor(color)) return color;
|
|
38
|
-
if (/^\d/.test(v) || v === "0" || v.includes("px") || v.slice(-2) === "em") return v;
|
|
39
|
-
if (v === "inset" || v === "none") return v;
|
|
40
|
-
const spacing = getSpacingByKey(v, "shadow");
|
|
41
|
-
if (spacing && spacing.shadow) return spacing.shadow;
|
|
42
|
-
return v;
|
|
43
|
-
}).join(" ");
|
|
44
|
-
}).join(", ");
|
|
45
|
-
}
|
|
46
|
-
const vp = CONFIG.varPrefix ? CONFIG.varPrefix + "-" : "";
|
|
47
|
-
const CSSVar = `--${vp}shadow-${key}` + (suffix ? `-${suffix}` : "");
|
|
48
|
-
if (CONFIG.useVariable) {
|
|
49
|
-
CONFIG.cssVars[CSSVar] = value;
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
var: CSSVar,
|
|
53
|
-
value
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
const getShadow = (value, globalTheme) => {
|
|
57
|
-
const CONFIG = getActiveConfig();
|
|
58
|
-
if (!globalTheme) globalTheme = CONFIG.globalTheme;
|
|
59
|
-
if (!isString(value)) {
|
|
60
|
-
if (CONFIG.verbose) console.warn(value, "- type for color is not valid");
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (isCSSVar(value)) return `var(${value})`;
|
|
64
|
-
const [name] = isArray(value) ? value : value.split(" ");
|
|
65
|
-
const SHADOW = CONFIG.shadow;
|
|
66
|
-
const val = SHADOW[name];
|
|
67
|
-
const isObj = isObject(val);
|
|
68
|
-
if (!val) {
|
|
69
|
-
if (CONFIG.verbose) console.warn("Can't find color ", name);
|
|
70
|
-
return value;
|
|
71
|
-
}
|
|
72
|
-
if (globalTheme) {
|
|
73
|
-
if (val[globalTheme]) return val[globalTheme].value;
|
|
74
|
-
else if (CONFIG.verbose) console.warn(value, " - does not have ", globalTheme);
|
|
75
|
-
}
|
|
76
|
-
if (isObj && val.value) return val.value;
|
|
77
|
-
if (isObj) {
|
|
78
|
-
const obj = {};
|
|
79
|
-
for (const mediaName in val) {
|
|
80
|
-
const query = CONFIG.media[mediaName.slice(1)];
|
|
81
|
-
const media = "@media " + (query === "print" ? `${query}` : `screen and ${query}`);
|
|
82
|
-
obj[media] = val.value;
|
|
83
|
-
}
|
|
84
|
-
return obj;
|
|
85
|
-
}
|
|
86
|
-
if (CONFIG.verbose) console.warn("Can't find color", value);
|
|
87
|
-
return value;
|
|
88
|
-
};
|
|
89
|
-
export {
|
|
90
|
-
getShadow,
|
|
91
|
-
setShadow
|
|
92
|
-
};
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { arrayzeValue } from "@symbo.ls/utils";
|
|
2
|
-
import { isArray, isString, merge } from "@symbo.ls/utils";
|
|
3
|
-
import { getActiveConfig } from "../factory.js";
|
|
4
|
-
import {
|
|
5
|
-
CSS_UNITS,
|
|
6
|
-
applyMediaSequenceVars,
|
|
7
|
-
applySequenceVars,
|
|
8
|
-
generateSequence,
|
|
9
|
-
getFnPrefixAndValue,
|
|
10
|
-
getSequenceValuePropertyPair
|
|
11
|
-
} from "../utils/index.js";
|
|
12
|
-
const runThroughMedia = (FACTORY) => {
|
|
13
|
-
for (const prop in FACTORY) {
|
|
14
|
-
const mediaProps = FACTORY[prop];
|
|
15
|
-
const isMediaName = prop.slice(0, 1) === "@";
|
|
16
|
-
if (!isMediaName) continue;
|
|
17
|
-
const { type, base, ratio, range, subSequence, h1Matches, unit } = FACTORY;
|
|
18
|
-
merge(mediaProps, {
|
|
19
|
-
type,
|
|
20
|
-
base,
|
|
21
|
-
ratio,
|
|
22
|
-
range,
|
|
23
|
-
subSequence,
|
|
24
|
-
h1Matches,
|
|
25
|
-
unit,
|
|
26
|
-
sequence: {},
|
|
27
|
-
scales: {},
|
|
28
|
-
templates: {},
|
|
29
|
-
vars: {}
|
|
30
|
-
});
|
|
31
|
-
generateSequence(mediaProps);
|
|
32
|
-
applyMediaSequenceVars(FACTORY, prop);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
const checkIfBoxSize = (propertyName) => {
|
|
36
|
-
const prop = propertyName.toLowerCase();
|
|
37
|
-
const includesWidth = prop.includes("width") || prop.includes("height");
|
|
38
|
-
const includesBorder = prop.includes("border") || prop.includes("outline");
|
|
39
|
-
return includesWidth && !includesBorder;
|
|
40
|
-
};
|
|
41
|
-
const applySpacingSequence = () => {
|
|
42
|
-
const CONFIG = getActiveConfig();
|
|
43
|
-
const { spacing: SPACING } = CONFIG;
|
|
44
|
-
generateSequence(SPACING);
|
|
45
|
-
applySequenceVars(SPACING);
|
|
46
|
-
runThroughMedia(SPACING);
|
|
47
|
-
};
|
|
48
|
-
const getSequence = (sequenceProps) => {
|
|
49
|
-
const CONFIG = getActiveConfig();
|
|
50
|
-
const { spacing: SPACING } = CONFIG;
|
|
51
|
-
if (!sequenceProps || !sequenceProps.sequence) return SPACING;
|
|
52
|
-
const hasGenerated = Object.keys(sequenceProps.sequence).length > 0;
|
|
53
|
-
return hasGenerated ? sequenceProps : generateSequence(sequenceProps);
|
|
54
|
-
};
|
|
55
|
-
const getSpacingByKey = (value, propertyName = "padding", sequenceProps, fnPrefix) => {
|
|
56
|
-
const sequence = getSequence(sequenceProps);
|
|
57
|
-
if (isString(value)) {
|
|
58
|
-
if (!fnPrefix && value.includes("(")) {
|
|
59
|
-
const fnArray = getFnPrefixAndValue(value);
|
|
60
|
-
fnPrefix = fnArray[0];
|
|
61
|
-
value = fnArray[1];
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const stack = fnPrefix ? [value] : arrayzeValue(value);
|
|
65
|
-
if (!isArray(stack)) return;
|
|
66
|
-
if (stack.length > 1) {
|
|
67
|
-
let suffix = "";
|
|
68
|
-
if (propertyName === "borderWidth") {
|
|
69
|
-
propertyName = "border";
|
|
70
|
-
suffix = "Width";
|
|
71
|
-
}
|
|
72
|
-
const directions = {
|
|
73
|
-
2: ["Block", "Inline"],
|
|
74
|
-
3: ["BlockStart", "Inline", "BlockEnd"],
|
|
75
|
-
4: ["BlockStart", "InlineEnd", "BlockEnd", "InlineStart"]
|
|
76
|
-
};
|
|
77
|
-
const wrapSequenceValueByDirection = (direction, i) => getSequenceValuePropertyPair(
|
|
78
|
-
stack[i],
|
|
79
|
-
propertyName + direction + suffix,
|
|
80
|
-
sequence,
|
|
81
|
-
fnPrefix
|
|
82
|
-
);
|
|
83
|
-
return directions[stack.length].map(
|
|
84
|
-
(dir, key) => wrapSequenceValueByDirection(dir, key)
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
return getSequenceValuePropertyPair(value, propertyName, sequence, fnPrefix);
|
|
88
|
-
};
|
|
89
|
-
const getSpacingBasedOnRatio = (props, propertyName, val, fnPrefix) => {
|
|
90
|
-
const CONFIG = getActiveConfig();
|
|
91
|
-
const { spacing: SPACING } = CONFIG;
|
|
92
|
-
let value = val || props[propertyName];
|
|
93
|
-
if (!fnPrefix && isString(value) && value.includes("(")) {
|
|
94
|
-
const fnArr = getFnPrefixAndValue(value);
|
|
95
|
-
fnPrefix = fnArr[0];
|
|
96
|
-
value = fnArr[1];
|
|
97
|
-
}
|
|
98
|
-
if (props.spacingRatio) {
|
|
99
|
-
const sequenceProps = applyCustomSequence(props);
|
|
100
|
-
return getSpacingByKey(value, propertyName, sequenceProps, fnPrefix);
|
|
101
|
-
}
|
|
102
|
-
return getSpacingByKey(value, propertyName, SPACING, fnPrefix);
|
|
103
|
-
};
|
|
104
|
-
const splitSpacedValue = (val) => {
|
|
105
|
-
const addDefault = (v) => {
|
|
106
|
-
const isSymbol = ["+", "-", "*", "/"].includes(v);
|
|
107
|
-
const hasUnits = CSS_UNITS.some((unit) => val.includes(unit));
|
|
108
|
-
if (isSymbol || hasUnits) return v;
|
|
109
|
-
const isSingleLetter = v.length < 3 && /[A-Z]/.test(v);
|
|
110
|
-
if (isSingleLetter) return v + "_default";
|
|
111
|
-
return v;
|
|
112
|
-
};
|
|
113
|
-
return val.split(",").map((v) => v.trim()).map(addDefault).join(",").split(" ").map(addDefault).join(" ");
|
|
114
|
-
};
|
|
115
|
-
export {
|
|
116
|
-
applySpacingSequence,
|
|
117
|
-
checkIfBoxSize,
|
|
118
|
-
getSpacingBasedOnRatio,
|
|
119
|
-
getSpacingByKey,
|
|
120
|
-
splitSpacedValue
|
|
121
|
-
};
|
package/dist/esm/system/svg.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { document } from "@symbo.ls/utils";
|
|
2
|
-
import { generateSprite, convertSvgToSymbol } from "../utils/index.js";
|
|
3
|
-
import { getActiveConfig } from "../factory.js";
|
|
4
|
-
const DEF_OPTIONS = {
|
|
5
|
-
document
|
|
6
|
-
};
|
|
7
|
-
const setSVG = (val, key) => {
|
|
8
|
-
const CONFIG = getActiveConfig();
|
|
9
|
-
if (!val) {
|
|
10
|
-
if (CONFIG.verbose) console.warn("setSVG: val is not defined", key);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
if (CONFIG.useSvgSprite) {
|
|
14
|
-
return convertSvgToSymbol(key, val);
|
|
15
|
-
}
|
|
16
|
-
return val;
|
|
17
|
-
};
|
|
18
|
-
const appendSVGSprite = (LIBRARY, options = DEF_OPTIONS) => {
|
|
19
|
-
const CONFIG = getActiveConfig();
|
|
20
|
-
const lib = Object.keys(LIBRARY).length ? {} : CONFIG.svg;
|
|
21
|
-
for (const key in LIBRARY) lib[key] = LIBRARY[key];
|
|
22
|
-
appendSVG(lib, options);
|
|
23
|
-
};
|
|
24
|
-
const setSvgIcon = (val, key) => {
|
|
25
|
-
const CONFIG = getActiveConfig();
|
|
26
|
-
if (CONFIG.useIconSprite && !CONFIG.semanticIcons?.[key]) {
|
|
27
|
-
return setSVG(val, key);
|
|
28
|
-
}
|
|
29
|
-
return val;
|
|
30
|
-
};
|
|
31
|
-
const appendSvgIconsSprite = (LIBRARY, options = DEF_OPTIONS) => {
|
|
32
|
-
const CONFIG = getActiveConfig();
|
|
33
|
-
const lib = Object.keys(LIBRARY).length ? {} : CONFIG.icons;
|
|
34
|
-
for (const key in LIBRARY) lib[key] = LIBRARY[key];
|
|
35
|
-
appendSVG(lib, options);
|
|
36
|
-
};
|
|
37
|
-
const createSVGSpriteElement = (doc, options = { isRoot: true }) => {
|
|
38
|
-
if (!doc || !doc.createElementNS) return;
|
|
39
|
-
const svgElem = doc.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
40
|
-
if (options.isRoot) {
|
|
41
|
-
svgElem.setAttribute("aria-hidden", "true");
|
|
42
|
-
svgElem.setAttribute("width", "0");
|
|
43
|
-
svgElem.setAttribute("height", "0");
|
|
44
|
-
svgElem.setAttribute("style", "position:absolute");
|
|
45
|
-
svgElem.setAttribute("id", "svgSprite");
|
|
46
|
-
}
|
|
47
|
-
return svgElem;
|
|
48
|
-
};
|
|
49
|
-
const parseSVGSprite = (doc, svgString) => {
|
|
50
|
-
const DOMParserCtor = typeof DOMParser !== "undefined" ? DOMParser : null;
|
|
51
|
-
if (DOMParserCtor) {
|
|
52
|
-
const wrapped = `<svg xmlns="http://www.w3.org/2000/svg">${svgString}</svg>`;
|
|
53
|
-
const parser = new DOMParserCtor();
|
|
54
|
-
const parsed = parser.parseFromString(wrapped, "image/svg+xml");
|
|
55
|
-
if (parsed.querySelector("parsererror")) return null;
|
|
56
|
-
return parsed.documentElement;
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
59
|
-
};
|
|
60
|
-
const moveChildren = (doc, from, to) => {
|
|
61
|
-
while (from.firstChild) {
|
|
62
|
-
const child = from.firstChild;
|
|
63
|
-
to.appendChild(doc.importNode(child, true));
|
|
64
|
-
child.remove();
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
const appendSVG = (lib, options = DEF_OPTIONS) => {
|
|
68
|
-
const CONFIG = getActiveConfig();
|
|
69
|
-
const doc = options.document || document;
|
|
70
|
-
if (!doc || !doc.documentElement) {
|
|
71
|
-
if (CONFIG.verbose) {
|
|
72
|
-
console.warn("To append SVG sprites it should be run in browser environment");
|
|
73
|
-
}
|
|
74
|
-
return generateSprite(lib);
|
|
75
|
-
}
|
|
76
|
-
const exists = doc.querySelector("#svgSprite");
|
|
77
|
-
const SVGsprite = generateSprite(lib);
|
|
78
|
-
const spriteHtml = `<svg aria-hidden="true" width="0" height="0" style="position:absolute" id="svgSprite">${SVGsprite}</svg>`;
|
|
79
|
-
const parsed = parseSVGSprite(doc, SVGsprite);
|
|
80
|
-
if (exists) {
|
|
81
|
-
if (parsed) {
|
|
82
|
-
moveChildren(doc, parsed, exists);
|
|
83
|
-
} else if (doc.body.insertAdjacentHTML) {
|
|
84
|
-
exists.insertAdjacentHTML("beforeend", SVGsprite);
|
|
85
|
-
} else {
|
|
86
|
-
const tempSVG = createSVGSpriteElement(doc, { isRoot: false });
|
|
87
|
-
tempSVG.innerHTML = SVGsprite;
|
|
88
|
-
exists.append(...tempSVG.children);
|
|
89
|
-
}
|
|
90
|
-
} else {
|
|
91
|
-
if (parsed) {
|
|
92
|
-
const svgSpriteDOM = createSVGSpriteElement(doc);
|
|
93
|
-
if (svgSpriteDOM && svgSpriteDOM.nodeType) {
|
|
94
|
-
moveChildren(doc, parsed, svgSpriteDOM);
|
|
95
|
-
doc.body.prepend(svgSpriteDOM);
|
|
96
|
-
}
|
|
97
|
-
} else if (doc.body.insertAdjacentHTML) {
|
|
98
|
-
doc.body.insertAdjacentHTML("afterbegin", spriteHtml);
|
|
99
|
-
} else {
|
|
100
|
-
const svgSpriteDOM = createSVGSpriteElement(doc);
|
|
101
|
-
if (svgSpriteDOM && svgSpriteDOM.nodeType) {
|
|
102
|
-
svgSpriteDOM.innerHTML = SVGsprite;
|
|
103
|
-
doc.body.prepend(svgSpriteDOM);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
export {
|
|
109
|
-
appendSVGSprite,
|
|
110
|
-
appendSvgIconsSprite,
|
|
111
|
-
setSVG,
|
|
112
|
-
setSvgIcon
|
|
113
|
-
};
|