@symbo.ls/scratch 3.8.8 → 3.14.0

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 (76) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/defaultConfig/class.js +1 -2
  3. package/dist/cjs/defaultConfig/font-family.js +6 -6
  4. package/dist/cjs/defaultConfig/icons.js +2 -2
  5. package/dist/cjs/defaultConfig/svg.js +2 -2
  6. package/dist/cjs/defaultConfig/timing.js +1 -1
  7. package/dist/cjs/factory.js +72 -12
  8. package/dist/cjs/index.js +6 -4
  9. package/dist/cjs/set.js +113 -52
  10. package/dist/cjs/system/color.js +72 -12
  11. package/dist/cjs/system/document.js +3 -3
  12. package/dist/cjs/system/font.js +14 -14
  13. package/dist/cjs/system/reset.js +34 -7
  14. package/dist/cjs/system/shadow.js +4 -3
  15. package/dist/cjs/system/spacing.js +18 -18
  16. package/dist/cjs/system/svg.js +34 -7
  17. package/dist/cjs/system/theme.js +51 -50
  18. package/dist/cjs/system/timing.js +6 -6
  19. package/dist/cjs/system/typography.js +12 -3
  20. package/dist/cjs/transforms/index.js +4 -4
  21. package/dist/cjs/utils/color.js +1 -1
  22. package/dist/cjs/utils/font.js +3 -1
  23. package/dist/cjs/utils/sequence.js +35 -16
  24. package/dist/cjs/utils/sprite.js +11 -4
  25. package/dist/cjs/utils/var.js +23 -9
  26. package/dist/esm/defaultConfig/class.js +1 -2
  27. package/dist/esm/defaultConfig/font-family.js +6 -6
  28. package/dist/esm/defaultConfig/icons.js +2 -2
  29. package/dist/esm/defaultConfig/svg.js +2 -2
  30. package/dist/esm/defaultConfig/timing.js +1 -1
  31. package/dist/esm/factory.js +72 -12
  32. package/dist/esm/index.js +6 -4
  33. package/dist/esm/set.js +114 -53
  34. package/dist/esm/system/color.js +72 -12
  35. package/dist/esm/system/document.js +3 -3
  36. package/dist/esm/system/font.js +5 -5
  37. package/dist/esm/system/reset.js +34 -7
  38. package/dist/esm/system/shadow.js +4 -3
  39. package/dist/esm/system/spacing.js +3 -3
  40. package/dist/esm/system/svg.js +34 -7
  41. package/dist/esm/system/theme.js +51 -50
  42. package/dist/esm/system/timing.js +2 -2
  43. package/dist/esm/system/typography.js +12 -3
  44. package/dist/esm/transforms/index.js +4 -4
  45. package/dist/esm/utils/color.js +1 -1
  46. package/dist/esm/utils/font.js +3 -1
  47. package/dist/esm/utils/sequence.js +35 -16
  48. package/dist/esm/utils/sprite.js +11 -4
  49. package/dist/esm/utils/var.js +23 -9
  50. package/dist/iife/index.js +728 -302
  51. package/index.js +1 -0
  52. package/package.json +11 -14
  53. package/src/defaultConfig/class.js +2 -1
  54. package/src/defaultConfig/font-family.js +3 -3
  55. package/src/defaultConfig/icons.js +1 -1
  56. package/src/defaultConfig/svg.js +1 -1
  57. package/src/defaultConfig/timing.js +1 -1
  58. package/src/factory.js +85 -13
  59. package/src/index.js +16 -5
  60. package/src/set.js +156 -63
  61. package/src/system/color.js +113 -12
  62. package/src/system/document.js +3 -3
  63. package/src/system/font.js +5 -5
  64. package/src/system/reset.js +41 -8
  65. package/src/system/shadow.js +4 -3
  66. package/src/system/spacing.js +3 -3
  67. package/src/system/svg.js +44 -7
  68. package/src/system/theme.js +87 -64
  69. package/src/system/timing.js +2 -2
  70. package/src/system/typography.js +12 -3
  71. package/src/transforms/index.js +4 -4
  72. package/src/utils/color.js +2 -1
  73. package/src/utils/font.js +7 -1
  74. package/src/utils/sequence.js +46 -29
  75. package/src/utils/sprite.js +15 -4
  76. package/src/utils/var.js +27 -9
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Scratch framework
2
2
 
3
- Scratch is CSS framework and methodology to build web, mobile and TV applications with one code base.
3
+ Design system factory for Symbols. Receives a configuration and outputs resolved design tokens (colors, themes, fonts, spacing, media queries). In v4, Scratch feeds into the atomic CSS engine (`@symbo.ls/css`) for class generation.
4
4
 
5
5
  [![npm version](https://badge.fury.io/js/%40rackai%2Fscratch.svg)](https://badge.fury.io/js/%40rackai%2Fscratch)
6
6
 
7
- Recevies a configuration and outputs the system of design related properties. It also applies reset by default and receives a few options:
7
+ Receives a configuration and outputs the system of design related properties. It also applies reset by default and receives a few options:
8
8
 
9
9
  | option | default | description |
10
10
  | --- | --- | --- |
@@ -18,8 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var class_exports = {};
20
20
  __export(class_exports, {
21
- CLASS: () => CLASS
21
+ class: () => defaultProps
22
22
  });
23
23
  module.exports = __toCommonJS(class_exports);
24
24
  const defaultProps = {};
25
- const CLASS = defaultProps;
@@ -18,9 +18,9 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var font_family_exports = {};
20
20
  __export(font_family_exports, {
21
- font_face: () => font_face,
22
- font_family: () => font_family,
23
- font_family_types: () => font_family_types
21
+ fontFace: () => fontFace,
22
+ fontFamily: () => fontFamily,
23
+ fontFamilyTypes: () => fontFamilyTypes
24
24
  });
25
25
  module.exports = __toCommonJS(font_family_exports);
26
26
  var defaultFont = {
@@ -29,10 +29,10 @@ var defaultFont = {
29
29
  family: "",
30
30
  type: ""
31
31
  };
32
- const font_family = {};
33
- const font_family_types = {
32
+ const fontFamily = {};
33
+ const fontFamilyTypes = {
34
34
  "sans-serif": "Helvetica, Arial, sans-serif, --system-default",
35
35
  serif: "Times New Roman, Georgia, serif, --system-default",
36
36
  monospace: "Courier New, monospace, --system-default"
37
37
  };
38
- const font_face = {};
38
+ const fontFace = {};
@@ -19,8 +19,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var icons_exports = {};
20
20
  __export(icons_exports, {
21
21
  icons: () => icons,
22
- semantic_icons: () => semantic_icons
22
+ semanticIcons: () => semanticIcons
23
23
  });
24
24
  module.exports = __toCommonJS(icons_exports);
25
25
  const icons = {};
26
- const semantic_icons = {};
26
+ const semanticIcons = {};
@@ -19,8 +19,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var svg_exports = {};
20
20
  __export(svg_exports, {
21
21
  svg: () => svg,
22
- svg_data: () => svg_data
22
+ svgData: () => svgData
23
23
  });
24
24
  module.exports = __toCommonJS(svg_exports);
25
25
  const svg = {};
26
- const svg_data = {};
26
+ const svgData = {};
@@ -21,7 +21,7 @@ __export(timing_exports, {
21
21
  timing: () => timing
22
22
  });
23
23
  module.exports = __toCommonJS(timing_exports);
24
- var import_sequence = require("./sequence");
24
+ var import_sequence = require("./sequence.js");
25
25
  const defaultProps = {
26
26
  default: 150,
27
27
  base: 150,
@@ -29,38 +29,42 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var factory_exports = {};
30
30
  __export(factory_exports, {
31
31
  CONFIG: () => CONFIG,
32
- CSS_MEDIA_VARS: () => CSS_MEDIA_VARS,
33
- CSS_VARS: () => CSS_VARS,
34
32
  FACTORY: () => FACTORY,
35
33
  activateConfig: () => activateConfig,
34
+ createConfig: () => createConfig,
35
+ cssMediaVars: () => cssMediaVars,
36
+ cssVars: () => cssVars,
36
37
  getActiveConfig: () => getActiveConfig,
37
- setActiveConfig: () => setActiveConfig
38
+ popConfig: () => popConfig,
39
+ pushConfig: () => pushConfig,
40
+ setActiveConfig: () => setActiveConfig,
41
+ toCamel: () => toCamel
38
42
  });
39
43
  module.exports = __toCommonJS(factory_exports);
40
- var import_utils = require("@domql/utils");
41
- var CONF = __toESM(require("./defaultConfig"), 1);
42
- const CSS_VARS = {};
43
- const CSS_MEDIA_VARS = {};
44
+ var import_utils = require("@symbo.ls/utils");
45
+ var CONF = __toESM(require("./defaultConfig/index.js"), 1);
46
+ const cssVars = {};
47
+ const cssMediaVars = {};
44
48
  const _CONF = CONF;
45
49
  const _confLower = {};
46
50
  const toCamel = (s) => s.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
47
- const toUpper = (s) => s.replace(/([A-Z])/g, "_$1").toUpperCase();
48
51
  for (const key in _CONF) {
49
52
  const lower = key.toLowerCase();
50
53
  _confLower[lower] = _CONF[key];
51
54
  const camel = toCamel(lower);
52
55
  if (camel !== lower) _confLower[camel] = _CONF[key];
53
56
  if (lower !== key) _confLower[key] = _CONF[key];
54
- const upper = toUpper(key);
55
- if (upper !== key) _confLower[upper] = _CONF[key];
56
57
  }
57
58
  const CONFIG = {
58
59
  verbose: false,
59
60
  useVariable: true,
60
61
  useReset: true,
61
62
  globalTheme: "auto",
62
- CSS_VARS,
63
- CSS_MEDIA_VARS,
63
+ cssVars,
64
+ cssMediaVars,
65
+ CSS_VARS: cssVars,
66
+ CSS_MEDIA_VARS: cssMediaVars,
67
+ _scratchConfig: true,
64
68
  ..._confLower
65
69
  };
66
70
  const cachedConfig = (0, import_utils.deepClone)(CONFIG);
@@ -74,7 +78,15 @@ const activateConfig = (def) => {
74
78
  }
75
79
  return FACTORY[def || FACTORY.active];
76
80
  };
81
+ const configStack = [];
82
+ const pushConfig = (config) => {
83
+ if (config && config._scratchConfig) configStack.push(config);
84
+ };
85
+ const popConfig = () => {
86
+ configStack.pop();
87
+ };
77
88
  const getActiveConfig = (def) => {
89
+ if (configStack.length) return configStack[configStack.length - 1];
78
90
  return FACTORY[def || FACTORY.active] || CONFIG;
79
91
  };
80
92
  const setActiveConfig = (newConfig) => {
@@ -83,3 +95,51 @@ const setActiveConfig = (newConfig) => {
83
95
  FACTORY["1"] = (0, import_utils.deepMerge)(newConfig, (0, import_utils.deepClone)(cachedConfig));
84
96
  return newConfig;
85
97
  };
98
+ const APP_FLAGS = [
99
+ "useReset",
100
+ "useVariable",
101
+ "useFontImport",
102
+ "useIconSprite",
103
+ "useSvgSprite",
104
+ "useDocumentTheme",
105
+ "useDefaultIcons",
106
+ "useDefaultConfig",
107
+ "verbose",
108
+ "globalTheme"
109
+ ];
110
+ const ALIAS_GROUPS = [
111
+ ["fontfamily", "fontFamily", "font_family"],
112
+ ["fontfamilytypes", "fontFamilyTypes"],
113
+ ["semanticicons", "semanticIcons"],
114
+ ["svgdata", "svgData"]
115
+ ];
116
+ const aliasCaseVariants = (cfg) => {
117
+ for (const vs of ALIAS_GROUPS) {
118
+ let merged;
119
+ for (const v of vs) {
120
+ const val = cfg[v];
121
+ if (!(0, import_utils.isObject)(val)) continue;
122
+ merged = merged ? (0, import_utils.deepMerge)(val, merged) : val;
123
+ }
124
+ if (!merged) continue;
125
+ for (const v of vs) if ((0, import_utils.isObject)(cfg[v])) cfg[v] = merged;
126
+ }
127
+ };
128
+ const createConfig = (name, overrides, { cleanBase = false } = {}) => {
129
+ const activeBase = cleanBase ? null : getActiveConfig();
130
+ const base = (0, import_utils.deepClone)(
131
+ !cleanBase && activeBase && activeBase._scratchConfig ? activeBase : cachedConfig
132
+ );
133
+ for (const flag of APP_FLAGS) {
134
+ delete base[flag];
135
+ }
136
+ const cfg = (0, import_utils.deepMerge)(overrides || {}, base);
137
+ cfg.cssVars = {};
138
+ cfg.cssMediaVars = {};
139
+ cfg.CSS_VARS = cfg.cssVars;
140
+ cfg.CSS_MEDIA_VARS = cfg.cssMediaVars;
141
+ cfg._scratchConfig = true;
142
+ aliasCaseVariants(cfg);
143
+ if (name) FACTORY[name] = cfg;
144
+ return cfg;
145
+ };
package/dist/cjs/index.js CHANGED
@@ -29,15 +29,17 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
29
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
30
  var index_exports = {};
31
31
  __export(index_exports, {
32
+ scratchDefaultConfig: () => scratchDefaultConfig,
32
33
  scratchSystem: () => scratchSystem,
33
34
  scratchUtils: () => scratchUtils
34
35
  });
35
36
  module.exports = __toCommonJS(index_exports);
36
37
  var scratchUtils = __toESM(require("./utils/index.js"), 1);
37
38
  var scratchSystem = __toESM(require("./system/index.js"), 1);
39
+ var scratchDefaultConfig = __toESM(require("./defaultConfig/index.js"), 1);
38
40
  __reExport(index_exports, require("./factory.js"), module.exports);
39
- __reExport(index_exports, require("./defaultConfig"), module.exports);
40
- __reExport(index_exports, require("./system"), module.exports);
41
- __reExport(index_exports, require("./utils"), module.exports);
42
- __reExport(index_exports, require("./transforms"), module.exports);
41
+ __reExport(index_exports, require("./defaultConfig/index.js"), module.exports);
42
+ __reExport(index_exports, require("./system/index.js"), module.exports);
43
+ __reExport(index_exports, require("./utils/index.js"), module.exports);
44
+ __reExport(index_exports, require("./transforms/index.js"), module.exports);
43
45
  __reExport(index_exports, require("./set.js"), module.exports);
package/dist/cjs/set.js CHANGED
@@ -26,13 +26,13 @@ __export(set_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(set_exports);
28
28
  var import_factory = require("./factory.js");
29
- var import_system = require("./system");
30
- var import_utils = require("@domql/utils");
29
+ var import_system = require("./system/index.js");
30
+ var import_utils = require("@symbo.ls/utils");
31
31
  const setVars = (val, key) => {
32
32
  const CONFIG = (0, import_factory.getActiveConfig)();
33
- const { CSS_VARS } = CONFIG;
33
+ const { cssVars } = CONFIG;
34
34
  const varName = key.startsWith("--") ? key : `--${key}`;
35
- CSS_VARS[varName] = val;
35
+ cssVars[varName] = val;
36
36
  return val;
37
37
  };
38
38
  const asIs = (val) => val;
@@ -40,14 +40,14 @@ const VALUE_TRANSFORMERS = {
40
40
  color: import_system.setColor,
41
41
  gradient: import_system.setGradient,
42
42
  font: import_system.setFont,
43
- font_family: import_system.setFontFamily,
43
+ fontFamily: import_system.setFontFamily,
44
44
  fontfamily: import_system.setFontFamily,
45
45
  theme: import_system.setTheme,
46
46
  icons: import_system.setSvgIcon,
47
- semantic_icons: asIs,
47
+ semanticIcons: asIs,
48
48
  semanticicons: asIs,
49
49
  svg: import_system.setSVG,
50
- svg_data: asIs,
50
+ svgData: asIs,
51
51
  typography: asIs,
52
52
  shadow: import_system.setShadow,
53
53
  spacing: asIs,
@@ -62,12 +62,14 @@ const VALUE_TRANSFORMERS = {
62
62
  };
63
63
  const setValue = (factoryName, value, key) => {
64
64
  const CONFIG = (0, import_factory.getActiveConfig)();
65
- const lowerName = factoryName.toLowerCase();
66
- const FACTORY2 = CONFIG[lowerName] || CONFIG[factoryName];
67
- if (VALUE_TRANSFORMERS[lowerName]) {
65
+ const camelName = (0, import_factory.toCamel)(factoryName);
66
+ const lowerName = camelName.toLowerCase();
67
+ const FACTORY2 = CONFIG[camelName] || CONFIG[lowerName] || CONFIG[factoryName];
68
+ const transformer = VALUE_TRANSFORMERS[camelName] || VALUE_TRANSFORMERS[lowerName];
69
+ if (transformer) {
68
70
  try {
69
- const result = VALUE_TRANSFORMERS[lowerName](value, key);
70
- FACTORY2[key] = result;
71
+ const result = transformer(value, key);
72
+ if (FACTORY2) FACTORY2[key] = result;
71
73
  return FACTORY2;
72
74
  } catch (error) {
73
75
  if (CONFIG.verbose)
@@ -80,7 +82,11 @@ const setValue = (factoryName, value, key) => {
80
82
  const setEach = (factoryName, props) => {
81
83
  const CONFIG = (0, import_factory.getActiveConfig)();
82
84
  const lowerName = factoryName.toLowerCase();
83
- const keys = Object.keys(props);
85
+ const keys = Object.keys(props).sort((a, b) => {
86
+ const aComposite = (0, import_utils.isObject)(props[a]) || (0, import_utils.isArray)(props[a]) ? 1 : 0;
87
+ const bComposite = (0, import_utils.isObject)(props[b]) || (0, import_utils.isArray)(props[b]) ? 1 : 0;
88
+ return aComposite - bComposite;
89
+ });
84
90
  keys.forEach((key) => {
85
91
  try {
86
92
  return setValue(lowerName, props[key], key);
@@ -98,33 +104,59 @@ const setEach = (factoryName, props) => {
98
104
  });
99
105
  return CONFIG[lowerName] || CONFIG[factoryName];
100
106
  };
101
- const changeGlobalTheme = (newTheme) => {
102
- const CONFIG = (0, import_factory.getActiveConfig)();
107
+ const changeGlobalTheme = (newTheme, targetConfig) => {
108
+ const CONFIG = targetConfig || (0, import_factory.getActiveConfig)();
103
109
  CONFIG.globalTheme = newTheme;
104
- if (typeof document !== "undefined" && newTheme && newTheme !== "auto") {
105
- document.documentElement.setAttribute("data-theme", newTheme);
106
- }
107
- for (const key in CONFIG.CSS_VARS) {
108
- if (key.startsWith("--theme-")) delete CONFIG.CSS_VARS[key];
110
+ const configDoc = CONFIG.document && CONFIG.document.documentElement ? CONFIG.document : null;
111
+ const targetDoc = configDoc || (typeof document !== "undefined" ? document : null);
112
+ const targetWin = targetDoc && targetDoc.defaultView || (typeof window !== "undefined" ? window : null);
113
+ if (targetDoc) {
114
+ const root = CONFIG.themeRoot || targetDoc.documentElement;
115
+ const forced = newTheme && newTheme !== "auto";
116
+ if (forced) {
117
+ root.setAttribute("data-theme", newTheme);
118
+ if (newTheme === "dark" || newTheme === "light") {
119
+ root.style.colorScheme = newTheme;
120
+ } else {
121
+ root.style.colorScheme = "light dark";
122
+ }
123
+ } else if (targetWin && targetWin.matchMedia) {
124
+ const apply = (mq2) => {
125
+ root.setAttribute("data-theme", mq2.matches ? "dark" : "light");
126
+ };
127
+ const mq = targetWin.matchMedia("(prefers-color-scheme: dark)");
128
+ apply(mq);
129
+ root.style.colorScheme = "light dark";
130
+ if (!CONFIG.__prefersListener) {
131
+ CONFIG.__prefersListener = apply;
132
+ try {
133
+ mq.addEventListener("change", apply);
134
+ } catch (e) {
135
+ mq.addListener(apply);
136
+ }
137
+ }
138
+ } else {
139
+ root.setAttribute("data-theme", "light");
140
+ root.style.colorScheme = "light";
141
+ }
109
142
  }
110
- for (const key in CONFIG.CSS_MEDIA_VARS) {
111
- delete CONFIG.CSS_MEDIA_VARS[key];
143
+ const themeVarPrefix = CONFIG.varPrefix ? `--${CONFIG.varPrefix}-theme-` : "--theme-";
144
+ for (const key in CONFIG.cssVars) {
145
+ if (key.startsWith(themeVarPrefix)) delete CONFIG.cssVars[key];
112
146
  }
113
- const source = CONFIG._originalTheme || CONFIG.theme;
114
- if (source) {
115
- const fresh = JSON.parse(JSON.stringify(source));
116
- CONFIG.theme = fresh;
117
- setEach("theme", fresh);
147
+ for (const key in CONFIG.cssMediaVars) {
148
+ delete CONFIG.cssMediaVars[key];
118
149
  }
119
- if (typeof document !== "undefined" && CONFIG.CSS_VARS) {
120
- const sheets = document.styleSheets;
150
+ if (targetDoc && CONFIG.cssVars) {
151
+ const targetSelector = CONFIG.scopeSelector || ":root";
152
+ const sheets = targetDoc.styleSheets;
121
153
  for (let i = 0; i < sheets.length; i++) {
122
154
  try {
123
155
  const rules = sheets[i].cssRules;
124
156
  for (let j = 0; j < rules.length; j++) {
125
- if (rules[j].selectorText === ":root") {
126
- for (const key in CONFIG.CSS_VARS) {
127
- rules[j].style.setProperty(key, CONFIG.CSS_VARS[key]);
157
+ if (rules[j].selectorText === targetSelector) {
158
+ for (const key in CONFIG.cssVars) {
159
+ rules[j].style.setProperty(key, CONFIG.cssVars[key]);
128
160
  }
129
161
  return CONFIG;
130
162
  }
@@ -137,7 +169,7 @@ const changeGlobalTheme = (newTheme) => {
137
169
  };
138
170
  const SET_OPTIONS = {};
139
171
  const set = (recivedConfig, options = SET_OPTIONS) => {
140
- let CONFIG = (0, import_factory.getActiveConfig)();
172
+ let CONFIG = options.config || (0, import_factory.getActiveConfig)();
141
173
  const {
142
174
  version,
143
175
  verbose,
@@ -147,19 +179,19 @@ const set = (recivedConfig, options = SET_OPTIONS) => {
147
179
  useFontImport,
148
180
  useIconSprite,
149
181
  globalTheme,
182
+ themeRoot,
150
183
  useDocumentTheme,
151
184
  useDefaultConfig,
152
185
  semanticIcons,
153
- SEMANTIC_ICONS,
154
- // deprecated
155
- semantic_icons,
156
186
  files,
187
+ assets,
157
188
  ...config
158
189
  } = recivedConfig;
159
190
  if (options.newConfig) {
160
191
  CONFIG = (0, import_factory.setActiveConfig)(options.newConfig);
161
192
  }
162
193
  if (files !== void 0) CONFIG.files = files;
194
+ if (assets !== void 0) CONFIG.assets = assets;
163
195
  if (verbose !== void 0) CONFIG.verbose = verbose;
164
196
  if (useVariable !== void 0) CONFIG.useVariable = useVariable;
165
197
  if (useReset !== void 0) CONFIG.useReset = useReset;
@@ -168,20 +200,46 @@ const set = (recivedConfig, options = SET_OPTIONS) => {
168
200
  if (useIconSprite !== void 0) CONFIG.useIconSprite = useIconSprite;
169
201
  if (useDocumentTheme !== void 0) CONFIG.useDocumentTheme = useDocumentTheme;
170
202
  if (globalTheme !== void 0) CONFIG.globalTheme = globalTheme;
203
+ if (themeRoot !== void 0) CONFIG.themeRoot = themeRoot;
171
204
  if (recivedConfig.useThemeSuffixedVars !== void 0)
172
205
  CONFIG.useThemeSuffixedVars = recivedConfig.useThemeSuffixedVars;
173
206
  if (useDefaultConfig !== void 0) CONFIG.useDefaultConfig = useDefaultConfig;
174
- const _semanticIcons = semanticIcons || SEMANTIC_ICONS || semantic_icons;
175
- if (_semanticIcons !== void 0) {
176
- CONFIG.semantic_icons = _semanticIcons;
177
- CONFIG.semanticIcons = CONFIG.semantic_icons;
178
- CONFIG.SEMANTIC_ICONS = CONFIG.semantic_icons;
179
- }
207
+ if (semanticIcons !== void 0) CONFIG.semanticIcons = semanticIcons;
180
208
  if (CONFIG.verbose) console.log(CONFIG);
181
- if (typeof document !== "undefined" && CONFIG.globalTheme && CONFIG.globalTheme !== "auto") {
182
- document.documentElement.setAttribute("data-theme", CONFIG.globalTheme);
209
+ const setConfigDoc = CONFIG.document && CONFIG.document.documentElement ? CONFIG.document : null;
210
+ const setTargetDoc = setConfigDoc || (typeof document !== "undefined" ? document : null);
211
+ const setTargetWin = setTargetDoc && setTargetDoc.defaultView || (typeof window !== "undefined" ? window : null);
212
+ const setRoot = setTargetDoc && (CONFIG.themeRoot || setTargetDoc.documentElement);
213
+ if (setRoot && typeof setRoot.setAttribute === "function") {
214
+ const forced = CONFIG.globalTheme && CONFIG.globalTheme !== "auto";
215
+ if (forced) {
216
+ setRoot.setAttribute("data-theme", CONFIG.globalTheme);
217
+ if (CONFIG.globalTheme === "dark" || CONFIG.globalTheme === "light") {
218
+ setRoot.style.colorScheme = CONFIG.globalTheme;
219
+ } else {
220
+ setRoot.style.colorScheme = "light dark";
221
+ }
222
+ } else if (setTargetWin && setTargetWin.matchMedia) {
223
+ const apply = (mq2) => {
224
+ setRoot.setAttribute("data-theme", mq2.matches ? "dark" : "light");
225
+ };
226
+ const mq = setTargetWin.matchMedia("(prefers-color-scheme: dark)");
227
+ apply(mq);
228
+ setRoot.style.colorScheme = "light dark";
229
+ if (!CONFIG.__prefersListener) {
230
+ CONFIG.__prefersListener = apply;
231
+ try {
232
+ mq.addEventListener("change", apply);
233
+ } catch (e) {
234
+ mq.addListener(apply);
235
+ }
236
+ }
237
+ } else {
238
+ setRoot.setAttribute("data-theme", "light");
239
+ setRoot.style.colorScheme = "light";
240
+ }
183
241
  }
184
- if (!CONFIG.__svg_cache) CONFIG.__svg_cache = {};
242
+ if (!CONFIG.__svgCache) CONFIG.__svgCache = {};
185
243
  const keys = Object.keys(config);
186
244
  const keySet = new Set(keys);
187
245
  keys.forEach((key) => {
@@ -190,29 +248,31 @@ const set = (recivedConfig, options = SET_OPTIONS) => {
190
248
  (0, import_utils.deepMerge)(config[lower], config[key]);
191
249
  }
192
250
  });
193
- if (config.theme && !CONFIG._originalTheme) {
194
- CONFIG._originalTheme = JSON.parse(JSON.stringify(config.theme));
195
- }
196
251
  keys.map((key) => {
197
252
  const lower = key.toLowerCase();
198
253
  if (lower !== key && keySet.has(lower)) return;
199
254
  return setEach(key, config[key]);
200
255
  });
201
- if (config.typography || config.TYPOGRAPHY) {
256
+ if (CONFIG.varPrefix) {
257
+ if (CONFIG.typography) CONFIG.typography.varPrefix = CONFIG.varPrefix;
258
+ if (CONFIG.spacing) CONFIG.spacing.varPrefix = CONFIG.varPrefix;
259
+ if (CONFIG.timing) CONFIG.timing.varPrefix = CONFIG.varPrefix;
260
+ }
261
+ if (config.typography) {
202
262
  try {
203
263
  (0, import_system.applyTypographySequence)();
204
264
  } catch (e) {
205
265
  if (CONFIG.verbose) console.warn("Error applying typography sequence", e);
206
266
  }
207
267
  }
208
- if (config.spacing || config.SPACING) {
268
+ if (config.spacing) {
209
269
  try {
210
270
  (0, import_system.applySpacingSequence)();
211
271
  } catch (e) {
212
272
  if (CONFIG.verbose) console.warn("Error applying spacing sequence", e);
213
273
  }
214
274
  }
215
- if (config.timing || config.TIMING) {
275
+ if (config.timing) {
216
276
  try {
217
277
  (0, import_system.applyTimingSequence)();
218
278
  } catch (e) {
@@ -220,6 +280,7 @@ const set = (recivedConfig, options = SET_OPTIONS) => {
220
280
  }
221
281
  }
222
282
  (0, import_system.applyDocument)();
223
- (0, import_system.applyReset)();
283
+ const computedReset = (0, import_system.applyReset)();
284
+ if (computedReset) CONFIG.reset = computedReset;
224
285
  return CONFIG;
225
286
  };
@@ -24,9 +24,9 @@ __export(color_exports, {
24
24
  setGradient: () => setGradient
25
25
  });
26
26
  module.exports = __toCommonJS(color_exports);
27
- var import_utils = require("@domql/utils");
27
+ var import_utils = require("@symbo.ls/utils");
28
28
  var import_factory = require("../factory.js");
29
- var import_utils2 = require("../utils");
29
+ var import_utils2 = require("../utils/index.js");
30
30
  const getColor = (value, key, config) => {
31
31
  const CONFIG = config || (0, import_factory.getActiveConfig)();
32
32
  if (!(0, import_utils.isString)(value)) {
@@ -98,11 +98,14 @@ const getMediaColor = (value, globalTheme, config) => {
98
98
  const isObj = (0, import_utils.isObject)(val);
99
99
  if (isObj && val.value) return getColor(value, `@${globalTheme}`, config);
100
100
  else if (isObj) {
101
+ if (CONFIG.useVariable && val.var) return `var(${val.var})`;
101
102
  if (globalTheme) return getColor(value, `@${globalTheme}`, config);
102
103
  else {
103
104
  const obj = {};
104
105
  for (const mediaName in val) {
106
+ if (mediaName.charCodeAt(0) !== 64) continue;
105
107
  const query = CONFIG.media[mediaName.slice(1)];
108
+ if (!query) continue;
106
109
  const media = "@media " + (query === "print" ? `${query}` : `screen and ${query}`);
107
110
  obj[media] = getColor(value, mediaName, config);
108
111
  }
@@ -120,7 +123,11 @@ const setColor = (val, key, suffix) => {
120
123
  val = getColor(rawRef);
121
124
  if (!(val.includes("rgb") || val.includes("var") || val.includes("#"))) {
122
125
  const parts = rawRef.split(" ");
123
- const refColor = CONFIG.color[parts[0]];
126
+ let refColor = CONFIG.color[parts[0]];
127
+ if (refColor && !refColor.value && !refColor.rgb && ((0, import_utils.isString)(refColor) || (0, import_utils.isArray)(refColor) || (0, import_utils.isObject)(refColor))) {
128
+ CONFIG.color[parts[0]] = setColor(refColor, parts[0]);
129
+ refColor = CONFIG.color[parts[0]];
130
+ }
124
131
  if (refColor && refColor.value) {
125
132
  let rgb2 = refColor.rgb;
126
133
  const alpha2 = parts[1] !== void 0 ? parts[1] : "1";
@@ -151,10 +158,7 @@ const setColor = (val, key, suffix) => {
151
158
  }
152
159
  }
153
160
  if ((0, import_utils.isArray)(val)) {
154
- return {
155
- "@light": setColor(val[0], key, "light"),
156
- "@dark": setColor(val[1], key, "dark")
157
- };
161
+ val = { "@light": val[0], "@dark": val[1] };
158
162
  }
159
163
  if ((0, import_utils.isObject)(val)) {
160
164
  const obj = {};
@@ -165,16 +169,71 @@ const setColor = (val, key, suffix) => {
165
169
  variant.slice(0, 1) === "@" ? variant.slice(1) : variant
166
170
  );
167
171
  }
172
+ if (CONFIG.useVariable) {
173
+ const vp2 = CONFIG.varPrefix ? CONFIG.varPrefix + "-" : "";
174
+ const adaptiveVar = `--${vp2}color-${key}`;
175
+ let fallbackValue;
176
+ const schemeValues = {};
177
+ for (const variant in obj) {
178
+ if (variant.charCodeAt(0) !== 64) continue;
179
+ const scheme = variant.slice(1);
180
+ const entry = obj[variant];
181
+ const value2 = entry && (entry.value || entry);
182
+ if (!value2 || typeof value2 !== "string") continue;
183
+ schemeValues[scheme] = value2;
184
+ if (scheme === "light" || fallbackValue === void 0) fallbackValue = value2;
185
+ }
186
+ if (fallbackValue !== void 0) {
187
+ CONFIG.cssVars[adaptiveVar] = fallbackValue;
188
+ if (!CONFIG.cssMediaVars) CONFIG.cssMediaVars = {};
189
+ for (const scheme in schemeValues) {
190
+ const sel = `[data-theme="${scheme}"]`;
191
+ if (!CONFIG.cssMediaVars[sel]) CONFIG.cssMediaVars[sel] = {};
192
+ CONFIG.cssMediaVars[sel][adaptiveVar] = schemeValues[scheme];
193
+ if (scheme === "light" || scheme === "dark") {
194
+ const mq = `@media (prefers-color-scheme: ${scheme})`;
195
+ if (!CONFIG.cssMediaVars[mq]) CONFIG.cssMediaVars[mq] = {};
196
+ CONFIG.cssMediaVars[mq][adaptiveVar] = schemeValues[scheme];
197
+ }
198
+ }
199
+ obj.var = adaptiveVar;
200
+ }
201
+ }
168
202
  return obj;
169
203
  }
170
- const CSSVar = `--color-${key}` + (suffix ? `-${suffix}` : "");
171
- const colorArr = (0, import_utils2.colorStringToRgbaArray)(val.value || val);
204
+ const vp = CONFIG.varPrefix ? CONFIG.varPrefix + "-" : "";
205
+ const CSSVar = `--${vp}color-${key}` + (suffix ? `-${suffix}` : "");
206
+ let resolvedVal = val.value || val;
207
+ if ((0, import_utils.isString)(resolvedVal) && resolvedVal.includes(".") && !resolvedVal.includes("(")) {
208
+ const [colorRef, alphaStr] = resolvedVal.split(".");
209
+ const refColor = CONFIG.color[colorRef];
210
+ if (refColor && refColor.rgb) {
211
+ resolvedVal = `rgba(${refColor.rgb}, ${parseFloat("0." + alphaStr) || 1})`;
212
+ }
213
+ }
214
+ if ((0, import_utils.isString)(resolvedVal) && !resolvedVal.includes("(") && !resolvedVal.startsWith("#")) {
215
+ const parsed = (0, import_utils2.parseColorToken)(resolvedVal);
216
+ if (parsed && parsed.name && !parsed.passthrough && !parsed.cssVar) {
217
+ const refColor = CONFIG.color[parsed.name];
218
+ if (refColor && !refColor.value && !refColor.rgb && ((0, import_utils.isString)(refColor) || (0, import_utils.isArray)(refColor) || (0, import_utils.isObject)(refColor))) {
219
+ CONFIG.color[parsed.name] = setColor(refColor, parsed.name);
220
+ }
221
+ const baseColor = CONFIG.color[parsed.name];
222
+ if (baseColor && baseColor.rgb) {
223
+ let rgb2 = baseColor.rgb;
224
+ if (parsed.tone) rgb2 = (0, import_utils2.getRgbTone)(rgb2, parsed.tone);
225
+ const alphaVal = parsed.alpha ? parseFloat(parsed.alpha) : 1;
226
+ resolvedVal = `rgba(${rgb2}, ${alphaVal})`;
227
+ }
228
+ }
229
+ }
230
+ const colorArr = (0, import_utils2.colorStringToRgbaArray)(resolvedVal);
172
231
  const [r, g, b, a = 1] = colorArr;
173
232
  const alpha = parseFloat(a.toFixed(2));
174
233
  const rgb = `${r}, ${g}, ${b}`;
175
234
  const value = `rgba(${rgb}, ${alpha})`;
176
235
  if (CONFIG.useVariable) {
177
- CONFIG.CSS_VARS[CSSVar] = value;
236
+ CONFIG.cssVars[CSSVar] = value;
178
237
  }
179
238
  return {
180
239
  var: CSSVar,
@@ -197,9 +256,10 @@ const setGradient = (val, key, suffix) => {
197
256
  for (const variant in val) obj[variant] = setGradient(val[variant], key, variant.slice(0, 1) === "@" ? variant.slice(1) : variant);
198
257
  return obj;
199
258
  }
200
- const CSSVar = `--gradient-${key}` + (suffix ? `-${suffix}` : "");
259
+ const vp = CONFIG.varPrefix ? CONFIG.varPrefix + "-" : "";
260
+ const CSSVar = `--${vp}gradient-${key}` + (suffix ? `-${suffix}` : "");
201
261
  if (CONFIG.useVariable) {
202
- CONFIG.CSS_VARS[CSSVar] = val.value || val;
262
+ CONFIG.cssVars[CSSVar] = val.value || val;
203
263
  }
204
264
  return {
205
265
  var: CSSVar,
@@ -21,12 +21,12 @@ __export(document_exports, {
21
21
  applyDocument: () => applyDocument
22
22
  });
23
23
  module.exports = __toCommonJS(document_exports);
24
- var import_utils = require("@domql/utils");
24
+ var import_utils = require("@symbo.ls/utils");
25
25
  var import_factory = require("../factory.js");
26
- var import_utils2 = require("../utils");
26
+ var import_utils2 = require("../utils/index.js");
27
27
  const applyDocument = () => {
28
28
  const CONFIG = (0, import_factory.getActiveConfig)();
29
- const { document: DOCUMENT, font_family: FONT_FAMILY, theme: THEME, typography: TYPOGRAPHY } = CONFIG;
29
+ const { document: DOCUMENT, fontFamily: FONT_FAMILY, theme: THEME, typography: TYPOGRAPHY } = CONFIG;
30
30
  return (0, import_utils.merge)(DOCUMENT, {
31
31
  theme: THEME.document,
32
32
  fontFamily: (0, import_utils2.getDefaultOrFirstKey)(FONT_FAMILY),