@visactor/vrender 0.20.6-beta.0 → 0.20.6

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.es.js CHANGED
@@ -1378,145 +1378,6 @@ class PointService {
1378
1378
  }
1379
1379
  }
1380
1380
 
1381
- function transformBoundsWithMatrix(out, bounds, matrix) {
1382
- const {
1383
- x1: x1,
1384
- y1: y1,
1385
- x2: x2,
1386
- y2: y2
1387
- } = bounds;
1388
- return matrix.onlyTranslate() ? (out !== bounds && out.setValue(bounds.x1, bounds.y1, bounds.x2, bounds.y2), out.translate(matrix.e, matrix.f), bounds) : (out.clear(), out.add(matrix.a * x1 + matrix.c * y1 + matrix.e, matrix.b * x1 + matrix.d * y1 + matrix.f), out.add(matrix.a * x2 + matrix.c * y1 + matrix.e, matrix.b * x2 + matrix.d * y1 + matrix.f), out.add(matrix.a * x2 + matrix.c * y2 + matrix.e, matrix.b * x2 + matrix.d * y2 + matrix.f), out.add(matrix.a * x1 + matrix.c * y2 + matrix.e, matrix.b * x1 + matrix.d * y2 + matrix.f), bounds);
1389
- }
1390
- class Bounds {
1391
- constructor(bounds) {
1392
- bounds ? this.setValue(bounds.x1, bounds.y1, bounds.x2, bounds.y2) : this.clear();
1393
- }
1394
- clone() {
1395
- return new Bounds(this);
1396
- }
1397
- clear() {
1398
- return this.x1 = +Number.MAX_VALUE, this.y1 = +Number.MAX_VALUE, this.x2 = -Number.MAX_VALUE, this.y2 = -Number.MAX_VALUE, this;
1399
- }
1400
- empty() {
1401
- return this.x1 === +Number.MAX_VALUE && this.y1 === +Number.MAX_VALUE && this.x2 === -Number.MAX_VALUE && this.y2 === -Number.MAX_VALUE;
1402
- }
1403
- equals(b) {
1404
- return this.x1 === b.x1 && this.y1 === b.y1 && this.x2 === b.x2 && this.y2 === b.y2;
1405
- }
1406
- setValue() {
1407
- let x1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1408
- let y1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1409
- let x2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1410
- let y2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1411
- return this.x1 = x1, this.y1 = y1, this.x2 = x2, this.y2 = y2, this;
1412
- }
1413
- set() {
1414
- let x1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1415
- let y1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1416
- let x2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1417
- let y2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1418
- return x2 < x1 ? (this.x2 = x1, this.x1 = x2) : (this.x1 = x1, this.x2 = x2), y2 < y1 ? (this.y2 = y1, this.y1 = y2) : (this.y1 = y1, this.y2 = y2), this;
1419
- }
1420
- add() {
1421
- let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1422
- let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1423
- return x < this.x1 && (this.x1 = x), y < this.y1 && (this.y1 = y), x > this.x2 && (this.x2 = x), y > this.y2 && (this.y2 = y), this;
1424
- }
1425
- expand() {
1426
- let d = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1427
- return isArray$1(d) ? (this.y1 -= d[0], this.x2 += d[1], this.y2 += d[2], this.x1 -= d[3]) : (this.x1 -= d, this.y1 -= d, this.x2 += d, this.y2 += d), this;
1428
- }
1429
- round() {
1430
- return this.x1 = Math.floor(this.x1), this.y1 = Math.floor(this.y1), this.x2 = Math.ceil(this.x2), this.y2 = Math.ceil(this.y2), this;
1431
- }
1432
- translate() {
1433
- let dx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1434
- let dy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1435
- return this.x1 += dx, this.x2 += dx, this.y1 += dy, this.y2 += dy, this;
1436
- }
1437
- rotate() {
1438
- let angle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1439
- let x = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1440
- let y = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1441
- const p = this.rotatedPoints(angle, x, y);
1442
- return this.clear().add(p[0], p[1]).add(p[2], p[3]).add(p[4], p[5]).add(p[6], p[7]);
1443
- }
1444
- scale() {
1445
- let sx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1446
- let sy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1447
- let x = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1448
- let y = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1449
- const p = this.scalePoints(sx, sy, x, y);
1450
- return this.clear().add(p[0], p[1]).add(p[2], p[3]);
1451
- }
1452
- union(b) {
1453
- return b.x1 < this.x1 && (this.x1 = b.x1), b.y1 < this.y1 && (this.y1 = b.y1), b.x2 > this.x2 && (this.x2 = b.x2), b.y2 > this.y2 && (this.y2 = b.y2), this;
1454
- }
1455
- intersect(b) {
1456
- return b.x1 > this.x1 && (this.x1 = b.x1), b.y1 > this.y1 && (this.y1 = b.y1), b.x2 < this.x2 && (this.x2 = b.x2), b.y2 < this.y2 && (this.y2 = b.y2), this;
1457
- }
1458
- encloses(b) {
1459
- return b && this.x1 <= b.x1 && this.x2 >= b.x2 && this.y1 <= b.y1 && this.y2 >= b.y2;
1460
- }
1461
- alignsWith(b) {
1462
- return b && (this.x1 === b.x1 || this.x2 === b.x2 || this.y1 === b.y1 || this.y2 === b.y2);
1463
- }
1464
- intersects(b) {
1465
- return b && !(this.x2 < b.x1 || this.x1 > b.x2 || this.y2 < b.y1 || this.y1 > b.y2);
1466
- }
1467
- contains() {
1468
- let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1469
- let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1470
- return !(x < this.x1 || x > this.x2 || y < this.y1 || y > this.y2);
1471
- }
1472
- containsPoint(p) {
1473
- return !(p.x < this.x1 || p.x > this.x2 || p.y < this.y1 || p.y > this.y2);
1474
- }
1475
- width() {
1476
- return this.empty() ? 0 : this.x2 - this.x1;
1477
- }
1478
- height() {
1479
- return this.empty() ? 0 : this.y2 - this.y1;
1480
- }
1481
- scaleX() {
1482
- let s = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1483
- return this.x1 *= s, this.x2 *= s, this;
1484
- }
1485
- scaleY() {
1486
- let s = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1487
- return this.y1 *= s, this.y2 *= s, this;
1488
- }
1489
- transformWithMatrix(matrix) {
1490
- return transformBoundsWithMatrix(this, this, matrix), this;
1491
- }
1492
- copy(b) {
1493
- return this.x1 = b.x1, this.y1 = b.y1, this.x2 = b.x2, this.y2 = b.y2, this;
1494
- }
1495
- rotatedPoints(angle, x, y) {
1496
- const {
1497
- x1: x1,
1498
- y1: y1,
1499
- x2: x2,
1500
- y2: y2
1501
- } = this,
1502
- cos = Math.cos(angle),
1503
- sin = Math.sin(angle),
1504
- cx = x - x * cos + y * sin,
1505
- cy = y - x * sin - y * cos;
1506
- return [cos * x1 - sin * y1 + cx, sin * x1 + cos * y1 + cy, cos * x1 - sin * y2 + cx, sin * x1 + cos * y2 + cy, cos * x2 - sin * y1 + cx, sin * x2 + cos * y1 + cy, cos * x2 - sin * y2 + cx, sin * x2 + cos * y2 + cy];
1507
- }
1508
- scalePoints(sx, sy, x, y) {
1509
- const {
1510
- x1: x1,
1511
- y1: y1,
1512
- x2: x2,
1513
- y2: y2
1514
- } = this;
1515
- return [sx * x1 + (1 - sx) * x, sy * y1 + (1 - sy) * y, sx * x2 + (1 - sx) * x, sy * y2 + (1 - sy) * y];
1516
- }
1517
- }
1518
- class AABBBounds extends Bounds {}
1519
-
1520
1381
  function degreeToRadian(degree) {
1521
1382
  return degree * (Math.PI / 180);
1522
1383
  }
@@ -1533,41 +1394,637 @@ function getAngleByPoint(center, point) {
1533
1394
  return Math.atan2(point.y - center.y, point.x - center.x);
1534
1395
  }
1535
1396
 
1536
- class Matrix {
1537
- constructor() {
1538
- let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
1539
- let b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1540
- let c = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1541
- let d = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
1542
- let e = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
1543
- let f = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
1544
- this.a = a, this.b = b, this.c = c, this.d = d, this.e = e, this.f = f;
1545
- }
1546
- equalToMatrix(m2) {
1547
- return !(this.e !== m2.e || this.f !== m2.f || this.a !== m2.a || this.d !== m2.d || this.b !== m2.b || this.c !== m2.c);
1548
- }
1549
- equalTo(a, b, c, d, e, f) {
1550
- return !(this.e !== e || this.f !== f || this.a !== a || this.d !== d || this.b !== b || this.c !== c);
1551
- }
1552
- setValue(a, b, c, d, e, f) {
1553
- return this.a = a, this.b = b, this.c = c, this.d = d, this.e = e, this.f = f, this;
1554
- }
1555
- reset() {
1556
- return this.a = 1, this.b = 0, this.c = 0, this.d = 1, this.e = 0, this.f = 0, this;
1557
- }
1558
- getInverse() {
1559
- const a = this.a,
1560
- b = this.b,
1561
- c = this.c,
1562
- d = this.d,
1563
- e = this.e,
1564
- f = this.f,
1565
- m = new Matrix(),
1566
- dt = a * d - b * c;
1567
- return m.a = d / dt, m.b = -b / dt, m.c = -c / dt, m.d = a / dt, m.e = (c * f - d * e) / dt, m.f = -(a * f - b * e) / dt, m;
1397
+ function sub(out, v1, v2) {
1398
+ out[0] = v1[0] - v2[0], out[1] = v1[1] - v2[1];
1399
+ }
1400
+ function isIntersect(left1, right1, left2, right2) {
1401
+ let min1 = left1[0],
1402
+ max1 = right1[0],
1403
+ min2 = left2[0],
1404
+ max2 = right2[0];
1405
+ return max1 < min1 && ([min1, max1] = [max1, min1]), max2 < min2 && ([max2, min2] = [min2, max2]), !(max1 < min2 || max2 < min1) && (min1 = left1[1], max1 = right1[1], min2 = left2[1], max2 = right2[1], max1 < min1 && ([min1, max1] = [max1, min1]), max2 < min2 && ([max2, min2] = [min2, max2]), !(max1 < min2 || max2 < min1));
1406
+ }
1407
+ function getIntersectPoint(left1, right1, left2, right2) {
1408
+ if (!isIntersect(left1, right1, left2, right2)) return !1;
1409
+ const dir1 = [0, 0],
1410
+ dir2 = [0, 0],
1411
+ tempVec = [0, 0];
1412
+ if (sub(dir1, right1, left1), sub(dir2, right2, left2), fuzzyEqualVec(dir1, dir2)) return !0;
1413
+ sub(tempVec, left2, left1);
1414
+ const t = crossProduct$1(tempVec, dir2) / crossProduct$1(dir1, dir2);
1415
+ return t >= 0 && t <= 1 && [left1[0] + dir1[0] * t, left1[1] + dir1[1] * t];
1416
+ }
1417
+ function getRectIntersect(bbox1, bbox2, format) {
1418
+ if (null === bbox1) return bbox2;
1419
+ if (null === bbox2) return bbox1;
1420
+ const {
1421
+ x11: x11,
1422
+ x12: x12,
1423
+ y11: y11,
1424
+ y12: y12,
1425
+ x21: x21,
1426
+ x22: x22,
1427
+ y21: y21,
1428
+ y22: y22
1429
+ } = formatTwoBBox(bbox1, bbox2, format);
1430
+ return x11 >= x22 || x12 <= x21 || y11 >= y22 || y12 <= y21 ? {
1431
+ x1: 0,
1432
+ y1: 0,
1433
+ x2: 0,
1434
+ y2: 0
1435
+ } : {
1436
+ x1: Math.max(x11, x21),
1437
+ y1: Math.max(y11, y21),
1438
+ x2: Math.min(x12, x22),
1439
+ y2: Math.min(y12, y22)
1440
+ };
1441
+ }
1442
+ var InnerBBox;
1443
+ !function (InnerBBox) {
1444
+ InnerBBox[InnerBBox.NONE = 0] = "NONE", InnerBBox[InnerBBox.BBOX1 = 1] = "BBOX1", InnerBBox[InnerBBox.BBOX2 = 2] = "BBOX2";
1445
+ }(InnerBBox || (InnerBBox = {}));
1446
+ const formatTwoBBox = (bbox1, bbox2, format) => {
1447
+ let x11 = bbox1.x1,
1448
+ x12 = bbox1.x2,
1449
+ y11 = bbox1.y1,
1450
+ y12 = bbox1.y2,
1451
+ x21 = bbox2.x1,
1452
+ x22 = bbox2.x2,
1453
+ y21 = bbox2.y1,
1454
+ y22 = bbox2.y2;
1455
+ return format && (x11 > x12 && ([x11, x12] = [x12, x11]), y11 > y12 && ([y11, y12] = [y12, y11]), x21 > x22 && ([x21, x22] = [x22, x21]), y21 > y22 && ([y21, y22] = [y22, y21])), {
1456
+ x11: x11,
1457
+ x12: x12,
1458
+ y11: y11,
1459
+ y12: y12,
1460
+ x21: x21,
1461
+ x22: x22,
1462
+ y21: y21,
1463
+ y22: y22
1464
+ };
1465
+ };
1466
+ function isRectIntersect(bbox1, bbox2, format) {
1467
+ if (bbox1 && bbox2) {
1468
+ if (!format) return !(bbox1.x1 > bbox2.x2 || bbox1.x2 < bbox2.x1 || bbox1.y1 > bbox2.y2 || bbox1.y2 < bbox2.y1);
1469
+ const {
1470
+ x11: x11,
1471
+ x12: x12,
1472
+ y11: y11,
1473
+ y12: y12,
1474
+ x21: x21,
1475
+ x22: x22,
1476
+ y21: y21,
1477
+ y22: y22
1478
+ } = formatTwoBBox(bbox1, bbox2, !0);
1479
+ return !(x11 > x22 || x12 < x21 || y11 > y22 || y12 < y21);
1568
1480
  }
1569
- rotate(rad) {
1570
- const c = Math.cos(rad),
1481
+ return !0;
1482
+ }
1483
+ function getProjectionRadius(checkAxis, axis) {
1484
+ return Math.abs(axis[0] * checkAxis[0] + axis[1] * checkAxis[1]);
1485
+ }
1486
+ function rotatePoint(_ref, rad) {
1487
+ let {
1488
+ x: x,
1489
+ y: y
1490
+ } = _ref;
1491
+ let origin = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
1492
+ x: 0,
1493
+ y: 0
1494
+ };
1495
+ return {
1496
+ x: (x - origin.x) * Math.cos(rad) - (y - origin.y) * Math.sin(rad) + origin.x,
1497
+ y: (x - origin.x) * Math.sin(rad) + (y - origin.y) * Math.cos(rad) + origin.y
1498
+ };
1499
+ }
1500
+ function getCenterPoint(box) {
1501
+ return {
1502
+ x: (box.x1 + box.x2) / 2,
1503
+ y: (box.y1 + box.y2) / 2
1504
+ };
1505
+ }
1506
+ function toRect(box, isDeg) {
1507
+ const deg = isDeg ? degreeToRadian(box.angle) : box.angle,
1508
+ cp = getCenterPoint(box);
1509
+ return [rotatePoint({
1510
+ x: box.x1,
1511
+ y: box.y1
1512
+ }, deg, cp), rotatePoint({
1513
+ x: box.x2,
1514
+ y: box.y1
1515
+ }, deg, cp), rotatePoint({
1516
+ x: box.x2,
1517
+ y: box.y2
1518
+ }, deg, cp), rotatePoint({
1519
+ x: box.x1,
1520
+ y: box.y2
1521
+ }, deg, cp)];
1522
+ }
1523
+ function isRotateAABBIntersect(box1, box2) {
1524
+ let isDeg = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !1;
1525
+ let ctx = arguments.length > 3 ? arguments[3] : undefined;
1526
+ const rect1 = toRect(box1, isDeg),
1527
+ rect2 = toRect(box2, isDeg),
1528
+ vector = (start, end) => [end.x - start.x, end.y - start.y];
1529
+ ctx && (ctx.save(), ctx.fillStyle = "red", ctx.globalAlpha = .6, rect1.forEach((item, index) => {
1530
+ 0 === index ? ctx.moveTo(item.x, item.y) : ctx.lineTo(item.x, item.y);
1531
+ }), ctx.fill(), ctx.restore(), ctx.save(), ctx.fillStyle = "green", ctx.globalAlpha = .6, rect2.forEach((item, index) => {
1532
+ 0 === index ? ctx.moveTo(item.x, item.y) : ctx.lineTo(item.x, item.y);
1533
+ }), ctx.fill(), ctx.restore());
1534
+ const p1 = getCenterPoint(box1),
1535
+ p2 = getCenterPoint(box2);
1536
+ ctx && ctx.fillRect(p1.x, p1.y, 2, 2), ctx && ctx.fillRect(p2.x, p2.y, 2, 2);
1537
+ const vp1p2 = vector(p1, p2),
1538
+ AB = vector(rect1[0], rect1[1]),
1539
+ BC = vector(rect1[1], rect1[2]),
1540
+ A1B1 = vector(rect2[0], rect2[1]),
1541
+ B1C1 = vector(rect2[1], rect2[2]),
1542
+ deg11 = isDeg ? degreeToRadian(box1.angle) : box1.angle;
1543
+ let deg12 = isDeg ? degreeToRadian(90 - box1.angle) : box1.angle + halfPi$1;
1544
+ const deg21 = isDeg ? degreeToRadian(box2.angle) : box2.angle;
1545
+ let deg22 = isDeg ? degreeToRadian(90 - box2.angle) : box2.angle + halfPi$1;
1546
+ deg12 > pi2 && (deg12 -= pi2), deg22 > pi2 && (deg22 -= pi2);
1547
+ const isCover = (checkAxisRadius, deg, targetAxis1, targetAxis2) => {
1548
+ const checkAxis = [Math.cos(deg), Math.sin(deg)];
1549
+ return checkAxisRadius + (getProjectionRadius(checkAxis, targetAxis1) + getProjectionRadius(checkAxis, targetAxis2)) / 2 > getProjectionRadius(checkAxis, vp1p2);
1550
+ };
1551
+ return isCover((box1.x2 - box1.x1) / 2, deg11, A1B1, B1C1) && isCover((box1.y2 - box1.y1) / 2, deg12, A1B1, B1C1) && isCover((box2.x2 - box2.x1) / 2, deg21, AB, BC) && isCover((box2.y2 - box2.y1) / 2, deg22, AB, BC);
1552
+ }
1553
+
1554
+ function isPointInLine(x0, y0, x1, y1, x, y) {
1555
+ if (y > y0 && y > y1 || y < y0 && y < y1) return 0;
1556
+ if (y1 === y0) return 0;
1557
+ const t = (y - y0) / (y1 - y0);
1558
+ let dir = y1 < y0 ? 1 : -1;
1559
+ 1 !== t && 0 !== t || (dir = y1 < y0 ? .5 : -.5);
1560
+ const x_ = t * (x1 - x0) + x0;
1561
+ return x_ === x ? 1 / 0 : x_ > x ? dir : 0;
1562
+ }
1563
+
1564
+ const eastAsianCharacterInfo = character => {
1565
+ let x = character.charCodeAt(0),
1566
+ y = 2 === character.length ? character.charCodeAt(1) : 0,
1567
+ codePoint = x;
1568
+ return 55296 <= x && x <= 56319 && 56320 <= y && y <= 57343 && (x &= 1023, y &= 1023, codePoint = x << 10 | y, codePoint += 65536), 12288 === codePoint || 65281 <= codePoint && codePoint <= 65376 || 65504 <= codePoint && codePoint <= 65510 ? "F" : 8361 === codePoint || 65377 <= codePoint && codePoint <= 65470 || 65474 <= codePoint && codePoint <= 65479 || 65482 <= codePoint && codePoint <= 65487 || 65490 <= codePoint && codePoint <= 65495 || 65498 <= codePoint && codePoint <= 65500 || 65512 <= codePoint && codePoint <= 65518 ? "H" : 4352 <= codePoint && codePoint <= 4447 || 4515 <= codePoint && codePoint <= 4519 || 4602 <= codePoint && codePoint <= 4607 || 9001 <= codePoint && codePoint <= 9002 || 11904 <= codePoint && codePoint <= 11929 || 11931 <= codePoint && codePoint <= 12019 || 12032 <= codePoint && codePoint <= 12245 || 12272 <= codePoint && codePoint <= 12283 || 12289 <= codePoint && codePoint <= 12350 || 12353 <= codePoint && codePoint <= 12438 || 12441 <= codePoint && codePoint <= 12543 || 12549 <= codePoint && codePoint <= 12589 || 12593 <= codePoint && codePoint <= 12686 || 12688 <= codePoint && codePoint <= 12730 || 12736 <= codePoint && codePoint <= 12771 || 12784 <= codePoint && codePoint <= 12830 || 12832 <= codePoint && codePoint <= 12871 || 12880 <= codePoint && codePoint <= 13054 || 13056 <= codePoint && codePoint <= 19903 || 19968 <= codePoint && codePoint <= 42124 || 42128 <= codePoint && codePoint <= 42182 || 43360 <= codePoint && codePoint <= 43388 || 44032 <= codePoint && codePoint <= 55203 || 55216 <= codePoint && codePoint <= 55238 || 55243 <= codePoint && codePoint <= 55291 || 63744 <= codePoint && codePoint <= 64255 || 65040 <= codePoint && codePoint <= 65049 || 65072 <= codePoint && codePoint <= 65106 || 65108 <= codePoint && codePoint <= 65126 || 65128 <= codePoint && codePoint <= 65131 || 110592 <= codePoint && codePoint <= 110593 || 127488 <= codePoint && codePoint <= 127490 || 127504 <= codePoint && codePoint <= 127546 || 127552 <= codePoint && codePoint <= 127560 || 127568 <= codePoint && codePoint <= 127569 || 131072 <= codePoint && codePoint <= 194367 || 177984 <= codePoint && codePoint <= 196605 || 196608 <= codePoint && codePoint <= 262141 ? "W" : 32 <= codePoint && codePoint <= 126 || 162 <= codePoint && codePoint <= 163 || 165 <= codePoint && codePoint <= 166 || 172 === codePoint || 175 === codePoint || 10214 <= codePoint && codePoint <= 10221 || 10629 <= codePoint && codePoint <= 10630 ? "Na" : 161 === codePoint || 164 === codePoint || 167 <= codePoint && codePoint <= 168 || 170 === codePoint || 173 <= codePoint && codePoint <= 174 || 176 <= codePoint && codePoint <= 180 || 182 <= codePoint && codePoint <= 186 || 188 <= codePoint && codePoint <= 191 || 198 === codePoint || 208 === codePoint || 215 <= codePoint && codePoint <= 216 || 222 <= codePoint && codePoint <= 225 || 230 === codePoint || 232 <= codePoint && codePoint <= 234 || 236 <= codePoint && codePoint <= 237 || 240 === codePoint || 242 <= codePoint && codePoint <= 243 || 247 <= codePoint && codePoint <= 250 || 252 === codePoint || 254 === codePoint || 257 === codePoint || 273 === codePoint || 275 === codePoint || 283 === codePoint || 294 <= codePoint && codePoint <= 295 || 299 === codePoint || 305 <= codePoint && codePoint <= 307 || 312 === codePoint || 319 <= codePoint && codePoint <= 322 || 324 === codePoint || 328 <= codePoint && codePoint <= 331 || 333 === codePoint || 338 <= codePoint && codePoint <= 339 || 358 <= codePoint && codePoint <= 359 || 363 === codePoint || 462 === codePoint || 464 === codePoint || 466 === codePoint || 468 === codePoint || 470 === codePoint || 472 === codePoint || 474 === codePoint || 476 === codePoint || 593 === codePoint || 609 === codePoint || 708 === codePoint || 711 === codePoint || 713 <= codePoint && codePoint <= 715 || 717 === codePoint || 720 === codePoint || 728 <= codePoint && codePoint <= 731 || 733 === codePoint || 735 === codePoint || 768 <= codePoint && codePoint <= 879 || 913 <= codePoint && codePoint <= 929 || 931 <= codePoint && codePoint <= 937 || 945 <= codePoint && codePoint <= 961 || 963 <= codePoint && codePoint <= 969 || 1025 === codePoint || 1040 <= codePoint && codePoint <= 1103 || 1105 === codePoint || 8208 === codePoint || 8211 <= codePoint && codePoint <= 8214 || 8216 <= codePoint && codePoint <= 8217 || 8220 <= codePoint && codePoint <= 8221 || 8224 <= codePoint && codePoint <= 8226 || 8228 <= codePoint && codePoint <= 8231 || 8240 === codePoint || 8242 <= codePoint && codePoint <= 8243 || 8245 === codePoint || 8251 === codePoint || 8254 === codePoint || 8308 === codePoint || 8319 === codePoint || 8321 <= codePoint && codePoint <= 8324 || 8364 === codePoint || 8451 === codePoint || 8453 === codePoint || 8457 === codePoint || 8467 === codePoint || 8470 === codePoint || 8481 <= codePoint && codePoint <= 8482 || 8486 === codePoint || 8491 === codePoint || 8531 <= codePoint && codePoint <= 8532 || 8539 <= codePoint && codePoint <= 8542 || 8544 <= codePoint && codePoint <= 8555 || 8560 <= codePoint && codePoint <= 8569 || 8585 === codePoint || 8592 <= codePoint && codePoint <= 8601 || 8632 <= codePoint && codePoint <= 8633 || 8658 === codePoint || 8660 === codePoint || 8679 === codePoint || 8704 === codePoint || 8706 <= codePoint && codePoint <= 8707 || 8711 <= codePoint && codePoint <= 8712 || 8715 === codePoint || 8719 === codePoint || 8721 === codePoint || 8725 === codePoint || 8730 === codePoint || 8733 <= codePoint && codePoint <= 8736 || 8739 === codePoint || 8741 === codePoint || 8743 <= codePoint && codePoint <= 8748 || 8750 === codePoint || 8756 <= codePoint && codePoint <= 8759 || 8764 <= codePoint && codePoint <= 8765 || 8776 === codePoint || 8780 === codePoint || 8786 === codePoint || 8800 <= codePoint && codePoint <= 8801 || 8804 <= codePoint && codePoint <= 8807 || 8810 <= codePoint && codePoint <= 8811 || 8814 <= codePoint && codePoint <= 8815 || 8834 <= codePoint && codePoint <= 8835 || 8838 <= codePoint && codePoint <= 8839 || 8853 === codePoint || 8857 === codePoint || 8869 === codePoint || 8895 === codePoint || 8978 === codePoint || 9312 <= codePoint && codePoint <= 9449 || 9451 <= codePoint && codePoint <= 9547 || 9552 <= codePoint && codePoint <= 9587 || 9600 <= codePoint && codePoint <= 9615 || 9618 <= codePoint && codePoint <= 9621 || 9632 <= codePoint && codePoint <= 9633 || 9635 <= codePoint && codePoint <= 9641 || 9650 <= codePoint && codePoint <= 9651 || 9654 <= codePoint && codePoint <= 9655 || 9660 <= codePoint && codePoint <= 9661 || 9664 <= codePoint && codePoint <= 9665 || 9670 <= codePoint && codePoint <= 9672 || 9675 === codePoint || 9678 <= codePoint && codePoint <= 9681 || 9698 <= codePoint && codePoint <= 9701 || 9711 === codePoint || 9733 <= codePoint && codePoint <= 9734 || 9737 === codePoint || 9742 <= codePoint && codePoint <= 9743 || 9748 <= codePoint && codePoint <= 9749 || 9756 === codePoint || 9758 === codePoint || 9792 === codePoint || 9794 === codePoint || 9824 <= codePoint && codePoint <= 9825 || 9827 <= codePoint && codePoint <= 9829 || 9831 <= codePoint && codePoint <= 9834 || 9836 <= codePoint && codePoint <= 9837 || 9839 === codePoint || 9886 <= codePoint && codePoint <= 9887 || 9918 <= codePoint && codePoint <= 9919 || 9924 <= codePoint && codePoint <= 9933 || 9935 <= codePoint && codePoint <= 9953 || 9955 === codePoint || 9960 <= codePoint && codePoint <= 9983 || 10045 === codePoint || 10071 === codePoint || 10102 <= codePoint && codePoint <= 10111 || 11093 <= codePoint && codePoint <= 11097 || 12872 <= codePoint && codePoint <= 12879 || 57344 <= codePoint && codePoint <= 63743 || 65024 <= codePoint && codePoint <= 65039 || 65533 === codePoint || 127232 <= codePoint && codePoint <= 127242 || 127248 <= codePoint && codePoint <= 127277 || 127280 <= codePoint && codePoint <= 127337 || 127344 <= codePoint && codePoint <= 127386 || 917760 <= codePoint && codePoint <= 917999 || 983040 <= codePoint && codePoint <= 1048573 || 1048576 <= codePoint && codePoint <= 1114109 ? "A" : "N";
1569
+ };
1570
+
1571
+ function getContextFont(text) {
1572
+ let defaultAttr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1573
+ let fontSizeScale = arguments.length > 2 ? arguments[2] : undefined;
1574
+ fontSizeScale || (fontSizeScale = 1);
1575
+ const {
1576
+ fontStyle = defaultAttr.fontStyle,
1577
+ fontVariant = defaultAttr.fontVariant,
1578
+ fontWeight = defaultAttr.fontWeight,
1579
+ fontSize = defaultAttr.fontSize,
1580
+ fontFamily = defaultAttr.fontFamily
1581
+ } = text;
1582
+ return (fontStyle ? fontStyle + " " : "") + (fontVariant ? fontVariant + " " : "") + (fontWeight ? fontWeight + " " : "") + fontSize * fontSizeScale + "px " + (fontFamily || "sans-serif");
1583
+ }
1584
+
1585
+ class TextMeasure {
1586
+ constructor(option, textSpec) {
1587
+ this._numberCharSize = null, this._fullCharSize = null, this._letterCharSize = null, this._specialCharSizeMap = {}, this._canvas = null, this._context = null, this._contextSaved = !1, this._notSupportCanvas = !1, this._notSupportVRender = !1, this._userSpec = {}, this.specialCharSet = "-/: .,@%'\"~", this._option = option, this._userSpec = null != textSpec ? textSpec : {}, this.textSpec = this._initSpec(), isValid$1(option.specialCharSet) && (this.specialCharSet = option.specialCharSet), this._standardMethod = isValid$1(option.getTextBounds) ? this.fullMeasure.bind(this) : this.measureWithNaiveCanvas.bind(this);
1588
+ }
1589
+ initContext() {
1590
+ if (this._notSupportCanvas) return !1;
1591
+ if (isNil$1(this._canvas) && (isValid$1(this._option.getCanvasForMeasure) && (this._canvas = this._option.getCanvasForMeasure()), isNil$1(this._canvas) && "undefined" != typeof window && void 0 !== window.document && globalThis && isValid$1(globalThis.document) && (this._canvas = globalThis.document.createElement("canvas"))), isNil$1(this._context) && isValid$1(this._canvas)) {
1592
+ const context = this._canvas.getContext("2d");
1593
+ isValid$1(context) && (context.save(), context.font = getContextFont(this.textSpec), this._contextSaved = !0, this._context = context);
1594
+ }
1595
+ return !isNil$1(this._context) || (this._notSupportCanvas = !0, !1);
1596
+ }
1597
+ _initSpec() {
1598
+ var _a, _b, _c;
1599
+ const {
1600
+ defaultFontParams = {}
1601
+ } = this._option,
1602
+ {
1603
+ fontStyle = defaultFontParams.fontStyle,
1604
+ fontVariant = defaultFontParams.fontVariant,
1605
+ fontWeight = null !== (_a = defaultFontParams.fontWeight) && void 0 !== _a ? _a : "normal",
1606
+ fontSize = null !== (_b = defaultFontParams.fontSize) && void 0 !== _b ? _b : 12,
1607
+ fontFamily = null !== (_c = defaultFontParams.fontFamily) && void 0 !== _c ? _c : "sans-serif",
1608
+ align: align,
1609
+ textAlign = null != align ? align : "center",
1610
+ baseline: baseline,
1611
+ textBaseline = null != baseline ? baseline : "middle",
1612
+ ellipsis: ellipsis,
1613
+ limit: limit
1614
+ } = this._userSpec;
1615
+ let {
1616
+ lineHeight = fontSize
1617
+ } = this._userSpec;
1618
+ if (isString$1(lineHeight) && "%" === lineHeight[lineHeight.length - 1]) {
1619
+ const scale = Number.parseFloat(lineHeight.substring(0, lineHeight.length - 1)) / 100;
1620
+ lineHeight = fontSize * scale;
1621
+ }
1622
+ return {
1623
+ fontStyle: fontStyle,
1624
+ fontVariant: fontVariant,
1625
+ fontFamily: fontFamily,
1626
+ fontSize: fontSize,
1627
+ fontWeight: fontWeight,
1628
+ textAlign: textAlign,
1629
+ textBaseline: textBaseline,
1630
+ ellipsis: ellipsis,
1631
+ limit: limit,
1632
+ lineHeight: lineHeight
1633
+ };
1634
+ }
1635
+ measure(text, method) {
1636
+ switch (method) {
1637
+ case "vrender":
1638
+ case "canopus":
1639
+ return this.fullMeasure(text);
1640
+ case "canvas":
1641
+ return this.measureWithNaiveCanvas(text);
1642
+ case "simple":
1643
+ return this.quickMeasureWithoutCanvas(text);
1644
+ default:
1645
+ return this.quickMeasure(text);
1646
+ }
1647
+ }
1648
+ fullMeasure(text) {
1649
+ if (isNil$1(text)) return {
1650
+ width: 0,
1651
+ height: 0
1652
+ };
1653
+ if (isNil$1(this._option.getTextBounds) || !this._notSupportVRender) return this.measureWithNaiveCanvas(text);
1654
+ const {
1655
+ fontFamily: fontFamily,
1656
+ fontSize: fontSize,
1657
+ fontWeight: fontWeight,
1658
+ textAlign: textAlign,
1659
+ textBaseline: textBaseline,
1660
+ ellipsis: ellipsis,
1661
+ limit: limit,
1662
+ lineHeight: lineHeight
1663
+ } = this.textSpec;
1664
+ let size;
1665
+ try {
1666
+ const bounds = this._option.getTextBounds({
1667
+ text: text,
1668
+ fontFamily: fontFamily,
1669
+ fontSize: fontSize,
1670
+ fontWeight: fontWeight,
1671
+ textAlign: textAlign,
1672
+ textBaseline: textBaseline,
1673
+ ellipsis: !!ellipsis,
1674
+ maxLineWidth: limit || 1 / 0,
1675
+ lineHeight: lineHeight
1676
+ });
1677
+ size = {
1678
+ width: bounds.width(),
1679
+ height: bounds.height()
1680
+ };
1681
+ } catch (e) {
1682
+ this._notSupportVRender = !0, size = this.measureWithNaiveCanvas(text);
1683
+ }
1684
+ return size;
1685
+ }
1686
+ measureWithNaiveCanvas(text) {
1687
+ return this._measureReduce(text, this._measureWithNaiveCanvas.bind(this));
1688
+ }
1689
+ _measureWithNaiveCanvas(text) {
1690
+ var _a;
1691
+ if (!this.initContext()) return this._quickMeasureWithoutCanvas(text);
1692
+ const metrics = this._context.measureText(text),
1693
+ {
1694
+ fontSize: fontSize,
1695
+ lineHeight: lineHeight
1696
+ } = this.textSpec;
1697
+ return {
1698
+ width: metrics.width,
1699
+ height: null !== (_a = lineHeight) && void 0 !== _a ? _a : fontSize
1700
+ };
1701
+ }
1702
+ quickMeasure(text) {
1703
+ return this._measureReduce(text, this._quickMeasure.bind(this));
1704
+ }
1705
+ _quickMeasure(text) {
1706
+ const totalSize = {
1707
+ width: 0,
1708
+ height: 0
1709
+ };
1710
+ for (let i = 0; i < text.length; i++) {
1711
+ const char = text[i];
1712
+ let size = this._measureSpecialChar(char);
1713
+ isNil$1(size) && TextMeasure.NUMBERS_CHAR_SET.includes(char) && (size = this._measureNumberChar()), isNil$1(size) && ["F", "W"].includes(eastAsianCharacterInfo(char)) && (size = this._measureFullSizeChar()), isNil$1(size) && (size = this._measureLetterChar()), totalSize.width += size.width, totalSize.height = Math.max(totalSize.height, size.height);
1714
+ }
1715
+ return totalSize;
1716
+ }
1717
+ quickMeasureWithoutCanvas(text) {
1718
+ return this._measureReduce(text, this._quickMeasureWithoutCanvas.bind(this));
1719
+ }
1720
+ _quickMeasureWithoutCanvas(text) {
1721
+ var _a;
1722
+ const totalSize = {
1723
+ width: 0,
1724
+ height: 0
1725
+ },
1726
+ {
1727
+ fontSize: fontSize,
1728
+ lineHeight: lineHeight
1729
+ } = this.textSpec;
1730
+ for (let i = 0; i < text.length; i++) {
1731
+ const char = text[i],
1732
+ size = ["F", "W"].includes(eastAsianCharacterInfo(char)) ? 1 : .53;
1733
+ totalSize.width += size * fontSize;
1734
+ }
1735
+ return totalSize.height = null !== (_a = lineHeight) && void 0 !== _a ? _a : fontSize, totalSize;
1736
+ }
1737
+ _measureReduce(text, processor) {
1738
+ var _a;
1739
+ const {
1740
+ fontSize: fontSize,
1741
+ lineHeight: lineHeight
1742
+ } = this.textSpec,
1743
+ defaultResult = {
1744
+ width: 0,
1745
+ height: 0
1746
+ };
1747
+ if (isNil$1(text)) return defaultResult;
1748
+ if (isArray$1(text)) {
1749
+ const textArr = text.filter(isValid$1).map(s => s.toString());
1750
+ return 0 === textArr.length ? defaultResult : 1 === textArr.length ? processor(textArr[0]) : {
1751
+ width: textArr.reduce((maxWidth, cur) => Math.max(maxWidth, processor(cur).width), 0),
1752
+ height: textArr.length * ((null !== (_a = lineHeight) && void 0 !== _a ? _a : fontSize) + 1) + 1
1753
+ };
1754
+ }
1755
+ return processor(text.toString());
1756
+ }
1757
+ _measureNumberChar() {
1758
+ if (isNil$1(this._numberCharSize)) {
1759
+ const numberBounds = this._standardMethod(TextMeasure.NUMBERS_CHAR_SET);
1760
+ this._numberCharSize = {
1761
+ width: numberBounds.width / TextMeasure.NUMBERS_CHAR_SET.length,
1762
+ height: numberBounds.height
1763
+ };
1764
+ }
1765
+ return this._numberCharSize;
1766
+ }
1767
+ _measureFullSizeChar() {
1768
+ return isNil$1(this._fullCharSize) && (this._fullCharSize = this._standardMethod(TextMeasure.FULL_SIZE_CHAR)), this._fullCharSize;
1769
+ }
1770
+ _measureLetterChar() {
1771
+ if (isNil$1(this._letterCharSize)) {
1772
+ const alphabetBounds = this._standardMethod(TextMeasure.ALPHABET_CHAR_SET);
1773
+ this._letterCharSize = {
1774
+ width: alphabetBounds.width / TextMeasure.ALPHABET_CHAR_SET.length,
1775
+ height: alphabetBounds.height
1776
+ };
1777
+ }
1778
+ return this._letterCharSize;
1779
+ }
1780
+ _measureSpecialChar(char) {
1781
+ return isValid$1(this._specialCharSizeMap[char]) ? this._specialCharSizeMap[char] : this.specialCharSet.includes(char) ? (this._specialCharSizeMap[char] = this._standardMethod(char), this._specialCharSizeMap[char]) : null;
1782
+ }
1783
+ release() {
1784
+ isValid$1(this._canvas) && (this._canvas = null), isValid$1(this._context) && (this._contextSaved && (this._context.restore(), this._contextSaved = !1), this._context = null);
1785
+ }
1786
+ }
1787
+ TextMeasure.ALPHABET_CHAR_SET = "abcdefghijklmnopqrstuvwxyz", TextMeasure.NUMBERS_CHAR_SET = "0123456789", TextMeasure.FULL_SIZE_CHAR = "字";
1788
+
1789
+ const calculateAnchorOfBounds = (bounds, anchorType) => {
1790
+ const {
1791
+ x1: x1,
1792
+ x2: x2,
1793
+ y1: y1,
1794
+ y2: y2
1795
+ } = bounds,
1796
+ rectWidth = Math.abs(x2 - x1),
1797
+ rectHeight = Math.abs(y2 - y1);
1798
+ let anchorX = (x1 + x2) / 2,
1799
+ anchorY = (y1 + y2) / 2,
1800
+ sx = 0,
1801
+ sy = 0;
1802
+ switch (anchorType) {
1803
+ case "top":
1804
+ case "inside-top":
1805
+ sy = -.5;
1806
+ break;
1807
+ case "bottom":
1808
+ case "inside-bottom":
1809
+ sy = .5;
1810
+ break;
1811
+ case "left":
1812
+ case "inside-left":
1813
+ sx = -.5;
1814
+ break;
1815
+ case "right":
1816
+ case "inside-right":
1817
+ sx = .5;
1818
+ break;
1819
+ case "top-right":
1820
+ sx = .5, sy = -.5;
1821
+ break;
1822
+ case "top-left":
1823
+ sx = -.5, sy = -.5;
1824
+ break;
1825
+ case "bottom-right":
1826
+ sx = .5, sy = .5;
1827
+ break;
1828
+ case "bottom-left":
1829
+ sx = -.5, sy = .5;
1830
+ }
1831
+ return anchorX += sx * rectWidth, anchorY += sy * rectHeight, {
1832
+ x: anchorX,
1833
+ y: anchorY
1834
+ };
1835
+ };
1836
+
1837
+ function transformBoundsWithMatrix(out, bounds, matrix) {
1838
+ const {
1839
+ x1: x1,
1840
+ y1: y1,
1841
+ x2: x2,
1842
+ y2: y2
1843
+ } = bounds;
1844
+ return matrix.onlyTranslate() ? (out !== bounds && out.setValue(bounds.x1, bounds.y1, bounds.x2, bounds.y2), out.translate(matrix.e, matrix.f), bounds) : (out.clear(), out.add(matrix.a * x1 + matrix.c * y1 + matrix.e, matrix.b * x1 + matrix.d * y1 + matrix.f), out.add(matrix.a * x2 + matrix.c * y1 + matrix.e, matrix.b * x2 + matrix.d * y1 + matrix.f), out.add(matrix.a * x2 + matrix.c * y2 + matrix.e, matrix.b * x2 + matrix.d * y2 + matrix.f), out.add(matrix.a * x1 + matrix.c * y2 + matrix.e, matrix.b * x1 + matrix.d * y2 + matrix.f), bounds);
1845
+ }
1846
+ class Bounds {
1847
+ constructor(bounds) {
1848
+ bounds ? this.setValue(bounds.x1, bounds.y1, bounds.x2, bounds.y2) : this.clear();
1849
+ }
1850
+ clone() {
1851
+ return new Bounds(this);
1852
+ }
1853
+ clear() {
1854
+ return this.x1 = +Number.MAX_VALUE, this.y1 = +Number.MAX_VALUE, this.x2 = -Number.MAX_VALUE, this.y2 = -Number.MAX_VALUE, this;
1855
+ }
1856
+ empty() {
1857
+ return this.x1 === +Number.MAX_VALUE && this.y1 === +Number.MAX_VALUE && this.x2 === -Number.MAX_VALUE && this.y2 === -Number.MAX_VALUE;
1858
+ }
1859
+ equals(b) {
1860
+ return this.x1 === b.x1 && this.y1 === b.y1 && this.x2 === b.x2 && this.y2 === b.y2;
1861
+ }
1862
+ setValue() {
1863
+ let x1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1864
+ let y1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1865
+ let x2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1866
+ let y2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1867
+ return this.x1 = x1, this.y1 = y1, this.x2 = x2, this.y2 = y2, this;
1868
+ }
1869
+ set() {
1870
+ let x1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1871
+ let y1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1872
+ let x2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1873
+ let y2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1874
+ return x2 < x1 ? (this.x2 = x1, this.x1 = x2) : (this.x1 = x1, this.x2 = x2), y2 < y1 ? (this.y2 = y1, this.y1 = y2) : (this.y1 = y1, this.y2 = y2), this;
1875
+ }
1876
+ add() {
1877
+ let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1878
+ let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1879
+ return x < this.x1 && (this.x1 = x), y < this.y1 && (this.y1 = y), x > this.x2 && (this.x2 = x), y > this.y2 && (this.y2 = y), this;
1880
+ }
1881
+ expand() {
1882
+ let d = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1883
+ return isArray$1(d) ? (this.y1 -= d[0], this.x2 += d[1], this.y2 += d[2], this.x1 -= d[3]) : (this.x1 -= d, this.y1 -= d, this.x2 += d, this.y2 += d), this;
1884
+ }
1885
+ round() {
1886
+ return this.x1 = Math.floor(this.x1), this.y1 = Math.floor(this.y1), this.x2 = Math.ceil(this.x2), this.y2 = Math.ceil(this.y2), this;
1887
+ }
1888
+ translate() {
1889
+ let dx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1890
+ let dy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1891
+ return this.x1 += dx, this.x2 += dx, this.y1 += dy, this.y2 += dy, this;
1892
+ }
1893
+ rotate() {
1894
+ let angle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1895
+ let x = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1896
+ let y = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1897
+ const p = this.rotatedPoints(angle, x, y);
1898
+ return this.clear().add(p[0], p[1]).add(p[2], p[3]).add(p[4], p[5]).add(p[6], p[7]);
1899
+ }
1900
+ scale() {
1901
+ let sx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1902
+ let sy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1903
+ let x = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1904
+ let y = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1905
+ const p = this.scalePoints(sx, sy, x, y);
1906
+ return this.clear().add(p[0], p[1]).add(p[2], p[3]);
1907
+ }
1908
+ union(b) {
1909
+ return b.x1 < this.x1 && (this.x1 = b.x1), b.y1 < this.y1 && (this.y1 = b.y1), b.x2 > this.x2 && (this.x2 = b.x2), b.y2 > this.y2 && (this.y2 = b.y2), this;
1910
+ }
1911
+ intersect(b) {
1912
+ return b.x1 > this.x1 && (this.x1 = b.x1), b.y1 > this.y1 && (this.y1 = b.y1), b.x2 < this.x2 && (this.x2 = b.x2), b.y2 < this.y2 && (this.y2 = b.y2), this;
1913
+ }
1914
+ encloses(b) {
1915
+ return b && this.x1 <= b.x1 && this.x2 >= b.x2 && this.y1 <= b.y1 && this.y2 >= b.y2;
1916
+ }
1917
+ alignsWith(b) {
1918
+ return b && (this.x1 === b.x1 || this.x2 === b.x2 || this.y1 === b.y1 || this.y2 === b.y2);
1919
+ }
1920
+ intersects(b) {
1921
+ return b && !(this.x2 < b.x1 || this.x1 > b.x2 || this.y2 < b.y1 || this.y1 > b.y2);
1922
+ }
1923
+ contains() {
1924
+ let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1925
+ let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1926
+ return !(x < this.x1 || x > this.x2 || y < this.y1 || y > this.y2);
1927
+ }
1928
+ containsPoint(p) {
1929
+ return !(p.x < this.x1 || p.x > this.x2 || p.y < this.y1 || p.y > this.y2);
1930
+ }
1931
+ width() {
1932
+ return this.empty() ? 0 : this.x2 - this.x1;
1933
+ }
1934
+ height() {
1935
+ return this.empty() ? 0 : this.y2 - this.y1;
1936
+ }
1937
+ scaleX() {
1938
+ let s = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1939
+ return this.x1 *= s, this.x2 *= s, this;
1940
+ }
1941
+ scaleY() {
1942
+ let s = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1943
+ return this.y1 *= s, this.y2 *= s, this;
1944
+ }
1945
+ transformWithMatrix(matrix) {
1946
+ return transformBoundsWithMatrix(this, this, matrix), this;
1947
+ }
1948
+ copy(b) {
1949
+ return this.x1 = b.x1, this.y1 = b.y1, this.x2 = b.x2, this.y2 = b.y2, this;
1950
+ }
1951
+ rotatedPoints(angle, x, y) {
1952
+ const {
1953
+ x1: x1,
1954
+ y1: y1,
1955
+ x2: x2,
1956
+ y2: y2
1957
+ } = this,
1958
+ cos = Math.cos(angle),
1959
+ sin = Math.sin(angle),
1960
+ cx = x - x * cos + y * sin,
1961
+ cy = y - x * sin - y * cos;
1962
+ return [cos * x1 - sin * y1 + cx, sin * x1 + cos * y1 + cy, cos * x1 - sin * y2 + cx, sin * x1 + cos * y2 + cy, cos * x2 - sin * y1 + cx, sin * x2 + cos * y1 + cy, cos * x2 - sin * y2 + cx, sin * x2 + cos * y2 + cy];
1963
+ }
1964
+ scalePoints(sx, sy, x, y) {
1965
+ const {
1966
+ x1: x1,
1967
+ y1: y1,
1968
+ x2: x2,
1969
+ y2: y2
1970
+ } = this;
1971
+ return [sx * x1 + (1 - sx) * x, sy * y1 + (1 - sy) * y, sx * x2 + (1 - sx) * x, sy * y2 + (1 - sy) * y];
1972
+ }
1973
+ }
1974
+ class AABBBounds extends Bounds {}
1975
+ class OBBBounds extends Bounds {
1976
+ constructor(bounds) {
1977
+ let angle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1978
+ super(bounds), bounds && (this.angle = angle);
1979
+ }
1980
+ intersects(b) {
1981
+ return isRotateAABBIntersect(this, b);
1982
+ }
1983
+ setValue() {
1984
+ let x1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1985
+ let y1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1986
+ let x2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1987
+ let y2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1988
+ let angle = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
1989
+ return super.setValue(x1, y1, x2, y2), this.angle = angle, this;
1990
+ }
1991
+ }
1992
+
1993
+ class Matrix {
1994
+ constructor() {
1995
+ let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
1996
+ let b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1997
+ let c = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1998
+ let d = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
1999
+ let e = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
2000
+ let f = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
2001
+ this.a = a, this.b = b, this.c = c, this.d = d, this.e = e, this.f = f;
2002
+ }
2003
+ equalToMatrix(m2) {
2004
+ return !(this.e !== m2.e || this.f !== m2.f || this.a !== m2.a || this.d !== m2.d || this.b !== m2.b || this.c !== m2.c);
2005
+ }
2006
+ equalTo(a, b, c, d, e, f) {
2007
+ return !(this.e !== e || this.f !== f || this.a !== a || this.d !== d || this.b !== b || this.c !== c);
2008
+ }
2009
+ setValue(a, b, c, d, e, f) {
2010
+ return this.a = a, this.b = b, this.c = c, this.d = d, this.e = e, this.f = f, this;
2011
+ }
2012
+ reset() {
2013
+ return this.a = 1, this.b = 0, this.c = 0, this.d = 1, this.e = 0, this.f = 0, this;
2014
+ }
2015
+ getInverse() {
2016
+ const a = this.a,
2017
+ b = this.b,
2018
+ c = this.c,
2019
+ d = this.d,
2020
+ e = this.e,
2021
+ f = this.f,
2022
+ m = new Matrix(),
2023
+ dt = a * d - b * c;
2024
+ return m.a = d / dt, m.b = -b / dt, m.c = -c / dt, m.d = a / dt, m.e = (c * f - d * e) / dt, m.f = -(a * f - b * e) / dt, m;
2025
+ }
2026
+ rotate(rad) {
2027
+ const c = Math.cos(rad),
1571
2028
  s = Math.sin(rad),
1572
2029
  m11 = this.a * c + this.c * s,
1573
2030
  m12 = this.b * c + this.d * s,
@@ -1991,522 +2448,152 @@ class Color {
1991
2448
  if (void 0 !== hexRes) return hexRes;
1992
2449
  if (/^(rgb|RGB|rgba|RGBA)/.test(formatValue)) {
1993
2450
  const aColor = formatValue.replace(/(?:\(|\)|rgba|RGBA|rgb|RGB)*/g, "").split(",");
1994
- return new RGB(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10), parseFloat(aColor[3]));
1995
- }
1996
- if (/^(hsl|HSL|hsla|HSLA)/.test(formatValue)) {
1997
- const aColor = formatValue.replace(/(?:\(|\)|hsla|HSLA|hsl|HSL)*/g, "").split(","),
1998
- rgb = hslToRgb(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10));
1999
- return new RGB(rgb.r, rgb.g, rgb.b, parseFloat(aColor[3]));
2000
- }
2001
- }
2002
- constructor(value) {
2003
- const color = Color.parseColorString(value);
2004
- color ? this.color = color : (console.warn(`Warn: 传入${value}无法解析为Color`), this.color = new RGB(255, 255, 255));
2005
- }
2006
- toRGBA() {
2007
- return this.color.formatRgb();
2008
- }
2009
- toString() {
2010
- return this.color.formatRgb();
2011
- }
2012
- toHex() {
2013
- return this.color.formatHex();
2014
- }
2015
- toHsl() {
2016
- return this.color.formatHsl();
2017
- }
2018
- brighter(k) {
2019
- const {
2020
- r: r,
2021
- g: g,
2022
- b: b
2023
- } = this.color;
2024
- return this.color.r = Math.max(0, Math.min(255, Math.floor(r * k))), this.color.g = Math.max(0, Math.min(255, Math.floor(g * k))), this.color.b = Math.max(0, Math.min(255, Math.floor(b * k))), this;
2025
- }
2026
- add(color) {
2027
- const {
2028
- r: r,
2029
- g: g,
2030
- b: b
2031
- } = this.color;
2032
- return this.color.r += Math.min(255, r + color.color.r), this.color.g += Math.min(255, g + color.color.g), this.color.b += Math.min(255, b + color.color.b), this;
2033
- }
2034
- sub(color) {
2035
- return this.color.r = Math.max(0, this.color.r - color.color.r), this.color.g = Math.max(0, this.color.g - color.color.g), this.color.b = Math.max(0, this.color.b - color.color.b), this;
2036
- }
2037
- multiply(color) {
2038
- const {
2039
- r: r,
2040
- g: g,
2041
- b: b
2042
- } = this.color;
2043
- return this.color.r = Math.max(0, Math.min(255, Math.floor(r * color.color.r))), this.color.g = Math.max(0, Math.min(255, Math.floor(g * color.color.g))), this.color.b = Math.max(0, Math.min(255, Math.floor(b * color.color.b))), this;
2044
- }
2045
- getHSVBrightness() {
2046
- return Math.max(this.color.r, this.color.g, this.color.b) / 255;
2047
- }
2048
- getHSLBrightness() {
2049
- return .5 * (Math.max(this.color.r, this.color.g, this.color.b) / 255 + Math.min(this.color.r, this.color.g, this.color.b) / 255);
2050
- }
2051
- setHsl(h, s, l) {
2052
- const opacity = this.color.opacity,
2053
- hsl = rgbToHsl(this.color.r, this.color.g, this.color.b),
2054
- rgb = hslToRgb(isNil$1(h) ? hsl.h : clamp$1(h, 0, 360), isNil$1(s) ? hsl.s : s >= 0 && s <= 1 ? 100 * s : s, isNil$1(l) ? hsl.l : l <= 1 && l >= 0 ? 100 * l : l);
2055
- return this.color = new RGB(rgb.r, rgb.g, rgb.b, opacity), this;
2056
- }
2057
- setRGB(r, g, b) {
2058
- return !isNil$1(r) && (this.color.r = r), !isNil$1(g) && (this.color.g = g), !isNil$1(b) && (this.color.b = b), this;
2059
- }
2060
- setHex(value) {
2061
- const formatValue = `${value}`.trim().toLowerCase(),
2062
- res = setHex(formatValue, !0);
2063
- return null != res ? res : this;
2064
- }
2065
- setColorName(name) {
2066
- const hex = DEFAULT_COLORS[name.toLowerCase()];
2067
- return void 0 !== hex ? this.setHex(hex) : console.warn("THREE.Color: Unknown color " + name), this;
2068
- }
2069
- setScalar(scalar) {
2070
- return this.color.r = scalar, this.color.g = scalar, this.color.b = scalar, this;
2071
- }
2072
- setOpacity() {
2073
- let o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
2074
- return this.color.opacity = o, this;
2075
- }
2076
- getLuminance() {
2077
- return (.2126 * this.color.r + .7152 * this.color.g + .0722 * this.color.b) / 255;
2078
- }
2079
- getLuminance2() {
2080
- return (.2627 * this.color.r + .678 * this.color.g + .0593 * this.color.b) / 255;
2081
- }
2082
- getLuminance3() {
2083
- return (.299 * this.color.r + .587 * this.color.g + .114 * this.color.b) / 255;
2084
- }
2085
- clone() {
2086
- return new Color(this.color.toString());
2087
- }
2088
- copyGammaToLinear(color) {
2089
- let gammaFactor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
2090
- return this.color.r = Math.pow(color.color.r, gammaFactor), this.color.g = Math.pow(color.color.g, gammaFactor), this.color.b = Math.pow(color.color.b, gammaFactor), this;
2091
- }
2092
- copyLinearToGamma(color) {
2093
- let gammaFactor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
2094
- const safeInverse = gammaFactor > 0 ? 1 / gammaFactor : 1;
2095
- return this.color.r = Math.pow(color.color.r, safeInverse), this.color.g = Math.pow(color.color.g, safeInverse), this.color.b = Math.pow(color.color.b, safeInverse), this;
2096
- }
2097
- convertGammaToLinear(gammaFactor) {
2098
- return this.copyGammaToLinear(this, gammaFactor), this;
2099
- }
2100
- convertLinearToGamma(gammaFactor) {
2101
- return this.copyLinearToGamma(this, gammaFactor), this;
2102
- }
2103
- copySRGBToLinear(color) {
2104
- return this.color.r = SRGBToLinear(color.color.r), this.color.g = SRGBToLinear(color.color.g), this.color.b = SRGBToLinear(color.color.b), this;
2451
+ return new RGB(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10), parseFloat(aColor[3]));
2452
+ }
2453
+ if (/^(hsl|HSL|hsla|HSLA)/.test(formatValue)) {
2454
+ const aColor = formatValue.replace(/(?:\(|\)|hsla|HSLA|hsl|HSL)*/g, "").split(","),
2455
+ rgb = hslToRgb(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10));
2456
+ return new RGB(rgb.r, rgb.g, rgb.b, parseFloat(aColor[3]));
2457
+ }
2105
2458
  }
2106
- copyLinearToSRGB(color) {
2107
- return this.color.r = LinearToSRGB(color.color.r), this.color.g = LinearToSRGB(color.color.g), this.color.b = LinearToSRGB(color.color.b), this;
2459
+ constructor(value) {
2460
+ const color = Color.parseColorString(value);
2461
+ color ? this.color = color : (console.warn(`Warn: 传入${value}无法解析为Color`), this.color = new RGB(255, 255, 255));
2108
2462
  }
2109
- convertSRGBToLinear() {
2110
- return this.copySRGBToLinear(this), this;
2463
+ toRGBA() {
2464
+ return this.color.formatRgb();
2111
2465
  }
2112
- convertLinearToSRGB() {
2113
- return this.copyLinearToSRGB(this), this;
2466
+ toString() {
2467
+ return this.color.formatRgb();
2114
2468
  }
2115
- }
2116
- class RGB {
2117
- constructor(r, g, b, opacity) {
2118
- this.r = isNaN(+r) ? 255 : Math.max(0, Math.min(255, +r)), this.g = isNaN(+g) ? 255 : Math.max(0, Math.min(255, +g)), this.b = isNaN(+b) ? 255 : Math.max(0, Math.min(255, +b)), isValid$1(opacity) ? this.opacity = isNaN(+opacity) ? 1 : Math.max(0, Math.min(1, +opacity)) : this.opacity = 1;
2469
+ toHex() {
2470
+ return this.color.formatHex();
2119
2471
  }
2120
- formatHex() {
2121
- return `#${hex(this.r) + hex(this.g) + hex(this.b) + (1 === this.opacity ? "" : hex(255 * this.opacity))}`;
2472
+ toHsl() {
2473
+ return this.color.formatHsl();
2122
2474
  }
2123
- formatRgb() {
2124
- const opacity = this.opacity;
2125
- return `${1 === opacity ? "rgb(" : "rgba("}${this.r},${this.g},${this.b}${1 === opacity ? ")" : `,${opacity})`}`;
2475
+ brighter(k) {
2476
+ const {
2477
+ r: r,
2478
+ g: g,
2479
+ b: b
2480
+ } = this.color;
2481
+ return this.color.r = Math.max(0, Math.min(255, Math.floor(r * k))), this.color.g = Math.max(0, Math.min(255, Math.floor(g * k))), this.color.b = Math.max(0, Math.min(255, Math.floor(b * k))), this;
2126
2482
  }
2127
- formatHsl() {
2128
- const opacity = this.opacity,
2129
- {
2130
- h: h,
2131
- s: s,
2132
- l: l
2133
- } = rgbToHsl(this.r, this.g, this.b);
2134
- return `${1 === opacity ? "hsl(" : "hsla("}${h},${s}%,${l}%${1 === opacity ? ")" : `,${opacity})`}`;
2483
+ add(color) {
2484
+ const {
2485
+ r: r,
2486
+ g: g,
2487
+ b: b
2488
+ } = this.color;
2489
+ return this.color.r += Math.min(255, r + color.color.r), this.color.g += Math.min(255, g + color.color.g), this.color.b += Math.min(255, b + color.color.b), this;
2135
2490
  }
2136
- toString() {
2137
- return this.formatHex();
2491
+ sub(color) {
2492
+ return this.color.r = Math.max(0, this.color.r - color.color.r), this.color.g = Math.max(0, this.color.g - color.color.g), this.color.b = Math.max(0, this.color.b - color.color.b), this;
2138
2493
  }
2139
- }
2140
-
2141
- function sub(out, v1, v2) {
2142
- out[0] = v1[0] - v2[0], out[1] = v1[1] - v2[1];
2143
- }
2144
- function isIntersect(left1, right1, left2, right2) {
2145
- let min1 = left1[0],
2146
- max1 = right1[0],
2147
- min2 = left2[0],
2148
- max2 = right2[0];
2149
- return max1 < min1 && ([min1, max1] = [max1, min1]), max2 < min2 && ([max2, min2] = [min2, max2]), !(max1 < min2 || max2 < min1) && (min1 = left1[1], max1 = right1[1], min2 = left2[1], max2 = right2[1], max1 < min1 && ([min1, max1] = [max1, min1]), max2 < min2 && ([max2, min2] = [min2, max2]), !(max1 < min2 || max2 < min1));
2150
- }
2151
- function getIntersectPoint(left1, right1, left2, right2) {
2152
- if (!isIntersect(left1, right1, left2, right2)) return !1;
2153
- const dir1 = [0, 0],
2154
- dir2 = [0, 0],
2155
- tempVec = [0, 0];
2156
- if (sub(dir1, right1, left1), sub(dir2, right2, left2), fuzzyEqualVec(dir1, dir2)) return !0;
2157
- sub(tempVec, left2, left1);
2158
- const t = crossProduct$1(tempVec, dir2) / crossProduct$1(dir1, dir2);
2159
- return t >= 0 && t <= 1 && [left1[0] + dir1[0] * t, left1[1] + dir1[1] * t];
2160
- }
2161
- function getRectIntersect(bbox1, bbox2, format) {
2162
- if (null === bbox1) return bbox2;
2163
- if (null === bbox2) return bbox1;
2164
- const {
2165
- x11: x11,
2166
- x12: x12,
2167
- y11: y11,
2168
- y12: y12,
2169
- x21: x21,
2170
- x22: x22,
2171
- y21: y21,
2172
- y22: y22
2173
- } = formatTwoBBox(bbox1, bbox2, format);
2174
- return x11 >= x22 || x12 <= x21 || y11 >= y22 || y12 <= y21 ? {
2175
- x1: 0,
2176
- y1: 0,
2177
- x2: 0,
2178
- y2: 0
2179
- } : {
2180
- x1: Math.max(x11, x21),
2181
- y1: Math.max(y11, y21),
2182
- x2: Math.min(x12, x22),
2183
- y2: Math.min(y12, y22)
2184
- };
2185
- }
2186
- var InnerBBox;
2187
- !function (InnerBBox) {
2188
- InnerBBox[InnerBBox.NONE = 0] = "NONE", InnerBBox[InnerBBox.BBOX1 = 1] = "BBOX1", InnerBBox[InnerBBox.BBOX2 = 2] = "BBOX2";
2189
- }(InnerBBox || (InnerBBox = {}));
2190
- const formatTwoBBox = (bbox1, bbox2, format) => {
2191
- let x11 = bbox1.x1,
2192
- x12 = bbox1.x2,
2193
- y11 = bbox1.y1,
2194
- y12 = bbox1.y2,
2195
- x21 = bbox2.x1,
2196
- x22 = bbox2.x2,
2197
- y21 = bbox2.y1,
2198
- y22 = bbox2.y2;
2199
- return format && (x11 > x12 && ([x11, x12] = [x12, x11]), y11 > y12 && ([y11, y12] = [y12, y11]), x21 > x22 && ([x21, x22] = [x22, x21]), y21 > y22 && ([y21, y22] = [y22, y21])), {
2200
- x11: x11,
2201
- x12: x12,
2202
- y11: y11,
2203
- y12: y12,
2204
- x21: x21,
2205
- x22: x22,
2206
- y21: y21,
2207
- y22: y22
2208
- };
2209
- };
2210
- function isRectIntersect(bbox1, bbox2, format) {
2211
- if (bbox1 && bbox2) {
2212
- if (!format) return !(bbox1.x1 > bbox2.x2 || bbox1.x2 < bbox2.x1 || bbox1.y1 > bbox2.y2 || bbox1.y2 < bbox2.y1);
2494
+ multiply(color) {
2213
2495
  const {
2214
- x11: x11,
2215
- x12: x12,
2216
- y11: y11,
2217
- y12: y12,
2218
- x21: x21,
2219
- x22: x22,
2220
- y21: y21,
2221
- y22: y22
2222
- } = formatTwoBBox(bbox1, bbox2, !0);
2223
- return !(x11 > x22 || x12 < x21 || y11 > y22 || y12 < y21);
2496
+ r: r,
2497
+ g: g,
2498
+ b: b
2499
+ } = this.color;
2500
+ return this.color.r = Math.max(0, Math.min(255, Math.floor(r * color.color.r))), this.color.g = Math.max(0, Math.min(255, Math.floor(g * color.color.g))), this.color.b = Math.max(0, Math.min(255, Math.floor(b * color.color.b))), this;
2224
2501
  }
2225
- return !0;
2226
- }
2227
-
2228
- function isPointInLine(x0, y0, x1, y1, x, y) {
2229
- if (y > y0 && y > y1 || y < y0 && y < y1) return 0;
2230
- if (y1 === y0) return 0;
2231
- const t = (y - y0) / (y1 - y0);
2232
- let dir = y1 < y0 ? 1 : -1;
2233
- 1 !== t && 0 !== t || (dir = y1 < y0 ? .5 : -.5);
2234
- const x_ = t * (x1 - x0) + x0;
2235
- return x_ === x ? 1 / 0 : x_ > x ? dir : 0;
2236
- }
2237
-
2238
- const eastAsianCharacterInfo = character => {
2239
- let x = character.charCodeAt(0),
2240
- y = 2 === character.length ? character.charCodeAt(1) : 0,
2241
- codePoint = x;
2242
- return 55296 <= x && x <= 56319 && 56320 <= y && y <= 57343 && (x &= 1023, y &= 1023, codePoint = x << 10 | y, codePoint += 65536), 12288 === codePoint || 65281 <= codePoint && codePoint <= 65376 || 65504 <= codePoint && codePoint <= 65510 ? "F" : 8361 === codePoint || 65377 <= codePoint && codePoint <= 65470 || 65474 <= codePoint && codePoint <= 65479 || 65482 <= codePoint && codePoint <= 65487 || 65490 <= codePoint && codePoint <= 65495 || 65498 <= codePoint && codePoint <= 65500 || 65512 <= codePoint && codePoint <= 65518 ? "H" : 4352 <= codePoint && codePoint <= 4447 || 4515 <= codePoint && codePoint <= 4519 || 4602 <= codePoint && codePoint <= 4607 || 9001 <= codePoint && codePoint <= 9002 || 11904 <= codePoint && codePoint <= 11929 || 11931 <= codePoint && codePoint <= 12019 || 12032 <= codePoint && codePoint <= 12245 || 12272 <= codePoint && codePoint <= 12283 || 12289 <= codePoint && codePoint <= 12350 || 12353 <= codePoint && codePoint <= 12438 || 12441 <= codePoint && codePoint <= 12543 || 12549 <= codePoint && codePoint <= 12589 || 12593 <= codePoint && codePoint <= 12686 || 12688 <= codePoint && codePoint <= 12730 || 12736 <= codePoint && codePoint <= 12771 || 12784 <= codePoint && codePoint <= 12830 || 12832 <= codePoint && codePoint <= 12871 || 12880 <= codePoint && codePoint <= 13054 || 13056 <= codePoint && codePoint <= 19903 || 19968 <= codePoint && codePoint <= 42124 || 42128 <= codePoint && codePoint <= 42182 || 43360 <= codePoint && codePoint <= 43388 || 44032 <= codePoint && codePoint <= 55203 || 55216 <= codePoint && codePoint <= 55238 || 55243 <= codePoint && codePoint <= 55291 || 63744 <= codePoint && codePoint <= 64255 || 65040 <= codePoint && codePoint <= 65049 || 65072 <= codePoint && codePoint <= 65106 || 65108 <= codePoint && codePoint <= 65126 || 65128 <= codePoint && codePoint <= 65131 || 110592 <= codePoint && codePoint <= 110593 || 127488 <= codePoint && codePoint <= 127490 || 127504 <= codePoint && codePoint <= 127546 || 127552 <= codePoint && codePoint <= 127560 || 127568 <= codePoint && codePoint <= 127569 || 131072 <= codePoint && codePoint <= 194367 || 177984 <= codePoint && codePoint <= 196605 || 196608 <= codePoint && codePoint <= 262141 ? "W" : 32 <= codePoint && codePoint <= 126 || 162 <= codePoint && codePoint <= 163 || 165 <= codePoint && codePoint <= 166 || 172 === codePoint || 175 === codePoint || 10214 <= codePoint && codePoint <= 10221 || 10629 <= codePoint && codePoint <= 10630 ? "Na" : 161 === codePoint || 164 === codePoint || 167 <= codePoint && codePoint <= 168 || 170 === codePoint || 173 <= codePoint && codePoint <= 174 || 176 <= codePoint && codePoint <= 180 || 182 <= codePoint && codePoint <= 186 || 188 <= codePoint && codePoint <= 191 || 198 === codePoint || 208 === codePoint || 215 <= codePoint && codePoint <= 216 || 222 <= codePoint && codePoint <= 225 || 230 === codePoint || 232 <= codePoint && codePoint <= 234 || 236 <= codePoint && codePoint <= 237 || 240 === codePoint || 242 <= codePoint && codePoint <= 243 || 247 <= codePoint && codePoint <= 250 || 252 === codePoint || 254 === codePoint || 257 === codePoint || 273 === codePoint || 275 === codePoint || 283 === codePoint || 294 <= codePoint && codePoint <= 295 || 299 === codePoint || 305 <= codePoint && codePoint <= 307 || 312 === codePoint || 319 <= codePoint && codePoint <= 322 || 324 === codePoint || 328 <= codePoint && codePoint <= 331 || 333 === codePoint || 338 <= codePoint && codePoint <= 339 || 358 <= codePoint && codePoint <= 359 || 363 === codePoint || 462 === codePoint || 464 === codePoint || 466 === codePoint || 468 === codePoint || 470 === codePoint || 472 === codePoint || 474 === codePoint || 476 === codePoint || 593 === codePoint || 609 === codePoint || 708 === codePoint || 711 === codePoint || 713 <= codePoint && codePoint <= 715 || 717 === codePoint || 720 === codePoint || 728 <= codePoint && codePoint <= 731 || 733 === codePoint || 735 === codePoint || 768 <= codePoint && codePoint <= 879 || 913 <= codePoint && codePoint <= 929 || 931 <= codePoint && codePoint <= 937 || 945 <= codePoint && codePoint <= 961 || 963 <= codePoint && codePoint <= 969 || 1025 === codePoint || 1040 <= codePoint && codePoint <= 1103 || 1105 === codePoint || 8208 === codePoint || 8211 <= codePoint && codePoint <= 8214 || 8216 <= codePoint && codePoint <= 8217 || 8220 <= codePoint && codePoint <= 8221 || 8224 <= codePoint && codePoint <= 8226 || 8228 <= codePoint && codePoint <= 8231 || 8240 === codePoint || 8242 <= codePoint && codePoint <= 8243 || 8245 === codePoint || 8251 === codePoint || 8254 === codePoint || 8308 === codePoint || 8319 === codePoint || 8321 <= codePoint && codePoint <= 8324 || 8364 === codePoint || 8451 === codePoint || 8453 === codePoint || 8457 === codePoint || 8467 === codePoint || 8470 === codePoint || 8481 <= codePoint && codePoint <= 8482 || 8486 === codePoint || 8491 === codePoint || 8531 <= codePoint && codePoint <= 8532 || 8539 <= codePoint && codePoint <= 8542 || 8544 <= codePoint && codePoint <= 8555 || 8560 <= codePoint && codePoint <= 8569 || 8585 === codePoint || 8592 <= codePoint && codePoint <= 8601 || 8632 <= codePoint && codePoint <= 8633 || 8658 === codePoint || 8660 === codePoint || 8679 === codePoint || 8704 === codePoint || 8706 <= codePoint && codePoint <= 8707 || 8711 <= codePoint && codePoint <= 8712 || 8715 === codePoint || 8719 === codePoint || 8721 === codePoint || 8725 === codePoint || 8730 === codePoint || 8733 <= codePoint && codePoint <= 8736 || 8739 === codePoint || 8741 === codePoint || 8743 <= codePoint && codePoint <= 8748 || 8750 === codePoint || 8756 <= codePoint && codePoint <= 8759 || 8764 <= codePoint && codePoint <= 8765 || 8776 === codePoint || 8780 === codePoint || 8786 === codePoint || 8800 <= codePoint && codePoint <= 8801 || 8804 <= codePoint && codePoint <= 8807 || 8810 <= codePoint && codePoint <= 8811 || 8814 <= codePoint && codePoint <= 8815 || 8834 <= codePoint && codePoint <= 8835 || 8838 <= codePoint && codePoint <= 8839 || 8853 === codePoint || 8857 === codePoint || 8869 === codePoint || 8895 === codePoint || 8978 === codePoint || 9312 <= codePoint && codePoint <= 9449 || 9451 <= codePoint && codePoint <= 9547 || 9552 <= codePoint && codePoint <= 9587 || 9600 <= codePoint && codePoint <= 9615 || 9618 <= codePoint && codePoint <= 9621 || 9632 <= codePoint && codePoint <= 9633 || 9635 <= codePoint && codePoint <= 9641 || 9650 <= codePoint && codePoint <= 9651 || 9654 <= codePoint && codePoint <= 9655 || 9660 <= codePoint && codePoint <= 9661 || 9664 <= codePoint && codePoint <= 9665 || 9670 <= codePoint && codePoint <= 9672 || 9675 === codePoint || 9678 <= codePoint && codePoint <= 9681 || 9698 <= codePoint && codePoint <= 9701 || 9711 === codePoint || 9733 <= codePoint && codePoint <= 9734 || 9737 === codePoint || 9742 <= codePoint && codePoint <= 9743 || 9748 <= codePoint && codePoint <= 9749 || 9756 === codePoint || 9758 === codePoint || 9792 === codePoint || 9794 === codePoint || 9824 <= codePoint && codePoint <= 9825 || 9827 <= codePoint && codePoint <= 9829 || 9831 <= codePoint && codePoint <= 9834 || 9836 <= codePoint && codePoint <= 9837 || 9839 === codePoint || 9886 <= codePoint && codePoint <= 9887 || 9918 <= codePoint && codePoint <= 9919 || 9924 <= codePoint && codePoint <= 9933 || 9935 <= codePoint && codePoint <= 9953 || 9955 === codePoint || 9960 <= codePoint && codePoint <= 9983 || 10045 === codePoint || 10071 === codePoint || 10102 <= codePoint && codePoint <= 10111 || 11093 <= codePoint && codePoint <= 11097 || 12872 <= codePoint && codePoint <= 12879 || 57344 <= codePoint && codePoint <= 63743 || 65024 <= codePoint && codePoint <= 65039 || 65533 === codePoint || 127232 <= codePoint && codePoint <= 127242 || 127248 <= codePoint && codePoint <= 127277 || 127280 <= codePoint && codePoint <= 127337 || 127344 <= codePoint && codePoint <= 127386 || 917760 <= codePoint && codePoint <= 917999 || 983040 <= codePoint && codePoint <= 1048573 || 1048576 <= codePoint && codePoint <= 1114109 ? "A" : "N";
2243
- };
2244
-
2245
- function getContextFont(text) {
2246
- let defaultAttr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2247
- let fontSizeScale = arguments.length > 2 ? arguments[2] : undefined;
2248
- fontSizeScale || (fontSizeScale = 1);
2249
- const {
2250
- fontStyle = defaultAttr.fontStyle,
2251
- fontVariant = defaultAttr.fontVariant,
2252
- fontWeight = defaultAttr.fontWeight,
2253
- fontSize = defaultAttr.fontSize,
2254
- fontFamily = defaultAttr.fontFamily
2255
- } = text;
2256
- return (fontStyle ? fontStyle + " " : "") + (fontVariant ? fontVariant + " " : "") + (fontWeight ? fontWeight + " " : "") + fontSize * fontSizeScale + "px " + (fontFamily || "sans-serif");
2257
- }
2258
-
2259
- class TextMeasure {
2260
- constructor(option, textSpec) {
2261
- this._numberCharSize = null, this._fullCharSize = null, this._letterCharSize = null, this._specialCharSizeMap = {}, this._canvas = null, this._context = null, this._contextSaved = !1, this._notSupportCanvas = !1, this._notSupportVRender = !1, this._userSpec = {}, this.specialCharSet = "-/: .,@%'\"~", this._option = option, this._userSpec = null != textSpec ? textSpec : {}, this.textSpec = this._initSpec(), isValid$1(option.specialCharSet) && (this.specialCharSet = option.specialCharSet), this._standardMethod = isValid$1(option.getTextBounds) ? this.fullMeasure.bind(this) : this.measureWithNaiveCanvas.bind(this);
2502
+ getHSVBrightness() {
2503
+ return Math.max(this.color.r, this.color.g, this.color.b) / 255;
2262
2504
  }
2263
- initContext() {
2264
- if (this._notSupportCanvas) return !1;
2265
- if (isNil$1(this._canvas) && (isValid$1(this._option.getCanvasForMeasure) && (this._canvas = this._option.getCanvasForMeasure()), isNil$1(this._canvas) && "undefined" != typeof window && void 0 !== window.document && globalThis && isValid$1(globalThis.document) && (this._canvas = globalThis.document.createElement("canvas"))), isNil$1(this._context) && isValid$1(this._canvas)) {
2266
- const context = this._canvas.getContext("2d");
2267
- isValid$1(context) && (context.save(), context.font = getContextFont(this.textSpec), this._contextSaved = !0, this._context = context);
2268
- }
2269
- return !isNil$1(this._context) || (this._notSupportCanvas = !0, !1);
2505
+ getHSLBrightness() {
2506
+ return .5 * (Math.max(this.color.r, this.color.g, this.color.b) / 255 + Math.min(this.color.r, this.color.g, this.color.b) / 255);
2270
2507
  }
2271
- _initSpec() {
2272
- var _a, _b, _c;
2273
- const {
2274
- defaultFontParams = {}
2275
- } = this._option,
2276
- {
2277
- fontStyle = defaultFontParams.fontStyle,
2278
- fontVariant = defaultFontParams.fontVariant,
2279
- fontWeight = null !== (_a = defaultFontParams.fontWeight) && void 0 !== _a ? _a : "normal",
2280
- fontSize = null !== (_b = defaultFontParams.fontSize) && void 0 !== _b ? _b : 12,
2281
- fontFamily = null !== (_c = defaultFontParams.fontFamily) && void 0 !== _c ? _c : "sans-serif",
2282
- align: align,
2283
- textAlign = null != align ? align : "center",
2284
- baseline: baseline,
2285
- textBaseline = null != baseline ? baseline : "middle",
2286
- ellipsis: ellipsis,
2287
- limit: limit
2288
- } = this._userSpec;
2289
- let {
2290
- lineHeight = fontSize
2291
- } = this._userSpec;
2292
- if (isString$1(lineHeight) && "%" === lineHeight[lineHeight.length - 1]) {
2293
- const scale = Number.parseFloat(lineHeight.substring(0, lineHeight.length - 1)) / 100;
2294
- lineHeight = fontSize * scale;
2295
- }
2296
- return {
2297
- fontStyle: fontStyle,
2298
- fontVariant: fontVariant,
2299
- fontFamily: fontFamily,
2300
- fontSize: fontSize,
2301
- fontWeight: fontWeight,
2302
- textAlign: textAlign,
2303
- textBaseline: textBaseline,
2304
- ellipsis: ellipsis,
2305
- limit: limit,
2306
- lineHeight: lineHeight
2307
- };
2508
+ setHsl(h, s, l) {
2509
+ const opacity = this.color.opacity,
2510
+ hsl = rgbToHsl(this.color.r, this.color.g, this.color.b),
2511
+ rgb = hslToRgb(isNil$1(h) ? hsl.h : clamp$1(h, 0, 360), isNil$1(s) ? hsl.s : s >= 0 && s <= 1 ? 100 * s : s, isNil$1(l) ? hsl.l : l <= 1 && l >= 0 ? 100 * l : l);
2512
+ return this.color = new RGB(rgb.r, rgb.g, rgb.b, opacity), this;
2308
2513
  }
2309
- measure(text, method) {
2310
- switch (method) {
2311
- case "vrender":
2312
- case "canopus":
2313
- return this.fullMeasure(text);
2314
- case "canvas":
2315
- return this.measureWithNaiveCanvas(text);
2316
- case "simple":
2317
- return this.quickMeasureWithoutCanvas(text);
2318
- default:
2319
- return this.quickMeasure(text);
2320
- }
2514
+ setRGB(r, g, b) {
2515
+ return !isNil$1(r) && (this.color.r = r), !isNil$1(g) && (this.color.g = g), !isNil$1(b) && (this.color.b = b), this;
2516
+ }
2517
+ setHex(value) {
2518
+ const formatValue = `${value}`.trim().toLowerCase(),
2519
+ res = setHex(formatValue, !0);
2520
+ return null != res ? res : this;
2321
2521
  }
2322
- fullMeasure(text) {
2323
- if (isNil$1(text)) return {
2324
- width: 0,
2325
- height: 0
2326
- };
2327
- if (isNil$1(this._option.getTextBounds) || !this._notSupportVRender) return this.measureWithNaiveCanvas(text);
2328
- const {
2329
- fontFamily: fontFamily,
2330
- fontSize: fontSize,
2331
- fontWeight: fontWeight,
2332
- textAlign: textAlign,
2333
- textBaseline: textBaseline,
2334
- ellipsis: ellipsis,
2335
- limit: limit,
2336
- lineHeight: lineHeight
2337
- } = this.textSpec;
2338
- let size;
2339
- try {
2340
- const bounds = this._option.getTextBounds({
2341
- text: text,
2342
- fontFamily: fontFamily,
2343
- fontSize: fontSize,
2344
- fontWeight: fontWeight,
2345
- textAlign: textAlign,
2346
- textBaseline: textBaseline,
2347
- ellipsis: !!ellipsis,
2348
- maxLineWidth: limit || 1 / 0,
2349
- lineHeight: lineHeight
2350
- });
2351
- size = {
2352
- width: bounds.width(),
2353
- height: bounds.height()
2354
- };
2355
- } catch (e) {
2356
- this._notSupportVRender = !0, size = this.measureWithNaiveCanvas(text);
2357
- }
2358
- return size;
2522
+ setColorName(name) {
2523
+ const hex = DEFAULT_COLORS[name.toLowerCase()];
2524
+ return void 0 !== hex ? this.setHex(hex) : console.warn("THREE.Color: Unknown color " + name), this;
2359
2525
  }
2360
- measureWithNaiveCanvas(text) {
2361
- return this._measureReduce(text, this._measureWithNaiveCanvas.bind(this));
2526
+ setScalar(scalar) {
2527
+ return this.color.r = scalar, this.color.g = scalar, this.color.b = scalar, this;
2362
2528
  }
2363
- _measureWithNaiveCanvas(text) {
2364
- var _a;
2365
- if (!this.initContext()) return this._quickMeasureWithoutCanvas(text);
2366
- const metrics = this._context.measureText(text),
2367
- {
2368
- fontSize: fontSize,
2369
- lineHeight: lineHeight
2370
- } = this.textSpec;
2371
- return {
2372
- width: metrics.width,
2373
- height: null !== (_a = lineHeight) && void 0 !== _a ? _a : fontSize
2374
- };
2529
+ setOpacity() {
2530
+ let o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
2531
+ return this.color.opacity = o, this;
2375
2532
  }
2376
- quickMeasure(text) {
2377
- return this._measureReduce(text, this._quickMeasure.bind(this));
2533
+ getLuminance() {
2534
+ return (.2126 * this.color.r + .7152 * this.color.g + .0722 * this.color.b) / 255;
2378
2535
  }
2379
- _quickMeasure(text) {
2380
- const totalSize = {
2381
- width: 0,
2382
- height: 0
2383
- };
2384
- for (let i = 0; i < text.length; i++) {
2385
- const char = text[i];
2386
- let size = this._measureSpecialChar(char);
2387
- isNil$1(size) && TextMeasure.NUMBERS_CHAR_SET.includes(char) && (size = this._measureNumberChar()), isNil$1(size) && ["F", "W"].includes(eastAsianCharacterInfo(char)) && (size = this._measureFullSizeChar()), isNil$1(size) && (size = this._measureLetterChar()), totalSize.width += size.width, totalSize.height = Math.max(totalSize.height, size.height);
2388
- }
2389
- return totalSize;
2536
+ getLuminance2() {
2537
+ return (.2627 * this.color.r + .678 * this.color.g + .0593 * this.color.b) / 255;
2390
2538
  }
2391
- quickMeasureWithoutCanvas(text) {
2392
- return this._measureReduce(text, this._quickMeasureWithoutCanvas.bind(this));
2539
+ getLuminance3() {
2540
+ return (.299 * this.color.r + .587 * this.color.g + .114 * this.color.b) / 255;
2393
2541
  }
2394
- _quickMeasureWithoutCanvas(text) {
2395
- var _a;
2396
- const totalSize = {
2397
- width: 0,
2398
- height: 0
2399
- },
2400
- {
2401
- fontSize: fontSize,
2402
- lineHeight: lineHeight
2403
- } = this.textSpec;
2404
- for (let i = 0; i < text.length; i++) {
2405
- const char = text[i],
2406
- size = ["F", "W"].includes(eastAsianCharacterInfo(char)) ? 1 : .53;
2407
- totalSize.width += size * fontSize;
2408
- }
2409
- return totalSize.height = null !== (_a = lineHeight) && void 0 !== _a ? _a : fontSize, totalSize;
2542
+ clone() {
2543
+ return new Color(this.color.toString());
2410
2544
  }
2411
- _measureReduce(text, processor) {
2412
- var _a;
2413
- const {
2414
- fontSize: fontSize,
2415
- lineHeight: lineHeight
2416
- } = this.textSpec,
2417
- defaultResult = {
2418
- width: 0,
2419
- height: 0
2420
- };
2421
- if (isNil$1(text)) return defaultResult;
2422
- if (isArray$1(text)) {
2423
- const textArr = text.filter(isValid$1).map(s => s.toString());
2424
- return 0 === textArr.length ? defaultResult : 1 === textArr.length ? processor(textArr[0]) : {
2425
- width: textArr.reduce((maxWidth, cur) => Math.max(maxWidth, processor(cur).width), 0),
2426
- height: textArr.length * ((null !== (_a = lineHeight) && void 0 !== _a ? _a : fontSize) + 1) + 1
2427
- };
2428
- }
2429
- return processor(text.toString());
2545
+ copyGammaToLinear(color) {
2546
+ let gammaFactor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
2547
+ return this.color.r = Math.pow(color.color.r, gammaFactor), this.color.g = Math.pow(color.color.g, gammaFactor), this.color.b = Math.pow(color.color.b, gammaFactor), this;
2430
2548
  }
2431
- _measureNumberChar() {
2432
- if (isNil$1(this._numberCharSize)) {
2433
- const numberBounds = this._standardMethod(TextMeasure.NUMBERS_CHAR_SET);
2434
- this._numberCharSize = {
2435
- width: numberBounds.width / TextMeasure.NUMBERS_CHAR_SET.length,
2436
- height: numberBounds.height
2437
- };
2438
- }
2439
- return this._numberCharSize;
2549
+ copyLinearToGamma(color) {
2550
+ let gammaFactor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
2551
+ const safeInverse = gammaFactor > 0 ? 1 / gammaFactor : 1;
2552
+ return this.color.r = Math.pow(color.color.r, safeInverse), this.color.g = Math.pow(color.color.g, safeInverse), this.color.b = Math.pow(color.color.b, safeInverse), this;
2440
2553
  }
2441
- _measureFullSizeChar() {
2442
- return isNil$1(this._fullCharSize) && (this._fullCharSize = this._standardMethod(TextMeasure.FULL_SIZE_CHAR)), this._fullCharSize;
2554
+ convertGammaToLinear(gammaFactor) {
2555
+ return this.copyGammaToLinear(this, gammaFactor), this;
2443
2556
  }
2444
- _measureLetterChar() {
2445
- if (isNil$1(this._letterCharSize)) {
2446
- const alphabetBounds = this._standardMethod(TextMeasure.ALPHABET_CHAR_SET);
2447
- this._letterCharSize = {
2448
- width: alphabetBounds.width / TextMeasure.ALPHABET_CHAR_SET.length,
2449
- height: alphabetBounds.height
2450
- };
2451
- }
2452
- return this._letterCharSize;
2557
+ convertLinearToGamma(gammaFactor) {
2558
+ return this.copyLinearToGamma(this, gammaFactor), this;
2453
2559
  }
2454
- _measureSpecialChar(char) {
2455
- return isValid$1(this._specialCharSizeMap[char]) ? this._specialCharSizeMap[char] : this.specialCharSet.includes(char) ? (this._specialCharSizeMap[char] = this._standardMethod(char), this._specialCharSizeMap[char]) : null;
2560
+ copySRGBToLinear(color) {
2561
+ return this.color.r = SRGBToLinear(color.color.r), this.color.g = SRGBToLinear(color.color.g), this.color.b = SRGBToLinear(color.color.b), this;
2456
2562
  }
2457
- release() {
2458
- isValid$1(this._canvas) && (this._canvas = null), isValid$1(this._context) && (this._contextSaved && (this._context.restore(), this._contextSaved = !1), this._context = null);
2563
+ copyLinearToSRGB(color) {
2564
+ return this.color.r = LinearToSRGB(color.color.r), this.color.g = LinearToSRGB(color.color.g), this.color.b = LinearToSRGB(color.color.b), this;
2565
+ }
2566
+ convertSRGBToLinear() {
2567
+ return this.copySRGBToLinear(this), this;
2568
+ }
2569
+ convertLinearToSRGB() {
2570
+ return this.copyLinearToSRGB(this), this;
2459
2571
  }
2460
2572
  }
2461
- TextMeasure.ALPHABET_CHAR_SET = "abcdefghijklmnopqrstuvwxyz", TextMeasure.NUMBERS_CHAR_SET = "0123456789", TextMeasure.FULL_SIZE_CHAR = "字";
2462
-
2463
- const calculateAnchorOfBounds = (bounds, anchorType) => {
2464
- const {
2465
- x1: x1,
2466
- x2: x2,
2467
- y1: y1,
2468
- y2: y2
2469
- } = bounds,
2470
- rectWidth = Math.abs(x2 - x1),
2471
- rectHeight = Math.abs(y2 - y1);
2472
- let anchorX = (x1 + x2) / 2,
2473
- anchorY = (y1 + y2) / 2,
2474
- sx = 0,
2475
- sy = 0;
2476
- switch (anchorType) {
2477
- case "top":
2478
- case "inside-top":
2479
- sy = -.5;
2480
- break;
2481
- case "bottom":
2482
- case "inside-bottom":
2483
- sy = .5;
2484
- break;
2485
- case "left":
2486
- case "inside-left":
2487
- sx = -.5;
2488
- break;
2489
- case "right":
2490
- case "inside-right":
2491
- sx = .5;
2492
- break;
2493
- case "top-right":
2494
- sx = .5, sy = -.5;
2495
- break;
2496
- case "top-left":
2497
- sx = -.5, sy = -.5;
2498
- break;
2499
- case "bottom-right":
2500
- sx = .5, sy = .5;
2501
- break;
2502
- case "bottom-left":
2503
- sx = -.5, sy = .5;
2573
+ class RGB {
2574
+ constructor(r, g, b, opacity) {
2575
+ this.r = isNaN(+r) ? 255 : Math.max(0, Math.min(255, +r)), this.g = isNaN(+g) ? 255 : Math.max(0, Math.min(255, +g)), this.b = isNaN(+b) ? 255 : Math.max(0, Math.min(255, +b)), isValid$1(opacity) ? this.opacity = isNaN(+opacity) ? 1 : Math.max(0, Math.min(1, +opacity)) : this.opacity = 1;
2504
2576
  }
2505
- return anchorX += sx * rectWidth, anchorY += sy * rectHeight, {
2506
- x: anchorX,
2507
- y: anchorY
2508
- };
2509
- };
2577
+ formatHex() {
2578
+ return `#${hex(this.r) + hex(this.g) + hex(this.b) + (1 === this.opacity ? "" : hex(255 * this.opacity))}`;
2579
+ }
2580
+ formatRgb() {
2581
+ const opacity = this.opacity;
2582
+ return `${1 === opacity ? "rgb(" : "rgba("}${this.r},${this.g},${this.b}${1 === opacity ? ")" : `,${opacity})`}`;
2583
+ }
2584
+ formatHsl() {
2585
+ const opacity = this.opacity,
2586
+ {
2587
+ h: h,
2588
+ s: s,
2589
+ l: l
2590
+ } = rgbToHsl(this.r, this.g, this.b);
2591
+ return `${1 === opacity ? "hsl(" : "hsla("}${h},${s}%,${l}%${1 === opacity ? ")" : `,${opacity})`}`;
2592
+ }
2593
+ toString() {
2594
+ return this.formatHex();
2595
+ }
2596
+ }
2510
2597
 
2511
2598
  const styleStringToObject = function () {
2512
2599
  let styleStr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
@@ -7575,8 +7662,9 @@ class TagPointsUpdate extends ACustomAnimate {
7575
7662
  }), this.clipRange && (out.clipRange = this.clipRange + (1 - this.clipRange) * ratio), this.segmentsCache && this.to.segments) {
7576
7663
  let start = 0;
7577
7664
  out.segments = this.to.segments.map((segment, index) => {
7578
- const points = this.points.slice(start, this.segmentsCache[start]);
7579
- return start += this.segmentsCache[start], Object.assign(Object.assign({}, segment), {
7665
+ const end = start + this.segmentsCache[index],
7666
+ points = this.points.slice(start, end);
7667
+ return start = end, Object.assign(Object.assign({}, segment), {
7580
7668
  points: points
7581
7669
  });
7582
7670
  });
@@ -9099,6 +9187,9 @@ class Graphic extends Node {
9099
9187
  get AABBBounds() {
9100
9188
  return this.tryUpdateAABBBounds("imprecise" === this.attribute.boundsMode);
9101
9189
  }
9190
+ get OBBBounds() {
9191
+ return this.tryUpdateOBBBounds();
9192
+ }
9102
9193
  get globalAABBBounds() {
9103
9194
  return this.tryUpdateGlobalAABBBounds();
9104
9195
  }
@@ -9111,7 +9202,7 @@ class Graphic extends Node {
9111
9202
  constructor() {
9112
9203
  let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
9113
9204
  var _a;
9114
- super(), this._AABBBounds = new AABBBounds(), this._updateTag = UpdateTag.INIT, this.attribute = params, this.valid = this.isValid(), params.background ? this.loadImage(null !== (_a = params.background.background) && void 0 !== _a ? _a : params.background, !0) : params.shadowGraphic && this.setShadowGraphic(params.shadowGraphic);
9205
+ super(), this._AABBBounds = new AABBBounds(), this._updateTag = UpdateTag.INIT, this.attribute = params, this.valid = this.isValid(), this.updateAABBBoundsStamp = 0, params.background ? this.loadImage(null !== (_a = params.background.background) && void 0 !== _a ? _a : params.background, !0) : params.shadowGraphic && this.setShadowGraphic(params.shadowGraphic);
9115
9206
  }
9116
9207
  setMode(mode) {
9117
9208
  "3d" === mode ? this.set3dMode() : this.set2dMode();
@@ -9145,13 +9236,22 @@ class Graphic extends Node {
9145
9236
  const bounds = this.doUpdateAABBBounds(full);
9146
9237
  return application.graphicService.afterUpdateAABBBounds(this, this.stage, this._AABBBounds, this, !0), bounds;
9147
9238
  }
9239
+ tryUpdateOBBBounds() {
9240
+ if (this._OBBBounds || (this._OBBBounds = new OBBBounds()), this.tryUpdateAABBBounds(), this.updateOBBBoundsStamp === this.updateAABBBoundsStamp) return this._OBBBounds;
9241
+ if (this.updateOBBBoundsStamp = this.updateAABBBoundsStamp, !this.valid) return this._OBBBounds.clear(), this._OBBBounds;
9242
+ return this.doUpdateOBBBounds();
9243
+ }
9148
9244
  combindShadowAABBBounds(bounds) {
9149
9245
  if (this.shadowRoot) {
9150
9246
  const b = this.shadowRoot.AABBBounds.clone();
9151
9247
  bounds.union(b);
9152
9248
  }
9153
9249
  }
9250
+ doUpdateOBBBounds() {
9251
+ return this._OBBBounds;
9252
+ }
9154
9253
  doUpdateAABBBounds(full) {
9254
+ this.updateAABBBoundsStamp++;
9155
9255
  const graphicTheme = this.getGraphicTheme();
9156
9256
  this._AABBBounds.clear();
9157
9257
  const attribute = this.attribute,
@@ -10191,6 +10291,7 @@ class Group extends Graphic {
10191
10291
  }), application.graphicService.updateTempAABBBounds(aabbBounds), application.graphicService.transformAABBBounds(attribute, aabbBounds, groupTheme, !1, this), originalAABBBounds.copy(aabbBounds), originalAABBBounds;
10192
10292
  }
10193
10293
  doUpdateAABBBounds() {
10294
+ this.updateAABBBoundsStamp++;
10194
10295
  const bounds = super.doUpdateAABBBounds();
10195
10296
  return this.parent && this.parent.addChildUpdateBoundTag(), this._emitCustomEvent("AAABBBoundsChange"), bounds;
10196
10297
  }
@@ -14084,7 +14185,10 @@ class InteractiveDrawItemInterceptorContribution {
14084
14185
  }
14085
14186
  beforeDrawInteractive(graphic, renderService, drawContext, drawContribution, params) {
14086
14187
  const baseGraphic = graphic.baseGraphic;
14087
- if (!baseGraphic.stage) {
14188
+ let intree = !!baseGraphic.stage,
14189
+ _g = baseGraphic.parent;
14190
+ for (; intree && _g && _g.stage !== _g;) intree = !!_g.stage, _g = _g.parent;
14191
+ if (!intree) {
14088
14192
  const interactiveLayer = drawContext.stage.getLayer("_builtin_interactive");
14089
14193
  if (interactiveLayer) {
14090
14194
  this.getShadowRoot(interactiveLayer).removeChild(graphic);
@@ -14436,6 +14540,35 @@ class Text extends Graphic {
14436
14540
  getGraphicTheme() {
14437
14541
  return getTheme(this).text;
14438
14542
  }
14543
+ doUpdateOBBBounds() {
14544
+ const graphicTheme = this.getGraphicTheme();
14545
+ this._OBBBounds.clear();
14546
+ const attribute = this.attribute,
14547
+ {
14548
+ angle = graphicTheme.angle
14549
+ } = attribute;
14550
+ if (!angle) {
14551
+ const b = this.AABBBounds;
14552
+ return this._OBBBounds.setValue(b.x1, b.y1, b.x2, b.y2), this._OBBBounds;
14553
+ }
14554
+ this.obbText || (this.obbText = new Text({})), this.obbText.setAttributes(Object.assign(Object.assign({}, attribute), {
14555
+ angle: 0
14556
+ }));
14557
+ const bounds1 = this.obbText.AABBBounds,
14558
+ {
14559
+ x: x,
14560
+ y: y
14561
+ } = attribute,
14562
+ boundsCenter = {
14563
+ x: (bounds1.x1 + bounds1.x2) / 2,
14564
+ y: (bounds1.y1 + bounds1.y2) / 2
14565
+ },
14566
+ center = rotatePoint(boundsCenter, angle, {
14567
+ x: x,
14568
+ y: y
14569
+ });
14570
+ return this._OBBBounds.copy(bounds1), this._OBBBounds.translate(center.x - boundsCenter.x, center.y - boundsCenter.y), this._OBBBounds.angle = angle, this._OBBBounds;
14571
+ }
14439
14572
  updateAABBBounds(attribute, textTheme, aabbBounds) {
14440
14573
  const {
14441
14574
  text = textTheme.text
@@ -15884,7 +16017,7 @@ class Glyph extends Graphic {
15884
16017
  }), aabbBounds;
15885
16018
  }
15886
16019
  doUpdateAABBBounds() {
15887
- this._AABBBounds.clear();
16020
+ this.updateAABBBoundsStamp++, this._AABBBounds.clear();
15888
16021
  const bounds = this.updateAABBBounds(this.attribute, this.getGraphicTheme(), this._AABBBounds);
15889
16022
  return this.clearUpdateBoundTag(), bounds;
15890
16023
  }
@@ -17047,13 +17180,14 @@ class Arc extends Graphic {
17047
17180
  return super.needUpdateTag(key, ARC_UPDATE_TAG_KEY);
17048
17181
  }
17049
17182
  toCustomPath() {
17183
+ var _a, _b, _c, _d;
17050
17184
  const attribute = this.attribute,
17051
17185
  {
17052
17186
  startAngle: startAngle,
17053
17187
  endAngle: endAngle
17054
17188
  } = this.getParsedAngle();
17055
- let innerRadius = attribute.innerRadius - (attribute.innerPadding || 0),
17056
- outerRadius = attribute.outerRadius - (attribute.outerPadding || 0);
17189
+ let innerRadius = (null !== (_a = attribute.innerRadius) && void 0 !== _a ? _a : 0) - (null !== (_b = attribute.innerPadding) && void 0 !== _b ? _b : 0),
17190
+ outerRadius = (null !== (_c = attribute.outerRadius) && void 0 !== _c ? _c : 0) - (null !== (_d = attribute.outerPadding) && void 0 !== _d ? _d : 0);
17057
17191
  const deltaAngle = abs(endAngle - startAngle),
17058
17192
  clockwise = endAngle > startAngle;
17059
17193
  if (outerRadius < innerRadius) {
@@ -28329,7 +28463,7 @@ const registerWrapText = _registerWrapText;
28329
28463
 
28330
28464
  const roughModule = _roughModule;
28331
28465
 
28332
- const version = "0.20.6-beta.0";
28466
+ const version = "0.20.6";
28333
28467
  preLoadAllModule();
28334
28468
  if (isBrowserEnv()) {
28335
28469
  loadBrowserEnv(container);