diff --git a/js/src/utilities/get-style.js b/js/src/utilities/get-style.js index 8287eb36ff..5b8ca67fe8 100644 --- a/js/src/utilities/get-style.js +++ b/js/src/utilities/get-style.js @@ -7,17 +7,33 @@ const getCssCustomProperties = () => { const cssCustomProperties = {} - let root = Object.entries(document.styleSheets).filter((value) => value[1].cssText.substring(0, ':root'.length) === ':root') - if (root.length === 0) { - root = Object.entries(document.styleSheets) + const sheets = document.styleSheets + let cssText = '' + for (let i = sheets.length - 1; i > -1; i--) { + const rules = sheets[i].cssRules + for (let j = rules.length - 1; j > -1; j--) { + if (rules[j].selectorText === '.ie-custom-properties') { + cssText = rules[j].cssText + break + } + } + if (cssText) { + break + } } - const rule = Object.entries(root[0][1].cssRules).filter((value) => value[1].selectorText === '.ie-custom-properties') - const cssText = rule[0][1].style.cssText + + cssText = cssText.substring( + cssText.lastIndexOf('{') + 1, + cssText.lastIndexOf('}') + ) + cssText.split(';').forEach((property) => { if (property) { const name = property.split(': ')[0] const value = property.split(': ')[1] - cssCustomProperties[`--${name.trim()}`] = value.trim() + if (name && value) { + cssCustomProperties[`--${name.trim()}`] = value.trim() + } } }) return cssCustomProperties @@ -38,16 +54,4 @@ const getStyle = (property, element = document.body) => { return style } -if (!Object.entries) { - Object.entries = function (obj) { - const ownProps = Object.keys(obj) - let i = ownProps.length - const resArray = new Array(i) - while (i--) { - resArray[i] = [ownProps[i], obj[ownProps[i]]] - } - return resArray - } -} - export default getStyle