mirror of
https://github.com/fmhy/edit.git
synced 2025-11-28 00:41:20 +11:00
Update ColorPicker.vue
This commit is contained in:
parent
29afad66fc
commit
03ebe6b337
1 changed files with 80 additions and 97 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
import { colors } from '@fmhy/colors'
|
import { colors } from '@fmhy/colors'
|
||||||
import { useStorage, useStyleTag } from '@vueuse/core'
|
import { useStorage, useStyleTag } from '@vueuse/core'
|
||||||
import { watch, onMounted } from 'vue'
|
import { watch, onMounted } from 'vue'
|
||||||
|
import Switch from './Switch.vue'
|
||||||
|
|
||||||
// Add Halloween colors
|
// Add Halloween colors
|
||||||
const halloweenColors = {
|
const halloweenColors = {
|
||||||
|
|
@ -40,6 +41,7 @@ const colorScales = [
|
||||||
|
|
||||||
type ColorNames = keyof typeof extendedColors
|
type ColorNames = keyof typeof extendedColors
|
||||||
const selectedColor = useStorage<ColorNames>('preferred-color', 'halloween')
|
const selectedColor = useStorage<ColorNames>('preferred-color', 'halloween')
|
||||||
|
const isAmoledMode = useStorage('amoled-mode', false)
|
||||||
|
|
||||||
const colorOptions = Object.keys(extendedColors).filter(
|
const colorOptions = Object.keys(extendedColors).filter(
|
||||||
(key) => typeof extendedColors[key as keyof typeof extendedColors] === 'object'
|
(key) => typeof extendedColors[key as keyof typeof extendedColors] === 'object'
|
||||||
|
|
@ -47,7 +49,7 @@ const colorOptions = Object.keys(extendedColors).filter(
|
||||||
|
|
||||||
const { css } = useStyleTag('', { id: 'brand-color' })
|
const { css } = useStyleTag('', { id: 'brand-color' })
|
||||||
|
|
||||||
const updateThemeColor = (colorName: ColorNames) => {
|
const updateThemeColor = (colorName: ColorNames, amoledEnabled: boolean) => {
|
||||||
const colorSet = extendedColors[colorName]
|
const colorSet = extendedColors[colorName]
|
||||||
|
|
||||||
const cssVars = colorScales
|
const cssVars = colorScales
|
||||||
|
|
@ -56,9 +58,30 @@ const updateThemeColor = (colorName: ColorNames) => {
|
||||||
|
|
||||||
const htmlElement = document.documentElement
|
const htmlElement = document.documentElement
|
||||||
|
|
||||||
|
// Manage theme classes
|
||||||
if (colorName === 'halloween') {
|
if (colorName === 'halloween') {
|
||||||
// Apply Halloween theme
|
|
||||||
htmlElement.classList.add('theme-halloween')
|
htmlElement.classList.add('theme-halloween')
|
||||||
|
} else {
|
||||||
|
htmlElement.classList.remove('theme-halloween')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (amoledEnabled) {
|
||||||
|
htmlElement.classList.add('theme-amoled')
|
||||||
|
} else {
|
||||||
|
htmlElement.classList.remove('theme-amoled')
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine dark background color based on AMOLED mode
|
||||||
|
const darkBg = amoledEnabled ? '#000000' : 'rgb(26, 26, 26)'
|
||||||
|
const darkBgAlt = amoledEnabled ? '#000000' : 'rgb(23, 23, 23)'
|
||||||
|
const darkBgElv = amoledEnabled ? 'rgba(0, 0, 0, 0.9)' : 'rgba(23, 23, 23, 0.8)'
|
||||||
|
const darkBgSoft = amoledEnabled ? '#000000' : 'rgb(23, 23, 23)'
|
||||||
|
|
||||||
|
// Apply Halloween theme backgrounds or normal backgrounds
|
||||||
|
if (colorName === 'halloween') {
|
||||||
|
const halloweenDarkBg = amoledEnabled ? '#000000' : 'rgb(15, 15, 15)'
|
||||||
|
const halloweenDarkBgAlt = amoledEnabled ? '#000000' : 'rgb(12, 12, 12)'
|
||||||
|
const halloweenDarkBgElv = amoledEnabled ? 'rgba(0, 0, 0, 0.9)' : 'rgba(12, 12, 12, 0.8)'
|
||||||
|
|
||||||
css.value = `
|
css.value = `
|
||||||
:root {
|
:root {
|
||||||
|
|
@ -75,12 +98,21 @@ const updateThemeColor = (colorName: ColorNames) => {
|
||||||
--vp-c-brand-2: ${colorSet[500]};
|
--vp-c-brand-2: ${colorSet[500]};
|
||||||
--vp-c-brand-3: ${colorSet[700]};
|
--vp-c-brand-3: ${colorSet[700]};
|
||||||
--vp-c-brand-soft: ${colorSet[300]};
|
--vp-c-brand-soft: ${colorSet[300]};
|
||||||
|
--vp-c-bg: ${halloweenDarkBg} !important;
|
||||||
|
--vp-c-bg-alt: ${halloweenDarkBgAlt} !important;
|
||||||
|
--vp-c-bg-elv: ${halloweenDarkBgElv} !important;
|
||||||
|
--vp-c-bg-soft: ${halloweenDarkBgAlt} !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark html, .dark body {
|
||||||
|
background-color: ${halloweenDarkBg} !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark .VPApp, .dark .Layout, .dark .VPContent, .dark .VPHome, .dark .VPHero, .dark #app, .dark .vp-doc {
|
||||||
|
background-color: ${halloweenDarkBg} !important;
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
} else {
|
} else {
|
||||||
// Remove Halloween theme and apply other theme with pure black backgrounds (but exclude buttons)
|
|
||||||
htmlElement.classList.remove('theme-halloween')
|
|
||||||
|
|
||||||
css.value = `
|
css.value = `
|
||||||
:root {
|
:root {
|
||||||
${cssVars}
|
${cssVars}
|
||||||
|
|
@ -88,10 +120,10 @@ const updateThemeColor = (colorName: ColorNames) => {
|
||||||
--vp-c-brand-2: ${colorSet[600]};
|
--vp-c-brand-2: ${colorSet[600]};
|
||||||
--vp-c-brand-3: ${colorSet[800]};
|
--vp-c-brand-3: ${colorSet[800]};
|
||||||
--vp-c-brand-soft: ${colorSet[400]};
|
--vp-c-brand-soft: ${colorSet[400]};
|
||||||
--vp-c-bg: #000000 !important;
|
--vp-c-bg: #ffffff !important;
|
||||||
--vp-c-bg-alt: #000000 !important;
|
--vp-c-bg-alt: #f9f9f9 !important;
|
||||||
--vp-c-bg-elv: #000000 !important;
|
--vp-c-bg-elv: rgba(255, 255, 255, 0.7) !important;
|
||||||
--vp-c-bg-soft: #000000 !important;
|
--vp-c-bg-soft: #f9f9f9 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dark {
|
.dark {
|
||||||
|
|
@ -100,114 +132,59 @@ const updateThemeColor = (colorName: ColorNames) => {
|
||||||
--vp-c-brand-2: ${colorSet[500]};
|
--vp-c-brand-2: ${colorSet[500]};
|
||||||
--vp-c-brand-3: ${colorSet[700]};
|
--vp-c-brand-3: ${colorSet[700]};
|
||||||
--vp-c-brand-soft: ${colorSet[300]};
|
--vp-c-brand-soft: ${colorSet[300]};
|
||||||
--vp-c-bg: #000000 !important;
|
--vp-c-bg: ${darkBg} !important;
|
||||||
--vp-c-bg-alt: #000000 !important;
|
--vp-c-bg-alt: ${darkBgAlt} !important;
|
||||||
--vp-c-bg-elv: #000000 !important;
|
--vp-c-bg-elv: ${darkBgElv} !important;
|
||||||
--vp-c-bg-soft: #000000 !important;
|
--vp-c-bg-soft: ${darkBgSoft} !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Main page backgrounds - pure black */
|
|
||||||
html, body {
|
html, body {
|
||||||
background-color: #000000 !important;
|
background-color: #ffffff !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* VitePress layout containers - pure black */
|
.VPApp, .Layout, .VPContent, .VPHome, .VPHero, #app, .vp-doc {
|
||||||
.VPApp, .Layout, .VPContent, .VPHome, .VPHero, #app {
|
background-color: #ffffff !important;
|
||||||
background-color: #000000 !important;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Content areas - pure black */
|
|
||||||
.vp-doc, .VPDoc, .content {
|
|
||||||
background-color: #000000 !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Navigation and sidebar backgrounds - pure black */
|
|
||||||
.VPNav, .VPSidebar, .VPLocalNav {
|
|
||||||
background-color: #000000 !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Footer - pure black */
|
|
||||||
.VPFooter {
|
|
||||||
background-color: #000000 !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* EXCLUDE buttons and interactive elements from black background */
|
|
||||||
button,
|
|
||||||
.VPButton,
|
|
||||||
.vp-button,
|
|
||||||
input[type="button"],
|
|
||||||
input[type="submit"],
|
|
||||||
.copy-button,
|
|
||||||
.nav-link,
|
|
||||||
.sidebar-link,
|
|
||||||
.pager-link,
|
|
||||||
.edit-link,
|
|
||||||
.outline-link,
|
|
||||||
.search-button,
|
|
||||||
[role="button"] {
|
|
||||||
background-color: initial !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Dark mode - same rules */
|
|
||||||
.dark html, .dark body {
|
.dark html, .dark body {
|
||||||
background-color: #000000 !important;
|
background-color: ${darkBg} !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dark .VPApp, .dark .Layout, .dark .VPContent, .dark .VPHome, .dark .VPHero, .dark #app {
|
.dark .VPApp, .dark .Layout, .dark .VPContent, .dark .VPHome, .dark .VPHero, .dark #app, .dark .vp-doc {
|
||||||
background-color: #000000 !important;
|
background-color: ${darkBg} !important;
|
||||||
}
|
|
||||||
|
|
||||||
.dark .vp-doc, .dark .VPDoc, .dark .content {
|
|
||||||
background-color: #000000 !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dark .VPNav, .dark .VPSidebar, .dark .VPLocalNav {
|
|
||||||
background-color: #000000 !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dark .VPFooter {
|
|
||||||
background-color: #000000 !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* EXCLUDE buttons in dark mode too */
|
|
||||||
.dark button,
|
|
||||||
.dark .VPButton,
|
|
||||||
.dark .vp-button,
|
|
||||||
.dark input[type="button"],
|
|
||||||
.dark input[type="submit"],
|
|
||||||
.dark .copy-button,
|
|
||||||
.dark .nav-link,
|
|
||||||
.dark .sidebar-link,
|
|
||||||
.dark .pager-link,
|
|
||||||
.dark .edit-link,
|
|
||||||
.dark .outline-link,
|
|
||||||
.dark .search-button,
|
|
||||||
.dark [role="button"] {
|
|
||||||
background-color: initial !important;
|
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set Halloween theme ASAP if its the pref
|
|
||||||
const storedTheme = localStorage.getItem('preferred-color')
|
|
||||||
if (!storedTheme || storedTheme === '"halloween"') {
|
|
||||||
document.documentElement.classList.add('theme-halloween')
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize theme color
|
|
||||||
updateThemeColor(selectedColor.value)
|
|
||||||
|
|
||||||
// halloween stuff
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
// Set Halloween theme ASAP if its the pref (only in browser)
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
const storedTheme = localStorage.getItem('preferred-color')
|
||||||
|
const storedAmoled = localStorage.getItem('amoled-mode')
|
||||||
|
|
||||||
|
if (!storedTheme || storedTheme === '"halloween"') {
|
||||||
|
document.documentElement.classList.add('theme-halloween')
|
||||||
|
}
|
||||||
|
if (storedAmoled === 'true') {
|
||||||
|
document.documentElement.classList.add('theme-amoled')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (selectedColor.value === 'halloween') {
|
if (selectedColor.value === 'halloween') {
|
||||||
document.documentElement.classList.add('theme-halloween')
|
document.documentElement.classList.add('theme-halloween')
|
||||||
}
|
}
|
||||||
|
if (isAmoledMode.value) {
|
||||||
|
document.documentElement.classList.add('theme-amoled')
|
||||||
|
}
|
||||||
|
|
||||||
// Re-apply the theme to ensure everything is initialized
|
// Re-apply the theme to ensure everything is initialized
|
||||||
updateThemeColor(selectedColor.value)
|
updateThemeColor(selectedColor.value, isAmoledMode.value)
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(selectedColor, updateThemeColor)
|
watch([selectedColor, isAmoledMode], ([color, amoled]) => {
|
||||||
|
updateThemeColor(color, amoled)
|
||||||
|
})
|
||||||
|
|
||||||
const normalizeColorName = (colorName: string) =>
|
const normalizeColorName = (colorName: string) =>
|
||||||
colorName.replaceAll(/-/g, ' ').charAt(0).toUpperCase() +
|
colorName.replaceAll(/-/g, ' ').charAt(0).toUpperCase() +
|
||||||
|
|
@ -219,7 +196,7 @@ const normalizeColorName = (colorName: string) =>
|
||||||
<div class="flex flex-wrap gap-2">
|
<div class="flex flex-wrap gap-2">
|
||||||
<div v-for="color in colorOptions" :key="color">
|
<div v-for="color in colorOptions" :key="color">
|
||||||
<button
|
<button
|
||||||
:class="[
|
:class=" [
|
||||||
'inline-block w-6 h-6 rounded-full transition-all duration-200'
|
'inline-block w-6 h-6 rounded-full transition-all duration-200'
|
||||||
]"
|
]"
|
||||||
@click="selectedColor = color"
|
@click="selectedColor = color"
|
||||||
|
|
@ -243,5 +220,11 @@ const normalizeColorName = (colorName: string) =>
|
||||||
<div class="mt-2 text-sm text-$vp-c-text-2">
|
<div class="mt-2 text-sm text-$vp-c-text-2">
|
||||||
Selected: {{ normalizeColorName(selectedColor) }}
|
Selected: {{ normalizeColorName(selectedColor) }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- AMOLED toggle -->
|
||||||
|
<div class="mt-4 flex items-center gap-2">
|
||||||
|
<span class="text-sm text-$vp-c-text-2">AMOLED</span>
|
||||||
|
<Switch @click="isAmoledMode = !isAmoledMode" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue