neo.mjs 4.7.7 → 4.8.1
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/package.json +1 -1
- package/src/main/addon/Stylesheet.mjs +32 -0
- package/src/worker/App.mjs +29 -1
package/package.json
CHANGED
@@ -31,6 +31,7 @@ class Stylesheet extends Base {
|
|
31
31
|
'createStyleSheet',
|
32
32
|
'deleteCssRules',
|
33
33
|
'insertCssRules',
|
34
|
+
'setCssVariable',
|
34
35
|
'swapStyleSheet'
|
35
36
|
]
|
36
37
|
},
|
@@ -264,6 +265,37 @@ class Stylesheet extends Base {
|
|
264
265
|
}
|
265
266
|
}
|
266
267
|
|
268
|
+
/**
|
269
|
+
* @param {Object} data
|
270
|
+
* @param {String} data.key
|
271
|
+
* @param {String} [data.priority] optionally pass 'important'
|
272
|
+
* @param {String} data.theme
|
273
|
+
* @param {String} data.value
|
274
|
+
*/
|
275
|
+
setCssVariable(data) {
|
276
|
+
let key = data.key,
|
277
|
+
rule, sheet;
|
278
|
+
|
279
|
+
if (!key.startsWith('--')) {
|
280
|
+
key = '--' + key;
|
281
|
+
}
|
282
|
+
|
283
|
+
for (sheet of document.styleSheets) {
|
284
|
+
if (sheet.href.includes(data.theme)) {
|
285
|
+
for (rule of sheet.cssRules) {
|
286
|
+
if (rule.type === 1) { // CSSRule.STYLE_RULE
|
287
|
+
if (rule.style.getPropertyValue(key) !== '') {
|
288
|
+
rule.style.setProperty(key, data.value, data.priority);
|
289
|
+
return true;
|
290
|
+
}
|
291
|
+
}
|
292
|
+
}
|
293
|
+
}
|
294
|
+
}
|
295
|
+
|
296
|
+
return false;
|
297
|
+
}
|
298
|
+
|
267
299
|
/**
|
268
300
|
* @param {Object} data
|
269
301
|
* @param {String} data.href
|
package/src/worker/App.mjs
CHANGED
@@ -55,7 +55,12 @@ class App extends Base {
|
|
55
55
|
*/
|
56
56
|
construct(config) {
|
57
57
|
super.construct(config);
|
58
|
-
|
58
|
+
|
59
|
+
let me = this;
|
60
|
+
|
61
|
+
// convenience shortcuts
|
62
|
+
Neo.applyDeltas = me.applyDeltas .bind(me);
|
63
|
+
Neo.setCssVariable = me.setCssVariable.bind(me);
|
59
64
|
}
|
60
65
|
|
61
66
|
/**
|
@@ -291,6 +296,29 @@ class App extends Base {
|
|
291
296
|
|
292
297
|
me.themeFilesCache = [];
|
293
298
|
}
|
299
|
+
|
300
|
+
/**
|
301
|
+
* @param {Object} data
|
302
|
+
* @param {String} data.key
|
303
|
+
* @param {String} [data.priority] optionally pass 'important'
|
304
|
+
* @param {String} data.theme=Neo.config.themes[0]
|
305
|
+
* @param {String} data.value
|
306
|
+
* @returns {Promise<any>}
|
307
|
+
*/
|
308
|
+
setCssVariable(data) {
|
309
|
+
let addon = Neo.main?.addon?.Stylesheet,
|
310
|
+
theme = Neo.config.themes?.[0];
|
311
|
+
|
312
|
+
if (!addon) {
|
313
|
+
return Promise.reject('Neo.main.addon.Stylesheet not imported');
|
314
|
+
} else {
|
315
|
+
if (theme.startsWith('neo-')) {
|
316
|
+
theme = theme.substring(4);
|
317
|
+
}
|
318
|
+
|
319
|
+
return addon.setCssVariable({theme, ...data});
|
320
|
+
}
|
321
|
+
}
|
294
322
|
}
|
295
323
|
|
296
324
|
let instance = Neo.applyClassConfig(App);
|