@visactor/vutils 0.17.2 → 0.18.0-alpha.0

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.
Files changed (123) hide show
  1. package/cjs/color/Color.d.ts +1 -162
  2. package/cjs/color/Color.js +9 -216
  3. package/cjs/color/Color.js.map +1 -1
  4. package/cjs/color/defaultColors.d.ts +150 -0
  5. package/cjs/color/defaultColors.js +155 -0
  6. package/cjs/color/defaultColors.js.map +1 -0
  7. package/cjs/color/index.d.ts +4 -1
  8. package/cjs/color/index.js +9 -9
  9. package/cjs/color/index.js.map +1 -1
  10. package/cjs/color/interpolate.d.ts +1 -1
  11. package/cjs/color/interpolate.js +2 -2
  12. package/cjs/color/interpolate.js.map +1 -1
  13. package/cjs/color/numberToHex.d.ts +1 -0
  14. package/cjs/color/numberToHex.js +10 -0
  15. package/cjs/color/numberToHex.js.map +1 -0
  16. package/cjs/color/numberToRgb.d.ts +3 -0
  17. package/cjs/color/numberToRgb.js +20 -0
  18. package/cjs/color/numberToRgb.js.map +1 -0
  19. package/cjs/color/parseColorString.d.ts +3 -0
  20. package/cjs/color/parseColorString.js +38 -0
  21. package/cjs/color/parseColorString.js.map +1 -0
  22. package/cjs/color/rgb.d.ts +11 -0
  23. package/cjs/color/rgb.js +37 -0
  24. package/cjs/color/rgb.js.map +1 -0
  25. package/cjs/common/debounce.js +1 -2
  26. package/cjs/common/getType.js +2 -1
  27. package/cjs/common/isNull.js +1 -2
  28. package/cjs/common/isObject.js +2 -1
  29. package/cjs/common/isShallowEqual.js +1 -1
  30. package/cjs/common/isString.js +1 -1
  31. package/cjs/common/isType.js +1 -1
  32. package/cjs/data-structure/index.d.ts +0 -1
  33. package/cjs/data-structure/index.js +2 -2
  34. package/cjs/data-structure/index.js.map +1 -1
  35. package/cjs/data-structure/point.d.ts +1 -1
  36. package/cjs/data-structure/point.js +6 -5
  37. package/cjs/data-structure/point.js.map +1 -1
  38. package/cjs/graphics/algorithm/index.d.ts +0 -1
  39. package/cjs/graphics/algorithm/index.js +1 -2
  40. package/cjs/graphics/algorithm/index.js.map +1 -1
  41. package/cjs/graphics/distance.d.ts +4 -0
  42. package/cjs/graphics/distance.js +22 -0
  43. package/cjs/graphics/distance.js.map +1 -0
  44. package/cjs/graphics/index.d.ts +1 -1
  45. package/cjs/graphics/index.js +2 -2
  46. package/cjs/graphics/index.js.map +1 -1
  47. package/cjs/graphics/text/measure/textMeasure.js +1 -1
  48. package/cjs/graphics/text/measure/textMeasure.js.map +1 -1
  49. package/cjs/index.d.ts +0 -1
  50. package/cjs/index.js +6 -7
  51. package/cjs/index.js.map +1 -1
  52. package/dist/index.js +139 -454
  53. package/dist/index.min.js +1 -1
  54. package/es/color/Color.d.ts +1 -162
  55. package/es/color/Color.js +8 -205
  56. package/es/color/Color.js.map +1 -1
  57. package/es/color/defaultColors.d.ts +150 -0
  58. package/es/color/defaultColors.js +151 -0
  59. package/es/color/defaultColors.js.map +1 -0
  60. package/es/color/index.d.ts +4 -1
  61. package/es/color/index.js +7 -1
  62. package/es/color/index.js.map +1 -1
  63. package/es/color/interpolate.d.ts +1 -1
  64. package/es/color/interpolate.js +1 -1
  65. package/es/color/interpolate.js.map +1 -1
  66. package/es/color/numberToHex.d.ts +1 -0
  67. package/es/color/numberToHex.js +4 -0
  68. package/es/color/numberToHex.js.map +1 -0
  69. package/es/color/numberToRgb.d.ts +3 -0
  70. package/es/color/numberToRgb.js +12 -0
  71. package/es/color/numberToRgb.js.map +1 -0
  72. package/es/color/parseColorString.d.ts +3 -0
  73. package/es/color/parseColorString.js +34 -0
  74. package/es/color/parseColorString.js.map +1 -0
  75. package/es/color/rgb.d.ts +11 -0
  76. package/es/color/rgb.js +26 -0
  77. package/es/color/rgb.js.map +1 -0
  78. package/es/common/debounce.js +1 -2
  79. package/es/common/getType.js +2 -1
  80. package/es/common/isNull.js +1 -2
  81. package/es/common/isObject.js +2 -1
  82. package/es/common/isShallowEqual.js +1 -1
  83. package/es/common/isString.js +1 -1
  84. package/es/common/isType.js +1 -1
  85. package/es/data-structure/index.d.ts +0 -1
  86. package/es/data-structure/index.js +0 -2
  87. package/es/data-structure/index.js.map +1 -1
  88. package/es/data-structure/point.d.ts +1 -1
  89. package/es/data-structure/point.js +4 -3
  90. package/es/data-structure/point.js.map +1 -1
  91. package/es/graphics/algorithm/index.d.ts +0 -1
  92. package/es/graphics/algorithm/index.js +0 -2
  93. package/es/graphics/algorithm/index.js.map +1 -1
  94. package/es/graphics/distance.d.ts +4 -0
  95. package/es/graphics/distance.js +14 -0
  96. package/es/graphics/distance.js.map +1 -0
  97. package/es/graphics/index.d.ts +1 -1
  98. package/es/graphics/index.js +2 -2
  99. package/es/graphics/index.js.map +1 -1
  100. package/es/graphics/text/measure/textMeasure.js +1 -1
  101. package/es/graphics/text/measure/textMeasure.js.map +1 -1
  102. package/es/index.d.ts +0 -1
  103. package/es/index.js +0 -2
  104. package/es/index.js.map +1 -1
  105. package/package.json +1 -1
  106. package/cjs/data-structure/hashTable.d.ts +0 -35
  107. package/cjs/data-structure/hashTable.js +0 -114
  108. package/cjs/data-structure/hashTable.js.map +0 -1
  109. package/cjs/graphics/graph-util.d.ts +0 -23
  110. package/cjs/graphics/graph-util.js +0 -47
  111. package/cjs/graphics/graph-util.js.map +0 -1
  112. package/cjs/lru.d.ts +0 -25
  113. package/cjs/lru.js +0 -45
  114. package/cjs/lru.js.map +0 -1
  115. package/es/data-structure/hashTable.d.ts +0 -35
  116. package/es/data-structure/hashTable.js +0 -104
  117. package/es/data-structure/hashTable.js.map +0 -1
  118. package/es/graphics/graph-util.d.ts +0 -23
  119. package/es/graphics/graph-util.js +0 -39
  120. package/es/graphics/graph-util.js.map +0 -1
  121. package/es/lru.d.ts +0 -25
  122. package/es/lru.js +0 -37
  123. package/es/lru.js.map +0 -1
package/dist/index.js CHANGED
@@ -1465,153 +1465,6 @@
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
-
1615
1468
  const epsilon = 1e-12;
1616
1469
  const pi = Math.PI;
1617
1470
  const halfPi = pi / 2;
@@ -1745,13 +1598,13 @@
1745
1598
  static distanceNN(x, y, x1, y1) {
1746
1599
  return sqrt(pow(x - x1, 2) + pow(y - y1, 2));
1747
1600
  }
1748
- static distancePN(point, x, y) {
1749
- return sqrt(pow(x - point.x, 2) + pow(y - point.y, 2));
1750
- }
1751
1601
  static pointAtPP(p1, p2, t) {
1752
1602
  return new Point((p2.x - p1.x) * t + p1.x, (p2.y - p1.y) * t + p1.y);
1753
1603
  }
1754
1604
  }
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
+ }
1755
1608
  class PolarPoint {
1756
1609
  constructor(r = 0, theta = 0, r1, theta1) {
1757
1610
  this.r = 0;
@@ -2302,113 +2155,9 @@
2302
2155
  out.f = of + ob * rotateCenterX + od * rotateCenterY - b1 * offsetX - d1 * offsetY;
2303
2156
  }
2304
2157
 
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 };
2158
+ function hex(value) {
2159
+ value = Math.max(0, Math.min(255, Math.round(value) || 0));
2160
+ return (value < 16 ? '0' : '') + value.toString(16);
2412
2161
  }
2413
2162
 
2414
2163
  function rgbToHsl(r, g, b) {
@@ -2448,10 +2197,35 @@
2448
2197
  };
2449
2198
  }
2450
2199
 
2451
- const REG_HEX = /^#([0-9a-f]{3,8})$/;
2452
- const DEFAULT_COLORS_OPACITY = {
2453
- transparent: 0xffffff00
2454
- };
2200
+ class RGB {
2201
+ constructor(r, g, b, opacity) {
2202
+ this.r = isNaN(+r) ? 255 : Math.max(0, Math.min(255, +r));
2203
+ this.g = isNaN(+g) ? 255 : Math.max(0, Math.min(255, +g));
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
+
2455
2229
  const DEFAULT_COLORS = {
2456
2230
  aliceblue: 0xf0f8ff,
2457
2231
  antiquewhite: 0xfaebd7,
@@ -2602,10 +2376,52 @@
2602
2376
  yellow: 0xffff00,
2603
2377
  yellowgreen: 0x9acd32
2604
2378
  };
2605
- function hex(value) {
2606
- value = Math.max(0, Math.min(255, Math.round(value) || 0));
2607
- return (value < 16 ? '0' : '') + value.toString(16);
2379
+
2380
+ function hslToRgb(h, s, l) {
2381
+ s /= 100;
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 };
2608
2423
  }
2424
+
2609
2425
  function rgb(value) {
2610
2426
  if (isNumber(value)) {
2611
2427
  return new RGB(value >> 16, (value >> 8) & 0xff, value & 0xff, 1);
@@ -2624,6 +2440,46 @@
2624
2440
  }
2625
2441
  return new RGB(255, 255, 255, 1);
2626
2442
  }
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
+
2627
2483
  function SRGBToLinear(c) {
2628
2484
  return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
2629
2485
  }
@@ -2660,42 +2516,8 @@
2660
2516
  return color.getHSVBrightness();
2661
2517
  }
2662
2518
  }
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
- }
2697
2519
  constructor(value) {
2698
- const color = Color.parseColorString(value);
2520
+ const color = parseColorString(value);
2699
2521
  if (color) {
2700
2522
  this.color = color;
2701
2523
  }
@@ -2854,34 +2676,6 @@
2854
2676
  return this;
2855
2677
  }
2856
2678
  }
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
- }
2885
2679
 
2886
2680
  function hexToRgb(str) {
2887
2681
  let r = '';
@@ -2936,10 +2730,12 @@
2936
2730
  __proto__: null,
2937
2731
  Color: Color,
2938
2732
  DEFAULT_COLORS: DEFAULT_COLORS,
2733
+ REG_HEX: REG_HEX,
2939
2734
  RGB: RGB,
2940
2735
  hexToRgb: hexToRgb,
2941
2736
  hslToRgb: hslToRgb,
2942
2737
  interpolateRgb: interpolateRgb,
2738
+ parseColorString: parseColorString,
2943
2739
  rgbToHex: rgbToHex,
2944
2740
  rgbToHsl: rgbToHsl
2945
2741
  });
@@ -3343,124 +3139,6 @@
3343
3139
  return nextList;
3344
3140
  }
3345
3141
 
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
-
3464
3142
  const EPSILON = 1e-8;
3465
3143
  function lineIntersectPolygon(a1x, a1y, a2x, a2y, points) {
3466
3144
  for (let i = 0, p2 = points[points.length - 1]; i < points.length; i++) {
@@ -3865,7 +3543,6 @@
3865
3543
  if (isNil(this._canvas) &&
3866
3544
  typeof window !== 'undefined' &&
3867
3545
  typeof window.document !== 'undefined' &&
3868
- globalThis &&
3869
3546
  isValid(globalThis.document)) {
3870
3547
  this._canvas = globalThis.document.createElement('canvas');
3871
3548
  }
@@ -4080,6 +3757,16 @@
4080
3757
  TextMeasure.NUMBERS_CHAR_SET = '0123456789';
4081
3758
  TextMeasure.FULL_SIZE_CHAR = '字';
4082
3759
 
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
+
4083
3770
  const hasConsole = typeof console !== 'undefined';
4084
3771
  function log(method, level, input) {
4085
3772
  const args = [level].concat([].slice.call(input));
@@ -4791,11 +4478,7 @@
4791
4478
  exports.DAY = DAY;
4792
4479
  exports.DEFAULT_COLORS = DEFAULT_COLORS;
4793
4480
  exports.EventEmitter = index$1;
4794
- exports.GraphicUtil = GraphicUtil;
4795
4481
  exports.HOUR = HOUR;
4796
- exports.HashTable = HashTable;
4797
- exports.HashValue = HashValue;
4798
- exports.LRU = LRU;
4799
4482
  exports.Logger = Logger;
4800
4483
  exports.MINUTE = MINUTE;
4801
4484
  exports.MONTH = MONTH;
@@ -4806,6 +4489,7 @@
4806
4489
  exports.Point = Point;
4807
4490
  exports.PointService = PointService;
4808
4491
  exports.PolarPoint = PolarPoint;
4492
+ exports.REG_HEX = REG_HEX;
4809
4493
  exports.RGB = RGB;
4810
4494
  exports.SECOND = SECOND;
4811
4495
  exports.SUBDIVISION_MAX_ITERATIONS = SUBDIVISION_MAX_ITERATIONS;
@@ -4844,6 +4528,9 @@
4844
4528
  exports.degreeToRadian = degreeToRadian;
4845
4529
  exports.destination = destination;
4846
4530
  exports.deviation = deviation;
4531
+ exports.distanceNN = distanceNN;
4532
+ exports.distancePN = distancePN;
4533
+ exports.distancePP = distancePP;
4847
4534
  exports.eastAsianCharacterInfo = eastAsianCharacterInfo;
4848
4535
  exports.epsilon = epsilon;
4849
4536
  exports.fixPrecision = fixPrecision;
@@ -4866,7 +4553,6 @@
4866
4553
  exports.getFormatFromValue = getFormatFromValue;
4867
4554
  exports.getIntersectPoint = getIntersectPoint;
4868
4555
  exports.getIntervalOptions = getIntervalOptions;
4869
- exports.getOBBFromLine = getOBBFromLine;
4870
4556
  exports.getRectIntersect = getRectIntersect;
4871
4557
  exports.getScale = getScale;
4872
4558
  exports.getScaleX = getScaleX;
@@ -4955,16 +4641,15 @@
4955
4641
  exports.normalTransform = normalTransform;
4956
4642
  exports.normalizePadding = normalizePadding;
4957
4643
  exports.pad = pad;
4644
+ exports.parseColorString = parseColorString;
4958
4645
  exports.parseUint8ToImageData = parseUint8ToImageData;
4959
4646
  exports.pi = pi;
4960
4647
  exports.pi2 = pi2;
4961
4648
  exports.pick = pick;
4962
4649
  exports.pickWithout = pickWithout;
4963
4650
  exports.pointAt = pointAt;
4964
- exports.pointBetweenLine = pointBetweenLine;
4651
+ exports.pointAtPP = pointAtPP;
4965
4652
  exports.pointInAABB = pointInAABB;
4966
- exports.pointInLine = pointInLine;
4967
- exports.pointInOBB = pointInOBB;
4968
4653
  exports.pointInRect = pointInRect;
4969
4654
  exports.polarToCartesian = polarToCartesian;
4970
4655
  exports.polygonContainPoint = polygonContainPoint;