@madooei/omni-themes
Version:
Universal theme library that works with any JavaScript framework. Provides perfect dark mode, system theme detection, and no-flash loading.
1 lines • 29.3 kB
Source Map (JSON)
{"version":3,"sources":["../src/util.ts","../src/script.ts","../src/store.ts"],"names":["themes","themesMap","defaultTheme","defaultLightTheme","defaultDarkTheme","dataAttributes","themeStorageKey","darkMediaQuery","enableColorScheme","enableSystem","updateClassAttribute","forcedThemeFlagAttribute","forcedTheme","atom","computed","onMount"],"mappings":";;;;;;;AAUO,SAAS,eACd,cACyB,EAAA;AACzB,EAAI,IAAA,OAAO,MAAW,KAAA,WAAA,EAAoB,OAAA,MAAA;AAC1C,EAAA,OAAO,MAAO,CAAA,UAAA,CAAW,cAAc,CAAA,CAAE,UAAU,MAAS,GAAA,OAAA;AAC9D;AAgBO,SAAS,UACd,QACA,EAAA,MAAA,EACA,WACA,cACA,EAAA,iBAAA,EACA,sBACA,wBACM,EAAA;AACN,EAAA,IAAI,CAAC,QAAA,IAAY,OAAO,MAAA,KAAW,WAAa,EAAA;AAEhD,EAAA,MAAM,OAAO,QAAS,CAAA,eAAA;AAGtB,EAAA,IACE,wBACA,IAAA,IAAA,CAAK,YAAa,CAAA,wBAAwB,MAAM,MAChD,EAAA;AACA,IAAA;AAAA;AAIF,EAAA,IAAI,oBAAsB,EAAA;AACxB,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,GAAG,MAAM,CAAA;AAC/B,IAAK,IAAA,CAAA,SAAA,CAAU,IAAI,QAAQ,CAAA;AAAA;AAI7B,EAAe,cAAA,CAAA,OAAA,CAAQ,CAAC,aAAwC,KAAA;AAC9D,IAAA,IAAI,aAAiB,IAAA,aAAA,CAAc,UAAW,CAAA,OAAO,CAAG,EAAA;AACtD,MAAK,IAAA,CAAA,YAAA,CAAa,eAAe,QAAQ,CAAA;AAAA;AAC3C,GACD,CAAA;AAGD,EAAA,IAAI,iBAAmB,EAAA;AACrB,IAAA,MAAM,WAAc,GAAA,SAAA,CAAU,IAAM,EAAA,Q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;AAAA,IAClB,SAAW,EAAA,kBAAA;AAAA,IACX,eAAA;AAAA,IACA,cAAA;AAAA,IACA,cAAA;AAAA,IACA,iBAAA;AAAA,IACA,YAAA;AAAA,IACA,oBAAA;AAAA,IACA,yBAAA;AAAA,IACA,wBAAA;AAAA,IACA;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["import type { DataAttributePattern, SystemTheme, ThemeName } from \"./types\";\n\n/**\n * Detects the system's color scheme preference.\n *\n * @param darkMediaQuery - The media query string to detect dark mode\n * preference.\n * @returns The detected system theme ('dark' or 'light'), or undefined if\n * running server-side.\n */\nexport function getSystemTheme(\n darkMediaQuery: string,\n): SystemTheme | undefined {\n if (typeof window === \"undefined\") return undefined;\n return window.matchMedia(darkMediaQuery).matches ? \"dark\" : \"light\";\n}\n\n/**\n * Updates the DOM to reflect the new theme.\n *\n * @param newTheme - The name of the new theme to apply.\n * @param themes - Array of all available theme names.\n * @param themesMap - Mapping of system themes to theme names.\n * @param dataAttributes - Array of data attributes to update with the new\n * theme.\n * @param enableColorScheme - Whether to update the color-scheme CSS property.\n * @param updateClassAttribute - Whether to update the class attribute of the\n * root element.\n * @param forcedThemeFlagAttribute - Data attribute indicating if a theme is\n * forced by the user.\n */\nexport function updateDOM(\n newTheme: ThemeName,\n themes: ThemeName[],\n themesMap: Record<SystemTheme, ThemeName[]>,\n dataAttributes: DataAttributePattern[],\n enableColorScheme: boolean,\n updateClassAttribute: boolean,\n forcedThemeFlagAttribute: DataAttributePattern,\n): void {\n if (!newTheme || typeof window === \"undefined\") return;\n\n const root = document.documentElement;\n\n // Check if theme is forced by user\n if (\n forcedThemeFlagAttribute &&\n root.getAttribute(forcedThemeFlagAttribute) === \"true\"\n ) {\n return;\n }\n\n // Update class attribute\n if (updateClassAttribute) {\n root.classList.remove(...themes);\n root.classList.add(newTheme);\n }\n\n // Update data attributes\n dataAttributes.forEach((dataAttribute: DataAttributePattern) => {\n if (dataAttribute && dataAttribute.startsWith(\"data-\")) {\n root.setAttribute(dataAttribute, newTheme);\n }\n });\n\n // Update color scheme\n if (enableColorScheme) {\n const colorScheme = themesMap.dark?.includes(newTheme)\n ? \"dark\"\n : themesMap.light?.includes(newTheme)\n ? \"light\"\n : null;\n if (colorScheme) {\n root.style.colorScheme = colorScheme;\n }\n }\n}\n\n/**\n * Temporarily disables all CSS transitions and animations on the page.\n *\n * @returns A cleanup function that, when called, will re-enable animations.\n *\n * @example\n * // Disable animations\n * const enableAnimations = disableAnimation();\n *\n * // Perform DOM operations here...\n *\n * // Re-enable animations\n * enableAnimations();\n */\nexport function disableAnimation(): () => void {\n const css = document.createElement(\"style\");\n css.appendChild(\n document.createTextNode(`\n *,\n *::before,\n *::after {\n -webkit-transition: none !important;\n -moz-transition: none !important;\n -o-transition: none !important;\n -ms-transition: none !important;\n transition: none !important;\n }\n `),\n );\n document.head.appendChild(css);\n\n return () => {\n // Force a reflow\n window.getComputedStyle(document.body);\n\n // Remove the style element in the next frame\n requestAnimationFrame(() => {\n document.head.removeChild(css);\n });\n };\n}\n","import type { ThemeName, ThemeStoreConfig } from \"./types\";\n\n/**\n * Creates a script string to apply the theme based on the provided configuration.\n * This script is designed to be injected into the <head> of the document to solve\n * the \"flash of incorrect theme\" (FOIT) issue.\n *\n * @param config - The theme store configuration object.\n * @returns A script string that can be injected into the HTML.\n */\nexport function createThemeScript({\n themes,\n themesMap,\n defaultTheme,\n defaultLightTheme,\n defaultDarkTheme,\n dataAttributes,\n themeStorageKey,\n darkMediaQuery,\n enableColorScheme,\n enableSystem,\n updateClassAttribute,\n forcedThemeFlagAttribute,\n}: Omit<ThemeStoreConfig, \"disableTransitionOnChange\">): string {\n // The `applyThemeScript` function is meant to be injected into the <head> of the document.\n // It's written in vanilla JavaScript to ensure browser compatibility.\n const applyThemeScript = (\n themes = [\"light\", \"dark\"],\n themesMap = { light: [\"light\"], dark: [\"dark\"] },\n defaultTheme = \"light\",\n defaultLightTheme = \"light\",\n defaultDarkTheme = \"dark\",\n dataAttributes = [`data-theme`],\n themeStorageKey = \"omni-theme\",\n darkMediaQuery = \"(prefers-color-scheme: dark)\",\n enableColorScheme = true,\n enableSystem = true,\n updateClassAttribute = true,\n forcedThemeFlagAttribute = \"data-theme-forced\",\n ) => {\n /* Don't run on the server */\n if (typeof window === \"undefined\") return;\n\n const root = document.documentElement;\n\n /* Don't respond to theme change if the user has forced a theme */\n if (\n forcedThemeFlagAttribute &&\n root.getAttribute(forcedThemeFlagAttribute) === \"true\"\n )\n return;\n\n let resolvedTheme = defaultTheme;\n const theme = localStorage && localStorage.getItem(themeStorageKey);\n\n if (theme && theme !== \"system\") {\n resolvedTheme = theme;\n } else if (enableSystem) {\n const systemTheme = window.matchMedia(darkMediaQuery).matches\n ? \"dark\"\n : \"light\";\n resolvedTheme =\n systemTheme === \"dark\" ? defaultDarkTheme : defaultLightTheme;\n }\n\n /* Update class attribute if enabled */\n if (updateClassAttribute) {\n root.classList.remove(...themes);\n root.classList.add(resolvedTheme);\n }\n\n /* Update data attributes */\n if (dataAttributes) {\n dataAttributes.forEach((dataAttribute) => {\n if (dataAttribute && dataAttribute.startsWith(\"data-\")) {\n root.setAttribute(dataAttribute, resolvedTheme);\n }\n });\n }\n\n /* Update color scheme if enabled */\n if (enableColorScheme && themesMap) {\n if (themesMap.dark && themesMap.dark.includes(resolvedTheme)) {\n root.style.colorScheme = \"dark\";\n } else if (themesMap.light && themesMap.light.includes(resolvedTheme)) {\n root.style.colorScheme = \"light\";\n }\n }\n };\n\n // Stringify the arguments to the applyThemeScript function\n const scriptArgs = JSON.stringify([\n themes,\n themesMap,\n defaultTheme,\n defaultLightTheme,\n defaultDarkTheme,\n dataAttributes,\n themeStorageKey,\n darkMediaQuery,\n enableColorScheme,\n enableSystem,\n updateClassAttribute,\n forcedThemeFlagAttribute,\n ]).slice(1, -1); // remove square brackets\n\n // Create the script string that runs as IIFE when injected\n const scriptString = `(${applyThemeScript.toString()})(${scriptArgs})`;\n\n // TODO: Minify the script string?\n return scriptString;\n}\n\n/**\n * Creates a factory function that generates scripts to apply a forced theme.\n *\n * @param config - Partial theme store configuration object.\n * @returns A function that creates a script string for applying a forced theme.\n */\nexport function createForcedThemeScriptFactory({\n themes,\n themesMap,\n dataAttributes,\n enableColorScheme,\n updateClassAttribute,\n forcedThemeFlagAttribute,\n}: Omit<\n ThemeStoreConfig,\n | \"defaultTheme\"\n | \"defaultLightTheme\"\n | \"defaultDarkTheme\"\n | \"themeStorageKey\"\n | \"darkMediaQuery\"\n | \"enableSystem\"\n | \"disableTransitionOnChange\"\n>): (forcedTheme: ThemeName) => string {\n return (forcedTheme: ThemeName): string => {\n // The `applyForcedThemeScript` function is meant to be injected into the <head> of the document.\n // It's written in vanilla JavaScript to ensure browser compatibility.\n const applyForcedThemeScript = (\n forcedTheme = \"light\",\n themes = [\"light\", \"dark\"],\n themesMap = { light: [\"light\"], dark: [\"dark\"] },\n dataAttributes = [`data-theme`],\n enableColorScheme = true,\n updateClassAttribute = true,\n forcedThemeFlagAttribute = \"data-theme-forced\",\n ) => {\n /* Don't run on the server */\n if (typeof window === \"undefined\") return;\n\n const root = document.documentElement;\n\n /* Mark the page that the user has forced a theme */\n if (forcedThemeFlagAttribute) {\n root.setAttribute(forcedThemeFlagAttribute, \"true\");\n }\n\n /* Update class attribute if enabled */\n if (updateClassAttribute) {\n root.classList.remove(...themes);\n root.classList.add(forcedTheme);\n }\n\n /* Update data attributes */\n if (dataAttributes) {\n dataAttributes.forEach((dataAttribute) => {\n if (dataAttribute && dataAttribute.startsWith(\"data-\")) {\n root.setAttribute(dataAttribute, forcedTheme);\n }\n });\n }\n\n /* Update color scheme if enabled */\n if (enableColorScheme && themesMap) {\n if (themesMap.dark && themesMap.dark.includes(forcedTheme)) {\n root.style.colorScheme = \"dark\";\n } else if (themesMap.light && themesMap.light.includes(forcedTheme)) {\n root.style.colorScheme = \"light\";\n }\n }\n };\n\n // Stringify the arguments to the applyForcedThemeScript function\n const scriptArgs = JSON.stringify([\n forcedTheme,\n themes,\n themesMap,\n dataAttributes,\n enableColorScheme,\n updateClassAttribute,\n forcedThemeFlagAttribute,\n ]).slice(1, -1); // remove square brackets\n\n // Create the script string that runs as IIFE when injected\n const scriptString = `(${applyForcedThemeScript.toString()})(${scriptArgs})`;\n\n // TODO: Minify the script string?\n return scriptString;\n };\n}\n","import { onMount, computed, atom } from \"nanostores\";\nimport type { ReadableAtom, WritableAtom } from \"nanostores\";\nimport type {\n SystemTheme,\n ThemeName,\n ThemeStore,\n ThemeStoreConfig,\n} from \"./types\";\nimport { updateDOM, disableAnimation, getSystemTheme } from \"./util\";\nimport { createForcedThemeScriptFactory, createThemeScript } from \"./script\";\n\ntype SystemThemeStateValue = SystemTheme | undefined;\n\nconst isServer = typeof window === \"undefined\";\n\n/**\n * Creates a theme store with the provided configuration.\n * @param config - The theme store configuration object.\n * @returns A theme store object.\n */\nexport function createThemeStore(config: ThemeStoreConfig): ThemeStore {\n const {\n themes,\n defaultTheme,\n defaultLightTheme,\n defaultDarkTheme,\n themesMap,\n themeStorageKey,\n darkMediaQuery,\n dataAttributes,\n enableColorScheme,\n enableSystem,\n updateClassAttribute,\n disableTransitionOnChange,\n forcedThemeFlagAttribute,\n debug,\n } = validateAndInitializeThemeStoreConfiguration(config);\n\n const $theme = atom<ThemeName>(\n defaultTheme ? defaultTheme : enableSystem ? \"system\" : themes[0],\n );\n\n const $systemTheme = atom<SystemThemeStateValue>(\n getSystemTheme(darkMediaQuery),\n );\n\n const $resolvedTheme = computed<\n ThemeName,\n [WritableAtom<ThemeName>, WritableAtom<SystemThemeStateValue>]\n >([$theme, $systemTheme], (theme, systemTheme) => {\n // Resolve the theme based on user preference and system theme\n if (theme !== \"system\") return theme;\n if (systemTheme === \"dark\") return defaultDarkTheme;\n if (systemTheme === \"light\") return defaultLightTheme;\n return defaultTheme;\n });\n\n onMount($theme, () => {\n if (debug) console.log(\"🚀 theme mounted:\", $theme.get());\n\n if (isServer) return;\n\n // Initialize from localStorage if available\n const storedValue = localStorage.getItem(themeStorageKey);\n if (storedValue !== null) {\n $theme.set(storedValue);\n }\n\n // Listen for theme changes in localStorage\n const handleStorageChange = (e: StorageEvent) => {\n if (e.key === themeStorageKey) {\n if (e.newValue !== null) $theme.set(e.newValue);\n }\n };\n\n window.addEventListener(\"storage\", handleStorageChange);\n\n return () => {\n if (debug) console.log(\"🚀 theme unmounted\");\n window.removeEventListener(\"storage\", handleStorageChange);\n };\n });\n\n onMount($systemTheme, () => {\n if (debug) console.log(\"🚀 system theme mounted:\", $systemTheme.get());\n\n if (isServer) return;\n\n // Listen for system theme changes\n const darkModeMediaQuery = window.matchMedia(darkMediaQuery);\n const handleMediaQueryChange = (e: MediaQueryListEvent) => {\n $systemTheme.set(e.matches ? \"dark\" : \"light\");\n };\n\n darkModeMediaQuery.addEventListener(\"change\", handleMediaQueryChange);\n\n return () => {\n if (debug) console.log(\"🚀 system theme unmounted\");\n darkModeMediaQuery.removeEventListener(\"change\", handleMediaQueryChange);\n };\n });\n\n onMount($resolvedTheme, () => {\n if (debug) console.log(\"🚀 resolved theme mounted:\", $resolvedTheme.get());\n\n return () => {\n if (debug) console.log(\"🚀 resolved theme unmounted\");\n };\n });\n\n // Add persistance to the theme atom\n $theme.subscribe((theme) => {\n if (isServer) return;\n\n // Update localStorage\n localStorage.setItem(themeStorageKey, theme);\n });\n\n $resolvedTheme.subscribe((resolvedTheme) => {\n if (isServer) return;\n\n // Disable transitions during theme change if configured\n const enableAnimations = disableTransitionOnChange\n ? disableAnimation()\n : null;\n\n // Update the DOM with the new theme\n updateDOM(\n resolvedTheme,\n themes,\n themesMap,\n dataAttributes,\n enableColorScheme,\n updateClassAttribute,\n forcedThemeFlagAttribute,\n );\n\n // Re-enable transitions if they were disabled\n enableAnimations?.();\n });\n\n // Create logger if debug is enabled\n if (debug) {\n $theme.listen((value) => console.log(\"🚀 theme:\", value));\n $systemTheme.listen((value) => console.log(\"🚀 system theme:\", value));\n $resolvedTheme.listen((value) => console.log(\"🚀 resolved theme:\", value));\n }\n\n const applyThemeScriptString = createThemeScript({\n themes,\n themesMap,\n defaultTheme,\n defaultLightTheme,\n defaultDarkTheme,\n dataAttributes,\n themeStorageKey,\n darkMediaQuery,\n enableColorScheme,\n enableSystem,\n updateClassAttribute,\n forcedThemeFlagAttribute,\n });\n\n const createForcedThemeScriptString = createForcedThemeScriptFactory({\n themes,\n themesMap,\n dataAttributes,\n enableColorScheme,\n updateClassAttribute,\n forcedThemeFlagAttribute,\n });\n\n return {\n themes: enableSystem ? [...themes, \"system\"] : themes,\n $theme: $theme as ReadableAtom<ThemeName>,\n $resolvedTheme,\n $systemTheme: $systemTheme as ReadableAtom<SystemThemeStateValue>,\n setTheme: (theme: ThemeName) => $theme.set(theme),\n applyThemeScriptString,\n createForcedThemeScriptString,\n };\n}\n\n/**\n * Validates and initializes the theme store configuration.\n * @param config - The theme store configuration object.\n * @returns The validated and initialized configuration object.\n */\nfunction validateAndInitializeThemeStoreConfiguration(\n config: ThemeStoreConfig,\n): Required<ThemeStoreConfig> {\n const {\n themes = [],\n defaultTheme,\n defaultLightTheme,\n defaultDarkTheme,\n themesMap,\n themeStorageKey = \"omni-theme\",\n darkMediaQuery = \"(prefers-color-scheme: dark)\",\n dataAttributes = [\"data-theme\"],\n enableColorScheme = true,\n enableSystem = true,\n updateClassAttribute = true,\n disableTransitionOnChange = false,\n forcedThemeFlagAttribute = \"data-theme-forced\",\n debug = false,\n } = config;\n\n // Validate and set default values for theme-related properties\n const validatedThemes = themes.length > 0 ? themes : [\"light\", \"dark\"];\n const validatedDefaultTheme =\n defaultTheme && validatedThemes.includes(defaultTheme)\n ? defaultTheme\n : enableSystem\n ? \"system\"\n : validatedThemes[0];\n\n const validatedDefaultLightTheme =\n defaultLightTheme && validatedThemes.includes(defaultLightTheme)\n ? defaultLightTheme\n : validatedThemes.find((t) => t.toLowerCase().includes(\"light\")) ||\n validatedThemes[0];\n\n const validatedDefaultDarkTheme =\n defaultDarkTheme && validatedThemes.includes(defaultDarkTheme)\n ? defaultDarkTheme\n : validatedThemes.find((t) => t.toLowerCase().includes(\"dark\")) ||\n validatedThemes[validatedThemes.length - 1];\n\n // Validate and set default values for themesMap\n const validatedThemesMap: Record<SystemTheme, ThemeName[]> = themesMap || {\n light: [validatedDefaultLightTheme],\n dark: [validatedDefaultDarkTheme],\n };\n\n // Ensure all themes in themesMap are valid\n Object.values(validatedThemesMap)\n .flat()\n .forEach((theme) => {\n if (!validatedThemes.includes(theme)) {\n throw new Error(\n `Invalid theme \"${theme}\" in themesMap. Must be one of ${validatedThemes.join(\n \", \",\n )}.`,\n );\n }\n });\n\n // If enableSystem is true, ensure all required properties are set\n if (enableSystem) {\n if (!validatedDefaultLightTheme || !validatedDefaultDarkTheme) {\n throw new Error(\n \"If enableSystem is true, both defaultLightTheme and defaultDarkTheme must be defined\",\n );\n }\n if (!validatedThemesMap.light || !validatedThemesMap.dark) {\n throw new Error(\n \"If enableSystem is true, themesMap must include both 'light' and 'dark' keys\",\n );\n }\n }\n\n return {\n themes: validatedThemes,\n defaultTheme: validatedDefaultTheme,\n defaultLightTheme: validatedDefaultLightTheme,\n defaultDarkTheme: validatedDefaultDarkTheme,\n themesMap: validatedThemesMap,\n themeStorageKey,\n darkMediaQuery,\n dataAttributes,\n enableColorScheme,\n enableSystem,\n updateClassAttribute,\n disableTransitionOnChange,\n forcedThemeFlagAttribute,\n debug,\n };\n}\n"]}