@swf2es/player-hosts 0.0.0-stage → 0.1.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 (405) hide show
  1. package/LICENSE +202 -0
  2. package/LICENSE.third-party +759 -0
  3. package/README.md +43 -2
  4. package/dist/indexeddb.d.ts +27 -0
  5. package/dist/indexeddb.d.ts.map +1 -0
  6. package/dist/indexeddb.js +170 -0
  7. package/dist/indexeddb.js.map +1 -0
  8. package/dist/node-worker.d.ts +2 -0
  9. package/dist/node-worker.d.ts.map +1 -0
  10. package/dist/node-worker.js +12 -0
  11. package/dist/node-worker.js.map +1 -0
  12. package/dist/node.d.ts +8 -0
  13. package/dist/node.d.ts.map +1 -0
  14. package/dist/node.js +43 -0
  15. package/dist/node.js.map +1 -0
  16. package/dist/precompiled.d.ts +31 -0
  17. package/dist/precompiled.d.ts.map +1 -0
  18. package/dist/precompiled.js +125 -0
  19. package/dist/precompiled.js.map +1 -0
  20. package/dist/stage3d.d.ts +13 -0
  21. package/dist/stage3d.d.ts.map +1 -0
  22. package/dist/stage3d.js +61 -0
  23. package/dist/stage3d.js.map +1 -0
  24. package/dist/thread/codegen/codegen.js +308 -0
  25. package/dist/thread/codegen/index.js +405 -0
  26. package/dist/thread/format/abc-names.js +126 -0
  27. package/dist/thread/format/actions.js +222 -0
  28. package/dist/thread/format/air-descriptor.js +63 -0
  29. package/dist/thread/format/api-versions.js +22 -0
  30. package/dist/thread/format/bitmap.js +199 -0
  31. package/dist/thread/format/button.js +60 -0
  32. package/dist/thread/format/compression.js +200 -0
  33. package/dist/thread/format/display.js +305 -0
  34. package/dist/thread/format/filters.js +136 -0
  35. package/dist/thread/format/font.js +168 -0
  36. package/dist/thread/format/index.js +26 -0
  37. package/dist/thread/format/pbj.js +484 -0
  38. package/dist/thread/format/shape.js +411 -0
  39. package/dist/thread/format/sound.js +91 -0
  40. package/dist/thread/format/swf.js +163 -0
  41. package/dist/thread/format/tags.js +58 -0
  42. package/dist/thread/format/text.js +135 -0
  43. package/dist/thread/format/zip.js +91 -0
  44. package/dist/thread/native/audio/binary.js +3 -0
  45. package/dist/thread/native/audio/index.js +72 -0
  46. package/dist/thread/native/base64.js +9 -0
  47. package/dist/thread/native/compress/binary.js +3 -0
  48. package/dist/thread/native/compress/index.js +145 -0
  49. package/dist/thread/native/instance.js +49 -0
  50. package/dist/thread/native/mp3/binary.js +3 -0
  51. package/dist/thread/native/mp3/index.js +48 -0
  52. package/dist/thread/native/render/binary.js +3 -0
  53. package/dist/thread/native/render/bitmap-kernel.js +591 -0
  54. package/dist/thread/native/render/draw-kernel.js +204 -0
  55. package/dist/thread/native/render/dxt-encoder.js +94 -0
  56. package/dist/thread/native/render/index.js +10 -0
  57. package/dist/thread/native/render/lines.js +122 -0
  58. package/dist/thread/native/render/module.js +26 -0
  59. package/dist/thread/native/render/pixel-ops.js +235 -0
  60. package/dist/thread/native/render/tessellator.js +250 -0
  61. package/dist/thread/player/avm1/amf.js +507 -0
  62. package/dist/thread/player/avm1/avm1.js +1304 -0
  63. package/dist/thread/player/avm1/bindings.js +214 -0
  64. package/dist/thread/player/avm1/classes.js +75 -0
  65. package/dist/thread/player/avm1/clips.js +229 -0
  66. package/dist/thread/player/avm1/compile.js +140 -0
  67. package/dist/thread/player/avm1/external.js +79 -0
  68. package/dist/thread/player/avm1/focus.js +278 -0
  69. package/dist/thread/player/avm1/globals/BitmapData.js +542 -0
  70. package/dist/thread/player/avm1/globals/Button.js +31 -0
  71. package/dist/thread/player/avm1/globals/Color.js +115 -0
  72. package/dist/thread/player/avm1/globals/ExternalInterface.js +310 -0
  73. package/dist/thread/player/avm1/globals/FileReference.js +217 -0
  74. package/dist/thread/player/avm1/globals/Key.js +60 -0
  75. package/dist/thread/player/avm1/globals/LoadVars.js +208 -0
  76. package/dist/thread/player/avm1/globals/LocalConnection.js +92 -0
  77. package/dist/thread/player/avm1/globals/MovieClip.js +1070 -0
  78. package/dist/thread/player/avm1/globals/MovieClipLoader.js +90 -0
  79. package/dist/thread/player/avm1/globals/NetConnection.js +261 -0
  80. package/dist/thread/player/avm1/globals/PrintJob.js +37 -0
  81. package/dist/thread/player/avm1/globals/Selection.js +62 -0
  82. package/dist/thread/player/avm1/globals/SharedObject.js +245 -0
  83. package/dist/thread/player/avm1/globals/Sound.js +238 -0
  84. package/dist/thread/player/avm1/globals/Stage.js +12 -0
  85. package/dist/thread/player/avm1/globals/StyleSheet.js +205 -0
  86. package/dist/thread/player/avm1/globals/TextField.js +396 -0
  87. package/dist/thread/player/avm1/globals/TextFormat.js +194 -0
  88. package/dist/thread/player/avm1/globals/TextSnapshot.js +88 -0
  89. package/dist/thread/player/avm1/globals/XML.js +396 -0
  90. package/dist/thread/player/avm1/globals/XMLNode.js +413 -0
  91. package/dist/thread/player/avm1/globals/XMLSocket.js +205 -0
  92. package/dist/thread/player/avm1/globals/drawing.js +202 -0
  93. package/dist/thread/player/avm1/globals/filters.js +635 -0
  94. package/dist/thread/player/avm1/globals/geom.js +600 -0
  95. package/dist/thread/player/avm1/input.js +483 -0
  96. package/dist/thread/player/avm1/keyboard.js +113 -0
  97. package/dist/thread/player/avm1/loads.js +352 -0
  98. package/dist/thread/player/avm1/net.js +219 -0
  99. package/dist/thread/player/avm1/paths.js +104 -0
  100. package/dist/thread/player/avm1/pointer.js +512 -0
  101. package/dist/thread/player/avm1/queue.js +303 -0
  102. package/dist/thread/player/avm1/sound.js +106 -0
  103. package/dist/thread/player/avm1/swf.js +141 -0
  104. package/dist/thread/player/avm1/timers.js +113 -0
  105. package/dist/thread/player/bitmap/bitmap.js +627 -0
  106. package/dist/thread/player/bitmap/draw.js +68 -0
  107. package/dist/thread/player/bitmap/dxt.js +11 -0
  108. package/dist/thread/player/bitmap/filters.js +656 -0
  109. package/dist/thread/player/bitmap/images.js +240 -0
  110. package/dist/thread/player/bitmap/kernel.js +65 -0
  111. package/dist/thread/player/bitmap/ops.js +1239 -0
  112. package/dist/thread/player/bitmap/pixel-bender.js +911 -0
  113. package/dist/thread/player/bitmap/png.js +139 -0
  114. package/dist/thread/player/bitmap/turbulence.js +89 -0
  115. package/dist/thread/player/clock.js +182 -0
  116. package/dist/thread/player/display/bitmapobject.js +25 -0
  117. package/dist/thread/player/display/bounds.js +520 -0
  118. package/dist/thread/player/display/buttonobject.js +305 -0
  119. package/dist/thread/player/display/color.js +40 -0
  120. package/dist/thread/player/display/container.js +150 -0
  121. package/dist/thread/player/display/display.js +14 -0
  122. package/dist/thread/player/display/displayobject.js +664 -0
  123. package/dist/thread/player/display/drawing.js +613 -0
  124. package/dist/thread/player/display/filters.js +285 -0
  125. package/dist/thread/player/display/geometry.js +189 -0
  126. package/dist/thread/player/display/gradients.js +117 -0
  127. package/dist/thread/player/display/graphicsdata.js +592 -0
  128. package/dist/thread/player/display/instantiate.js +71 -0
  129. package/dist/thread/player/display/matrix3d.js +373 -0
  130. package/dist/thread/player/display/morph.js +226 -0
  131. package/dist/thread/player/display/movieclip.js +680 -0
  132. package/dist/thread/player/display/perspective.js +193 -0
  133. package/dist/thread/player/display/scale9.js +236 -0
  134. package/dist/thread/player/display/shapeobject.js +131 -0
  135. package/dist/thread/player/display/shapes.js +407 -0
  136. package/dist/thread/player/display/textobjects.js +222 -0
  137. package/dist/thread/player/display/timeline.js +471 -0
  138. package/dist/thread/player/display/value-lists.js +40 -0
  139. package/dist/thread/player/display/videoobject.js +6 -0
  140. package/dist/thread/player/display/walk.js +127 -0
  141. package/dist/thread/player/files.js +334 -0
  142. package/dist/thread/player/hosts.js +207 -0
  143. package/dist/thread/player/input/avm1.js +82 -0
  144. package/dist/thread/player/input/context-menu.js +63 -0
  145. package/dist/thread/player/input/keyboard.js +458 -0
  146. package/dist/thread/player/input/pointer.js +863 -0
  147. package/dist/thread/player/input/text-editor.js +319 -0
  148. package/dist/thread/player/input/touch.js +209 -0
  149. package/dist/thread/player/localconnection.js +90 -0
  150. package/dist/thread/player/media/audio.js +376 -0
  151. package/dist/thread/player/media/dynamic-sound.js +90 -0
  152. package/dist/thread/player/media/extract.js +135 -0
  153. package/dist/thread/player/media/mp3.js +152 -0
  154. package/dist/thread/player/media/sounds.js +507 -0
  155. package/dist/thread/player/media/streaming-audio.js +133 -0
  156. package/dist/thread/player/player.js +616 -0
  157. package/dist/thread/player/playerglobal/air/net/WebSocket.js +250 -0
  158. package/dist/thread/player/playerglobal/air-library.js +8 -0
  159. package/dist/thread/player/playerglobal/flash/accessibility/Accessibility.js +21 -0
  160. package/dist/thread/player/playerglobal/flash/crypto/generateRandomBytes.js +32 -0
  161. package/dist/thread/player/playerglobal/flash/data/EncryptedLocalStore.js +61 -0
  162. package/dist/thread/player/playerglobal/flash/desktop/Clipboard.js +173 -0
  163. package/dist/thread/player/playerglobal/flash/desktop/NativeApplication.js +179 -0
  164. package/dist/thread/player/playerglobal/flash/display/AVM1Movie.js +19 -0
  165. package/dist/thread/player/playerglobal/flash/display/Bitmap.js +58 -0
  166. package/dist/thread/player/playerglobal/flash/display/BitmapData.js +633 -0
  167. package/dist/thread/player/playerglobal/flash/display/DisplayObject.js +614 -0
  168. package/dist/thread/player/playerglobal/flash/display/DisplayObjectContainer.js +224 -0
  169. package/dist/thread/player/playerglobal/flash/display/Graphics.js +345 -0
  170. package/dist/thread/player/playerglobal/flash/display/InteractiveObject.js +87 -0
  171. package/dist/thread/player/playerglobal/flash/display/Loader.js +79 -0
  172. package/dist/thread/player/playerglobal/flash/display/LoaderInfo.js +128 -0
  173. package/dist/thread/player/playerglobal/flash/display/MovieClip.js +194 -0
  174. package/dist/thread/player/playerglobal/flash/display/NativeWindow.js +245 -0
  175. package/dist/thread/player/playerglobal/flash/display/Shader.js +26 -0
  176. package/dist/thread/player/playerglobal/flash/display/ShaderData.js +85 -0
  177. package/dist/thread/player/playerglobal/flash/display/ShaderInput.js +64 -0
  178. package/dist/thread/player/playerglobal/flash/display/ShaderJob.js +181 -0
  179. package/dist/thread/player/playerglobal/flash/display/ShaderParameter.js +23 -0
  180. package/dist/thread/player/playerglobal/flash/display/Shape.js +13 -0
  181. package/dist/thread/player/playerglobal/flash/display/SimpleButton.js +103 -0
  182. package/dist/thread/player/playerglobal/flash/display/Sprite.js +84 -0
  183. package/dist/thread/player/playerglobal/flash/display/Stage.js +231 -0
  184. package/dist/thread/player/playerglobal/flash/display/Stage3D.js +54 -0
  185. package/dist/thread/player/playerglobal/flash/display/shaders.js +228 -0
  186. package/dist/thread/player/playerglobal/flash/events/Event.js +58 -0
  187. package/dist/thread/player/playerglobal/flash/events/EventDispatcher.js +103 -0
  188. package/dist/thread/player/playerglobal/flash/events/GestureEvent.js +34 -0
  189. package/dist/thread/player/playerglobal/flash/events/HTTPStatusEvent.js +8 -0
  190. package/dist/thread/player/playerglobal/flash/events/KeyboardEvent.js +51 -0
  191. package/dist/thread/player/playerglobal/flash/events/MouseEvent.js +59 -0
  192. package/dist/thread/player/playerglobal/flash/events/PressAndTapGestureEvent.js +30 -0
  193. package/dist/thread/player/playerglobal/flash/events/TimerEvent.js +16 -0
  194. package/dist/thread/player/playerglobal/flash/events/TouchEvent.js +45 -0
  195. package/dist/thread/player/playerglobal/flash/external/ExternalInterface.js +73 -0
  196. package/dist/thread/player/playerglobal/flash/filesystem/File.js +340 -0
  197. package/dist/thread/player/playerglobal/flash/filesystem/FileStream.js +453 -0
  198. package/dist/thread/player/playerglobal/flash/filesystem/paths.js +156 -0
  199. package/dist/thread/player/playerglobal/flash/filesystem/writes.js +143 -0
  200. package/dist/thread/player/playerglobal/flash/filters/BevelFilter.js +4 -0
  201. package/dist/thread/player/playerglobal/flash/filters/BitmapFilter.js +205 -0
  202. package/dist/thread/player/playerglobal/flash/filters/BlurFilter.js +4 -0
  203. package/dist/thread/player/playerglobal/flash/filters/ColorMatrixFilter.js +11 -0
  204. package/dist/thread/player/playerglobal/flash/filters/ConvolutionFilter.js +26 -0
  205. package/dist/thread/player/playerglobal/flash/filters/DisplacementMapFilter.js +51 -0
  206. package/dist/thread/player/playerglobal/flash/filters/DropShadowFilter.js +4 -0
  207. package/dist/thread/player/playerglobal/flash/filters/GlowFilter.js +4 -0
  208. package/dist/thread/player/playerglobal/flash/filters/GradientBevelFilter.js +4 -0
  209. package/dist/thread/player/playerglobal/flash/filters/GradientGlowFilter.js +4 -0
  210. package/dist/thread/player/playerglobal/flash/filters/ShaderFilter.js +53 -0
  211. package/dist/thread/player/playerglobal/flash/geom/Matrix3D.js +361 -0
  212. package/dist/thread/player/playerglobal/flash/geom/PerspectiveProjection.js +122 -0
  213. package/dist/thread/player/playerglobal/flash/geom/Transform.js +245 -0
  214. package/dist/thread/player/playerglobal/flash/geom/Utils3D.js +85 -0
  215. package/dist/thread/player/playerglobal/flash/globalization/Collator.js +149 -0
  216. package/dist/thread/player/playerglobal/flash/globalization/CurrencyFormatter.js +272 -0
  217. package/dist/thread/player/playerglobal/flash/globalization/CurrencyParseResult.js +21 -0
  218. package/dist/thread/player/playerglobal/flash/globalization/DateTimeFormatter.js +463 -0
  219. package/dist/thread/player/playerglobal/flash/globalization/LocaleID.js +144 -0
  220. package/dist/thread/player/playerglobal/flash/globalization/NumberFormatter.js +444 -0
  221. package/dist/thread/player/playerglobal/flash/globalization/NumberParseResult.js +22 -0
  222. package/dist/thread/player/playerglobal/flash/globalization/StringTools.js +59 -0
  223. package/dist/thread/player/playerglobal/flash/globalization/locale.js +190 -0
  224. package/dist/thread/player/playerglobal/flash/media/Camera.js +89 -0
  225. package/dist/thread/player/playerglobal/flash/media/Microphone.js +126 -0
  226. package/dist/thread/player/playerglobal/flash/media/Sound.js +543 -0
  227. package/dist/thread/player/playerglobal/flash/media/SoundMixer.js +74 -0
  228. package/dist/thread/player/playerglobal/flash/media/SoundTransform.js +40 -0
  229. package/dist/thread/player/playerglobal/flash/media/Video.js +43 -0
  230. package/dist/thread/player/playerglobal/flash/net/FileFilter.js +27 -0
  231. package/dist/thread/player/playerglobal/flash/net/FileReference.js +197 -0
  232. package/dist/thread/player/playerglobal/flash/net/LocalConnection.js +167 -0
  233. package/dist/thread/player/playerglobal/flash/net/NetConnection.js +155 -0
  234. package/dist/thread/player/playerglobal/flash/net/SharedObject.js +299 -0
  235. package/dist/thread/player/playerglobal/flash/net/Socket.js +282 -0
  236. package/dist/thread/player/playerglobal/flash/net/URLRequest.js +93 -0
  237. package/dist/thread/player/playerglobal/flash/net/URLStream.js +146 -0
  238. package/dist/thread/player/playerglobal/flash/net/XMLSocket.js +14 -0
  239. package/dist/thread/player/playerglobal/flash/net/local-modern.js +142 -0
  240. package/dist/thread/player/playerglobal/flash/net/local-values.js +217 -0
  241. package/dist/thread/player/playerglobal/flash/net/navigateToURL.js +29 -0
  242. package/dist/thread/player/playerglobal/flash/profiler/Telemetry.js +25 -0
  243. package/dist/thread/player/playerglobal/flash/sensors/Accelerometer.js +12 -0
  244. package/dist/thread/player/playerglobal/flash/system/ApplicationDomain.js +69 -0
  245. package/dist/thread/player/playerglobal/flash/system/Capabilities.js +163 -0
  246. package/dist/thread/player/playerglobal/flash/system/FSCommandHost.js +17 -0
  247. package/dist/thread/player/playerglobal/flash/system/Security.js +46 -0
  248. package/dist/thread/player/playerglobal/flash/system/SecurityDomain.js +21 -0
  249. package/dist/thread/player/playerglobal/flash/system/System.js +73 -0
  250. package/dist/thread/player/playerglobal/flash/system/Worker.js +112 -0
  251. package/dist/thread/player/playerglobal/flash/text/Font.js +95 -0
  252. package/dist/thread/player/playerglobal/flash/text/StaticText.js +16 -0
  253. package/dist/thread/player/playerglobal/flash/text/StyleSheet.js +65 -0
  254. package/dist/thread/player/playerglobal/flash/text/TextField.js +707 -0
  255. package/dist/thread/player/playerglobal/flash/text/TextRenderer.js +77 -0
  256. package/dist/thread/player/playerglobal/flash/text/engine/FontDescription.js +141 -0
  257. package/dist/thread/player/playerglobal/flash/text/engine/TabStop.js +46 -0
  258. package/dist/thread/player/playerglobal/flash/trace/Trace.js +17 -0
  259. package/dist/thread/player/playerglobal/flash/ui/ContextMenu.js +17 -0
  260. package/dist/thread/player/playerglobal/flash/ui/GameInput.js +19 -0
  261. package/dist/thread/player/playerglobal/flash/ui/Keyboard.js +27 -0
  262. package/dist/thread/player/playerglobal/flash/ui/Mouse.js +127 -0
  263. package/dist/thread/player/playerglobal/flash/ui/Multitouch.js +46 -0
  264. package/dist/thread/player/playerglobal/flash/utils/ByteArray.js +155 -0
  265. package/dist/thread/player/playerglobal/flash/utils/Timer.js +25 -0
  266. package/dist/thread/player/playerglobal/flash/xml/XMLDocument.js +74 -0
  267. package/dist/thread/player/playerglobal/index.js +224 -0
  268. package/dist/thread/player/playerglobal/libraries.js +10 -0
  269. package/dist/thread/player/playerglobal/playerglobal-library.js +22 -0
  270. package/dist/thread/player/playerglobal/toplevel.js +122 -0
  271. package/dist/thread/player/scripting/clipboard.js +146 -0
  272. package/dist/thread/player/scripting/code.js +900 -0
  273. package/dist/thread/player/scripting/evaluate.js +144 -0
  274. package/dist/thread/player/scripting/events.js +172 -0
  275. package/dist/thread/player/scripting/handover.js +182 -0
  276. package/dist/thread/player/scripting/lazy.js +38 -0
  277. package/dist/thread/player/scripting/lifecycle.js +272 -0
  278. package/dist/thread/player/scripting/loads.js +860 -0
  279. package/dist/thread/player/scripting/sha256.js +95 -0
  280. package/dist/thread/player/scripting/symbols.js +348 -0
  281. package/dist/thread/player/scripting/timers.js +434 -0
  282. package/dist/thread/player/scripting/workers.js +923 -0
  283. package/dist/thread/player/scripting.js +1018 -0
  284. package/dist/thread/player/stage.js +4 -0
  285. package/dist/thread/player/text/csm.js +113 -0
  286. package/dist/thread/player/text/css.js +167 -0
  287. package/dist/thread/player/text/fonts.js +97 -0
  288. package/dist/thread/player/text/layout.js +393 -0
  289. package/dist/thread/player/text/static.js +109 -0
  290. package/dist/thread/player/text/text.js +431 -0
  291. package/dist/thread/player/workers/thread.js +159 -0
  292. package/dist/thread/player/workers/wire.js +198 -0
  293. package/dist/thread/player-hosts/web-worker.js +19 -0
  294. package/dist/thread/runtime/avm1/activation.js +89 -0
  295. package/dist/thread/runtime/avm1/case.js +249 -0
  296. package/dist/thread/runtime/avm1/clips.js +334 -0
  297. package/dist/thread/runtime/avm1/control.js +280 -0
  298. package/dist/thread/runtime/avm1/errors.js +50 -0
  299. package/dist/thread/runtime/avm1/functions.js +249 -0
  300. package/dist/thread/runtime/avm1/globals/array.js +549 -0
  301. package/dist/thread/runtime/avm1/globals/broadcaster.js +131 -0
  302. package/dist/thread/runtime/avm1/globals/date.js +436 -0
  303. package/dist/thread/runtime/avm1/globals/global.js +344 -0
  304. package/dist/thread/runtime/avm1/globals/math.js +139 -0
  305. package/dist/thread/runtime/avm1/globals/number.js +93 -0
  306. package/dist/thread/runtime/avm1/globals/string.js +201 -0
  307. package/dist/thread/runtime/avm1/globals/timers.js +129 -0
  308. package/dist/thread/runtime/avm1/host.js +5 -0
  309. package/dist/thread/runtime/avm1/index.js +14 -0
  310. package/dist/thread/runtime/avm1/inheritance.js +132 -0
  311. package/dist/thread/runtime/avm1/numbers.js +298 -0
  312. package/dist/thread/runtime/avm1/objects.js +896 -0
  313. package/dist/thread/runtime/avm1/operators.js +170 -0
  314. package/dist/thread/runtime/avm1/realm.js +529 -0
  315. package/dist/thread/runtime/avm1/runtime.js +882 -0
  316. package/dist/thread/runtime/avm1/scope.js +385 -0
  317. package/dist/thread/runtime/avm1/urls.js +180 -0
  318. package/dist/thread/runtime/avm1/values.js +97 -0
  319. package/dist/thread/runtime/avm2/amf-classes.js +66 -0
  320. package/dist/thread/runtime/avm2/amf.js +801 -0
  321. package/dist/thread/runtime/avm2/array-conversion.js +100 -0
  322. package/dist/thread/runtime/avm2/builtin-library.js +21 -0
  323. package/dist/thread/runtime/avm2/cache-fill.js +86 -0
  324. package/dist/thread/runtime/avm2/classes.js +211 -0
  325. package/dist/thread/runtime/avm2/definitions.js +69 -0
  326. package/dist/thread/runtime/avm2/descriptors.js +5 -0
  327. package/dist/thread/runtime/avm2/dictionary-keys.js +295 -0
  328. package/dist/thread/runtime/avm2/domain-memory.js +75 -0
  329. package/dist/thread/runtime/avm2/domain.js +280 -0
  330. package/dist/thread/runtime/avm2/dynamic-properties.js +182 -0
  331. package/dist/thread/runtime/avm2/enumeration.js +393 -0
  332. package/dist/thread/runtime/avm2/errors.js +45 -0
  333. package/dist/thread/runtime/avm2/float-library.js +66 -0
  334. package/dist/thread/runtime/avm2/float.js +26 -0
  335. package/dist/thread/runtime/avm2/hooks.js +19 -0
  336. package/dist/thread/runtime/avm2/index.js +38 -0
  337. package/dist/thread/runtime/avm2/messages.js +177 -0
  338. package/dist/thread/runtime/avm2/method-factories.js +95 -0
  339. package/dist/thread/runtime/avm2/modules.js +105 -0
  340. package/dist/thread/runtime/avm2/names.js +248 -0
  341. package/dist/thread/runtime/avm2/natives/aliases.js +47 -0
  342. package/dist/thread/runtime/avm2/natives/array.js +390 -0
  343. package/dist/thread/runtime/avm2/natives/bytearray.js +1227 -0
  344. package/dist/thread/runtime/avm2/natives/case.js +88 -0
  345. package/dist/thread/runtime/avm2/natives/concurrent.js +199 -0
  346. package/dist/thread/runtime/avm2/natives/date.js +581 -0
  347. package/dist/thread/runtime/avm2/natives/define.js +130 -0
  348. package/dist/thread/runtime/avm2/natives/describe.js +351 -0
  349. package/dist/thread/runtime/avm2/natives/dictionary.js +12 -0
  350. package/dist/thread/runtime/avm2/natives/float-vector.js +81 -0
  351. package/dist/thread/runtime/avm2/natives/float.js +96 -0
  352. package/dist/thread/runtime/avm2/natives/index.js +64 -0
  353. package/dist/thread/runtime/avm2/natives/json.js +514 -0
  354. package/dist/thread/runtime/avm2/natives/number.js +162 -0
  355. package/dist/thread/runtime/avm2/natives/object.js +237 -0
  356. package/dist/thread/runtime/avm2/natives/proxy.js +75 -0
  357. package/dist/thread/runtime/avm2/natives/regexp.js +485 -0
  358. package/dist/thread/runtime/avm2/natives/shell-workers.js +404 -0
  359. package/dist/thread/runtime/avm2/natives/shell.js +557 -0
  360. package/dist/thread/runtime/avm2/natives/sort.js +377 -0
  361. package/dist/thread/runtime/avm2/natives/string.js +132 -0
  362. package/dist/thread/runtime/avm2/natives/sync.js +821 -0
  363. package/dist/thread/runtime/avm2/natives/toplevel.js +139 -0
  364. package/dist/thread/runtime/avm2/natives/vector-elements.js +46 -0
  365. package/dist/thread/runtime/avm2/natives/vector.js +406 -0
  366. package/dist/thread/runtime/avm2/natives/xml/access.js +633 -0
  367. package/dist/thread/runtime/avm2/natives/xml/build.js +291 -0
  368. package/dist/thread/runtime/avm2/natives/xml/chars.js +112 -0
  369. package/dist/thread/runtime/avm2/natives/xml/escape.js +38 -0
  370. package/dist/thread/runtime/avm2/natives/xml/names.js +204 -0
  371. package/dist/thread/runtime/avm2/natives/xml/node.js +272 -0
  372. package/dist/thread/runtime/avm2/natives/xml/operators.js +69 -0
  373. package/dist/thread/runtime/avm2/natives/xml/parser.js +356 -0
  374. package/dist/thread/runtime/avm2/natives/xml/strings.js +191 -0
  375. package/dist/thread/runtime/avm2/natives/xml/values.js +122 -0
  376. package/dist/thread/runtime/avm2/natives/xml/xml.js +645 -0
  377. package/dist/thread/runtime/avm2/number-strings.js +110 -0
  378. package/dist/thread/runtime/avm2/numbers.js +558 -0
  379. package/dist/thread/runtime/avm2/options.js +16 -0
  380. package/dist/thread/runtime/avm2/player-messages.js +550 -0
  381. package/dist/thread/runtime/avm2/property-cache.js +135 -0
  382. package/dist/thread/runtime/avm2/runtime.js +2644 -0
  383. package/dist/thread/runtime/avm2/traits.js +509 -0
  384. package/dist/thread/runtime/index.js +7 -0
  385. package/dist/web-worker.d.ts +2 -0
  386. package/dist/web-worker.d.ts.map +1 -0
  387. package/dist/web-worker.js +20 -0
  388. package/dist/web-worker.js.map +1 -0
  389. package/dist/websocket.d.ts +4 -0
  390. package/dist/websocket.d.ts.map +1 -0
  391. package/dist/websocket.js +27 -0
  392. package/dist/websocket.js.map +1 -0
  393. package/dist/workers.d.ts +35 -0
  394. package/dist/workers.d.ts.map +1 -0
  395. package/dist/workers.js +171 -0
  396. package/dist/workers.js.map +1 -0
  397. package/package.json +62 -3
  398. package/src/indexeddb.ts +227 -0
  399. package/src/node-worker.ts +13 -0
  400. package/src/node.ts +49 -0
  401. package/src/precompiled.ts +166 -0
  402. package/src/stage3d.ts +76 -0
  403. package/src/web-worker.ts +24 -0
  404. package/src/websocket.ts +32 -0
  405. package/src/workers.ts +255 -0
@@ -0,0 +1,204 @@
1
+ // BitmapData.draw of a bitmap in the normal blend mode, in the render
2
+ // module (draw.zig), one call a draw. Each draw copies into the module's
3
+ // input the rows of the source it reads and the destination's area, and
4
+ // the area back out after: no source is kept between draws, which costs no
5
+ // more than keeping them did for a game drawing hundreds of small bitmaps
6
+ // a frame, and holds nothing for them. Its own instance, so that the
7
+ // filters' calls (BitmapKernel) do not reset its input, let go of when its
8
+ // owner says it went idle, and after a draw that grew it past KEEP_BYTES.
9
+ import { renderInstance } from "./module.js";
10
+ /** draw.zig's flags. */
11
+ export const DRAW_SMOOTH = 1;
12
+ export const DRAW_TRANSFORM = 2;
13
+ export const DRAW_OPAQUE = 4;
14
+ export const DRAW_SKIP_ZERO_ALPHA = 8;
15
+ // draw.zig's results.
16
+ const INVALID = 0;
17
+ const WRITTEN = 2;
18
+ /** draw.zig's DrawParams: 14 doubles, then 14 words. */
19
+ const PARAMS = 168;
20
+ /** The most a draw copies in, its source's rows and its area; a larger one is drawn by the caller. */
21
+ const DRAWN_BYTES = 32 << 20;
22
+ /** The input a new instance takes first. */
23
+ const FIRST_BYTES = 1 << 20;
24
+ /** The memory an instance keeps after a draw; past it, the instance is let go of. */
25
+ const KEEP_BYTES = 16 << 20;
26
+ export class DrawKernel {
27
+ wasm = null;
28
+ /** Whether making an instance failed once, after which the module is never tried again. */
29
+ broken = false;
30
+ /** The input resetArena gave, and its bytes. */
31
+ input = 0;
32
+ inputBytes = 0;
33
+ buffer = null;
34
+ words = new Uint32Array(0);
35
+ doubles = new Float64Array(0);
36
+ ints = new Int32Array(0);
37
+ /** Where the last draw's area lies in the input. */
38
+ area = 0;
39
+ /** Whether the module drew since `idle` last asked. */
40
+ busy = false;
41
+ /** How many draws the module took. */
42
+ drawn = 0;
43
+ /** A job to fill for each draw. */
44
+ static job() {
45
+ return {
46
+ source: new Uint32Array(0),
47
+ sourceWidth: 0,
48
+ sourceHeight: 0,
49
+ sourceTop: 0,
50
+ sourceRows: 0,
51
+ into: new Uint32Array(0),
52
+ intoWidth: 0,
53
+ x: 0,
54
+ y: 0,
55
+ width: 0,
56
+ height: 0,
57
+ moved: false,
58
+ inverse: new Float64Array(6),
59
+ transform: new Float64Array(8),
60
+ tx: 0,
61
+ ty: 0,
62
+ flags: 0,
63
+ };
64
+ }
65
+ /** Whether an instance is held, with its memory. */
66
+ get held() {
67
+ return this.wasm !== null;
68
+ }
69
+ /** The job drawn in the module; never a write to the destination, which `writeBack` makes. */
70
+ draw(job) {
71
+ try {
72
+ return this.run(job);
73
+ }
74
+ catch {
75
+ // A trap: never resume that instance.
76
+ this.release();
77
+ return "refused";
78
+ }
79
+ }
80
+ /** The area the last draw wrote, copied into `into`. */
81
+ writeBack(job, into) {
82
+ const { x, y, width: w, height: h, intoWidth } = job;
83
+ const base = this.area >> 2;
84
+ this.refresh();
85
+ const words = this.words;
86
+ for (let row = 0; row < h; row++) {
87
+ const at = base + row * w;
88
+ into.set(words.subarray(at, at + w), (y + row) * intoWidth + x);
89
+ }
90
+ }
91
+ /** Whether the module drew nothing since this was last asked. */
92
+ idle() {
93
+ const idle = !this.busy;
94
+ this.busy = false;
95
+ return idle;
96
+ }
97
+ /** The instance let go of, and its memory with it; the next draw makes another. */
98
+ release() {
99
+ this.wasm = null;
100
+ this.buffer = null;
101
+ this.words = new Uint32Array(0);
102
+ this.doubles = new Float64Array(0);
103
+ this.ints = new Int32Array(0);
104
+ this.input = 0;
105
+ this.inputBytes = 0;
106
+ }
107
+ run(job) {
108
+ const { sourceWidth: sw, sourceRows: rows, width: w, height: h } = job;
109
+ const sourceBytes = sw * rows * 4;
110
+ const areaBytes = w * h * 4;
111
+ if (job.source.length !== sw * job.sourceHeight ||
112
+ sourceBytes + areaBytes > DRAWN_BYTES ||
113
+ !this.room(PARAMS + sourceBytes + areaBytes)) {
114
+ return "refused";
115
+ }
116
+ const wasm = this.wasm;
117
+ this.refresh();
118
+ const { words, doubles, ints } = this;
119
+ const p = this.input;
120
+ const src = p + PARAMS;
121
+ this.area = src + sourceBytes;
122
+ const top = job.sourceTop * sw;
123
+ words.set(job.source.subarray(top, top + rows * sw), src >> 2);
124
+ const base = this.area >> 2;
125
+ const { into, intoWidth, x, y } = job;
126
+ for (let row = 0; row < h; row++) {
127
+ const at = (y + row) * intoWidth + x;
128
+ words.set(into.subarray(at, at + w), base + row * w);
129
+ }
130
+ const d = p >> 3;
131
+ doubles.set(job.inverse, d);
132
+ doubles.set(job.transform, d + 6);
133
+ const i = (p + 112) >> 2;
134
+ words[i] = src;
135
+ words[i + 1] = sw;
136
+ words[i + 2] = job.sourceHeight;
137
+ words[i + 3] = this.area;
138
+ ints[i + 4] = x;
139
+ ints[i + 5] = y;
140
+ words[i + 6] = w;
141
+ words[i + 7] = h;
142
+ words[i + 8] = job.flags;
143
+ ints[i + 9] = job.tx;
144
+ ints[i + 10] = job.ty;
145
+ words[i + 11] = job.sourceTop;
146
+ words[i + 12] = rows;
147
+ words[i + 13] = 0;
148
+ const result = job.moved ? wasm.compositePixels(p) : wasm.drawPixels(p);
149
+ if (result === INVALID) {
150
+ return "refused";
151
+ }
152
+ this.drawn++;
153
+ this.busy = true;
154
+ return result === WRITTEN ? "written" : "untouched";
155
+ }
156
+ /**
157
+ * Whether the input holds `bytes`: an instance made where there is none,
158
+ * one grown past KEEP_BYTES made anew, and the input taken anew where it
159
+ * is smaller.
160
+ */
161
+ room(bytes) {
162
+ if (this.broken) {
163
+ return false;
164
+ }
165
+ // Grown past what it keeps by a large draw before, it goes, and its memory with it.
166
+ if (this.wasm && this.wasm.memory.buffer.byteLength > KEEP_BYTES) {
167
+ this.release();
168
+ }
169
+ if (this.wasm && this.inputBytes >= bytes) {
170
+ return true;
171
+ }
172
+ if (!this.wasm) {
173
+ try {
174
+ this.wasm = renderInstance(() => {
175
+ throw new Error("the draw kernel takes no tessellator");
176
+ });
177
+ }
178
+ catch {
179
+ this.broken = true;
180
+ return false;
181
+ }
182
+ }
183
+ // Half again what is asked, so that a few larger draws do not each take it anew.
184
+ const want = Math.max(FIRST_BYTES, bytes + (bytes >> 1));
185
+ this.input = this.wasm.resetArena(want);
186
+ if (!this.input) {
187
+ // Out of memory: the instance goes, and the next draw that fits makes another.
188
+ this.release();
189
+ return false;
190
+ }
191
+ this.inputBytes = want;
192
+ return true;
193
+ }
194
+ /** The views of the memory made again where it grew, which detached them. */
195
+ refresh() {
196
+ const buffer = this.wasm.memory.buffer;
197
+ if (buffer !== this.buffer) {
198
+ this.buffer = buffer;
199
+ this.words = new Uint32Array(buffer);
200
+ this.doubles = new Float64Array(buffer);
201
+ this.ints = new Int32Array(buffer);
202
+ }
203
+ }
204
+ }
@@ -0,0 +1,94 @@
1
+ // Compressed texture uploads, one whole level at a time in dxt.zig. The
2
+ // input is kept between levels and grown only as needed; the result is a
3
+ // view to consume before the next call, as context3d's TS encoder gives.
4
+ import { renderInstance } from "./module.js";
5
+ /** Enough to keep a 2048² DXT5 upload's input and output, including growth slack. */
6
+ const KEEP_BYTES = 32 << 20;
7
+ const FIRST_BYTES = 64 << 10;
8
+ export class DxtEncoder {
9
+ wasm = null;
10
+ broken = false;
11
+ input = 0;
12
+ inputBytes = 0;
13
+ /** Successful native encodes, so a reference comparison can rule out falling back. */
14
+ encoded = 0;
15
+ /** The memory kept now: a larger level's instance goes before the next call. */
16
+ get capacity() {
17
+ return this.wasm?.memory.buffer.byteLength ?? 0;
18
+ }
19
+ /** Release the instance and its memory; the next level makes another. */
20
+ release() {
21
+ this.wasm = null;
22
+ this.input = 0;
23
+ this.inputBytes = 0;
24
+ }
25
+ /**
26
+ * Top-down RGBA to DXT1 or DXT5, matching the TS encoder's blocks. The
27
+ * result stays valid until the next call; null leaves the level to TS.
28
+ */
29
+ encode = (rgba, dxt5, width, height) => {
30
+ if (!Number.isInteger(width) ||
31
+ !Number.isInteger(height) ||
32
+ width <= 0 ||
33
+ height <= 0 ||
34
+ width > 4096 ||
35
+ height > 4096 ||
36
+ rgba.length !== width * height * 4) {
37
+ return null;
38
+ }
39
+ try {
40
+ // A caller may use an earlier result as a smaller level's input. Preserve it if growth
41
+ // detaches that view, or a large earlier level causes its instance to be replaced.
42
+ if (this.wasm && rgba.buffer === this.wasm.memory.buffer) {
43
+ rgba = rgba.slice();
44
+ }
45
+ const length = Math.ceil(width / 4) * Math.ceil(height / 4) * (dxt5 ? 16 : 8);
46
+ if (!this.room(rgba.length + length)) {
47
+ return null;
48
+ }
49
+ const wasm = this.wasm;
50
+ const destination = this.input + rgba.length;
51
+ new Uint8Array(wasm.memory.buffer, this.input, rgba.length).set(rgba);
52
+ if (!wasm.encodeDxt(this.input, destination, width, height, dxt5 ? 1 : 0)) {
53
+ return null;
54
+ }
55
+ this.encoded++;
56
+ return new Uint8Array(wasm.memory.buffer, destination, length);
57
+ }
58
+ catch {
59
+ // A trapped instance is never resumed, and a refused module leaves the TS path available.
60
+ this.release();
61
+ return null;
62
+ }
63
+ };
64
+ room(bytes) {
65
+ if (this.broken) {
66
+ return false;
67
+ }
68
+ if (this.wasm && this.wasm.memory.buffer.byteLength > KEEP_BYTES) {
69
+ this.release();
70
+ }
71
+ if (this.wasm && this.inputBytes >= bytes) {
72
+ return true;
73
+ }
74
+ if (!this.wasm) {
75
+ try {
76
+ this.wasm = renderInstance(() => {
77
+ throw new Error("the DXT encoder takes no tessellator");
78
+ });
79
+ }
80
+ catch {
81
+ this.broken = true;
82
+ return false;
83
+ }
84
+ }
85
+ const want = Math.max(FIRST_BYTES, bytes + Math.floor(bytes / 2));
86
+ this.input = this.wasm.resetArena(want);
87
+ if (!this.input) {
88
+ this.release();
89
+ return false;
90
+ }
91
+ this.inputBytes = want;
92
+ return true;
93
+ }
94
+ }
@@ -0,0 +1,10 @@
1
+ // The render module's wrappers, each over an instance of its own: fills
2
+ // (Tessellator), a layer's lines (LineBuilder, also a Tessellator's
3
+ // `tessellate.lines`) and BitmapData's CPU filters and pixel operations
4
+ // (BitmapKernel), BitmapData.draw of a bitmap (DrawKernel), and DXT1/DXT5
5
+ // texture encoding (DxtEncoder).
6
+ export { BitmapKernel, } from "./bitmap-kernel.js";
7
+ export { DRAW_OPAQUE, DRAW_SKIP_ZERO_ALPHA, DRAW_SMOOTH, DRAW_TRANSFORM, DrawKernel, } from "./draw-kernel.js";
8
+ export { DxtEncoder } from "./dxt-encoder.js";
9
+ export { LineBuilder } from "./lines.js";
10
+ export { PATH_CUBIC, PATH_CURVE, PATH_LINE, PATH_MOVE, Tessellator, } from "./tessellator.js";
@@ -0,0 +1,122 @@
1
+ import { renderInstance, renderModule } from "./module.js";
2
+ /**
3
+ * A shape layer's lines built in one call by the render module's
4
+ * strokes.zig, its outlines filled by the module's libtess2, or its bands
5
+ * where libtess2 fails: the caller writes the layer into input() as
6
+ * strokes.zig reads it (the player's scene/strokes.ts) and calls build()
7
+ * with its length. Its instance is its own, apart from any Tessellator's,
8
+ * and held to the same limits as a Tessellator's (TessellatorOptions),
9
+ * which pass them on: where a fill would have run out of memory, so do the
10
+ * lines, and none are drawn.
11
+ */
12
+ export class LineBuilder {
13
+ instance = null;
14
+ view = new Float64Array(0);
15
+ layout = new Uint32Array(0);
16
+ /** libtess2 trapped the last instance: the next fills its outlines by the bands alone. */
17
+ trapped = false;
18
+ lastUnwound = false;
19
+ limit;
20
+ keep;
21
+ bands;
22
+ constructor(options = {}) {
23
+ this.limit = options.memoryLimit ?? 128 << 20;
24
+ this.keep = options.retainMemory ?? 8 << 20;
25
+ this.bands = options.bands ?? false;
26
+ renderModule();
27
+ }
28
+ /** Whether the last build() unwound, which the next, in a new instance by the bands, may not. */
29
+ get unwound() {
30
+ return this.lastUnwound;
31
+ }
32
+ /** Current retained Wasm capacity. */
33
+ get capacity() {
34
+ return this.instance?.memory.buffer.byteLength ?? 0;
35
+ }
36
+ /** A view of at least `n` f64s of input, valid until build(); null where no instance could be made. */
37
+ input(n) {
38
+ if (!this.instance) {
39
+ try {
40
+ this.instance = renderInstance(() => {
41
+ throw new Error("line tessellation allocation failed");
42
+ });
43
+ }
44
+ catch {
45
+ return null;
46
+ }
47
+ this.instance.setLimit(this.limit);
48
+ this.instance.bandsOnly(Number(this.bands || this.trapped));
49
+ }
50
+ const x = this.instance;
51
+ if (n > this.view.length || this.view.buffer !== x.memory.buffer) {
52
+ const size = Math.max(n, this.view.length * 2, 1024);
53
+ const at = x.lineInput(size);
54
+ if (!at) {
55
+ this.dispose();
56
+ return null;
57
+ }
58
+ this.view = new Float64Array(x.memory.buffer, at, size);
59
+ }
60
+ return this.view;
61
+ }
62
+ /**
63
+ * The layer in the input's first `length` f64s, copied out in one
64
+ * block: null for none, undefined where the module refused it (a
65
+ * position not a number) or failed. Where libtess2 trapped, the next
66
+ * instance fills the layer's outlines by the bands alone, for the
67
+ * caller's next input() and build().
68
+ */
69
+ build(length) {
70
+ this.lastUnwound = false;
71
+ const x = this.instance;
72
+ if (!x) {
73
+ return undefined;
74
+ }
75
+ try {
76
+ const status = x.lineBuild(length);
77
+ // Built without unwinding: libtess2 again for the next.
78
+ if (this.trapped) {
79
+ this.trapped = false;
80
+ x.bandsOnly(Number(this.bands));
81
+ }
82
+ if (status !== 0) {
83
+ return undefined;
84
+ }
85
+ const [at, vertices, count] = this.header(x);
86
+ if (count === 0) {
87
+ return null;
88
+ }
89
+ const copy = x.memory.buffer.slice(at, at + (vertices * 3 + count) * 4);
90
+ return {
91
+ positions: new Float32Array(copy, 0, vertices * 2),
92
+ colors: new Uint32Array(copy, vertices * 8, vertices),
93
+ indices: new Uint32Array(copy, vertices * 12, count),
94
+ };
95
+ }
96
+ catch {
97
+ // libtess2 unwound through the failure import: never resume that instance.
98
+ this.dispose();
99
+ this.trapped = true;
100
+ this.lastUnwound = true;
101
+ return undefined;
102
+ }
103
+ finally {
104
+ if (this.capacity > this.keep) {
105
+ this.dispose();
106
+ }
107
+ }
108
+ }
109
+ /** strokes.zig's layout, read again where memory grew. */
110
+ header(x) {
111
+ if (this.layout.buffer !== x.memory.buffer) {
112
+ this.layout = new Uint32Array(x.memory.buffer, x.lineHeader(), 3);
113
+ }
114
+ return this.layout;
115
+ }
116
+ /** The instance let go, its memory with it; the next input() makes another. */
117
+ dispose() {
118
+ this.instance = null;
119
+ this.view = new Float64Array(0);
120
+ this.layout = new Uint32Array(0);
121
+ }
122
+ }
@@ -0,0 +1,26 @@
1
+ import { decodeBase64 } from "../base64.js";
2
+ import { binary } from "./binary.js";
3
+ let module = null;
4
+ /**
5
+ * The render module (root.zig), compiled once and shared: the bitmap
6
+ * kernels, DXT encoder, tessellator and lines each make an instance of their
7
+ * own, so that each has its memory and lifecycle apart. It needs wasm
8
+ * SIMD throughout; this throws where the host refuses to compile it, as
9
+ * without SIMD or Wasm or under a CSP without 'wasm-unsafe-eval'.
10
+ */
11
+ export function renderModule() {
12
+ module ??= new WebAssembly.Module(decodeBase64(binary));
13
+ return module;
14
+ }
15
+ /**
16
+ * What an instance imports: libtess2's longjmp, which `failure` must
17
+ * throw from, and the host's own sine and cosine, which the lines take so
18
+ * that theirs are the player's JS's to the last bit.
19
+ */
20
+ function renderImports(failure) {
21
+ return { env: { failure, sine: Math.sin, cosine: Math.cos } };
22
+ }
23
+ /** An instance of the module, its memory its own. */
24
+ export function renderInstance(failure) {
25
+ return new WebAssembly.Instance(renderModule(), renderImports(failure)).exports;
26
+ }
@@ -0,0 +1,235 @@
1
+ // BitmapData's pixel operations in the render module (pixels.zig), over a
2
+ // store's pixels a band of rows at a time, so that the scratch stays near
3
+ // BAND_BYTES whatever the bitmap's size. Each band is copied in, worked on
4
+ // and copied back before the next, which reads what the bands before it
5
+ // wrote, as the one loop over the rows did: where the source is the
6
+ // destination and a band's rows of the two overlap, they are copied in as
7
+ // one block, so that a pixel reads what the pixels before it wrote.
8
+ // A band that traps is copied back never, and `Progress` lets the call made
9
+ // again in a new instance (BitmapKernel) take up at that band.
10
+ /** The rows of a band's work: about this much of the pixels it copies in. */
11
+ const BAND_BYTES = 1 << 20;
12
+ /** The params' room at the input's start, before tables and blocks. */
13
+ const HEAD = 256;
14
+ /** paletteMap's four tables of 256 entries, after the params. */
15
+ const TABLES = 4096;
16
+ /**
17
+ * `region` of `into` (`intoWidth` wide) made by the copy `op` of the rows of
18
+ * `from` (`fromWidth` wide) starting at (sx, sy), band by band; false where
19
+ * the module refused a band.
20
+ */
21
+ export function copyRows(wasm, into, intoWidth, from, fromWidth, region, sx, sy, transparent, op, progress) {
22
+ const { x: dx, y: dy, width: w, height: h } = region;
23
+ const same = into === from;
24
+ // A band's blocks: where the source is the destination, both in one block as wide as their union.
25
+ const wide = same ? w + Math.abs(sx - dx) : w;
26
+ const band = Math.max(1, Math.floor(BAND_BYTES / (wide * 8)));
27
+ for (; progress.row < h; progress.row += band) {
28
+ const r0 = progress.row;
29
+ const rows = Math.min(band, h - r0);
30
+ const dy0 = dy + r0;
31
+ const sy0 = sy + r0;
32
+ const joined = same && dy0 < sy0 + rows && sy0 < dy0 + rows;
33
+ const ux = joined ? Math.min(dx, sx) : 0;
34
+ const uy = joined ? Math.min(dy0, sy0) : 0;
35
+ const uw = joined ? Math.max(dx, sx) + w - ux : w;
36
+ const uh = joined ? Math.max(dy0, sy0) + rows - uy : rows;
37
+ const blocks = joined ? uw * uh : 2 * rows * w;
38
+ const at = wasm.resetArena(HEAD + TABLES + blocks * 4);
39
+ if (!at) {
40
+ return false;
41
+ }
42
+ const memory = new Uint32Array(wasm.memory.buffer);
43
+ const base = (at + HEAD + TABLES) >> 2;
44
+ let dst;
45
+ let src;
46
+ let stride;
47
+ if (joined) {
48
+ for (let row = 0; row < uh; row++) {
49
+ const start = (uy + row) * intoWidth + ux;
50
+ memory.set(into.subarray(start, start + uw), base + row * uw);
51
+ }
52
+ dst = base + (dy0 - uy) * uw + (dx - ux);
53
+ src = base + (sy0 - uy) * uw + (sx - ux);
54
+ stride = uw;
55
+ }
56
+ else {
57
+ dst = base;
58
+ src = base + rows * w;
59
+ stride = w;
60
+ // paletteMap's and a colour matrix's pixels are the source's alone: the destination's are not read.
61
+ const reads = op.op === "channel" || op.op === "merge";
62
+ for (let row = 0; row < rows; row++) {
63
+ if (reads) {
64
+ const to = (dy0 + row) * intoWidth + dx;
65
+ memory.set(into.subarray(to, to + w), dst + row * w);
66
+ }
67
+ const fromAt = (sy0 + row) * fromWidth + sx;
68
+ memory.set(from.subarray(fromAt, fromAt + w), src + row * w);
69
+ }
70
+ }
71
+ const params = new DataView(wasm.memory.buffer, at, HEAD);
72
+ const words = [w, rows, dst * 4, stride, src * 4, stride, Number(transparent), 0];
73
+ for (let k = 0; k < 8; k++) {
74
+ params.setUint32(k * 4, words[k], true);
75
+ }
76
+ let ok = 0;
77
+ switch (op.op) {
78
+ case "channel":
79
+ params.setInt32(32, op.from, true);
80
+ params.setUint32(36, op.to, true);
81
+ ok = wasm.channelPixels(at);
82
+ break;
83
+ case "merge":
84
+ for (let k = 0; k < 4; k++) {
85
+ params.setUint32(32 + k * 4, op.muls[k] >>> 0, true);
86
+ }
87
+ ok = wasm.mergePixels(at);
88
+ break;
89
+ case "palette": {
90
+ params.setUint32(32, at + HEAD, true);
91
+ params.setUint32(36, 0, true);
92
+ const tables = new Uint32Array(wasm.memory.buffer, at + HEAD, 1024);
93
+ for (let k = 0; k < 4; k++) {
94
+ tables.set(op.tables[k], k * 256);
95
+ }
96
+ ok = wasm.palettePixels(at);
97
+ break;
98
+ }
99
+ case "matrix": {
100
+ const near = op.near;
101
+ params.setInt32(32, sx, true);
102
+ params.setInt32(36, sy0, true);
103
+ params.setInt32(40, near?.x ?? 0, true);
104
+ params.setInt32(44, near?.y ?? 0, true);
105
+ params.setUint32(48, near?.width ?? 0, true);
106
+ params.setUint32(52, near?.height ?? 0, true);
107
+ params.setUint32(56, op.empty >>> 0, true);
108
+ params.setUint32(60, 0, true);
109
+ for (let k = 0; k < 20; k++) {
110
+ params.setFloat64(64 + k * 8, op.matrix[k], true);
111
+ }
112
+ ok = wasm.matrixPixels(at);
113
+ break;
114
+ }
115
+ }
116
+ if (!ok) {
117
+ return false;
118
+ }
119
+ // Read again: the call may have grown the memory.
120
+ const out = new Uint32Array(wasm.memory.buffer);
121
+ for (let row = 0; row < rows; row++) {
122
+ const to = (dy0 + row) * intoWidth + dx;
123
+ into.set(out.subarray(dst + row * stride, dst + row * stride + w), to);
124
+ }
125
+ }
126
+ return true;
127
+ }
128
+ /**
129
+ * colorTransform over `region` of `pixels` (`width` wide), in place, band by
130
+ * band: each channel's multiplier in 256ths and offset, red, green, blue,
131
+ * alpha; false where the module refused a band.
132
+ */
133
+ export function transformRows(wasm, pixels, width, region, muls, adds, progress) {
134
+ const { x, y, width: w, height: h } = region;
135
+ const band = Math.max(1, Math.floor(BAND_BYTES / (w * 4)));
136
+ for (; progress.row < h; progress.row += band) {
137
+ const rows = Math.min(band, h - progress.row);
138
+ const at = wasm.resetArena(HEAD + rows * w * 4);
139
+ if (!at) {
140
+ return false;
141
+ }
142
+ const block = (at + HEAD) >> 2;
143
+ const memory = new Uint32Array(wasm.memory.buffer);
144
+ for (let row = 0; row < rows; row++) {
145
+ const from = (y + progress.row + row) * width + x;
146
+ memory.set(pixels.subarray(from, from + w), block + row * w);
147
+ }
148
+ const params = new DataView(wasm.memory.buffer, at, HEAD);
149
+ const words = [w, rows, block * 4, w];
150
+ for (let k = 0; k < words.length; k++) {
151
+ params.setUint32(k * 4, words[k], true);
152
+ }
153
+ for (let k = 0; k < 4; k++) {
154
+ params.setFloat64(16 + k * 8, muls[k], true);
155
+ params.setFloat64(48 + k * 8, adds[k], true);
156
+ }
157
+ if (!wasm.transformPixels(at)) {
158
+ return false;
159
+ }
160
+ const out = new Uint32Array(wasm.memory.buffer);
161
+ for (let row = 0; row < rows; row++) {
162
+ const to = (y + progress.row + row) * width + x;
163
+ pixels.set(out.subarray(block + row * w, block + (row + 1) * w), to);
164
+ }
165
+ }
166
+ return true;
167
+ }
168
+ /**
169
+ * noise over every pixel, `count` a band: Park-Miller's generator from
170
+ * `progress.state`, which it moves on; false where the module refused a band.
171
+ */
172
+ export function noiseRows(wasm, pixels, lo, span, channels, gray, transparent, progress) {
173
+ const band = BAND_BYTES >> 2;
174
+ for (; progress.row < pixels.length; progress.row += band) {
175
+ const count = Math.min(band, pixels.length - progress.row);
176
+ const at = wasm.resetArena(HEAD + count * 4);
177
+ if (!at) {
178
+ return false;
179
+ }
180
+ const params = new DataView(wasm.memory.buffer, at, HEAD);
181
+ const words = [count, at + HEAD, progress.state, lo, span, channels, Number(gray)];
182
+ words.push(Number(transparent));
183
+ for (let k = 0; k < words.length; k++) {
184
+ params.setUint32(k * 4, words[k] >>> 0, true);
185
+ }
186
+ const state = wasm.noisePixels(at);
187
+ if (!state) {
188
+ return false;
189
+ }
190
+ pixels.set(new Uint32Array(wasm.memory.buffer, at + HEAD, count), progress.row);
191
+ progress.state = state;
192
+ }
193
+ return true;
194
+ }
195
+ /** perlinNoise over every pixel of a `width`-wide store, band by band; false where the module refused one. */
196
+ export function perlinRows(wasm, pixels, width, setup, progress) {
197
+ const height = pixels.length / width;
198
+ const octaves = setup.offsets.length;
199
+ const band = Math.max(1, Math.floor(BAND_BYTES / (width * 4)));
200
+ // The tables once, and a band's block, which each band uses again.
201
+ const at = wasm.resetArena(HEAD + 2056 + 8 + 32896 + octaves * 16 + band * width * 4);
202
+ if (!at) {
203
+ return false;
204
+ }
205
+ const lattice = at + HEAD;
206
+ const gradients = lattice + 2056 + 8 - ((lattice + 2056) & 7);
207
+ const offsets = gradients + 32896;
208
+ const block = offsets + octaves * 16;
209
+ new Int32Array(wasm.memory.buffer, lattice, 514).set(setup.lattice);
210
+ new Float64Array(wasm.memory.buffer, gradients, 4112).set(setup.gradients);
211
+ const list = new Float64Array(wasm.memory.buffer, offsets, octaves * 2);
212
+ for (let k = 0; k < octaves; k++) {
213
+ list[k * 2] = setup.offsets[k][0];
214
+ list[k * 2 + 1] = setup.offsets[k][1];
215
+ }
216
+ for (; progress.row < height; progress.row += band) {
217
+ const rows = Math.min(band, height - progress.row);
218
+ const params = new DataView(wasm.memory.buffer, at, HEAD);
219
+ const words = [width, rows, progress.row, block, lattice, gradients, offsets, octaves];
220
+ words.push(setup.channels, Number(setup.gray), Number(setup.fractal), Number(setup.stitch));
221
+ words.push(Number(setup.transparent), 0);
222
+ for (let k = 0; k < words.length; k++) {
223
+ params.setUint32(k * 4, words[k] >>> 0, true);
224
+ }
225
+ params.setFloat64(56, setup.fx, true);
226
+ params.setFloat64(64, setup.fy, true);
227
+ params.setFloat64(72, setup.stitchWidth, true);
228
+ params.setFloat64(80, setup.stitchHeight, true);
229
+ if (!wasm.perlinPixels(at)) {
230
+ return false;
231
+ }
232
+ pixels.set(new Uint32Array(wasm.memory.buffer, block, rows * width), progress.row * width);
233
+ }
234
+ return true;
235
+ }