@swf2es/player-hosts 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (405) hide show
  1. package/LICENSE +202 -0
  2. package/LICENSE.third-party +759 -0
  3. package/README.md +43 -2
  4. package/dist/indexeddb.d.ts +27 -0
  5. package/dist/indexeddb.d.ts.map +1 -0
  6. package/dist/indexeddb.js +170 -0
  7. package/dist/indexeddb.js.map +1 -0
  8. package/dist/node-worker.d.ts +2 -0
  9. package/dist/node-worker.d.ts.map +1 -0
  10. package/dist/node-worker.js +12 -0
  11. package/dist/node-worker.js.map +1 -0
  12. package/dist/node.d.ts +8 -0
  13. package/dist/node.d.ts.map +1 -0
  14. package/dist/node.js +43 -0
  15. package/dist/node.js.map +1 -0
  16. package/dist/precompiled.d.ts +31 -0
  17. package/dist/precompiled.d.ts.map +1 -0
  18. package/dist/precompiled.js +125 -0
  19. package/dist/precompiled.js.map +1 -0
  20. package/dist/stage3d.d.ts +13 -0
  21. package/dist/stage3d.d.ts.map +1 -0
  22. package/dist/stage3d.js +61 -0
  23. package/dist/stage3d.js.map +1 -0
  24. package/dist/thread/codegen/codegen.js +308 -0
  25. package/dist/thread/codegen/index.js +405 -0
  26. package/dist/thread/format/abc-names.js +126 -0
  27. package/dist/thread/format/actions.js +222 -0
  28. package/dist/thread/format/air-descriptor.js +63 -0
  29. package/dist/thread/format/api-versions.js +22 -0
  30. package/dist/thread/format/bitmap.js +199 -0
  31. package/dist/thread/format/button.js +60 -0
  32. package/dist/thread/format/compression.js +200 -0
  33. package/dist/thread/format/display.js +305 -0
  34. package/dist/thread/format/filters.js +136 -0
  35. package/dist/thread/format/font.js +168 -0
  36. package/dist/thread/format/index.js +26 -0
  37. package/dist/thread/format/pbj.js +484 -0
  38. package/dist/thread/format/shape.js +411 -0
  39. package/dist/thread/format/sound.js +91 -0
  40. package/dist/thread/format/swf.js +163 -0
  41. package/dist/thread/format/tags.js +58 -0
  42. package/dist/thread/format/text.js +135 -0
  43. package/dist/thread/format/zip.js +91 -0
  44. package/dist/thread/native/audio/binary.js +3 -0
  45. package/dist/thread/native/audio/index.js +72 -0
  46. package/dist/thread/native/base64.js +9 -0
  47. package/dist/thread/native/compress/binary.js +3 -0
  48. package/dist/thread/native/compress/index.js +145 -0
  49. package/dist/thread/native/instance.js +49 -0
  50. package/dist/thread/native/mp3/binary.js +3 -0
  51. package/dist/thread/native/mp3/index.js +48 -0
  52. package/dist/thread/native/render/binary.js +3 -0
  53. package/dist/thread/native/render/bitmap-kernel.js +591 -0
  54. package/dist/thread/native/render/draw-kernel.js +204 -0
  55. package/dist/thread/native/render/dxt-encoder.js +94 -0
  56. package/dist/thread/native/render/index.js +10 -0
  57. package/dist/thread/native/render/lines.js +122 -0
  58. package/dist/thread/native/render/module.js +26 -0
  59. package/dist/thread/native/render/pixel-ops.js +235 -0
  60. package/dist/thread/native/render/tessellator.js +250 -0
  61. package/dist/thread/player/avm1/amf.js +507 -0
  62. package/dist/thread/player/avm1/avm1.js +1304 -0
  63. package/dist/thread/player/avm1/bindings.js +214 -0
  64. package/dist/thread/player/avm1/classes.js +75 -0
  65. package/dist/thread/player/avm1/clips.js +229 -0
  66. package/dist/thread/player/avm1/compile.js +140 -0
  67. package/dist/thread/player/avm1/external.js +79 -0
  68. package/dist/thread/player/avm1/focus.js +278 -0
  69. package/dist/thread/player/avm1/globals/BitmapData.js +542 -0
  70. package/dist/thread/player/avm1/globals/Button.js +31 -0
  71. package/dist/thread/player/avm1/globals/Color.js +115 -0
  72. package/dist/thread/player/avm1/globals/ExternalInterface.js +310 -0
  73. package/dist/thread/player/avm1/globals/FileReference.js +217 -0
  74. package/dist/thread/player/avm1/globals/Key.js +60 -0
  75. package/dist/thread/player/avm1/globals/LoadVars.js +208 -0
  76. package/dist/thread/player/avm1/globals/LocalConnection.js +92 -0
  77. package/dist/thread/player/avm1/globals/MovieClip.js +1070 -0
  78. package/dist/thread/player/avm1/globals/MovieClipLoader.js +90 -0
  79. package/dist/thread/player/avm1/globals/NetConnection.js +261 -0
  80. package/dist/thread/player/avm1/globals/PrintJob.js +37 -0
  81. package/dist/thread/player/avm1/globals/Selection.js +62 -0
  82. package/dist/thread/player/avm1/globals/SharedObject.js +245 -0
  83. package/dist/thread/player/avm1/globals/Sound.js +238 -0
  84. package/dist/thread/player/avm1/globals/Stage.js +12 -0
  85. package/dist/thread/player/avm1/globals/StyleSheet.js +205 -0
  86. package/dist/thread/player/avm1/globals/TextField.js +396 -0
  87. package/dist/thread/player/avm1/globals/TextFormat.js +194 -0
  88. package/dist/thread/player/avm1/globals/TextSnapshot.js +88 -0
  89. package/dist/thread/player/avm1/globals/XML.js +396 -0
  90. package/dist/thread/player/avm1/globals/XMLNode.js +413 -0
  91. package/dist/thread/player/avm1/globals/XMLSocket.js +205 -0
  92. package/dist/thread/player/avm1/globals/drawing.js +202 -0
  93. package/dist/thread/player/avm1/globals/filters.js +635 -0
  94. package/dist/thread/player/avm1/globals/geom.js +600 -0
  95. package/dist/thread/player/avm1/input.js +483 -0
  96. package/dist/thread/player/avm1/keyboard.js +113 -0
  97. package/dist/thread/player/avm1/loads.js +352 -0
  98. package/dist/thread/player/avm1/net.js +219 -0
  99. package/dist/thread/player/avm1/paths.js +104 -0
  100. package/dist/thread/player/avm1/pointer.js +512 -0
  101. package/dist/thread/player/avm1/queue.js +303 -0
  102. package/dist/thread/player/avm1/sound.js +106 -0
  103. package/dist/thread/player/avm1/swf.js +141 -0
  104. package/dist/thread/player/avm1/timers.js +113 -0
  105. package/dist/thread/player/bitmap/bitmap.js +627 -0
  106. package/dist/thread/player/bitmap/draw.js +68 -0
  107. package/dist/thread/player/bitmap/dxt.js +11 -0
  108. package/dist/thread/player/bitmap/filters.js +656 -0
  109. package/dist/thread/player/bitmap/images.js +240 -0
  110. package/dist/thread/player/bitmap/kernel.js +65 -0
  111. package/dist/thread/player/bitmap/ops.js +1239 -0
  112. package/dist/thread/player/bitmap/pixel-bender.js +911 -0
  113. package/dist/thread/player/bitmap/png.js +139 -0
  114. package/dist/thread/player/bitmap/turbulence.js +89 -0
  115. package/dist/thread/player/clock.js +182 -0
  116. package/dist/thread/player/display/bitmapobject.js +25 -0
  117. package/dist/thread/player/display/bounds.js +520 -0
  118. package/dist/thread/player/display/buttonobject.js +305 -0
  119. package/dist/thread/player/display/color.js +40 -0
  120. package/dist/thread/player/display/container.js +150 -0
  121. package/dist/thread/player/display/display.js +14 -0
  122. package/dist/thread/player/display/displayobject.js +664 -0
  123. package/dist/thread/player/display/drawing.js +613 -0
  124. package/dist/thread/player/display/filters.js +285 -0
  125. package/dist/thread/player/display/geometry.js +189 -0
  126. package/dist/thread/player/display/gradients.js +117 -0
  127. package/dist/thread/player/display/graphicsdata.js +592 -0
  128. package/dist/thread/player/display/instantiate.js +71 -0
  129. package/dist/thread/player/display/matrix3d.js +373 -0
  130. package/dist/thread/player/display/morph.js +226 -0
  131. package/dist/thread/player/display/movieclip.js +680 -0
  132. package/dist/thread/player/display/perspective.js +193 -0
  133. package/dist/thread/player/display/scale9.js +236 -0
  134. package/dist/thread/player/display/shapeobject.js +131 -0
  135. package/dist/thread/player/display/shapes.js +407 -0
  136. package/dist/thread/player/display/textobjects.js +222 -0
  137. package/dist/thread/player/display/timeline.js +471 -0
  138. package/dist/thread/player/display/value-lists.js +40 -0
  139. package/dist/thread/player/display/videoobject.js +6 -0
  140. package/dist/thread/player/display/walk.js +127 -0
  141. package/dist/thread/player/files.js +334 -0
  142. package/dist/thread/player/hosts.js +207 -0
  143. package/dist/thread/player/input/avm1.js +82 -0
  144. package/dist/thread/player/input/context-menu.js +63 -0
  145. package/dist/thread/player/input/keyboard.js +458 -0
  146. package/dist/thread/player/input/pointer.js +863 -0
  147. package/dist/thread/player/input/text-editor.js +319 -0
  148. package/dist/thread/player/input/touch.js +209 -0
  149. package/dist/thread/player/localconnection.js +90 -0
  150. package/dist/thread/player/media/audio.js +376 -0
  151. package/dist/thread/player/media/dynamic-sound.js +90 -0
  152. package/dist/thread/player/media/extract.js +135 -0
  153. package/dist/thread/player/media/mp3.js +152 -0
  154. package/dist/thread/player/media/sounds.js +507 -0
  155. package/dist/thread/player/media/streaming-audio.js +133 -0
  156. package/dist/thread/player/player.js +616 -0
  157. package/dist/thread/player/playerglobal/air/net/WebSocket.js +250 -0
  158. package/dist/thread/player/playerglobal/air-library.js +8 -0
  159. package/dist/thread/player/playerglobal/flash/accessibility/Accessibility.js +21 -0
  160. package/dist/thread/player/playerglobal/flash/crypto/generateRandomBytes.js +32 -0
  161. package/dist/thread/player/playerglobal/flash/data/EncryptedLocalStore.js +61 -0
  162. package/dist/thread/player/playerglobal/flash/desktop/Clipboard.js +173 -0
  163. package/dist/thread/player/playerglobal/flash/desktop/NativeApplication.js +179 -0
  164. package/dist/thread/player/playerglobal/flash/display/AVM1Movie.js +19 -0
  165. package/dist/thread/player/playerglobal/flash/display/Bitmap.js +58 -0
  166. package/dist/thread/player/playerglobal/flash/display/BitmapData.js +633 -0
  167. package/dist/thread/player/playerglobal/flash/display/DisplayObject.js +614 -0
  168. package/dist/thread/player/playerglobal/flash/display/DisplayObjectContainer.js +224 -0
  169. package/dist/thread/player/playerglobal/flash/display/Graphics.js +345 -0
  170. package/dist/thread/player/playerglobal/flash/display/InteractiveObject.js +87 -0
  171. package/dist/thread/player/playerglobal/flash/display/Loader.js +79 -0
  172. package/dist/thread/player/playerglobal/flash/display/LoaderInfo.js +128 -0
  173. package/dist/thread/player/playerglobal/flash/display/MovieClip.js +194 -0
  174. package/dist/thread/player/playerglobal/flash/display/NativeWindow.js +245 -0
  175. package/dist/thread/player/playerglobal/flash/display/Shader.js +26 -0
  176. package/dist/thread/player/playerglobal/flash/display/ShaderData.js +85 -0
  177. package/dist/thread/player/playerglobal/flash/display/ShaderInput.js +64 -0
  178. package/dist/thread/player/playerglobal/flash/display/ShaderJob.js +181 -0
  179. package/dist/thread/player/playerglobal/flash/display/ShaderParameter.js +23 -0
  180. package/dist/thread/player/playerglobal/flash/display/Shape.js +13 -0
  181. package/dist/thread/player/playerglobal/flash/display/SimpleButton.js +103 -0
  182. package/dist/thread/player/playerglobal/flash/display/Sprite.js +84 -0
  183. package/dist/thread/player/playerglobal/flash/display/Stage.js +231 -0
  184. package/dist/thread/player/playerglobal/flash/display/Stage3D.js +54 -0
  185. package/dist/thread/player/playerglobal/flash/display/shaders.js +228 -0
  186. package/dist/thread/player/playerglobal/flash/events/Event.js +58 -0
  187. package/dist/thread/player/playerglobal/flash/events/EventDispatcher.js +103 -0
  188. package/dist/thread/player/playerglobal/flash/events/GestureEvent.js +34 -0
  189. package/dist/thread/player/playerglobal/flash/events/HTTPStatusEvent.js +8 -0
  190. package/dist/thread/player/playerglobal/flash/events/KeyboardEvent.js +51 -0
  191. package/dist/thread/player/playerglobal/flash/events/MouseEvent.js +59 -0
  192. package/dist/thread/player/playerglobal/flash/events/PressAndTapGestureEvent.js +30 -0
  193. package/dist/thread/player/playerglobal/flash/events/TimerEvent.js +16 -0
  194. package/dist/thread/player/playerglobal/flash/events/TouchEvent.js +45 -0
  195. package/dist/thread/player/playerglobal/flash/external/ExternalInterface.js +73 -0
  196. package/dist/thread/player/playerglobal/flash/filesystem/File.js +340 -0
  197. package/dist/thread/player/playerglobal/flash/filesystem/FileStream.js +453 -0
  198. package/dist/thread/player/playerglobal/flash/filesystem/paths.js +156 -0
  199. package/dist/thread/player/playerglobal/flash/filesystem/writes.js +143 -0
  200. package/dist/thread/player/playerglobal/flash/filters/BevelFilter.js +4 -0
  201. package/dist/thread/player/playerglobal/flash/filters/BitmapFilter.js +205 -0
  202. package/dist/thread/player/playerglobal/flash/filters/BlurFilter.js +4 -0
  203. package/dist/thread/player/playerglobal/flash/filters/ColorMatrixFilter.js +11 -0
  204. package/dist/thread/player/playerglobal/flash/filters/ConvolutionFilter.js +26 -0
  205. package/dist/thread/player/playerglobal/flash/filters/DisplacementMapFilter.js +51 -0
  206. package/dist/thread/player/playerglobal/flash/filters/DropShadowFilter.js +4 -0
  207. package/dist/thread/player/playerglobal/flash/filters/GlowFilter.js +4 -0
  208. package/dist/thread/player/playerglobal/flash/filters/GradientBevelFilter.js +4 -0
  209. package/dist/thread/player/playerglobal/flash/filters/GradientGlowFilter.js +4 -0
  210. package/dist/thread/player/playerglobal/flash/filters/ShaderFilter.js +53 -0
  211. package/dist/thread/player/playerglobal/flash/geom/Matrix3D.js +361 -0
  212. package/dist/thread/player/playerglobal/flash/geom/PerspectiveProjection.js +122 -0
  213. package/dist/thread/player/playerglobal/flash/geom/Transform.js +245 -0
  214. package/dist/thread/player/playerglobal/flash/geom/Utils3D.js +85 -0
  215. package/dist/thread/player/playerglobal/flash/globalization/Collator.js +149 -0
  216. package/dist/thread/player/playerglobal/flash/globalization/CurrencyFormatter.js +272 -0
  217. package/dist/thread/player/playerglobal/flash/globalization/CurrencyParseResult.js +21 -0
  218. package/dist/thread/player/playerglobal/flash/globalization/DateTimeFormatter.js +463 -0
  219. package/dist/thread/player/playerglobal/flash/globalization/LocaleID.js +144 -0
  220. package/dist/thread/player/playerglobal/flash/globalization/NumberFormatter.js +444 -0
  221. package/dist/thread/player/playerglobal/flash/globalization/NumberParseResult.js +22 -0
  222. package/dist/thread/player/playerglobal/flash/globalization/StringTools.js +59 -0
  223. package/dist/thread/player/playerglobal/flash/globalization/locale.js +190 -0
  224. package/dist/thread/player/playerglobal/flash/media/Camera.js +89 -0
  225. package/dist/thread/player/playerglobal/flash/media/Microphone.js +126 -0
  226. package/dist/thread/player/playerglobal/flash/media/Sound.js +543 -0
  227. package/dist/thread/player/playerglobal/flash/media/SoundMixer.js +74 -0
  228. package/dist/thread/player/playerglobal/flash/media/SoundTransform.js +40 -0
  229. package/dist/thread/player/playerglobal/flash/media/Video.js +43 -0
  230. package/dist/thread/player/playerglobal/flash/net/FileFilter.js +27 -0
  231. package/dist/thread/player/playerglobal/flash/net/FileReference.js +197 -0
  232. package/dist/thread/player/playerglobal/flash/net/LocalConnection.js +167 -0
  233. package/dist/thread/player/playerglobal/flash/net/NetConnection.js +155 -0
  234. package/dist/thread/player/playerglobal/flash/net/SharedObject.js +299 -0
  235. package/dist/thread/player/playerglobal/flash/net/Socket.js +282 -0
  236. package/dist/thread/player/playerglobal/flash/net/URLRequest.js +93 -0
  237. package/dist/thread/player/playerglobal/flash/net/URLStream.js +146 -0
  238. package/dist/thread/player/playerglobal/flash/net/XMLSocket.js +14 -0
  239. package/dist/thread/player/playerglobal/flash/net/local-modern.js +142 -0
  240. package/dist/thread/player/playerglobal/flash/net/local-values.js +217 -0
  241. package/dist/thread/player/playerglobal/flash/net/navigateToURL.js +29 -0
  242. package/dist/thread/player/playerglobal/flash/profiler/Telemetry.js +25 -0
  243. package/dist/thread/player/playerglobal/flash/sensors/Accelerometer.js +12 -0
  244. package/dist/thread/player/playerglobal/flash/system/ApplicationDomain.js +69 -0
  245. package/dist/thread/player/playerglobal/flash/system/Capabilities.js +163 -0
  246. package/dist/thread/player/playerglobal/flash/system/FSCommandHost.js +17 -0
  247. package/dist/thread/player/playerglobal/flash/system/Security.js +46 -0
  248. package/dist/thread/player/playerglobal/flash/system/SecurityDomain.js +21 -0
  249. package/dist/thread/player/playerglobal/flash/system/System.js +73 -0
  250. package/dist/thread/player/playerglobal/flash/system/Worker.js +112 -0
  251. package/dist/thread/player/playerglobal/flash/text/Font.js +95 -0
  252. package/dist/thread/player/playerglobal/flash/text/StaticText.js +16 -0
  253. package/dist/thread/player/playerglobal/flash/text/StyleSheet.js +65 -0
  254. package/dist/thread/player/playerglobal/flash/text/TextField.js +707 -0
  255. package/dist/thread/player/playerglobal/flash/text/TextRenderer.js +77 -0
  256. package/dist/thread/player/playerglobal/flash/text/engine/FontDescription.js +141 -0
  257. package/dist/thread/player/playerglobal/flash/text/engine/TabStop.js +46 -0
  258. package/dist/thread/player/playerglobal/flash/trace/Trace.js +17 -0
  259. package/dist/thread/player/playerglobal/flash/ui/ContextMenu.js +17 -0
  260. package/dist/thread/player/playerglobal/flash/ui/GameInput.js +19 -0
  261. package/dist/thread/player/playerglobal/flash/ui/Keyboard.js +27 -0
  262. package/dist/thread/player/playerglobal/flash/ui/Mouse.js +127 -0
  263. package/dist/thread/player/playerglobal/flash/ui/Multitouch.js +46 -0
  264. package/dist/thread/player/playerglobal/flash/utils/ByteArray.js +155 -0
  265. package/dist/thread/player/playerglobal/flash/utils/Timer.js +25 -0
  266. package/dist/thread/player/playerglobal/flash/xml/XMLDocument.js +74 -0
  267. package/dist/thread/player/playerglobal/index.js +224 -0
  268. package/dist/thread/player/playerglobal/libraries.js +10 -0
  269. package/dist/thread/player/playerglobal/playerglobal-library.js +22 -0
  270. package/dist/thread/player/playerglobal/toplevel.js +122 -0
  271. package/dist/thread/player/scripting/clipboard.js +146 -0
  272. package/dist/thread/player/scripting/code.js +900 -0
  273. package/dist/thread/player/scripting/evaluate.js +144 -0
  274. package/dist/thread/player/scripting/events.js +172 -0
  275. package/dist/thread/player/scripting/handover.js +182 -0
  276. package/dist/thread/player/scripting/lazy.js +38 -0
  277. package/dist/thread/player/scripting/lifecycle.js +272 -0
  278. package/dist/thread/player/scripting/loads.js +860 -0
  279. package/dist/thread/player/scripting/sha256.js +95 -0
  280. package/dist/thread/player/scripting/symbols.js +348 -0
  281. package/dist/thread/player/scripting/timers.js +434 -0
  282. package/dist/thread/player/scripting/workers.js +923 -0
  283. package/dist/thread/player/scripting.js +1018 -0
  284. package/dist/thread/player/stage.js +4 -0
  285. package/dist/thread/player/text/csm.js +113 -0
  286. package/dist/thread/player/text/css.js +167 -0
  287. package/dist/thread/player/text/fonts.js +97 -0
  288. package/dist/thread/player/text/layout.js +393 -0
  289. package/dist/thread/player/text/static.js +109 -0
  290. package/dist/thread/player/text/text.js +431 -0
  291. package/dist/thread/player/workers/thread.js +159 -0
  292. package/dist/thread/player/workers/wire.js +198 -0
  293. package/dist/thread/player-hosts/web-worker.js +19 -0
  294. package/dist/thread/runtime/avm1/activation.js +89 -0
  295. package/dist/thread/runtime/avm1/case.js +249 -0
  296. package/dist/thread/runtime/avm1/clips.js +334 -0
  297. package/dist/thread/runtime/avm1/control.js +280 -0
  298. package/dist/thread/runtime/avm1/errors.js +50 -0
  299. package/dist/thread/runtime/avm1/functions.js +249 -0
  300. package/dist/thread/runtime/avm1/globals/array.js +549 -0
  301. package/dist/thread/runtime/avm1/globals/broadcaster.js +131 -0
  302. package/dist/thread/runtime/avm1/globals/date.js +436 -0
  303. package/dist/thread/runtime/avm1/globals/global.js +344 -0
  304. package/dist/thread/runtime/avm1/globals/math.js +139 -0
  305. package/dist/thread/runtime/avm1/globals/number.js +93 -0
  306. package/dist/thread/runtime/avm1/globals/string.js +201 -0
  307. package/dist/thread/runtime/avm1/globals/timers.js +129 -0
  308. package/dist/thread/runtime/avm1/host.js +5 -0
  309. package/dist/thread/runtime/avm1/index.js +14 -0
  310. package/dist/thread/runtime/avm1/inheritance.js +132 -0
  311. package/dist/thread/runtime/avm1/numbers.js +298 -0
  312. package/dist/thread/runtime/avm1/objects.js +896 -0
  313. package/dist/thread/runtime/avm1/operators.js +170 -0
  314. package/dist/thread/runtime/avm1/realm.js +529 -0
  315. package/dist/thread/runtime/avm1/runtime.js +882 -0
  316. package/dist/thread/runtime/avm1/scope.js +385 -0
  317. package/dist/thread/runtime/avm1/urls.js +180 -0
  318. package/dist/thread/runtime/avm1/values.js +97 -0
  319. package/dist/thread/runtime/avm2/amf-classes.js +66 -0
  320. package/dist/thread/runtime/avm2/amf.js +801 -0
  321. package/dist/thread/runtime/avm2/array-conversion.js +100 -0
  322. package/dist/thread/runtime/avm2/builtin-library.js +21 -0
  323. package/dist/thread/runtime/avm2/cache-fill.js +86 -0
  324. package/dist/thread/runtime/avm2/classes.js +211 -0
  325. package/dist/thread/runtime/avm2/definitions.js +69 -0
  326. package/dist/thread/runtime/avm2/descriptors.js +5 -0
  327. package/dist/thread/runtime/avm2/dictionary-keys.js +295 -0
  328. package/dist/thread/runtime/avm2/domain-memory.js +75 -0
  329. package/dist/thread/runtime/avm2/domain.js +280 -0
  330. package/dist/thread/runtime/avm2/dynamic-properties.js +182 -0
  331. package/dist/thread/runtime/avm2/enumeration.js +393 -0
  332. package/dist/thread/runtime/avm2/errors.js +45 -0
  333. package/dist/thread/runtime/avm2/float-library.js +66 -0
  334. package/dist/thread/runtime/avm2/float.js +26 -0
  335. package/dist/thread/runtime/avm2/hooks.js +19 -0
  336. package/dist/thread/runtime/avm2/index.js +38 -0
  337. package/dist/thread/runtime/avm2/messages.js +177 -0
  338. package/dist/thread/runtime/avm2/method-factories.js +95 -0
  339. package/dist/thread/runtime/avm2/modules.js +105 -0
  340. package/dist/thread/runtime/avm2/names.js +248 -0
  341. package/dist/thread/runtime/avm2/natives/aliases.js +47 -0
  342. package/dist/thread/runtime/avm2/natives/array.js +390 -0
  343. package/dist/thread/runtime/avm2/natives/bytearray.js +1227 -0
  344. package/dist/thread/runtime/avm2/natives/case.js +88 -0
  345. package/dist/thread/runtime/avm2/natives/concurrent.js +199 -0
  346. package/dist/thread/runtime/avm2/natives/date.js +581 -0
  347. package/dist/thread/runtime/avm2/natives/define.js +130 -0
  348. package/dist/thread/runtime/avm2/natives/describe.js +351 -0
  349. package/dist/thread/runtime/avm2/natives/dictionary.js +12 -0
  350. package/dist/thread/runtime/avm2/natives/float-vector.js +81 -0
  351. package/dist/thread/runtime/avm2/natives/float.js +96 -0
  352. package/dist/thread/runtime/avm2/natives/index.js +64 -0
  353. package/dist/thread/runtime/avm2/natives/json.js +514 -0
  354. package/dist/thread/runtime/avm2/natives/number.js +162 -0
  355. package/dist/thread/runtime/avm2/natives/object.js +237 -0
  356. package/dist/thread/runtime/avm2/natives/proxy.js +75 -0
  357. package/dist/thread/runtime/avm2/natives/regexp.js +485 -0
  358. package/dist/thread/runtime/avm2/natives/shell-workers.js +404 -0
  359. package/dist/thread/runtime/avm2/natives/shell.js +557 -0
  360. package/dist/thread/runtime/avm2/natives/sort.js +377 -0
  361. package/dist/thread/runtime/avm2/natives/string.js +132 -0
  362. package/dist/thread/runtime/avm2/natives/sync.js +821 -0
  363. package/dist/thread/runtime/avm2/natives/toplevel.js +139 -0
  364. package/dist/thread/runtime/avm2/natives/vector-elements.js +46 -0
  365. package/dist/thread/runtime/avm2/natives/vector.js +406 -0
  366. package/dist/thread/runtime/avm2/natives/xml/access.js +633 -0
  367. package/dist/thread/runtime/avm2/natives/xml/build.js +291 -0
  368. package/dist/thread/runtime/avm2/natives/xml/chars.js +112 -0
  369. package/dist/thread/runtime/avm2/natives/xml/escape.js +38 -0
  370. package/dist/thread/runtime/avm2/natives/xml/names.js +204 -0
  371. package/dist/thread/runtime/avm2/natives/xml/node.js +272 -0
  372. package/dist/thread/runtime/avm2/natives/xml/operators.js +69 -0
  373. package/dist/thread/runtime/avm2/natives/xml/parser.js +356 -0
  374. package/dist/thread/runtime/avm2/natives/xml/strings.js +191 -0
  375. package/dist/thread/runtime/avm2/natives/xml/values.js +122 -0
  376. package/dist/thread/runtime/avm2/natives/xml/xml.js +645 -0
  377. package/dist/thread/runtime/avm2/number-strings.js +110 -0
  378. package/dist/thread/runtime/avm2/numbers.js +558 -0
  379. package/dist/thread/runtime/avm2/options.js +16 -0
  380. package/dist/thread/runtime/avm2/player-messages.js +550 -0
  381. package/dist/thread/runtime/avm2/property-cache.js +135 -0
  382. package/dist/thread/runtime/avm2/runtime.js +2644 -0
  383. package/dist/thread/runtime/avm2/traits.js +509 -0
  384. package/dist/thread/runtime/index.js +7 -0
  385. package/dist/web-worker.d.ts +2 -0
  386. package/dist/web-worker.d.ts.map +1 -0
  387. package/dist/web-worker.js +20 -0
  388. package/dist/web-worker.js.map +1 -0
  389. package/dist/websocket.d.ts +4 -0
  390. package/dist/websocket.d.ts.map +1 -0
  391. package/dist/websocket.js +27 -0
  392. package/dist/websocket.js.map +1 -0
  393. package/dist/workers.d.ts +35 -0
  394. package/dist/workers.d.ts.map +1 -0
  395. package/dist/workers.js +171 -0
  396. package/dist/workers.js.map +1 -0
  397. package/package.json +62 -3
  398. package/src/indexeddb.ts +227 -0
  399. package/src/node-worker.ts +13 -0
  400. package/src/node.ts +49 -0
  401. package/src/precompiled.ts +166 -0
  402. package/src/stage3d.ts +76 -0
  403. package/src/web-worker.ts +24 -0
  404. package/src/websocket.ts +32 -0
  405. package/src/workers.ts +255 -0
@@ -0,0 +1,600 @@
1
+ // flash.geom's AS2 classes, as Ruffle's (https://github.com/ruffle-rs/ruffle)
2
+ // core/src/avm1/globals/point.rs, rectangle.rs, matrix.rs,
3
+ // color_transform.rs and transform.rs have them: MIT OR Apache-2.0,
4
+ // Copyright (c) 2018-2022 Ruffle LLC and Ruffle contributors. Point,
5
+ // Rectangle and Matrix are plain objects, as Flash writes them in
6
+ // ActionScript: their methods read and write their properties by name, so
7
+ // any object with them will do, and their values are kept as given.
8
+ // ColorTransform and Transform hold native state. What a method makes, a
9
+ // Point, a Rectangle, a Matrix, is made by the class `_global.flash.geom`
10
+ // has then, a script's own among them, in doubles where Ruffle works in
11
+ // floats and twips.
12
+ import { avm1 } from "../../../runtime/index.js";
13
+ import { bounds, toStage } from "../../display/bounds.js";
14
+ import { TRANSFORM } from "../../display/display.js";
15
+ const num = (v, version) => avm1.toNumber(v, version);
16
+ const read = (o, name, version) => o instanceof avm1.Avm1Object ? avm1.get(o, name, version) : undefined;
17
+ const field = (o, name, version) => num(read(o, name, version), version);
18
+ /** `_global.flash.geom[name]`, as the realm has it now: undefined where there is none. */
19
+ function geomClass(realm, name, version) {
20
+ const geom = read(read(realm.global, "flash", version), "geom", version);
21
+ return read(geom, name, version);
22
+ }
23
+ /** A new `name` of `args`, by the class `flash.geom` has now; -1 where it has none (Ruffle). */
24
+ export function makeGeom(realm, name, args, version) {
25
+ const constr = geomClass(realm, name, version);
26
+ return constr instanceof avm1.Avm1Function ? realm.construct(constr, args, version) : -1;
27
+ }
28
+ /** `o.name(...args)`, a method found as code calls it; undefined where there is none. */
29
+ function callMethod(o, name, args, version) {
30
+ const method = read(o, name, version);
31
+ return method instanceof avm1.Avm1Function && o instanceof avm1.Avm1Object
32
+ ? method.call(o, args, version, 1)
33
+ : undefined;
34
+ }
35
+ /** `(a=1, b=2)`: each value as AVM1 makes it a string. */
36
+ function described(o, names, version, short) {
37
+ const parts = names.map((n, i) => `${short?.[i] ?? n}=${avm1.stringOf(avm1.get(o, n, version), version)}`);
38
+ return `(${parts.join(", ")})`;
39
+ }
40
+ /** A getter, and a setter if given, on `o` as `name`. */
41
+ function accessor(realm, o, name, get, set, flags = 0) {
42
+ const p = o.add(name, undefined, flags);
43
+ p.get = realm.method(get);
44
+ if (set !== null) {
45
+ p.set = realm.method(set);
46
+ }
47
+ }
48
+ function pointClass(realm) {
49
+ const proto = new avm1.Avm1Object(realm.objectProto);
50
+ const constr = realm.classOf(proto, (self, args, v) => {
51
+ avm1.set(self, "x", args.length === 0 ? 0 : args[0], v);
52
+ avm1.set(self, "y", args.length === 0 ? 0 : args[1], v);
53
+ return self;
54
+ }, () => undefined);
55
+ const point = (x, y, v) => makeGeom(realm, "Point", [x, y], v);
56
+ const method = (name, f) => proto.define(name, realm.method(f), 0);
57
+ accessor(realm, proto, "length", (self, _, v) => Math.hypot(field(self, "x", v), field(self, "y", v)), null);
58
+ method("add", (self, args, v) => point(field(self, "x", v) + field(args[0], "x", v), field(self, "y", v) + field(args[0], "y", v), v));
59
+ method("subtract", (self, args, v) => point(field(self, "x", v) - field(args[0], "x", v), field(self, "y", v) - field(args[0], "y", v), v));
60
+ method("equals", (self, args, v) => args[0] instanceof avm1.Avm1Object &&
61
+ read(self, "x", v) === read(args[0], "x", v) &&
62
+ read(self, "y", v) === read(args[0], "y", v));
63
+ method("normalize", (self, args, v) => {
64
+ // A point of no length stays as it is, as Flash's (the corpus's `point`).
65
+ const length = Math.hypot(field(self, "x", v), field(self, "y", v));
66
+ if (Number.isFinite(length) && length !== 0) {
67
+ const k = num(args[0], v) / length;
68
+ avm1.set(self, "x", field(self, "x", v) * k, v);
69
+ avm1.set(self, "y", field(self, "y", v) * k, v);
70
+ }
71
+ return undefined;
72
+ });
73
+ method("offset", (self, args, v) => {
74
+ avm1.set(self, "x", field(self, "x", v) + num(args[0], v), v);
75
+ avm1.set(self, "y", field(self, "y", v) + num(args[1], v), v);
76
+ return undefined;
77
+ });
78
+ method("clone", (self, _, v) => makeGeom(realm, "Point", [read(self, "x", v), read(self, "y", v)], v));
79
+ method("toString", (self, _, v) => described(self, ["x", "y"], v));
80
+ const statics = (name, f) => constr.define(name, realm.method(f), 0);
81
+ statics("distance", (_, args, v) => args.length < 2 ? Number.NaN : read(callMethod(args[0], "subtract", [args[1]], v), "length", v));
82
+ statics("interpolate", (_, args, v) => {
83
+ if (args.length < 3) {
84
+ return point(Number.NaN, Number.NaN, v);
85
+ }
86
+ const [a, b, f] = [args[0], args[1], num(args[2], v)];
87
+ const bx = field(b, "x", v);
88
+ const by = field(b, "y", v);
89
+ return point(bx - (bx - field(a, "x", v)) * f, by - (by - field(a, "y", v)) * f, v);
90
+ });
91
+ statics("polar", (_, args, v) => {
92
+ const length = num(args[0], v);
93
+ const angle = num(args[1], v);
94
+ return point(length * Math.cos(angle), length * Math.sin(angle), v);
95
+ });
96
+ return constr;
97
+ }
98
+ function rectangleClass(realm) {
99
+ const proto = new avm1.Avm1Object(realm.objectProto);
100
+ const NAMES = ["x", "y", "width", "height"];
101
+ const constr = realm.classOf(proto, (self, args, v) => {
102
+ for (const [i, n] of NAMES.entries()) {
103
+ avm1.set(self, n, args.length === 0 ? 0 : args[i], v);
104
+ }
105
+ return self;
106
+ }, () => undefined);
107
+ const f = (o, n, v) => field(o, n, v);
108
+ const put = (o, n, value, v) => avm1.set(o, n, value, v);
109
+ const make = (x, y, w, h, v) => makeGeom(realm, "Rectangle", [x, y, w, h], v);
110
+ const point = (x, y, v) => makeGeom(realm, "Point", [x, y], v);
111
+ const method = (name, fn) => proto.define(name, realm.method(fn), 0);
112
+ const empty = (o, v) => !(f(o, "width", v) > 0) || !(f(o, "height", v) > 0);
113
+ accessor(realm, proto, "left", (self, _, v) => read(self, "x", v), (self, args, v) => {
114
+ put(self, "width", f(self, "width", v) + f(self, "x", v) - num(args[0], v), v);
115
+ put(self, "x", args[0], v);
116
+ return undefined;
117
+ });
118
+ accessor(realm, proto, "top", (self, _, v) => read(self, "y", v), (self, args, v) => {
119
+ put(self, "height", f(self, "height", v) + f(self, "y", v) - num(args[0], v), v);
120
+ put(self, "y", args[0], v);
121
+ return undefined;
122
+ });
123
+ accessor(realm, proto, "right", (self, _, v) => f(self, "x", v) + f(self, "width", v), (self, args, v) => {
124
+ put(self, "width", num(args[0], v) - f(self, "x", v), v);
125
+ return undefined;
126
+ });
127
+ accessor(realm, proto, "bottom", (self, _, v) => f(self, "y", v) + f(self, "height", v), (self, args, v) => {
128
+ put(self, "height", num(args[0], v) - f(self, "y", v), v);
129
+ return undefined;
130
+ });
131
+ accessor(realm, proto, "topLeft",
132
+ // Points of the values as they are, not numbers (the corpus's `rectangle`).
133
+ (self, _, v) => makeGeom(realm, "Point", [read(self, "x", v), read(self, "y", v)], v), (self, args, v) => {
134
+ put(self, "width", f(self, "width", v) + f(self, "x", v) - f(args[0], "x", v), v);
135
+ put(self, "height", f(self, "height", v) + f(self, "y", v) - f(args[0], "y", v), v);
136
+ put(self, "x", read(args[0], "x", v), v);
137
+ put(self, "y", read(args[0], "y", v), v);
138
+ return undefined;
139
+ });
140
+ accessor(realm, proto, "bottomRight", (self, _, v) => point(f(self, "x", v) + f(self, "width", v), f(self, "y", v) + f(self, "height", v), v), (self, args, v) => {
141
+ put(self, "width", f(args[0], "x", v) - f(self, "x", v), v);
142
+ put(self, "height", f(args[0], "y", v) - f(self, "y", v), v);
143
+ return undefined;
144
+ });
145
+ accessor(realm, proto, "size", (self, _, v) => makeGeom(realm, "Point", [read(self, "width", v), read(self, "height", v)], v), (self, args, v) => {
146
+ put(self, "width", read(args[0], "x", v), v);
147
+ put(self, "height", read(args[0], "y", v), v);
148
+ return undefined;
149
+ });
150
+ method("clone", (self, _, v) => make(read(self, "x", v), read(self, "y", v), read(self, "width", v), read(self, "height", v), v));
151
+ method("isEmpty", (self, _, v) => empty(self, v));
152
+ method("setEmpty", (self, _, v) => {
153
+ for (const n of NAMES) {
154
+ put(self, n, 0, v);
155
+ }
156
+ return undefined;
157
+ });
158
+ const inflate = (self, dx, dy, v) => {
159
+ put(self, "x", f(self, "x", v) - dx, v);
160
+ put(self, "width", f(self, "width", v) + 2 * dx, v);
161
+ put(self, "y", f(self, "y", v) - dy, v);
162
+ put(self, "height", f(self, "height", v) + 2 * dy, v);
163
+ return undefined;
164
+ };
165
+ method("inflate", (self, args, v) => inflate(self, num(args[0], v), num(args[1], v), v));
166
+ method("inflatePoint", (self, args, v) => inflate(self, f(args[0], "x", v), f(args[0], "y", v), v));
167
+ const offset = (self, dx, dy, v) => {
168
+ put(self, "x", f(self, "x", v) + dx, v);
169
+ put(self, "y", f(self, "y", v) + dy, v);
170
+ return undefined;
171
+ };
172
+ method("offset", (self, args, v) => offset(self, num(args[0], v), num(args[1], v), v));
173
+ method("offsetPoint", (self, args, v) => offset(self, f(args[0], "x", v), f(args[0], "y", v), v));
174
+ // A NaN anywhere makes it undefined, neither in nor out (Ruffle).
175
+ const contains = (self, x, y, v) => {
176
+ const [rx, ry, w, h] = NAMES.map((n) => f(self, n, v));
177
+ if ([x, y, rx, ry, w, h].some(Number.isNaN)) {
178
+ return undefined;
179
+ }
180
+ return x >= rx && x < rx + w && y >= ry && y < ry + h;
181
+ };
182
+ method("contains", (self, args, v) => contains(self, num(args[0], v), num(args[1], v), v));
183
+ method("containsPoint", (self, args, v) => contains(self, f(args[0], "x", v), f(args[0], "y", v), v));
184
+ method("containsRectangle", (self, args, v) => {
185
+ const [rx, ry, w, h] = NAMES.map((n) => f(self, n, v));
186
+ const [ox, oy, ow, oh] = NAMES.map((n) => f(args[0], n, v));
187
+ if ([rx, ry, w, h, ox, oy, ow, oh].some(Number.isNaN)) {
188
+ return undefined;
189
+ }
190
+ return ox >= rx && oy >= ry && ox + ow <= rx + w && oy + oh <= ry + h;
191
+ });
192
+ const overlap = (self, other, v) => {
193
+ const [ax, ay, aw, ah] = NAMES.map((n) => f(self, n, v));
194
+ const [bx, by, bw, bh] = NAMES.map((n) => f(other, n, v));
195
+ const left = Math.max(ax, bx);
196
+ const top = Math.max(ay, by);
197
+ const right = Math.min(ax + aw, bx + bw);
198
+ const bottom = Math.min(ay + ah, by + bh);
199
+ return { left, top, right, bottom };
200
+ };
201
+ method("intersects", (self, args, v) => {
202
+ const o = overlap(self, args[0], v);
203
+ return o.right > o.left && o.bottom > o.top;
204
+ });
205
+ method("intersection", (self, args, v) => {
206
+ const o = overlap(self, args[0], v);
207
+ return o.right > o.left && o.bottom > o.top
208
+ ? make(o.left, o.top, o.right - o.left, o.bottom - o.top, v)
209
+ : make(0, 0, 0, 0, v);
210
+ });
211
+ method("union", (self, args, v) => {
212
+ // Empty here by a size not above 0: one of NaNs is not, and its NaNs go into the union.
213
+ const other = args[0];
214
+ const none = (o) => f(o, "width", v) <= 0 || f(o, "height", v) <= 0;
215
+ if (none(self)) {
216
+ return callMethod(other, "clone", [], v);
217
+ }
218
+ if (none(other)) {
219
+ return callMethod(self, "clone", [], v);
220
+ }
221
+ const [ax, ay, aw, ah] = NAMES.map((n) => f(self, n, v));
222
+ const [bx, by, bw, bh] = NAMES.map((n) => f(other, n, v));
223
+ const left = Math.min(ax, bx);
224
+ const top = Math.min(ay, by);
225
+ return make(left, top, Math.max(ax + aw, bx + bw) - left, Math.max(ay + ah, by + bh) - top, v);
226
+ });
227
+ method("equals", (self, args, v) => {
228
+ const other = args[0];
229
+ const constr = geomClass(realm, "Rectangle", v);
230
+ const prototype = read(constr, "prototype", v);
231
+ let p = other instanceof avm1.Avm1Object ? read(other, "__proto__", v) : undefined;
232
+ let isRectangle = false;
233
+ for (let depth = 0; p instanceof avm1.Avm1Object && depth < 256; depth++) {
234
+ if (p === prototype) {
235
+ isRectangle = true;
236
+ break;
237
+ }
238
+ p = read(p, "__proto__", v);
239
+ }
240
+ return isRectangle && NAMES.every((n) => read(self, n, v) === read(other, n, v));
241
+ });
242
+ method("toString", (self, _, v) => described(self, NAMES, v, ["x", "y", "w", "h"]));
243
+ return constr;
244
+ }
245
+ /** A matrix's six fields by name, as numbers. */
246
+ function matrixOf(o, v) {
247
+ return [
248
+ field(o, "a", v),
249
+ field(o, "b", v),
250
+ field(o, "c", v),
251
+ field(o, "d", v),
252
+ field(o, "tx", v),
253
+ field(o, "ty", v),
254
+ ];
255
+ }
256
+ const MATRIX_NAMES = ["a", "b", "c", "d", "tx", "ty"];
257
+ function setMatrix(o, m, v) {
258
+ for (const [i, n] of MATRIX_NAMES.entries()) {
259
+ avm1.set(o, n, m[i], v);
260
+ }
261
+ return undefined;
262
+ }
263
+ function matrixClass(realm) {
264
+ const proto = new avm1.Avm1Object(realm.objectProto);
265
+ const constr = realm.classOf(proto, (self, args, v) => {
266
+ if (args.length === 0) {
267
+ setMatrix(self, [1, 0, 0, 1, 0, 0], v);
268
+ }
269
+ else {
270
+ for (const [i, n] of MATRIX_NAMES.entries()) {
271
+ if (i < args.length) {
272
+ avm1.set(self, n, args[i], v);
273
+ }
274
+ }
275
+ }
276
+ return self;
277
+ }, () => undefined);
278
+ const method = (name, fn) => proto.define(name, realm.method(fn), 0);
279
+ const point = (x, y, v) => makeGeom(realm, "Point", [x, y], v);
280
+ method("identity", (self, _, v) => setMatrix(self, [1, 0, 0, 1, 0, 0], v));
281
+ method("translate", (self, args, v) => {
282
+ const [a, b, c, d, tx, ty] = matrixOf(self, v);
283
+ return setMatrix(self, [a, b, c, d, tx + num(args[0], v), ty + num(args[1], v)], v);
284
+ });
285
+ method("scale", (self, args, v) => {
286
+ const [a, b, c, d, tx, ty] = matrixOf(self, v);
287
+ const sx = num(args[0], v);
288
+ const sy = num(args[1], v);
289
+ return setMatrix(self, [a * sx, b * sy, c * sx, d * sy, tx * sx, ty * sy], v);
290
+ });
291
+ method("rotate", (self, args, v) => {
292
+ const [a, b, c, d, tx, ty] = matrixOf(self, v);
293
+ const q = num(args[0], v);
294
+ const cos = Math.cos(q);
295
+ const sin = Math.sin(q);
296
+ return setMatrix(self, [
297
+ a * cos - b * sin,
298
+ a * sin + b * cos,
299
+ c * cos - d * sin,
300
+ c * sin + d * cos,
301
+ tx * cos - ty * sin,
302
+ tx * sin + ty * cos,
303
+ ], v);
304
+ });
305
+ method("concat", (self, args, v) => {
306
+ const [a, b, c, d, tx, ty] = matrixOf(self, v);
307
+ const [ma, mb, mc, md, mtx, mty] = matrixOf(args[0], v);
308
+ return setMatrix(self, [
309
+ a * ma + b * mc,
310
+ a * mb + b * md,
311
+ c * ma + d * mc,
312
+ c * mb + d * md,
313
+ tx * ma + ty * mc + mtx,
314
+ tx * mb + ty * md + mty,
315
+ ], v);
316
+ });
317
+ method("invert", (self, _, v) => {
318
+ const [a, b, c, d, tx, ty] = matrixOf(self, v);
319
+ const det = a * d - b * c;
320
+ if (det === 0) {
321
+ return setMatrix(self, [1, 0, 0, 1, 0, 0], v);
322
+ }
323
+ return setMatrix(self, [d / det, -b / det, -c / det, a / det, (c * ty - d * tx) / det, (b * tx - a * ty) / det], v);
324
+ });
325
+ // A rotation not given is NaN, as Flash's; a translation not given is 0.
326
+ const box = (sx, sy, q, tx, ty) => {
327
+ const cos = Math.cos(q);
328
+ const sin = Math.sin(q);
329
+ return [sx * cos, sy * sin, -sx * sin, sy * cos, tx, ty];
330
+ };
331
+ const arg = (args, i, fallback, v) => i < args.length ? num(args[i], v) : fallback;
332
+ method("createBox", (self, args, v) => setMatrix(self, box(num(args[0], v), num(args[1], v), arg(args, 2, Number.NaN, v), arg(args, 3, 0, v), arg(args, 4, 0, v)), v));
333
+ method("createGradientBox", (self, args, v) => {
334
+ const w = num(args[0], v);
335
+ const h = num(args[1], v);
336
+ const x = arg(args, 3, 0, v);
337
+ const y = arg(args, 4, 0, v);
338
+ return setMatrix(self, box(w / 1638.4, h / 1638.4, arg(args, 2, 0, v), x + w / 2, y + h / 2), v);
339
+ });
340
+ method("transformPoint", (self, args, v) => {
341
+ const [a, b, c, d, tx, ty] = matrixOf(self, v);
342
+ const x = field(args[0], "x", v);
343
+ const y = field(args[0], "y", v);
344
+ return point(a * x + c * y + tx, b * x + d * y + ty, v);
345
+ });
346
+ method("deltaTransformPoint", (self, args, v) => {
347
+ const [a, b, c, d] = matrixOf(self, v);
348
+ const x = field(args[0], "x", v);
349
+ const y = field(args[0], "y", v);
350
+ return point(a * x + c * y, b * x + d * y, v);
351
+ });
352
+ method("clone", (self, _, v) => makeGeom(realm, "Matrix", MATRIX_NAMES.map((n) => read(self, n, v)), v));
353
+ method("toString", (self, _, v) => described(self, MATRIX_NAMES, v));
354
+ return constr;
355
+ }
356
+ /** A ColorTransform's eight values: the multipliers, red, green, blue, alpha, then the offsets. */
357
+ const colors = new WeakMap();
358
+ const COLOR_NAMES = [
359
+ "redMultiplier",
360
+ "greenMultiplier",
361
+ "blueMultiplier",
362
+ "alphaMultiplier",
363
+ "redOffset",
364
+ "greenOffset",
365
+ "blueOffset",
366
+ "alphaOffset",
367
+ ];
368
+ /** A native ColorTransform's values, or null for anything else. */
369
+ export function colorValues(o) {
370
+ return o instanceof avm1.Avm1Object ? (colors.get(o) ?? null) : null;
371
+ }
372
+ function colorTransformClass(realm) {
373
+ const proto = new avm1.Avm1Object(realm.objectProto);
374
+ const constr = realm.classOf(proto, (self, args, v) => {
375
+ const values = Float64Array.of(1, 1, 1, 1, 0, 0, 0, 0);
376
+ const copied = args.length === 1 ? colorValues(args[0]) : null;
377
+ if (copied) {
378
+ values.set(copied);
379
+ }
380
+ else if (args.length >= 8) {
381
+ for (let i = 0; i < 8; i++) {
382
+ values[i] = num(args[i], v);
383
+ }
384
+ }
385
+ colors.set(self, values);
386
+ return self;
387
+ }, () => undefined);
388
+ // Alpha first of each four, as Flash defines them: for..in lists them the other way.
389
+ for (const i of [3, 0, 1, 2, 7, 4, 5, 6]) {
390
+ const name = COLOR_NAMES[i];
391
+ accessor(realm, proto, name, (self) => colors.get(self)?.[i], (self, args, v) => {
392
+ const values = colors.get(self);
393
+ if (values) {
394
+ values[i] = num(args[0], v);
395
+ }
396
+ return undefined;
397
+ });
398
+ }
399
+ accessor(realm, proto, "rgb", (self) => {
400
+ const c = colors.get(self);
401
+ return c ? (((c[4] | 0) << 16) + ((c[5] | 0) << 8) + (c[6] | 0)) >>> 0 : undefined;
402
+ }, (self, args, v) => {
403
+ const c = colors.get(self);
404
+ if (c) {
405
+ const rgb = num(args[0], v) >>> 0;
406
+ c.set([0, 0, 0], 0);
407
+ c[4] = (rgb >>> 16) & 0xff;
408
+ c[5] = (rgb >>> 8) & 0xff;
409
+ c[6] = rgb & 0xff;
410
+ }
411
+ return undefined;
412
+ });
413
+ proto.define("concat", realm.method((self, args) => {
414
+ const c = colors.get(self);
415
+ const o = colorValues(args[0]);
416
+ if (c && o) {
417
+ for (let i = 0; i < 4; i++) {
418
+ c[4 + i] = o[4 + i] * c[i] + c[4 + i];
419
+ c[i] *= o[i];
420
+ }
421
+ }
422
+ return undefined;
423
+ }), 0);
424
+ proto.define("toString", realm.method((self, _, v) => described(self, COLOR_NAMES, v)), 0);
425
+ return constr;
426
+ }
427
+ /** A Transform's clip, by its AVM1 object, read again as it is used, as Ruffle's MovieClipReference is. */
428
+ const transforms = new WeakMap();
429
+ /** What a clip's AVM1 object, or a Transform's, is the face of; null for anything else. */
430
+ function displayOf(o) {
431
+ const face = o instanceof avm1.Avm1Object ? (transforms.get(o) ?? o) : null;
432
+ const target = face?.display?.target;
433
+ return target === undefined ? null : target;
434
+ }
435
+ /** `d`'s matrix as a new Matrix, in pixels. */
436
+ function matrixObject(host, m, v) {
437
+ return makeGeom(host.realm, "Matrix", [m.a, m.b, m.c, m.d, m.tx, m.ty], v);
438
+ }
439
+ function colorObject(host, c, v) {
440
+ return makeGeom(host.realm, "ColorTransform", c ?? [1, 1, 1, 1, 0, 0, 0, 0], v);
441
+ }
442
+ /** A 16-bit integer, wrapped, as a clip's colour transform keeps each value. */
443
+ export const int16 = (n) => ((n | 0) << 16) >> 16;
444
+ /** A multiplier as a clip keeps it, in 8.8 fixed point, 16 bits. */
445
+ const fixed8 = (n) => int16(Math.trunc(n * 256)) / 256;
446
+ /** An offset as a clip keeps it: whole, 16 bits (-66682.5 is -1147). */
447
+ const offset16 = (n) => int16(Math.floor(n));
448
+ /** A display object's colour transform as ColorTransform's eight values. */
449
+ function colorArgs(d) {
450
+ const c = d.colorTransform;
451
+ return c
452
+ ? [c.rMul, c.gMul, c.bMul, c.aMul, c.rAdd, c.gAdd, c.bAdd, c.aAdd]
453
+ : [1, 1, 1, 1, 0, 0, 0, 0];
454
+ }
455
+ /** `matrix` set on `d` where it has all six fields of its own: whole twips, as Flash keeps the translation. */
456
+ function setDisplayMatrix(d, matrix, v) {
457
+ if (!(matrix instanceof avm1.Avm1Object) ||
458
+ MATRIX_NAMES.some((n) => matrix.own(n, v) === undefined)) {
459
+ return;
460
+ }
461
+ const [a, b, c, dd, tx, ty] = matrixOf(matrix, v);
462
+ d.setMatrix({ a, b, c, d: dd, tx: Math.round(tx * 20) / 20, ty: Math.round(ty * 20) / 20 });
463
+ d.touch();
464
+ d.invalidate(TRANSFORM);
465
+ }
466
+ /**
467
+ * A native ColorTransform's values set as `d`'s colour transform, as a
468
+ * clip keeps them: the multipliers in 8.8 fixed point, the offsets whole,
469
+ * each 16 bits, wrapped (the corpus's `transform`: -66682.5 is -1147).
470
+ */
471
+ function setDisplayColor(d, color) {
472
+ const c = colorValues(color);
473
+ if (c === null) {
474
+ return;
475
+ }
476
+ d.colorTransform = {
477
+ rMul: fixed8(c[0]),
478
+ gMul: fixed8(c[1]),
479
+ bMul: fixed8(c[2]),
480
+ aMul: fixed8(c[3]),
481
+ rAdd: offset16(c[4]),
482
+ gAdd: offset16(c[5]),
483
+ bAdd: offset16(c[6]),
484
+ aAdd: offset16(c[7]),
485
+ };
486
+ d.touch();
487
+ d.invalidate(TRANSFORM);
488
+ }
489
+ function transformClass(host) {
490
+ const realm = host.realm;
491
+ const proto = new avm1.Avm1Object(realm.objectProto);
492
+ const constr = realm.classOf(proto, (self, args) => {
493
+ // Of exactly one clip; otherwise `new` gives undefined.
494
+ if (args.length !== 1 || displayOf(args[0]) === null || transforms.has(args[0])) {
495
+ return undefined;
496
+ }
497
+ transforms.set(self, args[0]);
498
+ return self;
499
+ }, () => undefined);
500
+ const clip = (self) => (transforms.has(self) ? displayOf(self) : null);
501
+ accessor(realm, proto, "matrix", (self, _, v) => {
502
+ const d = clip(self);
503
+ return d ? matrixObject(host, d.matrix, v) : undefined;
504
+ }, (self, args, v) => {
505
+ const d = clip(self);
506
+ if (d) {
507
+ setDisplayMatrix(d, args[0], v);
508
+ }
509
+ return undefined;
510
+ });
511
+ accessor(realm, proto, "colorTransform", (self, _, v) => {
512
+ const d = clip(self);
513
+ return d ? colorObject(host, colorArgs(d), v) : undefined;
514
+ }, (self, args) => {
515
+ const d = clip(self);
516
+ if (d) {
517
+ setDisplayColor(d, args[0]);
518
+ }
519
+ return undefined;
520
+ });
521
+ accessor(realm, proto, "concatenatedMatrix", (self, _, v) => {
522
+ const d = clip(self);
523
+ return d ? matrixObject(host, toStage(d, host.stageOf(d)), v) : undefined;
524
+ }, null);
525
+ accessor(realm, proto, "concatenatedColorTransform", (self, _, v) => {
526
+ const d = clip(self);
527
+ if (!d) {
528
+ return undefined;
529
+ }
530
+ // Each ancestor's applied after what is in it, each product kept as a clip keeps a
531
+ // colour transform (the corpus's `transform`).
532
+ let c = colorArgs(d);
533
+ for (let p = d.parent; p !== null; p = p.parent) {
534
+ const o = colorArgs(p);
535
+ c = [
536
+ fixed8(c[0] * o[0]),
537
+ fixed8(c[1] * o[1]),
538
+ fixed8(c[2] * o[2]),
539
+ fixed8(c[3] * o[3]),
540
+ offset16(c[4] * o[0] + o[4]),
541
+ offset16(c[5] * o[1] + o[5]),
542
+ offset16(c[6] * o[2] + o[6]),
543
+ offset16(c[7] * o[3] + o[7]),
544
+ ];
545
+ }
546
+ return colorObject(host, c, v);
547
+ }, null);
548
+ accessor(realm, proto, "pixelBounds", (self, _, v) => {
549
+ const d = clip(self);
550
+ if (!d) {
551
+ return undefined;
552
+ }
553
+ const r = bounds(d, true);
554
+ const m = toStage(d, host.stageOf(d));
555
+ if (r === null) {
556
+ return makeGeom(realm, "Rectangle", [0, 0, 0, 0], v);
557
+ }
558
+ const xs = [r.xMin, r.xMax].flatMap((x) => [r.yMin, r.yMax].map((y) => m.a * x + m.c * y + m.tx));
559
+ const ys = [r.xMin, r.xMax].flatMap((x) => [r.yMin, r.yMax].map((y) => m.b * x + m.d * y + m.ty));
560
+ const left = Math.min(...xs);
561
+ const top = Math.min(...ys);
562
+ return makeGeom(realm, "Rectangle", [left, top, Math.max(...xs) - left, Math.max(...ys) - top], v);
563
+ }, null);
564
+ return constr;
565
+ }
566
+ /** A clip's `transform`: a new Transform of it each read, as Flash gives one. */
567
+ export function transformOf(host, face, v) {
568
+ return makeGeom(host.realm, "Transform", [face], v);
569
+ }
570
+ /** `clip.transform = t`: the matrix and colour transform of the clip `t` is a Transform of. */
571
+ export function assignTransform(d, t) {
572
+ const from = t instanceof avm1.Avm1Object && transforms.has(t) ? displayOf(t) : null;
573
+ if (from === null) {
574
+ return;
575
+ }
576
+ const m = from.matrix;
577
+ d.setMatrix({ a: m.a, b: m.b, c: m.c, d: m.d, tx: m.tx, ty: m.ty });
578
+ d.colorTransform = from.colorTransform ? { ...from.colorTransform } : null;
579
+ d.touch();
580
+ d.invalidate(TRANSFORM);
581
+ }
582
+ /**
583
+ * `_global.flash`, from SWF 8, with `geom`'s classes; `display` waits for
584
+ * BitmapData. Its members are plain properties, as Flash's.
585
+ */
586
+ export function flashPackage(host) {
587
+ const realm = host.realm;
588
+ const flash = new avm1.Avm1Object(realm.objectProto);
589
+ const geom = new avm1.Avm1Object(realm.objectProto);
590
+ const display = new avm1.Avm1Object(realm.objectProto);
591
+ flash.define("geom", geom, 0);
592
+ flash.define("display", display, 0);
593
+ geom.define("Point", pointClass(realm), 0);
594
+ geom.define("Rectangle", rectangleClass(realm), 0);
595
+ geom.define("Matrix", matrixClass(realm), 0);
596
+ geom.define("ColorTransform", colorTransformClass(realm), 0);
597
+ geom.define("Transform", transformClass(host), 0);
598
+ realm.global.define("flash", flash, avm1.DONT_ENUM | avm1.VERSION_8);
599
+ return flash;
600
+ }