PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
3.2.1 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 All 127 releases
extendify / src / AutoLaunch / fetchers / get-style-document.js

get-style-document.js in Extendify 3.2.1, at src/AutoLaunch/fetchers/get-style-document.js

68 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {
2 applyPaletteGlobals,
3 applyPaletteStyles,
4 } from '@shared/lib/palette-globals';
5 import { getServedPalettes, palettesBySlug } from '@shared/lib/palettes';
6 import { deepMerge } from '@shared/lib/utils';
7
8 const empty = { settings: {}, styles: {} };
9
10 // The families ship with the theme; only a hosted font needs installing.
11 const fontLeaves = (fonts) => {
12 const { heading, body } = fonts ?? {};
13 if (!heading?.slug && !body?.slug) return empty;
14
15 return {
16 settings: {
17 typography: {
18 fontFamilies: {
19 custom: [heading, body].filter((font) => !!font?.host),
20 },
21 },
22 },
23 styles: {
24 ...(body?.slug && {
25 typography: {
26 fontFamily: `var(--wp--preset--font-family--${body.slug})`,
27 },
28 }),
29 ...(heading?.slug && {
30 elements: {
31 heading: {
32 typography: {
33 fontFamily: `var(--wp--preset--font-family--${heading.slug})`,
34 },
35 },
36 },
37 }),
38 },
39 };
40 };
41
42 const paletteLeaves = async (colorPalette) => {
43 if (!colorPalette) return empty;
44
45 const palettes = palettesBySlug(
46 await getServedPalettes('launch', colorPalette),
47 );
48 const palette = palettes[colorPalette];
49 // An unresolved slug leaves the theme's own colourway standing.
50 if (!palette) return empty;
51
52 return {
53 settings: applyPaletteGlobals({
54 currentSettings: {},
55 paletteSettings: palette.settings,
56 palettes,
57 }),
58 styles: applyPaletteStyles({
59 currentStyles: {},
60 paletteStyles: palette.styles,
61 palettes,
62 }),
63 };
64 };
65
66 export const getStyleDocument = async ({ colorPalette, fonts }) =>
67 deepMerge(await paletteLeaves(colorPalette), fontLeaves(fonts));
68