@symbo.ls/scratch 2.10.149 → 2.10.156

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.
Files changed (82) hide show
  1. package/dist/cjs/defaultConfig/animation.js +24 -0
  2. package/dist/cjs/defaultConfig/cases.js +24 -0
  3. package/dist/cjs/defaultConfig/color.js +32 -0
  4. package/dist/cjs/defaultConfig/document.js +24 -0
  5. package/dist/cjs/defaultConfig/font-family.js +39 -0
  6. package/dist/cjs/defaultConfig/font.js +33 -0
  7. package/dist/cjs/defaultConfig/icons.js +24 -0
  8. package/dist/cjs/defaultConfig/index.js +41 -0
  9. package/dist/cjs/defaultConfig/media.js +39 -0
  10. package/dist/cjs/defaultConfig/responsive.js +48 -0
  11. package/dist/cjs/defaultConfig/sequence.js +49 -0
  12. package/dist/cjs/defaultConfig/spacing.js +36 -0
  13. package/dist/cjs/defaultConfig/svg.js +26 -0
  14. package/dist/cjs/defaultConfig/theme.js +36 -0
  15. package/dist/cjs/defaultConfig/timing.js +36 -0
  16. package/dist/cjs/defaultConfig/typography.js +39 -0
  17. package/dist/cjs/defaultConfig/unit.js +26 -0
  18. package/dist/cjs/factory.js +69 -0
  19. package/dist/cjs/index.js +21 -0
  20. package/dist/cjs/package.json +4 -0
  21. package/dist/cjs/set.js +121 -0
  22. package/dist/cjs/system/color.js +169 -0
  23. package/dist/cjs/system/document.js +35 -0
  24. package/dist/cjs/system/font.js +50 -0
  25. package/dist/cjs/system/index.js +26 -0
  26. package/dist/cjs/system/reset.js +83 -0
  27. package/dist/cjs/system/spacing.js +129 -0
  28. package/dist/cjs/system/svg.js +81 -0
  29. package/dist/cjs/system/theme.js +255 -0
  30. package/dist/cjs/system/timing.js +48 -0
  31. package/dist/cjs/system/typography.js +94 -0
  32. package/dist/cjs/tests/index.js +28 -0
  33. package/dist/cjs/utils/color.js +163 -0
  34. package/dist/cjs/utils/font.js +70 -0
  35. package/dist/cjs/utils/index.js +23 -0
  36. package/dist/cjs/utils/object.js +73 -0
  37. package/dist/cjs/utils/sequence.js +199 -0
  38. package/dist/cjs/utils/sprite.js +63 -0
  39. package/dist/cjs/utils/theme.js +32 -0
  40. package/dist/cjs/utils/var.js +64 -0
  41. package/dist/esm/defaultConfig/animation.js +4 -0
  42. package/dist/esm/defaultConfig/cases.js +4 -0
  43. package/dist/esm/defaultConfig/color.js +12 -0
  44. package/dist/esm/defaultConfig/document.js +4 -0
  45. package/dist/esm/defaultConfig/font-family.js +19 -0
  46. package/dist/esm/defaultConfig/font.js +13 -0
  47. package/dist/esm/defaultConfig/icons.js +4 -0
  48. package/dist/esm/defaultConfig/index.js +20 -0
  49. package/dist/esm/defaultConfig/media.js +19 -0
  50. package/dist/esm/defaultConfig/responsive.js +28 -0
  51. package/dist/esm/defaultConfig/sequence.js +29 -0
  52. package/dist/esm/defaultConfig/spacing.js +16 -0
  53. package/dist/esm/defaultConfig/svg.js +6 -0
  54. package/dist/esm/defaultConfig/theme.js +16 -0
  55. package/dist/esm/defaultConfig/timing.js +16 -0
  56. package/dist/esm/defaultConfig/typography.js +19 -0
  57. package/dist/esm/defaultConfig/unit.js +6 -0
  58. package/dist/esm/factory.js +39 -0
  59. package/dist/esm/index.js +4 -0
  60. package/dist/esm/set.js +113 -0
  61. package/dist/esm/system/color.js +156 -0
  62. package/dist/esm/system/document.js +15 -0
  63. package/dist/esm/system/font.js +35 -0
  64. package/dist/esm/system/index.js +9 -0
  65. package/dist/esm/system/reset.js +63 -0
  66. package/dist/esm/system/spacing.js +115 -0
  67. package/dist/esm/system/svg.js +61 -0
  68. package/dist/esm/system/theme.js +240 -0
  69. package/dist/esm/system/timing.js +32 -0
  70. package/dist/esm/system/typography.js +80 -0
  71. package/dist/esm/tests/index.js +8 -0
  72. package/dist/esm/utils/color.js +143 -0
  73. package/dist/esm/utils/font.js +50 -0
  74. package/dist/esm/utils/index.js +6 -0
  75. package/dist/esm/utils/object.js +53 -0
  76. package/dist/esm/utils/sequence.js +179 -0
  77. package/dist/esm/utils/sprite.js +43 -0
  78. package/dist/esm/utils/theme.js +12 -0
  79. package/dist/esm/utils/var.js +44 -0
  80. package/package.json +15 -15
  81. package/dist/index.cjs.js +0 -2389
  82. package/dist/index.cjs.js.map +0 -7
@@ -0,0 +1,61 @@
1
+ import { document } from "@domql/globals";
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
+ if (!val) {
9
+ if (CONFIG.verbose)
10
+ console.warn("setSVG: val is not defined", key);
11
+ return;
12
+ }
13
+ const CONFIG = getActiveConfig();
14
+ if (CONFIG.useSvgSprite) {
15
+ return convertSvgToSymbol(key, val);
16
+ }
17
+ return val;
18
+ };
19
+ const appendSVGSprite = (LIBRARY, options = DEF_OPTIONS) => {
20
+ const CONFIG = getActiveConfig();
21
+ const doc = options.document || document;
22
+ const lib = Object.keys(LIBRARY).length ? {} : CONFIG.SVG;
23
+ for (let key in LIBRARY)
24
+ lib[key] = CONFIG.SVG[key];
25
+ const SVGsprite = generateSprite(lib);
26
+ if (!doc) {
27
+ console.warn("To append SVG sprites it should be run in browser environment");
28
+ return SVGsprite;
29
+ }
30
+ const svgSpriteDOM = doc.createElement("template");
31
+ svgSpriteDOM.innerHTML = SVGsprite;
32
+ doc.body.appendChild(svgSpriteDOM.content);
33
+ };
34
+ const setIcon = (val, key) => {
35
+ const CONFIG = getActiveConfig();
36
+ if (CONFIG.useIconSprite) {
37
+ return setSVG(val, key);
38
+ }
39
+ return val;
40
+ };
41
+ const appendIconsSprite = (LIBRARY, options = DEF_OPTIONS) => {
42
+ const CONFIG = getActiveConfig();
43
+ const doc = options.document || document;
44
+ const lib = Object.keys(LIBRARY).length ? {} : CONFIG.ICONS;
45
+ for (let key in LIBRARY)
46
+ lib[key] = CONFIG.ICONS[key];
47
+ const SVGsprite = generateSprite(lib);
48
+ if (!doc) {
49
+ console.warn("To append SVG Icon sprites it should be run in browser environment");
50
+ return SVGsprite;
51
+ }
52
+ const iconsSpriteDOM = doc.createElement("template");
53
+ iconsSpriteDOM.innerHTML = SVGsprite;
54
+ doc.body.appendChild(iconsSpriteDOM.content);
55
+ };
56
+ export {
57
+ appendIconsSprite,
58
+ appendSVGSprite,
59
+ setIcon,
60
+ setSVG
61
+ };
@@ -0,0 +1,240 @@
1
+ import { getColor } from "./color";
2
+ import { getActiveConfig } from "../factory.js";
3
+ import {
4
+ isObject,
5
+ isString,
6
+ isObjectLike,
7
+ isArray
8
+ } from "@domql/utils";
9
+ const ENV = "development";
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)
23
+ return theme.value;
24
+ theme.value = setThemeValue(theme);
25
+ return theme.value;
26
+ };
27
+ const getTheme = (value, modifier) => {
28
+ const CONFIG = getActiveConfig();
29
+ if (CONFIG.useVariable)
30
+ return getMediaTheme(value, modifier);
31
+ const { THEME } = CONFIG;
32
+ if (isString(value)) {
33
+ const [theme, subtheme] = value.split(" ");
34
+ const isOurTheme = THEME[theme];
35
+ if (isOurTheme) {
36
+ if (!subtheme && !modifier)
37
+ return getThemeValue(isOurTheme);
38
+ value = [theme, subtheme || modifier];
39
+ }
40
+ }
41
+ if (isObjectLike(value) && value[1]) {
42
+ const themeName = value[0];
43
+ const subThemeName = value[1];
44
+ const { helpers, media, state } = THEME[themeName];
45
+ if (media && media[subThemeName])
46
+ return getThemeValue(media[subThemeName]);
47
+ if (helpers && helpers[subThemeName])
48
+ return getThemeValue(helpers[subThemeName]);
49
+ if (state && state[subThemeName])
50
+ return getThemeValue(state[subThemeName]);
51
+ } else if (isObject(value))
52
+ return setThemeValue(value);
53
+ };
54
+ const setInverseTheme = (theme, variant, value) => {
55
+ if (isObject(variant)) {
56
+ theme.variants.inverse.value = setThemeValue(variant);
57
+ } else if (variant === true) {
58
+ const { color, background } = value;
59
+ theme.variants.inverse = {
60
+ value: {
61
+ color: background,
62
+ background: color
63
+ }
64
+ };
65
+ }
66
+ };
67
+ const setPseudo = (theme, key, variant, themeValue) => {
68
+ const result = getTheme(variant);
69
+ themeValue[`&:${key}`] = result;
70
+ if (isObject(variant) && !variant.value)
71
+ variant.value = result;
72
+ };
73
+ const setSelectors = (theme, value) => {
74
+ const { state } = theme;
75
+ if (!state)
76
+ return;
77
+ const keys = Object.keys(state);
78
+ keys.map((key) => {
79
+ const variant = state[key];
80
+ setPseudo(theme, key, variant, value);
81
+ return theme;
82
+ });
83
+ return theme;
84
+ };
85
+ const setPrefersScheme = (theme, key, variant, themeValue) => {
86
+ const result = getTheme(variant);
87
+ themeValue[`@media (prefers-color-scheme: ${key})`] = result;
88
+ if (isObject(variant) && !variant.value)
89
+ variant.value = result;
90
+ };
91
+ const setMedia = (theme, value) => {
92
+ const { media } = theme;
93
+ if (!media)
94
+ return;
95
+ const keys = Object.keys(media);
96
+ keys.map((key) => {
97
+ const variant = media[key];
98
+ if (key === "dark" || key === "light")
99
+ setPrefersScheme(theme, key, variant, value);
100
+ if (key === "inverse")
101
+ setInverseTheme(theme, variant, value);
102
+ return theme;
103
+ });
104
+ return theme;
105
+ };
106
+ const setHelpers = (theme, value) => {
107
+ const CONFIG = getActiveConfig();
108
+ const { helpers } = theme;
109
+ if (!helpers)
110
+ return;
111
+ const keys = Object.keys(helpers);
112
+ keys.map((key) => {
113
+ const helper = helpers[key];
114
+ if (isString(helper))
115
+ helpers[key] = CONFIG.THEME[helper];
116
+ else
117
+ getThemeValue(helpers[key]);
118
+ return theme;
119
+ });
120
+ return theme;
121
+ };
122
+ const setTheme = (val, key) => {
123
+ const CONFIG = getActiveConfig();
124
+ if (CONFIG.useVariable)
125
+ return setMediaTheme(val, key);
126
+ const { state, media, helpers } = val;
127
+ const value = setThemeValue(val, key);
128
+ const CSSvar = `--theme-${key}`;
129
+ setSelectors(val, value);
130
+ setMedia(val, value);
131
+ setHelpers(val, value);
132
+ return { var: CSSvar, value, state, media, helpers };
133
+ };
134
+ const keySetters = {
135
+ // eslint-disable-line
136
+ "@": (theme, value) => setMedia(theme, value),
137
+ ":": (theme, value) => setSelectors(theme, value),
138
+ ".": (theme, value) => setHelpers(theme, value)
139
+ };
140
+ const setMediaTheme = (val, key, suffix, prefers) => {
141
+ const CONFIG = getActiveConfig();
142
+ const { CSS_VARS } = CONFIG;
143
+ const theme = { value: val };
144
+ if (isObjectLike(val)) {
145
+ for (const param in val) {
146
+ const symb = param.slice(0, 1);
147
+ const value = val[param];
148
+ if (symb === "@" || symb === ":" || symb === ".") {
149
+ const hasPrefers = symb === "@" && param;
150
+ theme[param] = setMediaTheme(value, key, param, prefers || hasPrefers);
151
+ } else {
152
+ const color = getColor(value, prefers);
153
+ const metaSuffixes = [...new Set([prefers, suffix].filter((v) => v).map((v) => v.slice(1)))];
154
+ const varmetaSuffixName = metaSuffixes.length ? "-" + metaSuffixes.join("-") : "";
155
+ const CSSVar = `--theme-${key}${varmetaSuffixName}-${param}`;
156
+ if (CONFIG.useVariable) {
157
+ CSS_VARS[CSSVar] = color;
158
+ theme[param] = `var(${CSSVar})`;
159
+ } else {
160
+ theme[param] = color;
161
+ }
162
+ theme[`.${param}`] = { [param]: theme[param] };
163
+ }
164
+ }
165
+ if (theme["background"] || theme["color"] || theme["backgroundColor"]) {
166
+ theme[".inversed"] = {
167
+ color: theme["background"] || theme["backgroundColor"],
168
+ background: theme["color"]
169
+ };
170
+ }
171
+ }
172
+ if (isString(val) && val.slice(0, 2) === "--") {
173
+ const { THEME } = CONFIG;
174
+ const value = THEME[val.slice(2)];
175
+ const getReferenced = getMediaTheme(value, prefers);
176
+ return getReferenced;
177
+ }
178
+ return theme;
179
+ };
180
+ const recursiveTheme = (val) => {
181
+ const CONFIG = getActiveConfig();
182
+ const obj = {};
183
+ for (const param in val) {
184
+ const symb = param.slice(0, 1);
185
+ if (isObjectLike(val[param])) {
186
+ if (symb === "@") {
187
+ const query = CONFIG.MEDIA[param.slice(1)];
188
+ const media = `@media screen and ${query}`;
189
+ obj[media] = recursiveTheme(val[param]);
190
+ } else if (symb === ":") {
191
+ obj[`&${param}`] = recursiveTheme(val[param]);
192
+ }
193
+ } else
194
+ obj[param] = val[param];
195
+ }
196
+ return obj;
197
+ };
198
+ const findModifierFromArray = (val, modifierArray) => {
199
+ const currentMod = modifierArray.shift();
200
+ if (val[currentMod])
201
+ return findModifierFromArray(val[currentMod], modifierArray);
202
+ return val;
203
+ };
204
+ const findModifier = (val, modifier) => {
205
+ if (isArray(modifier))
206
+ return findModifierFromArray(val, modifier);
207
+ else if (isString(modifier) && val[modifier])
208
+ return val[modifier];
209
+ else
210
+ return val;
211
+ };
212
+ const checkForReference = (val, callback) => {
213
+ if (isString(val) && val.slice(0, 2) === "--")
214
+ return getMediaTheme(val.slice(2));
215
+ return val;
216
+ };
217
+ const checkThemeReference = (val) => checkForReference(val, checkThemeReference);
218
+ const getMediaTheme = (val, mod) => {
219
+ const CONFIG = getActiveConfig();
220
+ if (isString(val) && val.slice(0, 2) === "--")
221
+ val = getMediaTheme(val.slice(2));
222
+ if (!val || !isString(val)) {
223
+ if (CONFIG.verbose)
224
+ console.warn(val, "- theme is not string");
225
+ return;
226
+ }
227
+ const [name, ...modifier] = isArray(val) ? val : val.split(" ");
228
+ let value = CONFIG.THEME[name];
229
+ if (value && (modifier || mod)) {
230
+ value = findModifier(value, modifier.length ? modifier : mod);
231
+ }
232
+ const r = recursiveTheme(value);
233
+ return r;
234
+ };
235
+ export {
236
+ getMediaTheme,
237
+ getTheme,
238
+ setMediaTheme,
239
+ setTheme
240
+ };
@@ -0,0 +1,32 @@
1
+ import { toCamelCase } from "@symbo.ls/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,80 @@
1
+ import { getActiveConfig } from "../factory.js";
2
+ import {
3
+ applySequenceVars,
4
+ findHeadings,
5
+ generateSequence,
6
+ getSequenceValuePropertyPair,
7
+ merge
8
+ } from "../utils";
9
+ const runThroughMedia = (props) => {
10
+ const CONFIG = getActiveConfig();
11
+ const { TYPOGRAPHY, MEDIA } = CONFIG;
12
+ for (const prop in props) {
13
+ const mediaProps = props[prop];
14
+ if (prop.slice(0, 1) === "@") {
15
+ const { type, base, ratio, range, subSequence, h1Matches, unit } = props;
16
+ merge(mediaProps, {
17
+ type,
18
+ base,
19
+ ratio,
20
+ range,
21
+ subSequence,
22
+ h1Matches,
23
+ unit,
24
+ sequence: {},
25
+ scales: {},
26
+ templates: {},
27
+ vars: {}
28
+ });
29
+ generateSequence(mediaProps);
30
+ const mediaName = prop.slice(1);
31
+ applySequenceVars(mediaProps, mediaName);
32
+ const query = MEDIA[mediaName];
33
+ TYPOGRAPHY.templates[`@media screen and ${query}`] = {
34
+ fontSize: mediaProps.base / TYPOGRAPHY.browserDefault + unit
35
+ };
36
+ }
37
+ }
38
+ };
39
+ const applyHeadings = (props) => {
40
+ const CONFIG = getActiveConfig();
41
+ if (props.h1Matches) {
42
+ const unit = props.unit;
43
+ const HEADINGS = findHeadings(props);
44
+ const { templates } = props;
45
+ for (const k in HEADINGS) {
46
+ const headerName = `h${parseInt(k) + 1}`;
47
+ const headerStyle = templates[headerName];
48
+ templates[headerName] = {
49
+ fontSize: CONFIG.useVariable ? `var(${HEADINGS[k].variable})` : `${HEADINGS[k].scaling}${unit}`,
50
+ margin: headerStyle ? headerStyle.margin : 0,
51
+ lineHeight: headerStyle ? headerStyle.lineHeight : props.lineHeight,
52
+ letterSpacing: headerStyle ? headerStyle.letterSpacing : props.letterSpacing,
53
+ fontWeight: headerStyle ? headerStyle.fontWeight : 900 - k * 100
54
+ };
55
+ }
56
+ }
57
+ };
58
+ const applyTypographySequence = () => {
59
+ const CONFIG = getActiveConfig();
60
+ const { TYPOGRAPHY } = CONFIG;
61
+ generateSequence(TYPOGRAPHY);
62
+ applyHeadings(TYPOGRAPHY);
63
+ applySequenceVars(TYPOGRAPHY);
64
+ runThroughMedia(TYPOGRAPHY);
65
+ };
66
+ const getFontSizeByKey = (value) => {
67
+ const CONFIG = getActiveConfig();
68
+ const { TYPOGRAPHY } = CONFIG;
69
+ return getSequenceValuePropertyPair(
70
+ value,
71
+ "fontSize",
72
+ TYPOGRAPHY
73
+ );
74
+ };
75
+ export {
76
+ applyHeadings,
77
+ applyTypographySequence,
78
+ getFontSizeByKey,
79
+ runThroughMedia
80
+ };
@@ -0,0 +1,8 @@
1
+ const testWCAGAA = (colorA, colorB) => {
2
+ };
3
+ const testWCAGAAA = (colorA, colorB) => {
4
+ };
5
+ export {
6
+ testWCAGAA,
7
+ testWCAGAAA
8
+ };
@@ -0,0 +1,143 @@
1
+ import { document, window } from "@domql/globals";
2
+ const ENV = "development";
3
+ const colorStringToRgbaArray = (color) => {
4
+ if (color === "")
5
+ return;
6
+ if (color.toLowerCase() === "transparent")
7
+ return [0, 0, 0, 0];
8
+ if (color[0] === "#") {
9
+ if (color.length < 7) {
10
+ color = "#" + color[1] + color[1] + color[2] + color[2] + color[3] + color[3] + (color.length > 4 ? color[4] + color[4] : "");
11
+ }
12
+ return [
13
+ parseInt(color.substr(1, 2), 16),
14
+ parseInt(color.substr(3, 2), 16),
15
+ parseInt(color.substr(5, 2), 16),
16
+ color.length > 7 ? parseInt(color.substr(7, 2), 16) / 255 : 1
17
+ ];
18
+ }
19
+ if (color.indexOf("rgb") === -1) {
20
+ if (document && window) {
21
+ const elem = document.body.appendChild(document.createElement("fictum"));
22
+ const flag = "rgb(1, 2, 3)";
23
+ elem.style.color = flag;
24
+ if (elem.style.color !== flag)
25
+ return;
26
+ elem.style.color = color;
27
+ if (elem.style.color === flag || elem.style.color === "")
28
+ return;
29
+ color = window.getComputedStyle(elem).color;
30
+ document.body.removeChild(elem);
31
+ } else
32
+ console.warn("Color conversion failed, no document or window object found");
33
+ }
34
+ if (color.indexOf("rgb") === 0) {
35
+ if (color.indexOf("rgba") === -1)
36
+ color = `${color}, 1`;
37
+ return color.match(/[\.\d]+/g).map((a) => +a);
38
+ }
39
+ };
40
+ const mixTwoColors = (colorA, colorB, range = 0.5) => {
41
+ colorA = colorStringToRgbaArray(colorA);
42
+ colorB = colorStringToRgbaArray(colorB);
43
+ return mixTwoRgba(colorA, colorB, range);
44
+ };
45
+ const hexToRgb = (hex, alpha = 1) => {
46
+ const [r, g, b] = hex.match(/\w\w/g).map((x) => parseInt(x, 16));
47
+ return `rgb(${r},${g},${b})`;
48
+ };
49
+ const hexToRgbArray = (hex, alpha = 1) => {
50
+ const [r, g, b] = hex.match(/\w\w/g).map((x) => parseInt(x, 16));
51
+ return [r, g, b];
52
+ };
53
+ const rgbToHex = (r, g, b) => {
54
+ return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
55
+ };
56
+ const rgbArrayToHex = ([r, g, b]) => {
57
+ return ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
58
+ };
59
+ const hexToRgba = (hex, alpha = 1) => {
60
+ const [r, g, b] = hex.match(/\w\w/g).map((x) => parseInt(x, 16));
61
+ return `rgba(${r},${g},${b},${alpha})`;
62
+ };
63
+ const mixTwoRgb = (colorA, colorB, range = 0.5) => {
64
+ const arr = [];
65
+ for (let i = 0; i < 3; i++) {
66
+ arr[i] = ~~(colorA[i] + (colorB[i] - colorA[i]) * range);
67
+ }
68
+ return `rgb(${arr})`;
69
+ };
70
+ const changeLightness = (delta, hsl) => {
71
+ const [hue, saturation, lightness] = hsl;
72
+ const newLightness = Math.max(
73
+ 0,
74
+ Math.min(100, lightness + parseFloat(delta))
75
+ );
76
+ return [hue, saturation, newLightness];
77
+ };
78
+ const rgbToHSL = (r, g, b) => {
79
+ const a = Math.max(r, g, b);
80
+ const n = a - Math.min(r, g, b);
81
+ const f = 1 - Math.abs(a + a - n - 1);
82
+ const h = n && (a == r ? (g - b) / n : a == g ? 2 + (b - r) / n : 4 + (r - g) / n);
83
+ return [60 * (h < 0 ? h + 6 : h), f ? n / f : 0, (a + a - n) / 2];
84
+ };
85
+ const hslToRgb = (h, s, l, a = s * Math.min(l, 1 - l), f = (n, k = (n + h / 30) % 12) => l - a * Math.max(
86
+ Math.min(k - 3, 9 - k, 1),
87
+ -1
88
+ )) => [f(0), f(8), f(4)];
89
+ const getColorShade = (col, amt) => {
90
+ const num = parseInt(col, 16);
91
+ let r = (num >> 16) + amt;
92
+ if (r > 255)
93
+ r = 255;
94
+ else if (r < 0)
95
+ r = 0;
96
+ let b = (num >> 8 & 255) + amt;
97
+ if (b > 255)
98
+ b = 255;
99
+ else if (b < 0)
100
+ b = 0;
101
+ let g = (num & 255) + amt;
102
+ if (g > 255)
103
+ g = 255;
104
+ else if (g < 0)
105
+ g = 0;
106
+ return (g | b << 8 | r << 16).toString(16);
107
+ };
108
+ const mixTwoRgba = (colorA, colorB, range = 0.5) => {
109
+ const arr = [];
110
+ for (let i = 0; i < 4; i++) {
111
+ const round = i === 3 ? (x) => x : Math.round;
112
+ arr[i] = round(
113
+ colorA[i] + (colorB[i] - colorA[i]) * range
114
+ );
115
+ }
116
+ return `rgba(${arr})`;
117
+ };
118
+ const opacify = (color, opacity) => {
119
+ const arr = colorStringToRgbaArray(color);
120
+ if (!arr) {
121
+ if (ENV === "test" || ENV === "development")
122
+ console.warn(color + "color is not rgba");
123
+ return;
124
+ }
125
+ arr[3] = opacity;
126
+ return `rgba(${arr})`;
127
+ };
128
+ export {
129
+ changeLightness,
130
+ colorStringToRgbaArray,
131
+ getColorShade,
132
+ hexToRgb,
133
+ hexToRgbArray,
134
+ hexToRgba,
135
+ hslToRgb,
136
+ mixTwoColors,
137
+ mixTwoRgb,
138
+ mixTwoRgba,
139
+ opacify,
140
+ rgbArrayToHex,
141
+ rgbToHSL,
142
+ rgbToHex
143
+ };
@@ -0,0 +1,50 @@
1
+ const getDefaultOrFirstKey = (LIBRARY, key) => {
2
+ if (LIBRARY[key])
3
+ return LIBRARY[key].value;
4
+ if (LIBRARY.default)
5
+ return LIBRARY[LIBRARY.default].value;
6
+ const hasValue = Object.keys(LIBRARY)[0];
7
+ return hasValue && LIBRARY[hasValue] && LIBRARY[hasValue].value;
8
+ };
9
+ const getFontFormat = (url) => url.split(/[#?]/)[0].split(".").pop().trim();
10
+ const setInCustomFontMedia = (str) => `@font-face { ${str} }`;
11
+ const setCustomFont = (name, url, weight) => `
12
+ font-family: '${name}';
13
+ font-style: normal;
14
+ ${weight && `font-weight: ${weight};`}
15
+ src: url('${url}') format('${getFontFormat(url)}');`;
16
+ const setCustomFontMedia = (name, url, weight) => `@font-face {
17
+ ${setCustomFont(name, url, weight)}
18
+ }`;
19
+ const getFontFaceEach = (name, weights) => {
20
+ const keys = Object.keys(weights);
21
+ return keys.map((key) => {
22
+ const { url, fontWeight } = weights[key];
23
+ return setCustomFont(name, url, fontWeight);
24
+ });
25
+ };
26
+ const getFontFace = (LIBRARY) => {
27
+ const keys = Object.keys(LIBRARY);
28
+ return keys.map((key) => getFontFaceEach(key, LIBRARY[key].value));
29
+ };
30
+ const getFontFaceEachString = (name, weights) => {
31
+ const isArr = weights[0];
32
+ if (isArr)
33
+ return getFontFaceEach(name, weights).map(setInCustomFontMedia);
34
+ return setCustomFontMedia(name, weights.url);
35
+ };
36
+ const getFontFaceString = (LIBRARY) => {
37
+ const keys = Object.keys(LIBRARY);
38
+ return keys.map((key) => getFontFaceEachString(key, LIBRARY[key].value));
39
+ };
40
+ export {
41
+ getDefaultOrFirstKey,
42
+ getFontFace,
43
+ getFontFaceEach,
44
+ getFontFaceEachString,
45
+ getFontFaceString,
46
+ getFontFormat,
47
+ setCustomFont,
48
+ setCustomFontMedia,
49
+ setInCustomFontMedia
50
+ };
@@ -0,0 +1,6 @@
1
+ export * from "./object.js";
2
+ export * from "./color.js";
3
+ export * from "./font.js";
4
+ export * from "./sequence.js";
5
+ export * from "./var.js";
6
+ export * from "./sprite.js";
@@ -0,0 +1,53 @@
1
+ const isString = (arg) => typeof arg === "string";
2
+ const isArray = (arg) => Array.isArray(arg);
3
+ const isObject = (arg) => {
4
+ if (arg === null)
5
+ return false;
6
+ return typeof arg === "object" && arg.constructor === Object;
7
+ };
8
+ const isObjectLike = (arg) => {
9
+ if (arg === null)
10
+ return false;
11
+ return typeof arg === "object";
12
+ };
13
+ const merge = (obj, original) => {
14
+ for (const e in original) {
15
+ const objProp = obj[e];
16
+ const originalProp = original[e];
17
+ if (objProp === void 0) {
18
+ obj[e] = originalProp;
19
+ }
20
+ }
21
+ return obj;
22
+ };
23
+ const deepMerge = (obj, obj2) => {
24
+ for (const e in obj2) {
25
+ const objProp = obj[e];
26
+ const obj2Prop = obj2[e];
27
+ if (objProp === void 0) {
28
+ obj[e] = obj2Prop;
29
+ } else if (isObjectLike(objProp) && isObject(obj2Prop)) {
30
+ deepMerge(objProp, obj2Prop);
31
+ }
32
+ }
33
+ return obj;
34
+ };
35
+ const arrayze = (val) => {
36
+ if (isString(val))
37
+ return val.split(" ");
38
+ if (isObject(val))
39
+ return Object.keys(val).map((v) => val[v]);
40
+ if (isArray(val))
41
+ return val;
42
+ };
43
+ const isFunction = (arg) => typeof arg === "function";
44
+ export {
45
+ arrayze,
46
+ deepMerge,
47
+ isArray,
48
+ isFunction,
49
+ isObject,
50
+ isObjectLike,
51
+ isString,
52
+ merge
53
+ };