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,12 +1,17 @@
1
1
  import {
2
- native, type NativeGraphicsHandle, type NativeImageMapping,
2
+ native,
3
+ type NativeGraphicsHandle,
4
+ type NativeImageMapping,
3
5
  type NativeImageResource,
4
6
  } from '../internal/native';
5
7
  import { graphicsNative } from '../internal/graphics-state';
6
8
  import { nativeStruct } from '../internal/struct-view';
7
9
  import { streamDispatch } from '../internal/input-stream';
8
10
  import type { InputStream } from '../system/input-stream';
9
- import { colorStorage, type ReadonlyValue } from '../internal/value-storage';
11
+ import {
12
+ colorStorage,
13
+ type ReadonlyValue,
14
+ } from '../internal/value-storage';
10
15
  import { Vector2, Vector2u } from '../system/vector2';
11
16
  import { Color } from './color';
12
17
  import { IntRect } from './rect';
@@ -17,9 +22,20 @@ import { IntRect } from './rect';
17
22
  * @ja コンパイル時の const ビュー。実行時ストレージは同じネイティブ Uint8Array です。
18
23
  * @ko 컴파일 시점의 const 뷰입니다. 런타임 저장 공간은 동일한 네이티브 Uint8Array입니다.
19
24
  */
20
- export type ReadonlyPixels = Readonly<Pick<Uint8Array,
21
- number | 'length' | 'byteLength' | 'byteOffset' | typeof Symbol.iterator |
22
- 'slice' | 'entries' | 'keys' | 'values'>>;
25
+ export type ReadonlyPixels = Readonly<
26
+ Pick<
27
+ Uint8Array,
28
+ | number
29
+ | 'length'
30
+ | 'byteLength'
31
+ | 'byteOffset'
32
+ | typeof Symbol.iterator
33
+ | 'slice'
34
+ | 'entries'
35
+ | 'keys'
36
+ | 'values'
37
+ >
38
+ >;
23
39
 
24
40
  function coordinates(value: Readonly<Vector2u>): void {
25
41
  if (!(value instanceof Vector2) || value.scalarType !== 'u32') {
@@ -27,15 +43,24 @@ function coordinates(value: Readonly<Vector2u>): void {
27
43
  }
28
44
  }
29
45
 
30
- function content(value: ReadonlyValue<Color> | Uint8Array): number | Uint8Array {
31
- if (value instanceof Color) return value.toInteger();
32
- if (value instanceof Uint8Array) return value;
46
+ function content(
47
+ value: ReadonlyValue<Color> | Uint8Array,
48
+ ): number | Uint8Array {
49
+ if (value instanceof Color) {
50
+ return value.toInteger();
51
+ }
52
+ if (value instanceof Uint8Array) {
53
+ return value;
54
+ }
33
55
  throw new TypeError('Expected a Color or RGBA Uint8Array');
34
56
  }
35
57
 
36
58
  function view(mapping: NativeImageMapping) {
37
- return nativeStruct<{ width: number; height: number; pixels: Uint8Array }>(
38
- mapping.info, { pixels: new Uint8Array(mapping.buffer) });
59
+ return nativeStruct<{
60
+ width: number;
61
+ height: number;
62
+ pixels: Uint8Array;
63
+ }>(mapping.info, { pixels: new Uint8Array(mapping.buffer) });
39
64
  }
40
65
 
41
66
  /**
@@ -65,7 +90,9 @@ export class Image {
65
90
  static {
66
91
  imageFromMapping = mapping => {
67
92
  const image = Object.create(Image.prototype) as Image;
68
- Object.defineProperty(image, graphicsNative, { value: mapping.handle });
93
+ Object.defineProperty(image, graphicsNative, {
94
+ value: mapping.handle,
95
+ });
69
96
  image.state = view(mapping);
70
97
  return image;
71
98
  };
@@ -93,7 +120,8 @@ export class Image {
93
120
  * @ko 지정한 픽셀 크기의 이미지를 만듭니다. 색상으로 채우거나 RGBA8 바이트를 복사하며 기본 색상은 검정입니다.
94
121
  */
95
122
  constructor(
96
- size: Readonly<Vector2u>, colorOrPixels?: ReadonlyValue<Color> | Uint8Array,
123
+ size: Readonly<Vector2u>,
124
+ colorOrPixels?: ReadonlyValue<Color> | Uint8Array,
97
125
  );
98
126
  constructor(
99
127
  sizeOrSource?: Readonly<Vector2u> | Image,
@@ -107,7 +135,9 @@ export class Image {
107
135
  } else {
108
136
  coordinates(sizeOrSource);
109
137
  mapping = native.createImage(
110
- sizeOrSource.x, sizeOrSource.y, content(colorOrPixels),
138
+ sizeOrSource.x,
139
+ sizeOrSource.y,
140
+ content(colorOrPixels),
111
141
  );
112
142
  }
113
143
  this[graphicsNative] = mapping.handle;
@@ -157,9 +187,14 @@ export class Image {
157
187
  colorOrPixels: ReadonlyValue<Color> | Uint8Array = Color.Black,
158
188
  ): void {
159
189
  coordinates(size);
160
- this.state = view(native.resizeImage(
161
- this[graphicsNative], size.x, size.y, content(colorOrPixels),
162
- ));
190
+ this.state = view(
191
+ native.resizeImage(
192
+ this[graphicsNative],
193
+ size.x,
194
+ size.y,
195
+ content(colorOrPixels),
196
+ ),
197
+ );
163
198
  }
164
199
 
165
200
  /**
@@ -172,8 +207,12 @@ export class Image {
172
207
  getPixel(coords: Readonly<Vector2u>): Color {
173
208
  const offset = this.offset(coords);
174
209
  const pixels = this.pixels;
175
- return new Color(pixels[offset], pixels[offset + 1],
176
- pixels[offset + 2], pixels[offset + 3]);
210
+ return new Color(
211
+ pixels[offset],
212
+ pixels[offset + 1],
213
+ pixels[offset + 2],
214
+ pixels[offset + 3],
215
+ );
177
216
  }
178
217
 
179
218
  /**
@@ -185,7 +224,9 @@ export class Image {
185
224
  */
186
225
  setPixel(coords: Readonly<Vector2u>, color: ReadonlyValue<Color>): void {
187
226
  const offset = this.offset(coords);
188
- if (!(color instanceof Color)) throw new TypeError('Expected a Color');
227
+ if (!(color instanceof Color)) {
228
+ throw new TypeError('Expected a Color');
229
+ }
189
230
  this.pixels.set(color[colorStorage], offset);
190
231
  }
191
232
 
@@ -197,13 +238,15 @@ export class Image {
197
238
  * @ko color와 정확히 일치하는 픽셀의 알파를 alpha(기본값 0)로 설정하며 RGB는 유지합니다.
198
239
  */
199
240
  createMaskFromColor(color: ReadonlyValue<Color>, alpha = 0): void {
200
- if (!(color instanceof Color)) throw new TypeError('Expected a Color');
201
- if (typeof alpha !== 'number') throw new TypeError('Expected numeric alpha');
241
+ if (!(color instanceof Color)) {
242
+ throw new TypeError('Expected a Color');
243
+ }
244
+ if (typeof alpha !== 'number') {
245
+ throw new TypeError('Expected numeric alpha');
246
+ }
202
247
  // eslint-disable-next-line no-bitwise
203
248
  const byte = alpha & 255;
204
- native.maskImage(
205
- this[graphicsNative], color.toInteger(), byte,
206
- );
249
+ native.maskImage(this[graphicsNative], color.toInteger(), byte);
207
250
  }
208
251
 
209
252
  /**
@@ -216,18 +259,28 @@ export class Image {
216
259
  * 반환합니다.
217
260
  */
218
261
  copy(
219
- source: Image, dest: Readonly<Vector2u>,
220
- sourceRect?: ReadonlyValue<IntRect>, applyAlpha = false,
262
+ source: Image,
263
+ dest: Readonly<Vector2u>,
264
+ sourceRect?: ReadonlyValue<IntRect>,
265
+ applyAlpha = false,
221
266
  ): boolean {
222
- if (!(source instanceof Image)) throw new TypeError('Expected an Image');
267
+ if (!(source instanceof Image)) {
268
+ throw new TypeError('Expected an Image');
269
+ }
223
270
  coordinates(dest);
224
271
  if (sourceRect !== undefined && !(sourceRect instanceof IntRect)) {
225
272
  throw new TypeError('Expected an IntRect');
226
273
  }
227
274
  return native.copyImage(
228
- this[graphicsNative], source[graphicsNative], dest.x, dest.y,
229
- sourceRect?.position.x ?? 0, sourceRect?.position.y ?? 0,
230
- sourceRect?.size.x ?? 0, sourceRect?.size.y ?? 0, applyAlpha,
275
+ this[graphicsNative],
276
+ source[graphicsNative],
277
+ dest.x,
278
+ dest.y,
279
+ sourceRect?.position.x ?? 0,
280
+ sourceRect?.position.y ?? 0,
281
+ sourceRect?.size.x ?? 0,
282
+ sourceRect?.size.y ?? 0,
283
+ applyAlpha,
231
284
  );
232
285
  }
233
286
 
@@ -286,7 +339,9 @@ export class Image {
286
339
  */
287
340
  async loadFromStream(stream: InputStream): Promise<boolean> {
288
341
  let failure: { error: unknown } | undefined;
289
- const dispatch = streamDispatch(stream, error => { failure = { error }; });
342
+ const dispatch = streamDispatch(stream, error => {
343
+ failure = { error };
344
+ });
290
345
  try {
291
346
  return await this.load(callback => {
292
347
  native.loadImageStream(this[graphicsNative], dispatch, callback);
@@ -305,10 +360,17 @@ export class Image {
305
360
  */
306
361
  saveToFile(filename: string): Promise<boolean> {
307
362
  return new Promise((resolve, reject) => {
308
- native.saveImageFile(this[graphicsNative], filename, (error, result) => {
309
- if (error) reject(error);
310
- else resolve(result);
311
- });
363
+ native.saveImageFile(
364
+ this[graphicsNative],
365
+ filename,
366
+ (error, result) => {
367
+ if (error) {
368
+ reject(error);
369
+ } else {
370
+ resolve(result);
371
+ }
372
+ },
373
+ );
312
374
  });
313
375
  }
314
376
 
@@ -321,10 +383,17 @@ export class Image {
321
383
  */
322
384
  saveToMemory(format: string): Promise<Uint8Array | undefined> {
323
385
  return new Promise((resolve, reject) => {
324
- native.saveImageMemory(this[graphicsNative], format, (error, result) => {
325
- if (error) reject(error);
326
- else resolve(result);
327
- });
386
+ native.saveImageMemory(
387
+ this[graphicsNative],
388
+ format,
389
+ (error, result) => {
390
+ if (error) {
391
+ reject(error);
392
+ } else {
393
+ resolve(result);
394
+ }
395
+ },
396
+ );
328
397
  });
329
398
  }
330
399
 
@@ -335,14 +404,19 @@ export class Image {
335
404
  * @ja コールバックでネイティブデコードを駆動する、共通の非同期読み込み入口。
336
405
  * @ko 콜백으로 네이티브 디코딩을 구동하는 공통 비동기 로드 진입점입니다.
337
406
  */
338
- private load(start: (
339
- callback: (error: Error | null, mapping?: NativeImageMapping) => void,
340
- ) => void): Promise<boolean> {
407
+ private load(
408
+ start: (
409
+ callback: (error: Error | null, mapping?: NativeImageMapping) => void,
410
+ ) => void,
411
+ ): Promise<boolean> {
341
412
  return new Promise((resolve, reject) => {
342
413
  start((error, mapping) => {
343
- if (error) reject(error);
344
- else {
345
- if (mapping) this.state = view(mapping);
414
+ if (error) {
415
+ reject(error);
416
+ } else {
417
+ if (mapping) {
418
+ this.state = view(mapping);
419
+ }
346
420
  resolve(mapping !== undefined);
347
421
  }
348
422
  });
@@ -1,18 +1,29 @@
1
1
  import { native, type NativeValueHandle } from '../internal/native';
2
- import { LazyValue, nativeValue, memberValue } from '../internal/lazy-value';
2
+ import {
3
+ LazyValue,
4
+ nativeValue,
5
+ memberValue,
6
+ } from '../internal/lazy-value';
3
7
  import { scalarArrays, toScalar } from '../internal/scalar';
4
8
  import {
5
- rectStorage, rectNative, vector2Storage, mutableValue, type ReadonlyValue as R,
9
+ rectStorage,
10
+ rectNative,
11
+ vector2Storage,
12
+ mutableValue,
13
+ type ReadonlyValue as R,
6
14
  } from '../internal/value-storage';
7
15
  import {
8
- Vector2, Vector2i, Vector2f, vector2FromState,
16
+ Vector2,
17
+ Vector2i,
18
+ Vector2f,
19
+ vector2FromState,
9
20
  } from '../system/vector2';
10
21
 
11
22
  type RectScalar = 'i32' | 'f32';
12
23
  type RectArguments<T extends RectScalar> =
13
24
  | []
14
- | [ source: R<Rect<RectScalar>> ]
15
- | [ position: R<Vector2<T>>, size: R<Vector2<T>> ];
25
+ | [source: R<Rect<RectScalar>>]
26
+ | [position: R<Vector2<T>>, size: R<Vector2<T>>];
16
27
 
17
28
  // Match SFML's comparisons, including unordered floats and signed zero.
18
29
  const min = (a: number, b: number): number => (a < b ? a : b);
@@ -57,8 +68,9 @@ export class Rect<T extends RectScalar> {
57
68
 
58
69
  protected constructor(type: T, ...args: RectArguments<T>) {
59
70
  this.type = type;
60
- this.state = new LazyValue(new scalarArrays[type](4),
61
- buffer => native.wrapRect(type, buffer));
71
+ this.state = new LazyValue(new scalarArrays[type](4), buffer =>
72
+ native.wrapRect(type, buffer),
73
+ );
62
74
  if (args.length === 1) {
63
75
  const source = args[0];
64
76
  if (!(source instanceof Rect)) {
@@ -103,10 +115,12 @@ export class Rect<T extends RectScalar> {
103
115
  get position(): Vector2<T> {
104
116
  if (!this.positionView) {
105
117
  const parent = this.state;
106
- this.positionView = vector2FromState(this.type, memberValue(
107
- parent, parent.values.subarray(0, 2),
108
- handle => native.rectMember(handle, 0),
109
- ));
118
+ this.positionView = vector2FromState(
119
+ this.type,
120
+ memberValue(parent, parent.values.subarray(0, 2), handle =>
121
+ native.rectMember(handle, 0),
122
+ ),
123
+ );
110
124
  }
111
125
  return this.positionView;
112
126
  }
@@ -131,10 +145,12 @@ export class Rect<T extends RectScalar> {
131
145
  get size(): Vector2<T> {
132
146
  if (!this.sizeView) {
133
147
  const parent = this.state;
134
- this.sizeView = vector2FromState(this.type, memberValue(
135
- parent, parent.values.subarray(2, 4),
136
- handle => native.rectMember(handle, 1),
137
- ));
148
+ this.sizeView = vector2FromState(
149
+ this.type,
150
+ memberValue(parent, parent.values.subarray(2, 4), handle =>
151
+ native.rectMember(handle, 1),
152
+ ),
153
+ );
138
154
  }
139
155
  return this.sizeView;
140
156
  }
@@ -162,8 +178,12 @@ export class Rect<T extends RectScalar> {
162
178
  const data = this[rectStorage];
163
179
  const endX = toScalar(this.type, data[0] + data[2]);
164
180
  const endY = toScalar(this.type, data[1] + data[3]);
165
- return point.x >= min(data[0], endX) && point.x < max(data[0], endX) &&
166
- point.y >= min(data[1], endY) && point.y < max(data[1], endY);
181
+ return (
182
+ point.x >= min(data[0], endX) &&
183
+ point.x < max(data[0], endX) &&
184
+ point.y >= min(data[1], endY) &&
185
+ point.y < max(data[1], endY)
186
+ );
167
187
  }
168
188
 
169
189
  /**
@@ -175,7 +195,10 @@ export class Rect<T extends RectScalar> {
175
195
  * 반환합니다.
176
196
  */
177
197
  findIntersection(rectangle: R<Rect<T>>): Rect<T> | undefined {
178
- if (!(rectangle instanceof Rect) || rectangle.scalarType !== this.type) {
198
+ if (
199
+ !(rectangle instanceof Rect) ||
200
+ rectangle.scalarType !== this.type
201
+ ) {
179
202
  throw new TypeError('Rect operands must have the same scalar type');
180
203
  }
181
204
  const a = this[rectStorage];
@@ -188,7 +211,9 @@ export class Rect<T extends RectScalar> {
188
211
  const top = max(min(a[1], ay), min(b[1], by));
189
212
  const right = min(max(a[0], ax), max(b[0], bx));
190
213
  const bottom = min(max(a[1], ay), max(b[1], by));
191
- if (!(left < right && top < bottom)) return undefined;
214
+ if (!(left < right && top < bottom)) {
215
+ return undefined;
216
+ }
192
217
  const result = this.createResult();
193
218
  const data = result[rectStorage];
194
219
  data[0] = left;
@@ -209,8 +234,9 @@ export class Rect<T extends RectScalar> {
209
234
  const data = this[rectStorage];
210
235
  const x = data[0] + toScalar(this.type, data[2] / 2);
211
236
  const y = data[1] + toScalar(this.type, data[3] / 2);
212
- return (this.type === 'f32'
213
- ? new Vector2f(x, y) : new Vector2i(x, y)) as Vector2<T>;
237
+ return (
238
+ this.type === 'f32' ? new Vector2f(x, y) : new Vector2i(x, y)
239
+ ) as Vector2<T>;
214
240
  }
215
241
 
216
242
  protected createResult(): Rect<T> {
@@ -225,7 +251,9 @@ export class Rect<T extends RectScalar> {
225
251
  */
226
252
  private checkVector(value: R<Vector2<T>>): void {
227
253
  if (!(value instanceof Vector2) || value.scalarType !== this.type) {
228
- throw new TypeError('Rect requires a Vector2 with the same scalar type');
254
+ throw new TypeError(
255
+ 'Rect requires a Vector2 with the same scalar type',
256
+ );
229
257
  }
230
258
  }
231
259
  }
@@ -329,7 +357,9 @@ export function intRectFromState(
329
357
  state: LazyValue<'rect', Int32Array>,
330
358
  ): IntRect {
331
359
  return Object.assign(Object.create(IntRect.prototype), {
332
- [mutableValue]: true, type: 'i32', state,
360
+ [mutableValue]: true,
361
+ type: 'i32',
362
+ state,
333
363
  createResult: () => new IntRect(),
334
364
  });
335
365
  }
@@ -344,7 +374,9 @@ export function floatRectFromState(
344
374
  state: LazyValue<'rect', Float32Array>,
345
375
  ): FloatRect {
346
376
  return Object.assign(Object.create(FloatRect.prototype), {
347
- [mutableValue]: true, type: 'f32', state,
377
+ [mutableValue]: true,
378
+ type: 'f32',
379
+ state,
348
380
  createResult: () => new FloatRect(),
349
381
  });
350
382
  }
@@ -49,8 +49,9 @@ export interface ReadonlyRenderStates {
49
49
  * @ja ステンシルテスト設定。
50
50
  * @ko 스텐실 테스트 설정입니다.
51
51
  */
52
- readonly stencilMode: Readonly<Omit<StencilMode,
53
- 'stencilReference' | 'stencilMask'>> & {
52
+ readonly stencilMode: Readonly<
53
+ Omit<StencilMode, 'stencilReference' | 'stencilMask'>
54
+ > & {
54
55
  /**
55
56
  * Read-only stencil reference value.
56
57
  * @zh 只读模板参考值。
@@ -111,8 +112,14 @@ export type RenderStatesOptions = Partial<ReadonlyRenderStates>;
111
112
  * @ja 描画状態の入力。設定オブジェクト、または単一の変換、ブレンド、ステンシル、テクスチャ、シェーダーリソース。
112
113
  * @ko 그리기 상태 입력입니다. 설정 객체 또는 단일 변환, 블렌드 모드, 스텐실 모드, 텍스처, 셰이더 리소스입니다.
113
114
  */
114
- export type RenderStatesInput = RenderStatesOptions | ReadonlyValue<Transform> |
115
- Readonly<BlendMode> | Readonly<StencilMode> | ReadonlyTexture | ReadonlyShader | null;
115
+ export type RenderStatesInput =
116
+ | RenderStatesOptions
117
+ | ReadonlyValue<Transform>
118
+ | Readonly<BlendMode>
119
+ | Readonly<StencilMode>
120
+ | ReadonlyTexture
121
+ | ReadonlyShader
122
+ | null;
116
123
 
117
124
  const defaultOptions: RenderStatesOptions = Object.freeze({});
118
125
 
@@ -176,16 +183,25 @@ export class RenderStates {
176
183
  */
177
184
  constructor(source: RenderStatesInput = defaultOptions) {
178
185
  let options: RenderStatesOptions;
179
- if (source === defaultOptions) options = defaultOptions;
180
- else if (source instanceof RenderStates) options = source;
181
- else if (source instanceof Transform) options = { transform: source };
182
- else if (source instanceof BlendMode) options = { blendMode: source };
183
- else if (source instanceof StencilMode) options = { stencilMode: source };
184
- else if (source instanceof Shader) options = { shader: source };
185
- else if (source instanceof Texture || source === null) {
186
+ if (source === defaultOptions) {
187
+ options = defaultOptions;
188
+ } else if (source instanceof RenderStates) {
189
+ options = source;
190
+ } else if (source instanceof Transform) {
191
+ options = { transform: source };
192
+ } else if (source instanceof BlendMode) {
193
+ options = { blendMode: source };
194
+ } else if (source instanceof StencilMode) {
195
+ options = { stencilMode: source };
196
+ } else if (source instanceof Shader) {
197
+ options = { shader: source };
198
+ } else if (source instanceof Texture || source === null) {
186
199
  options = { texture: source };
187
- } else if (typeof source === 'object') options = source as RenderStatesOptions;
188
- else throw new TypeError('Expected render states');
200
+ } else if (typeof source === 'object') {
201
+ options = source as RenderStatesOptions;
202
+ } else {
203
+ throw new TypeError('Expected render states');
204
+ }
189
205
 
190
206
  if (options.shader != null && !(options.shader instanceof Shader)) {
191
207
  throw new TypeError('Expected a Shader or null');
@@ -193,7 +209,8 @@ export class RenderStates {
193
209
  this.blendMode = new BlendMode(options.blendMode ?? BlendAlpha);
194
210
  this.stencilMode = new StencilMode(options.stencilMode);
195
211
  const transform = options.transform;
196
- this.matrix = transform == null ? new Transform() : new Transform(transform);
212
+ this.matrix =
213
+ transform == null ? new Transform() : new Transform(transform);
197
214
  numericProperties(this, { coordinateType: CoordinateType.Pixels });
198
215
  this.coordinateType = options.coordinateType ?? CoordinateType.Pixels;
199
216
  this.texture = options.texture ?? null;