PluginProbe
Extendify / 3.1.4
Extendify v3.1.4
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 / functions / vibes.js

vibes.js in Extendify 3.1.4, at src/AutoLaunch/functions/vibes.js

66 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { getGlobalStyles } from '@auto-launch/functions/theme';
2
3 const isValidVibe = (selectedVibe) =>
4 !!selectedVibe &&
5 typeof selectedVibe === 'string' &&
6 selectedVibe.trim() !== '' &&
7 selectedVibe !== 'natural-1';
8
9 const generateSourceStyleName = (naturalStyleName, targetVibe) =>
10 naturalStyleName.replace('--natural-1--', `--${targetVibe}--`);
11
12 const processBlockVariations = (variations, targetVibe) =>
13 Object.fromEntries(
14 Object.entries(variations).map(([styleName, styleProperties]) => {
15 if (!styleName.includes('--natural-1--')) {
16 return [styleName, { ...styleProperties }];
17 }
18
19 const sourceStyleName = generateSourceStyleName(styleName, targetVibe);
20 const sourceStyle = variations[sourceStyleName];
21
22 return [
23 styleName,
24 sourceStyle ? { ...sourceStyle } : { ...styleProperties },
25 ];
26 }),
27 );
28
29 // Compute the vibe-adjusted blocks from the theme's global styles.
30 // Returns the blocks object (ready to merge into a variation) without
31 // POSTing anything. Callers should merge the result into the variation's
32 // styles before calling updateVariation — doing it this way avoids a
33 // separate POST that would overwrite the fonts, colors and other style
34 // overrides already set in the variation.
35 export const computeVibeAdjustedBlocks = async (selectedVibe) => {
36 if (!isValidVibe(selectedVibe)) return null;
37
38 const { styles: themeStyles } = await getGlobalStyles();
39 if (!themeStyles?.blocks) return null;
40
41 return Object.fromEntries(
42 Object.entries(themeStyles.blocks).map(([blockName, blockObj]) => {
43 if (!blockObj?.variations) {
44 return [blockName, blockObj];
45 }
46
47 const { variations, ...rest } = blockObj;
48 const hasNaturalVariations = Object.keys(variations).some((styleName) =>
49 styleName.includes('--natural-1--'),
50 );
51
52 if (!hasNaturalVariations) {
53 return [blockName, blockObj];
54 }
55
56 return [
57 blockName,
58 {
59 ...rest,
60 variations: processBlockVariations(variations, selectedVibe),
61 },
62 ];
63 }),
64 );
65 };
66