@gospore/theme 1.0.163 → 1.0.165
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -9
- package/dist/index.d.ts +5 -0
- package/dist/theme.cjs +45 -0
- package/dist/theme.cjs.map +1 -0
- package/dist/theme.css +1 -1
- package/dist/theme.es.js +292 -143
- package/dist/theme.es.js.map +1 -1
- package/dist/theme.umd.js +44 -1
- package/dist/theme.umd.js.map +1 -1
- package/dist/themeBootstrap.d.ts +20 -0
- package/package.json +9 -9
- package/dist/theme.cjs.js +0 -2
- package/dist/theme.cjs.js.map +0 -1
package/dist/theme.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.umd.js","names":[],"sources":["../src/modeStorage.ts","../src/portalHost.ts","../src/Theme.vue","../src/Theme.vue","../src/ThemeSwitcher.vue","../src/ThemeSwitcher.vue"],"sourcesContent":["const VALID_THEME_MODES = [\"auto\", \"light\", \"dark\"] as const;\nexport type ThemeMode = (typeof VALID_THEME_MODES)[number];\nconst STORAGE_KEY = \"gospore-theme-mode\";\nconst ONE_YEAR_IN_SECONDS = 60 * 60 * 24 * 365;\nconst DARK_MODE_QUERY = \"(prefers-color-scheme: dark)\";\n\nexport function readStoredMode(): ThemeMode | null {\n if (typeof document === \"undefined\") {\n return null;\n }\n const stored = getCookie(STORAGE_KEY);\n return isThemeMode(stored) ? stored : null;\n}\n\nexport function writeStoredMode(mode: ThemeMode) {\n if (typeof document === \"undefined\" || !VALID_THEME_MODES.includes(mode)) {\n return;\n }\n const hostname = typeof window !== \"undefined\" ? window.location.hostname : \"\";\n const protocol = typeof window !== \"undefined\" ? window.location.protocol : \"\";\n const domain = getCookieDomain(hostname);\n const secure = protocol === \"https:\";\n const attributes = [\"path=/\", `max-age=${ONE_YEAR_IN_SECONDS}`, \"SameSite=Lax\"];\n if (domain) {\n attributes.push(`domain=${domain}`);\n }\n if (secure) {\n attributes.push(\"Secure\");\n }\n document.cookie = [\n `${encodeURIComponent(STORAGE_KEY)}=${encodeURIComponent(mode)}`,\n ...attributes,\n ].join(\"; \");\n}\n\nexport function applyStoredModeToDocument(mode?: string | null) {\n if (typeof document === \"undefined\") {\n return;\n }\n const resolvedMode = isThemeMode(mode) ? mode : (readStoredMode() ?? \"auto\");\n console.log(\"Applying theme mode:\", resolvedMode);\n const darkMode = resolveDarkMode(resolvedMode);\n document.documentElement.setAttribute(\"dark-mode\", String(darkMode));\n}\n\nexport { VALID_THEME_MODES, STORAGE_KEY };\n\nfunction getCookie(name: string) {\n if (typeof document === \"undefined\" || !document.cookie) {\n return null;\n }\n const encodedName = `${encodeURIComponent(name)}=`;\n const cookies = document.cookie.split(\"; \");\n for (const cookie of cookies) {\n if (cookie.startsWith(encodedName)) {\n return decodeURIComponent(cookie.slice(encodedName.length));\n }\n }\n return null;\n}\n\nfunction getCookieDomain(hostname: string) {\n if (!hostname || hostname === \"localhost\") {\n return null;\n }\n const isIpAddress = /^\\d+(?:\\.\\d+){3}$/.test(hostname);\n if (isIpAddress) {\n return hostname;\n }\n const parts = hostname.split(\".\");\n if (parts.length <= 1) {\n return null;\n }\n if (parts.length === 2) {\n return hostname;\n }\n return parts.slice(-2).join(\".\");\n}\n\nfunction resolveDarkMode(mode: string) {\n if (mode === \"dark\") {\n return true;\n }\n if (mode === \"light\") {\n return false;\n }\n if (typeof window === \"undefined\") {\n return false;\n }\n try {\n const mediaQueryList =\n typeof window.matchMedia === \"function\" ? window.matchMedia(DARK_MODE_QUERY) : null;\n return mediaQueryList ? mediaQueryList.matches : false;\n } catch {\n return false;\n }\n}\n\nfunction isThemeMode(value: string | null | undefined): value is ThemeMode {\n return typeof value === \"string\" && (VALID_THEME_MODES as readonly string[]).includes(value);\n}\n","import { computed, inject } from \"vue\";\nimport type { InjectionKey, Ref } from \"vue\";\n\nexport type ThemePortalTarget = HTMLElement | string;\n\nexport const themePortalHostKey = Symbol.for(\"gospore.theme.portalHost\") as InjectionKey<\n Ref<HTMLElement | null>\n>;\n\nexport function useThemePortalTarget() {\n const hostRef = inject(themePortalHostKey, null);\n console.log(\"Using theme portal host:\", hostRef);\n const fallbackTarget: ThemePortalTarget =\n typeof document !== \"undefined\" ? document.body : \"body\";\n\n return computed<ThemePortalTarget>(() => hostRef?.value ?? fallbackTarget);\n}\n","<script lang=\"ts\">\ninterface GlobalAccentEntry {\n vars: Record<string, string>;\n enabled: boolean;\n}\n\nconst globalAccentStack: GlobalAccentEntry[] = [];\nconst appliedGlobalAccentKeys = new Set<string>();\n\nconst DARK_MODE_QUERY = \"(prefers-color-scheme: dark)\"\nconst PREFERS_REDUCED_MOTION_QUERY = \"(prefers-reduced-motion: reduce)\"\nconst THEME_TRANSITION_DURATION = 200\nconst BRAND_MIN_CONTRAST = 4.5\nconst BRAND_MIN_SURFACE_CONTRAST = 1.8\nconst BRAND_MIN_SUBTLE_SURFACE_CONTRAST = 1.15\nconst BRAND_MIN_SOFT_SURFACE_CONTRAST = 1.08\nconst BRAND_UI_TEXT_MIN_CONTRAST = 4.5\nconst BRAND_LIGHT_TEXT_SWITCH_DELTA = 3\nconst LIGHT_CANVAS_HEX = \"#ffffff\"\nconst DARK_CANVAS_HEX = \"#1f2228\"</script>\n\n<template>\n <div class=\"theme\" :style=\"brandVars\">\n <slot />\n <div ref=\"portalHost\" class=\"theme__portal-host\"></div>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { provide, ref, watch, onBeforeUnmount, computed } from \"vue\";\nimport type { PropType } from \"vue\";\nimport { applyStoredModeToDocument, readStoredMode, type ThemeMode } from \"./modeStorage\";\nimport \"what-input\";\nimport { themePortalHostKey } from \"./portalHost\";\n\ninterface RgbColor {\n r: number;\n g: number;\n b: number;\n}\n\ninterface OklchColor {\n l: number;\n c: number;\n h: number;\n}\n\ntype BrandRamp = Record<number, string>;\ntype BrandVars = Record<string, string>;\n\ninterface ReadableTextOptions {\n minContrast?: number;\n preferDark?: boolean;\n chromaScale?: number;\n initialLightness?: number;\n step?: number;\n}\n\ninterface ForegroundOptions extends ReadableTextOptions {\n darkCandidate?: string;\n lightCandidate?: string;\n preferredCandidate?: \"dark\" | \"light\";\n preferredMinContrast?: number;\n preferredSwitchDelta?: number;\n}\n\ndefineOptions({\n name: \"Theme\",\n});\ndefineSlots<{\n /** Application content that receives theme tokens and portal context. */\n default?: () => unknown;\n}>();\nconst props = defineProps({\n /**\n * Controls which color mode is active. auto follows the OS preference (and persisted storage\n * when used with ThemeSwitcher).\n */\n mode: {\n type: String as PropType<ThemeMode | undefined>,\n default: undefined,\n validator: (value: string) => [\"auto\", \"light\", \"dark\"].includes(value),\n },\n /**\n * Optional hex accent color (\"#RRGGBB\" or \"#RGB\"). When provided, Theme derives contrast-safe\n * semantic brand tokens and exposes them on the root .theme element (and the global document\n * for portals).\n */\n accentColor: {\n type: String,\n required: false,\n default: undefined,\n },\n /**\n * When true the brand vars are also exposed on <html>, allowing portals attached outside the\n * Theme subtree to inherit the accent colors.\n */\n exposeGlobalAccent: {\n type: Boolean,\n default: false,\n },\n});\n\nfunction applyGlobalAccentFromStack() {\n const root = document.documentElement;\n if (!root) {\n return;\n }\n\n appliedGlobalAccentKeys.forEach((key) => {\n root.style.removeProperty(key);\n });\n appliedGlobalAccentKeys.clear();\n\n const activeEntry = [...globalAccentStack]\n .reverse()\n .find((entry) => entry.enabled && entry.vars && Object.keys(entry.vars).length > 0);\n\n if (!activeEntry) {\n return;\n }\n\n Object.entries(activeEntry.vars).forEach(([key, value]) => {\n root.style.setProperty(key, value);\n appliedGlobalAccentKeys.add(key);\n });\n}\n\n\n\n\nconst darkModeMedia = window.matchMedia(DARK_MODE_QUERY);\nconst prefersReducedMotionMedia = window.matchMedia(PREFERS_REDUCED_MOTION_QUERY);\n\nconst initialMode = getEffectiveMode();\napplyStoredModeToDocument(initialMode);\n\nconst currentMode = ref(initialMode);\n\nconst theme = ref({\n darkMode: resolveDarkMode(initialMode),\n});\nconst portalHost = ref<HTMLElement | null>(null);\n\ndarkModeMedia.addEventListener(\"change\", handleSystemPreferenceChange);\n\nwatch(\n () => props.mode,\n () => {\n syncDarkMode();\n },\n { immediate: true },\n);\n\nwatch(\n () => theme.value.darkMode,\n (darkMode, previousValue) => {\n if (previousValue === undefined) {\n setDocumentDarkModeAttribute(darkMode);\n return;\n }\n withThemeTransition(() => {\n setDocumentDarkModeAttribute(darkMode);\n });\n },\n { immediate: true },\n);\n\nonBeforeUnmount(() => {\n darkModeMedia.removeEventListener(\"change\", handleSystemPreferenceChange);\n const index = globalAccentStack.indexOf(accentStackEntry);\n if (index !== -1) {\n globalAccentStack.splice(index, 1);\n }\n applyGlobalAccentFromStack();\n});\n\nfunction syncDarkMode() {\n const mode = getEffectiveMode();\n currentMode.value = mode;\n theme.value.darkMode = resolveDarkMode(mode);\n}\n\nfunction resolveDarkMode(mode: ThemeMode) {\n if (mode === \"dark\") {\n return true;\n }\n if (mode === \"light\") {\n return false;\n }\n return darkModeMedia.matches;\n}\n\nfunction handleSystemPreferenceChange(event: MediaQueryListEvent) {\n if (!event || currentMode.value !== \"auto\") {\n return;\n }\n theme.value.darkMode = event.matches;\n}\n\nfunction setDocumentDarkModeAttribute(darkMode: boolean) {\n document.documentElement.setAttribute(\"dark-mode\", String(darkMode));\n}\n\nfunction withThemeTransition(applyTheme: () => void) {\n if (prefersReducedMotionMedia.matches) {\n applyTheme();\n return;\n }\n const startViewTransition = document.startViewTransition?.bind(document);\n if (startViewTransition) {\n startViewTransition(() => {\n applyTheme();\n });\n return;\n }\n applyTheme();\n const element = document.documentElement;\n if (typeof element.animate !== \"function\") {\n return;\n }\n window.requestAnimationFrame(() => {\n element.animate([{ opacity: 0.85 }, { opacity: 1 }], {\n duration: THEME_TRANSITION_DURATION,\n easing: \"ease-in-out\",\n });\n });\n}\n\nfunction getEffectiveMode(): ThemeMode {\n return props.mode ?? readStoredMode() ?? \"auto\";\n}\n\nprovide(\"theme\", theme);\nprovide(themePortalHostKey, portalHost);\n\n// --- Accent helpers -------------------------------------------------------\n\n\nfunction normalizeHex(hex: string | undefined) {\n if (!hex) return null;\n const h = hex.trim().toLowerCase();\n const m = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.exec(h);\n if (!m) return null;\n if (h.length === 4) {\n // expand #rgb -> #rrggbb\n const r = h[1],\n g = h[2],\n b = h[3];\n return `#${r}${r}${g}${g}${b}${b}`;\n }\n return h;\n}\n\nfunction hexToRgb(hex: string | undefined): RgbColor | null {\n const h = normalizeHex(hex);\n if (!h) return null;\n const r = parseInt(h.slice(1, 3), 16);\n const g = parseInt(h.slice(3, 5), 16);\n const b = parseInt(h.slice(5, 7), 16);\n return { r, g, b };\n}\n\nfunction rgbToHex({ r, g, b }: RgbColor) {\n const toHex = (value: number) => value.toString(16).padStart(2, \"0\");\n return `#${toHex(r)}${toHex(g)}${toHex(b)}`;\n}\n\nfunction clamp01(value: number) {\n return Math.max(0, Math.min(1, value));\n}\n\nfunction srgbChannelToLinear(channel: number) {\n if (channel <= 0.04045) {\n return channel / 12.92;\n }\n return Math.pow((channel + 0.055) / 1.055, 2.4);\n}\n\nfunction linearChannelToSrgb(channel: number) {\n const normalized = clamp01(channel);\n if (normalized <= 0.0031308) {\n return 12.92 * normalized;\n }\n return 1.055 * Math.pow(normalized, 1 / 2.4) - 0.055;\n}\n\nfunction rgbToOklch({ r, g, b }: RgbColor): OklchColor {\n const rNorm = r / 255;\n const gNorm = g / 255;\n const bNorm = b / 255;\n\n const rLin = srgbChannelToLinear(rNorm);\n const gLin = srgbChannelToLinear(gNorm);\n const bLin = srgbChannelToLinear(bNorm);\n\n const l = 0.4122214708 * rLin + 0.5363325363 * gLin + 0.0514459929 * bLin;\n const m = 0.2119034982 * rLin + 0.6806995451 * gLin + 0.1073969566 * bLin;\n const s = 0.0883024619 * rLin + 0.2817188376 * gLin + 0.6299787005 * bLin;\n\n const lRoot = Math.cbrt(l);\n const mRoot = Math.cbrt(m);\n const sRoot = Math.cbrt(s);\n\n const oklabL = 0.2104542553 * lRoot + 0.793617785 * mRoot - 0.0040720468 * sRoot;\n const oklabA = 1.9779984951 * lRoot - 2.428592205 * mRoot + 0.4505937099 * sRoot;\n const oklabB = 0.0259040371 * lRoot + 0.7827717662 * mRoot - 0.808675766 * sRoot;\n\n const chroma = Math.sqrt(oklabA * oklabA + oklabB * oklabB);\n let hue = Math.atan2(oklabB, oklabA) * (180 / Math.PI);\n if (hue < 0) {\n hue += 360;\n }\n\n return { l: oklabL, c: chroma, h: hue };\n}\n\nfunction tryOklchToSrgb(l: number, c: number, h: number, clampLinear = false): RgbColor | null {\n const angle = (h * Math.PI) / 180;\n const a = c * Math.cos(angle);\n const b = c * Math.sin(angle);\n\n const lComponent = l + 0.3963377774 * a + 0.2158037573 * b;\n const mComponent = l - 0.1055613458 * a - 0.0638541728 * b;\n const sComponent = l - 0.0894841775 * a - 1.291485548 * b;\n\n const lCube = clampLinear ? clamp01(lComponent) : lComponent;\n const mCube = clampLinear ? clamp01(mComponent) : mComponent;\n const sCube = clampLinear ? clamp01(sComponent) : sComponent;\n\n if (!clampLinear) {\n const outOfRange =\n lCube < -0.0001 ||\n lCube > 1.0001 ||\n mCube < -0.0001 ||\n mCube > 1.0001 ||\n sCube < -0.0001 ||\n sCube > 1.0001;\n if (outOfRange) {\n return null;\n }\n }\n\n const lLin = lCube * lCube * lCube;\n const mLin = mCube * mCube * mCube;\n const sLin = sCube * sCube * sCube;\n\n let rLin = 4.0767416621 * lLin - 3.3077115913 * mLin + 0.2309699292 * sLin;\n let gLin = -1.2684380046 * lLin + 2.6097574011 * mLin - 0.3413193965 * sLin;\n let bLin = -0.0041960863 * lLin - 0.7034186147 * mLin + 1.707614701 * sLin;\n\n if (clampLinear) {\n rLin = clamp01(rLin);\n gLin = clamp01(gLin);\n bLin = clamp01(bLin);\n } else {\n const outOfRange =\n rLin < -0.0001 ||\n rLin > 1.0001 ||\n gLin < -0.0001 ||\n gLin > 1.0001 ||\n bLin < -0.0001 ||\n bLin > 1.0001;\n if (outOfRange) {\n return null;\n }\n }\n\n const r = clamp01(linearChannelToSrgb(rLin));\n const g = clamp01(linearChannelToSrgb(gLin));\n const bValue = clamp01(linearChannelToSrgb(bLin));\n\n return {\n r: Math.round(r * 255),\n g: Math.round(g * 255),\n b: Math.round(bValue * 255),\n };\n}\n\nfunction oklchToSrgb(l: number, c: number, h: number): RgbColor {\n let chroma = c;\n for (let attempt = 0; attempt < 8; attempt += 1) {\n const rgb = tryOklchToSrgb(l, chroma, h);\n if (rgb) {\n return rgb;\n }\n chroma *= 0.9;\n }\n return tryOklchToSrgb(l, clamp01(chroma), h, true) || { r: 0, g: 0, b: 0 };\n}\n\nfunction relativeLuminance(hex: string) {\n const rgb = hexToRgb(hex);\n if (!rgb) {\n return 0;\n }\n const r = srgbChannelToLinear(rgb.r / 255);\n const g = srgbChannelToLinear(rgb.g / 255);\n const b = srgbChannelToLinear(rgb.b / 255);\n return 0.2126 * r + 0.7152 * g + 0.0722 * b;\n}\n\nfunction contrastRatio(hexA: string, hexB: string) {\n const lumA = relativeLuminance(hexA);\n const lumB = relativeLuminance(hexB);\n const lighter = Math.max(lumA, lumB);\n const darker = Math.min(lumA, lumB);\n return (lighter + 0.05) / (darker + 0.05);\n}\n\nfunction makeReadableTextOnSurface(\n baseOklch: OklchColor,\n surfaceHex: string,\n options: ReadableTextOptions = {},\n) {\n const minContrast = options.minContrast ?? BRAND_MIN_CONTRAST;\n const preferDark = options.preferDark !== false;\n const textChroma = Math.max(\n 0.01,\n Math.min(0.06, (baseOklch.c || 0.12) * (options.chromaScale ?? 0.25)),\n );\n const initialLightness = options.initialLightness ?? (preferDark ? 0.24 : 0.94);\n const direction = preferDark ? -1 : 1;\n const step = options.step ?? 0.03;\n let lightness = clamp01(initialLightness);\n let bestHex = rgbToHex(oklchToSrgb(lightness, textChroma, baseOklch.h));\n let bestContrast = contrastRatio(surfaceHex, bestHex);\n\n for (let attempt = 0; attempt < 48; attempt += 1) {\n const textHex = rgbToHex(oklchToSrgb(lightness, textChroma, baseOklch.h));\n const ratio = contrastRatio(surfaceHex, textHex);\n\n if (ratio > bestContrast) {\n bestContrast = ratio;\n bestHex = textHex;\n }\n if (ratio >= minContrast) {\n return textHex;\n }\n\n lightness = clamp01(lightness + direction * step);\n if (lightness === 0 || lightness === 1) {\n break;\n }\n }\n\n const fallbackDark = \"#000000\";\n const fallbackLight = \"#ffffff\";\n const darkRatio = contrastRatio(surfaceHex, fallbackDark);\n const lightRatio = contrastRatio(surfaceHex, fallbackLight);\n\n if (darkRatio >= minContrast || lightRatio >= minContrast) {\n return darkRatio >= lightRatio ? fallbackDark : fallbackLight;\n }\n\n return bestHex;\n}\n\nfunction pickForegroundColor(\n baseOklch: OklchColor,\n surfaceHex: string,\n options: ForegroundOptions = {},\n) {\n const minContrast = options.minContrast ?? BRAND_MIN_CONTRAST;\n const darkCandidate = options.darkCandidate ?? \"#101214\";\n const lightCandidate = options.lightCandidate ?? \"#ffffff\";\n const preferredCandidate = options.preferredCandidate;\n const preferredMinContrast = options.preferredMinContrast ?? minContrast;\n const preferredSwitchDelta = options.preferredSwitchDelta ?? 0;\n const darkRatio = contrastRatio(surfaceHex, darkCandidate);\n const lightRatio = contrastRatio(surfaceHex, lightCandidate);\n const darkPasses = darkRatio >= minContrast;\n const lightPasses = lightRatio >= minContrast;\n const preferredLightPasses = lightRatio >= preferredMinContrast;\n const preferredDarkPasses = darkRatio >= preferredMinContrast;\n\n if (darkPasses || lightPasses) {\n if (preferredCandidate === \"light\" && preferredLightPasses) {\n return lightCandidate;\n }\n if (preferredCandidate === \"dark\" && preferredDarkPasses) {\n return darkCandidate;\n }\n\n if (preferredCandidate === \"light\" && lightPasses) {\n if (!darkPasses || darkRatio - lightRatio <= preferredSwitchDelta) {\n return lightCandidate;\n }\n return darkCandidate;\n }\n if (preferredCandidate === \"dark\" && darkPasses) {\n if (!lightPasses || lightRatio - darkRatio <= preferredSwitchDelta) {\n return darkCandidate;\n }\n return lightCandidate;\n }\n\n if (darkPasses && lightPasses) {\n return darkRatio >= lightRatio ? darkCandidate : lightCandidate;\n }\n return darkPasses ? darkCandidate : lightCandidate;\n }\n\n const preferDark = darkRatio >= lightRatio;\n return makeReadableTextOnSurface(baseOklch, surfaceHex, {\n minContrast,\n preferDark,\n initialLightness: preferDark ? 0.2 : 0.96,\n chromaScale: 0.1,\n });\n}\n\nconst BRAND_STOPS = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000];\nconst BRAND_LIGHTNESS_CURVE = [0.9, 0.84, 0.78, 0.72, 0.67, 0.62, 0.56, 0.5, 0.44, 0.38];\nconst BRAND_CHROMA_MULTIPLIERS = [0.28, 0.4, 0.54, 0.7, 0.86, 1, 1.08, 1.14, 1.2, 1.24];\n\n\n\n\n\n\n\n\nfunction pickRampStopForContrast(\n ramp: BrandRamp,\n stopCandidates: number[],\n referenceHex: string,\n minContrast: number,\n) {\n const fallbackStop = stopCandidates[stopCandidates.length - 1];\n for (const stop of stopCandidates) {\n const candidate = ramp[stop];\n if (!candidate) {\n continue;\n }\n if (contrastRatio(candidate, referenceHex) >= minContrast) {\n return stop;\n }\n }\n return fallbackStop;\n}\n\nfunction makeBrandRampFromSeed(baseOklch: OklchColor): BrandRamp {\n const lightnessOffset = baseOklch.l - BRAND_LIGHTNESS_CURVE[5];\n const minSeedChroma = baseOklch.c > 0.02 ? 0.02 : 0;\n\n return BRAND_STOPS.reduce<BrandRamp>((acc, stop, index) => {\n const lightness = clamp01(BRAND_LIGHTNESS_CURVE[index] + lightnessOffset);\n const chroma = Math.min(\n 0.4,\n Math.max(minSeedChroma, baseOklch.c * BRAND_CHROMA_MULTIPLIERS[index]),\n );\n acc[stop] = rgbToHex(oklchToSrgb(lightness, chroma, baseOklch.h));\n return acc;\n }, {});\n}\n\nfunction makeSemanticBrandTokens(baseOklch: OklchColor, ramp: BrandRamp): BrandVars {\n const lightSoftStops = [100, 200, 300, 400, 500, 600, 700];\n const lightSoftStop = pickRampStopForContrast(\n ramp,\n lightSoftStops,\n LIGHT_CANVAS_HEX,\n BRAND_MIN_SOFT_SURFACE_CONTRAST,\n );\n const lightSoftIndex = lightSoftStops.indexOf(lightSoftStop);\n const lightSoftHoveredStop =\n lightSoftStops[Math.min(lightSoftIndex + 1, lightSoftStops.length - 1)];\n const lightSoftPressedStop =\n lightSoftStops[Math.min(lightSoftIndex + 2, lightSoftStops.length - 1)];\n\n const darkSoftStops = [1000, 900, 800, 700, 600, 500];\n const darkSoftStop = pickRampStopForContrast(\n ramp,\n darkSoftStops,\n DARK_CANVAS_HEX,\n BRAND_MIN_SOFT_SURFACE_CONTRAST,\n );\n const darkSoftIndex = darkSoftStops.indexOf(darkSoftStop);\n const darkSoftHoveredStop =\n darkSoftStops[Math.min(darkSoftIndex + 1, darkSoftStops.length - 1)];\n const darkSoftPressedStop =\n darkSoftStops[Math.min(darkSoftIndex + 2, darkSoftStops.length - 1)];\n\n const lightSubtleStops = [200, 300, 400, 500, 600, 700, 800];\n const lightSubtleStop = pickRampStopForContrast(\n ramp,\n lightSubtleStops,\n LIGHT_CANVAS_HEX,\n BRAND_MIN_SUBTLE_SURFACE_CONTRAST,\n );\n const darkSubtleStops = [900, 800, 700, 600, 500, 400];\n const darkSubtleStop = pickRampStopForContrast(\n ramp,\n darkSubtleStops,\n DARK_CANVAS_HEX,\n BRAND_MIN_SUBTLE_SURFACE_CONTRAST,\n );\n\n const lightStrongStops = [600, 700, 800, 900, 1000];\n const lightStrongStop = pickRampStopForContrast(\n ramp,\n lightStrongStops,\n LIGHT_CANVAS_HEX,\n BRAND_MIN_SURFACE_CONTRAST,\n );\n const lightStrongIndex = lightStrongStops.indexOf(lightStrongStop);\n const lightStrongHoveredStop =\n lightStrongStops[Math.min(lightStrongIndex + 1, lightStrongStops.length - 1)];\n const lightStrongPressedStop =\n lightStrongStops[Math.min(lightStrongIndex + 2, lightStrongStops.length - 1)];\n\n const darkStrongStops = [400, 300, 200, 100];\n const darkStrongStop = pickRampStopForContrast(\n ramp,\n darkStrongStops,\n DARK_CANVAS_HEX,\n BRAND_MIN_SURFACE_CONTRAST,\n );\n const darkStrongIndex = darkStrongStops.indexOf(darkStrongStop);\n const darkStrongHoveredStop =\n darkStrongStops[Math.min(darkStrongIndex + 1, darkStrongStops.length - 1)];\n const darkStrongPressedStop =\n darkStrongStops[Math.min(darkStrongIndex + 2, darkStrongStops.length - 1)];\n\n const tokens: BrandVars = {\n \"--color-brand-surface-soft-light\": ramp[lightSoftStop],\n \"--color-brand-surface-soft-hovered-light\": ramp[lightSoftHoveredStop],\n \"--color-brand-surface-soft-pressed-light\": ramp[lightSoftPressedStop],\n \"--color-brand-surface-soft-dark\": ramp[darkSoftStop],\n \"--color-brand-surface-soft-hovered-dark\": ramp[darkSoftHoveredStop],\n \"--color-brand-surface-soft-pressed-dark\": ramp[darkSoftPressedStop],\n \"--color-brand-surface-subtle-light\": ramp[lightSubtleStop],\n \"--color-brand-surface-subtle-dark\": ramp[darkSubtleStop],\n \"--color-brand-surface-strong-light\": ramp[lightStrongStop],\n \"--color-brand-surface-strong-hovered-light\": ramp[lightStrongHoveredStop],\n \"--color-brand-surface-strong-pressed-light\": ramp[lightStrongPressedStop],\n \"--color-brand-surface-strong-dark\": ramp[darkStrongStop],\n \"--color-brand-surface-strong-hovered-dark\": ramp[darkStrongHoveredStop],\n \"--color-brand-surface-strong-pressed-dark\": ramp[darkStrongPressedStop],\n };\n\n const preferredSoftLightForeground = ramp[600];\n const softLightContrast = contrastRatio(\n tokens[\"--color-brand-surface-soft-light\"],\n preferredSoftLightForeground,\n );\n tokens[\"--color-brand-on-soft-light\"] =\n softLightContrast >= BRAND_MIN_CONTRAST\n ? preferredSoftLightForeground\n : pickForegroundColor(baseOklch, tokens[\"--color-brand-surface-soft-light\"], {\n minContrast: BRAND_MIN_CONTRAST,\n });\n tokens[\"--color-brand-on-soft-dark\"] = pickForegroundColor(\n baseOklch,\n tokens[\"--color-brand-surface-soft-dark\"],\n {\n minContrast: BRAND_MIN_CONTRAST,\n },\n );\n tokens[\"--color-brand-on-subtle-light\"] = pickForegroundColor(\n baseOklch,\n tokens[\"--color-brand-surface-subtle-light\"],\n {\n minContrast: BRAND_UI_TEXT_MIN_CONTRAST,\n preferredCandidate: \"light\",\n preferredMinContrast: BRAND_UI_TEXT_MIN_CONTRAST,\n preferredSwitchDelta: BRAND_LIGHT_TEXT_SWITCH_DELTA,\n },\n );\n tokens[\"--color-brand-on-subtle-dark\"] = pickForegroundColor(\n baseOklch,\n tokens[\"--color-brand-surface-subtle-dark\"],\n {\n minContrast: BRAND_MIN_CONTRAST,\n },\n );\n tokens[\"--color-brand-on-strong-light\"] = pickForegroundColor(\n baseOklch,\n tokens[\"--color-brand-surface-strong-light\"],\n {\n minContrast: BRAND_UI_TEXT_MIN_CONTRAST,\n preferredCandidate: \"light\",\n preferredMinContrast: BRAND_UI_TEXT_MIN_CONTRAST,\n preferredSwitchDelta: BRAND_LIGHT_TEXT_SWITCH_DELTA,\n },\n );\n tokens[\"--color-brand-on-strong-dark\"] = pickForegroundColor(\n baseOklch,\n tokens[\"--color-brand-surface-strong-dark\"],\n {\n minContrast: BRAND_MIN_CONTRAST,\n },\n );\n\n tokens[\"--color-brand-text-light\"] = tokens[\"--color-brand-surface-strong-light\"];\n tokens[\"--color-brand-text-dark\"] = tokens[\"--color-brand-surface-strong-dark\"];\n tokens[\"--color-brand-icon-light\"] = tokens[\"--color-brand-surface-strong-light\"];\n tokens[\"--color-brand-icon-dark\"] = tokens[\"--color-brand-surface-strong-dark\"];\n tokens[\"--color-brand-border-light\"] = tokens[\"--color-brand-surface-strong-light\"];\n tokens[\"--color-brand-border-dark\"] = tokens[\"--color-brand-surface-strong-dark\"];\n\n return tokens;\n}\n\nfunction makeBrandTokens(baseHex: string | undefined): BrandVars | null {\n const norm = normalizeHex(baseHex);\n if (!norm) {\n return null;\n }\n\n const baseRgb = hexToRgb(norm);\n if (!baseRgb) {\n return null;\n }\n\n const baseOklch = rgbToOklch(baseRgb);\n const ramp = makeBrandRampFromSeed(baseOklch);\n // Keep the incoming seed exact for debugging and transparency.\n ramp[600] = norm;\n\n return {\n \"--color-brand-seed\": norm,\n \"--color-brand-100\": ramp[100],\n \"--color-brand-200\": ramp[200],\n \"--color-brand-300\": ramp[300],\n \"--color-brand-400\": ramp[400],\n \"--color-brand-500\": ramp[500],\n \"--color-brand-600\": ramp[600],\n \"--color-brand-700\": ramp[700],\n \"--color-brand-800\": ramp[800],\n \"--color-brand-900\": ramp[900],\n \"--color-brand-1000\": ramp[1000],\n ...makeSemanticBrandTokens(baseOklch, ramp),\n };\n}\n\nconst brandVars = computed(() => makeBrandTokens(props.accentColor) ?? {});\n\nconst accentStackEntry = {\n vars: {},\n enabled: Boolean(props.exposeGlobalAccent),\n};\nglobalAccentStack.push(accentStackEntry);\n\nwatch(\n () => props.exposeGlobalAccent,\n (enabled) => {\n accentStackEntry.enabled = Boolean(enabled);\n applyGlobalAccentFromStack();\n },\n { immediate: true },\n);\n\nwatch(\n brandVars,\n (vars) => {\n if (vars && Object.keys(vars).length > 0) {\n accentStackEntry.vars = { ...vars };\n } else {\n accentStackEntry.vars = {};\n }\n applyGlobalAccentFromStack();\n },\n { immediate: true },\n);\n</script>\n\n<style lang=\"less\">\n@import \"index.less\";\n</style>\n","<script lang=\"ts\">\ninterface GlobalAccentEntry {\n vars: Record<string, string>;\n enabled: boolean;\n}\n\nconst globalAccentStack: GlobalAccentEntry[] = [];\nconst appliedGlobalAccentKeys = new Set<string>();\n</script>\n\n<template>\n <div class=\"theme\" :style=\"brandVars\">\n <slot />\n <div ref=\"portalHost\" class=\"theme__portal-host\"></div>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { provide, ref, watch, onBeforeUnmount, computed } from \"vue\";\nimport type { PropType } from \"vue\";\nimport { applyStoredModeToDocument, readStoredMode, type ThemeMode } from \"./modeStorage\";\nimport \"what-input\";\nimport { themePortalHostKey } from \"./portalHost\";\n\ninterface RgbColor {\n r: number;\n g: number;\n b: number;\n}\n\ninterface OklchColor {\n l: number;\n c: number;\n h: number;\n}\n\ntype BrandRamp = Record<number, string>;\ntype BrandVars = Record<string, string>;\n\ninterface ReadableTextOptions {\n minContrast?: number;\n preferDark?: boolean;\n chromaScale?: number;\n initialLightness?: number;\n step?: number;\n}\n\ninterface ForegroundOptions extends ReadableTextOptions {\n darkCandidate?: string;\n lightCandidate?: string;\n preferredCandidate?: \"dark\" | \"light\";\n preferredMinContrast?: number;\n preferredSwitchDelta?: number;\n}\n\ndefineOptions({\n name: \"Theme\",\n});\ndefineSlots<{\n /** Application content that receives theme tokens and portal context. */\n default?: () => unknown;\n}>();\nconst props = defineProps({\n /**\n * Controls which color mode is active. auto follows the OS preference (and persisted storage\n * when used with ThemeSwitcher).\n */\n mode: {\n type: String as PropType<ThemeMode | undefined>,\n default: undefined,\n validator: (value: string) => [\"auto\", \"light\", \"dark\"].includes(value),\n },\n /**\n * Optional hex accent color (\"#RRGGBB\" or \"#RGB\"). When provided, Theme derives contrast-safe\n * semantic brand tokens and exposes them on the root .theme element (and the global document\n * for portals).\n */\n accentColor: {\n type: String,\n required: false,\n default: undefined,\n },\n /**\n * When true the brand vars are also exposed on <html>, allowing portals attached outside the\n * Theme subtree to inherit the accent colors.\n */\n exposeGlobalAccent: {\n type: Boolean,\n default: false,\n },\n});\n\nfunction applyGlobalAccentFromStack() {\n const root = document.documentElement;\n if (!root) {\n return;\n }\n\n appliedGlobalAccentKeys.forEach((key) => {\n root.style.removeProperty(key);\n });\n appliedGlobalAccentKeys.clear();\n\n const activeEntry = [...globalAccentStack]\n .reverse()\n .find((entry) => entry.enabled && entry.vars && Object.keys(entry.vars).length > 0);\n\n if (!activeEntry) {\n return;\n }\n\n Object.entries(activeEntry.vars).forEach(([key, value]) => {\n root.style.setProperty(key, value);\n appliedGlobalAccentKeys.add(key);\n });\n}\n\nconst DARK_MODE_QUERY = \"(prefers-color-scheme: dark)\";\nconst PREFERS_REDUCED_MOTION_QUERY = \"(prefers-reduced-motion: reduce)\";\nconst THEME_TRANSITION_DURATION = 200;\nconst darkModeMedia = window.matchMedia(DARK_MODE_QUERY);\nconst prefersReducedMotionMedia = window.matchMedia(PREFERS_REDUCED_MOTION_QUERY);\n\nconst initialMode = getEffectiveMode();\napplyStoredModeToDocument(initialMode);\n\nconst currentMode = ref(initialMode);\n\nconst theme = ref({\n darkMode: resolveDarkMode(initialMode),\n});\nconst portalHost = ref<HTMLElement | null>(null);\n\ndarkModeMedia.addEventListener(\"change\", handleSystemPreferenceChange);\n\nwatch(\n () => props.mode,\n () => {\n syncDarkMode();\n },\n { immediate: true },\n);\n\nwatch(\n () => theme.value.darkMode,\n (darkMode, previousValue) => {\n if (previousValue === undefined) {\n setDocumentDarkModeAttribute(darkMode);\n return;\n }\n withThemeTransition(() => {\n setDocumentDarkModeAttribute(darkMode);\n });\n },\n { immediate: true },\n);\n\nonBeforeUnmount(() => {\n darkModeMedia.removeEventListener(\"change\", handleSystemPreferenceChange);\n const index = globalAccentStack.indexOf(accentStackEntry);\n if (index !== -1) {\n globalAccentStack.splice(index, 1);\n }\n applyGlobalAccentFromStack();\n});\n\nfunction syncDarkMode() {\n const mode = getEffectiveMode();\n currentMode.value = mode;\n theme.value.darkMode = resolveDarkMode(mode);\n}\n\nfunction resolveDarkMode(mode: ThemeMode) {\n if (mode === \"dark\") {\n return true;\n }\n if (mode === \"light\") {\n return false;\n }\n return darkModeMedia.matches;\n}\n\nfunction handleSystemPreferenceChange(event: MediaQueryListEvent) {\n if (!event || currentMode.value !== \"auto\") {\n return;\n }\n theme.value.darkMode = event.matches;\n}\n\nfunction setDocumentDarkModeAttribute(darkMode: boolean) {\n document.documentElement.setAttribute(\"dark-mode\", String(darkMode));\n}\n\nfunction withThemeTransition(applyTheme: () => void) {\n if (prefersReducedMotionMedia.matches) {\n applyTheme();\n return;\n }\n const startViewTransition = document.startViewTransition?.bind(document);\n if (startViewTransition) {\n startViewTransition(() => {\n applyTheme();\n });\n return;\n }\n applyTheme();\n const element = document.documentElement;\n if (typeof element.animate !== \"function\") {\n return;\n }\n window.requestAnimationFrame(() => {\n element.animate([{ opacity: 0.85 }, { opacity: 1 }], {\n duration: THEME_TRANSITION_DURATION,\n easing: \"ease-in-out\",\n });\n });\n}\n\nfunction getEffectiveMode(): ThemeMode {\n return props.mode ?? readStoredMode() ?? \"auto\";\n}\n\nprovide(\"theme\", theme);\nprovide(themePortalHostKey, portalHost);\n\n// --- Accent helpers -------------------------------------------------------\nconst BRAND_MIN_CONTRAST = 4.5;\n\nfunction normalizeHex(hex: string | undefined) {\n if (!hex) return null;\n const h = hex.trim().toLowerCase();\n const m = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.exec(h);\n if (!m) return null;\n if (h.length === 4) {\n // expand #rgb -> #rrggbb\n const r = h[1],\n g = h[2],\n b = h[3];\n return `#${r}${r}${g}${g}${b}${b}`;\n }\n return h;\n}\n\nfunction hexToRgb(hex: string | undefined): RgbColor | null {\n const h = normalizeHex(hex);\n if (!h) return null;\n const r = parseInt(h.slice(1, 3), 16);\n const g = parseInt(h.slice(3, 5), 16);\n const b = parseInt(h.slice(5, 7), 16);\n return { r, g, b };\n}\n\nfunction rgbToHex({ r, g, b }: RgbColor) {\n const toHex = (value: number) => value.toString(16).padStart(2, \"0\");\n return `#${toHex(r)}${toHex(g)}${toHex(b)}`;\n}\n\nfunction clamp01(value: number) {\n return Math.max(0, Math.min(1, value));\n}\n\nfunction srgbChannelToLinear(channel: number) {\n if (channel <= 0.04045) {\n return channel / 12.92;\n }\n return Math.pow((channel + 0.055) / 1.055, 2.4);\n}\n\nfunction linearChannelToSrgb(channel: number) {\n const normalized = clamp01(channel);\n if (normalized <= 0.0031308) {\n return 12.92 * normalized;\n }\n return 1.055 * Math.pow(normalized, 1 / 2.4) - 0.055;\n}\n\nfunction rgbToOklch({ r, g, b }: RgbColor): OklchColor {\n const rNorm = r / 255;\n const gNorm = g / 255;\n const bNorm = b / 255;\n\n const rLin = srgbChannelToLinear(rNorm);\n const gLin = srgbChannelToLinear(gNorm);\n const bLin = srgbChannelToLinear(bNorm);\n\n const l = 0.4122214708 * rLin + 0.5363325363 * gLin + 0.0514459929 * bLin;\n const m = 0.2119034982 * rLin + 0.6806995451 * gLin + 0.1073969566 * bLin;\n const s = 0.0883024619 * rLin + 0.2817188376 * gLin + 0.6299787005 * bLin;\n\n const lRoot = Math.cbrt(l);\n const mRoot = Math.cbrt(m);\n const sRoot = Math.cbrt(s);\n\n const oklabL = 0.2104542553 * lRoot + 0.793617785 * mRoot - 0.0040720468 * sRoot;\n const oklabA = 1.9779984951 * lRoot - 2.428592205 * mRoot + 0.4505937099 * sRoot;\n const oklabB = 0.0259040371 * lRoot + 0.7827717662 * mRoot - 0.808675766 * sRoot;\n\n const chroma = Math.sqrt(oklabA * oklabA + oklabB * oklabB);\n let hue = Math.atan2(oklabB, oklabA) * (180 / Math.PI);\n if (hue < 0) {\n hue += 360;\n }\n\n return { l: oklabL, c: chroma, h: hue };\n}\n\nfunction tryOklchToSrgb(l: number, c: number, h: number, clampLinear = false): RgbColor | null {\n const angle = (h * Math.PI) / 180;\n const a = c * Math.cos(angle);\n const b = c * Math.sin(angle);\n\n const lComponent = l + 0.3963377774 * a + 0.2158037573 * b;\n const mComponent = l - 0.1055613458 * a - 0.0638541728 * b;\n const sComponent = l - 0.0894841775 * a - 1.291485548 * b;\n\n const lCube = clampLinear ? clamp01(lComponent) : lComponent;\n const mCube = clampLinear ? clamp01(mComponent) : mComponent;\n const sCube = clampLinear ? clamp01(sComponent) : sComponent;\n\n if (!clampLinear) {\n const outOfRange =\n lCube < -0.0001 ||\n lCube > 1.0001 ||\n mCube < -0.0001 ||\n mCube > 1.0001 ||\n sCube < -0.0001 ||\n sCube > 1.0001;\n if (outOfRange) {\n return null;\n }\n }\n\n const lLin = lCube * lCube * lCube;\n const mLin = mCube * mCube * mCube;\n const sLin = sCube * sCube * sCube;\n\n let rLin = 4.0767416621 * lLin - 3.3077115913 * mLin + 0.2309699292 * sLin;\n let gLin = -1.2684380046 * lLin + 2.6097574011 * mLin - 0.3413193965 * sLin;\n let bLin = -0.0041960863 * lLin - 0.7034186147 * mLin + 1.707614701 * sLin;\n\n if (clampLinear) {\n rLin = clamp01(rLin);\n gLin = clamp01(gLin);\n bLin = clamp01(bLin);\n } else {\n const outOfRange =\n rLin < -0.0001 ||\n rLin > 1.0001 ||\n gLin < -0.0001 ||\n gLin > 1.0001 ||\n bLin < -0.0001 ||\n bLin > 1.0001;\n if (outOfRange) {\n return null;\n }\n }\n\n const r = clamp01(linearChannelToSrgb(rLin));\n const g = clamp01(linearChannelToSrgb(gLin));\n const bValue = clamp01(linearChannelToSrgb(bLin));\n\n return {\n r: Math.round(r * 255),\n g: Math.round(g * 255),\n b: Math.round(bValue * 255),\n };\n}\n\nfunction oklchToSrgb(l: number, c: number, h: number): RgbColor {\n let chroma = c;\n for (let attempt = 0; attempt < 8; attempt += 1) {\n const rgb = tryOklchToSrgb(l, chroma, h);\n if (rgb) {\n return rgb;\n }\n chroma *= 0.9;\n }\n return tryOklchToSrgb(l, clamp01(chroma), h, true) || { r: 0, g: 0, b: 0 };\n}\n\nfunction relativeLuminance(hex: string) {\n const rgb = hexToRgb(hex);\n if (!rgb) {\n return 0;\n }\n const r = srgbChannelToLinear(rgb.r / 255);\n const g = srgbChannelToLinear(rgb.g / 255);\n const b = srgbChannelToLinear(rgb.b / 255);\n return 0.2126 * r + 0.7152 * g + 0.0722 * b;\n}\n\nfunction contrastRatio(hexA: string, hexB: string) {\n const lumA = relativeLuminance(hexA);\n const lumB = relativeLuminance(hexB);\n const lighter = Math.max(lumA, lumB);\n const darker = Math.min(lumA, lumB);\n return (lighter + 0.05) / (darker + 0.05);\n}\n\nfunction makeReadableTextOnSurface(\n baseOklch: OklchColor,\n surfaceHex: string,\n options: ReadableTextOptions = {},\n) {\n const minContrast = options.minContrast ?? BRAND_MIN_CONTRAST;\n const preferDark = options.preferDark !== false;\n const textChroma = Math.max(\n 0.01,\n Math.min(0.06, (baseOklch.c || 0.12) * (options.chromaScale ?? 0.25)),\n );\n const initialLightness = options.initialLightness ?? (preferDark ? 0.24 : 0.94);\n const direction = preferDark ? -1 : 1;\n const step = options.step ?? 0.03;\n let lightness = clamp01(initialLightness);\n let bestHex = rgbToHex(oklchToSrgb(lightness, textChroma, baseOklch.h));\n let bestContrast = contrastRatio(surfaceHex, bestHex);\n\n for (let attempt = 0; attempt < 48; attempt += 1) {\n const textHex = rgbToHex(oklchToSrgb(lightness, textChroma, baseOklch.h));\n const ratio = contrastRatio(surfaceHex, textHex);\n\n if (ratio > bestContrast) {\n bestContrast = ratio;\n bestHex = textHex;\n }\n if (ratio >= minContrast) {\n return textHex;\n }\n\n lightness = clamp01(lightness + direction * step);\n if (lightness === 0 || lightness === 1) {\n break;\n }\n }\n\n const fallbackDark = \"#000000\";\n const fallbackLight = \"#ffffff\";\n const darkRatio = contrastRatio(surfaceHex, fallbackDark);\n const lightRatio = contrastRatio(surfaceHex, fallbackLight);\n\n if (darkRatio >= minContrast || lightRatio >= minContrast) {\n return darkRatio >= lightRatio ? fallbackDark : fallbackLight;\n }\n\n return bestHex;\n}\n\nfunction pickForegroundColor(\n baseOklch: OklchColor,\n surfaceHex: string,\n options: ForegroundOptions = {},\n) {\n const minContrast = options.minContrast ?? BRAND_MIN_CONTRAST;\n const darkCandidate = options.darkCandidate ?? \"#101214\";\n const lightCandidate = options.lightCandidate ?? \"#ffffff\";\n const preferredCandidate = options.preferredCandidate;\n const preferredMinContrast = options.preferredMinContrast ?? minContrast;\n const preferredSwitchDelta = options.preferredSwitchDelta ?? 0;\n const darkRatio = contrastRatio(surfaceHex, darkCandidate);\n const lightRatio = contrastRatio(surfaceHex, lightCandidate);\n const darkPasses = darkRatio >= minContrast;\n const lightPasses = lightRatio >= minContrast;\n const preferredLightPasses = lightRatio >= preferredMinContrast;\n const preferredDarkPasses = darkRatio >= preferredMinContrast;\n\n if (darkPasses || lightPasses) {\n if (preferredCandidate === \"light\" && preferredLightPasses) {\n return lightCandidate;\n }\n if (preferredCandidate === \"dark\" && preferredDarkPasses) {\n return darkCandidate;\n }\n\n if (preferredCandidate === \"light\" && lightPasses) {\n if (!darkPasses || darkRatio - lightRatio <= preferredSwitchDelta) {\n return lightCandidate;\n }\n return darkCandidate;\n }\n if (preferredCandidate === \"dark\" && darkPasses) {\n if (!lightPasses || lightRatio - darkRatio <= preferredSwitchDelta) {\n return darkCandidate;\n }\n return lightCandidate;\n }\n\n if (darkPasses && lightPasses) {\n return darkRatio >= lightRatio ? darkCandidate : lightCandidate;\n }\n return darkPasses ? darkCandidate : lightCandidate;\n }\n\n const preferDark = darkRatio >= lightRatio;\n return makeReadableTextOnSurface(baseOklch, surfaceHex, {\n minContrast,\n preferDark,\n initialLightness: preferDark ? 0.2 : 0.96,\n chromaScale: 0.1,\n });\n}\n\nconst BRAND_STOPS = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000];\nconst BRAND_LIGHTNESS_CURVE = [0.9, 0.84, 0.78, 0.72, 0.67, 0.62, 0.56, 0.5, 0.44, 0.38];\nconst BRAND_CHROMA_MULTIPLIERS = [0.28, 0.4, 0.54, 0.7, 0.86, 1, 1.08, 1.14, 1.2, 1.24];\nconst BRAND_MIN_SURFACE_CONTRAST = 1.8;\nconst BRAND_MIN_SUBTLE_SURFACE_CONTRAST = 1.15;\nconst BRAND_MIN_SOFT_SURFACE_CONTRAST = 1.08;\nconst BRAND_UI_TEXT_MIN_CONTRAST = 4.5;\nconst BRAND_LIGHT_TEXT_SWITCH_DELTA = 3;\nconst LIGHT_CANVAS_HEX = \"#ffffff\";\nconst DARK_CANVAS_HEX = \"#1f2228\";\n\nfunction pickRampStopForContrast(\n ramp: BrandRamp,\n stopCandidates: number[],\n referenceHex: string,\n minContrast: number,\n) {\n const fallbackStop = stopCandidates[stopCandidates.length - 1];\n for (const stop of stopCandidates) {\n const candidate = ramp[stop];\n if (!candidate) {\n continue;\n }\n if (contrastRatio(candidate, referenceHex) >= minContrast) {\n return stop;\n }\n }\n return fallbackStop;\n}\n\nfunction makeBrandRampFromSeed(baseOklch: OklchColor): BrandRamp {\n const lightnessOffset = baseOklch.l - BRAND_LIGHTNESS_CURVE[5];\n const minSeedChroma = baseOklch.c > 0.02 ? 0.02 : 0;\n\n return BRAND_STOPS.reduce<BrandRamp>((acc, stop, index) => {\n const lightness = clamp01(BRAND_LIGHTNESS_CURVE[index] + lightnessOffset);\n const chroma = Math.min(\n 0.4,\n Math.max(minSeedChroma, baseOklch.c * BRAND_CHROMA_MULTIPLIERS[index]),\n );\n acc[stop] = rgbToHex(oklchToSrgb(lightness, chroma, baseOklch.h));\n return acc;\n }, {});\n}\n\nfunction makeSemanticBrandTokens(baseOklch: OklchColor, ramp: BrandRamp): BrandVars {\n const lightSoftStops = [100, 200, 300, 400, 500, 600, 700];\n const lightSoftStop = pickRampStopForContrast(\n ramp,\n lightSoftStops,\n LIGHT_CANVAS_HEX,\n BRAND_MIN_SOFT_SURFACE_CONTRAST,\n );\n const lightSoftIndex = lightSoftStops.indexOf(lightSoftStop);\n const lightSoftHoveredStop =\n lightSoftStops[Math.min(lightSoftIndex + 1, lightSoftStops.length - 1)];\n const lightSoftPressedStop =\n lightSoftStops[Math.min(lightSoftIndex + 2, lightSoftStops.length - 1)];\n\n const darkSoftStops = [1000, 900, 800, 700, 600, 500];\n const darkSoftStop = pickRampStopForContrast(\n ramp,\n darkSoftStops,\n DARK_CANVAS_HEX,\n BRAND_MIN_SOFT_SURFACE_CONTRAST,\n );\n const darkSoftIndex = darkSoftStops.indexOf(darkSoftStop);\n const darkSoftHoveredStop =\n darkSoftStops[Math.min(darkSoftIndex + 1, darkSoftStops.length - 1)];\n const darkSoftPressedStop =\n darkSoftStops[Math.min(darkSoftIndex + 2, darkSoftStops.length - 1)];\n\n const lightSubtleStops = [200, 300, 400, 500, 600, 700, 800];\n const lightSubtleStop = pickRampStopForContrast(\n ramp,\n lightSubtleStops,\n LIGHT_CANVAS_HEX,\n BRAND_MIN_SUBTLE_SURFACE_CONTRAST,\n );\n const darkSubtleStops = [900, 800, 700, 600, 500, 400];\n const darkSubtleStop = pickRampStopForContrast(\n ramp,\n darkSubtleStops,\n DARK_CANVAS_HEX,\n BRAND_MIN_SUBTLE_SURFACE_CONTRAST,\n );\n\n const lightStrongStops = [600, 700, 800, 900, 1000];\n const lightStrongStop = pickRampStopForContrast(\n ramp,\n lightStrongStops,\n LIGHT_CANVAS_HEX,\n BRAND_MIN_SURFACE_CONTRAST,\n );\n const lightStrongIndex = lightStrongStops.indexOf(lightStrongStop);\n const lightStrongHoveredStop =\n lightStrongStops[Math.min(lightStrongIndex + 1, lightStrongStops.length - 1)];\n const lightStrongPressedStop =\n lightStrongStops[Math.min(lightStrongIndex + 2, lightStrongStops.length - 1)];\n\n const darkStrongStops = [400, 300, 200, 100];\n const darkStrongStop = pickRampStopForContrast(\n ramp,\n darkStrongStops,\n DARK_CANVAS_HEX,\n BRAND_MIN_SURFACE_CONTRAST,\n );\n const darkStrongIndex = darkStrongStops.indexOf(darkStrongStop);\n const darkStrongHoveredStop =\n darkStrongStops[Math.min(darkStrongIndex + 1, darkStrongStops.length - 1)];\n const darkStrongPressedStop =\n darkStrongStops[Math.min(darkStrongIndex + 2, darkStrongStops.length - 1)];\n\n const tokens: BrandVars = {\n \"--color-brand-surface-soft-light\": ramp[lightSoftStop],\n \"--color-brand-surface-soft-hovered-light\": ramp[lightSoftHoveredStop],\n \"--color-brand-surface-soft-pressed-light\": ramp[lightSoftPressedStop],\n \"--color-brand-surface-soft-dark\": ramp[darkSoftStop],\n \"--color-brand-surface-soft-hovered-dark\": ramp[darkSoftHoveredStop],\n \"--color-brand-surface-soft-pressed-dark\": ramp[darkSoftPressedStop],\n \"--color-brand-surface-subtle-light\": ramp[lightSubtleStop],\n \"--color-brand-surface-subtle-dark\": ramp[darkSubtleStop],\n \"--color-brand-surface-strong-light\": ramp[lightStrongStop],\n \"--color-brand-surface-strong-hovered-light\": ramp[lightStrongHoveredStop],\n \"--color-brand-surface-strong-pressed-light\": ramp[lightStrongPressedStop],\n \"--color-brand-surface-strong-dark\": ramp[darkStrongStop],\n \"--color-brand-surface-strong-hovered-dark\": ramp[darkStrongHoveredStop],\n \"--color-brand-surface-strong-pressed-dark\": ramp[darkStrongPressedStop],\n };\n\n const preferredSoftLightForeground = ramp[600];\n const softLightContrast = contrastRatio(\n tokens[\"--color-brand-surface-soft-light\"],\n preferredSoftLightForeground,\n );\n tokens[\"--color-brand-on-soft-light\"] =\n softLightContrast >= BRAND_MIN_CONTRAST\n ? preferredSoftLightForeground\n : pickForegroundColor(baseOklch, tokens[\"--color-brand-surface-soft-light\"], {\n minContrast: BRAND_MIN_CONTRAST,\n });\n tokens[\"--color-brand-on-soft-dark\"] = pickForegroundColor(\n baseOklch,\n tokens[\"--color-brand-surface-soft-dark\"],\n {\n minContrast: BRAND_MIN_CONTRAST,\n },\n );\n tokens[\"--color-brand-on-subtle-light\"] = pickForegroundColor(\n baseOklch,\n tokens[\"--color-brand-surface-subtle-light\"],\n {\n minContrast: BRAND_UI_TEXT_MIN_CONTRAST,\n preferredCandidate: \"light\",\n preferredMinContrast: BRAND_UI_TEXT_MIN_CONTRAST,\n preferredSwitchDelta: BRAND_LIGHT_TEXT_SWITCH_DELTA,\n },\n );\n tokens[\"--color-brand-on-subtle-dark\"] = pickForegroundColor(\n baseOklch,\n tokens[\"--color-brand-surface-subtle-dark\"],\n {\n minContrast: BRAND_MIN_CONTRAST,\n },\n );\n tokens[\"--color-brand-on-strong-light\"] = pickForegroundColor(\n baseOklch,\n tokens[\"--color-brand-surface-strong-light\"],\n {\n minContrast: BRAND_UI_TEXT_MIN_CONTRAST,\n preferredCandidate: \"light\",\n preferredMinContrast: BRAND_UI_TEXT_MIN_CONTRAST,\n preferredSwitchDelta: BRAND_LIGHT_TEXT_SWITCH_DELTA,\n },\n );\n tokens[\"--color-brand-on-strong-dark\"] = pickForegroundColor(\n baseOklch,\n tokens[\"--color-brand-surface-strong-dark\"],\n {\n minContrast: BRAND_MIN_CONTRAST,\n },\n );\n\n tokens[\"--color-brand-text-light\"] = tokens[\"--color-brand-surface-strong-light\"];\n tokens[\"--color-brand-text-dark\"] = tokens[\"--color-brand-surface-strong-dark\"];\n tokens[\"--color-brand-icon-light\"] = tokens[\"--color-brand-surface-strong-light\"];\n tokens[\"--color-brand-icon-dark\"] = tokens[\"--color-brand-surface-strong-dark\"];\n tokens[\"--color-brand-border-light\"] = tokens[\"--color-brand-surface-strong-light\"];\n tokens[\"--color-brand-border-dark\"] = tokens[\"--color-brand-surface-strong-dark\"];\n\n return tokens;\n}\n\nfunction makeBrandTokens(baseHex: string | undefined): BrandVars | null {\n const norm = normalizeHex(baseHex);\n if (!norm) {\n return null;\n }\n\n const baseRgb = hexToRgb(norm);\n if (!baseRgb) {\n return null;\n }\n\n const baseOklch = rgbToOklch(baseRgb);\n const ramp = makeBrandRampFromSeed(baseOklch);\n // Keep the incoming seed exact for debugging and transparency.\n ramp[600] = norm;\n\n return {\n \"--color-brand-seed\": norm,\n \"--color-brand-100\": ramp[100],\n \"--color-brand-200\": ramp[200],\n \"--color-brand-300\": ramp[300],\n \"--color-brand-400\": ramp[400],\n \"--color-brand-500\": ramp[500],\n \"--color-brand-600\": ramp[600],\n \"--color-brand-700\": ramp[700],\n \"--color-brand-800\": ramp[800],\n \"--color-brand-900\": ramp[900],\n \"--color-brand-1000\": ramp[1000],\n ...makeSemanticBrandTokens(baseOklch, ramp),\n };\n}\n\nconst brandVars = computed(() => makeBrandTokens(props.accentColor) ?? {});\n\nconst accentStackEntry = {\n vars: {},\n enabled: Boolean(props.exposeGlobalAccent),\n};\nglobalAccentStack.push(accentStackEntry);\n\nwatch(\n () => props.exposeGlobalAccent,\n (enabled) => {\n accentStackEntry.enabled = Boolean(enabled);\n applyGlobalAccentFromStack();\n },\n { immediate: true },\n);\n\nwatch(\n brandVars,\n (vars) => {\n if (vars && Object.keys(vars).length > 0) {\n accentStackEntry.vars = { ...vars };\n } else {\n accentStackEntry.vars = {};\n }\n applyGlobalAccentFromStack();\n },\n { immediate: true },\n);\n</script>\n\n<style lang=\"less\">\n@import \"index.less\";\n</style>\n","<template>\n <DropdownMenu v-model:open=\"open\" text=\"Theme\" aria-label=\"Select theme mode\">\n <DropdownItemGroup title=\"Theme\" item-role=\"menuitemradio\">\n <DropdownItemRadio\n v-model:checked=\"internalMode\"\n value=\"auto\"\n :label=\"MODE_LABELS.auto\"\n :aria-label=\"`${MODE_LABELS.auto} mode`\"\n />\n <hr class=\"theme-switcher-divider\" />\n <DropdownItemRadio\n v-model:checked=\"internalMode\"\n value=\"light\"\n :label=\"MODE_LABELS.light\"\n :aria-label=\"`${MODE_LABELS.light} mode`\"\n />\n <DropdownItemRadio\n v-model:checked=\"internalMode\"\n value=\"dark\"\n :label=\"MODE_LABELS.dark\"\n :aria-label=\"`${MODE_LABELS.dark} mode`\"\n />\n </DropdownItemGroup>\n </DropdownMenu>\n</template>\n\n<script setup lang=\"ts\">\nimport { ref, watch } from \"vue\";\nimport type { PropType } from \"vue\";\nimport { DropdownMenu, DropdownItemGroup, DropdownItemRadio } from \"@gospore/dropdown-menu\";\nimport {\n readStoredMode,\n writeStoredMode,\n VALID_THEME_MODES,\n applyStoredModeToDocument,\n type ThemeMode,\n} from \"./modeStorage\";\n\nconst MODE_OPTIONS: { value: ThemeMode; label: string }[] = [\n { value: \"auto\", label: \"System\" },\n { value: \"light\", label: \"Light\" },\n { value: \"dark\", label: \"Dark\" },\n];\nconst MODE_LABELS = MODE_OPTIONS.reduce<Record<ThemeMode, string>>(\n (map, option) => {\n map[option.value] = option.label;\n return map;\n },\n {} as Record<ThemeMode, string>,\n);\nconst VALID_MODES = VALID_THEME_MODES;\n\nconst props = defineProps({\n /** Selected theme mode. Supports v-model:mode and persists changes to local storage. */\n mode: {\n type: String as PropType<ThemeMode>,\n default: \"auto\",\n validator: (value: string) => [\"auto\", \"light\", \"dark\"].includes(value),\n },\n});\nconst emit = defineEmits([\"update:mode\"]);\n\napplyStoredModeToDocument();\n\nconst open = ref(false);\nconst initialMode = readStoredMode() ?? props.mode;\nconst internalMode = ref<ThemeMode>(VALID_MODES.includes(initialMode) ? initialMode : \"auto\");\nwatch(\n () => props.mode,\n (mode) => {\n if (VALID_MODES.includes(mode) && mode !== internalMode.value) {\n internalMode.value = mode;\n }\n },\n);\n\nwatch(\n internalMode,\n (mode) => {\n if (!VALID_MODES.includes(mode)) {\n internalMode.value = \"auto\";\n return;\n }\n open.value = false;\n emit(\"update:mode\", mode);\n writeStoredMode(mode);\n applyStoredModeToDocument(mode);\n },\n { immediate: true },\n);\n</script>\n\n<style scoped lang=\"less\">\n.theme-switcher-divider {\n margin: 4px 0;\n}\n</style>\n","<template>\n <DropdownMenu v-model:open=\"open\" text=\"Theme\" aria-label=\"Select theme mode\">\n <DropdownItemGroup title=\"Theme\" item-role=\"menuitemradio\">\n <DropdownItemRadio\n v-model:checked=\"internalMode\"\n value=\"auto\"\n :label=\"MODE_LABELS.auto\"\n :aria-label=\"`${MODE_LABELS.auto} mode`\"\n />\n <hr class=\"theme-switcher-divider\" />\n <DropdownItemRadio\n v-model:checked=\"internalMode\"\n value=\"light\"\n :label=\"MODE_LABELS.light\"\n :aria-label=\"`${MODE_LABELS.light} mode`\"\n />\n <DropdownItemRadio\n v-model:checked=\"internalMode\"\n value=\"dark\"\n :label=\"MODE_LABELS.dark\"\n :aria-label=\"`${MODE_LABELS.dark} mode`\"\n />\n </DropdownItemGroup>\n </DropdownMenu>\n</template>\n\n<script setup lang=\"ts\">\nimport { ref, watch } from \"vue\";\nimport type { PropType } from \"vue\";\nimport { DropdownMenu, DropdownItemGroup, DropdownItemRadio } from \"@gospore/dropdown-menu\";\nimport {\n readStoredMode,\n writeStoredMode,\n VALID_THEME_MODES,\n applyStoredModeToDocument,\n type ThemeMode,\n} from \"./modeStorage\";\n\nconst MODE_OPTIONS: { value: ThemeMode; label: string }[] = [\n { value: \"auto\", label: \"System\" },\n { value: \"light\", label: \"Light\" },\n { value: \"dark\", label: \"Dark\" },\n];\nconst MODE_LABELS = MODE_OPTIONS.reduce<Record<ThemeMode, string>>(\n (map, option) => {\n map[option.value] = option.label;\n return map;\n },\n {} as Record<ThemeMode, string>,\n);\nconst VALID_MODES = VALID_THEME_MODES;\n\nconst props = defineProps({\n /** Selected theme mode. Supports v-model:mode and persists changes to local storage. */\n mode: {\n type: String as PropType<ThemeMode>,\n default: \"auto\",\n validator: (value: string) => [\"auto\", \"light\", \"dark\"].includes(value),\n },\n});\nconst emit = defineEmits<{\n \"update:mode\": [value: ThemeMode];\n}>();\n\napplyStoredModeToDocument();\n\nconst open = ref(false);\nconst initialMode = readStoredMode() ?? props.mode;\nconst internalMode = ref<ThemeMode>(VALID_MODES.includes(initialMode) ? initialMode : \"auto\");\nwatch(\n () => props.mode,\n (mode) => {\n if (VALID_MODES.includes(mode) && mode !== internalMode.value) {\n internalMode.value = mode;\n }\n },\n);\n\nwatch(\n internalMode,\n (mode) => {\n if (!VALID_MODES.includes(mode)) {\n internalMode.value = \"auto\";\n return;\n }\n open.value = false;\n emit(\"update:mode\", mode);\n writeStoredMode(mode);\n applyStoredModeToDocument(mode);\n },\n { immediate: true },\n);\n</script>\n\n<style scoped lang=\"less\">\n.theme-switcher-divider {\n margin: 4px 0;\n}\n</style>\n"],"mappings":"uaAAA,IAAM,EAAoB,CAAC,OAAQ,QAAS,MAAM,EAE5C,EAAc,qBACd,EAAsB,KAAU,GAAK,IACrC,EAAkB,+BAExB,SAAgB,GAAmC,CAC/C,GAAI,OAAO,SAAa,IACpB,OAAO,KAEX,IAAM,EAAS,EAAU,CAAW,EACpC,OAAO,EAAY,CAAM,EAAI,EAAS,IAC1C,CAEA,SAAgB,EAAgB,EAAiB,CAC7C,GAAI,OAAO,SAAa,KAAe,CAAC,EAAkB,SAAS,CAAI,EACnE,OAEJ,IAAM,EAAW,OAAO,OAAW,IAAc,OAAO,SAAS,SAAW,GACtE,EAAW,OAAO,OAAW,IAAc,OAAO,SAAS,SAAW,GACtE,EAAS,EAAgB,CAAQ,EACjC,EAAS,IAAa,SACtB,EAAa,CAA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aAAU,IAAA,EAAA,EAAA,MAAA,CAAK,CAAA,CAAW,CAAC,MAAK,+EAOnC,EAAA,iBAAA,EAAA,CAJU,QAAS,EAAA,qCAAY,MAAA,EAC7B,MAAM,OACL,OAAA,EAAA,EAAA,MAAA,CAAO,CAAA,CAAW,CAAC,KACnB,aAAU,IAAA,EAAA,EAAA,MAAA,CAAK,CAAA,CAAW,CAAC,KAAI"}
|
|
1
|
+
{"version":3,"file":"theme.umd.js","names":[],"sources":["../src/modeStorage.ts","../src/portalHost.ts","../src/Theme.vue","../src/Theme.vue","../src/ThemeSwitcher.vue","../src/ThemeSwitcher.vue","../src/themeBootstrap.ts"],"sourcesContent":["const VALID_THEME_MODES = [\"auto\", \"light\", \"dark\"] as const;\nexport type ThemeMode = (typeof VALID_THEME_MODES)[number];\nconst STORAGE_KEY = \"gospore-theme-mode\";\nconst ONE_YEAR_IN_SECONDS = 60 * 60 * 24 * 365;\nconst DARK_MODE_QUERY = \"(prefers-color-scheme: dark)\";\n\nexport function readStoredMode(): ThemeMode | null {\n if (typeof document === \"undefined\") {\n return null;\n }\n const stored = getCookie(STORAGE_KEY);\n return isThemeMode(stored) ? stored : null;\n}\n\nexport function writeStoredMode(mode: ThemeMode) {\n if (typeof document === \"undefined\" || !VALID_THEME_MODES.includes(mode)) {\n return;\n }\n const hostname = typeof window !== \"undefined\" ? window.location.hostname : \"\";\n const protocol = typeof window !== \"undefined\" ? window.location.protocol : \"\";\n const secure = protocol === \"https:\";\n const attributes = [\"path=/\", `max-age=${ONE_YEAR_IN_SECONDS}`, \"SameSite=Lax\"];\n if (secure) {\n attributes.push(\"Secure\");\n }\n\n const legacyDomain = getLegacyCookieDomain(hostname);\n if (legacyDomain) {\n document.cookie = [\n `${encodeURIComponent(STORAGE_KEY)}=`,\n \"path=/\",\n \"max-age=0\",\n \"SameSite=Lax\",\n `domain=${legacyDomain}`,\n ...(secure ? [\"Secure\"] : []),\n ].join(\"; \");\n }\n\n document.cookie = [\n `${encodeURIComponent(STORAGE_KEY)}=${encodeURIComponent(mode)}`,\n ...attributes,\n ].join(\"; \");\n}\n\n// Releases before host-only storage guessed a shared domain from the final two hostname labels.\n// Expire that exact legacy scope before writing the replacement so an older cookie cannot win when\n// a browser serializes duplicate names by creation time. Invalid public-suffix guesses are ignored\n// by the browser, just as they were when originally written.\nfunction getLegacyCookieDomain(hostname: string) {\n if (!hostname || hostname === \"localhost\") {\n return null;\n }\n const isIpAddress = /^\\d+(?:\\.\\d+){3}$/.test(hostname);\n if (isIpAddress) {\n return hostname;\n }\n const parts = hostname.split(\".\");\n if (parts.length <= 1) {\n return null;\n }\n return parts.slice(-2).join(\".\");\n}\n\nexport function applyStoredModeToDocument(mode?: string | null) {\n if (typeof document === \"undefined\") {\n return;\n }\n const resolvedMode = isThemeMode(mode) ? mode : (readStoredMode() ?? \"auto\");\n const darkMode = resolveDarkMode(resolvedMode);\n document.documentElement.setAttribute(\"dark-mode\", String(darkMode));\n}\n\nexport { VALID_THEME_MODES, STORAGE_KEY };\n\nfunction getCookie(name: string) {\n if (typeof document === \"undefined\" || !document.cookie) {\n return null;\n }\n const encodedName = `${encodeURIComponent(name)}=`;\n const cookies = document.cookie.split(\"; \");\n for (const cookie of cookies) {\n if (cookie.startsWith(encodedName)) {\n try {\n return decodeURIComponent(cookie.slice(encodedName.length));\n } catch {\n return null;\n }\n }\n }\n return null;\n}\n\nfunction resolveDarkMode(mode: string) {\n if (mode === \"dark\") {\n return true;\n }\n if (mode === \"light\") {\n return false;\n }\n if (typeof window === \"undefined\") {\n return false;\n }\n try {\n const mediaQueryList =\n typeof window.matchMedia === \"function\" ? window.matchMedia(DARK_MODE_QUERY) : null;\n return mediaQueryList ? mediaQueryList.matches : false;\n } catch {\n return false;\n }\n}\n\nfunction isThemeMode(value: string | null | undefined): value is ThemeMode {\n return typeof value === \"string\" && (VALID_THEME_MODES as readonly string[]).includes(value);\n}\n","import { computed, inject } from \"vue\";\nimport type { InjectionKey, Ref } from \"vue\";\n\nexport type ThemePortalTarget = HTMLElement | string;\n\nexport const themePortalHostKey = Symbol.for(\"gospore.theme.portalHost\") as InjectionKey<\n Ref<HTMLElement | null>\n>;\n\nexport function useThemePortalTarget() {\n const hostRef = inject(themePortalHostKey, null);\n const fallbackTarget: ThemePortalTarget = \"body\";\n\n return computed<ThemePortalTarget>(() => hostRef?.value ?? fallbackTarget);\n}\n","<script lang=\"ts\">\ninterface GlobalAccentEntry {\n vars: Record<string, string>;\n enabled: boolean;\n}\n\ninterface GlobalModeEntry {\n darkMode: boolean;\n}\n\nconst globalAccentStack: GlobalAccentEntry[] = [];\nconst appliedGlobalAccentKeys = new Set<string>();\nconst originalGlobalAccentValues = new Map<string, { priority: string; value: string }>();\nconst globalModeStack: GlobalModeEntry[] = [];\nlet originalGlobalDarkModeAttribute: string | null | undefined;\n\nconst DARK_MODE_QUERY = \"(prefers-color-scheme: dark)\"\nconst PREFERS_REDUCED_MOTION_QUERY = \"(prefers-reduced-motion: reduce)\"\nconst THEME_TRANSITION_DURATION = 200\nconst BRAND_MIN_CONTRAST = 4.5\nconst BRAND_MIN_SURFACE_CONTRAST = 1.8\nconst BRAND_MIN_SUBTLE_SURFACE_CONTRAST = 1.15\nconst BRAND_MIN_SOFT_SURFACE_CONTRAST = 1.08\nconst BRAND_UI_TEXT_MIN_CONTRAST = 4.5\nconst BRAND_LIGHT_TEXT_SWITCH_DELTA = 3\nconst LIGHT_CANVAS_HEX = \"#ffffff\"\nconst DARK_CANVAS_HEX = \"#1f2228\"</script>\n\n<template>\n <div class=\"theme\" :style=\"brandVars\">\n <slot />\n <div ref=\"portalHost\" class=\"theme__portal-host\"></div>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { provide, ref, watch, onBeforeUnmount, computed, inject } from \"vue\";\nimport type { PropType, Ref } from \"vue\";\nimport { readStoredMode, type ThemeMode } from \"./modeStorage\";\nimport \"what-input\";\nimport { themePortalHostKey } from \"./portalHost\";\n\ninterface RgbColor {\n r: number;\n g: number;\n b: number;\n}\n\ninterface OklchColor {\n l: number;\n c: number;\n h: number;\n}\n\ntype BrandRamp = Record<number, string>;\ntype BrandVars = Record<string, string>;\n\ninterface ReadableTextOptions {\n minContrast?: number;\n preferDark?: boolean;\n chromaScale?: number;\n initialLightness?: number;\n step?: number;\n}\n\ninterface ForegroundOptions extends ReadableTextOptions {\n darkCandidate?: string;\n lightCandidate?: string;\n preferredCandidate?: \"dark\" | \"light\";\n preferredMinContrast?: number;\n preferredSwitchDelta?: number;\n}\n\ndefineOptions({\n name: \"Theme\",\n});\ndefineSlots<{\n /** Application content that receives theme tokens and portal context. */\n default?: () => unknown;\n}>();\nconst props = defineProps({\n /**\n * Controls which color mode is active. auto follows the OS preference (and persisted storage\n * when used with ThemeSwitcher).\n */\n mode: {\n type: String as PropType<ThemeMode | undefined>,\n default: undefined,\n validator: (value: string) => [\"auto\", \"light\", \"dark\"].includes(value),\n },\n /**\n * Optional hex accent color (\"#RRGGBB\" or \"#RGB\"). When provided, Theme derives contrast-safe\n * semantic brand tokens and exposes them on the root .theme element (and the global document\n * for portals).\n */\n accentColor: {\n type: String,\n required: false,\n default: undefined,\n },\n /**\n * When true the brand vars are also exposed on <html>, allowing portals attached outside the\n * Theme subtree to inherit the accent colors.\n */\n exposeGlobalAccent: {\n type: Boolean,\n default: false,\n },\n});\n\nfunction applyGlobalAccentFromStack() {\n if (typeof document === \"undefined\") {\n return;\n }\n const root = document.documentElement;\n if (!root) {\n return;\n }\n\n appliedGlobalAccentKeys.forEach((key) => {\n const original = originalGlobalAccentValues.get(key);\n if (original?.value) {\n root.style.setProperty(key, original.value, original.priority);\n } else {\n root.style.removeProperty(key);\n }\n });\n appliedGlobalAccentKeys.clear();\n\n const activeEntry = [...globalAccentStack]\n .reverse()\n .find((entry) => entry.enabled && entry.vars && Object.keys(entry.vars).length > 0);\n\n if (!activeEntry) {\n originalGlobalAccentValues.clear();\n return;\n }\n\n Object.entries(activeEntry.vars).forEach(([key, value]) => {\n if (!originalGlobalAccentValues.has(key)) {\n originalGlobalAccentValues.set(key, {\n priority: root.style.getPropertyPriority(key),\n value: root.style.getPropertyValue(key),\n });\n }\n root.style.setProperty(key, value);\n appliedGlobalAccentKeys.add(key);\n });\n}\n\n\n\n\nconst darkModeMedia = getMediaQueryList(DARK_MODE_QUERY);\nconst prefersReducedMotionMedia = getMediaQueryList(PREFERS_REDUCED_MOTION_QUERY);\nconst parentTheme = inject<Ref<{ darkMode: boolean }> | null>(\"theme\", null);\n\nconst initialMode = getEffectiveMode();\nconst currentMode = ref(initialMode);\nlet transitionAnimationFrameID: number | null = null;\n\nconst theme = ref({\n darkMode: resolveDarkMode(initialMode),\n});\nconst modeStackEntry: GlobalModeEntry = {\n darkMode: theme.value.darkMode,\n};\nlet modeStackEntryRegistered = false;\nsyncGlobalModeOwnership();\nconst portalHost = ref<HTMLElement | null>(null);\n\ndarkModeMedia.addEventListener(\"change\", handleSystemPreferenceChange);\n\nwatch(\n () => props.mode,\n () => {\n syncDarkMode();\n },\n { immediate: true },\n);\nwatch(\n () => parentTheme?.value.darkMode,\n () => {\n if (props.mode === undefined) {\n syncDarkMode();\n }\n },\n);\n\nwatch(\n () => theme.value.darkMode,\n (darkMode, previousValue) => {\n modeStackEntry.darkMode = darkMode;\n if (!modeStackEntryRegistered || !isActiveGlobalModeEntry(modeStackEntry)) {\n return;\n }\n if (previousValue === undefined) {\n setDocumentDarkModeAttribute(darkMode);\n return;\n }\n withThemeTransition(() => {\n if (isActiveGlobalModeEntry(modeStackEntry)) {\n setDocumentDarkModeAttribute(darkMode);\n }\n });\n },\n { immediate: true },\n);\n\nonBeforeUnmount(() => {\n darkModeMedia.removeEventListener(\"change\", handleSystemPreferenceChange);\n if (transitionAnimationFrameID !== null && typeof window !== \"undefined\") {\n window.cancelAnimationFrame(transitionAnimationFrameID);\n transitionAnimationFrameID = null;\n }\n if (modeStackEntryRegistered) {\n unregisterGlobalModeEntry(modeStackEntry);\n }\n const index = globalAccentStack.indexOf(accentStackEntry);\n if (index !== -1) {\n globalAccentStack.splice(index, 1);\n }\n applyGlobalAccentFromStack();\n});\n\nfunction syncDarkMode() {\n const mode = getEffectiveMode();\n const darkMode = resolveDarkMode(mode);\n currentMode.value = mode;\n modeStackEntry.darkMode = darkMode;\n syncGlobalModeOwnership();\n theme.value.darkMode = darkMode;\n}\n\nfunction syncGlobalModeOwnership() {\n const shouldOwnGlobalMode = parentTheme === null || props.mode !== undefined;\n if (shouldOwnGlobalMode && !modeStackEntryRegistered) {\n modeStackEntryRegistered = registerGlobalModeEntry(modeStackEntry);\n } else if (!shouldOwnGlobalMode && modeStackEntryRegistered) {\n unregisterGlobalModeEntry(modeStackEntry);\n modeStackEntryRegistered = false;\n }\n}\n\nfunction resolveDarkMode(mode: ThemeMode) {\n if (mode === \"dark\") {\n return true;\n }\n if (mode === \"light\") {\n return false;\n }\n return darkModeMedia.matches;\n}\n\nfunction handleSystemPreferenceChange(event: MediaQueryListEvent) {\n if (!event || currentMode.value !== \"auto\") {\n return;\n }\n theme.value.darkMode = event.matches;\n}\n\nfunction setDocumentDarkModeAttribute(darkMode: boolean) {\n if (typeof document === \"undefined\") {\n return;\n }\n document.documentElement.setAttribute(\"dark-mode\", String(darkMode));\n}\n\nfunction registerGlobalModeEntry(entry: GlobalModeEntry) {\n if (typeof document === \"undefined\") {\n return false;\n }\n if (globalModeStack.length === 0) {\n originalGlobalDarkModeAttribute = document.documentElement.getAttribute(\"dark-mode\");\n }\n globalModeStack.push(entry);\n setDocumentDarkModeAttribute(entry.darkMode);\n return true;\n}\n\nfunction isActiveGlobalModeEntry(entry: GlobalModeEntry) {\n return globalModeStack.at(-1) === entry;\n}\n\nfunction unregisterGlobalModeEntry(entry: GlobalModeEntry) {\n const index = globalModeStack.indexOf(entry);\n if (index === -1) {\n return;\n }\n\n const wasActive = index === globalModeStack.length - 1;\n globalModeStack.splice(index, 1);\n if (!wasActive || typeof document === \"undefined\") {\n return;\n }\n\n const previousEntry = globalModeStack.at(-1);\n if (previousEntry) {\n setDocumentDarkModeAttribute(previousEntry.darkMode);\n return;\n }\n\n if (originalGlobalDarkModeAttribute === null) {\n document.documentElement.removeAttribute(\"dark-mode\");\n } else if (originalGlobalDarkModeAttribute !== undefined) {\n document.documentElement.setAttribute(\"dark-mode\", originalGlobalDarkModeAttribute);\n }\n originalGlobalDarkModeAttribute = undefined;\n}\n\nfunction withThemeTransition(applyTheme: () => void) {\n if (\n prefersReducedMotionMedia.matches ||\n typeof document === \"undefined\" ||\n typeof window === \"undefined\"\n ) {\n applyTheme();\n return;\n }\n const startViewTransition = document.startViewTransition?.bind(document);\n if (startViewTransition) {\n startViewTransition(() => {\n applyTheme();\n });\n return;\n }\n applyTheme();\n const element = document.documentElement;\n if (typeof element.animate !== \"function\") {\n return;\n }\n if (transitionAnimationFrameID !== null) {\n window.cancelAnimationFrame(transitionAnimationFrameID);\n }\n transitionAnimationFrameID = window.requestAnimationFrame(() => {\n transitionAnimationFrameID = null;\n element.animate([{ opacity: 0.85 }, { opacity: 1 }], {\n duration: THEME_TRANSITION_DURATION,\n easing: \"ease-in-out\",\n });\n });\n}\n\nfunction getEffectiveMode(): ThemeMode {\n if (props.mode === undefined && parentTheme) {\n return parentTheme.value.darkMode ? \"dark\" : \"light\";\n }\n return props.mode ?? readStoredMode() ?? \"auto\";\n}\n\nfunction getMediaQueryList(query: string): MediaQueryList {\n if (typeof window !== \"undefined\" && typeof window.matchMedia === \"function\") {\n try {\n return window.matchMedia(query);\n } catch {\n // Fall through to a non-matching server-safe implementation.\n }\n }\n\n return {\n addEventListener() {},\n addListener() {},\n dispatchEvent: () => false,\n matches: false,\n media: query,\n onchange: null,\n removeEventListener() {},\n removeListener() {},\n };\n}\n\nprovide(\"theme\", theme);\nprovide(themePortalHostKey, portalHost);\n\n// --- Accent helpers -------------------------------------------------------\n\n\nfunction normalizeHex(hex: string | undefined) {\n if (!hex) return null;\n const h = hex.trim().toLowerCase();\n const m = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.exec(h);\n if (!m) return null;\n if (h.length === 4) {\n // expand #rgb -> #rrggbb\n const r = h[1],\n g = h[2],\n b = h[3];\n return `#${r}${r}${g}${g}${b}${b}`;\n }\n return h;\n}\n\nfunction hexToRgb(hex: string | undefined): RgbColor | null {\n const h = normalizeHex(hex);\n if (!h) return null;\n const r = parseInt(h.slice(1, 3), 16);\n const g = parseInt(h.slice(3, 5), 16);\n const b = parseInt(h.slice(5, 7), 16);\n return { r, g, b };\n}\n\nfunction rgbToHex({ r, g, b }: RgbColor) {\n const toHex = (value: number) => value.toString(16).padStart(2, \"0\");\n return `#${toHex(r)}${toHex(g)}${toHex(b)}`;\n}\n\nfunction clamp01(value: number) {\n return Math.max(0, Math.min(1, value));\n}\n\nfunction srgbChannelToLinear(channel: number) {\n if (channel <= 0.04045) {\n return channel / 12.92;\n }\n return Math.pow((channel + 0.055) / 1.055, 2.4);\n}\n\nfunction linearChannelToSrgb(channel: number) {\n const normalized = clamp01(channel);\n if (normalized <= 0.0031308) {\n return 12.92 * normalized;\n }\n return 1.055 * Math.pow(normalized, 1 / 2.4) - 0.055;\n}\n\nfunction rgbToOklch({ r, g, b }: RgbColor): OklchColor {\n const rNorm = r / 255;\n const gNorm = g / 255;\n const bNorm = b / 255;\n\n const rLin = srgbChannelToLinear(rNorm);\n const gLin = srgbChannelToLinear(gNorm);\n const bLin = srgbChannelToLinear(bNorm);\n\n const l = 0.4122214708 * rLin + 0.5363325363 * gLin + 0.0514459929 * bLin;\n const m = 0.2119034982 * rLin + 0.6806995451 * gLin + 0.1073969566 * bLin;\n const s = 0.0883024619 * rLin + 0.2817188376 * gLin + 0.6299787005 * bLin;\n\n const lRoot = Math.cbrt(l);\n const mRoot = Math.cbrt(m);\n const sRoot = Math.cbrt(s);\n\n const oklabL = 0.2104542553 * lRoot + 0.793617785 * mRoot - 0.0040720468 * sRoot;\n const oklabA = 1.9779984951 * lRoot - 2.428592205 * mRoot + 0.4505937099 * sRoot;\n const oklabB = 0.0259040371 * lRoot + 0.7827717662 * mRoot - 0.808675766 * sRoot;\n\n const chroma = Math.sqrt(oklabA * oklabA + oklabB * oklabB);\n let hue = Math.atan2(oklabB, oklabA) * (180 / Math.PI);\n if (hue < 0) {\n hue += 360;\n }\n\n return { l: oklabL, c: chroma, h: hue };\n}\n\nfunction tryOklchToSrgb(l: number, c: number, h: number, clampLinear = false): RgbColor | null {\n const angle = (h * Math.PI) / 180;\n const a = c * Math.cos(angle);\n const b = c * Math.sin(angle);\n\n const lComponent = l + 0.3963377774 * a + 0.2158037573 * b;\n const mComponent = l - 0.1055613458 * a - 0.0638541728 * b;\n const sComponent = l - 0.0894841775 * a - 1.291485548 * b;\n\n const lCube = clampLinear ? clamp01(lComponent) : lComponent;\n const mCube = clampLinear ? clamp01(mComponent) : mComponent;\n const sCube = clampLinear ? clamp01(sComponent) : sComponent;\n\n if (!clampLinear) {\n const outOfRange =\n lCube < -0.0001 ||\n lCube > 1.0001 ||\n mCube < -0.0001 ||\n mCube > 1.0001 ||\n sCube < -0.0001 ||\n sCube > 1.0001;\n if (outOfRange) {\n return null;\n }\n }\n\n const lLin = lCube * lCube * lCube;\n const mLin = mCube * mCube * mCube;\n const sLin = sCube * sCube * sCube;\n\n let rLin = 4.0767416621 * lLin - 3.3077115913 * mLin + 0.2309699292 * sLin;\n let gLin = -1.2684380046 * lLin + 2.6097574011 * mLin - 0.3413193965 * sLin;\n let bLin = -0.0041960863 * lLin - 0.7034186147 * mLin + 1.707614701 * sLin;\n\n if (clampLinear) {\n rLin = clamp01(rLin);\n gLin = clamp01(gLin);\n bLin = clamp01(bLin);\n } else {\n const outOfRange =\n rLin < -0.0001 ||\n rLin > 1.0001 ||\n gLin < -0.0001 ||\n gLin > 1.0001 ||\n bLin < -0.0001 ||\n bLin > 1.0001;\n if (outOfRange) {\n return null;\n }\n }\n\n const r = clamp01(linearChannelToSrgb(rLin));\n const g = clamp01(linearChannelToSrgb(gLin));\n const bValue = clamp01(linearChannelToSrgb(bLin));\n\n return {\n r: Math.round(r * 255),\n g: Math.round(g * 255),\n b: Math.round(bValue * 255),\n };\n}\n\nfunction oklchToSrgb(l: number, c: number, h: number): RgbColor {\n let chroma = c;\n for (let attempt = 0; attempt < 8; attempt += 1) {\n const rgb = tryOklchToSrgb(l, chroma, h);\n if (rgb) {\n return rgb;\n }\n chroma *= 0.9;\n }\n return tryOklchToSrgb(l, clamp01(chroma), h, true) || { r: 0, g: 0, b: 0 };\n}\n\nfunction relativeLuminance(hex: string) {\n const rgb = hexToRgb(hex);\n if (!rgb) {\n return 0;\n }\n const r = srgbChannelToLinear(rgb.r / 255);\n const g = srgbChannelToLinear(rgb.g / 255);\n const b = srgbChannelToLinear(rgb.b / 255);\n return 0.2126 * r + 0.7152 * g + 0.0722 * b;\n}\n\nfunction contrastRatio(hexA: string, hexB: string) {\n const lumA = relativeLuminance(hexA);\n const lumB = relativeLuminance(hexB);\n const lighter = Math.max(lumA, lumB);\n const darker = Math.min(lumA, lumB);\n return (lighter + 0.05) / (darker + 0.05);\n}\n\nfunction makeReadableTextOnSurface(\n baseOklch: OklchColor,\n surfaceHex: string,\n options: ReadableTextOptions = {},\n) {\n const minContrast = options.minContrast ?? BRAND_MIN_CONTRAST;\n const preferDark = options.preferDark !== false;\n const textChroma = Math.max(\n 0.01,\n Math.min(0.06, (baseOklch.c || 0.12) * (options.chromaScale ?? 0.25)),\n );\n const initialLightness = options.initialLightness ?? (preferDark ? 0.24 : 0.94);\n const direction = preferDark ? -1 : 1;\n const step = options.step ?? 0.03;\n let lightness = clamp01(initialLightness);\n let bestHex = rgbToHex(oklchToSrgb(lightness, textChroma, baseOklch.h));\n let bestContrast = contrastRatio(surfaceHex, bestHex);\n\n for (let attempt = 0; attempt < 48; attempt += 1) {\n const textHex = rgbToHex(oklchToSrgb(lightness, textChroma, baseOklch.h));\n const ratio = contrastRatio(surfaceHex, textHex);\n\n if (ratio > bestContrast) {\n bestContrast = ratio;\n bestHex = textHex;\n }\n if (ratio >= minContrast) {\n return textHex;\n }\n\n lightness = clamp01(lightness + direction * step);\n if (lightness === 0 || lightness === 1) {\n break;\n }\n }\n\n const fallbackDark = \"#000000\";\n const fallbackLight = \"#ffffff\";\n const darkRatio = contrastRatio(surfaceHex, fallbackDark);\n const lightRatio = contrastRatio(surfaceHex, fallbackLight);\n\n if (darkRatio >= minContrast || lightRatio >= minContrast) {\n return darkRatio >= lightRatio ? fallbackDark : fallbackLight;\n }\n\n return bestHex;\n}\n\nfunction pickForegroundColor(\n baseOklch: OklchColor,\n surfaceHex: string,\n options: ForegroundOptions = {},\n) {\n const minContrast = options.minContrast ?? BRAND_MIN_CONTRAST;\n const darkCandidate = options.darkCandidate ?? \"#101214\";\n const lightCandidate = options.lightCandidate ?? \"#ffffff\";\n const preferredCandidate = options.preferredCandidate;\n const preferredMinContrast = options.preferredMinContrast ?? minContrast;\n const preferredSwitchDelta = options.preferredSwitchDelta ?? 0;\n const darkRatio = contrastRatio(surfaceHex, darkCandidate);\n const lightRatio = contrastRatio(surfaceHex, lightCandidate);\n const darkPasses = darkRatio >= minContrast;\n const lightPasses = lightRatio >= minContrast;\n const preferredLightPasses = lightRatio >= preferredMinContrast;\n const preferredDarkPasses = darkRatio >= preferredMinContrast;\n\n if (darkPasses || lightPasses) {\n if (preferredCandidate === \"light\" && preferredLightPasses) {\n return lightCandidate;\n }\n if (preferredCandidate === \"dark\" && preferredDarkPasses) {\n return darkCandidate;\n }\n\n if (preferredCandidate === \"light\" && lightPasses) {\n if (!darkPasses || darkRatio - lightRatio <= preferredSwitchDelta) {\n return lightCandidate;\n }\n return darkCandidate;\n }\n if (preferredCandidate === \"dark\" && darkPasses) {\n if (!lightPasses || lightRatio - darkRatio <= preferredSwitchDelta) {\n return darkCandidate;\n }\n return lightCandidate;\n }\n\n if (darkPasses && lightPasses) {\n return darkRatio >= lightRatio ? darkCandidate : lightCandidate;\n }\n return darkPasses ? darkCandidate : lightCandidate;\n }\n\n const preferDark = darkRatio >= lightRatio;\n return makeReadableTextOnSurface(baseOklch, surfaceHex, {\n minContrast,\n preferDark,\n initialLightness: preferDark ? 0.2 : 0.96,\n chromaScale: 0.1,\n });\n}\n\nconst BRAND_STOPS = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000];\nconst BRAND_LIGHTNESS_CURVE = [0.9, 0.84, 0.78, 0.72, 0.67, 0.62, 0.56, 0.5, 0.44, 0.38];\nconst BRAND_CHROMA_MULTIPLIERS = [0.28, 0.4, 0.54, 0.7, 0.86, 1, 1.08, 1.14, 1.2, 1.24];\n\n\n\n\n\n\n\n\nfunction pickRampStopForContrast(\n ramp: BrandRamp,\n stopCandidates: number[],\n referenceHex: string,\n minContrast: number,\n) {\n const fallbackStop = stopCandidates[stopCandidates.length - 1];\n for (const stop of stopCandidates) {\n const candidate = ramp[stop];\n if (!candidate) {\n continue;\n }\n if (contrastRatio(candidate, referenceHex) >= minContrast) {\n return stop;\n }\n }\n return fallbackStop;\n}\n\nfunction pickReadableRampText(\n baseOklch: OklchColor,\n ramp: BrandRamp,\n stopCandidates: number[],\n surfaceHex: string,\n preferDark: boolean,\n) {\n for (const stop of stopCandidates) {\n const candidate = ramp[stop];\n if (candidate && contrastRatio(candidate, surfaceHex) >= BRAND_UI_TEXT_MIN_CONTRAST) {\n return candidate;\n }\n }\n\n return makeReadableTextOnSurface(baseOklch, surfaceHex, {\n chromaScale: 1,\n initialLightness: preferDark ? 0.45 : 0.72,\n minContrast: BRAND_UI_TEXT_MIN_CONTRAST,\n preferDark,\n });\n}\n\nfunction makeBrandRampFromSeed(baseOklch: OklchColor): BrandRamp {\n const lightnessOffset = baseOklch.l - BRAND_LIGHTNESS_CURVE[5];\n const minSeedChroma = baseOklch.c > 0.02 ? 0.02 : 0;\n\n return BRAND_STOPS.reduce<BrandRamp>((acc, stop, index) => {\n const lightness = clamp01(BRAND_LIGHTNESS_CURVE[index] + lightnessOffset);\n const chroma = Math.min(\n 0.4,\n Math.max(minSeedChroma, baseOklch.c * BRAND_CHROMA_MULTIPLIERS[index]),\n );\n acc[stop] = rgbToHex(oklchToSrgb(lightness, chroma, baseOklch.h));\n return acc;\n }, {});\n}\n\nfunction makeSemanticBrandTokens(baseOklch: OklchColor, ramp: BrandRamp): BrandVars {\n const lightSoftStops = [100, 200, 300, 400, 500, 600, 700];\n const lightSoftStop = pickRampStopForContrast(\n ramp,\n lightSoftStops,\n LIGHT_CANVAS_HEX,\n BRAND_MIN_SOFT_SURFACE_CONTRAST,\n );\n const lightSoftIndex = lightSoftStops.indexOf(lightSoftStop);\n const lightSoftHoveredStop =\n lightSoftStops[Math.min(lightSoftIndex + 1, lightSoftStops.length - 1)];\n const lightSoftPressedStop =\n lightSoftStops[Math.min(lightSoftIndex + 2, lightSoftStops.length - 1)];\n\n const darkSoftStops = [1000, 900, 800, 700, 600, 500];\n const darkSoftStop = pickRampStopForContrast(\n ramp,\n darkSoftStops,\n DARK_CANVAS_HEX,\n BRAND_MIN_SOFT_SURFACE_CONTRAST,\n );\n const darkSoftIndex = darkSoftStops.indexOf(darkSoftStop);\n const darkSoftHoveredStop =\n darkSoftStops[Math.min(darkSoftIndex + 1, darkSoftStops.length - 1)];\n const darkSoftPressedStop =\n darkSoftStops[Math.min(darkSoftIndex + 2, darkSoftStops.length - 1)];\n\n const lightSubtleStops = [200, 300, 400, 500, 600, 700, 800];\n const lightSubtleStop = pickRampStopForContrast(\n ramp,\n lightSubtleStops,\n LIGHT_CANVAS_HEX,\n BRAND_MIN_SUBTLE_SURFACE_CONTRAST,\n );\n const darkSubtleStops = [900, 800, 700, 600, 500, 400];\n const darkSubtleStop = pickRampStopForContrast(\n ramp,\n darkSubtleStops,\n DARK_CANVAS_HEX,\n BRAND_MIN_SUBTLE_SURFACE_CONTRAST,\n );\n\n const lightStrongStops = [600, 700, 800, 900, 1000];\n const lightStrongStop = pickRampStopForContrast(\n ramp,\n lightStrongStops,\n LIGHT_CANVAS_HEX,\n BRAND_MIN_SURFACE_CONTRAST,\n );\n const lightStrongIndex = lightStrongStops.indexOf(lightStrongStop);\n const lightStrongHoveredStop =\n lightStrongStops[Math.min(lightStrongIndex + 1, lightStrongStops.length - 1)];\n const lightStrongPressedStop =\n lightStrongStops[Math.min(lightStrongIndex + 2, lightStrongStops.length - 1)];\n\n const darkStrongStops = [400, 300, 200, 100];\n const darkStrongStop = pickRampStopForContrast(\n ramp,\n darkStrongStops,\n DARK_CANVAS_HEX,\n BRAND_MIN_SURFACE_CONTRAST,\n );\n const darkStrongIndex = darkStrongStops.indexOf(darkStrongStop);\n const darkStrongHoveredStop =\n darkStrongStops[Math.min(darkStrongIndex + 1, darkStrongStops.length - 1)];\n const darkStrongPressedStop =\n darkStrongStops[Math.min(darkStrongIndex + 2, darkStrongStops.length - 1)];\n\n const tokens: BrandVars = {\n \"--color-brand-surface-soft-light\": ramp[lightSoftStop],\n \"--color-brand-surface-soft-hovered-light\": ramp[lightSoftHoveredStop],\n \"--color-brand-surface-soft-pressed-light\": ramp[lightSoftPressedStop],\n \"--color-brand-surface-soft-dark\": ramp[darkSoftStop],\n \"--color-brand-surface-soft-hovered-dark\": ramp[darkSoftHoveredStop],\n \"--color-brand-surface-soft-pressed-dark\": ramp[darkSoftPressedStop],\n \"--color-brand-surface-subtle-light\": ramp[lightSubtleStop],\n \"--color-brand-surface-subtle-dark\": ramp[darkSubtleStop],\n \"--color-brand-surface-strong-light\": ramp[lightStrongStop],\n \"--color-brand-surface-strong-hovered-light\": ramp[lightStrongHoveredStop],\n \"--color-brand-surface-strong-pressed-light\": ramp[lightStrongPressedStop],\n \"--color-brand-surface-strong-dark\": ramp[darkStrongStop],\n \"--color-brand-surface-strong-hovered-dark\": ramp[darkStrongHoveredStop],\n \"--color-brand-surface-strong-pressed-dark\": ramp[darkStrongPressedStop],\n };\n\n const preferredSoftLightForeground = ramp[600];\n const softLightContrast = contrastRatio(\n tokens[\"--color-brand-surface-soft-light\"],\n preferredSoftLightForeground,\n );\n tokens[\"--color-brand-on-soft-light\"] =\n softLightContrast >= BRAND_MIN_CONTRAST\n ? preferredSoftLightForeground\n : pickForegroundColor(baseOklch, tokens[\"--color-brand-surface-soft-light\"], {\n minContrast: BRAND_MIN_CONTRAST,\n });\n tokens[\"--color-brand-on-soft-dark\"] = pickForegroundColor(\n baseOklch,\n tokens[\"--color-brand-surface-soft-dark\"],\n {\n minContrast: BRAND_MIN_CONTRAST,\n },\n );\n tokens[\"--color-brand-on-subtle-light\"] = pickForegroundColor(\n baseOklch,\n tokens[\"--color-brand-surface-subtle-light\"],\n {\n minContrast: BRAND_UI_TEXT_MIN_CONTRAST,\n preferredCandidate: \"light\",\n preferredMinContrast: BRAND_UI_TEXT_MIN_CONTRAST,\n preferredSwitchDelta: BRAND_LIGHT_TEXT_SWITCH_DELTA,\n },\n );\n tokens[\"--color-brand-on-subtle-dark\"] = pickForegroundColor(\n baseOklch,\n tokens[\"--color-brand-surface-subtle-dark\"],\n {\n minContrast: BRAND_MIN_CONTRAST,\n },\n );\n tokens[\"--color-brand-on-strong-light\"] = pickForegroundColor(\n baseOklch,\n tokens[\"--color-brand-surface-strong-light\"],\n {\n minContrast: BRAND_UI_TEXT_MIN_CONTRAST,\n preferredCandidate: \"light\",\n preferredMinContrast: BRAND_UI_TEXT_MIN_CONTRAST,\n preferredSwitchDelta: BRAND_LIGHT_TEXT_SWITCH_DELTA,\n },\n );\n tokens[\"--color-brand-on-strong-dark\"] = pickForegroundColor(\n baseOklch,\n tokens[\"--color-brand-surface-strong-dark\"],\n {\n minContrast: BRAND_MIN_CONTRAST,\n },\n );\n\n tokens[\"--color-brand-text-light\"] = pickReadableRampText(\n baseOklch,\n ramp,\n [600, 700, 800, 900, 1000],\n LIGHT_CANVAS_HEX,\n true,\n );\n tokens[\"--color-brand-text-dark\"] = pickReadableRampText(\n baseOklch,\n ramp,\n [400, 300, 200, 100],\n DARK_CANVAS_HEX,\n false,\n );\n tokens[\"--color-brand-icon-light\"] = tokens[\"--color-brand-text-light\"];\n tokens[\"--color-brand-icon-dark\"] = tokens[\"--color-brand-text-dark\"];\n tokens[\"--color-brand-border-light\"] = tokens[\"--color-brand-text-light\"];\n tokens[\"--color-brand-border-dark\"] = tokens[\"--color-brand-text-dark\"];\n\n return tokens;\n}\n\nfunction makeBrandTokens(baseHex: string | undefined): BrandVars | null {\n const norm = normalizeHex(baseHex);\n if (!norm) {\n return null;\n }\n\n const baseRgb = hexToRgb(norm);\n if (!baseRgb) {\n return null;\n }\n\n const baseOklch = rgbToOklch(baseRgb);\n const ramp = makeBrandRampFromSeed(baseOklch);\n // Keep the incoming seed exact for debugging and transparency.\n ramp[600] = norm;\n\n return {\n \"--color-brand-seed\": norm,\n \"--color-brand-100\": ramp[100],\n \"--color-brand-200\": ramp[200],\n \"--color-brand-300\": ramp[300],\n \"--color-brand-400\": ramp[400],\n \"--color-brand-500\": ramp[500],\n \"--color-brand-600\": ramp[600],\n \"--color-brand-700\": ramp[700],\n \"--color-brand-800\": ramp[800],\n \"--color-brand-900\": ramp[900],\n \"--color-brand-1000\": ramp[1000],\n ...makeSemanticBrandTokens(baseOklch, ramp),\n };\n}\n\nconst brandVars = computed(() => makeBrandTokens(props.accentColor) ?? {});\n\nconst accentStackEntry = {\n vars: {},\n enabled: Boolean(props.exposeGlobalAccent),\n};\nif (typeof document !== \"undefined\") {\n globalAccentStack.push(accentStackEntry);\n}\n\nwatch(\n () => props.exposeGlobalAccent,\n (enabled) => {\n accentStackEntry.enabled = Boolean(enabled);\n applyGlobalAccentFromStack();\n },\n { immediate: true },\n);\n\nwatch(\n brandVars,\n (vars) => {\n if (vars && Object.keys(vars).length > 0) {\n accentStackEntry.vars = { ...vars };\n } else {\n accentStackEntry.vars = {};\n }\n applyGlobalAccentFromStack();\n },\n { immediate: true },\n);\n</script>\n\n<style lang=\"less\">\n@import \"index.less\";\n</style>\n","<script lang=\"ts\">\ninterface GlobalAccentEntry {\n vars: Record<string, string>;\n enabled: boolean;\n}\n\ninterface GlobalModeEntry {\n darkMode: boolean;\n}\n\nconst globalAccentStack: GlobalAccentEntry[] = [];\nconst appliedGlobalAccentKeys = new Set<string>();\nconst originalGlobalAccentValues = new Map<string, { priority: string; value: string }>();\nconst globalModeStack: GlobalModeEntry[] = [];\nlet originalGlobalDarkModeAttribute: string | null | undefined;\n</script>\n\n<template>\n <div class=\"theme\" :style=\"brandVars\">\n <slot />\n <div ref=\"portalHost\" class=\"theme__portal-host\"></div>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { provide, ref, watch, onBeforeUnmount, computed, inject } from \"vue\";\nimport type { PropType, Ref } from \"vue\";\nimport { readStoredMode, type ThemeMode } from \"./modeStorage\";\nimport \"what-input\";\nimport { themePortalHostKey } from \"./portalHost\";\n\ninterface RgbColor {\n r: number;\n g: number;\n b: number;\n}\n\ninterface OklchColor {\n l: number;\n c: number;\n h: number;\n}\n\ntype BrandRamp = Record<number, string>;\ntype BrandVars = Record<string, string>;\n\ninterface ReadableTextOptions {\n minContrast?: number;\n preferDark?: boolean;\n chromaScale?: number;\n initialLightness?: number;\n step?: number;\n}\n\ninterface ForegroundOptions extends ReadableTextOptions {\n darkCandidate?: string;\n lightCandidate?: string;\n preferredCandidate?: \"dark\" | \"light\";\n preferredMinContrast?: number;\n preferredSwitchDelta?: number;\n}\n\ndefineOptions({\n name: \"Theme\",\n});\ndefineSlots<{\n /** Application content that receives theme tokens and portal context. */\n default?: () => unknown;\n}>();\nconst props = defineProps({\n /**\n * Controls which color mode is active. auto follows the OS preference (and persisted storage\n * when used with ThemeSwitcher).\n */\n mode: {\n type: String as PropType<ThemeMode | undefined>,\n default: undefined,\n validator: (value: string) => [\"auto\", \"light\", \"dark\"].includes(value),\n },\n /**\n * Optional hex accent color (\"#RRGGBB\" or \"#RGB\"). When provided, Theme derives contrast-safe\n * semantic brand tokens and exposes them on the root .theme element (and the global document\n * for portals).\n */\n accentColor: {\n type: String,\n required: false,\n default: undefined,\n },\n /**\n * When true the brand vars are also exposed on <html>, allowing portals attached outside the\n * Theme subtree to inherit the accent colors.\n */\n exposeGlobalAccent: {\n type: Boolean,\n default: false,\n },\n});\n\nfunction applyGlobalAccentFromStack() {\n if (typeof document === \"undefined\") {\n return;\n }\n const root = document.documentElement;\n if (!root) {\n return;\n }\n\n appliedGlobalAccentKeys.forEach((key) => {\n const original = originalGlobalAccentValues.get(key);\n if (original?.value) {\n root.style.setProperty(key, original.value, original.priority);\n } else {\n root.style.removeProperty(key);\n }\n });\n appliedGlobalAccentKeys.clear();\n\n const activeEntry = [...globalAccentStack]\n .reverse()\n .find((entry) => entry.enabled && entry.vars && Object.keys(entry.vars).length > 0);\n\n if (!activeEntry) {\n originalGlobalAccentValues.clear();\n return;\n }\n\n Object.entries(activeEntry.vars).forEach(([key, value]) => {\n if (!originalGlobalAccentValues.has(key)) {\n originalGlobalAccentValues.set(key, {\n priority: root.style.getPropertyPriority(key),\n value: root.style.getPropertyValue(key),\n });\n }\n root.style.setProperty(key, value);\n appliedGlobalAccentKeys.add(key);\n });\n}\n\nconst DARK_MODE_QUERY = \"(prefers-color-scheme: dark)\";\nconst PREFERS_REDUCED_MOTION_QUERY = \"(prefers-reduced-motion: reduce)\";\nconst THEME_TRANSITION_DURATION = 200;\nconst darkModeMedia = getMediaQueryList(DARK_MODE_QUERY);\nconst prefersReducedMotionMedia = getMediaQueryList(PREFERS_REDUCED_MOTION_QUERY);\nconst parentTheme = inject<Ref<{ darkMode: boolean }> | null>(\"theme\", null);\n\nconst initialMode = getEffectiveMode();\nconst currentMode = ref(initialMode);\nlet transitionAnimationFrameID: number | null = null;\n\nconst theme = ref({\n darkMode: resolveDarkMode(initialMode),\n});\nconst modeStackEntry: GlobalModeEntry = {\n darkMode: theme.value.darkMode,\n};\nlet modeStackEntryRegistered = false;\nsyncGlobalModeOwnership();\nconst portalHost = ref<HTMLElement | null>(null);\n\ndarkModeMedia.addEventListener(\"change\", handleSystemPreferenceChange);\n\nwatch(\n () => props.mode,\n () => {\n syncDarkMode();\n },\n { immediate: true },\n);\nwatch(\n () => parentTheme?.value.darkMode,\n () => {\n if (props.mode === undefined) {\n syncDarkMode();\n }\n },\n);\n\nwatch(\n () => theme.value.darkMode,\n (darkMode, previousValue) => {\n modeStackEntry.darkMode = darkMode;\n if (!modeStackEntryRegistered || !isActiveGlobalModeEntry(modeStackEntry)) {\n return;\n }\n if (previousValue === undefined) {\n setDocumentDarkModeAttribute(darkMode);\n return;\n }\n withThemeTransition(() => {\n if (isActiveGlobalModeEntry(modeStackEntry)) {\n setDocumentDarkModeAttribute(darkMode);\n }\n });\n },\n { immediate: true },\n);\n\nonBeforeUnmount(() => {\n darkModeMedia.removeEventListener(\"change\", handleSystemPreferenceChange);\n if (transitionAnimationFrameID !== null && typeof window !== \"undefined\") {\n window.cancelAnimationFrame(transitionAnimationFrameID);\n transitionAnimationFrameID = null;\n }\n if (modeStackEntryRegistered) {\n unregisterGlobalModeEntry(modeStackEntry);\n }\n const index = globalAccentStack.indexOf(accentStackEntry);\n if (index !== -1) {\n globalAccentStack.splice(index, 1);\n }\n applyGlobalAccentFromStack();\n});\n\nfunction syncDarkMode() {\n const mode = getEffectiveMode();\n const darkMode = resolveDarkMode(mode);\n currentMode.value = mode;\n modeStackEntry.darkMode = darkMode;\n syncGlobalModeOwnership();\n theme.value.darkMode = darkMode;\n}\n\nfunction syncGlobalModeOwnership() {\n const shouldOwnGlobalMode = parentTheme === null || props.mode !== undefined;\n if (shouldOwnGlobalMode && !modeStackEntryRegistered) {\n modeStackEntryRegistered = registerGlobalModeEntry(modeStackEntry);\n } else if (!shouldOwnGlobalMode && modeStackEntryRegistered) {\n unregisterGlobalModeEntry(modeStackEntry);\n modeStackEntryRegistered = false;\n }\n}\n\nfunction resolveDarkMode(mode: ThemeMode) {\n if (mode === \"dark\") {\n return true;\n }\n if (mode === \"light\") {\n return false;\n }\n return darkModeMedia.matches;\n}\n\nfunction handleSystemPreferenceChange(event: MediaQueryListEvent) {\n if (!event || currentMode.value !== \"auto\") {\n return;\n }\n theme.value.darkMode = event.matches;\n}\n\nfunction setDocumentDarkModeAttribute(darkMode: boolean) {\n if (typeof document === \"undefined\") {\n return;\n }\n document.documentElement.setAttribute(\"dark-mode\", String(darkMode));\n}\n\nfunction registerGlobalModeEntry(entry: GlobalModeEntry) {\n if (typeof document === \"undefined\") {\n return false;\n }\n if (globalModeStack.length === 0) {\n originalGlobalDarkModeAttribute = document.documentElement.getAttribute(\"dark-mode\");\n }\n globalModeStack.push(entry);\n setDocumentDarkModeAttribute(entry.darkMode);\n return true;\n}\n\nfunction isActiveGlobalModeEntry(entry: GlobalModeEntry) {\n return globalModeStack.at(-1) === entry;\n}\n\nfunction unregisterGlobalModeEntry(entry: GlobalModeEntry) {\n const index = globalModeStack.indexOf(entry);\n if (index === -1) {\n return;\n }\n\n const wasActive = index === globalModeStack.length - 1;\n globalModeStack.splice(index, 1);\n if (!wasActive || typeof document === \"undefined\") {\n return;\n }\n\n const previousEntry = globalModeStack.at(-1);\n if (previousEntry) {\n setDocumentDarkModeAttribute(previousEntry.darkMode);\n return;\n }\n\n if (originalGlobalDarkModeAttribute === null) {\n document.documentElement.removeAttribute(\"dark-mode\");\n } else if (originalGlobalDarkModeAttribute !== undefined) {\n document.documentElement.setAttribute(\"dark-mode\", originalGlobalDarkModeAttribute);\n }\n originalGlobalDarkModeAttribute = undefined;\n}\n\nfunction withThemeTransition(applyTheme: () => void) {\n if (\n prefersReducedMotionMedia.matches ||\n typeof document === \"undefined\" ||\n typeof window === \"undefined\"\n ) {\n applyTheme();\n return;\n }\n const startViewTransition = document.startViewTransition?.bind(document);\n if (startViewTransition) {\n startViewTransition(() => {\n applyTheme();\n });\n return;\n }\n applyTheme();\n const element = document.documentElement;\n if (typeof element.animate !== \"function\") {\n return;\n }\n if (transitionAnimationFrameID !== null) {\n window.cancelAnimationFrame(transitionAnimationFrameID);\n }\n transitionAnimationFrameID = window.requestAnimationFrame(() => {\n transitionAnimationFrameID = null;\n element.animate([{ opacity: 0.85 }, { opacity: 1 }], {\n duration: THEME_TRANSITION_DURATION,\n easing: \"ease-in-out\",\n });\n });\n}\n\nfunction getEffectiveMode(): ThemeMode {\n if (props.mode === undefined && parentTheme) {\n return parentTheme.value.darkMode ? \"dark\" : \"light\";\n }\n return props.mode ?? readStoredMode() ?? \"auto\";\n}\n\nfunction getMediaQueryList(query: string): MediaQueryList {\n if (typeof window !== \"undefined\" && typeof window.matchMedia === \"function\") {\n try {\n return window.matchMedia(query);\n } catch {\n // Fall through to a non-matching server-safe implementation.\n }\n }\n\n return {\n addEventListener() {},\n addListener() {},\n dispatchEvent: () => false,\n matches: false,\n media: query,\n onchange: null,\n removeEventListener() {},\n removeListener() {},\n };\n}\n\nprovide(\"theme\", theme);\nprovide(themePortalHostKey, portalHost);\n\n// --- Accent helpers -------------------------------------------------------\nconst BRAND_MIN_CONTRAST = 4.5;\n\nfunction normalizeHex(hex: string | undefined) {\n if (!hex) return null;\n const h = hex.trim().toLowerCase();\n const m = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.exec(h);\n if (!m) return null;\n if (h.length === 4) {\n // expand #rgb -> #rrggbb\n const r = h[1],\n g = h[2],\n b = h[3];\n return `#${r}${r}${g}${g}${b}${b}`;\n }\n return h;\n}\n\nfunction hexToRgb(hex: string | undefined): RgbColor | null {\n const h = normalizeHex(hex);\n if (!h) return null;\n const r = parseInt(h.slice(1, 3), 16);\n const g = parseInt(h.slice(3, 5), 16);\n const b = parseInt(h.slice(5, 7), 16);\n return { r, g, b };\n}\n\nfunction rgbToHex({ r, g, b }: RgbColor) {\n const toHex = (value: number) => value.toString(16).padStart(2, \"0\");\n return `#${toHex(r)}${toHex(g)}${toHex(b)}`;\n}\n\nfunction clamp01(value: number) {\n return Math.max(0, Math.min(1, value));\n}\n\nfunction srgbChannelToLinear(channel: number) {\n if (channel <= 0.04045) {\n return channel / 12.92;\n }\n return Math.pow((channel + 0.055) / 1.055, 2.4);\n}\n\nfunction linearChannelToSrgb(channel: number) {\n const normalized = clamp01(channel);\n if (normalized <= 0.0031308) {\n return 12.92 * normalized;\n }\n return 1.055 * Math.pow(normalized, 1 / 2.4) - 0.055;\n}\n\nfunction rgbToOklch({ r, g, b }: RgbColor): OklchColor {\n const rNorm = r / 255;\n const gNorm = g / 255;\n const bNorm = b / 255;\n\n const rLin = srgbChannelToLinear(rNorm);\n const gLin = srgbChannelToLinear(gNorm);\n const bLin = srgbChannelToLinear(bNorm);\n\n const l = 0.4122214708 * rLin + 0.5363325363 * gLin + 0.0514459929 * bLin;\n const m = 0.2119034982 * rLin + 0.6806995451 * gLin + 0.1073969566 * bLin;\n const s = 0.0883024619 * rLin + 0.2817188376 * gLin + 0.6299787005 * bLin;\n\n const lRoot = Math.cbrt(l);\n const mRoot = Math.cbrt(m);\n const sRoot = Math.cbrt(s);\n\n const oklabL = 0.2104542553 * lRoot + 0.793617785 * mRoot - 0.0040720468 * sRoot;\n const oklabA = 1.9779984951 * lRoot - 2.428592205 * mRoot + 0.4505937099 * sRoot;\n const oklabB = 0.0259040371 * lRoot + 0.7827717662 * mRoot - 0.808675766 * sRoot;\n\n const chroma = Math.sqrt(oklabA * oklabA + oklabB * oklabB);\n let hue = Math.atan2(oklabB, oklabA) * (180 / Math.PI);\n if (hue < 0) {\n hue += 360;\n }\n\n return { l: oklabL, c: chroma, h: hue };\n}\n\nfunction tryOklchToSrgb(l: number, c: number, h: number, clampLinear = false): RgbColor | null {\n const angle = (h * Math.PI) / 180;\n const a = c * Math.cos(angle);\n const b = c * Math.sin(angle);\n\n const lComponent = l + 0.3963377774 * a + 0.2158037573 * b;\n const mComponent = l - 0.1055613458 * a - 0.0638541728 * b;\n const sComponent = l - 0.0894841775 * a - 1.291485548 * b;\n\n const lCube = clampLinear ? clamp01(lComponent) : lComponent;\n const mCube = clampLinear ? clamp01(mComponent) : mComponent;\n const sCube = clampLinear ? clamp01(sComponent) : sComponent;\n\n if (!clampLinear) {\n const outOfRange =\n lCube < -0.0001 ||\n lCube > 1.0001 ||\n mCube < -0.0001 ||\n mCube > 1.0001 ||\n sCube < -0.0001 ||\n sCube > 1.0001;\n if (outOfRange) {\n return null;\n }\n }\n\n const lLin = lCube * lCube * lCube;\n const mLin = mCube * mCube * mCube;\n const sLin = sCube * sCube * sCube;\n\n let rLin = 4.0767416621 * lLin - 3.3077115913 * mLin + 0.2309699292 * sLin;\n let gLin = -1.2684380046 * lLin + 2.6097574011 * mLin - 0.3413193965 * sLin;\n let bLin = -0.0041960863 * lLin - 0.7034186147 * mLin + 1.707614701 * sLin;\n\n if (clampLinear) {\n rLin = clamp01(rLin);\n gLin = clamp01(gLin);\n bLin = clamp01(bLin);\n } else {\n const outOfRange =\n rLin < -0.0001 ||\n rLin > 1.0001 ||\n gLin < -0.0001 ||\n gLin > 1.0001 ||\n bLin < -0.0001 ||\n bLin > 1.0001;\n if (outOfRange) {\n return null;\n }\n }\n\n const r = clamp01(linearChannelToSrgb(rLin));\n const g = clamp01(linearChannelToSrgb(gLin));\n const bValue = clamp01(linearChannelToSrgb(bLin));\n\n return {\n r: Math.round(r * 255),\n g: Math.round(g * 255),\n b: Math.round(bValue * 255),\n };\n}\n\nfunction oklchToSrgb(l: number, c: number, h: number): RgbColor {\n let chroma = c;\n for (let attempt = 0; attempt < 8; attempt += 1) {\n const rgb = tryOklchToSrgb(l, chroma, h);\n if (rgb) {\n return rgb;\n }\n chroma *= 0.9;\n }\n return tryOklchToSrgb(l, clamp01(chroma), h, true) || { r: 0, g: 0, b: 0 };\n}\n\nfunction relativeLuminance(hex: string) {\n const rgb = hexToRgb(hex);\n if (!rgb) {\n return 0;\n }\n const r = srgbChannelToLinear(rgb.r / 255);\n const g = srgbChannelToLinear(rgb.g / 255);\n const b = srgbChannelToLinear(rgb.b / 255);\n return 0.2126 * r + 0.7152 * g + 0.0722 * b;\n}\n\nfunction contrastRatio(hexA: string, hexB: string) {\n const lumA = relativeLuminance(hexA);\n const lumB = relativeLuminance(hexB);\n const lighter = Math.max(lumA, lumB);\n const darker = Math.min(lumA, lumB);\n return (lighter + 0.05) / (darker + 0.05);\n}\n\nfunction makeReadableTextOnSurface(\n baseOklch: OklchColor,\n surfaceHex: string,\n options: ReadableTextOptions = {},\n) {\n const minContrast = options.minContrast ?? BRAND_MIN_CONTRAST;\n const preferDark = options.preferDark !== false;\n const textChroma = Math.max(\n 0.01,\n Math.min(0.06, (baseOklch.c || 0.12) * (options.chromaScale ?? 0.25)),\n );\n const initialLightness = options.initialLightness ?? (preferDark ? 0.24 : 0.94);\n const direction = preferDark ? -1 : 1;\n const step = options.step ?? 0.03;\n let lightness = clamp01(initialLightness);\n let bestHex = rgbToHex(oklchToSrgb(lightness, textChroma, baseOklch.h));\n let bestContrast = contrastRatio(surfaceHex, bestHex);\n\n for (let attempt = 0; attempt < 48; attempt += 1) {\n const textHex = rgbToHex(oklchToSrgb(lightness, textChroma, baseOklch.h));\n const ratio = contrastRatio(surfaceHex, textHex);\n\n if (ratio > bestContrast) {\n bestContrast = ratio;\n bestHex = textHex;\n }\n if (ratio >= minContrast) {\n return textHex;\n }\n\n lightness = clamp01(lightness + direction * step);\n if (lightness === 0 || lightness === 1) {\n break;\n }\n }\n\n const fallbackDark = \"#000000\";\n const fallbackLight = \"#ffffff\";\n const darkRatio = contrastRatio(surfaceHex, fallbackDark);\n const lightRatio = contrastRatio(surfaceHex, fallbackLight);\n\n if (darkRatio >= minContrast || lightRatio >= minContrast) {\n return darkRatio >= lightRatio ? fallbackDark : fallbackLight;\n }\n\n return bestHex;\n}\n\nfunction pickForegroundColor(\n baseOklch: OklchColor,\n surfaceHex: string,\n options: ForegroundOptions = {},\n) {\n const minContrast = options.minContrast ?? BRAND_MIN_CONTRAST;\n const darkCandidate = options.darkCandidate ?? \"#101214\";\n const lightCandidate = options.lightCandidate ?? \"#ffffff\";\n const preferredCandidate = options.preferredCandidate;\n const preferredMinContrast = options.preferredMinContrast ?? minContrast;\n const preferredSwitchDelta = options.preferredSwitchDelta ?? 0;\n const darkRatio = contrastRatio(surfaceHex, darkCandidate);\n const lightRatio = contrastRatio(surfaceHex, lightCandidate);\n const darkPasses = darkRatio >= minContrast;\n const lightPasses = lightRatio >= minContrast;\n const preferredLightPasses = lightRatio >= preferredMinContrast;\n const preferredDarkPasses = darkRatio >= preferredMinContrast;\n\n if (darkPasses || lightPasses) {\n if (preferredCandidate === \"light\" && preferredLightPasses) {\n return lightCandidate;\n }\n if (preferredCandidate === \"dark\" && preferredDarkPasses) {\n return darkCandidate;\n }\n\n if (preferredCandidate === \"light\" && lightPasses) {\n if (!darkPasses || darkRatio - lightRatio <= preferredSwitchDelta) {\n return lightCandidate;\n }\n return darkCandidate;\n }\n if (preferredCandidate === \"dark\" && darkPasses) {\n if (!lightPasses || lightRatio - darkRatio <= preferredSwitchDelta) {\n return darkCandidate;\n }\n return lightCandidate;\n }\n\n if (darkPasses && lightPasses) {\n return darkRatio >= lightRatio ? darkCandidate : lightCandidate;\n }\n return darkPasses ? darkCandidate : lightCandidate;\n }\n\n const preferDark = darkRatio >= lightRatio;\n return makeReadableTextOnSurface(baseOklch, surfaceHex, {\n minContrast,\n preferDark,\n initialLightness: preferDark ? 0.2 : 0.96,\n chromaScale: 0.1,\n });\n}\n\nconst BRAND_STOPS = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000];\nconst BRAND_LIGHTNESS_CURVE = [0.9, 0.84, 0.78, 0.72, 0.67, 0.62, 0.56, 0.5, 0.44, 0.38];\nconst BRAND_CHROMA_MULTIPLIERS = [0.28, 0.4, 0.54, 0.7, 0.86, 1, 1.08, 1.14, 1.2, 1.24];\nconst BRAND_MIN_SURFACE_CONTRAST = 1.8;\nconst BRAND_MIN_SUBTLE_SURFACE_CONTRAST = 1.15;\nconst BRAND_MIN_SOFT_SURFACE_CONTRAST = 1.08;\nconst BRAND_UI_TEXT_MIN_CONTRAST = 4.5;\nconst BRAND_LIGHT_TEXT_SWITCH_DELTA = 3;\nconst LIGHT_CANVAS_HEX = \"#ffffff\";\nconst DARK_CANVAS_HEX = \"#1f2228\";\n\nfunction pickRampStopForContrast(\n ramp: BrandRamp,\n stopCandidates: number[],\n referenceHex: string,\n minContrast: number,\n) {\n const fallbackStop = stopCandidates[stopCandidates.length - 1];\n for (const stop of stopCandidates) {\n const candidate = ramp[stop];\n if (!candidate) {\n continue;\n }\n if (contrastRatio(candidate, referenceHex) >= minContrast) {\n return stop;\n }\n }\n return fallbackStop;\n}\n\nfunction pickReadableRampText(\n baseOklch: OklchColor,\n ramp: BrandRamp,\n stopCandidates: number[],\n surfaceHex: string,\n preferDark: boolean,\n) {\n for (const stop of stopCandidates) {\n const candidate = ramp[stop];\n if (candidate && contrastRatio(candidate, surfaceHex) >= BRAND_UI_TEXT_MIN_CONTRAST) {\n return candidate;\n }\n }\n\n return makeReadableTextOnSurface(baseOklch, surfaceHex, {\n chromaScale: 1,\n initialLightness: preferDark ? 0.45 : 0.72,\n minContrast: BRAND_UI_TEXT_MIN_CONTRAST,\n preferDark,\n });\n}\n\nfunction makeBrandRampFromSeed(baseOklch: OklchColor): BrandRamp {\n const lightnessOffset = baseOklch.l - BRAND_LIGHTNESS_CURVE[5];\n const minSeedChroma = baseOklch.c > 0.02 ? 0.02 : 0;\n\n return BRAND_STOPS.reduce<BrandRamp>((acc, stop, index) => {\n const lightness = clamp01(BRAND_LIGHTNESS_CURVE[index] + lightnessOffset);\n const chroma = Math.min(\n 0.4,\n Math.max(minSeedChroma, baseOklch.c * BRAND_CHROMA_MULTIPLIERS[index]),\n );\n acc[stop] = rgbToHex(oklchToSrgb(lightness, chroma, baseOklch.h));\n return acc;\n }, {});\n}\n\nfunction makeSemanticBrandTokens(baseOklch: OklchColor, ramp: BrandRamp): BrandVars {\n const lightSoftStops = [100, 200, 300, 400, 500, 600, 700];\n const lightSoftStop = pickRampStopForContrast(\n ramp,\n lightSoftStops,\n LIGHT_CANVAS_HEX,\n BRAND_MIN_SOFT_SURFACE_CONTRAST,\n );\n const lightSoftIndex = lightSoftStops.indexOf(lightSoftStop);\n const lightSoftHoveredStop =\n lightSoftStops[Math.min(lightSoftIndex + 1, lightSoftStops.length - 1)];\n const lightSoftPressedStop =\n lightSoftStops[Math.min(lightSoftIndex + 2, lightSoftStops.length - 1)];\n\n const darkSoftStops = [1000, 900, 800, 700, 600, 500];\n const darkSoftStop = pickRampStopForContrast(\n ramp,\n darkSoftStops,\n DARK_CANVAS_HEX,\n BRAND_MIN_SOFT_SURFACE_CONTRAST,\n );\n const darkSoftIndex = darkSoftStops.indexOf(darkSoftStop);\n const darkSoftHoveredStop =\n darkSoftStops[Math.min(darkSoftIndex + 1, darkSoftStops.length - 1)];\n const darkSoftPressedStop =\n darkSoftStops[Math.min(darkSoftIndex + 2, darkSoftStops.length - 1)];\n\n const lightSubtleStops = [200, 300, 400, 500, 600, 700, 800];\n const lightSubtleStop = pickRampStopForContrast(\n ramp,\n lightSubtleStops,\n LIGHT_CANVAS_HEX,\n BRAND_MIN_SUBTLE_SURFACE_CONTRAST,\n );\n const darkSubtleStops = [900, 800, 700, 600, 500, 400];\n const darkSubtleStop = pickRampStopForContrast(\n ramp,\n darkSubtleStops,\n DARK_CANVAS_HEX,\n BRAND_MIN_SUBTLE_SURFACE_CONTRAST,\n );\n\n const lightStrongStops = [600, 700, 800, 900, 1000];\n const lightStrongStop = pickRampStopForContrast(\n ramp,\n lightStrongStops,\n LIGHT_CANVAS_HEX,\n BRAND_MIN_SURFACE_CONTRAST,\n );\n const lightStrongIndex = lightStrongStops.indexOf(lightStrongStop);\n const lightStrongHoveredStop =\n lightStrongStops[Math.min(lightStrongIndex + 1, lightStrongStops.length - 1)];\n const lightStrongPressedStop =\n lightStrongStops[Math.min(lightStrongIndex + 2, lightStrongStops.length - 1)];\n\n const darkStrongStops = [400, 300, 200, 100];\n const darkStrongStop = pickRampStopForContrast(\n ramp,\n darkStrongStops,\n DARK_CANVAS_HEX,\n BRAND_MIN_SURFACE_CONTRAST,\n );\n const darkStrongIndex = darkStrongStops.indexOf(darkStrongStop);\n const darkStrongHoveredStop =\n darkStrongStops[Math.min(darkStrongIndex + 1, darkStrongStops.length - 1)];\n const darkStrongPressedStop =\n darkStrongStops[Math.min(darkStrongIndex + 2, darkStrongStops.length - 1)];\n\n const tokens: BrandVars = {\n \"--color-brand-surface-soft-light\": ramp[lightSoftStop],\n \"--color-brand-surface-soft-hovered-light\": ramp[lightSoftHoveredStop],\n \"--color-brand-surface-soft-pressed-light\": ramp[lightSoftPressedStop],\n \"--color-brand-surface-soft-dark\": ramp[darkSoftStop],\n \"--color-brand-surface-soft-hovered-dark\": ramp[darkSoftHoveredStop],\n \"--color-brand-surface-soft-pressed-dark\": ramp[darkSoftPressedStop],\n \"--color-brand-surface-subtle-light\": ramp[lightSubtleStop],\n \"--color-brand-surface-subtle-dark\": ramp[darkSubtleStop],\n \"--color-brand-surface-strong-light\": ramp[lightStrongStop],\n \"--color-brand-surface-strong-hovered-light\": ramp[lightStrongHoveredStop],\n \"--color-brand-surface-strong-pressed-light\": ramp[lightStrongPressedStop],\n \"--color-brand-surface-strong-dark\": ramp[darkStrongStop],\n \"--color-brand-surface-strong-hovered-dark\": ramp[darkStrongHoveredStop],\n \"--color-brand-surface-strong-pressed-dark\": ramp[darkStrongPressedStop],\n };\n\n const preferredSoftLightForeground = ramp[600];\n const softLightContrast = contrastRatio(\n tokens[\"--color-brand-surface-soft-light\"],\n preferredSoftLightForeground,\n );\n tokens[\"--color-brand-on-soft-light\"] =\n softLightContrast >= BRAND_MIN_CONTRAST\n ? preferredSoftLightForeground\n : pickForegroundColor(baseOklch, tokens[\"--color-brand-surface-soft-light\"], {\n minContrast: BRAND_MIN_CONTRAST,\n });\n tokens[\"--color-brand-on-soft-dark\"] = pickForegroundColor(\n baseOklch,\n tokens[\"--color-brand-surface-soft-dark\"],\n {\n minContrast: BRAND_MIN_CONTRAST,\n },\n );\n tokens[\"--color-brand-on-subtle-light\"] = pickForegroundColor(\n baseOklch,\n tokens[\"--color-brand-surface-subtle-light\"],\n {\n minContrast: BRAND_UI_TEXT_MIN_CONTRAST,\n preferredCandidate: \"light\",\n preferredMinContrast: BRAND_UI_TEXT_MIN_CONTRAST,\n preferredSwitchDelta: BRAND_LIGHT_TEXT_SWITCH_DELTA,\n },\n );\n tokens[\"--color-brand-on-subtle-dark\"] = pickForegroundColor(\n baseOklch,\n tokens[\"--color-brand-surface-subtle-dark\"],\n {\n minContrast: BRAND_MIN_CONTRAST,\n },\n );\n tokens[\"--color-brand-on-strong-light\"] = pickForegroundColor(\n baseOklch,\n tokens[\"--color-brand-surface-strong-light\"],\n {\n minContrast: BRAND_UI_TEXT_MIN_CONTRAST,\n preferredCandidate: \"light\",\n preferredMinContrast: BRAND_UI_TEXT_MIN_CONTRAST,\n preferredSwitchDelta: BRAND_LIGHT_TEXT_SWITCH_DELTA,\n },\n );\n tokens[\"--color-brand-on-strong-dark\"] = pickForegroundColor(\n baseOklch,\n tokens[\"--color-brand-surface-strong-dark\"],\n {\n minContrast: BRAND_MIN_CONTRAST,\n },\n );\n\n tokens[\"--color-brand-text-light\"] = pickReadableRampText(\n baseOklch,\n ramp,\n [600, 700, 800, 900, 1000],\n LIGHT_CANVAS_HEX,\n true,\n );\n tokens[\"--color-brand-text-dark\"] = pickReadableRampText(\n baseOklch,\n ramp,\n [400, 300, 200, 100],\n DARK_CANVAS_HEX,\n false,\n );\n tokens[\"--color-brand-icon-light\"] = tokens[\"--color-brand-text-light\"];\n tokens[\"--color-brand-icon-dark\"] = tokens[\"--color-brand-text-dark\"];\n tokens[\"--color-brand-border-light\"] = tokens[\"--color-brand-text-light\"];\n tokens[\"--color-brand-border-dark\"] = tokens[\"--color-brand-text-dark\"];\n\n return tokens;\n}\n\nfunction makeBrandTokens(baseHex: string | undefined): BrandVars | null {\n const norm = normalizeHex(baseHex);\n if (!norm) {\n return null;\n }\n\n const baseRgb = hexToRgb(norm);\n if (!baseRgb) {\n return null;\n }\n\n const baseOklch = rgbToOklch(baseRgb);\n const ramp = makeBrandRampFromSeed(baseOklch);\n // Keep the incoming seed exact for debugging and transparency.\n ramp[600] = norm;\n\n return {\n \"--color-brand-seed\": norm,\n \"--color-brand-100\": ramp[100],\n \"--color-brand-200\": ramp[200],\n \"--color-brand-300\": ramp[300],\n \"--color-brand-400\": ramp[400],\n \"--color-brand-500\": ramp[500],\n \"--color-brand-600\": ramp[600],\n \"--color-brand-700\": ramp[700],\n \"--color-brand-800\": ramp[800],\n \"--color-brand-900\": ramp[900],\n \"--color-brand-1000\": ramp[1000],\n ...makeSemanticBrandTokens(baseOklch, ramp),\n };\n}\n\nconst brandVars = computed(() => makeBrandTokens(props.accentColor) ?? {});\n\nconst accentStackEntry = {\n vars: {},\n enabled: Boolean(props.exposeGlobalAccent),\n};\nif (typeof document !== \"undefined\") {\n globalAccentStack.push(accentStackEntry);\n}\n\nwatch(\n () => props.exposeGlobalAccent,\n (enabled) => {\n accentStackEntry.enabled = Boolean(enabled);\n applyGlobalAccentFromStack();\n },\n { immediate: true },\n);\n\nwatch(\n brandVars,\n (vars) => {\n if (vars && Object.keys(vars).length > 0) {\n accentStackEntry.vars = { ...vars };\n } else {\n accentStackEntry.vars = {};\n }\n applyGlobalAccentFromStack();\n },\n { immediate: true },\n);\n</script>\n\n<style lang=\"less\">\n@import \"index.less\";\n</style>\n","<template>\n <DropdownMenu v-model:open=\"open\" text=\"Theme\" aria-label=\"Select theme mode\">\n <DropdownItemGroup title=\"Theme\" item-role=\"menuitemradio\">\n <DropdownItemRadio\n v-model:checked=\"internalMode\"\n value=\"auto\"\n :label=\"MODE_LABELS.auto\"\n :aria-label=\"`${MODE_LABELS.auto} mode`\"\n />\n <hr class=\"theme-switcher-divider\" />\n <DropdownItemRadio\n v-model:checked=\"internalMode\"\n value=\"light\"\n :label=\"MODE_LABELS.light\"\n :aria-label=\"`${MODE_LABELS.light} mode`\"\n />\n <DropdownItemRadio\n v-model:checked=\"internalMode\"\n value=\"dark\"\n :label=\"MODE_LABELS.dark\"\n :aria-label=\"`${MODE_LABELS.dark} mode`\"\n />\n </DropdownItemGroup>\n </DropdownMenu>\n</template>\n\n<script setup lang=\"ts\">\nimport { inject, ref, watch } from \"vue\";\nimport type { PropType } from \"vue\";\nimport { DropdownMenu, DropdownItemGroup, DropdownItemRadio } from \"@gospore/dropdown-menu\";\nimport {\n readStoredMode,\n writeStoredMode,\n VALID_THEME_MODES,\n applyStoredModeToDocument,\n type ThemeMode,\n} from \"./modeStorage\";\n\nconst MODE_OPTIONS: { value: ThemeMode; label: string }[] = [\n { value: \"auto\", label: \"System\" },\n { value: \"light\", label: \"Light\" },\n { value: \"dark\", label: \"Dark\" },\n];\nconst MODE_LABELS = MODE_OPTIONS.reduce<Record<ThemeMode, string>>(\n (map, option) => {\n map[option.value] = option.label;\n return map;\n },\n {} as Record<ThemeMode, string>,\n);\nconst VALID_MODES = VALID_THEME_MODES;\n\nconst props = defineProps({\n /** Selected theme mode. Supports v-model:mode and persists changes to local storage. */\n mode: {\n type: String as PropType<ThemeMode>,\n default: \"auto\",\n validator: (value: string) => [\"auto\", \"light\", \"dark\"].includes(value),\n },\n});\nconst emit = defineEmits([\"update:mode\"]);\n\nconst hasThemeProvider = inject(\"theme\", null) !== null;\nif (!hasThemeProvider) {\n applyStoredModeToDocument();\n}\n\nconst open = ref(false);\nconst initialMode = readStoredMode() ?? props.mode;\nconst internalMode = ref<ThemeMode>(VALID_MODES.includes(initialMode) ? initialMode : \"auto\");\nwatch(\n () => props.mode,\n (mode) => {\n if (VALID_MODES.includes(mode) && mode !== internalMode.value) {\n internalMode.value = mode;\n }\n },\n);\n\nwatch(\n internalMode,\n (mode) => {\n if (!VALID_MODES.includes(mode)) {\n internalMode.value = \"auto\";\n return;\n }\n open.value = false;\n emit(\"update:mode\", mode);\n writeStoredMode(mode);\n if (!hasThemeProvider) {\n applyStoredModeToDocument(mode);\n }\n },\n { immediate: true },\n);\n</script>\n\n<style scoped lang=\"less\">\n.theme-switcher-divider {\n margin: 4px 0;\n}\n</style>\n","<template>\n <DropdownMenu v-model:open=\"open\" text=\"Theme\" aria-label=\"Select theme mode\">\n <DropdownItemGroup title=\"Theme\" item-role=\"menuitemradio\">\n <DropdownItemRadio\n v-model:checked=\"internalMode\"\n value=\"auto\"\n :label=\"MODE_LABELS.auto\"\n :aria-label=\"`${MODE_LABELS.auto} mode`\"\n />\n <hr class=\"theme-switcher-divider\" />\n <DropdownItemRadio\n v-model:checked=\"internalMode\"\n value=\"light\"\n :label=\"MODE_LABELS.light\"\n :aria-label=\"`${MODE_LABELS.light} mode`\"\n />\n <DropdownItemRadio\n v-model:checked=\"internalMode\"\n value=\"dark\"\n :label=\"MODE_LABELS.dark\"\n :aria-label=\"`${MODE_LABELS.dark} mode`\"\n />\n </DropdownItemGroup>\n </DropdownMenu>\n</template>\n\n<script setup lang=\"ts\">\nimport { inject, ref, watch } from \"vue\";\nimport type { PropType } from \"vue\";\nimport { DropdownMenu, DropdownItemGroup, DropdownItemRadio } from \"@gospore/dropdown-menu\";\nimport {\n readStoredMode,\n writeStoredMode,\n VALID_THEME_MODES,\n applyStoredModeToDocument,\n type ThemeMode,\n} from \"./modeStorage\";\n\nconst MODE_OPTIONS: { value: ThemeMode; label: string }[] = [\n { value: \"auto\", label: \"System\" },\n { value: \"light\", label: \"Light\" },\n { value: \"dark\", label: \"Dark\" },\n];\nconst MODE_LABELS = MODE_OPTIONS.reduce<Record<ThemeMode, string>>(\n (map, option) => {\n map[option.value] = option.label;\n return map;\n },\n {} as Record<ThemeMode, string>,\n);\nconst VALID_MODES = VALID_THEME_MODES;\n\nconst props = defineProps({\n /** Selected theme mode. Supports v-model:mode and persists changes to local storage. */\n mode: {\n type: String as PropType<ThemeMode>,\n default: \"auto\",\n validator: (value: string) => [\"auto\", \"light\", \"dark\"].includes(value),\n },\n});\nconst emit = defineEmits<{\n \"update:mode\": [value: ThemeMode];\n}>();\n\nconst hasThemeProvider = inject(\"theme\", null) !== null;\nif (!hasThemeProvider) {\n applyStoredModeToDocument();\n}\n\nconst open = ref(false);\nconst initialMode = readStoredMode() ?? props.mode;\nconst internalMode = ref<ThemeMode>(VALID_MODES.includes(initialMode) ? initialMode : \"auto\");\nwatch(\n () => props.mode,\n (mode) => {\n if (VALID_MODES.includes(mode) && mode !== internalMode.value) {\n internalMode.value = mode;\n }\n },\n);\n\nwatch(\n internalMode,\n (mode) => {\n if (!VALID_MODES.includes(mode)) {\n internalMode.value = \"auto\";\n return;\n }\n open.value = false;\n emit(\"update:mode\", mode);\n writeStoredMode(mode);\n if (!hasThemeProvider) {\n applyStoredModeToDocument(mode);\n }\n },\n { immediate: true },\n);\n</script>\n\n<style scoped lang=\"less\">\n.theme-switcher-divider {\n margin: 4px 0;\n}\n</style>\n","import { STORAGE_KEY, VALID_THEME_MODES } from \"./modeStorage\";\n\nconst DARK_MODE_QUERY = \"(prefers-color-scheme: dark)\";\nconst LIGHT_BACKGROUND_FALLBACK = \"#ffffff\";\nconst LIGHT_BACKGROUND = \"oklch(100% 0 250)\";\nconst DARK_BACKGROUND_FALLBACK = \"#1f2228\";\nconst DARK_BACKGROUND = \"oklch(15% 0.0045 250)\";\n\ninterface ThemeBootstrapHtmlTag {\n tag: \"script\" | \"style\";\n children: string;\n injectTo: \"head\";\n}\n\nexport interface ThemeBootstrapPlugin {\n name: string;\n enforce: \"pre\";\n transformIndexHtml: {\n order: \"pre\";\n handler: () => ThemeBootstrapHtmlTag[];\n };\n}\n\n/**\n * Injects the persisted theme mode and matching canvas color before the first frame paints. The\n * returned object is structurally compatible with a Vite HTML transform plugin without making Vite\n * a runtime dependency of @gospore/theme.\n */\nexport function createThemeBootstrapPlugin(): ThemeBootstrapPlugin {\n return {\n name: \"gospore-theme-bootstrap\",\n enforce: \"pre\",\n transformIndexHtml: {\n order: \"pre\",\n handler: () => [\n {\n tag: \"style\",\n children: createCriticalThemeStyle(),\n injectTo: \"head\",\n },\n {\n tag: \"script\",\n children: createThemeBootstrapScript(),\n injectTo: \"head\",\n },\n ],\n },\n };\n}\n\nfunction createThemeBootstrapScript() {\n return `(() => {\n const storageKey = ${JSON.stringify(STORAGE_KEY)};\n const validModes = ${JSON.stringify(VALID_THEME_MODES)};\n const encodedKey = encodeURIComponent(storageKey) + \"=\";\n const storedCookie = document.cookie\n .split(\"; \")\n .find((entry) => entry.startsWith(encodedKey));\n let mode = \"auto\";\n\n if (storedCookie) {\n try {\n const storedMode = decodeURIComponent(storedCookie.slice(encodedKey.length));\n if (validModes.includes(storedMode)) mode = storedMode;\n } catch {}\n }\n\n let systemDark = false;\n if (mode === \"auto\") {\n try {\n systemDark =\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(${JSON.stringify(DARK_MODE_QUERY)}).matches;\n } catch {}\n }\n\n document.documentElement.setAttribute(\n \"dark-mode\",\n String(mode === \"dark\" || (mode === \"auto\" && systemDark)),\n );\n})();`;\n}\n\nfunction createCriticalThemeStyle() {\n return `html {\n background-color: ${LIGHT_BACKGROUND_FALLBACK};\n background-color: ${LIGHT_BACKGROUND};\n color-scheme: light;\n}\n\nhtml[dark-mode=\"true\"] {\n background-color: ${DARK_BACKGROUND_FALLBACK};\n background-color: ${DARK_BACKGROUND};\n color-scheme: dark;\n}\n\nbody {\n background-color: inherit;\n}`;\n}\n"],"mappings":"uaAAA,IAAM,EAAoB,CAAC,OAAQ,QAAS,MAAM,EAE5C,EAAc,qBACd,EAAsB,KAAU,GAAK,IACrC,EAAkB,+BAExB,SAAgB,GAAmC,CAC/C,GAAI,OAAO,SAAa,IACpB,OAAO,KAEX,IAAM,EAAS,EAAU,CAAW,EACpC,OAAO,EAAY,CAAM,EAAI,EAAS,IAC1C,CAEA,SAAgB,EAAgB,EAAiB,CAC7C,GAAI,OAAO,SAAa,KAAe,CAAC,EAAkB,SAAS,CAAI,EACnE,OAEJ,IAAM,EAAW,OAAO,OAAW,IAAc,OAAO,SAAS,SAAW,GAEtE,GADW,OAAO,OAAW,IAAc,OAAO,SAAS,SAAW,MAChD,SACtB,EAAa,CAAC,SAAU,WAAW,IAAuB,cAAc,EAC1E,GACA,EAAW,KAAK,QAAQ,EAG5B,IAAM,EAAe,EAAsB,CAAQ,EAC/C,IACA,SAAS,OAAS,CACd,GAAG,mBAAmB,CAAW,EAAE,GACnC,SACA,YACA,eACA,UAAU,I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,MAAA,CAAK,CAAA,CAAW,CAAC,MAAK,+EAOnC,EAAA,iBAAA,EAAA,CAJU,QAAS,EAAA,qCAAY,MAAA,EAC7B,MAAM,OACL,OAAA,EAAA,EAAA,MAAA,CAAO,CAAA,CAAW,CAAC,KACnB,aAAU,IAAA,EAAA,EAAA,MAAA,CAAK,CAAA,CAAW,CAAC,KAAI,mHElB1C,EAAkB,+BAClB,EAA4B,UAC5B,EAAmB,oBACnB,EAA2B,UAC3B,EAAkB,wBAsBxB,SAAgB,GAAmD,CAC/D,MAAO,CACH,KAAM,0BACN,QAAS,MACT,mBAAoB,CAChB,MAAO,MACP,YAAe,CACX,CACI,IAAK,QACL,SAAU,EAAyB,EACnC,SAAU,MACd,EACA,CACI,IAAK,SACL,SAAU,EAA2B,EACrC,SAAU,MACd,CACJ,CACJ,CACJ,CACJ,CAEA,SAAS,GAA6B,CAClC,MAAO;yBACc,KAAK,UAAU,CAAW,EAAE;yBAC5B,KAAK,UAAU,CAAiB,EAAE;;;;;;;;;;;;;;;;;;;oCAmBvB,KAAK,UAAU,CAAe,EAAE;;;;;;;;MASpE,CAEA,SAAS,GAA2B,CAChC,MAAO;wBACa,EAA0B;wBAC1B,EAAiB;;;;;wBAKjB,EAAyB;wBACzB,EAAgB;;;;;;EAOxC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface ThemeBootstrapHtmlTag {
|
|
2
|
+
tag: "script" | "style";
|
|
3
|
+
children: string;
|
|
4
|
+
injectTo: "head";
|
|
5
|
+
}
|
|
6
|
+
export interface ThemeBootstrapPlugin {
|
|
7
|
+
name: string;
|
|
8
|
+
enforce: "pre";
|
|
9
|
+
transformIndexHtml: {
|
|
10
|
+
order: "pre";
|
|
11
|
+
handler: () => ThemeBootstrapHtmlTag[];
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Injects the persisted theme mode and matching canvas color before the first frame paints. The
|
|
16
|
+
* returned object is structurally compatible with a Vite HTML transform plugin without making Vite
|
|
17
|
+
* a runtime dependency of @gospore/theme.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createThemeBootstrapPlugin(): ThemeBootstrapPlugin;
|
|
20
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gospore/theme",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "1.0.165",
|
|
4
|
+
"gitHead": "1eaeb04c9f84e4fe6bff9ec2c54a8f9b8e46374b",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "Gospore",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
10
10
|
"type": "module",
|
|
11
|
-
"main": "./dist/theme.cjs
|
|
11
|
+
"main": "./dist/theme.cjs",
|
|
12
12
|
"module": "./dist/theme.es.js",
|
|
13
13
|
"types": "./dist/index.d.ts",
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
16
16
|
"import": "./dist/theme.es.js",
|
|
17
|
-
"require": "./dist/theme.cjs
|
|
17
|
+
"require": "./dist/theme.cjs",
|
|
18
18
|
"types": "./dist/index.d.ts"
|
|
19
19
|
},
|
|
20
20
|
"./theme.css": "./dist/theme.css",
|
|
21
21
|
"./umd": {
|
|
22
|
-
"import": "./dist/theme.umd.js"
|
|
23
|
-
"require": "./dist/theme.umd.js"
|
|
22
|
+
"import": "./dist/theme.umd.js"
|
|
24
23
|
}
|
|
25
24
|
},
|
|
26
25
|
"scripts": {
|
|
27
26
|
"build": "vite build"
|
|
28
27
|
},
|
|
29
28
|
"dependencies": {
|
|
30
|
-
"@gospore/dropdown-menu": "^1.0.
|
|
29
|
+
"@gospore/dropdown-menu": "^1.0.132",
|
|
31
30
|
"what-input": "^5.2.12"
|
|
32
31
|
},
|
|
33
32
|
"devDependencies": {
|
|
34
33
|
"@vitejs/plugin-vue": "^6.0.7",
|
|
35
34
|
"unplugin-vue-macros": "^2.14.5",
|
|
36
|
-
"vite": "^8.1.4"
|
|
35
|
+
"vite": "^8.1.4",
|
|
36
|
+
"vue": "^3.5.39"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"vue": "^3.
|
|
39
|
+
"vue": "^3.5.0"
|
|
40
40
|
}
|
|
41
41
|
}
|
package/dist/theme.cjs.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("vue");require("what-input");let t=require("@gospore/dropdown-menu");var n=[`auto`,`light`,`dark`],r=`gospore-theme-mode`,i=3600*24*365,a=`(prefers-color-scheme: dark)`;function o(){if(typeof document>`u`)return null;let e=l(r);return f(e)?e:null}function s(e){if(typeof document>`u`||!n.includes(e))return;let t=typeof window<`u`?window.location.hostname:``,a=typeof window<`u`?window.location.protocol:``,o=u(t),s=a===`https:`,c=[`path=/`,`max-age=${i}`,`SameSite=Lax`];o&&c.push(`domain=${o}`),s&&c.push(`Secure`),document.cookie=[`${encodeURIComponent(r)}=${encodeURIComponent(e)}`,...c].join(`; `)}function c(e){if(typeof document>`u`)return;let t=f(e)?e:o()??`auto`;console.log(`Applying theme mode:`,t);let n=d(t);document.documentElement.setAttribute(`dark-mode`,String(n))}function l(e){if(typeof document>`u`||!document.cookie)return null;let t=`${encodeURIComponent(e)}=`,n=document.cookie.split(`; `);for(let e of n)if(e.startsWith(t))return decodeURIComponent(e.slice(t.length));return null}function u(e){if(!e||e===`localhost`)return null;if(/^\d+(?:\.\d+){3}$/.test(e))return e;let t=e.split(`.`);return t.length<=1?null:t.length===2?e:t.slice(-2).join(`.`)}function d(e){if(e===`dark`)return!0;if(e===`light`||typeof window>`u`)return!1;try{let e=typeof window.matchMedia==`function`?window.matchMedia(a):null;return e?e.matches:!1}catch{return!1}}function f(e){return typeof e==`string`&&n.includes(e)}var p=Symbol.for(`gospore.theme.portalHost`);function m(){let t=(0,e.inject)(p,null);console.log(`Using theme portal host:`,t);let n=typeof document<`u`?document.body:`body`;return(0,e.computed)(()=>t?.value??n)}var h=[],g=new Set,_=`(prefers-color-scheme: dark)`,v=`(prefers-reduced-motion: reduce)`,y=200,b=4.5,x=1.8,S=1.15,C=1.08,w=4.5,T=3,E=`#ffffff`,D=`#1f2228`,O=(0,e.defineComponent)({name:`Theme`,__name:`Theme`,props:{mode:{type:String,default:void 0,validator:e=>[`auto`,`light`,`dark`].includes(e)},accentColor:{type:String,required:!1,default:void 0},exposeGlobalAccent:{type:Boolean,default:!1}},setup(t){let n=t;function r(){let e=document.documentElement;if(!e)return;g.forEach(t=>{e.style.removeProperty(t)}),g.clear();let t=[...h].reverse().find(e=>e.enabled&&e.vars&&Object.keys(e.vars).length>0);t&&Object.entries(t.vars).forEach(([t,n])=>{e.style.setProperty(t,n),g.add(t)})}let i=window.matchMedia(_),a=window.matchMedia(v),s=j();c(s);let l=(0,e.ref)(s),u=(0,e.ref)({darkMode:m(s)}),d=(0,e.ref)(null);i.addEventListener(`change`,O),(0,e.watch)(()=>n.mode,()=>{f()},{immediate:!0}),(0,e.watch)(()=>u.value.darkMode,(e,t)=>{if(t===void 0){k(e);return}A(()=>{k(e)})},{immediate:!0}),(0,e.onBeforeUnmount)(()=>{i.removeEventListener(`change`,O);let e=h.indexOf($);e!==-1&&h.splice(e,1),r()});function f(){let e=j();l.value=e,u.value.darkMode=m(e)}function m(e){return e===`dark`||e!==`light`&&i.matches}function O(e){!e||l.value!==`auto`||(u.value.darkMode=e.matches)}function k(e){document.documentElement.setAttribute(`dark-mode`,String(e))}function A(e){if(a.matches){e();return}let t=document.startViewTransition?.bind(document);if(t){t(()=>{e()});return}e();let n=document.documentElement;typeof n.animate==`function`&&window.requestAnimationFrame(()=>{n.animate([{opacity:.85},{opacity:1}],{duration:y,easing:`ease-in-out`})})}function j(){return n.mode??o()??`auto`}(0,e.provide)(`theme`,u),(0,e.provide)(p,d);function M(e){if(!e)return null;let t=e.trim().toLowerCase();if(!/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t))return null;if(t.length===4){let e=t[1],n=t[2],r=t[3];return`#${e}${e}${n}${n}${r}${r}`}return t}function N(e){let t=M(e);return t?{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16)}:null}function P({r:e,g:t,b:n}){let r=e=>e.toString(16).padStart(2,`0`);return`#${r(e)}${r(t)}${r(n)}`}function F(e){return Math.max(0,Math.min(1,e))}function I(e){return e<=.04045?e/12.92:((e+.055)/1.055)**2.4}function L(e){let t=F(e);return t<=.0031308?12.92*t:1.055*t**(1/2.4)-.055}function R({r:e,g:t,b:n}){let r=e/255,i=t/255,a=n/255,o=I(r),s=I(i),c=I(a),l=.4122214708*o+.5363325363*s+.0514459929*c,u=.2119034982*o+.6806995451*s+.1073969566*c,d=.0883024619*o+.2817188376*s+.6299787005*c,f=Math.cbrt(l),p=Math.cbrt(u),m=Math.cbrt(d),h=.2104542553*f+.793617785*p-.0040720468*m,g=1.9779984951*f-2.428592205*p+.4505937099*m,_=.0259040371*f+.7827717662*p-.808675766*m,v=Math.sqrt(g*g+_*_),y=180/Math.PI*Math.atan2(_,g);return y<0&&(y+=360),{l:h,c:v,h:y}}function z(e,t,n,r=!1){let i=n*Math.PI/180,a=t*Math.cos(i),o=t*Math.sin(i),s=e+.3963377774*a+.2158037573*o,c=e-.1055613458*a-.0638541728*o,l=e-.0894841775*a-1.291485548*o,u=r?F(s):s,d=r?F(c):c,f=r?F(l):l;if(!r&&(u<-1e-4||u>1.0001||d<-1e-4||d>1.0001||f<-1e-4||f>1.0001))return null;let p=u*u*u,m=d*d*d,h=f*f*f,g=4.0767416621*p-3.3077115913*m+.2309699292*h,_=-1.2684380046*p+2.6097574011*m-.3413193965*h,v=-.0041960863*p-.7034186147*m+1.707614701*h;if(r)g=F(g),_=F(_),v=F(v);else if(g<-1e-4||g>1.0001||_<-1e-4||_>1.0001||v<-1e-4||v>1.0001)return null;let y=F(L(g)),b=F(L(_)),x=F(L(v));return{r:Math.round(y*255),g:Math.round(b*255),b:Math.round(x*255)}}function B(e,t,n){let r=t;for(let t=0;t<8;t+=1){let t=z(e,r,n);if(t)return t;r*=.9}return z(e,F(r),n,!0)||{r:0,g:0,b:0}}function V(e){let t=N(e);if(!t)return 0;let n=I(t.r/255),r=I(t.g/255),i=I(t.b/255);return .2126*n+.7152*r+.0722*i}function H(e,t){let n=V(e),r=V(t),i=Math.max(n,r),a=Math.min(n,r);return(i+.05)/(a+.05)}function U(e,t,n={}){let r=n.minContrast??b,i=n.preferDark!==!1,a=Math.max(.01,Math.min(.06,(e.c||.12)*(n.chromaScale??.25))),o=n.initialLightness??(i?.24:.94),s=i?-1:1,c=n.step??.03,l=F(o),u=P(B(l,a,e.h)),d=H(t,u);for(let n=0;n<48;n+=1){let n=P(B(l,a,e.h)),i=H(t,n);if(i>d&&(d=i,u=n),i>=r)return n;if(l=F(l+s*c),l===0||l===1)break}let f=`#000000`,p=`#ffffff`,m=H(t,f),h=H(t,p);return m>=r||h>=r?m>=h?f:p:u}function W(e,t,n={}){let r=n.minContrast??b,i=n.darkCandidate??`#101214`,a=n.lightCandidate??`#ffffff`,o=n.preferredCandidate,s=n.preferredMinContrast??r,c=n.preferredSwitchDelta??0,l=H(t,i),u=H(t,a),d=l>=r,f=u>=r,p=u>=s,m=l>=s;if(d||f)return o===`light`&&p?a:o===`dark`&&m?i:o===`light`&&f?!d||l-u<=c?a:i:o===`dark`&&d?!f||u-l<=c?i:a:d&&f?l>=u?i:a:d?i:a;let h=l>=u;return U(e,t,{minContrast:r,preferDark:h,initialLightness:h?.2:.96,chromaScale:.1})}let G=[100,200,300,400,500,600,700,800,900,1e3],K=[.9,.84,.78,.72,.67,.62,.56,.5,.44,.38],q=[.28,.4,.54,.7,.86,1,1.08,1.14,1.2,1.24];function J(e,t,n,r){let i=t[t.length-1];for(let i of t){let t=e[i];if(t&&H(t,n)>=r)return i}return i}function Y(e){let t=e.l-K[5],n=e.c>.02?.02:0;return G.reduce((r,i,a)=>(r[i]=P(B(F(K[a]+t),Math.min(.4,Math.max(n,e.c*q[a])),e.h)),r),{})}function X(e,t){let n=[100,200,300,400,500,600,700],r=J(t,n,E,C),i=n.indexOf(r),a=n[Math.min(i+1,n.length-1)],o=n[Math.min(i+2,n.length-1)],s=[1e3,900,800,700,600,500],c=J(t,s,D,C),l=s.indexOf(c),u=s[Math.min(l+1,s.length-1)],d=s[Math.min(l+2,s.length-1)],f=J(t,[200,300,400,500,600,700,800],E,S),p=J(t,[900,800,700,600,500,400],D,S),m=[600,700,800,900,1e3],h=J(t,m,E,x),g=m.indexOf(h),_=m[Math.min(g+1,m.length-1)],v=m[Math.min(g+2,m.length-1)],y=[400,300,200,100],O=J(t,y,D,x),k=y.indexOf(O),A=y[Math.min(k+1,y.length-1)],j=y[Math.min(k+2,y.length-1)],M={"--color-brand-surface-soft-light":t[r],"--color-brand-surface-soft-hovered-light":t[a],"--color-brand-surface-soft-pressed-light":t[o],"--color-brand-surface-soft-dark":t[c],"--color-brand-surface-soft-hovered-dark":t[u],"--color-brand-surface-soft-pressed-dark":t[d],"--color-brand-surface-subtle-light":t[f],"--color-brand-surface-subtle-dark":t[p],"--color-brand-surface-strong-light":t[h],"--color-brand-surface-strong-hovered-light":t[_],"--color-brand-surface-strong-pressed-light":t[v],"--color-brand-surface-strong-dark":t[O],"--color-brand-surface-strong-hovered-dark":t[A],"--color-brand-surface-strong-pressed-dark":t[j]},N=t[600];return M[`--color-brand-on-soft-light`]=H(M[`--color-brand-surface-soft-light`],N)>=b?N:W(e,M[`--color-brand-surface-soft-light`],{minContrast:b}),M[`--color-brand-on-soft-dark`]=W(e,M[`--color-brand-surface-soft-dark`],{minContrast:b}),M[`--color-brand-on-subtle-light`]=W(e,M[`--color-brand-surface-subtle-light`],{minContrast:w,preferredCandidate:`light`,preferredMinContrast:w,preferredSwitchDelta:T}),M[`--color-brand-on-subtle-dark`]=W(e,M[`--color-brand-surface-subtle-dark`],{minContrast:b}),M[`--color-brand-on-strong-light`]=W(e,M[`--color-brand-surface-strong-light`],{minContrast:w,preferredCandidate:`light`,preferredMinContrast:w,preferredSwitchDelta:T}),M[`--color-brand-on-strong-dark`]=W(e,M[`--color-brand-surface-strong-dark`],{minContrast:b}),M[`--color-brand-text-light`]=M[`--color-brand-surface-strong-light`],M[`--color-brand-text-dark`]=M[`--color-brand-surface-strong-dark`],M[`--color-brand-icon-light`]=M[`--color-brand-surface-strong-light`],M[`--color-brand-icon-dark`]=M[`--color-brand-surface-strong-dark`],M[`--color-brand-border-light`]=M[`--color-brand-surface-strong-light`],M[`--color-brand-border-dark`]=M[`--color-brand-surface-strong-dark`],M}function Z(e){let t=M(e);if(!t)return null;let n=N(t);if(!n)return null;let r=R(n),i=Y(r);return i[600]=t,{"--color-brand-seed":t,"--color-brand-100":i[100],"--color-brand-200":i[200],"--color-brand-300":i[300],"--color-brand-400":i[400],"--color-brand-500":i[500],"--color-brand-600":i[600],"--color-brand-700":i[700],"--color-brand-800":i[800],"--color-brand-900":i[900],"--color-brand-1000":i[1e3],...X(r,i)}}let Q=(0,e.computed)(()=>Z(n.accentColor)??{}),$={vars:{},enabled:!!n.exposeGlobalAccent};return h.push($),(0,e.watch)(()=>n.exposeGlobalAccent,e=>{$.enabled=!!e,r()},{immediate:!0}),(0,e.watch)(Q,e=>{e&&Object.keys(e).length>0?$.vars={...e}:$.vars={},r()},{immediate:!0}),(t,n)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{class:`theme`,style:(0,e.normalizeStyle)(Q.value)},[(0,e.renderSlot)(t.$slots,`default`),(0,e.createElementVNode)(`div`,{ref_key:`portalHost`,ref:d,class:`theme__portal-host`},null,512)],4))}}),k=((e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n})((0,e.defineComponent)({__name:`ThemeSwitcher`,props:{mode:{type:String,default:`auto`,validator:e=>[`auto`,`light`,`dark`].includes(e)}},emits:[`update:mode`],setup(r,{emit:i}){let a=[{value:`auto`,label:`System`},{value:`light`,label:`Light`},{value:`dark`,label:`Dark`}].reduce((e,t)=>(e[t.value]=t.label,e),{}),l=n,u=r,d=i;c();let f=(0,e.ref)(!1),p=o()??u.mode,m=(0,e.ref)(l.includes(p)?p:`auto`);return(0,e.watch)(()=>u.mode,e=>{l.includes(e)&&e!==m.value&&(m.value=e)}),(0,e.watch)(m,e=>{if(!l.includes(e)){m.value=`auto`;return}f.value=!1,d(`update:mode`,e),s(e),c(e)},{immediate:!0}),(n,r)=>((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(t.DropdownMenu),{open:f.value,"onUpdate:open":r[3]||=e=>f.value=e,text:`Theme`,"aria-label":`Select theme mode`},{default:(0,e.withCtx)(()=>[(0,e.createVNode)((0,e.unref)(t.DropdownItemGroup),{title:`Theme`,"item-role":`menuitemradio`},{default:(0,e.withCtx)(()=>[(0,e.createVNode)((0,e.unref)(t.DropdownItemRadio),{checked:m.value,"onUpdate:checked":r[0]||=e=>m.value=e,value:`auto`,label:(0,e.unref)(a).auto,"aria-label":`${(0,e.unref)(a).auto} mode`},null,8,[`checked`,`label`,`aria-label`]),r[4]||=(0,e.createElementVNode)(`hr`,{class:`theme-switcher-divider`},null,-1),(0,e.createVNode)((0,e.unref)(t.DropdownItemRadio),{checked:m.value,"onUpdate:checked":r[1]||=e=>m.value=e,value:`light`,label:(0,e.unref)(a).light,"aria-label":`${(0,e.unref)(a).light} mode`},null,8,[`checked`,`label`,`aria-label`]),(0,e.createVNode)((0,e.unref)(t.DropdownItemRadio),{checked:m.value,"onUpdate:checked":r[2]||=e=>m.value=e,value:`dark`,label:(0,e.unref)(a).dark,"aria-label":`${(0,e.unref)(a).dark} mode`},null,8,[`checked`,`label`,`aria-label`])]),_:1})]),_:1},8,[`open`]))}}),[[`__scopeId`,`data-v-be9d7090`]]);exports.Theme=O,exports.ThemeSwitcher=k,exports.themePortalHostKey=p,exports.useThemePortalTarget=m;
|
|
2
|
-
//# sourceMappingURL=theme.cjs.js.map
|