@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,411 @@
1
+ // Shapes as DefineShape, DefineShape2, DefineShape3 and DefineShape4 hold
2
+ // them (SWF specification, chapter 6): fill and line styles, then shape
3
+ // records, edges in twips relative to the pen and style changes that move
4
+ // it or switch styles, until an end record; and morph shapes, which hold
5
+ // two such shapes to blend. The player turns the edges into closed paths
6
+ // per fill; this file only decodes them.
7
+ import { SwfReader } from "./swf.js";
8
+ import { DefineMorphShape, DefineMorphShape2, DefineShape, DefineShape2, DefineShape3, DefineShape4, } from "./tags.js";
9
+ export const IDENTITY = { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 };
10
+ export function readMatrix(r) {
11
+ r.align();
12
+ const m = { ...IDENTITY };
13
+ if (r.ub(1)) {
14
+ const n = r.ub(5);
15
+ m.a = r.sb(n) / 65536;
16
+ m.d = r.sb(n) / 65536;
17
+ }
18
+ if (r.ub(1)) {
19
+ const n = r.ub(5);
20
+ m.b = r.sb(n) / 65536;
21
+ m.c = r.sb(n) / 65536;
22
+ }
23
+ const n = r.ub(5);
24
+ m.tx = r.sb(n);
25
+ m.ty = r.sb(n);
26
+ r.align();
27
+ return m;
28
+ }
29
+ export function readColorTransform(r, alpha) {
30
+ r.align();
31
+ const hasAdd = r.ub(1);
32
+ const hasMul = r.ub(1);
33
+ const n = r.ub(4);
34
+ const ct = { rMul: 1, gMul: 1, bMul: 1, aMul: 1, rAdd: 0, gAdd: 0, bAdd: 0, aAdd: 0 };
35
+ if (hasMul) {
36
+ ct.rMul = r.sb(n) / 256;
37
+ ct.gMul = r.sb(n) / 256;
38
+ ct.bMul = r.sb(n) / 256;
39
+ if (alpha) {
40
+ ct.aMul = r.sb(n) / 256;
41
+ }
42
+ }
43
+ if (hasAdd) {
44
+ ct.rAdd = r.sb(n);
45
+ ct.gAdd = r.sb(n);
46
+ ct.bAdd = r.sb(n);
47
+ if (alpha) {
48
+ ct.aAdd = r.sb(n);
49
+ }
50
+ }
51
+ r.align();
52
+ return ct;
53
+ }
54
+ /** RGB, or RGBA with alpha, as 0xAARRGGBB. */
55
+ function readColor(r, alpha) {
56
+ const red = r.u8();
57
+ const green = r.u8();
58
+ const blue = r.u8();
59
+ const a = alpha ? r.u8() : 255;
60
+ return ((a << 24) | (red << 16) | (green << 8) | blue) >>> 0;
61
+ }
62
+ function readGradient(r, alpha, focal) {
63
+ const matrix = readMatrix(r);
64
+ r.align();
65
+ const spread = r.ub(2);
66
+ const interpolation = r.ub(2);
67
+ const count = r.ub(4);
68
+ const stops = [];
69
+ for (let i = 0; i < count; i++) {
70
+ stops.push({ ratio: r.u8(), color: readColor(r, alpha) });
71
+ }
72
+ const f = focal ? r.s16() : 0;
73
+ return { matrix, spread, interpolation, stops, focal: f / 256 };
74
+ }
75
+ function readFill(r, version) {
76
+ const alpha = version >= 3;
77
+ const type = r.u8();
78
+ if (type === 0x00) {
79
+ return { type: "solid", color: readColor(r, alpha) };
80
+ }
81
+ if (type === 0x10 || type === 0x12 || type === 0x13) {
82
+ const kind = type === 0x10 ? "linear" : type === 0x12 ? "radial" : "focal";
83
+ return { type: kind, gradient: readGradient(r, alpha, type === 0x13) };
84
+ }
85
+ // Bitmap fills 0x40 to 0x43: repeating or clipped, smoothed or not. Any
86
+ // other type byte reads as one too, rather than failing the shape.
87
+ const bitmap = r.u16();
88
+ const matrix = readMatrix(r);
89
+ return { type: "bitmap", bitmap, matrix, repeat: (type & 1) === 0, smooth: (type & 2) === 0 };
90
+ }
91
+ function readFills(r, version) {
92
+ let count = r.u8();
93
+ if (count === 0xff && version >= 2) {
94
+ count = r.u16();
95
+ }
96
+ const fills = [];
97
+ for (let i = 0; i < count && !r.overrun; i++) {
98
+ fills.push(readFill(r, version));
99
+ }
100
+ return fills;
101
+ }
102
+ /** A line of DefineShape to DefineShape3, or a MORPHLINESTYLE's start or end: round, its colour only. */
103
+ function plainLine(width, color) {
104
+ return {
105
+ width,
106
+ color,
107
+ startCap: 0,
108
+ endCap: 0,
109
+ join: 0,
110
+ miterLimit: 3,
111
+ noHScale: false,
112
+ noVScale: false,
113
+ pixelHinting: false,
114
+ noClose: false,
115
+ fill: null,
116
+ };
117
+ }
118
+ /** LINESTYLE2's flags and miter limit, which MORPHLINESTYLE2 has too, before its fill or colour. */
119
+ function readLineFlags(r) {
120
+ const startCap = r.ub(2);
121
+ const join = r.ub(2);
122
+ const hasFill = r.ub(1) === 1;
123
+ const noHScale = r.ub(1) === 1;
124
+ const noVScale = r.ub(1) === 1;
125
+ const pixelHinting = r.ub(1) === 1;
126
+ r.ub(5); // reserved: the flags fill two bytes, must be zero
127
+ const noClose = r.ub(1) === 1;
128
+ const endCap = r.ub(2);
129
+ const miterLimit = join === 2 ? r.u16() / 256 : 3;
130
+ return { startCap, endCap, join, miterLimit, noHScale, noVScale, pixelHinting, noClose, hasFill };
131
+ }
132
+ /** The colour a filled line stands for where only a colour is read. */
133
+ function fillColor(fill) {
134
+ return fill.type === "solid"
135
+ ? fill.color
136
+ : fill.type === "bitmap"
137
+ ? 0xff000000
138
+ : (fill.gradient.stops[0]?.color ?? 0xff000000);
139
+ }
140
+ function readLines(r, version) {
141
+ let count = r.u8();
142
+ if (count === 0xff && version >= 2) {
143
+ count = r.u16();
144
+ }
145
+ const lines = [];
146
+ for (let i = 0; i < count && !r.overrun; i++) {
147
+ const width = r.u16();
148
+ if (version < 4) {
149
+ lines.push(plainLine(width, readColor(r, version >= 3)));
150
+ continue;
151
+ }
152
+ const { hasFill, ...flags } = readLineFlags(r);
153
+ const fill = hasFill ? readFill(r, version) : null;
154
+ const color = fill ? fillColor(fill) : readColor(r, true);
155
+ lines.push({ width, color, ...flags, fill });
156
+ }
157
+ return lines;
158
+ }
159
+ /** The records from the reader's position: fill and line bit counts first, then records to the end record. */
160
+ export function readRecords(r, version) {
161
+ r.align();
162
+ let fillBits = r.ub(4);
163
+ let lineBits = r.ub(4);
164
+ const records = [];
165
+ for (;;) {
166
+ if (r.overrun) {
167
+ return { records, truncated: true };
168
+ }
169
+ if (r.ub(1)) {
170
+ // An edge.
171
+ const straight = r.ub(1);
172
+ const n = r.ub(4) + 2;
173
+ if (straight) {
174
+ const general = r.ub(1);
175
+ const vertical = general ? 0 : r.ub(1);
176
+ const dx = general || !vertical ? r.sb(n) : 0;
177
+ const dy = general || vertical ? r.sb(n) : 0;
178
+ records.push({ type: "line", dx, dy });
179
+ }
180
+ else {
181
+ records.push({ type: "curve", cx: r.sb(n), cy: r.sb(n), ax: r.sb(n), ay: r.sb(n) });
182
+ }
183
+ continue;
184
+ }
185
+ const flags = r.ub(5);
186
+ if (flags === 0) {
187
+ return { records, truncated: false };
188
+ }
189
+ let moveTo = null;
190
+ if (flags & 1) {
191
+ const n = r.ub(5);
192
+ moveTo = { x: r.sb(n), y: r.sb(n) };
193
+ }
194
+ const fill0 = flags & 2 ? r.ub(fillBits) : null;
195
+ const fill1 = flags & 4 ? r.ub(fillBits) : null;
196
+ const line = flags & 8 ? r.ub(lineBits) : null;
197
+ let styles = null;
198
+ if (flags & 16 && version >= 2) {
199
+ styles = { fills: readFills(r, version), lines: readLines(r, version) };
200
+ r.align();
201
+ fillBits = r.ub(4);
202
+ lineBits = r.ub(4);
203
+ }
204
+ records.push({ type: "style", moveTo, fill0, fill1, line, styles });
205
+ }
206
+ }
207
+ /**
208
+ * SWF 8 brought the unsmoothed bitmap fills (0x42, 0x43). In an older SWF
209
+ * Flash Player draws the others unsmoothed as well, still or moving, as
210
+ * Ruffle reads them; AIR's runtime smooths them (`avm1-bitmap-smoothing-swf7`).
211
+ */
212
+ const SMOOTHED_FILLS_VERSION = 8;
213
+ function unsmooth(fill) {
214
+ if (fill?.type === "bitmap") {
215
+ fill.smooth = false;
216
+ }
217
+ }
218
+ function unsmoothStyles(fills, lines) {
219
+ for (let i = 0; i < fills.length; i++) {
220
+ unsmooth(fills[i]);
221
+ }
222
+ for (let i = 0; i < lines.length; i++) {
223
+ unsmooth(lines[i].fill);
224
+ }
225
+ }
226
+ /**
227
+ * A DefineShape tag's body, of the version its code gives, from a SWF of
228
+ * `swfVersion`, which decides whether its bitmap fills may be smoothed.
229
+ */
230
+ export function readShape(bytes, code, offset, length, swfVersion = SMOOTHED_FILLS_VERSION) {
231
+ const version = code === DefineShape ? 1 : code === DefineShape2 ? 2 : code === DefineShape3 ? 3 : 4;
232
+ if (code !== DefineShape &&
233
+ code !== DefineShape2 &&
234
+ code !== DefineShape3 &&
235
+ code !== DefineShape4) {
236
+ throw new Error(`tag ${code} is not a shape`);
237
+ }
238
+ const r = new SwfReader(bytes, offset, offset + length);
239
+ const id = r.u16();
240
+ const bounds = r.rect();
241
+ let edgeBounds = null;
242
+ if (version === 4) {
243
+ edgeBounds = r.rect();
244
+ r.u8();
245
+ }
246
+ const fills = readFills(r, version);
247
+ const lines = readLines(r, version);
248
+ const { records, truncated } = readRecords(r, version);
249
+ if (swfVersion < SMOOTHED_FILLS_VERSION) {
250
+ unsmoothStyles(fills, lines);
251
+ for (let i = 0; i < records.length; i++) {
252
+ const record = records[i];
253
+ if (record.type === "style" && record.styles) {
254
+ unsmoothStyles(record.styles.fills, record.styles.lines);
255
+ }
256
+ }
257
+ }
258
+ return { id, bounds, edgeBounds, fills, lines, records, truncated };
259
+ }
260
+ /** MORPHGRADIENT: both matrices, then each stop's start and end. */
261
+ function readMorphGradient(r, focal) {
262
+ const startMatrix = readMatrix(r);
263
+ const endMatrix = readMatrix(r);
264
+ // The count's byte carries spread and interpolation as a shape's
265
+ // gradient's does, which Flash writes and reads alike.
266
+ const spread = r.ub(2);
267
+ const interpolation = r.ub(2);
268
+ const count = r.ub(4);
269
+ const startStops = [];
270
+ const endStops = [];
271
+ for (let i = 0; i < count; i++) {
272
+ startStops.push({ ratio: r.u8(), color: readColor(r, true) });
273
+ endStops.push({ ratio: r.u8(), color: readColor(r, true) });
274
+ }
275
+ const startFocal = focal ? r.s16() / 256 : 0;
276
+ const endFocal = focal ? r.s16() / 256 : 0;
277
+ return {
278
+ start: { matrix: startMatrix, spread, interpolation, stops: startStops, focal: startFocal },
279
+ end: { matrix: endMatrix, spread, interpolation, stops: endStops, focal: endFocal },
280
+ };
281
+ }
282
+ function readMorphFill(r) {
283
+ const type = r.u8();
284
+ if (type === 0x00) {
285
+ return {
286
+ start: { type: "solid", color: readColor(r, true) },
287
+ end: { type: "solid", color: readColor(r, true) },
288
+ };
289
+ }
290
+ if (type === 0x10 || type === 0x12 || type === 0x13) {
291
+ const kind = type === 0x10 ? "linear" : type === 0x12 ? "radial" : "focal";
292
+ const { start, end } = readMorphGradient(r, type === 0x13);
293
+ return { start: { type: kind, gradient: start }, end: { type: kind, gradient: end } };
294
+ }
295
+ const bitmap = r.u16();
296
+ const repeat = (type & 1) === 0;
297
+ const smooth = (type & 2) === 0;
298
+ return {
299
+ start: { type: "bitmap", bitmap, matrix: readMatrix(r), repeat, smooth },
300
+ end: { type: "bitmap", bitmap, matrix: readMatrix(r), repeat, smooth },
301
+ };
302
+ }
303
+ function readMorphFills(r) {
304
+ let count = r.u8();
305
+ if (count === 0xff) {
306
+ count = r.u16();
307
+ }
308
+ const fills = [];
309
+ for (let i = 0; i < count && !r.overrun; i++) {
310
+ fills.push(readMorphFill(r));
311
+ }
312
+ return fills;
313
+ }
314
+ /**
315
+ * MORPHLINESTYLE (version 1) or MORPHLINESTYLE2 (2): both widths, then colours, or flags and a
316
+ * fill.
317
+ */
318
+ function readMorphLines(r, version) {
319
+ let count = r.u8();
320
+ if (count === 0xff) {
321
+ count = r.u16();
322
+ }
323
+ const lines = [];
324
+ for (let i = 0; i < count && !r.overrun; i++) {
325
+ const startWidth = r.u16();
326
+ const endWidth = r.u16();
327
+ if (version < 2) {
328
+ const startColor = readColor(r, true);
329
+ lines.push({
330
+ start: plainLine(startWidth, startColor),
331
+ end: plainLine(endWidth, readColor(r, true)),
332
+ });
333
+ continue;
334
+ }
335
+ const { hasFill, ...flags } = readLineFlags(r);
336
+ if (hasFill) {
337
+ const fill = readMorphFill(r);
338
+ lines.push({
339
+ start: { width: startWidth, color: fillColor(fill.start), ...flags, fill: fill.start },
340
+ end: { width: endWidth, color: fillColor(fill.end), ...flags, fill: fill.end },
341
+ });
342
+ continue;
343
+ }
344
+ const startColor = readColor(r, true);
345
+ const endColor = readColor(r, true);
346
+ lines.push({
347
+ start: { width: startWidth, color: startColor, ...flags, fill: null },
348
+ end: { width: endWidth, color: endColor, ...flags, fill: null },
349
+ });
350
+ }
351
+ return lines;
352
+ }
353
+ /**
354
+ * A DefineMorphShape or DefineMorphShape2 tag's body, of the version its
355
+ * code gives, from a SWF of `swfVersion` (as `readShape`).
356
+ */
357
+ export function readMorphShape(bytes, code, offset, length, swfVersion = SMOOTHED_FILLS_VERSION) {
358
+ if (code !== DefineMorphShape && code !== DefineMorphShape2) {
359
+ throw new Error(`tag ${code} is not a morph shape`);
360
+ }
361
+ const version = code === DefineMorphShape ? 1 : 2;
362
+ const r = new SwfReader(bytes, offset, offset + length);
363
+ const id = r.u16();
364
+ const startBounds = r.rect();
365
+ const endBounds = r.rect();
366
+ let startEdgeBounds = null;
367
+ let endEdgeBounds = null;
368
+ if (version === 2) {
369
+ startEdgeBounds = r.rect();
370
+ endEdgeBounds = r.rect();
371
+ r.u8();
372
+ }
373
+ // The end's records are where the offset says, which may be past where
374
+ // the start's end when a tool pads them.
375
+ const endOffset = r.u32();
376
+ const endAt = r.pos + endOffset;
377
+ const fills = readMorphFills(r);
378
+ const lines = readMorphLines(r, version);
379
+ // The start's records stop at the end's, where the offset lies past the
380
+ // styles and in the tag: one missing its end record reads no further. A
381
+ // style change in either end's records brings no new styles: version 1
382
+ // reads none.
383
+ const offsetValid = endOffset !== 0 && endAt >= r.pos && endAt <= r.end;
384
+ const start = readRecords(offsetValid ? new SwfReader(r.bytes, r.pos, endAt) : r, 1);
385
+ if (offsetValid) {
386
+ r.pos = endAt;
387
+ }
388
+ const end = readRecords(r, 1);
389
+ if (swfVersion < SMOOTHED_FILLS_VERSION) {
390
+ for (let i = 0; i < fills.length; i++) {
391
+ unsmooth(fills[i].start);
392
+ unsmooth(fills[i].end);
393
+ }
394
+ for (let i = 0; i < lines.length; i++) {
395
+ unsmooth(lines[i].start.fill);
396
+ unsmooth(lines[i].end.fill);
397
+ }
398
+ }
399
+ return {
400
+ id,
401
+ startBounds,
402
+ endBounds,
403
+ startEdgeBounds,
404
+ endEdgeBounds,
405
+ fills,
406
+ lines,
407
+ start: start.records,
408
+ end: end.records,
409
+ truncated: start.truncated || end.truncated,
410
+ };
411
+ }
@@ -0,0 +1,91 @@
1
+ // DefineSound's header and encoded samples, and the tags that play sounds
2
+ // from a timeline: StartSound and StartSound2, the stream of
3
+ // SoundStreamHead and SoundStreamBlock, and DefineButtonSound. Decoding
4
+ // belongs to the player, where a host can supply an audio device.
5
+ import { readString } from "./display.js";
6
+ import { SwfReader } from "./swf.js";
7
+ import { StartSound2 } from "./tags.js";
8
+ const RATES = [5512.5, 11025, 22050, 44100];
9
+ export function readSound(bytes, tag) {
10
+ const r = new SwfReader(bytes, tag.offset, tag.offset + tag.length);
11
+ const id = r.u16();
12
+ const flags = r.u8();
13
+ const format = flags >> 4;
14
+ const sampleRate = RATES[(flags >> 2) & 3];
15
+ const sampleSize = (flags & 2) === 0 ? 8 : 16;
16
+ const channels = (flags & 1) === 0 ? 1 : 2;
17
+ const sampleCount = r.u32();
18
+ const seekSamples = format === 2 ? r.s16() : 0;
19
+ return {
20
+ id,
21
+ format,
22
+ sampleRate,
23
+ sampleSize,
24
+ channels,
25
+ sampleCount,
26
+ seekSamples,
27
+ data: bytes.subarray(r.pos, tag.offset + tag.length),
28
+ };
29
+ }
30
+ export function readSoundInfo(r) {
31
+ const flags = r.u8();
32
+ const inPoint = flags & 0x01 ? r.u32() : null;
33
+ const outPoint = flags & 0x02 ? r.u32() : null;
34
+ const loops = flags & 0x04 ? r.u16() : 1;
35
+ let envelope = null;
36
+ if (flags & 0x08) {
37
+ envelope = [];
38
+ for (let n = r.u8(); n > 0 && !r.overrun; n--) {
39
+ envelope.push({ sample: r.u32(), left: r.u16() / 32768, right: r.u16() / 32768 });
40
+ }
41
+ }
42
+ return {
43
+ stop: (flags & 0x20) !== 0,
44
+ noMultiple: (flags & 0x10) !== 0,
45
+ inPoint,
46
+ outPoint,
47
+ loops,
48
+ envelope,
49
+ };
50
+ }
51
+ export function readStartSound(bytes, tag) {
52
+ const r = new SwfReader(bytes, tag.offset, tag.offset + tag.length);
53
+ if (tag.code === StartSound2) {
54
+ const className = readString(r);
55
+ return { id: null, className, info: readSoundInfo(r) };
56
+ }
57
+ const id = r.u16();
58
+ return { id, className: null, info: readSoundInfo(r) };
59
+ }
60
+ export function readSoundStreamHead(bytes, tag) {
61
+ const r = new SwfReader(bytes, tag.offset, tag.offset + tag.length);
62
+ // The playback format is only a hint; the stream's own follows it.
63
+ r.u8();
64
+ const flags = r.u8();
65
+ return {
66
+ format: flags >> 4,
67
+ sampleRate: RATES[(flags >> 2) & 3],
68
+ sampleSize: (flags & 2) === 0 ? 8 : 16,
69
+ channels: (flags & 1) === 0 ? 1 : 2,
70
+ samplesPerBlock: r.u16(),
71
+ };
72
+ }
73
+ export function readSoundStreamBlock(bytes, tag, format) {
74
+ const end = tag.offset + tag.length;
75
+ if (format !== 2) {
76
+ return { sampleCount: null, data: bytes.subarray(tag.offset, end) };
77
+ }
78
+ const r = new SwfReader(bytes, tag.offset, end);
79
+ const sampleCount = r.u16();
80
+ return { sampleCount, data: bytes.subarray(Math.min(end, tag.offset + 4), end) };
81
+ }
82
+ export function readButtonSound(bytes, tag) {
83
+ const r = new SwfReader(bytes, tag.offset, tag.offset + tag.length);
84
+ const id = r.u16();
85
+ const sounds = [];
86
+ for (let i = 0; i < 4; i++) {
87
+ const sound = r.pos + 2 <= r.end ? r.u16() : 0;
88
+ sounds.push(sound === 0 ? null : { id: sound, info: readSoundInfo(r) });
89
+ }
90
+ return { id, sounds };
91
+ }
@@ -0,0 +1,163 @@
1
+ // A SWF's movie header and its tags, as the SWF file format specification
2
+ // (version 19) lays them out: after the 8-byte file header and the body's
3
+ // decompression, the frame size as a RECT, the frame rate as 8.8 fixed
4
+ // point, the frame count, then tags to an End tag or the body's end.
5
+ import { decompressSwf, decompressSwfPrefix } from "./compression.js";
6
+ import { End, FileAttributes, SetBackgroundColor } from "./tags.js";
7
+ const SIGNATURES = { FWS: "none", CWS: "zlib", ZWS: "lzma" };
8
+ /** Read the 8-byte header every SWF starts with. */
9
+ export function readSwfHeader(bytes) {
10
+ if (bytes.length < 8) {
11
+ throw new RangeError(`SWF header needs 8 bytes, got ${bytes.length}`);
12
+ }
13
+ const signature = String.fromCharCode(bytes[0], bytes[1], bytes[2]);
14
+ const compression = SIGNATURES[signature];
15
+ if (!compression) {
16
+ throw new TypeError(`Not a SWF file (signature ${JSON.stringify(signature)})`);
17
+ }
18
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
19
+ return { compression, version: bytes[3], fileLength: view.getUint32(4, true) };
20
+ }
21
+ /** Reads bits and bytes of a SWF body, bits most significant first, as the format packs them. */
22
+ export class SwfReader {
23
+ bytes;
24
+ pos;
25
+ end;
26
+ bit = 0;
27
+ byte = 0;
28
+ constructor(bytes, pos = 0, end = bytes.length) {
29
+ this.bytes = bytes;
30
+ this.pos = pos;
31
+ this.end = end;
32
+ }
33
+ /** Past the end: every read after it gives 0. */
34
+ get overrun() {
35
+ return this.pos > this.end;
36
+ }
37
+ align() {
38
+ this.bit = 0;
39
+ }
40
+ ub(n) {
41
+ let v = 0;
42
+ for (let i = 0; i < n; i++) {
43
+ if (this.bit === 0) {
44
+ this.byte = this.pos < this.end ? this.bytes[this.pos] : 0;
45
+ this.pos++;
46
+ this.bit = 8;
47
+ }
48
+ this.bit--;
49
+ v = v * 2 + ((this.byte >> this.bit) & 1);
50
+ }
51
+ return v;
52
+ }
53
+ sb(n) {
54
+ if (n > 0 && n <= 32 && n === (n | 0)) {
55
+ const shift = 32 - n;
56
+ return (this.ub(n) << shift) >> shift;
57
+ }
58
+ if (n === 0) {
59
+ return 0;
60
+ }
61
+ const v = this.ub(n);
62
+ return v >= 2 ** (n - 1) ? v - 2 ** n : v;
63
+ }
64
+ u8() {
65
+ this.align();
66
+ const v = this.pos < this.end ? this.bytes[this.pos] : 0;
67
+ this.pos++;
68
+ return v;
69
+ }
70
+ u16() {
71
+ return this.u8() | (this.u8() << 8);
72
+ }
73
+ u32() {
74
+ return (this.u16() | (this.u16() << 16)) >>> 0;
75
+ }
76
+ s16() {
77
+ return (this.u16() << 16) >> 16;
78
+ }
79
+ rect() {
80
+ this.align();
81
+ const n = this.ub(5);
82
+ const rect = { xMin: this.sb(n), xMax: this.sb(n), yMin: this.sb(n), yMax: this.sb(n) };
83
+ this.align();
84
+ return rect;
85
+ }
86
+ }
87
+ /** A SWF's header and tags, its body decompressed. */
88
+ export function readSwf(file) {
89
+ const header = readSwfHeader(file);
90
+ const bytes = decompressSwf(file);
91
+ const r = new SwfReader(bytes, 8);
92
+ const frameSize = r.rect();
93
+ const frameRate = r.u16() / 256;
94
+ const frameCount = r.u16();
95
+ const { tags, truncated } = readTags(bytes, r.pos, bytes.length);
96
+ return { header, bytes, frameSize, frameRate, frameCount, tags, truncated };
97
+ }
98
+ /** The tags from `start` to an End tag or `end`, as a sprite's or the file's. */
99
+ export function readTags(bytes, start, end) {
100
+ const tags = [];
101
+ const r = new SwfReader(bytes, start, end);
102
+ while (r.pos + 2 <= end) {
103
+ const codeAndLength = r.u16();
104
+ const code = codeAndLength >> 6;
105
+ let length = codeAndLength & 0x3f;
106
+ const long = length === 0x3f;
107
+ if (long) {
108
+ length = r.u32();
109
+ }
110
+ if (r.pos + length > end) {
111
+ tags.push({ code, offset: r.pos, length: Math.max(0, end - r.pos), long });
112
+ return { tags, truncated: true };
113
+ }
114
+ tags.push({ code, offset: r.pos, length, long });
115
+ r.pos += length;
116
+ if (code === End) {
117
+ break;
118
+ }
119
+ }
120
+ return { tags, truncated: false };
121
+ }
122
+ /** The background colour SetBackgroundColor sets, 0xRRGGBB, or white without one. */
123
+ export function backgroundColor(swf) {
124
+ const tag = swf.tags.find((t) => t.code === SetBackgroundColor);
125
+ if (!tag || tag.length < 3) {
126
+ return 0xffffff;
127
+ }
128
+ const b = swf.bytes;
129
+ return (b[tag.offset] << 16) | (b[tag.offset + 1] << 8) | b[tag.offset + 2];
130
+ }
131
+ /**
132
+ * The flags of a SWF file's FileAttributes, from the start of the file
133
+ * alone, as Flash Player reads them, FileAttributes being the first tag:
134
+ * 0 for a SWF whose first tag is another. For a host that must not
135
+ * decompress the whole of a SWF it does not trust, as a desktop shell
136
+ * choosing a local SWF's sandbox; ActionScript3 is 0x08, UseNetwork 0x01.
137
+ */
138
+ export function fileAttributes(file) {
139
+ // The header's rect is 17 bytes at most, then the rate, count, and a long tag header.
140
+ const bytes = decompressSwfPrefix(file, 64);
141
+ try {
142
+ const r = new SwfReader(bytes, 8);
143
+ r.rect();
144
+ r.u16();
145
+ r.u16();
146
+ const head = r.u16();
147
+ if (head >> 6 !== FileAttributes) {
148
+ return 0;
149
+ }
150
+ if ((head & 0x3f) === 0x3f) {
151
+ r.u32();
152
+ }
153
+ return r.u8();
154
+ }
155
+ catch {
156
+ return 0;
157
+ }
158
+ }
159
+ /** Whether FileAttributes marks the SWF as ActionScript 3; without the bit it is an AVM1 movie. */
160
+ export function isAs3(swf) {
161
+ const tag = swf.tags.find((t) => t.code === FileAttributes);
162
+ return !!tag && tag.length >= 1 && (swf.bytes[tag.offset] & 0x08) !== 0;
163
+ }