Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Download src/utils/theme.ts from lerobot/visualize_dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/lerobot/visualize_dataset/resolve/main/src/utils/theme.ts
- Command line
-
hf download hf://spaces/lerobot/visualize_dataset/src/utils/theme.ts
-
curl -L -o theme.ts https://huggingface.co/spaces/lerobot/visualize_dataset/resolve/main/src/utils/theme.ts
1.01 kB
| "use client"; | |
| import { useSyncExternalStore } from "react"; | |
| import { THEME_STORAGE_KEY } from "./theme-init"; | |
| export type Theme = "light" | "dark"; | |
| function getTheme(): Theme { | |
| return document.documentElement.classList.contains("dark") ? "dark" : "light"; | |
| } | |
| function subscribe(onChange: () => void): () => void { | |
| const observer = new MutationObserver(onChange); | |
| observer.observe(document.documentElement, { | |
| attributes: true, | |
| attributeFilter: ["class"], | |
| }); | |
| return () => observer.disconnect(); | |
| } | |
| export function setTheme(theme: Theme) { | |
| document.documentElement.classList.toggle("dark", theme === "dark"); | |
| try { | |
| localStorage.setItem(THEME_STORAGE_KEY, theme); | |
| } catch { | |
| // Storage blocked (private mode, embedded iframe): the choice lasts for this page only. | |
| } | |
| } | |
| /** The current theme, for code that needs actual colours (Three.js) rather than CSS variables. */ | |
| export function useTheme(): Theme { | |
| return useSyncExternalStore(subscribe, getTheme, () => "dark"); | |
| } | |