youtuber-blog-frontend/build/server/chunks/mode-watcher-DyhmqlyS.js.map

1 line
14 KiB
Plaintext
Raw Normal View History

2024-06-21 23:07:37 +00:00
{"version":3,"file":"mode-watcher-DyhmqlyS.js","sources":["../../../.svelte-kit/adapter-node/chunks/mode-watcher.js"],"sourcesContent":["import { c as create_ssr_component, d as add_attribute } from \"./ssr.js\";\nimport { d as derived, w as writable } from \"./index2.js\";\nlet timeoutAction;\nlet timeoutEnable;\nfunction withoutTransition(action) {\n if (typeof document === \"undefined\")\n return;\n clearTimeout(timeoutAction);\n clearTimeout(timeoutEnable);\n const style = document.createElement(\"style\");\n const css = document.createTextNode(`* {\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 style.appendChild(css);\n const disable = () => document.head.appendChild(style);\n const enable = () => document.head.removeChild(style);\n if (typeof window.getComputedStyle !== \"undefined\") {\n disable();\n action();\n window.getComputedStyle(style).opacity;\n enable();\n return;\n }\n if (typeof window.requestAnimationFrame !== \"undefined\") {\n disable();\n action();\n window.requestAnimationFrame(enable);\n return;\n }\n disable();\n timeoutAction = window.setTimeout(() => {\n action();\n timeoutEnable = window.setTimeout(enable, 120);\n }, 120);\n}\nconst noopStorage = {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getItem: (_key) => null,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n setItem: (_key, _value) => {\n }\n};\nconst isBrowser = typeof document !== \"undefined\";\nconst modes = [\"dark\", \"light\", \"system\"];\nconst localStorageKey = \"mode-watcher-mode\";\nconst userPrefersMode = createUserPrefersMode();\nconst systemPrefersMode = createSystemMode();\nconst themeColors = writable(void 0);\nconst disableTransitions = writable(true);\nconst derivedMode = createDerivedMode();\nfunction createUserPrefersMode() {\n const defaultValue = \"system\";\n const storage = isBrowser ? localStorage : noopStorage;\n const initialValue = storage.getItem(localStorageKey);\n let value = isValidMode(initialValue) ? initialValue : defaultValue;\n const { subscribe, set: _set } = writable(value, () => {\n if (!isBrowser)\n return;\n const handler = (e) => {\n if (e.key !== localStorageKey)\n return;\n const newValue = e.newValue;\n if (isValidMode(newValue)) {\n _set(value = newValue);\n } else {\n _set(value = defaultValue);\n }\n };\n addEventListener(\"storage\", handler);\n return () => removeEventListener(\"storage\", handler);\n });\n function set(v) {\n _set(value = v);\n storage.setItem(localStorageKey, value);\n }\n return {\n subscribe,\n set\n };\n}\nfunction createSystemMode() {\n const defaultValue = void 0;\n let track = true;\n const { subscribe, set } = writable(defaultValue, () => {\n if (!isBrowser)\n return;\n const handler = (e) => {\n if (!track)\n return;\n set(e.matches ? \"light\" : \"dark\");\n };\n const mediaQueryState = window.matchMedia(\"(prefers-color-scheme: light)\");\n mediaQueryState.addEventListener(\"change\", handler);\n return () => mediaQueryState.removeEventListener(\"change\", handler);\n });\n function query() {\n if (!isBrowser)\n return;\n const mediaQueryState = window.matchMedia(\"(prefers-color-scheme: light)\");\n set(mediaQueryState.matches ? \"light\" : \"dark\");\n }\n function tracking(active) {\n track = active;\n }\n return {\n subscribe,\n query,\n tracking\n };\n}\nfunction createDerivedMode() {\n const { subscribe } = derived([userPrefersMode, systemPrefersMode, themeColors, disableTransitions], ([$userPrefersMode, $systemPrefersMode, $themeColors, $disableTransitions]) => {\n if (!isBrowser)\n return void 0;\n const derivedMode2 = $userPrefersMode === \"system\" ? $systemPrefersMode : $userPrefersMode;\n function update() {\n const