@sepveneto/dao 0.0.4 → 0.1.0

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.
Files changed (93) hide show
  1. package/README.md +58 -0
  2. package/dist/Loader.d.ts +3 -3
  3. package/dist/ResourceManager.d.ts +8 -2
  4. package/dist/app/Application.d.ts +18 -0
  5. package/dist/app/ResizePlugin.d.ts +16 -0
  6. package/dist/app/__tests__/Application.test.d.ts +1 -0
  7. package/dist/app/index.d.ts +1 -0
  8. package/dist/assets/Assets.d.ts +1 -0
  9. package/dist/dao.cjs +2 -2
  10. package/dist/dao.cjs.map +1 -0
  11. package/dist/dao.js +2175 -426
  12. package/dist/dao.js.map +1 -0
  13. package/dist/events/FederatedEvent.d.ts +15 -0
  14. package/dist/events/FederatedEventMap.d.ts +13 -0
  15. package/dist/events/__tests__/EventSystem.test.d.ts +1 -0
  16. package/dist/main.d.ts +8 -28
  17. package/dist/maths/Bounds.d.ts +31 -0
  18. package/dist/maths/Matrix.d.ts +85 -0
  19. package/dist/maths/Point.d.ts +17 -0
  20. package/dist/maths/const.d.ts +14 -0
  21. package/dist/maths/index.d.ts +18 -0
  22. package/dist/maths/shapes/Polygon.d.ts +10 -0
  23. package/dist/maths/shapes/Rectangle.d.ts +11 -0
  24. package/dist/renderer/CanvasPool.d.ts +11 -0
  25. package/dist/renderer/InstructionSet.d.ts +18 -0
  26. package/dist/renderer/index.d.ts +66 -0
  27. package/dist/renderer/texture/RenderTexture.d.ts +7 -0
  28. package/dist/renderer/texture/Texture.d.ts +25 -0
  29. package/dist/renderer/texture/TextureSource.d.ts +50 -0
  30. package/dist/scene/ViewContainer.d.ts +22 -0
  31. package/dist/scene/batcher/Batcher.d.ts +10 -0
  32. package/dist/scene/batcher/BatcherPipe.d.ts +34 -0
  33. package/dist/scene/batcher/index.d.ts +2 -0
  34. package/dist/scene/container/Container.d.ts +198 -0
  35. package/dist/scene/container/RenderGroup.d.ts +24 -0
  36. package/dist/scene/container/__tests__/Container.Sort.test.d.ts +1 -0
  37. package/dist/scene/container/__tests__/RenderGroup.test.d.ts +1 -0
  38. package/dist/scene/container/__tests__/transform-visibility.test.d.ts +1 -0
  39. package/dist/scene/container/__tests__/transform.test.d.ts +1 -0
  40. package/dist/scene/container/destroyTypes.d.ts +9 -0
  41. package/dist/scene/container/mixins/childrenHelperMixin.d.ts +5 -0
  42. package/dist/scene/container/mixins/effectMixin.d.ts +16 -0
  43. package/dist/scene/container/mixins/measureMixin.d.ts +14 -0
  44. package/dist/scene/container/mixins/sortMixin.d.ts +13 -0
  45. package/dist/scene/container/utils/updateRenderGroupTransform.d.ts +4 -0
  46. package/dist/scene/container/utils.d.ts +2 -0
  47. package/dist/scene/graphics/Graphics.d.ts +19 -0
  48. package/dist/scene/graphics/GraphicsContext.d.ts +61 -0
  49. package/dist/scene/graphics/GraphicsPipe.d.ts +15 -0
  50. package/dist/scene/graphics/index.d.ts +3 -0
  51. package/dist/scene/graphics/path/GraphicsPath.d.ts +25 -0
  52. package/dist/scene/graphics/path/ShapePath.d.ts +27 -0
  53. package/dist/scene/graphics/path/buildAdaptiveBezier.d.ts +14 -0
  54. package/dist/scene/index.d.ts +6 -0
  55. package/dist/scene/mask/StencilMask.d.ts +14 -0
  56. package/dist/scene/mask/StencilMaskPipe.d.ts +16 -0
  57. package/dist/scene/sprite/Sprite.d.ts +22 -0
  58. package/dist/scene/sprite/SpritePipe.d.ts +12 -0
  59. package/dist/scene/sprite/index.d.ts +2 -0
  60. package/dist/scene/text/Text.d.ts +40 -0
  61. package/dist/scene/text/TextPipe.d.ts +24 -0
  62. package/dist/scene/text/TextStyle.d.ts +632 -0
  63. package/dist/scene/text/TextSystem.d.ts +19 -0
  64. package/dist/scene/text/__tests__/Text.test.d.ts +1 -0
  65. package/dist/scene/text/index.d.ts +2 -0
  66. package/dist/scene/text/utils.d.ts +74 -0
  67. package/dist/system/CanvasContextSystem.d.ts +15 -0
  68. package/dist/system/EventSystem.d.ts +49 -5
  69. package/dist/system/ExtractSystem.d.ts +18 -0
  70. package/dist/system/RenderGroupSystem.d.ts +16 -0
  71. package/dist/system/ViewSystem.d.ts +22 -0
  72. package/dist/system/index.d.ts +2 -0
  73. package/dist/ticker/Ticker.d.ts +290 -0
  74. package/dist/ticker/TickerListener.d.ts +21 -0
  75. package/dist/ticker/index.d.ts +2 -0
  76. package/dist/utils/index.d.ts +12 -0
  77. package/dist/utils/type.d.ts +16 -0
  78. package/dist/utils/uid.d.ts +19 -0
  79. package/package.json +19 -3
  80. package/dist/Camera.d.ts +0 -46
  81. package/dist/Container.d.ts +0 -17
  82. package/dist/Display.d.ts +0 -60
  83. package/dist/Factory.d.ts +0 -7
  84. package/dist/GameObject.d.ts +0 -17
  85. package/dist/Projection.d.ts +0 -25
  86. package/dist/Renderer.d.ts +0 -6
  87. package/dist/Scene.d.ts +0 -27
  88. package/dist/SortStragety.d.ts +0 -10
  89. package/dist/World.d.ts +0 -7
  90. package/dist/system/InputSystem.d.ts +0 -37
  91. package/dist/system/SortSystem.d.ts +0 -8
  92. package/dist/system/TweenManager.d.ts +0 -49
  93. package/dist/utils.d.ts +0 -5
package/dist/dao.js CHANGED
@@ -1,541 +1,2290 @@
1
- var GameObject = class {
1
+ var __create = Object.create, __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __getOwnPropNames = Object.getOwnPropertyNames, __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty, __commonJSMin = (n, j) => () => (j || n((j = { exports: {} }).exports, j), j.exports), __copyProps = (n, P, I, L) => {
2
+ if (P && typeof P == "object" || typeof P == "function") for (var R = __getOwnPropNames(P), z = 0, B = R.length, V; z < B; z++) V = R[z], !__hasOwnProp.call(n, V) && V !== I && __defProp(n, V, {
3
+ get: ((n) => P[n]).bind(null, V),
4
+ enumerable: !(L = __getOwnPropDesc(P, V)) || L.enumerable
5
+ });
6
+ return n;
7
+ }, __toESM = (M, N, F) => (F = M == null ? {} : __create(__getProtoOf(M)), __copyProps(N || !M || !M.__esModule ? __defProp(F, "default", {
8
+ value: M,
9
+ enumerable: !0
10
+ }) : F, M));
11
+ const PI_2 = Math.PI * 2;
12
+ var Matrix = class n {
13
+ constructor(n = 1, j = 0, M = 0, N = 1, P = 0, F = 0) {
14
+ this.a = n, this.b = j, this.c = M, this.d = N, this.tx = P, this.ty = F;
15
+ }
16
+ static append(j, M) {
17
+ return new n(M.a * j.a + M.b * j.c, M.a * j.b + M.b * j.d, M.c * j.a + M.d * j.c, M.c * j.b + M.d * j.d, M.tx * j.a + M.ty * j.c + j.tx, M.tx * j.b + M.ty * j.d + j.ty);
18
+ }
19
+ apply(n) {
20
+ let { x: j, y: M } = n;
21
+ return new Vector2(j * this.a + M * this.c + this.tx, j * this.b + M * this.d + this.ty);
22
+ }
23
+ appendFrom(n, j) {
24
+ let M = n.a, N = n.b, P = n.c, F = n.d, I = n.tx, L = n.ty, R = j.a, z = j.b, B = j.c, V = j.d, H = j.tx, U = j.ty;
25
+ this.a = M * R + N * B, this.b = M * z + N * V, this.c = P * R + F * B, this.d = P * z + F * V, this.tx = I * R + L * B + H, this.ty = I * z + L * V + U;
26
+ }
27
+ set(n, j, M, N, P, F) {
28
+ this.a = n, this.b = j, this.c = M, this.d = N, this.tx = P, this.ty = F;
29
+ }
30
+ applyInverse(n, j) {
31
+ j = j || new Vector2();
32
+ let M = this.a, N = this.b, P = this.c, F = this.d, I = this.tx, L = this.ty, R = 1 / (M * F + P * -N), z = n.x, B = n.y;
33
+ return j.x = F * R * z + -P * R * B + (L * P - I * F) * R, j.y = M * R * B + -N * R * z + (-L * M + I * N) * R, j;
34
+ }
35
+ copyFrom(n) {
36
+ return this.a = n.a, this.b = n.b, this.c = n.c, this.d = n.d, this.tx = n.tx, this.ty = n.ty, this;
37
+ }
38
+ decompose(n) {
39
+ let j = this.a, M = this.b, N = this.c, P = this.d, F = n.pivot, I = -Math.atan2(-N, P), L = Math.atan2(M, j), R = Math.abs(I + L);
40
+ return R < 1e-5 || Math.abs(PI_2 - R) < 1e-5 ? (n.rotation = L, n.skew.x = n.skew.y = 0) : (n.rotation = 0, n.skew.x = I, n.skew.y = L), n.scale.x = Math.sqrt(j * j + M * M), n.scale.y = Math.sqrt(N * N + P * P), n.position.x = this.tx + F.x * j + F.y * N, n.position.y = this.ty + F.x * M + F.y * P, n;
41
+ }
42
+ clone() {
43
+ let j = new n();
44
+ return j.a = this.a, j.b = this.b, j.c = this.c, j.d = this.d, j.tx = this.tx, j.ty = this.ty, j;
45
+ }
46
+ }, Rectangle = class n {
47
+ constructor(n = 0, j = 0, M = 0, N = 0) {
48
+ this.type = "rectangle", this.x = n, this.y = j, this.width = M, this.height = N;
49
+ }
50
+ getBounds() {
51
+ let j = new n();
52
+ return j.copyFrom(this), j;
53
+ }
54
+ copyFrom(n) {
55
+ return this.x = n.x, this.y = n.y, this.width = n.width, this.height = n.height, this;
56
+ }
57
+ contains(n, j) {
58
+ return this.width <= 0 || this.height <= 0 ? !1 : n >= this.x && n < this.x + this.width && j >= this.y && j < this.y + this.height;
59
+ }
60
+ }, Vector2 = class {
61
+ constructor(n = 0, j = 0) {
62
+ this.x = n, this.y = j;
63
+ }
64
+ set(n, j) {
65
+ j == null ? this.x = this.y = n : (this.x = n, this.y = j);
66
+ }
67
+ copyFrom(n) {
68
+ this.set(n.x, n.y);
69
+ }
70
+ };
71
+ function nextPow2(n) {
72
+ return n += n === 0 ? 1 : 0, --n, n |= n >>> 1, n |= n >>> 2, n |= n >>> 4, n |= n >>> 8, n |= n >>> 16, n + 1;
73
+ }
74
+ const CanvasPool = new class {
2
75
  constructor() {
3
- this.x = 0, this.y = 0, this.z = 0, this.width = 0, this.height = 0, this.zIndex = 0, this.originX = 0, this.originY = 0, this.rotation = 0;
76
+ this._canvasPool = Object.create(null);
77
+ }
78
+ getOptimalCanvasAndContext(n, j, M = 1) {
79
+ let N = nextPow2(n * M - 1e-6), P = nextPow2(j * M - 1e-6), F = N << 17 + P << 1;
80
+ this._canvasPool[F] || (this._canvasPool[F] = []);
81
+ let I = this._canvasPool[F].pop();
82
+ if (I) return I;
83
+ {
84
+ let n = document.createElement("canvas");
85
+ return n.width = N, n.height = P, {
86
+ canvas: n,
87
+ context: n.getContext("2d")
88
+ };
89
+ }
4
90
  }
5
- setOrigin(r, T) {
6
- this.originX = r, this.originY = T;
91
+ }();
92
+ var uidCache = { default: -1 };
93
+ function uid(n = "default") {
94
+ return uidCache[n] === void 0 && (uidCache[n] = -1), ++uidCache[n];
95
+ }
96
+ var _TextStyle, TextStyle = class n {
97
+ constructor(j) {
98
+ this.uid = uid("textStyle");
99
+ let M = {
100
+ ...n.defaultStyle,
101
+ ...j
102
+ };
103
+ for (let n in M) {
104
+ let j = n;
105
+ this[j] = M[n];
106
+ }
7
107
  }
8
- draw(r, T) {
9
- r.save(), r.rotate(this.rotation), this.render(r), r.restore();
108
+ get styleKey() {
109
+ return `${this.uid}-${this._tick}`;
10
110
  }
11
- render(r) {
12
- if (!this.texture) return;
13
- let T = this.width || this.texture.width, E = this.height || this.texture.height;
14
- r.drawImage(this.texture, -T * this.originX, -E * this.originY, T, E);
111
+ get fontSize() {
112
+ return this._fontSize;
15
113
  }
16
- update(r) {}
17
- }, Container = class extends GameObject {
18
- constructor(...r) {
19
- super(...r), this.x = 0, this.y = 0, this.z = 0, this.rotation = 0, this.scaleX = 1, this.scaleY = 1, this.children = [];
114
+ set fontSize(n) {
115
+ this._fontSize !== n && (this._fontSize = n, this.update());
20
116
  }
21
- add(r) {
22
- this.children.push(r), this.updateBounds();
117
+ get fill() {
118
+ return this._fill;
23
119
  }
24
- updateBounds() {
25
- if (!this.children.length) {
26
- this.width = 0, this.height = 0;
27
- return;
120
+ set fill(n) {
121
+ this._fill !== n && (this._fill = n, this.update());
122
+ }
123
+ get align() {
124
+ return this._align;
125
+ }
126
+ set align(n) {
127
+ this._align !== n && (this._align = n, this.update());
128
+ }
129
+ get wordWarp() {
130
+ return this._wordWrap;
131
+ }
132
+ set wordWrap(n) {
133
+ this._wordWrap !== n && (this._wordWrap = n, this.update());
134
+ }
135
+ get fontFamily() {
136
+ return this._fontFamily;
137
+ }
138
+ set fontFamily(n) {
139
+ this._fontFamily !== n && (this._fontFamily = n, this.update());
140
+ }
141
+ get leading() {
142
+ return this._leading;
143
+ }
144
+ set leading(n) {
145
+ this._leading !== n && (this._leading = n, this.update());
146
+ }
147
+ get fontStyle() {
148
+ return this._fontStyle;
149
+ }
150
+ set fontStyle(n) {
151
+ this._fontStyle !== n && (this._fontStyle = n.toLowerCase(), this.update());
152
+ }
153
+ get textBaseline() {
154
+ return this._textBaseline;
155
+ }
156
+ set textBaseline(n) {
157
+ this._textBaseline = n, this.update();
158
+ }
159
+ get lineHeight() {
160
+ return this._lineHeight;
161
+ }
162
+ set lineHeight(n) {
163
+ this._lineHeight !== n && (this._lineHeight = n, this.update());
164
+ }
165
+ get letterSpacing() {
166
+ return this._letterSpacing;
167
+ }
168
+ set letterSpacing(n) {
169
+ this._letterSpacing !== n && (this._letterSpacing = n, this.update());
170
+ }
171
+ get fontVariant() {
172
+ return this._fontVariant;
173
+ }
174
+ set fontVariant(n) {
175
+ this._fontVariant !== n && (this._fontVariant = n, this.update());
176
+ }
177
+ get fontWeight() {
178
+ return this._fontWeight;
179
+ }
180
+ set fontWeight(n) {
181
+ this._fontWeight !== n && (this._fontWeight = n, this.update());
182
+ }
183
+ get _fontString() {
184
+ return this._cachedFontString === null && (this._cachedFontString = fontStringFromTextStyle(this)), this._cachedFontString;
185
+ }
186
+ update() {
187
+ this._tick++, this._cachedFontString = null;
188
+ }
189
+ destroy(n = !1) {
190
+ this._fill = null;
191
+ }
192
+ };
193
+ _TextStyle = TextStyle, _TextStyle.defaultStyle = {
194
+ align: "left",
195
+ breakWords: !1,
196
+ dropShadow: null,
197
+ fill: "black",
198
+ fontFamily: "Arial",
199
+ fontSize: 26,
200
+ fontStyle: "normal",
201
+ fontVariant: "normal",
202
+ fontWeight: "normal",
203
+ leading: 0,
204
+ letterSpacing: 0,
205
+ lineHeight: 0,
206
+ padding: 0,
207
+ stroke: null,
208
+ textBaseline: "alphabetic",
209
+ trim: !1,
210
+ whiteSpace: "pre",
211
+ wordWrap: !1,
212
+ wordWrapWidth: 100
213
+ };
214
+ var genericFontFamilies = [
215
+ "serif",
216
+ "sans-serif",
217
+ "monospace",
218
+ "cursive",
219
+ "fantasy",
220
+ "system-ui"
221
+ ];
222
+ function fontStringFromTextStyle(n) {
223
+ let j = typeof n.fontSize == "number" ? `${n.fontSize}px` : n.fontSize, M = n.fontFamily;
224
+ Array.isArray(n.fontFamily) || (M = n.fontFamily.split(","));
225
+ for (let n = M.length - 1; n >= 0; n--) {
226
+ let j = M[n].trim();
227
+ !/([\"\'])[^\'\"]+\1/.test(j) && !genericFontFamilies.includes(j) && (j = `"${j}"`), M[n] = j;
228
+ }
229
+ return `${n.fontStyle} ${n.fontVariant} ${n.fontWeight} ${j} ${M.join(",")}`;
230
+ }
231
+ var _TextMetrics;
232
+ const NEWLINE_MATCH_REGEX = /(?:\r\n|\r|\n)/;
233
+ var TextMetrics = class n {
234
+ constructor(n, j, M, N, P, F, I, L, R) {
235
+ this.text = n, this.style = j, this.width = M, this.height = N, this.lines = P, this.lineWidths = F, this.lineHeight = I, this.maxLineWidth = L, this.fontProperties = R;
236
+ }
237
+ static get canvas() {
238
+ if (!n._canvas) {
239
+ let j;
240
+ try {
241
+ let M = new OffscreenCanvas(0, 0);
242
+ if (M.getContext("2d", { willReadFrequently: !0 }).measureText) return n._canvas = M, M;
243
+ j = createCanvas(10, 10);
244
+ } catch (n) {
245
+ j = createCanvas(10, 10);
246
+ }
247
+ n._canvas = j;
248
+ }
249
+ return n._canvas;
250
+ }
251
+ static get context() {
252
+ return n._context || (n._context = n.canvas.getContext("2d", { willReadFrequently: !0 })), n._context;
253
+ }
254
+ static measureText(j, M) {
255
+ let N = `${j}-${M.styleKey}`;
256
+ if (n._measurementCache.has(N)) return n._measurementCache.get(N);
257
+ let P = M._fontString, F = n.measureFont(P);
258
+ F.fontSize === 0 && (F.fontSize = M.fontSize, F.ascent = M.fontSize, F.descent = 0);
259
+ let I = n.context;
260
+ I.font = P;
261
+ let L = j.split(NEWLINE_MATCH_REGEX), R = Array(L.length), z = 0;
262
+ for (let j = 0; j < L.length; ++j) {
263
+ let N = n._measureText(L[j], M.letterSpacing);
264
+ R[j] = N, z = Math.max(z, N);
265
+ }
266
+ let B = M.lineHeight || F.fontSize, V = new n(j, M, z, Math.max(B, F.fontSize + (L.length - 1) * (B + M.leading)), L, R, B, z, F);
267
+ return n._measurementCache.set(N, V), V;
268
+ }
269
+ static _measureText(j, M) {
270
+ var N, P;
271
+ let F = n.context;
272
+ F.letterSpacing = "0px", F.textLetterSpacing = M;
273
+ let I = F.measureText(j), L = I.width, R = 0;
274
+ L > 0 && (R = (n.graphemeSegmenter(j).length - 1) * M, L += R);
275
+ let z = -((N = I.actualBoundingBoxLeft) == null ? 0 : N), B = ((P = I.actualBoundingBoxRight) == null ? 0 : P) - z;
276
+ return I.width > 0 && (B += R), Math.max(L, B);
277
+ }
278
+ static measureFont(j) {
279
+ var M, N;
280
+ if (n._fonts[j]) return n._fonts[j];
281
+ let P = n.context;
282
+ P.font = j;
283
+ let F = P.measureText(n.METRICS_STRING + n.BASELINE_SYMBOL), I = (M = F.actualBoundingBoxAscent) == null ? 0 : M, L = (N = F.actualBoundingBoxDescent) == null ? 0 : N, R = {
284
+ ascent: I,
285
+ descent: L,
286
+ fontSize: I + L
287
+ };
288
+ return n._fonts[j] = R, R;
289
+ }
290
+ };
291
+ _TextMetrics = TextMetrics, _TextMetrics.METRICS_STRING = "|ÉqÅ", _TextMetrics.BASELINE_SYMBOL = "M", _TextMetrics._measurementCache = /* @__PURE__ */ new Map(), _TextMetrics._fonts = {}, _TextMetrics.graphemeSegmenter = (() => {
292
+ var n;
293
+ if (typeof ((n = Intl) == null ? void 0 : n.Segmenter) == "function") {
294
+ let n = new Intl.Segmenter();
295
+ return (j) => {
296
+ let M = n.segment(j), N = [], P = 0;
297
+ for (let n of M) N[P++] = n.segment;
298
+ return N;
299
+ };
300
+ }
301
+ return (n) => [...n];
302
+ })();
303
+ function createCanvas(n, j) {
304
+ let M = document.createElement("canvas");
305
+ return M.width = n, M.height = j, M;
306
+ }
307
+ function generateTextTexture(n) {
308
+ let { text: j, style: M, resolution: N = 1, padding: P = 0 } = n, F = TextMetrics.measureText(j, M), I = Math.ceil(Math.ceil(Math.max(1, F.width) + P * 2) * N), L = Math.ceil(Math.ceil(Math.max(1, F.height) + P * 2) * N), R = CanvasPool.getOptimalCanvasAndContext(I, L);
309
+ return renderTextToCanvas(M, N, P, R, F), {
310
+ canvasAndContext: R,
311
+ frame: new Rectangle(0, 0, I, L)
312
+ };
313
+ }
314
+ function renderTextToCanvas(n, j, M, N, P) {
315
+ let { context: F } = N, I = fontStringFromTextStyle(n), { lines: L, lineHeight: R, lineWidths: z, maxLineWidth: B, fontProperties: V } = P;
316
+ F.resetTransform(), F.scale(j, j), F.textBaseline = n.textBaseline, F.font = I;
317
+ let H = Math.min(0, (R - V.fontSize) / 2);
318
+ F.fillStyle = n.fill;
319
+ for (let j = 0; j < L.length; ++j) {
320
+ let P = getAlignmentOffset(z[j], B, n.align), F = j * R + V.ascent + H, I = 0;
321
+ if (n.align === "justify" && n.wordWrap && j < L.length - 1) {
322
+ let n = countSpaces(L[j]);
323
+ n > 0 && (I = (B - z[j]) / n);
324
+ }
325
+ drawLetterSpacing(L[j], n, N, P + M, F + M, !1, I);
326
+ }
327
+ }
328
+ function getAlignmentOffset(n, j, M) {
329
+ return M === "right" ? j - n : M === "center" ? (j - n) / 2 : 0;
330
+ }
331
+ function countSpaces(n) {
332
+ let j = 0;
333
+ for (let M = 0; M < n.length; M++) n.charCodeAt(M) === 32 && j++;
334
+ return j;
335
+ }
336
+ function drawLetterSpacing(n, j, M, N, P, F = !1, I = 0) {
337
+ let L = M.context, R = j.letterSpacing;
338
+ if (R === 0 && I === 0) {
339
+ L.fillText(n, N, P);
340
+ return;
341
+ }
342
+ if (I !== 0 && R === 0) {
343
+ let j = n.split(" "), M = N, F = L.measureText(" ").width;
344
+ for (let n = 0; n < j.length; ++n) L.fillText(j[n], M, P), M += L.measureText(j[n]).width + F + I;
345
+ return;
346
+ }
347
+ let z = N, B = TextMetrics.graphemeSegmenter(n), V = L.measureText(n).width, H = 0;
348
+ for (let n = 0; n < B.length; ++n) {
349
+ let j = B[n];
350
+ L.fillText(j, z, P);
351
+ let M = "";
352
+ for (let j = n + 1; j < B.length; ++j) M += B[j];
353
+ H = L.measureText(M).width, z += V - H + R, j === "" && (z += I), V = H;
354
+ }
355
+ }
356
+ var eventemitter3_default = (/* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((n, j) => {
357
+ var M = Object.prototype.hasOwnProperty, N = "~";
358
+ function P() {}
359
+ Object.create && (P.prototype = Object.create(null), new P().__proto__ || (N = !1));
360
+ function F(n, j, M) {
361
+ this.fn = n, this.context = j, this.once = M || !1;
362
+ }
363
+ function I(n, j, M, P, I) {
364
+ if (typeof M != "function") throw TypeError("The listener must be a function");
365
+ var L = new F(M, P || n, I), R = N ? N + j : j;
366
+ return n._events[R] ? n._events[R].fn ? n._events[R] = [n._events[R], L] : n._events[R].push(L) : (n._events[R] = L, n._eventsCount++), n;
367
+ }
368
+ function L(n, j) {
369
+ --n._eventsCount === 0 ? n._events = new P() : delete n._events[j];
370
+ }
371
+ function R() {
372
+ this._events = new P(), this._eventsCount = 0;
373
+ }
374
+ R.prototype.eventNames = function() {
375
+ var n = [], j, P;
376
+ if (this._eventsCount === 0) return n;
377
+ for (P in j = this._events) M.call(j, P) && n.push(N ? P.slice(1) : P);
378
+ return Object.getOwnPropertySymbols ? n.concat(Object.getOwnPropertySymbols(j)) : n;
379
+ }, R.prototype.listeners = function(n) {
380
+ var j = N ? N + n : n, M = this._events[j];
381
+ if (!M) return [];
382
+ if (M.fn) return [M.fn];
383
+ for (var P = 0, F = M.length, I = Array(F); P < F; P++) I[P] = M[P].fn;
384
+ return I;
385
+ }, R.prototype.listenerCount = function(n) {
386
+ var j = N ? N + n : n, M = this._events[j];
387
+ return M ? M.fn ? 1 : M.length : 0;
388
+ }, R.prototype.emit = function(n, j, M, P, F, I) {
389
+ var L = N ? N + n : n;
390
+ if (!this._events[L]) return !1;
391
+ var R = this._events[L], z = arguments.length, B, V;
392
+ if (R.fn) {
393
+ switch (R.once && this.removeListener(n, R.fn, void 0, !0), z) {
394
+ case 1: return R.fn.call(R.context), !0;
395
+ case 2: return R.fn.call(R.context, j), !0;
396
+ case 3: return R.fn.call(R.context, j, M), !0;
397
+ case 4: return R.fn.call(R.context, j, M, P), !0;
398
+ case 5: return R.fn.call(R.context, j, M, P, F), !0;
399
+ case 6: return R.fn.call(R.context, j, M, P, F, I), !0;
400
+ }
401
+ for (V = 1, B = Array(z - 1); V < z; V++) B[V - 1] = arguments[V];
402
+ R.fn.apply(R.context, B);
403
+ } else {
404
+ var H = R.length, U;
405
+ for (V = 0; V < H; V++) switch (R[V].once && this.removeListener(n, R[V].fn, void 0, !0), z) {
406
+ case 1:
407
+ R[V].fn.call(R[V].context);
408
+ break;
409
+ case 2:
410
+ R[V].fn.call(R[V].context, j);
411
+ break;
412
+ case 3:
413
+ R[V].fn.call(R[V].context, j, M);
414
+ break;
415
+ case 4:
416
+ R[V].fn.call(R[V].context, j, M, P);
417
+ break;
418
+ default:
419
+ if (!B) for (U = 1, B = Array(z - 1); U < z; U++) B[U - 1] = arguments[U];
420
+ R[V].fn.apply(R[V].context, B);
421
+ }
422
+ }
423
+ return !0;
424
+ }, R.prototype.on = function(n, j, M) {
425
+ return I(this, n, j, M, !1);
426
+ }, R.prototype.once = function(n, j, M) {
427
+ return I(this, n, j, M, !0);
428
+ }, R.prototype.removeListener = function(n, j, M, P) {
429
+ var F = N ? N + n : n;
430
+ if (!this._events[F]) return this;
431
+ if (!j) return L(this, F), this;
432
+ var I = this._events[F];
433
+ if (I.fn) I.fn === j && (!P || I.once) && (!M || I.context === M) && L(this, F);
434
+ else {
435
+ for (var R = 0, z = [], B = I.length; R < B; R++) (I[R].fn !== j || P && !I[R].once || M && I[R].context !== M) && z.push(I[R]);
436
+ z.length ? this._events[F] = z.length === 1 ? z[0] : z : L(this, F);
437
+ }
438
+ return this;
439
+ }, R.prototype.removeAllListeners = function(n) {
440
+ var j;
441
+ return n ? (j = N ? N + n : n, this._events[j] && L(this, j)) : (this._events = new P(), this._eventsCount = 0), this;
442
+ }, R.prototype.off = R.prototype.removeListener, R.prototype.addListener = R.prototype.on, R.prefixed = N, R.EventEmitter = R, j !== void 0 && (j.exports = R);
443
+ })))(), 1)).default, _TextureSource, TextureSource = class n extends eventemitter3_default {
444
+ constructor(j) {
445
+ super(), this._resolution = 1, this.pixelWidth = 1, this.pixelHeight = 1, this.width = 1, this.height = 1;
446
+ let M = {
447
+ ...n.defaultOptions,
448
+ ...j
449
+ };
450
+ this.label = j.label, this.resource = M.resource, this._resolution = M.resolution, M.width ? this.pixelWidth = j.width * this._resolution : this.pixelWidth = this.resource && this.resourceWidth || 1, M.height ? this.pixelHeight = j.height * this._resolution : this.pixelHeight = this.resource && this.resourceHeight || 1, this.width = this.pixelWidth / this._resolution, this.height = this.pixelHeight / this._resolution;
451
+ }
452
+ get resolution() {
453
+ return this._resolution;
454
+ }
455
+ set resolution(n) {
456
+ this._resolution !== n && (this._resolution = n, this.width = this.pixelWidth / n, this.height = this.pixelHeight / n);
457
+ }
458
+ get resourceWidth() {
459
+ let n = this.resource;
460
+ return n.naturalWidth || n.width;
461
+ }
462
+ get resourceHeight() {
463
+ let n = this.resource;
464
+ return n.naturalHeight || n.height;
465
+ }
466
+ resize(n, j, M) {
467
+ M || (M = this._resolution), n || (n = this.width), j || (j = this.height);
468
+ let N = Math.round(n * M), P = Math.round(j * M);
469
+ return this.width = N / M, this.height = P / M, this._resolution = M, this.pixelWidth === N && this.pixelHeight === P ? !1 : (this.pixelWidth = N, this.pixelHeight = P, this.emit("resize", this), !0);
470
+ }
471
+ };
472
+ _TextureSource = TextureSource, _TextureSource.defaultOptions = { resolution: 1 };
473
+ var CanvasSource = class extends TextureSource {
474
+ constructor(n) {
475
+ n.resource || (n.resource = createCanvas()), n.width || (n.width = n.resource.width, n.autoDensity || (n.width /= n.resolution)), n.height || (n.height = n.resource.height, n.autoDensity || (n.height /= n.resolution)), super(n), this.autoDensity = n.autoDensity, this.resizeCanvas();
476
+ }
477
+ resizeCanvas() {
478
+ this.autoDensity && (this.resource.style.width = `${this.width}px`, this.resource.style.height = `${this.height}px`), (this.resource.width !== this.pixelWidth || this.resource.height !== this.pixelHeight) && (this.resource.width = this.pixelWidth, this.resource.height = this.pixelHeight);
479
+ }
480
+ resize(n = this.width, j = this.height, M = this._resolution) {
481
+ let N = super.resize(n, j, M);
482
+ return N && this.resizeCanvas(), N;
483
+ }
484
+ }, Texture = class {
485
+ constructor({ source: n, label: j, frame: M, orig: N, rotate: P } = {}) {
486
+ if (this.frame = new Rectangle(), this.noFrame = !1, this.label = j, this.source = n, M) this.frame.copyFrom(M);
487
+ else {
488
+ this.noFrame = !0;
489
+ let { width: j, height: M } = n;
490
+ this.frame.width = j, this.frame.height = M;
28
491
  }
29
- let r = Infinity, T = Infinity, E = -Infinity, D = -Infinity;
30
- this.children.forEach((O) => {
31
- let k = O.width || 0, A = O.height || 0, j = O.x, M = O.y;
32
- r = Math.min(r, j), T = Math.min(T, M), E = Math.max(E, j + k), D = Math.max(D, M + A);
33
- }), this.width = E - r, this.height = D - T;
492
+ this.orig = N || this.frame, this.rotate = P == null ? 0 : P, this.destroyed = !1;
493
+ }
494
+ get source() {
495
+ return this._source;
34
496
  }
35
- remove(r) {
36
- let T = this.children.indexOf(r);
37
- T !== -1 && (this.children.splice(T, 1), this.updateBounds());
497
+ set source(n) {
498
+ this._source && this._source.off("resize", this.update, this), this._source = n, n.on("resize", this.update, this);
38
499
  }
39
- update(r) {
40
- this.children.forEach((T) => {
41
- var E;
42
- return (E = T.update) == null ? void 0 : E.call(T, r);
500
+ get width() {
501
+ return this.orig.width;
502
+ }
503
+ get height() {
504
+ return this.orig.height;
505
+ }
506
+ update() {
507
+ this.noFrame && (this.frame.width = this._source.width, this.frame.height = this._source.height);
508
+ }
509
+ };
510
+ Texture.EMPTY = new Texture({
511
+ label: "EMPTY",
512
+ source: new TextureSource({ label: "EMPTY" })
513
+ });
514
+ var File = class {
515
+ constructor(n, j) {
516
+ this.key = n, this.url = j;
517
+ }
518
+ }, ImageFile = class extends File {
519
+ load() {
520
+ return new Promise((n, j) => {
521
+ let M = new Image();
522
+ M.onload = () => n(M), M.onerror = () => j(/* @__PURE__ */ Error(`Failed to load ${this.url}`)), M.src = this.url;
43
523
  });
44
524
  }
45
- draw(r, T) {
46
- this.children.forEach((E) => {
47
- this.drawChild(E, r, T);
525
+ }, Loader = class {
526
+ constructor() {
527
+ this.queue = [], this.textures = new Cache();
528
+ }
529
+ async image(n, j) {
530
+ let M = await fetch(j), N = new Texture({ source: new TextureSource({ resource: await createImageBitmap(await M.blob()) }) });
531
+ return this.textures.add(n, N), N;
532
+ }
533
+ async load() {
534
+ let n = this.queue.map((n) => n.load().then((j) => {
535
+ n instanceof ImageFile && this.textures.add(n.key, j);
536
+ }));
537
+ this.queue.length = 0, await Promise.all(n);
538
+ }
539
+ }, Cache = class {
540
+ constructor() {
541
+ this.map = /* @__PURE__ */ new Map();
542
+ }
543
+ add(n, j) {
544
+ this.map.has(n) || this.map.set(n, j);
545
+ }
546
+ get(n) {
547
+ let j = this.map.get(n);
548
+ if (!j) throw Error(`Asset ${n} not found`);
549
+ return j;
550
+ }
551
+ has(n) {
552
+ return this.map.has(n);
553
+ }
554
+ remove(n) {
555
+ this.map.delete(n);
556
+ }
557
+ clear() {
558
+ this.map.clear();
559
+ }
560
+ }, ResourceManager = class {
561
+ constructor() {
562
+ this.textures = new Cache(), this.loader = new Loader();
563
+ }
564
+ async load(n) {
565
+ let j = n.map(async (n) => {
566
+ let j = await this.loader.image(n.alias, n.src);
567
+ return {
568
+ key: n.alias,
569
+ value: j
570
+ };
48
571
  });
572
+ return (await Promise.all(j)).reduce((n, j) => (n[j.key] = j.value, n), {});
49
573
  }
50
- drawChild(r, T, E) {
51
- let D = this.width * this.originX, O = this.height * this.originY, k = Math.cos(this.rotation), A = Math.sin(this.rotation), j = (r.x - D) * this.scaleX, M = (r.y - O) * this.scaleY, N = this.x + j * k - M * A, P = this.y + j * A + M * k, F = this.z + r.z, I = this.rotation + r.rotation, { px: L, py: R } = E.projection.project(N, P, F);
52
- console.log(N, P, this.x, this.y), T.save(), T.translate(L, R), T.rotate(I), r.render(T), T.restore();
574
+ };
575
+ const Assets = new ResourceManager();
576
+ var FederatedEvent = class {
577
+ constructor(n) {
578
+ this.system = n;
579
+ }
580
+ getLocalPosition(n, j) {
581
+ return n.worldTransform.applyInverse(j || this.global);
582
+ }
583
+ composedPath() {
584
+ return (!this.path || this.path[this.path.length - 1] !== this.target) && (this.path = this.target ? this.system.propagationPath(this.target) : []), this.path;
585
+ }
586
+ }, _EventSystem, PROPAGATION_LIMIT = 2048, EventSystem = class {
587
+ constructor(n) {
588
+ this.domElement = null, this.rootTarget = null, this.resolution = 1, this._allInteractiveElements = [], this._hitElements = [], this._isPointerMoveEvent = !1, this.mappingState = { trackingData: {} }, this.renderer = n, this.resolution = n.resolution, this._onPointerDown = this._onPointerDown.bind(this), this._onPointerMove = this._onPointerMove.bind(this), this._onPointerUp = this._onPointerUp.bind(this), this._onPointerOverOut = this._onPointerOverOut.bind(this), this.init();
589
+ }
590
+ trackingData(n) {
591
+ return this.mappingState.trackingData[n] || (this.mappingState.trackingData[n] = {
592
+ pressTargetsByButton: {},
593
+ clicksByButton: {},
594
+ overTargets: null
595
+ }), this.mappingState.trackingData[n];
596
+ }
597
+ init() {
598
+ let n = this.renderer.canvas;
599
+ this.setTargetElement(n);
600
+ }
601
+ setTargetElement(n) {
602
+ this._removeEvents(), this.domElement = n, this._addEvents();
603
+ }
604
+ dispatchEvent(n, j) {
605
+ if (!n.target) return;
606
+ let M = n.composedPath();
607
+ for (let N = 0; N < M.length - 1; ++N) n.currentTarget = M[N], this._notifyTarget(n, j);
608
+ n.currentTarget = n.target, this._notifyTarget(n, j);
609
+ }
610
+ _notifyTarget(n, j) {
611
+ j != null || (j = n.type);
612
+ let M = n.currentTarget._events[j];
613
+ if (M) if ("fn" in M) M.once && n.target.removeListener(j, M.fn, void 0, !0), M.fn.call(M.context, n);
614
+ else for (let N = 0; N < M.length; ++N) {
615
+ let P = M[N];
616
+ P.once && n.target.removeListener(j, P.fn, void 0, !0), P.fn.call(P.context, n);
617
+ }
53
618
  }
54
- }, Renderer = class {
55
- constructor(r) {
56
- this.ctx = r;
619
+ propagationPath(n) {
620
+ let j = [n];
621
+ for (let M = 0; M < PROPAGATION_LIMIT && (n !== this.rootTarget || n.parent); ++M) {
622
+ if (!n.parent) throw Error("Cannot find propagation path to disconnected target");
623
+ j.push(n.parent), n = n.parent;
624
+ }
625
+ return j.reverse(), j;
626
+ }
627
+ _removeEvents() {
628
+ let n = this.domElement;
629
+ n && (globalThis.document.removeEventListener("pointermove", this._onPointerMove, !0), n.removeEventListener("pointerdown", this._onPointerDown, !0), n.removeEventListener("pointerleave", this._onPointerOverOut, !0), n.removeEventListener("pointerover", this._onPointerOverOut, !0), globalThis.document.removeEventListener("pointerup", this._onPointerUp, !0));
630
+ }
631
+ _addEvents() {
632
+ let n = this.domElement;
633
+ if (!n) return;
634
+ let j = n.style;
635
+ j && (j.touchAction = "none"), globalThis.document.addEventListener("pointermove", this._onPointerMove, !0), n.addEventListener("pointerdown", this._onPointerDown, !0), n.addEventListener("pointerleave", this._onPointerOverOut, !0), n.addEventListener("pointerover", this._onPointerOverOut, !0), globalThis.document.addEventListener("pointerup", this._onPointerUp, !0);
636
+ }
637
+ _onPointerMove(n) {
638
+ var j;
639
+ if (this.rootTarget = this.renderer.renderedObject, !this.rootTarget) return;
640
+ this._isPointerMoveEvent = !0, this._allInteractiveElements.length = 0, this._hitElements.length = 0;
641
+ let M = this.createPointEvent(n);
642
+ this._isPointerMoveEvent = !1;
643
+ let N = this.trackingData(n.pointerId), P = findMountedTarget(N.overTargets);
644
+ if (((j = N.overTargets) == null ? void 0 : j.length) > 0 && P !== M.target) {
645
+ let j = this.createPointEvent(n, "pointerout", P);
646
+ this.dispatchEvent(j, "pointerout");
647
+ let N = M.composedPath();
648
+ if (!N.includes(P)) {
649
+ let j = this.createPointEvent(n, "pointerleave", P);
650
+ for (; j.target && !N.includes(j.target);) j.currentTarget = j.target, this._notifyTarget(j), j.target = j.target.parent;
651
+ }
652
+ }
653
+ if (P !== M.target) {
654
+ let n = "pointerover", j = this.clonePointEvent(M, n);
655
+ this.dispatchEvent(j, n);
656
+ let N = P == null ? void 0 : P.parent;
657
+ for (; N && N !== this.rootTarget.parent && N !== M.target;) N = N.parent;
658
+ if (!N || N === this.rootTarget.parent) {
659
+ let n = this.clonePointEvent(M, "pointerenter");
660
+ for (; n.target && n.target !== P && n.target !== this.rootTarget.parent;) n.currentTarget = n.target, this._notifyTarget(n), n.target = n.target.parent;
661
+ }
662
+ }
663
+ this.dispatchEvent(M, "pointermove");
664
+ let F = this._allInteractiveElements;
665
+ for (let n = F.length - 1; n >= 0; --n) M.currentTarget = F[n], this._notifyTarget(M, "globalpointermove");
666
+ this._allInteractiveElements.length = 0, this._hitElements.length = 0, N.overTargets = M.composedPath();
667
+ }
668
+ _onPointerDown(n) {
669
+ if (this.rootTarget = this.renderer.renderedObject, !this.rootTarget) return;
670
+ let j = this.createPointEvent(n);
671
+ this.dispatchEvent(j, "pointerdown");
672
+ let M = this.trackingData(n.pointerId);
673
+ M.pressTargetsByButton[n.button] = j.composedPath();
674
+ }
675
+ _onPointerOverOut(n) {
676
+ if (this.rootTarget = this.renderer.renderedObject, !this.rootTarget) return;
677
+ let j = this.createPointEvent(n);
678
+ this.dispatchEvent(j, "pointerout");
679
+ }
680
+ _onPointerUp(n) {
681
+ if (this.rootTarget = this.renderer.renderedObject, !this.rootTarget) return;
682
+ let j = n.target;
683
+ n.composedPath && n.composedPath().length > 1 && (j = n.composedPath()[0]);
684
+ let M = j === this.domElement ? "" : "outside", N = this.createPointEvent(n);
685
+ this.dispatchEvent(N, `pointerup${M}`);
686
+ }
687
+ _isInteractive(n) {
688
+ return n === "static";
689
+ }
690
+ createPointEvent(n, j, M) {
691
+ var N;
692
+ let P = this.mapPositionToPoint(n.clientX, n.clientY);
693
+ n.type === "pointerleave" && (j = "pointerout");
694
+ let F = new FederatedEvent(this);
695
+ return F.type = j, F.nativeEvent = n, F.target = (N = M == null ? this.hitTest(P.x, P.y) : M) == null ? this._hitElements[0] : N, F.global = P, F;
696
+ }
697
+ clonePointEvent(n, j) {
698
+ let M = new FederatedEvent(this);
699
+ return M.nativeEvent = n.nativeEvent, M.global = n.global, M.type = j == null ? n.type : j, M.path = n.composedPath().slice(), M.target = n.target, M;
700
+ }
701
+ mapPositionToPoint(n, j) {
702
+ let M = this.domElement, N = M.isConnected ? M.getBoundingClientRect() : {
703
+ x: 0,
704
+ y: 0,
705
+ width: M.width,
706
+ height: M.height,
707
+ left: 0,
708
+ top: 0
709
+ }, P = 1 / this.resolution, F = new Vector2();
710
+ return F.x = (n - N.left) * (M.width / N.width) * P, F.y = (j - N.top) * (M.height / N.height) * P, F;
711
+ }
712
+ hitTest(n, j) {
713
+ let M = this._isPointerMoveEvent, N = this[M ? "hitTestMoveRecursive" : "hitTestRecursive"](this.rootTarget, this.rootTarget.eventMode, new Vector2(n, j));
714
+ return N && N[0];
715
+ }
716
+ _interactivePrune(n) {
717
+ return !n || !n.visible || n.eventMode === "none";
718
+ }
719
+ hitTestMoveRecursive(n, j, M) {
720
+ let N = !1;
721
+ if (this._interactivePrune(n)) return;
722
+ let P = n.children;
723
+ if (P && P.length > 0) for (let F = P.length - 1; F >= 0; --F) {
724
+ let I = P[F], L = this.hitTestMoveRecursive(I, this._isInteractive(j) ? j : I.eventMode, M);
725
+ if (L) {
726
+ if (L.length > 0 && !L[L.length - 1].parent) continue;
727
+ let j = this._isInteractive(n.eventMode);
728
+ (L.length > 0 || j) && (j && this._allInteractiveElements.push(n), L.push(n)), this._hitElements.length === 0 && (this._hitElements = L), N = !0;
729
+ }
730
+ }
731
+ let F = this._isInteractive(j), I = this._isInteractive(n.eventMode);
732
+ if (I && this._allInteractiveElements.push(n), !(this._hitElements.length > 0)) {
733
+ if (N) return this._hitElements;
734
+ if (F && this.hitTestFn(n, M)) return I ? [n] : [];
735
+ }
57
736
  }
58
- render(r) {
59
- let E = this.ctx, D = r.camera;
60
- E.clearRect(0, 0, E.canvas.width, E.canvas.height), D.apply(E), r.displayList.render(E);
61
- for (let O of r.world.objects) if (O instanceof Container) O.draw(E, D);
62
- else {
63
- let { px: r, py: T } = D.projection.project(O.x, O.y, O.z);
64
- E.save(), E.translate(r, T), O.draw(E, D), E.restore();
737
+ hitTestRecursive(n, j, M) {
738
+ let N = n.children;
739
+ for (let P = N.length - 1; P >= 0; P--) {
740
+ let F = N[P], I = this.hitTestRecursive(F, this._isInteractive(j) ? j : F.eventMode, M);
741
+ if (I) {
742
+ let j = this._isInteractive(n.eventMode);
743
+ return (I.length > 0 || j) && I.push(n), I;
744
+ }
745
+ }
746
+ let P = this._isInteractive(j), F = this._isInteractive(n.eventMode);
747
+ return P && this.hitTestFn(n, M) ? F ? [n] : [] : null;
748
+ }
749
+ hitTestFn(n, j) {
750
+ if (n.hitArea) return !0;
751
+ if (n.containsPoint) {
752
+ let M = n.worldTransform.applyInverse(j);
753
+ return n.containsPoint(M);
65
754
  }
66
- D.restore(E);
755
+ return !1;
67
756
  }
68
- }, EventSystem = class {
757
+ };
758
+ _EventSystem = EventSystem, _EventSystem.desc = { name: "events" };
759
+ function findMountedTarget(n) {
760
+ if (!n) return;
761
+ let j = n[0];
762
+ for (let M = 1; M < n.length && n[M].parent === j; ++M) j = n[M];
763
+ return j;
764
+ }
765
+ var InstructionSet = class {
69
766
  constructor() {
70
- this.events = /* @__PURE__ */ new Map();
767
+ this.instructions = [], this.instructionSize = 0;
768
+ }
769
+ reset() {
770
+ this.instructionSize = 0;
71
771
  }
72
- on(r, T) {
73
- this.events.has(r) || this.events.set(r, /* @__PURE__ */ new Set()), this.events.get(r).add(T);
772
+ add(n) {
773
+ this.instructions[this.instructionSize++] = n;
74
774
  }
75
- off(r, T) {
76
- this.events.has(r) && this.events.get(r).delete(T);
775
+ }, RenderGroup = class {
776
+ constructor(n) {
777
+ this.worldTransform = new Matrix(), this.localTransform = new Matrix(), this.root = null, this.instructionSet = new InstructionSet(), this.structureDidChange = !0, this.renderGroupParent = null, this.renderGroupChildren = [], this.childrenToUpdate = Object.create(null), this.init(n);
77
778
  }
78
- emit(r, ...T) {
79
- if (this.events.has(r)) for (let E of this.events.get(r)) E(...T);
779
+ init(n) {
780
+ this.root = n;
781
+ let j = n.children;
782
+ for (let n = 0; n < j.length; ++n) this.addChild(j[n]);
783
+ }
784
+ addChild(n) {
785
+ this.structureDidChange = !0, n.parentRenderGroup = this, n.parent === this.root ? n.relativeRenderGroupDepth = 1 : n.relativeRenderGroupDepth = n.parent.relativeRenderGroupDepth + 1, n.didChange = !0, this.onChildUpdate(n);
786
+ let j = n.children;
787
+ for (let n = 0; n < j.length; ++n) this.addChild(j[n]);
788
+ }
789
+ removeChild(n) {
790
+ if (this.structureDidChange = !0, n.parentRenderGroup = null, n.renderGroup) {
791
+ this._removeRenderGroupChild(n.renderGroup);
792
+ return;
793
+ }
794
+ let j = n.children;
795
+ for (let n = 0; n < j.length; ++n) this.removeChild(j[n]);
796
+ }
797
+ removeChildren(n) {
798
+ for (let j = 0; j < n.length; ++j) this.removeChild(n[j]);
799
+ }
800
+ _removeRenderGroupChild(n) {
801
+ let j = this.renderGroupChildren.indexOf(n);
802
+ j > -1 && this.renderGroupChildren.splice(j, 1), n.renderGroupParent = null;
803
+ }
804
+ onChildUpdate(n) {
805
+ let j = this.childrenToUpdate[n.relativeRenderGroupDepth];
806
+ j || (j = this.childrenToUpdate[n.relativeRenderGroupDepth] = {
807
+ index: 0,
808
+ list: []
809
+ }), j.list[j.index++] = n;
810
+ }
811
+ destroy() {
812
+ this.root = null, this.instructionSet = null;
80
813
  }
81
814
  };
82
- function _typeof(r) {
83
- "@babel/helpers - typeof";
84
- return _typeof = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(r) {
85
- return typeof r;
86
- } : function(r) {
87
- return r && typeof Symbol == "function" && r.constructor === Symbol && r !== Symbol.prototype ? "symbol" : typeof r;
88
- }, _typeof(r);
815
+ function updateBounds(n, j, M) {
816
+ let { width: N, height: P } = M.orig;
817
+ n.minX = -j.x * N, n.minY = -j.y * P, n.maxX = n.minX + N, n.maxY = n.minY + P;
89
818
  }
90
- function toPrimitive(r, T) {
91
- if (_typeof(r) != "object" || !r) return r;
92
- var E = r[Symbol.toPrimitive];
93
- if (E !== void 0) {
94
- var D = E.call(r, T || "default");
95
- if (_typeof(D) != "object") return D;
96
- throw TypeError("@@toPrimitive must return a primitive value.");
97
- }
98
- return (T === "string" ? String : Number)(r);
819
+ function applyMixins(n, ...j) {
820
+ for (let M of j) Object.defineProperties(n.prototype, Object.getOwnPropertyDescriptors(M));
99
821
  }
100
- function toPropertyKey(r) {
101
- var T = toPrimitive(r, "string");
102
- return _typeof(T) == "symbol" ? T : T + "";
822
+ var ObservablePoint = class {
823
+ constructor(n, j, M) {
824
+ this._x = j || 0, this._y = M || 0, this._observer = n;
825
+ }
826
+ set(n = 0, j = n) {
827
+ return (this._x !== n || this._y !== j) && (this._x = n, this._y = j, this._observer._onUpdate(this)), this;
828
+ }
829
+ get x() {
830
+ return this._x;
831
+ }
832
+ set x(n) {
833
+ this._x !== n && (this._x = n, this._observer._onUpdate(this));
834
+ }
835
+ get y() {
836
+ return this._y;
837
+ }
838
+ set y(n) {
839
+ this._y !== n && (this._y = n, this._observer._onUpdate(this));
840
+ }
841
+ copyFrom(n) {
842
+ return (this.x !== n.x || this.y !== n.y) && (this._x = n.x, this._y = n.y, this._observer._onUpdate(this)), this;
843
+ }
844
+ toVector2() {
845
+ return new Vector2(this.x, this.y);
846
+ }
847
+ };
848
+ const RAD_TO_DEG = 180 / Math.PI, DEG_TO_RAD = Math.PI / 180;
849
+ var Bounds = class n {
850
+ constructor(n = Infinity, j = Infinity, M = -Infinity, N = -Infinity) {
851
+ this.minX = Infinity, this.minY = Infinity, this.maxX = -Infinity, this.maxY = -Infinity, this.matrix = new Matrix(), this.minX = n, this.minY = j, this.maxX = M, this.maxY = N;
852
+ }
853
+ clone() {
854
+ return new n(this.minX, this.minY, this.maxX, this.maxY);
855
+ }
856
+ isEmpty() {
857
+ return this.minX >= this.maxX || this.minY >= this.maxY;
858
+ }
859
+ clear() {
860
+ this.minX = Infinity, this.minY = Infinity, this.maxX = -Infinity, this.maxY = -Infinity;
861
+ }
862
+ get width() {
863
+ return this.maxX - this.minX;
864
+ }
865
+ set width(n) {
866
+ this.maxX = this.minX + n;
867
+ }
868
+ get height() {
869
+ return this.maxY - this.minY;
870
+ }
871
+ set height(n) {
872
+ this.maxY = this.minY + n;
873
+ }
874
+ get left() {
875
+ return this.minX;
876
+ }
877
+ get right() {
878
+ return this.maxX;
879
+ }
880
+ get top() {
881
+ return this.minY;
882
+ }
883
+ get bottom() {
884
+ return this.maxY;
885
+ }
886
+ get isValid() {
887
+ return this.minX + this.minY !== Infinity;
888
+ }
889
+ set(n, j, M, N) {
890
+ this.minX = n, this.minY = j, this.maxX = M, this.maxY = N;
891
+ }
892
+ addBounds(n, j) {
893
+ this.addFrame(n.minX, n.minY, n.maxX, n.maxY, j);
894
+ }
895
+ addRect(n, j) {
896
+ this.addFrame(n.x, n.y, n.width + n.x, n.height + n.y, j);
897
+ }
898
+ addFrame(n, j, M, N, P) {
899
+ P || (P = this.matrix);
900
+ let F = P.a, I = P.b, L = P.c, R = P.d, z = P.tx, B = P.ty;
901
+ updateMinMax(F * n + L * j + z, I * n + R * j + B, this), updateMinMax(F * M + L * j + z, I * M + R * j + B, this), updateMinMax(F * n + L * N + z, I * n + R * N + B, this), updateMinMax(F * M + L * N + z, I * M + R * N + B, this);
902
+ }
903
+ get rectangle() {
904
+ this._rectangle || (this._rectangle = new Rectangle());
905
+ let n = this._rectangle;
906
+ return n.x = this.minX, n.y = this.minY, n.width = this.maxX - this.minX, n.height = this.maxY - this.minY, n;
907
+ }
908
+ addBoundsMask(n) {
909
+ this.minX = this.minX > n.minX ? this.minX : n.minX, this.minY = this.minY > n.minY ? this.minY : n.minY, this.maxX = this.maxX < n.maxX ? this.maxX : n.maxX, this.maxY = this.maxY < n.maxY ? this.maxY : n.maxY;
910
+ }
911
+ };
912
+ function updateMinMax(n, j, M) {
913
+ n < M.minX && (M.minX = n), n > M.maxX && (M.maxX = n), j < M.minY && (M.minY = j), j > M.maxY && (M.maxY = j);
103
914
  }
104
- function _defineProperty(r, T, E) {
105
- return (T = toPropertyKey(T)) in r ? Object.defineProperty(r, T, {
106
- value: E,
107
- enumerable: !0,
108
- configurable: !0,
109
- writable: !0
110
- }) : r[T] = E, r;
915
+ function getLocalBounds(n, j, M) {
916
+ return j.clear(), M || (M = new Matrix()), _getLocalBounds(n, j, M, n, !0), j.isValid || j.set(0, 0, 0, 0), j;
111
917
  }
112
- function ownKeys(r, T) {
113
- var E = Object.keys(r);
114
- if (Object.getOwnPropertySymbols) {
115
- var D = Object.getOwnPropertySymbols(r);
116
- T && (D = D.filter(function(T) {
117
- return Object.getOwnPropertyDescriptor(r, T).enumerable;
118
- })), E.push.apply(E, D);
119
- }
120
- return E;
918
+ function _getLocalBounds(n, j, M, N, P) {
919
+ let F = new Matrix();
920
+ if (P) F.copyFrom(M);
921
+ else {
922
+ if (!n.visible || !n.measurable) return;
923
+ n.updateLocalTransform(), F.appendFrom(n.localTransform, M);
924
+ }
925
+ let I = j, L = !!n.effects.length;
926
+ if (L && (j = new Bounds()), n.boundsArea) j.addRect(n.boundsArea, F);
927
+ else {
928
+ n.renderPipeId && (j.matrix = F, j.addBounds(n.bounds));
929
+ let M = n.children;
930
+ for (let n = 0; n < M.length; n++) _getLocalBounds(M[n], j, F, N, !1);
931
+ if (L) {
932
+ for (let M = 0; M < n.effects.length; ++M) {
933
+ var R, z;
934
+ (R = (z = n.effects[M]).addLocalBounds) == null || R.call(z, j, N);
935
+ }
936
+ I.addBounds(j, new Matrix());
937
+ }
938
+ }
939
+ return j;
121
940
  }
122
- function _objectSpread2(r) {
123
- for (var T = 1; T < arguments.length; T++) {
124
- var E = arguments[T] == null ? {} : arguments[T];
125
- T % 2 ? ownKeys(Object(E), !0).forEach(function(T) {
126
- _defineProperty(r, T, E[T]);
127
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(r, Object.getOwnPropertyDescriptors(E)) : ownKeys(Object(E)).forEach(function(T) {
128
- Object.defineProperty(r, T, Object.getOwnPropertyDescriptor(E, T));
129
- });
941
+ var StencilMask = class {
942
+ constructor(n) {
943
+ this.pipe = "stencilMask", this.mask = n, n.includeInBuild = !1, n.measurable = !1;
130
944
  }
131
- return r;
945
+ addLocalBounds(n, j) {
946
+ let M = new Bounds();
947
+ this.mask.measurable = !0;
948
+ let N = getMatrixRelativeToParent(this.mask, j);
949
+ getLocalBounds(this.mask, M, N), this.mask.measurable = !1, n.addBoundsMask(M);
950
+ }
951
+ };
952
+ function getMatrixRelativeToParent(n, j, M) {
953
+ return M || (M = new Matrix()), n === j ? M : (M = getMatrixRelativeToParent(n.parent, j, M), n.updateLocalTransform(), Matrix.append(M, n.localTransform));
132
954
  }
133
- const InputEventType = {
134
- KEY_DOWN: Symbol("keyDown"),
135
- KEY_UP: Symbol("keyUp"),
136
- POINTER_DOWN: Symbol("pointerDown"),
137
- POINTER_MOVE: Symbol("pointerMove"),
138
- POINTER_UP: Symbol("pointerUp")
955
+ const effectMixin = {
956
+ effects: [],
957
+ _maskEffect: null,
958
+ addEffect(n) {
959
+ this.effects.push(n), this._updateIsSimple();
960
+ },
961
+ removeEffect(n) {
962
+ let j = this.effects.indexOf(n);
963
+ j === -1 && this.effects.splice(j, 1), this._updateIsSimple();
964
+ },
965
+ set mask(n) {
966
+ let j = this._maskEffect;
967
+ n !== (j == null ? void 0 : j.mask) && (j && (this.removeEffect(j), this._maskEffect = null), n != null && (this._maskEffect = new StencilMask(n), this.addEffect(this._maskEffect)));
968
+ },
969
+ get mask() {
970
+ var n;
971
+ return (n = this._maskEffect) == null ? void 0 : n.mask;
972
+ }
973
+ }, sortMixin = {
974
+ _zIndex: 0,
975
+ sortableChildren: !1,
976
+ sortDirty: !1
977
+ }, measureMixin = {
978
+ _localBoundsCacheData: null,
979
+ _localBounds: null,
980
+ _setWidth(n, j) {
981
+ let M = Math.sign(this.scale.x) || 1;
982
+ j === 0 ? this.scale.x = M : this.scale.x = n / j * M;
983
+ },
984
+ _setHeight(n, j) {
985
+ let M = Math.sign(this.scale.y) || 1;
986
+ j === 0 ? this.scale.y = M : this.scale.y = n / j * M;
987
+ },
988
+ getLocalBounds() {
989
+ return this._localBounds || (this._localBounds = new Bounds()), getLocalBounds(this, this._localBounds), this._localBounds;
990
+ }
139
991
  };
140
- var InputSystem = class {
141
- constructor(r, T) {
142
- this.keys = /* @__PURE__ */ new Set(), this.pointer = {
143
- x: 0,
144
- y: 0,
145
- dx: 0,
146
- dy: 0,
147
- down: !1,
148
- justDown: !1,
149
- justUp: !1,
150
- id: null
151
- }, this.target = r, this.events = T, window.addEventListener("keydown", (r) => {
152
- r.preventDefault(), this.keys.add(r.code), this.events.emit(InputEventType.KEY_DOWN, r);
153
- }), window.addEventListener("keyup", (r) => {
154
- this.keys.delete(r.code), this.events.emit(InputEventType.KEY_UP, r);
155
- }), r.addEventListener("mousedown", this.onDown.bind(this)), r.addEventListener("mousemove", this.onMove.bind(this)), r.addEventListener("mouseup", this.onUp.bind(this)), r.addEventListener("touchstart", this.onDown.bind(this), { passive: !1 }), r.addEventListener("touchmove", this.onMove.bind(this), { passive: !1 }), r.addEventListener("touchend", this.onUp.bind(this));
992
+ function clearList(n, j) {
993
+ j || (j = 0);
994
+ for (let M = j; M < n.length && n[M]; ++M) n[M] = null;
995
+ }
996
+ function assignWithIgnore(n, j, M = {}) {
997
+ for (let N in j) !M[N] && j[N] !== void 0 && (n[N] = j[N]);
998
+ }
999
+ const childrenHelperMixin = { removeChildren(n = 0, j) {
1000
+ let M = j == null ? this.children.length : j, N = M - n, P = [];
1001
+ if (N > 0 && N <= M) {
1002
+ for (let j = M - 1; j >= n; --j) {
1003
+ let n = this.children[j];
1004
+ n && (P.push(n), n.parent = null);
1005
+ }
1006
+ removeItems(this.children, n, M);
1007
+ let j = this.renderGroup || this.parentRenderGroup;
1008
+ return j && j.removeChildren(P), P;
1009
+ } else if (N === 0 && this.children.length === 0) return P;
1010
+ throw Error("removeChildren: numeric values are outside the acceptable range.");
1011
+ } };
1012
+ function removeItems(n, j, M) {
1013
+ let N = n.length, P;
1014
+ if (j >= N || M === 0) return;
1015
+ M = j + M > N ? N - j : M;
1016
+ let F = N - M;
1017
+ for (P = j; P < F; ++P) n[P] = n[P + M];
1018
+ n.length = F;
1019
+ }
1020
+ const UPDATE_COLOR = 1, UPDATE_BLEND = 2, UPDATE_VISIBLE = 4, UPDATE_TRANSFORM = 8;
1021
+ var defaultSkew = new ObservablePoint(null), defaultOrigin = new ObservablePoint(null), defaultScale = new ObservablePoint(null, 1, 1), defaultPivot = new ObservablePoint(null), Container = class extends eventemitter3_default {
1022
+ constructor(n = {}) {
1023
+ super(), this.destroyed = !1, this.renderGroup = null, this.parentRenderGroup = null, this.parent = null, this.eventMode = "passive", this.hitArea = null, this._position = new ObservablePoint(this, 0, 0), this.includeInBuild = !0, this.didChange = !1, this.isSimple = !0, this.measurable = !0, this.relativeRenderGroupDepth = 0, this._attrUpdateTick = 0, this._localTransformUpdateTick = 0, this._updateFlags = 15, this.localDisplayStatus = 7, this.globalDisplayStatus = 7, this.children = [], this.localTransform = new Matrix(), this.relativeGroupTransform = new Matrix(), this.groupTransform = this.relativeGroupTransform, this._rotation = 0, this._cx = 1, this._sx = 0, this._cy = 0, this._sy = 1, this._skew = defaultSkew, this._scale = defaultScale, this._origin = defaultOrigin, this._pivot = defaultPivot, this.localAlpha = 1, this.groupColor = 16777215, this.localColor = 16777215, this.groupAlpha = 1, this.groupColorAlpha = 4294967295, assignWithIgnore(this, n, {
1024
+ children: !0,
1025
+ parent: !0,
1026
+ effects: !0
1027
+ }), this.effects = [];
156
1028
  }
157
- update() {
158
- this.pointer.justDown = !1, this.pointer.justUp = !1, this.pointer.dx = 0, this.pointer.dy = 0;
1029
+ get renderable() {
1030
+ return !!(this.localDisplayStatus & 1);
159
1031
  }
160
- isKeyboardDown(r) {
161
- return this.keys.has(r);
1032
+ set renderable(n) {
1033
+ let j = n ? 1 : 0;
1034
+ (this.localDisplayStatus & 1) !== j && (this._updateFlags |= 4, this.localDisplayStatus ^= 1, this.parentRenderGroup && (this.parentRenderGroup.structureDidChange = !0), this._onUpdate());
162
1035
  }
163
- onDown(r) {
164
- r.preventDefault();
165
- let T = this._getPoint(r);
166
- if (!T) {
167
- console.warn("missing point");
168
- return;
169
- }
170
- this.pointer.down = !0, this.pointer.justDown = !0, this.pointer.x = T.x, this.pointer.y = T.y, this.pointer.id = T.id, this.events.emit(InputEventType.POINTER_DOWN, _objectSpread2({}, this.pointer));
1036
+ get visible() {
1037
+ return !!(this.localDisplayStatus & 2);
171
1038
  }
172
- onMove(r) {
173
- if (!this.pointer.down) return;
174
- r.preventDefault();
175
- let T = this._getPoint(r);
176
- if (!T) {
177
- console.warn("missing point");
178
- return;
1039
+ set visible(n) {
1040
+ let j = n ? 2 : 0;
1041
+ (this.localDisplayStatus & 2) !== j && (this.parentRenderGroup && (this.parentRenderGroup.structureDidChange = !0), this._updateFlags |= 4, this.localDisplayStatus ^= 2, this._onUpdate());
1042
+ }
1043
+ get isRenderGroup() {
1044
+ return !!this.renderGroup;
1045
+ }
1046
+ set isRenderGroup(n) {
1047
+ !!this.renderGroup !== n && (n ? this.enableRenderGroup() : this.disableRenderGroup());
1048
+ }
1049
+ get zIndex() {
1050
+ return this._zIndex;
1051
+ }
1052
+ set zIndex(n) {
1053
+ n !== this._zIndex && (this._zIndex = n, this.depthOfChildModified());
1054
+ }
1055
+ _updateIsSimple() {
1056
+ this.isSimple = !this.renderGroup && this.effects.length == 0;
1057
+ }
1058
+ sortChildren() {
1059
+ this.sortDirty && (this.sortDirty = !1, this.children.sort(sortChildren));
1060
+ }
1061
+ depthOfChildModified() {
1062
+ this.parent && (this.parent.sortableChildren = !0, this.parent.sortDirty = !0), this.parentRenderGroup;
1063
+ }
1064
+ enableRenderGroup() {
1065
+ this.renderGroup || (this.renderGroup = new RenderGroup(this), this.groupTransform = new Matrix(), this._updateIsSimple());
1066
+ }
1067
+ disableRenderGroup() {
1068
+ if (!this.renderGroup) return;
1069
+ let n = this.parentRenderGroup;
1070
+ n == null || n.removeChild(this), this.renderGroup = null, this.groupTransform = this.relativeGroupTransform, n == null || n.addChild(this), this._updateIsSimple();
1071
+ }
1072
+ collectRenderables(n, j) {
1073
+ this.globalDisplayStatus < 7 || !this.includeInBuild || (this.sortableChildren && this.sortChildren(), this.isSimple ? this.collectRenderableSimple(n, j) : this.renderGroup || this.collectRenderablesWithEffects(n, j));
1074
+ }
1075
+ collectRenderablesWithEffects(n, j) {
1076
+ for (let M = 0; M < this.effects.length; ++M) {
1077
+ let N = this.effects[M];
1078
+ n[N.pipe].push(N, j);
1079
+ }
1080
+ this.collectRenderableSimple(n, j);
1081
+ for (let M = 0; M < this.effects.length; ++M) {
1082
+ let N = this.effects[M];
1083
+ n[N.pipe].pop(N, j);
179
1084
  }
180
- this.pointer.dx += T.x - this.pointer.x, this.pointer.dy += T.y - this.pointer.y, this.pointer.x = T.x, this.pointer.y = T.y, this.events.emit(InputEventType.POINTER_MOVE, _objectSpread2({}, this.pointer));
181
1085
  }
182
- onUp() {
183
- this.pointer.down = !1, this.pointer.justUp = !0, this.pointer.id = null, this.events.emit(InputEventType.POINTER_UP, _objectSpread2({}, this.pointer));
1086
+ collectRenderableSimple(n, j) {
1087
+ let M = this.children;
1088
+ for (let N = 0; N < M.length; ++N) M[N].collectRenderables(n, j);
184
1089
  }
185
- _getPoint(r) {
186
- let T = this.target.getBoundingClientRect(), E, D, O = "mouse";
187
- if (r instanceof TouchEvent) {
188
- let T = r.touches[0] || r.changedTouches[0];
189
- if (!T) return;
190
- E = T.clientX, D = T.clientY, O = T.identifier;
191
- } else E = r.clientX, D = r.clientY;
192
- return {
193
- x: E - T.left,
194
- y: D - T.top,
195
- id: O
196
- };
1090
+ setFromMatrix(n) {
1091
+ n.decompose(this);
1092
+ }
1093
+ _updateSkew() {
1094
+ let n = this.rotation, j = this.skew;
1095
+ this._cx = Math.cos(n + j.y), this._sx = Math.sin(n + j.y), this._cy = -Math.sin(n - j.x), this._sy = Math.cos(n - j.x);
1096
+ }
1097
+ updateLocalTransform() {
1098
+ let n = this._attrUpdateTick;
1099
+ if (this._localTransformUpdateTick === n) return;
1100
+ this._localTransformUpdateTick = n, this._updateSkew();
1101
+ let j = this.position, M = this.localTransform, N = this._scale.x, P = this._scale.y, F = -this._origin.x, I = -this._origin.y, L = this._pivot.x, R = this._pivot.y;
1102
+ M.a = this._cx * N, M.b = this._sx * N, M.c = this._cy * P, M.d = this._sy * P, M.tx = j.x - (L * M.a + R * M.c) + (F * M.a + I * M.c) - F, M.ty = j.y - (L * M.b + R * M.d) + (F * M.b + I * M.d) - I;
1103
+ }
1104
+ get alpha() {
1105
+ return this.localAlpha;
1106
+ }
1107
+ set alpha(n) {
1108
+ n !== this.localAlpha && (this.localAlpha = n, this._updateFlags |= 1, this._onUpdate());
1109
+ }
1110
+ get root() {
1111
+ let n = this.parent, j = this.parent;
1112
+ for (; n;) n.parent || (j = n), n = n.parent;
1113
+ return j;
1114
+ }
1115
+ get worldTransform() {
1116
+ return this._worldTransform || (this._worldTransform = new Matrix()), this.renderGroup ? this._worldTransform.copyFrom(this.renderGroup.worldTransform) : this.parentRenderGroup && this._worldTransform.appendFrom(this.relativeGroupTransform, this.parentRenderGroup.worldTransform), this._worldTransform;
1117
+ }
1118
+ get x() {
1119
+ return this._position.x;
1120
+ }
1121
+ set x(n) {
1122
+ this._position.x = n;
1123
+ }
1124
+ get position() {
1125
+ return this._position;
1126
+ }
1127
+ set position(n) {
1128
+ this._position.copyFrom(n);
1129
+ }
1130
+ get y() {
1131
+ return this._position.y;
1132
+ }
1133
+ set y(n) {
1134
+ this._position.y = n;
1135
+ }
1136
+ get rotation() {
1137
+ return this._rotation;
1138
+ }
1139
+ set rotation(n) {
1140
+ this._rotation !== n && (this._rotation = n, this._onUpdate(this._skew));
1141
+ }
1142
+ get angle() {
1143
+ return this.rotation * RAD_TO_DEG;
1144
+ }
1145
+ set angle(n) {
1146
+ this.rotation = n * DEG_TO_RAD;
1147
+ }
1148
+ get skew() {
1149
+ return this._skew === defaultSkew && (this._skew = new ObservablePoint(this, 0, 0)), this._skew;
1150
+ }
1151
+ set skew(n) {
1152
+ this._skew === defaultSkew && (this._skew = new ObservablePoint(this, 0, 0)), this._skew.copyFrom(n);
1153
+ }
1154
+ get scale() {
1155
+ return this._scale === defaultScale && (this._scale = new ObservablePoint(this, 1, 1)), this._scale;
1156
+ }
1157
+ set scale(n) {
1158
+ this._scale === defaultScale && (this._scale = new ObservablePoint(this, 1, 1)), this._scale.copyFrom(n);
1159
+ }
1160
+ get pivot() {
1161
+ return this._pivot === defaultPivot && (this._pivot = new ObservablePoint(this, 0, 0)), this._pivot;
1162
+ }
1163
+ set pivot(n) {
1164
+ this._pivot === defaultPivot && (this._pivot = new ObservablePoint(this, 0, 0)), this._pivot.copyFrom(n);
1165
+ }
1166
+ get origin() {
1167
+ return this._origin === defaultOrigin && (this._origin = new ObservablePoint(this, 0, 0)), this._origin;
1168
+ }
1169
+ set origin(n) {
1170
+ this._origin === defaultOrigin && (this._origin = new ObservablePoint(this, 0, 0)), this._origin.copyFrom(n);
197
1171
  }
198
- }, Camera = class {
199
1172
  get width() {
200
- return this.viewport.width;
1173
+ return Math.abs(this.scale.x * this.getLocalBounds().width);
201
1174
  }
1175
+ set width(n) {}
202
1176
  get height() {
203
- return this.viewport.height;
1177
+ return Math.abs(this.scale.y * this.getLocalBounds().height);
204
1178
  }
205
- constructor(r) {
206
- this.viewport = {
207
- x: 0,
208
- y: 0,
209
- width: 0,
210
- height: 0
211
- }, this.x = 0, this.y = 0, this.zoom = 1, this._followLerp = 1, this._offsetX = 0, this._offsetY = 0, this.originX = 0, this.originY = 0, this.projection = r;
212
- }
213
- setOrigin(r, T) {
214
- this.originX = r, this.originY = T;
215
- }
216
- setViewport(r, T, E, D) {
217
- this.viewport = {
218
- x: r,
219
- y: T,
220
- width: E,
221
- height: D
222
- };
1179
+ set height(n) {}
1180
+ addChild(...n) {
1181
+ if (n.length > 1) {
1182
+ for (let j = 0; j < n.length; ++j) this.addChild(n[j]);
1183
+ return n[0];
1184
+ }
1185
+ let j = n[0], M = this.renderGroup || this.parentRenderGroup;
1186
+ return j.parent === this ? (this.children.splice(this.children.indexOf(j), 1), this.children.push(j), M && (M.structureDidChange = !0), j) : (this.sortableChildren && (this.sortDirty = !0), j.parent && j.parent.removeChild(j), this.children.push(j), this.sortableChildren && (this.sortDirty = !0), j.parent = this, j.didChange = !0, j._updateFlags = 7, M && M.addChild(j), j._zIndex != 0 && j.depthOfChildModified(), j);
223
1187
  }
224
- apply(r) {
225
- r.save(), r.translate(this.originX * this.viewport.width, this.originY * this.viewport.height), r.scale(this.zoom, this.zoom), r.translate(-Math.round(this.x), -Math.round(this.y));
1188
+ removeChild(...n) {
1189
+ if (n.length > 1) {
1190
+ for (let j = 0; j < n.length; ++j) this.removeChild(n[j]);
1191
+ return n[0];
1192
+ }
1193
+ let j = n[0];
1194
+ if (!j) return j;
1195
+ let M = this.children.indexOf(j);
1196
+ return M > -1 && (this.children.splice(M, 1), j.parent = null), j;
1197
+ }
1198
+ _onUpdate(n) {
1199
+ n && n === this._skew && this._updateSkew(), this._attrUpdateTick++, !this.didChange && (this.didChange = !0, this.parentRenderGroup && this.parentRenderGroup.onChildUpdate(this));
1200
+ }
1201
+ toGlobal(n, j) {
1202
+ return this.getGlobalTransform(j).apply(n);
1203
+ }
1204
+ toLocal(n, j, M) {
1205
+ let N;
1206
+ return j && (N = j.toGlobal(n)), N = this.getGlobalTransform(M).applyInverse(n), N;
1207
+ }
1208
+ getGlobalTransform(n = !1) {
1209
+ if (n) return this.worldTransform.clone();
1210
+ this.updateLocalTransform();
1211
+ let j = new Matrix(), M = updateTransformBackwards(this, j);
1212
+ return j.appendFrom(this.localTransform, M), j;
1213
+ }
1214
+ getGlobalPosition(n = !1) {
1215
+ return this.parent ? this.parent.toGlobal(this._position, n) : this._position.toVector2();
1216
+ }
1217
+ destroy(n = !1) {
1218
+ var j, M;
1219
+ if (this.destroyed) return;
1220
+ this.destroyed = !0;
1221
+ let N;
1222
+ if (this.children.length && (N = this.removeChildren(0, this.children.length)), (j = this.parent) == null || j.removeChild(this), this.parent = null, this._maskEffect = null, this.effects = null, this._position = null, this._scale = null, this._pivot = null, this._origin = null, this._skew = null, (typeof n == "boolean" ? n : n != null && n.children) && N) for (let j = 0; j < N.length; ++j) N[j].destroy(n);
1223
+ (M = this.renderGroup) == null || M.destroy(), this.renderGroup = null;
226
1224
  }
227
- restore(r) {
228
- r.restore();
1225
+ };
1226
+ function updateTransformBackwards(n, j) {
1227
+ let M = n.parent;
1228
+ if (M) {
1229
+ updateTransformBackwards(M, j), M.updateLocalTransform();
1230
+ let n = Matrix.append(j, M.localTransform);
1231
+ j.copyFrom(n);
1232
+ }
1233
+ return j;
1234
+ }
1235
+ function sortChildren(n, j) {
1236
+ return n._zIndex - j._zIndex;
1237
+ }
1238
+ applyMixins(Container, sortMixin, effectMixin, measureMixin, childrenHelperMixin);
1239
+ var UPDATE_BLEND_COLOR_VISIBLE = 7;
1240
+ function updateRenderGroupTransform(n, j = !1) {
1241
+ let M = n.root;
1242
+ n.worldTransform.copyFrom(M.localTransform);
1243
+ let N = n.childrenToUpdate;
1244
+ for (let j in N) {
1245
+ let M = Number(j), P = N[M], F = P.list, I = P.index;
1246
+ for (let j = 0; j < I; ++j) {
1247
+ let N = F[j];
1248
+ N.parentRenderGroup === n && N.relativeRenderGroupDepth === M && updateTransform(N, 0);
1249
+ }
1250
+ clearList(F, I), P.index = 0;
229
1251
  }
230
- project(r, T, E = 0) {
231
- let { px: D, py: O } = this.projection.project(r, T, E);
232
- return {
233
- px: D - this.x,
234
- py: O - this.y
1252
+ if (j) for (let M = 0; M < n.renderGroupChildren.length; ++M) updateRenderGroupTransform(n.renderGroupChildren[M], j);
1253
+ }
1254
+ function updateTransform(n, j) {
1255
+ n.didChange = !1;
1256
+ let M = n.parent, N = n.localTransform;
1257
+ n.updateLocalTransform(), M && (j |= n._updateFlags, n.relativeGroupTransform.appendFrom(N, M.relativeGroupTransform), j & UPDATE_BLEND_COLOR_VISIBLE && updateBlendColorVisible(n, M, j));
1258
+ let P = n.children;
1259
+ for (let n = 0; n < P.length; n++) updateTransform(P[n], j);
1260
+ }
1261
+ function updateBlendColorVisible(n, j, M) {
1262
+ if (M & 1) {
1263
+ n.groupColor = j.groupColor;
1264
+ let M = n.localAlpha * j.groupAlpha;
1265
+ M = M < 0 ? 0 : M > 1 ? 1 : M, n.groupAlpha = M, n.groupColorAlpha = n.groupColor + ((M * 255 | 0) << 24);
1266
+ }
1267
+ M & 4 && (n.globalDisplayStatus = n.localDisplayStatus & j.globalDisplayStatus), n._updateFlags = 0;
1268
+ }
1269
+ var _RenderGroupSystem, RenderGroupSystem = class {
1270
+ constructor(n) {
1271
+ this.renderer = n;
1272
+ }
1273
+ _updateRenderGroup(n) {
1274
+ let j = this.renderer, M = j.renderPipes;
1275
+ n.instructionSet.renderPipes = M, updateRenderGroupTransform(n), n.structureDidChange && (n.structureDidChange = !1, this._buildInstructions(n, j));
1276
+ }
1277
+ render({ container: n, transform: j }) {
1278
+ let M = this.renderer;
1279
+ j && n.renderGroup.localTransform.copyFrom(j), M.canvasContext.globalTransform = j ? n.renderGroup.localTransform : n.renderGroup.worldTransform, this._updateRenderGroup(n.renderGroup), executeInstructions(n.renderGroup, M.renderPipes);
1280
+ }
1281
+ _buildInstructions(n, j) {
1282
+ let M = j.renderPipes, N = n.root;
1283
+ n.instructionSet.reset(), N.sortableChildren && N.sortChildren(), M.batch.buildStart(), N.collectRenderablesWithEffects(M, n.instructionSet), M.batch.buildEnd(n.instructionSet);
1284
+ }
1285
+ };
1286
+ _RenderGroupSystem = RenderGroupSystem, _RenderGroupSystem.desc = { name: "renderGroup" };
1287
+ function executeInstructions(n, j) {
1288
+ let { instructionSet: M } = n, N = M.instructions;
1289
+ for (let n = 0; n < M.instructionSize; n++) {
1290
+ let M = N[n];
1291
+ j[M.renderPipeId].execute(M);
1292
+ }
1293
+ }
1294
+ var _SpritePipe, SpritePipe = class {
1295
+ constructor(n) {
1296
+ this._renderer = n;
1297
+ }
1298
+ addRenderable(n, j) {
1299
+ this._renderer.renderPipes.batch.addToBatch({
1300
+ renderable: n,
1301
+ texture: n.texture,
1302
+ transform: n.relativeGroupTransform,
1303
+ bounds: n.bounds,
1304
+ roundPixels: this._renderer._roundPixels | n._roundPixels
1305
+ }, j);
1306
+ }
1307
+ destroy() {
1308
+ this._renderer = null;
1309
+ }
1310
+ };
1311
+ _SpritePipe = SpritePipe, _SpritePipe.desc = { name: "sprite" };
1312
+ var _TextPipe, TextPipe = class {
1313
+ constructor(n) {
1314
+ this._renderer = n;
1315
+ }
1316
+ addRenderable(n, j) {
1317
+ let M = this._getRuntimeText(n);
1318
+ if (n._didTextUpdate) {
1319
+ let j = n._autoResolution ? this._renderer.resolution : n.resolution;
1320
+ (M.currentKey !== n.styleKey || n._resolution !== j) && this._updateRuntimeText(n), n._didTextUpdate = !1, updateBounds(M.bounds, n._anchor, M.texture);
1321
+ }
1322
+ this._renderer.renderPipes.batch.addToBatch(M, j);
1323
+ }
1324
+ initCacheText(n) {
1325
+ let j = {
1326
+ currentKey: "--",
1327
+ transform: n.relativeGroupTransform,
1328
+ bounds: n.bounds,
1329
+ roundPixels: this._renderer._roundPixels | n._roundPixels,
1330
+ renderable: n,
1331
+ texture: null,
1332
+ destroy: function() {
1333
+ this.renderable = null, this.texture = null, this.bounds = null;
1334
+ }
235
1335
  };
1336
+ return n._runtimeData[this._renderer.uid] = j, j;
236
1337
  }
237
- follow(r, T) {
238
- var E, D, O;
239
- this._followTarget = r, this._followLerp = (E = T == null ? void 0 : T.lerp) == null ? 1 : E, this._offsetX = (D = T == null ? void 0 : T.offsetX) == null ? 0 : D, this._offsetY = (O = T == null ? void 0 : T.offsetY) == null ? 0 : O;
1338
+ _getRuntimeText(n) {
1339
+ return n._runtimeData[this._renderer.uid] || this.initCacheText(n);
240
1340
  }
241
- stopFollow() {
242
- this._followTarget = void 0;
1341
+ _updateRuntimeText(n) {
1342
+ let j = this._getRuntimeText(n);
1343
+ j.texture, n._resolution = n._autoResolution ? this._renderer.resolution : n.resolution, j.texture = this._renderer.text.getManagedTexture(n), j.currentKey = n.styleKey;
243
1344
  }
244
- update() {
245
- if (!this._followTarget) return;
246
- let { x: r, y: T, z: E } = this._followTarget, { px: D, py: O } = this.project(r, T, E), k = D + this._offsetX, A = O + this._offsetY;
247
- this.x += k * this._followLerp, this.y += A * this._followLerp;
1345
+ destroy() {
1346
+ this._renderer = null;
1347
+ }
1348
+ };
1349
+ _TextPipe = TextPipe, _TextPipe.desc = { name: "text" };
1350
+ var ViewContainer = class extends Container {
1351
+ constructor(...n) {
1352
+ super(...n), this._runtimeData = Object.create(null), this._roundPixels = 0, this._bounds = new Bounds(0, 1, 0, 0);
248
1353
  }
249
- }, CameraController = class {
250
- constructor(r, T) {
251
- this.speed = 300, this.camera = r, this.input = T;
1354
+ get bounds() {
1355
+ return this.updateBounds(), this._bounds;
252
1356
  }
253
- update(r) {
254
- let T = this.speed * r / 1e3;
255
- this.input.isKeyboardDown("ArrowUp") && (this.camera.y += T), this.input.isKeyboardDown("ArrowDown") && (this.camera.y -= T), this.input.isKeyboardDown("ArrowLeft") && (this.camera.x += T), this.input.isKeyboardDown("ArrowRight") && (this.camera.x -= T);
1357
+ onViewUpdate() {
1358
+ this.renderGroup || this.parentRenderGroup;
256
1359
  }
257
- }, DisplayObject = class {
1360
+ collectRenderableSimple(n, j) {
1361
+ let M = n[this.renderPipeId];
1362
+ M && M.addRenderable && M.addRenderable(this, j);
1363
+ let N = this.children;
1364
+ for (let M = 0; M < N.length; ++M) N[M].collectRenderables(n, j);
1365
+ }
1366
+ containsPoint(n) {
1367
+ let j = this.bounds, { x: M, y: N } = n;
1368
+ return M > j.minX && M < j.maxX && N > j.minY && N < j.maxY;
1369
+ }
1370
+ get roundPixels() {
1371
+ return !!this._roundPixels;
1372
+ }
1373
+ set roundPixels(n) {
1374
+ this._roundPixels = n ? 1 : 0;
1375
+ }
1376
+ destroy(n = !1) {
1377
+ for (let n in this._runtimeData) this._runtimeData[n].destroy();
1378
+ this._runtimeData = Object.create(null), this.onViewUpdate(), super.destroy(n), this._bounds = null;
1379
+ }
1380
+ }, Polygon = class {
258
1381
  constructor() {
259
- this.x = 0, this.y = 0, this.originX = .5, this.originY = .5;
1382
+ this.points = [], this.type = "polygon";
260
1383
  }
261
- }, ImageObject = class extends DisplayObject {
262
- constructor(r, T, E, D = 1) {
263
- super(), this.resolution = 1, this.x = r, this.y = T, this.texture = E, this.resolution = D, this.width = E.width / D, this.height = E.height / D;
1384
+ construction() {}
1385
+ get lastX() {
1386
+ return this.points[this.points.length - 2];
264
1387
  }
265
- render(r) {
266
- r.drawImage(this.texture, this.x - this.width * this.originX, this.y - this.height * this.originY, this.width, this.height);
1388
+ get lastY() {
1389
+ return this.points[this.points.length - 1];
267
1390
  }
268
- }, DisplayList = class {
1391
+ getBounds() {
1392
+ let n = new Rectangle(), j = this.points, M = Infinity, N = Infinity, P = -Infinity, F = -Infinity;
1393
+ for (let n = 0; n < j.length; n += 2) {
1394
+ let I = j[n], L = j[n + 1];
1395
+ M = Math.min(M, I), N = Math.min(N, L), P = Math.max(P, I), F = Math.max(F, L);
1396
+ }
1397
+ return n.x = M, n.width = P - M, n.y = N, n.height = F - N, n;
1398
+ }
1399
+ }, RECURSION_LIMIT = 8, FLT_EPSILON = 1.1920929e-7, PATH_DISTANCE_EPSILON = 1, curveAngleToleranceEpsilon = .01, mAngleTolerance = 0, mCuspLimit = 0;
1400
+ function buildAdaptiveBezier(n, j, M, N, P, F, I, L, R, z) {
1401
+ let B = (PATH_DISTANCE_EPSILON - Math.min(.99, Math.max(0, z == null ? .5 : z))) / 1;
1402
+ return B *= B, begin(j, M, N, P, F, I, L, R, n, B), n;
1403
+ }
1404
+ function begin(n, j, M, N, P, F, I, L, R, z) {
1405
+ recursive(n, j, M, N, P, F, I, L, R, z, 0), R.push(I, L);
1406
+ }
1407
+ function recursive(n, j, M, N, P, F, I, L, R, z, B) {
1408
+ if (B > RECURSION_LIMIT) return;
1409
+ let V = Math.PI, H = (n + M) / 2, U = (j + N) / 2, W = (M + P) / 2, G = (N + F) / 2, K = (P + I) / 2, q = (F + L) / 2, J = (H + W) / 2, Y = (U + G) / 2, X = (W + K) / 2, Z = (G + q) / 2, Q = (J + X) / 2, $ = (Y + Z) / 2;
1410
+ if (B > 0) {
1411
+ let B = I - n, H = L - j, U = Math.abs((M - I) * H - (N - L) * B), W = Math.abs((P - I) * H - (F - L) * B), G, K;
1412
+ if (U > FLT_EPSILON && W > FLT_EPSILON) {
1413
+ if ((U + W) * (U + W) <= z * (B * B + H * H)) {
1414
+ if (mAngleTolerance < curveAngleToleranceEpsilon) {
1415
+ R.push(Q, $);
1416
+ return;
1417
+ }
1418
+ let z = Math.atan2(F - N, P - M);
1419
+ if (G = Math.abs(z - Math.atan2(N - j, M - n)), K = Math.abs(Math.atan2(L - F, I - P) - z), G >= V && (G = 2 * V - G), K >= V && (K = 2 * V - K), G + K < mAngleTolerance) {
1420
+ R.push(Q, $);
1421
+ return;
1422
+ }
1423
+ if (mCuspLimit !== 0) {
1424
+ if (G > mCuspLimit) {
1425
+ R.push(M, N);
1426
+ return;
1427
+ }
1428
+ if (K > mCuspLimit) {
1429
+ R.push(P, F);
1430
+ return;
1431
+ }
1432
+ }
1433
+ }
1434
+ } else if (U > FLT_EPSILON) {
1435
+ if (U * U <= z * (B * B + H * H)) {
1436
+ if (mAngleTolerance < curveAngleToleranceEpsilon) {
1437
+ R.push(Q, $);
1438
+ return;
1439
+ }
1440
+ if (G = Math.abs(Math.atan2(F - N, P - M) - Math.atan2(N - j, M - n)), G >= V && (G = 2 * V - G), G < mAngleTolerance) {
1441
+ R.push(M, N), R.push(P, F);
1442
+ return;
1443
+ }
1444
+ if (mCuspLimit !== 0 && G > mCuspLimit) {
1445
+ R.push(M, N);
1446
+ return;
1447
+ }
1448
+ }
1449
+ } else if (W > FLT_EPSILON) {
1450
+ if (W * W <= z * (B * B + H * H)) {
1451
+ if (mAngleTolerance < curveAngleToleranceEpsilon) {
1452
+ R.push(Q, $);
1453
+ return;
1454
+ }
1455
+ if (G = Math.abs(Math.atan2(L - F, I - P) - Math.atan2(F - N, P - M)), G >= V && (G = 2 * V - G), G < mAngleTolerance) {
1456
+ R.push(M, N), R.push(P, F);
1457
+ return;
1458
+ }
1459
+ if (mCuspLimit !== 0 && G > mCuspLimit) {
1460
+ R.push(P, F);
1461
+ return;
1462
+ }
1463
+ }
1464
+ } else if (B = Q - (n + I) / 2, H = $ - (j + L) / 2, B * B + H * H <= z) {
1465
+ R.push(Q, $);
1466
+ return;
1467
+ }
1468
+ }
1469
+ recursive(n, j, H, U, J, Y, Q, $, R, z, B + 1), recursive(Q, $, X, Z, K, q, I, L, R, z, B + 1);
1470
+ }
1471
+ var ShapePath = class {
1472
+ constructor(n) {
1473
+ this.shapePrimitives = [], this._bounds = new Bounds(), this._graphicsPath = n;
1474
+ }
1475
+ _ensurePoly(n = !0) {
1476
+ this._currentPoly || (this._currentPoly = new Polygon(), n && this._currentPoly.points.push(0, 0));
1477
+ }
1478
+ lineTo(n, j) {
1479
+ this._ensurePoly();
1480
+ let M = this._currentPoly.points, N = M[M.length - 2], P = M[M.length - 1];
1481
+ return (N !== n || P !== j) && M.push(n, j), this;
1482
+ }
1483
+ rect(n, j, M, N) {
1484
+ return this.drawShape(new Rectangle(n, j, M, N)), this;
1485
+ }
1486
+ drawShape(n) {
1487
+ return this.endPloy(), this.shapePrimitives.push({ shape: n }), this;
1488
+ }
1489
+ moveTo(n, j) {
1490
+ return this.startPoly(n, j), this;
1491
+ }
1492
+ bezierCurveTo(n, j, M, N, P, F, I) {
1493
+ this._ensurePoly();
1494
+ let L = this._currentPoly.points;
1495
+ return buildAdaptiveBezier(L, this._currentPoly.lastX, this._currentPoly.lastY, n, j, M, N, P, F, I), this;
1496
+ }
1497
+ startPoly(n, j) {
1498
+ return this._currentPoly && this.endPloy(), this._currentPoly = new Polygon(), this._currentPoly.points.push(n, j), this;
1499
+ }
1500
+ endPloy(n = !1) {
1501
+ let j = this._currentPoly;
1502
+ j && j.points.length > 2 && (j.closePath = n, this.shapePrimitives.push({ shape: j })), this._currentPoly = null;
1503
+ }
1504
+ closePath() {
1505
+ return this.endPloy(!0), this;
1506
+ }
1507
+ buildPath() {
1508
+ let n = this._graphicsPath;
1509
+ for (let j = 0; j < n.instructions.length; ++j) {
1510
+ let M = n.instructions[j];
1511
+ this[M.action](...M.data);
1512
+ }
1513
+ return this;
1514
+ }
1515
+ get bounds() {
1516
+ let n = this._bounds;
1517
+ n.clear();
1518
+ let j = this.shapePrimitives;
1519
+ for (let M = 0; M < j.length; ++M) {
1520
+ let N = j[M].shape.getBounds();
1521
+ n.addRect(N);
1522
+ }
1523
+ return n;
1524
+ }
1525
+ }, GraphicsPath = class n {
1526
+ constructor() {
1527
+ this.instructions = [], this._dirty = !0;
1528
+ }
1529
+ rect(n, j, M, N) {
1530
+ return this.instructions.push({
1531
+ action: "rect",
1532
+ data: [
1533
+ n,
1534
+ j,
1535
+ M,
1536
+ N
1537
+ ]
1538
+ }), this._dirty = !0, this;
1539
+ }
1540
+ lineTo(...n) {
1541
+ return this.instructions.push({
1542
+ action: "lineTo",
1543
+ data: n
1544
+ }), this._dirty = !0, this;
1545
+ }
1546
+ bezierCurveTo(...n) {
1547
+ return this.instructions.push({
1548
+ action: "bezierCurveTo",
1549
+ data: n
1550
+ }), this;
1551
+ }
1552
+ moveTo(...n) {
1553
+ return this.instructions.push({
1554
+ action: "moveTo",
1555
+ data: n
1556
+ }), this;
1557
+ }
1558
+ closePath() {
1559
+ return this.instructions.push({
1560
+ action: "closePath",
1561
+ data: []
1562
+ }), this._dirty = !0, this;
1563
+ }
1564
+ get shapePath() {
1565
+ return this._shapePath || (this._shapePath = new ShapePath(this)), this._dirty && (this._dirty = !1, this._shapePath.buildPath()), this._shapePath;
1566
+ }
1567
+ get bounds() {
1568
+ return this.shapePath.bounds;
1569
+ }
1570
+ getLastPoint() {
1571
+ let n = this.instructions.length - 1, j = this.instructions[n];
1572
+ if (!j) return {
1573
+ x: 0,
1574
+ y: 0
1575
+ };
1576
+ switch (j.action) {
1577
+ case "moveTo":
1578
+ case "lineTo": return {
1579
+ x: j.data[0],
1580
+ y: j.data[1]
1581
+ };
1582
+ }
1583
+ return {
1584
+ x: 0,
1585
+ y: 0
1586
+ };
1587
+ }
1588
+ clear() {
1589
+ this.instructions.length = 0, this._dirty = !0;
1590
+ }
1591
+ clone() {
1592
+ let j = new n();
1593
+ return j.instructions = this.instructions.slice(), j;
1594
+ }
1595
+ }, _GraphicsContext, GraphicsContext = class n {
269
1596
  constructor() {
270
- this.list = [];
1597
+ this._activePath = new GraphicsPath(), this._bounds = new Bounds(), this.instructions = [];
271
1598
  }
272
- add(r) {
273
- this.list.push(r);
1599
+ setStrokeStyle(j) {
1600
+ this._strokeStyle = toStrokeStyle(j, n.defaultStrokeStyle);
274
1601
  }
275
- render(r) {
276
- this.list.forEach((T) => T.render(r));
1602
+ moveTo(n, j) {
1603
+ return this._activePath.moveTo(n, j), this;
277
1604
  }
278
- }, Text = class extends GameObject {
279
- constructor(r, T) {
280
- super(), this.x = 0, this.y = 0, this.visible = !0, this.width = 0, this.height = 0, this.dirty = !0, this.text = r, this.style = T, this.canvas = document.createElement("canvas"), this.ctx = this.canvas.getContext("2d"), this.texture = this.canvas;
1605
+ lineTo(n, j) {
1606
+ return this._activePath.lineTo(n, j), this;
281
1607
  }
282
- setText(r) {
283
- this.text !== r && (this.text = r, this.dirty = !0);
1608
+ bezierCurveTo(n, j, M, N, P, F, I) {
1609
+ return this._activePath.bezierCurveTo(n, j, M, N, P, F, I), this;
284
1610
  }
285
- setStyle(r) {
286
- Object.assign(this.style, r), this.dirty = !0;
1611
+ rect(n, j, M, N) {
1612
+ return this._activePath.rect(n, j, M, N), this;
287
1613
  }
288
- rebuild() {
289
- var r, T, E;
290
- if (!this.dirty) return;
291
- let D = this.ctx, O = this.style, k = this.text.split("\n"), A = (r = O.padding) == null ? {
292
- left: 0,
293
- right: 0,
294
- top: 0,
295
- bottom: 0
296
- } : r;
297
- D.font = `${(T = O.fontStyle) == null ? "" : T} ${O.fontSize}px ${O.fontFamily}`;
298
- let j = 0;
299
- for (let r of k) j = Math.max(j, D.measureText(r).width);
300
- let M = O.fontSize * 1.2;
301
- this.width = j + A.left + A.right, this.height = k.length * M + A.top + A.bottom, this.canvas.width = Math.ceil(this.width), this.canvas.height = Math.ceil(this.height), D.clearRect(0, 0, this.canvas.width, this.canvas.height), D.font = `${(E = O.fontStyle) == null ? "" : E} ${O.fontSize}px ${O.fontFamily}`, D.fillStyle = O.color, D.textBaseline = "top", O.shadow && (D.shadowOffsetX = O.shadow.offsetX, D.shadowOffsetY = O.shadow.offsetY, D.shadowColor = O.shadow.color, D.shadowBlur = O.shadow.blur);
302
- let N = A.top;
303
- for (let r of k) {
304
- let T = A.left, E = D.measureText(r).width;
305
- O.align === "center" ? T += (this.width - A.left - A.right - E) / 2 : O.align === "right" && (T += this.width - A.left - A.right - E), O.stroke && O.strokeThickness && (D.lineWidth = O.strokeThickness, D.strokeStyle = O.stroke, D.strokeText(r, T, N)), D.fillText(r, T, N), N += M;
306
- }
307
- this.dirty = !1;
308
- }
309
- render(r) {
310
- if (!this.texture) return;
311
- this.rebuild();
312
- let T = this.width || this.canvas.width, E = this.height;
313
- r.drawImage(this.texture, -T * this.originX, -E * this.originY, T, E);
1614
+ beginPath() {
1615
+ return this._activePath = new GraphicsPath(), this;
314
1616
  }
315
- };
316
- function asyncGeneratorStep(r, T, E, D, O, k, A) {
317
- try {
318
- var j = r[k](A), M = j.value;
319
- } catch (r) {
320
- E(r);
321
- return;
1617
+ closePath() {
1618
+ return this._activePath.closePath(), this;
322
1619
  }
323
- j.done ? T(M) : Promise.resolve(M).then(D, O);
324
- }
325
- function _asyncToGenerator(r) {
326
- return function() {
327
- var T = this, E = arguments;
328
- return new Promise(function(D, O) {
329
- var k = r.apply(T, E);
330
- function A(r) {
331
- asyncGeneratorStep(k, D, O, A, j, "next", r);
1620
+ fill(j) {
1621
+ let M = {
1622
+ ...n.defaultStrokeStyle,
1623
+ color: j
1624
+ };
1625
+ return this.instructions.push({
1626
+ action: "fill",
1627
+ data: {
1628
+ style: M,
1629
+ path: this._activePath.clone()
332
1630
  }
333
- function j(r) {
334
- asyncGeneratorStep(k, D, O, A, j, "throw", r);
1631
+ }), this;
1632
+ }
1633
+ stroke() {
1634
+ this.instructions.push({
1635
+ action: "stroke",
1636
+ data: {
1637
+ style: this._strokeStyle,
1638
+ path: this._activePath.clone()
335
1639
  }
336
- A(void 0);
337
- });
1640
+ }), this._initNextPathLocation();
1641
+ }
1642
+ _initNextPathLocation() {
1643
+ let { x: n, y: j } = this._activePath.getLastPoint();
1644
+ this._activePath.clear(), this._activePath.moveTo(n, j);
1645
+ }
1646
+ get bounds() {
1647
+ let n = this._bounds;
1648
+ n.clear();
1649
+ for (let j = 0; j < this.instructions.length; ++j) {
1650
+ let M = this.instructions[j], N = M.action;
1651
+ if (N === "fill") {
1652
+ let j = M.data;
1653
+ n.addBounds(j.path.bounds);
1654
+ } else if (N === "stroke") {
1655
+ let j = M.data, N = j.style.alignment, P = j.style.width * (1 - N);
1656
+ j.style.join;
1657
+ let F = j.path.bounds;
1658
+ n.addFrame(F.minX - P, F.minY - P, F.maxX + P, F.maxY + P);
1659
+ }
1660
+ }
1661
+ return n;
1662
+ }
1663
+ clone() {
1664
+ let j = new n();
1665
+ return j.instructions = this.instructions.slice(), j._activePath = this._activePath.clone(), j._bounds = this._bounds.clone(), j._strokeStyle = { ...this._strokeStyle }, j;
1666
+ }
1667
+ };
1668
+ _GraphicsContext = GraphicsContext, _GraphicsContext.defaultStrokeStyle = {
1669
+ width: 1,
1670
+ color: "#ffffff",
1671
+ alignment: .5,
1672
+ miterLimit: 10,
1673
+ cap: "butt",
1674
+ join: "miter",
1675
+ pixelLine: !1,
1676
+ alpha: 1
1677
+ };
1678
+ function toStrokeStyle(n, j) {
1679
+ return {
1680
+ ...j,
1681
+ ...n
338
1682
  };
339
1683
  }
340
- var File = class {
341
- constructor(r, T) {
342
- this.key = r, this.url = T;
1684
+ var Graphics = class extends ViewContainer {
1685
+ constructor(n) {
1686
+ super(), this.renderPipeId = "graphics", n instanceof GraphicsContext ? this.context = n : this.context = new GraphicsContext();
1687
+ }
1688
+ setStrokeStyle(...n) {
1689
+ return this._callContextMethod("setStrokeStyle", n);
1690
+ }
1691
+ rect(...n) {
1692
+ return this._callContextMethod("rect", n);
1693
+ }
1694
+ bezierCurveTo(...n) {
1695
+ return this._callContextMethod("bezierCurveTo", n);
1696
+ }
1697
+ lineTo(...n) {
1698
+ return this._callContextMethod("lineTo", n);
1699
+ }
1700
+ moveTo(...n) {
1701
+ return this._callContextMethod("moveTo", n);
1702
+ }
1703
+ stroke(...n) {
1704
+ return this._callContextMethod("stroke", n);
1705
+ }
1706
+ beginPath() {
1707
+ return this._callContextMethod("beginPath", []);
1708
+ }
1709
+ closePath() {
1710
+ return this._callContextMethod("closePath", []);
1711
+ }
1712
+ fill(n) {
1713
+ return this._callContextMethod("fill", [n]);
1714
+ }
1715
+ _callContextMethod(n, j) {
1716
+ return this.context[n](...j), this;
1717
+ }
1718
+ updateBounds() {}
1719
+ get bounds() {
1720
+ return this.context.bounds;
1721
+ }
1722
+ }, _GraphicsPipe, GraphicsPipe = class {
1723
+ constructor(n) {
1724
+ this._renderer = n;
1725
+ }
1726
+ addRenderable(n, j) {
1727
+ this._renderer.renderPipes.batch.break(j), j.add(n);
1728
+ }
1729
+ execute(n) {
1730
+ let j = this._renderer, M = j.canvasContext, N = M.activeConext, P = j.roundPixels, F = (n.groupColorAlpha >>> 24 & 255) / 255;
1731
+ if (!(F <= 0)) {
1732
+ N.save(), M.setContextTransform(n.relativeGroupTransform, P);
1733
+ for (let j = 0; j < n.context.instructions.length; ++j) {
1734
+ let M = n.context.instructions[j], P = M.data.style, I = P.alpha * F;
1735
+ if (I <= 0) continue;
1736
+ N.globalAlpha = I;
1737
+ let L = M.action === "stroke";
1738
+ if (L) {
1739
+ let n = P.color;
1740
+ N.lineWidth = P.width, N.lineCap = P.cap, N.lineJoin = P.join, N.miterLimit = P.miterLimit, N.strokeStyle = n;
1741
+ } else N.fillStyle = M.data.style.color;
1742
+ let R = M.data.path.shapePath.shapePrimitives;
1743
+ for (let n = 0; n < R.length; ++n) {
1744
+ let j = R[n];
1745
+ j.shape && (N.beginPath(), buildShapePath(N, j.shape), L ? N.stroke() : N.fill());
1746
+ }
1747
+ }
1748
+ N.restore();
1749
+ }
343
1750
  }
344
- }, ImageFile = class extends File {
345
- load() {
346
- return new Promise((r, T) => {
347
- let E = new Image();
348
- E.onload = () => r(E), E.onerror = () => T(/* @__PURE__ */ Error(`Failed to load ${this.url}`)), E.src = this.url;
1751
+ destroy() {
1752
+ this._renderer = null;
1753
+ }
1754
+ };
1755
+ _GraphicsPipe = GraphicsPipe, _GraphicsPipe.desc = { name: "graphics" };
1756
+ function buildShapePath(n, j) {
1757
+ switch (j.type) {
1758
+ case "rectangle": {
1759
+ let M = j;
1760
+ n.rect(M.x, M.y, M.width, M.height);
1761
+ break;
1762
+ }
1763
+ case "polygon": {
1764
+ let M = j, N = M.points;
1765
+ if (!N.length) return;
1766
+ n.moveTo(N[0], N[1]);
1767
+ for (let j = 2; j < N.length; j += 2) n.lineTo(N[j], N[j + 1]);
1768
+ M.closePath && n.closePath();
1769
+ break;
1770
+ }
1771
+ }
1772
+ }
1773
+ var _BatchPipe, Batch = class {
1774
+ constructor() {
1775
+ this.renderPipeId = "batch", this.elements = [];
1776
+ }
1777
+ }, BatchPipe = class {
1778
+ constructor(n) {
1779
+ this._renderer = n;
1780
+ }
1781
+ get batch() {
1782
+ return this._activeBatch;
1783
+ }
1784
+ buildStart() {
1785
+ this._activeBatch = new Batcher();
1786
+ }
1787
+ buildEnd(n) {
1788
+ this.break(n);
1789
+ }
1790
+ break(n) {
1791
+ this._activeBatch.build(n);
1792
+ }
1793
+ addToBatch(n, j) {
1794
+ this._activeBatch.add({
1795
+ ...n,
1796
+ getColor: () => n.renderable.groupColorAlpha
349
1797
  });
350
1798
  }
351
- }, Loader = class {
352
- constructor(r) {
353
- this.queue = [], this.textures = r;
1799
+ execute(n) {
1800
+ let j = n.elements;
1801
+ if (!j || !j.length) return;
1802
+ let M = this._renderer.canvasContext, N = M.activeConext;
1803
+ for (let n = 0; n < j.length; n++) {
1804
+ let P = j[n], F = P.roundPixels, I = (P.getColor() >>> 24 & 255) / 255;
1805
+ if (I <= 0) continue;
1806
+ N.globalAlpha = I, M.setContextTransform(P.transform, F === 1);
1807
+ let L = P.bounds, R = P.texture, z = R.frame, B = R.source._resolution || 1, V = z.x * B, H = z.y * B, U = z.width * B, W = z.height * B, G = L.minX, K = L.minY, q = L.maxX - L.minX, J = L.maxY - L.minY, Y = G, X = K, Z = q, Q = J;
1808
+ N.drawImage(R.source.resource, V, H, U, W, Y, X, Z, Q);
1809
+ }
354
1810
  }
355
- image(r, T) {
356
- return this.queue.push(new ImageFile(r, T)), this;
1811
+ destroy() {
1812
+ var n;
1813
+ this._renderer = null, (n = this._activeBatch) == null || n.destroy(), this._activeBatch = null;
357
1814
  }
358
- load() {
359
- var r = this;
360
- return _asyncToGenerator(function* () {
361
- let T = r.queue.map((T) => T.load().then((E) => {
362
- T instanceof ImageFile && r.textures.add(T.key, E);
363
- }));
364
- r.queue.length = 0, yield Promise.all(T);
365
- })();
366
- }
367
- }, _ResourceManager, Cache = class {
1815
+ };
1816
+ _BatchPipe = BatchPipe, _BatchPipe.desc = { name: "batch" };
1817
+ var Batcher = class {
368
1818
  constructor() {
369
- this.map = /* @__PURE__ */ new Map();
1819
+ this.renderPipeId = "batch", this.elements = [], this.elementSize = 0;
370
1820
  }
371
- add(r, T) {
372
- this.map.has(r) || this.map.set(r, T);
1821
+ add(n) {
1822
+ this.elements[this.elementSize++] = n;
373
1823
  }
374
- get(r) {
375
- let T = this.map.get(r);
376
- if (!T) throw Error(`Asset ${r} not found`);
377
- return T;
1824
+ build(n) {
1825
+ let j = new Batch(), M = this.elements;
1826
+ if (M[0]) {
1827
+ for (let n = 0; n < M.length; n++) {
1828
+ let N = M[n];
1829
+ this.elements[n] = null, j.elements.push(N);
1830
+ }
1831
+ n.add(j);
1832
+ }
378
1833
  }
379
- has(r) {
380
- return this.map.has(r);
1834
+ destroy() {
1835
+ this.elements = null;
1836
+ }
1837
+ }, _TextSystem, TextSystem = class {
1838
+ constructor(n) {
1839
+ this._activeTexture = {}, this.renderer = n;
1840
+ }
1841
+ getManagedTexture(n) {
1842
+ n._resolution = n._autoResolution ? this.renderer.resolution : n.resolution;
1843
+ let j = n.styleKey;
1844
+ if (this._activeTexture[j]) return this._activeTexture[j];
1845
+ let M = this.getTexture({
1846
+ text: n.text,
1847
+ style: n.style,
1848
+ resolution: n._resolution
1849
+ });
1850
+ return this._activeTexture[j] = M, M;
1851
+ }
1852
+ getTexture(n) {
1853
+ let { text: j, style: M } = n, N = n.resolution || this.renderer.resolution, { frame: P, canvasAndContext: F } = generateTextTexture({
1854
+ text: j,
1855
+ style: M,
1856
+ resolution: N
1857
+ }), I = F.canvas, L = new Texture({ source: new TextureSource({
1858
+ resource: I,
1859
+ resolution: N
1860
+ }) });
1861
+ return L.frame.width = P.width / N, L.frame.height = P.height / N, L;
381
1862
  }
382
- remove(r) {
383
- this.map.delete(r);
1863
+ };
1864
+ _TextSystem = TextSystem, _TextSystem.desc = { name: "text" };
1865
+ var _StencilMaskPipe, StencilMaskPipe = class {
1866
+ constructor(n) {
1867
+ this._canvasMaskStack = [], this._renderer = n;
1868
+ }
1869
+ push(n, j) {
1870
+ j.add({
1871
+ renderPipeId: "stencilMask",
1872
+ action: "pushMaskBegin",
1873
+ mask: n
1874
+ });
384
1875
  }
385
- clear() {
386
- this.map.clear();
1876
+ pop(n, j) {
1877
+ this._renderer.renderPipes.batch.break(j), j.add({
1878
+ renderPipeId: "stencilMask",
1879
+ action: "popMaskEnd",
1880
+ mask: n
1881
+ });
387
1882
  }
388
- }, ResourceManager = class {};
389
- _ResourceManager = ResourceManager, _ResourceManager.textures = new Cache(), _ResourceManager.loader = new Loader(_ResourceManager.textures);
390
- var AddFactory = class {
391
- constructor(r) {
392
- this.rm = ResourceManager, this.displayList = r;
1883
+ execute(n) {
1884
+ if (n.action !== "pushMaskBegin" && n.action !== "popMaskEnd") return;
1885
+ let j = this._renderer.canvasContext, M = j.activeConext;
1886
+ if (n.action === "popMaskEnd") {
1887
+ this._canvasMaskStack.pop() && M.restore();
1888
+ return;
1889
+ }
1890
+ let N = n.mask.mask, P = N.context.instructions, F = N._roundPixels === 1;
1891
+ M.save(), j.setContextTransform(N.relativeGroupTransform, F), M.beginPath();
1892
+ for (let n = 0; n < P.length; ++n) {
1893
+ let j = P[n], N = j.action;
1894
+ if (N !== "fill" && N !== "stroke") return;
1895
+ let F = j.data.path.shapePath.shapePrimitives;
1896
+ for (let n = 0; n < F.length; ++n) {
1897
+ let j = F[n].shape;
1898
+ buildShapePath(M, j);
1899
+ }
1900
+ }
1901
+ M.clip(), this._canvasMaskStack.push(!0);
393
1902
  }
394
- image(r, T, E, D = 1) {
395
- let O = new ImageObject(r, T, this.rm.textures.get(E), D);
396
- return this.displayList.add(O), O;
1903
+ destroy() {
1904
+ this._renderer = null;
397
1905
  }
398
- }, SortSystem = class {
399
- constructor(r, T) {
400
- this.world = r, this.strategy = T;
1906
+ };
1907
+ _StencilMaskPipe = StencilMaskPipe, _StencilMaskPipe.desc = { name: "stencilMask" };
1908
+ var RenderTexture = class n extends Texture {
1909
+ static create(j) {
1910
+ return new n({ source: new TextureSource(j) });
1911
+ }
1912
+ }, Sprite = class extends ViewContainer {
1913
+ constructor(n = Texture.EMPTY) {
1914
+ n instanceof Texture && (n = { texture: n });
1915
+ let { texture: j = Texture.EMPTY, width: M, height: N, ...P } = n;
1916
+ super({
1917
+ label: "Sprite",
1918
+ ...P
1919
+ }), this.renderPipeId = "sprite", this.texture = j, this.anchor = new Vector2(), M != null && (this.width = M), N != null && (this.height = N);
1920
+ }
1921
+ set texture(n) {
1922
+ n || (n = Texture.EMPTY), this._texture !== n && (this._texture = n, this._width && this._setWidth(this.width, this._texture.orig.width), this._height && this._setHeight(this.height, this._texture.orig.height), this.onViewUpdate());
1923
+ }
1924
+ get texture() {
1925
+ return this._texture;
401
1926
  }
402
- update() {
403
- this.world.objects.sort((r, T) => this.strategy.getKey(r) - this.strategy.getKey(T)), this.world.objects.sort((r, T) => r.zIndex - T.zIndex);
1927
+ get height() {
1928
+ return Math.abs(this.scale.y) * this.texture.orig.height;
404
1929
  }
405
- }, TweenData = class {
406
- constructor(r) {
407
- this.elapsed = 0, this.target = r.target, this.key = r.key, this.start = r.target[r.key], this.end = r.to, this.duration = r.duration, this.delay = r.delay || 0;
408
- let T = r.easing || "Linear";
409
- typeof T == "string" ? this.easing = Easings[T] : this.easing = T;
1930
+ set height(n) {
1931
+ let j = this.texture.orig.height, M = Math.sign(this.scale.y) || 1;
1932
+ j === 0 ? this.scale.y = M : this.scale.y = n / j * M, this._height = n;
410
1933
  }
411
- update(r) {
412
- if (this.delay > 0) return this.delay -= r, !1;
413
- this.elapsed += r;
414
- let T = Math.min(this.elapsed / this.duration, 1), E = this.easing(T);
415
- return this.target[this.key] = this.start + (this.end - this.start) * E, T === 1 ? (this.target[this.key] = this.end, !0) : !1;
1934
+ get width() {
1935
+ return Math.abs(this.scale.x) * this.texture.orig.width;
416
1936
  }
417
- reset() {
418
- this.elapsed = 0;
1937
+ set width(n) {
1938
+ let j = this.texture.orig.width, M = Math.sign(this.scale.x) || 1;
1939
+ j === 0 ? this.scale.x = M : this.scale.x = n / j * M, this._width = n;
1940
+ }
1941
+ updateBounds() {
1942
+ let n = this._bounds, { width: j, height: M } = this.texture.orig;
1943
+ n.minX = -this.anchor.x * j, n.maxX = n.minX + j, n.minY = -this.anchor.y * M, n.maxY = n.minY + M;
1944
+ }
1945
+ }, Text = class extends ViewContainer {
1946
+ constructor(n) {
1947
+ var j;
1948
+ let { text: M, resolution: N, style: P, width: F, height: I, ...L } = n;
1949
+ super(L), this.renderPipeId = "text", this._didTextUpdate = !0, this._resolution = null, this._autoResolution = !0, this._anchor = new ObservablePoint(this, 0, 0), this.text = (j = n.text) == null ? "" : j, this.style = P, this.resolution = N == null ? null : N, F != null && (this.width = F), I != null && (this.height = I);
1950
+ }
1951
+ set resolution(n) {
1952
+ this._autoResolution = n === null, this._resolution = n, this.onViewUpdate();
1953
+ }
1954
+ get resolution() {
1955
+ return this._resolution;
1956
+ }
1957
+ get anchor() {
1958
+ return this._anchor;
1959
+ }
1960
+ set anchor(n) {
1961
+ this._anchor.copyFrom(n);
1962
+ }
1963
+ get text() {
1964
+ return this._text;
1965
+ }
1966
+ set text(n) {
1967
+ let j = String(n);
1968
+ this._text !== j && (this._text = j, this.onViewUpdate());
1969
+ }
1970
+ get style() {
1971
+ return this._style;
1972
+ }
1973
+ set style(n) {
1974
+ n || (n = {}), n instanceof TextStyle ? this._style = n : this._style = new TextStyle(n), this.onViewUpdate();
1975
+ }
1976
+ get width() {
1977
+ return Math.abs(this.scale.x) * this.bounds.width;
1978
+ }
1979
+ set width(n) {
1980
+ this._setWidth(n, this.bounds.width);
1981
+ }
1982
+ get height() {
1983
+ return Math.abs(this.scale.y) * this.bounds.height;
1984
+ }
1985
+ set height(n) {
1986
+ this._setHeight(n, this.bounds.height);
1987
+ }
1988
+ onViewUpdate() {}
1989
+ updateBounds() {
1990
+ let n = this._bounds, j = this._anchor, M = TextMetrics.measureText(this._text, this._style), N = M.width, P = M.height;
1991
+ n.minX = -j._x * N, n.minY = -j._y * P, n.maxX = n.minX + N, n.maxY = n.minY + P;
1992
+ }
1993
+ get styleKey() {
1994
+ return `${this._text}:${this._style.styleKey}:${this._resolution}`;
1995
+ }
1996
+ destroy(n = !1) {
1997
+ super.destroy(n), this._bounds = null, this._anchor = null, (typeof n == "boolean" ? n : n != null && n.style) && this._style.destroy(n), this._style = null, this._text = null;
1998
+ }
1999
+ }, _ExtractSystem, ExtractSystem = class {
2000
+ constructor(n) {
2001
+ this._renderer = n;
2002
+ }
2003
+ texture(n) {
2004
+ return this._generateTexture(n);
2005
+ }
2006
+ _generateTexture(n) {
2007
+ n instanceof Container && (n = { target: n });
2008
+ let j = n.resolution || this._renderer.resolution, M = n.target, N = new Bounds(), P = n.frame || getLocalBounds(M, N).rectangle;
2009
+ P.width = Math.max(P.width, 1 / j) | 0, P.height = Math.max(P.height, 1 / j) | 0;
2010
+ let F = RenderTexture.create({
2011
+ width: P.width,
2012
+ height: P.height,
2013
+ resolution: j
2014
+ }), I = new Matrix();
2015
+ return I.tx = -P.x, I.ty = -P.y, this._renderer.render({
2016
+ clearColor: "transparent",
2017
+ container: M,
2018
+ transform: I,
2019
+ target: F
2020
+ }), F;
419
2021
  }
420
2022
  };
421
- const Easings = {
422
- Linear: (r) => r,
423
- EaseOutBack: (r) => {
424
- let T = 3.70158, E = r - 1;
425
- return 1 + E * E * ((T + 1) * E + T);
2023
+ _ExtractSystem = ExtractSystem, _ExtractSystem.desc = { name: "extract" };
2024
+ var _CanvasContextSystem, CanvasContextSystem = class {
2025
+ constructor(n) {
2026
+ this.activeResolution = 1, this.globalTransform = new Matrix(), this._renderer = n;
2027
+ }
2028
+ init() {
2029
+ this.activeConext = this._renderer.canvas.getContext("2d"), this.rootContext = this.activeConext, this.activeResolution = this._renderer.resolution;
2030
+ }
2031
+ setContextTransform(n, j, M) {
2032
+ let N = this.activeResolution, P = Matrix.append(this.globalTransform, n);
2033
+ M || (M = this.activeResolution), j ? this.activeConext.setTransform(P.a * M, P.b * M, P.c * M, P.d * M, P.tx * N | 0, P.ty * N | 0) : this.activeConext.setTransform(P.a * M, P.b * M, P.c * M, P.d * M, P.tx * N, P.ty * N);
426
2034
  }
427
2035
  };
428
- var Tween = class {
429
- constructor(r) {
430
- for (let T in this.datas = [], this.finished = !1, this.loop = !1, r.to) this.datas.push(new TweenData({
431
- target: r.target,
432
- key: T,
433
- to: r.to[T],
434
- duration: r.duration,
435
- easing: r.easing,
436
- delay: r.delay
437
- }));
438
- this.loop = r.loop || !1, this.onComplete = r.onComplete;
2036
+ _CanvasContextSystem = CanvasContextSystem, _CanvasContextSystem.desc = { name: "canvasContext" };
2037
+ var _ViewSystem, ViewSystem = class n {
2038
+ get resolution() {
2039
+ return this.texture.source._resolution;
2040
+ }
2041
+ set resolution(n) {
2042
+ this.texture.source.resize(this.texture.source.width, this.texture.source.height, n);
2043
+ }
2044
+ init(j) {
2045
+ j = {
2046
+ ...n.defaultOptions,
2047
+ ...j
2048
+ }, this.screen = new Rectangle(0, 0, j.width, j.height), this.canvas = createCanvas(), this.texture = new Texture({ source: new CanvasSource({
2049
+ resource: this.canvas,
2050
+ ...j
2051
+ }) }), this.resolution = j.resolution;
2052
+ }
2053
+ resize(n, j, M) {
2054
+ this.texture.source.resize(n, j, M), this.screen.width = this.texture.frame.width, this.screen.height = this.texture.frame.height;
439
2055
  }
440
- update(r) {
441
- if (this.finished) return;
442
- let T = !0;
443
- for (let E of this.datas) E.update(r) || (T = !1);
444
- if (T) if (this.loop) this.datas.forEach((r) => r.reset());
445
- else {
446
- var E;
447
- this.finished = !0, (E = this.onComplete) == null || E.call(this);
2056
+ };
2057
+ _ViewSystem = ViewSystem, _ViewSystem.desc = { name: "view" }, _ViewSystem.defaultOptions = {
2058
+ width: 800,
2059
+ height: 600,
2060
+ autoDensity: !1
2061
+ };
2062
+ var systems = [
2063
+ ViewSystem,
2064
+ EventSystem,
2065
+ RenderGroupSystem,
2066
+ TextSystem,
2067
+ ExtractSystem,
2068
+ CanvasContextSystem
2069
+ ], pipes = [
2070
+ BatchPipe,
2071
+ GraphicsPipe,
2072
+ TextPipe,
2073
+ SpritePipe,
2074
+ StencilMaskPipe
2075
+ ], CanvasRenderer = class extends eventemitter3_default {
2076
+ constructor() {
2077
+ super(), this.uid = uid("renderer"), this.renderedObject = null, this.renderPipes = {}, this.background = { color: "#000000" };
2078
+ }
2079
+ get canvas() {
2080
+ return this.view.canvas;
2081
+ }
2082
+ _addPipes() {
2083
+ pipes.forEach((n) => {
2084
+ this.renderPipes[n.desc.name] = new n(this);
2085
+ });
2086
+ }
2087
+ _addSystems() {
2088
+ systems.forEach((n) => {
2089
+ this[n.desc.name] = new n(this);
2090
+ });
2091
+ }
2092
+ async init(n) {
2093
+ this.resolution = n.resolution || 1, this._addSystems(), this._addPipes();
2094
+ for (let N = 0; N < systems.length; ++N) {
2095
+ var j, M;
2096
+ await ((j = (M = this[systems[N].desc.name]).init) == null ? void 0 : j.call(M, n));
2097
+ }
2098
+ n.backgroundColor && (this.background.color = n.backgroundColor), this._roundPixels = n.roundPixels ? 1 : 0;
2099
+ }
2100
+ get roundPixels() {
2101
+ return !!this._roundPixels;
2102
+ }
2103
+ render(n) {
2104
+ let j = n;
2105
+ if (j instanceof Container && (j = { container: j }), this.renderedObject = j.container, j.transform || (j.container.updateLocalTransform(), j.transform = j.container.localTransform), j.clearColor != null || (j.clearColor = this.background.color), !j.container.visible) return;
2106
+ j.container.enableRenderGroup();
2107
+ let M = j.container.renderGroup;
2108
+ if (this.activeRenderGroup = M, this.canvasContext.globalTransform = M.worldTransform, this.canvasContext.activeConext = this.canvasContext.rootContext, j.target) {
2109
+ let { context: n } = ensureCanvas(j.target.source);
2110
+ this.canvasContext.activeConext = n;
448
2111
  }
2112
+ this.clear(j), systems.forEach((n) => {
2113
+ var M, N;
2114
+ (M = (N = this[n.desc.name]).render) == null || M.call(N, j);
2115
+ });
449
2116
  }
450
- }, TweenManager = class {
451
- constructor() {
452
- this.tweens = [];
2117
+ clear(n) {
2118
+ let j = this.canvasContext.activeConext;
2119
+ j.setTransform(1, 0, 0, 1, 0, 0), j.clearRect(0, 0, this.canvas.width, this.canvas.height), j.globalAlpha = 1, j.fillStyle = n.clearColor, j.fillRect(0, 0, this.canvas.width, this.canvas.height), j.globalAlpha = 1;
2120
+ }
2121
+ destroy() {
2122
+ this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas), pipes.forEach((n) => {
2123
+ var j;
2124
+ (j = this.renderPipes[n.desc.name]) == null || j.destroy();
2125
+ }), this.renderPipes = null;
2126
+ }
2127
+ resize(n, j, M) {
2128
+ this.view.resize(n, j, M), this.emit("resize", this.view.screen.width, this.view.screen.height, this.view.resolution);
2129
+ }
2130
+ };
2131
+ function ensureCanvas(n) {
2132
+ let j = n.resource;
2133
+ return j || (j = createCanvas(n.pixelWidth, n.pixelHeight), n.resource = j), (j.width !== n.pixelWidth || j.height !== n.pixelHeight) && (j.width = n.pixelWidth, j.height = n.pixelHeight), {
2134
+ canvas: j,
2135
+ context: j.getContext("2d")
2136
+ };
2137
+ }
2138
+ var TickerListener = class {
2139
+ constructor(n, j, M = 0, N = !1) {
2140
+ this.next = null, this.previous = null, this.priority = 0, this._destroyed = !1, this._fn = n, this._context = j, this.priority = M, this._once = N;
2141
+ }
2142
+ match(n, j) {
2143
+ return this._fn === n && this._context === j;
453
2144
  }
454
- add(r) {
455
- let T = new Tween(r);
456
- return this.tweens.push(T), T;
2145
+ emit(n) {
2146
+ this._fn && (this._context ? this._fn.call(this._context, n) : this._fn(n));
2147
+ let j = this.next;
2148
+ return this._once && this.destroy(!0), this._destroyed && (this.next = null), j;
457
2149
  }
458
- update(r) {
459
- for (let T of this.tweens) T.update(r);
460
- this.tweens = this.tweens.filter((r) => !r.finished);
2150
+ destroy(n) {
2151
+ this._destroyed = !0, this._fn = null, this._context = null, this.previous && (this.previous.next = this.next), this.next && (this.next.previous = this.previous);
2152
+ let j = this.next;
2153
+ return this.next = n ? null : j, this.previous = null, j;
461
2154
  }
462
- }, World = class {
2155
+ connect(n) {
2156
+ this.previous = n, n.next && (n.next.previous = this), this.next = n.next, n.next = this;
2157
+ }
2158
+ }, _Ticker, Ticker = class n {
463
2159
  constructor() {
464
- this.objects = [];
2160
+ this.autoStart = !1, this.deltaTime = 1, this.lastTime = -1, this.speed = 1, this.started = !1, this._requestId = null, this._maxElapsedMS = 100, this._minElapsedMS = 0, this._lastFrame = -1, this._head = null, this._head = new TickerListener(null, null, Infinity), this.deltaMS = 1 / n.targetFPMS, this.elapsedMS = this.deltaMS, this._tick = (n) => {
2161
+ this._requestId = null, this.started && (this.update(n), this.started && this._requestId === null && (this._requestId = requestAnimationFrame(this._tick)));
2162
+ };
465
2163
  }
466
- add(r) {
467
- this.objects.push(r);
2164
+ update(j = performance.now()) {
2165
+ let M;
2166
+ if (j > this.lastTime) {
2167
+ if (M = this.elapsedMS = j - this.lastTime, M > this._maxElapsedMS && (M = this._maxElapsedMS), M *= this.speed, this._minElapsedMS) {
2168
+ let n = j - this._lastFrame | 0;
2169
+ if (n < this._minElapsedMS) return;
2170
+ this._lastFrame = j - n % this._minElapsedMS;
2171
+ }
2172
+ this.deltaMS = M, this.deltaTime = this.deltaMS * n.targetFPMS;
2173
+ let N = this._head, P = N.next;
2174
+ for (; P;) P = P.emit(this);
2175
+ N.next || this._cancelIfNeeded();
2176
+ } else this.deltaTime = this.deltaMS = this.elapsedMS = 0;
2177
+ this.lastTime = j;
468
2178
  }
469
- update(r) {
470
- for (let T of this.objects) T.update(r);
2179
+ get FPS() {
2180
+ return 1e3 / this.elapsedMS;
471
2181
  }
472
- }, Scene = class {
473
- constructor(r, T) {
474
- this.world = new World(), this.system = [], this.displayList = new DisplayList(), this.add = new AddFactory(this.displayList), this.camera = new Camera(r), this.tween = new TweenManager(), this.system.push(new SortSystem(this.world, T)), this.system.push(this.tween);
2182
+ get maxFPS() {
2183
+ return this._minElapsedMS ? Math.round(1e3 / this._minElapsedMS) : 0;
475
2184
  }
476
- _boot(r) {
477
- this.input = r.input, this.events = r.events, this.config = r.config;
2185
+ set maxFPS(n) {
2186
+ n === 0 ? this._minElapsedMS = 0 : (n < this.minFPS && (this.minFPS = n), this._minElapsedMS = 1 / (n / 1e3));
478
2187
  }
479
- registerSystem(r) {
480
- this.system.push(r);
2188
+ get minFPS() {
2189
+ return 1e3 / this._maxElapsedMS;
481
2190
  }
482
- create() {}
483
- resize(r, T) {
484
- this.camera.setViewport(0, 0, r, T);
2191
+ set minFPS(j) {
2192
+ this._maxElapsedMS = 1 / Math.min(Math.max(0, j) / 1e3, n.targetFPMS), this._minElapsedMS && j > this.maxFPS && (this.maxFPS = j);
485
2193
  }
486
- update(r) {
487
- for (let E of this.system) {
488
- var T;
489
- (T = E.update) == null || T.call(E, r);
2194
+ add(n, j, M = 0) {
2195
+ let N = new TickerListener(n, j, M), P = this._head.next, F = this._head;
2196
+ if (!P) N.connect(F);
2197
+ else {
2198
+ for (; P;) {
2199
+ if (N.priority > P.priority) {
2200
+ N.connect(F);
2201
+ break;
2202
+ }
2203
+ F = P, P = P.next;
2204
+ }
2205
+ N.previous || N.connect(F);
490
2206
  }
491
- this.camera.update(), this.world.update(r);
2207
+ return this._startIfPossible(), this;
492
2208
  }
493
- }, Projection2D = class {
494
- constructor(r = 1, T = 1) {
495
- this.scaleX = r, this.scaleY = T;
2209
+ start() {
2210
+ this.started || (this.started = !0, this._requestIfNeeded());
496
2211
  }
497
- project(r, T) {
498
- return {
499
- px: r * this.scaleX,
500
- py: T * this.scaleY
501
- };
2212
+ remove(n, j) {
2213
+ let M = this._head.next;
2214
+ for (; M;) M = M.match(n, j) ? M.destroy() : M.next;
2215
+ return this._head.next || this._cancelIfNeeded(), this;
502
2216
  }
503
- }, IsoProjection = class {
504
- constructor(r, T, E) {
505
- this.tileWidth = r, this.tileHeight = T, this.zHeight = E;
2217
+ _startIfPossible() {
2218
+ this.started ? this._requestIfNeeded() : this.autoStart && this.start();
506
2219
  }
507
- project(r, T, E = 0) {
508
- return {
509
- px: (r - T) * this.tileWidth / 2,
510
- py: (r + T) * this.tileHeight / 2 - E * this.zHeight
511
- };
2220
+ _requestIfNeeded() {
2221
+ this._requestId === null && this._head.next && (this.lastTime = performance.now(), this._lastFrame = this.lastTime, this._requestId = requestAnimationFrame(this._tick));
2222
+ }
2223
+ _cancelIfNeeded() {
2224
+ this._requestId !== null && (cancelAnimationFrame(this._requestId), this._requestId = null);
2225
+ }
2226
+ };
2227
+ _Ticker = Ticker, _Ticker.targetFPMS = .06;
2228
+ var plugins = [class {
2229
+ static init(n) {
2230
+ Object.defineProperty(this, "resizeTo", {
2231
+ configurable: !0,
2232
+ set(n) {
2233
+ globalThis.removeEventListener("resize", this.queueResize), this._resizeTo = n, n && (globalThis.addEventListener("resize", this.queueResize), this.resize());
2234
+ },
2235
+ get() {
2236
+ return this._resizeTo;
2237
+ }
2238
+ }), this.queueResize = () => {
2239
+ this._resizeTo && (this._cancelResize(), this._resizeId = requestAnimationFrame(() => this.resize));
2240
+ }, this._cancelResize = () => {
2241
+ this._resizeId && (cancelAnimationFrame(this._resizeId), this._resizeId = null);
2242
+ }, this.resize = () => {
2243
+ if (!this._resizeTo) return;
2244
+ this._cancelResize();
2245
+ let n, j;
2246
+ if (this._resizeTo === globalThis.window) n = globalThis.innerWidth, j = globalThis.innerHeight;
2247
+ else {
2248
+ let { clientWidth: M, clientHeight: N } = this._resizeTo;
2249
+ n = M, j = N;
2250
+ }
2251
+ this.renderer.resize(n, j), this.render();
2252
+ }, this._resizeId = null, this._resizeTo = null, this.resizeTo = n.resizeTo || null;
2253
+ }
2254
+ static destroy() {
2255
+ globalThis.removeEventListener("resize", this.queueResize), this._cancelResize(), this._cancelResize = null, this.queueResize = null, this.resizeTo = null, this.resize = null;
2256
+ }
2257
+ }], Application = class {
2258
+ constructor() {
2259
+ this.stage = new Container();
2260
+ }
2261
+ async init(n) {
2262
+ n = { ...n }, this.stage || (this.stage = new Container()), this.renderer = new CanvasRenderer(), await this.renderer.init(n), plugins.forEach((j) => {
2263
+ j.init.call(this, n);
2264
+ }), this.ticker = new Ticker(), (n.autoStart || n.autoStart == null) && this._ticker.start();
2265
+ }
2266
+ get canvas() {
2267
+ return this.renderer.canvas;
2268
+ }
2269
+ get screen() {
2270
+ return this.renderer.view.screen;
2271
+ }
2272
+ get ticker() {
2273
+ return this._ticker;
2274
+ }
2275
+ set ticker(n) {
2276
+ this._ticker && this._ticker.remove(this.render, this), this._ticker = n, n && n.add(this.render, this);
2277
+ }
2278
+ render() {
2279
+ this.renderer.render({ container: this.stage });
512
2280
  }
513
- }, IsoStragety = class {
514
- getKey(r) {
515
- return r.x + r.y + r.z;
516
- }
517
- }, ZIndexStragety = class {
518
- getKey(r) {
519
- return r.zIndex;
520
- }
521
- }, Game = class {
522
- constructor(r, T) {
523
- this.lastTime = 0, this.scene = null, this.config = _objectSpread2({
524
- width: window.innerWidth,
525
- height: window.innerHeight
526
- }, T);
527
- let O = window.innerWidth / this.config.width, k = window.devicePixelRatio;
528
- r.width = this.config.width * O * k, r.height = this.config.height * O * k, r.style.width = `${this.config.width * O}px`, r.style.height = `${this.config.height * O}px`;
529
- let A = r.getContext("2d");
530
- if (!A) throw Error("Canvas 2D context not found");
531
- this.events = new EventSystem(), this.input = new InputSystem(r, this.events), this.renderer = new Renderer(A), A.scale(O * k, O * k);
532
- }
533
- start(r) {
534
- this.scene = r, r._boot(this), r.registerSystem(this.input), r.registerSystem(this.events), r.create(), r.resize(this.config.width, this.config.height), window.requestAnimationFrame(this.loop.bind(this));
535
- }
536
- loop(r) {
537
- let T = r - this.lastTime;
538
- this.lastTime = r, this.scene && (this.scene.update(T), this.renderer.render(this.scene)), window.requestAnimationFrame(this.loop.bind(this));
2281
+ destroy() {
2282
+ let n = plugins.slice(0);
2283
+ n.reverse(), n.forEach((n) => {
2284
+ n.destroy.call(this);
2285
+ }), this.stage.destroy(), this.stage = null, this.renderer.destroy(), this.renderer = null;
539
2286
  }
540
2287
  };
541
- export { Cache, Camera, CameraController, Container, DisplayList, Easings, Game, GameObject, ImageObject, InputEventType, InputSystem, IsoProjection, IsoStragety, Projection2D, ResourceManager, Scene, Text, TweenManager, ZIndexStragety };
2288
+ export { Application, Assets, Cache, CanvasRenderer, Container, Graphics, GraphicsContext, GraphicsPipe, ImageFile, Loader, Matrix, PI_2, Rectangle, RenderGroup, ResourceManager, Sprite, Text, TextPipe, Texture, Ticker, TickerListener, UPDATE_BLEND, UPDATE_COLOR, UPDATE_TRANSFORM, UPDATE_VISIBLE, Vector2, ViewContainer, buildShapePath, nextPow2 };
2289
+
2290
+ //# sourceMappingURL=dao.js.map