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
@@ -37,8 +37,9 @@ class RenderWindow extends render_target_1.RenderTarget {
37
37
  const initializeViews = () => {
38
38
  super.initializeViews(window_1.Window.prototype.getSize.call(this));
39
39
  };
40
- if (native_1.native.isWindowOpen(this[graphics_state_1.graphicsNative]))
40
+ if (native_1.native.isWindowOpen(this[graphics_state_1.graphicsNative])) {
41
41
  initializeViews();
42
+ }
42
43
  (0, window_1.registerWindowHooks)(this, () => {
43
44
  initializeViews();
44
45
  this.onCreate();
@@ -93,8 +94,9 @@ class RenderWindow extends render_target_1.RenderTarget {
93
94
  * @ko 클라이언트 영역의 최소 픽셀 크기를 설정합니다. undefined는 제한을 해제합니다.
94
95
  */
95
96
  setMinimumSize(size) {
96
- if (size !== undefined)
97
+ if (size !== undefined) {
97
98
  (0, video_mode_1.windowSize)(size);
99
+ }
98
100
  this.flush();
99
101
  window_1.Window.prototype.setMinimumSize.call(this, size);
100
102
  }
@@ -105,8 +107,9 @@ class RenderWindow extends render_target_1.RenderTarget {
105
107
  * @ko 클라이언트 영역의 최대 픽셀 크기를 설정합니다. undefined는 제한을 해제합니다.
106
108
  */
107
109
  setMaximumSize(size) {
108
- if (size !== undefined)
110
+ if (size !== undefined) {
109
111
  (0, video_mode_1.windowSize)(size);
112
+ }
110
113
  this.flush();
111
114
  window_1.Window.prototype.setMaximumSize.call(this, size);
112
115
  }
@@ -45,32 +45,45 @@ function nameString(name) {
45
45
  }
46
46
  }
47
47
  function numeric(value) {
48
- if (typeof value === 'number')
48
+ if (typeof value === 'number') {
49
49
  return { type: 0, data: new Float32Array([value]) };
50
- if (typeof value === 'boolean')
50
+ }
51
+ if (typeof value === 'boolean') {
51
52
  return { type: 2, data: new Int32Array([+value]) };
52
- if (value instanceof Glsl.Vec2)
53
+ }
54
+ if (value instanceof Glsl.Vec2) {
53
55
  return { type: 3, data: value[value_storage_1.vector2Storage] };
54
- if (value instanceof Glsl.Vec3)
56
+ }
57
+ if (value instanceof Glsl.Vec3) {
55
58
  return { type: 4, data: value[value_storage_1.vector3Storage] };
56
- if (value instanceof Glsl.Vec4)
59
+ }
60
+ if (value instanceof Glsl.Vec4) {
57
61
  return { type: 5, data: value[glsl_value_1.glslStorage] };
58
- if (value instanceof Glsl.Ivec2)
62
+ }
63
+ if (value instanceof Glsl.Ivec2) {
59
64
  return { type: 6, data: value[value_storage_1.vector2Storage] };
60
- if (value instanceof Glsl.Ivec3)
65
+ }
66
+ if (value instanceof Glsl.Ivec3) {
61
67
  return { type: 7, data: value[value_storage_1.vector3Storage] };
62
- if (value instanceof Glsl.Ivec4)
68
+ }
69
+ if (value instanceof Glsl.Ivec4) {
63
70
  return { type: 8, data: value[glsl_value_1.glslStorage] };
64
- if (value instanceof Glsl.Bvec2)
71
+ }
72
+ if (value instanceof Glsl.Bvec2) {
65
73
  return { type: 9, data: new Int32Array(value[glsl_value_1.glslStorage]) };
66
- if (value instanceof Glsl.Bvec3)
74
+ }
75
+ if (value instanceof Glsl.Bvec3) {
67
76
  return { type: 10, data: new Int32Array(value[glsl_value_1.glslStorage]) };
68
- if (value instanceof Glsl.Bvec4)
77
+ }
78
+ if (value instanceof Glsl.Bvec4) {
69
79
  return { type: 11, data: new Int32Array(value[glsl_value_1.glslStorage]) };
70
- if (value instanceof Glsl.Mat3)
80
+ }
81
+ if (value instanceof Glsl.Mat3) {
71
82
  return { type: 12, data: value[glsl_value_1.glslStorage] };
72
- if (value instanceof Glsl.Mat4)
83
+ }
84
+ if (value instanceof Glsl.Mat4) {
73
85
  return { type: 13, data: value[glsl_value_1.glslStorage] };
86
+ }
74
87
  throw new TypeError('Expected a Shader uniform value');
75
88
  }
76
89
  /**
@@ -134,21 +147,26 @@ class Shader {
134
147
  const code = [null, null, null];
135
148
  for (let i = 0; i < 3; i++) {
136
149
  const stream = stages[i];
137
- if (stream === null)
150
+ if (stream === null) {
138
151
  continue;
139
- if (!(stream instanceof input_stream_1.InputStream))
152
+ }
153
+ if (!(stream instanceof input_stream_1.InputStream)) {
140
154
  throw new TypeError('Expected an InputStream');
155
+ }
141
156
  const size = await stream.getSize();
142
- if (size === undefined || size === 0n)
157
+ if (size === undefined || size === 0n) {
143
158
  return false;
159
+ }
144
160
  if (typeof size !== 'bigint' || size < 0n || size > 0x7fffffffn) {
145
161
  throw new RangeError('Shader stream size exceeds the buffer limit');
146
162
  }
147
- if (await stream.seek(0n) === undefined)
163
+ if ((await stream.seek(0n)) === undefined) {
148
164
  return false;
165
+ }
149
166
  const bytes = new Uint8Array(Number(size));
150
- if (await stream.read(bytes) !== size)
167
+ if ((await stream.read(bytes)) !== size) {
151
168
  return false;
169
+ }
152
170
  code[i] = Buffer.from(bytes.buffer).toString('utf8');
153
171
  }
154
172
  return this.compile(true, code);
@@ -168,7 +186,8 @@ class Shader {
168
186
  return;
169
187
  }
170
188
  const { type, data } = scalarType === 'int'
171
- ? { type: 1, data: new Int32Array([value]) } : numeric(value);
189
+ ? { type: 1, data: new Int32Array([value]) }
190
+ : numeric(value);
172
191
  (0, graphics_state_1.flushGraphics)();
173
192
  native_1.native.setShaderUniform(this[graphics_state_1.graphicsNative], name, type, data, false);
174
193
  }
@@ -183,14 +202,17 @@ class Shader {
183
202
  nameString(name);
184
203
  let type = 0;
185
204
  let data;
186
- if (values instanceof Float32Array)
205
+ if (values instanceof Float32Array) {
187
206
  data = values;
207
+ }
188
208
  else {
189
- if (!Array.isArray(values))
209
+ if (!Array.isArray(values)) {
190
210
  throw new TypeError('Expected a uniform array');
211
+ }
191
212
  const parts = Array.from(values, value => numeric(value));
192
- if (parts.length)
213
+ if (parts.length) {
193
214
  type = parts[0].type;
215
+ }
194
216
  if (![0, 3, 4, 5, 12, 13].includes(type) ||
195
217
  parts.some(part => part.type !== type)) {
196
218
  throw new TypeError('Expected a homogeneous float, vector or matrix array');
@@ -230,14 +252,18 @@ class Shader {
230
252
  * @ja 現在の環境がシェーダーに対応しているかを返します。
231
253
  * @ko 현재 환경의 셰이더 지원 여부를 반환합니다.
232
254
  */
233
- static isAvailable() { return native_1.native.isShaderAvailable(false); }
255
+ static isAvailable() {
256
+ return native_1.native.isShaderAvailable(false);
257
+ }
234
258
  /**
235
259
  * Returns whether the current environment supports geometry shaders.
236
260
  * @zh 返回当前环境是否支持几何着色器。
237
261
  * @ja 現在の環境がジオメトリシェーダーに対応しているかを返します。
238
262
  * @ko 현재 환경의 기하 셰이더 지원 여부를 반환합니다.
239
263
  */
240
- static isGeometryAvailable() { return native_1.native.isShaderAvailable(true); }
264
+ static isGeometryAvailable() {
265
+ return native_1.native.isShaderAvailable(true);
266
+ }
241
267
  /**
242
268
  * Normalizes stage arguments into a [vertex, geometry, fragment] tuple.
243
269
  * @zh 将阶段参数标准化为 [vertex, geometry, fragment] 三元组。
@@ -246,17 +272,21 @@ class Shader {
246
272
  */
247
273
  stages(sources) {
248
274
  if (sources.length === 2 && typeof sources[1] === 'number') {
249
- if (!Number.isInteger(sources[1]) || sources[1] < 0 || sources[1] > 2) {
275
+ if (!Number.isInteger(sources[1]) ||
276
+ sources[1] < 0 ||
277
+ sources[1] > 2) {
250
278
  throw new RangeError('Invalid shader type');
251
279
  }
252
280
  const result = [null, null, null];
253
281
  result[sources[1]] = sources[0];
254
282
  return result;
255
283
  }
256
- if (sources.length === 2)
284
+ if (sources.length === 2) {
257
285
  return [sources[0], null, sources[1]];
258
- if (sources.length === 3)
286
+ }
287
+ if (sources.length === 3) {
259
288
  return sources;
289
+ }
260
290
  throw new TypeError('Expected a shader source and type, or two/three sources');
261
291
  }
262
292
  /**
@@ -267,12 +297,15 @@ class Shader {
267
297
  */
268
298
  async load(memory, sources) {
269
299
  const stages = this.stages(sources).map(source => {
270
- if (source === null)
300
+ if (source === null) {
271
301
  return null;
272
- if (typeof source !== 'string')
302
+ }
303
+ if (typeof source !== 'string') {
273
304
  throw new TypeError('Expected shader source strings');
274
- if (!memory && source.includes('\0'))
305
+ }
306
+ if (!memory && source.includes('\0')) {
275
307
  throw new TypeError('Invalid shader path');
308
+ }
276
309
  return memory || !source ? source : (0, node_path_1.resolve)(source);
277
310
  });
278
311
  return this.compile(memory, stages);
@@ -286,10 +319,12 @@ class Shader {
286
319
  compile(memory, sources) {
287
320
  return new Promise((resolve, reject) => {
288
321
  native_1.native.compileShader(memory, sources, (error, program) => {
289
- if (error)
322
+ if (error) {
290
323
  return reject(error);
291
- if (!program)
324
+ }
325
+ if (!program) {
292
326
  return resolve(false);
327
+ }
293
328
  try {
294
329
  (0, graphics_state_1.flushGraphics)();
295
330
  native_1.native.commitShader(this[graphics_state_1.graphicsNative], program);
@@ -14,8 +14,9 @@ const drawable_1 = require("./drawable");
14
14
  const rect_1 = require("./rect");
15
15
  const texture_1 = require("./texture");
16
16
  function shapeNumber(value) {
17
- if (typeof value !== 'number')
17
+ if (typeof value !== 'number') {
18
18
  throw new TypeError('Expected a number');
19
+ }
19
20
  const result = Math.fround(value);
20
21
  if (!Number.isFinite(result)) {
21
22
  throw new RangeError('Expected a finite float32 value');
@@ -24,7 +25,8 @@ function shapeNumber(value) {
24
25
  }
25
26
  exports.shapeNumber = shapeNumber;
26
27
  function shapeCount(value) {
27
- if (!Number.isInteger(value) || value < 0 ||
28
+ if (!Number.isInteger(value) ||
29
+ value < 0 ||
28
30
  value > Math.floor(0x7fffffff / (6 * 20)) - 2) {
29
31
  throw new RangeError('Shape point count exceeds the buffer limit');
30
32
  }
@@ -45,12 +47,14 @@ class ShapeResource extends drawable_1.Drawable {
45
47
  const mapping = native_1.native.createShape((0, graphics_state_1.graphicsContext)(), init.kind, init.x ?? 0, init.y ?? 0, init.source?.[graphics_state_1.graphicsNative]);
46
48
  this[graphics_state_1.graphicsNative] = mapping.handle;
47
49
  this[graphics_state_1.shapeState] = {
48
- id: mapping.id, words: new Uint32Array(mapping.appearance),
50
+ id: mapping.id,
51
+ words: new Uint32Array(mapping.appearance),
49
52
  rectangle: new Int32Array(mapping.appearance, 12, 4),
50
53
  texture: init.source?.[graphics_state_1.shapeState].texture ?? null,
51
54
  };
52
55
  this[transformable_1.transformableState] = {
53
- handle: mapping.transformable, values: new Float32Array(mapping.buffer),
56
+ handle: mapping.transformable,
57
+ values: new Float32Array(mapping.buffer),
54
58
  };
55
59
  this.shapeInfo = (0, struct_view_1.nativeStruct)(mapping.info);
56
60
  }
@@ -65,11 +69,13 @@ class ShapeResource extends drawable_1.Drawable {
65
69
  if (texture !== null && !(texture instanceof texture_1.Texture)) {
66
70
  throw new TypeError('Expected a Texture or null');
67
71
  }
68
- if (typeof resetRect !== 'boolean')
72
+ if (typeof resetRect !== 'boolean') {
69
73
  throw new TypeError('Expected a boolean');
74
+ }
70
75
  const state = this[graphics_state_1.shapeState];
71
- const reset = texture && (resetRect ||
72
- (!state.texture && state.rectangle.every(value => value === 0)));
76
+ const reset = texture &&
77
+ (resetRect ||
78
+ (!state.texture && state.rectangle.every(value => value === 0)));
73
79
  if (texture !== state.texture) {
74
80
  native_1.native.setShapeTexture(this[graphics_state_1.graphicsNative], texture?.[graphics_state_1.graphicsNative] ?? null, texture?.[graphics_state_1.textureId] ?? 0);
75
81
  state.texture = texture;
@@ -96,8 +102,9 @@ class ShapeResource extends drawable_1.Drawable {
96
102
  * @ko 사용할 텍스처 픽셀 영역을 복사합니다. 음수 크기로 텍스처를 반전할 수 있습니다.
97
103
  */
98
104
  setTextureRect(rectangle) {
99
- if (!(rectangle instanceof rect_1.IntRect))
105
+ if (!(rectangle instanceof rect_1.IntRect)) {
100
106
  throw new TypeError('Expected an IntRect');
107
+ }
101
108
  this[graphics_state_1.shapeState].rectangle.set(rectangle[value_storage_1.rectStorage]);
102
109
  }
103
110
  /**
@@ -120,8 +127,9 @@ class ShapeResource extends drawable_1.Drawable {
120
127
  * @ko 채우기 색상을 설정합니다. 그릴 때 텍스처 색상과 곱해집니다.
121
128
  */
122
129
  setFillColor(color) {
123
- if (!(color instanceof color_1.Color))
130
+ if (!(color instanceof color_1.Color)) {
124
131
  throw new TypeError('Expected a Color');
132
+ }
125
133
  this[graphics_state_1.shapeState].words[1] = color.toInteger();
126
134
  }
127
135
  /**
@@ -140,8 +148,9 @@ class ShapeResource extends drawable_1.Drawable {
140
148
  * @ko 윤곽선 색상을 복사합니다.
141
149
  */
142
150
  setOutlineColor(color) {
143
- if (!(color instanceof color_1.Color))
151
+ if (!(color instanceof color_1.Color)) {
144
152
  throw new TypeError('Expected a Color');
153
+ }
145
154
  this[graphics_state_1.shapeState].words[2] = color.toInteger();
146
155
  }
147
156
  /**
@@ -181,8 +190,9 @@ class ShapeResource extends drawable_1.Drawable {
181
190
  */
182
191
  setMiterLimit(limit) {
183
192
  limit = shapeNumber(limit);
184
- if (limit < 1)
193
+ if (limit < 1) {
185
194
  throw new RangeError('Miter limit must be at least 1');
195
+ }
186
196
  this.changeGeometry(1, limit);
187
197
  }
188
198
  /**
@@ -224,10 +234,12 @@ class ShapeResource extends drawable_1.Drawable {
224
234
  target[graphics_state_1.recordShape](this, states);
225
235
  }
226
236
  [(_a = value_storage_1.mutableValue, graphics_state_1.dispatchDrawable)](target, states) {
227
- if (this.draw === ShapeResource.prototype.draw)
237
+ if (this.draw === ShapeResource.prototype.draw) {
228
238
  this.draw(target, states);
229
- else
239
+ }
240
+ else {
230
241
  super[graphics_state_1.dispatchDrawable](target, states);
242
+ }
231
243
  }
232
244
  }
233
245
  /**
@@ -17,9 +17,12 @@ class SpriteResource extends drawable_1.Drawable {
17
17
  super();
18
18
  this[_a] = true;
19
19
  const copy = source instanceof SpriteResource ? source : undefined;
20
- const texture = copy ? copy[graphics_state_1.spriteState].texture : source;
21
- if (!(texture instanceof texture_1.Texture))
20
+ const texture = copy
21
+ ? copy[graphics_state_1.spriteState].texture
22
+ : source;
23
+ if (!(texture instanceof texture_1.Texture)) {
22
24
  throw new TypeError('Expected a Texture');
25
+ }
23
26
  if (rectangle !== undefined && !(rectangle instanceof rect_1.IntRect)) {
24
27
  throw new TypeError('Expected an IntRect');
25
28
  }
@@ -29,11 +32,14 @@ class SpriteResource extends drawable_1.Drawable {
29
32
  const { handle, transformable, id, buffer, appearance } = native_1.native.createSprite((0, graphics_state_1.graphicsContext)(), texture[graphics_state_1.graphicsNative], texture[graphics_state_1.textureId]);
30
33
  this[graphics_state_1.graphicsNative] = handle;
31
34
  this[graphics_state_1.spriteState] = {
32
- id, words: new Uint32Array(appearance),
33
- rectangle: new Int32Array(appearance, 4, 4), texture,
35
+ id,
36
+ words: new Uint32Array(appearance),
37
+ rectangle: new Int32Array(appearance, 4, 4),
38
+ texture,
34
39
  };
35
40
  this[transformable_1.transformableState] = {
36
- handle: transformable, values: new Float32Array(buffer),
41
+ handle: transformable,
42
+ values: new Float32Array(buffer),
37
43
  };
38
44
  if (copy) {
39
45
  this[graphics_state_1.spriteState].words.set(copy[graphics_state_1.spriteState].words);
@@ -51,10 +57,12 @@ class SpriteResource extends drawable_1.Drawable {
51
57
  * @ko 텍스처 참조를 교체합니다. resetRect가 true이면 텍스처 영역을 전체 텍스처로 초기화합니다.
52
58
  */
53
59
  setTexture(texture, resetRect = false) {
54
- if (!(texture instanceof texture_1.Texture))
60
+ if (!(texture instanceof texture_1.Texture)) {
55
61
  throw new TypeError('Expected a Texture');
56
- if (typeof resetRect !== 'boolean')
62
+ }
63
+ if (typeof resetRect !== 'boolean') {
57
64
  throw new TypeError('Expected a boolean');
65
+ }
58
66
  const state = this[graphics_state_1.spriteState];
59
67
  if (texture !== state.texture) {
60
68
  native_1.native.setSpriteTexture(this[graphics_state_1.graphicsNative], texture[graphics_state_1.graphicsNative], texture[graphics_state_1.textureId]);
@@ -82,8 +90,9 @@ class SpriteResource extends drawable_1.Drawable {
82
90
  * @ko 텍스처 픽셀 영역을 복사합니다. 너비와 높이는 스프라이트 로컬 크기를 결정하며 음수 값으로 텍스처를 반전할 수 있습니다.
83
91
  */
84
92
  setTextureRect(rectangle) {
85
- if (!(rectangle instanceof rect_1.IntRect))
93
+ if (!(rectangle instanceof rect_1.IntRect)) {
86
94
  throw new TypeError('Expected an IntRect');
95
+ }
87
96
  this[graphics_state_1.spriteState].rectangle.set(rectangle[value_storage_1.rectStorage]);
88
97
  }
89
98
  /**
@@ -107,8 +116,9 @@ class SpriteResource extends drawable_1.Drawable {
107
116
  * @ko 텍스처와 채널별로 곱할 색상을 설정합니다. Alpha로 전체 불투명도를 제어할 수 있습니다.
108
117
  */
109
118
  setColor(color) {
110
- if (!(color instanceof color_1.Color))
119
+ if (!(color instanceof color_1.Color)) {
111
120
  throw new TypeError('Expected a Color');
121
+ }
112
122
  this[graphics_state_1.spriteState].words[5] = color.toInteger();
113
123
  }
114
124
  /**
@@ -134,8 +134,10 @@ class StencilValue {
134
134
  */
135
135
  constructor(value) {
136
136
  const input = value instanceof StencilValue ? value.value : value;
137
- if (!Number.isInteger(input) || typeof input !== 'number' ||
138
- input < -0x80000000 || input > 0xffffffff) {
137
+ if (!Number.isInteger(input) ||
138
+ typeof input !== 'number' ||
139
+ input < -0x80000000 ||
140
+ input > 0xffffffff) {
139
141
  throw new RangeError('Expected a 32-bit stencil value');
140
142
  }
141
143
  (0, numeric_properties_1.numericProperties)(this, {
@@ -160,11 +162,13 @@ class StencilMode {
160
162
  constructor(source = {}) {
161
163
  (0, numeric_properties_1.numericProperties)(this, {
162
164
  stencilComparison: StencilComparison.Always,
163
- stencilUpdateOperation: StencilUpdateOperation.Keep, stencilOnly: false,
165
+ stencilUpdateOperation: StencilUpdateOperation.Keep,
166
+ stencilOnly: false,
164
167
  });
165
- this.stencilComparison = source.stencilComparison ?? StencilComparison.Always;
166
- this.stencilUpdateOperation = source.stencilUpdateOperation ??
167
- StencilUpdateOperation.Keep;
168
+ this.stencilComparison =
169
+ source.stencilComparison ?? StencilComparison.Always;
170
+ this.stencilUpdateOperation =
171
+ source.stencilUpdateOperation ?? StencilUpdateOperation.Keep;
168
172
  this.stencilReference = new StencilValue(source.stencilReference ?? 0);
169
173
  this.stencilMask = new StencilValue(source.stencilMask ?? 0xffffffff);
170
174
  this.stencilOnly = source.stencilOnly ?? false;
@@ -4,8 +4,9 @@ exports.swap = void 0;
4
4
  const texture_1 = require("./texture");
5
5
  const vertex_buffer_1 = require("./vertex-buffer");
6
6
  function swap(left, right) {
7
- if (left instanceof texture_1.Texture && right instanceof texture_1.Texture)
7
+ if (left instanceof texture_1.Texture && right instanceof texture_1.Texture) {
8
8
  left.swap(right);
9
+ }
9
10
  else if (left instanceof vertex_buffer_1.VertexBuffer && right instanceof vertex_buffer_1.VertexBuffer) {
10
11
  left.swap(right);
11
12
  }