PluginProbe
Extendify / 2.2.0
Extendify v2.2.0
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 / Launch / lib / preview-helpers.js

preview-helpers.js in Extendify 2.2.0, at src/Launch/lib/preview-helpers.js

45 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 const FONT_VAR_PREFIX = '--wp--preset--font-family';
2 const HEADING_FONT_VAR_KEY = '--wp--preset--font-family--heading';
3 const BODY_FONT_VAR_KEY = '--wp--preset--font-family--body';
4
5 // Generates font links and styles from custom variations to override fonts in `theme-processed.json`
6 export const getFontOverrides = (variation) => {
7 let customFontLinks = '';
8 let fontOverrides = '';
9
10 if (!variation?.title) {
11 return { customFontLinks, fontOverrides };
12 }
13
14 // These values look like `var(--wp--preset--font-family--${fontFamilySlug})`
15 const headingFontVarValue =
16 variation.styles?.elements?.heading?.typography?.fontFamily;
17 const bodyFontVarValue = variation.styles?.typography?.fontFamily;
18 const customFonts =
19 variation.settings?.typography?.fontFamilies?.custom ?? [];
20
21 if (headingFontVarValue) {
22 fontOverrides += `:root { ${HEADING_FONT_VAR_KEY}: ${headingFontVarValue}; }`;
23 fontOverrides += `h1, h2, h3, h4, h5, h6 { font-family: ${headingFontVarValue} !important; }`;
24 }
25
26 if (bodyFontVarValue) {
27 fontOverrides += `:root { ${BODY_FONT_VAR_KEY}: ${bodyFontVarValue}; }`;
28 fontOverrides += `body { font-family: ${bodyFontVarValue} !important; }`;
29 }
30
31 for (const font of customFonts) {
32 const customFontLink = `<link id="ext-custom-font-${font.slug}" rel="stylesheet" href="${font.css}">`;
33 if (!customFontLinks.includes(customFontLink)) {
34 customFontLinks += customFontLink;
35 }
36
37 const fontOverride = `:root { ${FONT_VAR_PREFIX}--${font.slug}: "${font.fontFamily}"; }`;
38 if (!fontOverrides.includes(fontOverride)) {
39 fontOverrides += fontOverride;
40 }
41 }
42
43 return { customFontLinks, fontOverrides };
44 };
45