@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,193 @@
1
+ // A 3D display object's plane in perspective (docs/architecture/rendering.md, "3D
2
+ // display objects"): as Flash Player and adl project it, through the
3
+ // perspective projection of the nearest container above it that has one
4
+ // set, or else of its SWF's root (the stage's, for one put on the stage).
5
+ // Its matrix3D, those of the 3D objects above it and the 2D matrices
6
+ // between go into one 3D transform to that container's space, which the
7
+ // projection then divides: a 3D object inside another is in true 3D, not
8
+ // flattened into the other's plane. The plane of each object, 2D or 3D,
9
+ // is then a projective map of its space to the container's, and a 3D
10
+ // object's in its parent's is the parent's inverse after its own.
11
+ import { apply, concat, invert } from "./geometry.js";
12
+ /** Each player's stage's size, for the default projection of a root: centred on the stage and as wide. */
13
+ const stageSizes = new WeakMap();
14
+ export function setStageSize(stage, width, height) {
15
+ stageSizes.set(stage, { width, height });
16
+ }
17
+ /**
18
+ * A BitmapData's draw of what is on no stage, `top` the topmost of it: as
19
+ * in Flash, what is in 3D in it projects as on a stage the bitmap's size,
20
+ * centred on it, for the draw. Returns how to put it back, or null where it
21
+ * is on a stage already.
22
+ */
23
+ export function drawnAsStage(top, width, height) {
24
+ if (top.parent || top.loaderInfo || stageSizes.has(top)) {
25
+ return null;
26
+ }
27
+ stageSizes.set(top, { width, height });
28
+ return () => stageSizes.delete(top);
29
+ }
30
+ /** The size of the stage `d` is under, or Flash's default stage's where it is under none. */
31
+ function stageSizeOf(d) {
32
+ let top = d;
33
+ while (top.parent) {
34
+ top = top.parent;
35
+ }
36
+ return stageSizes.get(top) ?? { width: 550, height: 400 };
37
+ }
38
+ /** Flash's default field of view, 55 degrees, in radians. */
39
+ const FIELD_OF_VIEW = (55 * Math.PI) / 180;
40
+ /** The projection of what has none set: Flash's field of view, centred on (centerX, centerY). */
41
+ export function defaultProjection(centerX, centerY) {
42
+ return { fieldOfView: FIELD_OF_VIEW, centerX, centerY };
43
+ }
44
+ /** The focal length of a field of view in radians over a width, in float32 as Flash's. */
45
+ export function focalLengthOver(radians, width) {
46
+ return Math.fround((width / 2) * Math.fround(Math.tan((Math.PI - radians) / 2)));
47
+ }
48
+ /** Whether `d` projects what is in it: a projection set on it, a SWF's root, or the stage (no parent). */
49
+ function projects(d) {
50
+ return d.projection !== null || d.loaderInfo !== null || d.parent === null;
51
+ }
52
+ /** The container whose projection `o` is drawn through: the nearest above it that projects. */
53
+ function projectorOf(o) {
54
+ for (let p = o.parent; p; p = p.parent) {
55
+ if (projects(p)) {
56
+ return p;
57
+ }
58
+ }
59
+ return null;
60
+ }
61
+ /** The projection `d` projects through: its own, or the default of the stage or a root. */
62
+ function projectionOf(d) {
63
+ if (d.projection) {
64
+ return d.projection;
65
+ }
66
+ const stage = d.parent === null && d.loaderInfo !== null;
67
+ const size = stageSizeOf(d);
68
+ return stage ? defaultProjection(250, 250) : defaultProjection(size.width / 2, size.height / 2);
69
+ }
70
+ /**
71
+ * The focal length of a field of view in radians as `d` projects through
72
+ * it: the stage's projection measures 500 wide, any other object's the
73
+ * stage's width.
74
+ */
75
+ function focalLength(radians, d) {
76
+ const width = d.parent === null && d.loaderInfo !== null ? 500 : stageSizeOf(d).width;
77
+ return focalLengthOver(radians, width);
78
+ }
79
+ /** `m`, `d`'s own transform in 3D: its matrix3D, or its 2D matrix with z kept (a 3D object has no scroll). */
80
+ function own3D(d) {
81
+ const m = new Float64Array(16);
82
+ const space = d.space;
83
+ if (space) {
84
+ m.set(space.shown);
85
+ }
86
+ else {
87
+ const p = d.placed;
88
+ m.set([p.a, p.b, 0, 0, p.c, p.d, 0, 0, 0, 0, 1, 0, p.tx, p.ty, 0, 1]);
89
+ }
90
+ return m;
91
+ }
92
+ /** `a` after `b`: b's columns through a. */
93
+ function multiply(a, b) {
94
+ const out = new Float64Array(16);
95
+ for (let c = 0; c < 4; c++) {
96
+ for (let r = 0; r < 4; r++) {
97
+ out[c * 4 + r] =
98
+ a[r] * b[c * 4] +
99
+ a[4 + r] * b[c * 4 + 1] +
100
+ a[8 + r] * b[c * 4 + 2] +
101
+ a[12 + r] * b[c * 4 + 3];
102
+ }
103
+ }
104
+ return out;
105
+ }
106
+ /** `d`'s space to `top`'s in 3D, `top` excluded; null where `top` is not above it. */
107
+ function toSpace(d, top) {
108
+ let m = own3D(d);
109
+ for (let p = d.parent; p !== top; p = p.parent) {
110
+ if (!p) {
111
+ return null;
112
+ }
113
+ m = multiply(own3D(p), m);
114
+ }
115
+ return m;
116
+ }
117
+ /**
118
+ * A point in the projector's 3D space projected into its plane, as
119
+ * homogeneous coordinates: the field of view's focal length f, the centre
120
+ * (cx, cy), and a point at depth z drawn at f / (f + z) of its distance
121
+ * from the centre.
122
+ */
123
+ function project(projector, x, y, z) {
124
+ const p = projectionOf(projector);
125
+ const k = 1 / focalLength(p.fieldOfView, projector);
126
+ return [x + p.centerX * k * z, y + p.centerY * k * z, 1 + k * z];
127
+ }
128
+ /** The plane z = 0 of a 3D space `m` puts in the projector's, projected: a projective map. */
129
+ function planeOf(projector, m) {
130
+ const p = projectionOf(projector);
131
+ const k = 1 / focalLength(p.fieldOfView, projector);
132
+ const cx = p.centerX * k;
133
+ const cy = p.centerY * k;
134
+ return {
135
+ a: m[0] + cx * m[2],
136
+ b: m[1] + cy * m[2],
137
+ u: k * m[2] + m[3],
138
+ c: m[4] + cx * m[6],
139
+ d: m[5] + cy * m[6],
140
+ v: k * m[6] + m[7],
141
+ tx: m[12] + cx * m[14],
142
+ ty: m[13] + cy * m[14],
143
+ w: k * m[14] + m[15],
144
+ };
145
+ }
146
+ /**
147
+ * A 3D object's plane in its parent's space, in perspective (`placed`):
148
+ * through its projector's projection, its plane in the projector's space
149
+ * (`own`), and back through the parent's plane there (`back`, null where
150
+ * the parent is the projector), which is flat but for a 3D object above
151
+ * it. An object off the list projects through its topmost container's, as
152
+ * a root's.
153
+ */
154
+ export function placedInPerspective(o) {
155
+ const parent = o.parent;
156
+ if (!parent) {
157
+ const m = own3D(o);
158
+ const placed = { a: m[0], b: m[1], c: m[4], d: m[5], tx: m[12], ty: m[13], u: 0, v: 0, w: 1 };
159
+ return { placed, own: placed, back: null };
160
+ }
161
+ const projector = projectorOf(o);
162
+ const up = parent === projector ? null : toSpace(parent, projector);
163
+ const m = up ? multiply(up, own3D(o)) : own3D(o);
164
+ // A NaN anywhere, as an infinite scale's column has, goes into all of Flash's projection, which
165
+ // then draws nothing: the plane's z column alone would leave it out.
166
+ if (m.some(Number.isNaN)) {
167
+ m.fill(Number.NaN);
168
+ }
169
+ const own = planeOf(projector, m);
170
+ if (!up) {
171
+ return { placed: own, own, back: null };
172
+ }
173
+ const back = invert(planeOf(projector, up));
174
+ return { placed: (back ? concat(own, back) : own), own, back };
175
+ }
176
+ /**
177
+ * A point of `d`'s 3D space on the stage (`stage` itself excluded): into
178
+ * its projector's space, projected there, then through the projector's
179
+ * matrices up to the stage.
180
+ */
181
+ export function stagePoint3D(d, x, y, z, stage) {
182
+ const projector = projectorOf(d);
183
+ const m = projector && toSpace(d, projector);
184
+ if (!projector || !m) {
185
+ return apply(d.placed, x, y);
186
+ }
187
+ const [px, py, q] = project(projector, m[0] * x + m[4] * y + m[8] * z + m[12], m[1] * x + m[5] * y + m[9] * z + m[13], m[2] * x + m[6] * y + m[10] * z + m[14]);
188
+ let at = [px / q, py / q];
189
+ for (let p = projector; p && p !== stage; p = p.parent) {
190
+ at = apply(p.placed, at[0], at[1]);
191
+ }
192
+ return at;
193
+ }
@@ -0,0 +1,236 @@
1
+ import { ownBounds } from "./bounds.js";
2
+ import { Container, ShapeObject, StaticTextObject, TextObject, } from "./display.js";
3
+ import { apply, invert, union } from "./geometry.js";
4
+ import { MOVE, pointsOf } from "./shapes.js";
5
+ import { makeRoom, moveLast, same } from "./value-lists.js";
6
+ /**
7
+ * Flash slices only an object whose own matrix neither turns nor skews,
8
+ * to a 4096th, and mirrors neither way; any other scales as ever. adl
9
+ * slices b = 0.000244 and not 0.0002442: a 16.16 fraction under 16.
10
+ */
11
+ const SKEW = 1 / 4096;
12
+ /**
13
+ * An axis from the bounds' edges lo and hi and the grid's gLo and gHi,
14
+ * scaled by s: the corners keep their size in the parent's units, or,
15
+ * where the scaled size is less than theirs, share it in proportion and
16
+ * leave the centre none.
17
+ */
18
+ export function axis(lo, gLo, gHi, hi, s) {
19
+ const corners = gLo - lo + (hi - gHi);
20
+ const k = Math.min(1, (s * (hi - lo)) / corners);
21
+ return {
22
+ from: [lo, gLo, gHi, hi],
23
+ to: [lo, lo + (k * (gLo - lo)) / s, hi - (k * (hi - gHi)) / s, hi],
24
+ };
25
+ }
26
+ /**
27
+ * The bounds a grid divides: what `o` draws, without lines, and what each
28
+ * of its children draws itself, each in the child's own space, its matrix
29
+ * ignored, and nothing of the grandchildren; a text field or a static
30
+ * text counts for nothing, a bitmap or a video does. So adl slices: a
31
+ * child's bars moved 30 to the right leave the edges where the panel's
32
+ * are, one drawn out to 120 moves the right edge to 120 wherever the child
33
+ * is, and a grandchild's moves nothing.
34
+ */
35
+ export function sliceBounds(o) {
36
+ let r = ownBounds(o, false);
37
+ if (o instanceof Container) {
38
+ for (const child of o.children) {
39
+ if (!(child instanceof TextObject || child instanceof StaticTextObject)) {
40
+ const b = ownBounds(child, false);
41
+ if (b) {
42
+ r = union(r, b);
43
+ }
44
+ }
45
+ }
46
+ }
47
+ return r;
48
+ }
49
+ /** Whether `grid` is strictly inside `r` both ways, as Flash slices only by such a grid. */
50
+ export function gridInside(r, grid) {
51
+ return (r !== null &&
52
+ r.xMin < grid.xMin &&
53
+ grid.xMin < grid.xMax &&
54
+ grid.xMax < r.xMax &&
55
+ r.yMin < grid.yMin &&
56
+ grid.yMin < grid.yMax &&
57
+ grid.yMax < r.yMax);
58
+ }
59
+ /**
60
+ * The slice `o` draws its shapes with under its matrix `m`: null where it
61
+ * has no grid, or one not strictly inside its sliceBounds both ways, or a
62
+ * transform Flash does not slice under, or one that changes nothing.
63
+ */
64
+ export function sliceOf(o, m = o.matrix) {
65
+ const grid = o.scale9Grid;
66
+ if (!grid ||
67
+ !(m.a > 0 && m.d > 0 && Math.abs(m.b) < SKEW && Math.abs(m.c) < SKEW) ||
68
+ (m.a === 1 && m.d === 1)) {
69
+ return null;
70
+ }
71
+ const r = sliceBounds(o);
72
+ if (!r || !gridInside(r, grid)) {
73
+ return null;
74
+ }
75
+ const kept = slices.get(o);
76
+ if (kept &&
77
+ kept.grid === grid &&
78
+ kept.a === m.a &&
79
+ kept.d === m.d &&
80
+ kept.r.xMin === r.xMin &&
81
+ kept.r.yMin === r.yMin &&
82
+ kept.r.xMax === r.xMax &&
83
+ kept.r.yMax === r.yMax) {
84
+ return kept.slice;
85
+ }
86
+ const x = axis(r.xMin, grid.xMin, grid.xMax, r.xMax, m.a);
87
+ const y = axis(r.yMin, grid.yMin, grid.yMax, r.yMax, m.d);
88
+ const slice = { x, y, key: `${x.to.join()},${y.to.join()},${x.from.join()},${y.from.join()}` };
89
+ slices.set(o, { grid, a: m.a, d: m.d, r, slice });
90
+ return slice;
91
+ }
92
+ /**
93
+ * The slice `o` draws with as it is drawn: a MorphShape, it or a child,
94
+ * takes its ratio's blend first, as it does later in the same draw, so
95
+ * that a new ratio's bounds slice on its own frame, as adl's do, and not
96
+ * a frame late.
97
+ */
98
+ export function sliceDrawn(o) {
99
+ if (o instanceof ShapeObject && o.morph) {
100
+ o.drawn();
101
+ }
102
+ else if (o instanceof Container) {
103
+ for (const child of o.children) {
104
+ if (child instanceof ShapeObject && child.morph) {
105
+ child.drawn();
106
+ }
107
+ }
108
+ }
109
+ return sliceOf(o);
110
+ }
111
+ /** Each object's last slice and what it was made of: a hit test asks for it on every pointer move. */
112
+ const slices = new WeakMap();
113
+ /**
114
+ * Where `v` is drawn on the axis: piecewise linear through the edges, and
115
+ * on past the bounds at the corners' rate, as a curve's control point may be.
116
+ */
117
+ export function onAxis(axis, v) {
118
+ const { from, to } = axis;
119
+ const i = v < from[1] ? 0 : v < from[2] ? 1 : 2;
120
+ return to[i] + ((v - from[i]) * (to[i + 1] - to[i])) / (from[i + 1] - from[i]);
121
+ }
122
+ /**
123
+ * The slice that reshapes what `d` itself draws, and the matrix from its
124
+ * space to the owner's, null for the owner itself: its own grid's, or,
125
+ * for a shape, its parent's, unless it is filtered, which adl draws as a
126
+ * bitmap of it, stretched whole (the `slice-filtered` case). Null for none.
127
+ */
128
+ export function sliceFor(d) {
129
+ if (withinMask(d)) {
130
+ return null;
131
+ }
132
+ if (d.scale9Grid) {
133
+ const slice = sliceOf(d);
134
+ if (slice) {
135
+ return { slice, m: null };
136
+ }
137
+ }
138
+ const parent = d.parent;
139
+ if (d instanceof ShapeObject && parent?.scale9Grid && d.filters.length === 0) {
140
+ const slice = sliceOf(parent);
141
+ if (slice) {
142
+ return { slice, m: d.placed };
143
+ }
144
+ }
145
+ return null;
146
+ }
147
+ /**
148
+ * Whether `d` is a mask, a script's or a timeline's, or is in one: adl
149
+ * draws it unsliced, and its shape test hits nothing of it.
150
+ */
151
+ export function withinMask(d) {
152
+ for (let o = d; o; o = o.parent) {
153
+ if (o.maskOf !== null || o.clipDepth > 0) {
154
+ return true;
155
+ }
156
+ }
157
+ return false;
158
+ }
159
+ /**
160
+ * Layers with every point of their paths, fills' and lines' alike, moved
161
+ * as the slice moves them. A fill's gradient or bitmap keeps its matrix,
162
+ * stretched as ever, as Flash's does. `version` is a drawing's, whose
163
+ * layers change in place.
164
+ */
165
+ export function sliceLayers(layers, slice, m, version = 0) {
166
+ // Compared as values, not by a key formatted from them on every draw and hit test: the slice
167
+ // by its own key, made once with it, its matrix by its numbers.
168
+ let kept = sliced.get(layers);
169
+ for (let i = kept ? kept.length - 1 : -1; i >= 0; i--) {
170
+ const e = kept[i];
171
+ if (e.version === version &&
172
+ (e.slice === slice || e.slice.key === slice.key) &&
173
+ (e.m === null
174
+ ? m === null
175
+ : m !== null &&
176
+ same(e.m.a, m.a) &&
177
+ same(e.m.b, m.b) &&
178
+ same(e.m.c, m.c) &&
179
+ same(e.m.d, m.d) &&
180
+ same(e.m.tx, m.tx) &&
181
+ same(e.m.ty, m.ty))) {
182
+ return (i === kept.length - 1 ? e : moveLast(kept, i))
183
+ .layers;
184
+ }
185
+ }
186
+ const made = moveLayers(layers, slice, m);
187
+ if (!kept) {
188
+ kept = [];
189
+ sliced.set(layers, kept);
190
+ }
191
+ // The least lately used goes past a few: instances of one symbol at a few sizes alternate.
192
+ makeRoom(kept, SLICES_KEPT, () => false, () => { });
193
+ kept.push({ slice, m: m && { ...m }, version, layers: made });
194
+ return made;
195
+ }
196
+ const SLICES_KEPT = 4;
197
+ /**
198
+ * The latest slices of each set of layers, with the slice, matrix and
199
+ * version each was made for: a hit test asks on every pointer move, and
200
+ * the renderer again on a redraw that is not a reslice.
201
+ */
202
+ const sliced = new WeakMap();
203
+ function moveLayers(layers, slice, m) {
204
+ const inverse = m && invert(m);
205
+ if (m && !inverse) {
206
+ return layers;
207
+ }
208
+ const move = (path) => {
209
+ const out = path.slice();
210
+ for (let i = 0; i < out.length;) {
211
+ const points = pointsOf(out[i]);
212
+ for (let k = 0; k < points; k++) {
213
+ const at = i + 1 + 2 * k;
214
+ const [ox, oy] = m ? apply(m, out[at], out[at + 1]) : [out[at], out[at + 1]];
215
+ const sx = onAxis(slice.x, ox);
216
+ const sy = onAxis(slice.y, oy);
217
+ [out[at], out[at + 1]] = inverse ? apply(inverse, sx, sy) : [sx, sy];
218
+ }
219
+ i += 1 + 2 * points;
220
+ }
221
+ return out;
222
+ };
223
+ // drawTriangles' textured triangles stay where they were drawn.
224
+ return layers.map((layer) => ({
225
+ ...layer,
226
+ fills: layer.fills.map((f) => ({ ...f, contours: f.contours.map(move) })),
227
+ strokes: layer.strokes.map((s) => ({
228
+ ...s,
229
+ paths: s.paths.map(move),
230
+ closes: s.closes?.map((c) => {
231
+ const [, x, y] = move([MOVE, c.x, c.y]);
232
+ return { at: c.at, x, y };
233
+ }),
234
+ })),
235
+ }));
236
+ }
@@ -0,0 +1,131 @@
1
+ import { IDENTITY_COLOR } from "./color.js";
2
+ import { CONTENT, DisplayObject, pickWork, TRANSFORM } from "./displayobject.js";
3
+ import { morphAt } from "./morph.js";
4
+ export class ShapeObject extends DisplayObject {
5
+ /** The shape it draws, or last drew; null for a Shape a script made, which draws nothing yet. */
6
+ shape;
7
+ /** A MorphShape's morph, which `shape` is a blend of. */
8
+ morph = null;
9
+ /**
10
+ * The blend drawn() last made, and its morph and ratio: it stands while
11
+ * `shape` is still it, which a swap to a shape is not.
12
+ */
13
+ blended = null;
14
+ /**
15
+ * The shape Flash's bitmap cache of it still shows, given another of the
16
+ * same bounds while cached (`swap`), and the look it was cached with;
17
+ * null where it draws what it is. It goes for good when the look does.
18
+ */
19
+ stale = null;
20
+ constructor(shape) {
21
+ super();
22
+ this.shape = shape;
23
+ this.character = shape;
24
+ }
25
+ /** A MorphShape, its morph's start until it is drawn at another ratio. */
26
+ static ofMorph(morph) {
27
+ const shape = morphAt(morph, 0);
28
+ const object = new ShapeObject(shape);
29
+ object.morph = morph;
30
+ object.blended = { morph, ratio: 0, shape };
31
+ object.character = morph;
32
+ return object;
33
+ }
34
+ /**
35
+ * A MorphShape takes on a new ratio when it is next drawn (drawn): until
36
+ * then its bounds and hit tests are the last drawn blend's, as Flash's
37
+ * are (the corpus's hittest_morph).
38
+ */
39
+ applyPlace(place) {
40
+ const ratio = this.ratio;
41
+ super.applyPlace(place);
42
+ if (this.morph && this.ratio !== ratio) {
43
+ this.invalidate(CONTENT);
44
+ }
45
+ }
46
+ /** The shape to draw now: a MorphShape's blend at its ratio, which it keeps from here. */
47
+ drawn() {
48
+ // The blend it has is kept while its morph and ratio are: asking the
49
+ // morph again would turn over its few latest blends for nothing.
50
+ const b = this.blended;
51
+ if (this.morph &&
52
+ (b?.morph !== this.morph || b.ratio !== this.ratio || b.shape !== this.shape)) {
53
+ this.shape = morphAt(this.morph, this.ratio);
54
+ this.blended = { morph: this.morph, ratio: this.ratio, shape: this.shape };
55
+ // New bounds, which no invalidate tells of: the change of ratio did,
56
+ // but those it marked may have been measured since, with the old blend.
57
+ pickWork.changes++;
58
+ this.pickChanged(true);
59
+ }
60
+ return this.shape;
61
+ }
62
+ /**
63
+ * Flash draws the object again, its cache gone stale or not, for another
64
+ * scale, turn or skew, colour or filters; not when it only moves
65
+ * (`cache-replace`). The cache turned off counts only where a frame is
66
+ * drawn so: off and on again in between, it stands (the view's to tell).
67
+ */
68
+ invalidate(what) {
69
+ const stale = this.stale;
70
+ if (stale && what & TRANSFORM && !stale.stands(this)) {
71
+ this.stale = null;
72
+ what |= CONTENT;
73
+ }
74
+ super.invalidate(what);
75
+ }
76
+ }
77
+ /** What a bitmap cache was drawn of, and the look it was drawn with. */
78
+ export class StaleCache {
79
+ shape;
80
+ a;
81
+ b;
82
+ c;
83
+ d;
84
+ color;
85
+ filters;
86
+ constructor(shape, o) {
87
+ this.shape = shape;
88
+ ({ a: this.a, b: this.b, c: this.c, d: this.d } = o.matrix);
89
+ this.color = o.colorTransform;
90
+ this.filters = o.filters;
91
+ }
92
+ stands(o) {
93
+ const m = o.matrix;
94
+ return (m.a === this.a &&
95
+ m.b === this.b &&
96
+ m.c === this.c &&
97
+ m.d === this.d &&
98
+ sameColor(o.colorTransform, this.color) &&
99
+ sameFilters(o.filters, this.filters));
100
+ }
101
+ }
102
+ /**
103
+ * A place's filters are read anew at each move, the same or not. Those
104
+ * from a SWF are plain records; a script's displacement map holds its
105
+ * bitmap, so another list with one counts as other filters.
106
+ */
107
+ function sameFilters(a, b) {
108
+ if (a === b) {
109
+ return true;
110
+ }
111
+ if (a.length !== b.length || a.some((f) => f.kind === "displacementMap")) {
112
+ return false;
113
+ }
114
+ return JSON.stringify(a) === JSON.stringify(b);
115
+ }
116
+ /** Whether Flash draws `o` from a bitmap it keeps: cacheAsBitmap set, or filters. */
117
+ export function cached(o) {
118
+ return o.cachedAsBitmap || o.filters.length > 0;
119
+ }
120
+ function sameColor(a, b) {
121
+ const x = a ?? IDENTITY_COLOR;
122
+ const y = b ?? IDENTITY_COLOR;
123
+ return (x.rMul === y.rMul &&
124
+ x.gMul === y.gMul &&
125
+ x.bMul === y.bMul &&
126
+ x.aMul === y.aMul &&
127
+ x.rAdd === y.rAdd &&
128
+ x.gAdd === y.gAdd &&
129
+ x.bAdd === y.bAdd &&
130
+ x.aAdd === y.aAdd);
131
+ }