@symbo.ls/scratch 3.4.0 → 3.4.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.
@@ -39,12 +39,19 @@ module.exports = __toCommonJS(factory_exports);
39
39
  var import_utils = require("@domql/utils");
40
40
  var CONF = __toESM(require("./defaultConfig"), 1);
41
41
  const CSS_VARS = {};
42
+ const _CONF = CONF.default || CONF;
43
+ const _confLower = {};
44
+ for (const key in _CONF) {
45
+ const lower = key.toLowerCase();
46
+ _confLower[lower] = _CONF[key];
47
+ if (lower !== key) _confLower[key] = _CONF[key];
48
+ }
42
49
  const CONFIG = {
43
50
  verbose: false,
44
51
  useVariable: true,
45
52
  useReset: true,
46
53
  CSS_VARS,
47
- ...CONF.default || CONF
54
+ ..._confLower
48
55
  };
49
56
  const cachedConfig = (0, import_utils.deepClone)(CONFIG);
50
57
  const FACTORY = {
package/dist/cjs/set.js CHANGED
@@ -54,33 +54,33 @@ const VALUE_TRANSFORMERS = {
54
54
  unit: setSameValue,
55
55
  animation: setSameValue
56
56
  };
57
- const setValue = (FACTORY_NAME, value, key) => {
57
+ const setValue = (factoryName, value, key) => {
58
58
  const CONFIG = (0, import_factory.getActiveConfig)();
59
- const factoryName = FACTORY_NAME.toLowerCase();
60
- const FACTORY2 = CONFIG[FACTORY_NAME];
61
- if (VALUE_TRANSFORMERS[factoryName]) {
59
+ const lowerName = factoryName.toLowerCase();
60
+ const FACTORY2 = CONFIG[lowerName] || CONFIG[factoryName];
61
+ if (VALUE_TRANSFORMERS[lowerName]) {
62
62
  try {
63
- const result = VALUE_TRANSFORMERS[factoryName](value, key);
63
+ const result = VALUE_TRANSFORMERS[lowerName](value, key);
64
64
  FACTORY2[key] = result;
65
65
  return FACTORY2;
66
66
  } catch (error) {
67
- if (CONFIG.verbose) console.warn("Error setting", factoryName, "value", value, key, error);
67
+ if (CONFIG.verbose) console.warn("Error setting", lowerName, "value", value, key, error);
68
68
  }
69
69
  }
70
- if (CONFIG.verbose) console.warn("Can not find", factoryName, "method in scratch");
70
+ if (CONFIG.verbose) console.warn("Can not find", lowerName, "method in scratch");
71
71
  };
72
72
  const setEach = (factoryName, props) => {
73
73
  const CONFIG = (0, import_factory.getActiveConfig)();
74
- const FACTORY_NAME = factoryName.toUpperCase();
74
+ const lowerName = factoryName.toLowerCase();
75
75
  const keys = Object.keys(props);
76
76
  keys.forEach((key) => {
77
77
  try {
78
- return setValue(FACTORY_NAME, props[key], key);
78
+ return setValue(lowerName, props[key], key);
79
79
  } catch (error) {
80
- if (CONFIG.verbose) console.warn("Error setting", FACTORY_NAME, "value", props[key], key, error);
80
+ if (CONFIG.verbose) console.warn("Error setting", lowerName, "value", props[key], key, error);
81
81
  }
82
82
  });
83
- return CONFIG[FACTORY_NAME];
83
+ return CONFIG[lowerName] || CONFIG[factoryName];
84
84
  };
85
85
  const SET_OPTIONS = {};
86
86
  const set = (recivedConfig, options = SET_OPTIONS) => {
@@ -97,6 +97,7 @@ const set = (recivedConfig, options = SET_OPTIONS) => {
97
97
  useDocumentTheme,
98
98
  useDefaultConfig,
99
99
  SEMANTIC_ICONS,
100
+ semantic_icons,
100
101
  ...config
101
102
  } = recivedConfig;
102
103
  if (options.newConfig) {
@@ -111,7 +112,11 @@ const set = (recivedConfig, options = SET_OPTIONS) => {
111
112
  if (useDocumentTheme !== void 0) CONFIG.useDocumentTheme = useDocumentTheme;
112
113
  if (globalTheme !== void 0) CONFIG.globalTheme = globalTheme;
113
114
  if (useDefaultConfig !== void 0) CONFIG.useDefaultConfig = useDefaultConfig;
114
- if (SEMANTIC_ICONS !== void 0) CONFIG.SEMANTIC_ICONS = SEMANTIC_ICONS;
115
+ const _semanticIcons = SEMANTIC_ICONS || semantic_icons;
116
+ if (_semanticIcons !== void 0) {
117
+ CONFIG.semantic_icons = _semanticIcons;
118
+ CONFIG.SEMANTIC_ICONS = CONFIG.semantic_icons;
119
+ }
115
120
  if (CONFIG.verbose) console.log(CONFIG);
116
121
  if (!CONFIG.__svg_cache) CONFIG.__svg_cache = {};
117
122
  const keys = Object.keys(config);
@@ -6,12 +6,19 @@ import {
6
6
  } from "@domql/utils";
7
7
  import * as CONF from "./defaultConfig";
8
8
  const CSS_VARS = {};
9
+ const _CONF = CONF.default || CONF;
10
+ const _confLower = {};
11
+ for (const key in _CONF) {
12
+ const lower = key.toLowerCase();
13
+ _confLower[lower] = _CONF[key];
14
+ if (lower !== key) _confLower[key] = _CONF[key];
15
+ }
9
16
  const CONFIG = {
10
17
  verbose: false,
11
18
  useVariable: true,
12
19
  useReset: true,
13
20
  CSS_VARS,
14
- ...CONF.default || CONF
21
+ ..._confLower
15
22
  };
16
23
  const cachedConfig = deepClone(CONFIG);
17
24
  const FACTORY = {
package/dist/esm/set.js CHANGED
@@ -42,33 +42,33 @@ const VALUE_TRANSFORMERS = {
42
42
  unit: setSameValue,
43
43
  animation: setSameValue
44
44
  };
45
- const setValue = (FACTORY_NAME, value, key) => {
45
+ const setValue = (factoryName, value, key) => {
46
46
  const CONFIG = getActiveConfig();
47
- const factoryName = FACTORY_NAME.toLowerCase();
48
- const FACTORY2 = CONFIG[FACTORY_NAME];
49
- if (VALUE_TRANSFORMERS[factoryName]) {
47
+ const lowerName = factoryName.toLowerCase();
48
+ const FACTORY2 = CONFIG[lowerName] || CONFIG[factoryName];
49
+ if (VALUE_TRANSFORMERS[lowerName]) {
50
50
  try {
51
- const result = VALUE_TRANSFORMERS[factoryName](value, key);
51
+ const result = VALUE_TRANSFORMERS[lowerName](value, key);
52
52
  FACTORY2[key] = result;
53
53
  return FACTORY2;
54
54
  } catch (error) {
55
- if (CONFIG.verbose) console.warn("Error setting", factoryName, "value", value, key, error);
55
+ if (CONFIG.verbose) console.warn("Error setting", lowerName, "value", value, key, error);
56
56
  }
57
57
  }
58
- if (CONFIG.verbose) console.warn("Can not find", factoryName, "method in scratch");
58
+ if (CONFIG.verbose) console.warn("Can not find", lowerName, "method in scratch");
59
59
  };
60
60
  const setEach = (factoryName, props) => {
61
61
  const CONFIG = getActiveConfig();
62
- const FACTORY_NAME = factoryName.toUpperCase();
62
+ const lowerName = factoryName.toLowerCase();
63
63
  const keys = Object.keys(props);
64
64
  keys.forEach((key) => {
65
65
  try {
66
- return setValue(FACTORY_NAME, props[key], key);
66
+ return setValue(lowerName, props[key], key);
67
67
  } catch (error) {
68
- if (CONFIG.verbose) console.warn("Error setting", FACTORY_NAME, "value", props[key], key, error);
68
+ if (CONFIG.verbose) console.warn("Error setting", lowerName, "value", props[key], key, error);
69
69
  }
70
70
  });
71
- return CONFIG[FACTORY_NAME];
71
+ return CONFIG[lowerName] || CONFIG[factoryName];
72
72
  };
73
73
  const SET_OPTIONS = {};
74
74
  const set = (recivedConfig, options = SET_OPTIONS) => {
@@ -85,6 +85,7 @@ const set = (recivedConfig, options = SET_OPTIONS) => {
85
85
  useDocumentTheme,
86
86
  useDefaultConfig,
87
87
  SEMANTIC_ICONS,
88
+ semantic_icons,
88
89
  ...config
89
90
  } = recivedConfig;
90
91
  if (options.newConfig) {
@@ -99,7 +100,11 @@ const set = (recivedConfig, options = SET_OPTIONS) => {
99
100
  if (useDocumentTheme !== void 0) CONFIG.useDocumentTheme = useDocumentTheme;
100
101
  if (globalTheme !== void 0) CONFIG.globalTheme = globalTheme;
101
102
  if (useDefaultConfig !== void 0) CONFIG.useDefaultConfig = useDefaultConfig;
102
- if (SEMANTIC_ICONS !== void 0) CONFIG.SEMANTIC_ICONS = SEMANTIC_ICONS;
103
+ const _semanticIcons = SEMANTIC_ICONS || semantic_icons;
104
+ if (_semanticIcons !== void 0) {
105
+ CONFIG.semantic_icons = _semanticIcons;
106
+ CONFIG.SEMANTIC_ICONS = CONFIG.semantic_icons;
107
+ }
103
108
  if (CONFIG.verbose) console.log(CONFIG);
104
109
  if (!CONFIG.__svg_cache) CONFIG.__svg_cache = {};
105
110
  const keys = Object.keys(config);
@@ -969,12 +969,19 @@ var SmblsScratch = (() => {
969
969
 
970
970
  // src/factory.js
971
971
  var CSS_VARS = {};
972
+ var _CONF = void 0 || defaultConfig_exports;
973
+ var _confLower = {};
974
+ for (const key in _CONF) {
975
+ const lower = key.toLowerCase();
976
+ _confLower[lower] = _CONF[key];
977
+ if (lower !== key) _confLower[key] = _CONF[key];
978
+ }
972
979
  var CONFIG = {
973
980
  verbose: false,
974
981
  useVariable: true,
975
982
  useReset: true,
976
983
  CSS_VARS,
977
- ...void 0 || defaultConfig_exports
984
+ ..._confLower
978
985
  };
979
986
  var cachedConfig = deepClone(CONFIG);
980
987
  var FACTORY = {
@@ -1543,14 +1550,31 @@ var SmblsScratch = (() => {
1543
1550
  const parts = rawRef.split(" ");
1544
1551
  const refColor = CONFIG2.COLOR[parts[0]];
1545
1552
  if (refColor && refColor.value) {
1546
- if (parts[1] !== void 0) {
1547
- val = `rgba(${refColor.rgb}, ${parts[1]})`;
1548
- } else {
1549
- val = refColor.value;
1553
+ let rgb2 = refColor.rgb;
1554
+ const alpha2 = parts[1] !== void 0 ? parts[1] : "1";
1555
+ const tone = parts[2];
1556
+ if (tone) {
1557
+ rgb2 = getRgbTone(rgb2, tone);
1550
1558
  }
1559
+ val = `rgba(${rgb2}, ${alpha2})`;
1551
1560
  } else {
1552
- if (CONFIG2.verbose) console.warn(val, "- referred but does not exist");
1553
- val = parts[0];
1561
+ const tone = parts[2];
1562
+ const alpha2 = parts[1] !== void 0 ? parts[1] : "1";
1563
+ if (tone) {
1564
+ try {
1565
+ const rgb2 = colorStringToRgbaArray(parts[0]);
1566
+ if (rgb2 && rgb2.length >= 3) {
1567
+ const tonedRgb = getRgbTone(rgb2.slice(0, 3).join(", "), tone);
1568
+ val = `rgba(${tonedRgb}, ${alpha2})`;
1569
+ } else {
1570
+ val = parts[0];
1571
+ }
1572
+ } catch (e) {
1573
+ val = parts[0];
1574
+ }
1575
+ } else {
1576
+ val = parts[0];
1577
+ }
1554
1578
  }
1555
1579
  }
1556
1580
  }
@@ -2477,33 +2501,33 @@ var SmblsScratch = (() => {
2477
2501
  unit: setSameValue,
2478
2502
  animation: setSameValue
2479
2503
  };
2480
- var setValue = (FACTORY_NAME, value, key) => {
2504
+ var setValue = (factoryName, value, key) => {
2481
2505
  const CONFIG2 = getActiveConfig();
2482
- const factoryName = FACTORY_NAME.toLowerCase();
2483
- const FACTORY2 = CONFIG2[FACTORY_NAME];
2484
- if (VALUE_TRANSFORMERS[factoryName]) {
2506
+ const lowerName = factoryName.toLowerCase();
2507
+ const FACTORY2 = CONFIG2[lowerName] || CONFIG2[factoryName];
2508
+ if (VALUE_TRANSFORMERS[lowerName]) {
2485
2509
  try {
2486
- const result = VALUE_TRANSFORMERS[factoryName](value, key);
2510
+ const result = VALUE_TRANSFORMERS[lowerName](value, key);
2487
2511
  FACTORY2[key] = result;
2488
2512
  return FACTORY2;
2489
2513
  } catch (error) {
2490
- if (CONFIG2.verbose) console.warn("Error setting", factoryName, "value", value, key, error);
2514
+ if (CONFIG2.verbose) console.warn("Error setting", lowerName, "value", value, key, error);
2491
2515
  }
2492
2516
  }
2493
- if (CONFIG2.verbose) console.warn("Can not find", factoryName, "method in scratch");
2517
+ if (CONFIG2.verbose) console.warn("Can not find", lowerName, "method in scratch");
2494
2518
  };
2495
2519
  var setEach = (factoryName, props) => {
2496
2520
  const CONFIG2 = getActiveConfig();
2497
- const FACTORY_NAME = factoryName.toUpperCase();
2521
+ const lowerName = factoryName.toLowerCase();
2498
2522
  const keys = Object.keys(props);
2499
2523
  keys.forEach((key) => {
2500
2524
  try {
2501
- return setValue(FACTORY_NAME, props[key], key);
2525
+ return setValue(lowerName, props[key], key);
2502
2526
  } catch (error) {
2503
- if (CONFIG2.verbose) console.warn("Error setting", FACTORY_NAME, "value", props[key], key, error);
2527
+ if (CONFIG2.verbose) console.warn("Error setting", lowerName, "value", props[key], key, error);
2504
2528
  }
2505
2529
  });
2506
- return CONFIG2[FACTORY_NAME];
2530
+ return CONFIG2[lowerName] || CONFIG2[factoryName];
2507
2531
  };
2508
2532
  var SET_OPTIONS = {};
2509
2533
  var set = (recivedConfig, options = SET_OPTIONS) => {
@@ -2520,6 +2544,7 @@ var SmblsScratch = (() => {
2520
2544
  useDocumentTheme,
2521
2545
  useDefaultConfig,
2522
2546
  SEMANTIC_ICONS: SEMANTIC_ICONS2,
2547
+ semantic_icons,
2523
2548
  ...config
2524
2549
  } = recivedConfig;
2525
2550
  if (options.newConfig) {
@@ -2534,7 +2559,11 @@ var SmblsScratch = (() => {
2534
2559
  if (useDocumentTheme !== void 0) CONFIG2.useDocumentTheme = useDocumentTheme;
2535
2560
  if (globalTheme !== void 0) CONFIG2.globalTheme = globalTheme;
2536
2561
  if (useDefaultConfig !== void 0) CONFIG2.useDefaultConfig = useDefaultConfig;
2537
- if (SEMANTIC_ICONS2 !== void 0) CONFIG2.SEMANTIC_ICONS = SEMANTIC_ICONS2;
2562
+ const _semanticIcons = SEMANTIC_ICONS2 || semantic_icons;
2563
+ if (_semanticIcons !== void 0) {
2564
+ CONFIG2.semantic_icons = _semanticIcons;
2565
+ CONFIG2.SEMANTIC_ICONS = CONFIG2.semantic_icons;
2566
+ }
2538
2567
  if (CONFIG2.verbose) console.log(CONFIG2);
2539
2568
  if (!CONFIG2.__svg_cache) CONFIG2.__svg_cache = {};
2540
2569
  const keys = Object.keys(config);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@symbo.ls/scratch",
3
3
  "description": "Φ / CSS framework and methodology.",
4
4
  "author": "symbo.ls",
5
- "version": "3.4.0",
5
+ "version": "3.4.2",
6
6
  "files": [
7
7
  "dist",
8
8
  "*.js",
@@ -33,8 +33,8 @@
33
33
  "prepublish": "npm run build && npm run copy:package:cjs"
34
34
  },
35
35
  "dependencies": {
36
- "@domql/utils": "^3.4.0",
37
- "@symbo.ls/smbls-utils": "^3.4.0",
36
+ "@domql/utils": "^3.4.2",
37
+ "@symbo.ls/smbls-utils": "^3.4.2",
38
38
  "color-contrast-checker": "^1.5.0"
39
39
  },
40
40
  "gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
package/src/factory.js CHANGED
@@ -9,12 +9,23 @@ import {
9
9
  import * as CONF from './defaultConfig'
10
10
 
11
11
  export const CSS_VARS = {}
12
+
13
+ // Build CONFIG with lowercase keys as canonical
14
+ const _CONF = CONF.default || CONF
15
+ const _confLower = {}
16
+ for (const key in _CONF) {
17
+ const lower = key.toLowerCase()
18
+ _confLower[lower] = _CONF[key]
19
+ // backward compat: keep UPPERCASE alias pointing to same object
20
+ if (lower !== key) _confLower[key] = _CONF[key]
21
+ }
22
+
12
23
  export const CONFIG = {
13
24
  verbose: false,
14
25
  useVariable: true,
15
26
  useReset: true,
16
27
  CSS_VARS,
17
- ...(CONF.default || CONF)
28
+ ..._confLower
18
29
  }
19
30
 
20
31
  const cachedConfig = deepClone(CONFIG)
package/src/set.js CHANGED
@@ -56,38 +56,38 @@ export const VALUE_TRANSFORMERS = {
56
56
  * @param {String} key Key, or the name of the property
57
57
  * @returns {Object} Factory
58
58
  */
59
- export const setValue = (FACTORY_NAME, value, key) => {
59
+ export const setValue = (factoryName, value, key) => {
60
60
  const CONFIG = getActiveConfig()
61
- const factoryName = FACTORY_NAME.toLowerCase()
62
- const FACTORY = CONFIG[FACTORY_NAME]
61
+ const lowerName = factoryName.toLowerCase()
62
+ const FACTORY = CONFIG[lowerName] || CONFIG[factoryName]
63
63
 
64
- if (VALUE_TRANSFORMERS[factoryName]) {
64
+ if (VALUE_TRANSFORMERS[lowerName]) {
65
65
  try {
66
- const result = VALUE_TRANSFORMERS[factoryName](value, key)
66
+ const result = VALUE_TRANSFORMERS[lowerName](value, key)
67
67
  FACTORY[key] = result
68
68
  return FACTORY
69
69
  } catch (error) {
70
- if (CONFIG.verbose) console.warn('Error setting', factoryName, 'value', value, key, error)
70
+ if (CONFIG.verbose) console.warn('Error setting', lowerName, 'value', value, key, error)
71
71
  }
72
72
  }
73
73
 
74
- if (CONFIG.verbose) console.warn('Can not find', factoryName, 'method in scratch')
74
+ if (CONFIG.verbose) console.warn('Can not find', lowerName, 'method in scratch')
75
75
  }
76
76
 
77
77
  export const setEach = (factoryName, props) => {
78
78
  const CONFIG = getActiveConfig()
79
- const FACTORY_NAME = factoryName.toUpperCase()
79
+ const lowerName = factoryName.toLowerCase()
80
80
  const keys = Object.keys(props)
81
81
 
82
82
  keys.forEach((key) => {
83
83
  try {
84
- return setValue(FACTORY_NAME, props[key], key)
84
+ return setValue(lowerName, props[key], key)
85
85
  } catch (error) {
86
- if (CONFIG.verbose) console.warn('Error setting', FACTORY_NAME, 'value', props[key], key, error)
86
+ if (CONFIG.verbose) console.warn('Error setting', lowerName, 'value', props[key], key, error)
87
87
  }
88
88
  })
89
89
 
90
- return CONFIG[FACTORY_NAME]
90
+ return CONFIG[lowerName] || CONFIG[factoryName]
91
91
  }
92
92
 
93
93
  const SET_OPTIONS = {}
@@ -107,6 +107,7 @@ export const set = (recivedConfig, options = SET_OPTIONS) => {
107
107
  useDocumentTheme,
108
108
  useDefaultConfig,
109
109
  SEMANTIC_ICONS,
110
+ semantic_icons,
110
111
  ...config
111
112
  } = recivedConfig
112
113
 
@@ -123,7 +124,11 @@ export const set = (recivedConfig, options = SET_OPTIONS) => {
123
124
  if (useDocumentTheme !== undefined) CONFIG.useDocumentTheme = useDocumentTheme
124
125
  if (globalTheme !== undefined) CONFIG.globalTheme = globalTheme
125
126
  if (useDefaultConfig !== undefined) CONFIG.useDefaultConfig = useDefaultConfig
126
- if (SEMANTIC_ICONS !== undefined) CONFIG.SEMANTIC_ICONS = SEMANTIC_ICONS
127
+ const _semanticIcons = SEMANTIC_ICONS || semantic_icons
128
+ if (_semanticIcons !== undefined) {
129
+ CONFIG.semantic_icons = _semanticIcons
130
+ CONFIG.SEMANTIC_ICONS = CONFIG.semantic_icons // backward compat alias
131
+ }
127
132
  if (CONFIG.verbose) console.log(CONFIG)
128
133
 
129
134
  if (!CONFIG.__svg_cache) CONFIG.__svg_cache = {}
@@ -124,14 +124,32 @@ export const setColor = (val, key, suffix) => {
124
124
  const parts = rawRef.split(' ')
125
125
  const refColor = CONFIG.COLOR[parts[0]]
126
126
  if (refColor && refColor.value) {
127
- if (parts[1] !== undefined) {
128
- val = `rgba(${refColor.rgb}, ${parts[1]})`
129
- } else {
130
- val = refColor.value
127
+ let rgb = refColor.rgb
128
+ const alpha = parts[1] !== undefined ? parts[1] : '1'
129
+ const tone = parts[2]
130
+ if (tone) {
131
+ rgb = getRgbTone(rgb, tone)
131
132
  }
133
+ val = `rgba(${rgb}, ${alpha})`
132
134
  } else {
133
- if (CONFIG.verbose) console.warn(val, '- referred but does not exist')
134
- val = parts[0]
135
+ // Try to resolve as CSS keyword color with tone modifier
136
+ const tone = parts[2]
137
+ const alpha = parts[1] !== undefined ? parts[1] : '1'
138
+ if (tone) {
139
+ try {
140
+ const rgb = colorStringToRgbaArray(parts[0])
141
+ if (rgb && rgb.length >= 3) {
142
+ const tonedRgb = getRgbTone(rgb.slice(0, 3).join(', '), tone)
143
+ val = `rgba(${tonedRgb}, ${alpha})`
144
+ } else {
145
+ val = parts[0]
146
+ }
147
+ } catch (e) {
148
+ val = parts[0]
149
+ }
150
+ } else {
151
+ val = parts[0]
152
+ }
135
153
  }
136
154
  }
137
155
  }