@cmtlyt/lingshu-toolkit 0.3.0 → 0.5.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/247.js +66 -0
- package/dist/707.js +8 -2
- package/dist/react/index.js +2 -4
- package/dist/react/use-mount/index.js +1 -1
- package/dist/react/use-ref-state/index.js +1 -3
- package/dist/shared/allx/__test__/allsettled.test.d.ts +1 -0
- package/dist/shared/allx/__test__/basic.test.d.ts +1 -0
- package/dist/shared/allx/__test__/circular-dependency.test.d.ts +1 -0
- package/dist/shared/allx/__test__/dependency.test.d.ts +1 -0
- package/dist/shared/allx/__test__/edge-cases.test.d.ts +1 -0
- package/dist/shared/allx/__test__/error-handling.test.d.ts +1 -0
- package/dist/shared/allx/__test__/execution-order.test.d.ts +1 -0
- package/dist/shared/allx/__test__/falsy-values.test.d.ts +1 -0
- package/dist/shared/allx/__test__/performance.test.d.ts +1 -0
- package/dist/shared/allx/__test__/type-checking.test.d.ts +1 -0
- package/dist/shared/allx/__test__/use-cases.test.d.ts +1 -0
- package/dist/shared/allx/index.d.ts +13 -0
- package/dist/shared/allx/index.js +44 -0
- package/dist/shared/allx/types.d.ts +13 -0
- package/dist/shared/allx/types.js +0 -0
- package/dist/shared/allx/utils.d.ts +9 -0
- package/dist/shared/allx/utils.js +94 -0
- package/dist/shared/animation/index.d.ts +2 -2
- package/dist/shared/animation/index.js +19 -13
- package/dist/shared/animation/types.d.ts +6 -4
- package/dist/shared/animation/utils.d.ts +3 -5
- package/dist/shared/animation/utils.js +2 -6
- package/dist/shared/api-controller/__test__/index.browser.test.d.ts +1 -0
- package/dist/shared/api-controller/__test__/index.node.test.d.ts +1 -0
- package/dist/shared/api-controller/create-api.d.ts +26 -0
- package/dist/shared/api-controller/create-api.js +79 -0
- package/dist/shared/api-controller/index.d.ts +3 -0
- package/dist/shared/api-controller/index.js +3 -0
- package/dist/shared/api-controller/request.d.ts +7 -0
- package/dist/shared/api-controller/request.js +66 -0
- package/dist/shared/api-controller/types.d.ts +141 -0
- package/dist/shared/api-controller/types.js +0 -0
- package/dist/shared/api-controller/utils.d.ts +22 -0
- package/dist/shared/api-controller/utils.js +96 -0
- package/dist/shared/data-handler/tools.js +1 -3
- package/dist/shared/data-mixed-manager/__test__/basic.test.d.ts +1 -0
- package/dist/shared/data-mixed-manager/__test__/build-options.test.d.ts +1 -0
- package/dist/shared/data-mixed-manager/__test__/constructor-options.test.d.ts +1 -0
- package/dist/shared/data-mixed-manager/__test__/data-management.test.d.ts +1 -0
- package/dist/shared/data-mixed-manager/__test__/edge-cases.test.d.ts +1 -0
- package/dist/shared/data-mixed-manager/__test__/events.browser.test.d.ts +1 -0
- package/dist/shared/data-mixed-manager/__test__/events.test.d.ts +1 -0
- package/dist/shared/data-mixed-manager/__test__/fixed-slots.test.d.ts +1 -0
- package/dist/shared/data-mixed-manager/__test__/insert-mode.test.d.ts +1 -0
- package/dist/shared/data-mixed-manager/constants.d.ts +8 -0
- package/dist/shared/data-mixed-manager/constants.js +9 -0
- package/dist/shared/data-mixed-manager/index.d.ts +128 -0
- package/dist/shared/data-mixed-manager/index.js +226 -0
- package/dist/shared/data-mixed-manager/types.d.ts +90 -0
- package/dist/shared/data-mixed-manager/types.js +0 -0
- package/dist/shared/index.d.ts +5 -0
- package/dist/shared/index.js +957 -2
- package/dist/shared/logger/index.d.ts +5 -0
- package/dist/shared/logger/index.js +1 -0
- package/dist/shared/throw-error/index.d.ts +1 -0
- package/dist/shared/throw-error/index.js +5 -2
- package/dist/shared/try-call/index.d.ts +22 -0
- package/dist/shared/try-call/index.js +59 -0
- package/dist/shared/try-call/index.test.d.ts +1 -0
- package/dist/shared/types/base.d.ts +5 -0
- package/dist/shared/types/pack.d.ts +1 -1
- package/dist/shared/utils/__test__/base.test.d.ts +1 -0
- package/dist/shared/utils/__test__/verify.test.d.ts +1 -0
- package/dist/shared/utils/base.d.ts +3 -0
- package/dist/shared/utils/base.js +6 -0
- package/dist/shared/utils/index.d.ts +2 -0
- package/dist/shared/utils/index.js +2 -0
- package/dist/shared/utils/verify.d.ts +53 -0
- package/dist/shared/utils/verify.js +67 -0
- package/package.json +10 -7
- package/dist/607.js +0 -311
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
type Logger = {
|
|
2
2
|
[K in keyof Omit<Console, 'table'> as Console[K] extends (...args: any[]) => any ? K : never]: Console[K] extends (...args: [any, ...infer AS]) => infer R ? (fnName: string, ...args: AS) => R : never;
|
|
3
3
|
};
|
|
4
|
+
declare global {
|
|
5
|
+
var $$lingshu$$: {
|
|
6
|
+
disableLogger: boolean;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
4
9
|
export declare const logger: Logger;
|
|
5
10
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const logger = new Proxy(console, {
|
|
2
2
|
get (target, prop, receiver) {
|
|
3
|
+
if ((globalThis.$$lingshu$$ || {}).disableLogger) return ()=>void 0;
|
|
3
4
|
const oldLog = Reflect.get(target, prop, receiver).bind(console);
|
|
4
5
|
return (fnName, ...args)=>{
|
|
5
6
|
oldLog(`[@cmtlyt/lingshu-toolkit#${fnName}]:`, ...args);
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
export declare function createError(fnName: string, message: string, ErrorClass?: ErrorConstructor): Error;
|
|
1
2
|
export declare function throwError(fnName: string, message: string, ErrorClass?: ErrorConstructor): never;
|
|
2
3
|
export declare function throwType(fnName: string, message: string): never;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
function createError(fnName, message, ErrorClass = Error) {
|
|
2
|
+
return new ErrorClass(`[@cmtlyt/lingshu-toolkit#${fnName}]: ${message}`);
|
|
3
|
+
}
|
|
1
4
|
function throwError(fnName, message, ErrorClass = Error) {
|
|
2
|
-
throw
|
|
5
|
+
throw createError(fnName, message, ErrorClass);
|
|
3
6
|
}
|
|
4
7
|
function throwType(fnName, message) {
|
|
5
8
|
throwError(fnName, message, TypeError);
|
|
6
9
|
}
|
|
7
|
-
export { throwError, throwType };
|
|
10
|
+
export { createError, throwError, throwType };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
type TryCallResultValue<R, E> = Awaited<[E] extends [never] ? R : R | E>;
|
|
2
|
+
type TryCallResult<R, E> = [R] extends [never] ? E : R extends PromiseLike<infer P> ? Promise<TryCallResultValue<P, E>> : TryCallResultValue<R, E>;
|
|
3
|
+
type TryCallFinalArgs<R, E> = TryCallResultValue<R, E> | Error;
|
|
4
|
+
/**
|
|
5
|
+
* 包装一个拦截错误的函数
|
|
6
|
+
*
|
|
7
|
+
* @platform web, node, webworker
|
|
8
|
+
*
|
|
9
|
+
* @param cb 回调函数
|
|
10
|
+
* @param onError 错误处理函数
|
|
11
|
+
*/
|
|
12
|
+
export declare function tryCallFunc<A extends any[], R, E = never>(cb: (...args: A) => R, onError?: ((err: any) => E) | null, onFinal?: (result: TryCallFinalArgs<R, E>) => void): (...args: A) => TryCallResult<R, E>;
|
|
13
|
+
/**
|
|
14
|
+
* 尝试调用函数
|
|
15
|
+
*
|
|
16
|
+
* @platform web, node, webworker
|
|
17
|
+
*
|
|
18
|
+
* @param cb 回调函数
|
|
19
|
+
* @param onError 错误处理函数
|
|
20
|
+
*/
|
|
21
|
+
export declare function tryCall<R, E = never>(this: any, cb: () => R, onError?: ((err: any) => E) | null, onFinal?: (result: TryCallFinalArgs<R, E>) => void): TryCallResult<R, E>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { throwType } from "../throw-error/index.js";
|
|
2
|
+
import { isFunction, isPromiseLike } from "../utils/verify.js";
|
|
3
|
+
const EMPTY = Symbol('EMPTY');
|
|
4
|
+
function tryCallFunc(cb, onError, onFinal) {
|
|
5
|
+
if (!isFunction(cb)) throwType('tryCallFunc', 'callback is not a function');
|
|
6
|
+
const catchFn = (self, ctx, error)=>{
|
|
7
|
+
if (isFunction(onError)) try {
|
|
8
|
+
ctx.errorResult = Reflect.apply(onError, self, [
|
|
9
|
+
error
|
|
10
|
+
]);
|
|
11
|
+
} catch (err) {
|
|
12
|
+
ctx.error = err;
|
|
13
|
+
}
|
|
14
|
+
else ctx.error = error;
|
|
15
|
+
return ctx.errorResult;
|
|
16
|
+
};
|
|
17
|
+
const finallyFn = (self, ctx, result)=>{
|
|
18
|
+
try {
|
|
19
|
+
if (ctx.error !== EMPTY) throw ctx.error;
|
|
20
|
+
} finally{
|
|
21
|
+
if (isFunction(onFinal)) if (ctx.errorResult !== EMPTY) Reflect.apply(onFinal, self, [
|
|
22
|
+
ctx.errorResult
|
|
23
|
+
]);
|
|
24
|
+
else if (ctx.error !== EMPTY) Reflect.apply(onFinal, self, [
|
|
25
|
+
ctx.error
|
|
26
|
+
]);
|
|
27
|
+
else Reflect.apply(onFinal, self, [
|
|
28
|
+
result
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
return function(...args) {
|
|
33
|
+
const ctx = {
|
|
34
|
+
oriResult: EMPTY,
|
|
35
|
+
errorResult: EMPTY,
|
|
36
|
+
error: EMPTY
|
|
37
|
+
};
|
|
38
|
+
const asyncFn = async ()=>{
|
|
39
|
+
try {
|
|
40
|
+
ctx.oriResult = Reflect.apply(cb, this, args);
|
|
41
|
+
return ctx.oriResult;
|
|
42
|
+
} catch (error) {
|
|
43
|
+
return catchFn(this, ctx, error);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const fnPromise = asyncFn().catch((error)=>catchFn(this, ctx, error));
|
|
47
|
+
if (isPromiseLike(ctx.oriResult)) return fnPromise.then((result)=>{
|
|
48
|
+
finallyFn(this, ctx, result);
|
|
49
|
+
return result;
|
|
50
|
+
});
|
|
51
|
+
finallyFn(this, ctx, ctx.oriResult);
|
|
52
|
+
return ctx.oriResult !== EMPTY ? ctx.oriResult : ctx.errorResult;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function tryCall(cb, onError, onFinal) {
|
|
56
|
+
if (!isFunction(cb)) throwType('tryCall', 'callback is not a function');
|
|
57
|
+
return tryCallFunc(cb, onError, onFinal).call(this);
|
|
58
|
+
}
|
|
59
|
+
export { tryCall, tryCallFunc };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -6,3 +6,8 @@ export type IsBasicType<T> = T extends number | string | boolean | symbol | bigi
|
|
|
6
6
|
export type Printify<T> = T extends any[] ? T : [T] extends [never] ? T : {
|
|
7
7
|
[K in keyof T]: T[K];
|
|
8
8
|
};
|
|
9
|
+
export type PickRequired<T, K extends keyof T> = Printify<Omit<T, K> & Required<Pick<T, K>>>;
|
|
10
|
+
export type Func<A extends any[], R = any> = (...args: A) => R;
|
|
11
|
+
export type AnyFunc = (...args: any[]) => any;
|
|
12
|
+
export type UnULCase<T extends string> = T extends `${infer F}${infer R}` ? `${Uppercase<F> | Lowercase<F>}${UnULCase<R>}` : Uppercase<T> | Lowercase<T>;
|
|
13
|
+
export type Cast<X, Y> = X extends Y ? X : Y;
|
|
@@ -3,7 +3,7 @@ export type Pack<T> = {
|
|
|
3
3
|
[__PACK__]: T;
|
|
4
4
|
};
|
|
5
5
|
export type Unpack<T extends Pack<any>> = T extends Pack<infer U> ? U : never;
|
|
6
|
-
export type SafeUnpack<T
|
|
6
|
+
export type SafeUnpack<T> = T extends Pack<infer U> ? U : T;
|
|
7
7
|
export type IsPack<T> = Pack<any> extends T ? true : false;
|
|
8
8
|
export type HasPack<T> = (T extends any[] ? HasPack<T[number]> : IsPack<T>) extends false ? false : true;
|
|
9
9
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { AnyFunc, UnULCase } from '../types/base';
|
|
2
|
+
/** 判断是一个 symbol */
|
|
3
|
+
export declare function isSymbol(_v: unknown): _v is symbol;
|
|
4
|
+
/** 判断是一个 undefined */
|
|
5
|
+
export declare function isUndef(_v: unknown): _v is undefined;
|
|
6
|
+
/** 判断是一个 null */
|
|
7
|
+
export declare function isNull(_v: unknown): _v is null;
|
|
8
|
+
/** 判断是一个 null 或者 undefined */
|
|
9
|
+
export declare function isNullOrUndef(_v: unknown): _v is null | undefined;
|
|
10
|
+
/** 判断是一个 NaN */
|
|
11
|
+
export declare function isNaN(_v: unknown): _v is number;
|
|
12
|
+
/** 判断是一个 plain symbol */
|
|
13
|
+
export declare function isPlainSymbol(_v: unknown): _v is symbol;
|
|
14
|
+
/** 判断是一个对象 (数组也返回 true) */
|
|
15
|
+
export declare function isObject(_v: unknown): _v is object;
|
|
16
|
+
/** 判断是一个非数组对象 */
|
|
17
|
+
export declare function isPlainObject(_v: unknown): _v is object;
|
|
18
|
+
/** 判断是一个数组 */
|
|
19
|
+
export declare function isArray(_v: unknown): _v is any[];
|
|
20
|
+
/** 判断是否为空数组 */
|
|
21
|
+
export declare function isEmptyArray(_v: unknown): _v is [];
|
|
22
|
+
/** 判断是一个字符串 */
|
|
23
|
+
export declare function isString(_v: unknown): _v is string;
|
|
24
|
+
/** 判断是一个空字符串 */
|
|
25
|
+
export declare function isEmptyString(_v: unknown): _v is '';
|
|
26
|
+
/** 判断是一个数字 */
|
|
27
|
+
export declare function isNumber(_v: unknown): _v is number;
|
|
28
|
+
/** 判断是一个纯数字 (排除 NaN) */
|
|
29
|
+
export declare function isPlainNumber(_v: unknown): _v is number;
|
|
30
|
+
/** 判断是一个合法的对象 key */
|
|
31
|
+
export declare function isPropertyKey(_v: unknown): _v is PropertyKey;
|
|
32
|
+
/** 判断是一个布尔值 */
|
|
33
|
+
export declare function isBoolean(_v: unknown): _v is boolean;
|
|
34
|
+
/** 判断是一个 true 值 */
|
|
35
|
+
export declare function isTrue(_v: unknown): _v is true | UnULCase<'true'>;
|
|
36
|
+
/** 判断是一个 false 值 */
|
|
37
|
+
export declare function isFalse(_v: unknown): _v is false | UnULCase<'false'>;
|
|
38
|
+
/**
|
|
39
|
+
* 判断是一个真值
|
|
40
|
+
*
|
|
41
|
+
* @warn 字符串 'false' 等满足 isFalse 判断的字符串也会被视为真值
|
|
42
|
+
*/
|
|
43
|
+
export declare function isTruthy<T>(_v: T): _v is Exclude<T, false | 0 | '' | null | undefined>;
|
|
44
|
+
/**
|
|
45
|
+
* 判断是一个非值
|
|
46
|
+
*
|
|
47
|
+
* @warn 字符串 'false' 等满足 isFalse 判断的字符串不会被视为非值
|
|
48
|
+
*/
|
|
49
|
+
export declare function isFalsy(_v: unknown): _v is false | 0 | '' | null | undefined;
|
|
50
|
+
/** 判断是一个函数 */
|
|
51
|
+
export declare function isFunction(_v: unknown): _v is AnyFunc;
|
|
52
|
+
/** 判断是一个 Promise */
|
|
53
|
+
export declare function isPromiseLike(_v: unknown): _v is PromiseLike<any>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
function isSymbol(_v) {
|
|
2
|
+
return 'symbol' == typeof _v;
|
|
3
|
+
}
|
|
4
|
+
function isUndef(_v) {
|
|
5
|
+
return void 0 === _v;
|
|
6
|
+
}
|
|
7
|
+
function isNull(_v) {
|
|
8
|
+
return null === _v;
|
|
9
|
+
}
|
|
10
|
+
function isNullOrUndef(_v) {
|
|
11
|
+
return isNull(_v) || isUndef(_v);
|
|
12
|
+
}
|
|
13
|
+
function verify_isNaN(_v) {
|
|
14
|
+
return Number.isNaN(_v);
|
|
15
|
+
}
|
|
16
|
+
function isPlainSymbol(_v) {
|
|
17
|
+
return isSymbol(_v) && isUndef(Symbol.keyFor(_v));
|
|
18
|
+
}
|
|
19
|
+
function isObject(_v) {
|
|
20
|
+
return 'object' == typeof _v && !isNull(_v);
|
|
21
|
+
}
|
|
22
|
+
function isPlainObject(_v) {
|
|
23
|
+
return isObject(_v) && !isArray(_v);
|
|
24
|
+
}
|
|
25
|
+
function isArray(_v) {
|
|
26
|
+
return Array.isArray(_v);
|
|
27
|
+
}
|
|
28
|
+
function isEmptyArray(_v) {
|
|
29
|
+
return isArray(_v) && 0 === _v.length;
|
|
30
|
+
}
|
|
31
|
+
function isString(_v) {
|
|
32
|
+
return 'string' == typeof _v;
|
|
33
|
+
}
|
|
34
|
+
function isEmptyString(_v) {
|
|
35
|
+
return isString(_v) && 0 === _v.length;
|
|
36
|
+
}
|
|
37
|
+
function isNumber(_v) {
|
|
38
|
+
return 'number' == typeof _v;
|
|
39
|
+
}
|
|
40
|
+
function isPlainNumber(_v) {
|
|
41
|
+
return isNumber(_v) && !verify_isNaN(_v);
|
|
42
|
+
}
|
|
43
|
+
function isPropertyKey(_v) {
|
|
44
|
+
return isString(_v) || isNumber(_v) || isSymbol(_v);
|
|
45
|
+
}
|
|
46
|
+
function isBoolean(_v) {
|
|
47
|
+
return 'boolean' == typeof _v;
|
|
48
|
+
}
|
|
49
|
+
function isTrue(_v) {
|
|
50
|
+
return true === _v || isString(_v) && 'true' === _v.toLowerCase();
|
|
51
|
+
}
|
|
52
|
+
function isFalse(_v) {
|
|
53
|
+
return false === _v || isString(_v) && 'false' === _v.toLowerCase();
|
|
54
|
+
}
|
|
55
|
+
function isTruthy(_v) {
|
|
56
|
+
return !!_v;
|
|
57
|
+
}
|
|
58
|
+
function isFalsy(_v) {
|
|
59
|
+
return !(verify_isNaN(_v) || _v);
|
|
60
|
+
}
|
|
61
|
+
function isFunction(_v) {
|
|
62
|
+
return 'function' == typeof _v;
|
|
63
|
+
}
|
|
64
|
+
function isPromiseLike(_v) {
|
|
65
|
+
return isObject(_v) && isFunction(_v.then);
|
|
66
|
+
}
|
|
67
|
+
export { isArray, isBoolean, isEmptyArray, isEmptyString, isFalse, isFalsy, isFunction, verify_isNaN as isNaN, isNull, isNullOrUndef, isNumber, isObject, isPlainNumber, isPlainObject, isPlainSymbol, isPromiseLike, isPropertyKey, isString, isSymbol, isTrue, isTruthy, isUndef };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmtlyt/lingshu-toolkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/shared.js",
|
|
6
6
|
"module": "./dist/shared.js",
|
|
@@ -41,10 +41,11 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@biomejs/biome": "2.3.8",
|
|
44
|
-
"@cmtlyt/unplugin-shadcn-registry-generate": "^0.1.
|
|
44
|
+
"@cmtlyt/unplugin-shadcn-registry-generate": "^0.1.5",
|
|
45
45
|
"@commitlint/cli": "^20.3.1",
|
|
46
46
|
"@commitlint/config-conventional": "^20.3.1",
|
|
47
47
|
"@rslib/core": "^0.19.3",
|
|
48
|
+
"@rspress/core": "^2.0.8",
|
|
48
49
|
"@types/node": "^24.10.9",
|
|
49
50
|
"@types/react": "^19.2.9",
|
|
50
51
|
"@vitejs/plugin-react": "^5.1.2",
|
|
@@ -52,15 +53,16 @@
|
|
|
52
53
|
"@vitest/browser-playwright": "4.0.18",
|
|
53
54
|
"@vitest/coverage-v8": "4.0.18",
|
|
54
55
|
"@vitest/ui": "4.0.18",
|
|
56
|
+
"changelogithub": "^14.0.0",
|
|
55
57
|
"cross-env": "^10.1.0",
|
|
56
58
|
"esno": "^4.8.0",
|
|
57
59
|
"husky": "^9.1.7",
|
|
58
60
|
"jsdom": "^27.4.0",
|
|
59
61
|
"lint-staged": "^16.2.7",
|
|
62
|
+
"msw": "^2.12.14",
|
|
60
63
|
"playwright": "^1.58.1",
|
|
61
64
|
"react": "^19.2.4",
|
|
62
65
|
"react-dom": "^19.2.4",
|
|
63
|
-
"rspress": "^1.47.1",
|
|
64
66
|
"typescript": "^5.9.3",
|
|
65
67
|
"vite-tsconfig-paths": "^6.0.4",
|
|
66
68
|
"vitest": "4.0.18",
|
|
@@ -75,10 +77,11 @@
|
|
|
75
77
|
"devEngines": {
|
|
76
78
|
"runtime": {
|
|
77
79
|
"name": "node",
|
|
78
|
-
"version": ">=
|
|
80
|
+
"version": ">=22.12.0"
|
|
79
81
|
},
|
|
80
82
|
"packageManager": {
|
|
81
|
-
"name": "pnpm"
|
|
83
|
+
"name": "pnpm",
|
|
84
|
+
"version": ">=10.2.0"
|
|
82
85
|
}
|
|
83
86
|
},
|
|
84
87
|
"publishConfig": {
|
|
@@ -118,8 +121,8 @@
|
|
|
118
121
|
"preview:docs": "rspress preview",
|
|
119
122
|
"format": "biome format --write",
|
|
120
123
|
"test": "vitest --config=vitest.project.config.ts --coverage.enabled --ui",
|
|
121
|
-
"test:ci": "cross-env gen_file_disabled=true vitest run --config=vitest.project.config.ts",
|
|
122
|
-
"test:lib:ci": "cross-env gen_file_disabled=true vitest run",
|
|
124
|
+
"test:ci": "cross-env skip_type_check=true gen_file_disabled=true vitest run --config=vitest.project.config.ts",
|
|
125
|
+
"test:lib:ci": "cross-env skip_type_check=true gen_file_disabled=true vitest run",
|
|
123
126
|
"test:lib": "vitest --coverage.enabled --ui",
|
|
124
127
|
"script:gen-file": "esno scripts/gen-file.ts"
|
|
125
128
|
}
|
package/dist/607.js
DELETED
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
import { dataHandler, logger, $dt, throwError, $t, throwType } from "./707.js";
|
|
2
|
-
function withResolvers() {
|
|
3
|
-
return 'function' == typeof Promise.withResolvers ? Promise.withResolvers() : (()=>{
|
|
4
|
-
const resolver = {
|
|
5
|
-
promise: null,
|
|
6
|
-
resolve: null,
|
|
7
|
-
reject: null
|
|
8
|
-
};
|
|
9
|
-
resolver.promise = new Promise((resolve, reject)=>{
|
|
10
|
-
resolver.resolve = resolve;
|
|
11
|
-
resolver.reject = reject;
|
|
12
|
-
});
|
|
13
|
-
return resolver;
|
|
14
|
-
})();
|
|
15
|
-
}
|
|
16
|
-
const noop = ()=>void 0;
|
|
17
|
-
const identity = (_v)=>_v;
|
|
18
|
-
function getType(_v) {
|
|
19
|
-
return Object.prototype.toString.call(_v).slice(8, -1).toLowerCase();
|
|
20
|
-
}
|
|
21
|
-
function getNextValueHandler(from, to, valueFormatter) {
|
|
22
|
-
const type = getType(from);
|
|
23
|
-
const context = {
|
|
24
|
-
progress: 0,
|
|
25
|
-
valueFormatter
|
|
26
|
-
};
|
|
27
|
-
const baseNextValue = (_from, _to)=>{
|
|
28
|
-
const { valueFormatter: formatter, progress } = context;
|
|
29
|
-
if ('number' !== getType(_from)) return _from;
|
|
30
|
-
return formatter(_from + (_to - _from) * progress);
|
|
31
|
-
};
|
|
32
|
-
const arrayHandler = (_from, _to)=>{
|
|
33
|
-
const result = Array.from(_from, (item, idx)=>{
|
|
34
|
-
if (Array.isArray(item)) return arrayHandler(item, _to[idx]);
|
|
35
|
-
if ('object' === getType(item)) return objectHandler(item, _to[idx]);
|
|
36
|
-
return baseNextValue(item, _to[idx]);
|
|
37
|
-
});
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
const objectHandler = (_from, _to)=>{
|
|
41
|
-
const result = {};
|
|
42
|
-
const keys = Reflect.ownKeys(_from);
|
|
43
|
-
for(let i = 0; i < keys.length; i++){
|
|
44
|
-
const key = keys[i];
|
|
45
|
-
const fromValue = _from[key];
|
|
46
|
-
const toValue = _to[key];
|
|
47
|
-
if (Array.isArray(_from[key])) result[key] = arrayHandler(fromValue, toValue);
|
|
48
|
-
else if ('object' === getType(fromValue)) result[key] = objectHandler(fromValue, toValue);
|
|
49
|
-
else result[key] = baseNextValue(fromValue, toValue);
|
|
50
|
-
}
|
|
51
|
-
return result;
|
|
52
|
-
};
|
|
53
|
-
let nextValueHandler = baseNextValue;
|
|
54
|
-
if ('array' === type) nextValueHandler = arrayHandler;
|
|
55
|
-
else if ('object' === type) nextValueHandler = objectHandler;
|
|
56
|
-
return (progress)=>{
|
|
57
|
-
context.progress = progress;
|
|
58
|
-
return nextValueHandler(from, to);
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
function matchValid(from, to, valueParser) {
|
|
62
|
-
const fromType = getType(from);
|
|
63
|
-
const toType = getType(to);
|
|
64
|
-
if (fromType !== toType) throwType('animation/stepAnimation', 'from and to must be the same type');
|
|
65
|
-
if ('array' === fromType) {
|
|
66
|
-
if (from.length !== to.length) throwType('animation/stepAnimation', 'from and to must be the same length');
|
|
67
|
-
const result = [
|
|
68
|
-
Array.from({
|
|
69
|
-
length: from.length
|
|
70
|
-
}),
|
|
71
|
-
Array.from({
|
|
72
|
-
length: to.length
|
|
73
|
-
})
|
|
74
|
-
];
|
|
75
|
-
for(let i = 0; i < from.length; i++){
|
|
76
|
-
const [fromItem, toItem] = matchValid(from[i], to[i], valueParser);
|
|
77
|
-
result[0][i] = fromItem;
|
|
78
|
-
result[1][i] = toItem;
|
|
79
|
-
}
|
|
80
|
-
return result;
|
|
81
|
-
}
|
|
82
|
-
if ('object' === fromType) {
|
|
83
|
-
const toKeys = Reflect.ownKeys(to);
|
|
84
|
-
const fromKeys = new Set(Reflect.ownKeys(from));
|
|
85
|
-
const result = [
|
|
86
|
-
{},
|
|
87
|
-
{}
|
|
88
|
-
];
|
|
89
|
-
for(let i = 0; i < toKeys.length; i++){
|
|
90
|
-
const key = toKeys[i];
|
|
91
|
-
if (!fromKeys.has(key)) throwType('animation/stepAnimation', `from does not have this key: ${String(key)}`);
|
|
92
|
-
const [fromItem, toItem] = matchValid(from[key], to[key], valueParser);
|
|
93
|
-
result[0][key] = fromItem;
|
|
94
|
-
result[1][key] = toItem;
|
|
95
|
-
}
|
|
96
|
-
return result;
|
|
97
|
-
}
|
|
98
|
-
if ('number' !== fromType) return [
|
|
99
|
-
valueParser(from),
|
|
100
|
-
valueParser(to)
|
|
101
|
-
];
|
|
102
|
-
return [
|
|
103
|
-
from,
|
|
104
|
-
to
|
|
105
|
-
];
|
|
106
|
-
}
|
|
107
|
-
function createNextTick(resolvers, rcSignal) {
|
|
108
|
-
const nextTick = (()=>{
|
|
109
|
-
if ('function' == typeof globalThis.requestAnimationFrame) return globalThis.requestAnimationFrame;
|
|
110
|
-
return (callback)=>setTimeout(callback, 16);
|
|
111
|
-
})();
|
|
112
|
-
return (callback)=>{
|
|
113
|
-
if (rcSignal.stopSignal) return true;
|
|
114
|
-
nextTick(()=>tryRun(callback, resolvers, (error)=>{
|
|
115
|
-
rcSignal.stop();
|
|
116
|
-
resolvers.reject(error);
|
|
117
|
-
}));
|
|
118
|
-
return false;
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
async function tryRun(callback, resolvers, customErrorHandler) {
|
|
122
|
-
return new Promise((resolve, reject)=>{
|
|
123
|
-
const result = callback();
|
|
124
|
-
if (result && 'function' == typeof result.then) return result.then(resolve, reject);
|
|
125
|
-
resolve();
|
|
126
|
-
}).catch(customErrorHandler || resolvers.reject);
|
|
127
|
-
}
|
|
128
|
-
function createRunningControllerSignal(startFn, options) {
|
|
129
|
-
const { onStart, onStop, onClear } = options;
|
|
130
|
-
const resolvers = withResolvers();
|
|
131
|
-
const ctrl = {
|
|
132
|
-
stopSignal: true,
|
|
133
|
-
resolvers,
|
|
134
|
-
stop: ()=>{
|
|
135
|
-
ctrl.stopSignal = true;
|
|
136
|
-
onStop();
|
|
137
|
-
},
|
|
138
|
-
start: ()=>{
|
|
139
|
-
ctrl.stopSignal = false;
|
|
140
|
-
onStart();
|
|
141
|
-
startFn();
|
|
142
|
-
},
|
|
143
|
-
clear: ()=>{
|
|
144
|
-
ctrl.stopSignal = true;
|
|
145
|
-
onClear();
|
|
146
|
-
resolvers.resolve(true);
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
return ctrl;
|
|
150
|
-
}
|
|
151
|
-
function* stepAnimation(from, to, step, options = {}) {
|
|
152
|
-
if (!Number.isInteger(step) || step <= 0) throwError('stepAnimation', 'step must be a positive integer', RangeError);
|
|
153
|
-
const { parser: valueParser = identity, formatter: valueFormatter = identity } = options;
|
|
154
|
-
const [validFrom, validTo] = matchValid(from, to, valueParser);
|
|
155
|
-
const getNextValue = getNextValueHandler(validFrom, validTo, valueFormatter);
|
|
156
|
-
for(let i = 0; i <= step; i++){
|
|
157
|
-
const value = getNextValue(i / step);
|
|
158
|
-
yield value;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
const validInfo = $dt({
|
|
162
|
-
autoStart: $t.boolean(true),
|
|
163
|
-
easing: $t["function"](()=>identity),
|
|
164
|
-
onStart: $t["function"](()=>noop),
|
|
165
|
-
onStop: $t["function"](()=>noop),
|
|
166
|
-
onClear: $t["function"](()=>noop),
|
|
167
|
-
onUpdate: $t["function"](()=>noop),
|
|
168
|
-
onComplete: $t["function"](()=>noop),
|
|
169
|
-
formatter: $t["function"](()=>identity),
|
|
170
|
-
parser: $t["function"](()=>identity)
|
|
171
|
-
});
|
|
172
|
-
function animation(from, to, duration, options = {}) {
|
|
173
|
-
if (duration <= 0 || !Number.isInteger(duration)) throwError('animation', 'duration must be a positive integer', RangeError);
|
|
174
|
-
const validOptions = dataHandler(options, validInfo, {
|
|
175
|
-
unwrap: true
|
|
176
|
-
});
|
|
177
|
-
const [validFrom, validTo] = matchValid(from, to, validOptions.parser);
|
|
178
|
-
const { autoStart, easing, onComplete, onUpdate, formatter: valueFormatter } = validOptions;
|
|
179
|
-
const getNextValue = getNextValueHandler(validFrom, validTo, valueFormatter);
|
|
180
|
-
let startTime = 0;
|
|
181
|
-
let hasStarted = false;
|
|
182
|
-
const rcSignal = createRunningControllerSignal(()=>{
|
|
183
|
-
const now = performance.now();
|
|
184
|
-
startTime += now;
|
|
185
|
-
const stopFlag = nextTick(tick);
|
|
186
|
-
if (stopFlag) {
|
|
187
|
-
startTime -= performance.now();
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
if (!hasStarted) {
|
|
191
|
-
onUpdate(getNextValue(0));
|
|
192
|
-
hasStarted = true;
|
|
193
|
-
}
|
|
194
|
-
}, validOptions);
|
|
195
|
-
const { resolvers } = rcSignal;
|
|
196
|
-
const nextTick = createNextTick(resolvers, rcSignal);
|
|
197
|
-
const tick = ()=>{
|
|
198
|
-
const elapsed = performance.now() - startTime;
|
|
199
|
-
const progress = easing(Math.min(elapsed / duration, 1));
|
|
200
|
-
const value = getNextValue(progress);
|
|
201
|
-
onUpdate(value);
|
|
202
|
-
if (elapsed < duration) {
|
|
203
|
-
const stopFlag = nextTick(tick);
|
|
204
|
-
if (stopFlag) startTime = -elapsed;
|
|
205
|
-
} else {
|
|
206
|
-
onComplete();
|
|
207
|
-
resolvers.resolve(false);
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
if (false !== autoStart) rcSignal.start();
|
|
211
|
-
return {
|
|
212
|
-
promise: resolvers.promise,
|
|
213
|
-
stop: rcSignal.stop,
|
|
214
|
-
start: rcSignal.start,
|
|
215
|
-
clear: rcSignal.clear
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
function getEmpty(_v) {
|
|
219
|
-
return Array.isArray(_v) ? [] : {};
|
|
220
|
-
}
|
|
221
|
-
function valueCheck(_v) {
|
|
222
|
-
return Array.isArray(_v) || 'object' == typeof _v;
|
|
223
|
-
}
|
|
224
|
-
function conditionMerge(...input) {
|
|
225
|
-
const conditionItems = (input.length > 1 ? input : input[0]).map((item)=>{
|
|
226
|
-
let result = null;
|
|
227
|
-
if (Array.isArray(item)) {
|
|
228
|
-
const [condition, value, fullback] = item;
|
|
229
|
-
result = {
|
|
230
|
-
condition,
|
|
231
|
-
value,
|
|
232
|
-
fullback
|
|
233
|
-
};
|
|
234
|
-
} else if (Object.getOwnPropertyDescriptor(item, 'condition')) result = item;
|
|
235
|
-
else throwType('conditionMerge', 'input must be an ConditionItem');
|
|
236
|
-
const validValue = valueCheck(result.value);
|
|
237
|
-
const validFullback = void 0 === result.fullback || valueCheck(result.fullback);
|
|
238
|
-
if (!(validValue && validFullback)) throwType('conditionMerge', 'value and fullback must be an array or object');
|
|
239
|
-
return result;
|
|
240
|
-
});
|
|
241
|
-
const result = getEmpty(conditionItems[0].value);
|
|
242
|
-
const mergeFn = Array.isArray(result) ? (a1, a2)=>Reflect.apply(Array.prototype.splice.bind(a1, a1.length, 0), null, a2) : Object.assign;
|
|
243
|
-
for(let i = 0, item = conditionItems[i]; i < conditionItems.length; item = conditionItems[++i])mergeFn(result, item.condition ? item.value : item.fullback || getEmpty(item.value));
|
|
244
|
-
return result;
|
|
245
|
-
}
|
|
246
|
-
const create_storage_handler_validInfo = $dt({
|
|
247
|
-
storageKey: 'validString',
|
|
248
|
-
storageType: $t["enum"]([
|
|
249
|
-
'local',
|
|
250
|
-
'session',
|
|
251
|
-
'memory'
|
|
252
|
-
], 'local'),
|
|
253
|
-
autoSaveInterval: $t.number(0)
|
|
254
|
-
});
|
|
255
|
-
const memoryStorage = {
|
|
256
|
-
data: {},
|
|
257
|
-
getItem (key) {
|
|
258
|
-
return this.data[key];
|
|
259
|
-
},
|
|
260
|
-
setItem (key, value) {
|
|
261
|
-
this.data[key] = value;
|
|
262
|
-
},
|
|
263
|
-
removeItem (key) {
|
|
264
|
-
delete this.data[key];
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
function getStorage(storageType) {
|
|
268
|
-
try {
|
|
269
|
-
if ('memory' === storageType) return memoryStorage;
|
|
270
|
-
return 'local' === storageType ? localStorage : sessionStorage;
|
|
271
|
-
} catch {
|
|
272
|
-
logger.warn('createStorage', 'Failed to access localStorage or sessionStorage, using memoryStorage instead.');
|
|
273
|
-
return memoryStorage;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
const CLEAR_FLAG = Symbol('cleared');
|
|
277
|
-
function createStorageHandler(storageKey, initialData, options = {}) {
|
|
278
|
-
const { storageKey: validStorageKey, storageType, autoSaveInterval } = dataHandler({
|
|
279
|
-
storageKey,
|
|
280
|
-
...options
|
|
281
|
-
}, create_storage_handler_validInfo, {
|
|
282
|
-
unwrap: true
|
|
283
|
-
});
|
|
284
|
-
const storage = getStorage(storageType);
|
|
285
|
-
const storageData = storage.getItem(validStorageKey);
|
|
286
|
-
const context = {
|
|
287
|
-
data: storageData ? JSON.parse(storageData) : initialData || {}
|
|
288
|
-
};
|
|
289
|
-
return {
|
|
290
|
-
get (key) {
|
|
291
|
-
if (context.data === CLEAR_FLAG) throwError('createStorageHandler', 'Storage has been cleared.');
|
|
292
|
-
if (null == key) return context.data;
|
|
293
|
-
return context.data[key];
|
|
294
|
-
},
|
|
295
|
-
set (value, key) {
|
|
296
|
-
if (context.data === CLEAR_FLAG) throwError('createStorageHandler', 'Storage has been cleared.');
|
|
297
|
-
if (null == key) context.data = value;
|
|
298
|
-
else context.data[key] = value;
|
|
299
|
-
if (autoSaveInterval > 0) setTimeout(()=>{
|
|
300
|
-
storage.setItem(validStorageKey, JSON.stringify(context.data));
|
|
301
|
-
}, autoSaveInterval);
|
|
302
|
-
else storage.setItem(validStorageKey, JSON.stringify(context.data));
|
|
303
|
-
},
|
|
304
|
-
clear () {
|
|
305
|
-
context.data = CLEAR_FLAG;
|
|
306
|
-
storage.removeItem(validStorageKey);
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
Symbol('__PACK__');
|
|
311
|
-
export { animation, conditionMerge, createStorageHandler, stepAnimation, withResolvers };
|