@willphan1712000/frontend 1.8.3 → 1.9.0

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/index.d.mts CHANGED
@@ -774,4 +774,24 @@ declare const LinearAlgebra: {
774
774
  getVectorMagnitude(vector: number[]): number;
775
775
  };
776
776
 
777
- export { type AuthInterface, Avatar, Button, Canvas, ColorPickerSlider, DropdownSelect, Image$1 as Image, ImageEditor, Image as ImageUtilities, InputFile, InputGoogle, LinearAlgebra, Modern as ModernButton, MultiSelect, OptionSlider, type Options$2 as Options, RangeSlider, SessionProvider, type SessionType, type Options$1 as SliderOptions, type StorageInterface, TextArea, Transform, UploadImage, tools, useAuthClient, useSession };
777
+ declare const ThemeStateArray: readonly ["light", "dark", "system"];
778
+ type ThemeState = (typeof ThemeStateArray)[number];
779
+ interface UseThemeState {
780
+ setThemeState: (mode: ThemeState) => void;
781
+ getThemeState: () => ThemeState;
782
+ }
783
+
784
+ /**
785
+ * Custom React hook for managing and modifying the theme state ('light', 'dark', or 'system') on the web.
786
+ * It interacts with the browser's `localStorage` and `document.body` to persist and apply theme choices.
787
+ *
788
+ * @returns {UseThemeState} An object containing the following theme control methods:
789
+ * - `setThemeState(mode: ThemeState)`: Sets the theme to the specified mode.
790
+ * - `'light'`: Sets the storage item to `'light'`, removes the dark theme class from the document body, and disables the OS color scheme change listener.
791
+ * - `'dark'`: Sets the storage item to `'dark'`, adds the dark theme class to the document body, and disables the OS color scheme change listener.
792
+ * - `'system'`: Sets the storage item to `'system'`, matches the document body class to the current OS color scheme preference, and registers a listener to react to future OS color scheme preference changes.
793
+ * - `getThemeState()`: Retrieves the stored theme value from `localStorage`. Defaults to `'light'` if empty or invalid.
794
+ */
795
+ declare function useThemeState(): UseThemeState;
796
+
797
+ export { type AuthInterface, Avatar, Button, Canvas, ColorPickerSlider, DropdownSelect, Image$1 as Image, ImageEditor, Image as ImageUtilities, InputFile, InputGoogle, LinearAlgebra, Modern as ModernButton, MultiSelect, OptionSlider, type Options$2 as Options, RangeSlider, SessionProvider, type SessionType, type Options$1 as SliderOptions, type StorageInterface, TextArea, Transform, UploadImage, tools, useAuthClient, useSession, useThemeState };
package/dist/index.d.ts CHANGED
@@ -774,4 +774,24 @@ declare const LinearAlgebra: {
774
774
  getVectorMagnitude(vector: number[]): number;
775
775
  };
776
776
 
777
- export { type AuthInterface, Avatar, Button, Canvas, ColorPickerSlider, DropdownSelect, Image$1 as Image, ImageEditor, Image as ImageUtilities, InputFile, InputGoogle, LinearAlgebra, Modern as ModernButton, MultiSelect, OptionSlider, type Options$2 as Options, RangeSlider, SessionProvider, type SessionType, type Options$1 as SliderOptions, type StorageInterface, TextArea, Transform, UploadImage, tools, useAuthClient, useSession };
777
+ declare const ThemeStateArray: readonly ["light", "dark", "system"];
778
+ type ThemeState = (typeof ThemeStateArray)[number];
779
+ interface UseThemeState {
780
+ setThemeState: (mode: ThemeState) => void;
781
+ getThemeState: () => ThemeState;
782
+ }
783
+
784
+ /**
785
+ * Custom React hook for managing and modifying the theme state ('light', 'dark', or 'system') on the web.
786
+ * It interacts with the browser's `localStorage` and `document.body` to persist and apply theme choices.
787
+ *
788
+ * @returns {UseThemeState} An object containing the following theme control methods:
789
+ * - `setThemeState(mode: ThemeState)`: Sets the theme to the specified mode.
790
+ * - `'light'`: Sets the storage item to `'light'`, removes the dark theme class from the document body, and disables the OS color scheme change listener.
791
+ * - `'dark'`: Sets the storage item to `'dark'`, adds the dark theme class to the document body, and disables the OS color scheme change listener.
792
+ * - `'system'`: Sets the storage item to `'system'`, matches the document body class to the current OS color scheme preference, and registers a listener to react to future OS color scheme preference changes.
793
+ * - `getThemeState()`: Retrieves the stored theme value from `localStorage`. Defaults to `'light'` if empty or invalid.
794
+ */
795
+ declare function useThemeState(): UseThemeState;
796
+
797
+ export { type AuthInterface, Avatar, Button, Canvas, ColorPickerSlider, DropdownSelect, Image$1 as Image, ImageEditor, Image as ImageUtilities, InputFile, InputGoogle, LinearAlgebra, Modern as ModernButton, MultiSelect, OptionSlider, type Options$2 as Options, RangeSlider, SessionProvider, type SessionType, type Options$1 as SliderOptions, type StorageInterface, TextArea, Transform, UploadImage, tools, useAuthClient, useSession, useThemeState };
package/dist/index.js CHANGED
@@ -90,7 +90,8 @@ __export(index_exports, {
90
90
  UploadImage: () => UploadImage_default,
91
91
  tools: () => tools_default,
92
92
  useAuthClient: () => useAuthClient_default,
93
- useSession: () => useSession
93
+ useSession: () => useSession,
94
+ useThemeState: () => useThemeState
94
95
  });
95
96
  module.exports = __toCommonJS(index_exports);
96
97
 
@@ -3746,6 +3747,52 @@ var LinearAlgebra = {
3746
3747
  }
3747
3748
  };
3748
3749
  var LinearAlgebra_default = LinearAlgebra;
3750
+
3751
+ // src/utilities/theme/types.ts
3752
+ var ThemeStateArray = ["light", "dark", "system"];
3753
+ var config = {
3754
+ localStorageName: "will-theme",
3755
+ bodyClass: "will-dark"
3756
+ };
3757
+
3758
+ // src/utilities/theme/useThemeState.ts
3759
+ function useThemeState() {
3760
+ const { bodyClass, localStorageName } = config;
3761
+ const htmlClassProcess = (isDark) => {
3762
+ isDark ? document.body.classList.add(bodyClass) : document.body.classList.remove(bodyClass);
3763
+ };
3764
+ const themeCallback = (event) => htmlClassProcess(event.matches);
3765
+ const setLightTheme = () => {
3766
+ window.matchMedia("(prefers-color-scheme: dark)").removeEventListener("change", themeCallback);
3767
+ localStorage.setItem(localStorageName, ThemeStateArray[0]);
3768
+ document.body.classList.remove(bodyClass);
3769
+ };
3770
+ const setDarkTheme = () => {
3771
+ window.matchMedia("(prefers-color-scheme: dark)").removeEventListener("change", themeCallback);
3772
+ localStorage.setItem(localStorageName, ThemeStateArray[1]);
3773
+ document.body.classList.add(bodyClass);
3774
+ };
3775
+ const setSystem = () => {
3776
+ localStorage.setItem(localStorageName, ThemeStateArray[2]);
3777
+ htmlClassProcess(
3778
+ window.matchMedia("(prefers-color-scheme: dark)").matches
3779
+ );
3780
+ window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", themeCallback);
3781
+ };
3782
+ return {
3783
+ setThemeState: (mode) => {
3784
+ if (mode === "system") return setSystem();
3785
+ if (mode === "light") return setLightTheme();
3786
+ if (mode === "dark") return setDarkTheme();
3787
+ },
3788
+ getThemeState: () => {
3789
+ const theme = localStorage.getItem(localStorageName);
3790
+ if (!theme) return "light";
3791
+ if (!ThemeStateArray.includes(theme)) return "light";
3792
+ return theme;
3793
+ }
3794
+ };
3795
+ }
3749
3796
  // Annotate the CommonJS export names for ESM import in node:
3750
3797
  0 && (module.exports = {
3751
3798
  Avatar,
@@ -3769,5 +3816,6 @@ var LinearAlgebra_default = LinearAlgebra;
3769
3816
  UploadImage,
3770
3817
  tools,
3771
3818
  useAuthClient,
3772
- useSession
3819
+ useSession,
3820
+ useThemeState
3773
3821
  });
package/dist/index.mjs CHANGED
@@ -3707,6 +3707,52 @@ var LinearAlgebra = {
3707
3707
  }
3708
3708
  };
3709
3709
  var LinearAlgebra_default = LinearAlgebra;
3710
+
3711
+ // src/utilities/theme/types.ts
3712
+ var ThemeStateArray = ["light", "dark", "system"];
3713
+ var config = {
3714
+ localStorageName: "will-theme",
3715
+ bodyClass: "will-dark"
3716
+ };
3717
+
3718
+ // src/utilities/theme/useThemeState.ts
3719
+ function useThemeState() {
3720
+ const { bodyClass, localStorageName } = config;
3721
+ const htmlClassProcess = (isDark) => {
3722
+ isDark ? document.body.classList.add(bodyClass) : document.body.classList.remove(bodyClass);
3723
+ };
3724
+ const themeCallback = (event) => htmlClassProcess(event.matches);
3725
+ const setLightTheme = () => {
3726
+ window.matchMedia("(prefers-color-scheme: dark)").removeEventListener("change", themeCallback);
3727
+ localStorage.setItem(localStorageName, ThemeStateArray[0]);
3728
+ document.body.classList.remove(bodyClass);
3729
+ };
3730
+ const setDarkTheme = () => {
3731
+ window.matchMedia("(prefers-color-scheme: dark)").removeEventListener("change", themeCallback);
3732
+ localStorage.setItem(localStorageName, ThemeStateArray[1]);
3733
+ document.body.classList.add(bodyClass);
3734
+ };
3735
+ const setSystem = () => {
3736
+ localStorage.setItem(localStorageName, ThemeStateArray[2]);
3737
+ htmlClassProcess(
3738
+ window.matchMedia("(prefers-color-scheme: dark)").matches
3739
+ );
3740
+ window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", themeCallback);
3741
+ };
3742
+ return {
3743
+ setThemeState: (mode) => {
3744
+ if (mode === "system") return setSystem();
3745
+ if (mode === "light") return setLightTheme();
3746
+ if (mode === "dark") return setDarkTheme();
3747
+ },
3748
+ getThemeState: () => {
3749
+ const theme = localStorage.getItem(localStorageName);
3750
+ if (!theme) return "light";
3751
+ if (!ThemeStateArray.includes(theme)) return "light";
3752
+ return theme;
3753
+ }
3754
+ };
3755
+ }
3710
3756
  export {
3711
3757
  Avatar_default as Avatar,
3712
3758
  Button_default as Button,
@@ -3729,5 +3775,6 @@ export {
3729
3775
  UploadImage_default as UploadImage,
3730
3776
  tools_default as tools,
3731
3777
  useAuthClient_default as useAuthClient,
3732
- useSession
3778
+ useSession,
3779
+ useThemeState
3733
3780
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willphan1712000/frontend",
3
- "version": "1.8.3",
3
+ "version": "1.9.0",
4
4
  "description": "Frontend Library",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",