jc-structure 0.2.13 → 0.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/jc-structure.js +338 -209
- package/dist/jc-structure.umd.cjs +2 -2
- package/index.d.ts +97 -6
- package/package.json +3 -5
- package/types/global.d.ts +19 -1
- package/types/linkedList.d.ts +1 -1
package/dist/jc-structure.js
CHANGED
|
@@ -1,4 +1,34 @@
|
|
|
1
|
-
class
|
|
1
|
+
class G {
|
|
2
|
+
items = [];
|
|
3
|
+
head = 0;
|
|
4
|
+
tail = 0;
|
|
5
|
+
dequeue() {
|
|
6
|
+
if (this.isEmpty()) return;
|
|
7
|
+
const t = this.items[this.head];
|
|
8
|
+
return this.head++, t;
|
|
9
|
+
}
|
|
10
|
+
enqueue(...t) {
|
|
11
|
+
for (const e of t)
|
|
12
|
+
Array.isArray(e) ? (this.items.push(...e), this.tail += e.length) : (this.items.push(e), this.tail++);
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
front() {
|
|
16
|
+
return this.isEmpty() ? void 0 : this.items[this.head];
|
|
17
|
+
}
|
|
18
|
+
isEmpty() {
|
|
19
|
+
return this.head === this.tail;
|
|
20
|
+
}
|
|
21
|
+
size() {
|
|
22
|
+
return this.tail - this.head;
|
|
23
|
+
}
|
|
24
|
+
cleanup() {
|
|
25
|
+
this.items = [], this.head = 0, this.tail = 0;
|
|
26
|
+
}
|
|
27
|
+
toString() {
|
|
28
|
+
return this.isEmpty() ? "Queue: (0) []" : `Queue: (${this.size()}) [${this.front()} ...]`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
class B {
|
|
2
32
|
items = {};
|
|
3
33
|
count = 0;
|
|
4
34
|
lowestCount = 0;
|
|
@@ -42,14 +72,43 @@ class V {
|
|
|
42
72
|
size() {
|
|
43
73
|
return this.count - this.lowestCount;
|
|
44
74
|
}
|
|
45
|
-
|
|
75
|
+
cleanup() {
|
|
46
76
|
this.items = {}, this.count = 0, this.lowestCount = 0;
|
|
47
77
|
}
|
|
48
78
|
toString() {
|
|
49
|
-
return this.isEmpty() ? "" : `Queue
|
|
79
|
+
return this.isEmpty() ? "Queue: (0) []" : `Queue: (${this.size()}) [${this.front()} ...]`;
|
|
50
80
|
}
|
|
51
81
|
}
|
|
52
|
-
class
|
|
82
|
+
class O {
|
|
83
|
+
_arr;
|
|
84
|
+
constructor() {
|
|
85
|
+
this._arr = [];
|
|
86
|
+
}
|
|
87
|
+
isEmpty() {
|
|
88
|
+
return this._arr.length === 0;
|
|
89
|
+
}
|
|
90
|
+
cleanup() {
|
|
91
|
+
this._arr = [];
|
|
92
|
+
}
|
|
93
|
+
size() {
|
|
94
|
+
return this._arr.length;
|
|
95
|
+
}
|
|
96
|
+
toString() {
|
|
97
|
+
return this.isEmpty() ? "Stack: (0) []" : `Stack: (${this.size()}) [${this.peek()}, ...]`;
|
|
98
|
+
}
|
|
99
|
+
pop() {
|
|
100
|
+
return this._arr.pop();
|
|
101
|
+
}
|
|
102
|
+
push(...t) {
|
|
103
|
+
for (const e of t)
|
|
104
|
+
Array.isArray(e) ? this._arr.push(...e) : this._arr.push(e);
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
peek() {
|
|
108
|
+
return this._arr[this._arr.length - 1];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
class _ {
|
|
53
112
|
items = {};
|
|
54
113
|
count = 0;
|
|
55
114
|
constructor() {
|
|
@@ -93,14 +152,14 @@ class F {
|
|
|
93
152
|
size() {
|
|
94
153
|
return this.count;
|
|
95
154
|
}
|
|
96
|
-
|
|
155
|
+
cleanup() {
|
|
97
156
|
this.items = {}, this.count = 0;
|
|
98
157
|
}
|
|
99
158
|
toString() {
|
|
100
|
-
return this.isEmpty() ? "" : `Stack
|
|
159
|
+
return this.isEmpty() ? "Stack: (0) []" : `Stack: (${this.size()}) [ ${this.peek()} ...]`;
|
|
101
160
|
}
|
|
102
161
|
}
|
|
103
|
-
class
|
|
162
|
+
class X {
|
|
104
163
|
stack = [];
|
|
105
164
|
minStack = [];
|
|
106
165
|
push(t) {
|
|
@@ -126,45 +185,16 @@ class _ {
|
|
|
126
185
|
this.stack = [], this.minStack = [];
|
|
127
186
|
}
|
|
128
187
|
toString() {
|
|
129
|
-
return this.isEmpty() ? "" : `
|
|
188
|
+
return this.isEmpty() ? "Stack: (0) []" : `Stack: (${this.size()}) [ ${this.peek()} ...]`;
|
|
130
189
|
}
|
|
131
190
|
}
|
|
132
|
-
|
|
133
|
-
_arr;
|
|
134
|
-
constructor() {
|
|
135
|
-
this._arr = [];
|
|
136
|
-
}
|
|
137
|
-
isEmpty() {
|
|
138
|
-
return this._arr.length === 0;
|
|
139
|
-
}
|
|
140
|
-
clear() {
|
|
141
|
-
this._arr = [];
|
|
142
|
-
}
|
|
143
|
-
size() {
|
|
144
|
-
return this._arr.length;
|
|
145
|
-
}
|
|
146
|
-
toString() {
|
|
147
|
-
return this.isEmpty() ? "Stack: (0) []" : `Stack: (${this.size()}) [${this.peek()}, ...]`;
|
|
148
|
-
}
|
|
149
|
-
pop() {
|
|
150
|
-
return this._arr.pop();
|
|
151
|
-
}
|
|
152
|
-
push(...t) {
|
|
153
|
-
for (const e of t)
|
|
154
|
-
Array.isArray(e) ? this._arr.push(...e) : this._arr.push(e);
|
|
155
|
-
return this;
|
|
156
|
-
}
|
|
157
|
-
peek() {
|
|
158
|
-
return this._arr[this._arr.length - 1];
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
function C(h, t) {
|
|
191
|
+
function T(h, t) {
|
|
162
192
|
return h === t ? 0 : h < t ? -1 : 1;
|
|
163
193
|
}
|
|
164
194
|
class E {
|
|
165
195
|
heap = [];
|
|
166
196
|
compareFn;
|
|
167
|
-
constructor(t =
|
|
197
|
+
constructor(t = T) {
|
|
168
198
|
this.compareFn = t;
|
|
169
199
|
}
|
|
170
200
|
static getLeftIndex(t) {
|
|
@@ -188,14 +218,14 @@ class E {
|
|
|
188
218
|
isEmpty() {
|
|
189
219
|
return this.size() === 0;
|
|
190
220
|
}
|
|
191
|
-
|
|
221
|
+
cleanup() {
|
|
192
222
|
this.heap = [];
|
|
193
223
|
}
|
|
194
224
|
toString() {
|
|
195
225
|
return this.heap.toString();
|
|
196
226
|
}
|
|
197
227
|
}
|
|
198
|
-
class
|
|
228
|
+
class F extends E {
|
|
199
229
|
insert(t) {
|
|
200
230
|
return t ? !1 : (this.heap.push(t), this.siftUp(this.heap.length - 1), !0);
|
|
201
231
|
}
|
|
@@ -215,15 +245,15 @@ class D extends E {
|
|
|
215
245
|
E.swap(this.heap, e, t), t = e, e = E.getParentIndex(t);
|
|
216
246
|
}
|
|
217
247
|
}
|
|
218
|
-
class
|
|
219
|
-
constructor(t = (e, s) =>
|
|
248
|
+
class j extends F {
|
|
249
|
+
constructor(t = (e, s) => T(s, e)) {
|
|
220
250
|
super(t);
|
|
221
251
|
}
|
|
222
252
|
}
|
|
223
253
|
function U(h) {
|
|
224
254
|
return { value: h };
|
|
225
255
|
}
|
|
226
|
-
class
|
|
256
|
+
class Q {
|
|
227
257
|
capacity;
|
|
228
258
|
length = 0;
|
|
229
259
|
head = null;
|
|
@@ -256,12 +286,12 @@ class B {
|
|
|
256
286
|
s ? (this.detach(s), this.prepend(s), s.value = e) : (s = U(e), this.length++, this.prepend(s), this.trimCache(), this.lookup.set(t, s), this.reverseLookup);
|
|
257
287
|
}
|
|
258
288
|
}
|
|
259
|
-
class
|
|
289
|
+
class N {
|
|
260
290
|
constructor(t, e = null, s = null) {
|
|
261
291
|
this.value = t, this.next = e, this.prev = s;
|
|
262
292
|
}
|
|
263
293
|
}
|
|
264
|
-
class
|
|
294
|
+
class W {
|
|
265
295
|
count = 0;
|
|
266
296
|
head = null;
|
|
267
297
|
tail = null;
|
|
@@ -320,7 +350,7 @@ class X {
|
|
|
320
350
|
insert(t, e) {
|
|
321
351
|
if (e < 0 || e > this.count)
|
|
322
352
|
throw new Error(`Index out of bounds: ${e}`);
|
|
323
|
-
const s = new
|
|
353
|
+
const s = new N(t);
|
|
324
354
|
if (e === 0)
|
|
325
355
|
s.next = this.head, this.head && (this.head.prev = s), this.head = s, this.count === 0 && (this.tail = s);
|
|
326
356
|
else if (e === this.count)
|
|
@@ -344,7 +374,7 @@ class X {
|
|
|
344
374
|
return this.count++, !0;
|
|
345
375
|
}
|
|
346
376
|
push(t) {
|
|
347
|
-
const e = new
|
|
377
|
+
const e = new N(t);
|
|
348
378
|
this.head ? this.tail && (this.tail.next = e, e.prev = this.tail, this.tail = e) : (this.head = e, this.tail = e), this.count++;
|
|
349
379
|
}
|
|
350
380
|
remove(t) {
|
|
@@ -390,7 +420,7 @@ class X {
|
|
|
390
420
|
size() {
|
|
391
421
|
return this.count;
|
|
392
422
|
}
|
|
393
|
-
|
|
423
|
+
cleanup() {
|
|
394
424
|
this.head = null, this.tail = null, this.count = 0;
|
|
395
425
|
}
|
|
396
426
|
toString() {
|
|
@@ -416,10 +446,10 @@ class H {
|
|
|
416
446
|
this.key = t, this.value = e;
|
|
417
447
|
}
|
|
418
448
|
}
|
|
419
|
-
function
|
|
449
|
+
function C(h, t = { emptyString: !1, zeroNumber: !1 }) {
|
|
420
450
|
return h == null ? !(t.emptyString && h === "" || t.zeroNumber && h === 0) : !1;
|
|
421
451
|
}
|
|
422
|
-
class
|
|
452
|
+
class V {
|
|
423
453
|
table = [];
|
|
424
454
|
constructor() {
|
|
425
455
|
}
|
|
@@ -430,9 +460,9 @@ class q {
|
|
|
430
460
|
return -1;
|
|
431
461
|
}
|
|
432
462
|
set(t, e) {
|
|
433
|
-
if (
|
|
463
|
+
if (C(t))
|
|
434
464
|
throw new Error("key is required");
|
|
435
|
-
if (
|
|
465
|
+
if (C(e))
|
|
436
466
|
throw new Error("value is required");
|
|
437
467
|
if (this.has(t)) {
|
|
438
468
|
let s = this.getItemIndex(t);
|
|
@@ -479,7 +509,7 @@ class q {
|
|
|
479
509
|
size() {
|
|
480
510
|
return this.table.length;
|
|
481
511
|
}
|
|
482
|
-
|
|
512
|
+
cleanup() {
|
|
483
513
|
this.table = [];
|
|
484
514
|
}
|
|
485
515
|
toString() {
|
|
@@ -489,12 +519,12 @@ class q {
|
|
|
489
519
|
return t = t.slice(0, -1), t;
|
|
490
520
|
}
|
|
491
521
|
}
|
|
492
|
-
class
|
|
522
|
+
class J {
|
|
493
523
|
isDirected;
|
|
494
524
|
vertices;
|
|
495
525
|
adjList;
|
|
496
526
|
constructor(t = !1) {
|
|
497
|
-
this.isDirected = t, this.vertices = [], this.adjList = new
|
|
527
|
+
this.isDirected = t, this.vertices = [], this.adjList = new V();
|
|
498
528
|
}
|
|
499
529
|
addVertex(t) {
|
|
500
530
|
this.vertices.includes(t) || (this.vertices.push(t), this.adjList.set(t, []));
|
|
@@ -574,10 +604,10 @@ class w {
|
|
|
574
604
|
return this.mul(-1);
|
|
575
605
|
}
|
|
576
606
|
}
|
|
577
|
-
class
|
|
607
|
+
class S {
|
|
578
608
|
_matrix;
|
|
579
609
|
static zero(t, e) {
|
|
580
|
-
return new
|
|
610
|
+
return new S(
|
|
581
611
|
Array.from({ length: t }, () => Array.from({ length: e }, () => 0))
|
|
582
612
|
);
|
|
583
613
|
}
|
|
@@ -618,7 +648,7 @@ class I {
|
|
|
618
648
|
return this._matrix[t[0]][t[1]] = e, this;
|
|
619
649
|
}
|
|
620
650
|
mul(t) {
|
|
621
|
-
return new
|
|
651
|
+
return new S(this._matrix.map((e) => e.map((s) => s * t)));
|
|
622
652
|
}
|
|
623
653
|
div(t) {
|
|
624
654
|
return this.mul(1 / t);
|
|
@@ -626,7 +656,7 @@ class I {
|
|
|
626
656
|
add(t) {
|
|
627
657
|
if (this.row !== t.row || this.col !== t.col)
|
|
628
658
|
throw new Error("Matrix dimensions do not match");
|
|
629
|
-
return new
|
|
659
|
+
return new S(
|
|
630
660
|
this._matrix.map(
|
|
631
661
|
(e, s) => e.map((r, i) => r + t.getItem([s, i]))
|
|
632
662
|
)
|
|
@@ -644,14 +674,14 @@ class I {
|
|
|
644
674
|
mulVector(t) {
|
|
645
675
|
if (this.col !== t.dimension)
|
|
646
676
|
throw new Error("Matrix dimensions do not match");
|
|
647
|
-
return new
|
|
677
|
+
return new S(
|
|
648
678
|
this._matrix.map((e) => e.map((s, r) => s * t.getItem(r)))
|
|
649
679
|
);
|
|
650
680
|
}
|
|
651
681
|
mulMatrix(t) {
|
|
652
682
|
if (this.col !== t.row)
|
|
653
683
|
throw new Error("Matrix dimensions do not match");
|
|
654
|
-
const e =
|
|
684
|
+
const e = S.zero(this.row, t.col);
|
|
655
685
|
for (let s = 0; s < this.row; s++) {
|
|
656
686
|
const r = this.rowVector(s);
|
|
657
687
|
for (let i = 0; i < this.col; i++)
|
|
@@ -672,39 +702,57 @@ class u {
|
|
|
672
702
|
distanceTo(t) {
|
|
673
703
|
return u.distance(this, t);
|
|
674
704
|
}
|
|
705
|
+
static linearInterpolation(t, e, s) {
|
|
706
|
+
if (s < 0 || s > 1)
|
|
707
|
+
throw new Error("Parameter t must be in the range [0, 1]");
|
|
708
|
+
const r = t.x * (1 - s) + e.x * s, i = t.y * (1 - s) + e.y * s;
|
|
709
|
+
return new u(r, i);
|
|
710
|
+
}
|
|
711
|
+
static quadraticBezierInterpolation(t, e, s, r) {
|
|
712
|
+
if (r < 0 || r > 1)
|
|
713
|
+
throw new Error("Parameter t must be in the range [0, 1]");
|
|
714
|
+
const i = (1 - r) * (1 - r) * t.x + 2 * (1 - r) * r * e.x + r * r * s.x, n = (1 - r) * (1 - r) * t.y + 2 * (1 - r) * r * e.y + r * r * s.y;
|
|
715
|
+
return new u(i, n);
|
|
716
|
+
}
|
|
717
|
+
static cubicBezierInterpolation(t, e, s, r, i) {
|
|
718
|
+
if (i < 0 || i > 1)
|
|
719
|
+
throw new Error("Parameter t must be in the range [0, 1]");
|
|
720
|
+
const n = Math.pow(1 - i, 3) * t.x + 3 * Math.pow(1 - i, 2) * i * e.x + 3 * (1 - i) * Math.pow(i, 2) * s.x + Math.pow(i, 3) * r.x, a = Math.pow(1 - i, 3) * t.y + 3 * Math.pow(1 - i, 2) * i * e.y + 3 * (1 - i) * Math.pow(i, 2) * s.y + Math.pow(i, 3) * r.y;
|
|
721
|
+
return new u(n, a);
|
|
722
|
+
}
|
|
675
723
|
}
|
|
676
|
-
class
|
|
724
|
+
class y {
|
|
677
725
|
static EPSILON = 1e-10;
|
|
678
|
-
static sloped(t, e =
|
|
726
|
+
static sloped(t, e = y.EPSILON) {
|
|
679
727
|
const s = t.p2.x - t.p1.x, r = t.p2.y - t.p1.y;
|
|
680
728
|
return Math.abs(s) < e ? Math.abs(r) < e ? 0 : null : r / s;
|
|
681
729
|
}
|
|
682
|
-
static isParallel(t, e, s =
|
|
683
|
-
const r =
|
|
730
|
+
static isParallel(t, e, s = y.EPSILON) {
|
|
731
|
+
const r = y.sloped(t), i = y.sloped(e);
|
|
684
732
|
return r === null && i === null ? !0 : r === null || i === null ? !1 : Math.abs(r - i) < s;
|
|
685
733
|
}
|
|
686
|
-
static getIntersection(t, e, s =
|
|
687
|
-
if (
|
|
688
|
-
const r = t.p1.x, i = t.p1.y, n = t.p2.x, a = t.p2.y,
|
|
689
|
-
if (Math.abs(
|
|
690
|
-
const m = ((r -
|
|
691
|
-
if (m >= 0 && m <= 1 &&
|
|
692
|
-
const
|
|
693
|
-
return new u(
|
|
734
|
+
static getIntersection(t, e, s = y.EPSILON) {
|
|
735
|
+
if (y.isParallel(t, e)) return null;
|
|
736
|
+
const r = t.p1.x, i = t.p1.y, n = t.p2.x, a = t.p2.y, c = e.p1.x, f = e.p1.y, l = e.p2.x, o = e.p2.y, p = (r - n) * (f - o) - (i - a) * (c - l);
|
|
737
|
+
if (Math.abs(p) < s) return null;
|
|
738
|
+
const m = ((r - c) * (f - o) - (i - f) * (c - l)) / p, x = -((r - n) * (i - f) - (i - a) * (r - c)) / p;
|
|
739
|
+
if (m >= 0 && m <= 1 && x >= 0 && x <= 1) {
|
|
740
|
+
const P = r + m * (n - r), q = i + m * (a - i);
|
|
741
|
+
return new u(P, q);
|
|
694
742
|
}
|
|
695
743
|
return null;
|
|
696
744
|
}
|
|
697
745
|
static isIntersecting(t, e) {
|
|
698
|
-
return
|
|
746
|
+
return y.getIntersection(t, e) !== null;
|
|
699
747
|
}
|
|
700
|
-
static distanceToPoint(t, e, s =
|
|
701
|
-
const r = e.x - t.p1.x, i = e.y - t.p1.y, n = t.p2.x - t.p1.x, a = t.p2.y - t.p1.y,
|
|
702
|
-
let
|
|
703
|
-
f > s && (
|
|
704
|
-
let
|
|
705
|
-
|
|
706
|
-
const m = e.x -
|
|
707
|
-
return Math.hypot(m +
|
|
748
|
+
static distanceToPoint(t, e, s = y.EPSILON) {
|
|
749
|
+
const r = e.x - t.p1.x, i = e.y - t.p1.y, n = t.p2.x - t.p1.x, a = t.p2.y - t.p1.y, c = r * n + i * a, f = n * n + a * a;
|
|
750
|
+
let l = -1;
|
|
751
|
+
f > s && (l = c / f);
|
|
752
|
+
let o, p;
|
|
753
|
+
l < 0 ? (o = t.p1.x, p = t.p1.y) : l > 1 ? (o = t.p2.x, p = t.p2.y) : (o = t.p1.x + l * n, p = t.p1.y + l * a);
|
|
754
|
+
const m = e.x - o, x = e.y - p;
|
|
755
|
+
return Math.hypot(m + x);
|
|
708
756
|
}
|
|
709
757
|
p1;
|
|
710
758
|
p2;
|
|
@@ -722,13 +770,13 @@ class g {
|
|
|
722
770
|
get angle() {
|
|
723
771
|
return Math.atan2(this.p2.y - this.p1.y, this.p2.x - this.p1.x);
|
|
724
772
|
}
|
|
725
|
-
containsPoint(t, e =
|
|
773
|
+
containsPoint(t, e = y.EPSILON) {
|
|
726
774
|
const s = (t.x - this.p1.x) * (this.p2.y - this.p1.y) - (t.y - this.p1.y) * (this.p2.x - this.p1.x);
|
|
727
775
|
return Math.abs(s) > e ? !1 : (t.x - this.p1.x) * (t.x - this.p2.x) + (t.y - this.p1.y) * (t.y - this.p2.y) <= e;
|
|
728
776
|
}
|
|
729
777
|
get direction() {
|
|
730
778
|
const t = this.length;
|
|
731
|
-
if (t <
|
|
779
|
+
if (t < y.EPSILON) return new u(0, 0);
|
|
732
780
|
const e = (this.p2.x - this.p1.x) / t, s = (this.p2.y - this.p1.y) / t;
|
|
733
781
|
return new u(e, s);
|
|
734
782
|
}
|
|
@@ -739,31 +787,31 @@ class g {
|
|
|
739
787
|
return this.p2;
|
|
740
788
|
}
|
|
741
789
|
}
|
|
742
|
-
class
|
|
790
|
+
class L {
|
|
743
791
|
static EPSILON = 1e-10;
|
|
744
792
|
name;
|
|
745
793
|
constructor(t) {
|
|
746
794
|
this.name = t;
|
|
747
795
|
}
|
|
748
796
|
}
|
|
749
|
-
class
|
|
797
|
+
class d extends L {
|
|
750
798
|
static isValid(t, e, s) {
|
|
751
799
|
return t <= 0 || e <= 0 || s <= 0 ? !1 : t + e > s && t + s > e && e + s > t;
|
|
752
800
|
}
|
|
753
801
|
static area(t, e, s) {
|
|
754
|
-
if (!
|
|
802
|
+
if (!d.isValid(t, e, s))
|
|
755
803
|
throw new Error("Invalid triangle");
|
|
756
804
|
const r = (t + e + s) / 2;
|
|
757
805
|
return Math.sqrt(r * (r - t) * (r - e) * (r - s));
|
|
758
806
|
}
|
|
759
807
|
static getType(t, e, s) {
|
|
760
|
-
if (!
|
|
808
|
+
if (!d.isValid(t, e, s))
|
|
761
809
|
throw new Error("Invalid triangle sides");
|
|
762
|
-
const r = [t, e, s].sort((
|
|
763
|
-
return Math.abs(i - n) <
|
|
810
|
+
const r = [t, e, s].sort((c, f) => c - f), [i, n, a] = r;
|
|
811
|
+
return Math.abs(i - n) < d.EPSILON && Math.abs(n - a) < d.EPSILON ? "equilateral" : Math.abs(i - n) < d.EPSILON || Math.abs(n - a) < d.EPSILON ? "isosceles" : "scalene";
|
|
764
812
|
}
|
|
765
813
|
static getAngles(t, e, s) {
|
|
766
|
-
if (!
|
|
814
|
+
if (!d.isValid(t, e, s))
|
|
767
815
|
throw new Error("Invalid triangle sides");
|
|
768
816
|
const r = Math.acos((e * e + s * s - t * t) / (2 * e * s)), i = Math.acos((t * t + s * s - e * e) / (2 * t * s)), n = Math.PI - r - i;
|
|
769
817
|
return [r, i, n];
|
|
@@ -779,7 +827,7 @@ class p extends N {
|
|
|
779
827
|
areCollinear() {
|
|
780
828
|
return Math.abs(
|
|
781
829
|
(this.p2.x - this.p1.x) * (this.p3.y - this.p1.y) - (this.p3.x - this.p1.x) * (this.p2.y - this.p1.y)
|
|
782
|
-
) <
|
|
830
|
+
) < L.EPSILON;
|
|
783
831
|
}
|
|
784
832
|
get side() {
|
|
785
833
|
return [
|
|
@@ -789,19 +837,19 @@ class p extends N {
|
|
|
789
837
|
];
|
|
790
838
|
}
|
|
791
839
|
perimeter() {
|
|
792
|
-
return
|
|
840
|
+
return d.isValid(this.side[0], this.side[1], this.side[2]), this.side.reduce((t, e) => t + e, 0);
|
|
793
841
|
}
|
|
794
842
|
area() {
|
|
795
843
|
const [t, e, s] = this.side;
|
|
796
|
-
return
|
|
844
|
+
return d.area(t, e, s);
|
|
797
845
|
}
|
|
798
846
|
get type() {
|
|
799
847
|
const [t, e, s] = this.side;
|
|
800
|
-
return
|
|
848
|
+
return d.getType(t, e, s);
|
|
801
849
|
}
|
|
802
850
|
get angles() {
|
|
803
851
|
const [t, e, s] = this.side;
|
|
804
|
-
return
|
|
852
|
+
return d.getAngles(t, e, s);
|
|
805
853
|
}
|
|
806
854
|
get centroid() {
|
|
807
855
|
return new u(
|
|
@@ -815,29 +863,29 @@ class p extends N {
|
|
|
815
863
|
}
|
|
816
864
|
get circumcenter() {
|
|
817
865
|
const t = 2 * (this.p1.x * (this.p2.y - this.p3.y) + this.p2.x * (this.p3.y - this.p1.y) + this.p3.x * (this.p1.y - this.p2.y));
|
|
818
|
-
if (Math.abs(t) <
|
|
866
|
+
if (Math.abs(t) < d.EPSILON)
|
|
819
867
|
throw new Error("Cannot calculate circumcenter for collinear points");
|
|
820
868
|
const e = ((this.p1.x * this.p1.x + this.p1.y * this.p1.y) * (this.p2.y - this.p3.y) + (this.p2.x * this.p2.x + this.p2.y * this.p2.y) * (this.p3.y - this.p1.y) + (this.p3.x * this.p3.x + this.p3.y * this.p3.y) * (this.p1.y - this.p2.y)) / t, s = ((this.p1.x * this.p1.x + this.p1.y * this.p1.y) * (this.p3.x - this.p2.x) + (this.p2.x * this.p2.x + this.p2.y * this.p2.y) * (this.p1.x - this.p3.x) + (this.p3.x * this.p3.x + this.p3.y * this.p3.y) * (this.p2.x - this.p1.x)) / t;
|
|
821
869
|
return new u(e, s);
|
|
822
870
|
}
|
|
823
871
|
containsPoint(t) {
|
|
824
|
-
const e =
|
|
872
|
+
const e = d.area(
|
|
825
873
|
u.distance(t, this.p1),
|
|
826
874
|
u.distance(t, this.p2),
|
|
827
875
|
u.distance(this.p1, this.p2)
|
|
828
|
-
), s =
|
|
876
|
+
), s = d.area(
|
|
829
877
|
u.distance(t, this.p2),
|
|
830
878
|
u.distance(t, this.p3),
|
|
831
879
|
u.distance(this.p2, this.p3)
|
|
832
|
-
), r =
|
|
880
|
+
), r = d.area(
|
|
833
881
|
u.distance(t, this.p3),
|
|
834
882
|
u.distance(t, this.p1),
|
|
835
883
|
u.distance(this.p3, this.p1)
|
|
836
884
|
);
|
|
837
|
-
return Math.abs(e + s + r - this.area()) <
|
|
885
|
+
return Math.abs(e + s + r - this.area()) < d.EPSILON;
|
|
838
886
|
}
|
|
839
887
|
}
|
|
840
|
-
class
|
|
888
|
+
class Y {
|
|
841
889
|
static sleep(t) {
|
|
842
890
|
return new Promise((e) => setTimeout(e, t));
|
|
843
891
|
}
|
|
@@ -861,7 +909,7 @@ class W {
|
|
|
861
909
|
return t.prototype.constructor = s, s;
|
|
862
910
|
}
|
|
863
911
|
}
|
|
864
|
-
class
|
|
912
|
+
class Z {
|
|
865
913
|
static groupBy(t, e) {
|
|
866
914
|
if (!e)
|
|
867
915
|
throw new Error("generateKey is required");
|
|
@@ -873,8 +921,8 @@ class Q {
|
|
|
873
921
|
console.warn("Invalid key generated for item:", n);
|
|
874
922
|
continue;
|
|
875
923
|
}
|
|
876
|
-
const
|
|
877
|
-
|
|
924
|
+
const c = r.get(a) ?? [];
|
|
925
|
+
c.push(n), r.set(a, c);
|
|
878
926
|
} catch (a) {
|
|
879
927
|
console.error("Error generating key for item:", n, a);
|
|
880
928
|
}
|
|
@@ -907,23 +955,23 @@ class Q {
|
|
|
907
955
|
return e;
|
|
908
956
|
}
|
|
909
957
|
}
|
|
910
|
-
function
|
|
958
|
+
function R(h) {
|
|
911
959
|
return h !== null && (typeof h == "object" || typeof h == "function");
|
|
912
960
|
}
|
|
913
|
-
class
|
|
961
|
+
class K {
|
|
914
962
|
map = /* @__PURE__ */ new Map();
|
|
915
963
|
weakMap = /* @__PURE__ */ new WeakMap();
|
|
916
964
|
set(t, e) {
|
|
917
|
-
|
|
965
|
+
R(t) ? this.weakMap.set(t, e) : this.map.set(t, e);
|
|
918
966
|
}
|
|
919
967
|
get(t) {
|
|
920
|
-
return
|
|
968
|
+
return R(t) ? this.weakMap.get(t) : this.map.get(t);
|
|
921
969
|
}
|
|
922
970
|
has(t) {
|
|
923
|
-
return
|
|
971
|
+
return R(t) ? this.weakMap.has(t) : this.map.has(t);
|
|
924
972
|
}
|
|
925
973
|
}
|
|
926
|
-
class
|
|
974
|
+
class tt {
|
|
927
975
|
static jsonClone(t) {
|
|
928
976
|
try {
|
|
929
977
|
return JSON.parse(JSON.stringify(t));
|
|
@@ -942,8 +990,8 @@ class Z {
|
|
|
942
990
|
if (t instanceof Map) {
|
|
943
991
|
const n = /* @__PURE__ */ new Map();
|
|
944
992
|
e.set(t, n);
|
|
945
|
-
for (const [a,
|
|
946
|
-
n.set(this.deepClone(a, e), this.deepClone(
|
|
993
|
+
for (const [a, c] of t)
|
|
994
|
+
n.set(this.deepClone(a, e), this.deepClone(c, e));
|
|
947
995
|
return n;
|
|
948
996
|
}
|
|
949
997
|
if (t instanceof Set) {
|
|
@@ -956,7 +1004,7 @@ class Z {
|
|
|
956
1004
|
if (Array.isArray(t)) {
|
|
957
1005
|
const n = new Array(t.length);
|
|
958
1006
|
e.set(t, n);
|
|
959
|
-
for (let a = 0,
|
|
1007
|
+
for (let a = 0, c = t.length; a < c; a++)
|
|
960
1008
|
n[a] = this.deepClone(t[a], e);
|
|
961
1009
|
return n;
|
|
962
1010
|
}
|
|
@@ -977,8 +1025,8 @@ class Z {
|
|
|
977
1025
|
return new n(t);
|
|
978
1026
|
if (typeof t == "function")
|
|
979
1027
|
return new Proxy(t, {
|
|
980
|
-
apply(n, a,
|
|
981
|
-
return n.apply(a,
|
|
1028
|
+
apply(n, a, c) {
|
|
1029
|
+
return n.apply(a, c);
|
|
982
1030
|
},
|
|
983
1031
|
get(n, a) {
|
|
984
1032
|
if (a in n)
|
|
@@ -993,40 +1041,40 @@ class Z {
|
|
|
993
1041
|
return r;
|
|
994
1042
|
}
|
|
995
1043
|
}
|
|
996
|
-
const
|
|
1044
|
+
const $ = {
|
|
997
1045
|
date: "yyyy-MM-dd",
|
|
998
1046
|
datetime: "yyyy-MM-dd HH:mm:ss",
|
|
999
1047
|
time: "HH:mm:ss",
|
|
1000
1048
|
iso: "yyyy-MM-ddTHH:mm:ss.SSS"
|
|
1001
1049
|
};
|
|
1002
|
-
class
|
|
1050
|
+
class v {
|
|
1003
1051
|
static defaultOptions = {
|
|
1004
1052
|
paddingZero: !1,
|
|
1005
1053
|
locale: "en-US"
|
|
1006
1054
|
};
|
|
1007
1055
|
static setDefaultOptions(t) {
|
|
1008
|
-
|
|
1056
|
+
v.defaultOptions = { ...v.defaultOptions, ...t };
|
|
1009
1057
|
}
|
|
1010
1058
|
static format(t, e, s = {}) {
|
|
1011
|
-
const r = { ...
|
|
1012
|
-
return
|
|
1059
|
+
const r = { ...v.defaultOptions, ...s }, i = v.getDateInfo(t, r);
|
|
1060
|
+
return v.normalizeFormatter(e)(i);
|
|
1013
1061
|
}
|
|
1014
1062
|
// 获取日期信息
|
|
1015
1063
|
static getDateInfo(t, e) {
|
|
1016
|
-
const s = (
|
|
1064
|
+
const s = (o, p = 2) => e.paddingZero ? o.toString().padStart(p, "0") : o.toString(), r = t.getFullYear(), i = t.getMonth() + 1, n = t.getDate(), a = t.getHours(), c = t.getMinutes(), f = t.getSeconds(), l = t.getMilliseconds();
|
|
1017
1065
|
return {
|
|
1018
1066
|
year: r,
|
|
1019
1067
|
month: i,
|
|
1020
1068
|
day: n,
|
|
1021
1069
|
hour: a,
|
|
1022
|
-
minute:
|
|
1070
|
+
minute: c,
|
|
1023
1071
|
second: f,
|
|
1024
|
-
millisecond:
|
|
1072
|
+
millisecond: l,
|
|
1025
1073
|
yyyy: s(r, 4),
|
|
1026
1074
|
MM: s(i),
|
|
1027
1075
|
dd: s(n),
|
|
1028
1076
|
HH: s(a),
|
|
1029
|
-
mm: s(
|
|
1077
|
+
mm: s(c),
|
|
1030
1078
|
ss: s(f)
|
|
1031
1079
|
};
|
|
1032
1080
|
}
|
|
@@ -1035,7 +1083,7 @@ class S {
|
|
|
1035
1083
|
return t;
|
|
1036
1084
|
if (typeof t != "string")
|
|
1037
1085
|
throw new Error("Formatter must be a string or function");
|
|
1038
|
-
t in
|
|
1086
|
+
t in $ && (t = $[t]);
|
|
1039
1087
|
const e = {
|
|
1040
1088
|
yyyy: "yyyy",
|
|
1041
1089
|
MM: "MM",
|
|
@@ -1056,11 +1104,11 @@ class S {
|
|
|
1056
1104
|
};
|
|
1057
1105
|
}
|
|
1058
1106
|
static formatRelative(t, e = /* @__PURE__ */ new Date()) {
|
|
1059
|
-
const s = t.getTime() - e.getTime(), r = Math.abs(s), i = Math.floor(r / 1e3), n = Math.floor(i / 60), a = Math.floor(n / 60),
|
|
1060
|
-
return
|
|
1107
|
+
const s = t.getTime() - e.getTime(), r = Math.abs(s), i = Math.floor(r / 1e3), n = Math.floor(i / 60), a = Math.floor(n / 60), c = Math.floor(a / 24);
|
|
1108
|
+
return c > 0 ? s > 0 ? `${c}天后` : `${c}天前` : a > 0 ? s > 0 ? `${a}小时后` : `${a}小时前` : n > 0 ? s > 0 ? `${n}分钟后` : `${n}分钟前` : s > 0 ? "刚刚" : "";
|
|
1061
1109
|
}
|
|
1062
1110
|
}
|
|
1063
|
-
class
|
|
1111
|
+
class z {
|
|
1064
1112
|
lights;
|
|
1065
1113
|
currentIndex;
|
|
1066
1114
|
switchTime;
|
|
@@ -1070,7 +1118,7 @@ class T {
|
|
|
1070
1118
|
{ color: "green", latest: 10 },
|
|
1071
1119
|
{ color: "yellow", latest: 3 }
|
|
1072
1120
|
];
|
|
1073
|
-
constructor(t =
|
|
1121
|
+
constructor(t = z.DEFAULT_LIGHTS) {
|
|
1074
1122
|
this.lights = t, this.currentIndex = 0, this.switchTime = Date.now();
|
|
1075
1123
|
}
|
|
1076
1124
|
render(t) {
|
|
@@ -1095,12 +1143,21 @@ class T {
|
|
|
1095
1143
|
};
|
|
1096
1144
|
}
|
|
1097
1145
|
}
|
|
1098
|
-
class
|
|
1146
|
+
class et {
|
|
1099
1147
|
static escape(t) {
|
|
1100
1148
|
return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1101
1149
|
}
|
|
1150
|
+
static telephone = {
|
|
1151
|
+
loose: /\D?(\d[0-9-]{6,}\d)\D?/g
|
|
1152
|
+
};
|
|
1153
|
+
static consecutiveChars = /(.)\1+/g;
|
|
1154
|
+
// 匹配连续字符
|
|
1155
|
+
static chineseChar = /[\u4e00-\u9fa5]/g;
|
|
1156
|
+
// 匹配中文字符
|
|
1157
|
+
static domain = /^(?:https?:\/\/)?(?:[^\/]+)/i;
|
|
1158
|
+
static email = /^\w+([-+.]\w+)*@\w+([-.]\w+)*.\w+([-.]\w+)*$/;
|
|
1102
1159
|
}
|
|
1103
|
-
class
|
|
1160
|
+
class st {
|
|
1104
1161
|
static ROMAN_MAP = /* @__PURE__ */ new Map([
|
|
1105
1162
|
["M", 1e3],
|
|
1106
1163
|
["CM", 900],
|
|
@@ -1129,10 +1186,10 @@ class K {
|
|
|
1129
1186
|
if (this.ROMAN_MAP.has(n))
|
|
1130
1187
|
s += this.ROMAN_MAP.get(n), r += 2;
|
|
1131
1188
|
else {
|
|
1132
|
-
const a = t[r],
|
|
1133
|
-
if (!
|
|
1189
|
+
const a = t[r], c = this.ROMAN_MAP.get(a);
|
|
1190
|
+
if (!c)
|
|
1134
1191
|
throw new Error(`Invalid Roman numeral sequence at position ${r}`);
|
|
1135
|
-
s +=
|
|
1192
|
+
s += c, r += 1;
|
|
1136
1193
|
}
|
|
1137
1194
|
}
|
|
1138
1195
|
if (this.toRoman(s) !== t)
|
|
@@ -1151,7 +1208,13 @@ class K {
|
|
|
1151
1208
|
return e;
|
|
1152
1209
|
}
|
|
1153
1210
|
}
|
|
1154
|
-
class
|
|
1211
|
+
class g {
|
|
1212
|
+
static ensurePositiveInteger(t, e = 0) {
|
|
1213
|
+
if (!Number.isInteger(t) || t <= e)
|
|
1214
|
+
throw new Error(
|
|
1215
|
+
`n must be a positive integer and greater than ${e}`
|
|
1216
|
+
);
|
|
1217
|
+
}
|
|
1155
1218
|
static handleNumRange(t, e = !1, s = Number.MIN_SAFE_INTEGER, r = Number.MAX_SAFE_INTEGER) {
|
|
1156
1219
|
if (e && !Number.isInteger(t))
|
|
1157
1220
|
throw new Error("n must be an integer");
|
|
@@ -1159,19 +1222,19 @@ class y {
|
|
|
1159
1222
|
throw new RangeError(`n must be in the range of ${s} to ${r}`);
|
|
1160
1223
|
}
|
|
1161
1224
|
static consecutiveSum(t) {
|
|
1162
|
-
return
|
|
1225
|
+
return g.handleNumRange(t, !0, 0, 1e8), t * (t + 1) / 2;
|
|
1163
1226
|
}
|
|
1164
1227
|
static consecutiveSquaresSum(t) {
|
|
1165
|
-
return
|
|
1228
|
+
return g.handleNumRange(t, !0, 0, 1e6), t * (t + 1) * (2 * t + 1) / 6;
|
|
1166
1229
|
}
|
|
1167
1230
|
static consecutivecubesSum(t) {
|
|
1168
|
-
return
|
|
1231
|
+
return g.handleNumRange(t, !0, 0, 1e4), t * (t + 1) * (2 * t + 1) * (3 * t * t + 3 * t - 1) / 30;
|
|
1169
1232
|
}
|
|
1170
1233
|
static clamp(t, e, s) {
|
|
1171
1234
|
return s == null ? Math.min(t, e) : Math.min(Math.max(t, e), s);
|
|
1172
1235
|
}
|
|
1173
1236
|
static factorial(t) {
|
|
1174
|
-
if (
|
|
1237
|
+
if (g.handleNumRange(t, !0, 0, 1e3), t < 2)
|
|
1175
1238
|
return 1;
|
|
1176
1239
|
let e = 1;
|
|
1177
1240
|
for (let s = 2; s <= t; s++)
|
|
@@ -1179,10 +1242,10 @@ class y {
|
|
|
1179
1242
|
return e;
|
|
1180
1243
|
}
|
|
1181
1244
|
static fibonacci(t, e = 1, s = 1) {
|
|
1182
|
-
return
|
|
1245
|
+
return g.handleNumRange(t, !0, 0, 1e3), t < 2 ? s : this.fibonacci(t - 1, s, s + e);
|
|
1183
1246
|
}
|
|
1184
1247
|
static fibonacciIterative(t) {
|
|
1185
|
-
if (
|
|
1248
|
+
if (g.handleNumRange(t, !0, 0, 1e3), t < 2) return t;
|
|
1186
1249
|
let e = 0, s = 1;
|
|
1187
1250
|
for (let r = 2; r <= t; r++)
|
|
1188
1251
|
[e, s] = [s, (e + s) % 1000000007];
|
|
@@ -1192,13 +1255,13 @@ class y {
|
|
|
1192
1255
|
return Math.abs(t - e) < s;
|
|
1193
1256
|
}
|
|
1194
1257
|
static fastPower(t, e) {
|
|
1195
|
-
if (
|
|
1258
|
+
if (g.handleNumRange(e, !0, 0, 10), g.handleNumRange(t, !1, 0, 1e3), t === 0) return 0;
|
|
1196
1259
|
if (e === 0) return 1;
|
|
1197
1260
|
const s = this.fastPower(t, e >> 1);
|
|
1198
1261
|
return e % 2 === 0 ? s * s : s * s * t;
|
|
1199
1262
|
}
|
|
1200
1263
|
static fastSqrt(t) {
|
|
1201
|
-
if (
|
|
1264
|
+
if (g.handleNumRange(t, !1, 0, 1e8), typeof BigInt > "u")
|
|
1202
1265
|
return Math.sqrt(t);
|
|
1203
1266
|
const e = 0.5 * t, s = new ArrayBuffer(8);
|
|
1204
1267
|
new Float64Array(s)[0] = t;
|
|
@@ -1214,19 +1277,19 @@ class y {
|
|
|
1214
1277
|
return [];
|
|
1215
1278
|
if (e < 0 || !Number.isInteger(e))
|
|
1216
1279
|
throw new Error("Precision must be a non-negative integer");
|
|
1217
|
-
const s = t.reduce((
|
|
1280
|
+
const s = t.reduce((o, p) => o + p, 0);
|
|
1218
1281
|
if (s === 0)
|
|
1219
1282
|
return t.map(() => "0%");
|
|
1220
|
-
const i = 100 * Math.pow(10, e), n = t.map((
|
|
1221
|
-
let f = a.reduce((
|
|
1222
|
-
for (;
|
|
1223
|
-
let
|
|
1224
|
-
for (let m = 0; m <
|
|
1225
|
-
|
|
1226
|
-
if (
|
|
1227
|
-
a[
|
|
1283
|
+
const i = 100 * Math.pow(10, e), n = t.map((o) => o / s * i), a = n.map((o) => Math.floor(o)), c = n.map((o, p) => o - a[p]);
|
|
1284
|
+
let f = a.reduce((o, p) => o + p, 0), l = i - f;
|
|
1285
|
+
for (; l > 0; ) {
|
|
1286
|
+
let o = -1, p = -1;
|
|
1287
|
+
for (let m = 0; m < c.length; m++)
|
|
1288
|
+
c[m] > p && (p = c[m], o = m);
|
|
1289
|
+
if (o === -1) break;
|
|
1290
|
+
a[o]++, c[o] = 0, l--;
|
|
1228
1291
|
}
|
|
1229
|
-
return a.map((
|
|
1292
|
+
return a.map((o) => `${(o / i * 100).toFixed(e)}%`);
|
|
1230
1293
|
}
|
|
1231
1294
|
static gcd(t, e) {
|
|
1232
1295
|
return e === 0 ? t : this.gcd(e, t % e);
|
|
@@ -1241,9 +1304,11 @@ class y {
|
|
|
1241
1304
|
return t % 2 === 1 || t % 2 === -1;
|
|
1242
1305
|
}
|
|
1243
1306
|
static isPrime(t) {
|
|
1244
|
-
if (t
|
|
1307
|
+
if (g.ensurePositiveInteger(t, 1), t == 2 || t == 3 || t == 5 || t == 7)
|
|
1308
|
+
return !0;
|
|
1309
|
+
if (t % 2 === 0 || t % 3 === 0 || t % 5 === 0 || t % 7 === 0)
|
|
1245
1310
|
return !1;
|
|
1246
|
-
for (let e =
|
|
1311
|
+
for (let e = 7; e <= Math.sqrt(t); e += 2)
|
|
1247
1312
|
if (t % e === 0)
|
|
1248
1313
|
return !1;
|
|
1249
1314
|
return !0;
|
|
@@ -1318,8 +1383,18 @@ class y {
|
|
|
1318
1383
|
const r = e[1] - e[0];
|
|
1319
1384
|
return (t - e[0]) * ((s[1] - s[0]) / r) + s[0];
|
|
1320
1385
|
}
|
|
1386
|
+
static getPythagoreanTriple(t) {
|
|
1387
|
+
if (t <= 0 || !Number.isInteger(t))
|
|
1388
|
+
throw new Error("n must be a positive integer");
|
|
1389
|
+
if (g.isOdd(t)) {
|
|
1390
|
+
const s = t * t;
|
|
1391
|
+
return [t, (s - 1) / 2, (s + 1) / 2];
|
|
1392
|
+
}
|
|
1393
|
+
const e = t / 2;
|
|
1394
|
+
return [t, e * e - 1, e * e + 1];
|
|
1395
|
+
}
|
|
1321
1396
|
}
|
|
1322
|
-
class
|
|
1397
|
+
class rt {
|
|
1323
1398
|
static READ = 1;
|
|
1324
1399
|
static WRITE = 2;
|
|
1325
1400
|
static SHARE = 4;
|
|
@@ -1338,7 +1413,7 @@ class tt {
|
|
|
1338
1413
|
return t ^ e;
|
|
1339
1414
|
}
|
|
1340
1415
|
}
|
|
1341
|
-
class
|
|
1416
|
+
class M {
|
|
1342
1417
|
static frequencyStatistics(t) {
|
|
1343
1418
|
return [...t].reduce(
|
|
1344
1419
|
(e, s) => (e[s] = (e[s] || 0) + 1, e),
|
|
@@ -1407,7 +1482,7 @@ class v {
|
|
|
1407
1482
|
return e;
|
|
1408
1483
|
}
|
|
1409
1484
|
static pointAt(t, e) {
|
|
1410
|
-
if (e >=
|
|
1485
|
+
if (e >= M.pointLength(t)) return;
|
|
1411
1486
|
let s = 0;
|
|
1412
1487
|
for (let r = 0, i = t.length; r < i; ) {
|
|
1413
1488
|
const n = t.codePointAt(r);
|
|
@@ -1417,10 +1492,10 @@ class v {
|
|
|
1417
1492
|
r += n > 65535 ? 2 : 1, s++;
|
|
1418
1493
|
}
|
|
1419
1494
|
}
|
|
1420
|
-
static sliceByPoint(t, e, s =
|
|
1495
|
+
static sliceByPoint(t, e, s = M.pointLength(t)) {
|
|
1421
1496
|
let r = "";
|
|
1422
1497
|
for (let i = e; i < s; i++)
|
|
1423
|
-
r +=
|
|
1498
|
+
r += M.pointAt(t, i);
|
|
1424
1499
|
return r;
|
|
1425
1500
|
}
|
|
1426
1501
|
static capitalize(t) {
|
|
@@ -1430,10 +1505,10 @@ class v {
|
|
|
1430
1505
|
return t.split("").reverse().join("");
|
|
1431
1506
|
}
|
|
1432
1507
|
static truncate(t, e, s = "...") {
|
|
1433
|
-
return t.length <= e ?
|
|
1508
|
+
return t.length <= e ? t : t.slice(0, e - s.length) + s;
|
|
1434
1509
|
}
|
|
1435
1510
|
static isPalindrome(t) {
|
|
1436
|
-
return t.toLowerCase().replace(/[^a-z0-9]/g, "") ===
|
|
1511
|
+
return t.toLowerCase().replace(/[^a-z0-9]/g, "") === M.reverse(t);
|
|
1437
1512
|
}
|
|
1438
1513
|
static count(t, e) {
|
|
1439
1514
|
const s = e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -1446,7 +1521,7 @@ class v {
|
|
|
1446
1521
|
return t.replace(/[A-Z]/g, (e) => `_${e.toLowerCase()}`);
|
|
1447
1522
|
}
|
|
1448
1523
|
}
|
|
1449
|
-
class
|
|
1524
|
+
class it {
|
|
1450
1525
|
static isValidHex(t) {
|
|
1451
1526
|
return /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t);
|
|
1452
1527
|
}
|
|
@@ -1454,7 +1529,28 @@ class et {
|
|
|
1454
1529
|
return /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.test(t);
|
|
1455
1530
|
}
|
|
1456
1531
|
}
|
|
1457
|
-
|
|
1532
|
+
class A {
|
|
1533
|
+
static basePriunt(t, e = {}) {
|
|
1534
|
+
const { title: s = "", color: r = "#909399", fontSize: i = "16px" } = e, n = s ? `background-color:${r};border:1px solid ${r};border-radius:3px 0 0 3px;padding:5px;color:#fff;font-size:${i};font-weight:bold;line-height:1.5;` : "", a = `border:1px solid ${r};color:${r};font-size:${i};padding:5px;border-radius:0 3px 3px 0;padding-right:30px;line-height:1.5;`;
|
|
1535
|
+
console.log(`%c ${s} %c ${t}`, n, a);
|
|
1536
|
+
}
|
|
1537
|
+
static success(t) {
|
|
1538
|
+
return A.basePriunt(t, { title: "success", color: "#67C23A" });
|
|
1539
|
+
}
|
|
1540
|
+
static error(t) {
|
|
1541
|
+
return A.basePriunt(t, { title: "error", color: "#F56C6C" });
|
|
1542
|
+
}
|
|
1543
|
+
static warning(t) {
|
|
1544
|
+
return A.basePriunt(t, { title: "warning", color: "#E6A23C" });
|
|
1545
|
+
}
|
|
1546
|
+
static normal(t) {
|
|
1547
|
+
return A.basePriunt(t, { title: "normal", color: "#909399" });
|
|
1548
|
+
}
|
|
1549
|
+
static primary(t) {
|
|
1550
|
+
return A.basePriunt(t, { title: "primary", color: "#409EFF" });
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
const I = {
|
|
1458
1554
|
AUTH_UNAUTHORIZED: "未授权事件",
|
|
1459
1555
|
AUTH_LOGIN_SUCCESS: "登录成功事件",
|
|
1460
1556
|
AUTH_LOGOUT: "注销事件",
|
|
@@ -1466,37 +1562,37 @@ const x = {
|
|
|
1466
1562
|
UI_HIDE_LOADING: "隐藏加载事件",
|
|
1467
1563
|
UI_SHOW_MESSAGE: "显示消息事件"
|
|
1468
1564
|
};
|
|
1469
|
-
class
|
|
1565
|
+
class b {
|
|
1470
1566
|
static instance = null;
|
|
1471
1567
|
listeners = {};
|
|
1472
1568
|
debugMode;
|
|
1473
1569
|
constructor(t = !1) {
|
|
1474
|
-
this.debugMode = t, Object.keys(
|
|
1570
|
+
this.debugMode = t, Object.keys(I).forEach(
|
|
1475
1571
|
(e) => {
|
|
1476
1572
|
this.listeners[e] = /* @__PURE__ */ new Set();
|
|
1477
1573
|
}
|
|
1478
1574
|
);
|
|
1479
1575
|
}
|
|
1480
1576
|
static getInstance(t) {
|
|
1481
|
-
return
|
|
1577
|
+
return b.instance || (b.instance = new b(t)), b.instance;
|
|
1482
1578
|
}
|
|
1483
1579
|
on(t, e) {
|
|
1484
|
-
this.debugLog(`添加事件监听: ${
|
|
1580
|
+
this.debugLog(`添加事件监听: ${I[t]}`), this.listeners[t].add(e);
|
|
1485
1581
|
}
|
|
1486
1582
|
emit(t, e) {
|
|
1487
|
-
this.debugLog(`触发事件: ${
|
|
1583
|
+
this.debugLog(`触发事件: ${I[t]}`, e), this.listeners[t].forEach((s) => {
|
|
1488
1584
|
try {
|
|
1489
1585
|
s(e);
|
|
1490
1586
|
} catch (r) {
|
|
1491
|
-
console.error(`事件 ${
|
|
1587
|
+
console.error(`事件 ${I[t]} 处理出错:`, r);
|
|
1492
1588
|
}
|
|
1493
1589
|
});
|
|
1494
1590
|
}
|
|
1495
1591
|
off(t, e) {
|
|
1496
|
-
this.debugLog(`移除事件监听: ${
|
|
1592
|
+
this.debugLog(`移除事件监听: ${I[t]}`), this.listeners[t].delete(e);
|
|
1497
1593
|
}
|
|
1498
1594
|
once(t, e) {
|
|
1499
|
-
this.debugLog(`添加一次性事件监听: ${
|
|
1595
|
+
this.debugLog(`添加一次性事件监听: ${I[t]}`);
|
|
1500
1596
|
const s = (r) => {
|
|
1501
1597
|
e(r), this.off(t, s);
|
|
1502
1598
|
};
|
|
@@ -1512,7 +1608,7 @@ class A {
|
|
|
1512
1608
|
this.debugMode && console.log(`[EventEmitter] ${t}`, e || "");
|
|
1513
1609
|
}
|
|
1514
1610
|
}
|
|
1515
|
-
class
|
|
1611
|
+
class k {
|
|
1516
1612
|
//#region private static members
|
|
1517
1613
|
static OPERATORS = /* @__PURE__ */ new Set(["+", "-", "*", "/"]);
|
|
1518
1614
|
static VALID_CHARS_REG = /^[0-9+\-*/().\s]+$/;
|
|
@@ -1576,7 +1672,7 @@ class P {
|
|
|
1576
1672
|
static EXPRESSION_REG = new RegExp("(?<!\\d)-?\\d*\\.?\\d+|[+\\-*/()]", "g");
|
|
1577
1673
|
static toArr(t) {
|
|
1578
1674
|
this.validateExpression(t);
|
|
1579
|
-
const e = t.match(
|
|
1675
|
+
const e = t.match(k.EXPRESSION_REG);
|
|
1580
1676
|
if (!e)
|
|
1581
1677
|
throw new Error("Invalid expression format");
|
|
1582
1678
|
return e.filter((s) => s.trim() !== "").map((s) => {
|
|
@@ -1588,7 +1684,7 @@ class P {
|
|
|
1588
1684
|
static infixToPostfix(t) {
|
|
1589
1685
|
if (!t?.trim())
|
|
1590
1686
|
throw new Error("Expression cannot be empty");
|
|
1591
|
-
const e = new
|
|
1687
|
+
const e = new O(), s = this.toArr(t);
|
|
1592
1688
|
console.log(s);
|
|
1593
1689
|
const r = [];
|
|
1594
1690
|
for (const i of s)
|
|
@@ -1605,8 +1701,8 @@ class P {
|
|
|
1605
1701
|
static evaluatePostfix(t) {
|
|
1606
1702
|
if (!t.length)
|
|
1607
1703
|
throw new Error("Postfix expression cannot be empty");
|
|
1608
|
-
typeof t == "string" && (t =
|
|
1609
|
-
const e = new
|
|
1704
|
+
typeof t == "string" && (t = k.toArr(t));
|
|
1705
|
+
const e = new O();
|
|
1610
1706
|
for (const s of t)
|
|
1611
1707
|
if (this.FLOAT_NUM_REG.test(s))
|
|
1612
1708
|
e.push(parseFloat(s));
|
|
@@ -1619,12 +1715,21 @@ class P {
|
|
|
1619
1715
|
return e.pop() ?? 0;
|
|
1620
1716
|
}
|
|
1621
1717
|
}
|
|
1622
|
-
class
|
|
1718
|
+
class D {
|
|
1623
1719
|
static isMatchingPair(t, e) {
|
|
1624
1720
|
return t === "(" && e === ")" || t === "{" && e === "}" || t === "[" && e === "]";
|
|
1625
1721
|
}
|
|
1722
|
+
static arr_2d_init(t, e, s = !1) {
|
|
1723
|
+
return typeof s == "boolean" ? Array.from(
|
|
1724
|
+
{ length: t },
|
|
1725
|
+
() => Array(e).fill(s)
|
|
1726
|
+
) : Array.from(
|
|
1727
|
+
{ length: t },
|
|
1728
|
+
() => Array(e).fill(s)
|
|
1729
|
+
);
|
|
1730
|
+
}
|
|
1626
1731
|
static isvalidBrackets(t) {
|
|
1627
|
-
const e = new
|
|
1732
|
+
const e = new O();
|
|
1628
1733
|
for (let s = 0, r = t.length; s < r; s++) {
|
|
1629
1734
|
const i = t[s];
|
|
1630
1735
|
if (["{", "[", "("].includes(i))
|
|
@@ -1639,36 +1744,60 @@ class st {
|
|
|
1639
1744
|
}
|
|
1640
1745
|
return e.isEmpty();
|
|
1641
1746
|
}
|
|
1747
|
+
static findPath(t, e, s) {
|
|
1748
|
+
const r = t.length, i = t[0].length, n = D.arr_2d_init(r, i, !1), a = new O(), c = [
|
|
1749
|
+
[-1, 0],
|
|
1750
|
+
[0, 1],
|
|
1751
|
+
[1, 0],
|
|
1752
|
+
[0, -1]
|
|
1753
|
+
];
|
|
1754
|
+
function f(l, o) {
|
|
1755
|
+
if (l < 0 || l >= r || o < 0 || o >= i || t[l][o] === 1 || n[l][o])
|
|
1756
|
+
return !1;
|
|
1757
|
+
if (t[l][o] === 2)
|
|
1758
|
+
return a.push([l, o]), !0;
|
|
1759
|
+
n[l][o] = !0, a.push([l, o]);
|
|
1760
|
+
for (const [p, m] of c) {
|
|
1761
|
+
const x = l + p, P = o + m;
|
|
1762
|
+
if (f(x, P))
|
|
1763
|
+
return !0;
|
|
1764
|
+
}
|
|
1765
|
+
return a.pop(), !1;
|
|
1766
|
+
}
|
|
1767
|
+
return f(e, s), a;
|
|
1768
|
+
}
|
|
1642
1769
|
}
|
|
1643
1770
|
export {
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1771
|
+
Z as Arr,
|
|
1772
|
+
G as ArrQueue,
|
|
1773
|
+
O as ArrStack,
|
|
1774
|
+
rt as BitPerm,
|
|
1775
|
+
it as Color,
|
|
1776
|
+
v as DateEx,
|
|
1777
|
+
V as Dictionary,
|
|
1778
|
+
b as Emitter,
|
|
1779
|
+
k as Expression,
|
|
1780
|
+
Y as Func,
|
|
1781
|
+
J as Graph,
|
|
1782
|
+
Q as LRU,
|
|
1783
|
+
y as Line,
|
|
1784
|
+
W as LinkedList,
|
|
1785
|
+
A as Log,
|
|
1786
|
+
S as Matrix,
|
|
1787
|
+
j as MaxHeap,
|
|
1788
|
+
K as MemoizeMap,
|
|
1789
|
+
F as MinHeap,
|
|
1790
|
+
X as MinStack,
|
|
1791
|
+
g as Num,
|
|
1792
|
+
tt as Obj,
|
|
1793
|
+
B as ObjQueue,
|
|
1794
|
+
_ as ObjStack,
|
|
1664
1795
|
u as Point,
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
T as TrafficLight,
|
|
1672
|
-
p as Triangle,
|
|
1796
|
+
et as Reg,
|
|
1797
|
+
st as Roman,
|
|
1798
|
+
D as StackApplication,
|
|
1799
|
+
M as Str,
|
|
1800
|
+
z as TrafficLight,
|
|
1801
|
+
d as Triangle,
|
|
1673
1802
|
w as Vector
|
|
1674
1803
|
};
|