@particle-network/ui-shared 0.4.1-beta.4 → 0.4.1-beta.6

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,4 +1,5 @@
1
1
  export * from './color';
2
+ export * from './hooks';
2
3
  export * from './radius';
3
4
  export * from './size';
4
5
  export * from './spacing';
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
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";
@@ -343,7 +343,8 @@ const CustomTheme = {
343
343
  ...UXDarkTheme,
344
344
  id: 'custom',
345
345
  zhName: '自定义',
346
- enName: 'Custom'
346
+ enName: 'Custom',
347
+ baseThemeId: UXDarkTheme.id
347
348
  };
348
349
  const themeData = [
349
350
  UXDarkTheme,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@particle-network/ui-shared",
3
- "version": "0.4.1-beta.4",
3
+ "version": "0.4.1-beta.6",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "react-native": "./dist/index.js",
@@ -44,8 +44,8 @@
44
44
  "@rsbuild/plugin-react": "^1.3.5",
45
45
  "@rslib/core": "^0.12.3",
46
46
  "@types/react": "^19.1.10",
47
- "@particle-network/eslint-config": "0.3.0",
48
- "@particle-network/lintstaged-config": "0.1.0"
47
+ "@particle-network/lintstaged-config": "0.1.0",
48
+ "@particle-network/eslint-config": "0.3.0"
49
49
  },
50
50
  "scripts": {
51
51
  "build": "rslib build",