@visactor/vutils 0.18.0-alpha.0 → 0.18.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/color/Color.d.ts +162 -1
- package/cjs/color/Color.js +216 -9
- package/cjs/color/Color.js.map +1 -1
- package/cjs/color/index.d.ts +1 -4
- package/cjs/color/index.js +9 -9
- package/cjs/color/index.js.map +1 -1
- package/cjs/color/interpolate.d.ts +1 -1
- package/cjs/color/interpolate.js +2 -2
- package/cjs/color/interpolate.js.map +1 -1
- package/cjs/common/ascending.js +1 -2
- package/cjs/common/debounce.js +2 -1
- package/cjs/common/isArrayLike.js +1 -2
- package/cjs/common/isNull.js +2 -1
- package/cjs/common/isShallowEqual.js +1 -2
- package/cjs/common/isString.js +1 -1
- package/cjs/common/isType.js +1 -1
- package/cjs/common/isUndefined.js +1 -1
- package/cjs/common/isValid.js +1 -1
- package/cjs/common/isValidNumber.js +1 -1
- package/cjs/common/isValidUrl.js +1 -1
- package/cjs/common/lowerFirst.js +1 -1
- package/cjs/data-structure/bounds.js +1 -1
- package/cjs/data-structure/hashTable.d.ts +35 -0
- package/cjs/data-structure/hashTable.js +115 -0
- package/cjs/data-structure/hashTable.js.map +1 -0
- package/cjs/data-structure/index.d.ts +1 -0
- package/cjs/data-structure/index.js +3 -3
- package/cjs/data-structure/index.js.map +1 -1
- package/cjs/data-structure/matrix.js +1 -1
- package/cjs/data-structure/point.d.ts +1 -1
- package/cjs/data-structure/point.js +6 -7
- package/cjs/data-structure/point.js.map +1 -1
- package/cjs/format/number/formatDecimal.d.ts +2 -0
- package/cjs/format/number/formatDecimal.js +18 -0
- package/cjs/format/number/formatDecimal.js.map +1 -0
- package/cjs/format/number/formatGroup.d.ts +1 -0
- package/cjs/format/number/formatGroup.js +17 -0
- package/cjs/format/number/formatGroup.js.map +1 -0
- package/cjs/format/number/formatPrefixAuto.d.ts +2 -0
- package/cjs/format/number/formatPrefixAuto.js +18 -0
- package/cjs/format/number/formatPrefixAuto.js.map +1 -0
- package/cjs/format/number/formatRounded.d.ts +1 -0
- package/cjs/format/number/formatRounded.js +17 -0
- package/cjs/format/number/formatRounded.js.map +1 -0
- package/cjs/format/number/formatTrim.d.ts +1 -0
- package/cjs/format/number/formatTrim.js +25 -0
- package/cjs/format/number/formatTrim.js.map +1 -0
- package/cjs/format/number/index.d.ts +2 -0
- package/cjs/format/number/index.js +21 -0
- package/cjs/format/number/index.js.map +1 -0
- package/cjs/format/number/number.d.ts +53 -0
- package/cjs/format/number/number.js +121 -0
- package/cjs/format/number/number.js.map +1 -0
- package/cjs/format/number/specifier.d.ts +28 -0
- package/cjs/format/number/specifier.js +41 -0
- package/cjs/format/number/specifier.js.map +1 -0
- package/cjs/format/time.d.ts +79 -0
- package/cjs/format/time.js +204 -0
- package/cjs/format/time.js.map +1 -0
- package/cjs/graphics/algorithm/index.d.ts +1 -0
- package/cjs/graphics/algorithm/index.js +2 -1
- package/cjs/graphics/algorithm/index.js.map +1 -1
- package/cjs/graphics/graph-util.d.ts +23 -0
- package/cjs/graphics/graph-util.js +47 -0
- package/cjs/graphics/graph-util.js.map +1 -0
- package/cjs/graphics/index.d.ts +1 -1
- package/cjs/graphics/index.js +2 -2
- package/cjs/graphics/index.js.map +1 -1
- package/cjs/graphics/text/measure/textMeasure.js +1 -1
- package/cjs/graphics/text/measure/textMeasure.js.map +1 -1
- package/cjs/index.d.ts +3 -0
- package/cjs/index.js +8 -6
- package/cjs/index.js.map +1 -1
- package/cjs/lru.d.ts +25 -0
- package/cjs/lru.js +45 -0
- package/cjs/lru.js.map +1 -0
- package/dist/index.js +1140 -139
- package/dist/index.min.js +1 -1
- package/es/color/Color.d.ts +162 -1
- package/es/color/Color.js +205 -8
- package/es/color/Color.js.map +1 -1
- package/es/color/index.d.ts +1 -4
- package/es/color/index.js +1 -7
- package/es/color/index.js.map +1 -1
- package/es/color/interpolate.d.ts +1 -1
- package/es/color/interpolate.js +1 -1
- package/es/color/interpolate.js.map +1 -1
- package/es/common/ascending.js +1 -2
- package/es/common/debounce.js +2 -1
- package/es/common/isArrayLike.js +1 -2
- package/es/common/isNull.js +2 -1
- package/es/common/isShallowEqual.js +1 -2
- package/es/common/isString.js +1 -1
- package/es/common/isType.js +1 -1
- package/es/common/isUndefined.js +1 -1
- package/es/common/isValid.js +1 -1
- package/es/common/isValidNumber.js +1 -1
- package/es/common/isValidUrl.js +1 -1
- package/es/common/lowerFirst.js +1 -1
- package/es/data-structure/bounds.js +1 -1
- package/es/data-structure/hashTable.d.ts +35 -0
- package/es/data-structure/hashTable.js +105 -0
- package/es/data-structure/hashTable.js.map +1 -0
- package/es/data-structure/index.d.ts +1 -0
- package/es/data-structure/index.js +3 -1
- package/es/data-structure/index.js.map +1 -1
- package/es/data-structure/matrix.js +1 -1
- package/es/data-structure/point.d.ts +1 -1
- package/es/data-structure/point.js +4 -5
- package/es/data-structure/point.js.map +1 -1
- package/es/format/number/formatDecimal.d.ts +2 -0
- package/es/format/number/formatDecimal.js +11 -0
- package/es/format/number/formatDecimal.js.map +1 -0
- package/es/format/number/formatGroup.d.ts +1 -0
- package/es/format/number/formatGroup.js +11 -0
- package/es/format/number/formatGroup.js.map +1 -0
- package/es/format/number/formatPrefixAuto.d.ts +2 -0
- package/es/format/number/formatPrefixAuto.js +11 -0
- package/es/format/number/formatPrefixAuto.js.map +1 -0
- package/es/format/number/formatRounded.d.ts +1 -0
- package/es/format/number/formatRounded.js +9 -0
- package/es/format/number/formatRounded.js.map +1 -0
- package/es/format/number/formatTrim.d.ts +1 -0
- package/es/format/number/formatTrim.js +19 -0
- package/es/format/number/formatTrim.js.map +1 -0
- package/es/format/number/index.d.ts +2 -0
- package/es/format/number/index.js +4 -0
- package/es/format/number/index.js.map +1 -0
- package/es/format/number/number.d.ts +53 -0
- package/es/format/number/number.js +125 -0
- package/es/format/number/number.js.map +1 -0
- package/es/format/number/specifier.d.ts +28 -0
- package/es/format/number/specifier.js +34 -0
- package/es/format/number/specifier.js.map +1 -0
- package/es/format/time.d.ts +79 -0
- package/es/format/time.js +196 -0
- package/es/format/time.js.map +1 -0
- package/es/graphics/algorithm/index.d.ts +1 -0
- package/es/graphics/algorithm/index.js +2 -0
- package/es/graphics/algorithm/index.js.map +1 -1
- package/es/graphics/graph-util.d.ts +23 -0
- package/es/graphics/graph-util.js +39 -0
- package/es/graphics/graph-util.js.map +1 -0
- package/es/graphics/index.d.ts +1 -1
- package/es/graphics/index.js +2 -2
- package/es/graphics/index.js.map +1 -1
- package/es/graphics/text/measure/textMeasure.js +1 -1
- package/es/graphics/text/measure/textMeasure.js.map +1 -1
- package/es/index.d.ts +3 -0
- package/es/index.js +6 -0
- package/es/index.js.map +1 -1
- package/es/lru.d.ts +25 -0
- package/es/lru.js +37 -0
- package/es/lru.js.map +1 -0
- package/package.json +3 -3
- package/cjs/color/defaultColors.d.ts +0 -150
- package/cjs/color/defaultColors.js +0 -155
- package/cjs/color/defaultColors.js.map +0 -1
- package/cjs/color/numberToHex.d.ts +0 -1
- package/cjs/color/numberToHex.js +0 -10
- package/cjs/color/numberToHex.js.map +0 -1
- package/cjs/color/numberToRgb.d.ts +0 -3
- package/cjs/color/numberToRgb.js +0 -20
- package/cjs/color/numberToRgb.js.map +0 -1
- package/cjs/color/parseColorString.d.ts +0 -3
- package/cjs/color/parseColorString.js +0 -38
- package/cjs/color/parseColorString.js.map +0 -1
- package/cjs/color/rgb.d.ts +0 -11
- package/cjs/color/rgb.js +0 -37
- package/cjs/color/rgb.js.map +0 -1
- package/cjs/graphics/distance.d.ts +0 -4
- package/cjs/graphics/distance.js +0 -22
- package/cjs/graphics/distance.js.map +0 -1
- package/es/color/defaultColors.d.ts +0 -150
- package/es/color/defaultColors.js +0 -151
- package/es/color/defaultColors.js.map +0 -1
- package/es/color/numberToHex.d.ts +0 -1
- package/es/color/numberToHex.js +0 -4
- package/es/color/numberToHex.js.map +0 -1
- package/es/color/numberToRgb.d.ts +0 -3
- package/es/color/numberToRgb.js +0 -12
- package/es/color/numberToRgb.js.map +0 -1
- package/es/color/parseColorString.d.ts +0 -3
- package/es/color/parseColorString.js +0 -34
- package/es/color/parseColorString.js.map +0 -1
- package/es/color/rgb.d.ts +0 -11
- package/es/color/rgb.js +0 -26
- package/es/color/rgb.js.map +0 -1
- package/es/graphics/distance.d.ts +0 -4
- package/es/graphics/distance.js +0 -14
- package/es/graphics/distance.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1465,6 +1465,153 @@
|
|
|
1465
1465
|
});
|
|
1466
1466
|
}
|
|
1467
1467
|
|
|
1468
|
+
class HashValue {
|
|
1469
|
+
}
|
|
1470
|
+
class HashTable {
|
|
1471
|
+
constructor() {
|
|
1472
|
+
this.items = {};
|
|
1473
|
+
this.itemList = [];
|
|
1474
|
+
}
|
|
1475
|
+
get type() {
|
|
1476
|
+
return 'xhHashTable';
|
|
1477
|
+
}
|
|
1478
|
+
set(key, value) {
|
|
1479
|
+
const vl = new HashValue();
|
|
1480
|
+
vl.key = key;
|
|
1481
|
+
vl.value = value;
|
|
1482
|
+
let index = this.itemList.length;
|
|
1483
|
+
if (this.has(key)) {
|
|
1484
|
+
index = this.items[key].index;
|
|
1485
|
+
}
|
|
1486
|
+
vl.index = index;
|
|
1487
|
+
this.itemList[index] = vl;
|
|
1488
|
+
this.items[key] = vl;
|
|
1489
|
+
return vl;
|
|
1490
|
+
}
|
|
1491
|
+
clear() {
|
|
1492
|
+
this.items = {};
|
|
1493
|
+
this.itemList = [];
|
|
1494
|
+
}
|
|
1495
|
+
del(key) {
|
|
1496
|
+
if (this.has(key)) {
|
|
1497
|
+
const index = this.items[key].index;
|
|
1498
|
+
if (index > -1) {
|
|
1499
|
+
this.itemList.splice(index, 1);
|
|
1500
|
+
}
|
|
1501
|
+
delete this.items[key];
|
|
1502
|
+
this.resetIndex();
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
delFrom(index) {
|
|
1506
|
+
for (let i = index + 1; i < this.count(); i++) {
|
|
1507
|
+
const key = this.itemList[i].key;
|
|
1508
|
+
delete this.items[key];
|
|
1509
|
+
}
|
|
1510
|
+
this.itemList.splice(index + 1, this.count() - index);
|
|
1511
|
+
this.resetIndex();
|
|
1512
|
+
}
|
|
1513
|
+
resetIndex() {
|
|
1514
|
+
this.foreachHashv((k, v) => {
|
|
1515
|
+
const index = this.itemList.indexOf(v);
|
|
1516
|
+
this.items[k].index = index;
|
|
1517
|
+
});
|
|
1518
|
+
}
|
|
1519
|
+
has(key) {
|
|
1520
|
+
return key in this.items;
|
|
1521
|
+
}
|
|
1522
|
+
get(key) {
|
|
1523
|
+
if (this.has(key)) {
|
|
1524
|
+
return this.items[key].value;
|
|
1525
|
+
}
|
|
1526
|
+
return null;
|
|
1527
|
+
}
|
|
1528
|
+
count() {
|
|
1529
|
+
return this.itemList.length;
|
|
1530
|
+
}
|
|
1531
|
+
all() {
|
|
1532
|
+
return this.itemList.map(vl => {
|
|
1533
|
+
return vl.value;
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1536
|
+
first() {
|
|
1537
|
+
return this.itemList[0].value;
|
|
1538
|
+
}
|
|
1539
|
+
last() {
|
|
1540
|
+
return this.itemList[this.itemList.length - 1].value;
|
|
1541
|
+
}
|
|
1542
|
+
getByIndex(index) {
|
|
1543
|
+
return this.itemList[index].value;
|
|
1544
|
+
}
|
|
1545
|
+
getKeyByIndex(index) {
|
|
1546
|
+
return this.itemList[index].key;
|
|
1547
|
+
}
|
|
1548
|
+
foreach(callback) {
|
|
1549
|
+
for (const key in this.items) {
|
|
1550
|
+
const returnVal = callback(key, this.items[key].value);
|
|
1551
|
+
if (returnVal === false) {
|
|
1552
|
+
return false;
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
return true;
|
|
1556
|
+
}
|
|
1557
|
+
foreachHashv(callback) {
|
|
1558
|
+
for (const key in this.items) {
|
|
1559
|
+
const returnVal = callback(key, this.items[key]);
|
|
1560
|
+
if (returnVal === false) {
|
|
1561
|
+
return false;
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
return true;
|
|
1565
|
+
}
|
|
1566
|
+
hasValue(value) {
|
|
1567
|
+
for (const key in this.items) {
|
|
1568
|
+
if (this.items[key].value === value) {
|
|
1569
|
+
return true;
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
return false;
|
|
1573
|
+
}
|
|
1574
|
+
indexOf(key) {
|
|
1575
|
+
if (this.has(key)) {
|
|
1576
|
+
return this.items[key].index;
|
|
1577
|
+
}
|
|
1578
|
+
return -1;
|
|
1579
|
+
}
|
|
1580
|
+
insertAt(index, value, key) {
|
|
1581
|
+
const hashV = new HashValue();
|
|
1582
|
+
hashV.index = index;
|
|
1583
|
+
hashV.key = key;
|
|
1584
|
+
hashV.value = value;
|
|
1585
|
+
this.itemList.splice(index, 0, hashV);
|
|
1586
|
+
this.items[key] = hashV;
|
|
1587
|
+
this.resetIndex();
|
|
1588
|
+
}
|
|
1589
|
+
sort(callback) {
|
|
1590
|
+
return this.itemList.sort((a, b) => {
|
|
1591
|
+
return callback(a.value, b.value);
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
toArray() {
|
|
1595
|
+
return this.itemList.slice(0, this.itemList.length).map(vl => {
|
|
1596
|
+
return vl.value;
|
|
1597
|
+
});
|
|
1598
|
+
}
|
|
1599
|
+
push(lists) {
|
|
1600
|
+
lists.foreach((key, value) => {
|
|
1601
|
+
this.set(key, value);
|
|
1602
|
+
});
|
|
1603
|
+
}
|
|
1604
|
+
mapKey() {
|
|
1605
|
+
const returnArr = [];
|
|
1606
|
+
for (const key in this.items) {
|
|
1607
|
+
returnArr.push(key);
|
|
1608
|
+
}
|
|
1609
|
+
return returnArr;
|
|
1610
|
+
}
|
|
1611
|
+
toImmutableMap() {
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1468
1615
|
const epsilon = 1e-12;
|
|
1469
1616
|
const pi = Math.PI;
|
|
1470
1617
|
const halfPi = pi / 2;
|
|
@@ -1598,13 +1745,13 @@
|
|
|
1598
1745
|
static distanceNN(x, y, x1, y1) {
|
|
1599
1746
|
return sqrt(pow(x - x1, 2) + pow(y - y1, 2));
|
|
1600
1747
|
}
|
|
1748
|
+
static distancePN(point, x, y) {
|
|
1749
|
+
return sqrt(pow(x - point.x, 2) + pow(y - point.y, 2));
|
|
1750
|
+
}
|
|
1601
1751
|
static pointAtPP(p1, p2, t) {
|
|
1602
1752
|
return new Point((p2.x - p1.x) * t + p1.x, (p2.y - p1.y) * t + p1.y);
|
|
1603
1753
|
}
|
|
1604
1754
|
}
|
|
1605
|
-
function pointAtPP(p1, p2, t) {
|
|
1606
|
-
return new Point((p2.x - p1.x) * t + p1.x, (p2.y - p1.y) * t + p1.y);
|
|
1607
|
-
}
|
|
1608
1755
|
class PolarPoint {
|
|
1609
1756
|
constructor(r = 0, theta = 0, r1, theta1) {
|
|
1610
1757
|
this.r = 0;
|
|
@@ -2155,9 +2302,113 @@
|
|
|
2155
2302
|
out.f = of + ob * rotateCenterX + od * rotateCenterY - b1 * offsetX - d1 * offsetY;
|
|
2156
2303
|
}
|
|
2157
2304
|
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2305
|
+
class LRU {
|
|
2306
|
+
constructor() {
|
|
2307
|
+
this.CLEAN_THRESHOLD = 1e3;
|
|
2308
|
+
this.L_TIME = 1000;
|
|
2309
|
+
this.R_COUNT = 1;
|
|
2310
|
+
this.R_TIMESTAMP_MAX_SIZE = 20;
|
|
2311
|
+
}
|
|
2312
|
+
clearCache(cache, params) {
|
|
2313
|
+
const { CLEAN_THRESHOLD = this.CLEAN_THRESHOLD, L_TIME = this.L_TIME, R_COUNT = this.R_COUNT } = params;
|
|
2314
|
+
if (cache.size < CLEAN_THRESHOLD) {
|
|
2315
|
+
return 0;
|
|
2316
|
+
}
|
|
2317
|
+
let clearNum = 0;
|
|
2318
|
+
const clear = (key) => {
|
|
2319
|
+
clearNum++;
|
|
2320
|
+
cache.delete(key);
|
|
2321
|
+
};
|
|
2322
|
+
const now = Date.now();
|
|
2323
|
+
cache.forEach((item, key) => {
|
|
2324
|
+
if (item.timestamp.length < R_COUNT) {
|
|
2325
|
+
return clear(key);
|
|
2326
|
+
}
|
|
2327
|
+
let useCount = 0;
|
|
2328
|
+
while (now - item.timestamp[item.timestamp.length - 1 - useCount] < L_TIME) {
|
|
2329
|
+
useCount++;
|
|
2330
|
+
if (useCount >= R_COUNT) {
|
|
2331
|
+
break;
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
if (useCount < R_COUNT) {
|
|
2335
|
+
return clear(key);
|
|
2336
|
+
}
|
|
2337
|
+
while (now - item.timestamp[0] > L_TIME) {
|
|
2338
|
+
item.timestamp.shift();
|
|
2339
|
+
}
|
|
2340
|
+
return;
|
|
2341
|
+
});
|
|
2342
|
+
return clearNum;
|
|
2343
|
+
}
|
|
2344
|
+
addLimitedTimestamp(cacheItem, t, params) {
|
|
2345
|
+
const { R_TIMESTAMP_MAX_SIZE = this.R_TIMESTAMP_MAX_SIZE } = params;
|
|
2346
|
+
if (cacheItem.timestamp.length > R_TIMESTAMP_MAX_SIZE) {
|
|
2347
|
+
cacheItem.timestamp.shift();
|
|
2348
|
+
}
|
|
2349
|
+
cacheItem.timestamp.push(t);
|
|
2350
|
+
}
|
|
2351
|
+
clearTimeStamp(cache, params) {
|
|
2352
|
+
const { L_TIME = this.L_TIME } = params;
|
|
2353
|
+
const now = Date.now();
|
|
2354
|
+
cache.forEach(item => {
|
|
2355
|
+
while (now - item.timestamp[0] > L_TIME) {
|
|
2356
|
+
item.timestamp.shift();
|
|
2357
|
+
}
|
|
2358
|
+
});
|
|
2359
|
+
}
|
|
2360
|
+
clearItemTimestamp(cacheItem, params) {
|
|
2361
|
+
const { L_TIME = this.L_TIME } = params;
|
|
2362
|
+
const now = Date.now();
|
|
2363
|
+
while (now - cacheItem.timestamp[0] > L_TIME) {
|
|
2364
|
+
cacheItem.timestamp.shift();
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2368
|
+
|
|
2369
|
+
function hslToRgb(h, s, l) {
|
|
2370
|
+
s /= 100;
|
|
2371
|
+
l /= 100;
|
|
2372
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
2373
|
+
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
|
|
2374
|
+
const m = l - c / 2;
|
|
2375
|
+
let r = 0;
|
|
2376
|
+
let g = 0;
|
|
2377
|
+
let b = 0;
|
|
2378
|
+
if (0 <= h && h < 60) {
|
|
2379
|
+
r = c;
|
|
2380
|
+
g = x;
|
|
2381
|
+
b = 0;
|
|
2382
|
+
}
|
|
2383
|
+
else if (60 <= h && h < 120) {
|
|
2384
|
+
r = x;
|
|
2385
|
+
g = c;
|
|
2386
|
+
b = 0;
|
|
2387
|
+
}
|
|
2388
|
+
else if (120 <= h && h < 180) {
|
|
2389
|
+
r = 0;
|
|
2390
|
+
g = c;
|
|
2391
|
+
b = x;
|
|
2392
|
+
}
|
|
2393
|
+
else if (180 <= h && h < 240) {
|
|
2394
|
+
r = 0;
|
|
2395
|
+
g = x;
|
|
2396
|
+
b = c;
|
|
2397
|
+
}
|
|
2398
|
+
else if (240 <= h && h < 300) {
|
|
2399
|
+
r = x;
|
|
2400
|
+
g = 0;
|
|
2401
|
+
b = c;
|
|
2402
|
+
}
|
|
2403
|
+
else if (300 <= h && h < 360) {
|
|
2404
|
+
r = c;
|
|
2405
|
+
g = 0;
|
|
2406
|
+
b = x;
|
|
2407
|
+
}
|
|
2408
|
+
r = Math.round((r + m) * 255);
|
|
2409
|
+
g = Math.round((g + m) * 255);
|
|
2410
|
+
b = Math.round((b + m) * 255);
|
|
2411
|
+
return { r, g, b };
|
|
2161
2412
|
}
|
|
2162
2413
|
|
|
2163
2414
|
function rgbToHsl(r, g, b) {
|
|
@@ -2197,35 +2448,10 @@
|
|
|
2197
2448
|
};
|
|
2198
2449
|
}
|
|
2199
2450
|
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
this.b = isNaN(+b) ? 255 : Math.max(0, Math.min(255, +b));
|
|
2205
|
-
if (isValid(opacity)) {
|
|
2206
|
-
this.opacity = isNaN(+opacity) ? 1 : Math.max(0, Math.min(1, +opacity));
|
|
2207
|
-
}
|
|
2208
|
-
else {
|
|
2209
|
-
this.opacity = 1;
|
|
2210
|
-
}
|
|
2211
|
-
}
|
|
2212
|
-
formatHex() {
|
|
2213
|
-
return `#${hex(this.r) + hex(this.g) + hex(this.b) + (this.opacity === 1 ? '' : hex(this.opacity * 255))}`;
|
|
2214
|
-
}
|
|
2215
|
-
formatRgb() {
|
|
2216
|
-
const opacity = this.opacity;
|
|
2217
|
-
return `${opacity === 1 ? 'rgb(' : 'rgba('}${this.r},${this.g},${this.b}${opacity === 1 ? ')' : `,${opacity})`}`;
|
|
2218
|
-
}
|
|
2219
|
-
formatHsl() {
|
|
2220
|
-
const opacity = this.opacity;
|
|
2221
|
-
const { h, s, l } = rgbToHsl(this.r, this.g, this.b);
|
|
2222
|
-
return `${opacity === 1 ? 'hsl(' : 'hsla('}${h},${s}%,${l}%${opacity === 1 ? ')' : `,${opacity})`}`;
|
|
2223
|
-
}
|
|
2224
|
-
toString() {
|
|
2225
|
-
return this.formatHex();
|
|
2226
|
-
}
|
|
2227
|
-
}
|
|
2228
|
-
|
|
2451
|
+
const REG_HEX = /^#([0-9a-f]{3,8})$/;
|
|
2452
|
+
const DEFAULT_COLORS_OPACITY = {
|
|
2453
|
+
transparent: 0xffffff00
|
|
2454
|
+
};
|
|
2229
2455
|
const DEFAULT_COLORS = {
|
|
2230
2456
|
aliceblue: 0xf0f8ff,
|
|
2231
2457
|
antiquewhite: 0xfaebd7,
|
|
@@ -2376,52 +2602,10 @@
|
|
|
2376
2602
|
yellow: 0xffff00,
|
|
2377
2603
|
yellowgreen: 0x9acd32
|
|
2378
2604
|
};
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
l /= 100;
|
|
2383
|
-
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
2384
|
-
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
|
|
2385
|
-
const m = l - c / 2;
|
|
2386
|
-
let r = 0;
|
|
2387
|
-
let g = 0;
|
|
2388
|
-
let b = 0;
|
|
2389
|
-
if (0 <= h && h < 60) {
|
|
2390
|
-
r = c;
|
|
2391
|
-
g = x;
|
|
2392
|
-
b = 0;
|
|
2393
|
-
}
|
|
2394
|
-
else if (60 <= h && h < 120) {
|
|
2395
|
-
r = x;
|
|
2396
|
-
g = c;
|
|
2397
|
-
b = 0;
|
|
2398
|
-
}
|
|
2399
|
-
else if (120 <= h && h < 180) {
|
|
2400
|
-
r = 0;
|
|
2401
|
-
g = c;
|
|
2402
|
-
b = x;
|
|
2403
|
-
}
|
|
2404
|
-
else if (180 <= h && h < 240) {
|
|
2405
|
-
r = 0;
|
|
2406
|
-
g = x;
|
|
2407
|
-
b = c;
|
|
2408
|
-
}
|
|
2409
|
-
else if (240 <= h && h < 300) {
|
|
2410
|
-
r = x;
|
|
2411
|
-
g = 0;
|
|
2412
|
-
b = c;
|
|
2413
|
-
}
|
|
2414
|
-
else if (300 <= h && h < 360) {
|
|
2415
|
-
r = c;
|
|
2416
|
-
g = 0;
|
|
2417
|
-
b = x;
|
|
2418
|
-
}
|
|
2419
|
-
r = Math.round((r + m) * 255);
|
|
2420
|
-
g = Math.round((g + m) * 255);
|
|
2421
|
-
b = Math.round((b + m) * 255);
|
|
2422
|
-
return { r, g, b };
|
|
2605
|
+
function hex(value) {
|
|
2606
|
+
value = Math.max(0, Math.min(255, Math.round(value) || 0));
|
|
2607
|
+
return (value < 16 ? '0' : '') + value.toString(16);
|
|
2423
2608
|
}
|
|
2424
|
-
|
|
2425
2609
|
function rgb(value) {
|
|
2426
2610
|
if (isNumber(value)) {
|
|
2427
2611
|
return new RGB(value >> 16, (value >> 8) & 0xff, value & 0xff, 1);
|
|
@@ -2440,46 +2624,6 @@
|
|
|
2440
2624
|
}
|
|
2441
2625
|
return new RGB(255, 255, 255, 1);
|
|
2442
2626
|
}
|
|
2443
|
-
|
|
2444
|
-
const DEFAULT_COLORS_OPACITY = {
|
|
2445
|
-
transparent: 0xffffff00
|
|
2446
|
-
};
|
|
2447
|
-
const REG_HEX = /^#([0-9a-f]{3,8})$/;
|
|
2448
|
-
function parseColorString(color) {
|
|
2449
|
-
if (isValid(DEFAULT_COLORS_OPACITY[color])) {
|
|
2450
|
-
return rgba(DEFAULT_COLORS_OPACITY[color]);
|
|
2451
|
-
}
|
|
2452
|
-
if (isValid(DEFAULT_COLORS[color])) {
|
|
2453
|
-
return rgb(DEFAULT_COLORS[color]);
|
|
2454
|
-
}
|
|
2455
|
-
const formatValue = `${color}`.trim().toLowerCase();
|
|
2456
|
-
const isHex = REG_HEX.exec(formatValue);
|
|
2457
|
-
if (isHex) {
|
|
2458
|
-
const hex = parseInt(isHex[1], 16);
|
|
2459
|
-
const hexLength = isHex[1].length;
|
|
2460
|
-
if (hexLength === 3) {
|
|
2461
|
-
return new RGB(((hex >> 8) & 0xf) + (((hex >> 8) & 0xf) << 4), ((hex >> 4) & 0xf) + (((hex >> 4) & 0xf) << 4), (hex & 0xf) + ((hex & 0xf) << 4), 1);
|
|
2462
|
-
}
|
|
2463
|
-
if (hexLength === 6) {
|
|
2464
|
-
return rgb(hex);
|
|
2465
|
-
}
|
|
2466
|
-
else if (hexLength === 8) {
|
|
2467
|
-
return new RGB((hex >> 24) & 0xff, (hex >> 16) & 0xff, (hex >> 8) & 0xff, (hex & 0xff) / 0xff);
|
|
2468
|
-
}
|
|
2469
|
-
return;
|
|
2470
|
-
}
|
|
2471
|
-
if (/^(rgb|RGB|rgba|RGBA)/.test(formatValue)) {
|
|
2472
|
-
const aColor = formatValue.replace(/(?:\(|\)|rgba|RGBA|rgb|RGB)*/g, '').split(',');
|
|
2473
|
-
return new RGB(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10), parseFloat(aColor[3]));
|
|
2474
|
-
}
|
|
2475
|
-
if (/^(hsl|HSL|hsla|HSLA)/.test(formatValue)) {
|
|
2476
|
-
const aColor = formatValue.replace(/(?:\(|\)|hsla|HSLA|hsl|HSL)*/g, '').split(',');
|
|
2477
|
-
const rgb = hslToRgb(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10));
|
|
2478
|
-
return new RGB(rgb.r, rgb.g, rgb.b, parseFloat(aColor[3]));
|
|
2479
|
-
}
|
|
2480
|
-
return;
|
|
2481
|
-
}
|
|
2482
|
-
|
|
2483
2627
|
function SRGBToLinear(c) {
|
|
2484
2628
|
return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
|
|
2485
2629
|
}
|
|
@@ -2516,8 +2660,42 @@
|
|
|
2516
2660
|
return color.getHSVBrightness();
|
|
2517
2661
|
}
|
|
2518
2662
|
}
|
|
2663
|
+
static parseColorString(value) {
|
|
2664
|
+
if (isValid(DEFAULT_COLORS_OPACITY[value])) {
|
|
2665
|
+
return rgba(DEFAULT_COLORS_OPACITY[value]);
|
|
2666
|
+
}
|
|
2667
|
+
if (isValid(DEFAULT_COLORS[value])) {
|
|
2668
|
+
return rgb(DEFAULT_COLORS[value]);
|
|
2669
|
+
}
|
|
2670
|
+
const formatValue = `${value}`.trim().toLowerCase();
|
|
2671
|
+
const isHex = REG_HEX.exec(formatValue);
|
|
2672
|
+
if (isHex) {
|
|
2673
|
+
const hex = parseInt(isHex[1], 16);
|
|
2674
|
+
const hexLength = isHex[1].length;
|
|
2675
|
+
if (hexLength === 3) {
|
|
2676
|
+
return new RGB(((hex >> 8) & 0xf) + (((hex >> 8) & 0xf) << 4), ((hex >> 4) & 0xf) + (((hex >> 4) & 0xf) << 4), (hex & 0xf) + ((hex & 0xf) << 4), 1);
|
|
2677
|
+
}
|
|
2678
|
+
if (hexLength === 6) {
|
|
2679
|
+
return rgb(hex);
|
|
2680
|
+
}
|
|
2681
|
+
else if (hexLength === 8) {
|
|
2682
|
+
return new RGB((hex >> 24) & 0xff, (hex >> 16) & 0xff, (hex >> 8) & 0xff, (hex & 0xff) / 0xff);
|
|
2683
|
+
}
|
|
2684
|
+
return;
|
|
2685
|
+
}
|
|
2686
|
+
if (/^(rgb|RGB|rgba|RGBA)/.test(formatValue)) {
|
|
2687
|
+
const aColor = formatValue.replace(/(?:\(|\)|rgba|RGBA|rgb|RGB)*/g, '').split(',');
|
|
2688
|
+
return new RGB(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10), parseFloat(aColor[3]));
|
|
2689
|
+
}
|
|
2690
|
+
if (/^(hsl|HSL|hsla|HSLA)/.test(formatValue)) {
|
|
2691
|
+
const aColor = formatValue.replace(/(?:\(|\)|hsla|HSLA|hsl|HSL)*/g, '').split(',');
|
|
2692
|
+
const rgb = hslToRgb(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10));
|
|
2693
|
+
return new RGB(rgb.r, rgb.g, rgb.b, parseFloat(aColor[3]));
|
|
2694
|
+
}
|
|
2695
|
+
return;
|
|
2696
|
+
}
|
|
2519
2697
|
constructor(value) {
|
|
2520
|
-
const color = parseColorString(value);
|
|
2698
|
+
const color = Color.parseColorString(value);
|
|
2521
2699
|
if (color) {
|
|
2522
2700
|
this.color = color;
|
|
2523
2701
|
}
|
|
@@ -2676,6 +2854,34 @@
|
|
|
2676
2854
|
return this;
|
|
2677
2855
|
}
|
|
2678
2856
|
}
|
|
2857
|
+
class RGB {
|
|
2858
|
+
constructor(r, g, b, opacity) {
|
|
2859
|
+
this.r = isNaN(+r) ? 255 : Math.max(0, Math.min(255, +r));
|
|
2860
|
+
this.g = isNaN(+g) ? 255 : Math.max(0, Math.min(255, +g));
|
|
2861
|
+
this.b = isNaN(+b) ? 255 : Math.max(0, Math.min(255, +b));
|
|
2862
|
+
if (isValid(opacity)) {
|
|
2863
|
+
this.opacity = isNaN(+opacity) ? 1 : Math.max(0, Math.min(1, +opacity));
|
|
2864
|
+
}
|
|
2865
|
+
else {
|
|
2866
|
+
this.opacity = 1;
|
|
2867
|
+
}
|
|
2868
|
+
}
|
|
2869
|
+
formatHex() {
|
|
2870
|
+
return `#${hex(this.r) + hex(this.g) + hex(this.b) + (this.opacity === 1 ? '' : hex(this.opacity * 255))}`;
|
|
2871
|
+
}
|
|
2872
|
+
formatRgb() {
|
|
2873
|
+
const opacity = this.opacity;
|
|
2874
|
+
return `${opacity === 1 ? 'rgb(' : 'rgba('}${this.r},${this.g},${this.b}${opacity === 1 ? ')' : `,${opacity})`}`;
|
|
2875
|
+
}
|
|
2876
|
+
formatHsl() {
|
|
2877
|
+
const opacity = this.opacity;
|
|
2878
|
+
const { h, s, l } = rgbToHsl(this.r, this.g, this.b);
|
|
2879
|
+
return `${opacity === 1 ? 'hsl(' : 'hsla('}${h},${s}%,${l}%${opacity === 1 ? ')' : `,${opacity})`}`;
|
|
2880
|
+
}
|
|
2881
|
+
toString() {
|
|
2882
|
+
return this.formatHex();
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2679
2885
|
|
|
2680
2886
|
function hexToRgb(str) {
|
|
2681
2887
|
let r = '';
|
|
@@ -2730,12 +2936,10 @@
|
|
|
2730
2936
|
__proto__: null,
|
|
2731
2937
|
Color: Color,
|
|
2732
2938
|
DEFAULT_COLORS: DEFAULT_COLORS,
|
|
2733
|
-
REG_HEX: REG_HEX,
|
|
2734
2939
|
RGB: RGB,
|
|
2735
2940
|
hexToRgb: hexToRgb,
|
|
2736
2941
|
hslToRgb: hslToRgb,
|
|
2737
2942
|
interpolateRgb: interpolateRgb,
|
|
2738
|
-
parseColorString: parseColorString,
|
|
2739
2943
|
rgbToHex: rgbToHex,
|
|
2740
2944
|
rgbToHsl: rgbToHsl
|
|
2741
2945
|
});
|
|
@@ -3139,6 +3343,124 @@
|
|
|
3139
3343
|
return nextList;
|
|
3140
3344
|
}
|
|
3141
3345
|
|
|
3346
|
+
let dirX;
|
|
3347
|
+
let dirY;
|
|
3348
|
+
let normalX;
|
|
3349
|
+
let normalY;
|
|
3350
|
+
let len;
|
|
3351
|
+
let lineWidthDiv2;
|
|
3352
|
+
let width;
|
|
3353
|
+
let height;
|
|
3354
|
+
function getOBBFromLine(point1, point2, lineWidth) {
|
|
3355
|
+
dirX = point2.x - point1.x;
|
|
3356
|
+
dirY = point2.y - point1.y;
|
|
3357
|
+
(normalX = dirY), (normalY = -dirX);
|
|
3358
|
+
width = len = Math.sqrt(normalX * normalX + normalY * normalY);
|
|
3359
|
+
height = lineWidth;
|
|
3360
|
+
normalX /= len;
|
|
3361
|
+
normalY /= len;
|
|
3362
|
+
lineWidthDiv2 = lineWidth / 2;
|
|
3363
|
+
dirX = lineWidthDiv2 * normalX;
|
|
3364
|
+
dirY = lineWidthDiv2 * normalY;
|
|
3365
|
+
const point11 = { x: point1.x + dirX, y: point1.y + dirY };
|
|
3366
|
+
const point12 = { x: point1.x - dirX, y: point1.y - dirY };
|
|
3367
|
+
const point13 = { x: point2.x + dirX, y: point2.y + dirY };
|
|
3368
|
+
const point14 = { x: point2.x - dirX, y: point2.y - dirY };
|
|
3369
|
+
return {
|
|
3370
|
+
point1: point11,
|
|
3371
|
+
point2: point12,
|
|
3372
|
+
point3: point13,
|
|
3373
|
+
point4: point14,
|
|
3374
|
+
width,
|
|
3375
|
+
height,
|
|
3376
|
+
left: Math.min(point1.x, point2.x) - Math.abs(dirX),
|
|
3377
|
+
top: Math.min(point1.y, point2.y) - Math.abs(dirY)
|
|
3378
|
+
};
|
|
3379
|
+
}
|
|
3380
|
+
const point1 = { x: 0, y: 0 };
|
|
3381
|
+
const point2 = { x: 0, y: 0 };
|
|
3382
|
+
function pointInOBB(point, obb) {
|
|
3383
|
+
point1.x = (obb.point1.x + obb.point2.x) / 2;
|
|
3384
|
+
point1.y = (obb.point1.y + obb.point2.y) / 2;
|
|
3385
|
+
point2.x = (obb.point3.x + obb.point4.x) / 2;
|
|
3386
|
+
point2.y = (obb.point3.y + obb.point4.y) / 2;
|
|
3387
|
+
return pointInLine(point, point1, point2, obb.height);
|
|
3388
|
+
}
|
|
3389
|
+
function pointInLine(point, point1, point2, lineWidth) {
|
|
3390
|
+
return lengthFromPointToLine(point, point1, point2) <= lineWidth / 2 && pointBetweenLine(point, point1, point2);
|
|
3391
|
+
}
|
|
3392
|
+
const dir1 = { x: 0, y: 0 };
|
|
3393
|
+
const dir2 = { x: 0, y: 0 };
|
|
3394
|
+
const normal = { x: 0, y: 0 };
|
|
3395
|
+
function pointBetweenLine(point, point1, point2) {
|
|
3396
|
+
dir1.x = point1.x - point.x;
|
|
3397
|
+
dir1.y = point1.y - point.y;
|
|
3398
|
+
dir2.x = point2.x - point.x;
|
|
3399
|
+
dir2.y = point2.y - point.y;
|
|
3400
|
+
normal.x = point1.y - point2.y;
|
|
3401
|
+
normal.y = point2.x - point1.x;
|
|
3402
|
+
return crossProductPoint(dir1, normal) * crossProductPoint(dir2, normal) < 0;
|
|
3403
|
+
}
|
|
3404
|
+
|
|
3405
|
+
function getContextFont$1({ fontStyle, fontVariant, fontWeight, fontSize, fontFamily }) {
|
|
3406
|
+
return ('' +
|
|
3407
|
+
(fontStyle ? fontStyle + ' ' : '') +
|
|
3408
|
+
(fontVariant ? fontVariant + ' ' : '') +
|
|
3409
|
+
(fontWeight ? fontWeight + ' ' : '') +
|
|
3410
|
+
(fontSize || 12) +
|
|
3411
|
+
'px ' +
|
|
3412
|
+
(fontFamily ? fontFamily : 'sans-serif'));
|
|
3413
|
+
}
|
|
3414
|
+
class GraphicUtil {
|
|
3415
|
+
constructor(canvas) {
|
|
3416
|
+
this.canvas = canvas;
|
|
3417
|
+
if (canvas) {
|
|
3418
|
+
this.ctx = canvas.getContext('2d');
|
|
3419
|
+
}
|
|
3420
|
+
}
|
|
3421
|
+
setCanvas(canvas) {
|
|
3422
|
+
this.canvas = canvas;
|
|
3423
|
+
if (canvas) {
|
|
3424
|
+
this.ctx = canvas.getContext('2d');
|
|
3425
|
+
}
|
|
3426
|
+
}
|
|
3427
|
+
measureText(tc) {
|
|
3428
|
+
if (!this.canvas) {
|
|
3429
|
+
console.warn('[warn] no canvas, measureText might be not accurate');
|
|
3430
|
+
return this.estimate(tc);
|
|
3431
|
+
}
|
|
3432
|
+
return this.measureTextByCanvas(tc);
|
|
3433
|
+
}
|
|
3434
|
+
measureTextByCanvas(tc) {
|
|
3435
|
+
if (!this.ctx) {
|
|
3436
|
+
console.error('[error!!!]measureTextByCanvas can not be called without canvas');
|
|
3437
|
+
return { width: -1, height: tc.fontSize };
|
|
3438
|
+
}
|
|
3439
|
+
this.ctx.font = getContextFont$1(tc);
|
|
3440
|
+
return {
|
|
3441
|
+
width: this.ctx.measureText(tc.text).width,
|
|
3442
|
+
height: tc.fontSize
|
|
3443
|
+
};
|
|
3444
|
+
}
|
|
3445
|
+
estimate({ text, fontSize }) {
|
|
3446
|
+
let eCharLen = 0;
|
|
3447
|
+
let cCharLen = 0;
|
|
3448
|
+
for (let i = 0; i < text.length; i++) {
|
|
3449
|
+
text.charCodeAt(i) < 128 ? eCharLen++ : cCharLen++;
|
|
3450
|
+
}
|
|
3451
|
+
return {
|
|
3452
|
+
width: ~~(0.8 * eCharLen * fontSize + cCharLen * fontSize),
|
|
3453
|
+
height: fontSize
|
|
3454
|
+
};
|
|
3455
|
+
}
|
|
3456
|
+
static getDefaultUtils(canvas) {
|
|
3457
|
+
if (!GraphicUtil.instance) {
|
|
3458
|
+
GraphicUtil.instance = new GraphicUtil(canvas);
|
|
3459
|
+
}
|
|
3460
|
+
return GraphicUtil.instance;
|
|
3461
|
+
}
|
|
3462
|
+
}
|
|
3463
|
+
|
|
3142
3464
|
const EPSILON = 1e-8;
|
|
3143
3465
|
function lineIntersectPolygon(a1x, a1y, a2x, a2y, points) {
|
|
3144
3466
|
for (let i = 0, p2 = points[points.length - 1]; i < points.length; i++) {
|
|
@@ -3543,6 +3865,7 @@
|
|
|
3543
3865
|
if (isNil(this._canvas) &&
|
|
3544
3866
|
typeof window !== 'undefined' &&
|
|
3545
3867
|
typeof window.document !== 'undefined' &&
|
|
3868
|
+
globalThis &&
|
|
3546
3869
|
isValid(globalThis.document)) {
|
|
3547
3870
|
this._canvas = globalThis.document.createElement('canvas');
|
|
3548
3871
|
}
|
|
@@ -3757,16 +4080,6 @@
|
|
|
3757
4080
|
TextMeasure.NUMBERS_CHAR_SET = '0123456789';
|
|
3758
4081
|
TextMeasure.FULL_SIZE_CHAR = '字';
|
|
3759
4082
|
|
|
3760
|
-
function distancePP(p1, p2) {
|
|
3761
|
-
return sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2));
|
|
3762
|
-
}
|
|
3763
|
-
function distanceNN(x, y, x1, y1) {
|
|
3764
|
-
return sqrt(pow(x - x1, 2) + pow(y - y1, 2));
|
|
3765
|
-
}
|
|
3766
|
-
function distancePN(point, x, y) {
|
|
3767
|
-
return sqrt(pow(x - point.x, 2) + pow(y - point.y, 2));
|
|
3768
|
-
}
|
|
3769
|
-
|
|
3770
4083
|
const hasConsole = typeof console !== 'undefined';
|
|
3771
4084
|
function log(method, level, input) {
|
|
3772
4085
|
const args = [level].concat([].slice.call(input));
|
|
@@ -4471,6 +4784,684 @@
|
|
|
4471
4784
|
return { x: lng, y: lat };
|
|
4472
4785
|
}
|
|
4473
4786
|
|
|
4787
|
+
class TimeUtil {
|
|
4788
|
+
static getInstance() {
|
|
4789
|
+
if (!TimeUtil.instance) {
|
|
4790
|
+
TimeUtil.instance = new TimeUtil();
|
|
4791
|
+
}
|
|
4792
|
+
return TimeUtil.instance;
|
|
4793
|
+
}
|
|
4794
|
+
constructor() {
|
|
4795
|
+
this.locale_shortWeekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
4796
|
+
this.locale_periods = ['AM', 'PM'];
|
|
4797
|
+
this.locale_weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
4798
|
+
this.locale_shortMonths = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
4799
|
+
this.numberRe = /^\s*\d+/;
|
|
4800
|
+
this.pads = { '-': '', _: ' ', '0': '0' };
|
|
4801
|
+
this.requoteRe = /[\\^$*+?|[\]().{}]/g;
|
|
4802
|
+
this.locale_months = [
|
|
4803
|
+
'January',
|
|
4804
|
+
'February',
|
|
4805
|
+
'March',
|
|
4806
|
+
'April',
|
|
4807
|
+
'May',
|
|
4808
|
+
'June',
|
|
4809
|
+
'July',
|
|
4810
|
+
'August',
|
|
4811
|
+
'September',
|
|
4812
|
+
'October',
|
|
4813
|
+
'November',
|
|
4814
|
+
'December'
|
|
4815
|
+
];
|
|
4816
|
+
this.formatShortWeekday = (d) => {
|
|
4817
|
+
return this.locale_shortWeekdays[d.getDay()];
|
|
4818
|
+
};
|
|
4819
|
+
this.formatWeekday = (d) => {
|
|
4820
|
+
return this.locale_weekdays[d.getDay()];
|
|
4821
|
+
};
|
|
4822
|
+
this.formatShortMonth = (d) => {
|
|
4823
|
+
return this.locale_shortMonths[d.getMonth()];
|
|
4824
|
+
};
|
|
4825
|
+
this.formatMonth = (d) => {
|
|
4826
|
+
return this.locale_months[d.getMonth()];
|
|
4827
|
+
};
|
|
4828
|
+
this.formatDayOfMonth = (d, p) => {
|
|
4829
|
+
return this.pad(d.getDate(), p, 2);
|
|
4830
|
+
};
|
|
4831
|
+
this.formatHour24 = (d, p) => {
|
|
4832
|
+
return this.pad(d.getHours(), p, 2);
|
|
4833
|
+
};
|
|
4834
|
+
this.formatHour12 = (d, p) => {
|
|
4835
|
+
return this.pad(d.getHours() % 12 || 12, p, 2);
|
|
4836
|
+
};
|
|
4837
|
+
this.formatMilliseconds = (d, p) => {
|
|
4838
|
+
return this.pad(d.getMilliseconds(), p, 3);
|
|
4839
|
+
};
|
|
4840
|
+
this.formatMonthNumber = (d, p) => {
|
|
4841
|
+
return this.pad(d.getMonth() + 1, p, 2);
|
|
4842
|
+
};
|
|
4843
|
+
this.formatMinutes = (d, p) => {
|
|
4844
|
+
return this.pad(d.getMinutes(), p, 2);
|
|
4845
|
+
};
|
|
4846
|
+
this.formatPeriod = (d) => {
|
|
4847
|
+
return this.locale_periods[+(d.getHours() >= 12)];
|
|
4848
|
+
};
|
|
4849
|
+
this.formatSeconds = (d, p) => {
|
|
4850
|
+
return this.pad(d.getSeconds(), p, 2);
|
|
4851
|
+
};
|
|
4852
|
+
this.formatFullYear = (d, p) => {
|
|
4853
|
+
return this.pad(d.getFullYear() % 10000, p, 4);
|
|
4854
|
+
};
|
|
4855
|
+
this.formatUTCShortWeekday = (d) => {
|
|
4856
|
+
return this.locale_shortWeekdays[d.getUTCDay()];
|
|
4857
|
+
};
|
|
4858
|
+
this.formatUTCWeekday = (d) => {
|
|
4859
|
+
return this.locale_weekdays[d.getUTCDay()];
|
|
4860
|
+
};
|
|
4861
|
+
this.formatUTCShortMonth = (d) => {
|
|
4862
|
+
return this.locale_shortMonths[d.getUTCMonth()];
|
|
4863
|
+
};
|
|
4864
|
+
this.formatUTCMonth = (d) => {
|
|
4865
|
+
return this.locale_months[d.getUTCMonth()];
|
|
4866
|
+
};
|
|
4867
|
+
this.formatUTCDayOfMonth = (d, p) => {
|
|
4868
|
+
return this.pad(d.getUTCDate(), p, 2);
|
|
4869
|
+
};
|
|
4870
|
+
this.formatUTCHour24 = (d, p) => {
|
|
4871
|
+
return this.pad(d.getUTCHours(), p, 2);
|
|
4872
|
+
};
|
|
4873
|
+
this.formatUTCHour12 = (d, p) => {
|
|
4874
|
+
return this.pad(d.getUTCHours() % 12 || 12, p, 2);
|
|
4875
|
+
};
|
|
4876
|
+
this.formatUTCMilliseconds = (d, p) => {
|
|
4877
|
+
return this.pad(d.getUTCMilliseconds(), p, 3);
|
|
4878
|
+
};
|
|
4879
|
+
this.formatUTCMonthNumber = (d, p) => {
|
|
4880
|
+
return this.pad(d.getUTCMonth() + 1, p, 2);
|
|
4881
|
+
};
|
|
4882
|
+
this.formatUTCMinutes = (d, p) => {
|
|
4883
|
+
return this.pad(d.getUTCMinutes(), p, 2);
|
|
4884
|
+
};
|
|
4885
|
+
this.formatUTCPeriod = (d) => {
|
|
4886
|
+
return this.locale_periods[+(d.getUTCHours() >= 12)];
|
|
4887
|
+
};
|
|
4888
|
+
this.formatUTCSeconds = (d, p) => {
|
|
4889
|
+
return this.pad(d.getUTCSeconds(), p, 2);
|
|
4890
|
+
};
|
|
4891
|
+
this.formatUTCFullYear = (d, p) => {
|
|
4892
|
+
return this.pad(d.getUTCFullYear() % 10000, p, 4);
|
|
4893
|
+
};
|
|
4894
|
+
this.formats = {
|
|
4895
|
+
a: this.formatShortWeekday,
|
|
4896
|
+
A: this.formatWeekday,
|
|
4897
|
+
b: this.formatShortMonth,
|
|
4898
|
+
B: this.formatMonth,
|
|
4899
|
+
d: this.formatDayOfMonth,
|
|
4900
|
+
e: this.formatDayOfMonth,
|
|
4901
|
+
H: this.formatHour24,
|
|
4902
|
+
I: this.formatHour12,
|
|
4903
|
+
L: this.formatMilliseconds,
|
|
4904
|
+
m: this.formatMonthNumber,
|
|
4905
|
+
M: this.formatMinutes,
|
|
4906
|
+
p: this.formatPeriod,
|
|
4907
|
+
S: this.formatSeconds,
|
|
4908
|
+
Y: this.formatFullYear
|
|
4909
|
+
};
|
|
4910
|
+
this.utcFormats = {
|
|
4911
|
+
a: this.formatUTCShortWeekday,
|
|
4912
|
+
A: this.formatUTCWeekday,
|
|
4913
|
+
b: this.formatUTCShortMonth,
|
|
4914
|
+
B: this.formatUTCMonth,
|
|
4915
|
+
d: this.formatUTCDayOfMonth,
|
|
4916
|
+
e: this.formatUTCDayOfMonth,
|
|
4917
|
+
H: this.formatUTCHour24,
|
|
4918
|
+
I: this.formatUTCHour12,
|
|
4919
|
+
L: this.formatUTCMilliseconds,
|
|
4920
|
+
m: this.formatUTCMonthNumber,
|
|
4921
|
+
M: this.formatUTCMinutes,
|
|
4922
|
+
p: this.formatUTCPeriod,
|
|
4923
|
+
S: this.formatUTCSeconds,
|
|
4924
|
+
Y: this.formatUTCFullYear
|
|
4925
|
+
};
|
|
4926
|
+
this.parseShortWeekday = (d, string, i) => {
|
|
4927
|
+
const n = this.shortWeekdayRe.exec(string.slice(i));
|
|
4928
|
+
return n ? ((d.w = this.shortWeekdayLookup.get(n[0].toLowerCase())), i + n[0].length) : -1;
|
|
4929
|
+
};
|
|
4930
|
+
this.parseWeekday = (d, string, i) => {
|
|
4931
|
+
const n = this.weekdayRe.exec(string.slice(i));
|
|
4932
|
+
return n ? ((d.w = this.weekdayLookup.get(n[0].toLowerCase())), i + n[0].length) : -1;
|
|
4933
|
+
};
|
|
4934
|
+
this.parseShortMonth = (d, string, i) => {
|
|
4935
|
+
const n = this.shortMonthRe.exec(string.slice(i));
|
|
4936
|
+
return n ? ((d.m = this.shortMonthLookup.get(n[0].toLowerCase())), i + n[0].length) : -1;
|
|
4937
|
+
};
|
|
4938
|
+
this.parseMonth = (d, string, i) => {
|
|
4939
|
+
const n = this.monthRe.exec(string.slice(i));
|
|
4940
|
+
return n ? ((d.m = this.monthLookup.get(n[0].toLowerCase())), i + n[0].length) : -1;
|
|
4941
|
+
};
|
|
4942
|
+
this.parseDayOfMonth = (d, string, i) => {
|
|
4943
|
+
const n = this.numberRe.exec(string.slice(i, i + 2));
|
|
4944
|
+
return n ? ((d.d = +n[0]), i + n[0].length) : -1;
|
|
4945
|
+
};
|
|
4946
|
+
this.parseHour24 = (d, string, i) => {
|
|
4947
|
+
const n = this.numberRe.exec(string.slice(i, i + 2));
|
|
4948
|
+
return n ? ((d.H = +n[0]), i + n[0].length) : -1;
|
|
4949
|
+
};
|
|
4950
|
+
this.parseMilliseconds = (d, string, i) => {
|
|
4951
|
+
const n = this.numberRe.exec(string.slice(i, i + 3));
|
|
4952
|
+
return n ? ((d.L = +n[0]), i + n[0].length) : -1;
|
|
4953
|
+
};
|
|
4954
|
+
this.parseMonthNumber = (d, string, i) => {
|
|
4955
|
+
const n = this.numberRe.exec(string.slice(i, i + 2));
|
|
4956
|
+
return n ? ((d.m = n - 1), i + n[0].length) : -1;
|
|
4957
|
+
};
|
|
4958
|
+
this.parseMinutes = (d, string, i) => {
|
|
4959
|
+
const n = this.numberRe.exec(string.slice(i, i + 2));
|
|
4960
|
+
return n ? ((d.M = +n[0]), i + n[0].length) : -1;
|
|
4961
|
+
};
|
|
4962
|
+
this.parsePeriod = (d, string, i) => {
|
|
4963
|
+
const n = this.periodRe.exec(string.slice(i));
|
|
4964
|
+
return n ? ((d.p = this.periodLookup.get(n[0].toLowerCase())), i + n[0].length) : -1;
|
|
4965
|
+
};
|
|
4966
|
+
this.parseSeconds = (d, string, i) => {
|
|
4967
|
+
const n = this.numberRe.exec(string.slice(i, i + 2));
|
|
4968
|
+
return n ? ((d.S = +n[0]), i + n[0].length) : -1;
|
|
4969
|
+
};
|
|
4970
|
+
this.parseFullYear = (d, string, i) => {
|
|
4971
|
+
const n = this.numberRe.exec(string.slice(i, i + 4));
|
|
4972
|
+
return n ? ((d.y = +n[0]), i + n[0].length) : -1;
|
|
4973
|
+
};
|
|
4974
|
+
this.parses = {
|
|
4975
|
+
a: this.parseShortWeekday,
|
|
4976
|
+
A: this.parseWeekday,
|
|
4977
|
+
b: this.parseShortMonth,
|
|
4978
|
+
B: this.parseMonth,
|
|
4979
|
+
d: this.parseDayOfMonth,
|
|
4980
|
+
e: this.parseDayOfMonth,
|
|
4981
|
+
H: this.parseHour24,
|
|
4982
|
+
I: this.parseHour24,
|
|
4983
|
+
L: this.parseMilliseconds,
|
|
4984
|
+
m: this.parseMonthNumber,
|
|
4985
|
+
M: this.parseMinutes,
|
|
4986
|
+
p: this.parsePeriod,
|
|
4987
|
+
S: this.parseSeconds,
|
|
4988
|
+
Y: this.parseFullYear
|
|
4989
|
+
};
|
|
4990
|
+
this.timeFormat = (specifier, timeText) => {
|
|
4991
|
+
return this.newFormat(specifier, this.formats)(new Date(this.getFullTimeStamp(timeText)));
|
|
4992
|
+
};
|
|
4993
|
+
this.timeUTCFormat = (specifier, timeText) => {
|
|
4994
|
+
return this.newFormat(specifier, this.utcFormats)(new Date(this.getFullTimeStamp(timeText)));
|
|
4995
|
+
};
|
|
4996
|
+
this.timeParse = (specifier, timeText) => {
|
|
4997
|
+
return this.newParse(specifier, false)(timeText + '');
|
|
4998
|
+
};
|
|
4999
|
+
this.requoteF = this.requote.bind(this);
|
|
5000
|
+
this.periodRe = this.formatRe(this.locale_periods);
|
|
5001
|
+
this.periodLookup = this.formatLookup(this.locale_periods);
|
|
5002
|
+
this.weekdayRe = this.formatRe(this.locale_weekdays);
|
|
5003
|
+
this.weekdayLookup = this.formatLookup(this.locale_weekdays);
|
|
5004
|
+
this.shortWeekdayRe = this.formatRe(this.locale_shortWeekdays);
|
|
5005
|
+
this.shortWeekdayLookup = this.formatLookup(this.locale_shortWeekdays);
|
|
5006
|
+
this.monthRe = this.formatRe(this.locale_months);
|
|
5007
|
+
this.monthLookup = this.formatLookup(this.locale_months);
|
|
5008
|
+
this.shortMonthRe = this.formatRe(this.locale_shortMonths);
|
|
5009
|
+
this.shortMonthLookup = this.formatLookup(this.locale_shortMonths);
|
|
5010
|
+
}
|
|
5011
|
+
requote(s) {
|
|
5012
|
+
return s.replace(this.requoteRe, '\\$&');
|
|
5013
|
+
}
|
|
5014
|
+
localDate(d) {
|
|
5015
|
+
if (0 <= d.y && d.y < 100) {
|
|
5016
|
+
const date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
|
|
5017
|
+
date.setFullYear(d.y);
|
|
5018
|
+
return date;
|
|
5019
|
+
}
|
|
5020
|
+
return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
|
|
5021
|
+
}
|
|
5022
|
+
utcDate(d) {
|
|
5023
|
+
if (0 <= d.y && d.y < 100) {
|
|
5024
|
+
const date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
|
|
5025
|
+
date.setUTCFullYear(d.y);
|
|
5026
|
+
return date;
|
|
5027
|
+
}
|
|
5028
|
+
return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
|
|
5029
|
+
}
|
|
5030
|
+
newDate(y, m, d) {
|
|
5031
|
+
return { y: y, m: m, d: d, H: 0, M: 0, S: 0, L: 0 };
|
|
5032
|
+
}
|
|
5033
|
+
formatRe(names) {
|
|
5034
|
+
return new RegExp('^(?:' + names.map(this.requoteF).join('|') + ')', 'i');
|
|
5035
|
+
}
|
|
5036
|
+
formatLookup(names) {
|
|
5037
|
+
return new Map(names.map((name, i) => [name.toLowerCase(), i]));
|
|
5038
|
+
}
|
|
5039
|
+
pad(value, fill, width) {
|
|
5040
|
+
const sign = value < 0 ? '-' : '';
|
|
5041
|
+
const string = (sign ? -value : value) + '';
|
|
5042
|
+
const length = string.length;
|
|
5043
|
+
return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
|
|
5044
|
+
}
|
|
5045
|
+
parseSpecifier(d, specifier, string, j) {
|
|
5046
|
+
let i = 0;
|
|
5047
|
+
const n = specifier.length;
|
|
5048
|
+
const m = string.length;
|
|
5049
|
+
let c;
|
|
5050
|
+
let parse;
|
|
5051
|
+
while (i < n) {
|
|
5052
|
+
if (j >= m) {
|
|
5053
|
+
return -1;
|
|
5054
|
+
}
|
|
5055
|
+
c = specifier.charCodeAt(i++);
|
|
5056
|
+
if (c === 37) {
|
|
5057
|
+
c = specifier.charAt(i++);
|
|
5058
|
+
parse = this.parses[c in this.pads ? specifier.charAt(i++) : c];
|
|
5059
|
+
if (!parse || (j = parse(d, string, j)) < 0) {
|
|
5060
|
+
return -1;
|
|
5061
|
+
}
|
|
5062
|
+
}
|
|
5063
|
+
else if (c !== string.charCodeAt(j++)) {
|
|
5064
|
+
return -1;
|
|
5065
|
+
}
|
|
5066
|
+
}
|
|
5067
|
+
return j;
|
|
5068
|
+
}
|
|
5069
|
+
newParse(specifier, Z) {
|
|
5070
|
+
const that = this;
|
|
5071
|
+
return function (string) {
|
|
5072
|
+
const d = that.newDate(1900, undefined, 1);
|
|
5073
|
+
const i = that.parseSpecifier(d, specifier, (string += ''), 0);
|
|
5074
|
+
if (i !== string.length) {
|
|
5075
|
+
return null;
|
|
5076
|
+
}
|
|
5077
|
+
if ('Q' in d) {
|
|
5078
|
+
return new Date(d.Q);
|
|
5079
|
+
}
|
|
5080
|
+
if ('s' in d) {
|
|
5081
|
+
return new Date(d.s * 1000 + ('L' in d ? d.L : 0));
|
|
5082
|
+
}
|
|
5083
|
+
if (Z && !('Z' in d)) {
|
|
5084
|
+
d.Z = 0;
|
|
5085
|
+
}
|
|
5086
|
+
if ('p' in d) {
|
|
5087
|
+
d.H = (d.H % 12) + d.p * 12;
|
|
5088
|
+
}
|
|
5089
|
+
if (d.m === undefined) {
|
|
5090
|
+
d.m = 'q' in d ? d.q : 0;
|
|
5091
|
+
}
|
|
5092
|
+
if ('Z' in d) {
|
|
5093
|
+
d.H += (d.Z / 100) | 0;
|
|
5094
|
+
d.M += d.Z % 100;
|
|
5095
|
+
return that.utcDate(d);
|
|
5096
|
+
}
|
|
5097
|
+
return that.localDate(d);
|
|
5098
|
+
};
|
|
5099
|
+
}
|
|
5100
|
+
newFormat(specifier, formats) {
|
|
5101
|
+
const that = this;
|
|
5102
|
+
return function (date) {
|
|
5103
|
+
const string = [];
|
|
5104
|
+
let i = -1;
|
|
5105
|
+
let j = 0;
|
|
5106
|
+
const n = specifier.length;
|
|
5107
|
+
let c;
|
|
5108
|
+
let pad;
|
|
5109
|
+
let format;
|
|
5110
|
+
if (!(date instanceof Date)) {
|
|
5111
|
+
date = new Date(+date);
|
|
5112
|
+
}
|
|
5113
|
+
while (++i < n) {
|
|
5114
|
+
if (specifier.charCodeAt(i) === 37) {
|
|
5115
|
+
string.push(specifier.slice(j, i));
|
|
5116
|
+
if ((pad = that.pads[(c = specifier.charAt(++i))])) {
|
|
5117
|
+
c = specifier.charAt(++i);
|
|
5118
|
+
}
|
|
5119
|
+
else {
|
|
5120
|
+
pad = c === 'e' ? ' ' : '0';
|
|
5121
|
+
}
|
|
5122
|
+
format = formats[c];
|
|
5123
|
+
c = format(date, pad);
|
|
5124
|
+
string.push(c);
|
|
5125
|
+
j = i + 1;
|
|
5126
|
+
}
|
|
5127
|
+
}
|
|
5128
|
+
string.push(specifier.slice(j, i));
|
|
5129
|
+
return string.join('');
|
|
5130
|
+
};
|
|
5131
|
+
}
|
|
5132
|
+
getFullTimeStamp(timeText) {
|
|
5133
|
+
const timeOriStamp = parseInt(timeText + '', 10);
|
|
5134
|
+
return String(timeOriStamp).length === 10 ? timeOriStamp * 1000 : timeOriStamp;
|
|
5135
|
+
}
|
|
5136
|
+
}
|
|
5137
|
+
|
|
5138
|
+
function formatDecimal(x) {
|
|
5139
|
+
return Math.abs((x = Math.round(x))) >= 1e21 ? x.toLocaleString('en').replace(/,/g, '') : x.toString(10);
|
|
5140
|
+
}
|
|
5141
|
+
function formatDecimalParts(x, p) {
|
|
5142
|
+
const _x = p ? x.toExponential(p - 1) : x.toExponential();
|
|
5143
|
+
const i = _x.indexOf('e');
|
|
5144
|
+
if (i < 0) {
|
|
5145
|
+
return null;
|
|
5146
|
+
}
|
|
5147
|
+
const coefficient = _x.slice(0, i);
|
|
5148
|
+
return [coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient, +_x.slice(i + 1)];
|
|
5149
|
+
}
|
|
5150
|
+
|
|
5151
|
+
function formatGroup(grouping, thousands) {
|
|
5152
|
+
return function (value, width) {
|
|
5153
|
+
let i = value.length;
|
|
5154
|
+
const t = [];
|
|
5155
|
+
let j = 0;
|
|
5156
|
+
let g = grouping[0];
|
|
5157
|
+
let length = 0;
|
|
5158
|
+
while (i > 0 && g > 0) {
|
|
5159
|
+
if (length + g + 1 > width) {
|
|
5160
|
+
g = Math.max(1, width - length);
|
|
5161
|
+
}
|
|
5162
|
+
t.push(value.substring((i -= g), i + g));
|
|
5163
|
+
if ((length += g + 1) > width) {
|
|
5164
|
+
break;
|
|
5165
|
+
}
|
|
5166
|
+
g = grouping[(j = (j + 1) % grouping.length)];
|
|
5167
|
+
}
|
|
5168
|
+
return t.reverse().join(thousands);
|
|
5169
|
+
};
|
|
5170
|
+
}
|
|
5171
|
+
|
|
5172
|
+
let prefixExponent;
|
|
5173
|
+
function formatPrefixAuto(x, p) {
|
|
5174
|
+
const d = formatDecimalParts(x, p);
|
|
5175
|
+
if (!d) {
|
|
5176
|
+
return x + '';
|
|
5177
|
+
}
|
|
5178
|
+
const coefficient = d[0];
|
|
5179
|
+
const exponent = d[1];
|
|
5180
|
+
const i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1;
|
|
5181
|
+
const n = coefficient.length;
|
|
5182
|
+
return i === n
|
|
5183
|
+
? coefficient
|
|
5184
|
+
: i > n
|
|
5185
|
+
? coefficient + new Array(i - n + 1).join('0')
|
|
5186
|
+
: i > 0
|
|
5187
|
+
? coefficient.slice(0, i) + '.' + coefficient.slice(i)
|
|
5188
|
+
: '0.' + new Array(1 - i).join('0') + formatDecimalParts(x, Math.max(0, p + i - 1))[0];
|
|
5189
|
+
}
|
|
5190
|
+
|
|
5191
|
+
function formatRounded(x, p) {
|
|
5192
|
+
const d = formatDecimalParts(x, p);
|
|
5193
|
+
if (!d) {
|
|
5194
|
+
return x + '';
|
|
5195
|
+
}
|
|
5196
|
+
const coefficient = d[0];
|
|
5197
|
+
const exponent = d[1];
|
|
5198
|
+
return exponent < 0
|
|
5199
|
+
? '0.' + new Array(-exponent).join('0') + coefficient
|
|
5200
|
+
: coefficient.length > exponent + 1
|
|
5201
|
+
? coefficient.slice(0, exponent + 1) + '.' + coefficient.slice(exponent + 1)
|
|
5202
|
+
: coefficient + new Array(exponent - coefficient.length + 2).join('0');
|
|
5203
|
+
}
|
|
5204
|
+
|
|
5205
|
+
function formatTrim(s) {
|
|
5206
|
+
const n = s.length;
|
|
5207
|
+
let i0 = -1;
|
|
5208
|
+
let i1;
|
|
5209
|
+
out: for (let i = 1; i < n; ++i) {
|
|
5210
|
+
switch (s[i]) {
|
|
5211
|
+
case '.':
|
|
5212
|
+
i0 = i1 = i;
|
|
5213
|
+
break;
|
|
5214
|
+
case '0':
|
|
5215
|
+
if (i0 === 0) {
|
|
5216
|
+
i0 = i;
|
|
5217
|
+
}
|
|
5218
|
+
i1 = i;
|
|
5219
|
+
break;
|
|
5220
|
+
default:
|
|
5221
|
+
if (!+s[i]) {
|
|
5222
|
+
break out;
|
|
5223
|
+
}
|
|
5224
|
+
if (i0 > 0) {
|
|
5225
|
+
i0 = 0;
|
|
5226
|
+
}
|
|
5227
|
+
break;
|
|
5228
|
+
}
|
|
5229
|
+
}
|
|
5230
|
+
return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
|
|
5231
|
+
}
|
|
5232
|
+
|
|
5233
|
+
class FormatSpecifier {
|
|
5234
|
+
constructor(specifier = {}) {
|
|
5235
|
+
this.fill = specifier.fill === undefined ? ' ' : specifier.fill + '';
|
|
5236
|
+
this.align = specifier.align === undefined ? '>' : specifier.align + '';
|
|
5237
|
+
this.sign = specifier.sign === undefined ? '-' : specifier.sign + '';
|
|
5238
|
+
this.symbol = specifier.symbol === undefined ? '' : specifier.symbol + '';
|
|
5239
|
+
this.zero = !!specifier.zero;
|
|
5240
|
+
this.width = specifier.width === undefined ? undefined : +specifier.width;
|
|
5241
|
+
this.comma = !!specifier.comma;
|
|
5242
|
+
this.precision = specifier.precision === undefined ? undefined : +specifier.precision;
|
|
5243
|
+
this.trim = !!specifier.trim;
|
|
5244
|
+
this.type = specifier.type === undefined ? '' : specifier.type + '';
|
|
5245
|
+
}
|
|
5246
|
+
toString() {
|
|
5247
|
+
return (this.fill +
|
|
5248
|
+
this.align +
|
|
5249
|
+
this.sign +
|
|
5250
|
+
this.symbol +
|
|
5251
|
+
(this.zero ? '0' : '') +
|
|
5252
|
+
(this.width === undefined ? '' : Math.max(1, this.width | 0)) +
|
|
5253
|
+
(this.comma ? ',' : '') +
|
|
5254
|
+
(this.precision === undefined ? '' : '.' + Math.max(0, this.precision | 0)) +
|
|
5255
|
+
(this.trim ? '~' : '') +
|
|
5256
|
+
this.type);
|
|
5257
|
+
}
|
|
5258
|
+
}
|
|
5259
|
+
const numberSpecifierReg = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
|
|
5260
|
+
function formatSpecifier(specifier) {
|
|
5261
|
+
let match;
|
|
5262
|
+
if (!(match = numberSpecifierReg.exec(specifier))) {
|
|
5263
|
+
Logger.getInstance().error('invalid format: ' + specifier);
|
|
5264
|
+
return;
|
|
5265
|
+
}
|
|
5266
|
+
return new FormatSpecifier({
|
|
5267
|
+
fill: match[1],
|
|
5268
|
+
align: match[2],
|
|
5269
|
+
sign: match[3],
|
|
5270
|
+
symbol: match[4],
|
|
5271
|
+
zero: match[5],
|
|
5272
|
+
width: match[6],
|
|
5273
|
+
comma: match[7],
|
|
5274
|
+
precision: match[8] && match[8].slice(1),
|
|
5275
|
+
trim: match[9],
|
|
5276
|
+
type: match[10]
|
|
5277
|
+
});
|
|
5278
|
+
}
|
|
5279
|
+
|
|
5280
|
+
const prefixes = ['y', 'z', 'a', 'f', 'p', 'n', 'µ', 'm', '', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
|
|
5281
|
+
class NumberUtil {
|
|
5282
|
+
constructor() {
|
|
5283
|
+
this.locale = {
|
|
5284
|
+
thousands: ',',
|
|
5285
|
+
grouping: [3],
|
|
5286
|
+
currency: ['$', '']
|
|
5287
|
+
};
|
|
5288
|
+
this.group = this.locale.grouping === undefined || this.locale.thousands === undefined
|
|
5289
|
+
? (group) => group
|
|
5290
|
+
: formatGroup([...this.locale.grouping].map(Number), `${this.locale.thousands}`);
|
|
5291
|
+
this.currencyPrefix = this.locale.currency === undefined ? '' : this.locale.currency[0] + '';
|
|
5292
|
+
this.currencySuffix = this.locale.currency === undefined ? '' : this.locale.currency[1] + '';
|
|
5293
|
+
this.decimal = this.locale.decimal === undefined ? '.' : this.locale.decimal + '';
|
|
5294
|
+
this.numerals = this.locale.numerals === undefined
|
|
5295
|
+
? (numerals) => numerals
|
|
5296
|
+
: formatNumerals([...this.locale.numerals].map(String));
|
|
5297
|
+
this.percent = this.locale.percent === undefined ? '%' : this.locale.percent + '';
|
|
5298
|
+
this.minus = this.locale.minus === undefined ? '−' : this.locale.minus + '';
|
|
5299
|
+
this.nan = this.locale.nan === undefined ? 'NaN' : this.locale.nan + '';
|
|
5300
|
+
this.formatter = (specifier) => {
|
|
5301
|
+
return this.newFormat(specifier);
|
|
5302
|
+
};
|
|
5303
|
+
this.format = (specifier, value) => {
|
|
5304
|
+
return this.formatter(specifier)(value);
|
|
5305
|
+
};
|
|
5306
|
+
this.formatPrefix = (specifier, value) => {
|
|
5307
|
+
return this._formatPrefix(specifier, value);
|
|
5308
|
+
};
|
|
5309
|
+
}
|
|
5310
|
+
static getInstance() {
|
|
5311
|
+
if (!NumberUtil.instance) {
|
|
5312
|
+
NumberUtil.instance = new NumberUtil();
|
|
5313
|
+
}
|
|
5314
|
+
return NumberUtil.instance;
|
|
5315
|
+
}
|
|
5316
|
+
newFormat(specifier) {
|
|
5317
|
+
const specifierIns = formatSpecifier(specifier);
|
|
5318
|
+
let fill = specifierIns.fill;
|
|
5319
|
+
let align = specifierIns.align;
|
|
5320
|
+
const sign = specifierIns.sign;
|
|
5321
|
+
const symbol = specifierIns.symbol;
|
|
5322
|
+
let zero = specifierIns.zero;
|
|
5323
|
+
const width = specifierIns.width;
|
|
5324
|
+
let comma = specifierIns.comma;
|
|
5325
|
+
let precision = specifierIns.precision;
|
|
5326
|
+
let trim = specifierIns.trim;
|
|
5327
|
+
let type = specifierIns.type;
|
|
5328
|
+
if (type === 'n') {
|
|
5329
|
+
(comma = true), (type = 'g');
|
|
5330
|
+
}
|
|
5331
|
+
else if (!formatTypes[type]) {
|
|
5332
|
+
precision === undefined && (precision = 12), (trim = true), (type = 'g');
|
|
5333
|
+
}
|
|
5334
|
+
if (zero || (fill === '0' && align === '=')) {
|
|
5335
|
+
(zero = true), (fill = '0'), (align = '=');
|
|
5336
|
+
}
|
|
5337
|
+
const prefix = symbol === '$' ? this.currencyPrefix : symbol === '#' && /[boxX]/.test(type) ? '0' + type.toLowerCase() : '';
|
|
5338
|
+
const suffix = symbol === '$' ? this.currencySuffix : /[%p]/.test(type) ? this.percent : '';
|
|
5339
|
+
const formatType = formatTypes[type];
|
|
5340
|
+
const maybeSuffix = /[defgprstz%]/.test(type);
|
|
5341
|
+
precision =
|
|
5342
|
+
precision === undefined
|
|
5343
|
+
? 6
|
|
5344
|
+
: /[gprs]/.test(type)
|
|
5345
|
+
? Math.max(1, Math.min(21, precision))
|
|
5346
|
+
: Math.max(0, Math.min(20, precision));
|
|
5347
|
+
const { nan, minus, decimal, group, numerals } = this;
|
|
5348
|
+
function format(value) {
|
|
5349
|
+
let valuePrefix = prefix;
|
|
5350
|
+
let valueSuffix = suffix;
|
|
5351
|
+
let i;
|
|
5352
|
+
let n;
|
|
5353
|
+
let c;
|
|
5354
|
+
let _value = value;
|
|
5355
|
+
if (type === 'c') {
|
|
5356
|
+
valueSuffix = formatType(_value) + valueSuffix;
|
|
5357
|
+
_value = '';
|
|
5358
|
+
}
|
|
5359
|
+
else {
|
|
5360
|
+
_value = +_value;
|
|
5361
|
+
let valueNegative = _value < 0 || 1 / _value < 0;
|
|
5362
|
+
_value = isNaN(_value) ? nan : formatType(Math.abs(_value), precision);
|
|
5363
|
+
if (trim) {
|
|
5364
|
+
_value = formatTrim(_value);
|
|
5365
|
+
}
|
|
5366
|
+
if (valueNegative && +_value === 0 && sign !== '+') {
|
|
5367
|
+
valueNegative = false;
|
|
5368
|
+
}
|
|
5369
|
+
valuePrefix =
|
|
5370
|
+
(valueNegative ? (sign === '(' ? sign : minus) : sign === '-' || sign === '(' ? '' : sign) + valuePrefix;
|
|
5371
|
+
valueSuffix =
|
|
5372
|
+
(type === 's' ? prefixes[8 + prefixExponent / 3] : '') +
|
|
5373
|
+
valueSuffix +
|
|
5374
|
+
(valueNegative && sign === '(' ? ')' : '');
|
|
5375
|
+
if (maybeSuffix) {
|
|
5376
|
+
(i = -1), (n = _value.length);
|
|
5377
|
+
while (++i < n) {
|
|
5378
|
+
if (((c = _value.charCodeAt(i)), 48 > c || c > 57)) {
|
|
5379
|
+
valueSuffix = (c === 46 ? decimal + _value.slice(i + 1) : _value.slice(i)) + valueSuffix;
|
|
5380
|
+
_value = _value.slice(0, i);
|
|
5381
|
+
break;
|
|
5382
|
+
}
|
|
5383
|
+
}
|
|
5384
|
+
}
|
|
5385
|
+
}
|
|
5386
|
+
if (comma && !zero) {
|
|
5387
|
+
_value = group(_value, Infinity);
|
|
5388
|
+
}
|
|
5389
|
+
let length = valuePrefix.length + _value.length + valueSuffix.length;
|
|
5390
|
+
let padding = length < width ? new Array(width - length + 1).join(fill) : '';
|
|
5391
|
+
if (comma && zero) {
|
|
5392
|
+
_value = group(padding + _value, padding.length ? width - valueSuffix.length : Infinity);
|
|
5393
|
+
padding = '';
|
|
5394
|
+
}
|
|
5395
|
+
switch (align) {
|
|
5396
|
+
case '<':
|
|
5397
|
+
_value = valuePrefix + _value + valueSuffix + padding;
|
|
5398
|
+
break;
|
|
5399
|
+
case '=':
|
|
5400
|
+
_value = valuePrefix + padding + _value + valueSuffix;
|
|
5401
|
+
break;
|
|
5402
|
+
case '^':
|
|
5403
|
+
_value =
|
|
5404
|
+
padding.slice(0, (length = padding.length >> 1)) +
|
|
5405
|
+
valuePrefix +
|
|
5406
|
+
_value +
|
|
5407
|
+
valueSuffix +
|
|
5408
|
+
padding.slice(length);
|
|
5409
|
+
break;
|
|
5410
|
+
default:
|
|
5411
|
+
_value = padding + valuePrefix + _value + valueSuffix;
|
|
5412
|
+
break;
|
|
5413
|
+
}
|
|
5414
|
+
return numerals(_value);
|
|
5415
|
+
}
|
|
5416
|
+
format.toString = function () {
|
|
5417
|
+
return specifier + '';
|
|
5418
|
+
};
|
|
5419
|
+
return format;
|
|
5420
|
+
}
|
|
5421
|
+
_formatPrefix(specifier, value) {
|
|
5422
|
+
const _specifier = formatSpecifier(specifier);
|
|
5423
|
+
_specifier.type = 'f';
|
|
5424
|
+
const f = this.newFormat(_specifier.toString());
|
|
5425
|
+
const e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3;
|
|
5426
|
+
const k = Math.pow(10, -e);
|
|
5427
|
+
const prefix = prefixes[8 + e / 3];
|
|
5428
|
+
return function (value) {
|
|
5429
|
+
return f(k * value) + prefix;
|
|
5430
|
+
};
|
|
5431
|
+
}
|
|
5432
|
+
}
|
|
5433
|
+
const formatTypes = {
|
|
5434
|
+
'%': (x, p) => (x * 100).toFixed(p),
|
|
5435
|
+
b: (x) => Math.round(x).toString(2),
|
|
5436
|
+
c: (x) => x + '',
|
|
5437
|
+
d: formatDecimal,
|
|
5438
|
+
f: (x, p) => x.toFixed(p),
|
|
5439
|
+
e: (x, p) => x.toExponential(p),
|
|
5440
|
+
g: (x, p) => x.toPrecision(p),
|
|
5441
|
+
o: (x) => Math.round(x).toString(8),
|
|
5442
|
+
p: (x, p) => formatRounded(x * 100, p),
|
|
5443
|
+
r: formatRounded,
|
|
5444
|
+
s: formatPrefixAuto,
|
|
5445
|
+
X: (x) => Math.round(x).toString(16).toUpperCase(),
|
|
5446
|
+
x: (x) => Math.round(x).toString(16),
|
|
5447
|
+
t: (x, p) => {
|
|
5448
|
+
if (Number.isInteger(x)) {
|
|
5449
|
+
return x.toFixed(2);
|
|
5450
|
+
}
|
|
5451
|
+
return Math.floor(x * Math.pow(10, p)) / Math.pow(10, p) + '';
|
|
5452
|
+
},
|
|
5453
|
+
z: (x, p) => (x % 1 === 0 ? x + '' : x.toFixed(p))
|
|
5454
|
+
};
|
|
5455
|
+
function exponent(x) {
|
|
5456
|
+
const _x = formatDecimalParts(Math.abs(x));
|
|
5457
|
+
return _x ? _x[1] : NaN;
|
|
5458
|
+
}
|
|
5459
|
+
function formatNumerals(numerals) {
|
|
5460
|
+
return function (value) {
|
|
5461
|
+
return value.replace(/[0-9]/g, (i) => numerals[+i]);
|
|
5462
|
+
};
|
|
5463
|
+
}
|
|
5464
|
+
|
|
4474
5465
|
exports.AABBBounds = AABBBounds;
|
|
4475
5466
|
exports.Bounds = Bounds;
|
|
4476
5467
|
exports.Color = Color;
|
|
@@ -4478,23 +5469,29 @@
|
|
|
4478
5469
|
exports.DAY = DAY;
|
|
4479
5470
|
exports.DEFAULT_COLORS = DEFAULT_COLORS;
|
|
4480
5471
|
exports.EventEmitter = index$1;
|
|
5472
|
+
exports.FormatSpecifier = FormatSpecifier;
|
|
5473
|
+
exports.GraphicUtil = GraphicUtil;
|
|
4481
5474
|
exports.HOUR = HOUR;
|
|
5475
|
+
exports.HashTable = HashTable;
|
|
5476
|
+
exports.HashValue = HashValue;
|
|
5477
|
+
exports.LRU = LRU;
|
|
4482
5478
|
exports.Logger = Logger;
|
|
4483
5479
|
exports.MINUTE = MINUTE;
|
|
4484
5480
|
exports.MONTH = MONTH;
|
|
4485
5481
|
exports.Matrix = Matrix;
|
|
4486
5482
|
exports.NEWTON_ITERATIONS = NEWTON_ITERATIONS;
|
|
4487
5483
|
exports.NEWTON_MIN_SLOPE = NEWTON_MIN_SLOPE;
|
|
5484
|
+
exports.NumberUtil = NumberUtil;
|
|
4488
5485
|
exports.OBBBounds = OBBBounds;
|
|
4489
5486
|
exports.Point = Point;
|
|
4490
5487
|
exports.PointService = PointService;
|
|
4491
5488
|
exports.PolarPoint = PolarPoint;
|
|
4492
|
-
exports.REG_HEX = REG_HEX;
|
|
4493
5489
|
exports.RGB = RGB;
|
|
4494
5490
|
exports.SECOND = SECOND;
|
|
4495
5491
|
exports.SUBDIVISION_MAX_ITERATIONS = SUBDIVISION_MAX_ITERATIONS;
|
|
4496
5492
|
exports.SUBDIVISION_PRECISION = SUBDIVISION_PRECISION;
|
|
4497
5493
|
exports.TextMeasure = TextMeasure;
|
|
5494
|
+
exports.TimeUtil = TimeUtil;
|
|
4498
5495
|
exports.YEAR = YEAR;
|
|
4499
5496
|
exports.abs = abs;
|
|
4500
5497
|
exports.acos = acos;
|
|
@@ -4528,13 +5525,14 @@
|
|
|
4528
5525
|
exports.degreeToRadian = degreeToRadian;
|
|
4529
5526
|
exports.destination = destination;
|
|
4530
5527
|
exports.deviation = deviation;
|
|
4531
|
-
exports.distanceNN = distanceNN;
|
|
4532
|
-
exports.distancePN = distancePN;
|
|
4533
|
-
exports.distancePP = distancePP;
|
|
4534
5528
|
exports.eastAsianCharacterInfo = eastAsianCharacterInfo;
|
|
4535
5529
|
exports.epsilon = epsilon;
|
|
5530
|
+
exports.exponent = exponent;
|
|
4536
5531
|
exports.fixPrecision = fixPrecision;
|
|
4537
5532
|
exports.flattenArray = flattenArray;
|
|
5533
|
+
exports.formatNumerals = formatNumerals;
|
|
5534
|
+
exports.formatSpecifier = formatSpecifier;
|
|
5535
|
+
exports.formatTypes = formatTypes;
|
|
4538
5536
|
exports.fullYearGetterName = fullYearGetterName;
|
|
4539
5537
|
exports.fullYearSetterName = fullYearSetterName;
|
|
4540
5538
|
exports.fuzzyEqualNumber = fuzzyEqualNumber;
|
|
@@ -4553,6 +5551,7 @@
|
|
|
4553
5551
|
exports.getFormatFromValue = getFormatFromValue;
|
|
4554
5552
|
exports.getIntersectPoint = getIntersectPoint;
|
|
4555
5553
|
exports.getIntervalOptions = getIntervalOptions;
|
|
5554
|
+
exports.getOBBFromLine = getOBBFromLine;
|
|
4556
5555
|
exports.getRectIntersect = getRectIntersect;
|
|
4557
5556
|
exports.getScale = getScale;
|
|
4558
5557
|
exports.getScaleX = getScaleX;
|
|
@@ -4640,16 +5639,18 @@
|
|
|
4640
5639
|
exports.monthSetterName = monthSetterName;
|
|
4641
5640
|
exports.normalTransform = normalTransform;
|
|
4642
5641
|
exports.normalizePadding = normalizePadding;
|
|
5642
|
+
exports.numberSpecifierReg = numberSpecifierReg;
|
|
4643
5643
|
exports.pad = pad;
|
|
4644
|
-
exports.parseColorString = parseColorString;
|
|
4645
5644
|
exports.parseUint8ToImageData = parseUint8ToImageData;
|
|
4646
5645
|
exports.pi = pi;
|
|
4647
5646
|
exports.pi2 = pi2;
|
|
4648
5647
|
exports.pick = pick;
|
|
4649
5648
|
exports.pickWithout = pickWithout;
|
|
4650
5649
|
exports.pointAt = pointAt;
|
|
4651
|
-
exports.
|
|
5650
|
+
exports.pointBetweenLine = pointBetweenLine;
|
|
4652
5651
|
exports.pointInAABB = pointInAABB;
|
|
5652
|
+
exports.pointInLine = pointInLine;
|
|
5653
|
+
exports.pointInOBB = pointInOBB;
|
|
4653
5654
|
exports.pointInRect = pointInRect;
|
|
4654
5655
|
exports.polarToCartesian = polarToCartesian;
|
|
4655
5656
|
exports.polygonContainPoint = polygonContainPoint;
|