@visactor/vrender 0.20.6-alpha.0 → 0.20.6-alpha.1

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
@@ -1384,145 +1384,6 @@
1384
1384
  }
1385
1385
  }
1386
1386
 
1387
- function transformBoundsWithMatrix(out, bounds, matrix) {
1388
- const {
1389
- x1: x1,
1390
- y1: y1,
1391
- x2: x2,
1392
- y2: y2
1393
- } = bounds;
1394
- 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);
1395
- }
1396
- class Bounds {
1397
- constructor(bounds) {
1398
- bounds ? this.setValue(bounds.x1, bounds.y1, bounds.x2, bounds.y2) : this.clear();
1399
- }
1400
- clone() {
1401
- return new Bounds(this);
1402
- }
1403
- clear() {
1404
- return this.x1 = +Number.MAX_VALUE, this.y1 = +Number.MAX_VALUE, this.x2 = -Number.MAX_VALUE, this.y2 = -Number.MAX_VALUE, this;
1405
- }
1406
- empty() {
1407
- return this.x1 === +Number.MAX_VALUE && this.y1 === +Number.MAX_VALUE && this.x2 === -Number.MAX_VALUE && this.y2 === -Number.MAX_VALUE;
1408
- }
1409
- equals(b) {
1410
- return this.x1 === b.x1 && this.y1 === b.y1 && this.x2 === b.x2 && this.y2 === b.y2;
1411
- }
1412
- setValue() {
1413
- let x1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1414
- let y1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1415
- let x2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1416
- let y2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1417
- return this.x1 = x1, this.y1 = y1, this.x2 = x2, this.y2 = y2, this;
1418
- }
1419
- set() {
1420
- let x1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1421
- let y1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1422
- let x2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1423
- let y2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1424
- 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;
1425
- }
1426
- add() {
1427
- let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1428
- let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1429
- 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;
1430
- }
1431
- expand() {
1432
- let d = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1433
- 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;
1434
- }
1435
- round() {
1436
- 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;
1437
- }
1438
- translate() {
1439
- let dx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1440
- let dy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1441
- return this.x1 += dx, this.x2 += dx, this.y1 += dy, this.y2 += dy, this;
1442
- }
1443
- rotate() {
1444
- let angle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1445
- let x = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1446
- let y = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1447
- const p = this.rotatedPoints(angle, x, y);
1448
- return this.clear().add(p[0], p[1]).add(p[2], p[3]).add(p[4], p[5]).add(p[6], p[7]);
1449
- }
1450
- scale() {
1451
- let sx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1452
- let sy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1453
- let x = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1454
- let y = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1455
- const p = this.scalePoints(sx, sy, x, y);
1456
- return this.clear().add(p[0], p[1]).add(p[2], p[3]);
1457
- }
1458
- union(b) {
1459
- 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;
1460
- }
1461
- intersect(b) {
1462
- 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;
1463
- }
1464
- encloses(b) {
1465
- return b && this.x1 <= b.x1 && this.x2 >= b.x2 && this.y1 <= b.y1 && this.y2 >= b.y2;
1466
- }
1467
- alignsWith(b) {
1468
- return b && (this.x1 === b.x1 || this.x2 === b.x2 || this.y1 === b.y1 || this.y2 === b.y2);
1469
- }
1470
- intersects(b) {
1471
- return b && !(this.x2 < b.x1 || this.x1 > b.x2 || this.y2 < b.y1 || this.y1 > b.y2);
1472
- }
1473
- contains() {
1474
- let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1475
- let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1476
- return !(x < this.x1 || x > this.x2 || y < this.y1 || y > this.y2);
1477
- }
1478
- containsPoint(p) {
1479
- return !(p.x < this.x1 || p.x > this.x2 || p.y < this.y1 || p.y > this.y2);
1480
- }
1481
- width() {
1482
- return this.empty() ? 0 : this.x2 - this.x1;
1483
- }
1484
- height() {
1485
- return this.empty() ? 0 : this.y2 - this.y1;
1486
- }
1487
- scaleX() {
1488
- let s = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1489
- return this.x1 *= s, this.x2 *= s, this;
1490
- }
1491
- scaleY() {
1492
- let s = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1493
- return this.y1 *= s, this.y2 *= s, this;
1494
- }
1495
- transformWithMatrix(matrix) {
1496
- return transformBoundsWithMatrix(this, this, matrix), this;
1497
- }
1498
- copy(b) {
1499
- return this.x1 = b.x1, this.y1 = b.y1, this.x2 = b.x2, this.y2 = b.y2, this;
1500
- }
1501
- rotatedPoints(angle, x, y) {
1502
- const {
1503
- x1: x1,
1504
- y1: y1,
1505
- x2: x2,
1506
- y2: y2
1507
- } = this,
1508
- cos = Math.cos(angle),
1509
- sin = Math.sin(angle),
1510
- cx = x - x * cos + y * sin,
1511
- cy = y - x * sin - y * cos;
1512
- 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];
1513
- }
1514
- scalePoints(sx, sy, x, y) {
1515
- const {
1516
- x1: x1,
1517
- y1: y1,
1518
- x2: x2,
1519
- y2: y2
1520
- } = this;
1521
- return [sx * x1 + (1 - sx) * x, sy * y1 + (1 - sy) * y, sx * x2 + (1 - sx) * x, sy * y2 + (1 - sy) * y];
1522
- }
1523
- }
1524
- class AABBBounds extends Bounds {}
1525
-
1526
1387
  function degreeToRadian(degree) {
1527
1388
  return degree * (Math.PI / 180);
1528
1389
  }
@@ -1539,41 +1400,637 @@
1539
1400
  return Math.atan2(point.y - center.y, point.x - center.x);
1540
1401
  }
1541
1402
 
1542
- class Matrix {
1543
- constructor() {
1544
- let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
1545
- let b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1546
- let c = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1547
- let d = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
1548
- let e = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
1549
- let f = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
1550
- this.a = a, this.b = b, this.c = c, this.d = d, this.e = e, this.f = f;
1551
- }
1552
- equalToMatrix(m2) {
1553
- 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);
1554
- }
1555
- equalTo(a, b, c, d, e, f) {
1556
- return !(this.e !== e || this.f !== f || this.a !== a || this.d !== d || this.b !== b || this.c !== c);
1557
- }
1558
- setValue(a, b, c, d, e, f) {
1559
- return this.a = a, this.b = b, this.c = c, this.d = d, this.e = e, this.f = f, this;
1560
- }
1561
- reset() {
1562
- return this.a = 1, this.b = 0, this.c = 0, this.d = 1, this.e = 0, this.f = 0, this;
1563
- }
1564
- getInverse() {
1565
- const a = this.a,
1566
- b = this.b,
1567
- c = this.c,
1568
- d = this.d,
1569
- e = this.e,
1570
- f = this.f,
1571
- m = new Matrix(),
1572
- dt = a * d - b * c;
1573
- 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;
1403
+ function sub(out, v1, v2) {
1404
+ out[0] = v1[0] - v2[0], out[1] = v1[1] - v2[1];
1405
+ }
1406
+ function isIntersect(left1, right1, left2, right2) {
1407
+ let min1 = left1[0],
1408
+ max1 = right1[0],
1409
+ min2 = left2[0],
1410
+ max2 = right2[0];
1411
+ 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));
1412
+ }
1413
+ function getIntersectPoint(left1, right1, left2, right2) {
1414
+ if (!isIntersect(left1, right1, left2, right2)) return !1;
1415
+ const dir1 = [0, 0],
1416
+ dir2 = [0, 0],
1417
+ tempVec = [0, 0];
1418
+ if (sub(dir1, right1, left1), sub(dir2, right2, left2), fuzzyEqualVec(dir1, dir2)) return !0;
1419
+ sub(tempVec, left2, left1);
1420
+ const t = crossProduct$1(tempVec, dir2) / crossProduct$1(dir1, dir2);
1421
+ return t >= 0 && t <= 1 && [left1[0] + dir1[0] * t, left1[1] + dir1[1] * t];
1422
+ }
1423
+ function getRectIntersect(bbox1, bbox2, format) {
1424
+ if (null === bbox1) return bbox2;
1425
+ if (null === bbox2) return bbox1;
1426
+ const {
1427
+ x11: x11,
1428
+ x12: x12,
1429
+ y11: y11,
1430
+ y12: y12,
1431
+ x21: x21,
1432
+ x22: x22,
1433
+ y21: y21,
1434
+ y22: y22
1435
+ } = formatTwoBBox(bbox1, bbox2, format);
1436
+ return x11 >= x22 || x12 <= x21 || y11 >= y22 || y12 <= y21 ? {
1437
+ x1: 0,
1438
+ y1: 0,
1439
+ x2: 0,
1440
+ y2: 0
1441
+ } : {
1442
+ x1: Math.max(x11, x21),
1443
+ y1: Math.max(y11, y21),
1444
+ x2: Math.min(x12, x22),
1445
+ y2: Math.min(y12, y22)
1446
+ };
1447
+ }
1448
+ var InnerBBox;
1449
+ !function (InnerBBox) {
1450
+ InnerBBox[InnerBBox.NONE = 0] = "NONE", InnerBBox[InnerBBox.BBOX1 = 1] = "BBOX1", InnerBBox[InnerBBox.BBOX2 = 2] = "BBOX2";
1451
+ }(InnerBBox || (InnerBBox = {}));
1452
+ const formatTwoBBox = (bbox1, bbox2, format) => {
1453
+ let x11 = bbox1.x1,
1454
+ x12 = bbox1.x2,
1455
+ y11 = bbox1.y1,
1456
+ y12 = bbox1.y2,
1457
+ x21 = bbox2.x1,
1458
+ x22 = bbox2.x2,
1459
+ y21 = bbox2.y1,
1460
+ y22 = bbox2.y2;
1461
+ 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])), {
1462
+ x11: x11,
1463
+ x12: x12,
1464
+ y11: y11,
1465
+ y12: y12,
1466
+ x21: x21,
1467
+ x22: x22,
1468
+ y21: y21,
1469
+ y22: y22
1470
+ };
1471
+ };
1472
+ function isRectIntersect(bbox1, bbox2, format) {
1473
+ if (bbox1 && bbox2) {
1474
+ if (!format) return !(bbox1.x1 > bbox2.x2 || bbox1.x2 < bbox2.x1 || bbox1.y1 > bbox2.y2 || bbox1.y2 < bbox2.y1);
1475
+ const {
1476
+ x11: x11,
1477
+ x12: x12,
1478
+ y11: y11,
1479
+ y12: y12,
1480
+ x21: x21,
1481
+ x22: x22,
1482
+ y21: y21,
1483
+ y22: y22
1484
+ } = formatTwoBBox(bbox1, bbox2, !0);
1485
+ return !(x11 > x22 || x12 < x21 || y11 > y22 || y12 < y21);
1574
1486
  }
1575
- rotate(rad) {
1576
- const c = Math.cos(rad),
1487
+ return !0;
1488
+ }
1489
+ function getProjectionRadius(checkAxis, axis) {
1490
+ return Math.abs(axis[0] * checkAxis[0] + axis[1] * checkAxis[1]);
1491
+ }
1492
+ function rotatePoint(_ref, rad) {
1493
+ let {
1494
+ x: x,
1495
+ y: y
1496
+ } = _ref;
1497
+ let origin = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
1498
+ x: 0,
1499
+ y: 0
1500
+ };
1501
+ return {
1502
+ x: (x - origin.x) * Math.cos(rad) - (y - origin.y) * Math.sin(rad) + origin.x,
1503
+ y: (x - origin.x) * Math.sin(rad) + (y - origin.y) * Math.cos(rad) + origin.y
1504
+ };
1505
+ }
1506
+ function getCenterPoint(box) {
1507
+ return {
1508
+ x: (box.x1 + box.x2) / 2,
1509
+ y: (box.y1 + box.y2) / 2
1510
+ };
1511
+ }
1512
+ function toRect(box, isDeg) {
1513
+ const deg = isDeg ? degreeToRadian(box.angle) : box.angle,
1514
+ cp = getCenterPoint(box);
1515
+ return [rotatePoint({
1516
+ x: box.x1,
1517
+ y: box.y1
1518
+ }, deg, cp), rotatePoint({
1519
+ x: box.x2,
1520
+ y: box.y1
1521
+ }, deg, cp), rotatePoint({
1522
+ x: box.x2,
1523
+ y: box.y2
1524
+ }, deg, cp), rotatePoint({
1525
+ x: box.x1,
1526
+ y: box.y2
1527
+ }, deg, cp)];
1528
+ }
1529
+ function isRotateAABBIntersect(box1, box2) {
1530
+ let isDeg = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !1;
1531
+ let ctx = arguments.length > 3 ? arguments[3] : undefined;
1532
+ const rect1 = toRect(box1, isDeg),
1533
+ rect2 = toRect(box2, isDeg),
1534
+ vector = (start, end) => [end.x - start.x, end.y - start.y];
1535
+ ctx && (ctx.save(), ctx.fillStyle = "red", ctx.globalAlpha = .6, rect1.forEach((item, index) => {
1536
+ 0 === index ? ctx.moveTo(item.x, item.y) : ctx.lineTo(item.x, item.y);
1537
+ }), ctx.fill(), ctx.restore(), ctx.save(), ctx.fillStyle = "green", ctx.globalAlpha = .6, rect2.forEach((item, index) => {
1538
+ 0 === index ? ctx.moveTo(item.x, item.y) : ctx.lineTo(item.x, item.y);
1539
+ }), ctx.fill(), ctx.restore());
1540
+ const p1 = getCenterPoint(box1),
1541
+ p2 = getCenterPoint(box2);
1542
+ ctx && ctx.fillRect(p1.x, p1.y, 2, 2), ctx && ctx.fillRect(p2.x, p2.y, 2, 2);
1543
+ const vp1p2 = vector(p1, p2),
1544
+ AB = vector(rect1[0], rect1[1]),
1545
+ BC = vector(rect1[1], rect1[2]),
1546
+ A1B1 = vector(rect2[0], rect2[1]),
1547
+ B1C1 = vector(rect2[1], rect2[2]),
1548
+ deg11 = isDeg ? degreeToRadian(box1.angle) : box1.angle;
1549
+ let deg12 = isDeg ? degreeToRadian(90 - box1.angle) : box1.angle + halfPi$1;
1550
+ const deg21 = isDeg ? degreeToRadian(box2.angle) : box2.angle;
1551
+ let deg22 = isDeg ? degreeToRadian(90 - box2.angle) : box2.angle + halfPi$1;
1552
+ deg12 > pi2 && (deg12 -= pi2), deg22 > pi2 && (deg22 -= pi2);
1553
+ const isCover = (checkAxisRadius, deg, targetAxis1, targetAxis2) => {
1554
+ const checkAxis = [Math.cos(deg), Math.sin(deg)];
1555
+ return checkAxisRadius + (getProjectionRadius(checkAxis, targetAxis1) + getProjectionRadius(checkAxis, targetAxis2)) / 2 > getProjectionRadius(checkAxis, vp1p2);
1556
+ };
1557
+ 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);
1558
+ }
1559
+
1560
+ function isPointInLine(x0, y0, x1, y1, x, y) {
1561
+ if (y > y0 && y > y1 || y < y0 && y < y1) return 0;
1562
+ if (y1 === y0) return 0;
1563
+ const t = (y - y0) / (y1 - y0);
1564
+ let dir = y1 < y0 ? 1 : -1;
1565
+ 1 !== t && 0 !== t || (dir = y1 < y0 ? .5 : -.5);
1566
+ const x_ = t * (x1 - x0) + x0;
1567
+ return x_ === x ? 1 / 0 : x_ > x ? dir : 0;
1568
+ }
1569
+
1570
+ const eastAsianCharacterInfo = character => {
1571
+ let x = character.charCodeAt(0),
1572
+ y = 2 === character.length ? character.charCodeAt(1) : 0,
1573
+ codePoint = x;
1574
+ 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";
1575
+ };
1576
+
1577
+ function getContextFont(text) {
1578
+ let defaultAttr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1579
+ let fontSizeScale = arguments.length > 2 ? arguments[2] : undefined;
1580
+ fontSizeScale || (fontSizeScale = 1);
1581
+ const {
1582
+ fontStyle = defaultAttr.fontStyle,
1583
+ fontVariant = defaultAttr.fontVariant,
1584
+ fontWeight = defaultAttr.fontWeight,
1585
+ fontSize = defaultAttr.fontSize,
1586
+ fontFamily = defaultAttr.fontFamily
1587
+ } = text;
1588
+ return (fontStyle ? fontStyle + " " : "") + (fontVariant ? fontVariant + " " : "") + (fontWeight ? fontWeight + " " : "") + fontSize * fontSizeScale + "px " + (fontFamily || "sans-serif");
1589
+ }
1590
+
1591
+ class TextMeasure {
1592
+ constructor(option, textSpec) {
1593
+ 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);
1594
+ }
1595
+ initContext() {
1596
+ if (this._notSupportCanvas) return !1;
1597
+ 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)) {
1598
+ const context = this._canvas.getContext("2d");
1599
+ isValid$1(context) && (context.save(), context.font = getContextFont(this.textSpec), this._contextSaved = !0, this._context = context);
1600
+ }
1601
+ return !isNil$1(this._context) || (this._notSupportCanvas = !0, !1);
1602
+ }
1603
+ _initSpec() {
1604
+ var _a, _b, _c;
1605
+ const {
1606
+ defaultFontParams = {}
1607
+ } = this._option,
1608
+ {
1609
+ fontStyle = defaultFontParams.fontStyle,
1610
+ fontVariant = defaultFontParams.fontVariant,
1611
+ fontWeight = null !== (_a = defaultFontParams.fontWeight) && void 0 !== _a ? _a : "normal",
1612
+ fontSize = null !== (_b = defaultFontParams.fontSize) && void 0 !== _b ? _b : 12,
1613
+ fontFamily = null !== (_c = defaultFontParams.fontFamily) && void 0 !== _c ? _c : "sans-serif",
1614
+ align: align,
1615
+ textAlign = null != align ? align : "center",
1616
+ baseline: baseline,
1617
+ textBaseline = null != baseline ? baseline : "middle",
1618
+ ellipsis: ellipsis,
1619
+ limit: limit
1620
+ } = this._userSpec;
1621
+ let {
1622
+ lineHeight = fontSize
1623
+ } = this._userSpec;
1624
+ if (isString$1(lineHeight) && "%" === lineHeight[lineHeight.length - 1]) {
1625
+ const scale = Number.parseFloat(lineHeight.substring(0, lineHeight.length - 1)) / 100;
1626
+ lineHeight = fontSize * scale;
1627
+ }
1628
+ return {
1629
+ fontStyle: fontStyle,
1630
+ fontVariant: fontVariant,
1631
+ fontFamily: fontFamily,
1632
+ fontSize: fontSize,
1633
+ fontWeight: fontWeight,
1634
+ textAlign: textAlign,
1635
+ textBaseline: textBaseline,
1636
+ ellipsis: ellipsis,
1637
+ limit: limit,
1638
+ lineHeight: lineHeight
1639
+ };
1640
+ }
1641
+ measure(text, method) {
1642
+ switch (method) {
1643
+ case "vrender":
1644
+ case "canopus":
1645
+ return this.fullMeasure(text);
1646
+ case "canvas":
1647
+ return this.measureWithNaiveCanvas(text);
1648
+ case "simple":
1649
+ return this.quickMeasureWithoutCanvas(text);
1650
+ default:
1651
+ return this.quickMeasure(text);
1652
+ }
1653
+ }
1654
+ fullMeasure(text) {
1655
+ if (isNil$1(text)) return {
1656
+ width: 0,
1657
+ height: 0
1658
+ };
1659
+ if (isNil$1(this._option.getTextBounds) || !this._notSupportVRender) return this.measureWithNaiveCanvas(text);
1660
+ const {
1661
+ fontFamily: fontFamily,
1662
+ fontSize: fontSize,
1663
+ fontWeight: fontWeight,
1664
+ textAlign: textAlign,
1665
+ textBaseline: textBaseline,
1666
+ ellipsis: ellipsis,
1667
+ limit: limit,
1668
+ lineHeight: lineHeight
1669
+ } = this.textSpec;
1670
+ let size;
1671
+ try {
1672
+ const bounds = this._option.getTextBounds({
1673
+ text: text,
1674
+ fontFamily: fontFamily,
1675
+ fontSize: fontSize,
1676
+ fontWeight: fontWeight,
1677
+ textAlign: textAlign,
1678
+ textBaseline: textBaseline,
1679
+ ellipsis: !!ellipsis,
1680
+ maxLineWidth: limit || 1 / 0,
1681
+ lineHeight: lineHeight
1682
+ });
1683
+ size = {
1684
+ width: bounds.width(),
1685
+ height: bounds.height()
1686
+ };
1687
+ } catch (e) {
1688
+ this._notSupportVRender = !0, size = this.measureWithNaiveCanvas(text);
1689
+ }
1690
+ return size;
1691
+ }
1692
+ measureWithNaiveCanvas(text) {
1693
+ return this._measureReduce(text, this._measureWithNaiveCanvas.bind(this));
1694
+ }
1695
+ _measureWithNaiveCanvas(text) {
1696
+ var _a;
1697
+ if (!this.initContext()) return this._quickMeasureWithoutCanvas(text);
1698
+ const metrics = this._context.measureText(text),
1699
+ {
1700
+ fontSize: fontSize,
1701
+ lineHeight: lineHeight
1702
+ } = this.textSpec;
1703
+ return {
1704
+ width: metrics.width,
1705
+ height: null !== (_a = lineHeight) && void 0 !== _a ? _a : fontSize
1706
+ };
1707
+ }
1708
+ quickMeasure(text) {
1709
+ return this._measureReduce(text, this._quickMeasure.bind(this));
1710
+ }
1711
+ _quickMeasure(text) {
1712
+ const totalSize = {
1713
+ width: 0,
1714
+ height: 0
1715
+ };
1716
+ for (let i = 0; i < text.length; i++) {
1717
+ const char = text[i];
1718
+ let size = this._measureSpecialChar(char);
1719
+ 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);
1720
+ }
1721
+ return totalSize;
1722
+ }
1723
+ quickMeasureWithoutCanvas(text) {
1724
+ return this._measureReduce(text, this._quickMeasureWithoutCanvas.bind(this));
1725
+ }
1726
+ _quickMeasureWithoutCanvas(text) {
1727
+ var _a;
1728
+ const totalSize = {
1729
+ width: 0,
1730
+ height: 0
1731
+ },
1732
+ {
1733
+ fontSize: fontSize,
1734
+ lineHeight: lineHeight
1735
+ } = this.textSpec;
1736
+ for (let i = 0; i < text.length; i++) {
1737
+ const char = text[i],
1738
+ size = ["F", "W"].includes(eastAsianCharacterInfo(char)) ? 1 : .53;
1739
+ totalSize.width += size * fontSize;
1740
+ }
1741
+ return totalSize.height = null !== (_a = lineHeight) && void 0 !== _a ? _a : fontSize, totalSize;
1742
+ }
1743
+ _measureReduce(text, processor) {
1744
+ var _a;
1745
+ const {
1746
+ fontSize: fontSize,
1747
+ lineHeight: lineHeight
1748
+ } = this.textSpec,
1749
+ defaultResult = {
1750
+ width: 0,
1751
+ height: 0
1752
+ };
1753
+ if (isNil$1(text)) return defaultResult;
1754
+ if (isArray$1(text)) {
1755
+ const textArr = text.filter(isValid$1).map(s => s.toString());
1756
+ return 0 === textArr.length ? defaultResult : 1 === textArr.length ? processor(textArr[0]) : {
1757
+ width: textArr.reduce((maxWidth, cur) => Math.max(maxWidth, processor(cur).width), 0),
1758
+ height: textArr.length * ((null !== (_a = lineHeight) && void 0 !== _a ? _a : fontSize) + 1) + 1
1759
+ };
1760
+ }
1761
+ return processor(text.toString());
1762
+ }
1763
+ _measureNumberChar() {
1764
+ if (isNil$1(this._numberCharSize)) {
1765
+ const numberBounds = this._standardMethod(TextMeasure.NUMBERS_CHAR_SET);
1766
+ this._numberCharSize = {
1767
+ width: numberBounds.width / TextMeasure.NUMBERS_CHAR_SET.length,
1768
+ height: numberBounds.height
1769
+ };
1770
+ }
1771
+ return this._numberCharSize;
1772
+ }
1773
+ _measureFullSizeChar() {
1774
+ return isNil$1(this._fullCharSize) && (this._fullCharSize = this._standardMethod(TextMeasure.FULL_SIZE_CHAR)), this._fullCharSize;
1775
+ }
1776
+ _measureLetterChar() {
1777
+ if (isNil$1(this._letterCharSize)) {
1778
+ const alphabetBounds = this._standardMethod(TextMeasure.ALPHABET_CHAR_SET);
1779
+ this._letterCharSize = {
1780
+ width: alphabetBounds.width / TextMeasure.ALPHABET_CHAR_SET.length,
1781
+ height: alphabetBounds.height
1782
+ };
1783
+ }
1784
+ return this._letterCharSize;
1785
+ }
1786
+ _measureSpecialChar(char) {
1787
+ return isValid$1(this._specialCharSizeMap[char]) ? this._specialCharSizeMap[char] : this.specialCharSet.includes(char) ? (this._specialCharSizeMap[char] = this._standardMethod(char), this._specialCharSizeMap[char]) : null;
1788
+ }
1789
+ release() {
1790
+ isValid$1(this._canvas) && (this._canvas = null), isValid$1(this._context) && (this._contextSaved && (this._context.restore(), this._contextSaved = !1), this._context = null);
1791
+ }
1792
+ }
1793
+ TextMeasure.ALPHABET_CHAR_SET = "abcdefghijklmnopqrstuvwxyz", TextMeasure.NUMBERS_CHAR_SET = "0123456789", TextMeasure.FULL_SIZE_CHAR = "字";
1794
+
1795
+ const calculateAnchorOfBounds = (bounds, anchorType) => {
1796
+ const {
1797
+ x1: x1,
1798
+ x2: x2,
1799
+ y1: y1,
1800
+ y2: y2
1801
+ } = bounds,
1802
+ rectWidth = Math.abs(x2 - x1),
1803
+ rectHeight = Math.abs(y2 - y1);
1804
+ let anchorX = (x1 + x2) / 2,
1805
+ anchorY = (y1 + y2) / 2,
1806
+ sx = 0,
1807
+ sy = 0;
1808
+ switch (anchorType) {
1809
+ case "top":
1810
+ case "inside-top":
1811
+ sy = -.5;
1812
+ break;
1813
+ case "bottom":
1814
+ case "inside-bottom":
1815
+ sy = .5;
1816
+ break;
1817
+ case "left":
1818
+ case "inside-left":
1819
+ sx = -.5;
1820
+ break;
1821
+ case "right":
1822
+ case "inside-right":
1823
+ sx = .5;
1824
+ break;
1825
+ case "top-right":
1826
+ sx = .5, sy = -.5;
1827
+ break;
1828
+ case "top-left":
1829
+ sx = -.5, sy = -.5;
1830
+ break;
1831
+ case "bottom-right":
1832
+ sx = .5, sy = .5;
1833
+ break;
1834
+ case "bottom-left":
1835
+ sx = -.5, sy = .5;
1836
+ }
1837
+ return anchorX += sx * rectWidth, anchorY += sy * rectHeight, {
1838
+ x: anchorX,
1839
+ y: anchorY
1840
+ };
1841
+ };
1842
+
1843
+ function transformBoundsWithMatrix(out, bounds, matrix) {
1844
+ const {
1845
+ x1: x1,
1846
+ y1: y1,
1847
+ x2: x2,
1848
+ y2: y2
1849
+ } = bounds;
1850
+ 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);
1851
+ }
1852
+ class Bounds {
1853
+ constructor(bounds) {
1854
+ bounds ? this.setValue(bounds.x1, bounds.y1, bounds.x2, bounds.y2) : this.clear();
1855
+ }
1856
+ clone() {
1857
+ return new Bounds(this);
1858
+ }
1859
+ clear() {
1860
+ return this.x1 = +Number.MAX_VALUE, this.y1 = +Number.MAX_VALUE, this.x2 = -Number.MAX_VALUE, this.y2 = -Number.MAX_VALUE, this;
1861
+ }
1862
+ empty() {
1863
+ return this.x1 === +Number.MAX_VALUE && this.y1 === +Number.MAX_VALUE && this.x2 === -Number.MAX_VALUE && this.y2 === -Number.MAX_VALUE;
1864
+ }
1865
+ equals(b) {
1866
+ return this.x1 === b.x1 && this.y1 === b.y1 && this.x2 === b.x2 && this.y2 === b.y2;
1867
+ }
1868
+ setValue() {
1869
+ let x1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1870
+ let y1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1871
+ let x2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1872
+ let y2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1873
+ return this.x1 = x1, this.y1 = y1, this.x2 = x2, this.y2 = y2, this;
1874
+ }
1875
+ set() {
1876
+ let x1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1877
+ let y1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1878
+ let x2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1879
+ let y2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1880
+ 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;
1881
+ }
1882
+ add() {
1883
+ let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1884
+ let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1885
+ 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;
1886
+ }
1887
+ expand() {
1888
+ let d = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1889
+ 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;
1890
+ }
1891
+ round() {
1892
+ 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;
1893
+ }
1894
+ translate() {
1895
+ let dx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1896
+ let dy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1897
+ return this.x1 += dx, this.x2 += dx, this.y1 += dy, this.y2 += dy, this;
1898
+ }
1899
+ rotate() {
1900
+ let angle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1901
+ let x = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1902
+ let y = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1903
+ const p = this.rotatedPoints(angle, x, y);
1904
+ return this.clear().add(p[0], p[1]).add(p[2], p[3]).add(p[4], p[5]).add(p[6], p[7]);
1905
+ }
1906
+ scale() {
1907
+ let sx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1908
+ let sy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1909
+ let x = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1910
+ let y = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1911
+ const p = this.scalePoints(sx, sy, x, y);
1912
+ return this.clear().add(p[0], p[1]).add(p[2], p[3]);
1913
+ }
1914
+ union(b) {
1915
+ 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;
1916
+ }
1917
+ intersect(b) {
1918
+ 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;
1919
+ }
1920
+ encloses(b) {
1921
+ return b && this.x1 <= b.x1 && this.x2 >= b.x2 && this.y1 <= b.y1 && this.y2 >= b.y2;
1922
+ }
1923
+ alignsWith(b) {
1924
+ return b && (this.x1 === b.x1 || this.x2 === b.x2 || this.y1 === b.y1 || this.y2 === b.y2);
1925
+ }
1926
+ intersects(b) {
1927
+ return b && !(this.x2 < b.x1 || this.x1 > b.x2 || this.y2 < b.y1 || this.y1 > b.y2);
1928
+ }
1929
+ contains() {
1930
+ let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1931
+ let y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1932
+ return !(x < this.x1 || x > this.x2 || y < this.y1 || y > this.y2);
1933
+ }
1934
+ containsPoint(p) {
1935
+ return !(p.x < this.x1 || p.x > this.x2 || p.y < this.y1 || p.y > this.y2);
1936
+ }
1937
+ width() {
1938
+ return this.empty() ? 0 : this.x2 - this.x1;
1939
+ }
1940
+ height() {
1941
+ return this.empty() ? 0 : this.y2 - this.y1;
1942
+ }
1943
+ scaleX() {
1944
+ let s = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1945
+ return this.x1 *= s, this.x2 *= s, this;
1946
+ }
1947
+ scaleY() {
1948
+ let s = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1949
+ return this.y1 *= s, this.y2 *= s, this;
1950
+ }
1951
+ transformWithMatrix(matrix) {
1952
+ return transformBoundsWithMatrix(this, this, matrix), this;
1953
+ }
1954
+ copy(b) {
1955
+ return this.x1 = b.x1, this.y1 = b.y1, this.x2 = b.x2, this.y2 = b.y2, this;
1956
+ }
1957
+ rotatedPoints(angle, x, y) {
1958
+ const {
1959
+ x1: x1,
1960
+ y1: y1,
1961
+ x2: x2,
1962
+ y2: y2
1963
+ } = this,
1964
+ cos = Math.cos(angle),
1965
+ sin = Math.sin(angle),
1966
+ cx = x - x * cos + y * sin,
1967
+ cy = y - x * sin - y * cos;
1968
+ 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];
1969
+ }
1970
+ scalePoints(sx, sy, x, y) {
1971
+ const {
1972
+ x1: x1,
1973
+ y1: y1,
1974
+ x2: x2,
1975
+ y2: y2
1976
+ } = this;
1977
+ return [sx * x1 + (1 - sx) * x, sy * y1 + (1 - sy) * y, sx * x2 + (1 - sx) * x, sy * y2 + (1 - sy) * y];
1978
+ }
1979
+ }
1980
+ class AABBBounds extends Bounds {}
1981
+ class OBBBounds extends Bounds {
1982
+ constructor(bounds) {
1983
+ let angle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1984
+ super(bounds), bounds && (this.angle = angle);
1985
+ }
1986
+ intersects(b) {
1987
+ return isRotateAABBIntersect(this, b);
1988
+ }
1989
+ setValue() {
1990
+ let x1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1991
+ let y1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1992
+ let x2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1993
+ let y2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1994
+ let angle = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
1995
+ return super.setValue(x1, y1, x2, y2), this.angle = angle, this;
1996
+ }
1997
+ }
1998
+
1999
+ class Matrix {
2000
+ constructor() {
2001
+ let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
2002
+ let b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
2003
+ let c = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
2004
+ let d = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
2005
+ let e = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
2006
+ let f = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
2007
+ this.a = a, this.b = b, this.c = c, this.d = d, this.e = e, this.f = f;
2008
+ }
2009
+ equalToMatrix(m2) {
2010
+ 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);
2011
+ }
2012
+ equalTo(a, b, c, d, e, f) {
2013
+ return !(this.e !== e || this.f !== f || this.a !== a || this.d !== d || this.b !== b || this.c !== c);
2014
+ }
2015
+ setValue(a, b, c, d, e, f) {
2016
+ return this.a = a, this.b = b, this.c = c, this.d = d, this.e = e, this.f = f, this;
2017
+ }
2018
+ reset() {
2019
+ return this.a = 1, this.b = 0, this.c = 0, this.d = 1, this.e = 0, this.f = 0, this;
2020
+ }
2021
+ getInverse() {
2022
+ const a = this.a,
2023
+ b = this.b,
2024
+ c = this.c,
2025
+ d = this.d,
2026
+ e = this.e,
2027
+ f = this.f,
2028
+ m = new Matrix(),
2029
+ dt = a * d - b * c;
2030
+ 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;
2031
+ }
2032
+ rotate(rad) {
2033
+ const c = Math.cos(rad),
1577
2034
  s = Math.sin(rad),
1578
2035
  m11 = this.a * c + this.c * s,
1579
2036
  m12 = this.b * c + this.d * s,
@@ -1997,522 +2454,152 @@
1997
2454
  if (void 0 !== hexRes) return hexRes;
1998
2455
  if (/^(rgb|RGB|rgba|RGBA)/.test(formatValue)) {
1999
2456
  const aColor = formatValue.replace(/(?:\(|\)|rgba|RGBA|rgb|RGB)*/g, "").split(",");
2000
- return new RGB(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10), parseFloat(aColor[3]));
2001
- }
2002
- if (/^(hsl|HSL|hsla|HSLA)/.test(formatValue)) {
2003
- const aColor = formatValue.replace(/(?:\(|\)|hsla|HSLA|hsl|HSL)*/g, "").split(","),
2004
- rgb = hslToRgb(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10));
2005
- return new RGB(rgb.r, rgb.g, rgb.b, parseFloat(aColor[3]));
2006
- }
2007
- }
2008
- constructor(value) {
2009
- const color = Color.parseColorString(value);
2010
- color ? this.color = color : (console.warn(`Warn: 传入${value}无法解析为Color`), this.color = new RGB(255, 255, 255));
2011
- }
2012
- toRGBA() {
2013
- return this.color.formatRgb();
2014
- }
2015
- toString() {
2016
- return this.color.formatRgb();
2017
- }
2018
- toHex() {
2019
- return this.color.formatHex();
2020
- }
2021
- toHsl() {
2022
- return this.color.formatHsl();
2023
- }
2024
- brighter(k) {
2025
- const {
2026
- r: r,
2027
- g: g,
2028
- b: b
2029
- } = this.color;
2030
- 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;
2031
- }
2032
- add(color) {
2033
- const {
2034
- r: r,
2035
- g: g,
2036
- b: b
2037
- } = this.color;
2038
- 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;
2039
- }
2040
- sub(color) {
2041
- 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;
2042
- }
2043
- multiply(color) {
2044
- const {
2045
- r: r,
2046
- g: g,
2047
- b: b
2048
- } = this.color;
2049
- 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;
2050
- }
2051
- getHSVBrightness() {
2052
- return Math.max(this.color.r, this.color.g, this.color.b) / 255;
2053
- }
2054
- getHSLBrightness() {
2055
- 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);
2056
- }
2057
- setHsl(h, s, l) {
2058
- const opacity = this.color.opacity,
2059
- hsl = rgbToHsl(this.color.r, this.color.g, this.color.b),
2060
- 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);
2061
- return this.color = new RGB(rgb.r, rgb.g, rgb.b, opacity), this;
2062
- }
2063
- setRGB(r, g, b) {
2064
- return !isNil$1(r) && (this.color.r = r), !isNil$1(g) && (this.color.g = g), !isNil$1(b) && (this.color.b = b), this;
2065
- }
2066
- setHex(value) {
2067
- const formatValue = `${value}`.trim().toLowerCase(),
2068
- res = setHex(formatValue, !0);
2069
- return null != res ? res : this;
2070
- }
2071
- setColorName(name) {
2072
- const hex = DEFAULT_COLORS[name.toLowerCase()];
2073
- return void 0 !== hex ? this.setHex(hex) : console.warn("THREE.Color: Unknown color " + name), this;
2074
- }
2075
- setScalar(scalar) {
2076
- return this.color.r = scalar, this.color.g = scalar, this.color.b = scalar, this;
2077
- }
2078
- setOpacity() {
2079
- let o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
2080
- return this.color.opacity = o, this;
2081
- }
2082
- getLuminance() {
2083
- return (.2126 * this.color.r + .7152 * this.color.g + .0722 * this.color.b) / 255;
2084
- }
2085
- getLuminance2() {
2086
- return (.2627 * this.color.r + .678 * this.color.g + .0593 * this.color.b) / 255;
2087
- }
2088
- getLuminance3() {
2089
- return (.299 * this.color.r + .587 * this.color.g + .114 * this.color.b) / 255;
2090
- }
2091
- clone() {
2092
- return new Color(this.color.toString());
2093
- }
2094
- copyGammaToLinear(color) {
2095
- let gammaFactor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
2096
- 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;
2097
- }
2098
- copyLinearToGamma(color) {
2099
- let gammaFactor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
2100
- const safeInverse = gammaFactor > 0 ? 1 / gammaFactor : 1;
2101
- 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;
2102
- }
2103
- convertGammaToLinear(gammaFactor) {
2104
- return this.copyGammaToLinear(this, gammaFactor), this;
2105
- }
2106
- convertLinearToGamma(gammaFactor) {
2107
- return this.copyLinearToGamma(this, gammaFactor), this;
2108
- }
2109
- copySRGBToLinear(color) {
2110
- return this.color.r = SRGBToLinear(color.color.r), this.color.g = SRGBToLinear(color.color.g), this.color.b = SRGBToLinear(color.color.b), this;
2457
+ return new RGB(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10), parseFloat(aColor[3]));
2458
+ }
2459
+ if (/^(hsl|HSL|hsla|HSLA)/.test(formatValue)) {
2460
+ const aColor = formatValue.replace(/(?:\(|\)|hsla|HSLA|hsl|HSL)*/g, "").split(","),
2461
+ rgb = hslToRgb(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10));
2462
+ return new RGB(rgb.r, rgb.g, rgb.b, parseFloat(aColor[3]));
2463
+ }
2111
2464
  }
2112
- copyLinearToSRGB(color) {
2113
- return this.color.r = LinearToSRGB(color.color.r), this.color.g = LinearToSRGB(color.color.g), this.color.b = LinearToSRGB(color.color.b), this;
2465
+ constructor(value) {
2466
+ const color = Color.parseColorString(value);
2467
+ color ? this.color = color : (console.warn(`Warn: 传入${value}无法解析为Color`), this.color = new RGB(255, 255, 255));
2114
2468
  }
2115
- convertSRGBToLinear() {
2116
- return this.copySRGBToLinear(this), this;
2469
+ toRGBA() {
2470
+ return this.color.formatRgb();
2117
2471
  }
2118
- convertLinearToSRGB() {
2119
- return this.copyLinearToSRGB(this), this;
2472
+ toString() {
2473
+ return this.color.formatRgb();
2120
2474
  }
2121
- }
2122
- class RGB {
2123
- constructor(r, g, b, opacity) {
2124
- 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;
2475
+ toHex() {
2476
+ return this.color.formatHex();
2125
2477
  }
2126
- formatHex() {
2127
- return `#${hex(this.r) + hex(this.g) + hex(this.b) + (1 === this.opacity ? "" : hex(255 * this.opacity))}`;
2478
+ toHsl() {
2479
+ return this.color.formatHsl();
2128
2480
  }
2129
- formatRgb() {
2130
- const opacity = this.opacity;
2131
- return `${1 === opacity ? "rgb(" : "rgba("}${this.r},${this.g},${this.b}${1 === opacity ? ")" : `,${opacity})`}`;
2481
+ brighter(k) {
2482
+ const {
2483
+ r: r,
2484
+ g: g,
2485
+ b: b
2486
+ } = this.color;
2487
+ 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;
2132
2488
  }
2133
- formatHsl() {
2134
- const opacity = this.opacity,
2135
- {
2136
- h: h,
2137
- s: s,
2138
- l: l
2139
- } = rgbToHsl(this.r, this.g, this.b);
2140
- return `${1 === opacity ? "hsl(" : "hsla("}${h},${s}%,${l}%${1 === opacity ? ")" : `,${opacity})`}`;
2489
+ add(color) {
2490
+ const {
2491
+ r: r,
2492
+ g: g,
2493
+ b: b
2494
+ } = this.color;
2495
+ 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;
2141
2496
  }
2142
- toString() {
2143
- return this.formatHex();
2497
+ sub(color) {
2498
+ 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;
2144
2499
  }
2145
- }
2146
-
2147
- function sub(out, v1, v2) {
2148
- out[0] = v1[0] - v2[0], out[1] = v1[1] - v2[1];
2149
- }
2150
- function isIntersect(left1, right1, left2, right2) {
2151
- let min1 = left1[0],
2152
- max1 = right1[0],
2153
- min2 = left2[0],
2154
- max2 = right2[0];
2155
- 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));
2156
- }
2157
- function getIntersectPoint(left1, right1, left2, right2) {
2158
- if (!isIntersect(left1, right1, left2, right2)) return !1;
2159
- const dir1 = [0, 0],
2160
- dir2 = [0, 0],
2161
- tempVec = [0, 0];
2162
- if (sub(dir1, right1, left1), sub(dir2, right2, left2), fuzzyEqualVec(dir1, dir2)) return !0;
2163
- sub(tempVec, left2, left1);
2164
- const t = crossProduct$1(tempVec, dir2) / crossProduct$1(dir1, dir2);
2165
- return t >= 0 && t <= 1 && [left1[0] + dir1[0] * t, left1[1] + dir1[1] * t];
2166
- }
2167
- function getRectIntersect(bbox1, bbox2, format) {
2168
- if (null === bbox1) return bbox2;
2169
- if (null === bbox2) return bbox1;
2170
- const {
2171
- x11: x11,
2172
- x12: x12,
2173
- y11: y11,
2174
- y12: y12,
2175
- x21: x21,
2176
- x22: x22,
2177
- y21: y21,
2178
- y22: y22
2179
- } = formatTwoBBox(bbox1, bbox2, format);
2180
- return x11 >= x22 || x12 <= x21 || y11 >= y22 || y12 <= y21 ? {
2181
- x1: 0,
2182
- y1: 0,
2183
- x2: 0,
2184
- y2: 0
2185
- } : {
2186
- x1: Math.max(x11, x21),
2187
- y1: Math.max(y11, y21),
2188
- x2: Math.min(x12, x22),
2189
- y2: Math.min(y12, y22)
2190
- };
2191
- }
2192
- var InnerBBox;
2193
- !function (InnerBBox) {
2194
- InnerBBox[InnerBBox.NONE = 0] = "NONE", InnerBBox[InnerBBox.BBOX1 = 1] = "BBOX1", InnerBBox[InnerBBox.BBOX2 = 2] = "BBOX2";
2195
- }(InnerBBox || (InnerBBox = {}));
2196
- const formatTwoBBox = (bbox1, bbox2, format) => {
2197
- let x11 = bbox1.x1,
2198
- x12 = bbox1.x2,
2199
- y11 = bbox1.y1,
2200
- y12 = bbox1.y2,
2201
- x21 = bbox2.x1,
2202
- x22 = bbox2.x2,
2203
- y21 = bbox2.y1,
2204
- y22 = bbox2.y2;
2205
- 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])), {
2206
- x11: x11,
2207
- x12: x12,
2208
- y11: y11,
2209
- y12: y12,
2210
- x21: x21,
2211
- x22: x22,
2212
- y21: y21,
2213
- y22: y22
2214
- };
2215
- };
2216
- function isRectIntersect(bbox1, bbox2, format) {
2217
- if (bbox1 && bbox2) {
2218
- if (!format) return !(bbox1.x1 > bbox2.x2 || bbox1.x2 < bbox2.x1 || bbox1.y1 > bbox2.y2 || bbox1.y2 < bbox2.y1);
2500
+ multiply(color) {
2219
2501
  const {
2220
- x11: x11,
2221
- x12: x12,
2222
- y11: y11,
2223
- y12: y12,
2224
- x21: x21,
2225
- x22: x22,
2226
- y21: y21,
2227
- y22: y22
2228
- } = formatTwoBBox(bbox1, bbox2, !0);
2229
- return !(x11 > x22 || x12 < x21 || y11 > y22 || y12 < y21);
2502
+ r: r,
2503
+ g: g,
2504
+ b: b
2505
+ } = this.color;
2506
+ 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;
2230
2507
  }
2231
- return !0;
2232
- }
2233
-
2234
- function isPointInLine(x0, y0, x1, y1, x, y) {
2235
- if (y > y0 && y > y1 || y < y0 && y < y1) return 0;
2236
- if (y1 === y0) return 0;
2237
- const t = (y - y0) / (y1 - y0);
2238
- let dir = y1 < y0 ? 1 : -1;
2239
- 1 !== t && 0 !== t || (dir = y1 < y0 ? .5 : -.5);
2240
- const x_ = t * (x1 - x0) + x0;
2241
- return x_ === x ? 1 / 0 : x_ > x ? dir : 0;
2242
- }
2243
-
2244
- const eastAsianCharacterInfo = character => {
2245
- let x = character.charCodeAt(0),
2246
- y = 2 === character.length ? character.charCodeAt(1) : 0,
2247
- codePoint = x;
2248
- 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";
2249
- };
2250
-
2251
- function getContextFont(text) {
2252
- let defaultAttr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2253
- let fontSizeScale = arguments.length > 2 ? arguments[2] : undefined;
2254
- fontSizeScale || (fontSizeScale = 1);
2255
- const {
2256
- fontStyle = defaultAttr.fontStyle,
2257
- fontVariant = defaultAttr.fontVariant,
2258
- fontWeight = defaultAttr.fontWeight,
2259
- fontSize = defaultAttr.fontSize,
2260
- fontFamily = defaultAttr.fontFamily
2261
- } = text;
2262
- return (fontStyle ? fontStyle + " " : "") + (fontVariant ? fontVariant + " " : "") + (fontWeight ? fontWeight + " " : "") + fontSize * fontSizeScale + "px " + (fontFamily || "sans-serif");
2263
- }
2264
-
2265
- class TextMeasure {
2266
- constructor(option, textSpec) {
2267
- 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);
2508
+ getHSVBrightness() {
2509
+ return Math.max(this.color.r, this.color.g, this.color.b) / 255;
2268
2510
  }
2269
- initContext() {
2270
- if (this._notSupportCanvas) return !1;
2271
- 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)) {
2272
- const context = this._canvas.getContext("2d");
2273
- isValid$1(context) && (context.save(), context.font = getContextFont(this.textSpec), this._contextSaved = !0, this._context = context);
2274
- }
2275
- return !isNil$1(this._context) || (this._notSupportCanvas = !0, !1);
2511
+ getHSLBrightness() {
2512
+ 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);
2276
2513
  }
2277
- _initSpec() {
2278
- var _a, _b, _c;
2279
- const {
2280
- defaultFontParams = {}
2281
- } = this._option,
2282
- {
2283
- fontStyle = defaultFontParams.fontStyle,
2284
- fontVariant = defaultFontParams.fontVariant,
2285
- fontWeight = null !== (_a = defaultFontParams.fontWeight) && void 0 !== _a ? _a : "normal",
2286
- fontSize = null !== (_b = defaultFontParams.fontSize) && void 0 !== _b ? _b : 12,
2287
- fontFamily = null !== (_c = defaultFontParams.fontFamily) && void 0 !== _c ? _c : "sans-serif",
2288
- align: align,
2289
- textAlign = null != align ? align : "center",
2290
- baseline: baseline,
2291
- textBaseline = null != baseline ? baseline : "middle",
2292
- ellipsis: ellipsis,
2293
- limit: limit
2294
- } = this._userSpec;
2295
- let {
2296
- lineHeight = fontSize
2297
- } = this._userSpec;
2298
- if (isString$1(lineHeight) && "%" === lineHeight[lineHeight.length - 1]) {
2299
- const scale = Number.parseFloat(lineHeight.substring(0, lineHeight.length - 1)) / 100;
2300
- lineHeight = fontSize * scale;
2301
- }
2302
- return {
2303
- fontStyle: fontStyle,
2304
- fontVariant: fontVariant,
2305
- fontFamily: fontFamily,
2306
- fontSize: fontSize,
2307
- fontWeight: fontWeight,
2308
- textAlign: textAlign,
2309
- textBaseline: textBaseline,
2310
- ellipsis: ellipsis,
2311
- limit: limit,
2312
- lineHeight: lineHeight
2313
- };
2514
+ setHsl(h, s, l) {
2515
+ const opacity = this.color.opacity,
2516
+ hsl = rgbToHsl(this.color.r, this.color.g, this.color.b),
2517
+ 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);
2518
+ return this.color = new RGB(rgb.r, rgb.g, rgb.b, opacity), this;
2314
2519
  }
2315
- measure(text, method) {
2316
- switch (method) {
2317
- case "vrender":
2318
- case "canopus":
2319
- return this.fullMeasure(text);
2320
- case "canvas":
2321
- return this.measureWithNaiveCanvas(text);
2322
- case "simple":
2323
- return this.quickMeasureWithoutCanvas(text);
2324
- default:
2325
- return this.quickMeasure(text);
2326
- }
2520
+ setRGB(r, g, b) {
2521
+ return !isNil$1(r) && (this.color.r = r), !isNil$1(g) && (this.color.g = g), !isNil$1(b) && (this.color.b = b), this;
2522
+ }
2523
+ setHex(value) {
2524
+ const formatValue = `${value}`.trim().toLowerCase(),
2525
+ res = setHex(formatValue, !0);
2526
+ return null != res ? res : this;
2327
2527
  }
2328
- fullMeasure(text) {
2329
- if (isNil$1(text)) return {
2330
- width: 0,
2331
- height: 0
2332
- };
2333
- if (isNil$1(this._option.getTextBounds) || !this._notSupportVRender) return this.measureWithNaiveCanvas(text);
2334
- const {
2335
- fontFamily: fontFamily,
2336
- fontSize: fontSize,
2337
- fontWeight: fontWeight,
2338
- textAlign: textAlign,
2339
- textBaseline: textBaseline,
2340
- ellipsis: ellipsis,
2341
- limit: limit,
2342
- lineHeight: lineHeight
2343
- } = this.textSpec;
2344
- let size;
2345
- try {
2346
- const bounds = this._option.getTextBounds({
2347
- text: text,
2348
- fontFamily: fontFamily,
2349
- fontSize: fontSize,
2350
- fontWeight: fontWeight,
2351
- textAlign: textAlign,
2352
- textBaseline: textBaseline,
2353
- ellipsis: !!ellipsis,
2354
- maxLineWidth: limit || 1 / 0,
2355
- lineHeight: lineHeight
2356
- });
2357
- size = {
2358
- width: bounds.width(),
2359
- height: bounds.height()
2360
- };
2361
- } catch (e) {
2362
- this._notSupportVRender = !0, size = this.measureWithNaiveCanvas(text);
2363
- }
2364
- return size;
2528
+ setColorName(name) {
2529
+ const hex = DEFAULT_COLORS[name.toLowerCase()];
2530
+ return void 0 !== hex ? this.setHex(hex) : console.warn("THREE.Color: Unknown color " + name), this;
2365
2531
  }
2366
- measureWithNaiveCanvas(text) {
2367
- return this._measureReduce(text, this._measureWithNaiveCanvas.bind(this));
2532
+ setScalar(scalar) {
2533
+ return this.color.r = scalar, this.color.g = scalar, this.color.b = scalar, this;
2368
2534
  }
2369
- _measureWithNaiveCanvas(text) {
2370
- var _a;
2371
- if (!this.initContext()) return this._quickMeasureWithoutCanvas(text);
2372
- const metrics = this._context.measureText(text),
2373
- {
2374
- fontSize: fontSize,
2375
- lineHeight: lineHeight
2376
- } = this.textSpec;
2377
- return {
2378
- width: metrics.width,
2379
- height: null !== (_a = lineHeight) && void 0 !== _a ? _a : fontSize
2380
- };
2535
+ setOpacity() {
2536
+ let o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
2537
+ return this.color.opacity = o, this;
2381
2538
  }
2382
- quickMeasure(text) {
2383
- return this._measureReduce(text, this._quickMeasure.bind(this));
2539
+ getLuminance() {
2540
+ return (.2126 * this.color.r + .7152 * this.color.g + .0722 * this.color.b) / 255;
2384
2541
  }
2385
- _quickMeasure(text) {
2386
- const totalSize = {
2387
- width: 0,
2388
- height: 0
2389
- };
2390
- for (let i = 0; i < text.length; i++) {
2391
- const char = text[i];
2392
- let size = this._measureSpecialChar(char);
2393
- 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);
2394
- }
2395
- return totalSize;
2542
+ getLuminance2() {
2543
+ return (.2627 * this.color.r + .678 * this.color.g + .0593 * this.color.b) / 255;
2396
2544
  }
2397
- quickMeasureWithoutCanvas(text) {
2398
- return this._measureReduce(text, this._quickMeasureWithoutCanvas.bind(this));
2545
+ getLuminance3() {
2546
+ return (.299 * this.color.r + .587 * this.color.g + .114 * this.color.b) / 255;
2399
2547
  }
2400
- _quickMeasureWithoutCanvas(text) {
2401
- var _a;
2402
- const totalSize = {
2403
- width: 0,
2404
- height: 0
2405
- },
2406
- {
2407
- fontSize: fontSize,
2408
- lineHeight: lineHeight
2409
- } = this.textSpec;
2410
- for (let i = 0; i < text.length; i++) {
2411
- const char = text[i],
2412
- size = ["F", "W"].includes(eastAsianCharacterInfo(char)) ? 1 : .53;
2413
- totalSize.width += size * fontSize;
2414
- }
2415
- return totalSize.height = null !== (_a = lineHeight) && void 0 !== _a ? _a : fontSize, totalSize;
2548
+ clone() {
2549
+ return new Color(this.color.toString());
2416
2550
  }
2417
- _measureReduce(text, processor) {
2418
- var _a;
2419
- const {
2420
- fontSize: fontSize,
2421
- lineHeight: lineHeight
2422
- } = this.textSpec,
2423
- defaultResult = {
2424
- width: 0,
2425
- height: 0
2426
- };
2427
- if (isNil$1(text)) return defaultResult;
2428
- if (isArray$1(text)) {
2429
- const textArr = text.filter(isValid$1).map(s => s.toString());
2430
- return 0 === textArr.length ? defaultResult : 1 === textArr.length ? processor(textArr[0]) : {
2431
- width: textArr.reduce((maxWidth, cur) => Math.max(maxWidth, processor(cur).width), 0),
2432
- height: textArr.length * ((null !== (_a = lineHeight) && void 0 !== _a ? _a : fontSize) + 1) + 1
2433
- };
2434
- }
2435
- return processor(text.toString());
2551
+ copyGammaToLinear(color) {
2552
+ let gammaFactor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
2553
+ 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;
2436
2554
  }
2437
- _measureNumberChar() {
2438
- if (isNil$1(this._numberCharSize)) {
2439
- const numberBounds = this._standardMethod(TextMeasure.NUMBERS_CHAR_SET);
2440
- this._numberCharSize = {
2441
- width: numberBounds.width / TextMeasure.NUMBERS_CHAR_SET.length,
2442
- height: numberBounds.height
2443
- };
2444
- }
2445
- return this._numberCharSize;
2555
+ copyLinearToGamma(color) {
2556
+ let gammaFactor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
2557
+ const safeInverse = gammaFactor > 0 ? 1 / gammaFactor : 1;
2558
+ 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;
2446
2559
  }
2447
- _measureFullSizeChar() {
2448
- return isNil$1(this._fullCharSize) && (this._fullCharSize = this._standardMethod(TextMeasure.FULL_SIZE_CHAR)), this._fullCharSize;
2560
+ convertGammaToLinear(gammaFactor) {
2561
+ return this.copyGammaToLinear(this, gammaFactor), this;
2449
2562
  }
2450
- _measureLetterChar() {
2451
- if (isNil$1(this._letterCharSize)) {
2452
- const alphabetBounds = this._standardMethod(TextMeasure.ALPHABET_CHAR_SET);
2453
- this._letterCharSize = {
2454
- width: alphabetBounds.width / TextMeasure.ALPHABET_CHAR_SET.length,
2455
- height: alphabetBounds.height
2456
- };
2457
- }
2458
- return this._letterCharSize;
2563
+ convertLinearToGamma(gammaFactor) {
2564
+ return this.copyLinearToGamma(this, gammaFactor), this;
2459
2565
  }
2460
- _measureSpecialChar(char) {
2461
- return isValid$1(this._specialCharSizeMap[char]) ? this._specialCharSizeMap[char] : this.specialCharSet.includes(char) ? (this._specialCharSizeMap[char] = this._standardMethod(char), this._specialCharSizeMap[char]) : null;
2566
+ copySRGBToLinear(color) {
2567
+ return this.color.r = SRGBToLinear(color.color.r), this.color.g = SRGBToLinear(color.color.g), this.color.b = SRGBToLinear(color.color.b), this;
2462
2568
  }
2463
- release() {
2464
- isValid$1(this._canvas) && (this._canvas = null), isValid$1(this._context) && (this._contextSaved && (this._context.restore(), this._contextSaved = !1), this._context = null);
2569
+ copyLinearToSRGB(color) {
2570
+ return this.color.r = LinearToSRGB(color.color.r), this.color.g = LinearToSRGB(color.color.g), this.color.b = LinearToSRGB(color.color.b), this;
2571
+ }
2572
+ convertSRGBToLinear() {
2573
+ return this.copySRGBToLinear(this), this;
2574
+ }
2575
+ convertLinearToSRGB() {
2576
+ return this.copyLinearToSRGB(this), this;
2465
2577
  }
2466
2578
  }
2467
- TextMeasure.ALPHABET_CHAR_SET = "abcdefghijklmnopqrstuvwxyz", TextMeasure.NUMBERS_CHAR_SET = "0123456789", TextMeasure.FULL_SIZE_CHAR = "字";
2468
-
2469
- const calculateAnchorOfBounds = (bounds, anchorType) => {
2470
- const {
2471
- x1: x1,
2472
- x2: x2,
2473
- y1: y1,
2474
- y2: y2
2475
- } = bounds,
2476
- rectWidth = Math.abs(x2 - x1),
2477
- rectHeight = Math.abs(y2 - y1);
2478
- let anchorX = (x1 + x2) / 2,
2479
- anchorY = (y1 + y2) / 2,
2480
- sx = 0,
2481
- sy = 0;
2482
- switch (anchorType) {
2483
- case "top":
2484
- case "inside-top":
2485
- sy = -.5;
2486
- break;
2487
- case "bottom":
2488
- case "inside-bottom":
2489
- sy = .5;
2490
- break;
2491
- case "left":
2492
- case "inside-left":
2493
- sx = -.5;
2494
- break;
2495
- case "right":
2496
- case "inside-right":
2497
- sx = .5;
2498
- break;
2499
- case "top-right":
2500
- sx = .5, sy = -.5;
2501
- break;
2502
- case "top-left":
2503
- sx = -.5, sy = -.5;
2504
- break;
2505
- case "bottom-right":
2506
- sx = .5, sy = .5;
2507
- break;
2508
- case "bottom-left":
2509
- sx = -.5, sy = .5;
2579
+ class RGB {
2580
+ constructor(r, g, b, opacity) {
2581
+ 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;
2510
2582
  }
2511
- return anchorX += sx * rectWidth, anchorY += sy * rectHeight, {
2512
- x: anchorX,
2513
- y: anchorY
2514
- };
2515
- };
2583
+ formatHex() {
2584
+ return `#${hex(this.r) + hex(this.g) + hex(this.b) + (1 === this.opacity ? "" : hex(255 * this.opacity))}`;
2585
+ }
2586
+ formatRgb() {
2587
+ const opacity = this.opacity;
2588
+ return `${1 === opacity ? "rgb(" : "rgba("}${this.r},${this.g},${this.b}${1 === opacity ? ")" : `,${opacity})`}`;
2589
+ }
2590
+ formatHsl() {
2591
+ const opacity = this.opacity,
2592
+ {
2593
+ h: h,
2594
+ s: s,
2595
+ l: l
2596
+ } = rgbToHsl(this.r, this.g, this.b);
2597
+ return `${1 === opacity ? "hsl(" : "hsla("}${h},${s}%,${l}%${1 === opacity ? ")" : `,${opacity})`}`;
2598
+ }
2599
+ toString() {
2600
+ return this.formatHex();
2601
+ }
2602
+ }
2516
2603
 
2517
2604
  const styleStringToObject = function () {
2518
2605
  let styleStr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
@@ -9106,6 +9193,9 @@
9106
9193
  get AABBBounds() {
9107
9194
  return this.tryUpdateAABBBounds("imprecise" === this.attribute.boundsMode);
9108
9195
  }
9196
+ get OBBBounds() {
9197
+ return this.tryUpdateOBBBounds();
9198
+ }
9109
9199
  get globalAABBBounds() {
9110
9200
  return this.tryUpdateGlobalAABBBounds();
9111
9201
  }
@@ -9118,7 +9208,7 @@
9118
9208
  constructor() {
9119
9209
  let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
9120
9210
  var _a;
9121
- super(), this._AABBBounds = new AABBBounds(), this._updateTag = exports.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);
9211
+ super(), this._AABBBounds = new AABBBounds(), this._updateTag = exports.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);
9122
9212
  }
9123
9213
  setMode(mode) {
9124
9214
  "3d" === mode ? this.set3dMode() : this.set2dMode();
@@ -9152,13 +9242,22 @@
9152
9242
  const bounds = this.doUpdateAABBBounds(full);
9153
9243
  return application.graphicService.afterUpdateAABBBounds(this, this.stage, this._AABBBounds, this, !0), bounds;
9154
9244
  }
9245
+ tryUpdateOBBBounds() {
9246
+ if (this._OBBBounds || (this._OBBBounds = new OBBBounds()), this.tryUpdateAABBBounds(), this.updateOBBBoundsStamp === this.updateAABBBoundsStamp) return this._OBBBounds;
9247
+ if (this.updateOBBBoundsStamp = this.updateAABBBoundsStamp, !this.valid) return this._OBBBounds.clear(), this._OBBBounds;
9248
+ return this.doUpdateOBBBounds();
9249
+ }
9155
9250
  combindShadowAABBBounds(bounds) {
9156
9251
  if (this.shadowRoot) {
9157
9252
  const b = this.shadowRoot.AABBBounds.clone();
9158
9253
  bounds.union(b);
9159
9254
  }
9160
9255
  }
9256
+ doUpdateOBBBounds() {
9257
+ return this._OBBBounds;
9258
+ }
9161
9259
  doUpdateAABBBounds(full) {
9260
+ this.updateAABBBoundsStamp++;
9162
9261
  const graphicTheme = this.getGraphicTheme();
9163
9262
  this._AABBBounds.clear();
9164
9263
  const attribute = this.attribute,
@@ -10198,6 +10297,7 @@
10198
10297
  }), application.graphicService.updateTempAABBBounds(aabbBounds), application.graphicService.transformAABBBounds(attribute, aabbBounds, groupTheme, !1, this), originalAABBBounds.copy(aabbBounds), originalAABBBounds;
10199
10298
  }
10200
10299
  doUpdateAABBBounds() {
10300
+ this.updateAABBBoundsStamp++;
10201
10301
  const bounds = super.doUpdateAABBBounds();
10202
10302
  return this.parent && this.parent.addChildUpdateBoundTag(), this._emitCustomEvent("AAABBBoundsChange"), bounds;
10203
10303
  }
@@ -14091,7 +14191,10 @@
14091
14191
  }
14092
14192
  beforeDrawInteractive(graphic, renderService, drawContext, drawContribution, params) {
14093
14193
  const baseGraphic = graphic.baseGraphic;
14094
- if (!baseGraphic.stage) {
14194
+ let intree = !!baseGraphic.stage,
14195
+ _g = baseGraphic.parent;
14196
+ for (; intree && _g && _g.stage !== _g;) intree = !!_g.stage, _g = _g.parent;
14197
+ if (!intree) {
14095
14198
  const interactiveLayer = drawContext.stage.getLayer("_builtin_interactive");
14096
14199
  if (interactiveLayer) {
14097
14200
  this.getShadowRoot(interactiveLayer).removeChild(graphic);
@@ -14443,6 +14546,35 @@
14443
14546
  getGraphicTheme() {
14444
14547
  return getTheme(this).text;
14445
14548
  }
14549
+ doUpdateOBBBounds() {
14550
+ const graphicTheme = this.getGraphicTheme();
14551
+ this._OBBBounds.clear();
14552
+ const attribute = this.attribute,
14553
+ {
14554
+ angle = graphicTheme.angle
14555
+ } = attribute;
14556
+ if (!angle) {
14557
+ const b = this.AABBBounds;
14558
+ return this._OBBBounds.setValue(b.x1, b.y1, b.x2, b.y2), this._OBBBounds;
14559
+ }
14560
+ this.obbText || (this.obbText = new Text({})), this.obbText.setAttributes(Object.assign(Object.assign({}, attribute), {
14561
+ angle: 0
14562
+ }));
14563
+ const bounds1 = this.obbText.AABBBounds,
14564
+ {
14565
+ x: x,
14566
+ y: y
14567
+ } = attribute,
14568
+ boundsCenter = {
14569
+ x: (bounds1.x1 + bounds1.x2) / 2,
14570
+ y: (bounds1.y1 + bounds1.y2) / 2
14571
+ },
14572
+ center = rotatePoint(boundsCenter, angle, {
14573
+ x: x,
14574
+ y: y
14575
+ });
14576
+ return this._OBBBounds.copy(bounds1), this._OBBBounds.translate(center.x - boundsCenter.x, center.y - boundsCenter.y), this._OBBBounds.angle = angle, this._OBBBounds;
14577
+ }
14446
14578
  updateAABBBounds(attribute, textTheme, aabbBounds) {
14447
14579
  const {
14448
14580
  text = textTheme.text
@@ -15891,7 +16023,7 @@
15891
16023
  }), aabbBounds;
15892
16024
  }
15893
16025
  doUpdateAABBBounds() {
15894
- this._AABBBounds.clear();
16026
+ this.updateAABBBoundsStamp++, this._AABBBounds.clear();
15895
16027
  const bounds = this.updateAABBBounds(this.attribute, this.getGraphicTheme(), this._AABBBounds);
15896
16028
  return this.clearUpdateBoundTag(), bounds;
15897
16029
  }
@@ -17054,13 +17186,14 @@
17054
17186
  return super.needUpdateTag(key, ARC_UPDATE_TAG_KEY);
17055
17187
  }
17056
17188
  toCustomPath() {
17189
+ var _a, _b, _c, _d;
17057
17190
  const attribute = this.attribute,
17058
17191
  {
17059
17192
  startAngle: startAngle,
17060
17193
  endAngle: endAngle
17061
17194
  } = this.getParsedAngle();
17062
- let innerRadius = attribute.innerRadius - (attribute.innerPadding || 0),
17063
- outerRadius = attribute.outerRadius - (attribute.outerPadding || 0);
17195
+ let innerRadius = (null !== (_a = attribute.innerRadius) && void 0 !== _a ? _a : 0) - (null !== (_b = attribute.innerPadding) && void 0 !== _b ? _b : 0),
17196
+ outerRadius = (null !== (_c = attribute.outerRadius) && void 0 !== _c ? _c : 0) - (null !== (_d = attribute.outerPadding) && void 0 !== _d ? _d : 0);
17064
17197
  const deltaAngle = abs(endAngle - startAngle),
17065
17198
  clockwise = endAngle > startAngle;
17066
17199
  if (outerRadius < innerRadius) {
@@ -28336,7 +28469,7 @@
28336
28469
 
28337
28470
  const roughModule = _roughModule;
28338
28471
 
28339
- const version = "0.20.6-alpha.0";
28472
+ const version = "0.20.6-alpha.1";
28340
28473
  preLoadAllModule();
28341
28474
  if (isBrowserEnv()) {
28342
28475
  loadBrowserEnv(container);