modern-canvas 0.1.1 → 0.1.3

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.cjs CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  const colord = require('colord');
4
4
  const namesPlugin = require('colord/plugins/names');
5
- const earcut = require('earcut');
5
+ const modernPath2d = require('modern-path2d');
6
+ const modernIdoc = require('modern-idoc');
6
7
  const modernText = require('modern-text');
7
8
 
8
9
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
9
10
 
10
11
  const namesPlugin__default = /*#__PURE__*/_interopDefaultCompat(namesPlugin);
11
- const earcut__default = /*#__PURE__*/_interopDefaultCompat(earcut);
12
12
 
13
13
  const PI = Math.PI;
14
14
  const PI_2 = PI * 2;
@@ -623,13 +623,13 @@ class Geometry extends Resource {
623
623
  }
624
624
  }
625
625
 
626
- var __defProp$B = Object.defineProperty;
627
- var __decorateClass$B = (decorators, target, key, kind) => {
626
+ var __defProp$A = Object.defineProperty;
627
+ var __decorateClass$A = (decorators, target, key, kind) => {
628
628
  var result = void 0 ;
629
629
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
630
630
  if (decorator = decorators[i])
631
631
  result = (decorator(target, key, result) ) || result;
632
- if (result) __defProp$B(target, key, result);
632
+ if (result) __defProp$A(target, key, result);
633
633
  return result;
634
634
  };
635
635
  class IndexBuffer extends Resource {
@@ -673,20 +673,20 @@ class IndexBuffer extends Resource {
673
673
  return result;
674
674
  }
675
675
  }
676
- __decorateClass$B([
676
+ __decorateClass$A([
677
677
  protectedProperty({ default: null })
678
678
  ], IndexBuffer.prototype, "data");
679
- __decorateClass$B([
679
+ __decorateClass$A([
680
680
  protectedProperty({ default: false })
681
681
  ], IndexBuffer.prototype, "dynamic");
682
682
 
683
- var __defProp$A = Object.defineProperty;
684
- var __decorateClass$A = (decorators, target, key, kind) => {
683
+ var __defProp$z = Object.defineProperty;
684
+ var __decorateClass$z = (decorators, target, key, kind) => {
685
685
  var result = void 0 ;
686
686
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
687
687
  if (decorator = decorators[i])
688
688
  result = (decorator(target, key, result) ) || result;
689
- if (result) __defProp$A(target, key, result);
689
+ if (result) __defProp$z(target, key, result);
690
690
  return result;
691
691
  };
692
692
  class VertexBuffer extends Resource {
@@ -730,20 +730,20 @@ class VertexBuffer extends Resource {
730
730
  return result;
731
731
  }
732
732
  }
733
- __decorateClass$A([
733
+ __decorateClass$z([
734
734
  protectedProperty({ default: null })
735
735
  ], VertexBuffer.prototype, "data");
736
- __decorateClass$A([
736
+ __decorateClass$z([
737
737
  protectedProperty({ default: false })
738
738
  ], VertexBuffer.prototype, "dynamic");
739
739
 
740
- var __defProp$z = Object.defineProperty;
741
- var __decorateClass$z = (decorators, target, key, kind) => {
740
+ var __defProp$y = Object.defineProperty;
741
+ var __decorateClass$y = (decorators, target, key, kind) => {
742
742
  var result = void 0 ;
743
743
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
744
744
  if (decorator = decorators[i])
745
745
  result = (decorator(target, key, result) ) || result;
746
- if (result) __defProp$z(target, key, result);
746
+ if (result) __defProp$y(target, key, result);
747
747
  return result;
748
748
  };
749
749
  class VertexAttribute extends Resource {
@@ -780,25 +780,25 @@ class VertexAttribute extends Resource {
780
780
  return result;
781
781
  }
782
782
  }
783
- __decorateClass$z([
783
+ __decorateClass$y([
784
784
  protectedProperty()
785
785
  ], VertexAttribute.prototype, "buffer");
786
- __decorateClass$z([
786
+ __decorateClass$y([
787
787
  protectedProperty({ default: 0 })
788
788
  ], VertexAttribute.prototype, "size");
789
- __decorateClass$z([
789
+ __decorateClass$y([
790
790
  protectedProperty({ default: false })
791
791
  ], VertexAttribute.prototype, "normalized");
792
- __decorateClass$z([
792
+ __decorateClass$y([
793
793
  protectedProperty({ default: "float" })
794
794
  ], VertexAttribute.prototype, "type");
795
- __decorateClass$z([
795
+ __decorateClass$y([
796
796
  protectedProperty()
797
797
  ], VertexAttribute.prototype, "stride");
798
- __decorateClass$z([
798
+ __decorateClass$y([
799
799
  protectedProperty()
800
800
  ], VertexAttribute.prototype, "offset");
801
- __decorateClass$z([
801
+ __decorateClass$y([
802
802
  protectedProperty()
803
803
  ], VertexAttribute.prototype, "divisor");
804
804
 
@@ -982,13 +982,13 @@ class UvGeometry extends Geometry {
982
982
  }
983
983
  }
984
984
 
985
- var __defProp$y = Object.defineProperty;
986
- var __decorateClass$y = (decorators, target, key, kind) => {
985
+ var __defProp$x = Object.defineProperty;
986
+ var __decorateClass$x = (decorators, target, key, kind) => {
987
987
  var result = void 0 ;
988
988
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
989
989
  if (decorator = decorators[i])
990
990
  result = (decorator(target, key, result) ) || result;
991
- if (result) __defProp$y(target, key, result);
991
+ if (result) __defProp$x(target, key, result);
992
992
  return result;
993
993
  };
994
994
  class MainLoop extends _Object {
@@ -1029,1731 +1029,182 @@ class MainLoop extends _Object {
1029
1029
  }
1030
1030
  }
1031
1031
  }
1032
- __decorateClass$y([
1032
+ __decorateClass$x([
1033
1033
  property({ default: 24 })
1034
1034
  ], MainLoop.prototype, "fps");
1035
- __decorateClass$y([
1035
+ __decorateClass$x([
1036
1036
  property({ default: 1 })
1037
1037
  ], MainLoop.prototype, "speed");
1038
1038
 
1039
- const RECURSION_LIMIT$1 = 8;
1040
- const FLT_EPSILON$1 = 11920929e-14;
1041
- const PATH_DISTANCE_EPSILON$1 = 1;
1042
- function buildAdaptiveBezier(points, sX, sY, cp1x, cp1y, cp2x, cp2y, eX, eY, smoothness = 0.5) {
1043
- const scale = 1;
1044
- const smoothing = Math.min(
1045
- 0.99,
1046
- // a value of 1.0 actually inverts smoothing, so we cap it at 0.99
1047
- Math.max(0, smoothness)
1048
- );
1049
- let distanceTolerance = (PATH_DISTANCE_EPSILON$1 - smoothing) / scale;
1050
- distanceTolerance *= distanceTolerance;
1051
- begin$1(sX, sY, cp1x, cp1y, cp2x, cp2y, eX, eY, points, distanceTolerance);
1052
- return points;
1053
- }
1054
- function begin$1(sX, sY, cp1x, cp1y, cp2x, cp2y, eX, eY, points, distanceTolerance) {
1055
- recursive$1(sX, sY, cp1x, cp1y, cp2x, cp2y, eX, eY, points, distanceTolerance, 0);
1056
- points.push(eX, eY);
1057
- }
1058
- function recursive$1(x1, y1, x2, y2, x3, y3, x4, y4, points, distanceTolerance, level) {
1059
- if (level > RECURSION_LIMIT$1)
1060
- return;
1061
- const x12 = (x1 + x2) / 2;
1062
- const y12 = (y1 + y2) / 2;
1063
- const x23 = (x2 + x3) / 2;
1064
- const y23 = (y2 + y3) / 2;
1065
- const x34 = (x3 + x4) / 2;
1066
- const y34 = (y3 + y4) / 2;
1067
- const x123 = (x12 + x23) / 2;
1068
- const y123 = (y12 + y23) / 2;
1069
- const x234 = (x23 + x34) / 2;
1070
- const y234 = (y23 + y34) / 2;
1071
- const x1234 = (x123 + x234) / 2;
1072
- const y1234 = (y123 + y234) / 2;
1073
- if (level > 0) {
1074
- let dx = x4 - x1;
1075
- let dy = y4 - y1;
1076
- const d2 = Math.abs((x2 - x4) * dy - (y2 - y4) * dx);
1077
- const d3 = Math.abs((x3 - x4) * dy - (y3 - y4) * dx);
1078
- if (d2 > FLT_EPSILON$1 && d3 > FLT_EPSILON$1) {
1079
- if ((d2 + d3) * (d2 + d3) <= distanceTolerance * (dx * dx + dy * dy)) {
1080
- {
1081
- points.push(x1234, y1234);
1082
- return;
1083
- }
1039
+ class Vector extends EventEmitter {
1040
+ constructor(dim) {
1041
+ super();
1042
+ this.dim = dim;
1043
+ }
1044
+ _array = [];
1045
+ get length() {
1046
+ return this.dim;
1047
+ }
1048
+ _operate(operator, target, output) {
1049
+ const { dim: length, _array: array } = this;
1050
+ let targetArray;
1051
+ if (typeof target === "number") {
1052
+ targetArray = Array.from({ length }, () => target);
1053
+ } else if (target instanceof Matrix || target instanceof Vector) {
1054
+ targetArray = target.toArray();
1055
+ } else {
1056
+ targetArray = target;
1057
+ }
1058
+ let outputObject;
1059
+ let outputArray = [];
1060
+ if (!output) {
1061
+ outputObject = this;
1062
+ } else if (output instanceof Vector) {
1063
+ outputObject = output;
1064
+ } else {
1065
+ outputArray = output;
1066
+ }
1067
+ if (target instanceof Matrix) {
1068
+ const { cols } = target;
1069
+ switch (operator) {
1070
+ case "*":
1071
+ for (let x = 0; x < length; x++) {
1072
+ let val = 0;
1073
+ for (let y = 0; y < length; y++) {
1074
+ val += array[x] * targetArray[y * cols + x];
1075
+ }
1076
+ outputArray[x] = val;
1077
+ }
1078
+ break;
1079
+ default:
1080
+ throw new Error(`Not support operator in '${this.toName()} ${operator} ${target.toName()}'`);
1084
1081
  }
1085
- } else if (d2 > FLT_EPSILON$1) {
1086
- if (d2 * d2 <= distanceTolerance * (dx * dx + dy * dy)) {
1087
- {
1088
- points.push(x1234, y1234);
1089
- return;
1082
+ } else {
1083
+ switch (operator) {
1084
+ case "+":
1085
+ for (let i = 0; i < length; i++) {
1086
+ outputArray[i] = array[i] + targetArray[i];
1087
+ }
1088
+ break;
1089
+ case "-":
1090
+ for (let i = 0; i < length; i++) {
1091
+ outputArray[i] = array[i] - targetArray[i];
1092
+ }
1093
+ break;
1094
+ case "*":
1095
+ for (let i = 0; i < length; i++) {
1096
+ outputArray[i] = array[i] * targetArray[i];
1097
+ }
1098
+ break;
1099
+ case "/":
1100
+ for (let i = 0; i < length; i++) {
1101
+ outputArray[i] = array[i] / targetArray[i];
1102
+ }
1103
+ break;
1104
+ case "rot": {
1105
+ const c = Math.cos(targetArray[0]);
1106
+ const s = Math.sin(targetArray[0]);
1107
+ outputArray[0] = array[0] * c - array[1] * s;
1108
+ outputArray[1] = array[1] * c + array[0] * s;
1109
+ break;
1090
1110
  }
1091
- }
1092
- } else if (d3 > FLT_EPSILON$1) {
1093
- if (d3 * d3 <= distanceTolerance * (dx * dx + dy * dy)) {
1094
- {
1095
- points.push(x1234, y1234);
1096
- return;
1111
+ case "==": {
1112
+ let flag = true;
1113
+ for (let i = 0; i < length; i++) {
1114
+ flag = flag && array[i] === targetArray[i];
1115
+ }
1116
+ return flag;
1097
1117
  }
1118
+ case "=":
1119
+ for (let i = 0; i < length; i++) {
1120
+ const val = targetArray[i];
1121
+ if (val !== void 0) {
1122
+ array[i] = val;
1123
+ }
1124
+ }
1125
+ this._emitUpdate(array);
1126
+ return this;
1127
+ default:
1128
+ throw new Error(`Not support operator in '${this.toName()} ${operator} Vector'`);
1098
1129
  }
1099
- } else {
1100
- dx = x1234 - (x1 + x4) / 2;
1101
- dy = y1234 - (y1 + y4) / 2;
1102
- if (dx * dx + dy * dy <= distanceTolerance) {
1103
- points.push(x1234, y1234);
1104
- return;
1105
- }
1106
- }
1107
- }
1108
- recursive$1(x1, y1, x12, y12, x123, y123, x1234, y1234, points, distanceTolerance, level + 1);
1109
- recursive$1(x1234, y1234, x234, y234, x34, y34, x4, y4, points, distanceTolerance, level + 1);
1110
- }
1111
-
1112
- const RECURSION_LIMIT = 8;
1113
- const FLT_EPSILON = 11920929e-14;
1114
- const PATH_DISTANCE_EPSILON = 1;
1115
- function buildAdaptiveQuadratic(points, sX, sY, cp1x, cp1y, eX, eY, smoothness = 0.5) {
1116
- const scale = 1;
1117
- const smoothing = Math.min(
1118
- 0.99,
1119
- // a value of 1.0 actually inverts smoothing, so we cap it at 0.99
1120
- Math.max(0, smoothness)
1121
- );
1122
- let distanceTolerance = (PATH_DISTANCE_EPSILON - smoothing) / scale;
1123
- distanceTolerance *= distanceTolerance;
1124
- begin(sX, sY, cp1x, cp1y, eX, eY, points, distanceTolerance);
1125
- return points;
1126
- }
1127
- function begin(sX, sY, cp1x, cp1y, eX, eY, points, distanceTolerance) {
1128
- recursive(points, sX, sY, cp1x, cp1y, eX, eY, distanceTolerance, 0);
1129
- points.push(eX, eY);
1130
- }
1131
- function recursive(points, x1, y1, x2, y2, x3, y3, distanceTolerance, level) {
1132
- if (level > RECURSION_LIMIT)
1133
- return;
1134
- const x12 = (x1 + x2) / 2;
1135
- const y12 = (y1 + y2) / 2;
1136
- const x23 = (x2 + x3) / 2;
1137
- const y23 = (y2 + y3) / 2;
1138
- const x123 = (x12 + x23) / 2;
1139
- const y123 = (y12 + y23) / 2;
1140
- let dx = x3 - x1;
1141
- let dy = y3 - y1;
1142
- const d = Math.abs((x2 - x3) * dy - (y2 - y3) * dx);
1143
- if (d > FLT_EPSILON) {
1144
- if (d * d <= distanceTolerance * (dx * dx + dy * dy)) {
1145
- {
1146
- points.push(x123, y123);
1147
- return;
1148
- }
1149
- }
1150
- } else {
1151
- dx = x123 - (x1 + x3) / 2;
1152
- dy = y123 - (y1 + y3) / 2;
1153
- if (dx * dx + dy * dy <= distanceTolerance) {
1154
- points.push(x123, y123);
1155
- return;
1156
- }
1157
- }
1158
- recursive(points, x1, y1, x12, y12, x123, y123, distanceTolerance, level + 1);
1159
- recursive(points, x123, y123, x23, y23, x3, y3, distanceTolerance, level + 1);
1160
- }
1161
-
1162
- function buildArc(points, x, y, radius, start, end, clockwise, steps) {
1163
- let dist = Math.abs(start - end);
1164
- if (!clockwise && start > end) {
1165
- dist = 2 * Math.PI - dist;
1166
- } else if (clockwise && end > start) {
1167
- dist = 2 * Math.PI - dist;
1168
- }
1169
- steps = steps || Math.max(6, Math.floor(6 * radius ** (1 / 3) * (dist / Math.PI)));
1170
- steps = Math.max(steps, 3);
1171
- let f = dist / steps;
1172
- let t = start;
1173
- f *= clockwise ? -1 : 1;
1174
- for (let i = 0; i < steps + 1; i++) {
1175
- const cs = Math.cos(t);
1176
- const sn = Math.sin(t);
1177
- const nx = x + cs * radius;
1178
- const ny = y + sn * radius;
1179
- points.push(nx, ny);
1180
- t += f;
1181
- }
1182
- }
1183
-
1184
- function buildArcTo(points, x1, y1, x2, y2, radius) {
1185
- const fromX = points[points.length - 2];
1186
- const fromY = points[points.length - 1];
1187
- const a1 = fromY - y1;
1188
- const b1 = fromX - x1;
1189
- const a2 = y2 - y1;
1190
- const b2 = x2 - x1;
1191
- const mm = Math.abs(a1 * b2 - b1 * a2);
1192
- if (mm < 1e-8 || radius === 0) {
1193
- if (points[points.length - 2] !== x1 || points[points.length - 1] !== y1) {
1194
- points.push(x1, y1);
1195
- }
1196
- return;
1197
- }
1198
- const dd = a1 * a1 + b1 * b1;
1199
- const cc = a2 * a2 + b2 * b2;
1200
- const tt = a1 * a2 + b1 * b2;
1201
- const k1 = radius * Math.sqrt(dd) / mm;
1202
- const k2 = radius * Math.sqrt(cc) / mm;
1203
- const j1 = k1 * tt / dd;
1204
- const j2 = k2 * tt / cc;
1205
- const cx = k1 * b2 + k2 * b1;
1206
- const cy = k1 * a2 + k2 * a1;
1207
- const px = b1 * (k2 + j1);
1208
- const py = a1 * (k2 + j1);
1209
- const qx = b2 * (k1 + j2);
1210
- const qy = a2 * (k1 + j2);
1211
- const startAngle = Math.atan2(py - cy, px - cx);
1212
- const endAngle = Math.atan2(qy - cy, qx - cx);
1213
- buildArc(points, cx + x1, cy + y1, radius, startAngle, endAngle, b1 * a2 > b2 * a1);
1214
- }
1215
-
1216
- const TAU = Math.PI * 2;
1217
- const out = {
1218
- centerX: 0,
1219
- centerY: 0,
1220
- ang1: 0,
1221
- ang2: 0
1222
- };
1223
- function mapToEllipse({ x, y }, rx, ry, cosPhi, sinPhi, centerX, centerY, out2) {
1224
- x *= rx;
1225
- y *= ry;
1226
- const xp = cosPhi * x - sinPhi * y;
1227
- const yp = sinPhi * x + cosPhi * y;
1228
- out2.x = xp + centerX;
1229
- out2.y = yp + centerY;
1230
- return out2;
1231
- }
1232
- function approxUnitArc(ang1, ang2) {
1233
- const a1 = ang2 === -1.5707963267948966 ? -0.551915024494 : 4 / 3 * Math.tan(ang2 / 4);
1234
- const a = ang2 === 1.5707963267948966 ? 0.551915024494 : a1;
1235
- const x1 = Math.cos(ang1);
1236
- const y1 = Math.sin(ang1);
1237
- const x2 = Math.cos(ang1 + ang2);
1238
- const y2 = Math.sin(ang1 + ang2);
1239
- return [
1240
- {
1241
- x: x1 - y1 * a,
1242
- y: y1 + x1 * a
1243
- },
1244
- {
1245
- x: x2 + y2 * a,
1246
- y: y2 - x2 * a
1247
- },
1248
- {
1249
- x: x2,
1250
- y: y2
1251
1130
  }
1252
- ];
1253
- }
1254
- function vectorAngle(ux, uy, vx, vy) {
1255
- const sign = ux * vy - uy * vx < 0 ? -1 : 1;
1256
- let dot = ux * vx + uy * vy;
1257
- if (dot > 1) {
1258
- dot = 1;
1259
- }
1260
- if (dot < -1) {
1261
- dot = -1;
1262
- }
1263
- return sign * Math.acos(dot);
1264
- }
1265
- function getArcCenter(px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinPhi, cosPhi, pxp, pyp, out2) {
1266
- const rxSq = rx ** 2;
1267
- const rySq = ry ** 2;
1268
- const pxpSq = pxp ** 2;
1269
- const pypSq = pyp ** 2;
1270
- let radicant = rxSq * rySq - rxSq * pypSq - rySq * pxpSq;
1271
- if (radicant < 0) {
1272
- radicant = 0;
1273
- }
1274
- radicant /= rxSq * pypSq + rySq * pxpSq;
1275
- radicant = Math.sqrt(radicant) * (largeArcFlag === sweepFlag ? -1 : 1);
1276
- const centerXp = radicant * rx / ry * pyp;
1277
- const centerYp = radicant * -ry / rx * pxp;
1278
- const centerX = cosPhi * centerXp - sinPhi * centerYp + (px + cx) / 2;
1279
- const centerY = sinPhi * centerXp + cosPhi * centerYp + (py + cy) / 2;
1280
- const vx1 = (pxp - centerXp) / rx;
1281
- const vy1 = (pyp - centerYp) / ry;
1282
- const vx2 = (-pxp - centerXp) / rx;
1283
- const vy2 = (-pyp - centerYp) / ry;
1284
- const ang1 = vectorAngle(1, 0, vx1, vy1);
1285
- let ang2 = vectorAngle(vx1, vy1, vx2, vy2);
1286
- if (sweepFlag === 0 && ang2 > 0) {
1287
- ang2 -= TAU;
1288
- }
1289
- if (sweepFlag === 1 && ang2 < 0) {
1290
- ang2 += TAU;
1291
- }
1292
- out2.centerX = centerX;
1293
- out2.centerY = centerY;
1294
- out2.ang1 = ang1;
1295
- out2.ang2 = ang2;
1296
- }
1297
- function buildArcToSvg(points, px, py, cx, cy, rx, ry, xAxisRotation = 0, largeArcFlag = 0, sweepFlag = 0) {
1298
- if (rx === 0 || ry === 0) {
1299
- return;
1300
- }
1301
- const sinPhi = Math.sin(xAxisRotation * TAU / 360);
1302
- const cosPhi = Math.cos(xAxisRotation * TAU / 360);
1303
- const pxp = cosPhi * (px - cx) / 2 + sinPhi * (py - cy) / 2;
1304
- const pyp = -sinPhi * (px - cx) / 2 + cosPhi * (py - cy) / 2;
1305
- if (pxp === 0 && pyp === 0) {
1306
- return;
1307
- }
1308
- rx = Math.abs(rx);
1309
- ry = Math.abs(ry);
1310
- const lambda = pxp ** 2 / rx ** 2 + pyp ** 2 / ry ** 2;
1311
- if (lambda > 1) {
1312
- rx *= Math.sqrt(lambda);
1313
- ry *= Math.sqrt(lambda);
1314
- }
1315
- getArcCenter(px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinPhi, cosPhi, pxp, pyp, out);
1316
- let { ang1, ang2 } = out;
1317
- const { centerX, centerY } = out;
1318
- let ratio = Math.abs(ang2) / (TAU / 4);
1319
- if (Math.abs(1 - ratio) < 1e-7) {
1320
- ratio = 1;
1321
- }
1322
- const segments = Math.max(Math.ceil(ratio), 1);
1323
- ang2 /= segments;
1324
- let lastX = points[points.length - 2];
1325
- let lastY = points[points.length - 1];
1326
- const outCurvePoint = { x: 0, y: 0 };
1327
- for (let i = 0; i < segments; i++) {
1328
- const curve = approxUnitArc(ang1, ang2);
1329
- const { x: x1, y: y1 } = mapToEllipse(curve[0], rx, ry, cosPhi, sinPhi, centerX, centerY, outCurvePoint);
1330
- const { x: x2, y: y2 } = mapToEllipse(curve[1], rx, ry, cosPhi, sinPhi, centerX, centerY, outCurvePoint);
1331
- const { x, y } = mapToEllipse(curve[2], rx, ry, cosPhi, sinPhi, centerX, centerY, outCurvePoint);
1332
- buildAdaptiveBezier(points, lastX, lastY, x1, y1, x2, y2, x, y);
1333
- lastX = x;
1334
- lastY = y;
1335
- ang1 += ang2;
1336
- }
1337
- }
1338
-
1339
- class Circle {
1340
- constructor(x = 0, y = 0, radius = 0) {
1341
- this.x = x;
1342
- this.y = y;
1343
- this.radius = radius;
1344
- }
1345
- contains(x, y) {
1346
- if (this.radius <= 0)
1347
- return false;
1348
- const r2 = this.radius * this.radius;
1349
- let dx = this.x - x;
1350
- let dy = this.y - y;
1351
- dx *= dx;
1352
- dy *= dy;
1353
- return dx + dy <= r2;
1354
- }
1355
- strokeContains(x, y, width) {
1356
- if (this.radius === 0)
1357
- return false;
1358
- const dx = this.x - x;
1359
- const dy = this.y - y;
1360
- const r = this.radius;
1361
- const w2 = width / 2;
1362
- const distance = Math.sqrt(dx * dx + dy * dy);
1363
- return distance < r + w2 && distance > r - w2;
1364
- }
1365
- clone() {
1366
- return new Circle(this.x, this.y, this.radius);
1367
- }
1368
- copyFrom(circle) {
1369
- this.x = circle.x;
1370
- this.y = circle.y;
1371
- this.radius = circle.radius;
1372
- return this;
1131
+ return outputObject?.set(outputArray) ?? outputArray;
1373
1132
  }
1374
- copyTo(circle) {
1375
- circle.copyFrom(this);
1376
- return circle;
1133
+ add(value, output) {
1134
+ return this._operate("+", value, output);
1377
1135
  }
1378
- getBounds(out) {
1379
- out = out || new Rectangle();
1380
- out.x = this.x - this.radius;
1381
- out.y = this.y - this.radius;
1382
- out.width = this.radius * 2;
1383
- out.height = this.radius * 2;
1384
- return out;
1136
+ sub(value, output) {
1137
+ return this._operate("-", value, output);
1385
1138
  }
1386
- buildOutline(points) {
1387
- buildCircle.build(this, points);
1139
+ multiply(value, output) {
1140
+ return this._operate("*", value, output);
1388
1141
  }
1389
- buildGeometry(vertices, indices) {
1390
- const points = [];
1391
- this.buildOutline(points);
1392
- buildCircle.triangulate(points, vertices, 2, 0, indices, 0);
1142
+ divide(value, output) {
1143
+ return this._operate("/", value, output);
1393
1144
  }
1394
- }
1395
-
1396
- class Ellipse {
1397
- constructor(x = 0, y = 0, halfWidth = 0, halfHeight = 0) {
1398
- this.x = x;
1399
- this.y = y;
1400
- this.halfWidth = halfWidth;
1401
- this.halfHeight = halfHeight;
1145
+ rotate(angle) {
1146
+ return this._operate("rot", angle);
1402
1147
  }
1403
- contains(x, y) {
1404
- if (this.halfWidth <= 0 || this.halfHeight <= 0) {
1405
- return false;
1148
+ set(value, ...args) {
1149
+ if (args.length && typeof value === "number") {
1150
+ value = [value, ...args];
1406
1151
  }
1407
- let normx = (x - this.x) / this.halfWidth;
1408
- let normy = (y - this.y) / this.halfHeight;
1409
- normx *= normx;
1410
- normy *= normy;
1411
- return normx + normy <= 1;
1152
+ return this._operate("=", value);
1412
1153
  }
1413
- strokeContains(x, y, width) {
1414
- const { halfWidth, halfHeight } = this;
1415
- if (halfWidth <= 0 || halfHeight <= 0) {
1416
- return false;
1417
- }
1418
- const halfStrokeWidth = width / 2;
1419
- const innerA = halfWidth - halfStrokeWidth;
1420
- const innerB = halfHeight - halfStrokeWidth;
1421
- const outerA = halfWidth + halfStrokeWidth;
1422
- const outerB = halfHeight + halfStrokeWidth;
1423
- const normalizedX = x - this.x;
1424
- const normalizedY = y - this.y;
1425
- const innerEllipse = normalizedX * normalizedX / (innerA * innerA) + normalizedY * normalizedY / (innerB * innerB);
1426
- const outerEllipse = normalizedX * normalizedX / (outerA * outerA) + normalizedY * normalizedY / (outerB * outerB);
1427
- return innerEllipse > 1 && outerEllipse <= 1;
1154
+ equals(value) {
1155
+ return this._operate("==", value);
1428
1156
  }
1429
1157
  clone() {
1430
- return new Ellipse(this.x, this.y, this.halfWidth, this.halfHeight);
1158
+ const cloned = new this.constructor();
1159
+ cloned.set(this.toArray());
1160
+ return cloned;
1431
1161
  }
1432
- copyFrom(ellipse) {
1433
- this.x = ellipse.x;
1434
- this.y = ellipse.y;
1435
- this.halfWidth = ellipse.halfWidth;
1436
- this.halfHeight = ellipse.halfHeight;
1162
+ onUpdate(callback) {
1163
+ this.on("update", callback);
1437
1164
  return this;
1438
1165
  }
1439
- copyTo(ellipse) {
1440
- ellipse.copyFrom(this);
1441
- return ellipse;
1442
- }
1443
- getBounds() {
1444
- return new Rectangle(this.x - this.halfWidth, this.y - this.halfHeight, this.halfWidth * 2, this.halfHeight * 2);
1445
- }
1446
- buildOutline(points) {
1447
- buildCircle.build(this, points);
1448
- }
1449
- buildGeometry(vertices, indices) {
1450
- const points = [];
1451
- this.buildOutline(points);
1452
- buildCircle.triangulate(points, vertices, 2, 0, indices, 0);
1453
- }
1454
- }
1455
-
1456
- function squaredDistanceToLineSegment(x, y, x1, y1, x2, y2) {
1457
- const a = x - x1;
1458
- const b = y - y1;
1459
- const c = x2 - x1;
1460
- const d = y2 - y1;
1461
- const dot = a * c + b * d;
1462
- const lenSq = c * c + d * d;
1463
- let param = -1;
1464
- if (lenSq !== 0) {
1465
- param = dot / lenSq;
1466
- }
1467
- let xx;
1468
- let yy;
1469
- if (param < 0) {
1470
- xx = x1;
1471
- yy = y1;
1472
- } else if (param > 1) {
1473
- xx = x2;
1474
- yy = y2;
1475
- } else {
1476
- xx = x1 + param * c;
1477
- yy = y1 + param * d;
1478
- }
1479
- const dx = x - xx;
1480
- const dy = y - yy;
1481
- return dx * dx + dy * dy;
1482
- }
1483
- class Triangle {
1484
- constructor(x = 0, y = 0, x2 = 0, y2 = 0, x3 = 0, y3 = 0) {
1485
- this.x = x;
1486
- this.y = y;
1487
- this.x2 = x2;
1488
- this.y2 = y2;
1489
- this.x3 = x3;
1490
- this.y3 = y3;
1491
- }
1492
- contains(x, y) {
1493
- const s = (this.x - this.x3) * (y - this.y3) - (this.y - this.y3) * (x - this.x3);
1494
- const t = (this.x2 - this.x) * (y - this.y) - (this.y2 - this.y) * (x - this.x);
1495
- if (s < 0 !== t < 0 && s !== 0 && t !== 0)
1496
- return false;
1497
- const d = (this.x3 - this.x2) * (y - this.y2) - (this.y3 - this.y2) * (x - this.x2);
1498
- return d === 0 || d < 0 === s + t <= 0;
1499
- }
1500
- strokeContains(pointX, pointY, strokeWidth) {
1501
- const halfStrokeWidth = strokeWidth / 2;
1502
- const halfStrokeWidthSquared = halfStrokeWidth * halfStrokeWidth;
1503
- const { x, x2, x3, y, y2, y3 } = this;
1504
- if (squaredDistanceToLineSegment(pointX, pointY, x, y, x2, y3) <= halfStrokeWidthSquared || squaredDistanceToLineSegment(pointX, pointY, x2, y2, x3, y3) <= halfStrokeWidthSquared || squaredDistanceToLineSegment(pointX, pointY, x3, y3, x, y) <= halfStrokeWidthSquared) {
1505
- return true;
1506
- }
1507
- return false;
1508
- }
1509
- clone() {
1510
- return new Triangle(this.x, this.y, this.x2, this.y2, this.x3, this.y3);
1511
- }
1512
- copyFrom(triangle) {
1513
- this.x = triangle.x;
1514
- this.y = triangle.y;
1515
- this.x2 = triangle.x2;
1516
- this.y2 = triangle.y2;
1517
- this.x3 = triangle.x3;
1518
- this.y3 = triangle.y3;
1166
+ offUpdate(callback) {
1167
+ this.off("update", callback);
1519
1168
  return this;
1520
1169
  }
1521
- copyTo(triangle) {
1522
- triangle.copyFrom(this);
1523
- return triangle;
1170
+ _emitUpdate(array) {
1171
+ this._onUpdate(array);
1172
+ this.emit("update", array);
1524
1173
  }
1525
- getBounds(out) {
1526
- out = out || new Rectangle();
1527
- const minX = Math.min(this.x, this.x2, this.x3);
1528
- const maxX = Math.max(this.x, this.x2, this.x3);
1529
- const minY = Math.min(this.y, this.y2, this.y3);
1530
- const maxY = Math.max(this.y, this.y2, this.y3);
1531
- out.x = minX;
1532
- out.y = minY;
1533
- out.width = maxX - minX;
1534
- out.height = maxY - minY;
1535
- return out;
1174
+ _onUpdate(_array) {
1536
1175
  }
1537
- buildOutline(points) {
1538
- buildTriangle.build(this, points);
1176
+ toArray() {
1177
+ return this._array.slice();
1539
1178
  }
1540
- buildGeometry(vertices, indices) {
1541
- const points = [];
1542
- this.buildOutline(points);
1543
- buildTriangle.triangulate(points, vertices, 2, 0, indices, 0);
1179
+ toName() {
1180
+ return `Vector${this.dim}`;
1544
1181
  }
1545
1182
  }
1546
1183
 
1547
- class Polygon {
1548
- points;
1549
- closed;
1550
- get lastX() {
1551
- return this.points[this.points.length - 2];
1552
- }
1553
- get lastY() {
1554
- return this.points[this.points.length - 1];
1555
- }
1556
- get x() {
1557
- return this.points[this.points.length - 2];
1558
- }
1559
- get y() {
1560
- return this.points[this.points.length - 1];
1561
- }
1562
- constructor(...points) {
1563
- let flat = Array.isArray(points[0]) ? points[0] : points;
1564
- if (typeof flat[0] !== "number") {
1565
- const p = [];
1566
- for (let i = 0, il = flat.length; i < il; i++) {
1567
- p.push(flat[i].x, flat[i].y);
1568
- }
1569
- flat = p;
1184
+ class Matrix extends EventEmitter {
1185
+ constructor(rows, cols, array) {
1186
+ super();
1187
+ this.rows = rows;
1188
+ this.cols = cols;
1189
+ if (array) {
1190
+ this.set(array);
1191
+ } else {
1192
+ this.identity();
1570
1193
  }
1571
- this.points = flat;
1572
- this.closed = true;
1573
1194
  }
1574
- reset() {
1575
- this.points.length = 0;
1576
- return this;
1195
+ _array = [];
1196
+ get length() {
1197
+ return this.cols * this.rows;
1577
1198
  }
1578
- contains(x, y) {
1579
- let inside = false;
1580
- const length = this.points.length / 2;
1581
- for (let i = 0, j = length - 1; i < length; j = i++) {
1582
- const xi = this.points[i * 2];
1583
- const yi = this.points[i * 2 + 1];
1584
- const xj = this.points[j * 2];
1585
- const yj = this.points[j * 2 + 1];
1586
- const intersect = yi > y !== yj > y && x < (xj - xi) * ((y - yi) / (yj - yi)) + xi;
1587
- if (intersect) {
1588
- inside = !inside;
1589
- }
1590
- }
1591
- return inside;
1592
- }
1593
- strokeContains(x, y, strokeWidth) {
1594
- const halfStrokeWidth = strokeWidth / 2;
1595
- const halfStrokeWidthSqrd = halfStrokeWidth * halfStrokeWidth;
1596
- const { points } = this;
1597
- const iterationLength = points.length - (this.closed ? 0 : 2);
1598
- for (let i = 0; i < iterationLength; i += 2) {
1599
- const x1 = points[i];
1600
- const y1 = points[i + 1];
1601
- const x2 = points[(i + 2) % points.length];
1602
- const y2 = points[(i + 3) % points.length];
1603
- const distanceSqrd = squaredDistanceToLineSegment(x, y, x1, y1, x2, y2);
1604
- if (distanceSqrd <= halfStrokeWidthSqrd) {
1605
- return true;
1606
- }
1607
- }
1608
- return false;
1609
- }
1610
- clone() {
1611
- const points = this.points.slice();
1612
- const polygon = new Polygon(points);
1613
- polygon.closed = this.closed;
1614
- return polygon;
1615
- }
1616
- copyFrom(polygon) {
1617
- this.points = polygon.points.slice();
1618
- this.closed = polygon.closed;
1619
- return this;
1620
- }
1621
- copyTo(polygon) {
1622
- polygon.copyFrom(this);
1623
- return polygon;
1624
- }
1625
- getBounds(out) {
1626
- out = out || new Rectangle();
1627
- const points = this.points;
1628
- let minX = Infinity;
1629
- let maxX = -Infinity;
1630
- let minY = Infinity;
1631
- let maxY = -Infinity;
1632
- for (let i = 0, n = points.length; i < n; i += 2) {
1633
- const x = points[i];
1634
- const y = points[i + 1];
1635
- minX = x < minX ? x : minX;
1636
- maxX = x > maxX ? x : maxX;
1637
- minY = y < minY ? y : minY;
1638
- maxY = y > maxY ? y : maxY;
1639
- }
1640
- out.x = minX;
1641
- out.width = maxX - minX;
1642
- out.y = minY;
1643
- out.height = maxY - minY;
1644
- return out;
1645
- }
1646
- buildOutline(points) {
1647
- buildPolygon.build(this, points);
1648
- }
1649
- buildGeometry(vertices, indices) {
1650
- const points = [];
1651
- this.buildOutline(points);
1652
- buildPolygon.triangulate(points, vertices, 2, 0, indices, 0);
1653
- }
1654
- }
1655
-
1656
- function isCornerWithinStroke(pX, pY, cornerX, cornerY, radius, halfStrokeWidth) {
1657
- const dx = pX - cornerX;
1658
- const dy = pY - cornerY;
1659
- const distance = Math.sqrt(dx * dx + dy * dy);
1660
- return distance >= radius - halfStrokeWidth && distance <= radius + halfStrokeWidth;
1661
- }
1662
- class RoundedRectangle {
1663
- constructor(x = 0, y = 0, width = 0, height = 0, radius = width / 4) {
1664
- this.x = x;
1665
- this.y = y;
1666
- this.width = width;
1667
- this.height = height;
1668
- this.radius = radius;
1669
- }
1670
- getBounds(out) {
1671
- out = out || new Rectangle();
1672
- out.x = this.x;
1673
- out.y = this.y;
1674
- out.width = this.width;
1675
- out.height = this.height;
1676
- return out;
1677
- }
1678
- clone() {
1679
- return new RoundedRectangle(this.x, this.y, this.width, this.height, this.radius);
1680
- }
1681
- copyFrom(rectangle) {
1682
- this.x = rectangle.x;
1683
- this.y = rectangle.y;
1684
- this.width = rectangle.width;
1685
- this.height = rectangle.height;
1686
- return this;
1687
- }
1688
- copyTo(rectangle) {
1689
- rectangle.copyFrom(this);
1690
- return rectangle;
1691
- }
1692
- contains(x, y) {
1693
- if (this.width <= 0 || this.height <= 0) {
1694
- return false;
1695
- }
1696
- if (x >= this.x && x <= this.x + this.width) {
1697
- if (y >= this.y && y <= this.y + this.height) {
1698
- const radius = Math.max(0, Math.min(this.radius, Math.min(this.width, this.height) / 2));
1699
- if (y >= this.y + radius && y <= this.y + this.height - radius || x >= this.x + radius && x <= this.x + this.width - radius) {
1700
- return true;
1701
- }
1702
- let dx = x - (this.x + radius);
1703
- let dy = y - (this.y + radius);
1704
- const radius2 = radius * radius;
1705
- if (dx * dx + dy * dy <= radius2) {
1706
- return true;
1707
- }
1708
- dx = x - (this.x + this.width - radius);
1709
- if (dx * dx + dy * dy <= radius2) {
1710
- return true;
1711
- }
1712
- dy = y - (this.y + this.height - radius);
1713
- if (dx * dx + dy * dy <= radius2) {
1714
- return true;
1715
- }
1716
- dx = x - (this.x + radius);
1717
- if (dx * dx + dy * dy <= radius2) {
1718
- return true;
1719
- }
1720
- }
1721
- }
1722
- return false;
1723
- }
1724
- strokeContains(pX, pY, strokeWidth) {
1725
- const { x, y, width, height, radius } = this;
1726
- const halfStrokeWidth = strokeWidth / 2;
1727
- const innerX = x + radius;
1728
- const innerY = y + radius;
1729
- const innerWidth = width - radius * 2;
1730
- const innerHeight = height - radius * 2;
1731
- const rightBound = x + width;
1732
- const bottomBound = y + height;
1733
- if ((pX >= x - halfStrokeWidth && pX <= x + halfStrokeWidth || pX >= rightBound - halfStrokeWidth && pX <= rightBound + halfStrokeWidth) && pY >= innerY && pY <= innerY + innerHeight) {
1734
- return true;
1735
- }
1736
- if ((pY >= y - halfStrokeWidth && pY <= y + halfStrokeWidth || pY >= bottomBound - halfStrokeWidth && pY <= bottomBound + halfStrokeWidth) && pX >= innerX && pX <= innerX + innerWidth) {
1737
- return true;
1738
- }
1739
- return (
1740
- // Top-left
1741
- pX < innerX && pY < innerY && isCornerWithinStroke(pX, pY, innerX, innerY, radius, halfStrokeWidth) || pX > rightBound - radius && pY < innerY && isCornerWithinStroke(pX, pY, rightBound - radius, innerY, radius, halfStrokeWidth) || pX > rightBound - radius && pY > bottomBound - radius && isCornerWithinStroke(pX, pY, rightBound - radius, bottomBound - radius, radius, halfStrokeWidth) || pX < innerX && pY > bottomBound - radius && isCornerWithinStroke(pX, pY, innerX, bottomBound - radius, radius, halfStrokeWidth)
1742
- );
1743
- }
1744
- buildOutline(points) {
1745
- buildCircle.build(this, points);
1746
- }
1747
- buildGeometry(vertices, indices) {
1748
- const points = [];
1749
- this.buildOutline(points);
1750
- buildCircle.triangulate(points, vertices, 2, 0, indices, 0);
1751
- }
1752
- }
1753
-
1754
- class Star extends Polygon {
1755
- constructor(x = 0, y = 0, points = 5, radius = 1, innerRadius, rotation = 0) {
1756
- innerRadius = innerRadius || radius / 2;
1757
- const startAngle = -1 * Math.PI / 2 + rotation;
1758
- const len = points * 2;
1759
- const delta = PI_2 / len;
1760
- const polygon = [];
1761
- for (let i = 0; i < len; i++) {
1762
- const r = i % 2 ? innerRadius : radius;
1763
- const angle = i * delta + startAngle;
1764
- polygon.push(
1765
- x + r * Math.cos(angle),
1766
- y + r * Math.sin(angle)
1767
- );
1768
- }
1769
- super(polygon);
1770
- }
1771
- }
1772
-
1773
- const buildCircle = {
1774
- build(shape, points) {
1775
- let x;
1776
- let y;
1777
- let dx;
1778
- let dy;
1779
- let rx;
1780
- let ry;
1781
- if (shape instanceof Circle) {
1782
- x = shape.x;
1783
- y = shape.y;
1784
- rx = ry = shape.radius;
1785
- dx = dy = 0;
1786
- } else if (shape instanceof Ellipse) {
1787
- x = shape.x;
1788
- y = shape.y;
1789
- rx = shape.halfWidth;
1790
- ry = shape.halfHeight;
1791
- dx = dy = 0;
1792
- } else {
1793
- const roundedRect = shape;
1794
- const halfWidth = roundedRect.width / 2;
1795
- const halfHeight = roundedRect.height / 2;
1796
- x = roundedRect.x + halfWidth;
1797
- y = roundedRect.y + halfHeight;
1798
- rx = ry = Math.max(0, Math.min(roundedRect.radius, Math.min(halfWidth, halfHeight)));
1799
- dx = halfWidth - rx;
1800
- dy = halfHeight - ry;
1801
- }
1802
- if (!(rx >= 0 && ry >= 0 && dx >= 0 && dy >= 0)) {
1803
- return points;
1804
- }
1805
- const n = Math.ceil(2.3 * Math.sqrt(rx + ry));
1806
- const m = n * 8 + (dx ? 4 : 0) + (dy ? 4 : 0);
1807
- if (m === 0) {
1808
- return points;
1809
- }
1810
- if (n === 0) {
1811
- points[0] = points[6] = x + dx;
1812
- points[1] = points[3] = y + dy;
1813
- points[2] = points[4] = x - dx;
1814
- points[5] = points[7] = y - dy;
1815
- return points;
1816
- }
1817
- let j1 = 0;
1818
- let j2 = n * 4 + (dx ? 2 : 0) + 2;
1819
- let j3 = j2;
1820
- let j4 = m;
1821
- let x0 = dx + rx;
1822
- let y0 = dy;
1823
- let x1 = x + x0;
1824
- let x2 = x - x0;
1825
- let y1 = y + y0;
1826
- points[j1++] = x1;
1827
- points[j1++] = y1;
1828
- points[--j2] = y1;
1829
- points[--j2] = x2;
1830
- if (dy) {
1831
- const y22 = y - y0;
1832
- points[j3++] = x2;
1833
- points[j3++] = y22;
1834
- points[--j4] = y22;
1835
- points[--j4] = x1;
1836
- }
1837
- for (let i = 1; i < n; i++) {
1838
- const a = Math.PI / 2 * (i / n);
1839
- const x02 = dx + Math.cos(a) * rx;
1840
- const y02 = dy + Math.sin(a) * ry;
1841
- const x12 = x + x02;
1842
- const x22 = x - x02;
1843
- const y12 = y + y02;
1844
- const y22 = y - y02;
1845
- points[j1++] = x12;
1846
- points[j1++] = y12;
1847
- points[--j2] = y12;
1848
- points[--j2] = x22;
1849
- points[j3++] = x22;
1850
- points[j3++] = y22;
1851
- points[--j4] = y22;
1852
- points[--j4] = x12;
1853
- }
1854
- x0 = dx;
1855
- y0 = dy + ry;
1856
- x1 = x + x0;
1857
- x2 = x - x0;
1858
- y1 = y + y0;
1859
- const y2 = y - y0;
1860
- points[j1++] = x1;
1861
- points[j1++] = y1;
1862
- points[--j4] = y2;
1863
- points[--j4] = x1;
1864
- if (dx) {
1865
- points[j1++] = x2;
1866
- points[j1++] = y1;
1867
- points[--j4] = y2;
1868
- points[--j4] = x2;
1869
- }
1870
- return points;
1871
- },
1872
- triangulate(points, vertices, verticesStride, verticesOffset, indices, indicesOffset) {
1873
- if (points.length === 0) {
1874
- return;
1875
- }
1876
- let centerX = 0;
1877
- let centerY = 0;
1878
- for (let i = 0; i < points.length; i += 2) {
1879
- centerX += points[i];
1880
- centerY += points[i + 1];
1881
- }
1882
- centerX /= points.length / 2;
1883
- centerY /= points.length / 2;
1884
- let count = verticesOffset;
1885
- vertices[count * verticesStride] = centerX;
1886
- vertices[count * verticesStride + 1] = centerY;
1887
- const centerIndex = count++;
1888
- for (let i = 0; i < points.length; i += 2) {
1889
- vertices[count * verticesStride] = points[i];
1890
- vertices[count * verticesStride + 1] = points[i + 1];
1891
- if (i > 0) {
1892
- indices[indicesOffset++] = count;
1893
- indices[indicesOffset++] = centerIndex;
1894
- indices[indicesOffset++] = count - 1;
1895
- }
1896
- count++;
1897
- }
1898
- indices[indicesOffset++] = centerIndex + 1;
1899
- indices[indicesOffset++] = centerIndex;
1900
- indices[indicesOffset++] = count - 1;
1901
- }
1902
- };
1903
-
1904
- class Point {
1905
- constructor(x = 0, y = 0) {
1906
- this.x = x;
1907
- this.y = y;
1908
- }
1909
- static _shared;
1910
- static get shared() {
1911
- const point = this._shared ?? new Point();
1912
- point.x = 0;
1913
- point.y = 0;
1914
- return point;
1915
- }
1916
- copyFrom(p) {
1917
- this.set(p.x, p.y);
1918
- return this;
1919
- }
1920
- copyTo(p) {
1921
- p.set(this.x, this.y);
1922
- return p;
1923
- }
1924
- equals(p) {
1925
- return p.x === this.x && p.y === this.y;
1926
- }
1927
- set(x = 0, y = x) {
1928
- this.x = x;
1929
- this.y = y;
1930
- return this;
1931
- }
1932
- }
1933
-
1934
- function getOrientationOfPoints(points) {
1935
- const m = points.length;
1936
- if (m < 6) {
1937
- return 1;
1938
- }
1939
- let area = 0;
1940
- for (let i = 0, x1 = points[m - 2], y1 = points[m - 1]; i < m; i += 2) {
1941
- const x2 = points[i];
1942
- const y2 = points[i + 1];
1943
- area += (x2 - x1) * (y2 + y1);
1944
- x1 = x2;
1945
- y1 = y2;
1946
- }
1947
- if (area < 0) {
1948
- return -1;
1949
- }
1950
- return 1;
1951
- }
1952
-
1953
- function triangulateWithHoles(points, holes, vertices, verticesStride, verticesOffset, indices, indicesOffset) {
1954
- const triangles = earcut__default(points, holes, 2);
1955
- if (!triangles) {
1956
- return;
1957
- }
1958
- for (let i = 0; i < triangles.length; i += 3) {
1959
- indices[indicesOffset++] = triangles[i] + verticesOffset;
1960
- indices[indicesOffset++] = triangles[i + 1] + verticesOffset;
1961
- indices[indicesOffset++] = triangles[i + 2] + verticesOffset;
1962
- }
1963
- let index = verticesOffset * verticesStride;
1964
- for (let i = 0; i < points.length; i += 2) {
1965
- vertices[index] = points[i];
1966
- vertices[index + 1] = points[i + 1];
1967
- index += verticesStride;
1968
- }
1969
- }
1970
-
1971
- const closePointEps = 1e-4;
1972
- const curveEps = 1e-4;
1973
- function square(x, y, nx, ny, innerWeight, outerWeight, clockwise, verts) {
1974
- const ix = x - nx * innerWeight;
1975
- const iy = y - ny * innerWeight;
1976
- const ox = x + nx * outerWeight;
1977
- const oy = y + ny * outerWeight;
1978
- let exx;
1979
- let eyy;
1980
- if (clockwise) {
1981
- exx = ny;
1982
- eyy = -nx;
1983
- } else {
1984
- exx = -ny;
1985
- eyy = nx;
1986
- }
1987
- const eix = ix + exx;
1988
- const eiy = iy + eyy;
1989
- const eox = ox + exx;
1990
- const eoy = oy + eyy;
1991
- verts.push(eix, eiy);
1992
- verts.push(eox, eoy);
1993
- return 2;
1994
- }
1995
- function round(cx, cy, sx, sy, ex, ey, verts, clockwise) {
1996
- const cx2p0x = sx - cx;
1997
- const cy2p0y = sy - cy;
1998
- let angle0 = Math.atan2(cx2p0x, cy2p0y);
1999
- let angle1 = Math.atan2(ex - cx, ey - cy);
2000
- if (clockwise && angle0 < angle1) {
2001
- angle0 += Math.PI * 2;
2002
- } else if (!clockwise && angle0 > angle1) {
2003
- angle1 += Math.PI * 2;
2004
- }
2005
- let startAngle = angle0;
2006
- const angleDiff = angle1 - angle0;
2007
- const absAngleDiff = Math.abs(angleDiff);
2008
- const radius = Math.sqrt(cx2p0x * cx2p0x + cy2p0y * cy2p0y);
2009
- const segCount = (15 * absAngleDiff * Math.sqrt(radius) / Math.PI >> 0) + 1;
2010
- const angleInc = angleDiff / segCount;
2011
- startAngle += angleInc;
2012
- if (clockwise) {
2013
- verts.push(cx, cy);
2014
- verts.push(sx, sy);
2015
- for (let i = 1, angle = startAngle; i < segCount; i++, angle += angleInc) {
2016
- verts.push(cx, cy);
2017
- verts.push(cx + Math.sin(angle) * radius, cy + Math.cos(angle) * radius);
2018
- }
2019
- verts.push(cx, cy);
2020
- verts.push(ex, ey);
2021
- } else {
2022
- verts.push(sx, sy);
2023
- verts.push(cx, cy);
2024
- for (let i = 1, angle = startAngle; i < segCount; i++, angle += angleInc) {
2025
- verts.push(cx + Math.sin(angle) * radius, cy + Math.cos(angle) * radius);
2026
- verts.push(cx, cy);
2027
- }
2028
- verts.push(ex, ey);
2029
- verts.push(cx, cy);
2030
- }
2031
- return segCount * 2;
2032
- }
2033
- function buildLine(points, lineStyle, flipAlignment, closed, vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
2034
- const eps = closePointEps;
2035
- if (points.length === 0) {
2036
- return;
2037
- }
2038
- const style = lineStyle;
2039
- let alignment = style.alignment;
2040
- if (lineStyle.alignment !== 0.5) {
2041
- let orientation = getOrientationOfPoints(points);
2042
- if (flipAlignment)
2043
- orientation *= -1;
2044
- alignment = (alignment - 0.5) * orientation + 0.5;
2045
- }
2046
- const firstPoint = new Point(points[0], points[1]);
2047
- const lastPoint = new Point(points[points.length - 2], points[points.length - 1]);
2048
- const closedShape = closed;
2049
- const closedPath = Math.abs(firstPoint.x - lastPoint.x) < eps && Math.abs(firstPoint.y - lastPoint.y) < eps;
2050
- if (closedShape) {
2051
- points = points.slice();
2052
- if (closedPath) {
2053
- points.pop();
2054
- points.pop();
2055
- lastPoint.set(points[points.length - 2], points[points.length - 1]);
2056
- }
2057
- const midPointX = (firstPoint.x + lastPoint.x) * 0.5;
2058
- const midPointY = (lastPoint.y + firstPoint.y) * 0.5;
2059
- points.unshift(midPointX, midPointY);
2060
- points.push(midPointX, midPointY);
2061
- }
2062
- const verts = vertices;
2063
- const length = points.length / 2;
2064
- let indexCount = points.length;
2065
- const indexStart = verts.length / 2;
2066
- const width = style.width / 2;
2067
- const widthSquared = width * width;
2068
- const miterLimitSquared = style.miterLimit * style.miterLimit;
2069
- let x0 = points[0];
2070
- let y0 = points[1];
2071
- let x1 = points[2];
2072
- let y1 = points[3];
2073
- let x2 = 0;
2074
- let y2 = 0;
2075
- let perpX = -(y0 - y1);
2076
- let perpY = x0 - x1;
2077
- let perp1x = 0;
2078
- let perp1y = 0;
2079
- let dist = Math.sqrt(perpX * perpX + perpY * perpY);
2080
- perpX /= dist;
2081
- perpY /= dist;
2082
- perpX *= width;
2083
- perpY *= width;
2084
- const ratio = alignment;
2085
- const innerWeight = (1 - ratio) * 2;
2086
- const outerWeight = ratio * 2;
2087
- if (!closedShape) {
2088
- if (style.cap === "round") {
2089
- indexCount += round(
2090
- x0 - perpX * (innerWeight - outerWeight) * 0.5,
2091
- y0 - perpY * (innerWeight - outerWeight) * 0.5,
2092
- x0 - perpX * innerWeight,
2093
- y0 - perpY * innerWeight,
2094
- x0 + perpX * outerWeight,
2095
- y0 + perpY * outerWeight,
2096
- verts,
2097
- true
2098
- ) + 2;
2099
- } else if (style.cap === "square") {
2100
- indexCount += square(x0, y0, perpX, perpY, innerWeight, outerWeight, true, verts);
2101
- }
2102
- }
2103
- verts.push(
2104
- x0 - perpX * innerWeight,
2105
- y0 - perpY * innerWeight
2106
- );
2107
- verts.push(
2108
- x0 + perpX * outerWeight,
2109
- y0 + perpY * outerWeight
2110
- );
2111
- for (let i = 1; i < length - 1; ++i) {
2112
- x0 = points[(i - 1) * 2];
2113
- y0 = points[(i - 1) * 2 + 1];
2114
- x1 = points[i * 2];
2115
- y1 = points[i * 2 + 1];
2116
- x2 = points[(i + 1) * 2];
2117
- y2 = points[(i + 1) * 2 + 1];
2118
- perpX = -(y0 - y1);
2119
- perpY = x0 - x1;
2120
- dist = Math.sqrt(perpX * perpX + perpY * perpY);
2121
- perpX /= dist;
2122
- perpY /= dist;
2123
- perpX *= width;
2124
- perpY *= width;
2125
- perp1x = -(y1 - y2);
2126
- perp1y = x1 - x2;
2127
- dist = Math.sqrt(perp1x * perp1x + perp1y * perp1y);
2128
- perp1x /= dist;
2129
- perp1y /= dist;
2130
- perp1x *= width;
2131
- perp1y *= width;
2132
- const dx0 = x1 - x0;
2133
- const dy0 = y0 - y1;
2134
- const dx1 = x1 - x2;
2135
- const dy1 = y2 - y1;
2136
- const dot = dx0 * dx1 + dy0 * dy1;
2137
- const cross = dy0 * dx1 - dy1 * dx0;
2138
- const clockwise = cross < 0;
2139
- if (Math.abs(cross) < 1e-3 * Math.abs(dot)) {
2140
- verts.push(
2141
- x1 - perpX * innerWeight,
2142
- y1 - perpY * innerWeight
2143
- );
2144
- verts.push(
2145
- x1 + perpX * outerWeight,
2146
- y1 + perpY * outerWeight
2147
- );
2148
- if (dot >= 0) {
2149
- if (style.join === "round") {
2150
- indexCount += round(
2151
- x1,
2152
- y1,
2153
- x1 - perpX * innerWeight,
2154
- y1 - perpY * innerWeight,
2155
- x1 - perp1x * innerWeight,
2156
- y1 - perp1y * innerWeight,
2157
- verts,
2158
- false
2159
- ) + 4;
2160
- } else {
2161
- indexCount += 2;
2162
- }
2163
- verts.push(
2164
- x1 - perp1x * outerWeight,
2165
- y1 - perp1y * outerWeight
2166
- );
2167
- verts.push(
2168
- x1 + perp1x * innerWeight,
2169
- y1 + perp1y * innerWeight
2170
- );
2171
- }
2172
- continue;
2173
- }
2174
- const c1 = (-perpX + x0) * (-perpY + y1) - (-perpX + x1) * (-perpY + y0);
2175
- const c2 = (-perp1x + x2) * (-perp1y + y1) - (-perp1x + x1) * (-perp1y + y2);
2176
- const px = (dx0 * c2 - dx1 * c1) / cross;
2177
- const py = (dy1 * c1 - dy0 * c2) / cross;
2178
- const pDist = (px - x1) * (px - x1) + (py - y1) * (py - y1);
2179
- const imx = x1 + (px - x1) * innerWeight;
2180
- const imy = y1 + (py - y1) * innerWeight;
2181
- const omx = x1 - (px - x1) * outerWeight;
2182
- const omy = y1 - (py - y1) * outerWeight;
2183
- const smallerInsideSegmentSq = Math.min(dx0 * dx0 + dy0 * dy0, dx1 * dx1 + dy1 * dy1);
2184
- const insideWeight = clockwise ? innerWeight : outerWeight;
2185
- const smallerInsideDiagonalSq = smallerInsideSegmentSq + insideWeight * insideWeight * widthSquared;
2186
- const insideMiterOk = pDist <= smallerInsideDiagonalSq;
2187
- if (insideMiterOk) {
2188
- if (style.join === "bevel" || pDist / widthSquared > miterLimitSquared) {
2189
- if (clockwise) {
2190
- verts.push(imx, imy);
2191
- verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight);
2192
- verts.push(imx, imy);
2193
- verts.push(x1 + perp1x * outerWeight, y1 + perp1y * outerWeight);
2194
- } else {
2195
- verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight);
2196
- verts.push(omx, omy);
2197
- verts.push(x1 - perp1x * innerWeight, y1 - perp1y * innerWeight);
2198
- verts.push(omx, omy);
2199
- }
2200
- indexCount += 2;
2201
- } else if (style.join === "round") {
2202
- if (clockwise) {
2203
- verts.push(imx, imy);
2204
- verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight);
2205
- indexCount += round(
2206
- x1,
2207
- y1,
2208
- x1 + perpX * outerWeight,
2209
- y1 + perpY * outerWeight,
2210
- x1 + perp1x * outerWeight,
2211
- y1 + perp1y * outerWeight,
2212
- verts,
2213
- true
2214
- ) + 4;
2215
- verts.push(imx, imy);
2216
- verts.push(x1 + perp1x * outerWeight, y1 + perp1y * outerWeight);
2217
- } else {
2218
- verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight);
2219
- verts.push(omx, omy);
2220
- indexCount += round(
2221
- x1,
2222
- y1,
2223
- x1 - perpX * innerWeight,
2224
- y1 - perpY * innerWeight,
2225
- x1 - perp1x * innerWeight,
2226
- y1 - perp1y * innerWeight,
2227
- verts,
2228
- false
2229
- ) + 4;
2230
- verts.push(x1 - perp1x * innerWeight, y1 - perp1y * innerWeight);
2231
- verts.push(omx, omy);
2232
- }
2233
- } else {
2234
- verts.push(imx, imy);
2235
- verts.push(omx, omy);
2236
- }
2237
- } else {
2238
- verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight);
2239
- verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight);
2240
- if (style.join === "round") {
2241
- if (clockwise) {
2242
- indexCount += round(
2243
- x1,
2244
- y1,
2245
- x1 + perpX * outerWeight,
2246
- y1 + perpY * outerWeight,
2247
- x1 + perp1x * outerWeight,
2248
- y1 + perp1y * outerWeight,
2249
- verts,
2250
- true
2251
- ) + 2;
2252
- } else {
2253
- indexCount += round(
2254
- x1,
2255
- y1,
2256
- x1 - perpX * innerWeight,
2257
- y1 - perpY * innerWeight,
2258
- x1 - perp1x * innerWeight,
2259
- y1 - perp1y * innerWeight,
2260
- verts,
2261
- false
2262
- ) + 2;
2263
- }
2264
- } else if (style.join === "miter" && pDist / widthSquared <= miterLimitSquared) {
2265
- if (clockwise) {
2266
- verts.push(omx, omy);
2267
- verts.push(omx, omy);
2268
- } else {
2269
- verts.push(imx, imy);
2270
- verts.push(imx, imy);
2271
- }
2272
- indexCount += 2;
2273
- }
2274
- verts.push(x1 - perp1x * innerWeight, y1 - perp1y * innerWeight);
2275
- verts.push(x1 + perp1x * outerWeight, y1 + perp1y * outerWeight);
2276
- indexCount += 2;
2277
- }
2278
- }
2279
- x0 = points[(length - 2) * 2];
2280
- y0 = points[(length - 2) * 2 + 1];
2281
- x1 = points[(length - 1) * 2];
2282
- y1 = points[(length - 1) * 2 + 1];
2283
- perpX = -(y0 - y1);
2284
- perpY = x0 - x1;
2285
- dist = Math.sqrt(perpX * perpX + perpY * perpY);
2286
- perpX /= dist;
2287
- perpY /= dist;
2288
- perpX *= width;
2289
- perpY *= width;
2290
- verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight);
2291
- verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight);
2292
- if (!closedShape) {
2293
- if (style.cap === "round") {
2294
- indexCount += round(
2295
- x1 - perpX * (innerWeight - outerWeight) * 0.5,
2296
- y1 - perpY * (innerWeight - outerWeight) * 0.5,
2297
- x1 - perpX * innerWeight,
2298
- y1 - perpY * innerWeight,
2299
- x1 + perpX * outerWeight,
2300
- y1 + perpY * outerWeight,
2301
- verts,
2302
- false
2303
- ) + 2;
2304
- } else if (style.cap === "square") {
2305
- indexCount += square(x1, y1, perpX, perpY, innerWeight, outerWeight, false, verts);
2306
- }
2307
- }
2308
- const eps2 = curveEps * curveEps;
2309
- for (let i = indexStart; i < indexCount + indexStart - 2; ++i) {
2310
- x0 = verts[i * 2];
2311
- y0 = verts[i * 2 + 1];
2312
- x1 = verts[(i + 1) * 2];
2313
- y1 = verts[(i + 1) * 2 + 1];
2314
- x2 = verts[(i + 2) * 2];
2315
- y2 = verts[(i + 2) * 2 + 1];
2316
- if (Math.abs(x0 * (y1 - y2) + x1 * (y2 - y0) + x2 * (y0 - y1)) < eps2) {
2317
- continue;
2318
- }
2319
- indices.push(i, i + 1, i + 2);
2320
- }
2321
- }
2322
-
2323
- const emptyArray = [];
2324
- const buildPolygon = {
2325
- build(shape, points) {
2326
- for (let i = 0; i < shape.points.length; i++) {
2327
- points[i] = shape.points[i];
2328
- }
2329
- return points;
2330
- },
2331
- triangulate(points, vertices, verticesStride, verticesOffset, indices, indicesOffset) {
2332
- triangulateWithHoles(points, emptyArray, vertices, verticesStride, verticesOffset, indices, indicesOffset);
2333
- }
2334
- };
2335
-
2336
- const buildRectangle = {
2337
- build(shape, points) {
2338
- const rectData = shape;
2339
- const x = rectData.x;
2340
- const y = rectData.y;
2341
- const width = rectData.width;
2342
- const height = rectData.height;
2343
- if (!(width >= 0 && height >= 0)) {
2344
- return points;
2345
- }
2346
- points[0] = x;
2347
- points[1] = y;
2348
- points[2] = x + width;
2349
- points[3] = y;
2350
- points[4] = x + width;
2351
- points[5] = y + height;
2352
- points[6] = x;
2353
- points[7] = y + height;
2354
- return points;
2355
- },
2356
- triangulate(points, vertices, verticesStride, verticesOffset, indices, indicesOffset) {
2357
- let count = 0;
2358
- verticesOffset *= verticesStride;
2359
- vertices[verticesOffset + count] = points[0];
2360
- vertices[verticesOffset + count + 1] = points[1];
2361
- count += verticesStride;
2362
- vertices[verticesOffset + count] = points[2];
2363
- vertices[verticesOffset + count + 1] = points[3];
2364
- count += verticesStride;
2365
- vertices[verticesOffset + count] = points[6];
2366
- vertices[verticesOffset + count + 1] = points[7];
2367
- count += verticesStride;
2368
- vertices[verticesOffset + count] = points[4];
2369
- vertices[verticesOffset + count + 1] = points[5];
2370
- count += verticesStride;
2371
- const verticesIndex = verticesOffset / verticesStride;
2372
- indices[indicesOffset++] = verticesIndex;
2373
- indices[indicesOffset++] = verticesIndex + 1;
2374
- indices[indicesOffset++] = verticesIndex + 2;
2375
- indices[indicesOffset++] = verticesIndex + 1;
2376
- indices[indicesOffset++] = verticesIndex + 3;
2377
- indices[indicesOffset++] = verticesIndex + 2;
2378
- }
2379
- };
2380
-
2381
- const buildTriangle = {
2382
- build(shape, points) {
2383
- points[0] = shape.x;
2384
- points[1] = shape.y;
2385
- points[2] = shape.x2;
2386
- points[3] = shape.y2;
2387
- points[4] = shape.x3;
2388
- points[5] = shape.y3;
2389
- return points;
2390
- },
2391
- triangulate(points, vertices, verticesStride, verticesOffset, indices, indicesOffset) {
2392
- let count = 0;
2393
- verticesOffset *= verticesStride;
2394
- vertices[verticesOffset + count] = points[0];
2395
- vertices[verticesOffset + count + 1] = points[1];
2396
- count += verticesStride;
2397
- vertices[verticesOffset + count] = points[2];
2398
- vertices[verticesOffset + count + 1] = points[3];
2399
- count += verticesStride;
2400
- vertices[verticesOffset + count] = points[4];
2401
- vertices[verticesOffset + count + 1] = points[5];
2402
- const verticesIndex = verticesOffset / verticesStride;
2403
- indices[indicesOffset++] = verticesIndex;
2404
- indices[indicesOffset++] = verticesIndex + 1;
2405
- indices[indicesOffset++] = verticesIndex + 2;
2406
- }
2407
- };
2408
-
2409
- const tempPoints = [new Point(), new Point(), new Point(), new Point()];
2410
- class Rectangle {
2411
- constructor(x = 0, y = 0, width = 0, height = 0) {
2412
- this.x = x;
2413
- this.y = y;
2414
- this.width = width;
2415
- this.height = height;
2416
- }
2417
- get left() {
2418
- return this.x;
2419
- }
2420
- get right() {
2421
- return this.x + this.width;
2422
- }
2423
- get top() {
2424
- return this.y;
2425
- }
2426
- get bottom() {
2427
- return this.y + this.height;
2428
- }
2429
- isEmpty() {
2430
- return this.left === this.right || this.top === this.bottom;
2431
- }
2432
- copyFromBounds(bounds) {
2433
- this.x = bounds.minX;
2434
- this.y = bounds.minY;
2435
- this.width = bounds.maxX - bounds.minX;
2436
- this.height = bounds.maxY - bounds.minY;
2437
- return this;
2438
- }
2439
- contains(x, y) {
2440
- if (this.width <= 0 || this.height <= 0) {
2441
- return false;
2442
- }
2443
- if (x >= this.x && x < this.x + this.width) {
2444
- if (y >= this.y && y < this.y + this.height) {
2445
- return true;
2446
- }
2447
- }
2448
- return false;
2449
- }
2450
- strokeContains(x, y, strokeWidth) {
2451
- const { width, height } = this;
2452
- if (width <= 0 || height <= 0)
2453
- return false;
2454
- const _x = this.x;
2455
- const _y = this.y;
2456
- const outerLeft = _x - strokeWidth / 2;
2457
- const outerRight = _x + width + strokeWidth / 2;
2458
- const outerTop = _y - strokeWidth / 2;
2459
- const outerBottom = _y + height + strokeWidth / 2;
2460
- const innerLeft = _x + strokeWidth / 2;
2461
- const innerRight = _x + width - strokeWidth / 2;
2462
- const innerTop = _y + strokeWidth / 2;
2463
- const innerBottom = _y + height - strokeWidth / 2;
2464
- return x >= outerLeft && x <= outerRight && y >= outerTop && y <= outerBottom && !(x > innerLeft && x < innerRight && y > innerTop && y < innerBottom);
2465
- }
2466
- clone() {
2467
- return new Rectangle(this.x, this.y, this.width, this.height);
2468
- }
2469
- copyFrom(rectangle) {
2470
- this.x = rectangle.x;
2471
- this.y = rectangle.y;
2472
- this.width = rectangle.width;
2473
- this.height = rectangle.height;
2474
- }
2475
- copyTo(rectangle) {
2476
- rectangle.copyFrom(this);
2477
- }
2478
- intersects(other, transform) {
2479
- if (!transform) {
2480
- const x02 = this.x < other.x ? other.x : this.x;
2481
- const x12 = this.right > other.right ? other.right : this.right;
2482
- if (x12 <= x02) {
2483
- return false;
2484
- }
2485
- const y02 = this.y < other.y ? other.y : this.y;
2486
- const y12 = this.bottom > other.bottom ? other.bottom : this.bottom;
2487
- return y12 > y02;
2488
- }
2489
- const x0 = this.left;
2490
- const x1 = this.right;
2491
- const y0 = this.top;
2492
- const y1 = this.bottom;
2493
- if (x1 <= x0 || y1 <= y0) {
2494
- return false;
2495
- }
2496
- const lt = tempPoints[0].set(other.left, other.top);
2497
- const lb = tempPoints[1].set(other.left, other.bottom);
2498
- const rt = tempPoints[2].set(other.right, other.top);
2499
- const rb = tempPoints[3].set(other.right, other.bottom);
2500
- if (rt.x <= lt.x || lb.y <= lt.y) {
2501
- return false;
2502
- }
2503
- const { a, d, b, c } = transform.toObject();
2504
- const s = Math.sign(a * d - b * c);
2505
- if (s === 0) {
2506
- return false;
2507
- }
2508
- [lt.x, lt.y] = transform.applyToPoint(lt.x, lt.y);
2509
- [lb.x, lb.y] = transform.applyToPoint(lb.x, lb.y);
2510
- [rt.x, rt.y] = transform.applyToPoint(rt.x, rt.y);
2511
- [rb.x, rb.y] = transform.applyToPoint(rb.x, lt.y);
2512
- if (Math.max(lt.x, lb.x, rt.x, rb.x) <= x0 || Math.min(lt.x, lb.x, rt.x, rb.x) >= x1 || Math.max(lt.y, lb.y, rt.y, rb.y) <= y0 || Math.min(lt.y, lb.y, rt.y, rb.y) >= y1) {
2513
- return false;
2514
- }
2515
- const nx = s * (lb.y - lt.y);
2516
- const ny = s * (lt.x - lb.x);
2517
- const n00 = nx * x0 + ny * y0;
2518
- const n10 = nx * x1 + ny * y0;
2519
- const n01 = nx * x0 + ny * y1;
2520
- const n11 = nx * x1 + ny * y1;
2521
- if (Math.max(n00, n10, n01, n11) <= nx * lt.x + ny * lt.y || Math.min(n00, n10, n01, n11) >= nx * rb.x + ny * rb.y) {
2522
- return false;
2523
- }
2524
- const mx = s * (lt.y - rt.y);
2525
- const my = s * (rt.x - lt.x);
2526
- const m00 = mx * x0 + my * y0;
2527
- const m10 = mx * x1 + my * y0;
2528
- const m01 = mx * x0 + my * y1;
2529
- const m11 = mx * x1 + my * y1;
2530
- if (Math.max(m00, m10, m01, m11) <= mx * lt.x + my * lt.y || Math.min(m00, m10, m01, m11) >= mx * rb.x + my * rb.y) {
2531
- return false;
2532
- }
2533
- return true;
2534
- }
2535
- pad(paddingX = 0, paddingY = paddingX) {
2536
- this.x -= paddingX;
2537
- this.y -= paddingY;
2538
- this.width += paddingX * 2;
2539
- this.height += paddingY * 2;
2540
- return this;
2541
- }
2542
- fit(rectangle) {
2543
- const x1 = Math.max(this.x, rectangle.x);
2544
- const x2 = Math.min(this.x + this.width, rectangle.x + rectangle.width);
2545
- const y1 = Math.max(this.y, rectangle.y);
2546
- const y2 = Math.min(this.y + this.height, rectangle.y + rectangle.height);
2547
- this.x = x1;
2548
- this.width = Math.max(x2 - x1, 0);
2549
- this.y = y1;
2550
- this.height = Math.max(y2 - y1, 0);
2551
- return this;
2552
- }
2553
- ceil(resolution = 1, eps = 1e-3) {
2554
- const x2 = Math.ceil((this.x + this.width - eps) * resolution) / resolution;
2555
- const y2 = Math.ceil((this.y + this.height - eps) * resolution) / resolution;
2556
- this.x = Math.floor((this.x + eps) * resolution) / resolution;
2557
- this.y = Math.floor((this.y + eps) * resolution) / resolution;
2558
- this.width = x2 - this.x;
2559
- this.height = y2 - this.y;
2560
- return this;
2561
- }
2562
- enlarge(rectangle) {
2563
- const x1 = Math.min(this.x, rectangle.x);
2564
- const x2 = Math.max(this.x + this.width, rectangle.x + rectangle.width);
2565
- const y1 = Math.min(this.y, rectangle.y);
2566
- const y2 = Math.max(this.y + this.height, rectangle.y + rectangle.height);
2567
- this.x = x1;
2568
- this.width = x2 - x1;
2569
- this.y = y1;
2570
- this.height = y2 - y1;
2571
- return this;
2572
- }
2573
- getBounds(out) {
2574
- out = out || new Rectangle();
2575
- out.copyFrom(this);
2576
- return out;
2577
- }
2578
- buildOutline(points) {
2579
- buildRectangle.build(this, points);
2580
- }
2581
- buildGeometry(vertices, indices) {
2582
- const points = [];
2583
- this.buildOutline(points);
2584
- buildRectangle.triangulate(points, vertices, 2, 0, indices, 0);
2585
- }
2586
- }
2587
-
2588
- class Vector extends EventEmitter {
2589
- constructor(dim) {
2590
- super();
2591
- this.dim = dim;
2592
- }
2593
- _array = [];
2594
- get length() {
2595
- return this.dim;
2596
- }
2597
- _operate(operator, target, output) {
2598
- const { dim: length, _array: array } = this;
2599
- let targetArray;
2600
- if (typeof target === "number") {
2601
- targetArray = Array.from({ length }, () => target);
2602
- } else if (target instanceof Matrix || target instanceof Vector) {
2603
- targetArray = target.toArray();
2604
- } else {
2605
- targetArray = target;
2606
- }
2607
- let outputObject;
2608
- let outputArray = [];
2609
- if (!output) {
2610
- outputObject = this;
2611
- } else if (output instanceof Vector) {
2612
- outputObject = output;
2613
- } else {
2614
- outputArray = output;
2615
- }
2616
- if (target instanceof Matrix) {
2617
- const { cols } = target;
2618
- switch (operator) {
2619
- case "*":
2620
- for (let x = 0; x < length; x++) {
2621
- let val = 0;
2622
- for (let y = 0; y < length; y++) {
2623
- val += array[x] * targetArray[y * cols + x];
2624
- }
2625
- outputArray[x] = val;
2626
- }
2627
- break;
2628
- default:
2629
- throw new Error(`Not support operator in '${this.toName()} ${operator} ${target.toName()}'`);
2630
- }
2631
- } else {
2632
- switch (operator) {
2633
- case "+":
2634
- for (let i = 0; i < length; i++) {
2635
- outputArray[i] = array[i] + targetArray[i];
2636
- }
2637
- break;
2638
- case "-":
2639
- for (let i = 0; i < length; i++) {
2640
- outputArray[i] = array[i] - targetArray[i];
2641
- }
2642
- break;
2643
- case "*":
2644
- for (let i = 0; i < length; i++) {
2645
- outputArray[i] = array[i] * targetArray[i];
2646
- }
2647
- break;
2648
- case "/":
2649
- for (let i = 0; i < length; i++) {
2650
- outputArray[i] = array[i] / targetArray[i];
2651
- }
2652
- break;
2653
- case "rot": {
2654
- const c = Math.cos(targetArray[0]);
2655
- const s = Math.sin(targetArray[0]);
2656
- outputArray[0] = array[0] * c - array[1] * s;
2657
- outputArray[1] = array[1] * c + array[0] * s;
2658
- break;
2659
- }
2660
- case "==": {
2661
- let flag = true;
2662
- for (let i = 0; i < length; i++) {
2663
- flag = flag && array[i] === targetArray[i];
2664
- }
2665
- return flag;
2666
- }
2667
- case "=":
2668
- for (let i = 0; i < length; i++) {
2669
- const val = targetArray[i];
2670
- if (val !== void 0) {
2671
- array[i] = val;
2672
- }
2673
- }
2674
- this._emitUpdate(array);
2675
- return this;
2676
- default:
2677
- throw new Error(`Not support operator in '${this.toName()} ${operator} Vector'`);
2678
- }
2679
- }
2680
- return outputObject?.set(outputArray) ?? outputArray;
2681
- }
2682
- add(value, output) {
2683
- return this._operate("+", value, output);
2684
- }
2685
- sub(value, output) {
2686
- return this._operate("-", value, output);
2687
- }
2688
- multiply(value, output) {
2689
- return this._operate("*", value, output);
2690
- }
2691
- divide(value, output) {
2692
- return this._operate("/", value, output);
2693
- }
2694
- rotate(angle) {
2695
- return this._operate("rot", angle);
2696
- }
2697
- set(value, ...args) {
2698
- if (args.length && typeof value === "number") {
2699
- value = [value, ...args];
2700
- }
2701
- return this._operate("=", value);
2702
- }
2703
- equals(value) {
2704
- return this._operate("==", value);
2705
- }
2706
- clone() {
2707
- const cloned = new this.constructor();
2708
- cloned.set(this.toArray());
2709
- return cloned;
2710
- }
2711
- onUpdate(callback) {
2712
- this.on("update", callback);
2713
- return this;
2714
- }
2715
- offUpdate(callback) {
2716
- this.off("update", callback);
2717
- return this;
2718
- }
2719
- _emitUpdate(array) {
2720
- this._onUpdate(array);
2721
- this.emit("update", array);
2722
- }
2723
- _onUpdate(_array) {
2724
- }
2725
- toArray() {
2726
- return this._array.slice();
2727
- }
2728
- toName() {
2729
- return `Vector${this.dim}`;
2730
- }
2731
- }
2732
-
2733
- class Matrix extends EventEmitter {
2734
- constructor(rows, cols, array) {
2735
- super();
2736
- this.rows = rows;
2737
- this.cols = cols;
2738
- if (array) {
2739
- this.set(array);
2740
- } else {
2741
- this.identity();
2742
- }
2743
- }
2744
- _array = [];
2745
- get length() {
2746
- return this.cols * this.rows;
2747
- }
2748
- _operate(operator, target, output) {
2749
- const { cols, rows, length, _array: array } = this;
2750
- let targetArray;
2751
- if (typeof target === "number") {
2752
- targetArray = Array.from({ length }, () => target);
2753
- } else if (target instanceof Vector || target instanceof Matrix) {
2754
- targetArray = target.toArray();
2755
- } else {
2756
- targetArray = target;
1199
+ _operate(operator, target, output) {
1200
+ const { cols, rows, length, _array: array } = this;
1201
+ let targetArray;
1202
+ if (typeof target === "number") {
1203
+ targetArray = Array.from({ length }, () => target);
1204
+ } else if (target instanceof Vector || target instanceof Matrix) {
1205
+ targetArray = target.toArray();
1206
+ } else {
1207
+ targetArray = target;
2757
1208
  }
2758
1209
  let outputObject;
2759
1210
  let outputArray = [];
@@ -2876,6 +1327,12 @@ class Matrix extends EventEmitter {
2876
1327
  }
2877
1328
  }
2878
1329
 
1330
+ class Matrix2 extends Matrix {
1331
+ constructor(array) {
1332
+ super(2, 2, array);
1333
+ }
1334
+ }
1335
+
2879
1336
  class Matrix3 extends Matrix {
2880
1337
  constructor(array) {
2881
1338
  super(3, 3, array);
@@ -2914,6 +1371,72 @@ class Matrix3 extends Matrix {
2914
1371
  }
2915
1372
  }
2916
1373
 
1374
+ class Matrix4 extends Matrix {
1375
+ constructor(array) {
1376
+ super(4, 4, array);
1377
+ }
1378
+ }
1379
+
1380
+ class Projection2D extends Matrix3 {
1381
+ constructor(_x = 0, _y = 0, _width = 0, _height = 0, _flipY = false) {
1382
+ super();
1383
+ this._x = _x;
1384
+ this._y = _y;
1385
+ this._width = _width;
1386
+ this._height = _height;
1387
+ this._flipY = _flipY;
1388
+ this._performUpdateArray();
1389
+ }
1390
+ flipY(flipY) {
1391
+ if (this._flipY !== flipY) {
1392
+ this._flipY = flipY;
1393
+ this._performUpdateArray();
1394
+ }
1395
+ return this;
1396
+ }
1397
+ translate(x, y) {
1398
+ if (this._x !== x || this._y !== y) {
1399
+ this._x = x;
1400
+ this._y = y;
1401
+ this._performUpdateArray();
1402
+ }
1403
+ return this;
1404
+ }
1405
+ resize(width, height) {
1406
+ if (this._width !== width || this._height !== height) {
1407
+ this._width = width;
1408
+ this._height = height;
1409
+ this._performUpdateArray();
1410
+ }
1411
+ return this;
1412
+ }
1413
+ _performUpdateArray() {
1414
+ const width = this._width;
1415
+ const height = this._height;
1416
+ if (!width || !height) {
1417
+ return;
1418
+ }
1419
+ const x = this._x;
1420
+ const y = this._y;
1421
+ const sign = !this._flipY ? 1 : -1;
1422
+ const a = 1 / width * 2;
1423
+ const d = sign * (1 / height * 2);
1424
+ const tx = -1 - x * a;
1425
+ const ty = -sign - y * d;
1426
+ this.set([
1427
+ a,
1428
+ 0,
1429
+ tx,
1430
+ 0,
1431
+ d,
1432
+ ty,
1433
+ 0,
1434
+ 0,
1435
+ 1
1436
+ ]);
1437
+ }
1438
+ }
1439
+
2917
1440
  class Transform2D extends Matrix3 {
2918
1441
  constructor(autoUpdate = true) {
2919
1442
  super();
@@ -3055,848 +1578,85 @@ class Transform2D extends Matrix3 {
3055
1578
  scale3d(x, y, z) {
3056
1579
  return this.scale(x, y, z);
3057
1580
  }
3058
- rotate(rad) {
3059
- this._rotate = rad;
3060
- this._updateSkew();
3061
- this._requestUpdateArray();
3062
- return this;
3063
- }
3064
- rotateX(x) {
3065
- return this.scaleY(this._rotateToScale(x));
3066
- }
3067
- rotateY(y) {
3068
- return this.scaleX(this._rotateToScale(y));
3069
- }
3070
- rotateZ(z) {
3071
- return this.rotate(z);
3072
- }
3073
- rotate3d(x, y, z, rad) {
3074
- const [rx, ry, rz] = this._rotate3d(x, y, z, rad);
3075
- rx && this.rotateX(rx);
3076
- ry && this.rotateY(ry);
3077
- rz && this.rotateZ(rz);
3078
- return this;
3079
- }
3080
- _rotateToScale(rad) {
3081
- const val = rad / PI_2;
3082
- return val <= 0.5 ? val * -4 + 1 : (val - 1) * 4 + 1;
3083
- }
3084
- _rotate3d(x, y, z, rad) {
3085
- if (x === 1 && y === 0 && z === 0) {
3086
- return [rad, 0, 0];
3087
- } else if (x === 0 && y === 1 && z === 0) {
3088
- return [0, rad, 0];
3089
- } else if (x === 0 && y === 0) {
3090
- return [0, 0, rad];
3091
- } else {
3092
- const cos = Math.cos(rad);
3093
- const sin = Math.sin(rad);
3094
- const m11 = cos + x * x * (1 - cos);
3095
- const m12 = x * y * (1 - cos) - z * sin;
3096
- const m13 = x * z * (1 - cos) + y * sin;
3097
- const m22 = cos + y * y * (1 - cos);
3098
- const m23 = y * z * (1 - cos) - x * sin;
3099
- const m33 = cos + z * z * (1 - cos);
3100
- const rotateX = -Math.atan2(-m23, m22);
3101
- const rotateY = -Math.atan2(m13, Math.sqrt(m23 * m23 + m33 * m33));
3102
- const rotateZ = -Math.atan2(-m12, m11);
3103
- return [rotateX, rotateY, rotateZ];
3104
- }
3105
- }
3106
- applyToPoint(x, y) {
3107
- const { a, c, tx, b, d, ty } = this.toObject();
3108
- return [
3109
- a * x + c * y + tx,
3110
- b * x + d * y + ty
3111
- ];
3112
- }
3113
- inverse() {
3114
- return this.clone().invert();
3115
- }
3116
- update() {
3117
- let updated = false;
3118
- if (this._needsUpdateArray) {
3119
- this._needsUpdateArray = false;
3120
- this._performUpdateArray();
3121
- updated = true;
3122
- }
3123
- if (this._needsUpdateFields) {
3124
- this._needsUpdateFields = false;
3125
- this._performUpdateFields();
3126
- updated = true;
3127
- }
3128
- return updated;
3129
- }
3130
- isIdentity() {
3131
- const { a, b, c, d, tx, ty } = this.toObject();
3132
- return a === 1 && b === 0 && c === 0 && d === 1 && tx === 0 && ty === 0;
3133
- }
3134
- toObject() {
3135
- const [a, c, tx, b, d, ty, , , tz] = this._array;
3136
- return { a, c, tx, b, d, ty, tz };
3137
- }
3138
- }
3139
-
3140
- const defaultMatrix = new Transform2D();
3141
- class Bounds {
3142
- constructor(minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity) {
3143
- this.minX = minX;
3144
- this.minY = minY;
3145
- this.maxX = maxX;
3146
- this.maxY = maxY;
3147
- }
3148
- matrix = defaultMatrix;
3149
- _rectangle;
3150
- get x() {
3151
- return this.minX;
3152
- }
3153
- set x(value) {
3154
- const width = this.maxX - this.minX;
3155
- this.minX = value;
3156
- this.maxX = value + width;
3157
- }
3158
- get y() {
3159
- return this.minY;
3160
- }
3161
- set y(value) {
3162
- const height = this.maxY - this.minY;
3163
- this.minY = value;
3164
- this.maxY = value + height;
3165
- }
3166
- get width() {
3167
- return this.maxX - this.minX;
3168
- }
3169
- set width(value) {
3170
- this.maxX = this.minX + value;
3171
- }
3172
- get height() {
3173
- return this.maxY - this.minY;
3174
- }
3175
- set height(value) {
3176
- this.maxY = this.minY + value;
3177
- }
3178
- get left() {
3179
- return this.minX;
3180
- }
3181
- get right() {
3182
- return this.maxX;
3183
- }
3184
- get top() {
3185
- return this.minY;
3186
- }
3187
- get bottom() {
3188
- return this.maxY;
3189
- }
3190
- get isPositive() {
3191
- return this.maxX - this.minX > 0 && this.maxY - this.minY > 0;
3192
- }
3193
- get isValid() {
3194
- return this.minX + this.minY !== Infinity;
3195
- }
3196
- isEmpty() {
3197
- return this.minX > this.maxX || this.minY > this.maxY;
3198
- }
3199
- get rectangle() {
3200
- if (!this._rectangle) {
3201
- this._rectangle = new Rectangle();
3202
- }
3203
- const rectangle = this._rectangle;
3204
- if (this.minX > this.maxX || this.minY > this.maxY) {
3205
- rectangle.x = 0;
3206
- rectangle.y = 0;
3207
- rectangle.width = 0;
3208
- rectangle.height = 0;
3209
- } else {
3210
- rectangle.copyFromBounds(this);
3211
- }
3212
- return rectangle;
3213
- }
3214
- clear() {
3215
- this.minX = Infinity;
3216
- this.minY = Infinity;
3217
- this.maxX = -Infinity;
3218
- this.maxY = -Infinity;
3219
- this.matrix = defaultMatrix;
3220
- return this;
3221
- }
3222
- set(x0, y0, x1, y1) {
3223
- this.minX = x0;
3224
- this.minY = y0;
3225
- this.maxX = x1;
3226
- this.maxY = y1;
3227
- return this;
3228
- }
3229
- addFrame(x0, y0, x1, y1, matrix) {
3230
- matrix ||= this.matrix;
3231
- const { a, b, c, d, tx, ty } = matrix.toObject();
3232
- let minX = this.minX;
3233
- let minY = this.minY;
3234
- let maxX = this.maxX;
3235
- let maxY = this.maxY;
3236
- let x = a * x0 + c * y0 + tx;
3237
- let y = b * x0 + d * y0 + ty;
3238
- if (x < minX)
3239
- minX = x;
3240
- if (y < minY)
3241
- minY = y;
3242
- if (x > maxX)
3243
- maxX = x;
3244
- if (y > maxY)
3245
- maxY = y;
3246
- x = a * x1 + c * y0 + tx;
3247
- y = b * x1 + d * y0 + ty;
3248
- if (x < minX)
3249
- minX = x;
3250
- if (y < minY)
3251
- minY = y;
3252
- if (x > maxX)
3253
- maxX = x;
3254
- if (y > maxY)
3255
- maxY = y;
3256
- x = a * x0 + c * y1 + tx;
3257
- y = b * x0 + d * y1 + ty;
3258
- if (x < minX)
3259
- minX = x;
3260
- if (y < minY)
3261
- minY = y;
3262
- if (x > maxX)
3263
- maxX = x;
3264
- if (y > maxY)
3265
- maxY = y;
3266
- x = a * x1 + c * y1 + tx;
3267
- y = b * x1 + d * y1 + ty;
3268
- if (x < minX)
3269
- minX = x;
3270
- if (y < minY)
3271
- minY = y;
3272
- if (x > maxX)
3273
- maxX = x;
3274
- if (y > maxY)
3275
- maxY = y;
3276
- this.minX = minX;
3277
- this.minY = minY;
3278
- this.maxX = maxX;
3279
- this.maxY = maxY;
3280
- }
3281
- addRect(rect, matrix) {
3282
- this.addFrame(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height, matrix);
3283
- return this;
3284
- }
3285
- addBounds(bounds, matrix) {
3286
- this.addFrame(bounds.minX, bounds.minY, bounds.maxX, bounds.maxY, matrix);
3287
- return this;
3288
- }
3289
- addBoundsMask(mask) {
3290
- this.minX = this.minX > mask.minX ? this.minX : mask.minX;
3291
- this.minY = this.minY > mask.minY ? this.minY : mask.minY;
3292
- this.maxX = this.maxX < mask.maxX ? this.maxX : mask.maxX;
3293
- this.maxY = this.maxY < mask.maxY ? this.maxY : mask.maxY;
3294
- }
3295
- applyMatrix(matrix) {
3296
- const minX = this.minX;
3297
- const minY = this.minY;
3298
- const maxX = this.maxX;
3299
- const maxY = this.maxY;
3300
- const { a, b, c, d, tx, ty } = matrix.toObject();
3301
- let x = a * minX + c * minY + tx;
3302
- let y = b * minX + d * minY + ty;
3303
- this.minX = x;
3304
- this.minY = y;
3305
- this.maxX = x;
3306
- this.maxY = y;
3307
- x = a * maxX + c * minY + tx;
3308
- y = b * maxX + d * minY + ty;
3309
- this.minX = x < this.minX ? x : this.minX;
3310
- this.minY = y < this.minY ? y : this.minY;
3311
- this.maxX = x > this.maxX ? x : this.maxX;
3312
- this.maxY = y > this.maxY ? y : this.maxY;
3313
- x = a * minX + c * maxY + tx;
3314
- y = b * minX + d * maxY + ty;
3315
- this.minX = x < this.minX ? x : this.minX;
3316
- this.minY = y < this.minY ? y : this.minY;
3317
- this.maxX = x > this.maxX ? x : this.maxX;
3318
- this.maxY = y > this.maxY ? y : this.maxY;
3319
- x = a * maxX + c * maxY + tx;
3320
- y = b * maxX + d * maxY + ty;
3321
- this.minX = x < this.minX ? x : this.minX;
3322
- this.minY = y < this.minY ? y : this.minY;
3323
- this.maxX = x > this.maxX ? x : this.maxX;
3324
- this.maxY = y > this.maxY ? y : this.maxY;
3325
- }
3326
- fit(rect) {
3327
- if (this.minX < rect.left)
3328
- this.minX = rect.left;
3329
- if (this.maxX > rect.right)
3330
- this.maxX = rect.right;
3331
- if (this.minY < rect.top)
3332
- this.minY = rect.top;
3333
- if (this.maxY > rect.bottom)
3334
- this.maxY = rect.bottom;
3335
- return this;
3336
- }
3337
- fitBounds(left, right, top, bottom) {
3338
- if (this.minX < left)
3339
- this.minX = left;
3340
- if (this.maxX > right)
3341
- this.maxX = right;
3342
- if (this.minY < top)
3343
- this.minY = top;
3344
- if (this.maxY > bottom)
3345
- this.maxY = bottom;
3346
- return this;
3347
- }
3348
- pad(paddingX, paddingY = paddingX) {
3349
- this.minX -= paddingX;
3350
- this.maxX += paddingX;
3351
- this.minY -= paddingY;
3352
- this.maxY += paddingY;
3353
- return this;
3354
- }
3355
- ceil() {
3356
- this.minX = Math.floor(this.minX);
3357
- this.minY = Math.floor(this.minY);
3358
- this.maxX = Math.ceil(this.maxX);
3359
- this.maxY = Math.ceil(this.maxY);
3360
- return this;
3361
- }
3362
- clone() {
3363
- return new Bounds(this.minX, this.minY, this.maxX, this.maxY);
3364
- }
3365
- scale(x, y = x) {
3366
- this.minX *= x;
3367
- this.minY *= y;
3368
- this.maxX *= x;
3369
- this.maxY *= y;
3370
- return this;
3371
- }
3372
- addVertexData(vertexData, beginOffset, endOffset, matrix) {
3373
- let minX = this.minX;
3374
- let minY = this.minY;
3375
- let maxX = this.maxX;
3376
- let maxY = this.maxY;
3377
- matrix ||= this.matrix;
3378
- const { a, b, c, d, tx, ty } = matrix.toObject();
3379
- for (let i = beginOffset; i < endOffset; i += 2) {
3380
- const localX = vertexData[i];
3381
- const localY = vertexData[i + 1];
3382
- const x = a * localX + c * localY + tx;
3383
- const y = b * localX + d * localY + ty;
3384
- minX = x < minX ? x : minX;
3385
- minY = y < minY ? y : minY;
3386
- maxX = x > maxX ? x : maxX;
3387
- maxY = y > maxY ? y : maxY;
3388
- }
3389
- this.minX = minX;
3390
- this.minY = minY;
3391
- this.maxX = maxX;
3392
- this.maxY = maxY;
3393
- }
3394
- containsPoint(x, y) {
3395
- if (this.minX <= x && this.minY <= y && this.maxX >= x && this.maxY >= y) {
3396
- return true;
3397
- }
3398
- return false;
3399
- }
3400
- }
3401
-
3402
- const dSegmentRE = /([astvzqmhlc])([^astvzqmhlc]*)/gi;
3403
- const dNumberRE = /-?\d*\.?\d+(?:e[-+]?\d+)?/gi;
3404
- const dLengthMap = { a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0 };
3405
- class SVGPath {
3406
- defines = [];
3407
- _calls = [];
3408
- _dirty = false;
3409
- get path2D() {
3410
- const path2D = new Path2D();
3411
- if (this._dirty) {
3412
- this._dirty = false;
3413
- this._calls.forEach((call) => {
3414
- path2D[call.method](...call.args);
3415
- });
3416
- }
3417
- return path2D;
3418
- }
3419
- constructor(d) {
3420
- if (typeof d === "string") {
3421
- this.defines = this._parseDefines(d);
3422
- } else {
3423
- this.defines = d.defines.slice();
3424
- }
3425
- this.update();
3426
- }
3427
- _addCall(method, args = [], dirty = true) {
3428
- this._calls.push({ method, args });
3429
- if (dirty) {
3430
- this._dirty = true;
3431
- }
3432
- return this;
3433
- }
3434
- _parseDefines(d) {
3435
- const defines = [];
3436
- d.replace(dSegmentRE, (_, rawCommand, rawArgs) => {
3437
- const args = rawArgs.match(dNumberRE)?.map(Number) ?? [];
3438
- let command = rawCommand.toLowerCase();
3439
- if (command === "m" && args.length > 2) {
3440
- defines.push({ command: rawCommand, args: args.splice(0, 2) });
3441
- command = "l";
3442
- rawCommand = rawCommand === "m" ? "l" : "L";
3443
- }
3444
- while (true) {
3445
- if (args.length === dLengthMap[command]) {
3446
- defines.push({ command: rawCommand, args });
3447
- return "";
3448
- }
3449
- if (args.length < dLengthMap[command])
3450
- throw new Error("malformed path defines");
3451
- defines.push({ command: rawCommand, args: args.splice(0, dLengthMap[command]) });
3452
- }
3453
- });
3454
- return defines;
3455
- }
3456
- update() {
3457
- const subpaths = [];
3458
- let currentSubPath = null;
3459
- let lastX = 0;
3460
- let lastY = 0;
3461
- for (let i = 0; i < this.defines.length; i++) {
3462
- const { command, args } = this.defines[i];
3463
- switch (command) {
3464
- case "M":
3465
- this._addCall("moveTo", [lastX = args[0], lastY = args[1]]);
3466
- break;
3467
- case "m":
3468
- this._addCall("moveTo", [lastX += args[0], lastY += args[1]]);
3469
- break;
3470
- case "H":
3471
- this._addCall("lineTo", [lastX = args[0], lastY]);
3472
- break;
3473
- case "h":
3474
- this._addCall("lineTo", [lastX += args[0], lastY]);
3475
- break;
3476
- case "V":
3477
- this._addCall("lineTo", [lastX, lastY = args[0]]);
3478
- break;
3479
- case "v":
3480
- this._addCall("lineTo", [lastX, lastY += args[0]]);
3481
- break;
3482
- case "L":
3483
- this._addCall("lineTo", [lastX = args[0], lastY = args[1]]);
3484
- break;
3485
- case "l":
3486
- this._addCall("lineTo", [lastX += args[0], lastY += args[1]]);
3487
- break;
3488
- case "C":
3489
- this._addCall("bezierCurveTo", [args[0], args[1], args[2], args[3], args[4], args[5]]);
3490
- lastX = args[4];
3491
- lastY = args[5];
3492
- break;
3493
- case "c":
3494
- this._addCall("bezierCurveTo", [
3495
- lastX + args[0],
3496
- lastY + args[1],
3497
- lastX + args[2],
3498
- lastY + args[3],
3499
- lastX + args[4],
3500
- lastY + args[5]
3501
- ]);
3502
- lastX += args[4];
3503
- lastY += args[5];
3504
- break;
3505
- case "Q":
3506
- this._addCall("quadraticCurveTo", [args[0], args[1], args[2], args[3]]);
3507
- lastX = args[2];
3508
- lastY = args[3];
3509
- break;
3510
- case "q":
3511
- this._addCall("quadraticCurveTo", [
3512
- lastX + args[0],
3513
- lastY + args[1],
3514
- lastX + args[2],
3515
- lastY + args[3]
3516
- ]);
3517
- lastX += args[2];
3518
- lastY += args[3];
3519
- break;
3520
- case "S":
3521
- this._smoothBezierCurveTo(args[0], args[1], args[2], args[3]);
3522
- lastX = args[2];
3523
- lastY = args[3];
3524
- break;
3525
- case "s":
3526
- this._smoothBezierCurveTo(
3527
- lastX + args[0],
3528
- lastY + args[1],
3529
- lastX + args[2],
3530
- lastY + args[3]
3531
- );
3532
- lastX += args[2];
3533
- lastY += args[3];
3534
- break;
3535
- case "T":
3536
- this._smoothQuadraticCurveTo(lastX = args[0], lastY = args[1]);
3537
- break;
3538
- case "t":
3539
- this._smoothQuadraticCurveTo(lastX += args[0], lastY += args[1]);
3540
- break;
3541
- case "A":
3542
- this._addCall("ellipticalArc", [args[0], args[1], args[2], args[3], args[4], args[5], args[6]]);
3543
- lastX = args[5];
3544
- lastY = args[6];
3545
- break;
3546
- case "a":
3547
- this._addCall("ellipticalArc", [args[0], args[1], args[2], args[3], args[4], args[5], args[6]]);
3548
- lastX += args[5];
3549
- lastY += args[6];
3550
- break;
3551
- case "Z":
3552
- case "z":
3553
- this._addCall("closePath");
3554
- if (subpaths.length > 0) {
3555
- currentSubPath = subpaths.pop();
3556
- if (currentSubPath) {
3557
- lastX = currentSubPath.startX;
3558
- lastY = currentSubPath.startY;
3559
- } else {
3560
- lastX = 0;
3561
- lastY = 0;
3562
- }
3563
- }
3564
- currentSubPath = null;
3565
- break;
3566
- default:
3567
- console.warn(`Unknown SVG path command: ${command}`);
3568
- }
3569
- if (command !== "Z" && command !== "z") {
3570
- if (currentSubPath === null) {
3571
- currentSubPath = { startX: lastX, startY: lastY };
3572
- subpaths.push(currentSubPath);
3573
- }
3574
- }
3575
- }
3576
- }
3577
- _getLastPoint(out) {
3578
- let index = this._calls.length - 1;
3579
- let call = this._calls[index];
3580
- if (!call) {
3581
- out.x = 0;
3582
- out.y = 0;
3583
- return out;
3584
- }
3585
- while (call.method === "closePath") {
3586
- index--;
3587
- if (index < 0) {
3588
- out.x = 0;
3589
- out.y = 0;
3590
- return out;
3591
- }
3592
- call = this._calls[index];
3593
- }
3594
- switch (call.method) {
3595
- case "moveTo":
3596
- case "lineTo":
3597
- out.set(call.args[0], call.args[1]);
3598
- break;
3599
- case "quadraticCurveTo":
3600
- out.set(call.args[2], call.args[3]);
3601
- break;
3602
- case "bezierCurveTo":
3603
- out.set(call.args[4], call.args[5]);
3604
- break;
3605
- case "arc":
3606
- case "ellipticalArc":
3607
- out.set(call.args[5], call.args[6]);
3608
- break;
3609
- case "addPath":
3610
- call.args[0]._getLastPoint(out);
3611
- break;
3612
- }
3613
- return out;
3614
- }
3615
- _smoothBezierCurveTo(cp2x, cp2y, x, y, smoothness) {
3616
- const last = this._calls[this._calls.length - 1];
3617
- const lastPoint = this._getLastPoint(Point.shared);
3618
- let cp1x;
3619
- let cp1y;
3620
- if (!last || last.method !== "bezierCurveTo") {
3621
- cp1x = lastPoint.x;
3622
- cp1y = lastPoint.y;
3623
- } else {
3624
- cp1x = last.args[2];
3625
- cp1y = last.args[3];
3626
- const currentX = lastPoint.x;
3627
- const currentY = lastPoint.y;
3628
- cp1x = currentX + (currentX - cp1x);
3629
- cp1y = currentY + (currentY - cp1y);
3630
- }
3631
- this._addCall("bezierCurveTo", [cp1x, cp1y, cp2x, cp2y, x, y, smoothness]);
3632
- return this;
3633
- }
3634
- _smoothQuadraticCurveTo(x, y, smoothness) {
3635
- const last = this._calls[this._calls.length - 1];
3636
- const lastPoint = this._getLastPoint(Point.shared);
3637
- let cpx1;
3638
- let cpy1;
3639
- if (!last || last.method !== "quadraticCurveTo") {
3640
- cpx1 = lastPoint.x;
3641
- cpy1 = lastPoint.y;
3642
- } else {
3643
- cpx1 = last.args[0];
3644
- cpy1 = last.args[1];
3645
- const currentX = lastPoint.x;
3646
- const currentY = lastPoint.y;
3647
- cpx1 = currentX + (currentX - cpx1);
3648
- cpy1 = currentY + (currentY - cpy1);
3649
- }
3650
- this._addCall("quadraticCurveTo", [cpx1, cpy1, x, y, smoothness]);
3651
- return this;
3652
- }
3653
- }
3654
-
3655
- const tempRectangle = new Rectangle();
3656
- class Path2D {
3657
- _polygon;
3658
- _bounds = new Bounds();
3659
- shapes = [];
3660
- get bounds() {
3661
- const bounds = this._bounds;
3662
- bounds.clear();
3663
- const shapes = this.shapes;
3664
- for (let i = 0; i < shapes.length; i++) {
3665
- const shape = shapes[i];
3666
- const boundsRect = shape.shape.getBounds(tempRectangle);
3667
- if (shape.transform) {
3668
- bounds.addRect(boundsRect, shape.transform);
3669
- } else {
3670
- bounds.addRect(boundsRect);
3671
- }
3672
- }
3673
- return bounds;
3674
- }
3675
- startPolygon(x, y) {
3676
- if (this._polygon) {
3677
- this.endPolygon();
3678
- }
3679
- this._polygon = new Polygon([x, y]);
3680
- return this;
3681
- }
3682
- endPolygon(closePath = false) {
3683
- const polygon = this._polygon;
3684
- if (polygon && polygon.points.length > 2) {
3685
- polygon.closed = closePath;
3686
- this.shapes.push({
3687
- shape: polygon
3688
- });
3689
- }
3690
- this._polygon = void 0;
3691
- return this;
3692
- }
3693
- ensurePolygon(start = true) {
3694
- if (this._polygon)
3695
- return;
3696
- this._polygon = new Polygon();
3697
- if (start) {
3698
- const lastShape = this.shapes[this.shapes.length - 1];
3699
- if (lastShape) {
3700
- let lx = lastShape.shape.x;
3701
- let ly = lastShape.shape.y;
3702
- if (!lastShape.transform?.isIdentity()) {
3703
- const t = lastShape.transform.toObject();
3704
- const tempX = lx;
3705
- lx = t.a * lx + t.c * ly + t.tx;
3706
- ly = t.b * tempX + t.d * ly + t.ty;
3707
- }
3708
- this._polygon.points.push(lx, ly);
3709
- } else {
3710
- this._polygon.points.push(0, 0);
3711
- }
3712
- }
3713
- }
3714
- beginPath() {
3715
- return this;
3716
- }
3717
- moveTo(x, y) {
3718
- this.startPolygon(x, y);
3719
- return this;
3720
- }
3721
- lineTo(x, y) {
3722
- this.ensurePolygon();
3723
- const points = this._polygon.points;
3724
- const fromX = points[points.length - 2];
3725
- const fromY = points[points.length - 1];
3726
- if (fromX !== x || fromY !== y) {
3727
- points.push(x, y);
3728
- }
3729
- return this;
3730
- }
3731
- bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y, smoothness) {
3732
- this.ensurePolygon();
3733
- buildAdaptiveBezier(
3734
- this._polygon.points,
3735
- this._polygon.lastX,
3736
- this._polygon.lastY,
3737
- cp1x,
3738
- cp1y,
3739
- cp2x,
3740
- cp2y,
3741
- x,
3742
- y,
3743
- smoothness
3744
- );
3745
- return this;
3746
- }
3747
- quadraticCurveTo(cp1x, cp1y, x, y, smoothing) {
3748
- this.ensurePolygon();
3749
- buildAdaptiveQuadratic(
3750
- this._polygon.points,
3751
- this._polygon.lastX,
3752
- this._polygon.lastY,
3753
- cp1x,
3754
- cp1y,
3755
- x,
3756
- y,
3757
- smoothing
3758
- );
3759
- return this;
3760
- }
3761
- rect(x, y, width, height, transform) {
3762
- this.addShape(new Rectangle(x, y, width, height), transform);
3763
- }
3764
- roundRect(x, y, width, height, radii, transform) {
3765
- this.addShape(new RoundedRectangle(x, y, width, height, radii), transform);
3766
- }
3767
- ellipse(x, y, radiusX, radiusY, transform) {
3768
- this.addShape(new Ellipse(x, y, radiusX, radiusY), transform);
3769
- }
3770
- arc(x, y, radius, startAngle, endAngle, counterclockwise) {
3771
- this.ensurePolygon(false);
3772
- const points = this._polygon.points;
3773
- buildArc(points, x, y, radius, startAngle, endAngle, counterclockwise);
3774
- return this;
3775
- }
3776
- ellipticalArc(rx, ry, xAxisRotation, largeArcFlag, sweepFlag, x, y) {
3777
- buildArcToSvg(
3778
- this._polygon.points,
3779
- this._polygon.lastX,
3780
- this._polygon.lastY,
3781
- x,
3782
- y,
3783
- rx,
3784
- ry,
3785
- xAxisRotation,
3786
- largeArcFlag,
3787
- sweepFlag
3788
- );
3789
- return this;
3790
- }
3791
- poly(points, close = false, transform) {
3792
- const polygon = new Polygon(points);
3793
- polygon.closed = close;
3794
- this.addShape(polygon, transform);
1581
+ rotate(rad) {
1582
+ this._rotate = rad;
1583
+ this._updateSkew();
1584
+ this._requestUpdateArray();
3795
1585
  return this;
3796
1586
  }
3797
- addShape(shape, transform) {
3798
- this.endPolygon();
3799
- this.shapes.push({ shape, transform });
3800
- return this;
1587
+ rotateX(x) {
1588
+ return this.scaleY(this._rotateToScale(x));
3801
1589
  }
3802
- addPath(path2D) {
3803
- this.endPolygon();
3804
- path2D.endPolygon();
3805
- path2D.shapes.forEach((shape) => {
3806
- this.shapes.push(shape);
3807
- });
3808
- return this;
1590
+ rotateY(y) {
1591
+ return this.scaleX(this._rotateToScale(y));
3809
1592
  }
3810
- addSVGPath(d) {
3811
- this.addPath(new SVGPath(d).path2D);
3812
- return this;
1593
+ rotateZ(z) {
1594
+ return this.rotate(z);
3813
1595
  }
3814
- closePath() {
3815
- this.endPolygon(true);
1596
+ rotate3d(x, y, z, rad) {
1597
+ const [rx, ry, rz] = this._rotate3d(x, y, z, rad);
1598
+ rx && this.rotateX(rx);
1599
+ ry && this.rotateY(ry);
1600
+ rz && this.rotateZ(rz);
3816
1601
  return this;
3817
1602
  }
3818
- buildOutline(points = []) {
3819
- this.shapes.forEach((item) => item.shape.buildOutline(points));
3820
- return points;
3821
- }
3822
- buildGeometry(vertices = [], indices = []) {
3823
- this.shapes.forEach((item) => item.shape.buildGeometry(vertices, indices));
3824
- return {
3825
- vertices,
3826
- indices
3827
- };
1603
+ _rotateToScale(rad) {
1604
+ const val = rad / PI_2;
1605
+ return val <= 0.5 ? val * -4 + 1 : (val - 1) * 4 + 1;
3828
1606
  }
3829
- }
3830
-
3831
- class Matrix2 extends Matrix {
3832
- constructor(array) {
3833
- super(2, 2, array);
1607
+ _rotate3d(x, y, z, rad) {
1608
+ if (x === 1 && y === 0 && z === 0) {
1609
+ return [rad, 0, 0];
1610
+ } else if (x === 0 && y === 1 && z === 0) {
1611
+ return [0, rad, 0];
1612
+ } else if (x === 0 && y === 0) {
1613
+ return [0, 0, rad];
1614
+ } else {
1615
+ const cos = Math.cos(rad);
1616
+ const sin = Math.sin(rad);
1617
+ const m11 = cos + x * x * (1 - cos);
1618
+ const m12 = x * y * (1 - cos) - z * sin;
1619
+ const m13 = x * z * (1 - cos) + y * sin;
1620
+ const m22 = cos + y * y * (1 - cos);
1621
+ const m23 = y * z * (1 - cos) - x * sin;
1622
+ const m33 = cos + z * z * (1 - cos);
1623
+ const rotateX = -Math.atan2(-m23, m22);
1624
+ const rotateY = -Math.atan2(m13, Math.sqrt(m23 * m23 + m33 * m33));
1625
+ const rotateZ = -Math.atan2(-m12, m11);
1626
+ return [rotateX, rotateY, rotateZ];
1627
+ }
3834
1628
  }
3835
- }
3836
-
3837
- class Matrix4 extends Matrix {
3838
- constructor(array) {
3839
- super(4, 4, array);
1629
+ applyToPoint(x, y) {
1630
+ const { a, c, tx, b, d, ty } = this.toObject();
1631
+ return [
1632
+ a * x + c * y + tx,
1633
+ b * x + d * y + ty
1634
+ ];
3840
1635
  }
3841
- }
3842
-
3843
- class Projection2D extends Matrix3 {
3844
- constructor(_x = 0, _y = 0, _width = 0, _height = 0, _flipY = false) {
3845
- super();
3846
- this._x = _x;
3847
- this._y = _y;
3848
- this._width = _width;
3849
- this._height = _height;
3850
- this._flipY = _flipY;
3851
- this._performUpdateArray();
1636
+ inverse() {
1637
+ return this.clone().invert();
3852
1638
  }
3853
- flipY(flipY) {
3854
- if (this._flipY !== flipY) {
3855
- this._flipY = flipY;
1639
+ update() {
1640
+ let updated = false;
1641
+ if (this._needsUpdateArray) {
1642
+ this._needsUpdateArray = false;
3856
1643
  this._performUpdateArray();
1644
+ updated = true;
3857
1645
  }
3858
- return this;
3859
- }
3860
- translate(x, y) {
3861
- if (this._x !== x || this._y !== y) {
3862
- this._x = x;
3863
- this._y = y;
3864
- this._performUpdateArray();
1646
+ if (this._needsUpdateFields) {
1647
+ this._needsUpdateFields = false;
1648
+ this._performUpdateFields();
1649
+ updated = true;
3865
1650
  }
3866
- return this;
1651
+ return updated;
3867
1652
  }
3868
- resize(width, height) {
3869
- if (this._width !== width || this._height !== height) {
3870
- this._width = width;
3871
- this._height = height;
3872
- this._performUpdateArray();
3873
- }
3874
- return this;
1653
+ isIdentity() {
1654
+ const { a, b, c, d, tx, ty } = this.toObject();
1655
+ return a === 1 && b === 0 && c === 0 && d === 1 && tx === 0 && ty === 0;
3875
1656
  }
3876
- _performUpdateArray() {
3877
- const width = this._width;
3878
- const height = this._height;
3879
- if (!width || !height) {
3880
- return;
3881
- }
3882
- const x = this._x;
3883
- const y = this._y;
3884
- const sign = !this._flipY ? 1 : -1;
3885
- const a = 1 / width * 2;
3886
- const d = sign * (1 / height * 2);
3887
- const tx = -1 - x * a;
3888
- const ty = -sign - y * d;
3889
- this.set([
3890
- a,
3891
- 0,
3892
- tx,
3893
- 0,
3894
- d,
3895
- ty,
3896
- 0,
3897
- 0,
3898
- 1
3899
- ]);
1657
+ toObject() {
1658
+ const [a, c, tx, b, d, ty, , , tz] = this._array;
1659
+ return { a, c, tx, b, d, ty, tz };
3900
1660
  }
3901
1661
  }
3902
1662
 
@@ -4005,14 +1765,14 @@ class Vector4 extends Vector {
4005
1765
  }
4006
1766
  }
4007
1767
 
4008
- var __defProp$x = Object.defineProperty;
1768
+ var __defProp$w = Object.defineProperty;
4009
1769
  var __getOwnPropDesc$t = Object.getOwnPropertyDescriptor;
4010
- var __decorateClass$x = (decorators, target, key, kind) => {
1770
+ var __decorateClass$w = (decorators, target, key, kind) => {
4011
1771
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$t(target, key) : target;
4012
1772
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
4013
1773
  if (decorator = decorators[i])
4014
1774
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
4015
- if (kind && result) __defProp$x(target, key, result);
1775
+ if (kind && result) __defProp$w(target, key, result);
4016
1776
  return result;
4017
1777
  };
4018
1778
  var InternalMode = /* @__PURE__ */ ((InternalMode2) => {
@@ -4410,22 +2170,22 @@ exports.Node = class Node extends Reference {
4410
2170
  return node;
4411
2171
  }
4412
2172
  };
4413
- __decorateClass$x([
2173
+ __decorateClass$w([
4414
2174
  property()
4415
2175
  ], exports.Node.prototype, "name", 2);
4416
- __decorateClass$x([
2176
+ __decorateClass$w([
4417
2177
  property()
4418
2178
  ], exports.Node.prototype, "mask", 2);
4419
- __decorateClass$x([
2179
+ __decorateClass$w([
4420
2180
  property({ default: "visible" })
4421
2181
  ], exports.Node.prototype, "visibility", 2);
4422
- __decorateClass$x([
2182
+ __decorateClass$w([
4423
2183
  property({ default: 0 })
4424
2184
  ], exports.Node.prototype, "visibleDelay", 2);
4425
- __decorateClass$x([
2185
+ __decorateClass$w([
4426
2186
  property({ default: Number.MAX_SAFE_INTEGER })
4427
2187
  ], exports.Node.prototype, "visibleDuration", 2);
4428
- exports.Node = __decorateClass$x([
2188
+ exports.Node = __decorateClass$w([
4429
2189
  customNode("Node")
4430
2190
  ], exports.Node);
4431
2191
 
@@ -4455,14 +2215,14 @@ class RenderStack {
4455
2215
  }
4456
2216
  }
4457
2217
 
4458
- var __defProp$w = Object.defineProperty;
2218
+ var __defProp$v = Object.defineProperty;
4459
2219
  var __getOwnPropDesc$s = Object.getOwnPropertyDescriptor;
4460
- var __decorateClass$w = (decorators, target, key, kind) => {
2220
+ var __decorateClass$v = (decorators, target, key, kind) => {
4461
2221
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$s(target, key) : target;
4462
2222
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
4463
2223
  if (decorator = decorators[i])
4464
2224
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
4465
- if (kind && result) __defProp$w(target, key, result);
2225
+ if (kind && result) __defProp$v(target, key, result);
4466
2226
  return result;
4467
2227
  };
4468
2228
  exports.Timer = class Timer extends exports.Node {
@@ -4504,29 +2264,29 @@ exports.Timer = class Timer extends exports.Node {
4504
2264
  this.addTime(delta);
4505
2265
  }
4506
2266
  };
4507
- __decorateClass$w([
2267
+ __decorateClass$v([
4508
2268
  property({ default: 0 })
4509
2269
  ], exports.Timer.prototype, "start", 2);
4510
- __decorateClass$w([
2270
+ __decorateClass$v([
4511
2271
  property({ default: 0 })
4512
2272
  ], exports.Timer.prototype, "current", 2);
4513
- __decorateClass$w([
2273
+ __decorateClass$v([
4514
2274
  property({ default: Number.MAX_SAFE_INTEGER })
4515
2275
  ], exports.Timer.prototype, "end", 2);
4516
- __decorateClass$w([
2276
+ __decorateClass$v([
4517
2277
  property({ default: false })
4518
2278
  ], exports.Timer.prototype, "loop", 2);
4519
- exports.Timer = __decorateClass$w([
2279
+ exports.Timer = __decorateClass$v([
4520
2280
  customNode("Timer")
4521
2281
  ], exports.Timer);
4522
2282
 
4523
- var __defProp$v = Object.defineProperty;
4524
- var __decorateClass$v = (decorators, target, key, kind) => {
2283
+ var __defProp$u = Object.defineProperty;
2284
+ var __decorateClass$u = (decorators, target, key, kind) => {
4525
2285
  var result = void 0 ;
4526
2286
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
4527
2287
  if (decorator = decorators[i])
4528
2288
  result = (decorator(target, key, result) ) || result;
4529
- if (result) __defProp$v(target, key, result);
2289
+ if (result) __defProp$u(target, key, result);
4530
2290
  return result;
4531
2291
  };
4532
2292
  class Texture extends Resource {
@@ -4652,22 +2412,22 @@ class Texture extends Resource {
4652
2412
  }
4653
2413
  }
4654
2414
  }
4655
- __decorateClass$v([
2415
+ __decorateClass$u([
4656
2416
  protectedProperty()
4657
2417
  ], Texture.prototype, "source");
4658
- __decorateClass$v([
2418
+ __decorateClass$u([
4659
2419
  protectedProperty({ default: 0 })
4660
2420
  ], Texture.prototype, "width");
4661
- __decorateClass$v([
2421
+ __decorateClass$u([
4662
2422
  protectedProperty({ default: 0 })
4663
2423
  ], Texture.prototype, "height");
4664
- __decorateClass$v([
2424
+ __decorateClass$u([
4665
2425
  protectedProperty({ default: "linear" })
4666
2426
  ], Texture.prototype, "filterMode");
4667
- __decorateClass$v([
2427
+ __decorateClass$u([
4668
2428
  protectedProperty({ default: "clamp_to_edge" })
4669
2429
  ], Texture.prototype, "wrapMode");
4670
- __decorateClass$v([
2430
+ __decorateClass$u([
4671
2431
  protectedProperty({ default: 1 })
4672
2432
  ], Texture.prototype, "pixelRatio");
4673
2433
 
@@ -4803,13 +2563,13 @@ class PixelsTexture extends Texture {
4803
2563
  }
4804
2564
  }
4805
2565
 
4806
- var __defProp$u = Object.defineProperty;
4807
- var __decorateClass$u = (decorators, target, key, kind) => {
2566
+ var __defProp$t = Object.defineProperty;
2567
+ var __decorateClass$t = (decorators, target, key, kind) => {
4808
2568
  var result = void 0 ;
4809
2569
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
4810
2570
  if (decorator = decorators[i])
4811
2571
  result = (decorator(target, key, result) ) || result;
4812
- if (result) __defProp$u(target, key, result);
2572
+ if (result) __defProp$t(target, key, result);
4813
2573
  return result;
4814
2574
  };
4815
2575
  function resolveOptions(options) {
@@ -5052,10 +2812,10 @@ const _VideoTexture = class _VideoTexture extends Texture {
5052
2812
  }
5053
2813
  }
5054
2814
  };
5055
- __decorateClass$u([
2815
+ __decorateClass$t([
5056
2816
  protectedProperty({ default: true })
5057
2817
  ], _VideoTexture.prototype, "autoUpdate");
5058
- __decorateClass$u([
2818
+ __decorateClass$t([
5059
2819
  protectedProperty({ default: 0 })
5060
2820
  ], _VideoTexture.prototype, "fps");
5061
2821
  let VideoTexture = _VideoTexture;
@@ -5064,14 +2824,14 @@ class ViewportTexture extends PixelsTexture {
5064
2824
  //
5065
2825
  }
5066
2826
 
5067
- var __defProp$t = Object.defineProperty;
2827
+ var __defProp$s = Object.defineProperty;
5068
2828
  var __getOwnPropDesc$r = Object.getOwnPropertyDescriptor;
5069
- var __decorateClass$t = (decorators, target, key, kind) => {
2829
+ var __decorateClass$s = (decorators, target, key, kind) => {
5070
2830
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$r(target, key) : target;
5071
2831
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
5072
2832
  if (decorator = decorators[i])
5073
2833
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
5074
- if (kind && result) __defProp$t(target, key, result);
2834
+ if (kind && result) __defProp$s(target, key, result);
5075
2835
  return result;
5076
2836
  };
5077
2837
  exports.Viewport = class Viewport extends exports.Node {
@@ -5192,19 +2952,19 @@ exports.Viewport = class Viewport extends exports.Node {
5192
2952
  return this._projection.toArray(transpose);
5193
2953
  }
5194
2954
  };
5195
- __decorateClass$t([
2955
+ __decorateClass$s([
5196
2956
  property({ default: 0 })
5197
2957
  ], exports.Viewport.prototype, "x", 2);
5198
- __decorateClass$t([
2958
+ __decorateClass$s([
5199
2959
  property({ default: 0 })
5200
2960
  ], exports.Viewport.prototype, "y", 2);
5201
- __decorateClass$t([
2961
+ __decorateClass$s([
5202
2962
  property({ default: 0 })
5203
2963
  ], exports.Viewport.prototype, "width", 2);
5204
- __decorateClass$t([
2964
+ __decorateClass$s([
5205
2965
  property({ default: 0 })
5206
2966
  ], exports.Viewport.prototype, "height", 2);
5207
- exports.Viewport = __decorateClass$t([
2967
+ exports.Viewport = __decorateClass$s([
5208
2968
  customNode({
5209
2969
  tag: "Viewport",
5210
2970
  renderable: true
@@ -5623,30 +3383,7 @@ class ColorTexture extends Texture {
5623
3383
  }
5624
3384
  }
5625
3385
 
5626
- var __defProp$s = Object.defineProperty;
5627
- var __decorateClass$s = (decorators, target, key, kind) => {
5628
- var result = void 0 ;
5629
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
5630
- if (decorator = decorators[i])
5631
- result = (decorator(target, key, result) ) || result;
5632
- if (result) __defProp$s(target, key, result);
5633
- return result;
5634
- };
5635
- function proxy$1() {
5636
- return function(target, method) {
5637
- Object.defineProperty(target.constructor.prototype, method, {
5638
- get() {
5639
- return (...args) => {
5640
- this._path2D[method](...args);
5641
- return this;
5642
- };
5643
- },
5644
- configurable: true,
5645
- enumerable: true
5646
- });
5647
- };
5648
- }
5649
- class CanvasContext {
3386
+ class CanvasContext extends modernPath2d.Path2D {
5650
3387
  textureTransform;
5651
3388
  fillStyle;
5652
3389
  strokeStyle;
@@ -5654,7 +3391,6 @@ class CanvasContext {
5654
3391
  lineJoin;
5655
3392
  lineWidth;
5656
3393
  miterLimit;
5657
- _path2D = new Path2D();
5658
3394
  _defaultStyle = Texture.EMPTY;
5659
3395
  _stroked = [];
5660
3396
  _filled = [];
@@ -5667,10 +3403,9 @@ class CanvasContext {
5667
3403
  texture = new ColorTexture(this.strokeStyle);
5668
3404
  }
5669
3405
  }
5670
- this._path2D.endPolygon();
5671
- if (this._path2D.shapes.length) {
3406
+ if (this.curves.length) {
5672
3407
  this._stroked.push({
5673
- shapes: this._path2D.shapes.slice(),
3408
+ shapes: this.curves.slice(),
5674
3409
  texture,
5675
3410
  textureTransform: this.textureTransform,
5676
3411
  style: {
@@ -5681,7 +3416,7 @@ class CanvasContext {
5681
3416
  miterLimit: this.miterLimit ?? 10
5682
3417
  }
5683
3418
  });
5684
- this._path2D.shapes.length = 0;
3419
+ this.curves.length = 0;
5685
3420
  }
5686
3421
  }
5687
3422
  fillRect(x, y, width, height) {
@@ -5700,11 +3435,11 @@ class CanvasContext {
5700
3435
  }
5701
3436
  }
5702
3437
  this._filled.push({
5703
- shapes: this._path2D.shapes.slice(),
3438
+ shapes: this.curves.slice(),
5704
3439
  texture,
5705
3440
  textureTransform: this.textureTransform
5706
3441
  });
5707
- this._path2D.shapes.length = 0;
3442
+ this.curves.length = 0;
5708
3443
  }
5709
3444
  reset() {
5710
3445
  this.strokeStyle = void 0;
@@ -5714,8 +3449,7 @@ class CanvasContext {
5714
3449
  this.lineJoin = void 0;
5715
3450
  this.lineWidth = void 0;
5716
3451
  this.miterLimit = void 0;
5717
- this._path2D.endPolygon();
5718
- this._path2D.shapes.length = 0;
3452
+ this.curves.length = 0;
5719
3453
  this._stroked.length = 0;
5720
3454
  this._filled.length = 0;
5721
3455
  }
@@ -5756,14 +3490,20 @@ class CanvasContext {
5756
3490
  texture = void 0;
5757
3491
  };
5758
3492
  for (let len = this._stroked.length, i = 0; i < len; i++) {
3493
+ startUv = vertices.length;
5759
3494
  const graphics = this._stroked[i];
5760
3495
  texture ??= graphics.texture;
5761
3496
  const points = [];
5762
3497
  for (let len2 = graphics.shapes.length, i2 = 0; i2 < len2; i2++) {
5763
- graphics.shapes[i2].shape.buildOutline(points);
3498
+ graphics.shapes[i2].getAdaptivePointArray(points);
5764
3499
  }
5765
- startUv = vertices.length;
5766
- buildLine(points, graphics.style, false, true, vertices, 0, 0, indices);
3500
+ modernPath2d.strokeTriangulate(points, {
3501
+ vertices,
3502
+ indices,
3503
+ lineStyle: graphics.style,
3504
+ flipAlignment: false,
3505
+ closed: true
3506
+ });
5767
3507
  this.buildUvs(startUv, vertices, uvs, graphics.texture, graphics.textureTransform);
5768
3508
  push("stroke");
5769
3509
  }
@@ -5775,7 +3515,10 @@ class CanvasContext {
5775
3515
  }
5776
3516
  startUv = vertices.length;
5777
3517
  for (let len2 = graphics.shapes.length, i2 = 0; i2 < len2; i2++) {
5778
- graphics.shapes[i2].shape.buildGeometry(vertices, indices);
3518
+ graphics.shapes[i2].fillTriangulate({
3519
+ vertices,
3520
+ indices
3521
+ });
5779
3522
  }
5780
3523
  this.buildUvs(startUv, vertices, uvs, graphics.texture, graphics.textureTransform);
5781
3524
  }
@@ -5785,48 +3528,6 @@ class CanvasContext {
5785
3528
  return batchables;
5786
3529
  }
5787
3530
  }
5788
- __decorateClass$s([
5789
- proxy$1()
5790
- ], CanvasContext.prototype, "moveTo");
5791
- __decorateClass$s([
5792
- proxy$1()
5793
- ], CanvasContext.prototype, "lineTo");
5794
- __decorateClass$s([
5795
- proxy$1()
5796
- ], CanvasContext.prototype, "bezierCurveTo");
5797
- __decorateClass$s([
5798
- proxy$1()
5799
- ], CanvasContext.prototype, "quadraticCurveTo");
5800
- __decorateClass$s([
5801
- proxy$1()
5802
- ], CanvasContext.prototype, "ellipticalArc");
5803
- __decorateClass$s([
5804
- proxy$1()
5805
- ], CanvasContext.prototype, "rect");
5806
- __decorateClass$s([
5807
- proxy$1()
5808
- ], CanvasContext.prototype, "roundRect");
5809
- __decorateClass$s([
5810
- proxy$1()
5811
- ], CanvasContext.prototype, "ellipse");
5812
- __decorateClass$s([
5813
- proxy$1()
5814
- ], CanvasContext.prototype, "arc");
5815
- __decorateClass$s([
5816
- proxy$1()
5817
- ], CanvasContext.prototype, "poly");
5818
- __decorateClass$s([
5819
- proxy$1()
5820
- ], CanvasContext.prototype, "addShape");
5821
- __decorateClass$s([
5822
- proxy$1()
5823
- ], CanvasContext.prototype, "addPath");
5824
- __decorateClass$s([
5825
- proxy$1()
5826
- ], CanvasContext.prototype, "addSvgPath");
5827
- __decorateClass$s([
5828
- proxy$1()
5829
- ], CanvasContext.prototype, "closePath");
5830
3531
 
5831
3532
  class Loader {
5832
3533
  }
@@ -6263,61 +3964,22 @@ function getComputedFilterColorMatrix() {
6263
3964
  return m;
6264
3965
  }
6265
3966
 
6266
- class Style2DOffsetModule extends Style2DModule {
6267
- install(Style2D) {
6268
- defineProperty(Style2D, "offsetPath");
6269
- defineProperty(Style2D, "offsetAnchor");
6270
- defineProperty(Style2D, "offsetDistance");
6271
- defineProperty(Style2D, "offsetPosition");
6272
- Style2D.prototype.getComputedOffset = getComputedOffset;
6273
- }
6274
- }
6275
- function getComputedOffset() {
6276
- const offsetPath = this.offsetPath;
6277
- if (!offsetPath)
6278
- return;
6279
- if (offsetPath.startsWith("path")) {
6280
- const path = offsetPath.match(/path\(["'](.+)["']\)/)?.[1];
6281
- if (!path)
6282
- return;
6283
- path.split(" ").forEach((arg) => {
6284
- });
6285
- } else if (offsetPath.startsWith("ray")) ; else if (offsetPath.startsWith("url")) ; else if (offsetPath.startsWith("circle")) ; else if (offsetPath.startsWith("ellipse")) ; else if (offsetPath.startsWith("insett")) ; else if (offsetPath.startsWith("polygon")) ; else if (offsetPath.startsWith("rect")) ; else if (offsetPath.startsWith("xywh")) ;
6286
- }
6287
-
6288
3967
  class Style2DTextModule extends Style2DModule {
6289
3968
  install(Style2D) {
6290
- defineProperty(Style2D, "color", { default: "#000000" });
6291
- defineProperty(Style2D, "fontSize", { default: 14 });
6292
- defineProperty(Style2D, "fontWeight", { default: "normal" });
6293
- defineProperty(Style2D, "fontFamily", { default: "sans-serif" });
6294
- defineProperty(Style2D, "fontStyle", { default: "normal" });
6295
- defineProperty(Style2D, "fontKerning", { default: "normal" });
6296
- defineProperty(Style2D, "textWrap", { default: "wrap" });
6297
- defineProperty(Style2D, "textAlign", { default: "start" });
6298
- defineProperty(Style2D, "verticalAlign", { default: "middle" });
6299
- defineProperty(Style2D, "textTransform", { default: "none" });
6300
- defineProperty(Style2D, "textDecoration", { default: null });
6301
- defineProperty(Style2D, "textStrokeWidth", { default: 0 });
6302
- defineProperty(Style2D, "textStrokeColor", { default: "#000000" });
3969
+ const style = modernIdoc.getDefaultTextStyle();
3970
+ for (const key in style) {
3971
+ defineProperty(Style2D, key, { default: style[key] });
3972
+ }
6303
3973
  defineProperty(Style2D, "direction", { default: "inherit" });
6304
- defineProperty(Style2D, "lineHeight", { default: 1 });
6305
- defineProperty(Style2D, "letterSpacing", { default: 0 });
6306
- defineProperty(Style2D, "writingMode", { default: "horizontal-tb" });
6307
3974
  }
6308
3975
  }
6309
3976
 
6310
3977
  class Style2DTransformModule extends Style2DModule {
6311
3978
  install(Style2D) {
6312
- defineProperty(Style2D, "left", { default: 0 });
6313
- defineProperty(Style2D, "top", { default: 0 });
6314
- defineProperty(Style2D, "width", { default: 0 });
6315
- defineProperty(Style2D, "height", { default: 0 });
6316
- defineProperty(Style2D, "rotate", { default: 0 });
6317
- defineProperty(Style2D, "scaleX", { default: 1 });
6318
- defineProperty(Style2D, "scaleY", { default: 1 });
6319
- defineProperty(Style2D, "transform");
6320
- defineProperty(Style2D, "transformOrigin", { default: "center" });
3979
+ const style = modernIdoc.getDefaultTransformStyle();
3980
+ for (const key in style) {
3981
+ defineProperty(Style2D, key, { default: style[key] });
3982
+ }
6321
3983
  Style2D.prototype.getComputedTransform = getComputedTransform;
6322
3984
  Style2D.prototype.getComputedTransformOrigin = getComputedTransformOrigin;
6323
3985
  }
@@ -6326,7 +3988,11 @@ function getComputedTransform() {
6326
3988
  const transform = new Transform2D();
6327
3989
  const transform3d = new Transform2D(false);
6328
3990
  const transform2d = new Transform2D(false).scale(this.scaleX, this.scaleY).translate(this.left, this.top).rotate(this.rotate * DEG_TO_RAD);
6329
- parseCssFunctions(this.transform ?? "", { width: this.width, height: this.height }).forEach(({ name, args }) => {
3991
+ let _transform = this.transform;
3992
+ if (!_transform || _transform === "none") {
3993
+ _transform = "";
3994
+ }
3995
+ parseCssFunctions(_transform, { width: this.width, height: this.height }).forEach(({ name, args }) => {
6330
3996
  const values = args.map((arg) => arg.normalizedIntValue);
6331
3997
  transform.identity();
6332
3998
  switch (name) {
@@ -6437,15 +4103,6 @@ function getComputedTransformOrigin() {
6437
4103
  });
6438
4104
  }
6439
4105
 
6440
- const modules = {
6441
- __proto__: null,
6442
- Style2DBackgroundModule: Style2DBackgroundModule,
6443
- Style2DFilterModule: Style2DFilterModule,
6444
- Style2DOffsetModule: Style2DOffsetModule,
6445
- Style2DTextModule: Style2DTextModule,
6446
- Style2DTransformModule: Style2DTransformModule
6447
- };
6448
-
6449
4106
  var __defProp$r = Object.defineProperty;
6450
4107
  var __decorateClass$r = (decorators, target, key, kind) => {
6451
4108
  var result = void 0 ;
@@ -6499,7 +4156,12 @@ __decorateClass$r([
6499
4156
  __decorateClass$r([
6500
4157
  property({ default: "visible" })
6501
4158
  ], Style2D.prototype, "overflow");
6502
- Object.values(modules).forEach((Module) => {
4159
+ [
4160
+ Style2DBackgroundModule,
4161
+ Style2DFilterModule,
4162
+ Style2DTextModule,
4163
+ Style2DTransformModule
4164
+ ].forEach((Module) => {
6503
4165
  new Module().install(Style2D);
6504
4166
  });
6505
4167
 
@@ -7068,7 +4730,7 @@ exports.Node2D = class Node2D extends exports.CanvasItem {
7068
4730
  width = newWidth;
7069
4731
  height = newHeight;
7070
4732
  }
7071
- return new Rectangle(left, top, width, height);
4733
+ return new modernPath2d.BoundingBox(left, top, width, height);
7072
4734
  }
7073
4735
  _onUpdateStyleProperty(key, value, oldValue) {
7074
4736
  super._onUpdateStyleProperty(key, value, oldValue);
@@ -7558,6 +5220,9 @@ var __decorateClass$k = (decorators, target, key, kind) => {
7558
5220
  const textStyles = new Set(Object.keys(modernText.textDefaultStyle));
7559
5221
  exports.Text2D = class Text2D extends exports.Node2D {
7560
5222
  effects;
5223
+ measureDom;
5224
+ fonts;
5225
+ text = new modernText.Text();
7561
5226
  texture = new Texture(document.createElement("canvas"));
7562
5227
  _subTextsCount = 0;
7563
5228
  constructor(options) {
@@ -7568,6 +5233,9 @@ exports.Text2D = class Text2D extends exports.Node2D {
7568
5233
  super._onUpdateProperty(key, value, oldValue);
7569
5234
  switch (key) {
7570
5235
  case "content":
5236
+ case "effects":
5237
+ case "measureDom":
5238
+ case "fonts":
7571
5239
  case "split":
7572
5240
  this._updateSplit();
7573
5241
  this.requestRedraw();
@@ -7579,6 +5247,13 @@ exports.Text2D = class Text2D extends exports.Node2D {
7579
5247
  });
7580
5248
  }
7581
5249
  }
5250
+ _updateText() {
5251
+ this.text.style = this.style.toJSON();
5252
+ this.text.content = this.content ?? "";
5253
+ this.text.effects = this.effects;
5254
+ this.text.fonts = this.fonts;
5255
+ this.text.measureDom = this.measureDom;
5256
+ }
7582
5257
  _onUpdateStyleProperty(key, value, oldValue) {
7583
5258
  if (key === "height")
7584
5259
  return;
@@ -7622,13 +5297,8 @@ exports.Text2D = class Text2D extends exports.Node2D {
7622
5297
  }
7623
5298
  }
7624
5299
  measure() {
7625
- const result = modernText.measureText({
7626
- content: this.content,
7627
- style: {
7628
- ...this.style.toJSON(),
7629
- height: void 0
7630
- }
7631
- });
5300
+ this._updateText();
5301
+ const result = this.text.measure();
7632
5302
  if (!this.style.width)
7633
5303
  this.style.width = result.boundingBox.width;
7634
5304
  if (!this.style.height)
@@ -7672,12 +5342,10 @@ exports.Text2D = class Text2D extends exports.Node2D {
7672
5342
  if (onText2DRender) {
7673
5343
  onText2DRender();
7674
5344
  } else {
7675
- modernText.renderText({
7676
- view: this.texture.source,
5345
+ this._updateText();
5346
+ this.text.render({
7677
5347
  pixelRatio: this.pixelRatio,
7678
- content: this.content,
7679
- effects: this.effects,
7680
- style: this.style.toJSON()
5348
+ view: this.texture.source
7681
5349
  });
7682
5350
  }
7683
5351
  this.texture.requestUpload();
@@ -7702,6 +5370,12 @@ __decorateClass$k([
7702
5370
  __decorateClass$k([
7703
5371
  property()
7704
5372
  ], exports.Text2D.prototype, "effects", 2);
5373
+ __decorateClass$k([
5374
+ protectedProperty()
5375
+ ], exports.Text2D.prototype, "measureDom", 2);
5376
+ __decorateClass$k([
5377
+ protectedProperty()
5378
+ ], exports.Text2D.prototype, "fonts", 2);
7705
5379
  exports.Text2D = __decorateClass$k([
7706
5380
  customNode("Text2D")
7707
5381
  ], exports.Text2D);
@@ -13725,7 +11399,8 @@ class Engine extends SceneTree {
13725
11399
  } else {
13726
11400
  this.resize(
13727
11401
  width || this.gl.drawingBufferWidth || this.view?.clientWidth || 200,
13728
- height || this.gl.drawingBufferHeight || this.view?.clientHeight || 200
11402
+ height || this.gl.drawingBufferHeight || this.view?.clientHeight || 200,
11403
+ !view
13729
11404
  );
13730
11405
  }
13731
11406
  }
@@ -13864,16 +11539,13 @@ exports.Assets = Assets;
13864
11539
  exports.AudioPipeline = AudioPipeline;
13865
11540
  exports.AudioProcessor = AudioProcessor;
13866
11541
  exports.AudioSpectrum = AudioSpectrum;
13867
- exports.Bounds = Bounds;
13868
11542
  exports.CanvasContext = CanvasContext;
13869
- exports.Circle = Circle;
13870
11543
  exports.Color = Color;
13871
11544
  exports.ColorMatrix = ColorMatrix;
13872
11545
  exports.ColorTexture = ColorTexture;
13873
11546
  exports.DEG_TO_RAD = DEG_TO_RAD;
13874
11547
  exports.DEVICE_PIXEL_RATIO = DEVICE_PIXEL_RATIO;
13875
11548
  exports.EffectMaterial = EffectMaterial;
13876
- exports.Ellipse = Ellipse;
13877
11549
  exports.Engine = Engine;
13878
11550
  exports.EventEmitter = EventEmitter;
13879
11551
  exports.FontLoader = FontLoader;
@@ -13900,21 +11572,16 @@ exports.Matrix4 = Matrix4;
13900
11572
  exports.MouseInputEvent = MouseInputEvent;
13901
11573
  exports.PI = PI;
13902
11574
  exports.PI_2 = PI_2;
13903
- exports.Path2D = Path2D;
13904
11575
  exports.PixelsTexture = PixelsTexture;
13905
- exports.Point = Point;
13906
11576
  exports.PointerInputEvent = PointerInputEvent;
13907
- exports.Polygon = Polygon;
13908
11577
  exports.Projection2D = Projection2D;
13909
11578
  exports.QuadGeometry = QuadGeometry;
13910
11579
  exports.QuadUvGeometry = QuadUvGeometry;
13911
11580
  exports.RAD_TO_DEG = RAD_TO_DEG;
13912
- exports.Rectangle = Rectangle;
13913
11581
  exports.Reference = Reference;
13914
11582
  exports.RenderStack = RenderStack;
13915
11583
  exports.Renderer = Renderer;
13916
11584
  exports.Resource = Resource;
13917
- exports.RoundedRectangle = RoundedRectangle;
13918
11585
  exports.SUPPORTS_AUDIO_CONTEXT = SUPPORTS_AUDIO_CONTEXT;
13919
11586
  exports.SUPPORTS_CLICK_EVENTS = SUPPORTS_CLICK_EVENTS;
13920
11587
  exports.SUPPORTS_CREATE_IMAGE_BITMAP = SUPPORTS_CREATE_IMAGE_BITMAP;
@@ -13929,14 +11596,11 @@ exports.SUPPORTS_WEBKIT_AUDIO_CONTEXT = SUPPORTS_WEBKIT_AUDIO_CONTEXT;
13929
11596
  exports.SUPPORTS_WEBKIT_OFFLINE_AUDIO_CONTEXT = SUPPORTS_WEBKIT_OFFLINE_AUDIO_CONTEXT;
13930
11597
  exports.SUPPORTS_WEB_AUDIO = SUPPORTS_WEB_AUDIO;
13931
11598
  exports.SUPPORTS_WHEEL_EVENTS = SUPPORTS_WHEEL_EVENTS;
13932
- exports.SVGPath = SVGPath;
13933
11599
  exports.SceneTree = SceneTree;
13934
- exports.Star = Star;
13935
11600
  exports.Style2D = Style2D;
13936
11601
  exports.Style2DBackgroundModule = Style2DBackgroundModule;
13937
11602
  exports.Style2DFilterModule = Style2DFilterModule;
13938
11603
  exports.Style2DModule = Style2DModule;
13939
- exports.Style2DOffsetModule = Style2DOffsetModule;
13940
11604
  exports.Style2DTextModule = Style2DTextModule;
13941
11605
  exports.Style2DTransformModule = Style2DTransformModule;
13942
11606
  exports.TextLoader = TextLoader;
@@ -13944,7 +11608,6 @@ exports.Texture = Texture;
13944
11608
  exports.TextureLoader = TextureLoader;
13945
11609
  exports.Ticker = Ticker;
13946
11610
  exports.Transform2D = Transform2D;
13947
- exports.Triangle = Triangle;
13948
11611
  exports.UIInputEvent = UIInputEvent;
13949
11612
  exports.UvGeometry = UvGeometry;
13950
11613
  exports.UvMaterial = UvMaterial;
@@ -13978,23 +11641,11 @@ exports.WebSound = WebSound;
13978
11641
  exports.WheelInputEvent = WheelInputEvent;
13979
11642
  exports._Object = _Object;
13980
11643
  exports.assets = assets;
13981
- exports.buildAdaptiveBezier = buildAdaptiveBezier;
13982
- exports.buildAdaptiveQuadratic = buildAdaptiveQuadratic;
13983
- exports.buildArc = buildArc;
13984
- exports.buildArcTo = buildArcTo;
13985
- exports.buildArcToSvg = buildArcToSvg;
13986
- exports.buildCircle = buildCircle;
13987
- exports.buildLine = buildLine;
13988
- exports.buildPolygon = buildPolygon;
13989
- exports.buildRectangle = buildRectangle;
13990
- exports.buildTriangle = buildTriangle;
13991
11644
  exports.clamp = clamp;
13992
- exports.closePointEps = closePointEps;
13993
11645
  exports.createHTMLCanvas = createHTMLCanvas;
13994
11646
  exports.createNode = createNode;
13995
11647
  exports.crossOrigin = crossOrigin;
13996
11648
  exports.cubicBezier = cubicBezier;
13997
- exports.curveEps = curveEps;
13998
11649
  exports.curves = curves;
13999
11650
  exports.customNode = customNode;
14000
11651
  exports.customNodes = customNodes;
@@ -14024,6 +11675,5 @@ exports.parseCssProperty = parseCssProperty;
14024
11675
  exports.property = property;
14025
11676
  exports.protectedProperty = protectedProperty;
14026
11677
  exports.render = render;
14027
- exports.squaredDistanceToLineSegment = squaredDistanceToLineSegment;
14028
11678
  exports.timingFunctions = timingFunctions;
14029
11679
  exports.uid = uid;