UNPKG

wxt

Version:

⚡ Next-gen Web Extension Framework

22 lines (21 loc) 662 B
//#region src/utils/split-shadow-root-css.ts /** @module wxt/utils/split-shadow-root-css */ const AT_RULE_BLOCKS = /(\s*@(property|font-face)[\s\S]*?{[\s\S]*?})/gm; /** * Given a CSS string that will be loaded into a shadow root, split it into two * parts: * * - `documentCss`: CSS that needs to be applied to the document (like * `@property`) * - `shadowCss`: CSS that needs to be applied to the shadow root * * @param css */ function splitShadowRootCss(css) { return { documentCss: Array.from(css.matchAll(AT_RULE_BLOCKS), (m) => m[0]).join("").trim(), shadowCss: css.replace(AT_RULE_BLOCKS, "").trim() }; } //#endregion export { splitShadowRootCss };