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0.1.10/static/theme-init.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@varavel/ui@0.1.10/static/theme-init.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n * @fileoverview Varavel UI theme bootstrapper.\n *\n * Resolves and applies the user's saved theme preference before the first paint\n * to prevent a flash of incorrect theme styles.\n *\n * The bootstrapper also exposes a small runtime bridge on\n * `window.__varavelUiTheme` so the Svelte runtime can read and update the same\n * source of truth without duplicating browser logic.\n */\n\n(() => {\n  const STORAGE_KEY = \"varavel-theme\";\n  const THEME_CHANGE_EVENT = \"varavel-theme-change\";\n\n  /** @typedef {\"light\" | \"dark\" | \"system\"} ThemePreference */\n  /** @typedef {\"light\" | \"dark\"} ResolvedTheme */\n\n  /**\n   * @typedef {object} ThemeState\n   * @property {ThemePreference} theme The saved user preference.\n   * @property {ResolvedTheme} resolved The concrete theme applied to the document.\n   */\n\n  /**\n   * @typedef {object} ThemeRuntimeApi\n   * @property {(theme: ThemePreference) => void} set Persists and applies a preference.\n   * @property {() => ThemeState} get Returns the current preference and resolved theme.\n   */\n\n  // `matchMedia` is optional in restrictive or non-browser environments.\n  const mql =\n    typeof window !== \"undefined\" && window.matchMedia\n      ? window.matchMedia(\"(prefers-color-scheme: dark)\")\n      : null;\n\n  /**\n   * Returns whether a value is a supported theme preference.\n   *\n   * @param {unknown} value - Value to validate.\n   * @returns {value is ThemePreference} Whether the value is supported.\n   */\n  const isThemePreference = (value) =>\n    value === \"light\" || value === \"dark\" || value === \"system\";\n\n  /**\n   * Resolves a preference to the concrete theme applied to the document.\n   *\n   * `\"system\"` follows the current `prefers-color-scheme` media query.\n   *\n   * @param {ThemePreference} theme - Preference to resolve.\n   * @returns {ResolvedTheme} The resolved document theme.\n   */\n  const resolveTheme = (theme) => {\n    if (theme === \"light\") return \"light\";\n    if (theme === \"dark\") return \"dark\";\n    return mql?.matches ? \"dark\" : \"light\";\n  };\n\n  /**\n   * Reads the saved theme preference and derives the resolved document theme.\n   *\n   * If storage is unavailable or contains an invalid value, the preference falls\n   * back to `\"system\"`.\n   *\n   * @returns {ThemeState} The current preference and resolved theme.\n   */\n  const getThemeState = () => {\n    /** @type {ThemePreference} */\n    let theme = \"system\";\n\n    try {\n      const stored = localStorage.getItem(STORAGE_KEY);\n      if (isThemePreference(stored)) {\n        theme = stored;\n      } else {\n        localStorage.setItem(STORAGE_KEY, \"system\");\n      }\n    } catch (_) {\n      // Fallback already set to \"system\"\n    }\n\n    return {\n      theme,\n      resolved: resolveTheme(theme),\n    };\n  };\n\n  /**\n   * Applies a theme preference to the document and emits a runtime update event.\n   *\n   * The document keeps both `data-theme` and the `dark` class in sync so the\n   * runtime works with the package theme tokens and any consumer CSS that relies\n   * on Tailwind's dark selector.\n   *\n   * @param {ThemePreference} theme - Theme preference to apply.\n   */\n  const applyDOM = (theme) => {\n    try {\n      const resolved = resolveTheme(theme);\n\n      document.documentElement.dataset.theme = resolved;\n      document.documentElement.classList.toggle(\"dark\", resolved === \"dark\");\n      document.documentElement.style.colorScheme = resolved;\n\n      window.dispatchEvent(\n        new CustomEvent(THEME_CHANGE_EVENT, {\n          detail: { theme, resolved },\n        }),\n      );\n    } catch (_) {\n      // Fail silently in highly restrictive environments\n    }\n  };\n\n  // Initial synchronous paint to prevent FOUC\n  const initialState = getThemeState();\n  applyDOM(initialState.theme);\n\n  /** @type {ThemeRuntimeApi} */\n  window.__varavelUiTheme = {\n    /**\n     * Persists and applies a theme preference immediately.\n     *\n     * Invalid input is normalized to `\"system\"` to keep the runtime predictable.\n     *\n     * @param {ThemePreference} newTheme - Preference to save and apply.\n     */\n    set: (newTheme) => {\n      const safeTheme = isThemePreference(newTheme) ? newTheme : \"system\";\n      try {\n        localStorage.setItem(STORAGE_KEY, safeTheme);\n      } catch (_) {\n        // Ignore storage quotas or privacy blocks\n      }\n      applyDOM(safeTheme);\n    },\n\n    /**\n     * Returns the current theme state.\n     *\n     * @returns {ThemeState} The saved preference and resolved document theme.\n     */\n    get: getThemeState,\n  };\n\n  // React to OS-level theme changes when the active preference is `system`.\n  if (mql) {\n    const handleSystemThemeChange = () => {\n      const state = getThemeState();\n      if (state.theme === \"system\") {\n        applyDOM(\"system\");\n      }\n    };\n\n    if (typeof mql.addEventListener === \"function\") {\n      mql.addEventListener(\"change\", handleSystemThemeChange);\n    } else if (typeof mql.addListener === \"function\") {\n      mql.addListener(handleSystemThemeChange);\n    }\n  }\n\n  // Keep other tabs in sync, including `localStorage.clear()` resets.\n  window.addEventListener(\"storage\", (event) => {\n    if (event.storageArea !== localStorage) {\n      return;\n    }\n\n    if (event.key === STORAGE_KEY || event.key === null) {\n      applyDOM(getThemeState().theme);\n    }\n  });\n})();\n"]}