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,19 +68,25 @@ export class EffectProcessor {
68
68
  * @ja ブロック処理とキューのアンダーラン・オーバーランの統計を返します。
69
69
  * @ko 블록 처리 및 큐 언더런과 오버런 통계를 반환합니다.
70
70
  */
71
- getWorkerStats(): AudioWorkerStats { return this.session.getStats(); }
71
+ getWorkerStats(): AudioWorkerStats {
72
+ return this.session.getStats();
73
+ }
72
74
  /**
73
75
  * Return the Worker error, or undefined if there is none.
74
76
  * @zh 返回 Worker 错误;没有错误时为 undefined。
75
77
  * @ja Worker のエラーを返します。エラーがなければ undefined。
76
78
  * @ko Worker 오류를 반환합니다. 오류가 없으면 undefined입니다.
77
79
  */
78
- getWorkerError(): Error | undefined { return this.session.error; }
80
+ getWorkerError(): Error | undefined {
81
+ return this.session.error;
82
+ }
79
83
  /**
80
84
  * Asynchronously close the effect Worker session.
81
85
  * @zh 异步关闭效果 Worker 会话。
82
86
  * @ja エフェクト Worker セッションを非同期で閉じます。
83
87
  * @ko 효과 Worker 세션을 비동기로 닫습니다.
84
88
  */
85
- close(): Promise<void> { return this.session.close(); }
89
+ close(): Promise<void> {
90
+ return this.session.close();
91
+ }
86
92
  }
@@ -1,5 +1,9 @@
1
1
  import {
2
- audioNative, audioHandle, audioAsync, AudioQueue, type AudioHandle,
2
+ audioNative,
3
+ audioHandle,
4
+ audioAsync,
5
+ AudioQueue,
6
+ type AudioHandle,
3
7
  type AudioFileMapping,
4
8
  } from '../internal/audio-native';
5
9
  import { Time } from '../system/time';
@@ -28,7 +32,9 @@ export class InputSoundFile {
28
32
  private u32: Uint32Array;
29
33
  private channelMap: Int32Array;
30
34
  private stream?: AudioInputStream;
31
- private custom?: NonNullable<Awaited<ReturnType<typeof findAudioReaderInput>>>;
35
+ private custom?: NonNullable<
36
+ Awaited<ReturnType<typeof findAudioReaderInput>>
37
+ >;
32
38
  private customMetadata?: AudioHandle<'fileMetadata'>;
33
39
 
34
40
  /**
@@ -52,14 +58,18 @@ export class InputSoundFile {
52
58
  * @ja 音声ファイルを非同期で開いて形式情報を読み取り、成功したかどうかを返します。
53
59
  * @ko 오디오 파일을 비동기로 열고 형식 정보를 읽어 성공 여부를 반환합니다.
54
60
  */
55
- openFromFile(filename: string): Promise<boolean> { return this.open(filename); }
61
+ openFromFile(filename: string): Promise<boolean> {
62
+ return this.open(filename);
63
+ }
56
64
  /**
57
65
  * Asynchronously open encoded audio bytes, returning whether it succeeded.
58
66
  * @zh 异步打开编码音频字节,返回是否成功。
59
67
  * @ja エンコード済み音声バイトを非同期で開き、成功したかどうかを返します。
60
68
  * @ko 인코딩된 오디오 바이트를 비동기로 열고 성공 여부를 반환합니다.
61
69
  */
62
- openFromMemory(data: Uint8Array): Promise<boolean> { return this.open(data); }
70
+ openFromMemory(data: Uint8Array): Promise<boolean> {
71
+ return this.open(data);
72
+ }
63
73
  /**
64
74
  * Asynchronously open a seekable stream, retaining the data source reference
65
75
  * during reading.
@@ -76,51 +86,67 @@ export class InputSoundFile {
76
86
  * @ja 全チャンネルのサンプル総数を返します。
77
87
  * @ko 모든 채널의 샘플 총수를 반환합니다.
78
88
  */
79
- getSampleCount(): bigint { return this.u64[0]; }
89
+ getSampleCount(): bigint {
90
+ return this.u64[0];
91
+ }
80
92
  /**
81
93
  * Return the current sample offset, including all interleaved channels.
82
94
  * @zh 返回当前样本偏移,包含所有交错声道。
83
95
  * @ja 全インターリーブチャンネルを含む現在のサンプルオフセットを返します。
84
96
  * @ko 모든 인터리브 채널을 포함하는 현재 샘플 오프셋을 반환합니다.
85
97
  */
86
- getSampleOffset(): bigint { return this.u64[1]; }
98
+ getSampleOffset(): bigint {
99
+ return this.u64[1];
100
+ }
87
101
  /**
88
102
  * Return the total audio duration.
89
103
  * @zh 返回音频总时长。
90
104
  * @ja 音声全体の長さを返します。
91
105
  * @ko 오디오의 전체 길이를 반환합니다.
92
106
  */
93
- getDuration(): Time { return new Time(this.i64[2]); }
107
+ getDuration(): Time {
108
+ return new Time(this.i64[2]);
109
+ }
94
110
  /**
95
111
  * Return the time corresponding to the current decoding position.
96
112
  * @zh 返回当前解码位置对应的时间。
97
113
  * @ja 現在のデコード位置に対応する時刻を返します。
98
114
  * @ko 현재 디코딩 위치에 해당하는 시간을 반환합니다.
99
115
  */
100
- getTimeOffset(): Time { return new Time(this.i64[3]); }
116
+ getTimeOffset(): Time {
117
+ return new Time(this.i64[3]);
118
+ }
101
119
  /**
102
120
  * Return the sample rate per channel, in Hz.
103
121
  * @zh 返回每声道采样率,单位为 Hz。
104
122
  * @ja チャンネルごとのサンプルレートを Hz で返します。
105
123
  * @ko 채널별 샘플 레이트를 Hz 단위로 반환합니다.
106
124
  */
107
- getSampleRate(): number { return this.u32[10]; }
125
+ getSampleRate(): number {
126
+ return this.u32[10];
127
+ }
108
128
  /**
109
129
  * Return the number of channels.
110
130
  * @zh 返回声道数。
111
131
  * @ja チャンネル数を返します。
112
132
  * @ko 채널 수를 반환합니다.
113
133
  */
114
- getChannelCount(): number { return this.u32[11]; }
134
+ getChannelCount(): number {
135
+ return this.u32[11];
136
+ }
115
137
  /**
116
138
  * Return the position mapping of interleaved channels.
117
139
  * @zh 返回交错声道的位置映射。
118
140
  * @ja インターリーブチャンネルの位置マッピングを返します。
119
141
  * @ko 인터리브 채널의 위치 매핑을 반환합니다.
120
142
  */
121
- getChannelMap(): ChannelMap { return this.channelMap; }
143
+ getChannelMap(): ChannelMap {
144
+ return this.channelMap;
145
+ }
122
146
  /** @internal */
123
- [cancelAudioInput](): void { this.stream?.close(); }
147
+ [cancelAudioInput](): void {
148
+ this.stream?.close();
149
+ }
124
150
  /**
125
151
  * Asynchronously decode into data, returning the actual number of samples
126
152
  * written; return 0n at the end. Do not modify the buffer before completion.
@@ -134,16 +160,24 @@ export class InputSoundFile {
134
160
  samples(data);
135
161
  return this.queue.run(async () => {
136
162
  if (this.custom) {
137
- const count = data.length ? await this.custom.reader.read(data) : 0n;
138
- if (typeof count !== 'bigint' || count < 0n ||
139
- count > BigInt(data.length)) {
163
+ const count = data.length
164
+ ? await this.custom.reader.read(data)
165
+ : 0n;
166
+ if (
167
+ typeof count !== 'bigint' ||
168
+ count < 0n ||
169
+ count > BigInt(data.length)
170
+ ) {
140
171
  throw new RangeError('Reader returned an invalid sample count');
141
172
  }
142
173
  audioNative.updateAudioFileMetadata(this.customMetadata!, 0, count);
143
174
  return count;
144
175
  }
145
- await this.runStream(() => audioAsync<void>(callback =>
146
- audioNative.readAudioInput(this[audioHandle], data, callback)));
176
+ await this.runStream(() =>
177
+ audioAsync<void>(callback =>
178
+ audioNative.readAudioInput(this[audioHandle], data, callback),
179
+ ),
180
+ );
147
181
  return this.u64[4];
148
182
  });
149
183
  }
@@ -160,17 +194,30 @@ export class InputSoundFile {
160
194
  const time = offset instanceof Time;
161
195
  const value = time ? duration(offset) : offset;
162
196
  if (typeof value !== 'bigint' || (!time && value < 0n)) {
163
- throw new RangeError('Expected a non-negative sample offset or a Time');
197
+ throw new RangeError(
198
+ 'Expected a non-negative sample offset or a Time',
199
+ );
164
200
  }
165
201
  return this.queue.run(async () => {
166
202
  if (this.custom) {
167
- audioNative.updateAudioFileMetadata(this.customMetadata!,
168
- time ? 2 : 1, value);
203
+ audioNative.updateAudioFileMetadata(
204
+ this.customMetadata!,
205
+ time ? 2 : 1,
206
+ value,
207
+ );
169
208
  await this.custom.reader.seek(this.u64[4]);
170
209
  audioNative.updateAudioFileMetadata(this.customMetadata!, 3);
171
210
  } else {
172
- await this.runStream(() => audioAsync<void>(callback =>
173
- audioNative.seekAudioInput(this[audioHandle], value, time, callback)));
211
+ await this.runStream(() =>
212
+ audioAsync<void>(callback =>
213
+ audioNative.seekAudioInput(
214
+ this[audioHandle],
215
+ value,
216
+ time,
217
+ callback,
218
+ ),
219
+ ),
220
+ );
174
221
  }
175
222
  });
176
223
  }
@@ -183,8 +230,11 @@ export class InputSoundFile {
183
230
  */
184
231
  close(): Promise<void> {
185
232
  return this.queue.run(async () => {
186
- this.map(await audioAsync<AudioFileMapping>(callback =>
187
- audioNative.closeAudioInput(this[audioHandle], callback)));
233
+ this.map(
234
+ await audioAsync<AudioFileMapping>(callback =>
235
+ audioNative.closeAudioInput(this[audioHandle], callback),
236
+ ),
237
+ );
188
238
  this.stream?.close();
189
239
  this.stream = undefined;
190
240
  await this.releaseCustom();
@@ -203,7 +253,11 @@ export class InputSoundFile {
203
253
  const custom = this.custom;
204
254
  this.custom = undefined;
205
255
  this.customMetadata = undefined;
206
- try { await custom?.reader.close(); } finally { await custom?.owned?.close(); }
256
+ try {
257
+ await custom?.reader.close();
258
+ } finally {
259
+ await custom?.owned?.close();
260
+ }
207
261
  }
208
262
  private open(input: string | Uint8Array | InputStream): Promise<boolean> {
209
263
  return this.queue.run(async () => {
@@ -212,13 +266,20 @@ export class InputSoundFile {
212
266
  let opened = false;
213
267
  try {
214
268
  const info = await custom.reader.open(custom.stream);
215
- if (info === undefined) return false;
269
+ if (info === undefined) {
270
+ return false;
271
+ }
216
272
  if (!(info instanceof SoundFileReaderInfo)) {
217
- throw new TypeError('Reader.open must return SoundFileReader.Info');
273
+ throw new TypeError(
274
+ 'Reader.open must return SoundFileReader.Info',
275
+ );
218
276
  }
219
- const mapping = audioNative.createAudioFileMetadata(info[audioHandle]);
277
+ const mapping = audioNative.createAudioFileMetadata(
278
+ info[audioHandle],
279
+ );
220
280
  await audioAsync<AudioFileMapping>(callback =>
221
- audioNative.closeAudioInput(this[audioHandle], callback));
281
+ audioNative.closeAudioInput(this[audioHandle], callback),
282
+ );
222
283
  await this.releaseCustom();
223
284
  this.stream?.close();
224
285
  this.stream = undefined;
@@ -229,19 +290,28 @@ export class InputSoundFile {
229
290
  return true;
230
291
  } finally {
231
292
  if (!opened) {
232
- try { await custom.reader.close(); } finally {
293
+ try {
294
+ await custom.reader.close();
295
+ } finally {
233
296
  await custom.owned?.close();
234
297
  }
235
298
  }
236
299
  }
237
300
  }
238
- const stream = typeof input === 'string' || input instanceof Uint8Array
239
- ? undefined : new AudioInputStream(input);
301
+ const stream =
302
+ typeof input === 'string' || input instanceof Uint8Array
303
+ ? undefined
304
+ : new AudioInputStream(input);
240
305
  let opened = false;
241
306
  try {
242
- const load = () => audioAsync<AudioFileMapping | undefined>(callback =>
243
- audioNative.openAudioInput(this[audioHandle],
244
- stream ? stream.handle : input as string | Uint8Array, callback));
307
+ const load = () =>
308
+ audioAsync<AudioFileMapping | undefined>(callback =>
309
+ audioNative.openAudioInput(
310
+ this[audioHandle],
311
+ stream ? stream.handle : (input as string | Uint8Array),
312
+ callback,
313
+ ),
314
+ );
245
315
  const mapping = await (stream ? stream.run(load) : load());
246
316
  if (mapping) {
247
317
  await this.releaseCustom();
@@ -252,7 +322,9 @@ export class InputSoundFile {
252
322
  }
253
323
  return opened;
254
324
  } finally {
255
- if (!opened) stream?.close();
325
+ if (!opened) {
326
+ stream?.close();
327
+ }
256
328
  }
257
329
  });
258
330
  }
@@ -5,13 +5,20 @@ import type { ReadonlyValue as R } from '../internal/value-storage';
5
5
  import { Cone, type ConeInput, float, vector, angle } from './value';
6
6
 
7
7
  export { Cone } from './value';
8
- let state: { handle: ReturnType<typeof audioNative.createAudioListener>['handle'];
9
- values: Float32Array } | undefined;
8
+ let state:
9
+ | {
10
+ handle: ReturnType<typeof audioNative.createAudioListener>['handle'];
11
+ values: Float32Array;
12
+ }
13
+ | undefined;
10
14
 
11
15
  function listener() {
12
16
  if (!state) {
13
17
  const mapping = audioNative.createAudioListener();
14
- state = { handle: mapping.handle, values: new Float32Array(mapping.buffer) };
18
+ state = {
19
+ handle: mapping.handle,
20
+ values: new Float32Array(mapping.buffer),
21
+ };
15
22
  }
16
23
  return state;
17
24
  }
@@ -57,49 +64,63 @@ export function getGlobalVolume(): number {
57
64
  * @ja リスナーの 3D 位置のコピーを返します。
58
65
  * @ko 리스너의 3차원 위치 복사본을 반환합니다.
59
66
  */
60
- export function getPosition(): Vector3f { return getVector(1); }
67
+ export function getPosition(): Vector3f {
68
+ return getVector(1);
69
+ }
61
70
  /**
62
71
  * Set the listener's position in world coordinates.
63
72
  * @zh 设置监听者的世界坐标位置。
64
73
  * @ja リスナーのワールド座標での位置を設定します。
65
74
  * @ko 리스너의 월드 좌표 위치를 설정합니다.
66
75
  */
67
- export function setPosition(value: R<Vector3f>): void { setVector(1, value); }
76
+ export function setPosition(value: R<Vector3f>): void {
77
+ setVector(1, value);
78
+ }
68
79
  /**
69
80
  * Return a copy of the listener's facing direction.
70
81
  * @zh 返回监听者的朝向副本。
71
82
  * @ja リスナーの向きのコピーを返します。
72
83
  * @ko 리스너가 향하는 방향의 복사본을 반환합니다.
73
84
  */
74
- export function getDirection(): Vector3f { return getVector(4); }
85
+ export function getDirection(): Vector3f {
86
+ return getVector(4);
87
+ }
75
88
  /**
76
89
  * Set the listener's forward direction.
77
90
  * @zh 设置监听者的正前方方向。
78
91
  * @ja リスナーの前方方向を設定します。
79
92
  * @ko 리스너의 정면 방향을 설정합니다.
80
93
  */
81
- export function setDirection(value: R<Vector3f>): void { setVector(4, value); }
94
+ export function setDirection(value: R<Vector3f>): void {
95
+ setVector(4, value);
96
+ }
82
97
  /**
83
98
  * Return a copy of the listener's velocity.
84
99
  * @zh 返回监听者的速度副本。
85
100
  * @ja リスナーの速度のコピーを返します。
86
101
  * @ko 리스너 속도의 복사본을 반환합니다.
87
102
  */
88
- export function getVelocity(): Vector3f { return getVector(7); }
103
+ export function getVelocity(): Vector3f {
104
+ return getVector(7);
105
+ }
89
106
  /**
90
107
  * Set the listener's velocity for the Doppler effect, in position units/second.
91
108
  * @zh 设置监听者的速度,用于多普勒效应,单位为位置单位/秒。
92
109
  * @ja ドップラー効果用のリスナー速度を設定します。単位は位置単位/秒です。
93
110
  * @ko 도플러 효과에 사용할 리스너 속도를 설정합니다. 단위는 위치 단위/초입니다.
94
111
  */
95
- export function setVelocity(value: R<Vector3f>): void { setVector(7, value); }
112
+ export function setVelocity(value: R<Vector3f>): void {
113
+ setVector(7, value);
114
+ }
96
115
  /**
97
116
  * Return a copy of the listener's up direction.
98
117
  * @zh 返回监听者上方方向的副本。
99
118
  * @ja リスナーの上方向のコピーを返します。
100
119
  * @ko 리스너 위쪽 방향의 복사본을 반환합니다.
101
120
  */
102
- export function getUpVector(): Vector3f { return getVector(10); }
121
+ export function getUpVector(): Vector3f {
122
+ return getVector(10);
123
+ }
103
124
  /**
104
125
  * Set the listener's up direction, which defines orientation together with the
105
126
  * forward direction.
@@ -107,7 +128,9 @@ export function getUpVector(): Vector3f { return getVector(10); }
107
128
  * @ja リスナーの上方向を設定します。前方方向とともに空間内の向きを決めます。
108
129
  * @ko 리스너의 위쪽 방향을 설정합니다. 정면 방향과 함께 공간상의 방향을 결정합니다.
109
130
  */
110
- export function setUpVector(value: R<Vector3f>): void { setVector(10, value); }
131
+ export function setUpVector(value: R<Vector3f>): void {
132
+ setVector(10, value);
133
+ }
111
134
  /**
112
135
  * Copy directional cone parameters and update the native listener.
113
136
  * @zh 复制方向锥参数并更新原生监听者。
@@ -131,6 +154,9 @@ export function setCone(value: Readonly<ConeInput>): void {
131
154
  export function getCone(): Cone {
132
155
  const { handle, values } = listener();
133
156
  audioNative.audioListenerField(handle, 13, false);
134
- return new Cone({ innerAngle: radians(values[13]), outerAngle: radians(values[14]),
135
- outerGain: values[15] });
157
+ return new Cone({
158
+ innerAngle: radians(values[13]),
159
+ outerAngle: radians(values[14]),
160
+ outerGain: values[15],
161
+ });
136
162
  }