jc-structure 0.1.19 → 0.1.22

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