@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,616 @@
1
+ // A SWF loaded and played: its root clip on its first frame, and each tick
2
+ // a frame on, in the order Flash runs one: the clips that were on the
3
+ // display list advance their timelines (a clip made in this frame does not
4
+ // advance until the next); with scripts, the frame's events and scripts
5
+ // follow, or an AVM1 SWF's actions; then the frame is drawn.
6
+ import { backgroundColor, readSwf } from "../format/index.js";
7
+ import { Avm1Keyboard } from "./avm1/keyboard.js";
8
+ import { Avm1Pointer } from "./avm1/pointer.js";
9
+ import { decodeImages, decodeInBrowser } from "./bitmap/images.js";
10
+ import { drawKernelFrame, drawKernelLetGo, drawKernelUsed } from "./bitmap/kernel.js";
11
+ import { BUTTON, CLIP, Container, MovieClip, OTHER, unloads, walkList, } from "./display/display.js";
12
+ import { setStageSize } from "./display/perspective.js";
13
+ import { readLibrary } from "./display/timeline.js";
14
+ import { customContextMenu } from "./input/context-menu.js";
15
+ import { KeyboardInput } from "./input/keyboard.js";
16
+ import { PointerInput } from "./input/pointer.js";
17
+ import { TouchInput } from "./input/touch.js";
18
+ import { soundHostOf, streamFrames } from "./media/sounds.js";
19
+ /** Ordinary frames one advance() may run at most, however fast the SWF and slow the display. */
20
+ const MAX_FRAMES_PER_CALL = 5;
21
+ /** A stream may catch up further when its scripts are cheap; input still gets a bounded turn. */
22
+ const MAX_STREAM_FRAMES = 60;
23
+ const MIN_STREAM_BUDGET_MS = 8;
24
+ const MAX_STREAM_BUDGET_MS = 50;
25
+ /** The host's recent calls to advance() whose lower median is its typical interval. */
26
+ const INTERVALS = 9;
27
+ /** Calls seen before the typical interval is trusted; until then, a frame per call at most. */
28
+ const MIN_INTERVALS = 3;
29
+ /**
30
+ * The longest typical interval taken for a display's, in ms: none
31
+ * refreshes slower than about 30 Hz. Longer, the host is lagging, its
32
+ * calls stretched by the frames themselves, and more frames a call would
33
+ * feed the lag; it gets one a call and the content slows down, as Flash's.
34
+ */
35
+ const DISPLAY_INTERVAL = 36;
36
+ /**
37
+ * The longest a frame waits for a load from bytes, in ms of the host's
38
+ * time (Scripting.holdsFrame): a load that never ends does not stop the
39
+ * player for good.
40
+ */
41
+ const HOLD_LIMIT = 10_000;
42
+ export class Player {
43
+ bytes;
44
+ scripting;
45
+ avm1;
46
+ swf;
47
+ root;
48
+ /**
49
+ * The stage, which holds the root and what scripts put beside it, as a
50
+ * loader does the SWF it loads: what a host draws. With scripts,
51
+ * flash.display.Stage's other face.
52
+ */
53
+ stage = new Container();
54
+ library;
55
+ width;
56
+ height;
57
+ frameRate;
58
+ swfBackground;
59
+ /** The stage's colour, 0xRRGGBB: the SWF's SetBackgroundColor until a script sets Stage.color; a host that reads it each frame follows that. */
60
+ get background() {
61
+ return this.scripting?.stageColor ?? this.swfBackground;
62
+ }
63
+ /**
64
+ * The stage's quality, "LOW" to "BEST": the host's at the start, then what
65
+ * a script sets, Stage.quality or AVM1's _quality; a host that reads it
66
+ * each frame draws by it.
67
+ */
68
+ get quality() {
69
+ return this.scripting?.quality ?? this.avm1?.quality ?? "HIGH";
70
+ }
71
+ set quality(quality) {
72
+ if (this.scripting) {
73
+ this.scripting.quality = quality;
74
+ }
75
+ if (this.avm1) {
76
+ this.avm1.quality = quality;
77
+ }
78
+ }
79
+ /** The host's build, a short commit or a version, which the context menu's About item names. */
80
+ build = null;
81
+ defaultContextMenu = true;
82
+ get showDefaultContextMenu() {
83
+ return this.scripting?.showDefaultContextMenu ?? this.defaultContextMenu;
84
+ }
85
+ set showDefaultContextMenu(value) {
86
+ this.defaultContextMenu = value;
87
+ if (this.scripting) {
88
+ this.scripting.showDefaultContextMenu = value;
89
+ }
90
+ }
91
+ /** Renderer-independent mouse routing, once scripts have been loaded. */
92
+ pointer;
93
+ avm1Pointer;
94
+ /** The keyboard's, likewise: keys to the focused object, and typing into a focused field. */
95
+ keyboard;
96
+ /** Touches, likewise: TouchEvents, and the mouse the primary touch moves. */
97
+ touch;
98
+ /**
99
+ * Without scripts the player is ready at once, but for the images of
100
+ * its bitmap fills, which `start` decodes; with them, `start` loads the
101
+ * SWF's code and constructs the root, which is asynchronous. An AVM1
102
+ * SWF's actions run with `avm1`, which `start` compiles them for; an
103
+ * ActionScript 3 SWF's never do.
104
+ */
105
+ constructor(bytes, scripting = null, avm1 = null) {
106
+ this.bytes = bytes;
107
+ this.scripting = scripting;
108
+ this.avm1 = avm1;
109
+ this.swf = readSwf(bytes);
110
+ this.library = readLibrary(this.swf);
111
+ this.width = Math.round((this.swf.frameSize.xMax - this.swf.frameSize.xMin) / 20);
112
+ this.height = Math.round((this.swf.frameSize.yMax - this.swf.frameSize.yMin) / 20);
113
+ setStageSize(this.stage, this.width, this.height);
114
+ this.frameRate = this.swf.frameRate || 24;
115
+ this.swfBackground = backgroundColor(this.swf);
116
+ drawKernelUsed();
117
+ const keyboard = scripting ? new KeyboardInput(this.stage, scripting) : null;
118
+ // An AVM1 SWF's keys go to Key, its buttons and its clips.
119
+ this.keyboard = keyboard ?? (avm1 && !scripting ? new Avm1Keyboard(avm1) : null);
120
+ const pointer = scripting ? new PointerInput(this.stage, scripting, keyboard) : null;
121
+ // An AVM1 SWF's buttons and clips take the pointer by AVM1's rules.
122
+ this.avm1Pointer = avm1 && !scripting ? new Avm1Pointer(this.stage, avm1) : null;
123
+ this.pointer = pointer ?? this.avm1Pointer;
124
+ this.touch = pointer && scripting ? new TouchInput(this.stage, scripting, pointer) : null;
125
+ if (scripting) {
126
+ scripting.pointer = pointer;
127
+ }
128
+ this.root = new MovieClip(this.library.root, this.library);
129
+ this.stage.addChildAt(this.root, 0);
130
+ // An AVM1 SWF's clips play through its AVM1, from the first frame on.
131
+ avm1?.attach(this.swf, this.library, this.root, bytes.length);
132
+ if (!scripting) {
133
+ this.root.enterFirstFrame();
134
+ }
135
+ }
136
+ /**
137
+ * With scripts: load the SWF's code, make the stage's and the root's
138
+ * AS3 objects (the root's of the document class, SymbolClass's id 0, or
139
+ * MovieClip), which enters the first frame, and run its scripts, as
140
+ * Flash has done when it dispatches INIT.
141
+ */
142
+ async start() {
143
+ const s = this.scripting;
144
+ if (!s) {
145
+ // Its bitmap fills' images, which a SWF with scripts decodes as it links.
146
+ await decodeImages(this.library, decodeInBrowser);
147
+ // Its first frame's actions, once its code is loaded.
148
+ if (this.avm1) {
149
+ await this.avm1.load(this.swf);
150
+ }
151
+ return;
152
+ }
153
+ await s.code.loadSwf(this.swf, this.library);
154
+ s.stage = this.stage;
155
+ s.root = this.root;
156
+ s.stageWidth = this.width;
157
+ s.stageHeight = this.height;
158
+ s.onStageLayout?.();
159
+ s.stageColor = this.swfBackground;
160
+ s.frameRate = this.frameRate;
161
+ s.constructAs(this.stage, s.rt.classNamed("flash.display::Stage"));
162
+ // The first frame has its time too: the clock is a frame's duration on as it runs, as in Flash.
163
+ s.timers.beginFrame(1000 / this.frameRate);
164
+ // The main SWF's LoaderInfo: on the root, which every display object under it reports.
165
+ const info = s.loads.loaderInfo(null);
166
+ s.loads.describe(info, this.bytes, this.swf);
167
+ info.$loaded = this.bytes.length;
168
+ info.$url = s.url;
169
+ info.$params = s.loads.mainParameters();
170
+ this.root.loaderInfo = info;
171
+ // The stage's too: what a script puts on the stage itself has the stage
172
+ // for its root and this for its LoaderInfo, and takes hits, as in Flash.
173
+ this.stage.loaderInfo = info;
174
+ // The main SWF's root is root1, as Flash names the root at depth 0.
175
+ this.root.name = "root1";
176
+ // Its first frame's children are there before the document class's constructor runs.
177
+ this.root.placeFirstFrame();
178
+ // A document class's constructor that throws is reported, and the SWF
179
+ // plays on as far as it got, as in Flash and Ruffle: the object is the
180
+ // root's from its super() on, its listeners and frame scripts kept.
181
+ let constructed = false;
182
+ try {
183
+ s.constructAs(this.root, s.rt.classNamed(this.library.classes.get(0) ?? "flash.display::MovieClip", s.mainDomain));
184
+ constructed = true;
185
+ s.lifecycle.rootConstructed(this.root);
186
+ }
187
+ catch (error) {
188
+ s.reportUncaught(error);
189
+ }
190
+ info.$content = this.root.object ?? null;
191
+ s.loads.mainLoaded(info, constructed);
192
+ this.root.enterFirstFrame();
193
+ s.frame(this.stage, false);
194
+ this.frameRate = s.frameRate;
195
+ }
196
+ /** Whether destroy has been called. */
197
+ get destroyed() {
198
+ return this.stopped;
199
+ }
200
+ stopped = false;
201
+ /** Snapshot the SWF's menu on demand; hosts keep the callbacks only while it is open. */
202
+ contextMenu(p) {
203
+ if (this.stopped) {
204
+ return [];
205
+ }
206
+ this.pointer?.flush();
207
+ const s = this.scripting;
208
+ let menu = { items: [], quality: this.showDefaultContextMenu };
209
+ try {
210
+ if (s) {
211
+ menu = s.clipboard.gesture(() => customContextMenu(s, this.stage, p));
212
+ s.updates++;
213
+ }
214
+ }
215
+ catch (error) {
216
+ s?.reportUncaught(error);
217
+ }
218
+ if (menu.quality) {
219
+ const qualities = ["LOW", "MEDIUM", "HIGH", "BEST"];
220
+ for (let i = 0; i < qualities.length; i++) {
221
+ const quality = qualities[i];
222
+ menu.items.push({
223
+ caption: `Quality: ${quality[0]}${quality.slice(1).toLowerCase()}`,
224
+ enabled: true,
225
+ checked: this.quality === quality,
226
+ separatorBefore: i === 0 && menu.items.length > 0,
227
+ select: () => {
228
+ if (!this.stopped) {
229
+ this.quality = quality;
230
+ }
231
+ },
232
+ });
233
+ }
234
+ }
235
+ return menu.items;
236
+ }
237
+ /**
238
+ * Stop for good: no frame plays after, and with scripts their sounds,
239
+ * connections and fetches end (Scripting.destroy). What the host made
240
+ * for the player, its renderer, its input bindings and its loop, is the
241
+ * host's to let go.
242
+ */
243
+ destroy() {
244
+ if (!this.stopped) {
245
+ drawKernelLetGo();
246
+ }
247
+ this.stopped = true;
248
+ this.scripting?.destroy();
249
+ this.avm1?.destroy();
250
+ unloads.count++;
251
+ }
252
+ active = true;
253
+ /** The activation the host last asked for, applied once no script runs. */
254
+ wanted = true;
255
+ applying = false;
256
+ /** How many times the player has been activated or deactivated: each may run listeners. */
257
+ activations = 0;
258
+ /** Whether the player has the system's focus, as last applied; true until a host says otherwise. */
259
+ get isActive() {
260
+ return this.active;
261
+ }
262
+ /**
263
+ * The host's window or page gained or lost focus, or was hidden or shown.
264
+ * Losing it, the keys held are let go, the AVM1 Key's too, and then
265
+ * DEACTIVATE is broadcast to every EventDispatcher that listens, display
266
+ * object or not; gaining it back, ACTIVATE. Keys are let go with no
267
+ * keyUp: Flash sends none when it loses focus, which is why content
268
+ * clears its own keys on DEACTIVATE, and a keyUp the user never made
269
+ * could fire an action in a game. The mouse's buttons stay the
270
+ * pointer's, which finds a release it never saw at its next move.
271
+ *
272
+ * It applies once the JavaScript that called it has returned, or at the
273
+ * next frame, whichever comes first: the page may move its focus in a
274
+ * call a script made, an ExternalInterface call's, and no listener runs
275
+ * inside another script. Only the last state asked for counts, so a blur
276
+ * and a focus in one call send nothing, and a host may call this on
277
+ * every focus, blur and visibility change it sees.
278
+ */
279
+ setActive(active) {
280
+ this.wanted = active;
281
+ if (!this.applying && active !== this.active) {
282
+ this.applying = true;
283
+ queueMicrotask(() => this.applyActive());
284
+ }
285
+ }
286
+ /** The activation asked for, if it changed; once per change. */
287
+ applyActive() {
288
+ this.applying = false;
289
+ const active = this.wanted;
290
+ if (this.stopped || active === this.active) {
291
+ return;
292
+ }
293
+ this.active = active;
294
+ this.activations++;
295
+ if (!active) {
296
+ this.avm1?.releaseKeys();
297
+ }
298
+ this.scripting?.broadcastActivation(active ? "activate" : "deactivate");
299
+ }
300
+ /** Time a host has let pass, in ms, still to be played as frames. */
301
+ owed = 0;
302
+ /** The host's time the frame due has waited for a load from bytes so far. */
303
+ held = 0;
304
+ /** The last INTERVALS times passed to advance(), a ring, for the host's typical interval. */
305
+ intervals = [];
306
+ nextInterval = 0;
307
+ /** Frames the last call to advance() played. */
308
+ lastRan = 0;
309
+ sortedIntervals = [];
310
+ /** Frames played. */
311
+ played = 0;
312
+ /** The clips a tick advances, kept: the whole display list's, every frame. Null while in use. */
313
+ ticking = [];
314
+ /**
315
+ * A count that moves whenever what the player shows may have changed: a
316
+ * frame played, a key, a pointer event that changes a button, focus or a
317
+ * selection, a script's updateAfterEvent, a call from the page into
318
+ * one of the SWF's ExternalInterface callbacks, or the player activated
319
+ * or deactivated. A plain pointer move does not: what its listeners
320
+ * change shows at the next frame, as Flash and Ruffle draw it, so a fast
321
+ * mouse does not draw faster than the SWF. Loads and socket data arrive
322
+ * in a frame. A host that draws only when this moved draws every frame
323
+ * Flash would, and none in between, once it has drawn after start; what
324
+ * the host itself changes, a resize, it draws for itself.
325
+ */
326
+ get changes() {
327
+ return (this.played +
328
+ (this.pointer?.redraws ?? 0) +
329
+ (this.touch?.redraws ?? 0) +
330
+ (this.scripting?.updates ?? 0) +
331
+ (this.keyboard?.handled ?? 0) +
332
+ (this.scripting?.hostCalls ?? 0) +
333
+ this.activations);
334
+ }
335
+ /**
336
+ * Play what `dt` milliseconds are worth, as Flash paces: frames on a
337
+ * grid of the frame rate's duration. Without streamed audio, those a
338
+ * long frame or a stall lost are dropped, not caught up with. Flash runs
339
+ * the frame due at once after an overrun and the next at its grid slot, never two
340
+ * back to back (measured in adl, docs/architecture/input.md), so content that
341
+ * moves by the time between frames always sees time pass between them.
342
+ * A call runs as many frames as the host's typical interval holds, the
343
+ * lower median of its recent calls and never the current one, so a
344
+ * hitch does not become a burst: one where the SWF's frame is as long
345
+ * as the display's or longer, more for a SWF faster than the display,
346
+ * and one while the interval is longer than a display's. `busy` is the
347
+ * ms the host's last call took, by its own clock: where its frames each
348
+ * took longer than a frame, they overran, and the call runs one, as
349
+ * Flash runs the frame after an overrun alone. The interval cannot tell
350
+ * that from a display's: a SWF that spins on getTimer to hold itself to
351
+ * a slower rate makes the calls a display's interval apart, and two
352
+ * frames a call would wait twice as long. Where the clock skipped to
353
+ * the time such a spin waited for, sparing the host the spin, no frame
354
+ * plays until the real clock has caught up with it. A `dt` that is
355
+ * not a finite positive number counts as none. A host playing in real
356
+ * time calls this each animation frame; the tests step frames with
357
+ * tick(). A stream's device cursor can request a bounded batch of frames
358
+ * to catch its timeline up, with scripts and events on each; the host
359
+ * draws once after the batch. Returns how many frames it played.
360
+ */
361
+ advance(dt, busy = 0) {
362
+ if (this.stopped) {
363
+ return 0;
364
+ }
365
+ drawKernelFrame();
366
+ // The pointer's and the touches' last moves, so the frame's scripts see where they are now.
367
+ this.pointer?.flush();
368
+ this.touch?.flush();
369
+ const passed = Number.isFinite(dt) && dt > 0 ? dt : 0;
370
+ const frame = 1000 / this.frameRate;
371
+ const typical = this.typicalInterval(passed);
372
+ const overran = this.lastRan > 0 && busy / this.lastRan > frame;
373
+ let most = typical > DISPLAY_INTERVAL || overran
374
+ ? 1
375
+ : Math.min(MAX_FRAMES_PER_CALL, Math.max(1, Math.round(typical / frame)));
376
+ // A frame that waits for a load from bytes plays once it is ready, as
377
+ // Flash's waits for the parse. The frames do not catch up the time
378
+ // held: they stop at the frame's slot. The timers count it, as Flash's
379
+ // do, but fire nothing due after that slot until the frame has played,
380
+ // its content made and INIT and COMPLETE told: Flash's parse takes a
381
+ // few tens of milliseconds where a compile here may take seconds, and
382
+ // content counts on having its content before a timer set at the call.
383
+ // That holds for the call in which the load came too, which its
384
+ // compile may have taken whole. Each load waited for has the ten
385
+ // seconds to itself: one asked as the last comes does not inherit its
386
+ // wait.
387
+ const timers = this.scripting?.timers;
388
+ // A spin on getTimer had the clock skip ahead to the time it waited
389
+ // for (clock.ts), AS3's or an AVM1 movie's: no frame until the real
390
+ // clock is there, or nearer than the next call would be, as Flash's
391
+ // next frame would wait for the spin. What is owed meanwhile is kept,
392
+ // not dropped: the frame after the spin is due at once, as after an
393
+ // overrun.
394
+ const early = typical / 2;
395
+ const clock = timers ?? this.avm1?.timers;
396
+ const ahead = clock?.ahead() ?? 0;
397
+ const waiting = ahead > early;
398
+ if (waiting) {
399
+ most = 0;
400
+ }
401
+ let holding = false;
402
+ let resuming = false;
403
+ if (!this.scripting?.heldTime()) {
404
+ this.held = 0;
405
+ }
406
+ else if (!this.scripting.holdsFrame()) {
407
+ this.held = 0;
408
+ resuming = true;
409
+ }
410
+ else if (this.held < HOLD_LIMIT) {
411
+ this.held += passed;
412
+ holding = true;
413
+ most = 0;
414
+ }
415
+ let framePassed = passed;
416
+ if (holding || resuming) {
417
+ timers?.holdAfter(Math.max(0, frame - this.owed));
418
+ framePassed = Math.max(0, Math.min(passed, frame - this.owed));
419
+ }
420
+ else {
421
+ timers?.release();
422
+ }
423
+ this.owed += framePassed;
424
+ // How many frames play and what is owed after, worked out first: the
425
+ // timers fire by each frame's time on the grid, not the call's.
426
+ let n = 0;
427
+ let rest = this.owed;
428
+ while (n < most && rest >= frame) {
429
+ rest -= frame;
430
+ n++;
431
+ }
432
+ // Whole frames lost are dropped, the part of one kept for the grid's
433
+ // phase; but not within half an interval of the next, where a call
434
+ // that came a little early leaves one owed under ordinary jitter.
435
+ if (!waiting && rest >= frame + Math.min(frame, typical) / 2) {
436
+ rest %= frame;
437
+ }
438
+ // Streamed audio keeps running through render lag. Catch its timeline
439
+ // up in bounded batches, without drawing the intermediate frames or
440
+ // changing the pacing of movies with only event sounds.
441
+ const ordinary = n;
442
+ if (!holding && !resuming && !waiting) {
443
+ n = Math.max(n, Math.min(MAX_STREAM_FRAMES, this.streamFrames()));
444
+ }
445
+ // Render lag leaves fewer calls to do the same timeline work. Give
446
+ // those calls more CPU time, while still yielding between batches.
447
+ const deadline = n > ordinary
448
+ ? performance.now() +
449
+ Math.max(MIN_STREAM_BUDGET_MS, Math.min(MAX_STREAM_BUDGET_MS, passed / 2))
450
+ : Infinity;
451
+ timers?.hostPassed(passed);
452
+ const deferRender = n > 1;
453
+ let ran = false;
454
+ try {
455
+ for (let i = 0; i < n; i++) {
456
+ if (i >= ordinary &&
457
+ (this.streamFrames() === 0 ||
458
+ (i > 0 &&
459
+ (performance.now() >= deadline ||
460
+ (this.scripting?.heldTime() && this.scripting.holdsFrame()))))) {
461
+ n = i;
462
+ break;
463
+ }
464
+ // Owed as each frame starts: a frame that throws leaves those after it owed.
465
+ this.owed = rest + Math.max(0, ordinary - 1 - i) * frame;
466
+ timers?.frameAt((n - 1 - i) * frame, rest);
467
+ ran = true;
468
+ this.tick(!deferRender);
469
+ // The frame spun to wait: the next waits for the real clock.
470
+ if (i + 1 < n && clock && clock.ahead() > early) {
471
+ n = i + 1;
472
+ break;
473
+ }
474
+ }
475
+ }
476
+ catch (error) {
477
+ if (ran && deferRender) {
478
+ this.scripting?.renderFrame([error]);
479
+ }
480
+ throw error;
481
+ }
482
+ finally {
483
+ timers?.frameAt(Number.NaN, Number.NaN);
484
+ this.lastRan = n;
485
+ if (resuming) {
486
+ timers?.release();
487
+ }
488
+ }
489
+ if (ran && deferRender) {
490
+ this.scripting?.renderFrame();
491
+ }
492
+ // Flash fires timers shorter than a frame between frames too: a call
493
+ // that played none checks them. Not while the clock waits at a spin's
494
+ // time, though: Flash's would be spinning still, and a timer the frame
495
+ // fired would fire again at the same time.
496
+ if (n === 0) {
497
+ this.owed = rest;
498
+ if (ahead <= 0) {
499
+ timers?.betweenFrames(frame);
500
+ // An AVM1 SWF's setInterval timers too.
501
+ this.avm1?.idle();
502
+ }
503
+ this.scripting?.renderPending();
504
+ }
505
+ return n;
506
+ }
507
+ streamFrames() {
508
+ if (this.avm1) {
509
+ return streamFrames(this.avm1.sounds);
510
+ }
511
+ const s = this.scripting;
512
+ return s ? Math.max(streamFrames(soundHostOf(s)), s.loads.streamFrames()) : 0;
513
+ }
514
+ /** `dt` recorded, and the lower median of the recent intervals; 0 until there are a few. */
515
+ typicalInterval(dt) {
516
+ const intervals = this.intervals;
517
+ if (intervals.length < INTERVALS) {
518
+ intervals.push(dt);
519
+ }
520
+ else {
521
+ intervals[this.nextInterval] = dt;
522
+ this.nextInterval = (this.nextInterval + 1) % INTERVALS;
523
+ }
524
+ if (intervals.length < MIN_INTERVALS) {
525
+ return 0;
526
+ }
527
+ const sorted = this.sortedIntervals;
528
+ sorted.length = 0;
529
+ for (let i = 0; i < intervals.length; i++) {
530
+ sorted.push(intervals[i]);
531
+ }
532
+ sorted.sort((a, b) => a - b);
533
+ return sorted[(sorted.length - 1) >> 1];
534
+ }
535
+ /**
536
+ * The next frame: every clip advances, those on the display list, parents
537
+ * before children, loaded SWFs' too, and the orphans a script took off it,
538
+ * which play on; all of them, found first, so that one a parent's frame
539
+ * takes off still has its frame, as in Flash. Then the frame's scripts.
540
+ * A batch defers rendering until its last frame has played.
541
+ */
542
+ tick(render = true) {
543
+ this.applyActive();
544
+ // An AVM1 SWF halted at what Flash cannot read plays no more.
545
+ if (this.stopped || this.avm1?.halted) {
546
+ return;
547
+ }
548
+ this.played++;
549
+ // An AVM1 SWF's clips play in its order, the newest first.
550
+ if (this.avm1 && !this.scripting) {
551
+ this.avm1.tick();
552
+ this.avm1Pointer?.frameEnded();
553
+ return;
554
+ }
555
+ this.scripting?.timers.beginFrame(1000 / this.frameRate);
556
+ const clips = this.ticking ?? [];
557
+ this.ticking = null;
558
+ let count = 0;
559
+ const frames = this.scripting?.frames;
560
+ // One a goto made sit this frame out takes all in it along.
561
+ const sitsOut = (clip) => clip.skipsAfter >= 0 && clip.skipsAfter === frames;
562
+ const collect = (o) => {
563
+ if (o.kind === CLIP && sitsOut(o)) {
564
+ return;
565
+ }
566
+ // The clips under a container from the list it keeps (walkList); a button's states all
567
+ // play, whichever it shows, walked as they are.
568
+ if (o instanceof Container && o.kind !== BUTTON) {
569
+ const { items, ends } = walkList(o);
570
+ for (let i = 0; i < items.length;) {
571
+ const item = items[i];
572
+ if (item.kind === BUTTON) {
573
+ collect(item);
574
+ }
575
+ else if (sitsOut(item)) {
576
+ i = ends[i];
577
+ continue;
578
+ }
579
+ else {
580
+ clips[count++] = item;
581
+ }
582
+ i++;
583
+ }
584
+ return;
585
+ }
586
+ if (o.kind === CLIP) {
587
+ clips[count++] = o;
588
+ }
589
+ const children = o.kind === BUTTON ? o.playingStates() : o.frameChildren;
590
+ for (let i = 0; i < children.length; i++) {
591
+ const child = children[i];
592
+ if (child.kind !== OTHER || child.frameChildren.length !== 0) {
593
+ collect(child);
594
+ }
595
+ }
596
+ };
597
+ collect(this.stage);
598
+ for (const orphan of this.scripting?.lifecycle.orphanRoots() ?? []) {
599
+ collect(orphan);
600
+ }
601
+ // Let go of once advanced, so that the kept list holds none past the tick.
602
+ try {
603
+ for (let i = 0; i < count; i++) {
604
+ clips[i].advance();
605
+ }
606
+ }
607
+ finally {
608
+ clips.fill(null, 0, count);
609
+ this.ticking = clips;
610
+ }
611
+ if (this.scripting) {
612
+ this.scripting.frame(this.stage, true, render);
613
+ this.frameRate = this.scripting.frameRate;
614
+ }
615
+ }
616
+ }