From 6e1c538e4182263a75fb65b0f3c5d1ad9de94541 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 20 Jan 2020 01:31:54 +0200 Subject: multiple fixes to make style switcher not die. Made shadows work, incuding compatibility --- src/services/style_setter/style_setter.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/services/style_setter/style_setter.js') diff --git a/src/services/style_setter/style_setter.js b/src/services/style_setter/style_setter.js index 74af190c..ee264c49 100644 --- a/src/services/style_setter/style_setter.js +++ b/src/services/style_setter/style_setter.js @@ -291,8 +291,8 @@ export const generateShadows = (input, colors, mod) => { const shadows = Object.entries({ ...DEFAULT_SHADOWS, ...(input.shadows || {}) - }).reduce((shadowsAcc, [slotName, shadowdefs]) => { - const newShadow = shadowdefs.reduce((shadowAcc, def) => [ + }).reduce((shadowsAcc, [slotName, shadowDefs]) => { + const newShadow = shadowDefs.reduce((shadowAcc, def) => [ ...shadowAcc, { ...def, @@ -380,6 +380,25 @@ export const getThemes = () => { }) } +/** + * This handles compatibility issues when importing v2 theme's shadows to current format + * + * Back in v2 shadows allowed you to use dynamic colors however those used pure CSS3 variables + */ +export const shadows2to3 = (shadows) => { + return Object.entries(shadows).reduce((shadowsAcc, [slotName, shadowDefs]) => { + const isDynamic = ({ color }) => console.log(color) || color.startsWith('--') + const newShadow = shadowDefs.reduce((shadowAcc, def) => [ + ...shadowAcc, + { + ...def, + alpha: isDynamic(def) ? 1 : def.alpha + } + ], []) + return { ...shadowsAcc, [slotName]: newShadow } + }, {}) +} + export const setPreset = (val, commit) => { return getThemes() .then((themes) => themes[val] ? themes[val] : themes['pleroma-dark']) -- cgit v1.2.3-70-g09d2