@visactor/vutils 0.18.16 → 0.18.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1958,249 +1958,21 @@
1958
1958
  }
1959
1959
  }
1960
1960
 
1961
- function transformBoundsWithMatrix(out, bounds, matrix) {
1962
- const { x1, y1, x2, y2 } = bounds;
1963
- if (matrix.onlyTranslate()) {
1964
- if (out !== bounds) {
1965
- out.setValue(bounds.x1, bounds.y1, bounds.x2, bounds.y2);
1966
- }
1967
- out.translate(matrix.e, matrix.f);
1968
- return bounds;
1969
- }
1970
- out.clear();
1971
- out.add(matrix.a * x1 + matrix.c * y1 + matrix.e, matrix.b * x1 + matrix.d * y1 + matrix.f);
1972
- out.add(matrix.a * x2 + matrix.c * y1 + matrix.e, matrix.b * x2 + matrix.d * y1 + matrix.f);
1973
- out.add(matrix.a * x2 + matrix.c * y2 + matrix.e, matrix.b * x2 + matrix.d * y2 + matrix.f);
1974
- out.add(matrix.a * x1 + matrix.c * y2 + matrix.e, matrix.b * x1 + matrix.d * y2 + matrix.f);
1975
- return bounds;
1976
- }
1977
- function transformBounds(bounds, x, y, scaleX, scaleY, angle, rotateCenter) {
1978
- if (abs(scaleX) <= epsilon || abs(scaleY) <= epsilon) {
1979
- return;
1980
- }
1981
- scaleX !== 1 && bounds.scaleX(scaleX);
1982
- scaleY !== 1 && bounds.scaleY(scaleY);
1983
- if (isFinite(angle) && Math.abs(angle) > epsilon) {
1984
- let rx = 0;
1985
- let ry = 0;
1986
- if (rotateCenter !== undefined) {
1987
- rx = rotateCenter[0];
1988
- ry = rotateCenter[1];
1989
- }
1990
- bounds.rotate(angle, rx, ry);
1991
- }
1992
- bounds.translate(x, y);
1993
- }
1994
- class Bounds {
1995
- constructor(bounds) {
1996
- if (bounds) {
1997
- this.setValue(bounds.x1, bounds.y1, bounds.x2, bounds.y2);
1998
- }
1999
- else {
2000
- this.clear();
2001
- }
2002
- }
2003
- clone() {
2004
- return new Bounds(this);
2005
- }
2006
- clear() {
2007
- this.x1 = +Number.MAX_VALUE;
2008
- this.y1 = +Number.MAX_VALUE;
2009
- this.x2 = -Number.MAX_VALUE;
2010
- this.y2 = -Number.MAX_VALUE;
2011
- return this;
2012
- }
2013
- empty() {
2014
- return (this.x1 === +Number.MAX_VALUE &&
2015
- this.y1 === +Number.MAX_VALUE &&
2016
- this.x2 === -Number.MAX_VALUE &&
2017
- this.y2 === -Number.MAX_VALUE);
2018
- }
2019
- equals(b) {
2020
- return this.x1 === b.x1 && this.y1 === b.y1 && this.x2 === b.x2 && this.y2 === b.y2;
2021
- }
2022
- setValue(x1 = 0, y1 = 0, x2 = 0, y2 = 0) {
2023
- this.x1 = x1;
2024
- this.y1 = y1;
2025
- this.x2 = x2;
2026
- this.y2 = y2;
2027
- return this;
2028
- }
2029
- set(x1 = 0, y1 = 0, x2 = 0, y2 = 0) {
2030
- if (x2 < x1) {
2031
- this.x2 = x1;
2032
- this.x1 = x2;
2033
- }
2034
- else {
2035
- this.x1 = x1;
2036
- this.x2 = x2;
2037
- }
2038
- if (y2 < y1) {
2039
- this.y2 = y1;
2040
- this.y1 = y2;
2041
- }
2042
- else {
2043
- this.y1 = y1;
2044
- this.y2 = y2;
2045
- }
2046
- return this;
2047
- }
2048
- add(x = 0, y = 0) {
2049
- if (x < this.x1) {
2050
- this.x1 = x;
2051
- }
2052
- if (y < this.y1) {
2053
- this.y1 = y;
2054
- }
2055
- if (x > this.x2) {
2056
- this.x2 = x;
2057
- }
2058
- if (y > this.y2) {
2059
- this.y2 = y;
2060
- }
2061
- return this;
2062
- }
2063
- expand(d = 0) {
2064
- if (isArray(d)) {
2065
- this.y1 -= d[0];
2066
- this.x2 += d[1];
2067
- this.y2 += d[2];
2068
- this.x1 -= d[3];
2069
- }
2070
- else {
2071
- this.x1 -= d;
2072
- this.y1 -= d;
2073
- this.x2 += d;
2074
- this.y2 += d;
2075
- }
2076
- return this;
2077
- }
2078
- round() {
2079
- this.x1 = Math.floor(this.x1);
2080
- this.y1 = Math.floor(this.y1);
2081
- this.x2 = Math.ceil(this.x2);
2082
- this.y2 = Math.ceil(this.y2);
2083
- return this;
2084
- }
2085
- translate(dx = 0, dy = 0) {
2086
- this.x1 += dx;
2087
- this.x2 += dx;
2088
- this.y1 += dy;
2089
- this.y2 += dy;
2090
- return this;
2091
- }
2092
- rotate(angle = 0, x = 0, y = 0) {
2093
- const p = this.rotatedPoints(angle, x, y);
2094
- return this.clear().add(p[0], p[1]).add(p[2], p[3]).add(p[4], p[5]).add(p[6], p[7]);
2095
- }
2096
- scale(sx = 0, sy = 0, x = 0, y = 0) {
2097
- const p = this.scalePoints(sx, sy, x, y);
2098
- return this.clear().add(p[0], p[1]).add(p[2], p[3]);
2099
- }
2100
- union(b) {
2101
- if (b.x1 < this.x1) {
2102
- this.x1 = b.x1;
2103
- }
2104
- if (b.y1 < this.y1) {
2105
- this.y1 = b.y1;
2106
- }
2107
- if (b.x2 > this.x2) {
2108
- this.x2 = b.x2;
2109
- }
2110
- if (b.y2 > this.y2) {
2111
- this.y2 = b.y2;
2112
- }
2113
- return this;
2114
- }
2115
- intersect(b) {
2116
- if (b.x1 > this.x1) {
2117
- this.x1 = b.x1;
2118
- }
2119
- if (b.y1 > this.y1) {
2120
- this.y1 = b.y1;
2121
- }
2122
- if (b.x2 < this.x2) {
2123
- this.x2 = b.x2;
2124
- }
2125
- if (b.y2 < this.y2) {
2126
- this.y2 = b.y2;
2127
- }
2128
- return this;
2129
- }
2130
- encloses(b) {
2131
- return b && this.x1 <= b.x1 && this.x2 >= b.x2 && this.y1 <= b.y1 && this.y2 >= b.y2;
2132
- }
2133
- alignsWith(b) {
2134
- return b && (this.x1 === b.x1 || this.x2 === b.x2 || this.y1 === b.y1 || this.y2 === b.y2);
2135
- }
2136
- intersects(b) {
2137
- return b && !(this.x2 < b.x1 || this.x1 > b.x2 || this.y2 < b.y1 || this.y1 > b.y2);
2138
- }
2139
- contains(x = 0, y = 0) {
2140
- return !(x < this.x1 || x > this.x2 || y < this.y1 || y > this.y2);
2141
- }
2142
- containsPoint(p) {
2143
- return !(p.x < this.x1 || p.x > this.x2 || p.y < this.y1 || p.y > this.y2);
2144
- }
2145
- width() {
2146
- if (this.empty()) {
2147
- return 0;
2148
- }
2149
- return this.x2 - this.x1;
2150
- }
2151
- height() {
2152
- if (this.empty()) {
2153
- return 0;
1961
+ const parseUint8ToImageData = (buffer, width, height) => {
1962
+ const clampBuffer = new Uint8ClampedArray(buffer);
1963
+ const flipClampBuffer = new Uint8ClampedArray(buffer.length);
1964
+ for (let i = height - 1; i >= 0; i--) {
1965
+ for (let j = 0; j < width; j++) {
1966
+ const sourceIdx = i * width * 4 + j * 4;
1967
+ const targetIdx = (height - i) * width * 4 + j * 4;
1968
+ flipClampBuffer[targetIdx] = clampBuffer[sourceIdx];
1969
+ flipClampBuffer[targetIdx + 1] = clampBuffer[sourceIdx + 1];
1970
+ flipClampBuffer[targetIdx + 2] = clampBuffer[sourceIdx + 2];
1971
+ flipClampBuffer[targetIdx + 3] = clampBuffer[sourceIdx + 3];
2154
1972
  }
2155
- return this.y2 - this.y1;
2156
- }
2157
- scaleX(s = 0) {
2158
- this.x1 *= s;
2159
- this.x2 *= s;
2160
- return this;
2161
- }
2162
- scaleY(s = 0) {
2163
- this.y1 *= s;
2164
- this.y2 *= s;
2165
- return this;
2166
- }
2167
- transformWithMatrix(matrix) {
2168
- transformBoundsWithMatrix(this, this, matrix);
2169
- return this;
2170
- }
2171
- copy(b) {
2172
- this.x1 = b.x1;
2173
- this.y1 = b.y1;
2174
- this.x2 = b.x2;
2175
- this.y2 = b.y2;
2176
- return this;
2177
- }
2178
- rotatedPoints(angle, x, y) {
2179
- const { x1, y1, x2, y2 } = this;
2180
- const cos = Math.cos(angle);
2181
- const sin = Math.sin(angle);
2182
- const cx = x - x * cos + y * sin;
2183
- const cy = y - x * sin - y * cos;
2184
- return [
2185
- cos * x1 - sin * y1 + cx,
2186
- sin * x1 + cos * y1 + cy,
2187
- cos * x1 - sin * y2 + cx,
2188
- sin * x1 + cos * y2 + cy,
2189
- cos * x2 - sin * y1 + cx,
2190
- sin * x2 + cos * y1 + cy,
2191
- cos * x2 - sin * y2 + cx,
2192
- sin * x2 + cos * y2 + cy
2193
- ];
2194
- }
2195
- scalePoints(sx, sy, x, y) {
2196
- const { x1, y1, x2, y2 } = this;
2197
- return [sx * x1 + (1 - sx) * x, sy * y1 + (1 - sy) * y, sx * x2 + (1 - sx) * x, sy * y2 + (1 - sy) * y];
2198
1973
  }
2199
- }
2200
- class AABBBounds extends Bounds {
2201
- }
2202
- class OBBBounds extends Bounds {
2203
- }
1974
+ return new ImageData(flipClampBuffer, width, height);
1975
+ };
2204
1976
 
2205
1977
  function degreeToRadian(degree) {
2206
1978
  return degree * (Math.PI / 180);
@@ -2320,16 +2092,16 @@
2320
2092
  }
2321
2093
  else {
2322
2094
  if (sin > 0) {
2323
- radiusList.push(Math.abs((height - y) / cos));
2095
+ radiusList.push(Math.abs((height - y) / sin));
2324
2096
  }
2325
2097
  else {
2326
- radiusList.push(Math.abs(y / cos));
2098
+ radiusList.push(Math.abs(y / sin));
2327
2099
  }
2328
2100
  if (cos > 0) {
2329
- radiusList.push(Math.abs((width - x) / sin));
2101
+ radiusList.push(Math.abs((width - x) / cos));
2330
2102
  }
2331
2103
  else {
2332
- radiusList.push(Math.abs(x / sin));
2104
+ radiusList.push(Math.abs(x / cos));
2333
2105
  }
2334
2106
  }
2335
2107
  });
@@ -2349,2051 +2121,2293 @@
2349
2121
  return 1;
2350
2122
  }
2351
2123
 
2352
- class Matrix {
2353
- constructor(a = 1, b = 0, c = 0, d = 1, e = 0, f = 0) {
2354
- this.a = a;
2355
- this.b = b;
2356
- this.c = c;
2357
- this.d = d;
2358
- this.e = e;
2359
- this.f = f;
2360
- }
2361
- equalToMatrix(m2) {
2362
- return !(this.e !== m2.e ||
2363
- this.f !== m2.f ||
2364
- this.a !== m2.a ||
2365
- this.d !== m2.d ||
2366
- this.b !== m2.b ||
2367
- this.c !== m2.c);
2124
+ function sub(out, v1, v2) {
2125
+ out[0] = v1[0] - v2[0];
2126
+ out[1] = v1[1] - v2[1];
2127
+ }
2128
+ function isIntersect(left1, right1, left2, right2) {
2129
+ let min1 = left1[0];
2130
+ let max1 = right1[0];
2131
+ let min2 = left2[0];
2132
+ let max2 = right2[0];
2133
+ if (max1 < min1) {
2134
+ [min1, max1] = [max1, min1];
2368
2135
  }
2369
- equalTo(a, b, c, d, e, f) {
2370
- return !(this.e !== e || this.f !== f || this.a !== a || this.d !== d || this.b !== b || this.c !== c);
2136
+ if (max2 < min2) {
2137
+ [max2, min2] = [min2, max2];
2371
2138
  }
2372
- setValue(a, b, c, d, e, f) {
2373
- this.a = a;
2374
- this.b = b;
2375
- this.c = c;
2376
- this.d = d;
2377
- this.e = e;
2378
- this.f = f;
2379
- return this;
2139
+ if (max1 < min2 || max2 < min1) {
2140
+ return false;
2380
2141
  }
2381
- reset() {
2382
- this.a = 1;
2383
- this.b = 0;
2384
- this.c = 0;
2385
- this.d = 1;
2386
- this.e = 0;
2387
- this.f = 0;
2388
- return this;
2142
+ (min1 = left1[1]), (max1 = right1[1]), (min2 = left2[1]), (max2 = right2[1]);
2143
+ if (max1 < min1) {
2144
+ [min1, max1] = [max1, min1];
2389
2145
  }
2390
- getInverse() {
2391
- const a = this.a;
2392
- const b = this.b;
2393
- const c = this.c;
2394
- const d = this.d;
2395
- const e = this.e;
2396
- const f = this.f;
2397
- const m = new Matrix();
2398
- const dt = a * d - b * c;
2399
- m.a = d / dt;
2400
- m.b = -b / dt;
2401
- m.c = -c / dt;
2402
- m.d = a / dt;
2403
- m.e = (c * f - d * e) / dt;
2404
- m.f = -(a * f - b * e) / dt;
2405
- return m;
2146
+ if (max2 < min2) {
2147
+ [max2, min2] = [min2, max2];
2406
2148
  }
2407
- rotate(rad) {
2408
- const c = Math.cos(rad);
2409
- const s = Math.sin(rad);
2410
- const m11 = this.a * c + this.c * s;
2411
- const m12 = this.b * c + this.d * s;
2412
- const m21 = this.a * -s + this.c * c;
2413
- const m22 = this.b * -s + this.d * c;
2414
- this.a = m11;
2415
- this.b = m12;
2416
- this.c = m21;
2417
- this.d = m22;
2418
- return this;
2149
+ if (max1 < min2 || max2 < min1) {
2150
+ return false;
2419
2151
  }
2420
- rotateByCenter(rad, cx, cy) {
2421
- const cos = Math.cos(rad);
2422
- const sin = Math.sin(rad);
2423
- const rotateM13 = (1 - cos) * cx + sin * cy;
2424
- const rotateM23 = (1 - cos) * cy - sin * cx;
2425
- const m11 = cos * this.a - sin * this.b;
2426
- const m21 = sin * this.a + cos * this.b;
2427
- const m12 = cos * this.c - sin * this.d;
2428
- const m22 = sin * this.c + cos * this.d;
2429
- const m13 = cos * this.e - sin * this.f + rotateM13;
2430
- const m23 = sin * this.e + cos * this.f + rotateM23;
2431
- this.a = m11;
2432
- this.b = m21;
2433
- this.c = m12;
2434
- this.d = m22;
2435
- this.e = m13;
2436
- this.f = m23;
2437
- return this;
2152
+ return true;
2153
+ }
2154
+ function getIntersectPoint(left1, right1, left2, right2) {
2155
+ if (!isIntersect(left1, right1, left2, right2)) {
2156
+ return false;
2438
2157
  }
2439
- scale(sx, sy) {
2440
- this.a *= sx;
2441
- this.b *= sx;
2442
- this.c *= sy;
2443
- this.d *= sy;
2444
- return this;
2158
+ const dir1 = [0, 0];
2159
+ const dir2 = [0, 0];
2160
+ const tempVec = [0, 0];
2161
+ sub(dir1, right1, left1);
2162
+ sub(dir2, right2, left2);
2163
+ if (fuzzyEqualVec(dir1, dir2)) {
2164
+ return true;
2445
2165
  }
2446
- setScale(sx, sy) {
2447
- this.b = (this.b / this.a) * sx;
2448
- this.c = (this.c / this.d) * sy;
2449
- this.a = sx;
2450
- this.d = sy;
2451
- return this;
2166
+ sub(tempVec, left2, left1);
2167
+ const t = crossProduct(tempVec, dir2) / crossProduct(dir1, dir2);
2168
+ if (t >= 0 && t <= 1) {
2169
+ return [left1[0] + dir1[0] * t, left1[1] + dir1[1] * t];
2452
2170
  }
2453
- transform(a, b, c, d, e, f) {
2454
- this.multiply(a, b, c, d, e, f);
2455
- return this;
2171
+ return false;
2172
+ }
2173
+ function getRectIntersect(bbox1, bbox2, format) {
2174
+ if (bbox1 === null) {
2175
+ return bbox2;
2456
2176
  }
2457
- translate(x, y) {
2458
- this.e += this.a * x + this.c * y;
2459
- this.f += this.b * x + this.d * y;
2460
- return this;
2177
+ if (bbox2 === null) {
2178
+ return bbox1;
2461
2179
  }
2462
- transpose() {
2463
- const { a, b, c, d, e, f } = this;
2464
- this.a = b;
2465
- this.b = a;
2466
- this.c = d;
2467
- this.d = c;
2468
- this.e = f;
2469
- this.f = e;
2470
- return this;
2180
+ const { x11, x12, y11, y12, x21, x22, y21, y22 } = formatTwoBBox(bbox1, bbox2, format);
2181
+ if (x11 >= x22 || x12 <= x21 || y11 >= y22 || y12 <= y21) {
2182
+ return { x1: 0, y1: 0, x2: 0, y2: 0 };
2471
2183
  }
2472
- multiply(a2, b2, c2, d2, e2, f2) {
2473
- const a1 = this.a;
2474
- const b1 = this.b;
2475
- const c1 = this.c;
2476
- const d1 = this.d;
2477
- const e1 = this.e;
2478
- const f1 = this.f;
2479
- const m11 = a1 * a2 + c1 * b2;
2480
- const m12 = b1 * a2 + d1 * b2;
2481
- const m21 = a1 * c2 + c1 * d2;
2482
- const m22 = b1 * c2 + d1 * d2;
2483
- const dx = a1 * e2 + c1 * f2 + e1;
2484
- const dy = b1 * e2 + d1 * f2 + f1;
2485
- this.a = m11;
2486
- this.b = m12;
2487
- this.c = m21;
2488
- this.d = m22;
2489
- this.e = dx;
2490
- this.f = dy;
2491
- return this;
2184
+ return { x1: Math.max(x11, x21), y1: Math.max(y11, y21), x2: Math.min(x12, x22), y2: Math.min(y12, y22) };
2185
+ }
2186
+ exports.InnerBBox = void 0;
2187
+ (function (InnerBBox) {
2188
+ InnerBBox[InnerBBox["NONE"] = 0] = "NONE";
2189
+ InnerBBox[InnerBBox["BBOX1"] = 1] = "BBOX1";
2190
+ InnerBBox[InnerBBox["BBOX2"] = 2] = "BBOX2";
2191
+ })(exports.InnerBBox || (exports.InnerBBox = {}));
2192
+ const formatTwoBBox = (bbox1, bbox2, format) => {
2193
+ let x11 = bbox1.x1;
2194
+ let x12 = bbox1.x2;
2195
+ let y11 = bbox1.y1;
2196
+ let y12 = bbox1.y2;
2197
+ let x21 = bbox2.x1;
2198
+ let x22 = bbox2.x2;
2199
+ let y21 = bbox2.y1;
2200
+ let y22 = bbox2.y2;
2201
+ if (format) {
2202
+ if (x11 > x12) {
2203
+ [x11, x12] = [x12, x11];
2204
+ }
2205
+ if (y11 > y12) {
2206
+ [y11, y12] = [y12, y11];
2207
+ }
2208
+ if (x21 > x22) {
2209
+ [x21, x22] = [x22, x21];
2210
+ }
2211
+ if (y21 > y22) {
2212
+ [y21, y22] = [y22, y21];
2213
+ }
2492
2214
  }
2493
- interpolate(m2, t) {
2494
- const m = new Matrix();
2495
- m.a = this.a + (m2.a - this.a) * t;
2496
- m.b = this.b + (m2.b - this.b) * t;
2497
- m.c = this.c + (m2.c - this.c) * t;
2498
- m.d = this.d + (m2.d - this.d) * t;
2499
- m.e = this.e + (m2.e - this.e) * t;
2500
- m.f = this.f + (m2.f - this.f) * t;
2501
- return m;
2215
+ return { x11, x12, y11, y12, x21, x22, y21, y22 };
2216
+ };
2217
+ function rectInsideAnotherRect(bbox1, bbox2, format) {
2218
+ if (!bbox1 || !bbox2) {
2219
+ return exports.InnerBBox.NONE;
2502
2220
  }
2503
- transformPoint(source, target) {
2504
- const { a, b, c, d, e, f } = this;
2505
- const dt = a * d - b * c;
2506
- const nextA = d / dt;
2507
- const nextB = -b / dt;
2508
- const nextC = -c / dt;
2509
- const nextD = a / dt;
2510
- const nextE = (c * f - d * e) / dt;
2511
- const nextF = -(a * f - b * e) / dt;
2512
- const { x, y } = source;
2513
- target.x = x * nextA + y * nextC + nextE;
2514
- target.y = x * nextB + y * nextD + nextF;
2221
+ const { x11, x12, y11, y12, x21, x22, y21, y22 } = formatTwoBBox(bbox1, bbox2, format);
2222
+ if (x11 > x21 && x12 < x22 && y11 > y21 && y12 < y22) {
2223
+ return exports.InnerBBox.BBOX1;
2515
2224
  }
2516
- onlyTranslate(scale = 1) {
2517
- return this.a === scale && this.b === 0 && this.c === 0 && this.d === scale;
2225
+ if (x21 > x11 && x22 < x12 && y21 > y11 && y22 < y12) {
2226
+ return exports.InnerBBox.BBOX2;
2518
2227
  }
2519
- clone() {
2520
- return new Matrix(this.a, this.b, this.c, this.d, this.e, this.f);
2521
- }
2522
- toTransformAttrs() {
2523
- const a = this.a;
2524
- const b = this.b;
2525
- const c = this.c;
2526
- const d = this.d;
2527
- const e = this.e;
2528
- const f = this.f;
2529
- const delta = a * d - b * c;
2530
- const result = {
2531
- x: e,
2532
- y: f,
2533
- rotateDeg: 0,
2534
- scaleX: 0,
2535
- scaleY: 0,
2536
- skewX: 0,
2537
- skewY: 0
2538
- };
2539
- if (a !== 0 || b !== 0) {
2540
- const r = Math.sqrt(a * a + b * b);
2541
- result.rotateDeg = b > 0 ? Math.acos(a / r) : -Math.acos(a / r);
2542
- result.scaleX = r;
2543
- result.scaleY = delta / r;
2544
- result.skewX = (a * c + b * d) / delta;
2545
- result.skewY = 0;
2546
- }
2547
- else if (c !== 0 || d !== 0) {
2548
- const s = Math.sqrt(c * c + d * d);
2549
- result.rotateDeg = Math.PI / 2 - (d > 0 ? Math.acos(-c / s) : -Math.acos(c / s));
2550
- result.scaleX = delta / s;
2551
- result.scaleY = s;
2552
- result.skewX = 0;
2553
- result.skewY = (a * c + b * d) / delta;
2554
- }
2555
- else ;
2556
- result.rotateDeg = radianToDegree(result.rotateDeg);
2557
- return result;
2228
+ return exports.InnerBBox.NONE;
2229
+ }
2230
+ function isRectIntersect(bbox1, bbox2, format) {
2231
+ if (bbox1 && bbox2) {
2232
+ if (!format) {
2233
+ if (bbox1.x1 > bbox2.x2 || bbox1.x2 < bbox2.x1 || bbox1.y1 > bbox2.y2 || bbox1.y2 < bbox2.y1) {
2234
+ return false;
2235
+ }
2236
+ return true;
2237
+ }
2238
+ const { x11, x12, y11, y12, x21, x22, y21, y22 } = formatTwoBBox(bbox1, bbox2, true);
2239
+ if (x11 > x22 || x12 < x21 || y11 > y22 || y12 < y21) {
2240
+ return false;
2241
+ }
2242
+ return true;
2558
2243
  }
2244
+ return true;
2559
2245
  }
2560
- function normalTransform(out, origin, x, y, scaleX, scaleY, angle, rotateCenter) {
2561
- const oa = origin.a;
2562
- const ob = origin.b;
2563
- const oc = origin.c;
2564
- const od = origin.d;
2565
- const oe = origin.e;
2566
- const of = origin.f;
2567
- const cosTheta = cos(angle);
2568
- const sinTheta = sin(angle);
2569
- let rotateCenterX;
2570
- let rotateCenterY;
2571
- if (rotateCenter) {
2572
- rotateCenterX = rotateCenter[0];
2573
- rotateCenterY = rotateCenter[1];
2246
+ function pointInRect(point, bbox, format) {
2247
+ if (!bbox) {
2248
+ return true;
2574
2249
  }
2575
- else {
2576
- rotateCenterX = x;
2577
- rotateCenterY = y;
2250
+ if (!format) {
2251
+ return point.x >= bbox.x1 && point.x <= bbox.x2 && point.y >= bbox.y1 && point.y <= bbox.y2;
2578
2252
  }
2579
- const offsetX = rotateCenterX - x;
2580
- const offsetY = rotateCenterY - y;
2581
- const a1 = oa * cosTheta + oc * sinTheta;
2582
- const b1 = ob * cosTheta + od * sinTheta;
2583
- const c1 = oc * cosTheta - oa * sinTheta;
2584
- const d1 = od * cosTheta - ob * sinTheta;
2585
- out.a = scaleX * a1;
2586
- out.b = scaleX * b1;
2587
- out.c = scaleY * c1;
2588
- out.d = scaleY * d1;
2589
- out.e = oe + oa * rotateCenterX + oc * rotateCenterY - a1 * offsetX - c1 * offsetY;
2590
- out.f = of + ob * rotateCenterX + od * rotateCenterY - b1 * offsetX - d1 * offsetY;
2591
- }
2592
-
2593
- class LRU {
2594
- constructor() {
2595
- this.CLEAN_THRESHOLD = 1e3;
2596
- this.L_TIME = 1000;
2597
- this.R_COUNT = 1;
2598
- this.R_TIMESTAMP_MAX_SIZE = 20;
2253
+ let x11 = bbox.x1;
2254
+ let x12 = bbox.x2;
2255
+ let y11 = bbox.y1;
2256
+ let y12 = bbox.y2;
2257
+ if (x11 > x12) {
2258
+ [x11, x12] = [x12, x11];
2599
2259
  }
2600
- clearCache(cache, params) {
2601
- const { CLEAN_THRESHOLD = this.CLEAN_THRESHOLD, L_TIME = this.L_TIME, R_COUNT = this.R_COUNT } = params;
2602
- if (cache.size < CLEAN_THRESHOLD) {
2603
- return 0;
2604
- }
2605
- let clearNum = 0;
2606
- const clear = (key) => {
2607
- clearNum++;
2608
- cache.delete(key);
2609
- };
2610
- const now = Date.now();
2611
- cache.forEach((item, key) => {
2612
- if (item.timestamp.length < R_COUNT) {
2613
- return clear(key);
2260
+ if (y11 > y12) {
2261
+ [y11, y12] = [y12, y11];
2262
+ }
2263
+ return point.x >= x11 && point.x <= x12 && point.y >= y11 && point.y <= y12;
2264
+ }
2265
+ function getProjectionRadius(checkAxis, axis) {
2266
+ return Math.abs(axis[0] * checkAxis[0] + axis[1] * checkAxis[1]);
2267
+ }
2268
+ function rotatePoint({ x, y }, rad, origin = { x: 0, y: 0 }) {
2269
+ return {
2270
+ x: (x - origin.x) * Math.cos(rad) - (y - origin.y) * Math.sin(rad) + origin.x,
2271
+ y: (x - origin.x) * Math.sin(rad) + (y - origin.y) * Math.cos(rad) + origin.y
2272
+ };
2273
+ }
2274
+ function getCenterPoint(box) {
2275
+ return {
2276
+ x: (box.x1 + box.x2) / 2,
2277
+ y: (box.y1 + box.y2) / 2
2278
+ };
2279
+ }
2280
+ function toRect(box, isDeg) {
2281
+ const deg = isDeg ? degreeToRadian(box.angle) : box.angle;
2282
+ const cp = getCenterPoint(box);
2283
+ return [
2284
+ rotatePoint({
2285
+ x: box.x1,
2286
+ y: box.y1
2287
+ }, deg, cp),
2288
+ rotatePoint({
2289
+ x: box.x2,
2290
+ y: box.y1
2291
+ }, deg, cp),
2292
+ rotatePoint({
2293
+ x: box.x2,
2294
+ y: box.y2
2295
+ }, deg, cp),
2296
+ rotatePoint({
2297
+ x: box.x1,
2298
+ y: box.y2
2299
+ }, deg, cp)
2300
+ ];
2301
+ }
2302
+ function isRotateAABBIntersect(box1, box2, isDeg = false, ctx) {
2303
+ const rect1 = toRect(box1, isDeg);
2304
+ const rect2 = toRect(box2, isDeg);
2305
+ const vector = (start, end) => {
2306
+ return [end.x - start.x, end.y - start.y];
2307
+ };
2308
+ if (ctx) {
2309
+ ctx.save();
2310
+ ctx.fillStyle = 'red';
2311
+ ctx.globalAlpha = 0.6;
2312
+ rect1.forEach((item, index) => {
2313
+ if (index === 0) {
2314
+ ctx.moveTo(item.x, item.y);
2614
2315
  }
2615
- let useCount = 0;
2616
- while (now - item.timestamp[item.timestamp.length - 1 - useCount] < L_TIME) {
2617
- useCount++;
2618
- if (useCount >= R_COUNT) {
2619
- break;
2620
- }
2316
+ else {
2317
+ ctx.lineTo(item.x, item.y);
2621
2318
  }
2622
- if (useCount < R_COUNT) {
2623
- return clear(key);
2319
+ });
2320
+ ctx.fill();
2321
+ ctx.restore();
2322
+ ctx.save();
2323
+ ctx.fillStyle = 'green';
2324
+ ctx.globalAlpha = 0.6;
2325
+ rect2.forEach((item, index) => {
2326
+ if (index === 0) {
2327
+ ctx.moveTo(item.x, item.y);
2624
2328
  }
2625
- while (now - item.timestamp[0] > L_TIME) {
2626
- item.timestamp.shift();
2329
+ else {
2330
+ ctx.lineTo(item.x, item.y);
2627
2331
  }
2628
- return;
2629
2332
  });
2630
- return clearNum;
2631
- }
2632
- addLimitedTimestamp(cacheItem, t, params) {
2633
- const { R_TIMESTAMP_MAX_SIZE = this.R_TIMESTAMP_MAX_SIZE } = params;
2634
- if (cacheItem.timestamp.length > R_TIMESTAMP_MAX_SIZE) {
2635
- cacheItem.timestamp.shift();
2636
- }
2637
- cacheItem.timestamp.push(t);
2333
+ ctx.fill();
2334
+ ctx.restore();
2638
2335
  }
2639
- clearTimeStamp(cache, params) {
2640
- const { L_TIME = this.L_TIME } = params;
2641
- const now = Date.now();
2642
- cache.forEach(item => {
2643
- while (now - item.timestamp[0] > L_TIME) {
2644
- item.timestamp.shift();
2645
- }
2646
- });
2336
+ const p1 = getCenterPoint(box1);
2337
+ const p2 = getCenterPoint(box2);
2338
+ ctx && ctx.fillRect(p1.x, p1.y, 2, 2);
2339
+ ctx && ctx.fillRect(p2.x, p2.y, 2, 2);
2340
+ const vp1p2 = vector(p1, p2);
2341
+ const AB = vector(rect1[0], rect1[1]);
2342
+ const BC = vector(rect1[1], rect1[2]);
2343
+ const A1B1 = vector(rect2[0], rect2[1]);
2344
+ const B1C1 = vector(rect2[1], rect2[2]);
2345
+ const deg11 = isDeg ? degreeToRadian(box1.angle) : box1.angle;
2346
+ let deg12 = isDeg ? degreeToRadian(90 - box1.angle) : box1.angle + halfPi;
2347
+ const deg21 = isDeg ? degreeToRadian(box2.angle) : box2.angle;
2348
+ let deg22 = isDeg ? degreeToRadian(90 - box2.angle) : box2.angle + halfPi;
2349
+ if (deg12 > pi2) {
2350
+ deg12 -= pi2;
2647
2351
  }
2648
- clearItemTimestamp(cacheItem, params) {
2649
- const { L_TIME = this.L_TIME } = params;
2650
- const now = Date.now();
2651
- while (now - cacheItem.timestamp[0] > L_TIME) {
2652
- cacheItem.timestamp.shift();
2653
- }
2352
+ if (deg22 > pi2) {
2353
+ deg22 -= pi2;
2654
2354
  }
2355
+ const isCover = (checkAxisRadius, deg, targetAxis1, targetAxis2) => {
2356
+ const checkAxis = [Math.cos(deg), Math.sin(deg)];
2357
+ const targetAxisRadius = (getProjectionRadius(checkAxis, targetAxis1) + getProjectionRadius(checkAxis, targetAxis2)) / 2;
2358
+ const centerPointRadius = getProjectionRadius(checkAxis, vp1p2);
2359
+ return checkAxisRadius + targetAxisRadius > centerPointRadius;
2360
+ };
2361
+ return (isCover((box1.x2 - box1.x1) / 2, deg11, A1B1, B1C1) &&
2362
+ isCover((box1.y2 - box1.y1) / 2, deg12, A1B1, B1C1) &&
2363
+ isCover((box2.x2 - box2.x1) / 2, deg21, AB, BC) &&
2364
+ isCover((box2.y2 - box2.y1) / 2, deg22, AB, BC));
2655
2365
  }
2656
2366
 
2657
- function hslToRgb(h, s, l) {
2658
- s /= 100;
2659
- l /= 100;
2660
- const c = (1 - Math.abs(2 * l - 1)) * s;
2661
- const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
2662
- const m = l - c / 2;
2663
- let r = 0;
2664
- let g = 0;
2665
- let b = 0;
2666
- if (0 <= h && h < 60) {
2667
- r = c;
2668
- g = x;
2669
- b = 0;
2670
- }
2671
- else if (60 <= h && h < 120) {
2672
- r = x;
2673
- g = c;
2674
- b = 0;
2675
- }
2676
- else if (120 <= h && h < 180) {
2677
- r = 0;
2678
- g = c;
2679
- b = x;
2680
- }
2681
- else if (180 <= h && h < 240) {
2682
- r = 0;
2683
- g = x;
2684
- b = c;
2685
- }
2686
- else if (240 <= h && h < 300) {
2687
- r = x;
2688
- g = 0;
2689
- b = c;
2690
- }
2691
- else if (300 <= h && h < 360) {
2692
- r = c;
2693
- g = 0;
2694
- b = x;
2695
- }
2696
- r = Math.round((r + m) * 255);
2697
- g = Math.round((g + m) * 255);
2698
- b = Math.round((b + m) * 255);
2699
- return { r, g, b };
2367
+ let x1;
2368
+ let y1;
2369
+ let x2;
2370
+ let y2;
2371
+ function getAABBFromPoints(points) {
2372
+ (x1 = Infinity), (y1 = Infinity), (x2 = -Infinity), (y2 = -Infinity);
2373
+ points.forEach(point => {
2374
+ if (x1 > point.x) {
2375
+ x1 = point.x;
2376
+ }
2377
+ if (x2 < point.x) {
2378
+ x2 = point.x;
2379
+ }
2380
+ if (y1 > point.y) {
2381
+ y1 = point.y;
2382
+ }
2383
+ if (y2 < point.y) {
2384
+ y2 = point.y;
2385
+ }
2386
+ });
2387
+ return { x1, y1, x2, y2 };
2700
2388
  }
2701
-
2702
- function rgbToHsl(r, g, b) {
2703
- r /= 255;
2704
- g /= 255;
2705
- b /= 255;
2706
- const cMin = Math.min(r, g, b);
2707
- const cMax = Math.max(r, g, b);
2708
- const delta = cMax - cMin;
2709
- let h = 0;
2710
- let s = 0;
2711
- let l = 0;
2712
- if (delta === 0) {
2713
- h = 0;
2714
- }
2715
- else if (cMax === r) {
2716
- h = ((g - b) / delta) % 6;
2389
+ function pointInAABB(point, aabb) {
2390
+ return pointInRect(point, aabb, false);
2391
+ }
2392
+ function unionAABB(bounds1, bounds2, buffer = 3, format = false) {
2393
+ let x11 = bounds1.x1;
2394
+ let x12 = bounds1.x2;
2395
+ let y11 = bounds1.y1;
2396
+ let y12 = bounds1.y2;
2397
+ let x21 = bounds2.x1;
2398
+ let x22 = bounds2.x2;
2399
+ let y21 = bounds2.y1;
2400
+ let y22 = bounds2.y2;
2401
+ if (format) {
2402
+ let temp;
2403
+ if (x11 > x12) {
2404
+ temp = x11;
2405
+ x11 = x12;
2406
+ x12 = temp;
2407
+ }
2408
+ if (y11 > y12) {
2409
+ temp = y11;
2410
+ y11 = y12;
2411
+ y12 = temp;
2412
+ }
2413
+ if (x21 > x22) {
2414
+ temp = x21;
2415
+ x21 = x22;
2416
+ x22 = temp;
2417
+ }
2418
+ if (y21 > y22) {
2419
+ temp = y21;
2420
+ y21 = y22;
2421
+ y22 = temp;
2422
+ }
2717
2423
  }
2718
- else if (cMax === g) {
2719
- h = (b - r) / delta + 2;
2424
+ if (x11 >= x22 || x12 <= x21 || y11 >= y22 || y12 <= y21) {
2425
+ return [bounds1, bounds2];
2720
2426
  }
2721
- else {
2722
- h = (r - g) / delta + 4;
2427
+ const area1 = (x12 - x11 + buffer * 2) * (y12 - y11 + buffer * 2);
2428
+ const area2 = (x22 - x21 + buffer * 2) * (y22 - y21 + buffer * 2);
2429
+ const x1 = Math.min(x11, x21);
2430
+ const y1 = Math.min(y11, y21);
2431
+ const x2 = Math.max(x12, x22);
2432
+ const y2 = Math.max(y12, y22);
2433
+ const unionArea = (x2 - x1) * (y2 - y1);
2434
+ if (area1 + area2 > unionArea) {
2435
+ return [{ x1, x2, y1, y2 }];
2723
2436
  }
2724
- h = Math.round(h * 60);
2725
- if (h < 0) {
2726
- h += 360;
2437
+ return [bounds1, bounds2];
2438
+ }
2439
+ function mergeAABB(boundsList) {
2440
+ const nextList = [];
2441
+ function _merge(baseBound, list) {
2442
+ const l = [];
2443
+ list.forEach(b => {
2444
+ let arr;
2445
+ if ((arr = unionAABB(baseBound, b)).length > 1) {
2446
+ l.push(b);
2447
+ return;
2448
+ }
2449
+ baseBound = arr[0];
2450
+ });
2451
+ nextList.push(baseBound);
2452
+ l.length && _merge(l[0], l.slice(1));
2727
2453
  }
2728
- l = (cMax + cMin) / 2;
2729
- s = delta === 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));
2730
- s = +(s * 100).toFixed(1);
2731
- l = +(l * 100).toFixed(1);
2454
+ _merge(boundsList[0], boundsList.slice(1));
2455
+ return nextList;
2456
+ }
2457
+
2458
+ let dirX;
2459
+ let dirY;
2460
+ let normalX;
2461
+ let normalY;
2462
+ let len;
2463
+ let lineWidthDiv2;
2464
+ let width;
2465
+ let height;
2466
+ function getOBBFromLine(point1, point2, lineWidth) {
2467
+ dirX = point2.x - point1.x;
2468
+ dirY = point2.y - point1.y;
2469
+ (normalX = dirY), (normalY = -dirX);
2470
+ width = len = Math.sqrt(normalX * normalX + normalY * normalY);
2471
+ height = lineWidth;
2472
+ normalX /= len;
2473
+ normalY /= len;
2474
+ lineWidthDiv2 = lineWidth / 2;
2475
+ dirX = lineWidthDiv2 * normalX;
2476
+ dirY = lineWidthDiv2 * normalY;
2477
+ const point11 = { x: point1.x + dirX, y: point1.y + dirY };
2478
+ const point12 = { x: point1.x - dirX, y: point1.y - dirY };
2479
+ const point13 = { x: point2.x + dirX, y: point2.y + dirY };
2480
+ const point14 = { x: point2.x - dirX, y: point2.y - dirY };
2732
2481
  return {
2733
- h,
2734
- s,
2735
- l
2482
+ point1: point11,
2483
+ point2: point12,
2484
+ point3: point13,
2485
+ point4: point14,
2486
+ width,
2487
+ height,
2488
+ left: Math.min(point1.x, point2.x) - Math.abs(dirX),
2489
+ top: Math.min(point1.y, point2.y) - Math.abs(dirY)
2736
2490
  };
2737
2491
  }
2492
+ const point1 = { x: 0, y: 0 };
2493
+ const point2 = { x: 0, y: 0 };
2494
+ function pointInOBB(point, obb) {
2495
+ point1.x = (obb.point1.x + obb.point2.x) / 2;
2496
+ point1.y = (obb.point1.y + obb.point2.y) / 2;
2497
+ point2.x = (obb.point3.x + obb.point4.x) / 2;
2498
+ point2.y = (obb.point3.y + obb.point4.y) / 2;
2499
+ return pointInLine(point, point1, point2, obb.height);
2500
+ }
2501
+ function pointInLine(point, point1, point2, lineWidth) {
2502
+ return lengthFromPointToLine(point, point1, point2) <= lineWidth / 2 && pointBetweenLine(point, point1, point2);
2503
+ }
2504
+ const dir1 = { x: 0, y: 0 };
2505
+ const dir2 = { x: 0, y: 0 };
2506
+ const normal = { x: 0, y: 0 };
2507
+ function pointBetweenLine(point, point1, point2) {
2508
+ dir1.x = point1.x - point.x;
2509
+ dir1.y = point1.y - point.y;
2510
+ dir2.x = point2.x - point.x;
2511
+ dir2.y = point2.y - point.y;
2512
+ normal.x = point1.y - point2.y;
2513
+ normal.y = point2.x - point1.x;
2514
+ return crossProductPoint(dir1, normal) * crossProductPoint(dir2, normal) < 0;
2515
+ }
2738
2516
 
2739
- const REG_HEX = /^#([0-9a-f]{3,8})$/;
2740
- const DEFAULT_COLORS_OPACITY = {
2741
- transparent: 0xffffff00
2742
- };
2743
- const DEFAULT_COLORS = {
2744
- aliceblue: 0xf0f8ff,
2745
- antiquewhite: 0xfaebd7,
2746
- aqua: 0x00ffff,
2747
- aquamarine: 0x7fffd4,
2748
- azure: 0xf0ffff,
2749
- beige: 0xf5f5dc,
2750
- bisque: 0xffe4c4,
2751
- black: 0x000000,
2752
- blanchedalmond: 0xffebcd,
2753
- blue: 0x0000ff,
2754
- blueviolet: 0x8a2be2,
2755
- brown: 0xa52a2a,
2756
- burlywood: 0xdeb887,
2757
- cadetblue: 0x5f9ea0,
2758
- chartreuse: 0x7fff00,
2759
- chocolate: 0xd2691e,
2760
- coral: 0xff7f50,
2761
- cornflowerblue: 0x6495ed,
2762
- cornsilk: 0xfff8dc,
2763
- crimson: 0xdc143c,
2764
- cyan: 0x00ffff,
2765
- darkblue: 0x00008b,
2766
- darkcyan: 0x008b8b,
2767
- darkgoldenrod: 0xb8860b,
2768
- darkgray: 0xa9a9a9,
2769
- darkgreen: 0x006400,
2770
- darkgrey: 0xa9a9a9,
2771
- darkkhaki: 0xbdb76b,
2772
- darkmagenta: 0x8b008b,
2773
- darkolivegreen: 0x556b2f,
2774
- darkorange: 0xff8c00,
2775
- darkorchid: 0x9932cc,
2776
- darkred: 0x8b0000,
2777
- darksalmon: 0xe9967a,
2778
- darkseagreen: 0x8fbc8f,
2779
- darkslateblue: 0x483d8b,
2780
- darkslategray: 0x2f4f4f,
2781
- darkslategrey: 0x2f4f4f,
2782
- darkturquoise: 0x00ced1,
2783
- darkviolet: 0x9400d3,
2784
- deeppink: 0xff1493,
2785
- deepskyblue: 0x00bfff,
2786
- dimgray: 0x696969,
2787
- dimgrey: 0x696969,
2788
- dodgerblue: 0x1e90ff,
2789
- firebrick: 0xb22222,
2790
- floralwhite: 0xfffaf0,
2791
- forestgreen: 0x228b22,
2792
- fuchsia: 0xff00ff,
2793
- gainsboro: 0xdcdcdc,
2794
- ghostwhite: 0xf8f8ff,
2795
- gold: 0xffd700,
2796
- goldenrod: 0xdaa520,
2797
- gray: 0x808080,
2798
- green: 0x008000,
2799
- greenyellow: 0xadff2f,
2800
- grey: 0x808080,
2801
- honeydew: 0xf0fff0,
2802
- hotpink: 0xff69b4,
2803
- indianred: 0xcd5c5c,
2804
- indigo: 0x4b0082,
2805
- ivory: 0xfffff0,
2806
- khaki: 0xf0e68c,
2807
- lavender: 0xe6e6fa,
2808
- lavenderblush: 0xfff0f5,
2809
- lawngreen: 0x7cfc00,
2810
- lemonchiffon: 0xfffacd,
2811
- lightblue: 0xadd8e6,
2812
- lightcoral: 0xf08080,
2813
- lightcyan: 0xe0ffff,
2814
- lightgoldenrodyellow: 0xfafad2,
2815
- lightgray: 0xd3d3d3,
2816
- lightgreen: 0x90ee90,
2817
- lightgrey: 0xd3d3d3,
2818
- lightpink: 0xffb6c1,
2819
- lightsalmon: 0xffa07a,
2820
- lightseagreen: 0x20b2aa,
2821
- lightskyblue: 0x87cefa,
2822
- lightslategray: 0x778899,
2823
- lightslategrey: 0x778899,
2824
- lightsteelblue: 0xb0c4de,
2825
- lightyellow: 0xffffe0,
2826
- lime: 0x00ff00,
2827
- limegreen: 0x32cd32,
2828
- linen: 0xfaf0e6,
2829
- magenta: 0xff00ff,
2830
- maroon: 0x800000,
2831
- mediumaquamarine: 0x66cdaa,
2832
- mediumblue: 0x0000cd,
2833
- mediumorchid: 0xba55d3,
2834
- mediumpurple: 0x9370db,
2835
- mediumseagreen: 0x3cb371,
2836
- mediumslateblue: 0x7b68ee,
2837
- mediumspringgreen: 0x00fa9a,
2838
- mediumturquoise: 0x48d1cc,
2839
- mediumvioletred: 0xc71585,
2840
- midnightblue: 0x191970,
2841
- mintcream: 0xf5fffa,
2842
- mistyrose: 0xffe4e1,
2843
- moccasin: 0xffe4b5,
2844
- navajowhite: 0xffdead,
2845
- navy: 0x000080,
2846
- oldlace: 0xfdf5e6,
2847
- olive: 0x808000,
2848
- olivedrab: 0x6b8e23,
2849
- orange: 0xffa500,
2850
- orangered: 0xff4500,
2851
- orchid: 0xda70d6,
2852
- palegoldenrod: 0xeee8aa,
2853
- palegreen: 0x98fb98,
2854
- paleturquoise: 0xafeeee,
2855
- palevioletred: 0xdb7093,
2856
- papayawhip: 0xffefd5,
2857
- peachpuff: 0xffdab9,
2858
- peru: 0xcd853f,
2859
- pink: 0xffc0cb,
2860
- plum: 0xdda0dd,
2861
- powderblue: 0xb0e0e6,
2862
- purple: 0x800080,
2863
- rebeccapurple: 0x663399,
2864
- red: 0xff0000,
2865
- rosybrown: 0xbc8f8f,
2866
- royalblue: 0x4169e1,
2867
- saddlebrown: 0x8b4513,
2868
- salmon: 0xfa8072,
2869
- sandybrown: 0xf4a460,
2870
- seagreen: 0x2e8b57,
2871
- seashell: 0xfff5ee,
2872
- sienna: 0xa0522d,
2873
- silver: 0xc0c0c0,
2874
- skyblue: 0x87ceeb,
2875
- slateblue: 0x6a5acd,
2876
- slategray: 0x708090,
2877
- slategrey: 0x708090,
2878
- snow: 0xfffafa,
2879
- springgreen: 0x00ff7f,
2880
- steelblue: 0x4682b4,
2881
- tan: 0xd2b48c,
2882
- teal: 0x008080,
2883
- thistle: 0xd8bfd8,
2884
- tomato: 0xff6347,
2885
- turquoise: 0x40e0d0,
2886
- violet: 0xee82ee,
2887
- wheat: 0xf5deb3,
2888
- white: 0xffffff,
2889
- whitesmoke: 0xf5f5f5,
2890
- yellow: 0xffff00,
2891
- yellowgreen: 0x9acd32
2892
- };
2893
- function hex(value) {
2894
- value = Math.max(0, Math.min(255, Math.round(value) || 0));
2895
- return (value < 16 ? '0' : '') + value.toString(16);
2896
- }
2897
- function rgb(value) {
2898
- if (isNumber(value)) {
2899
- return new RGB(value >> 16, (value >> 8) & 0xff, value & 0xff, 1);
2900
- }
2901
- else if (isArray(value)) {
2902
- return new RGB(value[0], value[1], value[2]);
2903
- }
2904
- return new RGB(255, 255, 255);
2905
- }
2906
- function rgba(value) {
2907
- if (isNumber(value)) {
2908
- return new RGB(value >>> 24, (value >>> 16) & 0xff, (value >>> 8) & 0xff, value & 0xff);
2909
- }
2910
- else if (isArray(value)) {
2911
- return new RGB(value[0], value[1], value[2], value[3]);
2912
- }
2913
- return new RGB(255, 255, 255, 1);
2914
- }
2915
- function SRGBToLinear(c) {
2916
- return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
2917
- }
2918
- function LinearToSRGB(c) {
2919
- return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
2517
+ function getContextFont$1({ fontStyle, fontVariant, fontWeight, fontSize, fontFamily }) {
2518
+ return ('' +
2519
+ (fontStyle ? fontStyle + ' ' : '') +
2520
+ (fontVariant ? fontVariant + ' ' : '') +
2521
+ (fontWeight ? fontWeight + ' ' : '') +
2522
+ (fontSize || 12) +
2523
+ 'px ' +
2524
+ (fontFamily ? fontFamily : 'sans-serif'));
2920
2525
  }
2921
- const setHex = (formatValue, forceHex) => {
2922
- const isHex = REG_HEX.exec(formatValue);
2923
- if (forceHex || isHex) {
2924
- const hex = parseInt(isHex[1], 16);
2925
- const hexLength = isHex[1].length;
2926
- if (hexLength === 3) {
2927
- return new RGB(((hex >> 8) & 0xf) + (((hex >> 8) & 0xf) << 4), ((hex >> 4) & 0xf) + (((hex >> 4) & 0xf) << 4), (hex & 0xf) + ((hex & 0xf) << 4), 1);
2928
- }
2929
- if (hexLength === 6) {
2930
- return rgb(hex);
2931
- }
2932
- else if (hexLength === 8) {
2933
- return new RGB((hex >> 24) & 0xff, (hex >> 16) & 0xff, (hex >> 8) & 0xff, (hex & 0xff) / 0xff);
2526
+ class GraphicUtil {
2527
+ constructor(canvas) {
2528
+ this.canvas = canvas;
2529
+ if (canvas) {
2530
+ this.ctx = canvas.getContext('2d');
2934
2531
  }
2935
- return null;
2936
2532
  }
2937
- return undefined;
2938
- };
2939
- class Color {
2940
- static Brighter(source, b = 1) {
2941
- if (b === 1) {
2942
- return source;
2533
+ setCanvas(canvas) {
2534
+ this.canvas = canvas;
2535
+ if (canvas) {
2536
+ this.ctx = canvas.getContext('2d');
2943
2537
  }
2944
- return new Color(source).brighter(b).toRGBA();
2945
2538
  }
2946
- static SetOpacity(source, o = 1) {
2947
- if (o === 1) {
2948
- return source;
2539
+ measureText(tc) {
2540
+ if (!this.canvas) {
2541
+ console.warn('[warn] no canvas, measureText might be not accurate');
2542
+ return this.estimate(tc);
2949
2543
  }
2950
- return new Color(source).setOpacity(o).toRGBA();
2544
+ return this.measureTextByCanvas(tc);
2951
2545
  }
2952
- static getColorBrightness(source, model = 'hsl') {
2953
- const color = source instanceof Color ? source : new Color(source);
2954
- switch (model) {
2955
- case 'hsv':
2956
- return color.getHSVBrightness();
2957
- case 'hsl':
2958
- return color.getHSLBrightness();
2959
- case 'lum':
2960
- return color.getLuminance();
2961
- case 'lum2':
2962
- return color.getLuminance2();
2963
- case 'lum3':
2964
- return color.getLuminance3();
2965
- default:
2966
- return color.getHSVBrightness();
2546
+ measureTextByCanvas(tc) {
2547
+ if (!this.ctx) {
2548
+ console.error('[error!!!]measureTextByCanvas can not be called without canvas');
2549
+ return { width: -1, height: tc.fontSize };
2967
2550
  }
2551
+ this.ctx.font = getContextFont$1(tc);
2552
+ return {
2553
+ width: this.ctx.measureText(tc.text).width,
2554
+ height: tc.fontSize
2555
+ };
2968
2556
  }
2969
- static parseColorString(value) {
2970
- if (isValid(DEFAULT_COLORS_OPACITY[value])) {
2971
- return rgba(DEFAULT_COLORS_OPACITY[value]);
2972
- }
2973
- if (isValid(DEFAULT_COLORS[value])) {
2974
- return rgb(DEFAULT_COLORS[value]);
2975
- }
2976
- const formatValue = `${value}`.trim().toLowerCase();
2977
- const hexRes = setHex(formatValue);
2978
- if (hexRes !== undefined) {
2979
- return hexRes;
2980
- }
2981
- if (/^(rgb|RGB|rgba|RGBA)/.test(formatValue)) {
2982
- const aColor = formatValue.replace(/(?:\(|\)|rgba|RGBA|rgb|RGB)*/g, '').split(',');
2983
- return new RGB(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10), parseFloat(aColor[3]));
2984
- }
2985
- if (/^(hsl|HSL|hsla|HSLA)/.test(formatValue)) {
2986
- const aColor = formatValue.replace(/(?:\(|\)|hsla|HSLA|hsl|HSL)*/g, '').split(',');
2987
- const rgb = hslToRgb(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10));
2988
- return new RGB(rgb.r, rgb.g, rgb.b, parseFloat(aColor[3]));
2557
+ estimate({ text, fontSize }) {
2558
+ let eCharLen = 0;
2559
+ let cCharLen = 0;
2560
+ for (let i = 0; i < text.length; i++) {
2561
+ text.charCodeAt(i) < 128 ? eCharLen++ : cCharLen++;
2989
2562
  }
2990
- return;
2563
+ return {
2564
+ width: ~~(0.8 * eCharLen * fontSize + cCharLen * fontSize),
2565
+ height: fontSize
2566
+ };
2991
2567
  }
2992
- constructor(value) {
2993
- const color = Color.parseColorString(value);
2994
- if (color) {
2995
- this.color = color;
2568
+ static getDefaultUtils(canvas) {
2569
+ if (!GraphicUtil.instance) {
2570
+ GraphicUtil.instance = new GraphicUtil(canvas);
2996
2571
  }
2997
- else {
2998
- console.warn(`Warn: 传入${value}无法解析为Color`);
2999
- this.color = new RGB(255, 255, 255);
2572
+ return GraphicUtil.instance;
2573
+ }
2574
+ }
2575
+
2576
+ const EPSILON = 1e-8;
2577
+ function lineIntersectPolygon(a1x, a1y, a2x, a2y, points) {
2578
+ for (let i = 0, p2 = points[points.length - 1]; i < points.length; i++) {
2579
+ const p = points[i];
2580
+ if (isIntersect([a1x, a1y], [a2x, a2y], [p.x, p.y], [p2.x, p2.y])) {
2581
+ return true;
3000
2582
  }
2583
+ p2 = p;
3001
2584
  }
3002
- toRGBA() {
3003
- return this.color.formatRgb();
2585
+ return false;
2586
+ }
2587
+ function polygonContainPoint(points, x, y) {
2588
+ let w = 0;
2589
+ let p = points[0];
2590
+ if (!p) {
2591
+ return false;
3004
2592
  }
3005
- toString() {
3006
- return this.color.formatRgb();
2593
+ for (let i = 1; i < points.length; i++) {
2594
+ const p2 = points[i];
2595
+ w += isPointInLine(p.x, p.y, p2.x, p2.y, x, y);
2596
+ p = p2;
3007
2597
  }
3008
- toHex() {
3009
- return this.color.formatHex();
2598
+ const p0 = points[0];
2599
+ if (!isAroundEqual(p.x, p0.x) || !isAroundEqual(p.y, p0.y)) {
2600
+ w += isPointInLine(p.x, p.y, p0.x, p0.y, x, y);
3010
2601
  }
3011
- toHsl() {
3012
- return this.color.formatHsl();
2602
+ return w !== 0;
2603
+ }
2604
+ function isPointInLine(x0, y0, x1, y1, x, y) {
2605
+ if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
2606
+ return 0;
3013
2607
  }
3014
- brighter(k) {
3015
- const { r, g, b } = this.color;
3016
- this.color.r = Math.max(0, Math.min(255, Math.floor(r * k)));
3017
- this.color.g = Math.max(0, Math.min(255, Math.floor(g * k)));
3018
- this.color.b = Math.max(0, Math.min(255, Math.floor(b * k)));
3019
- return this;
2608
+ if (y1 === y0) {
2609
+ return 0;
3020
2610
  }
3021
- add(color) {
3022
- const { r, g, b } = this.color;
3023
- this.color.r += Math.min(255, r + color.color.r);
3024
- this.color.g += Math.min(255, g + color.color.g);
3025
- this.color.b += Math.min(255, b + color.color.b);
3026
- return this;
3027
- }
3028
- sub(color) {
3029
- this.color.r = Math.max(0, this.color.r - color.color.r);
3030
- this.color.g = Math.max(0, this.color.g - color.color.g);
3031
- this.color.b = Math.max(0, this.color.b - color.color.b);
3032
- return this;
3033
- }
3034
- multiply(color) {
3035
- const { r, g, b } = this.color;
3036
- this.color.r = Math.max(0, Math.min(255, Math.floor(r * color.color.r)));
3037
- this.color.g = Math.max(0, Math.min(255, Math.floor(g * color.color.g)));
3038
- this.color.b = Math.max(0, Math.min(255, Math.floor(b * color.color.b)));
3039
- return this;
3040
- }
3041
- getHSVBrightness() {
3042
- return Math.max(this.color.r, this.color.g, this.color.b) / 255;
3043
- }
3044
- getHSLBrightness() {
3045
- return ((Math.max(this.color.r, this.color.g, this.color.b) / 255 +
3046
- Math.min(this.color.r, this.color.g, this.color.b) / 255) *
3047
- 0.5);
3048
- }
3049
- setHsl(h, s, l) {
3050
- const opacity = this.color.opacity;
3051
- const hsl = rgbToHsl(this.color.r, this.color.g, this.color.b);
3052
- const rgb = hslToRgb(isNil(h) ? hsl.h : clamp(h, 0, 360), isNil(s) ? hsl.s : s >= 0 && s <= 1 ? s * 100 : s, isNil(l) ? hsl.l : l <= 1 && l >= 0 ? l * 100 : l);
3053
- this.color = new RGB(rgb.r, rgb.g, rgb.b, opacity);
3054
- return this;
3055
- }
3056
- setRGB(r, g, b) {
3057
- !isNil(r) && (this.color.r = r);
3058
- !isNil(g) && (this.color.g = g);
3059
- !isNil(b) && (this.color.b = b);
3060
- return this;
3061
- }
3062
- setHex(value) {
3063
- const formatValue = `${value}`.trim().toLowerCase();
3064
- const res = setHex(formatValue, true);
3065
- return res !== null && res !== void 0 ? res : this;
3066
- }
3067
- setColorName(name) {
3068
- const hex = DEFAULT_COLORS[name.toLowerCase()];
3069
- if (typeof hex !== 'undefined') {
3070
- this.setHex(hex);
3071
- }
3072
- else {
3073
- console.warn('THREE.Color: Unknown color ' + name);
3074
- }
3075
- return this;
3076
- }
3077
- setScalar(scalar) {
3078
- this.color.r = scalar;
3079
- this.color.g = scalar;
3080
- this.color.b = scalar;
3081
- return this;
3082
- }
3083
- setOpacity(o = 1) {
3084
- this.color.opacity = o;
3085
- return this;
3086
- }
3087
- getLuminance() {
3088
- return (0.2126 * this.color.r + 0.7152 * this.color.g + 0.0722 * this.color.b) / 255;
3089
- }
3090
- getLuminance2() {
3091
- return (0.2627 * this.color.r + 0.678 * this.color.g + 0.0593 * this.color.b) / 255;
3092
- }
3093
- getLuminance3() {
3094
- return (0.299 * this.color.r + 0.587 * this.color.g + 0.114 * this.color.b) / 255;
3095
- }
3096
- clone() {
3097
- return new Color(this.color.toString());
3098
- }
3099
- copyGammaToLinear(color, gammaFactor = 2.0) {
3100
- this.color.r = Math.pow(color.color.r, gammaFactor);
3101
- this.color.g = Math.pow(color.color.g, gammaFactor);
3102
- this.color.b = Math.pow(color.color.b, gammaFactor);
3103
- return this;
3104
- }
3105
- copyLinearToGamma(color, gammaFactor = 2.0) {
3106
- const safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
3107
- this.color.r = Math.pow(color.color.r, safeInverse);
3108
- this.color.g = Math.pow(color.color.g, safeInverse);
3109
- this.color.b = Math.pow(color.color.b, safeInverse);
3110
- return this;
3111
- }
3112
- convertGammaToLinear(gammaFactor) {
3113
- this.copyGammaToLinear(this, gammaFactor);
3114
- return this;
3115
- }
3116
- convertLinearToGamma(gammaFactor) {
3117
- this.copyLinearToGamma(this, gammaFactor);
3118
- return this;
3119
- }
3120
- copySRGBToLinear(color) {
3121
- this.color.r = SRGBToLinear(color.color.r);
3122
- this.color.g = SRGBToLinear(color.color.g);
3123
- this.color.b = SRGBToLinear(color.color.b);
3124
- return this;
3125
- }
3126
- copyLinearToSRGB(color) {
3127
- this.color.r = LinearToSRGB(color.color.r);
3128
- this.color.g = LinearToSRGB(color.color.g);
3129
- this.color.b = LinearToSRGB(color.color.b);
3130
- return this;
3131
- }
3132
- convertSRGBToLinear() {
3133
- this.copySRGBToLinear(this);
3134
- return this;
3135
- }
3136
- convertLinearToSRGB() {
3137
- this.copyLinearToSRGB(this);
3138
- return this;
2611
+ const t = (y - y0) / (y1 - y0);
2612
+ let dir = y1 < y0 ? 1 : -1;
2613
+ if (t === 1 || t === 0) {
2614
+ dir = y1 < y0 ? 0.5 : -0.5;
3139
2615
  }
2616
+ const x_ = t * (x1 - x0) + x0;
2617
+ return x_ === x ? Infinity : x_ > x ? dir : 0;
3140
2618
  }
3141
- class RGB {
3142
- constructor(r, g, b, opacity) {
3143
- this.r = isNaN(+r) ? 255 : Math.max(0, Math.min(255, +r));
3144
- this.g = isNaN(+g) ? 255 : Math.max(0, Math.min(255, +g));
3145
- this.b = isNaN(+b) ? 255 : Math.max(0, Math.min(255, +b));
3146
- if (isValid(opacity)) {
3147
- this.opacity = isNaN(+opacity) ? 1 : Math.max(0, Math.min(1, +opacity));
2619
+ function isAroundEqual(a, b) {
2620
+ return Math.abs(a - b) < EPSILON;
2621
+ }
2622
+ function polygonIntersectPolygon(pointsA, pointsB) {
2623
+ for (let i = 0; i < pointsB.length; i++) {
2624
+ if (polygonContainPoint(pointsA, pointsB[i].x, pointsB[i].y)) {
2625
+ return true;
3148
2626
  }
3149
- else {
3150
- this.opacity = 1;
2627
+ if (i > 0 && lineIntersectPolygon(pointsB[i - 1].x, pointsB[i - 1].y, pointsB[i].x, pointsB[i].y, pointsA)) {
2628
+ return true;
3151
2629
  }
3152
2630
  }
3153
- formatHex() {
3154
- return `#${hex(this.r) + hex(this.g) + hex(this.b) + (this.opacity === 1 ? '' : hex(this.opacity * 255))}`;
3155
- }
3156
- formatRgb() {
3157
- const opacity = this.opacity;
3158
- return `${opacity === 1 ? 'rgb(' : 'rgba('}${this.r},${this.g},${this.b}${opacity === 1 ? ')' : `,${opacity})`}`;
2631
+ return false;
2632
+ }
2633
+
2634
+ const calculateAnchorOfArc = (arcAttr, anchorType) => {
2635
+ const { startAngle, endAngle, innerRadius, outerRadius } = arcAttr;
2636
+ let angle = (startAngle + endAngle) / 2;
2637
+ let radius = (innerRadius + outerRadius) / 2;
2638
+ switch (anchorType) {
2639
+ case 'inner-start':
2640
+ angle = startAngle;
2641
+ radius = innerRadius;
2642
+ break;
2643
+ case 'outer-start':
2644
+ angle = startAngle;
2645
+ radius = outerRadius;
2646
+ break;
2647
+ case 'inner-end':
2648
+ angle = endAngle;
2649
+ radius = innerRadius;
2650
+ break;
2651
+ case 'outer-end':
2652
+ angle = endAngle;
2653
+ radius = outerRadius;
2654
+ break;
2655
+ case 'inner-middle':
2656
+ radius = innerRadius;
2657
+ break;
2658
+ case 'outer-middle':
2659
+ radius = outerRadius;
2660
+ break;
3159
2661
  }
3160
- formatHsl() {
3161
- const opacity = this.opacity;
3162
- const { h, s, l } = rgbToHsl(this.r, this.g, this.b);
3163
- return `${opacity === 1 ? 'hsl(' : 'hsla('}${h},${s}%,${l}%${opacity === 1 ? ')' : `,${opacity})`}`;
2662
+ return { angle, radius };
2663
+ };
2664
+
2665
+ function stringWidth(string, ambiguousCharacterIsNarrow = true) {
2666
+ if (typeof string !== 'string' || string.length === 0) {
2667
+ return 0;
3164
2668
  }
3165
- toString() {
3166
- return this.formatHex();
2669
+ string = stripAnsi(string);
2670
+ if (string.length === 0) {
2671
+ return 0;
3167
2672
  }
3168
- }
3169
-
3170
- function hexToRgb(str) {
3171
- let r = '';
3172
- let g = '';
3173
- let b = '';
3174
- const strtIndex = str[0] === '#' ? 1 : 0;
3175
- for (let i = strtIndex; i < str.length; i++) {
3176
- if (str[i] === '#') {
2673
+ string = string.replace(emojiRegex(), ' ');
2674
+ const ambiguousCharacterWidth = ambiguousCharacterIsNarrow ? 1 : 2;
2675
+ let width = 0;
2676
+ for (const character of string) {
2677
+ const codePoint = character.codePointAt(0);
2678
+ if (codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f)) {
3177
2679
  continue;
3178
2680
  }
3179
- if (i < strtIndex + 2) {
3180
- r += str[i];
3181
- }
3182
- else if (i < strtIndex + 4) {
3183
- g += str[i];
2681
+ if (codePoint >= 0x300 && codePoint <= 0x36f) {
2682
+ continue;
3184
2683
  }
3185
- else if (i < strtIndex + 6) {
3186
- b += str[i];
2684
+ const code = eastAsianCharacterInfo(character);
2685
+ switch (code) {
2686
+ case 'F':
2687
+ case 'W':
2688
+ width += 2;
2689
+ break;
2690
+ case 'A':
2691
+ width += ambiguousCharacterWidth;
2692
+ break;
2693
+ default:
2694
+ width += 1;
3187
2695
  }
3188
2696
  }
3189
- const ri = parseInt(r, 16);
3190
- const gi = parseInt(g, 16);
3191
- const bi = parseInt(b, 16);
3192
- return [ri, gi, bi];
3193
- }
3194
-
3195
- function rgbToHex(r, g, b) {
3196
- return Number((1 << 24) + (r << 16) + (g << 8) + b)
3197
- .toString(16)
3198
- .slice(1);
2697
+ return width;
3199
2698
  }
3200
-
3201
- function interpolateRgb(colorA, colorB) {
3202
- const redA = colorA.r;
3203
- const redB = colorB.r;
3204
- const greenA = colorA.g;
3205
- const greenB = colorB.g;
3206
- const blueA = colorA.b;
3207
- const blueB = colorB.b;
3208
- const opacityA = colorA.opacity;
3209
- const opacityB = colorB.opacity;
3210
- return (t) => {
3211
- const r = Math.round(redA * (1 - t) + redB * t);
3212
- const g = Math.round(greenA * (1 - t) + greenB * t);
3213
- const b = Math.round(blueA * (1 - t) + blueB * t);
3214
- const opacity = opacityA * (1 - t) + opacityB * t;
3215
- return new RGB(r, g, b, opacity);
3216
- };
3217
- }
3218
-
3219
- var index = /*#__PURE__*/Object.freeze({
3220
- __proto__: null,
3221
- Color: Color,
3222
- DEFAULT_COLORS: DEFAULT_COLORS,
3223
- RGB: RGB,
3224
- hexToRgb: hexToRgb,
3225
- hslToRgb: hslToRgb,
3226
- interpolateRgb: interpolateRgb,
3227
- rgbToHex: rgbToHex,
3228
- rgbToHsl: rgbToHsl
3229
- });
3230
-
3231
- const parseUint8ToImageData = (buffer, width, height) => {
3232
- const clampBuffer = new Uint8ClampedArray(buffer);
3233
- const flipClampBuffer = new Uint8ClampedArray(buffer.length);
3234
- for (let i = height - 1; i >= 0; i--) {
3235
- for (let j = 0; j < width; j++) {
3236
- const sourceIdx = i * width * 4 + j * 4;
3237
- const targetIdx = (height - i) * width * 4 + j * 4;
3238
- flipClampBuffer[targetIdx] = clampBuffer[sourceIdx];
3239
- flipClampBuffer[targetIdx + 1] = clampBuffer[sourceIdx + 1];
3240
- flipClampBuffer[targetIdx + 2] = clampBuffer[sourceIdx + 2];
3241
- flipClampBuffer[targetIdx + 3] = clampBuffer[sourceIdx + 3];
3242
- }
2699
+ const stripAnsi = (string) => {
2700
+ if (typeof string !== 'string') {
2701
+ throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
3243
2702
  }
3244
- return new ImageData(flipClampBuffer, width, height);
2703
+ return string.replace(ansiRegex(), '');
3245
2704
  };
3246
-
3247
- function sub(out, v1, v2) {
3248
- out[0] = v1[0] - v2[0];
3249
- out[1] = v1[1] - v2[1];
3250
- }
3251
- function isIntersect(left1, right1, left2, right2) {
3252
- let min1 = left1[0];
3253
- let max1 = right1[0];
3254
- let min2 = left2[0];
3255
- let max2 = right2[0];
3256
- if (max1 < min1) {
3257
- [min1, max1] = [max1, min1];
3258
- }
3259
- if (max2 < min2) {
3260
- [max2, min2] = [min2, max2];
3261
- }
3262
- if (max1 < min2 || max2 < min1) {
3263
- return false;
3264
- }
3265
- (min1 = left1[1]), (max1 = right1[1]), (min2 = left2[1]), (max2 = right2[1]);
3266
- if (max1 < min1) {
3267
- [min1, max1] = [max1, min1];
3268
- }
3269
- if (max2 < min2) {
3270
- [max2, min2] = [min2, max2];
3271
- }
3272
- if (max1 < min2 || max2 < min1) {
3273
- return false;
3274
- }
3275
- return true;
3276
- }
3277
- function getIntersectPoint(left1, right1, left2, right2) {
3278
- if (!isIntersect(left1, right1, left2, right2)) {
3279
- return false;
3280
- }
3281
- const dir1 = [0, 0];
3282
- const dir2 = [0, 0];
3283
- const tempVec = [0, 0];
3284
- sub(dir1, right1, left1);
3285
- sub(dir2, right2, left2);
3286
- if (fuzzyEqualVec(dir1, dir2)) {
3287
- return true;
3288
- }
3289
- sub(tempVec, left2, left1);
3290
- const t = crossProduct(tempVec, dir2) / crossProduct(dir1, dir2);
3291
- if (t >= 0 && t <= 1) {
3292
- return [left1[0] + dir1[0] * t, left1[1] + dir1[1] * t];
3293
- }
3294
- return false;
3295
- }
3296
- function getRectIntersect(bbox1, bbox2, format) {
3297
- if (bbox1 === null) {
3298
- return bbox2;
3299
- }
3300
- if (bbox2 === null) {
3301
- return bbox1;
3302
- }
3303
- const { x11, x12, y11, y12, x21, x22, y21, y22 } = formatTwoBBox(bbox1, bbox2, format);
3304
- if (x11 >= x22 || x12 <= x21 || y11 >= y22 || y12 <= y21) {
3305
- return { x1: 0, y1: 0, x2: 0, y2: 0 };
3306
- }
3307
- return { x1: Math.max(x11, x21), y1: Math.max(y11, y21), x2: Math.min(x12, x22), y2: Math.min(y12, y22) };
3308
- }
3309
- exports.InnerBBox = void 0;
3310
- (function (InnerBBox) {
3311
- InnerBBox[InnerBBox["NONE"] = 0] = "NONE";
3312
- InnerBBox[InnerBBox["BBOX1"] = 1] = "BBOX1";
3313
- InnerBBox[InnerBBox["BBOX2"] = 2] = "BBOX2";
3314
- })(exports.InnerBBox || (exports.InnerBBox = {}));
3315
- const formatTwoBBox = (bbox1, bbox2, format) => {
3316
- let x11 = bbox1.x1;
3317
- let x12 = bbox1.x2;
3318
- let y11 = bbox1.y1;
3319
- let y12 = bbox1.y2;
3320
- let x21 = bbox2.x1;
3321
- let x22 = bbox2.x2;
3322
- let y21 = bbox2.y1;
3323
- let y22 = bbox2.y2;
3324
- if (format) {
3325
- if (x11 > x12) {
3326
- [x11, x12] = [x12, x11];
3327
- }
3328
- if (y11 > y12) {
3329
- [y11, y12] = [y12, y11];
3330
- }
3331
- if (x21 > x22) {
3332
- [x21, x22] = [x22, x21];
3333
- }
3334
- if (y21 > y22) {
3335
- [y21, y22] = [y22, y21];
3336
- }
3337
- }
3338
- return { x11, x12, y11, y12, x21, x22, y21, y22 };
2705
+ const ansiRegex = ({ onlyFirst = false } = {}) => {
2706
+ const pattern = [
2707
+ '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
2708
+ '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))'
2709
+ ].join('|');
2710
+ return new RegExp(pattern, onlyFirst ? undefined : 'g');
3339
2711
  };
3340
- function rectInsideAnotherRect(bbox1, bbox2, format) {
3341
- if (!bbox1 || !bbox2) {
3342
- return exports.InnerBBox.NONE;
3343
- }
3344
- const { x11, x12, y11, y12, x21, x22, y21, y22 } = formatTwoBBox(bbox1, bbox2, format);
3345
- if (x11 > x21 && x12 < x22 && y11 > y21 && y12 < y22) {
3346
- return exports.InnerBBox.BBOX1;
3347
- }
3348
- if (x21 > x11 && x22 < x12 && y21 > y11 && y22 < y12) {
3349
- return exports.InnerBBox.BBOX2;
3350
- }
3351
- return exports.InnerBBox.NONE;
3352
- }
3353
- function isRectIntersect(bbox1, bbox2, format) {
3354
- if (bbox1 && bbox2) {
3355
- if (!format) {
3356
- if (bbox1.x1 > bbox2.x2 || bbox1.x2 < bbox2.x1 || bbox1.y1 > bbox2.y2 || bbox1.y2 < bbox2.y1) {
3357
- return false;
3358
- }
3359
- return true;
3360
- }
3361
- const { x11, x12, y11, y12, x21, x22, y21, y22 } = formatTwoBBox(bbox1, bbox2, true);
3362
- if (x11 > x22 || x12 < x21 || y11 > y22 || y12 < y21) {
3363
- return false;
3364
- }
3365
- return true;
2712
+ const eastAsianCharacterInfo = (character) => {
2713
+ let x = character.charCodeAt(0);
2714
+ let y = character.length === 2 ? character.charCodeAt(1) : 0;
2715
+ let codePoint = x;
2716
+ if (0xd800 <= x && x <= 0xdbff && 0xdc00 <= y && y <= 0xdfff) {
2717
+ x &= 0x3ff;
2718
+ y &= 0x3ff;
2719
+ codePoint = (x << 10) | y;
2720
+ codePoint += 0x10000;
3366
2721
  }
3367
- return true;
3368
- }
3369
- function pointInRect(point, bbox, format) {
3370
- if (!bbox) {
3371
- return true;
2722
+ if (0x3000 === codePoint ||
2723
+ (0xff01 <= codePoint && codePoint <= 0xff60) ||
2724
+ (0xffe0 <= codePoint && codePoint <= 0xffe6)) {
2725
+ return 'F';
3372
2726
  }
3373
- if (!format) {
3374
- return point.x >= bbox.x1 && point.x <= bbox.x2 && point.y >= bbox.y1 && point.y <= bbox.y2;
2727
+ if (0x20a9 === codePoint ||
2728
+ (0xff61 <= codePoint && codePoint <= 0xffbe) ||
2729
+ (0xffc2 <= codePoint && codePoint <= 0xffc7) ||
2730
+ (0xffca <= codePoint && codePoint <= 0xffcf) ||
2731
+ (0xffd2 <= codePoint && codePoint <= 0xffd7) ||
2732
+ (0xffda <= codePoint && codePoint <= 0xffdc) ||
2733
+ (0xffe8 <= codePoint && codePoint <= 0xffee)) {
2734
+ return 'H';
3375
2735
  }
3376
- let x11 = bbox.x1;
3377
- let x12 = bbox.x2;
3378
- let y11 = bbox.y1;
3379
- let y12 = bbox.y2;
3380
- if (x11 > x12) {
3381
- [x11, x12] = [x12, x11];
2736
+ if ((0x1100 <= codePoint && codePoint <= 0x115f) ||
2737
+ (0x11a3 <= codePoint && codePoint <= 0x11a7) ||
2738
+ (0x11fa <= codePoint && codePoint <= 0x11ff) ||
2739
+ (0x2329 <= codePoint && codePoint <= 0x232a) ||
2740
+ (0x2e80 <= codePoint && codePoint <= 0x2e99) ||
2741
+ (0x2e9b <= codePoint && codePoint <= 0x2ef3) ||
2742
+ (0x2f00 <= codePoint && codePoint <= 0x2fd5) ||
2743
+ (0x2ff0 <= codePoint && codePoint <= 0x2ffb) ||
2744
+ (0x3001 <= codePoint && codePoint <= 0x303e) ||
2745
+ (0x3041 <= codePoint && codePoint <= 0x3096) ||
2746
+ (0x3099 <= codePoint && codePoint <= 0x30ff) ||
2747
+ (0x3105 <= codePoint && codePoint <= 0x312d) ||
2748
+ (0x3131 <= codePoint && codePoint <= 0x318e) ||
2749
+ (0x3190 <= codePoint && codePoint <= 0x31ba) ||
2750
+ (0x31c0 <= codePoint && codePoint <= 0x31e3) ||
2751
+ (0x31f0 <= codePoint && codePoint <= 0x321e) ||
2752
+ (0x3220 <= codePoint && codePoint <= 0x3247) ||
2753
+ (0x3250 <= codePoint && codePoint <= 0x32fe) ||
2754
+ (0x3300 <= codePoint && codePoint <= 0x4dbf) ||
2755
+ (0x4e00 <= codePoint && codePoint <= 0xa48c) ||
2756
+ (0xa490 <= codePoint && codePoint <= 0xa4c6) ||
2757
+ (0xa960 <= codePoint && codePoint <= 0xa97c) ||
2758
+ (0xac00 <= codePoint && codePoint <= 0xd7a3) ||
2759
+ (0xd7b0 <= codePoint && codePoint <= 0xd7c6) ||
2760
+ (0xd7cb <= codePoint && codePoint <= 0xd7fb) ||
2761
+ (0xf900 <= codePoint && codePoint <= 0xfaff) ||
2762
+ (0xfe10 <= codePoint && codePoint <= 0xfe19) ||
2763
+ (0xfe30 <= codePoint && codePoint <= 0xfe52) ||
2764
+ (0xfe54 <= codePoint && codePoint <= 0xfe66) ||
2765
+ (0xfe68 <= codePoint && codePoint <= 0xfe6b) ||
2766
+ (0x1b000 <= codePoint && codePoint <= 0x1b001) ||
2767
+ (0x1f200 <= codePoint && codePoint <= 0x1f202) ||
2768
+ (0x1f210 <= codePoint && codePoint <= 0x1f23a) ||
2769
+ (0x1f240 <= codePoint && codePoint <= 0x1f248) ||
2770
+ (0x1f250 <= codePoint && codePoint <= 0x1f251) ||
2771
+ (0x20000 <= codePoint && codePoint <= 0x2f73f) ||
2772
+ (0x2b740 <= codePoint && codePoint <= 0x2fffd) ||
2773
+ (0x30000 <= codePoint && codePoint <= 0x3fffd)) {
2774
+ return 'W';
3382
2775
  }
3383
- if (y11 > y12) {
3384
- [y11, y12] = [y12, y11];
2776
+ if ((0x0020 <= codePoint && codePoint <= 0x007e) ||
2777
+ (0x00a2 <= codePoint && codePoint <= 0x00a3) ||
2778
+ (0x00a5 <= codePoint && codePoint <= 0x00a6) ||
2779
+ 0x00ac === codePoint ||
2780
+ 0x00af === codePoint ||
2781
+ (0x27e6 <= codePoint && codePoint <= 0x27ed) ||
2782
+ (0x2985 <= codePoint && codePoint <= 0x2986)) {
2783
+ return 'Na';
3385
2784
  }
3386
- return point.x >= x11 && point.x <= x12 && point.y >= y11 && point.y <= y12;
3387
- }
3388
- function getProjectionRadius(checkAxis, axis) {
3389
- return Math.abs(axis[0] * checkAxis[0] + axis[1] * checkAxis[1]);
3390
- }
3391
- function rotate({ x, y }, deg, origin = { x: 0, y: 0 }) {
3392
- return {
3393
- x: (x - origin.x) * Math.cos(deg) + (y - origin.y) * Math.sin(deg) + origin.x,
3394
- y: (x - origin.x) * Math.sin(deg) + (origin.y - y) * Math.cos(deg) + origin.y
3395
- };
3396
- }
3397
- function getCenterPoint(box) {
3398
- return {
3399
- x: (box.x1 + box.x2) / 2,
3400
- y: (box.y1 + box.y2) / 2
3401
- };
3402
- }
3403
- function toRect(box, isDeg) {
3404
- const deg = isDeg ? box.angle : degreeToRadian(box.angle);
3405
- const cp = getCenterPoint(box);
3406
- return [
3407
- rotate({
3408
- x: box.x1,
3409
- y: box.y1
3410
- }, deg, cp),
3411
- rotate({
3412
- x: box.x2,
3413
- y: box.y1
3414
- }, deg, cp),
3415
- rotate({
3416
- x: box.x2,
3417
- y: box.y2
3418
- }, deg, cp),
3419
- rotate({
3420
- x: box.x1,
3421
- y: box.y2
3422
- }, deg, cp)
3423
- ];
2785
+ if (0x00a1 === codePoint ||
2786
+ 0x00a4 === codePoint ||
2787
+ (0x00a7 <= codePoint && codePoint <= 0x00a8) ||
2788
+ 0x00aa === codePoint ||
2789
+ (0x00ad <= codePoint && codePoint <= 0x00ae) ||
2790
+ (0x00b0 <= codePoint && codePoint <= 0x00b4) ||
2791
+ (0x00b6 <= codePoint && codePoint <= 0x00ba) ||
2792
+ (0x00bc <= codePoint && codePoint <= 0x00bf) ||
2793
+ 0x00c6 === codePoint ||
2794
+ 0x00d0 === codePoint ||
2795
+ (0x00d7 <= codePoint && codePoint <= 0x00d8) ||
2796
+ (0x00de <= codePoint && codePoint <= 0x00e1) ||
2797
+ 0x00e6 === codePoint ||
2798
+ (0x00e8 <= codePoint && codePoint <= 0x00ea) ||
2799
+ (0x00ec <= codePoint && codePoint <= 0x00ed) ||
2800
+ 0x00f0 === codePoint ||
2801
+ (0x00f2 <= codePoint && codePoint <= 0x00f3) ||
2802
+ (0x00f7 <= codePoint && codePoint <= 0x00fa) ||
2803
+ 0x00fc === codePoint ||
2804
+ 0x00fe === codePoint ||
2805
+ 0x0101 === codePoint ||
2806
+ 0x0111 === codePoint ||
2807
+ 0x0113 === codePoint ||
2808
+ 0x011b === codePoint ||
2809
+ (0x0126 <= codePoint && codePoint <= 0x0127) ||
2810
+ 0x012b === codePoint ||
2811
+ (0x0131 <= codePoint && codePoint <= 0x0133) ||
2812
+ 0x0138 === codePoint ||
2813
+ (0x013f <= codePoint && codePoint <= 0x0142) ||
2814
+ 0x0144 === codePoint ||
2815
+ (0x0148 <= codePoint && codePoint <= 0x014b) ||
2816
+ 0x014d === codePoint ||
2817
+ (0x0152 <= codePoint && codePoint <= 0x0153) ||
2818
+ (0x0166 <= codePoint && codePoint <= 0x0167) ||
2819
+ 0x016b === codePoint ||
2820
+ 0x01ce === codePoint ||
2821
+ 0x01d0 === codePoint ||
2822
+ 0x01d2 === codePoint ||
2823
+ 0x01d4 === codePoint ||
2824
+ 0x01d6 === codePoint ||
2825
+ 0x01d8 === codePoint ||
2826
+ 0x01da === codePoint ||
2827
+ 0x01dc === codePoint ||
2828
+ 0x0251 === codePoint ||
2829
+ 0x0261 === codePoint ||
2830
+ 0x02c4 === codePoint ||
2831
+ 0x02c7 === codePoint ||
2832
+ (0x02c9 <= codePoint && codePoint <= 0x02cb) ||
2833
+ 0x02cd === codePoint ||
2834
+ 0x02d0 === codePoint ||
2835
+ (0x02d8 <= codePoint && codePoint <= 0x02db) ||
2836
+ 0x02dd === codePoint ||
2837
+ 0x02df === codePoint ||
2838
+ (0x0300 <= codePoint && codePoint <= 0x036f) ||
2839
+ (0x0391 <= codePoint && codePoint <= 0x03a1) ||
2840
+ (0x03a3 <= codePoint && codePoint <= 0x03a9) ||
2841
+ (0x03b1 <= codePoint && codePoint <= 0x03c1) ||
2842
+ (0x03c3 <= codePoint && codePoint <= 0x03c9) ||
2843
+ 0x0401 === codePoint ||
2844
+ (0x0410 <= codePoint && codePoint <= 0x044f) ||
2845
+ 0x0451 === codePoint ||
2846
+ 0x2010 === codePoint ||
2847
+ (0x2013 <= codePoint && codePoint <= 0x2016) ||
2848
+ (0x2018 <= codePoint && codePoint <= 0x2019) ||
2849
+ (0x201c <= codePoint && codePoint <= 0x201d) ||
2850
+ (0x2020 <= codePoint && codePoint <= 0x2022) ||
2851
+ (0x2024 <= codePoint && codePoint <= 0x2027) ||
2852
+ 0x2030 === codePoint ||
2853
+ (0x2032 <= codePoint && codePoint <= 0x2033) ||
2854
+ 0x2035 === codePoint ||
2855
+ 0x203b === codePoint ||
2856
+ 0x203e === codePoint ||
2857
+ 0x2074 === codePoint ||
2858
+ 0x207f === codePoint ||
2859
+ (0x2081 <= codePoint && codePoint <= 0x2084) ||
2860
+ 0x20ac === codePoint ||
2861
+ 0x2103 === codePoint ||
2862
+ 0x2105 === codePoint ||
2863
+ 0x2109 === codePoint ||
2864
+ 0x2113 === codePoint ||
2865
+ 0x2116 === codePoint ||
2866
+ (0x2121 <= codePoint && codePoint <= 0x2122) ||
2867
+ 0x2126 === codePoint ||
2868
+ 0x212b === codePoint ||
2869
+ (0x2153 <= codePoint && codePoint <= 0x2154) ||
2870
+ (0x215b <= codePoint && codePoint <= 0x215e) ||
2871
+ (0x2160 <= codePoint && codePoint <= 0x216b) ||
2872
+ (0x2170 <= codePoint && codePoint <= 0x2179) ||
2873
+ 0x2189 === codePoint ||
2874
+ (0x2190 <= codePoint && codePoint <= 0x2199) ||
2875
+ (0x21b8 <= codePoint && codePoint <= 0x21b9) ||
2876
+ 0x21d2 === codePoint ||
2877
+ 0x21d4 === codePoint ||
2878
+ 0x21e7 === codePoint ||
2879
+ 0x2200 === codePoint ||
2880
+ (0x2202 <= codePoint && codePoint <= 0x2203) ||
2881
+ (0x2207 <= codePoint && codePoint <= 0x2208) ||
2882
+ 0x220b === codePoint ||
2883
+ 0x220f === codePoint ||
2884
+ 0x2211 === codePoint ||
2885
+ 0x2215 === codePoint ||
2886
+ 0x221a === codePoint ||
2887
+ (0x221d <= codePoint && codePoint <= 0x2220) ||
2888
+ 0x2223 === codePoint ||
2889
+ 0x2225 === codePoint ||
2890
+ (0x2227 <= codePoint && codePoint <= 0x222c) ||
2891
+ 0x222e === codePoint ||
2892
+ (0x2234 <= codePoint && codePoint <= 0x2237) ||
2893
+ (0x223c <= codePoint && codePoint <= 0x223d) ||
2894
+ 0x2248 === codePoint ||
2895
+ 0x224c === codePoint ||
2896
+ 0x2252 === codePoint ||
2897
+ (0x2260 <= codePoint && codePoint <= 0x2261) ||
2898
+ (0x2264 <= codePoint && codePoint <= 0x2267) ||
2899
+ (0x226a <= codePoint && codePoint <= 0x226b) ||
2900
+ (0x226e <= codePoint && codePoint <= 0x226f) ||
2901
+ (0x2282 <= codePoint && codePoint <= 0x2283) ||
2902
+ (0x2286 <= codePoint && codePoint <= 0x2287) ||
2903
+ 0x2295 === codePoint ||
2904
+ 0x2299 === codePoint ||
2905
+ 0x22a5 === codePoint ||
2906
+ 0x22bf === codePoint ||
2907
+ 0x2312 === codePoint ||
2908
+ (0x2460 <= codePoint && codePoint <= 0x24e9) ||
2909
+ (0x24eb <= codePoint && codePoint <= 0x254b) ||
2910
+ (0x2550 <= codePoint && codePoint <= 0x2573) ||
2911
+ (0x2580 <= codePoint && codePoint <= 0x258f) ||
2912
+ (0x2592 <= codePoint && codePoint <= 0x2595) ||
2913
+ (0x25a0 <= codePoint && codePoint <= 0x25a1) ||
2914
+ (0x25a3 <= codePoint && codePoint <= 0x25a9) ||
2915
+ (0x25b2 <= codePoint && codePoint <= 0x25b3) ||
2916
+ (0x25b6 <= codePoint && codePoint <= 0x25b7) ||
2917
+ (0x25bc <= codePoint && codePoint <= 0x25bd) ||
2918
+ (0x25c0 <= codePoint && codePoint <= 0x25c1) ||
2919
+ (0x25c6 <= codePoint && codePoint <= 0x25c8) ||
2920
+ 0x25cb === codePoint ||
2921
+ (0x25ce <= codePoint && codePoint <= 0x25d1) ||
2922
+ (0x25e2 <= codePoint && codePoint <= 0x25e5) ||
2923
+ 0x25ef === codePoint ||
2924
+ (0x2605 <= codePoint && codePoint <= 0x2606) ||
2925
+ 0x2609 === codePoint ||
2926
+ (0x260e <= codePoint && codePoint <= 0x260f) ||
2927
+ (0x2614 <= codePoint && codePoint <= 0x2615) ||
2928
+ 0x261c === codePoint ||
2929
+ 0x261e === codePoint ||
2930
+ 0x2640 === codePoint ||
2931
+ 0x2642 === codePoint ||
2932
+ (0x2660 <= codePoint && codePoint <= 0x2661) ||
2933
+ (0x2663 <= codePoint && codePoint <= 0x2665) ||
2934
+ (0x2667 <= codePoint && codePoint <= 0x266a) ||
2935
+ (0x266c <= codePoint && codePoint <= 0x266d) ||
2936
+ 0x266f === codePoint ||
2937
+ (0x269e <= codePoint && codePoint <= 0x269f) ||
2938
+ (0x26be <= codePoint && codePoint <= 0x26bf) ||
2939
+ (0x26c4 <= codePoint && codePoint <= 0x26cd) ||
2940
+ (0x26cf <= codePoint && codePoint <= 0x26e1) ||
2941
+ 0x26e3 === codePoint ||
2942
+ (0x26e8 <= codePoint && codePoint <= 0x26ff) ||
2943
+ 0x273d === codePoint ||
2944
+ 0x2757 === codePoint ||
2945
+ (0x2776 <= codePoint && codePoint <= 0x277f) ||
2946
+ (0x2b55 <= codePoint && codePoint <= 0x2b59) ||
2947
+ (0x3248 <= codePoint && codePoint <= 0x324f) ||
2948
+ (0xe000 <= codePoint && codePoint <= 0xf8ff) ||
2949
+ (0xfe00 <= codePoint && codePoint <= 0xfe0f) ||
2950
+ 0xfffd === codePoint ||
2951
+ (0x1f100 <= codePoint && codePoint <= 0x1f10a) ||
2952
+ (0x1f110 <= codePoint && codePoint <= 0x1f12d) ||
2953
+ (0x1f130 <= codePoint && codePoint <= 0x1f169) ||
2954
+ (0x1f170 <= codePoint && codePoint <= 0x1f19a) ||
2955
+ (0xe0100 <= codePoint && codePoint <= 0xe01ef) ||
2956
+ (0xf0000 <= codePoint && codePoint <= 0xffffd) ||
2957
+ (0x100000 <= codePoint && codePoint <= 0x10fffd)) {
2958
+ return 'A';
2959
+ }
2960
+ return 'N';
2961
+ };
2962
+ const emojiRegex = () => {
2963
+ return /[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26F9(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC3\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC08\uDC26](?:\u200D\u2B1B)?|[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE])))?))?|\uDC6F(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDD75(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE88\uDE90-\uDEBD\uDEBF-\uDEC2\uDECE-\uDEDB\uDEE0-\uDEE8]|\uDD3C(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF])?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g;
2964
+ };
2965
+
2966
+ function getContextFont(text, defaultAttr = {}, fontSizeScale) {
2967
+ if (!fontSizeScale) {
2968
+ fontSizeScale = 1;
2969
+ }
2970
+ const { fontStyle = defaultAttr.fontStyle, fontVariant = defaultAttr.fontVariant, fontWeight = defaultAttr.fontWeight, fontSize = defaultAttr.fontSize, fontFamily = defaultAttr.fontFamily } = text;
2971
+ return ('' +
2972
+ (fontStyle ? fontStyle + ' ' : '') +
2973
+ (fontVariant ? fontVariant + ' ' : '') +
2974
+ (fontWeight ? fontWeight + ' ' : '') +
2975
+ fontSize * fontSizeScale +
2976
+ 'px ' +
2977
+ (fontFamily ? fontFamily : 'sans-serif'));
3424
2978
  }
3425
- function isRotateAABBIntersect(box1, box2, isDeg = false, ctx) {
3426
- const rect1 = toRect(box1, isDeg);
3427
- const rect2 = toRect(box2, isDeg);
3428
- const vector = (start, end) => {
3429
- return [end.x - start.x, end.y - start.y];
3430
- };
3431
- if (ctx) {
3432
- ctx.save();
3433
- ctx.fillStyle = 'red';
3434
- ctx.globalAlpha = 0.6;
3435
- rect1.forEach((item, index) => {
3436
- if (index === 0) {
3437
- ctx.moveTo(item.x, item.y);
2979
+
2980
+ class TextMeasure {
2981
+ constructor(option, textSpec) {
2982
+ this._numberCharSize = null;
2983
+ this._fullCharSize = null;
2984
+ this._letterCharSize = null;
2985
+ this._specialCharSizeMap = {};
2986
+ this._canvas = null;
2987
+ this._context = null;
2988
+ this._contextSaved = false;
2989
+ this._notSupportCanvas = false;
2990
+ this._notSupportVRender = false;
2991
+ this._userSpec = {};
2992
+ this.specialCharSet = '-/: .,@%\'"~';
2993
+ this._option = option;
2994
+ this._userSpec = textSpec !== null && textSpec !== void 0 ? textSpec : {};
2995
+ this.textSpec = this._initSpec();
2996
+ if (isValid(option.specialCharSet)) {
2997
+ this.specialCharSet = option.specialCharSet;
2998
+ }
2999
+ this._standardMethod = isValid(option.getTextBounds)
3000
+ ? this.fullMeasure.bind(this)
3001
+ : this.measureWithNaiveCanvas.bind(this);
3002
+ }
3003
+ initContext() {
3004
+ if (this._notSupportCanvas) {
3005
+ return false;
3006
+ }
3007
+ if (isNil(this._canvas)) {
3008
+ if (isValid(this._option.getCanvasForMeasure)) {
3009
+ this._canvas = this._option.getCanvasForMeasure();
3010
+ }
3011
+ if (isNil(this._canvas) &&
3012
+ typeof window !== 'undefined' &&
3013
+ typeof window.document !== 'undefined' &&
3014
+ globalThis &&
3015
+ isValid(globalThis.document)) {
3016
+ this._canvas = globalThis.document.createElement('canvas');
3017
+ }
3018
+ }
3019
+ if (isNil(this._context) && isValid(this._canvas)) {
3020
+ const context = this._canvas.getContext('2d');
3021
+ if (isValid(context)) {
3022
+ context.save();
3023
+ context.font = getContextFont(this.textSpec);
3024
+ this._contextSaved = true;
3025
+ this._context = context;
3026
+ }
3027
+ }
3028
+ if (isNil(this._context)) {
3029
+ this._notSupportCanvas = true;
3030
+ return false;
3031
+ }
3032
+ return true;
3033
+ }
3034
+ _initSpec() {
3035
+ var _a, _b, _c;
3036
+ const { defaultFontParams = {} } = this._option;
3037
+ const { fontStyle = defaultFontParams.fontStyle, fontVariant = defaultFontParams.fontVariant, fontWeight = (_a = defaultFontParams.fontWeight) !== null && _a !== void 0 ? _a : 'normal', fontSize = (_b = defaultFontParams.fontSize) !== null && _b !== void 0 ? _b : 12, fontFamily = (_c = defaultFontParams.fontFamily) !== null && _c !== void 0 ? _c : 'sans-serif', align, textAlign = align !== null && align !== void 0 ? align : 'center', baseline, textBaseline = baseline !== null && baseline !== void 0 ? baseline : 'middle', ellipsis, limit } = this._userSpec;
3038
+ let { lineHeight = fontSize } = this._userSpec;
3039
+ if (isString(lineHeight) && lineHeight[lineHeight.length - 1] === '%') {
3040
+ const scale = Number.parseFloat(lineHeight.substring(0, lineHeight.length - 1)) / 100;
3041
+ lineHeight = fontSize * scale;
3042
+ }
3043
+ return {
3044
+ fontStyle,
3045
+ fontVariant,
3046
+ fontFamily,
3047
+ fontSize,
3048
+ fontWeight,
3049
+ textAlign,
3050
+ textBaseline,
3051
+ ellipsis,
3052
+ limit,
3053
+ lineHeight
3054
+ };
3055
+ }
3056
+ measure(text, method) {
3057
+ switch (method) {
3058
+ case 'vrender':
3059
+ case 'canopus':
3060
+ return this.fullMeasure(text);
3061
+ case 'canvas':
3062
+ return this.measureWithNaiveCanvas(text);
3063
+ case 'simple':
3064
+ return this.quickMeasureWithoutCanvas(text);
3065
+ case 'quick':
3066
+ default:
3067
+ return this.quickMeasure(text);
3068
+ }
3069
+ }
3070
+ fullMeasure(text) {
3071
+ if (isNil(text)) {
3072
+ return { width: 0, height: 0 };
3073
+ }
3074
+ if (isNil(this._option.getTextBounds) || !this._notSupportVRender) {
3075
+ return this.measureWithNaiveCanvas(text);
3076
+ }
3077
+ const { fontFamily, fontSize, fontWeight, textAlign, textBaseline, ellipsis, limit, lineHeight } = this.textSpec;
3078
+ let size;
3079
+ try {
3080
+ const bounds = this._option.getTextBounds({
3081
+ text,
3082
+ fontFamily,
3083
+ fontSize,
3084
+ fontWeight,
3085
+ textAlign,
3086
+ textBaseline,
3087
+ ellipsis: !!ellipsis,
3088
+ maxLineWidth: limit || Infinity,
3089
+ lineHeight
3090
+ });
3091
+ size = { width: bounds.width(), height: bounds.height() };
3092
+ }
3093
+ catch (e) {
3094
+ this._notSupportVRender = true;
3095
+ size = this.measureWithNaiveCanvas(text);
3096
+ }
3097
+ return size;
3098
+ }
3099
+ measureWithNaiveCanvas(text) {
3100
+ return this._measureReduce(text, this._measureWithNaiveCanvas.bind(this));
3101
+ }
3102
+ _measureWithNaiveCanvas(text) {
3103
+ var _a;
3104
+ if (!this.initContext()) {
3105
+ return this._quickMeasureWithoutCanvas(text);
3106
+ }
3107
+ const metrics = this._context.measureText(text);
3108
+ const { fontSize, lineHeight } = this.textSpec;
3109
+ return { width: metrics.width, height: (_a = lineHeight) !== null && _a !== void 0 ? _a : fontSize };
3110
+ }
3111
+ quickMeasure(text) {
3112
+ return this._measureReduce(text, this._quickMeasure.bind(this));
3113
+ }
3114
+ _quickMeasure(text) {
3115
+ const totalSize = {
3116
+ width: 0,
3117
+ height: 0
3118
+ };
3119
+ for (let i = 0; i < text.length; i++) {
3120
+ const char = text[i];
3121
+ let size = this._measureSpecialChar(char);
3122
+ if (isNil(size) && TextMeasure.NUMBERS_CHAR_SET.includes(char)) {
3123
+ size = this._measureNumberChar();
3438
3124
  }
3439
- else {
3440
- ctx.lineTo(item.x, item.y);
3125
+ if (isNil(size) && ['F', 'W'].includes(eastAsianCharacterInfo(char))) {
3126
+ size = this._measureFullSizeChar();
3441
3127
  }
3442
- });
3443
- ctx.fill();
3444
- ctx.restore();
3445
- ctx.save();
3446
- ctx.fillStyle = 'green';
3447
- ctx.globalAlpha = 0.6;
3448
- rect2.forEach((item, index) => {
3449
- if (index === 0) {
3450
- ctx.moveTo(item.x, item.y);
3128
+ if (isNil(size)) {
3129
+ size = this._measureLetterChar();
3451
3130
  }
3452
- else {
3453
- ctx.lineTo(item.x, item.y);
3131
+ totalSize.width += size.width;
3132
+ totalSize.height = Math.max(totalSize.height, size.height);
3133
+ }
3134
+ return totalSize;
3135
+ }
3136
+ quickMeasureWithoutCanvas(text) {
3137
+ return this._measureReduce(text, this._quickMeasureWithoutCanvas.bind(this));
3138
+ }
3139
+ _quickMeasureWithoutCanvas(text) {
3140
+ var _a;
3141
+ const totalSize = {
3142
+ width: 0,
3143
+ height: 0
3144
+ };
3145
+ const { fontSize, lineHeight } = this.textSpec;
3146
+ for (let i = 0; i < text.length; i++) {
3147
+ const char = text[i];
3148
+ const size = ['F', 'W'].includes(eastAsianCharacterInfo(char)) ? 1 : 0.53;
3149
+ totalSize.width += size * fontSize;
3150
+ }
3151
+ totalSize.height = (_a = lineHeight) !== null && _a !== void 0 ? _a : fontSize;
3152
+ return totalSize;
3153
+ }
3154
+ _measureReduce(text, processor) {
3155
+ var _a;
3156
+ const { fontSize, lineHeight } = this.textSpec;
3157
+ const defaultResult = { width: 0, height: 0 };
3158
+ if (isNil(text)) {
3159
+ return defaultResult;
3160
+ }
3161
+ else if (isArray(text)) {
3162
+ const textArr = text.filter(isValid).map(s => s.toString());
3163
+ if (textArr.length === 0) {
3164
+ return defaultResult;
3454
3165
  }
3455
- });
3456
- ctx.fill();
3457
- ctx.restore();
3166
+ else if (textArr.length === 1) {
3167
+ return processor(textArr[0]);
3168
+ }
3169
+ return {
3170
+ width: textArr.reduce((maxWidth, cur) => Math.max(maxWidth, processor(cur).width), 0),
3171
+ height: textArr.length * (((_a = lineHeight) !== null && _a !== void 0 ? _a : fontSize) + 1) + 1
3172
+ };
3173
+ }
3174
+ return processor(text.toString());
3175
+ }
3176
+ _measureNumberChar() {
3177
+ if (isNil(this._numberCharSize)) {
3178
+ const numberBounds = this._standardMethod(TextMeasure.NUMBERS_CHAR_SET);
3179
+ this._numberCharSize = {
3180
+ width: numberBounds.width / TextMeasure.NUMBERS_CHAR_SET.length,
3181
+ height: numberBounds.height
3182
+ };
3183
+ }
3184
+ return this._numberCharSize;
3185
+ }
3186
+ _measureFullSizeChar() {
3187
+ if (isNil(this._fullCharSize)) {
3188
+ this._fullCharSize = this._standardMethod(TextMeasure.FULL_SIZE_CHAR);
3189
+ }
3190
+ return this._fullCharSize;
3191
+ }
3192
+ _measureLetterChar() {
3193
+ if (isNil(this._letterCharSize)) {
3194
+ const alphabetBounds = this._standardMethod(TextMeasure.ALPHABET_CHAR_SET);
3195
+ this._letterCharSize = {
3196
+ width: alphabetBounds.width / TextMeasure.ALPHABET_CHAR_SET.length,
3197
+ height: alphabetBounds.height
3198
+ };
3199
+ }
3200
+ return this._letterCharSize;
3201
+ }
3202
+ _measureSpecialChar(char) {
3203
+ if (isValid(this._specialCharSizeMap[char])) {
3204
+ return this._specialCharSizeMap[char];
3205
+ }
3206
+ if (this.specialCharSet.includes(char)) {
3207
+ this._specialCharSizeMap[char] = this._standardMethod(char);
3208
+ return this._specialCharSizeMap[char];
3209
+ }
3210
+ return null;
3211
+ }
3212
+ release() {
3213
+ if (isValid(this._canvas)) {
3214
+ this._canvas = null;
3215
+ }
3216
+ if (isValid(this._context)) {
3217
+ if (this._contextSaved) {
3218
+ this._context.restore();
3219
+ this._contextSaved = false;
3220
+ }
3221
+ this._context = null;
3222
+ }
3223
+ }
3224
+ }
3225
+ TextMeasure.ALPHABET_CHAR_SET = 'abcdefghijklmnopqrstuvwxyz';
3226
+ TextMeasure.NUMBERS_CHAR_SET = '0123456789';
3227
+ TextMeasure.FULL_SIZE_CHAR = '字';
3228
+
3229
+ const calculateAnchorOfBounds = (bounds, anchorType) => {
3230
+ const { x1, x2, y1, y2 } = bounds;
3231
+ const rectWidth = Math.abs(x2 - x1);
3232
+ const rectHeight = Math.abs(y2 - y1);
3233
+ let anchorX = (x1 + x2) / 2;
3234
+ let anchorY = (y1 + y2) / 2;
3235
+ let sx = 0;
3236
+ let sy = 0;
3237
+ switch (anchorType) {
3238
+ case 'top':
3239
+ case 'inside-top':
3240
+ sy = -0.5;
3241
+ break;
3242
+ case 'bottom':
3243
+ case 'inside-bottom':
3244
+ sy = 0.5;
3245
+ break;
3246
+ case 'left':
3247
+ case 'inside-left':
3248
+ sx = -0.5;
3249
+ break;
3250
+ case 'right':
3251
+ case 'inside-right':
3252
+ sx = 0.5;
3253
+ break;
3254
+ case 'top-right':
3255
+ sx = 0.5;
3256
+ sy = -0.5;
3257
+ break;
3258
+ case 'top-left':
3259
+ sx = -0.5;
3260
+ sy = -0.5;
3261
+ break;
3262
+ case 'bottom-right':
3263
+ sx = 0.5;
3264
+ sy = 0.5;
3265
+ break;
3266
+ case 'bottom-left':
3267
+ sx = -0.5;
3268
+ sy = 0.5;
3269
+ }
3270
+ anchorX += sx * rectWidth;
3271
+ anchorY += sy * rectHeight;
3272
+ return { x: anchorX, y: anchorY };
3273
+ };
3274
+
3275
+ function transformBoundsWithMatrix(out, bounds, matrix) {
3276
+ const { x1, y1, x2, y2 } = bounds;
3277
+ if (matrix.onlyTranslate()) {
3278
+ if (out !== bounds) {
3279
+ out.setValue(bounds.x1, bounds.y1, bounds.x2, bounds.y2);
3280
+ }
3281
+ out.translate(matrix.e, matrix.f);
3282
+ return bounds;
3283
+ }
3284
+ out.clear();
3285
+ out.add(matrix.a * x1 + matrix.c * y1 + matrix.e, matrix.b * x1 + matrix.d * y1 + matrix.f);
3286
+ out.add(matrix.a * x2 + matrix.c * y1 + matrix.e, matrix.b * x2 + matrix.d * y1 + matrix.f);
3287
+ out.add(matrix.a * x2 + matrix.c * y2 + matrix.e, matrix.b * x2 + matrix.d * y2 + matrix.f);
3288
+ out.add(matrix.a * x1 + matrix.c * y2 + matrix.e, matrix.b * x1 + matrix.d * y2 + matrix.f);
3289
+ return bounds;
3290
+ }
3291
+ function transformBounds(bounds, x, y, scaleX, scaleY, angle, rotateCenter) {
3292
+ if (abs(scaleX) <= epsilon || abs(scaleY) <= epsilon) {
3293
+ return;
3294
+ }
3295
+ scaleX !== 1 && bounds.scaleX(scaleX);
3296
+ scaleY !== 1 && bounds.scaleY(scaleY);
3297
+ if (isFinite(angle) && Math.abs(angle) > epsilon) {
3298
+ let rx = 0;
3299
+ let ry = 0;
3300
+ if (rotateCenter !== undefined) {
3301
+ rx = rotateCenter[0];
3302
+ ry = rotateCenter[1];
3303
+ }
3304
+ bounds.rotate(angle, rx, ry);
3305
+ }
3306
+ bounds.translate(x, y);
3307
+ }
3308
+ class Bounds {
3309
+ constructor(bounds) {
3310
+ if (bounds) {
3311
+ this.setValue(bounds.x1, bounds.y1, bounds.x2, bounds.y2);
3312
+ }
3313
+ else {
3314
+ this.clear();
3315
+ }
3316
+ }
3317
+ clone() {
3318
+ return new Bounds(this);
3319
+ }
3320
+ clear() {
3321
+ this.x1 = +Number.MAX_VALUE;
3322
+ this.y1 = +Number.MAX_VALUE;
3323
+ this.x2 = -Number.MAX_VALUE;
3324
+ this.y2 = -Number.MAX_VALUE;
3325
+ return this;
3326
+ }
3327
+ empty() {
3328
+ return (this.x1 === +Number.MAX_VALUE &&
3329
+ this.y1 === +Number.MAX_VALUE &&
3330
+ this.x2 === -Number.MAX_VALUE &&
3331
+ this.y2 === -Number.MAX_VALUE);
3332
+ }
3333
+ equals(b) {
3334
+ return this.x1 === b.x1 && this.y1 === b.y1 && this.x2 === b.x2 && this.y2 === b.y2;
3335
+ }
3336
+ setValue(x1 = 0, y1 = 0, x2 = 0, y2 = 0) {
3337
+ this.x1 = x1;
3338
+ this.y1 = y1;
3339
+ this.x2 = x2;
3340
+ this.y2 = y2;
3341
+ return this;
3342
+ }
3343
+ set(x1 = 0, y1 = 0, x2 = 0, y2 = 0) {
3344
+ if (x2 < x1) {
3345
+ this.x2 = x1;
3346
+ this.x1 = x2;
3347
+ }
3348
+ else {
3349
+ this.x1 = x1;
3350
+ this.x2 = x2;
3351
+ }
3352
+ if (y2 < y1) {
3353
+ this.y2 = y1;
3354
+ this.y1 = y2;
3355
+ }
3356
+ else {
3357
+ this.y1 = y1;
3358
+ this.y2 = y2;
3359
+ }
3360
+ return this;
3361
+ }
3362
+ add(x = 0, y = 0) {
3363
+ if (x < this.x1) {
3364
+ this.x1 = x;
3365
+ }
3366
+ if (y < this.y1) {
3367
+ this.y1 = y;
3368
+ }
3369
+ if (x > this.x2) {
3370
+ this.x2 = x;
3371
+ }
3372
+ if (y > this.y2) {
3373
+ this.y2 = y;
3374
+ }
3375
+ return this;
3458
3376
  }
3459
- const p1 = getCenterPoint(box1);
3460
- const p2 = getCenterPoint(box2);
3461
- ctx && ctx.fillRect(p1.x, p1.y, 2, 2);
3462
- ctx && ctx.fillRect(p2.x, p2.y, 2, 2);
3463
- const vp1p2 = vector(p1, p2);
3464
- const AB = vector(rect1[0], rect1[1]);
3465
- const BC = vector(rect1[1], rect1[2]);
3466
- const A1B1 = vector(rect2[0], rect2[1]);
3467
- const B1C1 = vector(rect2[1], rect2[2]);
3468
- const deg11 = isDeg ? box1.angle : degreeToRadian(box1.angle);
3469
- let deg12 = isDeg ? box1.angle + halfPi : degreeToRadian(90 - box1.angle);
3470
- const deg21 = isDeg ? box2.angle : degreeToRadian(box2.angle);
3471
- let deg22 = isDeg ? box2.angle + halfPi : degreeToRadian(90 - box2.angle);
3472
- if (deg12 > pi2) {
3473
- deg12 -= pi2;
3377
+ expand(d = 0) {
3378
+ if (isArray(d)) {
3379
+ this.y1 -= d[0];
3380
+ this.x2 += d[1];
3381
+ this.y2 += d[2];
3382
+ this.x1 -= d[3];
3383
+ }
3384
+ else {
3385
+ this.x1 -= d;
3386
+ this.y1 -= d;
3387
+ this.x2 += d;
3388
+ this.y2 += d;
3389
+ }
3390
+ return this;
3474
3391
  }
3475
- if (deg22 > pi2) {
3476
- deg22 -= pi2;
3392
+ round() {
3393
+ this.x1 = Math.floor(this.x1);
3394
+ this.y1 = Math.floor(this.y1);
3395
+ this.x2 = Math.ceil(this.x2);
3396
+ this.y2 = Math.ceil(this.y2);
3397
+ return this;
3477
3398
  }
3478
- const isCover = (checkAxisRadius, deg, targetAxis1, targetAxis2) => {
3479
- const checkAxis = [Math.cos(deg), Math.sin(deg)];
3480
- const targetAxisRadius = (getProjectionRadius(checkAxis, targetAxis1) + getProjectionRadius(checkAxis, targetAxis2)) / 2;
3481
- const centerPointRadius = getProjectionRadius(checkAxis, vp1p2);
3482
- return checkAxisRadius + targetAxisRadius > centerPointRadius;
3483
- };
3484
- return (isCover((box1.x2 - box1.x1) / 2, deg11, A1B1, B1C1) &&
3485
- isCover((box1.y2 - box1.y1) / 2, deg12, A1B1, B1C1) &&
3486
- isCover((box2.x2 - box2.x1) / 2, deg21, AB, BC) &&
3487
- isCover((box2.y2 - box2.y1) / 2, deg22, AB, BC));
3488
- }
3489
-
3490
- let x1;
3491
- let y1;
3492
- let x2;
3493
- let y2;
3494
- function getAABBFromPoints(points) {
3495
- (x1 = Infinity), (y1 = Infinity), (x2 = -Infinity), (y2 = -Infinity);
3496
- points.forEach(point => {
3497
- if (x1 > point.x) {
3498
- x1 = point.x;
3399
+ translate(dx = 0, dy = 0) {
3400
+ this.x1 += dx;
3401
+ this.x2 += dx;
3402
+ this.y1 += dy;
3403
+ this.y2 += dy;
3404
+ return this;
3405
+ }
3406
+ rotate(angle = 0, x = 0, y = 0) {
3407
+ const p = this.rotatedPoints(angle, x, y);
3408
+ return this.clear().add(p[0], p[1]).add(p[2], p[3]).add(p[4], p[5]).add(p[6], p[7]);
3409
+ }
3410
+ scale(sx = 0, sy = 0, x = 0, y = 0) {
3411
+ const p = this.scalePoints(sx, sy, x, y);
3412
+ return this.clear().add(p[0], p[1]).add(p[2], p[3]);
3413
+ }
3414
+ union(b) {
3415
+ if (b.x1 < this.x1) {
3416
+ this.x1 = b.x1;
3499
3417
  }
3500
- if (x2 < point.x) {
3501
- x2 = point.x;
3418
+ if (b.y1 < this.y1) {
3419
+ this.y1 = b.y1;
3502
3420
  }
3503
- if (y1 > point.y) {
3504
- y1 = point.y;
3421
+ if (b.x2 > this.x2) {
3422
+ this.x2 = b.x2;
3505
3423
  }
3506
- if (y2 < point.y) {
3507
- y2 = point.y;
3424
+ if (b.y2 > this.y2) {
3425
+ this.y2 = b.y2;
3508
3426
  }
3509
- });
3510
- return { x1, y1, x2, y2 };
3511
- }
3512
- function pointInAABB(point, aabb) {
3513
- return pointInRect(point, aabb, false);
3514
- }
3515
- function unionAABB(bounds1, bounds2, buffer = 3, format = false) {
3516
- let x11 = bounds1.x1;
3517
- let x12 = bounds1.x2;
3518
- let y11 = bounds1.y1;
3519
- let y12 = bounds1.y2;
3520
- let x21 = bounds2.x1;
3521
- let x22 = bounds2.x2;
3522
- let y21 = bounds2.y1;
3523
- let y22 = bounds2.y2;
3524
- if (format) {
3525
- let temp;
3526
- if (x11 > x12) {
3527
- temp = x11;
3528
- x11 = x12;
3529
- x12 = temp;
3427
+ return this;
3428
+ }
3429
+ intersect(b) {
3430
+ if (b.x1 > this.x1) {
3431
+ this.x1 = b.x1;
3530
3432
  }
3531
- if (y11 > y12) {
3532
- temp = y11;
3533
- y11 = y12;
3534
- y12 = temp;
3433
+ if (b.y1 > this.y1) {
3434
+ this.y1 = b.y1;
3535
3435
  }
3536
- if (x21 > x22) {
3537
- temp = x21;
3538
- x21 = x22;
3539
- x22 = temp;
3436
+ if (b.x2 < this.x2) {
3437
+ this.x2 = b.x2;
3540
3438
  }
3541
- if (y21 > y22) {
3542
- temp = y21;
3543
- y21 = y22;
3544
- y22 = temp;
3439
+ if (b.y2 < this.y2) {
3440
+ this.y2 = b.y2;
3545
3441
  }
3442
+ return this;
3546
3443
  }
3547
- if (x11 >= x22 || x12 <= x21 || y11 >= y22 || y12 <= y21) {
3548
- return [bounds1, bounds2];
3444
+ encloses(b) {
3445
+ return b && this.x1 <= b.x1 && this.x2 >= b.x2 && this.y1 <= b.y1 && this.y2 >= b.y2;
3549
3446
  }
3550
- const area1 = (x12 - x11 + buffer * 2) * (y12 - y11 + buffer * 2);
3551
- const area2 = (x22 - x21 + buffer * 2) * (y22 - y21 + buffer * 2);
3552
- const x1 = Math.min(x11, x21);
3553
- const y1 = Math.min(y11, y21);
3554
- const x2 = Math.max(x12, x22);
3555
- const y2 = Math.max(y12, y22);
3556
- const unionArea = (x2 - x1) * (y2 - y1);
3557
- if (area1 + area2 > unionArea) {
3558
- return [{ x1, x2, y1, y2 }];
3447
+ alignsWith(b) {
3448
+ return b && (this.x1 === b.x1 || this.x2 === b.x2 || this.y1 === b.y1 || this.y2 === b.y2);
3559
3449
  }
3560
- return [bounds1, bounds2];
3561
- }
3562
- function mergeAABB(boundsList) {
3563
- const nextList = [];
3564
- function _merge(baseBound, list) {
3565
- const l = [];
3566
- list.forEach(b => {
3567
- let arr;
3568
- if ((arr = unionAABB(baseBound, b)).length > 1) {
3569
- l.push(b);
3570
- return;
3571
- }
3572
- baseBound = arr[0];
3573
- });
3574
- nextList.push(baseBound);
3575
- l.length && _merge(l[0], l.slice(1));
3450
+ intersects(b) {
3451
+ return b && !(this.x2 < b.x1 || this.x1 > b.x2 || this.y2 < b.y1 || this.y1 > b.y2);
3576
3452
  }
3577
- _merge(boundsList[0], boundsList.slice(1));
3578
- return nextList;
3579
- }
3580
-
3581
- let dirX;
3582
- let dirY;
3583
- let normalX;
3584
- let normalY;
3585
- let len;
3586
- let lineWidthDiv2;
3587
- let width;
3588
- let height;
3589
- function getOBBFromLine(point1, point2, lineWidth) {
3590
- dirX = point2.x - point1.x;
3591
- dirY = point2.y - point1.y;
3592
- (normalX = dirY), (normalY = -dirX);
3593
- width = len = Math.sqrt(normalX * normalX + normalY * normalY);
3594
- height = lineWidth;
3595
- normalX /= len;
3596
- normalY /= len;
3597
- lineWidthDiv2 = lineWidth / 2;
3598
- dirX = lineWidthDiv2 * normalX;
3599
- dirY = lineWidthDiv2 * normalY;
3600
- const point11 = { x: point1.x + dirX, y: point1.y + dirY };
3601
- const point12 = { x: point1.x - dirX, y: point1.y - dirY };
3602
- const point13 = { x: point2.x + dirX, y: point2.y + dirY };
3603
- const point14 = { x: point2.x - dirX, y: point2.y - dirY };
3604
- return {
3605
- point1: point11,
3606
- point2: point12,
3607
- point3: point13,
3608
- point4: point14,
3609
- width,
3610
- height,
3611
- left: Math.min(point1.x, point2.x) - Math.abs(dirX),
3612
- top: Math.min(point1.y, point2.y) - Math.abs(dirY)
3613
- };
3614
- }
3615
- const point1 = { x: 0, y: 0 };
3616
- const point2 = { x: 0, y: 0 };
3617
- function pointInOBB(point, obb) {
3618
- point1.x = (obb.point1.x + obb.point2.x) / 2;
3619
- point1.y = (obb.point1.y + obb.point2.y) / 2;
3620
- point2.x = (obb.point3.x + obb.point4.x) / 2;
3621
- point2.y = (obb.point3.y + obb.point4.y) / 2;
3622
- return pointInLine(point, point1, point2, obb.height);
3623
- }
3624
- function pointInLine(point, point1, point2, lineWidth) {
3625
- return lengthFromPointToLine(point, point1, point2) <= lineWidth / 2 && pointBetweenLine(point, point1, point2);
3626
- }
3627
- const dir1 = { x: 0, y: 0 };
3628
- const dir2 = { x: 0, y: 0 };
3629
- const normal = { x: 0, y: 0 };
3630
- function pointBetweenLine(point, point1, point2) {
3631
- dir1.x = point1.x - point.x;
3632
- dir1.y = point1.y - point.y;
3633
- dir2.x = point2.x - point.x;
3634
- dir2.y = point2.y - point.y;
3635
- normal.x = point1.y - point2.y;
3636
- normal.y = point2.x - point1.x;
3637
- return crossProductPoint(dir1, normal) * crossProductPoint(dir2, normal) < 0;
3638
- }
3639
-
3640
- function getContextFont$1({ fontStyle, fontVariant, fontWeight, fontSize, fontFamily }) {
3641
- return ('' +
3642
- (fontStyle ? fontStyle + ' ' : '') +
3643
- (fontVariant ? fontVariant + ' ' : '') +
3644
- (fontWeight ? fontWeight + ' ' : '') +
3645
- (fontSize || 12) +
3646
- 'px ' +
3647
- (fontFamily ? fontFamily : 'sans-serif'));
3648
- }
3649
- class GraphicUtil {
3650
- constructor(canvas) {
3651
- this.canvas = canvas;
3652
- if (canvas) {
3653
- this.ctx = canvas.getContext('2d');
3453
+ contains(x = 0, y = 0) {
3454
+ return !(x < this.x1 || x > this.x2 || y < this.y1 || y > this.y2);
3455
+ }
3456
+ containsPoint(p) {
3457
+ return !(p.x < this.x1 || p.x > this.x2 || p.y < this.y1 || p.y > this.y2);
3458
+ }
3459
+ width() {
3460
+ if (this.empty()) {
3461
+ return 0;
3654
3462
  }
3463
+ return this.x2 - this.x1;
3655
3464
  }
3656
- setCanvas(canvas) {
3657
- this.canvas = canvas;
3658
- if (canvas) {
3659
- this.ctx = canvas.getContext('2d');
3465
+ height() {
3466
+ if (this.empty()) {
3467
+ return 0;
3660
3468
  }
3469
+ return this.y2 - this.y1;
3661
3470
  }
3662
- measureText(tc) {
3663
- if (!this.canvas) {
3664
- console.warn('[warn] no canvas, measureText might be not accurate');
3665
- return this.estimate(tc);
3666
- }
3667
- return this.measureTextByCanvas(tc);
3471
+ scaleX(s = 0) {
3472
+ this.x1 *= s;
3473
+ this.x2 *= s;
3474
+ return this;
3668
3475
  }
3669
- measureTextByCanvas(tc) {
3670
- if (!this.ctx) {
3671
- console.error('[error!!!]measureTextByCanvas can not be called without canvas');
3672
- return { width: -1, height: tc.fontSize };
3673
- }
3674
- this.ctx.font = getContextFont$1(tc);
3675
- return {
3676
- width: this.ctx.measureText(tc.text).width,
3677
- height: tc.fontSize
3678
- };
3476
+ scaleY(s = 0) {
3477
+ this.y1 *= s;
3478
+ this.y2 *= s;
3479
+ return this;
3679
3480
  }
3680
- estimate({ text, fontSize }) {
3681
- let eCharLen = 0;
3682
- let cCharLen = 0;
3683
- for (let i = 0; i < text.length; i++) {
3684
- text.charCodeAt(i) < 128 ? eCharLen++ : cCharLen++;
3685
- }
3686
- return {
3687
- width: ~~(0.8 * eCharLen * fontSize + cCharLen * fontSize),
3688
- height: fontSize
3689
- };
3481
+ transformWithMatrix(matrix) {
3482
+ transformBoundsWithMatrix(this, this, matrix);
3483
+ return this;
3690
3484
  }
3691
- static getDefaultUtils(canvas) {
3692
- if (!GraphicUtil.instance) {
3693
- GraphicUtil.instance = new GraphicUtil(canvas);
3694
- }
3695
- return GraphicUtil.instance;
3485
+ copy(b) {
3486
+ this.x1 = b.x1;
3487
+ this.y1 = b.y1;
3488
+ this.x2 = b.x2;
3489
+ this.y2 = b.y2;
3490
+ return this;
3491
+ }
3492
+ rotatedPoints(angle, x, y) {
3493
+ const { x1, y1, x2, y2 } = this;
3494
+ const cos = Math.cos(angle);
3495
+ const sin = Math.sin(angle);
3496
+ const cx = x - x * cos + y * sin;
3497
+ const cy = y - x * sin - y * cos;
3498
+ return [
3499
+ cos * x1 - sin * y1 + cx,
3500
+ sin * x1 + cos * y1 + cy,
3501
+ cos * x1 - sin * y2 + cx,
3502
+ sin * x1 + cos * y2 + cy,
3503
+ cos * x2 - sin * y1 + cx,
3504
+ sin * x2 + cos * y1 + cy,
3505
+ cos * x2 - sin * y2 + cx,
3506
+ sin * x2 + cos * y2 + cy
3507
+ ];
3508
+ }
3509
+ scalePoints(sx, sy, x, y) {
3510
+ const { x1, y1, x2, y2 } = this;
3511
+ return [sx * x1 + (1 - sx) * x, sy * y1 + (1 - sy) * y, sx * x2 + (1 - sx) * x, sy * y2 + (1 - sy) * y];
3696
3512
  }
3697
3513
  }
3698
-
3699
- const EPSILON = 1e-8;
3700
- function lineIntersectPolygon(a1x, a1y, a2x, a2y, points) {
3701
- for (let i = 0, p2 = points[points.length - 1]; i < points.length; i++) {
3702
- const p = points[i];
3703
- if (isIntersect([a1x, a1y], [a2x, a2y], [p.x, p.y], [p2.x, p2.y])) {
3704
- return true;
3514
+ class AABBBounds extends Bounds {
3515
+ }
3516
+ class OBBBounds extends Bounds {
3517
+ constructor(bounds, angle = 0) {
3518
+ super(bounds);
3519
+ if (bounds) {
3520
+ this.angle = angle;
3705
3521
  }
3706
- p2 = p;
3707
3522
  }
3708
- return false;
3523
+ intersects(b) {
3524
+ return isRotateAABBIntersect(this, b);
3525
+ }
3526
+ setValue(x1 = 0, y1 = 0, x2 = 0, y2 = 0, angle = 0) {
3527
+ super.setValue(x1, y1, x2, y2);
3528
+ this.angle = angle;
3529
+ return this;
3530
+ }
3709
3531
  }
3710
- function polygonContainPoint(points, x, y) {
3711
- let w = 0;
3712
- let p = points[0];
3713
- if (!p) {
3714
- return false;
3532
+
3533
+ class Matrix {
3534
+ constructor(a = 1, b = 0, c = 0, d = 1, e = 0, f = 0) {
3535
+ this.a = a;
3536
+ this.b = b;
3537
+ this.c = c;
3538
+ this.d = d;
3539
+ this.e = e;
3540
+ this.f = f;
3715
3541
  }
3716
- for (let i = 1; i < points.length; i++) {
3717
- const p2 = points[i];
3718
- w += isPointInLine(p.x, p.y, p2.x, p2.y, x, y);
3719
- p = p2;
3542
+ equalToMatrix(m2) {
3543
+ return !(this.e !== m2.e ||
3544
+ this.f !== m2.f ||
3545
+ this.a !== m2.a ||
3546
+ this.d !== m2.d ||
3547
+ this.b !== m2.b ||
3548
+ this.c !== m2.c);
3720
3549
  }
3721
- const p0 = points[0];
3722
- if (!isAroundEqual(p.x, p0.x) || !isAroundEqual(p.y, p0.y)) {
3723
- w += isPointInLine(p.x, p.y, p0.x, p0.y, x, y);
3550
+ equalTo(a, b, c, d, e, f) {
3551
+ return !(this.e !== e || this.f !== f || this.a !== a || this.d !== d || this.b !== b || this.c !== c);
3552
+ }
3553
+ setValue(a, b, c, d, e, f) {
3554
+ this.a = a;
3555
+ this.b = b;
3556
+ this.c = c;
3557
+ this.d = d;
3558
+ this.e = e;
3559
+ this.f = f;
3560
+ return this;
3561
+ }
3562
+ reset() {
3563
+ this.a = 1;
3564
+ this.b = 0;
3565
+ this.c = 0;
3566
+ this.d = 1;
3567
+ this.e = 0;
3568
+ this.f = 0;
3569
+ return this;
3570
+ }
3571
+ getInverse() {
3572
+ const a = this.a;
3573
+ const b = this.b;
3574
+ const c = this.c;
3575
+ const d = this.d;
3576
+ const e = this.e;
3577
+ const f = this.f;
3578
+ const m = new Matrix();
3579
+ const dt = a * d - b * c;
3580
+ m.a = d / dt;
3581
+ m.b = -b / dt;
3582
+ m.c = -c / dt;
3583
+ m.d = a / dt;
3584
+ m.e = (c * f - d * e) / dt;
3585
+ m.f = -(a * f - b * e) / dt;
3586
+ return m;
3587
+ }
3588
+ rotate(rad) {
3589
+ const c = Math.cos(rad);
3590
+ const s = Math.sin(rad);
3591
+ const m11 = this.a * c + this.c * s;
3592
+ const m12 = this.b * c + this.d * s;
3593
+ const m21 = this.a * -s + this.c * c;
3594
+ const m22 = this.b * -s + this.d * c;
3595
+ this.a = m11;
3596
+ this.b = m12;
3597
+ this.c = m21;
3598
+ this.d = m22;
3599
+ return this;
3600
+ }
3601
+ rotateByCenter(rad, cx, cy) {
3602
+ const cos = Math.cos(rad);
3603
+ const sin = Math.sin(rad);
3604
+ const rotateM13 = (1 - cos) * cx + sin * cy;
3605
+ const rotateM23 = (1 - cos) * cy - sin * cx;
3606
+ const m11 = cos * this.a - sin * this.b;
3607
+ const m21 = sin * this.a + cos * this.b;
3608
+ const m12 = cos * this.c - sin * this.d;
3609
+ const m22 = sin * this.c + cos * this.d;
3610
+ const m13 = cos * this.e - sin * this.f + rotateM13;
3611
+ const m23 = sin * this.e + cos * this.f + rotateM23;
3612
+ this.a = m11;
3613
+ this.b = m21;
3614
+ this.c = m12;
3615
+ this.d = m22;
3616
+ this.e = m13;
3617
+ this.f = m23;
3618
+ return this;
3619
+ }
3620
+ scale(sx, sy) {
3621
+ this.a *= sx;
3622
+ this.b *= sx;
3623
+ this.c *= sy;
3624
+ this.d *= sy;
3625
+ return this;
3626
+ }
3627
+ setScale(sx, sy) {
3628
+ this.b = (this.b / this.a) * sx;
3629
+ this.c = (this.c / this.d) * sy;
3630
+ this.a = sx;
3631
+ this.d = sy;
3632
+ return this;
3633
+ }
3634
+ transform(a, b, c, d, e, f) {
3635
+ this.multiply(a, b, c, d, e, f);
3636
+ return this;
3637
+ }
3638
+ translate(x, y) {
3639
+ this.e += this.a * x + this.c * y;
3640
+ this.f += this.b * x + this.d * y;
3641
+ return this;
3642
+ }
3643
+ transpose() {
3644
+ const { a, b, c, d, e, f } = this;
3645
+ this.a = b;
3646
+ this.b = a;
3647
+ this.c = d;
3648
+ this.d = c;
3649
+ this.e = f;
3650
+ this.f = e;
3651
+ return this;
3652
+ }
3653
+ multiply(a2, b2, c2, d2, e2, f2) {
3654
+ const a1 = this.a;
3655
+ const b1 = this.b;
3656
+ const c1 = this.c;
3657
+ const d1 = this.d;
3658
+ const e1 = this.e;
3659
+ const f1 = this.f;
3660
+ const m11 = a1 * a2 + c1 * b2;
3661
+ const m12 = b1 * a2 + d1 * b2;
3662
+ const m21 = a1 * c2 + c1 * d2;
3663
+ const m22 = b1 * c2 + d1 * d2;
3664
+ const dx = a1 * e2 + c1 * f2 + e1;
3665
+ const dy = b1 * e2 + d1 * f2 + f1;
3666
+ this.a = m11;
3667
+ this.b = m12;
3668
+ this.c = m21;
3669
+ this.d = m22;
3670
+ this.e = dx;
3671
+ this.f = dy;
3672
+ return this;
3673
+ }
3674
+ interpolate(m2, t) {
3675
+ const m = new Matrix();
3676
+ m.a = this.a + (m2.a - this.a) * t;
3677
+ m.b = this.b + (m2.b - this.b) * t;
3678
+ m.c = this.c + (m2.c - this.c) * t;
3679
+ m.d = this.d + (m2.d - this.d) * t;
3680
+ m.e = this.e + (m2.e - this.e) * t;
3681
+ m.f = this.f + (m2.f - this.f) * t;
3682
+ return m;
3724
3683
  }
3725
- return w !== 0;
3726
- }
3727
- function isPointInLine(x0, y0, x1, y1, x, y) {
3728
- if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
3729
- return 0;
3684
+ transformPoint(source, target) {
3685
+ const { a, b, c, d, e, f } = this;
3686
+ const dt = a * d - b * c;
3687
+ const nextA = d / dt;
3688
+ const nextB = -b / dt;
3689
+ const nextC = -c / dt;
3690
+ const nextD = a / dt;
3691
+ const nextE = (c * f - d * e) / dt;
3692
+ const nextF = -(a * f - b * e) / dt;
3693
+ const { x, y } = source;
3694
+ target.x = x * nextA + y * nextC + nextE;
3695
+ target.y = x * nextB + y * nextD + nextF;
3730
3696
  }
3731
- if (y1 === y0) {
3732
- return 0;
3697
+ onlyTranslate(scale = 1) {
3698
+ return this.a === scale && this.b === 0 && this.c === 0 && this.d === scale;
3733
3699
  }
3734
- const t = (y - y0) / (y1 - y0);
3735
- let dir = y1 < y0 ? 1 : -1;
3736
- if (t === 1 || t === 0) {
3737
- dir = y1 < y0 ? 0.5 : -0.5;
3700
+ clone() {
3701
+ return new Matrix(this.a, this.b, this.c, this.d, this.e, this.f);
3738
3702
  }
3739
- const x_ = t * (x1 - x0) + x0;
3740
- return x_ === x ? Infinity : x_ > x ? dir : 0;
3741
- }
3742
- function isAroundEqual(a, b) {
3743
- return Math.abs(a - b) < EPSILON;
3744
- }
3745
- function polygonIntersectPolygon(pointsA, pointsB) {
3746
- for (let i = 0; i < pointsB.length; i++) {
3747
- if (polygonContainPoint(pointsA, pointsB[i].x, pointsB[i].y)) {
3748
- return true;
3703
+ toTransformAttrs() {
3704
+ const a = this.a;
3705
+ const b = this.b;
3706
+ const c = this.c;
3707
+ const d = this.d;
3708
+ const e = this.e;
3709
+ const f = this.f;
3710
+ const delta = a * d - b * c;
3711
+ const result = {
3712
+ x: e,
3713
+ y: f,
3714
+ rotateDeg: 0,
3715
+ scaleX: 0,
3716
+ scaleY: 0,
3717
+ skewX: 0,
3718
+ skewY: 0
3719
+ };
3720
+ if (a !== 0 || b !== 0) {
3721
+ const r = Math.sqrt(a * a + b * b);
3722
+ result.rotateDeg = b > 0 ? Math.acos(a / r) : -Math.acos(a / r);
3723
+ result.scaleX = r;
3724
+ result.scaleY = delta / r;
3725
+ result.skewX = (a * c + b * d) / delta;
3726
+ result.skewY = 0;
3749
3727
  }
3750
- if (i > 0 && lineIntersectPolygon(pointsB[i - 1].x, pointsB[i - 1].y, pointsB[i].x, pointsB[i].y, pointsA)) {
3751
- return true;
3728
+ else if (c !== 0 || d !== 0) {
3729
+ const s = Math.sqrt(c * c + d * d);
3730
+ result.rotateDeg = Math.PI / 2 - (d > 0 ? Math.acos(-c / s) : -Math.acos(c / s));
3731
+ result.scaleX = delta / s;
3732
+ result.scaleY = s;
3733
+ result.skewX = 0;
3734
+ result.skewY = (a * c + b * d) / delta;
3752
3735
  }
3736
+ else ;
3737
+ result.rotateDeg = radianToDegree(result.rotateDeg);
3738
+ return result;
3753
3739
  }
3754
- return false;
3755
3740
  }
3756
-
3757
- const calculateAnchorOfArc = (arcAttr, anchorType) => {
3758
- const { startAngle, endAngle, innerRadius, outerRadius } = arcAttr;
3759
- let angle = (startAngle + endAngle) / 2;
3760
- let radius = (innerRadius + outerRadius) / 2;
3761
- switch (anchorType) {
3762
- case 'inner-start':
3763
- angle = startAngle;
3764
- radius = innerRadius;
3765
- break;
3766
- case 'outer-start':
3767
- angle = startAngle;
3768
- radius = outerRadius;
3769
- break;
3770
- case 'inner-end':
3771
- angle = endAngle;
3772
- radius = innerRadius;
3773
- break;
3774
- case 'outer-end':
3775
- angle = endAngle;
3776
- radius = outerRadius;
3777
- break;
3778
- case 'inner-middle':
3779
- radius = innerRadius;
3780
- break;
3781
- case 'outer-middle':
3782
- radius = outerRadius;
3783
- break;
3741
+ function normalTransform(out, origin, x, y, scaleX, scaleY, angle, rotateCenter) {
3742
+ const oa = origin.a;
3743
+ const ob = origin.b;
3744
+ const oc = origin.c;
3745
+ const od = origin.d;
3746
+ const oe = origin.e;
3747
+ const of = origin.f;
3748
+ const cosTheta = cos(angle);
3749
+ const sinTheta = sin(angle);
3750
+ let rotateCenterX;
3751
+ let rotateCenterY;
3752
+ if (rotateCenter) {
3753
+ rotateCenterX = rotateCenter[0];
3754
+ rotateCenterY = rotateCenter[1];
3784
3755
  }
3785
- return { angle, radius };
3786
- };
3787
-
3788
- function stringWidth(string, ambiguousCharacterIsNarrow = true) {
3789
- if (typeof string !== 'string' || string.length === 0) {
3790
- return 0;
3756
+ else {
3757
+ rotateCenterX = x;
3758
+ rotateCenterY = y;
3791
3759
  }
3792
- string = stripAnsi(string);
3793
- if (string.length === 0) {
3794
- return 0;
3760
+ const offsetX = rotateCenterX - x;
3761
+ const offsetY = rotateCenterY - y;
3762
+ const a1 = oa * cosTheta + oc * sinTheta;
3763
+ const b1 = ob * cosTheta + od * sinTheta;
3764
+ const c1 = oc * cosTheta - oa * sinTheta;
3765
+ const d1 = od * cosTheta - ob * sinTheta;
3766
+ out.a = scaleX * a1;
3767
+ out.b = scaleX * b1;
3768
+ out.c = scaleY * c1;
3769
+ out.d = scaleY * d1;
3770
+ out.e = oe + oa * rotateCenterX + oc * rotateCenterY - a1 * offsetX - c1 * offsetY;
3771
+ out.f = of + ob * rotateCenterX + od * rotateCenterY - b1 * offsetX - d1 * offsetY;
3772
+ }
3773
+
3774
+ class LRU {
3775
+ constructor() {
3776
+ this.CLEAN_THRESHOLD = 1e3;
3777
+ this.L_TIME = 1000;
3778
+ this.R_COUNT = 1;
3779
+ this.R_TIMESTAMP_MAX_SIZE = 20;
3795
3780
  }
3796
- string = string.replace(emojiRegex(), ' ');
3797
- const ambiguousCharacterWidth = ambiguousCharacterIsNarrow ? 1 : 2;
3798
- let width = 0;
3799
- for (const character of string) {
3800
- const codePoint = character.codePointAt(0);
3801
- if (codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f)) {
3802
- continue;
3781
+ clearCache(cache, params) {
3782
+ const { CLEAN_THRESHOLD = this.CLEAN_THRESHOLD, L_TIME = this.L_TIME, R_COUNT = this.R_COUNT } = params;
3783
+ if (cache.size < CLEAN_THRESHOLD) {
3784
+ return 0;
3803
3785
  }
3804
- if (codePoint >= 0x300 && codePoint <= 0x36f) {
3805
- continue;
3786
+ let clearNum = 0;
3787
+ const clear = (key) => {
3788
+ clearNum++;
3789
+ cache.delete(key);
3790
+ };
3791
+ const now = Date.now();
3792
+ cache.forEach((item, key) => {
3793
+ if (item.timestamp.length < R_COUNT) {
3794
+ return clear(key);
3795
+ }
3796
+ let useCount = 0;
3797
+ while (now - item.timestamp[item.timestamp.length - 1 - useCount] < L_TIME) {
3798
+ useCount++;
3799
+ if (useCount >= R_COUNT) {
3800
+ break;
3801
+ }
3802
+ }
3803
+ if (useCount < R_COUNT) {
3804
+ return clear(key);
3805
+ }
3806
+ while (now - item.timestamp[0] > L_TIME) {
3807
+ item.timestamp.shift();
3808
+ }
3809
+ return;
3810
+ });
3811
+ return clearNum;
3812
+ }
3813
+ addLimitedTimestamp(cacheItem, t, params) {
3814
+ const { R_TIMESTAMP_MAX_SIZE = this.R_TIMESTAMP_MAX_SIZE } = params;
3815
+ if (cacheItem.timestamp.length > R_TIMESTAMP_MAX_SIZE) {
3816
+ cacheItem.timestamp.shift();
3806
3817
  }
3807
- const code = eastAsianCharacterInfo(character);
3808
- switch (code) {
3809
- case 'F':
3810
- case 'W':
3811
- width += 2;
3812
- break;
3813
- case 'A':
3814
- width += ambiguousCharacterWidth;
3815
- break;
3816
- default:
3817
- width += 1;
3818
+ cacheItem.timestamp.push(t);
3819
+ }
3820
+ clearTimeStamp(cache, params) {
3821
+ const { L_TIME = this.L_TIME } = params;
3822
+ const now = Date.now();
3823
+ cache.forEach(item => {
3824
+ while (now - item.timestamp[0] > L_TIME) {
3825
+ item.timestamp.shift();
3826
+ }
3827
+ });
3828
+ }
3829
+ clearItemTimestamp(cacheItem, params) {
3830
+ const { L_TIME = this.L_TIME } = params;
3831
+ const now = Date.now();
3832
+ while (now - cacheItem.timestamp[0] > L_TIME) {
3833
+ cacheItem.timestamp.shift();
3818
3834
  }
3819
3835
  }
3820
- return width;
3821
3836
  }
3822
- const stripAnsi = (string) => {
3823
- if (typeof string !== 'string') {
3824
- throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
3825
- }
3826
- return string.replace(ansiRegex(), '');
3827
- };
3828
- const ansiRegex = ({ onlyFirst = false } = {}) => {
3829
- const pattern = [
3830
- '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
3831
- '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))'
3832
- ].join('|');
3833
- return new RegExp(pattern, onlyFirst ? undefined : 'g');
3834
- };
3835
- const eastAsianCharacterInfo = (character) => {
3836
- let x = character.charCodeAt(0);
3837
- let y = character.length === 2 ? character.charCodeAt(1) : 0;
3838
- let codePoint = x;
3839
- if (0xd800 <= x && x <= 0xdbff && 0xdc00 <= y && y <= 0xdfff) {
3840
- x &= 0x3ff;
3841
- y &= 0x3ff;
3842
- codePoint = (x << 10) | y;
3843
- codePoint += 0x10000;
3837
+
3838
+ function hslToRgb(h, s, l) {
3839
+ s /= 100;
3840
+ l /= 100;
3841
+ const c = (1 - Math.abs(2 * l - 1)) * s;
3842
+ const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
3843
+ const m = l - c / 2;
3844
+ let r = 0;
3845
+ let g = 0;
3846
+ let b = 0;
3847
+ if (0 <= h && h < 60) {
3848
+ r = c;
3849
+ g = x;
3850
+ b = 0;
3844
3851
  }
3845
- if (0x3000 === codePoint ||
3846
- (0xff01 <= codePoint && codePoint <= 0xff60) ||
3847
- (0xffe0 <= codePoint && codePoint <= 0xffe6)) {
3848
- return 'F';
3852
+ else if (60 <= h && h < 120) {
3853
+ r = x;
3854
+ g = c;
3855
+ b = 0;
3849
3856
  }
3850
- if (0x20a9 === codePoint ||
3851
- (0xff61 <= codePoint && codePoint <= 0xffbe) ||
3852
- (0xffc2 <= codePoint && codePoint <= 0xffc7) ||
3853
- (0xffca <= codePoint && codePoint <= 0xffcf) ||
3854
- (0xffd2 <= codePoint && codePoint <= 0xffd7) ||
3855
- (0xffda <= codePoint && codePoint <= 0xffdc) ||
3856
- (0xffe8 <= codePoint && codePoint <= 0xffee)) {
3857
- return 'H';
3857
+ else if (120 <= h && h < 180) {
3858
+ r = 0;
3859
+ g = c;
3860
+ b = x;
3858
3861
  }
3859
- if ((0x1100 <= codePoint && codePoint <= 0x115f) ||
3860
- (0x11a3 <= codePoint && codePoint <= 0x11a7) ||
3861
- (0x11fa <= codePoint && codePoint <= 0x11ff) ||
3862
- (0x2329 <= codePoint && codePoint <= 0x232a) ||
3863
- (0x2e80 <= codePoint && codePoint <= 0x2e99) ||
3864
- (0x2e9b <= codePoint && codePoint <= 0x2ef3) ||
3865
- (0x2f00 <= codePoint && codePoint <= 0x2fd5) ||
3866
- (0x2ff0 <= codePoint && codePoint <= 0x2ffb) ||
3867
- (0x3001 <= codePoint && codePoint <= 0x303e) ||
3868
- (0x3041 <= codePoint && codePoint <= 0x3096) ||
3869
- (0x3099 <= codePoint && codePoint <= 0x30ff) ||
3870
- (0x3105 <= codePoint && codePoint <= 0x312d) ||
3871
- (0x3131 <= codePoint && codePoint <= 0x318e) ||
3872
- (0x3190 <= codePoint && codePoint <= 0x31ba) ||
3873
- (0x31c0 <= codePoint && codePoint <= 0x31e3) ||
3874
- (0x31f0 <= codePoint && codePoint <= 0x321e) ||
3875
- (0x3220 <= codePoint && codePoint <= 0x3247) ||
3876
- (0x3250 <= codePoint && codePoint <= 0x32fe) ||
3877
- (0x3300 <= codePoint && codePoint <= 0x4dbf) ||
3878
- (0x4e00 <= codePoint && codePoint <= 0xa48c) ||
3879
- (0xa490 <= codePoint && codePoint <= 0xa4c6) ||
3880
- (0xa960 <= codePoint && codePoint <= 0xa97c) ||
3881
- (0xac00 <= codePoint && codePoint <= 0xd7a3) ||
3882
- (0xd7b0 <= codePoint && codePoint <= 0xd7c6) ||
3883
- (0xd7cb <= codePoint && codePoint <= 0xd7fb) ||
3884
- (0xf900 <= codePoint && codePoint <= 0xfaff) ||
3885
- (0xfe10 <= codePoint && codePoint <= 0xfe19) ||
3886
- (0xfe30 <= codePoint && codePoint <= 0xfe52) ||
3887
- (0xfe54 <= codePoint && codePoint <= 0xfe66) ||
3888
- (0xfe68 <= codePoint && codePoint <= 0xfe6b) ||
3889
- (0x1b000 <= codePoint && codePoint <= 0x1b001) ||
3890
- (0x1f200 <= codePoint && codePoint <= 0x1f202) ||
3891
- (0x1f210 <= codePoint && codePoint <= 0x1f23a) ||
3892
- (0x1f240 <= codePoint && codePoint <= 0x1f248) ||
3893
- (0x1f250 <= codePoint && codePoint <= 0x1f251) ||
3894
- (0x20000 <= codePoint && codePoint <= 0x2f73f) ||
3895
- (0x2b740 <= codePoint && codePoint <= 0x2fffd) ||
3896
- (0x30000 <= codePoint && codePoint <= 0x3fffd)) {
3897
- return 'W';
3862
+ else if (180 <= h && h < 240) {
3863
+ r = 0;
3864
+ g = x;
3865
+ b = c;
3898
3866
  }
3899
- if ((0x0020 <= codePoint && codePoint <= 0x007e) ||
3900
- (0x00a2 <= codePoint && codePoint <= 0x00a3) ||
3901
- (0x00a5 <= codePoint && codePoint <= 0x00a6) ||
3902
- 0x00ac === codePoint ||
3903
- 0x00af === codePoint ||
3904
- (0x27e6 <= codePoint && codePoint <= 0x27ed) ||
3905
- (0x2985 <= codePoint && codePoint <= 0x2986)) {
3906
- return 'Na';
3867
+ else if (240 <= h && h < 300) {
3868
+ r = x;
3869
+ g = 0;
3870
+ b = c;
3907
3871
  }
3908
- if (0x00a1 === codePoint ||
3909
- 0x00a4 === codePoint ||
3910
- (0x00a7 <= codePoint && codePoint <= 0x00a8) ||
3911
- 0x00aa === codePoint ||
3912
- (0x00ad <= codePoint && codePoint <= 0x00ae) ||
3913
- (0x00b0 <= codePoint && codePoint <= 0x00b4) ||
3914
- (0x00b6 <= codePoint && codePoint <= 0x00ba) ||
3915
- (0x00bc <= codePoint && codePoint <= 0x00bf) ||
3916
- 0x00c6 === codePoint ||
3917
- 0x00d0 === codePoint ||
3918
- (0x00d7 <= codePoint && codePoint <= 0x00d8) ||
3919
- (0x00de <= codePoint && codePoint <= 0x00e1) ||
3920
- 0x00e6 === codePoint ||
3921
- (0x00e8 <= codePoint && codePoint <= 0x00ea) ||
3922
- (0x00ec <= codePoint && codePoint <= 0x00ed) ||
3923
- 0x00f0 === codePoint ||
3924
- (0x00f2 <= codePoint && codePoint <= 0x00f3) ||
3925
- (0x00f7 <= codePoint && codePoint <= 0x00fa) ||
3926
- 0x00fc === codePoint ||
3927
- 0x00fe === codePoint ||
3928
- 0x0101 === codePoint ||
3929
- 0x0111 === codePoint ||
3930
- 0x0113 === codePoint ||
3931
- 0x011b === codePoint ||
3932
- (0x0126 <= codePoint && codePoint <= 0x0127) ||
3933
- 0x012b === codePoint ||
3934
- (0x0131 <= codePoint && codePoint <= 0x0133) ||
3935
- 0x0138 === codePoint ||
3936
- (0x013f <= codePoint && codePoint <= 0x0142) ||
3937
- 0x0144 === codePoint ||
3938
- (0x0148 <= codePoint && codePoint <= 0x014b) ||
3939
- 0x014d === codePoint ||
3940
- (0x0152 <= codePoint && codePoint <= 0x0153) ||
3941
- (0x0166 <= codePoint && codePoint <= 0x0167) ||
3942
- 0x016b === codePoint ||
3943
- 0x01ce === codePoint ||
3944
- 0x01d0 === codePoint ||
3945
- 0x01d2 === codePoint ||
3946
- 0x01d4 === codePoint ||
3947
- 0x01d6 === codePoint ||
3948
- 0x01d8 === codePoint ||
3949
- 0x01da === codePoint ||
3950
- 0x01dc === codePoint ||
3951
- 0x0251 === codePoint ||
3952
- 0x0261 === codePoint ||
3953
- 0x02c4 === codePoint ||
3954
- 0x02c7 === codePoint ||
3955
- (0x02c9 <= codePoint && codePoint <= 0x02cb) ||
3956
- 0x02cd === codePoint ||
3957
- 0x02d0 === codePoint ||
3958
- (0x02d8 <= codePoint && codePoint <= 0x02db) ||
3959
- 0x02dd === codePoint ||
3960
- 0x02df === codePoint ||
3961
- (0x0300 <= codePoint && codePoint <= 0x036f) ||
3962
- (0x0391 <= codePoint && codePoint <= 0x03a1) ||
3963
- (0x03a3 <= codePoint && codePoint <= 0x03a9) ||
3964
- (0x03b1 <= codePoint && codePoint <= 0x03c1) ||
3965
- (0x03c3 <= codePoint && codePoint <= 0x03c9) ||
3966
- 0x0401 === codePoint ||
3967
- (0x0410 <= codePoint && codePoint <= 0x044f) ||
3968
- 0x0451 === codePoint ||
3969
- 0x2010 === codePoint ||
3970
- (0x2013 <= codePoint && codePoint <= 0x2016) ||
3971
- (0x2018 <= codePoint && codePoint <= 0x2019) ||
3972
- (0x201c <= codePoint && codePoint <= 0x201d) ||
3973
- (0x2020 <= codePoint && codePoint <= 0x2022) ||
3974
- (0x2024 <= codePoint && codePoint <= 0x2027) ||
3975
- 0x2030 === codePoint ||
3976
- (0x2032 <= codePoint && codePoint <= 0x2033) ||
3977
- 0x2035 === codePoint ||
3978
- 0x203b === codePoint ||
3979
- 0x203e === codePoint ||
3980
- 0x2074 === codePoint ||
3981
- 0x207f === codePoint ||
3982
- (0x2081 <= codePoint && codePoint <= 0x2084) ||
3983
- 0x20ac === codePoint ||
3984
- 0x2103 === codePoint ||
3985
- 0x2105 === codePoint ||
3986
- 0x2109 === codePoint ||
3987
- 0x2113 === codePoint ||
3988
- 0x2116 === codePoint ||
3989
- (0x2121 <= codePoint && codePoint <= 0x2122) ||
3990
- 0x2126 === codePoint ||
3991
- 0x212b === codePoint ||
3992
- (0x2153 <= codePoint && codePoint <= 0x2154) ||
3993
- (0x215b <= codePoint && codePoint <= 0x215e) ||
3994
- (0x2160 <= codePoint && codePoint <= 0x216b) ||
3995
- (0x2170 <= codePoint && codePoint <= 0x2179) ||
3996
- 0x2189 === codePoint ||
3997
- (0x2190 <= codePoint && codePoint <= 0x2199) ||
3998
- (0x21b8 <= codePoint && codePoint <= 0x21b9) ||
3999
- 0x21d2 === codePoint ||
4000
- 0x21d4 === codePoint ||
4001
- 0x21e7 === codePoint ||
4002
- 0x2200 === codePoint ||
4003
- (0x2202 <= codePoint && codePoint <= 0x2203) ||
4004
- (0x2207 <= codePoint && codePoint <= 0x2208) ||
4005
- 0x220b === codePoint ||
4006
- 0x220f === codePoint ||
4007
- 0x2211 === codePoint ||
4008
- 0x2215 === codePoint ||
4009
- 0x221a === codePoint ||
4010
- (0x221d <= codePoint && codePoint <= 0x2220) ||
4011
- 0x2223 === codePoint ||
4012
- 0x2225 === codePoint ||
4013
- (0x2227 <= codePoint && codePoint <= 0x222c) ||
4014
- 0x222e === codePoint ||
4015
- (0x2234 <= codePoint && codePoint <= 0x2237) ||
4016
- (0x223c <= codePoint && codePoint <= 0x223d) ||
4017
- 0x2248 === codePoint ||
4018
- 0x224c === codePoint ||
4019
- 0x2252 === codePoint ||
4020
- (0x2260 <= codePoint && codePoint <= 0x2261) ||
4021
- (0x2264 <= codePoint && codePoint <= 0x2267) ||
4022
- (0x226a <= codePoint && codePoint <= 0x226b) ||
4023
- (0x226e <= codePoint && codePoint <= 0x226f) ||
4024
- (0x2282 <= codePoint && codePoint <= 0x2283) ||
4025
- (0x2286 <= codePoint && codePoint <= 0x2287) ||
4026
- 0x2295 === codePoint ||
4027
- 0x2299 === codePoint ||
4028
- 0x22a5 === codePoint ||
4029
- 0x22bf === codePoint ||
4030
- 0x2312 === codePoint ||
4031
- (0x2460 <= codePoint && codePoint <= 0x24e9) ||
4032
- (0x24eb <= codePoint && codePoint <= 0x254b) ||
4033
- (0x2550 <= codePoint && codePoint <= 0x2573) ||
4034
- (0x2580 <= codePoint && codePoint <= 0x258f) ||
4035
- (0x2592 <= codePoint && codePoint <= 0x2595) ||
4036
- (0x25a0 <= codePoint && codePoint <= 0x25a1) ||
4037
- (0x25a3 <= codePoint && codePoint <= 0x25a9) ||
4038
- (0x25b2 <= codePoint && codePoint <= 0x25b3) ||
4039
- (0x25b6 <= codePoint && codePoint <= 0x25b7) ||
4040
- (0x25bc <= codePoint && codePoint <= 0x25bd) ||
4041
- (0x25c0 <= codePoint && codePoint <= 0x25c1) ||
4042
- (0x25c6 <= codePoint && codePoint <= 0x25c8) ||
4043
- 0x25cb === codePoint ||
4044
- (0x25ce <= codePoint && codePoint <= 0x25d1) ||
4045
- (0x25e2 <= codePoint && codePoint <= 0x25e5) ||
4046
- 0x25ef === codePoint ||
4047
- (0x2605 <= codePoint && codePoint <= 0x2606) ||
4048
- 0x2609 === codePoint ||
4049
- (0x260e <= codePoint && codePoint <= 0x260f) ||
4050
- (0x2614 <= codePoint && codePoint <= 0x2615) ||
4051
- 0x261c === codePoint ||
4052
- 0x261e === codePoint ||
4053
- 0x2640 === codePoint ||
4054
- 0x2642 === codePoint ||
4055
- (0x2660 <= codePoint && codePoint <= 0x2661) ||
4056
- (0x2663 <= codePoint && codePoint <= 0x2665) ||
4057
- (0x2667 <= codePoint && codePoint <= 0x266a) ||
4058
- (0x266c <= codePoint && codePoint <= 0x266d) ||
4059
- 0x266f === codePoint ||
4060
- (0x269e <= codePoint && codePoint <= 0x269f) ||
4061
- (0x26be <= codePoint && codePoint <= 0x26bf) ||
4062
- (0x26c4 <= codePoint && codePoint <= 0x26cd) ||
4063
- (0x26cf <= codePoint && codePoint <= 0x26e1) ||
4064
- 0x26e3 === codePoint ||
4065
- (0x26e8 <= codePoint && codePoint <= 0x26ff) ||
4066
- 0x273d === codePoint ||
4067
- 0x2757 === codePoint ||
4068
- (0x2776 <= codePoint && codePoint <= 0x277f) ||
4069
- (0x2b55 <= codePoint && codePoint <= 0x2b59) ||
4070
- (0x3248 <= codePoint && codePoint <= 0x324f) ||
4071
- (0xe000 <= codePoint && codePoint <= 0xf8ff) ||
4072
- (0xfe00 <= codePoint && codePoint <= 0xfe0f) ||
4073
- 0xfffd === codePoint ||
4074
- (0x1f100 <= codePoint && codePoint <= 0x1f10a) ||
4075
- (0x1f110 <= codePoint && codePoint <= 0x1f12d) ||
4076
- (0x1f130 <= codePoint && codePoint <= 0x1f169) ||
4077
- (0x1f170 <= codePoint && codePoint <= 0x1f19a) ||
4078
- (0xe0100 <= codePoint && codePoint <= 0xe01ef) ||
4079
- (0xf0000 <= codePoint && codePoint <= 0xffffd) ||
4080
- (0x100000 <= codePoint && codePoint <= 0x10fffd)) {
4081
- return 'A';
3872
+ else if (300 <= h && h < 360) {
3873
+ r = c;
3874
+ g = 0;
3875
+ b = x;
3876
+ }
3877
+ r = Math.round((r + m) * 255);
3878
+ g = Math.round((g + m) * 255);
3879
+ b = Math.round((b + m) * 255);
3880
+ return { r, g, b };
3881
+ }
3882
+
3883
+ function rgbToHsl(r, g, b) {
3884
+ r /= 255;
3885
+ g /= 255;
3886
+ b /= 255;
3887
+ const cMin = Math.min(r, g, b);
3888
+ const cMax = Math.max(r, g, b);
3889
+ const delta = cMax - cMin;
3890
+ let h = 0;
3891
+ let s = 0;
3892
+ let l = 0;
3893
+ if (delta === 0) {
3894
+ h = 0;
4082
3895
  }
4083
- return 'N';
3896
+ else if (cMax === r) {
3897
+ h = ((g - b) / delta) % 6;
3898
+ }
3899
+ else if (cMax === g) {
3900
+ h = (b - r) / delta + 2;
3901
+ }
3902
+ else {
3903
+ h = (r - g) / delta + 4;
3904
+ }
3905
+ h = Math.round(h * 60);
3906
+ if (h < 0) {
3907
+ h += 360;
3908
+ }
3909
+ l = (cMax + cMin) / 2;
3910
+ s = delta === 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));
3911
+ s = +(s * 100).toFixed(1);
3912
+ l = +(l * 100).toFixed(1);
3913
+ return {
3914
+ h,
3915
+ s,
3916
+ l
3917
+ };
3918
+ }
3919
+
3920
+ const REG_HEX = /^#([0-9a-f]{3,8})$/;
3921
+ const DEFAULT_COLORS_OPACITY = {
3922
+ transparent: 0xffffff00
4084
3923
  };
4085
- const emojiRegex = () => {
4086
- return /[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26F9(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC3\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC08\uDC26](?:\u200D\u2B1B)?|[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE])))?))?|\uDC6F(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDD75(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE88\uDE90-\uDEBD\uDEBF-\uDEC2\uDECE-\uDEDB\uDEE0-\uDEE8]|\uDD3C(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF])?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g;
3924
+ const DEFAULT_COLORS = {
3925
+ aliceblue: 0xf0f8ff,
3926
+ antiquewhite: 0xfaebd7,
3927
+ aqua: 0x00ffff,
3928
+ aquamarine: 0x7fffd4,
3929
+ azure: 0xf0ffff,
3930
+ beige: 0xf5f5dc,
3931
+ bisque: 0xffe4c4,
3932
+ black: 0x000000,
3933
+ blanchedalmond: 0xffebcd,
3934
+ blue: 0x0000ff,
3935
+ blueviolet: 0x8a2be2,
3936
+ brown: 0xa52a2a,
3937
+ burlywood: 0xdeb887,
3938
+ cadetblue: 0x5f9ea0,
3939
+ chartreuse: 0x7fff00,
3940
+ chocolate: 0xd2691e,
3941
+ coral: 0xff7f50,
3942
+ cornflowerblue: 0x6495ed,
3943
+ cornsilk: 0xfff8dc,
3944
+ crimson: 0xdc143c,
3945
+ cyan: 0x00ffff,
3946
+ darkblue: 0x00008b,
3947
+ darkcyan: 0x008b8b,
3948
+ darkgoldenrod: 0xb8860b,
3949
+ darkgray: 0xa9a9a9,
3950
+ darkgreen: 0x006400,
3951
+ darkgrey: 0xa9a9a9,
3952
+ darkkhaki: 0xbdb76b,
3953
+ darkmagenta: 0x8b008b,
3954
+ darkolivegreen: 0x556b2f,
3955
+ darkorange: 0xff8c00,
3956
+ darkorchid: 0x9932cc,
3957
+ darkred: 0x8b0000,
3958
+ darksalmon: 0xe9967a,
3959
+ darkseagreen: 0x8fbc8f,
3960
+ darkslateblue: 0x483d8b,
3961
+ darkslategray: 0x2f4f4f,
3962
+ darkslategrey: 0x2f4f4f,
3963
+ darkturquoise: 0x00ced1,
3964
+ darkviolet: 0x9400d3,
3965
+ deeppink: 0xff1493,
3966
+ deepskyblue: 0x00bfff,
3967
+ dimgray: 0x696969,
3968
+ dimgrey: 0x696969,
3969
+ dodgerblue: 0x1e90ff,
3970
+ firebrick: 0xb22222,
3971
+ floralwhite: 0xfffaf0,
3972
+ forestgreen: 0x228b22,
3973
+ fuchsia: 0xff00ff,
3974
+ gainsboro: 0xdcdcdc,
3975
+ ghostwhite: 0xf8f8ff,
3976
+ gold: 0xffd700,
3977
+ goldenrod: 0xdaa520,
3978
+ gray: 0x808080,
3979
+ green: 0x008000,
3980
+ greenyellow: 0xadff2f,
3981
+ grey: 0x808080,
3982
+ honeydew: 0xf0fff0,
3983
+ hotpink: 0xff69b4,
3984
+ indianred: 0xcd5c5c,
3985
+ indigo: 0x4b0082,
3986
+ ivory: 0xfffff0,
3987
+ khaki: 0xf0e68c,
3988
+ lavender: 0xe6e6fa,
3989
+ lavenderblush: 0xfff0f5,
3990
+ lawngreen: 0x7cfc00,
3991
+ lemonchiffon: 0xfffacd,
3992
+ lightblue: 0xadd8e6,
3993
+ lightcoral: 0xf08080,
3994
+ lightcyan: 0xe0ffff,
3995
+ lightgoldenrodyellow: 0xfafad2,
3996
+ lightgray: 0xd3d3d3,
3997
+ lightgreen: 0x90ee90,
3998
+ lightgrey: 0xd3d3d3,
3999
+ lightpink: 0xffb6c1,
4000
+ lightsalmon: 0xffa07a,
4001
+ lightseagreen: 0x20b2aa,
4002
+ lightskyblue: 0x87cefa,
4003
+ lightslategray: 0x778899,
4004
+ lightslategrey: 0x778899,
4005
+ lightsteelblue: 0xb0c4de,
4006
+ lightyellow: 0xffffe0,
4007
+ lime: 0x00ff00,
4008
+ limegreen: 0x32cd32,
4009
+ linen: 0xfaf0e6,
4010
+ magenta: 0xff00ff,
4011
+ maroon: 0x800000,
4012
+ mediumaquamarine: 0x66cdaa,
4013
+ mediumblue: 0x0000cd,
4014
+ mediumorchid: 0xba55d3,
4015
+ mediumpurple: 0x9370db,
4016
+ mediumseagreen: 0x3cb371,
4017
+ mediumslateblue: 0x7b68ee,
4018
+ mediumspringgreen: 0x00fa9a,
4019
+ mediumturquoise: 0x48d1cc,
4020
+ mediumvioletred: 0xc71585,
4021
+ midnightblue: 0x191970,
4022
+ mintcream: 0xf5fffa,
4023
+ mistyrose: 0xffe4e1,
4024
+ moccasin: 0xffe4b5,
4025
+ navajowhite: 0xffdead,
4026
+ navy: 0x000080,
4027
+ oldlace: 0xfdf5e6,
4028
+ olive: 0x808000,
4029
+ olivedrab: 0x6b8e23,
4030
+ orange: 0xffa500,
4031
+ orangered: 0xff4500,
4032
+ orchid: 0xda70d6,
4033
+ palegoldenrod: 0xeee8aa,
4034
+ palegreen: 0x98fb98,
4035
+ paleturquoise: 0xafeeee,
4036
+ palevioletred: 0xdb7093,
4037
+ papayawhip: 0xffefd5,
4038
+ peachpuff: 0xffdab9,
4039
+ peru: 0xcd853f,
4040
+ pink: 0xffc0cb,
4041
+ plum: 0xdda0dd,
4042
+ powderblue: 0xb0e0e6,
4043
+ purple: 0x800080,
4044
+ rebeccapurple: 0x663399,
4045
+ red: 0xff0000,
4046
+ rosybrown: 0xbc8f8f,
4047
+ royalblue: 0x4169e1,
4048
+ saddlebrown: 0x8b4513,
4049
+ salmon: 0xfa8072,
4050
+ sandybrown: 0xf4a460,
4051
+ seagreen: 0x2e8b57,
4052
+ seashell: 0xfff5ee,
4053
+ sienna: 0xa0522d,
4054
+ silver: 0xc0c0c0,
4055
+ skyblue: 0x87ceeb,
4056
+ slateblue: 0x6a5acd,
4057
+ slategray: 0x708090,
4058
+ slategrey: 0x708090,
4059
+ snow: 0xfffafa,
4060
+ springgreen: 0x00ff7f,
4061
+ steelblue: 0x4682b4,
4062
+ tan: 0xd2b48c,
4063
+ teal: 0x008080,
4064
+ thistle: 0xd8bfd8,
4065
+ tomato: 0xff6347,
4066
+ turquoise: 0x40e0d0,
4067
+ violet: 0xee82ee,
4068
+ wheat: 0xf5deb3,
4069
+ white: 0xffffff,
4070
+ whitesmoke: 0xf5f5f5,
4071
+ yellow: 0xffff00,
4072
+ yellowgreen: 0x9acd32
4087
4073
  };
4088
-
4089
- function getContextFont(text, defaultAttr = {}, fontSizeScale) {
4090
- if (!fontSizeScale) {
4091
- fontSizeScale = 1;
4074
+ function hex(value) {
4075
+ value = Math.max(0, Math.min(255, Math.round(value) || 0));
4076
+ return (value < 16 ? '0' : '') + value.toString(16);
4077
+ }
4078
+ function rgb(value) {
4079
+ if (isNumber(value)) {
4080
+ return new RGB(value >> 16, (value >> 8) & 0xff, value & 0xff, 1);
4092
4081
  }
4093
- const { fontStyle = defaultAttr.fontStyle, fontVariant = defaultAttr.fontVariant, fontWeight = defaultAttr.fontWeight, fontSize = defaultAttr.fontSize, fontFamily = defaultAttr.fontFamily } = text;
4094
- return ('' +
4095
- (fontStyle ? fontStyle + ' ' : '') +
4096
- (fontVariant ? fontVariant + ' ' : '') +
4097
- (fontWeight ? fontWeight + ' ' : '') +
4098
- fontSize * fontSizeScale +
4099
- 'px ' +
4100
- (fontFamily ? fontFamily : 'sans-serif'));
4082
+ else if (isArray(value)) {
4083
+ return new RGB(value[0], value[1], value[2]);
4084
+ }
4085
+ return new RGB(255, 255, 255);
4101
4086
  }
4102
-
4103
- class TextMeasure {
4104
- constructor(option, textSpec) {
4105
- this._numberCharSize = null;
4106
- this._fullCharSize = null;
4107
- this._letterCharSize = null;
4108
- this._specialCharSizeMap = {};
4109
- this._canvas = null;
4110
- this._context = null;
4111
- this._contextSaved = false;
4112
- this._notSupportCanvas = false;
4113
- this._notSupportVRender = false;
4114
- this._userSpec = {};
4115
- this.specialCharSet = '-/: .,@%\'"~';
4116
- this._option = option;
4117
- this._userSpec = textSpec !== null && textSpec !== void 0 ? textSpec : {};
4118
- this.textSpec = this._initSpec();
4119
- if (isValid(option.specialCharSet)) {
4120
- this.specialCharSet = option.specialCharSet;
4121
- }
4122
- this._standardMethod = isValid(option.getTextBounds)
4123
- ? this.fullMeasure.bind(this)
4124
- : this.measureWithNaiveCanvas.bind(this);
4087
+ function rgba(value) {
4088
+ if (isNumber(value)) {
4089
+ return new RGB(value >>> 24, (value >>> 16) & 0xff, (value >>> 8) & 0xff, value & 0xff);
4125
4090
  }
4126
- initContext() {
4127
- if (this._notSupportCanvas) {
4128
- return false;
4091
+ else if (isArray(value)) {
4092
+ return new RGB(value[0], value[1], value[2], value[3]);
4093
+ }
4094
+ return new RGB(255, 255, 255, 1);
4095
+ }
4096
+ function SRGBToLinear(c) {
4097
+ return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
4098
+ }
4099
+ function LinearToSRGB(c) {
4100
+ return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
4101
+ }
4102
+ const setHex = (formatValue, forceHex) => {
4103
+ const isHex = REG_HEX.exec(formatValue);
4104
+ if (forceHex || isHex) {
4105
+ const hex = parseInt(isHex[1], 16);
4106
+ const hexLength = isHex[1].length;
4107
+ if (hexLength === 3) {
4108
+ return new RGB(((hex >> 8) & 0xf) + (((hex >> 8) & 0xf) << 4), ((hex >> 4) & 0xf) + (((hex >> 4) & 0xf) << 4), (hex & 0xf) + ((hex & 0xf) << 4), 1);
4129
4109
  }
4130
- if (isNil(this._canvas)) {
4131
- if (isValid(this._option.getCanvasForMeasure)) {
4132
- this._canvas = this._option.getCanvasForMeasure();
4133
- }
4134
- if (isNil(this._canvas) &&
4135
- typeof window !== 'undefined' &&
4136
- typeof window.document !== 'undefined' &&
4137
- globalThis &&
4138
- isValid(globalThis.document)) {
4139
- this._canvas = globalThis.document.createElement('canvas');
4140
- }
4110
+ if (hexLength === 6) {
4111
+ return rgb(hex);
4141
4112
  }
4142
- if (isNil(this._context) && isValid(this._canvas)) {
4143
- const context = this._canvas.getContext('2d');
4144
- if (isValid(context)) {
4145
- context.save();
4146
- context.font = getContextFont(this.textSpec);
4147
- this._contextSaved = true;
4148
- this._context = context;
4149
- }
4113
+ else if (hexLength === 8) {
4114
+ return new RGB((hex >> 24) & 0xff, (hex >> 16) & 0xff, (hex >> 8) & 0xff, (hex & 0xff) / 0xff);
4150
4115
  }
4151
- if (isNil(this._context)) {
4152
- this._notSupportCanvas = true;
4153
- return false;
4116
+ return null;
4117
+ }
4118
+ return undefined;
4119
+ };
4120
+ class Color {
4121
+ static Brighter(source, b = 1) {
4122
+ if (b === 1) {
4123
+ return source;
4154
4124
  }
4155
- return true;
4125
+ return new Color(source).brighter(b).toRGBA();
4156
4126
  }
4157
- _initSpec() {
4158
- var _a, _b, _c;
4159
- const { defaultFontParams = {} } = this._option;
4160
- const { fontStyle = defaultFontParams.fontStyle, fontVariant = defaultFontParams.fontVariant, fontWeight = (_a = defaultFontParams.fontWeight) !== null && _a !== void 0 ? _a : 'normal', fontSize = (_b = defaultFontParams.fontSize) !== null && _b !== void 0 ? _b : 12, fontFamily = (_c = defaultFontParams.fontFamily) !== null && _c !== void 0 ? _c : 'sans-serif', align, textAlign = align !== null && align !== void 0 ? align : 'center', baseline, textBaseline = baseline !== null && baseline !== void 0 ? baseline : 'middle', ellipsis, limit } = this._userSpec;
4161
- let { lineHeight = fontSize } = this._userSpec;
4162
- if (isString(lineHeight) && lineHeight[lineHeight.length - 1] === '%') {
4163
- const scale = Number.parseFloat(lineHeight.substring(0, lineHeight.length - 1)) / 100;
4164
- lineHeight = fontSize * scale;
4127
+ static SetOpacity(source, o = 1) {
4128
+ if (o === 1) {
4129
+ return source;
4165
4130
  }
4166
- return {
4167
- fontStyle,
4168
- fontVariant,
4169
- fontFamily,
4170
- fontSize,
4171
- fontWeight,
4172
- textAlign,
4173
- textBaseline,
4174
- ellipsis,
4175
- limit,
4176
- lineHeight
4177
- };
4131
+ return new Color(source).setOpacity(o).toRGBA();
4178
4132
  }
4179
- measure(text, method) {
4180
- switch (method) {
4181
- case 'vrender':
4182
- case 'canopus':
4183
- return this.fullMeasure(text);
4184
- case 'canvas':
4185
- return this.measureWithNaiveCanvas(text);
4186
- case 'simple':
4187
- return this.quickMeasureWithoutCanvas(text);
4188
- case 'quick':
4133
+ static getColorBrightness(source, model = 'hsl') {
4134
+ const color = source instanceof Color ? source : new Color(source);
4135
+ switch (model) {
4136
+ case 'hsv':
4137
+ return color.getHSVBrightness();
4138
+ case 'hsl':
4139
+ return color.getHSLBrightness();
4140
+ case 'lum':
4141
+ return color.getLuminance();
4142
+ case 'lum2':
4143
+ return color.getLuminance2();
4144
+ case 'lum3':
4145
+ return color.getLuminance3();
4189
4146
  default:
4190
- return this.quickMeasure(text);
4147
+ return color.getHSVBrightness();
4191
4148
  }
4192
4149
  }
4193
- fullMeasure(text) {
4194
- if (isNil(text)) {
4195
- return { width: 0, height: 0 };
4150
+ static parseColorString(value) {
4151
+ if (isValid(DEFAULT_COLORS_OPACITY[value])) {
4152
+ return rgba(DEFAULT_COLORS_OPACITY[value]);
4196
4153
  }
4197
- if (isNil(this._option.getTextBounds) || !this._notSupportVRender) {
4198
- return this.measureWithNaiveCanvas(text);
4154
+ if (isValid(DEFAULT_COLORS[value])) {
4155
+ return rgb(DEFAULT_COLORS[value]);
4199
4156
  }
4200
- const { fontFamily, fontSize, fontWeight, textAlign, textBaseline, ellipsis, limit, lineHeight } = this.textSpec;
4201
- let size;
4202
- try {
4203
- const bounds = this._option.getTextBounds({
4204
- text,
4205
- fontFamily,
4206
- fontSize,
4207
- fontWeight,
4208
- textAlign,
4209
- textBaseline,
4210
- ellipsis: !!ellipsis,
4211
- maxLineWidth: limit || Infinity,
4212
- lineHeight
4213
- });
4214
- size = { width: bounds.width(), height: bounds.height() };
4157
+ const formatValue = `${value}`.trim().toLowerCase();
4158
+ const hexRes = setHex(formatValue);
4159
+ if (hexRes !== undefined) {
4160
+ return hexRes;
4215
4161
  }
4216
- catch (e) {
4217
- this._notSupportVRender = true;
4218
- size = this.measureWithNaiveCanvas(text);
4162
+ if (/^(rgb|RGB|rgba|RGBA)/.test(formatValue)) {
4163
+ const aColor = formatValue.replace(/(?:\(|\)|rgba|RGBA|rgb|RGB)*/g, '').split(',');
4164
+ return new RGB(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10), parseFloat(aColor[3]));
4219
4165
  }
4220
- return size;
4166
+ if (/^(hsl|HSL|hsla|HSLA)/.test(formatValue)) {
4167
+ const aColor = formatValue.replace(/(?:\(|\)|hsla|HSLA|hsl|HSL)*/g, '').split(',');
4168
+ const rgb = hslToRgb(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10));
4169
+ return new RGB(rgb.r, rgb.g, rgb.b, parseFloat(aColor[3]));
4170
+ }
4171
+ return;
4172
+ }
4173
+ constructor(value) {
4174
+ const color = Color.parseColorString(value);
4175
+ if (color) {
4176
+ this.color = color;
4177
+ }
4178
+ else {
4179
+ console.warn(`Warn: 传入${value}无法解析为Color`);
4180
+ this.color = new RGB(255, 255, 255);
4181
+ }
4182
+ }
4183
+ toRGBA() {
4184
+ return this.color.formatRgb();
4185
+ }
4186
+ toString() {
4187
+ return this.color.formatRgb();
4188
+ }
4189
+ toHex() {
4190
+ return this.color.formatHex();
4191
+ }
4192
+ toHsl() {
4193
+ return this.color.formatHsl();
4194
+ }
4195
+ brighter(k) {
4196
+ const { r, g, b } = this.color;
4197
+ this.color.r = Math.max(0, Math.min(255, Math.floor(r * k)));
4198
+ this.color.g = Math.max(0, Math.min(255, Math.floor(g * k)));
4199
+ this.color.b = Math.max(0, Math.min(255, Math.floor(b * k)));
4200
+ return this;
4201
+ }
4202
+ add(color) {
4203
+ const { r, g, b } = this.color;
4204
+ this.color.r += Math.min(255, r + color.color.r);
4205
+ this.color.g += Math.min(255, g + color.color.g);
4206
+ this.color.b += Math.min(255, b + color.color.b);
4207
+ return this;
4208
+ }
4209
+ sub(color) {
4210
+ this.color.r = Math.max(0, this.color.r - color.color.r);
4211
+ this.color.g = Math.max(0, this.color.g - color.color.g);
4212
+ this.color.b = Math.max(0, this.color.b - color.color.b);
4213
+ return this;
4214
+ }
4215
+ multiply(color) {
4216
+ const { r, g, b } = this.color;
4217
+ this.color.r = Math.max(0, Math.min(255, Math.floor(r * color.color.r)));
4218
+ this.color.g = Math.max(0, Math.min(255, Math.floor(g * color.color.g)));
4219
+ this.color.b = Math.max(0, Math.min(255, Math.floor(b * color.color.b)));
4220
+ return this;
4221
+ }
4222
+ getHSVBrightness() {
4223
+ return Math.max(this.color.r, this.color.g, this.color.b) / 255;
4224
+ }
4225
+ getHSLBrightness() {
4226
+ return ((Math.max(this.color.r, this.color.g, this.color.b) / 255 +
4227
+ Math.min(this.color.r, this.color.g, this.color.b) / 255) *
4228
+ 0.5);
4229
+ }
4230
+ setHsl(h, s, l) {
4231
+ const opacity = this.color.opacity;
4232
+ const hsl = rgbToHsl(this.color.r, this.color.g, this.color.b);
4233
+ const rgb = hslToRgb(isNil(h) ? hsl.h : clamp(h, 0, 360), isNil(s) ? hsl.s : s >= 0 && s <= 1 ? s * 100 : s, isNil(l) ? hsl.l : l <= 1 && l >= 0 ? l * 100 : l);
4234
+ this.color = new RGB(rgb.r, rgb.g, rgb.b, opacity);
4235
+ return this;
4236
+ }
4237
+ setRGB(r, g, b) {
4238
+ !isNil(r) && (this.color.r = r);
4239
+ !isNil(g) && (this.color.g = g);
4240
+ !isNil(b) && (this.color.b = b);
4241
+ return this;
4242
+ }
4243
+ setHex(value) {
4244
+ const formatValue = `${value}`.trim().toLowerCase();
4245
+ const res = setHex(formatValue, true);
4246
+ return res !== null && res !== void 0 ? res : this;
4247
+ }
4248
+ setColorName(name) {
4249
+ const hex = DEFAULT_COLORS[name.toLowerCase()];
4250
+ if (typeof hex !== 'undefined') {
4251
+ this.setHex(hex);
4252
+ }
4253
+ else {
4254
+ console.warn('THREE.Color: Unknown color ' + name);
4255
+ }
4256
+ return this;
4257
+ }
4258
+ setScalar(scalar) {
4259
+ this.color.r = scalar;
4260
+ this.color.g = scalar;
4261
+ this.color.b = scalar;
4262
+ return this;
4263
+ }
4264
+ setOpacity(o = 1) {
4265
+ this.color.opacity = o;
4266
+ return this;
4267
+ }
4268
+ getLuminance() {
4269
+ return (0.2126 * this.color.r + 0.7152 * this.color.g + 0.0722 * this.color.b) / 255;
4270
+ }
4271
+ getLuminance2() {
4272
+ return (0.2627 * this.color.r + 0.678 * this.color.g + 0.0593 * this.color.b) / 255;
4273
+ }
4274
+ getLuminance3() {
4275
+ return (0.299 * this.color.r + 0.587 * this.color.g + 0.114 * this.color.b) / 255;
4276
+ }
4277
+ clone() {
4278
+ return new Color(this.color.toString());
4279
+ }
4280
+ copyGammaToLinear(color, gammaFactor = 2.0) {
4281
+ this.color.r = Math.pow(color.color.r, gammaFactor);
4282
+ this.color.g = Math.pow(color.color.g, gammaFactor);
4283
+ this.color.b = Math.pow(color.color.b, gammaFactor);
4284
+ return this;
4285
+ }
4286
+ copyLinearToGamma(color, gammaFactor = 2.0) {
4287
+ const safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
4288
+ this.color.r = Math.pow(color.color.r, safeInverse);
4289
+ this.color.g = Math.pow(color.color.g, safeInverse);
4290
+ this.color.b = Math.pow(color.color.b, safeInverse);
4291
+ return this;
4221
4292
  }
4222
- measureWithNaiveCanvas(text) {
4223
- return this._measureReduce(text, this._measureWithNaiveCanvas.bind(this));
4293
+ convertGammaToLinear(gammaFactor) {
4294
+ this.copyGammaToLinear(this, gammaFactor);
4295
+ return this;
4224
4296
  }
4225
- _measureWithNaiveCanvas(text) {
4226
- var _a;
4227
- if (!this.initContext()) {
4228
- return this._quickMeasureWithoutCanvas(text);
4229
- }
4230
- const metrics = this._context.measureText(text);
4231
- const { fontSize, lineHeight } = this.textSpec;
4232
- return { width: metrics.width, height: (_a = lineHeight) !== null && _a !== void 0 ? _a : fontSize };
4297
+ convertLinearToGamma(gammaFactor) {
4298
+ this.copyLinearToGamma(this, gammaFactor);
4299
+ return this;
4233
4300
  }
4234
- quickMeasure(text) {
4235
- return this._measureReduce(text, this._quickMeasure.bind(this));
4301
+ copySRGBToLinear(color) {
4302
+ this.color.r = SRGBToLinear(color.color.r);
4303
+ this.color.g = SRGBToLinear(color.color.g);
4304
+ this.color.b = SRGBToLinear(color.color.b);
4305
+ return this;
4236
4306
  }
4237
- _quickMeasure(text) {
4238
- const totalSize = {
4239
- width: 0,
4240
- height: 0
4241
- };
4242
- for (let i = 0; i < text.length; i++) {
4243
- const char = text[i];
4244
- let size = this._measureSpecialChar(char);
4245
- if (isNil(size) && TextMeasure.NUMBERS_CHAR_SET.includes(char)) {
4246
- size = this._measureNumberChar();
4247
- }
4248
- if (isNil(size) && ['F', 'W'].includes(eastAsianCharacterInfo(char))) {
4249
- size = this._measureFullSizeChar();
4250
- }
4251
- if (isNil(size)) {
4252
- size = this._measureLetterChar();
4253
- }
4254
- totalSize.width += size.width;
4255
- totalSize.height = Math.max(totalSize.height, size.height);
4256
- }
4257
- return totalSize;
4307
+ copyLinearToSRGB(color) {
4308
+ this.color.r = LinearToSRGB(color.color.r);
4309
+ this.color.g = LinearToSRGB(color.color.g);
4310
+ this.color.b = LinearToSRGB(color.color.b);
4311
+ return this;
4258
4312
  }
4259
- quickMeasureWithoutCanvas(text) {
4260
- return this._measureReduce(text, this._quickMeasureWithoutCanvas.bind(this));
4313
+ convertSRGBToLinear() {
4314
+ this.copySRGBToLinear(this);
4315
+ return this;
4261
4316
  }
4262
- _quickMeasureWithoutCanvas(text) {
4263
- var _a;
4264
- const totalSize = {
4265
- width: 0,
4266
- height: 0
4267
- };
4268
- const { fontSize, lineHeight } = this.textSpec;
4269
- for (let i = 0; i < text.length; i++) {
4270
- const char = text[i];
4271
- const size = ['F', 'W'].includes(eastAsianCharacterInfo(char)) ? 1 : 0.53;
4272
- totalSize.width += size * fontSize;
4273
- }
4274
- totalSize.height = (_a = lineHeight) !== null && _a !== void 0 ? _a : fontSize;
4275
- return totalSize;
4317
+ convertLinearToSRGB() {
4318
+ this.copyLinearToSRGB(this);
4319
+ return this;
4276
4320
  }
4277
- _measureReduce(text, processor) {
4278
- var _a;
4279
- const { fontSize, lineHeight } = this.textSpec;
4280
- const defaultResult = { width: 0, height: 0 };
4281
- if (isNil(text)) {
4282
- return defaultResult;
4321
+ }
4322
+ class RGB {
4323
+ constructor(r, g, b, opacity) {
4324
+ this.r = isNaN(+r) ? 255 : Math.max(0, Math.min(255, +r));
4325
+ this.g = isNaN(+g) ? 255 : Math.max(0, Math.min(255, +g));
4326
+ this.b = isNaN(+b) ? 255 : Math.max(0, Math.min(255, +b));
4327
+ if (isValid(opacity)) {
4328
+ this.opacity = isNaN(+opacity) ? 1 : Math.max(0, Math.min(1, +opacity));
4283
4329
  }
4284
- else if (isArray(text)) {
4285
- const textArr = text.filter(isValid).map(s => s.toString());
4286
- if (textArr.length === 0) {
4287
- return defaultResult;
4288
- }
4289
- else if (textArr.length === 1) {
4290
- return processor(textArr[0]);
4291
- }
4292
- return {
4293
- width: textArr.reduce((maxWidth, cur) => Math.max(maxWidth, processor(cur).width), 0),
4294
- height: textArr.length * (((_a = lineHeight) !== null && _a !== void 0 ? _a : fontSize) + 1) + 1
4295
- };
4330
+ else {
4331
+ this.opacity = 1;
4296
4332
  }
4297
- return processor(text.toString());
4298
4333
  }
4299
- _measureNumberChar() {
4300
- if (isNil(this._numberCharSize)) {
4301
- const numberBounds = this._standardMethod(TextMeasure.NUMBERS_CHAR_SET);
4302
- this._numberCharSize = {
4303
- width: numberBounds.width / TextMeasure.NUMBERS_CHAR_SET.length,
4304
- height: numberBounds.height
4305
- };
4306
- }
4307
- return this._numberCharSize;
4334
+ formatHex() {
4335
+ return `#${hex(this.r) + hex(this.g) + hex(this.b) + (this.opacity === 1 ? '' : hex(this.opacity * 255))}`;
4308
4336
  }
4309
- _measureFullSizeChar() {
4310
- if (isNil(this._fullCharSize)) {
4311
- this._fullCharSize = this._standardMethod(TextMeasure.FULL_SIZE_CHAR);
4312
- }
4313
- return this._fullCharSize;
4337
+ formatRgb() {
4338
+ const opacity = this.opacity;
4339
+ return `${opacity === 1 ? 'rgb(' : 'rgba('}${this.r},${this.g},${this.b}${opacity === 1 ? ')' : `,${opacity})`}`;
4314
4340
  }
4315
- _measureLetterChar() {
4316
- if (isNil(this._letterCharSize)) {
4317
- const alphabetBounds = this._standardMethod(TextMeasure.ALPHABET_CHAR_SET);
4318
- this._letterCharSize = {
4319
- width: alphabetBounds.width / TextMeasure.ALPHABET_CHAR_SET.length,
4320
- height: alphabetBounds.height
4321
- };
4322
- }
4323
- return this._letterCharSize;
4341
+ formatHsl() {
4342
+ const opacity = this.opacity;
4343
+ const { h, s, l } = rgbToHsl(this.r, this.g, this.b);
4344
+ return `${opacity === 1 ? 'hsl(' : 'hsla('}${h},${s}%,${l}%${opacity === 1 ? ')' : `,${opacity})`}`;
4324
4345
  }
4325
- _measureSpecialChar(char) {
4326
- if (isValid(this._specialCharSizeMap[char])) {
4327
- return this._specialCharSizeMap[char];
4346
+ toString() {
4347
+ return this.formatHex();
4348
+ }
4349
+ }
4350
+
4351
+ function hexToRgb(str) {
4352
+ let r = '';
4353
+ let g = '';
4354
+ let b = '';
4355
+ const strtIndex = str[0] === '#' ? 1 : 0;
4356
+ for (let i = strtIndex; i < str.length; i++) {
4357
+ if (str[i] === '#') {
4358
+ continue;
4328
4359
  }
4329
- if (this.specialCharSet.includes(char)) {
4330
- this._specialCharSizeMap[char] = this._standardMethod(char);
4331
- return this._specialCharSizeMap[char];
4360
+ if (i < strtIndex + 2) {
4361
+ r += str[i];
4332
4362
  }
4333
- return null;
4334
- }
4335
- release() {
4336
- if (isValid(this._canvas)) {
4337
- this._canvas = null;
4363
+ else if (i < strtIndex + 4) {
4364
+ g += str[i];
4338
4365
  }
4339
- if (isValid(this._context)) {
4340
- if (this._contextSaved) {
4341
- this._context.restore();
4342
- this._contextSaved = false;
4343
- }
4344
- this._context = null;
4366
+ else if (i < strtIndex + 6) {
4367
+ b += str[i];
4345
4368
  }
4346
4369
  }
4370
+ const ri = parseInt(r, 16);
4371
+ const gi = parseInt(g, 16);
4372
+ const bi = parseInt(b, 16);
4373
+ return [ri, gi, bi];
4347
4374
  }
4348
- TextMeasure.ALPHABET_CHAR_SET = 'abcdefghijklmnopqrstuvwxyz';
4349
- TextMeasure.NUMBERS_CHAR_SET = '0123456789';
4350
- TextMeasure.FULL_SIZE_CHAR = '字';
4351
4375
 
4352
- const calculateAnchorOfBounds = (bounds, anchorType) => {
4353
- const { x1, x2, y1, y2 } = bounds;
4354
- const rectWidth = Math.abs(x2 - x1);
4355
- const rectHeight = Math.abs(y2 - y1);
4356
- let anchorX = (x1 + x2) / 2;
4357
- let anchorY = (y1 + y2) / 2;
4358
- let sx = 0;
4359
- let sy = 0;
4360
- switch (anchorType) {
4361
- case 'top':
4362
- case 'inside-top':
4363
- sy = -0.5;
4364
- break;
4365
- case 'bottom':
4366
- case 'inside-bottom':
4367
- sy = 0.5;
4368
- break;
4369
- case 'left':
4370
- case 'inside-left':
4371
- sx = -0.5;
4372
- break;
4373
- case 'right':
4374
- case 'inside-right':
4375
- sx = 0.5;
4376
- break;
4377
- case 'top-right':
4378
- sx = 0.5;
4379
- sy = -0.5;
4380
- break;
4381
- case 'top-left':
4382
- sx = -0.5;
4383
- sy = -0.5;
4384
- break;
4385
- case 'bottom-right':
4386
- sx = 0.5;
4387
- sy = 0.5;
4388
- break;
4389
- case 'bottom-left':
4390
- sx = -0.5;
4391
- sy = 0.5;
4392
- }
4393
- anchorX += sx * rectWidth;
4394
- anchorY += sy * rectHeight;
4395
- return { x: anchorX, y: anchorY };
4396
- };
4376
+ function rgbToHex(r, g, b) {
4377
+ return Number((1 << 24) + (r << 16) + (g << 8) + b)
4378
+ .toString(16)
4379
+ .slice(1);
4380
+ }
4381
+
4382
+ function interpolateRgb(colorA, colorB) {
4383
+ const redA = colorA.r;
4384
+ const redB = colorB.r;
4385
+ const greenA = colorA.g;
4386
+ const greenB = colorB.g;
4387
+ const blueA = colorA.b;
4388
+ const blueB = colorB.b;
4389
+ const opacityA = colorA.opacity;
4390
+ const opacityB = colorB.opacity;
4391
+ return (t) => {
4392
+ const r = Math.round(redA * (1 - t) + redB * t);
4393
+ const g = Math.round(greenA * (1 - t) + greenB * t);
4394
+ const b = Math.round(blueA * (1 - t) + blueB * t);
4395
+ const opacity = opacityA * (1 - t) + opacityB * t;
4396
+ return new RGB(r, g, b, opacity);
4397
+ };
4398
+ }
4399
+
4400
+ var index = /*#__PURE__*/Object.freeze({
4401
+ __proto__: null,
4402
+ Color: Color,
4403
+ DEFAULT_COLORS: DEFAULT_COLORS,
4404
+ RGB: RGB,
4405
+ hexToRgb: hexToRgb,
4406
+ hslToRgb: hslToRgb,
4407
+ interpolateRgb: interpolateRgb,
4408
+ rgbToHex: rgbToHex,
4409
+ rgbToHsl: rgbToHsl
4410
+ });
4397
4411
 
4398
4412
  function normalizePadding(padding) {
4399
4413
  if (isValidNumber(padding)) {
@@ -6324,6 +6338,7 @@
6324
6338
  exports.rectInsideAnotherRect = rectInsideAnotherRect;
6325
6339
  exports.rgbToHex = rgbToHex;
6326
6340
  exports.rgbToHsl = rgbToHsl;
6341
+ exports.rotatePoint = rotatePoint;
6327
6342
  exports.scale = scale;
6328
6343
  exports.secondCount = secondCount;
6329
6344
  exports.secondField = secondField;