@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,373 @@
1
+ // Flash's 4×4 matrices: 16 float32 values in column-major order, as
2
+ // Matrix3D.rawData has them, and Flash's float arithmetic on them, each
3
+ // product and sum rounded to float32 (Ruffle's matrix3d.rs, which the
4
+ // corpus's matrix3d tests check against Flash). What Matrix3D, a display
5
+ // object's 3D transform and Utils3D share.
6
+ const f = Math.fround;
7
+ export function identity3D() {
8
+ return Float32Array.of(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
9
+ }
10
+ export function scale3D(x, y, z) {
11
+ return Float32Array.of(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
12
+ }
13
+ export function translation3D(x, y, z) {
14
+ return Float32Array.of(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1);
15
+ }
16
+ /** `lhs` × `rhs`: `rhs` applied first. */
17
+ export function multiply3D(lhs, rhs) {
18
+ const out = new Float32Array(16);
19
+ for (let column = 0; column < 4; column++) {
20
+ for (let row = 0; row < 4; row++) {
21
+ const c = column * 4;
22
+ out[c + row] = f(f(f(f(lhs[row] * rhs[c]) + f(lhs[4 + row] * rhs[c + 1])) + f(lhs[8 + row] * rhs[c + 2])) +
23
+ f(lhs[12 + row] * rhs[c + 3]));
24
+ }
25
+ }
26
+ return out;
27
+ }
28
+ function det3(m) {
29
+ return f(f(f(m[0] * f(f(m[4] * m[8]) - f(m[7] * m[5]))) - f(m[3] * f(f(m[1] * m[8]) - f(m[7] * m[2])))) +
30
+ f(m[6] * f(f(m[1] * m[5]) - f(m[4] * m[2]))));
31
+ }
32
+ /**
33
+ * Flash's determinant: without projection, the 3×3 part's with the last
34
+ * element folded in; otherwise expanded over the first row, which keeps
35
+ * its infinities as Flash's does.
36
+ */
37
+ export function determinant3D(m) {
38
+ if (m[3] === 0 && m[7] === 0 && m[11] === 0) {
39
+ return det3([
40
+ m[0],
41
+ m[1],
42
+ f(m[2] * m[15]),
43
+ m[4],
44
+ m[5],
45
+ f(m[6] * m[15]),
46
+ m[8],
47
+ m[9],
48
+ f(m[10] * m[15]),
49
+ ]);
50
+ }
51
+ const d0 = det3([m[5], m[6], m[7], m[9], m[10], m[11], m[13], m[14], m[15]]);
52
+ const d4 = det3([m[1], m[2], m[3], m[9], m[10], m[11], m[13], m[14], m[15]]);
53
+ const d8 = det3([m[1], m[2], m[3], m[5], m[6], m[7], m[13], m[14], m[15]]);
54
+ const d12 = det3([m[1], m[2], m[3], m[5], m[6], m[7], m[9], m[10], m[11]]);
55
+ return f(f(f(f(m[0] * d0) - f(m[4] * d4)) + f(m[8] * d8)) - f(m[12] * d12));
56
+ }
57
+ /**
58
+ * The inverse, or null for a matrix Flash takes for singular, its
59
+ * determinant within 1e-11 of 0 (Ruffle's). Gauss-Jordan elimination with
60
+ * partial pivoting in float32, each pivot row multiplied by the float32
61
+ * reciprocal of its pivot, which gives adl's inverses to the last bit
62
+ * where the cofactors' do not.
63
+ */
64
+ export function invert3D(m) {
65
+ if (!(Math.abs(determinant3D(m)) > 1e-11)) {
66
+ return null;
67
+ }
68
+ // Rows of the matrix and of the identity it becomes.
69
+ const a = [0, 1, 2, 3].map((r) => [0, 1, 2, 3].map((c) => m[c * 4 + r]));
70
+ const b = [0, 1, 2, 3].map((r) => [0, 1, 2, 3].map((c) => (r === c ? 1 : 0)));
71
+ for (let c = 0; c < 4; c++) {
72
+ let p = c;
73
+ for (let r = c + 1; r < 4; r++) {
74
+ if (Math.abs(a[r][c]) > Math.abs(a[p][c])) {
75
+ p = r;
76
+ }
77
+ }
78
+ [a[c], a[p]] = [a[p], a[c]];
79
+ [b[c], b[p]] = [b[p], b[c]];
80
+ if (a[c][c] === 0) {
81
+ return null;
82
+ }
83
+ const over = f(1 / a[c][c]);
84
+ for (let j = 0; j < 4; j++) {
85
+ a[c][j] = f(a[c][j] * over);
86
+ b[c][j] = f(b[c][j] * over);
87
+ }
88
+ for (let r = 0; r < 4; r++) {
89
+ const k = a[r][c];
90
+ if (r === c) {
91
+ continue;
92
+ }
93
+ for (let j = 0; j < 4; j++) {
94
+ a[r][j] = f(a[r][j] - f(k * a[c][j]));
95
+ b[r][j] = f(b[r][j] - f(k * b[c][j]));
96
+ }
97
+ }
98
+ }
99
+ return Float32Array.from({ length: 16 }, (_, i) => b[i % 4][i >> 2]);
100
+ }
101
+ /**
102
+ * A rotation by `degrees` about `axis`, around `pivot`, as adl gives it to
103
+ * the last bit: the axis made a unit one in float32, the rotation's
104
+ * elements in doubles, and the pivot's translations multiplied on in
105
+ * float32. Before SWF 13 Flash took the axis as it came, not made a unit
106
+ * one first, which scales what a longer axis turns.
107
+ */
108
+ export function rotation3D(degrees, axis, [px, py, pz], unit = true) {
109
+ let [x, y, z] = axis;
110
+ if (unit) {
111
+ const length = f(Math.sqrt(f(f(f(x * x) + f(y * y)) + f(z * z))));
112
+ x = f(x / length);
113
+ y = f(y / length);
114
+ z = f(z / length);
115
+ }
116
+ // Rounded as Flash's, multiplied before the division.
117
+ const radians = (degrees * Math.PI) / 180;
118
+ const c = Math.cos(radians);
119
+ const s = Math.sin(radians);
120
+ const t = 1 - c;
121
+ const r = Float32Array.of(c + t * x * x, t * x * y + s * z, t * x * z - s * y, 0, t * x * y - s * z, c + t * y * y, t * y * z + s * x, 0, t * x * z + s * y, t * y * z - s * x, c + t * z * z, 0, 0, 0, 0, 1);
122
+ if (px === 0 && py === 0 && pz === 0) {
123
+ return r;
124
+ }
125
+ return multiply3D(translation3D(px, py, pz), multiply3D(r, translation3D(-px, -py, -pz)));
126
+ }
127
+ /**
128
+ * Translation × rotation × scale, the order observable with components
129
+ * that are not finite. Euler angles are in radians, about x, then y, then z.
130
+ */
131
+ export function compose3D([tx, ty, tz], [rx, ry, rz, rw], [sx, sy, sz], orientation) {
132
+ const r = new Float64Array(16);
133
+ if (orientation === "eulerAngles") {
134
+ // In float32, sin y times cos z and sin z taken first, as the corpus's matrix3d_compose has Flash's.
135
+ const cx = f(Math.cos(rx));
136
+ const cy = f(Math.cos(ry));
137
+ const cz = f(Math.cos(rz));
138
+ const sinX = f(Math.sin(rx));
139
+ const sinY = f(Math.sin(ry));
140
+ const sinZ = f(Math.sin(rz));
141
+ const yz = f(sinY * cz);
142
+ const yZ = f(sinY * sinZ);
143
+ r[0] = f(cy * cz);
144
+ r[1] = f(cy * sinZ);
145
+ r[2] = -sinY;
146
+ r[4] = f(f(sinX * yz) - f(cx * sinZ));
147
+ r[5] = f(f(sinX * yZ) + f(cx * cz));
148
+ r[6] = f(sinX * cy);
149
+ r[8] = f(f(cx * yz) + f(sinX * sinZ));
150
+ r[9] = f(f(cx * yZ) - f(sinX * cz));
151
+ r[10] = f(cx * cy);
152
+ }
153
+ else {
154
+ let x = rx;
155
+ let y = ry;
156
+ let z = rz;
157
+ let w = rw;
158
+ if (orientation === "axisAngle") {
159
+ const half = Math.sin(w / 2);
160
+ x *= half;
161
+ y *= half;
162
+ z *= half;
163
+ w = Math.cos(w / 2);
164
+ }
165
+ r[0] = 1 - 2 * y * y - 2 * z * z;
166
+ r[1] = 2 * x * y + 2 * w * z;
167
+ r[2] = 2 * x * z - 2 * w * y;
168
+ r[4] = 2 * x * y - 2 * w * z;
169
+ r[5] = 1 - 2 * x * x - 2 * z * z;
170
+ r[6] = 2 * y * z + 2 * w * x;
171
+ r[8] = 2 * x * z + 2 * w * y;
172
+ r[9] = 2 * y * z - 2 * w * x;
173
+ r[10] = 1 - 2 * x * x - 2 * y * y;
174
+ }
175
+ r[15] = 1;
176
+ // The translation put in its column, not multiplied on: an infinite scale's column is then
177
+ // infinite where the rotation's is 1, and NaN only where it is 0, as Flash's is.
178
+ const m = multiply3D(new Float32Array(r), scale3D(sx, sy, sz));
179
+ m[12] = f(tx);
180
+ m[13] = f(ty);
181
+ m[14] = f(tz);
182
+ return m;
183
+ }
184
+ function dot3(a, b) {
185
+ return f(f(f(a[0] * b[0]) + f(a[1] * b[1])) + f(a[2] * b[2]));
186
+ }
187
+ /** `a` less `k` times `b`. */
188
+ function less3(a, k, b) {
189
+ return a.map((x, i) => f(x - f(k * b[i])));
190
+ }
191
+ /**
192
+ * Translation, rotation and scale, each [x, y, z, w], as Matrix3D.decompose
193
+ * gives them: the columns made orthonormal one after another, in float32,
194
+ * each scale what was left of its column, so a skew goes, and a mirror is
195
+ * the z scale's sign. The rotation is read from what is left, as OpenFL's
196
+ * decompose reads it (Ruffle's), the axis and angle Flash's own way.
197
+ */
198
+ export function decompose3D(raw, orientation) {
199
+ const translation = [raw[12], raw[13], raw[14], 0];
200
+ const c0 = [raw[0], raw[1], raw[2]];
201
+ const scaleX = f(Math.sqrt(dot3(c0, c0)));
202
+ const u0 = c0.map((x) => f(x / scaleX));
203
+ const c1 = less3([raw[4], raw[5], raw[6]], dot3(u0, [raw[4], raw[5], raw[6]]), u0);
204
+ const scaleY = f(Math.sqrt(dot3(c1, c1)));
205
+ const u1 = c1.map((x) => f(x / scaleY));
206
+ let c2 = [raw[8], raw[9], raw[10]];
207
+ c2 = less3(c2, dot3(u0, c2), u0);
208
+ c2 = less3(c2, dot3(u1, c2), u1);
209
+ let scaleZ = f(Math.sqrt(dot3(c2, c2)));
210
+ let u2 = c2.map((x) => f(x / scaleZ));
211
+ const cross = [
212
+ u1[1] * u2[2] - u1[2] * u2[1],
213
+ u1[2] * u2[0] - u1[0] * u2[2],
214
+ u1[0] * u2[1] - u1[1] * u2[0],
215
+ ];
216
+ if (u0[0] * cross[0] + u0[1] * cross[1] + u0[2] * cross[2] < 0) {
217
+ scaleZ = -scaleZ;
218
+ u2 = u2.map((x) => -x);
219
+ }
220
+ const m = [...u0, 0, ...u1, 0, ...u2, 0];
221
+ const rotation = [0, 0, 0, 0];
222
+ if (orientation === "axisAngle") {
223
+ rotation[3] = f(Math.acos(f(f(f(f(m[0] + m[5]) + m[10]) - 1) / 2)));
224
+ const twice = f(2 * f(Math.sin(rotation[3])));
225
+ if (twice !== 0) {
226
+ rotation[0] = f(f(m[6] - m[9]) / twice);
227
+ rotation[1] = f(f(m[8] - m[2]) / twice);
228
+ rotation[2] = f(f(m[1] - m[4]) / twice);
229
+ }
230
+ }
231
+ else if (orientation === "quaternion") {
232
+ const trace = m[0] + m[5] + m[10];
233
+ if (trace > 0) {
234
+ rotation[3] = Math.sqrt(1 + trace) / 2;
235
+ rotation[0] = (m[6] - m[9]) / (4 * rotation[3]);
236
+ rotation[1] = (m[8] - m[2]) / (4 * rotation[3]);
237
+ rotation[2] = (m[1] - m[4]) / (4 * rotation[3]);
238
+ }
239
+ else if (m[0] > m[5] && m[0] > m[10]) {
240
+ rotation[0] = Math.sqrt(1 + m[0] - m[5] - m[10]) / 2;
241
+ rotation[3] = (m[6] - m[9]) / (4 * rotation[0]);
242
+ rotation[1] = (m[1] + m[4]) / (4 * rotation[0]);
243
+ rotation[2] = (m[8] + m[2]) / (4 * rotation[0]);
244
+ }
245
+ else if (m[5] > m[10]) {
246
+ rotation[1] = Math.sqrt(1 + m[5] - m[0] - m[10]) / 2;
247
+ rotation[0] = (m[1] + m[4]) / (4 * rotation[1]);
248
+ rotation[3] = (m[8] - m[2]) / (4 * rotation[1]);
249
+ rotation[2] = (m[6] + m[9]) / (4 * rotation[1]);
250
+ }
251
+ else {
252
+ rotation[2] = Math.sqrt(1 + m[10] - m[0] - m[5]) / 2;
253
+ rotation[0] = (m[8] + m[2]) / (4 * rotation[2]);
254
+ rotation[1] = (m[6] + m[9]) / (4 * rotation[2]);
255
+ rotation[3] = (m[1] - m[4]) / (4 * rotation[2]);
256
+ }
257
+ }
258
+ else {
259
+ rotation[1] = f(Math.asin(-m[2]));
260
+ if (m[2] !== 1 && m[2] !== -1) {
261
+ rotation[0] = f(Math.atan2(m[6], m[10]));
262
+ rotation[2] = f(Math.atan2(m[1], m[0]));
263
+ }
264
+ else {
265
+ rotation[0] = f(Math.atan2(m[4], m[5]));
266
+ }
267
+ }
268
+ return [translation, rotation, [scaleX, scaleY, scaleZ, 0]];
269
+ }
270
+ /** `m` applied to (x, y, z, 1), in float32 as Matrix3D.transformVector's; `w` 0 leaves out the translation. */
271
+ export function transform3D(m, x0, y0, z0, w = 1) {
272
+ const x = f(x0);
273
+ const y = f(y0);
274
+ const z = f(z0);
275
+ const out = [];
276
+ for (let row = 0; row < 4; row++) {
277
+ const sum = f(f(f(m[row] * x) + f(m[4 + row] * y)) + f(m[8 + row] * z));
278
+ out.push(w ? f(sum + m[12 + row]) : sum);
279
+ }
280
+ return out;
281
+ }
282
+ /**
283
+ * Both taken apart as decompose takes them, the translations and scales
284
+ * lerped and the rotations slerped, and put together with the scale
285
+ * applied after the rotation, as adl does: a scale that is not uniform
286
+ * then stretches the turned axes (the `three-d` case). Ruffle's corpus
287
+ * has the scale dropped, which adl does not.
288
+ */
289
+ export function interpolate3D(from, to, percent) {
290
+ const [t0, q0, s0] = decompose3D(from, "quaternion");
291
+ const [t1, q1, s1] = decompose3D(to, "quaternion");
292
+ const lerp = (a, b) => [0, 1, 2].map((i) => a[i] + (b[i] - a[i]) * percent);
293
+ let dot = q0[0] * q1[0] + q0[1] * q1[1] + q0[2] * q1[2] + q0[3] * q1[3];
294
+ let end = q1;
295
+ if (dot < 0) {
296
+ dot = -dot;
297
+ end = q1.map((c) => -c);
298
+ }
299
+ let k0 = 1 - percent;
300
+ let k1 = percent;
301
+ if (dot <= 0.9995) {
302
+ const theta = Math.acos(dot);
303
+ const sinTheta = Math.sin(theta);
304
+ k0 = Math.sin((1 - percent) * theta) / sinTheta;
305
+ k1 = Math.sin(percent * theta) / sinTheta;
306
+ }
307
+ let r = q0.map((c, i) => c * k0 + end[i] * k1);
308
+ const length = Math.hypot(...r);
309
+ r = length === 0 ? [0, 0, 0, 1] : r.map((c) => c / length);
310
+ const [sx, sy, sz] = lerp(s0, s1);
311
+ const turned = compose3D(lerp(t0, t1), r, [1, 1, 1], "quaternion");
312
+ return multiply3D(translation3D(turned[12], turned[13], turned[14]), multiply3D(scale3D(sx, sy, sz), turned.map((v, i) => (i >= 12 && i < 15 ? 0 : v))));
313
+ }
314
+ /**
315
+ * `v` made a unit one, times the float32 reciprocal of its length, as adl
316
+ * makes even a denormal one; null for one of no length in float32.
317
+ */
318
+ function unit3(v) {
319
+ const squared = dot3(v, v);
320
+ const k = f(1 / Math.sqrt(squared));
321
+ return squared === 0 ? null : v.map((x) => f(x * k));
322
+ }
323
+ /** In doubles: adl's side of an `at` and `up` nearly parallel comes out so, where float32's is none. */
324
+ function cross3(a, b) {
325
+ return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
326
+ }
327
+ /** A rotation whose columns are `x`, `y` and `z`. */
328
+ function columns3D(x, y, z) {
329
+ return Float32Array.of(...x, 0, ...y, 0, ...z, 0, 0, 0, 0, 1);
330
+ }
331
+ /**
332
+ * Matrix3D.pointAt as adl has it, to a float32 rounding or two; Ruffle and
333
+ * Shumway leave it a stub. The object-relative `at` turns to face `pos`
334
+ * from the matrix's position, and `up` to the world's (0, -1, 0), each
335
+ * made square to the other; left out they are (0, 1, 0) and (0, 0, 1), not
336
+ * the documented (0, 0, -1) and (0, -1, 0), which turn it otherwise. With
337
+ * M's linear part K · R · S, R and S as decompose finds them and K the
338
+ * skew it drops, it becomes K · L · S · Q: L the facing frame, x across,
339
+ * y up and z toward `pos`, and Q taking `at` and `up` to its z and y. The
340
+ * translation stays and the projection row goes. Null, the matrix left as
341
+ * it was, where a direction has no length in float32: `pos` at the
342
+ * position or along the world's up, `at` zero, or `up` zero or parallel
343
+ * to it. A NaN anywhere makes every element NaN, as in adl.
344
+ */
345
+ export function pointAt3D(m, pos, at, up) {
346
+ const toward = unit3(pos.map((v, i) => f(f(v) - m[12 + i])));
347
+ const across = toward && unit3(cross3(toward, [0, -1, 0]));
348
+ const facing = unit3(at.map(f));
349
+ const side = facing && unit3(cross3(up.map(f), facing));
350
+ if (!toward || !across || !facing || !side) {
351
+ return null;
352
+ }
353
+ const above = cross3(across, toward);
354
+ const top = cross3(facing, side);
355
+ const frame = columns3D(across.map((v) => -v), above, toward);
356
+ // Rows, not columns: the inverse of the rotation taking z and y to `at` and `up`.
357
+ const object = columns3D([side[0], top[0], facing[0]], [side[1], top[1], facing[1]], [side[2], top[2], facing[2]]);
358
+ const [, rotation, scale] = decompose3D(m, "eulerAngles");
359
+ const linear = Float32Array.from(m);
360
+ linear.fill(0, 12, 15);
361
+ linear[3] = linear[7] = linear[11] = 0;
362
+ linear[15] = 1;
363
+ const unskewed = invert3D(compose3D([0, 0, 0], rotation, scale, "eulerAngles"));
364
+ const skew = unskewed ? multiply3D(linear, unskewed) : identity3D();
365
+ const out = multiply3D(skew, multiply3D(frame, multiply3D(scale3D(scale[0], scale[1], scale[2]), object)));
366
+ if (out.some(Number.isNaN)) {
367
+ return out.fill(Number.NaN);
368
+ }
369
+ out[12] = m[12];
370
+ out[13] = m[13];
371
+ out[14] = m[14];
372
+ return out;
373
+ }
@@ -0,0 +1,226 @@
1
+ import { boundsOf, shapeLayers } from "./shapes.js";
2
+ // Grow only after a ratio returns following eviction: longer looping tweens
3
+ // otherwise rebuild every frame, while fresh ratios gain nothing from more space.
4
+ const KEPT_BLENDS = 64;
5
+ const MOST_BLENDS = 256;
6
+ const histories = new WeakMap();
7
+ /**
8
+ * The shape `character` is at `ratio`, 0 its start to 65535 its end: made
9
+ * the first time it is asked for and kept while it is among the morph's
10
+ * latest, as a tween asks for a new ratio on each frame.
11
+ */
12
+ export function morphAt(character, ratio) {
13
+ const blends = character.blends;
14
+ let shape = blends.get(ratio);
15
+ if (shape) {
16
+ // Last in the map's order, the most recently asked for.
17
+ blends.delete(ratio);
18
+ blends.set(ratio, shape);
19
+ return shape;
20
+ }
21
+ let history = histories.get(character);
22
+ if (blends.size === 0 && history) {
23
+ histories.delete(character);
24
+ history = undefined;
25
+ }
26
+ if (history && history.limit < MOST_BLENDS && history.evicted.delete(ratio)) {
27
+ history.limit *= 2;
28
+ history.evicted.clear();
29
+ }
30
+ const blended = blend(character.morph, ratio / 65535);
31
+ shape = {
32
+ type: "shape",
33
+ id: character.id,
34
+ shape: boundsOf(blended),
35
+ layers: shapeLayers(blended, character.bitmap),
36
+ };
37
+ blends.set(ratio, shape);
38
+ const limit = history?.limit ?? KEPT_BLENDS;
39
+ if (blends.size > limit) {
40
+ const oldest = blends.keys().next().value;
41
+ blends.delete(oldest);
42
+ if (limit < MOST_BLENDS) {
43
+ if (!history) {
44
+ history = { limit, evicted: new Set() };
45
+ histories.set(character, history);
46
+ }
47
+ history.evicted.add(oldest);
48
+ if (history.evicted.size > MOST_BLENDS) {
49
+ history.evicted.delete(history.evicted.keys().next().value);
50
+ }
51
+ }
52
+ }
53
+ return shape;
54
+ }
55
+ const mix = (a, b, t) => a + (b - a) * t;
56
+ /** Each channel of two 0xAARRGGBB colours mixed, as a byte. */
57
+ function mixColor(a, b, t) {
58
+ let out = 0;
59
+ for (let shift = 24; shift >= 0; shift -= 8) {
60
+ const channel = Math.round(mix((a >>> shift) & 0xff, (b >>> shift) & 0xff, t));
61
+ out = out * 256 + channel;
62
+ }
63
+ return out;
64
+ }
65
+ function mixMatrix(a, b, t) {
66
+ return {
67
+ a: mix(a.a, b.a, t),
68
+ b: mix(a.b, b.b, t),
69
+ c: mix(a.c, b.c, t),
70
+ d: mix(a.d, b.d, t),
71
+ tx: mix(a.tx, b.tx, t),
72
+ ty: mix(a.ty, b.ty, t),
73
+ };
74
+ }
75
+ function mixRect(a, b, t) {
76
+ return {
77
+ xMin: mix(a.xMin, b.xMin, t),
78
+ xMax: mix(a.xMax, b.xMax, t),
79
+ yMin: mix(a.yMin, b.yMin, t),
80
+ yMax: mix(a.yMax, b.yMax, t),
81
+ };
82
+ }
83
+ function mixGradient(a, b, t) {
84
+ return {
85
+ matrix: mixMatrix(a.matrix, b.matrix, t),
86
+ spread: a.spread,
87
+ interpolation: a.interpolation,
88
+ stops: a.stops.map((stop, i) => {
89
+ const other = b.stops[i] ?? stop;
90
+ return {
91
+ ratio: Math.round(mix(stop.ratio, other.ratio, t)),
92
+ color: mixColor(stop.color, other.color, t),
93
+ };
94
+ }),
95
+ focal: mix(a.focal, b.focal, t),
96
+ };
97
+ }
98
+ /** Two fills of one MORPHFILLSTYLE, which share their type. */
99
+ function mixFill(a, b, t) {
100
+ if (a.type === "solid" && b.type === "solid") {
101
+ return { type: "solid", color: mixColor(a.color, b.color, t) };
102
+ }
103
+ if (a.type === "bitmap" && b.type === "bitmap") {
104
+ return { ...a, matrix: mixMatrix(a.matrix, b.matrix, t) };
105
+ }
106
+ if (a.type !== "solid" && a.type !== "bitmap" && b.type === a.type) {
107
+ return { type: a.type, gradient: mixGradient(a.gradient, b.gradient, t) };
108
+ }
109
+ return a;
110
+ }
111
+ function mixLine(a, b, t) {
112
+ return {
113
+ ...a,
114
+ width: mix(a.width, b.width, t),
115
+ color: mixColor(a.color, b.color, t),
116
+ fill: a.fill && b.fill ? mixFill(a.fill, b.fill, t) : a.fill,
117
+ };
118
+ }
119
+ const NO_EDGE = { type: "line", dx: 0, dy: 0 };
120
+ /**
121
+ * An edge from `pen` in absolute twips: its control point, halfway along a straight one, and
122
+ * anchor.
123
+ */
124
+ function absolute(e, pen) {
125
+ if (e.type === "line") {
126
+ const anchor = { x: pen.x + e.dx, y: pen.y + e.dy };
127
+ return {
128
+ control: { x: (pen.x + anchor.x) / 2, y: (pen.y + anchor.y) / 2 },
129
+ anchor,
130
+ straight: true,
131
+ };
132
+ }
133
+ const control = { x: pen.x + e.cx, y: pen.y + e.cy };
134
+ return { control, anchor: { x: control.x + e.ax, y: control.y + e.ay }, straight: false };
135
+ }
136
+ /**
137
+ * Two points mixed, to the twip: whole twips keep the pen's sums exact, and closed paths closed.
138
+ */
139
+ const mixPoint = (a, b, t) => ({
140
+ x: Math.round(mix(a.x, b.x, t)),
141
+ y: Math.round(mix(a.y, b.y, t)),
142
+ });
143
+ /**
144
+ * The morph at `t`, 0 to 1. The ends' edges pair in order, a straight
145
+ * one with a curve as a curve, and their points are mixed where they lie,
146
+ * not their deltas. A style change is the start's, its move mixed with
147
+ * the end's where the end has one there, else with the end's pen; a move
148
+ * only the end has moves the pen from the start's.
149
+ */
150
+ export function blend(morph, t) {
151
+ const records = [];
152
+ const start = morph.start;
153
+ const end = morph.end;
154
+ let startPen = { x: 0, y: 0 };
155
+ let endPen = { x: 0, y: 0 };
156
+ let pen = { x: 0, y: 0 };
157
+ let i = 0;
158
+ let j = 0;
159
+ while (i < start.length) {
160
+ const s = start[i];
161
+ const e = end[j];
162
+ if (s.type === "style") {
163
+ const endStyle = e?.type === "style" ? e : null;
164
+ if (endStyle) {
165
+ j++;
166
+ endPen = endStyle.moveTo ?? endPen;
167
+ }
168
+ startPen = s.moveTo ?? startPen;
169
+ const moves = s.moveTo !== null || endStyle?.moveTo;
170
+ if (moves) {
171
+ pen = mixPoint(startPen, endPen, t);
172
+ }
173
+ records.push({ ...s, moveTo: moves ? pen : null });
174
+ i++;
175
+ continue;
176
+ }
177
+ if (e?.type === "style") {
178
+ if (e.moveTo) {
179
+ endPen = e.moveTo;
180
+ pen = mixPoint(startPen, endPen, t);
181
+ records.push({
182
+ type: "style",
183
+ moveTo: pen,
184
+ fill0: null,
185
+ fill1: null,
186
+ line: null,
187
+ styles: null,
188
+ });
189
+ }
190
+ j++;
191
+ continue;
192
+ }
193
+ const a = absolute(s, startPen);
194
+ const b = absolute(e ?? NO_EDGE, endPen);
195
+ const anchor = mixPoint(a.anchor, b.anchor, t);
196
+ if (a.straight && b.straight) {
197
+ records.push({ type: "line", dx: anchor.x - pen.x, dy: anchor.y - pen.y });
198
+ }
199
+ else {
200
+ const control = mixPoint(a.control, b.control, t);
201
+ records.push({
202
+ type: "curve",
203
+ cx: control.x - pen.x,
204
+ cy: control.y - pen.y,
205
+ ax: anchor.x - control.x,
206
+ ay: anchor.y - control.y,
207
+ });
208
+ }
209
+ startPen = a.anchor;
210
+ endPen = b.anchor;
211
+ pen = anchor;
212
+ i++;
213
+ j++;
214
+ }
215
+ return {
216
+ id: morph.id,
217
+ bounds: mixRect(morph.startBounds, morph.endBounds, t),
218
+ edgeBounds: morph.startEdgeBounds && morph.endEdgeBounds
219
+ ? mixRect(morph.startEdgeBounds, morph.endEdgeBounds, t)
220
+ : null,
221
+ fills: morph.fills.map((f) => mixFill(f.start, f.end, t)),
222
+ lines: morph.lines.map((l) => mixLine(l.start, l.end, t)),
223
+ records,
224
+ truncated: morph.truncated,
225
+ };
226
+ }