@symbo.ls/scratch 3.2.3 → 3.2.7

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 (66) hide show
  1. package/dist/cjs/factory.js +23 -494
  2. package/dist/cjs/index.js +11 -2742
  3. package/dist/cjs/set.js +66 -2060
  4. package/dist/esm/factory.js +43 -0
  5. package/dist/esm/index.js +12 -0
  6. package/dist/esm/set.js +148 -0
  7. package/dist/iife/index.js +2580 -0
  8. package/package.json +25 -15
  9. package/src/set.js +22 -7
  10. package/src/system/color.js +48 -11
  11. package/src/system/font.js +19 -5
  12. package/src/system/reset.js +12 -3
  13. package/src/system/shadow.js +20 -13
  14. package/src/system/spacing.js +63 -56
  15. package/src/system/theme.js +4 -3
  16. package/src/system/timing.js +1 -1
  17. package/src/transforms/index.js +212 -95
  18. package/src/utils/color.js +79 -0
  19. package/src/utils/font.js +54 -14
  20. package/src/utils/sequence.js +94 -39
  21. package/src/utils/sprite.js +2 -2
  22. package/src/utils/unit.js +69 -2
  23. package/src/utils/var.js +1 -2
  24. package/dist/cjs/defaultConfig/animation.js +0 -26
  25. package/dist/cjs/defaultConfig/cases.js +0 -26
  26. package/dist/cjs/defaultConfig/class.js +0 -27
  27. package/dist/cjs/defaultConfig/color.js +0 -28
  28. package/dist/cjs/defaultConfig/document.js +0 -26
  29. package/dist/cjs/defaultConfig/font-family.js +0 -34
  30. package/dist/cjs/defaultConfig/font.js +0 -26
  31. package/dist/cjs/defaultConfig/grid.js +0 -27
  32. package/dist/cjs/defaultConfig/icons.js +0 -28
  33. package/dist/cjs/defaultConfig/index.js +0 -222
  34. package/dist/cjs/defaultConfig/media.js +0 -31
  35. package/dist/cjs/defaultConfig/responsive.js +0 -52
  36. package/dist/cjs/defaultConfig/sequence.js +0 -51
  37. package/dist/cjs/defaultConfig/shadow.js +0 -26
  38. package/dist/cjs/defaultConfig/spacing.js +0 -87
  39. package/dist/cjs/defaultConfig/svg.js +0 -28
  40. package/dist/cjs/defaultConfig/templates.js +0 -26
  41. package/dist/cjs/defaultConfig/theme.js +0 -26
  42. package/dist/cjs/defaultConfig/timing.js +0 -68
  43. package/dist/cjs/defaultConfig/typography.js +0 -72
  44. package/dist/cjs/defaultConfig/unit.js +0 -28
  45. package/dist/cjs/package.json +0 -4
  46. package/dist/cjs/system/color.js +0 -1175
  47. package/dist/cjs/system/document.js +0 -987
  48. package/dist/cjs/system/font.js +0 -1009
  49. package/dist/cjs/system/index.js +0 -2227
  50. package/dist/cjs/system/reset.js +0 -1099
  51. package/dist/cjs/system/shadow.js +0 -1384
  52. package/dist/cjs/system/spacing.js +0 -1338
  53. package/dist/cjs/system/svg.js +0 -1086
  54. package/dist/cjs/system/theme.js +0 -1276
  55. package/dist/cjs/system/timing.js +0 -1213
  56. package/dist/cjs/system/typography.js +0 -1311
  57. package/dist/cjs/tests/index.js +0 -30
  58. package/dist/cjs/transforms/index.js +0 -1613
  59. package/dist/cjs/utils/color.js +0 -333
  60. package/dist/cjs/utils/font.js +0 -69
  61. package/dist/cjs/utils/index.js +0 -1548
  62. package/dist/cjs/utils/sequence.js +0 -1198
  63. package/dist/cjs/utils/sprite.js +0 -579
  64. package/dist/cjs/utils/theme.js +0 -31
  65. package/dist/cjs/utils/unit.js +0 -28
  66. package/dist/cjs/utils/var.js +0 -1040
@@ -0,0 +1,43 @@
1
+ import {
2
+ deepClone,
3
+ deepMerge,
4
+ isDefined,
5
+ isObject
6
+ } from "@domql/utils";
7
+ import * as CONF from "./defaultConfig";
8
+ const CSS_VARS = {};
9
+ const CONFIG = {
10
+ verbose: false,
11
+ useVariable: true,
12
+ useReset: true,
13
+ CSS_VARS,
14
+ ...CONF.default || CONF
15
+ };
16
+ const cachedConfig = deepClone(CONFIG);
17
+ const FACTORY = {
18
+ active: "0",
19
+ 0: CONFIG
20
+ };
21
+ const activateConfig = (def) => {
22
+ if (isDefined(def)) {
23
+ FACTORY.active = def;
24
+ }
25
+ return FACTORY[def || FACTORY.active];
26
+ };
27
+ const getActiveConfig = (def) => {
28
+ return FACTORY[def || FACTORY.active] || CONFIG;
29
+ };
30
+ const setActiveConfig = (newConfig) => {
31
+ if (!isObject(newConfig)) return;
32
+ FACTORY.active = "1";
33
+ FACTORY["1"] = deepMerge(newConfig, deepClone(cachedConfig));
34
+ return newConfig;
35
+ };
36
+ export {
37
+ CONFIG,
38
+ CSS_VARS,
39
+ FACTORY,
40
+ activateConfig,
41
+ getActiveConfig,
42
+ setActiveConfig
43
+ };
@@ -0,0 +1,12 @@
1
+ import * as scratchUtils from "./utils/index.js";
2
+ import * as scratchSystem from "./system/index.js";
3
+ export * from "./factory.js";
4
+ export * from "./defaultConfig";
5
+ export * from "./system";
6
+ export * from "./utils";
7
+ export * from "./transforms";
8
+ export * from "./set.js";
9
+ export {
10
+ scratchSystem,
11
+ scratchUtils
12
+ };
@@ -0,0 +1,148 @@
1
+ import { FACTORY, getActiveConfig, setActiveConfig } 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";
17
+ import { isFunction, deepMerge } from "@domql/utils";
18
+ const setCases = (val, key) => {
19
+ if (isFunction(val)) return val();
20
+ return val;
21
+ };
22
+ const setSameValue = (val, key) => val;
23
+ const VALUE_TRANSFORMERS = {
24
+ color: setColor,
25
+ gradient: setGradient,
26
+ font: setFont,
27
+ font_family: setFontFamily,
28
+ theme: setTheme,
29
+ icons: setSvgIcon,
30
+ semantic_icons: setSameValue,
31
+ svg: setSVG,
32
+ svg_data: setSameValue,
33
+ typography: setSameValue,
34
+ cases: setCases,
35
+ shadow: setShadow,
36
+ spacing: setSameValue,
37
+ media: setSameValue,
38
+ grid: setSameValue,
39
+ class: setSameValue,
40
+ timing: setSameValue,
41
+ reset: setSameValue,
42
+ unit: setSameValue,
43
+ animation: setSameValue
44
+ };
45
+ const setValue = (FACTORY_NAME, value, key) => {
46
+ const CONFIG = getActiveConfig();
47
+ const factoryName = FACTORY_NAME.toLowerCase();
48
+ const FACTORY2 = CONFIG[FACTORY_NAME];
49
+ if (VALUE_TRANSFORMERS[factoryName]) {
50
+ try {
51
+ const result = VALUE_TRANSFORMERS[factoryName](value, key);
52
+ FACTORY2[key] = result;
53
+ return FACTORY2;
54
+ } catch (error) {
55
+ if (CONFIG.verbose) console.warn("Error setting", factoryName, "value", value, key, error);
56
+ }
57
+ }
58
+ if (CONFIG.verbose) console.warn("Can not find", factoryName, "method in scratch");
59
+ };
60
+ const setEach = (factoryName, props) => {
61
+ const CONFIG = getActiveConfig();
62
+ const FACTORY_NAME = factoryName.toUpperCase();
63
+ const keys = Object.keys(props);
64
+ keys.forEach((key) => {
65
+ try {
66
+ return setValue(FACTORY_NAME, props[key], key);
67
+ } catch (error) {
68
+ if (CONFIG.verbose) console.warn("Error setting", FACTORY_NAME, "value", props[key], key, error);
69
+ }
70
+ });
71
+ return CONFIG[FACTORY_NAME];
72
+ };
73
+ const SET_OPTIONS = {};
74
+ const set = (recivedConfig, options = SET_OPTIONS) => {
75
+ let CONFIG = getActiveConfig();
76
+ const {
77
+ version,
78
+ verbose,
79
+ useVariable,
80
+ useReset,
81
+ useSvgSprite,
82
+ useFontImport,
83
+ useIconSprite,
84
+ globalTheme,
85
+ useDocumentTheme,
86
+ useDefaultConfig,
87
+ SEMANTIC_ICONS,
88
+ ...config
89
+ } = recivedConfig;
90
+ if (options.newConfig) {
91
+ CONFIG = setActiveConfig(options.newConfig);
92
+ }
93
+ if (verbose !== void 0) CONFIG.verbose = verbose;
94
+ if (useVariable !== void 0) CONFIG.useVariable = useVariable;
95
+ if (useReset !== void 0) CONFIG.useReset = useReset;
96
+ if (useFontImport !== void 0) CONFIG.useFontImport = useFontImport;
97
+ if (useSvgSprite !== void 0) CONFIG.useSvgSprite = useSvgSprite;
98
+ if (useIconSprite !== void 0) CONFIG.useIconSprite = useIconSprite;
99
+ if (useDocumentTheme !== void 0) CONFIG.useDocumentTheme = useDocumentTheme;
100
+ if (globalTheme !== void 0) CONFIG.globalTheme = globalTheme;
101
+ if (useDefaultConfig !== void 0) CONFIG.useDefaultConfig = useDefaultConfig;
102
+ if (SEMANTIC_ICONS !== void 0) CONFIG.SEMANTIC_ICONS = SEMANTIC_ICONS;
103
+ if (CONFIG.verbose) console.log(CONFIG);
104
+ if (!CONFIG.__svg_cache) CONFIG.__svg_cache = {};
105
+ const keys = Object.keys(config);
106
+ const keySet = new Set(keys);
107
+ keys.forEach((key) => {
108
+ const lower = key.toLowerCase();
109
+ if (lower !== key && keySet.has(lower)) {
110
+ deepMerge(config[lower], config[key]);
111
+ }
112
+ });
113
+ keys.map((key) => {
114
+ const lower = key.toLowerCase();
115
+ if (lower !== key && keySet.has(lower)) return;
116
+ return setEach(key, config[key]);
117
+ });
118
+ if (config.TYPOGRAPHY || config.typography) {
119
+ try {
120
+ applyTypographySequence();
121
+ } catch (e) {
122
+ if (CONFIG.verbose) console.warn("Error applying typography sequence", e);
123
+ }
124
+ }
125
+ if (config.SPACING || config.spacing) {
126
+ try {
127
+ applySpacingSequence();
128
+ } catch (e) {
129
+ if (CONFIG.verbose) console.warn("Error applying spacing sequence", e);
130
+ }
131
+ }
132
+ if (config.TIMING || config.timing) {
133
+ try {
134
+ applyTimingSequence();
135
+ } catch (e) {
136
+ if (CONFIG.verbose) console.warn("Error applying timing sequence", e);
137
+ }
138
+ }
139
+ applyDocument();
140
+ applyReset();
141
+ return CONFIG;
142
+ };
143
+ export {
144
+ VALUE_TRANSFORMERS,
145
+ set,
146
+ setEach,
147
+ setValue
148
+ };