sfml.js 1.0.0-rc.2 → 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 (314) hide show
  1. package/README.ja.md +16 -11
  2. package/README.ko.md +16 -11
  3. package/README.md +16 -11
  4. package/README.zh-CN.md +16 -11
  5. package/assets/breakout.png +0 -0
  6. package/binding.gyp +23 -16
  7. package/dist/audio/effect-processor.js +9 -3
  8. package/dist/audio/input-sound-file.js +41 -15
  9. package/dist/audio/listener.js +33 -11
  10. package/dist/audio/music.js +41 -18
  11. package/dist/audio/output-sound-file.js +4 -2
  12. package/dist/audio/playback-device.js +11 -3
  13. package/dist/audio/sound-buffer-recorder.js +8 -5
  14. package/dist/audio/sound-buffer.js +40 -17
  15. package/dist/audio/sound-file-factory.js +21 -9
  16. package/dist/audio/sound-file-reader.js +21 -7
  17. package/dist/audio/sound-recorder.js +36 -15
  18. package/dist/audio/sound-source.js +117 -40
  19. package/dist/audio/sound-stream.js +14 -5
  20. package/dist/audio/sound.js +9 -4
  21. package/dist/audio/value.js +42 -16
  22. package/dist/graphics/blend-mode.js +2 -1
  23. package/dist/graphics/boolean-vector.d.ts +1 -2
  24. package/dist/graphics/boolean-vector.js +19 -9
  25. package/dist/graphics/color.js +2 -1
  26. package/dist/graphics/convex-shape.js +7 -3
  27. package/dist/graphics/font.js +52 -23
  28. package/dist/graphics/glsl-matrix.js +8 -3
  29. package/dist/graphics/glsl.js +47 -16
  30. package/dist/graphics/glyph.js +27 -10
  31. package/dist/graphics/image.js +30 -14
  32. package/dist/graphics/rect.js +15 -8
  33. package/dist/graphics/render-states.js +18 -9
  34. package/dist/graphics/render-target.js +49 -23
  35. package/dist/graphics/render-texture.js +24 -12
  36. package/dist/graphics/render-window.js +6 -3
  37. package/dist/graphics/shader.js +67 -32
  38. package/dist/graphics/shape.js +25 -13
  39. package/dist/graphics/sprite.js +19 -9
  40. package/dist/graphics/stencil-mode.js +10 -6
  41. package/dist/graphics/swap.js +2 -1
  42. package/dist/graphics/text.js +123 -48
  43. package/dist/graphics/texture.js +48 -24
  44. package/dist/graphics/transform.js +29 -13
  45. package/dist/graphics/transformable.js +2 -1
  46. package/dist/graphics/vertex-array.js +40 -18
  47. package/dist/graphics/vertex-buffer.js +39 -19
  48. package/dist/graphics/vertex.js +6 -3
  49. package/dist/graphics/view.js +30 -14
  50. package/dist/index.d.ts +4 -4
  51. package/dist/internal/audio-codec-registry.js +12 -6
  52. package/dist/internal/audio-input-stream.js +2 -1
  53. package/dist/internal/audio-music-pump.js +58 -24
  54. package/dist/internal/audio-recorder-session.js +17 -7
  55. package/dist/internal/audio-worker-session.js +28 -10
  56. package/dist/internal/audio-worker.js +40 -21
  57. package/dist/internal/glsl-value.d.ts +3 -1
  58. package/dist/internal/glsl-value.js +18 -8
  59. package/dist/internal/graphics-state.js +29 -15
  60. package/dist/internal/input-stream.d.ts +3 -1
  61. package/dist/internal/input-stream.js +16 -7
  62. package/dist/internal/numeric-properties.js +2 -1
  63. package/dist/internal/render-states.js +2 -1
  64. package/dist/internal/scalar.js +22 -13
  65. package/dist/internal/shaped-glyph.d.ts +3 -1
  66. package/dist/internal/shaped-glyph.js +12 -4
  67. package/dist/internal/struct-view.d.ts +3 -1
  68. package/dist/internal/struct-view.js +3 -1
  69. package/dist/internal/transformable.js +2 -1
  70. package/dist/network/common.js +23 -11
  71. package/dist/network/dns.js +25 -17
  72. package/dist/network/ftp.js +43 -18
  73. package/dist/network/http.js +126 -56
  74. package/dist/network/ip-address.js +50 -25
  75. package/dist/network/packet.js +63 -25
  76. package/dist/network/sftp.js +175 -74
  77. package/dist/network/socket-selector.js +28 -14
  78. package/dist/network/socket.js +71 -30
  79. package/dist/network/tcp-listener.js +42 -19
  80. package/dist/network/tcp-socket.js +111 -53
  81. package/dist/network/tls-material.js +2 -1
  82. package/dist/network/udp-socket.js +68 -33
  83. package/dist/system/angle.js +2 -1
  84. package/dist/system/clock.js +4 -2
  85. package/dist/system/err.js +5 -2
  86. package/dist/system/file-input-stream.js +8 -4
  87. package/dist/system/input-stream.js +6 -3
  88. package/dist/system/operators.d.ts +1 -1
  89. package/dist/system/operators.js +90 -50
  90. package/dist/system/sleep.js +4 -2
  91. package/dist/system/time.js +12 -6
  92. package/dist/system/vector2.js +6 -7
  93. package/dist/system/vector3.js +11 -6
  94. package/dist/window/clipboard.js +2 -1
  95. package/dist/window/context.js +10 -5
  96. package/dist/window/cursor.js +2 -1
  97. package/dist/window/event.js +9 -5
  98. package/dist/window/mouse.js +4 -2
  99. package/dist/window/video-mode.js +2 -1
  100. package/dist/window/window.js +19 -12
  101. package/native/addon.cc +25 -12
  102. package/native/audio-binding.cc +266 -126
  103. package/native/audio-codec-binding.cc +147 -77
  104. package/native/audio-device-binding.cc +76 -49
  105. package/native/audio-file-binding.cc +116 -67
  106. package/native/audio-recorder-binding.cc +147 -98
  107. package/native/audio-recorder.h +1 -1
  108. package/native/audio-state.h +53 -30
  109. package/native/audio-stream-binding.cc +148 -94
  110. package/native/audio-stream.h +5 -4
  111. package/native/audio-worker-binding.cc +163 -81
  112. package/native/audio-worker.h +35 -19
  113. package/native/batch-drawable.cc +29 -16
  114. package/native/batch-drawable.h +11 -8
  115. package/native/context-binding.cc +40 -27
  116. package/native/context-settings.h +15 -8
  117. package/native/deferred-delete.cc +9 -6
  118. package/native/deferred-delete.h +7 -8
  119. package/native/error-stream-binding.cc +42 -28
  120. package/native/font-binding.cc +89 -48
  121. package/native/graphics-binding.cc +122 -72
  122. package/native/graphics-state.h +50 -36
  123. package/native/image-binding.cc +38 -24
  124. package/native/image-state.h +26 -18
  125. package/native/input-binding.cc +42 -27
  126. package/native/render-window-binding.cc +38 -23
  127. package/native/shader-binding.cc +115 -50
  128. package/native/shape-binding.cc +94 -49
  129. package/native/shape-state.h +18 -9
  130. package/native/shaped-glyph-storage.h +9 -5
  131. package/native/stream-binding.cc +143 -117
  132. package/native/system-binding.cc +17 -12
  133. package/native/text-binding.cc +68 -35
  134. package/native/text-state.h +25 -18
  135. package/native/texture-binding.cc +42 -33
  136. package/native/texture-resource.h +20 -12
  137. package/native/time-value.h +3 -1
  138. package/native/transformable-binding.cc +12 -6
  139. package/native/transformable-state.h +6 -6
  140. package/native/value-binding.h +46 -28
  141. package/native/value-layout.h +10 -10
  142. package/native/values-binding.cc +29 -23
  143. package/native/vertex-binding.cc +18 -12
  144. package/native/vertex-buffer-binding.cc +38 -24
  145. package/native/vertex-storage.h +2 -2
  146. package/native/view-data.h +4 -3
  147. package/native/window-binding.cc +75 -45
  148. package/native/window-event.h +20 -11
  149. package/native/window-owner.h +15 -12
  150. package/package.json +43 -50
  151. package/src/audio/effect-processor.ts +9 -3
  152. package/src/audio/input-sound-file.ts +108 -36
  153. package/src/audio/listener.ts +39 -13
  154. package/src/audio/music.ts +112 -47
  155. package/src/audio/output-sound-file.ts +40 -11
  156. package/src/audio/playback-device.ts +23 -8
  157. package/src/audio/sound-buffer-recorder.ts +35 -13
  158. package/src/audio/sound-buffer.ts +166 -58
  159. package/src/audio/sound-file-factory.ts +127 -49
  160. package/src/audio/sound-file-reader.ts +49 -15
  161. package/src/audio/sound-recorder.ts +100 -34
  162. package/src/audio/sound-source.ts +142 -45
  163. package/src/audio/sound-stream.ts +15 -5
  164. package/src/audio/sound.ts +12 -4
  165. package/src/audio/value.ts +89 -26
  166. package/src/graphics/blend-mode.ts +3 -1
  167. package/src/graphics/boolean-vector.ts +56 -26
  168. package/src/graphics/color.ts +3 -1
  169. package/src/graphics/convex-shape.ts +10 -3
  170. package/src/graphics/font.ts +171 -50
  171. package/src/graphics/glsl-matrix.ts +9 -3
  172. package/src/graphics/glsl.ts +81 -35
  173. package/src/graphics/glyph.ts +67 -26
  174. package/src/graphics/image.ts +119 -45
  175. package/src/graphics/rect.ts +56 -24
  176. package/src/graphics/render-states.ts +31 -14
  177. package/src/graphics/render-target.ts +197 -81
  178. package/src/graphics/render-texture.ts +36 -12
  179. package/src/graphics/render-window.ts +9 -3
  180. package/src/graphics/shader.ts +186 -61
  181. package/src/graphics/shape.ts +93 -35
  182. package/src/graphics/sprite.ts +64 -25
  183. package/src/graphics/stencil-mode.ts +12 -6
  184. package/src/graphics/swap.ts +3 -2
  185. package/src/graphics/text.ts +229 -74
  186. package/src/graphics/texture.ts +180 -61
  187. package/src/graphics/transform.ts +132 -47
  188. package/src/graphics/transformable.ts +3 -1
  189. package/src/graphics/vertex-array.ts +87 -35
  190. package/src/graphics/vertex-buffer.ts +97 -33
  191. package/src/graphics/vertex.ts +9 -3
  192. package/src/graphics/view.ts +59 -21
  193. package/src/index.ts +101 -23
  194. package/src/internal/audio-codec-registry.ts +18 -6
  195. package/src/internal/audio-input-stream.ts +6 -2
  196. package/src/internal/audio-music-pump.ts +116 -41
  197. package/src/internal/audio-native.ts +249 -96
  198. package/src/internal/audio-recorder-session.ts +68 -24
  199. package/src/internal/audio-worker-session.ts +65 -21
  200. package/src/internal/audio-worker.ts +85 -41
  201. package/src/internal/glsl-value.ts +26 -11
  202. package/src/internal/graphics-state.ts +57 -20
  203. package/src/internal/input-stream.ts +23 -10
  204. package/src/internal/native.ts +252 -99
  205. package/src/internal/numeric-properties.ts +2 -1
  206. package/src/internal/render-states.ts +3 -1
  207. package/src/internal/scalar.ts +33 -14
  208. package/src/internal/shaped-glyph.ts +25 -12
  209. package/src/internal/struct-view.ts +40 -13
  210. package/src/internal/transformable.ts +3 -1
  211. package/src/network/common.ts +35 -11
  212. package/src/network/dns.ts +95 -38
  213. package/src/network/ftp.ts +129 -47
  214. package/src/network/http.ts +232 -77
  215. package/src/network/ip-address.ts +118 -48
  216. package/src/network/packet.ts +161 -54
  217. package/src/network/sftp.ts +498 -168
  218. package/src/network/socket-selector.ts +66 -26
  219. package/src/network/socket.ts +133 -46
  220. package/src/network/tcp-listener.ts +78 -29
  221. package/src/network/tcp-socket.ts +240 -95
  222. package/src/network/tls-material.ts +6 -2
  223. package/src/network/udp-socket.ts +147 -53
  224. package/src/system/angle.ts +3 -1
  225. package/src/system/clock.ts +12 -4
  226. package/src/system/err.ts +5 -2
  227. package/src/system/file-input-stream.ts +12 -4
  228. package/src/system/input-stream.ts +9 -3
  229. package/src/system/operators.ts +290 -115
  230. package/src/system/sleep.ts +6 -2
  231. package/src/system/time.ts +18 -6
  232. package/src/system/timeout-with-predicate.ts +19 -8
  233. package/src/system/vector2.ts +101 -49
  234. package/src/system/vector3.ts +85 -36
  235. package/src/window/clipboard.ts +3 -1
  236. package/src/window/context.ts +15 -5
  237. package/src/window/cursor.ts +3 -1
  238. package/src/window/event.ts +26 -12
  239. package/src/window/mouse.ts +6 -2
  240. package/src/window/video-mode.ts +3 -1
  241. package/src/window/window.ts +119 -37
  242. package/test/native/audio-probes.cc +74 -36
  243. package/test/native/deferred-delete-probes.cc +17 -11
  244. package/test/native/drawable-probes.cc +70 -36
  245. package/test/native/exception-probes.cc +14 -9
  246. package/test/native/image-probes.cc +20 -10
  247. package/test/native/matrix-probes.cc +8 -4
  248. package/test/native/network-oracle.cc +17 -11
  249. package/test/native/render-texture-probes.cc +33 -24
  250. package/test/native/shader-probes.cc +9 -9
  251. package/test/native/shape-probes.cc +37 -23
  252. package/test/native/sprite-probes.cc +41 -25
  253. package/test/native/system-probes.cc +58 -35
  254. package/test/native/text-probes.cc +77 -44
  255. package/test/native/texture-probes.cc +43 -26
  256. package/test/native/time-probes.cc +18 -12
  257. package/test/native/transform-probes.cc +15 -10
  258. package/test/native/transformable-probes.cc +23 -17
  259. package/test/native/value-oracle.h +9 -4
  260. package/test/native/value-probes.cc +31 -23
  261. package/test/native/vertex-array-probes.cc +22 -14
  262. package/test/native/vertex-buffer-probes.cc +28 -17
  263. package/test/native/view-probes.cc +29 -17
  264. package/test/native/window-probes.cc +66 -33
  265. package/tools/ensure-sfml.cjs +9 -0
  266. package/tools/generate-network-constants.cjs +11 -6
  267. package/tools/generate-window-constants.cjs +31 -12
  268. package/docs/README.ja.md +0 -30
  269. package/docs/README.ko.md +0 -30
  270. package/docs/README.md +0 -30
  271. package/docs/README.zh-CN.md +0 -30
  272. package/docs/api.ja.md +0 -84
  273. package/docs/api.ko.md +0 -84
  274. package/docs/api.md +0 -81
  275. package/docs/api.zh-CN.md +0 -81
  276. package/docs/audio.ja.md +0 -249
  277. package/docs/audio.ko.md +0 -251
  278. package/docs/audio.md +0 -252
  279. package/docs/audio.zh-CN.md +0 -252
  280. package/docs/concepts.ja.md +0 -130
  281. package/docs/concepts.ko.md +0 -130
  282. package/docs/concepts.md +0 -131
  283. package/docs/concepts.zh-CN.md +0 -131
  284. package/docs/development.ja.md +0 -148
  285. package/docs/development.ko.md +0 -148
  286. package/docs/development.md +0 -150
  287. package/docs/development.zh-CN.md +0 -150
  288. package/docs/getting-started.ja.md +0 -154
  289. package/docs/getting-started.ko.md +0 -154
  290. package/docs/getting-started.md +0 -156
  291. package/docs/getting-started.zh-CN.md +0 -156
  292. package/docs/graphics.ja.md +0 -256
  293. package/docs/graphics.ko.md +0 -254
  294. package/docs/graphics.md +0 -255
  295. package/docs/graphics.zh-CN.md +0 -257
  296. package/docs/network.ja.md +0 -214
  297. package/docs/network.ko.md +0 -216
  298. package/docs/network.md +0 -218
  299. package/docs/network.zh-CN.md +0 -218
  300. package/docs/system.ja.md +0 -169
  301. package/docs/system.ko.md +0 -171
  302. package/docs/system.md +0 -173
  303. package/docs/system.zh-CN.md +0 -173
  304. package/docs/window.ja.md +0 -138
  305. package/docs/window.ko.md +0 -140
  306. package/docs/window.md +0 -141
  307. package/docs/window.zh-CN.md +0 -141
  308. package/native/exception-boundary.h +0 -97
  309. package/native/numeric-fields.h +0 -96
  310. package/native/shared-handle.h +0 -69
  311. package/test/tsconfig.json +0 -8
  312. package/tools/configure-lsp.cjs +0 -23
  313. package/tools/lib_downloader.cjs +0 -92
  314. package/tools/lib_downloader_urls.cjs +0 -23
@@ -6,7 +6,9 @@ const minInt64 = -(2n ** 63n);
6
6
  const maxInt64 = 2n ** 63n - 1n;
7
7
 
8
8
  export function checkedMicroseconds(value: bigint): bigint {
9
- if (typeof value !== 'bigint') throw new TypeError('Expected a bigint');
9
+ if (typeof value !== 'bigint') {
10
+ throw new TypeError('Expected a bigint');
11
+ }
10
12
  if (value < minInt64 || value > maxInt64) {
11
13
  throw new RangeError('Time must fit in a signed 64-bit microsecond count');
12
14
  }
@@ -18,9 +20,13 @@ export function checkedMicroseconds(value: bigint): bigint {
18
20
  /* eslint-disable no-bitwise */
19
21
  function int64AsFloat(value: bigint): number {
20
22
  const magnitude = value < 0n ? -value : value;
21
- if (magnitude <= 9007199254740991n) return Math.fround(Number(value));
23
+ if (magnitude <= 9007199254740991n) {
24
+ return Math.fround(Number(value));
25
+ }
22
26
  let exponent = Math.floor(Math.log2(Number(magnitude)));
23
- if (magnitude < (1n << BigInt(exponent))) exponent--;
27
+ if (magnitude < (1n << BigInt(exponent))) {
28
+ exponent--;
29
+ }
24
30
  const shift = BigInt(exponent - 23);
25
31
  let significand = magnitude >> shift;
26
32
  const remainder = magnitude - (significand << shift);
@@ -35,7 +41,9 @@ function int64AsFloat(value: bigint): number {
35
41
  /* eslint-enable no-bitwise */
36
42
 
37
43
  function floatScalar(value: number): number {
38
- if (typeof value !== 'number') throw new TypeError('Expected a number');
44
+ if (typeof value !== 'number') {
45
+ throw new TypeError('Expected a number');
46
+ }
39
47
  const result = Math.fround(value);
40
48
  if (!Number.isFinite(result)) {
41
49
  throw new RangeError('Time requires a finite float32 value');
@@ -163,7 +171,9 @@ export function seconds(amount: number): Time {
163
171
  * 32비트 정수 범위 내여야 한다.
164
172
  */
165
173
  export function milliseconds(amount: number): Time {
166
- if (typeof amount !== 'number') throw new TypeError('Expected a number');
174
+ if (typeof amount !== 'number') {
175
+ throw new TypeError('Expected a number');
176
+ }
167
177
  const integer = Math.trunc(amount);
168
178
  if (!Number.isFinite(integer) ||
169
179
  integer < -2147483648 || integer > 2147483647) {
@@ -210,7 +220,9 @@ export function remainderTime(
210
220
  ): bigint {
211
221
  const lhs = left.asMicroseconds();
212
222
  const rhs = right.asMicroseconds();
213
- if (rhs === 0n) throw new RangeError('Cannot divide by zero');
223
+ if (rhs === 0n) {
224
+ throw new RangeError('Cannot divide by zero');
225
+ }
214
226
  if (lhs === minInt64 && rhs === -1n) {
215
227
  throw new RangeError('Time remainder quotient exceeds the int64 range');
216
228
  }
@@ -37,7 +37,10 @@ export class TimeoutWithPredicate {
37
37
  * @ko 주기적 확인 설정을 생성한다. period 기본값은 1밀리초이며
38
38
  * null이면 첫 확인에서 대기를 종료한다.
39
39
  */
40
- constructor(predicate: TimeoutPredicate | null, period?: ReadonlyValue<Time>);
40
+ constructor(
41
+ predicate: TimeoutPredicate | null,
42
+ period?: ReadonlyValue<Time>,
43
+ );
41
44
  /**
42
45
  * Copy the configuration, retaining the same predicate and copying the
43
46
  * check period.
@@ -47,27 +50,35 @@ export class TimeoutWithPredicate {
47
50
  */
48
51
  constructor(source: Readonly<TimeoutWithPredicate>);
49
52
  constructor(
50
- source: ReadonlyValue<Time> | TimeoutPredicate | null |
51
- Readonly<TimeoutWithPredicate>, period?: ReadonlyValue<Time>,
53
+ source:
54
+ | ReadonlyValue<Time>
55
+ | TimeoutPredicate
56
+ | null
57
+ | Readonly<TimeoutWithPredicate>,
58
+ period?: ReadonlyValue<Time>,
52
59
  ) {
53
60
  if (source instanceof Time || source instanceof TimeoutWithPredicate) {
54
61
  if (period !== undefined) {
55
62
  throw new TypeError('A timeout or copy accepts only one argument');
56
63
  }
57
64
  this.predicate = source instanceof Time ? stop : source.predicate;
58
- this.period = Object.freeze(new Time(
59
- source instanceof Time ? source : source.period));
65
+ this.period = Object.freeze(
66
+ new Time(source instanceof Time ? source : source.period),
67
+ );
60
68
  return;
61
69
  }
62
70
  if (source !== null && typeof source !== 'function') {
63
- throw new TypeError('Expected a Time, predicate, null or TimeoutWithPredicate');
71
+ throw new TypeError(
72
+ 'Expected a Time, predicate, null or TimeoutWithPredicate',
73
+ );
64
74
  }
65
75
  if (period !== undefined && !(period instanceof Time)) {
66
76
  throw new TypeError('Expected a Time period');
67
77
  }
68
78
  this.predicate = source ?? stop;
69
- this.period = Object.freeze(new Time(
70
- period === undefined ? milliseconds(1) : period));
79
+ this.period = Object.freeze(
80
+ new Time(period === undefined ? milliseconds(1) : period),
81
+ );
71
82
  }
72
83
 
73
84
  /**
@@ -3,26 +3,37 @@ import { LazyValue, nativeValue } from '../internal/lazy-value';
3
3
  import { Angle, radians } from './angle';
4
4
  import type { Bvec2 } from '../graphics/boolean-vector';
5
5
  import {
6
- vector2Storage, vector2Native, type ReadonlyValue, mutableValue,
6
+ vector2Storage,
7
+ vector2Native,
8
+ type ReadonlyValue,
9
+ mutableValue,
7
10
  } from '../internal/value-storage';
8
11
  import {
9
- scalarArrays, requireFloat, toScalar, scalarProduct, convertScalar,
10
- validateScalar, type ScalarType, type Scalar, type ScalarArray,
11
- type NumberScalar, type FloatScalar,
12
+ scalarArrays,
13
+ requireFloat,
14
+ toScalar,
15
+ scalarProduct,
16
+ convertScalar,
17
+ validateScalar,
18
+ type ScalarType,
19
+ type Scalar,
20
+ type ScalarArray,
21
+ type NumberScalar,
22
+ type FloatScalar,
12
23
  } from '../internal/scalar';
13
24
 
14
25
  export type { ScalarType } from '../internal/scalar';
15
26
 
16
27
  type Vector2Source =
17
- ReadonlyValue<Vector2<ScalarType>> | ReadonlyValue<Bvec2>;
28
+ | ReadonlyValue<Vector2<ScalarType>>
29
+ | ReadonlyValue<Bvec2>;
18
30
  type Vector2Arguments<T extends ScalarType = NumberScalar> =
19
31
  | []
20
- | [ x: Scalar<T>, y: Scalar<T> ]
21
- | [ source: Vector2Source ];
22
- type PolarArguments = [ r: number, phi: ReadonlyValue<Angle> ];
32
+ | [x: Scalar<T>, y: Scalar<T>]
33
+ | [source: Vector2Source];
34
+ type PolarArguments = [r: number, phi: ReadonlyValue<Angle>];
23
35
 
24
- type Vector2State =
25
- LazyValue<'vector2', ScalarArray>;
36
+ type Vector2State = LazyValue<'vector2', ScalarArray>;
26
37
 
27
38
  /**
28
39
  * sf::Vector2<T>, with a native handle lazily bound to its existing storage.
@@ -59,7 +70,9 @@ export class Vector2<T extends ScalarType> {
59
70
  */
60
71
  constructor(
61
72
  scalarType: T,
62
- ...args: Vector2Arguments<T> | (T extends FloatScalar ? PolarArguments : never)
73
+ ...args:
74
+ | Vector2Arguments<T>
75
+ | (T extends FloatScalar ? PolarArguments : never)
63
76
  );
64
77
  /**
65
78
  * Copy the vector and its scalar type with independent storage.
@@ -72,15 +85,18 @@ export class Vector2<T extends ScalarType> {
72
85
  typeOrSource: T | ReadonlyValue<Vector2<T>>,
73
86
  ...args: Vector2Arguments<ScalarType> | PolarArguments
74
87
  ) {
75
- this.type = typeof typeOrSource === 'string'
76
- ? typeOrSource
77
- : typeOrSource.scalarType as T;
88
+ this.type =
89
+ typeof typeOrSource === 'string'
90
+ ? typeOrSource
91
+ : (typeOrSource.scalarType as T);
78
92
  validateScalar(this.type);
79
93
  const type = this.type;
80
- this.state = new LazyValue(new scalarArrays[type](2),
81
- buffer => native.wrapVector2(type, buffer));
94
+ this.state = new LazyValue(new scalarArrays[type](2), buffer =>
95
+ native.wrapVector2(type, buffer),
96
+ );
82
97
 
83
- const source = typeof typeOrSource === 'string' ? args[0] : typeOrSource;
98
+ const source =
99
+ typeof typeOrSource === 'string' ? args[0] : typeOrSource;
84
100
  if (typeof source === 'number' || typeof source === 'bigint') {
85
101
  if (args[1] instanceof Angle) {
86
102
  requireFloat(this.type);
@@ -97,7 +113,8 @@ export class Vector2<T extends ScalarType> {
97
113
  if (source instanceof Vector2 && source.scalarType === type) {
98
114
  const input = source[vector2Storage];
99
115
  new Uint8Array(this.state.values.buffer).set(
100
- new Uint8Array(input.buffer, input.byteOffset, input.byteLength));
116
+ new Uint8Array(input.buffer, input.byteOffset, input.byteLength),
117
+ );
101
118
  } else {
102
119
  this.x = convertScalar(type, source.x) as Scalar<T>;
103
120
  this.y = convertScalar(type, source.y) as Scalar<T>;
@@ -200,12 +217,17 @@ export class Vector2<T extends ScalarType> {
200
217
  normalized(this: ReadonlyValue<Vector2<T & FloatScalar>>): Vector2<T>;
201
218
  normalized(): Vector2<T> {
202
219
  requireFloat(this.type);
203
- const length = toScalar(this.type, Math.sqrt(this.lengthSquared() as number));
220
+ const length = toScalar(
221
+ this.type,
222
+ Math.sqrt(this.lengthSquared() as number),
223
+ );
204
224
  if (length === 0) {
205
225
  throw new RangeError('Cannot normalize a vector with zero length');
206
226
  }
207
- return this.createResult((this.x as number) / length,
208
- (this.y as number) / length);
227
+ return this.createResult(
228
+ (this.x as number) / length,
229
+ (this.y as number) / length,
230
+ );
209
231
  }
210
232
 
211
233
  /**
@@ -242,7 +264,9 @@ export class Vector2<T extends ScalarType> {
242
264
  if (rhs.x === 0 && rhs.y === 0) {
243
265
  throw new RangeError('Cannot calculate angle to a zero vector');
244
266
  }
245
- return radians(Math.atan2(this.cross(rhs) as number, this.dot(rhs) as number));
267
+ return radians(
268
+ Math.atan2(this.cross(rhs) as number, this.dot(rhs) as number),
269
+ );
246
270
  }
247
271
 
248
272
  /**
@@ -255,7 +279,8 @@ export class Vector2<T extends ScalarType> {
255
279
  * 화면 좌표에서 양의 각도는 시계 방향이다.
256
280
  */
257
281
  rotatedBy(
258
- this: ReadonlyValue<Vector2<T & FloatScalar>>, phi: ReadonlyValue<Angle>,
282
+ this: ReadonlyValue<Vector2<T & FloatScalar>>,
283
+ phi: ReadonlyValue<Angle>,
259
284
  ): Vector2<T>;
260
285
  rotatedBy(phi: ReadonlyValue<Angle>): Vector2<T> {
261
286
  requireFloat(this.type);
@@ -288,10 +313,14 @@ export class Vector2<T extends ScalarType> {
288
313
  if (axis.x === 0 && axis.y === 0) {
289
314
  throw new RangeError('Cannot project onto a zero vector');
290
315
  }
291
- const ratio = toScalar(this.type,
292
- (this.dot(axis) as number) / (axis.lengthSquared() as number));
293
- return this.createResult(ratio * (axis.x as number),
294
- ratio * (axis.y as number));
316
+ const ratio = toScalar(
317
+ this.type,
318
+ (this.dot(axis) as number) / (axis.lengthSquared() as number),
319
+ );
320
+ return this.createResult(
321
+ ratio * (axis.x as number),
322
+ ratio * (axis.y as number),
323
+ );
295
324
  }
296
325
 
297
326
  /**
@@ -303,13 +332,16 @@ export class Vector2<T extends ScalarType> {
303
332
  dot(rhs: ReadonlyValue<Vector2<T>>): Scalar<T> {
304
333
  this.checkScalarType(rhs);
305
334
  if (typeof this.x === 'bigint') {
306
- return convertScalar(this.type,
307
- this.x * (rhs.x as bigint) +
308
- (this.y as bigint) * (rhs.y as bigint)) as Scalar<T>;
335
+ return convertScalar(
336
+ this.type,
337
+ this.x * (rhs.x as bigint) + (this.y as bigint) * (rhs.y as bigint),
338
+ ) as Scalar<T>;
309
339
  }
310
- return toScalar(this.type,
340
+ return toScalar(
341
+ this.type,
311
342
  scalarProduct(this.type, this.x as number, rhs.x as number) +
312
- scalarProduct(this.type, this.y as number, rhs.y as number)) as Scalar<T>;
343
+ scalarProduct(this.type, this.y as number, rhs.y as number),
344
+ ) as Scalar<T>;
313
345
  }
314
346
 
315
347
  /**
@@ -324,13 +356,16 @@ export class Vector2<T extends ScalarType> {
324
356
  cross(rhs: ReadonlyValue<Vector2<T>>): Scalar<T> {
325
357
  this.checkScalarType(rhs);
326
358
  if (typeof this.x === 'bigint') {
327
- return convertScalar(this.type,
328
- this.x * (rhs.y as bigint) -
329
- (this.y as bigint) * (rhs.x as bigint)) as Scalar<T>;
359
+ return convertScalar(
360
+ this.type,
361
+ this.x * (rhs.y as bigint) - (this.y as bigint) * (rhs.x as bigint),
362
+ ) as Scalar<T>;
330
363
  }
331
- return toScalar(this.type,
364
+ return toScalar(
365
+ this.type,
332
366
  scalarProduct(this.type, this.x as number, rhs.y as number) -
333
- scalarProduct(this.type, this.y as number, rhs.x as number)) as Scalar<T>;
367
+ scalarProduct(this.type, this.y as number, rhs.x as number),
368
+ ) as Scalar<T>;
334
369
  }
335
370
 
336
371
  /**
@@ -352,8 +387,10 @@ export class Vector2<T extends ScalarType> {
352
387
  componentWiseMul(rhs: ReadonlyValue<Vector2<T>>): Vector2<T> {
353
388
  this.checkScalarType(rhs);
354
389
  if (typeof this.x === 'bigint') {
355
- return this.createResult(this.x * (rhs.x as bigint),
356
- (this.y as bigint) * (rhs.y as bigint));
390
+ return this.createResult(
391
+ this.x * (rhs.x as bigint),
392
+ (this.y as bigint) * (rhs.y as bigint),
393
+ );
357
394
  }
358
395
  return this.createResult(
359
396
  scalarProduct(this.type, this.x as number, rhs.x as number),
@@ -373,17 +410,26 @@ export class Vector2<T extends ScalarType> {
373
410
  componentWiseDiv(rhs: ReadonlyValue<Vector2<T>>): Vector2<T> {
374
411
  this.checkScalarType(rhs);
375
412
  if (rhs.x === 0 || rhs.y === 0 || rhs.x === 0n || rhs.y === 0n) {
376
- throw new RangeError('Vector2.componentWiseDiv() cannot divide by zero');
413
+ throw new RangeError(
414
+ 'Vector2.componentWiseDiv() cannot divide by zero',
415
+ );
377
416
  }
378
417
  if (typeof this.x === 'bigint') {
379
- return this.createResult(this.x / (rhs.x as bigint),
380
- (this.y as bigint) / (rhs.y as bigint));
418
+ return this.createResult(
419
+ this.x / (rhs.x as bigint),
420
+ (this.y as bigint) / (rhs.y as bigint),
421
+ );
381
422
  }
382
- return this.createResult((this.x as number) / (rhs.x as number),
383
- (this.y as number) / (rhs.y as number));
423
+ return this.createResult(
424
+ (this.x as number) / (rhs.x as number),
425
+ (this.y as number) / (rhs.y as number),
426
+ );
384
427
  }
385
428
 
386
- protected createResult(x: number | bigint, y: number | bigint): Vector2<T> {
429
+ protected createResult(
430
+ x: number | bigint,
431
+ y: number | bigint,
432
+ ): Vector2<T> {
387
433
  return new Vector2(this.type, x as Scalar<T>, y as Scalar<T>);
388
434
  }
389
435
 
@@ -395,7 +441,9 @@ export class Vector2<T extends ScalarType> {
395
441
 
396
442
  private checkScalarType(rhs: ReadonlyValue<Vector2<T>>): void {
397
443
  if (!(rhs instanceof Vector2) || rhs.scalarType !== this.type) {
398
- throw new TypeError('Vector2 operands must have the same scalar type');
444
+ throw new TypeError(
445
+ 'Vector2 operands must have the same scalar type',
446
+ );
399
447
  }
400
448
  }
401
449
  }
@@ -524,8 +572,11 @@ export class Vector2f extends Vector2<'f32'> {
524
572
 
525
573
  const vector2Classes = { i32: Vector2i, u32: Vector2u, f32: Vector2f };
526
574
 
527
- function createMemberResult(this: Vector2<'i32' | 'u32' | 'f32'>,
528
- x: number, y: number) {
575
+ function createMemberResult(
576
+ this: Vector2<'i32' | 'u32' | 'f32'>,
577
+ x: number,
578
+ y: number,
579
+ ) {
529
580
  const Constructor = vector2Classes[this.scalarType];
530
581
  return new Constructor(x, y);
531
582
  }
@@ -537,7 +588,8 @@ function createMemberResult(this: Vector2<'i32' | 'u32' | 'f32'>,
537
588
  * @ko 내부 멤버 뷰. 부모를 통해 네이티브 소유권을 확인할 수 있다.
538
589
  */
539
590
  export function vector2FromState<T extends 'i32' | 'u32' | 'f32'>(
540
- type: T, state: Vector2State,
591
+ type: T,
592
+ state: Vector2State,
541
593
  ): Vector2<T> {
542
594
  // Bypass allocation and initialize the same fields as the value constructor.
543
595
  return Object.assign(Object.create(vector2Classes[type].prototype), {
@@ -2,20 +2,32 @@ import { native, type NativeValueHandle } from '../internal/native';
2
2
  import { LazyValue, nativeValue } from '../internal/lazy-value';
3
3
  import type { Bvec3 } from '../graphics/boolean-vector';
4
4
  import {
5
- vector3Storage, vector3Native, mutableValue, type ReadonlyValue,
5
+ vector3Storage,
6
+ vector3Native,
7
+ mutableValue,
8
+ type ReadonlyValue,
6
9
  } from '../internal/value-storage';
7
10
  import {
8
- scalarArrays, toScalar, scalarProduct, requireFloat, type ScalarType,
9
- convertScalar, validateScalar, type Scalar, type ScalarArray,
10
- type NumberScalar, type FloatScalar,
11
+ scalarArrays,
12
+ toScalar,
13
+ scalarProduct,
14
+ requireFloat,
15
+ type ScalarType,
16
+ convertScalar,
17
+ validateScalar,
18
+ type Scalar,
19
+ type ScalarArray,
20
+ type NumberScalar,
21
+ type FloatScalar,
11
22
  } from '../internal/scalar';
12
23
 
13
24
  type Vector3Source =
14
- ReadonlyValue<Vector3<ScalarType>> | ReadonlyValue<Bvec3>;
25
+ | ReadonlyValue<Vector3<ScalarType>>
26
+ | ReadonlyValue<Bvec3>;
15
27
  type Vector3Arguments<T extends ScalarType = NumberScalar> =
16
28
  | []
17
- | [ x: Scalar<T>, y: Scalar<T>, z: Scalar<T> ]
18
- | [ source: Vector3Source ];
29
+ | [x: Scalar<T>, y: Scalar<T>, z: Scalar<T>]
30
+ | [source: Vector3Source];
19
31
 
20
32
  /**
21
33
  * sf::Vector3<T>, stored as three consecutive values of its scalar type.
@@ -26,8 +38,7 @@ type Vector3Arguments<T extends ScalarType = NumberScalar> =
26
38
  export class Vector3<T extends ScalarType> {
27
39
  readonly [mutableValue] = true;
28
40
  private readonly type: T;
29
- private readonly state:
30
- LazyValue<'vector3', ScalarArray>;
41
+ private readonly state: LazyValue<'vector3', ScalarArray>;
31
42
 
32
43
  /**
33
44
  * Create a 3D vector of the specified scalar type.
@@ -59,13 +70,17 @@ export class Vector3<T extends ScalarType> {
59
70
  typeOrSource: T | ReadonlyValue<Vector3<T>>,
60
71
  ...args: Vector3Arguments<ScalarType>
61
72
  ) {
62
- this.type = typeof typeOrSource === 'string'
63
- ? typeOrSource : typeOrSource.scalarType as T;
73
+ this.type =
74
+ typeof typeOrSource === 'string'
75
+ ? typeOrSource
76
+ : (typeOrSource.scalarType as T);
64
77
  const type = this.type;
65
78
  validateScalar(type);
66
- this.state = new LazyValue(new scalarArrays[type](3),
67
- buffer => native.wrapVector3(type, buffer));
68
- const source = typeof typeOrSource === 'string' ? args[0] : typeOrSource;
79
+ this.state = new LazyValue(new scalarArrays[type](3), buffer =>
80
+ native.wrapVector3(type, buffer),
81
+ );
82
+ const source =
83
+ typeof typeOrSource === 'string' ? args[0] : typeOrSource;
69
84
  if (typeof source === 'number' || typeof source === 'bigint') {
70
85
  this.x = source as Scalar<T>;
71
86
  this.y = (args[1] ?? 0) as Scalar<T>;
@@ -74,7 +89,8 @@ export class Vector3<T extends ScalarType> {
74
89
  if (source instanceof Vector3 && source.scalarType === type) {
75
90
  const input = source[vector3Storage];
76
91
  new Uint8Array(this.state.values.buffer).set(
77
- new Uint8Array(input.buffer, input.byteOffset, input.byteLength));
92
+ new Uint8Array(input.buffer, input.byteOffset, input.byteLength),
93
+ );
78
94
  } else {
79
95
  this.x = convertScalar(type, source.x) as Scalar<T>;
80
96
  this.y = convertScalar(type, source.y) as Scalar<T>;
@@ -199,12 +215,16 @@ export class Vector3<T extends ScalarType> {
199
215
  normalized(this: ReadonlyValue<Vector3<T & FloatScalar>>): Vector3<T>;
200
216
  normalized(): Vector3<T> {
201
217
  requireFloat(this.type);
202
- const length = toScalar(this.type, Math.sqrt(this.lengthSquared() as number));
218
+ const length = toScalar(
219
+ this.type,
220
+ Math.sqrt(this.lengthSquared() as number),
221
+ );
203
222
  if (length === 0) {
204
223
  throw new RangeError('Cannot normalize a vector with zero length');
205
224
  }
206
225
  return this.createResult(
207
- (this.x as number) / length, (this.y as number) / length,
226
+ (this.x as number) / length,
227
+ (this.y as number) / length,
208
228
  (this.z as number) / length,
209
229
  );
210
230
  }
@@ -218,16 +238,22 @@ export class Vector3<T extends ScalarType> {
218
238
  dot(rhs: ReadonlyValue<Vector3<T>>): Scalar<T> {
219
239
  this.checkScalarType(rhs);
220
240
  if (typeof this.x === 'bigint') {
221
- return convertScalar(this.type,
241
+ return convertScalar(
242
+ this.type,
222
243
  this.x * (rhs.x as bigint) +
223
- (this.y as bigint) * (rhs.y as bigint) +
224
- (this.z as bigint) * (rhs.z as bigint)) as Scalar<T>;
244
+ (this.y as bigint) * (rhs.y as bigint) +
245
+ (this.z as bigint) * (rhs.z as bigint),
246
+ ) as Scalar<T>;
225
247
  }
226
- const xy = toScalar(this.type,
248
+ const xy = toScalar(
249
+ this.type,
227
250
  scalarProduct(this.type, this.x as number, rhs.x as number) +
228
- scalarProduct(this.type, this.y as number, rhs.y as number));
229
- return toScalar(this.type, xy +
230
- scalarProduct(this.type, this.z as number, rhs.z as number)) as Scalar<T>;
251
+ scalarProduct(this.type, this.y as number, rhs.y as number),
252
+ );
253
+ return toScalar(
254
+ this.type,
255
+ xy + scalarProduct(this.type, this.z as number, rhs.z as number),
256
+ ) as Scalar<T>;
231
257
  }
232
258
 
233
259
  /**
@@ -267,9 +293,11 @@ export class Vector3<T extends ScalarType> {
267
293
  componentWiseMul(rhs: ReadonlyValue<Vector3<T>>): Vector3<T> {
268
294
  this.checkScalarType(rhs);
269
295
  if (typeof this.x === 'bigint') {
270
- return this.createResult(this.x * (rhs.x as bigint),
296
+ return this.createResult(
297
+ this.x * (rhs.x as bigint),
271
298
  (this.y as bigint) * (rhs.y as bigint),
272
- (this.z as bigint) * (rhs.z as bigint));
299
+ (this.z as bigint) * (rhs.z as bigint),
300
+ );
273
301
  }
274
302
  return this.createResult(
275
303
  scalarProduct(this.type, this.x as number, rhs.x as number),
@@ -289,29 +317,50 @@ export class Vector3<T extends ScalarType> {
289
317
  */
290
318
  componentWiseDiv(rhs: ReadonlyValue<Vector3<T>>): Vector3<T> {
291
319
  this.checkScalarType(rhs);
292
- if (rhs.x === 0 || rhs.y === 0 || rhs.z === 0 ||
293
- rhs.x === 0n || rhs.y === 0n || rhs.z === 0n) {
294
- throw new RangeError('Vector3.componentWiseDiv() cannot divide by zero');
320
+ if (
321
+ rhs.x === 0 ||
322
+ rhs.y === 0 ||
323
+ rhs.z === 0 ||
324
+ rhs.x === 0n ||
325
+ rhs.y === 0n ||
326
+ rhs.z === 0n
327
+ ) {
328
+ throw new RangeError(
329
+ 'Vector3.componentWiseDiv() cannot divide by zero',
330
+ );
295
331
  }
296
332
  if (typeof this.x === 'bigint') {
297
- return this.createResult(this.x / (rhs.x as bigint),
333
+ return this.createResult(
334
+ this.x / (rhs.x as bigint),
298
335
  (this.y as bigint) / (rhs.y as bigint),
299
- (this.z as bigint) / (rhs.z as bigint));
336
+ (this.z as bigint) / (rhs.z as bigint),
337
+ );
300
338
  }
301
- return this.createResult((this.x as number) / (rhs.x as number),
339
+ return this.createResult(
340
+ (this.x as number) / (rhs.x as number),
302
341
  (this.y as number) / (rhs.y as number),
303
- (this.z as number) / (rhs.z as number));
342
+ (this.z as number) / (rhs.z as number),
343
+ );
304
344
  }
305
345
 
306
346
  protected createResult(
307
- x: number | bigint, y: number | bigint, z: number | bigint,
347
+ x: number | bigint,
348
+ y: number | bigint,
349
+ z: number | bigint,
308
350
  ): Vector3<T> {
309
- return new Vector3(this.type, x as Scalar<T>, y as Scalar<T>, z as Scalar<T>);
351
+ return new Vector3(
352
+ this.type,
353
+ x as Scalar<T>,
354
+ y as Scalar<T>,
355
+ z as Scalar<T>,
356
+ );
310
357
  }
311
358
 
312
359
  private checkScalarType(rhs: ReadonlyValue<Vector3<T>>): void {
313
360
  if (!(rhs instanceof Vector3) || rhs.scalarType !== this.type) {
314
- throw new TypeError('Vector3 operands must have the same scalar type');
361
+ throw new TypeError(
362
+ 'Vector3 operands must have the same scalar type',
363
+ );
315
364
  }
316
365
  }
317
366
  }
@@ -17,6 +17,8 @@ export function getString(): string {
17
17
  * @ko 시스템 클립보드 텍스트를 text로 교체한다.
18
18
  */
19
19
  export function setString(text: string): void {
20
- if (typeof text !== 'string') throw new TypeError('Expected clipboard text');
20
+ if (typeof text !== 'string') {
21
+ throw new TypeError('Expected clipboard text');
22
+ }
21
23
  native.setClipboardString(text);
22
24
  }
@@ -16,7 +16,9 @@ export type ReadonlyContext = Readonly<Pick<Context, 'getSettings'>>;
16
16
 
17
17
  const contexts = new Map<bigint, WeakRef<Context>>();
18
18
  const collected = new FinalizationRegistry<bigint>(key => {
19
- if (!contexts.get(key)?.deref()) contexts.delete(key);
19
+ if (!contexts.get(key)?.deref()) {
20
+ contexts.delete(key);
21
+ }
20
22
  });
21
23
 
22
24
  function remember(key: bigint, context: Context): void {
@@ -77,7 +79,9 @@ export class Context {
77
79
  * 활성화 또는 비활성화한 뒤 성공 여부를 반환한다.
78
80
  */
79
81
  setActive(active: boolean): boolean {
80
- if (typeof active !== 'boolean') throw new TypeError('Expected a boolean');
82
+ if (typeof active !== 'boolean') {
83
+ throw new TypeError('Expected a boolean');
84
+ }
81
85
  flushGraphics();
82
86
  return native.setContextActive(this[graphicsNative], active);
83
87
  }
@@ -103,11 +107,17 @@ export class Context {
103
107
  */
104
108
  static getActiveContext(): ReadonlyContext | undefined {
105
109
  const key = native.getActiveContextKey();
106
- if (key === undefined) return undefined;
110
+ if (key === undefined) {
111
+ return undefined;
112
+ }
107
113
  const existing = contexts.get(key)?.deref();
108
- if (existing) return existing;
114
+ if (existing) {
115
+ return existing;
116
+ }
109
117
  const mapping = native.referenceActiveContext();
110
- if (!mapping) return undefined;
118
+ if (!mapping) {
119
+ return undefined;
120
+ }
111
121
  const context = Object.create(Context.prototype) as Context;
112
122
  Object.defineProperties(context, {
113
123
  [graphicsNative]: { value: mapping.handle },
@@ -76,7 +76,9 @@ export class Cursor {
76
76
  ) {
77
77
  const handle = typeof source === 'number' ? systemCursor(source)
78
78
  : pixelCursor(source, size!, hotspot!);
79
- if (!handle) throw new SFMLError('Failed to create cursor');
79
+ if (!handle) {
80
+ throw new SFMLError('Failed to create cursor');
81
+ }
80
82
  this[graphicsNative] = handle;
81
83
  }
82
84