| 1 |
import { replaceVibeBlocks } from '@shared/lib/vibe-blocks'; |
| 2 |
import { applyVibeGlobals, applyVibeStyles } from '@shared/lib/vibe-globals'; |
| 3 |
import { getVibes, vibesBySlug } from '@shared/lib/vibes'; |
| 4 |
|
| 5 |
// natural-1 is what the theme already ships, so it contributes nothing. |
| 6 |
const isValidVibe = (selectedVibe) => |
| 7 |
!!selectedVibe && |
| 8 |
typeof selectedVibe === 'string' && |
| 9 |
selectedVibe.trim() !== '' && |
| 10 |
selectedVibe !== 'natural-1'; |
| 11 |
|
| 12 |
// Layout rides along because WordPress derives fluid type from wideSize. |
| 13 |
export const computeVibeAdjustments = async (selectedVibe, variation) => { |
| 14 |
if (!isValidVibe(selectedVibe)) return null; |
| 15 |
|
| 16 |
const vibes = vibesBySlug(await getVibes(selectedVibe)); |
| 17 |
const vibe = vibes[selectedVibe]; |
| 18 |
if (!vibe) return null; |
| 19 |
|
| 20 |
const styles = applyVibeStyles({ |
| 21 |
currentStyles: variation?.styles ?? {}, |
| 22 |
vibeStyles: vibe.styles, |
| 23 |
vibes, |
| 24 |
}); |
| 25 |
|
| 26 |
return { |
| 27 |
settings: applyVibeGlobals({ |
| 28 |
currentSettings: variation?.settings ?? {}, |
| 29 |
vibeSettings: vibe.settings, |
| 30 |
vibes, |
| 31 |
}), |
| 32 |
styles: { |
| 33 |
...styles, |
| 34 |
blocks: replaceVibeBlocks({ |
| 35 |
currentBlocks: styles?.blocks, |
| 36 |
vibeBlocks: vibe.blocks, |
| 37 |
selectedVibe, |
| 38 |
}), |
| 39 |
}, |
| 40 |
}; |
| 41 |
}; |
| 42 |
|