@swf2es/player-hosts 0.0.0-stage → 0.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 (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,591 @@
1
+ import { renderInstance, renderModule } from "./module.js";
2
+ import { copyRows, noiseRows, perlinRows, transformRows, } from "./pixel-ops.js";
3
+ // blur.zig's Kind and Flags.
4
+ const KINDS = ["glow", "dropShadow", "bevel", "gradientGlow", "gradientBevel"];
5
+ const LAYER_INNER = 1;
6
+ const LAYER_KNOCKOUT = 2;
7
+ const LAYER_HIDE_OBJECT = 4;
8
+ const LAYER_TYPE_INNER = 8;
9
+ const LAYER_TYPE_OUTER = 16;
10
+ const LAYER_INVERT = 32;
11
+ /** blur.zig's LayerParams, and a gradient's table after it. */
12
+ const LAYER_PARAMS = 192;
13
+ const TABLE_BYTES = 1024;
14
+ /**
15
+ * What a tile's input and scratch take at most, so that a filter over a
16
+ * large bitmap keeps its instance under retainMemory's default; a tile
17
+ * whose filter reaches far is four times its reach a side, whatever that
18
+ * takes, its blocks cut to the bitmap and the reach round it.
19
+ */
20
+ const TILE_BYTES = 4 << 20;
21
+ /** The arena's header an allocation, its alignment and the stack's room, with some to spare. */
22
+ const SLACK = 64 << 10;
23
+ /**
24
+ * Whether `area` is a rect blur.zig takes: whole, of some size. It never
25
+ * sees where the rect lies, which the blocks copied in hold.
26
+ */
27
+ function sized(area) {
28
+ const { x, y, width: w, height: h } = area;
29
+ return (Number.isSafeInteger(x) &&
30
+ Number.isSafeInteger(y) &&
31
+ Number.isInteger(w) &&
32
+ Number.isInteger(h) &&
33
+ w > 0 &&
34
+ h > 0 &&
35
+ w <= 0x100000 &&
36
+ h <= 0x100000);
37
+ }
38
+ /** A blur as the player keeps it: 0 to 255, or NaN, which blurs nothing. */
39
+ function blurry(v) {
40
+ return Number.isNaN(v) || (v >= 0 && v <= 255);
41
+ }
42
+ const unit = (v) => v >= 0 && v <= 1;
43
+ const rgb = (v) => Number.isInteger(v) && v >= 0 && v <= 0xffffff;
44
+ /** How far `quality` runs of a blur reach, each way: each half its box, whole taps. */
45
+ function reach(blur, quality) {
46
+ return quality * Math.ceil((blur || 0) / 2);
47
+ }
48
+ /** The bytes a run's line buffer and sums take over a plane `w` wide (blur.zig's blur). */
49
+ function runBytes(w, blurX, blurY) {
50
+ const line = blurX > 1 ? (w + 2 * Math.ceil(blurX / 2) + 3) * 4 : 0;
51
+ return line + (blurY > 1 ? w * 4 : 0);
52
+ }
53
+ /**
54
+ * `rect`, where it lies wholly past the bitmap on one side, moved to lie just
55
+ * past it: as far out as the player lets a rect lie, past the convolution's
56
+ * bounds, every tap reads there what it reads here, the nearest edge or the
57
+ * filter's colour.
58
+ */
59
+ function inward(source, rect) {
60
+ const along = (at, size, length) => at + size <= 0 ? -size : at >= length ? length : at;
61
+ return {
62
+ ...rect,
63
+ x: along(rect.x, rect.width, source.width),
64
+ y: along(rect.y, rect.height, source.height),
65
+ };
66
+ }
67
+ /**
68
+ * `block` within the bitmap grown by a blur's reach (hx, hy), past which
69
+ * every pass of it holds nothing: null where it lies wholly past. A block
70
+ * whose reads past the bitmap are not nothing (an inner glow's, of 255 less
71
+ * the alpha) is not to be cut.
72
+ */
73
+ function within(block, source, hx, hy) {
74
+ const x0 = Math.max(block.x, -hx);
75
+ const y0 = Math.max(block.y, -hy);
76
+ const x1 = Math.min(block.x + block.width, source.width + hx);
77
+ const y1 = Math.min(block.y + block.height, source.height + hy);
78
+ return x1 > x0 && y1 > y0 ? { x: x0, y: y0, width: x1 - x0, height: y1 - y0 } : null;
79
+ }
80
+ /**
81
+ * `area` in tiles, `bytes` of a tile `w` by `h` within TILE_BYTES where its
82
+ * reach (`far`) lets it: tiles four times the reach a side at least. Null
83
+ * where they do not fit the module.
84
+ */
85
+ function tiles(area, far, bytes) {
86
+ const of = (side) => bytes(Math.min(side, area.width), Math.min(side, area.height));
87
+ let side = Math.max(area.width, area.height);
88
+ // Smaller, a tile would be mostly the reach round it, read again for each.
89
+ while (side > 16 && of(side) > TILE_BYTES && side > 4 * far) {
90
+ side = Math.ceil(side / 2);
91
+ }
92
+ if (!(of(side) + SLACK <= MOST_BYTES)) {
93
+ return null;
94
+ }
95
+ const out = [];
96
+ for (let y = 0; y < area.height; y += side) {
97
+ for (let x = 0; x < area.width; x += side) {
98
+ out.push({
99
+ x: area.x + x,
100
+ y: area.y + y,
101
+ width: Math.min(side, area.width - x),
102
+ height: Math.min(side, area.height - y),
103
+ });
104
+ }
105
+ }
106
+ return out;
107
+ }
108
+ /** What a call's input and scratch may take of the module's 128 MiB, the stack's and statics' room left. */
109
+ const MOST_BYTES = 120 * 1024 * 1024;
110
+ /** `area` of the source into `into`, row by row; 0 past the bitmap. */
111
+ function copy(source, area, into) {
112
+ const { width: sw, height: sh, pixels } = source;
113
+ const x0 = Math.max(0, area.x);
114
+ const y0 = Math.max(0, area.y);
115
+ const x1 = Math.min(sw, area.x + area.width);
116
+ const y1 = Math.min(sh, area.y + area.height);
117
+ if (x0 > area.x || y0 > area.y || x1 < area.x + area.width || y1 < area.y + area.height) {
118
+ into.fill(0);
119
+ }
120
+ for (let sy = y0; sy < y1 && x1 > x0; sy++) {
121
+ into.set(pixels.subarray(sy * sw + x0, sy * sw + x1), (sy - area.y) * area.width + x0 - area.x);
122
+ }
123
+ }
124
+ /** The alpha of `area` of the source into `into`, a byte a pixel; 0 past the bitmap. */
125
+ function copyAlpha(source, area, into) {
126
+ const { width: sw, height: sh, pixels } = source;
127
+ const x0 = Math.max(0, area.x);
128
+ const y0 = Math.max(0, area.y);
129
+ const x1 = Math.min(sw, area.x + area.width);
130
+ const y1 = Math.min(sh, area.y + area.height);
131
+ if (x0 > area.x || y0 > area.y || x1 < area.x + area.width || y1 < area.y + area.height) {
132
+ into.fill(0);
133
+ }
134
+ for (let sy = y0; sy < y1 && x1 > x0; sy++) {
135
+ let o = (sy - area.y) * area.width + x0 - area.x;
136
+ const end = sy * sw + x1;
137
+ for (let i = sy * sw + x0; i < end; i++) {
138
+ into[o++] = pixels[i] >>> 24;
139
+ }
140
+ }
141
+ }
142
+ /**
143
+ * The blocks of the source a layer over `area` blurs the alpha of, and its
144
+ * reads of them, moved by each of `offsets`: blurred once over where they
145
+ * all read and as far round it as the blur reaches (hx, hy), as a bevel
146
+ * reads on and back; reads further apart than `area` is wide or high, each
147
+ * over its own, so that a block is `area`'s size wherever the offset takes
148
+ * it. As the player's JS read them.
149
+ */
150
+ function alphaReads(area, hx, hy, offsets) {
151
+ const kxs = offsets.map(([dx]) => Math.floor(dx));
152
+ const kys = offsets.map(([, dy]) => Math.floor(dy));
153
+ const x0 = Math.min(...kxs);
154
+ const y0 = Math.min(...kys);
155
+ const spanX = Math.max(...kxs) - x0;
156
+ const spanY = Math.max(...kys) - y0;
157
+ if (offsets.length > 1 && (spanX > area.width || spanY > area.height)) {
158
+ const each = offsets.map((offset) => alphaReads(area, hx, hy, [offset]));
159
+ return {
160
+ reads: each.map(({ reads }) => reads[0]),
161
+ moves: each.map(({ moves }, k) => ({ ...moves[0], read: k })),
162
+ };
163
+ }
164
+ return {
165
+ reads: [
166
+ {
167
+ x: area.x + x0 - hx,
168
+ y: area.y + y0 - hy,
169
+ width: area.width + 1 + spanX + 2 * hx,
170
+ height: area.height + 1 + spanY + 2 * hy,
171
+ },
172
+ ],
173
+ moves: offsets.map(([dx, dy], i) => ({
174
+ read: 0,
175
+ x: hx + (kxs[i] - x0) + (dx - kxs[i]),
176
+ y: hy + (kys[i] - y0) + (dy - kys[i]),
177
+ })),
178
+ };
179
+ }
180
+ // Params.flags in convolve.zig.
181
+ const FLAG_CLAMP = 1;
182
+ const FLAG_SOURCE_TRANSPARENT = 2;
183
+ const FLAG_PRESERVE_ALPHA = 4;
184
+ const FLAG_PREMULTIPLY = 8;
185
+ // About what one call's input block and output hold: a large rect is
186
+ // convolved a band of rows at a time, so that its scratch stays far under
187
+ // retainMemory's default and the instance is kept rather than regrown.
188
+ const BAND_BYTES = 1 << 20;
189
+ /**
190
+ * BitmapData's CPU filters in the render module: a convolution
191
+ * (convolve.zig), and a blur, a glow, a drop shadow, a bevel and a gradient
192
+ * glow or bevel (blur.zig), on one instance, its scratch bounded. It
193
+ * compiles the render module as it is made, and throws where the host
194
+ * refuses it. Results own their buffers; rejection leaves the source
195
+ * untouched.
196
+ */
197
+ export class BitmapKernel {
198
+ instance = null;
199
+ keep;
200
+ constructor(options = {}) {
201
+ this.keep = options.retainMemory ?? 8 << 20;
202
+ if (!Number.isInteger(this.keep) || this.keep < 0 || this.keep > 128 << 20) {
203
+ throw new RangeError("invalid bitmap kernel memory limit");
204
+ }
205
+ renderModule();
206
+ }
207
+ get capacity() {
208
+ return this.instance?.memory.buffer.byteLength ?? 0;
209
+ }
210
+ dispose() {
211
+ this.instance = null;
212
+ }
213
+ /**
214
+ * The convolved pixels, owned by the caller, or null where they would not
215
+ * fit; where the instance traps, the call is made again in a new one
216
+ * once. Never writes to the source.
217
+ */
218
+ convolve = (source, area, filter, transparent) => {
219
+ const { width: sw, height: sh } = source;
220
+ const cols = filter.matrixX;
221
+ const rows = filter.matrixY;
222
+ // Wholly past the kernel's reach of the bitmap, every tap reads alike, the nearest edge's or
223
+ // the filter's colour, wherever the rect is.
224
+ const grown = inward(source, {
225
+ x: area.x - cols,
226
+ y: area.y - rows,
227
+ width: area.width + 2 * cols,
228
+ height: area.height + 2 * rows,
229
+ });
230
+ const x = grown.x + cols;
231
+ const y = grown.y + rows;
232
+ const { width: w, height: h } = area;
233
+ if (![sw, sh, x, y, w, h, cols, rows].every(Number.isInteger) ||
234
+ sw <= 0 ||
235
+ sh <= 0 ||
236
+ sw > 0x3fffffff ||
237
+ sh > 0x3fffffff ||
238
+ source.pixels.length !== sw * sh ||
239
+ Math.abs(x) > 0x3fffffff ||
240
+ Math.abs(y) > 0x3fffffff ||
241
+ w <= 0 ||
242
+ h <= 0 ||
243
+ w > 0x100000 ||
244
+ h > 0x100000 ||
245
+ cols <= 0 ||
246
+ rows <= 0 ||
247
+ cols > 15 ||
248
+ rows > 15) {
249
+ return null;
250
+ }
251
+ const clampX = (v) => Math.max(0, Math.min(sw - 1, v));
252
+ const clampY = (v) => Math.max(0, Math.min(sh - 1, v));
253
+ const x0 = clampX(x - (cols >> 1));
254
+ const nw = clampX(x + w + cols - (cols >> 1) - 2) - x0 + 1;
255
+ // Each band's output rows read its rows of the source and the kernel's
256
+ // reach above and below them, which the next band copies again.
257
+ const band = Math.max(1, Math.min(h, Math.floor(BAND_BYTES / ((nw + w) * 4))));
258
+ const nhMax = Math.min(band + rows - 1, sh);
259
+ const matrixOffset = Math.ceil((96 + nw * nhMax * 4) / 8) * 8;
260
+ const inputMax = matrixOffset + cols * rows * 8;
261
+ // Leave room for the stack and alignment before reserving any native input;
262
+ // the kernel's planes hold at most 16 lines.
263
+ if (!Number.isSafeInteger(inputMax) ||
264
+ inputMax + (16 * nw + 1) * 16 + w * 32 + w * band * 4 > 127 * 1024 * 1024) {
265
+ return null;
266
+ }
267
+ let result;
268
+ try {
269
+ result = new Uint32Array(w * h);
270
+ }
271
+ catch {
272
+ return null;
273
+ }
274
+ return this.call((wasm) => {
275
+ const flags = (filter.clamp ? FLAG_CLAMP : 0) |
276
+ (source.transparent ? FLAG_SOURCE_TRANSPARENT : 0) |
277
+ (filter.preserveAlpha ? FLAG_PRESERVE_ALPHA : 0) |
278
+ (transparent ? FLAG_PREMULTIPLY : 0);
279
+ for (let top = 0; top < h; top += band) {
280
+ const bandY = y + top;
281
+ const bandH = Math.min(band, h - top);
282
+ const y0 = clampY(bandY - (rows >> 1));
283
+ const nh = clampY(bandY + bandH + rows - (rows >> 1) - 2) - y0 + 1;
284
+ const offset = Math.ceil((96 + nw * nh * 4) / 8) * 8;
285
+ const pointer = wasm.resetArena(offset + cols * rows * 8);
286
+ if (!pointer) {
287
+ return null;
288
+ }
289
+ const pixelPointer = pointer + 96;
290
+ const matrixPointer = pointer + offset;
291
+ new Int32Array(wasm.memory.buffer, pointer, 16).set([
292
+ sw,
293
+ sh,
294
+ x,
295
+ bandY,
296
+ w,
297
+ bandH,
298
+ x0,
299
+ y0,
300
+ nw,
301
+ nh,
302
+ cols,
303
+ rows,
304
+ flags,
305
+ pixelPointer,
306
+ matrixPointer,
307
+ 0,
308
+ ]);
309
+ new Float64Array(wasm.memory.buffer, pointer + 64, 2).set([
310
+ filter.divisor || 1,
311
+ filter.bias,
312
+ ]);
313
+ new Int32Array(wasm.memory.buffer, pointer + 80, 2).set([
314
+ Math.floor(filter.alpha * 255) | 0,
315
+ filter.color | 0,
316
+ ]);
317
+ const into = new Uint32Array(wasm.memory.buffer, pixelPointer, nw * nh);
318
+ for (let row = 0; row < nh; row++) {
319
+ into.set(source.pixels.subarray((y0 + row) * sw + x0, (y0 + row) * sw + x0 + nw), row * nw);
320
+ }
321
+ const matrix = new Float64Array(wasm.memory.buffer, matrixPointer, cols * rows);
322
+ for (let k = 0; k < matrix.length; k++) {
323
+ matrix[k] = filter.matrix[k] || 0;
324
+ }
325
+ const out = wasm.convolve(pointer);
326
+ if (!out) {
327
+ // An ordinary allocation rejection can reuse its arena on a later call.
328
+ return null;
329
+ }
330
+ // The kernel can grow memory; construct this view afterwards and copy before scratch reuse.
331
+ result.set(new Uint32Array(wasm.memory.buffer, out, w * bandH), top * w);
332
+ }
333
+ return result;
334
+ }, true);
335
+ };
336
+ /**
337
+ * The blur filter over `area` of the source, 0 past the bitmap: its
338
+ * premultiplied channels blurred apart (blur.zig), owned by the caller;
339
+ * null where the values are not the player's or the pixels would not fit.
340
+ * Large rects are filtered in tiles, each read as far round as the blur
341
+ * reaches. A trap is made again in a new instance once. Never writes to
342
+ * the source.
343
+ */
344
+ blur = (source, area, blurX, blurY, quality) => {
345
+ if (!sized(area) ||
346
+ !blurry(blurX) ||
347
+ !blurry(blurY) ||
348
+ !(Number.isInteger(quality) && quality >= 0 && quality <= 15)) {
349
+ return null;
350
+ }
351
+ const hx = reach(blurX, quality);
352
+ const hy = reach(blurY, quality);
353
+ // A block is cut to the bitmap and the reach round it.
354
+ const blockBytes = (w, h) => {
355
+ const bw = Math.min(w, source.width) + 2 * hx;
356
+ const n = bw * (Math.min(h, source.height) + 2 * hy);
357
+ return 32 + n * 6 + runBytes(bw, blurX, blurY);
358
+ };
359
+ const parts = tiles(area, Math.max(hx, hy), blockBytes);
360
+ if (!parts) {
361
+ return null;
362
+ }
363
+ const result = new Uint32Array(area.width * area.height);
364
+ return this.call((wasm) => {
365
+ for (const t of parts) {
366
+ const block = within({ x: t.x - hx, y: t.y - hy, width: t.width + 2 * hx, height: t.height + 2 * hy }, source, hx, hy);
367
+ // Past the blur's reach of the bitmap: nothing.
368
+ if (!block) {
369
+ continue;
370
+ }
371
+ const n = block.width * block.height;
372
+ const pointer = wasm.resetArena(32 + n * 4);
373
+ if (!pointer) {
374
+ return null;
375
+ }
376
+ new Int32Array(wasm.memory.buffer, pointer, 4).set([
377
+ block.width,
378
+ block.height,
379
+ quality,
380
+ pointer + 32,
381
+ ]);
382
+ new Float64Array(wasm.memory.buffer, pointer + 16, 2).set([blurX, blurY]);
383
+ copy(source, block, new Uint32Array(wasm.memory.buffer, pointer + 32, n));
384
+ const out = wasm.blurFilter(pointer);
385
+ if (!out) {
386
+ return null;
387
+ }
388
+ // What the block holds of the tile, past the reach round it; nothing past the block.
389
+ const blurred = new Uint32Array(wasm.memory.buffer, out, n);
390
+ const x0 = Math.max(t.x, block.x);
391
+ const x1 = Math.min(t.x + t.width, block.x + block.width);
392
+ const y0 = Math.max(t.y, block.y);
393
+ const y1 = Math.min(t.y + t.height, block.y + block.height);
394
+ for (let y = y0; y < y1 && x1 > x0; y++) {
395
+ const from = (y - block.y) * block.width + x0 - block.x;
396
+ result.set(blurred.subarray(from, from + x1 - x0), (y - area.y) * area.width + x0 - area.x);
397
+ }
398
+ }
399
+ return result;
400
+ }, true);
401
+ };
402
+ /**
403
+ * A glow's, a shadow's, a bevel's or a gradient one's result over `area`
404
+ * of the source (blur.zig), read from the source moved by each of
405
+ * `offsets` (one, or two for a bevel, on and back): the alpha of blocks of
406
+ * the source blurred, read there, and the layer placed on the source's
407
+ * pixels; owned by the caller, null where the values are not the player's
408
+ * or the pixels would not fit. Large rects are filtered in tiles. A trap
409
+ * is made again in a new instance once. Never writes to the source.
410
+ */
411
+ layer = (source, area, f, offsets) => {
412
+ const kind = KINDS.indexOf(f.kind);
413
+ const bevel = f.kind === "bevel" || f.kind === "gradientBevel";
414
+ if (kind < 0 ||
415
+ !sized(area) ||
416
+ offsets.length !== (bevel ? 2 : 1) ||
417
+ !offsets.every(([x, y]) => Math.abs(x) < 2 ** 31 && Math.abs(y) < 2 ** 31) ||
418
+ !(Number.isInteger(f.quality) && f.quality >= 0 && f.quality <= 15) ||
419
+ !blurry(f.blurX) ||
420
+ !blurry(f.blurY) ||
421
+ !(f.strength >= 0 && f.strength <= 255) ||
422
+ !unit(f.alpha) ||
423
+ !unit(f.highlightAlpha) ||
424
+ !unit(f.shadowAlpha) ||
425
+ !rgb(f.color) ||
426
+ !rgb(f.highlightColor) ||
427
+ !rgb(f.shadowColor) ||
428
+ (f.table !== null && f.table.length !== 256)) {
429
+ return null;
430
+ }
431
+ const hx = reach(f.blurX, f.quality);
432
+ const hy = reach(f.blurY, f.quality);
433
+ // A tile's pixels, its blocks' alpha and their scratch, and its reads' planes and columns;
434
+ // a block cut to the bitmap and the reach round it, unless it reads 255 past it.
435
+ const cut = (r) => f.invert
436
+ ? r
437
+ : {
438
+ ...r,
439
+ width: Math.min(r.width, source.width + 2 * hx),
440
+ height: Math.min(r.height, source.height + 2 * hy),
441
+ };
442
+ const tileBytes = (w, h) => {
443
+ const { reads } = alphaReads({ x: 0, y: 0, width: w, height: h }, hx, hy, offsets);
444
+ const read = reads
445
+ .map(cut)
446
+ .reduce((sum, r) => sum + r.width * r.height * 2 + runBytes(r.width, f.blurX, f.blurY), 0);
447
+ return LAYER_PARAMS + TABLE_BYTES + w * h * 4 + read + offsets.length * (w * h + w * 16);
448
+ };
449
+ const parts = tiles(area, Math.max(hx, hy), tileBytes);
450
+ if (!parts) {
451
+ return null;
452
+ }
453
+ const flags = (f.inner ? LAYER_INNER : 0) |
454
+ (f.knockout ? LAYER_KNOCKOUT : 0) |
455
+ (f.hideObject ? LAYER_HIDE_OBJECT : 0) |
456
+ (f.type === "inner" ? LAYER_TYPE_INNER : 0) |
457
+ (f.type === "outer" ? LAYER_TYPE_OUTER : 0) |
458
+ (f.invert ? LAYER_INVERT : 0);
459
+ const result = new Uint32Array(area.width * area.height);
460
+ return this.call((wasm) => {
461
+ for (const t of parts) {
462
+ const whole = alphaReads(t, hx, hy, offsets);
463
+ // Past the bitmap and the blur's reach round it, the alpha blurred is nothing, as the
464
+ // block's reads past it are: a block cut there, a pixel past it kept of one wholly so,
465
+ // its moves still the whole block's, which blur.zig reads the cut by.
466
+ const reads = f.invert
467
+ ? whole.reads
468
+ : whole.reads.map((r) => within(r, source, hx, hy) ?? { ...r, width: 1, height: 1 });
469
+ const moves = whole.moves;
470
+ const n = t.width * t.height;
471
+ const alpha = reads.reduce((sum, r) => sum + r.width * r.height, 0);
472
+ const pointer = wasm.resetArena(LAYER_PARAMS + TABLE_BYTES + n * 4 + alpha);
473
+ if (!pointer) {
474
+ return null;
475
+ }
476
+ const buffer = wasm.memory.buffer;
477
+ const table = pointer + LAYER_PARAMS;
478
+ const pixels = table + TABLE_BYTES;
479
+ const ints = new Int32Array(buffer, pointer, LAYER_PARAMS / 4);
480
+ ints.fill(0);
481
+ ints.set([kind, flags, t.width, t.height, pixels, f.quality, reads.length, moves.length]);
482
+ let at = pixels + n * 4;
483
+ for (const [k, r] of reads.entries()) {
484
+ const from = whole.reads[k];
485
+ ints.set([at, r.width, r.height, r.x - from.x, r.y - from.y], 8 + k * 6);
486
+ copyAlpha(source, r, new Uint8Array(buffer, at, r.width * r.height));
487
+ at += r.width * r.height;
488
+ }
489
+ const floats = new Float64Array(buffer, pointer, LAYER_PARAMS / 8);
490
+ for (const [k, m] of moves.entries()) {
491
+ ints[20 + k * 6] = m.read;
492
+ floats[11 + k * 3] = m.x;
493
+ floats[12 + k * 3] = m.y;
494
+ }
495
+ floats.set([f.blurX, f.blurY, f.strength, f.alpha, f.highlightAlpha, f.shadowAlpha], 16);
496
+ ints.set([f.color, f.highlightColor, f.shadowColor, table], 44);
497
+ if (f.table) {
498
+ new Uint32Array(buffer, table, 256).set(f.table);
499
+ }
500
+ copy(source, t, new Uint32Array(buffer, pixels, n));
501
+ const out = wasm.layerFilter(pointer);
502
+ if (!out) {
503
+ return null;
504
+ }
505
+ const placed = new Uint32Array(wasm.memory.buffer, out, n);
506
+ for (let row = 0; row < t.height; row++) {
507
+ result.set(placed.subarray(row * t.width, (row + 1) * t.width), (t.y - area.y + row) * area.width + t.x - area.x);
508
+ }
509
+ }
510
+ return result;
511
+ }, true);
512
+ };
513
+ /**
514
+ * `region` of `into` (`intoWidth` wide) made by the copy `op` of `from`'s
515
+ * pixels from (sx, sy) on: copyChannel, merge, paletteMap or a colour
516
+ * matrix filter (pixel-ops.ts), each pixel reading what the pixels before
517
+ * it wrote where `from` is `into`. False where the module refused it,
518
+ * which may leave the rows done before it done.
519
+ */
520
+ copy(into, intoWidth, from, fromWidth, region, sx, sy, transparent, op) {
521
+ if (!whole(region) || !Number.isInteger(sx) || !Number.isInteger(sy)) {
522
+ return false;
523
+ }
524
+ const progress = { row: 0, state: 0 };
525
+ return (this.call((wasm) => copyRows(wasm, into, intoWidth, from, fromWidth, region, sx, sy, transparent, op, progress)
526
+ ? true
527
+ : null, true) ?? false);
528
+ }
529
+ /** colorTransform over `region` of `pixels` (`width` wide), in place: false where the module refused it. */
530
+ transform(pixels, width, region, muls, adds) {
531
+ if (!whole(region)) {
532
+ return false;
533
+ }
534
+ const progress = { row: 0, state: 0 };
535
+ return (this.call((wasm) => (transformRows(wasm, pixels, width, region, muls, adds, progress) ? true : null), true) ?? false);
536
+ }
537
+ /**
538
+ * noise over every pixel, Park-Miller's generator from `state` (1 to
539
+ * 2^31 - 2), values lo + r % span: false where the module refused it.
540
+ */
541
+ noise(pixels, state, lo, span, channels, gray, transparent) {
542
+ if (!(Number.isInteger(state) && state >= 1 && state < 2147483647) || pixels.length === 0) {
543
+ return false;
544
+ }
545
+ const progress = { row: 0, state };
546
+ return (this.call((wasm) => noiseRows(wasm, pixels, lo, span, channels, gray, transparent, progress) ? true : null, true) ?? false);
547
+ }
548
+ /** perlinNoise over every pixel of a `width`-wide store: false where the module refused it. */
549
+ perlin(pixels, width, setup) {
550
+ if (!(width > 0) || pixels.length % width !== 0 || pixels.length === 0) {
551
+ return false;
552
+ }
553
+ const progress = { row: 0, state: 0 };
554
+ return (this.call((wasm) => (perlinRows(wasm, pixels, width, setup, progress) ? true : null), true) ??
555
+ false);
556
+ }
557
+ /** `body` on the instance, made where there is none: made again in a new one where it traps if `again`. */
558
+ call(body, again) {
559
+ try {
560
+ if (!this.instance) {
561
+ try {
562
+ this.instance = renderInstance(() => {
563
+ throw new Error("the bitmap kernel takes no tessellator");
564
+ });
565
+ }
566
+ catch {
567
+ return null;
568
+ }
569
+ }
570
+ return body(this.instance);
571
+ }
572
+ catch {
573
+ // A trap: never resume that instance.
574
+ this.dispose();
575
+ return again ? this.call(body, false) : null;
576
+ }
577
+ finally {
578
+ if (this.capacity > this.keep) {
579
+ this.dispose();
580
+ }
581
+ }
582
+ }
583
+ }
584
+ /** Whether `r` is a rect of whole pixels with an area, within a store. */
585
+ function whole(r) {
586
+ return ([r.x, r.y, r.width, r.height].every(Number.isInteger) &&
587
+ r.x >= 0 &&
588
+ r.y >= 0 &&
589
+ r.width > 0 &&
590
+ r.height > 0);
591
+ }