neo.mjs 4.7.7 → 4.8.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.
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
|