@vpmedia/phaser 1.103.0 → 1.105.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 (298) hide show
  1. package/dist/index.js +997 -403
  2. package/dist/index.js.map +1 -1
  3. package/dist/phaser/core/animation.d.ts +35 -11
  4. package/dist/phaser/core/animation.d.ts.map +1 -1
  5. package/dist/phaser/core/animation_manager.d.ts +20 -10
  6. package/dist/phaser/core/animation_manager.d.ts.map +1 -1
  7. package/dist/phaser/core/animation_parser.d.ts +2 -2
  8. package/dist/phaser/core/animation_parser.d.ts.map +1 -1
  9. package/dist/phaser/core/array_set.d.ts +3 -3
  10. package/dist/phaser/core/array_set.d.ts.map +1 -1
  11. package/dist/phaser/core/cache.d.ts +68 -60
  12. package/dist/phaser/core/cache.d.ts.map +1 -1
  13. package/dist/phaser/core/device.d.ts +23 -0
  14. package/dist/phaser/core/device.d.ts.map +1 -1
  15. package/dist/phaser/core/device_util.d.ts +10 -10
  16. package/dist/phaser/core/device_util.d.ts.map +1 -1
  17. package/dist/phaser/core/dom.d.ts +6 -5
  18. package/dist/phaser/core/dom.d.ts.map +1 -1
  19. package/dist/phaser/core/event_manager.d.ts +49 -158
  20. package/dist/phaser/core/event_manager.d.ts.map +1 -1
  21. package/dist/phaser/core/factory.d.ts +8 -7
  22. package/dist/phaser/core/factory.d.ts.map +1 -1
  23. package/dist/phaser/core/frame.d.ts +27 -48
  24. package/dist/phaser/core/frame.d.ts.map +1 -1
  25. package/dist/phaser/core/frame_data.d.ts +11 -58
  26. package/dist/phaser/core/frame_data.d.ts.map +1 -1
  27. package/dist/phaser/core/frame_util.d.ts +4 -14
  28. package/dist/phaser/core/frame_util.d.ts.map +1 -1
  29. package/dist/phaser/core/game.d.ts +50 -3
  30. package/dist/phaser/core/game.d.ts.map +1 -1
  31. package/dist/phaser/core/input.d.ts +66 -13
  32. package/dist/phaser/core/input.d.ts.map +1 -1
  33. package/dist/phaser/core/input_handler.d.ts +64 -20
  34. package/dist/phaser/core/input_handler.d.ts.map +1 -1
  35. package/dist/phaser/core/input_mouse.d.ts +26 -1
  36. package/dist/phaser/core/input_mouse.d.ts.map +1 -1
  37. package/dist/phaser/core/input_mspointer.d.ts +18 -2
  38. package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
  39. package/dist/phaser/core/input_pointer.d.ts +53 -9
  40. package/dist/phaser/core/input_pointer.d.ts.map +1 -1
  41. package/dist/phaser/core/input_touch.d.ts +19 -1
  42. package/dist/phaser/core/input_touch.d.ts.map +1 -1
  43. package/dist/phaser/core/loader.d.ts +56 -28
  44. package/dist/phaser/core/loader.d.ts.map +1 -1
  45. package/dist/phaser/core/loader_parser.d.ts +4 -4
  46. package/dist/phaser/core/loader_parser.d.ts.map +1 -1
  47. package/dist/phaser/core/raf.d.ts +2 -2
  48. package/dist/phaser/core/raf.d.ts.map +1 -1
  49. package/dist/phaser/core/scale_manager.d.ts +77 -17
  50. package/dist/phaser/core/scale_manager.d.ts.map +1 -1
  51. package/dist/phaser/core/scene.d.ts +3 -1
  52. package/dist/phaser/core/scene.d.ts.map +1 -1
  53. package/dist/phaser/core/scene_manager.d.ts +25 -9
  54. package/dist/phaser/core/scene_manager.d.ts.map +1 -1
  55. package/dist/phaser/core/signal.d.ts +9 -8
  56. package/dist/phaser/core/signal.d.ts.map +1 -1
  57. package/dist/phaser/core/signal_binding.d.ts +2 -2
  58. package/dist/phaser/core/signal_binding.d.ts.map +1 -1
  59. package/dist/phaser/core/sound.d.ts +58 -10
  60. package/dist/phaser/core/sound.d.ts.map +1 -1
  61. package/dist/phaser/core/sound_manager.d.ts +28 -9
  62. package/dist/phaser/core/sound_manager.d.ts.map +1 -1
  63. package/dist/phaser/core/sound_sprite.d.ts +10 -4
  64. package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
  65. package/dist/phaser/core/stage.d.ts +7 -3
  66. package/dist/phaser/core/stage.d.ts.map +1 -1
  67. package/dist/phaser/core/time.d.ts +32 -5
  68. package/dist/phaser/core/time.d.ts.map +1 -1
  69. package/dist/phaser/core/timer.d.ts +30 -10
  70. package/dist/phaser/core/timer.d.ts.map +1 -1
  71. package/dist/phaser/core/timer_event.d.ts +11 -12
  72. package/dist/phaser/core/timer_event.d.ts.map +1 -1
  73. package/dist/phaser/core/tween.d.ts +38 -14
  74. package/dist/phaser/core/tween.d.ts.map +1 -1
  75. package/dist/phaser/core/tween_data.d.ts +30 -5
  76. package/dist/phaser/core/tween_data.d.ts.map +1 -1
  77. package/dist/phaser/core/tween_easing.d.ts +31 -31
  78. package/dist/phaser/core/tween_easing.d.ts.map +1 -1
  79. package/dist/phaser/core/tween_manager.d.ts +8 -4
  80. package/dist/phaser/core/tween_manager.d.ts.map +1 -1
  81. package/dist/phaser/core/world.d.ts +1 -1
  82. package/dist/phaser/core/world.d.ts.map +1 -1
  83. package/dist/phaser/display/bitmap_text.d.ts +35 -20
  84. package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
  85. package/dist/phaser/display/button.d.ts +24 -8
  86. package/dist/phaser/display/button.d.ts.map +1 -1
  87. package/dist/phaser/display/canvas/buffer.d.ts +6 -2
  88. package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
  89. package/dist/phaser/display/canvas/graphics.d.ts +3 -3
  90. package/dist/phaser/display/canvas/graphics.d.ts.map +1 -1
  91. package/dist/phaser/display/canvas/masker.d.ts.map +1 -1
  92. package/dist/phaser/display/canvas/pool.d.ts +2 -2
  93. package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
  94. package/dist/phaser/display/canvas/renderer.d.ts +18 -5
  95. package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
  96. package/dist/phaser/display/canvas/tinter.d.ts +3 -3
  97. package/dist/phaser/display/canvas/tinter.d.ts.map +1 -1
  98. package/dist/phaser/display/canvas/util.d.ts +9 -9
  99. package/dist/phaser/display/canvas/util.d.ts.map +1 -1
  100. package/dist/phaser/display/display_object.d.ts +82 -23
  101. package/dist/phaser/display/display_object.d.ts.map +1 -1
  102. package/dist/phaser/display/graphics.d.ts +42 -16
  103. package/dist/phaser/display/graphics.d.ts.map +1 -1
  104. package/dist/phaser/display/graphics_data.d.ts +11 -1
  105. package/dist/phaser/display/graphics_data.d.ts.map +1 -1
  106. package/dist/phaser/display/graphics_data_util.d.ts +1 -1
  107. package/dist/phaser/display/graphics_data_util.d.ts.map +1 -1
  108. package/dist/phaser/display/group.d.ts +24 -9
  109. package/dist/phaser/display/group.d.ts.map +1 -1
  110. package/dist/phaser/display/image.d.ts +36 -13
  111. package/dist/phaser/display/image.d.ts.map +1 -1
  112. package/dist/phaser/display/sprite_batch.d.ts +1 -1
  113. package/dist/phaser/display/sprite_batch.d.ts.map +1 -1
  114. package/dist/phaser/display/sprite_util.d.ts +5 -5
  115. package/dist/phaser/display/sprite_util.d.ts.map +1 -1
  116. package/dist/phaser/display/text.d.ts +86 -66
  117. package/dist/phaser/display/text.d.ts.map +1 -1
  118. package/dist/phaser/display/webgl/abstract_filter.d.ts +8 -1
  119. package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
  120. package/dist/phaser/display/webgl/base_texture.d.ts +14 -2
  121. package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
  122. package/dist/phaser/display/webgl/blend_manager.d.ts +5 -2
  123. package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
  124. package/dist/phaser/display/webgl/earcut.d.ts +10 -10
  125. package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
  126. package/dist/phaser/display/webgl/earcut_node.d.ts +1 -1
  127. package/dist/phaser/display/webgl/earcut_node.d.ts.map +1 -1
  128. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +17 -1
  129. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
  130. package/dist/phaser/display/webgl/filter_manager.d.ts +5 -1
  131. package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
  132. package/dist/phaser/display/webgl/filter_texture.d.ts +7 -2
  133. package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
  134. package/dist/phaser/display/webgl/graphics.d.ts +11 -10
  135. package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
  136. package/dist/phaser/display/webgl/graphics_data.d.ts +11 -1
  137. package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
  138. package/dist/phaser/display/webgl/mask_manager.d.ts.map +1 -1
  139. package/dist/phaser/display/webgl/render_texture.d.ts +12 -1
  140. package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
  141. package/dist/phaser/display/webgl/renderer.d.ts +25 -6
  142. package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
  143. package/dist/phaser/display/webgl/shader/complex.d.ts +7 -1
  144. package/dist/phaser/display/webgl/shader/complex.d.ts.map +1 -1
  145. package/dist/phaser/display/webgl/shader/fast.d.ts +8 -1
  146. package/dist/phaser/display/webgl/shader/fast.d.ts.map +1 -1
  147. package/dist/phaser/display/webgl/shader/normal.d.ts +11 -0
  148. package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
  149. package/dist/phaser/display/webgl/shader/primitive.d.ts +7 -1
  150. package/dist/phaser/display/webgl/shader/primitive.d.ts.map +1 -1
  151. package/dist/phaser/display/webgl/shader/strip.d.ts +7 -1
  152. package/dist/phaser/display/webgl/shader/strip.d.ts.map +1 -1
  153. package/dist/phaser/display/webgl/shader_manager.d.ts +14 -2
  154. package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
  155. package/dist/phaser/display/webgl/sprite_batch.d.ts +19 -2
  156. package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
  157. package/dist/phaser/display/webgl/stencil_manager.d.ts +8 -4
  158. package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
  159. package/dist/phaser/display/webgl/texture.d.ts +35 -2
  160. package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
  161. package/dist/phaser/display/webgl/texture_util.d.ts +2 -2
  162. package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
  163. package/dist/phaser/display/webgl/util.d.ts +6 -6
  164. package/dist/phaser/display/webgl/util.d.ts.map +1 -1
  165. package/dist/phaser/geom/circle.d.ts +11 -10
  166. package/dist/phaser/geom/circle.d.ts.map +1 -1
  167. package/dist/phaser/geom/ellipse.d.ts +6 -5
  168. package/dist/phaser/geom/ellipse.d.ts.map +1 -1
  169. package/dist/phaser/geom/line.d.ts +14 -14
  170. package/dist/phaser/geom/line.d.ts.map +1 -1
  171. package/dist/phaser/geom/matrix.d.ts +13 -12
  172. package/dist/phaser/geom/matrix.d.ts.map +1 -1
  173. package/dist/phaser/geom/point.d.ts +19 -19
  174. package/dist/phaser/geom/point.d.ts.map +1 -1
  175. package/dist/phaser/geom/polygon.d.ts +6 -6
  176. package/dist/phaser/geom/polygon.d.ts.map +1 -1
  177. package/dist/phaser/geom/rectangle.d.ts +20 -20
  178. package/dist/phaser/geom/rectangle.d.ts.map +1 -1
  179. package/dist/phaser/geom/rounded_rectangle.d.ts +2 -2
  180. package/dist/phaser/geom/rounded_rectangle.d.ts.map +1 -1
  181. package/dist/phaser/geom/util/circle.d.ts +9 -7
  182. package/dist/phaser/geom/util/circle.d.ts.map +1 -1
  183. package/dist/phaser/geom/util/ellipse.d.ts +1 -1
  184. package/dist/phaser/geom/util/ellipse.d.ts.map +1 -1
  185. package/dist/phaser/geom/util/line.d.ts +5 -3
  186. package/dist/phaser/geom/util/line.d.ts.map +1 -1
  187. package/dist/phaser/geom/util/matrix.d.ts +2 -1
  188. package/dist/phaser/geom/util/matrix.d.ts.map +1 -1
  189. package/dist/phaser/geom/util/point.d.ts +19 -19
  190. package/dist/phaser/geom/util/point.d.ts.map +1 -1
  191. package/dist/phaser/geom/util/polygon.d.ts +2 -1
  192. package/dist/phaser/geom/util/polygon.d.ts.map +1 -1
  193. package/dist/phaser/geom/util/rectangle.d.ts +17 -15
  194. package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
  195. package/dist/phaser/geom/util/rounded_rectangle.d.ts +2 -1
  196. package/dist/phaser/geom/util/rounded_rectangle.d.ts.map +1 -1
  197. package/dist/phaser/util/math.d.ts +51 -142
  198. package/dist/phaser/util/math.d.ts.map +1 -1
  199. package/package.json +2 -2
  200. package/src/phaser/core/animation.ts +41 -18
  201. package/src/phaser/core/animation_manager.ts +21 -12
  202. package/src/phaser/core/animation_parser.ts +11 -3
  203. package/src/phaser/core/array_set.ts +8 -8
  204. package/src/phaser/core/cache.ts +75 -60
  205. package/src/phaser/core/device.ts +23 -1
  206. package/src/phaser/core/device_util.ts +10 -10
  207. package/src/phaser/core/dom.ts +5 -5
  208. package/src/phaser/core/event_manager.ts +52 -177
  209. package/src/phaser/core/factory.ts +25 -17
  210. package/src/phaser/core/frame.ts +37 -51
  211. package/src/phaser/core/frame_data.ts +29 -74
  212. package/src/phaser/core/frame_util.ts +3 -16
  213. package/src/phaser/core/game.ts +40 -11
  214. package/src/phaser/core/input.ts +68 -17
  215. package/src/phaser/core/input_handler.ts +81 -45
  216. package/src/phaser/core/input_mouse.ts +42 -13
  217. package/src/phaser/core/input_mspointer.ts +24 -9
  218. package/src/phaser/core/input_pointer.ts +55 -12
  219. package/src/phaser/core/input_touch.ts +26 -9
  220. package/src/phaser/core/loader.ts +97 -42
  221. package/src/phaser/core/loader_parser.ts +6 -7
  222. package/src/phaser/core/raf.ts +2 -2
  223. package/src/phaser/core/scale_manager.ts +85 -27
  224. package/src/phaser/core/scene.ts +3 -2
  225. package/src/phaser/core/scene_manager.ts +26 -11
  226. package/src/phaser/core/signal.ts +10 -10
  227. package/src/phaser/core/signal_binding.ts +2 -2
  228. package/src/phaser/core/sound.ts +72 -26
  229. package/src/phaser/core/sound_manager.ts +31 -13
  230. package/src/phaser/core/sound_sprite.ts +10 -5
  231. package/src/phaser/core/stage.ts +8 -4
  232. package/src/phaser/core/time.ts +33 -7
  233. package/src/phaser/core/timer.ts +40 -14
  234. package/src/phaser/core/timer_event.ts +23 -14
  235. package/src/phaser/core/tween.ts +43 -23
  236. package/src/phaser/core/tween_data.ts +31 -7
  237. package/src/phaser/core/tween_easing.ts +31 -31
  238. package/src/phaser/core/tween_manager.ts +10 -7
  239. package/src/phaser/core/world.ts +1 -2
  240. package/src/phaser/display/bitmap_text.ts +41 -18
  241. package/src/phaser/display/button.ts +24 -23
  242. package/src/phaser/display/canvas/buffer.ts +6 -3
  243. package/src/phaser/display/canvas/graphics.ts +3 -4
  244. package/src/phaser/display/canvas/masker.ts +2 -3
  245. package/src/phaser/display/canvas/pool.ts +3 -4
  246. package/src/phaser/display/canvas/renderer.ts +19 -7
  247. package/src/phaser/display/canvas/tinter.ts +4 -5
  248. package/src/phaser/display/canvas/util.ts +9 -9
  249. package/src/phaser/display/display_object.ts +120 -61
  250. package/src/phaser/display/graphics.ts +56 -25
  251. package/src/phaser/display/graphics_data.ts +11 -2
  252. package/src/phaser/display/graphics_data_util.ts +1 -2
  253. package/src/phaser/display/group.ts +32 -14
  254. package/src/phaser/display/image.ts +37 -19
  255. package/src/phaser/display/sprite_batch.ts +1 -2
  256. package/src/phaser/display/sprite_util.ts +5 -6
  257. package/src/phaser/display/text.ts +82 -56
  258. package/src/phaser/display/webgl/abstract_filter.ts +8 -2
  259. package/src/phaser/display/webgl/base_texture.ts +14 -3
  260. package/src/phaser/display/webgl/blend_manager.ts +5 -3
  261. package/src/phaser/display/webgl/earcut.ts +27 -27
  262. package/src/phaser/display/webgl/earcut_node.ts +1 -1
  263. package/src/phaser/display/webgl/fast_sprite_batch.ts +19 -4
  264. package/src/phaser/display/webgl/filter_manager.ts +5 -2
  265. package/src/phaser/display/webgl/filter_texture.ts +7 -3
  266. package/src/phaser/display/webgl/graphics.ts +10 -11
  267. package/src/phaser/display/webgl/graphics_data.ts +11 -2
  268. package/src/phaser/display/webgl/mask_manager.ts +2 -3
  269. package/src/phaser/display/webgl/render_texture.ts +12 -2
  270. package/src/phaser/display/webgl/renderer.ts +24 -7
  271. package/src/phaser/display/webgl/shader/complex.ts +7 -2
  272. package/src/phaser/display/webgl/shader/fast.ts +8 -2
  273. package/src/phaser/display/webgl/shader/normal.ts +12 -2
  274. package/src/phaser/display/webgl/shader/primitive.ts +7 -2
  275. package/src/phaser/display/webgl/shader/strip.ts +7 -2
  276. package/src/phaser/display/webgl/shader_manager.ts +13 -3
  277. package/src/phaser/display/webgl/sprite_batch.ts +20 -4
  278. package/src/phaser/display/webgl/stencil_manager.ts +8 -5
  279. package/src/phaser/display/webgl/texture.ts +35 -4
  280. package/src/phaser/display/webgl/texture_util.ts +2 -3
  281. package/src/phaser/display/webgl/util.ts +6 -6
  282. package/src/phaser/geom/circle.ts +10 -10
  283. package/src/phaser/geom/ellipse.ts +6 -6
  284. package/src/phaser/geom/line.ts +14 -14
  285. package/src/phaser/geom/matrix.ts +12 -12
  286. package/src/phaser/geom/point.ts +19 -19
  287. package/src/phaser/geom/polygon.ts +5 -5
  288. package/src/phaser/geom/rectangle.ts +21 -21
  289. package/src/phaser/geom/rounded_rectangle.ts +2 -2
  290. package/src/phaser/geom/util/circle.ts +7 -7
  291. package/src/phaser/geom/util/ellipse.ts +1 -1
  292. package/src/phaser/geom/util/line.ts +5 -5
  293. package/src/phaser/geom/util/matrix.ts +1 -1
  294. package/src/phaser/geom/util/point.ts +20 -20
  295. package/src/phaser/geom/util/polygon.ts +1 -1
  296. package/src/phaser/geom/util/rectangle.ts +15 -15
  297. package/src/phaser/geom/util/rounded_rectangle.ts +1 -1
  298. package/src/phaser/util/math.ts +65 -151
@@ -7,7 +7,7 @@ import { Point } from '../point.js';
7
7
  * @param {Point} output - The point to store the result in (optional).
8
8
  * @returns {Point} A new point containing the sum of the two points.
9
9
  */
10
- export const add = (a, b, output = null) => {
10
+ export const add = (a: Point, b: Point, output: Point = null) => {
11
11
  const result = output || new Point();
12
12
  result.x = a.x + b.x;
13
13
  result.y = a.y + b.y;
@@ -21,7 +21,7 @@ export const add = (a, b, output = null) => {
21
21
  * @param {Point} output - The point to store the result in (optional).
22
22
  * @returns {Point} A new point containing the difference of the two points.
23
23
  */
24
- export const subtract = (a, b, output = null) => {
24
+ export const subtract = (a: Point, b: Point, output: Point = null) => {
25
25
  const result = output || new Point();
26
26
  result.x = a.x - b.x;
27
27
  result.y = a.y - b.y;
@@ -35,7 +35,7 @@ export const subtract = (a, b, output = null) => {
35
35
  * @param {Point} output - The point to store the result in (optional).
36
36
  * @returns {Point} A new point containing the product of the two points.
37
37
  */
38
- export const multiply = (a, b, output = null) => {
38
+ export const multiply = (a: Point, b: Point, output: Point = null) => {
39
39
  const result = output || new Point();
40
40
  result.x = a.x * b.x;
41
41
  result.y = a.y * b.y;
@@ -49,7 +49,7 @@ export const multiply = (a, b, output = null) => {
49
49
  * @param {Point} output - The point to store the result in (optional).
50
50
  * @returns {Point} A new point containing the quotient of the two points.
51
51
  */
52
- export const divide = (a, b, output = null) => {
52
+ export const divide = (a: Point, b: Point, output: Point = null) => {
53
53
  const result = output || new Point();
54
54
  result.x = a.x / b.x;
55
55
  result.y = a.y / b.y;
@@ -62,7 +62,7 @@ export const divide = (a, b, output = null) => {
62
62
  * @param {Point} b - The second point to compare.
63
63
  * @returns {boolean} True if the points are equal, false otherwise.
64
64
  */
65
- export const equals = (a, b) => {
65
+ export const equals = (a: Point, b: Point) => {
66
66
  return a.x === b.x && a.y === b.y;
67
67
  };
68
68
 
@@ -72,7 +72,7 @@ export const equals = (a, b) => {
72
72
  * @param {Point} b - The second point to calculate the angle to.
73
73
  * @returns {number} The angle between the two points in radians.
74
74
  */
75
- export const angle = (a, b) => {
75
+ export const angle = (a: Point, b: Point) => {
76
76
  return Math.atan2(a.y - b.y, a.x - b.x);
77
77
  };
78
78
 
@@ -82,7 +82,7 @@ export const angle = (a, b) => {
82
82
  * @param {Point} output - The point to store the result in (optional).
83
83
  * @returns {Point} A new point with negated coordinates.
84
84
  */
85
- export const negative = (a, output = null) => {
85
+ export const negative = (a: Point, output: Point = null) => {
86
86
  const result = output || new Point();
87
87
  return result.setTo(-a.x, -a.y);
88
88
  };
@@ -95,7 +95,7 @@ export const negative = (a, output = null) => {
95
95
  * @param {Point} output - The point to store the result in (optional).
96
96
  * @returns {Point} A new point with the result of the operation.
97
97
  */
98
- export const multiplyAdd = (a, b, s, output = null) => {
98
+ export const multiplyAdd = (a: Point, b: Point, s: number, output: Point = null) => {
99
99
  const result = output || new Point();
100
100
  return result.setTo(a.x + b.x * s, a.y + b.y * s);
101
101
  };
@@ -108,7 +108,7 @@ export const multiplyAdd = (a, b, s, output = null) => {
108
108
  * @param {Point} output - The point to store the result in (optional).
109
109
  * @returns {Point} A new point interpolated between the two points.
110
110
  */
111
- export const interpolate = (a, b, f, output = null) => {
111
+ export const interpolate = (a: Point, b: Point, f: number, output: Point = null) => {
112
112
  const result = output || new Point();
113
113
  return result.setTo(a.x + (b.x - a.x) * f, a.y + (b.y - a.y) * f);
114
114
  };
@@ -119,7 +119,7 @@ export const interpolate = (a, b, f, output = null) => {
119
119
  * @param {Point} output - The point to store the result in (optional).
120
120
  * @returns {Point} A new point that is perpendicular to the input point.
121
121
  */
122
- export const perp = (a, output = null) => {
122
+ export const perp = (a: Point, output: Point = null) => {
123
123
  const result = output || new Point();
124
124
  return result.setTo(-a.y, a.x);
125
125
  };
@@ -130,7 +130,7 @@ export const perp = (a, output = null) => {
130
130
  * @param {Point} output - The point to store the result in (optional).
131
131
  * @returns {Point} A new point that is perpendicular to the input point (rotated clockwise).
132
132
  */
133
- export const rperp = (a, output = null) => {
133
+ export const rperp = (a: Point, output: Point = null) => {
134
134
  const result = output || new Point();
135
135
  return result.setTo(a.y, -a.x);
136
136
  };
@@ -142,7 +142,7 @@ export const rperp = (a, output = null) => {
142
142
  * @param {boolean} round - Whether to round the result (default: false).
143
143
  * @returns {number} The distance between the two points.
144
144
  */
145
- export const distance = (a, b, round = false) => {
145
+ export const distance = (a: Point, b: Point, round: boolean = false) => {
146
146
  const dx = a.x - b.x;
147
147
  const dy = a.y - b.y;
148
148
  const abDistance = Math.sqrt(dx * dx + dy * dy);
@@ -156,7 +156,7 @@ export const distance = (a, b, round = false) => {
156
156
  * @param {Point} output - The point to store the result in (optional).
157
157
  * @returns {Point} A new point with the projected result.
158
158
  */
159
- export const project = (a, b, output = null) => {
159
+ export const project = (a: Point, b: Point, output: Point = null) => {
160
160
  const result = output || new Point();
161
161
  const amt = a.dot(b) / b.getMagnitudeSq();
162
162
  if (amt !== 0) {
@@ -172,7 +172,7 @@ export const project = (a, b, output = null) => {
172
172
  * @param {Point} output - The point to store the result in (optional).
173
173
  * @returns {Point} A new point with the projected result.
174
174
  */
175
- export const projectUnit = (a, b, output = null) => {
175
+ export const projectUnit = (a: Point, b: Point, output: Point = null) => {
176
176
  const result = output || new Point();
177
177
  const amt = a.dot(b);
178
178
  if (amt !== 0) {
@@ -187,7 +187,7 @@ export const projectUnit = (a, b, output = null) => {
187
187
  * @param {Point} output - The point to store the result in (optional).
188
188
  * @returns {Point} A new point with the same x coordinate but negated y coordinate.
189
189
  */
190
- export const normalRightHand = (a, output = null) => {
190
+ export const normalRightHand = (a: Point, output: Point = null) => {
191
191
  const result = output || new Point();
192
192
  return result.setTo(a.y * -1, a.x);
193
193
  };
@@ -198,7 +198,7 @@ export const normalRightHand = (a, output = null) => {
198
198
  * @param {Point} output - The point to store the result in (optional).
199
199
  * @returns {Point} A new normalized point.
200
200
  */
201
- export const normalize = (a, output = null) => {
201
+ export const normalize = (a: Point, output: Point = null) => {
202
202
  const result = output || new Point();
203
203
  const m = a.getMagnitude();
204
204
  if (m !== 0) {
@@ -217,7 +217,7 @@ export const normalize = (a, output = null) => {
217
217
  * @param {number | null | undefined} dist - The distance to rotate from (default: null).
218
218
  * @returns {Point} The rotated point instance for chaining.
219
219
  */
220
- export const rotate = (a, x, y, ang, asDegrees, dist) => {
220
+ export const rotate = (a: Point, x: number, y: number, ang: number, asDegrees: boolean, dist: number | null | undefined) => {
221
221
  if (asDegrees) {
222
222
  ang *= Math.PI / 180;
223
223
  }
@@ -244,7 +244,7 @@ export const rotate = (a, x, y, ang, asDegrees, dist) => {
244
244
  * @returns {Point} A new point representing the centroid of the input points.
245
245
  * @throws {Error} If the points array is empty.
246
246
  */
247
- export const centroid = (points, output = null) => {
247
+ export const centroid = (points: Point[], output: Point = null) => {
248
248
  const result = output || new Point();
249
249
  const pointsLen = points.length;
250
250
  if (pointsLen < 1) {
@@ -268,7 +268,7 @@ export const centroid = (points, output = null) => {
268
268
  * @param {string} yProp - The name of the property containing the y value (default: 'y').
269
269
  * @returns {Point} A new point with parsed x and y values.
270
270
  */
271
- export const parse = (obj, xProp = 'x', yProp = 'y') => {
271
+ export const parse = (obj: any, xProp: string = 'x', yProp: string = 'y') => {
272
272
  const point = new Point();
273
273
  if (obj[xProp]) {
274
274
  point.x = Number.parseInt(obj[xProp], 10);
@@ -285,7 +285,7 @@ export const parse = (obj, xProp = 'x', yProp = 'y') => {
285
285
  * @param {Point} output - The point to store the result in (optional).
286
286
  * @returns {Point} A new point with the same coordinates as the input.
287
287
  */
288
- export const clone = (input, output = null) => {
288
+ export const clone = (input: Point, output: Point = null) => {
289
289
  const result = output || new Point();
290
290
  result.setTo(input.x, input.y);
291
291
  return result;
@@ -6,7 +6,7 @@ import { Polygon } from '../polygon.js';
6
6
  * @param {Polygon} output - Optional polygon to store the result in.
7
7
  * @returns {Polygon} The cloned polygon.
8
8
  */
9
- export const clone = (input, output = null) => {
9
+ export const clone = (input: Polygon, output: Polygon = null) => {
10
10
  const result = output || new Polygon();
11
11
  result.setTo(input._points.slice());
12
12
  return result;
@@ -8,7 +8,7 @@ import { Rectangle } from '../rectangle.js';
8
8
  * @param {number} dy - The amount to inflate the rectangle vertically.
9
9
  * @returns {Rectangle} The inflated rectangle.
10
10
  */
11
- export const inflate = (a, dx, dy) => {
11
+ export const inflate = (a: Rectangle, dx: number, dy: number) => {
12
12
  a.x -= dx;
13
13
  a.width += 2 * dx;
14
14
  a.y -= dy;
@@ -22,7 +22,7 @@ export const inflate = (a, dx, dy) => {
22
22
  * @param {object} point - The point containing x and y values to inflate the rectangle by.
23
23
  * @returns {Rectangle} The inflated rectangle.
24
24
  */
25
- export const inflatePoint = (a, point) => {
25
+ export const inflatePoint = (a: Rectangle, point: any) => {
26
26
  return inflate(a, point.x, point.y);
27
27
  };
28
28
 
@@ -32,7 +32,7 @@ export const inflatePoint = (a, point) => {
32
32
  * @param {Point} output - Optional point to store the result in.
33
33
  * @returns {Point} The size of the rectangle as a point (width, height).
34
34
  */
35
- export const size = (a, output = null) => {
35
+ export const size = (a: Rectangle, output: Point = null) => {
36
36
  const result = output || new Point();
37
37
  result.setTo(a.width, a.height);
38
38
  return result;
@@ -44,7 +44,7 @@ export const size = (a, output = null) => {
44
44
  * @param {Rectangle} output - Optional rectangle to store the result in.
45
45
  * @returns {Rectangle} The cloned rectangle.
46
46
  */
47
- export const clone = (input, output = null) => {
47
+ export const clone = (input: Rectangle, output: Rectangle = null) => {
48
48
  const result = output || new Rectangle();
49
49
  result.setTo(input.x, input.y, input.width, input.height);
50
50
  return result;
@@ -57,7 +57,7 @@ export const clone = (input, output = null) => {
57
57
  * @param {number} y - The y coordinate of the point.
58
58
  * @returns {boolean} True if the point is contained within the rectangle, false otherwise.
59
59
  */
60
- export const contains = (a, x, y) => {
60
+ export const contains = (a: Rectangle, x: number, y: number) => {
61
61
  if (a.width <= 0 || a.height <= 0) {
62
62
  return false;
63
63
  }
@@ -74,7 +74,7 @@ export const contains = (a, x, y) => {
74
74
  * @param {number} y - The y coordinate of the point.
75
75
  * @returns {boolean} True if the point is contained within the rectangle, false otherwise.
76
76
  */
77
- export const containsRaw = (rx, ry, rw, rh, x, y) => {
77
+ export const containsRaw = (rx: number, ry: number, rw: number, rh: number, x: number, y: number) => {
78
78
  return x >= rx && x < rx + rw && y >= ry && y < ry + rh;
79
79
  };
80
80
 
@@ -84,7 +84,7 @@ export const containsRaw = (rx, ry, rw, rh, x, y) => {
84
84
  * @param {Point} point - The point to check.
85
85
  * @returns {boolean} True if the point is contained within the rectangle, false otherwise.
86
86
  */
87
- export const containsPoint = (a, point) => {
87
+ export const containsPoint = (a: Rectangle, point: Point) => {
88
88
  return contains(a, point.x, point.y);
89
89
  };
90
90
 
@@ -94,7 +94,7 @@ export const containsPoint = (a, point) => {
94
94
  * @param {Rectangle} b - The second rectangle to check.
95
95
  * @returns {boolean} True if rectangle a contains rectangle b, false otherwise.
96
96
  */
97
- export const containsRect = (a, b) => {
97
+ export const containsRect = (a: Rectangle, b: Rectangle) => {
98
98
  if (a.volume > b.volume) {
99
99
  return false;
100
100
  }
@@ -107,7 +107,7 @@ export const containsRect = (a, b) => {
107
107
  * @param {Rectangle} b - The second rectangle to compare.
108
108
  * @returns {boolean} True if the rectangles are equal, false otherwise.
109
109
  */
110
- export const equals = (a, b) => {
110
+ export const equals = (a: Rectangle, b: Rectangle) => {
111
111
  return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
112
112
  };
113
113
 
@@ -117,7 +117,7 @@ export const equals = (a, b) => {
117
117
  * @param {Rectangle} b - The second rectangle to compare.
118
118
  * @returns {boolean} True if the rectangles have the same dimensions, false otherwise.
119
119
  */
120
- export const sameDimensions = (a, b) => {
120
+ export const sameDimensions = (a: Rectangle, b: Rectangle) => {
121
121
  return a.width === b.width && a.height === b.height;
122
122
  };
123
123
 
@@ -127,7 +127,7 @@ export const sameDimensions = (a, b) => {
127
127
  * @param {Rectangle} b - The second rectangle to check.
128
128
  * @returns {boolean} True if the rectangles intersect, false otherwise.
129
129
  */
130
- export const intersects = (a, b) => {
130
+ export const intersects = (a: Rectangle, b: Rectangle) => {
131
131
  if (a.width <= 0 || a.height <= 0 || b.width <= 0 || b.height <= 0) {
132
132
  return false;
133
133
  }
@@ -141,7 +141,7 @@ export const intersects = (a, b) => {
141
141
  * @param {Rectangle} output - Optional rectangle to store the result in.
142
142
  * @returns {Rectangle} The intersection of the rectangles, or an empty rectangle if they don't intersect.
143
143
  */
144
- export const intersection = (a, b, output = null) => {
144
+ export const intersection = (a: Rectangle, b: Rectangle, output: Rectangle = null) => {
145
145
  const result = output || new Rectangle();
146
146
  if (intersects(a, b)) {
147
147
  result.x = Math.max(a.x, b.x);
@@ -162,7 +162,7 @@ export const intersection = (a, b, output = null) => {
162
162
  * @param {number} tolerance - Optional tolerance value for intersection.
163
163
  * @returns {boolean} True if the rectangle intersects with the area, false otherwise.
164
164
  */
165
- export const intersectsRaw = (a, left, right, top, bottom, tolerance = 0) => {
165
+ export const intersectsRaw = (a: Rectangle, left: number, right: number, top: number, bottom: number, tolerance: number = 0) => {
166
166
  return !(
167
167
  left > a.right + tolerance ||
168
168
  right < a.left - tolerance ||
@@ -178,7 +178,7 @@ export const intersectsRaw = (a, left, right, top, bottom, tolerance = 0) => {
178
178
  * @param {Rectangle} output - Optional rectangle to store the result in.
179
179
  * @returns {Rectangle} The union of the rectangles.
180
180
  */
181
- export const union = (a, b, output = null) => {
181
+ export const union = (a: Rectangle, b: Rectangle, output: Rectangle = null) => {
182
182
  const result = output || new Rectangle();
183
183
  return result.setTo(
184
184
  Math.min(a.x, b.x),
@@ -194,7 +194,7 @@ export const union = (a, b, output = null) => {
194
194
  * @param {Rectangle} output - Optional rectangle to store the result in.
195
195
  * @returns {Rectangle} The AABB of the points.
196
196
  */
197
- export const aabb = (points, output = null) => {
197
+ export const aabb = (points: Point[], output: Rectangle = null) => {
198
198
  const result = output || new Rectangle();
199
199
  let xMax = Number.NEGATIVE_INFINITY;
200
200
  let xMin = Number.POSITIVE_INFINITY;
@@ -6,7 +6,7 @@ import { RoundedRectangle } from '../rounded_rectangle.js';
6
6
  * @param {RoundedRectangle} output - Optional rounded rectangle to store the result in.
7
7
  * @returns {RoundedRectangle} The cloned rounded rectangle.
8
8
  */
9
- export const clone = (input, output = null) => {
9
+ export const clone = (input: RoundedRectangle, output: RoundedRectangle = null) => {
10
10
  const result = output || new RoundedRectangle();
11
11
  result.x = input.x;
12
12
  result.y = input.y;
@@ -2,31 +2,39 @@ export const DEG_TO_RAD = Math.PI / 180;
2
2
  export const RAD_TO_DEG = 180 / Math.PI;
3
3
  export const PI_2 = Math.PI * 2;
4
4
 
5
- /**
6
- * Converts a hexadecimal color value to RGB components.
7
- * @param {number} hex - The hexadecimal color value.
8
- * @returns {number[]} An array containing the RGB components [r, g, b].
9
- */
10
- export const hex2rgb = (hex) => {
5
+ export interface ColorTarget {
6
+ r?: number;
7
+ g?: number;
8
+ b?: number;
9
+ a?: number;
10
+ rgba?: string;
11
+ color?: number;
12
+ color32?: number;
13
+ }
14
+
15
+ export interface ColorComponents {
16
+ alpha: number;
17
+ red: number;
18
+ green: number;
19
+ blue: number;
20
+ a: number;
21
+ r: number;
22
+ g: number;
23
+ b: number;
24
+ }
25
+
26
+ /** Converts a hexadecimal color value to RGB components. */
27
+ export const hex2rgb = (hex: number): [number, number, number] => {
11
28
  return [((hex >> 16) & 0xff) / 255, ((hex >> 8) & 0xff) / 255, (hex & 0xff) / 255];
12
29
  };
13
30
 
14
- /**
15
- * Converts RGB components to a hexadecimal color value.
16
- * @param {number} rgb - The RGB components array [r, g, b].
17
- * @returns {number} The hexadecimal color value.
18
- */
19
- export const rgb2hex = (rgb) => {
31
+ /** Converts RGB components to a hexadecimal color value. */
32
+ export const rgb2hex = (rgb: number[]): number => {
20
33
  return ((rgb[0] * 255) << 16) + ((rgb[1] * 255) << 8) + rgb[2] * 255;
21
34
  };
22
35
 
23
- /**
24
- * Gets the next power of two greater than or equal to a value.
25
- * @param {number} value - The input value.
26
- * @returns {number} The next power of two.
27
- */
28
- export const getNextPowerOfTwo = (value) => {
29
- // see: https://en.wikipedia.org/wiki/Power_of_two#Fast_algorithm_to_check_if_a_positive_number_is_a_power_of_two
36
+ /** Gets the next power of two greater than or equal to a value. */
37
+ export const getNextPowerOfTwo = (value: number): number => {
30
38
  if (value > 0 && (value & (value - 1)) === 0) {
31
39
  return value;
32
40
  }
@@ -37,52 +45,28 @@ export const getNextPowerOfTwo = (value) => {
37
45
  return result;
38
46
  };
39
47
 
40
- /**
41
- * Checks if both width and height are powers of two.
42
- * @param {number} width - The width to check.
43
- * @param {number} height - The height to check.
44
- * @returns {boolean} True if both width and height are powers of two, false otherwise.
45
- */
46
- export const isPowerOfTwo = (width, height) => {
48
+ /** Checks if both width and height are powers of two. */
49
+ export const isPowerOfTwo = (width: number, height: number): boolean => {
47
50
  return width > 0 && (width & (width - 1)) === 0 && height > 0 && (height & (height - 1)) === 0;
48
51
  };
49
52
 
50
- /**
51
- * Converts degrees to radians.
52
- * @param {number} degrees - The angle in degrees.
53
- * @returns {number} The angle in radians.
54
- */
55
- export const degToRad = (degrees) => {
53
+ /** Converts degrees to radians. */
54
+ export const degToRad = (degrees: number): number => {
56
55
  return degrees * DEG_TO_RAD;
57
56
  };
58
57
 
59
- /**
60
- * Converts radians to degrees.
61
- * @param {number} radians - The angle in radians.
62
- * @returns {number} The angle in degrees.
63
- */
64
- export const radToDeg = (radians) => {
58
+ /** Converts radians to degrees. */
59
+ export const radToDeg = (radians: number): number => {
65
60
  return radians * RAD_TO_DEG;
66
61
  };
67
62
 
68
- /**
69
- * Gets a random integer between min and max (inclusive).
70
- * @param {number} min - The minimum value.
71
- * @param {number} max - The maximum value.
72
- * @returns {number} A random integer between min and max.
73
- */
74
- export const between = (min, max) => {
63
+ /** Gets a random integer between min and max (inclusive). */
64
+ export const between = (min: number, max: number): number => {
75
65
  return Math.floor(Math.random() * (max - min + 1) + min);
76
66
  };
77
67
 
78
- /**
79
- * Snaps a value to the nearest multiple of gap, starting from start.
80
- * @param {number} input - The value to snap.
81
- * @param {number} gap - The gap size to snap to.
82
- * @param {number} start - The starting offset for snapping.
83
- * @returns {number} The snapped value.
84
- */
85
- export const snapToCeil = (input, gap = 0, start = 0) => {
68
+ /** Snaps a value to the nearest multiple of gap, starting from start. */
69
+ export const snapToCeil = (input: number, gap: number = 0, start: number = 0): number => {
86
70
  if (gap === 0) {
87
71
  return input;
88
72
  }
@@ -91,14 +75,8 @@ export const snapToCeil = (input, gap = 0, start = 0) => {
91
75
  return start + input;
92
76
  };
93
77
 
94
- /**
95
- * Wraps a value within a range.
96
- * @param {number} value - The value to wrap.
97
- * @param {number} min - The minimum value of the range.
98
- * @param {number} max - The maximum value of the range.
99
- * @returns {number} The wrapped value.
100
- */
101
- export const wrap = (value, min, max) => {
78
+ /** Wraps a value within a range. */
79
+ export const wrap = (value: number, min: number, max: number): number => {
102
80
  const range = max - min;
103
81
  if (range <= 0) {
104
82
  return 0;
@@ -110,34 +88,18 @@ export const wrap = (value, min, max) => {
110
88
  return result + min;
111
89
  };
112
90
 
113
- /**
114
- * Performs linear interpolation between two values.
115
- * @param {number} p0 - The first point.
116
- * @param {number} p1 - The second point.
117
- * @param {number} t - The interpolation factor (0 to 1).
118
- * @returns {number} The interpolated value.
119
- */
120
- export const linear = (p0, p1, t) => {
91
+ /** Performs linear interpolation between two values. */
92
+ export const linear = (p0: number, p1: number, t: number): number => {
121
93
  return (p1 - p0) * t + p0;
122
94
  };
123
95
 
124
- /**
125
- * Calculates the absolute difference between two numbers.
126
- * @param {number} a - The first number.
127
- * @param {number} b - The second number.
128
- * @returns {number} The absolute difference between a and b.
129
- */
130
- export const difference = (a, b) => {
96
+ /** Calculates the absolute difference between two numbers. */
97
+ export const difference = (a: number, b: number): number => {
131
98
  return Math.abs(a - b);
132
99
  };
133
100
 
134
- /**
135
- * Performs linear interpolation on an array of values.
136
- * @param {number[]} v - The array of values.
137
- * @param {number} k - The interpolation factor (0 to 1).
138
- * @returns {number} The interpolated value.
139
- */
140
- export const linearInterpolation = (v, k) => {
101
+ /** Performs linear interpolation on an array of values. */
102
+ export const linearInterpolation = (v: number[], k: number): number => {
141
103
  const m = v.length - 1;
142
104
  const f = m * k;
143
105
  const i = Math.floor(f);
@@ -150,62 +112,31 @@ export const linearInterpolation = (v, k) => {
150
112
  return linear(v[i], v[i + 1 > m ? m : i + 1], f - i);
151
113
  };
152
114
 
153
- /**
154
- * Calculates the distance between two points.
155
- * @param {number} x1 - The x-coordinate of the first point.
156
- * @param {number} y1 - The y-coordinate of the first point.
157
- * @param {number} x2 - The x-coordinate of the second point.
158
- * @param {number} y2 - The y-coordinate of the second point.
159
- * @returns {number} The distance between the two points.
160
- */
161
- export const distance = (x1, y1, x2, y2) => {
115
+ /** Calculates the distance between two points. */
116
+ export const distance = (x1: number, y1: number, x2: number, y2: number): number => {
162
117
  const dx = x1 - x2;
163
118
  const dy = y1 - y2;
164
119
  return Math.sqrt(dx * dx + dy * dy);
165
120
  };
166
121
 
167
- /**
168
- * Checks if two numbers are within a tolerance of each other.
169
- * @param {number} a - The first number.
170
- * @param {number} b - The second number.
171
- * @param {number} tolerance - The tolerance value.
172
- * @returns {boolean} True if the numbers are within tolerance, false otherwise.
173
- */
174
- export const within = (a, b, tolerance) => {
122
+ /** Checks if two numbers are within a tolerance of each other. */
123
+ export const within = (a: number, b: number, tolerance: number): boolean => {
175
124
  return Math.abs(a - b) <= tolerance;
176
125
  };
177
126
 
178
- /**
179
- * Creates a 32-bit color value from alpha, red, green, and blue components.
180
- * @param {number} a - The alpha component (0-255).
181
- * @param {number} r - The red component (0-255).
182
- * @param {number} g - The green component (0-255).
183
- * @param {number} b - The blue component (0-255).
184
- * @returns {number} The 32-bit color value.
185
- */
186
- export const getColor32 = (a, r, g, b) => {
127
+ /** Creates a 32-bit color value from alpha, red, green, and blue components. */
128
+ export const getColor32 = (a: number, r: number, g: number, b: number): number => {
187
129
  return (a << 24) | (r << 16) | (g << 8) | b;
188
130
  };
189
131
 
190
- /**
191
- * Creates a 24-bit color value from red, green, and blue components.
192
- * @param {number} r - The red component (0-255).
193
- * @param {number} g - The green component (0-255).
194
- * @param {number} b - The blue component (0-255).
195
- * @returns {number} The 24-bit color value.
196
- */
197
- export const getColor = (r, g, b) => {
132
+ /** Creates a 24-bit color value from red, green, and blue components. */
133
+ export const getColor = (r: number, g: number, b: number): number => {
198
134
  return (r << 16) | (g << 8) | b;
199
135
  };
200
136
 
201
- /**
202
- * Converts a hex color string to RGB components.
203
- * @param {string} value - The hex color string (e.g. "#FF0000").
204
- * @param {{r?: number, g?: number, b?: number}} out - The object to store the result in.
205
- */
206
- export const hexToColor = (value, out) => {
207
- // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
208
- value = value.replace(/^(?:#|0x)?([a-f\d])([a-f\d])([a-f\d])$/i, (m, r, g, b) => r + r + g + g + b + b);
137
+ /** Converts a hex color string to RGB components. */
138
+ export const hexToColor = (value: string, out: ColorTarget): void => {
139
+ value = value.replace(/^(?:#|0x)?([a-f\d])([a-f\d])([a-f\d])$/i, (_m, r, g, b) => r + r + g + g + b + b);
209
140
  const result = /^(?:#|0x)?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(value);
210
141
  if (result) {
211
142
  out.r = Number.parseInt(result[1], 16);
@@ -214,12 +145,8 @@ export const hexToColor = (value, out) => {
214
145
  }
215
146
  };
216
147
 
217
- /**
218
- * Converts a web color string (e.g. "rgb(255, 0, 0)") to RGB components with alpha.
219
- * @param {string} value - The web color string (e.g. "rgba(255, 0, 0, 0.5)").
220
- * @param {{r?: number, g?: number, b?: number, a?: number}} out - The object to store the result in.
221
- */
222
- export const webToColor = (value, out) => {
148
+ /** Converts a web color string (e.g. "rgb(255, 0, 0)") to RGB components with alpha. */
149
+ export const webToColor = (value: string, out: ColorTarget): void => {
223
150
  const result = /^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d+(?:\.\d+)?))?\s*\)$/.exec(value);
224
151
  if (result) {
225
152
  out.r = Number.parseInt(result[1], 10);
@@ -229,14 +156,9 @@ export const webToColor = (value, out) => {
229
156
  }
230
157
  };
231
158
 
232
- /**
233
- * Extracts RGB components from a 32-bit color value.
234
- * @param {number} color - The 32-bit color value.
235
- * @returns {{ alpha: number, red: number, green: number, blue: number, a: number, r: number, g: number, b: number}} An object containing the color components.
236
- */
237
- export const getRGB = (color) => {
159
+ /** Extracts RGB components from a 32-bit color value. */
160
+ export const getRGB = (color: number): ColorComponents => {
238
161
  if (color > 16777215) {
239
- // The color value has an alpha component
240
162
  return {
241
163
  alpha: color >>> 24,
242
164
  red: (color >> 16) & 0xff,
@@ -260,32 +182,24 @@ export const getRGB = (color) => {
260
182
  };
261
183
  };
262
184
 
263
- /**
264
- * Converts a color value (string or number) to an object with various color formats.
265
- * @param {string|number} value - The color value (e.g. "#FF0000" or 0xFF0000).
266
- * @param {{a?: number, r?: number, g?: number, b?: number, rgba?: string, color?: number, color32?: number}} out - The object to store the result in.
267
- * @returns {{a?: number, r?: number, g?: number, b?: number, rgba?: string, color?: number, color32?: number}} The updated out object.
268
- */
269
- export const valueToColor = (value, out) => {
185
+ /** Converts a color value (string or number) to an object with various color formats. */
186
+ export const valueToColor = (value: string | number, out: ColorTarget): ColorTarget => {
270
187
  if (typeof value === 'string') {
271
188
  if (value.indexOf('rgb') === 0) {
272
189
  webToColor(value, out);
273
190
  } else {
274
- // `hexToColor` does not support alpha; match `createColor`.
275
191
  out.a = 1;
276
192
  hexToColor(value, out);
277
193
  }
278
194
  } else if (typeof value === 'number') {
279
- // `getRGB` does not take optional object to modify;
280
- // alpha is also adjusted to match `createColor`.
281
195
  const tempColor = getRGB(value);
282
196
  out.r = tempColor.r;
283
197
  out.g = tempColor.g;
284
198
  out.b = tempColor.b;
285
199
  out.a = tempColor.a / 255;
286
200
  }
287
- out.rgba = `rgba(${out.r.toString()},${out.g.toString()},${out.b.toString()},${out.a.toString()})`;
288
- out.color = getColor(out.r, out.g, out.b);
289
- out.color32 = getColor32(out.a * 255, out.r, out.g, out.b);
201
+ out.rgba = `rgba(${out.r!.toString()},${out.g!.toString()},${out.b!.toString()},${out.a!.toString()})`;
202
+ out.color = getColor(out.r!, out.g!, out.b!);
203
+ out.color32 = getColor32(out.a! * 255, out.r!, out.g!, out.b!);
290
204
  return out;
291
205
  };