@pawover/kit 0.4.1 → 0.5.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.
@@ -1,4 +1,6 @@
1
1
  import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
2
+ import { ArrayUtil, EnvUtil, ObjectUtil, StringUtil, TypeUtil } from "@pawover/kit-utils";
3
+ import { clone, isEqual } from "es-toolkit";
2
4
  //#region src/react/useLatest.ts
3
5
  /**
4
6
  * 返回当前最新值的 Hook
@@ -11,2017 +13,6 @@ function useLatest(value) {
11
13
  return ref;
12
14
  }
13
15
  //#endregion
14
- //#region ../utils/dist/math-Cvy9HBP0.js
15
- /**
16
- * 类型工具类
17
- */
18
- var TypeUtil = class {
19
- static PROTOTYPE_TAGS = {
20
- STRING: "[object String]",
21
- NUMBER: "[object Number]",
22
- BOOLEAN: "[object Boolean]",
23
- BIGINT: "[object BigInt]",
24
- SYMBOL: "[object Symbol]",
25
- UNDEFINED: "[object Undefined]",
26
- NULL: "[object Null]",
27
- OBJECT: "[object Object]",
28
- FUNCTION: "[object Function]",
29
- GENERATOR_FUNCTION: "[object GeneratorFunction]",
30
- ASYNC_FUNCTION: "[object AsyncFunction]",
31
- ASYNC_GENERATOR_FUNCTION: "[object AsyncGeneratorFunction]",
32
- PROMISE: "[object Promise]",
33
- MAP: "[object Map]",
34
- SET: "[object Set]",
35
- WEAK_MAP: "[object WeakMap]",
36
- WEAK_SET: "[object WeakSet]",
37
- BLOB: "[object Blob]",
38
- FILE: "[object File]",
39
- READABLE_STREAM: "[object ReadableStream]",
40
- GLOBAL: "[object global]",
41
- WINDOW: "[object Window]",
42
- IFRAME: "[object HTMLIFrameElement]",
43
- DATE: "[object Date]",
44
- ERROR: "[object Error]",
45
- REG_EXP: "[object RegExp]",
46
- WEB_SOCKET: "[object WebSocket]",
47
- URL_SEARCH_PARAMS: "[object URLSearchParams]",
48
- ABORT_SIGNAL: "[object AbortSignal]"
49
- };
50
- static TYPED_ARRAY_TAGS = /* @__PURE__ */ new Set([
51
- "[object Int8Array]",
52
- "[object Uint8Array]",
53
- "[object Uint8ClampedArray]",
54
- "[object Int16Array]",
55
- "[object Uint16Array]",
56
- "[object Int32Array]",
57
- "[object Uint32Array]",
58
- "[object Float32Array]",
59
- "[object Float64Array]",
60
- "[object BigInt64Array]",
61
- "[object BigUint64Array]"
62
- ]);
63
- /**
64
- * 获取值的 [[Prototype]] 标签
65
- *
66
- * @param value - 任意 JavaScript 值
67
- * @returns 标准化的类型标签字符串
68
- */
69
- static getPrototypeString(value) {
70
- return Object.prototype.toString.call(value);
71
- }
72
- static isConstructable(fn) {
73
- try {
74
- Reflect.construct(fn, []);
75
- return true;
76
- } catch {
77
- return false;
78
- }
79
- }
80
- /**
81
- * 检查 value 是否为 string 类型
82
- * - 当 `checkEmpty` 为 `true` 时,会先 trim 再判断是否为空
83
- *
84
- * @param value 待检查值
85
- * @param checkEmpty 是否检查空字符串(含空白字符串),默认为 `false`
86
- * @returns 是否为字符串
87
- * @example
88
- * ```ts
89
- * TypeUtil.isString("abc"); // true
90
- * TypeUtil.isString(""); // true
91
- * TypeUtil.isString("", true); // false
92
- * TypeUtil.isString(" ", true); // false
93
- * TypeUtil.isString(" a ", true); // true
94
- * ```
95
- */
96
- static isString(value, checkEmpty = false) {
97
- return typeof value === "string" && (!checkEmpty || value.trim().length > 0);
98
- }
99
- /**
100
- * 检查 value 是否为 number 类型
101
- * - 默认会调用 `TypeUtil.isNaN`(内部基于 `Number.isNaN`)过滤掉 `NaN`
102
- *
103
- * @param value 待检查值
104
- * @param checkNaN 是否检查 `NaN`,默认为 `true`
105
- * @returns 是否为 number
106
- * @example
107
- * ```ts
108
- * TypeUtil.isNumber(1); // true
109
- * TypeUtil.isNumber(NaN); // false (default)
110
- * TypeUtil.isNumber(NaN, false); // true
111
- * ```
112
- */
113
- static isNumber(value, checkNaN = true) {
114
- return typeof value === "number" && (!checkNaN || !this.isNaN(value));
115
- }
116
- /**
117
- * 检查 value 是否为 NaN
118
- * - 禁止使用全局 `isNaN`,其会先进行隐式数字转换,可能导致误判(例如 `isNaN("foo") === true`)
119
- * - 使用 `Number.isNaN` 仅在值本身就是 `NaN` 时返回 `true`,语义更严格且更安全
120
- *
121
- * @param value 待检查值
122
- * @returns 是否为 NaN
123
- * @example
124
- * ```ts
125
- * TypeUtil.isNaN(NaN); // true
126
- * ```
127
- */
128
- static isNaN(value) {
129
- return Number.isNaN(value);
130
- }
131
- /**
132
- * 检查 value 是否为整数
133
- *
134
- * @param value 待检查值
135
- * @param checkSafe 是否附加安全整数检查
136
- * @returns 是否为整数
137
- * @example
138
- * ```ts
139
- * TypeUtil.isInteger(1); // true
140
- * TypeUtil.isInteger(1.1); // false
141
- * ```
142
- */
143
- static isInteger(value, checkSafe = true) {
144
- const check = Number.isInteger(value);
145
- return checkSafe ? check && Number.isSafeInteger(value) : check;
146
- }
147
- /**
148
- * 检查 value 是否为正整数
149
- * - 此函数中 `0` 不被视为正整数
150
- *
151
- * @param value 待检查值
152
- * @param checkSafe 是否附加安全整数检查
153
- * @example
154
- * ```ts
155
- * TypeUtil.isPositiveInteger(1); // true
156
- * TypeUtil.isPositiveInteger(0); // false
157
- * ```
158
- */
159
- static isPositiveInteger(value, checkSafe = true) {
160
- return this.isInteger(value, checkSafe) && value > 0;
161
- }
162
- /**
163
- * 检查 value 是否为负整数
164
- * - 此函数中 `0` 不被视为负整数
165
- *
166
- * @param value 待检查值
167
- * @param checkSafe 是否附加安全整数检查
168
- * @example
169
- * ```ts
170
- * TypeUtil.isNegativeInteger(-1); // true
171
- * TypeUtil.isNegativeInteger(0); // false
172
- * ```
173
- */
174
- static isNegativeInteger(value, checkSafe = true) {
175
- return this.isInteger(value, checkSafe) && value < 0;
176
- }
177
- /**
178
- * 检查 value 是否为 Infinity
179
- * - 排除 `NaN`
180
- *
181
- * @param value 待检查值
182
- * @example
183
- * ```ts
184
- * TypeUtil.isInfinity(Infinity); // true
185
- * TypeUtil.isInfinity(1); // false
186
- * ```
187
- */
188
- static isInfinity(value) {
189
- return this.isNumber(value) && (Number.POSITIVE_INFINITY === value || Number.NEGATIVE_INFINITY === value);
190
- }
191
- /**
192
- * 检查 value 是否类似 Infinity
193
- * - 排除 `NaN`
194
- *
195
- * @param value 待检查值
196
- * @example
197
- * ```ts
198
- * TypeUtil.isInfinityLike("Infinity"); // true
199
- * TypeUtil.isInfinityLike("123"); // false
200
- * ```
201
- */
202
- static isInfinityLike(value) {
203
- const check = this.isInfinity(value);
204
- if (check) return check;
205
- if (typeof value === "string") return [
206
- "infinity",
207
- "-infinity",
208
- "+infinity",
209
- "Infinity",
210
- "-Infinity",
211
- "+Infinity"
212
- ].includes(value.trim());
213
- return false;
214
- }
215
- /**
216
- * 检查 value 是否为 Boolean
217
- * @param value 待检查值
218
- * @returns 是否为 Boolean
219
- * @example
220
- * ```ts
221
- * TypeUtil.isBoolean(false); // true
222
- * ```
223
- */
224
- static isBoolean(value) {
225
- return typeof value === "boolean";
226
- }
227
- /**
228
- * 检查 value 是否为 BigInt
229
- * @param value 待检查值
230
- * @returns 是否为 BigInt
231
- * @example
232
- * ```ts
233
- * TypeUtil.isBigInt(1n); // true
234
- * ```
235
- */
236
- static isBigInt(value) {
237
- return typeof value === "bigint";
238
- }
239
- /**
240
- * 检查 value 是否为 Symbol
241
- * @param value 待检查值
242
- * @returns 是否为 Symbol
243
- * @example
244
- * ```ts
245
- * TypeUtil.isSymbol(Symbol("a")); // true
246
- * ```
247
- */
248
- static isSymbol(value) {
249
- return typeof value === "symbol";
250
- }
251
- /**
252
- * 检查 value 是否为 undefined
253
- * @param value 待检查值
254
- * @returns 是否为 undefined
255
- * @example
256
- * ```ts
257
- * TypeUtil.isUndefined(undefined); // true
258
- * ```
259
- */
260
- static isUndefined(value) {
261
- return typeof value === "undefined";
262
- }
263
- /**
264
- * 检查 value 是否为 null
265
- * @param value 待检查值
266
- * @returns 是否为 null
267
- * @example
268
- * ```ts
269
- * TypeUtil.isNull(null); // true
270
- * ```
271
- */
272
- static isNull(value) {
273
- return value === null;
274
- }
275
- /**
276
- * 检查 value 是否为 Function
277
- * @param value 待检查值
278
- * @returns 是否为 Function
279
- * @example
280
- * ```ts
281
- * TypeUtil.isFunction(() => {}); // true
282
- * ```
283
- */
284
- static isFunction(value) {
285
- return typeof value === "function";
286
- }
287
- /**
288
- * 检查 value 是否为 AsyncFunction
289
- * @param value 待检查值
290
- * @returns 是否为 AsyncFunction
291
- * @example
292
- * ```ts
293
- * TypeUtil.isAsyncFunction(async () => {}); // true
294
- * ```
295
- */
296
- static isAsyncFunction(value) {
297
- return this.isFunction(value) && this.getPrototypeString(value) === this.PROTOTYPE_TAGS.ASYNC_FUNCTION;
298
- }
299
- /**
300
- * 检查 value 是否为 GeneratorFunction
301
- * @param value 待检查值
302
- * @returns 是否为 GeneratorFunction
303
- * @example
304
- * ```ts
305
- * TypeUtil.isGeneratorFunction(function * a () {}); // true
306
- * ```
307
- */
308
- static isGeneratorFunction(value) {
309
- return this.isFunction(value) && this.getPrototypeString(value) === this.PROTOTYPE_TAGS.GENERATOR_FUNCTION;
310
- }
311
- /**
312
- * 检查 value 是否为 AsyncGeneratorFunction
313
- * @param value 待检查值
314
- * @returns 是否为 AsyncGeneratorFunction
315
- * @example
316
- * ```ts
317
- * TypeUtil.isAsyncGeneratorFunction(async function * a () {}); // true
318
- * ```
319
- */
320
- static isAsyncGeneratorFunction(value) {
321
- return this.isFunction(value) && this.getPrototypeString(value) === this.PROTOTYPE_TAGS.ASYNC_GENERATOR_FUNCTION;
322
- }
323
- /**
324
- * 检查 value 是否为 Promise
325
- * @param value 待检查值
326
- * @returns 是否为 Promise
327
- * @example
328
- * ```ts
329
- * TypeUtil.isPromise(Promise.resolve(1)); // true
330
- * ```
331
- */
332
- static isPromise(value) {
333
- return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.PROMISE;
334
- }
335
- /**
336
- * 检查 value 是否为 PromiseLike
337
- * - 可识别拥有 then 方法的非 Promise 对象
338
- * @param value 待检查值
339
- * @returns 是否为 PromiseLike
340
- * @example
341
- * ```ts
342
- * TypeUtil.isPromiseLike({ then: () => {} }); // true
343
- * ```
344
- */
345
- static isPromiseLike(value) {
346
- return this.isPromise(value) || this.isPlainObject(value, false) && this.isFunction(value["then"]);
347
- }
348
- /**
349
- * 判断是否为普通对象类型
350
- * - 可选是否检查原型为 `Object.prototype`,防止原型链污染
351
- *
352
- * @param value 待检查值
353
- * @param prototypeCheck 是否进行原型检查,默认 `true`
354
- * @returns 是否为 Plain Object (当 prototypeCheck=true) 或 object
355
- * @example
356
- * ```ts
357
- * TypeUtil.isPlainObject({}); // true
358
- * TypeUtil.isPlainObject([]); // false
359
- * TypeUtil.isPlainObject(new Date()); // false
360
- * TypeUtil.isPlainObject(new (class {})()); // false
361
- * TypeUtil.isPlainObject(new (class {})(), false); // true
362
- * TypeUtil.isPlainObject(Object.create(null)) // false
363
- * TypeUtil.isPlainObject(Object.create(null), false) // true
364
- * ```
365
- */
366
- static isPlainObject(value, prototypeCheck = true) {
367
- const check = this.getPrototypeString(value) === this.PROTOTYPE_TAGS.OBJECT;
368
- return prototypeCheck ? check && Object.getPrototypeOf(value) === Object.prototype : check;
369
- }
370
- /**
371
- * 判断是否为广义对象类型
372
- *
373
- * @param value 待检查值
374
- * @returns 是否为对象
375
- * @example
376
- * ```ts
377
- * TypeUtil.isObject({}); // true
378
- * TypeUtil.isObject([]); // true
379
- * TypeUtil.isObject(new Date()); // true
380
- * TypeUtil.isObject(null); // false
381
- * TypeUtil.isObject("string"); // false
382
- * ```
383
- */
384
- static isObject(value) {
385
- return typeof value === "object" && value !== null;
386
- }
387
- /**
388
- * 判断一个对象是否为有效的枚举
389
- * - 枚举成员不能为空
390
- * - 枚举成员的键不能具有数值名
391
- * - 枚举成员的值必须类型一致且为 `string` 或 `number` 类型
392
- * - 枚举成员的值不能重复
393
- * - 枚举成员的值必须全部为双向映射或非双向映射
394
- *
395
- * @param enumeration 待检查值
396
- * @returns [是否为有效的枚举, 是否为双向枚举]
397
- * @example
398
- * ```ts
399
- * enum A { X, Y }
400
- * TypeUtil.isEnumeration(A); // [true, true]
401
- * ```
402
- */
403
- static isEnumeration(enumeration) {
404
- if (typeof enumeration !== "object" || enumeration === null) return [false, false];
405
- const keys = Object.keys(enumeration);
406
- if (keys.length === 0) return [false, false];
407
- const originalKeys = [];
408
- const numericKeys = [];
409
- for (const key of keys) if (/^\d+$/.test(key)) numericKeys.push(key);
410
- else originalKeys.push(key);
411
- if (originalKeys.length === 0) return [false, false];
412
- let valueType = null;
413
- const values = [];
414
- for (const key of originalKeys) {
415
- const value = enumeration[key];
416
- const type = typeof value;
417
- if (type !== "string" && type !== "number") return [false, false];
418
- if (valueType === null) valueType = type;
419
- else if (type !== valueType) return [false, false];
420
- values.push(value);
421
- }
422
- if (new Set(values).size !== values.length) return [false, false];
423
- let isBidirectional = false;
424
- if (numericKeys.length > 0) {
425
- if (numericKeys.length !== originalKeys.length) return [false, false];
426
- const reverseMappedNames = /* @__PURE__ */ new Set();
427
- for (const numKey of numericKeys) {
428
- const reverseValue = enumeration[numKey];
429
- if (typeof reverseValue !== "string") return [false, false];
430
- if (!originalKeys.includes(reverseValue)) return [false, false];
431
- reverseMappedNames.add(reverseValue);
432
- }
433
- if (reverseMappedNames.size !== originalKeys.length) return [false, false];
434
- isBidirectional = true;
435
- }
436
- return [true, isBidirectional];
437
- }
438
- /**
439
- * 检查 value 是否为 Class
440
- *
441
- * @param value 待检查值
442
- * @returns 是否为 Class
443
- * @example
444
- * ```ts
445
- * class A {}
446
- * TypeUtil.isClass(A); // true
447
- * TypeUtil.isClass(() => {}); // false
448
- * ```
449
- */
450
- static isClass(value) {
451
- return this.isFunction(value) && !this.isAsyncFunction(value) && Function.prototype.toString.call(value).startsWith("class ") && this.isConstructable(value) && value.prototype !== void 0;
452
- }
453
- /**
454
- * 检查 value 是否为数组
455
- *
456
- * @param value 待检查值
457
- * @returns 是否为数组
458
- * @example
459
- * ```ts
460
- * TypeUtil.isArray([]); // true
461
- * ```
462
- */
463
- static isArray(value) {
464
- return Array.isArray(value);
465
- }
466
- /**
467
- * 检查 value 是否为 TypedArray
468
- *
469
- * @param value 待检查值
470
- * @returns 是否为 TypedArray
471
- * @example
472
- * ```ts
473
- * TypeUtil.isTypedArray(new Int8Array()); // true
474
- * ```
475
- */
476
- static isTypedArray(value) {
477
- return typeof value === "object" && value !== null && this.TYPED_ARRAY_TAGS.has(this.getPrototypeString(value));
478
- }
479
- /**
480
- * 检查 value 是否为 Map
481
- * @param value 待检查值
482
- * @returns 是否为 Map
483
- * @example
484
- * ```ts
485
- * TypeUtil.isMap(new Map()); // true
486
- * ```
487
- */
488
- static isMap(value) {
489
- return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.MAP;
490
- }
491
- /**
492
- * 检查 value 是否为 WeakMap
493
- * @param value 待检查值
494
- * @returns 是否为 WeakMap
495
- * @example
496
- * ```ts
497
- * TypeUtil.isWeakMap(new WeakMap()); // true
498
- * ```
499
- */
500
- static isWeakMap(value) {
501
- return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.WEAK_MAP;
502
- }
503
- /**
504
- * 检查 value 是否为 Set
505
- * @param value 待检查值
506
- * @returns 是否为 Set
507
- * @example
508
- * ```ts
509
- * TypeUtil.isSet(new Set()); // true
510
- * ```
511
- */
512
- static isSet(value) {
513
- return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.SET;
514
- }
515
- /**
516
- * 检查 value 是否为 WeakSet
517
- * @param value 待检查值
518
- * @returns 是否为 WeakSet
519
- * @example
520
- * ```ts
521
- * TypeUtil.isWeakSet(new WeakSet()); // true
522
- * ```
523
- */
524
- static isWeakSet(value) {
525
- return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.WEAK_SET;
526
- }
527
- /**
528
- * 检查 value 是否为 Blob
529
- * @param value 待检查值
530
- * @returns 是否为 Blob
531
- * @example
532
- * ```ts
533
- * TypeUtil.isBlob(new Blob(["a"])); // true
534
- * ```
535
- */
536
- static isBlob(value) {
537
- return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.BLOB;
538
- }
539
- /**
540
- * 检查 value 是否为 File
541
- * @param value 待检查值
542
- * @returns 是否为 File
543
- * @example
544
- * ```ts
545
- * TypeUtil.isFile(new File(["a"], "a.txt")); // true
546
- * ```
547
- */
548
- static isFile(value) {
549
- return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.FILE;
550
- }
551
- /**
552
- * 检查 value 是否为 ReadableStream
553
- * - Uses `Object.prototype.toString` where supported (modern browsers, Node.js ≥18).
554
- * - Falls back to duck-typing in older environments.
555
- * - Resistant to basic forgery, but not 100% secure in all polyfill scenarios.
556
- * - ⚠️ Note: In older Node.js (<18) or with non-compliant polyfills, this may return false positives or negatives.
557
- *
558
- * @param value 待检查值
559
- * @returns 是否为 ReadableStream
560
- * @example
561
- * ```ts
562
- * TypeUtil.isReadableStream(new ReadableStream()); // true
563
- * ```
564
- */
565
- static isReadableStream(value) {
566
- if (this.getPrototypeString(value) === this.PROTOTYPE_TAGS.READABLE_STREAM) return true;
567
- return this.isPlainObject(value) && this.isFunction(value["getReader"]) && this.isFunction(value["pipeThrough"]);
568
- }
569
- /**
570
- * 检查 value 是否为 Window
571
- * @param value 待检查值
572
- * @returns 是否为 Window
573
- * @example
574
- * ```ts
575
- * TypeUtil.isWindow(window); // true
576
- * ```
577
- */
578
- static isWindow(value) {
579
- return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.WINDOW;
580
- }
581
- /**
582
- * 检查 value 是否为 HTMLIFrameElement
583
- * @param value 待检查值
584
- * @returns 是否为 HTMLIFrameElement
585
- * @example
586
- * ```ts
587
- * TypeUtil.isIframe(document.createElement("iframe")); // true
588
- * ```
589
- */
590
- static isIframe(value) {
591
- if (typeof window === "undefined") return false;
592
- return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.IFRAME;
593
- }
594
- /**
595
- * 检查 value 是否为 Date 对象
596
- *
597
- * @param value 待检查值
598
- * @param invalidCheck 是否要求日期有效(非 Invalid Date)。默认 true
599
- * - true: 仅当是有效 Date 对象时返回 true(排除 new Date('invalid'))
600
- * - false: 只要 [[Prototype]] 是 Date 即返回 true(包含 Invalid Date)
601
- * @returns 是否为 Date 对象,根据 invalidCheck 返回不同语义的 Date 判定
602
- *
603
- * @example
604
- * ```ts
605
- * TypeUtil.isDate(new Date()); // true
606
- * TypeUtil.isDate(new Date('invalid')); // false
607
- * TypeUtil.isDate(new Date('invalid'), false); // true
608
- * TypeUtil.isDate(null); // false
609
- * TypeUtil.isDate({}); // false
610
- * ```
611
- */
612
- static isDate(value, invalidCheck = true) {
613
- if (!value || typeof value !== "object") return false;
614
- if (this.getPrototypeString(value) !== this.PROTOTYPE_TAGS.DATE) return false;
615
- if (!invalidCheck) return true;
616
- try {
617
- const time = value.getTime();
618
- return typeof time === "number" && !Number.isNaN(time);
619
- } catch {
620
- return false;
621
- }
622
- }
623
- /**
624
- * 检查 value 是否为 Error 对象
625
- * @param value 待检查值
626
- * @returns 是否为 Error
627
- * @example
628
- * ```ts
629
- * TypeUtil.isError(new Error("x")); // true
630
- * ```
631
- */
632
- static isError(value) {
633
- return value instanceof Error || this.getPrototypeString(value) === this.PROTOTYPE_TAGS.ERROR;
634
- }
635
- /**
636
- * 检查 value 是否为 RegExp
637
- * @param value 待检查值
638
- * @returns 是否为 RegExp
639
- * @example
640
- * ```ts
641
- * TypeUtil.isRegExp(/a/); // true
642
- * ```
643
- */
644
- static isRegExp(value) {
645
- if (typeof value !== "object" || value === null) return false;
646
- try {
647
- const regex = value;
648
- return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.REG_EXP && this.isString(regex.source) && this.isString(regex.flags) && this.isBoolean(regex.global) && this.isFunction(regex.test);
649
- } catch (error) {
650
- return false;
651
- }
652
- }
653
- /**
654
- * 检查 value 是否为 WebSocket
655
- * @param value 待检查值
656
- * @returns 是否为 WebSocket
657
- * @example
658
- * ```ts
659
- * TypeUtil.isWebSocket(new WebSocket("wss://echo.websocket.events")); // true
660
- * ```
661
- */
662
- static isWebSocket(value) {
663
- return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.WEB_SOCKET;
664
- }
665
- /**
666
- * 检查 value 是否为 URLSearchParams
667
- * @param value 待检查值
668
- * @returns 是否为 URLSearchParams
669
- * @example
670
- * ```ts
671
- * TypeUtil.isURLSearchParams(new URLSearchParams("a=1")); // true
672
- * ```
673
- */
674
- static isURLSearchParams(value) {
675
- return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.URL_SEARCH_PARAMS;
676
- }
677
- /**
678
- * 检查 value 是否为 AbortSignal
679
- * @param value 待检查值
680
- * @returns 是否为 AbortSignal
681
- * @example
682
- * ```ts
683
- * TypeUtil.isAbortSignal(new AbortController().signal); // true
684
- * ```
685
- */
686
- static isAbortSignal(value) {
687
- return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.ABORT_SIGNAL;
688
- }
689
- /**
690
- * 检查 value 是否为可迭代对象 (Iterable)
691
- * @param value 待检查值
692
- * @returns 是否为 Iterable
693
- * @example
694
- * ```ts
695
- * TypeUtil.isIterable([1, 2]); // true
696
- * ```
697
- */
698
- static isIterable(value) {
699
- return !!value && typeof value[Symbol.iterator] === "function";
700
- }
701
- /**
702
- * 检查 value 是否为 Falsy 值 (false, 0, "", null, undefined, NaN)
703
- * @param value 待检查值
704
- * @returns 是否为 Falsy
705
- * @example
706
- * ```ts
707
- * TypeUtil.isFalsy(0); // true
708
- * ```
709
- */
710
- static isFalsy(value) {
711
- if (this.isNaN(value) || this.isNull(value) || this.isUndefined(value)) return true;
712
- return value === false || value === 0 || value === 0n || value === "";
713
- }
714
- /**
715
- * 检查 value 是否为 FalsyLike 值
716
- * - 包含字符串形式的 `"null"`、`"undefined"`、`"false"`、`"0"` 等
717
- *
718
- * @param value 待检查值
719
- * @returns 是否为 FalsyLike
720
- * @example
721
- * ```ts
722
- * TypeUtil.isFalsyLike("false"); // true
723
- * TypeUtil.isFalsyLike("hello"); // false
724
- * ```
725
- */
726
- static isFalsyLike(value) {
727
- if (this.isFalsy(value)) return true;
728
- return typeof value === "string" && (value === "null" || value === "undefined" || value === "NaN" || value === "false" || value === "0" || value === "-0" || value === "0n");
729
- }
730
- };
731
- /**
732
- * 字符串工具类
733
- */
734
- var StringUtil = class {
735
- static cast(candidate, checkEmpty = true, trim = true) {
736
- if (checkEmpty) {
737
- if (candidate === null || candidate === void 0) return "";
738
- if (typeof candidate === "string" && candidate.trim().length === 0) return "";
739
- }
740
- const result = String(candidate);
741
- return trim ? result.trim() : result;
742
- }
743
- /**
744
- * 从字符串中提取数字字符串
745
- * - 移除非数字字符,保留符号和小数点
746
- *
747
- * @param input 待处理字符串
748
- * @returns 提取出的数字字符串
749
- * @example
750
- * ```ts
751
- * StringUtil.toNumber("$1,234.56"); // "1234.56"
752
- * StringUtil.toNumber("abc-123"); // "-123"
753
- * ```
754
- */
755
- static toNumber(input) {
756
- if (!TypeUtil.isString(input, true)) return "0";
757
- const cleaned = input.replace(/[^0-9.-]/g, "");
758
- if (!cleaned) return "0";
759
- let isDecimal = false;
760
- let signCount = 0;
761
- let firstIndex = -1;
762
- const stringList = cleaned.split("").map((s, i) => {
763
- if (s === ".") {
764
- if (isDecimal) return "";
765
- isDecimal = true;
766
- return ".";
767
- }
768
- if (s === "-") {
769
- firstIndex === -1 && signCount++;
770
- return "";
771
- }
772
- firstIndex === -1 && (firstIndex = i);
773
- return s;
774
- });
775
- const sign = signCount % 2 === 1 ? "-" : "";
776
- if (firstIndex === -1) return sign + "0";
777
- let result = stringList.join("");
778
- if (result.startsWith(".")) result = "0" + result;
779
- if (result.endsWith(".")) result = result.slice(0, -1);
780
- return sign + result;
781
- }
782
- static toLowerCase(input) {
783
- if (!TypeUtil.isString(input, true)) return "";
784
- return input.toLowerCase();
785
- }
786
- static toUpperCase(input) {
787
- if (!TypeUtil.isString(input, true)) return "";
788
- return input.toUpperCase();
789
- }
790
- /**
791
- * 字符串首字母大小写
792
- * - 包含非西欧字母字符时,不处理
793
- * - 纯字母且全大写时,不处理
794
- * - 纯字母且非全大写时,首字母小写,其余保留
795
- * - 纯字母且非全大写时,首字母大写,其余保留
796
- *
797
- * @param input 待处理字符串
798
- * @param caseType 大小写类型
799
- * @returns 处理后的字符串
800
- * @example
801
- * ```ts
802
- * StringUtil.toInitialCase("Hello", "lower"); // "hello"
803
- * StringUtil.toInitialCase("hello", "upper"); // "Hello"
804
- * ```
805
- */
806
- static toInitialCase(input, caseType) {
807
- if (!TypeUtil.isString(input, true)) return "";
808
- return input.replace(/\S+/g, (word) => {
809
- if (/[^a-zA-Z\u00C0-\u017F]/.test(word)) return word;
810
- if (word === word.toLocaleUpperCase()) return word;
811
- if (caseType === "lower" && word[0]) return word[0].toLocaleLowerCase() + word.slice(1);
812
- if (caseType === "upper" && word[0]) return word[0].toLocaleUpperCase() + word.slice(1);
813
- return word;
814
- });
815
- }
816
- /**
817
- * 将路径转换为 POSIX 风格
818
- * - 统一使用正斜杠 (/)
819
- * - 可选移除 Windows 盘符 (如 C:)
820
- * - 可选移除开头的斜杠
821
- * - 规范化连续斜杠为单个斜杠
822
- *
823
- * @param input 待处理字符串
824
- * @param removeLeadingSlash 是否移除开头斜杠,默认为 `false`。如果移除了盘符,路径通常会以 / 开头,此参数可控制是否保留该 /
825
- * @returns 转换后的路径,如果输入无效则返回空字符串
826
- *
827
- * @example
828
- * ```ts
829
- * StringUtil.toPosix("C:\\Windows\\System32"); // 默认: "/Windows/System32" (移除了 C: 并标准化)
830
- *
831
- * StringUtil.toPosix("C:\\Windows\\System32", true); // 移除开头斜杠: "Windows/System32"
832
- *
833
- * StringUtil.toPosix("\\\\server\\share\\file.txt"); // UNC 路径: "/server/share/file.txt"
834
- *
835
- * StringUtil.toPosix("folder\\subfolder\\file.txt"); // 相对路径: "folder/subfolder/file.txt"
836
- * ```
837
- */
838
- static toPosix(input, removeLeadingSlash = false) {
839
- if (!TypeUtil.isString(input, true)) return "";
840
- let normalized = input.replace(/^[A-Za-z]:([\\/])?/, (_, separator) => {
841
- return separator ? "/" : "";
842
- });
843
- normalized = normalized.replaceAll("\\", "/");
844
- normalized = normalized.replaceAll(/\/+/g, "/");
845
- if (removeLeadingSlash && normalized.startsWith("/")) normalized = normalized.substring(1);
846
- return normalized;
847
- }
848
- static toJson(input, fallback) {
849
- if (!TypeUtil.isString(input, true)) return fallback;
850
- try {
851
- return JSON.parse(input);
852
- } catch (error) {
853
- return fallback;
854
- }
855
- }
856
- static toValues(input, valueType = "number", splitSymbol = ",") {
857
- if (!TypeUtil.isString(input, true)) return [];
858
- try {
859
- const values = input.split(splitSymbol);
860
- if (valueType === "number") return values.map((d) => Number(d));
861
- return values;
862
- } catch (error) {
863
- return [];
864
- }
865
- }
866
- /**
867
- * 从字符串中裁切掉所有的前缀和后缀字符
868
- *
869
- * @param input 待处理字符串
870
- * @param charsToTrim 裁切字符,默认为 `" "`
871
- * @returns 裁切后的字符串
872
- * @example
873
- * ```ts
874
- * StringUtil.trim(" hello "); // "hello"
875
- * StringUtil.trim("__hello__", "_"); // "hello"
876
- * ```
877
- */
878
- static trim(input, charsToTrim = " ") {
879
- if (!TypeUtil.isString(input, true)) return "";
880
- const toTrim = charsToTrim.replace(/[\W]{1}/g, "\\$&");
881
- const regex = new RegExp(`^[${toTrim}]+|[${toTrim}]+$`, "g");
882
- return input.replace(regex, "");
883
- }
884
- /**
885
- * 截取字符串
886
- * - 支持自定义省略符,不会截断在汉字中间(因为JS字符串本身按字符处理)
887
- *
888
- * @param input 待处理字符串
889
- * @param maxLength 最大长度 (包含省略符)
890
- * @param ellipsis 省略符,默认为 `...`
891
- * @returns 截取后的字符串
892
- * @example
893
- * ```ts
894
- * StringUtil.truncate("hello world", 8); // "hello..."
895
- * ```
896
- */
897
- static truncate(input, maxLength, ellipsis = "...") {
898
- if (!TypeUtil.isString(input, true)) return "";
899
- const codePoints = Array.from(input);
900
- if (!TypeUtil.isInteger(maxLength) || maxLength < 0) return input;
901
- if (codePoints.length <= maxLength) return input;
902
- const availableLength = maxLength - ellipsis.length;
903
- if (availableLength <= 0) return "";
904
- return codePoints.slice(0, availableLength).join("") + ellipsis;
905
- }
906
- /**
907
- * 字符串模板替换
908
- * - 使用对象的属性值替换字符串中的 {{key}} 模板
909
- *
910
- * @param input 待处理字符串
911
- * @param template 模板对象
912
- * @param regex 模板匹配正则 (默认: `\{\{(.+?)\}\}`)
913
- * @returns 替换后的字符串
914
- * @example
915
- * ```ts
916
- * StringUtil.template("Hello {{name}}", { name: "World" }); // "Hello World"
917
- * ```
918
- */
919
- static template(input, template, regex = /\{\{(.+?)\}\}/g) {
920
- if (!TypeUtil.isString(input, true)) return "";
921
- regex.lastIndex = 0;
922
- let result = "";
923
- let from = 0;
924
- let match;
925
- while (match = regex.exec(input)) {
926
- const replacement = template[match[1]];
927
- const valueToInsert = replacement === null || replacement === void 0 ? match[0] : replacement;
928
- result += input.slice(from, match.index) + valueToInsert;
929
- from = regex.lastIndex;
930
- }
931
- return result + input.slice(from);
932
- }
933
- /**
934
- * 字符串替换
935
- * - 替换第一个匹配项
936
- *
937
- * @param input 待处理字符串
938
- * @param search 匹配项
939
- * @param replacement 替换项
940
- * @returns 替换后的字符串
941
- * @example
942
- * ```ts
943
- * StringUtil.replace("hello world", "world", "context"); // "hello context"
944
- * ```
945
- */
946
- static replace(input, search, replacement) {
947
- if (!TypeUtil.isString(input, true)) return "";
948
- return input.replace(search, replacement);
949
- }
950
- };
951
- //#endregion
952
- //#region ../utils/dist/index.js
953
- /**
954
- * 数组工具类
955
- */
956
- var ArrayUtil = class {
957
- static cast(candidate, checkEmpty = true) {
958
- if (checkEmpty && (TypeUtil.isUndefined(candidate) || TypeUtil.isNull(candidate))) return [];
959
- return TypeUtil.isArray(candidate) ? [...candidate] : [candidate];
960
- }
961
- static first(initialList, fallback) {
962
- if (!TypeUtil.isArray(initialList) || initialList.length === 0) return fallback;
963
- return initialList[0];
964
- }
965
- static last(initialList, fallback) {
966
- if (!TypeUtil.isArray(initialList) || initialList.length === 0) return fallback;
967
- return initialList[initialList.length - 1];
968
- }
969
- /**
970
- * 数组竞选
971
- * - 返回在匹配函数的比较条件中获胜的最终项目,适用于更复杂的最小值/最大值计算
972
- *
973
- * @param initialList 数组
974
- * @param match 匹配函数
975
- * @returns 获胜的元素,如果数组为空或参数无效则返回 `null`
976
- * @example
977
- * ```ts
978
- * const list = [1, 10, 5];
979
- * ArrayUtil.compete(list, (a, b) => (a > b ? a : b)); // 10
980
- * ArrayUtil.compete(list, (a, b) => (a < b ? a : b)); // 1
981
- * ```
982
- */
983
- static compete(initialList, match) {
984
- if (!TypeUtil.isArray(initialList) || initialList.length === 0 || !TypeUtil.isFunction(match)) return null;
985
- return initialList.reduce(match);
986
- }
987
- /**
988
- * 统计数组的项目出现次数
989
- * - 通过给定的标识符匹配函数,返回一个对象,其中键是回调函数返回的 key 值,每个值是一个整数,表示该 key 出现的次数
990
- *
991
- * @param initialList 初始数组
992
- * @param match 匹配函数
993
- * @returns 统计对象
994
- * @example
995
- * ```ts
996
- * const list = ["a", "b", "a", "c"];
997
- * ArrayUtil.count(list, (x) => x); // { a: 2, b: 1, c: 1 }
998
- *
999
- * const users = [{ id: 1, group: "A" }, { id: 2, group: "B" }, { id: 3, group: "A" }];
1000
- * ArrayUtil.count(users, (u) => u.group); // { A: 2, B: 1 }
1001
- * ```
1002
- */
1003
- static count(initialList, match) {
1004
- if (!TypeUtil.isArray(initialList) || !TypeUtil.isFunction(match)) return {};
1005
- return initialList.reduce((prev, curr, index) => {
1006
- const id = match(curr, index).toString();
1007
- prev[id] = (prev[id] ?? 0) + 1;
1008
- return prev;
1009
- }, {});
1010
- }
1011
- /**
1012
- * 获取数组差集
1013
- * - 返回在 `initialList` 中存在,但在 `diffList` 中不存在的元素
1014
- *
1015
- * @param initialList 初始数组
1016
- * @param diffList 对比数组
1017
- * @param match 匹配函数
1018
- * @returns 差集数组
1019
- * @example
1020
- * ```ts
1021
- * ArrayUtil.difference([1, 2, 3], [2, 3, 4]); // [1]
1022
- * ArrayUtil.difference([{ id: 1 }, { id: 2 }], [{ id: 2 }], (x) => x.id); // [{ id: 1 }]
1023
- * ```
1024
- */
1025
- static difference(initialList, diffList, match) {
1026
- if (!TypeUtil.isArray(initialList) && !TypeUtil.isArray(diffList)) return [];
1027
- if (!TypeUtil.isArray(initialList) || !initialList.length) return [];
1028
- if (!TypeUtil.isArray(diffList) || !diffList.length) return [...initialList];
1029
- if (!TypeUtil.isFunction(match)) {
1030
- const arraySet = new Set(diffList);
1031
- return Array.from(new Set(initialList.filter((item) => !arraySet.has(item))));
1032
- }
1033
- const map = /* @__PURE__ */ new Map();
1034
- diffList.forEach((item, index) => {
1035
- map.set(match(item, index), true);
1036
- });
1037
- return initialList.filter((item, index) => !map.get(match(item, index)));
1038
- }
1039
- static intersection(initialList, diffList, match) {
1040
- if (!TypeUtil.isArray(initialList) || !TypeUtil.isArray(diffList)) return [];
1041
- if (!initialList.length || !diffList.length) return [];
1042
- if (!TypeUtil.isFunction(match)) {
1043
- const diffSet = new Set(diffList);
1044
- return initialList.filter((item) => diffSet.has(item));
1045
- }
1046
- const diffKeys = new Set(diffList.map((item, index) => match(item, index)));
1047
- return initialList.filter((item, index) => diffKeys.has(match(item, index)));
1048
- }
1049
- static merge(initialList, mergeList, match) {
1050
- if (!TypeUtil.isArray(initialList)) return [];
1051
- if (!TypeUtil.isArray(mergeList)) return [...initialList];
1052
- if (!TypeUtil.isFunction(match)) return Array.from(/* @__PURE__ */ new Set([...initialList, ...mergeList]));
1053
- const keys = /* @__PURE__ */ new Map();
1054
- mergeList.forEach((item, index) => {
1055
- keys.set(match(item, index), item);
1056
- });
1057
- return initialList.map((prevItem, index) => {
1058
- const key = match(prevItem, index);
1059
- return keys.has(key) ? keys.get(key) : prevItem;
1060
- });
1061
- }
1062
- static pick(initialList, filter, mapper) {
1063
- if (!TypeUtil.isArray(initialList)) return [];
1064
- if (!TypeUtil.isFunction(filter)) return [...initialList];
1065
- const hasMapper = TypeUtil.isFunction(mapper);
1066
- return initialList.reduce((prev, curr, index) => {
1067
- if (!filter(curr, index)) return prev;
1068
- if (hasMapper) prev.push(mapper(curr, index));
1069
- else prev.push(curr);
1070
- return prev;
1071
- }, []);
1072
- }
1073
- static replace(initialList, newItem, match) {
1074
- if (!TypeUtil.isArray(initialList) || !initialList.length) return [];
1075
- if (!TypeUtil.isFunction(match)) return [...initialList];
1076
- for (let i = 0; i < initialList.length; i++) {
1077
- const item = initialList[i];
1078
- if (match(item, i)) return [
1079
- ...initialList.slice(0, i),
1080
- newItem,
1081
- ...initialList.slice(i + 1, initialList.length)
1082
- ];
1083
- }
1084
- return [...initialList];
1085
- }
1086
- /**
1087
- * 数组项替换并移动
1088
- * - 在给定的数组中,替换并移动符合匹配函数结果的项目
1089
- * - 只替换和移动第一个匹配项
1090
- * - 未匹配时,根据 `position` 在指定位置插入 `newItem`
1091
- *
1092
- * @param initialList 初始数组
1093
- * @param newItem 替换项
1094
- * @param match 匹配函数
1095
- * @param position 移动位置,可选 `start` | `end` | 索引位置, 默认为 `end`
1096
- * @returns
1097
- * @example
1098
- * ```ts
1099
- * ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2, 0); // [5, 1, 3, 4]
1100
- * ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2, 2); // [1, 3, 5, 4]
1101
- * ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2, "start"); // [5, 1, 3, 4]
1102
- * ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2); // [1, 3, 4, 5]
1103
- * ```
1104
- */
1105
- static replaceMove(initialList, newItem, match, position) {
1106
- if (!TypeUtil.isArray(initialList)) return [];
1107
- if (!initialList.length) return [newItem];
1108
- if (!TypeUtil.isFunction(match)) return [...initialList];
1109
- const result = [...initialList];
1110
- const matchIndex = initialList.findIndex(match);
1111
- if (matchIndex !== -1) result.splice(matchIndex, 1);
1112
- if (position === "start") result.unshift(newItem);
1113
- else if (position === 0 || TypeUtil.isPositiveInteger(position, false)) result.splice(Math.min(position, result.length), 0, newItem);
1114
- else result.push(newItem);
1115
- return result;
1116
- }
1117
- /**
1118
- * 数组切分
1119
- * - 将数组以指定的长度切分后,组合在高维数组中
1120
- *
1121
- * @param initialList 初始数组
1122
- * @param size 分割尺寸,默认 `10`
1123
- * @returns 切分后的二维数组
1124
- * @example
1125
- * ```ts
1126
- * ArrayUtil.split([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
1127
- * ```
1128
- */
1129
- static split(initialList, size = 10) {
1130
- if (!TypeUtil.isArray(initialList)) return [];
1131
- if (!TypeUtil.isPositiveInteger(size, false)) return [];
1132
- const count = Math.ceil(initialList.length / size);
1133
- return Array.from({ length: count }).fill(null).map((_c, i) => {
1134
- return initialList.slice(i * size, i * size + size);
1135
- });
1136
- }
1137
- /**
1138
- * 数组分组过滤
1139
- * - 给定一个数组和一个条件,返回一个由两个数组组成的元组,其中第一个数组包含所有满足条件的项,第二个数组包含所有不满足条件的项
1140
- *
1141
- * @param initialList 初始数组
1142
- * @param match 条件匹配函数
1143
- * @returns [满足条件的项[], 不满足条件的项[]]
1144
- * @example
1145
- * ```ts
1146
- * ArrayUtil.fork([1, 2, 3, 4], (n) => n % 2 === 0); // [[2, 4], [1, 3]]
1147
- * ```
1148
- */
1149
- static fork(initialList, match) {
1150
- const forked = [[], []];
1151
- if (TypeUtil.isArray(initialList)) initialList.forEach((item, index) => {
1152
- forked[match(item, index) ? 0 : 1].push(item);
1153
- });
1154
- return forked;
1155
- }
1156
- /**
1157
- * 数组解压
1158
- * - `ArrayUtil.zip` 的反向操作
1159
- *
1160
- * @param arrayList 压缩后的数组
1161
- * @returns 解压后的二维数组
1162
- * @example
1163
- * ```ts
1164
- * ArrayUtil.unzip([[1, "a"], [2, "b"]]); // [[1, 2], ["a", "b"]]
1165
- * ```
1166
- */
1167
- static unzip(arrayList) {
1168
- if (!TypeUtil.isArray(arrayList) || !arrayList.length) return [];
1169
- const out = new Array(arrayList.reduce((max, arr) => Math.max(max, arr.length), 0));
1170
- let index = 0;
1171
- const get = (array) => array[index];
1172
- for (; index < out.length; index++) out[index] = Array.from(arrayList, get);
1173
- return out;
1174
- }
1175
- static zip(...arrays) {
1176
- return this.unzip(arrays);
1177
- }
1178
- static zipToObject(keys, values) {
1179
- const result = {};
1180
- if (!TypeUtil.isArray(keys) || !keys.length) return result;
1181
- const getValue = TypeUtil.isFunction(values) ? values : TypeUtil.isArray(values) ? (_k, i) => values[i] : (_k, _i) => values;
1182
- return keys.reduce((acc, key, idx) => {
1183
- acc[key] = getValue(key, idx);
1184
- return acc;
1185
- }, result);
1186
- }
1187
- };
1188
- (class {
1189
- /**
1190
- * 每秒的毫秒数
1191
- * @example
1192
- * ```ts
1193
- * DateTimeUtil.MILLISECONDS_PER_SECOND; // 1000
1194
- * ```
1195
- */
1196
- static MILLISECONDS_PER_SECOND = 1e3;
1197
- /**
1198
- * 每分钟的秒数
1199
- * @example
1200
- * ```ts
1201
- * DateTimeUtil.SECOND_PER_MINUTE; // 60
1202
- * ```
1203
- */
1204
- static SECOND_PER_MINUTE = 60;
1205
- /**
1206
- * 每小时的分钟数
1207
- * @example
1208
- * ```ts
1209
- * DateTimeUtil.MINUTE_PER_HOUR; // 60
1210
- * ```
1211
- */
1212
- static MINUTE_PER_HOUR = 60;
1213
- /**
1214
- * 每小时的秒数
1215
- * @example
1216
- * ```ts
1217
- * DateTimeUtil.SECOND_PER_HOUR; // 3600
1218
- * ```
1219
- */
1220
- static SECOND_PER_HOUR = this.SECOND_PER_MINUTE ** 2;
1221
- /**
1222
- * 每天小时数
1223
- * @example
1224
- * ```ts
1225
- * DateTimeUtil.HOUR_PER_DAY; // 24
1226
- * ```
1227
- */
1228
- static HOUR_PER_DAY = 24;
1229
- /**
1230
- * 每天秒数
1231
- * @example
1232
- * ```ts
1233
- * DateTimeUtil.SECOND_PER_DAY; // 86400
1234
- * ```
1235
- */
1236
- static SECOND_PER_DAY = this.SECOND_PER_HOUR * this.HOUR_PER_DAY;
1237
- /**
1238
- * 每周天数
1239
- * @example
1240
- * ```ts
1241
- * DateTimeUtil.DAY_PER_WEEK; // 7
1242
- * ```
1243
- */
1244
- static DAY_PER_WEEK = 7;
1245
- /**
1246
- * 每月天数
1247
- * @example
1248
- * ```ts
1249
- * DateTimeUtil.DAY_PER_MONTH; // 30
1250
- * ```
1251
- */
1252
- static DAY_PER_MONTH = 30;
1253
- /**
1254
- * 每年天数
1255
- * @example
1256
- * ```ts
1257
- * DateTimeUtil.DAY_PER_YEAR; // 365
1258
- * ```
1259
- */
1260
- static DAY_PER_YEAR = 365;
1261
- /**
1262
- * 每年月数
1263
- * @example
1264
- * ```ts
1265
- * DateTimeUtil.MONTH_PER_YEAR; // 12
1266
- * ```
1267
- */
1268
- static MONTH_PER_YEAR = 12;
1269
- /**
1270
- * 每年平均周
1271
- * @example
1272
- * ```ts
1273
- * DateTimeUtil.WEEK_PER_YEAR; // 52
1274
- * ```
1275
- */
1276
- static WEEK_PER_YEAR = 52;
1277
- /**
1278
- * 每月平均周
1279
- * @example
1280
- * ```ts
1281
- * DateTimeUtil.WEEK_PER_MONTH; // 4
1282
- * ```
1283
- */
1284
- static WEEK_PER_MONTH = 4;
1285
- /**
1286
- * 常用时间格式模板集合
1287
- *
1288
- * @example
1289
- * ```ts
1290
- * DateTimeUtil.FORMAT.ISO_DATE; // "yyyy-MM-dd"
1291
- * DateTimeUtil.FORMAT.CN_DATE_TIME; // "yyyy年MM月dd日 HH时mm分ss秒"
1292
- * ```
1293
- */
1294
- static FORMAT = {
1295
- ISO_DATE: "yyyy-MM-dd",
1296
- ISO_TIME: "HH:mm:ss",
1297
- ISO_DATE_TIME: "yyyy-MM-dd HH:mm:ss",
1298
- ISO_DATE_TIME_MS: "yyyy-MM-dd HH:mm:ss.SSS",
1299
- ISO_DATETIME_TZ: "yyyy-MM-dd'T'HH:mm:ssXXX",
1300
- ISO_DATETIME_TZ_MS: "yyyy-MM-dd'T'HH:mm:ss.SSSXXX",
1301
- US_DATE: "MM/dd/yyyy",
1302
- US_DATE_TIME: "MM/dd/yyyy HH:mm:ss",
1303
- US_DATE_SHORT_YEAR: "MM/dd/yy",
1304
- EU_DATE: "dd/MM/yyyy",
1305
- EU_DATE_TIME: "dd/MM/yyyy HH:mm:ss",
1306
- CN_DATE: "yyyy年MM月dd日",
1307
- CN_DATE_TIME: "yyyy年MM月dd日 HH时mm分ss秒",
1308
- CN_DATE_WEEKDAY: "yyyy年MM月dd日 EEE",
1309
- CN_WEEKDAY_FULL: "EEEE",
1310
- SHORT_DATE: "yy-MM-dd",
1311
- SHORT_DATE_SLASH: "yy/MM/dd",
1312
- MONTH_DAY: "MM-dd",
1313
- MONTH_DAY_CN: "MM月dd日",
1314
- DATE_WITH_WEEKDAY_SHORT: "yyyy-MM-dd (EEE)",
1315
- DATE_WITH_WEEKDAY_FULL: "yyyy-MM-dd (EEEE)",
1316
- TIME_24: "HH:mm:ss",
1317
- TIME_24_NO_SEC: "HH:mm",
1318
- TIME_12: "hh:mm:ss a",
1319
- TIME_12_NO_SEC: "hh:mm a",
1320
- TIMESTAMP: "yyyyMMddHHmmss",
1321
- TIMESTAMP_MS: "yyyyMMddHHmmssSSS",
1322
- RFC2822: "EEE, dd MMM yyyy HH:mm:ss xxx",
1323
- READABLE_DATE: "MMM dd, yyyy",
1324
- READABLE_DATE_TIME: "MMM dd, yyyy HH:mm",
1325
- COMPACT_DATETIME: "yyyyMMdd_HHmmss"
1326
- };
1327
- /**
1328
- * 获取当前时区信息
1329
- *
1330
- * @returns 时区信息对象 (UTC偏移和时区名称)
1331
- * @example
1332
- * ```ts
1333
- * DateTimeUtil.getTimeZone(); // { UTC: "UTC+8", timeZone: "Asia/Shanghai" }
1334
- * ```
1335
- */
1336
- static getTimeZone() {
1337
- const hour = 0 - (/* @__PURE__ */ new Date()).getTimezoneOffset() / this.MINUTE_PER_HOUR;
1338
- return {
1339
- UTC: "UTC" + (hour >= 0 ? "+" + hour : hour),
1340
- timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone
1341
- };
1342
- }
1343
- });
1344
- /**
1345
- * 环境检查工具类
1346
- */
1347
- var EnvUtil = class {
1348
- static _isBrowser = typeof window !== "undefined" && TypeUtil.isFunction(window?.document?.createElement);
1349
- static _isWebWorker = typeof window === "undefined" && typeof self !== "undefined" && "importScripts" in self;
1350
- static _isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
1351
- /**
1352
- * 检测是否处于浏览器环境
1353
- *
1354
- * @returns 是否为浏览器环境
1355
- * @example
1356
- * ```ts
1357
- * EnvUtil.isBrowser(); // true: 浏览器, false: Node.js
1358
- * ```
1359
- */
1360
- static isBrowser() {
1361
- return this._isBrowser;
1362
- }
1363
- /**
1364
- * 检测是否处于 Web Worker 环境
1365
- *
1366
- * @returns 是否为 Web Worker 环境
1367
- * @example
1368
- * ```ts
1369
- * EnvUtil.isWebWorker(); // true: Worker, false: 主线程/Node.js
1370
- * ```
1371
- */
1372
- static isWebWorker() {
1373
- return this._isWebWorker;
1374
- }
1375
- /**
1376
- * 检测是否处于 React Native 环境
1377
- *
1378
- * @returns 是否为 React Native 环境
1379
- * @example
1380
- * ```ts
1381
- * EnvUtil.isReactNative(); // true: React Native, false: Web/Node.js
1382
- * ```
1383
- */
1384
- static isReactNative() {
1385
- return this._isReactNative;
1386
- }
1387
- /**
1388
- * 检查是否在 iframe 环境中
1389
- *
1390
- * @returns 是否在 iframe 中
1391
- * @example
1392
- * ```ts
1393
- * EnvUtil.isIframe(); // true: 当前页面在 iframe 中
1394
- * ```
1395
- */
1396
- static isIframe() {
1397
- if (typeof window === "undefined") return false;
1398
- try {
1399
- return window.top !== window.self;
1400
- } catch (error) {
1401
- if (error.name === "SecurityError") return true;
1402
- return false;
1403
- }
1404
- }
1405
- /**
1406
- * 检测当前设备是否为桌面设备
1407
- *
1408
- * @param minWidth - 桌面设备最小宽度(默认 1200px)
1409
- * @param minScreenSize - 桌面设备最小屏幕尺寸(默认 10英寸)
1410
- * @param dpi - 标准 DPI 基准(默认 160)
1411
- * @returns 是否为桌面设备
1412
- * @example
1413
- * ```ts
1414
- * // 假设 window.innerWidth = 1920
1415
- * EnvUtil.isDesktop(); // true
1416
- *
1417
- * // 自定义阈值
1418
- * EnvUtil.isDesktop(1440, 13); // 更严格的桌面检测
1419
- * ```
1420
- */
1421
- static isDesktop(minWidth = 1200, minScreenSize = 10, dpi = 160) {
1422
- if (typeof window === "undefined" || !TypeUtil.isPositiveInteger(minWidth) || !TypeUtil.isPositiveInteger(minScreenSize)) return false;
1423
- if (window.innerWidth < minWidth) return false;
1424
- try {
1425
- const widthPx = window.screen.width;
1426
- const heightPx = window.screen.height;
1427
- const DPI = dpi * (window.devicePixelRatio || 1);
1428
- const widthInch = widthPx / DPI;
1429
- const heightInch = heightPx / DPI;
1430
- return Math.sqrt(widthInch ** 2 + heightInch ** 2) >= minScreenSize;
1431
- } catch {
1432
- return true;
1433
- }
1434
- }
1435
- /**
1436
- * 检测当前设备是否为 Windows 桌面设备
1437
- *
1438
- * @param minWidth - 桌面设备最小宽度(默认 1200px)
1439
- * @param minScreenSize - 桌面设备最小屏幕尺寸(默认 10英寸)
1440
- * @param dpi - 标准 DPI 基准(默认 160)
1441
- * @returns 是否为 Windows 桌面设备
1442
- * @example
1443
- * ```ts
1444
- * // UA contains Windows
1445
- * EnvUtil.isWindowsDesktop(); // true
1446
- * ```
1447
- */
1448
- static isWindowsDesktop(minWidth = 1200, minScreenSize = 10, dpi = 160) {
1449
- if (typeof navigator === "undefined" || !navigator.userAgent) return false;
1450
- return /Windows/i.test(navigator.userAgent) && this.isDesktop(minWidth, minScreenSize, dpi);
1451
- }
1452
- /**
1453
- * 检测当前设备是否为 macOS 桌面设备
1454
- *
1455
- * @param minWidth - 桌面设备最小宽度(默认 1200px)
1456
- * @param minScreenSize - 桌面设备最小屏幕尺寸(默认 10英寸)
1457
- * @param dpi - 标准 DPI 基准(默认 160)
1458
- * @returns 是否为 macOS 桌面设备
1459
- * @example
1460
- * ```ts
1461
- * // UA contains Macintosh
1462
- * EnvUtil.isMacOSDesktop(); // true
1463
- * ```
1464
- */
1465
- static isMacOSDesktop(minWidth = 1200, minScreenSize = 10, dpi = 160) {
1466
- if (typeof navigator === "undefined" || !navigator.userAgent) return false;
1467
- return /Macintosh/i.test(navigator.userAgent) && this.isDesktop(minWidth, minScreenSize, dpi);
1468
- }
1469
- /**
1470
- * 检测当前设备是否为移动设备
1471
- *
1472
- * @param maxWidth - 移动设备最大宽度(默认 768px)
1473
- * @param dpi - 标准 DPI 基准(默认 160)
1474
- * @returns 是否为移动设备
1475
- * @example
1476
- * ```ts
1477
- * // 假设 window.innerWidth = 500
1478
- * EnvUtil.isMobile(); // true
1479
- * ```
1480
- */
1481
- static isMobile(maxWidth = 768, dpi = 160) {
1482
- if (typeof window === "undefined" || !TypeUtil.isPositiveInteger(maxWidth)) return false;
1483
- if (window.innerWidth >= maxWidth) return false;
1484
- try {
1485
- const widthPx = window.screen.width;
1486
- const heightPx = window.screen.height;
1487
- const DPI = dpi * (window.devicePixelRatio || 1);
1488
- const widthInch = widthPx / DPI;
1489
- const heightInch = heightPx / DPI;
1490
- return Math.sqrt(widthInch ** 2 + heightInch ** 2) < 7;
1491
- } catch {
1492
- return true;
1493
- }
1494
- }
1495
- /**
1496
- * 检测当前设备是否为IOS移动设备
1497
- *
1498
- * @param maxWidth - 移动设备最大宽度(默认 768px)
1499
- * @param dpi - 标准 DPI 基准(默认 160)
1500
- * @returns 是否为 iOS 移动设备 (iPhone/iPod)
1501
- * @example
1502
- * ```ts
1503
- * // UA contains iPhone
1504
- * EnvUtil.isIOSMobile(); // true
1505
- * ```
1506
- */
1507
- static isIOSMobile(maxWidth = 768, dpi = 160) {
1508
- if (typeof navigator === "undefined" || !navigator.userAgent) return false;
1509
- return /iPhone|iPad|iPod/i.test(navigator.userAgent) && this.isMobile(maxWidth, dpi);
1510
- }
1511
- /**
1512
- * 检测当前设备是否为平板
1513
- *
1514
- * @param minWidth - 平板最小宽度(默认 768px)
1515
- * @param maxWidth - 平板最大宽度(默认 1200px)
1516
- * @param dpi - 标准 DPI 基准(默认 160)
1517
- * @returns 是否为平板设备
1518
- * @example
1519
- * ```ts
1520
- * // 假设 window.innerWidth = 1000
1521
- * EnvUtil.isTablet(); // true
1522
- * ```
1523
- */
1524
- static isTablet(minWidth = 768, maxWidth = 1200, dpi = 160) {
1525
- if (typeof window === "undefined" || !TypeUtil.isPositiveInteger(minWidth) || !TypeUtil.isPositiveInteger(maxWidth)) return false;
1526
- const width = window.innerWidth;
1527
- const isWithinWidthRange = width >= minWidth && width <= maxWidth;
1528
- try {
1529
- const widthPx = window.screen.width;
1530
- const heightPx = window.screen.height;
1531
- const DPI = dpi * (window.devicePixelRatio || 1);
1532
- const widthInch = widthPx / DPI;
1533
- const heightInch = heightPx / DPI;
1534
- const screenInches = Math.sqrt(widthInch ** 2 + heightInch ** 2);
1535
- return isWithinWidthRange || screenInches >= 7;
1536
- } catch {
1537
- return isWithinWidthRange;
1538
- }
1539
- }
1540
- };
1541
- /**
1542
- * MIME 工具类
1543
- */
1544
- var MimeUtil = class {
1545
- /**
1546
- * 文件类型 MIME 常量
1547
- * - 每个类型对应具体的文件扩展名
1548
- */
1549
- static FILE_MIME = {
1550
- /** 普通文本文件(.txt) */
1551
- TEXT: "text/plain",
1552
- /** 超文本标记语言文档(.html/.htm) */
1553
- HTML: "text/html",
1554
- /** 层叠样式表文件(.css) */
1555
- CSS: "text/css",
1556
- /** 逗号分隔值文件/表格数据(.csv) */
1557
- CSV: "text/csv",
1558
- /** 制表符分隔值文件(.tsv) */
1559
- TSV: "text/tab-separated-values",
1560
- /** XML 文档(.xml) */
1561
- XML: "application/xml",
1562
- /** XML 文档/兼容值 */
1563
- XML_LEGACY: "text/xml",
1564
- /** XHTML 文档(.xhtml/.xht) */
1565
- XHTML: "application/xhtml+xml",
1566
- /** JavaScript 文件(.js) */
1567
- JS: "text/javascript",
1568
- /** TypeScript 文件(.ts) */
1569
- TS: "text/typescript",
1570
- /** Python 文件(.py) */
1571
- PY: "text/x-python",
1572
- /** Shell 脚本 (.sh) */
1573
- SH: "text/x-sh",
1574
- /** C 语言源文件(.c) */
1575
- C: "text/x-c",
1576
- /** C++ 源文件(.cpp/.cc/.cxx) */
1577
- CPP: "text/x-c++",
1578
- /** C# 源文件(.cs) */
1579
- CSHARP: "text/x-csharp",
1580
- /** Java 源文件(.java) */
1581
- JAVA: "text/x-java",
1582
- /** Go 源文件(.go) */
1583
- GO: "text/x-go",
1584
- /** Rust 源文件(.rs) */
1585
- RUST: "text/x-rust",
1586
- /** PHP 文件(.php) */
1587
- PHP: "text/x-php",
1588
- /** Ruby 文件(.rb) */
1589
- RUBY: "text/x-ruby",
1590
- /** Swift 源文件(.swift) */
1591
- SWIFT: "text/x-swift",
1592
- /** YAML 文档(.yaml/.yml) */
1593
- YAML: "application/yaml",
1594
- /** YAML 文档/兼容值 */
1595
- YAML_LEGACY: "text/vnd.yaml",
1596
- /** TOML 文档(.toml) */
1597
- TOML: "application/toml",
1598
- /** TOML 文档/兼容值 */
1599
- TOML_LEGACY: "text/x-toml",
1600
- /** SQL 脚本(.sql) */
1601
- SQL: "application/sql",
1602
- /** SQL 脚本/兼容值 */
1603
- SQL_LEGACY: "text/x-sql",
1604
- /** Markdown 格式文档(.md/.markdown) */
1605
- MARKDOWN: "text/markdown",
1606
- /** 富文本格式文档(.rtf) */
1607
- RTF: "application/rtf",
1608
- /** iCalendar 日历格式(.ics) */
1609
- CALENDAR: "text/calendar",
1610
- /** JPEG 图像(.jpg/.jpeg) */
1611
- JPEG: "image/jpeg",
1612
- /** JPG 图像(JPEG 别名,.jpg) */
1613
- JPG: "image/jpeg",
1614
- /** PNG 图像/无损压缩,支持透明(.png) */
1615
- PNG: "image/png",
1616
- /** GIF 图像/支持动画(.gif) */
1617
- GIF: "image/gif",
1618
- /** Windows 位图(.bmp) */
1619
- BMP: "image/bmp",
1620
- /** SVG 向量图形(.svg) */
1621
- SVG: "image/svg+xml",
1622
- /** APNG 动态图像(.apng) */
1623
- APNG: "image/apng",
1624
- /** AVIF 图像/高效压缩(.avif) */
1625
- AVIF: "image/avif",
1626
- /** 图标文件格式(.ico) */
1627
- ICO: "image/vnd.microsoft.icon",
1628
- /** 图标文件格式/兼容值(.ico) */
1629
- ICO_LEGACY: "image/x-icon",
1630
- /** WebP 图像/高效压缩(.webp) */
1631
- WEBP: "image/webp",
1632
- /** TIFF 图像(.tif/.tiff) */
1633
- TIFF: "image/tiff",
1634
- /** HEIC 图像/高效编码(.heic) */
1635
- HEIC: "image/heic",
1636
- /** HEIF 图像/高效编码(.heif) */
1637
- HEIF: "image/heif",
1638
- /** Adobe Photoshop 文件(.psd) */
1639
- PSD: "image/vnd.adobe.photoshop",
1640
- /** MP3 音频(.mp3) */
1641
- MP3: "audio/mpeg",
1642
- /** AAC 音频(.aac) */
1643
- AAC: "audio/aac",
1644
- /** MIDI 音乐文件(.mid/.midi) */
1645
- MIDI: "audio/midi",
1646
- /** OGG 音频(.oga) */
1647
- OGG_AUDIO: "audio/ogg",
1648
- /** Opus 音频(.opus) */
1649
- OPUS: "audio/opus",
1650
- /** FLAC 无损音频(.flac) */
1651
- FLAC: "audio/flac",
1652
- /** WAV 音频(.wav) */
1653
- WAV: "audio/wav",
1654
- /** WebM 音频(.weba) */
1655
- WEBM_AUDIO: "audio/webm",
1656
- /** RealAudio 音频(.ra/.ram) */
1657
- REAL_AUDIO: "audio/x-pn-realaudio",
1658
- /** MP4 视频(.mp4) */
1659
- MP4: "video/mp4",
1660
- /** MPEG 视频(.mpeg/.mpg) */
1661
- MPEG: "video/mpeg",
1662
- /** OGG 视频(.ogv) */
1663
- OGG_VIDEO: "video/ogg",
1664
- /** AVI 视频(.avi) */
1665
- AVI: "video/x-msvideo",
1666
- /** 3GPP 视频(.3gp) */
1667
- THREE_GPP: "video/3gpp",
1668
- /** 3GPP2 视频(.3g2) */
1669
- THREE_GPP2: "video/3gpp2",
1670
- /** WebM 视频(.webm) */
1671
- WEBM: "video/webm",
1672
- /** Matroska 视频(.mkv) */
1673
- MKV: "video/x-matroska",
1674
- /** Matroska 音频(.mka) */
1675
- MKA: "audio/x-matroska",
1676
- /** QuickTime 视频(.mov) */
1677
- QUICKTIME: "video/quicktime",
1678
- /** PDF 文档(.pdf) */
1679
- PDF: "application/pdf",
1680
- /** Word 97-2003 文档(.doc) */
1681
- DOC: "application/msword",
1682
- /** Word 2007+ 文档(.docx) */
1683
- DOCX: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
1684
- /** Excel 2007+ 工作簿(.xlsx) */
1685
- XLSX: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
1686
- /** 启用宏的Excel工作簿(.xlsm) */
1687
- XLSM: "application/vnd.ms-excel.sheet.macroEnabled.12",
1688
- /** Excel模板文件(.xltx) */
1689
- XLTX: "application/vnd.openxmlformats-officedocument.spreadsheetml.template",
1690
- /** PowerPoint 2007+ 演示文稿(.pptx) */
1691
- PPTX: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
1692
- /** PowerPoint 97-2003 演示文稿(.ppt) */
1693
- PPT: "application/vnd.ms-powerpoint",
1694
- /** OpenDocument 文本文档(.odt) */
1695
- ODT: "application/vnd.oasis.opendocument.text",
1696
- /** OpenDocument 表格文档(.ods) */
1697
- ODS: "application/vnd.oasis.opendocument.spreadsheet",
1698
- /** OpenDocument 演示文稿(.odp) */
1699
- ODP: "application/vnd.oasis.opendocument.presentation",
1700
- /** EPUB 电子书(.epub) */
1701
- EPUB: "application/epub+zip",
1702
- /** Kindle 电子书(.azw) */
1703
- AZW: "application/vnd.amazon.ebook",
1704
- /** ZIP 压缩文件(.zip) */
1705
- ZIP: "application/zip",
1706
- /** GZIP 压缩文件(.gz) */
1707
- GZIP: "application/gzip",
1708
- /** TAR 归档文件(.tar) */
1709
- TAR: "application/x-tar",
1710
- /** BZip 归档(.bz) */
1711
- BZIP: "application/x-bzip",
1712
- /** BZip2 归档(.bz2) */
1713
- BZIP2: "application/x-bzip2",
1714
- /** 7-Zip 压缩文件(.7z) */
1715
- SEVEN_Z: "application/x-7z-compressed",
1716
- /** RAR 压缩文件(.rar) */
1717
- RAR: "application/vnd.rar",
1718
- /** XZ 压缩文件(.xz) */
1719
- XZ: "application/x-xz",
1720
- /** Zstandard 压缩文件(.zst) */
1721
- ZSTD: "application/zstd",
1722
- /** ISO 光盘镜像(.iso) */
1723
- ISO9660_IMAGE: "application/x-iso9660-image",
1724
- /** JSON 数据格式(.json) */
1725
- JSON: "application/json",
1726
- /** JSON-LD 格式(.jsonld) */
1727
- LD_JSON: "application/ld+json",
1728
- /** Web App Manifest(.webmanifest) */
1729
- MANIFEST: "application/manifest+json",
1730
- /** Java 归档文件(.jar) */
1731
- JAR: "application/java-archive",
1732
- /** WebAssembly 二进制指令格式(.wasm) */
1733
- WASM: "application/wasm",
1734
- /** MS 嵌入式 OpenType 字体(.eot) */
1735
- EOT: "application/vnd.ms-fontobject",
1736
- /** OpenType 字体(.otf) */
1737
- OTF: "font/otf",
1738
- /** WOFF 字体(.woff) */
1739
- WOFF: "font/woff",
1740
- /** WOFF2 字体(.woff2) */
1741
- WOFF2: "font/woff2",
1742
- /** TrueType 字体(.ttf) */
1743
- TTF: "font/ttf",
1744
- /** Excel 97-2003 工作簿(.xls) */
1745
- XLS: "application/vnd.ms-excel",
1746
- /** Microsoft XPS 文档(.xps) */
1747
- XPS: "application/vnd.ms-xpsdocument",
1748
- /** Word 启用宏文档(.docm) */
1749
- DOCM: "application/vnd.ms-word.document.macroEnabled.12"
1750
- };
1751
- /**
1752
- * 协议/内容类型 MIME 常量
1753
- * - 用于 HTTP 请求/响应内容协商,无对应文件扩展名
1754
- */
1755
- static PROTOCOL_MIME = {
1756
- /** 通用二进制数据流 */
1757
- OCTET_STREAM: "application/octet-stream",
1758
- /** URL 编码表单 */
1759
- FORM_URLENCODED: "application/x-www-form-urlencoded",
1760
- /** multipart 表单 */
1761
- FORM_DATA: "multipart/form-data",
1762
- /** Server-Sent Events 数据流 */
1763
- EVENT_STREAM: "text/event-stream",
1764
- /** 问题详情 JSON(RFC 9457) */
1765
- PROBLEM_JSON: "application/problem+json",
1766
- /** JSON Patch(RFC 6902) */
1767
- JSON_PATCH: "application/json-patch+json",
1768
- /** JSON Merge Patch(RFC 7386) */
1769
- MERGE_PATCH_JSON: "application/merge-patch+json"
1770
- };
1771
- /**
1772
- * 根据文件后缀名获取对应的标准 MIME 类型(含历史兼容值)
1773
- * - 支持带 `.` 或不带 `.` 的后缀名,不区分大小写
1774
- * - 元组第一项始终为 IANA 官方标准 MIME,后续项为历史兼容值
1775
- * - 仅查询文件类型 MIME,不包含无后缀对应的协议类型
1776
- *
1777
- * @param extension 文件后缀名(如 `".png"` / `"png"` / `".PNG"`)
1778
- * @returns 标准 MIME + 兼容值的元组;如无匹配则返回 `undefined`
1779
- * @example
1780
- * ```ts
1781
- * MimeUtil.fromExtension(".png"); // ["image/png"]
1782
- * MimeUtil.fromExtension("ico"); // ["image/vnd.microsoft.icon", "image/x-icon"]
1783
- * MimeUtil.fromExtension(".xml"); // ["application/xml", "text/xml"]
1784
- * MimeUtil.fromExtension(".xyz"); // undefined
1785
- * ```
1786
- */
1787
- static fromExtension(extension) {
1788
- const ext = StringUtil.cast(extension).toLowerCase();
1789
- const key = ext.startsWith(".") ? ext : `.${ext}`;
1790
- return EXT_TO_MIME[key];
1791
- }
1792
- /**
1793
- * 根据 MIME 类型获取对应的文件后缀名列表
1794
- * - 一个 MIME 类型可能对应多个后缀名(如 `text/html` → `.html` / `.htm`)
1795
- * - 兼容值和标准值映射到相同的后缀(如 `image/x-icon` 和 `image/vnd.microsoft.icon` 均返回 `[".ico"]`)
1796
- * - 仅查询文件类型 MIME,协议类型无对应后缀
1797
- *
1798
- * @param mime MIME 类型字符串(如 `"image/png"` / `"IMAGE/PNG"`)
1799
- * @returns 文件后缀名列表;如无匹配则返回 `undefined`
1800
- * @example
1801
- * ```ts
1802
- * MimeUtil.toExtension("IMAGE/PNG"); // [".png"]
1803
- * MimeUtil.toExtension("text/html"); // [".html", ".htm"]
1804
- * MimeUtil.toExtension("image/jpeg"); // [".jpg", ".jpeg"]
1805
- * MimeUtil.toExtension("application/octet-stream"); // undefined
1806
- * ```
1807
- */
1808
- static toExtension(mime) {
1809
- const m = StringUtil.cast(mime).toLowerCase();
1810
- return MIME_TO_EXT.get(m);
1811
- }
1812
- };
1813
- const EXT_TO_MIME = {
1814
- ".txt": [MimeUtil.FILE_MIME.TEXT],
1815
- ".html": [MimeUtil.FILE_MIME.HTML],
1816
- ".htm": [MimeUtil.FILE_MIME.HTML],
1817
- ".css": [MimeUtil.FILE_MIME.CSS],
1818
- ".csv": [MimeUtil.FILE_MIME.CSV],
1819
- ".tsv": [MimeUtil.FILE_MIME.TSV],
1820
- ".xml": [MimeUtil.FILE_MIME.XML, MimeUtil.FILE_MIME.XML_LEGACY],
1821
- ".xhtml": [MimeUtil.FILE_MIME.XHTML],
1822
- ".xht": [MimeUtil.FILE_MIME.XHTML],
1823
- ".js": [MimeUtil.FILE_MIME.JS],
1824
- ".ts": [MimeUtil.FILE_MIME.TS],
1825
- ".py": [MimeUtil.FILE_MIME.PY],
1826
- ".sh": [MimeUtil.FILE_MIME.SH],
1827
- ".c": [MimeUtil.FILE_MIME.C],
1828
- ".cpp": [MimeUtil.FILE_MIME.CPP],
1829
- ".cc": [MimeUtil.FILE_MIME.CPP],
1830
- ".cxx": [MimeUtil.FILE_MIME.CPP],
1831
- ".cs": [MimeUtil.FILE_MIME.CSHARP],
1832
- ".java": [MimeUtil.FILE_MIME.JAVA],
1833
- ".go": [MimeUtil.FILE_MIME.GO],
1834
- ".rs": [MimeUtil.FILE_MIME.RUST],
1835
- ".php": [MimeUtil.FILE_MIME.PHP],
1836
- ".rb": [MimeUtil.FILE_MIME.RUBY],
1837
- ".swift": [MimeUtil.FILE_MIME.SWIFT],
1838
- ".yaml": [MimeUtil.FILE_MIME.YAML, MimeUtil.FILE_MIME.YAML_LEGACY],
1839
- ".yml": [MimeUtil.FILE_MIME.YAML, MimeUtil.FILE_MIME.YAML_LEGACY],
1840
- ".toml": [MimeUtil.FILE_MIME.TOML, MimeUtil.FILE_MIME.TOML_LEGACY],
1841
- ".sql": [MimeUtil.FILE_MIME.SQL, MimeUtil.FILE_MIME.SQL_LEGACY],
1842
- ".md": [MimeUtil.FILE_MIME.MARKDOWN],
1843
- ".markdown": [MimeUtil.FILE_MIME.MARKDOWN],
1844
- ".rtf": [MimeUtil.FILE_MIME.RTF],
1845
- ".ics": [MimeUtil.FILE_MIME.CALENDAR],
1846
- ".jpg": [MimeUtil.FILE_MIME.JPEG],
1847
- ".jpeg": [MimeUtil.FILE_MIME.JPEG],
1848
- ".png": [MimeUtil.FILE_MIME.PNG],
1849
- ".gif": [MimeUtil.FILE_MIME.GIF],
1850
- ".bmp": [MimeUtil.FILE_MIME.BMP],
1851
- ".svg": [MimeUtil.FILE_MIME.SVG],
1852
- ".apng": [MimeUtil.FILE_MIME.APNG],
1853
- ".avif": [MimeUtil.FILE_MIME.AVIF],
1854
- ".ico": [MimeUtil.FILE_MIME.ICO, MimeUtil.FILE_MIME.ICO_LEGACY],
1855
- ".webp": [MimeUtil.FILE_MIME.WEBP],
1856
- ".tif": [MimeUtil.FILE_MIME.TIFF],
1857
- ".tiff": [MimeUtil.FILE_MIME.TIFF],
1858
- ".heic": [MimeUtil.FILE_MIME.HEIC],
1859
- ".heif": [MimeUtil.FILE_MIME.HEIF],
1860
- ".psd": [MimeUtil.FILE_MIME.PSD],
1861
- ".mp3": [MimeUtil.FILE_MIME.MP3],
1862
- ".aac": [MimeUtil.FILE_MIME.AAC],
1863
- ".mid": [MimeUtil.FILE_MIME.MIDI],
1864
- ".midi": [MimeUtil.FILE_MIME.MIDI],
1865
- ".oga": [MimeUtil.FILE_MIME.OGG_AUDIO],
1866
- ".opus": [MimeUtil.FILE_MIME.OPUS],
1867
- ".flac": [MimeUtil.FILE_MIME.FLAC],
1868
- ".wav": [MimeUtil.FILE_MIME.WAV],
1869
- ".weba": [MimeUtil.FILE_MIME.WEBM_AUDIO],
1870
- ".ra": [MimeUtil.FILE_MIME.REAL_AUDIO],
1871
- ".ram": [MimeUtil.FILE_MIME.REAL_AUDIO],
1872
- ".mp4": [MimeUtil.FILE_MIME.MP4],
1873
- ".mpeg": [MimeUtil.FILE_MIME.MPEG],
1874
- ".mpg": [MimeUtil.FILE_MIME.MPEG],
1875
- ".ogv": [MimeUtil.FILE_MIME.OGG_VIDEO],
1876
- ".avi": [MimeUtil.FILE_MIME.AVI],
1877
- ".3gp": [MimeUtil.FILE_MIME.THREE_GPP],
1878
- ".3g2": [MimeUtil.FILE_MIME.THREE_GPP2],
1879
- ".webm": [MimeUtil.FILE_MIME.WEBM],
1880
- ".mkv": [MimeUtil.FILE_MIME.MKV],
1881
- ".mka": [MimeUtil.FILE_MIME.MKA],
1882
- ".mov": [MimeUtil.FILE_MIME.QUICKTIME],
1883
- ".pdf": [MimeUtil.FILE_MIME.PDF],
1884
- ".doc": [MimeUtil.FILE_MIME.DOC],
1885
- ".docx": [MimeUtil.FILE_MIME.DOCX],
1886
- ".xlsx": [MimeUtil.FILE_MIME.XLSX],
1887
- ".xlsm": [MimeUtil.FILE_MIME.XLSM],
1888
- ".xltx": [MimeUtil.FILE_MIME.XLTX],
1889
- ".pptx": [MimeUtil.FILE_MIME.PPTX],
1890
- ".ppt": [MimeUtil.FILE_MIME.PPT],
1891
- ".odt": [MimeUtil.FILE_MIME.ODT],
1892
- ".ods": [MimeUtil.FILE_MIME.ODS],
1893
- ".odp": [MimeUtil.FILE_MIME.ODP],
1894
- ".epub": [MimeUtil.FILE_MIME.EPUB],
1895
- ".azw": [MimeUtil.FILE_MIME.AZW],
1896
- ".zip": [MimeUtil.FILE_MIME.ZIP],
1897
- ".gz": [MimeUtil.FILE_MIME.GZIP],
1898
- ".tar": [MimeUtil.FILE_MIME.TAR],
1899
- ".bz": [MimeUtil.FILE_MIME.BZIP],
1900
- ".bz2": [MimeUtil.FILE_MIME.BZIP2],
1901
- ".7z": [MimeUtil.FILE_MIME.SEVEN_Z],
1902
- ".rar": [MimeUtil.FILE_MIME.RAR],
1903
- ".xz": [MimeUtil.FILE_MIME.XZ],
1904
- ".zst": [MimeUtil.FILE_MIME.ZSTD],
1905
- ".iso": [MimeUtil.FILE_MIME.ISO9660_IMAGE],
1906
- ".json": [MimeUtil.FILE_MIME.JSON],
1907
- ".jsonld": [MimeUtil.FILE_MIME.LD_JSON],
1908
- ".webmanifest": [MimeUtil.FILE_MIME.MANIFEST],
1909
- ".jar": [MimeUtil.FILE_MIME.JAR],
1910
- ".wasm": [MimeUtil.FILE_MIME.WASM],
1911
- ".eot": [MimeUtil.FILE_MIME.EOT],
1912
- ".otf": [MimeUtil.FILE_MIME.OTF],
1913
- ".woff": [MimeUtil.FILE_MIME.WOFF],
1914
- ".woff2": [MimeUtil.FILE_MIME.WOFF2],
1915
- ".ttf": [MimeUtil.FILE_MIME.TTF],
1916
- ".xls": [MimeUtil.FILE_MIME.XLS],
1917
- ".xps": [MimeUtil.FILE_MIME.XPS],
1918
- ".docm": [MimeUtil.FILE_MIME.DOCM]
1919
- };
1920
- const MIME_TO_EXT = (() => {
1921
- const map = /* @__PURE__ */ new Map();
1922
- for (const [ext, mimes] of Object.entries(EXT_TO_MIME)) for (const mime of mimes) {
1923
- const exts = map.get(mime);
1924
- if (exts) {
1925
- if (!exts.includes(ext)) exts.push(ext);
1926
- } else map.set(mime, [ext]);
1927
- }
1928
- return map;
1929
- })();
1930
- /**
1931
- * 对象工具类
1932
- */
1933
- var ObjectUtil = class {
1934
- static keys(value) {
1935
- return Object.keys(value);
1936
- }
1937
- static values(value) {
1938
- return Object.values(value);
1939
- }
1940
- static entries(value) {
1941
- return Object.entries(value);
1942
- }
1943
- /**
1944
- * 映射对象条目
1945
- * - 将对象的键值对映射为新的键值对
1946
- *
1947
- * @param plainObject 对象
1948
- * @param toEntry 映射函数
1949
- * @returns 映射后的新对象
1950
- * @example
1951
- * ```ts
1952
- * const obj = { a: 1, b: 2 };
1953
- *
1954
- * ObjectUtil.entriesMap(obj, (k, v) => [k, v * 2]); // { a: 2, b: 4 }
1955
- *
1956
- * ObjectUtil.entriesMap(obj, (k, v) => [`prefix_${String(k)}`, `${v}x`]); // { prefix_a: "1x", prefix_b: "2x" }
1957
- * ```
1958
- */
1959
- static entriesMap(plainObject, toEntry) {
1960
- const defaultResult = {};
1961
- if (!TypeUtil.isPlainObject(plainObject)) return defaultResult;
1962
- return this.entries(plainObject).reduce((acc, [key, value]) => {
1963
- const [newKey, newValue] = toEntry(key, value);
1964
- acc[newKey] = newValue;
1965
- return acc;
1966
- }, defaultResult);
1967
- }
1968
- static pick(obj, keys) {
1969
- const result = {};
1970
- if (!TypeUtil.isPlainObject(obj)) return result;
1971
- if (!TypeUtil.isArray(keys)) return obj;
1972
- return keys.reduce((acc, key) => {
1973
- if (key in obj) acc[key] = obj[key];
1974
- return acc;
1975
- }, result);
1976
- }
1977
- static omit(obj, keys) {
1978
- const result = {};
1979
- if (!TypeUtil.isPlainObject(obj)) return result;
1980
- if (!TypeUtil.isArray(keys)) return obj;
1981
- const keysToOmit = new Set(keys);
1982
- return Object.keys(obj).reduce((acc, key) => {
1983
- if (!keysToOmit.has(key)) acc[key] = obj[key];
1984
- return acc;
1985
- }, result);
1986
- }
1987
- static invert(obj) {
1988
- const result = {};
1989
- if (!TypeUtil.isPlainObject(obj)) return result;
1990
- for (const [k, v] of this.entries(obj)) if (TypeUtil.isString(v) || TypeUtil.isNumber(v) || TypeUtil.isSymbol(v)) result[v] = k;
1991
- return result;
1992
- }
1993
- static crush(obj) {
1994
- if (!obj) return {};
1995
- function crushReducer(crushed, value, path) {
1996
- if (TypeUtil.isPlainObject(value) || TypeUtil.isArray(value)) for (const [prop, propValue] of Object.entries(value)) crushReducer(crushed, propValue, path ? `${path}.${prop}` : prop);
1997
- else crushed[path] = value;
1998
- return crushed;
1999
- }
2000
- return crushReducer({}, obj, "");
2001
- }
2002
- static enumKeys(enumeration) {
2003
- const [isEnum, isBidirectionalEnum] = TypeUtil.isEnumeration(enumeration);
2004
- if (!isEnum) throw Error("function [enumKeys] expected parameter to be a enum, and requires at least one member");
2005
- const keys = this.keys(enumeration);
2006
- if (isBidirectionalEnum) return keys.splice(keys.length / 2, keys.length / 2);
2007
- return keys;
2008
- }
2009
- static enumValues(enumeration) {
2010
- const [isEnum, isBidirectionalEnum] = TypeUtil.isEnumeration(enumeration);
2011
- if (!isEnum) throw Error("function [enumValues] expected parameter to be a enum, and requires at least one member");
2012
- const values = this.values(enumeration);
2013
- if (isBidirectionalEnum) return values.splice(values.length / 2, values.length / 2);
2014
- return values;
2015
- }
2016
- static enumEntries(enumeration) {
2017
- const [isEnum, isBidirectionalEnum] = TypeUtil.isEnumeration(enumeration);
2018
- if (!isEnum) throw Error("function [enumEntries] expected parameter to be a enum, and requires at least one member");
2019
- const entries = this.entries(enumeration);
2020
- if (isBidirectionalEnum) return entries.splice(entries.length / 2, entries.length / 2);
2021
- return entries;
2022
- }
2023
- };
2024
- //#endregion
2025
16
  //#region src/react/useMount.ts
2026
17
  /**
2027
18
  * 在组件初始化时执行的 Hook
@@ -2056,423 +47,6 @@ function useMount(effect) {
2056
47
  }, [effectRef]);
2057
48
  }
2058
49
  //#endregion
2059
- //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/_internal/globalThis.mjs
2060
- const globalThis_ = typeof globalThis === "object" && globalThis || typeof window === "object" && window || typeof self === "object" && self || typeof global === "object" && global || (function() {
2061
- return this;
2062
- })();
2063
- //#endregion
2064
- //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/function/noop.mjs
2065
- /**
2066
- * A no-operation function that does nothing.
2067
- * This can be used as a placeholder or default function.
2068
- *
2069
- * @example
2070
- * noop(); // Does nothing
2071
- *
2072
- * @returns This function does not return anything.
2073
- */
2074
- function noop() {}
2075
- //#endregion
2076
- //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/predicate/isPrimitive.mjs
2077
- /**
2078
- * Checks whether a value is a JavaScript primitive.
2079
- * JavaScript primitives include null, undefined, strings, numbers, booleans, symbols, and bigints.
2080
- *
2081
- * @param value The value to check.
2082
- * @returns Returns true if `value` is a primitive, false otherwise.
2083
- *
2084
- * @example
2085
- * isPrimitive(null); // true
2086
- * isPrimitive(undefined); // true
2087
- * isPrimitive('123'); // true
2088
- * isPrimitive(false); // true
2089
- * isPrimitive(true); // true
2090
- * isPrimitive(Symbol('a')); // true
2091
- * isPrimitive(123n); // true
2092
- * isPrimitive({}); // false
2093
- * isPrimitive(new Date()); // false
2094
- * isPrimitive(new Map()); // false
2095
- * isPrimitive(new Set()); // false
2096
- * isPrimitive([1, 2, 3]); // false
2097
- */
2098
- function isPrimitive(value) {
2099
- return value == null || typeof value !== "object" && typeof value !== "function";
2100
- }
2101
- //#endregion
2102
- //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/predicate/isTypedArray.mjs
2103
- /**
2104
- * Checks if a value is a TypedArray.
2105
- * @param x The value to check.
2106
- * @returns Returns true if `x` is a TypedArray, false otherwise.
2107
- *
2108
- * @example
2109
- * const arr = new Uint8Array([1, 2, 3]);
2110
- * isTypedArray(arr); // true
2111
- *
2112
- * const regularArray = [1, 2, 3];
2113
- * isTypedArray(regularArray); // false
2114
- *
2115
- * const buffer = new ArrayBuffer(16);
2116
- * isTypedArray(buffer); // false
2117
- */
2118
- function isTypedArray(x) {
2119
- return ArrayBuffer.isView(x) && !(x instanceof DataView);
2120
- }
2121
- //#endregion
2122
- //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/object/clone.mjs
2123
- /**
2124
- * Creates a shallow clone of the given object.
2125
- *
2126
- * @template T - The type of the object.
2127
- * @param obj - The object to clone.
2128
- * @returns A shallow clone of the given object.
2129
- *
2130
- * @example
2131
- * // Clone a primitive value
2132
- * const num = 29;
2133
- * const clonedNum = clone(num);
2134
- * console.log(clonedNum); // 29
2135
- * console.log(clonedNum === num); // true
2136
- *
2137
- * @example
2138
- * // Clone an array
2139
- * const arr = [1, 2, 3];
2140
- * const clonedArr = clone(arr);
2141
- * console.log(clonedArr); // [1, 2, 3]
2142
- * console.log(clonedArr === arr); // false
2143
- *
2144
- * @example
2145
- * // Clone an object
2146
- * const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };
2147
- * const clonedObj = clone(obj);
2148
- * console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }
2149
- * console.log(clonedObj === obj); // false
2150
- */
2151
- function clone(obj) {
2152
- if (isPrimitive(obj)) return obj;
2153
- if (Array.isArray(obj) || isTypedArray(obj) || obj instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && obj instanceof SharedArrayBuffer) return obj.slice(0);
2154
- const prototype = Object.getPrototypeOf(obj);
2155
- if (prototype == null) return Object.assign(Object.create(prototype), obj);
2156
- const Constructor = prototype.constructor;
2157
- if (obj instanceof Date || obj instanceof Map || obj instanceof Set) return new Constructor(obj);
2158
- if (obj instanceof RegExp) {
2159
- const newRegExp = new Constructor(obj);
2160
- newRegExp.lastIndex = obj.lastIndex;
2161
- return newRegExp;
2162
- }
2163
- if (obj instanceof DataView) return new Constructor(obj.buffer.slice(0));
2164
- if (obj instanceof Error) {
2165
- let newError;
2166
- if (obj instanceof AggregateError) newError = new Constructor(obj.errors, obj.message, { cause: obj.cause });
2167
- else newError = new Constructor(obj.message, { cause: obj.cause });
2168
- newError.stack = obj.stack;
2169
- Object.assign(newError, obj);
2170
- return newError;
2171
- }
2172
- if (typeof File !== "undefined" && obj instanceof File) return new Constructor([obj], obj.name, {
2173
- type: obj.type,
2174
- lastModified: obj.lastModified
2175
- });
2176
- if (typeof obj === "object") return Object.assign(Object.create(prototype), obj);
2177
- return obj;
2178
- }
2179
- //#endregion
2180
- //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/predicate/isBuffer.mjs
2181
- /**
2182
- * Checks if the given value is a Buffer instance.
2183
- *
2184
- * This function tests whether the provided value is an instance of Buffer.
2185
- * It returns `true` if the value is a Buffer, and `false` otherwise.
2186
- *
2187
- * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Buffer`.
2188
- *
2189
- * @param x - The value to check if it is a Buffer.
2190
- * @returns Returns `true` if `x` is a Buffer, else `false`.
2191
- *
2192
- * @example
2193
- * const buffer = Buffer.from("test");
2194
- * console.log(isBuffer(buffer)); // true
2195
- *
2196
- * const notBuffer = "not a buffer";
2197
- * console.log(isBuffer(notBuffer)); // false
2198
- */
2199
- function isBuffer(x) {
2200
- return typeof globalThis_.Buffer !== "undefined" && globalThis_.Buffer.isBuffer(x);
2201
- }
2202
- //#endregion
2203
- //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/compat/_internal/getSymbols.mjs
2204
- function getSymbols(object) {
2205
- return Object.getOwnPropertySymbols(object).filter((symbol) => Object.prototype.propertyIsEnumerable.call(object, symbol));
2206
- }
2207
- //#endregion
2208
- //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/compat/_internal/getTag.mjs
2209
- /**
2210
- * Gets the `toStringTag` of `value`.
2211
- *
2212
- * @private
2213
- * @param {T} value The value to query.
2214
- * @returns {string} Returns the `Object.prototype.toString.call` result.
2215
- */
2216
- function getTag(value) {
2217
- if (value == null) return value === void 0 ? "[object Undefined]" : "[object Null]";
2218
- return Object.prototype.toString.call(value);
2219
- }
2220
- //#endregion
2221
- //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/compat/_internal/tags.mjs
2222
- const regexpTag = "[object RegExp]";
2223
- const stringTag = "[object String]";
2224
- const numberTag = "[object Number]";
2225
- const booleanTag = "[object Boolean]";
2226
- const symbolTag = "[object Symbol]";
2227
- const dateTag = "[object Date]";
2228
- const mapTag = "[object Map]";
2229
- const setTag = "[object Set]";
2230
- const arrayTag = "[object Array]";
2231
- const functionTag = "[object Function]";
2232
- const arrayBufferTag = "[object ArrayBuffer]";
2233
- const objectTag = "[object Object]";
2234
- const errorTag = "[object Error]";
2235
- const dataViewTag = "[object DataView]";
2236
- const uint8ArrayTag = "[object Uint8Array]";
2237
- const uint8ClampedArrayTag = "[object Uint8ClampedArray]";
2238
- const uint16ArrayTag = "[object Uint16Array]";
2239
- const uint32ArrayTag = "[object Uint32Array]";
2240
- const bigUint64ArrayTag = "[object BigUint64Array]";
2241
- const int8ArrayTag = "[object Int8Array]";
2242
- const int16ArrayTag = "[object Int16Array]";
2243
- const int32ArrayTag = "[object Int32Array]";
2244
- const bigInt64ArrayTag = "[object BigInt64Array]";
2245
- const float32ArrayTag = "[object Float32Array]";
2246
- const float64ArrayTag = "[object Float64Array]";
2247
- //#endregion
2248
- //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/predicate/isPlainObject.mjs
2249
- /**
2250
- * Checks if a given value is a plain object.
2251
- *
2252
- * @param value - The value to check.
2253
- * @returns True if the value is a plain object, otherwise false.
2254
- *
2255
- * @example
2256
- * ```typescript
2257
- * // ✅👇 True
2258
- *
2259
- * isPlainObject({ }); // ✅
2260
- * isPlainObject({ key: 'value' }); // ✅
2261
- * isPlainObject({ key: new Date() }); // ✅
2262
- * isPlainObject(new Object()); // ✅
2263
- * isPlainObject(Object.create(null)); // ✅
2264
- * isPlainObject({ nested: { key: true} }); // ✅
2265
- * isPlainObject(new Proxy({}, {})); // ✅
2266
- * isPlainObject({ [Symbol('tag')]: 'A' }); // ✅
2267
- *
2268
- * // ✅👇 (cross-realms, node context, workers, ...)
2269
- * const runInNewContext = await import('node:vm').then(
2270
- * (mod) => mod.runInNewContext
2271
- * );
2272
- * isPlainObject(runInNewContext('({})')); // ✅
2273
- *
2274
- * // ❌👇 False
2275
- *
2276
- * class Test { };
2277
- * isPlainObject(new Test()) // ❌
2278
- * isPlainObject(10); // ❌
2279
- * isPlainObject(null); // ❌
2280
- * isPlainObject('hello'); // ❌
2281
- * isPlainObject([]); // ❌
2282
- * isPlainObject(new Date()); // ❌
2283
- * isPlainObject(new Uint8Array([1])); // ❌
2284
- * isPlainObject(Buffer.from('ABC')); // ❌
2285
- * isPlainObject(Promise.resolve({})); // ❌
2286
- * isPlainObject(Object.create({})); // ❌
2287
- * isPlainObject(new (class Cls {})); // ❌
2288
- * isPlainObject(globalThis); // ❌,
2289
- * ```
2290
- */
2291
- function isPlainObject(value) {
2292
- if (!value || typeof value !== "object") return false;
2293
- const proto = Object.getPrototypeOf(value);
2294
- if (!(proto === null || proto === Object.prototype || Object.getPrototypeOf(proto) === null)) return false;
2295
- return Object.prototype.toString.call(value) === "[object Object]";
2296
- }
2297
- //#endregion
2298
- //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/_internal/isEqualsSameValueZero.mjs
2299
- /**
2300
- * Performs a `SameValueZero` comparison between two values to determine if they are equivalent.
2301
- *
2302
- * @param {any} value - The value to compare.
2303
- * @param {any} other - The other value to compare.
2304
- * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2305
- *
2306
- * @example
2307
- * eq(1, 1); // true
2308
- * eq(0, -0); // true
2309
- * eq(NaN, NaN); // true
2310
- * eq('a', Object('a')); // false
2311
- */
2312
- function isEqualsSameValueZero(value, other) {
2313
- return value === other || Number.isNaN(value) && Number.isNaN(other);
2314
- }
2315
- //#endregion
2316
- //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/predicate/isEqualWith.mjs
2317
- /**
2318
- * Compares two values for equality using a custom comparison function.
2319
- *
2320
- * The custom function allows for fine-tuned control over the comparison process. If it returns a boolean, that result determines the equality. If it returns undefined, the function falls back to the default equality comparison.
2321
- *
2322
- * This function also uses the custom equality function to compare values inside objects,
2323
- * arrays, maps, sets, and other complex structures, ensuring a deep comparison.
2324
- *
2325
- * This approach provides flexibility in handling complex comparisons while maintaining efficient default behavior for simpler cases.
2326
- *
2327
- * The custom comparison function can take up to six parameters:
2328
- * - `x`: The value from the first object `a`.
2329
- * - `y`: The value from the second object `b`.
2330
- * - `property`: The property key used to get `x` and `y`.
2331
- * - `xParent`: The parent of the first value `x`.
2332
- * - `yParent`: The parent of the second value `y`.
2333
- * - `stack`: An internal stack (Map) to handle circular references.
2334
- *
2335
- * @param a - The first value to compare.
2336
- * @param b - The second value to compare.
2337
- * @param areValuesEqual - A function to customize the comparison.
2338
- * If it returns a boolean, that result will be used. If it returns undefined,
2339
- * the default equality comparison will be used.
2340
- * @returns `true` if the values are equal according to the customizer, otherwise `false`.
2341
- *
2342
- * @example
2343
- * const customizer = (a, b) => {
2344
- * if (typeof a === 'string' && typeof b === 'string') {
2345
- * return a.toLowerCase() === b.toLowerCase();
2346
- * }
2347
- * };
2348
- * isEqualWith('Hello', 'hello', customizer); // true
2349
- * isEqualWith({ a: 'Hello' }, { a: 'hello' }, customizer); // true
2350
- * isEqualWith([1, 2, 3], [1, 2, 3], customizer); // true
2351
- */
2352
- function isEqualWith(a, b, areValuesEqual) {
2353
- return isEqualWithImpl(a, b, void 0, void 0, void 0, void 0, areValuesEqual);
2354
- }
2355
- function isEqualWithImpl(a, b, property, aParent, bParent, stack, areValuesEqual) {
2356
- const result = areValuesEqual(a, b, property, aParent, bParent, stack);
2357
- if (result !== void 0) return result;
2358
- if (typeof a === typeof b) switch (typeof a) {
2359
- case "bigint":
2360
- case "string":
2361
- case "boolean":
2362
- case "symbol":
2363
- case "undefined": return a === b;
2364
- case "number": return a === b || Object.is(a, b);
2365
- case "function": return a === b;
2366
- case "object": return areObjectsEqual(a, b, stack, areValuesEqual);
2367
- }
2368
- return areObjectsEqual(a, b, stack, areValuesEqual);
2369
- }
2370
- function areObjectsEqual(a, b, stack, areValuesEqual) {
2371
- if (Object.is(a, b)) return true;
2372
- let aTag = getTag(a);
2373
- let bTag = getTag(b);
2374
- if (aTag === "[object Arguments]") aTag = objectTag;
2375
- if (bTag === "[object Arguments]") bTag = objectTag;
2376
- if (aTag !== bTag) return false;
2377
- switch (aTag) {
2378
- case stringTag: return a.toString() === b.toString();
2379
- case numberTag: return isEqualsSameValueZero(a.valueOf(), b.valueOf());
2380
- case booleanTag:
2381
- case dateTag:
2382
- case symbolTag: return Object.is(a.valueOf(), b.valueOf());
2383
- case regexpTag: return a.source === b.source && a.flags === b.flags;
2384
- case functionTag: return a === b;
2385
- }
2386
- stack = stack ?? /* @__PURE__ */ new Map();
2387
- const aStack = stack.get(a);
2388
- const bStack = stack.get(b);
2389
- if (aStack != null && bStack != null) return aStack === b;
2390
- stack.set(a, b);
2391
- stack.set(b, a);
2392
- try {
2393
- switch (aTag) {
2394
- case mapTag:
2395
- if (a.size !== b.size) return false;
2396
- for (const [key, value] of a.entries()) if (!b.has(key) || !isEqualWithImpl(value, b.get(key), key, a, b, stack, areValuesEqual)) return false;
2397
- return true;
2398
- case setTag: {
2399
- if (a.size !== b.size) return false;
2400
- const aValues = Array.from(a.values());
2401
- const bValues = Array.from(b.values());
2402
- for (let i = 0; i < aValues.length; i++) {
2403
- const aValue = aValues[i];
2404
- const index = bValues.findIndex((bValue) => {
2405
- return isEqualWithImpl(aValue, bValue, void 0, a, b, stack, areValuesEqual);
2406
- });
2407
- if (index === -1) return false;
2408
- bValues.splice(index, 1);
2409
- }
2410
- return true;
2411
- }
2412
- case arrayTag:
2413
- case uint8ArrayTag:
2414
- case uint8ClampedArrayTag:
2415
- case uint16ArrayTag:
2416
- case uint32ArrayTag:
2417
- case bigUint64ArrayTag:
2418
- case int8ArrayTag:
2419
- case int16ArrayTag:
2420
- case int32ArrayTag:
2421
- case bigInt64ArrayTag:
2422
- case float32ArrayTag:
2423
- case float64ArrayTag:
2424
- if (isBuffer(a) !== isBuffer(b)) return false;
2425
- if (a.length !== b.length) return false;
2426
- for (let i = 0; i < a.length; i++) if (!isEqualWithImpl(a[i], b[i], i, a, b, stack, areValuesEqual)) return false;
2427
- return true;
2428
- case arrayBufferTag:
2429
- if (a.byteLength !== b.byteLength) return false;
2430
- return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
2431
- case dataViewTag:
2432
- if (a.byteLength !== b.byteLength || a.byteOffset !== b.byteOffset) return false;
2433
- return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
2434
- case errorTag: return a.name === b.name && a.message === b.message;
2435
- case objectTag: {
2436
- if (!(areObjectsEqual(a.constructor, b.constructor, stack, areValuesEqual) || isPlainObject(a) && isPlainObject(b))) return false;
2437
- const aKeys = [...Object.keys(a), ...getSymbols(a)];
2438
- const bKeys = [...Object.keys(b), ...getSymbols(b)];
2439
- if (aKeys.length !== bKeys.length) return false;
2440
- for (let i = 0; i < aKeys.length; i++) {
2441
- const propKey = aKeys[i];
2442
- const aProp = a[propKey];
2443
- if (!Object.hasOwn(b, propKey)) return false;
2444
- const bProp = b[propKey];
2445
- if (!isEqualWithImpl(aProp, bProp, propKey, a, b, stack, areValuesEqual)) return false;
2446
- }
2447
- return true;
2448
- }
2449
- default: return false;
2450
- }
2451
- } finally {
2452
- stack.delete(a);
2453
- stack.delete(b);
2454
- }
2455
- }
2456
- //#endregion
2457
- //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/predicate/isEqual.mjs
2458
- /**
2459
- * Checks if two values are equal, including support for `Date`, `RegExp`, and deep object comparison.
2460
- *
2461
- * @param a - The first value to compare.
2462
- * @param b - The second value to compare.
2463
- * @returns `true` if the values are equal, otherwise `false`.
2464
- *
2465
- * @example
2466
- * isEqual(1, 1); // true
2467
- * isEqual({ a: 1 }, { a: 1 }); // true
2468
- * isEqual(/abc/g, /abc/g); // true
2469
- * isEqual(new Date('2020-01-01'), new Date('2020-01-01')); // true
2470
- * isEqual([1, 2, 3], [1, 2, 3]); // true
2471
- */
2472
- function isEqual(a, b) {
2473
- return isEqualWith(a, b, noop);
2474
- }
2475
- //#endregion
2476
50
  //#region src/react/useResponsive.ts
2477
51
  /** 屏幕响应断点 token 配置 */
2478
52
  const BREAK_POINT_TOKEN = {