sfml.js 1.0.0 → 1.2.1

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 (313) hide show
  1. package/README.ja.md +10 -9
  2. package/README.ko.md +10 -9
  3. package/README.md +10 -9
  4. package/README.zh-CN.md +10 -9
  5. package/binding.gyp +23 -16
  6. package/dist/audio/effect-processor.js +9 -3
  7. package/dist/audio/input-sound-file.js +41 -15
  8. package/dist/audio/listener.js +33 -11
  9. package/dist/audio/music.js +41 -18
  10. package/dist/audio/output-sound-file.js +4 -2
  11. package/dist/audio/playback-device.js +11 -3
  12. package/dist/audio/sound-buffer-recorder.js +8 -5
  13. package/dist/audio/sound-buffer.js +40 -17
  14. package/dist/audio/sound-file-factory.js +21 -9
  15. package/dist/audio/sound-file-reader.js +21 -7
  16. package/dist/audio/sound-recorder.js +36 -15
  17. package/dist/audio/sound-source.js +117 -40
  18. package/dist/audio/sound-stream.js +14 -5
  19. package/dist/audio/sound.js +9 -4
  20. package/dist/audio/value.js +42 -16
  21. package/dist/graphics/blend-mode.js +2 -1
  22. package/dist/graphics/boolean-vector.d.ts +1 -2
  23. package/dist/graphics/boolean-vector.js +19 -9
  24. package/dist/graphics/color.js +2 -1
  25. package/dist/graphics/convex-shape.js +7 -3
  26. package/dist/graphics/font.js +52 -23
  27. package/dist/graphics/glsl-matrix.js +8 -3
  28. package/dist/graphics/glsl.js +47 -16
  29. package/dist/graphics/glyph.js +27 -10
  30. package/dist/graphics/image.js +30 -14
  31. package/dist/graphics/rect.js +15 -8
  32. package/dist/graphics/render-states.js +18 -9
  33. package/dist/graphics/render-target.js +49 -23
  34. package/dist/graphics/render-texture.js +24 -12
  35. package/dist/graphics/render-window.js +6 -3
  36. package/dist/graphics/shader.js +67 -32
  37. package/dist/graphics/shape.js +25 -13
  38. package/dist/graphics/sprite.js +19 -9
  39. package/dist/graphics/stencil-mode.js +10 -6
  40. package/dist/graphics/swap.js +2 -1
  41. package/dist/graphics/text.js +123 -48
  42. package/dist/graphics/texture.js +48 -24
  43. package/dist/graphics/transform.js +29 -13
  44. package/dist/graphics/transformable.js +2 -1
  45. package/dist/graphics/vertex-array.js +40 -18
  46. package/dist/graphics/vertex-buffer.js +39 -19
  47. package/dist/graphics/vertex.js +6 -3
  48. package/dist/graphics/view.js +30 -14
  49. package/dist/index.d.ts +4 -4
  50. package/dist/internal/audio-codec-registry.js +12 -6
  51. package/dist/internal/audio-input-stream.js +2 -1
  52. package/dist/internal/audio-music-pump.js +58 -24
  53. package/dist/internal/audio-recorder-session.js +17 -7
  54. package/dist/internal/audio-worker-session.js +28 -10
  55. package/dist/internal/audio-worker.js +40 -21
  56. package/dist/internal/glsl-value.d.ts +3 -1
  57. package/dist/internal/glsl-value.js +18 -8
  58. package/dist/internal/graphics-state.js +29 -15
  59. package/dist/internal/input-stream.d.ts +3 -1
  60. package/dist/internal/input-stream.js +16 -7
  61. package/dist/internal/numeric-properties.js +2 -1
  62. package/dist/internal/render-states.js +2 -1
  63. package/dist/internal/scalar.js +22 -13
  64. package/dist/internal/shaped-glyph.d.ts +3 -1
  65. package/dist/internal/shaped-glyph.js +12 -4
  66. package/dist/internal/struct-view.d.ts +3 -1
  67. package/dist/internal/struct-view.js +3 -1
  68. package/dist/internal/transformable.js +2 -1
  69. package/dist/network/common.js +23 -11
  70. package/dist/network/dns.js +25 -17
  71. package/dist/network/ftp.js +43 -18
  72. package/dist/network/http.js +126 -56
  73. package/dist/network/ip-address.js +50 -25
  74. package/dist/network/packet.js +63 -25
  75. package/dist/network/sftp.js +175 -74
  76. package/dist/network/socket-selector.js +28 -14
  77. package/dist/network/socket.js +71 -30
  78. package/dist/network/tcp-listener.js +42 -19
  79. package/dist/network/tcp-socket.js +111 -53
  80. package/dist/network/tls-material.js +2 -1
  81. package/dist/network/udp-socket.js +68 -33
  82. package/dist/system/angle.js +2 -1
  83. package/dist/system/clock.js +4 -2
  84. package/dist/system/err.js +5 -2
  85. package/dist/system/file-input-stream.js +8 -4
  86. package/dist/system/input-stream.js +6 -3
  87. package/dist/system/operators.d.ts +1 -1
  88. package/dist/system/operators.js +90 -50
  89. package/dist/system/sleep.js +4 -2
  90. package/dist/system/time.js +12 -6
  91. package/dist/system/vector2.js +6 -7
  92. package/dist/system/vector3.js +11 -6
  93. package/dist/window/clipboard.js +2 -1
  94. package/dist/window/context.js +10 -5
  95. package/dist/window/cursor.js +2 -1
  96. package/dist/window/event.js +9 -5
  97. package/dist/window/mouse.js +4 -2
  98. package/dist/window/video-mode.js +2 -1
  99. package/dist/window/window.js +19 -12
  100. package/native/addon.cc +25 -12
  101. package/native/audio-binding.cc +266 -126
  102. package/native/audio-codec-binding.cc +147 -77
  103. package/native/audio-device-binding.cc +76 -49
  104. package/native/audio-file-binding.cc +116 -67
  105. package/native/audio-recorder-binding.cc +147 -98
  106. package/native/audio-recorder.h +1 -1
  107. package/native/audio-state.h +53 -30
  108. package/native/audio-stream-binding.cc +148 -94
  109. package/native/audio-stream.h +5 -4
  110. package/native/audio-worker-binding.cc +163 -81
  111. package/native/audio-worker.h +35 -19
  112. package/native/batch-drawable.cc +29 -16
  113. package/native/batch-drawable.h +11 -8
  114. package/native/context-binding.cc +40 -27
  115. package/native/context-settings.h +15 -8
  116. package/native/deferred-delete.cc +9 -6
  117. package/native/deferred-delete.h +7 -8
  118. package/native/error-stream-binding.cc +42 -28
  119. package/native/font-binding.cc +89 -48
  120. package/native/graphics-binding.cc +122 -72
  121. package/native/graphics-state.h +50 -36
  122. package/native/image-binding.cc +38 -24
  123. package/native/image-state.h +26 -18
  124. package/native/input-binding.cc +42 -27
  125. package/native/render-window-binding.cc +38 -23
  126. package/native/shader-binding.cc +115 -50
  127. package/native/shape-binding.cc +94 -49
  128. package/native/shape-state.h +18 -9
  129. package/native/shaped-glyph-storage.h +9 -5
  130. package/native/stream-binding.cc +143 -117
  131. package/native/system-binding.cc +17 -12
  132. package/native/text-binding.cc +68 -35
  133. package/native/text-state.h +25 -18
  134. package/native/texture-binding.cc +42 -33
  135. package/native/texture-resource.h +20 -12
  136. package/native/time-value.h +3 -1
  137. package/native/transformable-binding.cc +12 -6
  138. package/native/transformable-state.h +6 -6
  139. package/native/value-binding.h +46 -28
  140. package/native/value-layout.h +10 -10
  141. package/native/values-binding.cc +29 -23
  142. package/native/vertex-binding.cc +18 -12
  143. package/native/vertex-buffer-binding.cc +38 -24
  144. package/native/vertex-storage.h +2 -2
  145. package/native/view-data.h +4 -3
  146. package/native/window-binding.cc +75 -45
  147. package/native/window-event.h +20 -11
  148. package/native/window-owner.h +15 -12
  149. package/package.json +44 -51
  150. package/src/audio/effect-processor.ts +9 -3
  151. package/src/audio/input-sound-file.ts +108 -36
  152. package/src/audio/listener.ts +39 -13
  153. package/src/audio/music.ts +112 -47
  154. package/src/audio/output-sound-file.ts +40 -11
  155. package/src/audio/playback-device.ts +23 -8
  156. package/src/audio/sound-buffer-recorder.ts +35 -13
  157. package/src/audio/sound-buffer.ts +166 -58
  158. package/src/audio/sound-file-factory.ts +127 -49
  159. package/src/audio/sound-file-reader.ts +49 -15
  160. package/src/audio/sound-recorder.ts +100 -34
  161. package/src/audio/sound-source.ts +142 -45
  162. package/src/audio/sound-stream.ts +15 -5
  163. package/src/audio/sound.ts +12 -4
  164. package/src/audio/value.ts +89 -26
  165. package/src/graphics/blend-mode.ts +3 -1
  166. package/src/graphics/boolean-vector.ts +56 -26
  167. package/src/graphics/color.ts +3 -1
  168. package/src/graphics/convex-shape.ts +10 -3
  169. package/src/graphics/font.ts +171 -50
  170. package/src/graphics/glsl-matrix.ts +9 -3
  171. package/src/graphics/glsl.ts +81 -35
  172. package/src/graphics/glyph.ts +67 -26
  173. package/src/graphics/image.ts +119 -45
  174. package/src/graphics/rect.ts +56 -24
  175. package/src/graphics/render-states.ts +31 -14
  176. package/src/graphics/render-target.ts +197 -81
  177. package/src/graphics/render-texture.ts +36 -12
  178. package/src/graphics/render-window.ts +9 -3
  179. package/src/graphics/shader.ts +186 -61
  180. package/src/graphics/shape.ts +93 -35
  181. package/src/graphics/sprite.ts +64 -25
  182. package/src/graphics/stencil-mode.ts +12 -6
  183. package/src/graphics/swap.ts +3 -2
  184. package/src/graphics/text.ts +229 -74
  185. package/src/graphics/texture.ts +180 -61
  186. package/src/graphics/transform.ts +132 -47
  187. package/src/graphics/transformable.ts +3 -1
  188. package/src/graphics/vertex-array.ts +87 -35
  189. package/src/graphics/vertex-buffer.ts +97 -33
  190. package/src/graphics/vertex.ts +9 -3
  191. package/src/graphics/view.ts +59 -21
  192. package/src/index.ts +101 -23
  193. package/src/internal/audio-codec-registry.ts +18 -6
  194. package/src/internal/audio-input-stream.ts +6 -2
  195. package/src/internal/audio-music-pump.ts +116 -41
  196. package/src/internal/audio-native.ts +249 -96
  197. package/src/internal/audio-recorder-session.ts +68 -24
  198. package/src/internal/audio-worker-session.ts +65 -21
  199. package/src/internal/audio-worker.ts +85 -41
  200. package/src/internal/glsl-value.ts +26 -11
  201. package/src/internal/graphics-state.ts +57 -20
  202. package/src/internal/input-stream.ts +23 -10
  203. package/src/internal/native.ts +252 -99
  204. package/src/internal/numeric-properties.ts +2 -1
  205. package/src/internal/render-states.ts +3 -1
  206. package/src/internal/scalar.ts +33 -14
  207. package/src/internal/shaped-glyph.ts +25 -12
  208. package/src/internal/struct-view.ts +40 -13
  209. package/src/internal/transformable.ts +3 -1
  210. package/src/network/common.ts +35 -11
  211. package/src/network/dns.ts +95 -38
  212. package/src/network/ftp.ts +129 -47
  213. package/src/network/http.ts +232 -77
  214. package/src/network/ip-address.ts +118 -48
  215. package/src/network/packet.ts +161 -54
  216. package/src/network/sftp.ts +498 -168
  217. package/src/network/socket-selector.ts +66 -26
  218. package/src/network/socket.ts +133 -46
  219. package/src/network/tcp-listener.ts +78 -29
  220. package/src/network/tcp-socket.ts +240 -95
  221. package/src/network/tls-material.ts +6 -2
  222. package/src/network/udp-socket.ts +147 -53
  223. package/src/system/angle.ts +3 -1
  224. package/src/system/clock.ts +12 -4
  225. package/src/system/err.ts +5 -2
  226. package/src/system/file-input-stream.ts +12 -4
  227. package/src/system/input-stream.ts +9 -3
  228. package/src/system/operators.ts +290 -115
  229. package/src/system/sleep.ts +6 -2
  230. package/src/system/time.ts +18 -6
  231. package/src/system/timeout-with-predicate.ts +19 -8
  232. package/src/system/vector2.ts +101 -49
  233. package/src/system/vector3.ts +85 -36
  234. package/src/window/clipboard.ts +3 -1
  235. package/src/window/context.ts +15 -5
  236. package/src/window/cursor.ts +3 -1
  237. package/src/window/event.ts +26 -12
  238. package/src/window/mouse.ts +6 -2
  239. package/src/window/video-mode.ts +3 -1
  240. package/src/window/window.ts +119 -37
  241. package/test/native/audio-probes.cc +74 -36
  242. package/test/native/deferred-delete-probes.cc +17 -11
  243. package/test/native/drawable-probes.cc +70 -36
  244. package/test/native/exception-probes.cc +14 -9
  245. package/test/native/image-probes.cc +20 -10
  246. package/test/native/matrix-probes.cc +8 -4
  247. package/test/native/network-oracle.cc +17 -11
  248. package/test/native/render-texture-probes.cc +33 -24
  249. package/test/native/shader-probes.cc +9 -9
  250. package/test/native/shape-probes.cc +37 -23
  251. package/test/native/sprite-probes.cc +41 -25
  252. package/test/native/system-probes.cc +58 -35
  253. package/test/native/text-probes.cc +77 -44
  254. package/test/native/texture-probes.cc +43 -26
  255. package/test/native/time-probes.cc +18 -12
  256. package/test/native/transform-probes.cc +15 -10
  257. package/test/native/transformable-probes.cc +23 -17
  258. package/test/native/value-oracle.h +9 -4
  259. package/test/native/value-probes.cc +31 -23
  260. package/test/native/vertex-array-probes.cc +22 -14
  261. package/test/native/vertex-buffer-probes.cc +28 -17
  262. package/test/native/view-probes.cc +29 -17
  263. package/test/native/window-probes.cc +66 -33
  264. package/tools/ensure-sfml.cjs +9 -0
  265. package/tools/generate-network-constants.cjs +11 -6
  266. package/tools/generate-window-constants.cjs +31 -12
  267. package/docs/README.ja.md +0 -30
  268. package/docs/README.ko.md +0 -30
  269. package/docs/README.md +0 -30
  270. package/docs/README.zh-CN.md +0 -30
  271. package/docs/api.ja.md +0 -84
  272. package/docs/api.ko.md +0 -84
  273. package/docs/api.md +0 -81
  274. package/docs/api.zh-CN.md +0 -81
  275. package/docs/audio.ja.md +0 -249
  276. package/docs/audio.ko.md +0 -251
  277. package/docs/audio.md +0 -252
  278. package/docs/audio.zh-CN.md +0 -252
  279. package/docs/concepts.ja.md +0 -130
  280. package/docs/concepts.ko.md +0 -130
  281. package/docs/concepts.md +0 -131
  282. package/docs/concepts.zh-CN.md +0 -131
  283. package/docs/development.ja.md +0 -144
  284. package/docs/development.ko.md +0 -144
  285. package/docs/development.md +0 -146
  286. package/docs/development.zh-CN.md +0 -146
  287. package/docs/getting-started.ja.md +0 -154
  288. package/docs/getting-started.ko.md +0 -154
  289. package/docs/getting-started.md +0 -156
  290. package/docs/getting-started.zh-CN.md +0 -156
  291. package/docs/graphics.ja.md +0 -256
  292. package/docs/graphics.ko.md +0 -254
  293. package/docs/graphics.md +0 -255
  294. package/docs/graphics.zh-CN.md +0 -257
  295. package/docs/network.ja.md +0 -214
  296. package/docs/network.ko.md +0 -216
  297. package/docs/network.md +0 -218
  298. package/docs/network.zh-CN.md +0 -218
  299. package/docs/system.ja.md +0 -169
  300. package/docs/system.ko.md +0 -171
  301. package/docs/system.md +0 -173
  302. package/docs/system.zh-CN.md +0 -173
  303. package/docs/window.ja.md +0 -138
  304. package/docs/window.ko.md +0 -140
  305. package/docs/window.md +0 -141
  306. package/docs/window.zh-CN.md +0 -141
  307. package/native/exception-boundary.h +0 -97
  308. package/native/numeric-fields.h +0 -96
  309. package/native/shared-handle.h +0 -107
  310. package/test/tsconfig.json +0 -8
  311. package/tools/configure-lsp.cjs +0 -23
  312. package/tools/lib_downloader.cjs +0 -92
  313. package/tools/lib_downloader_urls.cjs +0 -23
@@ -1,5 +1,10 @@
1
1
  import { Angle, positiveRemainder, radians } from './angle';
2
- import { Time, checkedMicroseconds, scaleTime, remainderTime } from './time';
2
+ import {
3
+ Time,
4
+ checkedMicroseconds,
5
+ scaleTime,
6
+ remainderTime,
7
+ } from './time';
3
8
  import { Vector2, Vector2i, Vector2u, Vector2f } from './vector2';
4
9
  import { Vector3, Vector3i, Vector3u, Vector3f } from './vector3';
5
10
  import { Color } from '../graphics/color';
@@ -12,45 +17,87 @@ import { IpAddress } from '../network/ip-address';
12
17
  import { Bvec2, Bvec3, BooleanVector } from '../graphics/boolean-vector';
13
18
  import { glslStorage } from '../internal/glsl-value';
14
19
  import {
15
- type ScalarType, type Scalar, type ScalarArray, type NumberScalar,
16
- toScalar, scalarProduct, isBigIntScalar, convertScalar,
20
+ type ScalarType,
21
+ type Scalar,
22
+ type ScalarArray,
23
+ type NumberScalar,
24
+ toScalar,
25
+ scalarProduct,
26
+ isBigIntScalar,
27
+ convertScalar,
17
28
  } from '../internal/scalar';
18
29
  import {
19
- angleStorage, timeStorage, vector2Storage, vector3Storage, colorStorage,
20
- rectStorage, transformStorage,
30
+ angleStorage,
31
+ timeStorage,
32
+ vector2Storage,
33
+ vector3Storage,
34
+ colorStorage,
35
+ rectStorage,
36
+ transformStorage,
21
37
  type ReadonlyValue as R,
22
38
  } from '../internal/value-storage';
23
39
 
24
- type Intersect<U> = (U extends unknown ? (value: U) => void : never) extends
25
- ((value: infer I) => void) ? I : never;
26
- type VectorAddition = Intersect<{ [T in ScalarType]: {
27
- (left: R<Vector2<T>>, right: R<Vector2<T>>): Vector2<T>;
28
- (left: R<Vector3<T>>, right: R<Vector3<T>>): Vector3<T>;
29
- } }[ScalarType]>;
30
- type VectorAdditionAssign = Intersect<{ [T in ScalarType]: {
31
- (left: Vector2<T>, right: R<Vector2<T>>): Vector2<T>;
32
- (left: Vector3<T>, right: R<Vector3<T>>): Vector3<T>;
33
- } }[ScalarType]>;
34
- type VectorNegation = Intersect<{ [T in ScalarType]: {
35
- (value: R<Vector2<T>>): Vector2<T>;
36
- (value: R<Vector3<T>>): Vector3<T>;
37
- } }[ScalarType]>;
38
- type VectorScale = Intersect<{ [T in ScalarType]: {
39
- (left: R<Vector2<T>>, right: Scalar<T>): Vector2<T>;
40
- (left: R<Vector3<T>>, right: Scalar<T>): Vector3<T>;
41
- } }[ScalarType]>;
42
- type VectorScaleAssign = Intersect<{ [T in ScalarType]: {
43
- (left: Vector2<T>, right: Scalar<T>): Vector2<T>;
44
- (left: Vector3<T>, right: Scalar<T>): Vector3<T>;
45
- } }[ScalarType]>;
46
- type VectorLeftScale = Intersect<{ [T in ScalarType]: {
47
- (left: Scalar<T>, right: R<Vector2<T>>): Vector2<T>;
48
- (left: Scalar<T>, right: R<Vector3<T>>): Vector3<T>;
49
- } }[ScalarType]>;
50
- type VectorEquality = Intersect<{ [T in ScalarType]: {
51
- (left: R<Vector2<T>>, right: R<Vector2<T>>): boolean;
52
- (left: R<Vector3<T>>, right: R<Vector3<T>>): boolean;
53
- } }[ScalarType]>;
40
+ type Intersect<U> = (
41
+ U extends unknown ? (value: U) => void : never
42
+ ) extends (value: infer I) => void
43
+ ? I
44
+ : never;
45
+ type VectorAddition = Intersect<
46
+ {
47
+ [T in ScalarType]: {
48
+ (left: R<Vector2<T>>, right: R<Vector2<T>>): Vector2<T>;
49
+ (left: R<Vector3<T>>, right: R<Vector3<T>>): Vector3<T>;
50
+ };
51
+ }[ScalarType]
52
+ >;
53
+ type VectorAdditionAssign = Intersect<
54
+ {
55
+ [T in ScalarType]: {
56
+ (left: Vector2<T>, right: R<Vector2<T>>): Vector2<T>;
57
+ (left: Vector3<T>, right: R<Vector3<T>>): Vector3<T>;
58
+ };
59
+ }[ScalarType]
60
+ >;
61
+ type VectorNegation = Intersect<
62
+ {
63
+ [T in ScalarType]: {
64
+ (value: R<Vector2<T>>): Vector2<T>;
65
+ (value: R<Vector3<T>>): Vector3<T>;
66
+ };
67
+ }[ScalarType]
68
+ >;
69
+ type VectorScale = Intersect<
70
+ {
71
+ [T in ScalarType]: {
72
+ (left: R<Vector2<T>>, right: Scalar<T>): Vector2<T>;
73
+ (left: R<Vector3<T>>, right: Scalar<T>): Vector3<T>;
74
+ };
75
+ }[ScalarType]
76
+ >;
77
+ type VectorScaleAssign = Intersect<
78
+ {
79
+ [T in ScalarType]: {
80
+ (left: Vector2<T>, right: Scalar<T>): Vector2<T>;
81
+ (left: Vector3<T>, right: Scalar<T>): Vector3<T>;
82
+ };
83
+ }[ScalarType]
84
+ >;
85
+ type VectorLeftScale = Intersect<
86
+ {
87
+ [T in ScalarType]: {
88
+ (left: Scalar<T>, right: R<Vector2<T>>): Vector2<T>;
89
+ (left: Scalar<T>, right: R<Vector3<T>>): Vector3<T>;
90
+ };
91
+ }[ScalarType]
92
+ >;
93
+ type VectorEquality = Intersect<
94
+ {
95
+ [T in ScalarType]: {
96
+ (left: R<Vector2<T>>, right: R<Vector2<T>>): boolean;
97
+ (left: R<Vector3<T>>, right: R<Vector3<T>>): boolean;
98
+ };
99
+ }[ScalarType]
100
+ >;
54
101
 
55
102
  interface Addition extends VectorAddition {
56
103
  (left: R<Bvec2>, right: R<Bvec2>): Bvec2;
@@ -112,24 +159,48 @@ interface Equality extends VectorEquality {
112
159
  }
113
160
 
114
161
  type Value =
115
- | Time | Angle | Color | Vector2<ScalarType> | Vector3<ScalarType>
116
- | Bvec2 | Bvec3;
162
+ | Time
163
+ | Angle
164
+ | Color
165
+ | Vector2<ScalarType>
166
+ | Vector3<ScalarType>
167
+ | Bvec2
168
+ | Bvec3;
117
169
  type Input =
118
- | R<Time> | R<Angle> | R<Color>
119
- | R<Vector2<ScalarType>> | R<Vector3<ScalarType>> | R<Bvec2> | R<Bvec3>;
170
+ | R<Time>
171
+ | R<Angle>
172
+ | R<Color>
173
+ | R<Vector2<ScalarType>>
174
+ | R<Vector3<ScalarType>>
175
+ | R<Bvec2>
176
+ | R<Bvec3>;
120
177
 
121
178
  function storage(value: Input) {
122
- if (value instanceof BooleanVector) return value[glslStorage];
123
- if (value instanceof Color) return value[colorStorage];
124
- if (value instanceof Angle) return value[angleStorage];
125
- if (value instanceof Vector2) return value[vector2Storage];
126
- if (value instanceof Vector3) return value[vector3Storage];
179
+ if (value instanceof BooleanVector) {
180
+ return value[glslStorage];
181
+ }
182
+ if (value instanceof Color) {
183
+ return value[colorStorage];
184
+ }
185
+ if (value instanceof Angle) {
186
+ return value[angleStorage];
187
+ }
188
+ if (value instanceof Vector2) {
189
+ return value[vector2Storage];
190
+ }
191
+ if (value instanceof Vector3) {
192
+ return value[vector3Storage];
193
+ }
127
194
  throw new TypeError('Expected an Angle, Color, Vector2 or Vector3');
128
195
  }
129
196
 
130
197
  function scalarType(value: Input): ScalarType | 'bool' {
131
- if (value instanceof BooleanVector) return 'bool';
132
- if (value instanceof Angle) return 'f32';
198
+ if (value instanceof BooleanVector) {
199
+ return 'bool';
200
+ }
201
+ if (value instanceof Angle) {
202
+ return 'f32';
203
+ }
133
204
  if (value instanceof Vector2 || value instanceof Vector3) {
134
205
  return value.scalarType;
135
206
  }
@@ -149,26 +220,56 @@ function checkPair(left: Input, right: Input): void {
149
220
  }
150
221
  return;
151
222
  }
152
- if (storage(left).length !== storage(right).length ||
153
- scalarType(left) !== scalarType(right)) {
154
- throw new TypeError('Operands must have the same value and scalar type');
223
+ if (
224
+ storage(left).length !== storage(right).length ||
225
+ scalarType(left) !== scalarType(right)
226
+ ) {
227
+ throw new TypeError(
228
+ 'Operands must have the same value and scalar type',
229
+ );
155
230
  }
156
231
  }
157
232
 
158
233
  function copy(value: Input): Value {
159
- if (value instanceof Bvec2) return new Bvec2(value);
160
- if (value instanceof Bvec3) return new Bvec3(value);
161
- if (value instanceof Time) return new Time(value);
162
- if (value instanceof Color) return new Color(value);
163
- if (value instanceof Angle) return new Angle(value);
164
- if (value instanceof Vector2i) return new Vector2i(value);
165
- if (value instanceof Vector2u) return new Vector2u(value);
166
- if (value instanceof Vector2f) return new Vector2f(value);
167
- if (value instanceof Vector3i) return new Vector3i(value);
168
- if (value instanceof Vector3u) return new Vector3u(value);
169
- if (value instanceof Vector3f) return new Vector3f(value);
170
- if (value instanceof Vector2) return new Vector2(value);
171
- if (value instanceof Vector3) return new Vector3(value);
234
+ if (value instanceof Bvec2) {
235
+ return new Bvec2(value);
236
+ }
237
+ if (value instanceof Bvec3) {
238
+ return new Bvec3(value);
239
+ }
240
+ if (value instanceof Time) {
241
+ return new Time(value);
242
+ }
243
+ if (value instanceof Color) {
244
+ return new Color(value);
245
+ }
246
+ if (value instanceof Angle) {
247
+ return new Angle(value);
248
+ }
249
+ if (value instanceof Vector2i) {
250
+ return new Vector2i(value);
251
+ }
252
+ if (value instanceof Vector2u) {
253
+ return new Vector2u(value);
254
+ }
255
+ if (value instanceof Vector2f) {
256
+ return new Vector2f(value);
257
+ }
258
+ if (value instanceof Vector3i) {
259
+ return new Vector3i(value);
260
+ }
261
+ if (value instanceof Vector3u) {
262
+ return new Vector3u(value);
263
+ }
264
+ if (value instanceof Vector3f) {
265
+ return new Vector3f(value);
266
+ }
267
+ if (value instanceof Vector2) {
268
+ return new Vector2(value);
269
+ }
270
+ if (value instanceof Vector3) {
271
+ return new Vector3(value);
272
+ }
172
273
  throw new TypeError('Expected an Angle, Color, Vector2 or Vector3');
173
274
  }
174
275
 
@@ -179,23 +280,32 @@ function checkMutable(value: Value): void {
179
280
  }
180
281
 
181
282
  function combine(
182
- left: Value, right: Input, operation: 'add' | 'subtract',
283
+ left: Value,
284
+ right: Input,
285
+ operation: 'add' | 'subtract',
183
286
  ): Value {
184
287
  checkMutable(left);
185
288
  checkPair(left, right);
186
289
  if (left instanceof Time && right instanceof Time) {
187
- left[timeStorage] = checkedMicroseconds(operation === 'add'
188
- ? left.asMicroseconds() + right.asMicroseconds()
189
- : left.asMicroseconds() - right.asMicroseconds());
290
+ left[timeStorage] = checkedMicroseconds(
291
+ operation === 'add'
292
+ ? left.asMicroseconds() + right.asMicroseconds()
293
+ : left.asMicroseconds() - right.asMicroseconds(),
294
+ );
190
295
  return left;
191
296
  }
192
297
  const leftData = storage(left);
193
298
  const rightData = storage(right);
194
- if (leftData instanceof BigInt64Array || leftData instanceof BigUint64Array) {
299
+ if (
300
+ leftData instanceof BigInt64Array ||
301
+ leftData instanceof BigUint64Array
302
+ ) {
195
303
  const b = rightData as BigInt64Array | BigUint64Array;
196
304
  for (let index = 0; index < leftData.length; index++) {
197
- leftData[index] = operation === 'add'
198
- ? leftData[index] + b[index] : leftData[index] - b[index];
305
+ leftData[index] =
306
+ operation === 'add'
307
+ ? leftData[index] + b[index]
308
+ : leftData[index] - b[index];
199
309
  }
200
310
  return left;
201
311
  }
@@ -204,16 +314,20 @@ function combine(
204
314
  const isColor = left instanceof Color;
205
315
  const isBoolean = left instanceof BooleanVector;
206
316
  for (let index = 0; index < a.length; index++) {
207
- const result = operation === 'add'
208
- ? a[index] + b[index] : a[index] - b[index];
209
- a[index] = isColor ? Math.min(255, Math.max(0, result))
210
- : isBoolean ? Number(result !== 0) : result;
317
+ const result =
318
+ operation === 'add' ? a[index] + b[index] : a[index] - b[index];
319
+ a[index] = isColor
320
+ ? Math.min(255, Math.max(0, result))
321
+ : isBoolean
322
+ ? Number(result !== 0)
323
+ : result;
211
324
  }
212
325
  return left;
213
326
  }
214
327
 
215
328
  function modulate(
216
- left: Value, right: Input | number | bigint | boolean,
329
+ left: Value,
330
+ right: Input | number | bigint | boolean,
217
331
  ): Color {
218
332
  checkMutable(left);
219
333
  if (!(left instanceof Color) || !(right instanceof Color)) {
@@ -223,13 +337,14 @@ function modulate(
223
337
  const b = right[colorStorage];
224
338
  for (let index = 0; index < 4; index++) {
225
339
  // Uint8Array truncates the nonnegative quotient, matching SFML.
226
- a[index] = a[index] * b[index] / 255;
340
+ a[index] = (a[index] * b[index]) / 255;
227
341
  }
228
342
  return left;
229
343
  }
230
344
 
231
345
  function scale(
232
- left: Value, right: number | bigint | boolean,
346
+ left: Value,
347
+ right: number | bigint | boolean,
233
348
  operation: 'multiply' | 'divide',
234
349
  ): Value {
235
350
  checkMutable(left);
@@ -240,11 +355,15 @@ function scale(
240
355
  if (operation === 'divide' && !right) {
241
356
  throw new RangeError('Cannot divide by zero');
242
357
  }
243
- if (!right) left[glslStorage].fill(0);
358
+ if (!right) {
359
+ left[glslStorage].fill(0);
360
+ }
244
361
  return left;
245
362
  }
246
363
  if (left instanceof Time) {
247
- if (typeof right === 'boolean') throw new TypeError('Expected a scalar');
364
+ if (typeof right === 'boolean') {
365
+ throw new TypeError('Expected a scalar');
366
+ }
248
367
  left[timeStorage] = scaleTime(left, right, operation);
249
368
  return left;
250
369
  }
@@ -253,26 +372,33 @@ function scale(
253
372
  }
254
373
  const type = scalarType(left) as ScalarType;
255
374
  if (isBigIntScalar(type)) {
256
- if (typeof right !== 'bigint') throw new TypeError('Expected a bigint scalar');
375
+ if (typeof right !== 'bigint') {
376
+ throw new TypeError('Expected a bigint scalar');
377
+ }
257
378
  const scalar = convertScalar(type, right) as bigint;
258
379
  if (operation === 'divide' && scalar === 0n) {
259
380
  throw new RangeError('Cannot divide by zero');
260
381
  }
261
382
  const data = storage(left) as BigInt64Array | BigUint64Array;
262
383
  for (let i = 0; i < data.length; i++) {
263
- data[i] = operation === 'multiply' ? data[i] * scalar : data[i] / scalar;
384
+ data[i] =
385
+ operation === 'multiply' ? data[i] * scalar : data[i] / scalar;
264
386
  }
265
387
  return left;
266
388
  }
267
- if (typeof right !== 'number') throw new TypeError('Expected a scalar');
389
+ if (typeof right !== 'number') {
390
+ throw new TypeError('Expected a scalar');
391
+ }
268
392
  const scalar = toScalar(type, right);
269
393
  if (operation === 'divide' && scalar === 0) {
270
394
  throw new RangeError('Cannot divide by zero');
271
395
  }
272
396
  const a = storage(left) as ScalarArray<NumberScalar>;
273
397
  for (let index = 0; index < a.length; index++) {
274
- a[index] = operation === 'multiply'
275
- ? scalarProduct(type, a[index], scalar) : a[index] / scalar;
398
+ a[index] =
399
+ operation === 'multiply'
400
+ ? scalarProduct(type, a[index], scalar)
401
+ : a[index] / scalar;
276
402
  }
277
403
  return left;
278
404
  }
@@ -338,7 +464,9 @@ export const negate = ((value: Input) => {
338
464
  }
339
465
  const data = storage(result);
340
466
  if (!(result instanceof BooleanVector)) {
341
- for (let index = 0; index < data.length; index++) data[index] = -data[index];
467
+ for (let index = 0; index < data.length; index++) {
468
+ data[index] = -data[index];
469
+ }
342
470
  }
343
471
  return result;
344
472
  }) as Negation;
@@ -357,21 +485,31 @@ export const multiply = ((
357
485
  right: Input | R<Transform> | number | bigint | boolean,
358
486
  ) => {
359
487
  if (left instanceof Transform) {
360
- if (right instanceof Transform) return new Transform(left).combine(right);
488
+ if (right instanceof Transform) {
489
+ return new Transform(left).combine(right);
490
+ }
361
491
  if (right instanceof Vector2 && right.scalarType === 'f32') {
362
492
  return left.transformPoint(right as R<Vector2f>);
363
493
  }
364
- throw new TypeError('Transform multiplication requires Transform or Vector2f');
494
+ throw new TypeError(
495
+ 'Transform multiplication requires Transform or Vector2f',
496
+ );
365
497
  }
366
498
  if (right instanceof Transform) {
367
- throw new TypeError('Transform must be the left multiplication operand');
499
+ throw new TypeError(
500
+ 'Transform must be the left multiplication operand',
501
+ );
368
502
  }
369
503
  if (left instanceof Color && right instanceof Color) {
370
504
  return modulate(new Color(left), right);
371
505
  }
372
- const leftScalar = typeof left === 'number' || typeof left === 'bigint' ||
506
+ const leftScalar =
507
+ typeof left === 'number' ||
508
+ typeof left === 'bigint' ||
373
509
  typeof left === 'boolean';
374
- const rightScalar = typeof right === 'number' || typeof right === 'bigint' ||
510
+ const rightScalar =
511
+ typeof right === 'number' ||
512
+ typeof right === 'bigint' ||
375
513
  typeof right === 'boolean';
376
514
  if (leftScalar && !rightScalar) {
377
515
  return scale(copy(right as Input), left, 'multiply');
@@ -380,7 +518,8 @@ export const multiply = ((
380
518
  return scale(copy(left as Input), right, 'multiply');
381
519
  }
382
520
  throw new TypeError('Multiplication requires one value and one scalar');
383
- }) as Scale & LeftScale & {
521
+ }) as Scale &
522
+ LeftScale & {
384
523
  (left: R<Transform>, right: R<Transform>): Transform;
385
524
  (left: R<Transform>, right: R<Vector2f>): Vector2f;
386
525
  (left: R<Color>, right: R<Color>): Color;
@@ -400,7 +539,9 @@ export const multiplyAssign = ((
400
539
  ) => {
401
540
  if (left instanceof Transform) {
402
541
  if (!(right instanceof Transform)) {
403
- throw new TypeError('Transform assignment requires another Transform');
542
+ throw new TypeError(
543
+ 'Transform assignment requires another Transform',
544
+ );
404
545
  }
405
546
  return left.combine(right);
406
547
  }
@@ -410,8 +551,11 @@ export const multiplyAssign = ((
410
551
  if (left instanceof Color || right instanceof Color) {
411
552
  return modulate(left, right as Input | number | bigint | boolean);
412
553
  }
413
- if (typeof right !== 'number' && typeof right !== 'bigint' &&
414
- typeof right !== 'boolean') {
554
+ if (
555
+ typeof right !== 'number' &&
556
+ typeof right !== 'bigint' &&
557
+ typeof right !== 'boolean'
558
+ ) {
415
559
  throw new TypeError('Expected a scalar');
416
560
  }
417
561
  return scale(left, right, 'multiply');
@@ -426,8 +570,10 @@ export const multiplyAssign = ((
426
570
  * @ja 左の値をスカラーで直接除算して返す。除数がゼロなら RangeError をスローする。
427
571
  * @ko 왼쪽 값을 스칼라로 제자리에서 나누고 반환한다. 제수가 0이면 RangeError를 던진다.
428
572
  */
429
- export const divideAssign = ((left: Value, right: number | bigint | boolean) =>
430
- scale(left, right, 'divide')) as ScaleAssign;
573
+ export const divideAssign = ((
574
+ left: Value,
575
+ right: number | bigint | boolean,
576
+ ) => scale(left, right, 'divide')) as ScaleAssign;
431
577
 
432
578
  /**
433
579
  * Return a new object divided by a scalar; dividing two Time or two Angle
@@ -439,10 +585,14 @@ export const divideAssign = ((left: Value, right: number | bigint | boolean) =>
439
585
  * 수치 비율을 반환한다.
440
586
  */
441
587
  export const divide = ((
442
- left: Input, right: Input | number | bigint | boolean,
588
+ left: Input,
589
+ right: Input | number | bigint | boolean,
443
590
  ) => {
444
- if (typeof right === 'number' || typeof right === 'bigint' ||
445
- typeof right === 'boolean') {
591
+ if (
592
+ typeof right === 'number' ||
593
+ typeof right === 'bigint' ||
594
+ typeof right === 'boolean'
595
+ ) {
446
596
  return scale(copy(left), right, 'divide');
447
597
  }
448
598
  if (left instanceof Time || right instanceof Time) {
@@ -457,7 +607,9 @@ export const divide = ((
457
607
  if (!(left instanceof Angle) || !(right instanceof Angle)) {
458
608
  throw new TypeError('Only two angles can be divided to obtain a ratio');
459
609
  }
460
- if (right.asRadians() === 0) throw new RangeError('Cannot divide by zero');
610
+ if (right.asRadians() === 0) {
611
+ throw new RangeError('Cannot divide by zero');
612
+ }
461
613
  return Math.fround(left.asRadians() / right.asRadians());
462
614
  }) as Scale & {
463
615
  (left: R<Time>, right: R<Time>): number;
@@ -480,7 +632,8 @@ export function modulo(left: R<Time>, right: R<Time>): Time;
480
632
  */
481
633
  export function modulo(left: R<Angle>, right: R<Angle>): Angle;
482
634
  export function modulo(
483
- left: R<Time> | R<Angle>, right: R<Time> | R<Angle>,
635
+ left: R<Time> | R<Angle>,
636
+ right: R<Time> | R<Angle>,
484
637
  ): Time | Angle {
485
638
  checkPair(left, right);
486
639
  if (left instanceof Time && right instanceof Time) {
@@ -510,7 +663,8 @@ export function moduloAssign(left: Time, right: R<Time>): Time;
510
663
  */
511
664
  export function moduloAssign(left: Angle, right: R<Angle>): Angle;
512
665
  export function moduloAssign(
513
- left: Time | Angle, right: R<Time> | R<Angle>,
666
+ left: Time | Angle,
667
+ right: R<Time> | R<Angle>,
514
668
  ): Time | Angle {
515
669
  checkMutable(left);
516
670
  checkPair(left, right);
@@ -522,13 +676,21 @@ export function moduloAssign(
522
676
  throw new TypeError('Expected matching Time or Angle operands');
523
677
  }
524
678
  left[angleStorage][0] = positiveRemainder(
525
- left.asRadians(), right.asRadians(),
679
+ left.asRadians(),
680
+ right.asRadians(),
526
681
  );
527
682
  return left;
528
683
  }
529
684
 
530
- type EqualityInput = Input | R<FloatRect> | R<IntRect> | R<Transform> |
531
- Readonly<BlendMode> | Readonly<StencilMode> | Readonly<VideoMode> | IpAddress;
685
+ type EqualityInput =
686
+ | Input
687
+ | R<FloatRect>
688
+ | R<IntRect>
689
+ | R<Transform>
690
+ | Readonly<BlendMode>
691
+ | Readonly<StencilMode>
692
+ | Readonly<VideoMode>
693
+ | IpAddress;
532
694
  const transformElements = [ 0, 1, 3, 4, 5, 7, 12, 13, 15 ];
533
695
 
534
696
  function equals(left: EqualityInput, right: EqualityInput): boolean {
@@ -545,22 +707,28 @@ function equals(left: EqualityInput, right: EqualityInput): boolean {
545
707
  if (!(left instanceof BlendMode) || !(right instanceof BlendMode)) {
546
708
  throw new TypeError('BlendMode equality requires two blend modes');
547
709
  }
548
- return left.colorSrcFactor === right.colorSrcFactor &&
710
+ return (
711
+ left.colorSrcFactor === right.colorSrcFactor &&
549
712
  left.colorDstFactor === right.colorDstFactor &&
550
713
  left.colorEquation === right.colorEquation &&
551
714
  left.alphaSrcFactor === right.alphaSrcFactor &&
552
715
  left.alphaDstFactor === right.alphaDstFactor &&
553
- left.alphaEquation === right.alphaEquation;
716
+ left.alphaEquation === right.alphaEquation
717
+ );
554
718
  }
555
719
  if (left instanceof StencilMode || right instanceof StencilMode) {
556
720
  if (!(left instanceof StencilMode) || !(right instanceof StencilMode)) {
557
- throw new TypeError('StencilMode equality requires two stencil modes');
721
+ throw new TypeError(
722
+ 'StencilMode equality requires two stencil modes',
723
+ );
558
724
  }
559
- return left.stencilComparison === right.stencilComparison &&
725
+ return (
726
+ left.stencilComparison === right.stencilComparison &&
560
727
  left.stencilUpdateOperation === right.stencilUpdateOperation &&
561
728
  left.stencilReference.value === right.stencilReference.value &&
562
729
  left.stencilMask.value === right.stencilMask.value &&
563
- left.stencilOnly === right.stencilOnly;
730
+ left.stencilOnly === right.stencilOnly
731
+ );
564
732
  }
565
733
  if (left instanceof Transform || right instanceof Transform) {
566
734
  if (!(left instanceof Transform) || !(right instanceof Transform)) {
@@ -571,14 +739,16 @@ function equals(left: EqualityInput, right: EqualityInput): boolean {
571
739
  return transformElements.every(index => a[index] === b[index]);
572
740
  }
573
741
  if (left instanceof Rect || right instanceof Rect) {
574
- if (!(left instanceof Rect) || !(right instanceof Rect) ||
575
- left.scalarType !== right.scalarType) {
742
+ if (
743
+ !(left instanceof Rect) ||
744
+ !(right instanceof Rect) ||
745
+ left.scalarType !== right.scalarType
746
+ ) {
576
747
  throw new TypeError('Rect operands must have the same scalar type');
577
748
  }
578
749
  const a = left[rectStorage];
579
750
  const b = right[rectStorage];
580
- return a[0] === b[0] && a[1] === b[1] &&
581
- a[2] === b[2] && a[3] === b[3];
751
+ return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];
582
752
  }
583
753
  checkPair(left as Input, right as Input);
584
754
  if (left instanceof Time && right instanceof Time) {
@@ -587,7 +757,9 @@ function equals(left: EqualityInput, right: EqualityInput): boolean {
587
757
  const a = storage(left as Input);
588
758
  const b = storage(right as Input);
589
759
  for (let index = 0; index < a.length; index++) {
590
- if (a[index] !== b[index]) return false;
760
+ if (a[index] !== b[index]) {
761
+ return false;
762
+ }
591
763
  }
592
764
  return true;
593
765
  }
@@ -629,7 +801,10 @@ function compare(
629
801
  return operation(left.compare(right), 0);
630
802
  }
631
803
  if (left instanceof VideoMode || right instanceof VideoMode) {
632
- return operation(compareVideoModes(left as VideoMode, right as VideoMode), 0);
804
+ return operation(
805
+ compareVideoModes(left as VideoMode, right as VideoMode),
806
+ 0,
807
+ );
633
808
  }
634
809
  if (left instanceof Time && right instanceof Time) {
635
810
  return operation(left.asMicroseconds(), right.asMicroseconds());
@@ -11,9 +11,13 @@ const maximumDelay = 2147483647n;
11
11
  * @ko 비동기 대기. 호출 스레드는 계속 이벤트 루프에서 사용할 수 있다.
12
12
  */
13
13
  export async function sleep(duration: ReadonlyValue<Time>): Promise<void> {
14
- if (!(duration instanceof Time)) throw new TypeError('Expected a Time');
14
+ if (!(duration instanceof Time)) {
15
+ throw new TypeError('Expected a Time');
16
+ }
15
17
  const microseconds = duration.asMicroseconds();
16
- if (microseconds <= 0n) return;
18
+ if (microseconds <= 0n) {
19
+ return;
20
+ }
17
21
  // Round positive fractions up to a millisecond. Snapshot before the await.
18
22
  let remaining = (microseconds + 999n) / 1000n;
19
23
  while (remaining > 0n) {