PluginProbe
Extendify / 3.1.2
Extendify v3.1.2
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 / Library / util / css.js

css.js in Extendify 3.1.2, at src/Library/util/css.js

48 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import apiFetch from '@wordpress/api-fetch';
2
3 // Add required rules here and they will be checked in Launch
4 // previews and added to Additional CSS
5 export const requiredCSSVars = {
6 '--wp--preset--spacing--30': 'clamp(1.5rem, 5vw, 2rem)',
7 '--wp--preset--spacing--40':
8 'clamp(1.8rem, 1.8rem + ((1vw - 0.48rem) * 2.885), 3rem)',
9 '--wp--preset--spacing--50': 'clamp(2.5rem, 8vw, 4rem)',
10 '--wp--preset--spacing--60': 'clamp(2.5rem, 8vw, 6rem)',
11 '--wp--preset--spacing--70': 'clamp(3.75rem, 10vw, 7rem)',
12 '--wp--preset--spacing--80':
13 'clamp(5rem, 5.25rem + ((1vw - 0.48rem) * 9.096), 8rem)',
14 };
15
16 export const addGlobalCSS = async (missingCSSVars) => {
17 const id = window.extSharedData.globalStylesPostID;
18 const { styles, settings } = await apiFetch({
19 path: `/wp/v2/global-styles/${id}`,
20 });
21 // If any of the rules are already in the CSS, don't add them
22 missingCSSVars = missingCSSVars.filter(
23 (key) => !styles?.css?.includes(`${key}:`),
24 );
25 if (!missingCSSVars.length) return;
26 const reduced = missingCSSVars.reduce((acc, key) => {
27 acc += `${key}: ${requiredCSSVars[key]};\n`;
28 return acc;
29 }, ':root {\n');
30 const missingCSSVarsString = `${reduced}\n}`;
31 apiFetch({
32 path: `/wp/v2/global-styles/${id}`,
33 method: 'PATCH',
34 data: {
35 id,
36 settings,
37 styles: {
38 ...styles,
39 css:
40 // Preserve the existing css
41 (styles?.css ?? '') +
42 (styles?.css ? '\n' : '') +
43 missingCSSVarsString,
44 },
45 },
46 });
47 };
48