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
@@ -68,7 +68,9 @@ class Music extends sound_stream_1.SoundStream {
68
68
  * @ko 스트리밍 재생을 위해 오디오 파일을 비동기로 열고 성공 여부를 반환합니다.
69
69
  * play를 자동으로 호출하지 않습니다.
70
70
  */
71
- openFromFile(filename) { return this.open(filename); }
71
+ openFromFile(filename) {
72
+ return this.open(filename);
73
+ }
72
74
  /**
73
75
  * Asynchronously open encoded audio bytes for streaming, returning whether it
74
76
  * succeeded.
@@ -77,7 +79,9 @@ class Music extends sound_stream_1.SoundStream {
77
79
  * 成功したかどうかを返します。
78
80
  * @ko 스트리밍 재생을 위해 인코딩된 오디오 바이트를 비동기로 열고 성공 여부를 반환합니다.
79
81
  */
80
- openFromMemory(data) { return this.open(data); }
82
+ openFromMemory(data) {
83
+ return this.open(data);
84
+ }
81
85
  /**
82
86
  * Asynchronously open a seekable stream, retaining the data source needed for
83
87
  * decoding until close.
@@ -99,7 +103,9 @@ class Music extends sound_stream_1.SoundStream {
99
103
  * @ko 스트리밍 디코딩 펌프의 최근 오류를 반환합니다.
100
104
  * 펌프를 사용하지 않거나 오류가 없으면 undefined입니다.
101
105
  */
102
- getWorkerError() { return this.pump?.error; }
106
+ getWorkerError() {
107
+ return this.pump?.error;
108
+ }
103
109
  /**
104
110
  * Return streaming decoder queue statistics, or undefined if no pump is used.
105
111
  * @zh 返回流式解码队列统计;未使用解码泵时为 undefined。
@@ -126,13 +132,15 @@ class Music extends sound_stream_1.SoundStream {
126
132
  ++this.closeGeneration;
127
133
  const context = callbackContext.getStore();
128
134
  const reentrant = context?.owner.deref() === this;
129
- // Stop feeding before queueing cleanup so open cannot wait for initial data.
135
+ // Stop feeding before queueing cleanup so open cannot wait
136
+ // for initial data.
130
137
  // @zh 先终止供数,再排队等待清理,避免打开过程仍在等待首批数据。
131
138
  // @ja 先に供給を停止してから後処理をキューに入れ、初期データ待ちを防ぎます。
132
139
  // @ko 열기가 초기 데이터를 기다리지 않도록 공급 중단 후 정리를 큐에 넣습니다.
133
140
  this.pump?.requestClose();
134
- if (reentrant && context.pump !== this.pump)
141
+ if (reentrant && context.pump !== this.pump) {
135
142
  context.pump.requestClose();
143
+ }
136
144
  const closed = this.queue.run(async () => {
137
145
  this.stop();
138
146
  try {
@@ -155,7 +163,10 @@ class Music extends sound_stream_1.SoundStream {
155
163
  * @ja 音楽全体の長さを返します。
156
164
  * @ko 음악의 전체 길이를 반환합니다.
157
165
  */
158
- getDuration() { this.command(7); return new time_1.Time(this.times[1]); }
166
+ getDuration() {
167
+ this.command(7);
168
+ return new time_1.Time(this.times[1]);
169
+ }
159
170
  /**
160
171
  * Return a copy of the loop region, including its starting offset and length.
161
172
  * @zh 返回循环区间副本,包含起点偏移和长度。
@@ -164,8 +175,10 @@ class Music extends sound_stream_1.SoundStream {
164
175
  */
165
176
  getLoopPoints() {
166
177
  this.command(6);
167
- return new value_1.TimeSpan({ offset: new time_1.Time(this.times[2]),
168
- length: new time_1.Time(this.times[3]) });
178
+ return new value_1.TimeSpan({
179
+ offset: new time_1.Time(this.times[2]),
180
+ length: new time_1.Time(this.times[3]),
181
+ });
169
182
  }
170
183
  /**
171
184
  * Set the loop region; call setLooping(true) separately to enable looping.
@@ -257,22 +270,25 @@ class Music extends sound_stream_1.SoundStream {
257
270
  createCallbacks() {
258
271
  if (this.onGetData === Music.prototype.onGetData &&
259
272
  this.onSeek === Music.prototype.onSeek &&
260
- this.onLoop === Music.prototype.onLoop)
273
+ this.onLoop === Music.prototype.onLoop) {
261
274
  return undefined;
275
+ }
262
276
  const owner = new WeakRef(this);
263
277
  return {
264
278
  onGetData: (chunk, pump) => callbackContext.run({ owner, pump }, () => {
265
279
  const target = owner.deref();
266
- if (target)
280
+ if (target) {
267
281
  return target.onGetData(chunk);
282
+ }
268
283
  pump.requestClose();
269
284
  chunk.sampleCount = 0;
270
285
  return false;
271
286
  }),
272
287
  onSeek: (offset, pump) => callbackContext.run({ owner, pump }, () => {
273
288
  const target = owner.deref();
274
- if (target)
289
+ if (target) {
275
290
  return target.onSeek(offset);
291
+ }
276
292
  pump.requestClose();
277
293
  }),
278
294
  onLoop: pump => callbackContext.run({ owner, pump }, () => owner.deref()?.onLoop()),
@@ -305,23 +321,29 @@ class Music extends sound_stream_1.SoundStream {
305
321
  }
306
322
  const generation = this.closeGeneration;
307
323
  return this.queue.run(async () => {
308
- if (generation !== this.closeGeneration)
324
+ if (generation !== this.closeGeneration) {
309
325
  return false;
326
+ }
310
327
  const callbacks = this.createCallbacks();
311
- if (callbacks || audio_codec_registry_1.audioReaders.size ||
328
+ if (callbacks ||
329
+ audio_codec_registry_1.audioReaders.size ||
312
330
  (typeof input !== 'string' && !(input instanceof Uint8Array))) {
313
331
  const file = new input_sound_file_1.InputSoundFile();
314
332
  let adopted = false;
315
333
  try {
316
- const ok = typeof input === 'string' ? await file.openFromFile(input)
317
- : input instanceof Uint8Array ? await file.openFromMemory(input)
334
+ const ok = typeof input === 'string'
335
+ ? await file.openFromFile(input)
336
+ : input instanceof Uint8Array
337
+ ? await file.openFromMemory(input)
318
338
  : await file.openFromStream(input);
319
- if (!ok || generation !== this.closeGeneration)
339
+ if (!ok || generation !== this.closeGeneration) {
320
340
  return false;
341
+ }
321
342
  this.stop();
322
343
  await this.closePump();
323
- if (generation !== this.closeGeneration)
344
+ if (generation !== this.closeGeneration) {
324
345
  return false;
346
+ }
325
347
  const mapping = audio_native_1.audioNative.openAudioMusicStream(this[audio_native_1.audioHandle], 1024, file.getChannelCount(), file.getSampleRate(), 8, Int32Array.from(file.getChannelMap()), file.getSampleCount());
326
348
  this.pump = new audio_music_pump_1.AudioMusicPump(mapping.handle, mapping.token, file, callbacks);
327
349
  adopted = true;
@@ -330,8 +352,9 @@ class Music extends sound_stream_1.SoundStream {
330
352
  return await this.pump.ready;
331
353
  }
332
354
  finally {
333
- if (!adopted)
355
+ if (!adopted) {
334
356
  await file.close();
357
+ }
335
358
  }
336
359
  }
337
360
  const ok = await (0, audio_native_1.audioAsync)(callback => audio_native_1.audioNative.openAudioMusic(this[audio_native_1.audioHandle], input, callback));
@@ -45,13 +45,15 @@ class OutputSoundFile {
45
45
  throw new TypeError('Writer.open must return a boolean');
46
46
  }
47
47
  opened = result;
48
- if (opened)
48
+ if (opened) {
49
49
  this.writer = writer;
50
+ }
50
51
  return opened;
51
52
  }
52
53
  finally {
53
- if (!opened)
54
+ if (!opened) {
54
55
  await writer.close();
56
+ }
55
57
  }
56
58
  });
57
59
  }
@@ -68,7 +68,9 @@ function command(id, name) {
68
68
  * @ja 利用可能な再生デバイスの名前を返します。
69
69
  * @ko 사용 가능한 재생 장치 이름을 반환합니다.
70
70
  */
71
- function getAvailableDevices() { return command(0); }
71
+ function getAvailableDevices() {
72
+ return command(0);
73
+ }
72
74
  exports.getAvailableDevices = getAvailableDevices;
73
75
  /**
74
76
  * Return the system's default playback device name,
@@ -109,7 +111,10 @@ exports.setDeviceToDefault = setDeviceToDefault;
109
111
  * @ja 音を出力しないヌルデバイスに切り替え、成功したかどうかを返します。
110
112
  * @ko 소리를 출력하지 않는 널 장치로 전환하고 성공 여부를 반환합니다.
111
113
  */
112
- function setDeviceToNull() { command(4); return values[3] !== 0; }
114
+ function setDeviceToNull() {
115
+ command(4);
116
+ return values[3] !== 0;
117
+ }
113
118
  exports.setDeviceToNull = setDeviceToNull;
114
119
  /**
115
120
  * Return the current playback device name, or undefined if unavailable.
@@ -138,7 +143,10 @@ exports.getDeviceSampleRate = getDeviceSampleRate;
138
143
  * @ja 現在のデバイスがシステムの既定デバイスに追従するかどうかを返します。
139
144
  * @ko 현재 장치가 시스템 기본 장치를 따르는지 반환합니다.
140
145
  */
141
- function isDefaultDevice() { command(7); return values[2] !== 0; }
146
+ function isDefaultDevice() {
147
+ command(7);
148
+ return values[2] !== 0;
149
+ }
142
150
  exports.isDefaultDevice = isDefaultDevice;
143
151
  /**
144
152
  * Set the device notification callback; undefined or null removes it.
@@ -31,7 +31,9 @@ class SoundBufferRecorder extends sound_recorder_1.SoundRecorder {
31
31
  * @ko 가장 최근 완성된 녹음 버퍼를 반환합니다.
32
32
  * 새 결과는 await stop() 후에 가져와야 합니다.
33
33
  */
34
- getBuffer() { return this.buffer; }
34
+ getBuffer() {
35
+ return this.buffer;
36
+ }
35
37
  /**
36
38
  * Called on the object's owning JS thread before capture begins; supports
37
39
  * synchronous or asynchronous returns, with false rejecting capture.
@@ -74,8 +76,7 @@ class SoundBufferRecorder extends sound_recorder_1.SoundRecorder {
74
76
  * 수정 후 super를 호출할 수 있으며, 호출하지 않으면 저장되지 않습니다.
75
77
  */
76
78
  onProcessSamples(samples) {
77
- return (0, audio_recorder_session_1.recorderCallbackSession)(this[audio_native_1.audioHandle], 'onProcessSamples')
78
- .append(samples);
79
+ return (0, audio_recorder_session_1.recorderCallbackSession)(this[audio_native_1.audioHandle], 'onProcessSamples').append(samples);
79
80
  }
80
81
  /**
81
82
  * Called once on the object's owning JS thread after the device stops and
@@ -105,9 +106,11 @@ class SoundBufferRecorder extends sound_recorder_1.SoundRecorder {
105
106
  */
106
107
  recorderCallbacks() {
107
108
  if (this.onStart === SoundBufferRecorder.prototype.onStart &&
108
- this.onProcessSamples === SoundBufferRecorder.prototype.onProcessSamples &&
109
- this.onStop === SoundBufferRecorder.prototype.onStop)
109
+ this.onProcessSamples ===
110
+ SoundBufferRecorder.prototype.onProcessSamples &&
111
+ this.onStop === SoundBufferRecorder.prototype.onStop) {
110
112
  return undefined;
113
+ }
111
114
  return SoundBufferRecorder.callbacks(new WeakRef(this));
112
115
  }
113
116
  /**
@@ -50,8 +50,9 @@ class SoundBuffer {
50
50
  if (!(source instanceof SoundBuffer)) {
51
51
  throw new TypeError('Expected a SoundBuffer');
52
52
  }
53
- if (source === this)
53
+ if (source === this) {
54
54
  return this;
55
+ }
55
56
  this.state = view(audio_native_1.audioNative.assignAudioBuffer(this[audio_native_1.audioHandle], source[audio_native_1.audioHandle]));
56
57
  return this;
57
58
  }
@@ -71,7 +72,9 @@ class SoundBuffer {
71
72
  * 성공 여부를 반환합니다.
72
73
  */
73
74
  loadFromFile(filename) {
74
- return audio_codec_registry_1.audioReaders.size ? this.loadDecoded(filename) : this.load(filename);
75
+ return audio_codec_registry_1.audioReaders.size
76
+ ? this.loadDecoded(filename)
77
+ : this.load(filename);
75
78
  }
76
79
  /**
77
80
  * Asynchronously decode encoded audio bytes and replace the PCM,
@@ -95,7 +98,8 @@ class SoundBuffer {
95
98
  * 스트림 오류는 Promise를 거부합니다.
96
99
  */
97
100
  loadFromStream(stream) {
98
- return audio_codec_registry_1.audioReaders.size ? this.loadDecoded(stream)
101
+ return audio_codec_registry_1.audioReaders.size
102
+ ? this.loadDecoded(stream)
99
103
  : this.load(new audio_input_stream_1.AudioInputStream(stream));
100
104
  }
101
105
  /**
@@ -110,8 +114,9 @@ class SoundBuffer {
110
114
  loadFromSamples(data, channelCount, sampleRate, channelMap) {
111
115
  (0, value_1.samples)(data);
112
116
  const result = audio_native_1.audioNative.audioBufferSamples(data, (0, value_1.unsigned)(sampleRate), (0, value_1.unsigned)(channelCount), (0, value_1.channels)(channelMap));
113
- if (!result)
117
+ if (!result) {
114
118
  return false;
119
+ }
115
120
  this.state = view(audio_native_1.audioNative.commitAudioBuffer(this[audio_native_1.audioHandle], result));
116
121
  return true;
117
122
  }
@@ -134,35 +139,45 @@ class SoundBuffer {
134
139
  * @ja 全チャンネルのサンプル総数を返します。
135
140
  * @ko 모든 채널의 샘플 총수를 반환합니다.
136
141
  */
137
- getSampleCount() { return this.state.sampleCount; }
142
+ getSampleCount() {
143
+ return this.state.sampleCount;
144
+ }
138
145
  /**
139
146
  * Return the sample rate per channel, in Hz.
140
147
  * @zh 返回每声道采样率,单位为 Hz。
141
148
  * @ja チャンネルごとのサンプルレートを Hz で返します。
142
149
  * @ko 채널별 샘플 레이트를 Hz 단위로 반환합니다.
143
150
  */
144
- getSampleRate() { return this.state.sampleRate; }
151
+ getSampleRate() {
152
+ return this.state.sampleRate;
153
+ }
145
154
  /**
146
155
  * Return the number of channels.
147
156
  * @zh 返回声道数量。
148
157
  * @ja チャンネル数を返します。
149
158
  * @ko 채널 수를 반환합니다.
150
159
  */
151
- getChannelCount() { return this.state.channelCount; }
160
+ getChannelCount() {
161
+ return this.state.channelCount;
162
+ }
152
163
  /**
153
164
  * Return a read-only view of channel positions in interleaved order.
154
165
  * @zh 返回交错声道位置顺序的只读视图。
155
166
  * @ja インターリーブ順のチャンネル位置の読み取り専用ビューを返します。
156
167
  * @ko 인터리브 순서의 채널 위치를 나타내는 읽기 전용 뷰를 반환합니다.
157
168
  */
158
- getChannelMap() { return this.state.channelMap; }
169
+ getChannelMap() {
170
+ return this.state.channelMap;
171
+ }
159
172
  /**
160
173
  * Return a copy of the total audio duration.
161
174
  * @zh 返回音频总时长副本。
162
175
  * @ja 音声全体の長さのコピーを返します。
163
176
  * @ko 오디오 전체 길이의 복사본을 반환합니다.
164
177
  */
165
- getDuration() { return new time_1.Time(this.state.duration); }
178
+ getDuration() {
179
+ return new time_1.Time(this.state.duration);
180
+ }
166
181
  /**
167
182
  * Asynchronously encode and save using the file extension to select the
168
183
  * format, returning whether it succeeded.
@@ -177,10 +192,12 @@ class SoundBuffer {
177
192
  const output = new output_sound_file_1.OutputSoundFile();
178
193
  try {
179
194
  const ok = await output.openFromFile(filename, this.getSampleRate(), this.getChannelCount(), this.getChannelMap());
180
- if (!ok)
195
+ if (!ok) {
181
196
  return false;
182
- if (this.state.samples.length)
197
+ }
198
+ if (this.state.samples.length) {
183
199
  await output.write(this.state.samples);
200
+ }
184
201
  return true;
185
202
  }
186
203
  finally {
@@ -194,20 +211,25 @@ class SoundBuffer {
194
211
  return this.queue.run(async () => {
195
212
  const file = new input_sound_file_1.InputSoundFile();
196
213
  try {
197
- const ok = typeof input === 'string' ? await file.openFromFile(input)
198
- : input instanceof Uint8Array ? await file.openFromMemory(input)
214
+ const ok = typeof input === 'string'
215
+ ? await file.openFromFile(input)
216
+ : input instanceof Uint8Array
217
+ ? await file.openFromMemory(input)
199
218
  : await file.openFromStream(input);
200
- if (!ok)
219
+ if (!ok) {
201
220
  return false;
221
+ }
202
222
  const count = file.getSampleCount();
203
- if (count > 0xffffffffn)
223
+ if (count > 0xffffffffn) {
204
224
  throw new RangeError('Sample buffer is too large');
225
+ }
205
226
  const data = new Int16Array(audio_native_1.audioNative.allocateAudioSamples(Number(count)));
206
227
  let position = 0;
207
228
  while (position < data.length) {
208
229
  const read = Number(await file.read(data.subarray(position)));
209
- if (!read)
230
+ if (!read) {
210
231
  return false;
232
+ }
211
233
  position += read;
212
234
  }
213
235
  return this.loadFromSamples(data, file.getChannelCount(), file.getSampleRate(), file.getChannelMap());
@@ -223,8 +245,9 @@ class SoundBuffer {
223
245
  try {
224
246
  const load = () => (0, audio_native_1.audioAsync)(callback => audio_native_1.audioNative.loadAudioBuffer(stream ? stream.handle : input, callback));
225
247
  const data = await (stream ? stream.run(load) : load());
226
- if (!data)
248
+ if (!data) {
227
249
  return false;
250
+ }
228
251
  this.state = view(audio_native_1.audioNative.commitAudioBuffer(this[audio_native_1.audioHandle], data));
229
252
  return true;
230
253
  }
@@ -17,18 +17,21 @@ class NativeReader extends sound_file_reader_1.SoundFileReader {
17
17
  return this.queue.run(async () => {
18
18
  const next = new audio_input_stream_1.AudioInputStream(stream);
19
19
  try {
20
- if (await stream.seek(0n) !== 0n)
20
+ if ((await stream.seek(0n)) !== 0n) {
21
21
  return undefined;
22
+ }
22
23
  const mapping = await next.run(() => (0, audio_native_1.audioAsync)(callback => audio_native_1.audioNative.openAudioReader(this.handle, next.handle, callback)));
23
- if (!mapping)
24
+ if (!mapping) {
24
25
  return undefined;
26
+ }
25
27
  this.stream?.close();
26
28
  this.stream = next;
27
29
  return new sound_file_reader_1.SoundFileReaderInfo(undefined, mapping);
28
30
  }
29
31
  finally {
30
- if (this.stream !== next)
32
+ if (this.stream !== next) {
31
33
  next.close();
34
+ }
32
35
  }
33
36
  });
34
37
  }
@@ -69,8 +72,9 @@ class NativeWriter extends sound_file_writer_1.SoundFileWriter {
69
72
  write(data) {
70
73
  (0, value_1.samples)(data);
71
74
  return this.queue.run(async () => {
72
- if (!this.opened)
75
+ if (!this.opened) {
73
76
  throw new Error('Writer is not open');
77
+ }
74
78
  await (0, audio_native_1.audioAsync)(callback => audio_native_1.audioNative.writeAudioWriter(this.handle, data, callback));
75
79
  });
76
80
  }
@@ -167,7 +171,9 @@ class SoundFileFactory {
167
171
  * @ko 파일을 탐지하여 일치하는 디코더를 생성합니다.
168
172
  * 일치 항목이 없으면 undefined이며, 사용 전 open을 호출해야 합니다.
169
173
  */
170
- static createReaderFromFilename(filename) { return this.createReader(filename); }
174
+ static createReaderFromFilename(filename) {
175
+ return this.createReader(filename);
176
+ }
171
177
  /**
172
178
  * Probe encoded audio bytes and create a matching decoder, or return
173
179
  * undefined if none matches.
@@ -177,7 +183,9 @@ class SoundFileFactory {
177
183
  * @ko 인코딩된 오디오 바이트를 탐지하여 일치하는 디코더를 생성합니다.
178
184
  * 일치 항목이 없으면 undefined를 반환합니다.
179
185
  */
180
- static createReaderFromMemory(data) { return this.createReader(data); }
186
+ static createReaderFromMemory(data) {
187
+ return this.createReader(data);
188
+ }
181
189
  /**
182
190
  * Probe stream contents and create a matching decoder, or return undefined
183
191
  * if none matches.
@@ -187,7 +195,9 @@ class SoundFileFactory {
187
195
  * @ko 스트림 내용을 탐지하여 일치하는 디코더를 생성합니다.
188
196
  * 일치 항목이 없으면 undefined를 반환합니다.
189
197
  */
190
- static createReaderFromStream(stream) { return this.createReader(stream); }
198
+ static createReaderFromStream(stream) {
199
+ return this.createReader(stream);
200
+ }
191
201
  /**
192
202
  * Create an encoder by filename; return undefined if none matches.
193
203
  * Calling open is still required before writing.
@@ -199,8 +209,9 @@ class SoundFileFactory {
199
209
  */
200
210
  static async createWriterFromFilename(filename) {
201
211
  const custom = await (0, audio_codec_registry_1.findAudioWriter)(filename);
202
- if (custom)
212
+ if (custom) {
203
213
  return custom;
214
+ }
204
215
  const handle = audio_native_1.audioNative.createAudioWriter(filename);
205
216
  return handle ? new NativeWriter(handle) : undefined;
206
217
  }
@@ -211,7 +222,8 @@ class SoundFileFactory {
211
222
  return custom.reader;
212
223
  }
213
224
  const bridge = typeof input === 'string' || input instanceof Uint8Array
214
- ? undefined : new audio_input_stream_1.AudioInputStream(input);
225
+ ? undefined
226
+ : new audio_input_stream_1.AudioInputStream(input);
215
227
  try {
216
228
  const create = () => (0, audio_native_1.audioAsync)(callback => audio_native_1.audioNative.createAudioReader(bridge ? bridge.handle : input, callback));
217
229
  const handle = await (bridge ? bridge.run(create) : create());
@@ -45,7 +45,9 @@ class SoundFileReaderInfo {
45
45
  * @ja 全チャンネルのサンプル総数。
46
46
  * @ko 모든 채널의 샘플 총수입니다.
47
47
  */
48
- get sampleCount() { return this.count[0]; }
48
+ get sampleCount() {
49
+ return this.count[0];
50
+ }
49
51
  /**
50
52
  * Set the total sample count as an unsigned 64-bit integer.
51
53
  * @zh 设置无符号 64 位样本总数。
@@ -53,7 +55,9 @@ class SoundFileReaderInfo {
53
55
  * @ko 샘플 총수를 부호 없는 64비트 정수로 설정합니다.
54
56
  */
55
57
  set sampleCount(value) {
56
- if (typeof value !== 'bigint' || value < 0n || value > 0xffffffffffffffffn) {
58
+ if (typeof value !== 'bigint' ||
59
+ value < 0n ||
60
+ value > 0xffffffffffffffffn) {
57
61
  throw new RangeError('Expected uint64 sample count');
58
62
  }
59
63
  this.count[0] = value;
@@ -64,35 +68,45 @@ class SoundFileReaderInfo {
64
68
  * @ja チャンネル数。
65
69
  * @ko 채널 수입니다.
66
70
  */
67
- get channelCount() { return this.channels[0]; }
71
+ get channelCount() {
72
+ return this.channels[0];
73
+ }
68
74
  /**
69
75
  * Set the number of channels.
70
76
  * @zh 设置声道数量。
71
77
  * @ja チャンネル数を設定します。
72
78
  * @ko 채널 수를 설정합니다.
73
79
  */
74
- set channelCount(value) { this.channels[0] = (0, value_1.unsigned)(value); }
80
+ set channelCount(value) {
81
+ this.channels[0] = (0, value_1.unsigned)(value);
82
+ }
75
83
  /**
76
84
  * Sample rate per channel, in Hz.
77
85
  * @zh 每声道采样率,单位为 Hz。
78
86
  * @ja チャンネルごとのサンプルレート。単位は Hz。
79
87
  * @ko 채널별 샘플 레이트이며 단위는 Hz입니다.
80
88
  */
81
- get sampleRate() { return this.rate[0]; }
89
+ get sampleRate() {
90
+ return this.rate[0];
91
+ }
82
92
  /**
83
93
  * Set the sample rate in Hz.
84
94
  * @zh 设置采样率,单位为 Hz。
85
95
  * @ja サンプルレートを Hz で設定します。
86
96
  * @ko 샘플 레이트를 Hz 단위로 설정합니다.
87
97
  */
88
- set sampleRate(value) { this.rate[0] = (0, value_1.unsigned)(value); }
98
+ set sampleRate(value) {
99
+ this.rate[0] = (0, value_1.unsigned)(value);
100
+ }
89
101
  /**
90
102
  * Read-only view of interleaved channel positions.
91
103
  * @zh 交错声道位置的只读视图。
92
104
  * @ja インターリーブチャンネル位置の読み取り専用ビュー。
93
105
  * @ko 인터리브 채널 위치의 읽기 전용 뷰입니다.
94
106
  */
95
- get channelMap() { return this.map; }
107
+ get channelMap() {
108
+ return this.map;
109
+ }
96
110
  /**
97
111
  * Copy the channel position mapping.
98
112
  * @zh 复制声道位置映射。