PluginProbe
Extendify / 3.1.4
Extendify v3.1.4
3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 0.7.0 All 126 releases
extendify / src / Agent / lib / custom-css.js

custom-css.js in Extendify 3.1.4, at src/Agent/lib/custom-css.js

24 lines 1013 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // Mirrors WP_Theme_JSON::process_blocks_custom_css — diverge and the preview
2 // shows an effect the save drops, or hides one it keeps.
3 const HAS_MARKUP = /<\/?\w/;
4 const PSEUDO_ELEMENT = /([>+~\s]*::[a-zA-Z-]+)/;
5
6 export const processCustomCss = (css, selector) => {
7 if (!css || HAS_MARKUP.test(css)) return '';
8 return css.split('&').reduce((out, part) => {
9 if (!part) return out;
10 if (!part.includes('{')) {
11 return `${out}:root :where(${selector.trim()}){${part.trim()}}`;
12 }
13 // A bare } makes make-pot skip the file, dropping the bundle's translations.
14 const [nested, declarations, ...rest] = part.replace(/\}/g, '').split('{');
15 if (rest.length || declarations === undefined) return out;
16 const pseudo = nested.match(PSEUDO_ELEMENT)?.[1] ?? '';
17 const bare = pseudo ? nested.replace(pseudo, '') : nested;
18 const scoped = bare.startsWith(' ')
19 ? `${selector} ${bare.trim()}`
20 : `${selector}${bare}`;
21 return `${out}:root :where(${scoped})${pseudo}{${declarations.trim()}}`;
22 }, '');
23 };
24