sfml.js 1.0.0 → 1.1.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 (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 +40 -48
  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,6 +1,11 @@
1
1
  import { Socket as UdpHandle, type RemoteInfo } from 'node:dgram';
2
- import { Socket, SocketStatus as Status,
3
- socketEvents, SocketType, type SocketHandle } from './socket';
2
+ import {
3
+ Socket,
4
+ SocketStatus as Status,
5
+ socketEvents,
6
+ SocketType,
7
+ type SocketHandle,
8
+ } from './socket';
4
9
  import { IpAddress } from './ip-address';
5
10
  import { Packet, packetReceive, packetSend } from './packet';
6
11
  import { SerialQueue, bytes, uint, waitFor } from './common';
@@ -86,7 +91,9 @@ export class UdpSocket extends Socket {
86
91
  * @ko 바인딩되지 않은 UDP 소켓을 생성하며 기본적으로 비동기 블로킹 동작을
87
92
  * 사용합니다.
88
93
  */
89
- constructor() { super(SocketType.Udp); }
94
+ constructor() {
95
+ super(SocketType.Udp);
96
+ }
90
97
  /**
91
98
  * Return the bound local port, or 0 when unbound.
92
99
  * @zh 返回已绑定的本地端口,未绑定时为 0。
@@ -105,18 +112,28 @@ export class UdpSocket extends Socket {
105
112
  * @ko 로컬 포트와 주소를 비동기로 바인딩합니다. port가 0이면 시스템이
106
113
  * 할당하며 기본적으로 IPv4를 사용합니다.
107
114
  */
108
- async bind(port: number, address: IpAddress = IpAddress.Any): Promise<Status> {
115
+ async bind(
116
+ port: number,
117
+ address: IpAddress = IpAddress.Any,
118
+ ): Promise<Status> {
109
119
  uint(port, 65535);
110
- if (!(address instanceof IpAddress)) throw new TypeError('Expected IpAddress');
120
+ if (!(address instanceof IpAddress)) {
121
+ throw new TypeError('Expected IpAddress');
122
+ }
111
123
  this.create(address.getType());
112
124
  const socket = this.transport!;
113
125
  const generation = this.epoch;
114
- const ready = waitFor(this[socketEvents], () => this.bound ||
115
- !!this.failure || this.epoch !== generation);
126
+ const ready = waitFor(
127
+ this[socketEvents],
128
+ () => this.bound || !!this.failure || this.epoch !== generation,
129
+ );
116
130
  socket.bind(port, address.toString());
117
131
  await ready;
118
- return this.epoch !== generation ? Status.Disconnected
119
- : this.bound ? Status.Done : Status.Error;
132
+ return this.epoch !== generation
133
+ ? Status.Disconnected
134
+ : this.bound
135
+ ? Status.Done
136
+ : Status.Error;
120
137
  }
121
138
  /**
122
139
  * Reject non-UDP Node transports before adoption.
@@ -125,7 +142,9 @@ export class UdpSocket extends Socket {
125
142
  * @ko 인수 전에 UDP가 아닌 Node 전송 객체를 거부합니다.
126
143
  */
127
144
  protected validateHandle(handle: SocketHandle): void {
128
- if (!(handle instanceof UdpHandle)) throw new TypeError('Expected Node UDP');
145
+ if (!(handle instanceof UdpHandle)) {
146
+ throw new TypeError('Expected Node UDP');
147
+ }
129
148
  }
130
149
  /**
131
150
  * Integrate an allocated or adopted UDP handle into the same datagram queue
@@ -142,41 +161,63 @@ export class UdpSocket extends Socket {
142
161
  // Node 运行时保存创建地址族,但当前 @types/node 未声明此字段。
143
162
  const { type } = socket as UdpHandle & { type: 'udp4' | 'udp6' };
144
163
  this.family = type === 'udp4' ? 4 : 6;
145
- const current = () => this.transport === socket && this.epoch === generation;
164
+ const current = () =>
165
+ this.transport === socket && this.epoch === generation;
146
166
  const error = (error: Error) => {
147
- if (!current()) return;
148
- this.failure = error; this.changed();
167
+ if (!current()) {
168
+ return;
169
+ }
170
+ this.failure = error;
171
+ this.changed();
149
172
  };
150
173
  const message = (data: Buffer, peer: RemoteInfo) => {
151
- if (!current()) return;
152
- if (this.pendingBytes + data.length <= 8 * 1024 * 1024 &&
153
- this.pending.length < 4096) {
174
+ if (!current()) {
175
+ return;
176
+ }
177
+ if (
178
+ this.pendingBytes + data.length <= 8 * 1024 * 1024 &&
179
+ this.pending.length < 4096
180
+ ) {
154
181
  this.pending.push({ data, peer });
155
182
  this.pendingBytes += data.length;
156
183
  this.changed();
157
184
  }
158
185
  };
159
186
  const listening = () => {
160
- if (!current()) return;
187
+ if (!current()) {
188
+ return;
189
+ }
161
190
  this.bound = true;
162
- if (this.family === 4) socket.setBroadcast(true);
191
+ if (this.family === 4) {
192
+ socket.setBroadcast(true);
193
+ }
163
194
  this.changed();
164
195
  };
165
196
  const closed = () => {
166
- if (!current()) return;
167
- this.bound = false; this.changed();
197
+ if (!current()) {
198
+ return;
199
+ }
200
+ this.bound = false;
201
+ this.changed();
168
202
  };
169
- socket.on('error', error)
203
+ socket
204
+ .on('error', error)
170
205
  .on('message', message)
171
206
  .on('listening', listening)
172
207
  .on('close', closed);
173
208
  this.detach = () => {
174
- socket.off('error', error)
209
+ socket
210
+ .off('error', error)
175
211
  .off('message', message)
176
212
  .off('listening', listening)
177
213
  .off('close', closed);
178
214
  };
179
- try { socket.address(); listening(); } catch { this.bound = false; }
215
+ try {
216
+ socket.address();
217
+ listening();
218
+ } catch {
219
+ this.bound = false;
220
+ }
180
221
  }
181
222
  /**
182
223
  * Close the UDP transport and clear datagrams pending receipt.
@@ -184,7 +225,9 @@ export class UdpSocket extends Socket {
184
225
  * @ja UDP トランスポートを閉じ、受信待ちのデータグラムを消去します。
185
226
  * @ko UDP 전송 객체를 닫고 수신 대기 중인 데이터그램을 비웁니다.
186
227
  */
187
- unbind(): void { this.close(); }
228
+ unbind(): void {
229
+ this.close();
230
+ }
188
231
  /**
189
232
  * Clear the old transport's binding state and datagrams;
190
233
  * the generation change cancels old reads.
@@ -208,37 +251,66 @@ export class UdpSocket extends Socket {
208
251
  * @ko 호출 시점의 데이터 스냅샷을 하나의 데이터그램으로 송신합니다.
209
252
  * 바인딩되지 않았으면 대상 주소 계열에 맞는 임시 포트에 자동 바인딩합니다.
210
253
  */
211
- send(data: Uint8Array | Packet, address: IpAddress, port: number):
212
- Promise<Status> {
254
+ send(
255
+ data: Uint8Array | Packet,
256
+ address: IpAddress,
257
+ port: number,
258
+ ): Promise<Status> {
213
259
  uint(port, 65535);
214
- if (!(address instanceof IpAddress)) throw new TypeError('Expected IpAddress');
215
- const input = Buffer.from(data instanceof Packet ? data[packetSend]() : bytes(data));
216
- if (input.length > UdpSocket.MaxDatagramSize) return Promise.resolve(Status.Error);
217
- if (!this.transport) this.create(address.getType());
260
+ if (!(address instanceof IpAddress)) {
261
+ throw new TypeError('Expected IpAddress');
262
+ }
263
+ const input = Buffer.from(
264
+ data instanceof Packet ? data[packetSend]() : bytes(data),
265
+ );
266
+ if (input.length > UdpSocket.MaxDatagramSize) {
267
+ return Promise.resolve(Status.Error);
268
+ }
269
+ if (!this.transport) {
270
+ this.create(address.getType());
271
+ }
218
272
  const generation = this.epoch;
219
- return this.writes.run(() => this.sendBytes(input, address, port, generation));
273
+ return this.writes.run(() =>
274
+ this.sendBytes(input, address, port, generation),
275
+ );
220
276
  }
221
277
  /** 发送字节数据报,未绑定时自动绑定。 */
222
- private async sendBytes(input: Buffer, address: IpAddress, port: number,
223
- generation: number): Promise<Status> {
224
- if (generation !== this.epoch) return Status.Disconnected;
225
- if (this.family !== (address.isV4() ? 4 : 6)) return Status.Error;
278
+ private async sendBytes(
279
+ input: Buffer,
280
+ address: IpAddress,
281
+ port: number,
282
+ generation: number,
283
+ ): Promise<Status> {
284
+ if (generation !== this.epoch) {
285
+ return Status.Disconnected;
286
+ }
287
+ if (this.family !== (address.isV4() ? 4 : 6)) {
288
+ return Status.Error;
289
+ }
226
290
  const socket = this.transport!;
227
291
  let onError!: (error: Error) => void;
228
292
  const completion = new Promise<Status>(resolve => {
229
293
  const done = (error?: Error | null) => {
230
- if (generation !== this.epoch) return resolve(Status.Disconnected);
231
- if (error) this.failure = error;
294
+ if (generation !== this.epoch) {
295
+ return resolve(Status.Disconnected);
296
+ }
297
+ if (error) {
298
+ this.failure = error;
299
+ }
232
300
  resolve(error ? Status.Error : Status.Done);
233
301
  };
234
302
  // Node 在 bind 失败时丢弃排队的 send 回调,必须监听 error 完成它。
235
303
  onError = done;
236
304
  socket.once('error', onError);
237
- try { socket.send(input, port, address.toString(), done); } catch (error) {
305
+ try {
306
+ socket.send(input, port, address.toString(), done);
307
+ } catch (error) {
238
308
  done(error instanceof Error ? error : new Error(String(error)));
239
309
  }
240
310
  });
241
- try { return await this.awaitWrite(completion, generation); } finally {
311
+ try {
312
+ return await this.awaitWrite(completion, generation);
313
+ } finally {
242
314
  socket.off('error', onError);
243
315
  }
244
316
  }
@@ -254,23 +326,41 @@ export class UdpSocket extends Socket {
254
326
  * 폐기하고 Error를 반환합니다. 논블로킹 모드에서 데이터가 없으면 NotReady입니다.
255
327
  */
256
328
  receive(destination: Uint8Array | Packet): Promise<DatagramResult> {
257
- const output = destination instanceof Packet ? undefined : bytes(destination);
329
+ const output =
330
+ destination instanceof Packet ? undefined : bytes(destination);
258
331
  const generation = this.epoch;
259
332
  return this.reads.run(async () => {
260
- const result = (status: Status): DatagramResult =>
261
- ({ status, received: 0, remotePort: 0 });
262
- await this.awaitReady(() => this.pending.length > 0 || !this.bound ||
263
- !!this.failure, generation);
264
- if (generation !== this.epoch || !this.bound) return result(Status.Error);
333
+ const result = (status: Status): DatagramResult => ({
334
+ status,
335
+ received: 0,
336
+ remotePort: 0,
337
+ });
338
+ await this.awaitReady(
339
+ () => this.pending.length > 0 || !this.bound || !!this.failure,
340
+ generation,
341
+ );
342
+ if (generation !== this.epoch || !this.bound) {
343
+ return result(Status.Error);
344
+ }
265
345
  const item = this.pending.shift();
266
- if (!item) return result(this.failure ? Status.Error : Status.NotReady);
346
+ if (!item) {
347
+ return result(this.failure ? Status.Error : Status.NotReady);
348
+ }
267
349
  this.pendingBytes -= item.data.length;
268
- if (output && output.length < item.data.length) return result(Status.Error);
269
- if (destination instanceof Packet) destination[packetReceive](item.data);
270
- else item.data.copy(output!);
271
- return { status: Status.Done, received: item.data.length,
350
+ if (output && output.length < item.data.length) {
351
+ return result(Status.Error);
352
+ }
353
+ if (destination instanceof Packet) {
354
+ destination[packetReceive](item.data);
355
+ } else {
356
+ item.data.copy(output!);
357
+ }
358
+ return {
359
+ status: Status.Done,
360
+ received: item.data.length,
272
361
  remoteAddress: IpAddress.fromString(item.peer.address),
273
- remotePort: item.peer.port };
362
+ remotePort: item.peer.port,
363
+ };
274
364
  });
275
365
  }
276
366
  /**
@@ -279,7 +369,9 @@ export class UdpSocket extends Socket {
279
369
  * @ja バインド状態を返します。派生クラスで拡張できます。
280
370
  * @ko 바인딩 상태를 반환하며 파생 클래스에서 확장할 수 있습니다.
281
371
  */
282
- protected isAlive(): boolean { return this.bound; }
372
+ protected isAlive(): boolean {
373
+ return this.bound;
374
+ }
283
375
  /**
284
376
  * Return readiness bits for pending datagrams and the current binding.
285
377
  * @zh 返回待接收数据报和当前绑定对应的就绪位。
@@ -290,5 +382,7 @@ export class UdpSocket extends Socket {
290
382
  // eslint-disable-next-line no-bitwise
291
383
  return ((this.pending.length ? 1 : 0) | (this.bound ? 2 : 0)) & mask;
292
384
  }
293
- protected getNativeHandle(): UdpHandle | undefined { return this.transport; }
385
+ protected getNativeHandle(): UdpHandle | undefined {
386
+ return this.transport;
387
+ }
294
388
  }
@@ -14,7 +14,9 @@ const tau = Math.fround(pi * 2);
14
14
  * @ko SFML의 float32 나머지. 소수부를 버린 몫은 int32 범위 내여야 한다.
15
15
  */
16
16
  export function positiveRemainder(a: number, b: number): number {
17
- if (!(b > 0)) throw new RangeError('Angle modulus must be positive');
17
+ if (!(b > 0)) {
18
+ throw new RangeError('Angle modulus must be positive');
19
+ }
18
20
  // C++ int has no negative zero, unlike Math.trunc().
19
21
  const truncated = Math.trunc(Math.fround(a / b));
20
22
  const quotient = truncated === 0 ? 0 : truncated;
@@ -23,7 +23,9 @@ export class Clock {
23
23
  */
24
24
  constructor(source?: ReadonlyValue<Clock>) {
25
25
  if (source !== undefined) {
26
- if (!(source instanceof Clock)) throw new TypeError('Expected a Clock');
26
+ if (!(source instanceof Clock)) {
27
+ throw new TypeError('Expected a Clock');
28
+ }
27
29
  this.reference = source.reference;
28
30
  this.stopped = source.stopped;
29
31
  } else {
@@ -38,7 +40,9 @@ export class Clock {
38
40
  * @ko stop()으로 일시 정지한 시간을 제외한 누적 실행 시간을 반환한다.
39
41
  */
40
42
  getElapsedTime(): Time {
41
- return new Time(((this.stopped ?? hrtime.bigint()) - this.reference) / 1000n);
43
+ return new Time(
44
+ ((this.stopped ?? hrtime.bigint()) - this.reference) / 1000n,
45
+ );
42
46
  }
43
47
 
44
48
  /**
@@ -71,7 +75,9 @@ export class Clock {
71
75
  * @ko 누적 시간을 유지하며 측정을 일시 정지한다.
72
76
  */
73
77
  stop(this: Clock): void {
74
- if (this.stopped === undefined) this.stopped = hrtime.bigint();
78
+ if (this.stopped === undefined) {
79
+ this.stopped = hrtime.bigint();
80
+ }
75
81
  }
76
82
 
77
83
  /**
@@ -96,7 +102,9 @@ export class Clock {
96
102
 
97
103
  private resetAt(running: boolean): Time {
98
104
  const now = hrtime.bigint();
99
- const elapsed = new Time(((this.stopped ?? now) - this.reference) / 1000n);
105
+ const elapsed = new Time(
106
+ ((this.stopped ?? now) - this.reference) / 1000n,
107
+ );
100
108
  this.reference = now;
101
109
  this.stopped = running ? undefined : now;
102
110
  return elapsed;
package/src/system/err.ts CHANGED
@@ -46,8 +46,11 @@ export function setErrorOutput(target?: Writable | null): void {
46
46
  throw new TypeError('Expected an open Writable');
47
47
  }
48
48
  // Native retains this destination until all bytes captured for it drain.
49
- // Buffers can split UTF-8 sequences; consumers decode them as a byte stream.
50
- native.setErrorOutput((bytes: Buffer) => { target.write(bytes); });
49
+ // Buffers can split UTF-8 sequences; consumers decode them
50
+ // as a byte stream.
51
+ native.setErrorOutput((bytes: Buffer) => {
52
+ target.write(bytes);
53
+ });
51
54
  if (!listening) {
52
55
  process.on('beforeExit', drainBeforeExit);
53
56
  listening = true;
@@ -52,7 +52,9 @@ export class FileInputStream extends InputStream {
52
52
  }
53
53
  return this.enqueue(() => {
54
54
  const file = this.file;
55
- if (!file) return undefined;
55
+ if (!file) {
56
+ return undefined;
57
+ }
56
58
  if (!Number.isSafeInteger(this.position + data.byteLength)) {
57
59
  throw new RangeError('Read exceeds Node filesystem offset precision');
58
60
  }
@@ -60,7 +62,9 @@ export class FileInputStream extends InputStream {
60
62
  return new Promise<bigint | undefined>(resolve => {
61
63
  read(file.fd, data, 0, data.byteLength, this.position,
62
64
  (error, bytesRead) => {
63
- if (error) return resolve(undefined);
65
+ if (error) {
66
+ return resolve(undefined);
67
+ }
64
68
  this.position += bytesRead;
65
69
  resolve(BigInt(bytesRead));
66
70
  });
@@ -84,7 +88,9 @@ export class FileInputStream extends InputStream {
84
88
  throw new RangeError('Expected an offset from 0 to 2^53 - 1');
85
89
  }
86
90
  return this.enqueue(() => {
87
- if (!this.file) return undefined;
91
+ if (!this.file) {
92
+ return undefined;
93
+ }
88
94
  this.position = Number(position);
89
95
  return position;
90
96
  });
@@ -113,7 +119,9 @@ export class FileInputStream extends InputStream {
113
119
  */
114
120
  getSize(): Promise<bigint | undefined> {
115
121
  return this.enqueue(async () => {
116
- if (!this.file) return undefined;
122
+ if (!this.file) {
123
+ return undefined;
124
+ }
117
125
  try {
118
126
  return (await this.file.stat({ bigint: true })).size;
119
127
  } catch {
@@ -71,7 +71,9 @@ export class MemoryInputStream extends InputStream {
71
71
  */
72
72
  constructor(data?: Uint8Array) {
73
73
  super();
74
- if (data !== undefined) this.open(data);
74
+ if (data !== undefined) {
75
+ this.open(data);
76
+ }
75
77
  }
76
78
 
77
79
  /**
@@ -100,7 +102,9 @@ export class MemoryInputStream extends InputStream {
100
102
  * 스트림 끝에서는 0n, 열리지 않은 경우 undefined를 반환한다.
101
103
  */
102
104
  read(destination: Uint8Array): bigint | undefined {
103
- if (!this.data) return undefined;
105
+ if (!this.data) {
106
+ return undefined;
107
+ }
104
108
  const count = Math.min(destination.length,
105
109
  this.data.length - this.position);
106
110
  destination.set(this.data.subarray(this.position, this.position + count));
@@ -122,7 +126,9 @@ export class MemoryInputStream extends InputStream {
122
126
  if (typeof position !== 'bigint' || position < 0n) {
123
127
  throw new RangeError('Expected a non-negative bigint position');
124
128
  }
125
- if (!this.data) return undefined;
129
+ if (!this.data) {
130
+ return undefined;
131
+ }
126
132
  this.position = Number(position > BigInt(this.data.length)
127
133
  ? BigInt(this.data.length) : position);
128
134
  return BigInt(this.position);