@m2c2kit/core 0.3.13 → 0.3.15

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 (3) hide show
  1. package/dist/index.d.ts +154 -47
  2. package/dist/index.js +1217 -1054
  3. package/package.json +19 -17
package/dist/index.js CHANGED
@@ -6,15 +6,10 @@ var ActionType = /* @__PURE__ */ ((ActionType2) => {
6
6
  ActionType2["Move"] = "Move";
7
7
  ActionType2["Scale"] = "Scale";
8
8
  ActionType2["FadeAlpha"] = "FadeAlpha";
9
+ ActionType2["Rotate"] = "Rotate";
9
10
  return ActionType2;
10
11
  })(ActionType || {});
11
12
 
12
- var __defProp$k = Object.defineProperty;
13
- var __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
- var __publicField$k = (obj, key, value) => {
15
- __defNormalProp$k(obj, typeof key !== "symbol" ? key + "" : key, value);
16
- return value;
17
- };
18
13
  class Easings {
19
14
  }
20
15
  // These easing functions are adapted from work by Robert Penner
@@ -33,134 +28,444 @@ class Easings {
33
28
  // Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
34
29
  // Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
35
30
  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
- __publicField$k(Easings, "none", (t, b, c, d) => {
31
+ Easings.none = (t, b, c, d) => {
37
32
  return c + b;
38
- });
39
- __publicField$k(Easings, "linear", (t, b, c, d) => {
33
+ };
34
+ Easings.linear = (t, b, c, d) => {
40
35
  return c * t / d + b;
41
- });
42
- __publicField$k(Easings, "quadraticIn", (t, b, c, d) => {
36
+ };
37
+ Easings.quadraticIn = (t, b, c, d) => {
43
38
  t /= d;
44
39
  return c * t * t + b;
45
- });
46
- __publicField$k(Easings, "quadraticOut", (t, b, c, d) => {
40
+ };
41
+ Easings.quadraticOut = (t, b, c, d) => {
47
42
  t /= d;
48
43
  return -c * t * (t - 2) + b;
49
- });
50
- __publicField$k(Easings, "quadraticInOut", (t, b, c, d) => {
44
+ };
45
+ Easings.quadraticInOut = (t, b, c, d) => {
51
46
  t /= d / 2;
52
47
  if (t < 1)
53
48
  return c / 2 * t * t + b;
54
49
  t--;
55
50
  return -c / 2 * (t * (t - 2) - 1) + b;
56
- });
57
- __publicField$k(Easings, "cubicIn", (t, b, c, d) => {
51
+ };
52
+ Easings.cubicIn = (t, b, c, d) => {
58
53
  t /= d;
59
54
  return c * t * t * t + b;
60
- });
61
- __publicField$k(Easings, "cubicOut", (t, b, c, d) => {
55
+ };
56
+ Easings.cubicOut = (t, b, c, d) => {
62
57
  t /= d;
63
58
  t--;
64
59
  return c * (t * t * t + 1) + b;
65
- });
66
- __publicField$k(Easings, "cubicInOut", (t, b, c, d) => {
60
+ };
61
+ Easings.cubicInOut = (t, b, c, d) => {
67
62
  t /= d / 2;
68
63
  if (t < 1)
69
64
  return c / 2 * t * t * t + b;
70
65
  t -= 2;
71
66
  return c / 2 * (t * t * t + 2) + b;
72
- });
73
- __publicField$k(Easings, "quarticIn", (t, b, c, d) => {
67
+ };
68
+ Easings.quarticIn = (t, b, c, d) => {
74
69
  t /= d;
75
70
  return c * t * t * t * t + b;
76
- });
77
- __publicField$k(Easings, "quarticOut", (t, b, c, d) => {
71
+ };
72
+ Easings.quarticOut = (t, b, c, d) => {
78
73
  t /= d;
79
74
  t--;
80
75
  return -c * (t * t * t * t - 1) + b;
81
- });
82
- __publicField$k(Easings, "quarticInOut", (t, b, c, d) => {
76
+ };
77
+ Easings.quarticInOut = (t, b, c, d) => {
83
78
  t /= d / 2;
84
79
  if (t < 1)
85
80
  return c / 2 * t * t * t * t + b;
86
81
  t -= 2;
87
82
  return -c / 2 * (t * t * t * t - 2) + b;
88
- });
89
- __publicField$k(Easings, "quinticIn", (t, b, c, d) => {
83
+ };
84
+ Easings.quinticIn = (t, b, c, d) => {
90
85
  t /= d;
91
86
  return c * t * t * t * t * t + b;
92
- });
93
- __publicField$k(Easings, "quinticOut", (t, b, c, d) => {
87
+ };
88
+ Easings.quinticOut = (t, b, c, d) => {
94
89
  t /= d;
95
90
  t--;
96
91
  return c * (t * t * t * t * t + 1) + b;
97
- });
98
- __publicField$k(Easings, "quinticInOut", (t, b, c, d) => {
92
+ };
93
+ Easings.quinticInOut = (t, b, c, d) => {
99
94
  t /= d / 2;
100
95
  if (t < 1)
101
96
  return c / 2 * t * t * t * t * t + b;
102
97
  t -= 2;
103
98
  return c / 2 * (t * t * t * t * t + 2) + b;
104
- });
105
- __publicField$k(Easings, "sinusoidalIn", (t, b, c, d) => {
99
+ };
100
+ Easings.sinusoidalIn = (t, b, c, d) => {
106
101
  return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
107
- });
108
- __publicField$k(Easings, "sinusoidalOut", (t, b, c, d) => {
102
+ };
103
+ Easings.sinusoidalOut = (t, b, c, d) => {
109
104
  return c * Math.sin(t / d * (Math.PI / 2)) + b;
110
- });
111
- __publicField$k(Easings, "sinusoidalInOut", (t, b, c, d) => {
105
+ };
106
+ Easings.sinusoidalInOut = (t, b, c, d) => {
112
107
  return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
113
- });
114
- __publicField$k(Easings, "exponentialIn", (t, b, c, d) => {
108
+ };
109
+ Easings.exponentialIn = (t, b, c, d) => {
115
110
  return c * Math.pow(2, 10 * (t / d - 1)) + b;
116
- });
117
- __publicField$k(Easings, "exponentialOut", (t, b, c, d) => {
111
+ };
112
+ Easings.exponentialOut = (t, b, c, d) => {
118
113
  return c * (-Math.pow(2, -10 * t / d) + 1) + b;
119
- });
120
- __publicField$k(Easings, "exponentialInOut", (t, b, c, d) => {
114
+ };
115
+ Easings.exponentialInOut = (t, b, c, d) => {
121
116
  t /= d / 2;
122
117
  if (t < 1)
123
118
  return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
124
119
  t--;
125
120
  return c / 2 * (-Math.pow(2, -10 * t) + 2) + b;
126
- });
127
- __publicField$k(Easings, "circularIn", (t, b, c, d) => {
121
+ };
122
+ Easings.circularIn = (t, b, c, d) => {
128
123
  t /= d;
129
124
  return -c * (Math.sqrt(1 - t * t) - 1) + b;
130
- });
131
- __publicField$k(Easings, "circularOut", (t, b, c, d) => {
125
+ };
126
+ Easings.circularOut = (t, b, c, d) => {
132
127
  t /= d;
133
128
  t--;
134
129
  return c * Math.sqrt(1 - t * t) + b;
135
- });
136
- __publicField$k(Easings, "circularInOut", (t, b, c, d) => {
130
+ };
131
+ Easings.circularInOut = (t, b, c, d) => {
137
132
  t /= d / 2;
138
133
  if (t < 1)
139
134
  return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
140
135
  t -= 2;
141
136
  return c / 2 * (Math.sqrt(1 - t * t) + 1) + b;
142
- });
143
-
144
- var __defProp$j = Object.defineProperty;
145
- var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
146
- var __publicField$j = (obj, key, value) => {
147
- __defNormalProp$j(obj, typeof key !== "symbol" ? key + "" : key, value);
148
- return value;
149
137
  };
138
+
139
+ var EntityType = /* @__PURE__ */ ((EntityType2) => {
140
+ EntityType2["Entity"] = "Entity";
141
+ EntityType2["Scene"] = "Scene";
142
+ EntityType2["Sprite"] = "Sprite";
143
+ EntityType2["Label"] = "Label";
144
+ EntityType2["TextLine"] = "TextLine";
145
+ EntityType2["Shape"] = "Shape";
146
+ EntityType2["Composite"] = "Composite";
147
+ return EntityType2;
148
+ })(EntityType || {});
149
+
150
+ var ShapeType = /* @__PURE__ */ ((ShapeType2) => {
151
+ ShapeType2["Undefined"] = "Undefined";
152
+ ShapeType2["Rectangle"] = "Rectangle";
153
+ ShapeType2["Circle"] = "Circle";
154
+ ShapeType2["Path"] = "Path";
155
+ return ShapeType2;
156
+ })(ShapeType || {});
157
+
158
+ class M2c2KitHelpers {
159
+ /**
160
+ * Calculates the four points of the bounding box of the entity, taking
161
+ * into account the entity's rotation (as well as the rotation of its
162
+ * ancestors).
163
+ *
164
+ * @remarks This method is used to calculate the rotated bounding box of an
165
+ * entity when in order to determine if a point is inside the entity in
166
+ * response to DOM pointer events. This method is NOT used to prepare the
167
+ * CanvasKit canvas for drawing the entity.
168
+ *
169
+ * @param drawableEntity
170
+ * @returns array of points representing the rotated entity
171
+ */
172
+ static calculateRotatedPoints(drawableEntity) {
173
+ const entities = drawableEntity.ancestors;
174
+ entities.reverse();
175
+ entities.push(drawableEntity);
176
+ const entityPointsArray = entities.map((entity) => {
177
+ const boundingBox = M2c2KitHelpers.calculateEntityAbsoluteBoundingBox(entity);
178
+ return M2c2KitHelpers.boundingBoxToPoints(boundingBox);
179
+ });
180
+ for (let i = 0; i < entityPointsArray.length; i++) {
181
+ if (!entityNeedsRotation(entities[i])) {
182
+ continue;
183
+ }
184
+ const entityPoints = entityPointsArray[i];
185
+ const radians = entities[i].zRotation;
186
+ const center = M2c2KitHelpers.findCentroid(entityPoints);
187
+ for (let j = i; j < entities.length; j++) {
188
+ entityPointsArray[j] = rotateRectangle(
189
+ entityPointsArray[j],
190
+ radians,
191
+ center
192
+ );
193
+ }
194
+ }
195
+ return entityPointsArray[entityPointsArray.length - 1];
196
+ }
197
+ /**
198
+ * Rotates the canvas so the entity appears rotated when drawn.
199
+ *
200
+ * @remarks Entities inherit rotations from their ancestors. Each ancestor,
201
+ * however, rotates around its own anchor point. Thus, we must rotate the
202
+ * canvas around the anchor point of each ancestor as well as the entity's
203
+ * anchor point.
204
+ *
205
+ * @param canvas - CanvasKit canvas to rotate
206
+ * @param drawableEntity - Entity to rotate the canvas for
207
+ */
208
+ static rotateCanvasForDrawableEntity(canvas, drawableEntity) {
209
+ const rotationTransforms = M2c2KitHelpers.calculateRotationTransforms(drawableEntity);
210
+ if (rotationTransforms.length === 0) {
211
+ return;
212
+ }
213
+ const drawScale = Globals.canvasScale / drawableEntity.absoluteScale;
214
+ applyRotationTransformsToCanvas(rotationTransforms, drawScale, canvas);
215
+ }
216
+ /**
217
+ * Calculates the absolute bounding box of the entity before any rotation
218
+ * is applied.
219
+ *
220
+ * @remarks The absolute bounding box is the bounding box of the entity
221
+ * relative to the scene's origin (0, 0).
222
+ *
223
+ * @param entity
224
+ * @returns the bounding box of the entity
225
+ */
226
+ static calculateEntityAbsoluteBoundingBox(entity) {
227
+ const anchorPoint = entity.anchorPoint;
228
+ const scale = entity.absoluteScale;
229
+ let width = entity.size.width;
230
+ let height = entity.size.height;
231
+ if (entity.type === EntityType.Shape && entity.shapeType === ShapeType.Circle) {
232
+ const radius = entity.circleOfRadius;
233
+ if (!radius) {
234
+ throw "circleOfRadius is undefined";
235
+ }
236
+ width = radius * 2;
237
+ height = radius * 2;
238
+ }
239
+ const xMin = entity.absolutePosition.x - width * anchorPoint.x * scale;
240
+ const xMax = entity.absolutePosition.x + width * (1 - anchorPoint.x) * scale;
241
+ const yMin = entity.absolutePosition.y - height * anchorPoint.y * scale;
242
+ const yMax = entity.absolutePosition.y + height * (1 - anchorPoint.y) * scale;
243
+ return { xMin, xMax, yMin, yMax };
244
+ }
245
+ /**
246
+ * Converts an angle from radians to degrees.
247
+ *
248
+ * @remarks In m2c2kit, radians are counter clockwise from the positive
249
+ * x-axis, but the rotate method in CanvasKit uses degrees clockwise. Thus
250
+ * we negate after conversion from radians to degrees.
251
+ *
252
+ * @param radians - The angle in radians
253
+ * @returns The angle in degrees
254
+ */
255
+ static radiansToDegrees(radians) {
256
+ return -M2c2KitHelpers.normalizeAngleRadians(radians) * (180 / Math.PI);
257
+ }
258
+ /**
259
+ * Normalizes an angle in radians to the range [0, 2*Math.PI)
260
+ *
261
+ * @param radians - angle in radians
262
+ * @returns normalized angle in radians
263
+ */
264
+ static normalizeAngleRadians(radians) {
265
+ const quotient = Math.floor(radians / (2 * Math.PI));
266
+ let normalized = radians - quotient * (2 * Math.PI);
267
+ if (normalized < 0) {
268
+ normalized += 2 * Math.PI;
269
+ }
270
+ return normalized;
271
+ }
272
+ /**
273
+ * Checks if two points are on the same side of a line.
274
+ *
275
+ * @remarks The line is defined by two points, a and b. The function uses
276
+ * the cross product to determine the relative position of the points.
277
+ *
278
+ * @param p1 - point to check
279
+ * @param p2 - point to check
280
+ * @param a - point that defines one end of the line
281
+ * @param b - point that defines the other end of the line
282
+ * @returns true if p1 and p2 are on the same side of the line, or false
283
+ * otherwise
284
+ */
285
+ static arePointsOnSameSideOfLine(p1, p2, a, b) {
286
+ const cp1 = (b.x - a.x) * (p1.y - a.y) - (b.y - a.y) * (p1.x - a.x);
287
+ const cp2 = (b.x - a.x) * (p2.y - a.y) - (b.y - a.y) * (p2.x - a.x);
288
+ return cp1 * cp2 >= 0;
289
+ }
290
+ /**
291
+ * Checks if a point is inside a rectangle.
292
+ *
293
+ * @remarks The rectangle may have been rotated (sides might not be parallel
294
+ * to the axes).
295
+ *
296
+ * @param point - The Point to check
297
+ * @param rect - An array of four Points representing the vertices of the
298
+ * rectangle in clockwise order
299
+ * @returns true if the Point is inside the rectangle
300
+ */
301
+ static isPointInsideRectangle(point, rect) {
302
+ if (rect.length !== 4) {
303
+ throw new Error("Invalid input: expected an array of four points");
304
+ }
305
+ return M2c2KitHelpers.arePointsOnSameSideOfLine(
306
+ point,
307
+ rect[2],
308
+ rect[0],
309
+ rect[1]
310
+ ) && M2c2KitHelpers.arePointsOnSameSideOfLine(
311
+ point,
312
+ rect[3],
313
+ rect[1],
314
+ rect[2]
315
+ ) && M2c2KitHelpers.arePointsOnSameSideOfLine(
316
+ point,
317
+ rect[0],
318
+ rect[2],
319
+ rect[3]
320
+ ) && M2c2KitHelpers.arePointsOnSameSideOfLine(point, rect[1], rect[3], rect[0]);
321
+ }
322
+ /**
323
+ * Checks if the entity or any of its ancestors have been rotated.
324
+ *
325
+ * @param entity - entity to check
326
+ * @returns true if the entity or any of its ancestors have been rotated
327
+ */
328
+ static entityOrAncestorHasBeenRotated(entity) {
329
+ const entities = entity.ancestors;
330
+ entities.push(entity);
331
+ return entities.some((entity2) => entityNeedsRotation(entity2));
332
+ }
333
+ /**
334
+ * Converts a bounding box to an array of four points representing the
335
+ * vertices of the rectangle.
336
+ *
337
+ * @remarks In m2c2kit, the y-axis is inverted: origin is in the upper-left.
338
+ * Vertices are returned in clockwise order starting from the upper-left.
339
+ *
340
+ * @param boundingBox
341
+ * @returns An array of four points
342
+ */
343
+ static boundingBoxToPoints(boundingBox) {
344
+ const { xMin, xMax, yMin, yMax } = boundingBox;
345
+ const points = [
346
+ { x: xMin, y: yMin },
347
+ // Top left
348
+ { x: xMax, y: yMin },
349
+ // Top right
350
+ { x: xMax, y: yMax },
351
+ // Bottom right
352
+ { x: xMin, y: yMax }
353
+ // Bottom left
354
+ ];
355
+ return points;
356
+ }
357
+ /**
358
+ * Finds the centroid of a rectangle.
359
+ *
360
+ * @param points - An array of four points representing the vertices of the
361
+ * rectangle.
362
+ * @returns array of points representing the centroid of the rectangle.
363
+ */
364
+ static findCentroid(points) {
365
+ if (points.length !== 4) {
366
+ throw new Error("Invalid input: expected an array of four points");
367
+ }
368
+ let xSum = 0;
369
+ let ySum = 0;
370
+ for (const point of points) {
371
+ xSum += point.x;
372
+ ySum += point.y;
373
+ }
374
+ const xAvg = xSum / 4;
375
+ const yAvg = ySum / 4;
376
+ return { x: xAvg, y: yAvg };
377
+ }
378
+ /**
379
+ * Rotates a point, counterclockwise, around another point by an angle in
380
+ * radians.
381
+ *
382
+ * @param point - Point to rotate
383
+ * @param radians - angle in radians
384
+ * @param center - Point to rotate around
385
+ * @returns rotated point
386
+ */
387
+ static rotatePoint(point, radians, center) {
388
+ const dx = point.x - center.x;
389
+ const dy = point.y - center.y;
390
+ const x = dx * Math.cos(-radians) - dy * Math.sin(-radians);
391
+ const y = dx * Math.sin(-radians) + dy * Math.cos(-radians);
392
+ return {
393
+ x: x + center.x,
394
+ y: y + center.y
395
+ };
396
+ }
397
+ /**
398
+ * Calculates the rotation transforms to apply to entity, respecting any
399
+ * ancestor rotations.
400
+ *
401
+ * @param drawableEntity - entity to calculate rotation transforms for
402
+ * @returns array of rotation transforms to apply
403
+ */
404
+ static calculateRotationTransforms(drawableEntity) {
405
+ const rotationTransforms = [];
406
+ const entities = drawableEntity.ancestors;
407
+ entities.reverse();
408
+ entities.push(drawableEntity);
409
+ entities.forEach((entity) => {
410
+ if (entityNeedsRotation(entity)) {
411
+ const drawable = entity;
412
+ if (drawable.type === EntityType.Scene) {
413
+ const center2 = {
414
+ x: drawable.absolutePosition.x + drawable.size.width * 0.5,
415
+ y: drawable.absolutePosition.y + drawable.size.height * 0.5
416
+ };
417
+ rotationTransforms.push({
418
+ radians: drawable.zRotation,
419
+ center: center2
420
+ });
421
+ return;
422
+ }
423
+ const boundingBox = M2c2KitHelpers.calculateEntityAbsoluteBoundingBox(drawable);
424
+ const points = M2c2KitHelpers.boundingBoxToPoints(boundingBox);
425
+ const center = M2c2KitHelpers.findCentroid(points);
426
+ rotationTransforms.push({
427
+ radians: drawable.zRotation,
428
+ center
429
+ });
430
+ }
431
+ });
432
+ return rotationTransforms;
433
+ }
434
+ }
435
+ function applyRotationTransformsToCanvas(rotationTransforms, scale, canvas) {
436
+ rotationTransforms.forEach((transform) => {
437
+ canvas.rotate(
438
+ M2c2KitHelpers.radiansToDegrees(transform.radians),
439
+ transform.center.x * scale,
440
+ transform.center.y * scale
441
+ );
442
+ });
443
+ }
444
+ function entityNeedsRotation(entity) {
445
+ return M2c2KitHelpers.normalizeAngleRadians(entity.zRotation) !== 0 && entity.isDrawable;
446
+ }
447
+ function rotateRectangle(rect, radians, center) {
448
+ if (rect.length !== 4) {
449
+ throw new Error("Invalid input: expected an array of four points");
450
+ }
451
+ const rotated = [];
452
+ for (const p of rect) {
453
+ rotated.push(M2c2KitHelpers.rotatePoint(p, radians, center));
454
+ }
455
+ return rotated;
456
+ }
457
+
150
458
  class Action {
151
459
  constructor(runDuringTransition = false) {
152
- __publicField$j(this, "startOffset", -1);
153
- __publicField$j(this, "endOffset", -1);
154
- __publicField$j(this, "started", false);
155
- __publicField$j(this, "running", false);
156
- __publicField$j(this, "completed", false);
157
- __publicField$j(this, "runStartTime", -1);
158
- __publicField$j(this, "duration", 0);
159
- __publicField$j(this, "runDuringTransition");
160
- __publicField$j(this, "parent");
161
- __publicField$j(this, "isParent", false);
162
- __publicField$j(this, "isChild", false);
163
- __publicField$j(this, "key");
460
+ this.startOffset = -1;
461
+ this.endOffset = -1;
462
+ this.started = false;
463
+ this.running = false;
464
+ this.completed = false;
465
+ this.runStartTime = -1;
466
+ this.duration = 0;
467
+ this.isParent = false;
468
+ this.isChild = false;
164
469
  this.runDuringTransition = runDuringTransition;
165
470
  }
166
471
  /**
@@ -170,12 +475,11 @@ class Action {
170
475
  * @returns The move action
171
476
  */
172
477
  static move(options) {
173
- var _a, _b;
174
478
  return new MoveAction(
175
479
  options.point,
176
480
  options.duration,
177
- (_a = options.easing) != null ? _a : Easings.linear,
178
- (_b = options.runDuringTransition) != null ? _b : false
481
+ options.easing ?? Easings.linear,
482
+ options.runDuringTransition ?? false
179
483
  );
180
484
  }
181
485
  /**
@@ -185,10 +489,9 @@ class Action {
185
489
  * @returns The wait action
186
490
  */
187
491
  static wait(options) {
188
- var _a;
189
492
  return new WaitAction(
190
493
  options.duration,
191
- (_a = options.runDuringTransition) != null ? _a : false
494
+ options.runDuringTransition ?? false
192
495
  );
193
496
  }
194
497
  /**
@@ -198,10 +501,9 @@ class Action {
198
501
  * @returns The custom action
199
502
  */
200
503
  static custom(options) {
201
- var _a;
202
504
  return new CustomAction(
203
505
  options.callback,
204
- (_a = options.runDuringTransition) != null ? _a : false
506
+ options.runDuringTransition ?? false
205
507
  );
206
508
  }
207
509
  /**
@@ -234,6 +536,37 @@ class Action {
234
536
  options.runDuringTransition
235
537
  );
236
538
  }
539
+ /**
540
+ * Creates an action that will rotate the entity.
541
+ *
542
+ * @remarks Rotate actions are applied to their children. In addition to this entity's rotate action, all ancestors' rotate actions will also be applied.
543
+ *
544
+ * @param options - {@link RotateActionOptions}
545
+ * @returns The rotate action
546
+ */
547
+ static rotate(options) {
548
+ if (options.byAngle !== void 0 && options.toAngle !== void 0) {
549
+ throw new Error("rotate Action: cannot specify both byAngle and toAngle");
550
+ }
551
+ if (options.byAngle === void 0 && options.toAngle === void 0) {
552
+ throw new Error("rotate Action: must specify either byAngle or toAngle");
553
+ }
554
+ if (options.toAngle === void 0 && options.shortestUnitArc !== void 0) {
555
+ throw new Error(
556
+ "rotate Action: shortestUnitArc can only be specified when toAngle is provided"
557
+ );
558
+ }
559
+ if (options.toAngle !== void 0 && options.shortestUnitArc === void 0) {
560
+ options.shortestUnitArc = true;
561
+ }
562
+ return new RotateAction(
563
+ options.byAngle,
564
+ options.toAngle,
565
+ options.shortestUnitArc,
566
+ options.duration,
567
+ options.runDuringTransition
568
+ );
569
+ }
237
570
  /**
238
571
  * Creates an array of actions that will be run in order.
239
572
  *
@@ -329,6 +662,17 @@ class Action {
329
662
  });
330
663
  break;
331
664
  }
665
+ case ActionType.Rotate: {
666
+ const rotate = action;
667
+ cloned = Action.rotate({
668
+ byAngle: rotate.byAngle,
669
+ toAngle: rotate.toAngle,
670
+ shortestUnitArc: rotate.shortestUnitArc,
671
+ duration: rotate.duration,
672
+ runDuringTransition: rotate.runDuringTransition
673
+ });
674
+ break;
675
+ }
332
676
  case ActionType.Wait: {
333
677
  const wait = action;
334
678
  cloned = Action.wait({
@@ -430,6 +774,41 @@ class Action {
430
774
  fadeAlphaAction.completed = true;
431
775
  }
432
776
  }
777
+ if (action.type === ActionType.Rotate) {
778
+ const rotateAction = action;
779
+ if (!rotateAction.started) {
780
+ if (rotateAction.byAngle !== void 0) {
781
+ rotateAction.delta = rotateAction.byAngle;
782
+ }
783
+ if (rotateAction.toAngle !== void 0) {
784
+ rotateAction.toAngle = M2c2KitHelpers.normalizeAngleRadians(
785
+ rotateAction.toAngle
786
+ );
787
+ entity.zRotation = M2c2KitHelpers.normalizeAngleRadians(
788
+ entity.zRotation
789
+ );
790
+ rotateAction.delta = rotateAction.toAngle - entity.zRotation;
791
+ if (rotateAction.shortestUnitArc === true && Math.abs(rotateAction.delta) > Math.PI) {
792
+ rotateAction.delta = 2 * Math.PI - Math.abs(rotateAction.delta);
793
+ }
794
+ }
795
+ rotateAction.started = true;
796
+ rotateAction.finalValue = entity.zRotation + rotateAction.delta;
797
+ }
798
+ if (elapsed < rotateAction.duration) {
799
+ entity.zRotation = entity.zRotation + rotateAction.delta * (dt / rotateAction.duration);
800
+ if (rotateAction.delta <= 0 && entity.zRotation < rotateAction.finalValue) {
801
+ entity.zRotation = rotateAction.finalValue;
802
+ }
803
+ if (rotateAction.delta > 0 && entity.zRotation > rotateAction.finalValue) {
804
+ entity.zRotation = rotateAction.finalValue;
805
+ }
806
+ } else {
807
+ entity.zRotation = rotateAction.finalValue;
808
+ rotateAction.running = false;
809
+ rotateAction.completed = true;
810
+ }
811
+ }
433
812
  }
434
813
  /**
435
814
  * Calculates the duration of an action, including any children actions
@@ -467,17 +846,16 @@ class Action {
467
846
  * @param action that needs assigning start and end offsets
468
847
  */
469
848
  calculateStartEndOffsets(action) {
470
- var _a, _b, _c;
471
849
  let parentStartOffset;
472
850
  if (action.parent === void 0) {
473
851
  parentStartOffset = 0;
474
852
  } else {
475
853
  parentStartOffset = action.parent.startOffset;
476
854
  }
477
- if (((_a = action.parent) == null ? void 0 : _a.type) === ActionType.Group) {
855
+ if (action.parent?.type === ActionType.Group) {
478
856
  action.startOffset = parentStartOffset;
479
857
  action.endOffset = action.startOffset + action.duration;
480
- } else if (((_b = action.parent) == null ? void 0 : _b.type) === ActionType.Sequence) {
858
+ } else if (action.parent?.type === ActionType.Sequence) {
481
859
  const parent = action.parent;
482
860
  let dur = 0;
483
861
  for (const a of parent.children) {
@@ -493,7 +871,7 @@ class Action {
493
871
  action.endOffset = action.startOffset + action.duration;
494
872
  }
495
873
  if (action.isParent) {
496
- (_c = action.children) == null ? void 0 : _c.forEach(
874
+ action.children?.forEach(
497
875
  (child) => this.calculateStartEndOffsets(child)
498
876
  );
499
877
  }
@@ -551,8 +929,7 @@ class Action {
551
929
  class SequenceAction extends Action {
552
930
  constructor(actions) {
553
931
  super();
554
- __publicField$j(this, "type", ActionType.Sequence);
555
- __publicField$j(this, "children");
932
+ this.type = ActionType.Sequence;
556
933
  this.children = actions;
557
934
  this.isParent = true;
558
935
  }
@@ -560,8 +937,8 @@ class SequenceAction extends Action {
560
937
  class GroupAction extends Action {
561
938
  constructor(actions) {
562
939
  super();
563
- __publicField$j(this, "type", ActionType.Group);
564
- __publicField$j(this, "children", new Array());
940
+ this.type = ActionType.Group;
941
+ this.children = new Array();
565
942
  this.children = actions;
566
943
  this.isParent = true;
567
944
  }
@@ -569,8 +946,7 @@ class GroupAction extends Action {
569
946
  class CustomAction extends Action {
570
947
  constructor(callback, runDuringTransition = false) {
571
948
  super(runDuringTransition);
572
- __publicField$j(this, "type", ActionType.Custom);
573
- __publicField$j(this, "callback");
949
+ this.type = ActionType.Custom;
574
950
  this.callback = callback;
575
951
  this.isParent = false;
576
952
  this.duration = 0;
@@ -579,7 +955,7 @@ class CustomAction extends Action {
579
955
  class WaitAction extends Action {
580
956
  constructor(duration, runDuringTransition) {
581
957
  super(runDuringTransition);
582
- __publicField$j(this, "type", ActionType.Wait);
958
+ this.type = ActionType.Wait;
583
959
  this.duration = duration;
584
960
  this.isParent = false;
585
961
  }
@@ -587,12 +963,9 @@ class WaitAction extends Action {
587
963
  class MoveAction extends Action {
588
964
  constructor(point, duration, easing, runDuringTransition) {
589
965
  super(runDuringTransition);
590
- __publicField$j(this, "type", ActionType.Move);
591
- __publicField$j(this, "point");
592
- __publicField$j(this, "startPoint");
593
- __publicField$j(this, "dx", 0);
594
- __publicField$j(this, "dy", 0);
595
- __publicField$j(this, "easing");
966
+ this.type = ActionType.Move;
967
+ this.dx = 0;
968
+ this.dy = 0;
596
969
  this.duration = duration;
597
970
  this.point = point;
598
971
  this.isParent = false;
@@ -603,9 +976,8 @@ class MoveAction extends Action {
603
976
  class ScaleAction extends Action {
604
977
  constructor(scale, duration, runDuringTransition = false) {
605
978
  super(runDuringTransition);
606
- __publicField$j(this, "type", ActionType.Scale);
607
- __publicField$j(this, "scale");
608
- __publicField$j(this, "delta", 0);
979
+ this.type = ActionType.Scale;
980
+ this.delta = 0;
609
981
  this.duration = duration;
610
982
  this.scale = scale;
611
983
  this.isParent = false;
@@ -614,58 +986,363 @@ class ScaleAction extends Action {
614
986
  class FadeAlphaAction extends Action {
615
987
  constructor(alpha, duration, runDuringTransition = false) {
616
988
  super(runDuringTransition);
617
- __publicField$j(this, "type", ActionType.FadeAlpha);
618
- __publicField$j(this, "alpha");
619
- __publicField$j(this, "delta", 0);
989
+ this.type = ActionType.FadeAlpha;
990
+ this.delta = 0;
620
991
  this.duration = duration;
621
992
  this.alpha = alpha;
622
993
  this.isParent = false;
623
994
  }
624
- }
625
-
626
- var ActivityType = /* @__PURE__ */ ((ActivityType2) => {
627
- ActivityType2["Game"] = "Game";
628
- ActivityType2["Survey"] = "Survey";
629
- return ActivityType2;
630
- })(ActivityType || {});
631
-
632
- class CanvasKitHelpers {
995
+ }
996
+ class RotateAction extends Action {
997
+ constructor(byAngle, toAngle, shortestUnitArc, duration, runDuringTransition = false) {
998
+ super(runDuringTransition);
999
+ this.type = ActionType.Rotate;
1000
+ this.delta = 0;
1001
+ this.finalValue = NaN;
1002
+ this.duration = duration;
1003
+ this.byAngle = byAngle;
1004
+ this.toAngle = toAngle;
1005
+ this.shortestUnitArc = shortestUnitArc;
1006
+ this.isParent = false;
1007
+ }
1008
+ }
1009
+
1010
+ var ActivityType = /* @__PURE__ */ ((ActivityType2) => {
1011
+ ActivityType2["Game"] = "Game";
1012
+ ActivityType2["Survey"] = "Survey";
1013
+ return ActivityType2;
1014
+ })(ActivityType || {});
1015
+
1016
+ class CanvasKitHelpers {
1017
+ /**
1018
+ * Frees up resources that were allocated by CanvasKit.
1019
+ *
1020
+ * @remarks This frees objects created in WebAssembly by
1021
+ * canvaskit-wasm. JavaScript garbage collection won't
1022
+ * free these wasm objects.
1023
+ */
1024
+ static Dispose(objects) {
1025
+ objects.filter((o) => !o?.isDeleted()).forEach((o) => o?.delete());
1026
+ }
1027
+ static makePaint(canvasKit, color, style, isAntialiased) {
1028
+ const paint = new canvasKit.Paint();
1029
+ paint.setColor(canvasKit.Color(color[0], color[1], color[2], color[3]));
1030
+ paint.setStyle(style);
1031
+ paint.setAntiAlias(isAntialiased);
1032
+ return paint;
1033
+ }
1034
+ }
1035
+
1036
+ class MutablePath {
1037
+ constructor() {
1038
+ this._subpaths = new Array();
1039
+ this.currentPath = new Array();
1040
+ }
1041
+ get subpaths() {
1042
+ if (this.currentPath.length > 0) {
1043
+ return [...this._subpaths, this.currentPath];
1044
+ } else {
1045
+ return this._subpaths;
1046
+ }
1047
+ }
1048
+ /**
1049
+ * Starts a new subpath at a given point.
1050
+ *
1051
+ * @param point - location at which to start the new subpath
1052
+ */
1053
+ move(point) {
1054
+ if (this.currentPath.length > 0) {
1055
+ this._subpaths.push(this.currentPath);
1056
+ }
1057
+ this.currentPath = new Array();
1058
+ this.currentPath.push(point);
1059
+ }
1060
+ /**
1061
+ * Adds a straight line to the current subpath.
1062
+ *
1063
+ * @remarks The line is added from the last point in the current subpath to
1064
+ * the given point.
1065
+ *
1066
+ * @param point - location where the line will end
1067
+ */
1068
+ addLine(point) {
1069
+ this.currentPath.push(point);
1070
+ }
1071
+ /**
1072
+ * Removes all subpaths from the shape.
1073
+ */
1074
+ clear() {
1075
+ this._subpaths = new Array();
1076
+ this.currentPath = new Array();
1077
+ }
1078
+ /**
1079
+ * Makes a deep copy.
1080
+ *
1081
+ * @returns a deep copy
1082
+ */
1083
+ duplicate() {
1084
+ const newPath = new MutablePath();
1085
+ newPath._subpaths = JSON.parse(JSON.stringify(this._subpaths));
1086
+ newPath.currentPath = JSON.parse(JSON.stringify(this.currentPath));
1087
+ return newPath;
1088
+ }
1089
+ }
1090
+
1091
+ class WebColors {
1092
+ }
1093
+ WebColors.Transparent = [0, 0, 0, 0];
1094
+ WebColors.MediumVioletRed = [199, 21, 133, 1];
1095
+ WebColors.DeepPink = [255, 20, 147, 1];
1096
+ WebColors.PaleVioletRed = [219, 112, 147, 1];
1097
+ WebColors.HotPink = [255, 105, 180, 1];
1098
+ WebColors.LightPink = [255, 182, 193, 1];
1099
+ WebColors.Pink = [255, 192, 203, 1];
1100
+ WebColors.DarkRed = [139, 0, 0, 1];
1101
+ WebColors.Red = [255, 0, 0, 1];
1102
+ WebColors.Firebrick = [178, 34, 34, 1];
1103
+ WebColors.Crimson = [220, 20, 60, 1];
1104
+ WebColors.IndianRed = [205, 92, 92, 1];
1105
+ WebColors.LightCoral = [240, 128, 128, 1];
1106
+ WebColors.Salmon = [250, 128, 114, 1];
1107
+ WebColors.DarkSalmon = [233, 150, 122, 1];
1108
+ WebColors.LightSalmon = [255, 160, 122, 1];
1109
+ WebColors.OrangeRed = [255, 69, 0, 1];
1110
+ WebColors.Tomato = [255, 99, 71, 1];
1111
+ WebColors.DarkOrange = [255, 140, 0, 1];
1112
+ WebColors.Coral = [255, 127, 80, 1];
1113
+ WebColors.Orange = [255, 165, 0, 1];
1114
+ WebColors.DarkKhaki = [189, 183, 107, 1];
1115
+ WebColors.Gold = [255, 215, 0, 1];
1116
+ WebColors.Khaki = [240, 230, 140, 1];
1117
+ WebColors.PeachPuff = [255, 218, 185, 1];
1118
+ WebColors.Yellow = [255, 255, 0, 1];
1119
+ WebColors.PaleGoldenrod = [238, 232, 170, 1];
1120
+ WebColors.Moccasin = [255, 228, 181, 1];
1121
+ WebColors.PapayaWhip = [255, 239, 213, 1];
1122
+ WebColors.LightGoldenrodYellow = [250, 250, 210, 1];
1123
+ WebColors.LemonChiffon = [255, 250, 205, 1];
1124
+ WebColors.LightYellow = [255, 255, 224, 1];
1125
+ WebColors.Maroon = [128, 0, 0, 1];
1126
+ WebColors.Brown = [165, 42, 42, 1];
1127
+ WebColors.SaddleBrown = [139, 69, 19, 1];
1128
+ WebColors.Sienna = [160, 82, 45, 1];
1129
+ WebColors.Chocolate = [210, 105, 30, 1];
1130
+ WebColors.DarkGoldenrod = [184, 134, 11, 1];
1131
+ WebColors.Peru = [205, 133, 63, 1];
1132
+ WebColors.RosyBrown = [188, 143, 143, 1];
1133
+ WebColors.Goldenrod = [218, 165, 32, 1];
1134
+ WebColors.SandyBrown = [244, 164, 96, 1];
1135
+ WebColors.Tan = [210, 180, 140, 1];
1136
+ WebColors.Burlywood = [222, 184, 135, 1];
1137
+ WebColors.Wheat = [245, 222, 179, 1];
1138
+ WebColors.NavajoWhite = [255, 222, 173, 1];
1139
+ WebColors.Bisque = [255, 228, 196, 1];
1140
+ WebColors.BlanchedAlmond = [255, 235, 205, 1];
1141
+ WebColors.Cornsilk = [255, 248, 220, 1];
1142
+ WebColors.DarkGreen = [0, 100, 0, 1];
1143
+ WebColors.Green = [0, 128, 0, 1];
1144
+ WebColors.DarkOliveGreen = [85, 107, 47, 1];
1145
+ WebColors.ForestGreen = [34, 139, 34, 1];
1146
+ WebColors.SeaGreen = [46, 139, 87, 1];
1147
+ WebColors.Olive = [128, 128, 0, 1];
1148
+ WebColors.OliveDrab = [107, 142, 35, 1];
1149
+ WebColors.MediumSeaGreen = [60, 179, 113, 1];
1150
+ WebColors.LimeGreen = [50, 205, 50, 1];
1151
+ WebColors.Lime = [0, 255, 0, 1];
1152
+ WebColors.SpringGreen = [0, 255, 127, 1];
1153
+ WebColors.MediumSpringGreen = [0, 250, 154, 1];
1154
+ WebColors.DarkSeaGreen = [143, 188, 143, 1];
1155
+ WebColors.MediumAquamarine = [102, 205, 170, 1];
1156
+ WebColors.YellowGreen = [154, 205, 50, 1];
1157
+ WebColors.LawnGreen = [124, 252, 0, 1];
1158
+ WebColors.Chartreuse = [127, 255, 0, 1];
1159
+ WebColors.LightGreen = [144, 238, 144, 1];
1160
+ WebColors.GreenYellow = [173, 255, 47, 1];
1161
+ WebColors.PaleGreen = [152, 251, 152, 1];
1162
+ WebColors.Teal = [0, 128, 128, 1];
1163
+ WebColors.DarkCyan = [0, 139, 139, 1];
1164
+ WebColors.LightSeaGreen = [32, 178, 170, 1];
1165
+ WebColors.CadetBlue = [95, 158, 160, 1];
1166
+ WebColors.DarkTurquoise = [0, 206, 209, 1];
1167
+ WebColors.MediumTurquoise = [72, 209, 204, 1];
1168
+ WebColors.Turquoise = [64, 224, 208, 1];
1169
+ WebColors.Aqua = [0, 255, 255, 1];
1170
+ WebColors.Cyan = [0, 255, 255, 1];
1171
+ WebColors.Aquamarine = [127, 255, 212, 1];
1172
+ WebColors.PaleTurquoise = [175, 238, 238, 1];
1173
+ WebColors.LightCyan = [224, 255, 255, 1];
1174
+ WebColors.Navy = [0, 0, 128, 1];
1175
+ WebColors.DarkBlue = [0, 0, 139, 1];
1176
+ WebColors.MediumBlue = [0, 0, 205, 1];
1177
+ WebColors.Blue = [0, 0, 255, 1];
1178
+ WebColors.MidnightBlue = [25, 25, 112, 1];
1179
+ WebColors.RoyalBlue = [65, 105, 225, 1];
1180
+ WebColors.SteelBlue = [70, 130, 180, 1];
1181
+ WebColors.DodgerBlue = [30, 144, 255, 1];
1182
+ WebColors.DeepSkyBlue = [0, 191, 255, 1];
1183
+ WebColors.CornflowerBlue = [100, 149, 237, 1];
1184
+ WebColors.SkyBlue = [135, 206, 235, 1];
1185
+ WebColors.LightSkyBlue = [135, 206, 250, 1];
1186
+ WebColors.LightSteelBlue = [176, 196, 222, 1];
1187
+ WebColors.LightBlue = [173, 216, 230, 1];
1188
+ WebColors.PowderBlue = [176, 224, 230, 1];
1189
+ WebColors.Indigo = [75, 0, 130, 1];
1190
+ WebColors.Purple = [128, 0, 128, 1];
1191
+ WebColors.DarkMagenta = [139, 0, 139, 1];
1192
+ WebColors.DarkViolet = [148, 0, 211, 1];
1193
+ WebColors.DarkSlateBlue = [72, 61, 139, 1];
1194
+ WebColors.BlueViolet = [138, 43, 226, 1];
1195
+ WebColors.DarkOrchid = [153, 50, 204, 1];
1196
+ WebColors.Fuchsia = [255, 0, 255, 1];
1197
+ WebColors.Magenta = [255, 0, 255, 1];
1198
+ WebColors.SlateBlue = [106, 90, 205, 1];
1199
+ WebColors.MediumSlateBlue = [123, 104, 238, 1];
1200
+ WebColors.MediumOrchid = [186, 85, 211, 1];
1201
+ WebColors.MediumPurple = [147, 112, 219, 1];
1202
+ WebColors.Orchid = [218, 112, 214, 1];
1203
+ WebColors.Violet = [238, 130, 238, 1];
1204
+ WebColors.Plum = [221, 160, 221, 1];
1205
+ WebColors.Thistle = [216, 191, 216, 1];
1206
+ WebColors.Lavender = [230, 230, 250, 1];
1207
+ WebColors.MistyRose = [255, 228, 225, 1];
1208
+ WebColors.AntiqueWhite = [250, 235, 215, 1];
1209
+ WebColors.Linen = [250, 240, 230, 1];
1210
+ WebColors.Beige = [245, 245, 220, 1];
1211
+ WebColors.WhiteSmoke = [245, 245, 245, 1];
1212
+ WebColors.LavenderBlush = [255, 240, 245, 1];
1213
+ WebColors.OldLace = [253, 245, 230, 1];
1214
+ WebColors.AliceBlue = [240, 248, 255, 1];
1215
+ WebColors.Seashell = [255, 245, 238, 1];
1216
+ WebColors.GhostWhite = [248, 248, 255, 1];
1217
+ WebColors.Honeydew = [240, 255, 240, 1];
1218
+ WebColors.FloralWhite = [255, 250, 240, 1];
1219
+ WebColors.Azure = [240, 255, 255, 1];
1220
+ WebColors.MintCream = [245, 255, 250, 1];
1221
+ WebColors.Snow = [255, 250, 250, 1];
1222
+ WebColors.Ivory = [255, 255, 240, 1];
1223
+ WebColors.White = [255, 255, 255, 1];
1224
+ WebColors.Black = [0, 0, 0, 1];
1225
+ WebColors.DarkSlateGray = [47, 79, 79, 1];
1226
+ WebColors.DimGray = [105, 105, 105, 1];
1227
+ WebColors.SlateGray = [112, 128, 144, 1];
1228
+ WebColors.Gray = [128, 128, 128, 1];
1229
+ WebColors.LightSlateGray = [119, 136, 153, 1];
1230
+ WebColors.DarkGray = [169, 169, 169, 1];
1231
+ WebColors.Silver = [192, 192, 192, 1];
1232
+ WebColors.LightGray = [211, 211, 211, 1];
1233
+ WebColors.Gainsboro = [220, 220, 220, 1];
1234
+ WebColors.RebeccaPurple = [102, 51, 153, 1];
1235
+
1236
+ class Constants {
1237
+ }
1238
+ /** Size of the font showing frames per second */
1239
+ Constants.FPS_DISPLAY_TEXT_FONT_SIZE = 12;
1240
+ /** Color of the font showing frames per second */
1241
+ Constants.FPS_DISPLAY_TEXT_COLOR = [0, 0, 0, 0.5];
1242
+ /** Frequency, in milliseconds, at which to update frames per second metric shown on the screen */
1243
+ Constants.FPS_DISPLAY_UPDATE_INTERVAL = 1e3;
1244
+ /** Maximum number of activity metrics to log. */
1245
+ Constants.MAXIMUM_RECORDED_ACTIVITY_METRICS = 32;
1246
+ /** The frames per second will be logged in game metrics if the FPS is lower than this value */
1247
+ Constants.FPS_METRIC_REPORT_THRESHOLD = 59;
1248
+ /** Scene color, if none is specified. */
1249
+ Constants.DEFAULT_SCENE_BACKGROUND_COLOR = WebColors.White;
1250
+ /** Shape fill color, if none is specified. */
1251
+ Constants.DEFAULT_SHAPE_FILL_COLOR = WebColors.Red;
1252
+ /** Color of paths in a shape, if none is specified. */
1253
+ Constants.DEFAULT_PATH_STROKE_COLOR = WebColors.Red;
1254
+ /** Line width of paths in a shape, if none is specified. */
1255
+ Constants.DEFAULT_PATH_LINE_WIDTH = 2;
1256
+ /** Color of text in Label and TextLine, if none is specified. */
1257
+ Constants.DEFAULT_FONT_COLOR = WebColors.Black;
1258
+ /** Font size in Label and TextLine, if none is specified. */
1259
+ Constants.DEFAULT_FONT_SIZE = 16;
1260
+ Constants.LIMITED_FPS_RATE = 5;
1261
+ Constants.FREE_ENTITIES_SCENE_NAME = "__freeEntitiesScene";
1262
+ Constants.OUTGOING_SCENE_NAME = "__outgoingScene";
1263
+ Constants.OUTGOING_SCENE_SPRITE_NAME = "__outgoingSceneSprite";
1264
+ Constants.OUTGOING_SCENE_IMAGE_NAME = "__outgoingSceneSnapshot";
1265
+ Constants.SESSION_INITIALIZATION_POLLING_INTERVAL_MS = 50;
1266
+
1267
+ class ColorfulMutablePath extends MutablePath {
1268
+ constructor() {
1269
+ super(...arguments);
1270
+ /** Stroke color to be applied to subsequent lines. */
1271
+ this.strokeColor = Constants.DEFAULT_PATH_STROKE_COLOR;
1272
+ /** Line width to be applied to subsequent lines. */
1273
+ this.lineWidth = Constants.DEFAULT_PATH_LINE_WIDTH;
1274
+ /** Colors and widths of lines in the path. */
1275
+ this.linePresentations = [];
1276
+ }
1277
+ /**
1278
+ * Adds a straight line to the current subpath
1279
+ *
1280
+ * @remarks The line is added from the last point in the current subpath to
1281
+ * the given point, with the current stroke color and line width.
1282
+ *
1283
+ * @param point - location where the line will end
1284
+ */
1285
+ addLine(point) {
1286
+ if (this.isNewLinePresentation()) {
1287
+ this.linePresentations.push({
1288
+ strokeColor: this.strokeColor,
1289
+ lineWidth: this.lineWidth,
1290
+ subpathIndex: this._subpaths.length,
1291
+ pointIndex: this.currentPath.length - 1
1292
+ });
1293
+ }
1294
+ this.currentPath.push(point);
1295
+ }
633
1296
  /**
634
- * Frees up resources that were allocated by CanvasKit.
1297
+ * Checks if the current line presentation (stroke color and line width) is
1298
+ * different from the last line presentation.
635
1299
  *
636
- * @remarks This frees objects created in WebAssembly by
637
- * canvaskit-wasm. JavaScript garbage collection won't
638
- * free these wasm objects.
1300
+ * @returns true if the current line presentation is different from the last
639
1301
  */
640
- static Dispose(objects) {
641
- objects.filter((o) => !(o == null ? void 0 : o.isDeleted())).forEach((o) => o == null ? void 0 : o.delete());
1302
+ isNewLinePresentation() {
1303
+ if (this.linePresentations.length === 0) {
1304
+ return true;
1305
+ }
1306
+ const currentLinePresentation = this.linePresentations[this.linePresentations.length - 1];
1307
+ return currentLinePresentation.strokeColor !== this.strokeColor || currentLinePresentation.lineWidth !== this.lineWidth;
642
1308
  }
643
- static makePaint(canvasKit, color, style, isAntialiased) {
644
- const paint = new canvasKit.Paint();
645
- paint.setColor(canvasKit.Color(color[0], color[1], color[2], color[3]));
646
- paint.setStyle(style);
647
- paint.setAntiAlias(isAntialiased);
648
- return paint;
1309
+ /**
1310
+ * Removes all subpaths from the shape and resets the stroke color and line
1311
+ * width to their default values.
1312
+ */
1313
+ clear() {
1314
+ super.clear();
1315
+ this.linePresentations = [];
1316
+ this.strokeColor = Constants.DEFAULT_PATH_STROKE_COLOR;
1317
+ this.lineWidth = Constants.DEFAULT_PATH_LINE_WIDTH;
1318
+ }
1319
+ /**
1320
+ * Makes a deep copy.
1321
+ *
1322
+ * @returns a deep copy
1323
+ */
1324
+ duplicate() {
1325
+ const newPath = super.duplicate();
1326
+ newPath.strokeColor = JSON.parse(JSON.stringify(this.strokeColor));
1327
+ newPath.lineWidth = this.lineWidth;
1328
+ newPath.linePresentations = JSON.parse(
1329
+ JSON.stringify(this.linePresentations)
1330
+ );
1331
+ return newPath;
649
1332
  }
650
1333
  }
651
1334
 
652
- var __defProp$i = Object.defineProperty;
653
- var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
654
- var __publicField$i = (obj, key, value) => {
655
- __defNormalProp$i(obj, typeof key !== "symbol" ? key + "" : key, value);
656
- return value;
657
- };
658
1335
  class GlobalVariables {
659
1336
  constructor() {
660
- __publicField$i(this, "now", NaN);
661
- __publicField$i(this, "deltaTime", NaN);
662
- __publicField$i(this, "canvasScale", NaN);
1337
+ this.now = NaN;
1338
+ this.deltaTime = NaN;
1339
+ this.canvasScale = NaN;
663
1340
  // _rootScale is the scaling factor to be applied to scenes to scale up or
664
1341
  // down to fit the device's window while preserving the aspect ratio the
665
1342
  // game was designed for
666
- __publicField$i(this, "rootScale", 1);
667
- __publicField$i(this, "canvasCssWidth", NaN);
668
- __publicField$i(this, "canvasCssHeight", NaN);
1343
+ this.rootScale = 1;
1344
+ this.canvasCssWidth = NaN;
1345
+ this.canvasCssHeight = NaN;
669
1346
  }
670
1347
  }
671
1348
 
@@ -687,20 +1364,8 @@ var ConstraintType = /* @__PURE__ */ ((ConstraintType2) => {
687
1364
  return ConstraintType2;
688
1365
  })(ConstraintType || {});
689
1366
 
690
- var __defProp$h = Object.defineProperty;
691
- var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
692
- var __publicField$h = (obj, key, value) => {
693
- __defNormalProp$h(obj, typeof key !== "symbol" ? key + "" : key, value);
694
- return value;
695
- };
696
1367
  class LayoutConstraint {
697
1368
  constructor(type, alterEntity) {
698
- // the constraint, e.g., bottomToTopOf
699
- __publicField$h(this, "type");
700
- // alter is the other entity that the focal entity is constrained to.
701
- // in the example above, A is the focal entity, B is the alter
702
- // thus the alter entity property is B
703
- __publicField$h(this, "alterEntity");
704
1369
  // the below 3 properties are calculated from the constraint type
705
1370
  // (we set them to false by default to avoid undefined warnings, but
706
1371
  // they will be definitely assigned in the constructor logic)
@@ -708,37 +1373,37 @@ class LayoutConstraint {
708
1373
  //
709
1374
  // does the constraint affect the Y or X axis? If not, then it's
710
1375
  // a horizontal constraint
711
- __publicField$h(this, "verticalConstraint", false);
1376
+ this.verticalConstraint = false;
712
1377
  // does the constraint apply to the focal entity's "minimum" position
713
1378
  // along its axis? That is, does the constraint reference the focal
714
1379
  // entity's "top" or "start"? Top and start are considered minimums because
715
1380
  // our origin (0, 0) in the upper left.
716
1381
  // If not, then the constraint applies to the focal entity's "maximum"
717
1382
  // position, e.g., its "bottom" or "end".
718
- __publicField$h(this, "focalEntityMinimum", false);
1383
+ this.focalEntityMinimum = false;
719
1384
  // does the constraint apply to the alter entity's "minimum" position
720
1385
  // along its axis?
721
- __publicField$h(this, "alterEntityMinimum", false);
722
- __publicField$h(this, "verticalTypes", [
1386
+ this.alterEntityMinimum = false;
1387
+ this.verticalTypes = [
723
1388
  ConstraintType.topToTopOf,
724
1389
  ConstraintType.topToBottomOf,
725
1390
  ConstraintType.bottomToTopOf,
726
1391
  ConstraintType.bottomToBottomOf
727
- ]);
1392
+ ];
728
1393
  // e.g., entity A
729
- __publicField$h(this, "focalEntityMinimumTypes", [
1394
+ this.focalEntityMinimumTypes = [
730
1395
  ConstraintType.topToTopOf,
731
1396
  ConstraintType.topToBottomOf,
732
1397
  ConstraintType.startToStartOf,
733
1398
  ConstraintType.startToEndOf
734
- ]);
1399
+ ];
735
1400
  // e.g., entity B
736
- __publicField$h(this, "alterEntityMinimumTypes", [
1401
+ this.alterEntityMinimumTypes = [
737
1402
  ConstraintType.topToTopOf,
738
1403
  ConstraintType.bottomToTopOf,
739
1404
  ConstraintType.startToStartOf,
740
1405
  ConstraintType.endToStartOf
741
- ]);
1406
+ ];
742
1407
  this.type = type;
743
1408
  this.alterEntity = alterEntity;
744
1409
  if (this.verticalTypes.includes(type)) {
@@ -769,26 +1434,15 @@ class LayoutConstraint {
769
1434
  }
770
1435
  }
771
1436
 
772
- var EntityType = /* @__PURE__ */ ((EntityType2) => {
773
- EntityType2["Entity"] = "Entity";
774
- EntityType2["Scene"] = "Scene";
775
- EntityType2["Sprite"] = "Sprite";
776
- EntityType2["Label"] = "Label";
777
- EntityType2["TextLine"] = "TextLine";
778
- EntityType2["Shape"] = "Shape";
779
- EntityType2["Composite"] = "Composite";
780
- return EntityType2;
781
- })(EntityType || {});
782
-
783
1437
  class Uuid {
784
1438
  static generate() {
785
1439
  try {
786
1440
  return crypto.randomUUID();
787
- } catch (e) {
1441
+ } catch {
788
1442
  let randomValue;
789
1443
  try {
790
1444
  randomValue = () => crypto.getRandomValues(new Uint8Array(1))[0];
791
- } catch (e2) {
1445
+ } catch {
792
1446
  randomValue = () => Math.floor(Math.random() * 256);
793
1447
  }
794
1448
  return (1e7.toString() + -1e3 + -4e3 + -8e3 + -1e11).replace(
@@ -822,12 +1476,6 @@ const EventType = {
822
1476
  FrameDidSimulatePhysics: "FrameDidSimulatePhysics"
823
1477
  };
824
1478
 
825
- var __defProp$g = Object.defineProperty;
826
- var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
827
- var __publicField$g = (obj, key, value) => {
828
- __defNormalProp$g(obj, typeof key !== "symbol" ? key + "" : key, value);
829
- return value;
830
- };
831
1479
  function handleDrawableOptions(drawable, options) {
832
1480
  if (options.anchorPoint) {
833
1481
  drawable.anchorPoint = options.anchorPoint;
@@ -863,63 +1511,59 @@ function handleInterfaceOptions(entity, options) {
863
1511
  }
864
1512
  class Entity {
865
1513
  constructor(options = {}) {
866
- __publicField$g(this, "type", EntityType.Entity);
867
- __publicField$g(this, "isDrawable", false);
868
- __publicField$g(this, "isShape", false);
869
- __publicField$g(this, "isText", false);
870
- // Entity Options
871
- __publicField$g(this, "name");
872
- __publicField$g(this, "position", { x: 0, y: 0 });
1514
+ this.type = EntityType.Entity;
1515
+ this.isDrawable = false;
1516
+ this.isShape = false;
1517
+ this.isText = false;
1518
+ this.position = { x: 0, y: 0 };
873
1519
  // position of the entity in the parent coordinate system
874
- __publicField$g(this, "scale", 1);
875
- __publicField$g(this, "alpha", 1);
876
- __publicField$g(this, "isUserInteractionEnabled", false);
877
- __publicField$g(this, "draggable", false);
878
- __publicField$g(this, "hidden", false);
879
- __publicField$g(this, "layout", {});
880
- __publicField$g(this, "_game");
881
- __publicField$g(this, "parent");
882
- __publicField$g(this, "children", new Array());
883
- __publicField$g(this, "absolutePosition", { x: 0, y: 0 });
1520
+ this.scale = 1;
1521
+ this.alpha = 1;
1522
+ this.zRotation = 0;
1523
+ this.isUserInteractionEnabled = false;
1524
+ this.draggable = false;
1525
+ this.hidden = false;
1526
+ this.layout = {};
1527
+ this.children = new Array();
1528
+ this.absolutePosition = { x: 0, y: 0 };
884
1529
  // position within the root coordinate system
885
- __publicField$g(this, "size", { width: 0, height: 0 });
886
- __publicField$g(this, "absoluteScale", 1);
887
- __publicField$g(this, "absoluteAlpha", 1);
888
- __publicField$g(this, "absoluteAlphaChange", 0);
889
- __publicField$g(this, "actions", new Array());
890
- __publicField$g(this, "queuedAction");
891
- __publicField$g(this, "originalActions", new Array());
892
- __publicField$g(this, "eventListeners", new Array());
893
- __publicField$g(this, "uuid", Uuid.generate());
894
- __publicField$g(this, "needsInitialization", true);
1530
+ this.size = { width: 0, height: 0 };
1531
+ this.absoluteScale = 1;
1532
+ this.absoluteAlpha = 1;
1533
+ this.absoluteAlphaChange = 0;
1534
+ this.actions = new Array();
1535
+ this.originalActions = new Array();
1536
+ this.eventListeners = new Array();
1537
+ this.uuid = Uuid.generate();
1538
+ this.needsInitialization = true;
895
1539
  // library users might put anything in userData property
896
1540
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
897
- __publicField$g(this, "userData", {});
898
- __publicField$g(this, "loopMessages", /* @__PURE__ */ new Set());
1541
+ this.userData = {};
1542
+ this.loopMessages = /* @__PURE__ */ new Set();
899
1543
  /** Is the entity in a pressed state? E.g., did the user put the pointer
900
1544
  * down on the entity and not yet release it? */
901
- __publicField$g(this, "pressed", false);
902
- __publicField$g(this, "withinHitArea", false);
1545
+ this.pressed = false;
1546
+ this.withinHitArea = false;
903
1547
  /** Is the entity in a pressed state AND is the pointer within the entity's
904
1548
  * hit area? For example, a user may put the pointer down on the entity, but
905
1549
  * then move the pointer, while still down, beyond the entity's hit area. In
906
1550
  * this case, pressed = true, but pressedAndWithinHitArea = false. */
907
- __publicField$g(this, "pressedAndWithinHitArea", false);
1551
+ this.pressedAndWithinHitArea = false;
908
1552
  /** When the entity initially enters the pressed state, what is the pointer
909
1553
  * offset? (offset from the canvas's origin to the pointer position). We
910
1554
  * save this because it will be needed if this press then led to a drag. */
911
- __publicField$g(this, "pressedInitialPointerOffset", { x: NaN, y: NaN });
1555
+ this.pressedInitialPointerOffset = { x: NaN, y: NaN };
912
1556
  /** What was the previous pointer offset when the entity was in a dragging
913
1557
  * state? */
914
- __publicField$g(this, "draggingLastPointerOffset", { x: NaN, y: NaN });
1558
+ this.draggingLastPointerOffset = { x: NaN, y: NaN };
915
1559
  /** Is the entity in a dragging state? */
916
- __publicField$g(this, "dragging", false);
1560
+ this.dragging = false;
917
1561
  /**
918
1562
  * Overrides toString() and returns a human-friendly description of the entity.
919
1563
  *
920
1564
  * @remarks Inspiration from https://stackoverflow.com/a/35361695
921
1565
  */
922
- __publicField$g(this, "toString", () => {
1566
+ this.toString = () => {
923
1567
  let type = this.type.toString();
924
1568
  if (this.type == EntityType.Composite) {
925
1569
  type = this.compositeType;
@@ -929,7 +1573,7 @@ class Entity {
929
1573
  } else {
930
1574
  return `${type} (${this.uuid})`;
931
1575
  }
932
- });
1576
+ };
933
1577
  if (options.name === void 0) {
934
1578
  this.name = this.uuid;
935
1579
  } else {
@@ -944,6 +1588,9 @@ class Entity {
944
1588
  if (options.alpha !== void 0) {
945
1589
  this.alpha = options.alpha;
946
1590
  }
1591
+ if (options.zRotation !== void 0) {
1592
+ this.zRotation = options.zRotation;
1593
+ }
947
1594
  if (options.isUserInteractionEnabled !== void 0) {
948
1595
  this.isUserInteractionEnabled = options.isUserInteractionEnabled;
949
1596
  }
@@ -984,7 +1631,6 @@ class Entity {
984
1631
  * @returns true if entity has been added
985
1632
  */
986
1633
  isPartOfGame() {
987
- var _a;
988
1634
  if (this.type === EntityType.Scene && this._game === void 0) {
989
1635
  return false;
990
1636
  }
@@ -1000,7 +1646,7 @@ class Entity {
1000
1646
  return findParentScene(entity.parent);
1001
1647
  }
1002
1648
  };
1003
- return ((_a = findParentScene(this)) == null ? void 0 : _a._game) !== void 0;
1649
+ return findParentScene(this)?._game !== void 0;
1004
1650
  }
1005
1651
  /**
1006
1652
  * Adds a child to this parent entity. Throws exception if the child's name
@@ -1033,10 +1679,7 @@ class Entity {
1033
1679
  } else {
1034
1680
  const descendants = this.descendants;
1035
1681
  if (descendants.includes(child)) {
1036
- otherParents = descendants.filter((d) => d.children.includes(child)).map((d) => {
1037
- var _a;
1038
- return (_a = d.parent) != null ? _a : void 0;
1039
- });
1682
+ otherParents = descendants.filter((d) => d.children.includes(child)).map((d) => d.parent ?? void 0);
1040
1683
  }
1041
1684
  }
1042
1685
  if (otherParents.length === 0) {
@@ -1051,7 +1694,7 @@ class Entity {
1051
1694
  );
1052
1695
  }
1053
1696
  throw new Error(
1054
- `Cannot add child entity ${child.toString()} to parent entity ${this.toString()}. This child already exists on other parent entity: ${firstOtherParent == null ? void 0 : firstOtherParent.toString()}}. Remove the child from the other parent first.`
1697
+ `Cannot add child entity ${child.toString()} to parent entity ${this.toString()}. This child already exists on other parent entity: ${firstOtherParent?.toString()}}. Remove the child from the other parent first.`
1055
1698
  );
1056
1699
  }
1057
1700
  /**
@@ -1358,7 +2001,7 @@ class Entity {
1358
2001
  entityUuid: this.uuid,
1359
2002
  callback
1360
2003
  };
1361
- if (callbackOptions == null ? void 0 : callbackOptions.replaceExisting) {
2004
+ if (callbackOptions?.replaceExisting) {
1362
2005
  this.eventListeners = this.eventListeners.filter(
1363
2006
  (listener) => !(listener.entityUuid === eventListener.entityUuid && listener.type === eventListener.type)
1364
2007
  );
@@ -1456,7 +2099,6 @@ class Entity {
1456
2099
  return alpha * inheritedAlpha;
1457
2100
  }
1458
2101
  update() {
1459
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1460
2102
  if (this.needsInitialization) {
1461
2103
  this.initialize();
1462
2104
  this.needsInitialization = false;
@@ -1469,18 +2111,18 @@ class Entity {
1469
2111
  this.absoluteScale = this.scale;
1470
2112
  } else {
1471
2113
  this.absoluteScale = this.parent.absoluteScale * this.scale;
1472
- if (((_a = this.layout) == null ? void 0 : _a.constraints) === void 0) {
2114
+ if (this.layout?.constraints === void 0) {
1473
2115
  this.absolutePosition.x = this.parent.absolutePosition.x + this.position.x * this.parent.absoluteScale;
1474
2116
  this.absolutePosition.y = this.parent.absolutePosition.y + this.position.y * this.parent.absoluteScale;
1475
2117
  } else {
1476
- const horizontalBias = (_d = (_c = (_b = this.layout) == null ? void 0 : _b.constraints) == null ? void 0 : _c.horizontalBias) != null ? _d : 0.5;
1477
- const verticalBias = (_g = (_f = (_e = this.layout) == null ? void 0 : _e.constraints) == null ? void 0 : _f.verticalBias) != null ? _g : 0.5;
1478
- const marginTop = (_i = (_h = this.layout) == null ? void 0 : _h.marginTop) != null ? _i : 0;
1479
- const marginBottom = (_k = (_j = this.layout) == null ? void 0 : _j.marginBottom) != null ? _k : 0;
1480
- const marginStart = (_m = (_l = this.layout) == null ? void 0 : _l.marginStart) != null ? _m : 0;
1481
- const marginEnd = (_o = (_n = this.layout) == null ? void 0 : _n.marginEnd) != null ? _o : 0;
2118
+ const horizontalBias = this.layout?.constraints?.horizontalBias ?? 0.5;
2119
+ const verticalBias = this.layout?.constraints?.verticalBias ?? 0.5;
2120
+ const marginTop = this.layout?.marginTop ?? 0;
2121
+ const marginBottom = this.layout?.marginBottom ?? 0;
2122
+ const marginStart = this.layout?.marginStart ?? 0;
2123
+ const marginEnd = this.layout?.marginEnd ?? 0;
1482
2124
  const layoutConstraints = this.parseLayoutConstraints(
1483
- (_p = this.layout) == null ? void 0 : _p.constraints,
2125
+ this.layout?.constraints,
1484
2126
  //this.parentScene.game.entities
1485
2127
  this.parentSceneAsEntity.descendants
1486
2128
  );
@@ -1578,10 +2220,9 @@ class Entity {
1578
2220
  }
1579
2221
  const adjList = /* @__PURE__ */ new Map();
1580
2222
  this.children.forEach((child) => {
1581
- var _a2;
1582
2223
  adjList.set(
1583
2224
  child.uuid,
1584
- getSiblingConstraintUuids(this, (_a2 = child.layout) == null ? void 0 : _a2.constraints)
2225
+ getSiblingConstraintUuids(this, child.layout?.constraints)
1585
2226
  );
1586
2227
  });
1587
2228
  const sortedUuids = this.findTopologicalSort(adjList);
@@ -1717,7 +2358,6 @@ class Entity {
1717
2358
  * @param adjList Adjacency List that represent a graph with vertices and edges
1718
2359
  */
1719
2360
  findTopologicalSort(adjList) {
1720
- var _a;
1721
2361
  const tSort = [];
1722
2362
  const inDegree = /* @__PURE__ */ new Map();
1723
2363
  adjList.forEach((edges, vertex) => {
@@ -1745,7 +2385,7 @@ class Entity {
1745
2385
  }
1746
2386
  tSort.push(current);
1747
2387
  if (adjList.has(current)) {
1748
- (_a = adjList.get(current)) == null ? void 0 : _a.forEach((edge) => {
2388
+ adjList.get(current)?.forEach((edge) => {
1749
2389
  if (inDegree.has(edge) && inDegree.get(edge) > 0) {
1750
2390
  const newDegree = inDegree.get(edge) - 1;
1751
2391
  inDegree.set(edge, newDegree);
@@ -1760,12 +2400,6 @@ class Entity {
1760
2400
  }
1761
2401
  }
1762
2402
 
1763
- var __defProp$f = Object.defineProperty;
1764
- var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1765
- var __publicField$f = (obj, key, value) => {
1766
- __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
1767
- return value;
1768
- };
1769
2403
  class Composite extends Entity {
1770
2404
  /**
1771
2405
  * Base Drawable object for creating custom entities ("composites") composed of primitive entities.
@@ -1774,12 +2408,12 @@ class Composite extends Entity {
1774
2408
  */
1775
2409
  constructor(options = {}) {
1776
2410
  super(options);
1777
- __publicField$f(this, "type", EntityType.Composite);
1778
- __publicField$f(this, "compositeType", "<compositeType>");
1779
- __publicField$f(this, "isDrawable", true);
2411
+ this.type = EntityType.Composite;
2412
+ this.compositeType = "<compositeType>";
2413
+ this.isDrawable = true;
1780
2414
  // Drawable options
1781
- __publicField$f(this, "anchorPoint", { x: 0.5, y: 0.5 });
1782
- __publicField$f(this, "zPosition", 0);
2415
+ this.anchorPoint = { x: 0.5, y: 0.5 };
2416
+ this.zPosition = 0;
1783
2417
  handleInterfaceOptions(this, options);
1784
2418
  }
1785
2419
  // eslint-disable-next-line @typescript-eslint/no-empty-function
@@ -1796,194 +2430,6 @@ class Composite extends Entity {
1796
2430
  }
1797
2431
  }
1798
2432
 
1799
- var __defProp$e = Object.defineProperty;
1800
- var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1801
- var __publicField$e = (obj, key, value) => {
1802
- __defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
1803
- return value;
1804
- };
1805
- class WebColors {
1806
- }
1807
- __publicField$e(WebColors, "Transparent", [0, 0, 0, 0]);
1808
- __publicField$e(WebColors, "MediumVioletRed", [199, 21, 133, 1]);
1809
- __publicField$e(WebColors, "DeepPink", [255, 20, 147, 1]);
1810
- __publicField$e(WebColors, "PaleVioletRed", [219, 112, 147, 1]);
1811
- __publicField$e(WebColors, "HotPink", [255, 105, 180, 1]);
1812
- __publicField$e(WebColors, "LightPink", [255, 182, 193, 1]);
1813
- __publicField$e(WebColors, "Pink", [255, 192, 203, 1]);
1814
- __publicField$e(WebColors, "DarkRed", [139, 0, 0, 1]);
1815
- __publicField$e(WebColors, "Red", [255, 0, 0, 1]);
1816
- __publicField$e(WebColors, "Firebrick", [178, 34, 34, 1]);
1817
- __publicField$e(WebColors, "Crimson", [220, 20, 60, 1]);
1818
- __publicField$e(WebColors, "IndianRed", [205, 92, 92, 1]);
1819
- __publicField$e(WebColors, "LightCoral", [240, 128, 128, 1]);
1820
- __publicField$e(WebColors, "Salmon", [250, 128, 114, 1]);
1821
- __publicField$e(WebColors, "DarkSalmon", [233, 150, 122, 1]);
1822
- __publicField$e(WebColors, "LightSalmon", [255, 160, 122, 1]);
1823
- __publicField$e(WebColors, "OrangeRed", [255, 69, 0, 1]);
1824
- __publicField$e(WebColors, "Tomato", [255, 99, 71, 1]);
1825
- __publicField$e(WebColors, "DarkOrange", [255, 140, 0, 1]);
1826
- __publicField$e(WebColors, "Coral", [255, 127, 80, 1]);
1827
- __publicField$e(WebColors, "Orange", [255, 165, 0, 1]);
1828
- __publicField$e(WebColors, "DarkKhaki", [189, 183, 107, 1]);
1829
- __publicField$e(WebColors, "Gold", [255, 215, 0, 1]);
1830
- __publicField$e(WebColors, "Khaki", [240, 230, 140, 1]);
1831
- __publicField$e(WebColors, "PeachPuff", [255, 218, 185, 1]);
1832
- __publicField$e(WebColors, "Yellow", [255, 255, 0, 1]);
1833
- __publicField$e(WebColors, "PaleGoldenrod", [238, 232, 170, 1]);
1834
- __publicField$e(WebColors, "Moccasin", [255, 228, 181, 1]);
1835
- __publicField$e(WebColors, "PapayaWhip", [255, 239, 213, 1]);
1836
- __publicField$e(WebColors, "LightGoldenrodYellow", [250, 250, 210, 1]);
1837
- __publicField$e(WebColors, "LemonChiffon", [255, 250, 205, 1]);
1838
- __publicField$e(WebColors, "LightYellow", [255, 255, 224, 1]);
1839
- __publicField$e(WebColors, "Maroon", [128, 0, 0, 1]);
1840
- __publicField$e(WebColors, "Brown", [165, 42, 42, 1]);
1841
- __publicField$e(WebColors, "SaddleBrown", [139, 69, 19, 1]);
1842
- __publicField$e(WebColors, "Sienna", [160, 82, 45, 1]);
1843
- __publicField$e(WebColors, "Chocolate", [210, 105, 30, 1]);
1844
- __publicField$e(WebColors, "DarkGoldenrod", [184, 134, 11, 1]);
1845
- __publicField$e(WebColors, "Peru", [205, 133, 63, 1]);
1846
- __publicField$e(WebColors, "RosyBrown", [188, 143, 143, 1]);
1847
- __publicField$e(WebColors, "Goldenrod", [218, 165, 32, 1]);
1848
- __publicField$e(WebColors, "SandyBrown", [244, 164, 96, 1]);
1849
- __publicField$e(WebColors, "Tan", [210, 180, 140, 1]);
1850
- __publicField$e(WebColors, "Burlywood", [222, 184, 135, 1]);
1851
- __publicField$e(WebColors, "Wheat", [245, 222, 179, 1]);
1852
- __publicField$e(WebColors, "NavajoWhite", [255, 222, 173, 1]);
1853
- __publicField$e(WebColors, "Bisque", [255, 228, 196, 1]);
1854
- __publicField$e(WebColors, "BlanchedAlmond", [255, 235, 205, 1]);
1855
- __publicField$e(WebColors, "Cornsilk", [255, 248, 220, 1]);
1856
- __publicField$e(WebColors, "DarkGreen", [0, 100, 0, 1]);
1857
- __publicField$e(WebColors, "Green", [0, 128, 0, 1]);
1858
- __publicField$e(WebColors, "DarkOliveGreen", [85, 107, 47, 1]);
1859
- __publicField$e(WebColors, "ForestGreen", [34, 139, 34, 1]);
1860
- __publicField$e(WebColors, "SeaGreen", [46, 139, 87, 1]);
1861
- __publicField$e(WebColors, "Olive", [128, 128, 0, 1]);
1862
- __publicField$e(WebColors, "OliveDrab", [107, 142, 35, 1]);
1863
- __publicField$e(WebColors, "MediumSeaGreen", [60, 179, 113, 1]);
1864
- __publicField$e(WebColors, "LimeGreen", [50, 205, 50, 1]);
1865
- __publicField$e(WebColors, "Lime", [0, 255, 0, 1]);
1866
- __publicField$e(WebColors, "SpringGreen", [0, 255, 127, 1]);
1867
- __publicField$e(WebColors, "MediumSpringGreen", [0, 250, 154, 1]);
1868
- __publicField$e(WebColors, "DarkSeaGreen", [143, 188, 143, 1]);
1869
- __publicField$e(WebColors, "MediumAquamarine", [102, 205, 170, 1]);
1870
- __publicField$e(WebColors, "YellowGreen", [154, 205, 50, 1]);
1871
- __publicField$e(WebColors, "LawnGreen", [124, 252, 0, 1]);
1872
- __publicField$e(WebColors, "Chartreuse", [127, 255, 0, 1]);
1873
- __publicField$e(WebColors, "LightGreen", [144, 238, 144, 1]);
1874
- __publicField$e(WebColors, "GreenYellow", [173, 255, 47, 1]);
1875
- __publicField$e(WebColors, "PaleGreen", [152, 251, 152, 1]);
1876
- __publicField$e(WebColors, "Teal", [0, 128, 128, 1]);
1877
- __publicField$e(WebColors, "DarkCyan", [0, 139, 139, 1]);
1878
- __publicField$e(WebColors, "LightSeaGreen", [32, 178, 170, 1]);
1879
- __publicField$e(WebColors, "CadetBlue", [95, 158, 160, 1]);
1880
- __publicField$e(WebColors, "DarkTurquoise", [0, 206, 209, 1]);
1881
- __publicField$e(WebColors, "MediumTurquoise", [72, 209, 204, 1]);
1882
- __publicField$e(WebColors, "Turquoise", [64, 224, 208, 1]);
1883
- __publicField$e(WebColors, "Aqua", [0, 255, 255, 1]);
1884
- __publicField$e(WebColors, "Cyan", [0, 255, 255, 1]);
1885
- __publicField$e(WebColors, "Aquamarine", [127, 255, 212, 1]);
1886
- __publicField$e(WebColors, "PaleTurquoise", [175, 238, 238, 1]);
1887
- __publicField$e(WebColors, "LightCyan", [224, 255, 255, 1]);
1888
- __publicField$e(WebColors, "Navy", [0, 0, 128, 1]);
1889
- __publicField$e(WebColors, "DarkBlue", [0, 0, 139, 1]);
1890
- __publicField$e(WebColors, "MediumBlue", [0, 0, 205, 1]);
1891
- __publicField$e(WebColors, "Blue", [0, 0, 255, 1]);
1892
- __publicField$e(WebColors, "MidnightBlue", [25, 25, 112, 1]);
1893
- __publicField$e(WebColors, "RoyalBlue", [65, 105, 225, 1]);
1894
- __publicField$e(WebColors, "SteelBlue", [70, 130, 180, 1]);
1895
- __publicField$e(WebColors, "DodgerBlue", [30, 144, 255, 1]);
1896
- __publicField$e(WebColors, "DeepSkyBlue", [0, 191, 255, 1]);
1897
- __publicField$e(WebColors, "CornflowerBlue", [100, 149, 237, 1]);
1898
- __publicField$e(WebColors, "SkyBlue", [135, 206, 235, 1]);
1899
- __publicField$e(WebColors, "LightSkyBlue", [135, 206, 250, 1]);
1900
- __publicField$e(WebColors, "LightSteelBlue", [176, 196, 222, 1]);
1901
- __publicField$e(WebColors, "LightBlue", [173, 216, 230, 1]);
1902
- __publicField$e(WebColors, "PowderBlue", [176, 224, 230, 1]);
1903
- __publicField$e(WebColors, "Indigo", [75, 0, 130, 1]);
1904
- __publicField$e(WebColors, "Purple", [128, 0, 128, 1]);
1905
- __publicField$e(WebColors, "DarkMagenta", [139, 0, 139, 1]);
1906
- __publicField$e(WebColors, "DarkViolet", [148, 0, 211, 1]);
1907
- __publicField$e(WebColors, "DarkSlateBlue", [72, 61, 139, 1]);
1908
- __publicField$e(WebColors, "BlueViolet", [138, 43, 226, 1]);
1909
- __publicField$e(WebColors, "DarkOrchid", [153, 50, 204, 1]);
1910
- __publicField$e(WebColors, "Fuchsia", [255, 0, 255, 1]);
1911
- __publicField$e(WebColors, "Magenta", [255, 0, 255, 1]);
1912
- __publicField$e(WebColors, "SlateBlue", [106, 90, 205, 1]);
1913
- __publicField$e(WebColors, "MediumSlateBlue", [123, 104, 238, 1]);
1914
- __publicField$e(WebColors, "MediumOrchid", [186, 85, 211, 1]);
1915
- __publicField$e(WebColors, "MediumPurple", [147, 112, 219, 1]);
1916
- __publicField$e(WebColors, "Orchid", [218, 112, 214, 1]);
1917
- __publicField$e(WebColors, "Violet", [238, 130, 238, 1]);
1918
- __publicField$e(WebColors, "Plum", [221, 160, 221, 1]);
1919
- __publicField$e(WebColors, "Thistle", [216, 191, 216, 1]);
1920
- __publicField$e(WebColors, "Lavender", [230, 230, 250, 1]);
1921
- __publicField$e(WebColors, "MistyRose", [255, 228, 225, 1]);
1922
- __publicField$e(WebColors, "AntiqueWhite", [250, 235, 215, 1]);
1923
- __publicField$e(WebColors, "Linen", [250, 240, 230, 1]);
1924
- __publicField$e(WebColors, "Beige", [245, 245, 220, 1]);
1925
- __publicField$e(WebColors, "WhiteSmoke", [245, 245, 245, 1]);
1926
- __publicField$e(WebColors, "LavenderBlush", [255, 240, 245, 1]);
1927
- __publicField$e(WebColors, "OldLace", [253, 245, 230, 1]);
1928
- __publicField$e(WebColors, "AliceBlue", [240, 248, 255, 1]);
1929
- __publicField$e(WebColors, "Seashell", [255, 245, 238, 1]);
1930
- __publicField$e(WebColors, "GhostWhite", [248, 248, 255, 1]);
1931
- __publicField$e(WebColors, "Honeydew", [240, 255, 240, 1]);
1932
- __publicField$e(WebColors, "FloralWhite", [255, 250, 240, 1]);
1933
- __publicField$e(WebColors, "Azure", [240, 255, 255, 1]);
1934
- __publicField$e(WebColors, "MintCream", [245, 255, 250, 1]);
1935
- __publicField$e(WebColors, "Snow", [255, 250, 250, 1]);
1936
- __publicField$e(WebColors, "Ivory", [255, 255, 240, 1]);
1937
- __publicField$e(WebColors, "White", [255, 255, 255, 1]);
1938
- __publicField$e(WebColors, "Black", [0, 0, 0, 1]);
1939
- __publicField$e(WebColors, "DarkSlateGray", [47, 79, 79, 1]);
1940
- __publicField$e(WebColors, "DimGray", [105, 105, 105, 1]);
1941
- __publicField$e(WebColors, "SlateGray", [112, 128, 144, 1]);
1942
- __publicField$e(WebColors, "Gray", [128, 128, 128, 1]);
1943
- __publicField$e(WebColors, "LightSlateGray", [119, 136, 153, 1]);
1944
- __publicField$e(WebColors, "DarkGray", [169, 169, 169, 1]);
1945
- __publicField$e(WebColors, "Silver", [192, 192, 192, 1]);
1946
- __publicField$e(WebColors, "LightGray", [211, 211, 211, 1]);
1947
- __publicField$e(WebColors, "Gainsboro", [220, 220, 220, 1]);
1948
- __publicField$e(WebColors, "RebeccaPurple", [102, 51, 153, 1]);
1949
-
1950
- var __defProp$d = Object.defineProperty;
1951
- var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1952
- var __publicField$d = (obj, key, value) => {
1953
- __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
1954
- return value;
1955
- };
1956
- class Constants {
1957
- }
1958
- /** Size of the font showing frames per second */
1959
- __publicField$d(Constants, "FPS_DISPLAY_TEXT_FONT_SIZE", 12);
1960
- /** Color of the font showing frames per second */
1961
- __publicField$d(Constants, "FPS_DISPLAY_TEXT_COLOR", [0, 0, 0, 0.5]);
1962
- /** Frequency, in milliseconds, at which to update frames per second metric shown on the screen */
1963
- __publicField$d(Constants, "FPS_DISPLAY_UPDATE_INTERVAL", 1e3);
1964
- /** Maximum number of activity metrics to log. */
1965
- __publicField$d(Constants, "MAXIMUM_RECORDED_ACTIVITY_METRICS", 32);
1966
- /** The frames per second will be logged in game metrics if the FPS is lower than this value */
1967
- __publicField$d(Constants, "FPS_METRIC_REPORT_THRESHOLD", 59);
1968
- /** Scene color, if none is specified. */
1969
- __publicField$d(Constants, "DEFAULT_SCENE_BACKGROUND_COLOR", WebColors.White);
1970
- /** Shape fill color, if none is specified. */
1971
- __publicField$d(Constants, "DEFAULT_SHAPE_FILL_COLOR", WebColors.Red);
1972
- /** Color of paths in a shape, if none is specified. */
1973
- __publicField$d(Constants, "DEFAULT_PATH_STROKE_COLOR", WebColors.Red);
1974
- /** Line width of paths in a shape, if none is specified. */
1975
- __publicField$d(Constants, "DEFAULT_PATH_LINE_WIDTH", 2);
1976
- /** Color of text in Label and TextLine, if none is specified. */
1977
- __publicField$d(Constants, "DEFAULT_FONT_COLOR", WebColors.Black);
1978
- /** Font size in Label and TextLine, if none is specified. */
1979
- __publicField$d(Constants, "DEFAULT_FONT_SIZE", 16);
1980
- __publicField$d(Constants, "LIMITED_FPS_RATE", 5);
1981
- __publicField$d(Constants, "FREE_ENTITIES_SCENE_NAME", "__freeEntitiesScene");
1982
- __publicField$d(Constants, "OUTGOING_SCENE_NAME", "__outgoingScene");
1983
- __publicField$d(Constants, "OUTGOING_SCENE_SPRITE_NAME", "__outgoingSceneSprite");
1984
- __publicField$d(Constants, "OUTGOING_SCENE_IMAGE_NAME", "__outgoingSceneSnapshot");
1985
- __publicField$d(Constants, "SESSION_INITIALIZATION_POLLING_INTERVAL_MS", 50);
1986
-
1987
2433
  var Dimensions = /* @__PURE__ */ ((Dimensions2) => {
1988
2434
  Dimensions2[Dimensions2["MatchConstraint"] = 0] = "MatchConstraint";
1989
2435
  return Dimensions2;
@@ -2228,22 +2674,12 @@ function property(e) {
2228
2674
  return meta;
2229
2675
  }
2230
2676
 
2231
- var __defProp$c = Object.defineProperty;
2232
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2233
- var __publicField$c = (obj, key, value) => {
2234
- __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
2235
- return value;
2236
- };
2237
2677
  class GameTypefaces {
2238
2678
  }
2239
2679
  class FontManager {
2240
2680
  constructor(session) {
2241
- __publicField$c(this, "canvasKit");
2242
- __publicField$c(this, "fontMgr");
2243
- __publicField$c(this, "gameTypefaces", new GameTypefaces());
2244
- __publicField$c(this, "fontData", new Array());
2245
- __publicField$c(this, "session");
2246
- __publicField$c(this, "games");
2681
+ this.gameTypefaces = new GameTypefaces();
2682
+ this.fontData = new Array();
2247
2683
  this.session = session;
2248
2684
  }
2249
2685
  /**
@@ -2277,20 +2713,17 @@ class FontManager {
2277
2713
  fetchFonts(games) {
2278
2714
  this.games = games;
2279
2715
  const fontsToFetch = games.flatMap(
2280
- (game) => {
2281
- var _a;
2282
- return (
2283
- // no fonts in game if game.options.fonts is undefined
2284
- (_a = game.options.fonts) == null ? void 0 : _a.map((font, i) => {
2285
- return {
2286
- gameUuid: game.uuid,
2287
- fontUrl: font.url,
2288
- fontName: font.fontName,
2289
- isDefault: i === 0
2290
- };
2291
- })
2292
- );
2293
- }
2716
+ (game) => (
2717
+ // no fonts in game if game.options.fonts is undefined
2718
+ game.options.fonts?.map((font, i) => {
2719
+ return {
2720
+ gameUuid: game.uuid,
2721
+ fontUrl: font.url,
2722
+ fontName: font.fontName,
2723
+ isDefault: i === 0
2724
+ };
2725
+ })
2726
+ )
2294
2727
  ).filter((f) => f !== void 0);
2295
2728
  if (fontsToFetch.length === 0) {
2296
2729
  return Promise.all([Promise.resolve()]);
@@ -2323,23 +2756,21 @@ class FontManager {
2323
2756
  * to our engine by creating canvaskit Typefaces.
2324
2757
  */
2325
2758
  loadAllGamesFontData() {
2326
- var _a;
2327
2759
  if (this.fontData.length === 0) {
2328
2760
  return;
2329
2761
  }
2330
2762
  if (!this.canvasKit) {
2331
2763
  throw new Error("canvasKit undefined");
2332
2764
  }
2333
- this.fontMgr = (_a = this.canvasKit.FontMgr.FromData(
2765
+ this.fontMgr = this.canvasKit.FontMgr.FromData(
2334
2766
  ...this.fontData.map((f) => f.fontArrayBuffer)
2335
- )) != null ? _a : void 0;
2767
+ ) ?? void 0;
2336
2768
  if (!this.fontMgr) {
2337
2769
  throw new Error("error creating FontMgr while loading fonts");
2338
2770
  }
2339
2771
  this.fontData.forEach((font) => {
2340
- var _a2, _b, _c;
2341
2772
  const result = ttfInfo(new DataView(font.fontArrayBuffer));
2342
- const fontFamilyUtf16Be = (_a2 = result.meta.property.filter((p) => p.name === "font-family").find(Boolean)) == null ? void 0 : _a2.text;
2773
+ const fontFamilyUtf16Be = result.meta.property.filter((p) => p.name === "font-family").find(Boolean)?.text;
2343
2774
  if (fontFamilyUtf16Be === void 0) {
2344
2775
  throw new Error(
2345
2776
  `error loading fonts. could not get font-family name from font at ${font.fontUrl}`
@@ -2359,7 +2790,7 @@ class FontManager {
2359
2790
  if (!typeface) {
2360
2791
  throw new Error("cannot make typeface from font array buffer");
2361
2792
  }
2362
- const gameId = (_c = (_b = this.games) == null ? void 0 : _b.find((g) => g.uuid === font.gameUuid)) == null ? void 0 : _c.id;
2793
+ const gameId = this.games?.find((g) => g.uuid === font.gameUuid)?.id;
2363
2794
  console.log(
2364
2795
  `\u26AA typeface ${font.fontName} ${font.isDefault ? "(default) " : ""}created from font-family ${fontFamily} for game ${gameId}`
2365
2796
  );
@@ -2375,29 +2806,6 @@ class FontManager {
2375
2806
  }
2376
2807
  }
2377
2808
 
2378
- var __defProp$b = Object.defineProperty;
2379
- var __defProps$5 = Object.defineProperties;
2380
- var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
2381
- var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
2382
- var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
2383
- var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
2384
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2385
- var __spreadValues$7 = (a, b) => {
2386
- for (var prop in b || (b = {}))
2387
- if (__hasOwnProp$7.call(b, prop))
2388
- __defNormalProp$b(a, prop, b[prop]);
2389
- if (__getOwnPropSymbols$7)
2390
- for (var prop of __getOwnPropSymbols$7(b)) {
2391
- if (__propIsEnum$7.call(b, prop))
2392
- __defNormalProp$b(a, prop, b[prop]);
2393
- }
2394
- return a;
2395
- };
2396
- var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
2397
- var __publicField$b = (obj, key, value) => {
2398
- __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
2399
- return value;
2400
- };
2401
2809
  class Sprite extends Entity {
2402
2810
  /**
2403
2811
  * Visual image displayed on the screen.
@@ -2408,16 +2816,13 @@ class Sprite extends Entity {
2408
2816
  */
2409
2817
  constructor(options = {}) {
2410
2818
  super(options);
2411
- __publicField$b(this, "type", EntityType.Sprite);
2412
- __publicField$b(this, "isDrawable", true);
2819
+ this.type = EntityType.Sprite;
2820
+ this.isDrawable = true;
2413
2821
  // Drawable options
2414
- __publicField$b(this, "anchorPoint", { x: 0.5, y: 0.5 });
2415
- __publicField$b(this, "zPosition", 0);
2822
+ this.anchorPoint = { x: 0.5, y: 0.5 };
2823
+ this.zPosition = 0;
2416
2824
  // Sprite options
2417
- __publicField$b(this, "_imageName", "");
2418
- // public getter/setter is below
2419
- __publicField$b(this, "loadedImage");
2420
- __publicField$b(this, "_paint");
2825
+ this._imageName = "";
2421
2826
  handleInterfaceOptions(this, options);
2422
2827
  if (options.imageName !== void 0) {
2423
2828
  this.imageName = options.imageName;
@@ -2444,8 +2849,7 @@ class Sprite extends Entity {
2444
2849
  this.needsInitialization = false;
2445
2850
  }
2446
2851
  dispose() {
2447
- var _a;
2448
- CanvasKitHelpers.Dispose([(_a = this.loadedImage) == null ? void 0 : _a.image, this._paint]);
2852
+ CanvasKitHelpers.Dispose([this.loadedImage?.image, this._paint]);
2449
2853
  }
2450
2854
  set imageName(imageName) {
2451
2855
  this._imageName = imageName;
@@ -2476,10 +2880,12 @@ class Sprite extends Entity {
2476
2880
  * provided, name will be the new uuid
2477
2881
  */
2478
2882
  duplicate(newName) {
2479
- const dest = new Sprite(__spreadProps$5(__spreadValues$7(__spreadValues$7({}, this.getEntityOptions()), this.getDrawableOptions()), {
2883
+ const dest = new Sprite({
2884
+ ...this.getEntityOptions(),
2885
+ ...this.getDrawableOptions(),
2480
2886
  imageName: this.imageName,
2481
2887
  name: newName
2482
- }));
2888
+ });
2483
2889
  if (this.children.length > 0) {
2484
2890
  dest.children = this.children.map((child) => {
2485
2891
  const clonedChild = child.duplicate();
@@ -2498,6 +2904,7 @@ class Sprite extends Entity {
2498
2904
  canvas.save();
2499
2905
  const drawScale = Globals.canvasScale / this.absoluteScale;
2500
2906
  canvas.scale(1 / drawScale, 1 / drawScale);
2907
+ M2c2KitHelpers.rotateCanvasForDrawableEntity(canvas, this);
2501
2908
  const x = (this.absolutePosition.x - this.size.width * this.anchorPoint.x * this.absoluteScale) * drawScale;
2502
2909
  const y = (this.absolutePosition.y - this.size.height * this.anchorPoint.y * this.absoluteScale) * drawScale;
2503
2910
  if (this.absoluteAlphaChange !== 0) {
@@ -2534,29 +2941,6 @@ class LoadedImage {
2534
2941
  }
2535
2942
  }
2536
2943
 
2537
- var __defProp$a = Object.defineProperty;
2538
- var __defProps$4 = Object.defineProperties;
2539
- var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
2540
- var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
2541
- var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
2542
- var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
2543
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2544
- var __spreadValues$6 = (a, b) => {
2545
- for (var prop in b || (b = {}))
2546
- if (__hasOwnProp$6.call(b, prop))
2547
- __defNormalProp$a(a, prop, b[prop]);
2548
- if (__getOwnPropSymbols$6)
2549
- for (var prop of __getOwnPropSymbols$6(b)) {
2550
- if (__propIsEnum$6.call(b, prop))
2551
- __defNormalProp$a(a, prop, b[prop]);
2552
- }
2553
- return a;
2554
- };
2555
- var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
2556
- var __publicField$a = (obj, key, value) => {
2557
- __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
2558
- return value;
2559
- };
2560
2944
  class Scene extends Entity {
2561
2945
  /**
2562
2946
  * Top-level entity that holds all other entities, such as sprites, rectangles, or labels, that will be displayed on the screen
@@ -2567,18 +2951,15 @@ class Scene extends Entity {
2567
2951
  */
2568
2952
  constructor(options = {}) {
2569
2953
  super(options);
2570
- __publicField$a(this, "type", EntityType.Scene);
2571
- __publicField$a(this, "isDrawable", true);
2954
+ this.type = EntityType.Scene;
2955
+ this.isDrawable = true;
2572
2956
  // Drawable options
2573
- __publicField$a(this, "anchorPoint", { x: 0, y: 0 });
2574
- __publicField$a(this, "zPosition", 0);
2957
+ this.anchorPoint = { x: 0, y: 0 };
2958
+ this.zPosition = 0;
2575
2959
  // Scene options
2576
- __publicField$a(this, "_backgroundColor", Constants.DEFAULT_SCENE_BACKGROUND_COLOR);
2577
- __publicField$a(this, "_active", false);
2578
- __publicField$a(this, "_transitioning", false);
2579
- __publicField$a(this, "_setupCallback");
2580
- __publicField$a(this, "_appearCallback");
2581
- __publicField$a(this, "backgroundPaint");
2960
+ this._backgroundColor = Constants.DEFAULT_SCENE_BACKGROUND_COLOR;
2961
+ this._active = false;
2962
+ this._transitioning = false;
2582
2963
  handleInterfaceOptions(this, options);
2583
2964
  if (options.backgroundColor) {
2584
2965
  this.backgroundColor = options.backgroundColor;
@@ -2634,10 +3015,12 @@ class Scene extends Entity {
2634
3015
  * provided, name will be the new uuid
2635
3016
  */
2636
3017
  duplicate(newName) {
2637
- const dest = new Scene(__spreadProps$4(__spreadValues$6(__spreadValues$6({}, this.getEntityOptions()), this.getDrawableOptions()), {
3018
+ const dest = new Scene({
3019
+ ...this.getEntityOptions(),
3020
+ ...this.getDrawableOptions(),
2638
3021
  backgroundColor: this.backgroundColor,
2639
3022
  name: newName
2640
- }));
3023
+ });
2641
3024
  dest.game = this.game;
2642
3025
  if (this.children.length > 0) {
2643
3026
  dest.children = this.children.map((child) => {
@@ -2680,6 +3063,7 @@ class Scene extends Entity {
2680
3063
  canvas.save();
2681
3064
  const drawScale = Globals.canvasScale / this.absoluteScale;
2682
3065
  canvas.scale(1 / drawScale, 1 / drawScale);
3066
+ M2c2KitHelpers.rotateCanvasForDrawableEntity(canvas, this);
2683
3067
  if (!this.backgroundPaint) {
2684
3068
  throw new Error(`in Scene ${this}, background paint is undefined.`);
2685
3069
  }
@@ -2724,12 +3108,6 @@ class Scene extends Entity {
2724
3108
  }
2725
3109
  }
2726
3110
 
2727
- var __defProp$9 = Object.defineProperty;
2728
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2729
- var __publicField$9 = (obj, key, value) => {
2730
- __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
2731
- return value;
2732
- };
2733
3111
  class Transition {
2734
3112
  /**
2735
3113
  * Creates a scene transition in which the outgoing scene slides out and the incoming scene slides in, as if the incoming scene pushes it.
@@ -2738,11 +3116,10 @@ class Transition {
2738
3116
  * @returns
2739
3117
  */
2740
3118
  static slide(options) {
2741
- var _a;
2742
3119
  return new SlideTransition(
2743
3120
  options.direction,
2744
3121
  options.duration,
2745
- (_a = options.easing) != null ? _a : Easings.linear
3122
+ options.easing ?? Easings.linear
2746
3123
  );
2747
3124
  }
2748
3125
  /**
@@ -2755,9 +3132,7 @@ class Transition {
2755
3132
  class NoneTransition extends Transition {
2756
3133
  constructor() {
2757
3134
  super();
2758
- __publicField$9(this, "type", "None" /* None */);
2759
- __publicField$9(this, "easing");
2760
- __publicField$9(this, "duration");
3135
+ this.type = "None" /* None */;
2761
3136
  this.duration = NaN;
2762
3137
  this.easing = Easings.none;
2763
3138
  }
@@ -2765,10 +3140,7 @@ class NoneTransition extends Transition {
2765
3140
  class SlideTransition extends Transition {
2766
3141
  constructor(direction, duration, easing) {
2767
3142
  super();
2768
- __publicField$9(this, "type", "Slide" /* Slide */);
2769
- __publicField$9(this, "easing");
2770
- __publicField$9(this, "duration");
2771
- __publicField$9(this, "direction");
3143
+ this.type = "Slide" /* Slide */;
2772
3144
  this.direction = direction;
2773
3145
  this.duration = duration;
2774
3146
  this.easing = easing;
@@ -2793,25 +3165,18 @@ class SceneTransition {
2793
3165
  }
2794
3166
  }
2795
3167
 
2796
- var __defProp$8 = Object.defineProperty;
2797
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2798
- var __publicField$8 = (obj, key, value) => {
2799
- __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
2800
- return value;
2801
- };
2802
3168
  const _Timer = class _Timer {
2803
3169
  constructor(name) {
2804
3170
  // startTime is the timestamp of the current active run
2805
- __publicField$8(this, "startTime", NaN);
2806
- __publicField$8(this, "stopTime", NaN);
2807
- __publicField$8(this, "stopped", true);
3171
+ this.startTime = NaN;
3172
+ this.stopTime = NaN;
3173
+ this.stopped = true;
2808
3174
  /**
2809
3175
  * cumulativeElapsed is a cumulative total of elapsed time while the timer
2810
3176
  * was in previous started (running) states, NOT INCLUDING the possibly
2811
3177
  * active run's duration
2812
3178
  */
2813
- __publicField$8(this, "cumulativeElapsed", NaN);
2814
- __publicField$8(this, "name");
3179
+ this.cumulativeElapsed = NaN;
2815
3180
  this.name = name;
2816
3181
  }
2817
3182
  /**
@@ -2963,7 +3328,7 @@ const _Timer = class _Timer {
2963
3328
  return this._timers.some((t) => t.name === name);
2964
3329
  }
2965
3330
  };
2966
- __publicField$8(_Timer, "_timers", new Array());
3331
+ _Timer._timers = new Array();
2967
3332
  let Timer = _Timer;
2968
3333
 
2969
3334
  const deviceMetadataSchema = {
@@ -3073,39 +3438,16 @@ class WebGlInfo {
3073
3438
  }
3074
3439
  }
3075
3440
 
3076
- var __defProp$7 = Object.defineProperty;
3077
- var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
3078
- var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
3079
- var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
3080
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3081
- var __spreadValues$5 = (a, b) => {
3082
- for (var prop in b || (b = {}))
3083
- if (__hasOwnProp$5.call(b, prop))
3084
- __defNormalProp$7(a, prop, b[prop]);
3085
- if (__getOwnPropSymbols$5)
3086
- for (var prop of __getOwnPropSymbols$5(b)) {
3087
- if (__propIsEnum$5.call(b, prop))
3088
- __defNormalProp$7(a, prop, b[prop]);
3089
- }
3090
- return a;
3091
- };
3092
- var __publicField$7 = (obj, key, value) => {
3093
- __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
3094
- return value;
3095
- };
3096
3441
  class I18n {
3097
3442
  constructor(options) {
3098
- __publicField$7(this, "_translations");
3099
- __publicField$7(this, "locale", "");
3100
- __publicField$7(this, "fallbackLocale", "en");
3101
- __publicField$7(this, "environmentLocale", this.getEnvironmentLocale());
3102
- __publicField$7(this, "options");
3103
- var _a;
3443
+ this.locale = "";
3444
+ this.fallbackLocale = "en";
3445
+ this.environmentLocale = this.getEnvironmentLocale();
3104
3446
  this.options = options;
3105
- this._translations = (_a = this.mergeAdditionalTranslations(
3447
+ this._translations = this.mergeAdditionalTranslations(
3106
3448
  options.translations,
3107
3449
  options.additionalTranslations
3108
- )) != null ? _a : {};
3450
+ ) ?? {};
3109
3451
  if (options.locale.toLowerCase() === "auto") {
3110
3452
  this.locale = this.environmentLocale;
3111
3453
  if (!this.locale) {
@@ -3158,11 +3500,10 @@ class I18n {
3158
3500
  return localizationParameters;
3159
3501
  }
3160
3502
  t(key, useFallback = false) {
3161
- var _a, _b;
3162
3503
  if (useFallback) {
3163
- return (_a = this._translations[this.fallbackLocale]) == null ? void 0 : _a[key];
3504
+ return this._translations[this.fallbackLocale]?.[key];
3164
3505
  }
3165
- return (_b = this._translations[this.locale]) == null ? void 0 : _b[key];
3506
+ return this._translations[this.locale]?.[key];
3166
3507
  }
3167
3508
  get translations() {
3168
3509
  return this._translations;
@@ -3187,7 +3528,10 @@ class I18n {
3187
3528
  const processedLocales = new Array();
3188
3529
  for (const locale in baseTranslations) {
3189
3530
  processedLocales.push(locale);
3190
- result[locale] = __spreadValues$5(__spreadValues$5({}, baseTranslations[locale]), additionalTranslations[locale]);
3531
+ result[locale] = {
3532
+ ...baseTranslations[locale],
3533
+ ...additionalTranslations[locale]
3534
+ };
3191
3535
  }
3192
3536
  for (const locale in additionalTranslations) {
3193
3537
  if (processedLocales.includes(locale)) {
@@ -3309,49 +3653,6 @@ class DomHelpers {
3309
3653
  }
3310
3654
  }
3311
3655
 
3312
- var ShapeType = /* @__PURE__ */ ((ShapeType2) => {
3313
- ShapeType2["Undefined"] = "Undefined";
3314
- ShapeType2["Rectangle"] = "Rectangle";
3315
- ShapeType2["Circle"] = "Circle";
3316
- ShapeType2["Path"] = "Path";
3317
- return ShapeType2;
3318
- })(ShapeType || {});
3319
-
3320
- var __defProp$6 = Object.defineProperty;
3321
- var __defProps$3 = Object.defineProperties;
3322
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
3323
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
3324
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
3325
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
3326
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3327
- var __spreadValues$4 = (a, b) => {
3328
- for (var prop in b || (b = {}))
3329
- if (__hasOwnProp$4.call(b, prop))
3330
- __defNormalProp$6(a, prop, b[prop]);
3331
- if (__getOwnPropSymbols$4)
3332
- for (var prop of __getOwnPropSymbols$4(b)) {
3333
- if (__propIsEnum$4.call(b, prop))
3334
- __defNormalProp$6(a, prop, b[prop]);
3335
- }
3336
- return a;
3337
- };
3338
- var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
3339
- var __objRest = (source, exclude) => {
3340
- var target = {};
3341
- for (var prop in source)
3342
- if (__hasOwnProp$4.call(source, prop) && exclude.indexOf(prop) < 0)
3343
- target[prop] = source[prop];
3344
- if (source != null && __getOwnPropSymbols$4)
3345
- for (var prop of __getOwnPropSymbols$4(source)) {
3346
- if (exclude.indexOf(prop) < 0 && __propIsEnum$4.call(source, prop))
3347
- target[prop] = source[prop];
3348
- }
3349
- return target;
3350
- };
3351
- var __publicField$6 = (obj, key, value) => {
3352
- __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
3353
- return value;
3354
- };
3355
3656
  class Game {
3356
3657
  /**
3357
3658
  * The base class for all games. New games should extend this class.
@@ -3359,66 +3660,44 @@ class Game {
3359
3660
  * @param options - {@link GameOptions}
3360
3661
  */
3361
3662
  constructor(options) {
3362
- __publicField$6(this, "type", ActivityType.Game);
3363
- __publicField$6(this, "_canvasKit");
3364
- __publicField$6(this, "_session");
3365
- __publicField$6(this, "uuid", Uuid.generate());
3366
- __publicField$6(this, "name");
3367
- __publicField$6(this, "id");
3368
- __publicField$6(this, "options");
3369
- __publicField$6(this, "beginTimestamp", NaN);
3370
- __publicField$6(this, "beginIso8601Timestamp", "");
3371
- __publicField$6(this, "eventListeners", new Array());
3372
- __publicField$6(this, "gameMetrics", new Array());
3373
- __publicField$6(this, "fpsMetricReportThreshold");
3374
- __publicField$6(this, "maximumRecordedActivityMetrics");
3375
- __publicField$6(this, "stepCount", 0);
3376
- __publicField$6(this, "steppingNow", 0);
3377
- __publicField$6(this, "i18n");
3378
- __publicField$6(this, "warmupFunctionQueue", new Array());
3379
- __publicField$6(this, "loaderElementsRemoved", false);
3380
- __publicField$6(this, "_dataStores");
3381
- __publicField$6(this, "additionalParameters");
3382
- __publicField$6(this, "staticTrialSchema", {});
3383
- /** The scene, or its name as a string, to be presented when the game is started. If this is undefined, the game will start with the first scene that has been added */
3384
- __publicField$6(this, "entryScene");
3385
- __publicField$6(this, "data", {
3663
+ this.type = ActivityType.Game;
3664
+ this.uuid = Uuid.generate();
3665
+ this.beginTimestamp = NaN;
3666
+ this.beginIso8601Timestamp = "";
3667
+ this.eventListeners = new Array();
3668
+ this.gameMetrics = new Array();
3669
+ this.stepCount = 0;
3670
+ this.steppingNow = 0;
3671
+ this.warmupFunctionQueue = new Array();
3672
+ this.loaderElementsRemoved = false;
3673
+ this.staticTrialSchema = {};
3674
+ this.data = {
3386
3675
  trials: new Array()
3387
- });
3676
+ };
3388
3677
  /** The 0-based index of the current trial */
3389
- __publicField$6(this, "trialIndex", 0);
3390
- __publicField$6(this, "htmlCanvas");
3391
- __publicField$6(this, "surface");
3392
- __publicField$6(this, "showFps");
3393
- __publicField$6(this, "bodyBackgroundColor");
3394
- __publicField$6(this, "currentScene");
3395
- __publicField$6(this, "priorUpdateTime");
3396
- __publicField$6(this, "fpsTextFont");
3397
- __publicField$6(this, "fpsTextPaint");
3398
- __publicField$6(this, "drawnFrames", 0);
3399
- __publicField$6(this, "lastFpsUpdate", 0);
3400
- __publicField$6(this, "nextFpsUpdate", 0);
3401
- __publicField$6(this, "fpsRate", 0);
3402
- __publicField$6(this, "animationFramesRequested", 0);
3403
- __publicField$6(this, "limitFps", false);
3404
- __publicField$6(this, "unitTesting", false);
3405
- __publicField$6(this, "gameStopRequested", false);
3406
- __publicField$6(this, "webGlRendererInfo", "");
3407
- __publicField$6(this, "canvasCssWidth", 0);
3408
- __publicField$6(this, "canvasCssHeight", 0);
3409
- __publicField$6(this, "scenes", new Array());
3410
- __publicField$6(this, "freeEntitiesScene", new Scene({
3678
+ this.trialIndex = 0;
3679
+ this.drawnFrames = 0;
3680
+ this.lastFpsUpdate = 0;
3681
+ this.nextFpsUpdate = 0;
3682
+ this.fpsRate = 0;
3683
+ this.animationFramesRequested = 0;
3684
+ this.limitFps = false;
3685
+ this.unitTesting = false;
3686
+ this.gameStopRequested = false;
3687
+ this.webGlRendererInfo = "";
3688
+ this.canvasCssWidth = 0;
3689
+ this.canvasCssHeight = 0;
3690
+ this.scenes = new Array();
3691
+ this.freeEntitiesScene = new Scene({
3411
3692
  name: Constants.FREE_ENTITIES_SCENE_NAME,
3412
3693
  backgroundColor: [255, 255, 255, 0]
3413
- }));
3414
- __publicField$6(this, "incomingSceneTransitions", new Array());
3415
- __publicField$6(this, "currentSceneSnapshot");
3416
- __publicField$6(this, "pendingScreenshot");
3694
+ });
3695
+ this.incomingSceneTransitions = new Array();
3417
3696
  /**
3418
3697
  * The m2c2kit engine will automatically include these schema and their
3419
3698
  * values in the trial data.
3420
3699
  */
3421
- __publicField$6(this, "automaticTrialSchema", {
3700
+ this.automaticTrialSchema = {
3422
3701
  document_uuid: {
3423
3702
  type: "string",
3424
3703
  format: "uuid",
@@ -3450,9 +3729,8 @@ class Game {
3450
3729
  type: "integer",
3451
3730
  description: "Difference in minutes between UTC and device timezone. Calculated from Date.getTimezoneOffset()."
3452
3731
  }
3453
- });
3454
- __publicField$6(this, "snapshots", new Array());
3455
- var _a, _b;
3732
+ };
3733
+ this.snapshots = new Array();
3456
3734
  if (!options.id || options.id.trim() === "") {
3457
3735
  throw new Error("id is required in GameOptions");
3458
3736
  }
@@ -3461,31 +3739,33 @@ class Game {
3461
3739
  this.id = options.id;
3462
3740
  this.freeEntitiesScene.game = this;
3463
3741
  this.freeEntitiesScene.needsInitialization = true;
3464
- this.fpsMetricReportThreshold = (_a = options.fpsMetricReportThreshold) != null ? _a : Constants.FPS_METRIC_REPORT_THRESHOLD;
3465
- this.maximumRecordedActivityMetrics = (_b = options.maximumRecordedActivityMetrics) != null ? _b : Constants.MAXIMUM_RECORDED_ACTIVITY_METRICS;
3742
+ this.fpsMetricReportThreshold = options.fpsMetricReportThreshold ?? Constants.FPS_METRIC_REPORT_THRESHOLD;
3743
+ this.maximumRecordedActivityMetrics = options.maximumRecordedActivityMetrics ?? Constants.MAXIMUM_RECORDED_ACTIVITY_METRICS;
3466
3744
  this.addLocalizationParametersToGameParameters();
3467
3745
  if (!this.options.trialSchema) {
3468
3746
  this.options.trialSchema = {};
3469
3747
  }
3470
3748
  }
3471
3749
  addLocalizationParametersToGameParameters() {
3472
- this.options.parameters = __spreadValues$4(__spreadValues$4({}, this.options.parameters), I18n.makeLocalizationParameters());
3750
+ this.options.parameters = {
3751
+ ...this.options.parameters,
3752
+ ...I18n.makeLocalizationParameters()
3753
+ };
3473
3754
  }
3474
3755
  async init() {
3475
3756
  return this.initialize();
3476
3757
  }
3477
3758
  async initialize() {
3478
- var _a, _b;
3479
3759
  if (this.isLocalizationRequested()) {
3480
3760
  const options = this.getLocalizationOptionsFromGameParameters();
3481
3761
  this.i18n = new I18n(options);
3482
3762
  }
3483
- if ((_a = this.session.options.activityCallbacks) == null ? void 0 : _a.onActivityLifecycle) {
3763
+ if (this.session.options.activityCallbacks?.onActivityLifecycle) {
3484
3764
  this.onStart(this.session.options.activityCallbacks.onActivityLifecycle);
3485
3765
  this.onCancel(this.session.options.activityCallbacks.onActivityLifecycle);
3486
3766
  this.onEnd(this.session.options.activityCallbacks.onActivityLifecycle);
3487
3767
  }
3488
- if ((_b = this.session.options.activityCallbacks) == null ? void 0 : _b.onActivityResults) {
3768
+ if (this.session.options.activityCallbacks?.onActivityResults) {
3489
3769
  this.onData(this.session.options.activityCallbacks.onActivityResults);
3490
3770
  }
3491
3771
  }
@@ -3874,16 +4154,15 @@ class Game {
3874
4154
  * @param entryScene - The scene (Scene object or its string name) to display when the game starts
3875
4155
  */
3876
4156
  async start(entryScene) {
3877
- var _a, _b;
3878
4157
  const gameInitOptions = this.options;
3879
- this.unitTesting = (_a = gameInitOptions._unitTesting) != null ? _a : false;
4158
+ this.unitTesting = gameInitOptions._unitTesting ?? false;
3880
4159
  this.setupHtmlCanvases(
3881
4160
  gameInitOptions.canvasId,
3882
4161
  gameInitOptions.width,
3883
4162
  gameInitOptions.height,
3884
4163
  gameInitOptions.stretch
3885
4164
  );
3886
- this.showFps = (_b = gameInitOptions.showFps) != null ? _b : false;
4165
+ this.showFps = gameInitOptions.showFps ?? false;
3887
4166
  this.bodyBackgroundColor = gameInitOptions.bodyBackgroundColor;
3888
4167
  this.initData();
3889
4168
  this.setupCanvasKitSurface();
@@ -3995,11 +4274,10 @@ class Game {
3995
4274
  }
3996
4275
  }
3997
4276
  advanceStepsHandler(mouseEvent) {
3998
- var _a, _b;
3999
- if (((_a = mouseEvent == null ? void 0 : mouseEvent.target) == null ? void 0 : _a.id) === "1-step-advance") {
4277
+ if (mouseEvent?.target?.id === "1-step-advance") {
4000
4278
  this.steppingNow = this.steppingNow + 16.66666666666667;
4001
4279
  this.stepCount = this.stepCount + 1;
4002
- } else if (((_b = mouseEvent == null ? void 0 : mouseEvent.target) == null ? void 0 : _b.id) === "55-step-advance") {
4280
+ } else if (mouseEvent?.target?.id === "55-step-advance") {
4003
4281
  this.steppingNow = this.steppingNow + 16.66666666666667 * 55;
4004
4282
  this.stepCount = this.stepCount + 55;
4005
4283
  }
@@ -4169,12 +4447,11 @@ class Game {
4169
4447
  this.entities.filter((e) => e.isDrawable).forEach((e) => e.dispose());
4170
4448
  }
4171
4449
  initData() {
4172
- var _a;
4173
4450
  this.trialIndex = 0;
4174
4451
  this.data = {
4175
4452
  trials: new Array()
4176
4453
  };
4177
- const trialSchema = (_a = this.options.trialSchema) != null ? _a : {};
4454
+ const trialSchema = this.options.trialSchema ?? {};
4178
4455
  const variables = Object.entries(trialSchema);
4179
4456
  for (const [variableName, propertySchema] of variables) {
4180
4457
  if (propertySchema.type !== void 0 && !this.propertySchemaDataTypeIsValid(propertySchema.type)) {
@@ -4256,7 +4533,6 @@ class Game {
4256
4533
  * @param value - value of the variable to set
4257
4534
  */
4258
4535
  addTrialData(variableName, value) {
4259
- var _a, _b, _c;
4260
4536
  if (!this.options.trialSchema) {
4261
4537
  throw new Error(
4262
4538
  "no trial schema were provided in GameOptions. cannot add trial data"
@@ -4268,17 +4544,17 @@ class Game {
4268
4544
  for (const [variableName2] of variables) {
4269
4545
  emptyTrial[variableName2] = null;
4270
4546
  }
4271
- this.data.trials.push(__spreadProps$3(__spreadValues$4({
4547
+ this.data.trials.push({
4272
4548
  document_uuid: Uuid.generate(),
4273
4549
  session_uuid: this.session.uuid,
4274
4550
  activity_uuid: this.uuid,
4275
4551
  activity_id: this.options.id,
4276
4552
  activity_version: this.options.version,
4277
- device_timezone: (_c = (_b = (_a = Intl == null ? void 0 : Intl.DateTimeFormat()) == null ? void 0 : _a.resolvedOptions()) == null ? void 0 : _b.timeZone) != null ? _c : "",
4278
- device_timezone_offset_minutes: (/* @__PURE__ */ new Date()).getTimezoneOffset()
4279
- }, emptyTrial), {
4553
+ device_timezone: Intl?.DateTimeFormat()?.resolvedOptions()?.timeZone ?? "",
4554
+ device_timezone_offset_minutes: (/* @__PURE__ */ new Date()).getTimezoneOffset(),
4555
+ ...emptyTrial,
4280
4556
  device_metadata: this.getDeviceMetadata()
4281
- }));
4557
+ });
4282
4558
  }
4283
4559
  if (!(variableName in this.options.trialSchema)) {
4284
4560
  throw new Error(`trial variable ${variableName} not defined in schema`);
@@ -4337,12 +4613,12 @@ class Game {
4337
4613
  * Rather than modify the source code for the game, you can do the following
4338
4614
  * to ensure that the participant ID is saved for each trial:
4339
4615
  *
4340
- * game.addTrialSchema({
4341
- * participant_id: {
4616
+ * game.addTrialSchema(&#123
4617
+ * participant_id: &#123
4342
4618
  * type: "string",
4343
4619
  * description: "ID of the participant",
4344
- * }
4345
- * });
4620
+ * &#125;
4621
+ * &#125;);
4346
4622
  * game.addStaticTrialData("participant_id", "12345");
4347
4623
  *
4348
4624
  * When Game.trialComplete() is called, the participant_id variable will
@@ -4371,9 +4647,11 @@ class Game {
4371
4647
  * the appropriate time. It is not triggered automatically.
4372
4648
  */
4373
4649
  trialComplete() {
4374
- var _a, _b;
4375
4650
  if (Object.keys(this.staticTrialSchema).length > 0) {
4376
- this.data.trials[this.trialIndex] = __spreadValues$4(__spreadValues$4({}, this.data.trials[this.trialIndex]), this.staticTrialSchema);
4651
+ this.data.trials[this.trialIndex] = {
4652
+ ...this.data.trials[this.trialIndex],
4653
+ ...this.staticTrialSchema
4654
+ };
4377
4655
  }
4378
4656
  this.trialIndex++;
4379
4657
  const resultsEvent = {
@@ -4387,10 +4665,10 @@ class Game {
4387
4665
  data: this.data,
4388
4666
  dataSchema: this.makeGameDataSchema(),
4389
4667
  activityConfiguration: this.makeGameActivityConfiguration(
4390
- (_a = this.options.parameters) != null ? _a : {}
4668
+ this.options.parameters ?? {}
4391
4669
  ),
4392
4670
  activityConfigurationSchema: this.makeGameActivityConfigurationSchema(
4393
- (_b = this.options.parameters) != null ? _b : {}
4671
+ this.options.parameters ?? {}
4394
4672
  ),
4395
4673
  activityMetrics: this.gameMetrics
4396
4674
  };
@@ -4402,9 +4680,11 @@ class Game {
4402
4680
  $comment: `Activity identifier: ${this.options.id}, version: ${this.options.version}.`,
4403
4681
  $schema: "https://json-schema.org/draft/2019-09/schema",
4404
4682
  type: "object",
4405
- properties: __spreadProps$3(__spreadValues$4(__spreadValues$4({}, this.automaticTrialSchema), this.options.trialSchema), {
4683
+ properties: {
4684
+ ...this.automaticTrialSchema,
4685
+ ...this.options.trialSchema,
4406
4686
  device_metadata: deviceMetadataSchema
4407
- })
4687
+ }
4408
4688
  };
4409
4689
  return newDataSchema;
4410
4690
  }
@@ -4425,9 +4705,11 @@ class Game {
4425
4705
  $defs: {
4426
4706
  trial: {
4427
4707
  type: "object",
4428
- properties: __spreadProps$3(__spreadValues$4(__spreadValues$4({}, this.automaticTrialSchema), this.options.trialSchema), {
4708
+ properties: {
4709
+ ...this.automaticTrialSchema,
4710
+ ...this.options.trialSchema,
4429
4711
  device_metadata: deviceMetadataSchema
4430
- })
4712
+ }
4431
4713
  }
4432
4714
  }
4433
4715
  };
@@ -4442,15 +4724,17 @@ class Game {
4442
4724
  */
4443
4725
  makeGameActivityConfiguration(parameters) {
4444
4726
  const gameParams = JSON.parse(JSON.stringify(parameters));
4445
- const _a = gameParams, result = __objRest(_a, [
4446
- "locale",
4727
+ const {
4728
+ locale,
4447
4729
  // eslint-disable-line @typescript-eslint/no-unused-vars
4448
- "fallback_locale",
4730
+ fallback_locale,
4449
4731
  // eslint-disable-line @typescript-eslint/no-unused-vars
4450
- "missing_translation_font_color",
4732
+ missing_translation_font_color,
4451
4733
  // eslint-disable-line @typescript-eslint/no-unused-vars
4452
- "translations"
4453
- ]);
4734
+ translations,
4735
+ // eslint-disable-line @typescript-eslint/no-unused-vars
4736
+ ...result
4737
+ } = gameParams;
4454
4738
  for (const prop in result) {
4455
4739
  for (const subProp in result[prop]) {
4456
4740
  if (subProp == "default") {
@@ -4462,15 +4746,17 @@ class Game {
4462
4746
  }
4463
4747
  makeGameActivityConfigurationSchema(parameters) {
4464
4748
  const gameParams = JSON.parse(JSON.stringify(parameters));
4465
- const _a = gameParams, result = __objRest(_a, [
4466
- "locale",
4749
+ const {
4750
+ locale,
4467
4751
  // eslint-disable-line @typescript-eslint/no-unused-vars
4468
- "fallback_locale",
4752
+ fallback_locale,
4469
4753
  // eslint-disable-line @typescript-eslint/no-unused-vars
4470
- "missing_translation_font_color",
4754
+ missing_translation_font_color,
4471
4755
  // eslint-disable-line @typescript-eslint/no-unused-vars
4472
- "translations"
4473
- ]);
4756
+ translations,
4757
+ // eslint-disable-line @typescript-eslint/no-unused-vars
4758
+ ...result
4759
+ } = gameParams;
4474
4760
  for (const prop in result) {
4475
4761
  if (!("type" in result[prop]) && "value" in result[prop]) {
4476
4762
  const valueType = typeof result[prop]["default"];
@@ -4501,7 +4787,6 @@ class Game {
4501
4787
  * appropriate time. It is not triggered automatically.
4502
4788
  */
4503
4789
  end() {
4504
- var _a, _b;
4505
4790
  const activityEndEvent = {
4506
4791
  target: this,
4507
4792
  type: EventType.ActivityEnd
@@ -4510,10 +4795,10 @@ class Game {
4510
4795
  data: this.data,
4511
4796
  dataSchema: this.makeGameDataSchema(),
4512
4797
  activityConfiguration: this.makeGameActivityConfiguration(
4513
- (_a = this.options.parameters) != null ? _a : {}
4798
+ this.options.parameters ?? {}
4514
4799
  ),
4515
4800
  activityConfigurationSchema: this.makeGameActivityConfigurationSchema(
4516
- (_b = this.options.parameters) != null ? _b : {}
4801
+ this.options.parameters ?? {}
4517
4802
  ),
4518
4803
  activityMetrics: this.gameMetrics
4519
4804
  };
@@ -4530,7 +4815,6 @@ class Game {
4530
4815
  * appropriate time. It is not triggered automatically.
4531
4816
  */
4532
4817
  cancel() {
4533
- var _a, _b;
4534
4818
  const activityCancelEvent = {
4535
4819
  target: this,
4536
4820
  type: EventType.ActivityCancel
@@ -4539,10 +4823,10 @@ class Game {
4539
4823
  data: this.data,
4540
4824
  dataSchema: this.makeGameDataSchema(),
4541
4825
  activityConfiguration: this.makeGameActivityConfiguration(
4542
- (_a = this.options.parameters) != null ? _a : {}
4826
+ this.options.parameters ?? {}
4543
4827
  ),
4544
4828
  activityConfigurationSchema: this.makeGameActivityConfigurationSchema(
4545
- (_b = this.options.parameters) != null ? _b : {}
4829
+ this.options.parameters ?? {}
4546
4830
  ),
4547
4831
  activityMetrics: this.gameMetrics
4548
4832
  };
@@ -4614,7 +4898,7 @@ class Game {
4614
4898
  this.interceptWebGlCalls();
4615
4899
  try {
4616
4900
  this.webGlRendererInfo = WebGlInfo.getRendererString();
4617
- } catch (e) {
4901
+ } catch {
4618
4902
  this.webGlRendererInfo = "err";
4619
4903
  WebGlInfo.dispose();
4620
4904
  }
@@ -4701,13 +4985,12 @@ class Game {
4701
4985
  );
4702
4986
  }
4703
4987
  loop(canvas) {
4704
- var _a;
4705
4988
  if (!this.surface) {
4706
4989
  throw new Error("surface is undefined");
4707
4990
  }
4708
4991
  if (this.warmupFunctionQueue.length > 0) {
4709
4992
  const warmup = this.warmupFunctionQueue.shift();
4710
- warmup == null ? void 0 : warmup.warmupFunction.call(this, canvas, warmup.positionOffset);
4993
+ warmup?.warmupFunction.call(this, canvas, warmup.positionOffset);
4711
4994
  this.surface.requestAnimationFrame(this.loop.bind(this));
4712
4995
  return;
4713
4996
  }
@@ -4732,7 +5015,7 @@ class Game {
4732
5015
  this.update();
4733
5016
  this.draw(canvas);
4734
5017
  while (this.snapshots.length > 0) {
4735
- (_a = this.snapshots.shift()) == null ? void 0 : _a.delete();
5018
+ this.snapshots.shift()?.delete();
4736
5019
  }
4737
5020
  this.snapshots.push(this.takeCurrentSceneSnapshot());
4738
5021
  this.freeEntitiesScene.draw(canvas);
@@ -5540,9 +5823,24 @@ class Game {
5540
5823
  width = radius * 2;
5541
5824
  height = radius * 2;
5542
5825
  }
5543
- const x = domPointerEvent.offsetX;
5544
- const y = domPointerEvent.offsetY;
5545
- const bb = this.calculateEntityAbsoluteBoundingBox(entity);
5826
+ let x = domPointerEvent.offsetX;
5827
+ let y = domPointerEvent.offsetY;
5828
+ const bb = M2c2KitHelpers.calculateEntityAbsoluteBoundingBox(entity);
5829
+ if (M2c2KitHelpers.entityOrAncestorHasBeenRotated(entity)) {
5830
+ const transforms = M2c2KitHelpers.calculateRotationTransforms(
5831
+ entity
5832
+ );
5833
+ transforms.forEach((transform) => {
5834
+ const rotatedPoint = M2c2KitHelpers.rotatePoint(
5835
+ { x, y },
5836
+ // take negative because we are applying the reverse rotation
5837
+ -transform.radians,
5838
+ transform.center
5839
+ );
5840
+ x = rotatedPoint.x;
5841
+ y = rotatedPoint.y;
5842
+ });
5843
+ }
5546
5844
  const relativeX = (x - bb.xMin) / (bb.xMax - bb.xMin) * width;
5547
5845
  const relativeY = (y - bb.yMin) / (bb.yMax - bb.yMin) * height;
5548
5846
  return { x: relativeX, y: relativeY };
@@ -5593,7 +5891,7 @@ class Game {
5593
5891
  activityUuid: this.uuid,
5594
5892
  callback
5595
5893
  };
5596
- if (options == null ? void 0 : options.replaceExisting) {
5894
+ if (options?.replaceExisting) {
5597
5895
  this.eventListeners = this.eventListeners.filter(
5598
5896
  (listener) => !(listener.activityUuid === eventListener.activityUuid && listener.type === eventListener.type)
5599
5897
  );
@@ -5602,7 +5900,11 @@ class Game {
5602
5900
  }
5603
5901
  raiseActivityEventOnListeners(activityEvent, extra) {
5604
5902
  if (extra) {
5605
- activityEvent = __spreadValues$4(__spreadValues$4({}, activityEvent), extra);
5903
+ activityEvent = {
5904
+ ...activityEvent,
5905
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5906
+ ...extra
5907
+ };
5606
5908
  }
5607
5909
  this.eventListeners.filter((listener) => listener.type === activityEvent.type).forEach((listener) => {
5608
5910
  listener.callback(activityEvent);
@@ -5650,8 +5952,7 @@ class Game {
5650
5952
  });
5651
5953
  }
5652
5954
  sceneCanReceiveUserInteraction(scene) {
5653
- var _a;
5654
- if (scene.game === ((_a = scene.game.session) == null ? void 0 : _a.currentActivity) && scene._transitioning === false) {
5955
+ if (scene.game === scene.game.session?.currentActivity && scene._transitioning === false) {
5655
5956
  return true;
5656
5957
  }
5657
5958
  return false;
@@ -5670,14 +5971,14 @@ class Game {
5670
5971
  throw "only drawable entities can receive pointer events";
5671
5972
  }
5672
5973
  if (entity.type === EntityType.Shape && entity.shapeType === ShapeType.Circle) {
5673
- const bb2 = this.calculateEntityAbsoluteBoundingBox(entity);
5974
+ const bb = M2c2KitHelpers.calculateEntityAbsoluteBoundingBox(entity);
5674
5975
  const radius = entity.circleOfRadius;
5675
5976
  if (!radius) {
5676
5977
  throw "circleOfRadius is undefined";
5677
5978
  }
5678
5979
  const center = {
5679
- x: bb2.xMin + radius * entity.absoluteScale,
5680
- y: bb2.yMin + radius * entity.absoluteScale
5980
+ x: bb.xMin + radius * entity.absoluteScale,
5981
+ y: bb.yMin + radius * entity.absoluteScale
5681
5982
  };
5682
5983
  const distance = Math.sqrt(
5683
5984
  Math.pow(x - center.x, 2) + Math.pow(y - center.y, 2)
@@ -5690,30 +5991,10 @@ class Game {
5690
5991
  if (entity.type === EntityType.TextLine && isNaN(entity.size.width)) {
5691
5992
  return false;
5692
5993
  }
5693
- const bb = this.calculateEntityAbsoluteBoundingBox(entity);
5694
- if (entity.isUserInteractionEnabled && x >= bb.xMin && x <= bb.xMax && y >= bb.yMin && y <= bb.yMax) {
5695
- return true;
5696
- }
5697
- return false;
5698
- }
5699
- calculateEntityAbsoluteBoundingBox(entity) {
5700
- const anchorPoint = entity.anchorPoint;
5701
- const scale = entity.absoluteScale;
5702
- let width = entity.size.width;
5703
- let height = entity.size.height;
5704
- if (entity.type === EntityType.Shape && entity.shapeType === ShapeType.Circle) {
5705
- const radius = entity.circleOfRadius;
5706
- if (!radius) {
5707
- throw "circleOfRadius is undefined";
5708
- }
5709
- width = radius * 2;
5710
- height = radius * 2;
5711
- }
5712
- const xMin = entity.absolutePosition.x - width * anchorPoint.x * scale;
5713
- const xMax = entity.absolutePosition.x + width * (1 - anchorPoint.x) * scale;
5714
- const yMin = entity.absolutePosition.y - height * anchorPoint.y * scale;
5715
- const yMax = entity.absolutePosition.y + height * (1 - anchorPoint.y) * scale;
5716
- return { xMin, xMax, yMin, yMax };
5994
+ const points = M2c2KitHelpers.calculateRotatedPoints(
5995
+ entity
5996
+ );
5997
+ return entity.isUserInteractionEnabled && M2c2KitHelpers.isPointInsideRectangle({ x, y }, points);
5717
5998
  }
5718
5999
  prependAssetsGameIdUrl(url) {
5719
6000
  function hasUrlScheme(str) {
@@ -5738,25 +6019,14 @@ class RenderedDataUrlImage {
5738
6019
  }
5739
6020
  }
5740
6021
 
5741
- var __defProp$5 = Object.defineProperty;
5742
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5743
- var __publicField$5 = (obj, key, value) => {
5744
- __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
5745
- return value;
5746
- };
5747
6022
  class RenderedImages {
5748
6023
  }
5749
6024
  class LoadedImages {
5750
6025
  }
5751
6026
  class ImageManager {
5752
6027
  constructor(session) {
5753
- __publicField$5(this, "canvasKit");
5754
- __publicField$5(this, "renderedImages", new RenderedImages());
5755
- __publicField$5(this, "loadedImages", new LoadedImages());
5756
- __publicField$5(this, "_scratchCanvas");
5757
- __publicField$5(this, "ctx");
5758
- __publicField$5(this, "scale");
5759
- __publicField$5(this, "session");
6028
+ this.renderedImages = new RenderedImages();
6029
+ this.loadedImages = new LoadedImages();
5760
6030
  this.session = session;
5761
6031
  }
5762
6032
  /**
@@ -6030,10 +6300,9 @@ class ImageManager {
6030
6300
  return window.btoa(binary);
6031
6301
  }
6032
6302
  inferImageSubtypeFromUrl(url) {
6033
- var _a, _b;
6034
6303
  let subtype = "jpeg";
6035
- if (url == null ? void 0 : url.includes(".")) {
6036
- subtype = (_b = (_a = url.split(".").pop()) == null ? void 0 : _a.toLowerCase()) != null ? _b : "jpeg";
6304
+ if (url?.includes(".")) {
6305
+ subtype = url.split(".").pop()?.toLowerCase() ?? "jpeg";
6037
6306
  if (subtype === "") {
6038
6307
  subtype = "jpeg";
6039
6308
  }
@@ -6052,7 +6321,7 @@ class ImageManager {
6052
6321
  img = this.canvasKit.MakeImageFromEncoded(
6053
6322
  this.dataURLtoArrayBuffer(loadedDataUrlImage.dataUrlImage)
6054
6323
  );
6055
- } catch (e) {
6324
+ } catch {
6056
6325
  throw new Error(
6057
6326
  `could not create image with name "${loadedDataUrlImage.name}."`
6058
6327
  );
@@ -6104,9 +6373,8 @@ class ImageManager {
6104
6373
  return u8arr.buffer;
6105
6374
  }
6106
6375
  removeScratchCanvas() {
6107
- var _a;
6108
6376
  this.ctx = void 0;
6109
- (_a = this._scratchCanvas) == null ? void 0 : _a.remove();
6377
+ this._scratchCanvas?.remove();
6110
6378
  }
6111
6379
  }
6112
6380
 
@@ -6117,29 +6385,6 @@ var LabelHorizontalAlignmentMode = /* @__PURE__ */ ((LabelHorizontalAlignmentMod
6117
6385
  return LabelHorizontalAlignmentMode2;
6118
6386
  })(LabelHorizontalAlignmentMode || {});
6119
6387
 
6120
- var __defProp$4 = Object.defineProperty;
6121
- var __defProps$2 = Object.defineProperties;
6122
- var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
6123
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
6124
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
6125
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
6126
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6127
- var __spreadValues$3 = (a, b) => {
6128
- for (var prop in b || (b = {}))
6129
- if (__hasOwnProp$3.call(b, prop))
6130
- __defNormalProp$4(a, prop, b[prop]);
6131
- if (__getOwnPropSymbols$3)
6132
- for (var prop of __getOwnPropSymbols$3(b)) {
6133
- if (__propIsEnum$3.call(b, prop))
6134
- __defNormalProp$4(a, prop, b[prop]);
6135
- }
6136
- return a;
6137
- };
6138
- var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
6139
- var __publicField$4 = (obj, key, value) => {
6140
- __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
6141
- return value;
6142
- };
6143
6388
  class Label extends Entity {
6144
6389
  /**
6145
6390
  * Single or multi-line text formatted and rendered on the screen.
@@ -6150,36 +6395,22 @@ class Label extends Entity {
6150
6395
  */
6151
6396
  constructor(options = {}) {
6152
6397
  super(options);
6153
- __publicField$4(this, "type", EntityType.Label);
6154
- __publicField$4(this, "isDrawable", true);
6155
- __publicField$4(this, "isText", true);
6398
+ this.type = EntityType.Label;
6399
+ this.isDrawable = true;
6400
+ this.isText = true;
6156
6401
  // Drawable options
6157
- __publicField$4(this, "anchorPoint", { x: 0.5, y: 0.5 });
6158
- __publicField$4(this, "zPosition", 0);
6402
+ this.anchorPoint = { x: 0.5, y: 0.5 };
6403
+ this.zPosition = 0;
6159
6404
  // Text options
6160
- __publicField$4(this, "_text", "");
6161
- // public getter/setter is below
6162
- __publicField$4(this, "_fontName");
6163
- // public getter/setter is below
6164
- __publicField$4(this, "_fontNames");
6405
+ this._text = "";
6165
6406
  // public getter/setter is below
6166
- __publicField$4(this, "_fontColor", Constants.DEFAULT_FONT_COLOR);
6407
+ this._fontColor = Constants.DEFAULT_FONT_COLOR;
6167
6408
  // public getter/setter is below
6168
- __publicField$4(this, "_fontSize", Constants.DEFAULT_FONT_SIZE);
6409
+ this._fontSize = Constants.DEFAULT_FONT_SIZE;
6169
6410
  // public getter/setter is below
6170
6411
  // Label options
6171
- __publicField$4(this, "_horizontalAlignmentMode", LabelHorizontalAlignmentMode.Center);
6172
- // public getter/setter is below
6173
- __publicField$4(this, "_preferredMaxLayoutWidth");
6174
- // public getter/setter is below
6175
- __publicField$4(this, "_backgroundColor");
6176
- // public getter/setter is below
6177
- __publicField$4(this, "paragraph");
6178
- __publicField$4(this, "paraStyle");
6179
- __publicField$4(this, "builder");
6180
- __publicField$4(this, "_fontPaint");
6181
- __publicField$4(this, "_backgroundPaint");
6182
- __publicField$4(this, "_translatedText", "");
6412
+ this._horizontalAlignmentMode = LabelHorizontalAlignmentMode.Center;
6413
+ this._translatedText = "";
6183
6414
  handleInterfaceOptions(this, options);
6184
6415
  if (options.horizontalAlignmentMode) {
6185
6416
  this.horizontalAlignmentMode = options.horizontalAlignmentMode;
@@ -6195,7 +6426,6 @@ class Label extends Entity {
6195
6426
  }
6196
6427
  }
6197
6428
  initialize() {
6198
- var _a, _b, _c;
6199
6429
  let ckTextAlign = this.canvasKit.TextAlign.Center;
6200
6430
  switch (this.horizontalAlignmentMode) {
6201
6431
  case LabelHorizontalAlignmentMode.Center:
@@ -6347,7 +6577,7 @@ class Label extends Entity {
6347
6577
  this.paragraph = this.builder.build();
6348
6578
  const preferredWidth = (
6349
6579
  //this.preferredMaxLayoutWidth ?? this.parentScene.game.canvasCssWidth;
6350
- (_a = this.preferredMaxLayoutWidth) != null ? _a : Globals.canvasCssWidth
6580
+ this.preferredMaxLayoutWidth ?? Globals.canvasCssWidth
6351
6581
  );
6352
6582
  let calculatedWidth = preferredWidth;
6353
6583
  if (preferredWidth === 0 || this.layout.width === 0) {
@@ -6356,8 +6586,8 @@ class Label extends Entity {
6356
6586
  "width is set to match parent, but entity has no parent"
6357
6587
  );
6358
6588
  }
6359
- const marginStart = (_b = this.layout.marginStart) != null ? _b : 0;
6360
- const marginEnd = (_c = this.layout.marginEnd) != null ? _c : 0;
6589
+ const marginStart = this.layout.marginStart ?? 0;
6590
+ const marginEnd = this.layout.marginEnd ?? 0;
6361
6591
  calculatedWidth = this.parent.size.width - (marginStart + marginEnd);
6362
6592
  }
6363
6593
  this.paragraph.layout(calculatedWidth * Globals.canvasScale);
@@ -6468,12 +6698,15 @@ class Label extends Entity {
6468
6698
  * provided, name will be the new uuid
6469
6699
  */
6470
6700
  duplicate(newName) {
6471
- const dest = new Label(__spreadProps$2(__spreadValues$3(__spreadValues$3(__spreadValues$3({}, this.getEntityOptions()), this.getDrawableOptions()), this.getTextOptions()), {
6701
+ const dest = new Label({
6702
+ ...this.getEntityOptions(),
6703
+ ...this.getDrawableOptions(),
6704
+ ...this.getTextOptions(),
6472
6705
  horizontalAlignmentMode: this.horizontalAlignmentMode,
6473
6706
  preferredMaxLayoutWidth: this.preferredMaxLayoutWidth,
6474
6707
  backgroundColor: this.backgroundColor,
6475
6708
  name: newName
6476
- }));
6709
+ });
6477
6710
  if (this.children.length > 0) {
6478
6711
  dest.children = this.children.map((child) => {
6479
6712
  const clonedChild = child.duplicate();
@@ -6494,6 +6727,7 @@ class Label extends Entity {
6494
6727
  canvas.save();
6495
6728
  const drawScale = Globals.canvasScale / this.absoluteScale;
6496
6729
  canvas.scale(1 / drawScale, 1 / drawScale);
6730
+ M2c2KitHelpers.rotateCanvasForDrawableEntity(canvas, this);
6497
6731
  const x = (this.absolutePosition.x - this.size.width * this.anchorPoint.x * this.absoluteScale) * drawScale;
6498
6732
  const y = (this.absolutePosition.y - this.size.height * this.anchorPoint.y * this.absoluteScale) * drawScale;
6499
6733
  if (this.paragraph === void 0) {
@@ -6517,57 +6751,6 @@ class Label extends Entity {
6517
6751
  }
6518
6752
  }
6519
6753
 
6520
- var __defProp$3 = Object.defineProperty;
6521
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6522
- var __publicField$3 = (obj, key, value) => {
6523
- __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
6524
- return value;
6525
- };
6526
- class MutablePath {
6527
- constructor() {
6528
- __publicField$3(this, "size", { width: 0, height: 0 });
6529
- __publicField$3(this, "_subpaths", new Array());
6530
- __publicField$3(this, "currentPath", new Array());
6531
- }
6532
- get subpaths() {
6533
- if (this.currentPath.length > 0) {
6534
- return [...this._subpaths, this.currentPath];
6535
- } else {
6536
- return this._subpaths;
6537
- }
6538
- }
6539
- /**
6540
- * Starts a new subpath at a given point.
6541
- *
6542
- * @param point - location at which to start the new subpath
6543
- */
6544
- move(point) {
6545
- if (this.currentPath.length > 0) {
6546
- this._subpaths.push(this.currentPath);
6547
- }
6548
- this.currentPath = new Array();
6549
- this.currentPath.push(point);
6550
- }
6551
- /**
6552
- * Adds a straight line to the current subpath.
6553
- *
6554
- * @remarks The line is added from the last point in the current subpath to
6555
- * the given point.
6556
- *
6557
- * @param point - location where the line will end
6558
- */
6559
- addLine(point) {
6560
- this.currentPath.push(point);
6561
- }
6562
- clear() {
6563
- this._subpaths = new Array();
6564
- this.currentPath = new Array();
6565
- }
6566
- duplicate(newName) {
6567
- throw new Error("Method not implemented.");
6568
- }
6569
- }
6570
-
6571
6754
  class RandomDraws {
6572
6755
  /**
6573
6756
  * Draws a single random integer from a uniform distribution of integers in
@@ -6620,7 +6803,7 @@ class RandomDraws {
6620
6803
  * grid location to be along the diagonal, the predicate would be:
6621
6804
  * (row, column) => row === column
6622
6805
  * @returns Array of grid cells. Each cell is object in form of:
6623
- * \{ row: number, column: number \}. Grid cell locations are zero-based
6806
+ * &#123 row: number, column: number &#125;. Grid cell locations are zero-based
6624
6807
  */
6625
6808
  static FromGridWithoutReplacement(n, rows, columns, predicate) {
6626
6809
  const result = new Array();
@@ -6661,10 +6844,7 @@ function getAugmentedNamespace(n) {
6661
6844
  if (typeof f == "function") {
6662
6845
  var a = function a () {
6663
6846
  if (this instanceof a) {
6664
- var args = [null];
6665
- args.push.apply(args, arguments);
6666
- var Ctor = Function.bind.apply(f, args);
6667
- return new Ctor();
6847
+ return Reflect.construct(f, arguments, this.constructor);
6668
6848
  }
6669
6849
  return f.apply(this, arguments);
6670
6850
  };
@@ -7231,26 +7411,6 @@ var w;w||(w=typeof CanvasKitInit !== 'undefined' ? CanvasKitInit : {});var da,ea
7231
7411
  var canvaskitExports = canvaskit.exports;
7232
7412
  var CanvasKitInit = /*@__PURE__*/getDefaultExportFromCjs(canvaskitExports);
7233
7413
 
7234
- var __defProp$2 = Object.defineProperty;
7235
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
7236
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
7237
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
7238
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7239
- var __spreadValues$2 = (a, b) => {
7240
- for (var prop in b || (b = {}))
7241
- if (__hasOwnProp$2.call(b, prop))
7242
- __defNormalProp$2(a, prop, b[prop]);
7243
- if (__getOwnPropSymbols$2)
7244
- for (var prop of __getOwnPropSymbols$2(b)) {
7245
- if (__propIsEnum$2.call(b, prop))
7246
- __defNormalProp$2(a, prop, b[prop]);
7247
- }
7248
- return a;
7249
- };
7250
- var __publicField$2 = (obj, key, value) => {
7251
- __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
7252
- return value;
7253
- };
7254
7414
  class Session {
7255
7415
  /**
7256
7416
  * A Session contains one or more activities. The session manages the start
@@ -7259,17 +7419,10 @@ class Session {
7259
7419
  * @param options
7260
7420
  */
7261
7421
  constructor(options) {
7262
- __publicField$2(this, "options");
7263
- __publicField$2(this, "fontManager");
7264
- __publicField$2(this, "imageManager");
7265
- __publicField$2(this, "currentActivity");
7266
- __publicField$2(this, "uuid");
7267
- __publicField$2(this, "dataStores");
7268
- __publicField$2(this, "eventListeners", new Array());
7269
- __publicField$2(this, "sessionDictionary", /* @__PURE__ */ new Map());
7270
- __publicField$2(this, "canvasKit");
7271
- __publicField$2(this, "initialized", false);
7272
- __publicField$2(this, "version", "0.3.13 (f05b4c6d)");
7422
+ this.eventListeners = new Array();
7423
+ this.sessionDictionary = /* @__PURE__ */ new Map();
7424
+ this.initialized = false;
7425
+ this.version = "0.3.15 (38470c49)";
7273
7426
  this.options = options;
7274
7427
  for (const activity of this.options.activities) {
7275
7428
  if (this.options.activities.filter((a) => a === activity).length > 1) {
@@ -7343,9 +7496,9 @@ class Session {
7343
7496
  const eventListener = {
7344
7497
  type,
7345
7498
  callback,
7346
- key: options == null ? void 0 : options.key
7499
+ key: options?.key
7347
7500
  };
7348
- if (options == null ? void 0 : options.replaceExisting) {
7501
+ if (options?.replaceExisting) {
7349
7502
  this.eventListeners = this.eventListeners.filter(
7350
7503
  (listener) => !(listener.type === eventListener.type)
7351
7504
  );
@@ -7354,7 +7507,11 @@ class Session {
7354
7507
  }
7355
7508
  raiseEventOnListeners(event, extra) {
7356
7509
  if (extra) {
7357
- event = __spreadValues$2(__spreadValues$2({}, event), extra);
7510
+ event = {
7511
+ ...event,
7512
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7513
+ ...extra
7514
+ };
7358
7515
  }
7359
7516
  this.eventListeners.filter((listener) => listener.type === event.type).forEach((listener) => {
7360
7517
  listener.callback(event);
@@ -7430,13 +7587,12 @@ class Session {
7430
7587
  }
7431
7588
  const activityPrototype = Object.getPrototypeOf(activity);
7432
7589
  const gamePrototype = Object.getPrototypeOf(activityPrototype);
7433
- return (activityPrototype == null ? void 0 : activityPrototype.init) !== (gamePrototype == null ? void 0 : gamePrototype.init);
7590
+ return activityPrototype?.init !== gamePrototype?.init;
7434
7591
  }
7435
7592
  /**
7436
7593
  * Asynchronously initializes the m2c2kit engine and loads assets
7437
7594
  */
7438
7595
  async initialize() {
7439
- var _a;
7440
7596
  console.log(`\u26AA @m2c2kit/core version ${this.version}`);
7441
7597
  Timer.start("sessionInitialize");
7442
7598
  const sessionInitializeEvent = {
@@ -7448,7 +7604,7 @@ class Session {
7448
7604
  DomHelpers.setSpinnerVisibility(true);
7449
7605
  DomHelpers.setCanvasOverlayVisibility(true);
7450
7606
  this.dataStores = this.options.dataStores;
7451
- if (((_a = this.dataStores) == null ? void 0 : _a.length) === 0) {
7607
+ if (this.dataStores?.length === 0) {
7452
7608
  throw new Error(
7453
7609
  "Session.initialize(): dataStores must be undefined or a non-zero array of datastores."
7454
7610
  );
@@ -7737,9 +7893,8 @@ class Session {
7737
7893
  }
7738
7894
  getImagesConfigurationFromGames() {
7739
7895
  return this.options.activities.filter((activity) => activity.type == ActivityType.Game).map((activity) => {
7740
- var _a;
7741
7896
  const game = activity;
7742
- return { uuid: game.uuid, images: (_a = game.options.images) != null ? _a : [] };
7897
+ return { uuid: game.uuid, images: game.options.images ?? [] };
7743
7898
  });
7744
7899
  }
7745
7900
  prependAssetsUrl(url) {
@@ -7756,29 +7911,6 @@ class Session {
7756
7911
  }
7757
7912
  }
7758
7913
 
7759
- var __defProp$1 = Object.defineProperty;
7760
- var __defProps$1 = Object.defineProperties;
7761
- var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
7762
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
7763
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
7764
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
7765
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7766
- var __spreadValues$1 = (a, b) => {
7767
- for (var prop in b || (b = {}))
7768
- if (__hasOwnProp$1.call(b, prop))
7769
- __defNormalProp$1(a, prop, b[prop]);
7770
- if (__getOwnPropSymbols$1)
7771
- for (var prop of __getOwnPropSymbols$1(b)) {
7772
- if (__propIsEnum$1.call(b, prop))
7773
- __defNormalProp$1(a, prop, b[prop]);
7774
- }
7775
- return a;
7776
- };
7777
- var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
7778
- var __publicField$1 = (obj, key, value) => {
7779
- __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
7780
- return value;
7781
- };
7782
7914
  class Shape extends Entity {
7783
7915
  /**
7784
7916
  * Rectangular, circular, or path-based shape
@@ -7787,45 +7919,41 @@ class Shape extends Entity {
7787
7919
  */
7788
7920
  constructor(options = {}) {
7789
7921
  super(options);
7790
- __publicField$1(this, "type", EntityType.Shape);
7791
- __publicField$1(this, "isDrawable", true);
7792
- __publicField$1(this, "isShape", true);
7922
+ this.type = EntityType.Shape;
7923
+ this.isDrawable = true;
7924
+ this.isShape = true;
7793
7925
  // Drawable options
7794
- __publicField$1(this, "anchorPoint", { x: 0.5, y: 0.5 });
7795
- __publicField$1(this, "zPosition", 0);
7926
+ this.anchorPoint = { x: 0.5, y: 0.5 };
7927
+ this.zPosition = 0;
7796
7928
  // Shape options
7797
7929
  // TODO: fix the Size issue; should be readonly (calculated value) in all entities, but Rectangle
7798
- __publicField$1(this, "shapeType", ShapeType.Undefined);
7799
- __publicField$1(this, "circleOfRadius");
7800
- __publicField$1(this, "rect");
7801
- __publicField$1(this, "path");
7802
- __publicField$1(this, "ckPath", null);
7803
- __publicField$1(this, "ckPathWidth");
7804
- __publicField$1(this, "ckPathHeight");
7805
- __publicField$1(this, "cornerRadius", 0);
7806
- __publicField$1(this, "_fillColor", Constants.DEFAULT_SHAPE_FILL_COLOR);
7807
- __publicField$1(this, "_strokeColor");
7808
- __publicField$1(this, "lineWidth");
7809
- __publicField$1(this, "_isAntialiased", true);
7810
- __publicField$1(this, "_fillColorPaintAntialiased");
7811
- __publicField$1(this, "_strokeColorPaintAntialiased");
7812
- __publicField$1(this, "_fillColorPaintNotAntialiased");
7813
- __publicField$1(this, "_strokeColorPaintNotAntialiased");
7814
- __publicField$1(this, "svgPathRequestedWidth");
7815
- __publicField$1(this, "svgPathRequestedHeight");
7816
- __publicField$1(this, "svgPathScaleForResizing", 1);
7817
- __publicField$1(this, "svgPathWidth", 0);
7818
- __publicField$1(this, "svgPathHeight", 0);
7819
- __publicField$1(this, "svgPreviousAbsoluteX", NaN);
7820
- __publicField$1(this, "svgPreviousAbsoluteY", NaN);
7821
- __publicField$1(this, "svgFirstPathDraw", true);
7930
+ this.shapeType = ShapeType.Undefined;
7931
+ this.ckPath = null;
7932
+ this.cornerRadius = 0;
7933
+ this._fillColor = Constants.DEFAULT_SHAPE_FILL_COLOR;
7934
+ this._isAntialiased = true;
7935
+ this.svgPathScaleForResizing = 1;
7936
+ this.svgPathWidth = 0;
7937
+ this.svgPathHeight = 0;
7938
+ this.svgPreviousAbsoluteX = NaN;
7939
+ this.svgPreviousAbsoluteY = NaN;
7940
+ this.svgFirstPathDraw = true;
7941
+ this.colorfulPathPaints = /* @__PURE__ */ new Map();
7822
7942
  handleInterfaceOptions(this, options);
7823
7943
  if (options.path !== void 0) {
7824
7944
  this.path = options.path;
7825
7945
  this.shapeType = ShapeType.Path;
7826
- if (this.path.size !== void 0) {
7827
- this.size.height = this.path.size.height;
7828
- this.size.width = this.path.size.width;
7946
+ if (this.shapeIsM2Path()) {
7947
+ if (options.size !== void 0) {
7948
+ this.size = options.size;
7949
+ }
7950
+ }
7951
+ if (this.shapeIsSvgStringPath()) {
7952
+ if (options.size !== void 0) {
7953
+ throw new Error(
7954
+ "Size cannot be specified when path is SVG string path"
7955
+ );
7956
+ }
7829
7957
  }
7830
7958
  this.svgPathRequestedWidth = options.path.width;
7831
7959
  this.svgPathRequestedHeight = options.path.height;
@@ -7906,11 +8034,16 @@ class Shape extends Entity {
7906
8034
  initialize() {
7907
8035
  if (this.shapeType === ShapeType.Path) {
7908
8036
  if (this.shapeIsSvgStringPath()) {
7909
- const pathSvgString = this.path.svgPathString;
7910
- if (!pathSvgString) {
8037
+ const pathString = this.path.pathString ?? this.path.svgPathString;
8038
+ if (!pathString) {
7911
8039
  throw new Error("SVG Path string is null/undefined");
7912
8040
  }
7913
- this.ckPath = this.canvasKit.Path.MakeFromSVGString(pathSvgString);
8041
+ if (this.path.svgPathString !== void 0) {
8042
+ console.warn(
8043
+ `warning: svgPathString is deprecated. Use pathString instead.`
8044
+ );
8045
+ }
8046
+ this.ckPath = this.canvasKit.Path.MakeFromSVGString(pathString);
7914
8047
  if (!this.ckPath) {
7915
8048
  throw new Error("could not make CanvasKit Path from SVG string");
7916
8049
  }
@@ -7928,6 +8061,13 @@ class Shape extends Entity {
7928
8061
  this.svgPreviousAbsoluteY = 0;
7929
8062
  }
7930
8063
  }
8064
+ if (this.shapeIsM2Path()) {
8065
+ if (this.size.width === 0 || this.size.height === 0 || this.size.width === void 0 || this.size.height === void 0) {
8066
+ throw new Error(
8067
+ "Size of shape must have non-zero height and width when path is M2Path"
8068
+ );
8069
+ }
8070
+ }
7931
8071
  if (this.fillColor) {
7932
8072
  this.fillColorPaintAntialiased = CanvasKitHelpers.makePaint(
7933
8073
  this.canvasKit,
@@ -7966,7 +8106,8 @@ class Shape extends Entity {
7966
8106
  this._strokeColorPaintNotAntialiased,
7967
8107
  this._fillColorPaintAntialiased,
7968
8108
  this._fillColorPaintNotAntialiased,
7969
- this.ckPath
8109
+ this.ckPath,
8110
+ ...Array.from(this.colorfulPathPaints.values())
7970
8111
  ]);
7971
8112
  }
7972
8113
  /**
@@ -7980,7 +8121,9 @@ class Shape extends Entity {
7980
8121
  * provided, name will be the new uuid
7981
8122
  */
7982
8123
  duplicate(newName) {
7983
- const dest = new Shape(__spreadProps$1(__spreadValues$1(__spreadValues$1({}, this.getEntityOptions()), this.getDrawableOptions()), {
8124
+ const dest = new Shape({
8125
+ ...this.getEntityOptions(),
8126
+ ...this.getDrawableOptions(),
7984
8127
  shapeType: this.shapeType,
7985
8128
  circleOfRadius: this.circleOfRadius,
7986
8129
  rect: this.rect,
@@ -7989,7 +8132,7 @@ class Shape extends Entity {
7989
8132
  strokeColor: this.strokeColor,
7990
8133
  lineWidth: this.lineWidth,
7991
8134
  name: newName
7992
- }));
8135
+ });
7993
8136
  if (this.children.length > 0) {
7994
8137
  dest.children = this.children.map((child) => {
7995
8138
  const clonedChild = child.duplicate();
@@ -8006,6 +8149,7 @@ class Shape extends Entity {
8006
8149
  canvas.save();
8007
8150
  const drawScale = Globals.canvasScale / this.absoluteScale;
8008
8151
  canvas.scale(1 / drawScale, 1 / drawScale);
8152
+ M2c2KitHelpers.rotateCanvasForDrawableEntity(canvas, this);
8009
8153
  if (this.absoluteAlphaChange !== 0) {
8010
8154
  this.applyAlphaToPaints(this.absoluteAlpha, [
8011
8155
  this._fillColorPaintAntialiased,
@@ -8040,8 +8184,52 @@ class Shape extends Entity {
8040
8184
  const drawScale = Globals.canvasScale / this.absoluteScale;
8041
8185
  const pathOriginX = (this.absolutePosition.x - this.anchorPoint.x * this.size.width * this.absoluteScale) * drawScale;
8042
8186
  const pathOriginY = (this.absolutePosition.y - this.anchorPoint.y * this.size.height * this.absoluteScale) * drawScale;
8187
+ if (this.pathIsM2ColorfulPath(this.path)) {
8188
+ const linePresentations = this.path.linePresentations;
8189
+ let lp = 0;
8190
+ const subpaths = this.path.subpaths;
8191
+ let paint;
8192
+ for (let s = 0; s < subpaths.length; s++) {
8193
+ const subpath = subpaths[s];
8194
+ const points = subpath.flat();
8195
+ for (let i = 0; i < points.length - 1; i++) {
8196
+ if (linePresentations[lp].subpathIndex === s && linePresentations[lp].pointIndex === i) {
8197
+ const strokeColor = linePresentations[lp].strokeColor;
8198
+ const lineWidth = linePresentations[lp].lineWidth;
8199
+ const paintKey = [...strokeColor, lineWidth].toString();
8200
+ paint = this.colorfulPathPaints.get(paintKey);
8201
+ if (paint === void 0) {
8202
+ paint = CanvasKitHelpers.makePaint(
8203
+ this.canvasKit,
8204
+ strokeColor,
8205
+ this.canvasKit.PaintStyle.Stroke,
8206
+ true
8207
+ );
8208
+ paint.setStrokeWidth(lineWidth * Globals.canvasScale);
8209
+ this.colorfulPathPaints.set(paintKey, paint);
8210
+ }
8211
+ if (lp < linePresentations.length - 1) {
8212
+ lp++;
8213
+ }
8214
+ }
8215
+ if (paint === void 0) {
8216
+ throw new Error("paint is undefined");
8217
+ }
8218
+ canvas.drawLine(
8219
+ pathOriginX + points[i].x * Globals.canvasScale,
8220
+ pathOriginY + points[i].y * Globals.canvasScale,
8221
+ pathOriginX + points[i + 1].x * Globals.canvasScale,
8222
+ pathOriginY + points[i + 1].y * Globals.canvasScale,
8223
+ paint
8224
+ );
8225
+ }
8226
+ }
8227
+ return;
8228
+ }
8043
8229
  if (this.strokeColor && this.strokeColorPaintAntialiased && this.lineWidth) {
8044
- this.strokeColorPaintAntialiased.setStrokeWidth(this.lineWidth);
8230
+ this.strokeColorPaintAntialiased.setStrokeWidth(
8231
+ this.lineWidth * Globals.canvasScale
8232
+ );
8045
8233
  const subpaths = this.path.subpaths;
8046
8234
  for (const subpath of subpaths) {
8047
8235
  const points = subpath.flat();
@@ -8107,12 +8295,13 @@ class Shape extends Entity {
8107
8295
  return this.svgFirstPathDraw === true || x !== this.svgPreviousAbsoluteX || y !== this.svgPreviousAbsoluteY;
8108
8296
  }
8109
8297
  shapeIsSvgStringPath() {
8110
- var _a;
8111
- return ((_a = this.path) == null ? void 0 : _a.svgPathString) !== void 0;
8298
+ return this.path?.pathString !== void 0 || this.path?.svgPathString !== void 0;
8112
8299
  }
8113
8300
  shapeIsM2Path() {
8114
- var _a;
8115
- return ((_a = this.path) == null ? void 0 : _a.subpaths) !== void 0;
8301
+ return this.path?.subpaths !== void 0;
8302
+ }
8303
+ pathIsM2ColorfulPath(path) {
8304
+ return path !== void 0 && "linePresentations" in path;
8116
8305
  }
8117
8306
  drawCircle(canvas) {
8118
8307
  if (!this.circleOfRadius) {
@@ -8314,29 +8503,6 @@ class Story {
8314
8503
  }
8315
8504
  }
8316
8505
 
8317
- var __defProp = Object.defineProperty;
8318
- var __defProps = Object.defineProperties;
8319
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
8320
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8321
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8322
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
8323
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8324
- var __spreadValues = (a, b) => {
8325
- for (var prop in b || (b = {}))
8326
- if (__hasOwnProp.call(b, prop))
8327
- __defNormalProp(a, prop, b[prop]);
8328
- if (__getOwnPropSymbols)
8329
- for (var prop of __getOwnPropSymbols(b)) {
8330
- if (__propIsEnum.call(b, prop))
8331
- __defNormalProp(a, prop, b[prop]);
8332
- }
8333
- return a;
8334
- };
8335
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
8336
- var __publicField = (obj, key, value) => {
8337
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8338
- return value;
8339
- };
8340
8506
  class TextLine extends Entity {
8341
8507
  /**
8342
8508
  * Single-line text rendered on the screen.
@@ -8346,33 +8512,26 @@ class TextLine extends Entity {
8346
8512
  * @param options - {@link TextLineOptions}
8347
8513
  */
8348
8514
  constructor(options = {}) {
8349
- var _a;
8350
8515
  super(options);
8351
- __publicField(this, "type", EntityType.TextLine);
8352
- __publicField(this, "isDrawable", true);
8353
- __publicField(this, "isText", true);
8516
+ this.type = EntityType.TextLine;
8517
+ this.isDrawable = true;
8518
+ this.isText = true;
8354
8519
  // Drawable options
8355
- __publicField(this, "zPosition", 0);
8520
+ this.zPosition = 0;
8356
8521
  // We don't know TextLine width in advance, so we must text align left,
8357
8522
  // and so anchorPoint is (0, .5). (we do know height, which is fontSize)
8358
- __publicField(this, "anchorPoint", { x: 0, y: 0.5 });
8523
+ this.anchorPoint = { x: 0, y: 0.5 };
8359
8524
  // Text options
8360
- __publicField(this, "_text", "");
8361
- // public getter/setter is below
8362
- __publicField(this, "_fontName");
8525
+ this._text = "";
8363
8526
  // public getter/setter is below
8364
- __publicField(this, "_fontColor", Constants.DEFAULT_FONT_COLOR);
8527
+ this._fontColor = Constants.DEFAULT_FONT_COLOR;
8365
8528
  // public getter/setter is below
8366
- __publicField(this, "_fontSize", Constants.DEFAULT_FONT_SIZE);
8367
- // public getter/setter is below
8368
- __publicField(this, "paint");
8369
- __publicField(this, "font");
8370
- __publicField(this, "typeface", null);
8371
- __publicField(this, "_translatedText", "");
8372
- __publicField(this, "missingTranslationPaint");
8529
+ this._fontSize = Constants.DEFAULT_FONT_SIZE;
8530
+ this.typeface = null;
8531
+ this._translatedText = "";
8373
8532
  handleInterfaceOptions(this, options);
8374
8533
  this.size.height = this.fontSize;
8375
- this.size.width = (_a = options.width) != null ? _a : NaN;
8534
+ this.size.width = options.width ?? NaN;
8376
8535
  }
8377
8536
  get text() {
8378
8537
  return this._text;
@@ -8474,10 +8633,13 @@ class TextLine extends Entity {
8474
8633
  * provided, name will be the new uuid
8475
8634
  */
8476
8635
  duplicate(newName) {
8477
- const dest = new TextLine(__spreadProps(__spreadValues(__spreadValues(__spreadValues({}, this.getEntityOptions()), this.getDrawableOptions()), this.getTextOptions()), {
8636
+ const dest = new TextLine({
8637
+ ...this.getEntityOptions(),
8638
+ ...this.getDrawableOptions(),
8639
+ ...this.getTextOptions(),
8478
8640
  width: this.size.width,
8479
8641
  name: newName
8480
- }));
8642
+ });
8481
8643
  if (this.children.length > 0) {
8482
8644
  dest.children = this.children.map((child) => {
8483
8645
  const clonedChild = child.duplicate();
@@ -8492,6 +8654,7 @@ class TextLine extends Entity {
8492
8654
  canvas.save();
8493
8655
  const drawScale = Globals.canvasScale / this.absoluteScale;
8494
8656
  canvas.scale(1 / drawScale, 1 / drawScale);
8657
+ M2c2KitHelpers.rotateCanvasForDrawableEntity(canvas, this);
8495
8658
  const x = this.absolutePosition.x * drawScale;
8496
8659
  const y = (this.absolutePosition.y + this.size.height * this.anchorPoint.y * this.absoluteScale) * drawScale;
8497
8660
  let textForDraw;
@@ -8548,5 +8711,5 @@ class TextLine extends Entity {
8548
8711
  }
8549
8712
  }
8550
8713
 
8551
- export { Action, ActivityType, CanvasKitHelpers, Composite, Constants, ConstraintType, CustomAction, Dimensions, Easings, Entity, EntityType, Equals, EventType, FadeAlphaAction, FontManager, Game, GlobalVariables, GroupAction, I18n, ImageManager, Label, LabelHorizontalAlignmentMode, LayoutConstraint, LoadedImage, MoveAction, MutablePath, NoneTransition, RandomDraws, ScaleAction, Scene, SceneTransition, SequenceAction, Session, Shape, ShapeType, SlideTransition, Sprite, Story, TextLine, Timer, Transition, TransitionDirection, TransitionType, Uuid, WaitAction, WebColors, WebGlInfo, handleInterfaceOptions };
8714
+ export { Action, ActivityType, CanvasKitHelpers, ColorfulMutablePath, Composite, Constants, ConstraintType, CustomAction, Dimensions, Easings, Entity, EntityType, Equals, EventType, FadeAlphaAction, FontManager, Game, GlobalVariables, GroupAction, I18n, ImageManager, Label, LabelHorizontalAlignmentMode, LayoutConstraint, LoadedImage, MoveAction, MutablePath, NoneTransition, RandomDraws, RotateAction, ScaleAction, Scene, SceneTransition, SequenceAction, Session, Shape, ShapeType, SlideTransition, Sprite, Story, TextLine, Timer, Transition, TransitionDirection, TransitionType, Uuid, WaitAction, WebColors, WebGlInfo, handleInterfaceOptions };
8552
8715
  //# sourceMappingURL=index.js.map