@tonar/react-kit 0.1.0-beta.2 → 0.2.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.
@@ -1,12 +1,13 @@
1
- import { FC, ReactNode, JSX, PropsWithChildren } from 'react';
2
- export type CustomShowProps<T> = PropsWithChildren<{
3
- /** 判断条件 */
4
- when: T | null | undefined | false;
5
- /** 不满足条件时的渲染内容 */
6
- fallback?: ReactNode;
1
+ import { FC, JSX, PropsWithChildren, ReactNode } from "react";
2
+ //#region src/components/custom-show/index.d.ts
3
+ type CustomShowProps<T> = PropsWithChildren<{
4
+ /** 判断条件 */
5
+ when: T | null | undefined | false;
6
+ /** 不满足条件时的渲染内容 */
7
+ fallback?: ReactNode;
7
8
  }>;
8
- export interface CustomShowType<T> extends FC<CustomShowProps<T>> {
9
- (props: CustomShowProps<T>): JSX.Element;
9
+ interface CustomShowType<T> extends FC<CustomShowProps<T>> {
10
+ (props: CustomShowProps<T>): JSX.Element;
10
11
  }
11
12
  /**
12
13
  * @author sonion
@@ -17,5 +18,6 @@ export interface CustomShowType<T> extends FC<CustomShowProps<T>> {
17
18
  * @param {(value: T | null | undefined | false) => ReactNode} props.children 满足条件时的渲染内容
18
19
  * @returns {JSX.Element} - 组件节点
19
20
  */
20
- declare function CustomShow<T>({ when, fallback, children, }: CustomShowProps<T>): JSX.Element;
21
- export default CustomShow;
21
+ declare function CustomShow<T>({ when, fallback, children }: CustomShowProps<T>): JSX.Element;
22
+ //#endregion
23
+ export { CustomShowProps, CustomShowType, CustomShow as default };
@@ -1,14 +1,15 @@
1
- import { Component, ErrorInfo, ReactNode } from 'react';
2
- export interface ErrorBoundaryProps {
3
- /** 正常展示 */
4
- children: ReactNode;
5
- /** 错误发生时显示的回退内容 */
6
- fallback: ReactNode;
7
- /** 错误信息的提示文本 */
8
- msg?: string;
1
+ import { Component, ErrorInfo, ReactNode } from "react";
2
+ //#region src/components/error-boundary/index.d.ts
3
+ interface ErrorBoundaryProps {
4
+ /** 正常展示 */
5
+ children: ReactNode;
6
+ /** 错误发生时显示的回退内容 */
7
+ fallback: ReactNode;
8
+ /** 错误信息的提示文本 */
9
+ msg?: string;
9
10
  }
10
11
  interface State {
11
- hasError: boolean;
12
+ hasError: boolean;
12
13
  }
13
14
  /**
14
15
  * @author sonion
@@ -20,12 +21,12 @@ interface State {
20
21
  * @returns {import('react').JSX.Element} - 组件节点
21
22
  */
22
23
  declare class ErrorBoundary extends Component<ErrorBoundaryProps, State> {
23
- state: State;
24
- private msg;
25
- static getDerivedStateFromError(): State;
26
- componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
27
- render(): ReactNode;
24
+ state: State;
25
+ private msg;
26
+ static getDerivedStateFromError(): State;
27
+ componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
28
+ render(): ReactNode;
28
29
  }
29
30
  type ErrorBoundaryType = typeof ErrorBoundary;
30
- export type { ErrorBoundaryType };
31
- export default ErrorBoundary;
31
+ //#endregion
32
+ export { ErrorBoundaryProps, type ErrorBoundaryType, ErrorBoundary as default };
@@ -1,8 +1,6 @@
1
- export * from './carousel';
2
- export { default as Carousel } from './carousel';
3
- export * from './custom-show';
4
- export { default as CustomShow } from './custom-show';
5
- export * from './async-custom-show';
6
- export { default as AsyncCustomShow } from './async-custom-show';
7
- export * from './error-boundary';
8
- export { default as ErrorBoundary } from './error-boundary';
1
+ import { RerenderType, ShowArrowType } from "./carousel/hooks/index.js";
2
+ import Carousel, { CarouselProps, CarouselRef, CarouselType } from "./carousel/index.js";
3
+ import CustomShow, { CustomShowProps, CustomShowType } from "./custom-show/index.js";
4
+ import AsyncCustomShow, { AsyncCustomShowProps, AsyncCustomShowType } from "./async-custom-show/index.js";
5
+ import ErrorBoundary, { ErrorBoundaryProps, ErrorBoundaryType } from "./error-boundary/index.js";
6
+ export { AsyncCustomShow, AsyncCustomShowProps, AsyncCustomShowType, Carousel, CarouselProps, CarouselRef, type CarouselType, CustomShow, CustomShowProps, CustomShowType, ErrorBoundary, ErrorBoundaryProps, type ErrorBoundaryType, type RerenderType, type ShowArrowType };
@@ -1,3 +1,4 @@
1
+ //#region src/hooks/async-guard/index.d.ts
1
2
  /**
2
3
  * @author sonion
3
4
  * @description 异步操作锁,防止重复调用。通过返回的 Promise 确定是否执行中,执行中不可重复触发。
@@ -6,4 +7,6 @@
6
7
  * @param {string} [msg] - 警告信息
7
8
  * @returns {[boolean, (...args: T) => Promise<R | void>]} - 返回是否执行中,执行方法
8
9
  */
9
- export declare const useAsyncActionLock: <T extends unknown[], R>(asyncAction: (...args: T) => Promise<R>, onPendingChange?: (isPending: boolean, ...args: T) => void, msg?: string) => readonly [boolean, (...args: T) => Promise<R | void>];
10
+ declare const useAsyncActionLock: <T extends unknown[], R>(asyncAction: (...args: T) => Promise<R>, onPendingChange?: (isPending: boolean, ...args: T) => void, msg?: string) => readonly [boolean, (...args: T) => Promise<R | void>];
11
+ //#endregion
12
+ export { useAsyncActionLock };
@@ -1,5 +1,6 @@
1
- export * from './state';
2
- export * from './timer';
3
- export * from './observer';
4
- export * from './storage';
5
- export * from './async-guard';
1
+ import { useCreateSafeRef, useDistinctState, useLatestCallback, useStaticState } from "./state/index.js";
2
+ import { useInterval, useRAfInterval } from "./timer/index.js";
3
+ import { useIntersectionObserver, useMutationObserver, useResizeObserver } from "./observer/index.js";
4
+ import { useStorage } from "./storage/index.js";
5
+ import { useAsyncActionLock } from "./async-guard/index.js";
6
+ export { useAsyncActionLock, useCreateSafeRef, useDistinctState, useIntersectionObserver, useInterval, useLatestCallback, useMutationObserver, useRAfInterval, useResizeObserver, useStaticState, useStorage };
@@ -1,3 +1,4 @@
1
+ //#region src/hooks/observer/index.d.ts
1
2
  type MutationObserverCallback = (entry: MutationRecord[], observer: MutationObserver) => void;
2
3
  /**
3
4
  * @author sonion
@@ -5,26 +6,26 @@ type MutationObserverCallback = (entry: MutationRecord[], observer: MutationObse
5
6
  * @param {MutationObserverCallback} callback - 回调函数,参数为 MutationRecord[]
6
7
  * @param {boolean} [once] - 是否只观察一次,默认false
7
8
  */
8
- export declare const useMutationObserver: (callback: MutationObserverCallback, once?: boolean) => {
9
- /** 开始观察 因重新生成观察器observe不会更新,故不可以observe是否更新做依赖依据 */
10
- observe: (el: Node | null, options?: MutationObserverInit) => void;
11
- /** 获取所有未处理的观察记录 */
12
- takeRecords: () => MutationRecord[] | undefined;
13
- /** 取消所有观察,用observe重新启用 */
14
- disconnect: () => void | undefined;
9
+ declare const useMutationObserver: (callback: MutationObserverCallback, once?: boolean) => {
10
+ /** 开始观察 因重新生成观察器observe不会更新,故不可以observe是否更新做依赖依据 */
11
+ observe: (el: Node | null, options?: MutationObserverInit) => void;
12
+ /** 获取所有未处理的观察记录 */
13
+ takeRecords: () => MutationRecord[] | undefined;
14
+ /** 取消所有观察,用observe重新启用 */
15
+ disconnect: () => void | undefined;
15
16
  };
16
17
  type IntersectionObserverCallback = (
17
18
  /** 交叉目标 */
18
- target: Element,
19
+ target: Element,
19
20
  /** 交叉目标的根元素 */
20
- root: Element | undefined,
21
+ root: Element | undefined,
21
22
  /** 交叉观察器实例 */
22
23
  observer: IntersectionObserver) => void;
23
24
  type IntersectionObserverParams = {
24
- callback: IntersectionObserverCallback;
25
- rootMargin?: number;
26
- threshold?: number;
27
- once?: boolean;
25
+ callback: IntersectionObserverCallback;
26
+ rootMargin?: number;
27
+ threshold?: number;
28
+ once?: boolean;
28
29
  };
29
30
  /**
30
31
  * @author sonion
@@ -35,22 +36,22 @@ type IntersectionObserverParams = {
35
36
  * @param {number} [params.threshold] - 被观察目标与观察区交叉多少触发,0-1
36
37
  * @param {boolean} [params.once] - 是否只触发一次
37
38
  */
38
- export declare const useIntersectionObserver: ({ callback, rootMargin, threshold, once, }: IntersectionObserverParams) => {
39
- rootRef: Element | undefined;
40
- /** 设置观察区域 */
41
- setRootRef: (node: Element | null) => void;
42
- /** 开始观察 */
43
- observe: (el: Element | null) => void;
44
- /** 取消观察 */
45
- unobserve: (el: Element | null) => void | null | undefined;
46
- /** 取消所有观察,用observe重新启用 */
47
- disconnect: () => void | undefined;
48
- /** 获取 未触发回调前,所有未处理的观察记录,触发后清空 */
49
- takeRecords: () => IntersectionObserverEntry[] | undefined;
39
+ declare const useIntersectionObserver: ({ callback, rootMargin, threshold, once }: IntersectionObserverParams) => {
40
+ rootRef: Element | undefined;
41
+ /** 设置观察区域 */
42
+ setRootRef: (node: Element | null) => void;
43
+ /** 开始观察 */
44
+ observe: (el: Element | null) => void;
45
+ /** 取消观察 */
46
+ unobserve: (el: Element | null) => void | null | undefined;
47
+ /** 取消所有观察,用observe重新启用 */
48
+ disconnect: () => void | undefined;
49
+ /** 获取 未触发回调前,所有未处理的观察记录,触发后清空 */
50
+ takeRecords: () => IntersectionObserverEntry[] | undefined;
50
51
  };
51
52
  type ResizeObserverCallback = (
52
53
  /** 变化记录 */
53
- entry: ResizeObserverEntry,
54
+ entry: ResizeObserverEntry,
54
55
  /** 观察器实例 */
55
56
  observer: ResizeObserver) => void;
56
57
  /**
@@ -59,12 +60,13 @@ observer: ResizeObserver) => void;
59
60
  * @param {ResizeObserverCallback} callback - 回调函数,参数为ResizeObserverEntry
60
61
  * @param {boolean} [once] - 是否只观察一次,默认false
61
62
  */
62
- export declare const useResizeObserver: (callback: ResizeObserverCallback, once?: boolean) => {
63
- /** 开始观察 因重新生成观察器observe不会更新,故不可以observe是否更新做依赖依据 */
64
- observe: (el: Element | null, options?: ResizeObserverOptions) => void;
65
- /** 取消观察 */
66
- unobserve: (el: Element | null) => void | null | undefined;
67
- /** 取消所有观察,用observe重新启用 */
68
- disconnect: () => void | undefined;
63
+ declare const useResizeObserver: (callback: ResizeObserverCallback, once?: boolean) => {
64
+ /** 开始观察 因重新生成观察器observe不会更新,故不可以observe是否更新做依赖依据 */
65
+ observe: (el: Element | null, options?: ResizeObserverOptions) => void;
66
+ /** 取消观察 */
67
+ unobserve: (el: Element | null) => void | null | undefined;
68
+ /** 取消所有观察,用observe重新启用 */
69
+ disconnect: () => void | undefined;
69
70
  };
70
- export {};
71
+ //#endregion
72
+ export { useIntersectionObserver, useMutationObserver, useResizeObserver };
@@ -1,15 +1,16 @@
1
- import { SetStateAction } from 'react';
1
+ import { SetStateAction } from "react";
2
+ //#region src/hooks/state/index.d.ts
2
3
  /**
3
4
  * @author sonion
4
5
  * @description 创建静态的state, 不会触发组件重新渲染
5
6
  * @param {T} initialValue - 初始值
6
7
  */
7
- export declare function useStaticState<T>(initialValue: T): [() => T, (t: T) => void, (t?: T) => T];
8
- export declare function useStaticState<T>(initialValue?: undefined): [() => T | undefined, (t: T) => void, (t?: T) => T | undefined];
8
+ declare function useStaticState<T>(initialValue: T): [() => T, (t: T) => void, (t?: T) => T];
9
+ declare function useStaticState<T>(initialValue?: undefined): [() => T | undefined, (t: T) => void, (t?: T) => T | undefined];
9
10
  type AnyFn = (...args: never[]) => unknown;
10
11
  interface UseLatestCallbackType {
11
- <T extends AnyFn>(cb: T): T;
12
- <T extends AnyFn>(cb?: T): (...args: Parameters<T>) => ReturnType<T>;
12
+ <T extends AnyFn>(cb: T): T;
13
+ <T extends AnyFn | undefined = undefined>(cb?: T): T extends undefined ? () => void : T;
13
14
  }
14
15
  /**
15
16
  * @author sonion
@@ -18,7 +19,7 @@ interface UseLatestCallbackType {
18
19
  * @param {T} cb - 依赖函数、依赖函数数组、依赖函数对象
19
20
  * @returns {T} - 返回稳定的函数引用,始终调用最新的 cb
20
21
  */
21
- export declare const useLatestCallback: UseLatestCallbackType;
22
+ declare const useLatestCallback: UseLatestCallbackType;
22
23
  /**
23
24
  * @author sonion
24
25
  * @description 创建相同值不触发组件重新渲染的state。和useCreateSafeRef类似,但useCreateSafeRef更专注于ref
@@ -28,22 +29,23 @@ export declare const useLatestCallback: UseLatestCallbackType;
28
29
  * @param {(prev: T, next: T) => boolean} [params.hasDiff] - 对比函数,返回true变更生效。默认对比引用是否不相同。
29
30
  * @param {boolean} [params.onlyEvent] - 是否仅触发事件,不更新值,避免重渲染
30
31
  */
31
- export declare function useDistinctState<T>(params: {
32
- initialValue: T | (() => T);
33
- onChange?: (val: T) => void;
34
- hasDiff?: (prev?: T, next?: T) => boolean;
35
- onlyEvent: true;
32
+ declare function useDistinctState<T>(params: {
33
+ initialValue: T | (() => T);
34
+ onChange?: (val: T) => void;
35
+ hasDiff?: (prev?: T, next?: T) => boolean;
36
+ onlyEvent: true;
36
37
  }): [undefined, (val: SetStateAction<T>) => void, () => T];
37
- export declare function useDistinctState<T>(params: {
38
- initialValue: T | (() => T);
39
- onChange?: (val: T) => void;
40
- hasDiff?: (prev?: T, next?: T) => boolean;
41
- onlyEvent?: false;
38
+ declare function useDistinctState<T>(params: {
39
+ initialValue: T | (() => T);
40
+ onChange?: (val: T) => void;
41
+ hasDiff?: (prev?: T, next?: T) => boolean;
42
+ onlyEvent?: false;
42
43
  }): [T, (val: SetStateAction<T>) => void, () => T];
43
44
  /**
44
45
  * @author sonion
45
46
  * @description 创建安全的Ref引用
46
47
  * @param {(oldNode?: T, newNode?: T) => boolean} [hasDiff] - 对比函数,返回true变更生效。默认对比引用是否不相同。
47
48
  */
48
- export declare const useCreateSafeRef: <T extends object = HTMLElement>(hasDiff?: (oldNode?: T, newNode?: T) => boolean) => readonly [T | undefined, (node: T | null) => void, import('react').MutableRefObject<boolean>];
49
- export {};
49
+ declare const useCreateSafeRef: <T extends object = HTMLElement>(hasDiff?: (oldNode?: T, newNode?: T) => boolean) => readonly [T | undefined, (node: T | null) => void, import("react").MutableRefObject<boolean>];
50
+ //#endregion
51
+ export { useCreateSafeRef, useDistinctState, useLatestCallback, useStaticState };
@@ -1,16 +1,16 @@
1
- import { useDistinctState } from '../state';
2
- type StorageType = typeof localStorage | typeof sessionStorage;
1
+ import { useDistinctState } from "../state/index.js";
2
+ //#region src/hooks/storage/index.d.ts
3
3
  type StorageParams<T> = Omit<Parameters<typeof useDistinctState<T>>[0], 'onlyEvent' | 'initialValue'> & {
4
- /** 储存的key */
5
- key: string;
6
- /** 默认值 */
7
- defaultValue: T;
8
- /** 储存类型。 localStorage 或 sessionStorage */
9
- storage?: StorageType;
10
- /** 初始化类型检查函数,检查不通过使用初始值。可避免类型不对引起的错误 */
11
- checkType?: (val: T) => boolean;
12
- /** tab关闭前的回调, 相同key的不同回调只有初始生效。 */
13
- beforeunload?: (key: string, value: T, storage: StorageType) => void;
4
+ /** 储存的key */
5
+ key: string;
6
+ /** 默认值 */
7
+ defaultValue: T;
8
+ /** 储存类型。 localStorage 或 sessionStorage */
9
+ storage?: Storage;
10
+ /** 初始化类型检查函数,检查不通过使用初始值。可避免类型不对引起的错误 */
11
+ checkType?: (val: T) => boolean;
12
+ /** tab关闭前的回调, 相同key的不同回调只有初始生效。 */
13
+ beforeunload?: (key: string, value: T, storage: Storage) => void;
14
14
  };
15
15
  /**
16
16
  * @author sonion
@@ -24,5 +24,6 @@ type StorageParams<T> = Omit<Parameters<typeof useDistinctState<T>>[0], 'onlyEve
24
24
  * @param [params.checkType] - 初始化类型检查函数,检查不通过使用初始值。可避免类型不对引起的错误
25
25
  * @param [params.beforeunload] - tab关闭前的回调。
26
26
  */
27
- export declare const useStorage: <T>({ key, defaultValue, hasDiff, onChange, storage, checkType, beforeunload, }: StorageParams<T>) => readonly [T, (value: T | ((val: T) => T)) => void, () => void, () => void | undefined];
28
- export {};
27
+ declare const useStorage: <T>({ key, defaultValue, hasDiff, onChange, storage, checkType, beforeunload }: StorageParams<T>) => readonly [T, (value: T | ((val: T) => T)) => void, () => void, () => void | undefined];
28
+ //#endregion
29
+ export { useStorage };
@@ -1,3 +1,4 @@
1
+ //#region src/hooks/timer/index.d.ts
1
2
  /**
2
3
  * @author sonion
3
4
  * @description 自管理定时器的interval
@@ -5,7 +6,7 @@
5
6
  * @param {number} duration - 时间间隔
6
7
  * @returns {[() => void, () => void]} - [启动函数, 清除函数]
7
8
  */
8
- export declare const useInterval: (cb: () => void, duration: number) => readonly [() => void, () => void];
9
+ declare const useInterval: (cb: () => void, duration: number) => readonly [() => void, () => void];
9
10
  /**
10
11
  * @author sonion
11
12
  * @description 自管理定时器的rAfInterval
@@ -13,4 +14,6 @@ export declare const useInterval: (cb: () => void, duration: number) => readonly
13
14
  * @param {number} duration - 时间间隔
14
15
  * @returns {[() => void, () => void]} - [启动函数, 清除函数]
15
16
  */
16
- export declare const useRAfInterval: (cb: () => void, duration: number) => readonly [() => void, () => void];
17
+ declare const useRAfInterval: (cb: () => void, duration: number) => readonly [() => void, () => void];
18
+ //#endregion
19
+ export { useInterval, useRAfInterval };
@@ -1,2 +1,13 @@
1
- export * from './components';
2
- export * from './hooks';
1
+ import { RerenderType, ShowArrowType } from "./components/carousel/hooks/index.js";
2
+ import Carousel, { CarouselProps, CarouselRef, CarouselType } from "./components/carousel/index.js";
3
+ import CustomShow, { CustomShowProps, CustomShowType } from "./components/custom-show/index.js";
4
+ import AsyncCustomShow, { AsyncCustomShowProps, AsyncCustomShowType } from "./components/async-custom-show/index.js";
5
+ import ErrorBoundary, { ErrorBoundaryProps, ErrorBoundaryType } from "./components/error-boundary/index.js";
6
+ import "./components/index.js";
7
+ import { useCreateSafeRef, useDistinctState, useLatestCallback, useStaticState } from "./hooks/state/index.js";
8
+ import { useInterval, useRAfInterval } from "./hooks/timer/index.js";
9
+ import { useIntersectionObserver, useMutationObserver, useResizeObserver } from "./hooks/observer/index.js";
10
+ import { useStorage } from "./hooks/storage/index.js";
11
+ import { useAsyncActionLock } from "./hooks/async-guard/index.js";
12
+ import "./hooks/index.js";
13
+ export { AsyncCustomShow, AsyncCustomShowProps, AsyncCustomShowType, Carousel, CarouselProps, CarouselRef, type CarouselType, CustomShow, CustomShowProps, CustomShowType, ErrorBoundary, ErrorBoundaryProps, type ErrorBoundaryType, type RerenderType, type ShowArrowType, useAsyncActionLock, useCreateSafeRef, useDistinctState, useIntersectionObserver, useInterval, useLatestCallback, useMutationObserver, useRAfInterval, useResizeObserver, useStaticState, useStorage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tonar/react-kit",
3
- "version": "0.1.0-beta.2",
3
+ "version": "0.2.7",
4
4
  "private": false,
5
5
  "description": "@tonar/react-kit: React 18 components and hooks for carousels, conditional rendering, error boundaries, state helpers, observers, storage, timers, and async action locking.",
6
6
  "keywords": [
@@ -25,34 +25,31 @@
25
25
  "sideEffects": [
26
26
  "**/*.css"
27
27
  ],
28
- "module": "dist/index.esm.js",
28
+ "module": "dist/index.es.js",
29
29
  "types": "dist/types/index.d.ts",
30
30
  "exports": {
31
31
  ".": {
32
- "import": "./dist/index.esm.js",
32
+ "import": "./dist/index.es.js",
33
33
  "types": "./dist/types/index.d.ts"
34
34
  },
35
35
  "./hooks": {
36
- "import": "./dist/hooks.esm.js",
36
+ "import": "./dist/hooks.es.js",
37
37
  "types": "./dist/types/hooks/index.d.ts"
38
38
  },
39
39
  "./components": {
40
- "import": "./dist/components.esm.js",
40
+ "import": "./dist/components.es.js",
41
41
  "types": "./dist/types/components/index.d.ts"
42
42
  }
43
43
  },
44
44
  "dependencies": {
45
- "@tonar/utils": "0.1.0-beta.2"
45
+ "@tonar/utils": "0.2.7"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@testing-library/react": "^16.3.2",
49
49
  "@types/react": "^18.3.31",
50
50
  "@types/react-dom": "^18.3.7",
51
- "@vitejs/plugin-react": "^6.0.3",
52
51
  "react": "^18.3.1",
53
- "react-dom": "^18.3.1",
54
- "sass-embedded": "^1.100.0",
55
- "vite-plugin-lib-inject-css": "^2.2.2"
52
+ "react-dom": "^18.3.1"
56
53
  },
57
54
  "peerDependencies": {
58
55
  "react": "^18.0.0",
@@ -65,7 +62,7 @@
65
62
  }
66
63
  },
67
64
  "scripts": {
68
- "build": "rimraf dist && vite build",
65
+ "build": "tsdown",
69
66
  "typecheck": "pnpm exec tsc --noEmit",
70
67
  "test": "vitest --run"
71
68
  }
@@ -1,2 +0,0 @@
1
- import { i as e, n as t, r as n, t as r } from "./js/components.C-It6ulM.js";
2
- export { t as AsyncCustomShow, e as Carousel, n as CustomShow, r as ErrorBoundary };
@@ -1 +0,0 @@
1
- ._carousel_1ryaf_1{width:100%;height:100%;position:relative;overflow:hidden}._carousel_1ryaf_1[style*=--wrapperWidth]{width:calc(var(--wrapperWidth) * 1px)}._carousel_1ryaf_1[style*=--wrapperHeight]{height:calc(var(--wrapperHeight) * 1px)}._carousel_1ryaf_1:not([style*=--cardHeight]) ._wrapper_1ryaf_13 ._inner_1ryaf_13{height:100%}._carousel_1ryaf_1[style*=--cardWidth] ._wrapper_1ryaf_13{width:calc(var(--cardWidth) * 1px)}._carousel_1ryaf_1[style*=--cardWidth] ._wrapper_1ryaf_13 ._inner_1ryaf_13{transform:translateX(calc(var(--index) * (var(--cardWidth) + var(--gapSize,0)) * -1px))}._carousel_1ryaf_1[style*=--cardWidth] ._wrapper_1ryaf_13 ._inner_1ryaf_13>*{flex:0 0 calc(var(--cardWidth) * 1px);height:100%}._carousel_1ryaf_1:not([style*=--cardWidth]) ._wrapper_1ryaf_13{width:100%}._carousel_1ryaf_1:not([style*=--cardWidth]) ._wrapper_1ryaf_13 ._inner_1ryaf_13{transform:translateX(calc((-100% + var(--gapSize,0) * -1px) * var(--index)))}._carousel_1ryaf_1:not([style*=--cardWidth]) ._wrapper_1ryaf_13 ._inner_1ryaf_13>*{flex:0 0 100%;height:100%}._carousel_1ryaf_1:hover>._arrow_1ryaf_36.hover{display:block}._carousel_1ryaf_1>._arrow_1ryaf_36.hover,._carousel_1ryaf_1>._arrow_1ryaf_36.none{display:none}._carousel_1ryaf_1>._arrow_1ryaf_36.always,._carousel_1ryaf_1>._arrow_1ryaf_36.auto{display:block}._carousel_1ryaf_1>._arrow_1ryaf_36 ._left_1ryaf_48,._carousel_1ryaf_1>._arrow_1ryaf_36 ._right_1ryaf_49{z-index:9;cursor:pointer;background:#fff url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjEiIGhlaWdodD0iMjAiIHZpZXdCb3g9IjAgMCAyMSAyMCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGcgaWQ9ImRvd24iPgo8cGF0aCBpZD0iVW5pb24iIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNNi43OTE4MiA1Ljc2ODY1QzYuNDAyNzMgNS4zNzk1NiA2LjQwMjczIDQuNzQ4NzEgNi43OTE4MiA0LjM1OTYyTDcuNDk2MzQgMy42NTUxQzcuODg1NDMgMy4yNjYwMSA4LjUxNjI4IDMuMjY2MDEgOC45MDUzNyAzLjY1NTFMMTQuNTQxNSA5LjI5MTI0QzE0LjczNzEgOS40ODY4MyAxNC44MzQ0IDkuNzQzNSAxNC44MzMzIDkuOTk5ODVDMTQuODM0NCAxMC4yNTYyIDE0LjczNzEgMTAuNTEyOSAxNC41NDE1IDEwLjcwODVMOC45MDUzNyAxNi4zNDQ2QzguNTE2MjggMTYuNzMzNyA3Ljg4NTQzIDE2LjczMzcgNy40OTYzNCAxNi4zNDQ2TDYuNzkxODIgMTUuNjQwMUM2LjQwMjczIDE1LjI1MSA2LjQwMjczIDE0LjYyMDEgNi43OTE4MiAxNC4yMzExTDExLjAyMyA5Ljk5OTg1TDYuNzkxODIgNS43Njg2NVoiIGZpbGw9IiMwMDY2RkMiLz4KPC9nPgo8L3N2Zz4K) 50%/contain no-repeat content-box border-box;border:1px solid #dde2e9;border-radius:50%;width:20px;height:20px;padding:14px;display:none;position:absolute;top:50%;transform:translateY(-50%);box-shadow:0 15px 35px -2px #0000000d,0 5px 15px #0000000d}._carousel_1ryaf_1>._arrow_1ryaf_36>.show{display:block}._carousel_1ryaf_1>._arrow_1ryaf_36 ._left_1ryaf_48{left:12px;transform:translateY(-50%)rotate(180deg)}._carousel_1ryaf_1>._arrow_1ryaf_36 ._right_1ryaf_49{right:12px}._carousel_1ryaf_1 ._wrapper_1ryaf_13{height:100%}._carousel_1ryaf_1 ._wrapper_1ryaf_13 ._inner_1ryaf_13{gap:calc(var(--gapSize) * 1px);height:calc(var(--cardHeight) * 1px);transition:transform .3s;display:flex}._indicator_1ryaf_85{z-index:9;border-radius:8px;gap:8px;display:flex;position:absolute;bottom:-17px;left:50%;transform:translate(-50%)}._indicator_1ryaf_85.none{display:none}._indicator_1ryaf_85.line>i{background-color:var(--Gray-3,#e5e8ef);cursor:pointer;border-radius:8px;width:40px;height:5px}._indicator_1ryaf_85.line>i.active{background:var(--byte-plus-blue-brand-primary-60,#0066fc)}._indicator_1ryaf_85.dot>i{background-color:var(--Gray-3,#e5e8ef);cursor:pointer;border-radius:50%;width:6px;height:6px}._indicator_1ryaf_85.dot>i.active{background:var(--byte-plus-blue-brand-primary-60,#0066fc)}
package/dist/hooks.esm.js DELETED
@@ -1,195 +0,0 @@
1
- import { useCallback as e, useEffect as t, useMemo as n, useRef as r, useState as i } from "react";
2
- import { clearRAfInterval as a, rAfInterval as o } from "@tonar/utils";
3
- //#region src/hooks/state/index.ts
4
- function s(t) {
5
- let n = r(t);
6
- return [
7
- e(() => n.current, []),
8
- e((e) => n.current = e, []),
9
- e((e) => e === void 0 ? n.current : n.current = e, [])
10
- ];
11
- }
12
- var c = (t) => {
13
- let n = r(t);
14
- return n.current !== t && (n.current = t), e((...e) => n.current?.(...e), []);
15
- };
16
- function l({ initialValue: t, onChange: n, hasDiff: a = (e, t) => e !== t, onlyEvent: o }) {
17
- let s = r(void 0), [l, u] = i(() => s.current = typeof t == "function" ? t() : t), d = c(n), f = e((e) => {
18
- let t = typeof e == "function" ? e(s.current) : e;
19
- (a ?? ((e, t) => e !== t))(s.current, t) && (d?.(t), s.current = t, o || u(t));
20
- }, [
21
- d,
22
- o,
23
- u,
24
- !!a
25
- ]);
26
- return [
27
- o ? void 0 : l,
28
- f,
29
- e(() => s.current, [])
30
- ];
31
- }
32
- var u = (t) => {
33
- let [n, a] = i(), o = r(!1);
34
- return [
35
- n,
36
- e((e) => {
37
- e && (t ?? ((e, t) => e !== t))(n, e) && (o.current = !0, a(e));
38
- }, [n, !!t]),
39
- o
40
- ];
41
- }, d = (t, n) => {
42
- let [, , r] = s(void 0), i = c(t), a = e(() => {
43
- clearTimeout(r()), r(setTimeout(() => {
44
- try {
45
- i?.();
46
- } catch (e) {
47
- console.error("useInterval error", e);
48
- }
49
- a?.();
50
- }, n));
51
- }, [
52
- n,
53
- i,
54
- r
55
- ]);
56
- return [a, e(() => clearTimeout(r()), [r])];
57
- }, f = (t, n) => {
58
- let [, , r] = s(void 0);
59
- return [e(() => {
60
- a(r()), r(o(t, n));
61
- }, [
62
- t,
63
- n,
64
- r
65
- ]), e(() => a(r()), [r])];
66
- }, p = (n, i = !1) => {
67
- let a = r(), o = c(n);
68
- return t(() => () => {
69
- a.current?.disconnect?.(), a.current = void 0;
70
- }, []), {
71
- observe: e((e, t) => {
72
- e && (a.current ?? (a.current = new MutationObserver((e, t) => {
73
- o?.(e, t), i && t.disconnect();
74
- })), a.current?.observe?.(e, t));
75
- }, [i, o]),
76
- takeRecords: e(() => a.current?.takeRecords?.(), []),
77
- disconnect: e(() => a.current?.disconnect?.(), [])
78
- };
79
- }, m = ({ callback: i, rootMargin: a = 100, threshold: o = 0, once: l = !1 }) => {
80
- let d = r(), [f, p] = u(), m = c(i), h = n(() => ({
81
- root: f,
82
- rootMargin: `${a}px`,
83
- threshold: o
84
- }), [
85
- f,
86
- a,
87
- o
88
- ]), [, , g] = s(h);
89
- t(() => () => {
90
- d.current?.disconnect?.(), d.current = void 0;
91
- }, [h]);
92
- let _ = e((e) => {
93
- e && (g() !== h && (d.current?.disconnect?.(), d.current = void 0, g(h)), d.current ?? (d.current = new IntersectionObserver((e, t) => {
94
- e.forEach((e) => {
95
- e.isIntersecting && (m?.(e.target, f, t), l && t.unobserve?.(e.target));
96
- });
97
- }, h)), d.current?.unobserve?.(e), d.current?.observe?.(e));
98
- }, [
99
- h,
100
- l,
101
- m
102
- ]), v = e((e) => e && d.current?.unobserve?.(e), []), y = e(() => d.current?.takeRecords?.(), []);
103
- return {
104
- rootRef: f,
105
- setRootRef: p,
106
- observe: _,
107
- unobserve: v,
108
- disconnect: e(() => d.current?.disconnect?.(), []),
109
- takeRecords: y
110
- };
111
- }, h = (n, i = !1) => {
112
- let a = r(), o = c(n);
113
- return t(() => () => {
114
- a.current?.disconnect?.(), a.current = void 0;
115
- }, []), {
116
- observe: e((e, t) => {
117
- e && (a.current ?? (a.current = new ResizeObserver((e, t) => {
118
- e.forEach((e) => {
119
- o?.(e, t);
120
- }), i && t.disconnect();
121
- })), a.current?.unobserve?.(e), a.current?.observe?.(e, t));
122
- }, [i, o]),
123
- unobserve: e((e) => e && a.current?.unobserve?.(e), []),
124
- disconnect: e(() => a.current?.disconnect?.(), [])
125
- };
126
- }, g = ({ key: n, defaultValue: i, hasDiff: a, onChange: o, storage: s = localStorage, checkType: u = () => !0, beforeunload: d }) => {
127
- let f = c((e) => {
128
- try {
129
- let t = e ? JSON.parse(e) : i;
130
- return u(t) ? t : i;
131
- } catch (e) {
132
- return console.warn("规范化出错,已使用默认值", e), i;
133
- }
134
- }), [p, m] = l({
135
- initialValue: () => f(s.getItem(n) ?? ""),
136
- hasDiff: a,
137
- onChange: o
138
- }), h = r(/* @__PURE__ */ new WeakSet()), g = e((e) => {
139
- try {
140
- m((t) => {
141
- let r = e instanceof Function ? e(t) : e, i = JSON.stringify(r);
142
- s.setItem(n, i);
143
- let a = new StorageEvent("storage", {
144
- key: n,
145
- newValue: i,
146
- storageArea: s
147
- });
148
- return h.current.add(a), window.dispatchEvent(a), r;
149
- });
150
- } catch (e) {
151
- console.error("持久化储存错误", e);
152
- }
153
- }, [
154
- n,
155
- s,
156
- m
157
- ]), _ = c((e) => {
158
- if (!(h.current.has(e) || e.storageArea !== s || e.key !== n)) try {
159
- let t = f(e.newValue ?? "");
160
- m(t);
161
- } catch (e) {
162
- console.error("storage事件处理出错", e);
163
- }
164
- });
165
- t(() => (window.addEventListener("storage", _), () => window.removeEventListener("storage", _)), [_]);
166
- let v = c(() => d?.(n, p, s));
167
- return t(() => {
168
- d && window.addEventListener("beforeunload", v);
169
- }, []), [
170
- p,
171
- g,
172
- () => window.removeEventListener("storage", _),
173
- () => d && window.removeEventListener("beforeunload", v)
174
- ];
175
- }, _ = (t, n, r) => {
176
- let [a, o] = i(!1), [, , l] = s(a), u = c(n), d = e((e, ...t) => {
177
- l(e), o(e), u?.(e, ...t);
178
- }, [u, l]), f = c(t);
179
- return [a, e((...e) => l() ? (console.log(r || "正在提交中,请稍后再试"), Promise.resolve()) : (d(!0, ...e), new Promise((t, n) => {
180
- try {
181
- t(f?.(...e));
182
- } catch (e) {
183
- n(e);
184
- }
185
- }).finally(() => {
186
- d(!1, ...e);
187
- })), [
188
- f,
189
- r,
190
- d,
191
- l
192
- ])];
193
- };
194
- //#endregion
195
- export { _ as useAsyncActionLock, u as useCreateSafeRef, l as useDistinctState, m as useIntersectionObserver, d as useInterval, c as useLatestCallback, p as useMutationObserver, f as useRAfInterval, h as useResizeObserver, s as useStaticState, g as useStorage };
package/dist/index.esm.js DELETED
@@ -1,3 +0,0 @@
1
- import { useAsyncActionLock as e, useCreateSafeRef as t, useDistinctState as n, useIntersectionObserver as r, useInterval as i, useLatestCallback as a, useMutationObserver as o, useRAfInterval as s, useResizeObserver as c, useStaticState as l, useStorage as u } from "./hooks.esm.js";
2
- import { i as d, n as f, r as p, t as m } from "./js/components.C-It6ulM.js";
3
- export { f as AsyncCustomShow, d as Carousel, p as CustomShow, m as ErrorBoundary, e as useAsyncActionLock, t as useCreateSafeRef, n as useDistinctState, r as useIntersectionObserver, i as useInterval, a as useLatestCallback, o as useMutationObserver, s as useRAfInterval, c as useResizeObserver, l as useStaticState, u as useStorage };