jc-structure 0.1.14 → 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.
@@ -12,13 +12,23 @@ class V {
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 V {
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 C(r, t) {
132
+ function P(r, t) {
115
133
  return r === t ? 0 : r < t ? -1 : 1;
116
134
  }
117
135
  class w {
118
136
  heap = [];
119
137
  compareFn;
120
- constructor(t = C) {
138
+ constructor(t = P) {
121
139
  this.compareFn = t;
122
140
  }
123
141
  static getLeftIndex(t) {
@@ -148,7 +166,7 @@ class w {
148
166
  return this.heap.toString();
149
167
  }
150
168
  }
151
- class P extends w {
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
  }
@@ -168,15 +186,15 @@ class P extends w {
168
186
  w.swap(this.heap, e, t), t = e, e = w.getParentIndex(t);
169
187
  }
170
188
  }
171
- class q extends P {
172
- constructor(t = (e, s) => C(s, e)) {
189
+ class q extends O {
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 _ {
197
+ class j {
180
198
  capacity;
181
199
  length = 0;
182
200
  head = null;
@@ -206,14 +224,14 @@ class _ {
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 v {
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 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 A();
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 z {
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 L(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 j {
323
+ class R {
306
324
  table = [];
307
325
  constructor() {
308
326
  }
@@ -313,15 +331,15 @@ class j {
313
331
  return -1;
314
332
  }
315
333
  set(t, e) {
316
- if (L(t))
334
+ if (M(t))
317
335
  throw new Error("key is required");
318
- if (L(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 z(t, e);
342
+ const s = new C(t, e);
325
343
  this.table.push(s);
326
344
  }
327
345
  }
@@ -372,12 +390,12 @@ class j {
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 j();
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 g {
420
+ class y {
403
421
  _data;
404
422
  static zero(t) {
405
- return new g(...Array(t).fill(0));
423
+ return new y(...Array(t).fill(0));
406
424
  }
407
425
  constructor(...t) {
408
426
  this._data = t;
@@ -421,7 +439,7 @@ class g {
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 g(...e);
442
+ return new y(...e);
425
443
  }
426
444
  add(t) {
427
445
  if (this.dimension !== t.dimension)
@@ -429,7 +447,7 @@ class g {
429
447
  const e = this._data.map(
430
448
  (s, i) => s + t._data[i]
431
449
  );
432
- return new g(...e);
450
+ return new y(...e);
433
451
  }
434
452
  sub(t) {
435
453
  if (this.dimension !== t.dimension)
@@ -437,10 +455,10 @@ class g {
437
455
  const e = this._data.map(
438
456
  (s, i) => s - t._data[i]
439
457
  );
440
- return new g(...e);
458
+ return new y(...e);
441
459
  }
442
460
  mul(t) {
443
- return new g(...this._data.map((e) => e * t));
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 g(...this._matrix[t]);
501
+ return new y(...this._matrix[t]);
484
502
  }
485
503
  colVector(t) {
486
- return new g(...this._matrix.map((e) => e[t]));
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 a {
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,42 +562,42 @@ class a {
544
562
  this.x = t, this.y = e;
545
563
  }
546
564
  distanceTo(t) {
547
- return a.distance(this, t);
565
+ return u.distance(this, t);
548
566
  }
549
567
  }
550
- class l {
568
+ class g {
551
569
  // 使用更合适的精度阈值常量
552
570
  static EPSILON = 1e-10;
553
- static sloped(t, e = l.EPSILON) {
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 = l.EPSILON) {
558
- const i = l.sloped(t), n = l.sloped(e);
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 = l.EPSILON) {
562
- if (l.isParallel(t, e)) return null;
563
- const i = t.p1.x, n = t.p1.y, o = t.p2.x, h = t.p2.y, u = e.p1.x, p = e.p1.y, d = e.p2.x, m = e.p2.y, f = (i - o) * (p - m) - (n - h) * (u - d);
564
- if (Math.abs(f) < s) return null;
565
- const y = ((i - u) * (p - m) - (n - p) * (u - d)) / f, S = -((i - o) * (n - p) - (n - h) * (i - u)) / f;
566
- if (y >= 0 && y <= 1 && S >= 0 && S <= 1) {
567
- const N = i + y * (o - i), O = n + y * (h - n);
568
- return new a(N, O);
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);
582
+ if (Math.abs(l) < s) return null;
583
+ const d = ((i - c) * (f - a) - (n - f) * (c - m)) / l, S = -((i - h) * (n - f) - (n - o) * (i - c)) / l;
584
+ if (d >= 0 && d <= 1 && S >= 0 && S <= 1) {
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 l.getIntersection(t, e) !== null;
591
+ return g.getIntersection(t, e) !== null;
574
592
  }
575
- static distanceToPoint(t, e, s = l.EPSILON) {
576
- const i = e.x - t.p1.x, n = e.y - t.p1.y, o = t.p2.x - t.p1.x, h = t.p2.y - t.p1.y, u = i * o + n * h, p = o * o + h * h;
577
- let d = -1;
578
- p > s && (d = u / p);
579
- let m, f;
580
- d < 0 ? (m = t.p1.x, f = t.p1.y) : d > 1 ? (m = t.p2.x, f = t.p2.y) : (m = t.p1.x + d * o, f = t.p1.y + d * h);
581
- const y = e.x - m, S = e.y - f;
582
- return Math.hypot(y + S);
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;
600
+ return Math.hypot(d + S);
583
601
  }
584
602
  p1;
585
603
  p2;
@@ -592,21 +610,21 @@ class l {
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 a(t, e);
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 = l.EPSILON) {
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 < l.EPSILON) return new a(0, 0);
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 a(e, s);
627
+ return new u(e, s);
610
628
  }
611
629
  get start() {
612
630
  return this.p1;
@@ -615,34 +633,34 @@ class l {
615
633
  return this.p2;
616
634
  }
617
635
  }
618
- class k {
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 c extends k {
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
  }
629
647
  static area(t, e, s) {
630
- if (!c.isValid(t, e, s))
648
+ if (!p.isValid(t, e, s))
631
649
  throw new Error("Invalid triangle");
632
650
  const i = (t + e + s) / 2;
633
651
  return Math.sqrt(i * (i - t) * (i - e) * (i - s));
634
652
  }
635
653
  static getType(t, e, s) {
636
- if (!c.isValid(t, e, s))
654
+ if (!p.isValid(t, e, s))
637
655
  throw new Error("Invalid triangle sides");
638
- const i = [t, e, s].sort((u, p) => u - p), [n, o, h] = i;
639
- return Math.abs(n - o) < c.EPSILON && Math.abs(o - h) < c.EPSILON ? "equilateral" : Math.abs(n - o) < c.EPSILON || Math.abs(o - h) < c.EPSILON ? "isosceles" : "scalene";
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
- if (!c.isValid(t, e, s))
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)), o = Math.PI - i - n;
645
- return [i, n, o];
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,68 +673,68 @@ class c extends k {
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
- ) < k.EPSILON;
676
+ ) < A.EPSILON;
659
677
  }
660
678
  get side() {
661
679
  return [
662
- a.distance(this.p1, this.p2),
663
- a.distance(this.p2, this.p3),
664
- a.distance(this.p3, this.p1)
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() {
668
- return c.isValid(this.side[0], this.side[1], this.side[2]), this.side.reduce((t, e) => t + e, 0);
686
+ return p.isValid(this.side[0], this.side[1], this.side[2]), this.side.reduce((t, e) => t + e, 0);
669
687
  }
670
688
  area() {
671
689
  const [t, e, s] = this.side;
672
- return c.area(t, e, s);
690
+ return p.area(t, e, s);
673
691
  }
674
692
  get type() {
675
693
  const [t, e, s] = this.side;
676
- return c.getType(t, e, s);
694
+ return p.getType(t, e, s);
677
695
  }
678
696
  get angles() {
679
697
  const [t, e, s] = this.side;
680
- return c.getAngles(t, e, s);
698
+ return p.getAngles(t, e, s);
681
699
  }
682
700
  get centroid() {
683
- return new a(
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, o = (t * this.p1.y + e * this.p2.y + s * this.p3.y) / i;
690
- return new a(n, o);
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
- if (Math.abs(t) < c.EPSILON)
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 a(e, s);
715
+ return new u(e, s);
698
716
  }
699
717
  containsPoint(t) {
700
- const e = c.area(
701
- a.distance(t, this.p1),
702
- a.distance(t, this.p2),
703
- a.distance(this.p1, this.p2)
704
- ), s = c.area(
705
- a.distance(t, this.p2),
706
- a.distance(t, this.p3),
707
- a.distance(this.p2, this.p3)
708
- ), i = c.area(
709
- a.distance(t, this.p3),
710
- a.distance(t, this.p1),
711
- a.distance(this.p3, this.p1)
718
+ const e = p.area(
719
+ u.distance(t, this.p1),
720
+ u.distance(t, this.p2),
721
+ u.distance(this.p1, this.p2)
722
+ ), s = p.area(
723
+ u.distance(t, this.p2),
724
+ u.distance(t, this.p3),
725
+ u.distance(this.p2, this.p3)
726
+ ), i = p.area(
727
+ u.distance(t, this.p3),
728
+ u.distance(t, this.p1),
729
+ u.distance(this.p3, this.p1)
712
730
  );
713
- return Math.abs(e + s + i - this.area()) < c.EPSILON;
731
+ return Math.abs(e + s + i - this.area()) < p.EPSILON;
714
732
  }
715
733
  }
716
- function T(r) {
734
+ function _(r) {
717
735
  return new Promise((t) => setTimeout(t, r));
718
736
  }
719
- function F(r) {
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 M(r) {
750
+ function b(r) {
733
751
  return r !== null && (typeof r == "object" || typeof r == "function");
734
752
  }
735
- class G {
753
+ class F {
736
754
  map = /* @__PURE__ */ new Map();
737
755
  weakMap = /* @__PURE__ */ new WeakMap();
738
756
  set(t, e) {
739
- M(t) ? this.weakMap.set(t, e) : this.map.set(t, e);
757
+ b(t) ? this.weakMap.set(t, e) : this.map.set(t, e);
740
758
  }
741
759
  get(t) {
742
- return M(t) ? this.weakMap.get(t) : this.map.get(t);
760
+ return b(t) ? this.weakMap.get(t) : this.map.get(t);
743
761
  }
744
762
  has(t) {
745
- return M(t) ? this.weakMap.has(t) : this.map.has(t);
763
+ return b(t) ? this.weakMap.has(t) : this.map.has(t);
746
764
  }
747
765
  }
748
- function B(r) {
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 B(r) {
754
772
  }
755
773
  function e(s) {
756
774
  for (let i = t.length - 1; i >= 0; i--) {
757
- const n = t[i], o = n[t[i].length - 1];
758
- if (o < s) {
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 o > s && i === 0 && (t[i] = [s]);
779
+ } else h > s && i === 0 && (t[i] = [s]);
762
780
  }
763
781
  }
764
782
  return t[t.length - 1];
765
783
  }
766
- class X {
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 o of t)
787
- if (!e.has(o))
788
- throw new Error(`Invalid Roman numeral character: ${o}`);
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 o = t.slice(i, i + 2);
792
- if (this.ROMAN_MAP.has(o))
793
- s += this.ROMAN_MAP.get(o), i += 2;
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 h = t[i], u = this.ROMAN_MAP.get(h);
796
- if (!u)
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 += u, i += 1;
816
+ s += c, i += 1;
799
817
  }
800
818
  }
801
819
  if (this.toRoman(s) !== t)
@@ -814,7 +832,178 @@ class X {
814
832
  return e;
815
833
  }
816
834
  }
817
- function Q(r) {
835
+ class G {
836
+ static isValidPositiveInteger(t) {
837
+ return Number.isInteger(t) && t > 0 && t <= Number.MAX_SAFE_INTEGER;
838
+ }
839
+ static isPowerOfTwo(t) {
840
+ return t > 0 && (t & t - 1) === 0;
841
+ }
842
+ static isOdd(t) {
843
+ return t % 2 === 1 || t % 2 === -1;
844
+ }
845
+ static factorial(t) {
846
+ if (!this.isValidPositiveInteger(t))
847
+ throw new Error("Input must be a non-negative integer");
848
+ if (t < 2)
849
+ return 1;
850
+ let e = 1;
851
+ for (let s = 2; s <= t; s++)
852
+ e *= s;
853
+ return e;
854
+ }
855
+ static fibonacci(t, e = 1, s = 1) {
856
+ if (!this.isValidPositiveInteger(t))
857
+ throw new Error("Input must be a non-negative integer");
858
+ return t < 2 ? s : this.fibonacci(t - 1, s, s + e);
859
+ }
860
+ static fibonacciIterative(t) {
861
+ if (t < 2) return t;
862
+ let e = 0, s = 1;
863
+ for (let i = 2; i < t; i++)
864
+ [e, s] = [s, (e + s) % 1000000007];
865
+ return s;
866
+ }
867
+ static getPercentWithPrecision(t, e = 2) {
868
+ if (!Array.isArray(t) || t.length === 0)
869
+ return [];
870
+ if (e < 0 || !Number.isInteger(e))
871
+ throw new Error("Precision must be a non-negative integer");
872
+ const s = t.reduce((a, l) => a + l, 0);
873
+ if (s === 0)
874
+ return t.map(() => "0%");
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--;
883
+ }
884
+ return o.map((a) => `${(a / n * 100).toFixed(e)}%`);
885
+ }
886
+ static fastSqrt(t) {
887
+ if (t < 0)
888
+ throw new Error("n must be a non-negative number");
889
+ const e = 0.5 * t;
890
+ let s = new BigInt64Array(new Float32Array([t]).buffer)[0];
891
+ s = 0x1ff7a3bea91d9b1bn + (s >> 1n);
892
+ let i = new Float64Array(new BigInt64Array([s]).buffer)[0];
893
+ return i = i * 0.5 + e / i, i = i * 0.5 + e / i, i = i * 0.5 + e / i, i;
894
+ }
895
+ static gcd(t, e) {
896
+ return e === 0 ? t : this.gcd(e, t % e);
897
+ }
898
+ static lcm(t, e) {
899
+ return t * e / this.gcd(t, e);
900
+ }
901
+ static isPrime(t) {
902
+ if (t <= 1)
903
+ return !1;
904
+ for (let e = 2; e <= Math.sqrt(t); e++)
905
+ if (t % e === 0)
906
+ return !1;
907
+ return !0;
908
+ }
909
+ static isPalindrome(t) {
910
+ if (t < 0 || t % 10 === 0 && t !== 0)
911
+ return !1;
912
+ let e = 0, s = t;
913
+ for (; t > 0; ) {
914
+ const i = t % 10;
915
+ e = e * 10 + i, t = Math.floor(t / 10);
916
+ }
917
+ return s === e;
918
+ }
919
+ static isArmstrong(t) {
920
+ const e = t.toString(), s = e.length;
921
+ let i = 0;
922
+ for (let n = 0; n < s; n++)
923
+ i += Math.pow(parseInt(e[n]), s);
924
+ return i === t;
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
+ }
934
+ static isPerfect(t) {
935
+ let e = 0;
936
+ for (let s = 1; s < t; s++)
937
+ t % s === 0 && (e += s);
938
+ return e === t;
939
+ }
940
+ static middle(t, e) {
941
+ return e - (e - t >> 1);
942
+ }
943
+ static scale(t, e, s) {
944
+ if (e[0] >= e[1] || s[0] >= s[1])
945
+ throw new Error("Invalid range");
946
+ t = this.clamp(t, e[0], e[1]);
947
+ const i = e[1] - e[0];
948
+ return (t - e[0]) * ((s[1] - s[0]) / i) + s[0];
949
+ }
950
+ static clamp(t, e, s) {
951
+ return Math.min(Math.max(t, e), s);
952
+ }
953
+ static randomInt(t, e) {
954
+ return Math.floor(Math.random() * (e - t + 1)) + t;
955
+ }
956
+ static floatEqual(t, e, s = 1e-6) {
957
+ return Math.abs(t - e) < s;
958
+ }
959
+ static isSameSign(t, e) {
960
+ return t >= 0 && e >= 0 || t <= 0 && e <= 0;
961
+ }
962
+ }
963
+ class W {
964
+ static READ = 1;
965
+ static WRITE = 2;
966
+ static SHARE = 4;
967
+ static DELETE = 8;
968
+ static CREATE = 16;
969
+ static include(t, e) {
970
+ return (t & e) === e;
971
+ }
972
+ static add(t, e) {
973
+ return t | e;
974
+ }
975
+ static remove(t, e) {
976
+ return t & ~e;
977
+ }
978
+ static toggle(t, e) {
979
+ return t ^ e;
980
+ }
981
+ }
982
+ class X {
983
+ static longestCommonPrefix(t) {
984
+ if (!t.length) return "";
985
+ let e = t[0];
986
+ for (let s = 1; s < t.length; s++)
987
+ for (; !t[s].startsWith(e); )
988
+ if (e = e.slice(0, -1), e === "") return "";
989
+ return e;
990
+ }
991
+ static uuid(t) {
992
+ return typeof t == "number" ? (t ^ Math.random() * 16 >> t / 4).toString(16) : (9987e3 + -1e11).toString().replace(/[018]/g, (e) => {
993
+ const s = parseInt(e, 10);
994
+ return this.uuid(s);
995
+ });
996
+ }
997
+ }
998
+ class Q {
999
+ static isValidHex(t) {
1000
+ return /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t);
1001
+ }
1002
+ static isValidRGB(t) {
1003
+ return /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.test(t);
1004
+ }
1005
+ }
1006
+ function K(r) {
818
1007
  let t;
819
1008
  const e = new Proxy(r, {
820
1009
  construct(s, i, n) {
@@ -839,7 +1028,7 @@ const x = {
839
1028
  UI_HIDE_LOADING: "隐藏加载事件",
840
1029
  UI_SHOW_MESSAGE: "显示消息事件"
841
1030
  };
842
- class v {
1031
+ class I {
843
1032
  static instance = null;
844
1033
  listeners = {};
845
1034
  debugMode;
@@ -852,7 +1041,7 @@ class v {
852
1041
  }
853
1042
  // 单例模式
854
1043
  static getInstance(t) {
855
- return v.instance || (v.instance = new v(t)), v.instance;
1044
+ return I.instance || (I.instance = new I(t)), I.instance;
856
1045
  }
857
1046
  /**
858
1047
  * 添加事件监听器
@@ -912,231 +1101,11 @@ class v {
912
1101
  this.debugMode && console.log(`[EventEmitter] ${t}`, e || "");
913
1102
  }
914
1103
  }
915
- const b = {
916
- scriptRegex: /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
917
- javascriptRegex: /javascript:/gi,
918
- eventHandlerRegex: /on\w+\s*=/gi,
919
- allowedTags: /* @__PURE__ */ new Set([
920
- "div",
921
- "span",
922
- "p",
923
- "a",
924
- "img",
925
- "button",
926
- "input",
927
- "form",
928
- "label",
929
- "select",
930
- "option",
931
- "textarea",
932
- "ul",
933
- "ol",
934
- "li",
935
- "table",
936
- "tr",
937
- "td",
938
- "th",
939
- "thead",
940
- "tbody",
941
- "tfoot",
942
- "h1",
943
- "h2",
944
- "h3",
945
- "h4",
946
- "h5",
947
- "h6",
948
- "hr",
949
- "br",
950
- "section",
951
- "article",
952
- "nav",
953
- "header",
954
- "footer",
955
- "main",
956
- "aside",
957
- "figure",
958
- "figcaption"
959
- ]),
960
- allowedAttributes: /* @__PURE__ */ new Set(["class", "id", "href", "src", "alt", "title"])
961
- };
962
- class I {
963
- static instance;
964
- constructor() {
965
- }
966
- static getInstance() {
967
- return I.instance || (I.instance = new I()), I.instance;
968
- }
969
- /**
970
- * 创建DOM元素
971
- * @param tagName 标签名
972
- * @param attributes 属性对象
973
- * @param content 元素内容
974
- * @returns 创建的HTMLElement
975
- */
976
- createElement(t, e = {}, s = "") {
977
- if (!b.allowedTags.has(t.toLowerCase()))
978
- throw new Error(`Unsupported tag: ${t}`);
979
- const i = document.createElement(t);
980
- return this._processAttributes(i, e), this._processContent(i, s), i;
981
- }
982
- /**
983
- * 批量创建元素
984
- * @param items 元素配置数组
985
- * @param container 容器元素
986
- */
987
- createBatch(t, e) {
988
- const s = document.createDocumentFragment();
989
- t.forEach((i) => {
990
- const n = this.createElement(
991
- i.tag,
992
- i.attributes || {},
993
- i.content || ""
994
- );
995
- s.appendChild(n);
996
- }), e.appendChild(s);
997
- }
998
- /**
999
- * 安全地设置HTML内容
1000
- * @param element 目标元素
1001
- * @param html HTML字符串
1002
- */
1003
- setHtml(t, e) {
1004
- const s = this._sanitizeHtml(e);
1005
- t.innerHTML = s;
1006
- }
1007
- /**
1008
- * 处理元素属性
1009
- * @private
1010
- */
1011
- _processAttributes(t, e) {
1012
- Object.entries(e).forEach(([s, i]) => {
1013
- if (!b.allowedAttributes.has(s) && !s.startsWith("data-")) {
1014
- console.warn(`Potentially unsafe attribute: ${s}`);
1015
- return;
1016
- }
1017
- if (typeof i == "function")
1018
- s.startsWith("on") && t.addEventListener(
1019
- s.slice(2).toLowerCase(),
1020
- i
1021
- );
1022
- else
1023
- switch (s) {
1024
- case "className":
1025
- t.className = i;
1026
- break;
1027
- case "dataset":
1028
- Object.assign(t.dataset, i);
1029
- break;
1030
- case "style":
1031
- Object.assign(t.style, i);
1032
- break;
1033
- default:
1034
- t.setAttribute(s, i);
1035
- }
1036
- });
1037
- }
1038
- /**
1039
- * 处理元素内容
1040
- * @private
1041
- */
1042
- _processContent(t, e) {
1043
- typeof e == "string" ? t.textContent = e : e instanceof Node ? t.appendChild(e) : Array.isArray(e) && e.forEach((s) => {
1044
- typeof s == "string" ? t.appendChild(document.createTextNode(s)) : t.appendChild(s);
1045
- });
1046
- }
1047
- /**
1048
- * 清理HTML字符串
1049
- * @private
1050
- */
1051
- _sanitizeHtml(t) {
1052
- return t.replace(b.scriptRegex, "").replace(b.javascriptRegex, "").replace(b.eventHandlerRegex, "");
1053
- }
1054
- }
1055
- class K {
1056
- features;
1057
- constructor() {
1058
- this.features = this.detectFeatures();
1059
- }
1060
- detectFeatures() {
1061
- return {
1062
- geolocation: "geolocation" in navigator,
1063
- notification: "Notification" in window,
1064
- serviceWorker: "serviceWorker" in navigator,
1065
- webShare: "share" in navigator,
1066
- deviceOrientation: "DeviceOrientationEvent" in window,
1067
- battery: "getBattery" in navigator,
1068
- online: "onLine" in navigator
1069
- };
1070
- }
1071
- async getLocation(t = {}) {
1072
- if (!this.features.geolocation)
1073
- throw new Error("Geolocation is not supported");
1074
- const e = {
1075
- enableHighAccuracy: !0,
1076
- timeout: 10 * 1e3,
1077
- maximumAge: 300 * 1e3
1078
- };
1079
- return new Promise((s, i) => {
1080
- navigator.geolocation.getCurrentPosition(
1081
- (n) => s({
1082
- latitude: n.coords.latitude,
1083
- longitude: n.coords.longitude,
1084
- accuracy: n.coords.accuracy,
1085
- timstamp: n.timestamp
1086
- }),
1087
- (n) => {
1088
- const o = {
1089
- 1: "User denied the request for Geolocation.",
1090
- 2: "Position information is unavailable.",
1091
- 3: "The request to get user location timed out."
1092
- };
1093
- i(new Error(o[n.code] || "Unknown error"));
1094
- },
1095
- { ...e, ...t }
1096
- );
1097
- });
1098
- }
1099
- async sendNotification(t, e) {
1100
- if (!this.features.notification)
1101
- throw new Error("Notification is not supported");
1102
- if (Notification.permission === "default" && await Notification.requestPermission() !== "granted")
1103
- throw new Error("Notification permission is not granted");
1104
- if (Notification.permission !== "granted")
1105
- throw new Error("Notification permission is not granted");
1106
- return new Notification(t, {
1107
- icon: e.icon,
1108
- badge: e.badge,
1109
- ...e
1110
- });
1111
- }
1112
- async registerServiceWorker(t) {
1113
- if (!this.features.serviceWorker)
1114
- throw new Error("Service Worker is not supported");
1115
- try {
1116
- const e = await navigator.serviceWorker.register(t);
1117
- return console.log("Service Worker registered with scope:", e), e;
1118
- } catch (e) {
1119
- throw console.error("Service Worker registration failed:", e), e;
1120
- }
1121
- }
1122
- async shareContent(t) {
1123
- if (this.features.webShare)
1124
- try {
1125
- return await navigator.share(t), !0;
1126
- } catch (e) {
1127
- return e instanceof Error && e.name != "AbortError" && console.error("Error sharing content:", e), !1;
1128
- }
1129
- else
1130
- try {
1131
- return await navigator.clipboard.writeText(
1132
- t.url || t.text || ""
1133
- ), this.sendNotification("Copied to clipboard", {
1134
- body: "Link copied to clipboard"
1135
- }), !0;
1136
- } catch (e) {
1137
- return console.error("Error copying to clipboard:", e), !1;
1138
- }
1139
- }
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;
1140
1109
  }
1141
1110
  String.prototype.pointLength = function() {
1142
1111
  let r = 0;
@@ -1199,35 +1168,38 @@ Object.defineProperties(Element.prototype, {
1199
1168
  });
1200
1169
  Text.prototype.surround = function(r = "strong", t = "") {
1201
1170
  if (!this.nodeValue || !r || !t) return null;
1202
- const s = r.split("."), i = s[0], n = s.slice(1).join(" "), o = this.textContent.indexOf(t);
1203
- if (o < 0) return null;
1204
- const h = document.createRange();
1205
- h.setStart(this, o), h.setEnd(this, o + t.length);
1206
- const u = document.createElement(i);
1207
- return n && (u.className = n), h.surroundContents(u), u;
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;
1208
1177
  };
1209
1178
  export {
1210
- j as Dictionary,
1211
- I as DomHelper,
1212
- v as Emitter,
1213
- W as Graph,
1214
- B as LIS,
1215
- _ as LRU,
1216
- l as Line,
1217
- H as LinkedList,
1179
+ W as BitPerm,
1180
+ Q as Color,
1181
+ R as Dictionary,
1182
+ I as Emitter,
1183
+ $ as Graph,
1184
+ T as LIS,
1185
+ j as LRU,
1186
+ g as Line,
1187
+ U as LinkedList,
1218
1188
  E as Matrix,
1219
1189
  q as MaxHeap,
1220
- G as MemoizeMap,
1221
- P as MinHeap,
1222
- $ as MinStack,
1223
- a as Point,
1190
+ F as MemoizeMap,
1191
+ O as MinHeap,
1192
+ D as MinStack,
1193
+ G as Num,
1194
+ u as Point,
1224
1195
  V as Queue,
1225
- X as Roman,
1226
- U as Stack,
1227
- c as Triangle,
1228
- g as Vector,
1229
- K as WebAppManager,
1230
- F as isValidBracket,
1231
- Q as singleton,
1232
- T as sleep
1196
+ B as Roman,
1197
+ z as Stack,
1198
+ X as Str,
1199
+ p as Triangle,
1200
+ y as Vector,
1201
+ Z as binarySearchTemplate,
1202
+ H as isValidBracket,
1203
+ K as singleton,
1204
+ _ as sleep
1233
1205
  };