From 311d93594392c504d6690b5240474e1448a997b5 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 7 Nov 2024 18:34:59 +0200 Subject: [PATCH 1/6] some documentation for functions --- .../theme_data/theme3_slot_functions.js | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/services/theme_data/theme3_slot_functions.js b/src/services/theme_data/theme3_slot_functions.js index 8600217a9..ae644763a 100644 --- a/src/services/theme_data/theme3_slot_functions.js +++ b/src/services/theme_data/theme3_slot_functions.js @@ -15,6 +15,11 @@ export const process = (text, functions, { findColor, findShadow }, { dynamicVar export const colorFunctions = { alpha: { argsNeeded: 2, + documentation: 'Changes alpha value of the color only to be used for CSS variables', + args: [ + 'color: source color used', + 'amount: alpha value' + ], exec: (args, { findColor }, { dynamicVars, staticVars }) => { const [color, amountArg] = args @@ -25,6 +30,11 @@ export const colorFunctions = { }, brightness: { argsNeeded: 2, + document: 'Changes brightness/lightness of color in HSL colorspace', + args: [ + 'color: source color used', + 'amount: lightness value' + ], exec: (args, { findColor }, { dynamicVars, staticVars }) => { const [color, amountArg] = args @@ -35,6 +45,15 @@ export const colorFunctions = { }, textColor: { argsNeeded: 2, + documentation: 'Get text color with adequate contrast for given background and intended text color. Same function is used internally', + args: [ + 'background: color of backdrop where text will be shown', + 'foreground: intended text color', + `[preserve]: (optional) intended color preservation: +'preserve' - try to preserve the color +'no-preserve' - if can't get adequate color - fall back to black or white +'no-auto' - don't do anything (useless as a color function)` + ], exec: (args, { findColor }, { dynamicVars, staticVars }) => { const [backgroundArg, foregroundArg, preserve = 'preserve'] = args @@ -46,6 +65,12 @@ export const colorFunctions = { }, blend: { argsNeeded: 3, + documentation: 'Alpha blending between two colors', + args: [ + 'background: bottom layer color', + 'amount: opacity of top layer', + 'foreground: upper layer color' + ], exec: (args, { findColor }, { dynamicVars, staticVars }) => { const [backgroundArg, amountArg, foregroundArg] = args @@ -58,6 +83,11 @@ export const colorFunctions = { }, mod: { argsNeeded: 2, + documentation: 'Old function that increases or decreases brightness depending if color is dark or light. Advised against using it as it might give unexpected results.', + args: [ + 'color: source color', + 'amount: how much darken/brighten the color' + ], exec: (args, { findColor }, { dynamicVars, staticVars }) => { const [colorArg, amountArg] = args @@ -75,6 +105,13 @@ export const colorFunctions = { export const shadowFunctions = { borderSide: { argsNeeded: 3, + documentation: 'Simulate a border on a side with a shadow, best works on inset border', + args: [ + 'color: border color', + 'side: string indicating on which side border should be, takes either one word or two words joined by dash (i.e. "left" or "bottom-right")', + '[alpha]: (Optional) border opacity, defaults to 1 (fully opaque)', + '[inset]: (Optional) whether border should be on the inside or outside, defaults to inside' + ], exec: (args, { findColor }) => { const [color, side, alpha = '1', widthArg = '1', inset = 'inset'] = args From 7c947115e26a91e6ad64d71697848a14ea8d459b Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Tue, 12 Nov 2024 21:05:56 +0200 Subject: [PATCH 2/6] make active tab to jut out slightly to indicate that it's active (inspired by winMe) --- .../opacity_input/opacity_input.vue | 4 +- .../roundness_input/roundness_input.vue | 51 +++++++++++++++++++ src/components/tab_switcher/tab_switcher.scss | 8 ++- 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 src/components/roundness_input/roundness_input.vue diff --git a/src/components/opacity_input/opacity_input.vue b/src/components/opacity_input/opacity_input.vue index 5a80b100d..dea17a46c 100644 --- a/src/components/opacity_input/opacity_input.vue +++ b/src/components/opacity_input/opacity_input.vue @@ -8,7 +8,7 @@ class="label" :class="{ faint: !present || disabled }" > - {{ $t('settings.style.common.opacity') }} + {{ label }} +
+ + + +
+ + + diff --git a/src/components/tab_switcher/tab_switcher.scss b/src/components/tab_switcher/tab_switcher.scss index 4e242b91b..a4d5aa3ae 100644 --- a/src/components/tab_switcher/tab_switcher.scss +++ b/src/components/tab_switcher/tab_switcher.scss @@ -119,7 +119,7 @@ .tab { flex: 1; box-sizing: content-box; - min-width: 10em; + max-width: 9em; min-width: 1px; border-top-right-radius: 0; border-bottom-right-radius: 0; @@ -128,6 +128,11 @@ margin-right: -200px; margin-left: 1em; + &:not(.active) { + margin-top: 0; + margin-left: 1.5em; + } + @media all and (max-width: 800px) { padding-left: 0.25em; padding-right: calc(0.25em + 200px); @@ -181,6 +186,7 @@ &:not(.active) { z-index: 4; + margin-top: 0.25em; &:hover { z-index: 6; From 4aaf6bcc59a7fb7f84f1c59f54ab1d528f820340 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Tue, 12 Nov 2024 21:08:59 +0200 Subject: [PATCH 3/6] remove extra slots --- src/components/palette_editor/palette_editor.vue | 12 +----------- src/i18n/en.json | 10 ---------- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/src/components/palette_editor/palette_editor.vue b/src/components/palette_editor/palette_editor.vue index 91236ce77..9dd8d8683 100644 --- a/src/components/palette_editor/palette_editor.vue +++ b/src/components/palette_editor/palette_editor.vue @@ -75,17 +75,7 @@ const paletteKeys = [ 'cBlue', 'cGreen', 'cOrange', - 'wallpaper', - 'extra1', - 'extra2', - 'extra3', - 'extra4', - 'extra5', - 'extra6', - 'extra7', - 'extra8', - 'extra9', - 'extra10' + 'wallpaper' ] const fallback = (key) => { diff --git a/src/i18n/en.json b/src/i18n/en.json index 3d531ad96..01b23211f 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -771,16 +771,6 @@ "cGreen": "Green color", "cOrange": "Orange color", "wallpaper": "Wallpaper", - "extra1": "Extra 1", - "extra2": "Extra 2", - "extra3": "Extra 3", - "extra4": "Extra 4", - "extra5": "Extra 5", - "extra6": "Extra 6", - "extra7": "Extra 7", - "extra8": "Extra 8", - "extra9": "Extra 9", - "extra10": "Extra 10", "v2_unsupported": "Older v2 themes don't support palettes. Switch to v3 theme to make use of palettes" }, "editor": { From a2a58dc082ecb1fe7e509b66b0073957c6a192f9 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Tue, 12 Nov 2024 21:10:02 +0200 Subject: [PATCH 4/6] improve robustness and responsiveness --- .../tabs/style_tab/style_tab.js | 35 ++++++++++++------- .../shadow_control/shadow_control.js | 11 ++++-- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/components/settings_modal/tabs/style_tab/style_tab.js b/src/components/settings_modal/tabs/style_tab/style_tab.js index a612f5a9e..7989793db 100644 --- a/src/components/settings_modal/tabs/style_tab/style_tab.js +++ b/src/components/settings_modal/tabs/style_tab/style_tab.js @@ -1,6 +1,6 @@ -import { ref, reactive, computed, watch, provide } from 'vue' +import { ref, reactive, computed, watch, watchEffect, provide } from 'vue' import { useStore } from 'vuex' -import { get, set, unset } from 'lodash' +import { get, set, unset, throttle } from 'lodash' import Select from 'src/components/select/select.vue' import SelectMotion from 'src/components/select/select_motion.vue' @@ -639,13 +639,21 @@ export default { const overallPreviewRules = ref([]) exports.overallPreviewRules = overallPreviewRules - const overallPreviewCssRules = computed(() => getScopedVersion( - getCssRules(overallPreviewRules.value), - '#edited-style-preview' - ).join('\n')) + const overallPreviewCssRules = ref([]) + watchEffect(throttle(() => { + try { + overallPreviewCssRules.value = getScopedVersion( + getCssRules(overallPreviewRules.value), + '#edited-style-preview' + ).join('\n') + } catch (e) { + console.error(e) + } + }, 500)) + exports.overallPreviewCssRules = overallPreviewCssRules - const updateOverallPreview = () => { + const updateOverallPreview = throttle(() => { try { overallPreviewRules.value = init({ inputRuleset: exportRules.value, @@ -657,7 +665,7 @@ export default { console.error('Could not compile preview theme', e) return null } - } + }, 1000) // // Apart from "hover" we can't really show how component looks like in // certain states, so we have to fake them. @@ -730,10 +738,13 @@ export default { return r.component === 'Root' }) const rootDirectivesEntries = Object.entries(rootComponent.directives) - const directives = Object.fromEntries( - rootDirectivesEntries - .filter(([k, v]) => k.startsWith('--') && v.startsWith('color | ')) - .map(([k, v]) => [k.substring(2), v.substring('color | '.length)])) + const directives = {} + rootDirectivesEntries + .filter(([k, v]) => k.startsWith('--') && v.startsWith('color | ')) + .map(([k, v]) => [k.substring(2), v.substring('color | '.length)]) + .forEach(([k, v]) => { + directives[k] = findColor(v, { dynamicVars: {}, staticVars: directives }) + }) return directives }) provide('staticVars', staticVars) diff --git a/src/components/shadow_control/shadow_control.js b/src/components/shadow_control/shadow_control.js index d137f0175..0657621dd 100644 --- a/src/components/shadow_control/shadow_control.js +++ b/src/components/shadow_control/shadow_control.js @@ -112,9 +112,14 @@ export default { }, getColorFallback () { if (this.staticVars && this.selected?.color) { - const computedColor = findColor(this.selected.color, { dynamicVars: {}, staticVars: this.staticVars }, true) - if (computedColor) return rgb2hex(computedColor) - return null + try { + const computedColor = findColor(this.selected.color, { dynamicVars: {}, staticVars: this.staticVars }, true) + if (computedColor) return rgb2hex(computedColor) + return null + } catch (e) { + console.warn(e) + return null + } } else { return this.currentFallback?.color } From d787fb1a608f4e8bec7f7f0c01344c4f9d0b6b3b Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Tue, 12 Nov 2024 21:10:50 +0200 Subject: [PATCH 5/6] roundness control --- src/components/settings_modal/tabs/style_tab/style_tab.js | 4 ++++ .../settings_modal/tabs/style_tab/style_tab.vue | 8 ++++++++ src/i18n/en.json | 2 ++ 3 files changed, 14 insertions(+) diff --git a/src/components/settings_modal/tabs/style_tab/style_tab.js b/src/components/settings_modal/tabs/style_tab/style_tab.js index 7989793db..9b4c5701b 100644 --- a/src/components/settings_modal/tabs/style_tab/style_tab.js +++ b/src/components/settings_modal/tabs/style_tab/style_tab.js @@ -11,6 +11,7 @@ import ShadowControl from 'src/components/shadow_control/shadow_control.vue' import ColorInput from 'src/components/color_input/color_input.vue' import PaletteEditor from 'src/components/palette_editor/palette_editor.vue' import OpacityInput from 'src/components/opacity_input/opacity_input.vue' +import RoundnessInput from 'src/components/roundness_input/roundness_input.vue' import TabSwitcher from 'src/components/tab_switcher/tab_switcher.jsx' import Tooltip from 'src/components/tooltip/tooltip.vue' import ContrastRatio from 'src/components/contrast_ratio/contrast_ratio.vue' @@ -72,6 +73,7 @@ export default { ColorInput, PaletteEditor, OpacityInput, + RoundnessInput, ContrastRatio, Preview, VirtualDirectivesTab @@ -347,6 +349,8 @@ export default { exports.isBackgroundColorPresent = isElementPresent(null, 'background', '#FFFFFF') exports.editedOpacity = getEditedElement(null, 'opacity') exports.isOpacityPresent = isElementPresent(null, 'opacity', 1) + exports.editedRoundness = getEditedElement(null, 'roundness') + exports.isRoundnessPresent = isElementPresent(null, 'roundness', 0) exports.editedTextColor = getEditedElement('Text', 'textColor') exports.isTextColorPresent = isElementPresent('Text', 'textColor', '#000000') exports.editedTextAuto = getEditedElement('Text', 'textAuto') diff --git a/src/components/settings_modal/tabs/style_tab/style_tab.vue b/src/components/settings_modal/tabs/style_tab/style_tab.vue index 638b789a2..f95c7aca3 100644 --- a/src/components/settings_modal/tabs/style_tab/style_tab.vue +++ b/src/components/settings_modal/tabs/style_tab/style_tab.vue @@ -286,6 +286,14 @@ + + + +
Date: Tue, 12 Nov 2024 23:24:28 +0200 Subject: [PATCH 6/6] allow setting palettes from style --- src/boot/after_store.js | 7 ++ .../settings_modal/tabs/appearance_tab.js | 67 ++++++++++++++++--- .../settings_modal/tabs/appearance_tab.scss | 1 + .../settings_modal/tabs/appearance_tab.vue | 23 ++++++- .../tabs/style_tab/style_tab.js | 67 ++++++++++++------- src/i18n/en.json | 4 +- src/modules/interface.js | 8 +-- .../theme_data/theme_data_3.service.js | 4 +- static/palettes/index.json | 8 +-- 9 files changed, 143 insertions(+), 46 deletions(-) diff --git a/src/boot/after_store.js b/src/boot/after_store.js index 20a1a591a..f88da23a1 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -390,6 +390,13 @@ const afterStoreSetup = async ({ store, i18n }) => { app.use(store) app.use(i18n) + // Little thing to get out of invalid theme state + window.resetThemes = () => { + store.dispatch('resetThemeV3') + store.dispatch('resetThemeV3Palette') + store.dispatch('resetThemeV2') + } + app.use(vClickOutside) app.use(VBodyScrollLock) app.use(VueVirtualScroller) diff --git a/src/components/settings_modal/tabs/appearance_tab.js b/src/components/settings_modal/tabs/appearance_tab.js index bba4647c6..1e8f596f2 100644 --- a/src/components/settings_modal/tabs/appearance_tab.js +++ b/src/components/settings_modal/tabs/appearance_tab.js @@ -33,7 +33,7 @@ const AppearanceTab = { data () { return { availableStyles: [], - availablePalettes: [], + bundledPalettes: [], fileImporter: newImporter({ accept: '.json, .piss', validator: this.importValidator, @@ -41,8 +41,8 @@ const AppearanceTab = { onImportFailure: this.onImportFailure }), palettesKeys: [ - 'background', - 'foreground', + 'bg', + 'fg', 'link', 'text', 'cRed', @@ -103,13 +103,13 @@ const AppearanceTab = { })) }) - updateIndex('palette').then(palettes => { - palettes.forEach(([key, palettePromise]) => palettePromise.then(v => { + updateIndex('palette').then(bundledPalettes => { + bundledPalettes.forEach(([key, palettePromise]) => palettePromise.then(v => { if (Array.isArray(v)) { const [ name, - background, - foreground, + bg, + fg, text, link, cRed = '#FF0000', @@ -117,9 +117,9 @@ const AppearanceTab = { cBlue = '#0000FF', cOrange = '#E3FF00' ] = v - this.availablePalettes.push({ key, name, background, foreground, text, link, cRed, cBlue, cGreen, cOrange }) + this.bundledPalettes.push({ key, name, bg, fg, text, link, cRed, cBlue, cGreen, cOrange }) } else { - this.availablePalettes.push({ key, ...v }) + this.bundledPalettes.push({ key, ...v }) } })) }) @@ -147,6 +147,50 @@ const AppearanceTab = { }) }, computed: { + availablePalettes () { + return [ + ...this.bundledPalettes, + ...this.stylePalettes + ] + }, + stylePalettes () { + if (!this.mergedConfig.styleCustomData) return + const meta = this.mergedConfig.styleCustomData + .find(x => x.component === '@meta') + const result = this.mergedConfig.styleCustomData + .filter(x => x.component.startsWith('@palette')) + .map(x => { + const { + variant, + bg, + fg, + text, + link, + accent, + cRed, + cBlue, + cGreen, + cOrange, + wallpaper + } = x + + const result = { + name: `${meta.name}: ${variant}`, + bg, + fg, + text, + link, + accent, + cRed, + cBlue, + cGreen, + cOrange, + wallpaper + } + return Object.fromEntries(Object.entries(result).filter(([k, v]) => v)) + }) + return result + }, noIntersectionObserver () { return !window.IntersectionObserver }, @@ -253,6 +297,11 @@ const AppearanceTab = { this.$store.dispatch('setPalette', name) this.$store.dispatch('applyTheme') }, + setPaletteCustom (p) { + this.$store.dispatch('resetThemeV2') + this.$store.dispatch('setPaletteCustom', p) + this.$store.dispatch('applyTheme') + }, resetTheming (name) { this.$store.dispatch('resetThemeV2') this.$store.dispatch('resetThemeV3') diff --git a/src/components/settings_modal/tabs/appearance_tab.scss b/src/components/settings_modal/tabs/appearance_tab.scss index b95ef07db..c78b4accc 100644 --- a/src/components/settings_modal/tabs/appearance_tab.scss +++ b/src/components/settings_modal/tabs/appearance_tab.scss @@ -25,6 +25,7 @@ grid-template-columns: 1fr 1fr; grid-gap: 0.5em; + h4, .unsupported-theme-v2 { grid-column: 1 / span 2; } diff --git a/src/components/settings_modal/tabs/appearance_tab.vue b/src/components/settings_modal/tabs/appearance_tab.vue index 32f6f1a72..1b43a690b 100644 --- a/src/components/settings_modal/tabs/appearance_tab.vue +++ b/src/components/settings_modal/tabs/appearance_tab.vue @@ -72,8 +72,9 @@

{{ $t('settings.style.themes3.palette.label') }}