-
Notifications
You must be signed in to change notification settings - Fork 48
/
cssUtils.js
28 lines (26 loc) · 995 Bytes
/
cssUtils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
export function getRootCssStyles(rootRule = ":root") {
// Get all CSS rules for the document using Array methods
const cssRulesArray = [...document.styleSheets]
.map(styleSheet => {
try {
return [...styleSheet.cssRules]
.map(rule => rule)
} catch (e) {
// console.log('Access to stylesheet %s is denied. Ignoring...', styleSheet.href);
}
})
var cssVars = [];
// Get custom styles from root css rule
Object.values(cssRulesArray).forEach(arrayElement => {
Object.values(arrayElement).forEach(ruleElement => {
if (ruleElement.selectorText === rootRule) {
Object.values(ruleElement.style).forEach(style => {
if (style.startsWith('--spine-') && cssVars.indexOf(style) == -1) {
cssVars.push(style);
}
})
}
})
})
return cssVars;
}