asterui 0.12.89 → 0.12.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Chart.js +91 -88
- package/dist/components/Chart.js.map +1 -1
- package/dist/components/QRCode.js +14 -14
- package/dist/components/QRCode.js.map +1 -1
- package/dist/components/Terminal.js +96 -93
- package/dist/components/Terminal.js.map +1 -1
- package/dist/components/ThemeController.js +1 -1
- package/dist/components/ThemeController.js.map +1 -1
- package/dist/components/Watermark.js +12 -12
- package/dist/components/Watermark.js.map +1 -1
- package/dist/hooks/useTheme.d.ts +11 -21
- package/dist/hooks/useTheme.js +63 -94
- package/dist/hooks/useTheme.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +45 -44
- package/dist/providers/ThemeProvider.d.ts +5 -13
- package/dist/providers/ThemeProvider.js +61 -64
- package/dist/providers/ThemeProvider.js.map +1 -1
- package/package.json +1 -1
package/dist/hooks/useTheme.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
const p = /* @__PURE__ */ new Set([
|
|
1
|
+
import { useHasThemeProvider as a, useThemeContext as f } from "../providers/ThemeProvider.js";
|
|
2
|
+
const d = /* @__PURE__ */ new Set([
|
|
4
3
|
"dark",
|
|
5
4
|
"synthwave",
|
|
6
5
|
"halloween",
|
|
@@ -13,106 +12,76 @@ const p = /* @__PURE__ */ new Set([
|
|
|
13
12
|
"coffee",
|
|
14
13
|
"dim",
|
|
15
14
|
"sunset"
|
|
16
|
-
])
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
15
|
+
]);
|
|
16
|
+
function h() {
|
|
17
|
+
if (a()) {
|
|
18
|
+
const t = f();
|
|
19
|
+
return {
|
|
20
|
+
theme: t.theme,
|
|
21
|
+
isDark: t.isDark,
|
|
22
|
+
setTheme: t.setTheme,
|
|
23
|
+
toggleTheme: t.toggleTheme,
|
|
24
|
+
systemTheme: t.systemTheme
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const e = typeof document < "u" ? document.documentElement.getAttribute("data-theme") ?? void 0 : void 0, r = typeof window < "u" && window.matchMedia("(prefers-color-scheme: dark)").matches, n = e ? d.has(e) : r;
|
|
28
|
+
return {
|
|
29
|
+
theme: e,
|
|
30
|
+
isDark: n,
|
|
31
|
+
setTheme: (t) => document.documentElement.setAttribute("data-theme", t),
|
|
32
|
+
toggleTheme: () => {
|
|
33
|
+
const t = document.documentElement.getAttribute("data-theme"), s = t ? d.has(t) : r;
|
|
34
|
+
document.documentElement.setAttribute("data-theme", s ? "light" : "dark");
|
|
35
|
+
},
|
|
36
|
+
systemTheme: r ? "dark" : "light"
|
|
37
|
+
};
|
|
38
|
+
}
|
|
28
39
|
let o = null;
|
|
29
|
-
function
|
|
40
|
+
function u() {
|
|
30
41
|
return o || (o = document.createElement("span"), o.style.position = "absolute", o.style.visibility = "hidden", o.style.pointerEvents = "none", o.style.width = "0", o.style.height = "0", o.style.overflow = "hidden", document.body.appendChild(o)), o;
|
|
31
42
|
}
|
|
32
|
-
function
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
const n = getComputedStyle(
|
|
43
|
+
function i(c) {
|
|
44
|
+
const e = u();
|
|
45
|
+
e.style.color = c;
|
|
46
|
+
const n = getComputedStyle(e).color.match(/\d+/g);
|
|
36
47
|
if (!n) return "#000000";
|
|
37
|
-
const [
|
|
38
|
-
return `#${((1 << 24) + (
|
|
48
|
+
const [t, s, m] = n.map(Number);
|
|
49
|
+
return `#${((1 << 24) + (t << 16) + (s << 8) + m).toString(16).slice(1)}`;
|
|
39
50
|
}
|
|
40
|
-
function
|
|
41
|
-
if (typeof document > "u")
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
function y() {
|
|
52
|
+
if (typeof document > "u")
|
|
53
|
+
return {
|
|
54
|
+
background: "#ffffff",
|
|
55
|
+
foreground: "#000000",
|
|
56
|
+
primary: "#6366f1",
|
|
57
|
+
primaryContent: "#ffffff",
|
|
58
|
+
secondary: "#f000b8",
|
|
59
|
+
accent: "#37cdbe",
|
|
60
|
+
info: "#3abff8",
|
|
61
|
+
success: "#36d399",
|
|
62
|
+
warning: "#fbbd23",
|
|
63
|
+
error: "#f87272"
|
|
64
|
+
};
|
|
65
|
+
const c = getComputedStyle(document.documentElement), e = (r, n) => {
|
|
66
|
+
const t = c.getPropertyValue(r).trim();
|
|
67
|
+
return t ? i(t) : n;
|
|
45
68
|
};
|
|
46
69
|
return {
|
|
47
|
-
background:
|
|
48
|
-
foreground:
|
|
49
|
-
primary:
|
|
50
|
-
primaryContent:
|
|
51
|
-
secondary:
|
|
52
|
-
accent:
|
|
53
|
-
info:
|
|
54
|
-
success:
|
|
55
|
-
warning:
|
|
56
|
-
error:
|
|
70
|
+
background: e("--color-base-100", "#ffffff"),
|
|
71
|
+
foreground: e("--color-base-content", "#000000"),
|
|
72
|
+
primary: e("--color-primary", "#6366f1"),
|
|
73
|
+
primaryContent: e("--color-primary-content", "#ffffff"),
|
|
74
|
+
secondary: e("--color-secondary", "#f000b8"),
|
|
75
|
+
accent: e("--color-accent", "#37cdbe"),
|
|
76
|
+
info: e("--color-info", "#3abff8"),
|
|
77
|
+
success: e("--color-success", "#36d399"),
|
|
78
|
+
warning: e("--color-warning", "#fbbd23"),
|
|
79
|
+
error: e("--color-error", "#f87272")
|
|
57
80
|
};
|
|
58
81
|
}
|
|
59
|
-
function k() {
|
|
60
|
-
return typeof window > "u" ? "light" : window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
61
|
-
}
|
|
62
|
-
function C() {
|
|
63
|
-
return typeof document > "u" ? null : document.documentElement.getAttribute("data-theme");
|
|
64
|
-
}
|
|
65
|
-
function x() {
|
|
66
|
-
return b() ? S() : E();
|
|
67
|
-
}
|
|
68
|
-
function S() {
|
|
69
|
-
const e = T(), [t, s] = u(a), n = g(!1);
|
|
70
|
-
return f(() => {
|
|
71
|
-
requestAnimationFrame(() => {
|
|
72
|
-
s(h());
|
|
73
|
-
}), n.current = !0;
|
|
74
|
-
}, [e.resolvedTheme]), l(() => ({
|
|
75
|
-
theme: e.theme,
|
|
76
|
-
resolvedTheme: e.resolvedTheme,
|
|
77
|
-
isDark: e.isDark,
|
|
78
|
-
setTheme: e.setTheme,
|
|
79
|
-
toggleTheme: e.toggleTheme,
|
|
80
|
-
colors: t,
|
|
81
|
-
systemTheme: e.systemTheme
|
|
82
|
-
}), [e.theme, e.resolvedTheme, e.isDark, e.setTheme, e.toggleTheme, t, e.systemTheme]);
|
|
83
|
-
}
|
|
84
|
-
function E() {
|
|
85
|
-
const [e, t] = u(!1), [s, n] = u(a);
|
|
86
|
-
return f(() => {
|
|
87
|
-
const r = () => {
|
|
88
|
-
const d = C(), y = k();
|
|
89
|
-
let i = !1;
|
|
90
|
-
d ? i = p.has(d) : i = y === "dark", t(i), requestAnimationFrame(() => {
|
|
91
|
-
n(h());
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
r();
|
|
95
|
-
const c = new MutationObserver(r);
|
|
96
|
-
c.observe(document.documentElement, {
|
|
97
|
-
attributes: !0,
|
|
98
|
-
attributeFilter: ["data-theme", "class"]
|
|
99
|
-
});
|
|
100
|
-
const m = window.matchMedia("(prefers-color-scheme: dark)");
|
|
101
|
-
return m.addEventListener("change", r), () => {
|
|
102
|
-
c.disconnect(), m.removeEventListener("change", r);
|
|
103
|
-
};
|
|
104
|
-
}, []), l(() => ({
|
|
105
|
-
theme: void 0,
|
|
106
|
-
resolvedTheme: void 0,
|
|
107
|
-
isDark: e,
|
|
108
|
-
setTheme: void 0,
|
|
109
|
-
toggleTheme: void 0,
|
|
110
|
-
colors: s,
|
|
111
|
-
systemTheme: void 0
|
|
112
|
-
}), [e, s]);
|
|
113
|
-
}
|
|
114
82
|
export {
|
|
115
|
-
|
|
116
|
-
|
|
83
|
+
h as default,
|
|
84
|
+
y as getThemeColors,
|
|
85
|
+
h as useTheme
|
|
117
86
|
};
|
|
118
87
|
//# sourceMappingURL=useTheme.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTheme.js","sources":["../../src/hooks/useTheme.ts"],"sourcesContent":["import { useEffect, useState, useMemo, useRef } from 'react'\nimport { useHasThemeProvider, useThemeContext, type ThemeColors } from '../providers/ThemeProvider'\n\nexport type { ThemeColors }\n\n// Common dark themes in DaisyUI\nconst DARK_THEMES = new Set([\n 'dark', 'synthwave', 'halloween', 'forest', 'black', 'luxury', 'dracula',\n 'business', 'night', 'coffee', 'dim', 'sunset'\n])\n\nexport interface UseThemeReturn {\n /** The theme setting (what user selected). Only available with ThemeProvider. */\n theme: string | undefined\n /** The actual applied theme. Only available with ThemeProvider. */\n resolvedTheme: string | undefined\n /** Whether dark mode is active */\n isDark: boolean\n /** Set the theme. Only available with ThemeProvider. */\n setTheme: ((theme: string) => void) | undefined\n /** Toggle between light and dark. Only available with ThemeProvider. */\n toggleTheme: (() => void) | undefined\n /** Computed theme colors as hex values. Computed asynchronously after theme changes. */\n colors: ThemeColors\n /** The system preference. Only available with ThemeProvider. */\n systemTheme: 'light' | 'dark' | undefined\n}\n\nconst SSR_COLORS: ThemeColors = {\n background: '#ffffff',\n foreground: '#000000',\n primary: '#6366f1',\n primaryContent: '#ffffff',\n secondary: '#f000b8',\n accent: '#37cdbe',\n info: '#3abff8',\n success: '#36d399',\n warning: '#fbbd23',\n error: '#f87272',\n}\n\n// Persistent hidden element for DOM-based color conversion\nlet colorProbe: HTMLSpanElement | null = null\n\nfunction getColorProbe(): HTMLSpanElement {\n if (!colorProbe) {\n colorProbe = document.createElement('span')\n colorProbe.style.position = 'absolute'\n colorProbe.style.visibility = 'hidden'\n colorProbe.style.pointerEvents = 'none'\n colorProbe.style.width = '0'\n colorProbe.style.height = '0'\n colorProbe.style.overflow = 'hidden'\n document.body.appendChild(colorProbe)\n }\n return colorProbe\n}\n\n/** Convert any CSS color (including oklch) to hex via getComputedStyle */\nfunction colorToHex(color: string): string {\n const probe = getColorProbe()\n probe.style.color = color\n const computed = getComputedStyle(probe).color\n // getComputedStyle returns rgb(r, g, b) or rgba(r, g, b, a)\n const match = computed.match(/\\d+/g)\n if (!match) return '#000000'\n const [r, g, b] = match.map(Number)\n return `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}`\n}\n\nfunction computeThemeColors(): ThemeColors {\n if (typeof document === 'undefined') return SSR_COLORS\n\n const style = getComputedStyle(document.documentElement)\n const getColor = (varName: string, fallback: string): string => {\n const value = style.getPropertyValue(varName).trim()\n return value ? colorToHex(value) : fallback\n }\n\n return {\n background: getColor('--color-base-100', '#ffffff'),\n foreground: getColor('--color-base-content', '#000000'),\n primary: getColor('--color-primary', '#6366f1'),\n primaryContent: getColor('--color-primary-content', '#ffffff'),\n secondary: getColor('--color-secondary', '#f000b8'),\n accent: getColor('--color-accent', '#37cdbe'),\n info: getColor('--color-info', '#3abff8'),\n success: getColor('--color-success', '#36d399'),\n warning: getColor('--color-warning', '#fbbd23'),\n error: getColor('--color-error', '#f87272'),\n }\n}\n\nfunction getSystemTheme(): 'light' | 'dark' {\n if (typeof window === 'undefined') return 'light'\n return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'\n}\n\nfunction getCurrentTheme(): string | null {\n if (typeof document === 'undefined') return null\n return document.documentElement.getAttribute('data-theme')\n}\n\n/**\n * Hook to detect current theme and get computed colors.\n *\n * When used within a ThemeProvider, returns full theme control including\n * setTheme, theme selection, and resolved theme.\n *\n * When used standalone (without ThemeProvider), provides read-only access\n * to isDark and colors based on the current data-theme attribute and\n * system preference.\n *\n * Colors are computed asynchronously after mount and theme changes,\n * using DOM-based color conversion (no canvas).\n *\n * @example\n * // With ThemeProvider (full control)\n * const { theme, setTheme, resolvedTheme, isDark, colors } = useTheme()\n * setTheme('dark')\n *\n * @example\n * // Without ThemeProvider (read-only)\n * const { isDark, colors } = useTheme()\n * // colors.primary, colors.foreground, etc.\n */\nexport function useTheme(): UseThemeReturn {\n const hasProvider = useHasThemeProvider()\n\n if (hasProvider) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useThemeWithProvider()\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useThemeStandalone()\n}\n\n/**\n * Theme hook when ThemeProvider is present.\n */\nfunction useThemeWithProvider(): UseThemeReturn {\n const context = useThemeContext()\n const [colors, setColors] = useState<ThemeColors>(SSR_COLORS)\n const mountedRef = useRef(false)\n\n useEffect(() => {\n // On mount and when theme changes, compute colors after CSS has applied\n requestAnimationFrame(() => {\n setColors(computeThemeColors())\n })\n mountedRef.current = true\n }, [context.resolvedTheme])\n\n return useMemo(() => ({\n theme: context.theme,\n resolvedTheme: context.resolvedTheme,\n isDark: context.isDark,\n setTheme: context.setTheme,\n toggleTheme: context.toggleTheme,\n colors,\n systemTheme: context.systemTheme,\n }), [context.theme, context.resolvedTheme, context.isDark, context.setTheme, context.toggleTheme, colors, context.systemTheme])\n}\n\n/**\n * Standalone theme detection (no ThemeProvider)\n */\nfunction useThemeStandalone(): UseThemeReturn {\n const [isDark, setIsDark] = useState(false)\n const [colors, setColors] = useState<ThemeColors>(SSR_COLORS)\n\n useEffect(() => {\n const updateTheme = () => {\n const currentTheme = getCurrentTheme()\n const systemTheme = getSystemTheme()\n\n let dark = false\n if (currentTheme) {\n dark = DARK_THEMES.has(currentTheme)\n } else {\n dark = systemTheme === 'dark'\n }\n\n setIsDark(dark)\n\n // Compute colors after CSS has applied\n requestAnimationFrame(() => {\n setColors(computeThemeColors())\n })\n }\n\n updateTheme()\n\n const observer = new MutationObserver(updateTheme)\n observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: ['data-theme', 'class']\n })\n\n const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')\n mediaQuery.addEventListener('change', updateTheme)\n\n return () => {\n observer.disconnect()\n mediaQuery.removeEventListener('change', updateTheme)\n }\n }, [])\n\n return useMemo(() => ({\n theme: undefined,\n resolvedTheme: undefined,\n isDark,\n setTheme: undefined,\n toggleTheme: undefined,\n colors,\n systemTheme: undefined,\n }), [isDark, colors])\n}\n\nexport default useTheme\n"],"names":["DARK_THEMES","SSR_COLORS","colorProbe","getColorProbe","colorToHex","color","probe","match","g","b","computeThemeColors","style","getColor","varName","fallback","value","getSystemTheme","getCurrentTheme","useTheme","useHasThemeProvider","useThemeWithProvider","useThemeStandalone","context","useThemeContext","colors","setColors","useState","mountedRef","useRef","useEffect","useMemo","isDark","setIsDark","updateTheme","currentTheme","systemTheme","dark","observer","mediaQuery"],"mappings":";;AAMA,MAAMA,wBAAkB,IAAI;AAAA,EAC1B;AAAA,EAAQ;AAAA,EAAa;AAAA,EAAa;AAAA,EAAU;AAAA,EAAS;AAAA,EAAU;AAAA,EAC/D;AAAA,EAAY;AAAA,EAAS;AAAA,EAAU;AAAA,EAAO;AACxC,CAAC,GAmBKC,IAA0B;AAAA,EAC9B,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,SAAS;AAAA,EACT,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,SAAS;AAAA,EACT,SAAS;AAAA,EACT,OAAO;AACT;AAGA,IAAIC,IAAqC;AAEzC,SAASC,IAAiC;AACxC,SAAKD,MACHA,IAAa,SAAS,cAAc,MAAM,GAC1CA,EAAW,MAAM,WAAW,YAC5BA,EAAW,MAAM,aAAa,UAC9BA,EAAW,MAAM,gBAAgB,QACjCA,EAAW,MAAM,QAAQ,KACzBA,EAAW,MAAM,SAAS,KAC1BA,EAAW,MAAM,WAAW,UAC5B,SAAS,KAAK,YAAYA,CAAU,IAE/BA;AACT;AAGA,SAASE,EAAWC,GAAuB;AACzC,QAAMC,IAAQH,EAAA;AACd,EAAAG,EAAM,MAAM,QAAQD;AAGpB,QAAME,IAFW,iBAAiBD,CAAK,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AAS,WAAA,GACTC,EAAW,oBAAoB,UAAUL,CAAW;AAAA,IACtD;AAAA,EACF,GAAG,CAAA,CAAE,GAEEH,EAAQ,OAAO;AAAA,IACpB,OAAO;AAAA,IACP,eAAe;AAAA,IACf,QAAAC;AAAA,IACA,UAAU;AAAA,IACV,aAAa;AAAA,IACb,QAAAP;AAAA,IACA,aAAa;AAAA,EAAA,IACX,CAACO,GAAQP,CAAM,CAAC;AACtB;"}
|
|
1
|
+
{"version":3,"file":"useTheme.js","sources":["../../src/hooks/useTheme.ts"],"sourcesContent":["import { useHasThemeProvider, useThemeContext, type ThemeColors } from '../providers/ThemeProvider'\n\nexport type { ThemeColors }\n\n// Common dark themes in DaisyUI\nconst DARK_THEMES = new Set([\n 'dark', 'synthwave', 'halloween', 'forest', 'black', 'luxury', 'dracula',\n 'business', 'night', 'coffee', 'dim', 'sunset'\n])\n\nexport interface UseThemeReturn {\n /** The theme setting (what user selected). Only available with ThemeProvider. */\n theme: string | undefined\n /** Whether dark mode is active */\n isDark: boolean\n /** Set the theme. Only available with ThemeProvider. */\n setTheme: ((theme: string) => void) | undefined\n /** Toggle between light and dark. Only available with ThemeProvider. */\n toggleTheme: (() => void) | undefined\n /** The system preference. Only available with ThemeProvider. */\n systemTheme: 'light' | 'dark' | undefined\n}\n\n/**\n * Hook to detect and control the current theme.\n *\n * When used within a ThemeProvider, returns full theme control.\n * When used standalone, provides read-only isDark based on data-theme or system preference.\n *\n * Does NOT compute colors — use getThemeColors() where you need hex values.\n *\n * @example\n * const { isDark, setTheme, toggleTheme } = useTheme()\n */\nexport function useTheme(): UseThemeReturn {\n const hasProvider = useHasThemeProvider()\n\n if (hasProvider) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const context = useThemeContext()\n return {\n theme: context.theme,\n isDark: context.isDark,\n setTheme: context.setTheme,\n toggleTheme: context.toggleTheme,\n systemTheme: context.systemTheme,\n }\n }\n\n // Fallback when used outside ThemeProvider — read from DOM\n const theme = typeof document !== 'undefined'\n ? document.documentElement.getAttribute('data-theme') ?? undefined\n : undefined\n const systemDark = typeof window !== 'undefined'\n && window.matchMedia('(prefers-color-scheme: dark)').matches\n const isDark = theme ? DARK_THEMES.has(theme) : systemDark\n\n return {\n theme,\n isDark,\n setTheme: (t: string) => document.documentElement.setAttribute('data-theme', t),\n toggleTheme: () => {\n const current = document.documentElement.getAttribute('data-theme')\n const currentIsDark = current ? DARK_THEMES.has(current) : systemDark\n document.documentElement.setAttribute('data-theme', currentIsDark ? 'light' : 'dark')\n },\n systemTheme: (systemDark ? 'dark' : 'light') as 'light' | 'dark',\n }\n}\n\n// --- Color utilities (for components that need hex values) ---\n\n/** Persistent hidden element for DOM-based color conversion */\nlet colorProbe: HTMLSpanElement | null = null\n\nfunction getColorProbe(): HTMLSpanElement {\n if (!colorProbe) {\n colorProbe = document.createElement('span')\n colorProbe.style.position = 'absolute'\n colorProbe.style.visibility = 'hidden'\n colorProbe.style.pointerEvents = 'none'\n colorProbe.style.width = '0'\n colorProbe.style.height = '0'\n colorProbe.style.overflow = 'hidden'\n document.body.appendChild(colorProbe)\n }\n return colorProbe\n}\n\n/** Convert any CSS color (including oklch) to hex via getComputedStyle */\nfunction colorToHex(color: string): string {\n const probe = getColorProbe()\n probe.style.color = color\n const computed = getComputedStyle(probe).color\n const match = computed.match(/\\d+/g)\n if (!match) return '#000000'\n const [r, g, b] = match.map(Number)\n return `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}`\n}\n\n/**\n * Compute current DaisyUI theme colors as hex values.\n * Call this on demand when you need hex colors (e.g., for canvas, xterm).\n * Not reactive — call it inside useEffect after theme changes.\n */\nexport function getThemeColors(): ThemeColors {\n if (typeof document === 'undefined') {\n return {\n background: '#ffffff',\n foreground: '#000000',\n primary: '#6366f1',\n primaryContent: '#ffffff',\n secondary: '#f000b8',\n accent: '#37cdbe',\n info: '#3abff8',\n success: '#36d399',\n warning: '#fbbd23',\n error: '#f87272',\n }\n }\n\n const style = getComputedStyle(document.documentElement)\n const getColor = (varName: string, fallback: string): string => {\n const value = style.getPropertyValue(varName).trim()\n return value ? colorToHex(value) : fallback\n }\n\n return {\n background: getColor('--color-base-100', '#ffffff'),\n foreground: getColor('--color-base-content', '#000000'),\n primary: getColor('--color-primary', '#6366f1'),\n primaryContent: getColor('--color-primary-content', '#ffffff'),\n secondary: getColor('--color-secondary', '#f000b8'),\n accent: getColor('--color-accent', '#37cdbe'),\n info: getColor('--color-info', '#3abff8'),\n success: getColor('--color-success', '#36d399'),\n warning: getColor('--color-warning', '#fbbd23'),\n error: getColor('--color-error', '#f87272'),\n }\n}\n\nexport default useTheme\n"],"names":["DARK_THEMES","useTheme","useHasThemeProvider","context","useThemeContext","theme","systemDark","isDark","current","currentIsDark","colorProbe","getColorProbe","colorToHex","color","probe","match","r","g","b","getThemeColors","style","getColor","varName","fallback","value"],"mappings":";AAKA,MAAMA,wBAAkB,IAAI;AAAA,EAC1B;AAAA,EAAQ;AAAA,EAAa;AAAA,EAAa;AAAA,EAAU;AAAA,EAAS;AAAA,EAAU;AAAA,EAC/D;AAAA,EAAY;AAAA,EAAS;AAAA,EAAU;AAAA,EAAO;AACxC,CAAC;AA0BM,SAASC,IAA2B;AAGzC,MAFoBC,EAAA,GAEH;AAEf,UAAMC,IAAUC,EAAA;AAChB,WAAO;AAAA,MACL,OAAOD,EAAQ;AAAA,MACf,QAAQA,EAAQ;AAAA,MAChB,UAAUA,EAAQ;AAAA,MAClB,aAAaA,EAAQ;AAAA,MACrB,aAAaA,EAAQ;AAAA,IAAA;AAAA,EAEzB;AAGA,QAAME,IAAQ,OAAO,WAAa,MAC9B,SAAS,gBAAgB,aAAa,YAAY,KAAK,SACvD,QACEC,IAAa,OAAO,SAAW,OAChC,OAAO,WAAW,8BAA8B,EAAE,SACjDC,IAASF,IAAQL,EAAY,IAAIK,CAAK,IAAIC;AAEhD,SAAO;AAAA,IACL,OAAAD;AAAA,IACA,QAAAE;AAAA,IACA,UAAU,CAAC,MAAc,SAAS,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QJ,EAAM,iBAAiBE,CAAO,EAAE,KAAA;AAC9C,WAAOE,IAAQZ,EAAWY,CAAK,IAAID;AAAA,EACrC;AAEA,SAAO;AAAA,IACL,YAAYF,EAAS,oBAAoB,SAAS;AAAA,IAClD,YAAYA,EAAS,wBAAwB,SAAS;AAAA,IACtD,SAASA,EAAS,mBAAmB,SAAS;AAAA,IAC9C,gBAAgBA,EAAS,2BAA2B,SAAS;AAAA,IAC7D,WAAWA,EAAS,qBAAqB,SAAS;AAAA,IAClD,QAAQA,EAAS,kBAAkB,SAAS;AAAA,IAC5C,MAAMA,EAAS,gBAAgB,SAAS;AAAA,IACxC,SAASA,EAAS,mBAAmB,SAAS;AAAA,IAC9C,SAASA,EAAS,mBAAmB,SAAS;AAAA,IAC9C,OAAOA,EAAS,iBAAiB,SAAS;AAAA,EAAA;AAE9C;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -220,5 +220,5 @@ export { useKeyPress, useKeyPressCallback } from './hooks/useKeyPress';
|
|
|
220
220
|
export type { UseKeyPressOptions } from './hooks/useKeyPress';
|
|
221
221
|
export { useWindowSize } from './hooks/useWindowSize';
|
|
222
222
|
export type { WindowSize } from './hooks/useWindowSize';
|
|
223
|
-
export { useTheme } from './hooks/useTheme';
|
|
223
|
+
export { useTheme, getThemeColors } from './hooks/useTheme';
|
|
224
224
|
export type { UseThemeReturn, ThemeColors } from './hooks/useTheme';
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Affix as e } from "./components/Affix.js";
|
|
2
2
|
import { AspectRatio as p } from "./components/AspectRatio.js";
|
|
3
|
-
import { Anchor as
|
|
3
|
+
import { Anchor as f } from "./components/Anchor.js";
|
|
4
4
|
import { Alert as a } from "./components/Alert.js";
|
|
5
5
|
import { Autocomplete as n } from "./components/Autocomplete.js";
|
|
6
6
|
import { Avatar as u, AvatarGroup as l } from "./components/Avatar.js";
|
|
7
7
|
import { Badge as C } from "./components/Badge.js";
|
|
8
8
|
import { Breadcrumb as g } from "./components/Breadcrumb.js";
|
|
9
9
|
import { Button as S } from "./components/Button.js";
|
|
10
|
-
import { SizeContext as
|
|
10
|
+
import { SizeContext as P, SizeProvider as k, useSize as v } from "./contexts/SizeContext.js";
|
|
11
11
|
import { CopyButton as D } from "./components/CopyButton.js";
|
|
12
12
|
import { Checkbox as B } from "./components/Checkbox.js";
|
|
13
13
|
import { Chat as w } from "./components/Chat.js";
|
|
@@ -23,14 +23,14 @@ import { ContextMenu as Z } from "./components/ContextMenu.js";
|
|
|
23
23
|
import { Countdown as $ } from "./components/Countdown.js";
|
|
24
24
|
import { DatePicker as ro } from "./components/DatePicker.js";
|
|
25
25
|
import { DateOfBirth as to, dateOfBirthRequired as po } from "./components/DateOfBirth.js";
|
|
26
|
-
import { MonthCalendar as
|
|
26
|
+
import { MonthCalendar as fo } from "./components/MonthCalendar.js";
|
|
27
27
|
import { WeekCalendar as ao } from "./components/WeekCalendar.js";
|
|
28
28
|
import { Descriptions as no } from "./components/Descriptions.js";
|
|
29
29
|
import { Diff as uo } from "./components/Diff.js";
|
|
30
30
|
import { Dock as Co } from "./components/Dock.js";
|
|
31
31
|
import { Divider as go } from "./components/Divider.js";
|
|
32
32
|
import { Drawer as So } from "./components/Drawer.js";
|
|
33
|
-
import { ResponsiveDrawer as
|
|
33
|
+
import { ResponsiveDrawer as Po } from "./components/ResponsiveDrawer.js";
|
|
34
34
|
import { Fieldset as vo } from "./components/Fieldset.js";
|
|
35
35
|
import { FileInput as Do } from "./components/FileInput.js";
|
|
36
36
|
import { Filter as Bo } from "./components/Filter.js";
|
|
@@ -47,14 +47,14 @@ import { Empty as Zo } from "./components/Empty.js";
|
|
|
47
47
|
import { Input as $o } from "./components/Input.js";
|
|
48
48
|
import { InputNumber as rr } from "./components/InputNumber.js";
|
|
49
49
|
import { Join as tr } from "./components/Join.js";
|
|
50
|
-
import { Kbd as
|
|
50
|
+
import { Kbd as mr } from "./components/Kbd.js";
|
|
51
51
|
import { Layout as xr, useSiderContext as ar } from "./components/Layout.js";
|
|
52
52
|
import { List as nr } from "./components/List.js";
|
|
53
53
|
import { Loading as ur } from "./components/Loading.js";
|
|
54
54
|
import { Mask as dr } from "./components/Mask.js";
|
|
55
55
|
import { Masonry as cr } from "./components/Masonry.js";
|
|
56
56
|
import { Mention as Tr } from "./components/Mention.js";
|
|
57
|
-
import { Menu as
|
|
57
|
+
import { Menu as hr } from "./components/Menu.js";
|
|
58
58
|
import { Browser as kr } from "./components/Browser.js";
|
|
59
59
|
import { Code as Rr } from "./components/Code.js";
|
|
60
60
|
import { Phone as br } from "./components/Phone.js";
|
|
@@ -73,7 +73,7 @@ import { RadialProgress as Zr } from "./components/RadialProgress.js";
|
|
|
73
73
|
import { Range as $r } from "./components/Range.js";
|
|
74
74
|
import { Rating as re } from "./components/Rating.js";
|
|
75
75
|
import { Result as te } from "./components/Result.js";
|
|
76
|
-
import { Select as
|
|
76
|
+
import { Select as me } from "./components/Select.js";
|
|
77
77
|
import { Segmented as xe } from "./components/Segmented.js";
|
|
78
78
|
import { Skeleton as se } from "./components/Skeleton.js";
|
|
79
79
|
import { Space as ie } from "./components/Space.js";
|
|
@@ -81,7 +81,7 @@ import { Splitter as le } from "./components/Splitter.js";
|
|
|
81
81
|
import { Stats as Ce } from "./components/Stat.js";
|
|
82
82
|
import { Status as ge } from "./components/Status.js";
|
|
83
83
|
import { Steps as Se } from "./components/Steps.js";
|
|
84
|
-
import { Table as
|
|
84
|
+
import { Table as Pe } from "./components/Table.js";
|
|
85
85
|
import { Tabs as ve } from "./components/Tabs.js";
|
|
86
86
|
import { Textarea as De } from "./components/Textarea.js";
|
|
87
87
|
import { TextRotate as Be } from "./components/TextRotate.js";
|
|
@@ -98,34 +98,34 @@ import { Tree as Ze } from "./components/Tree.js";
|
|
|
98
98
|
import { TreeSelect as $e, TreeSelectComponent as ot } from "./components/TreeSelect.js";
|
|
99
99
|
import { Typography as et } from "./components/Typography.js";
|
|
100
100
|
import { Upload as pt } from "./components/Upload.js";
|
|
101
|
-
import { Watermark as
|
|
101
|
+
import { Watermark as ft } from "./components/Watermark.js";
|
|
102
102
|
import { Hide as at, Show as st } from "./components/Responsive.js";
|
|
103
103
|
import { useBreakpoint as it } from "./hooks/useBreakpoint.js";
|
|
104
104
|
import { useDisclosure as lt } from "./hooks/useDisclosure.js";
|
|
105
105
|
import { useClipboard as Ct } from "./hooks/useClipboard.js";
|
|
106
106
|
import { useLocalStorage as gt } from "./hooks/useLocalStorage.js";
|
|
107
107
|
import { useDebounce as St } from "./hooks/useDebounce.js";
|
|
108
|
-
import { useClickOutside as
|
|
108
|
+
import { useClickOutside as Pt } from "./hooks/useClickOutside.js";
|
|
109
109
|
import { usePrevious as vt } from "./hooks/usePrevious.js";
|
|
110
110
|
import { useHover as Dt } from "./hooks/useHover.js";
|
|
111
111
|
import { useKeyPress as Bt, useKeyPressCallback as Ft } from "./hooks/useKeyPress.js";
|
|
112
112
|
import { useWindowSize as yt } from "./hooks/useWindowSize.js";
|
|
113
|
-
import {
|
|
114
|
-
import { default as
|
|
115
|
-
import { default as
|
|
116
|
-
import { default as
|
|
117
|
-
import { default as
|
|
118
|
-
import { default as
|
|
119
|
-
import { default as
|
|
120
|
-
import { default as
|
|
121
|
-
import { default as
|
|
122
|
-
import { default as
|
|
123
|
-
import { default as
|
|
124
|
-
import { useWatch as
|
|
113
|
+
import { getThemeColors as At, useTheme as Lt } from "./hooks/useTheme.js";
|
|
114
|
+
import { default as zt } from "./locale/en-US.js";
|
|
115
|
+
import { default as Wt } from "./locale/en-GB.js";
|
|
116
|
+
import { default as Kt } from "./locale/en-CA.js";
|
|
117
|
+
import { default as Et } from "./locale/zh-CN.js";
|
|
118
|
+
import { default as Jt } from "./locale/es-ES.js";
|
|
119
|
+
import { default as jt } from "./locale/ja-JP.js";
|
|
120
|
+
import { default as Qt } from "./locale/pt-BR.js";
|
|
121
|
+
import { default as Xt } from "./locale/de-DE.js";
|
|
122
|
+
import { default as Zt } from "./locale/fr-FR.js";
|
|
123
|
+
import { default as $t } from "./locale/ko-KR.js";
|
|
124
|
+
import { useWatch as rp } from "react-hook-form";
|
|
125
125
|
export {
|
|
126
126
|
e as Affix,
|
|
127
127
|
a as Alert,
|
|
128
|
-
|
|
128
|
+
f as Anchor,
|
|
129
129
|
p as AspectRatio,
|
|
130
130
|
n as Autocomplete,
|
|
131
131
|
u as Avatar,
|
|
@@ -175,17 +175,17 @@ export {
|
|
|
175
175
|
$o as Input,
|
|
176
176
|
rr as InputNumber,
|
|
177
177
|
tr as Join,
|
|
178
|
-
|
|
178
|
+
mr as Kbd,
|
|
179
179
|
xr as Layout,
|
|
180
180
|
nr as List,
|
|
181
181
|
ur as Loading,
|
|
182
182
|
dr as Mask,
|
|
183
183
|
cr as Masonry,
|
|
184
184
|
Tr as Mention,
|
|
185
|
-
|
|
185
|
+
hr as Menu,
|
|
186
186
|
Hr as MessageManager,
|
|
187
187
|
yr as Modal,
|
|
188
|
-
|
|
188
|
+
fo as MonthCalendar,
|
|
189
189
|
Ar as Navbar,
|
|
190
190
|
Kr as OTPInput,
|
|
191
191
|
Er as Pagination,
|
|
@@ -197,13 +197,13 @@ export {
|
|
|
197
197
|
Xr as Radio,
|
|
198
198
|
$r as Range,
|
|
199
199
|
re as Rating,
|
|
200
|
-
|
|
200
|
+
Po as ResponsiveDrawer,
|
|
201
201
|
te as Result,
|
|
202
202
|
Eo as Row,
|
|
203
203
|
xe as Segmented,
|
|
204
|
-
|
|
204
|
+
me as Select,
|
|
205
205
|
st as Show,
|
|
206
|
-
|
|
206
|
+
P as SizeContext,
|
|
207
207
|
k as SizeProvider,
|
|
208
208
|
se as Skeleton,
|
|
209
209
|
ie as Space,
|
|
@@ -211,7 +211,7 @@ export {
|
|
|
211
211
|
Ce as Stats,
|
|
212
212
|
ge as Status,
|
|
213
213
|
Se as Steps,
|
|
214
|
-
|
|
214
|
+
Pe as Table,
|
|
215
215
|
ve as Tabs,
|
|
216
216
|
ye as Tag,
|
|
217
217
|
Me as TagLiveRegion,
|
|
@@ -230,23 +230,24 @@ export {
|
|
|
230
230
|
ot as TreeSelectComponent,
|
|
231
231
|
et as Typography,
|
|
232
232
|
pt as Upload,
|
|
233
|
-
|
|
233
|
+
ft as Watermark,
|
|
234
234
|
ao as WeekCalendar,
|
|
235
235
|
Fr as Window,
|
|
236
236
|
po as dateOfBirthRequired,
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
237
|
+
Xt as deDE,
|
|
238
|
+
Kt as enCA,
|
|
239
|
+
Wt as enGB,
|
|
240
|
+
zt as enUS,
|
|
241
|
+
Jt as esES,
|
|
242
|
+
Zt as frFR,
|
|
243
|
+
At as getThemeColors,
|
|
244
|
+
jt as jaJP,
|
|
245
|
+
$t as koKR,
|
|
245
246
|
Wr as message,
|
|
246
247
|
Ir as notification,
|
|
247
|
-
|
|
248
|
+
Qt as ptBR,
|
|
248
249
|
it as useBreakpoint,
|
|
249
|
-
|
|
250
|
+
Pt as useClickOutside,
|
|
250
251
|
Ct as useClipboard,
|
|
251
252
|
E as useComponentLocale,
|
|
252
253
|
N as useConfig,
|
|
@@ -263,10 +264,10 @@ export {
|
|
|
263
264
|
vt as usePrevious,
|
|
264
265
|
ar as useSiderContext,
|
|
265
266
|
v as useSize,
|
|
266
|
-
|
|
267
|
+
Lt as useTheme,
|
|
267
268
|
We as useThemeContext,
|
|
268
|
-
|
|
269
|
+
rp as useWatch,
|
|
269
270
|
yt as useWindowSize,
|
|
270
|
-
|
|
271
|
+
Et as zhCN
|
|
271
272
|
};
|
|
272
273
|
//# sourceMappingURL=index.js.map
|
|
@@ -5,12 +5,6 @@ export interface ThemeProviderProps {
|
|
|
5
5
|
defaultTheme?: string;
|
|
6
6
|
/** localStorage key for persisting theme. Set to false to disable persistence. */
|
|
7
7
|
storageKey?: string | false;
|
|
8
|
-
/** Light theme to use when system preference is light */
|
|
9
|
-
lightTheme?: string;
|
|
10
|
-
/** Dark theme to use when system preference is dark */
|
|
11
|
-
darkTheme?: string;
|
|
12
|
-
/** Custom function to determine if a theme is dark */
|
|
13
|
-
isDarkTheme?: (theme: string) => boolean;
|
|
14
8
|
}
|
|
15
9
|
export interface ThemeColors {
|
|
16
10
|
background: string;
|
|
@@ -25,11 +19,9 @@ export interface ThemeColors {
|
|
|
25
19
|
error: string;
|
|
26
20
|
}
|
|
27
21
|
export interface ThemeContextValue {
|
|
28
|
-
/** The theme setting (what user selected
|
|
29
|
-
theme: string;
|
|
30
|
-
/**
|
|
31
|
-
resolvedTheme: string;
|
|
32
|
-
/** Whether the resolved theme is dark */
|
|
22
|
+
/** The theme setting (what user selected) */
|
|
23
|
+
theme: string | undefined;
|
|
24
|
+
/** Whether the current theme is dark */
|
|
33
25
|
isDark: boolean;
|
|
34
26
|
/** Set the theme */
|
|
35
27
|
setTheme: (theme: string) => void;
|
|
@@ -38,10 +30,10 @@ export interface ThemeContextValue {
|
|
|
38
30
|
/** The system preference ("light" or "dark") */
|
|
39
31
|
systemTheme: 'light' | 'dark';
|
|
40
32
|
}
|
|
41
|
-
export declare function ThemeProvider({ children, defaultTheme, storageKey,
|
|
33
|
+
export declare function ThemeProvider({ children, defaultTheme, storageKey, }: ThemeProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
42
34
|
/**
|
|
43
35
|
* Hook to access theme context.
|
|
44
|
-
*
|
|
36
|
+
* Works with or without ThemeProvider.
|
|
45
37
|
*/
|
|
46
38
|
export declare function useThemeContext(): ThemeContextValue;
|
|
47
39
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
3
|
-
const
|
|
1
|
+
import { jsx as E } from "react/jsx-runtime";
|
|
2
|
+
import { useState as l, useEffect as a, useCallback as f, useMemo as p, createContext as S, useContext as k } from "react";
|
|
3
|
+
const w = /* @__PURE__ */ new Set([
|
|
4
4
|
"dark",
|
|
5
5
|
"synthwave",
|
|
6
6
|
"halloween",
|
|
@@ -13,76 +13,73 @@ const C = /* @__PURE__ */ new Set([
|
|
|
13
13
|
"coffee",
|
|
14
14
|
"dim",
|
|
15
15
|
"sunset"
|
|
16
|
-
]),
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (!t || typeof window > "u") return null;
|
|
22
|
-
try {
|
|
23
|
-
return localStorage.getItem(t);
|
|
24
|
-
} catch {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function b(t, f) {
|
|
29
|
-
if (!(!t || typeof window > "u"))
|
|
30
|
-
try {
|
|
31
|
-
localStorage.setItem(t, f);
|
|
32
|
-
} catch {
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function V({
|
|
36
|
-
children: t,
|
|
37
|
-
defaultTheme: f = "system",
|
|
38
|
-
storageKey: r = "asterui-theme",
|
|
39
|
-
lightTheme: c = "light",
|
|
40
|
-
darkTheme: d = "dark",
|
|
41
|
-
isDarkTheme: s
|
|
16
|
+
]), d = S(null);
|
|
17
|
+
function I({
|
|
18
|
+
children: s,
|
|
19
|
+
defaultTheme: v,
|
|
20
|
+
storageKey: t = "asterui-theme"
|
|
42
21
|
}) {
|
|
43
|
-
const [
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
22
|
+
const [o, T] = l(
|
|
23
|
+
() => typeof window < "u" && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"
|
|
24
|
+
), [n, i] = l(() => {
|
|
25
|
+
if (t && typeof window < "u")
|
|
26
|
+
try {
|
|
27
|
+
const e = localStorage.getItem(t);
|
|
28
|
+
if (e) return e;
|
|
29
|
+
} catch {
|
|
30
|
+
}
|
|
31
|
+
return v ?? o;
|
|
32
|
+
}), u = n ? w.has(n) : o === "dark";
|
|
33
|
+
a(() => {
|
|
34
|
+
n ? document.documentElement.setAttribute("data-theme", n) : document.documentElement.removeAttribute("data-theme");
|
|
35
|
+
}, [n]), a(() => {
|
|
47
36
|
if (typeof window > "u") return;
|
|
48
|
-
const e = window.matchMedia("(prefers-color-scheme: dark)"),
|
|
49
|
-
return e.addEventListener("change",
|
|
50
|
-
}, []),
|
|
51
|
-
if (!
|
|
52
|
-
const e = (
|
|
53
|
-
|
|
37
|
+
const e = window.matchMedia("(prefers-color-scheme: dark)"), r = (c) => T(c.matches ? "dark" : "light");
|
|
38
|
+
return e.addEventListener("change", r), () => e.removeEventListener("change", r);
|
|
39
|
+
}, []), a(() => {
|
|
40
|
+
if (!t || typeof window > "u") return;
|
|
41
|
+
const e = (r) => {
|
|
42
|
+
r.key === t && r.newValue && i(r.newValue);
|
|
54
43
|
};
|
|
55
44
|
return window.addEventListener("storage", e), () => window.removeEventListener("storage", e);
|
|
56
|
-
}, [
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
45
|
+
}, [t]);
|
|
46
|
+
const m = f((e) => {
|
|
47
|
+
if (i(e), t)
|
|
48
|
+
try {
|
|
49
|
+
localStorage.setItem(t, e);
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
}, [t]), h = f(() => {
|
|
53
|
+
i((e) => {
|
|
54
|
+
const c = (e ? w.has(e) : o === "dark") ? "light" : "dark";
|
|
55
|
+
if (t)
|
|
56
|
+
try {
|
|
57
|
+
localStorage.setItem(t, c);
|
|
58
|
+
} catch {
|
|
59
|
+
}
|
|
60
|
+
return c;
|
|
63
61
|
});
|
|
64
|
-
}, [
|
|
65
|
-
theme:
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return /* @__PURE__ */ M(w.Provider, { value: L, children: t });
|
|
62
|
+
}, [o, t]), x = p(() => ({
|
|
63
|
+
theme: n,
|
|
64
|
+
isDark: u,
|
|
65
|
+
setTheme: m,
|
|
66
|
+
toggleTheme: h,
|
|
67
|
+
systemTheme: o
|
|
68
|
+
}), [n, u, m, h, o]);
|
|
69
|
+
return /* @__PURE__ */ E(d.Provider, { value: x, children: s });
|
|
73
70
|
}
|
|
74
|
-
function
|
|
75
|
-
const
|
|
76
|
-
if (!
|
|
71
|
+
function g() {
|
|
72
|
+
const s = k(d);
|
|
73
|
+
if (!s)
|
|
77
74
|
throw new Error("useThemeContext must be used within a ThemeProvider");
|
|
78
|
-
return
|
|
75
|
+
return s;
|
|
79
76
|
}
|
|
80
|
-
function
|
|
81
|
-
return
|
|
77
|
+
function D() {
|
|
78
|
+
return k(d) !== null;
|
|
82
79
|
}
|
|
83
80
|
export {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
I as ThemeProvider,
|
|
82
|
+
D as useHasThemeProvider,
|
|
83
|
+
g as useThemeContext
|
|
87
84
|
};
|
|
88
85
|
//# sourceMappingURL=ThemeProvider.js.map
|