@vpmedia/phaser 1.123.0 → 1.124.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 (206) hide show
  1. package/dist/index.js +339 -323
  2. package/dist/index.js.map +1 -1
  3. package/dist/phaser/core/animation.d.ts +3 -3
  4. package/dist/phaser/core/animation.d.ts.map +1 -1
  5. package/dist/phaser/core/animation_manager.d.ts.map +1 -1
  6. package/dist/phaser/core/animation_parser.d.ts +27 -2
  7. package/dist/phaser/core/animation_parser.d.ts.map +1 -1
  8. package/dist/phaser/core/array_set.d.ts +11 -11
  9. package/dist/phaser/core/array_set.d.ts.map +1 -1
  10. package/dist/phaser/core/cache.d.ts.map +1 -1
  11. package/dist/phaser/core/callback.d.ts.map +1 -1
  12. package/dist/phaser/core/dom.d.ts +125 -19
  13. package/dist/phaser/core/dom.d.ts.map +1 -1
  14. package/dist/phaser/core/factory.d.ts +3 -2
  15. package/dist/phaser/core/factory.d.ts.map +1 -1
  16. package/dist/phaser/core/input.d.ts +3 -2
  17. package/dist/phaser/core/input.d.ts.map +1 -1
  18. package/dist/phaser/core/input_handler.d.ts.map +1 -1
  19. package/dist/phaser/core/input_mouse.d.ts +5 -1
  20. package/dist/phaser/core/input_mouse.d.ts.map +1 -1
  21. package/dist/phaser/core/input_pointer.d.ts +3 -3
  22. package/dist/phaser/core/input_pointer.d.ts.map +1 -1
  23. package/dist/phaser/core/input_touch.d.ts +8 -8
  24. package/dist/phaser/core/input_touch.d.ts.map +1 -1
  25. package/dist/phaser/core/loader.d.ts +11 -2
  26. package/dist/phaser/core/loader.d.ts.map +1 -1
  27. package/dist/phaser/core/loader_parser.d.ts +14 -1
  28. package/dist/phaser/core/loader_parser.d.ts.map +1 -1
  29. package/dist/phaser/core/raf.d.ts +1 -1
  30. package/dist/phaser/core/raf.d.ts.map +1 -1
  31. package/dist/phaser/core/scale_manager.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/sound.d.ts.map +1 -1
  35. package/dist/phaser/core/sound_manager.d.ts +1 -1
  36. package/dist/phaser/core/sound_manager.d.ts.map +1 -1
  37. package/dist/phaser/core/stage.d.ts +16 -6
  38. package/dist/phaser/core/stage.d.ts.map +1 -1
  39. package/dist/phaser/core/time.d.ts.map +1 -1
  40. package/dist/phaser/core/timer.d.ts +1 -1
  41. package/dist/phaser/core/timer.d.ts.map +1 -1
  42. package/dist/phaser/core/tween.d.ts +13 -5
  43. package/dist/phaser/core/tween.d.ts.map +1 -1
  44. package/dist/phaser/core/tween_data.d.ts +9 -7
  45. package/dist/phaser/core/tween_data.d.ts.map +1 -1
  46. package/dist/phaser/core/tween_manager.d.ts.map +1 -1
  47. package/dist/phaser/display/button.d.ts +6 -5
  48. package/dist/phaser/display/button.d.ts.map +1 -1
  49. package/dist/phaser/display/canvas/buffer.d.ts +1 -1
  50. package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
  51. package/dist/phaser/display/canvas/masker.d.ts +1 -1
  52. package/dist/phaser/display/canvas/masker.d.ts.map +1 -1
  53. package/dist/phaser/display/canvas/pool.d.ts +2 -2
  54. package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
  55. package/dist/phaser/display/canvas/renderer.d.ts +9 -8
  56. package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
  57. package/dist/phaser/display/display_object.d.ts +3 -1
  58. package/dist/phaser/display/display_object.d.ts.map +1 -1
  59. package/dist/phaser/display/graphics.d.ts +1 -1
  60. package/dist/phaser/display/graphics.d.ts.map +1 -1
  61. package/dist/phaser/display/group.d.ts +1 -1
  62. package/dist/phaser/display/group.d.ts.map +1 -1
  63. package/dist/phaser/display/image.d.ts +6 -5
  64. package/dist/phaser/display/image.d.ts.map +1 -1
  65. package/dist/phaser/display/sprite_util.d.ts +3 -2
  66. package/dist/phaser/display/sprite_util.d.ts.map +1 -1
  67. package/dist/phaser/display/text.d.ts +2 -16
  68. package/dist/phaser/display/text.d.ts.map +1 -1
  69. package/dist/phaser/display/webgl/abstract_filter.d.ts +14 -8
  70. package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
  71. package/dist/phaser/display/webgl/blend_manager.d.ts +2 -3
  72. package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
  73. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +11 -5
  74. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
  75. package/dist/phaser/display/webgl/filter_manager.d.ts +6 -4
  76. package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
  77. package/dist/phaser/display/webgl/filter_texture.d.ts +4 -4
  78. package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
  79. package/dist/phaser/display/webgl/graphics.d.ts +2 -2
  80. package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
  81. package/dist/phaser/display/webgl/mask_manager.d.ts +3 -2
  82. package/dist/phaser/display/webgl/mask_manager.d.ts.map +1 -1
  83. package/dist/phaser/display/webgl/render_texture.d.ts +11 -8
  84. package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
  85. package/dist/phaser/display/webgl/renderer.d.ts +8 -4
  86. package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
  87. package/dist/phaser/display/webgl/shader/normal.d.ts +28 -3
  88. package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
  89. package/dist/phaser/display/webgl/sprite_batch.d.ts +6 -5
  90. package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
  91. package/dist/phaser/display/webgl/stencil_manager.d.ts +3 -3
  92. package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
  93. package/dist/phaser/display/webgl/texture_util.d.ts +2 -2
  94. package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
  95. package/dist/phaser/display/webgl/util.d.ts +1 -1
  96. package/dist/phaser/display/webgl/util.d.ts.map +1 -1
  97. package/dist/phaser/geom/circle.d.ts.map +1 -1
  98. package/dist/phaser/geom/line.d.ts +10 -1
  99. package/dist/phaser/geom/line.d.ts.map +1 -1
  100. package/dist/phaser/geom/rectangle.d.ts.map +1 -1
  101. package/dist/phaser/geom/util/circle.d.ts +2 -1
  102. package/dist/phaser/geom/util/circle.d.ts.map +1 -1
  103. package/dist/phaser/geom/util/point.d.ts +1 -1
  104. package/dist/phaser/geom/util/point.d.ts.map +1 -1
  105. package/dist/phaser/geom/util/rectangle.d.ts +1 -1
  106. package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
  107. package/dist/phaser/util/math.d.ts.map +1 -1
  108. package/package.json +1 -1
  109. package/src/phaser/core/animation.ts +4 -4
  110. package/src/phaser/core/animation_manager.ts +10 -10
  111. package/src/phaser/core/animation_parser.ts +30 -24
  112. package/src/phaser/core/array_set.ts +27 -27
  113. package/src/phaser/core/cache.test.ts +33 -33
  114. package/src/phaser/core/cache.ts +3 -3
  115. package/src/phaser/core/callback.ts +1 -0
  116. package/src/phaser/core/callback_context.test.ts +8 -8
  117. package/src/phaser/core/dom.ts +15 -5
  118. package/src/phaser/core/factory.ts +9 -2
  119. package/src/phaser/core/frame_data.test.ts +23 -23
  120. package/src/phaser/core/input.ts +9 -8
  121. package/src/phaser/core/input_handler.test.ts +18 -18
  122. package/src/phaser/core/input_handler.ts +1 -1
  123. package/src/phaser/core/input_mouse.ts +9 -8
  124. package/src/phaser/core/input_pointer.test.ts +26 -26
  125. package/src/phaser/core/input_pointer.ts +3 -3
  126. package/src/phaser/core/input_touch.ts +8 -8
  127. package/src/phaser/core/loader.test.ts +26 -26
  128. package/src/phaser/core/loader.ts +25 -25
  129. package/src/phaser/core/loader_parser.test.ts +16 -16
  130. package/src/phaser/core/loader_parser.ts +16 -6
  131. package/src/phaser/core/raf.ts +1 -1
  132. package/src/phaser/core/registry.test.ts +6 -6
  133. package/src/phaser/core/scale_manager.ts +2 -2
  134. package/src/phaser/core/scene_manager.test.ts +30 -30
  135. package/src/phaser/core/scene_manager.ts +1 -1
  136. package/src/phaser/core/signal.test.ts +8 -8
  137. package/src/phaser/core/signal.ts +1 -1
  138. package/src/phaser/core/signal_dispatch.test.ts +30 -30
  139. package/src/phaser/core/sound.ts +20 -8
  140. package/src/phaser/core/sound_manager.ts +6 -6
  141. package/src/phaser/core/stage.ts +19 -9
  142. package/src/phaser/core/time.ts +1 -1
  143. package/src/phaser/core/timer.test.ts +47 -47
  144. package/src/phaser/core/timer.ts +1 -1
  145. package/src/phaser/core/tween.ts +28 -25
  146. package/src/phaser/core/tween_data.test.ts +119 -0
  147. package/src/phaser/core/tween_data.ts +54 -39
  148. package/src/phaser/core/tween_easing.test.ts +5 -5
  149. package/src/phaser/core/tween_manager.ts +2 -2
  150. package/src/phaser/display/bitmap_text.test.ts +30 -30
  151. package/src/phaser/display/button.ts +8 -6
  152. package/src/phaser/display/canvas/buffer.ts +2 -2
  153. package/src/phaser/display/canvas/masker.ts +1 -1
  154. package/src/phaser/display/canvas/pool.test.ts +20 -20
  155. package/src/phaser/display/canvas/pool.ts +3 -3
  156. package/src/phaser/display/canvas/renderer.ts +12 -11
  157. package/src/phaser/display/canvas/util.test.ts +25 -25
  158. package/src/phaser/display/display_object.ts +3 -1
  159. package/src/phaser/display/graphics.test.ts +70 -20
  160. package/src/phaser/display/graphics.ts +38 -32
  161. package/src/phaser/display/group.ts +4 -4
  162. package/src/phaser/display/image.ts +28 -25
  163. package/src/phaser/display/sprite_util.ts +3 -2
  164. package/src/phaser/display/text.test.ts +28 -25
  165. package/src/phaser/display/text.ts +21 -18
  166. package/src/phaser/display/webgl/abstract_filter.ts +20 -10
  167. package/src/phaser/display/webgl/blend_manager.ts +4 -5
  168. package/src/phaser/display/webgl/earcut.test.ts +20 -20
  169. package/src/phaser/display/webgl/fast_sprite_batch.ts +21 -16
  170. package/src/phaser/display/webgl/filter_manager.ts +7 -4
  171. package/src/phaser/display/webgl/filter_texture.ts +5 -5
  172. package/src/phaser/display/webgl/graphics.ts +2 -2
  173. package/src/phaser/display/webgl/mask_manager.ts +9 -14
  174. package/src/phaser/display/webgl/render_texture.ts +15 -14
  175. package/src/phaser/display/webgl/renderer.ts +7 -6
  176. package/src/phaser/display/webgl/shader/normal.ts +41 -31
  177. package/src/phaser/display/webgl/shader/shader.test.ts +24 -24
  178. package/src/phaser/display/webgl/shader_manager.test.ts +18 -18
  179. package/src/phaser/display/webgl/sprite_batch.ts +8 -8
  180. package/src/phaser/display/webgl/stencil_manager.ts +4 -4
  181. package/src/phaser/display/webgl/texture_util.ts +2 -2
  182. package/src/phaser/display/webgl/util.ts +1 -1
  183. package/src/phaser/geom/circle.test.ts +38 -38
  184. package/src/phaser/geom/circle.ts +7 -7
  185. package/src/phaser/geom/ellipse.test.ts +12 -12
  186. package/src/phaser/geom/line.test.ts +15 -15
  187. package/src/phaser/geom/line.ts +5 -2
  188. package/src/phaser/geom/matrix.test.ts +31 -31
  189. package/src/phaser/geom/point.test.ts +31 -31
  190. package/src/phaser/geom/polygon.test.ts +27 -27
  191. package/src/phaser/geom/rectangle.test.ts +87 -87
  192. package/src/phaser/geom/rectangle.ts +11 -11
  193. package/src/phaser/geom/rounded_rectangle.test.ts +9 -9
  194. package/src/phaser/geom/util/circle.test.ts +5 -5
  195. package/src/phaser/geom/util/circle.ts +2 -1
  196. package/src/phaser/geom/util/ellipse.test.ts +2 -2
  197. package/src/phaser/geom/util/line.test.ts +2 -2
  198. package/src/phaser/geom/util/matrix.test.ts +4 -4
  199. package/src/phaser/geom/util/point.test.ts +2 -2
  200. package/src/phaser/geom/util/point.ts +1 -1
  201. package/src/phaser/geom/util/polygon.test.ts +2 -2
  202. package/src/phaser/geom/util/rectangle.test.ts +2 -2
  203. package/src/phaser/geom/util/rectangle.ts +1 -1
  204. package/src/phaser/geom/util/rounded_rectangle.test.ts +2 -2
  205. package/src/phaser/util/math.test.ts +41 -41
  206. package/src/phaser/util/math.ts +5 -2
@@ -38,6 +38,22 @@ export type GraphicsWebGLBucket = {
38
38
  gl: IdentifiedWebGLRenderingContext;
39
39
  };
40
40
 
41
+ /**
42
+ * Reports whether a triangle winds towards the viewer. In two dimensions the cross product is a
43
+ * scalar, so its sign alone says which way the face points.
44
+ * @param {Point[]} points - The three corners of the triangle, in order.
45
+ * @returns {boolean} True when the triangle faces the viewer.
46
+ */
47
+ const isFrontFacing = (points: Point[]): boolean => {
48
+ const [a, b, c] = points;
49
+ if (!a || !b || !c) {
50
+ return true;
51
+ }
52
+ const ab = new Point(b.x - a.x, b.y - a.y);
53
+ const cb = new Point(b.x - c.x, b.y - c.y);
54
+ return cb.cross(ab) > 0;
55
+ };
56
+
41
57
  export class Graphics extends DisplayObject {
42
58
  declare public type: number;
43
59
  declare public renderable: boolean;
@@ -887,18 +903,10 @@ export class Graphics extends DisplayObject {
887
903
  */
888
904
  public drawTriangle(points: Point[], cull = false): void {
889
905
  const triangle = new Polygon(points);
890
- if (cull) {
891
- const [a, b, c] = points as [Point, Point, Point];
892
- const cameraToFace = new Point(0 - a.x, 0 - a.y);
893
- const ab = new Point(b.x - a.x, b.y - a.y);
894
- const cb = new Point(b.x - c.x, b.y - c.y);
895
- const faceNormal = cb.cross(ab);
896
- if (cameraToFace.dot(faceNormal as any) > 0) {
897
- this.drawPolygon(triangle);
898
- }
899
- } else {
900
- this.drawPolygon(triangle);
906
+ if (cull && !isFrontFacing(points)) {
907
+ return;
901
908
  }
909
+ this.drawPolygon(triangle);
902
910
  }
903
911
 
904
912
  /**
@@ -907,43 +915,41 @@ export class Graphics extends DisplayObject {
907
915
  * @param {number[]} indices - The indices of the vertices to use.
908
916
  * @param {boolean} cull - Whether to perform backface culling.
909
917
  */
910
- public drawTriangles(vertices: any, indices: number[], cull = false): void {
911
- const point1 = new Point();
912
- const point2 = new Point();
913
- const point3 = new Point();
914
- let points = [];
918
+ public drawTriangles(vertices: Point[] | number[], indices: number[], cull = false): void {
919
+ let points: Point[] = [];
915
920
  let i;
916
921
  if (!indices) {
917
922
  if (vertices[0] instanceof Point) {
918
- for (i = 0; i < vertices.length / 3; i += 1) {
919
- this.drawTriangle([vertices[i * 3], vertices[i * 3 + 1], vertices[i * 3 + 2]], cull);
923
+ const corners = vertices as Point[];
924
+ for (i = 0; i < corners.length / 3; i += 1) {
925
+ this.drawTriangle([corners[i * 3]!, corners[i * 3 + 1]!, corners[i * 3 + 2]!], cull);
920
926
  }
921
927
  } else {
922
- for (i = 0; i < vertices.length / 6; i += 1) {
923
- point1.x = vertices[i * 6 + 0]!;
924
- point1.y = vertices[i * 6 + 1]!;
925
- point2.x = vertices[i * 6 + 2]!;
926
- point2.y = vertices[i * 6 + 3]!;
927
- point3.x = vertices[i * 6 + 4]!;
928
- point3.y = vertices[i * 6 + 5]!;
929
- this.drawTriangle([point1, point2, point3], cull);
928
+ const coordinates = vertices as number[];
929
+ for (i = 0; i < coordinates.length / 6; i += 1) {
930
+ this.drawTriangle(
931
+ [
932
+ new Point(coordinates[i * 6 + 0], coordinates[i * 6 + 1]),
933
+ new Point(coordinates[i * 6 + 2], coordinates[i * 6 + 3]),
934
+ new Point(coordinates[i * 6 + 4], coordinates[i * 6 + 5]),
935
+ ],
936
+ cull
937
+ );
930
938
  }
931
939
  }
932
940
  } else if (vertices[0] instanceof Point) {
941
+ const corners = vertices as Point[];
933
942
  for (i = 0; i < indices.length / 3; i += 1) {
934
- points.push(vertices[indices[i * 3]!]);
935
- points.push(vertices[indices[i * 3 + 1]!]);
936
- points.push(vertices[indices[i * 3 + 2]!]);
943
+ points.push(corners[indices[i * 3]!]!, corners[indices[i * 3 + 1]!]!, corners[indices[i * 3 + 2]!]!);
937
944
  if (points.length === 3) {
938
945
  this.drawTriangle(points, cull);
939
946
  points = [];
940
947
  }
941
948
  }
942
949
  } else {
950
+ const coordinates = vertices as number[];
943
951
  for (i = 0; i < indices.length; i += 1) {
944
- point1.x = vertices[indices[i]! * 2]!;
945
- point1.y = vertices[indices[i]! * 2 + 1]!;
946
- points.push(point1.copyTo({} as any));
952
+ points.push(new Point(coordinates[indices[i]! * 2], coordinates[indices[i]! * 2 + 1]));
947
953
  if (points.length === 3) {
948
954
  this.drawTriangle(points, cull);
949
955
  points = [];
@@ -288,11 +288,11 @@ export class Group extends DisplayObject {
288
288
  * @param {boolean} silent - Whether to dispatch events.
289
289
  * @returns {boolean} True if the child was removed, false otherwise.
290
290
  */
291
- public remove(child: any, destroy = true, silent = false): boolean {
291
+ public remove(child: DisplayObject, destroy = true, silent = false): boolean {
292
292
  if (this.children.length === 0 || !this.children.includes(child)) {
293
293
  return false;
294
294
  }
295
- if (!silent && child.events && !child.destroyPhase) {
295
+ if (!silent && child.events) {
296
296
  child.events.onRemovedFromGroup$dispatch(child, this);
297
297
  }
298
298
  const removed = this.removeChild(child);
@@ -301,7 +301,7 @@ export class Group extends DisplayObject {
301
301
  this.next();
302
302
  }
303
303
  if (destroy && removed) {
304
- (removed as any).destroy(true);
304
+ removed.destroy(true);
305
305
  }
306
306
  return true;
307
307
  }
@@ -323,7 +323,7 @@ export class Group extends DisplayObject {
323
323
  }
324
324
  const removed = this.removeChild(first);
325
325
  if (destroy && removed) {
326
- (removed as any).destroy(true, destroyTexture);
326
+ removed.destroy(true, destroyTexture);
327
327
  }
328
328
  } while (this.children.length > 0);
329
329
  this.cursor = null;
@@ -7,12 +7,13 @@ import { DisplayObject } from './display_object.js';
7
7
  import { getBounds, getLocalBounds, renderCanvas, renderWebGL, setTexture } from './sprite_util.js';
8
8
  import { Texture } from './webgl/texture.js';
9
9
  import type { Game } from '../core/game.js';
10
- import type { Frame } from '../core/frame.js';
10
+ import { Frame } from '../core/frame.js';
11
11
  import type { Matrix } from '../geom/matrix.js';
12
12
  import type { RenderSession } from './render_session.js';
13
+ import type { AbstractFilter } from './webgl/abstract_filter.js';
13
14
 
14
15
  export class Image extends DisplayObject {
15
- public key!: any;
16
+ public key!: string | number | Texture | null;
16
17
  public texture!: Texture;
17
18
  declare public _width: number;
18
19
  declare public _height: number;
@@ -21,8 +22,8 @@ export class Image extends DisplayObject {
21
22
  public tilingTexture!: Texture | null;
22
23
  public tintedTexture!: HTMLCanvasElement | null;
23
24
  public blendMode!: number;
24
- public shader!: object | null;
25
- public _frame!: any;
25
+ public shader!: AbstractFilter | null;
26
+ public _frame!: Frame | Rectangle | null;
26
27
  public pendingDestroy!: boolean;
27
28
  declare public events: EventManager;
28
29
  public animations!: AnimationManager;
@@ -180,7 +181,7 @@ export class Image extends DisplayObject {
180
181
  * Sets the current frame of this image.
181
182
  * @param {Frame} frame - The frame to set.
182
183
  */
183
- public setFrame(frame: Frame): void {
184
+ public setFrame(frame: Frame | Rectangle): void {
184
185
  this._frame = frame;
185
186
  this.texture.frame.x = frame.x;
186
187
  this.texture.frame.y = frame.y;
@@ -190,25 +191,26 @@ export class Image extends DisplayObject {
190
191
  this.texture.crop.y = frame.y;
191
192
  this.texture.crop.width = frame.width;
192
193
  this.texture.crop.height = frame.height;
193
- if (frame.trimmed) {
194
+ const trimmed = frame instanceof Frame && frame.trimmed ? frame : null;
195
+ if (trimmed) {
194
196
  if (this.texture.trim) {
195
- this.texture.trim.x = frame.spriteSourceSizeX;
196
- this.texture.trim.y = frame.spriteSourceSizeY;
197
- this.texture.trim.width = frame.sourceSizeW;
198
- this.texture.trim.height = frame.sourceSizeH;
197
+ this.texture.trim.x = trimmed.spriteSourceSizeX;
198
+ this.texture.trim.y = trimmed.spriteSourceSizeY;
199
+ this.texture.trim.width = trimmed.sourceSizeW;
200
+ this.texture.trim.height = trimmed.sourceSizeH;
199
201
  } else {
200
202
  this.texture.trim = new Rectangle(
201
- frame.spriteSourceSizeX,
202
- frame.spriteSourceSizeY,
203
- frame.sourceSizeW,
204
- frame.sourceSizeH
203
+ trimmed.spriteSourceSizeX,
204
+ trimmed.spriteSourceSizeY,
205
+ trimmed.sourceSizeW,
206
+ trimmed.sourceSizeH
205
207
  );
206
208
  }
207
- this.texture.width = frame.sourceSizeW;
208
- this.texture.height = frame.sourceSizeH;
209
- this.texture.frame.width = frame.sourceSizeW;
210
- this.texture.frame.height = frame.sourceSizeH;
211
- } else if (!frame.trimmed && this.texture.trim) {
209
+ this.texture.width = trimmed.sourceSizeW;
210
+ this.texture.height = trimmed.sourceSizeH;
211
+ this.texture.frame.width = trimmed.sourceSizeW;
212
+ this.texture.frame.height = trimmed.sourceSizeH;
213
+ } else if (this.texture.trim) {
212
214
  this.texture.trim = null;
213
215
  }
214
216
  if (this.cropRect) {
@@ -308,13 +310,14 @@ export class Image extends DisplayObject {
308
310
  const oldY = this.texture.crop.y;
309
311
  const oldW = this.texture.crop.width;
310
312
  const oldH = this.texture.crop.height;
313
+ const frame = this._frame!;
311
314
  this._crop = clone(this.cropRect, this._crop);
312
- this._crop.x += this._frame.x;
313
- this._crop.y += this._frame.y;
314
- const cx = Math.max(this._frame.x, this._crop.x);
315
- const cy = Math.max(this._frame.y, this._crop.y);
316
- const cw = Math.min(this._frame.right, this._crop.right) - cx;
317
- const ch = Math.min(this._frame.bottom, this._crop.bottom) - cy;
315
+ this._crop.x += frame.x;
316
+ this._crop.y += frame.y;
317
+ const cx = Math.max(frame.x, this._crop.x);
318
+ const cy = Math.max(frame.y, this._crop.y);
319
+ const cw = Math.min(frame.right, this._crop.right) - cx;
320
+ const ch = Math.min(frame.bottom, this._crop.bottom) - cy;
318
321
  this.texture.crop.x = cx;
319
322
  this.texture.crop.y = cy;
320
323
  this.texture.crop.width = cw;
@@ -6,6 +6,7 @@ import type { Texture } from './webgl/texture.js';
6
6
  import type { Matrix } from '../geom/matrix.js';
7
7
  import type { RenderSession } from './render_session.js';
8
8
  import { setSmoothing } from './canvas/util.js';
9
+ import type { Rectangle } from '../geom/rectangle.js';
9
10
 
10
11
  /**
11
12
  * Sets the texture of a sprite.
@@ -29,7 +30,7 @@ export const setTexture = (target: Image, texture: Texture, destroyBase = false)
29
30
  * @param {object} matrix - The transformation matrix.
30
31
  * @returns {Rectangle} The bounds rectangle.
31
32
  */
32
- export const getBounds = (target: Image, matrix: Matrix | null = null) => {
33
+ export const getBounds = (target: Image, matrix: Matrix | null = null): Rectangle => {
33
34
  if (target.currentBounds) {
34
35
  return target.currentBounds;
35
36
  }
@@ -110,7 +111,7 @@ export const getBounds = (target: Image, matrix: Matrix | null = null) => {
110
111
  * @param {Image} target - The target image to get local bounds for.
111
112
  * @returns {Rectangle} The local bounds rectangle.
112
113
  */
113
- export const getLocalBounds = (target: Image) => {
114
+ export const getLocalBounds = (target: Image): Rectangle => {
114
115
  const matrixCache = target.worldTransform;
115
116
  target.worldTransform = getIdentityMatrix();
116
117
  for (const child of target.children) {
@@ -36,99 +36,102 @@ const createContext2D = (): CanvasRenderingContext2D =>
36
36
  const createGame = (): Game =>
37
37
  ({
38
38
  renderer: { resolution: 1 },
39
- cache: { getImage: () => null },
40
- add: { existing: (child: unknown) => child },
39
+ cache: { getImage: (): null => null },
40
+ add: { existing: (child: unknown): unknown => child },
41
41
  }) as unknown as Game;
42
42
 
43
43
  const createText = (value: string | number): Text => new Text(createGame(), 0, 0, value);
44
44
 
45
- describe('Text', () => {
45
+ describe('Text', (): void => {
46
46
  const originalGetContext = HTMLCanvasElement.prototype.getContext;
47
47
 
48
- beforeAll(() => {
49
- HTMLCanvasElement.prototype.getContext = function getContext(this: HTMLCanvasElement, id: string) {
48
+ beforeAll((): void => {
49
+ HTMLCanvasElement.prototype.getContext = function getContext(
50
+ this: HTMLCanvasElement,
51
+ id: string
52
+ ): CanvasRenderingContext2D | null {
50
53
  return id === '2d' ? createContext2D() : null;
51
54
  } as typeof HTMLCanvasElement.prototype.getContext;
52
55
  });
53
56
 
54
- beforeEach(() => {
57
+ beforeEach((): void => {
55
58
  getRegistry().CACHE_MISSING_IMAGE = textureFromCanvas(document.createElement('canvas'));
56
59
  });
57
60
 
58
- afterAll(() => {
61
+ afterAll((): void => {
59
62
  HTMLCanvasElement.prototype.getContext = originalGetContext;
60
63
  });
61
64
 
62
- describe('constructor', () => {
63
- it('keeps a string as-is', () => {
65
+ describe('constructor', (): void => {
66
+ it('keeps a string as-is', (): void => {
64
67
  expect(createText('hello').text).toBe('hello');
65
68
  });
66
69
 
67
70
  // Callers pass numbers straight into game.add.text(). The constructor must coerce:
68
71
  // updateText() calls .split() on the value, which throws on a number.
69
- it('coerces a number to its string form', () => {
72
+ it('coerces a number to its string form', (): void => {
70
73
  expect(createText(42).text).toBe('42');
71
74
  });
72
75
 
73
- it('coerces zero rather than falling back to the empty string', () => {
76
+ it('coerces zero rather than falling back to the empty string', (): void => {
74
77
  expect(createText(0).text).toBe('0');
75
78
  });
76
79
 
77
- it('coerces a negative number', () => {
80
+ it('coerces a negative number', (): void => {
78
81
  expect(createText(-7).text).toBe('-7');
79
82
  });
80
83
 
81
- it('defaults to the empty string', () => {
84
+ it('defaults to the empty string', (): void => {
82
85
  expect(new Text(createGame(), 0, 0).text).toBe('');
83
86
  });
84
87
 
85
- it('renders a numeric label without throwing', () => {
86
- expect(() => createText(2026)).not.toThrow();
88
+ it('renders a numeric label without throwing', (): void => {
89
+ expect((): Text => createText(2026)).not.toThrow();
87
90
  });
88
91
  });
89
92
 
90
- describe('text setter', () => {
91
- it('coerces a number assigned after construction', () => {
93
+ describe('text setter', (): void => {
94
+ it('coerces a number assigned after construction', (): void => {
92
95
  const text = createText('start');
93
96
  text.text = 99;
94
97
  expect(text.text).toBe('99');
95
98
  });
96
99
  });
97
100
 
98
- describe('fontSize', () => {
101
+ describe('fontSize', (): void => {
99
102
  // A px-suffixed size cannot be read with Number(); it yields NaN. An autofix made exactly that
100
103
  // substitution once already.
101
- it('reads a px size back as a number', () => {
104
+ it('reads a px size back as a number', (): void => {
102
105
  const text = new Text(createGame(), 0, 0, 'hello', { font: '20px Arial' });
103
106
  expect(text.fontSize).toBe(20);
104
107
  });
105
108
 
106
- it('round trips through the setter', () => {
109
+ it('round trips through the setter', (): void => {
107
110
  const text = createText('hello');
108
111
  text.fontSize = 32;
109
112
  expect(text.fontSize).toBe(32);
110
113
  });
111
114
 
112
- it('reads zero back as zero', () => {
115
+ it('reads zero back as zero', (): void => {
113
116
  const text = createText('hello');
114
117
  text.fontSize = 0;
115
118
  expect(text.fontSize).toBe(0);
116
119
  });
117
120
 
118
- it('never reports NaN for a styled font', () => {
121
+ it('never reports NaN for a styled font', (): void => {
119
122
  const text = new Text(createGame(), 0, 0, 'hello', { font: 'bold 14px Arial' });
120
123
  expect(Number.isNaN(text.fontSize)).toBe(false);
121
124
  });
122
125
  });
123
126
 
124
- describe('setText', () => {
125
- it('coerces a number', () => {
127
+ describe('setText', (): void => {
128
+ it('coerces a number', (): void => {
126
129
  const text = createText('start');
127
130
  text.setText(123);
128
131
  expect(text.text).toBe('123');
129
132
  });
130
133
 
131
- it('returns itself for chaining', () => {
134
+ it('returns itself for chaining', (): void => {
132
135
  const text = createText('start');
133
136
  expect(text.setText('next')).toBe(text);
134
137
  });
@@ -229,10 +229,7 @@ export class Text extends Image {
229
229
  public updateText(): void {
230
230
  this.texture.baseTexture.resolution = this._res;
231
231
  this.context.font = this.style.font;
232
- let outputText: any = this.text;
233
- if (this.style.wordWrap) {
234
- outputText = this.runWordWrap(this.text);
235
- }
232
+ const outputText = this.style.wordWrap ? this.runWordWrap(this.text) : this.text;
236
233
  // Split text into lines
237
234
  const lines = outputText.split(/(?:\r\n|\r|\n)/);
238
235
  // Calculate text width
@@ -250,24 +247,28 @@ export class Text extends Image {
250
247
  }
251
248
  this._charCount = 0;
252
249
  for (let i = 0; i < drawnLines; i += 1) {
250
+ const currentLine = lines[i]!;
253
251
  if (tabs === 0) {
254
252
  // Simple layout (no tabs)
255
253
  lineWidth = this.style.strokeThickness + this.padding.x;
256
- lineWidth += this.hasCharacterStyles() ? this.measureLine(lines[i]) : this.context.measureText(lines[i]).width;
254
+ lineWidth += this.hasCharacterStyles()
255
+ ? this.measureLine(currentLine)
256
+ : this.context.measureText(currentLine).width;
257
257
  // Adjust for wrapped text
258
258
  if (this.style.wordWrap) {
259
259
  lineWidth -= this.context.measureText(' ').width;
260
260
  }
261
261
  } else {
262
262
  // Complex layout (tabs)
263
- const line = lines[i].split(/(?:\t)/);
263
+ const line = currentLine.split(/(?:\t)/);
264
264
  lineWidth = this.padding.x + this.style.strokeThickness;
265
265
  if (Array.isArray(tabs)) {
266
266
  let tab = 0;
267
267
  for (let c = 0; c < line.length; c += 1) {
268
+ const part = line[c]!;
268
269
  const section = this.hasCharacterStyles()
269
- ? this.measureLine(line[c])
270
- : Math.ceil(this.context.measureText(line[c]).width);
270
+ ? this.measureLine(part)
271
+ : Math.ceil(this.context.measureText(part).width);
271
272
  if (c > 0) {
272
273
  tab += tabs[c - 1]!;
273
274
  }
@@ -317,6 +318,7 @@ export class Text extends Image {
317
318
  this._charCount = 0;
318
319
  // Draw text line by line
319
320
  for (let i = 0; i < drawnLines; i += 1) {
321
+ const line = lines[i]!;
320
322
  // Split the line by
321
323
  linePositionX = this.style.strokeThickness / 2;
322
324
  linePositionY = this.style.strokeThickness / 2 + i * lineHeight + fontProperties.ascent;
@@ -333,22 +335,22 @@ export class Text extends Image {
333
335
  linePositionY = Math.round(linePositionY);
334
336
  }
335
337
  if (this.hasCharacterStyles()) {
336
- this.updateLine(lines[i], linePositionX, linePositionY);
338
+ this.updateLine(line, linePositionX, linePositionY);
337
339
  } else {
338
340
  if (this.style.stroke && this.style.strokeThickness) {
339
341
  this.updateShadow(this.style.shadowStroke ?? false);
340
342
  if (tabs === 0) {
341
- this.context.strokeText(lines[i], linePositionX, linePositionY);
343
+ this.context.strokeText(line, linePositionX, linePositionY);
342
344
  } else {
343
- this.renderTabLine(lines[i], linePositionX, linePositionY, false);
345
+ this.renderTabLine(line, linePositionX, linePositionY, false);
344
346
  }
345
347
  }
346
348
  if (this.style.fill) {
347
349
  this.updateShadow(this.style.shadowFill ?? false);
348
350
  if (tabs === 0) {
349
- this.context.fillText(lines[i], linePositionX, linePositionY);
351
+ this.context.fillText(line, linePositionX, linePositionY);
350
352
  } else {
351
- this.renderTabLine(lines[i], linePositionX, linePositionY, true);
353
+ this.renderTabLine(line, linePositionX, linePositionY, true);
352
354
  }
353
355
  }
354
356
  }
@@ -738,7 +740,7 @@ export class Text extends Image {
738
740
  * @param {string} font - The font string to convert.
739
741
  * @returns {{ font: string, fontStyle?: string, fontVariant?: string, fontWeight?: string, fontSize?: string, fontFamily?: string }} The font components.
740
742
  */
741
- public fontToComponents(font: string) {
743
+ public fontToComponents(font: string): FontComponents {
742
744
  // The format is specified in http://www.w3.org/TR/CSS2/fonts.html#font-shorthand:
743
745
  // style - normal | italic | oblique | inherit
744
746
  // variant - normal | small-caps | inherit
@@ -826,19 +828,20 @@ export class Text extends Image {
826
828
  * @param {string[]|string[][]} list - The list of text to parse.
827
829
  * @returns {Text} This Text object for chaining.
828
830
  */
829
- public parseList(list: any): this {
831
+ public parseList(list: string[] | string[][]): this {
830
832
  if (!Array.isArray(list)) {
831
833
  return this;
832
834
  }
833
835
  let s = '';
834
836
  for (let i = 0; i < list.length; i += 1) {
835
- if (Array.isArray(list[i])) {
836
- s += list[i].join('\t');
837
+ const row = list[i]!;
838
+ if (Array.isArray(row)) {
839
+ s += row.join('\t');
837
840
  if (i < list.length - 1) {
838
841
  s += '\n';
839
842
  }
840
843
  } else {
841
- s += list[i];
844
+ s += row;
842
845
  if (i < list.length - 1) {
843
846
  s += '\t';
844
847
  }
@@ -1,17 +1,27 @@
1
+ import { v4 as uuidv4 } from 'uuid';
2
+ import type { NormalShader } from './shader/normal.js';
3
+
4
+ /** A shader uniform: its GLSL type and the value bound to it. */
5
+ export type ShaderUniform = {
6
+ type: string;
7
+ value: unknown;
8
+ };
9
+
1
10
  export class AbstractFilter {
2
- [key: string]: any;
3
- public passes!: any;
4
- public shaders!: any;
5
- public dirty!: any;
6
- public padding!: any;
7
- public uniforms!: any;
8
- public fragmentSrc!: any;
11
+ public _UID: string;
12
+ public passes: AbstractFilter[];
13
+ public shaders: NormalShader[];
14
+ public dirty: boolean;
15
+ public padding: number;
16
+ public uniforms: Record<string, ShaderUniform>;
17
+ public fragmentSrc: string[];
9
18
  /**
10
19
  * Creates a new AbstractFilter instance.
11
20
  * @param {string[]} fragmentSrc - The fragment shader source.
12
21
  * @param {object} uniforms - The uniform variables for the shader.
13
22
  */
14
- public constructor(fragmentSrc: string[], uniforms?: any) {
23
+ public constructor(fragmentSrc: string[], uniforms?: Record<string, ShaderUniform>) {
24
+ this._UID = uuidv4();
15
25
  this.passes = [this];
16
26
  this.shaders = [];
17
27
  this.dirty = true;
@@ -24,8 +34,8 @@ export class AbstractFilter {
24
34
  * Initializes the filter.
25
35
  */
26
36
  public syncUniforms(): void {
27
- for (let i = 0, j = this.shaders.length; i < j; i += 1) {
28
- this.shaders[i].dirty = true;
37
+ for (const shader of this.shaders) {
38
+ shader.dirty = true;
29
39
  }
30
40
  }
31
41
  }
@@ -1,7 +1,6 @@
1
1
  export class WebGLBlendModeManager {
2
- [key: string]: any;
3
- public gl: any = null;
4
- public currentBlendMode: any = 99_999;
2
+ public gl!: WebGLRenderingContext;
3
+ public currentBlendMode = 99_999;
5
4
  /**
6
5
  * Creates a new BlendModeManager instance.
7
6
  */
@@ -26,7 +25,7 @@ export class WebGLBlendModeManager {
26
25
  this.currentBlendMode = blendMode;
27
26
  const blendModeWebGL = globalThis.PhaserRegistry.blendModesWebGL[this.currentBlendMode];
28
27
  if (blendModeWebGL) {
29
- this.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]);
28
+ this.gl.blendFunc(blendModeWebGL[0]!, blendModeWebGL[1]!);
30
29
  }
31
30
  return true;
32
31
  }
@@ -35,6 +34,6 @@ export class WebGLBlendModeManager {
35
34
  * Sets the blend mode for the WebGL context.
36
35
  */
37
36
  public destroy(): void {
38
- this.gl = null;
37
+ this.gl = null!;
39
38
  }
40
39
  }