@pawover/kit 0.0.0-alpha.9 → 0.0.0-beta.1

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.
Files changed (83) hide show
  1. package/dist/enums.d.ts +25 -0
  2. package/dist/enums.d.ts.map +1 -0
  3. package/dist/enums.js +25 -0
  4. package/dist/enums.js.map +1 -0
  5. package/dist/hooks-alova.d.ts +23 -0
  6. package/dist/hooks-alova.d.ts.map +1 -0
  7. package/dist/hooks-alova.js +39 -0
  8. package/dist/hooks-alova.js.map +1 -0
  9. package/dist/hooks-react.d.ts +89 -0
  10. package/dist/hooks-react.d.ts.map +1 -0
  11. package/dist/hooks-react.js +334 -0
  12. package/dist/hooks-react.js.map +1 -0
  13. package/dist/index.d.ts +2411 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +1375 -1
  16. package/dist/index.js.map +1 -0
  17. package/dist/patches-fetchEventSource.d.ts +806 -0
  18. package/dist/patches-fetchEventSource.d.ts.map +1 -0
  19. package/dist/patches-fetchEventSource.js +315 -0
  20. package/dist/patches-fetchEventSource.js.map +1 -0
  21. package/dist/vite.d.ts +13 -0
  22. package/dist/vite.d.ts.map +1 -0
  23. package/dist/vite.js +23 -0
  24. package/dist/vite.js.map +1 -0
  25. package/dist/zod.d.ts +105 -0
  26. package/dist/zod.d.ts.map +1 -0
  27. package/dist/zod.js +138 -0
  28. package/dist/zod.js.map +1 -0
  29. package/metadata.json +157 -0
  30. package/package.json +51 -35
  31. package/dist/enums/index.js +0 -20
  32. package/dist/hooks/react/index.js +0 -5
  33. package/dist/hooks/react/useCreation.js +0 -19
  34. package/dist/hooks/react/useLatest.js +0 -13
  35. package/dist/hooks/react/useMount.js +0 -29
  36. package/dist/hooks/react/useResponsive.js +0 -59
  37. package/dist/hooks/react/useUnmount.js +0 -18
  38. package/dist/types/enums/index.d.ts +0 -20
  39. package/dist/types/hooks/react/index.d.ts +0 -5
  40. package/dist/types/hooks/react/useCreation.d.ts +0 -10
  41. package/dist/types/hooks/react/useLatest.d.ts +0 -8
  42. package/dist/types/hooks/react/useMount.d.ts +0 -11
  43. package/dist/types/hooks/react/useResponsive.d.ts +0 -16
  44. package/dist/types/hooks/react/useUnmount.d.ts +0 -7
  45. package/dist/types/index.d.ts +0 -1
  46. package/dist/types/utils/array.d.ts +0 -76
  47. package/dist/types/utils/clone.d.ts +0 -13
  48. package/dist/types/utils/index.d.ts +0 -7
  49. package/dist/types/utils/object.d.ts +0 -54
  50. package/dist/types/utils/string.d.ts +0 -15
  51. package/dist/types/utils/to.d.ts +0 -5
  52. package/dist/types/utils/tree/index.d.ts +0 -6
  53. package/dist/types/utils/tree/rowsToTree.d.ts +0 -10
  54. package/dist/types/utils/tree/treeFilter.d.ts +0 -6
  55. package/dist/types/utils/tree/treeFind.d.ts +0 -8
  56. package/dist/types/utils/tree/treeForEach.d.ts +0 -5
  57. package/dist/types/utils/tree/treeMap.d.ts +0 -6
  58. package/dist/types/utils/tree/treeToRows.d.ts +0 -9
  59. package/dist/types/utils/tree/types.d.ts +0 -24
  60. package/dist/types/utils/typeof.d.ts +0 -37
  61. package/dist/types/zod/index.d.ts +0 -3
  62. package/dist/types/zod/primitive.d.ts +0 -32
  63. package/dist/types/zod/validator/input.d.ts +0 -27
  64. package/dist/types/zod/validator/societal.d.ts +0 -39
  65. package/dist/utils/array.js +0 -196
  66. package/dist/utils/clone.js +0 -75
  67. package/dist/utils/index.js +0 -7
  68. package/dist/utils/object.js +0 -149
  69. package/dist/utils/string.js +0 -73
  70. package/dist/utils/to.js +0 -16
  71. package/dist/utils/tree/index.js +0 -6
  72. package/dist/utils/tree/rowsToTree.js +0 -35
  73. package/dist/utils/tree/treeFilter.js +0 -92
  74. package/dist/utils/tree/treeFind.js +0 -82
  75. package/dist/utils/tree/treeForEach.js +0 -60
  76. package/dist/utils/tree/treeMap.js +0 -79
  77. package/dist/utils/tree/treeToRows.js +0 -13
  78. package/dist/utils/tree/types.js +0 -10
  79. package/dist/utils/typeof.js +0 -149
  80. package/dist/zod/index.js +0 -3
  81. package/dist/zod/primitive.js +0 -32
  82. package/dist/zod/validator/input.js +0 -39
  83. package/dist/zod/validator/societal.js +0 -57
package/dist/index.js CHANGED
@@ -1 +1,1375 @@
1
- export * from "./utils";
1
+ //#region src/utils/typeof/types.ts
2
+ const PROTOTYPE_TAGS = {
3
+ abortSignal: "[object AbortSignal]",
4
+ array: "[object Array]",
5
+ asyncFunction: "[object AsyncFunction]",
6
+ asyncGeneratorFunction: "[object AsyncGeneratorFunction]",
7
+ bigInt: "[object BigInt]",
8
+ blob: "[object Blob]",
9
+ boolean: "[object Boolean]",
10
+ date: "[object Date]",
11
+ error: "[object Error]",
12
+ file: "[object File]",
13
+ function: "[object Function]",
14
+ generatorFunction: "[object GeneratorFunction]",
15
+ map: "[object Map]",
16
+ null: "[object Null]",
17
+ number: "[object Number]",
18
+ object: "[object Object]",
19
+ promise: "[object Promise]",
20
+ readableStream: "[object ReadableStream]",
21
+ regExp: "[object RegExp]",
22
+ set: "[object Set]",
23
+ string: "[object String]",
24
+ symbol: "[object Symbol]",
25
+ undefined: "[object Undefined]",
26
+ URLSearchParams: "[object URLSearchParams]",
27
+ weakMap: "[object WeakMap]",
28
+ weakSet: "[object WeakSet]",
29
+ webSocket: "[object WebSocket]",
30
+ window: "[object Window]"
31
+ };
32
+ const TYPED_ARRAY_TAGS = new Set([
33
+ "[object Int8Array]",
34
+ "[object Uint8Array]",
35
+ "[object Uint8ClampedArray]",
36
+ "[object Int16Array]",
37
+ "[object Uint16Array]",
38
+ "[object Int32Array]",
39
+ "[object Uint32Array]",
40
+ "[object Float32Array]",
41
+ "[object Float64Array]",
42
+ "[object BigInt64Array]",
43
+ "[object BigUint64Array]"
44
+ ]);
45
+ function resolvePrototypeString(value) {
46
+ return Object.prototype.toString.call(value);
47
+ }
48
+
49
+ //#endregion
50
+ //#region src/utils/typeof/isAbortSignal.ts
51
+ function isAbortSignal(value) {
52
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.abortSignal;
53
+ }
54
+
55
+ //#endregion
56
+ //#region src/utils/typeof/isArray.ts
57
+ function isArray(value) {
58
+ return Array.isArray(value);
59
+ }
60
+ function isTypedArray(value) {
61
+ return typeof value === "object" && value !== null && TYPED_ARRAY_TAGS.has(resolvePrototypeString(value));
62
+ }
63
+
64
+ //#endregion
65
+ //#region src/utils/typeof/isBigInt.ts
66
+ function isBigInt(value) {
67
+ return typeof value === "bigint";
68
+ }
69
+
70
+ //#endregion
71
+ //#region src/utils/typeof/isBlob.ts
72
+ function isBlob(value) {
73
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.blob;
74
+ }
75
+
76
+ //#endregion
77
+ //#region src/utils/typeof/isBoolean.ts
78
+ function isBoolean(value) {
79
+ return typeof value === "boolean";
80
+ }
81
+
82
+ //#endregion
83
+ //#region src/utils/typeof/isClass.ts
84
+ function isConstructable(fn) {
85
+ try {
86
+ Reflect.construct(fn, []);
87
+ return true;
88
+ } catch {
89
+ return false;
90
+ }
91
+ }
92
+ function isClass(value) {
93
+ return isFunction(value) && !isAsyncFunction(value) && Function.prototype.toString.call(value).startsWith("class ") && isConstructable(value) && value.prototype !== void 0;
94
+ }
95
+
96
+ //#endregion
97
+ //#region src/utils/typeof/isObject.ts
98
+ /**
99
+ * 判断是否为对象类型
100
+ * - 可选是否检查原型为 `Object.prototype`,防止原型链污染
101
+ *
102
+ * @param value - 待检查值
103
+ * @param prototypeCheck - 是否进行原型检查,默认 `true`
104
+ */
105
+ function isObject(value, prototypeCheck = true) {
106
+ const check = resolvePrototypeString(value) === PROTOTYPE_TAGS.object;
107
+ return prototypeCheck ? check && Object.getPrototypeOf(value) === Object.prototype : check;
108
+ }
109
+
110
+ //#endregion
111
+ //#region src/utils/typeof/isDate.ts
112
+ function isDate(value) {
113
+ if (!isObject(value)) return false;
114
+ try {
115
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.date && typeof value["getTime"] === "function";
116
+ } catch (error) {
117
+ return false;
118
+ }
119
+ }
120
+
121
+ //#endregion
122
+ //#region src/utils/typeof/isEqual.ts
123
+ /**
124
+ * 检查给定的值是否相等
125
+ * @reference https://github.com/radashi-org/radashi/blob/main/src/typed/isEqual.ts
126
+ *
127
+ * @param {T} x
128
+ * @param {T} y
129
+ */
130
+ function isEqual(x, y) {
131
+ if (Object.is(x, y)) return true;
132
+ if (isDate(x) && isDate(y)) return x.getTime() === y.getTime();
133
+ if (isRegExp(x) && isRegExp(y)) return x.toString() === y.toString();
134
+ if (typeof x !== "object" || x === null || typeof y !== "object" || y === null) return false;
135
+ const keysX = Reflect.ownKeys(x);
136
+ const keysY = Reflect.ownKeys(y);
137
+ if (keysX.length !== keysY.length) return false;
138
+ for (const key of keysX) {
139
+ if (!Reflect.has(y, key)) return false;
140
+ if (!isEqual(x[key], y[key])) return false;
141
+ }
142
+ return true;
143
+ }
144
+
145
+ //#endregion
146
+ //#region src/utils/typeof/isError.ts
147
+ function isError(value) {
148
+ return value instanceof Error || resolvePrototypeString(value) === PROTOTYPE_TAGS.error;
149
+ }
150
+
151
+ //#endregion
152
+ //#region src/utils/typeof/isFalsy.ts
153
+ function isFalsy(value) {
154
+ if (isNaN(value) || isNull(value) || isUndefined(value)) return true;
155
+ return value === false || value === 0 || value === 0n || value === "";
156
+ }
157
+ function isFalsyLike(value) {
158
+ if (isFalsy(value)) return true;
159
+ return typeof value === "string" && (value === "null" || value === "undefined" || value === "NaN" || value === "false" || value === "0" || value === "0n");
160
+ }
161
+
162
+ //#endregion
163
+ //#region src/utils/typeof/isFile.ts
164
+ function isFile(value) {
165
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.file;
166
+ }
167
+
168
+ //#endregion
169
+ //#region src/utils/typeof/isFunction.ts
170
+ function isFunction(value) {
171
+ return typeof value === "function";
172
+ }
173
+ function isAsyncFunction(value) {
174
+ return isFunction(value) && resolvePrototypeString(value) === PROTOTYPE_TAGS.asyncFunction;
175
+ }
176
+ function isGeneratorFunction(value) {
177
+ return isFunction(value) && resolvePrototypeString(value) === PROTOTYPE_TAGS.generatorFunction;
178
+ }
179
+ function isAsyncGeneratorFunction(value) {
180
+ return isFunction(value) && resolvePrototypeString(value) === PROTOTYPE_TAGS.asyncGeneratorFunction;
181
+ }
182
+
183
+ //#endregion
184
+ //#region src/utils/typeof/isIterable.ts
185
+ function isIterable(value) {
186
+ return isObject(value) && Symbol.iterator in value;
187
+ }
188
+
189
+ //#endregion
190
+ //#region src/utils/typeof/isMap.ts
191
+ function isMap(value) {
192
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.map;
193
+ }
194
+ function isWeakMap(value) {
195
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.weakMap;
196
+ }
197
+
198
+ //#endregion
199
+ //#region src/utils/typeof/isNull.ts
200
+ function isNull(value) {
201
+ return value === null;
202
+ }
203
+
204
+ //#endregion
205
+ //#region src/utils/typeof/isNumber.ts
206
+ /**
207
+ * 检查 value 是否为 number 类型
208
+ *
209
+ * @param value - 待检查值
210
+ * @param checkNaN - 是否排除 `NaN`,默认为 `true`
211
+ */
212
+ function isNumber(value, checkNaN = true) {
213
+ return typeof value === "number" && (!checkNaN || !isNaN(value));
214
+ }
215
+ /**
216
+ * 检查 value 是否为 NaN
217
+ *
218
+ * @param value - 待检查值
219
+ */
220
+ function isNaN(value) {
221
+ return Number.isNaN(value);
222
+ }
223
+ /**
224
+ * 检查 value 是否为整数
225
+ *
226
+ * @param value - 待检查值
227
+ * @param safeCheck - 是否附加安全数检查
228
+ */
229
+ function isInteger(value, safeCheck = true) {
230
+ const check = Number.isInteger(value);
231
+ return safeCheck ? check && Number.isSafeInteger(value) : check;
232
+ }
233
+ /**
234
+ * 检查 value 是否为正整数
235
+ * - 此函数中 `0` 不被视为正整数
236
+ *
237
+ * @param value - 待检查值
238
+ * @param safeCheck - 是否附加安全数检查
239
+ */
240
+ function isPositiveInteger(value, safeCheck = true) {
241
+ return isInteger(value, safeCheck) && value > 0;
242
+ }
243
+ /**
244
+ * 检查 value 是否为负整数
245
+ * - 此函数中 `0` 不被视为负整数
246
+ *
247
+ * @param value - 待检查值
248
+ * @param safeCheck - 是否附加安全数检查
249
+ */
250
+ function isNegativeInteger(value, safeCheck = true) {
251
+ return isInteger(value, safeCheck) && value < 0;
252
+ }
253
+ /**
254
+ * 检查 value 是否为 Infinity
255
+ * - 排除 `NaN`
256
+ *
257
+ * @param value - 待检查值
258
+ */
259
+ function isInfinity(value) {
260
+ return isNumber(value) && (Number.POSITIVE_INFINITY === value || Number.NEGATIVE_INFINITY === value);
261
+ }
262
+ /**
263
+ * 检查 value 是否类似 Infinity
264
+ * - 排除 `NaN`
265
+ *
266
+ * @param value - 待检查值
267
+ */
268
+ function isInfinityLike(value) {
269
+ const check = isInfinity(value);
270
+ if (check) return check;
271
+ if (typeof value === "string") {
272
+ const v = value.trim().toLowerCase();
273
+ return v === "infinity" || v === "-infinity" || v === "+infinity";
274
+ }
275
+ return false;
276
+ }
277
+
278
+ //#endregion
279
+ //#region src/utils/typeof/isPromise.ts
280
+ function isPromise(value) {
281
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.promise;
282
+ }
283
+ function isPromiseLike(value) {
284
+ return isPromise(value) || isObject(value) && isFunction(value["then"]);
285
+ }
286
+
287
+ //#endregion
288
+ //#region src/utils/typeof/isReadableStream.ts
289
+ /**
290
+ * Checks if a value is a WHATWG ReadableStream instance.
291
+ *
292
+ * - Uses `Object.prototype.toString` where supported (modern browsers, Node.js ≥18).
293
+ * - Falls back to duck-typing in older environments.
294
+ * - Resistant to basic forgery, but not 100% secure in all polyfill scenarios.
295
+ *
296
+ * ⚠️ Note: In older Node.js (<18) or with non-compliant polyfills, this may return false positives or negatives.
297
+ */
298
+ function isReadableStream(value) {
299
+ if (resolvePrototypeString(value) === PROTOTYPE_TAGS.readableStream) return true;
300
+ return isObject(value) && isFunction(value["getReader"]) && isFunction(value["pipeThrough"]);
301
+ }
302
+
303
+ //#endregion
304
+ //#region src/utils/typeof/isRegExp.ts
305
+ function isRegExp(value) {
306
+ if (!isObject(value)) return false;
307
+ try {
308
+ const regex = value;
309
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.regExp && isString(regex.source) && isString(regex.flags) && isBoolean(regex.global) && isFunction(regex.test);
310
+ } catch (error) {
311
+ return false;
312
+ }
313
+ }
314
+
315
+ //#endregion
316
+ //#region src/utils/typeof/isSet.ts
317
+ function isSet(value) {
318
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.set;
319
+ }
320
+ function isWeakSet(value) {
321
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.weakSet;
322
+ }
323
+
324
+ //#endregion
325
+ //#region src/utils/typeof/isString.ts
326
+ function isString(value) {
327
+ return typeof value === "string";
328
+ }
329
+
330
+ //#endregion
331
+ //#region src/utils/typeof/isSymbol.ts
332
+ function isSymbol(value) {
333
+ return typeof value === "symbol";
334
+ }
335
+
336
+ //#endregion
337
+ //#region src/utils/typeof/isUndefined.ts
338
+ function isUndefined(value) {
339
+ return typeof value === "undefined";
340
+ }
341
+
342
+ //#endregion
343
+ //#region src/utils/typeof/isURLSearchParams.ts
344
+ function isURLSearchParams(value) {
345
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.URLSearchParams;
346
+ }
347
+
348
+ //#endregion
349
+ //#region src/utils/typeof/isWebSocket.ts
350
+ function isWebSocket(value) {
351
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.webSocket;
352
+ }
353
+
354
+ //#endregion
355
+ //#region src/utils/typeof/isWindow.ts
356
+ function isWindow(value) {
357
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.window;
358
+ }
359
+
360
+ //#endregion
361
+ //#region src/utils/array/arrayCast.ts
362
+ /**
363
+ * 构造数组
364
+ * @param candidate 待构造项
365
+ * @param checkEmpty 是否检查 `undefined` 和 `null`
366
+ */
367
+ function arrayCast(candidate, checkEmpty = true) {
368
+ if (checkEmpty && (isUndefined(candidate) || isNull(candidate))) return [];
369
+ return isArray(candidate) ? [...candidate] : [candidate];
370
+ }
371
+
372
+ //#endregion
373
+ //#region src/utils/array/arrayCompete.ts
374
+ /**
375
+ * 数组竞争
376
+ * - 返回在匹配函数的比较条件中获胜的最终项目,适用于更复杂的最小值/最大值计算
377
+ *
378
+ * @param initialList 数组
379
+ * @param match 匹配函数
380
+ */
381
+ function arrayCompete(initialList, match) {
382
+ if (!isArray(initialList) || initialList.length === 0 || !isFunction(match)) return null;
383
+ return initialList.reduce(match);
384
+ }
385
+
386
+ //#endregion
387
+ //#region src/utils/array/arrayCounting.ts
388
+ /**
389
+ * 统计数组的项目出现次数
390
+ * - 通过给定的标识符匹配函数,返回一个对象,其中键是回调函数返回的 key 值,每个值是一个整数,表示该 key 出现的次数
391
+ *
392
+ * @param initialList 初始数组
393
+ * @param match 匹配函数
394
+ */
395
+ function arrayCounting(initialList, match) {
396
+ if (!isArray(initialList) || !isFunction(match)) return {};
397
+ return initialList.reduce((prev, curr) => {
398
+ const id = match(curr).toString();
399
+ prev[id] = (prev[id] ?? 0) + 1;
400
+ return prev;
401
+ }, {});
402
+ }
403
+
404
+ //#endregion
405
+ //#region src/utils/array/arrayDifference.ts
406
+ /**
407
+ * 求数组差集
408
+ *
409
+ * @param initialList 初始数组
410
+ * @param diffList 对比数组
411
+ * @param match 匹配函数
412
+ */
413
+ function arrayDifference(initialList, diffList, match) {
414
+ if (!isArray(initialList) && !isArray(diffList)) return [];
415
+ if (!isArray(initialList) || !initialList.length) return [...diffList];
416
+ if (!isArray(diffList) || !diffList.length) return [...initialList];
417
+ if (!isFunction(match)) {
418
+ const arraySet = new Set(diffList);
419
+ return Array.from(new Set(initialList.filter((item) => !arraySet.has(item))));
420
+ }
421
+ const map = /* @__PURE__ */ new Map();
422
+ diffList.forEach((item) => {
423
+ map.set(match(item), true);
424
+ });
425
+ return initialList.filter((a) => !map.get(match(a)));
426
+ }
427
+
428
+ //#endregion
429
+ //#region src/utils/array/arrayFirst.ts
430
+ function arrayFirst(initialList, saveValue) {
431
+ if (!isArray(initialList) || initialList.length === 0) return saveValue;
432
+ return initialList[0];
433
+ }
434
+
435
+ //#endregion
436
+ //#region src/utils/array/arrayFork.ts
437
+ /**
438
+ * 数组分组过滤
439
+ * - 给定一个数组和一个条件,返回一个由两个数组组成的元组,其中第一个数组包含所有满足条件的项,第二个数组包含所有不满足条件的项
440
+ *
441
+ * @param initialList 初始数组
442
+ * @param match 条件匹配函数
443
+ */
444
+ function arrayFork(initialList, match) {
445
+ const forked = [[], []];
446
+ if (isArray(initialList)) for (const item of initialList) forked[match(item) ? 0 : 1].push(item);
447
+ return forked;
448
+ }
449
+
450
+ //#endregion
451
+ //#region src/utils/array/arrayIntersection.ts
452
+ /**
453
+ * 求数组交集
454
+ *
455
+ * @param initialList 初始数组
456
+ * @param diffList 对比数组
457
+ * @param match 匹配函数
458
+ */
459
+ function arrayIntersection(initialList, diffList, match) {
460
+ if (!isArray(initialList) && !isArray(diffList)) return [];
461
+ if (!isArray(initialList) || !initialList.length) return [...diffList];
462
+ if (!isArray(diffList) || !diffList.length) return [...initialList];
463
+ if (!isFunction(match)) {
464
+ const arraySet = new Set(diffList);
465
+ return Array.from(new Set(initialList.filter((item) => arraySet.has(item))));
466
+ }
467
+ const map = /* @__PURE__ */ new Map();
468
+ diffList.forEach((item) => {
469
+ map.set(match(item), true);
470
+ });
471
+ return initialList.filter((a) => map.get(match(a)));
472
+ }
473
+
474
+ //#endregion
475
+ //#region src/utils/array/arrayLast.ts
476
+ function arrayLast(initialList, saveValue) {
477
+ if (!isArray(initialList) || initialList.length === 0) return saveValue;
478
+ return initialList[initialList.length - 1];
479
+ }
480
+
481
+ //#endregion
482
+ //#region src/utils/array/arrayMerge.ts
483
+ /**
484
+ * 数组合并
485
+ * - 通过给定的标识符匹配函数,用第二个数组中的匹配项替换第一个数组中匹配项的所有内容
486
+ *
487
+ * @param initialList 初始数组
488
+ * @param mergeList 待合并数组
489
+ * @param match 匹配函数
490
+ */
491
+ function arrayMerge(initialList, mergeList, match) {
492
+ if (!isArray(initialList)) return [];
493
+ if (!isArray(mergeList)) return [...initialList];
494
+ if (!isFunction(match)) return Array.from(new Set([...initialList, ...mergeList]));
495
+ const keys = /* @__PURE__ */ new Map();
496
+ for (const item of mergeList) keys.set(match(item), item);
497
+ return initialList.map((prevItem) => {
498
+ const key = match(prevItem);
499
+ return keys.has(key) ? keys.get(key) : prevItem;
500
+ });
501
+ }
502
+
503
+ //#endregion
504
+ //#region src/utils/array/arrayPick.ts
505
+ /**
506
+ * 数组选择
507
+ * - 一次性应用 `filter` 和 `map` 操作
508
+ *
509
+ * @param initialList 初始数组
510
+ * @param filter filter 函数
511
+ * @param mapper map 函数
512
+ */
513
+ function arrayPick(initialList, filter, mapper) {
514
+ if (!isArray(initialList)) return [];
515
+ if (!isFunction(filter)) return [...initialList];
516
+ const hasMapper = isFunction(mapper);
517
+ return initialList.reduce((prev, curr, index) => {
518
+ if (!filter(curr, index)) return prev;
519
+ if (hasMapper) prev.push(mapper(curr, index));
520
+ else prev.push(curr);
521
+ return prev;
522
+ }, []);
523
+ }
524
+
525
+ //#endregion
526
+ //#region src/utils/array/arrayReplace.ts
527
+ /**
528
+ * 数组项替换
529
+ * - 在给定的数组中,替换符合匹配函数结果的项目。只替换第一个匹配项。始终返回原始数组的副本。
530
+ *
531
+ * @param initialList 初始数组
532
+ * @param newItem 替换项
533
+ * @param match 匹配函数
534
+ */
535
+ function arrayReplace(initialList, newItem, match) {
536
+ if (!initialList) return [];
537
+ if (newItem === void 0 || !isFunction(match)) return [...initialList];
538
+ for (let i = 0; i < initialList.length; i++) {
539
+ const item = initialList[i];
540
+ if (item !== void 0 && match(item, i)) return [
541
+ ...initialList.slice(0, i),
542
+ newItem,
543
+ ...initialList.slice(i + 1, initialList.length)
544
+ ];
545
+ }
546
+ return [...initialList];
547
+ }
548
+
549
+ //#endregion
550
+ //#region src/utils/array/arraySplit.ts
551
+ /**
552
+ * 数组切分
553
+ * - 将数组以指定的长度切分后,组合在高维数组中
554
+ *
555
+ * @param initialList 初始数组
556
+ * @param size 分割尺寸,默认 `10`
557
+ */
558
+ function arraySplit(initialList, size = 10) {
559
+ if (!isArray(initialList)) return [];
560
+ const count = Math.ceil(initialList.length / size);
561
+ return Array.from({ length: count }).fill(null).map((_c, i) => {
562
+ return initialList.slice(i * size, i * size + size);
563
+ });
564
+ }
565
+
566
+ //#endregion
567
+ //#region src/utils/function/to.ts
568
+ /**
569
+ * @param promise
570
+ * @param errorExt - 可以传递给err对象的其他信息
571
+ */
572
+ function to(promise, errorExt) {
573
+ return promise.then((data) => [null, data]).catch((err) => {
574
+ if (errorExt) return [{
575
+ ...err,
576
+ ...errorExt
577
+ }, void 0];
578
+ return [err ? err : /* @__PURE__ */ new Error("defaultError"), void 0];
579
+ });
580
+ }
581
+
582
+ //#endregion
583
+ //#region src/utils/string/stringToNumber.ts
584
+ const R1$1 = /[^0-9.-]/g;
585
+ /**
586
+ * 从字符串中提取数字字符串
587
+ *
588
+ * @param input 待处理字符串
589
+ */
590
+ function stringToNumber(input) {
591
+ if (!isString(input) || !input.length) return "";
592
+ const cleaned = input.replace(R1$1, "");
593
+ let isDecimal = false;
594
+ let signCount = 0;
595
+ let firstIndex = -1;
596
+ const stringList = cleaned.split("").map((s, i) => {
597
+ if (s === ".") {
598
+ if (isDecimal) return "";
599
+ isDecimal = true;
600
+ return ".";
601
+ }
602
+ if (s === "-") {
603
+ firstIndex === -1 && signCount++;
604
+ return "";
605
+ }
606
+ firstIndex === -1 && (firstIndex = i);
607
+ return s;
608
+ });
609
+ const sign = signCount % 2 === 1 ? "-" : "";
610
+ if (firstIndex === -1) return sign + "0";
611
+ let result = stringList.join("");
612
+ if (result.startsWith(".")) result = "0" + result;
613
+ if (result.endsWith(".")) result = result.slice(0, -1);
614
+ return sign + result;
615
+ }
616
+
617
+ //#endregion
618
+ //#region src/utils/math/toMathBignumber.ts
619
+ /**
620
+ * 将任意类型的值转换为 `math.bignumber`
621
+ *
622
+ * @param mathJsInstance mathJs 实例
623
+ * @param value 任意类型的值
624
+ * @param saveValue 安全值
625
+ */
626
+ function toMathBignumber(mathJsInstance, value, saveValue) {
627
+ const errorValue = saveValue ?? mathJsInstance.bignumber(0);
628
+ if (isFalsyLike(value) || isInfinityLike(value)) return errorValue;
629
+ try {
630
+ return mathJsInstance.bignumber(stringToNumber(`${value}`));
631
+ } catch (error) {
632
+ return errorValue;
633
+ }
634
+ }
635
+
636
+ //#endregion
637
+ //#region src/utils/math/toMathDecimal.ts
638
+ function toMathDecimal(mathJsInstance, value, precision, isFormat = true) {
639
+ const bigNumber = toMathBignumber(mathJsInstance, value);
640
+ return isFormat ? mathJsInstance.format(bigNumber, {
641
+ notation: "fixed",
642
+ precision
643
+ }) : bigNumber;
644
+ }
645
+
646
+ //#endregion
647
+ //#region src/utils/math/toMathEvaluate.ts
648
+ /**
649
+ * 数学表达式求值
650
+ *
651
+ * @param mathJsInstance mathJs 实例
652
+ * @param expr 表达式
653
+ * @param scope 键值映射
654
+ */
655
+ function toMathEvaluate(mathJsInstance, expr, scope) {
656
+ const evaluateValue = `${mathJsInstance.evaluate(expr, scope || {})}`;
657
+ return mathJsInstance.format(toMathBignumber(mathJsInstance, evaluateValue), { notation: "fixed" });
658
+ }
659
+
660
+ //#endregion
661
+ //#region src/utils/object/cloneDeep.ts
662
+ const DefaultCloningStrategy = {
663
+ cloneMap(input, track, clone) {
664
+ const output = track(/* @__PURE__ */ new Map());
665
+ for (const [key, value] of input) output.set(key, clone(value));
666
+ return output;
667
+ },
668
+ cloneSet(input, track, clone) {
669
+ const output = track(/* @__PURE__ */ new Set());
670
+ for (const value of input) output.add(clone(value));
671
+ return output;
672
+ },
673
+ cloneArray(input, track, clone) {
674
+ const output = track(new Array(input.length));
675
+ input.forEach((value, index) => {
676
+ output[index] = clone(value);
677
+ });
678
+ return output;
679
+ },
680
+ cloneObject(input, track, clone) {
681
+ const output = track(Object.create(Object.getPrototypeOf(input)));
682
+ for (const key of Reflect.ownKeys(input)) {
683
+ const descriptor = Object.getOwnPropertyDescriptor(input, key);
684
+ if ("value" in descriptor) descriptor.value = clone(descriptor.value);
685
+ Object.defineProperty(output, key, descriptor);
686
+ }
687
+ return output;
688
+ },
689
+ cloneOther(input, track) {
690
+ return track(input);
691
+ }
692
+ };
693
+ /**
694
+ * cloneDeep
695
+ * @reference https://github.com/radashi-org/radashi/blob/main/src/object/cloneDeep.ts
696
+ */
697
+ function cloneDeep(root, customStrategy) {
698
+ const strategy = {
699
+ ...DefaultCloningStrategy,
700
+ ...customStrategy
701
+ };
702
+ const tracked = /* @__PURE__ */ new Map();
703
+ const track = (parent, newParent) => {
704
+ tracked.set(parent, newParent);
705
+ return newParent;
706
+ };
707
+ const clone = (value) => {
708
+ return value && typeof value === "object" ? tracked.get(value) ?? cloneDeep$1(value, strategy) : value;
709
+ };
710
+ const cloneDeep$1 = (parent, strategy$1) => {
711
+ const newParent = (isObject(parent) ? strategy$1.cloneObject : isArray(parent) ? strategy$1.cloneArray : isMap(parent) ? strategy$1.cloneMap : isSet(parent) ? strategy$1.cloneSet : strategy$1.cloneOther)(parent, track.bind(null, parent), clone);
712
+ if (!newParent) return cloneDeep$1(parent, DefaultCloningStrategy);
713
+ tracked.set(parent, newParent);
714
+ return newParent;
715
+ };
716
+ return cloneDeep$1(root, strategy);
717
+ }
718
+
719
+ //#endregion
720
+ //#region src/utils/object/objectKeys.ts
721
+ /**
722
+ * 返回对象的可枚举属性和方法的名称
723
+ * - `Object.keys` 始终返回 `string[]` 类型,此函数可以返回具体类型
724
+ *
725
+ * @param obj 对象
726
+ */
727
+ function objectKeys(obj) {
728
+ return Object.keys(obj);
729
+ }
730
+
731
+ //#endregion
732
+ //#region src/utils/object/enumTypeCheck.ts
733
+ function enumTypeCheck(enumeration) {
734
+ if (!isObject(enumeration)) throw Error(`function enumKeys expected parameter is a enum, but got ${typeof enumeration}`);
735
+ if (!objectKeys(enumeration).length) throw Error("Enum requires at least one member");
736
+ return enumeration;
737
+ }
738
+
739
+ //#endregion
740
+ //#region src/utils/object/objectEntries.ts
741
+ /**
742
+ * 返回对象的可枚举属性的键/值数组
743
+ *
744
+ * @param obj 对象
745
+ */
746
+ function objectEntries(obj) {
747
+ return Object.entries(obj);
748
+ }
749
+
750
+ //#endregion
751
+ //#region src/utils/object/objectValues.ts
752
+ /**
753
+ * 返回对象的可枚举属性的值数组
754
+ *
755
+ * @param obj 对象
756
+ */
757
+ function objectValues(obj) {
758
+ return Object.values(obj);
759
+ }
760
+
761
+ //#endregion
762
+ //#region src/utils/object/enumEntries.ts
763
+ /**
764
+ * 返回枚举的属性的键/值数组
765
+ *
766
+ * @param enumeration 枚举
767
+ */
768
+ function enumEntries(enumeration) {
769
+ const e = enumTypeCheck(enumeration);
770
+ const keys = objectKeys(e);
771
+ const values = objectValues(e);
772
+ const entries = objectEntries(e);
773
+ if (keys.every((k) => values.some((v) => `${v}` === k))) return entries.splice(keys.length / 2, keys.length / 2);
774
+ return entries;
775
+ }
776
+
777
+ //#endregion
778
+ //#region src/utils/object/enumKeys.ts
779
+ /**
780
+ * 获取枚举所有属性的键
781
+ *
782
+ * @param enumeration 枚举
783
+ */
784
+ function enumKeys(enumeration) {
785
+ const e = enumTypeCheck(enumeration);
786
+ const keys = objectKeys(e);
787
+ const values = objectValues(e);
788
+ if (keys.every((k) => values.some((v) => `${v}` === k))) return keys.splice(keys.length / 2, keys.length / 2);
789
+ return keys;
790
+ }
791
+
792
+ //#endregion
793
+ //#region src/utils/object/enumValues.ts
794
+ /**
795
+ * 获取枚举所有属性的值
796
+ *
797
+ * @param enumeration 枚举
798
+ */
799
+ function enumValues(enumeration) {
800
+ const e = enumTypeCheck(enumeration);
801
+ const keys = objectKeys(e);
802
+ const values = objectValues(e);
803
+ if (keys.every((k) => values.some((v) => `${v}` === k))) return values.splice(keys.length / 2, keys.length / 2);
804
+ return values;
805
+ }
806
+
807
+ //#endregion
808
+ //#region src/utils/object/mapEntries.ts
809
+ function mapEntries(obj, toEntry) {
810
+ const defaultResult = {};
811
+ if (!obj) return defaultResult;
812
+ return objectEntries(obj).reduce((acc, [key, value]) => {
813
+ const [newKey, newValue] = toEntry(key, value);
814
+ acc[newKey] = newValue;
815
+ return acc;
816
+ }, defaultResult);
817
+ }
818
+
819
+ //#endregion
820
+ //#region src/utils/object/objectAssign.ts
821
+ /**
822
+ * 递归地将第二个对象合并到第一个对象的副本中
823
+ * - 只有普通对象才会递归合并
824
+ *
825
+ * @param initial 初始对象
826
+ * @param override 待合并对象
827
+ */
828
+ function objectAssign(initial, override) {
829
+ if (!isObject(initial) || !isObject(override)) return initial ?? override ?? {};
830
+ const proto = Object.getPrototypeOf(initial);
831
+ const assigned = proto ? { ...initial } : Object.assign(Object.create(proto), initial);
832
+ for (const key of Object.keys(override)) assigned[key] = isObject(initial[key]) && isObject(override[key]) ? objectAssign(initial[key], override[key]) : override[key];
833
+ return assigned;
834
+ }
835
+
836
+ //#endregion
837
+ //#region src/utils/object/objectCrush.ts
838
+ function objectCrush(value) {
839
+ if (!value) return {};
840
+ function crushReducer(crushed, value$1, path) {
841
+ if (isObject(value$1) || isArray(value$1)) for (const [prop, propValue] of Object.entries(value$1)) crushReducer(crushed, propValue, path ? `${path}.${prop}` : prop);
842
+ else crushed[path] = value$1;
843
+ return crushed;
844
+ }
845
+ return crushReducer({}, value, "");
846
+ }
847
+
848
+ //#endregion
849
+ //#region src/utils/object/objectPick.ts
850
+ function objectPick(obj, keys) {
851
+ const result = {};
852
+ if (!isObject(obj)) return result;
853
+ if (!isArray(keys)) return obj;
854
+ return keys.reduce((acc, curr) => {
855
+ if (curr in obj) acc[curr] = obj[curr];
856
+ return acc;
857
+ }, result);
858
+ }
859
+
860
+ //#endregion
861
+ //#region src/utils/object/objectSwitch.ts
862
+ /**
863
+ * 对象反转
864
+ * - 返回交换了对象的可枚举属性的值/键对象
865
+ *
866
+ * @param obj 对象
867
+ */
868
+ function objectSwitch(obj) {
869
+ const result = {};
870
+ if (!isObject(obj)) return result;
871
+ for (const [k, v] of objectEntries(obj)) result[v] = k;
872
+ return result;
873
+ }
874
+
875
+ //#endregion
876
+ //#region src/utils/string/stringInitialCase.ts
877
+ const R1 = /\S+/g;
878
+ const R2 = /[^a-zA-Z\u00C0-\u017F]/;
879
+ /**
880
+ * 字符串首字母大小写
881
+ * - 包含非西欧字母字符时,不处理
882
+ * - 纯字母且全大写时,不处理
883
+ * - 纯字母且非全大写时,首字母小写,其余保留
884
+ * - 纯字母且非全大写时,首字母大写,其余保留
885
+ *
886
+ * @param input 待处理字符串
887
+ * @param caseType 大小写类型
888
+ */
889
+ function stringInitialCase(input, caseType) {
890
+ if (!isString(input) || !input.length) return "";
891
+ return input.replace(R1, (word) => {
892
+ if (R2.test(word)) return word;
893
+ if (word === word.toLocaleUpperCase()) return word;
894
+ if (caseType === "lower" && word[0]) return word[0].toLocaleLowerCase() + word.slice(1);
895
+ if (caseType === "upper" && word[0]) return word[0].toLocaleUpperCase() + word.slice(1);
896
+ return word;
897
+ });
898
+ }
899
+
900
+ //#endregion
901
+ //#region src/utils/string/stringReplace.ts
902
+ /**
903
+ * 字符串替换
904
+ * - 替换第一个匹配项
905
+ *
906
+ * @param input 待处理字符串
907
+ * @param search 匹配项
908
+ * @param replacement 替换项
909
+ */
910
+ function stringReplace(input, search, replacement) {
911
+ if (!isString(input) || !input.length) return "";
912
+ return input.replace(search, replacement);
913
+ }
914
+
915
+ //#endregion
916
+ //#region src/utils/string/stringTemplate.ts
917
+ /**
918
+ * 字符串模板替换
919
+ *
920
+ * @param input 待处理字符串
921
+ * @param template 模板对象
922
+ * @param regex 模板匹配正则
923
+ */
924
+ function stringTemplate(input, template, regex = /\{\{(.+?)\}\}/g) {
925
+ if (!isString(input) || !input.length) return "";
926
+ let result = "";
927
+ let from = 0;
928
+ let match;
929
+ while (match = regex.exec(input)) {
930
+ result += input.slice(from, match.index) + template[match[1]];
931
+ from = regex.lastIndex;
932
+ }
933
+ return result + input.slice(from);
934
+ }
935
+
936
+ //#endregion
937
+ //#region src/utils/string/stringToJson.ts
938
+ /**
939
+ * 处理 JSON 字符串
940
+ *
941
+ * @param input 待处理字符串
942
+ * @param safeValue 安全值
943
+ */
944
+ function stringToJson(input, safeValue) {
945
+ if (!isString(input) || !input.length) return safeValue;
946
+ try {
947
+ return JSON.parse(input);
948
+ } catch (error) {
949
+ return safeValue;
950
+ }
951
+ }
952
+
953
+ //#endregion
954
+ //#region src/utils/string/stringToValues.ts
955
+ function stringToValues(input, valueType = "number", splitSymbol = ",") {
956
+ if (!isString(input) || !input.length) return [];
957
+ try {
958
+ const values = input.split(splitSymbol);
959
+ if (valueType === "number") return values.map((d) => Number(d));
960
+ return values;
961
+ } catch (error) {
962
+ return [];
963
+ }
964
+ }
965
+
966
+ //#endregion
967
+ //#region src/utils/tree/types.ts
968
+ function getFinalChildrenKey(tree, meta, options) {
969
+ if (isFunction(options.getChildrenKey)) {
970
+ const dynamicChildrenKey = options.getChildrenKey(tree, meta);
971
+ if (dynamicChildrenKey && dynamicChildrenKey !== null) return dynamicChildrenKey;
972
+ }
973
+ return options.childrenKey;
974
+ }
975
+
976
+ //#endregion
977
+ //#region src/utils/tree/treeFilter.ts
978
+ function preImpl$3(row, callback, options) {
979
+ if (!callback(row, options)) return;
980
+ const finalChildrenKey = getFinalChildrenKey(row, options, options);
981
+ const children = row[finalChildrenKey];
982
+ let newChildren;
983
+ if (isArray(children)) {
984
+ const nextLevelOptions = {
985
+ ...options,
986
+ parents: [...options.parents, row],
987
+ depth: options.depth + 1
988
+ };
989
+ newChildren = children.map((c) => preImpl$3(c, callback, nextLevelOptions)).filter((c) => !!c);
990
+ }
991
+ return {
992
+ ...row,
993
+ [finalChildrenKey]: newChildren
994
+ };
995
+ }
996
+ function postImpl$3(row, callback, options) {
997
+ const finalChildrenKey = getFinalChildrenKey(row, options, options);
998
+ const children = row[finalChildrenKey];
999
+ let newChildren;
1000
+ if (isArray(children)) {
1001
+ const nextLevelOptions = {
1002
+ ...options,
1003
+ parents: [...options.parents, row],
1004
+ depth: options.depth + 1
1005
+ };
1006
+ newChildren = children.map((c) => preImpl$3(c, callback, nextLevelOptions)).filter((c) => !!c);
1007
+ }
1008
+ if (!callback(row, options)) return;
1009
+ return {
1010
+ ...row,
1011
+ [finalChildrenKey]: newChildren
1012
+ };
1013
+ }
1014
+ function breadthImpl$3(row, callback, options) {
1015
+ const queue = [{
1016
+ queueRow: row,
1017
+ queueOptions: options
1018
+ }];
1019
+ const resultCache = /* @__PURE__ */ new WeakMap();
1020
+ const newNodeCache = /* @__PURE__ */ new WeakMap();
1021
+ const childrenKeyCache = /* @__PURE__ */ new WeakMap();
1022
+ let result;
1023
+ const runQueue = () => {
1024
+ if (queue.length === 0) return result;
1025
+ const { queueRow, queueOptions } = queue.shift();
1026
+ const finalChildrenKey = getFinalChildrenKey(queueRow, queueOptions, queueOptions);
1027
+ const children = queueRow[finalChildrenKey];
1028
+ if (isArray(children)) {
1029
+ const nextLevelOptions = {
1030
+ ...queueOptions,
1031
+ parents: [...queueOptions.parents, queueRow],
1032
+ depth: queueOptions.depth + 1
1033
+ };
1034
+ const subQueueItems = children.map((queueRow$1) => ({
1035
+ queueRow: queueRow$1,
1036
+ queueOptions: nextLevelOptions
1037
+ }));
1038
+ queue.push(...subQueueItems);
1039
+ }
1040
+ const parent = arrayLast(queueOptions.parents);
1041
+ const isTopNode = queueOptions.depth === 0;
1042
+ const parentResult = parent && resultCache.get(parent);
1043
+ if (!isTopNode && !parentResult) return runQueue();
1044
+ const callbackResult = callback(queueRow, queueOptions);
1045
+ if (isTopNode && !callbackResult) return;
1046
+ const newNode = {
1047
+ ...queueRow,
1048
+ [finalChildrenKey]: void 0
1049
+ };
1050
+ if (isTopNode) result = newNode;
1051
+ resultCache.set(queueRow, callbackResult);
1052
+ newNodeCache.set(queueRow, newNode);
1053
+ childrenKeyCache.set(queueRow, finalChildrenKey);
1054
+ if (callbackResult && parent) {
1055
+ const parentNewNode = newNodeCache.get(parent);
1056
+ const parentChildrenKey = childrenKeyCache.get(parent);
1057
+ if (parentNewNode && parentChildrenKey) {
1058
+ if (!parentNewNode[parentChildrenKey]) parentNewNode[parentChildrenKey] = [];
1059
+ parentNewNode[parentChildrenKey].push(newNode);
1060
+ }
1061
+ }
1062
+ return runQueue();
1063
+ };
1064
+ return runQueue();
1065
+ }
1066
+ const strategies$3 = {
1067
+ pre: preImpl$3,
1068
+ post: postImpl$3,
1069
+ breadth: breadthImpl$3
1070
+ };
1071
+ function treeFilter(tree, callback, options = {}) {
1072
+ const { childrenKey = "children", strategy = "pre", getChildrenKey } = options;
1073
+ const traversalMethod = strategies$3[strategy];
1074
+ const innerOptions = {
1075
+ childrenKey,
1076
+ depth: 0,
1077
+ parents: [],
1078
+ getChildrenKey
1079
+ };
1080
+ return isArray(tree) ? tree.map((row) => traversalMethod(row, callback, innerOptions)).filter((t) => !!t) : traversalMethod(tree, callback, innerOptions) || [];
1081
+ }
1082
+
1083
+ //#endregion
1084
+ //#region src/utils/tree/treeFind.ts
1085
+ const strategies$2 = {
1086
+ pre: preImpl$2,
1087
+ post: postImpl$2,
1088
+ breadth: breadthImpl$2
1089
+ };
1090
+ function preImpl$2(row, callback, options) {
1091
+ if (callback(row, options)) return row;
1092
+ const children = row[getFinalChildrenKey(row, options, options)];
1093
+ if (isArray(children)) for (const child of children) {
1094
+ const result = preImpl$2(child, callback, {
1095
+ ...options,
1096
+ parents: [...options.parents, row],
1097
+ depth: options.depth + 1
1098
+ });
1099
+ if (result) return result;
1100
+ }
1101
+ }
1102
+ function postImpl$2(row, callback, options) {
1103
+ const children = row[getFinalChildrenKey(row, options, options)];
1104
+ if (isArray(children)) for (const child of children) {
1105
+ const result = postImpl$2(child, callback, {
1106
+ ...options,
1107
+ parents: [...options.parents, row],
1108
+ depth: options.depth + 1
1109
+ });
1110
+ if (result) return result;
1111
+ }
1112
+ if (callback(row, options)) return row;
1113
+ }
1114
+ function breadthImpl$2(row, callback, options) {
1115
+ const queue = [{
1116
+ queueRow: row,
1117
+ queueOptions: options
1118
+ }];
1119
+ const runQueue = () => {
1120
+ if (queue.length === 0) return;
1121
+ const { queueRow, queueOptions } = queue.shift();
1122
+ const children = queueRow[getFinalChildrenKey(queueRow, queueOptions, queueOptions)];
1123
+ if (isArray(children)) {
1124
+ const nextLevelOptions = {
1125
+ ...queueOptions,
1126
+ parents: [...queueOptions.parents, queueRow],
1127
+ depth: queueOptions.depth + 1
1128
+ };
1129
+ const subQueueItems = children.map((queueRow$1) => ({
1130
+ queueRow: queueRow$1,
1131
+ queueOptions: nextLevelOptions
1132
+ }));
1133
+ queue.push(...subQueueItems);
1134
+ }
1135
+ if (callback(queueRow, queueOptions)) return queueRow;
1136
+ return runQueue();
1137
+ };
1138
+ return runQueue();
1139
+ }
1140
+ /**
1141
+ * 查找树节点,找到第一个返回非空值的节点
1142
+ */
1143
+ function treeFind(tree, callback, options = {}) {
1144
+ const { childrenKey = "children", strategy = "pre", getChildrenKey } = options;
1145
+ const traversalMethod = strategies$2[strategy];
1146
+ const innerOptions = {
1147
+ childrenKey,
1148
+ depth: 0,
1149
+ parents: [],
1150
+ getChildrenKey
1151
+ };
1152
+ if (isArray(tree)) {
1153
+ for (const row of tree) {
1154
+ const result = traversalMethod(row, callback, innerOptions);
1155
+ if (result) return result;
1156
+ }
1157
+ return;
1158
+ }
1159
+ return traversalMethod(tree, callback, innerOptions);
1160
+ }
1161
+
1162
+ //#endregion
1163
+ //#region src/utils/tree/treeForEach.ts
1164
+ const strategies$1 = {
1165
+ pre: preImpl$1,
1166
+ post: postImpl$1,
1167
+ breadth: breadthImpl$1
1168
+ };
1169
+ function preImpl$1(row, callback, options) {
1170
+ callback(row, options);
1171
+ const children = row[getFinalChildrenKey(row, options, options)];
1172
+ if (isArray(children)) {
1173
+ const nextLevelOptions = {
1174
+ ...options,
1175
+ parents: [...options.parents, row],
1176
+ depth: options.depth + 1
1177
+ };
1178
+ for (const child of children) preImpl$1(child, callback, nextLevelOptions);
1179
+ }
1180
+ }
1181
+ function postImpl$1(row, callback, options) {
1182
+ const children = row[getFinalChildrenKey(row, options, options)];
1183
+ if (isArray(children)) {
1184
+ const nextLevelOptions = {
1185
+ ...options,
1186
+ parents: [...options.parents, row],
1187
+ depth: options.depth + 1
1188
+ };
1189
+ for (const child of children) postImpl$1(child, callback, nextLevelOptions);
1190
+ }
1191
+ callback(row, options);
1192
+ }
1193
+ function breadthImpl$1(row, callback, options) {
1194
+ const queue = [{
1195
+ queueRow: row,
1196
+ queueOptions: options
1197
+ }];
1198
+ const runQueue = () => {
1199
+ if (queue.length === 0) return;
1200
+ const { queueRow, queueOptions } = queue.shift();
1201
+ const children = queueRow[getFinalChildrenKey(queueRow, queueOptions, queueOptions)];
1202
+ if (isArray(children)) {
1203
+ const nextLevelOptions = {
1204
+ ...queueOptions,
1205
+ parents: [...queueOptions.parents, queueRow],
1206
+ depth: queueOptions.depth + 1
1207
+ };
1208
+ const subQueueItems = children.map((queueRow$1) => ({
1209
+ queueRow: queueRow$1,
1210
+ queueOptions: nextLevelOptions
1211
+ }));
1212
+ queue.push(...subQueueItems);
1213
+ }
1214
+ callback(queueRow, queueOptions);
1215
+ runQueue();
1216
+ };
1217
+ runQueue();
1218
+ }
1219
+ function treeForEach(tree, callback, options = {}) {
1220
+ const { childrenKey = "children", strategy = "pre", getChildrenKey } = options;
1221
+ const traversalMethod = strategies$1[strategy];
1222
+ const innerOptions = {
1223
+ childrenKey,
1224
+ depth: 0,
1225
+ parents: [],
1226
+ getChildrenKey
1227
+ };
1228
+ if (isArray(tree)) for (const row of tree) traversalMethod(row, callback, innerOptions);
1229
+ else traversalMethod(tree, callback, innerOptions);
1230
+ }
1231
+
1232
+ //#endregion
1233
+ //#region src/utils/tree/treeMap.ts
1234
+ const strategies = {
1235
+ pre: preImpl,
1236
+ post: postImpl,
1237
+ breadth: breadthImpl
1238
+ };
1239
+ function preImpl(row, callback, options) {
1240
+ const finalChildrenKey = getFinalChildrenKey(row, options, options);
1241
+ const result = callback(row, options);
1242
+ const children = row[finalChildrenKey];
1243
+ let newChildren;
1244
+ if (isArray(children)) {
1245
+ const nextLevelOptions = {
1246
+ ...options,
1247
+ parents: [...options.parents, row],
1248
+ depth: options.depth + 1
1249
+ };
1250
+ newChildren = children.map((c) => preImpl(c, callback, nextLevelOptions));
1251
+ }
1252
+ return {
1253
+ ...result,
1254
+ [finalChildrenKey]: newChildren
1255
+ };
1256
+ }
1257
+ function postImpl(row, callback, options) {
1258
+ const finalChildrenKey = getFinalChildrenKey(row, options, options);
1259
+ const children = row[finalChildrenKey];
1260
+ let newChildren;
1261
+ if (isArray(children)) {
1262
+ const nextLevelOptions = {
1263
+ ...options,
1264
+ parents: [...options.parents, row],
1265
+ depth: options.depth + 1
1266
+ };
1267
+ newChildren = children.map((c) => postImpl(c, callback, nextLevelOptions));
1268
+ }
1269
+ return {
1270
+ ...callback(row, options),
1271
+ [finalChildrenKey]: newChildren
1272
+ };
1273
+ }
1274
+ function breadthImpl(row, callback, options) {
1275
+ const queue = [{
1276
+ queueRow: row,
1277
+ queueOptions: options
1278
+ }];
1279
+ const cache = /* @__PURE__ */ new WeakMap();
1280
+ const childrenKeyCache = /* @__PURE__ */ new WeakMap();
1281
+ let result;
1282
+ const runQueue = () => {
1283
+ if (queue.length === 0) return result;
1284
+ const { queueRow, queueOptions } = queue.shift();
1285
+ const finalChildrenKey = getFinalChildrenKey(queueRow, queueOptions, queueOptions);
1286
+ const children = queueRow[finalChildrenKey];
1287
+ if (isArray(children)) {
1288
+ const nextLevelOptions = {
1289
+ ...queueOptions,
1290
+ parents: [...queueOptions.parents, queueRow],
1291
+ depth: queueOptions.depth + 1
1292
+ };
1293
+ const subQueueItems = children.map((queueRow$1) => ({
1294
+ queueRow: queueRow$1,
1295
+ queueOptions: nextLevelOptions
1296
+ }));
1297
+ queue.push(...subQueueItems);
1298
+ }
1299
+ const res = callback(queueRow, queueOptions);
1300
+ cache.set(queueRow, res);
1301
+ childrenKeyCache.set(queueRow, finalChildrenKey);
1302
+ const parent = arrayLast(queueOptions.parents);
1303
+ if (parent) {
1304
+ const newParent = cache.get(parent);
1305
+ const parentChildrenKey = childrenKeyCache.get(parent);
1306
+ if (newParent && parentChildrenKey) if (newParent[parentChildrenKey]) newParent[parentChildrenKey].push(res);
1307
+ else newParent[parentChildrenKey] = [res];
1308
+ }
1309
+ if (queueOptions.depth === 0) result = res;
1310
+ return runQueue();
1311
+ };
1312
+ return runQueue();
1313
+ }
1314
+ function treeMap(tree, callback, options = {}) {
1315
+ const { childrenKey = "children", strategy = "pre", getChildrenKey } = options;
1316
+ const traversalMethod = strategies[strategy];
1317
+ const innerOptions = {
1318
+ childrenKey,
1319
+ depth: 0,
1320
+ parents: [],
1321
+ getChildrenKey
1322
+ };
1323
+ return isArray(tree) ? tree.map((row) => traversalMethod(row, callback, innerOptions)) : traversalMethod(tree, callback, innerOptions);
1324
+ }
1325
+
1326
+ //#endregion
1327
+ //#region src/utils/tree/rowsToTree.ts
1328
+ /**
1329
+ * 行结构 转 树结构
1330
+ */
1331
+ function rowsToTree(rows, options) {
1332
+ const { parentIdKey = "parentId", rowKey = "id", childrenKey = "children" } = options || {};
1333
+ const result = [];
1334
+ const map = /* @__PURE__ */ new Map();
1335
+ for (const row of rows) {
1336
+ const id = row[rowKey];
1337
+ if (!map.get(id)) map.set(id, row);
1338
+ }
1339
+ for (const row of rows) {
1340
+ const parentId = row[parentIdKey];
1341
+ const parent = map.get(parentId);
1342
+ if (!parent || !parentId) {
1343
+ result.push(row);
1344
+ continue;
1345
+ }
1346
+ const siblings = parent[childrenKey];
1347
+ if (isNull(siblings) || isUndefined(siblings)) parent[childrenKey] = [row];
1348
+ else if (Array.isArray(siblings)) siblings.push(row);
1349
+ else {
1350
+ const message = `The key "${childrenKey.toString()}" in parent item is not an array.`;
1351
+ throw new Error(message);
1352
+ }
1353
+ }
1354
+ return result;
1355
+ }
1356
+
1357
+ //#endregion
1358
+ //#region src/utils/tree/treeToRows.ts
1359
+ /**
1360
+ * 树结构 转 行结构
1361
+ */
1362
+ function treeToRows(tree, options = {}) {
1363
+ const { childrenKey = "children" } = options;
1364
+ const result = [];
1365
+ if (!tree) return result;
1366
+ treeForEach(tree, (t) => result.push({
1367
+ ...t,
1368
+ [childrenKey]: void 0
1369
+ }), options);
1370
+ return result;
1371
+ }
1372
+
1373
+ //#endregion
1374
+ export { arrayCast, arrayCompete, arrayCounting, arrayDifference, arrayFirst, arrayFork, arrayIntersection, arrayLast, arrayMerge, arrayPick, arrayReplace, arraySplit, cloneDeep, enumEntries, enumKeys, enumTypeCheck, enumValues, isAbortSignal, isArray, isAsyncFunction, isAsyncGeneratorFunction, isBigInt, isBlob, isBoolean, isClass, isDate, isEqual, isError, isFalsy, isFalsyLike, isFile, isFunction, isGeneratorFunction, isInfinity, isInfinityLike, isInteger, isIterable, isMap, isNaN, isNegativeInteger, isNull, isNumber, isObject, isPositiveInteger, isPromise, isPromiseLike, isReadableStream, isRegExp, isSet, isString, isSymbol, isTypedArray, isURLSearchParams, isUndefined, isWeakMap, isWeakSet, isWebSocket, isWindow, mapEntries, objectAssign, objectCrush, objectEntries, objectKeys, objectPick, objectSwitch, objectValues, rowsToTree, stringInitialCase, stringReplace, stringTemplate, stringToJson, stringToNumber, stringToValues, to, toMathBignumber, toMathDecimal, toMathEvaluate, treeFilter, treeFind, treeForEach, treeMap, treeToRows };
1375
+ //# sourceMappingURL=index.js.map