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