@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,121 @@
|
|
|
1
|
+
import { arrayzeValue } from "@symbo.ls/smbls-utils";
|
|
2
|
+
import { isArray, isString, merge } from "@domql/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";
|
|
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 } = CONFIG;
|
|
44
|
+
generateSequence(SPACING);
|
|
45
|
+
applySequenceVars(SPACING);
|
|
46
|
+
runThroughMedia(SPACING);
|
|
47
|
+
};
|
|
48
|
+
const getSequence = (sequenceProps) => {
|
|
49
|
+
const CONFIG = getActiveConfig();
|
|
50
|
+
const { 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 } = 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
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { document } from "@domql/utils";
|
|
2
|
+
import { generateSprite, convertSvgToSymbol } from "../utils";
|
|
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] = CONFIG.SVG[key];
|
|
22
|
+
appendSVG(lib, options);
|
|
23
|
+
};
|
|
24
|
+
const setSvgIcon = (val, key) => {
|
|
25
|
+
const CONFIG = getActiveConfig();
|
|
26
|
+
if (CONFIG.useIconSprite && !CONFIG.SEMANTIC_ICONS?.[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] = CONFIG.ICONS[key];
|
|
35
|
+
appendSVG(lib, options);
|
|
36
|
+
};
|
|
37
|
+
const createSVGSpriteElement = (options = { isRoot: true }) => {
|
|
38
|
+
if (!document || !document.createElementNS) return;
|
|
39
|
+
const svgElem = document.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 appendSVG = (lib, options = DEF_OPTIONS) => {
|
|
50
|
+
const CONFIG = getActiveConfig();
|
|
51
|
+
const doc = options.document || document;
|
|
52
|
+
if (!doc || !doc.documentElement) {
|
|
53
|
+
if (CONFIG.verbose) {
|
|
54
|
+
console.warn("To append SVG sprites it should be run in browser environment");
|
|
55
|
+
}
|
|
56
|
+
return generateSprite(lib);
|
|
57
|
+
}
|
|
58
|
+
const exists = doc.querySelector("#svgSprite");
|
|
59
|
+
const SVGsprite = generateSprite(lib);
|
|
60
|
+
if (exists) {
|
|
61
|
+
const tempSVG = createSVGSpriteElement({ isRoot: false });
|
|
62
|
+
tempSVG.innerHTML = SVGsprite;
|
|
63
|
+
exists.append(...tempSVG.children);
|
|
64
|
+
} else {
|
|
65
|
+
const svgSpriteDOM = createSVGSpriteElement();
|
|
66
|
+
if (svgSpriteDOM && svgSpriteDOM.nodeType) {
|
|
67
|
+
svgSpriteDOM.innerHTML = SVGsprite;
|
|
68
|
+
doc.body.prepend(svgSpriteDOM);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
export {
|
|
73
|
+
appendSVGSprite,
|
|
74
|
+
appendSvgIconsSprite,
|
|
75
|
+
setSVG,
|
|
76
|
+
setSvgIcon
|
|
77
|
+
};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { getColor } from "./color";
|
|
2
|
+
import { getActiveConfig } from "../factory.js";
|
|
3
|
+
import { isCSSVar } from "../utils/color.js";
|
|
4
|
+
import {
|
|
5
|
+
isObject,
|
|
6
|
+
isString,
|
|
7
|
+
isObjectLike,
|
|
8
|
+
isArray
|
|
9
|
+
} from "@domql/utils";
|
|
10
|
+
const setThemeValue = (theme) => {
|
|
11
|
+
const value = {};
|
|
12
|
+
const { state, media, helpers, ...rest } = theme;
|
|
13
|
+
const keys = Object.keys(rest);
|
|
14
|
+
keys.map((key) => {
|
|
15
|
+
const conditions = ["color", "Color", "background", "border"];
|
|
16
|
+
const isColor = conditions.some((k) => key.includes(k));
|
|
17
|
+
return value[key] = isColor ? getColor(theme[key]) : theme[key];
|
|
18
|
+
});
|
|
19
|
+
return value;
|
|
20
|
+
};
|
|
21
|
+
const getThemeValue = (theme) => {
|
|
22
|
+
if (theme.value) return theme.value;
|
|
23
|
+
theme.value = setThemeValue(theme);
|
|
24
|
+
return theme.value;
|
|
25
|
+
};
|
|
26
|
+
const getTheme = (value, modifier) => {
|
|
27
|
+
const CONFIG = getActiveConfig();
|
|
28
|
+
if (CONFIG.useVariable) return getMediaTheme(value, modifier);
|
|
29
|
+
const { THEME } = CONFIG;
|
|
30
|
+
if (isString(value)) {
|
|
31
|
+
const [theme, subtheme] = value.split(" ");
|
|
32
|
+
const isOurTheme = THEME[theme];
|
|
33
|
+
if (isOurTheme) {
|
|
34
|
+
if (!subtheme && !modifier) return getThemeValue(isOurTheme);
|
|
35
|
+
value = [theme, subtheme || modifier];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (isObjectLike(value) && value[1]) {
|
|
39
|
+
const themeName = value[0];
|
|
40
|
+
const subThemeName = value[1];
|
|
41
|
+
const { helpers, media, state } = THEME[themeName];
|
|
42
|
+
if (media && media[subThemeName]) return getThemeValue(media[subThemeName]);
|
|
43
|
+
if (helpers && helpers[subThemeName]) return getThemeValue(helpers[subThemeName]);
|
|
44
|
+
if (state && state[subThemeName]) return getThemeValue(state[subThemeName]);
|
|
45
|
+
} else if (isObject(value)) return setThemeValue(value);
|
|
46
|
+
};
|
|
47
|
+
const setInverseTheme = (theme, variant, value) => {
|
|
48
|
+
if (isObject(variant)) {
|
|
49
|
+
theme.variants.inverse.value = setThemeValue(variant);
|
|
50
|
+
} else if (variant === true) {
|
|
51
|
+
const { color, background } = value;
|
|
52
|
+
theme.variants.inverse = {
|
|
53
|
+
value: {
|
|
54
|
+
color: background,
|
|
55
|
+
background: color
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const setPseudo = (theme, key, variant, themeValue) => {
|
|
61
|
+
const result = getTheme(variant);
|
|
62
|
+
themeValue[`&:${key}`] = result;
|
|
63
|
+
if (isObject(variant) && !variant.value) variant.value = result;
|
|
64
|
+
};
|
|
65
|
+
const setSelectors = (theme, value) => {
|
|
66
|
+
const { state } = theme;
|
|
67
|
+
if (!state) return;
|
|
68
|
+
const keys = Object.keys(state);
|
|
69
|
+
keys.map((key) => {
|
|
70
|
+
const variant = state[key];
|
|
71
|
+
setPseudo(theme, key, variant, value);
|
|
72
|
+
return theme;
|
|
73
|
+
});
|
|
74
|
+
return theme;
|
|
75
|
+
};
|
|
76
|
+
const setPrefersScheme = (theme, key, variant, themeValue) => {
|
|
77
|
+
const result = getTheme(variant);
|
|
78
|
+
themeValue[`@media (prefers-color-scheme: ${key})`] = result;
|
|
79
|
+
if (isObject(variant) && !variant.value) variant.value = result;
|
|
80
|
+
};
|
|
81
|
+
const setMedia = (theme, value) => {
|
|
82
|
+
const { media } = theme;
|
|
83
|
+
if (!media) return;
|
|
84
|
+
const keys = Object.keys(media);
|
|
85
|
+
keys.map((key) => {
|
|
86
|
+
const variant = media[key];
|
|
87
|
+
if (key === "dark" || key === "light") setPrefersScheme(theme, key, variant, value);
|
|
88
|
+
if (key === "inverse") setInverseTheme(theme, variant, value);
|
|
89
|
+
return theme;
|
|
90
|
+
});
|
|
91
|
+
return theme;
|
|
92
|
+
};
|
|
93
|
+
const setHelpers = (theme, value) => {
|
|
94
|
+
const CONFIG = getActiveConfig();
|
|
95
|
+
const { helpers } = theme;
|
|
96
|
+
if (!helpers) return;
|
|
97
|
+
const keys = Object.keys(helpers);
|
|
98
|
+
keys.map((key) => {
|
|
99
|
+
const helper = helpers[key];
|
|
100
|
+
if (isString(helper)) helpers[key] = CONFIG.THEME[helper];
|
|
101
|
+
else getThemeValue(helpers[key]);
|
|
102
|
+
return theme;
|
|
103
|
+
});
|
|
104
|
+
return theme;
|
|
105
|
+
};
|
|
106
|
+
const setTheme = (val, key) => {
|
|
107
|
+
const CONFIG = getActiveConfig();
|
|
108
|
+
if (CONFIG.useVariable) return setMediaTheme(val, key);
|
|
109
|
+
const { state, media, helpers } = val;
|
|
110
|
+
const value = setThemeValue(val, key);
|
|
111
|
+
const CSSvar = `--theme-${key}`;
|
|
112
|
+
setSelectors(val, value);
|
|
113
|
+
setMedia(val, value);
|
|
114
|
+
setHelpers(val, value);
|
|
115
|
+
return { var: CSSvar, value, state, media, helpers };
|
|
116
|
+
};
|
|
117
|
+
const keySetters = {
|
|
118
|
+
// eslint-disable-line
|
|
119
|
+
"@": (theme, value) => setMedia(theme, value),
|
|
120
|
+
":": (theme, value) => setSelectors(theme, value),
|
|
121
|
+
".": (theme, value) => setHelpers(theme, value)
|
|
122
|
+
};
|
|
123
|
+
const setMediaTheme = (val, key, suffix, prefers) => {
|
|
124
|
+
const CONFIG = getActiveConfig();
|
|
125
|
+
const { CSS_VARS } = CONFIG;
|
|
126
|
+
const theme = { value: val };
|
|
127
|
+
if (isObjectLike(val)) {
|
|
128
|
+
for (const param in val) {
|
|
129
|
+
const symb = param.slice(0, 1);
|
|
130
|
+
const value = val[param];
|
|
131
|
+
if (symb === "@" || symb === ":" || symb === ".") {
|
|
132
|
+
const hasPrefers = symb === "@" && param;
|
|
133
|
+
theme[param] = setMediaTheme(value, key, param, prefers || hasPrefers);
|
|
134
|
+
} else {
|
|
135
|
+
const color = getColor(value, prefers);
|
|
136
|
+
const metaSuffixes = [...new Set([prefers, suffix].filter((v) => v).map((v) => v.slice(1)))];
|
|
137
|
+
const varmetaSuffixName = metaSuffixes.length ? "-" + metaSuffixes.join("-") : "";
|
|
138
|
+
const CSSVar = `--theme-${key}${varmetaSuffixName}-${param}`;
|
|
139
|
+
if (CONFIG.useVariable) {
|
|
140
|
+
CSS_VARS[CSSVar] = color;
|
|
141
|
+
theme[param] = `var(${CSSVar})`;
|
|
142
|
+
} else {
|
|
143
|
+
theme[param] = color;
|
|
144
|
+
}
|
|
145
|
+
theme[`.${param}`] = { [param]: theme[param] };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (theme.background || theme.color || theme.backgroundColor) {
|
|
149
|
+
theme[".inversed"] = {
|
|
150
|
+
color: theme.background || theme.backgroundColor,
|
|
151
|
+
background: theme.color
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (isString(val) && isCSSVar(val)) {
|
|
156
|
+
const { THEME } = CONFIG;
|
|
157
|
+
const value = THEME[val.slice(2)];
|
|
158
|
+
const getReferenced = getMediaTheme(value, prefers);
|
|
159
|
+
return getReferenced;
|
|
160
|
+
}
|
|
161
|
+
return theme;
|
|
162
|
+
};
|
|
163
|
+
const recursiveTheme = (val) => {
|
|
164
|
+
const CONFIG = getActiveConfig();
|
|
165
|
+
const obj = {};
|
|
166
|
+
for (const param in val) {
|
|
167
|
+
const symb = param.slice(0, 1);
|
|
168
|
+
if (isObjectLike(val[param])) {
|
|
169
|
+
if (symb === "@") {
|
|
170
|
+
const query = CONFIG.MEDIA[param.slice(1)];
|
|
171
|
+
const media = "@media " + (query === "print" ? `${query}` : `screen and ${query}`);
|
|
172
|
+
obj[media] = recursiveTheme(val[param]);
|
|
173
|
+
} else if (symb === ":") {
|
|
174
|
+
obj[`&${param}`] = recursiveTheme(val[param]);
|
|
175
|
+
}
|
|
176
|
+
} else obj[param] = val[param];
|
|
177
|
+
}
|
|
178
|
+
return obj;
|
|
179
|
+
};
|
|
180
|
+
const findModifierFromArray = (val, modifierArray) => {
|
|
181
|
+
const currentMod = modifierArray.shift();
|
|
182
|
+
if (val[currentMod]) return findModifierFromArray(val[currentMod], modifierArray);
|
|
183
|
+
return val;
|
|
184
|
+
};
|
|
185
|
+
const findModifier = (val, modifier) => {
|
|
186
|
+
if (isArray(modifier)) return findModifierFromArray(val, modifier);
|
|
187
|
+
else if (isString(modifier) && val[modifier]) return val[modifier];
|
|
188
|
+
else return val;
|
|
189
|
+
};
|
|
190
|
+
const checkForReference = (val, callback) => {
|
|
191
|
+
if (isString(val) && isCSSVar(val)) return getMediaTheme(val.slice(2));
|
|
192
|
+
return val;
|
|
193
|
+
};
|
|
194
|
+
const checkThemeReference = (val) => checkForReference(val, checkThemeReference);
|
|
195
|
+
const getMediaTheme = (value, modifier) => {
|
|
196
|
+
const activeConfig = getActiveConfig();
|
|
197
|
+
if (isString(value) && isCSSVar(value)) {
|
|
198
|
+
value = getMediaTheme(value.slice(2));
|
|
199
|
+
}
|
|
200
|
+
if (!value || !isString(value)) {
|
|
201
|
+
if (activeConfig.verbose) {
|
|
202
|
+
console.warn(`${value} - Theme is not a string`);
|
|
203
|
+
}
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const [themeName, ...themeModifiers] = isArray(value) ? value : value.split(" ");
|
|
207
|
+
let themeValue = activeConfig.THEME[themeName];
|
|
208
|
+
if (themeValue && (themeModifiers || modifier)) {
|
|
209
|
+
themeValue = findModifier(themeValue, themeModifiers.length ? themeModifiers : modifier);
|
|
210
|
+
}
|
|
211
|
+
const resolvedTheme = recursiveTheme(themeValue);
|
|
212
|
+
return resolvedTheme;
|
|
213
|
+
};
|
|
214
|
+
export {
|
|
215
|
+
getMediaTheme,
|
|
216
|
+
getTheme,
|
|
217
|
+
setMediaTheme,
|
|
218
|
+
setTheme
|
|
219
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { toCamelCase } from "@symbo.ls/smbls-utils";
|
|
2
|
+
import { getActiveConfig } from "../factory.js";
|
|
3
|
+
import {
|
|
4
|
+
applySequenceVars,
|
|
5
|
+
generateSequence,
|
|
6
|
+
getSequenceValuePropertyPair
|
|
7
|
+
} from "../utils";
|
|
8
|
+
const applyTimingSequence = () => {
|
|
9
|
+
const CONFIG = getActiveConfig();
|
|
10
|
+
const { TIMING } = CONFIG;
|
|
11
|
+
generateSequence(TIMING);
|
|
12
|
+
applySequenceVars(TIMING);
|
|
13
|
+
};
|
|
14
|
+
const getTimingFunction = (value) => {
|
|
15
|
+
const CONFIG = getActiveConfig();
|
|
16
|
+
const { TIMING } = CONFIG;
|
|
17
|
+
return TIMING[value] || TIMING[toCamelCase(value)] || value;
|
|
18
|
+
};
|
|
19
|
+
const getTimingByKey = (value, property = "timing") => {
|
|
20
|
+
const CONFIG = getActiveConfig();
|
|
21
|
+
const { TIMING } = CONFIG;
|
|
22
|
+
return getSequenceValuePropertyPair(
|
|
23
|
+
value,
|
|
24
|
+
property,
|
|
25
|
+
TIMING
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
export {
|
|
29
|
+
applyTimingSequence,
|
|
30
|
+
getTimingByKey,
|
|
31
|
+
getTimingFunction
|
|
32
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { merge } from "@domql/utils";
|
|
2
|
+
import { getActiveConfig } from "../factory.js";
|
|
3
|
+
import {
|
|
4
|
+
applyMediaSequenceVars,
|
|
5
|
+
applySequenceVars,
|
|
6
|
+
findHeadings,
|
|
7
|
+
generateSequence,
|
|
8
|
+
getSequenceValuePropertyPair
|
|
9
|
+
} from "../utils";
|
|
10
|
+
const runThroughMedia = (FACTORY) => {
|
|
11
|
+
const CONFIG = getActiveConfig();
|
|
12
|
+
const { TYPOGRAPHY, MEDIA } = CONFIG;
|
|
13
|
+
for (const prop in FACTORY) {
|
|
14
|
+
const isPropMedia = prop.slice(0, 1) === "@";
|
|
15
|
+
const mediaValue = FACTORY[prop];
|
|
16
|
+
if (!isPropMedia) continue;
|
|
17
|
+
const { mediaRegenerate } = FACTORY;
|
|
18
|
+
const mediaName = prop.slice(1);
|
|
19
|
+
const { type, base, ratio, range, subSequence, h1Matches, unit } = FACTORY;
|
|
20
|
+
merge(mediaValue, {
|
|
21
|
+
type,
|
|
22
|
+
base,
|
|
23
|
+
ratio,
|
|
24
|
+
range,
|
|
25
|
+
subSequence,
|
|
26
|
+
h1Matches,
|
|
27
|
+
unit
|
|
28
|
+
});
|
|
29
|
+
const query = MEDIA[mediaName];
|
|
30
|
+
const media = "@media " + (query === "print" ? `${query}` : `screen and ${query}`);
|
|
31
|
+
TYPOGRAPHY.templates[media] = {
|
|
32
|
+
fontSize: mediaValue.base / TYPOGRAPHY.browserDefault + unit
|
|
33
|
+
};
|
|
34
|
+
if (!mediaRegenerate) {
|
|
35
|
+
applyMediaSequenceVars(FACTORY, prop);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
merge(mediaValue, {
|
|
39
|
+
sequence: {},
|
|
40
|
+
scales: {},
|
|
41
|
+
templates: {},
|
|
42
|
+
vars: {}
|
|
43
|
+
});
|
|
44
|
+
generateSequence(mediaValue);
|
|
45
|
+
applyMediaSequenceVars(FACTORY, prop);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const applyHeadings = (props) => {
|
|
49
|
+
const CONFIG = getActiveConfig();
|
|
50
|
+
if (props.h1Matches) {
|
|
51
|
+
const unit = props.unit;
|
|
52
|
+
const HEADINGS = findHeadings(props);
|
|
53
|
+
const { templates } = props;
|
|
54
|
+
for (const k in HEADINGS) {
|
|
55
|
+
const headerName = `h${parseInt(k) + 1}`;
|
|
56
|
+
const headerStyle = templates[headerName];
|
|
57
|
+
templates[headerName] = {
|
|
58
|
+
fontSize: CONFIG.useVariable ? `var(${HEADINGS[k]?.variable})` : `${HEADINGS[k]?.scaling}${unit}`,
|
|
59
|
+
margin: headerStyle ? headerStyle.margin : 0,
|
|
60
|
+
lineHeight: headerStyle ? headerStyle.lineHeight : props.lineHeight,
|
|
61
|
+
letterSpacing: headerStyle ? headerStyle.letterSpacing : props.letterSpacing,
|
|
62
|
+
fontWeight: headerStyle ? headerStyle.fontWeight : 900 - k * 100
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const applyTypographySequence = () => {
|
|
68
|
+
const CONFIG = getActiveConfig();
|
|
69
|
+
const { TYPOGRAPHY } = CONFIG;
|
|
70
|
+
generateSequence(TYPOGRAPHY);
|
|
71
|
+
applyHeadings(TYPOGRAPHY);
|
|
72
|
+
applySequenceVars(TYPOGRAPHY);
|
|
73
|
+
runThroughMedia(TYPOGRAPHY);
|
|
74
|
+
};
|
|
75
|
+
const getFontSizeByKey = (value) => {
|
|
76
|
+
const CONFIG = getActiveConfig();
|
|
77
|
+
const { TYPOGRAPHY } = CONFIG;
|
|
78
|
+
return getSequenceValuePropertyPair(value, "fontSize", TYPOGRAPHY);
|
|
79
|
+
};
|
|
80
|
+
export {
|
|
81
|
+
applyHeadings,
|
|
82
|
+
applyTypographySequence,
|
|
83
|
+
getFontSizeByKey,
|
|
84
|
+
runThroughMedia
|
|
85
|
+
};
|