-
-
Save 14paxton/70018ca1b4b990db4fbf4edfd1907af8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dumpCSSText(element) { | |
if (!element?.id) { | |
element.id = `${element.tagName}-${Math.floor(Math.random() * 7777)}` | |
} | |
let promises = [] | |
let o = getComputedStyle(element); | |
promises.push(new Promise(function (res, rej) { | |
let s = `#${element.id}{ `; | |
for (let i = 0; i < o.length; i++) { | |
let html = '' | |
s += o[i] + `: ` + o.getPropertyValue(o[i]) + '; '; | |
} | |
s += ` } ` | |
res(s) | |
})); | |
const children = element?.children | |
if (children) { | |
for (let child of children) { | |
promises.push.apply(promises, dumpCSSText(child)) | |
} | |
} | |
return promises; | |
} | |
export const generateRulesAll = async (element) => { | |
let promises = []; | |
promises = dumpCSSText(element) | |
let cssString = '' | |
await Promise.all(promises).then(result => { | |
result.forEach(function (css) { | |
cssString += css | |
}); | |
}) | |
return cssString | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment