import type { ReactNode } from 'react' import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react' export type Theme = 'light' | 'dark' | 'system' type ResolvedTheme = Exclude type ThemeContextValue = { /** The preference the user picked, `system` included. */ theme: Theme /** The preference already resolved against the OS setting. */ resolvedTheme: ResolvedTheme setTheme: (theme: Theme) => void } const STORAGE_KEY = 'superlist-theme' const DARK_QUERY = '(prefers-color-scheme: dark)' /** Browser chrome color (the iOS status bar) per theme. Keep in sync with `index.html`. */ const THEME_COLORS: Record = { light: '#f9f8f5', dark: '#0f1411' } /** * This theme handling is hand-rolled on purpose. Libraries such as `next-themes` * avoid the pre-paint flash by rendering a `