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
@@ -279,7 +279,9 @@ class HttpRequest {
279
279
  * @ja リクエストメソッドを設定します。
280
280
  * @ko 요청 메서드를 설정합니다.
281
281
  */
282
- setMethod(method) { this.method = (0, common_1.uint)(method, 4); }
282
+ setMethod(method) {
283
+ this.method = (0, common_1.uint)(method, 4);
284
+ }
283
285
  /**
284
286
  * Set the URL-encoded path and query string, adding a leading slash
285
287
  * if missing.
@@ -318,17 +320,21 @@ class HttpRequest {
318
320
  }
319
321
  [prepareRequest](host) {
320
322
  const fields = new Map(this.fields);
321
- if (!fields.has('host'))
323
+ if (!fields.has('host')) {
322
324
  fields.set('host', host);
323
- if (!fields.has('from'))
325
+ }
326
+ if (!fields.has('from')) {
324
327
  fields.set('from', 'user@sfml-dev.org');
325
- if (!fields.has('user-agent'))
328
+ }
329
+ if (!fields.has('user-agent')) {
326
330
  fields.set('user-agent', 'sfml.js');
331
+ }
327
332
  if (!fields.has('content-length')) {
328
333
  fields.set('content-length', String(this.body.length));
329
334
  }
330
- if (!fields.has('connection'))
335
+ if (!fields.has('connection')) {
331
336
  fields.set('connection', 'close');
337
+ }
332
338
  if (fields.has('transfer-encoding')) {
333
339
  throw new TypeError('Request bodies use Content-Length framing');
334
340
  }
@@ -339,8 +345,10 @@ class HttpRequest {
339
345
  `HTTP/${this.major}.${this.minor}\r\n` +
340
346
  [...fields].map(([key, value]) => `${key}: ${value}\r\n`).join('') +
341
347
  '\r\n';
342
- return { bytes: Buffer.concat([Buffer.from(header), this.body]),
343
- head: this.method === HttpMethod.Head };
348
+ return {
349
+ bytes: Buffer.concat([Buffer.from(header), this.body]),
350
+ head: this.method === HttpMethod.Head,
351
+ };
344
352
  }
345
353
  }
346
354
  /**
@@ -383,42 +391,54 @@ class HttpResponse {
383
391
  * @ko 대소문자를 구분하지 않는 이름으로 응답 헤더를 읽습니다.
384
392
  * 없으면 빈 문자열을 반환합니다.
385
393
  */
386
- getField(field) { return this.fields.get(field.toLowerCase()) ?? ''; }
394
+ getField(field) {
395
+ return this.fields.get(field.toLowerCase()) ?? '';
396
+ }
387
397
  /**
388
398
  * Return the server status code or client error code.
389
399
  * @zh 返回服务端状态码或客户端错误码。
390
400
  * @ja サーバーの状態コードまたはクライアントのエラーコードを返します。
391
401
  * @ko 서버 상태 코드 또는 클라이언트 오류 코드를 반환합니다.
392
402
  */
393
- getStatus() { return this.status; }
403
+ getStatus() {
404
+ return this.status;
405
+ }
394
406
  /**
395
407
  * Return the response's HTTP major version.
396
408
  * @zh 返回响应的 HTTP 主版本。
397
409
  * @ja レスポンスの HTTP メジャーバージョンを返します。
398
410
  * @ko 응답의 HTTP 주 버전을 반환합니다.
399
411
  */
400
- getMajorHttpVersion() { return this.major; }
412
+ getMajorHttpVersion() {
413
+ return this.major;
414
+ }
401
415
  /**
402
416
  * Return the response's HTTP minor version.
403
417
  * @zh 返回响应的 HTTP 次版本。
404
418
  * @ja レスポンスの HTTP マイナーバージョンを返します。
405
419
  * @ko 응답의 HTTP 부 버전을 반환합니다.
406
420
  */
407
- getMinorHttpVersion() { return this.minor; }
421
+ getMinorHttpVersion() {
422
+ return this.minor;
423
+ }
408
424
  /**
409
425
  * Decode the response body as a UTF-8 string.
410
426
  * @zh 将响应体按 UTF-8 解码为字符串。
411
427
  * @ja レスポンス本文を UTF-8 文字列として復号します。
412
428
  * @ko 응답 본문을 UTF-8 문자열로 디코딩합니다.
413
429
  */
414
- getBody() { return this.body.toString('utf8'); }
430
+ getBody() {
431
+ return this.body.toString('utf8');
432
+ }
415
433
  /**
416
434
  * Return an independent copy of the raw response body bytes.
417
435
  * @zh 返回响应体原始字节的独立副本。
418
436
  * @ja レスポンス本文の生バイトの独立したコピーを返します。
419
437
  * @ko 응답 본문 원시 바이트의 독립적인 복사본을 반환합니다.
420
438
  */
421
- getBodyBytes() { return Uint8Array.from(this.body); }
439
+ getBodyBytes() {
440
+ return Uint8Array.from(this.body);
441
+ }
422
442
  }
423
443
  /**
424
444
  * HTTP response status enumeration.
@@ -445,55 +465,69 @@ class ResponseParser {
445
465
  this.done = false;
446
466
  }
447
467
  feed(data, ended = false) {
448
- if (this.pending.length)
468
+ if (this.pending.length) {
449
469
  this.pending = Buffer.concat([this.pending, data]);
450
- else
470
+ }
471
+ else {
451
472
  this.pending = data;
473
+ }
452
474
  if (!this.status) {
453
475
  const end = this.pending.indexOf('\r\n\r\n');
454
476
  if (end < 0) {
455
- if (this.pending.length > 65536 || ended)
477
+ if (this.pending.length > 65536 || ended) {
456
478
  throw new Error('Invalid header');
479
+ }
457
480
  return undefined;
458
481
  }
459
482
  const lines = this.pending.toString('latin1', 0, end).split('\r\n');
460
483
  const match = /^HTTP\/(\d+)\.(\d+) (\d{3})(?: |$)/.exec(lines.shift());
461
- if (!match)
484
+ if (!match) {
462
485
  throw new Error('Invalid HTTP status line');
486
+ }
463
487
  this.major = Number(match[1]);
464
488
  this.minor = Number(match[2]);
465
489
  this.status = Number(match[3]);
466
- for (const line of lines)
490
+ for (const line of lines) {
467
491
  this.field(line);
492
+ }
468
493
  this.pending = this.pending.subarray(end + 4);
469
494
  if (this.status >= 100 && this.status < 200 && this.status !== 101) {
470
495
  this.status = 0;
471
496
  this.fields.clear();
472
497
  return this.feed(Buffer.alloc(0), ended);
473
498
  }
474
- this.chunked = this.fields.get('transfer-encoding')?.toLowerCase()
475
- .split(',')
476
- .map(value => value.trim())
477
- .includes('chunked') ?? false;
499
+ this.chunked =
500
+ this.fields
501
+ .get('transfer-encoding')
502
+ ?.toLowerCase()
503
+ .split(',')
504
+ .map(value => value.trim())
505
+ .includes('chunked') ?? false;
478
506
  const length = this.fields.get('content-length');
479
507
  if (!this.chunked && length !== undefined) {
480
- if (!/^\d+$/.test(length))
508
+ if (!/^\d+$/.test(length)) {
481
509
  throw new Error('Invalid Content-Length');
510
+ }
482
511
  this.remaining = Number(length);
483
- if (!Number.isSafeInteger(this.remaining) || this.remaining > 67108864) {
512
+ if (!Number.isSafeInteger(this.remaining) ||
513
+ this.remaining > 67108864) {
484
514
  throw new Error('HTTP body exceeds 64 MiB');
485
515
  }
486
516
  }
487
- if (this.head || this.status === 204 || this.status === 304 ||
488
- this.status === 101)
517
+ if (this.head ||
518
+ this.status === 204 ||
519
+ this.status === 304 ||
520
+ this.status === 101) {
489
521
  this.done = true;
522
+ }
490
523
  }
491
524
  while (!this.done && this.pending.length) {
492
525
  if (this.chunked) {
493
526
  if (this.trailers) {
494
527
  const end = this.pending.indexOf('\r\n');
495
- if (end < 0)
528
+ if (end < 0) {
496
529
  break;
530
+ }
497
531
  if (end === 0) {
498
532
  this.done = true;
499
533
  break;
@@ -503,8 +537,9 @@ class ResponseParser {
503
537
  continue;
504
538
  }
505
539
  if (this.chunkCrlf) {
506
- if (this.pending.length < 2)
540
+ if (this.pending.length < 2) {
507
541
  break;
542
+ }
508
543
  if (this.pending.toString('latin1', 0, 2) !== '\r\n') {
509
544
  throw new Error('Invalid chunk terminator');
510
545
  }
@@ -513,11 +548,15 @@ class ResponseParser {
513
548
  }
514
549
  if (this.chunkRemaining === undefined) {
515
550
  const end = this.pending.indexOf('\r\n');
516
- if (end < 0)
551
+ if (end < 0) {
517
552
  break;
518
- const text = this.pending.toString('latin1', 0, end).split(';')[0];
519
- if (!/^[0-9a-f]+$/i.test(text))
553
+ }
554
+ const text = this.pending
555
+ .toString('latin1', 0, end)
556
+ .split(';')[0];
557
+ if (!/^[0-9a-f]+$/i.test(text)) {
520
558
  throw new Error('Invalid chunk length');
559
+ }
521
560
  this.chunkRemaining = parseInt(text, 16);
522
561
  if (this.chunkRemaining > 67108864 - this.count) {
523
562
  throw new Error('HTTP body exceeds 64 MiB');
@@ -541,40 +580,50 @@ class ResponseParser {
541
580
  this.consume(count);
542
581
  if (this.remaining !== undefined) {
543
582
  this.remaining -= count;
544
- if (!this.remaining)
583
+ if (!this.remaining) {
545
584
  this.done = true;
585
+ }
546
586
  }
547
587
  }
548
588
  }
549
- if (this.remaining === 0 && !this.chunked)
589
+ if (this.remaining === 0 && !this.chunked) {
550
590
  this.done = true;
551
- if (this.pending.length > 65536)
591
+ }
592
+ if (this.pending.length > 65536) {
552
593
  throw new Error('HTTP framing exceeds limit');
594
+ }
553
595
  if (ended && !this.done) {
554
596
  if (this.chunked || this.remaining !== undefined) {
555
597
  throw new Error('Truncated HTTP response');
556
598
  }
557
599
  this.done = true;
558
600
  }
559
- return this.done ? new HttpResponse(this.status, this.fields, Buffer.concat(this.chunks, this.count), this.major, this.minor) : undefined;
601
+ return this.done
602
+ ? new HttpResponse(this.status, this.fields, Buffer.concat(this.chunks, this.count), this.major, this.minor)
603
+ : undefined;
560
604
  }
561
605
  consume(count) {
562
- if (this.count + count > 67108864)
606
+ if (this.count + count > 67108864) {
563
607
  throw new Error('HTTP body exceeds 64 MiB');
564
- if (count)
608
+ }
609
+ if (count) {
565
610
  this.chunks.push(this.pending.subarray(0, count));
611
+ }
566
612
  this.count += count;
567
613
  this.pending = this.pending.subarray(count);
568
614
  }
569
615
  field(line) {
570
616
  const split = line.indexOf(':');
571
- if (split <= 0)
617
+ if (split <= 0) {
572
618
  throw new Error('Invalid HTTP header field');
619
+ }
573
620
  const name = line.slice(0, split).toLowerCase();
574
621
  const value = line.slice(split + 1).trim();
575
- if (name === 'content-length' && this.fields.has(name) &&
576
- this.fields.get(name) !== value)
622
+ if (name === 'content-length' &&
623
+ this.fields.has(name) &&
624
+ this.fields.get(name) !== value) {
577
625
  throw new Error('Conflicting lengths');
626
+ }
578
627
  this.fields.set(name, value);
579
628
  }
580
629
  }
@@ -598,8 +647,9 @@ class Http {
598
647
  * port가 0이면 URL 포트 또는 프로토콜 기본 포트를 유지합니다.
599
648
  */
600
649
  constructor(host, port = 0, type) {
601
- if (host !== undefined)
650
+ if (host !== undefined) {
602
651
  this.setHost(host, port, type);
652
+ }
603
653
  }
604
654
  /**
605
655
  * Set the server and optional IP address family, returning whether the
@@ -612,16 +662,20 @@ class Http {
612
662
  */
613
663
  setHost(host, port = 0, type) {
614
664
  (0, common_1.uint)(port, 65535);
615
- if (type !== undefined)
665
+ if (type !== undefined) {
616
666
  (0, common_1.uint)(type, 1);
617
- if (typeof host !== 'string')
667
+ }
668
+ if (typeof host !== 'string') {
618
669
  throw new TypeError('Expected a hostname');
670
+ }
619
671
  try {
620
672
  const parsed = new URL(host.includes('://') ? host : `http://${host}`);
621
- if (!['http:', 'https:'].includes(parsed.protocol))
673
+ if (!['http:', 'https:'].includes(parsed.protocol)) {
622
674
  return false;
623
- if (port)
675
+ }
676
+ if (port) {
624
677
  parsed.port = String(port);
678
+ }
625
679
  this.host = parsed;
626
680
  this.family = type;
627
681
  return true;
@@ -659,37 +713,50 @@ class Http {
659
713
  * @ko signal - 선택적 취소 신호. 취소 시 ConnectionFailed를 반환합니다.
660
714
  */
661
715
  async sendRequest(request, timeout = time_1.Time.Zero, verifyServer = true, signal) {
662
- if (!(request instanceof HttpRequest))
716
+ if (!(request instanceof HttpRequest)) {
663
717
  throw new TypeError('Expected Request');
718
+ }
664
719
  const milliseconds = (0, common_1.millisecondsOf)(timeout);
665
720
  const host = this.host;
666
- if (!host || signal?.aborted)
721
+ if (!host || signal?.aborted) {
667
722
  return new HttpResponse();
723
+ }
668
724
  const prepared = request[prepareRequest](host.host);
669
- const options = { host: host.hostname.replace(/^\[|\]$/g, ''),
725
+ const options = {
726
+ host: host.hostname.replace(/^\[|\]$/g, ''),
670
727
  port: Number(host.port) || (host.protocol === 'https:' ? 443 : 80),
671
- family: this.family === undefined ? 0 : this.family === ip_address_1.IpAddressType.IpV4 ? 4 : 6 };
728
+ family: this.family === undefined
729
+ ? 0
730
+ : this.family === ip_address_1.IpAddressType.IpV4
731
+ ? 4
732
+ : 6,
733
+ };
672
734
  return new Promise(resolve => {
673
735
  let finished = false;
674
736
  let timer;
675
737
  const parser = new ResponseParser(prepared.head);
676
738
  let socket;
677
739
  const finish = (response = new HttpResponse()) => {
678
- if (finished)
740
+ if (finished) {
679
741
  return;
742
+ }
680
743
  finished = true;
681
- if (timer)
744
+ if (timer) {
682
745
  clearTimeout(timer);
746
+ }
683
747
  signal?.removeEventListener('abort', abort);
684
748
  socket?.destroy();
685
749
  resolve(response);
686
750
  };
687
- function abort() { finish(); }
751
+ function abort() {
752
+ finish();
753
+ }
688
754
  const receive = (data, ended = false) => {
689
755
  try {
690
756
  const response = parser.feed(data, ended);
691
- if (response)
757
+ if (response) {
692
758
  finish(response);
759
+ }
693
760
  }
694
761
  catch {
695
762
  finish(new HttpResponse(HttpStatus.InvalidResponse));
@@ -703,15 +770,18 @@ class Http {
703
770
  };
704
771
  socket = (0, node_tls_1.connect)(secureOptions, () => socket.write(prepared.bytes));
705
772
  }
706
- else
773
+ else {
707
774
  socket = (0, node_net_1.connect)(options, () => socket.write(prepared.bytes));
708
- socket.on('data', receive)
775
+ }
776
+ socket
777
+ .on('data', receive)
709
778
  .on('end', () => receive(Buffer.alloc(0), true))
710
779
  .on('error', () => finish())
711
780
  .on('close', () => finish());
712
781
  signal?.addEventListener('abort', abort, { once: true });
713
- if (milliseconds)
782
+ if (milliseconds) {
714
783
  timer = setTimeout(abort, milliseconds);
784
+ }
715
785
  });
716
786
  }
717
787
  }
@@ -37,16 +37,22 @@ var IpAddressType;
37
37
  */
38
38
  class IpAddress {
39
39
  constructor(address, b, c, d) {
40
- if (address instanceof IpAddress)
40
+ if (address instanceof IpAddress) {
41
41
  this.data = Buffer.from(address.data);
42
+ }
42
43
  else if (address instanceof Uint8Array) {
43
- if (address.length !== 16)
44
+ if (address.length !== 16) {
44
45
  throw new RangeError('IPv6 needs 16 bytes');
46
+ }
45
47
  this.data = Buffer.from(address);
46
48
  }
47
49
  else if (b !== undefined) {
48
- this.data = Buffer.from([(0, common_1.uint)(address, 255), (0, common_1.uint)(b, 255),
49
- (0, common_1.uint)(c, 255), (0, common_1.uint)(d, 255)]);
50
+ this.data = Buffer.from([
51
+ (0, common_1.uint)(address, 255),
52
+ (0, common_1.uint)(b, 255),
53
+ (0, common_1.uint)(c, 255),
54
+ (0, common_1.uint)(d, 255),
55
+ ]);
50
56
  }
51
57
  else {
52
58
  this.data = Buffer.alloc(4);
@@ -63,22 +69,27 @@ class IpAddress {
63
69
  * 허용하지 않으며, 형식이 잘못되면 undefined를 반환합니다.
64
70
  */
65
71
  static fromString(address) {
66
- if (typeof address !== 'string')
72
+ if (typeof address !== 'string') {
67
73
  throw new TypeError('Expected an IP string');
74
+ }
68
75
  // SFML inet_pton rejects zone identifiers and non-canonical IPv4 forms.
69
76
  const family = address.includes('%') ? 0 : (0, node_net_1.isIP)(address);
70
- if (!family)
77
+ if (!family) {
71
78
  return undefined;
79
+ }
72
80
  // ipaddr.js normalizes ::a.b.c.d into ::ffff:a.b.c.d. SFML retains the
73
81
  // original 128 bits, so expand the dotted suffix before parsing IPv6.
74
82
  const normalized = family === 6
75
83
  ? address.replace(/(?:\d+\.){3}\d+$/, suffix => {
76
84
  const octets = suffix.split('.').map(Number);
77
- return (octets[0] * 256 + octets[1]).toString(16) + ':' +
78
- (octets[2] * 256 + octets[3]).toString(16);
79
- }) : address;
85
+ return ((octets[0] * 256 + octets[1]).toString(16) +
86
+ ':' +
87
+ (octets[2] * 256 + octets[3]).toString(16));
88
+ })
89
+ : address;
80
90
  const data = Buffer.from(ipaddr.parse(normalized).toByteArray());
81
- return family === 4 ? new IpAddress(data.readUInt32BE())
91
+ return family === 4
92
+ ? new IpAddress(data.readUInt32BE())
82
93
  : new IpAddress(data);
83
94
  }
84
95
  /**
@@ -92,8 +103,9 @@ class IpAddress {
92
103
  */
93
104
  static async resolve(hostname) {
94
105
  const literal = this.fromString(hostname);
95
- if (literal)
106
+ if (literal) {
96
107
  return literal;
108
+ }
97
109
  const { resolve } = await Promise.resolve().then(() => require('./dns'));
98
110
  return (await resolve(hostname))?.find(address => address.isV4());
99
111
  }
@@ -129,23 +141,27 @@ class IpAddress {
129
141
  * secure는 HTTPS를 사용하며, 실패 시 undefined를 반환합니다.
130
142
  */
131
143
  static async getPublicAddress(timeout = time_1.Time.Zero, type = IpAddressType.IpV4, secure = false) {
132
- if (type !== undefined)
144
+ if (type !== undefined) {
133
145
  (0, common_1.uint)(type, 1);
146
+ }
134
147
  if (!secure) {
135
148
  const dns = await Promise.resolve().then(() => require('./dns'));
136
149
  for (const family of type === undefined
137
- ? [IpAddressType.IpV6, IpAddressType.IpV4] : [type]) {
150
+ ? [IpAddressType.IpV6, IpAddressType.IpV4]
151
+ : [type]) {
138
152
  const address = await dns.getPublicAddress(timeout, family);
139
- if (address)
153
+ if (address) {
140
154
  return address;
155
+ }
141
156
  }
142
157
  }
143
158
  const { Http } = await Promise.resolve().then(() => require('./http'));
144
159
  for (const host of ['ifconfig.co', 'ifconfig.me', 'icanhazip.com']) {
145
160
  const client = new Http(`${secure ? 'https' : 'http'}://${host}`, 0, type);
146
161
  const response = await client.sendRequest(new Http.Request('/ip'), timeout, secure);
147
- if (response.getStatus() !== 200)
162
+ if (response.getStatus() !== 200) {
148
163
  continue;
164
+ }
149
165
  const address = this.fromString(response.getBody().trim());
150
166
  if (address && (type === undefined || address.getType() === type)) {
151
167
  return address;
@@ -160,13 +176,15 @@ class IpAddress {
160
176
  * @ko 점으로 구분한 십진수 IPv4 또는 압축된 IPv6 텍스트를 반환합니다.
161
177
  */
162
178
  toString() {
163
- if (this.isV4())
179
+ if (this.isV4()) {
164
180
  return [...this.data].join('.');
181
+ }
165
182
  const compatible = this.data.subarray(0, 12).every(byte => byte === 0);
166
183
  const mapped = this.data.subarray(0, 10).every(byte => byte === 0) &&
167
- this.data[10] === 255 && this.data[11] === 255;
184
+ this.data[10] === 255 &&
185
+ this.data[11] === 255;
168
186
  if (mapped || (compatible && (this.data[12] || this.data[13]))) {
169
- return (mapped ? '::ffff:' : '::') + [...this.data.subarray(12)].join('.');
187
+ return ((mapped ? '::ffff:' : '::') + [...this.data.subarray(12)].join('.'));
170
188
  }
171
189
  return ipaddr.fromByteArray([...this.data]).toString();
172
190
  }
@@ -180,8 +198,9 @@ class IpAddress {
180
198
  * IPv6 주소이면 TypeError를 던집니다.
181
199
  */
182
200
  toInteger() {
183
- if (!this.isV4())
201
+ if (!this.isV4()) {
184
202
  throw new TypeError('Expected an IPv4 address');
203
+ }
185
204
  return this.data.readUInt32BE();
186
205
  }
187
206
  /**
@@ -193,8 +212,9 @@ class IpAddress {
193
212
  * IPv4 주소이면 TypeError를 던집니다.
194
213
  */
195
214
  toBytes() {
196
- if (!this.isV6())
215
+ if (!this.isV6()) {
197
216
  throw new TypeError('Expected an IPv6 address');
217
+ }
198
218
  return Uint8Array.from(this.data);
199
219
  }
200
220
  /**
@@ -212,14 +232,18 @@ class IpAddress {
212
232
  * @ja IPv4 アドレスかどうかを返します。
213
233
  * @ko IPv4 주소인지 반환합니다.
214
234
  */
215
- isV4() { return this.data.length === 4; }
235
+ isV4() {
236
+ return this.data.length === 4;
237
+ }
216
238
  /**
217
239
  * Return whether this is an IPv6 address.
218
240
  * @zh 返回是否为 IPv6 地址。
219
241
  * @ja IPv6 アドレスかどうかを返します。
220
242
  * @ko IPv6 주소인지 반환합니다.
221
243
  */
222
- isV6() { return this.data.length === 16; }
244
+ isV6() {
245
+ return this.data.length === 16;
246
+ }
223
247
  /**
224
248
  * Compare by address family then address bytes;
225
249
  * return a negative number, zero, or a positive number.
@@ -229,10 +253,11 @@ class IpAddress {
229
253
  * @ko 주소 계열, 주소 바이트 순서로 비교하며 음수, 0 또는 양수를 반환합니다.
230
254
  */
231
255
  compare(other) {
232
- if (!(other instanceof IpAddress))
256
+ if (!(other instanceof IpAddress)) {
233
257
  throw new TypeError('Expected IpAddress');
234
- return this.data.length - other.data.length ||
235
- Buffer.compare(this.data, other.data);
258
+ }
259
+ return (this.data.length - other.data.length ||
260
+ Buffer.compare(this.data, other.data));
236
261
  }
237
262
  }
238
263
  /**