jc-structure 0.1.18 → 0.1.21
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 +541 -389
- package/dist/jc-structure.umd.cjs +2 -2
- package/index.d.ts +283 -53
- package/package.json +1 -1
- package/types/global.d.ts +41 -0
- package/types/extend.d.ts +0 -57
package/dist/jc-structure.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class H {
|
|
2
2
|
items = {};
|
|
3
3
|
count = 0;
|
|
4
4
|
lowestCount = 0;
|
|
@@ -49,7 +49,7 @@ class V {
|
|
|
49
49
|
return this.isEmpty() ? "" : `Queue(size: ${this.size()}):[${this.items[this.lowestCount]},...rest]`;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
class
|
|
52
|
+
class D {
|
|
53
53
|
items = {};
|
|
54
54
|
count = 0;
|
|
55
55
|
constructor() {
|
|
@@ -100,7 +100,7 @@ class z {
|
|
|
100
100
|
return this.isEmpty() ? "" : `Stack(count: ${this.count}):[${this.items[this.count - 1]},...rest]`;
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
-
class
|
|
103
|
+
class U {
|
|
104
104
|
stack = [];
|
|
105
105
|
minStack = [];
|
|
106
106
|
push(t) {
|
|
@@ -129,13 +129,13 @@ class D {
|
|
|
129
129
|
return this.isEmpty() ? "" : `MinStack(count: ${this.size()}):[${this.getMin()},...rest]`;
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
function
|
|
133
|
-
return
|
|
132
|
+
function k(h, t) {
|
|
133
|
+
return h === t ? 0 : h < t ? -1 : 1;
|
|
134
134
|
}
|
|
135
|
-
class
|
|
135
|
+
class E {
|
|
136
136
|
heap = [];
|
|
137
137
|
compareFn;
|
|
138
|
-
constructor(t =
|
|
138
|
+
constructor(t = k) {
|
|
139
139
|
this.compareFn = t;
|
|
140
140
|
}
|
|
141
141
|
static getLeftIndex(t) {
|
|
@@ -166,7 +166,7 @@ class y {
|
|
|
166
166
|
return this.heap.toString();
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
|
-
class
|
|
169
|
+
class L extends E {
|
|
170
170
|
insert(t) {
|
|
171
171
|
return t ? !1 : (this.heap.push(t), this.siftUp(this.heap.length - 1), !0);
|
|
172
172
|
}
|
|
@@ -177,24 +177,24 @@ class O extends y {
|
|
|
177
177
|
return this.heap[0] = this.heap.pop(), this.siftDown(0), t;
|
|
178
178
|
}
|
|
179
179
|
siftUp(t) {
|
|
180
|
-
let e = t, s =
|
|
181
|
-
s <
|
|
180
|
+
let e = t, s = E.getLeftIndex(e), r = E.getRightIndex(e), i = this.size();
|
|
181
|
+
s < i && this.compareFn(this.heap[e], this.heap[s]) === -1 && (e = s), r < i && this.compareFn(this.heap[e], this.heap[r]) === 1 && (e = r), e !== t && (E.swap(this.heap, t, e), this.siftUp(e));
|
|
182
182
|
}
|
|
183
183
|
siftDown(t) {
|
|
184
|
-
let e =
|
|
184
|
+
let e = E.getParentIndex(t);
|
|
185
185
|
for (; t > 0 && e && this.compareFn(this.heap[e], this.heap[t]) === 1; )
|
|
186
|
-
|
|
186
|
+
E.swap(this.heap, e, t), t = e, e = E.getParentIndex(t);
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
|
-
class q extends
|
|
190
|
-
constructor(t = (e, s) =>
|
|
189
|
+
class q extends L {
|
|
190
|
+
constructor(t = (e, s) => k(s, e)) {
|
|
191
191
|
super(t);
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
|
-
function
|
|
195
|
-
return { value:
|
|
194
|
+
function z(h) {
|
|
195
|
+
return { value: h };
|
|
196
196
|
}
|
|
197
|
-
class
|
|
197
|
+
class F {
|
|
198
198
|
capacity;
|
|
199
199
|
length = 0;
|
|
200
200
|
head = null;
|
|
@@ -224,31 +224,31 @@ class j {
|
|
|
224
224
|
}
|
|
225
225
|
update(t, e) {
|
|
226
226
|
let s = this.lookup.get(t);
|
|
227
|
-
s ? (this.detach(s), this.prepend(s), s.value = e) : (s =
|
|
227
|
+
s ? (this.detach(s), this.prepend(s), s.value = e) : (s = z(e), this.length++, this.prepend(s), this.trimCache(), this.lookup.set(t, s), this.reverseLookup);
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
|
-
class
|
|
230
|
+
class O {
|
|
231
231
|
value;
|
|
232
232
|
next = void 0;
|
|
233
233
|
}
|
|
234
|
-
class
|
|
234
|
+
class T {
|
|
235
235
|
count = 0;
|
|
236
236
|
head = void 0;
|
|
237
237
|
constructor() {
|
|
238
238
|
}
|
|
239
239
|
indexOf(t) {
|
|
240
|
-
let e = this.head, s = 0,
|
|
240
|
+
let e = this.head, s = 0, r = !1;
|
|
241
241
|
for (; e; ) {
|
|
242
242
|
if (this.equals(e.value, t)) {
|
|
243
|
-
|
|
243
|
+
r = !0;
|
|
244
244
|
break;
|
|
245
245
|
}
|
|
246
246
|
s++, e = e.next;
|
|
247
247
|
}
|
|
248
|
-
return
|
|
248
|
+
return r ? s : -1;
|
|
249
249
|
}
|
|
250
250
|
equals(t, e) {
|
|
251
|
-
return !1;
|
|
251
|
+
return t === e ? !0 : t == null || e == null ? !1 : typeof t == "object" && typeof e == "object" ? JSON.stringify(t) === JSON.stringify(e) : !1;
|
|
252
252
|
}
|
|
253
253
|
getElementAt(t) {
|
|
254
254
|
if (t < 0 || t >= this.count)
|
|
@@ -264,19 +264,19 @@ class U {
|
|
|
264
264
|
return this.getElementAt(t)?.value;
|
|
265
265
|
}
|
|
266
266
|
insert(t, e) {
|
|
267
|
-
let s = new
|
|
267
|
+
let s = new O();
|
|
268
268
|
if (s.value = t, e > this.count || e < 0)
|
|
269
269
|
throw new Error("index error");
|
|
270
270
|
this.count++;
|
|
271
|
-
let
|
|
271
|
+
let r, i;
|
|
272
272
|
if (e === 0) {
|
|
273
273
|
s.next = this.head, this.head = s;
|
|
274
274
|
return;
|
|
275
275
|
}
|
|
276
|
-
|
|
276
|
+
r = this.getElementAt(e - 1), i = r.next, r.next = s, s.next = i;
|
|
277
277
|
}
|
|
278
278
|
push(t) {
|
|
279
|
-
let e = new
|
|
279
|
+
let e = new O();
|
|
280
280
|
if (e.value = t, this.count++, this.isEmpty()) {
|
|
281
281
|
this.head = e;
|
|
282
282
|
return;
|
|
@@ -291,8 +291,8 @@ class U {
|
|
|
291
291
|
removeAt(t) {
|
|
292
292
|
if (this.isEmpty() || t < 0 || t >= this.count)
|
|
293
293
|
return;
|
|
294
|
-
let e = this.getElementAt(t), s = this.getElementAt(t - 1),
|
|
295
|
-
return t === 0 && (this.head =
|
|
294
|
+
let e = this.getElementAt(t), s = this.getElementAt(t - 1), r = e?.next;
|
|
295
|
+
return t === 0 && (this.head = r), s && (s.next = r), this.count--, e?.value;
|
|
296
296
|
}
|
|
297
297
|
isEmpty() {
|
|
298
298
|
return this.count === 0;
|
|
@@ -310,17 +310,17 @@ class U {
|
|
|
310
310
|
return t = t.slice(0, -1), t;
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
|
-
class
|
|
313
|
+
class $ {
|
|
314
314
|
key;
|
|
315
315
|
value;
|
|
316
316
|
constructor(t, e) {
|
|
317
317
|
this.key = t, this.value = e;
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
|
-
function
|
|
321
|
-
return
|
|
320
|
+
function b(h, t = { emptyString: !1, zeroNumber: !1 }) {
|
|
321
|
+
return h == null ? !(t.emptyString && h === "" || t.zeroNumber && h === 0) : !1;
|
|
322
322
|
}
|
|
323
|
-
class
|
|
323
|
+
class V {
|
|
324
324
|
table = [];
|
|
325
325
|
constructor() {
|
|
326
326
|
}
|
|
@@ -331,15 +331,15 @@ class R {
|
|
|
331
331
|
return -1;
|
|
332
332
|
}
|
|
333
333
|
set(t, e) {
|
|
334
|
-
if (
|
|
334
|
+
if (b(t))
|
|
335
335
|
throw new Error("key is required");
|
|
336
|
-
if (
|
|
336
|
+
if (b(e))
|
|
337
337
|
throw new Error("value is required");
|
|
338
338
|
if (this.has(t)) {
|
|
339
339
|
let s = this.getItemIndex(t);
|
|
340
340
|
this.table[s].value = e;
|
|
341
341
|
} else {
|
|
342
|
-
const s = new
|
|
342
|
+
const s = new $(t, e);
|
|
343
343
|
this.table.push(s);
|
|
344
344
|
}
|
|
345
345
|
}
|
|
@@ -369,8 +369,8 @@ class R {
|
|
|
369
369
|
}
|
|
370
370
|
forEach(t) {
|
|
371
371
|
for (let e = 0, s = this.size(); e < s; e++) {
|
|
372
|
-
let
|
|
373
|
-
if (!t(
|
|
372
|
+
let r = this.table[e];
|
|
373
|
+
if (!t(r.key, r.value))
|
|
374
374
|
break;
|
|
375
375
|
}
|
|
376
376
|
}
|
|
@@ -390,12 +390,12 @@ class R {
|
|
|
390
390
|
return t = t.slice(0, -1), t;
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
|
-
class
|
|
393
|
+
class B {
|
|
394
394
|
isDirected;
|
|
395
395
|
vertices;
|
|
396
396
|
adjList;
|
|
397
397
|
constructor(t = !1) {
|
|
398
|
-
this.isDirected = t, this.vertices = [], this.adjList = new
|
|
398
|
+
this.isDirected = t, this.vertices = [], this.adjList = new V();
|
|
399
399
|
}
|
|
400
400
|
addVertex(t) {
|
|
401
401
|
this.vertices.includes(t) || (this.vertices.push(t), this.adjList.set(t, []));
|
|
@@ -445,7 +445,7 @@ class w {
|
|
|
445
445
|
if (this.dimension !== t.dimension)
|
|
446
446
|
throw new Error("Vectors must have the same dimension to add");
|
|
447
447
|
const e = this._data.map(
|
|
448
|
-
(s,
|
|
448
|
+
(s, r) => s + t._data[r]
|
|
449
449
|
);
|
|
450
450
|
return new w(...e);
|
|
451
451
|
}
|
|
@@ -453,7 +453,7 @@ class w {
|
|
|
453
453
|
if (this.dimension !== t.dimension)
|
|
454
454
|
throw new Error("Vectors must have the same dimension to subtract");
|
|
455
455
|
const e = this._data.map(
|
|
456
|
-
(s,
|
|
456
|
+
(s, r) => s - t._data[r]
|
|
457
457
|
);
|
|
458
458
|
return new w(...e);
|
|
459
459
|
}
|
|
@@ -464,7 +464,7 @@ class w {
|
|
|
464
464
|
if (this.dimension !== t.dimension)
|
|
465
465
|
throw new Error("Vectors must have the same dimension to dot product");
|
|
466
466
|
return this._data.reduce(
|
|
467
|
-
(e, s,
|
|
467
|
+
(e, s, r) => e + s * t._data[r],
|
|
468
468
|
0
|
|
469
469
|
);
|
|
470
470
|
}
|
|
@@ -475,19 +475,19 @@ class w {
|
|
|
475
475
|
return this.mul(-1);
|
|
476
476
|
}
|
|
477
477
|
}
|
|
478
|
-
class
|
|
478
|
+
class I {
|
|
479
479
|
_matrix;
|
|
480
480
|
static zero(t, e) {
|
|
481
|
-
return new
|
|
481
|
+
return new I(
|
|
482
482
|
Array.from({ length: t }, () => Array.from({ length: e }, () => 0))
|
|
483
483
|
);
|
|
484
484
|
}
|
|
485
485
|
static rotate(t) {
|
|
486
486
|
const e = t.length;
|
|
487
487
|
for (let s = 0; s < (e + 1) / 2; s++)
|
|
488
|
-
for (let
|
|
489
|
-
const
|
|
490
|
-
t[e - 1 -
|
|
488
|
+
for (let r = s; r < e / 2; r++) {
|
|
489
|
+
const i = t[e - 1 - r][s];
|
|
490
|
+
t[e - 1 - r][s] = t[e - 1 - s][e - 1 - r], t[e - 1 - s][e - 1 - r] = t[r][e - 1 - s], t[r][e - 1 - s] = t[s][r], t[s][r] = i;
|
|
491
491
|
}
|
|
492
492
|
return t;
|
|
493
493
|
}
|
|
@@ -519,7 +519,7 @@ class x {
|
|
|
519
519
|
return this._matrix[t[0]][t[1]] = e, this;
|
|
520
520
|
}
|
|
521
521
|
mul(t) {
|
|
522
|
-
return new
|
|
522
|
+
return new I(this._matrix.map((e) => e.map((s) => s * t)));
|
|
523
523
|
}
|
|
524
524
|
div(t) {
|
|
525
525
|
return this.mul(1 / t);
|
|
@@ -527,9 +527,9 @@ class x {
|
|
|
527
527
|
add(t) {
|
|
528
528
|
if (this.row !== t.row || this.col !== t.col)
|
|
529
529
|
throw new Error("Matrix dimensions do not match");
|
|
530
|
-
return new
|
|
530
|
+
return new I(
|
|
531
531
|
this._matrix.map(
|
|
532
|
-
(e, s) => e.map((
|
|
532
|
+
(e, s) => e.map((r, i) => r + t.getItem([s, i]))
|
|
533
533
|
)
|
|
534
534
|
);
|
|
535
535
|
}
|
|
@@ -545,18 +545,18 @@ class x {
|
|
|
545
545
|
mulVector(t) {
|
|
546
546
|
if (this.col !== t.dimension)
|
|
547
547
|
throw new Error("Matrix dimensions do not match");
|
|
548
|
-
return new
|
|
549
|
-
this._matrix.map((e) => e.map((s,
|
|
548
|
+
return new I(
|
|
549
|
+
this._matrix.map((e) => e.map((s, r) => s * t.getItem(r)))
|
|
550
550
|
);
|
|
551
551
|
}
|
|
552
552
|
mulMatrix(t) {
|
|
553
553
|
if (this.col !== t.row)
|
|
554
554
|
throw new Error("Matrix dimensions do not match");
|
|
555
|
-
const e =
|
|
555
|
+
const e = I.zero(this.row, t.col);
|
|
556
556
|
for (let s = 0; s < this.row; s++) {
|
|
557
|
-
const
|
|
558
|
-
for (let
|
|
559
|
-
e.setItem([s,
|
|
557
|
+
const r = this.rowVector(s);
|
|
558
|
+
for (let i = 0; i < this.col; i++)
|
|
559
|
+
e.setItem([s, i], r.dot(t.colVector(i)));
|
|
560
560
|
}
|
|
561
561
|
return e;
|
|
562
562
|
}
|
|
@@ -575,24 +575,23 @@ class u {
|
|
|
575
575
|
}
|
|
576
576
|
}
|
|
577
577
|
class g {
|
|
578
|
-
// 使用更合适的精度阈值常量
|
|
579
578
|
static EPSILON = 1e-10;
|
|
580
579
|
static sloped(t, e = g.EPSILON) {
|
|
581
|
-
const s = t.p2.x - t.p1.x,
|
|
582
|
-
return Math.abs(s) < e ? Math.abs(
|
|
580
|
+
const s = t.p2.x - t.p1.x, r = t.p2.y - t.p1.y;
|
|
581
|
+
return Math.abs(s) < e ? Math.abs(r) < e ? 0 : null : r / s;
|
|
583
582
|
}
|
|
584
583
|
static isParallel(t, e, s = g.EPSILON) {
|
|
585
|
-
const
|
|
586
|
-
return
|
|
584
|
+
const r = g.sloped(t), i = g.sloped(e);
|
|
585
|
+
return r === null && i === null ? !0 : r === null || i === null ? !1 : Math.abs(r - i) < s;
|
|
587
586
|
}
|
|
588
587
|
static getIntersection(t, e, s = g.EPSILON) {
|
|
589
588
|
if (g.isParallel(t, e)) return null;
|
|
590
|
-
const
|
|
589
|
+
const r = t.p1.x, i = t.p1.y, n = t.p2.x, a = t.p2.y, o = e.p1.x, d = e.p1.y, f = e.p2.x, c = e.p2.y, l = (r - n) * (d - c) - (i - a) * (o - f);
|
|
591
590
|
if (Math.abs(l) < s) return null;
|
|
592
|
-
const
|
|
593
|
-
if (
|
|
594
|
-
const
|
|
595
|
-
return new u(
|
|
591
|
+
const m = ((r - o) * (d - c) - (i - d) * (o - f)) / l, A = -((r - n) * (i - d) - (i - a) * (r - o)) / l;
|
|
592
|
+
if (m >= 0 && m <= 1 && A >= 0 && A <= 1) {
|
|
593
|
+
const N = r + m * (n - r), C = i + m * (a - i);
|
|
594
|
+
return new u(N, C);
|
|
596
595
|
}
|
|
597
596
|
return null;
|
|
598
597
|
}
|
|
@@ -600,13 +599,13 @@ class g {
|
|
|
600
599
|
return g.getIntersection(t, e) !== null;
|
|
601
600
|
}
|
|
602
601
|
static distanceToPoint(t, e, s = g.EPSILON) {
|
|
603
|
-
const
|
|
604
|
-
let
|
|
605
|
-
|
|
606
|
-
let
|
|
607
|
-
|
|
608
|
-
const
|
|
609
|
-
return Math.hypot(
|
|
602
|
+
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, o = r * n + i * a, d = n * n + a * a;
|
|
603
|
+
let f = -1;
|
|
604
|
+
d > s && (f = o / d);
|
|
605
|
+
let c, l;
|
|
606
|
+
f < 0 ? (c = t.p1.x, l = t.p1.y) : f > 1 ? (c = t.p2.x, l = t.p2.y) : (c = t.p1.x + f * n, l = t.p1.y + f * a);
|
|
607
|
+
const m = e.x - c, A = e.y - l;
|
|
608
|
+
return Math.hypot(m + A);
|
|
610
609
|
}
|
|
611
610
|
p1;
|
|
612
611
|
p2;
|
|
@@ -628,7 +627,6 @@ class g {
|
|
|
628
627
|
const s = (t.x - this.p1.x) * (this.p2.y - this.p1.y) - (t.y - this.p1.y) * (this.p2.x - this.p1.x);
|
|
629
628
|
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;
|
|
630
629
|
}
|
|
631
|
-
// 获取线段的方向向量
|
|
632
630
|
get direction() {
|
|
633
631
|
const t = this.length;
|
|
634
632
|
if (t < g.EPSILON) return new u(0, 0);
|
|
@@ -642,47 +640,47 @@ class g {
|
|
|
642
640
|
return this.p2;
|
|
643
641
|
}
|
|
644
642
|
}
|
|
645
|
-
class
|
|
643
|
+
class R {
|
|
646
644
|
static EPSILON = 1e-10;
|
|
647
645
|
name;
|
|
648
646
|
constructor(t) {
|
|
649
647
|
this.name = t;
|
|
650
648
|
}
|
|
651
649
|
}
|
|
652
|
-
class p extends
|
|
650
|
+
class p extends R {
|
|
653
651
|
static isValid(t, e, s) {
|
|
654
652
|
return t <= 0 || e <= 0 || s <= 0 ? !1 : t + e > s && t + s > e && e + s > t;
|
|
655
653
|
}
|
|
656
654
|
static area(t, e, s) {
|
|
657
655
|
if (!p.isValid(t, e, s))
|
|
658
656
|
throw new Error("Invalid triangle");
|
|
659
|
-
const
|
|
660
|
-
return Math.sqrt(
|
|
657
|
+
const r = (t + e + s) / 2;
|
|
658
|
+
return Math.sqrt(r * (r - t) * (r - e) * (r - s));
|
|
661
659
|
}
|
|
662
660
|
static getType(t, e, s) {
|
|
663
661
|
if (!p.isValid(t, e, s))
|
|
664
662
|
throw new Error("Invalid triangle sides");
|
|
665
|
-
const
|
|
666
|
-
return Math.abs(
|
|
663
|
+
const r = [t, e, s].sort((o, d) => o - d), [i, n, a] = r;
|
|
664
|
+
return Math.abs(i - n) < p.EPSILON && Math.abs(n - a) < p.EPSILON ? "equilateral" : Math.abs(i - n) < p.EPSILON || Math.abs(n - a) < p.EPSILON ? "isosceles" : "scalene";
|
|
667
665
|
}
|
|
668
666
|
static getAngles(t, e, s) {
|
|
669
667
|
if (!p.isValid(t, e, s))
|
|
670
668
|
throw new Error("Invalid triangle sides");
|
|
671
|
-
const
|
|
672
|
-
return [i, n
|
|
669
|
+
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;
|
|
670
|
+
return [r, i, n];
|
|
673
671
|
}
|
|
674
672
|
p1;
|
|
675
673
|
p2;
|
|
676
674
|
p3;
|
|
677
|
-
constructor(t, e, s,
|
|
678
|
-
if (super(
|
|
675
|
+
constructor(t, e, s, r = "triangle") {
|
|
676
|
+
if (super(r), this.p1 = t, this.p2 = e, this.p3 = s, this.areCollinear())
|
|
679
677
|
throw new Error("Points are collinear, cannot form a triangle");
|
|
680
678
|
}
|
|
681
679
|
// 检查三点是否共线
|
|
682
680
|
areCollinear() {
|
|
683
681
|
return Math.abs(
|
|
684
682
|
(this.p2.x - this.p1.x) * (this.p3.y - this.p1.y) - (this.p3.x - this.p1.x) * (this.p2.y - this.p1.y)
|
|
685
|
-
) <
|
|
683
|
+
) < R.EPSILON;
|
|
686
684
|
}
|
|
687
685
|
get side() {
|
|
688
686
|
return [
|
|
@@ -713,8 +711,8 @@ class p extends A {
|
|
|
713
711
|
);
|
|
714
712
|
}
|
|
715
713
|
get incenter() {
|
|
716
|
-
const [t, e, s] = this.side,
|
|
717
|
-
return new u(
|
|
714
|
+
const [t, e, s] = this.side, r = this.perimeter() / 2, i = (t * this.p1.x + e * this.p2.x + s * this.p3.x) / r, n = (t * this.p1.y + e * this.p2.y + s * this.p3.y) / r;
|
|
715
|
+
return new u(i, n);
|
|
718
716
|
}
|
|
719
717
|
get circumcenter() {
|
|
720
718
|
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));
|
|
@@ -732,65 +730,243 @@ class p extends A {
|
|
|
732
730
|
u.distance(t, this.p2),
|
|
733
731
|
u.distance(t, this.p3),
|
|
734
732
|
u.distance(this.p2, this.p3)
|
|
735
|
-
),
|
|
733
|
+
), r = p.area(
|
|
736
734
|
u.distance(t, this.p3),
|
|
737
735
|
u.distance(t, this.p1),
|
|
738
736
|
u.distance(this.p3, this.p1)
|
|
739
737
|
);
|
|
740
|
-
return Math.abs(e + s +
|
|
738
|
+
return Math.abs(e + s + r - this.area()) < p.EPSILON;
|
|
741
739
|
}
|
|
742
740
|
}
|
|
743
|
-
|
|
744
|
-
|
|
741
|
+
class G {
|
|
742
|
+
static sleep(t) {
|
|
743
|
+
return new Promise((e) => setTimeout(e, t));
|
|
744
|
+
}
|
|
745
|
+
static binarySearchTemplate(t, e, s) {
|
|
746
|
+
let r = -1, i = t.length, n;
|
|
747
|
+
for (; i - r > 1; )
|
|
748
|
+
n = i - (i - r) >> 1, s(t[n], e) ? i = n : r = n;
|
|
749
|
+
return i;
|
|
750
|
+
}
|
|
751
|
+
static singleton(t) {
|
|
752
|
+
let e;
|
|
753
|
+
const s = new Proxy(t, {
|
|
754
|
+
construct(r, i, n) {
|
|
755
|
+
return e || (e = Reflect.construct(
|
|
756
|
+
r,
|
|
757
|
+
i,
|
|
758
|
+
n
|
|
759
|
+
)), e;
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
return t.prototype.constructor = s, s;
|
|
763
|
+
}
|
|
745
764
|
}
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
"
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
765
|
+
class _ {
|
|
766
|
+
static groupBy(t, e) {
|
|
767
|
+
if (!e)
|
|
768
|
+
throw new Error("generateKey is required");
|
|
769
|
+
const s = typeof e == "string" ? (i) => i[e] : e, r = /* @__PURE__ */ new Map();
|
|
770
|
+
for (const [i, n] of t.entries())
|
|
771
|
+
try {
|
|
772
|
+
const a = s(n, i, t);
|
|
773
|
+
if (a == null) {
|
|
774
|
+
console.warn("Invalid key generated for item:", n);
|
|
775
|
+
continue;
|
|
776
|
+
}
|
|
777
|
+
const o = r.get(a) ?? [];
|
|
778
|
+
o.push(n), r.set(a, o);
|
|
779
|
+
} catch (a) {
|
|
780
|
+
console.error("Error generating key for item:", n, a);
|
|
781
|
+
}
|
|
782
|
+
return Object.fromEntries(r);
|
|
783
|
+
}
|
|
784
|
+
static LIS(t) {
|
|
785
|
+
if (!t.length) return [];
|
|
786
|
+
const e = [[t[0]]];
|
|
787
|
+
for (let r = 1, i = t.length; r < i; r++) {
|
|
788
|
+
const n = t[r];
|
|
789
|
+
s(n);
|
|
790
|
+
}
|
|
791
|
+
function s(r) {
|
|
792
|
+
for (let i = e.length - 1; i >= 0; i--) {
|
|
793
|
+
const n = e[i], a = n[e[i].length - 1];
|
|
794
|
+
if (a < r) {
|
|
795
|
+
e[i + 1] = [...n, r];
|
|
796
|
+
break;
|
|
797
|
+
} else a > r && i === 0 && (e[i] = [r]);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
return e[e.length - 1];
|
|
801
|
+
}
|
|
802
|
+
static LCP(t) {
|
|
803
|
+
if (!t.length) return "";
|
|
804
|
+
let e = t[0];
|
|
805
|
+
for (let s = 1; s < t.length; s++)
|
|
806
|
+
for (; !t[s].startsWith(e); )
|
|
807
|
+
if (e = e.slice(0, -1), e === "") return "";
|
|
808
|
+
return e;
|
|
809
|
+
}
|
|
758
810
|
}
|
|
759
|
-
function
|
|
760
|
-
return
|
|
811
|
+
function v(h) {
|
|
812
|
+
return h !== null && (typeof h == "object" || typeof h == "function");
|
|
761
813
|
}
|
|
762
|
-
class
|
|
814
|
+
class W {
|
|
763
815
|
map = /* @__PURE__ */ new Map();
|
|
764
816
|
weakMap = /* @__PURE__ */ new WeakMap();
|
|
765
817
|
set(t, e) {
|
|
766
|
-
|
|
818
|
+
v(t) ? this.weakMap.set(t, e) : this.map.set(t, e);
|
|
767
819
|
}
|
|
768
820
|
get(t) {
|
|
769
|
-
return
|
|
821
|
+
return v(t) ? this.weakMap.get(t) : this.map.get(t);
|
|
770
822
|
}
|
|
771
823
|
has(t) {
|
|
772
|
-
return
|
|
824
|
+
return v(t) ? this.weakMap.has(t) : this.map.has(t);
|
|
773
825
|
}
|
|
774
826
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
827
|
+
class X {
|
|
828
|
+
static jsonClone(t) {
|
|
829
|
+
try {
|
|
830
|
+
return JSON.parse(JSON.stringify(t));
|
|
831
|
+
} catch {
|
|
832
|
+
throw new Error("Object is not JSON cloneable");
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
static structureClone(t) {
|
|
836
|
+
return structuredClone(t);
|
|
837
|
+
}
|
|
838
|
+
static deepClone(t, e = /* @__PURE__ */ new WeakMap()) {
|
|
839
|
+
if (t == null || typeof t != "object") return t;
|
|
840
|
+
if (e.has(t)) return e.get(t);
|
|
841
|
+
if (t instanceof Date) return new Date(t.getTime());
|
|
842
|
+
if (t instanceof RegExp) return new RegExp(t.source, t.flags);
|
|
843
|
+
if (t instanceof Map) {
|
|
844
|
+
const n = /* @__PURE__ */ new Map();
|
|
845
|
+
e.set(t, n);
|
|
846
|
+
for (const [a, o] of t)
|
|
847
|
+
n.set(this.deepClone(a, e), this.deepClone(o, e));
|
|
848
|
+
return n;
|
|
789
849
|
}
|
|
850
|
+
if (t instanceof Set) {
|
|
851
|
+
const n = /* @__PURE__ */ new Set();
|
|
852
|
+
e.set(t, n);
|
|
853
|
+
for (const a of t)
|
|
854
|
+
n.add(this.deepClone(a, e));
|
|
855
|
+
return n;
|
|
856
|
+
}
|
|
857
|
+
if (Array.isArray(t)) {
|
|
858
|
+
const n = new Array(t.length);
|
|
859
|
+
e.set(t, n);
|
|
860
|
+
for (let a = 0, o = t.length; a < o; a++)
|
|
861
|
+
n[a] = this.deepClone(t[a], e);
|
|
862
|
+
return n;
|
|
863
|
+
}
|
|
864
|
+
if (t instanceof ArrayBuffer) return t.slice(0);
|
|
865
|
+
const s = [
|
|
866
|
+
Int8Array,
|
|
867
|
+
Uint8Array,
|
|
868
|
+
Uint8ClampedArray,
|
|
869
|
+
Int16Array,
|
|
870
|
+
Uint16Array,
|
|
871
|
+
Int32Array,
|
|
872
|
+
Uint32Array,
|
|
873
|
+
Float32Array,
|
|
874
|
+
Float64Array
|
|
875
|
+
];
|
|
876
|
+
for (const n of s)
|
|
877
|
+
if (t instanceof n)
|
|
878
|
+
return new n(t);
|
|
879
|
+
if (typeof t == "function")
|
|
880
|
+
return new Proxy(t, {
|
|
881
|
+
apply(n, a, o) {
|
|
882
|
+
return n.apply(a, o);
|
|
883
|
+
},
|
|
884
|
+
get(n, a) {
|
|
885
|
+
if (a in n)
|
|
886
|
+
return n[a];
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
const r = Object.create(Object.getPrototypeOf(t));
|
|
890
|
+
e.set(t, r);
|
|
891
|
+
const i = Object.getOwnPropertyDescriptors(t);
|
|
892
|
+
for (const [n, a] of Object.entries(i))
|
|
893
|
+
a.value !== void 0 && (a.value = this.deepClone(a.value, e)), Object.defineProperty(r, n, a);
|
|
894
|
+
return r;
|
|
790
895
|
}
|
|
791
|
-
return t[t.length - 1];
|
|
792
896
|
}
|
|
793
|
-
|
|
897
|
+
const P = {
|
|
898
|
+
date: "yyyy-MM-dd",
|
|
899
|
+
datetime: "yyyy-MM-dd HH:mm:ss",
|
|
900
|
+
time: "HH:mm:ss",
|
|
901
|
+
iso: "yyyy-MM-ddTHH:mm:ss.SSS"
|
|
902
|
+
};
|
|
903
|
+
class S {
|
|
904
|
+
static defaultOptions = {
|
|
905
|
+
paddingZero: !1,
|
|
906
|
+
locale: "en-US"
|
|
907
|
+
};
|
|
908
|
+
static setDefaultOptions(t) {
|
|
909
|
+
S.defaultOptions = { ...S.defaultOptions, ...t };
|
|
910
|
+
}
|
|
911
|
+
static format(t, e, s = {}) {
|
|
912
|
+
const r = { ...S.defaultOptions, ...s }, i = S.getDateInfo(t, r);
|
|
913
|
+
return S.normalizeFormatter(e)(i);
|
|
914
|
+
}
|
|
915
|
+
// 获取日期信息
|
|
916
|
+
static getDateInfo(t, e) {
|
|
917
|
+
const s = (c, l = 2) => e.paddingZero ? c.toString().padStart(l, "0") : c.toString(), r = t.getFullYear(), i = t.getMonth() + 1, n = t.getDate(), a = t.getHours(), o = t.getMinutes(), d = t.getSeconds(), f = t.getMilliseconds();
|
|
918
|
+
return {
|
|
919
|
+
year: r,
|
|
920
|
+
month: i,
|
|
921
|
+
day: n,
|
|
922
|
+
hour: a,
|
|
923
|
+
minute: o,
|
|
924
|
+
second: d,
|
|
925
|
+
millisecond: f,
|
|
926
|
+
yyyy: s(r, 4),
|
|
927
|
+
MM: s(i),
|
|
928
|
+
dd: s(n),
|
|
929
|
+
HH: s(a),
|
|
930
|
+
mm: s(o),
|
|
931
|
+
ss: s(d)
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
static normalizeFormatter(t) {
|
|
935
|
+
if (typeof t == "function")
|
|
936
|
+
return t;
|
|
937
|
+
if (typeof t != "string")
|
|
938
|
+
throw new Error("Formatter must be a string or function");
|
|
939
|
+
t in P && (t = P[t]);
|
|
940
|
+
const e = {
|
|
941
|
+
yyyy: "yyyy",
|
|
942
|
+
MM: "MM",
|
|
943
|
+
dd: "dd",
|
|
944
|
+
HH: "HH",
|
|
945
|
+
mm: "mm",
|
|
946
|
+
ss: "ss",
|
|
947
|
+
SSS: "SSS"
|
|
948
|
+
};
|
|
949
|
+
return (s) => {
|
|
950
|
+
let r = t;
|
|
951
|
+
for (const [i, n] of Object.entries(e))
|
|
952
|
+
r = r.replace(
|
|
953
|
+
new RegExp(i, "g"),
|
|
954
|
+
String(s[n] || "")
|
|
955
|
+
);
|
|
956
|
+
return r;
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
static formatRelative(t, e = /* @__PURE__ */ new Date()) {
|
|
960
|
+
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), o = Math.floor(a / 24);
|
|
961
|
+
return o > 0 ? s > 0 ? `${o}天后` : `${o}天前` : a > 0 ? s > 0 ? `${a}小时后` : `${a}小时前` : n > 0 ? s > 0 ? `${n}分钟后` : `${n}分钟前` : s > 0 ? "刚刚" : "";
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
class Q {
|
|
965
|
+
static escape(t) {
|
|
966
|
+
return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
class j {
|
|
794
970
|
static ROMAN_MAP = /* @__PURE__ */ new Map([
|
|
795
971
|
["M", 1e3],
|
|
796
972
|
["CM", 900],
|
|
@@ -810,19 +986,19 @@ class B {
|
|
|
810
986
|
if (t.length === 0)
|
|
811
987
|
throw new Error("Input cannot be empty");
|
|
812
988
|
const e = /* @__PURE__ */ new Set(["I", "V", "X", "L", "C", "D", "M"]);
|
|
813
|
-
for (const
|
|
814
|
-
if (!e.has(
|
|
815
|
-
throw new Error(`Invalid Roman numeral character: ${
|
|
816
|
-
let s = 0,
|
|
817
|
-
for (;
|
|
818
|
-
const
|
|
819
|
-
if (this.ROMAN_MAP.has(
|
|
820
|
-
s += this.ROMAN_MAP.get(
|
|
989
|
+
for (const n of t)
|
|
990
|
+
if (!e.has(n))
|
|
991
|
+
throw new Error(`Invalid Roman numeral character: ${n}`);
|
|
992
|
+
let s = 0, r = 0;
|
|
993
|
+
for (; r < t.length; ) {
|
|
994
|
+
const n = t.slice(r, r + 2);
|
|
995
|
+
if (this.ROMAN_MAP.has(n))
|
|
996
|
+
s += this.ROMAN_MAP.get(n), r += 2;
|
|
821
997
|
else {
|
|
822
|
-
const
|
|
823
|
-
if (!
|
|
824
|
-
throw new Error(`Invalid Roman numeral sequence at position ${
|
|
825
|
-
s +=
|
|
998
|
+
const a = t[r], o = this.ROMAN_MAP.get(a);
|
|
999
|
+
if (!o)
|
|
1000
|
+
throw new Error(`Invalid Roman numeral sequence at position ${r}`);
|
|
1001
|
+
s += o, r += 1;
|
|
826
1002
|
}
|
|
827
1003
|
}
|
|
828
1004
|
if (this.toRoman(s) !== t)
|
|
@@ -835,26 +1011,33 @@ class B {
|
|
|
835
1011
|
if (!Number.isInteger(t))
|
|
836
1012
|
throw new Error("Number must be an integer");
|
|
837
1013
|
let e = "";
|
|
838
|
-
for (const [s,
|
|
839
|
-
for (; t >=
|
|
840
|
-
e += s, t -=
|
|
1014
|
+
for (const [s, r] of this.ROMAN_MAP)
|
|
1015
|
+
for (; t >= r; )
|
|
1016
|
+
e += s, t -= r;
|
|
841
1017
|
return e;
|
|
842
1018
|
}
|
|
843
1019
|
}
|
|
844
|
-
class
|
|
845
|
-
static
|
|
846
|
-
|
|
1020
|
+
class y extends Number {
|
|
1021
|
+
static handleNumRange(t, e = !1, s = Number.MIN_SAFE_INTEGER, r = Number.MAX_SAFE_INTEGER) {
|
|
1022
|
+
if (e && !Number.isInteger(t))
|
|
1023
|
+
throw new Error("n must be an integer");
|
|
1024
|
+
if (t < s || t >= r)
|
|
1025
|
+
throw new RangeError(`n must be in the range of ${s} to ${r}`);
|
|
847
1026
|
}
|
|
848
|
-
static
|
|
849
|
-
return t
|
|
1027
|
+
static consecutiveSum(t) {
|
|
1028
|
+
return y.handleNumRange(t, !0, 0, 1e8), t * (t + 1) / 2;
|
|
850
1029
|
}
|
|
851
|
-
static
|
|
852
|
-
return t
|
|
1030
|
+
static consecutiveSquaresSum(t) {
|
|
1031
|
+
return y.handleNumRange(t, !0, 0, 1e6), t * (t + 1) * (2 * t + 1) / 6;
|
|
1032
|
+
}
|
|
1033
|
+
static consecutivecubesSum(t) {
|
|
1034
|
+
return y.handleNumRange(t, !0, 0, 1e4), t * (t + 1) * (2 * t + 1) * (3 * t * t + 3 * t - 1) / 30;
|
|
1035
|
+
}
|
|
1036
|
+
static clamp(t, e, s) {
|
|
1037
|
+
return s == null ? Math.min(t, e) : Math.min(Math.max(t, e), s);
|
|
853
1038
|
}
|
|
854
1039
|
static factorial(t) {
|
|
855
|
-
if (
|
|
856
|
-
throw new Error("Input must be a non-negative integer");
|
|
857
|
-
if (t < 2)
|
|
1040
|
+
if (y.handleNumRange(t, !0, 0, 1e3), t < 2)
|
|
858
1041
|
return 1;
|
|
859
1042
|
let e = 1;
|
|
860
1043
|
for (let s = 2; s <= t; s++)
|
|
@@ -862,50 +1045,66 @@ class G {
|
|
|
862
1045
|
return e;
|
|
863
1046
|
}
|
|
864
1047
|
static fibonacci(t, e = 1, s = 1) {
|
|
865
|
-
|
|
866
|
-
throw new Error("Input must be a non-negative integer");
|
|
867
|
-
return t < 2 ? s : this.fibonacci(t - 1, s, s + e);
|
|
1048
|
+
return y.handleNumRange(t, !0, 0, 1e3), t < 2 ? s : this.fibonacci(t - 1, s, s + e);
|
|
868
1049
|
}
|
|
869
1050
|
static fibonacciIterative(t) {
|
|
870
|
-
if (t < 2) return t;
|
|
1051
|
+
if (y.handleNumRange(t, !0, 0, 1e3), t < 2) return t;
|
|
871
1052
|
let e = 0, s = 1;
|
|
872
|
-
for (let
|
|
1053
|
+
for (let r = 2; r <= t; r++)
|
|
873
1054
|
[e, s] = [s, (e + s) % 1000000007];
|
|
874
1055
|
return s;
|
|
875
1056
|
}
|
|
1057
|
+
static floatEqual(t, e, s = 1e-6) {
|
|
1058
|
+
return Math.abs(t - e) < s;
|
|
1059
|
+
}
|
|
1060
|
+
static fastPower(t, e) {
|
|
1061
|
+
if (y.handleNumRange(e, !0, 0, 10), y.handleNumRange(t, !1, 0, 1e3), t === 0) return 0;
|
|
1062
|
+
if (e === 0) return 1;
|
|
1063
|
+
const s = this.fastPower(t, e >> 1);
|
|
1064
|
+
return e % 2 === 0 ? s * s : s * s * t;
|
|
1065
|
+
}
|
|
1066
|
+
static fastSqrt(t) {
|
|
1067
|
+
if (y.handleNumRange(t, !1, 0, 1e8), typeof BigInt > "u")
|
|
1068
|
+
return Math.sqrt(t);
|
|
1069
|
+
const e = 0.5 * t, s = new ArrayBuffer(8);
|
|
1070
|
+
new Float64Array(s)[0] = t;
|
|
1071
|
+
let r = new BigInt64Array(s)[0];
|
|
1072
|
+
r = 0x1ff7a3bea91d9b1bn + (r >> 1n);
|
|
1073
|
+
const i = new ArrayBuffer(8);
|
|
1074
|
+
new BigInt64Array(i)[0] = r;
|
|
1075
|
+
let n = new Float64Array(i)[0];
|
|
1076
|
+
return n = n * 0.5 + e / n, n = n * 0.5 + e / n, n = n * 0.5 + e / n, n;
|
|
1077
|
+
}
|
|
876
1078
|
static getPercentWithPrecision(t, e = 2) {
|
|
877
1079
|
if (!Array.isArray(t) || t.length === 0)
|
|
878
1080
|
return [];
|
|
879
1081
|
if (e < 0 || !Number.isInteger(e))
|
|
880
1082
|
throw new Error("Precision must be a non-negative integer");
|
|
881
|
-
const s = t.reduce((
|
|
1083
|
+
const s = t.reduce((c, l) => c + l, 0);
|
|
882
1084
|
if (s === 0)
|
|
883
1085
|
return t.map(() => "0%");
|
|
884
|
-
const
|
|
885
|
-
let
|
|
886
|
-
for (;
|
|
887
|
-
let
|
|
888
|
-
for (let
|
|
889
|
-
|
|
890
|
-
if (
|
|
891
|
-
|
|
1086
|
+
const i = 100 * Math.pow(10, e), n = t.map((c) => c / s * i), a = n.map((c) => Math.floor(c)), o = n.map((c, l) => c - a[l]);
|
|
1087
|
+
let d = a.reduce((c, l) => c + l, 0), f = i - d;
|
|
1088
|
+
for (; f > 0; ) {
|
|
1089
|
+
let c = -1, l = -1;
|
|
1090
|
+
for (let m = 0; m < o.length; m++)
|
|
1091
|
+
o[m] > l && (l = o[m], c = m);
|
|
1092
|
+
if (c === -1) break;
|
|
1093
|
+
a[c]++, o[c] = 0, f--;
|
|
892
1094
|
}
|
|
893
|
-
return
|
|
894
|
-
}
|
|
895
|
-
static fastSqrt(t) {
|
|
896
|
-
if (t < 0)
|
|
897
|
-
throw new Error("n must be a non-negative number");
|
|
898
|
-
const e = 0.5 * t;
|
|
899
|
-
let s = new BigInt64Array(new Float32Array([t]).buffer)[0];
|
|
900
|
-
s = 0x1ff7a3bea91d9b1bn + (s >> 1n);
|
|
901
|
-
let i = new Float64Array(new BigInt64Array([s]).buffer)[0];
|
|
902
|
-
return i = i * 0.5 + e / i, i = i * 0.5 + e / i, i = i * 0.5 + e / i, i;
|
|
1095
|
+
return a.map((c) => `${(c / i * 100).toFixed(e)}%`);
|
|
903
1096
|
}
|
|
904
1097
|
static gcd(t, e) {
|
|
905
1098
|
return e === 0 ? t : this.gcd(e, t % e);
|
|
906
1099
|
}
|
|
907
|
-
static
|
|
908
|
-
return t
|
|
1100
|
+
static isValidPositiveInteger(t) {
|
|
1101
|
+
return Number.isInteger(t) && t > 0 && t <= Number.MAX_SAFE_INTEGER;
|
|
1102
|
+
}
|
|
1103
|
+
static isPowerOfTwo(t) {
|
|
1104
|
+
return t > 0 && (t & t - 1) === 0;
|
|
1105
|
+
}
|
|
1106
|
+
static isOdd(t) {
|
|
1107
|
+
return t % 2 === 1 || t % 2 === -1;
|
|
909
1108
|
}
|
|
910
1109
|
static isPrime(t) {
|
|
911
1110
|
if (t <= 1)
|
|
@@ -920,23 +1119,23 @@ class G {
|
|
|
920
1119
|
return !1;
|
|
921
1120
|
let e = 0, s = t;
|
|
922
1121
|
for (; t > 0; ) {
|
|
923
|
-
const
|
|
924
|
-
e = e * 10 +
|
|
1122
|
+
const r = t % 10;
|
|
1123
|
+
e = e * 10 + r, t = Math.floor(t / 10);
|
|
925
1124
|
}
|
|
926
1125
|
return s === e;
|
|
927
1126
|
}
|
|
928
1127
|
static isArmstrong(t) {
|
|
929
1128
|
const e = t.toString(), s = e.length;
|
|
930
|
-
let
|
|
931
|
-
for (let
|
|
932
|
-
|
|
933
|
-
return
|
|
1129
|
+
let r = 0;
|
|
1130
|
+
for (let i = 0; i < s; i++)
|
|
1131
|
+
r += Math.pow(parseInt(e[i]), s);
|
|
1132
|
+
return r === t;
|
|
934
1133
|
}
|
|
935
1134
|
static isHappy(t) {
|
|
936
1135
|
const e = /* @__PURE__ */ new Set();
|
|
937
1136
|
for (; t !== 1; ) {
|
|
938
1137
|
if (e.has(t)) return !1;
|
|
939
|
-
e.add(t), t = (t + "").split("").reduce((s,
|
|
1138
|
+
e.add(t), t = (t + "").split("").reduce((s, r) => s + Number(r) * Number(r), 0);
|
|
940
1139
|
}
|
|
941
1140
|
return !0;
|
|
942
1141
|
}
|
|
@@ -946,15 +1145,8 @@ class G {
|
|
|
946
1145
|
t % s === 0 && (e += s);
|
|
947
1146
|
return e === t;
|
|
948
1147
|
}
|
|
949
|
-
static
|
|
950
|
-
return
|
|
951
|
-
}
|
|
952
|
-
static scale(t, e, s) {
|
|
953
|
-
if (e[0] >= e[1] || s[0] >= s[1])
|
|
954
|
-
throw new Error("Invalid range");
|
|
955
|
-
t = this.clamp(t, e[0], e[1]);
|
|
956
|
-
const i = e[1] - e[0];
|
|
957
|
-
return (t - e[0]) * ((s[1] - s[0]) / i) + s[0];
|
|
1148
|
+
static isSameSign(t, e) {
|
|
1149
|
+
return t >= 0 && e >= 0 || t <= 0 && e <= 0;
|
|
958
1150
|
}
|
|
959
1151
|
static isRange(t, e, s) {
|
|
960
1152
|
if (s == null && (s = e, e = 0), e >= s)
|
|
@@ -963,8 +1155,11 @@ class G {
|
|
|
963
1155
|
);
|
|
964
1156
|
return e <= t && t < s;
|
|
965
1157
|
}
|
|
966
|
-
static
|
|
967
|
-
return
|
|
1158
|
+
static lcm(t, e) {
|
|
1159
|
+
return t * e / this.gcd(t, e);
|
|
1160
|
+
}
|
|
1161
|
+
static middle(t, e) {
|
|
1162
|
+
return e - (e - t >> 1);
|
|
968
1163
|
}
|
|
969
1164
|
static random(t, e) {
|
|
970
1165
|
if (e == null && (e = t, t = 0), t >= e)
|
|
@@ -982,39 +1177,15 @@ class G {
|
|
|
982
1177
|
const s = Math.pow(10, e);
|
|
983
1178
|
return Math.round(t * s) / s;
|
|
984
1179
|
}
|
|
985
|
-
static
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
static fastPower(t, e) {
|
|
992
|
-
if (t < 0)
|
|
993
|
-
throw new Error("a must be greater than 0");
|
|
994
|
-
if (e < 0 || !Number.isInteger(e))
|
|
995
|
-
throw new Error("n must be a non-negative integer");
|
|
996
|
-
if (t === 0) return 0;
|
|
997
|
-
if (e === 0) return 1;
|
|
998
|
-
const s = this.fastPower(t, e >> 1);
|
|
999
|
-
return e % 2 === 0 ? s * s : s * s * t;
|
|
1000
|
-
}
|
|
1001
|
-
static consecutiveSum(t) {
|
|
1002
|
-
if (!this.isValidPositiveInteger)
|
|
1003
|
-
throw new Error("n must be a positive integer");
|
|
1004
|
-
return t * (t + 1) / 2;
|
|
1005
|
-
}
|
|
1006
|
-
static consecutiveSquaresSum(t) {
|
|
1007
|
-
if (!this.isValidPositiveInteger)
|
|
1008
|
-
throw new Error("n must be a positive integer");
|
|
1009
|
-
return t * (t + 1) * (2 * t + 1) / 6;
|
|
1010
|
-
}
|
|
1011
|
-
static consecutivecubesSum(t) {
|
|
1012
|
-
if (!this.isValidPositiveInteger)
|
|
1013
|
-
throw new Error("n must be a positive integer");
|
|
1014
|
-
return t * (t + 1) * (2 * t + 1) * (3 * t * t + 3 * t - 1) / 30;
|
|
1180
|
+
static scale(t, e, s) {
|
|
1181
|
+
if (e[0] >= e[1] || s[0] >= s[1])
|
|
1182
|
+
throw new Error("Invalid range");
|
|
1183
|
+
t = this.clamp(t, e[0], e[1]);
|
|
1184
|
+
const r = e[1] - e[0];
|
|
1185
|
+
return (t - e[0]) * ((s[1] - s[0]) / r) + s[0];
|
|
1015
1186
|
}
|
|
1016
1187
|
}
|
|
1017
|
-
class
|
|
1188
|
+
class J {
|
|
1018
1189
|
static READ = 1;
|
|
1019
1190
|
static WRITE = 2;
|
|
1020
1191
|
static SHARE = 4;
|
|
@@ -1033,23 +1204,118 @@ class W {
|
|
|
1033
1204
|
return t ^ e;
|
|
1034
1205
|
}
|
|
1035
1206
|
}
|
|
1036
|
-
class
|
|
1037
|
-
static
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
if (e = e.slice(0, -1), e === "") return "";
|
|
1043
|
-
return e;
|
|
1207
|
+
class Z extends String {
|
|
1208
|
+
static frequencyStatistics(t) {
|
|
1209
|
+
return [...t].reduce(
|
|
1210
|
+
(e, s) => (e[s] = (e[s] || 0) + 1, e),
|
|
1211
|
+
{}
|
|
1212
|
+
);
|
|
1044
1213
|
}
|
|
1045
|
-
static
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1214
|
+
static isValidBracket(t) {
|
|
1215
|
+
const e = [], s = {
|
|
1216
|
+
"(": ")",
|
|
1217
|
+
"[": "]",
|
|
1218
|
+
"{": "}"
|
|
1219
|
+
}, r = new Set(Object.values(s));
|
|
1220
|
+
for (const i of t)
|
|
1221
|
+
if (i in s)
|
|
1222
|
+
e.push(s[i]);
|
|
1223
|
+
else if (r.has(i) && i !== e.pop())
|
|
1224
|
+
return !1;
|
|
1225
|
+
return e.length === 0;
|
|
1226
|
+
}
|
|
1227
|
+
static random(t = 8) {
|
|
1228
|
+
const e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
1229
|
+
let s = "";
|
|
1230
|
+
for (let r = 0; r < t; r++)
|
|
1231
|
+
s += e.charAt(Math.floor(Math.random() * e.length));
|
|
1232
|
+
return s;
|
|
1233
|
+
}
|
|
1234
|
+
static template(t, e) {
|
|
1235
|
+
return t.replace(/\${(\w+)}/g, (s, r) => e[r] || "");
|
|
1236
|
+
}
|
|
1237
|
+
static escapeHtml(t) {
|
|
1238
|
+
const e = {
|
|
1239
|
+
"&": "&",
|
|
1240
|
+
"<": "<",
|
|
1241
|
+
">": ">",
|
|
1242
|
+
'"': """,
|
|
1243
|
+
"'": "'",
|
|
1244
|
+
" ": " ",
|
|
1245
|
+
"±": "±",
|
|
1246
|
+
"×": "×",
|
|
1247
|
+
"÷": "÷",
|
|
1248
|
+
"≠": "≠",
|
|
1249
|
+
"≤": "≤",
|
|
1250
|
+
"≥": "≥"
|
|
1251
|
+
}, s = new RegExp(
|
|
1252
|
+
`[${Object.keys(e).join("")}]`,
|
|
1253
|
+
"g"
|
|
1254
|
+
);
|
|
1255
|
+
return t.replace(s, (r) => e[r]);
|
|
1256
|
+
}
|
|
1257
|
+
static isEmail(t) {
|
|
1258
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t);
|
|
1259
|
+
}
|
|
1260
|
+
static isUrl(t) {
|
|
1261
|
+
try {
|
|
1262
|
+
return new URL(t), !0;
|
|
1263
|
+
} catch {
|
|
1264
|
+
return !1;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
constructor(t) {
|
|
1268
|
+
super(t);
|
|
1269
|
+
}
|
|
1270
|
+
pointLength() {
|
|
1271
|
+
let t = 0;
|
|
1272
|
+
for (let e = 0, s = this.length; e < s; ) {
|
|
1273
|
+
const r = this.codePointAt(e);
|
|
1274
|
+
e += r > 65535 ? 2 : 1, t++;
|
|
1275
|
+
}
|
|
1276
|
+
return t;
|
|
1277
|
+
}
|
|
1278
|
+
pointAt(t) {
|
|
1279
|
+
if (t >= this.pointLength()) return;
|
|
1280
|
+
let e = 0;
|
|
1281
|
+
for (let s = 0, r = this.length; s < r; ) {
|
|
1282
|
+
const i = this.codePointAt(s);
|
|
1283
|
+
if (!i) return;
|
|
1284
|
+
if (e === t)
|
|
1285
|
+
return String.fromCodePoint(i);
|
|
1286
|
+
s += i > 65535 ? 2 : 1, e++;
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
sliceByPoint(t, e = this.pointLength()) {
|
|
1290
|
+
let s = "";
|
|
1291
|
+
for (let r = t; r < e; r++)
|
|
1292
|
+
s += this.pointAt(r);
|
|
1293
|
+
return s;
|
|
1294
|
+
}
|
|
1295
|
+
capitalize() {
|
|
1296
|
+
return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase();
|
|
1297
|
+
}
|
|
1298
|
+
reverse() {
|
|
1299
|
+
return this.split("").reverse().join("");
|
|
1300
|
+
}
|
|
1301
|
+
truncate(t, e = "...") {
|
|
1302
|
+
return this.length <= t ? this : this.slice(0, t - e.length) + e;
|
|
1303
|
+
}
|
|
1304
|
+
isPalindrome() {
|
|
1305
|
+
return this.toLowerCase().replace(/[^a-z0-9]/g, "") === this.reverse();
|
|
1306
|
+
}
|
|
1307
|
+
count(t) {
|
|
1308
|
+
const e = t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1309
|
+
return (this.match(new RegExp(e, "g")) || []).length;
|
|
1310
|
+
}
|
|
1311
|
+
toCamelCase() {
|
|
1312
|
+
return this.replace(/_([a-z])/g, (t, e) => e.toUpperCase());
|
|
1313
|
+
}
|
|
1314
|
+
toSnakeCase() {
|
|
1315
|
+
return this.replace(/[A-Z]/g, (t) => `_${t.toLowerCase()}`);
|
|
1050
1316
|
}
|
|
1051
1317
|
}
|
|
1052
|
-
class
|
|
1318
|
+
class Y {
|
|
1053
1319
|
static isValidHex(t) {
|
|
1054
1320
|
return /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t);
|
|
1055
1321
|
}
|
|
@@ -1057,20 +1323,7 @@ class Q {
|
|
|
1057
1323
|
return /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.test(t);
|
|
1058
1324
|
}
|
|
1059
1325
|
}
|
|
1060
|
-
|
|
1061
|
-
let t;
|
|
1062
|
-
const e = new Proxy(r, {
|
|
1063
|
-
construct(s, i, n) {
|
|
1064
|
-
return t || (t = Reflect.construct(
|
|
1065
|
-
s,
|
|
1066
|
-
i,
|
|
1067
|
-
n
|
|
1068
|
-
)), t;
|
|
1069
|
-
}
|
|
1070
|
-
});
|
|
1071
|
-
return r.prototype.constructor = e, e;
|
|
1072
|
-
}
|
|
1073
|
-
const E = {
|
|
1326
|
+
const x = {
|
|
1074
1327
|
AUTH_UNAUTHORIZED: "未授权事件",
|
|
1075
1328
|
AUTH_LOGIN_SUCCESS: "登录成功事件",
|
|
1076
1329
|
AUTH_LOGOUT: "注销事件",
|
|
@@ -1082,72 +1335,45 @@ const E = {
|
|
|
1082
1335
|
UI_HIDE_LOADING: "隐藏加载事件",
|
|
1083
1336
|
UI_SHOW_MESSAGE: "显示消息事件"
|
|
1084
1337
|
};
|
|
1085
|
-
class
|
|
1338
|
+
class M {
|
|
1086
1339
|
static instance = null;
|
|
1087
1340
|
listeners = {};
|
|
1088
1341
|
debugMode;
|
|
1089
1342
|
constructor(t = !1) {
|
|
1090
|
-
this.debugMode = t, Object.keys(
|
|
1343
|
+
this.debugMode = t, Object.keys(x).forEach(
|
|
1091
1344
|
(e) => {
|
|
1092
1345
|
this.listeners[e] = /* @__PURE__ */ new Set();
|
|
1093
1346
|
}
|
|
1094
1347
|
);
|
|
1095
1348
|
}
|
|
1096
|
-
// 单例模式
|
|
1097
1349
|
static getInstance(t) {
|
|
1098
|
-
return
|
|
1350
|
+
return M.instance || (M.instance = new M(t)), M.instance;
|
|
1099
1351
|
}
|
|
1100
|
-
/**
|
|
1101
|
-
* 添加事件监听器
|
|
1102
|
-
* @param event 事件名称
|
|
1103
|
-
* @param listener 监听函数
|
|
1104
|
-
*/
|
|
1105
1352
|
on(t, e) {
|
|
1106
|
-
this.debugLog(`添加事件监听: ${
|
|
1353
|
+
this.debugLog(`添加事件监听: ${x[t]}`), this.listeners[t].add(e);
|
|
1107
1354
|
}
|
|
1108
|
-
/**
|
|
1109
|
-
* 触发事件
|
|
1110
|
-
* @param event 事件名称
|
|
1111
|
-
* @param params 事件参数
|
|
1112
|
-
*/
|
|
1113
1355
|
emit(t, e) {
|
|
1114
|
-
this.debugLog(`触发事件: ${
|
|
1356
|
+
this.debugLog(`触发事件: ${x[t]}`, e), this.listeners[t].forEach((s) => {
|
|
1115
1357
|
try {
|
|
1116
1358
|
s(e);
|
|
1117
|
-
} catch (
|
|
1118
|
-
console.error(`事件 ${
|
|
1359
|
+
} catch (r) {
|
|
1360
|
+
console.error(`事件 ${x[t]} 处理出错:`, r);
|
|
1119
1361
|
}
|
|
1120
1362
|
});
|
|
1121
1363
|
}
|
|
1122
|
-
/**
|
|
1123
|
-
* 移除事件监听器
|
|
1124
|
-
* @param event 事件名称
|
|
1125
|
-
* @param listener 监听函数
|
|
1126
|
-
*/
|
|
1127
1364
|
off(t, e) {
|
|
1128
|
-
this.debugLog(`移除事件监听: ${
|
|
1365
|
+
this.debugLog(`移除事件监听: ${x[t]}`), this.listeners[t].delete(e);
|
|
1129
1366
|
}
|
|
1130
|
-
/**
|
|
1131
|
-
* 添加一次性事件监听器
|
|
1132
|
-
* @param event 事件名称
|
|
1133
|
-
* @param listener 监听函数
|
|
1134
|
-
*/
|
|
1135
1367
|
once(t, e) {
|
|
1136
|
-
this.debugLog(`添加一次性事件监听: ${
|
|
1137
|
-
const s = (
|
|
1138
|
-
e(
|
|
1368
|
+
this.debugLog(`添加一次性事件监听: ${x[t]}`);
|
|
1369
|
+
const s = (r) => {
|
|
1370
|
+
e(r), this.off(t, s);
|
|
1139
1371
|
};
|
|
1140
1372
|
this.on(t, s);
|
|
1141
1373
|
}
|
|
1142
|
-
/**
|
|
1143
|
-
* 清除所有事件监听器
|
|
1144
|
-
*/
|
|
1145
1374
|
clear() {
|
|
1146
1375
|
this.debugLog("清除所有事件监听器"), Object.values(this.listeners).forEach((t) => t.clear());
|
|
1147
1376
|
}
|
|
1148
|
-
/**
|
|
1149
|
-
* 获取指定事件的监听器数量
|
|
1150
|
-
*/
|
|
1151
1377
|
getListenerCount(t) {
|
|
1152
1378
|
return this.listeners[t].size;
|
|
1153
1379
|
}
|
|
@@ -1155,105 +1381,31 @@ class I {
|
|
|
1155
1381
|
this.debugMode && console.log(`[EventEmitter] ${t}`, e || "");
|
|
1156
1382
|
}
|
|
1157
1383
|
}
|
|
1158
|
-
function Z(r, t, e) {
|
|
1159
|
-
let s = -1, i = r.length, n;
|
|
1160
|
-
for (; i - s > 1; )
|
|
1161
|
-
n = i - (i - s) >> 1, e(r[n], t) ? i = n : s = n;
|
|
1162
|
-
return i;
|
|
1163
|
-
}
|
|
1164
|
-
String.prototype.pointLength = function() {
|
|
1165
|
-
let r = 0;
|
|
1166
|
-
for (let t = 0, e = this.length; t < e; ) {
|
|
1167
|
-
const s = this.codePointAt(t);
|
|
1168
|
-
t += s > 65535 ? 2 : 1, r++;
|
|
1169
|
-
}
|
|
1170
|
-
return r;
|
|
1171
|
-
};
|
|
1172
|
-
String.prototype.pointAt = function(r) {
|
|
1173
|
-
if (r >= this.pointLength()) return;
|
|
1174
|
-
let t = 0;
|
|
1175
|
-
for (let e = 0, s = this.length; e < s; ) {
|
|
1176
|
-
const i = this.codePointAt(e);
|
|
1177
|
-
if (!i) return;
|
|
1178
|
-
if (t === r)
|
|
1179
|
-
return String.fromCodePoint(i);
|
|
1180
|
-
e += i > 65535 ? 2 : 1, t++;
|
|
1181
|
-
}
|
|
1182
|
-
};
|
|
1183
|
-
String.prototype.sliceByPoint = function(r, t = this.pointLength()) {
|
|
1184
|
-
let e = "";
|
|
1185
|
-
for (let s = r; s < t; s++)
|
|
1186
|
-
e += this.pointAt(s);
|
|
1187
|
-
return e;
|
|
1188
|
-
};
|
|
1189
|
-
RegExp.escape = function(r) {
|
|
1190
|
-
return r.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1191
|
-
};
|
|
1192
|
-
Element.prototype.farthest = function(r) {
|
|
1193
|
-
if (typeof r != "string" || !r) return null;
|
|
1194
|
-
let t = null, e = this;
|
|
1195
|
-
for (; e; ) {
|
|
1196
|
-
const s = e.closest(r);
|
|
1197
|
-
if (!s)
|
|
1198
|
-
break;
|
|
1199
|
-
t = s, e = s.parentElement;
|
|
1200
|
-
}
|
|
1201
|
-
return t;
|
|
1202
|
-
};
|
|
1203
|
-
Object.defineProperties(Element.prototype, {
|
|
1204
|
-
firstElement: {
|
|
1205
|
-
get: function() {
|
|
1206
|
-
if (!this.children.length) return null;
|
|
1207
|
-
let r = this.firstElementChild, t = null;
|
|
1208
|
-
for (; r; )
|
|
1209
|
-
t = r, r = r.firstElementChild;
|
|
1210
|
-
return t;
|
|
1211
|
-
}
|
|
1212
|
-
},
|
|
1213
|
-
lastElement: {
|
|
1214
|
-
get: function() {
|
|
1215
|
-
if (!this.children.length) return null;
|
|
1216
|
-
let r = this.lastElementChild, t = null;
|
|
1217
|
-
for (; r; )
|
|
1218
|
-
t = r, r = r.lastElementChild;
|
|
1219
|
-
return t;
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
});
|
|
1223
|
-
Text.prototype.surround = function(r = "strong", t = "") {
|
|
1224
|
-
if (!this.nodeValue || !r || !t) return null;
|
|
1225
|
-
const s = r.split("."), i = s[0], n = s.slice(1).join(" "), h = this.textContent.indexOf(t);
|
|
1226
|
-
if (h < 0) return null;
|
|
1227
|
-
const o = document.createRange();
|
|
1228
|
-
o.setStart(this, h), o.setEnd(this, h + t.length);
|
|
1229
|
-
const c = document.createElement(i);
|
|
1230
|
-
return n && (c.className = n), o.surroundContents(c), c;
|
|
1231
|
-
};
|
|
1232
1384
|
export {
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1385
|
+
_ as Arr,
|
|
1386
|
+
J as BitPerm,
|
|
1387
|
+
Y as Color,
|
|
1388
|
+
S as DateEx,
|
|
1389
|
+
V as Dictionary,
|
|
1390
|
+
M as Emitter,
|
|
1391
|
+
G as Func,
|
|
1392
|
+
B as Graph,
|
|
1393
|
+
F as LRU,
|
|
1240
1394
|
g as Line,
|
|
1241
|
-
|
|
1242
|
-
|
|
1395
|
+
T as LinkedList,
|
|
1396
|
+
I as Matrix,
|
|
1243
1397
|
q as MaxHeap,
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1398
|
+
W as MemoizeMap,
|
|
1399
|
+
L as MinHeap,
|
|
1400
|
+
U as MinStack,
|
|
1401
|
+
y as Num,
|
|
1402
|
+
X as Obj,
|
|
1248
1403
|
u as Point,
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1404
|
+
H as Queue,
|
|
1405
|
+
Q as Reg,
|
|
1406
|
+
j as Roman,
|
|
1407
|
+
D as Stack,
|
|
1408
|
+
Z as Str,
|
|
1253
1409
|
p as Triangle,
|
|
1254
|
-
w as Vector
|
|
1255
|
-
Z as binarySearchTemplate,
|
|
1256
|
-
H as isValidBracket,
|
|
1257
|
-
K as singleton,
|
|
1258
|
-
_ as sleep
|
|
1410
|
+
w as Vector
|
|
1259
1411
|
};
|