@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
@@ -52,7 +52,7 @@ export class BitmapText extends DisplayObject {
52
52
  /**
53
53
  * Destroys this bitmap text and cleans up resources.
54
54
  */
55
- public override destroy() {
55
+ public override destroy(): void {
56
56
  this._prevAnchor = null!;
57
57
  this._glyphs = null!;
58
58
  this._text = null!;
@@ -63,7 +63,7 @@ export class BitmapText extends DisplayObject {
63
63
  /**
64
64
  * Called before the update cycle for this bitmap text.
65
65
  */
66
- public override preUpdate() {
66
+ public override preUpdate(): void {
67
67
  if (this.pendingDestroy) {
68
68
  this.destroy();
69
69
  return;
@@ -86,7 +86,7 @@ export class BitmapText extends DisplayObject {
86
86
  * Sets the text to display.
87
87
  * @param {string} text - The new text to display.
88
88
  */
89
- public setText(text: string) {
89
+ public setText(text: string): void {
90
90
  this.text = text;
91
91
  }
92
92
 
@@ -164,7 +164,7 @@ export class BitmapText extends DisplayObject {
164
164
  * @param {string} replace - The character to use for replacement of invalid characters (default: '').
165
165
  * @returns {string} The cleaned text.
166
166
  */
167
- public cleanText(text: string, replace = '') {
167
+ public cleanText(text: string, replace = ''): string {
168
168
  const data = this._data.font;
169
169
  if (!data) {
170
170
  return '';
@@ -189,7 +189,7 @@ export class BitmapText extends DisplayObject {
189
189
  /**
190
190
  * Updates the internal text rendering based on current properties and content.
191
191
  */
192
- public updateText() {
192
+ public updateText(): void {
193
193
  const data = this._data.font;
194
194
  if (!data) {
195
195
  return;
@@ -260,7 +260,7 @@ export class BitmapText extends DisplayObject {
260
260
  * Removes unused glyphs from the pool and returns the number removed.
261
261
  * @returns {number} The number of glyphs that were removed from the pool.
262
262
  */
263
- public purgeGlyphs() {
263
+ public purgeGlyphs(): number {
264
264
  const len = this._glyphs.length;
265
265
  const kept = [];
266
266
  for (const glyph of this._glyphs) {
@@ -295,7 +295,7 @@ export class BitmapText extends DisplayObject {
295
295
  * @param {number} _position - The character position to apply the color to.
296
296
  * @returns {BitmapText} This bitmap text instance for chaining.
297
297
  */
298
- public addColor(value: string, _position: number) {
298
+ public addColor(value: string, _position: number): this {
299
299
  const color = typeof value === 'string' ? Number.parseInt(value.replace('#', ''), 16) : value;
300
300
  if (color !== this._tint) {
301
301
  this._tint = color;
@@ -308,7 +308,7 @@ export class BitmapText extends DisplayObject {
308
308
  * Gets the text alignment property.
309
309
  * @returns {string} The current text alignment (left, center, right).
310
310
  */
311
- public get align() {
311
+ public get align(): string {
312
312
  return this._align;
313
313
  }
314
314
 
@@ -327,7 +327,7 @@ export class BitmapText extends DisplayObject {
327
327
  * Gets the tint color of this bitmap text.
328
328
  * @returns {number} The current tint color in RGB format.
329
329
  */
330
- public get tint() {
330
+ public get tint(): number {
331
331
  return this._tint;
332
332
  }
333
333
 
@@ -346,7 +346,7 @@ export class BitmapText extends DisplayObject {
346
346
  * Gets the fill color of this bitmap text as a hex string.
347
347
  * @returns {string} The current fill color in hex format.
348
348
  */
349
- public get fill() {
349
+ public get fill(): string {
350
350
  if (typeof this.tint === 'number') {
351
351
  let colorStr = this.tint.toString(16);
352
352
  while (colorStr.length < 6) {
@@ -369,7 +369,7 @@ export class BitmapText extends DisplayObject {
369
369
  * Gets the font key used by this bitmap text.
370
370
  * @returns {string} The current font key.
371
371
  */
372
- public get font() {
372
+ public get font(): string {
373
373
  return this._font;
374
374
  }
375
375
 
@@ -430,7 +430,7 @@ export class BitmapText extends DisplayObject {
430
430
  * Gets the maximum width of this bitmap text.
431
431
  * @returns {number} The current maximum width.
432
432
  */
433
- public get maxWidth() {
433
+ public get maxWidth(): number {
434
434
  return this._maxWidth;
435
435
  }
436
436
 
@@ -449,7 +449,7 @@ export class BitmapText extends DisplayObject {
449
449
  * Gets whether smoothing is enabled for this bitmap text's font.
450
450
  * @returns {boolean} True if smoothing is enabled, false otherwise.
451
451
  */
452
- public get smoothed() {
452
+ public get smoothed(): boolean {
453
453
  return !this._data.base.scaleMode;
454
454
  }
455
455
 
@@ -85,7 +85,7 @@ export class Button extends Image {
85
85
  /**
86
86
  * Destroys this button and cleans up resources.
87
87
  */
88
- public override destroy() {
88
+ public override destroy(): void {
89
89
  this._onOverFrame = null;
90
90
  this._onOutFrame = null;
91
91
  this._onDownFrame = null;
@@ -113,12 +113,12 @@ export class Button extends Image {
113
113
  * @param {boolean} isEnabled - Whether the button should be enabled (true) or disabled (false).
114
114
  * @param {boolean} isImmediate - Whether to change the state immediately or with a delay (default: false).
115
115
  */
116
- public setEnabled(isEnabled: boolean, isImmediate = false) {
116
+ public setEnabled(isEnabled: boolean, isImmediate = false): void {
117
117
  this.input.enabled = isEnabled;
118
118
  if (isImmediate) {
119
119
  this.changeStateFrame(isEnabled ? STATE_UP : STATE_DISABLED);
120
120
  } else {
121
- setTimeout(() => {
121
+ setTimeout((): void => {
122
122
  this.changeStateFrame(isEnabled ? STATE_UP : STATE_DISABLED);
123
123
  }, 1);
124
124
  }
@@ -127,14 +127,14 @@ export class Button extends Image {
127
127
  /**
128
128
  * Clears all the frame settings for this button.
129
129
  */
130
- public clearFrames() {
130
+ public clearFrames(): void {
131
131
  this.setFrames(null, null, null, null, null);
132
132
  }
133
133
 
134
134
  /**
135
135
  * Called when this button is removed from the world.
136
136
  */
137
- public removedFromWorld() {
137
+ public removedFromWorld(): void {
138
138
  this.inputEnabled = false;
139
139
  }
140
140
 
@@ -144,7 +144,7 @@ export class Button extends Image {
144
144
  * @param {string} frame - The frame identifier to set for this state.
145
145
  * @param {boolean} switchImmediately - Whether to switch to the new frame immediately (default: false).
146
146
  */
147
- public setStateFrame(state: string, frame: string | null, switchImmediately = false) {
147
+ public setStateFrame(state: string, frame: string | null, switchImmediately = false): void {
148
148
  const frameKey: `_on${string}Frame` = `_on${state}Frame`;
149
149
  if (frame) {
150
150
  this[frameKey] = frame;
@@ -161,7 +161,7 @@ export class Button extends Image {
161
161
  * @param {string} newState - The new state to change to (Over, Out, Down, Up, Disabled).
162
162
  * @returns {boolean} True if the frame was changed, false otherwise.
163
163
  */
164
- public changeStateFrame(newState: string) {
164
+ public changeStateFrame(newState: string): boolean {
165
165
  if (this.freezeFrames) {
166
166
  return false;
167
167
  }
@@ -192,7 +192,7 @@ export class Button extends Image {
192
192
  downFrame: string | null,
193
193
  upFrame: string | null,
194
194
  disabledFrame: string | null = null
195
- ) {
195
+ ): void {
196
196
  this.setStateFrame(STATE_OVER, overFrame, this.input.pointerOver());
197
197
  this.setStateFrame(STATE_OUT, outFrame, !this.input.pointerOver());
198
198
  this.setStateFrame(STATE_DOWN, downFrame, this.input.pointerDown());
@@ -207,7 +207,7 @@ export class Button extends Image {
207
207
  * @param {object} _sprite - The sprite that triggered the event.
208
208
  * @param {object} pointer - The pointer that triggered the event.
209
209
  */
210
- public onInputOverHandler(_sprite: any, pointer: any) {
210
+ public onInputOverHandler(_sprite: any, pointer: any): void {
211
211
  if (pointer.justReleased() && (this.justReleasedPreventsOver & pointer.pointerMode) === pointer.pointerMode) {
212
212
  // If the Pointer was only just released then we don't fire an over event
213
213
  return;
@@ -226,7 +226,7 @@ export class Button extends Image {
226
226
  * @param {object} _sprite - The sprite that triggered the event.
227
227
  * @param {object} pointer - The pointer that triggered the event.
228
228
  */
229
- public onInputOutHandler(_sprite: any, pointer: any) {
229
+ public onInputOutHandler(_sprite: any, pointer: any): void {
230
230
  this.changeStateFrame(STATE_OUT);
231
231
  if (this.onInputOut) {
232
232
  this.onInputOut.dispatch(this, pointer);
@@ -238,7 +238,7 @@ export class Button extends Image {
238
238
  * @param {object} _sprite - The sprite that triggered the event.
239
239
  * @param {object} pointer - The pointer that triggered the event.
240
240
  */
241
- public onInputDownHandler(_sprite: any, pointer: any) {
241
+ public onInputDownHandler(_sprite: any, pointer: any): void {
242
242
  this.changeStateFrame(STATE_DOWN);
243
243
  if (this.onInputDown) {
244
244
  this.onInputDown.dispatch(this, pointer);
@@ -251,7 +251,7 @@ export class Button extends Image {
251
251
  * @param {object} pointer - The pointer that triggered the event.
252
252
  * @param {boolean} isOver - Whether the pointer is currently over the button (default: true).
253
253
  */
254
- public onInputUpHandler(_sprite: any, pointer: any, isOver: boolean) {
254
+ public onInputUpHandler(_sprite: any, pointer: any, isOver: boolean): void {
255
255
  if (this.onInputUp) {
256
256
  this.onInputUp.dispatch(this, pointer, isOver);
257
257
  }
@@ -277,7 +277,7 @@ export class Button extends Image {
277
277
  * Gets whether input is currently enabled for this button.
278
278
  * @returns {boolean} True if input is enabled, false otherwise.
279
279
  */
280
- public get inputEnabled() {
280
+ public get inputEnabled(): boolean {
281
281
  return this.input && this.input.enabled;
282
282
  }
283
283
 
@@ -22,7 +22,7 @@ export class CanvasBuffer {
22
22
  /**
23
23
  * Clears the canvas buffer.
24
24
  */
25
- public clear() {
25
+ public clear(): void {
26
26
  this.context.setTransform(1, 0, 0, 1, 0, 0);
27
27
  this.context.clearRect(0, 0, this.width, this.height);
28
28
  }
@@ -32,7 +32,7 @@ export class CanvasBuffer {
32
32
  * @param {number} width - The new width of the canvas buffer.
33
33
  * @param {number} height - The new height of the canvas buffer.
34
34
  */
35
- public resize(width: number, height: number) {
35
+ public resize(width: number, height: number): void {
36
36
  this.width = width;
37
37
  this.height = height;
38
38
  this.canvas.width = width;
@@ -42,7 +42,7 @@ export class CanvasBuffer {
42
42
  /**
43
43
  * Destroys the canvas buffer and cleans up resources.
44
44
  */
45
- public destroy() {
45
+ public destroy(): void {
46
46
  try {
47
47
  this.context?.reset();
48
48
  } catch {
@@ -9,7 +9,7 @@ import { RoundedRectangle } from '../../geom/rounded_rectangle.js';
9
9
  * Renders a graphics object to canvas.
10
10
  * @param {Graphics} graphics - The graphics object to render.
11
11
  */
12
- export const updateGraphicsTint = (graphics: Graphics) => {
12
+ export const updateGraphicsTint = (graphics: Graphics): void => {
13
13
  if (graphics.tint === 0xffffff) {
14
14
  return;
15
15
  }
@@ -35,7 +35,7 @@ export const updateGraphicsTint = (graphics: Graphics) => {
35
35
  * @param {Graphics} graphics - The graphics object to render.
36
36
  * @param {object} context - The canvas rendering context.
37
37
  */
38
- export const renderGraphics = (graphics: Graphics, context: CanvasRenderingContext2D) => {
38
+ export const renderGraphics = (graphics: Graphics, context: CanvasRenderingContext2D): void => {
39
39
  const { worldAlpha } = graphics;
40
40
  if (graphics.dirty) {
41
41
  updateGraphicsTint(graphics);
@@ -163,7 +163,7 @@ export const renderGraphics = (graphics: Graphics, context: CanvasRenderingConte
163
163
  * @param {Graphics} graphics - The graphics object to render.
164
164
  * @param {object} context - The canvas rendering context.
165
165
  */
166
- export const renderGraphicsMask = (graphics: Graphics, context: CanvasRenderingContext2D) => {
166
+ export const renderGraphicsMask = (graphics: Graphics, context: CanvasRenderingContext2D): void => {
167
167
  const len = graphics.graphicsData.length;
168
168
  if (len === 0) {
169
169
  return;
@@ -7,7 +7,7 @@ import type { Graphics } from '../graphics.js';
7
7
  * @param {object} maskData - The mask data to apply.
8
8
  * @param {object} renderSession - The rendering session object.
9
9
  */
10
- export const pushMask = (maskData: any, renderSession: RenderSession) => {
10
+ export const pushMask = (maskData: any, renderSession: RenderSession): void => {
11
11
  const { context } = renderSession;
12
12
  context.save();
13
13
  const cacheAlpha = maskData.alpha;
@@ -31,6 +31,6 @@ export const pushMask = (maskData: any, renderSession: RenderSession) => {
31
31
  * @param {object} _maskData - Unused; the canvas path restores whatever was saved.
32
32
  * @param {object} renderSession - The rendering session object.
33
33
  */
34
- export const popMask = (_maskData: Graphics | null, renderSession: RenderSession) => {
34
+ export const popMask = (_maskData: Graphics | null, renderSession: RenderSession): void => {
35
35
  renderSession.context.restore();
36
36
  };
@@ -13,7 +13,7 @@ export const getPool = (): CanvasPoolEntry[] => {
13
13
  * Gets the current size of the canvas pool.
14
14
  * @returns {number} The current size of the canvas pool.
15
15
  */
16
- export const getFirst = () => {
16
+ export const getFirst = (): number => {
17
17
  const pool = getPool();
18
18
  for (let i = 0; i < pool.length; i += 1) {
19
19
  if (!pool[i]!.parent) {
@@ -27,7 +27,7 @@ export const getFirst = () => {
27
27
  * Adds a canvas to the pool with the specified parent.
28
28
  * @param {object} parent - The parent object for the canvas.
29
29
  */
30
- export const remove = (parent: any) => {
30
+ export const remove = (parent: any): void => {
31
31
  const pool = getPool();
32
32
  for (const entry of pool) {
33
33
  if (entry.parent === parent) {
@@ -42,7 +42,7 @@ export const remove = (parent: any) => {
42
42
  * Removes a canvas from the pool.
43
43
  * @param {HTMLCanvasElement} canvas - The canvas to remove from the pool.
44
44
  */
45
- export const removeByCanvas = (canvas: HTMLCanvasElement) => {
45
+ export const removeByCanvas = (canvas: HTMLCanvasElement): void => {
46
46
  const pool = getPool();
47
47
  for (const entry of pool) {
48
48
  if (entry.canvas === canvas) {
@@ -57,7 +57,7 @@ export const removeByCanvas = (canvas: HTMLCanvasElement) => {
57
57
  * Gets the total count of canvases in the pool.
58
58
  * @returns {number} The total count of canvases in the pool.
59
59
  */
60
- export const getTotal = () => {
60
+ export const getTotal = (): number => {
61
61
  const pool = getPool();
62
62
  let c = 0;
63
63
  for (const entry of pool) {
@@ -72,7 +72,7 @@ export const getTotal = () => {
72
72
  * Gets the number of free canvases in the pool.
73
73
  * @returns {number} The number of free canvases in the pool.
74
74
  */
75
- export const getFree = () => {
75
+ export const getFree = (): number => {
76
76
  const pool = getPool();
77
77
  let c = 0;
78
78
  for (const entry of pool) {
@@ -91,7 +91,7 @@ export const getFree = () => {
91
91
  * @param {boolean} skipPool - True to skip using the pool and create a new canvas.
92
92
  * @returns {HTMLCanvasElement} The canvas from the pool or a newly created one.
93
93
  */
94
- export const create = (parent: any, width?: any, height?: any, skipPool = false) => {
94
+ export const create = (parent: any, width?: any, height?: any, skipPool = false): HTMLCanvasElement => {
95
95
  if (parent === undefined) {
96
96
  console.warn('Created CanvasPool element with undefined parent.');
97
97
  }
@@ -81,7 +81,7 @@ export class CanvasRenderer {
81
81
  * Renders the stage to canvas.
82
82
  * @param {Stage} root - The root stage to render.
83
83
  */
84
- public render(root: Stage) {
84
+ public render(root: Stage): void {
85
85
  if (!this.context) {
86
86
  return;
87
87
  }
@@ -106,7 +106,7 @@ export class CanvasRenderer {
106
106
  * Destroys this renderer and cleans up resources.
107
107
  * @param {boolean} removeView - Whether to remove the view from the DOM.
108
108
  */
109
- public destroy(removeView = true) {
109
+ public destroy(removeView = true): void {
110
110
  if (removeView && this.view.parent) {
111
111
  this.view.parent.removeChild(this.view);
112
112
  }
@@ -117,7 +117,7 @@ export class CanvasRenderer {
117
117
  * @param {number} width - The new width of the canvas.
118
118
  * @param {number} height - The new height of the canvas.
119
119
  */
120
- public resize(width: number, height: number) {
120
+ public resize(width: number, height: number): void {
121
121
  this.width = width * this.resolution;
122
122
  this.height = height * this.resolution;
123
123
  this.view.width = this.width;
@@ -137,7 +137,7 @@ export class CanvasRenderer {
137
137
  * @param {CanvasRenderingContext2D} context - The canvas rendering context.
138
138
  * @param {Matrix} matrix - The transformation matrix.
139
139
  */
140
- public renderDisplayObject(displayObject: any, context?: any, matrix?: any) {
140
+ public renderDisplayObject(displayObject: any, context?: any, matrix?: any): void {
141
141
  this.renderSession.context = context ?? this.context;
142
142
  this.renderSession.resolution = this.resolution;
143
143
  displayObject.renderCanvas(this.renderSession, matrix);
@@ -146,7 +146,7 @@ export class CanvasRenderer {
146
146
  /**
147
147
  * Maps blend modes to canvas rendering operations.
148
148
  */
149
- public mapBlendModes() {
149
+ public mapBlendModes(): void {
150
150
  if (globalThis.PhaserRegistry.blendModesCanvas) {
151
151
  return;
152
152
  }
@@ -176,7 +176,7 @@ export class CanvasRenderer {
176
176
  * Initializes the WebGL context for rendering.
177
177
  * @param {Game} game - The game instance.
178
178
  */
179
- public initContext(_game: Game) {
179
+ public initContext(_game: Game): void {
180
180
  // stub
181
181
  }
182
182
  }
@@ -1,3 +1,4 @@
1
+ import type { Texture } from '../webgl/texture.js';
1
2
  import { ENGINE_ERROR_CREATING_CANVAS_2D_CONTEXT, ENGINE_ERROR_GETTING_DOCUMENT } from '../../core/error_code.js';
2
3
  import { hex2rgb } from '../../util/math.js';
3
4
  import { create, removeByCanvas } from './pool.js';
@@ -24,7 +25,7 @@ export const getTintedTexture = (sprite: Image, color: number): HTMLCanvasElemen
24
25
  * @param {HTMLCanvasElement} canvas - The canvas to render to.
25
26
  * @throws {Error} If the operation fails.
26
27
  */
27
- export const tintWithMultiply = (texture: any, color: any, canvas: HTMLCanvasElement) => {
28
+ export const tintWithMultiply = (texture: Texture, color: number, canvas: HTMLCanvasElement): void => {
28
29
  const context = canvas.getContext('2d', { willReadFrequently: false });
29
30
  if (!context) {
30
31
  throw new Error(ENGINE_ERROR_CREATING_CANVAS_2D_CONTEXT);
@@ -38,9 +39,29 @@ export const tintWithMultiply = (texture: any, color: any, canvas: HTMLCanvasEle
38
39
  context.fillStyle = `#${`00000${Math.trunc(color).toString(16)}`.slice(-6)}`;
39
40
  context.fillRect(0, 0, crop.width, crop.height);
40
41
  context.globalCompositeOperation = 'multiply';
41
- context.drawImage(texture.baseTexture.source, crop.x, crop.y, crop.width, crop.height, 0, 0, crop.width, crop.height);
42
+ context.drawImage(
43
+ texture.baseTexture.source!,
44
+ crop.x,
45
+ crop.y,
46
+ crop.width,
47
+ crop.height,
48
+ 0,
49
+ 0,
50
+ crop.width,
51
+ crop.height
52
+ );
42
53
  context.globalCompositeOperation = 'destination-atop';
43
- context.drawImage(texture.baseTexture.source, crop.x, crop.y, crop.width, crop.height, 0, 0, crop.width, crop.height);
54
+ context.drawImage(
55
+ texture.baseTexture.source!,
56
+ crop.x,
57
+ crop.y,
58
+ crop.width,
59
+ crop.height,
60
+ 0,
61
+ 0,
62
+ crop.width,
63
+ crop.height
64
+ );
44
65
  };
45
66
 
46
67
  /**
@@ -50,7 +71,7 @@ export const tintWithMultiply = (texture: any, color: any, canvas: HTMLCanvasEle
50
71
  * @param {HTMLCanvasElement} canvas - The canvas to render to.
51
72
  * @throws {Error} If the operation fails.
52
73
  */
53
- export const tintWithPerPixel = (texture: any, color: any, canvas: HTMLCanvasElement) => {
74
+ export const tintWithPerPixel = (texture: Texture, color: number, canvas: HTMLCanvasElement): void => {
54
75
  const context = canvas.getContext('2d', { willReadFrequently: false });
55
76
  if (!context) {
56
77
  throw new Error(ENGINE_ERROR_CREATING_CANVAS_2D_CONTEXT);
@@ -59,7 +80,17 @@ export const tintWithPerPixel = (texture: any, color: any, canvas: HTMLCanvasEle
59
80
  canvas.width = crop.width;
60
81
  canvas.height = crop.height;
61
82
  context.globalCompositeOperation = 'copy';
62
- context.drawImage(texture.baseTexture.source, crop.x, crop.y, crop.width, crop.height, 0, 0, crop.width, crop.height);
83
+ context.drawImage(
84
+ texture.baseTexture.source!,
85
+ crop.x,
86
+ crop.y,
87
+ crop.width,
88
+ crop.height,
89
+ 0,
90
+ 0,
91
+ crop.width,
92
+ crop.height
93
+ );
63
94
  const rgbValues = hex2rgb(color);
64
95
  const r = rgbValues[0];
65
96
  const g = rgbValues[1];
@@ -86,7 +117,7 @@ export const tintWithPerPixel = (texture: any, color: any, canvas: HTMLCanvasEle
86
117
  * @returns {boolean} True if the tinter can handle the texture, false otherwise.
87
118
  * @throws {Error} If the operation fails.
88
119
  */
89
- export const checkInverseAlpha = () => {
120
+ export const checkInverseAlpha = (): boolean => {
90
121
  // Check for DOM
91
122
  if (document === undefined) {
92
123
  throw new Error(ENGINE_ERROR_GETTING_DOCUMENT);
@@ -128,7 +159,7 @@ export const checkInverseAlpha = () => {
128
159
  * @returns {boolean} True if the tinter can handle the texture, false otherwise.
129
160
  * @throws {Error} If the operation fails.
130
161
  */
131
- export const canUseNewCanvasBlendModes = () => {
162
+ export const canUseNewCanvasBlendModes = (): boolean => {
132
163
  // Check for DOM
133
164
  if (document === undefined) {
134
165
  throw new Error(ENGINE_ERROR_GETTING_DOCUMENT);
@@ -169,7 +200,7 @@ export const canUseNewCanvasBlendModes = () => {
169
200
  * Creates a new Tinter instance.
170
201
  * @param {Game} game - The game instance.
171
202
  */
172
- export const detectCapabilities = (game: Game) => {
203
+ export const detectCapabilities = (game: Game): void => {
173
204
  getRegistry();
174
205
  try {
175
206
  globalThis.PhaserRegistry.CAN_CANVAS_USE_MULTIPLY = canUseNewCanvasBlendModes();
@@ -9,7 +9,13 @@ import { create as createCanvas } from './pool.js';
9
9
  * @param {boolean} skipPool - Whether to skip using the canvas pool.
10
10
  * @returns {HTMLCanvasElement} The created HTML canvas element.
11
11
  */
12
- export const create = (parent: any, width: number, height: number, id: string, skipPool: boolean) => {
12
+ export const create = (
13
+ parent: any,
14
+ width: number,
15
+ height: number,
16
+ id: string,
17
+ skipPool: boolean
18
+ ): HTMLCanvasElement => {
13
19
  width = width || 256;
14
20
  height = height || 256;
15
21
  const canvas = skipPool ? document.createElement('canvas') : createCanvas(parent, width, height);
@@ -28,7 +34,7 @@ export const create = (parent: any, width: number, height: number, id: string, s
28
34
  * @param {string} color - The background color to set.
29
35
  * @returns {HTMLCanvasElement} The modified canvas element.
30
36
  */
31
- export const setBackgroundColor = (canvas: HTMLCanvasElement, color = 'rgb(0,0,0)') => {
37
+ export const setBackgroundColor = (canvas: HTMLCanvasElement, color = 'rgb(0,0,0)'): HTMLCanvasElement => {
32
38
  canvas.style.backgroundColor = color;
33
39
  return canvas;
34
40
  };
@@ -39,7 +45,7 @@ export const setBackgroundColor = (canvas: HTMLCanvasElement, color = 'rgb(0,0,0
39
45
  * @param {string} value - The touch action value to set.
40
46
  * @returns {HTMLCanvasElement} The modified canvas element.
41
47
  */
42
- export const setTouchAction = (canvas: HTMLCanvasElement, value = 'none') => {
48
+ export const setTouchAction = (canvas: HTMLCanvasElement, value = 'none'): HTMLCanvasElement => {
43
49
  value = value || 'none';
44
50
  canvas.style.setProperty('-ms-touch-action', value);
45
51
  canvas.style.setProperty('touch-action', value);
@@ -52,7 +58,7 @@ export const setTouchAction = (canvas: HTMLCanvasElement, value = 'none') => {
52
58
  * @param {string} value - The user select value to set.
53
59
  * @returns {HTMLCanvasElement} The modified canvas element.
54
60
  */
55
- export const setUserSelect = (canvas: HTMLCanvasElement, value = 'none') => {
61
+ export const setUserSelect = (canvas: HTMLCanvasElement, value = 'none'): HTMLCanvasElement => {
56
62
  value = value || 'none';
57
63
  canvas.style.setProperty('-webkit-touch-callout', value);
58
64
  canvas.style.setProperty('-webkit-user-select', value);
@@ -71,7 +77,7 @@ export const setUserSelect = (canvas: HTMLCanvasElement, value = 'none') => {
71
77
  * @param {boolean} overflowHidden - Whether to set overflow hidden on the parent.
72
78
  * @returns {HTMLCanvasElement} The added canvas element.
73
79
  */
74
- export const addToDOM = (canvas: HTMLCanvasElement, parent: any, overflowHidden = true) => {
80
+ export const addToDOM = (canvas: HTMLCanvasElement, parent: any, overflowHidden = true): HTMLCanvasElement => {
75
81
  let target;
76
82
  if (parent) {
77
83
  if (typeof parent === 'string') {
@@ -95,7 +101,7 @@ export const addToDOM = (canvas: HTMLCanvasElement, parent: any, overflowHidden
95
101
  * Removes a canvas element from the DOM.
96
102
  * @param {HTMLCanvasElement} canvas - The canvas element to remove.
97
103
  */
98
- export const removeFromDOM = (canvas: HTMLCanvasElement) => {
104
+ export const removeFromDOM = (canvas: HTMLCanvasElement): void => {
99
105
  if (canvas && canvas.parentNode) {
100
106
  canvas.parentNode.removeChild(canvas);
101
107
  }
@@ -120,7 +126,7 @@ export const setTransform = (
120
126
  scaleY: number,
121
127
  skewX: number,
122
128
  skewY: number
123
- ) => {
129
+ ): CanvasRenderingContext2D => {
124
130
  context.setTransform(scaleX, skewX, skewY, scaleY, translateX, translateY);
125
131
  return context;
126
132
  };
@@ -130,7 +136,7 @@ export const setTransform = (
130
136
  * @param {CanvasRenderingContext2D} context - The canvas rendering context.
131
137
  * @returns {string | null} The smoothing property name or null if not found.
132
138
  */
133
- export const getSmoothingPrefix = (context: CanvasRenderingContext2D) => {
139
+ export const getSmoothingPrefix = (context: CanvasRenderingContext2D): string | null => {
134
140
  const VENDORS = ['i', 'webkitI', 'msI', 'mozI', 'oI'];
135
141
  // the vendor-prefixed smoothing flags predate the standard property and are absent from lib.dom
136
142
  const smoothingFlags = context as unknown as Record<string, boolean | undefined>;
@@ -159,7 +165,7 @@ export const setSmoothing = (context: CanvasRenderingContext2D, property: string
159
165
  * @param {boolean} value - The smoothing enabled value to set.
160
166
  * @returns {CanvasRenderingContext2D} The modified rendering context.
161
167
  */
162
- export const setSmoothingEnabled = (context: CanvasRenderingContext2D, value: boolean) => {
168
+ export const setSmoothingEnabled = (context: CanvasRenderingContext2D, value: boolean): CanvasRenderingContext2D => {
163
169
  const s = getSmoothingPrefix(context);
164
170
  if (s) {
165
171
  setSmoothing(context, s, value);