jc-structure 0.1.15 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- class j {
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
- const e = t.length === 1 && Array.isArray(t[0]) ? t[0] : t;
16
- return this.batchEnqueue(e), this;
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((e) => {
20
- this.isValidItem(e) && (this.items[this.count] = e, this.count++);
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 U {
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
- return t == null || t == null ? this : Array.isArray(t) ? this.addItems(t) : this.addItem(t);
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 k(r, t) {
132
+ function P(r, t) {
115
133
  return r === t ? 0 : r < t ? -1 : 1;
116
134
  }
117
135
  class y {
118
136
  heap = [];
119
137
  compareFn;
120
- constructor(t = k) {
138
+ constructor(t = P) {
121
139
  this.compareFn = t;
122
140
  }
123
141
  static getLeftIndex(t) {
@@ -169,14 +187,14 @@ class O extends y {
169
187
  }
170
188
  }
171
189
  class q extends O {
172
- constructor(t = (e, s) => k(s, e)) {
190
+ constructor(t = (e, s) => P(s, e)) {
173
191
  super(t);
174
192
  }
175
193
  }
176
- function R(r) {
194
+ function L(r) {
177
195
  return { value: r };
178
196
  }
179
- class D {
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 = R(e), this.length++, this.prepend(s), this.trimCache(), this.lookup.set(t, s), this.reverseLookup);
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
- let A = class {
230
+ class S {
213
231
  value;
214
232
  next = void 0;
215
- };
216
- class H {
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 A();
267
+ let s = new S();
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 A();
279
+ let e = new S();
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 V {
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 P(r, t = { emptyString: !1, zeroNumber: !1 }) {
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 z {
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 (P(t))
334
+ if (M(t))
317
335
  throw new Error("key is required");
318
- if (P(e))
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 V(t, e);
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 W {
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 z();
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, []));
@@ -457,13 +475,22 @@ class w {
457
475
  return this.mul(-1);
458
476
  }
459
477
  }
460
- class E {
478
+ class x {
461
479
  _matrix;
462
480
  static zero(t, e) {
463
- return new E(
481
+ return new x(
464
482
  Array.from({ length: t }, () => Array.from({ length: e }, () => 0))
465
483
  );
466
484
  }
485
+ static rotate(t) {
486
+ const e = t.length;
487
+ for (let s = 0; s < (e + 1) / 2; s++)
488
+ for (let i = s; i < e / 2; i++) {
489
+ const n = t[e - 1 - i][s];
490
+ t[e - 1 - i][s] = t[e - 1 - s][e - 1 - i], t[e - 1 - s][e - 1 - i] = t[i][e - 1 - s], t[i][e - 1 - s] = t[s][i], t[s][i] = n;
491
+ }
492
+ return t;
493
+ }
467
494
  constructor(t) {
468
495
  this._matrix = t;
469
496
  }
@@ -492,7 +519,7 @@ class E {
492
519
  return this._matrix[t[0]][t[1]] = e, this;
493
520
  }
494
521
  mul(t) {
495
- return new E(this._matrix.map((e) => e.map((s) => s * t)));
522
+ return new x(this._matrix.map((e) => e.map((s) => s * t)));
496
523
  }
497
524
  div(t) {
498
525
  return this.mul(1 / t);
@@ -500,7 +527,7 @@ class E {
500
527
  add(t) {
501
528
  if (this.row !== t.row || this.col !== t.col)
502
529
  throw new Error("Matrix dimensions do not match");
503
- return new E(
530
+ return new x(
504
531
  this._matrix.map(
505
532
  (e, s) => e.map((i, n) => i + t.getItem([s, n]))
506
533
  )
@@ -518,14 +545,14 @@ class E {
518
545
  mulVector(t) {
519
546
  if (this.col !== t.dimension)
520
547
  throw new Error("Matrix dimensions do not match");
521
- return new E(
548
+ return new x(
522
549
  this._matrix.map((e) => e.map((s, i) => s * t.getItem(i)))
523
550
  );
524
551
  }
525
552
  mulMatrix(t) {
526
553
  if (this.col !== t.row)
527
554
  throw new Error("Matrix dimensions do not match");
528
- const e = E.zero(this.row, t.col);
555
+ const e = x.zero(this.row, t.col);
529
556
  for (let s = 0; s < this.row; s++) {
530
557
  const i = this.rowVector(s);
531
558
  for (let n = 0; n < this.col; n++)
@@ -534,7 +561,7 @@ class E {
534
561
  return e;
535
562
  }
536
563
  }
537
- class c {
564
+ class u {
538
565
  static distance(t, e) {
539
566
  return Math.hypot(e.x - t.x, e.y - t.y);
540
567
  }
@@ -544,42 +571,42 @@ class c {
544
571
  this.x = t, this.y = e;
545
572
  }
546
573
  distanceTo(t) {
547
- return c.distance(this, t);
574
+ return u.distance(this, t);
548
575
  }
549
576
  }
550
- class m {
577
+ class g {
551
578
  // 使用更合适的精度阈值常量
552
579
  static EPSILON = 1e-10;
553
- static sloped(t, e = m.EPSILON) {
580
+ static sloped(t, e = g.EPSILON) {
554
581
  const s = t.p2.x - t.p1.x, i = t.p2.y - t.p1.y;
555
582
  return Math.abs(s) < e ? Math.abs(i) < e ? 0 : null : i / s;
556
583
  }
557
- static isParallel(t, e, s = m.EPSILON) {
558
- const i = m.sloped(t), n = m.sloped(e);
584
+ static isParallel(t, e, s = g.EPSILON) {
585
+ const i = g.sloped(t), n = g.sloped(e);
559
586
  return i === null && n === null ? !0 : i === null || n === null ? !1 : Math.abs(i - n) < s;
560
587
  }
561
- static getIntersection(t, e, s = m.EPSILON) {
562
- if (m.isParallel(t, e)) return null;
563
- const i = t.p1.x, n = t.p1.y, a = t.p2.x, h = t.p2.y, u = e.p1.x, f = e.p1.y, g = e.p2.x, o = e.p2.y, l = (i - a) * (f - o) - (n - h) * (u - g);
588
+ static getIntersection(t, e, s = g.EPSILON) {
589
+ if (g.isParallel(t, e)) return null;
590
+ 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
591
  if (Math.abs(l) < s) return null;
565
- const d = ((i - u) * (f - o) - (n - f) * (u - g)) / l, S = -((i - a) * (n - f) - (n - h) * (i - u)) / l;
566
- if (d >= 0 && d <= 1 && S >= 0 && S <= 1) {
567
- const C = i + d * (a - i), L = n + d * (h - n);
568
- return new c(C, L);
592
+ const d = ((i - c) * (f - a) - (n - f) * (c - m)) / l, v = -((i - h) * (n - f) - (n - o) * (i - c)) / l;
593
+ if (d >= 0 && d <= 1 && v >= 0 && v <= 1) {
594
+ const k = i + d * (h - i), N = n + d * (o - n);
595
+ return new u(k, N);
569
596
  }
570
597
  return null;
571
598
  }
572
599
  static isIntersecting(t, e) {
573
- return m.getIntersection(t, e) !== null;
600
+ return g.getIntersection(t, e) !== null;
574
601
  }
575
- static distanceToPoint(t, e, s = m.EPSILON) {
576
- const i = e.x - t.p1.x, n = e.y - t.p1.y, a = t.p2.x - t.p1.x, h = t.p2.y - t.p1.y, u = i * a + n * h, f = a * a + h * h;
577
- let g = -1;
578
- f > s && (g = u / f);
579
- let o, l;
580
- g < 0 ? (o = t.p1.x, l = t.p1.y) : g > 1 ? (o = t.p2.x, l = t.p2.y) : (o = t.p1.x + g * a, l = t.p1.y + g * h);
581
- const d = e.x - o, S = e.y - l;
582
- return Math.hypot(d + S);
602
+ static distanceToPoint(t, e, s = g.EPSILON) {
603
+ 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;
604
+ let m = -1;
605
+ f > s && (m = c / f);
606
+ let a, l;
607
+ 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);
608
+ const d = e.x - a, v = e.y - l;
609
+ return Math.hypot(d + v);
583
610
  }
584
611
  p1;
585
612
  p2;
@@ -592,21 +619,21 @@ class m {
592
619
  }
593
620
  get midpoint() {
594
621
  const t = (this.p1.x + this.p2.x) / 2, e = (this.p1.y + this.p2.y) / 2;
595
- return new c(t, e);
622
+ return new u(t, e);
596
623
  }
597
624
  get angle() {
598
625
  return Math.atan2(this.p2.y - this.p1.y, this.p2.x - this.p1.x);
599
626
  }
600
- containsPoint(t, e = m.EPSILON) {
627
+ containsPoint(t, e = g.EPSILON) {
601
628
  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
629
  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
630
  }
604
631
  // 获取线段的方向向量
605
632
  get direction() {
606
633
  const t = this.length;
607
- if (t < m.EPSILON) return new c(0, 0);
634
+ if (t < g.EPSILON) return new u(0, 0);
608
635
  const e = (this.p2.x - this.p1.x) / t, s = (this.p2.y - this.p1.y) / t;
609
- return new c(e, s);
636
+ return new u(e, s);
610
637
  }
611
638
  get start() {
612
639
  return this.p1;
@@ -615,14 +642,14 @@ class m {
615
642
  return this.p2;
616
643
  }
617
644
  }
618
- class N {
645
+ class A {
619
646
  static EPSILON = 1e-10;
620
647
  name;
621
648
  constructor(t) {
622
649
  this.name = t;
623
650
  }
624
651
  }
625
- class p extends N {
652
+ class p extends A {
626
653
  static isValid(t, e, s) {
627
654
  return t <= 0 || e <= 0 || s <= 0 ? !1 : t + e > s && t + s > e && e + s > t;
628
655
  }
@@ -635,14 +662,14 @@ class p extends N {
635
662
  static getType(t, e, s) {
636
663
  if (!p.isValid(t, e, s))
637
664
  throw new Error("Invalid triangle sides");
638
- const i = [t, e, s].sort((u, f) => u - f), [n, a, h] = i;
639
- return Math.abs(n - a) < p.EPSILON && Math.abs(a - h) < p.EPSILON ? "equilateral" : Math.abs(n - a) < p.EPSILON || Math.abs(a - h) < p.EPSILON ? "isosceles" : "scalene";
665
+ const i = [t, e, s].sort((c, f) => c - f), [n, h, o] = i;
666
+ 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
667
  }
641
668
  static getAngles(t, e, s) {
642
669
  if (!p.isValid(t, e, s))
643
670
  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)), a = Math.PI - i - n;
645
- return [i, n, a];
671
+ 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;
672
+ return [i, n, h];
646
673
  }
647
674
  p1;
648
675
  p2;
@@ -655,13 +682,13 @@ class p extends N {
655
682
  areCollinear() {
656
683
  return Math.abs(
657
684
  (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
- ) < N.EPSILON;
685
+ ) < A.EPSILON;
659
686
  }
660
687
  get side() {
661
688
  return [
662
- c.distance(this.p1, this.p2),
663
- c.distance(this.p2, this.p3),
664
- c.distance(this.p3, this.p1)
689
+ u.distance(this.p1, this.p2),
690
+ u.distance(this.p2, this.p3),
691
+ u.distance(this.p3, this.p1)
665
692
  ];
666
693
  }
667
694
  perimeter() {
@@ -680,43 +707,43 @@ class p extends N {
680
707
  return p.getAngles(t, e, s);
681
708
  }
682
709
  get centroid() {
683
- return new c(
710
+ return new u(
684
711
  (this.p1.x + this.p2.x + this.p3.x) / 3,
685
712
  (this.p1.y + this.p2.y + this.p3.y) / 3
686
713
  );
687
714
  }
688
715
  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, a = (t * this.p1.y + e * this.p2.y + s * this.p3.y) / i;
690
- return new c(n, a);
716
+ 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;
717
+ return new u(n, h);
691
718
  }
692
719
  get circumcenter() {
693
720
  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
721
  if (Math.abs(t) < p.EPSILON)
695
722
  throw new Error("Cannot calculate circumcenter for collinear points");
696
723
  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 c(e, s);
724
+ return new u(e, s);
698
725
  }
699
726
  containsPoint(t) {
700
727
  const e = p.area(
701
- c.distance(t, this.p1),
702
- c.distance(t, this.p2),
703
- c.distance(this.p1, this.p2)
728
+ u.distance(t, this.p1),
729
+ u.distance(t, this.p2),
730
+ u.distance(this.p1, this.p2)
704
731
  ), s = p.area(
705
- c.distance(t, this.p2),
706
- c.distance(t, this.p3),
707
- c.distance(this.p2, this.p3)
732
+ u.distance(t, this.p2),
733
+ u.distance(t, this.p3),
734
+ u.distance(this.p2, this.p3)
708
735
  ), i = p.area(
709
- c.distance(t, this.p3),
710
- c.distance(t, this.p1),
711
- c.distance(this.p3, this.p1)
736
+ u.distance(t, this.p3),
737
+ u.distance(t, this.p1),
738
+ u.distance(this.p3, this.p1)
712
739
  );
713
740
  return Math.abs(e + s + i - this.area()) < p.EPSILON;
714
741
  }
715
742
  }
716
- function T(r) {
743
+ function _(r) {
717
744
  return new Promise((t) => setTimeout(t, r));
718
745
  }
719
- function F(r) {
746
+ function H(r) {
720
747
  const t = [], e = {
721
748
  "(": ")",
722
749
  "[": "]",
@@ -729,23 +756,23 @@ function F(r) {
729
756
  return !1;
730
757
  return t.length === 0;
731
758
  }
732
- function M(r) {
759
+ function b(r) {
733
760
  return r !== null && (typeof r == "object" || typeof r == "function");
734
761
  }
735
- class B {
762
+ class T {
736
763
  map = /* @__PURE__ */ new Map();
737
764
  weakMap = /* @__PURE__ */ new WeakMap();
738
765
  set(t, e) {
739
- M(t) ? this.weakMap.set(t, e) : this.map.set(t, e);
766
+ b(t) ? this.weakMap.set(t, e) : this.map.set(t, e);
740
767
  }
741
768
  get(t) {
742
- return M(t) ? this.weakMap.get(t) : this.map.get(t);
769
+ return b(t) ? this.weakMap.get(t) : this.map.get(t);
743
770
  }
744
771
  has(t) {
745
- return M(t) ? this.weakMap.has(t) : this.map.has(t);
772
+ return b(t) ? this.weakMap.has(t) : this.map.has(t);
746
773
  }
747
774
  }
748
- function G(r) {
775
+ function F(r) {
749
776
  if (!r.length) return [];
750
777
  const t = [[r[0]]];
751
778
  for (let s = 1, i = r.length; s < i; s++) {
@@ -754,16 +781,16 @@ function G(r) {
754
781
  }
755
782
  function e(s) {
756
783
  for (let i = t.length - 1; i >= 0; i--) {
757
- const n = t[i], a = n[t[i].length - 1];
758
- if (a < s) {
784
+ const n = t[i], h = n[t[i].length - 1];
785
+ if (h < s) {
759
786
  t[i + 1] = [...n, s];
760
787
  break;
761
- } else a > s && i === 0 && (t[i] = [s]);
788
+ } else h > s && i === 0 && (t[i] = [s]);
762
789
  }
763
790
  }
764
791
  return t[t.length - 1];
765
792
  }
766
- class X {
793
+ class B {
767
794
  static ROMAN_MAP = /* @__PURE__ */ new Map([
768
795
  ["M", 1e3],
769
796
  ["CM", 900],
@@ -783,19 +810,19 @@ class X {
783
810
  if (t.length === 0)
784
811
  throw new Error("Input cannot be empty");
785
812
  const e = /* @__PURE__ */ new Set(["I", "V", "X", "L", "C", "D", "M"]);
786
- for (const a of t)
787
- if (!e.has(a))
788
- throw new Error(`Invalid Roman numeral character: ${a}`);
813
+ for (const h of t)
814
+ if (!e.has(h))
815
+ throw new Error(`Invalid Roman numeral character: ${h}`);
789
816
  let s = 0, i = 0;
790
817
  for (; i < t.length; ) {
791
- const a = t.slice(i, i + 2);
792
- if (this.ROMAN_MAP.has(a))
793
- s += this.ROMAN_MAP.get(a), i += 2;
818
+ const h = t.slice(i, i + 2);
819
+ if (this.ROMAN_MAP.has(h))
820
+ s += this.ROMAN_MAP.get(h), i += 2;
794
821
  else {
795
- const h = t[i], u = this.ROMAN_MAP.get(h);
796
- if (!u)
822
+ const o = t[i], c = this.ROMAN_MAP.get(o);
823
+ if (!c)
797
824
  throw new Error(`Invalid Roman numeral sequence at position ${i}`);
798
- s += u, i += 1;
825
+ s += c, i += 1;
799
826
  }
800
827
  }
801
828
  if (this.toRoman(s) !== t)
@@ -814,7 +841,7 @@ class X {
814
841
  return e;
815
842
  }
816
843
  }
817
- class Q {
844
+ class G {
818
845
  static isValidPositiveInteger(t) {
819
846
  return Number.isInteger(t) && t > 0 && t <= Number.MAX_SAFE_INTEGER;
820
847
  }
@@ -840,31 +867,30 @@ class Q {
840
867
  return t < 2 ? s : this.fibonacci(t - 1, s, s + e);
841
868
  }
842
869
  static fibonacciIterative(t) {
843
- if (!this.isValidPositiveInteger(t))
844
- throw new Error("Input must be a non-negative integer");
845
- let e = 1, s = 1;
870
+ if (t < 2) return t;
871
+ let e = 0, s = 1;
846
872
  for (let i = 2; i < t; i++)
847
- [e, s] = [s, e + s];
848
- return t === 0 ? 0 : s;
873
+ [e, s] = [s, (e + s) % 1000000007];
874
+ return s;
849
875
  }
850
876
  static getPercentWithPrecision(t, e = 2) {
851
877
  if (!Array.isArray(t) || t.length === 0)
852
878
  return [];
853
879
  if (e < 0 || !Number.isInteger(e))
854
880
  throw new Error("Precision must be a non-negative integer");
855
- const s = t.reduce((o, l) => o + l, 0);
881
+ const s = t.reduce((a, l) => a + l, 0);
856
882
  if (s === 0)
857
883
  return t.map(() => "0%");
858
- const n = 100 * Math.pow(10, e), a = t.map((o) => o / s * n), h = a.map((o) => Math.floor(o)), u = a.map((o, l) => o - h[l]);
859
- let f = h.reduce((o, l) => o + l, 0), g = n - f;
860
- for (; g > 0; ) {
861
- let o = -1, l = -1;
862
- for (let d = 0; d < u.length; d++)
863
- u[d] > l && (l = u[d], o = d);
864
- if (o === -1) break;
865
- h[o]++, u[o] = 0, g--;
884
+ 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]);
885
+ let f = o.reduce((a, l) => a + l, 0), m = n - f;
886
+ for (; m > 0; ) {
887
+ let a = -1, l = -1;
888
+ for (let d = 0; d < c.length; d++)
889
+ c[d] > l && (l = c[d], a = d);
890
+ if (a === -1) break;
891
+ o[a]++, c[a] = 0, m--;
866
892
  }
867
- return h.map((o) => `${(o / n * 100).toFixed(e)}%`);
893
+ return o.map((a) => `${(a / n * 100).toFixed(e)}%`);
868
894
  }
869
895
  static fastSqrt(t) {
870
896
  if (t < 0)
@@ -875,9 +901,6 @@ class Q {
875
901
  let i = new Float64Array(new BigInt64Array([s]).buffer)[0];
876
902
  return i = i * 0.5 + e / i, i = i * 0.5 + e / i, i = i * 0.5 + e / i, i;
877
903
  }
878
- static middle(t, e) {
879
- return e - (e - t >> 1);
880
- }
881
904
  static gcd(t, e) {
882
905
  return e === 0 ? t : this.gcd(e, t % e);
883
906
  }
@@ -909,20 +932,55 @@ class Q {
909
932
  i += Math.pow(parseInt(e[n]), s);
910
933
  return i === t;
911
934
  }
935
+ static isHappy(t) {
936
+ const e = /* @__PURE__ */ new Set();
937
+ for (; t !== 1; ) {
938
+ if (e.has(t)) return !1;
939
+ e.add(t), t = (t + "").split("").reduce((s, i) => s + Number(i) * Number(i), 0);
940
+ }
941
+ return !0;
942
+ }
912
943
  static isPerfect(t) {
913
944
  let e = 0;
914
945
  for (let s = 1; s < t; s++)
915
946
  t % s === 0 && (e += s);
916
947
  return e === t;
917
948
  }
949
+ static middle(t, e) {
950
+ return e - (e - t >> 1);
951
+ }
918
952
  static scale(t, e, s) {
919
953
  if (e[0] >= e[1] || s[0] >= s[1])
920
954
  throw new Error("Invalid range");
955
+ t = this.clamp(t, e[0], e[1]);
921
956
  const i = e[1] - e[0];
922
957
  return (t - e[0]) * ((s[1] - s[0]) / i) + s[0];
923
958
  }
959
+ static isRange(t, e, s) {
960
+ if (s == null && (s = e, e = 0), e >= s)
961
+ throw new Error(
962
+ "The maximum value must be greater than the minimum value"
963
+ );
964
+ return e <= t && t < s;
965
+ }
966
+ static clamp(t, e, s) {
967
+ return s == null ? Math.min(t, e) : Math.min(Math.max(t, e), s);
968
+ }
969
+ static random(t, e) {
970
+ if (e == null && (e = t, t = 0), t >= e)
971
+ throw new Error(
972
+ "The maximum value must be greater than the minimum value"
973
+ );
974
+ return Math.random() * (e - t) + t;
975
+ }
924
976
  static randomInt(t, e) {
925
- return Math.floor(Math.random() * (e - t + 1)) + t;
977
+ return Math.floor(this.random(t, e));
978
+ }
979
+ static round(t, e = 0) {
980
+ if (!Number.isInteger(e))
981
+ throw new Error("precision must be an integer");
982
+ const s = Math.pow(10, e);
983
+ return Math.round(t * s) / s;
926
984
  }
927
985
  static floatEqual(t, e, s = 1e-6) {
928
986
  return Math.abs(t - e) < s;
@@ -930,8 +988,33 @@ class Q {
930
988
  static isSameSign(t, e) {
931
989
  return t >= 0 && e >= 0 || t <= 0 && e <= 0;
932
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;
1015
+ }
933
1016
  }
934
- class K {
1017
+ class W {
935
1018
  static READ = 1;
936
1019
  static WRITE = 2;
937
1020
  static SHARE = 4;
@@ -950,7 +1033,7 @@ class K {
950
1033
  return t ^ e;
951
1034
  }
952
1035
  }
953
- class Z {
1036
+ class X {
954
1037
  static longestCommonPrefix(t) {
955
1038
  if (!t.length) return "";
956
1039
  let e = t[0];
@@ -966,7 +1049,7 @@ class Z {
966
1049
  });
967
1050
  }
968
1051
  }
969
- class J {
1052
+ class Q {
970
1053
  static isValidHex(t) {
971
1054
  return /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t);
972
1055
  }
@@ -974,7 +1057,7 @@ class J {
974
1057
  return /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.test(t);
975
1058
  }
976
1059
  }
977
- function Y(r) {
1060
+ function K(r) {
978
1061
  let t;
979
1062
  const e = new Proxy(r, {
980
1063
  construct(s, i, n) {
@@ -987,7 +1070,7 @@ function Y(r) {
987
1070
  });
988
1071
  return r.prototype.constructor = e, e;
989
1072
  }
990
- const x = {
1073
+ const E = {
991
1074
  AUTH_UNAUTHORIZED: "未授权事件",
992
1075
  AUTH_LOGIN_SUCCESS: "登录成功事件",
993
1076
  AUTH_LOGOUT: "注销事件",
@@ -1004,7 +1087,7 @@ class I {
1004
1087
  listeners = {};
1005
1088
  debugMode;
1006
1089
  constructor(t = !1) {
1007
- this.debugMode = t, Object.keys(x).forEach(
1090
+ this.debugMode = t, Object.keys(E).forEach(
1008
1091
  (e) => {
1009
1092
  this.listeners[e] = /* @__PURE__ */ new Set();
1010
1093
  }
@@ -1020,7 +1103,7 @@ class I {
1020
1103
  * @param listener 监听函数
1021
1104
  */
1022
1105
  on(t, e) {
1023
- this.debugLog(`添加事件监听: ${x[t]}`), this.listeners[t].add(e);
1106
+ this.debugLog(`添加事件监听: ${E[t]}`), this.listeners[t].add(e);
1024
1107
  }
1025
1108
  /**
1026
1109
  * 触发事件
@@ -1028,11 +1111,11 @@ class I {
1028
1111
  * @param params 事件参数
1029
1112
  */
1030
1113
  emit(t, e) {
1031
- this.debugLog(`触发事件: ${x[t]}`, e), this.listeners[t].forEach((s) => {
1114
+ this.debugLog(`触发事件: ${E[t]}`, e), this.listeners[t].forEach((s) => {
1032
1115
  try {
1033
1116
  s(e);
1034
1117
  } catch (i) {
1035
- console.error(`事件 ${x[t]} 处理出错:`, i);
1118
+ console.error(`事件 ${E[t]} 处理出错:`, i);
1036
1119
  }
1037
1120
  });
1038
1121
  }
@@ -1042,7 +1125,7 @@ class I {
1042
1125
  * @param listener 监听函数
1043
1126
  */
1044
1127
  off(t, e) {
1045
- this.debugLog(`移除事件监听: ${x[t]}`), this.listeners[t].delete(e);
1128
+ this.debugLog(`移除事件监听: ${E[t]}`), this.listeners[t].delete(e);
1046
1129
  }
1047
1130
  /**
1048
1131
  * 添加一次性事件监听器
@@ -1050,7 +1133,7 @@ class I {
1050
1133
  * @param listener 监听函数
1051
1134
  */
1052
1135
  once(t, e) {
1053
- this.debugLog(`添加一次性事件监听: ${x[t]}`);
1136
+ this.debugLog(`添加一次性事件监听: ${E[t]}`);
1054
1137
  const s = (i) => {
1055
1138
  e(i), this.off(t, s);
1056
1139
  };
@@ -1072,231 +1155,11 @@ class I {
1072
1155
  this.debugMode && console.log(`[EventEmitter] ${t}`, e || "");
1073
1156
  }
1074
1157
  }
1075
- const b = {
1076
- scriptRegex: /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
1077
- javascriptRegex: /javascript:/gi,
1078
- eventHandlerRegex: /on\w+\s*=/gi,
1079
- allowedTags: /* @__PURE__ */ new Set([
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
- }
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;
1300
1163
  }
1301
1164
  String.prototype.pointLength = function() {
1302
1165
  let r = 0;
@@ -1359,39 +1222,38 @@ Object.defineProperties(Element.prototype, {
1359
1222
  });
1360
1223
  Text.prototype.surround = function(r = "strong", t = "") {
1361
1224
  if (!this.nodeValue || !r || !t) return null;
1362
- const s = r.split("."), i = s[0], n = s.slice(1).join(" "), a = this.textContent.indexOf(t);
1363
- if (a < 0) return null;
1364
- const h = document.createRange();
1365
- h.setStart(this, a), h.setEnd(this, a + t.length);
1366
- const u = document.createElement(i);
1367
- return n && (u.className = n), h.surroundContents(u), u;
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;
1368
1231
  };
1369
1232
  export {
1370
- K as BitPerm,
1371
- J as Color,
1372
- z as Dictionary,
1373
- v as DomHelper,
1233
+ W as BitPerm,
1234
+ Q as Color,
1235
+ R as Dictionary,
1374
1236
  I as Emitter,
1375
- W as Graph,
1376
- G as LIS,
1377
- D as LRU,
1378
- m as Line,
1379
- H as LinkedList,
1380
- E as Matrix,
1237
+ $ as Graph,
1238
+ F as LIS,
1239
+ j as LRU,
1240
+ g as Line,
1241
+ U as LinkedList,
1242
+ x as Matrix,
1381
1243
  q as MaxHeap,
1382
- B as MemoizeMap,
1244
+ T as MemoizeMap,
1383
1245
  O as MinHeap,
1384
- $ as MinStack,
1385
- Q as Num,
1386
- c as Point,
1387
- j as Queue,
1388
- X as Roman,
1389
- U as Stack,
1390
- Z as Str,
1246
+ D as MinStack,
1247
+ G as Num,
1248
+ u as Point,
1249
+ V as Queue,
1250
+ B as Roman,
1251
+ z as Stack,
1252
+ X as Str,
1391
1253
  p as Triangle,
1392
1254
  w as Vector,
1393
- tt as WebAppManager,
1394
- F as isValidBracket,
1395
- Y as singleton,
1396
- T as sleep
1255
+ Z as binarySearchTemplate,
1256
+ H as isValidBracket,
1257
+ K as singleton,
1258
+ _ as sleep
1397
1259
  };