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
@@ -89,7 +89,9 @@ class TcpSocket extends socket_1.Socket {
89
89
  * @ja ローカルポートを返し、未割り当てなら 0 を返します。
90
90
  * @ko 로컬 포트를 반환하며 아직 할당되지 않았으면 0입니다.
91
91
  */
92
- getLocalPort() { return this.transport?.localPort ?? 0; }
92
+ getLocalPort() {
93
+ return this.transport?.localPort ?? 0;
94
+ }
93
95
  /**
94
96
  * Return the peer address, or undefined when not connected.
95
97
  * @zh 返回对端地址,未连接时为 undefined。
@@ -97,7 +99,9 @@ class TcpSocket extends socket_1.Socket {
97
99
  * @ko 상대 주소를 반환하며 연결되지 않았으면 undefined입니다.
98
100
  */
99
101
  getRemoteAddress() {
100
- const address = this.connected ? this.transport?.remoteAddress : undefined;
102
+ const address = this.connected
103
+ ? this.transport?.remoteAddress
104
+ : undefined;
101
105
  return address ? ip_address_1.IpAddress.fromString(address) : undefined;
102
106
  }
103
107
  /**
@@ -107,7 +111,7 @@ class TcpSocket extends socket_1.Socket {
107
111
  * @ko 상대 포트를 반환하며 연결되지 않았으면 0입니다.
108
112
  */
109
113
  getRemotePort() {
110
- return this.connected ? this.transport?.remotePort ?? 0 : 0;
114
+ return this.connected ? (this.transport?.remotePort ?? 0) : 0;
111
115
  }
112
116
  /**
113
117
  * Start a TCP connection; wait for completion by default, or return NotReady
@@ -120,31 +124,39 @@ class TcpSocket extends socket_1.Socket {
120
124
  * NotReady를 반환합니다. Time.Zero는 제한 시간이 없습니다.
121
125
  */
122
126
  async connect(address, port, timeout = time_1.Time.Zero) {
123
- if (!(address instanceof ip_address_1.IpAddress))
127
+ if (!(address instanceof ip_address_1.IpAddress)) {
124
128
  throw new TypeError('Expected IpAddress');
129
+ }
125
130
  (0, common_1.uint)(port, 65535);
126
131
  const milliseconds = (0, common_1.millisecondsOf)(timeout);
127
132
  this.create(address.getType());
128
133
  const generation = this.epoch;
129
134
  const socket = this.transport;
130
135
  let timer;
131
- const done = (0, common_1.waitFor)(this[socket_1.socketEvents], () => this.connected || this.ended ||
132
- this.epoch !== generation).then(() => {
133
- if (timer)
136
+ const done = (0, common_1.waitFor)(this[socket_1.socketEvents], () => this.connected || this.ended || this.epoch !== generation).then(() => {
137
+ if (timer) {
134
138
  clearTimeout(timer);
135
- return this.epoch !== generation ? socket_1.SocketStatus.Disconnected
136
- : this.connected ? socket_1.SocketStatus.Done : socket_1.SocketStatus.Error;
139
+ }
140
+ return this.epoch !== generation
141
+ ? socket_1.SocketStatus.Disconnected
142
+ : this.connected
143
+ ? socket_1.SocketStatus.Done
144
+ : socket_1.SocketStatus.Error;
137
145
  });
138
146
  if (milliseconds) {
139
147
  timer = setTimeout(() => {
140
- if (this.epoch !== generation)
148
+ if (this.epoch !== generation) {
141
149
  return;
150
+ }
142
151
  this.failure = new Error('Connection timed out');
143
152
  socket.destroy(this.failure);
144
153
  }, milliseconds);
145
154
  }
146
- socket.connect({ host: address.toString(), port,
147
- family: address.isV4() ? 4 : 6 });
155
+ socket.connect({
156
+ host: address.toString(),
157
+ port,
158
+ family: address.isV4() ? 4 : 6,
159
+ });
148
160
  return this.blocking ? done : socket_1.SocketStatus.NotReady;
149
161
  }
150
162
  /**
@@ -153,7 +165,9 @@ class TcpSocket extends socket_1.Socket {
153
165
  * @ja 接続を即座に閉じ、未完了のパケット送受信状態を消去します。
154
166
  * @ko 즉시 연결을 닫고 미완료 패킷 송수신 상태를 지웁니다.
155
167
  */
156
- disconnect() { this.close(); }
168
+ disconnect() {
169
+ this.close();
170
+ }
157
171
  /**
158
172
  * Reject UDP or listener transports before adoption.
159
173
  * @zh 接管前拒绝 UDP 或监听传输。
@@ -161,8 +175,9 @@ class TcpSocket extends socket_1.Socket {
161
175
  * @ko 인수 전에 UDP 또는 리스너 전송 객체를 거부합니다.
162
176
  */
163
177
  validateHandle(handle) {
164
- if (!(handle instanceof node_net_1.Socket))
178
+ if (!(handle instanceof node_net_1.Socket)) {
165
179
  throw new TypeError('Expected Node TCP');
180
+ }
166
181
  }
167
182
  /**
168
183
  * Integrate the handle allocated or adopted by protected create into
@@ -213,12 +228,16 @@ class TcpSocket extends socket_1.Socket {
213
228
  * 기본적으로 검증하며 CA 바이트는 PEM 또는 DER를 지원합니다.
214
229
  */
215
230
  async setupTlsClient(hostname, verifyOrCa = true) {
216
- if (typeof hostname !== 'string')
231
+ if (typeof hostname !== 'string') {
217
232
  throw new TypeError('Expected hostname');
233
+ }
218
234
  return this.setupTls(() => (0, node_tls_1.connect)({
219
- socket: this.transport, servername: hostname,
235
+ socket: this.transport,
236
+ servername: hostname,
220
237
  rejectUnauthorized: verifyOrCa !== false,
221
- ca: typeof verifyOrCa === 'boolean' ? undefined : (0, tls_material_1.tlsCertificate)(verifyOrCa),
238
+ ca: typeof verifyOrCa === 'boolean'
239
+ ? undefined
240
+ : (0, tls_material_1.tlsCertificate)(verifyOrCa),
222
241
  }), 'secureConnect');
223
242
  }
224
243
  /**
@@ -251,14 +270,17 @@ class TcpSocket extends socket_1.Socket {
251
270
  getCurrentCiphersuiteName() {
252
271
  return this.tlsStatus === TlsStatus.HandshakeComplete &&
253
272
  this.transport instanceof node_tls_1.TLSSocket
254
- ? this.transport.getCipher()?.standardName ??
255
- this.transport.getCipher()?.name : undefined;
273
+ ? (this.transport.getCipher()?.standardName ??
274
+ this.transport.getCipher()?.name)
275
+ : undefined;
256
276
  }
257
277
  send(data) {
258
278
  const generation = this.epoch;
259
279
  // Snapshot at call time, including for nonblocking writes accepted by Node.
260
280
  const snapshot = data instanceof packet_1.Packet
261
- ? this.outgoing?.packet === data ? undefined : Buffer.from(data[packet_1.packetSend]())
281
+ ? this.outgoing?.packet === data
282
+ ? undefined
283
+ : Buffer.from(data[packet_1.packetSend]())
262
284
  : Buffer.from((0, common_1.bytes)(data));
263
285
  return this.writes.run(async () => {
264
286
  const packet = data instanceof packet_1.Packet ? data : undefined;
@@ -281,15 +303,19 @@ class TcpSocket extends socket_1.Socket {
281
303
  this.outgoing = { packet, data: wire, position: 0 };
282
304
  }
283
305
  const input = this.outgoing
284
- ? this.outgoing.data.subarray(this.outgoing.position) : snapshot;
306
+ ? this.outgoing.data.subarray(this.outgoing.position)
307
+ : snapshot;
285
308
  const socket = this.transport;
286
- if (!input.length)
309
+ if (!input.length) {
287
310
  return result(socket_1.SocketStatus.Done);
288
- const room = this.blocking ? input.length
311
+ }
312
+ const room = this.blocking
313
+ ? input.length
289
314
  : Math.max(0, socket.writableHighWaterMark - socket.writableLength);
290
315
  const count = Math.min(input.length, room);
291
- if (!count)
316
+ if (!count) {
292
317
  return result(socket_1.SocketStatus.NotReady);
318
+ }
293
319
  const completion = new Promise(resolve => {
294
320
  socket.write(input.subarray(0, count), error => resolve(error ? socket_1.SocketStatus.Error : socket_1.SocketStatus.Done));
295
321
  });
@@ -300,11 +326,14 @@ class TcpSocket extends socket_1.Socket {
300
326
  }
301
327
  }
302
328
  const status = this.blocking
303
- ? await this.awaitWrite(completion, generation) : socket_1.SocketStatus.Done;
304
- if (generation !== this.epoch)
329
+ ? await this.awaitWrite(completion, generation)
330
+ : socket_1.SocketStatus.Done;
331
+ if (generation !== this.epoch) {
305
332
  return result(socket_1.SocketStatus.Disconnected, count);
333
+ }
306
334
  return result(status === socket_1.SocketStatus.Done && count < input.length
307
- ? socket_1.SocketStatus.Partial : status, count);
335
+ ? socket_1.SocketStatus.Partial
336
+ : status, count);
308
337
  });
309
338
  }
310
339
  receive(destination) {
@@ -314,7 +343,8 @@ class TcpSocket extends socket_1.Socket {
314
343
  if (destination instanceof packet_1.Packet) {
315
344
  for (;;) {
316
345
  const header = this.packetSize === undefined;
317
- const needed = header ? 4 - this.prefixSize
346
+ const needed = header
347
+ ? 4 - this.prefixSize
318
348
  : this.packetSize - this.packetBytes;
319
349
  if (!needed && !header) {
320
350
  const payload = Buffer.concat(this.packetChunks, this.packetBytes);
@@ -323,8 +353,9 @@ class TcpSocket extends socket_1.Socket {
323
353
  return socket_1.SocketStatus.Done;
324
354
  }
325
355
  const chunk = await this.readChunk(needed, generation);
326
- if (typeof chunk === 'number')
356
+ if (typeof chunk === 'number') {
327
357
  return chunk;
358
+ }
328
359
  if (header) {
329
360
  chunk.copy(this.prefix, this.prefixSize);
330
361
  this.prefixSize += chunk.length;
@@ -346,11 +377,13 @@ class TcpSocket extends socket_1.Socket {
346
377
  if (this.prefixSize || this.packetSize !== undefined) {
347
378
  throw new Error('Finish receiving the pending Packet first');
348
379
  }
349
- if (!output.length)
380
+ if (!output.length) {
350
381
  return { status: socket_1.SocketStatus.Error, received: 0 };
382
+ }
351
383
  const chunk = await this.readChunk(output.length, generation);
352
- if (typeof chunk === 'number')
384
+ if (typeof chunk === 'number') {
353
385
  return { status: chunk, received: 0 };
386
+ }
354
387
  chunk.copy(output);
355
388
  return { status: socket_1.SocketStatus.Done, received: chunk.length };
356
389
  });
@@ -361,7 +394,9 @@ class TcpSocket extends socket_1.Socket {
361
394
  * @ja TCP トランスポートの生存状態を返します。派生クラスで拡張できます。
362
395
  * @ko TCP 전송 객체의 활성 상태를 반환하며 파생 클래스에서 확장할 수 있습니다.
363
396
  */
364
- isAlive() { return !!this.transport && !this.ended; }
397
+ isAlive() {
398
+ return !!this.transport && !this.ended;
399
+ }
365
400
  /**
366
401
  * Return readiness bits for receiving, sending, and the TLS handshake.
367
402
  * @zh 返回接收、发送及 TLS 握手对应的就绪位。
@@ -371,13 +406,19 @@ class TcpSocket extends socket_1.Socket {
371
406
  getReadiness(mask) {
372
407
  const socket = this.transport;
373
408
  const receive = socket && (socket.readableLength > 0 || this.ended) ? 1 : 0;
374
- const send = this.connected && socket && !socket.destroyed &&
375
- !socket.writableNeedDrain && this.tlsStatus !== TlsStatus.HandshakeStarted
376
- ? 2 : 0;
409
+ const send = this.connected &&
410
+ socket &&
411
+ !socket.destroyed &&
412
+ !socket.writableNeedDrain &&
413
+ this.tlsStatus !== TlsStatus.HandshakeStarted
414
+ ? 2
415
+ : 0;
377
416
  // eslint-disable-next-line no-bitwise
378
417
  return (receive | send) & mask;
379
418
  }
380
- getNativeHandle() { return this.transport; }
419
+ getNativeHandle() {
420
+ return this.transport;
421
+ }
381
422
  /** 重置 Packet 分帧累积状态。 */
382
423
  resetPacket() {
383
424
  this.prefixSize = 0;
@@ -387,17 +428,19 @@ class TcpSocket extends socket_1.Socket {
387
428
  }
388
429
  /** 异步读取最多 max 字节,含代际校验。 */
389
430
  async readChunk(max, generation) {
390
- const available = () => this.ended ||
391
- (this.transport?.readableLength ?? 0) > 0;
431
+ const available = () => this.ended || (this.transport?.readableLength ?? 0) > 0;
392
432
  await this.awaitReady(available, generation);
393
- if (generation !== this.epoch)
433
+ if (generation !== this.epoch) {
394
434
  return socket_1.SocketStatus.Disconnected;
435
+ }
395
436
  const socket = this.transport;
396
437
  const count = Math.min(max, socket?.readableLength ?? 0);
397
- if (count)
438
+ if (count) {
398
439
  return socket.read(count);
399
- if (this.ended)
440
+ }
441
+ if (this.ended) {
400
442
  return this.failure ? socket_1.SocketStatus.Error : socket_1.SocketStatus.Disconnected;
443
+ }
401
444
  return socket_1.SocketStatus.NotReady;
402
445
  }
403
446
  /** 绑定套接字事件监听并设置 TCP_NODELAY。 */
@@ -408,35 +451,43 @@ class TcpSocket extends socket_1.Socket {
408
451
  socket.setNoDelay(true);
409
452
  const generation = this.epoch;
410
453
  const current = () => socket === this.transport && generation === this.epoch;
411
- const readable = () => { if (current())
412
- this.changed(); };
454
+ const readable = () => {
455
+ if (current()) {
456
+ this.changed();
457
+ }
458
+ };
413
459
  const connected = () => {
414
- if (!current())
460
+ if (!current()) {
415
461
  return;
462
+ }
416
463
  this.connected = true;
417
464
  this.changed();
418
465
  };
419
466
  const ended = () => {
420
- if (!current())
467
+ if (!current()) {
421
468
  return;
469
+ }
422
470
  this.connected = false;
423
471
  this.ended = true;
424
472
  this.changed();
425
473
  };
426
474
  const error = (error) => {
427
- if (!current())
475
+ if (!current()) {
428
476
  return;
477
+ }
429
478
  this.failure = error;
430
479
  ended();
431
480
  };
432
- socket.on('readable', readable)
481
+ socket
482
+ .on('readable', readable)
433
483
  .on('drain', readable)
434
484
  .on('connect', connected)
435
485
  .on('end', ended)
436
486
  .on('close', ended)
437
487
  .on('error', error);
438
488
  this.detach = () => {
439
- socket.off('readable', readable)
489
+ socket
490
+ .off('readable', readable)
440
491
  .off('drain', readable)
441
492
  .off('connect', connected)
442
493
  .off('end', ended)
@@ -446,11 +497,13 @@ class TcpSocket extends socket_1.Socket {
446
497
  }
447
498
  /** 将空闲连接升级为 TLS 并等待握手完成。 */
448
499
  async setupTls(create, event) {
449
- if (!this.connected)
500
+ if (!this.connected) {
450
501
  return TlsStatus.NotConnected;
502
+ }
451
503
  const generation = this.epoch;
452
504
  if (this.tlsStatus === TlsStatus.NotConnected) {
453
- if (this.transport.readableLength || this.transport.writableLength) {
505
+ if (this.transport.readableLength ||
506
+ this.transport.writableLength) {
454
507
  throw new Error('TLS upgrade requires an empty plaintext queue');
455
508
  }
456
509
  try {
@@ -459,14 +512,18 @@ class TcpSocket extends socket_1.Socket {
459
512
  this.attach(socket);
460
513
  this.tlsStatus = TlsStatus.HandshakeStarted;
461
514
  const secure = () => {
462
- if (socket !== this.transport || generation !== this.epoch)
515
+ if (socket !== this.transport || generation !== this.epoch) {
463
516
  return;
517
+ }
464
518
  this.tlsStatus = TlsStatus.HandshakeComplete;
465
519
  this.changed();
466
520
  };
467
521
  socket.once(event, secure);
468
522
  const detach = this.detach;
469
- this.detach = () => { detach?.(); socket.off(event, secure); };
523
+ this.detach = () => {
524
+ detach?.();
525
+ socket.off(event, secure);
526
+ };
470
527
  }
471
528
  catch (error) {
472
529
  this.failure = error;
@@ -479,7 +536,8 @@ class TcpSocket extends socket_1.Socket {
479
536
  this.tlsStatus !== TlsStatus.HandshakeStarted ||
480
537
  generation !== this.epoch);
481
538
  }
482
- return this.ended || generation !== this.epoch ? TlsStatus.Error
539
+ return this.ended || generation !== this.epoch
540
+ ? TlsStatus.Error
483
541
  : this.tlsStatus;
484
542
  }
485
543
  }
@@ -13,8 +13,9 @@ const common_1 = require("./common");
13
13
  * Node TLS가 허용하는 PEM으로 변환합니다.
14
14
  */
15
15
  function tlsCertificate(input) {
16
- if (typeof input === 'string')
16
+ if (typeof input === 'string') {
17
17
  return input;
18
+ }
18
19
  const data = (0, common_1.bytes)(input);
19
20
  return data.includes('-----BEGIN CERTIFICATE-----')
20
21
  ? data : new node_crypto_1.X509Certificate(data).toString();
@@ -60,17 +60,20 @@ class UdpSocket extends socket_1.Socket {
60
60
  */
61
61
  async bind(port, address = ip_address_1.IpAddress.Any) {
62
62
  (0, common_1.uint)(port, 65535);
63
- if (!(address instanceof ip_address_1.IpAddress))
63
+ if (!(address instanceof ip_address_1.IpAddress)) {
64
64
  throw new TypeError('Expected IpAddress');
65
+ }
65
66
  this.create(address.getType());
66
67
  const socket = this.transport;
67
68
  const generation = this.epoch;
68
- const ready = (0, common_1.waitFor)(this[socket_1.socketEvents], () => this.bound ||
69
- !!this.failure || this.epoch !== generation);
69
+ const ready = (0, common_1.waitFor)(this[socket_1.socketEvents], () => this.bound || !!this.failure || this.epoch !== generation);
70
70
  socket.bind(port, address.toString());
71
71
  await ready;
72
- return this.epoch !== generation ? socket_1.SocketStatus.Disconnected
73
- : this.bound ? socket_1.SocketStatus.Done : socket_1.SocketStatus.Error;
72
+ return this.epoch !== generation
73
+ ? socket_1.SocketStatus.Disconnected
74
+ : this.bound
75
+ ? socket_1.SocketStatus.Done
76
+ : socket_1.SocketStatus.Error;
74
77
  }
75
78
  /**
76
79
  * Reject non-UDP Node transports before adoption.
@@ -79,8 +82,9 @@ class UdpSocket extends socket_1.Socket {
79
82
  * @ko 인수 전에 UDP가 아닌 Node 전송 객체를 거부합니다.
80
83
  */
81
84
  validateHandle(handle) {
82
- if (!(handle instanceof node_dgram_1.Socket))
85
+ if (!(handle instanceof node_dgram_1.Socket)) {
83
86
  throw new TypeError('Expected Node UDP');
87
+ }
84
88
  }
85
89
  /**
86
90
  * Integrate an allocated or adopted UDP handle into the same datagram queue
@@ -99,14 +103,16 @@ class UdpSocket extends socket_1.Socket {
99
103
  this.family = type === 'udp4' ? 4 : 6;
100
104
  const current = () => this.transport === socket && this.epoch === generation;
101
105
  const error = (error) => {
102
- if (!current())
106
+ if (!current()) {
103
107
  return;
108
+ }
104
109
  this.failure = error;
105
110
  this.changed();
106
111
  };
107
112
  const message = (data, peer) => {
108
- if (!current())
113
+ if (!current()) {
109
114
  return;
115
+ }
110
116
  if (this.pendingBytes + data.length <= 8 * 1024 * 1024 &&
111
117
  this.pending.length < 4096) {
112
118
  this.pending.push({ data, peer });
@@ -115,25 +121,30 @@ class UdpSocket extends socket_1.Socket {
115
121
  }
116
122
  };
117
123
  const listening = () => {
118
- if (!current())
124
+ if (!current()) {
119
125
  return;
126
+ }
120
127
  this.bound = true;
121
- if (this.family === 4)
128
+ if (this.family === 4) {
122
129
  socket.setBroadcast(true);
130
+ }
123
131
  this.changed();
124
132
  };
125
133
  const closed = () => {
126
- if (!current())
134
+ if (!current()) {
127
135
  return;
136
+ }
128
137
  this.bound = false;
129
138
  this.changed();
130
139
  };
131
- socket.on('error', error)
140
+ socket
141
+ .on('error', error)
132
142
  .on('message', message)
133
143
  .on('listening', listening)
134
144
  .on('close', closed);
135
145
  this.detach = () => {
136
- socket.off('error', error)
146
+ socket
147
+ .off('error', error)
137
148
  .off('message', message)
138
149
  .off('listening', listening)
139
150
  .off('close', closed);
@@ -152,7 +163,9 @@ class UdpSocket extends socket_1.Socket {
152
163
  * @ja UDP トランスポートを閉じ、受信待ちのデータグラムを消去します。
153
164
  * @ko UDP 전송 객체를 닫고 수신 대기 중인 데이터그램을 비웁니다.
154
165
  */
155
- unbind() { this.close(); }
166
+ unbind() {
167
+ this.close();
168
+ }
156
169
  /**
157
170
  * Clear the old transport's binding state and datagrams;
158
171
  * the generation change cancels old reads.
@@ -178,30 +191,37 @@ class UdpSocket extends socket_1.Socket {
178
191
  */
179
192
  send(data, address, port) {
180
193
  (0, common_1.uint)(port, 65535);
181
- if (!(address instanceof ip_address_1.IpAddress))
194
+ if (!(address instanceof ip_address_1.IpAddress)) {
182
195
  throw new TypeError('Expected IpAddress');
196
+ }
183
197
  const input = Buffer.from(data instanceof packet_1.Packet ? data[packet_1.packetSend]() : (0, common_1.bytes)(data));
184
- if (input.length > UdpSocket.MaxDatagramSize)
198
+ if (input.length > UdpSocket.MaxDatagramSize) {
185
199
  return Promise.resolve(socket_1.SocketStatus.Error);
186
- if (!this.transport)
200
+ }
201
+ if (!this.transport) {
187
202
  this.create(address.getType());
203
+ }
188
204
  const generation = this.epoch;
189
205
  return this.writes.run(() => this.sendBytes(input, address, port, generation));
190
206
  }
191
207
  /** 发送字节数据报,未绑定时自动绑定。 */
192
208
  async sendBytes(input, address, port, generation) {
193
- if (generation !== this.epoch)
209
+ if (generation !== this.epoch) {
194
210
  return socket_1.SocketStatus.Disconnected;
195
- if (this.family !== (address.isV4() ? 4 : 6))
211
+ }
212
+ if (this.family !== (address.isV4() ? 4 : 6)) {
196
213
  return socket_1.SocketStatus.Error;
214
+ }
197
215
  const socket = this.transport;
198
216
  let onError;
199
217
  const completion = new Promise(resolve => {
200
218
  const done = (error) => {
201
- if (generation !== this.epoch)
219
+ if (generation !== this.epoch) {
202
220
  return resolve(socket_1.SocketStatus.Disconnected);
203
- if (error)
221
+ }
222
+ if (error) {
204
223
  this.failure = error;
224
+ }
205
225
  resolve(error ? socket_1.SocketStatus.Error : socket_1.SocketStatus.Done);
206
226
  };
207
227
  // Node 在 bind 失败时丢弃排队的 send 回调,必须监听 error 完成它。
@@ -236,24 +256,35 @@ class UdpSocket extends socket_1.Socket {
236
256
  const output = destination instanceof packet_1.Packet ? undefined : (0, common_1.bytes)(destination);
237
257
  const generation = this.epoch;
238
258
  return this.reads.run(async () => {
239
- const result = (status) => ({ status, received: 0, remotePort: 0 });
240
- await this.awaitReady(() => this.pending.length > 0 || !this.bound ||
241
- !!this.failure, generation);
242
- if (generation !== this.epoch || !this.bound)
259
+ const result = (status) => ({
260
+ status,
261
+ received: 0,
262
+ remotePort: 0,
263
+ });
264
+ await this.awaitReady(() => this.pending.length > 0 || !this.bound || !!this.failure, generation);
265
+ if (generation !== this.epoch || !this.bound) {
243
266
  return result(socket_1.SocketStatus.Error);
267
+ }
244
268
  const item = this.pending.shift();
245
- if (!item)
269
+ if (!item) {
246
270
  return result(this.failure ? socket_1.SocketStatus.Error : socket_1.SocketStatus.NotReady);
271
+ }
247
272
  this.pendingBytes -= item.data.length;
248
- if (output && output.length < item.data.length)
273
+ if (output && output.length < item.data.length) {
249
274
  return result(socket_1.SocketStatus.Error);
250
- if (destination instanceof packet_1.Packet)
275
+ }
276
+ if (destination instanceof packet_1.Packet) {
251
277
  destination[packet_1.packetReceive](item.data);
252
- else
278
+ }
279
+ else {
253
280
  item.data.copy(output);
254
- return { status: socket_1.SocketStatus.Done, received: item.data.length,
281
+ }
282
+ return {
283
+ status: socket_1.SocketStatus.Done,
284
+ received: item.data.length,
255
285
  remoteAddress: ip_address_1.IpAddress.fromString(item.peer.address),
256
- remotePort: item.peer.port };
286
+ remotePort: item.peer.port,
287
+ };
257
288
  });
258
289
  }
259
290
  /**
@@ -262,7 +293,9 @@ class UdpSocket extends socket_1.Socket {
262
293
  * @ja バインド状態を返します。派生クラスで拡張できます。
263
294
  * @ko 바인딩 상태를 반환하며 파생 클래스에서 확장할 수 있습니다.
264
295
  */
265
- isAlive() { return this.bound; }
296
+ isAlive() {
297
+ return this.bound;
298
+ }
266
299
  /**
267
300
  * Return readiness bits for pending datagrams and the current binding.
268
301
  * @zh 返回待接收数据报和当前绑定对应的就绪位。
@@ -273,7 +306,9 @@ class UdpSocket extends socket_1.Socket {
273
306
  // eslint-disable-next-line no-bitwise
274
307
  return ((this.pending.length ? 1 : 0) | (this.bound ? 2 : 0)) & mask;
275
308
  }
276
- getNativeHandle() { return this.transport; }
309
+ getNativeHandle() {
310
+ return this.transport;
311
+ }
277
312
  }
278
313
  /**
279
314
  * Maximum UDP datagram payload size in bytes allowed by this implementation.
@@ -14,8 +14,9 @@ const tau = Math.fround(pi * 2);
14
14
  * @ko SFML의 float32 나머지. 소수부를 버린 몫은 int32 범위 내여야 한다.
15
15
  */
16
16
  function positiveRemainder(a, b) {
17
- if (!(b > 0))
17
+ if (!(b > 0)) {
18
18
  throw new RangeError('Angle modulus must be positive');
19
+ }
19
20
  // C++ int has no negative zero, unlike Math.trunc().
20
21
  const truncated = Math.trunc(Math.fround(a / b));
21
22
  const quotient = truncated === 0 ? 0 : truncated;
@@ -21,8 +21,9 @@ class Clock {
21
21
  */
22
22
  constructor(source) {
23
23
  if (source !== undefined) {
24
- if (!(source instanceof Clock))
24
+ if (!(source instanceof Clock)) {
25
25
  throw new TypeError('Expected a Clock');
26
+ }
26
27
  this.reference = source.reference;
27
28
  this.stopped = source.stopped;
28
29
  }
@@ -67,8 +68,9 @@ class Clock {
67
68
  * @ko 누적 시간을 유지하며 측정을 일시 정지한다.
68
69
  */
69
70
  stop() {
70
- if (this.stopped === undefined)
71
+ if (this.stopped === undefined) {
71
72
  this.stopped = node_process_1.hrtime.bigint();
73
+ }
72
74
  }
73
75
  /**
74
76
  * Clear and start timing, returning the previous accumulated running time.
@@ -47,8 +47,11 @@ function setErrorOutput(target) {
47
47
  throw new TypeError('Expected an open Writable');
48
48
  }
49
49
  // Native retains this destination until all bytes captured for it drain.
50
- // Buffers can split UTF-8 sequences; consumers decode them as a byte stream.
51
- native_1.native.setErrorOutput((bytes) => { target.write(bytes); });
50
+ // Buffers can split UTF-8 sequences; consumers decode them
51
+ // as a byte stream.
52
+ native_1.native.setErrorOutput((bytes) => {
53
+ target.write(bytes);
54
+ });
52
55
  if (!listening) {
53
56
  process.on('beforeExit', drainBeforeExit);
54
57
  listening = true;