jc-structure 0.1.1 → 0.1.2

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 j {
2
2
  items = {};
3
3
  count = 0;
4
4
  lowestCount = 0;
@@ -30,7 +30,7 @@ class z {
30
30
  return this.isEmpty() ? "" : `Queue(size: ${this.size()}):[${this.items[this.lowestCount]},...rest]`;
31
31
  }
32
32
  }
33
- class j {
33
+ class U {
34
34
  items = {};
35
35
  count = 0;
36
36
  constructor() {
@@ -62,13 +62,13 @@ class j {
62
62
  return this.isEmpty() ? "" : `Stack(count: ${this.count}):[${this.items[this.count - 1]},...rest]`;
63
63
  }
64
64
  }
65
- function N(n, t) {
66
- return n === t ? 0 : n < t ? -1 : 1;
65
+ function O(r, t) {
66
+ return r === t ? 0 : r < t ? -1 : 1;
67
67
  }
68
- class g {
68
+ class m {
69
69
  heap = [];
70
70
  compareFn;
71
- constructor(t = N) {
71
+ constructor(t = O) {
72
72
  this.compareFn = t;
73
73
  }
74
74
  static getLeftIndex(t) {
@@ -99,7 +99,7 @@ class g {
99
99
  return this.heap.toString();
100
100
  }
101
101
  }
102
- class A extends g {
102
+ class P extends m {
103
103
  insert(t) {
104
104
  return t ? !1 : (this.heap.push(t), this.siftUp(this.heap.length - 1), !0);
105
105
  }
@@ -110,24 +110,24 @@ class A extends g {
110
110
  return this.heap[0] = this.heap.pop(), this.siftDown(0), t;
111
111
  }
112
112
  siftUp(t) {
113
- let e = t, s = g.getLeftIndex(e), i = g.getRightIndex(e), r = this.size();
114
- s < r && this.compareFn(this.heap[e], this.heap[s]) === -1 && (e = s), i < r && this.compareFn(this.heap[e], this.heap[i]) === 1 && (e = i), e !== t && (g.swap(this.heap, t, e), this.siftUp(e));
113
+ let e = t, s = m.getLeftIndex(e), i = m.getRightIndex(e), n = this.size();
114
+ 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 && (m.swap(this.heap, t, e), this.siftUp(e));
115
115
  }
116
116
  siftDown(t) {
117
- let e = g.getParentIndex(t);
117
+ let e = m.getParentIndex(t);
118
118
  for (; t > 0 && e && this.compareFn(this.heap[e], this.heap[t]) === 1; )
119
- g.swap(this.heap, e, t), t = e, e = g.getParentIndex(t);
119
+ m.swap(this.heap, e, t), t = e, e = m.getParentIndex(t);
120
120
  }
121
121
  }
122
- class R extends A {
123
- constructor(t = (e, s) => N(s, e)) {
122
+ class V extends P {
123
+ constructor(t = (e, s) => O(s, e)) {
124
124
  super(t);
125
125
  }
126
126
  }
127
- function C(n) {
128
- return { value: n };
127
+ function R(r) {
128
+ return { value: r };
129
129
  }
130
- class V {
130
+ class D {
131
131
  capacity;
132
132
  length = 0;
133
133
  head = null;
@@ -157,14 +157,14 @@ class V {
157
157
  }
158
158
  update(t, e) {
159
159
  let s = this.lookup.get(t);
160
- s ? (this.detach(s), this.prepend(s), s.value = e) : (s = C(e), this.length++, this.prepend(s), this.trimCache(), this.lookup.set(t, s), this.reverseLookup);
160
+ 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);
161
161
  }
162
162
  }
163
- let I = class {
163
+ let M = class {
164
164
  value;
165
165
  next = void 0;
166
166
  };
167
- class W {
167
+ class _ {
168
168
  count = 0;
169
169
  head = void 0;
170
170
  constructor() {
@@ -197,19 +197,19 @@ class W {
197
197
  return this.getElementAt(t)?.value;
198
198
  }
199
199
  insert(t, e) {
200
- let s = new I();
200
+ let s = new M();
201
201
  if (s.value = t, e > this.count || e < 0)
202
202
  throw new Error("index error");
203
203
  this.count++;
204
- let i, r;
204
+ let i, n;
205
205
  if (e === 0) {
206
206
  s.next = this.head, this.head = s;
207
207
  return;
208
208
  }
209
- i = this.getElementAt(e - 1), r = i.next, i.next = s, s.next = r;
209
+ i = this.getElementAt(e - 1), n = i.next, i.next = s, s.next = n;
210
210
  }
211
211
  push(t) {
212
- let e = new I();
212
+ let e = new M();
213
213
  if (e.value = t, this.count++, this.isEmpty()) {
214
214
  this.head = e;
215
215
  return;
@@ -243,17 +243,17 @@ class W {
243
243
  return t = t.slice(0, -1), t;
244
244
  }
245
245
  }
246
- class O {
246
+ class k {
247
247
  key;
248
248
  value;
249
249
  constructor(t, e) {
250
250
  this.key = t, this.value = e;
251
251
  }
252
252
  }
253
- function M(n, t = { emptyString: !1, zeroNumber: !1 }) {
254
- return n == null ? !(t.emptyString && n === "" || t.zeroNumber && n === 0) : !1;
253
+ function L(r, t = { emptyString: !1, zeroNumber: !1 }) {
254
+ return r == null ? !(t.emptyString && r === "" || t.zeroNumber && r === 0) : !1;
255
255
  }
256
- class k {
256
+ class z {
257
257
  table = [];
258
258
  constructor() {
259
259
  }
@@ -264,15 +264,15 @@ class k {
264
264
  return -1;
265
265
  }
266
266
  set(t, e) {
267
- if (M(t))
267
+ if (L(t))
268
268
  throw new Error("key is required");
269
- if (M(e))
269
+ if (L(e))
270
270
  throw new Error("value is required");
271
271
  if (this.has(t)) {
272
272
  let s = this.getItemIndex(t);
273
273
  this.table[s].value = e;
274
274
  } else {
275
- const s = new O(t, e);
275
+ const s = new k(t, e);
276
276
  this.table.push(s);
277
277
  }
278
278
  }
@@ -323,12 +323,12 @@ class k {
323
323
  return t = t.slice(0, -1), t;
324
324
  }
325
325
  }
326
- class D {
326
+ class q {
327
327
  isDirected;
328
328
  vertices;
329
329
  adjList;
330
330
  constructor(t = !1) {
331
- this.isDirected = t, this.vertices = [], this.adjList = new k();
331
+ this.isDirected = t, this.vertices = [], this.adjList = new z();
332
332
  }
333
333
  addVertex(t) {
334
334
  this.vertices.includes(t) || (this.vertices.push(t), this.adjList.set(t, []));
@@ -408,10 +408,10 @@ class f {
408
408
  return this.mul(-1);
409
409
  }
410
410
  }
411
- class y {
411
+ class x {
412
412
  _matrix;
413
413
  static zero(t, e) {
414
- return new y(
414
+ return new x(
415
415
  Array.from({ length: t }, () => Array.from({ length: e }, () => 0))
416
416
  );
417
417
  }
@@ -443,7 +443,7 @@ class y {
443
443
  return this._matrix[t[0]][t[1]] = e, this;
444
444
  }
445
445
  mul(t) {
446
- return new y(this._matrix.map((e) => e.map((s) => s * t)));
446
+ return new x(this._matrix.map((e) => e.map((s) => s * t)));
447
447
  }
448
448
  div(t) {
449
449
  return this.mul(1 / t);
@@ -451,9 +451,9 @@ class y {
451
451
  add(t) {
452
452
  if (this.row !== t.row || this.col !== t.col)
453
453
  throw new Error("Matrix dimensions do not match");
454
- return new y(
454
+ return new x(
455
455
  this._matrix.map(
456
- (e, s) => e.map((i, r) => i + t.getItem([s, r]))
456
+ (e, s) => e.map((i, n) => i + t.getItem([s, n]))
457
457
  )
458
458
  );
459
459
  }
@@ -469,23 +469,23 @@ class y {
469
469
  mulVector(t) {
470
470
  if (this.col !== t.dimension)
471
471
  throw new Error("Matrix dimensions do not match");
472
- return new y(
472
+ return new x(
473
473
  this._matrix.map((e) => e.map((s, i) => s * t.getItem(i)))
474
474
  );
475
475
  }
476
476
  mulMatrix(t) {
477
477
  if (this.col !== t.row)
478
478
  throw new Error("Matrix dimensions do not match");
479
- const e = y.zero(this.row, t.col);
479
+ const e = x.zero(this.row, t.col);
480
480
  for (let s = 0; s < this.row; s++) {
481
481
  const i = this.rowVector(s);
482
- for (let r = 0; r < this.col; r++)
483
- e.setItem([s, r], i.dot(t.colVector(r)));
482
+ for (let n = 0; n < this.col; n++)
483
+ e.setItem([s, n], i.dot(t.colVector(n)));
484
484
  }
485
485
  return e;
486
486
  }
487
487
  }
488
- class o {
488
+ class a {
489
489
  static distance(t, e) {
490
490
  return Math.hypot(e.x - t.x, e.y - t.y);
491
491
  }
@@ -495,47 +495,47 @@ class o {
495
495
  this.x = t, this.y = e;
496
496
  }
497
497
  distanceTo(t) {
498
- return o.distance(this, t);
498
+ return a.distance(this, t);
499
499
  }
500
500
  }
501
- class c {
501
+ class u {
502
502
  // 使用更合适的精度阈值常量
503
503
  static EPSILON = 1e-10;
504
504
  // 静态方法:计算斜率
505
505
  static sloped(t) {
506
506
  const e = t.p2.x - t.p1.x, s = t.p2.y - t.p1.y;
507
- return Math.abs(e) < c.EPSILON ? Math.abs(s) < c.EPSILON ? 0 : null : s / e;
507
+ return Math.abs(e) < u.EPSILON ? Math.abs(s) < u.EPSILON ? 0 : null : s / e;
508
508
  }
509
509
  // 静态方法:判断两条线是否平行
510
510
  static isParallel(t, e) {
511
- const s = c.sloped(t), i = c.sloped(e);
512
- return s === null && i === null ? !0 : s === null || i === null ? !1 : Math.abs(s - i) < c.EPSILON;
511
+ const s = u.sloped(t), i = u.sloped(e);
512
+ return s === null && i === null ? !0 : s === null || i === null ? !1 : Math.abs(s - i) < u.EPSILON;
513
513
  }
514
514
  // 静态方法:获取两条线的交点
515
515
  static getIntersection(t, e) {
516
- if (c.isParallel(t, e)) return null;
517
- const s = t.p1.x, i = t.p1.y, r = t.p2.x, a = t.p2.y, l = e.p1.x, u = e.p1.y, p = e.p2.x, m = e.p2.y, d = (s - r) * (u - m) - (i - a) * (l - p);
518
- if (Math.abs(d) < c.EPSILON) return null;
519
- const w = ((s - l) * (u - m) - (i - u) * (l - p)) / d, E = -((s - r) * (i - u) - (i - a) * (s - l)) / d;
520
- if (w >= 0 && w <= 1 && E >= 0 && E <= 1) {
521
- const P = s + w * (r - s), L = i + w * (a - i);
522
- return new o(P, L);
516
+ if (u.isParallel(t, e)) return null;
517
+ const s = t.p1.x, i = t.p1.y, n = t.p2.x, o = t.p2.y, l = e.p1.x, c = e.p1.y, p = e.p2.x, g = e.p2.y, d = (s - n) * (c - g) - (i - o) * (l - p);
518
+ if (Math.abs(d) < u.EPSILON) return null;
519
+ const w = ((s - l) * (c - g) - (i - c) * (l - p)) / d, I = -((s - n) * (i - c) - (i - o) * (s - l)) / d;
520
+ if (w >= 0 && w <= 1 && I >= 0 && I <= 1) {
521
+ const C = s + w * (n - s), A = i + w * (o - i);
522
+ return new a(C, A);
523
523
  }
524
524
  return null;
525
525
  }
526
526
  // 静态方法:判断两条线段是否相交
527
527
  static isIntersecting(t, e) {
528
- return c.getIntersection(t, e) !== null;
528
+ return u.getIntersection(t, e) !== null;
529
529
  }
530
530
  // 静态方法:计算点到线段的距离
531
531
  static distanceToPoint(t, e) {
532
- const s = e.x - t.p1.x, i = e.y - t.p1.y, r = t.p2.x - t.p1.x, a = t.p2.y - t.p1.y, l = s * r + i * a, u = r * r + a * a;
532
+ const s = e.x - t.p1.x, i = e.y - t.p1.y, n = t.p2.x - t.p1.x, o = t.p2.y - t.p1.y, l = s * n + i * o, c = n * n + o * o;
533
533
  let p = -1;
534
- u > c.EPSILON && (p = l / u);
535
- let m, d;
536
- p < 0 ? (m = t.p1.x, d = t.p1.y) : p > 1 ? (m = t.p2.x, d = t.p2.y) : (m = t.p1.x + p * r, d = t.p1.y + p * a);
537
- const w = e.x - m, E = e.y - d;
538
- return Math.hypot(w + E);
534
+ c > u.EPSILON && (p = l / c);
535
+ let g, d;
536
+ p < 0 ? (g = t.p1.x, d = t.p1.y) : p > 1 ? (g = t.p2.x, d = t.p2.y) : (g = t.p1.x + p * n, d = t.p1.y + p * o);
537
+ const w = e.x - g, I = e.y - d;
538
+ return Math.hypot(w + I);
539
539
  }
540
540
  p1;
541
541
  p2;
@@ -550,7 +550,7 @@ class c {
550
550
  // 获取线段中点
551
551
  get midpoint() {
552
552
  const t = (this.p1.x + this.p2.x) / 2, e = (this.p1.y + this.p2.y) / 2;
553
- return new o(t, e);
553
+ return new a(t, e);
554
554
  }
555
555
  // 获取线段的角度(弧度)
556
556
  get angle() {
@@ -559,24 +559,24 @@ class c {
559
559
  // 判断点是否在线段上
560
560
  containsPoint(t) {
561
561
  const e = (t.x - this.p1.x) * (this.p2.y - this.p1.y) - (t.y - this.p1.y) * (this.p2.x - this.p1.x);
562
- return Math.abs(e) > c.EPSILON ? !1 : (t.x - this.p1.x) * (t.x - this.p2.x) + (t.y - this.p1.y) * (t.y - this.p2.y) <= c.EPSILON;
562
+ return Math.abs(e) > u.EPSILON ? !1 : (t.x - this.p1.x) * (t.x - this.p2.x) + (t.y - this.p1.y) * (t.y - this.p2.y) <= u.EPSILON;
563
563
  }
564
564
  // 获取线段的方向向量
565
565
  get direction() {
566
566
  const t = this.length;
567
- if (t < c.EPSILON) return new o(0, 0);
567
+ if (t < u.EPSILON) return new a(0, 0);
568
568
  const e = (this.p2.x - this.p1.x) / t, s = (this.p2.y - this.p1.y) / t;
569
- return new o(e, s);
569
+ return new a(e, s);
570
570
  }
571
571
  }
572
- class S {
572
+ class N {
573
573
  static EPSILON = 1e-10;
574
574
  name;
575
575
  constructor(t) {
576
576
  this.name = t;
577
577
  }
578
578
  }
579
- class h extends S {
579
+ class h extends N {
580
580
  static isValid(t, e, s) {
581
581
  return t <= 0 || e <= 0 || s <= 0 ? !1 : t + e > s && t + s > e && e + s > t;
582
582
  }
@@ -589,14 +589,14 @@ class h extends S {
589
589
  static getType(t, e, s) {
590
590
  if (!h.isValid(t, e, s))
591
591
  throw new Error("Invalid triangle sides");
592
- const i = [t, e, s].sort((u, p) => u - p), [r, a, l] = i;
593
- return Math.abs(r - a) < h.EPSILON && Math.abs(a - l) < h.EPSILON ? "equilateral" : Math.abs(r - a) < h.EPSILON || Math.abs(a - l) < h.EPSILON ? "isosceles" : "scalene";
592
+ const i = [t, e, s].sort((c, p) => c - p), [n, o, l] = i;
593
+ return Math.abs(n - o) < h.EPSILON && Math.abs(o - l) < h.EPSILON ? "equilateral" : Math.abs(n - o) < h.EPSILON || Math.abs(o - l) < h.EPSILON ? "isosceles" : "scalene";
594
594
  }
595
595
  static getAngles(t, e, s) {
596
596
  if (!h.isValid(t, e, s))
597
597
  throw new Error("Invalid triangle sides");
598
- const i = Math.acos((e * e + s * s - t * t) / (2 * e * s)), r = Math.acos((t * t + s * s - e * e) / (2 * t * s)), a = Math.PI - i - r;
599
- return [i, r, a];
598
+ 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;
599
+ return [i, n, o];
600
600
  }
601
601
  p1;
602
602
  p2;
@@ -609,13 +609,13 @@ class h extends S {
609
609
  areCollinear() {
610
610
  return Math.abs(
611
611
  (this.p2.x - this.p1.x) * (this.p3.y - this.p1.y) - (this.p3.x - this.p1.x) * (this.p2.y - this.p1.y)
612
- ) < S.EPSILON;
612
+ ) < N.EPSILON;
613
613
  }
614
614
  get side() {
615
615
  return [
616
- o.distance(this.p1, this.p2),
617
- o.distance(this.p2, this.p3),
618
- o.distance(this.p3, this.p1)
616
+ a.distance(this.p1, this.p2),
617
+ a.distance(this.p2, this.p3),
618
+ a.distance(this.p3, this.p1)
619
619
  ];
620
620
  }
621
621
  perimeter() {
@@ -634,90 +634,90 @@ class h extends S {
634
634
  return h.getAngles(t, e, s);
635
635
  }
636
636
  get centroid() {
637
- return new o(
637
+ return new a(
638
638
  (this.p1.x + this.p2.x + this.p3.x) / 3,
639
639
  (this.p1.y + this.p2.y + this.p3.y) / 3
640
640
  );
641
641
  }
642
642
  get incenter() {
643
- const [t, e, s] = this.side, i = this.perimeter() / 2, r = (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;
644
- return new o(r, a);
643
+ 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;
644
+ return new a(n, o);
645
645
  }
646
646
  get circumcenter() {
647
647
  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));
648
648
  if (Math.abs(t) < h.EPSILON)
649
649
  throw new Error("Cannot calculate circumcenter for collinear points");
650
650
  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;
651
- return new o(e, s);
651
+ return new a(e, s);
652
652
  }
653
653
  containsPoint(t) {
654
654
  const e = h.area(
655
- o.distance(t, this.p1),
656
- o.distance(t, this.p2),
657
- o.distance(this.p1, this.p2)
655
+ a.distance(t, this.p1),
656
+ a.distance(t, this.p2),
657
+ a.distance(this.p1, this.p2)
658
658
  ), s = h.area(
659
- o.distance(t, this.p2),
660
- o.distance(t, this.p3),
661
- o.distance(this.p2, this.p3)
659
+ a.distance(t, this.p2),
660
+ a.distance(t, this.p3),
661
+ a.distance(this.p2, this.p3)
662
662
  ), i = h.area(
663
- o.distance(t, this.p3),
664
- o.distance(t, this.p1),
665
- o.distance(this.p3, this.p1)
663
+ a.distance(t, this.p3),
664
+ a.distance(t, this.p1),
665
+ a.distance(this.p3, this.p1)
666
666
  );
667
667
  return Math.abs(e + s + i - this.area()) < h.EPSILON;
668
668
  }
669
669
  }
670
- function F(n) {
671
- return new Promise((t) => setTimeout(t, n));
670
+ function H(r) {
671
+ return new Promise((t) => setTimeout(t, r));
672
672
  }
673
- function $(n) {
673
+ function W(r) {
674
674
  const t = [], e = {
675
675
  "(": ")",
676
676
  "[": "]",
677
677
  "{": "}"
678
678
  }, s = new Set(Object.values(e));
679
- for (const i of n)
679
+ for (const i of r)
680
680
  if (i in e)
681
681
  t.push(e[i]);
682
682
  else if (s.has(i) && i !== t.pop())
683
683
  return !1;
684
684
  return t.length === 0;
685
685
  }
686
- function b(n) {
687
- return n !== null && (typeof n == "object" || typeof n == "function");
686
+ function S(r) {
687
+ return r !== null && (typeof r == "object" || typeof r == "function");
688
688
  }
689
- class H {
689
+ class T {
690
690
  map = /* @__PURE__ */ new Map();
691
691
  weakMap = /* @__PURE__ */ new WeakMap();
692
692
  set(t, e) {
693
- b(t) ? this.weakMap.set(t, e) : this.map.set(t, e);
693
+ S(t) ? this.weakMap.set(t, e) : this.map.set(t, e);
694
694
  }
695
695
  get(t) {
696
- return b(t) ? this.weakMap.get(t) : this.map.get(t);
696
+ return S(t) ? this.weakMap.get(t) : this.map.get(t);
697
697
  }
698
698
  has(t) {
699
- return b(t) ? this.weakMap.has(t) : this.map.has(t);
699
+ return S(t) ? this.weakMap.has(t) : this.map.has(t);
700
700
  }
701
701
  }
702
- function U(n) {
703
- if (!n.length) return [];
704
- const t = [[n[0]]];
705
- for (let s = 1, i = n.length; s < i; s++) {
706
- const r = n[s];
707
- e(r);
702
+ function F(r) {
703
+ if (!r.length) return [];
704
+ const t = [[r[0]]];
705
+ for (let s = 1, i = r.length; s < i; s++) {
706
+ const n = r[s];
707
+ e(n);
708
708
  }
709
709
  function e(s) {
710
710
  for (let i = t.length - 1; i >= 0; i--) {
711
- const r = t[i], a = r[t[i].length - 1];
712
- if (a < s) {
713
- t[i + 1] = [...r, s];
711
+ const n = t[i], o = n[t[i].length - 1];
712
+ if (o < s) {
713
+ t[i + 1] = [...n, s];
714
714
  break;
715
- } else a > s && i === 0 && (t[i] = [s]);
715
+ } else o > s && i === 0 && (t[i] = [s]);
716
716
  }
717
717
  }
718
718
  return t[t.length - 1];
719
719
  }
720
- class B {
720
+ class G {
721
721
  static ROMAN_MAP = /* @__PURE__ */ new Map([
722
722
  ["M", 1e3],
723
723
  ["CM", 900],
@@ -737,19 +737,19 @@ class B {
737
737
  if (t.length === 0)
738
738
  throw new Error("Input cannot be empty");
739
739
  const e = /* @__PURE__ */ new Set(["I", "V", "X", "L", "C", "D", "M"]);
740
- for (const a of t)
741
- if (!e.has(a))
742
- throw new Error(`Invalid Roman numeral character: ${a}`);
740
+ for (const o of t)
741
+ if (!e.has(o))
742
+ throw new Error(`Invalid Roman numeral character: ${o}`);
743
743
  let s = 0, i = 0;
744
744
  for (; i < t.length; ) {
745
- const a = t.slice(i, i + 2);
746
- if (this.ROMAN_MAP.has(a))
747
- s += this.ROMAN_MAP.get(a), i += 2;
745
+ const o = t.slice(i, i + 2);
746
+ if (this.ROMAN_MAP.has(o))
747
+ s += this.ROMAN_MAP.get(o), i += 2;
748
748
  else {
749
- const l = t[i], u = this.ROMAN_MAP.get(l);
750
- if (!u)
749
+ const l = t[i], c = this.ROMAN_MAP.get(l);
750
+ if (!c)
751
751
  throw new Error(`Invalid Roman numeral sequence at position ${i}`);
752
- s += u, i += 1;
752
+ s += c, i += 1;
753
753
  }
754
754
  }
755
755
  if (this.toRoman(s) !== t)
@@ -768,20 +768,105 @@ class B {
768
768
  return e;
769
769
  }
770
770
  }
771
- function X(n) {
771
+ function B(r) {
772
772
  let t;
773
- const e = new Proxy(n, {
774
- construct(s, i, r) {
773
+ const e = new Proxy(r, {
774
+ construct(s, i, n) {
775
775
  return t || (t = Reflect.construct(
776
776
  s,
777
777
  i,
778
- r
778
+ n
779
779
  )), t;
780
780
  }
781
781
  });
782
- return n.prototype.constructor = e, e;
782
+ return r.prototype.constructor = e, e;
783
+ }
784
+ const y = {
785
+ AUTH_UNAUTHORIZED: "未授权事件",
786
+ AUTH_LOGIN_SUCCESS: "登录成功事件",
787
+ AUTH_LOGOUT: "注销事件",
788
+ AUTH_TOKEN_EXPIRED: "令牌过期事件",
789
+ REQUEST_ERROR: "请求错误事件",
790
+ REQUEST_TIMEOUT: "请求超时事件",
791
+ REQUEST_NETWORK_ERROR: "网络错误事件",
792
+ UI_SHOW_LOADING: "显示加载事件",
793
+ UI_HIDE_LOADING: "隐藏加载事件",
794
+ UI_SHOW_MESSAGE: "显示消息事件"
795
+ };
796
+ class b {
797
+ static instance = null;
798
+ listeners = {};
799
+ debugMode;
800
+ constructor(t = !1) {
801
+ this.debugMode = t, Object.keys(y).forEach(
802
+ (e) => {
803
+ this.listeners[e] = /* @__PURE__ */ new Set();
804
+ }
805
+ );
806
+ }
807
+ // 单例模式
808
+ static getInstance(t) {
809
+ return b.instance || (b.instance = new b(t)), b.instance;
810
+ }
811
+ /**
812
+ * 添加事件监听器
813
+ * @param event 事件名称
814
+ * @param listener 监听函数
815
+ */
816
+ on(t, e) {
817
+ this.debugLog(`添加事件监听: ${y[t]}`), this.listeners[t].add(e);
818
+ }
819
+ /**
820
+ * 触发事件
821
+ * @param event 事件名称
822
+ * @param params 事件参数
823
+ */
824
+ emit(t, e) {
825
+ this.debugLog(`触发事件: ${y[t]}`, e), this.listeners[t].forEach((s) => {
826
+ try {
827
+ s(e);
828
+ } catch (i) {
829
+ console.error(`事件 ${y[t]} 处理出错:`, i);
830
+ }
831
+ });
832
+ }
833
+ /**
834
+ * 移除事件监听器
835
+ * @param event 事件名称
836
+ * @param listener 监听函数
837
+ */
838
+ off(t, e) {
839
+ this.debugLog(`移除事件监听: ${y[t]}`), this.listeners[t].delete(e);
840
+ }
841
+ /**
842
+ * 添加一次性事件监听器
843
+ * @param event 事件名称
844
+ * @param listener 监听函数
845
+ */
846
+ once(t, e) {
847
+ this.debugLog(`添加一次性事件监听: ${y[t]}`);
848
+ const s = (i) => {
849
+ e(i), this.off(t, s);
850
+ };
851
+ this.on(t, s);
852
+ }
853
+ /**
854
+ * 清除所有事件监听器
855
+ */
856
+ clear() {
857
+ this.debugLog("清除所有事件监听器"), Object.values(this.listeners).forEach((t) => t.clear());
858
+ }
859
+ /**
860
+ * 获取指定事件的监听器数量
861
+ */
862
+ getListenerCount(t) {
863
+ return this.listeners[t].size;
864
+ }
865
+ debugLog(t, e) {
866
+ this.debugMode && console.log(`[EventEmitter] ${t}`, e || "");
867
+ }
783
868
  }
784
- const x = {
869
+ const E = {
785
870
  scriptRegex: /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
786
871
  javascriptRegex: /javascript:/gi,
787
872
  eventHandlerRegex: /on\w+\s*=/gi,
@@ -843,7 +928,7 @@ class v {
843
928
  * @returns 创建的HTMLElement
844
929
  */
845
930
  createElement(t, e = {}, s = "") {
846
- if (!x.allowedTags.has(t.toLowerCase()))
931
+ if (!E.allowedTags.has(t.toLowerCase()))
847
932
  throw new Error(`Unsupported tag: ${t}`);
848
933
  const i = document.createElement(t);
849
934
  return this._processAttributes(i, e), this._processContent(i, s), i;
@@ -856,12 +941,12 @@ class v {
856
941
  createBatch(t, e) {
857
942
  const s = document.createDocumentFragment();
858
943
  t.forEach((i) => {
859
- const r = this.createElement(
944
+ const n = this.createElement(
860
945
  i.tag,
861
946
  i.attributes || {},
862
947
  i.content || ""
863
948
  );
864
- s.appendChild(r);
949
+ s.appendChild(n);
865
950
  }), e.appendChild(s);
866
951
  }
867
952
  /**
@@ -879,7 +964,7 @@ class v {
879
964
  */
880
965
  _processAttributes(t, e) {
881
966
  Object.entries(e).forEach(([s, i]) => {
882
- if (!x.allowedAttributes.has(s) && !s.startsWith("data-")) {
967
+ if (!E.allowedAttributes.has(s) && !s.startsWith("data-")) {
883
968
  console.warn(`Potentially unsafe attribute: ${s}`);
884
969
  return;
885
970
  }
@@ -918,10 +1003,10 @@ class v {
918
1003
  * @private
919
1004
  */
920
1005
  _sanitizeHtml(t) {
921
- return t.replace(x.scriptRegex, "").replace(x.javascriptRegex, "").replace(x.eventHandlerRegex, "");
1006
+ return t.replace(E.scriptRegex, "").replace(E.javascriptRegex, "").replace(E.eventHandlerRegex, "");
922
1007
  }
923
1008
  }
924
- class G {
1009
+ class X {
925
1010
  features;
926
1011
  constructor() {
927
1012
  this.features = this.detectFeatures();
@@ -947,19 +1032,19 @@ class G {
947
1032
  };
948
1033
  return new Promise((s, i) => {
949
1034
  navigator.geolocation.getCurrentPosition(
950
- (r) => s({
951
- latitude: r.coords.latitude,
952
- longitude: r.coords.longitude,
953
- accuracy: r.coords.accuracy,
954
- timstamp: r.timestamp
1035
+ (n) => s({
1036
+ latitude: n.coords.latitude,
1037
+ longitude: n.coords.longitude,
1038
+ accuracy: n.coords.accuracy,
1039
+ timstamp: n.timestamp
955
1040
  }),
956
- (r) => {
957
- const a = {
1041
+ (n) => {
1042
+ const o = {
958
1043
  1: "User denied the request for Geolocation.",
959
1044
  2: "Position information is unavailable.",
960
1045
  3: "The request to get user location timed out."
961
1046
  };
962
- i(new Error(a[r.code] || "Unknown error"));
1047
+ i(new Error(o[n.code] || "Unknown error"));
963
1048
  },
964
1049
  { ...e, ...t }
965
1050
  );
@@ -1007,26 +1092,95 @@ class G {
1007
1092
  }
1008
1093
  }
1009
1094
  }
1095
+ String.prototype.pointLength = function() {
1096
+ let r = 0;
1097
+ for (let t = 0, e = this.length; t < e; ) {
1098
+ const s = this.codePointAt(t);
1099
+ t += s > 65535 ? 2 : 1, r++;
1100
+ }
1101
+ return r;
1102
+ };
1103
+ String.prototype.pointAt = function(r) {
1104
+ if (r >= this.pointLength()) return;
1105
+ let t = 0;
1106
+ for (let e = 0, s = this.length; e < s; ) {
1107
+ const i = this.codePointAt(e);
1108
+ if (!i) return;
1109
+ if (t === r)
1110
+ return String.fromCodePoint(i);
1111
+ e += i > 65535 ? 2 : 1, t++;
1112
+ }
1113
+ };
1114
+ String.prototype.sliceByPoint = function(r, t = this.pointLength()) {
1115
+ let e = "";
1116
+ for (let s = r; s < t; s++)
1117
+ e += this.pointAt(s);
1118
+ return e;
1119
+ };
1120
+ RegExp.escape = function(r) {
1121
+ return r.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1122
+ };
1123
+ Element.prototype.farthest = function(r) {
1124
+ if (typeof r != "string" || !r) return null;
1125
+ let t = null, e = this;
1126
+ for (; e; ) {
1127
+ const s = e.closest(r);
1128
+ if (!s)
1129
+ break;
1130
+ t = s, e = s.parentElement;
1131
+ }
1132
+ return t;
1133
+ };
1134
+ Object.defineProperties(Element.prototype, {
1135
+ firstElement: {
1136
+ get: function() {
1137
+ if (!this.children.length) return null;
1138
+ let r = this.firstElementChild, t = null;
1139
+ for (; r; )
1140
+ t = r, r = r.firstElementChild;
1141
+ return t;
1142
+ }
1143
+ },
1144
+ lastElement: {
1145
+ get: function() {
1146
+ if (!this.children.length) return null;
1147
+ let r = this.lastElementChild, t = null;
1148
+ for (; r; )
1149
+ t = r, r = r.lastElementChild;
1150
+ return t;
1151
+ }
1152
+ }
1153
+ });
1154
+ Text.prototype.surround = function(r = "strong", t = "") {
1155
+ if (!this.nodeValue || !r || !t) return null;
1156
+ const s = r.split("."), i = s[0], n = s.slice(1).join(" "), o = this.textContent.indexOf(t);
1157
+ if (o < 0) return null;
1158
+ const l = document.createRange();
1159
+ l.setStart(this, o), l.setEnd(this, o + t.length);
1160
+ const c = document.createElement(i);
1161
+ return n && (c.className = n), l.surroundContents(c), c;
1162
+ };
1010
1163
  export {
1011
- k as Dictionary,
1164
+ z as Dictionary,
1012
1165
  v as DomHelper,
1013
- D as Graph,
1014
- U as LIS,
1015
- V as LRU,
1016
- c as Line,
1017
- W as LinkedList,
1018
- y as Matrix,
1019
- R as MaxHeap,
1020
- H as MemoizeMap,
1021
- A as MinHeap,
1022
- o as Point,
1023
- z as Queue,
1024
- B as Roman,
1025
- j as Stack,
1166
+ b as Emitter,
1167
+ q as Graph,
1168
+ F as LIS,
1169
+ D as LRU,
1170
+ u as Line,
1171
+ _ as LinkedList,
1172
+ x as Matrix,
1173
+ V as MaxHeap,
1174
+ T as MemoizeMap,
1175
+ P as MinHeap,
1176
+ a as Point,
1177
+ j as Queue,
1178
+ G as Roman,
1179
+ U as Stack,
1026
1180
  h as Triangle,
1027
1181
  f as Vector,
1028
- G as WebAppManager,
1029
- $ as isValidBracket,
1030
- X as singleton,
1031
- F as sleep
1182
+ X as WebAppManager,
1183
+ W as isValidBracket,
1184
+ B as singleton,
1185
+ H as sleep
1032
1186
  };
@@ -1,2 +1,2 @@
1
- (function(o,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(o=typeof globalThis<"u"?globalThis:o||self,E(o["jc-structure"]={}))})(this,(function(o){"use strict";class E{items={};count=0;lowestCount=0;constructor(){}dequeue(){if(this.isEmpty())return;const t=this.items[this.lowestCount];return delete this.items[this.lowestCount],this.lowestCount++,t}enqueue(...t){t.forEach(e=>{this.items[this.count]=e,this.count++})}front(){return this.isEmpty()?void 0:this.items[this.lowestCount]}isEmpty(){return this.size()===0}size(){return this.count-this.lowestCount}clear(){this.items={},this.count=0,this.lowestCount=0}toString(){return this.isEmpty()?"":`Queue(size: ${this.size()}):[${this.items[this.lowestCount]},...rest]`}}class O{items={};count=0;constructor(){}pop(){if(this.isEmpty())return;this.count--;const t=this.items[this.count];return delete this.items[this.count],t}push(...t){t.forEach(e=>{this.items[this.count]=e,this.count++})}peek(){return this.isEmpty()?void 0:this.items[this.count-1]}isEmpty(){return this.count===0}size(){return this.count}clear(){this.items={},this.count=0}toString(){return this.isEmpty()?"":`Stack(count: ${this.count}):[${this.items[this.count-1]},...rest]`}}function S(n,t){return n===t?0:n<t?-1:1}class g{heap=[];compareFn;constructor(t=S){this.compareFn=t}static getLeftIndex(t){return 2*t+1}static getRightIndex(t){return 2*t+2}static getParentIndex(t){return t===0?void 0:Math.floor((t-1)/2)}static swap(t,e,s){[t[e],t[s]]=[t[s],t[e]]}find(){return this.isEmpty()?void 0:this.heap[0]}size(){return this.heap.length}isEmpty(){return this.size()===0}clear(){this.heap=[]}toString(){return this.heap.toString()}}class L extends g{insert(t){return t?!1:(this.heap.push(t),this.siftUp(this.heap.length-1),!0)}extract(){if(this.isEmpty())return;if(this.heap.length===1)return this.heap.shift();const t=this.heap[0];return this.heap[0]=this.heap.pop(),this.siftDown(0),t}siftUp(t){let e=t,s=g.getLeftIndex(e),i=g.getRightIndex(e),r=this.size();s<r&&this.compareFn(this.heap[e],this.heap[s])===-1&&(e=s),i<r&&this.compareFn(this.heap[e],this.heap[i])===1&&(e=i),e!==t&&(g.swap(this.heap,t,e),this.siftUp(e))}siftDown(t){let e=g.getParentIndex(t);for(;t>0&&e&&this.compareFn(this.heap[e],this.heap[t])===1;)g.swap(this.heap,e,t),t=e,e=g.getParentIndex(t)}}class k extends L{constructor(t=(e,s)=>S(s,e)){super(t)}}function z(n){return{value:n}}class j{capacity;length=0;head=null;tail=null;lookup=new Map;reverseLookup=new Map;constructor(t=10){this.capacity=t}prepend(t){this.head?(t.next=this.head,this.head.prev=t,this.head=t):this.head=this.tail=t}detach(t){t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),this.head===t&&(this.head=this.head.next||null),this.tail===t&&(this.tail=this.tail.prev||null),t.next=void 0,t.prev=void 0}trimCache(){if(this.length<=this.capacity)return;const t=this.tail;this.detach(t);const e=this.reverseLookup.get(t);this.lookup.delete(e),this.reverseLookup.delete(t),this.length--}get(t){const e=this.lookup.get(t);if(e)return this.detach(e),this.prepend(e),e.value}update(t,e){let s=this.lookup.get(t);s?(this.detach(s),this.prepend(s),s.value=e):(s=z(e),this.length++,this.prepend(s),this.trimCache(),this.lookup.set(t,s),this.reverseLookup)}}let N=class{value;next=void 0};class R{count=0;head=void 0;constructor(){}indexOf(t){let e=this.head,s=0,i=!1;for(;e;){if(this.equals(e.value,t)){i=!0;break}s++,e=e.next}return i?s:-1}equals(t,e){return!1}getElementAt(t){if(t<0||t>=this.count)return;if(t===0)return this.head;let e=this.head;for(let s=0;s<t;s++)e=e?.next;return e}getValueAt(t){return this.getElementAt(t)?.value}insert(t,e){let s=new N;if(s.value=t,e>this.count||e<0)throw new Error("index error");this.count++;let i,r;if(e===0){s.next=this.head,this.head=s;return}i=this.getElementAt(e-1),r=i.next,i.next=s,s.next=r}push(t){let e=new N;if(e.value=t,this.count++,this.isEmpty()){this.head=e;return}let s=this.getElementAt(this.count-1);s.next=e}remove(t){const e=this.indexOf(t);return e===-1?void 0:this.removeAt(e)}removeAt(t){if(this.isEmpty()||t<0||t>=this.count)return;let e=this.getElementAt(t),s=this.getElementAt(t-1),i=e?.next;return t===0&&(this.head=i),s&&(s.next=i),this.count--,e?.value}isEmpty(){return this.count===0}size(){return this.count}clear(){this.count=0,this.head=void 0}toString(){let t="",e=this.head;for(;e;)t+=e.value,t+=",",e=e.next;return t=t.slice(0,-1),t}}class V{key;value;constructor(t,e){this.key=t,this.value=e}}function P(n,t={emptyString:!1,zeroNumber:!1}){return n==null?!(t.emptyString&&n===""||t.zeroNumber&&n===0):!1}class A{table=[];constructor(){}getItemIndex(t){for(let e=0,s=this.table.length;e<s;e++)if(this.table[e].key===t)return e;return-1}set(t,e){if(P(t))throw new Error("key is required");if(P(e))throw new Error("value is required");if(this.has(t)){let s=this.getItemIndex(t);this.table[s].value=e}else{const s=new V(t,e);this.table.push(s)}}remove(t){if(this.has(t)){let e=this.getItemIndex(t);return this.table.splice(e,1)[0]}}has(t){return this.getItemIndex(t)!==-1}get(t){if(this.has(t)){let e=this.getItemIndex(t);return this.table[e]}}keys(){return this.table.map(t=>t.key)}values(){return this.table.map(t=>t.value)}keyValues(){return this.table.map(t=>[t.key,t.value])}forEach(t){for(let e=0,s=this.size();e<s;e++){let i=this.table[e];if(!t(i.key,i.value))break}}isEmpty(){return!this.size()}size(){return this.table.length}clear(){this.table=[]}toString(){let t="";for(let e=0,s=this.table.length;e<s;e++)t+=this.table[e].toString(),t+=",";return t=t.slice(0,-1),t}}class q{isDirected;vertices;adjList;constructor(t=!1){this.isDirected=t,this.vertices=[],this.adjList=new A}addVertex(t){this.vertices.includes(t)||(this.vertices.push(t),this.adjList.set(t,[]))}addEdge(t,e){this.adjList.get(t)||this.addVertex(t),this.adjList.get(e)||this.addVertex(e),this.adjList.get(t)?.value.indexOf(e)===-1&&this.adjList.get(t)?.value.push(e),this.isDirected||this.adjList.get(e)?.value.indexOf(t)===-1&&this.adjList.get(e)?.value.push(t)}getVertices(){return this.vertices}getAdjacencyList(){return this.adjList}toString(){let t="";for(let e=0;e<this.vertices.length;e++)t+=this.vertices[e]+"-->",t+=this.adjList.get(this.vertices[e])?.toString()||"",t+=`
2
- `;return t}}class f{_data;static zero(t){return new f(...Array(t).fill(0))}constructor(...t){this._data=t}get dimension(){return this._data.length}get norm(){return Math.hypot(...this._data)}getItem(t){return this._data[t]}normalize(){const t=this.norm;if(t===0)throw new Error("Cannot normalize a zero vector");const e=this._data.map(s=>s/t);return new f(...e)}add(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to add");const e=this._data.map((s,i)=>s+t._data[i]);return new f(...e)}sub(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to subtract");const e=this._data.map((s,i)=>s-t._data[i]);return new f(...e)}mul(t){return new f(...this._data.map(e=>e*t))}dot(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to dot product");return this._data.reduce((e,s,i)=>e+s*t._data[i],0)}pos(){return this.mul(1)}neg(){return this.mul(-1)}}class w{_matrix;static zero(t,e){return new w(Array.from({length:t},()=>Array.from({length:e},()=>0)))}constructor(t){this._matrix=t}get shape(){return[this._matrix.length,this._matrix[0].length]}get row(){return this.shape[0]}get col(){return this.shape[1]}get size(){return this.row*this.col}rowVector(t){return new f(...this._matrix[t])}colVector(t){return new f(...this._matrix.map(e=>e[t]))}getItem(t){return this._matrix[t[0]][t[1]]}setItem(t,e){return this._matrix[t[0]][t[1]]=e,this}mul(t){return new w(this._matrix.map(e=>e.map(s=>s*t)))}div(t){return this.mul(1/t)}add(t){if(this.row!==t.row||this.col!==t.col)throw new Error("Matrix dimensions do not match");return new w(this._matrix.map((e,s)=>e.map((i,r)=>i+t.getItem([s,r]))))}sub(t){return this.add(t.neg())}pos(){return this.mul(1)}neg(){return this.mul(-1)}mulVector(t){if(this.col!==t.dimension)throw new Error("Matrix dimensions do not match");return new w(this._matrix.map(e=>e.map((s,i)=>s*t.getItem(i))))}mulMatrix(t){if(this.col!==t.row)throw new Error("Matrix dimensions do not match");const e=w.zero(this.row,t.col);for(let s=0;s<this.row;s++){const i=this.rowVector(s);for(let r=0;r<this.col;r++)e.setItem([s,r],i.dot(t.colVector(r)))}return e}}class h{static distance(t,e){return Math.hypot(e.x-t.x,e.y-t.y)}x;y;constructor(t,e){this.x=t,this.y=e}distanceTo(t){return h.distance(this,t)}}class u{static EPSILON=1e-10;static sloped(t){const e=t.p2.x-t.p1.x,s=t.p2.y-t.p1.y;return Math.abs(e)<u.EPSILON?Math.abs(s)<u.EPSILON?0:null:s/e}static isParallel(t,e){const s=u.sloped(t),i=u.sloped(e);return s===null&&i===null?!0:s===null||i===null?!1:Math.abs(s-i)<u.EPSILON}static getIntersection(t,e){if(u.isParallel(t,e))return null;const s=t.p1.x,i=t.p1.y,r=t.p2.x,a=t.p2.y,p=e.p1.x,l=e.p1.y,d=e.p2.x,y=e.p2.y,m=(s-r)*(l-y)-(i-a)*(p-d);if(Math.abs(m)<u.EPSILON)return null;const v=((s-p)*(l-y)-(i-l)*(p-d))/m,I=-((s-r)*(i-l)-(i-a)*(s-p))/m;if(v>=0&&v<=1&&I>=0&&I<=1){const X=s+v*(r-s),G=i+v*(a-i);return new h(X,G)}return null}static isIntersecting(t,e){return u.getIntersection(t,e)!==null}static distanceToPoint(t,e){const s=e.x-t.p1.x,i=e.y-t.p1.y,r=t.p2.x-t.p1.x,a=t.p2.y-t.p1.y,p=s*r+i*a,l=r*r+a*a;let d=-1;l>u.EPSILON&&(d=p/l);let y,m;d<0?(y=t.p1.x,m=t.p1.y):d>1?(y=t.p2.x,m=t.p2.y):(y=t.p1.x+d*r,m=t.p1.y+d*a);const v=e.x-y,I=e.y-m;return Math.hypot(v+I)}p1;p2;constructor(t,e){this.p1=t,this.p2=e}get length(){const t=this.p2.x-this.p1.x,e=this.p2.y-this.p1.y;return Math.sqrt(t*t+e*e)}get midpoint(){const t=(this.p1.x+this.p2.x)/2,e=(this.p1.y+this.p2.y)/2;return new h(t,e)}get angle(){return Math.atan2(this.p2.y-this.p1.y,this.p2.x-this.p1.x)}containsPoint(t){const e=(t.x-this.p1.x)*(this.p2.y-this.p1.y)-(t.y-this.p1.y)*(this.p2.x-this.p1.x);return Math.abs(e)>u.EPSILON?!1:(t.x-this.p1.x)*(t.x-this.p2.x)+(t.y-this.p1.y)*(t.y-this.p2.y)<=u.EPSILON}get direction(){const t=this.length;if(t<u.EPSILON)return new h(0,0);const e=(this.p2.x-this.p1.x)/t,s=(this.p2.y-this.p1.y)/t;return new h(e,s)}}class C{static EPSILON=1e-10;name;constructor(t){this.name=t}}class c extends C{static isValid(t,e,s){return t<=0||e<=0||s<=0?!1:t+e>s&&t+s>e&&e+s>t}static area(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle");const i=(t+e+s)/2;return Math.sqrt(i*(i-t)*(i-e)*(i-s))}static getType(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=[t,e,s].sort((l,d)=>l-d),[r,a,p]=i;return Math.abs(r-a)<c.EPSILON&&Math.abs(a-p)<c.EPSILON?"equilateral":Math.abs(r-a)<c.EPSILON||Math.abs(a-p)<c.EPSILON?"isosceles":"scalene"}static getAngles(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=Math.acos((e*e+s*s-t*t)/(2*e*s)),r=Math.acos((t*t+s*s-e*e)/(2*t*s)),a=Math.PI-i-r;return[i,r,a]}p1;p2;p3;constructor(t,e,s,i="triangle"){if(super(i),this.p1=t,this.p2=e,this.p3=s,this.areCollinear())throw new Error("Points are collinear, cannot form a triangle")}areCollinear(){return Math.abs((this.p2.x-this.p1.x)*(this.p3.y-this.p1.y)-(this.p3.x-this.p1.x)*(this.p2.y-this.p1.y))<C.EPSILON}get side(){return[h.distance(this.p1,this.p2),h.distance(this.p2,this.p3),h.distance(this.p3,this.p1)]}perimeter(){return c.isValid(this.side[0],this.side[1],this.side[2]),this.side.reduce((t,e)=>t+e,0)}area(){const[t,e,s]=this.side;return c.area(t,e,s)}get type(){const[t,e,s]=this.side;return c.getType(t,e,s)}get angles(){const[t,e,s]=this.side;return c.getAngles(t,e,s)}get centroid(){return new h((this.p1.x+this.p2.x+this.p3.x)/3,(this.p1.y+this.p2.y+this.p3.y)/3)}get incenter(){const[t,e,s]=this.side,i=this.perimeter()/2,r=(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;return new h(r,a)}get circumcenter(){const t=2*(this.p1.x*(this.p2.y-this.p3.y)+this.p2.x*(this.p3.y-this.p1.y)+this.p3.x*(this.p1.y-this.p2.y));if(Math.abs(t)<c.EPSILON)throw new Error("Cannot calculate circumcenter for collinear points");const e=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p2.y-this.p3.y)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p3.y-this.p1.y)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p1.y-this.p2.y))/t,s=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p3.x-this.p2.x)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p1.x-this.p3.x)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p2.x-this.p1.x))/t;return new h(e,s)}containsPoint(t){const e=c.area(h.distance(t,this.p1),h.distance(t,this.p2),h.distance(this.p1,this.p2)),s=c.area(h.distance(t,this.p2),h.distance(t,this.p3),h.distance(this.p2,this.p3)),i=c.area(h.distance(t,this.p3),h.distance(t,this.p1),h.distance(this.p3,this.p1));return Math.abs(e+s+i-this.area())<c.EPSILON}}function D(n){return new Promise(t=>setTimeout(t,n))}function W(n){const t=[],e={"(":")","[":"]","{":"}"},s=new Set(Object.values(e));for(const i of n)if(i in e)t.push(e[i]);else if(s.has(i)&&i!==t.pop())return!1;return t.length===0}function M(n){return n!==null&&(typeof n=="object"||typeof n=="function")}class H{map=new Map;weakMap=new WeakMap;set(t,e){M(t)?this.weakMap.set(t,e):this.map.set(t,e)}get(t){return M(t)?this.weakMap.get(t):this.map.get(t)}has(t){return M(t)?this.weakMap.has(t):this.map.has(t)}}function F(n){if(!n.length)return[];const t=[[n[0]]];for(let s=1,i=n.length;s<i;s++){const r=n[s];e(r)}function e(s){for(let i=t.length-1;i>=0;i--){const r=t[i],a=r[t[i].length-1];if(a<s){t[i+1]=[...r,s];break}else a>s&&i===0&&(t[i]=[s])}}return t[t.length-1]}class ${static ROMAN_MAP=new Map([["M",1e3],["CM",900],["D",500],["CD",400],["C",100],["XC",90],["L",50],["XL",40],["X",10],["IX",9],["V",5],["IV",4],["I",1]]);static toInteger(t){if(t.length===0)throw new Error("Input cannot be empty");const e=new Set(["I","V","X","L","C","D","M"]);for(const a of t)if(!e.has(a))throw new Error(`Invalid Roman numeral character: ${a}`);let s=0,i=0;for(;i<t.length;){const a=t.slice(i,i+2);if(this.ROMAN_MAP.has(a))s+=this.ROMAN_MAP.get(a),i+=2;else{const p=t[i],l=this.ROMAN_MAP.get(p);if(!l)throw new Error(`Invalid Roman numeral sequence at position ${i}`);s+=l,i+=1}}if(this.toRoman(s)!==t)throw new Error("Invalid Roman numeral sequence");return s}static toRoman(t){if(t<=0||t>=4e3)throw new Error("Number must be between 1 and 3999");if(!Number.isInteger(t))throw new Error("Number must be an integer");let e="";for(const[s,i]of this.ROMAN_MAP)for(;t>=i;)e+=s,t-=i;return e}}function U(n){let t;const e=new Proxy(n,{construct(s,i,r){return t||(t=Reflect.construct(s,i,r)),t}});return n.prototype.constructor=e,e}const b={scriptRegex:/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,javascriptRegex:/javascript:/gi,eventHandlerRegex:/on\w+\s*=/gi,allowedTags:new Set(["div","span","p","a","img","button","input","form","label","select","option","textarea","ul","ol","li","table","tr","td","th","thead","tbody","tfoot","h1","h2","h3","h4","h5","h6","hr","br","section","article","nav","header","footer","main","aside","figure","figcaption"]),allowedAttributes:new Set(["class","id","href","src","alt","title"])};class x{static instance;constructor(){}static getInstance(){return x.instance||(x.instance=new x),x.instance}createElement(t,e={},s=""){if(!b.allowedTags.has(t.toLowerCase()))throw new Error(`Unsupported tag: ${t}`);const i=document.createElement(t);return this._processAttributes(i,e),this._processContent(i,s),i}createBatch(t,e){const s=document.createDocumentFragment();t.forEach(i=>{const r=this.createElement(i.tag,i.attributes||{},i.content||"");s.appendChild(r)}),e.appendChild(s)}setHtml(t,e){const s=this._sanitizeHtml(e);t.innerHTML=s}_processAttributes(t,e){Object.entries(e).forEach(([s,i])=>{if(!b.allowedAttributes.has(s)&&!s.startsWith("data-")){console.warn(`Potentially unsafe attribute: ${s}`);return}if(typeof i=="function")s.startsWith("on")&&t.addEventListener(s.slice(2).toLowerCase(),i);else switch(s){case"className":t.className=i;break;case"dataset":Object.assign(t.dataset,i);break;case"style":Object.assign(t.style,i);break;default:t.setAttribute(s,i)}})}_processContent(t,e){typeof e=="string"?t.textContent=e:e instanceof Node?t.appendChild(e):Array.isArray(e)&&e.forEach(s=>{typeof s=="string"?t.appendChild(document.createTextNode(s)):t.appendChild(s)})}_sanitizeHtml(t){return t.replace(b.scriptRegex,"").replace(b.javascriptRegex,"").replace(b.eventHandlerRegex,"")}}class B{features;constructor(){this.features=this.detectFeatures()}detectFeatures(){return{geolocation:"geolocation"in navigator,notification:"Notification"in window,serviceWorker:"serviceWorker"in navigator,webShare:"share"in navigator,deviceOrientation:"DeviceOrientationEvent"in window,battery:"getBattery"in navigator,online:"onLine"in navigator}}async getLocation(t={}){if(!this.features.geolocation)throw new Error("Geolocation is not supported");const e={enableHighAccuracy:!0,timeout:10*1e3,maximumAge:300*1e3};return new Promise((s,i)=>{navigator.geolocation.getCurrentPosition(r=>s({latitude:r.coords.latitude,longitude:r.coords.longitude,accuracy:r.coords.accuracy,timstamp:r.timestamp}),r=>{const a={1:"User denied the request for Geolocation.",2:"Position information is unavailable.",3:"The request to get user location timed out."};i(new Error(a[r.code]||"Unknown error"))},{...e,...t})})}async sendNotification(t,e){if(!this.features.notification)throw new Error("Notification is not supported");if(Notification.permission==="default"&&await Notification.requestPermission()!=="granted")throw new Error("Notification permission is not granted");if(Notification.permission!=="granted")throw new Error("Notification permission is not granted");return new Notification(t,{icon:e.icon,badge:e.badge,...e})}async registerServiceWorker(t){if(!this.features.serviceWorker)throw new Error("Service Worker is not supported");try{const e=await navigator.serviceWorker.register(t);return console.log("Service Worker registered with scope:",e),e}catch(e){throw console.error("Service Worker registration failed:",e),e}}async shareContent(t){if(this.features.webShare)try{return await navigator.share(t),!0}catch(e){return e instanceof Error&&e.name!="AbortError"&&console.error("Error sharing content:",e),!1}else try{return await navigator.clipboard.writeText(t.url||t.text||""),this.sendNotification("Copied to clipboard",{body:"Link copied to clipboard"}),!0}catch(e){return console.error("Error copying to clipboard:",e),!1}}}o.Dictionary=A,o.DomHelper=x,o.Graph=q,o.LIS=F,o.LRU=j,o.Line=u,o.LinkedList=R,o.Matrix=w,o.MaxHeap=k,o.MemoizeMap=H,o.MinHeap=L,o.Point=h,o.Queue=E,o.Roman=$,o.Stack=O,o.Triangle=c,o.Vector=f,o.WebAppManager=B,o.isValidBracket=W,o.singleton=U,o.sleep=D,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(a,I){typeof exports=="object"&&typeof module<"u"?I(exports):typeof define=="function"&&define.amd?define(["exports"],I):(a=typeof globalThis<"u"?globalThis:a||self,I(a["jc-structure"]={}))})(this,(function(a){"use strict";class I{items={};count=0;lowestCount=0;constructor(){}dequeue(){if(this.isEmpty())return;const t=this.items[this.lowestCount];return delete this.items[this.lowestCount],this.lowestCount++,t}enqueue(...t){t.forEach(e=>{this.items[this.count]=e,this.count++})}front(){return this.isEmpty()?void 0:this.items[this.lowestCount]}isEmpty(){return this.size()===0}size(){return this.count-this.lowestCount}clear(){this.items={},this.count=0,this.lowestCount=0}toString(){return this.isEmpty()?"":`Queue(size: ${this.size()}):[${this.items[this.lowestCount]},...rest]`}}class k{items={};count=0;constructor(){}pop(){if(this.isEmpty())return;this.count--;const t=this.items[this.count];return delete this.items[this.count],t}push(...t){t.forEach(e=>{this.items[this.count]=e,this.count++})}peek(){return this.isEmpty()?void 0:this.items[this.count-1]}isEmpty(){return this.count===0}size(){return this.count}clear(){this.items={},this.count=0}toString(){return this.isEmpty()?"":`Stack(count: ${this.count}):[${this.items[this.count-1]},...rest]`}}function N(r,t){return r===t?0:r<t?-1:1}class m{heap=[];compareFn;constructor(t=N){this.compareFn=t}static getLeftIndex(t){return 2*t+1}static getRightIndex(t){return 2*t+2}static getParentIndex(t){return t===0?void 0:Math.floor((t-1)/2)}static swap(t,e,s){[t[e],t[s]]=[t[s],t[e]]}find(){return this.isEmpty()?void 0:this.heap[0]}size(){return this.heap.length}isEmpty(){return this.size()===0}clear(){this.heap=[]}toString(){return this.heap.toString()}}class O extends m{insert(t){return t?!1:(this.heap.push(t),this.siftUp(this.heap.length-1),!0)}extract(){if(this.isEmpty())return;if(this.heap.length===1)return this.heap.shift();const t=this.heap[0];return this.heap[0]=this.heap.pop(),this.siftDown(0),t}siftUp(t){let e=t,s=m.getLeftIndex(e),i=m.getRightIndex(e),n=this.size();s<n&&this.compareFn(this.heap[e],this.heap[s])===-1&&(e=s),i<n&&this.compareFn(this.heap[e],this.heap[i])===1&&(e=i),e!==t&&(m.swap(this.heap,t,e),this.siftUp(e))}siftDown(t){let e=m.getParentIndex(t);for(;t>0&&e&&this.compareFn(this.heap[e],this.heap[t])===1;)m.swap(this.heap,e,t),t=e,e=m.getParentIndex(t)}}class j extends O{constructor(t=(e,s)=>N(s,e)){super(t)}}function z(r){return{value:r}}class U{capacity;length=0;head=null;tail=null;lookup=new Map;reverseLookup=new Map;constructor(t=10){this.capacity=t}prepend(t){this.head?(t.next=this.head,this.head.prev=t,this.head=t):this.head=this.tail=t}detach(t){t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),this.head===t&&(this.head=this.head.next||null),this.tail===t&&(this.tail=this.tail.prev||null),t.next=void 0,t.prev=void 0}trimCache(){if(this.length<=this.capacity)return;const t=this.tail;this.detach(t);const e=this.reverseLookup.get(t);this.lookup.delete(e),this.reverseLookup.delete(t),this.length--}get(t){const e=this.lookup.get(t);if(e)return this.detach(e),this.prepend(e),e.value}update(t,e){let s=this.lookup.get(t);s?(this.detach(s),this.prepend(s),s.value=e):(s=z(e),this.length++,this.prepend(s),this.trimCache(),this.lookup.set(t,s),this.reverseLookup)}}let A=class{value;next=void 0};class V{count=0;head=void 0;constructor(){}indexOf(t){let e=this.head,s=0,i=!1;for(;e;){if(this.equals(e.value,t)){i=!0;break}s++,e=e.next}return i?s:-1}equals(t,e){return!1}getElementAt(t){if(t<0||t>=this.count)return;if(t===0)return this.head;let e=this.head;for(let s=0;s<t;s++)e=e?.next;return e}getValueAt(t){return this.getElementAt(t)?.value}insert(t,e){let s=new A;if(s.value=t,e>this.count||e<0)throw new Error("index error");this.count++;let i,n;if(e===0){s.next=this.head,this.head=s;return}i=this.getElementAt(e-1),n=i.next,i.next=s,s.next=n}push(t){let e=new A;if(e.value=t,this.count++,this.isEmpty()){this.head=e;return}let s=this.getElementAt(this.count-1);s.next=e}remove(t){const e=this.indexOf(t);return e===-1?void 0:this.removeAt(e)}removeAt(t){if(this.isEmpty()||t<0||t>=this.count)return;let e=this.getElementAt(t),s=this.getElementAt(t-1),i=e?.next;return t===0&&(this.head=i),s&&(s.next=i),this.count--,e?.value}isEmpty(){return this.count===0}size(){return this.count}clear(){this.count=0,this.head=void 0}toString(){let t="",e=this.head;for(;e;)t+=e.value,t+=",",e=e.next;return t=t.slice(0,-1),t}}class D{key;value;constructor(t,e){this.key=t,this.value=e}}function C(r,t={emptyString:!1,zeroNumber:!1}){return r==null?!(t.emptyString&&r===""||t.zeroNumber&&r===0):!1}class P{table=[];constructor(){}getItemIndex(t){for(let e=0,s=this.table.length;e<s;e++)if(this.table[e].key===t)return e;return-1}set(t,e){if(C(t))throw new Error("key is required");if(C(e))throw new Error("value is required");if(this.has(t)){let s=this.getItemIndex(t);this.table[s].value=e}else{const s=new D(t,e);this.table.push(s)}}remove(t){if(this.has(t)){let e=this.getItemIndex(t);return this.table.splice(e,1)[0]}}has(t){return this.getItemIndex(t)!==-1}get(t){if(this.has(t)){let e=this.getItemIndex(t);return this.table[e]}}keys(){return this.table.map(t=>t.key)}values(){return this.table.map(t=>t.value)}keyValues(){return this.table.map(t=>[t.key,t.value])}forEach(t){for(let e=0,s=this.size();e<s;e++){let i=this.table[e];if(!t(i.key,i.value))break}}isEmpty(){return!this.size()}size(){return this.table.length}clear(){this.table=[]}toString(){let t="";for(let e=0,s=this.table.length;e<s;e++)t+=this.table[e].toString(),t+=",";return t=t.slice(0,-1),t}}class H{isDirected;vertices;adjList;constructor(t=!1){this.isDirected=t,this.vertices=[],this.adjList=new P}addVertex(t){this.vertices.includes(t)||(this.vertices.push(t),this.adjList.set(t,[]))}addEdge(t,e){this.adjList.get(t)||this.addVertex(t),this.adjList.get(e)||this.addVertex(e),this.adjList.get(t)?.value.indexOf(e)===-1&&this.adjList.get(t)?.value.push(e),this.isDirected||this.adjList.get(e)?.value.indexOf(t)===-1&&this.adjList.get(e)?.value.push(t)}getVertices(){return this.vertices}getAdjacencyList(){return this.adjList}toString(){let t="";for(let e=0;e<this.vertices.length;e++)t+=this.vertices[e]+"-->",t+=this.adjList.get(this.vertices[e])?.toString()||"",t+=`
2
+ `;return t}}class f{_data;static zero(t){return new f(...Array(t).fill(0))}constructor(...t){this._data=t}get dimension(){return this._data.length}get norm(){return Math.hypot(...this._data)}getItem(t){return this._data[t]}normalize(){const t=this.norm;if(t===0)throw new Error("Cannot normalize a zero vector");const e=this._data.map(s=>s/t);return new f(...e)}add(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to add");const e=this._data.map((s,i)=>s+t._data[i]);return new f(...e)}sub(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to subtract");const e=this._data.map((s,i)=>s-t._data[i]);return new f(...e)}mul(t){return new f(...this._data.map(e=>e*t))}dot(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to dot product");return this._data.reduce((e,s,i)=>e+s*t._data[i],0)}pos(){return this.mul(1)}neg(){return this.mul(-1)}}class w{_matrix;static zero(t,e){return new w(Array.from({length:t},()=>Array.from({length:e},()=>0)))}constructor(t){this._matrix=t}get shape(){return[this._matrix.length,this._matrix[0].length]}get row(){return this.shape[0]}get col(){return this.shape[1]}get size(){return this.row*this.col}rowVector(t){return new f(...this._matrix[t])}colVector(t){return new f(...this._matrix.map(e=>e[t]))}getItem(t){return this._matrix[t[0]][t[1]]}setItem(t,e){return this._matrix[t[0]][t[1]]=e,this}mul(t){return new w(this._matrix.map(e=>e.map(s=>s*t)))}div(t){return this.mul(1/t)}add(t){if(this.row!==t.row||this.col!==t.col)throw new Error("Matrix dimensions do not match");return new w(this._matrix.map((e,s)=>e.map((i,n)=>i+t.getItem([s,n]))))}sub(t){return this.add(t.neg())}pos(){return this.mul(1)}neg(){return this.mul(-1)}mulVector(t){if(this.col!==t.dimension)throw new Error("Matrix dimensions do not match");return new w(this._matrix.map(e=>e.map((s,i)=>s*t.getItem(i))))}mulMatrix(t){if(this.col!==t.row)throw new Error("Matrix dimensions do not match");const e=w.zero(this.row,t.col);for(let s=0;s<this.row;s++){const i=this.rowVector(s);for(let n=0;n<this.col;n++)e.setItem([s,n],i.dot(t.colVector(n)))}return e}}class h{static distance(t,e){return Math.hypot(e.x-t.x,e.y-t.y)}x;y;constructor(t,e){this.x=t,this.y=e}distanceTo(t){return h.distance(this,t)}}class p{static EPSILON=1e-10;static sloped(t){const e=t.p2.x-t.p1.x,s=t.p2.y-t.p1.y;return Math.abs(e)<p.EPSILON?Math.abs(s)<p.EPSILON?0:null:s/e}static isParallel(t,e){const s=p.sloped(t),i=p.sloped(e);return s===null&&i===null?!0:s===null||i===null?!1:Math.abs(s-i)<p.EPSILON}static getIntersection(t,e){if(p.isParallel(t,e))return null;const s=t.p1.x,i=t.p1.y,n=t.p2.x,o=t.p2.y,l=e.p1.x,u=e.p1.y,d=e.p2.x,y=e.p2.y,g=(s-n)*(u-y)-(i-o)*(l-d);if(Math.abs(g)<p.EPSILON)return null;const v=((s-l)*(u-y)-(i-u)*(l-d))/g,S=-((s-n)*(i-u)-(i-o)*(s-l))/g;if(v>=0&&v<=1&&S>=0&&S<=1){const B=s+v*(n-s),X=i+v*(o-i);return new h(B,X)}return null}static isIntersecting(t,e){return p.getIntersection(t,e)!==null}static distanceToPoint(t,e){const s=e.x-t.p1.x,i=e.y-t.p1.y,n=t.p2.x-t.p1.x,o=t.p2.y-t.p1.y,l=s*n+i*o,u=n*n+o*o;let d=-1;u>p.EPSILON&&(d=l/u);let y,g;d<0?(y=t.p1.x,g=t.p1.y):d>1?(y=t.p2.x,g=t.p2.y):(y=t.p1.x+d*n,g=t.p1.y+d*o);const v=e.x-y,S=e.y-g;return Math.hypot(v+S)}p1;p2;constructor(t,e){this.p1=t,this.p2=e}get length(){const t=this.p2.x-this.p1.x,e=this.p2.y-this.p1.y;return Math.sqrt(t*t+e*e)}get midpoint(){const t=(this.p1.x+this.p2.x)/2,e=(this.p1.y+this.p2.y)/2;return new h(t,e)}get angle(){return Math.atan2(this.p2.y-this.p1.y,this.p2.x-this.p1.x)}containsPoint(t){const e=(t.x-this.p1.x)*(this.p2.y-this.p1.y)-(t.y-this.p1.y)*(this.p2.x-this.p1.x);return Math.abs(e)>p.EPSILON?!1:(t.x-this.p1.x)*(t.x-this.p2.x)+(t.y-this.p1.y)*(t.y-this.p2.y)<=p.EPSILON}get direction(){const t=this.length;if(t<p.EPSILON)return new h(0,0);const e=(this.p2.x-this.p1.x)/t,s=(this.p2.y-this.p1.y)/t;return new h(e,s)}}class R{static EPSILON=1e-10;name;constructor(t){this.name=t}}class c extends R{static isValid(t,e,s){return t<=0||e<=0||s<=0?!1:t+e>s&&t+s>e&&e+s>t}static area(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle");const i=(t+e+s)/2;return Math.sqrt(i*(i-t)*(i-e)*(i-s))}static getType(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=[t,e,s].sort((u,d)=>u-d),[n,o,l]=i;return Math.abs(n-o)<c.EPSILON&&Math.abs(o-l)<c.EPSILON?"equilateral":Math.abs(n-o)<c.EPSILON||Math.abs(o-l)<c.EPSILON?"isosceles":"scalene"}static getAngles(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=Math.acos((e*e+s*s-t*t)/(2*e*s)),n=Math.acos((t*t+s*s-e*e)/(2*t*s)),o=Math.PI-i-n;return[i,n,o]}p1;p2;p3;constructor(t,e,s,i="triangle"){if(super(i),this.p1=t,this.p2=e,this.p3=s,this.areCollinear())throw new Error("Points are collinear, cannot form a triangle")}areCollinear(){return Math.abs((this.p2.x-this.p1.x)*(this.p3.y-this.p1.y)-(this.p3.x-this.p1.x)*(this.p2.y-this.p1.y))<R.EPSILON}get side(){return[h.distance(this.p1,this.p2),h.distance(this.p2,this.p3),h.distance(this.p3,this.p1)]}perimeter(){return c.isValid(this.side[0],this.side[1],this.side[2]),this.side.reduce((t,e)=>t+e,0)}area(){const[t,e,s]=this.side;return c.area(t,e,s)}get type(){const[t,e,s]=this.side;return c.getType(t,e,s)}get angles(){const[t,e,s]=this.side;return c.getAngles(t,e,s)}get centroid(){return new h((this.p1.x+this.p2.x+this.p3.x)/3,(this.p1.y+this.p2.y+this.p3.y)/3)}get incenter(){const[t,e,s]=this.side,i=this.perimeter()/2,n=(t*this.p1.x+e*this.p2.x+s*this.p3.x)/i,o=(t*this.p1.y+e*this.p2.y+s*this.p3.y)/i;return new h(n,o)}get circumcenter(){const t=2*(this.p1.x*(this.p2.y-this.p3.y)+this.p2.x*(this.p3.y-this.p1.y)+this.p3.x*(this.p1.y-this.p2.y));if(Math.abs(t)<c.EPSILON)throw new Error("Cannot calculate circumcenter for collinear points");const e=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p2.y-this.p3.y)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p3.y-this.p1.y)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p1.y-this.p2.y))/t,s=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p3.x-this.p2.x)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p1.x-this.p3.x)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p2.x-this.p1.x))/t;return new h(e,s)}containsPoint(t){const e=c.area(h.distance(t,this.p1),h.distance(t,this.p2),h.distance(this.p1,this.p2)),s=c.area(h.distance(t,this.p2),h.distance(t,this.p3),h.distance(this.p2,this.p3)),i=c.area(h.distance(t,this.p3),h.distance(t,this.p1),h.distance(this.p3,this.p1));return Math.abs(e+s+i-this.area())<c.EPSILON}}function $(r){return new Promise(t=>setTimeout(t,r))}function W(r){const t=[],e={"(":")","[":"]","{":"}"},s=new Set(Object.values(e));for(const i of r)if(i in e)t.push(e[i]);else if(s.has(i)&&i!==t.pop())return!1;return t.length===0}function L(r){return r!==null&&(typeof r=="object"||typeof r=="function")}class _{map=new Map;weakMap=new WeakMap;set(t,e){L(t)?this.weakMap.set(t,e):this.map.set(t,e)}get(t){return L(t)?this.weakMap.get(t):this.map.get(t)}has(t){return L(t)?this.weakMap.has(t):this.map.has(t)}}function q(r){if(!r.length)return[];const t=[[r[0]]];for(let s=1,i=r.length;s<i;s++){const n=r[s];e(n)}function e(s){for(let i=t.length-1;i>=0;i--){const n=t[i],o=n[t[i].length-1];if(o<s){t[i+1]=[...n,s];break}else o>s&&i===0&&(t[i]=[s])}}return t[t.length-1]}class T{static ROMAN_MAP=new Map([["M",1e3],["CM",900],["D",500],["CD",400],["C",100],["XC",90],["L",50],["XL",40],["X",10],["IX",9],["V",5],["IV",4],["I",1]]);static toInteger(t){if(t.length===0)throw new Error("Input cannot be empty");const e=new Set(["I","V","X","L","C","D","M"]);for(const o of t)if(!e.has(o))throw new Error(`Invalid Roman numeral character: ${o}`);let s=0,i=0;for(;i<t.length;){const o=t.slice(i,i+2);if(this.ROMAN_MAP.has(o))s+=this.ROMAN_MAP.get(o),i+=2;else{const l=t[i],u=this.ROMAN_MAP.get(l);if(!u)throw new Error(`Invalid Roman numeral sequence at position ${i}`);s+=u,i+=1}}if(this.toRoman(s)!==t)throw new Error("Invalid Roman numeral sequence");return s}static toRoman(t){if(t<=0||t>=4e3)throw new Error("Number must be between 1 and 3999");if(!Number.isInteger(t))throw new Error("Number must be an integer");let e="";for(const[s,i]of this.ROMAN_MAP)for(;t>=i;)e+=s,t-=i;return e}}function G(r){let t;const e=new Proxy(r,{construct(s,i,n){return t||(t=Reflect.construct(s,i,n)),t}});return r.prototype.constructor=e,e}const E={AUTH_UNAUTHORIZED:"未授权事件",AUTH_LOGIN_SUCCESS:"登录成功事件",AUTH_LOGOUT:"注销事件",AUTH_TOKEN_EXPIRED:"令牌过期事件",REQUEST_ERROR:"请求错误事件",REQUEST_TIMEOUT:"请求超时事件",REQUEST_NETWORK_ERROR:"网络错误事件",UI_SHOW_LOADING:"显示加载事件",UI_HIDE_LOADING:"隐藏加载事件",UI_SHOW_MESSAGE:"显示消息事件"};class x{static instance=null;listeners={};debugMode;constructor(t=!1){this.debugMode=t,Object.keys(E).forEach(e=>{this.listeners[e]=new Set})}static getInstance(t){return x.instance||(x.instance=new x(t)),x.instance}on(t,e){this.debugLog(`添加事件监听: ${E[t]}`),this.listeners[t].add(e)}emit(t,e){this.debugLog(`触发事件: ${E[t]}`,e),this.listeners[t].forEach(s=>{try{s(e)}catch(i){console.error(`事件 ${E[t]} 处理出错:`,i)}})}off(t,e){this.debugLog(`移除事件监听: ${E[t]}`),this.listeners[t].delete(e)}once(t,e){this.debugLog(`添加一次性事件监听: ${E[t]}`);const s=i=>{e(i),this.off(t,s)};this.on(t,s)}clear(){this.debugLog("清除所有事件监听器"),Object.values(this.listeners).forEach(t=>t.clear())}getListenerCount(t){return this.listeners[t].size}debugLog(t,e){this.debugMode&&console.log(`[EventEmitter] ${t}`,e||"")}}const M={scriptRegex:/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,javascriptRegex:/javascript:/gi,eventHandlerRegex:/on\w+\s*=/gi,allowedTags:new Set(["div","span","p","a","img","button","input","form","label","select","option","textarea","ul","ol","li","table","tr","td","th","thead","tbody","tfoot","h1","h2","h3","h4","h5","h6","hr","br","section","article","nav","header","footer","main","aside","figure","figcaption"]),allowedAttributes:new Set(["class","id","href","src","alt","title"])};class b{static instance;constructor(){}static getInstance(){return b.instance||(b.instance=new b),b.instance}createElement(t,e={},s=""){if(!M.allowedTags.has(t.toLowerCase()))throw new Error(`Unsupported tag: ${t}`);const i=document.createElement(t);return this._processAttributes(i,e),this._processContent(i,s),i}createBatch(t,e){const s=document.createDocumentFragment();t.forEach(i=>{const n=this.createElement(i.tag,i.attributes||{},i.content||"");s.appendChild(n)}),e.appendChild(s)}setHtml(t,e){const s=this._sanitizeHtml(e);t.innerHTML=s}_processAttributes(t,e){Object.entries(e).forEach(([s,i])=>{if(!M.allowedAttributes.has(s)&&!s.startsWith("data-")){console.warn(`Potentially unsafe attribute: ${s}`);return}if(typeof i=="function")s.startsWith("on")&&t.addEventListener(s.slice(2).toLowerCase(),i);else switch(s){case"className":t.className=i;break;case"dataset":Object.assign(t.dataset,i);break;case"style":Object.assign(t.style,i);break;default:t.setAttribute(s,i)}})}_processContent(t,e){typeof e=="string"?t.textContent=e:e instanceof Node?t.appendChild(e):Array.isArray(e)&&e.forEach(s=>{typeof s=="string"?t.appendChild(document.createTextNode(s)):t.appendChild(s)})}_sanitizeHtml(t){return t.replace(M.scriptRegex,"").replace(M.javascriptRegex,"").replace(M.eventHandlerRegex,"")}}class F{features;constructor(){this.features=this.detectFeatures()}detectFeatures(){return{geolocation:"geolocation"in navigator,notification:"Notification"in window,serviceWorker:"serviceWorker"in navigator,webShare:"share"in navigator,deviceOrientation:"DeviceOrientationEvent"in window,battery:"getBattery"in navigator,online:"onLine"in navigator}}async getLocation(t={}){if(!this.features.geolocation)throw new Error("Geolocation is not supported");const e={enableHighAccuracy:!0,timeout:10*1e3,maximumAge:300*1e3};return new Promise((s,i)=>{navigator.geolocation.getCurrentPosition(n=>s({latitude:n.coords.latitude,longitude:n.coords.longitude,accuracy:n.coords.accuracy,timstamp:n.timestamp}),n=>{const o={1:"User denied the request for Geolocation.",2:"Position information is unavailable.",3:"The request to get user location timed out."};i(new Error(o[n.code]||"Unknown error"))},{...e,...t})})}async sendNotification(t,e){if(!this.features.notification)throw new Error("Notification is not supported");if(Notification.permission==="default"&&await Notification.requestPermission()!=="granted")throw new Error("Notification permission is not granted");if(Notification.permission!=="granted")throw new Error("Notification permission is not granted");return new Notification(t,{icon:e.icon,badge:e.badge,...e})}async registerServiceWorker(t){if(!this.features.serviceWorker)throw new Error("Service Worker is not supported");try{const e=await navigator.serviceWorker.register(t);return console.log("Service Worker registered with scope:",e),e}catch(e){throw console.error("Service Worker registration failed:",e),e}}async shareContent(t){if(this.features.webShare)try{return await navigator.share(t),!0}catch(e){return e instanceof Error&&e.name!="AbortError"&&console.error("Error sharing content:",e),!1}else try{return await navigator.clipboard.writeText(t.url||t.text||""),this.sendNotification("Copied to clipboard",{body:"Link copied to clipboard"}),!0}catch(e){return console.error("Error copying to clipboard:",e),!1}}}String.prototype.pointLength=function(){let r=0;for(let t=0,e=this.length;t<e;){const s=this.codePointAt(t);t+=s>65535?2:1,r++}return r},String.prototype.pointAt=function(r){if(r>=this.pointLength())return;let t=0;for(let e=0,s=this.length;e<s;){const i=this.codePointAt(e);if(!i)return;if(t===r)return String.fromCodePoint(i);e+=i>65535?2:1,t++}},String.prototype.sliceByPoint=function(r,t=this.pointLength()){let e="";for(let s=r;s<t;s++)e+=this.pointAt(s);return e},RegExp.escape=function(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},Element.prototype.farthest=function(r){if(typeof r!="string"||!r)return null;let t=null,e=this;for(;e;){const s=e.closest(r);if(!s)break;t=s,e=s.parentElement}return t},Object.defineProperties(Element.prototype,{firstElement:{get:function(){if(!this.children.length)return null;let r=this.firstElementChild,t=null;for(;r;)t=r,r=r.firstElementChild;return t}},lastElement:{get:function(){if(!this.children.length)return null;let r=this.lastElementChild,t=null;for(;r;)t=r,r=r.lastElementChild;return t}}}),Text.prototype.surround=function(r="strong",t=""){if(!this.nodeValue||!r||!t)return null;const s=r.split("."),i=s[0],n=s.slice(1).join(" "),o=this.textContent.indexOf(t);if(o<0)return null;const l=document.createRange();l.setStart(this,o),l.setEnd(this,o+t.length);const u=document.createElement(i);return n&&(u.className=n),l.surroundContents(u),u},a.Dictionary=P,a.DomHelper=b,a.Emitter=x,a.Graph=H,a.LIS=q,a.LRU=U,a.Line=p,a.LinkedList=V,a.Matrix=w,a.MaxHeap=j,a.MemoizeMap=_,a.MinHeap=O,a.Point=h,a.Queue=I,a.Roman=T,a.Stack=k,a.Triangle=c,a.Vector=f,a.WebAppManager=F,a.isValidBracket=W,a.singleton=G,a.sleep=$,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jc-structure",
3
3
  "private": false,
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
package/types/extend.d.ts CHANGED
@@ -20,3 +20,38 @@ interface String {
20
20
  */
21
21
  sliceByPoint(this: string, start: number, end?: number): string;
22
22
  }
23
+
24
+ interface RegExpConstructor {
25
+ /**
26
+ * #### 转义正则表达式中的特殊字符
27
+ * @param str 字符串
28
+ */
29
+ escape(str: string): string;
30
+ }
31
+
32
+ interface Element {
33
+ /**
34
+ * #### 获取最深元素集合中的第一个元素
35
+ */
36
+ readonly firstElement: Element | null;
37
+ /**
38
+ * #### 获取最深元素集合中的最后一个元素
39
+ */
40
+ readonly lastElement: Element | null;
41
+ /**
42
+ * #### 最祖先的匹配元素
43
+ * @param this element
44
+ * @param selector 选择器
45
+ */
46
+ farthest<E extends Element = Element>(this: E, selector: string): E | null;
47
+ }
48
+
49
+ interface Text {
50
+ /**
51
+ * #### 将文本节点包裹在指定标签中
52
+ * @param this Text 该文本节点
53
+ * @param selector 要包裹的元素标签,默认为:'strong'
54
+ * @param text 要包裹的文本,默认为:''
55
+ */
56
+ surround(this: Text, selector?: string, text?: string): HTMLElement | null;
57
+ }
@@ -0,0 +1,20 @@
1
+ interface Vector {
2
+ get dimension(): number;
3
+ get norm(): number;
4
+ getItem(index: number): number;
5
+ normalize(): Vector;
6
+ add(vector: Vector): Vector;
7
+ sub(vector: Vector): Vector;
8
+ mul(scalar: number): Vector;
9
+ dot(vector: Vector): number;
10
+ pos(): Vector;
11
+ neg(): Vector;
12
+ }
13
+
14
+ interface VectorConstructor {
15
+ new (...args: number[]): Vector;
16
+ readonly prototype: Vector;
17
+ zero(dimension: number): Vector;
18
+ }
19
+
20
+ declare var Vector: VectorConstructor;