@nayhoo/ui 0.10.0 → 0.10.1

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.
Files changed (141) hide show
  1. package/dist/{chunk-DMFP5JKO.mjs → chunk-2BB77GZV.mjs} +3 -3
  2. package/dist/{chunk-T3GW2EMR.mjs → chunk-2TMFRLMM.mjs} +1 -1
  3. package/dist/{chunk-T3GW2EMR.mjs.map → chunk-2TMFRLMM.mjs.map} +1 -1
  4. package/dist/{chunk-ZNKUE6YY.mjs → chunk-3STUDMUG.mjs} +1 -1
  5. package/dist/{chunk-ZNKUE6YY.mjs.map → chunk-3STUDMUG.mjs.map} +1 -1
  6. package/dist/{chunk-QMCIR3TI.mjs → chunk-4C5Q6VK2.mjs} +3 -3
  7. package/dist/{chunk-64TEKDKL.mjs → chunk-52RVZRC4.mjs} +2 -2
  8. package/dist/{chunk-G4YCF3A2.mjs → chunk-AIOSEM6O.mjs} +1 -1
  9. package/dist/{chunk-G4YCF3A2.mjs.map → chunk-AIOSEM6O.mjs.map} +1 -1
  10. package/dist/{chunk-U6MTU5FF.mjs → chunk-BXK6WSNP.mjs} +10 -10
  11. package/dist/chunk-BXK6WSNP.mjs.map +1 -0
  12. package/dist/{chunk-QEBSZEY2.mjs → chunk-HFMY3EF3.mjs} +1 -1
  13. package/dist/{chunk-QEBSZEY2.mjs.map → chunk-HFMY3EF3.mjs.map} +1 -1
  14. package/dist/{chunk-QBPEU3GK.mjs → chunk-JSUIFF36.mjs} +1 -1
  15. package/dist/{chunk-QBPEU3GK.mjs.map → chunk-JSUIFF36.mjs.map} +1 -1
  16. package/dist/{chunk-DC6VQ7BG.mjs → chunk-LF6VSYRD.mjs} +2 -2
  17. package/dist/{chunk-IEZTYE5I.mjs → chunk-M6OYH5UA.mjs} +1 -1
  18. package/dist/{chunk-IEZTYE5I.mjs.map → chunk-M6OYH5UA.mjs.map} +1 -1
  19. package/dist/{chunk-GGJKRS5V.mjs → chunk-PIOIL3MF.mjs} +2 -2
  20. package/dist/{chunk-MDAIXJU2.mjs → chunk-QCTQCZQV.mjs} +1 -1
  21. package/dist/{chunk-MDAIXJU2.mjs.map → chunk-QCTQCZQV.mjs.map} +1 -1
  22. package/dist/{chunk-3HV65JYW.mjs → chunk-RD6HAWH5.mjs} +1 -1
  23. package/dist/{chunk-3HV65JYW.mjs.map → chunk-RD6HAWH5.mjs.map} +1 -1
  24. package/dist/{chunk-HRXZ3ELS.mjs → chunk-SC6WBBXG.mjs} +1 -1
  25. package/dist/{chunk-HRXZ3ELS.mjs.map → chunk-SC6WBBXG.mjs.map} +1 -1
  26. package/dist/{chunk-YO4LZRGU.mjs → chunk-SI36SYJ2.mjs} +1 -1
  27. package/dist/{chunk-YO4LZRGU.mjs.map → chunk-SI36SYJ2.mjs.map} +1 -1
  28. package/dist/{chunk-PGCB7RGD.mjs → chunk-TPPKQCXG.mjs} +1 -1
  29. package/dist/{chunk-PGCB7RGD.mjs.map → chunk-TPPKQCXG.mjs.map} +1 -1
  30. package/dist/{chunk-6UOQ737G.mjs → chunk-UVLWN6WJ.mjs} +1 -1
  31. package/dist/{chunk-6UOQ737G.mjs.map → chunk-UVLWN6WJ.mjs.map} +1 -1
  32. package/dist/{chunk-XX6PQF7O.mjs → chunk-VSQHQBZX.mjs} +1 -1
  33. package/dist/{chunk-XX6PQF7O.mjs.map → chunk-VSQHQBZX.mjs.map} +1 -1
  34. package/dist/{chunk-RYAY35UB.mjs → chunk-WUIQQ7C2.mjs} +2 -2
  35. package/dist/{chunk-IQLI5J2V.mjs → chunk-YZNF3EIN.mjs} +1 -1
  36. package/dist/{chunk-IQLI5J2V.mjs.map → chunk-YZNF3EIN.mjs.map} +1 -1
  37. package/dist/components/avatar.css +1 -1
  38. package/dist/components/avatar.css.map +1 -1
  39. package/dist/components/avatar.js.map +1 -1
  40. package/dist/components/avatar.mjs +1 -1
  41. package/dist/components/badge.css +1 -1
  42. package/dist/components/badge.css.map +1 -1
  43. package/dist/components/badge.js.map +1 -1
  44. package/dist/components/badge.mjs +1 -1
  45. package/dist/components/button.css +2 -2
  46. package/dist/components/button.css.map +1 -1
  47. package/dist/components/button.js.map +1 -1
  48. package/dist/components/button.mjs +4 -4
  49. package/dist/components/checkbox.css +1 -1
  50. package/dist/components/checkbox.css.map +1 -1
  51. package/dist/components/checkbox.js.map +1 -1
  52. package/dist/components/checkbox.mjs +1 -1
  53. package/dist/components/dropdown-menu.css +2 -2
  54. package/dist/components/dropdown-menu.css.map +1 -1
  55. package/dist/components/dropdown-menu.js.map +1 -1
  56. package/dist/components/dropdown-menu.mjs +3 -3
  57. package/dist/components/flex.css +1 -1
  58. package/dist/components/flex.css.map +1 -1
  59. package/dist/components/flex.js.map +1 -1
  60. package/dist/components/flex.mjs +2 -2
  61. package/dist/components/grid.css +1 -1
  62. package/dist/components/grid.css.map +1 -1
  63. package/dist/components/grid.js.map +1 -1
  64. package/dist/components/grid.mjs +1 -1
  65. package/dist/components/heading.css +1 -1
  66. package/dist/components/heading.css.map +1 -1
  67. package/dist/components/heading.js.map +1 -1
  68. package/dist/components/heading.mjs +2 -2
  69. package/dist/components/icon-button.css +2 -2
  70. package/dist/components/icon-button.css.map +1 -1
  71. package/dist/components/icon-button.js.map +1 -1
  72. package/dist/components/icon-button.mjs +4 -4
  73. package/dist/components/label.css +1 -1
  74. package/dist/components/label.css.map +1 -1
  75. package/dist/components/label.js.map +1 -1
  76. package/dist/components/label.mjs +1 -1
  77. package/dist/components/link.css +1 -1
  78. package/dist/components/link.css.map +1 -1
  79. package/dist/components/link.js.map +1 -1
  80. package/dist/components/link.mjs +1 -1
  81. package/dist/components/menu.css +2 -2
  82. package/dist/components/menu.css.map +1 -1
  83. package/dist/components/menu.js.map +1 -1
  84. package/dist/components/menu.mjs +3 -3
  85. package/dist/components/paragraph.css +1 -1
  86. package/dist/components/paragraph.css.map +1 -1
  87. package/dist/components/paragraph.js.map +1 -1
  88. package/dist/components/paragraph.mjs +1 -1
  89. package/dist/components/popover.css +1 -1
  90. package/dist/components/popover.css.map +1 -1
  91. package/dist/components/popover.js.map +1 -1
  92. package/dist/components/popover.mjs +1 -1
  93. package/dist/components/select.css +3 -3
  94. package/dist/components/select.css.map +1 -1
  95. package/dist/components/select.js.map +1 -1
  96. package/dist/components/select.mjs +5 -5
  97. package/dist/components/skeleton.css +1 -1
  98. package/dist/components/skeleton.css.map +1 -1
  99. package/dist/components/skeleton.js.map +1 -1
  100. package/dist/components/skeleton.mjs +1 -1
  101. package/dist/components/spinner.css +1 -1
  102. package/dist/components/spinner.css.map +1 -1
  103. package/dist/components/spinner.js.map +1 -1
  104. package/dist/components/spinner.mjs +2 -2
  105. package/dist/components/switch.css +1 -1
  106. package/dist/components/switch.css.map +1 -1
  107. package/dist/components/switch.js.map +1 -1
  108. package/dist/components/switch.mjs +1 -1
  109. package/dist/components/text-field.css +1 -1
  110. package/dist/components/text-field.css.map +1 -1
  111. package/dist/components/text-field.js.map +1 -1
  112. package/dist/components/text-field.mjs +1 -1
  113. package/dist/components/text.css +1 -1
  114. package/dist/components/text.css.map +1 -1
  115. package/dist/components/text.js.map +1 -1
  116. package/dist/components/text.mjs +2 -2
  117. package/dist/components/tooltip.css +1 -1
  118. package/dist/components/tooltip.css.map +1 -1
  119. package/dist/components/tooltip.js.map +1 -1
  120. package/dist/components/tooltip.mjs +4 -4
  121. package/dist/providers/index.css +8 -8
  122. package/dist/providers/index.css.map +1 -1
  123. package/dist/providers/index.d.mts +23 -14
  124. package/dist/providers/index.d.ts +23 -14
  125. package/dist/providers/index.js +151 -77
  126. package/dist/providers/index.js.map +1 -1
  127. package/dist/providers/index.mjs +159 -91
  128. package/dist/providers/index.mjs.map +1 -1
  129. package/dist/theme/index.css +20 -20
  130. package/dist/theme/index.css.map +1 -1
  131. package/dist/theme/index.js.map +1 -1
  132. package/dist/theme/index.mjs +15 -15
  133. package/dist/theme/index.mjs.map +1 -1
  134. package/package.json +1 -1
  135. package/dist/chunk-U6MTU5FF.mjs.map +0 -1
  136. /package/dist/{chunk-DMFP5JKO.mjs.map → chunk-2BB77GZV.mjs.map} +0 -0
  137. /package/dist/{chunk-QMCIR3TI.mjs.map → chunk-4C5Q6VK2.mjs.map} +0 -0
  138. /package/dist/{chunk-64TEKDKL.mjs.map → chunk-52RVZRC4.mjs.map} +0 -0
  139. /package/dist/{chunk-DC6VQ7BG.mjs.map → chunk-LF6VSYRD.mjs.map} +0 -0
  140. /package/dist/{chunk-GGJKRS5V.mjs.map → chunk-PIOIL3MF.mjs.map} +0 -0
  141. /package/dist/{chunk-RYAY35UB.mjs.map → chunk-WUIQQ7C2.mjs.map} +0 -0
@@ -1,29 +1,38 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
- import react__default from 'react';
4
3
  import * as ToastPrimitives from '@radix-ui/react-toast';
5
4
 
6
5
  type Theme = "light" | "dark" | "system";
7
6
 
8
- type ResolvedTheme = Exclude<Theme, "system">;
9
- type ThemeContextProps = {
10
- theme: Theme;
11
- setTheme: react__default.Dispatch<react__default.SetStateAction<Theme>>;
12
- resolvedTheme: ResolvedTheme;
7
+ type SystemTheme = Exclude<Theme, "system">;
8
+
9
+ interface ScriptProps extends react.DetailedHTMLProps<react.ScriptHTMLAttributes<HTMLScriptElement>, HTMLScriptElement> {
10
+ }
11
+ interface UseThemeProps {
12
+ /** List of all available theme names */
13
13
  themes: Theme[];
14
- };
15
- declare const ThemeContext: react__default.Context<ThemeContextProps>;
16
- type ThemeProviderProps = {
17
- children: react__default.ReactNode;
18
- };
19
- declare const ThemeProvider: ({ children }: ThemeProviderProps) => react_jsx_runtime.JSX.Element;
14
+ /** Update the theme */
15
+ setTheme: (value: Theme) => void;
16
+ /** Active theme name */
17
+ theme?: Theme | undefined;
18
+ /** If the active theme is "system", this returns whether the system preference resolved to "dark" or "light". Otherwise, identical to `theme` */
19
+ resolvedTheme?: Theme | undefined;
20
+ /** Returns the System theme preference ("dark" or "light"), regardless what the active theme is */
21
+ systemTheme?: SystemTheme | undefined;
22
+ }
23
+ interface ThemeProviderProps extends react.PropsWithChildren {
24
+ /** Props to pass the inline script */
25
+ scriptProps?: ScriptProps;
26
+ }
27
+ declare const useTheme: () => UseThemeProps;
28
+ declare const ThemeProvider: (props: ThemeProviderProps) => react_jsx_runtime.JSX.Element;
20
29
 
21
30
  type AddToastPayload = Omit<Toast, "status">;
22
31
  type ToastContextProps = ((payload: AddToastPayload) => void) & {
23
32
  error: (payload: AddToastPayload) => void;
24
33
  success: (payload: AddToastPayload) => void;
25
34
  };
26
- declare const ToastContext: react.Context<ToastContextProps>;
35
+ declare const useToast: () => ToastContextProps;
27
36
  declare const ToastProvider: ({ children, ...props }: ToastPrimitives.ToastProviderProps) => react_jsx_runtime.JSX.Element;
28
37
  type Toast = {
29
38
  title?: string;
@@ -36,4 +45,4 @@ declare const Toast: (props: ToastPrimitives.ToastProps & {
36
45
  }) => react_jsx_runtime.JSX.Element;
37
46
  declare const ToastAction: ({ ...props }: Omit<ToastPrimitives.ToastActionProps, "asChild">) => react_jsx_runtime.JSX.Element;
38
47
 
39
- export { ThemeContext, ThemeProvider, ToastAction, ToastContext, ToastProvider };
48
+ export { ThemeProvider, type ThemeProviderProps, ToastAction, ToastProvider, type UseThemeProps, useTheme, useToast };
@@ -1,29 +1,38 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
- import react__default from 'react';
4
3
  import * as ToastPrimitives from '@radix-ui/react-toast';
5
4
 
6
5
  type Theme = "light" | "dark" | "system";
7
6
 
8
- type ResolvedTheme = Exclude<Theme, "system">;
9
- type ThemeContextProps = {
10
- theme: Theme;
11
- setTheme: react__default.Dispatch<react__default.SetStateAction<Theme>>;
12
- resolvedTheme: ResolvedTheme;
7
+ type SystemTheme = Exclude<Theme, "system">;
8
+
9
+ interface ScriptProps extends react.DetailedHTMLProps<react.ScriptHTMLAttributes<HTMLScriptElement>, HTMLScriptElement> {
10
+ }
11
+ interface UseThemeProps {
12
+ /** List of all available theme names */
13
13
  themes: Theme[];
14
- };
15
- declare const ThemeContext: react__default.Context<ThemeContextProps>;
16
- type ThemeProviderProps = {
17
- children: react__default.ReactNode;
18
- };
19
- declare const ThemeProvider: ({ children }: ThemeProviderProps) => react_jsx_runtime.JSX.Element;
14
+ /** Update the theme */
15
+ setTheme: (value: Theme) => void;
16
+ /** Active theme name */
17
+ theme?: Theme | undefined;
18
+ /** If the active theme is "system", this returns whether the system preference resolved to "dark" or "light". Otherwise, identical to `theme` */
19
+ resolvedTheme?: Theme | undefined;
20
+ /** Returns the System theme preference ("dark" or "light"), regardless what the active theme is */
21
+ systemTheme?: SystemTheme | undefined;
22
+ }
23
+ interface ThemeProviderProps extends react.PropsWithChildren {
24
+ /** Props to pass the inline script */
25
+ scriptProps?: ScriptProps;
26
+ }
27
+ declare const useTheme: () => UseThemeProps;
28
+ declare const ThemeProvider: (props: ThemeProviderProps) => react_jsx_runtime.JSX.Element;
20
29
 
21
30
  type AddToastPayload = Omit<Toast, "status">;
22
31
  type ToastContextProps = ((payload: AddToastPayload) => void) & {
23
32
  error: (payload: AddToastPayload) => void;
24
33
  success: (payload: AddToastPayload) => void;
25
34
  };
26
- declare const ToastContext: react.Context<ToastContextProps>;
35
+ declare const useToast: () => ToastContextProps;
27
36
  declare const ToastProvider: ({ children, ...props }: ToastPrimitives.ToastProviderProps) => react_jsx_runtime.JSX.Element;
28
37
  type Toast = {
29
38
  title?: string;
@@ -36,4 +45,4 @@ declare const Toast: (props: ToastPrimitives.ToastProps & {
36
45
  }) => react_jsx_runtime.JSX.Element;
37
46
  declare const ToastAction: ({ ...props }: Omit<ToastPrimitives.ToastActionProps, "asChild">) => react_jsx_runtime.JSX.Element;
38
47
 
39
- export { ThemeContext, ThemeProvider, ToastAction, ToastContext, ToastProvider };
48
+ export { ThemeProvider, type ThemeProviderProps, ToastAction, ToastProvider, type UseThemeProps, useTheme, useToast };
@@ -30,11 +30,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/providers/index.ts
31
31
  var providers_exports = {};
32
32
  __export(providers_exports, {
33
- ThemeContext: () => ThemeContext,
34
33
  ThemeProvider: () => ThemeProvider,
35
34
  ToastAction: () => ToastAction,
36
- ToastContext: () => ToastContext,
37
- ToastProvider: () => ToastProvider
35
+ ToastProvider: () => ToastProvider,
36
+ useTheme: () => useTheme,
37
+ useToast: () => useToast
38
38
  });
39
39
  module.exports = __toCommonJS(providers_exports);
40
40
 
@@ -45,98 +45,150 @@ var darkTheme = "dark-theme__1mh7hnp0";
45
45
  var lightTheme = "light-theme__6in2mz0";
46
46
 
47
47
  // src/providers/theme-provider.tsx
48
- var import_react = require("react");
49
-
50
- // src/providers/script.ts
51
- var script = (storageKey2, defaultTheme2, classes2) => {
52
- const el = document.documentElement;
53
- function updateDOM(theme) {
54
- el.classList.remove(...Object.values(classes2));
55
- el.classList.add(classes2[theme]);
56
- }
57
- function getSystemTheme2() {
58
- return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
59
- }
60
- try {
61
- const themeName = localStorage.getItem(storageKey2) || defaultTheme2;
62
- const isSystem = themeName === "system";
63
- const theme = isSystem ? getSystemTheme2() : themeName;
64
- updateDOM(theme);
65
- } catch (e) {
66
- }
67
- };
68
-
69
- // src/providers/theme-provider.tsx
48
+ var React = __toESM(require("react"));
70
49
  var import_jsx_runtime = require("react/jsx-runtime");
71
- var MEDIA = "(prefers-color-scheme: dark)";
72
- var isServer = typeof window === "undefined";
73
- var storageKey = "nayhoo-theme";
74
- var themes = ["light", "dark", "system"];
75
- var defaultTheme = "system";
76
50
  var classes = {
77
51
  light: lightTheme,
78
52
  dark: darkTheme
79
53
  };
80
- var ThemeContext = (0, import_react.createContext)({
81
- theme: defaultTheme,
54
+ var defaultTheme = "system";
55
+ var storageKey = "nayhoo-theme";
56
+ var systemThemes = ["light", "dark"];
57
+ var themes = [...systemThemes, "system"];
58
+ var colorSchemes = ["light", "dark"];
59
+ var MEDIA = "(prefers-color-scheme: dark)";
60
+ var isServer = typeof window === "undefined";
61
+ var ThemeContext = React.createContext(void 0);
62
+ var defaultContext = {
82
63
  setTheme: () => {
83
64
  },
84
- resolvedTheme: "light",
85
65
  themes
86
- });
87
- var ThemeProvider = ({ children }) => {
88
- const [theme, setTheme] = (0, import_react.useState)(() => getTheme());
89
- const [resolvedTheme, setResolvedTheme] = (0, import_react.useState)(
66
+ };
67
+ var saveToLS = (storageKey2, value) => {
68
+ try {
69
+ localStorage.setItem(storageKey2, value);
70
+ } catch (e) {
71
+ }
72
+ };
73
+ var useTheme = () => {
74
+ var _a;
75
+ return (_a = React.useContext(ThemeContext)) != null ? _a : defaultContext;
76
+ };
77
+ var ThemeProvider = (props) => {
78
+ const context = React.useContext(ThemeContext);
79
+ if (context) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: props.children });
80
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Theme, { ...props });
81
+ };
82
+ var Theme = ({ children, scriptProps }) => {
83
+ const [theme, setThemeState] = React.useState(() => getTheme());
84
+ const [resolvedTheme, setResolvedTheme] = React.useState(
90
85
  () => theme === "system" ? getSystemTheme() : theme
91
86
  );
92
- const applyTheme = (0, import_react.useCallback)((theme2) => {
93
- const resolved = resolveTheme(theme2);
94
- setResolvedTheme(resolved);
87
+ const applyTheme = React.useCallback((theme2) => {
88
+ let resolved = theme2;
89
+ if (!resolved) return;
90
+ if (theme2 === "system") {
91
+ resolved = getSystemTheme();
92
+ }
95
93
  const d = document.documentElement;
96
- d.classList.remove(...Object.values(classes));
97
- d.classList.add(classes[resolved]);
94
+ const handleAttribute = () => {
95
+ d.classList.remove(...Object.values(classes));
96
+ if (resolved) d.classList.add(classes[resolved]);
97
+ };
98
+ handleAttribute();
99
+ const colorScheme = colorSchemes.some(
100
+ (colorScheme2) => colorScheme2 === resolved
101
+ ) ? resolved : null;
102
+ if (colorScheme) d.style.colorScheme = colorScheme;
103
+ }, []);
104
+ const setTheme = React.useCallback((value) => {
105
+ setThemeState(value);
106
+ saveToLS(storageKey, value);
98
107
  }, []);
99
- (0, import_react.useEffect)(() => {
108
+ const handleMediaQuery = React.useCallback(
109
+ (e) => {
110
+ const resolved = getSystemTheme(e);
111
+ setResolvedTheme(resolved);
112
+ if (theme === "system") {
113
+ applyTheme("system");
114
+ }
115
+ },
116
+ // eslint-disable-next-line react-hooks/exhaustive-deps
117
+ [theme]
118
+ );
119
+ React.useEffect(() => {
120
+ const media = window.matchMedia(MEDIA);
121
+ media.addListener(handleMediaQuery);
122
+ handleMediaQuery(media);
123
+ return () => media.removeListener(handleMediaQuery);
124
+ }, [handleMediaQuery]);
125
+ React.useEffect(() => {
126
+ const handleStorage = (e) => {
127
+ if (e.key !== storageKey) {
128
+ return;
129
+ }
130
+ if (!e.newValue || !isTheme(e.newValue)) {
131
+ setTheme(defaultTheme);
132
+ } else {
133
+ setThemeState(e.newValue);
134
+ }
135
+ };
136
+ window.addEventListener("storage", handleStorage);
137
+ return () => window.removeEventListener("storage", handleStorage);
138
+ }, [setTheme]);
139
+ React.useEffect(() => {
100
140
  applyTheme(theme);
101
- try {
102
- localStorage.setItem(storageKey, theme);
103
- } catch {
104
- }
105
- }, [applyTheme, theme]);
106
- const value = (0, import_react.useMemo)(
141
+ }, [theme]);
142
+ const providerValue = React.useMemo(
107
143
  () => ({
108
144
  theme,
109
145
  setTheme,
110
146
  resolvedTheme: theme === "system" ? resolvedTheme : theme,
111
- themes
147
+ themes,
148
+ systemTheme: resolvedTheme
112
149
  }),
113
150
  [theme, setTheme, resolvedTheme]
114
151
  );
115
- const scriptArgs = JSON.stringify([storageKey, defaultTheme, classes]).slice(
116
- 1,
117
- -1
118
- );
119
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ThemeContext, { value, children: [
152
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ThemeContext.Provider, { value: providerValue, children: [
120
153
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
121
- "script",
154
+ ThemeScript,
122
155
  {
123
- suppressHydrationWarning: true,
124
- dangerouslySetInnerHTML: {
125
- __html: `(${script.toString()})(${scriptArgs})`
156
+ ...{
157
+ scriptProps
126
158
  }
127
159
  }
128
160
  ),
129
161
  children
130
162
  ] });
131
163
  };
164
+ var ThemeScript = React.memo(
165
+ ({ scriptProps }) => {
166
+ const scriptArgs = JSON.stringify([
167
+ storageKey,
168
+ defaultTheme,
169
+ classes
170
+ ]).slice(1, -1);
171
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
172
+ "script",
173
+ {
174
+ ...scriptProps,
175
+ suppressHydrationWarning: true,
176
+ dangerouslySetInnerHTML: {
177
+ __html: `(${script.toString()})(${scriptArgs})`
178
+ }
179
+ }
180
+ );
181
+ }
182
+ );
183
+ ThemeScript.displayName = "ThemeScript";
132
184
  var getTheme = () => {
133
- if (isServer) return defaultTheme;
134
- let themeName;
185
+ if (isServer) return void 0;
186
+ let theme;
135
187
  try {
136
- themeName = localStorage.getItem(storageKey) || void 0;
188
+ theme = localStorage.getItem(storageKey) || void 0;
137
189
  } catch (e) {
138
190
  }
139
- return themes.find((theme) => theme === themeName) || defaultTheme;
191
+ return theme !== void 0 && isTheme(theme) ? theme : defaultTheme;
140
192
  };
141
193
  var getSystemTheme = (e) => {
142
194
  if (!e) e = window.matchMedia(MEDIA);
@@ -144,12 +196,27 @@ var getSystemTheme = (e) => {
144
196
  const systemTheme = isDark ? "dark" : "light";
145
197
  return systemTheme;
146
198
  };
147
- var resolveTheme = (theme) => {
148
- let resolved = theme;
149
- if (theme === "system") {
150
- resolved = getSystemTheme();
199
+ var isTheme = (value) => themes.some((theme) => theme === value);
200
+ var isSystemTheme = (value) => systemThemes.some((theme) => theme === value);
201
+ var script = () => {
202
+ const el = document.documentElement;
203
+ function updateDOM(theme) {
204
+ el.classList.remove(...Object.values(classes));
205
+ el.classList.add(classes[theme]);
206
+ setColorScheme(theme);
207
+ }
208
+ function setColorScheme(theme) {
209
+ if (systemThemes.some((systemTheme) => systemTheme === theme)) {
210
+ el.style.colorScheme = theme;
211
+ }
212
+ }
213
+ try {
214
+ const themeName = localStorage.getItem(storageKey) || defaultTheme;
215
+ const isSystem = themeName === "system";
216
+ const theme = isSystem || !isSystemTheme(themeName) ? getSystemTheme() : themeName;
217
+ updateDOM(theme);
218
+ } catch (e) {
151
219
  }
152
- return resolved;
153
220
  };
154
221
 
155
222
  // src/theme/recipes/spinner.css.ts
@@ -293,14 +360,21 @@ var import_react_icons = require("@radix-ui/react-icons");
293
360
  var ToastPrimitives = __toESM(require("@radix-ui/react-toast"));
294
361
  var React2 = __toESM(require("react"));
295
362
  var import_jsx_runtime7 = require("react/jsx-runtime");
296
- var defaultToast = Object.assign(() => {
297
- }, {
298
- success: () => {
363
+ var defaultContext2 = Object.assign(
364
+ () => {
299
365
  },
300
- error: () => {
366
+ {
367
+ success: () => {
368
+ },
369
+ error: () => {
370
+ }
301
371
  }
302
- });
303
- var ToastContext = React2.createContext(defaultToast);
372
+ );
373
+ var ToastContext = React2.createContext(defaultContext2);
374
+ var useToast = () => {
375
+ var _a;
376
+ return (_a = React2.useContext(ToastContext)) != null ? _a : defaultContext2;
377
+ };
304
378
  var toastElementsMapRef = React2.createRef();
305
379
  var defaultToastImpl = {
306
380
  toastElementsMapRef,
@@ -509,10 +583,10 @@ var ToastAction = ({
509
583
  };
510
584
  // Annotate the CommonJS export names for ESM import in node:
511
585
  0 && (module.exports = {
512
- ThemeContext,
513
586
  ThemeProvider,
514
587
  ToastAction,
515
- ToastContext,
516
- ToastProvider
588
+ ToastProvider,
589
+ useTheme,
590
+ useToast
517
591
  });
518
592
  //# sourceMappingURL=index.js.map