@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,860 @@
1
+ // What a SWF asks to load, and when it comes: a Loader's SWF or image, from a URL
2
+ // the host fetches or from bytes, compiled and linked off the frame, in
3
+ // the order asked, and given its LoaderInfo's events in the frame after;
4
+ // a URLStream's or a Sound's bytes, and the host's other callbacks, held
5
+ // for the next frame; navigateToURL's and sendToURL's requests; and the
6
+ // LoaderInfo of each, the main SWF's too.
7
+ import { isAs3, readSwf } from "../../format/index.js";
8
+ import { avm2 } from "../../runtime/index.js";
9
+ import { Avm1, getUrlNavigate } from "../avm1/avm1.js";
10
+ import { BitmapStore } from "../bitmap/bitmap.js";
11
+ import { decodeImageFile, decodeImages, hasUndecoded, imageFormat } from "../bitmap/images.js";
12
+ import { MovieClip, rootOf, unloads } from "../display/display.js";
13
+ import { readLibrary } from "../display/timeline.js";
14
+ import { LoadedAvm1Input } from "../input/avm1.js";
15
+ import { streamFrames } from "../media/sounds.js";
16
+ import { dispatchEvent } from "./events.js";
17
+ export class Loads {
18
+ s;
19
+ /** Only loaded AVM1 movies enter this map; ordinary AS3 players create no AVM1 runtime. */
20
+ avm1Movies = new Map();
21
+ /** Loads asked for and not yet completed, in order; each prepared after the one before it. */
22
+ loads = [];
23
+ /** AVM1 movies from bytes, in the order asked, for the end of a frame. */
24
+ avm1Loads = [];
25
+ preparing = Promise.resolve();
26
+ /** Host requests are independent of Loader's ordered preparation chain. */
27
+ pendingRequests = new Set();
28
+ /** Completed host byte requests delivered at the next frame, with scripts on the player thread. */
29
+ readyBytes = [];
30
+ /** A load from bytes was asked, and heldTime has not yet told of it ready. */
31
+ holding = false;
32
+ /** How many loads from bytes there have been: each gets a URL of its own under the main SWF's. */
33
+ dynamic = 0;
34
+ /** The main SWF's flashvars, as the host gave them. */
35
+ flashvars;
36
+ /** What the next frame does after EXIT_FRAME, before the loads' ends: the main SWF's load events. */
37
+ frameEnds = [];
38
+ constructor(s, options) {
39
+ this.s = s;
40
+ this.flashvars = options.parameters ?? {};
41
+ }
42
+ tickAvm1() {
43
+ if (this.avm1Movies.size === 0) {
44
+ return;
45
+ }
46
+ for (const [root, movie] of this.avm1Movies) {
47
+ if (movie.first) {
48
+ const swf = movie.first;
49
+ movie.first = null;
50
+ root.fresh = false;
51
+ movie.vm.startScripts(swf);
52
+ }
53
+ else {
54
+ movie.vm.tick(this.s.frameRate);
55
+ }
56
+ }
57
+ }
58
+ streamFrames() {
59
+ if (this.avm1Movies.size === 0) {
60
+ return 0;
61
+ }
62
+ let frames = 0;
63
+ for (const movie of this.avm1Movies.values()) {
64
+ frames = Math.max(frames, streamFrames(movie.vm.sounds));
65
+ }
66
+ return frames;
67
+ }
68
+ destroyAvm1() {
69
+ for (const movie of this.avm1Movies.values()) {
70
+ movie.vm.destroy(false);
71
+ }
72
+ this.avm1Movies.clear();
73
+ this.s.avm1Input = null;
74
+ }
75
+ /** Keep an asynchronous host task visible to settled(). */
76
+ trackRequest(task) {
77
+ this.pendingRequests.add(task);
78
+ void task.then(() => this.pendingRequests.delete(task), () => this.pendingRequests.delete(task));
79
+ }
80
+ /** Cross a host callback into the next player frame, where scripts may run. */
81
+ deferHostEvent(deliver) {
82
+ this.readyBytes.push(deliver);
83
+ }
84
+ /**
85
+ * A LoaderInfo for `loader` (null for the main SWF's), empty until its
86
+ * content is known: what its natives read is kept on it as $ fields.
87
+ */
88
+ loaderInfo(loader) {
89
+ const info = this.s.rt.construct(this.s.rt.classNamed("flash.display::LoaderInfo"));
90
+ info.$loader = loader;
91
+ info.$content = null;
92
+ info.$bytes = null;
93
+ info.$swf = null;
94
+ info.$image = null;
95
+ info.$url = null;
96
+ info.$params = NO_PARAMETERS;
97
+ info.$loaderURL = loader ? this.ownerUrl(loader) : this.s.url;
98
+ info.$loaded = 0;
99
+ info.$total = 0;
100
+ return info;
101
+ }
102
+ /** The main SWF's loaderInfo.parameters: its URL's query, then the flashvars. */
103
+ mainParameters() {
104
+ const parameters = queryParameters(this.s.url);
105
+ // A host in plain JavaScript may give other values: Flash's are strings.
106
+ for (const [name, value] of Object.entries(this.flashvars)) {
107
+ parameters.set(name, String(value));
108
+ }
109
+ return parameters;
110
+ }
111
+ /** What a LoaderInfo knows once its SWF is: the bytes, the header's version, frame rate and size. */
112
+ describe(info, bytes, swf) {
113
+ info.$bytes = bytes;
114
+ info.$total = bytes.length;
115
+ info.$swf = {
116
+ version: swf.header.version,
117
+ frameRate: swf.frameRate,
118
+ width: Math.round((swf.frameSize.xMax - swf.frameSize.xMin) / 20),
119
+ height: Math.round((swf.frameSize.yMax - swf.frameSize.yMin) / 20),
120
+ as3: isAs3(swf),
121
+ };
122
+ }
123
+ /**
124
+ * The domain a load goes into: the LoaderContext's applicationDomain, or
125
+ * by default a new child of the domain of the code that asked, as
126
+ * Flash's `new ApplicationDomain(ApplicationDomain.currentDomain)`.
127
+ */
128
+ loadDomain(applicationDomain) {
129
+ const chosen = applicationDomain?.$domain;
130
+ return chosen ?? this.s.rt.childDomain(this.s.code.codeDomain());
131
+ }
132
+ /**
133
+ * The URL of the SWF a Loader belongs to, which its content's loaderURL
134
+ * reports and its relative URLs resolve against: Flash's is the SWF whose
135
+ * code made the Loader, which the runtime does not track, so it is the
136
+ * SWF the Loader is on the display list of when it loads, else the main.
137
+ */
138
+ ownerUrl(loader) {
139
+ return rootOf(loader.$display)?.loaderInfo?.$url ?? this.s.url;
140
+ }
141
+ /**
142
+ * Whose a loadBytes' content is: the SWF whose code called it. Where the
143
+ * caller cannot be told, as from a timer, only while every SWF ever
144
+ * loaded had one origin is it that origin's, its Loader's SWF's on the
145
+ * display list, else the main SWF's, which then shares it; with several,
146
+ * no one's, an opaque URL that no check allows: never the main SWF's
147
+ * for a Loader nothing places, which an unloaded child may have made.
148
+ */
149
+ bytesOwner(loader) {
150
+ // This, requestLoad and Loader's _loadBytes are the player's frames.
151
+ const caller = this.s.code.callerUrl(3);
152
+ if (caller !== null) {
153
+ return caller;
154
+ }
155
+ if (new Set(this.s.code.everUrls().map(originOf)).size !== 1) {
156
+ return UNKNOWN_OWNER;
157
+ }
158
+ return this.ownerUrl(loader);
159
+ }
160
+ /**
161
+ * A Loader's loadBytes. Flash tells the whole of the progress at once, in
162
+ * the call, the URL still null; the content comes in a later frame, under
163
+ * a URL of the bytes' own.
164
+ */
165
+ requestLoad(loader, bytes, domain = this.loadDomain(null), parameters = null) {
166
+ const begun = this.begin(loader, parameters);
167
+ if (!begun) {
168
+ return;
169
+ }
170
+ const { info, generation } = begun;
171
+ // The bytes' SWF is the calling SWF's, as Flash gave loadBytes content
172
+ // the domain of the SWF that loaded it: its code is judged as that SWF's.
173
+ info.$loaderURL = this.bytesOwner(loader);
174
+ info.$dynamic = `${info.$loaderURL}/[[DYNAMIC]]/${++this.dynamic}`;
175
+ info.$bytes = bytes;
176
+ info.$total = bytes.length;
177
+ // A listener of either event may close the Loader or load anew, which ends this load.
178
+ this.progress(info, 0);
179
+ if (loader.$generation !== generation) {
180
+ return;
181
+ }
182
+ this.progress(info, bytes.length);
183
+ if (loader.$generation !== generation) {
184
+ return;
185
+ }
186
+ info.$domain = domain;
187
+ let swf = null;
188
+ try {
189
+ swf = readSwf(bytes);
190
+ }
191
+ catch {
192
+ // Not a SWF: refused when its turn comes, as Flash refuses it in a later frame.
193
+ }
194
+ if (swf && !isAs3(swf)) {
195
+ const load = this.newLoad(loader, generation, null, domain, parameters, swf);
196
+ load.bytes = bytes;
197
+ this.requestAvm1(load, swf);
198
+ return;
199
+ }
200
+ this.holding = true;
201
+ this.enqueue(loader, generation, null, Promise.resolve({ bytes, status: 0, headers: [] }), domain, parameters, swf);
202
+ }
203
+ /**
204
+ * An AVM1 SWF from bytes. Flash makes its AVM1Movie in the call, named
205
+ * then, and has it in the Loader at the end of the frame, after
206
+ * EXIT_FRAME, before the next frame begins: the last asked first, INIT
207
+ * and COMPLETE with each, as adl traces it (the `avm1-movie` case). A
208
+ * SWF with images has them decoded first, which may take frames; one
209
+ * whose images the decoder refuses ends in IOError #2124 there instead.
210
+ */
211
+ requestAvm1(load, swf) {
212
+ const library = this.avm1Library(swf, load.domain);
213
+ const pending = {
214
+ load,
215
+ swf,
216
+ library,
217
+ movie: this.avm1Movie(library),
218
+ ready: false,
219
+ failed: false,
220
+ };
221
+ this.avm1Loads.push(pending);
222
+ if (!hasUndecoded(library)) {
223
+ pending.ready = true;
224
+ return;
225
+ }
226
+ this.trackRequest(decodeImages(library, this.s.decodeImage).then(() => {
227
+ pending.ready = true;
228
+ }, () => {
229
+ pending.ready = true;
230
+ pending.failed = true;
231
+ }));
232
+ }
233
+ /** An AVM1 SWF's library: its timelines play by themselves, with no AS3 objects but the root's. */
234
+ avm1Library(swf, domain) {
235
+ const library = readLibrary(swf);
236
+ library.domain = domain;
237
+ return library;
238
+ }
239
+ /**
240
+ * An AVM1 SWF's root, not yet on its first frame, as AS3 sees it: an
241
+ * AVM1Movie, which is no InteractiveObject, so the pointer's hits on the
242
+ * movie's artwork go to its Loader; its own VM picks its buttons (input/avm1.ts).
243
+ */
244
+ avm1Movie(library) {
245
+ const root = new MovieClip(library.root, library);
246
+ root.avm1Root = true;
247
+ return this.s.constructAs(root, this.s.rt.classNamed("flash.display::AVM1Movie"));
248
+ }
249
+ /** The AVM1 movies from bytes ready by the end of this frame, the last asked first. */
250
+ deliverAvm1Loads() {
251
+ for (let i = this.avm1Loads.length - 1; i >= 0; i--) {
252
+ const pending = this.avm1Loads[i];
253
+ if (!pending.ready) {
254
+ continue;
255
+ }
256
+ this.avm1Loads.splice(i, 1);
257
+ try {
258
+ this.deliverAvm1(pending);
259
+ }
260
+ catch (error) {
261
+ this.s.reportUncaught(error);
262
+ }
263
+ }
264
+ }
265
+ /**
266
+ * An AVM1 movie from bytes as the Loader's content, then its INIT and
267
+ * COMPLETE. It keeps its first frame through the next frame's advance,
268
+ * as adl shows it, then plays at the stage's frame rate.
269
+ */
270
+ deliverAvm1(pending) {
271
+ const { load, swf, library, movie } = pending;
272
+ if (load.generation !== load.loader.$generation) {
273
+ return;
274
+ }
275
+ if (pending.failed) {
276
+ dispatchEvent(this.s, this.loaderInfoOf(load.loader), this.ioError(this.errorText(2124)));
277
+ return;
278
+ }
279
+ const end = this.complete(load, swf, library, null, movie);
280
+ movie.$display.fresh = true;
281
+ end();
282
+ }
283
+ /**
284
+ * A load begins: the one before it is dropped, pending or complete, and
285
+ * its LoaderInfo knows nothing again, as Flash's load() does at the call
286
+ * (Ruffle's `loader_reuse` trace), but the parameters its context gave,
287
+ * which Flash tells from the call on. The old content's REMOVED listeners
288
+ * may load anew themselves, and that load is then the one that counts:
289
+ * null tells the caller so.
290
+ */
291
+ begin(loader, parameters) {
292
+ this.closeLoad(loader);
293
+ const generation = loader.$generation;
294
+ this.dropContent(loader);
295
+ if (loader.$generation !== generation) {
296
+ return null;
297
+ }
298
+ const info = this.loaderInfoOf(loader);
299
+ info.$loaderURL = this.ownerUrl(loader);
300
+ info.$params = parameters ?? NO_PARAMETERS;
301
+ return { info, generation };
302
+ }
303
+ /** A Loader's close, and what a new load does first: a pending load does nothing when its turn comes, and its fetch is aborted. */
304
+ closeLoad(loader) {
305
+ loader.$generation = (loader.$generation ?? 0) + 1;
306
+ loader.$abort?.abort();
307
+ loader.$abort = null;
308
+ }
309
+ progress(info, loaded) {
310
+ info.$loaded = loaded;
311
+ dispatchEvent(this.s, info, this.s.rt.construct(this.s.rt.classNamed("flash.events::ProgressEvent"), "progress", false, false, loaded, info.$total));
312
+ }
313
+ /** A Loader's load of a URL: the host fetches it, resolved, and the load completes in a frame after the bytes arrive. */
314
+ requestLoadUrl(loader, request, domain = this.loadDomain(null), parameters = null) {
315
+ const begun = this.begin(loader, parameters);
316
+ if (!begun) {
317
+ return;
318
+ }
319
+ const { info, generation } = begun;
320
+ const outgoing = {
321
+ ...this.fetchRequest(request, info.$loaderURL),
322
+ purpose: "content",
323
+ };
324
+ const abort = new AbortController();
325
+ loader.$abort = abort;
326
+ const fetch = this.s.fetch;
327
+ this.enqueue(loader, generation, outgoing.url, fetch ? fetch(outgoing, abort.signal) : Promise.reject(), domain, parameters);
328
+ }
329
+ /**
330
+ * A URLStream's or a Sound's host request, delivered in a frame after the bytes arrive: a Sound's
331
+ * is "content", a URLStream's "data".
332
+ */
333
+ requestBytes(request, signal, deliver, purpose = "data") {
334
+ const outgoing = { ...this.fetchRequest(request, this.s.url), purpose };
335
+ const fetch = this.s.fetch;
336
+ // Attach both handlers at once; an early rejection must not be unhandled.
337
+ const fetched = (fetch ? fetch(outgoing, signal) : Promise.reject()).then((result) => result, () => ({ bytes: null, status: 0, headers: [] }));
338
+ const completed = fetched.then((result) => {
339
+ this.readyBytes.push(() => deliver(result, outgoing.url));
340
+ });
341
+ this.trackRequest(completed);
342
+ }
343
+ /**
344
+ * navigateToURL's page, resolved as a load's URL is; nothing where the
345
+ * host opens none, or for an empty URL, which Ruffle's navigators ignore
346
+ * rather than open the SWF's own directory. A browser navigates only by
347
+ * GET or POST, so any other method goes as a GET, its data in the query,
348
+ * as Flash's does from a browser.
349
+ */
350
+ navigateTo(request, window) {
351
+ if (String(request.$url) === "") {
352
+ return;
353
+ }
354
+ const post = String(request.$method ?? "GET").toUpperCase() === "POST";
355
+ this.s.navigate?.(this.fetchRequest(request, this.s.url, { method: post ? "POST" : "GET" }), window);
356
+ }
357
+ /** sendToURL's request, sent by the host's fetch and its response dropped, as Flash ignores it. */
358
+ sendTo(request) {
359
+ const fetch = this.s.fetch;
360
+ if (!fetch || !this.s.sendToUrl) {
361
+ return;
362
+ }
363
+ fetch({ ...this.fetchRequest(request, this.s.url), purpose: "send" }, new AbortController().signal).catch(() => { });
364
+ }
365
+ /** Security.loadPolicyFile's URL, resolved as a load's is, for the host to judge requests by. */
366
+ policyFile(url) {
367
+ this.s.loadPolicyFile?.(resolve(this.s.base ?? this.s.url, url));
368
+ }
369
+ /** Snapshot a URLRequest at load time, before scripts can change its data or headers. */
370
+ fetchRequest(request, base, options = {}) {
371
+ if (typeof request === "string") {
372
+ return { url: resolve(this.s.base ?? base, request), method: "GET", headers: [], body: null };
373
+ }
374
+ let url = String(request?.$url ?? "");
375
+ const method = options.method ?? String(request?.$method ?? "GET");
376
+ const get = method.toUpperCase() === "GET";
377
+ const post = method.toUpperCase() === "POST";
378
+ const data = request?.$data;
379
+ let body = null;
380
+ if (data !== null && data !== undefined) {
381
+ if (typeof data === "object" && this.s.rt.traitsOf(data).name === "flash.utils::ByteArray") {
382
+ if (!get) {
383
+ const bytes = avm2.bytesOf(this.s.rt, data);
384
+ body = bytes.buffer.slice(0, bytes.length);
385
+ }
386
+ }
387
+ else {
388
+ const text = this.s.rt.toString(data);
389
+ if (get) {
390
+ url = appendQuery(url, text);
391
+ }
392
+ else {
393
+ body = new TextEncoder().encode(text);
394
+ }
395
+ }
396
+ }
397
+ const headers = [];
398
+ if ((post || options.requestHeaders === "all") && options.requestHeaders !== false) {
399
+ for (const header of request?.$headers?.$a ?? []) {
400
+ headers.push([
401
+ this.s.rt.toString(this.s.rt.getProperty(header, this.s.rt.publicName("name"))),
402
+ this.s.rt.toString(this.s.rt.getProperty(header, this.s.rt.publicName("value"))),
403
+ ]);
404
+ }
405
+ }
406
+ if (body && !headers.some(([name]) => name.toLowerCase() === "content-type")) {
407
+ headers.push([
408
+ "Content-Type",
409
+ String(request?.$contentType ?? "application/x-www-form-urlencoded"),
410
+ ]);
411
+ }
412
+ return { url: resolve(this.s.base ?? base, url), method, headers, body };
413
+ }
414
+ /** The text a failed stream reports, using Flash Player's message and the resolved URL. */
415
+ streamError(url, local = false) {
416
+ const text = this.errorText(2032);
417
+ return local
418
+ ? text.replace(/\.$/, "")
419
+ : `${text} URL: ${resolve(this.s.base ?? this.s.url, url)}`;
420
+ }
421
+ /**
422
+ * Resolves once every load asked for so far has its code linked or has
423
+ * failed, so that a host stepping frames by hand sees each complete in
424
+ * the frame after its request, as Flash's loadBytes does.
425
+ */
426
+ settled() {
427
+ return Promise.all([this.preparing, ...this.pendingRequests]).then(() => { });
428
+ }
429
+ /**
430
+ * Whether the time since the host's last call was a load from bytes':
431
+ * one was asked since, or was still compiling at that call. Flash has a
432
+ * loadBytes' content in the frame after the call, ENTER_FRAME's,
433
+ * whatever the SWF's size, its code verified as it runs (the
434
+ * `loader-bytes-frames` case; in adl 0.5 MB of ABC and 8 MB of sounds
435
+ * still came in that frame), and content may count on it, as with a
436
+ * timer of a second, set at the call, that reads the Loader's child. True
437
+ * once more after the load is ready, for the call in which it came.
438
+ */
439
+ heldTime() {
440
+ if (!this.holding) {
441
+ return false;
442
+ }
443
+ this.holding = this.holdsFrame();
444
+ return true;
445
+ }
446
+ /**
447
+ * Whether the next frame waits for the load due next, one from bytes
448
+ * whose code still compiles. Not one behind a load of a URL whose bytes
449
+ * have not come: that is not Flash's to time. A closed one still
450
+ * compiling ahead of it is passed over, as it will never come.
451
+ */
452
+ holdsFrame() {
453
+ const next = this.loads.find((load) => !load.ready && !load.failed && load.generation === load.loader.$generation);
454
+ return next !== undefined && next.url === null;
455
+ }
456
+ newLoad(loader, generation, url, domain, parameters, swf) {
457
+ return {
458
+ loader,
459
+ generation,
460
+ url,
461
+ domain,
462
+ parameters,
463
+ bytes: new Uint8Array(0),
464
+ status: 0,
465
+ ready: null,
466
+ failed: null,
467
+ swf,
468
+ };
469
+ }
470
+ enqueue(loader, generation, url, bytes, domain, parameters, swf = null) {
471
+ const load = this.newLoad(loader, generation, url, domain, parameters, swf);
472
+ this.loads.push(load);
473
+ // Settled at once, not when its turn in the chain comes: a rejection must find its handler.
474
+ const fetched = bytes.then((result) => result, () => ({ bytes: null, status: 0, headers: [] }));
475
+ this.preparing = this.preparing.then(async () => {
476
+ const result = await fetched;
477
+ load.status = result.status;
478
+ if (!result.bytes) {
479
+ load.failed = `${this.errorText(2035)} URL: ${url}`;
480
+ return;
481
+ }
482
+ load.bytes = result.bytes;
483
+ // Where a redirect took it: the SWF is that URL's, for its LoaderInfo and its checks.
484
+ if (url !== null && result.url) {
485
+ load.url = result.url;
486
+ }
487
+ try {
488
+ load.ready = await this.prepare(load);
489
+ }
490
+ catch {
491
+ // Unknown or undecodable content, or code that does not link.
492
+ load.failed = this.errorText(2124);
493
+ }
494
+ });
495
+ }
496
+ /** "Error #id: message", as Flash's IOErrorEvent texts begin, debugger or not. */
497
+ errorText(id) {
498
+ return `Error #${id}: ${avm2.errorMessages[id]}`;
499
+ }
500
+ /** Decode an image or link a SWF off the frame; return what the frame does with it. */
501
+ async prepare(load) {
502
+ const format = imageFormat(load.bytes);
503
+ if (format) {
504
+ const pixels = await decodeImageFile(load.bytes, format, this.s.decodeImage);
505
+ if (!pixels) {
506
+ throw new Error("Image decode failed");
507
+ }
508
+ return () => this.completeImage(load, pixels, `image/${format}`);
509
+ }
510
+ const swf = load.swf ?? readSwf(load.bytes);
511
+ if (!isAs3(swf)) {
512
+ // An AVM1 SWF from a URL: its content comes as an AS3 SWF's does.
513
+ const library = this.avm1Library(swf, load.domain);
514
+ await decodeImages(library, this.s.decodeImage);
515
+ return () => this.complete(load, swf, library, null);
516
+ }
517
+ const library = readLibrary(swf);
518
+ library.domain = load.domain;
519
+ // Its images first: once its code is linked, a script in the domain can
520
+ // make its symbols, whose bitmaps take the pixels there are then.
521
+ await decodeImages(library, this.s.decodeImage);
522
+ // One from bytes is the SWF's that loaded it (bytesOwner), as far as its own URL goes.
523
+ const run = await this.s.code.link(swf, load.domain, load.url ?? this.loaderInfoOf(load.loader).$loaderURL ?? this.ownerUrl(load.loader), library);
524
+ // Bound as soon as linked, as its classes are found in the domain from
525
+ // here: one made before the load completes, as another SWF loaded into
526
+ // the domain completes, is its symbol's. Not a load closed or replaced
527
+ // meanwhile, which never completes.
528
+ if (load.generation === load.loader.$generation) {
529
+ this.s.bind(swf, library);
530
+ }
531
+ return () => this.complete(load, swf, library, run);
532
+ }
533
+ /** A Loader's unload: a pending load dropped, its content out of the display list, its LoaderInfo empty, the Loader kept; stopped for good if `stop`, as unloadAndStop has it, else playing on as an orphan. */
534
+ unload(loader, stop = false) {
535
+ this.closeLoad(loader);
536
+ const content = loader.$content ?? null;
537
+ this.dropContent(loader);
538
+ this.s.rt.forgetCaches();
539
+ if (stop && content) {
540
+ this.s.lifecycle.stopAll(content.$display);
541
+ }
542
+ }
543
+ /**
544
+ * The content let go of, as unload() and a new load do: the Loader's and
545
+ * the LoaderInfo's first, so an unload a listener asks for finds none,
546
+ * then UNLOAD on the LoaderInfo with the child still attached, as Flash's
547
+ * trace has it (the `loads-init` case), then the child out.
548
+ */
549
+ dropContent(loader) {
550
+ const content = loader.$content ?? null;
551
+ loader.$content = null;
552
+ const info = loader.$loaderInfo;
553
+ if (info) {
554
+ info.$content = null;
555
+ info.$bytes = null;
556
+ info.$swf = null;
557
+ info.$image = null;
558
+ info.$domain = undefined;
559
+ info.$url = null;
560
+ info.$params = NO_PARAMETERS;
561
+ info.$loaded = 0;
562
+ info.$total = 0;
563
+ }
564
+ if (content) {
565
+ const movie = this.avm1Movies.get(content.$display);
566
+ if (movie) {
567
+ movie.vm.destroy(false);
568
+ this.avm1Movies.delete(content.$display);
569
+ if (this.s.avm1Input?.remove(content.$display)) {
570
+ this.s.avm1Input = null;
571
+ }
572
+ }
573
+ unloads.count++;
574
+ }
575
+ if (content && info) {
576
+ dispatchEvent(this.s, info, this.s.event("unload"));
577
+ }
578
+ const display = loader.$display;
579
+ if (content?.$display?.parent === display) {
580
+ this.s.lifecycle.removing(content.$display);
581
+ display.removeChild(content.$display);
582
+ }
583
+ }
584
+ /**
585
+ * The main SWF, all of it loaded: INIT, final PROGRESS, then COMPLETE, after its first
586
+ * frame's scripts and EXIT_FRAME. Preloaders may subscribe in that frame's script and
587
+ * advance only from final progress, as AIR does for a streamed URL. Where its
588
+ * document class's constructor threw (`constructed` false), Flash sends
589
+ * COMPLETE alone (measured in adl).
590
+ */
591
+ mainLoaded(info, constructed = true) {
592
+ this.frameEnds.push(() => {
593
+ if (constructed) {
594
+ dispatchEvent(this.s, info, this.s.event("init"));
595
+ this.progress(info, info.$total);
596
+ }
597
+ dispatchEvent(this.s, info, this.s.event("complete"));
598
+ });
599
+ }
600
+ /**
601
+ * Give the loads whose code is linked their content, oldest first, and
602
+ * stop at one still linking: they complete in the order asked. What
603
+ * each does at the frame's end is returned. Each delivery and each load
604
+ * is on its own: one whose code throws, as a loaded SWF's document
605
+ * class's constructor, is reported, and those after it still come.
606
+ */
607
+ completeLoads() {
608
+ const ends = [];
609
+ if (this.readyBytes.length !== 0) {
610
+ for (const deliver of this.readyBytes.splice(0)) {
611
+ try {
612
+ deliver();
613
+ }
614
+ catch (error) {
615
+ this.s.reportUncaught(error);
616
+ }
617
+ }
618
+ }
619
+ while (this.loads.length && (this.loads[0].ready || this.loads[0].failed)) {
620
+ const load = this.loads.shift();
621
+ try {
622
+ this.completeLoad(load, ends);
623
+ }
624
+ catch (error) {
625
+ this.s.reportUncaught(error);
626
+ }
627
+ }
628
+ return ends;
629
+ }
630
+ completeLoad(load, ends) {
631
+ if (load.generation !== load.loader.$generation) {
632
+ return;
633
+ }
634
+ if (load.ready) {
635
+ ends.push(load.ready());
636
+ return;
637
+ }
638
+ const info = this.loaderInfoOf(load.loader);
639
+ if (load.url !== null) {
640
+ dispatchEvent(this.s, info, this.s.httpStatus(load.status));
641
+ if (load.generation !== load.loader.$generation) {
642
+ return;
643
+ }
644
+ }
645
+ dispatchEvent(this.s, info, this.ioError(load.failed ?? ""));
646
+ }
647
+ /** An IOErrorEvent of `text`, as a failed load ends. */
648
+ ioError(text) {
649
+ return this.s.rt.construct(this.s.rt.classNamed("flash.events::IOErrorEvent"), "ioError", false, false, text);
650
+ }
651
+ loaderInfoOf(loader) {
652
+ loader.$generation ??= 0;
653
+ loader.$loaderInfo ??= this.loaderInfo(loader);
654
+ return loader.$loaderInfo;
655
+ }
656
+ /**
657
+ * A load's content, in the frame after its bytes came, after ENTER_FRAME
658
+ * and before FRAME_CONSTRUCTED, as Flash: the SWF's code run; its
659
+ * document class constructed, with parent and stage null; ADDED to it
660
+ * while it still has no parent, as Flash does; then the LoaderInfo's
661
+ * content, and the Loader's child, with ADDED again and ADDED_TO_STAGE
662
+ * if the loader is on the stage. Its first frame's script runs with
663
+ * the frame's, and INIT and COMPLETE follow EXIT_FRAME.
664
+ */
665
+ complete(load, swf, library, run, made = null) {
666
+ const info = this.startContent(load, swf);
667
+ if (!info) {
668
+ return () => { };
669
+ }
670
+ const live = () => load.generation === load.loader.$generation;
671
+ let object;
672
+ let root;
673
+ let avm1 = null;
674
+ if (run) {
675
+ run();
676
+ this.s.symbols.addFontLibrary(library);
677
+ root = new MovieClip(library.root, library);
678
+ root.loaderInfo = info;
679
+ root.placeFirstFrame();
680
+ object = this.s.constructAs(root, this.s.rt.classNamed(library.classes.get(0) ?? "flash.display::MovieClip", load.domain));
681
+ dispatchEvent(this.s, object, this.s.event("added", true));
682
+ // The SWF's own code has run by now, its document class's constructor
683
+ // among it, which reaches the Loader through loaderInfo.loader.
684
+ if (!live()) {
685
+ return () => { };
686
+ }
687
+ }
688
+ else {
689
+ // Its scripts run in AVM1, sharing only the message broker and host services with AS3.
690
+ object = made ?? this.avm1Movie(library);
691
+ root = object.$display;
692
+ root.loaderInfo = info;
693
+ const s = this.s;
694
+ const vm = new Avm1(s.codegen, {
695
+ print: s.rt.print,
696
+ onUncaught: (error) => s.reportUncaught(error),
697
+ url: load.url ?? info.$dynamic ?? info.$loaderURL ?? s.url,
698
+ base: s.base ?? undefined,
699
+ fetch: s.fetch ?? undefined,
700
+ socket: s.socket ?? undefined,
701
+ audio: s.audio,
702
+ storage: s.storage,
703
+ fileHost: s.fileHost,
704
+ decodeImage: s.decodeImage,
705
+ externalInterface: s.externalInterface ?? undefined,
706
+ navigate: getUrlNavigate(s.navigate, load.url ?? s.url),
707
+ fsCommand: s.fsCommand ?? undefined,
708
+ sendToUrl: s.sendToUrl,
709
+ localConnections: s.localConnections,
710
+ realTime: s.timers.realTime,
711
+ });
712
+ vm.attach(swf, library, root, load.bytes.length, s.frameRate, s);
713
+ this.avm1Movies.set(root, { vm, first: load.url === null ? swf : null });
714
+ s.avm1Input ??= new LoadedAvm1Input(s);
715
+ s.avm1Input.add(root, vm);
716
+ avm1 = vm;
717
+ root.enterFirstFrame();
718
+ }
719
+ const end = this.attachContent(load, object);
720
+ if (avm1 && load.url !== null) {
721
+ avm1.startScripts(swf);
722
+ }
723
+ return end;
724
+ }
725
+ /** URL progress precedes image metadata, while a SWF header is known at full progress. */
726
+ startContent(load, swf) {
727
+ const info = this.loaderInfoOf(load.loader);
728
+ load.loader.$abort = null;
729
+ // A listener of any of these may close the Loader or load anew, and this load then ends here.
730
+ const live = () => load.generation === load.loader.$generation;
731
+ if (load.url !== null) {
732
+ // A load from bytes told these in the call; one of a URL tells them as
733
+ // the bytes come: OPEN knowing nothing, the total, then the bytes.
734
+ dispatchEvent(this.s, info, this.s.event("open"));
735
+ if (!live()) {
736
+ return null;
737
+ }
738
+ info.$total = load.bytes.length;
739
+ this.progress(info, 0);
740
+ if (!live()) {
741
+ return null;
742
+ }
743
+ // Its URL's query comes with the SWF, as Flash tells it from the
744
+ // second PROGRESS on, unless the context gave parameters.
745
+ if (!load.parameters) {
746
+ info.$params = queryParameters(load.url);
747
+ }
748
+ info.$domain = load.domain;
749
+ info.$bytes = load.bytes;
750
+ if (swf) {
751
+ this.describe(info, load.bytes, swf);
752
+ }
753
+ this.progress(info, load.bytes.length);
754
+ if (!live()) {
755
+ return null;
756
+ }
757
+ }
758
+ else if (swf) {
759
+ this.describe(info, load.bytes, swf);
760
+ }
761
+ return info;
762
+ }
763
+ completeImage(load, pixels, contentType) {
764
+ const info = this.startContent(load, null);
765
+ if (!info) {
766
+ return () => { };
767
+ }
768
+ info.$image = { width: pixels.width, height: pixels.height, contentType };
769
+ const rt = this.s.rt;
770
+ const data = rt.construct(rt.classNamed("flash.display::BitmapData"), 1, 1);
771
+ data.$store = BitmapStore.of(pixels);
772
+ const object = rt.construct(rt.classNamed("flash.display::Bitmap"), data);
773
+ object.$display.loaderInfo = info;
774
+ return this.attachContent(load, object);
775
+ }
776
+ attachContent(load, object) {
777
+ const info = this.loaderInfoOf(load.loader);
778
+ const root = object.$display;
779
+ const live = () => load.generation === load.loader.$generation;
780
+ info.$url = load.url ?? info.$dynamic ?? info.$loaderURL;
781
+ info.$content = object;
782
+ load.loader.$content = object;
783
+ const display = load.loader.$display;
784
+ display.addChildAt(root, display.children.length);
785
+ this.s.lifecycle.added(root);
786
+ return () => {
787
+ if (!live()) {
788
+ return;
789
+ }
790
+ dispatchEvent(this.s, info, this.s.event("init"));
791
+ if (!live()) {
792
+ return;
793
+ }
794
+ if (load.url !== null) {
795
+ dispatchEvent(this.s, info, this.s.httpStatus(load.status));
796
+ }
797
+ // An INIT or status listener that unloads has no COMPLETE, as Flash.
798
+ if (live()) {
799
+ dispatchEvent(this.s, info, this.s.event("complete"));
800
+ }
801
+ };
802
+ }
803
+ }
804
+ const NO_PARAMETERS = new Map();
805
+ /**
806
+ * The names and values of a URL's query, as Flash reads them into
807
+ * loaderInfo.parameters: decoded, `+` as a space, a name without `=` an
808
+ * empty value, an empty name left out, and the last of a name kept.
809
+ */
810
+ function queryParameters(url) {
811
+ const parameters = new Map();
812
+ const path = url.split("#", 1)[0];
813
+ const at = path.indexOf("?");
814
+ if (at < 0) {
815
+ return parameters;
816
+ }
817
+ for (const [name, value] of new URLSearchParams(path.slice(at + 1))) {
818
+ if (name !== "") {
819
+ parameters.set(name, value);
820
+ }
821
+ }
822
+ return parameters;
823
+ }
824
+ function appendQuery(url, query) {
825
+ if (!query) {
826
+ return url;
827
+ }
828
+ const at = url.indexOf("#");
829
+ const path = at < 0 ? url : url.slice(0, at);
830
+ const fragment = at < 0 ? "" : url.slice(at);
831
+ const separator = path.includes("?") ? (/[?&]$/.test(path) ? "" : "&") : "?";
832
+ return path + separator + query + fragment;
833
+ }
834
+ /** What loadBytes content of no one SWF is: an opaque origin, which no same-domain check passes. */
835
+ const UNKNOWN_OWNER = "about:blank";
836
+ /** A URL's origin, or the URL where it has none to read. */
837
+ function originOf(url) {
838
+ try {
839
+ return new URL(url).origin;
840
+ }
841
+ catch {
842
+ return url;
843
+ }
844
+ }
845
+ /**
846
+ * `url` against `base`, enough for a SWF's relative paths: one with a
847
+ * scheme is itself, one from the root keeps the base's origin, and any
848
+ * other replaces the base's last segment.
849
+ */
850
+ /** `url` against `base`, as Flash resolves a load's URL: AVM1's loads resolve by it too. */
851
+ export function resolve(base, url) {
852
+ if (/^[a-z][a-z0-9+.-]*:/i.test(url)) {
853
+ return url;
854
+ }
855
+ const origin = base.match(/^[a-z][a-z0-9+.-]*:\/\/[^/]*/i)?.[0] ?? "";
856
+ if (url.startsWith("/")) {
857
+ return origin + url;
858
+ }
859
+ return base.slice(0, base.lastIndexOf("/") + 1) + url;
860
+ }