mirror of
https://github.com/fmhy/edit.git
synced 2026-01-11 19:06:17 +00:00
* Add files for christmas theme, theme handler, feedback revamp and cattpuccin theme * Add files via upload * update image on home page * add tree logo for faster loading * change link to raw github
4.7 KiB
4.7 KiB
Theme System
This document explains the updated theme architecture, display modes, and integration components in the site.
Architecture
- Display modes:
lightanddark. - AMOLED: an enhancement of
darkmode (pure black backgrounds) toggled on top of dark — not a separate mode. - Themes: color schemes and optional design tokens that apply across modes.
- Modes are independent from themes; themes define colors and tokens for light/dark.
File Structure
docs/.vitepress/theme/themes/
├── types.ts // Type definitions
├── themeHandler.ts // Theme handler logic & DOM/CSS application
├── index.ts // Exports
└── configs/
├── index.ts // Theme registry (default + named themes)
└── catppuccin.ts // Example theme (default)
Core Types
DisplayMode:'light' | 'dark'.Theme:{ name, displayName, preview?, logo?, modes: { light, dark }, ... }.ModeColors:brand?: optional brand colors (1,2,3,soft). If omitted, the ColorPicker controls brand.bg,bgAlt,bgElv,bgMark?.text?: optional (1,2,3). If omitted, VitePress defaults are used.button:brandandaltsub-objects withbg,border,text,hover*,active*.customBlock:info,tip,warning,dangerwithbg,border,text,textDeep.selection:{ bg }.home?: optional hero styles.
Handler Behavior (themeHandler.ts)
- Persists
theme(vitepress-theme-name) andmode(vitepress-display-mode). - Applies HTML classes: always the current mode; adds
darkfor compatibility; addsamoledwhen dark + AMOLED enabled. - AMOLED handling: overrides dark backgrounds to pure black while retaining other dark tokens.
- Brand colors:
- If theme provides brand colors, inline CSS variables are set.
- If theme omits brand colors, inline brand variables are removed so the ColorPicker stylesheet takes effect.
- Text colors:
- Applied only if defined in the theme; otherwise defaults are used.
- Custom logo:
- If theme provides
logo, sets--vp-theme-logo: url(...)for downstream usage.
- If theme provides
UI Components
ThemeDropdown.vue: replaces the appearance toggle.- Options: Light, Dark, AMOLED (as dark variant).
- Stores/reads mode and AMOLED-enabled state.
- Aliased via
docs/.vitepress/config.mtsto overrideVPSwitchAppearance.vue.
ColorPicker.vue:- Controls brand color CSS variables via a stylesheet tag (
#brand-color). - Reapplies colors on a custom event
theme-changed-apply-colorswhen switching to themes without brand.
- Controls brand color CSS variables via a stylesheet tag (
ThemeSelector.vue:- Shows circular previews per theme (image via
previewor gradient fallback). - Calls
setTheme(name); independent from ColorPicker.
- Shows circular previews per theme (image via
Theme Registry (configs/index.ts)
- Example:
import { catppuccinTheme } from './catppuccin'
export const themeRegistry = {
default: catppuccinTheme,
catppuccin: catppuccinTheme
}
Creating a Theme (configs/<name>.ts)
- Export a
Themeobject with:name,displayName, optionalpreview(image URL/data) andlogo.modes.lightandmodes.darkobjects.- Optional
fonts,spacing,borderRadius,customProperties.
- Register it in
configs/index.ts. - If you omit
brandin a mode, the ColorPicker-selected brand colors will be used. - If you omit
textin a mode, VitePress default text colors will be used.
CSS Variables
- Brand:
--vp-c-brand-1,--vp-c-brand-2,--vp-c-brand-3,--vp-c-brand-soft. - Background:
--vp-c-bg,--vp-c-bg-alt,--vp-c-bg-elv,--vp-c-bg-mark. - Text:
--vp-c-text-1,--vp-c-text-2,--vp-c-text-3. - Buttons:
--vp-button-brand-*,--vp-button-alt-*. - Custom blocks:
--vp-custom-block-{type}-*. - Selection:
--vp-c-selection-bg. - Home hero:
--vp-home-hero-*. - Custom props: all keys in
customProperties. - Optional:
--vp-theme-logo(when theme defineslogo).
Migration Notes
- AMOLED is no longer a separate mode; it’s a dark enhancement (pure black backgrounds) toggled in the dropdown.
- The legacy
Appearance.vuetoggle is replaced byThemeDropdown.vuevia alias inconfig.mts. - Themes can rely on the ColorPicker for brand colors by omitting
brand.
Troubleshooting
- Theme not applying: ensure it’s added to
themeRegistryand named correctly. - Brand not changing: if a theme sets inline brand variables, ColorPicker won’t override; remove
brandfrom the theme to defer to ColorPicker. - Colors not updating after theme switch: ColorPicker listens for
theme-changed-apply-colors; make sure that event dispatch remains insetTheme(). - AMOLED not pure black: confirm dark mode is active and AMOLED toggle is enabled; handler overrides backgrounds when enabled.