jc-structure 0.1.1 → 0.1.3

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 U {
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 V {
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 A(r, t) {
66
+ return r === t ? 0 : r < t ? -1 : 1;
67
67
  }
68
- class g {
68
+ class w {
69
69
  heap = [];
70
70
  compareFn;
71
- constructor(t = N) {
71
+ constructor(t = A) {
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 R extends w {
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 = w.getLeftIndex(e), i = w.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 && (w.swap(this.heap, t, e), this.siftUp(e));
115
115
  }
116
116
  siftDown(t) {
117
- let e = g.getParentIndex(t);
117
+ let e = w.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
+ w.swap(this.heap, e, t), t = e, e = w.getParentIndex(t);
120
120
  }
121
121
  }
122
- class R extends A {
123
- constructor(t = (e, s) => N(s, e)) {
122
+ class _ extends R {
123
+ constructor(t = (e, s) => A(s, e)) {
124
124
  super(t);
125
125
  }
126
126
  }
127
- function C(n) {
128
- return { value: n };
127
+ function k(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 = k(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 L = class {
164
164
  value;
165
165
  next = void 0;
166
166
  };
167
- class W {
167
+ class q {
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 L();
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 L();
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 z {
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 C(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 j {
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 (C(t))
268
268
  throw new Error("key is required");
269
- if (M(e))
269
+ if (C(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 z(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 H {
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 j();
332
332
  }
333
333
  addVertex(t) {
334
334
  this.vertices.includes(t) || (this.vertices.push(t), this.adjList.set(t, []));
@@ -350,10 +350,10 @@ class D {
350
350
  return t;
351
351
  }
352
352
  }
353
- class f {
353
+ class g {
354
354
  _data;
355
355
  static zero(t) {
356
- return new f(...Array(t).fill(0));
356
+ return new g(...Array(t).fill(0));
357
357
  }
358
358
  constructor(...t) {
359
359
  this._data = t;
@@ -372,7 +372,7 @@ class f {
372
372
  if (t === 0)
373
373
  throw new Error("Cannot normalize a zero vector");
374
374
  const e = this._data.map((s) => s / t);
375
- return new f(...e);
375
+ return new g(...e);
376
376
  }
377
377
  add(t) {
378
378
  if (this.dimension !== t.dimension)
@@ -380,7 +380,7 @@ class f {
380
380
  const e = this._data.map(
381
381
  (s, i) => s + t._data[i]
382
382
  );
383
- return new f(...e);
383
+ return new g(...e);
384
384
  }
385
385
  sub(t) {
386
386
  if (this.dimension !== t.dimension)
@@ -388,10 +388,10 @@ class f {
388
388
  const e = this._data.map(
389
389
  (s, i) => s - t._data[i]
390
390
  );
391
- return new f(...e);
391
+ return new g(...e);
392
392
  }
393
393
  mul(t) {
394
- return new f(...this._data.map((e) => e * t));
394
+ return new g(...this._data.map((e) => e * t));
395
395
  }
396
396
  dot(t) {
397
397
  if (this.dimension !== t.dimension)
@@ -408,10 +408,10 @@ class f {
408
408
  return this.mul(-1);
409
409
  }
410
410
  }
411
- class y {
411
+ class E {
412
412
  _matrix;
413
413
  static zero(t, e) {
414
- return new y(
414
+ return new E(
415
415
  Array.from({ length: t }, () => Array.from({ length: e }, () => 0))
416
416
  );
417
417
  }
@@ -431,10 +431,10 @@ class y {
431
431
  return this.row * this.col;
432
432
  }
433
433
  rowVector(t) {
434
- return new f(...this._matrix[t]);
434
+ return new g(...this._matrix[t]);
435
435
  }
436
436
  colVector(t) {
437
- return new f(...this._matrix.map((e) => e[t]));
437
+ return new g(...this._matrix.map((e) => e[t]));
438
438
  }
439
439
  getItem(t) {
440
440
  return this._matrix[t[0]][t[1]];
@@ -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 E(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 E(
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 E(
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 = E.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,108 +495,105 @@ 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 l {
502
502
  // 使用更合适的精度阈值常量
503
503
  static EPSILON = 1e-10;
504
- // 静态方法:计算斜率
505
- static sloped(t) {
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;
508
- }
509
- // 静态方法:判断两条线是否平行
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;
513
- }
514
- // 静态方法:获取两条线的交点
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);
504
+ static sloped(t, e = l.EPSILON) {
505
+ const s = t.p2.x - t.p1.x, i = t.p2.y - t.p1.y;
506
+ return Math.abs(s) < e ? Math.abs(i) < e ? 0 : null : i / s;
507
+ }
508
+ static isParallel(t, e, s = l.EPSILON) {
509
+ const i = l.sloped(t), n = l.sloped(e);
510
+ return i === null && n === null ? !0 : i === null || n === null ? !1 : Math.abs(i - n) < s;
511
+ }
512
+ static getIntersection(t, e, s = l.EPSILON) {
513
+ if (l.isParallel(t, e)) return null;
514
+ const i = t.p1.x, n = t.p1.y, o = t.p2.x, h = t.p2.y, u = e.p1.x, p = e.p1.y, d = e.p2.x, m = e.p2.y, f = (i - o) * (p - m) - (n - h) * (u - d);
515
+ if (Math.abs(f) < s) return null;
516
+ const y = ((i - u) * (p - m) - (n - p) * (u - d)) / f, S = -((i - o) * (n - p) - (n - h) * (i - u)) / f;
517
+ if (y >= 0 && y <= 1 && S >= 0 && S <= 1) {
518
+ const O = i + y * (o - i), P = n + y * (h - n);
519
+ return new a(O, P);
523
520
  }
524
521
  return null;
525
522
  }
526
- // 静态方法:判断两条线段是否相交
527
523
  static isIntersecting(t, e) {
528
- return c.getIntersection(t, e) !== null;
529
- }
530
- // 静态方法:计算点到线段的距离
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;
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);
524
+ return l.getIntersection(t, e) !== null;
525
+ }
526
+ static distanceToPoint(t, e, s = l.EPSILON) {
527
+ const i = e.x - t.p1.x, n = e.y - t.p1.y, o = t.p2.x - t.p1.x, h = t.p2.y - t.p1.y, u = i * o + n * h, p = o * o + h * h;
528
+ let d = -1;
529
+ p > s && (d = u / p);
530
+ let m, f;
531
+ d < 0 ? (m = t.p1.x, f = t.p1.y) : d > 1 ? (m = t.p2.x, f = t.p2.y) : (m = t.p1.x + d * o, f = t.p1.y + d * h);
532
+ const y = e.x - m, S = e.y - f;
533
+ return Math.hypot(y + S);
539
534
  }
540
535
  p1;
541
536
  p2;
542
537
  constructor(t, e) {
543
538
  this.p1 = t, this.p2 = e;
544
539
  }
545
- // 获取线段长度
546
540
  get length() {
547
541
  const t = this.p2.x - this.p1.x, e = this.p2.y - this.p1.y;
548
542
  return Math.sqrt(t * t + e * e);
549
543
  }
550
- // 获取线段中点
551
544
  get midpoint() {
552
545
  const t = (this.p1.x + this.p2.x) / 2, e = (this.p1.y + this.p2.y) / 2;
553
- return new o(t, e);
546
+ return new a(t, e);
554
547
  }
555
- // 获取线段的角度(弧度)
556
548
  get angle() {
557
549
  return Math.atan2(this.p2.y - this.p1.y, this.p2.x - this.p1.x);
558
550
  }
559
- // 判断点是否在线段上
560
- containsPoint(t) {
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;
551
+ containsPoint(t, e = l.EPSILON) {
552
+ const s = (t.x - this.p1.x) * (this.p2.y - this.p1.y) - (t.y - this.p1.y) * (this.p2.x - this.p1.x);
553
+ 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;
563
554
  }
564
555
  // 获取线段的方向向量
565
556
  get direction() {
566
557
  const t = this.length;
567
- if (t < c.EPSILON) return new o(0, 0);
558
+ if (t < l.EPSILON) return new a(0, 0);
568
559
  const e = (this.p2.x - this.p1.x) / t, s = (this.p2.y - this.p1.y) / t;
569
- return new o(e, s);
560
+ return new a(e, s);
561
+ }
562
+ get start() {
563
+ return this.p1;
564
+ }
565
+ get end() {
566
+ return this.p2;
570
567
  }
571
568
  }
572
- class S {
569
+ class N {
573
570
  static EPSILON = 1e-10;
574
571
  name;
575
572
  constructor(t) {
576
573
  this.name = t;
577
574
  }
578
575
  }
579
- class h extends S {
576
+ class c extends N {
580
577
  static isValid(t, e, s) {
581
578
  return t <= 0 || e <= 0 || s <= 0 ? !1 : t + e > s && t + s > e && e + s > t;
582
579
  }
583
580
  static area(t, e, s) {
584
- if (!h.isValid(t, e, s))
581
+ if (!c.isValid(t, e, s))
585
582
  throw new Error("Invalid triangle");
586
583
  const i = (t + e + s) / 2;
587
584
  return Math.sqrt(i * (i - t) * (i - e) * (i - s));
588
585
  }
589
586
  static getType(t, e, s) {
590
- if (!h.isValid(t, e, s))
587
+ if (!c.isValid(t, e, s))
591
588
  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";
589
+ const i = [t, e, s].sort((u, p) => u - p), [n, o, h] = i;
590
+ return Math.abs(n - o) < c.EPSILON && Math.abs(o - h) < c.EPSILON ? "equilateral" : Math.abs(n - o) < c.EPSILON || Math.abs(o - h) < c.EPSILON ? "isosceles" : "scalene";
594
591
  }
595
592
  static getAngles(t, e, s) {
596
- if (!h.isValid(t, e, s))
593
+ if (!c.isValid(t, e, s))
597
594
  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];
595
+ 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;
596
+ return [i, n, o];
600
597
  }
601
598
  p1;
602
599
  p2;
@@ -609,110 +606,110 @@ class h extends S {
609
606
  areCollinear() {
610
607
  return Math.abs(
611
608
  (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;
609
+ ) < N.EPSILON;
613
610
  }
614
611
  get side() {
615
612
  return [
616
- o.distance(this.p1, this.p2),
617
- o.distance(this.p2, this.p3),
618
- o.distance(this.p3, this.p1)
613
+ a.distance(this.p1, this.p2),
614
+ a.distance(this.p2, this.p3),
615
+ a.distance(this.p3, this.p1)
619
616
  ];
620
617
  }
621
618
  perimeter() {
622
- return h.isValid(this.side[0], this.side[1], this.side[2]), this.side.reduce((t, e) => t + e, 0);
619
+ return c.isValid(this.side[0], this.side[1], this.side[2]), this.side.reduce((t, e) => t + e, 0);
623
620
  }
624
621
  area() {
625
622
  const [t, e, s] = this.side;
626
- return h.area(t, e, s);
623
+ return c.area(t, e, s);
627
624
  }
628
625
  get type() {
629
626
  const [t, e, s] = this.side;
630
- return h.getType(t, e, s);
627
+ return c.getType(t, e, s);
631
628
  }
632
629
  get angles() {
633
630
  const [t, e, s] = this.side;
634
- return h.getAngles(t, e, s);
631
+ return c.getAngles(t, e, s);
635
632
  }
636
633
  get centroid() {
637
- return new o(
634
+ return new a(
638
635
  (this.p1.x + this.p2.x + this.p3.x) / 3,
639
636
  (this.p1.y + this.p2.y + this.p3.y) / 3
640
637
  );
641
638
  }
642
639
  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);
640
+ 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;
641
+ return new a(n, o);
645
642
  }
646
643
  get circumcenter() {
647
644
  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
- if (Math.abs(t) < h.EPSILON)
645
+ if (Math.abs(t) < c.EPSILON)
649
646
  throw new Error("Cannot calculate circumcenter for collinear points");
650
647
  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);
648
+ return new a(e, s);
652
649
  }
653
650
  containsPoint(t) {
654
- const e = h.area(
655
- o.distance(t, this.p1),
656
- o.distance(t, this.p2),
657
- o.distance(this.p1, this.p2)
658
- ), s = h.area(
659
- o.distance(t, this.p2),
660
- o.distance(t, this.p3),
661
- o.distance(this.p2, this.p3)
662
- ), i = h.area(
663
- o.distance(t, this.p3),
664
- o.distance(t, this.p1),
665
- o.distance(this.p3, this.p1)
651
+ const e = c.area(
652
+ a.distance(t, this.p1),
653
+ a.distance(t, this.p2),
654
+ a.distance(this.p1, this.p2)
655
+ ), s = c.area(
656
+ a.distance(t, this.p2),
657
+ a.distance(t, this.p3),
658
+ a.distance(this.p2, this.p3)
659
+ ), i = c.area(
660
+ a.distance(t, this.p3),
661
+ a.distance(t, this.p1),
662
+ a.distance(this.p3, this.p1)
666
663
  );
667
- return Math.abs(e + s + i - this.area()) < h.EPSILON;
664
+ return Math.abs(e + s + i - this.area()) < c.EPSILON;
668
665
  }
669
666
  }
670
- function F(n) {
671
- return new Promise((t) => setTimeout(t, n));
667
+ function W(r) {
668
+ return new Promise((t) => setTimeout(t, r));
672
669
  }
673
- function $(n) {
670
+ function T(r) {
674
671
  const t = [], e = {
675
672
  "(": ")",
676
673
  "[": "]",
677
674
  "{": "}"
678
675
  }, s = new Set(Object.values(e));
679
- for (const i of n)
676
+ for (const i of r)
680
677
  if (i in e)
681
678
  t.push(e[i]);
682
679
  else if (s.has(i) && i !== t.pop())
683
680
  return !1;
684
681
  return t.length === 0;
685
682
  }
686
- function b(n) {
687
- return n !== null && (typeof n == "object" || typeof n == "function");
683
+ function M(r) {
684
+ return r !== null && (typeof r == "object" || typeof r == "function");
688
685
  }
689
- class H {
686
+ class F {
690
687
  map = /* @__PURE__ */ new Map();
691
688
  weakMap = /* @__PURE__ */ new WeakMap();
692
689
  set(t, e) {
693
- b(t) ? this.weakMap.set(t, e) : this.map.set(t, e);
690
+ M(t) ? this.weakMap.set(t, e) : this.map.set(t, e);
694
691
  }
695
692
  get(t) {
696
- return b(t) ? this.weakMap.get(t) : this.map.get(t);
693
+ return M(t) ? this.weakMap.get(t) : this.map.get(t);
697
694
  }
698
695
  has(t) {
699
- return b(t) ? this.weakMap.has(t) : this.map.has(t);
696
+ return M(t) ? this.weakMap.has(t) : this.map.has(t);
700
697
  }
701
698
  }
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);
699
+ function G(r) {
700
+ if (!r.length) return [];
701
+ const t = [[r[0]]];
702
+ for (let s = 1, i = r.length; s < i; s++) {
703
+ const n = r[s];
704
+ e(n);
708
705
  }
709
706
  function e(s) {
710
707
  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];
708
+ const n = t[i], o = n[t[i].length - 1];
709
+ if (o < s) {
710
+ t[i + 1] = [...n, s];
714
711
  break;
715
- } else a > s && i === 0 && (t[i] = [s]);
712
+ } else o > s && i === 0 && (t[i] = [s]);
716
713
  }
717
714
  }
718
715
  return t[t.length - 1];
@@ -737,16 +734,16 @@ class B {
737
734
  if (t.length === 0)
738
735
  throw new Error("Input cannot be empty");
739
736
  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}`);
737
+ for (const o of t)
738
+ if (!e.has(o))
739
+ throw new Error(`Invalid Roman numeral character: ${o}`);
743
740
  let s = 0, i = 0;
744
741
  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;
742
+ const o = t.slice(i, i + 2);
743
+ if (this.ROMAN_MAP.has(o))
744
+ s += this.ROMAN_MAP.get(o), i += 2;
748
745
  else {
749
- const l = t[i], u = this.ROMAN_MAP.get(l);
746
+ const h = t[i], u = this.ROMAN_MAP.get(h);
750
747
  if (!u)
751
748
  throw new Error(`Invalid Roman numeral sequence at position ${i}`);
752
749
  s += u, i += 1;
@@ -768,20 +765,105 @@ class B {
768
765
  return e;
769
766
  }
770
767
  }
771
- function X(n) {
768
+ function X(r) {
772
769
  let t;
773
- const e = new Proxy(n, {
774
- construct(s, i, r) {
770
+ const e = new Proxy(r, {
771
+ construct(s, i, n) {
775
772
  return t || (t = Reflect.construct(
776
773
  s,
777
774
  i,
778
- r
775
+ n
779
776
  )), t;
780
777
  }
781
778
  });
782
- return n.prototype.constructor = e, e;
779
+ return r.prototype.constructor = e, e;
783
780
  }
784
781
  const x = {
782
+ AUTH_UNAUTHORIZED: "未授权事件",
783
+ AUTH_LOGIN_SUCCESS: "登录成功事件",
784
+ AUTH_LOGOUT: "注销事件",
785
+ AUTH_TOKEN_EXPIRED: "令牌过期事件",
786
+ REQUEST_ERROR: "请求错误事件",
787
+ REQUEST_TIMEOUT: "请求超时事件",
788
+ REQUEST_NETWORK_ERROR: "网络错误事件",
789
+ UI_SHOW_LOADING: "显示加载事件",
790
+ UI_HIDE_LOADING: "隐藏加载事件",
791
+ UI_SHOW_MESSAGE: "显示消息事件"
792
+ };
793
+ class v {
794
+ static instance = null;
795
+ listeners = {};
796
+ debugMode;
797
+ constructor(t = !1) {
798
+ this.debugMode = t, Object.keys(x).forEach(
799
+ (e) => {
800
+ this.listeners[e] = /* @__PURE__ */ new Set();
801
+ }
802
+ );
803
+ }
804
+ // 单例模式
805
+ static getInstance(t) {
806
+ return v.instance || (v.instance = new v(t)), v.instance;
807
+ }
808
+ /**
809
+ * 添加事件监听器
810
+ * @param event 事件名称
811
+ * @param listener 监听函数
812
+ */
813
+ on(t, e) {
814
+ this.debugLog(`添加事件监听: ${x[t]}`), this.listeners[t].add(e);
815
+ }
816
+ /**
817
+ * 触发事件
818
+ * @param event 事件名称
819
+ * @param params 事件参数
820
+ */
821
+ emit(t, e) {
822
+ this.debugLog(`触发事件: ${x[t]}`, e), this.listeners[t].forEach((s) => {
823
+ try {
824
+ s(e);
825
+ } catch (i) {
826
+ console.error(`事件 ${x[t]} 处理出错:`, i);
827
+ }
828
+ });
829
+ }
830
+ /**
831
+ * 移除事件监听器
832
+ * @param event 事件名称
833
+ * @param listener 监听函数
834
+ */
835
+ off(t, e) {
836
+ this.debugLog(`移除事件监听: ${x[t]}`), this.listeners[t].delete(e);
837
+ }
838
+ /**
839
+ * 添加一次性事件监听器
840
+ * @param event 事件名称
841
+ * @param listener 监听函数
842
+ */
843
+ once(t, e) {
844
+ this.debugLog(`添加一次性事件监听: ${x[t]}`);
845
+ const s = (i) => {
846
+ e(i), this.off(t, s);
847
+ };
848
+ this.on(t, s);
849
+ }
850
+ /**
851
+ * 清除所有事件监听器
852
+ */
853
+ clear() {
854
+ this.debugLog("清除所有事件监听器"), Object.values(this.listeners).forEach((t) => t.clear());
855
+ }
856
+ /**
857
+ * 获取指定事件的监听器数量
858
+ */
859
+ getListenerCount(t) {
860
+ return this.listeners[t].size;
861
+ }
862
+ debugLog(t, e) {
863
+ this.debugMode && console.log(`[EventEmitter] ${t}`, e || "");
864
+ }
865
+ }
866
+ const b = {
785
867
  scriptRegex: /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
786
868
  javascriptRegex: /javascript:/gi,
787
869
  eventHandlerRegex: /on\w+\s*=/gi,
@@ -828,12 +910,12 @@ const x = {
828
910
  ]),
829
911
  allowedAttributes: /* @__PURE__ */ new Set(["class", "id", "href", "src", "alt", "title"])
830
912
  };
831
- class v {
913
+ class I {
832
914
  static instance;
833
915
  constructor() {
834
916
  }
835
917
  static getInstance() {
836
- return v.instance || (v.instance = new v()), v.instance;
918
+ return I.instance || (I.instance = new I()), I.instance;
837
919
  }
838
920
  /**
839
921
  * 创建DOM元素
@@ -843,7 +925,7 @@ class v {
843
925
  * @returns 创建的HTMLElement
844
926
  */
845
927
  createElement(t, e = {}, s = "") {
846
- if (!x.allowedTags.has(t.toLowerCase()))
928
+ if (!b.allowedTags.has(t.toLowerCase()))
847
929
  throw new Error(`Unsupported tag: ${t}`);
848
930
  const i = document.createElement(t);
849
931
  return this._processAttributes(i, e), this._processContent(i, s), i;
@@ -856,12 +938,12 @@ class v {
856
938
  createBatch(t, e) {
857
939
  const s = document.createDocumentFragment();
858
940
  t.forEach((i) => {
859
- const r = this.createElement(
941
+ const n = this.createElement(
860
942
  i.tag,
861
943
  i.attributes || {},
862
944
  i.content || ""
863
945
  );
864
- s.appendChild(r);
946
+ s.appendChild(n);
865
947
  }), e.appendChild(s);
866
948
  }
867
949
  /**
@@ -879,7 +961,7 @@ class v {
879
961
  */
880
962
  _processAttributes(t, e) {
881
963
  Object.entries(e).forEach(([s, i]) => {
882
- if (!x.allowedAttributes.has(s) && !s.startsWith("data-")) {
964
+ if (!b.allowedAttributes.has(s) && !s.startsWith("data-")) {
883
965
  console.warn(`Potentially unsafe attribute: ${s}`);
884
966
  return;
885
967
  }
@@ -918,10 +1000,10 @@ class v {
918
1000
  * @private
919
1001
  */
920
1002
  _sanitizeHtml(t) {
921
- return t.replace(x.scriptRegex, "").replace(x.javascriptRegex, "").replace(x.eventHandlerRegex, "");
1003
+ return t.replace(b.scriptRegex, "").replace(b.javascriptRegex, "").replace(b.eventHandlerRegex, "");
922
1004
  }
923
1005
  }
924
- class G {
1006
+ class Q {
925
1007
  features;
926
1008
  constructor() {
927
1009
  this.features = this.detectFeatures();
@@ -947,19 +1029,19 @@ class G {
947
1029
  };
948
1030
  return new Promise((s, i) => {
949
1031
  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
1032
+ (n) => s({
1033
+ latitude: n.coords.latitude,
1034
+ longitude: n.coords.longitude,
1035
+ accuracy: n.coords.accuracy,
1036
+ timstamp: n.timestamp
955
1037
  }),
956
- (r) => {
957
- const a = {
1038
+ (n) => {
1039
+ const o = {
958
1040
  1: "User denied the request for Geolocation.",
959
1041
  2: "Position information is unavailable.",
960
1042
  3: "The request to get user location timed out."
961
1043
  };
962
- i(new Error(a[r.code] || "Unknown error"));
1044
+ i(new Error(o[n.code] || "Unknown error"));
963
1045
  },
964
1046
  { ...e, ...t }
965
1047
  );
@@ -1007,26 +1089,95 @@ class G {
1007
1089
  }
1008
1090
  }
1009
1091
  }
1092
+ String.prototype.pointLength = function() {
1093
+ let r = 0;
1094
+ for (let t = 0, e = this.length; t < e; ) {
1095
+ const s = this.codePointAt(t);
1096
+ t += s > 65535 ? 2 : 1, r++;
1097
+ }
1098
+ return r;
1099
+ };
1100
+ String.prototype.pointAt = function(r) {
1101
+ if (r >= this.pointLength()) return;
1102
+ let t = 0;
1103
+ for (let e = 0, s = this.length; e < s; ) {
1104
+ const i = this.codePointAt(e);
1105
+ if (!i) return;
1106
+ if (t === r)
1107
+ return String.fromCodePoint(i);
1108
+ e += i > 65535 ? 2 : 1, t++;
1109
+ }
1110
+ };
1111
+ String.prototype.sliceByPoint = function(r, t = this.pointLength()) {
1112
+ let e = "";
1113
+ for (let s = r; s < t; s++)
1114
+ e += this.pointAt(s);
1115
+ return e;
1116
+ };
1117
+ RegExp.escape = function(r) {
1118
+ return r.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1119
+ };
1120
+ Element.prototype.farthest = function(r) {
1121
+ if (typeof r != "string" || !r) return null;
1122
+ let t = null, e = this;
1123
+ for (; e; ) {
1124
+ const s = e.closest(r);
1125
+ if (!s)
1126
+ break;
1127
+ t = s, e = s.parentElement;
1128
+ }
1129
+ return t;
1130
+ };
1131
+ Object.defineProperties(Element.prototype, {
1132
+ firstElement: {
1133
+ get: function() {
1134
+ if (!this.children.length) return null;
1135
+ let r = this.firstElementChild, t = null;
1136
+ for (; r; )
1137
+ t = r, r = r.firstElementChild;
1138
+ return t;
1139
+ }
1140
+ },
1141
+ lastElement: {
1142
+ get: function() {
1143
+ if (!this.children.length) return null;
1144
+ let r = this.lastElementChild, t = null;
1145
+ for (; r; )
1146
+ t = r, r = r.lastElementChild;
1147
+ return t;
1148
+ }
1149
+ }
1150
+ });
1151
+ Text.prototype.surround = function(r = "strong", t = "") {
1152
+ if (!this.nodeValue || !r || !t) return null;
1153
+ const s = r.split("."), i = s[0], n = s.slice(1).join(" "), o = this.textContent.indexOf(t);
1154
+ if (o < 0) return null;
1155
+ const h = document.createRange();
1156
+ h.setStart(this, o), h.setEnd(this, o + t.length);
1157
+ const u = document.createElement(i);
1158
+ return n && (u.className = n), h.surroundContents(u), u;
1159
+ };
1010
1160
  export {
1011
- k as Dictionary,
1012
- 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,
1161
+ j as Dictionary,
1162
+ I as DomHelper,
1163
+ v as Emitter,
1164
+ H as Graph,
1165
+ G as LIS,
1166
+ D as LRU,
1167
+ l as Line,
1168
+ q as LinkedList,
1169
+ E as Matrix,
1170
+ _ as MaxHeap,
1171
+ F as MemoizeMap,
1172
+ R as MinHeap,
1173
+ a as Point,
1174
+ U as Queue,
1024
1175
  B as Roman,
1025
- j as Stack,
1026
- h as Triangle,
1027
- f as Vector,
1028
- G as WebAppManager,
1029
- $ as isValidBracket,
1176
+ V as Stack,
1177
+ c as Triangle,
1178
+ g as Vector,
1179
+ Q as WebAppManager,
1180
+ T as isValidBracket,
1030
1181
  X as singleton,
1031
- F as sleep
1182
+ W as sleep
1032
1183
  };