jc-structure 0.1.14 → 0.1.15
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.
- package/dist/jc-structure.js +289 -125
- package/dist/jc-structure.umd.cjs +2 -2
- package/index.d.ts +203 -73
- package/package.json +1 -1
package/dist/jc-structure.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class j {
|
|
2
2
|
items = {};
|
|
3
3
|
count = 0;
|
|
4
4
|
lowestCount = 0;
|
|
@@ -111,13 +111,13 @@ class $ {
|
|
|
111
111
|
return this.isEmpty() ? "" : `MinStack(count: ${this.size()}):[${this.getMin()},...rest]`;
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
-
function
|
|
114
|
+
function k(r, t) {
|
|
115
115
|
return r === t ? 0 : r < t ? -1 : 1;
|
|
116
116
|
}
|
|
117
|
-
class
|
|
117
|
+
class y {
|
|
118
118
|
heap = [];
|
|
119
119
|
compareFn;
|
|
120
|
-
constructor(t =
|
|
120
|
+
constructor(t = k) {
|
|
121
121
|
this.compareFn = t;
|
|
122
122
|
}
|
|
123
123
|
static getLeftIndex(t) {
|
|
@@ -148,7 +148,7 @@ class w {
|
|
|
148
148
|
return this.heap.toString();
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
-
class
|
|
151
|
+
class O extends y {
|
|
152
152
|
insert(t) {
|
|
153
153
|
return t ? !1 : (this.heap.push(t), this.siftUp(this.heap.length - 1), !0);
|
|
154
154
|
}
|
|
@@ -159,24 +159,24 @@ class P extends w {
|
|
|
159
159
|
return this.heap[0] = this.heap.pop(), this.siftDown(0), t;
|
|
160
160
|
}
|
|
161
161
|
siftUp(t) {
|
|
162
|
-
let e = t, s =
|
|
163
|
-
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 && (
|
|
162
|
+
let e = t, s = y.getLeftIndex(e), i = y.getRightIndex(e), n = this.size();
|
|
163
|
+
s < n && this.compareFn(this.heap[e], this.heap[s]) === -1 && (e = s), i < n && this.compareFn(this.heap[e], this.heap[i]) === 1 && (e = i), e !== t && (y.swap(this.heap, t, e), this.siftUp(e));
|
|
164
164
|
}
|
|
165
165
|
siftDown(t) {
|
|
166
|
-
let e =
|
|
166
|
+
let e = y.getParentIndex(t);
|
|
167
167
|
for (; t > 0 && e && this.compareFn(this.heap[e], this.heap[t]) === 1; )
|
|
168
|
-
|
|
168
|
+
y.swap(this.heap, e, t), t = e, e = y.getParentIndex(t);
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
|
-
class q extends
|
|
172
|
-
constructor(t = (e, s) =>
|
|
171
|
+
class q extends O {
|
|
172
|
+
constructor(t = (e, s) => k(s, e)) {
|
|
173
173
|
super(t);
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
function R(r) {
|
|
177
177
|
return { value: r };
|
|
178
178
|
}
|
|
179
|
-
class
|
|
179
|
+
class D {
|
|
180
180
|
capacity;
|
|
181
181
|
length = 0;
|
|
182
182
|
head = null;
|
|
@@ -292,17 +292,17 @@ class H {
|
|
|
292
292
|
return t = t.slice(0, -1), t;
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
class
|
|
295
|
+
class V {
|
|
296
296
|
key;
|
|
297
297
|
value;
|
|
298
298
|
constructor(t, e) {
|
|
299
299
|
this.key = t, this.value = e;
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
|
-
function
|
|
302
|
+
function P(r, t = { emptyString: !1, zeroNumber: !1 }) {
|
|
303
303
|
return r == null ? !(t.emptyString && r === "" || t.zeroNumber && r === 0) : !1;
|
|
304
304
|
}
|
|
305
|
-
class
|
|
305
|
+
class z {
|
|
306
306
|
table = [];
|
|
307
307
|
constructor() {
|
|
308
308
|
}
|
|
@@ -313,15 +313,15 @@ class j {
|
|
|
313
313
|
return -1;
|
|
314
314
|
}
|
|
315
315
|
set(t, e) {
|
|
316
|
-
if (
|
|
316
|
+
if (P(t))
|
|
317
317
|
throw new Error("key is required");
|
|
318
|
-
if (
|
|
318
|
+
if (P(e))
|
|
319
319
|
throw new Error("value is required");
|
|
320
320
|
if (this.has(t)) {
|
|
321
321
|
let s = this.getItemIndex(t);
|
|
322
322
|
this.table[s].value = e;
|
|
323
323
|
} else {
|
|
324
|
-
const s = new
|
|
324
|
+
const s = new V(t, e);
|
|
325
325
|
this.table.push(s);
|
|
326
326
|
}
|
|
327
327
|
}
|
|
@@ -377,7 +377,7 @@ class W {
|
|
|
377
377
|
vertices;
|
|
378
378
|
adjList;
|
|
379
379
|
constructor(t = !1) {
|
|
380
|
-
this.isDirected = t, this.vertices = [], this.adjList = new
|
|
380
|
+
this.isDirected = t, this.vertices = [], this.adjList = new z();
|
|
381
381
|
}
|
|
382
382
|
addVertex(t) {
|
|
383
383
|
this.vertices.includes(t) || (this.vertices.push(t), this.adjList.set(t, []));
|
|
@@ -399,10 +399,10 @@ class W {
|
|
|
399
399
|
return t;
|
|
400
400
|
}
|
|
401
401
|
}
|
|
402
|
-
class
|
|
402
|
+
class w {
|
|
403
403
|
_data;
|
|
404
404
|
static zero(t) {
|
|
405
|
-
return new
|
|
405
|
+
return new w(...Array(t).fill(0));
|
|
406
406
|
}
|
|
407
407
|
constructor(...t) {
|
|
408
408
|
this._data = t;
|
|
@@ -421,7 +421,7 @@ class g {
|
|
|
421
421
|
if (t === 0)
|
|
422
422
|
throw new Error("Cannot normalize a zero vector");
|
|
423
423
|
const e = this._data.map((s) => s / t);
|
|
424
|
-
return new
|
|
424
|
+
return new w(...e);
|
|
425
425
|
}
|
|
426
426
|
add(t) {
|
|
427
427
|
if (this.dimension !== t.dimension)
|
|
@@ -429,7 +429,7 @@ class g {
|
|
|
429
429
|
const e = this._data.map(
|
|
430
430
|
(s, i) => s + t._data[i]
|
|
431
431
|
);
|
|
432
|
-
return new
|
|
432
|
+
return new w(...e);
|
|
433
433
|
}
|
|
434
434
|
sub(t) {
|
|
435
435
|
if (this.dimension !== t.dimension)
|
|
@@ -437,10 +437,10 @@ class g {
|
|
|
437
437
|
const e = this._data.map(
|
|
438
438
|
(s, i) => s - t._data[i]
|
|
439
439
|
);
|
|
440
|
-
return new
|
|
440
|
+
return new w(...e);
|
|
441
441
|
}
|
|
442
442
|
mul(t) {
|
|
443
|
-
return new
|
|
443
|
+
return new w(...this._data.map((e) => e * t));
|
|
444
444
|
}
|
|
445
445
|
dot(t) {
|
|
446
446
|
if (this.dimension !== t.dimension)
|
|
@@ -480,10 +480,10 @@ class E {
|
|
|
480
480
|
return this.row * this.col;
|
|
481
481
|
}
|
|
482
482
|
rowVector(t) {
|
|
483
|
-
return new
|
|
483
|
+
return new w(...this._matrix[t]);
|
|
484
484
|
}
|
|
485
485
|
colVector(t) {
|
|
486
|
-
return new
|
|
486
|
+
return new w(...this._matrix.map((e) => e[t]));
|
|
487
487
|
}
|
|
488
488
|
getItem(t) {
|
|
489
489
|
return this._matrix[t[0]][t[1]];
|
|
@@ -534,7 +534,7 @@ class E {
|
|
|
534
534
|
return e;
|
|
535
535
|
}
|
|
536
536
|
}
|
|
537
|
-
class
|
|
537
|
+
class c {
|
|
538
538
|
static distance(t, e) {
|
|
539
539
|
return Math.hypot(e.x - t.x, e.y - t.y);
|
|
540
540
|
}
|
|
@@ -544,42 +544,42 @@ class a {
|
|
|
544
544
|
this.x = t, this.y = e;
|
|
545
545
|
}
|
|
546
546
|
distanceTo(t) {
|
|
547
|
-
return
|
|
547
|
+
return c.distance(this, t);
|
|
548
548
|
}
|
|
549
549
|
}
|
|
550
|
-
class
|
|
550
|
+
class m {
|
|
551
551
|
// 使用更合适的精度阈值常量
|
|
552
552
|
static EPSILON = 1e-10;
|
|
553
|
-
static sloped(t, e =
|
|
553
|
+
static sloped(t, e = m.EPSILON) {
|
|
554
554
|
const s = t.p2.x - t.p1.x, i = t.p2.y - t.p1.y;
|
|
555
555
|
return Math.abs(s) < e ? Math.abs(i) < e ? 0 : null : i / s;
|
|
556
556
|
}
|
|
557
|
-
static isParallel(t, e, s =
|
|
558
|
-
const i =
|
|
557
|
+
static isParallel(t, e, s = m.EPSILON) {
|
|
558
|
+
const i = m.sloped(t), n = m.sloped(e);
|
|
559
559
|
return i === null && n === null ? !0 : i === null || n === null ? !1 : Math.abs(i - n) < s;
|
|
560
560
|
}
|
|
561
|
-
static getIntersection(t, e, s =
|
|
562
|
-
if (
|
|
563
|
-
const i = t.p1.x, n = t.p1.y,
|
|
564
|
-
if (Math.abs(
|
|
565
|
-
const
|
|
566
|
-
if (
|
|
567
|
-
const
|
|
568
|
-
return new
|
|
561
|
+
static getIntersection(t, e, s = m.EPSILON) {
|
|
562
|
+
if (m.isParallel(t, e)) return null;
|
|
563
|
+
const i = t.p1.x, n = t.p1.y, a = t.p2.x, h = t.p2.y, u = e.p1.x, f = e.p1.y, g = e.p2.x, o = e.p2.y, l = (i - a) * (f - o) - (n - h) * (u - g);
|
|
564
|
+
if (Math.abs(l) < s) return null;
|
|
565
|
+
const d = ((i - u) * (f - o) - (n - f) * (u - g)) / l, S = -((i - a) * (n - f) - (n - h) * (i - u)) / l;
|
|
566
|
+
if (d >= 0 && d <= 1 && S >= 0 && S <= 1) {
|
|
567
|
+
const C = i + d * (a - i), L = n + d * (h - n);
|
|
568
|
+
return new c(C, L);
|
|
569
569
|
}
|
|
570
570
|
return null;
|
|
571
571
|
}
|
|
572
572
|
static isIntersecting(t, e) {
|
|
573
|
-
return
|
|
573
|
+
return m.getIntersection(t, e) !== null;
|
|
574
574
|
}
|
|
575
|
-
static distanceToPoint(t, e, s =
|
|
576
|
-
const i = e.x - t.p1.x, n = e.y - t.p1.y,
|
|
577
|
-
let
|
|
578
|
-
|
|
579
|
-
let
|
|
580
|
-
|
|
581
|
-
const
|
|
582
|
-
return Math.hypot(
|
|
575
|
+
static distanceToPoint(t, e, s = m.EPSILON) {
|
|
576
|
+
const i = e.x - t.p1.x, n = e.y - t.p1.y, a = t.p2.x - t.p1.x, h = t.p2.y - t.p1.y, u = i * a + n * h, f = a * a + h * h;
|
|
577
|
+
let g = -1;
|
|
578
|
+
f > s && (g = u / f);
|
|
579
|
+
let o, l;
|
|
580
|
+
g < 0 ? (o = t.p1.x, l = t.p1.y) : g > 1 ? (o = t.p2.x, l = t.p2.y) : (o = t.p1.x + g * a, l = t.p1.y + g * h);
|
|
581
|
+
const d = e.x - o, S = e.y - l;
|
|
582
|
+
return Math.hypot(d + S);
|
|
583
583
|
}
|
|
584
584
|
p1;
|
|
585
585
|
p2;
|
|
@@ -592,21 +592,21 @@ class l {
|
|
|
592
592
|
}
|
|
593
593
|
get midpoint() {
|
|
594
594
|
const t = (this.p1.x + this.p2.x) / 2, e = (this.p1.y + this.p2.y) / 2;
|
|
595
|
-
return new
|
|
595
|
+
return new c(t, e);
|
|
596
596
|
}
|
|
597
597
|
get angle() {
|
|
598
598
|
return Math.atan2(this.p2.y - this.p1.y, this.p2.x - this.p1.x);
|
|
599
599
|
}
|
|
600
|
-
containsPoint(t, e =
|
|
600
|
+
containsPoint(t, e = m.EPSILON) {
|
|
601
601
|
const s = (t.x - this.p1.x) * (this.p2.y - this.p1.y) - (t.y - this.p1.y) * (this.p2.x - this.p1.x);
|
|
602
602
|
return Math.abs(s) > e ? !1 : (t.x - this.p1.x) * (t.x - this.p2.x) + (t.y - this.p1.y) * (t.y - this.p2.y) <= e;
|
|
603
603
|
}
|
|
604
604
|
// 获取线段的方向向量
|
|
605
605
|
get direction() {
|
|
606
606
|
const t = this.length;
|
|
607
|
-
if (t <
|
|
607
|
+
if (t < m.EPSILON) return new c(0, 0);
|
|
608
608
|
const e = (this.p2.x - this.p1.x) / t, s = (this.p2.y - this.p1.y) / t;
|
|
609
|
-
return new
|
|
609
|
+
return new c(e, s);
|
|
610
610
|
}
|
|
611
611
|
get start() {
|
|
612
612
|
return this.p1;
|
|
@@ -615,34 +615,34 @@ class l {
|
|
|
615
615
|
return this.p2;
|
|
616
616
|
}
|
|
617
617
|
}
|
|
618
|
-
class
|
|
618
|
+
class N {
|
|
619
619
|
static EPSILON = 1e-10;
|
|
620
620
|
name;
|
|
621
621
|
constructor(t) {
|
|
622
622
|
this.name = t;
|
|
623
623
|
}
|
|
624
624
|
}
|
|
625
|
-
class
|
|
625
|
+
class p extends N {
|
|
626
626
|
static isValid(t, e, s) {
|
|
627
627
|
return t <= 0 || e <= 0 || s <= 0 ? !1 : t + e > s && t + s > e && e + s > t;
|
|
628
628
|
}
|
|
629
629
|
static area(t, e, s) {
|
|
630
|
-
if (!
|
|
630
|
+
if (!p.isValid(t, e, s))
|
|
631
631
|
throw new Error("Invalid triangle");
|
|
632
632
|
const i = (t + e + s) / 2;
|
|
633
633
|
return Math.sqrt(i * (i - t) * (i - e) * (i - s));
|
|
634
634
|
}
|
|
635
635
|
static getType(t, e, s) {
|
|
636
|
-
if (!
|
|
636
|
+
if (!p.isValid(t, e, s))
|
|
637
637
|
throw new Error("Invalid triangle sides");
|
|
638
|
-
const i = [t, e, s].sort((u,
|
|
639
|
-
return Math.abs(n -
|
|
638
|
+
const i = [t, e, s].sort((u, f) => u - f), [n, a, h] = i;
|
|
639
|
+
return Math.abs(n - a) < p.EPSILON && Math.abs(a - h) < p.EPSILON ? "equilateral" : Math.abs(n - a) < p.EPSILON || Math.abs(a - h) < p.EPSILON ? "isosceles" : "scalene";
|
|
640
640
|
}
|
|
641
641
|
static getAngles(t, e, s) {
|
|
642
|
-
if (!
|
|
642
|
+
if (!p.isValid(t, e, s))
|
|
643
643
|
throw new Error("Invalid triangle sides");
|
|
644
|
-
const i = Math.acos((e * e + s * s - t * t) / (2 * e * s)), n = Math.acos((t * t + s * s - e * e) / (2 * t * s)),
|
|
645
|
-
return [i, n,
|
|
644
|
+
const i = Math.acos((e * e + s * s - t * t) / (2 * e * s)), n = Math.acos((t * t + s * s - e * e) / (2 * t * s)), a = Math.PI - i - n;
|
|
645
|
+
return [i, n, a];
|
|
646
646
|
}
|
|
647
647
|
p1;
|
|
648
648
|
p2;
|
|
@@ -655,62 +655,62 @@ class c extends k {
|
|
|
655
655
|
areCollinear() {
|
|
656
656
|
return Math.abs(
|
|
657
657
|
(this.p2.x - this.p1.x) * (this.p3.y - this.p1.y) - (this.p3.x - this.p1.x) * (this.p2.y - this.p1.y)
|
|
658
|
-
) <
|
|
658
|
+
) < N.EPSILON;
|
|
659
659
|
}
|
|
660
660
|
get side() {
|
|
661
661
|
return [
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
662
|
+
c.distance(this.p1, this.p2),
|
|
663
|
+
c.distance(this.p2, this.p3),
|
|
664
|
+
c.distance(this.p3, this.p1)
|
|
665
665
|
];
|
|
666
666
|
}
|
|
667
667
|
perimeter() {
|
|
668
|
-
return
|
|
668
|
+
return p.isValid(this.side[0], this.side[1], this.side[2]), this.side.reduce((t, e) => t + e, 0);
|
|
669
669
|
}
|
|
670
670
|
area() {
|
|
671
671
|
const [t, e, s] = this.side;
|
|
672
|
-
return
|
|
672
|
+
return p.area(t, e, s);
|
|
673
673
|
}
|
|
674
674
|
get type() {
|
|
675
675
|
const [t, e, s] = this.side;
|
|
676
|
-
return
|
|
676
|
+
return p.getType(t, e, s);
|
|
677
677
|
}
|
|
678
678
|
get angles() {
|
|
679
679
|
const [t, e, s] = this.side;
|
|
680
|
-
return
|
|
680
|
+
return p.getAngles(t, e, s);
|
|
681
681
|
}
|
|
682
682
|
get centroid() {
|
|
683
|
-
return new
|
|
683
|
+
return new c(
|
|
684
684
|
(this.p1.x + this.p2.x + this.p3.x) / 3,
|
|
685
685
|
(this.p1.y + this.p2.y + this.p3.y) / 3
|
|
686
686
|
);
|
|
687
687
|
}
|
|
688
688
|
get incenter() {
|
|
689
|
-
const [t, e, s] = this.side, i = this.perimeter() / 2, n = (t * this.p1.x + e * this.p2.x + s * this.p3.x) / i,
|
|
690
|
-
return new
|
|
689
|
+
const [t, e, s] = this.side, i = this.perimeter() / 2, n = (t * this.p1.x + e * this.p2.x + s * this.p3.x) / i, a = (t * this.p1.y + e * this.p2.y + s * this.p3.y) / i;
|
|
690
|
+
return new c(n, a);
|
|
691
691
|
}
|
|
692
692
|
get circumcenter() {
|
|
693
693
|
const t = 2 * (this.p1.x * (this.p2.y - this.p3.y) + this.p2.x * (this.p3.y - this.p1.y) + this.p3.x * (this.p1.y - this.p2.y));
|
|
694
|
-
if (Math.abs(t) <
|
|
694
|
+
if (Math.abs(t) < p.EPSILON)
|
|
695
695
|
throw new Error("Cannot calculate circumcenter for collinear points");
|
|
696
696
|
const e = ((this.p1.x * this.p1.x + this.p1.y * this.p1.y) * (this.p2.y - this.p3.y) + (this.p2.x * this.p2.x + this.p2.y * this.p2.y) * (this.p3.y - this.p1.y) + (this.p3.x * this.p3.x + this.p3.y * this.p3.y) * (this.p1.y - this.p2.y)) / t, s = ((this.p1.x * this.p1.x + this.p1.y * this.p1.y) * (this.p3.x - this.p2.x) + (this.p2.x * this.p2.x + this.p2.y * this.p2.y) * (this.p1.x - this.p3.x) + (this.p3.x * this.p3.x + this.p3.y * this.p3.y) * (this.p2.x - this.p1.x)) / t;
|
|
697
|
-
return new
|
|
697
|
+
return new c(e, s);
|
|
698
698
|
}
|
|
699
699
|
containsPoint(t) {
|
|
700
|
-
const e =
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
), s =
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
), i =
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
700
|
+
const e = p.area(
|
|
701
|
+
c.distance(t, this.p1),
|
|
702
|
+
c.distance(t, this.p2),
|
|
703
|
+
c.distance(this.p1, this.p2)
|
|
704
|
+
), s = p.area(
|
|
705
|
+
c.distance(t, this.p2),
|
|
706
|
+
c.distance(t, this.p3),
|
|
707
|
+
c.distance(this.p2, this.p3)
|
|
708
|
+
), i = p.area(
|
|
709
|
+
c.distance(t, this.p3),
|
|
710
|
+
c.distance(t, this.p1),
|
|
711
|
+
c.distance(this.p3, this.p1)
|
|
712
712
|
);
|
|
713
|
-
return Math.abs(e + s + i - this.area()) <
|
|
713
|
+
return Math.abs(e + s + i - this.area()) < p.EPSILON;
|
|
714
714
|
}
|
|
715
715
|
}
|
|
716
716
|
function T(r) {
|
|
@@ -732,7 +732,7 @@ function F(r) {
|
|
|
732
732
|
function M(r) {
|
|
733
733
|
return r !== null && (typeof r == "object" || typeof r == "function");
|
|
734
734
|
}
|
|
735
|
-
class
|
|
735
|
+
class B {
|
|
736
736
|
map = /* @__PURE__ */ new Map();
|
|
737
737
|
weakMap = /* @__PURE__ */ new WeakMap();
|
|
738
738
|
set(t, e) {
|
|
@@ -745,7 +745,7 @@ class G {
|
|
|
745
745
|
return M(t) ? this.weakMap.has(t) : this.map.has(t);
|
|
746
746
|
}
|
|
747
747
|
}
|
|
748
|
-
function
|
|
748
|
+
function G(r) {
|
|
749
749
|
if (!r.length) return [];
|
|
750
750
|
const t = [[r[0]]];
|
|
751
751
|
for (let s = 1, i = r.length; s < i; s++) {
|
|
@@ -754,11 +754,11 @@ function B(r) {
|
|
|
754
754
|
}
|
|
755
755
|
function e(s) {
|
|
756
756
|
for (let i = t.length - 1; i >= 0; i--) {
|
|
757
|
-
const n = t[i],
|
|
758
|
-
if (
|
|
757
|
+
const n = t[i], a = n[t[i].length - 1];
|
|
758
|
+
if (a < s) {
|
|
759
759
|
t[i + 1] = [...n, s];
|
|
760
760
|
break;
|
|
761
|
-
} else
|
|
761
|
+
} else a > s && i === 0 && (t[i] = [s]);
|
|
762
762
|
}
|
|
763
763
|
}
|
|
764
764
|
return t[t.length - 1];
|
|
@@ -783,14 +783,14 @@ class X {
|
|
|
783
783
|
if (t.length === 0)
|
|
784
784
|
throw new Error("Input cannot be empty");
|
|
785
785
|
const e = /* @__PURE__ */ new Set(["I", "V", "X", "L", "C", "D", "M"]);
|
|
786
|
-
for (const
|
|
787
|
-
if (!e.has(
|
|
788
|
-
throw new Error(`Invalid Roman numeral character: ${
|
|
786
|
+
for (const a of t)
|
|
787
|
+
if (!e.has(a))
|
|
788
|
+
throw new Error(`Invalid Roman numeral character: ${a}`);
|
|
789
789
|
let s = 0, i = 0;
|
|
790
790
|
for (; i < t.length; ) {
|
|
791
|
-
const
|
|
792
|
-
if (this.ROMAN_MAP.has(
|
|
793
|
-
s += this.ROMAN_MAP.get(
|
|
791
|
+
const a = t.slice(i, i + 2);
|
|
792
|
+
if (this.ROMAN_MAP.has(a))
|
|
793
|
+
s += this.ROMAN_MAP.get(a), i += 2;
|
|
794
794
|
else {
|
|
795
795
|
const h = t[i], u = this.ROMAN_MAP.get(h);
|
|
796
796
|
if (!u)
|
|
@@ -814,7 +814,167 @@ class X {
|
|
|
814
814
|
return e;
|
|
815
815
|
}
|
|
816
816
|
}
|
|
817
|
-
|
|
817
|
+
class Q {
|
|
818
|
+
static isValidPositiveInteger(t) {
|
|
819
|
+
return Number.isInteger(t) && t > 0 && t <= Number.MAX_SAFE_INTEGER;
|
|
820
|
+
}
|
|
821
|
+
static isPowerOfTwo(t) {
|
|
822
|
+
return t > 0 && (t & t - 1) === 0;
|
|
823
|
+
}
|
|
824
|
+
static isOdd(t) {
|
|
825
|
+
return t % 2 === 1 || t % 2 === -1;
|
|
826
|
+
}
|
|
827
|
+
static factorial(t) {
|
|
828
|
+
if (!this.isValidPositiveInteger(t))
|
|
829
|
+
throw new Error("Input must be a non-negative integer");
|
|
830
|
+
if (t < 2)
|
|
831
|
+
return 1;
|
|
832
|
+
let e = 1;
|
|
833
|
+
for (let s = 2; s <= t; s++)
|
|
834
|
+
e *= s;
|
|
835
|
+
return e;
|
|
836
|
+
}
|
|
837
|
+
static fibonacci(t, e = 1, s = 1) {
|
|
838
|
+
if (!this.isValidPositiveInteger(t))
|
|
839
|
+
throw new Error("Input must be a non-negative integer");
|
|
840
|
+
return t < 2 ? s : this.fibonacci(t - 1, s, s + e);
|
|
841
|
+
}
|
|
842
|
+
static fibonacciIterative(t) {
|
|
843
|
+
if (!this.isValidPositiveInteger(t))
|
|
844
|
+
throw new Error("Input must be a non-negative integer");
|
|
845
|
+
let e = 1, s = 1;
|
|
846
|
+
for (let i = 2; i < t; i++)
|
|
847
|
+
[e, s] = [s, e + s];
|
|
848
|
+
return t === 0 ? 0 : s;
|
|
849
|
+
}
|
|
850
|
+
static getPercentWithPrecision(t, e = 2) {
|
|
851
|
+
if (!Array.isArray(t) || t.length === 0)
|
|
852
|
+
return [];
|
|
853
|
+
if (e < 0 || !Number.isInteger(e))
|
|
854
|
+
throw new Error("Precision must be a non-negative integer");
|
|
855
|
+
const s = t.reduce((o, l) => o + l, 0);
|
|
856
|
+
if (s === 0)
|
|
857
|
+
return t.map(() => "0%");
|
|
858
|
+
const n = 100 * Math.pow(10, e), a = t.map((o) => o / s * n), h = a.map((o) => Math.floor(o)), u = a.map((o, l) => o - h[l]);
|
|
859
|
+
let f = h.reduce((o, l) => o + l, 0), g = n - f;
|
|
860
|
+
for (; g > 0; ) {
|
|
861
|
+
let o = -1, l = -1;
|
|
862
|
+
for (let d = 0; d < u.length; d++)
|
|
863
|
+
u[d] > l && (l = u[d], o = d);
|
|
864
|
+
if (o === -1) break;
|
|
865
|
+
h[o]++, u[o] = 0, g--;
|
|
866
|
+
}
|
|
867
|
+
return h.map((o) => `${(o / n * 100).toFixed(e)}%`);
|
|
868
|
+
}
|
|
869
|
+
static fastSqrt(t) {
|
|
870
|
+
if (t < 0)
|
|
871
|
+
throw new Error("n must be a non-negative number");
|
|
872
|
+
const e = 0.5 * t;
|
|
873
|
+
let s = new BigInt64Array(new Float32Array([t]).buffer)[0];
|
|
874
|
+
s = 0x1ff7a3bea91d9b1bn + (s >> 1n);
|
|
875
|
+
let i = new Float64Array(new BigInt64Array([s]).buffer)[0];
|
|
876
|
+
return i = i * 0.5 + e / i, i = i * 0.5 + e / i, i = i * 0.5 + e / i, i;
|
|
877
|
+
}
|
|
878
|
+
static middle(t, e) {
|
|
879
|
+
return e - (e - t >> 1);
|
|
880
|
+
}
|
|
881
|
+
static gcd(t, e) {
|
|
882
|
+
return e === 0 ? t : this.gcd(e, t % e);
|
|
883
|
+
}
|
|
884
|
+
static lcm(t, e) {
|
|
885
|
+
return t * e / this.gcd(t, e);
|
|
886
|
+
}
|
|
887
|
+
static isPrime(t) {
|
|
888
|
+
if (t <= 1)
|
|
889
|
+
return !1;
|
|
890
|
+
for (let e = 2; e <= Math.sqrt(t); e++)
|
|
891
|
+
if (t % e === 0)
|
|
892
|
+
return !1;
|
|
893
|
+
return !0;
|
|
894
|
+
}
|
|
895
|
+
static isPalindrome(t) {
|
|
896
|
+
if (t < 0 || t % 10 === 0 && t !== 0)
|
|
897
|
+
return !1;
|
|
898
|
+
let e = 0, s = t;
|
|
899
|
+
for (; t > 0; ) {
|
|
900
|
+
const i = t % 10;
|
|
901
|
+
e = e * 10 + i, t = Math.floor(t / 10);
|
|
902
|
+
}
|
|
903
|
+
return s === e;
|
|
904
|
+
}
|
|
905
|
+
static isArmstrong(t) {
|
|
906
|
+
const e = t.toString(), s = e.length;
|
|
907
|
+
let i = 0;
|
|
908
|
+
for (let n = 0; n < s; n++)
|
|
909
|
+
i += Math.pow(parseInt(e[n]), s);
|
|
910
|
+
return i === t;
|
|
911
|
+
}
|
|
912
|
+
static isPerfect(t) {
|
|
913
|
+
let e = 0;
|
|
914
|
+
for (let s = 1; s < t; s++)
|
|
915
|
+
t % s === 0 && (e += s);
|
|
916
|
+
return e === t;
|
|
917
|
+
}
|
|
918
|
+
static scale(t, e, s) {
|
|
919
|
+
if (e[0] >= e[1] || s[0] >= s[1])
|
|
920
|
+
throw new Error("Invalid range");
|
|
921
|
+
const i = e[1] - e[0];
|
|
922
|
+
return (t - e[0]) * ((s[1] - s[0]) / i) + s[0];
|
|
923
|
+
}
|
|
924
|
+
static randomInt(t, e) {
|
|
925
|
+
return Math.floor(Math.random() * (e - t + 1)) + t;
|
|
926
|
+
}
|
|
927
|
+
static floatEqual(t, e, s = 1e-6) {
|
|
928
|
+
return Math.abs(t - e) < s;
|
|
929
|
+
}
|
|
930
|
+
static isSameSign(t, e) {
|
|
931
|
+
return t >= 0 && e >= 0 || t <= 0 && e <= 0;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
class K {
|
|
935
|
+
static READ = 1;
|
|
936
|
+
static WRITE = 2;
|
|
937
|
+
static SHARE = 4;
|
|
938
|
+
static DELETE = 8;
|
|
939
|
+
static CREATE = 16;
|
|
940
|
+
static include(t, e) {
|
|
941
|
+
return (t & e) === e;
|
|
942
|
+
}
|
|
943
|
+
static add(t, e) {
|
|
944
|
+
return t | e;
|
|
945
|
+
}
|
|
946
|
+
static remove(t, e) {
|
|
947
|
+
return t & ~e;
|
|
948
|
+
}
|
|
949
|
+
static toggle(t, e) {
|
|
950
|
+
return t ^ e;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
class Z {
|
|
954
|
+
static longestCommonPrefix(t) {
|
|
955
|
+
if (!t.length) return "";
|
|
956
|
+
let e = t[0];
|
|
957
|
+
for (let s = 1; s < t.length; s++)
|
|
958
|
+
for (; !t[s].startsWith(e); )
|
|
959
|
+
if (e = e.slice(0, -1), e === "") return "";
|
|
960
|
+
return e;
|
|
961
|
+
}
|
|
962
|
+
static uuid(t) {
|
|
963
|
+
return typeof t == "number" ? (t ^ Math.random() * 16 >> t / 4).toString(16) : (9987e3 + -1e11).toString().replace(/[018]/g, (e) => {
|
|
964
|
+
const s = parseInt(e, 10);
|
|
965
|
+
return this.uuid(s);
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
class J {
|
|
970
|
+
static isValidHex(t) {
|
|
971
|
+
return /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t);
|
|
972
|
+
}
|
|
973
|
+
static isValidRGB(t) {
|
|
974
|
+
return /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.test(t);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
function Y(r) {
|
|
818
978
|
let t;
|
|
819
979
|
const e = new Proxy(r, {
|
|
820
980
|
construct(s, i, n) {
|
|
@@ -839,7 +999,7 @@ const x = {
|
|
|
839
999
|
UI_HIDE_LOADING: "隐藏加载事件",
|
|
840
1000
|
UI_SHOW_MESSAGE: "显示消息事件"
|
|
841
1001
|
};
|
|
842
|
-
class
|
|
1002
|
+
class I {
|
|
843
1003
|
static instance = null;
|
|
844
1004
|
listeners = {};
|
|
845
1005
|
debugMode;
|
|
@@ -852,7 +1012,7 @@ class v {
|
|
|
852
1012
|
}
|
|
853
1013
|
// 单例模式
|
|
854
1014
|
static getInstance(t) {
|
|
855
|
-
return
|
|
1015
|
+
return I.instance || (I.instance = new I(t)), I.instance;
|
|
856
1016
|
}
|
|
857
1017
|
/**
|
|
858
1018
|
* 添加事件监听器
|
|
@@ -959,12 +1119,12 @@ const b = {
|
|
|
959
1119
|
]),
|
|
960
1120
|
allowedAttributes: /* @__PURE__ */ new Set(["class", "id", "href", "src", "alt", "title"])
|
|
961
1121
|
};
|
|
962
|
-
class
|
|
1122
|
+
class v {
|
|
963
1123
|
static instance;
|
|
964
1124
|
constructor() {
|
|
965
1125
|
}
|
|
966
1126
|
static getInstance() {
|
|
967
|
-
return
|
|
1127
|
+
return v.instance || (v.instance = new v()), v.instance;
|
|
968
1128
|
}
|
|
969
1129
|
/**
|
|
970
1130
|
* 创建DOM元素
|
|
@@ -1052,7 +1212,7 @@ class I {
|
|
|
1052
1212
|
return t.replace(b.scriptRegex, "").replace(b.javascriptRegex, "").replace(b.eventHandlerRegex, "");
|
|
1053
1213
|
}
|
|
1054
1214
|
}
|
|
1055
|
-
class
|
|
1215
|
+
class tt {
|
|
1056
1216
|
features;
|
|
1057
1217
|
constructor() {
|
|
1058
1218
|
this.features = this.detectFeatures();
|
|
@@ -1085,12 +1245,12 @@ class K {
|
|
|
1085
1245
|
timstamp: n.timestamp
|
|
1086
1246
|
}),
|
|
1087
1247
|
(n) => {
|
|
1088
|
-
const
|
|
1248
|
+
const a = {
|
|
1089
1249
|
1: "User denied the request for Geolocation.",
|
|
1090
1250
|
2: "Position information is unavailable.",
|
|
1091
1251
|
3: "The request to get user location timed out."
|
|
1092
1252
|
};
|
|
1093
|
-
i(new Error(
|
|
1253
|
+
i(new Error(a[n.code] || "Unknown error"));
|
|
1094
1254
|
},
|
|
1095
1255
|
{ ...e, ...t }
|
|
1096
1256
|
);
|
|
@@ -1199,35 +1359,39 @@ Object.defineProperties(Element.prototype, {
|
|
|
1199
1359
|
});
|
|
1200
1360
|
Text.prototype.surround = function(r = "strong", t = "") {
|
|
1201
1361
|
if (!this.nodeValue || !r || !t) return null;
|
|
1202
|
-
const s = r.split("."), i = s[0], n = s.slice(1).join(" "),
|
|
1203
|
-
if (
|
|
1362
|
+
const s = r.split("."), i = s[0], n = s.slice(1).join(" "), a = this.textContent.indexOf(t);
|
|
1363
|
+
if (a < 0) return null;
|
|
1204
1364
|
const h = document.createRange();
|
|
1205
|
-
h.setStart(this,
|
|
1365
|
+
h.setStart(this, a), h.setEnd(this, a + t.length);
|
|
1206
1366
|
const u = document.createElement(i);
|
|
1207
1367
|
return n && (u.className = n), h.surroundContents(u), u;
|
|
1208
1368
|
};
|
|
1209
1369
|
export {
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1370
|
+
K as BitPerm,
|
|
1371
|
+
J as Color,
|
|
1372
|
+
z as Dictionary,
|
|
1373
|
+
v as DomHelper,
|
|
1374
|
+
I as Emitter,
|
|
1213
1375
|
W as Graph,
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1376
|
+
G as LIS,
|
|
1377
|
+
D as LRU,
|
|
1378
|
+
m as Line,
|
|
1217
1379
|
H as LinkedList,
|
|
1218
1380
|
E as Matrix,
|
|
1219
1381
|
q as MaxHeap,
|
|
1220
|
-
|
|
1221
|
-
|
|
1382
|
+
B as MemoizeMap,
|
|
1383
|
+
O as MinHeap,
|
|
1222
1384
|
$ as MinStack,
|
|
1223
|
-
|
|
1224
|
-
|
|
1385
|
+
Q as Num,
|
|
1386
|
+
c as Point,
|
|
1387
|
+
j as Queue,
|
|
1225
1388
|
X as Roman,
|
|
1226
1389
|
U as Stack,
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1390
|
+
Z as Str,
|
|
1391
|
+
p as Triangle,
|
|
1392
|
+
w as Vector,
|
|
1393
|
+
tt as WebAppManager,
|
|
1230
1394
|
F as isValidBracket,
|
|
1231
|
-
|
|
1395
|
+
Y as singleton,
|
|
1232
1396
|
T as sleep
|
|
1233
1397
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
`;return t}}class d{_data;static zero(t){return new d(...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 d(...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 d(...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 d(...e)}mul(t){return new d(...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 d(...this._matrix[t])}colVector(t){return new d(...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,e=p.EPSILON){const s=t.p2.x-t.p1.x,i=t.p2.y-t.p1.y;return Math.abs(s)<e?Math.abs(i)<e?0:null:i/s}static isParallel(t,e,s=p.EPSILON){const i=p.sloped(t),n=p.sloped(e);return i===null&&n===null?!0:i===null||n===null?!1:Math.abs(i-n)<s}static getIntersection(t,e,s=p.EPSILON){if(p.isParallel(t,e))return null;const i=t.p1.x,n=t.p1.y,o=t.p2.x,u=t.p2.y,l=e.p1.x,f=e.p1.y,g=e.p2.x,E=e.p2.y,m=(i-o)*(f-E)-(n-u)*(l-g);if(Math.abs(m)<s)return null;const I=((i-l)*(f-E)-(n-f)*(l-g))/m,L=-((i-o)*(n-f)-(n-u)*(i-l))/m;if(I>=0&&I<=1&&L>=0&&L<=1){const Q=i+I*(o-i),K=n+I*(u-n);return new h(Q,K)}return null}static isIntersecting(t,e){return p.getIntersection(t,e)!==null}static distanceToPoint(t,e,s=p.EPSILON){const i=e.x-t.p1.x,n=e.y-t.p1.y,o=t.p2.x-t.p1.x,u=t.p2.y-t.p1.y,l=i*o+n*u,f=o*o+u*u;let g=-1;f>s&&(g=l/f);let E,m;g<0?(E=t.p1.x,m=t.p1.y):g>1?(E=t.p2.x,m=t.p2.y):(E=t.p1.x+g*o,m=t.p1.y+g*u);const I=e.x-E,L=e.y-m;return Math.hypot(I+L)}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,e=p.EPSILON){const s=(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(s)>e?!1:(t.x-this.p1.x)*(t.x-this.p2.x)+(t.y-this.p1.y)*(t.y-this.p2.y)<=e}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)}get start(){return this.p1}get end(){return this.p2}}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((l,f)=>l-f),[n,o,u]=i;return Math.abs(n-o)<c.EPSILON&&Math.abs(o-u)<c.EPSILON?"equilateral":Math.abs(n-o)<c.EPSILON||Math.abs(o-u)<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 k(r){return r!==null&&(typeof r=="object"||typeof r=="function")}class T{map=new Map;weakMap=new WeakMap;set(t,e){k(t)?this.weakMap.set(t,e):this.map.set(t,e)}get(t){return k(t)?this.weakMap.get(t):this.map.get(t)}has(t){return k(t)?this.weakMap.has(t):this.map.has(t)}}function G(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 F{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 u=t[i],l=this.ROMAN_MAP.get(u);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 B(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 x={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 b{static instance=null;listeners={};debugMode;constructor(t=!1){this.debugMode=t,Object.keys(x).forEach(e=>{this.listeners[e]=new Set})}static getInstance(t){return b.instance||(b.instance=new b(t)),b.instance}on(t,e){this.debugLog(`添加事件监听: ${x[t]}`),this.listeners[t].add(e)}emit(t,e){this.debugLog(`触发事件: ${x[t]}`,e),this.listeners[t].forEach(s=>{try{s(e)}catch(i){console.error(`事件 ${x[t]} 处理出错:`,i)}})}off(t,e){this.debugLog(`移除事件监听: ${x[t]}`),this.listeners[t].delete(e)}once(t,e){this.debugLog(`添加一次性事件监听: ${x[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 v{static instance;constructor(){}static getInstance(){return v.instance||(v.instance=new v),v.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 X{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 u=document.createRange();u.setStart(this,o),u.setEnd(this,o+t.length);const l=document.createElement(i);return n&&(l.className=n),u.surroundContents(l),l},a.Dictionary=O,a.DomHelper=v,a.Emitter=b,a.Graph=H,a.LIS=G,a.LRU=D,a.Line=p,a.LinkedList=$,a.Matrix=w,a.MaxHeap=V,a.MemoizeMap=T,a.MinHeap=C,a.MinStack=j,a.Point=h,a.Queue=S,a.Roman=F,a.Stack=z,a.Triangle=c,a.Vector=d,a.WebAppManager=X,a.isValidBracket=W,a.singleton=B,a.sleep=_,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(o,S){typeof exports=="object"&&typeof module<"u"?S(exports):typeof define=="function"&&define.amd?define(["exports"],S):(o=typeof globalThis<"u"?globalThis:o||self,S(o["jc-structure"]={}))})(this,(function(o){"use strict";class S{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){if(t.length===0)return this;const e=t.length===1&&Array.isArray(t[0])?t[0]:t;return this.batchEnqueue(e),this}batchEnqueue(t){t.forEach(e=>{this.isValidItem(e)&&(this.items[this.count]=e,this.count++)})}isValidItem(t){return t!=null}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 V{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){return t==null||t==null?this:Array.isArray(t)?this.addItems(t):this.addItem(t)}addItem(t){if(!this.isValidItem(t))throw new Error("Invalid item: item cannot be null or undefined");return this.items[this.count]=t,this.count++,this}addItems(t){return t.filter(i=>this.isValidItem(i)).forEach(i=>{this.items[this.count]=i,this.count++}),this}isValidItem(t){return t!=null}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]`}}class z{stack=[];minStack=[];push(t){this.stack.push(t),(this.minStack.length===0||t<=this.minStack[this.minStack.length-1])&&this.minStack.push(t)}pop(){const t=this.stack.pop();return t===this.minStack[this.minStack.length-1]&&this.minStack.pop(),t}peek(){return this.stack[this.stack.length-1]}getMin(){return this.minStack[this.minStack.length-1]}isEmpty(){return this.size()===0}size(){return this.stack.length}clear(){this.stack=[],this.minStack=[]}toString(){return this.isEmpty()?"":`MinStack(count: ${this.size()}):[${this.getMin()},...rest]`}}function k(r,t){return r===t?0:r<t?-1:1}class E{heap=[];compareFn;constructor(t=k){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,i){[t[e],t[i]]=[t[i],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 N extends E{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,i=E.getLeftIndex(e),s=E.getRightIndex(e),n=this.size();i<n&&this.compareFn(this.heap[e],this.heap[i])===-1&&(e=i),s<n&&this.compareFn(this.heap[e],this.heap[s])===1&&(e=s),e!==t&&(E.swap(this.heap,t,e),this.siftUp(e))}siftDown(t){let e=E.getParentIndex(t);for(;t>0&&e&&this.compareFn(this.heap[e],this.heap[t])===1;)E.swap(this.heap,e,t),t=e,e=E.getParentIndex(t)}}class j extends N{constructor(t=(e,i)=>k(i,e)){super(t)}}function U(r){return{value:r}}class D{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 i=this.lookup.get(t);i?(this.detach(i),this.prepend(i),i.value=e):(i=U(e),this.length++,this.prepend(i),this.trimCache(),this.lookup.set(t,i),this.reverseLookup)}}let L=class{value;next=void 0};class ${count=0;head=void 0;constructor(){}indexOf(t){let e=this.head,i=0,s=!1;for(;e;){if(this.equals(e.value,t)){s=!0;break}i++,e=e.next}return s?i:-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 i=0;i<t;i++)e=e?.next;return e}getValueAt(t){return this.getElementAt(t)?.value}insert(t,e){let i=new L;if(i.value=t,e>this.count||e<0)throw new Error("index error");this.count++;let s,n;if(e===0){i.next=this.head,this.head=i;return}s=this.getElementAt(e-1),n=s.next,s.next=i,i.next=n}push(t){let e=new L;if(e.value=t,this.count++,this.isEmpty()){this.head=e;return}let i=this.getElementAt(this.count-1);i.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),i=this.getElementAt(t-1),s=e?.next;return t===0&&(this.head=s),i&&(i.next=s),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 q{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 O{table=[];constructor(){}getItemIndex(t){for(let e=0,i=this.table.length;e<i;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 i=this.getItemIndex(t);this.table[i].value=e}else{const i=new q(t,e);this.table.push(i)}}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,i=this.size();e<i;e++){let s=this.table[e];if(!t(s.key,s.value))break}}isEmpty(){return!this.size()}size(){return this.table.length}clear(){this.table=[]}toString(){let t="";for(let e=0,i=this.table.length;e<i;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 O}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 y{_data;static zero(t){return new y(...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(i=>i/t);return new y(...e)}add(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to add");const e=this._data.map((i,s)=>i+t._data[s]);return new y(...e)}sub(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to subtract");const e=this._data.map((i,s)=>i-t._data[s]);return new y(...e)}mul(t){return new y(...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,i,s)=>e+i*t._data[s],0)}pos(){return this.mul(1)}neg(){return this.mul(-1)}}class x{_matrix;static zero(t,e){return new x(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 y(...this._matrix[t])}colVector(t){return new y(...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 x(this._matrix.map(e=>e.map(i=>i*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 x(this._matrix.map((e,i)=>e.map((s,n)=>s+t.getItem([i,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 x(this._matrix.map(e=>e.map((i,s)=>i*t.getItem(s))))}mulMatrix(t){if(this.col!==t.row)throw new Error("Matrix dimensions do not match");const e=x.zero(this.row,t.col);for(let i=0;i<this.row;i++){const s=this.rowVector(i);for(let n=0;n<this.col;n++)e.setItem([i,n],s.dot(t.colVector(n)))}return e}}class c{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 c.distance(this,t)}}class f{static EPSILON=1e-10;static sloped(t,e=f.EPSILON){const i=t.p2.x-t.p1.x,s=t.p2.y-t.p1.y;return Math.abs(i)<e?Math.abs(s)<e?0:null:s/i}static isParallel(t,e,i=f.EPSILON){const s=f.sloped(t),n=f.sloped(e);return s===null&&n===null?!0:s===null||n===null?!1:Math.abs(s-n)<i}static getIntersection(t,e,i=f.EPSILON){if(f.isParallel(t,e))return null;const s=t.p1.x,n=t.p1.y,a=t.p2.x,u=t.p2.y,l=e.p1.x,m=e.p1.y,w=e.p2.x,h=e.p2.y,d=(s-a)*(m-h)-(n-u)*(l-w);if(Math.abs(d)<i)return null;const g=((s-l)*(m-h)-(n-m)*(l-w))/d,A=-((s-a)*(n-m)-(n-u)*(s-l))/d;if(g>=0&&g<=1&&A>=0&&A<=1){const Y=s+g*(a-s),tt=n+g*(u-n);return new c(Y,tt)}return null}static isIntersecting(t,e){return f.getIntersection(t,e)!==null}static distanceToPoint(t,e,i=f.EPSILON){const s=e.x-t.p1.x,n=e.y-t.p1.y,a=t.p2.x-t.p1.x,u=t.p2.y-t.p1.y,l=s*a+n*u,m=a*a+u*u;let w=-1;m>i&&(w=l/m);let h,d;w<0?(h=t.p1.x,d=t.p1.y):w>1?(h=t.p2.x,d=t.p2.y):(h=t.p1.x+w*a,d=t.p1.y+w*u);const g=e.x-h,A=e.y-d;return Math.hypot(g+A)}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 c(t,e)}get angle(){return Math.atan2(this.p2.y-this.p1.y,this.p2.x-this.p1.x)}containsPoint(t,e=f.EPSILON){const i=(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(i)>e?!1:(t.x-this.p1.x)*(t.x-this.p2.x)+(t.y-this.p1.y)*(t.y-this.p2.y)<=e}get direction(){const t=this.length;if(t<f.EPSILON)return new c(0,0);const e=(this.p2.x-this.p1.x)/t,i=(this.p2.y-this.p1.y)/t;return new c(e,i)}get start(){return this.p1}get end(){return this.p2}}class R{static EPSILON=1e-10;name;constructor(t){this.name=t}}class p extends R{static isValid(t,e,i){return t<=0||e<=0||i<=0?!1:t+e>i&&t+i>e&&e+i>t}static area(t,e,i){if(!p.isValid(t,e,i))throw new Error("Invalid triangle");const s=(t+e+i)/2;return Math.sqrt(s*(s-t)*(s-e)*(s-i))}static getType(t,e,i){if(!p.isValid(t,e,i))throw new Error("Invalid triangle sides");const s=[t,e,i].sort((l,m)=>l-m),[n,a,u]=s;return Math.abs(n-a)<p.EPSILON&&Math.abs(a-u)<p.EPSILON?"equilateral":Math.abs(n-a)<p.EPSILON||Math.abs(a-u)<p.EPSILON?"isosceles":"scalene"}static getAngles(t,e,i){if(!p.isValid(t,e,i))throw new Error("Invalid triangle sides");const s=Math.acos((e*e+i*i-t*t)/(2*e*i)),n=Math.acos((t*t+i*i-e*e)/(2*t*i)),a=Math.PI-s-n;return[s,n,a]}p1;p2;p3;constructor(t,e,i,s="triangle"){if(super(s),this.p1=t,this.p2=e,this.p3=i,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[c.distance(this.p1,this.p2),c.distance(this.p2,this.p3),c.distance(this.p3,this.p1)]}perimeter(){return p.isValid(this.side[0],this.side[1],this.side[2]),this.side.reduce((t,e)=>t+e,0)}area(){const[t,e,i]=this.side;return p.area(t,e,i)}get type(){const[t,e,i]=this.side;return p.getType(t,e,i)}get angles(){const[t,e,i]=this.side;return p.getAngles(t,e,i)}get centroid(){return new c((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,i]=this.side,s=this.perimeter()/2,n=(t*this.p1.x+e*this.p2.x+i*this.p3.x)/s,a=(t*this.p1.y+e*this.p2.y+i*this.p3.y)/s;return new c(n,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)<p.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,i=((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 c(e,i)}containsPoint(t){const e=p.area(c.distance(t,this.p1),c.distance(t,this.p2),c.distance(this.p1,this.p2)),i=p.area(c.distance(t,this.p2),c.distance(t,this.p3),c.distance(this.p2,this.p3)),s=p.area(c.distance(t,this.p3),c.distance(t,this.p1),c.distance(this.p3,this.p1));return Math.abs(e+i+s-this.area())<p.EPSILON}}function T(r){return new Promise(t=>setTimeout(t,r))}function _(r){const t=[],e={"(":")","[":"]","{":"}"},i=new Set(Object.values(e));for(const s of r)if(s in e)t.push(e[s]);else if(i.has(s)&&s!==t.pop())return!1;return t.length===0}function P(r){return r!==null&&(typeof r=="object"||typeof r=="function")}class W{map=new Map;weakMap=new WeakMap;set(t,e){P(t)?this.weakMap.set(t,e):this.map.set(t,e)}get(t){return P(t)?this.weakMap.get(t):this.map.get(t)}has(t){return P(t)?this.weakMap.has(t):this.map.has(t)}}function F(r){if(!r.length)return[];const t=[[r[0]]];for(let i=1,s=r.length;i<s;i++){const n=r[i];e(n)}function e(i){for(let s=t.length-1;s>=0;s--){const n=t[s],a=n[t[s].length-1];if(a<i){t[s+1]=[...n,i];break}else a>i&&s===0&&(t[s]=[i])}}return t[t.length-1]}class B{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 i=0,s=0;for(;s<t.length;){const a=t.slice(s,s+2);if(this.ROMAN_MAP.has(a))i+=this.ROMAN_MAP.get(a),s+=2;else{const u=t[s],l=this.ROMAN_MAP.get(u);if(!l)throw new Error(`Invalid Roman numeral sequence at position ${s}`);i+=l,s+=1}}if(this.toRoman(i)!==t)throw new Error("Invalid Roman numeral sequence");return i}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[i,s]of this.ROMAN_MAP)for(;t>=s;)e+=i,t-=s;return e}}class G{static isValidPositiveInteger(t){return Number.isInteger(t)&&t>0&&t<=Number.MAX_SAFE_INTEGER}static isPowerOfTwo(t){return t>0&&(t&t-1)===0}static isOdd(t){return t%2===1||t%2===-1}static factorial(t){if(!this.isValidPositiveInteger(t))throw new Error("Input must be a non-negative integer");if(t<2)return 1;let e=1;for(let i=2;i<=t;i++)e*=i;return e}static fibonacci(t,e=1,i=1){if(!this.isValidPositiveInteger(t))throw new Error("Input must be a non-negative integer");return t<2?i:this.fibonacci(t-1,i,i+e)}static fibonacciIterative(t){if(!this.isValidPositiveInteger(t))throw new Error("Input must be a non-negative integer");let e=1,i=1;for(let s=2;s<t;s++)[e,i]=[i,e+i];return t===0?0:i}static getPercentWithPrecision(t,e=2){if(!Array.isArray(t)||t.length===0)return[];if(e<0||!Number.isInteger(e))throw new Error("Precision must be a non-negative integer");const i=t.reduce((h,d)=>h+d,0);if(i===0)return t.map(()=>"0%");const n=100*Math.pow(10,e),a=t.map(h=>h/i*n),u=a.map(h=>Math.floor(h)),l=a.map((h,d)=>h-u[d]);let m=u.reduce((h,d)=>h+d,0),w=n-m;for(;w>0;){let h=-1,d=-1;for(let g=0;g<l.length;g++)l[g]>d&&(d=l[g],h=g);if(h===-1)break;u[h]++,l[h]=0,w--}return u.map(h=>`${(h/n*100).toFixed(e)}%`)}static fastSqrt(t){if(t<0)throw new Error("n must be a non-negative number");const e=.5*t;let i=new BigInt64Array(new Float32Array([t]).buffer)[0];i=0x1ff7a3bea91d9b1bn+(i>>1n);let s=new Float64Array(new BigInt64Array([i]).buffer)[0];return s=s*.5+e/s,s=s*.5+e/s,s=s*.5+e/s,s}static middle(t,e){return e-(e-t>>1)}static gcd(t,e){return e===0?t:this.gcd(e,t%e)}static lcm(t,e){return t*e/this.gcd(t,e)}static isPrime(t){if(t<=1)return!1;for(let e=2;e<=Math.sqrt(t);e++)if(t%e===0)return!1;return!0}static isPalindrome(t){if(t<0||t%10===0&&t!==0)return!1;let e=0,i=t;for(;t>0;){const s=t%10;e=e*10+s,t=Math.floor(t/10)}return i===e}static isArmstrong(t){const e=t.toString(),i=e.length;let s=0;for(let n=0;n<i;n++)s+=Math.pow(parseInt(e[n]),i);return s===t}static isPerfect(t){let e=0;for(let i=1;i<t;i++)t%i===0&&(e+=i);return e===t}static scale(t,e,i){if(e[0]>=e[1]||i[0]>=i[1])throw new Error("Invalid range");const s=e[1]-e[0];return(t-e[0])*((i[1]-i[0])/s)+i[0]}static randomInt(t,e){return Math.floor(Math.random()*(e-t+1))+t}static floatEqual(t,e,i=1e-6){return Math.abs(t-e)<i}static isSameSign(t,e){return t>=0&&e>=0||t<=0&&e<=0}}class X{static READ=1;static WRITE=2;static SHARE=4;static DELETE=8;static CREATE=16;static include(t,e){return(t&e)===e}static add(t,e){return t|e}static remove(t,e){return t&~e}static toggle(t,e){return t^e}}class Q{static longestCommonPrefix(t){if(!t.length)return"";let e=t[0];for(let i=1;i<t.length;i++)for(;!t[i].startsWith(e);)if(e=e.slice(0,-1),e==="")return"";return e}static uuid(t){return typeof t=="number"?(t^Math.random()*16>>t/4).toString(16):(9987e3+-1e11).toString().replace(/[018]/g,e=>{const i=parseInt(e,10);return this.uuid(i)})}}class K{static isValidHex(t){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t)}static isValidRGB(t){return/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.test(t)}}function Z(r){let t;const e=new Proxy(r,{construct(i,s,n){return t||(t=Reflect.construct(i,s,n)),t}});return r.prototype.constructor=e,e}const b={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 I{static instance=null;listeners={};debugMode;constructor(t=!1){this.debugMode=t,Object.keys(b).forEach(e=>{this.listeners[e]=new Set})}static getInstance(t){return I.instance||(I.instance=new I(t)),I.instance}on(t,e){this.debugLog(`添加事件监听: ${b[t]}`),this.listeners[t].add(e)}emit(t,e){this.debugLog(`触发事件: ${b[t]}`,e),this.listeners[t].forEach(i=>{try{i(e)}catch(s){console.error(`事件 ${b[t]} 处理出错:`,s)}})}off(t,e){this.debugLog(`移除事件监听: ${b[t]}`),this.listeners[t].delete(e)}once(t,e){this.debugLog(`添加一次性事件监听: ${b[t]}`);const i=s=>{e(s),this.off(t,i)};this.on(t,i)}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 v{static instance;constructor(){}static getInstance(){return v.instance||(v.instance=new v),v.instance}createElement(t,e={},i=""){if(!M.allowedTags.has(t.toLowerCase()))throw new Error(`Unsupported tag: ${t}`);const s=document.createElement(t);return this._processAttributes(s,e),this._processContent(s,i),s}createBatch(t,e){const i=document.createDocumentFragment();t.forEach(s=>{const n=this.createElement(s.tag,s.attributes||{},s.content||"");i.appendChild(n)}),e.appendChild(i)}setHtml(t,e){const i=this._sanitizeHtml(e);t.innerHTML=i}_processAttributes(t,e){Object.entries(e).forEach(([i,s])=>{if(!M.allowedAttributes.has(i)&&!i.startsWith("data-")){console.warn(`Potentially unsafe attribute: ${i}`);return}if(typeof s=="function")i.startsWith("on")&&t.addEventListener(i.slice(2).toLowerCase(),s);else switch(i){case"className":t.className=s;break;case"dataset":Object.assign(t.dataset,s);break;case"style":Object.assign(t.style,s);break;default:t.setAttribute(i,s)}})}_processContent(t,e){typeof e=="string"?t.textContent=e:e instanceof Node?t.appendChild(e):Array.isArray(e)&&e.forEach(i=>{typeof i=="string"?t.appendChild(document.createTextNode(i)):t.appendChild(i)})}_sanitizeHtml(t){return t.replace(M.scriptRegex,"").replace(M.javascriptRegex,"").replace(M.eventHandlerRegex,"")}}class J{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((i,s)=>{navigator.geolocation.getCurrentPosition(n=>i({latitude:n.coords.latitude,longitude:n.coords.longitude,accuracy:n.coords.accuracy,timstamp:n.timestamp}),n=>{const a={1:"User denied the request for Geolocation.",2:"Position information is unavailable.",3:"The request to get user location timed out."};s(new Error(a[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 i=this.codePointAt(t);t+=i>65535?2:1,r++}return r},String.prototype.pointAt=function(r){if(r>=this.pointLength())return;let t=0;for(let e=0,i=this.length;e<i;){const s=this.codePointAt(e);if(!s)return;if(t===r)return String.fromCodePoint(s);e+=s>65535?2:1,t++}},String.prototype.sliceByPoint=function(r,t=this.pointLength()){let e="";for(let i=r;i<t;i++)e+=this.pointAt(i);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 i=e.closest(r);if(!i)break;t=i,e=i.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 i=r.split("."),s=i[0],n=i.slice(1).join(" "),a=this.textContent.indexOf(t);if(a<0)return null;const u=document.createRange();u.setStart(this,a),u.setEnd(this,a+t.length);const l=document.createElement(s);return n&&(l.className=n),u.surroundContents(l),l},o.BitPerm=X,o.Color=K,o.Dictionary=O,o.DomHelper=v,o.Emitter=I,o.Graph=H,o.LIS=F,o.LRU=D,o.Line=f,o.LinkedList=$,o.Matrix=x,o.MaxHeap=j,o.MemoizeMap=W,o.MinHeap=N,o.MinStack=z,o.Num=G,o.Point=c,o.Queue=S,o.Roman=B,o.Stack=V,o.Str=Q,o.Triangle=p,o.Vector=y,o.WebAppManager=J,o.isValidBracket=_,o.singleton=Z,o.sleep=T,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
|
package/index.d.ts
CHANGED
|
@@ -324,23 +324,6 @@ declare module "jc-structure" {
|
|
|
324
324
|
has(key: unknown): boolean;
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
-
/**
|
|
328
|
-
* 罗马数字类
|
|
329
|
-
*/
|
|
330
|
-
interface RomanConstructor {
|
|
331
|
-
/**
|
|
332
|
-
* #### 转阿拉伯数字
|
|
333
|
-
* @param str 罗马数字文本
|
|
334
|
-
*/
|
|
335
|
-
toInteger(str: string): number;
|
|
336
|
-
/**
|
|
337
|
-
* #### 转罗马数字
|
|
338
|
-
* @param num 阿拉伯整数
|
|
339
|
-
*/
|
|
340
|
-
toRoman(num: number): string;
|
|
341
|
-
}
|
|
342
|
-
declare var Roman: RomanConstructor;
|
|
343
|
-
|
|
344
327
|
interface Point {
|
|
345
328
|
/**
|
|
346
329
|
* #### 点x坐标
|
|
@@ -443,67 +426,14 @@ declare module "jc-structure" {
|
|
|
443
426
|
}
|
|
444
427
|
declare var Line: LineConstructor;
|
|
445
428
|
|
|
446
|
-
/**
|
|
447
|
-
* ### 三角形类
|
|
448
|
-
*/
|
|
449
|
-
// export class Triangle {
|
|
450
|
-
// /**
|
|
451
|
-
// * #### 判断三条边是否能构成三角形
|
|
452
|
-
// * @param a 边长
|
|
453
|
-
// * @param b 边长
|
|
454
|
-
// * @param c 边长
|
|
455
|
-
// */
|
|
456
|
-
// static isValid(a: number, b: number, c: number): boolean;
|
|
457
|
-
// /**
|
|
458
|
-
// * #### 计算三角形的面积,采用秦九昭公式或叫海伦面积公式
|
|
459
|
-
// * @param a 边长
|
|
460
|
-
// * @param b 边长
|
|
461
|
-
// * @param c 边长
|
|
462
|
-
// */
|
|
463
|
-
// static area(a: number, b: number, c: number): number;
|
|
464
|
-
// /**
|
|
465
|
-
// * #### 获取三角形的角度
|
|
466
|
-
// * @param a 边长
|
|
467
|
-
// * @param b 边长
|
|
468
|
-
// * @param c 边长
|
|
469
|
-
// */
|
|
470
|
-
// static getAngles(a: number, b: number, c: number): [number, number, number];
|
|
471
|
-
// constructor(p1: Point, p2: Point, p3: Point): Triangle;
|
|
472
|
-
// /**
|
|
473
|
-
// * #### 获取三角形的边长
|
|
474
|
-
// */
|
|
475
|
-
// get side(): [number, number, number];
|
|
476
|
-
// /**
|
|
477
|
-
// * #### 获取三角形的内心点
|
|
478
|
-
// */
|
|
479
|
-
// get centroid(): Point;
|
|
480
|
-
// /**
|
|
481
|
-
// * #### 获取三角形的外切园心点
|
|
482
|
-
// */
|
|
483
|
-
// get circumcenter(): Point;
|
|
484
|
-
// /**
|
|
485
|
-
// * #### 获取三角形的内切园心点
|
|
486
|
-
// */
|
|
487
|
-
// get incenter(): Point;
|
|
488
|
-
// /**
|
|
489
|
-
// * #### 获取三角形的周长
|
|
490
|
-
// */
|
|
491
|
-
// perimeter(): number;
|
|
492
|
-
// /**
|
|
493
|
-
// * #### 获取三角形的面积
|
|
494
|
-
// */
|
|
495
|
-
// area(): number;
|
|
496
|
-
// /**
|
|
497
|
-
// * #### 判断点是否在三角形内
|
|
498
|
-
// * @param point
|
|
499
|
-
// */
|
|
500
|
-
// containsPoint(point: Point): boolean;
|
|
501
|
-
// }
|
|
502
429
|
enum TriangleType {
|
|
503
430
|
Equilateral = "equilateral", // 等边
|
|
504
431
|
Isosceles = "isosceles", // 等腰
|
|
505
432
|
Scalene = "scalene", // 不等边
|
|
506
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* ### 三角形类
|
|
436
|
+
*/
|
|
507
437
|
interface Triangle {
|
|
508
438
|
readonly p1: Point;
|
|
509
439
|
readonly p2: Point;
|
|
@@ -567,6 +497,7 @@ declare module "jc-structure" {
|
|
|
567
497
|
getTYpe(a: number, b: number, c: number): TriangleType;
|
|
568
498
|
}
|
|
569
499
|
declare var Triangle: TriangleConstructor;
|
|
500
|
+
|
|
570
501
|
/**
|
|
571
502
|
* ### 向量类
|
|
572
503
|
*/
|
|
@@ -660,4 +591,203 @@ declare module "jc-structure" {
|
|
|
660
591
|
* @param str 含括号的字符串
|
|
661
592
|
*/
|
|
662
593
|
export function isValidBracket(str: string): boolean;
|
|
594
|
+
|
|
595
|
+
interface NumConstructor {
|
|
596
|
+
new (value?: any): Number;
|
|
597
|
+
readonly prototype: Number;
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* #### 判断是否是有效的正整数
|
|
601
|
+
* @param n A numeric value
|
|
602
|
+
*/
|
|
603
|
+
isValidPositiveInteger(n: number): boolean;
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* #### 判断是否是2的幂
|
|
607
|
+
* @param n A numeric value
|
|
608
|
+
*/
|
|
609
|
+
isPowerOfTwo(n: number): boolean;
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* #### 判断是否是奇数
|
|
613
|
+
* @param n A numeric value
|
|
614
|
+
*/
|
|
615
|
+
isOdd(n: number): boolean;
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* #### 正整数阶乘
|
|
619
|
+
* @param n A numeric value
|
|
620
|
+
*/
|
|
621
|
+
factorial(n: number): number;
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* #### 计算斐波那契数
|
|
625
|
+
* - 采用尾递归的方法,避免递归深度过深导致的栈溢出问题
|
|
626
|
+
* @param n A positive integer
|
|
627
|
+
* @param start 起始值,默认为1
|
|
628
|
+
* @param total 总数,默认为1
|
|
629
|
+
*/
|
|
630
|
+
fibonacci(n: number, start?: number, total?: number): number;
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* #### 计算斐波那契数
|
|
634
|
+
* - 采用滑动数组的方法,避免递归深度过深导致的栈溢出问题
|
|
635
|
+
* @param n A positive integer
|
|
636
|
+
*/
|
|
637
|
+
fibonacciIterative(n: number): number;
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* #### 获取百分比字符串数组
|
|
641
|
+
* - 使用了"最大余数法"(也称为"汉密尔顿方法")来分配百分比
|
|
642
|
+
* - 这种方法可以确保所有百分比加起来正好等于100%,避免由于四舍五入造成的误差
|
|
643
|
+
* @param valueList 数值数组
|
|
644
|
+
* @param precision 精度位数,默认2位小数
|
|
645
|
+
* @returns 格式化的百分比字符串数组
|
|
646
|
+
*/
|
|
647
|
+
getPercentWithPrecision(valueList: number[], precision?: number): string[];
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* #### 史上最快开方算法
|
|
651
|
+
* @param n A non-negative number
|
|
652
|
+
*/
|
|
653
|
+
fastSqrt(n: number): number;
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* #### 获取中位数
|
|
657
|
+
* @param n A numeric value
|
|
658
|
+
*/
|
|
659
|
+
middle(n: number): number;
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* #### 获取最大公约数
|
|
663
|
+
* @param a
|
|
664
|
+
* @param b
|
|
665
|
+
*/
|
|
666
|
+
gcd(a: number, b: number): number;
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* #### 获取最小公倍数
|
|
670
|
+
* @param a
|
|
671
|
+
* @param b
|
|
672
|
+
*/
|
|
673
|
+
lcm(a: number, b: number): number;
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* #### 是否是素数
|
|
677
|
+
* @param n
|
|
678
|
+
*/
|
|
679
|
+
isPrime(n: number): boolean;
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* #### 是否是回文数
|
|
683
|
+
* @param n
|
|
684
|
+
*/
|
|
685
|
+
isPalindrome(n: number): boolean;
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* #### 是否是阿姆斯特朗数
|
|
689
|
+
* @param n
|
|
690
|
+
*/
|
|
691
|
+
isArmstrong(n: number): boolean;
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* #### 是否是完美数
|
|
695
|
+
* @param n
|
|
696
|
+
*/
|
|
697
|
+
isPerfect(n: number): boolean;
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* #### 线性比例缩放取值
|
|
701
|
+
* @param n
|
|
702
|
+
* @param original 原范围
|
|
703
|
+
* @param target 现范围
|
|
704
|
+
*/
|
|
705
|
+
scale(
|
|
706
|
+
n: number,
|
|
707
|
+
original: [number, number],
|
|
708
|
+
target: [number, number]
|
|
709
|
+
): number;
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* #### 获取随机整数,包含min和max
|
|
713
|
+
* @param min 最小数
|
|
714
|
+
* @param max 最大数
|
|
715
|
+
*/
|
|
716
|
+
randomInt(min: number, max: number): number;
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* #### 大约相等
|
|
720
|
+
* @param a
|
|
721
|
+
* @param b
|
|
722
|
+
* @param epsilon 默认为0.000001
|
|
723
|
+
*/
|
|
724
|
+
floatEqual(a: number, b: number, epsilon?: number): boolean;
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* #### 判断两个数是否同号
|
|
728
|
+
* @param a
|
|
729
|
+
* @param b
|
|
730
|
+
*/
|
|
731
|
+
isSameSign(a: number, b: number): boolean;
|
|
732
|
+
}
|
|
733
|
+
declare var Num: NumConstructor;
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* 罗马数字类
|
|
737
|
+
*/
|
|
738
|
+
interface RomanConstructor {
|
|
739
|
+
/**
|
|
740
|
+
* #### 转阿拉伯数字
|
|
741
|
+
* @param str 罗马数字文本
|
|
742
|
+
*/
|
|
743
|
+
toInteger(str: string): number;
|
|
744
|
+
/**
|
|
745
|
+
* #### 转罗马数字
|
|
746
|
+
* @param num 阿拉伯整数
|
|
747
|
+
*/
|
|
748
|
+
toRoman(num: number): string;
|
|
749
|
+
}
|
|
750
|
+
declare var Roman: RomanConstructor;
|
|
751
|
+
|
|
752
|
+
interface BitPerConstructor {
|
|
753
|
+
readonly READ: number;
|
|
754
|
+
readonly WRITE: number;
|
|
755
|
+
readonly SHARE: number;
|
|
756
|
+
readonly DELETE: number;
|
|
757
|
+
readonly CREATE: number;
|
|
758
|
+
/**
|
|
759
|
+
* #### 判断权限是否包含
|
|
760
|
+
* @param permission
|
|
761
|
+
* @param target
|
|
762
|
+
*/
|
|
763
|
+
include(permission: number, target: number): boolean;
|
|
764
|
+
/**
|
|
765
|
+
* #### 添加权限
|
|
766
|
+
* @param permission
|
|
767
|
+
* @param target
|
|
768
|
+
*/
|
|
769
|
+
add(permission: number, target: number): number;
|
|
770
|
+
/**
|
|
771
|
+
* #### 移除权限
|
|
772
|
+
* @param permission
|
|
773
|
+
* @param target
|
|
774
|
+
*/
|
|
775
|
+
remove(permission: number, target: number): number;
|
|
776
|
+
/**
|
|
777
|
+
* #### 切换权限
|
|
778
|
+
* @param permission
|
|
779
|
+
* @param target
|
|
780
|
+
*/
|
|
781
|
+
toggle(permission: number, target: number): number;
|
|
782
|
+
}
|
|
783
|
+
declare var BitPer: BitPerConstructor;
|
|
784
|
+
|
|
785
|
+
interface StrConstructor {
|
|
786
|
+
new (value?: any): String;
|
|
787
|
+
readonly prototype: String;
|
|
788
|
+
|
|
789
|
+
longestCommonPrefix(strs: string[]): string;
|
|
790
|
+
uuid(a?: number | string): string;
|
|
791
|
+
}
|
|
792
|
+
declare var Str: StrConstructor;
|
|
663
793
|
}
|