@vpmedia/phaser 1.115.0 → 1.117.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 (193) hide show
  1. package/dist/index.js +56 -96
  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 +15 -14
  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 +10 -9
  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 +20 -20
  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.map +1 -1
  20. package/dist/phaser/core/input_pointer.d.ts +19 -8
  21. package/dist/phaser/core/input_pointer.d.ts.map +1 -1
  22. package/dist/phaser/core/input_touch.d.ts.map +1 -1
  23. package/dist/phaser/core/loader.d.ts.map +1 -1
  24. package/dist/phaser/core/raf.d.ts.map +1 -1
  25. package/dist/phaser/core/scale_manager.d.ts +38 -13
  26. package/dist/phaser/core/scale_manager.d.ts.map +1 -1
  27. package/dist/phaser/core/scene.d.ts.map +1 -1
  28. package/dist/phaser/core/scene_manager.d.ts.map +1 -1
  29. package/dist/phaser/core/signal.d.ts.map +1 -1
  30. package/dist/phaser/core/signal_binding.d.ts.map +1 -1
  31. package/dist/phaser/core/sound.d.ts +2 -2
  32. package/dist/phaser/core/sound.d.ts.map +1 -1
  33. package/dist/phaser/core/sound_manager.d.ts +24 -22
  34. package/dist/phaser/core/sound_manager.d.ts.map +1 -1
  35. package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
  36. package/dist/phaser/core/stage.d.ts.map +1 -1
  37. package/dist/phaser/core/time.d.ts.map +1 -1
  38. package/dist/phaser/core/timer.d.ts +1 -1
  39. package/dist/phaser/core/timer.d.ts.map +1 -1
  40. package/dist/phaser/core/tween.d.ts.map +1 -1
  41. package/dist/phaser/core/tween_data.d.ts +26 -26
  42. package/dist/phaser/core/tween_data.d.ts.map +1 -1
  43. package/dist/phaser/core/tween_manager.d.ts.map +1 -1
  44. package/dist/phaser/core/world.d.ts.map +1 -1
  45. package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
  46. package/dist/phaser/display/button.d.ts.map +1 -1
  47. package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
  48. package/dist/phaser/display/canvas/graphics.d.ts.map +1 -1
  49. package/dist/phaser/display/canvas/masker.d.ts.map +1 -1
  50. package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
  51. package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
  52. package/dist/phaser/display/canvas/tinter.d.ts +3 -2
  53. package/dist/phaser/display/canvas/tinter.d.ts.map +1 -1
  54. package/dist/phaser/display/canvas/util.d.ts.map +1 -1
  55. package/dist/phaser/display/display_object.d.ts.map +1 -1
  56. package/dist/phaser/display/graphics.d.ts.map +1 -1
  57. package/dist/phaser/display/graphics_data.d.ts.map +1 -1
  58. package/dist/phaser/display/graphics_data_util.d.ts.map +1 -1
  59. package/dist/phaser/display/group.d.ts.map +1 -1
  60. package/dist/phaser/display/image.d.ts +2 -2
  61. package/dist/phaser/display/image.d.ts.map +1 -1
  62. package/dist/phaser/display/sprite_util.d.ts.map +1 -1
  63. package/dist/phaser/display/text.d.ts.map +1 -1
  64. package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
  65. package/dist/phaser/display/webgl/base_texture.d.ts +12 -10
  66. package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
  67. package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
  68. package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
  69. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +13 -12
  70. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
  71. package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
  72. package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
  73. package/dist/phaser/display/webgl/graphics.d.ts +9 -7
  74. package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
  75. package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
  76. package/dist/phaser/display/webgl/mask_manager.d.ts.map +1 -1
  77. package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
  78. package/dist/phaser/display/webgl/renderer.d.ts +12 -10
  79. package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
  80. package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
  81. package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
  82. package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
  83. package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
  84. package/dist/phaser/display/webgl/texture.d.ts +18 -33
  85. package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
  86. package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
  87. package/dist/phaser/display/webgl/util.d.ts.map +1 -1
  88. package/dist/phaser/geom/circle.d.ts.map +1 -1
  89. package/dist/phaser/geom/ellipse.d.ts.map +1 -1
  90. package/dist/phaser/geom/line.d.ts.map +1 -1
  91. package/dist/phaser/geom/matrix.d.ts +1 -1
  92. package/dist/phaser/geom/matrix.d.ts.map +1 -1
  93. package/dist/phaser/geom/point.d.ts.map +1 -1
  94. package/dist/phaser/geom/polygon.d.ts.map +1 -1
  95. package/dist/phaser/geom/rectangle.d.ts.map +1 -1
  96. package/dist/phaser/geom/rounded_rectangle.d.ts.map +1 -1
  97. package/dist/phaser/geom/util/circle.d.ts.map +1 -1
  98. package/dist/phaser/geom/util/ellipse.d.ts.map +1 -1
  99. package/dist/phaser/geom/util/line.d.ts +5 -4
  100. package/dist/phaser/geom/util/line.d.ts.map +1 -1
  101. package/dist/phaser/geom/util/matrix.d.ts.map +1 -1
  102. package/dist/phaser/geom/util/point.d.ts.map +1 -1
  103. package/dist/phaser/geom/util/polygon.d.ts.map +1 -1
  104. package/dist/phaser/geom/util/rectangle.d.ts +10 -1
  105. package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
  106. package/dist/phaser/geom/util/rounded_rectangle.d.ts.map +1 -1
  107. package/package.json +1 -1
  108. package/src/phaser/core/animation.ts +20 -20
  109. package/src/phaser/core/animation_manager.ts +27 -24
  110. package/src/phaser/core/animation_parser.ts +2 -2
  111. package/src/phaser/core/array_set.ts +7 -7
  112. package/src/phaser/core/cache.ts +55 -51
  113. package/src/phaser/core/callback_context.test.ts +70 -0
  114. package/src/phaser/core/device_util.ts +13 -13
  115. package/src/phaser/core/dom.ts +26 -22
  116. package/src/phaser/core/factory.ts +6 -6
  117. package/src/phaser/core/game.ts +10 -10
  118. package/src/phaser/core/input.ts +37 -39
  119. package/src/phaser/core/input_handler.ts +90 -93
  120. package/src/phaser/core/input_mouse.ts +19 -19
  121. package/src/phaser/core/input_mspointer.ts +15 -15
  122. package/src/phaser/core/input_pointer.ts +37 -28
  123. package/src/phaser/core/input_touch.ts +17 -17
  124. package/src/phaser/core/loader.ts +52 -52
  125. package/src/phaser/core/loader_parser.ts +3 -3
  126. package/src/phaser/core/raf.ts +3 -3
  127. package/src/phaser/core/scale_manager.ts +86 -67
  128. package/src/phaser/core/scene.ts +7 -7
  129. package/src/phaser/core/scene_manager.ts +16 -16
  130. package/src/phaser/core/signal.ts +29 -19
  131. package/src/phaser/core/signal_binding.ts +4 -4
  132. package/src/phaser/core/sound.ts +17 -17
  133. package/src/phaser/core/sound_manager.ts +71 -72
  134. package/src/phaser/core/sound_sprite.ts +1 -1
  135. package/src/phaser/core/stage.ts +7 -7
  136. package/src/phaser/core/time.ts +16 -16
  137. package/src/phaser/core/timer.ts +36 -26
  138. package/src/phaser/core/tween.ts +23 -23
  139. package/src/phaser/core/tween_data.ts +41 -37
  140. package/src/phaser/core/tween_manager.ts +11 -11
  141. package/src/phaser/core/world.ts +1 -1
  142. package/src/phaser/display/bitmap_text.ts +13 -13
  143. package/src/phaser/display/button.ts +13 -13
  144. package/src/phaser/display/canvas/buffer.ts +3 -3
  145. package/src/phaser/display/canvas/graphics.ts +3 -3
  146. package/src/phaser/display/canvas/masker.ts +2 -2
  147. package/src/phaser/display/canvas/pool.ts +6 -6
  148. package/src/phaser/display/canvas/renderer.ts +6 -6
  149. package/src/phaser/display/canvas/tinter.ts +39 -8
  150. package/src/phaser/display/canvas/util.ts +15 -9
  151. package/src/phaser/display/display_object.ts +38 -38
  152. package/src/phaser/display/graphics.ts +30 -30
  153. package/src/phaser/display/graphics_data.ts +1 -1
  154. package/src/phaser/display/graphics_data_util.ts +1 -1
  155. package/src/phaser/display/group.ts +16 -16
  156. package/src/phaser/display/image.ts +30 -26
  157. package/src/phaser/display/sprite_util.ts +12 -4
  158. package/src/phaser/display/text.ts +55 -55
  159. package/src/phaser/display/webgl/abstract_filter.ts +1 -1
  160. package/src/phaser/display/webgl/base_texture.ts +22 -18
  161. package/src/phaser/display/webgl/blend_manager.ts +3 -3
  162. package/src/phaser/display/webgl/earcut.ts +3 -3
  163. package/src/phaser/display/webgl/fast_sprite_batch.ts +26 -24
  164. package/src/phaser/display/webgl/filter_manager.ts +7 -7
  165. package/src/phaser/display/webgl/filter_texture.ts +3 -3
  166. package/src/phaser/display/webgl/graphics.ts +43 -41
  167. package/src/phaser/display/webgl/graphics_data.ts +2 -2
  168. package/src/phaser/display/webgl/mask_manager.ts +2 -2
  169. package/src/phaser/display/webgl/render_texture.ts +6 -6
  170. package/src/phaser/display/webgl/renderer.ts +20 -25
  171. package/src/phaser/display/webgl/shader/normal.ts +3 -3
  172. package/src/phaser/display/webgl/shader_manager.ts +2 -2
  173. package/src/phaser/display/webgl/sprite_batch.ts +9 -9
  174. package/src/phaser/display/webgl/stencil_manager.ts +4 -4
  175. package/src/phaser/display/webgl/texture.ts +23 -42
  176. package/src/phaser/display/webgl/texture_util.ts +2 -2
  177. package/src/phaser/display/webgl/util.ts +11 -7
  178. package/src/phaser/geom/circle.ts +21 -21
  179. package/src/phaser/geom/ellipse.ts +7 -7
  180. package/src/phaser/geom/line.ts +29 -29
  181. package/src/phaser/geom/matrix.ts +13 -13
  182. package/src/phaser/geom/point.ts +36 -30
  183. package/src/phaser/geom/polygon.ts +6 -6
  184. package/src/phaser/geom/rectangle.ts +42 -42
  185. package/src/phaser/geom/rounded_rectangle.ts +2 -2
  186. package/src/phaser/geom/util/circle.ts +7 -7
  187. package/src/phaser/geom/util/ellipse.ts +1 -1
  188. package/src/phaser/geom/util/line.ts +13 -5
  189. package/src/phaser/geom/util/matrix.ts +3 -3
  190. package/src/phaser/geom/util/point.ts +20 -20
  191. package/src/phaser/geom/util/polygon.ts +1 -1
  192. package/src/phaser/geom/util/rectangle.ts +34 -17
  193. package/src/phaser/geom/util/rounded_rectangle.ts +1 -1
@@ -137,7 +137,7 @@ export class Text extends Image {
137
137
  /**
138
138
  * Destroys this text object and cleans up resources.
139
139
  */
140
- public override destroy() {
140
+ public override destroy(): void {
141
141
  this.texture.destroy(true);
142
142
  remove(this);
143
143
  this.textBounds = null;
@@ -159,7 +159,7 @@ export class Text extends Image {
159
159
  * @param {boolean} shadowFill - Whether to apply the shadow to the fill.
160
160
  * @returns {Text} This Text object for chaining.
161
161
  */
162
- public setShadow(x = 0, y = 0, color = 'rgba(0, 0, 0, 1)', blur = 0, shadowStroke = true, shadowFill = true) {
162
+ public setShadow(x = 0, y = 0, color = 'rgba(0, 0, 0, 1)', blur = 0, shadowStroke = true, shadowFill = true): this {
163
163
  this.style.shadowOffsetX = x;
164
164
  this.style.shadowOffsetY = y;
165
165
  this.style.shadowColor = color;
@@ -176,7 +176,7 @@ export class Text extends Image {
176
176
  * @param {boolean} update - Whether to update the text immediately.
177
177
  * @returns {Text} This Text object for chaining.
178
178
  */
179
- public setStyle(style: TextStyle | null = null, update = false) {
179
+ public setStyle(style: TextStyle | null = null, update = false): this {
180
180
  const source: TextStyle = structuredClone(style) ?? {};
181
181
  const resolved: ResolvedTextStyle = {
182
182
  ...source,
@@ -226,7 +226,7 @@ export class Text extends Image {
226
226
  /**
227
227
  * Updates the text content and renders it to the canvas.
228
228
  */
229
- public updateText() {
229
+ public updateText(): void {
230
230
  this.texture.baseTexture.resolution = this._res;
231
231
  this.context.font = this.style.font;
232
232
  let outputText: any = this.text;
@@ -393,7 +393,7 @@ export class Text extends Image {
393
393
  * @param {number} y - The y position to start rendering from.
394
394
  * @param {boolean} fill - True to fill the text, false to stroke it.
395
395
  */
396
- public renderTabLine(line: string, x: number, y: number, fill: boolean) {
396
+ public renderTabLine(line: string, x: number, y: number, fill: boolean): void {
397
397
  const text = line.split(/(?:\t)/);
398
398
  const { tabs } = this.style;
399
399
  let snap = 0;
@@ -429,7 +429,7 @@ export class Text extends Image {
429
429
  * Updates the shadow properties for this text.
430
430
  * @param {string} state - The shadow state to update ('stroke' or 'fill').
431
431
  */
432
- public updateShadow(state: boolean) {
432
+ public updateShadow(state: boolean): void {
433
433
  if (state) {
434
434
  this.context.shadowOffsetX = this.style.shadowOffsetX;
435
435
  this.context.shadowOffsetY = this.style.shadowOffsetY;
@@ -448,7 +448,7 @@ export class Text extends Image {
448
448
  * @param {string} line - The line of text to measure.
449
449
  * @returns {number} The width of the line in pixels.
450
450
  */
451
- public measureLine(line: string) {
451
+ public measureLine(line: string): number {
452
452
  let lineLength = 0;
453
453
  for (const letter of line) {
454
454
  if (this.fontWeights.length > 0 || this.fontStyles.length > 0) {
@@ -489,7 +489,7 @@ export class Text extends Image {
489
489
  * @param {number} x - The x position to start updating from.
490
490
  * @param {number} y - The y position to start updating from.
491
491
  */
492
- public updateLine(line: string, x: number, y: number) {
492
+ public updateLine(line: string, x: number, y: number): void {
493
493
  for (const letter of line) {
494
494
  if (this.fontWeights.length > 0 || this.fontStyles.length > 0) {
495
495
  const components = this.fontToComponents(this.context.font);
@@ -528,7 +528,7 @@ export class Text extends Image {
528
528
  * Clears all color values from this text object.
529
529
  * @returns {Text} This Text object for chaining.
530
530
  */
531
- public clearColors() {
531
+ public clearColors(): this {
532
532
  this.colors = [];
533
533
  this.strokeColors = [];
534
534
  this.dirty = true;
@@ -539,7 +539,7 @@ export class Text extends Image {
539
539
  * Clears all font style values from this text object.
540
540
  * @returns {Text} This Text object for chaining.
541
541
  */
542
- public clearFontValues() {
542
+ public clearFontValues(): this {
543
543
  this.fontStyles = [];
544
544
  this.fontWeights = [];
545
545
  this.dirty = true;
@@ -552,7 +552,7 @@ export class Text extends Image {
552
552
  * @param {number} position - The character position to apply the color at.
553
553
  * @returns {Text} This Text object for chaining.
554
554
  */
555
- public addColor(color: string, position: number) {
555
+ public addColor(color: string, position: number): this {
556
556
  this.colors[position] = color;
557
557
  this.dirty = true;
558
558
  return this;
@@ -564,7 +564,7 @@ export class Text extends Image {
564
564
  * @param {number} position - The character position to apply the stroke color at.
565
565
  * @returns {Text} This Text object for chaining.
566
566
  */
567
- public addStrokeColor(color: string, position: number) {
567
+ public addStrokeColor(color: string, position: number): this {
568
568
  this.strokeColors[position] = color;
569
569
  this.dirty = true;
570
570
  return this;
@@ -576,7 +576,7 @@ export class Text extends Image {
576
576
  * @param {number} position - The character position to apply the font style at.
577
577
  * @returns {Text} This Text object for chaining.
578
578
  */
579
- public addFontStyle(style: string, position: number) {
579
+ public addFontStyle(style: string, position: number): this {
580
580
  this.fontStyles[position] = style;
581
581
  this.dirty = true;
582
582
  return this;
@@ -588,7 +588,7 @@ export class Text extends Image {
588
588
  * @param {number} position - The character position to apply the font weight at.
589
589
  * @returns {Text} This Text object for chaining.
590
590
  */
591
- public addFontWeight(weight: string, position: number) {
591
+ public addFontWeight(weight: string, position: number): this {
592
592
  this.fontWeights[position] = weight;
593
593
  this.dirty = true;
594
594
  return this;
@@ -599,7 +599,7 @@ export class Text extends Image {
599
599
  * @param {string} text - The text to precalculate word wrap for.
600
600
  * @returns {string[]} The wrapped lines of text.
601
601
  */
602
- public precalculateWordWrap(text: string) {
602
+ public precalculateWordWrap(text: string): string[] {
603
603
  this.texture.baseTexture.resolution = this._res;
604
604
  this.context.font = this.style.font;
605
605
  const wrappedLines = this.runWordWrap(text);
@@ -611,7 +611,7 @@ export class Text extends Image {
611
611
  * @param {string} text - The text to run word wrap on.
612
612
  * @returns {string} The wrapped text.
613
613
  */
614
- public runWordWrap(text: string) {
614
+ public runWordWrap(text: string): string {
615
615
  if (this.useAdvancedWrap) {
616
616
  return this.advancedWordWrap(text);
617
617
  }
@@ -624,7 +624,7 @@ export class Text extends Image {
624
624
  * @returns {string} The wrapped text.
625
625
  * @throws {Error} If the wordWrapWidth setting is less than a single character.
626
626
  */
627
- public advancedWordWrap(text: string) {
627
+ public advancedWordWrap(text: string): string {
628
628
  const { context } = this;
629
629
  const { wordWrapWidth } = this.style;
630
630
  let output = '';
@@ -706,7 +706,7 @@ export class Text extends Image {
706
706
  * @param {string} text - The text to run basic word wrap on.
707
707
  * @returns {string} The wrapped text.
708
708
  */
709
- public basicWordWrap(text: string) {
709
+ public basicWordWrap(text: string): string {
710
710
  let result = '';
711
711
  const lines = text.split('\n');
712
712
  for (let i = 0; i < lines.length; i += 1) {
@@ -738,7 +738,7 @@ export class Text extends Image {
738
738
  * Updates the font properties based on the given components.
739
739
  * @param {object} components - The font components to update from.
740
740
  */
741
- public updateFont(components: FontComponents) {
741
+ public updateFont(components: FontComponents): void {
742
742
  const font = this.componentsToFont(components);
743
743
  if (this.style.font !== font) {
744
744
  this.style.font = font;
@@ -791,7 +791,7 @@ export class Text extends Image {
791
791
  * @param {object} components - The font components to convert.
792
792
  * @returns {string} The font string.
793
793
  */
794
- public componentsToFont(components: FontComponents) {
794
+ public componentsToFont(components: FontComponents): string {
795
795
  const parts = [];
796
796
  let v;
797
797
  v = components.fontStyle;
@@ -827,7 +827,7 @@ export class Text extends Image {
827
827
  * @param {boolean} immediate - If true, updates the text immediately.
828
828
  * @returns {Text} This Text object for chaining.
829
829
  */
830
- public setText(text: string | number, immediate = false) {
830
+ public setText(text: string | number, immediate = false): this {
831
831
  this.text = text.toString() ?? '';
832
832
  if (immediate) {
833
833
  this.updateText();
@@ -842,7 +842,7 @@ export class Text extends Image {
842
842
  * @param {string[]|string[][]} list - The list of text to parse.
843
843
  * @returns {Text} This Text object for chaining.
844
844
  */
845
- public parseList(list: any) {
845
+ public parseList(list: any): this {
846
846
  if (!Array.isArray(list)) {
847
847
  return this;
848
848
  }
@@ -873,7 +873,7 @@ export class Text extends Image {
873
873
  * @param {number} height - The height of the bounds.
874
874
  * @returns {Text} This Text object for chaining.
875
875
  */
876
- public setTextBounds(x: number, y: number, width: number, height: number) {
876
+ public setTextBounds(x: number, y: number, width: number, height: number): this {
877
877
  if (x === undefined) {
878
878
  this.textBounds = null;
879
879
  } else {
@@ -893,7 +893,7 @@ export class Text extends Image {
893
893
  /**
894
894
  * Updates the texture of this object.
895
895
  */
896
- public updateTexture() {
896
+ public updateTexture(): void {
897
897
  const base = this.texture.baseTexture;
898
898
  const { crop } = this.texture;
899
899
  const { frame } = this.texture;
@@ -936,7 +936,7 @@ export class Text extends Image {
936
936
  * Renders this text object using WebGL.
937
937
  * @param {object} renderSession - The render session to use.
938
938
  */
939
- public override renderWebGL(renderSession: RenderSession) {
939
+ public override renderWebGL(renderSession: RenderSession): void {
940
940
  if (this.dirty) {
941
941
  this.updateText();
942
942
  this.dirty = false;
@@ -948,7 +948,7 @@ export class Text extends Image {
948
948
  * Renders this text object using Canvas.
949
949
  * @param {object} renderSession - The render session to use.
950
950
  */
951
- public override renderCanvas(renderSession: RenderSession) {
951
+ public override renderCanvas(renderSession: RenderSession): void {
952
952
  if (this.dirty) {
953
953
  this.updateText();
954
954
  this.dirty = false;
@@ -960,7 +960,7 @@ export class Text extends Image {
960
960
  * Gets the font properties cache object.
961
961
  * @returns {{[key: string]: {ascent: number, descent: number, fontSize: number}}} The font properties cache.
962
962
  */
963
- public getFontPropertiesCache() {
963
+ public getFontPropertiesCache(): Record<string, FontProperties> {
964
964
  globalThis.PhaserRegistry.fontPropertiesCache ??= {};
965
965
  return globalThis.PhaserRegistry.fontPropertiesCache;
966
966
  }
@@ -969,7 +969,7 @@ export class Text extends Image {
969
969
  * Gets the font properties canvas element.
970
970
  * @returns {HTMLCanvasElement} The font properties canvas element.
971
971
  */
972
- public getFontPropertiesCanvas() {
972
+ public getFontPropertiesCanvas(): HTMLCanvasElement {
973
973
  globalThis.PhaserRegistry.fontPropertiesCanvas ??= document.createElement('canvas');
974
974
  return globalThis.PhaserRegistry.fontPropertiesCanvas;
975
975
  }
@@ -978,7 +978,7 @@ export class Text extends Image {
978
978
  * Gets the font properties canvas context.
979
979
  * @returns {CanvasRenderingContext2D} The font properties canvas context.
980
980
  */
981
- public getFontPropertiesContext() {
981
+ public getFontPropertiesContext(): CanvasRenderingContext2D {
982
982
  if (!globalThis.PhaserRegistry.fontPropertiesContext) {
983
983
  const canvas = this.getFontPropertiesCanvas();
984
984
  const context = canvas.getContext('2d', { willReadFrequently: true });
@@ -995,7 +995,7 @@ export class Text extends Image {
995
995
  * @param {string} font - The font to determine properties for.
996
996
  * @returns {object} The font properties.
997
997
  */
998
- public determineFontProperties(font: string) {
998
+ public determineFontProperties(font: string): FontProperties {
999
999
  const fontPropertiesCache = this.getFontPropertiesCache();
1000
1000
  const cached = fontPropertiesCache[font];
1001
1001
  if (cached) {
@@ -1020,7 +1020,7 @@ export class Text extends Image {
1020
1020
  * @param {string} fontStyle - The font style to determine properties for.
1021
1021
  * @returns {{ascent: number, descent: number, fontSize: number}} The font properties.
1022
1022
  */
1023
- public determineFontPropertiesFallback(fontStyle: string) {
1023
+ public determineFontPropertiesFallback(fontStyle: string): FontProperties {
1024
1024
  const fontPropertiesCache = this.getFontPropertiesCache();
1025
1025
  const cached = fontPropertiesCache[fontStyle];
1026
1026
  if (!cached) {
@@ -1102,7 +1102,7 @@ export class Text extends Image {
1102
1102
  * @param {Matrix} matrix - The transformation matrix to use.
1103
1103
  * @returns {Rectangle} The bounds of this text object.
1104
1104
  */
1105
- public override getBounds(matrix: Matrix | null = null) {
1105
+ public override getBounds(matrix: Matrix | null = null): Rectangle {
1106
1106
  if (this.dirty) {
1107
1107
  this.updateText();
1108
1108
  this.dirty = false;
@@ -1136,7 +1136,7 @@ export class Text extends Image {
1136
1136
  * Gets the CSS font string for this object.
1137
1137
  * @returns {string} The CSS font string.
1138
1138
  */
1139
- public get cssFont() {
1139
+ public get cssFont(): string {
1140
1140
  return this.componentsToFont(this._fontComponents);
1141
1141
  }
1142
1142
 
@@ -1153,7 +1153,7 @@ export class Text extends Image {
1153
1153
  * Gets the font family of this object.
1154
1154
  * @returns {number} The font family.
1155
1155
  */
1156
- public get font() {
1156
+ public get font(): string {
1157
1157
  return this._fontComponents.fontFamily ?? '';
1158
1158
  }
1159
1159
 
@@ -1220,7 +1220,7 @@ export class Text extends Image {
1220
1220
  * Gets the font style of this object.
1221
1221
  * @returns {string} The font style.
1222
1222
  */
1223
- public get fontStyle() {
1223
+ public get fontStyle(): string {
1224
1224
  return this._fontComponents.fontStyle ?? 'normal';
1225
1225
  }
1226
1226
 
@@ -1237,7 +1237,7 @@ export class Text extends Image {
1237
1237
  * Gets the font variant of this object.
1238
1238
  * @returns {string} The font variant.
1239
1239
  */
1240
- public get fontVariant() {
1240
+ public get fontVariant(): string {
1241
1241
  return this._fontComponents.fontVariant ?? 'normal';
1242
1242
  }
1243
1243
 
@@ -1254,7 +1254,7 @@ export class Text extends Image {
1254
1254
  * Gets the fill color of this object.
1255
1255
  * @returns {number} The fill color.
1256
1256
  */
1257
- public get fill() {
1257
+ public get fill(): string {
1258
1258
  return this.style.fill;
1259
1259
  }
1260
1260
 
@@ -1273,7 +1273,7 @@ export class Text extends Image {
1273
1273
  * Gets the alignment of this object.
1274
1274
  * @returns {string} The text alignment.
1275
1275
  */
1276
- public get align() {
1276
+ public get align(): string {
1277
1277
  return this.style.align;
1278
1278
  }
1279
1279
 
@@ -1292,7 +1292,7 @@ export class Text extends Image {
1292
1292
  * Gets the resolution of this object.
1293
1293
  * @returns {number} The resolution.
1294
1294
  */
1295
- public get resolution() {
1295
+ public get resolution(): number {
1296
1296
  return this._res;
1297
1297
  }
1298
1298
 
@@ -1311,7 +1311,7 @@ export class Text extends Image {
1311
1311
  * Gets the tabs setting of this object.
1312
1312
  * @returns {number} The tabs setting.
1313
1313
  */
1314
- public get tabs() {
1314
+ public get tabs(): number | number[] {
1315
1315
  return this.style.tabs;
1316
1316
  }
1317
1317
 
@@ -1330,7 +1330,7 @@ export class Text extends Image {
1330
1330
  * Gets the horizontal bounds alignment of this object.
1331
1331
  * @returns {number} The horizontal bounds alignment.
1332
1332
  */
1333
- public get boundsAlignH() {
1333
+ public get boundsAlignH(): string {
1334
1334
  return this.style.boundsAlignH;
1335
1335
  }
1336
1336
 
@@ -1349,7 +1349,7 @@ export class Text extends Image {
1349
1349
  * Gets the vertical bounds alignment of this object.
1350
1350
  * @returns {number} The vertical bounds alignment.
1351
1351
  */
1352
- public get boundsAlignV() {
1352
+ public get boundsAlignV(): string {
1353
1353
  return this.style.boundsAlignV;
1354
1354
  }
1355
1355
 
@@ -1368,7 +1368,7 @@ export class Text extends Image {
1368
1368
  * Gets the stroke color of this object.
1369
1369
  * @returns {number} The stroke color.
1370
1370
  */
1371
- public get stroke() {
1371
+ public get stroke(): string {
1372
1372
  return this.style.stroke;
1373
1373
  }
1374
1374
 
@@ -1387,7 +1387,7 @@ export class Text extends Image {
1387
1387
  * Gets the stroke thickness of this object.
1388
1388
  * @returns {number} The stroke thickness.
1389
1389
  */
1390
- public get strokeThickness() {
1390
+ public get strokeThickness(): number {
1391
1391
  return this.style.strokeThickness;
1392
1392
  }
1393
1393
 
@@ -1406,7 +1406,7 @@ export class Text extends Image {
1406
1406
  * Gets the word wrap setting of this object.
1407
1407
  * @returns {number} The word wrap setting.
1408
1408
  */
1409
- public get wordWrap() {
1409
+ public get wordWrap(): boolean {
1410
1410
  return this.style.wordWrap;
1411
1411
  }
1412
1412
 
@@ -1425,7 +1425,7 @@ export class Text extends Image {
1425
1425
  * Gets the word wrap width of this object.
1426
1426
  * @returns {number} The word wrap width.
1427
1427
  */
1428
- public get wordWrapWidth() {
1428
+ public get wordWrapWidth(): number {
1429
1429
  return this.style.wordWrapWidth;
1430
1430
  }
1431
1431
 
@@ -1444,7 +1444,7 @@ export class Text extends Image {
1444
1444
  * Gets the line spacing of this object.
1445
1445
  * @returns {number} The line spacing.
1446
1446
  */
1447
- public get lineSpacing() {
1447
+ public get lineSpacing(): number {
1448
1448
  return this._lineSpacing;
1449
1449
  }
1450
1450
 
@@ -1466,7 +1466,7 @@ export class Text extends Image {
1466
1466
  * Gets the shadow offset X of this object.
1467
1467
  * @returns {number} The shadow offset X.
1468
1468
  */
1469
- public get shadowOffsetX() {
1469
+ public get shadowOffsetX(): number {
1470
1470
  return this.style.shadowOffsetX;
1471
1471
  }
1472
1472
 
@@ -1485,7 +1485,7 @@ export class Text extends Image {
1485
1485
  * Gets the shadow offset Y of this object.
1486
1486
  * @returns {number} The shadow offset Y.
1487
1487
  */
1488
- public get shadowOffsetY() {
1488
+ public get shadowOffsetY(): number {
1489
1489
  return this.style.shadowOffsetY;
1490
1490
  }
1491
1491
 
@@ -1504,7 +1504,7 @@ export class Text extends Image {
1504
1504
  * Gets the shadow color of this object.
1505
1505
  * @returns {number} The shadow color.
1506
1506
  */
1507
- public get shadowColor() {
1507
+ public get shadowColor(): string {
1508
1508
  return this.style.shadowColor;
1509
1509
  }
1510
1510
 
@@ -1523,7 +1523,7 @@ export class Text extends Image {
1523
1523
  * Gets the shadow blur of this object.
1524
1524
  * @returns {number} The shadow blur.
1525
1525
  */
1526
- public get shadowBlur() {
1526
+ public get shadowBlur(): number {
1527
1527
  return this.style.shadowBlur;
1528
1528
  }
1529
1529
 
@@ -1542,7 +1542,7 @@ export class Text extends Image {
1542
1542
  * Gets the shadow stroke setting of this object.
1543
1543
  * @returns {number} The shadow stroke setting.
1544
1544
  */
1545
- public get shadowStroke() {
1545
+ public get shadowStroke(): boolean {
1546
1546
  return this.style.shadowStroke ?? false;
1547
1547
  }
1548
1548
 
@@ -1561,7 +1561,7 @@ export class Text extends Image {
1561
1561
  * Gets the shadow fill setting of this object.
1562
1562
  * @returns {number} The shadow fill setting.
1563
1563
  */
1564
- public get shadowFill() {
1564
+ public get shadowFill(): boolean {
1565
1565
  return this.style.shadowFill ?? false;
1566
1566
  }
1567
1567
 
@@ -1580,7 +1580,7 @@ export class Text extends Image {
1580
1580
  * Gets the width of this object.
1581
1581
  * @returns {number} The width in pixels.
1582
1582
  */
1583
- public override get width() {
1583
+ public override get width(): number {
1584
1584
  if (this.dirty) {
1585
1585
  this.updateText();
1586
1586
  this.dirty = false;
@@ -1601,7 +1601,7 @@ export class Text extends Image {
1601
1601
  * Gets the height of this object.
1602
1602
  * @returns {number} The height in pixels.
1603
1603
  */
1604
- public override get height() {
1604
+ public override get height(): number {
1605
1605
  if (this.dirty) {
1606
1606
  this.updateText();
1607
1607
  this.dirty = false;
@@ -23,7 +23,7 @@ export class AbstractFilter {
23
23
  /**
24
24
  * Initializes the filter.
25
25
  */
26
- public syncUniforms() {
26
+ public syncUniforms(): void {
27
27
  for (let i = 0, j = this.shaders.length; i < j; i += 1) {
28
28
  this.shaders[i].dirty = true;
29
29
  }
@@ -1,24 +1,27 @@
1
+ /** What a base texture is uploaded from: a loaded image or a canvas the engine drew into. */
2
+ export type TextureSource = HTMLImageElement | HTMLCanvasElement;
3
+
1
4
  import { removeByCanvas } from '../canvas/pool.js';
2
5
 
3
6
  export class BaseTexture {
4
7
  public resolution: number = 1;
5
8
  public width: number = 100;
6
9
  public height: number = 100;
7
- public scaleMode!: any;
8
- public hasLoaded!: any;
9
- public source!: any;
10
- public premultipliedAlpha!: any;
11
- public _glTextures!: any;
12
- public mipmap!: any;
13
- public skipRender!: any;
14
- public _powerOf2!: any;
15
- public _dirty!: any;
10
+ public scaleMode!: number;
11
+ public hasLoaded!: boolean;
12
+ public source!: TextureSource | null;
13
+ public premultipliedAlpha!: boolean;
14
+ public _glTextures!: (WebGLTexture | null)[];
15
+ public mipmap!: boolean;
16
+ public skipRender!: boolean;
17
+ public _powerOf2!: boolean;
18
+ public _dirty!: boolean[];
16
19
  /**
17
20
  * Updates the base texture with a new source.
18
21
  * @param {HTMLCanvasElement} source - The new canvas element to use as the texture source.
19
22
  * @param {number} [scaleMode] - The scale mode to use for the texture.
20
23
  */
21
- public constructor(source: any, scaleMode?: any) {
24
+ public constructor(source: TextureSource | null, scaleMode?: number) {
22
25
  this.scaleMode = scaleMode ?? globalThis.PhaserRegistry.TEXTURE_SCALE_MODE;
23
26
  this.hasLoaded = false;
24
27
  this.source = source;
@@ -29,10 +32,11 @@ export class BaseTexture {
29
32
  this._powerOf2 = false;
30
33
  this._dirty = [true, true, true, true];
31
34
  if (source) {
32
- if ((this.source.complete || this.source.getContext) && this.source.width && this.source.height) {
35
+ const loaded = source instanceof HTMLImageElement ? source.complete : true;
36
+ if (loaded && source.width && source.height) {
33
37
  this.hasLoaded = true;
34
- this.width = this.source.naturalWidth ?? this.source.width;
35
- this.height = this.source.naturalHeight ?? this.source.height;
38
+ this.width = source instanceof HTMLImageElement ? source.naturalWidth : source.width;
39
+ this.height = source instanceof HTMLImageElement ? source.naturalHeight : source.height;
36
40
  this.dirty();
37
41
  }
38
42
  }
@@ -43,7 +47,7 @@ export class BaseTexture {
43
47
  * @param {number} width - The new width of the texture.
44
48
  * @param {number} height - The new height of the texture.
45
49
  */
46
- public forceLoaded(width: number, height: number) {
50
+ public forceLoaded(width: number, height: number): void {
47
51
  this.hasLoaded = true;
48
52
  this.width = width;
49
53
  this.height = height;
@@ -53,8 +57,8 @@ export class BaseTexture {
53
57
  /**
54
58
  * Destroys the texture.
55
59
  */
56
- public destroy() {
57
- if (this.source) {
60
+ public destroy(): void {
61
+ if (this.source instanceof HTMLCanvasElement) {
58
62
  removeByCanvas(this.source);
59
63
  }
60
64
  this.source = null;
@@ -64,7 +68,7 @@ export class BaseTexture {
64
68
  /**
65
69
  * Marks the texture as dirty.
66
70
  */
67
- public dirty() {
71
+ public dirty(): void {
68
72
  for (let i = 0; i < this._glTextures.length; i += 1) {
69
73
  this._dirty[i] = true;
70
74
  }
@@ -73,7 +77,7 @@ export class BaseTexture {
73
77
  /**
74
78
  * Unloads the texture from the GPU.
75
79
  */
76
- public unloadFromGPU() {
80
+ public unloadFromGPU(): void {
77
81
  this.dirty();
78
82
  for (let i = this._glTextures.length - 1; i >= 0; i -= 1) {
79
83
  const glTexture = this._glTextures[i];
@@ -10,7 +10,7 @@ export class WebGLBlendModeManager {
10
10
  * Initializes the blend mode manager with a WebGL context.
11
11
  * @param {WebGLRenderingContext} gl - The WebGL rendering context.
12
12
  */
13
- public setContext(gl: WebGLRenderingContext) {
13
+ public setContext(gl: WebGLRenderingContext): void {
14
14
  this.gl = gl;
15
15
  }
16
16
 
@@ -19,7 +19,7 @@ export class WebGLBlendModeManager {
19
19
  * @param {number} blendMode - The blend mode to set.
20
20
  * @returns {boolean} True if the blend mode was set successfully, false otherwise.
21
21
  */
22
- public setBlendMode(blendMode: number) {
22
+ public setBlendMode(blendMode: number): boolean {
23
23
  if (this.currentBlendMode === blendMode) {
24
24
  return false;
25
25
  }
@@ -34,7 +34,7 @@ export class WebGLBlendModeManager {
34
34
  /**
35
35
  * Sets the blend mode for the WebGL context.
36
36
  */
37
- public destroy() {
37
+ public destroy(): void {
38
38
  this.gl = null;
39
39
  }
40
40
  }
@@ -89,7 +89,7 @@ export function compareX(a: Node, b: Node): number {
89
89
  * @param {number} size - The size of the bounding box.
90
90
  * @returns {number} The calculated distance from the point to the triangle edge.
91
91
  */
92
- export function zOrder(x: number, y: number, minX: number, minY: number, size: number) {
92
+ export function zOrder(x: number, y: number, minX: number, minY: number, size: number): number {
93
93
  // coords are transformed into non-negative 15-bit integer range
94
94
  x = (32_767 * (x - minX)) / size;
95
95
  y = (32_767 * (y - minY)) / size;
@@ -162,7 +162,7 @@ export function pointInTriangle(
162
162
  cy: number,
163
163
  px: number,
164
164
  py: number
165
- ) {
165
+ ): boolean {
166
166
  return (
167
167
  (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 &&
168
168
  (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 &&
@@ -655,7 +655,7 @@ export function earcutLinked(
655
655
  minY?: number,
656
656
  size?: number,
657
657
  pass?: number
658
- ) {
658
+ ): void {
659
659
  if (!ear) {
660
660
  return;
661
661
  }