@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,627 @@
1
+ /** The nearest integer, a half to the even one, as C's rint rounds and Flash's pixel coordinates do. */
2
+ export function nearest(v) {
3
+ const f = Math.floor(v);
4
+ const d = v - f;
5
+ if (d !== 0.5) {
6
+ return d > 0.5 ? f + 1 : f;
7
+ }
8
+ return f % 2 === 0 ? f : f + 1;
9
+ }
10
+ /** How far a rect's edge reaches either way, as adl clamps it: 2^30 - 1. */
11
+ export const EDGE_LIMIT = 0x3fffffff;
12
+ /** The edge NaN makes, which lies off every bitmap: int's least. */
13
+ export const NAN_EDGE = -0x80000000;
14
+ /**
15
+ * A rect's edge as a pixel: rounded to the nearest, a half to the even
16
+ * one, then clamped to EDGE_LIMIT, so that Infinity and 1e20 lie past
17
+ * every bitmap as a huge finite edge does; NaN, which the clamp lets
18
+ * through, is int's least, as adl converts it (a copy's point moved by a
19
+ * clamped edge lands where 2^30 - 1 puts it).
20
+ */
21
+ export function pixelEdge(v) {
22
+ if (Number.isNaN(v)) {
23
+ return NAN_EDGE;
24
+ }
25
+ return Math.max(-EDGE_LIMIT, Math.min(EDGE_LIMIT, nearest(v))) + 0;
26
+ }
27
+ /**
28
+ * A flash.geom.Rectangle's numbers as the pixels Flash takes it to cover:
29
+ * each edge, x and x + width, as pixelEdge makes it, so a rect from 1.6 of
30
+ * 1.8 covers the pixel at 2 alone, and one from 3.5 of 1 covers none
31
+ * (Ruffle's bitmapdata_rectangle_rounding; under adl the same for every
32
+ * operation taking a rect). A width of Infinity reaches the bitmap's edge,
33
+ * one of NaN covers nothing, and an x of NaN or Infinity nothing either.
34
+ */
35
+ export function pixelRect(x, y, width, height) {
36
+ const x0 = pixelEdge(x);
37
+ const y0 = pixelEdge(y);
38
+ return { x: x0, y: y0, width: pixelEdge(x + width) - x0, height: pixelEdge(y + height) - y0 };
39
+ }
40
+ /**
41
+ * pixelRect of the rect as merge, copyChannel, paletteMap, threshold and
42
+ * pixelDissolve take it under adl: a negative width or height spans back
43
+ * from x to x + width, turned round on the numbers before their edges are
44
+ * made, so that 5 of -1e20 is a rect from -1e20 of 1e20, which the double
45
+ * rounds to end at 0, not one reaching from the clamped edge to 5.
46
+ */
47
+ export function spanRect(x, y, width, height) {
48
+ if (width < 0) {
49
+ x += width;
50
+ width = -width;
51
+ }
52
+ if (height < 0) {
53
+ y += height;
54
+ height = -height;
55
+ }
56
+ return pixelRect(x, y, width, height);
57
+ }
58
+ /** No gaps, shared by every copy that leaves none. */
59
+ const NO_GAPS = [];
60
+ /** The reciprocals Flash divides alpha out with, 8.8 fixed point. */
61
+ const RECIPROCAL = new Uint32Array(256);
62
+ for (let a = 1; a < 256; a++) {
63
+ RECIPROCAL[a] = Math.floor(0xff00 / a);
64
+ }
65
+ /** `argb` with its colour channels premultiplied by its alpha. */
66
+ export function premultiply(argb) {
67
+ const a = argb >>> 24;
68
+ if (a === 255) {
69
+ return argb >>> 0;
70
+ }
71
+ if (a === 0) {
72
+ return 0;
73
+ }
74
+ const r = ((((argb >>> 16) & 0xff) * a + 127) / 255) | 0;
75
+ const g = ((((argb >>> 8) & 0xff) * a + 127) / 255) | 0;
76
+ const b = (((argb & 0xff) * a + 127) / 255) | 0;
77
+ return ((a << 24) | (r << 16) | (g << 8) | b) >>> 0;
78
+ }
79
+ /** A premultiplied pixel with its alpha divided back out. */
80
+ export function unmultiply(pixel) {
81
+ const a = pixel >>> 24;
82
+ if (a === 255) {
83
+ return pixel >>> 0;
84
+ }
85
+ if (a === 0) {
86
+ return 0;
87
+ }
88
+ const k = RECIPROCAL[a];
89
+ const r = Math.min(255, ((((pixel >>> 16) & 0xff) * k + 127) >> 8) >>> 0);
90
+ const g = Math.min(255, ((((pixel >>> 8) & 0xff) * k + 127) >> 8) >>> 0);
91
+ const b = Math.min(255, (((pixel & 0xff) * k + 127) >> 8) >>> 0);
92
+ return ((a << 24) | (r << 16) | (g << 8) | b) >>> 0;
93
+ }
94
+ export class BitmapStore {
95
+ width;
96
+ height;
97
+ transparent;
98
+ cpu;
99
+ /**
100
+ * Whether `cpu` is a library bitmap's pixels, which every store made of it
101
+ * shares: copied before it is first written, so an atlas a SWF only reads
102
+ * from is one array, not one for the library and one for each BitmapData.
103
+ */
104
+ shared = false;
105
+ /** The renderers' copies of the store, one each, for `dispose` to free. */
106
+ copies = new Set();
107
+ /** The copy a draw wrote last, which reading `pixels` brings back while it is newer; null for none. */
108
+ gpu = null;
109
+ /** Whether the GPU's copy was written last, so the CPU's is behind until read. */
110
+ gpuNewer = false;
111
+ /** Counts each change, so a texture of the store knows to upload again. */
112
+ version = 0;
113
+ /**
114
+ * Whether the store is opaque but holds pixels below alpha 255, which
115
+ * erase and alpha leave in one (drawBitmap), as Flash's memory does.
116
+ * Its pixels then read two ways (adl): as they are, by what reads their
117
+ * values (getPixel32, getPixels, getVector, clone, compare, floodFill,
118
+ * Context3D's upload, a ShaderJob's input, unmultiplied), and opaque,
119
+ * alpha 255 over the premultiplied colour, by what draws or copies them
120
+ * (draw, copyPixels, encode, the screen, hitTest's alpha): `drawable`.
121
+ */
122
+ holdsAlpha = false;
123
+ /** `drawable`'s pixels and the version they are of, while the store holds alpha. */
124
+ opaqueCopy = null;
125
+ opaqueVersion = -1;
126
+ disposed = false;
127
+ /**
128
+ * The Bitmaps showing the store, told of each change so the renderer
129
+ * looks at them; held weakly, so a Bitmap taken off the display list
130
+ * and dropped is collected though the BitmapData lives on.
131
+ */
132
+ views = new Set();
133
+ /** `shared`, where given, is the pixels it holds, its own until written: see `of`. */
134
+ constructor(width, height, transparent, fill, shared) {
135
+ this.width = width;
136
+ this.height = height;
137
+ this.transparent = transparent;
138
+ if (shared) {
139
+ this.cpu = shared;
140
+ this.shared = true;
141
+ return;
142
+ }
143
+ this.cpu = new Uint32Array(width * height);
144
+ this.cpu.fill(this.premultiplied(fill));
145
+ }
146
+ /**
147
+ * Premultiplied ARGB, row by row, to read and write. Reading them brings
148
+ * the GPU's copy back first if a draw wrote it last, once: every CPU
149
+ * operation reads them, so each sees the store as the GPU left it. Shared
150
+ * pixels are copied first, as they may be written.
151
+ */
152
+ get pixels() {
153
+ const pixels = this.readable;
154
+ if (this.shared) {
155
+ this.cpu = pixels.slice();
156
+ this.shared = false;
157
+ }
158
+ return this.cpu;
159
+ }
160
+ set pixels(pixels) {
161
+ this.cpu = pixels;
162
+ this.shared = false;
163
+ this.gpuNewer = false;
164
+ }
165
+ /**
166
+ * The pixels as `pixels` gives them, to read only, never to write: shared
167
+ * pixels stay shared. An operation that writes a store and reads another,
168
+ * which may be the same, takes the one it writes first, so both are one array.
169
+ */
170
+ get readable() {
171
+ if (this.gpuNewer && this.gpu) {
172
+ this.cpu = this.gpu.read();
173
+ this.shared = false;
174
+ }
175
+ this.gpuNewer = false;
176
+ return this.cpu;
177
+ }
178
+ /** Whether the GPU's copy is newer than the CPU's, which a read of `pixels` would bring back. */
179
+ get newerOnGpu() {
180
+ return this.gpuNewer;
181
+ }
182
+ /** A draw wrote `copy`: the store changed, and the CPU's pixels and every other copy are behind it until read. */
183
+ drawnOnGpu(copy) {
184
+ this.gpu = copy;
185
+ this.gpuNewer = true;
186
+ this.changed();
187
+ copy.version = this.version;
188
+ }
189
+ /**
190
+ * The pixels for `copy` to upload once its context was lost and given
191
+ * back: the CPU's, a draw only the copy held lost with it, not read back
192
+ * from the texture, which is empty now.
193
+ */
194
+ lostOnGpu(copy) {
195
+ if (this.gpu === copy) {
196
+ this.gpu = null;
197
+ this.gpuNewer = false;
198
+ }
199
+ return this.readable;
200
+ }
201
+ /**
202
+ * `op` done on the GPU's copy where that is newer, so the pixels stay
203
+ * there: an operation after a draw would otherwise wait for the GPU and
204
+ * bring the whole store back, on every frame of a SWF that draws and then
205
+ * scrolls, fills or copies. Only an operation the GPU does exactly takes
206
+ * this way: moves of whole pixels and fills, never arithmetic. Whether
207
+ * it was done.
208
+ */
209
+ onGpu(op) {
210
+ const copy = this.gpu;
211
+ if (!this.gpuNewer || !copy || !op(copy)) {
212
+ return false;
213
+ }
214
+ // The op may have read the pixels back, for a texture of this store that
215
+ // was behind: the CPU then holds them as they were before it.
216
+ this.gpuNewer = true;
217
+ this.changed();
218
+ copy.version = this.version;
219
+ return true;
220
+ }
221
+ /**
222
+ * A store of its own holding `pixels`, premultiplied already, which are
223
+ * never written: the store shares them until it is.
224
+ */
225
+ static of(pixels) {
226
+ return new BitmapStore(pixels.width, pixels.height, pixels.transparent, 0, pixels.pixels);
227
+ }
228
+ /** `argb` as this store keeps it: premultiplied, and opaque where the store is. */
229
+ premultiplied(argb) {
230
+ return premultiply(this.transparent ? argb : argb | 0xff000000);
231
+ }
232
+ /** The rect clipped to the store: null where nothing of it lies within. */
233
+ clip(r) {
234
+ const x0 = Math.max(0, r.x);
235
+ const y0 = Math.max(0, r.y);
236
+ const x1 = Math.min(this.width, r.x + r.width);
237
+ const y1 = Math.min(this.height, r.y + r.height);
238
+ if (x1 <= x0 || y1 <= y0) {
239
+ return null;
240
+ }
241
+ return { x: x0, y: y0, width: x1 - x0, height: y1 - y0 };
242
+ }
243
+ getPixel32(x, y) {
244
+ if (x < 0 || y < 0 || x >= this.width || y >= this.height) {
245
+ return 0;
246
+ }
247
+ return this.unmultiplied(this.readable[y * this.width + x]);
248
+ }
249
+ /**
250
+ * A stored pixel as its value reads back: unmultiplied, but an opaque
251
+ * bitmap's as it is, which is the same but where it holds alpha.
252
+ */
253
+ unmultiplied(p) {
254
+ return this.transparent ? unmultiply(p) : p;
255
+ }
256
+ /**
257
+ * The pixels as a draw, a copy or the screen reads them, to read only:
258
+ * `readable`, but where an opaque store holds alpha, a copy at alpha 255.
259
+ */
260
+ get drawable() {
261
+ const pixels = this.readable;
262
+ if (!this.holdsAlpha) {
263
+ return pixels;
264
+ }
265
+ if (this.opaqueCopy === null || this.opaqueVersion !== this.version) {
266
+ const copy = this.opaqueCopy?.length === pixels.length
267
+ ? this.opaqueCopy
268
+ : new Uint32Array(pixels.length);
269
+ for (let i = 0; i < pixels.length; i++) {
270
+ copy[i] = (pixels[i] | 0xff000000) >>> 0;
271
+ }
272
+ this.opaqueCopy = copy;
273
+ this.opaqueVersion = this.version;
274
+ }
275
+ return this.opaqueCopy;
276
+ }
277
+ getPixel(x, y) {
278
+ return this.getPixel32(x, y) & 0xffffff;
279
+ }
280
+ setPixel32(x, y, argb) {
281
+ if (x < 0 || y < 0 || x >= this.width || y >= this.height) {
282
+ return;
283
+ }
284
+ this.pixels[y * this.width + x] = this.premultiplied(argb);
285
+ this.changed();
286
+ }
287
+ /** The colour set, the alpha kept as it was. */
288
+ setPixel(x, y, rgb) {
289
+ if (x < 0 || y < 0 || x >= this.width || y >= this.height) {
290
+ return;
291
+ }
292
+ const alpha = unmultiply(this.pixels[y * this.width + x]) & 0xff000000;
293
+ this.pixels[y * this.width + x] = this.premultiplied((alpha | (rgb & 0xffffff)) >>> 0);
294
+ this.changed();
295
+ }
296
+ fillRect(r, argb) {
297
+ const c = this.clip(r);
298
+ if (!c) {
299
+ return;
300
+ }
301
+ const pixel = this.premultiplied(argb);
302
+ if (this.onGpu((copy) => copy.fill(c, pixel))) {
303
+ return;
304
+ }
305
+ for (let y = c.y; y < c.y + c.height; y++) {
306
+ this.pixels.fill(pixel, y * this.width + c.x, y * this.width + c.x + c.width);
307
+ }
308
+ this.changed();
309
+ }
310
+ /**
311
+ * Flash's copyPixels: the source rect's pixels at the destination point,
312
+ * both clipped to their stores. With an alpha bitmap each premultiplied
313
+ * channel is scaled by its alpha at the matching point, k = a, or 256
314
+ * for 255, then shifted down 8, and where the alpha bitmap does not
315
+ * reach, the destination is left as it was; Ruffle's
316
+ * bitmapdata_copypixels_alpha_combine records Flash's 65,536 cases.
317
+ * Without `mergeAlpha` the pixels replace the destination's; with it,
318
+ * and always into an opaque destination, they go source over
319
+ * destination, s + ((d * (256 - sa)) >> 8) a channel (the 160 cases of
320
+ * bitmapdata_copypixels_alpha_merge). In place, a rect reaching past
321
+ * the bitmap's left or top edge may leave a gap (copyGaps).
322
+ */
323
+ copyPixels(source, rect, dx, dy, mergeAlpha, alpha = null, ax = 0, ay = 0) {
324
+ const gaps = source === this ? this.copyGaps(rect, dx, dy) : NO_GAPS;
325
+ // The point and alpha point as given, which the gaps are written from.
326
+ const gx = dx;
327
+ const gy = dy;
328
+ const gax = ax;
329
+ const gay = ay;
330
+ const s = source.clip(rect);
331
+ const d = s &&
332
+ this.clip({ x: dx + s.x - rect.x, y: dy + s.y - rect.y, width: s.width, height: s.height });
333
+ if (!s || !d) {
334
+ if (gaps.length) {
335
+ this.fillGaps(gaps, source, gx, gy, mergeAlpha, alpha, gax, gay);
336
+ this.changed();
337
+ }
338
+ return;
339
+ }
340
+ dx += s.x - rect.x;
341
+ dy += s.y - rect.y;
342
+ ax += s.x - rect.x;
343
+ ay += s.y - rect.y;
344
+ const sx = s.x + (d.x - dx);
345
+ const sy = s.y + (d.y - dy);
346
+ ax += d.x - dx;
347
+ ay += d.y - dy;
348
+ // A plain replacement, where the pixels land as they are: an opaque
349
+ // source's go over anything unchanged, and a gap is empty. In place,
350
+ // all but a move down and left, which Flash's order smears, are a
351
+ // memmove.
352
+ const replaces = !alpha && !source.holdsAlpha && (!source.transparent || (this.transparent && !mergeAlpha));
353
+ const smears = source === this && d.y > sy && d.x < sx;
354
+ if (replaces &&
355
+ !smears &&
356
+ this.onGpu((copy) => copy.copy(source, { x: sx, y: sy, width: d.width, height: d.height }, d.x, d.y) &&
357
+ gaps.every((gap) => copy.fill(gap, source.transparent ? 0 : 0xff000000)))) {
358
+ return;
359
+ }
360
+ // In place, in Flash's order, which reads what it already wrote in one
361
+ // direction (Ruffle's bitmapdata_copypixels_self): rows bottom-up when
362
+ // the copy moves down without moving left, columns right to left when
363
+ // it moves right.
364
+ const up = source === this && d.y > sy && d.x >= sx;
365
+ const left = source === this && d.x > sx;
366
+ // The arrays taken once, the written one first: a source or alpha that is this store reads
367
+ // it too, and so what the copy already wrote. A source that holds alpha is copied opaque, as
368
+ // a draw reads it; within itself, as it is.
369
+ const into = this.pixels;
370
+ const pixels = source !== this && source.holdsAlpha ? source.drawable : source.readable;
371
+ const mask = alpha?.readable ?? null;
372
+ const maskWidth = alpha?.width ?? 0;
373
+ const maskHeight = alpha?.height ?? 0;
374
+ for (let r = 0; r < d.height; r++) {
375
+ const row = up ? d.height - 1 - r : r;
376
+ const to = (d.y + row) * this.width + d.x;
377
+ const from = (sy + row) * source.width + sx;
378
+ for (let c = 0; c < d.width; c++) {
379
+ const i = left ? d.width - 1 - c : c;
380
+ let p = pixels[from + i];
381
+ if (mask) {
382
+ const mx = ax + i;
383
+ const my = ay + row;
384
+ if (mx < 0 || my < 0 || mx >= maskWidth || my >= maskHeight) {
385
+ continue;
386
+ }
387
+ p = scale(p, mask[my * maskWidth + mx] >>> 24);
388
+ }
389
+ into[to + i] = this.composite(p, into[to + i], mergeAlpha);
390
+ }
391
+ }
392
+ this.fillGaps(gaps, source, gx, gy, mergeAlpha, alpha, gax, gay);
393
+ this.changed();
394
+ }
395
+ /**
396
+ * The parts of an in-place copy Flash leaves empty: moved right and down
397
+ * by no more than its size, the rect is written whole from (dx, dy), and
398
+ * what of it lies left of or above the bitmap reads as nothing, where any
399
+ * other move (or another source) clips it and moves the point with it.
400
+ * Within the store, and apart; none for any other copy.
401
+ */
402
+ copyGaps(rect, dx, dy) {
403
+ // Where the source's (0, 0) lands.
404
+ const kx = dx - rect.x;
405
+ const ky = dy - rect.y;
406
+ if ((rect.x >= 0 && rect.y >= 0) ||
407
+ rect.width <= 0 ||
408
+ rect.height <= 0 ||
409
+ kx < 0 ||
410
+ ky < 0 ||
411
+ kx > rect.width ||
412
+ ky > rect.height) {
413
+ return NO_GAPS;
414
+ }
415
+ const right = dx + rect.width;
416
+ const bottom = dy + rect.height;
417
+ const left = this.clip({ x: dx, y: dy, width: Math.min(kx, right) - dx, height: rect.height });
418
+ const x0 = Math.max(dx, kx);
419
+ const top = this.clip({ x: x0, y: dy, width: right - x0, height: Math.min(ky, bottom) - dy });
420
+ return [left, top].filter((r) => r !== null);
421
+ }
422
+ /**
423
+ * The gaps of an in-place copy written, as an empty pixel copied: a
424
+ * transparent bitmap's are what Flash's memory held there, taken as
425
+ * transparent; an opaque one's Flash reads back as 0, alpha and all, and
426
+ * draws black, which this keeps them, as opaque black.
427
+ */
428
+ fillGaps(gaps, source, dx, dy, mergeAlpha, alpha, ax, ay) {
429
+ const empty = source.transparent ? 0 : 0xff000000;
430
+ for (const gap of gaps) {
431
+ for (let y = gap.y; y < gap.y + gap.height; y++) {
432
+ for (let x = gap.x; x < gap.x + gap.width; x++) {
433
+ let p = empty;
434
+ if (alpha) {
435
+ const mx = ax + x - dx;
436
+ const my = ay + y - dy;
437
+ if (mx < 0 || my < 0 || mx >= alpha.width || my >= alpha.height) {
438
+ continue;
439
+ }
440
+ p = scale(p, alpha.readable[my * alpha.width + mx] >>> 24);
441
+ }
442
+ const i = y * this.width + x;
443
+ this.pixels[i] = this.composite(p, this.pixels[i], mergeAlpha);
444
+ }
445
+ }
446
+ }
447
+ }
448
+ /** A copied pixel `p` on `d`: over it into an opaque store or merging, else in its place. */
449
+ composite(p, d, mergeAlpha) {
450
+ if (!this.transparent) {
451
+ return (over(p, d) | 0xff000000) >>> 0;
452
+ }
453
+ return mergeAlpha ? over(p, d) : p;
454
+ }
455
+ /** The rect's pixels, unmultiplied ARGB, row by row; the rect clipped to the store. */
456
+ getVector(r) {
457
+ const c = this.clip(r);
458
+ const out = [];
459
+ if (!c) {
460
+ return out;
461
+ }
462
+ for (let y = c.y; y < c.y + c.height; y++) {
463
+ for (let x = c.x; x < c.x + c.width; x++) {
464
+ out.push(this.unmultiplied(this.readable[y * this.width + x]));
465
+ }
466
+ }
467
+ return out;
468
+ }
469
+ /** Unmultiplied ARGB words in the destination's byte order, row by row; the rect clipped to the store. */
470
+ argbBytes(rect, littleEndian = false) {
471
+ const c = this.clip(rect);
472
+ if (!c) {
473
+ return new Uint8Array(0);
474
+ }
475
+ const pixels = this.readable;
476
+ const out = new Uint8Array(c.width * c.height * 4);
477
+ const view = new DataView(out.buffer);
478
+ let j = 0;
479
+ for (let y = c.y; y < c.y + c.height; y++) {
480
+ for (let i = y * this.width + c.x, end = i + c.width; i < end; i++, j += 4) {
481
+ const p = this.unmultiplied(pixels[i]);
482
+ view.setUint32(j, p, littleEndian);
483
+ }
484
+ }
485
+ return out;
486
+ }
487
+ /** The rect's pixels set from `values`, unmultiplied ARGB, row by row, as far as they go; how many it took. */
488
+ setVector(r, values) {
489
+ const c = this.clip(r);
490
+ if (!c) {
491
+ return 0;
492
+ }
493
+ // As many as there are values, row by row; the rest stay.
494
+ let k = 0;
495
+ for (let y = c.y; y < c.y + c.height && k < values.length; y++) {
496
+ for (let x = c.x; x < c.x + c.width && k < values.length; x++) {
497
+ this.pixels[y * this.width + x] = this.premultiplied(values[k++] >>> 0);
498
+ }
499
+ }
500
+ this.changed();
501
+ return k;
502
+ }
503
+ clone() {
504
+ const copy = new BitmapStore(this.width, this.height, this.transparent, 0);
505
+ copy.pixels.set(this.readable);
506
+ return copy;
507
+ }
508
+ dispose() {
509
+ this.pixels = new Uint32Array(0);
510
+ for (const copy of this.copies) {
511
+ copy.destroy();
512
+ }
513
+ this.copies.clear();
514
+ this.gpu = null;
515
+ this.disposed = true;
516
+ this.changed();
517
+ }
518
+ /** A change: counted, and told to each Bitmap showing the store. */
519
+ changed() {
520
+ this.version++;
521
+ for (const ref of this.views) {
522
+ const view = ref.deref();
523
+ if (view) {
524
+ view.pixelsChanged(this.disposed);
525
+ }
526
+ else {
527
+ this.views.delete(ref);
528
+ }
529
+ }
530
+ }
531
+ }
532
+ /** Source over destination, both premultiplied, as Flash does: s + ((d * (256 - sa)) >> 8) a channel. */
533
+ export function over(s, d) {
534
+ const sa = s >>> 24;
535
+ if (sa === 255) {
536
+ return s >>> 0;
537
+ }
538
+ if (sa === 0) {
539
+ return d >>> 0;
540
+ }
541
+ // Each channel written out: a closure over s and d would take a context each pixel.
542
+ const k = 256 - sa;
543
+ return (((Math.min(255, sa + (((d >>> 24) * k) >> 8)) << 24) |
544
+ (Math.min(255, ((s >>> 16) & 0xff) + ((((d >>> 16) & 0xff) * k) >> 8)) << 16) |
545
+ (Math.min(255, ((s >>> 8) & 0xff) + ((((d >>> 8) & 0xff) * k) >> 8)) << 8) |
546
+ Math.min(255, (s & 0xff) + (((d & 0xff) * k) >> 8))) >>>
547
+ 0);
548
+ }
549
+ /** A premultiplied pixel's channels scaled by an alpha, as Flash's alpha bitmap scales them. */
550
+ function scale(p, a) {
551
+ if (a === 255) {
552
+ return p >>> 0;
553
+ }
554
+ return ((((((p >>> 24) * a) >> 8) << 24) |
555
+ (((((p >>> 16) & 0xff) * a) >> 8) << 16) |
556
+ (((((p >>> 8) & 0xff) * a) >> 8) << 8) |
557
+ (((p & 0xff) * a) >> 8)) >>>
558
+ 0);
559
+ }
560
+ /** Each bitmap's fill store, by its pixels, which the SWFs that define the bitmap alike share. */
561
+ const fillStores = new WeakMap();
562
+ /**
563
+ * The store a SWF bitmap's fills draw from, one for all its shapes and for
564
+ * every SWF that defines it alike, so one texture; null until its image is
565
+ * decoded. Nothing writes it.
566
+ */
567
+ export function characterStore(character) {
568
+ const pixels = character.pixels;
569
+ if (!pixels) {
570
+ return null;
571
+ }
572
+ if (!character.store) {
573
+ let store = fillStores.get(pixels);
574
+ if (!store) {
575
+ store = BitmapStore.of(pixels);
576
+ fillStores.set(pixels, store);
577
+ }
578
+ character.store = store;
579
+ }
580
+ return character.store;
581
+ }
582
+ /** Whether a word's low byte comes first in memory, as on every machine a browser runs on. */
583
+ const LITTLE_ENDIAN = new Uint8Array(new Uint32Array([1]).buffer)[0] === 1;
584
+ /** Premultiplied ARGB as the RGBA bytes a texture holds, still premultiplied. */
585
+ export function rgbaOf(pixels) {
586
+ const out = new Uint8Array(pixels.length * 4);
587
+ rgbaInto(pixels, out);
588
+ return out;
589
+ }
590
+ /**
591
+ * rgbaOf into `out`, `pixels.length * 4` bytes or more, as a texture
592
+ * uploaded again and again takes it; `opaque`, every alpha 255, as an
593
+ * opaque store holding alpha draws (BitmapStore's drawable). Little-endian,
594
+ * a pixel is a word whose red and blue swap, written whole rather than a
595
+ * byte at a time.
596
+ */
597
+ export function rgbaInto(pixels, out, opaque = false) {
598
+ if (out.length < pixels.length * 4) {
599
+ throw new RangeError(`${out.length} bytes hold no ${pixels.length} pixels`);
600
+ }
601
+ const alpha = opaque ? 0xff000000 : 0;
602
+ if (LITTLE_ENDIAN && out.byteOffset % 4 === 0) {
603
+ const words = new Uint32Array(out.buffer, out.byteOffset, pixels.length);
604
+ for (let i = 0; i < pixels.length; i++) {
605
+ const p = pixels[i] | alpha;
606
+ words[i] = (p & 0xff00ff00) | ((p >>> 16) & 0xff) | ((p & 0xff) << 16);
607
+ }
608
+ return;
609
+ }
610
+ for (let i = 0; i < pixels.length; i++) {
611
+ const p = pixels[i] | alpha;
612
+ const j = i * 4;
613
+ out[j] = (p >>> 16) & 0xff;
614
+ out[j + 1] = (p >>> 8) & 0xff;
615
+ out[j + 2] = p & 0xff;
616
+ out[j + 3] = p >>> 24;
617
+ }
618
+ }
619
+ /** RGBA bytes read from a texture as premultiplied ARGB. */
620
+ export function argbOf(bytes) {
621
+ const out = new Uint32Array(bytes.length / 4);
622
+ for (let i = 0; i < out.length; i++) {
623
+ const j = i * 4;
624
+ out[i] = ((bytes[j + 3] << 24) | (bytes[j] << 16) | (bytes[j + 1] << 8) | bytes[j + 2]) >>> 0;
625
+ }
626
+ return out;
627
+ }
@@ -0,0 +1,68 @@
1
+ // A display object drawn into a bitmap: rendered by the host's renderer
2
+ // over its own bounds alone, then composited as a bitmap is (ops.ts
3
+ // drawBitmap). AS3's BitmapData.draw and AVM1's share it.
4
+ import { bounds } from "../display/bounds.js";
5
+ import { pickWork } from "../display/display.js";
6
+ import { transformRect } from "../display/geometry.js";
7
+ import { drawnAsStage } from "../display/perspective.js";
8
+ import { BitmapStore } from "./bitmap.js";
9
+ import { drawBitmap } from "./ops.js";
10
+ /** `d` drawn into `store` through `m`, as drawInto draws a display object. */
11
+ function drawObject(drawer, store, d, m, c, blend, r, samples) {
12
+ // Only the part the object can reach: its bounds through the matrix, a
13
+ // pixel wider for anti-aliasing, within the clip and the bitmap; the
14
+ // snapshot's cost is then the object's size, not the bitmap's.
15
+ const local = bounds(d, true);
16
+ if (!local) {
17
+ return;
18
+ }
19
+ const reach = transformRect(local, m);
20
+ const x0 = Math.max(0, Math.floor(reach.xMin) - 1, r ? r.x : 0);
21
+ const y0 = Math.max(0, Math.floor(reach.yMin) - 1, r ? r.y : 0);
22
+ const x1 = Math.min(store.width, Math.ceil(reach.xMax) + 1, r ? r.x + r.width : store.width);
23
+ const y1 = Math.min(store.height, Math.ceil(reach.yMax) + 1, r ? r.y + r.height : store.height);
24
+ if (x1 <= x0 || y1 <= y0) {
25
+ return;
26
+ }
27
+ const placed = { ...m, tx: m.tx - x0, ty: m.ty - y0 };
28
+ // Plain source over goes on the GPU, the store left there until a script reads it.
29
+ if (!c &&
30
+ blend === "normal" &&
31
+ drawer.drawInto(store, d, placed, x0, y0, x1 - x0, y1 - y0, samples)) {
32
+ return;
33
+ }
34
+ // Erase and alpha go by where the object is, not how much of a pixel it covers: adl draws
35
+ // them unsmoothed, as low quality draws.
36
+ const grid = blend === "erase" || blend === "alpha" ? 1 : samples;
37
+ const drawn = new BitmapStore(x1 - x0, y1 - y0, true, 0);
38
+ drawn.pixels = drawer.snapshot(d, placed, x1 - x0, y1 - y0, grid);
39
+ const at = { a: 1, b: 0, c: 0, d: 1, tx: x0, ty: y0 };
40
+ drawBitmap(store, drawn, at, c, blend, r, false, false, "drawing");
41
+ }
42
+ /**
43
+ * A display object drawn into `store` through `m` by `drawer`, the host's
44
+ * renderer, over its own bounds alone, then composited as a bitmap is: an
45
+ * AS3 BitmapData's draw, and an AVM1 one's.
46
+ */
47
+ export function drawDisplayObject(drawer, store, d, m, c, blend, r, samples) {
48
+ // What is in 3D in an object on no stage projects as on a stage the bitmap's size.
49
+ let top = d;
50
+ while (top.parent) {
51
+ top = top.parent;
52
+ }
53
+ const restore = drawnAsStage(top, store.width, store.height);
54
+ if (!restore) {
55
+ drawObject(drawer, store, d, m, c, blend, r, samples);
56
+ return;
57
+ }
58
+ // Planes in perspective made before are made again, for that stage and after it; only then,
59
+ // as each change picks the pointer's hover again and remakes every plane.
60
+ pickWork.changes++;
61
+ try {
62
+ drawObject(drawer, store, d, m, c, blend, r, samples);
63
+ }
64
+ finally {
65
+ restore();
66
+ pickWork.changes++;
67
+ }
68
+ }