@vpmedia/phaser 1.116.0 → 1.118.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/dist/index.js +195 -229
  2. package/dist/index.js.map +1 -1
  3. package/dist/phaser/core/animation.d.ts.map +1 -1
  4. package/dist/phaser/core/animation_manager.d.ts +16 -15
  5. package/dist/phaser/core/animation_manager.d.ts.map +1 -1
  6. package/dist/phaser/core/animation_parser.d.ts.map +1 -1
  7. package/dist/phaser/core/array_set.d.ts.map +1 -1
  8. package/dist/phaser/core/cache.d.ts +76 -47
  9. package/dist/phaser/core/cache.d.ts.map +1 -1
  10. package/dist/phaser/core/device_util.d.ts.map +1 -1
  11. package/dist/phaser/core/dom.d.ts.map +1 -1
  12. package/dist/phaser/core/factory.d.ts.map +1 -1
  13. package/dist/phaser/core/game.d.ts.map +1 -1
  14. package/dist/phaser/core/input.d.ts +17 -17
  15. package/dist/phaser/core/input.d.ts.map +1 -1
  16. package/dist/phaser/core/input_handler.d.ts +11 -13
  17. package/dist/phaser/core/input_handler.d.ts.map +1 -1
  18. package/dist/phaser/core/input_mouse.d.ts.map +1 -1
  19. package/dist/phaser/core/input_mspointer.d.ts +8 -7
  20. package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
  21. package/dist/phaser/core/input_pointer.d.ts +19 -8
  22. package/dist/phaser/core/input_pointer.d.ts.map +1 -1
  23. package/dist/phaser/core/input_touch.d.ts.map +1 -1
  24. package/dist/phaser/core/loader.d.ts +30 -1
  25. package/dist/phaser/core/loader.d.ts.map +1 -1
  26. package/dist/phaser/core/loader_parser.d.ts +24 -4
  27. package/dist/phaser/core/loader_parser.d.ts.map +1 -1
  28. package/dist/phaser/core/raf.d.ts.map +1 -1
  29. package/dist/phaser/core/scale_manager.d.ts +37 -12
  30. package/dist/phaser/core/scale_manager.d.ts.map +1 -1
  31. package/dist/phaser/core/scene.d.ts.map +1 -1
  32. package/dist/phaser/core/scene_manager.d.ts.map +1 -1
  33. package/dist/phaser/core/signal.d.ts.map +1 -1
  34. package/dist/phaser/core/signal_binding.d.ts.map +1 -1
  35. package/dist/phaser/core/sound.d.ts +15 -5
  36. package/dist/phaser/core/sound.d.ts.map +1 -1
  37. package/dist/phaser/core/sound_manager.d.ts +24 -22
  38. package/dist/phaser/core/sound_manager.d.ts.map +1 -1
  39. package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
  40. package/dist/phaser/core/stage.d.ts.map +1 -1
  41. package/dist/phaser/core/time.d.ts.map +1 -1
  42. package/dist/phaser/core/timer.d.ts +1 -1
  43. package/dist/phaser/core/timer.d.ts.map +1 -1
  44. package/dist/phaser/core/tween.d.ts +3 -3
  45. package/dist/phaser/core/tween.d.ts.map +1 -1
  46. package/dist/phaser/core/tween_data.d.ts +26 -26
  47. package/dist/phaser/core/tween_data.d.ts.map +1 -1
  48. package/dist/phaser/core/tween_manager.d.ts +8 -6
  49. package/dist/phaser/core/tween_manager.d.ts.map +1 -1
  50. package/dist/phaser/core/world.d.ts.map +1 -1
  51. package/dist/phaser/display/bitmap_text.d.ts +13 -8
  52. package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
  53. package/dist/phaser/display/button.d.ts.map +1 -1
  54. package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
  55. package/dist/phaser/display/canvas/graphics.d.ts.map +1 -1
  56. package/dist/phaser/display/canvas/masker.d.ts.map +1 -1
  57. package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
  58. package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
  59. package/dist/phaser/display/canvas/tinter.d.ts +3 -2
  60. package/dist/phaser/display/canvas/tinter.d.ts.map +1 -1
  61. package/dist/phaser/display/canvas/util.d.ts.map +1 -1
  62. package/dist/phaser/display/display_object.d.ts.map +1 -1
  63. package/dist/phaser/display/graphics.d.ts.map +1 -1
  64. package/dist/phaser/display/graphics_data.d.ts.map +1 -1
  65. package/dist/phaser/display/graphics_data_util.d.ts.map +1 -1
  66. package/dist/phaser/display/group.d.ts.map +1 -1
  67. package/dist/phaser/display/image.d.ts +2 -2
  68. package/dist/phaser/display/image.d.ts.map +1 -1
  69. package/dist/phaser/display/sprite_util.d.ts.map +1 -1
  70. package/dist/phaser/display/text.d.ts.map +1 -1
  71. package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
  72. package/dist/phaser/display/webgl/base_texture.d.ts +12 -10
  73. package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
  74. package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
  75. package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
  76. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +13 -12
  77. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
  78. package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
  79. package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
  80. package/dist/phaser/display/webgl/graphics.d.ts +9 -7
  81. package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
  82. package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
  83. package/dist/phaser/display/webgl/mask_manager.d.ts.map +1 -1
  84. package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
  85. package/dist/phaser/display/webgl/renderer.d.ts +12 -10
  86. package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
  87. package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
  88. package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
  89. package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
  90. package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
  91. package/dist/phaser/display/webgl/texture.d.ts +18 -33
  92. package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
  93. package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
  94. package/dist/phaser/display/webgl/util.d.ts.map +1 -1
  95. package/dist/phaser/geom/circle.d.ts.map +1 -1
  96. package/dist/phaser/geom/ellipse.d.ts.map +1 -1
  97. package/dist/phaser/geom/line.d.ts.map +1 -1
  98. package/dist/phaser/geom/matrix.d.ts +1 -1
  99. package/dist/phaser/geom/matrix.d.ts.map +1 -1
  100. package/dist/phaser/geom/point.d.ts.map +1 -1
  101. package/dist/phaser/geom/polygon.d.ts.map +1 -1
  102. package/dist/phaser/geom/rectangle.d.ts.map +1 -1
  103. package/dist/phaser/geom/rounded_rectangle.d.ts.map +1 -1
  104. package/dist/phaser/geom/util/circle.d.ts.map +1 -1
  105. package/dist/phaser/geom/util/ellipse.d.ts.map +1 -1
  106. package/dist/phaser/geom/util/line.d.ts +5 -4
  107. package/dist/phaser/geom/util/line.d.ts.map +1 -1
  108. package/dist/phaser/geom/util/matrix.d.ts.map +1 -1
  109. package/dist/phaser/geom/util/point.d.ts.map +1 -1
  110. package/dist/phaser/geom/util/polygon.d.ts.map +1 -1
  111. package/dist/phaser/geom/util/rectangle.d.ts +10 -1
  112. package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
  113. package/dist/phaser/geom/util/rounded_rectangle.d.ts.map +1 -1
  114. package/package.json +1 -1
  115. package/src/phaser/core/animation.ts +20 -20
  116. package/src/phaser/core/animation_manager.ts +27 -24
  117. package/src/phaser/core/animation_parser.ts +2 -2
  118. package/src/phaser/core/array_set.ts +7 -7
  119. package/src/phaser/core/cache.test.ts +201 -0
  120. package/src/phaser/core/cache.ts +174 -130
  121. package/src/phaser/core/device_util.ts +13 -13
  122. package/src/phaser/core/dom.ts +26 -22
  123. package/src/phaser/core/factory.ts +6 -6
  124. package/src/phaser/core/game.ts +10 -10
  125. package/src/phaser/core/input.ts +36 -38
  126. package/src/phaser/core/input_handler.ts +90 -93
  127. package/src/phaser/core/input_mouse.ts +19 -19
  128. package/src/phaser/core/input_mspointer.ts +25 -28
  129. package/src/phaser/core/input_pointer.ts +37 -28
  130. package/src/phaser/core/input_touch.ts +17 -17
  131. package/src/phaser/core/loader.ts +132 -92
  132. package/src/phaser/core/loader_parser.test.ts +115 -0
  133. package/src/phaser/core/loader_parser.ts +66 -38
  134. package/src/phaser/core/raf.ts +3 -3
  135. package/src/phaser/core/scale_manager.ts +86 -67
  136. package/src/phaser/core/scene.ts +7 -7
  137. package/src/phaser/core/scene_manager.ts +16 -16
  138. package/src/phaser/core/signal.ts +29 -19
  139. package/src/phaser/core/signal_binding.ts +4 -4
  140. package/src/phaser/core/sound.ts +45 -33
  141. package/src/phaser/core/sound_manager.ts +72 -73
  142. package/src/phaser/core/sound_sprite.ts +1 -1
  143. package/src/phaser/core/stage.ts +7 -7
  144. package/src/phaser/core/time.ts +16 -16
  145. package/src/phaser/core/timer.ts +36 -26
  146. package/src/phaser/core/tween.ts +29 -29
  147. package/src/phaser/core/tween_data.ts +41 -37
  148. package/src/phaser/core/tween_manager.ts +50 -43
  149. package/src/phaser/core/world.ts +1 -1
  150. package/src/phaser/display/bitmap_text.test.ts +212 -0
  151. package/src/phaser/display/bitmap_text.ts +52 -37
  152. package/src/phaser/display/button.ts +13 -13
  153. package/src/phaser/display/canvas/buffer.ts +3 -3
  154. package/src/phaser/display/canvas/graphics.ts +3 -3
  155. package/src/phaser/display/canvas/masker.ts +2 -2
  156. package/src/phaser/display/canvas/pool.ts +6 -6
  157. package/src/phaser/display/canvas/renderer.ts +6 -6
  158. package/src/phaser/display/canvas/tinter.ts +39 -8
  159. package/src/phaser/display/canvas/util.ts +15 -9
  160. package/src/phaser/display/display_object.ts +38 -38
  161. package/src/phaser/display/graphics.ts +30 -30
  162. package/src/phaser/display/graphics_data.ts +1 -1
  163. package/src/phaser/display/graphics_data_util.ts +1 -1
  164. package/src/phaser/display/group.ts +16 -16
  165. package/src/phaser/display/image.ts +30 -26
  166. package/src/phaser/display/sprite_util.ts +12 -4
  167. package/src/phaser/display/text.ts +55 -55
  168. package/src/phaser/display/webgl/abstract_filter.ts +1 -1
  169. package/src/phaser/display/webgl/base_texture.ts +22 -18
  170. package/src/phaser/display/webgl/blend_manager.ts +3 -3
  171. package/src/phaser/display/webgl/earcut.ts +3 -3
  172. package/src/phaser/display/webgl/fast_sprite_batch.ts +26 -24
  173. package/src/phaser/display/webgl/filter_manager.ts +7 -7
  174. package/src/phaser/display/webgl/filter_texture.ts +3 -3
  175. package/src/phaser/display/webgl/graphics.ts +43 -41
  176. package/src/phaser/display/webgl/graphics_data.ts +2 -2
  177. package/src/phaser/display/webgl/mask_manager.ts +2 -2
  178. package/src/phaser/display/webgl/render_texture.ts +6 -6
  179. package/src/phaser/display/webgl/renderer.ts +20 -25
  180. package/src/phaser/display/webgl/shader/normal.ts +3 -3
  181. package/src/phaser/display/webgl/shader_manager.ts +2 -2
  182. package/src/phaser/display/webgl/sprite_batch.ts +9 -9
  183. package/src/phaser/display/webgl/stencil_manager.ts +4 -4
  184. package/src/phaser/display/webgl/texture.ts +23 -42
  185. package/src/phaser/display/webgl/texture_util.ts +2 -2
  186. package/src/phaser/display/webgl/util.ts +11 -7
  187. package/src/phaser/geom/circle.ts +21 -21
  188. package/src/phaser/geom/ellipse.ts +7 -7
  189. package/src/phaser/geom/line.ts +29 -29
  190. package/src/phaser/geom/matrix.ts +13 -13
  191. package/src/phaser/geom/point.ts +36 -30
  192. package/src/phaser/geom/polygon.ts +6 -6
  193. package/src/phaser/geom/rectangle.ts +42 -42
  194. package/src/phaser/geom/rounded_rectangle.ts +2 -2
  195. package/src/phaser/geom/util/circle.ts +7 -7
  196. package/src/phaser/geom/util/ellipse.ts +1 -1
  197. package/src/phaser/geom/util/line.ts +13 -5
  198. package/src/phaser/geom/util/matrix.ts +3 -3
  199. package/src/phaser/geom/util/point.ts +20 -20
  200. package/src/phaser/geom/util/polygon.ts +1 -1
  201. package/src/phaser/geom/util/rectangle.ts +34 -17
  202. package/src/phaser/geom/util/rounded_rectangle.ts +1 -1
package/dist/index.js CHANGED
@@ -767,12 +767,6 @@ const containsRect = (a, b) => {
767
767
  * @returns {boolean} True if the rectangles are equal, false otherwise.
768
768
  */
769
769
  const equals$1 = (a, b) => a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
770
- /**
771
- * Checks if two rectangles intersect.
772
- * @param {Rectangle} a - The first rectangle to check.
773
- * @param {Rectangle} b - The second rectangle to check.
774
- * @returns {boolean} True if the rectangles intersect, false otherwise.
775
- */
776
770
  const intersects$1 = (a, b) => {
777
771
  if (a.width <= 0 || a.height <= 0 || b.width <= 0 || b.height <= 0) return false;
778
772
  return !(a.right < b.x || a.bottom < b.y || a.x > b.right || a.y > b.bottom);
@@ -3426,7 +3420,6 @@ var AnimationManager = class {
3426
3420
  this._frameData = null;
3427
3421
  this.currentAnim = null;
3428
3422
  this.currentFrame = null;
3429
- this.sprite = null;
3430
3423
  }
3431
3424
  /**
3432
3425
  * Loads frame data into the AnimationManager.
@@ -3488,9 +3481,12 @@ var AnimationManager = class {
3488
3481
  * @returns {boolean} True if all frames are valid, false otherwise.
3489
3482
  */
3490
3483
  validateFrames(frames, useNumericIndex = false) {
3491
- for (let i = 0; i < frames.length; i += 1) if (useNumericIndex) {
3492
- if (frames[i] > this._frameData.total) return false;
3493
- } else if (this._frameData.checkFrameName(frames[i]) === false) return false;
3484
+ for (let i = 0; i < frames.length; i += 1) {
3485
+ const frame = frames[i];
3486
+ if (useNumericIndex) {
3487
+ if (Number(frame) > this._frameData.total) return false;
3488
+ } else if (!this._frameData.checkFrameName(String(frame))) return false;
3489
+ }
3494
3490
  return true;
3495
3491
  }
3496
3492
  /**
@@ -3503,7 +3499,7 @@ var AnimationManager = class {
3503
3499
  play(name, frameRate = null, loop = null) {
3504
3500
  if (this._anims[name]) {
3505
3501
  if (this.currentAnim === this._anims[name]) {
3506
- if (this.currentAnim.isPlaying === false) {
3502
+ if (!this.currentAnim.isPlaying) {
3507
3503
  this.currentAnim.paused = false;
3508
3504
  return this.currentAnim.play(frameRate, loop);
3509
3505
  }
@@ -3591,13 +3587,13 @@ var AnimationManager = class {
3591
3587
  * @returns {boolean} True if the current animation is paused, false otherwise.
3592
3588
  */
3593
3589
  get paused() {
3594
- return this.currentAnim.isPaused;
3590
+ return this.currentAnim?.isPaused ?? false;
3595
3591
  }
3596
3592
  /**
3597
3593
  * Sets the paused state of the current animation.
3598
3594
  */
3599
3595
  set paused(value) {
3600
- this.currentAnim.paused = value;
3596
+ if (this.currentAnim) this.currentAnim.paused = value;
3601
3597
  }
3602
3598
  /**
3603
3599
  * Gets the name of the current animation.
@@ -3814,35 +3810,16 @@ var EventManager = class {
3814
3810
  };
3815
3811
  //#endregion
3816
3812
  //#region src/phaser/display/webgl/texture.ts
3813
+ /** The four corners of a texture frame in normalised texture space. */
3817
3814
  var TextureUvs = class {
3818
- noFrame;
3819
- baseTexture;
3820
- frame;
3821
- trim;
3822
- valid;
3823
- isTiling;
3824
- requiresUpdate;
3825
- requiresReTint;
3826
- _uvs;
3827
- width;
3828
- height;
3829
- crop;
3830
3815
  x0 = 0;
3831
3816
  y0 = 0;
3832
3817
  x1 = 0;
3833
3818
  y1 = 0;
3834
3819
  x2 = 0;
3835
- y2;
3836
- x3;
3837
- y3;
3838
- /**
3839
- * Creates a new Texture instance.
3840
- */
3841
- constructor() {
3842
- this.y2 = 0;
3843
- this.x3 = 0;
3844
- this.y3 = 0;
3845
- }
3820
+ y2 = 0;
3821
+ x3 = 0;
3822
+ y3 = 0;
3846
3823
  };
3847
3824
  var Texture = class Texture {
3848
3825
  noFrame = false;
@@ -3929,7 +3906,7 @@ var Texture = class Texture {
3929
3906
  this.valid = false;
3930
3907
  return;
3931
3908
  }
3932
- this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded;
3909
+ this.valid = Boolean(frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded);
3933
3910
  if (this.trim) {
3934
3911
  this.width = this.trim.width;
3935
3912
  this.height = this.trim.height;
@@ -4075,7 +4052,7 @@ var Image$1 = class extends DisplayObject {
4075
4052
  let setFrame = true;
4076
4053
  if (key instanceof Texture) this.setTexture(key);
4077
4054
  else {
4078
- const img = cache.getImage(key, true);
4055
+ const img = cache.getImage(key ?? void 0, true);
4079
4056
  if (img) {
4080
4057
  this.key = img.key;
4081
4058
  this.setTexture(new Texture(img.base));
@@ -4107,12 +4084,7 @@ var Image$1 = class extends DisplayObject {
4107
4084
  this.texture.trim.y = frame.spriteSourceSizeY;
4108
4085
  this.texture.trim.width = frame.sourceSizeW;
4109
4086
  this.texture.trim.height = frame.sourceSizeH;
4110
- } else this.texture.trim = {
4111
- x: frame.spriteSourceSizeX,
4112
- y: frame.spriteSourceSizeY,
4113
- width: frame.sourceSizeW,
4114
- height: frame.sourceSizeH
4115
- };
4087
+ } else this.texture.trim = new Rectangle(frame.spriteSourceSizeX, frame.spriteSourceSizeY, frame.sourceSizeW, frame.sourceSizeH);
4116
4088
  this.texture.width = frame.sourceSizeW;
4117
4089
  this.texture.height = frame.sourceSizeH;
4118
4090
  this.texture.frame.width = frame.sourceSizeW;
@@ -4398,12 +4370,13 @@ var BitmapText = class extends DisplayObject {
4398
4370
  charCode = 32;
4399
4371
  charData = data.chars[charCode];
4400
4372
  }
4401
- const kerning = prevCharCode && charData.kerning[prevCharCode] ? charData.kerning[prevCharCode] : 0;
4373
+ if (charData === void 0) continue;
4374
+ const kerning = (prevCharCode === null ? 0 : charData.kerning[prevCharCode]) ?? 0;
4402
4375
  if (/(\s)/.test(text.charAt(i))) {
4403
4376
  lastSpace = i;
4404
4377
  wrappedWidth = w;
4405
4378
  }
4406
- c = (kerning + charData.texture.width + charData.xOffset) * scale;
4379
+ c = (kerning + (charData.texture?.width ?? 0) + charData.xOffset) * scale;
4407
4380
  if (maxWidth && w + c >= maxWidth && lastSpace > -1) return {
4408
4381
  width: wrappedWidth || w,
4409
4382
  text: text.substr(0, i - (i - lastSpace)),
@@ -4429,7 +4402,7 @@ var BitmapText = class extends DisplayObject {
4429
4402
  * @returns {string} The cleaned text.
4430
4403
  */
4431
4404
  cleanText(text, replace = "") {
4432
- const data = this._data.font;
4405
+ const data = this._data?.font;
4433
4406
  if (!data) return "";
4434
4407
  const lines = text.replace(/\r\n|\n\r|\n|\r/g, "\n").split("\n");
4435
4408
  for (let i = 0; i < lines.length; i += 1) {
@@ -4445,22 +4418,25 @@ var BitmapText = class extends DisplayObject {
4445
4418
  * Updates the internal text rendering based on current properties and content.
4446
4419
  */
4447
4420
  updateText() {
4448
- const data = this._data.font;
4421
+ const data = this._data?.font;
4449
4422
  if (!data) return;
4450
4423
  let text = this.text;
4451
4424
  const scale = this._fontSize / data.size;
4452
4425
  const lines = [];
4453
4426
  let y = 0;
4454
4427
  this.textWidth = 0;
4455
- let line = { end: text.length === 0 };
4428
+ let end = false;
4456
4429
  do {
4457
- line = this.scanLine(data, scale, text);
4458
- line.y = y;
4430
+ const line = {
4431
+ ...this.scanLine(data, scale, text),
4432
+ y
4433
+ };
4459
4434
  lines.push(line);
4460
4435
  if (line.width > this.textWidth) this.textWidth = line.width;
4461
4436
  y += data.lineHeight * scale;
4462
4437
  text = text.slice(line.text.length + 1);
4463
- } while (line.end === false);
4438
+ end = line.end;
4439
+ } while (!end);
4464
4440
  this.textHeight = y;
4465
4441
  let t = 0;
4466
4442
  let align = 0;
@@ -4476,14 +4452,15 @@ var BitmapText = class extends DisplayObject {
4476
4452
  charCode = 32;
4477
4453
  charData = data.chars[charCode];
4478
4454
  }
4455
+ if (charData?.texture === void 0) continue;
4479
4456
  let g = this._glyphs[t];
4480
4457
  if (g) g.texture = charData.texture;
4481
4458
  else {
4482
4459
  g = new Image$1(this.game, 0, 0, charData.texture);
4483
- g.name = currentLine.text[c];
4460
+ g.name = currentLine.text[c] ?? "";
4484
4461
  this._glyphs.push(g);
4485
4462
  }
4486
- g.position.x = currentLine.chars[c] + align - ax;
4463
+ g.position.x = (currentLine.chars[c] ?? 0) + align - ax;
4487
4464
  g.position.y = currentLine.y + charData.yOffset * scale - ay;
4488
4465
  g.scale.setTo(scale, scale);
4489
4466
  g.tint = this.tint;
@@ -4618,9 +4595,9 @@ var BitmapText = class extends DisplayObject {
4618
4595
  * @param {number} value - The new font size to use.
4619
4596
  */
4620
4597
  set fontSize(value) {
4621
- value = Math.trunc(Number(value));
4622
- if (value !== this._fontSize && value > 0) {
4623
- this._fontSize = value;
4598
+ const size = Math.trunc(Number(value));
4599
+ if (size !== this._fontSize && size > 0) {
4600
+ this._fontSize = size;
4624
4601
  this.updateText();
4625
4602
  }
4626
4603
  }
@@ -4664,15 +4641,14 @@ var BitmapText = class extends DisplayObject {
4664
4641
  * @returns {boolean} True if smoothing is enabled, false otherwise.
4665
4642
  */
4666
4643
  get smoothed() {
4667
- return !this._data.base.scaleMode;
4644
+ return !this._data?.base.scaleMode;
4668
4645
  }
4669
4646
  /**
4670
4647
  * Sets whether smoothing is enabled for this bitmap text's font.
4671
4648
  * @param {boolean} value - Whether to enable smoothing (true) or not (false).
4672
4649
  */
4673
4650
  set smoothed(value) {
4674
- if (value) this._data.base.scaleMode = 0;
4675
- else this._data.base.scaleMode = 1;
4651
+ if (this._data) this._data.base.scaleMode = value ? 0 : 1;
4676
4652
  }
4677
4653
  };
4678
4654
  //#endregion
@@ -4705,7 +4681,6 @@ var InputHandler = class {
4705
4681
  isDragged;
4706
4682
  allowHorizontalDrag;
4707
4683
  allowVerticalDrag;
4708
- bringToTop;
4709
4684
  snapOffset;
4710
4685
  snapOnDrag;
4711
4686
  snapOnRelease;
@@ -4753,7 +4728,6 @@ var InputHandler = class {
4753
4728
  this.isDragged = false;
4754
4729
  this.allowHorizontalDrag = true;
4755
4730
  this.allowVerticalDrag = true;
4756
- this.bringToTop = false;
4757
4731
  this.snapOffset = null;
4758
4732
  this.snapOnDrag = false;
4759
4733
  this.snapOnRelease = false;
@@ -4863,7 +4837,6 @@ var InputHandler = class {
4863
4837
  this._pointerData.length = 0;
4864
4838
  this.boundsRect = null;
4865
4839
  this.boundsSprite = null;
4866
- this.sprite = null;
4867
4840
  }
4868
4841
  }
4869
4842
  /**
@@ -5054,7 +5027,7 @@ var InputHandler = class {
5054
5027
  */
5055
5028
  update(pointer) {
5056
5029
  if (this.sprite === null || this.sprite.parent === void 0) return false;
5057
- if (!this.enabled || !this.sprite.visible || !this.sprite.parent.visible) {
5030
+ if (!this.enabled || !this.sprite.visible || !this.sprite.parent?.visible) {
5058
5031
  this._pointerOutHandler(pointer);
5059
5032
  return false;
5060
5033
  }
@@ -5147,7 +5120,6 @@ var InputHandler = class {
5147
5120
  } else this._dragTimePass = true;
5148
5121
  }
5149
5122
  }
5150
- if (this.bringToTop) this.sprite.bringToTop();
5151
5123
  }
5152
5124
  }
5153
5125
  /**
@@ -5276,12 +5248,11 @@ var InputHandler = class {
5276
5248
  * @param {boolean} pixelPerfect - TBD.
5277
5249
  * @param {number} alphaThreshold - TBD.
5278
5250
  * @param {Rectangle | null | undefined} boundsRect - TBD.
5279
- * @param {DisplayObject | null | undefined} boundsSprite - TBD.
5251
+ * @param {Image | null | undefined} boundsSprite - TBD.
5280
5252
  */
5281
- enableDrag(lockCenter = false, bringToTop = false, pixelPerfect = false, alphaThreshold = 255, boundsRect = null, boundsSprite = null) {
5253
+ enableDrag(lockCenter = false, _bringToTop = false, pixelPerfect = false, alphaThreshold = 255, boundsRect = null, boundsSprite = null) {
5282
5254
  this._dragPoint = new Point();
5283
5255
  this.draggable = true;
5284
- this.bringToTop = bringToTop;
5285
5256
  this.dragOffset = new Point();
5286
5257
  this.dragFromCenter = lockCenter;
5287
5258
  this.pixelPerfectClick = pixelPerfect;
@@ -5318,10 +5289,6 @@ var InputHandler = class {
5318
5289
  }
5319
5290
  this._dragPoint.setTo(this.sprite.x - this.globalToLocalX(pointer.x), this.sprite.y - this.globalToLocalY(pointer.y));
5320
5291
  this.updateDrag(pointer, true);
5321
- if (this.bringToTop) {
5322
- this._dragPhase = true;
5323
- this.sprite.parent.bringToTop(this.sprite);
5324
- }
5325
5292
  this.dragStartPoint.setTo(x, y);
5326
5293
  this.sprite.events.onDragStart$dispatch(this.sprite, pointer, x, y);
5327
5294
  this._pendingDrag = false;
@@ -7440,7 +7407,7 @@ const buildRectangle = (graphicsData, webGLData) => {
7440
7407
  const { width } = rectData;
7441
7408
  const { height } = rectData;
7442
7409
  if (graphicsData.fill) {
7443
- const color = hex2rgb(graphicsData.fillColor);
7410
+ const color = hex2rgb(graphicsData.fillColor ?? 0);
7444
7411
  const alpha = graphicsData.fillAlpha;
7445
7412
  const r = color[0] * alpha;
7446
7413
  const g = color[1] * alpha;
@@ -7530,7 +7497,7 @@ const buildRoundedRectangle = (graphicsData, webGLData) => {
7530
7497
  recPoints = recPoints.concat(quadraticBezierCurve(x + width, y + radius, x + width, y, x + width - radius, y));
7531
7498
  recPoints = recPoints.concat(quadraticBezierCurve(x + radius, y, x, y, x, y + radius));
7532
7499
  if (graphicsData.fill) {
7533
- const color = hex2rgb(graphicsData.fillColor);
7500
+ const color = hex2rgb(graphicsData.fillColor ?? 0);
7534
7501
  const alpha = graphicsData.fillAlpha;
7535
7502
  const r = color[0] * alpha;
7536
7503
  const g = color[1] * alpha;
@@ -7566,7 +7533,7 @@ const buildCircle = (graphicsData, webGLData) => {
7566
7533
  const { y } = circleData;
7567
7534
  let width;
7568
7535
  let height;
7569
- if (graphicsData.shape instanceof Circle) {
7536
+ if (circleData instanceof Circle) {
7570
7537
  width = circleData.radius;
7571
7538
  height = circleData.radius;
7572
7539
  } else {
@@ -7575,7 +7542,7 @@ const buildCircle = (graphicsData, webGLData) => {
7575
7542
  }
7576
7543
  const seg = Math.PI * 2 / 40;
7577
7544
  if (graphicsData.fill) {
7578
- const color = hex2rgb(graphicsData.fillColor);
7545
+ const color = hex2rgb(graphicsData.fillColor ?? 0);
7579
7546
  const alpha = graphicsData.fillAlpha;
7580
7547
  const r = color[0] * alpha;
7581
7548
  const g = color[1] * alpha;
@@ -7611,7 +7578,7 @@ const buildComplexPoly = (graphicsData, webGLData) => {
7611
7578
  const { indices } = webGLData;
7612
7579
  webGLData.points = points;
7613
7580
  webGLData.alpha = graphicsData.fillAlpha;
7614
- webGLData.color = hex2rgb(graphicsData.fillColor);
7581
+ webGLData.color = hex2rgb(graphicsData.fillColor ?? 0);
7615
7582
  let minX = Infinity;
7616
7583
  let maxX = -Infinity;
7617
7584
  let minY = Infinity;
@@ -7642,7 +7609,7 @@ const buildPoly = (graphicsData, webGLData) => {
7642
7609
  const verts = webGLData.points;
7643
7610
  const { indices } = webGLData;
7644
7611
  const length = points.length / 2;
7645
- const color = hex2rgb(graphicsData.fillColor);
7612
+ const color = hex2rgb(graphicsData.fillColor ?? 0);
7646
7613
  const alpha = graphicsData.fillAlpha;
7647
7614
  const r = color[0] * alpha;
7648
7615
  const g = color[1] * alpha;
@@ -7799,10 +7766,10 @@ var BaseTexture = class {
7799
7766
  true
7800
7767
  ];
7801
7768
  if (source) {
7802
- if ((this.source.complete || this.source.getContext) && this.source.width && this.source.height) {
7769
+ if ((source instanceof HTMLImageElement ? source.complete : true) && source.width && source.height) {
7803
7770
  this.hasLoaded = true;
7804
- this.width = this.source.naturalWidth ?? this.source.width;
7805
- this.height = this.source.naturalHeight ?? this.source.height;
7771
+ this.width = source instanceof HTMLImageElement ? source.naturalWidth : source.width;
7772
+ this.height = source instanceof HTMLImageElement ? source.naturalHeight : source.height;
7806
7773
  this.dirty();
7807
7774
  }
7808
7775
  }
@@ -7822,7 +7789,7 @@ var BaseTexture = class {
7822
7789
  * Destroys the texture.
7823
7790
  */
7824
7791
  destroy() {
7825
- if (this.source) removeByCanvas(this.source);
7792
+ if (this.source instanceof HTMLCanvasElement) removeByCanvas(this.source);
7826
7793
  this.source = null;
7827
7794
  this.unloadFromGPU();
7828
7795
  }
@@ -11493,7 +11460,7 @@ var WebGLSpriteBatch = class {
11493
11460
  const { gl } = this;
11494
11461
  if (texture._dirty[gl.id]) {
11495
11462
  if (!this.renderSession.renderer.updateTexture(texture)) return;
11496
- } else gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]);
11463
+ } else gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id] ?? null);
11497
11464
  gl.drawElements(gl.TRIANGLES, size * 6, gl.UNSIGNED_SHORT, startIndex * 6 * 2);
11498
11465
  this.renderSession.drawCount += 1;
11499
11466
  }
@@ -11759,14 +11726,9 @@ var WebGLRenderer = class {
11759
11726
  */
11760
11727
  destroy() {
11761
11728
  globalThis.PhaserRegistry.GL_CONTEXTS[this.glContextId] = null;
11762
- this.projection = null;
11763
- this.offset = null;
11764
11729
  this.shaderManager.destroy();
11765
11730
  this.spriteBatch.destroy();
11766
11731
  this.filterManager.destroy();
11767
- this.shaderManager = null;
11768
- this.spriteBatch = null;
11769
- this.filterManager = null;
11770
11732
  if (this.gl) {
11771
11733
  this.gl.canvas.width = 1;
11772
11734
  this.gl.canvas.height = 1;
@@ -11883,7 +11845,7 @@ var WebGLRenderer = class {
11883
11845
  if (!texture.hasLoaded) return false;
11884
11846
  const { gl } = this;
11885
11847
  texture._glTextures[gl.id] ??= gl.createTexture();
11886
- gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]);
11848
+ gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id] ?? null);
11887
11849
  gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultipliedAlpha);
11888
11850
  gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source);
11889
11851
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, texture.scaleMode === 0 ? gl.LINEAR : gl.NEAREST);
@@ -12147,10 +12109,7 @@ const JSONDataHash = (game, json, _key) => {
12147
12109
  * @returns {object} The finalized bitmap font data.
12148
12110
  */
12149
12111
  const finalizeBitmapFont = (baseTexture, bitmapFontData) => {
12150
- Object.keys(bitmapFontData.chars).forEach((charCode) => {
12151
- const letter = bitmapFontData.chars[charCode];
12152
- letter.texture = new Texture(baseTexture, new Rectangle(letter.x, letter.y, letter.width, letter.height));
12153
- });
12112
+ for (const letter of Object.values(bitmapFontData.chars)) letter.texture = new Texture(baseTexture, new Rectangle(letter.x, letter.y, letter.width, letter.height));
12154
12113
  return bitmapFontData;
12155
12114
  };
12156
12115
  /**
@@ -12162,33 +12121,28 @@ const finalizeBitmapFont = (baseTexture, bitmapFontData) => {
12162
12121
  * @returns {object} The parsed bitmap font data.
12163
12122
  */
12164
12123
  const xmlBitmapFont = (xml, baseTexture, xSpacing, ySpacing) => {
12165
- const data = {};
12166
12124
  const info = xml.querySelectorAll("info")[0];
12167
12125
  const common = xml.querySelectorAll("common")[0];
12168
- data.font = info.getAttribute("face");
12169
- data.size = Math.trunc(Number(info.getAttribute("size")));
12170
- data.lineHeight = Math.trunc(Number(common.getAttribute("lineHeight"))) + ySpacing;
12171
- data.chars = {};
12172
- const letters = xml.querySelectorAll("char");
12173
- for (let i = 0; i < letters.length; i += 1) {
12174
- const charCode = Math.trunc(Number(letters[i].getAttribute("id")));
12175
- data.chars[charCode] = {
12176
- x: Math.trunc(Number(letters[i].getAttribute("x"))),
12177
- y: Math.trunc(Number(letters[i].getAttribute("y"))),
12178
- width: Math.trunc(Number(letters[i].getAttribute("width"))),
12179
- height: Math.trunc(Number(letters[i].getAttribute("height"))),
12180
- xOffset: Math.trunc(Number(letters[i].getAttribute("xoffset"))),
12181
- yOffset: Math.trunc(Number(letters[i].getAttribute("yoffset"))),
12182
- xAdvance: Math.trunc(Number(letters[i].getAttribute("xadvance"))) + xSpacing,
12183
- kerning: {}
12184
- };
12185
- }
12186
- const kernings = xml.querySelectorAll("kerning");
12187
- for (let i = 0; i < kernings.length; i += 1) {
12188
- const first = Math.trunc(Number(kernings[i].getAttribute("first")));
12189
- const second = Math.trunc(Number(kernings[i].getAttribute("second")));
12190
- const amount = Math.trunc(Number(kernings[i].getAttribute("amount")));
12191
- data.chars[second].kerning[first] = amount;
12126
+ const attr = (element, name) => Math.trunc(Number(element?.getAttribute(name)));
12127
+ const data = {
12128
+ font: info?.getAttribute("face") ?? "",
12129
+ size: attr(info, "size"),
12130
+ lineHeight: attr(common, "lineHeight") + ySpacing,
12131
+ chars: {}
12132
+ };
12133
+ for (const letter of xml.querySelectorAll("char")) data.chars[attr(letter, "id")] = {
12134
+ x: attr(letter, "x"),
12135
+ y: attr(letter, "y"),
12136
+ width: attr(letter, "width"),
12137
+ height: attr(letter, "height"),
12138
+ xOffset: attr(letter, "xoffset"),
12139
+ yOffset: attr(letter, "yoffset"),
12140
+ xAdvance: attr(letter, "xadvance") + xSpacing,
12141
+ kerning: {}
12142
+ };
12143
+ for (const kerning of xml.querySelectorAll("kerning")) {
12144
+ const char = data.chars[attr(kerning, "second")];
12145
+ if (char) char.kerning[attr(kerning, "first")] = attr(kerning, "amount");
12192
12146
  }
12193
12147
  return finalizeBitmapFont(baseTexture, data);
12194
12148
  };
@@ -12348,9 +12302,9 @@ var Cache = class {
12348
12302
  key,
12349
12303
  url,
12350
12304
  data,
12351
- base: new BaseTexture(data)
12305
+ base: new BaseTexture(data),
12306
+ frameData: JSONDataHash(this.game, atlasData, key)
12352
12307
  };
12353
- obj.frameData = JSONDataHash(this.game, atlasData, key);
12354
12308
  this._cache.image[key] = obj;
12355
12309
  this._resolveURL(url, obj);
12356
12310
  }
@@ -12361,13 +12315,14 @@ var Cache = class {
12361
12315
  * @param {object} data - The sound data to cache.
12362
12316
  */
12363
12317
  addSound(key, url, data) {
12364
- this._cache.sound[key] = {
12318
+ const obj = {
12365
12319
  url,
12366
12320
  data,
12367
12321
  isDecoding: false,
12368
12322
  decoded: false
12369
12323
  };
12370
- this._resolveURL(url, this._cache.sound[key]);
12324
+ this._cache.sound[key] = obj;
12325
+ this._resolveURL(url, obj);
12371
12326
  }
12372
12327
  /**
12373
12328
  * Adds text data to the cache.
@@ -12376,11 +12331,12 @@ var Cache = class {
12376
12331
  * @param {string} data - The text data to cache.
12377
12332
  */
12378
12333
  addText(key, url, data) {
12379
- this._cache.text[key] = {
12334
+ const obj = {
12380
12335
  url,
12381
12336
  data
12382
12337
  };
12383
- this._resolveURL(url, this._cache.text[key]);
12338
+ this._cache.text[key] = obj;
12339
+ this._resolveURL(url, obj);
12384
12340
  }
12385
12341
  /**
12386
12342
  * Adds a bitmap font to the cache.
@@ -12393,14 +12349,13 @@ var Cache = class {
12393
12349
  * @param {number} ySpacing - Vertical spacing between characters.
12394
12350
  */
12395
12351
  addBitmapFont(key, url, data, atlasData, atlasType, xSpacing = 0, ySpacing = 0) {
12352
+ const base = new BaseTexture(data);
12396
12353
  const obj = {
12397
12354
  url,
12398
12355
  data,
12399
- font: null,
12400
- base: new BaseTexture(data)
12356
+ font: atlasType === "json" ? jsonBitmapFont(atlasData, base, xSpacing, ySpacing) : xmlBitmapFont(atlasData, base, xSpacing, ySpacing),
12357
+ base
12401
12358
  };
12402
- if (atlasType === "json") obj.font = jsonBitmapFont(atlasData, obj.base, xSpacing, ySpacing);
12403
- else obj.font = xmlBitmapFont(atlasData, obj.base, xSpacing, ySpacing);
12404
12359
  this._cache.bitmapFont[key] = obj;
12405
12360
  this._resolveURL(url, obj);
12406
12361
  }
@@ -12411,11 +12366,12 @@ var Cache = class {
12411
12366
  * @param {object} data - The JSON data to cache.
12412
12367
  */
12413
12368
  addJSON(key, url, data) {
12414
- this._cache.json[key] = {
12369
+ const obj = {
12415
12370
  url,
12416
12371
  data
12417
12372
  };
12418
- this._resolveURL(url, this._cache.json[key]);
12373
+ this._cache.json[key] = obj;
12374
+ this._resolveURL(url, obj);
12419
12375
  }
12420
12376
  /**
12421
12377
  * Adds XML data to the cache.
@@ -12424,11 +12380,12 @@ var Cache = class {
12424
12380
  * @param {XMLDocument} data - The XML data to cache.
12425
12381
  */
12426
12382
  addXML(key, url, data) {
12427
- this._cache.xml[key] = {
12383
+ const obj = {
12428
12384
  url,
12429
12385
  data
12430
12386
  };
12431
- this._resolveURL(url, this._cache.xml[key]);
12387
+ this._cache.xml[key] = obj;
12388
+ this._resolveURL(url, obj);
12432
12389
  }
12433
12390
  /**
12434
12391
  * Updates a sound property in the cache.
@@ -12447,6 +12404,7 @@ var Cache = class {
12447
12404
  */
12448
12405
  decodedSound(key, data) {
12449
12406
  const sound = this.getSound(key);
12407
+ if (!sound) return;
12450
12408
  sound.data = data;
12451
12409
  sound.decoded = true;
12452
12410
  sound.isDecoding = false;
@@ -12457,7 +12415,7 @@ var Cache = class {
12457
12415
  * @returns {boolean} True if the sound is decoded, false otherwise.
12458
12416
  */
12459
12417
  isSoundDecoded(key) {
12460
- const sound = this.getItem(key, 3, "isSoundDecoded");
12418
+ const sound = this.getSound(key);
12461
12419
  if (sound) return sound.decoded;
12462
12420
  return null;
12463
12421
  }
@@ -12467,7 +12425,7 @@ var Cache = class {
12467
12425
  * @returns {boolean} True if the sound is ready, false otherwise.
12468
12426
  */
12469
12427
  isSoundReady(key) {
12470
- const sound = this.getItem(key, 3, "isSoundDecoded");
12428
+ const sound = this.getSound(key);
12471
12429
  if (sound) return sound.decoded && !this.game.sound.isLocked;
12472
12430
  return false;
12473
12431
  }
@@ -12487,7 +12445,8 @@ var Cache = class {
12487
12445
  * @returns {boolean} True if the URL has been resolved and cached, false otherwise.
12488
12446
  */
12489
12447
  checkURL(url) {
12490
- if (this._urlMap[this._resolveURL(url)]) return true;
12448
+ const resolved = this._resolveURL(url);
12449
+ if (resolved && this._urlMap?.[resolved]) return true;
12491
12450
  return false;
12492
12451
  }
12493
12452
  /**
@@ -12586,15 +12545,8 @@ var Cache = class {
12586
12545
  getCanvas(key) {
12587
12546
  return this.getItem(key, 0, "getCanvas", "canvas");
12588
12547
  }
12589
- /**
12590
- * TBD.
12591
- * @param {string} key - TBD.
12592
- * @param {boolean} full - TBD.
12593
- * @returns {HTMLImageElement} TBD.
12594
- */
12595
12548
  getImage(key = "__default", full = false) {
12596
- let img = this.getItem(key, 1, "getImage");
12597
- if (img === null) img = this.getItem("__missing", 1, "getImage");
12549
+ const img = this.getItem(String(key), 1, "getImage") ?? this.getItem("__missing", 1, "getImage");
12598
12550
  if (full) return img;
12599
12551
  return img.data;
12600
12552
  }
@@ -12761,7 +12713,7 @@ var Cache = class {
12761
12713
  */
12762
12714
  getURL(url) {
12763
12715
  const resolvedURL = this._resolveURL(url);
12764
- if (resolvedURL) return this._urlMap[resolvedURL];
12716
+ if (resolvedURL) return this._urlMap?.[resolvedURL] ?? null;
12765
12717
  this.game.logger.warn("Cache invalid url", { resolvedURL });
12766
12718
  return null;
12767
12719
  }
@@ -12772,8 +12724,9 @@ var Cache = class {
12772
12724
  */
12773
12725
  getKeys(cache = 1) {
12774
12726
  const result = [];
12775
- if (this._cacheMap[cache]) {
12776
- const keys = Object.keys(this._cacheMap[cache]);
12727
+ const bucket = this._cacheMap[cache];
12728
+ if (bucket) {
12729
+ const keys = Object.keys(bucket);
12777
12730
  for (const key of keys) if (key !== "__default" && key !== "__missing") result.push(key);
12778
12731
  }
12779
12732
  return result;
@@ -12792,7 +12745,7 @@ var Cache = class {
12792
12745
  */
12793
12746
  removeImage(key, destroyBaseTexture = true) {
12794
12747
  const img = this.getImage(key, true);
12795
- if (destroyBaseTexture && img.base) img.base.destroy();
12748
+ if (destroyBaseTexture) img.base.destroy();
12796
12749
  delete this._cache.image[key];
12797
12750
  }
12798
12751
  /**
@@ -12862,8 +12815,7 @@ var Cache = class {
12862
12815
  * Clears all GL textures from the cache.
12863
12816
  */
12864
12817
  clearGLTextures() {
12865
- const keys = Object.keys(this._cache.image);
12866
- for (const key of keys) this._cache.image[key].base._glTextures = [];
12818
+ for (const entry of Object.values(this._cache.image)) entry.base._glTextures = [];
12867
12819
  }
12868
12820
  /**
12869
12821
  * Resolves a URL and stores it in the cache.
@@ -12873,10 +12825,11 @@ var Cache = class {
12873
12825
  */
12874
12826
  _resolveURL(url, data = null) {
12875
12827
  if (!this.autoResolveURL) return null;
12828
+ if (!this._urlResolver) return null;
12876
12829
  this._urlResolver.src = this.game.load.baseURL + url;
12877
12830
  this._urlTemp = this._urlResolver.src;
12878
12831
  this._urlResolver.src = "";
12879
- if (data) this._urlMap[this._urlTemp] = data;
12832
+ if (data && this._urlMap) this._urlMap[this._urlTemp] = data;
12880
12833
  return this._urlTemp;
12881
12834
  }
12882
12835
  /**
@@ -12886,7 +12839,7 @@ var Cache = class {
12886
12839
  for (const cache of this._cacheMap) {
12887
12840
  const keys = cache ? Object.keys(cache) : [];
12888
12841
  for (const key of keys) if (key !== "__default" && key !== "__missing") {
12889
- if (cache[key].destroy) cache[key].destroy();
12842
+ cache[key].destroy?.();
12890
12843
  delete cache[key];
12891
12844
  }
12892
12845
  }
@@ -13600,14 +13553,10 @@ var MSPointer = class {
13600
13553
  if (this._onMSPointerDown) canvas.removeEventListener("pointerdown", this._onMSPointerDown, false);
13601
13554
  if (this._onMSPointerMove) canvas.removeEventListener("pointermove", this._onMSPointerMove, false);
13602
13555
  if (this._onMSPointerUp) canvas.removeEventListener("pointerup", this._onMSPointerUp, false);
13603
- if (this._onMSPointerUpGlobal) {
13604
- if (this._onMSPointerUpGlobal) globalThis.removeEventListener("MSPointerUp", this._onMSPointerUpGlobal, true);
13605
- }
13556
+ if (this._onMSPointerUpGlobal) globalThis.removeEventListener("MSPointerUp", this._onMSPointerUpGlobal, true);
13606
13557
  if (this._onMSPointerOver) canvas.removeEventListener("MSPointerOver", this._onMSPointerOver, true);
13607
13558
  if (this._onMSPointerOut) canvas.removeEventListener("MSPointerOut", this._onMSPointerOut, true);
13608
- if (this._onMSPointerUpGlobal) {
13609
- if (this._onMSPointerUpGlobal) globalThis.removeEventListener("pointerup", this._onMSPointerUpGlobal, true);
13610
- }
13559
+ if (this._onMSPointerUpGlobal) globalThis.removeEventListener("pointerup", this._onMSPointerUpGlobal, true);
13611
13560
  if (this._onMSPointerOver) canvas.removeEventListener("pointerover", this._onMSPointerOver, true);
13612
13561
  if (this._onMSPointerOut) canvas.removeEventListener("pointerout", this._onMSPointerOut, true);
13613
13562
  }
@@ -13930,8 +13879,8 @@ var Pointer = class {
13930
13879
  const moveCallback = input.moveCallbacks[i];
13931
13880
  moveCallback.callback.call(moveCallback.context, this, this.x, this.y, fromClick);
13932
13881
  }
13933
- if (this.targetObject !== null && this.targetObject.isDragged === true) {
13934
- if (this.targetObject.update(this) === false) this.targetObject = null;
13882
+ if (this.targetObject !== null && this.targetObject.isDragged) {
13883
+ if (!this.targetObject.update(this)) this.targetObject = null;
13935
13884
  } else if (input.interactiveItems.total > 0) this.processInteractiveObjects(fromClick);
13936
13885
  return this;
13937
13886
  }
@@ -14393,8 +14342,6 @@ var Input = class {
14393
14342
  this.recordPointerHistory = false;
14394
14343
  this.recordRate = 100;
14395
14344
  this.recordLimit = 100;
14396
- this.pointer1 = null;
14397
- this.pointer2 = null;
14398
14345
  this.pointer3 = null;
14399
14346
  this.pointer4 = null;
14400
14347
  this.pointer5 = null;
@@ -15323,41 +15270,41 @@ var Loader = class {
15323
15270
  * @param {object} pack - The pack file object to process.
15324
15271
  */
15325
15272
  processPack(pack) {
15326
- const packData = pack.data[pack.key];
15273
+ const packData = (pack.data ?? {})[pack.key];
15327
15274
  if (!packData) {
15328
15275
  this.game.logger.warn("Missing loader pack key", { key: pack.key });
15329
15276
  return;
15330
15277
  }
15331
- const packDataCompat = Array.isArray(packData) ? packData : packData.files;
15278
+ const packDataCompat = Array.isArray(packData) ? packData : packData.files ?? [];
15332
15279
  for (const file of packDataCompat) switch (file.type) {
15333
15280
  case "image":
15334
- this.image(file.key, file.url, file.overwrite);
15281
+ this.image(file.key, file.url ?? file.key, file.overwrite);
15335
15282
  break;
15336
15283
  case "text":
15337
- this.text(file.key, file.url, file.overwrite);
15284
+ this.text(file.key, file.url ?? file.key, file.overwrite);
15338
15285
  break;
15339
15286
  case "json":
15340
- this.json(file.key, file.url, file.overwrite);
15287
+ this.json(file.key, file.url ?? file.key, file.overwrite);
15341
15288
  break;
15342
15289
  case "xml":
15343
- this.xml(file.key, file.url, file.overwrite);
15290
+ this.xml(file.key, file.url ?? file.key, file.overwrite);
15344
15291
  break;
15345
15292
  case "spritesheet":
15346
- this.spritesheet(file.key, file.url, file.frameWidth, file.frameHeight, file.frameMax, file.margin, file.spacing);
15293
+ this.spritesheet(file.key, file.url ?? file.key, file.frameWidth ?? 0, file.frameHeight ?? 0, file.frameMax ?? -1, file.margin, file.spacing);
15347
15294
  break;
15348
15295
  case "audio":
15349
- this.audio(file.key, file.urls ?? file.url);
15296
+ this.audio(file.key, file.urls ?? file.url ?? file.key);
15350
15297
  break;
15351
15298
  case "audiosprite":
15352
- this.audioSprite(file.key, file.urls ?? file.url, file.jsonURL, file.jsonData);
15299
+ this.audioSprite(file.key, String(file.urls ?? file.url ?? file.key), file.jsonURL ?? "", file.jsonData);
15353
15300
  break;
15354
15301
  case "audioSprite":
15355
- this.audioSprite(file.key, file.audioURL, file.jsonURL, file.jsonData);
15302
+ this.audioSprite(file.key, file.audioURL ?? file.key, file.jsonURL ?? "", file.jsonData);
15356
15303
  break;
15357
15304
  case "bitmapFont":
15358
15305
  this.bitmapFont(file.key, file.textureURL, file.fontDataURL ?? file.atlasURL, file.atlasData, file.xSpacing, file.ySpacing);
15359
15306
  break;
15360
- case "atlas": this.atlas(file.key, file.textureURL, file.atlasURL, file.atlasData, TEXTURE_ATLAS_JSON_HASH);
15307
+ case "atlas": this.atlas(file.key, file.textureURL ?? file.key, file.atlasURL, file.atlasData, TEXTURE_ATLAS_JSON_HASH);
15361
15308
  }
15362
15309
  }
15363
15310
  /**
@@ -15413,28 +15360,34 @@ var Loader = class {
15413
15360
  loadImageTag(file) {
15414
15361
  this.log("loadImageTag", file);
15415
15362
  const scope = this;
15416
- file.data = new globalThis.Image();
15417
- file.data.name = file.key;
15418
- if (this.crossOrigin) file.data.crossOrigin = this.crossOrigin;
15419
- file.data.onload = () => {
15420
- if (file.data.onload) {
15421
- file.data.onload = null;
15422
- file.data.onerror = null;
15363
+ const image = new globalThis.Image();
15364
+ file.data = image;
15365
+ image.name = file.key;
15366
+ if (typeof this.crossOrigin === "string" && this.crossOrigin) image.crossOrigin = this.crossOrigin;
15367
+ image.onload = () => {
15368
+ if (image.onload) {
15369
+ image.onload = null;
15370
+ image.onerror = null;
15423
15371
  scope.fileComplete(file);
15424
15372
  }
15425
15373
  };
15426
- file.data.onerror = () => {
15374
+ image.onerror = () => {
15427
15375
  if (scope.isUseRetry && (!file.numRetry || file.numRetry < scope.maxRetry)) setTimeout(() => {
15428
15376
  file.numRetry = !file.numRetry ? 1 : file.numRetry += 1;
15429
15377
  scope.loadImageTag(file);
15430
15378
  }, 1e3);
15431
- else if (file.data.onload) {
15432
- file.data.onload = null;
15433
- file.data.onerror = null;
15379
+ else if (image.onload) {
15380
+ image.onload = null;
15381
+ image.onerror = null;
15434
15382
  scope.fileError(file);
15435
15383
  }
15436
15384
  };
15437
- file.data.src = this.transformUrl(file.url, file);
15385
+ const src = this.transformUrl(file.url, file);
15386
+ if (src === false) {
15387
+ this.fileError(file, null, "Could not resolve the file URL");
15388
+ return;
15389
+ }
15390
+ image.src = src;
15438
15391
  }
15439
15392
  /**
15440
15393
  * Loads a file using XMLHttpRequest with the specified parameters.
@@ -15592,14 +15545,19 @@ var Loader = class {
15592
15545
  });
15593
15546
  }
15594
15547
  break;
15595
- case "audio":
15596
- file.data = response.response;
15597
- this.cache.addSound(file.key, url, file.data);
15548
+ case "audio": {
15549
+ const audio = response.response;
15550
+ file.data = audio;
15551
+ this.cache.addSound(file.key, url, audio);
15598
15552
  if (file.autoDecode) this.game.sound.decode(file.key);
15599
15553
  break;
15600
- case "text":
15601
- file.data = response.responseText;
15602
- this.cache.addText(file.key, url, file.data);
15554
+ }
15555
+ case "text": {
15556
+ const { responseText } = response;
15557
+ file.data = responseText;
15558
+ this.cache.addText(file.key, url, responseText);
15559
+ break;
15560
+ }
15603
15561
  }
15604
15562
  if (loadNext) this.asyncComplete(file);
15605
15563
  }
@@ -16694,8 +16652,9 @@ var ScaleManager = class {
16694
16652
  if (canvas.parentNode) canvas.before(fsTarget);
16695
16653
  fsTarget.append(canvas);
16696
16654
  }
16697
- if (this.game.device.fullscreenKeyboard) fsTarget[this.game.device.requestFullscreen](Element.ALLOW_KEYBOARD_INPUT);
16698
- else fsTarget[this.game.device.requestFullscreen]();
16655
+ const requestFullscreen = fsTarget[this.game.device.requestFullscreen];
16656
+ if (this.game.device.fullscreenKeyboard) requestFullscreen?.call(fsTarget, Element.ALLOW_KEYBOARD_INPUT);
16657
+ else requestFullscreen?.call(fsTarget);
16699
16658
  return true;
16700
16659
  }
16701
16660
  /**
@@ -17328,8 +17287,9 @@ var Sound = class {
17328
17287
  */
17329
17288
  soundHasUnlocked(key) {
17330
17289
  if (key === this.key) {
17331
- this._sound = this.game.cache.getSoundData(this.key);
17332
- this.totalDuration = this._sound.duration;
17290
+ const buffer = this.game.cache.getSoundData(this.key);
17291
+ this._sound = buffer;
17292
+ this.totalDuration = buffer.duration;
17333
17293
  }
17334
17294
  }
17335
17295
  /**
@@ -17443,14 +17403,15 @@ var Sound = class {
17443
17403
  this.isPlaying = false;
17444
17404
  }
17445
17405
  if (marker === "" && Object.keys(this.markers).length > 0) return this;
17406
+ const markerData = marker === "" ? void 0 : this.markers[marker];
17446
17407
  if (marker !== "") {
17447
- if (this.markers[marker]) {
17408
+ if (markerData) {
17448
17409
  this.currentMarker = marker;
17449
- this.position = this.markers[marker].start;
17450
- this.volume = this.markers[marker].volume;
17451
- this.loop = this.markers[marker].loop;
17452
- this.duration = this.markers[marker].duration;
17453
- this.durationMS = this.markers[marker].durationMS;
17410
+ this.position = markerData.start;
17411
+ this.volume = markerData.volume;
17412
+ this.loop = markerData.loop;
17413
+ this.duration = markerData.duration;
17414
+ this.durationMS = markerData.durationMS;
17454
17415
  if (volume !== void 0) this.volume = volume;
17455
17416
  if (loop !== void 0) this.loop = loop;
17456
17417
  this._tempMarker = marker;
@@ -17462,8 +17423,8 @@ var Sound = class {
17462
17423
  return this;
17463
17424
  }
17464
17425
  } else {
17465
- position = position ?? 0;
17466
- if (volume === void 0) volume = this._volume;
17426
+ position ??= 0;
17427
+ volume ??= this._volume;
17467
17428
  if (loop === void 0) ({loop} = this);
17468
17429
  this.position = Math.max(0, position);
17469
17430
  this.volume = volume;
@@ -17498,7 +17459,7 @@ var Sound = class {
17498
17459
  this.onPlay.dispatch(this);
17499
17460
  } else {
17500
17461
  this.pendingPlayback = true;
17501
- if (this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).isDecoding === false) this.game.sound.decode(this.key);
17462
+ if (this.game.cache.getSound(this.key)?.isDecoding === false) this.game.sound.decode(this.key);
17502
17463
  }
17503
17464
  return this;
17504
17465
  }
@@ -17928,21 +17889,21 @@ var SoundManager = class {
17928
17889
  */
17929
17890
  stopAll() {
17930
17891
  if (this.noAudio) return;
17931
- for (let i = 0; i < this._sounds.length; i += 1) if (this._sounds[i]) this._sounds[i].stop();
17892
+ for (const sound of this._sounds) if (sound) sound.stop();
17932
17893
  }
17933
17894
  /**
17934
17895
  * Pauses all sounds in the manager.
17935
17896
  */
17936
17897
  pauseAll() {
17937
17898
  if (this.noAudio) return;
17938
- for (let i = 0; i < this._sounds.length; i += 1) if (this._sounds[i]) this._sounds[i].pause();
17899
+ for (const sound of this._sounds) if (sound) sound.pause();
17939
17900
  }
17940
17901
  /**
17941
17902
  * Resumes all sounds in the manager.
17942
17903
  */
17943
17904
  resumeAll() {
17944
17905
  if (this.noAudio) return;
17945
- for (let i = 0; i < this._sounds.length; i += 1) if (this._sounds[i]) this._sounds[i].resume();
17906
+ for (const sound of this._sounds) if (sound) sound.resume();
17946
17907
  }
17947
17908
  /**
17948
17909
  * Decodes an audio file for playback.
@@ -17950,7 +17911,7 @@ var SoundManager = class {
17950
17911
  */
17951
17912
  decode(key) {
17952
17913
  const soundData = this.game.cache.getSoundData(key);
17953
- if (!soundData) return;
17914
+ if (!(soundData instanceof ArrayBuffer)) return;
17954
17915
  if (this.game.cache.isSoundDecoded(key) === true) return;
17955
17916
  this.game.cache.updateSound(key, "isDecoding", true);
17956
17917
  this.context.decodeAudioData(soundData).then((buffer) => {
@@ -17974,11 +17935,12 @@ var SoundManager = class {
17974
17935
  * @param {object} callbackContext - The context in which to call the callback.
17975
17936
  */
17976
17937
  setDecodedCallback(files, callback, callbackContext) {
17977
- if (typeof files === "string") files = [files];
17938
+ const candidates = typeof files === "string" ? [files] : Array.isArray(files) ? files : [files];
17978
17939
  this._watchList.reset();
17979
- for (let i = 0; i < files.length; i += 1) if (files[i] instanceof Sound) {
17980
- if (!this.game.cache.isSoundDecoded(files[i].key)) this._watchList.add(files[i].key);
17981
- } else if (!this.game.cache.isSoundDecoded(files[i])) this._watchList.add(files[i]);
17940
+ for (const file of candidates) {
17941
+ const key = file instanceof Sound ? file.key : file;
17942
+ if (!this.game.cache.isSoundDecoded(key)) this._watchList.add(key);
17943
+ }
17982
17944
  if (this._watchList.total === 0) {
17983
17945
  this._watching = false;
17984
17946
  callback.call(callbackContext);
@@ -17993,7 +17955,7 @@ var SoundManager = class {
17993
17955
  */
17994
17956
  update() {
17995
17957
  if (this.noAudio) return;
17996
- for (let i = 0; i < this._sounds.length; i += 1) this._sounds[i].update();
17958
+ for (const sound of this._sounds) sound.update();
17997
17959
  if (this._watching) {
17998
17960
  let key = this._watchList.first;
17999
17961
  while (key) {
@@ -18003,7 +17965,7 @@ var SoundManager = class {
18003
17965
  if (this._watchList.total === 0) {
18004
17966
  this.game.logger.info("All sounds decoded");
18005
17967
  this._watching = false;
18006
- this._watchCallback.call(this._watchContext);
17968
+ this._watchCallback?.call(this._watchContext);
18007
17969
  }
18008
17970
  }
18009
17971
  }
@@ -18102,7 +18064,7 @@ var SoundManager = class {
18102
18064
  */
18103
18065
  destroy() {
18104
18066
  this.stopAll();
18105
- for (let i = 0; i < this._sounds.length; i += 1) if (this._sounds[i]) this._sounds[i].destroy();
18067
+ for (const sound of this._sounds) if (sound) sound.destroy();
18106
18068
  this._sounds = [];
18107
18069
  this.onChange.dispose();
18108
18070
  if (this.context?.close) this.context.close();
@@ -18999,9 +18961,9 @@ var TweenData = class {
18999
18961
  */
19000
18962
  update(time) {
19001
18963
  if (!this.isRunning) {
19002
- if (time >= this.startTime) this.isRunning = true;
18964
+ if (time >= (this.startTime ?? 0)) this.isRunning = true;
19003
18965
  else return 0;
19004
- } else if (time < this.startTime) return 1;
18966
+ } else if (time < (this.startTime ?? 0)) return 1;
19005
18967
  const ms = this.game.time.elapsedMS;
19006
18968
  if (this.parent.reverse) {
19007
18969
  this.dt -= ms * this.parent.timeScale;
@@ -19403,7 +19365,7 @@ var Tween = class {
19403
19365
  if (this.isPaused) {
19404
19366
  this.isPaused = false;
19405
19367
  this._codePaused = false;
19406
- for (const tweenData of this.timeline) if (!tweenData.isRunning) tweenData.startTime += this.game.time.time - this._pausedTime;
19368
+ for (const tweenData of this.timeline) if (!tweenData.isRunning) tweenData.startTime = (tweenData.startTime ?? 0) + (this.game.time.time - this._pausedTime);
19407
19369
  }
19408
19370
  }
19409
19371
  /**
@@ -19865,7 +19827,7 @@ var TweenManager = class {
19865
19827
  * This method removes all active and pending tweens.
19866
19828
  */
19867
19829
  removeAll() {
19868
- for (let i = 0; i < this._tweens.length; i += 1) this._tweens[i].pendingDelete = true;
19830
+ for (const tween of this._tweens) tween.pendingDelete = true;
19869
19831
  this._add = [];
19870
19832
  }
19871
19833
  /**
@@ -19874,14 +19836,17 @@ var TweenManager = class {
19874
19836
  * @param {object[]} children - Optional array of child objects to remove tweens from.
19875
19837
  */
19876
19838
  removeFrom(obj, children = null) {
19877
- let i;
19878
- let len;
19879
- if (Array.isArray(obj)) for (i = 0, len = obj.length; i < len; i += 1) this.removeFrom(obj[i]);
19880
- else if (obj.type === 7 && children) for (i = 0, len = obj.children.length; i < len; i += 1) this.removeFrom(obj.children[i]);
19881
- else {
19882
- for (i = 0, len = this._tweens.length; i < len; i += 1) if (obj === this._tweens[i].target) this.remove(this._tweens[i]);
19883
- for (i = 0, len = this._add.length; i < len; i += 1) if (obj === this._add[i].target) this.remove(this._add[i]);
19839
+ if (Array.isArray(obj)) {
19840
+ for (const entry of obj) this.removeFrom(entry);
19841
+ return;
19842
+ }
19843
+ const group = obj;
19844
+ if (group.type === 7 && children && group.children) {
19845
+ for (const child of group.children) this.removeFrom(child);
19846
+ return;
19884
19847
  }
19848
+ for (const tween of this._tweens.slice()) if (obj === tween.target) this.remove(tween);
19849
+ for (const tween of this._add.slice()) if (obj === tween.target) this.remove(tween);
19885
19850
  }
19886
19851
  /**
19887
19852
  * Add a tween to the manager.
@@ -19904,6 +19869,7 @@ var TweenManager = class {
19904
19869
  * @param {Tween | null | undefined} tween - The tween to remove.
19905
19870
  */
19906
19871
  remove(tween) {
19872
+ if (!tween) return;
19907
19873
  let i = this._tweens.indexOf(tween);
19908
19874
  if (i !== -1) this._tweens[i].pendingDelete = true;
19909
19875
  else {
@@ -19944,28 +19910,28 @@ var TweenManager = class {
19944
19910
  * This method pauses all active tweens.
19945
19911
  */
19946
19912
  _pauseAll() {
19947
- for (let i = this._tweens.length - 1; i >= 0; i -= 1) this._tweens[i]._pause();
19913
+ for (const tween of this._tweens) tween._pause();
19948
19914
  }
19949
19915
  /**
19950
19916
  * Resume all tweens managed by this manager.
19951
19917
  * This method resumes all paused tweens.
19952
19918
  */
19953
19919
  _resumeAll() {
19954
- for (let i = this._tweens.length - 1; i >= 0; i -= 1) this._tweens[i]._resume();
19920
+ for (const tween of this._tweens) tween._resume();
19955
19921
  }
19956
19922
  /**
19957
19923
  * Pause all tweens managed by this manager.
19958
19924
  * This method pauses all active tweens.
19959
19925
  */
19960
19926
  pauseAll() {
19961
- for (let i = this._tweens.length - 1; i >= 0; i -= 1) this._tweens[i].pause();
19927
+ for (const tween of this._tweens) tween.pause();
19962
19928
  }
19963
19929
  /**
19964
19930
  * Resume all tweens managed by this manager.
19965
19931
  * This method resumes all paused tweens.
19966
19932
  */
19967
19933
  resumeAll() {
19968
- for (let i = this._tweens.length - 1; i >= 0; i -= 1) this._tweens[i].resume(true);
19934
+ for (const tween of this._tweens) tween.resume();
19969
19935
  }
19970
19936
  };
19971
19937
  //#endregion