jc-structure 0.1.15 → 0.1.17
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 +196 -388
- package/dist/jc-structure.umd.cjs +2 -2
- package/package.json +1 -1
- package/types/queue.d.ts +2 -2
- package/types/shape.d.ts +11 -0
- package/types/stack.d.ts +4 -6
package/dist/jc-structure.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class V {
|
|
2
2
|
items = {};
|
|
3
3
|
count = 0;
|
|
4
4
|
lowestCount = 0;
|
|
@@ -12,13 +12,23 @@ class j {
|
|
|
12
12
|
enqueue(...t) {
|
|
13
13
|
if (t.length === 0)
|
|
14
14
|
return this;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
if (t.length === 1) {
|
|
16
|
+
const e = t[0];
|
|
17
|
+
return Array.isArray(e) ? this.batchEnqueue(e) : this.enqueueItem(e);
|
|
18
|
+
}
|
|
19
|
+
for (const e of t)
|
|
20
|
+
Array.isArray(e) ? this.batchEnqueue(e) : this.enqueueItem(e);
|
|
21
|
+
return this;
|
|
17
22
|
}
|
|
18
23
|
batchEnqueue(t) {
|
|
19
|
-
t.forEach((
|
|
20
|
-
this.isValidItem(
|
|
21
|
-
});
|
|
24
|
+
return t.filter((s) => this.isValidItem(s)).forEach((s) => {
|
|
25
|
+
this.isValidItem(s) && (this.items[this.count] = s, this.count++);
|
|
26
|
+
}), this;
|
|
27
|
+
}
|
|
28
|
+
enqueueItem(t) {
|
|
29
|
+
if (!this.isValidItem(t))
|
|
30
|
+
throw new Error("Invalid item");
|
|
31
|
+
return this.items[this.count] = t, this.count++, this;
|
|
22
32
|
}
|
|
23
33
|
isValidItem(t) {
|
|
24
34
|
return t != null;
|
|
@@ -39,7 +49,7 @@ class j {
|
|
|
39
49
|
return this.isEmpty() ? "" : `Queue(size: ${this.size()}):[${this.items[this.lowestCount]},...rest]`;
|
|
40
50
|
}
|
|
41
51
|
}
|
|
42
|
-
class
|
|
52
|
+
class z {
|
|
43
53
|
items = {};
|
|
44
54
|
count = 0;
|
|
45
55
|
constructor() {
|
|
@@ -50,8 +60,16 @@ class U {
|
|
|
50
60
|
const t = this.items[this.count];
|
|
51
61
|
return delete this.items[this.count], t;
|
|
52
62
|
}
|
|
53
|
-
push(t) {
|
|
54
|
-
|
|
63
|
+
push(...t) {
|
|
64
|
+
if (t.length === 0)
|
|
65
|
+
return this;
|
|
66
|
+
if (t.length === 1) {
|
|
67
|
+
const e = t[0];
|
|
68
|
+
return Array.isArray(e) ? this.addItems(e) : this.addItem(e);
|
|
69
|
+
}
|
|
70
|
+
for (const e of t)
|
|
71
|
+
Array.isArray(e) ? this.addItems(e) : this.addItem(e);
|
|
72
|
+
return this;
|
|
55
73
|
}
|
|
56
74
|
addItem(t) {
|
|
57
75
|
if (!this.isValidItem(t))
|
|
@@ -82,7 +100,7 @@ class U {
|
|
|
82
100
|
return this.isEmpty() ? "" : `Stack(count: ${this.count}):[${this.items[this.count - 1]},...rest]`;
|
|
83
101
|
}
|
|
84
102
|
}
|
|
85
|
-
class
|
|
103
|
+
class D {
|
|
86
104
|
stack = [];
|
|
87
105
|
minStack = [];
|
|
88
106
|
push(t) {
|
|
@@ -111,13 +129,13 @@ class $ {
|
|
|
111
129
|
return this.isEmpty() ? "" : `MinStack(count: ${this.size()}):[${this.getMin()},...rest]`;
|
|
112
130
|
}
|
|
113
131
|
}
|
|
114
|
-
function
|
|
132
|
+
function P(r, t) {
|
|
115
133
|
return r === t ? 0 : r < t ? -1 : 1;
|
|
116
134
|
}
|
|
117
|
-
class
|
|
135
|
+
class w {
|
|
118
136
|
heap = [];
|
|
119
137
|
compareFn;
|
|
120
|
-
constructor(t =
|
|
138
|
+
constructor(t = P) {
|
|
121
139
|
this.compareFn = t;
|
|
122
140
|
}
|
|
123
141
|
static getLeftIndex(t) {
|
|
@@ -148,7 +166,7 @@ class y {
|
|
|
148
166
|
return this.heap.toString();
|
|
149
167
|
}
|
|
150
168
|
}
|
|
151
|
-
class O extends
|
|
169
|
+
class O extends w {
|
|
152
170
|
insert(t) {
|
|
153
171
|
return t ? !1 : (this.heap.push(t), this.siftUp(this.heap.length - 1), !0);
|
|
154
172
|
}
|
|
@@ -159,24 +177,24 @@ class O extends y {
|
|
|
159
177
|
return this.heap[0] = this.heap.pop(), this.siftDown(0), t;
|
|
160
178
|
}
|
|
161
179
|
siftUp(t) {
|
|
162
|
-
let e = t, s =
|
|
163
|
-
s < n && this.compareFn(this.heap[e], this.heap[s]) === -1 && (e = s), i < n && this.compareFn(this.heap[e], this.heap[i]) === 1 && (e = i), e !== t && (
|
|
180
|
+
let e = t, s = w.getLeftIndex(e), i = w.getRightIndex(e), n = this.size();
|
|
181
|
+
s < n && this.compareFn(this.heap[e], this.heap[s]) === -1 && (e = s), i < n && this.compareFn(this.heap[e], this.heap[i]) === 1 && (e = i), e !== t && (w.swap(this.heap, t, e), this.siftUp(e));
|
|
164
182
|
}
|
|
165
183
|
siftDown(t) {
|
|
166
|
-
let e =
|
|
184
|
+
let e = w.getParentIndex(t);
|
|
167
185
|
for (; t > 0 && e && this.compareFn(this.heap[e], this.heap[t]) === 1; )
|
|
168
|
-
|
|
186
|
+
w.swap(this.heap, e, t), t = e, e = w.getParentIndex(t);
|
|
169
187
|
}
|
|
170
188
|
}
|
|
171
189
|
class q extends O {
|
|
172
|
-
constructor(t = (e, s) =>
|
|
190
|
+
constructor(t = (e, s) => P(s, e)) {
|
|
173
191
|
super(t);
|
|
174
192
|
}
|
|
175
193
|
}
|
|
176
|
-
function
|
|
194
|
+
function L(r) {
|
|
177
195
|
return { value: r };
|
|
178
196
|
}
|
|
179
|
-
class
|
|
197
|
+
class j {
|
|
180
198
|
capacity;
|
|
181
199
|
length = 0;
|
|
182
200
|
head = null;
|
|
@@ -206,14 +224,14 @@ class D {
|
|
|
206
224
|
}
|
|
207
225
|
update(t, e) {
|
|
208
226
|
let s = this.lookup.get(t);
|
|
209
|
-
s ? (this.detach(s), this.prepend(s), s.value = e) : (s =
|
|
227
|
+
s ? (this.detach(s), this.prepend(s), s.value = e) : (s = L(e), this.length++, this.prepend(s), this.trimCache(), this.lookup.set(t, s), this.reverseLookup);
|
|
210
228
|
}
|
|
211
229
|
}
|
|
212
|
-
|
|
230
|
+
class v {
|
|
213
231
|
value;
|
|
214
232
|
next = void 0;
|
|
215
|
-
}
|
|
216
|
-
class
|
|
233
|
+
}
|
|
234
|
+
class U {
|
|
217
235
|
count = 0;
|
|
218
236
|
head = void 0;
|
|
219
237
|
constructor() {
|
|
@@ -246,7 +264,7 @@ class H {
|
|
|
246
264
|
return this.getElementAt(t)?.value;
|
|
247
265
|
}
|
|
248
266
|
insert(t, e) {
|
|
249
|
-
let s = new
|
|
267
|
+
let s = new v();
|
|
250
268
|
if (s.value = t, e > this.count || e < 0)
|
|
251
269
|
throw new Error("index error");
|
|
252
270
|
this.count++;
|
|
@@ -258,7 +276,7 @@ class H {
|
|
|
258
276
|
i = this.getElementAt(e - 1), n = i.next, i.next = s, s.next = n;
|
|
259
277
|
}
|
|
260
278
|
push(t) {
|
|
261
|
-
let e = new
|
|
279
|
+
let e = new v();
|
|
262
280
|
if (e.value = t, this.count++, this.isEmpty()) {
|
|
263
281
|
this.head = e;
|
|
264
282
|
return;
|
|
@@ -292,17 +310,17 @@ class H {
|
|
|
292
310
|
return t = t.slice(0, -1), t;
|
|
293
311
|
}
|
|
294
312
|
}
|
|
295
|
-
class
|
|
313
|
+
class C {
|
|
296
314
|
key;
|
|
297
315
|
value;
|
|
298
316
|
constructor(t, e) {
|
|
299
317
|
this.key = t, this.value = e;
|
|
300
318
|
}
|
|
301
319
|
}
|
|
302
|
-
function
|
|
320
|
+
function M(r, t = { emptyString: !1, zeroNumber: !1 }) {
|
|
303
321
|
return r == null ? !(t.emptyString && r === "" || t.zeroNumber && r === 0) : !1;
|
|
304
322
|
}
|
|
305
|
-
class
|
|
323
|
+
class R {
|
|
306
324
|
table = [];
|
|
307
325
|
constructor() {
|
|
308
326
|
}
|
|
@@ -313,15 +331,15 @@ class z {
|
|
|
313
331
|
return -1;
|
|
314
332
|
}
|
|
315
333
|
set(t, e) {
|
|
316
|
-
if (
|
|
334
|
+
if (M(t))
|
|
317
335
|
throw new Error("key is required");
|
|
318
|
-
if (
|
|
336
|
+
if (M(e))
|
|
319
337
|
throw new Error("value is required");
|
|
320
338
|
if (this.has(t)) {
|
|
321
339
|
let s = this.getItemIndex(t);
|
|
322
340
|
this.table[s].value = e;
|
|
323
341
|
} else {
|
|
324
|
-
const s = new
|
|
342
|
+
const s = new C(t, e);
|
|
325
343
|
this.table.push(s);
|
|
326
344
|
}
|
|
327
345
|
}
|
|
@@ -372,12 +390,12 @@ class z {
|
|
|
372
390
|
return t = t.slice(0, -1), t;
|
|
373
391
|
}
|
|
374
392
|
}
|
|
375
|
-
class
|
|
393
|
+
class $ {
|
|
376
394
|
isDirected;
|
|
377
395
|
vertices;
|
|
378
396
|
adjList;
|
|
379
397
|
constructor(t = !1) {
|
|
380
|
-
this.isDirected = t, this.vertices = [], this.adjList = new
|
|
398
|
+
this.isDirected = t, this.vertices = [], this.adjList = new R();
|
|
381
399
|
}
|
|
382
400
|
addVertex(t) {
|
|
383
401
|
this.vertices.includes(t) || (this.vertices.push(t), this.adjList.set(t, []));
|
|
@@ -399,10 +417,10 @@ class W {
|
|
|
399
417
|
return t;
|
|
400
418
|
}
|
|
401
419
|
}
|
|
402
|
-
class
|
|
420
|
+
class y {
|
|
403
421
|
_data;
|
|
404
422
|
static zero(t) {
|
|
405
|
-
return new
|
|
423
|
+
return new y(...Array(t).fill(0));
|
|
406
424
|
}
|
|
407
425
|
constructor(...t) {
|
|
408
426
|
this._data = t;
|
|
@@ -421,7 +439,7 @@ class w {
|
|
|
421
439
|
if (t === 0)
|
|
422
440
|
throw new Error("Cannot normalize a zero vector");
|
|
423
441
|
const e = this._data.map((s) => s / t);
|
|
424
|
-
return new
|
|
442
|
+
return new y(...e);
|
|
425
443
|
}
|
|
426
444
|
add(t) {
|
|
427
445
|
if (this.dimension !== t.dimension)
|
|
@@ -429,7 +447,7 @@ class w {
|
|
|
429
447
|
const e = this._data.map(
|
|
430
448
|
(s, i) => s + t._data[i]
|
|
431
449
|
);
|
|
432
|
-
return new
|
|
450
|
+
return new y(...e);
|
|
433
451
|
}
|
|
434
452
|
sub(t) {
|
|
435
453
|
if (this.dimension !== t.dimension)
|
|
@@ -437,10 +455,10 @@ class w {
|
|
|
437
455
|
const e = this._data.map(
|
|
438
456
|
(s, i) => s - t._data[i]
|
|
439
457
|
);
|
|
440
|
-
return new
|
|
458
|
+
return new y(...e);
|
|
441
459
|
}
|
|
442
460
|
mul(t) {
|
|
443
|
-
return new
|
|
461
|
+
return new y(...this._data.map((e) => e * t));
|
|
444
462
|
}
|
|
445
463
|
dot(t) {
|
|
446
464
|
if (this.dimension !== t.dimension)
|
|
@@ -480,10 +498,10 @@ class E {
|
|
|
480
498
|
return this.row * this.col;
|
|
481
499
|
}
|
|
482
500
|
rowVector(t) {
|
|
483
|
-
return new
|
|
501
|
+
return new y(...this._matrix[t]);
|
|
484
502
|
}
|
|
485
503
|
colVector(t) {
|
|
486
|
-
return new
|
|
504
|
+
return new y(...this._matrix.map((e) => e[t]));
|
|
487
505
|
}
|
|
488
506
|
getItem(t) {
|
|
489
507
|
return this._matrix[t[0]][t[1]];
|
|
@@ -534,7 +552,7 @@ class E {
|
|
|
534
552
|
return e;
|
|
535
553
|
}
|
|
536
554
|
}
|
|
537
|
-
class
|
|
555
|
+
class u {
|
|
538
556
|
static distance(t, e) {
|
|
539
557
|
return Math.hypot(e.x - t.x, e.y - t.y);
|
|
540
558
|
}
|
|
@@ -544,41 +562,41 @@ class c {
|
|
|
544
562
|
this.x = t, this.y = e;
|
|
545
563
|
}
|
|
546
564
|
distanceTo(t) {
|
|
547
|
-
return
|
|
565
|
+
return u.distance(this, t);
|
|
548
566
|
}
|
|
549
567
|
}
|
|
550
|
-
class
|
|
568
|
+
class g {
|
|
551
569
|
// 使用更合适的精度阈值常量
|
|
552
570
|
static EPSILON = 1e-10;
|
|
553
|
-
static sloped(t, e =
|
|
571
|
+
static sloped(t, e = g.EPSILON) {
|
|
554
572
|
const s = t.p2.x - t.p1.x, i = t.p2.y - t.p1.y;
|
|
555
573
|
return Math.abs(s) < e ? Math.abs(i) < e ? 0 : null : i / s;
|
|
556
574
|
}
|
|
557
|
-
static isParallel(t, e, s =
|
|
558
|
-
const i =
|
|
575
|
+
static isParallel(t, e, s = g.EPSILON) {
|
|
576
|
+
const i = g.sloped(t), n = g.sloped(e);
|
|
559
577
|
return i === null && n === null ? !0 : i === null || n === null ? !1 : Math.abs(i - n) < s;
|
|
560
578
|
}
|
|
561
|
-
static getIntersection(t, e, s =
|
|
562
|
-
if (
|
|
563
|
-
const i = t.p1.x, n = t.p1.y,
|
|
579
|
+
static getIntersection(t, e, s = g.EPSILON) {
|
|
580
|
+
if (g.isParallel(t, e)) return null;
|
|
581
|
+
const i = t.p1.x, n = t.p1.y, h = t.p2.x, o = t.p2.y, c = e.p1.x, f = e.p1.y, m = e.p2.x, a = e.p2.y, l = (i - h) * (f - a) - (n - o) * (c - m);
|
|
564
582
|
if (Math.abs(l) < s) return null;
|
|
565
|
-
const d = ((i -
|
|
583
|
+
const d = ((i - c) * (f - a) - (n - f) * (c - m)) / l, S = -((i - h) * (n - f) - (n - o) * (i - c)) / l;
|
|
566
584
|
if (d >= 0 && d <= 1 && S >= 0 && S <= 1) {
|
|
567
|
-
const
|
|
568
|
-
return new
|
|
585
|
+
const k = i + d * (h - i), N = n + d * (o - n);
|
|
586
|
+
return new u(k, N);
|
|
569
587
|
}
|
|
570
588
|
return null;
|
|
571
589
|
}
|
|
572
590
|
static isIntersecting(t, e) {
|
|
573
|
-
return
|
|
574
|
-
}
|
|
575
|
-
static distanceToPoint(t, e, s =
|
|
576
|
-
const i = e.x - t.p1.x, n = e.y - t.p1.y,
|
|
577
|
-
let
|
|
578
|
-
f > s && (
|
|
579
|
-
let
|
|
580
|
-
|
|
581
|
-
const d = e.x -
|
|
591
|
+
return g.getIntersection(t, e) !== null;
|
|
592
|
+
}
|
|
593
|
+
static distanceToPoint(t, e, s = g.EPSILON) {
|
|
594
|
+
const i = e.x - t.p1.x, n = e.y - t.p1.y, h = t.p2.x - t.p1.x, o = t.p2.y - t.p1.y, c = i * h + n * o, f = h * h + o * o;
|
|
595
|
+
let m = -1;
|
|
596
|
+
f > s && (m = c / f);
|
|
597
|
+
let a, l;
|
|
598
|
+
m < 0 ? (a = t.p1.x, l = t.p1.y) : m > 1 ? (a = t.p2.x, l = t.p2.y) : (a = t.p1.x + m * h, l = t.p1.y + m * o);
|
|
599
|
+
const d = e.x - a, S = e.y - l;
|
|
582
600
|
return Math.hypot(d + S);
|
|
583
601
|
}
|
|
584
602
|
p1;
|
|
@@ -592,21 +610,21 @@ class m {
|
|
|
592
610
|
}
|
|
593
611
|
get midpoint() {
|
|
594
612
|
const t = (this.p1.x + this.p2.x) / 2, e = (this.p1.y + this.p2.y) / 2;
|
|
595
|
-
return new
|
|
613
|
+
return new u(t, e);
|
|
596
614
|
}
|
|
597
615
|
get angle() {
|
|
598
616
|
return Math.atan2(this.p2.y - this.p1.y, this.p2.x - this.p1.x);
|
|
599
617
|
}
|
|
600
|
-
containsPoint(t, e =
|
|
618
|
+
containsPoint(t, e = g.EPSILON) {
|
|
601
619
|
const s = (t.x - this.p1.x) * (this.p2.y - this.p1.y) - (t.y - this.p1.y) * (this.p2.x - this.p1.x);
|
|
602
620
|
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;
|
|
603
621
|
}
|
|
604
622
|
// 获取线段的方向向量
|
|
605
623
|
get direction() {
|
|
606
624
|
const t = this.length;
|
|
607
|
-
if (t <
|
|
625
|
+
if (t < g.EPSILON) return new u(0, 0);
|
|
608
626
|
const e = (this.p2.x - this.p1.x) / t, s = (this.p2.y - this.p1.y) / t;
|
|
609
|
-
return new
|
|
627
|
+
return new u(e, s);
|
|
610
628
|
}
|
|
611
629
|
get start() {
|
|
612
630
|
return this.p1;
|
|
@@ -615,14 +633,14 @@ class m {
|
|
|
615
633
|
return this.p2;
|
|
616
634
|
}
|
|
617
635
|
}
|
|
618
|
-
class
|
|
636
|
+
class A {
|
|
619
637
|
static EPSILON = 1e-10;
|
|
620
638
|
name;
|
|
621
639
|
constructor(t) {
|
|
622
640
|
this.name = t;
|
|
623
641
|
}
|
|
624
642
|
}
|
|
625
|
-
class p extends
|
|
643
|
+
class p extends A {
|
|
626
644
|
static isValid(t, e, s) {
|
|
627
645
|
return t <= 0 || e <= 0 || s <= 0 ? !1 : t + e > s && t + s > e && e + s > t;
|
|
628
646
|
}
|
|
@@ -635,14 +653,14 @@ class p extends N {
|
|
|
635
653
|
static getType(t, e, s) {
|
|
636
654
|
if (!p.isValid(t, e, s))
|
|
637
655
|
throw new Error("Invalid triangle sides");
|
|
638
|
-
const i = [t, e, s].sort((
|
|
639
|
-
return Math.abs(n -
|
|
656
|
+
const i = [t, e, s].sort((c, f) => c - f), [n, h, o] = i;
|
|
657
|
+
return Math.abs(n - h) < p.EPSILON && Math.abs(h - o) < p.EPSILON ? "equilateral" : Math.abs(n - h) < p.EPSILON || Math.abs(h - o) < p.EPSILON ? "isosceles" : "scalene";
|
|
640
658
|
}
|
|
641
659
|
static getAngles(t, e, s) {
|
|
642
660
|
if (!p.isValid(t, e, s))
|
|
643
661
|
throw new Error("Invalid triangle sides");
|
|
644
|
-
const i = Math.acos((e * e + s * s - t * t) / (2 * e * s)), n = Math.acos((t * t + s * s - e * e) / (2 * t * s)),
|
|
645
|
-
return [i, n,
|
|
662
|
+
const i = Math.acos((e * e + s * s - t * t) / (2 * e * s)), n = Math.acos((t * t + s * s - e * e) / (2 * t * s)), h = Math.PI - i - n;
|
|
663
|
+
return [i, n, h];
|
|
646
664
|
}
|
|
647
665
|
p1;
|
|
648
666
|
p2;
|
|
@@ -655,13 +673,13 @@ class p extends N {
|
|
|
655
673
|
areCollinear() {
|
|
656
674
|
return Math.abs(
|
|
657
675
|
(this.p2.x - this.p1.x) * (this.p3.y - this.p1.y) - (this.p3.x - this.p1.x) * (this.p2.y - this.p1.y)
|
|
658
|
-
) <
|
|
676
|
+
) < A.EPSILON;
|
|
659
677
|
}
|
|
660
678
|
get side() {
|
|
661
679
|
return [
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
680
|
+
u.distance(this.p1, this.p2),
|
|
681
|
+
u.distance(this.p2, this.p3),
|
|
682
|
+
u.distance(this.p3, this.p1)
|
|
665
683
|
];
|
|
666
684
|
}
|
|
667
685
|
perimeter() {
|
|
@@ -680,43 +698,43 @@ class p extends N {
|
|
|
680
698
|
return p.getAngles(t, e, s);
|
|
681
699
|
}
|
|
682
700
|
get centroid() {
|
|
683
|
-
return new
|
|
701
|
+
return new u(
|
|
684
702
|
(this.p1.x + this.p2.x + this.p3.x) / 3,
|
|
685
703
|
(this.p1.y + this.p2.y + this.p3.y) / 3
|
|
686
704
|
);
|
|
687
705
|
}
|
|
688
706
|
get incenter() {
|
|
689
|
-
const [t, e, s] = this.side, i = this.perimeter() / 2, n = (t * this.p1.x + e * this.p2.x + s * this.p3.x) / i,
|
|
690
|
-
return new
|
|
707
|
+
const [t, e, s] = this.side, i = this.perimeter() / 2, n = (t * this.p1.x + e * this.p2.x + s * this.p3.x) / i, h = (t * this.p1.y + e * this.p2.y + s * this.p3.y) / i;
|
|
708
|
+
return new u(n, h);
|
|
691
709
|
}
|
|
692
710
|
get circumcenter() {
|
|
693
711
|
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));
|
|
694
712
|
if (Math.abs(t) < p.EPSILON)
|
|
695
713
|
throw new Error("Cannot calculate circumcenter for collinear points");
|
|
696
714
|
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;
|
|
697
|
-
return new
|
|
715
|
+
return new u(e, s);
|
|
698
716
|
}
|
|
699
717
|
containsPoint(t) {
|
|
700
718
|
const e = p.area(
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
719
|
+
u.distance(t, this.p1),
|
|
720
|
+
u.distance(t, this.p2),
|
|
721
|
+
u.distance(this.p1, this.p2)
|
|
704
722
|
), s = p.area(
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
723
|
+
u.distance(t, this.p2),
|
|
724
|
+
u.distance(t, this.p3),
|
|
725
|
+
u.distance(this.p2, this.p3)
|
|
708
726
|
), i = p.area(
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
727
|
+
u.distance(t, this.p3),
|
|
728
|
+
u.distance(t, this.p1),
|
|
729
|
+
u.distance(this.p3, this.p1)
|
|
712
730
|
);
|
|
713
731
|
return Math.abs(e + s + i - this.area()) < p.EPSILON;
|
|
714
732
|
}
|
|
715
733
|
}
|
|
716
|
-
function
|
|
734
|
+
function _(r) {
|
|
717
735
|
return new Promise((t) => setTimeout(t, r));
|
|
718
736
|
}
|
|
719
|
-
function
|
|
737
|
+
function H(r) {
|
|
720
738
|
const t = [], e = {
|
|
721
739
|
"(": ")",
|
|
722
740
|
"[": "]",
|
|
@@ -729,23 +747,23 @@ function F(r) {
|
|
|
729
747
|
return !1;
|
|
730
748
|
return t.length === 0;
|
|
731
749
|
}
|
|
732
|
-
function
|
|
750
|
+
function b(r) {
|
|
733
751
|
return r !== null && (typeof r == "object" || typeof r == "function");
|
|
734
752
|
}
|
|
735
|
-
class
|
|
753
|
+
class F {
|
|
736
754
|
map = /* @__PURE__ */ new Map();
|
|
737
755
|
weakMap = /* @__PURE__ */ new WeakMap();
|
|
738
756
|
set(t, e) {
|
|
739
|
-
|
|
757
|
+
b(t) ? this.weakMap.set(t, e) : this.map.set(t, e);
|
|
740
758
|
}
|
|
741
759
|
get(t) {
|
|
742
|
-
return
|
|
760
|
+
return b(t) ? this.weakMap.get(t) : this.map.get(t);
|
|
743
761
|
}
|
|
744
762
|
has(t) {
|
|
745
|
-
return
|
|
763
|
+
return b(t) ? this.weakMap.has(t) : this.map.has(t);
|
|
746
764
|
}
|
|
747
765
|
}
|
|
748
|
-
function
|
|
766
|
+
function T(r) {
|
|
749
767
|
if (!r.length) return [];
|
|
750
768
|
const t = [[r[0]]];
|
|
751
769
|
for (let s = 1, i = r.length; s < i; s++) {
|
|
@@ -754,16 +772,16 @@ function G(r) {
|
|
|
754
772
|
}
|
|
755
773
|
function e(s) {
|
|
756
774
|
for (let i = t.length - 1; i >= 0; i--) {
|
|
757
|
-
const n = t[i],
|
|
758
|
-
if (
|
|
775
|
+
const n = t[i], h = n[t[i].length - 1];
|
|
776
|
+
if (h < s) {
|
|
759
777
|
t[i + 1] = [...n, s];
|
|
760
778
|
break;
|
|
761
|
-
} else
|
|
779
|
+
} else h > s && i === 0 && (t[i] = [s]);
|
|
762
780
|
}
|
|
763
781
|
}
|
|
764
782
|
return t[t.length - 1];
|
|
765
783
|
}
|
|
766
|
-
class
|
|
784
|
+
class B {
|
|
767
785
|
static ROMAN_MAP = /* @__PURE__ */ new Map([
|
|
768
786
|
["M", 1e3],
|
|
769
787
|
["CM", 900],
|
|
@@ -783,19 +801,19 @@ class X {
|
|
|
783
801
|
if (t.length === 0)
|
|
784
802
|
throw new Error("Input cannot be empty");
|
|
785
803
|
const e = /* @__PURE__ */ new Set(["I", "V", "X", "L", "C", "D", "M"]);
|
|
786
|
-
for (const
|
|
787
|
-
if (!e.has(
|
|
788
|
-
throw new Error(`Invalid Roman numeral character: ${
|
|
804
|
+
for (const h of t)
|
|
805
|
+
if (!e.has(h))
|
|
806
|
+
throw new Error(`Invalid Roman numeral character: ${h}`);
|
|
789
807
|
let s = 0, i = 0;
|
|
790
808
|
for (; i < t.length; ) {
|
|
791
|
-
const
|
|
792
|
-
if (this.ROMAN_MAP.has(
|
|
793
|
-
s += this.ROMAN_MAP.get(
|
|
809
|
+
const h = t.slice(i, i + 2);
|
|
810
|
+
if (this.ROMAN_MAP.has(h))
|
|
811
|
+
s += this.ROMAN_MAP.get(h), i += 2;
|
|
794
812
|
else {
|
|
795
|
-
const
|
|
796
|
-
if (!
|
|
813
|
+
const o = t[i], c = this.ROMAN_MAP.get(o);
|
|
814
|
+
if (!c)
|
|
797
815
|
throw new Error(`Invalid Roman numeral sequence at position ${i}`);
|
|
798
|
-
s +=
|
|
816
|
+
s += c, i += 1;
|
|
799
817
|
}
|
|
800
818
|
}
|
|
801
819
|
if (this.toRoman(s) !== t)
|
|
@@ -814,7 +832,7 @@ class X {
|
|
|
814
832
|
return e;
|
|
815
833
|
}
|
|
816
834
|
}
|
|
817
|
-
class
|
|
835
|
+
class G {
|
|
818
836
|
static isValidPositiveInteger(t) {
|
|
819
837
|
return Number.isInteger(t) && t > 0 && t <= Number.MAX_SAFE_INTEGER;
|
|
820
838
|
}
|
|
@@ -840,31 +858,30 @@ class Q {
|
|
|
840
858
|
return t < 2 ? s : this.fibonacci(t - 1, s, s + e);
|
|
841
859
|
}
|
|
842
860
|
static fibonacciIterative(t) {
|
|
843
|
-
if (
|
|
844
|
-
|
|
845
|
-
let e = 1, s = 1;
|
|
861
|
+
if (t < 2) return t;
|
|
862
|
+
let e = 0, s = 1;
|
|
846
863
|
for (let i = 2; i < t; i++)
|
|
847
|
-
[e, s] = [s, e + s];
|
|
848
|
-
return
|
|
864
|
+
[e, s] = [s, (e + s) % 1000000007];
|
|
865
|
+
return s;
|
|
849
866
|
}
|
|
850
867
|
static getPercentWithPrecision(t, e = 2) {
|
|
851
868
|
if (!Array.isArray(t) || t.length === 0)
|
|
852
869
|
return [];
|
|
853
870
|
if (e < 0 || !Number.isInteger(e))
|
|
854
871
|
throw new Error("Precision must be a non-negative integer");
|
|
855
|
-
const s = t.reduce((
|
|
872
|
+
const s = t.reduce((a, l) => a + l, 0);
|
|
856
873
|
if (s === 0)
|
|
857
874
|
return t.map(() => "0%");
|
|
858
|
-
const n = 100 * Math.pow(10, e),
|
|
859
|
-
let f =
|
|
860
|
-
for (;
|
|
861
|
-
let
|
|
862
|
-
for (let d = 0; d <
|
|
863
|
-
|
|
864
|
-
if (
|
|
865
|
-
|
|
875
|
+
const n = 100 * Math.pow(10, e), h = t.map((a) => a / s * n), o = h.map((a) => Math.floor(a)), c = h.map((a, l) => a - o[l]);
|
|
876
|
+
let f = o.reduce((a, l) => a + l, 0), m = n - f;
|
|
877
|
+
for (; m > 0; ) {
|
|
878
|
+
let a = -1, l = -1;
|
|
879
|
+
for (let d = 0; d < c.length; d++)
|
|
880
|
+
c[d] > l && (l = c[d], a = d);
|
|
881
|
+
if (a === -1) break;
|
|
882
|
+
o[a]++, c[a] = 0, m--;
|
|
866
883
|
}
|
|
867
|
-
return
|
|
884
|
+
return o.map((a) => `${(a / n * 100).toFixed(e)}%`);
|
|
868
885
|
}
|
|
869
886
|
static fastSqrt(t) {
|
|
870
887
|
if (t < 0)
|
|
@@ -875,9 +892,6 @@ class Q {
|
|
|
875
892
|
let i = new Float64Array(new BigInt64Array([s]).buffer)[0];
|
|
876
893
|
return i = i * 0.5 + e / i, i = i * 0.5 + e / i, i = i * 0.5 + e / i, i;
|
|
877
894
|
}
|
|
878
|
-
static middle(t, e) {
|
|
879
|
-
return e - (e - t >> 1);
|
|
880
|
-
}
|
|
881
895
|
static gcd(t, e) {
|
|
882
896
|
return e === 0 ? t : this.gcd(e, t % e);
|
|
883
897
|
}
|
|
@@ -909,18 +923,33 @@ class Q {
|
|
|
909
923
|
i += Math.pow(parseInt(e[n]), s);
|
|
910
924
|
return i === t;
|
|
911
925
|
}
|
|
926
|
+
static isHappy(t) {
|
|
927
|
+
const e = /* @__PURE__ */ new Set();
|
|
928
|
+
for (; t !== 1; ) {
|
|
929
|
+
if (e.has(t)) return !1;
|
|
930
|
+
e.add(t), t = (t + "").split("").reduce((s, i) => s + Number(i) * Number(i), 0);
|
|
931
|
+
}
|
|
932
|
+
return !0;
|
|
933
|
+
}
|
|
912
934
|
static isPerfect(t) {
|
|
913
935
|
let e = 0;
|
|
914
936
|
for (let s = 1; s < t; s++)
|
|
915
937
|
t % s === 0 && (e += s);
|
|
916
938
|
return e === t;
|
|
917
939
|
}
|
|
940
|
+
static middle(t, e) {
|
|
941
|
+
return e - (e - t >> 1);
|
|
942
|
+
}
|
|
918
943
|
static scale(t, e, s) {
|
|
919
944
|
if (e[0] >= e[1] || s[0] >= s[1])
|
|
920
945
|
throw new Error("Invalid range");
|
|
946
|
+
t = this.clamp(t, e[0], e[1]);
|
|
921
947
|
const i = e[1] - e[0];
|
|
922
948
|
return (t - e[0]) * ((s[1] - s[0]) / i) + s[0];
|
|
923
949
|
}
|
|
950
|
+
static clamp(t, e, s) {
|
|
951
|
+
return Math.min(Math.max(t, e), s);
|
|
952
|
+
}
|
|
924
953
|
static randomInt(t, e) {
|
|
925
954
|
return Math.floor(Math.random() * (e - t + 1)) + t;
|
|
926
955
|
}
|
|
@@ -931,7 +960,7 @@ class Q {
|
|
|
931
960
|
return t >= 0 && e >= 0 || t <= 0 && e <= 0;
|
|
932
961
|
}
|
|
933
962
|
}
|
|
934
|
-
class
|
|
963
|
+
class W {
|
|
935
964
|
static READ = 1;
|
|
936
965
|
static WRITE = 2;
|
|
937
966
|
static SHARE = 4;
|
|
@@ -950,7 +979,7 @@ class K {
|
|
|
950
979
|
return t ^ e;
|
|
951
980
|
}
|
|
952
981
|
}
|
|
953
|
-
class
|
|
982
|
+
class X {
|
|
954
983
|
static longestCommonPrefix(t) {
|
|
955
984
|
if (!t.length) return "";
|
|
956
985
|
let e = t[0];
|
|
@@ -966,7 +995,7 @@ class Z {
|
|
|
966
995
|
});
|
|
967
996
|
}
|
|
968
997
|
}
|
|
969
|
-
class
|
|
998
|
+
class Q {
|
|
970
999
|
static isValidHex(t) {
|
|
971
1000
|
return /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t);
|
|
972
1001
|
}
|
|
@@ -974,7 +1003,7 @@ class J {
|
|
|
974
1003
|
return /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.test(t);
|
|
975
1004
|
}
|
|
976
1005
|
}
|
|
977
|
-
function
|
|
1006
|
+
function K(r) {
|
|
978
1007
|
let t;
|
|
979
1008
|
const e = new Proxy(r, {
|
|
980
1009
|
construct(s, i, n) {
|
|
@@ -1072,231 +1101,11 @@ class I {
|
|
|
1072
1101
|
this.debugMode && console.log(`[EventEmitter] ${t}`, e || "");
|
|
1073
1102
|
}
|
|
1074
1103
|
}
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
"div",
|
|
1081
|
-
"span",
|
|
1082
|
-
"p",
|
|
1083
|
-
"a",
|
|
1084
|
-
"img",
|
|
1085
|
-
"button",
|
|
1086
|
-
"input",
|
|
1087
|
-
"form",
|
|
1088
|
-
"label",
|
|
1089
|
-
"select",
|
|
1090
|
-
"option",
|
|
1091
|
-
"textarea",
|
|
1092
|
-
"ul",
|
|
1093
|
-
"ol",
|
|
1094
|
-
"li",
|
|
1095
|
-
"table",
|
|
1096
|
-
"tr",
|
|
1097
|
-
"td",
|
|
1098
|
-
"th",
|
|
1099
|
-
"thead",
|
|
1100
|
-
"tbody",
|
|
1101
|
-
"tfoot",
|
|
1102
|
-
"h1",
|
|
1103
|
-
"h2",
|
|
1104
|
-
"h3",
|
|
1105
|
-
"h4",
|
|
1106
|
-
"h5",
|
|
1107
|
-
"h6",
|
|
1108
|
-
"hr",
|
|
1109
|
-
"br",
|
|
1110
|
-
"section",
|
|
1111
|
-
"article",
|
|
1112
|
-
"nav",
|
|
1113
|
-
"header",
|
|
1114
|
-
"footer",
|
|
1115
|
-
"main",
|
|
1116
|
-
"aside",
|
|
1117
|
-
"figure",
|
|
1118
|
-
"figcaption"
|
|
1119
|
-
]),
|
|
1120
|
-
allowedAttributes: /* @__PURE__ */ new Set(["class", "id", "href", "src", "alt", "title"])
|
|
1121
|
-
};
|
|
1122
|
-
class v {
|
|
1123
|
-
static instance;
|
|
1124
|
-
constructor() {
|
|
1125
|
-
}
|
|
1126
|
-
static getInstance() {
|
|
1127
|
-
return v.instance || (v.instance = new v()), v.instance;
|
|
1128
|
-
}
|
|
1129
|
-
/**
|
|
1130
|
-
* 创建DOM元素
|
|
1131
|
-
* @param tagName 标签名
|
|
1132
|
-
* @param attributes 属性对象
|
|
1133
|
-
* @param content 元素内容
|
|
1134
|
-
* @returns 创建的HTMLElement
|
|
1135
|
-
*/
|
|
1136
|
-
createElement(t, e = {}, s = "") {
|
|
1137
|
-
if (!b.allowedTags.has(t.toLowerCase()))
|
|
1138
|
-
throw new Error(`Unsupported tag: ${t}`);
|
|
1139
|
-
const i = document.createElement(t);
|
|
1140
|
-
return this._processAttributes(i, e), this._processContent(i, s), i;
|
|
1141
|
-
}
|
|
1142
|
-
/**
|
|
1143
|
-
* 批量创建元素
|
|
1144
|
-
* @param items 元素配置数组
|
|
1145
|
-
* @param container 容器元素
|
|
1146
|
-
*/
|
|
1147
|
-
createBatch(t, e) {
|
|
1148
|
-
const s = document.createDocumentFragment();
|
|
1149
|
-
t.forEach((i) => {
|
|
1150
|
-
const n = this.createElement(
|
|
1151
|
-
i.tag,
|
|
1152
|
-
i.attributes || {},
|
|
1153
|
-
i.content || ""
|
|
1154
|
-
);
|
|
1155
|
-
s.appendChild(n);
|
|
1156
|
-
}), e.appendChild(s);
|
|
1157
|
-
}
|
|
1158
|
-
/**
|
|
1159
|
-
* 安全地设置HTML内容
|
|
1160
|
-
* @param element 目标元素
|
|
1161
|
-
* @param html HTML字符串
|
|
1162
|
-
*/
|
|
1163
|
-
setHtml(t, e) {
|
|
1164
|
-
const s = this._sanitizeHtml(e);
|
|
1165
|
-
t.innerHTML = s;
|
|
1166
|
-
}
|
|
1167
|
-
/**
|
|
1168
|
-
* 处理元素属性
|
|
1169
|
-
* @private
|
|
1170
|
-
*/
|
|
1171
|
-
_processAttributes(t, e) {
|
|
1172
|
-
Object.entries(e).forEach(([s, i]) => {
|
|
1173
|
-
if (!b.allowedAttributes.has(s) && !s.startsWith("data-")) {
|
|
1174
|
-
console.warn(`Potentially unsafe attribute: ${s}`);
|
|
1175
|
-
return;
|
|
1176
|
-
}
|
|
1177
|
-
if (typeof i == "function")
|
|
1178
|
-
s.startsWith("on") && t.addEventListener(
|
|
1179
|
-
s.slice(2).toLowerCase(),
|
|
1180
|
-
i
|
|
1181
|
-
);
|
|
1182
|
-
else
|
|
1183
|
-
switch (s) {
|
|
1184
|
-
case "className":
|
|
1185
|
-
t.className = i;
|
|
1186
|
-
break;
|
|
1187
|
-
case "dataset":
|
|
1188
|
-
Object.assign(t.dataset, i);
|
|
1189
|
-
break;
|
|
1190
|
-
case "style":
|
|
1191
|
-
Object.assign(t.style, i);
|
|
1192
|
-
break;
|
|
1193
|
-
default:
|
|
1194
|
-
t.setAttribute(s, i);
|
|
1195
|
-
}
|
|
1196
|
-
});
|
|
1197
|
-
}
|
|
1198
|
-
/**
|
|
1199
|
-
* 处理元素内容
|
|
1200
|
-
* @private
|
|
1201
|
-
*/
|
|
1202
|
-
_processContent(t, e) {
|
|
1203
|
-
typeof e == "string" ? t.textContent = e : e instanceof Node ? t.appendChild(e) : Array.isArray(e) && e.forEach((s) => {
|
|
1204
|
-
typeof s == "string" ? t.appendChild(document.createTextNode(s)) : t.appendChild(s);
|
|
1205
|
-
});
|
|
1206
|
-
}
|
|
1207
|
-
/**
|
|
1208
|
-
* 清理HTML字符串
|
|
1209
|
-
* @private
|
|
1210
|
-
*/
|
|
1211
|
-
_sanitizeHtml(t) {
|
|
1212
|
-
return t.replace(b.scriptRegex, "").replace(b.javascriptRegex, "").replace(b.eventHandlerRegex, "");
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
class tt {
|
|
1216
|
-
features;
|
|
1217
|
-
constructor() {
|
|
1218
|
-
this.features = this.detectFeatures();
|
|
1219
|
-
}
|
|
1220
|
-
detectFeatures() {
|
|
1221
|
-
return {
|
|
1222
|
-
geolocation: "geolocation" in navigator,
|
|
1223
|
-
notification: "Notification" in window,
|
|
1224
|
-
serviceWorker: "serviceWorker" in navigator,
|
|
1225
|
-
webShare: "share" in navigator,
|
|
1226
|
-
deviceOrientation: "DeviceOrientationEvent" in window,
|
|
1227
|
-
battery: "getBattery" in navigator,
|
|
1228
|
-
online: "onLine" in navigator
|
|
1229
|
-
};
|
|
1230
|
-
}
|
|
1231
|
-
async getLocation(t = {}) {
|
|
1232
|
-
if (!this.features.geolocation)
|
|
1233
|
-
throw new Error("Geolocation is not supported");
|
|
1234
|
-
const e = {
|
|
1235
|
-
enableHighAccuracy: !0,
|
|
1236
|
-
timeout: 10 * 1e3,
|
|
1237
|
-
maximumAge: 300 * 1e3
|
|
1238
|
-
};
|
|
1239
|
-
return new Promise((s, i) => {
|
|
1240
|
-
navigator.geolocation.getCurrentPosition(
|
|
1241
|
-
(n) => s({
|
|
1242
|
-
latitude: n.coords.latitude,
|
|
1243
|
-
longitude: n.coords.longitude,
|
|
1244
|
-
accuracy: n.coords.accuracy,
|
|
1245
|
-
timstamp: n.timestamp
|
|
1246
|
-
}),
|
|
1247
|
-
(n) => {
|
|
1248
|
-
const a = {
|
|
1249
|
-
1: "User denied the request for Geolocation.",
|
|
1250
|
-
2: "Position information is unavailable.",
|
|
1251
|
-
3: "The request to get user location timed out."
|
|
1252
|
-
};
|
|
1253
|
-
i(new Error(a[n.code] || "Unknown error"));
|
|
1254
|
-
},
|
|
1255
|
-
{ ...e, ...t }
|
|
1256
|
-
);
|
|
1257
|
-
});
|
|
1258
|
-
}
|
|
1259
|
-
async sendNotification(t, e) {
|
|
1260
|
-
if (!this.features.notification)
|
|
1261
|
-
throw new Error("Notification is not supported");
|
|
1262
|
-
if (Notification.permission === "default" && await Notification.requestPermission() !== "granted")
|
|
1263
|
-
throw new Error("Notification permission is not granted");
|
|
1264
|
-
if (Notification.permission !== "granted")
|
|
1265
|
-
throw new Error("Notification permission is not granted");
|
|
1266
|
-
return new Notification(t, {
|
|
1267
|
-
icon: e.icon,
|
|
1268
|
-
badge: e.badge,
|
|
1269
|
-
...e
|
|
1270
|
-
});
|
|
1271
|
-
}
|
|
1272
|
-
async registerServiceWorker(t) {
|
|
1273
|
-
if (!this.features.serviceWorker)
|
|
1274
|
-
throw new Error("Service Worker is not supported");
|
|
1275
|
-
try {
|
|
1276
|
-
const e = await navigator.serviceWorker.register(t);
|
|
1277
|
-
return console.log("Service Worker registered with scope:", e), e;
|
|
1278
|
-
} catch (e) {
|
|
1279
|
-
throw console.error("Service Worker registration failed:", e), e;
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
async shareContent(t) {
|
|
1283
|
-
if (this.features.webShare)
|
|
1284
|
-
try {
|
|
1285
|
-
return await navigator.share(t), !0;
|
|
1286
|
-
} catch (e) {
|
|
1287
|
-
return e instanceof Error && e.name != "AbortError" && console.error("Error sharing content:", e), !1;
|
|
1288
|
-
}
|
|
1289
|
-
else
|
|
1290
|
-
try {
|
|
1291
|
-
return await navigator.clipboard.writeText(
|
|
1292
|
-
t.url || t.text || ""
|
|
1293
|
-
), this.sendNotification("Copied to clipboard", {
|
|
1294
|
-
body: "Link copied to clipboard"
|
|
1295
|
-
}), !0;
|
|
1296
|
-
} catch (e) {
|
|
1297
|
-
return console.error("Error copying to clipboard:", e), !1;
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1104
|
+
function Z(r, t, e) {
|
|
1105
|
+
let s = -1, i = r.length, n;
|
|
1106
|
+
for (; i - s > 1; )
|
|
1107
|
+
n = i - (i - s) >> 1, e(r[n], t) ? i = n : s = n;
|
|
1108
|
+
return i;
|
|
1300
1109
|
}
|
|
1301
1110
|
String.prototype.pointLength = function() {
|
|
1302
1111
|
let r = 0;
|
|
@@ -1359,39 +1168,38 @@ Object.defineProperties(Element.prototype, {
|
|
|
1359
1168
|
});
|
|
1360
1169
|
Text.prototype.surround = function(r = "strong", t = "") {
|
|
1361
1170
|
if (!this.nodeValue || !r || !t) return null;
|
|
1362
|
-
const s = r.split("."), i = s[0], n = s.slice(1).join(" "),
|
|
1363
|
-
if (
|
|
1364
|
-
const
|
|
1365
|
-
|
|
1366
|
-
const
|
|
1367
|
-
return n && (
|
|
1171
|
+
const s = r.split("."), i = s[0], n = s.slice(1).join(" "), h = this.textContent.indexOf(t);
|
|
1172
|
+
if (h < 0) return null;
|
|
1173
|
+
const o = document.createRange();
|
|
1174
|
+
o.setStart(this, h), o.setEnd(this, h + t.length);
|
|
1175
|
+
const c = document.createElement(i);
|
|
1176
|
+
return n && (c.className = n), o.surroundContents(c), c;
|
|
1368
1177
|
};
|
|
1369
1178
|
export {
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
v as DomHelper,
|
|
1179
|
+
W as BitPerm,
|
|
1180
|
+
Q as Color,
|
|
1181
|
+
R as Dictionary,
|
|
1374
1182
|
I as Emitter,
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1183
|
+
$ as Graph,
|
|
1184
|
+
T as LIS,
|
|
1185
|
+
j as LRU,
|
|
1186
|
+
g as Line,
|
|
1187
|
+
U as LinkedList,
|
|
1380
1188
|
E as Matrix,
|
|
1381
1189
|
q as MaxHeap,
|
|
1382
|
-
|
|
1190
|
+
F as MemoizeMap,
|
|
1383
1191
|
O as MinHeap,
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1192
|
+
D as MinStack,
|
|
1193
|
+
G as Num,
|
|
1194
|
+
u as Point,
|
|
1195
|
+
V as Queue,
|
|
1196
|
+
B as Roman,
|
|
1197
|
+
z as Stack,
|
|
1198
|
+
X as Str,
|
|
1391
1199
|
p as Triangle,
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1200
|
+
y as Vector,
|
|
1201
|
+
Z as binarySearchTemplate,
|
|
1202
|
+
H as isValidBracket,
|
|
1203
|
+
K as singleton,
|
|
1204
|
+
_ as sleep
|
|
1397
1205
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
`;return t}}class y{_data;static zero(t){return new y(...Array(t).fill(0))}constructor(...t){this._data=t}get dimension(){return this._data.length}get norm(){return Math.hypot(...this._data)}getItem(t){return this._data[t]}normalize(){const t=this.norm;if(t===0)throw new Error("Cannot normalize a zero vector");const e=this._data.map(i=>i/t);return new y(...e)}add(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to add");const e=this._data.map((i,s)=>i+t._data[s]);return new y(...e)}sub(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to subtract");const e=this._data.map((i,s)=>i-t._data[s]);return new y(...e)}mul(t){return new y(...this._data.map(e=>e*t))}dot(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to dot product");return this._data.reduce((e,i,s)=>e+i*t._data[s],0)}pos(){return this.mul(1)}neg(){return this.mul(-1)}}class x{_matrix;static zero(t,e){return new x(Array.from({length:t},()=>Array.from({length:e},()=>0)))}constructor(t){this._matrix=t}get shape(){return[this._matrix.length,this._matrix[0].length]}get row(){return this.shape[0]}get col(){return this.shape[1]}get size(){return this.row*this.col}rowVector(t){return new y(...this._matrix[t])}colVector(t){return new y(...this._matrix.map(e=>e[t]))}getItem(t){return this._matrix[t[0]][t[1]]}setItem(t,e){return this._matrix[t[0]][t[1]]=e,this}mul(t){return new x(this._matrix.map(e=>e.map(i=>i*t)))}div(t){return this.mul(1/t)}add(t){if(this.row!==t.row||this.col!==t.col)throw new Error("Matrix dimensions do not match");return new x(this._matrix.map((e,i)=>e.map((s,n)=>s+t.getItem([i,n]))))}sub(t){return this.add(t.neg())}pos(){return this.mul(1)}neg(){return this.mul(-1)}mulVector(t){if(this.col!==t.dimension)throw new Error("Matrix dimensions do not match");return new x(this._matrix.map(e=>e.map((i,s)=>i*t.getItem(s))))}mulMatrix(t){if(this.col!==t.row)throw new Error("Matrix dimensions do not match");const e=x.zero(this.row,t.col);for(let i=0;i<this.row;i++){const s=this.rowVector(i);for(let n=0;n<this.col;n++)e.setItem([i,n],s.dot(t.colVector(n)))}return e}}class c{static distance(t,e){return Math.hypot(e.x-t.x,e.y-t.y)}x;y;constructor(t,e){this.x=t,this.y=e}distanceTo(t){return c.distance(this,t)}}class f{static EPSILON=1e-10;static sloped(t,e=f.EPSILON){const i=t.p2.x-t.p1.x,s=t.p2.y-t.p1.y;return Math.abs(i)<e?Math.abs(s)<e?0:null:s/i}static isParallel(t,e,i=f.EPSILON){const s=f.sloped(t),n=f.sloped(e);return s===null&&n===null?!0:s===null||n===null?!1:Math.abs(s-n)<i}static getIntersection(t,e,i=f.EPSILON){if(f.isParallel(t,e))return null;const s=t.p1.x,n=t.p1.y,a=t.p2.x,u=t.p2.y,l=e.p1.x,m=e.p1.y,w=e.p2.x,h=e.p2.y,d=(s-a)*(m-h)-(n-u)*(l-w);if(Math.abs(d)<i)return null;const g=((s-l)*(m-h)-(n-m)*(l-w))/d,A=-((s-a)*(n-m)-(n-u)*(s-l))/d;if(g>=0&&g<=1&&A>=0&&A<=1){const Y=s+g*(a-s),tt=n+g*(u-n);return new c(Y,tt)}return null}static isIntersecting(t,e){return f.getIntersection(t,e)!==null}static distanceToPoint(t,e,i=f.EPSILON){const s=e.x-t.p1.x,n=e.y-t.p1.y,a=t.p2.x-t.p1.x,u=t.p2.y-t.p1.y,l=s*a+n*u,m=a*a+u*u;let w=-1;m>i&&(w=l/m);let h,d;w<0?(h=t.p1.x,d=t.p1.y):w>1?(h=t.p2.x,d=t.p2.y):(h=t.p1.x+w*a,d=t.p1.y+w*u);const g=e.x-h,A=e.y-d;return Math.hypot(g+A)}p1;p2;constructor(t,e){this.p1=t,this.p2=e}get length(){const t=this.p2.x-this.p1.x,e=this.p2.y-this.p1.y;return Math.sqrt(t*t+e*e)}get midpoint(){const t=(this.p1.x+this.p2.x)/2,e=(this.p1.y+this.p2.y)/2;return new c(t,e)}get angle(){return Math.atan2(this.p2.y-this.p1.y,this.p2.x-this.p1.x)}containsPoint(t,e=f.EPSILON){const i=(t.x-this.p1.x)*(this.p2.y-this.p1.y)-(t.y-this.p1.y)*(this.p2.x-this.p1.x);return Math.abs(i)>e?!1:(t.x-this.p1.x)*(t.x-this.p2.x)+(t.y-this.p1.y)*(t.y-this.p2.y)<=e}get direction(){const t=this.length;if(t<f.EPSILON)return new c(0,0);const e=(this.p2.x-this.p1.x)/t,i=(this.p2.y-this.p1.y)/t;return new c(e,i)}get start(){return this.p1}get end(){return this.p2}}class R{static EPSILON=1e-10;name;constructor(t){this.name=t}}class p extends R{static isValid(t,e,i){return t<=0||e<=0||i<=0?!1:t+e>i&&t+i>e&&e+i>t}static area(t,e,i){if(!p.isValid(t,e,i))throw new Error("Invalid triangle");const s=(t+e+i)/2;return Math.sqrt(s*(s-t)*(s-e)*(s-i))}static getType(t,e,i){if(!p.isValid(t,e,i))throw new Error("Invalid triangle sides");const s=[t,e,i].sort((l,m)=>l-m),[n,a,u]=s;return Math.abs(n-a)<p.EPSILON&&Math.abs(a-u)<p.EPSILON?"equilateral":Math.abs(n-a)<p.EPSILON||Math.abs(a-u)<p.EPSILON?"isosceles":"scalene"}static getAngles(t,e,i){if(!p.isValid(t,e,i))throw new Error("Invalid triangle sides");const s=Math.acos((e*e+i*i-t*t)/(2*e*i)),n=Math.acos((t*t+i*i-e*e)/(2*t*i)),a=Math.PI-s-n;return[s,n,a]}p1;p2;p3;constructor(t,e,i,s="triangle"){if(super(s),this.p1=t,this.p2=e,this.p3=i,this.areCollinear())throw new Error("Points are collinear, cannot form a triangle")}areCollinear(){return Math.abs((this.p2.x-this.p1.x)*(this.p3.y-this.p1.y)-(this.p3.x-this.p1.x)*(this.p2.y-this.p1.y))<R.EPSILON}get side(){return[c.distance(this.p1,this.p2),c.distance(this.p2,this.p3),c.distance(this.p3,this.p1)]}perimeter(){return p.isValid(this.side[0],this.side[1],this.side[2]),this.side.reduce((t,e)=>t+e,0)}area(){const[t,e,i]=this.side;return p.area(t,e,i)}get type(){const[t,e,i]=this.side;return p.getType(t,e,i)}get angles(){const[t,e,i]=this.side;return p.getAngles(t,e,i)}get centroid(){return new c((this.p1.x+this.p2.x+this.p3.x)/3,(this.p1.y+this.p2.y+this.p3.y)/3)}get incenter(){const[t,e,i]=this.side,s=this.perimeter()/2,n=(t*this.p1.x+e*this.p2.x+i*this.p3.x)/s,a=(t*this.p1.y+e*this.p2.y+i*this.p3.y)/s;return new c(n,a)}get circumcenter(){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));if(Math.abs(t)<p.EPSILON)throw new Error("Cannot calculate circumcenter for collinear points");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,i=((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;return new c(e,i)}containsPoint(t){const e=p.area(c.distance(t,this.p1),c.distance(t,this.p2),c.distance(this.p1,this.p2)),i=p.area(c.distance(t,this.p2),c.distance(t,this.p3),c.distance(this.p2,this.p3)),s=p.area(c.distance(t,this.p3),c.distance(t,this.p1),c.distance(this.p3,this.p1));return Math.abs(e+i+s-this.area())<p.EPSILON}}function T(r){return new Promise(t=>setTimeout(t,r))}function _(r){const t=[],e={"(":")","[":"]","{":"}"},i=new Set(Object.values(e));for(const s of r)if(s in e)t.push(e[s]);else if(i.has(s)&&s!==t.pop())return!1;return t.length===0}function P(r){return r!==null&&(typeof r=="object"||typeof r=="function")}class W{map=new Map;weakMap=new WeakMap;set(t,e){P(t)?this.weakMap.set(t,e):this.map.set(t,e)}get(t){return P(t)?this.weakMap.get(t):this.map.get(t)}has(t){return P(t)?this.weakMap.has(t):this.map.has(t)}}function F(r){if(!r.length)return[];const t=[[r[0]]];for(let i=1,s=r.length;i<s;i++){const n=r[i];e(n)}function e(i){for(let s=t.length-1;s>=0;s--){const n=t[s],a=n[t[s].length-1];if(a<i){t[s+1]=[...n,i];break}else a>i&&s===0&&(t[s]=[i])}}return t[t.length-1]}class B{static ROMAN_MAP=new Map([["M",1e3],["CM",900],["D",500],["CD",400],["C",100],["XC",90],["L",50],["XL",40],["X",10],["IX",9],["V",5],["IV",4],["I",1]]);static toInteger(t){if(t.length===0)throw new Error("Input cannot be empty");const e=new Set(["I","V","X","L","C","D","M"]);for(const a of t)if(!e.has(a))throw new Error(`Invalid Roman numeral character: ${a}`);let i=0,s=0;for(;s<t.length;){const a=t.slice(s,s+2);if(this.ROMAN_MAP.has(a))i+=this.ROMAN_MAP.get(a),s+=2;else{const u=t[s],l=this.ROMAN_MAP.get(u);if(!l)throw new Error(`Invalid Roman numeral sequence at position ${s}`);i+=l,s+=1}}if(this.toRoman(i)!==t)throw new Error("Invalid Roman numeral sequence");return i}static toRoman(t){if(t<=0||t>=4e3)throw new Error("Number must be between 1 and 3999");if(!Number.isInteger(t))throw new Error("Number must be an integer");let e="";for(const[i,s]of this.ROMAN_MAP)for(;t>=s;)e+=i,t-=s;return e}}class G{static isValidPositiveInteger(t){return Number.isInteger(t)&&t>0&&t<=Number.MAX_SAFE_INTEGER}static isPowerOfTwo(t){return t>0&&(t&t-1)===0}static isOdd(t){return t%2===1||t%2===-1}static factorial(t){if(!this.isValidPositiveInteger(t))throw new Error("Input must be a non-negative integer");if(t<2)return 1;let e=1;for(let i=2;i<=t;i++)e*=i;return e}static fibonacci(t,e=1,i=1){if(!this.isValidPositiveInteger(t))throw new Error("Input must be a non-negative integer");return t<2?i:this.fibonacci(t-1,i,i+e)}static fibonacciIterative(t){if(!this.isValidPositiveInteger(t))throw new Error("Input must be a non-negative integer");let e=1,i=1;for(let s=2;s<t;s++)[e,i]=[i,e+i];return t===0?0:i}static getPercentWithPrecision(t,e=2){if(!Array.isArray(t)||t.length===0)return[];if(e<0||!Number.isInteger(e))throw new Error("Precision must be a non-negative integer");const i=t.reduce((h,d)=>h+d,0);if(i===0)return t.map(()=>"0%");const n=100*Math.pow(10,e),a=t.map(h=>h/i*n),u=a.map(h=>Math.floor(h)),l=a.map((h,d)=>h-u[d]);let m=u.reduce((h,d)=>h+d,0),w=n-m;for(;w>0;){let h=-1,d=-1;for(let g=0;g<l.length;g++)l[g]>d&&(d=l[g],h=g);if(h===-1)break;u[h]++,l[h]=0,w--}return u.map(h=>`${(h/n*100).toFixed(e)}%`)}static fastSqrt(t){if(t<0)throw new Error("n must be a non-negative number");const e=.5*t;let i=new BigInt64Array(new Float32Array([t]).buffer)[0];i=0x1ff7a3bea91d9b1bn+(i>>1n);let s=new Float64Array(new BigInt64Array([i]).buffer)[0];return s=s*.5+e/s,s=s*.5+e/s,s=s*.5+e/s,s}static middle(t,e){return e-(e-t>>1)}static gcd(t,e){return e===0?t:this.gcd(e,t%e)}static lcm(t,e){return t*e/this.gcd(t,e)}static isPrime(t){if(t<=1)return!1;for(let e=2;e<=Math.sqrt(t);e++)if(t%e===0)return!1;return!0}static isPalindrome(t){if(t<0||t%10===0&&t!==0)return!1;let e=0,i=t;for(;t>0;){const s=t%10;e=e*10+s,t=Math.floor(t/10)}return i===e}static isArmstrong(t){const e=t.toString(),i=e.length;let s=0;for(let n=0;n<i;n++)s+=Math.pow(parseInt(e[n]),i);return s===t}static isPerfect(t){let e=0;for(let i=1;i<t;i++)t%i===0&&(e+=i);return e===t}static scale(t,e,i){if(e[0]>=e[1]||i[0]>=i[1])throw new Error("Invalid range");const s=e[1]-e[0];return(t-e[0])*((i[1]-i[0])/s)+i[0]}static randomInt(t,e){return Math.floor(Math.random()*(e-t+1))+t}static floatEqual(t,e,i=1e-6){return Math.abs(t-e)<i}static isSameSign(t,e){return t>=0&&e>=0||t<=0&&e<=0}}class X{static READ=1;static WRITE=2;static SHARE=4;static DELETE=8;static CREATE=16;static include(t,e){return(t&e)===e}static add(t,e){return t|e}static remove(t,e){return t&~e}static toggle(t,e){return t^e}}class Q{static longestCommonPrefix(t){if(!t.length)return"";let e=t[0];for(let i=1;i<t.length;i++)for(;!t[i].startsWith(e);)if(e=e.slice(0,-1),e==="")return"";return e}static uuid(t){return typeof t=="number"?(t^Math.random()*16>>t/4).toString(16):(9987e3+-1e11).toString().replace(/[018]/g,e=>{const i=parseInt(e,10);return this.uuid(i)})}}class K{static isValidHex(t){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t)}static isValidRGB(t){return/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.test(t)}}function Z(r){let t;const e=new Proxy(r,{construct(i,s,n){return t||(t=Reflect.construct(i,s,n)),t}});return r.prototype.constructor=e,e}const b={AUTH_UNAUTHORIZED:"未授权事件",AUTH_LOGIN_SUCCESS:"登录成功事件",AUTH_LOGOUT:"注销事件",AUTH_TOKEN_EXPIRED:"令牌过期事件",REQUEST_ERROR:"请求错误事件",REQUEST_TIMEOUT:"请求超时事件",REQUEST_NETWORK_ERROR:"网络错误事件",UI_SHOW_LOADING:"显示加载事件",UI_HIDE_LOADING:"隐藏加载事件",UI_SHOW_MESSAGE:"显示消息事件"};class I{static instance=null;listeners={};debugMode;constructor(t=!1){this.debugMode=t,Object.keys(b).forEach(e=>{this.listeners[e]=new Set})}static getInstance(t){return I.instance||(I.instance=new I(t)),I.instance}on(t,e){this.debugLog(`添加事件监听: ${b[t]}`),this.listeners[t].add(e)}emit(t,e){this.debugLog(`触发事件: ${b[t]}`,e),this.listeners[t].forEach(i=>{try{i(e)}catch(s){console.error(`事件 ${b[t]} 处理出错:`,s)}})}off(t,e){this.debugLog(`移除事件监听: ${b[t]}`),this.listeners[t].delete(e)}once(t,e){this.debugLog(`添加一次性事件监听: ${b[t]}`);const i=s=>{e(s),this.off(t,i)};this.on(t,i)}clear(){this.debugLog("清除所有事件监听器"),Object.values(this.listeners).forEach(t=>t.clear())}getListenerCount(t){return this.listeners[t].size}debugLog(t,e){this.debugMode&&console.log(`[EventEmitter] ${t}`,e||"")}}const M={scriptRegex:/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,javascriptRegex:/javascript:/gi,eventHandlerRegex:/on\w+\s*=/gi,allowedTags:new Set(["div","span","p","a","img","button","input","form","label","select","option","textarea","ul","ol","li","table","tr","td","th","thead","tbody","tfoot","h1","h2","h3","h4","h5","h6","hr","br","section","article","nav","header","footer","main","aside","figure","figcaption"]),allowedAttributes:new Set(["class","id","href","src","alt","title"])};class v{static instance;constructor(){}static getInstance(){return v.instance||(v.instance=new v),v.instance}createElement(t,e={},i=""){if(!M.allowedTags.has(t.toLowerCase()))throw new Error(`Unsupported tag: ${t}`);const s=document.createElement(t);return this._processAttributes(s,e),this._processContent(s,i),s}createBatch(t,e){const i=document.createDocumentFragment();t.forEach(s=>{const n=this.createElement(s.tag,s.attributes||{},s.content||"");i.appendChild(n)}),e.appendChild(i)}setHtml(t,e){const i=this._sanitizeHtml(e);t.innerHTML=i}_processAttributes(t,e){Object.entries(e).forEach(([i,s])=>{if(!M.allowedAttributes.has(i)&&!i.startsWith("data-")){console.warn(`Potentially unsafe attribute: ${i}`);return}if(typeof s=="function")i.startsWith("on")&&t.addEventListener(i.slice(2).toLowerCase(),s);else switch(i){case"className":t.className=s;break;case"dataset":Object.assign(t.dataset,s);break;case"style":Object.assign(t.style,s);break;default:t.setAttribute(i,s)}})}_processContent(t,e){typeof e=="string"?t.textContent=e:e instanceof Node?t.appendChild(e):Array.isArray(e)&&e.forEach(i=>{typeof i=="string"?t.appendChild(document.createTextNode(i)):t.appendChild(i)})}_sanitizeHtml(t){return t.replace(M.scriptRegex,"").replace(M.javascriptRegex,"").replace(M.eventHandlerRegex,"")}}class J{features;constructor(){this.features=this.detectFeatures()}detectFeatures(){return{geolocation:"geolocation"in navigator,notification:"Notification"in window,serviceWorker:"serviceWorker"in navigator,webShare:"share"in navigator,deviceOrientation:"DeviceOrientationEvent"in window,battery:"getBattery"in navigator,online:"onLine"in navigator}}async getLocation(t={}){if(!this.features.geolocation)throw new Error("Geolocation is not supported");const e={enableHighAccuracy:!0,timeout:10*1e3,maximumAge:300*1e3};return new Promise((i,s)=>{navigator.geolocation.getCurrentPosition(n=>i({latitude:n.coords.latitude,longitude:n.coords.longitude,accuracy:n.coords.accuracy,timstamp:n.timestamp}),n=>{const a={1:"User denied the request for Geolocation.",2:"Position information is unavailable.",3:"The request to get user location timed out."};s(new Error(a[n.code]||"Unknown error"))},{...e,...t})})}async sendNotification(t,e){if(!this.features.notification)throw new Error("Notification is not supported");if(Notification.permission==="default"&&await Notification.requestPermission()!=="granted")throw new Error("Notification permission is not granted");if(Notification.permission!=="granted")throw new Error("Notification permission is not granted");return new Notification(t,{icon:e.icon,badge:e.badge,...e})}async registerServiceWorker(t){if(!this.features.serviceWorker)throw new Error("Service Worker is not supported");try{const e=await navigator.serviceWorker.register(t);return console.log("Service Worker registered with scope:",e),e}catch(e){throw console.error("Service Worker registration failed:",e),e}}async shareContent(t){if(this.features.webShare)try{return await navigator.share(t),!0}catch(e){return e instanceof Error&&e.name!="AbortError"&&console.error("Error sharing content:",e),!1}else try{return await navigator.clipboard.writeText(t.url||t.text||""),this.sendNotification("Copied to clipboard",{body:"Link copied to clipboard"}),!0}catch(e){return console.error("Error copying to clipboard:",e),!1}}}String.prototype.pointLength=function(){let r=0;for(let t=0,e=this.length;t<e;){const i=this.codePointAt(t);t+=i>65535?2:1,r++}return r},String.prototype.pointAt=function(r){if(r>=this.pointLength())return;let t=0;for(let e=0,i=this.length;e<i;){const s=this.codePointAt(e);if(!s)return;if(t===r)return String.fromCodePoint(s);e+=s>65535?2:1,t++}},String.prototype.sliceByPoint=function(r,t=this.pointLength()){let e="";for(let i=r;i<t;i++)e+=this.pointAt(i);return e},RegExp.escape=function(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},Element.prototype.farthest=function(r){if(typeof r!="string"||!r)return null;let t=null,e=this;for(;e;){const i=e.closest(r);if(!i)break;t=i,e=i.parentElement}return t},Object.defineProperties(Element.prototype,{firstElement:{get:function(){if(!this.children.length)return null;let r=this.firstElementChild,t=null;for(;r;)t=r,r=r.firstElementChild;return t}},lastElement:{get:function(){if(!this.children.length)return null;let r=this.lastElementChild,t=null;for(;r;)t=r,r=r.lastElementChild;return t}}}),Text.prototype.surround=function(r="strong",t=""){if(!this.nodeValue||!r||!t)return null;const i=r.split("."),s=i[0],n=i.slice(1).join(" "),a=this.textContent.indexOf(t);if(a<0)return null;const u=document.createRange();u.setStart(this,a),u.setEnd(this,a+t.length);const l=document.createElement(s);return n&&(l.className=n),u.surroundContents(l),l},o.BitPerm=X,o.Color=K,o.Dictionary=O,o.DomHelper=v,o.Emitter=I,o.Graph=H,o.LIS=F,o.LRU=D,o.Line=f,o.LinkedList=$,o.Matrix=x,o.MaxHeap=j,o.MemoizeMap=W,o.MinHeap=N,o.MinStack=z,o.Num=G,o.Point=c,o.Queue=S,o.Roman=B,o.Stack=V,o.Str=Q,o.Triangle=p,o.Vector=y,o.WebAppManager=J,o.isValidBracket=_,o.singleton=Z,o.sleep=T,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(a,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(a=typeof globalThis<"u"?globalThis:a||self,b(a["jc-structure"]={}))})(this,(function(a){"use strict";class b{items={};count=0;lowestCount=0;constructor(){}dequeue(){if(this.isEmpty())return;const t=this.items[this.lowestCount];return delete this.items[this.lowestCount],this.lowestCount++,t}enqueue(...t){if(t.length===0)return this;if(t.length===1){const e=t[0];return Array.isArray(e)?this.batchEnqueue(e):this.enqueueItem(e)}for(const e of t)Array.isArray(e)?this.batchEnqueue(e):this.enqueueItem(e);return this}batchEnqueue(t){return t.filter(s=>this.isValidItem(s)).forEach(s=>{this.isValidItem(s)&&(this.items[this.count]=s,this.count++)}),this}enqueueItem(t){if(!this.isValidItem(t))throw new Error("Invalid item");return this.items[this.count]=t,this.count++,this}isValidItem(t){return t!=null}front(){return this.isEmpty()?void 0:this.items[this.lowestCount]}isEmpty(){return this.size()===0}size(){return this.count-this.lowestCount}clear(){this.items={},this.count=0,this.lowestCount=0}toString(){return this.isEmpty()?"":`Queue(size: ${this.size()}):[${this.items[this.lowestCount]},...rest]`}}class C{items={};count=0;constructor(){}pop(){if(this.isEmpty())return;this.count--;const t=this.items[this.count];return delete this.items[this.count],t}push(...t){if(t.length===0)return this;if(t.length===1){const e=t[0];return Array.isArray(e)?this.addItems(e):this.addItem(e)}for(const e of t)Array.isArray(e)?this.addItems(e):this.addItem(e);return this}addItem(t){if(!this.isValidItem(t))throw new Error("Invalid item: item cannot be null or undefined");return this.items[this.count]=t,this.count++,this}addItems(t){return t.filter(s=>this.isValidItem(s)).forEach(s=>{this.items[this.count]=s,this.count++}),this}isValidItem(t){return t!=null}peek(){return this.isEmpty()?void 0:this.items[this.count-1]}isEmpty(){return this.count===0}size(){return this.count}clear(){this.items={},this.count=0}toString(){return this.isEmpty()?"":`Stack(count: ${this.count}):[${this.items[this.count-1]},...rest]`}}class R{stack=[];minStack=[];push(t){this.stack.push(t),(this.minStack.length===0||t<=this.minStack[this.minStack.length-1])&&this.minStack.push(t)}pop(){const t=this.stack.pop();return t===this.minStack[this.minStack.length-1]&&this.minStack.pop(),t}peek(){return this.stack[this.stack.length-1]}getMin(){return this.minStack[this.minStack.length-1]}isEmpty(){return this.size()===0}size(){return this.stack.length}clear(){this.stack=[],this.minStack=[]}toString(){return this.isEmpty()?"":`MinStack(count: ${this.size()}):[${this.getMin()},...rest]`}}function A(r,t){return r===t?0:r<t?-1:1}class E{heap=[];compareFn;constructor(t=A){this.compareFn=t}static getLeftIndex(t){return 2*t+1}static getRightIndex(t){return 2*t+2}static getParentIndex(t){return t===0?void 0:Math.floor((t-1)/2)}static swap(t,e,s){[t[e],t[s]]=[t[s],t[e]]}find(){return this.isEmpty()?void 0:this.heap[0]}size(){return this.heap.length}isEmpty(){return this.size()===0}clear(){this.heap=[]}toString(){return this.heap.toString()}}class P extends E{insert(t){return t?!1:(this.heap.push(t),this.siftUp(this.heap.length-1),!0)}extract(){if(this.isEmpty())return;if(this.heap.length===1)return this.heap.shift();const t=this.heap[0];return this.heap[0]=this.heap.pop(),this.siftDown(0),t}siftUp(t){let e=t,s=E.getLeftIndex(e),i=E.getRightIndex(e),n=this.size();s<n&&this.compareFn(this.heap[e],this.heap[s])===-1&&(e=s),i<n&&this.compareFn(this.heap[e],this.heap[i])===1&&(e=i),e!==t&&(E.swap(this.heap,t,e),this.siftUp(e))}siftDown(t){let e=E.getParentIndex(t);for(;t>0&&e&&this.compareFn(this.heap[e],this.heap[t])===1;)E.swap(this.heap,e,t),t=e,e=E.getParentIndex(t)}}class V extends P{constructor(t=(e,s)=>A(s,e)){super(t)}}function z(r){return{value:r}}class D{capacity;length=0;head=null;tail=null;lookup=new Map;reverseLookup=new Map;constructor(t=10){this.capacity=t}prepend(t){this.head?(t.next=this.head,this.head.prev=t,this.head=t):this.head=this.tail=t}detach(t){t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),this.head===t&&(this.head=this.head.next||null),this.tail===t&&(this.tail=this.tail.prev||null),t.next=void 0,t.prev=void 0}trimCache(){if(this.length<=this.capacity)return;const t=this.tail;this.detach(t);const e=this.reverseLookup.get(t);this.lookup.delete(e),this.reverseLookup.delete(t),this.length--}get(t){const e=this.lookup.get(t);if(e)return this.detach(e),this.prepend(e),e.value}update(t,e){let s=this.lookup.get(t);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)}}class k{value;next=void 0}class j{count=0;head=void 0;constructor(){}indexOf(t){let e=this.head,s=0,i=!1;for(;e;){if(this.equals(e.value,t)){i=!0;break}s++,e=e.next}return i?s:-1}equals(t,e){return!1}getElementAt(t){if(t<0||t>=this.count)return;if(t===0)return this.head;let e=this.head;for(let s=0;s<t;s++)e=e?.next;return e}getValueAt(t){return this.getElementAt(t)?.value}insert(t,e){let s=new k;if(s.value=t,e>this.count||e<0)throw new Error("index error");this.count++;let i,n;if(e===0){s.next=this.head,this.head=s;return}i=this.getElementAt(e-1),n=i.next,i.next=s,s.next=n}push(t){let e=new k;if(e.value=t,this.count++,this.isEmpty()){this.head=e;return}let s=this.getElementAt(this.count-1);s.next=e}remove(t){const e=this.indexOf(t);return e===-1?void 0:this.removeAt(e)}removeAt(t){if(this.isEmpty()||t<0||t>=this.count)return;let e=this.getElementAt(t),s=this.getElementAt(t-1),i=e?.next;return t===0&&(this.head=i),s&&(s.next=i),this.count--,e?.value}isEmpty(){return this.count===0}size(){return this.count}clear(){this.count=0,this.head=void 0}toString(){let t="",e=this.head;for(;e;)t+=e.value,t+=",",e=e.next;return t=t.slice(0,-1),t}}class q{key;value;constructor(t,e){this.key=t,this.value=e}}function L(r,t={emptyString:!1,zeroNumber:!1}){return r==null?!(t.emptyString&&r===""||t.zeroNumber&&r===0):!1}class N{table=[];constructor(){}getItemIndex(t){for(let e=0,s=this.table.length;e<s;e++)if(this.table[e].key===t)return e;return-1}set(t,e){if(L(t))throw new Error("key is required");if(L(e))throw new Error("value is required");if(this.has(t)){let s=this.getItemIndex(t);this.table[s].value=e}else{const s=new q(t,e);this.table.push(s)}}remove(t){if(this.has(t)){let e=this.getItemIndex(t);return this.table.splice(e,1)[0]}}has(t){return this.getItemIndex(t)!==-1}get(t){if(this.has(t)){let e=this.getItemIndex(t);return this.table[e]}}keys(){return this.table.map(t=>t.key)}values(){return this.table.map(t=>t.value)}keyValues(){return this.table.map(t=>[t.key,t.value])}forEach(t){for(let e=0,s=this.size();e<s;e++){let i=this.table[e];if(!t(i.key,i.value))break}}isEmpty(){return!this.size()}size(){return this.table.length}clear(){this.table=[]}toString(){let t="";for(let e=0,s=this.table.length;e<s;e++)t+=this.table[e].toString(),t+=",";return t=t.slice(0,-1),t}}class U{isDirected;vertices;adjList;constructor(t=!1){this.isDirected=t,this.vertices=[],this.adjList=new N}addVertex(t){this.vertices.includes(t)||(this.vertices.push(t),this.adjList.set(t,[]))}addEdge(t,e){this.adjList.get(t)||this.addVertex(t),this.adjList.get(e)||this.addVertex(e),this.adjList.get(t)?.value.indexOf(e)===-1&&this.adjList.get(t)?.value.push(e),this.isDirected||this.adjList.get(e)?.value.indexOf(t)===-1&&this.adjList.get(e)?.value.push(t)}getVertices(){return this.vertices}getAdjacencyList(){return this.adjList}toString(){let t="";for(let e=0;e<this.vertices.length;e++)t+=this.vertices[e]+"-->",t+=this.adjList.get(this.vertices[e])?.toString()||"",t+=`
|
|
2
|
+
`;return t}}class w{_data;static zero(t){return new w(...Array(t).fill(0))}constructor(...t){this._data=t}get dimension(){return this._data.length}get norm(){return Math.hypot(...this._data)}getItem(t){return this._data[t]}normalize(){const t=this.norm;if(t===0)throw new Error("Cannot normalize a zero vector");const e=this._data.map(s=>s/t);return new w(...e)}add(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to add");const e=this._data.map((s,i)=>s+t._data[i]);return new w(...e)}sub(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to subtract");const e=this._data.map((s,i)=>s-t._data[i]);return new w(...e)}mul(t){return new w(...this._data.map(e=>e*t))}dot(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to dot product");return this._data.reduce((e,s,i)=>e+s*t._data[i],0)}pos(){return this.mul(1)}neg(){return this.mul(-1)}}class x{_matrix;static zero(t,e){return new x(Array.from({length:t},()=>Array.from({length:e},()=>0)))}constructor(t){this._matrix=t}get shape(){return[this._matrix.length,this._matrix[0].length]}get row(){return this.shape[0]}get col(){return this.shape[1]}get size(){return this.row*this.col}rowVector(t){return new w(...this._matrix[t])}colVector(t){return new w(...this._matrix.map(e=>e[t]))}getItem(t){return this._matrix[t[0]][t[1]]}setItem(t,e){return this._matrix[t[0]][t[1]]=e,this}mul(t){return new x(this._matrix.map(e=>e.map(s=>s*t)))}div(t){return this.mul(1/t)}add(t){if(this.row!==t.row||this.col!==t.col)throw new Error("Matrix dimensions do not match");return new x(this._matrix.map((e,s)=>e.map((i,n)=>i+t.getItem([s,n]))))}sub(t){return this.add(t.neg())}pos(){return this.mul(1)}neg(){return this.mul(-1)}mulVector(t){if(this.col!==t.dimension)throw new Error("Matrix dimensions do not match");return new x(this._matrix.map(e=>e.map((s,i)=>s*t.getItem(i))))}mulMatrix(t){if(this.col!==t.row)throw new Error("Matrix dimensions do not match");const e=x.zero(this.row,t.col);for(let s=0;s<this.row;s++){const i=this.rowVector(s);for(let n=0;n<this.col;n++)e.setItem([s,n],i.dot(t.colVector(n)))}return e}}class u{static distance(t,e){return Math.hypot(e.x-t.x,e.y-t.y)}x;y;constructor(t,e){this.x=t,this.y=e}distanceTo(t){return u.distance(this,t)}}class f{static EPSILON=1e-10;static sloped(t,e=f.EPSILON){const s=t.p2.x-t.p1.x,i=t.p2.y-t.p1.y;return Math.abs(s)<e?Math.abs(i)<e?0:null:i/s}static isParallel(t,e,s=f.EPSILON){const i=f.sloped(t),n=f.sloped(e);return i===null&&n===null?!0:i===null||n===null?!1:Math.abs(i-n)<s}static getIntersection(t,e,s=f.EPSILON){if(f.isParallel(t,e))return null;const i=t.p1.x,n=t.p1.y,h=t.p2.x,c=t.p2.y,l=e.p1.x,g=e.p1.y,y=e.p2.x,o=e.p2.y,d=(i-h)*(g-o)-(n-c)*(l-y);if(Math.abs(d)<s)return null;const m=((i-l)*(g-o)-(n-g)*(l-y))/d,M=-((i-h)*(n-g)-(n-c)*(i-l))/d;if(m>=0&&m<=1&&M>=0&&M<=1){const Z=i+m*(h-i),J=n+m*(c-n);return new u(Z,J)}return null}static isIntersecting(t,e){return f.getIntersection(t,e)!==null}static distanceToPoint(t,e,s=f.EPSILON){const i=e.x-t.p1.x,n=e.y-t.p1.y,h=t.p2.x-t.p1.x,c=t.p2.y-t.p1.y,l=i*h+n*c,g=h*h+c*c;let y=-1;g>s&&(y=l/g);let o,d;y<0?(o=t.p1.x,d=t.p1.y):y>1?(o=t.p2.x,d=t.p2.y):(o=t.p1.x+y*h,d=t.p1.y+y*c);const m=e.x-o,M=e.y-d;return Math.hypot(m+M)}p1;p2;constructor(t,e){this.p1=t,this.p2=e}get length(){const t=this.p2.x-this.p1.x,e=this.p2.y-this.p1.y;return Math.sqrt(t*t+e*e)}get midpoint(){const t=(this.p1.x+this.p2.x)/2,e=(this.p1.y+this.p2.y)/2;return new u(t,e)}get angle(){return Math.atan2(this.p2.y-this.p1.y,this.p2.x-this.p1.x)}containsPoint(t,e=f.EPSILON){const s=(t.x-this.p1.x)*(this.p2.y-this.p1.y)-(t.y-this.p1.y)*(this.p2.x-this.p1.x);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}get direction(){const t=this.length;if(t<f.EPSILON)return new u(0,0);const e=(this.p2.x-this.p1.x)/t,s=(this.p2.y-this.p1.y)/t;return new u(e,s)}get start(){return this.p1}get end(){return this.p2}}class O{static EPSILON=1e-10;name;constructor(t){this.name=t}}class p extends O{static isValid(t,e,s){return t<=0||e<=0||s<=0?!1:t+e>s&&t+s>e&&e+s>t}static area(t,e,s){if(!p.isValid(t,e,s))throw new Error("Invalid triangle");const i=(t+e+s)/2;return Math.sqrt(i*(i-t)*(i-e)*(i-s))}static getType(t,e,s){if(!p.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=[t,e,s].sort((l,g)=>l-g),[n,h,c]=i;return Math.abs(n-h)<p.EPSILON&&Math.abs(h-c)<p.EPSILON?"equilateral":Math.abs(n-h)<p.EPSILON||Math.abs(h-c)<p.EPSILON?"isosceles":"scalene"}static getAngles(t,e,s){if(!p.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=Math.acos((e*e+s*s-t*t)/(2*e*s)),n=Math.acos((t*t+s*s-e*e)/(2*t*s)),h=Math.PI-i-n;return[i,n,h]}p1;p2;p3;constructor(t,e,s,i="triangle"){if(super(i),this.p1=t,this.p2=e,this.p3=s,this.areCollinear())throw new Error("Points are collinear, cannot form a triangle")}areCollinear(){return Math.abs((this.p2.x-this.p1.x)*(this.p3.y-this.p1.y)-(this.p3.x-this.p1.x)*(this.p2.y-this.p1.y))<O.EPSILON}get side(){return[u.distance(this.p1,this.p2),u.distance(this.p2,this.p3),u.distance(this.p3,this.p1)]}perimeter(){return p.isValid(this.side[0],this.side[1],this.side[2]),this.side.reduce((t,e)=>t+e,0)}area(){const[t,e,s]=this.side;return p.area(t,e,s)}get type(){const[t,e,s]=this.side;return p.getType(t,e,s)}get angles(){const[t,e,s]=this.side;return p.getAngles(t,e,s)}get centroid(){return new u((this.p1.x+this.p2.x+this.p3.x)/3,(this.p1.y+this.p2.y+this.p3.y)/3)}get incenter(){const[t,e,s]=this.side,i=this.perimeter()/2,n=(t*this.p1.x+e*this.p2.x+s*this.p3.x)/i,h=(t*this.p1.y+e*this.p2.y+s*this.p3.y)/i;return new u(n,h)}get circumcenter(){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));if(Math.abs(t)<p.EPSILON)throw new Error("Cannot calculate circumcenter for collinear points");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;return new u(e,s)}containsPoint(t){const e=p.area(u.distance(t,this.p1),u.distance(t,this.p2),u.distance(this.p1,this.p2)),s=p.area(u.distance(t,this.p2),u.distance(t,this.p3),u.distance(this.p2,this.p3)),i=p.area(u.distance(t,this.p3),u.distance(t,this.p1),u.distance(this.p3,this.p1));return Math.abs(e+s+i-this.area())<p.EPSILON}}function $(r){return new Promise(t=>setTimeout(t,r))}function H(r){const t=[],e={"(":")","[":"]","{":"}"},s=new Set(Object.values(e));for(const i of r)if(i in e)t.push(e[i]);else if(s.has(i)&&i!==t.pop())return!1;return t.length===0}function v(r){return r!==null&&(typeof r=="object"||typeof r=="function")}class _{map=new Map;weakMap=new WeakMap;set(t,e){v(t)?this.weakMap.set(t,e):this.map.set(t,e)}get(t){return v(t)?this.weakMap.get(t):this.map.get(t)}has(t){return v(t)?this.weakMap.has(t):this.map.has(t)}}function T(r){if(!r.length)return[];const t=[[r[0]]];for(let s=1,i=r.length;s<i;s++){const n=r[s];e(n)}function e(s){for(let i=t.length-1;i>=0;i--){const n=t[i],h=n[t[i].length-1];if(h<s){t[i+1]=[...n,s];break}else h>s&&i===0&&(t[i]=[s])}}return t[t.length-1]}class B{static ROMAN_MAP=new Map([["M",1e3],["CM",900],["D",500],["CD",400],["C",100],["XC",90],["L",50],["XL",40],["X",10],["IX",9],["V",5],["IV",4],["I",1]]);static toInteger(t){if(t.length===0)throw new Error("Input cannot be empty");const e=new Set(["I","V","X","L","C","D","M"]);for(const h of t)if(!e.has(h))throw new Error(`Invalid Roman numeral character: ${h}`);let s=0,i=0;for(;i<t.length;){const h=t.slice(i,i+2);if(this.ROMAN_MAP.has(h))s+=this.ROMAN_MAP.get(h),i+=2;else{const c=t[i],l=this.ROMAN_MAP.get(c);if(!l)throw new Error(`Invalid Roman numeral sequence at position ${i}`);s+=l,i+=1}}if(this.toRoman(s)!==t)throw new Error("Invalid Roman numeral sequence");return s}static toRoman(t){if(t<=0||t>=4e3)throw new Error("Number must be between 1 and 3999");if(!Number.isInteger(t))throw new Error("Number must be an integer");let e="";for(const[s,i]of this.ROMAN_MAP)for(;t>=i;)e+=s,t-=i;return e}}class F{static isValidPositiveInteger(t){return Number.isInteger(t)&&t>0&&t<=Number.MAX_SAFE_INTEGER}static isPowerOfTwo(t){return t>0&&(t&t-1)===0}static isOdd(t){return t%2===1||t%2===-1}static factorial(t){if(!this.isValidPositiveInteger(t))throw new Error("Input must be a non-negative integer");if(t<2)return 1;let e=1;for(let s=2;s<=t;s++)e*=s;return e}static fibonacci(t,e=1,s=1){if(!this.isValidPositiveInteger(t))throw new Error("Input must be a non-negative integer");return t<2?s:this.fibonacci(t-1,s,s+e)}static fibonacciIterative(t){if(t<2)return t;let e=0,s=1;for(let i=2;i<t;i++)[e,s]=[s,(e+s)%1000000007];return s}static getPercentWithPrecision(t,e=2){if(!Array.isArray(t)||t.length===0)return[];if(e<0||!Number.isInteger(e))throw new Error("Precision must be a non-negative integer");const s=t.reduce((o,d)=>o+d,0);if(s===0)return t.map(()=>"0%");const n=100*Math.pow(10,e),h=t.map(o=>o/s*n),c=h.map(o=>Math.floor(o)),l=h.map((o,d)=>o-c[d]);let g=c.reduce((o,d)=>o+d,0),y=n-g;for(;y>0;){let o=-1,d=-1;for(let m=0;m<l.length;m++)l[m]>d&&(d=l[m],o=m);if(o===-1)break;c[o]++,l[o]=0,y--}return c.map(o=>`${(o/n*100).toFixed(e)}%`)}static fastSqrt(t){if(t<0)throw new Error("n must be a non-negative number");const e=.5*t;let s=new BigInt64Array(new Float32Array([t]).buffer)[0];s=0x1ff7a3bea91d9b1bn+(s>>1n);let i=new Float64Array(new BigInt64Array([s]).buffer)[0];return i=i*.5+e/i,i=i*.5+e/i,i=i*.5+e/i,i}static gcd(t,e){return e===0?t:this.gcd(e,t%e)}static lcm(t,e){return t*e/this.gcd(t,e)}static isPrime(t){if(t<=1)return!1;for(let e=2;e<=Math.sqrt(t);e++)if(t%e===0)return!1;return!0}static isPalindrome(t){if(t<0||t%10===0&&t!==0)return!1;let e=0,s=t;for(;t>0;){const i=t%10;e=e*10+i,t=Math.floor(t/10)}return s===e}static isArmstrong(t){const e=t.toString(),s=e.length;let i=0;for(let n=0;n<s;n++)i+=Math.pow(parseInt(e[n]),s);return i===t}static isHappy(t){const e=new Set;for(;t!==1;){if(e.has(t))return!1;e.add(t),t=(t+"").split("").reduce((s,i)=>s+Number(i)*Number(i),0)}return!0}static isPerfect(t){let e=0;for(let s=1;s<t;s++)t%s===0&&(e+=s);return e===t}static middle(t,e){return e-(e-t>>1)}static scale(t,e,s){if(e[0]>=e[1]||s[0]>=s[1])throw new Error("Invalid range");t=this.clamp(t,e[0],e[1]);const i=e[1]-e[0];return(t-e[0])*((s[1]-s[0])/i)+s[0]}static clamp(t,e,s){return Math.min(Math.max(t,e),s)}static randomInt(t,e){return Math.floor(Math.random()*(e-t+1))+t}static floatEqual(t,e,s=1e-6){return Math.abs(t-e)<s}static isSameSign(t,e){return t>=0&&e>=0||t<=0&&e<=0}}class G{static READ=1;static WRITE=2;static SHARE=4;static DELETE=8;static CREATE=16;static include(t,e){return(t&e)===e}static add(t,e){return t|e}static remove(t,e){return t&~e}static toggle(t,e){return t^e}}class Q{static longestCommonPrefix(t){if(!t.length)return"";let e=t[0];for(let s=1;s<t.length;s++)for(;!t[s].startsWith(e);)if(e=e.slice(0,-1),e==="")return"";return e}static uuid(t){return typeof t=="number"?(t^Math.random()*16>>t/4).toString(16):(9987e3+-1e11).toString().replace(/[018]/g,e=>{const s=parseInt(e,10);return this.uuid(s)})}}class W{static isValidHex(t){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t)}static isValidRGB(t){return/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.test(t)}}function X(r){let t;const e=new Proxy(r,{construct(s,i,n){return t||(t=Reflect.construct(s,i,n)),t}});return r.prototype.constructor=e,e}const I={AUTH_UNAUTHORIZED:"未授权事件",AUTH_LOGIN_SUCCESS:"登录成功事件",AUTH_LOGOUT:"注销事件",AUTH_TOKEN_EXPIRED:"令牌过期事件",REQUEST_ERROR:"请求错误事件",REQUEST_TIMEOUT:"请求超时事件",REQUEST_NETWORK_ERROR:"网络错误事件",UI_SHOW_LOADING:"显示加载事件",UI_HIDE_LOADING:"隐藏加载事件",UI_SHOW_MESSAGE:"显示消息事件"};class S{static instance=null;listeners={};debugMode;constructor(t=!1){this.debugMode=t,Object.keys(I).forEach(e=>{this.listeners[e]=new Set})}static getInstance(t){return S.instance||(S.instance=new S(t)),S.instance}on(t,e){this.debugLog(`添加事件监听: ${I[t]}`),this.listeners[t].add(e)}emit(t,e){this.debugLog(`触发事件: ${I[t]}`,e),this.listeners[t].forEach(s=>{try{s(e)}catch(i){console.error(`事件 ${I[t]} 处理出错:`,i)}})}off(t,e){this.debugLog(`移除事件监听: ${I[t]}`),this.listeners[t].delete(e)}once(t,e){this.debugLog(`添加一次性事件监听: ${I[t]}`);const s=i=>{e(i),this.off(t,s)};this.on(t,s)}clear(){this.debugLog("清除所有事件监听器"),Object.values(this.listeners).forEach(t=>t.clear())}getListenerCount(t){return this.listeners[t].size}debugLog(t,e){this.debugMode&&console.log(`[EventEmitter] ${t}`,e||"")}}function K(r,t,e){let s=-1,i=r.length,n;for(;i-s>1;)n=i-(i-s)>>1,e(r[n],t)?i=n:s=n;return i}String.prototype.pointLength=function(){let r=0;for(let t=0,e=this.length;t<e;){const s=this.codePointAt(t);t+=s>65535?2:1,r++}return r},String.prototype.pointAt=function(r){if(r>=this.pointLength())return;let t=0;for(let e=0,s=this.length;e<s;){const i=this.codePointAt(e);if(!i)return;if(t===r)return String.fromCodePoint(i);e+=i>65535?2:1,t++}},String.prototype.sliceByPoint=function(r,t=this.pointLength()){let e="";for(let s=r;s<t;s++)e+=this.pointAt(s);return e},RegExp.escape=function(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},Element.prototype.farthest=function(r){if(typeof r!="string"||!r)return null;let t=null,e=this;for(;e;){const s=e.closest(r);if(!s)break;t=s,e=s.parentElement}return t},Object.defineProperties(Element.prototype,{firstElement:{get:function(){if(!this.children.length)return null;let r=this.firstElementChild,t=null;for(;r;)t=r,r=r.firstElementChild;return t}},lastElement:{get:function(){if(!this.children.length)return null;let r=this.lastElementChild,t=null;for(;r;)t=r,r=r.lastElementChild;return t}}}),Text.prototype.surround=function(r="strong",t=""){if(!this.nodeValue||!r||!t)return null;const s=r.split("."),i=s[0],n=s.slice(1).join(" "),h=this.textContent.indexOf(t);if(h<0)return null;const c=document.createRange();c.setStart(this,h),c.setEnd(this,h+t.length);const l=document.createElement(i);return n&&(l.className=n),c.surroundContents(l),l},a.BitPerm=G,a.Color=W,a.Dictionary=N,a.Emitter=S,a.Graph=U,a.LIS=T,a.LRU=D,a.Line=f,a.LinkedList=j,a.Matrix=x,a.MaxHeap=V,a.MemoizeMap=_,a.MinHeap=P,a.MinStack=R,a.Num=F,a.Point=u,a.Queue=b,a.Roman=B,a.Stack=C,a.Str=Q,a.Triangle=p,a.Vector=w,a.binarySearchTemplate=K,a.isValidBracket=H,a.singleton=X,a.sleep=$,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
package/types/queue.d.ts
CHANGED
package/types/shape.d.ts
ADDED
package/types/stack.d.ts
CHANGED
|
@@ -12,13 +12,11 @@ interface IStack<T> extends Structure {
|
|
|
12
12
|
pop(): T | undefined;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* ####
|
|
16
|
-
* @param
|
|
15
|
+
* #### 添加一个或多个元素
|
|
16
|
+
* @param items
|
|
17
17
|
*/
|
|
18
|
-
push(
|
|
19
|
-
|
|
20
|
-
push(...items: T[]): this;
|
|
21
|
-
push(itemOrItems: T | T[]): this;
|
|
18
|
+
push(...items: (T | T[])[]): this;
|
|
19
|
+
|
|
22
20
|
/**
|
|
23
21
|
* #### 返回栈顶元素,但不移除
|
|
24
22
|
*/
|