@symbo.ls/scratch 3.8.6 → 3.8.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.
package/dist/cjs/set.js CHANGED
@@ -101,14 +101,37 @@ const setEach = (factoryName, props) => {
101
101
  const changeGlobalTheme = (newTheme) => {
102
102
  const CONFIG = (0, import_factory.getActiveConfig)();
103
103
  CONFIG.globalTheme = newTheme;
104
+ if (typeof document !== "undefined" && newTheme && newTheme !== "auto") {
105
+ document.documentElement.setAttribute("data-theme", newTheme);
106
+ }
104
107
  for (const key in CONFIG.CSS_VARS) {
105
108
  if (key.startsWith("--theme-")) delete CONFIG.CSS_VARS[key];
106
109
  }
107
110
  for (const key in CONFIG.CSS_MEDIA_VARS) {
108
111
  delete CONFIG.CSS_MEDIA_VARS[key];
109
112
  }
110
- if (CONFIG.theme) {
111
- setEach("theme", CONFIG.theme);
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);
118
+ }
119
+ if (typeof document !== "undefined" && CONFIG.CSS_VARS) {
120
+ const sheets = document.styleSheets;
121
+ for (let i = 0; i < sheets.length; i++) {
122
+ try {
123
+ const rules = sheets[i].cssRules;
124
+ 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]);
128
+ }
129
+ return CONFIG;
130
+ }
131
+ }
132
+ } catch (e) {
133
+ }
134
+ }
112
135
  }
113
136
  return CONFIG;
114
137
  };
@@ -155,6 +178,9 @@ const set = (recivedConfig, options = SET_OPTIONS) => {
155
178
  CONFIG.SEMANTIC_ICONS = CONFIG.semantic_icons;
156
179
  }
157
180
  if (CONFIG.verbose) console.log(CONFIG);
181
+ if (typeof document !== "undefined" && CONFIG.globalTheme && CONFIG.globalTheme !== "auto") {
182
+ document.documentElement.setAttribute("data-theme", CONFIG.globalTheme);
183
+ }
158
184
  if (!CONFIG.__svg_cache) CONFIG.__svg_cache = {};
159
185
  const keys = Object.keys(config);
160
186
  const keySet = new Set(keys);
@@ -164,6 +190,9 @@ const set = (recivedConfig, options = SET_OPTIONS) => {
164
190
  (0, import_utils.deepMerge)(config[lower], config[key]);
165
191
  }
166
192
  });
193
+ if (config.theme && !CONFIG._originalTheme) {
194
+ CONFIG._originalTheme = JSON.parse(JSON.stringify(config.theme));
195
+ }
167
196
  keys.map((key) => {
168
197
  const lower = key.toLowerCase();
169
198
  if (lower !== key && keySet.has(lower)) return;
package/dist/esm/set.js CHANGED
@@ -88,14 +88,37 @@ const setEach = (factoryName, props) => {
88
88
  const changeGlobalTheme = (newTheme) => {
89
89
  const CONFIG = getActiveConfig();
90
90
  CONFIG.globalTheme = newTheme;
91
+ if (typeof document !== "undefined" && newTheme && newTheme !== "auto") {
92
+ document.documentElement.setAttribute("data-theme", newTheme);
93
+ }
91
94
  for (const key in CONFIG.CSS_VARS) {
92
95
  if (key.startsWith("--theme-")) delete CONFIG.CSS_VARS[key];
93
96
  }
94
97
  for (const key in CONFIG.CSS_MEDIA_VARS) {
95
98
  delete CONFIG.CSS_MEDIA_VARS[key];
96
99
  }
97
- if (CONFIG.theme) {
98
- setEach("theme", CONFIG.theme);
100
+ const source = CONFIG._originalTheme || CONFIG.theme;
101
+ if (source) {
102
+ const fresh = JSON.parse(JSON.stringify(source));
103
+ CONFIG.theme = fresh;
104
+ setEach("theme", fresh);
105
+ }
106
+ if (typeof document !== "undefined" && CONFIG.CSS_VARS) {
107
+ const sheets = document.styleSheets;
108
+ for (let i = 0; i < sheets.length; i++) {
109
+ try {
110
+ const rules = sheets[i].cssRules;
111
+ for (let j = 0; j < rules.length; j++) {
112
+ if (rules[j].selectorText === ":root") {
113
+ for (const key in CONFIG.CSS_VARS) {
114
+ rules[j].style.setProperty(key, CONFIG.CSS_VARS[key]);
115
+ }
116
+ return CONFIG;
117
+ }
118
+ }
119
+ } catch (e) {
120
+ }
121
+ }
99
122
  }
100
123
  return CONFIG;
101
124
  };
@@ -142,6 +165,9 @@ const set = (recivedConfig, options = SET_OPTIONS) => {
142
165
  CONFIG.SEMANTIC_ICONS = CONFIG.semantic_icons;
143
166
  }
144
167
  if (CONFIG.verbose) console.log(CONFIG);
168
+ if (typeof document !== "undefined" && CONFIG.globalTheme && CONFIG.globalTheme !== "auto") {
169
+ document.documentElement.setAttribute("data-theme", CONFIG.globalTheme);
170
+ }
145
171
  if (!CONFIG.__svg_cache) CONFIG.__svg_cache = {};
146
172
  const keys = Object.keys(config);
147
173
  const keySet = new Set(keys);
@@ -151,6 +177,9 @@ const set = (recivedConfig, options = SET_OPTIONS) => {
151
177
  deepMerge(config[lower], config[key]);
152
178
  }
153
179
  });
180
+ if (config.theme && !CONFIG._originalTheme) {
181
+ CONFIG._originalTheme = JSON.parse(JSON.stringify(config.theme));
182
+ }
154
183
  keys.map((key) => {
155
184
  const lower = key.toLowerCase();
156
185
  if (lower !== key && keySet.has(lower)) return;
@@ -182,6 +182,7 @@ var SmblsScratch = (() => {
182
182
  exec = (param, element, state, context) => {
183
183
  if (isFunction(param)) {
184
184
  if (!element) return;
185
+ if (typeof param.call !== "function") return param;
185
186
  const result = param.call(
186
187
  element,
187
188
  element,
@@ -3067,14 +3068,37 @@ var SmblsScratch = (() => {
3067
3068
  var changeGlobalTheme = (newTheme) => {
3068
3069
  const CONFIG2 = getActiveConfig();
3069
3070
  CONFIG2.globalTheme = newTheme;
3071
+ if (typeof document !== "undefined" && newTheme && newTheme !== "auto") {
3072
+ document.documentElement.setAttribute("data-theme", newTheme);
3073
+ }
3070
3074
  for (const key in CONFIG2.CSS_VARS) {
3071
3075
  if (key.startsWith("--theme-")) delete CONFIG2.CSS_VARS[key];
3072
3076
  }
3073
3077
  for (const key in CONFIG2.CSS_MEDIA_VARS) {
3074
3078
  delete CONFIG2.CSS_MEDIA_VARS[key];
3075
3079
  }
3076
- if (CONFIG2.theme) {
3077
- setEach("theme", CONFIG2.theme);
3080
+ const source = CONFIG2._originalTheme || CONFIG2.theme;
3081
+ if (source) {
3082
+ const fresh = JSON.parse(JSON.stringify(source));
3083
+ CONFIG2.theme = fresh;
3084
+ setEach("theme", fresh);
3085
+ }
3086
+ if (typeof document !== "undefined" && CONFIG2.CSS_VARS) {
3087
+ const sheets = document.styleSheets;
3088
+ for (let i = 0; i < sheets.length; i++) {
3089
+ try {
3090
+ const rules = sheets[i].cssRules;
3091
+ for (let j = 0; j < rules.length; j++) {
3092
+ if (rules[j].selectorText === ":root") {
3093
+ for (const key in CONFIG2.CSS_VARS) {
3094
+ rules[j].style.setProperty(key, CONFIG2.CSS_VARS[key]);
3095
+ }
3096
+ return CONFIG2;
3097
+ }
3098
+ }
3099
+ } catch (e) {
3100
+ }
3101
+ }
3078
3102
  }
3079
3103
  return CONFIG2;
3080
3104
  };
@@ -3121,6 +3145,9 @@ var SmblsScratch = (() => {
3121
3145
  CONFIG2.SEMANTIC_ICONS = CONFIG2.semantic_icons;
3122
3146
  }
3123
3147
  if (CONFIG2.verbose) console.log(CONFIG2);
3148
+ if (typeof document !== "undefined" && CONFIG2.globalTheme && CONFIG2.globalTheme !== "auto") {
3149
+ document.documentElement.setAttribute("data-theme", CONFIG2.globalTheme);
3150
+ }
3124
3151
  if (!CONFIG2.__svg_cache) CONFIG2.__svg_cache = {};
3125
3152
  const keys = Object.keys(config);
3126
3153
  const keySet = new Set(keys);
@@ -3130,6 +3157,9 @@ var SmblsScratch = (() => {
3130
3157
  deepMerge(config[lower], config[key]);
3131
3158
  }
3132
3159
  });
3160
+ if (config.theme && !CONFIG2._originalTheme) {
3161
+ CONFIG2._originalTheme = JSON.parse(JSON.stringify(config.theme));
3162
+ }
3133
3163
  keys.map((key) => {
3134
3164
  const lower = key.toLowerCase();
3135
3165
  if (lower !== key && keySet.has(lower)) return;
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.8.6",
5
+ "version": "3.8.7",
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.8.6",
37
- "@symbo.ls/smbls-utils": "^3.8.6",
36
+ "@domql/utils": "^3.8.7",
37
+ "@symbo.ls/smbls-utils": "^3.8.7",
38
38
  "color-contrast-checker": "^1.5.0"
39
39
  },
40
40
  "gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
package/src/set.js CHANGED
@@ -109,6 +109,11 @@ export const changeGlobalTheme = (newTheme) => {
109
109
  const CONFIG = getActiveConfig()
110
110
  CONFIG.globalTheme = newTheme
111
111
 
112
+ // Set data-theme attribute on document element for CSS selector-based theming
113
+ if (typeof document !== 'undefined' && newTheme && newTheme !== 'auto') {
114
+ document.documentElement.setAttribute('data-theme', newTheme)
115
+ }
116
+
112
117
  // Clear theme-related CSS vars
113
118
  for (const key in CONFIG.CSS_VARS) {
114
119
  if (key.startsWith('--theme-')) delete CONFIG.CSS_VARS[key]
@@ -119,9 +124,31 @@ export const changeGlobalTheme = (newTheme) => {
119
124
  delete CONFIG.CSS_MEDIA_VARS[key]
120
125
  }
121
126
 
122
- // Re-process all themes with the new globalTheme
123
- if (CONFIG.theme) {
124
- setEach('theme', CONFIG.theme)
127
+ // Re-process themes from original definitions (not mutated processed ones)
128
+ const source = CONFIG._originalTheme || CONFIG.theme
129
+ if (source) {
130
+ // Deep clone to avoid re-mutating the originals
131
+ const fresh = JSON.parse(JSON.stringify(source))
132
+ CONFIG.theme = fresh
133
+ setEach('theme', fresh)
134
+ }
135
+
136
+ // Apply updated CSS vars to the existing :root stylesheet rule
137
+ if (typeof document !== 'undefined' && CONFIG.CSS_VARS) {
138
+ const sheets = document.styleSheets
139
+ for (let i = 0; i < sheets.length; i++) {
140
+ try {
141
+ const rules = sheets[i].cssRules
142
+ for (let j = 0; j < rules.length; j++) {
143
+ if (rules[j].selectorText === ':root') {
144
+ for (const key in CONFIG.CSS_VARS) {
145
+ rules[j].style.setProperty(key, CONFIG.CSS_VARS[key])
146
+ }
147
+ return CONFIG
148
+ }
149
+ }
150
+ } catch (e) { /* cross-origin stylesheet */ }
151
+ }
125
152
  }
126
153
 
127
154
  return CONFIG
@@ -174,6 +201,11 @@ export const set = (recivedConfig, options = SET_OPTIONS) => {
174
201
  }
175
202
  if (CONFIG.verbose) console.log(CONFIG)
176
203
 
204
+ // Set data-theme attribute on document for CSS selector-based theming
205
+ if (typeof document !== 'undefined' && CONFIG.globalTheme && CONFIG.globalTheme !== 'auto') {
206
+ document.documentElement.setAttribute('data-theme', CONFIG.globalTheme)
207
+ }
208
+
177
209
  if (!CONFIG.__svg_cache) CONFIG.__svg_cache = {}
178
210
 
179
211
  const keys = Object.keys(config)
@@ -187,6 +219,11 @@ export const set = (recivedConfig, options = SET_OPTIONS) => {
187
219
  }
188
220
  })
189
221
 
222
+ // Store original theme definitions before processing mutates them
223
+ if (config.theme && !CONFIG._originalTheme) {
224
+ CONFIG._originalTheme = JSON.parse(JSON.stringify(config.theme))
225
+ }
226
+
190
227
  // Process only lowercase keys (skip UPPERCASE when lowercase equivalent exists)
191
228
  keys.map((key) => {
192
229
  const lower = key.toLowerCase()