@symbo.ls/scratch 2.10.161 → 2.10.163

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 (40) hide show
  1. package/package.json +5 -5
  2. package/dist/esm/defaultConfig/animation.js +0 -4
  3. package/dist/esm/defaultConfig/cases.js +0 -4
  4. package/dist/esm/defaultConfig/color.js +0 -12
  5. package/dist/esm/defaultConfig/document.js +0 -4
  6. package/dist/esm/defaultConfig/font-family.js +0 -19
  7. package/dist/esm/defaultConfig/font.js +0 -13
  8. package/dist/esm/defaultConfig/icons.js +0 -4
  9. package/dist/esm/defaultConfig/index.js +0 -20
  10. package/dist/esm/defaultConfig/media.js +0 -19
  11. package/dist/esm/defaultConfig/responsive.js +0 -28
  12. package/dist/esm/defaultConfig/sequence.js +0 -29
  13. package/dist/esm/defaultConfig/spacing.js +0 -16
  14. package/dist/esm/defaultConfig/svg.js +0 -6
  15. package/dist/esm/defaultConfig/theme.js +0 -16
  16. package/dist/esm/defaultConfig/timing.js +0 -16
  17. package/dist/esm/defaultConfig/typography.js +0 -19
  18. package/dist/esm/defaultConfig/unit.js +0 -6
  19. package/dist/esm/factory.js +0 -39
  20. package/dist/esm/index.js +0 -4
  21. package/dist/esm/set.js +0 -113
  22. package/dist/esm/system/color.js +0 -156
  23. package/dist/esm/system/document.js +0 -15
  24. package/dist/esm/system/font.js +0 -35
  25. package/dist/esm/system/index.js +0 -9
  26. package/dist/esm/system/reset.js +0 -63
  27. package/dist/esm/system/spacing.js +0 -115
  28. package/dist/esm/system/svg.js +0 -61
  29. package/dist/esm/system/theme.js +0 -240
  30. package/dist/esm/system/timing.js +0 -32
  31. package/dist/esm/system/typography.js +0 -80
  32. package/dist/esm/tests/index.js +0 -8
  33. package/dist/esm/utils/color.js +0 -143
  34. package/dist/esm/utils/font.js +0 -50
  35. package/dist/esm/utils/index.js +0 -6
  36. package/dist/esm/utils/object.js +0 -53
  37. package/dist/esm/utils/sequence.js +0 -179
  38. package/dist/esm/utils/sprite.js +0 -43
  39. package/dist/esm/utils/theme.js +0 -12
  40. package/dist/esm/utils/var.js +0 -44
@@ -1,143 +0,0 @@
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
- };
@@ -1,50 +0,0 @@
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
- };
@@ -1,6 +0,0 @@
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";
@@ -1,53 +0,0 @@
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
- };
@@ -1,179 +0,0 @@
1
- import { isString } from "@domql/utils";
2
- import { toDashCase } from "@symbo.ls/utils";
3
- import { getActiveConfig } from "../factory.js";
4
- const numToLetterMap = {
5
- "-6": "U",
6
- "-5": "V",
7
- "-4": "W",
8
- "-3": "X",
9
- "-2": "Y",
10
- "-1": "Z",
11
- 0: "A",
12
- 1: "B",
13
- 2: "C",
14
- 3: "D",
15
- 4: "E",
16
- 5: "F",
17
- 6: "G",
18
- 7: "H",
19
- 8: "I",
20
- 9: "J",
21
- 10: "K",
22
- 11: "L",
23
- 12: "M",
24
- 13: "N",
25
- 14: "O",
26
- 15: "P",
27
- 16: "Q",
28
- 17: "R",
29
- 18: "S",
30
- 19: "T"
31
- };
32
- const setSequenceValue = (props, sequenceProps) => {
33
- const { key, variable, value, scaling, index } = props;
34
- sequenceProps.sequence[key] = {
35
- key,
36
- decimal: ~~(value * 100) / 100,
37
- val: ~~value,
38
- scaling,
39
- index,
40
- variable
41
- };
42
- sequenceProps.scales[key] = scaling;
43
- sequenceProps.vars[variable] = scaling + sequenceProps.unit;
44
- };
45
- const generateSubSequence = (props, sequenceProps) => {
46
- const { key, base, value, ratio, variable, index } = props;
47
- const next = value * ratio;
48
- const diff = next - value;
49
- const smallscale = diff / 1.618;
50
- const valueRounded = ~~value;
51
- const nextRounded = ~~next;
52
- const diffRounded = nextRounded - valueRounded;
53
- let arr = [];
54
- const first = next - smallscale;
55
- const second = value + smallscale;
56
- const middle = (first + second) / 2;
57
- if (diffRounded > 16)
58
- arr = [first, middle, second];
59
- else
60
- arr = [first, second];
61
- arr.map((v, k) => {
62
- const scaling = ~~(v / base * 1e3) / 1e3;
63
- const newVar = variable + (k + 1);
64
- const props2 = {
65
- key: key + (k + 1),
66
- variable: newVar,
67
- value: v,
68
- scaling,
69
- index: index + (k + 1) / 10
70
- };
71
- return setSequenceValue(props2, sequenceProps);
72
- });
73
- };
74
- const switchSequenceOnNegative = (key, base, ratio) => {
75
- return base * Math.pow(ratio, key);
76
- };
77
- const generateSequence = (sequenceProps) => {
78
- const { type, base, ratio, range, subSequence } = sequenceProps;
79
- const n = Math.abs(range[0]) + Math.abs(range[1]);
80
- const prefix = "--" + (type && type.replace(".", "-")) + "-";
81
- for (let i = 0; i <= n; i++) {
82
- const key = range[1] - i;
83
- const letterKey = numToLetterMap[key];
84
- const value = switchSequenceOnNegative(key, base, ratio);
85
- const scaling = ~~(value / base * 100) / 100;
86
- const variable = prefix + letterKey;
87
- const props = {
88
- key: letterKey,
89
- variable,
90
- value,
91
- base,
92
- scaling,
93
- ratio,
94
- index: key
95
- };
96
- setSequenceValue(props, sequenceProps);
97
- if (subSequence)
98
- generateSubSequence(props, sequenceProps);
99
- }
100
- return sequenceProps;
101
- };
102
- const getSequenceValue = (value = "A", sequenceProps) => {
103
- const CONFIG = getActiveConfig();
104
- const { UNIT } = CONFIG;
105
- const {
106
- sequence,
107
- unit = UNIT.default,
108
- useVariable
109
- } = sequenceProps;
110
- if (isString(value) && value.slice(0, 2) === "--")
111
- return `var(${value})`;
112
- const prefix = `--${toDashCase(sequenceProps.type.replace(".", "-"))}-`;
113
- const startsWithDashOrLetterRegex = /^-?[a-zA-Z]/i;
114
- const startsWithDashOrLetter = startsWithDashOrLetterRegex.test(value);
115
- if (value === "none" || value === "auto" || value === "unset" || value === "inherit" || value === "fit-content" || value === "min-content" || value === "max-content" || value.includes("calc") || !startsWithDashOrLetter)
116
- return value;
117
- const letterVal = value.toUpperCase();
118
- const isNegative = letterVal.slice(0, 1) === "-" ? "-" : "";
119
- let absValue = isNegative ? letterVal.slice(1) : letterVal;
120
- let mediaName = "";
121
- if (absValue.includes("-")) {
122
- mediaName = "-" + absValue.split("-")[1].toLowerCase();
123
- absValue = absValue.split("-")[0];
124
- }
125
- const varValue = (v) => `var(${prefix}${v}${mediaName})`;
126
- if (absValue.includes("+")) {
127
- const args = absValue.split("+");
128
- const [first, second] = args;
129
- const joint = `${varValue(first)} + ${varValue(second)}`;
130
- return isNegative ? `calc((${joint}) * -1)` : `calc(${joint})`;
131
- } else if (absValue.includes("-")) {
132
- const args = absValue.split("-");
133
- const [first, second] = args;
134
- const joint = `${varValue(first)} - ${varValue(second)}`;
135
- return isNegative ? `calc((${joint}) * -1)` : `calc(${joint})`;
136
- }
137
- if (!sequence[absValue] && absValue.length === 2) {
138
- if (CONFIG.verbose)
139
- console.warn(absValue, "- value is not found because `subSequence` is set to false");
140
- absValue = absValue.slice(0, 1);
141
- }
142
- if (useVariable || CONFIG.useVariable) {
143
- const varValue2 = `var(${prefix}${absValue}${mediaName})`;
144
- return isNegative ? `calc(${varValue2} * -1)` : varValue2;
145
- }
146
- const sequenceItem = sequence ? sequence[absValue] : null;
147
- if (!sequenceItem)
148
- return console.warn("can't find", sequence, absValue);
149
- if (unit === "ms" || unit === "s") {
150
- return isNegative + sequenceItem.val + unit;
151
- }
152
- return isNegative + sequenceItem.scaling + unit;
153
- };
154
- const getSequenceValuePropertyPair = (value, propertyName, sequenceProps) => {
155
- if (typeof value !== "string") {
156
- console.warn(propertyName, value, "is not a string");
157
- return {};
158
- }
159
- if (value === "-" || value === "")
160
- return {};
161
- return { [propertyName]: getSequenceValue(value, sequenceProps) };
162
- };
163
- const findHeadingLetter = (h1Matches, index) => numToLetterMap[h1Matches - index];
164
- const findHeadings = (propertyNames) => {
165
- const { h1Matches, sequence } = propertyNames;
166
- return new Array(6).fill(null).map((_, i) => {
167
- const findLetter = findHeadingLetter(h1Matches, i);
168
- return sequence[findLetter];
169
- });
170
- };
171
- export {
172
- findHeadingLetter,
173
- findHeadings,
174
- generateSequence,
175
- generateSubSequence,
176
- getSequenceValue,
177
- getSequenceValuePropertyPair,
178
- numToLetterMap
179
- };
@@ -1,43 +0,0 @@
1
- import { isString } from "@domql/utils";
2
- const generateSprite = (icons) => {
3
- let sprite = '<svg aria-hidden="true" width="0" height="0" style="position:absolute">';
4
- for (let key in icons) {
5
- sprite += icons[key];
6
- }
7
- sprite += "</svg>";
8
- return sprite;
9
- };
10
- const parseRootAttributes = (htmlString) => {
11
- if (!isString(htmlString)) {
12
- return console.warn(`parseRootAttributes: ${htmlString} is not a string`);
13
- }
14
- let match = htmlString.match(/<svg\s+(.*?)>/);
15
- if (!match || !match[1]) {
16
- return {};
17
- }
18
- let attrString = match[1];
19
- let attrs = attrString.match(/(\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|\s*\/?[>"']))+.)["']?/gm);
20
- return attrs.reduce((acc, attr) => {
21
- let [key, value] = attr.split("=");
22
- acc[key] = value.replace(/['"]/g, "");
23
- return acc;
24
- }, {});
25
- };
26
- const convertSvgToSymbol = (key, code) => {
27
- const extractAttrs = parseRootAttributes(code);
28
- const { width, height } = extractAttrs;
29
- const viewBox = extractAttrs.viewBox || `0 0 ${width || 24} ${height || 24}`;
30
- const xmlns = "http://www.w3.org/2000/svg";
31
- let symbol = code.replace(
32
- "<svg",
33
- `<symbol id="${key}" xmlns="${xmlns}" viewBox="${viewBox}"`
34
- );
35
- symbol = symbol.replace(/width="[^\"]*/, "");
36
- symbol = symbol.replace(/height="[^\"]*/, "");
37
- symbol = symbol.replace("</svg", "</symbol");
38
- return symbol;
39
- };
40
- export {
41
- convertSvgToSymbol,
42
- generateSprite
43
- };
@@ -1,12 +0,0 @@
1
- const returnSubThemeOrDefault = (orig, theme) => {
2
- if (!orig)
3
- return;
4
- if (orig.themes && orig.themes[theme])
5
- return orig.themes[theme];
6
- if (orig[theme])
7
- return [orig, orig[theme]];
8
- return orig;
9
- };
10
- export {
11
- returnSubThemeOrDefault
12
- };
@@ -1,44 +0,0 @@
1
- import { getActiveConfig } from "../factory.js";
2
- import { isObjectLike } from "@domql/utils";
3
- const ENV = "development";
4
- const setVariables = (result, key) => {
5
- const CONFIG = getActiveConfig();
6
- const { CSS_VARS } = CONFIG;
7
- if (isObjectLike(result.value)) {
8
- } else {
9
- CSS_VARS[result.var] = result.value;
10
- }
11
- };
12
- const applySequenceVars = (props, mediaName, options = {}) => {
13
- const CONFIG = getActiveConfig();
14
- const { UNIT, MEDIA, TIMING, CSS_VARS } = CONFIG;
15
- const unit = props.unit || UNIT.default;
16
- const { sequence, scales } = props;
17
- for (const key in sequence) {
18
- const item = sequence[key];
19
- const value = (props.type === TIMING.type ? sequence[key].val : scales[key]) + unit;
20
- if (mediaName) {
21
- const query = MEDIA[mediaName];
22
- if (!query) {
23
- if (CONFIG.verbose)
24
- console.warn("Can't find query ", query);
25
- }
26
- let underMediaQuery = CSS_VARS[`@media ${query}`];
27
- if (!underMediaQuery)
28
- underMediaQuery = CSS_VARS[`@media ${query}`] = {};
29
- underMediaQuery[item.variable] = `var(${item.variable + "-" + mediaName})`;
30
- CSS_VARS[item.variable + "-" + mediaName] = value;
31
- } else {
32
- if (options.useDefault === false) {
33
- CSS_VARS[item.variable] = value;
34
- } else {
35
- CSS_VARS[item.variable + "-default"] = value;
36
- CSS_VARS[item.variable] = `var(${item.variable + "-default"})`;
37
- }
38
- }
39
- }
40
- };
41
- export {
42
- applySequenceVars,
43
- setVariables
44
- };