@flowgram.ai/utils 0.1.0-alpha.3 → 0.1.0-alpha.31
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/esm/index.js +62 -40
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +181 -21
- package/dist/index.d.ts +181 -21
- package/dist/index.js +66 -43
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { interfaces } from 'inversify';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
5
|
+
* SPDX-License-Identifier: MIT
|
|
6
|
+
*/
|
|
3
7
|
declare const PI: number;
|
|
4
8
|
/** Two Pi. */
|
|
5
9
|
declare const PI_2: number;
|
|
@@ -21,6 +25,10 @@ declare enum SHAPES {
|
|
|
21
25
|
RREC = 4
|
|
22
26
|
}
|
|
23
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
30
|
+
* SPDX-License-Identifier: MIT
|
|
31
|
+
*/
|
|
24
32
|
declare class Vector2 {
|
|
25
33
|
x: number;
|
|
26
34
|
y: number;
|
|
@@ -35,6 +43,10 @@ declare class Vector2 {
|
|
|
35
43
|
dot(v: Vector2): number;
|
|
36
44
|
}
|
|
37
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
48
|
+
* SPDX-License-Identifier: MIT
|
|
49
|
+
*/
|
|
38
50
|
/**
|
|
39
51
|
* Common interface for points. Both Point and ObservablePoint implement it
|
|
40
52
|
*/
|
|
@@ -49,6 +61,10 @@ interface IPoint {
|
|
|
49
61
|
y: number;
|
|
50
62
|
}
|
|
51
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
66
|
+
* SPDX-License-Identifier: MIT
|
|
67
|
+
*/
|
|
52
68
|
type SchemaType = 'string' | 'integer' | 'float' | 'boolean' | 'enum' | 'object' | 'range' | 'color' | 'array';
|
|
53
69
|
interface SchemaMixinDefaults {
|
|
54
70
|
[defaultKey: string]: any;
|
|
@@ -101,6 +117,11 @@ declare namespace Schema {
|
|
|
101
117
|
function isBaseType(decoration: SchemaDecoration): boolean;
|
|
102
118
|
}
|
|
103
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
122
|
+
* SPDX-License-Identifier: MIT
|
|
123
|
+
*/
|
|
124
|
+
|
|
104
125
|
interface PositionSchema {
|
|
105
126
|
x: number;
|
|
106
127
|
y: number;
|
|
@@ -165,6 +186,11 @@ declare namespace SizeSchema {
|
|
|
165
186
|
function empty(): SizeSchema;
|
|
166
187
|
}
|
|
167
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
191
|
+
* SPDX-License-Identifier: MIT
|
|
192
|
+
*/
|
|
193
|
+
|
|
168
194
|
type OpacitySchema = number;
|
|
169
195
|
interface FlipSchema {
|
|
170
196
|
x: boolean;
|
|
@@ -207,6 +233,11 @@ declare const ShadowSchemaDecoration: SchemaDecoration<ShadowSchema>;
|
|
|
207
233
|
declare const TintSchemaDecoration: SchemaDecoration<TintSchema>;
|
|
208
234
|
declare const OpacitySchemaDecoration: SchemaDecoration<OpacitySchema>;
|
|
209
235
|
|
|
236
|
+
/**
|
|
237
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
238
|
+
* SPDX-License-Identifier: MIT
|
|
239
|
+
*/
|
|
240
|
+
|
|
210
241
|
/**
|
|
211
242
|
* Size object, contains width and height
|
|
212
243
|
*/
|
|
@@ -389,6 +420,11 @@ declare class OBBRect {
|
|
|
389
420
|
getProjectionRadius(axis: Vector2): number;
|
|
390
421
|
}
|
|
391
422
|
|
|
423
|
+
/**
|
|
424
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
425
|
+
* SPDX-License-Identifier: MIT
|
|
426
|
+
*/
|
|
427
|
+
|
|
392
428
|
/**
|
|
393
429
|
* The Circle object is used to help draw graphics and can also be used to specify a hit area for displayObjects.
|
|
394
430
|
*/
|
|
@@ -425,6 +461,11 @@ declare class Circle {
|
|
|
425
461
|
getBounds(): Rectangle;
|
|
426
462
|
}
|
|
427
463
|
|
|
464
|
+
/**
|
|
465
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
466
|
+
* SPDX-License-Identifier: MIT
|
|
467
|
+
*/
|
|
468
|
+
|
|
428
469
|
/**
|
|
429
470
|
* The Point object represents a location in a two-dimensional coordinate system, where x represents
|
|
430
471
|
* the horizontal axis and y represents the vertical axis.
|
|
@@ -496,6 +537,11 @@ declare class ObservablePoint<T = any> implements IPoint {
|
|
|
496
537
|
equals(p: IPoint): boolean;
|
|
497
538
|
}
|
|
498
539
|
|
|
540
|
+
/**
|
|
541
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
542
|
+
* SPDX-License-Identifier: MIT
|
|
543
|
+
*/
|
|
544
|
+
|
|
499
545
|
/**
|
|
500
546
|
* Transform that takes care about its versions
|
|
501
547
|
*
|
|
@@ -564,6 +610,11 @@ declare class Transform {
|
|
|
564
610
|
set rotation(value: number);
|
|
565
611
|
}
|
|
566
612
|
|
|
613
|
+
/**
|
|
614
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
615
|
+
* SPDX-License-Identifier: MIT
|
|
616
|
+
*/
|
|
617
|
+
|
|
567
618
|
/**
|
|
568
619
|
* The PIXIJS Matrix as a class makes it a lot faster.
|
|
569
620
|
*
|
|
@@ -727,6 +778,11 @@ declare class Matrix {
|
|
|
727
778
|
copyFrom(matrix: Matrix): this;
|
|
728
779
|
}
|
|
729
780
|
|
|
781
|
+
/**
|
|
782
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
783
|
+
* SPDX-License-Identifier: MIT
|
|
784
|
+
*/
|
|
785
|
+
|
|
730
786
|
/**
|
|
731
787
|
* The Point object represents a location in a two-dimensional coordinate system, where x represents
|
|
732
788
|
* the horizontal axis and y represents the vertical axis.
|
|
@@ -811,6 +867,11 @@ declare namespace Point {
|
|
|
811
867
|
function moveDistanceToDirection(current: IPoint, direction: IPoint, distance: number): IPoint;
|
|
812
868
|
}
|
|
813
869
|
|
|
870
|
+
/**
|
|
871
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
872
|
+
* SPDX-License-Identifier: MIT
|
|
873
|
+
*/
|
|
874
|
+
|
|
814
875
|
declare namespace Angle {
|
|
815
876
|
/**
|
|
816
877
|
* Wrap an angle.
|
|
@@ -838,8 +899,18 @@ declare namespace Angle {
|
|
|
838
899
|
function betweenPoints(point1: IPoint, point2: IPoint, originPoint?: IPoint): number;
|
|
839
900
|
}
|
|
840
901
|
|
|
902
|
+
/**
|
|
903
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
904
|
+
* SPDX-License-Identifier: MIT
|
|
905
|
+
*/
|
|
841
906
|
declare function deepFreeze<T>(obj: T): T;
|
|
842
907
|
declare function notEmpty<T>(arg: T | undefined | null): arg is T;
|
|
908
|
+
/**
|
|
909
|
+
* filter dangerous key, prevent prototype pollution injection
|
|
910
|
+
* @param key key to be filtered
|
|
911
|
+
* @returns filtered key
|
|
912
|
+
*/
|
|
913
|
+
declare const safeKey: (key: string) => string;
|
|
843
914
|
/**
|
|
844
915
|
* `true` if the argument is an empty object. Otherwise, `false`.
|
|
845
916
|
*/
|
|
@@ -889,6 +960,10 @@ declare const NOOP: () => void;
|
|
|
889
960
|
*/
|
|
890
961
|
declare function isPlainObject(obj: any): boolean;
|
|
891
962
|
|
|
963
|
+
/**
|
|
964
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
965
|
+
* SPDX-License-Identifier: MIT
|
|
966
|
+
*/
|
|
892
967
|
interface AsClass<T> {
|
|
893
968
|
new (...args: any[]): T;
|
|
894
969
|
}
|
|
@@ -905,7 +980,15 @@ type MaybePromise<T> = T | PromiseLike<T>;
|
|
|
905
980
|
type RecursivePartial<T> = {
|
|
906
981
|
[P in keyof T]?: T[P] extends Array<infer I> ? Array<RecursivePartial<I>> : RecursivePartial<T[P]>;
|
|
907
982
|
};
|
|
983
|
+
type Without<T, U> = {
|
|
984
|
+
[P in Exclude<keyof T, keyof U>]?: never;
|
|
985
|
+
};
|
|
986
|
+
type Xor<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
|
|
908
987
|
|
|
988
|
+
/**
|
|
989
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
990
|
+
* SPDX-License-Identifier: MIT
|
|
991
|
+
*/
|
|
909
992
|
/**
|
|
910
993
|
* An object that performs a cleanup operation when `.dispose()` is called.
|
|
911
994
|
*
|
|
@@ -922,25 +1005,11 @@ declare namespace Disposable {
|
|
|
922
1005
|
function create(func: () => void): Disposable;
|
|
923
1006
|
const NULL: Readonly<Disposable>;
|
|
924
1007
|
}
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
}
|
|
931
|
-
declare class DisposableCollection implements Disposable {
|
|
932
|
-
protected readonly disposables: (Disposable & {
|
|
933
|
-
_origin: Disposable;
|
|
934
|
-
})[];
|
|
935
|
-
protected readonly onDisposeEmitter: Emitter<void>;
|
|
936
|
-
private _disposed;
|
|
937
|
-
constructor(...toDispose: Disposable[]);
|
|
938
|
-
get onDispose(): Event<void>;
|
|
939
|
-
get disposed(): boolean;
|
|
940
|
-
dispose(): void;
|
|
941
|
-
push(disposable: Disposable): Disposable;
|
|
942
|
-
pushAll(disposables: Disposable[]): Disposable[];
|
|
943
|
-
}
|
|
1008
|
+
|
|
1009
|
+
/**
|
|
1010
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1011
|
+
* SPDX-License-Identifier: MIT
|
|
1012
|
+
*/
|
|
944
1013
|
|
|
945
1014
|
interface EventListener$1<T> {
|
|
946
1015
|
(args: T): void;
|
|
@@ -952,7 +1021,6 @@ declare namespace Event {
|
|
|
952
1021
|
const None: Event<any>;
|
|
953
1022
|
}
|
|
954
1023
|
declare class Emitter<T = any> {
|
|
955
|
-
static LEAK_WARNING_THRESHHOLD: number;
|
|
956
1024
|
private _event?;
|
|
957
1025
|
private _listeners?;
|
|
958
1026
|
private _disposed;
|
|
@@ -962,6 +1030,35 @@ declare class Emitter<T = any> {
|
|
|
962
1030
|
dispose(): void;
|
|
963
1031
|
}
|
|
964
1032
|
|
|
1033
|
+
/**
|
|
1034
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1035
|
+
* SPDX-License-Identifier: MIT
|
|
1036
|
+
*/
|
|
1037
|
+
|
|
1038
|
+
declare class DisposableImpl implements Disposable {
|
|
1039
|
+
readonly toDispose: DisposableCollection;
|
|
1040
|
+
dispose(): void;
|
|
1041
|
+
get disposed(): boolean;
|
|
1042
|
+
get onDispose(): Event<void>;
|
|
1043
|
+
}
|
|
1044
|
+
declare class DisposableCollection implements Disposable {
|
|
1045
|
+
protected readonly disposables: Disposable[];
|
|
1046
|
+
protected readonly onDisposeEmitter: Emitter<void>;
|
|
1047
|
+
private _disposed;
|
|
1048
|
+
constructor(...toDispose: Disposable[]);
|
|
1049
|
+
get length(): number;
|
|
1050
|
+
get onDispose(): Event<void>;
|
|
1051
|
+
get disposed(): boolean;
|
|
1052
|
+
dispose(): void;
|
|
1053
|
+
push(disposable: Disposable): Disposable;
|
|
1054
|
+
pushAll(disposables: Disposable[]): Disposable[];
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
/**
|
|
1058
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1059
|
+
* SPDX-License-Identifier: MIT
|
|
1060
|
+
*/
|
|
1061
|
+
|
|
965
1062
|
interface CancellationToken {
|
|
966
1063
|
/**
|
|
967
1064
|
* A flag signalling is cancellation has been requested.
|
|
@@ -999,6 +1096,11 @@ declare function cancelled(): Error;
|
|
|
999
1096
|
declare function isCancelled(err: Error | undefined): boolean;
|
|
1000
1097
|
declare function checkCancelled(token?: CancellationToken): void;
|
|
1001
1098
|
|
|
1099
|
+
/**
|
|
1100
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1101
|
+
* SPDX-License-Identifier: MIT
|
|
1102
|
+
*/
|
|
1103
|
+
|
|
1002
1104
|
/**
|
|
1003
1105
|
* Simple implementation of the deferred pattern.
|
|
1004
1106
|
* An object that exposes a promise and functions to resolve and reject it.
|
|
@@ -1035,6 +1137,11 @@ declare class PromisePool {
|
|
|
1035
1137
|
run<T>(tasks: PromiseTask<T>[], checkIfRetry?: (res: T) => boolean): Promise<T[]>;
|
|
1036
1138
|
}
|
|
1037
1139
|
|
|
1140
|
+
/**
|
|
1141
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1142
|
+
* SPDX-License-Identifier: MIT
|
|
1143
|
+
*/
|
|
1144
|
+
|
|
1038
1145
|
interface CacheManager<T, ITEM extends CacheOriginItem = CacheOriginItem> extends Disposable {
|
|
1039
1146
|
get(): T;
|
|
1040
1147
|
getMore(count: number, autoDelete?: boolean): T[];
|
|
@@ -1101,6 +1208,10 @@ declare namespace Cache {
|
|
|
1101
1208
|
function createWeakCache(): WeakCache;
|
|
1102
1209
|
}
|
|
1103
1210
|
|
|
1211
|
+
/**
|
|
1212
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1213
|
+
* SPDX-License-Identifier: MIT
|
|
1214
|
+
*/
|
|
1104
1215
|
declare namespace Compare {
|
|
1105
1216
|
/**
|
|
1106
1217
|
* 比较,默认浅比较
|
|
@@ -1120,6 +1231,11 @@ declare namespace Compare {
|
|
|
1120
1231
|
function isArrayShallowChanged(arr1: any[], arr2: any[]): boolean;
|
|
1121
1232
|
}
|
|
1122
1233
|
|
|
1234
|
+
/**
|
|
1235
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1236
|
+
* SPDX-License-Identifier: MIT
|
|
1237
|
+
*/
|
|
1238
|
+
|
|
1123
1239
|
type CSSStyle = {
|
|
1124
1240
|
[P in keyof CSSStyleDeclaration]?: string | number | undefined;
|
|
1125
1241
|
};
|
|
@@ -1153,10 +1269,18 @@ declare namespace domUtils {
|
|
|
1153
1269
|
function createDOMCache<T extends DOMCache = DOMCache>(parent: HTMLElement, className: string | (() => HTMLElement), children?: string): CacheManager<T>;
|
|
1154
1270
|
}
|
|
1155
1271
|
|
|
1272
|
+
/**
|
|
1273
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1274
|
+
* SPDX-License-Identifier: MIT
|
|
1275
|
+
*/
|
|
1156
1276
|
type LocalId = number;
|
|
1157
1277
|
declare function generateLocalId(): LocalId;
|
|
1158
1278
|
declare function _setIdx(idx: number): void;
|
|
1159
1279
|
|
|
1280
|
+
/**
|
|
1281
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1282
|
+
* SPDX-License-Identifier: MIT
|
|
1283
|
+
*/
|
|
1160
1284
|
declare function iterToArray<T = any>(iter: IterableIterator<T>): T[];
|
|
1161
1285
|
declare function arrayToSet(arr: any[]): Set<any>;
|
|
1162
1286
|
/**
|
|
@@ -1167,8 +1291,17 @@ declare function arrayToSet(arr: any[]): Set<any>;
|
|
|
1167
1291
|
*/
|
|
1168
1292
|
declare function arrayUnion(arr: any[]): any[];
|
|
1169
1293
|
|
|
1294
|
+
/**
|
|
1295
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1296
|
+
* SPDX-License-Identifier: MIT
|
|
1297
|
+
*/
|
|
1298
|
+
|
|
1170
1299
|
declare function bindContributions(bind: interfaces.Bind, target: any, contribs: any[]): void;
|
|
1171
1300
|
|
|
1301
|
+
/**
|
|
1302
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1303
|
+
* SPDX-License-Identifier: MIT
|
|
1304
|
+
*/
|
|
1172
1305
|
type RequestFn = (...args: any[]) => Promise<any>;
|
|
1173
1306
|
/**
|
|
1174
1307
|
* 请求缓存
|
|
@@ -1178,12 +1311,22 @@ declare const RequestCache: Map<any, Promise<any>>;
|
|
|
1178
1311
|
declare function clearRequestCache(): void;
|
|
1179
1312
|
declare function requestWithMemo(req: RequestFn, cacheTime?: number, createCacheKey?: (...args: any[]) => any): RequestFn;
|
|
1180
1313
|
|
|
1314
|
+
/**
|
|
1315
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1316
|
+
* SPDX-License-Identifier: MIT
|
|
1317
|
+
*/
|
|
1318
|
+
|
|
1181
1319
|
type FuncMaybePromise<D> = (d: D, ...others: any[]) => MaybePromise<D>;
|
|
1182
1320
|
type FuncPromise<D> = (d: D, ...others: any[]) => Promise<D>;
|
|
1183
1321
|
type Func<D> = (d: D, ...others: any[]) => D;
|
|
1184
1322
|
declare function composeAsync<D>(...fns: FuncMaybePromise<D>[]): FuncPromise<D>;
|
|
1185
1323
|
declare function compose<D>(...fns: Func<D>[]): Func<D>;
|
|
1186
1324
|
|
|
1325
|
+
/**
|
|
1326
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1327
|
+
* SPDX-License-Identifier: MIT
|
|
1328
|
+
*/
|
|
1329
|
+
|
|
1187
1330
|
declare const ContributionProvider: unique symbol;
|
|
1188
1331
|
interface ContributionProvider<T extends object> {
|
|
1189
1332
|
getContributions(): T[];
|
|
@@ -1191,10 +1334,19 @@ interface ContributionProvider<T extends object> {
|
|
|
1191
1334
|
}
|
|
1192
1335
|
declare function bindContributionProvider(bind: interfaces.Bind, id: symbol): void;
|
|
1193
1336
|
|
|
1337
|
+
/**
|
|
1338
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1339
|
+
* SPDX-License-Identifier: MIT
|
|
1340
|
+
*/
|
|
1341
|
+
|
|
1194
1342
|
type EventListener<K extends keyof HTMLElementEventMap> = (this: HTMLElement, event: HTMLElementEventMap[K]) => any;
|
|
1195
1343
|
type EventListenerOrEventListenerObject$1<K extends keyof HTMLElementEventMap> = EventListener<K>;
|
|
1196
1344
|
declare function addEventListener<K extends keyof HTMLElementEventMap>(element: HTMLElement, type: K, listener: EventListenerOrEventListenerObject$1<K>, useCapture?: boolean): Disposable;
|
|
1197
1345
|
|
|
1346
|
+
/**
|
|
1347
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1348
|
+
* SPDX-License-Identifier: MIT
|
|
1349
|
+
*/
|
|
1198
1350
|
declare class Logger {
|
|
1199
1351
|
isDevEnv(): boolean;
|
|
1200
1352
|
info(...props: any): void;
|
|
@@ -1204,11 +1356,19 @@ declare class Logger {
|
|
|
1204
1356
|
}
|
|
1205
1357
|
declare const logger: Logger;
|
|
1206
1358
|
|
|
1359
|
+
/**
|
|
1360
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1361
|
+
* SPDX-License-Identifier: MIT
|
|
1362
|
+
*/
|
|
1207
1363
|
declare function createStyleElement(styleId: string, container?: HTMLElement): HTMLStyleElement;
|
|
1208
1364
|
declare const DecorationStyle: {
|
|
1209
1365
|
createStyleElement: typeof createStyleElement;
|
|
1210
1366
|
};
|
|
1211
1367
|
|
|
1368
|
+
/**
|
|
1369
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1370
|
+
* SPDX-License-Identifier: MIT
|
|
1371
|
+
*/
|
|
1212
1372
|
declare function useRefresh(defaultValue?: any): (v?: any) => void;
|
|
1213
1373
|
|
|
1214
|
-
export { Angle, type AsClass, type CSSStyle, Cache, type CacheManager, type CacheOpts, type CacheOriginItem, CancellationToken, CancellationTokenSource, Circle, Compare, ContributionProvider, CropSchemaDecoration, DEG_TO_RAD, type DOMCache, DecorationStyle, Deferred, Disposable, DisposableCollection, DisposableImpl, Emitter, Event, type EventListener$1 as EventListener, type FlipSchema, FlipSchemaDecoration, type IPoint, type ISize, type LocalId, type MarginSchema, Matrix, type MaybeArray, type MaybePromise, MutableToken, NOOP, OBBRect, type OpacitySchema, OpacitySchemaDecoration, type OriginSchema, OriginSchemaDecoration, PI, PI_2, PaddingSchema, PaddingSchemaDecoration, Point, type PositionSchema, PositionSchemaDecoration, PromiseDeferred, PromisePool, type PromisePoolOpts, type PromiseTask, RAD_TO_DEG, Rectangle, RectangleAlignTitle, RectangleAlignType, type RecursivePartial, RequestCache, type RotationSchema, RotationSchemaDecoration, SHAPES, type ScaleSchema, ScaleSchemaDecoration, Schema, SchemaDecoration, type SchemaType, type ScrollSchema, type ShadowSchema, ShadowSchemaDecoration, type ShortCache, SizeSchema, SizeSchemaDecoration, type SkewSchema, SkewSchemaDecoration, TintSchema, TintSchemaDecoration, Transform, TransformSchema, TransformSchemaDecoration, type WeakCache, _setIdx, addEventListener, arrayToSet, arrayUnion, bindContributionProvider, bindContributions, cancelled, checkCancelled, clearRequestCache, compose, composeAsync, deepFreeze, delay, domUtils, each, filter, generateLocalId, getByKey, getTag, isCancelled, isEmpty, isFunction, isNumber, isObject, isPlainObject, isString, iterToArray, logger, mapKeys, mapValues, notEmpty, omit, pick, reduce, requestWithMemo, retry, setByKey, useRefresh, values };
|
|
1374
|
+
export { Angle, type AsClass, type CSSStyle, Cache, type CacheManager, type CacheOpts, type CacheOriginItem, CancellationToken, CancellationTokenSource, Circle, Compare, ContributionProvider, CropSchemaDecoration, DEG_TO_RAD, type DOMCache, DecorationStyle, Deferred, Disposable, DisposableCollection, DisposableImpl, Emitter, Event, type EventListener$1 as EventListener, type FlipSchema, FlipSchemaDecoration, type IPoint, type ISize, type LocalId, type MarginSchema, Matrix, type MaybeArray, type MaybePromise, MutableToken, NOOP, OBBRect, type OpacitySchema, OpacitySchemaDecoration, type OriginSchema, OriginSchemaDecoration, PI, PI_2, PaddingSchema, PaddingSchemaDecoration, Point, type PositionSchema, PositionSchemaDecoration, PromiseDeferred, PromisePool, type PromisePoolOpts, type PromiseTask, RAD_TO_DEG, Rectangle, RectangleAlignTitle, RectangleAlignType, type RecursivePartial, RequestCache, type RotationSchema, RotationSchemaDecoration, SHAPES, type ScaleSchema, ScaleSchemaDecoration, Schema, SchemaDecoration, type SchemaType, type ScrollSchema, type ShadowSchema, ShadowSchemaDecoration, type ShortCache, SizeSchema, SizeSchemaDecoration, type SkewSchema, SkewSchemaDecoration, TintSchema, TintSchemaDecoration, Transform, TransformSchema, TransformSchemaDecoration, type WeakCache, type Xor, _setIdx, addEventListener, arrayToSet, arrayUnion, bindContributionProvider, bindContributions, cancelled, checkCancelled, clearRequestCache, compose, composeAsync, deepFreeze, delay, domUtils, each, filter, generateLocalId, getByKey, getTag, isCancelled, isEmpty, isFunction, isNumber, isObject, isPlainObject, isString, iterToArray, logger, mapKeys, mapValues, notEmpty, omit, pick, reduce, requestWithMemo, retry, safeKey, setByKey, useRefresh, values };
|
package/dist/index.js
CHANGED
|
@@ -28,8 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
30
|
// src/index.ts
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
33
|
Angle: () => Angle,
|
|
34
34
|
Cache: () => Cache,
|
|
35
35
|
CancellationToken: () => CancellationToken,
|
|
@@ -116,11 +116,12 @@ __export(src_exports, {
|
|
|
116
116
|
reduce: () => reduce,
|
|
117
117
|
requestWithMemo: () => requestWithMemo,
|
|
118
118
|
retry: () => retry,
|
|
119
|
+
safeKey: () => safeKey,
|
|
119
120
|
setByKey: () => setByKey,
|
|
120
121
|
useRefresh: () => useRefresh,
|
|
121
122
|
values: () => values
|
|
122
123
|
});
|
|
123
|
-
module.exports = __toCommonJS(
|
|
124
|
+
module.exports = __toCommonJS(index_exports);
|
|
124
125
|
|
|
125
126
|
// src/math/const.ts
|
|
126
127
|
var { PI } = Math;
|
|
@@ -1399,6 +1400,27 @@ var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
|
1399
1400
|
function notEmpty(arg) {
|
|
1400
1401
|
return arg !== void 0 && arg !== null;
|
|
1401
1402
|
}
|
|
1403
|
+
var safeKey = (key) => {
|
|
1404
|
+
const dangerousProps = [
|
|
1405
|
+
"__proto__",
|
|
1406
|
+
"constructor",
|
|
1407
|
+
"prototype",
|
|
1408
|
+
"__defineGetter__",
|
|
1409
|
+
"__defineSetter__",
|
|
1410
|
+
"__lookupGetter__",
|
|
1411
|
+
"__lookupSetter__",
|
|
1412
|
+
"hasOwnProperty",
|
|
1413
|
+
"isPrototypeOf",
|
|
1414
|
+
"propertyIsEnumerable",
|
|
1415
|
+
"toString",
|
|
1416
|
+
"valueOf",
|
|
1417
|
+
"toLocaleString"
|
|
1418
|
+
];
|
|
1419
|
+
if (dangerousProps.includes(key.toLowerCase())) {
|
|
1420
|
+
return "";
|
|
1421
|
+
}
|
|
1422
|
+
return key;
|
|
1423
|
+
};
|
|
1402
1424
|
function isEmpty(arg) {
|
|
1403
1425
|
return keys(arg).length === 0 && arg.constructor === Object;
|
|
1404
1426
|
}
|
|
@@ -1430,18 +1452,18 @@ function setByKey(target, key, newValue, autoCreateObject = true, clone = false)
|
|
|
1430
1452
|
while (targetKeys.length > 0) {
|
|
1431
1453
|
key = targetKeys.shift();
|
|
1432
1454
|
if (targetKeys.length === 0) {
|
|
1433
|
-
target[key] = newValue;
|
|
1455
|
+
target[safeKey(key)] = newValue;
|
|
1434
1456
|
return originTarget;
|
|
1435
1457
|
}
|
|
1436
1458
|
if (typeof target[key] !== "object") {
|
|
1437
1459
|
if (!autoCreateObject) return originTarget;
|
|
1438
|
-
target[key] = {};
|
|
1460
|
+
target[safeKey(key)] = {};
|
|
1439
1461
|
}
|
|
1440
1462
|
if (clone) {
|
|
1441
1463
|
if (Array.isArray(target[key])) {
|
|
1442
|
-
target[key] = target[key].slice();
|
|
1464
|
+
target[safeKey(key)] = target[key].slice();
|
|
1443
1465
|
} else {
|
|
1444
|
-
target[key] = { ...target[key] };
|
|
1466
|
+
target[safeKey(key)] = { ...target[key] };
|
|
1445
1467
|
}
|
|
1446
1468
|
}
|
|
1447
1469
|
target = target[key];
|
|
@@ -1480,13 +1502,29 @@ function isNumber(v) {
|
|
|
1480
1502
|
return typeof v === "number" || isObject(v) && getTag(v) === "[object Number]";
|
|
1481
1503
|
}
|
|
1482
1504
|
|
|
1505
|
+
// src/disposable.ts
|
|
1506
|
+
var Disposable;
|
|
1507
|
+
((Disposable2) => {
|
|
1508
|
+
function is(thing) {
|
|
1509
|
+
return typeof thing === "object" && thing !== null && typeof thing.dispose === "function";
|
|
1510
|
+
}
|
|
1511
|
+
Disposable2.is = is;
|
|
1512
|
+
function create(func) {
|
|
1513
|
+
return {
|
|
1514
|
+
dispose: func
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
1517
|
+
Disposable2.create = create;
|
|
1518
|
+
Disposable2.NULL = Object.freeze(create(() => {
|
|
1519
|
+
}));
|
|
1520
|
+
})(Disposable || (Disposable = {}));
|
|
1521
|
+
|
|
1483
1522
|
// src/event.ts
|
|
1484
|
-
var DisposableNULL = Object.freeze({ dispose: NOOP });
|
|
1485
1523
|
var Event;
|
|
1486
|
-
((
|
|
1487
|
-
|
|
1524
|
+
((Event3) => {
|
|
1525
|
+
Event3.None = () => Disposable.NULL;
|
|
1488
1526
|
})(Event || (Event = {}));
|
|
1489
|
-
var
|
|
1527
|
+
var Emitter = class {
|
|
1490
1528
|
constructor() {
|
|
1491
1529
|
this._disposed = false;
|
|
1492
1530
|
}
|
|
@@ -1494,15 +1532,12 @@ var _Emitter = class _Emitter {
|
|
|
1494
1532
|
if (!this._event) {
|
|
1495
1533
|
this._event = (listener, thisArgs) => {
|
|
1496
1534
|
if (this._disposed) {
|
|
1497
|
-
return
|
|
1535
|
+
return Disposable.NULL;
|
|
1498
1536
|
}
|
|
1499
1537
|
if (!this._listeners) {
|
|
1500
1538
|
this._listeners = [];
|
|
1501
1539
|
}
|
|
1502
1540
|
const finalListener = thisArgs ? listener.bind(thisArgs) : listener;
|
|
1503
|
-
if (this._listeners.length >= _Emitter.LEAK_WARNING_THRESHHOLD) {
|
|
1504
|
-
console.warn(`[Emitter] Listeners length >= ${_Emitter.LEAK_WARNING_THRESHHOLD}`);
|
|
1505
|
-
}
|
|
1506
1541
|
this._listeners.push(finalListener);
|
|
1507
1542
|
const eventDisposable = {
|
|
1508
1543
|
dispose: () => {
|
|
@@ -1535,25 +1570,8 @@ var _Emitter = class _Emitter {
|
|
|
1535
1570
|
this._disposed = true;
|
|
1536
1571
|
}
|
|
1537
1572
|
};
|
|
1538
|
-
_Emitter.LEAK_WARNING_THRESHHOLD = 175;
|
|
1539
|
-
var Emitter = _Emitter;
|
|
1540
1573
|
|
|
1541
|
-
// src/disposable.ts
|
|
1542
|
-
var Disposable;
|
|
1543
|
-
((Disposable2) => {
|
|
1544
|
-
function is(thing) {
|
|
1545
|
-
return typeof thing === "object" && thing !== null && typeof thing.dispose === "function";
|
|
1546
|
-
}
|
|
1547
|
-
Disposable2.is = is;
|
|
1548
|
-
function create(func) {
|
|
1549
|
-
return {
|
|
1550
|
-
dispose: func
|
|
1551
|
-
};
|
|
1552
|
-
}
|
|
1553
|
-
Disposable2.create = create;
|
|
1554
|
-
Disposable2.NULL = Object.freeze(create(() => {
|
|
1555
|
-
}));
|
|
1556
|
-
})(Disposable || (Disposable = {}));
|
|
1574
|
+
// src/disposable-collection.ts
|
|
1557
1575
|
var DisposableImpl = class {
|
|
1558
1576
|
constructor() {
|
|
1559
1577
|
this.toDispose = new DisposableCollection();
|
|
@@ -1575,6 +1593,9 @@ var DisposableCollection = class {
|
|
|
1575
1593
|
this._disposed = false;
|
|
1576
1594
|
toDispose.forEach((d) => this.push(d));
|
|
1577
1595
|
}
|
|
1596
|
+
get length() {
|
|
1597
|
+
return this.disposables.length;
|
|
1598
|
+
}
|
|
1578
1599
|
get onDispose() {
|
|
1579
1600
|
return this.onDisposeEmitter.event;
|
|
1580
1601
|
}
|
|
@@ -1598,25 +1619,26 @@ var DisposableCollection = class {
|
|
|
1598
1619
|
}
|
|
1599
1620
|
push(disposable) {
|
|
1600
1621
|
if (this.disposed) return Disposable.NULL;
|
|
1622
|
+
if (disposable === Disposable.NULL) {
|
|
1623
|
+
return Disposable.NULL;
|
|
1624
|
+
}
|
|
1601
1625
|
const { disposables } = this;
|
|
1602
|
-
if (disposables.find((d) => d
|
|
1626
|
+
if (disposables.find((d) => d === disposable)) {
|
|
1603
1627
|
return Disposable.NULL;
|
|
1604
1628
|
}
|
|
1605
|
-
|
|
1629
|
+
const originalDispose = disposable.dispose;
|
|
1606
1630
|
const toRemove = Disposable.create(() => {
|
|
1607
|
-
const index = disposables.indexOf(
|
|
1631
|
+
const index = disposables.indexOf(disposable);
|
|
1608
1632
|
if (index !== -1) {
|
|
1609
1633
|
disposables.splice(index, 1);
|
|
1610
1634
|
}
|
|
1635
|
+
disposable.dispose = originalDispose;
|
|
1611
1636
|
});
|
|
1612
|
-
|
|
1613
|
-
dispose
|
|
1614
|
-
|
|
1615
|
-
disposable.dispose();
|
|
1616
|
-
},
|
|
1617
|
-
_origin: disposable
|
|
1637
|
+
disposable.dispose = () => {
|
|
1638
|
+
toRemove.dispose();
|
|
1639
|
+
disposable.dispose();
|
|
1618
1640
|
};
|
|
1619
|
-
disposables.push(
|
|
1641
|
+
disposables.push(disposable);
|
|
1620
1642
|
return toRemove;
|
|
1621
1643
|
}
|
|
1622
1644
|
pushAll(disposables) {
|
|
@@ -2611,6 +2633,7 @@ function useRefresh(defaultValue) {
|
|
|
2611
2633
|
reduce,
|
|
2612
2634
|
requestWithMemo,
|
|
2613
2635
|
retry,
|
|
2636
|
+
safeKey,
|
|
2614
2637
|
setByKey,
|
|
2615
2638
|
useRefresh,
|
|
2616
2639
|
values
|