@symbo.ls/scratch 3.14.0 → 3.14.2
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/package.json +2 -2
- package/src/utils/sprite.js +29 -12
- package/dist/cjs/defaultConfig/animation.js +0 -24
- package/dist/cjs/defaultConfig/cases.js +0 -24
- package/dist/cjs/defaultConfig/class.js +0 -24
- package/dist/cjs/defaultConfig/color.js +0 -31
- package/dist/cjs/defaultConfig/document.js +0 -24
- package/dist/cjs/defaultConfig/font-family.js +0 -38
- package/dist/cjs/defaultConfig/font.js +0 -33
- package/dist/cjs/defaultConfig/grid.js +0 -25
- package/dist/cjs/defaultConfig/icons.js +0 -26
- package/dist/cjs/defaultConfig/index.js +0 -46
- package/dist/cjs/defaultConfig/media.js +0 -29
- package/dist/cjs/defaultConfig/responsive.js +0 -50
- package/dist/cjs/defaultConfig/sequence.js +0 -49
- package/dist/cjs/defaultConfig/shadow.js +0 -24
- package/dist/cjs/defaultConfig/spacing.js +0 -38
- package/dist/cjs/defaultConfig/svg.js +0 -26
- package/dist/cjs/defaultConfig/templates.js +0 -24
- package/dist/cjs/defaultConfig/theme.js +0 -36
- package/dist/cjs/defaultConfig/timing.js +0 -37
- package/dist/cjs/defaultConfig/typography.js +0 -41
- package/dist/cjs/defaultConfig/unit.js +0 -26
- package/dist/cjs/factory.js +0 -145
- package/dist/cjs/index.js +0 -45
- package/dist/cjs/set.js +0 -286
- package/dist/cjs/system/color.js +0 -268
- package/dist/cjs/system/document.js +0 -36
- package/dist/cjs/system/font.js +0 -71
- package/dist/cjs/system/index.js +0 -27
- package/dist/cjs/system/reset.js +0 -114
- package/dist/cjs/system/shadow.js +0 -108
- package/dist/cjs/system/spacing.js +0 -134
- package/dist/cjs/system/svg.js +0 -133
- package/dist/cjs/system/theme.js +0 -496
- package/dist/cjs/system/timing.js +0 -48
- package/dist/cjs/system/typography.js +0 -108
- package/dist/cjs/tests/index.js +0 -28
- package/dist/cjs/transforms/index.js +0 -219
- package/dist/cjs/utils/color.js +0 -206
- package/dist/cjs/utils/font.js +0 -114
- package/dist/cjs/utils/index.js +0 -24
- package/dist/cjs/utils/sequence.js +0 -342
- package/dist/cjs/utils/sprite.js +0 -92
- package/dist/cjs/utils/theme.js +0 -29
- package/dist/cjs/utils/unit.js +0 -79
- package/dist/cjs/utils/var.js +0 -116
- 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
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
var defaultFont = {
|
|
2
|
-
// eslint-disable-line
|
|
3
|
-
name: "",
|
|
4
|
-
family: "",
|
|
5
|
-
type: ""
|
|
6
|
-
};
|
|
7
|
-
const fontFamily = {};
|
|
8
|
-
const fontFamilyTypes = {
|
|
9
|
-
"sans-serif": "Helvetica, Arial, sans-serif, --system-default",
|
|
10
|
-
serif: "Times New Roman, Georgia, serif, --system-default",
|
|
11
|
-
monospace: "Courier New, monospace, --system-default"
|
|
12
|
-
};
|
|
13
|
-
const fontFace = {};
|
|
14
|
-
export {
|
|
15
|
-
fontFace,
|
|
16
|
-
fontFamily,
|
|
17
|
-
fontFamilyTypes
|
|
18
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export * from "./sequence.js";
|
|
2
|
-
export * from "./unit.js";
|
|
3
|
-
export * from "./typography.js";
|
|
4
|
-
export * from "./font.js";
|
|
5
|
-
export * from "./font-family.js";
|
|
6
|
-
export * from "./media.js";
|
|
7
|
-
export * from "./spacing.js";
|
|
8
|
-
export * from "./color.js";
|
|
9
|
-
export * from "./theme.js";
|
|
10
|
-
export * from "./shadow.js";
|
|
11
|
-
export * from "./icons.js";
|
|
12
|
-
export * from "./timing.js";
|
|
13
|
-
export * from "./document.js";
|
|
14
|
-
export * from "./responsive.js";
|
|
15
|
-
export * from "./animation.js";
|
|
16
|
-
export * from "./svg.js";
|
|
17
|
-
export * from "./templates.js";
|
|
18
|
-
export * from "./grid.js";
|
|
19
|
-
export * from "./class.js";
|
|
20
|
-
const reset = {};
|
|
21
|
-
const vars = {};
|
|
22
|
-
export {
|
|
23
|
-
reset,
|
|
24
|
-
vars
|
|
25
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const breakpoints = {
|
|
2
|
-
screenL: 1920,
|
|
3
|
-
screenM: 1680,
|
|
4
|
-
screenS: 1440,
|
|
5
|
-
tabletL: 1366,
|
|
6
|
-
tabletM: 1280,
|
|
7
|
-
tabletS: 1024,
|
|
8
|
-
mobileL: 768,
|
|
9
|
-
mobileM: 560,
|
|
10
|
-
mobileS: 480,
|
|
11
|
-
mobileXS: 375
|
|
12
|
-
};
|
|
13
|
-
const devices = {
|
|
14
|
-
screenXXL: [2560, 1440],
|
|
15
|
-
screenXL: [2240, 1260],
|
|
16
|
-
screenL: [1920, 1024],
|
|
17
|
-
screenM: [1680, 1024],
|
|
18
|
-
screenS: [1440, 720],
|
|
19
|
-
tabletL: [1366, 926],
|
|
20
|
-
tabletM: [1280, 768],
|
|
21
|
-
tabletS: [1024, 768],
|
|
22
|
-
mobileL: [768, 375],
|
|
23
|
-
mobileM: [560, 768],
|
|
24
|
-
mobileS: [480, 768],
|
|
25
|
-
mobileXS: [375, 768]
|
|
26
|
-
};
|
|
27
|
-
export {
|
|
28
|
-
breakpoints,
|
|
29
|
-
devices
|
|
30
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const sequence = {
|
|
2
|
-
"minor-second": 1.067,
|
|
3
|
-
"major-second": 1.125,
|
|
4
|
-
"minor-third": 1.2,
|
|
5
|
-
"major-third": 1.25,
|
|
6
|
-
"perfect-fourth": 1.333,
|
|
7
|
-
"augmented-fourth": 1.414,
|
|
8
|
-
"perfect-fifth": 1.5,
|
|
9
|
-
"minor-sixth": 1.6,
|
|
10
|
-
phi: 1.618,
|
|
11
|
-
// golden-ratio
|
|
12
|
-
"major-sixth": 1.667,
|
|
13
|
-
"square-root-3": 1.732,
|
|
14
|
-
// theodorus
|
|
15
|
-
"minor-seventh": 1.778,
|
|
16
|
-
"major-seventh": 1.875,
|
|
17
|
-
octave: 2,
|
|
18
|
-
"square-root-5": 2.23,
|
|
19
|
-
// pythagoras
|
|
20
|
-
"major-tenth": 2.5,
|
|
21
|
-
"major-eleventh": 2.667,
|
|
22
|
-
"major-twelfth": 3,
|
|
23
|
-
pi: 3.14,
|
|
24
|
-
// archimedes
|
|
25
|
-
"double-octave": 4
|
|
26
|
-
};
|
|
27
|
-
export {
|
|
28
|
-
sequence
|
|
29
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { sequence } from "./sequence.js";
|
|
2
|
-
import { typography } from "./typography.js";
|
|
3
|
-
const defaultProps = {
|
|
4
|
-
base: typography.base,
|
|
5
|
-
type: "spacing",
|
|
6
|
-
ratio: sequence.phi,
|
|
7
|
-
range: [-5, 15],
|
|
8
|
-
subSequence: true,
|
|
9
|
-
mediaRegenerate: false,
|
|
10
|
-
unit: "em",
|
|
11
|
-
sequence: {},
|
|
12
|
-
scales: {},
|
|
13
|
-
vars: {}
|
|
14
|
-
};
|
|
15
|
-
const spacing = defaultProps;
|
|
16
|
-
export {
|
|
17
|
-
spacing
|
|
18
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const themeA = {
|
|
2
|
-
// eslint-disable-line no-unused-vars
|
|
3
|
-
text: "blue",
|
|
4
|
-
background: "white",
|
|
5
|
-
border: "black",
|
|
6
|
-
// .opacity(0.2),
|
|
7
|
-
active: {},
|
|
8
|
-
helpers: [],
|
|
9
|
-
themes: {},
|
|
10
|
-
inverse: {}
|
|
11
|
-
// schemeAInverse
|
|
12
|
-
};
|
|
13
|
-
const theme = {};
|
|
14
|
-
export {
|
|
15
|
-
theme
|
|
16
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { sequence } from "./sequence.js";
|
|
2
|
-
const defaultProps = {
|
|
3
|
-
default: 150,
|
|
4
|
-
base: 150,
|
|
5
|
-
type: "timing",
|
|
6
|
-
ratio: sequence["perfect-fourth"],
|
|
7
|
-
range: [-3, 12],
|
|
8
|
-
mediaRegenerate: false,
|
|
9
|
-
unit: "ms",
|
|
10
|
-
sequence: {},
|
|
11
|
-
scales: {},
|
|
12
|
-
vars: {}
|
|
13
|
-
};
|
|
14
|
-
const timing = defaultProps;
|
|
15
|
-
export {
|
|
16
|
-
timing
|
|
17
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { sequence } from "./sequence.js";
|
|
2
|
-
const defaultProps = {
|
|
3
|
-
browserDefault: 16,
|
|
4
|
-
base: 16,
|
|
5
|
-
type: "font-size",
|
|
6
|
-
ratio: sequence["minor-third"],
|
|
7
|
-
range: [-3, 12],
|
|
8
|
-
h1Matches: 6,
|
|
9
|
-
lineHeight: 1.5,
|
|
10
|
-
subSequence: true,
|
|
11
|
-
mediaRegenerate: false,
|
|
12
|
-
unit: "em",
|
|
13
|
-
templates: {},
|
|
14
|
-
sequence: {},
|
|
15
|
-
scales: {},
|
|
16
|
-
vars: {}
|
|
17
|
-
};
|
|
18
|
-
const typography = defaultProps;
|
|
19
|
-
export {
|
|
20
|
-
typography
|
|
21
|
-
};
|
package/dist/esm/factory.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
deepClone,
|
|
3
|
-
deepMerge,
|
|
4
|
-
isDefined,
|
|
5
|
-
isObject
|
|
6
|
-
} from "@symbo.ls/utils";
|
|
7
|
-
import * as CONF from "./defaultConfig/index.js";
|
|
8
|
-
const cssVars = {};
|
|
9
|
-
const cssMediaVars = {};
|
|
10
|
-
const _CONF = CONF;
|
|
11
|
-
const _confLower = {};
|
|
12
|
-
const toCamel = (s) => s.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
13
|
-
for (const key in _CONF) {
|
|
14
|
-
const lower = key.toLowerCase();
|
|
15
|
-
_confLower[lower] = _CONF[key];
|
|
16
|
-
const camel = toCamel(lower);
|
|
17
|
-
if (camel !== lower) _confLower[camel] = _CONF[key];
|
|
18
|
-
if (lower !== key) _confLower[key] = _CONF[key];
|
|
19
|
-
}
|
|
20
|
-
const CONFIG = {
|
|
21
|
-
verbose: false,
|
|
22
|
-
useVariable: true,
|
|
23
|
-
useReset: true,
|
|
24
|
-
globalTheme: "auto",
|
|
25
|
-
cssVars,
|
|
26
|
-
cssMediaVars,
|
|
27
|
-
CSS_VARS: cssVars,
|
|
28
|
-
CSS_MEDIA_VARS: cssMediaVars,
|
|
29
|
-
_scratchConfig: true,
|
|
30
|
-
..._confLower
|
|
31
|
-
};
|
|
32
|
-
const cachedConfig = deepClone(CONFIG);
|
|
33
|
-
const FACTORY = {
|
|
34
|
-
active: "0",
|
|
35
|
-
0: CONFIG
|
|
36
|
-
};
|
|
37
|
-
const activateConfig = (def) => {
|
|
38
|
-
if (isDefined(def)) {
|
|
39
|
-
FACTORY.active = def;
|
|
40
|
-
}
|
|
41
|
-
return FACTORY[def || FACTORY.active];
|
|
42
|
-
};
|
|
43
|
-
const configStack = [];
|
|
44
|
-
const pushConfig = (config) => {
|
|
45
|
-
if (config && config._scratchConfig) configStack.push(config);
|
|
46
|
-
};
|
|
47
|
-
const popConfig = () => {
|
|
48
|
-
configStack.pop();
|
|
49
|
-
};
|
|
50
|
-
const getActiveConfig = (def) => {
|
|
51
|
-
if (configStack.length) return configStack[configStack.length - 1];
|
|
52
|
-
return FACTORY[def || FACTORY.active] || CONFIG;
|
|
53
|
-
};
|
|
54
|
-
const setActiveConfig = (newConfig) => {
|
|
55
|
-
if (!isObject(newConfig)) return;
|
|
56
|
-
FACTORY.active = "1";
|
|
57
|
-
FACTORY["1"] = deepMerge(newConfig, deepClone(cachedConfig));
|
|
58
|
-
return newConfig;
|
|
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
|
-
};
|
|
108
|
-
export {
|
|
109
|
-
CONFIG,
|
|
110
|
-
FACTORY,
|
|
111
|
-
activateConfig,
|
|
112
|
-
createConfig,
|
|
113
|
-
cssMediaVars,
|
|
114
|
-
cssVars,
|
|
115
|
-
getActiveConfig,
|
|
116
|
-
popConfig,
|
|
117
|
-
pushConfig,
|
|
118
|
-
setActiveConfig,
|
|
119
|
-
toCamel
|
|
120
|
-
};
|
package/dist/esm/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as scratchUtils from "./utils/index.js";
|
|
2
|
-
import * as scratchSystem from "./system/index.js";
|
|
3
|
-
import * as scratchDefaultConfig from "./defaultConfig/index.js";
|
|
4
|
-
export * from "./factory.js";
|
|
5
|
-
export * from "./defaultConfig/index.js";
|
|
6
|
-
export * from "./system/index.js";
|
|
7
|
-
export * from "./utils/index.js";
|
|
8
|
-
export * from "./transforms/index.js";
|
|
9
|
-
export * from "./set.js";
|
|
10
|
-
export {
|
|
11
|
-
scratchDefaultConfig,
|
|
12
|
-
scratchSystem,
|
|
13
|
-
scratchUtils
|
|
14
|
-
};
|
package/dist/esm/set.js
DELETED
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
import { FACTORY, getActiveConfig, setActiveConfig, toCamel } from "./factory.js";
|
|
2
|
-
import {
|
|
3
|
-
setColor,
|
|
4
|
-
setGradient,
|
|
5
|
-
setFont,
|
|
6
|
-
setFontFamily,
|
|
7
|
-
setTheme,
|
|
8
|
-
setSvgIcon,
|
|
9
|
-
setSVG,
|
|
10
|
-
applyTypographySequence,
|
|
11
|
-
applySpacingSequence,
|
|
12
|
-
applyReset,
|
|
13
|
-
applyTimingSequence,
|
|
14
|
-
applyDocument,
|
|
15
|
-
setShadow
|
|
16
|
-
} from "./system/index.js";
|
|
17
|
-
import { deepMerge, isObject, isArray } from "@symbo.ls/utils";
|
|
18
|
-
const setVars = (val, key) => {
|
|
19
|
-
const CONFIG = getActiveConfig();
|
|
20
|
-
const { cssVars } = CONFIG;
|
|
21
|
-
const varName = key.startsWith("--") ? key : `--${key}`;
|
|
22
|
-
cssVars[varName] = val;
|
|
23
|
-
return val;
|
|
24
|
-
};
|
|
25
|
-
const asIs = (val) => val;
|
|
26
|
-
const VALUE_TRANSFORMERS = {
|
|
27
|
-
color: setColor,
|
|
28
|
-
gradient: setGradient,
|
|
29
|
-
font: setFont,
|
|
30
|
-
fontFamily: setFontFamily,
|
|
31
|
-
fontfamily: setFontFamily,
|
|
32
|
-
theme: setTheme,
|
|
33
|
-
icons: setSvgIcon,
|
|
34
|
-
semanticIcons: asIs,
|
|
35
|
-
semanticicons: asIs,
|
|
36
|
-
svg: setSVG,
|
|
37
|
-
svgData: asIs,
|
|
38
|
-
typography: asIs,
|
|
39
|
-
shadow: setShadow,
|
|
40
|
-
spacing: asIs,
|
|
41
|
-
media: asIs,
|
|
42
|
-
grid: asIs,
|
|
43
|
-
class: asIs,
|
|
44
|
-
timing: asIs,
|
|
45
|
-
reset: asIs,
|
|
46
|
-
unit: asIs,
|
|
47
|
-
animation: asIs,
|
|
48
|
-
vars: setVars
|
|
49
|
-
};
|
|
50
|
-
const setValue = (factoryName, value, key) => {
|
|
51
|
-
const CONFIG = getActiveConfig();
|
|
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) {
|
|
57
|
-
try {
|
|
58
|
-
const result = transformer(value, key);
|
|
59
|
-
if (FACTORY2) FACTORY2[key] = result;
|
|
60
|
-
return FACTORY2;
|
|
61
|
-
} catch (error) {
|
|
62
|
-
if (CONFIG.verbose)
|
|
63
|
-
console.warn("Error setting", lowerName, "value", value, key, error);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (CONFIG.verbose)
|
|
67
|
-
console.warn("Can not find", lowerName, "method in scratch");
|
|
68
|
-
};
|
|
69
|
-
const setEach = (factoryName, props) => {
|
|
70
|
-
const CONFIG = getActiveConfig();
|
|
71
|
-
const lowerName = factoryName.toLowerCase();
|
|
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
|
-
});
|
|
77
|
-
keys.forEach((key) => {
|
|
78
|
-
try {
|
|
79
|
-
return setValue(lowerName, props[key], key);
|
|
80
|
-
} catch (error) {
|
|
81
|
-
if (CONFIG.verbose)
|
|
82
|
-
console.warn(
|
|
83
|
-
"Error setting",
|
|
84
|
-
lowerName,
|
|
85
|
-
"value",
|
|
86
|
-
props[key],
|
|
87
|
-
key,
|
|
88
|
-
error
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
return CONFIG[lowerName] || CONFIG[factoryName];
|
|
93
|
-
};
|
|
94
|
-
const changeGlobalTheme = (newTheme, targetConfig) => {
|
|
95
|
-
const CONFIG = targetConfig || getActiveConfig();
|
|
96
|
-
CONFIG.globalTheme = newTheme;
|
|
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
|
-
}
|
|
129
|
-
}
|
|
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];
|
|
133
|
-
}
|
|
134
|
-
for (const key in CONFIG.cssMediaVars) {
|
|
135
|
-
delete CONFIG.cssMediaVars[key];
|
|
136
|
-
}
|
|
137
|
-
if (targetDoc && CONFIG.cssVars) {
|
|
138
|
-
const targetSelector = CONFIG.scopeSelector || ":root";
|
|
139
|
-
const sheets = targetDoc.styleSheets;
|
|
140
|
-
for (let i = 0; i < sheets.length; i++) {
|
|
141
|
-
try {
|
|
142
|
-
const rules = sheets[i].cssRules;
|
|
143
|
-
for (let j = 0; j < rules.length; j++) {
|
|
144
|
-
if (rules[j].selectorText === targetSelector) {
|
|
145
|
-
for (const key in CONFIG.cssVars) {
|
|
146
|
-
rules[j].style.setProperty(key, CONFIG.cssVars[key]);
|
|
147
|
-
}
|
|
148
|
-
return CONFIG;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
} catch (e) {
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return CONFIG;
|
|
156
|
-
};
|
|
157
|
-
const SET_OPTIONS = {};
|
|
158
|
-
const set = (recivedConfig, options = SET_OPTIONS) => {
|
|
159
|
-
let CONFIG = options.config || getActiveConfig();
|
|
160
|
-
const {
|
|
161
|
-
version,
|
|
162
|
-
verbose,
|
|
163
|
-
useVariable,
|
|
164
|
-
useReset,
|
|
165
|
-
useSvgSprite,
|
|
166
|
-
useFontImport,
|
|
167
|
-
useIconSprite,
|
|
168
|
-
globalTheme,
|
|
169
|
-
themeRoot,
|
|
170
|
-
useDocumentTheme,
|
|
171
|
-
useDefaultConfig,
|
|
172
|
-
semanticIcons,
|
|
173
|
-
files,
|
|
174
|
-
assets,
|
|
175
|
-
...config
|
|
176
|
-
} = recivedConfig;
|
|
177
|
-
if (options.newConfig) {
|
|
178
|
-
CONFIG = setActiveConfig(options.newConfig);
|
|
179
|
-
}
|
|
180
|
-
if (files !== void 0) CONFIG.files = files;
|
|
181
|
-
if (assets !== void 0) CONFIG.assets = assets;
|
|
182
|
-
if (verbose !== void 0) CONFIG.verbose = verbose;
|
|
183
|
-
if (useVariable !== void 0) CONFIG.useVariable = useVariable;
|
|
184
|
-
if (useReset !== void 0) CONFIG.useReset = useReset;
|
|
185
|
-
if (useFontImport !== void 0) CONFIG.useFontImport = useFontImport;
|
|
186
|
-
if (useSvgSprite !== void 0) CONFIG.useSvgSprite = useSvgSprite;
|
|
187
|
-
if (useIconSprite !== void 0) CONFIG.useIconSprite = useIconSprite;
|
|
188
|
-
if (useDocumentTheme !== void 0) CONFIG.useDocumentTheme = useDocumentTheme;
|
|
189
|
-
if (globalTheme !== void 0) CONFIG.globalTheme = globalTheme;
|
|
190
|
-
if (themeRoot !== void 0) CONFIG.themeRoot = themeRoot;
|
|
191
|
-
if (recivedConfig.useThemeSuffixedVars !== void 0)
|
|
192
|
-
CONFIG.useThemeSuffixedVars = recivedConfig.useThemeSuffixedVars;
|
|
193
|
-
if (useDefaultConfig !== void 0) CONFIG.useDefaultConfig = useDefaultConfig;
|
|
194
|
-
if (semanticIcons !== void 0) CONFIG.semanticIcons = semanticIcons;
|
|
195
|
-
if (CONFIG.verbose) console.log(CONFIG);
|
|
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
|
-
}
|
|
228
|
-
}
|
|
229
|
-
if (!CONFIG.__svgCache) CONFIG.__svgCache = {};
|
|
230
|
-
const keys = Object.keys(config);
|
|
231
|
-
const keySet = new Set(keys);
|
|
232
|
-
keys.forEach((key) => {
|
|
233
|
-
const lower = key.toLowerCase();
|
|
234
|
-
if (lower !== key && keySet.has(lower)) {
|
|
235
|
-
deepMerge(config[lower], config[key]);
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
keys.map((key) => {
|
|
239
|
-
const lower = key.toLowerCase();
|
|
240
|
-
if (lower !== key && keySet.has(lower)) return;
|
|
241
|
-
return setEach(key, config[key]);
|
|
242
|
-
});
|
|
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) {
|
|
249
|
-
try {
|
|
250
|
-
applyTypographySequence();
|
|
251
|
-
} catch (e) {
|
|
252
|
-
if (CONFIG.verbose) console.warn("Error applying typography sequence", e);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
if (config.spacing) {
|
|
256
|
-
try {
|
|
257
|
-
applySpacingSequence();
|
|
258
|
-
} catch (e) {
|
|
259
|
-
if (CONFIG.verbose) console.warn("Error applying spacing sequence", e);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
if (config.timing) {
|
|
263
|
-
try {
|
|
264
|
-
applyTimingSequence();
|
|
265
|
-
} catch (e) {
|
|
266
|
-
if (CONFIG.verbose) console.warn("Error applying timing sequence", e);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
applyDocument();
|
|
270
|
-
const computedReset = applyReset();
|
|
271
|
-
if (computedReset) CONFIG.reset = computedReset;
|
|
272
|
-
return CONFIG;
|
|
273
|
-
};
|
|
274
|
-
export {
|
|
275
|
-
VALUE_TRANSFORMERS,
|
|
276
|
-
changeGlobalTheme,
|
|
277
|
-
set,
|
|
278
|
-
setEach,
|
|
279
|
-
setValue
|
|
280
|
-
};
|