@particle-network/ui-shared 0.4.1-beta.5 → 0.4.1-beta.7

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.
@@ -0,0 +1,3 @@
1
+ export * from './use-color-scheme';
2
+ export * from './use-theme-color';
3
+ export * from './use-theme-store';
@@ -0,0 +1,3 @@
1
+ export * from "./use-color-scheme.js";
2
+ export * from "./use-theme-color.js";
3
+ export * from "./use-theme-store.js";
@@ -0,0 +1,5 @@
1
+ export declare const useColorScheme: () => {
2
+ colorScheme: import("..").ColorScheme;
3
+ isDark: boolean;
4
+ isLight: boolean;
5
+ };
@@ -0,0 +1,14 @@
1
+ import { useMemo } from "react";
2
+ import { useThemeStore } from "./use-theme-store.js";
3
+ const useColorScheme = ()=>{
4
+ const { colorScheme } = useThemeStore((state)=>state.theme);
5
+ const scheme = useMemo(()=>({
6
+ colorScheme,
7
+ isDark: 'dark' === colorScheme,
8
+ isLight: 'light' === colorScheme
9
+ }), [
10
+ colorScheme
11
+ ]);
12
+ return scheme;
13
+ };
14
+ export { useColorScheme };
@@ -0,0 +1 @@
1
+ export declare const useThemeColor: () => Record<import("..").ThemeColorVariable, string>;
@@ -0,0 +1,6 @@
1
+ import { useThemeStore } from "./use-theme-store.js";
2
+ const useThemeColor = ()=>{
3
+ const { colorVariables } = useThemeStore((state)=>state.theme);
4
+ return colorVariables;
5
+ };
6
+ export { useThemeColor };
@@ -0,0 +1,46 @@
1
+ import type { ThemeItemType } from '../theme-data';
2
+ export type FontLoadStatus = 'idle' | 'loading' | 'success' | 'error';
3
+ interface State {
4
+ /**
5
+ * 保存的主题
6
+ */
7
+ theme: ThemeItemType;
8
+ /**
9
+ * 保存的自定义主题配置(当切换到其他主题时保存,切回 custom 时恢复)
10
+ */
11
+ customTheme: ThemeItemType;
12
+ /**
13
+ * 保存的字体链接
14
+ */
15
+ fontUrl: string;
16
+ /**
17
+ * 应用的字体名称
18
+ */
19
+ fontName: string;
20
+ /**
21
+ * 字体加载状态
22
+ */
23
+ fontLoadStatus: FontLoadStatus;
24
+ }
25
+ interface Actions {
26
+ setTheme: (theme: ThemeItemType) => void;
27
+ setCustomTheme: (customTheme: ThemeItemType) => void;
28
+ setFontUrl: (fontUrl: string) => void;
29
+ setFontLoadStatus: (status: FontLoadStatus) => void;
30
+ setFontName: (name: string) => void;
31
+ }
32
+ type ThemeStore = State & Actions;
33
+ export declare const useThemeStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<ThemeStore>, "setState" | "persist"> & {
34
+ setState(partial: ThemeStore | Partial<ThemeStore> | ((state: ThemeStore) => ThemeStore | Partial<ThemeStore>), replace?: false | undefined): unknown;
35
+ setState(state: ThemeStore | ((state: ThemeStore) => ThemeStore), replace: true): unknown;
36
+ persist: {
37
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<ThemeStore, unknown, unknown>>) => void;
38
+ clearStorage: () => void;
39
+ rehydrate: () => Promise<void> | void;
40
+ hasHydrated: () => boolean;
41
+ onHydrate: (fn: (state: ThemeStore) => void) => () => void;
42
+ onFinishHydration: (fn: (state: ThemeStore) => void) => () => void;
43
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<ThemeStore, unknown, unknown>>;
44
+ };
45
+ }>;
46
+ export {};
@@ -0,0 +1,36 @@
1
+ import { create } from "zustand";
2
+ import { createJSONStorage, persist } from "zustand/middleware";
3
+ import { CustomTheme, UXDarkTheme } from "../theme-data.js";
4
+ const useThemeStore = create()(persist((set)=>({
5
+ theme: UXDarkTheme,
6
+ customTheme: CustomTheme,
7
+ fontUrl: '',
8
+ fontName: '',
9
+ fontLoadStatus: 'idle',
10
+ setTheme: (theme)=>set({
11
+ theme
12
+ }),
13
+ setCustomTheme: (customTheme)=>set({
14
+ customTheme
15
+ }),
16
+ setFontUrl: (fontUrl)=>set({
17
+ fontUrl
18
+ }),
19
+ setFontLoadStatus: (fontLoadStatus)=>set({
20
+ fontLoadStatus
21
+ }),
22
+ setFontName: (fontName)=>set({
23
+ fontName
24
+ })
25
+ }), {
26
+ name: 'ux-preference-theme',
27
+ version: 2,
28
+ storage: createJSONStorage(()=>'undefined' != typeof window ? window.localStorage : {}),
29
+ partialize: (state)=>({
30
+ theme: state.theme,
31
+ customTheme: state.customTheme,
32
+ fontName: state.fontName,
33
+ fontUrl: state.fontUrl
34
+ })
35
+ }));
36
+ export { useThemeStore };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from './color';
2
+ export * from './hooks';
2
3
  export * from './radius';
3
4
  export * from './size';
4
5
  export * from './spacing';
5
6
  export * from './tailwind-color';
6
7
  export * from './theme-data';
8
+ export * from './utils';
package/dist/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from "./color.js";
2
+ export * from "./hooks/index.js";
2
3
  export * from "./radius.js";
3
4
  export * from "./size.js";
4
5
  export * from "./spacing.js";
5
6
  export * from "./tailwind-color.js";
6
7
  export * from "./theme-data.js";
8
+ export * from "./utils.js";
@@ -0,0 +1,4 @@
1
+ export declare function objectEntries<T extends object>(obj: T): [keyof T & string, T[keyof T & string]][];
2
+ export declare function objectKeys<T extends object>(obj: T): (keyof T & string)[];
3
+ export declare function objectValues<T extends object>(obj: T): T[keyof T & string][];
4
+ export declare function objectFromEntries<T extends object>(entries: [keyof T & string, T[keyof T & string]][]): T;
package/dist/utils.js ADDED
@@ -0,0 +1,13 @@
1
+ function objectEntries(obj) {
2
+ return Object.entries(obj);
3
+ }
4
+ function objectKeys(obj) {
5
+ return Object.keys(obj);
6
+ }
7
+ function objectValues(obj) {
8
+ return Object.values(obj);
9
+ }
10
+ function objectFromEntries(entries) {
11
+ return Object.fromEntries(entries);
12
+ }
13
+ export { objectEntries, objectFromEntries, objectKeys, objectValues };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@particle-network/ui-shared",
3
- "version": "0.4.1-beta.5",
3
+ "version": "0.4.1-beta.7",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "react-native": "./dist/index.js",