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
@@ -21,7 +21,8 @@ class AudioMusicPump {
21
21
  this.rejectReady = reject;
22
22
  });
23
23
  void this.ready.catch(() => { });
24
- this.done = Promise.resolve().then(() => this.run(token))
24
+ this.done = Promise.resolve()
25
+ .then(() => this.run(token))
25
26
  .catch((error) => {
26
27
  if (!this.closed || !(0, audio_input_stream_1.isAudioInputCancellation)(error)) {
27
28
  this.failure ?? (this.failure = error instanceof Error ? error : new Error(String(error)));
@@ -31,11 +32,17 @@ class AudioMusicPump {
31
32
  .finally(() => this.resolveReady(false));
32
33
  }
33
34
  /** 最近的解码或用户回调错误。 */
34
- get error() { return this.failure; }
35
+ get error() {
36
+ return this.failure;
37
+ }
35
38
  /** 读取 Native 队列的累计统计。 */
36
39
  getStats() {
37
40
  const fields = new BigUint64Array(audio_native_1.audioNative.audioWorkerStats(this.handle));
38
- return { underruns: fields[0], overruns: fields[1], processed: fields[2] };
41
+ return {
42
+ underruns: fields[0],
43
+ overruns: fields[1],
44
+ processed: fields[2],
45
+ };
39
46
  }
40
47
  /** 请求关闭但不等待当前用户回调,允许在回调内安全调用。 */
41
48
  requestClose() {
@@ -48,8 +55,9 @@ class AudioMusicPump {
48
55
  async close() {
49
56
  this.requestClose();
50
57
  await this.done;
51
- if (this.failure)
58
+ if (this.failure) {
52
59
  throw this.failure;
60
+ }
53
61
  }
54
62
  /** 默认解码实现;只能由当前会话的 onGetData 调用。 */
55
63
  async onGetData(chunk) {
@@ -62,41 +70,54 @@ class AudioMusicPump {
62
70
  const position = this.file.getSampleOffset();
63
71
  const end = counts[3] + counts[4];
64
72
  let size = chunk.samples.length;
65
- if (fields[4] && counts[4] && position <= end &&
66
- position + BigInt(size) > end)
73
+ if (fields[4] &&
74
+ counts[4] &&
75
+ position <= end &&
76
+ position + BigInt(size) > end) {
67
77
  size = Number(end - position);
78
+ }
68
79
  let count;
69
80
  try {
70
81
  count = await this.file.read(chunk.samples.subarray(0, size));
71
82
  }
72
83
  catch (error) {
73
- if (!this.closed || !(0, audio_input_stream_1.isAudioInputCancellation)(error))
84
+ if (!this.closed || !(0, audio_input_stream_1.isAudioInputCancellation)(error)) {
74
85
  throw error;
86
+ }
75
87
  chunk.sampleCount = 0;
76
88
  return false;
77
89
  }
78
90
  const next = position + count;
79
91
  const loopEnd = fields[4] !== 0 && counts[4] !== 0n && next === end;
80
92
  chunk.sampleCount = Number(count);
81
- this.loopOffset = loopEnd ? counts[3] : next >= counts[2] ? 0n : undefined;
93
+ this.loopOffset = loopEnd
94
+ ? counts[3]
95
+ : next >= counts[2]
96
+ ? 0n
97
+ : undefined;
82
98
  return count !== 0n && next < counts[2] && !loopEnd;
83
99
  }
84
100
  /** 默认定位文件;时间以微秒表示。 */
85
101
  async onSeek(offset) {
86
- if (this.closed)
102
+ if (this.closed) {
87
103
  return;
104
+ }
88
105
  const target = this.seekTarget?.time === offset.asMicroseconds()
89
- ? this.seekTarget.sample : offset;
106
+ ? this.seekTarget.sample
107
+ : offset;
90
108
  try {
91
109
  await this.file.seek(target);
92
110
  }
93
111
  catch (error) {
94
- if (!this.closed || !(0, audio_input_stream_1.isAudioInputCancellation)(error))
112
+ if (!this.closed || !(0, audio_input_stream_1.isAudioInputCancellation)(error)) {
95
113
  throw error;
114
+ }
96
115
  }
97
116
  }
98
117
  /** 返回默认文件解码的下一轮交错样本位置。 */
99
- onLoop() { return this.loopOffset; }
118
+ onLoop() {
119
+ return this.loopOffset;
120
+ }
100
121
  /** 用户回调错误独立于取消状态保留,并进入 ready/close 错误通道。 */
101
122
  async dispatch(callback) {
102
123
  try {
@@ -121,18 +142,22 @@ class AudioMusicPump {
121
142
  try {
122
143
  for (;;) {
123
144
  const operation = audio_native_1.audioNative.pollAudioWorker(mapping.handle);
124
- if (operation === -3)
145
+ if (operation === -3) {
125
146
  break;
147
+ }
126
148
  if (operation === -2) {
127
149
  const offset = new time_1.Time(times[0]);
128
- this.seekTarget = times[5] >= 0n
129
- ? { time: times[0], sample: times[5] } : undefined;
150
+ this.seekTarget =
151
+ times[5] >= 0n
152
+ ? { time: times[0], sample: times[5] }
153
+ : undefined;
130
154
  try {
131
155
  if (this.callbacks) {
132
156
  await this.dispatch(() => this.callbacks.onSeek(offset, this));
133
157
  }
134
- else
158
+ else {
135
159
  await this.onSeek(offset);
160
+ }
136
161
  }
137
162
  finally {
138
163
  this.seekTarget = undefined;
@@ -142,8 +167,9 @@ class AudioMusicPump {
142
167
  if (operation === -1) {
143
168
  await new Promise(resolve => {
144
169
  this.timer = setTimeout(resolve, 2);
145
- if (this.primed && !this.closed)
170
+ if (this.primed && !this.closed) {
146
171
  this.timer.unref();
172
+ }
147
173
  });
148
174
  this.timer = undefined;
149
175
  continue;
@@ -154,26 +180,34 @@ class AudioMusicPump {
154
180
  const more = await (this.callbacks
155
181
  ? this.dispatch(() => this.callbacks.onGetData(chunk, this))
156
182
  : this.onGetData(chunk));
157
- if (this.closed)
183
+ if (this.closed) {
158
184
  break;
185
+ }
159
186
  if (typeof more !== 'boolean') {
160
187
  throw new TypeError('onGetData must return a boolean');
161
188
  }
162
189
  if (chunk.samples !== samples) {
163
190
  throw new TypeError('Fill the provided native sample buffer');
164
191
  }
165
- if (!Number.isInteger(chunk.sampleCount) || chunk.sampleCount < 0 ||
192
+ if (!Number.isInteger(chunk.sampleCount) ||
193
+ chunk.sampleCount < 0 ||
166
194
  chunk.sampleCount > samples.length) {
167
195
  throw new RangeError('Invalid stream sample count');
168
196
  }
169
197
  fields[2] = chunk.sampleCount;
170
198
  fields[3] = +more;
171
- const loop = more ? undefined : await (this.callbacks
172
- ? this.dispatch(() => this.callbacks.onLoop(this)) : this.onLoop());
173
- if (this.closed)
199
+ const loop = more
200
+ ? undefined
201
+ : await (this.callbacks
202
+ ? this.dispatch(() => this.callbacks.onLoop(this))
203
+ : this.onLoop());
204
+ if (this.closed) {
174
205
  break;
175
- if (loop !== undefined && (typeof loop !== 'bigint' ||
176
- loop < 0n || loop > 0x7fffffffffffffffn)) {
206
+ }
207
+ if (loop !== undefined &&
208
+ (typeof loop !== 'bigint' ||
209
+ loop < 0n ||
210
+ loop > 0x7fffffffffffffffn)) {
177
211
  throw new RangeError('Invalid loop sample offset');
178
212
  }
179
213
  times[1] = loop ?? -1n;
@@ -9,13 +9,15 @@ const invocation = new node_async_hooks_1.AsyncLocalStorage();
9
9
  function currentRecorderSession(recorder) {
10
10
  const context = invocation.getStore();
11
11
  return context?.active && context.session.recorder === recorder
12
- ? context.session : undefined;
12
+ ? context.session
13
+ : undefined;
13
14
  }
14
15
  exports.currentRecorderSession = currentRecorderSession;
15
16
  /** 取得 super 默认实现对应的会话;拒绝过期或阶段不匹配的异步调用。 */
16
17
  function recorderCallbackSession(recorder, phase) {
17
18
  const context = invocation.getStore();
18
- if (!context?.active || context.phase !== phase ||
19
+ if (!context?.active ||
20
+ context.phase !== phase ||
19
21
  context.session.recorder !== recorder) {
20
22
  throw new Error(`${phase} must run inside its active Recorder callback`);
21
23
  }
@@ -87,8 +89,9 @@ class AudioRecorderSession {
87
89
  this.draining = true;
88
90
  this.timer?.ref();
89
91
  await this.done;
90
- if (this.error)
92
+ if (this.error) {
91
93
  throw this.error;
94
+ }
92
95
  }
93
96
  /** 停止设备并等待本会话完整结束。 */
94
97
  async stop() {
@@ -98,7 +101,11 @@ class AudioRecorderSession {
98
101
  /** 返回 Native 队列统计,processed 的单位为交错样本。 */
99
102
  getStats() {
100
103
  const fields = new BigUint64Array(audio_native_1.audioNative.audioWorkerStats(this.handle));
101
- return { underruns: fields[0], overruns: fields[1], processed: fields[2] };
104
+ return {
105
+ underruns: fields[0],
106
+ overruns: fields[1],
107
+ processed: fields[2],
108
+ };
102
109
  }
103
110
  /** 保留首个错误,避免清理异常覆盖原始回调错误。 */
104
111
  fail(error) {
@@ -131,17 +138,20 @@ class AudioRecorderSession {
131
138
  started = await this.devices.run(() => (0, audio_native_1.audioAsync)(callback => audio_native_1.audioNative.startAudioRecorder(this.recorder, callback)));
132
139
  }
133
140
  resolveReady(started && !this.stopping);
134
- if (!started)
141
+ if (!started) {
135
142
  return;
143
+ }
136
144
  for (;;) {
137
145
  const status = audio_native_1.audioNative.pollAudioWorker(this.handle);
138
- if (status === -3)
146
+ if (status === -3) {
139
147
  break;
148
+ }
140
149
  if (status === -1) {
141
150
  await new Promise(resolve => {
142
151
  this.timer = setTimeout(resolve, 1);
143
- if (!this.draining)
152
+ if (!this.draining) {
144
153
  this.timer.unref();
154
+ }
145
155
  });
146
156
  this.timer = undefined;
147
157
  continue;
@@ -11,25 +11,36 @@ class AudioWorkerSession {
11
11
  constructor(handle, token, kind, options, context, onStop) {
12
12
  this.handle = handle;
13
13
  this.failure = {};
14
- const module = options.module instanceof URL ? options.module.href
14
+ const module = options.module instanceof URL
15
+ ? options.module.href
15
16
  : (0, node_url_1.pathToFileURL)((0, node_path_1.resolve)(options.module)).href;
16
17
  const worker = new node_worker_threads_1.Worker((0, node_path_1.join)(__dirname, 'audio-worker.js'), {
17
- workerData: { token, kind, module, exportName: options.exportName,
18
- data: options.data, context },
18
+ workerData: {
19
+ token,
20
+ kind,
21
+ module,
22
+ exportName: options.exportName,
23
+ data: options.data,
24
+ context,
25
+ },
19
26
  });
20
27
  this.worker = worker;
21
28
  const failure = this.failure;
22
29
  let completed = false;
23
30
  this.ready = new Promise((resolveReady, reject) => {
24
31
  worker.on('message', (message) => {
25
- if (message.type === 'closed')
32
+ if (message.type === 'closed') {
26
33
  completed = true;
27
- if (message.type === 'ready')
34
+ }
35
+ if (message.type === 'ready') {
28
36
  resolveReady(true);
29
- if (message.type === 'aborted')
37
+ }
38
+ if (message.type === 'aborted') {
30
39
  resolveReady(false);
31
- if (message.type === 'stop')
40
+ }
41
+ if (message.type === 'stop') {
32
42
  onStop?.();
43
+ }
33
44
  if (message.type === 'error') {
34
45
  failure.error = new error_1.SFMLError(message.error ?? 'Audio worker failed');
35
46
  audio_native_1.audioNative.closeAudioWorker(handle);
@@ -62,10 +73,16 @@ class AudioWorkerSession {
62
73
  });
63
74
  cleanup.register(this, handle, this);
64
75
  }
65
- get error() { return this.failure.error; }
76
+ get error() {
77
+ return this.failure.error;
78
+ }
66
79
  getStats() {
67
80
  const fields = new BigUint64Array(audio_native_1.audioNative.audioWorkerStats(this.handle));
68
- return { underruns: fields[0], overruns: fields[1], processed: fields[2] };
81
+ return {
82
+ underruns: fields[0],
83
+ overruns: fields[1],
84
+ processed: fields[2],
85
+ };
69
86
  }
70
87
  async close() {
71
88
  cleanup.unregister(this);
@@ -75,8 +92,9 @@ class AudioWorkerSession {
75
92
  async drain() {
76
93
  this.worker.ref();
77
94
  await this.done;
78
- if (this.error)
95
+ if (this.error) {
79
96
  throw this.error;
97
+ }
80
98
  }
81
99
  }
82
100
  exports.AudioWorkerSession = AudioWorkerSession;
@@ -13,12 +13,15 @@ async function run() {
13
13
  const handle = mapping.handle;
14
14
  const fields = new Int32Array(mapping.fields);
15
15
  const time = new BigInt64Array(mapping.time);
16
- const pcm = setup.kind === 'effect' ? []
16
+ const pcm = setup.kind === 'effect'
17
+ ? []
17
18
  : mapping.input.map(buffer => new Int16Array(buffer));
18
19
  const input = setup.kind === 'effect'
19
- ? mapping.input.map(buffer => new Float32Array(buffer)) : [];
20
+ ? mapping.input.map(buffer => new Float32Array(buffer))
21
+ : [];
20
22
  const output = setup.kind === 'effect'
21
- ? mapping.output.map(buffer => new Float32Array(buffer)) : [];
23
+ ? mapping.output.map(buffer => new Float32Array(buffer))
24
+ : [];
22
25
  let callbacks = {};
23
26
  try {
24
27
  const module = await importModule(setup.module);
@@ -26,28 +29,33 @@ async function run() {
26
29
  if (typeof factory !== 'function') {
27
30
  throw new TypeError('Audio worker export must be a factory');
28
31
  }
29
- callbacks = await factory(setup.context, setup.data);
32
+ callbacks = (await factory(setup.context, setup.data));
30
33
  const required = setup.kind === 'stream'
31
- ? ['onGetData', 'onSeek'] : setup.kind === 'recorder'
32
- ? ['onProcessSamples'] : ['process'];
34
+ ? ['onGetData', 'onSeek']
35
+ : setup.kind === 'recorder'
36
+ ? ['onProcessSamples']
37
+ : ['process'];
33
38
  for (const name of required) {
34
39
  if (typeof callbacks[name] !== 'function') {
35
40
  throw new TypeError(`Audio worker requires ${name}()`);
36
41
  }
37
42
  }
38
- if (setup.kind === 'recorder' && callbacks.onStart &&
39
- !await callbacks.onStart()) {
43
+ if (setup.kind === 'recorder' &&
44
+ callbacks.onStart &&
45
+ !(await callbacks.onStart())) {
40
46
  node_worker_threads_1.parentPort.postMessage({ type: 'aborted' });
41
47
  return;
42
48
  }
43
49
  let ready = setup.kind !== 'stream';
44
- if (ready)
50
+ if (ready) {
45
51
  node_worker_threads_1.parentPort.postMessage({ type: 'ready' });
52
+ }
46
53
  let primed = 0;
47
54
  for (;;) {
48
55
  const operation = audio_native_1.audioNative.pollAudioWorker(handle);
49
- if (operation === -3)
56
+ if (operation === -3) {
50
57
  break;
58
+ }
51
59
  if (operation === -2) {
52
60
  await callbacks.onSeek(new time_1.Time(time[0]));
53
61
  continue;
@@ -65,7 +73,8 @@ async function run() {
65
73
  if (chunk.samples !== pcm[fields[0]]) {
66
74
  throw new TypeError('Fill the provided native sample buffer');
67
75
  }
68
- if (!Number.isInteger(chunk.sampleCount) || chunk.sampleCount < 0 ||
76
+ if (!Number.isInteger(chunk.sampleCount) ||
77
+ chunk.sampleCount < 0 ||
69
78
  chunk.sampleCount > chunk.samples.length) {
70
79
  throw new RangeError('Invalid stream sample count');
71
80
  }
@@ -73,8 +82,10 @@ async function run() {
73
82
  fields[3] = +more;
74
83
  if (!more) {
75
84
  const loop = callbacks.onLoop ? await callbacks.onLoop() : 0n;
76
- if (loop !== undefined && (typeof loop !== 'bigint' || loop < 0n ||
77
- loop > 0x7fffffffffffffffn)) {
85
+ if (loop !== undefined &&
86
+ (typeof loop !== 'bigint' ||
87
+ loop < 0n ||
88
+ loop > 0x7fffffffffffffffn)) {
78
89
  throw new RangeError('Invalid loop sample offset');
79
90
  }
80
91
  time[1] = loop ?? -1n;
@@ -97,12 +108,14 @@ async function run() {
97
108
  }
98
109
  else {
99
110
  const channels = fields[3];
100
- const result = await callbacks.process(fields[5] ? null
111
+ const result = await callbacks.process(fields[5]
112
+ ? null
101
113
  : input[fields[0]].subarray(fields[4], fields[4] + fields[2]), fields[7], output[fields[1]].subarray(0, fields[6] * channels), fields[6], channels);
102
114
  if (result) {
103
115
  if (!Number.isInteger(result.inputFrameCount) ||
104
116
  !Number.isInteger(result.outputFrameCount) ||
105
- result.inputFrameCount < 0 || result.inputFrameCount > fields[7] ||
117
+ result.inputFrameCount < 0 ||
118
+ result.inputFrameCount > fields[7] ||
106
119
  result.outputFrameCount < 0 ||
107
120
  result.outputFrameCount > fields[6]) {
108
121
  throw new RangeError('Effect frame counts exceed the leased block');
@@ -119,16 +132,22 @@ async function run() {
119
132
  }
120
133
  finally {
121
134
  audio_native_1.audioNative.closeAudioWorker(handle);
122
- if (setup.kind === 'recorder')
135
+ if (setup.kind === 'recorder') {
123
136
  await callbacks.onStop?.();
124
- else
137
+ }
138
+ else {
125
139
  await callbacks.onClose?.();
140
+ }
126
141
  }
127
142
  }
128
- void run().catch((error) => {
129
- node_worker_threads_1.parentPort.postMessage({ type: 'error',
130
- error: error instanceof Error ? error.stack : String(error) });
131
- }).finally(() => {
143
+ void run()
144
+ .catch((error) => {
145
+ node_worker_threads_1.parentPort.postMessage({
146
+ type: 'error',
147
+ error: error instanceof Error ? error.stack : String(error),
148
+ });
149
+ })
150
+ .finally(() => {
132
151
  node_worker_threads_1.parentPort.postMessage({ type: 'closed' });
133
152
  node_worker_threads_1.parentPort.close();
134
153
  });
@@ -3,7 +3,9 @@ import type { NativeValueHandle, NativeValueMapping } from './native';
3
3
  import { mutableValue } from './value-storage';
4
4
  export declare const glslStorage: unique symbol;
5
5
  export declare const glslNative: unique symbol;
6
- /** Internal storage only; concrete GLSL types define their own component API. */
6
+ /**
7
+ * Internal storage only; concrete GLSL types define their own component API.
8
+ */
7
9
  export declare abstract class GlslValue<K extends string, A extends ValueArray> {
8
10
  readonly [mutableValue] = true;
9
11
  private readonly state;
@@ -6,7 +6,9 @@ const lazy_value_1 = require("./lazy-value");
6
6
  const value_storage_1 = require("./value-storage");
7
7
  exports.glslStorage = Symbol('Glsl.storage');
8
8
  exports.glslNative = Symbol('Glsl.native');
9
- /** Internal storage only; concrete GLSL types define their own component API. */
9
+ /**
10
+ * Internal storage only; concrete GLSL types define their own component API.
11
+ */
10
12
  class GlslValue {
11
13
  constructor(values, wrap) {
12
14
  this[_a] = true;
@@ -32,9 +34,9 @@ class BooleanComponents extends GlslValue {
32
34
  this.scalarType = 'bool';
33
35
  for (let i = 0; i < components.length; i++) {
34
36
  // C++ conversion treats NaN as nonzero, unlike JavaScript Boolean(NaN).
35
- this[exports.glslStorage][i] =
36
- Number(components[i] !== 0 && components[i] !== 0n &&
37
- components[i] !== false);
37
+ this[exports.glslStorage][i] = Number(components[i] !== 0 &&
38
+ components[i] !== 0n &&
39
+ components[i] !== false);
38
40
  }
39
41
  }
40
42
  /**
@@ -43,27 +45,35 @@ class BooleanComponents extends GlslValue {
43
45
  * @ja X の真偽値成分。
44
46
  * @ko X 불리언 성분.
45
47
  */
46
- get x() { return this[exports.glslStorage][0] !== 0; }
48
+ get x() {
49
+ return this[exports.glslStorage][0] !== 0;
50
+ }
47
51
  /**
48
52
  * Set the X boolean component.
49
53
  * @zh 设置 X 布尔分量。
50
54
  * @ja X の真偽値成分を設定します。
51
55
  * @ko X 불리언 성분을 설정합니다.
52
56
  */
53
- set x(value) { this[exports.glslStorage][0] = value ? 1 : 0; }
57
+ set x(value) {
58
+ this[exports.glslStorage][0] = value ? 1 : 0;
59
+ }
54
60
  /**
55
61
  * Y boolean component.
56
62
  * @zh Y 布尔分量。
57
63
  * @ja Y の真偽値成分。
58
64
  * @ko Y 불리언 성분.
59
65
  */
60
- get y() { return this[exports.glslStorage][1] !== 0; }
66
+ get y() {
67
+ return this[exports.glslStorage][1] !== 0;
68
+ }
61
69
  /**
62
70
  * Set the Y boolean component.
63
71
  * @zh 设置 Y 布尔分量。
64
72
  * @ja Y の真偽値成分を設定します。
65
73
  * @ko Y 불리언 성분을 설정합니다.
66
74
  */
67
- set y(value) { this[exports.glslStorage][1] = value ? 1 : 0; }
75
+ set y(value) {
76
+ this[exports.glslStorage][1] = value ? 1 : 0;
77
+ }
68
78
  }
69
79
  exports.BooleanComponents = BooleanComponents;
@@ -36,10 +36,12 @@ exports.registerTarget = registerTarget;
36
36
  function flushGraphics() {
37
37
  for (const reference of targets) {
38
38
  const target = reference.deref();
39
- if (target)
39
+ if (target) {
40
40
  target[exports.graphicsFlush]();
41
- else
41
+ }
42
+ else {
42
43
  targets.delete(reference);
44
+ }
43
45
  }
44
46
  }
45
47
  exports.flushGraphics = flushGraphics;
@@ -47,18 +49,21 @@ exports.flushGraphics = flushGraphics;
47
49
  function flushShapeReaders(shape) {
48
50
  for (const reference of targets) {
49
51
  const target = reference.deref();
50
- if (!target)
52
+ if (!target) {
51
53
  targets.delete(reference);
52
- else if (target[exports.graphicsShapeReads]?.().has(shape))
54
+ }
55
+ else if (target[exports.graphicsShapeReads]?.().has(shape)) {
53
56
  target[exports.graphicsFlush]();
57
+ }
54
58
  }
55
59
  }
56
60
  exports.flushShapeReaders = flushShapeReaders;
57
61
  /** Reject feedback or a new cycle before reserving any command/vertex space. */
58
62
  function validateTextureRead(reader, texture) {
59
63
  const owner = texture?.[exports.textureOwner];
60
- if (!owner)
64
+ if (!owner) {
61
65
  return;
66
+ }
62
67
  if (owner === reader) {
63
68
  throw new error_1.SFMLError('Cannot sample a render target from its own texture');
64
69
  }
@@ -69,13 +74,15 @@ function validateTextureRead(reader, texture) {
69
74
  if (target === reader) {
70
75
  throw new error_1.SFMLError('Cyclic texture dependency: display an intermediate target');
71
76
  }
72
- if (visited.has(target))
77
+ if (visited.has(target)) {
73
78
  continue;
79
+ }
74
80
  visited.add(target);
75
81
  for (const source of target[exports.graphicsReads]()) {
76
82
  const dependency = source[exports.textureOwner];
77
- if (dependency)
83
+ if (dependency) {
78
84
  pending.push(dependency);
85
+ }
79
86
  }
80
87
  }
81
88
  }
@@ -91,11 +98,13 @@ function flushTextureReaders(writer) {
91
98
  }
92
99
  for (const texture of target[exports.graphicsReads]()) {
93
100
  const owner = texture[exports.textureOwner];
94
- if (!owner)
101
+ if (!owner) {
95
102
  continue;
103
+ }
96
104
  let consumers = readers.get(owner);
97
- if (!consumers)
98
- readers.set(owner, consumers = new Set());
105
+ if (!consumers) {
106
+ readers.set(owner, (consumers = new Set()));
107
+ }
99
108
  consumers.add(target);
100
109
  }
101
110
  }
@@ -103,21 +112,26 @@ function flushTextureReaders(writer) {
103
112
  const visiting = new Set();
104
113
  const done = new Set();
105
114
  const visit = (source) => {
106
- if (visiting.has(source))
115
+ if (visiting.has(source)) {
107
116
  throw new error_1.SFMLError('Cyclic texture dependency');
108
- if (done.has(source))
117
+ }
118
+ if (done.has(source)) {
109
119
  return;
120
+ }
110
121
  visiting.add(source);
111
- for (const target of readers.get(source) ?? [])
122
+ for (const target of readers.get(source) ?? []) {
112
123
  visit(target);
124
+ }
113
125
  visiting.delete(source);
114
126
  done.add(source);
115
- if (source !== writer)
127
+ if (source !== writer) {
116
128
  ordered.push(source);
129
+ }
117
130
  };
118
131
  visit(writer);
119
132
  // Collect the complete order before performing any native submissions.
120
- for (const target of ordered)
133
+ for (const target of ordered) {
121
134
  target[exports.graphicsFlush]();
135
+ }
122
136
  }
123
137
  exports.flushTextureReaders = flushTextureReaders;
@@ -1,4 +1,6 @@
1
1
  import type { InputStream } from '../system/input-stream';
2
2
  import type { NativeStreamDispatch } from './native';
3
- /** Keep the stream alive until native decoding and every pending read finish. */
3
+ /**
4
+ * Keep the stream alive until native decoding and every pending read finish.
5
+ */
4
6
  export declare function streamDispatch(stream: InputStream, onError: (error: unknown) => void): NativeStreamDispatch;