swf2js 0.1.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (416) hide show
  1. package/README.md +81 -14
  2. package/package.json +11 -7
  3. package/studio/actionscript-roundtrip.test.js +54 -0
  4. package/studio/actionscript-scripts.test.js +169 -0
  5. package/studio/animated-image.test.js +137 -0
  6. package/studio/arithmetic.test.js +16 -0
  7. package/studio/as3-import.test.js +110 -0
  8. package/studio/audio-info.test.js +44 -0
  9. package/studio/components.test.js +152 -0
  10. package/studio/document-editing.test.js +92 -0
  11. package/studio/examples/01-space-mission.json +1628 -0
  12. package/studio/examples/02-clockwork-vault.json +1079 -0
  13. package/studio/examples/03-neon-synth.json +1364 -0
  14. package/studio/examples/04-kinetic-poster.json +923 -0
  15. package/studio/examples/05-signal-relay.json +1131 -0
  16. package/studio/examples/06-calculator.json +564 -0
  17. package/studio/frame-editing.test.js +129 -0
  18. package/studio/frame-events.test.js +117 -0
  19. package/studio/groups.test.js +88 -0
  20. package/studio/index.html +962 -0
  21. package/studio/interaction-triggers.test.js +37 -0
  22. package/studio/linked-actions.test.js +48 -0
  23. package/studio/lottie.test.js +208 -0
  24. package/studio/masks.test.js +43 -0
  25. package/studio/media-assets.test.js +62 -0
  26. package/studio/paint-tools.test.js +60 -0
  27. package/studio/playback.test.js +17 -0
  28. package/studio/project-io.test.js +405 -0
  29. package/studio/project-preview.test.js +475 -0
  30. package/studio/scene-transition.test.js +32 -0
  31. package/studio/server/archive-companions.js +27 -0
  32. package/studio/server/as3-library.js +91 -0
  33. package/studio/server/assets.js +162 -0
  34. package/studio/server/audio-info.js +82 -0
  35. package/studio/server/font-files.js +332 -0
  36. package/studio/server/http.js +135 -0
  37. package/studio/server/linked-actions.js +93 -0
  38. package/studio/server/png-decode.js +1 -0
  39. package/studio/server/project-movie.js +1164 -0
  40. package/studio/server/project-preview.js +152 -0
  41. package/studio/server/projects.js +370 -0
  42. package/studio/server/report.js +29 -0
  43. package/studio/server/routes.js +93 -0
  44. package/studio/server/swf-authoring.js +90 -0
  45. package/studio/server/swf-control-runtime.as +513 -0
  46. package/studio/server/swf-controls.js +119 -0
  47. package/studio/server/swf-export.js +293 -0
  48. package/studio/server/swf-import.js +1675 -0
  49. package/studio/server/swf-morphs.js +64 -0
  50. package/studio/server/swf-routes.js +42 -0
  51. package/studio/server/swf-streams.js +80 -0
  52. package/studio/server/swf-transition-runtime.as +52 -0
  53. package/studio/server/tween-recovery.js +106 -0
  54. package/studio/server-api.test.js +283 -0
  55. package/studio/server.js +320 -0
  56. package/studio/src/animated-image.js +423 -0
  57. package/studio/src/appearance-inspector.js +63 -0
  58. package/studio/src/arithmetic.js +50 -0
  59. package/studio/src/authored-controls.js +42 -0
  60. package/studio/src/busy.js +41 -0
  61. package/studio/src/canvas.js +430 -0
  62. package/studio/src/clipper-browser.js +2 -0
  63. package/studio/src/color-transform.js +38 -0
  64. package/studio/src/component-inspector.js +126 -0
  65. package/studio/src/components.js +268 -0
  66. package/studio/src/display-frame.js +262 -0
  67. package/studio/src/document-editing.js +69 -0
  68. package/studio/src/event-editor.js +150 -0
  69. package/studio/src/frame-editing.js +150 -0
  70. package/studio/src/frame-events.js +128 -0
  71. package/studio/src/frame-image.js +28 -0
  72. package/studio/src/groups.js +125 -0
  73. package/studio/src/handler-editor.js +122 -0
  74. package/studio/src/history.js +83 -0
  75. package/studio/src/imported-paths.js +99 -0
  76. package/studio/src/index.js +3582 -0
  77. package/studio/src/interaction-triggers.js +42 -0
  78. package/studio/src/json-patch.js +77 -0
  79. package/studio/src/layer-icons.js +25 -0
  80. package/studio/src/lottie-export.js +948 -0
  81. package/studio/src/lottie-import.js +1138 -0
  82. package/studio/src/masks.js +69 -0
  83. package/studio/src/media-assets.js +188 -0
  84. package/studio/src/media-library.js +193 -0
  85. package/studio/src/model.js +431 -0
  86. package/studio/src/numeric-fields.js +46 -0
  87. package/studio/src/object-list.js +57 -0
  88. package/studio/src/paint-tools.js +76 -0
  89. package/studio/src/placement-effects.js +74 -0
  90. package/studio/src/playback.js +10 -0
  91. package/studio/src/preview-audio.js +64 -0
  92. package/studio/src/preview-interactions.js +106 -0
  93. package/studio/src/preview-recorder.js +335 -0
  94. package/studio/src/preview-surface.js +338 -0
  95. package/studio/src/project-io.js +905 -0
  96. package/studio/src/project-session.js +375 -0
  97. package/studio/src/projects-dialog.js +319 -0
  98. package/studio/src/scene-transition.js +129 -0
  99. package/studio/src/script-editor.js +175 -0
  100. package/studio/src/script-references.js +74 -0
  101. package/studio/src/scripted-controls.js +146 -0
  102. package/studio/src/scripts.js +185 -0
  103. package/studio/src/stage-guides.js +101 -0
  104. package/studio/src/svg-animation.js +416 -0
  105. package/studio/src/svg-context.js +522 -0
  106. package/studio/src/svg-frame.js +413 -0
  107. package/studio/src/svg-import.js +1208 -0
  108. package/studio/src/swf-recording.js +104 -0
  109. package/studio/src/symbol-library.js +39 -0
  110. package/studio/src/symbols.js +62 -0
  111. package/studio/src/text-fields.js +58 -0
  112. package/studio/src/theme.js +43 -0
  113. package/studio/src/timeline.js +321 -0
  114. package/studio/src/vector-cut.js +103 -0
  115. package/studio/src/vector-geometry.js +254 -0
  116. package/studio/src/vector-style.js +146 -0
  117. package/studio/src/video-encode.js +84 -0
  118. package/studio/src/video-export.js +331 -0
  119. package/studio/src/video-mux.js +339 -0
  120. package/studio/src/video-playback.js +281 -0
  121. package/studio/src/workspace.js +344 -0
  122. package/studio/stroke-style.test.js +119 -0
  123. package/studio/styles.css +1547 -0
  124. package/studio/svg-export.test.js +162 -0
  125. package/studio/svg-import.test.js +318 -0
  126. package/studio/swf-authoring.test.js +140 -0
  127. package/studio/swf-export.test.js +324 -0
  128. package/studio/swf-import.test.js +489 -0
  129. package/studio/symbols.test.js +68 -0
  130. package/studio/tests/accessibility-interactions.mjs +138 -0
  131. package/studio/tests/appearance-interactions.mjs +103 -0
  132. package/studio/tests/control-interactions.mjs +60 -0
  133. package/studio/tests/event-interactions.mjs +117 -0
  134. package/studio/tests/external-resources.mjs +174 -0
  135. package/studio/tests/frame-image.mjs +71 -0
  136. package/studio/tests/html-export.mjs +68 -0
  137. package/studio/tests/import-files.mjs +131 -0
  138. package/studio/tests/lottie.mjs +125 -0
  139. package/studio/tests/mask-interactions.mjs +148 -0
  140. package/studio/tests/media-interactions.mjs +109 -0
  141. package/studio/tests/paint-interactions.mjs +64 -0
  142. package/studio/tests/project-interactions.mjs +244 -0
  143. package/studio/tests/script-interactions.mjs +178 -0
  144. package/studio/tests/scripted-control-interactions.mjs +107 -0
  145. package/studio/tests/svg-export.mjs +149 -0
  146. package/studio/tests/text-field-interactions.mjs +64 -0
  147. package/studio/tests/theme-interactions.mjs +53 -0
  148. package/studio/tests/timeline-browser.mjs +507 -0
  149. package/studio/tests/transition-interactions.mjs +94 -0
  150. package/studio/tests/trigger-interactions.mjs +93 -0
  151. package/studio/tests/video-export.mjs +243 -0
  152. package/studio/tests/workspace-interactions.mjs +226 -0
  153. package/studio/tween-recovery.test.js +31 -0
  154. package/studio/vector-style.test.js +56 -0
  155. package/studio/video-export.test.js +326 -0
  156. package/studiospec/actionscript.md +88 -0
  157. package/studiospec/architecture.md +378 -0
  158. package/studiospec/controls.md +100 -0
  159. package/studiospec/file-support.md +268 -0
  160. package/studiospec/lottie.md +69 -0
  161. package/studiospec/requirements.md +135 -0
  162. package/studiospec/stroke-style.md +95 -0
  163. package/studiospec/svg-export.md +83 -0
  164. package/studiospec/svg-import.md +139 -0
  165. package/studiospec/swooflib-integration.md +115 -0
  166. package/studiospec/tasks.md +573 -0
  167. package/studiospec/video-export.md +127 -0
  168. package/swf2js/__tests__/actionscript.test.js +1609 -0
  169. package/swf2js/__tests__/adpcm-audio.test.js +43 -0
  170. package/swf2js/__tests__/as2-compiler.test.js +153 -0
  171. package/swf2js/__tests__/as3-mixed-depth.test.js +498 -0
  172. package/swf2js/__tests__/authored-sprite-hit.test.js +118 -0
  173. package/swf2js/__tests__/authored-sprite-sizing.test.js +164 -0
  174. package/swf2js/__tests__/avm1-action-prefix.test.js +134 -0
  175. package/swf2js/__tests__/avm1-attach-movie.test.js +1151 -0
  176. package/swf2js/__tests__/avm1-boxhead-budget.test.js +73 -0
  177. package/swf2js/__tests__/avm1-cfg-bubble-tanks.test.js +101 -0
  178. package/swf2js/__tests__/avm1-cfg-mario-kart.test.js +184 -0
  179. package/swf2js/__tests__/avm1-cfg-mario.test.js +31 -0
  180. package/swf2js/__tests__/avm1-cfg-pacman.test.js +49 -0
  181. package/swf2js/__tests__/avm1-checkers-gameplay.test.js +122 -0
  182. package/swf2js/__tests__/avm1-clip-actions.test.js +2002 -0
  183. package/swf2js/__tests__/avm1-clone-drag.test.js +626 -0
  184. package/swf2js/__tests__/avm1-decompiler.test.js +102 -0
  185. package/swf2js/__tests__/avm1-dynamic-locals.test.js +159 -0
  186. package/swf2js/__tests__/avm1-formal-parameters.test.js +71 -0
  187. package/swf2js/__tests__/avm1-key-events.test.js +52 -0
  188. package/swf2js/__tests__/avm1-load-bitmap.test.js +75 -0
  189. package/swf2js/__tests__/avm1-loading-host-actions.test.js +764 -0
  190. package/swf2js/__tests__/avm1-multibyte-strings.test.js +63 -0
  191. package/swf2js/__tests__/avm1-pacman-gameplay.test.js +115 -0
  192. package/swf2js/__tests__/avm1-shape-hittest.test.js +311 -0
  193. package/swf2js/__tests__/avm1-shared-bodies.test.js +57 -0
  194. package/swf2js/__tests__/avm1-shared-runtime.test.js +1364 -0
  195. package/swf2js/__tests__/avm1-snake-gameplay.test.js +139 -0
  196. package/swf2js/__tests__/avm1-super.test.js +70 -0
  197. package/swf2js/__tests__/avm1-target-path.test.js +325 -0
  198. package/swf2js/__tests__/avm1-try.test.js +229 -0
  199. package/swf2js/__tests__/avm2-activation-closures.test.js +65 -0
  200. package/swf2js/__tests__/avm2-applytype.test.js +180 -0
  201. package/swf2js/__tests__/avm2-call-ops.test.js +232 -0
  202. package/swf2js/__tests__/avm2-callsuperid.test.js +231 -0
  203. package/swf2js/__tests__/avm2-class-initializer.test.js +219 -0
  204. package/swf2js/__tests__/avm2-custom-namespace.test.js +139 -0
  205. package/swf2js/__tests__/avm2-describe-type.test.js +96 -0
  206. package/swf2js/__tests__/avm2-dictionary.test.js +96 -0
  207. package/swf2js/__tests__/avm2-domain-memory.test.js +332 -0
  208. package/swf2js/__tests__/avm2-e4x.test.js +326 -0
  209. package/swf2js/__tests__/avm2-exceptions.test.js +81 -0
  210. package/swf2js/__tests__/avm2-findprop.test.js +110 -0
  211. package/swf2js/__tests__/avm2-getlex.test.js +166 -0
  212. package/swf2js/__tests__/avm2-global-slot.test.js +106 -0
  213. package/swf2js/__tests__/avm2-interface.test.js +95 -0
  214. package/swf2js/__tests__/avm2-multiname-precedence.test.js +148 -0
  215. package/swf2js/__tests__/avm2-named-namespace-types.test.js +106 -0
  216. package/swf2js/__tests__/avm2-optional-args.test.js +100 -0
  217. package/swf2js/__tests__/avm2-outer-scopes.test.js +101 -0
  218. package/swf2js/__tests__/avm2-package-internal-class.test.js +106 -0
  219. package/swf2js/__tests__/avm2-protected-namespace.test.js +105 -0
  220. package/swf2js/__tests__/avm2-protected.test.js +214 -0
  221. package/swf2js/__tests__/avm2-qwop-gameplay.test.js +116 -0
  222. package/swf2js/__tests__/avm2-runtime-namespaces.test.js +159 -0
  223. package/swf2js/__tests__/avm2-script-traits.test.js +89 -0
  224. package/swf2js/__tests__/avm2-shared-runtime.test.js +52 -0
  225. package/swf2js/__tests__/avm2-slot-ops.test.js +117 -0
  226. package/swf2js/__tests__/avm2-type-ops.test.js +224 -0
  227. package/swf2js/__tests__/bevel-filter.test.js +116 -0
  228. package/swf2js/__tests__/bitmap-button-mask.test.js +106 -0
  229. package/swf2js/__tests__/bitmap-data-draw.test.js +388 -0
  230. package/swf2js/__tests__/bitmap-decoder.test.js +108 -0
  231. package/swf2js/__tests__/bitmapdata-color-bounds.test.js +70 -0
  232. package/swf2js/__tests__/bitmapdata-copy-channel.test.js +91 -0
  233. package/swf2js/__tests__/bitmapdata-copy-pixels.test.js +136 -0
  234. package/swf2js/__tests__/bitmapdata-fill-compare.test.js +241 -0
  235. package/swf2js/__tests__/bitmapdata-filter.test.js +232 -0
  236. package/swf2js/__tests__/bitmapdata-hit-test.test.js +71 -0
  237. package/swf2js/__tests__/bitmapdata-merge.test.js +84 -0
  238. package/swf2js/__tests__/bitmapdata-palette-map.test.js +92 -0
  239. package/swf2js/__tests__/bitmapdata-pixels-io.test.js +198 -0
  240. package/swf2js/__tests__/bitmapdata-threshold.test.js +97 -0
  241. package/swf2js/__tests__/bitmapdata-vector.test.js +82 -0
  242. package/swf2js/__tests__/blur-filter.test.js +48 -0
  243. package/swf2js/__tests__/bundle-emitter.test.js +394 -0
  244. package/swf2js/__tests__/button-actions.test.js +370 -0
  245. package/swf2js/__tests__/button-color-transform.test.js +48 -0
  246. package/swf2js/__tests__/button-decoder.test.js +106 -0
  247. package/swf2js/__tests__/button-hit-test.test.js +825 -0
  248. package/swf2js/__tests__/button-scaling-grid.test.js +124 -0
  249. package/swf2js/__tests__/button-sound.test.js +105 -0
  250. package/swf2js/__tests__/bytearray-coercion.test.js +23 -0
  251. package/swf2js/__tests__/bytearray-object-serialization.test.js +380 -0
  252. package/swf2js/__tests__/cfg-switch-loop.test.js +103 -0
  253. package/swf2js/__tests__/clip-depth-mask.test.js +119 -0
  254. package/swf2js/__tests__/clipped-bitmap-fill.test.js +118 -0
  255. package/swf2js/__tests__/companion-swf.test.js +638 -0
  256. package/swf2js/__tests__/context-menu.test.js +149 -0
  257. package/swf2js/__tests__/convolution-filter.test.js +74 -0
  258. package/swf2js/__tests__/definefont4.test.js +280 -0
  259. package/swf2js/__tests__/display-displacement.test.js +161 -0
  260. package/swf2js/__tests__/display-list.test.js +80 -0
  261. package/swf2js/__tests__/display-mask-render.test.js +656 -0
  262. package/swf2js/__tests__/displayobject-stage.test.js +320 -0
  263. package/swf2js/__tests__/embedded-script-audio.test.js +131 -0
  264. package/swf2js/__tests__/embedded-swf.test.js +202 -0
  265. package/swf2js/__tests__/embedded-textfield.test.js +107 -0
  266. package/swf2js/__tests__/embedded-timeline-audio.test.js +182 -0
  267. package/swf2js/__tests__/embedded-timeline-input.test.js +420 -0
  268. package/swf2js/__tests__/embedded-timer-lifecycle.test.js +145 -0
  269. package/swf2js/__tests__/event-priority-order.test.js +125 -0
  270. package/swf2js/__tests__/event-weak-listeners.test.js +53 -0
  271. package/swf2js/__tests__/event-will-trigger.test.js +43 -0
  272. package/swf2js/__tests__/flash-text-engine-content.test.js +115 -0
  273. package/swf2js/__tests__/flash-text-engine-format.test.js +95 -0
  274. package/swf2js/__tests__/flash-text-engine-line.test.js +314 -0
  275. package/swf2js/__tests__/font-encoder.test.js +95 -0
  276. package/swf2js/__tests__/font-outline-text.test.js +659 -0
  277. package/swf2js/__tests__/glow-shadow-filter.test.js +68 -0
  278. package/swf2js/__tests__/graphics-bitmap-smoothing.test.js +32 -0
  279. package/swf2js/__tests__/graphics-fill-lifetime.test.js +36 -0
  280. package/swf2js/__tests__/graphics-gradient-matrix.test.js +53 -0
  281. package/swf2js/__tests__/graphics-stroke-hit-test.test.js +457 -0
  282. package/swf2js/__tests__/hit-test-primitives.test.js +414 -0
  283. package/swf2js/__tests__/input-events.test.js +714 -0
  284. package/swf2js/__tests__/integration/corpus.test.js +41 -0
  285. package/swf2js/__tests__/loader-embedded-swf.test.js +210 -0
  286. package/swf2js/__tests__/loader-info.test.js +81 -0
  287. package/swf2js/__tests__/local-connection.test.js +122 -0
  288. package/swf2js/__tests__/morph-focal-gradient.test.js +51 -0
  289. package/swf2js/__tests__/morph-topology.test.js +267 -0
  290. package/swf2js/__tests__/movie-data-codec.test.js +128 -0
  291. package/swf2js/__tests__/nellymoser-audio.test.js +84 -0
  292. package/swf2js/__tests__/opaque-background-cache.test.js +352 -0
  293. package/swf2js/__tests__/path-stream.test.js +81 -0
  294. package/swf2js/__tests__/place-object-filters.test.js +88 -0
  295. package/swf2js/__tests__/place-object3-decoder.test.js +116 -0
  296. package/swf2js/__tests__/place-object3-image.test.js +85 -0
  297. package/swf2js/__tests__/player-version.test.js +46 -0
  298. package/swf2js/__tests__/root-textfield.test.js +287 -0
  299. package/swf2js/__tests__/scaling-grid.test.js +183 -0
  300. package/swf2js/__tests__/shape-decoder.test.js +361 -0
  301. package/swf2js/__tests__/shape-line-style2.test.js +138 -0
  302. package/swf2js/__tests__/shape-nonscaling-stroke.test.js +131 -0
  303. package/swf2js/__tests__/shape-pixel-hint.test.js +101 -0
  304. package/swf2js/__tests__/simplebutton-pointer.test.js +1477 -0
  305. package/swf2js/__tests__/socket-offline.test.js +67 -0
  306. package/swf2js/__tests__/sound-avm1-stop.test.js +99 -0
  307. package/swf2js/__tests__/sound-envelope.test.js +110 -0
  308. package/swf2js/__tests__/sound-extract.test.js +168 -0
  309. package/swf2js/__tests__/sound-id3.test.js +283 -0
  310. package/swf2js/__tests__/sound-load.test.js +259 -0
  311. package/swf2js/__tests__/sound-mixer-spectrum.test.js +261 -0
  312. package/swf2js/__tests__/sound-stream-sprite.test.js +624 -0
  313. package/swf2js/__tests__/sound-transform.test.js +104 -0
  314. package/swf2js/__tests__/speex-audio.test.js +77 -0
  315. package/swf2js/__tests__/stage-noscale.test.js +45 -0
  316. package/swf2js/__tests__/swf-encoder.test.js +134 -0
  317. package/swf2js/__tests__/swflib-assemble.test.js +20 -0
  318. package/swf2js/__tests__/textfield-html-text.test.js +368 -0
  319. package/swf2js/__tests__/textfield-line-layout.test.js +339 -0
  320. package/swf2js/__tests__/textfield-programmatic-overlay.test.js +2506 -0
  321. package/swf2js/__tests__/textfield-scroll.test.js +79 -0
  322. package/swf2js/__tests__/textfield-selection.test.js +383 -0
  323. package/swf2js/__tests__/timeline-effect-surfaces.test.js +295 -0
  324. package/swf2js/__tests__/timeline-named-anchor.test.js +139 -0
  325. package/swf2js/__tests__/timeline-scenes.test.js +1723 -0
  326. package/swf2js/__tests__/urlloader-http-status.test.js +236 -0
  327. package/{src → swf2js}/cli.js +43 -11
  328. package/swf2js/compiler/as2-classes.js +156 -0
  329. package/swf2js/compiler/as2-parser.js +598 -0
  330. package/swf2js/compiler/avm1-codegen.js +897 -0
  331. package/swf2js/compiler/index.js +28 -0
  332. package/{src → swf2js}/decoder/button-decoder.js +3 -1
  333. package/swf2js/decoder/png.js +114 -0
  334. package/{src → swf2js}/decoder/shape-decoder.js +20 -10
  335. package/{src → swf2js}/decoder/tag-decoder.js +5 -3
  336. package/{src → swf2js}/decoder/tag-types.js +4 -0
  337. package/swf2js/decompiler/avm1-decompiler.js +1138 -0
  338. package/{src → swf2js}/emitter/asset-encoder.js +66 -113
  339. package/{src → swf2js}/emitter/bundle-emitter.js +209 -78
  340. package/swf2js/emitter/external-resources.js +39 -0
  341. package/swf2js/emitter/movie-data-codec.js +91 -0
  342. package/swf2js/encoder/bit-writer.js +182 -0
  343. package/swf2js/encoder/shape-encoder.js +310 -0
  344. package/swf2js/encoder/swf-builder.js +639 -0
  345. package/swf2js/encoder/swf-writer.js +55 -0
  346. package/{src/runtime/swflib/assemble.js → swf2js/runtime/assemble-swooflib.js} +4 -3
  347. package/{src → swf2js}/runtime/avm1-runtime.js +102 -63
  348. package/{src → swf2js}/runtime/index.js +1 -1
  349. package/{src → swf2js}/runtime/movie-runtime.js +28 -2
  350. package/{src → swf2js}/transpiler/actionscript.js +82 -19
  351. package/{src → swf2js}/transpiler/avm1/avm1-opcodes.js +5 -3
  352. package/{src → swf2js}/transpiler/avm1/avm1-transpiler.js +69 -6
  353. package/{src → swf2js}/transpiler/avm2/avm2-transpiler.js +1 -1
  354. package/{src → swf2js}/transpiler/timeline/display-list.js +41 -22
  355. package/{src → swf2js}/transpiler/timeline/timeline-codegen.js +97 -36
  356. package/swooflib/README.md +569 -0
  357. package/swooflib/adpcm.js +147 -0
  358. package/{src/runtime/swflib → swooflib}/builtins.js +6 -0
  359. package/{src/runtime/swflib → swooflib}/context-menu.js +7 -1
  360. package/swooflib/control-definitions.js +42 -0
  361. package/swooflib/control-widget.js +763 -0
  362. package/swooflib/controls.js +300 -0
  363. package/{src/runtime/swflib → swooflib}/display.js +16 -10
  364. package/{src/runtime/swflib → swooflib}/events.js +11 -0
  365. package/{src/runtime/swflib → swooflib}/flash.js +6 -5
  366. package/{src/runtime/swflib → swooflib}/graphics.js +81 -19
  367. package/{src/runtime/swflib → swooflib}/input.js +12 -14
  368. package/{src/runtime/swflib → swooflib}/loader.js +52 -22
  369. package/swooflib/movie-network.js +86 -0
  370. package/swooflib/path-stream.js +169 -0
  371. package/{src/runtime/swflib → swooflib}/render.js +3 -13
  372. package/{src/runtime/swflib → swooflib}/sound.js +25 -2
  373. package/{src/runtime/swflib → swooflib}/stage.js +3 -3
  374. package/swooflib/stream-time.js +21 -0
  375. package/{src/runtime/swflib → swooflib}/system.js +88 -37
  376. package/{src/runtime/swflib → swooflib}/text-paint.js +14 -3
  377. package/{src/runtime/swflib → swooflib}/text.js +8 -0
  378. package/swooflib/xml-node.js +53 -0
  379. package/src/emitter/timeline-data-codec.js +0 -58
  380. /package/{src → swf2js}/decoder/symbol-table.js +0 -0
  381. /package/{src → swf2js}/emitter/embedded-swf.js +0 -0
  382. /package/{src → swf2js}/emitter/font-encoder.js +0 -0
  383. /package/{src → swf2js}/model/swf-document.js +0 -0
  384. /package/{src → swf2js}/model/transpile-result.js +0 -0
  385. /package/{src → swf2js}/parser/bit-reader.js +0 -0
  386. /package/{src → swf2js}/parser/decompressor.js +0 -0
  387. /package/{src → swf2js}/parser/swf-parser.js +0 -0
  388. /package/{src → swf2js}/pretty-printer/pretty-printer.js +0 -0
  389. /package/{src → swf2js}/runtime/avm2-runtime.js +0 -0
  390. /package/{src → swf2js}/runtime/embedded-movie-runtime.js +0 -0
  391. /package/{src → swf2js}/transpiler/avm1/avm1-ir.js +0 -0
  392. /package/{src → swf2js}/transpiler/avm1/avm1-rewrite.js +0 -0
  393. /package/{src → swf2js}/transpiler/avm2/abc-reader.js +0 -0
  394. /package/{src → swf2js}/transpiler/cfg-structurer.js +0 -0
  395. /package/{src → swf2js}/util/diagnostics.js +0 -0
  396. /package/{src → swf2js}/util/logger.js +0 -0
  397. /package/{src/runtime/swflib → swooflib}/bitmap-image.js +0 -0
  398. /package/{src/runtime/swflib → swooflib}/bitmap.js +0 -0
  399. /package/{src/runtime/swflib → swooflib}/bytearray.js +0 -0
  400. /package/{src/runtime/swflib → swooflib}/compiled-swf.js +0 -0
  401. /package/{src/runtime/swflib → swooflib}/cursor-flag.js +0 -0
  402. /package/{src/runtime/swflib → swooflib}/dictionary.js +0 -0
  403. /package/{src/runtime/swflib → swooflib}/filters.js +0 -0
  404. /package/{src/runtime/swflib → swooflib}/geom.js +0 -0
  405. /package/{src/runtime/swflib → swooflib}/glyph-metrics.js +0 -0
  406. /package/{src/runtime/swflib → swooflib}/host.js +0 -0
  407. /package/{src/runtime/swflib → swooflib}/inherit.js +0 -0
  408. /package/{src/runtime/swflib → swooflib}/marks.js +0 -0
  409. /package/{src/runtime/swflib → swooflib}/matrix3d.js +0 -0
  410. /package/{src/runtime/swflib → swooflib}/pointer-bridge.js +0 -0
  411. /package/{src/runtime/swflib → swooflib}/projection.js +0 -0
  412. /package/{src/runtime/swflib → swooflib}/sprite-drag.js +0 -0
  413. /package/{src/runtime/swflib → swooflib}/stage-ref.js +0 -0
  414. /package/{src/runtime/swflib → swooflib}/text-field.js +0 -0
  415. /package/{src/runtime/swflib → swooflib}/transform.js +0 -0
  416. /package/{src/runtime/swflib → swooflib}/xml.js +0 -0
@@ -0,0 +1,56 @@
1
+ import assert from 'node:assert/strict';
2
+ import test from 'node:test';
3
+ import { ensureKeyframe, poseAt } from './src/model.js';
4
+ import { parseProjectJson, serializeProject } from './src/project-io.js';
5
+
6
+ function projectWith(element) {
7
+ return parseProjectJson(JSON.stringify({ stage: { width: 800, height: 450, frameRate: 24 },
8
+ scenes: [{ durationFrames: 11, elements: [{ type: 'rectangle', ...element }] }] }));
9
+ }
10
+
11
+ test('vector styles inherit base values and round-trip explicit resets', () => {
12
+ const project = projectWith({ gradient: { type: 'radial', focus: -0.25 },
13
+ effect: { type: 'shadow' }, keyframes: [{ frame: 1 }, { frame: 11, gradient: null, effect: null }] });
14
+ const el = project.scenes[0].elements[0];
15
+ assert.deepEqual(poseAt(el, 5).gradient, { type: 'radial', focus: -0.25, endColor: '#ffffff' });
16
+ assert.equal(poseAt(el, 5).effect.angle, 45);
17
+ assert.equal(poseAt(el, 11).gradient, null);
18
+ assert.equal(poseAt(el, 11).effect, null);
19
+ assert.equal(serializeProject(parseProjectJson(serializeProject(project))), serializeProject(project));
20
+ assert.doesNotMatch(serializeProject(projectWith({})), /"gradient"|"effect"/);
21
+ });
22
+
23
+ test('compatible style parameters tween with easing and newly captured keys own their values', () => {
24
+ const el = projectWith({ keyframes: [
25
+ { frame: 1, tween: 'easeIn', gradient: { type: 'linear', endColor: '#000000', angle: 0 },
26
+ effect: { type: 'glow', blurX: 4 } },
27
+ { frame: 9, gradient: { type: 'linear', endColor: '#ffffff', angle: 80 },
28
+ effect: { type: 'glow', blurX: 20 } },
29
+ { frame: 11, gradient: { type: 'radial' }, effect: { type: 'blur' } },
30
+ ] }).scenes[0].elements[0];
31
+ assert.deepEqual(poseAt(el, 5).gradient, { type: 'linear', endColor: '#404040', angle: 20 });
32
+ assert.equal(poseAt(el, 5).effect.blurX, 8);
33
+ assert.equal(poseAt(el, 10).gradient.type, 'linear');
34
+ assert.equal(poseAt(el, 10).effect.type, 'glow');
35
+ el.keyframes[0].tween = 'hold';
36
+ const middle = ensureKeyframe(el, 5);
37
+ assert.equal(middle.gradient.angle, 0);
38
+ middle.effect.blurX = 42;
39
+ assert.equal(el.keyframes[0].effect.blurX, 4);
40
+ });
41
+
42
+ test('vector style validation covers base objects, frame overrides and supported targets', () => {
43
+ for (const [style, message] of [
44
+ [{ gradient: { type: 'conical' } }, /gradient.*type/],
45
+ [{ gradient: { type: 'linear', endColor: 'white' } }, /gradient.endColor/],
46
+ [{ gradient: { type: 'radial', focus: -1.1 } }, /gradient.focus/],
47
+ [{ effect: { type: 'shadow', alpha: 2 } }, /effect.alpha/],
48
+ [{ effect: { type: 'blur', blurX: '2' } }, /effect.blurX/],
49
+ ]) {
50
+ assert.throws(() => projectWith(style), message);
51
+ assert.throws(() => projectWith({ keyframes: [{ frame: 1, ...style }] }), message);
52
+ }
53
+ assert.throws(() => projectWith({ type: 'line', gradient: { type: 'linear' } }), /unsupported/);
54
+ assert.throws(() => projectWith({ type: 'text', effect: { type: 'glow' } }), /unsupported/);
55
+ assert.equal(projectWith({ type: 'line', effect: { type: 'blur' } }).scenes[0].elements[0].effect.blurX, 8);
56
+ });
@@ -0,0 +1,326 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { writeMp4, writeWebm } from './src/video-mux.js';
4
+ import { createAudioSchedule, playHeadless, videoExportRefusal } from './src/video-playback.js';
5
+ import { avcCodec, outputSize } from './src/video-encode.js';
6
+
7
+ // ---- Synthetic streams ----------------------------------------------------------------------
8
+
9
+ function videoChunks(count, fps, keyEvery) {
10
+ return Array.from({ length: count }, (_, i) => {
11
+ const timestamp = Math.round(i * 1e6 / fps);
12
+ return { data: Uint8Array.of(0xa0 + (i % 16), i & 255, 7), timestamp,
13
+ duration: Math.round((i + 1) * 1e6 / fps) - timestamp, key: i % keyEvery === 0 };
14
+ });
15
+ }
16
+ function audioChunks(count) {
17
+ return Array.from({ length: count }, (_, i) => ({ data: Uint8Array.of(0x50, i & 255), timestamp: Math.round(i * 1024 * 1e6 / 48000),
18
+ duration: Math.round(1024 * 1e6 / 48000), key: true }));
19
+ }
20
+ const avcC = Uint8Array.of(1, 0x64, 0, 0x28, 0xff, 0xe1, 0, 4, 0x67, 0x64, 0, 0x28, 1, 0, 4, 0x68, 0xee, 0x3c, 0x80);
21
+
22
+ // ---- MP4 reader -------------------------------------------------------------------------------
23
+
24
+ const CONTAINERS = new Set(['moov', 'trak', 'mdia', 'minf', 'stbl', 'dinf', 'edts']);
25
+ function boxes(bytes, start = 0, end = bytes.length) {
26
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
27
+ const out = [];
28
+ for (let offset = start; offset < end;) {
29
+ const size = view.getUint32(offset);
30
+ const type = String.fromCharCode(...bytes.subarray(offset + 4, offset + 8));
31
+ assert.ok(size >= 8 && offset + size <= end, `box ${type} fits its parent`);
32
+ const box = { type, offset, size, body: bytes.subarray(offset + 8, offset + size), view: new DataView(bytes.buffer, bytes.byteOffset + offset + 8, size - 8) };
33
+ if (CONTAINERS.has(type)) box.children = boxes(bytes, offset + 8, offset + size);
34
+ out.push(box);
35
+ offset += size;
36
+ }
37
+ return out;
38
+ }
39
+ const find = (list, path) => path.split('/').reduce((items, type) => items.flatMap(item => (item.children ?? []).filter(child => child.type === type)), [{ children: list }]);
40
+ const table = (box, width = 1, skip = 4) => {
41
+ const count = box.view.getUint32(skip);
42
+ return Array.from({ length: count }, (_, i) => Array.from({ length: width }, (_, j) => box.view.getUint32(skip + 4 + (i * width + j) * 4)));
43
+ };
44
+
45
+ test('MP4 puts moov before mdat and indexes every sample', () => {
46
+ const fps = 12;
47
+ const video = videoChunks(30, fps, 24);
48
+ const audio = audioChunks(50);
49
+ const file = writeMp4({ width: 320, height: 240, video: { codec: 'avc', description: avcC, chunks: video },
50
+ audio: { codec: 'aac', sampleRate: 48000, channels: 2, description: Uint8Array.of(0x11, 0x90), chunks: audio } });
51
+ const top = boxes(file);
52
+ assert.deepEqual(top.map(box => box.type), ['ftyp', 'moov', 'mdat']);
53
+ const traks = find(top, 'moov/trak');
54
+ assert.equal(traks.length, 2);
55
+ const mvhd = find(top, 'moov/mvhd')[0];
56
+ assert.equal(mvhd.view.getUint32(12), 1000, 'movie timescale');
57
+ assert.equal(mvhd.view.getUint32(16), 2500, '30 frames at 12 fps');
58
+
59
+ for (const [trak, chunks, kind] of [[traks[0], video, 'vide'], [traks[1], audio, 'soun']]) {
60
+ const tree = [trak];
61
+ assert.equal(String.fromCharCode(...find(tree, 'trak/mdia/hdlr')[0].body.subarray(8, 12)), kind);
62
+ const stbl = find(tree, 'trak/mdia/minf/stbl')[0].children;
63
+ const get = type => stbl.find(box => box.type === type);
64
+ const sizes = table(get('stsz'), 1, 8).map(([size]) => size);
65
+ assert.deepEqual(sizes, chunks.map(chunk => chunk.data.length));
66
+ const stts = table(get('stts'), 2);
67
+ assert.equal(stts.reduce((sum, [count]) => sum + count, 0), chunks.length);
68
+ // Walk stsc and stco: each sample's bytes must be at its indexed position.
69
+ const offsets = table(get('stco')).map(([offset]) => offset);
70
+ const runs = table(get('stsc'), 3);
71
+ let sample = 0;
72
+ offsets.forEach((offset, chunkIndex) => {
73
+ const run = runs.findLast(([first]) => first <= chunkIndex + 1);
74
+ for (let i = 0; i < run[1]; i++, sample++) {
75
+ assert.deepEqual(file.subarray(offset, offset + sizes[sample]), chunks[sample].data);
76
+ offset += sizes[sample];
77
+ }
78
+ });
79
+ assert.equal(sample, chunks.length);
80
+ if (kind === 'vide') {
81
+ assert.deepEqual(table(get('stss')).map(([n]) => n), [1, 25], 'key frames are sync samples');
82
+ const mdhd = find(tree, 'trak/mdia/mdhd')[0];
83
+ assert.equal(mdhd.view.getUint32(12), 90000);
84
+ assert.equal(mdhd.view.getUint32(16), 225000, 'video duration is exact');
85
+ const entry = get('stsd').body.subarray(8);
86
+ assert.equal(String.fromCharCode(...entry.subarray(4, 8)), 'avc1');
87
+ assert.ok(Buffer.from(entry).includes(Buffer.from([...Buffer.from('avcC'), ...avcC])), 'avcC record is embedded');
88
+ } else {
89
+ // The edit list skips the AAC encoder's 2112 priming samples.
90
+ const elst = find(tree, 'trak/edts')[0];
91
+ assert.ok(elst, 'audio has an edit list');
92
+ const view = new DataView(elst.body.buffer, elst.body.byteOffset + 8);
93
+ assert.equal(view.getUint32(4), 1);
94
+ assert.equal(view.getUint32(12), 2112, 'media time starts after the priming');
95
+ assert.equal(view.getUint32(8), Math.round((audio.length * 1024 - 2112) / 48));
96
+ const entry = get('stsd').body.subarray(8);
97
+ assert.equal(String.fromCharCode(...entry.subarray(4, 8)), 'mp4a');
98
+ assert.ok(Buffer.from(entry).includes(Buffer.from('esds')));
99
+ }
100
+ }
101
+ });
102
+
103
+ test('MP4 interleaves audio and video in half-second chunks', () => {
104
+ const file = writeMp4({ width: 64, height: 64, video: { codec: 'avc', description: avcC, chunks: videoChunks(24, 12, 24) },
105
+ audio: { codec: 'opus', sampleRate: 48000, channels: 2, chunks: audioChunks(94) } });
106
+ const traks = find(boxes(file), 'moov/trak');
107
+ const offsets = traks.map(trak => table(find([trak], 'trak/mdia/minf/stbl/stco')[0]).map(([offset]) => offset));
108
+ assert.equal(offsets[0].length, 4);
109
+ assert.ok(offsets[1][0] > offsets[0][0] && offsets[1][0] < offsets[0][1], 'audio follows the first video chunk');
110
+ assert.ok(Buffer.from(file).includes(Buffer.from('dOps')), 'Opus in MP4 uses dOps');
111
+ });
112
+
113
+ test('MP4 without audio has one track', () => {
114
+ const file = writeMp4({ width: 64, height: 64, video: { codec: 'avc', description: avcC, chunks: videoChunks(3, 10, 10) } });
115
+ assert.equal(find(boxes(file), 'moov/trak').length, 1);
116
+ assert.throws(() => writeMp4({ width: 64, height: 64, video: { codec: 'avc', chunks: videoChunks(1, 10, 10) } }), /avcC/);
117
+ });
118
+
119
+ // ---- WebM reader ------------------------------------------------------------------------------
120
+
121
+ function vint(bytes, offset, keepMarker) {
122
+ const first = bytes[offset];
123
+ let width = 1;
124
+ while (width <= 8 && !(first & (0x80 >> (width - 1)))) width++;
125
+ let value = keepMarker ? first : first & (0xff >> width);
126
+ for (let i = 1; i < width; i++) value = value * 256 + bytes[offset + i];
127
+ return { value, width };
128
+ }
129
+ const MASTERS = new Set([0x1a45dfa3, 0x18538067, 0x114d9b74, 0x4dbb, 0x1549a966, 0x1654ae6b, 0xae, 0xe0, 0xe1, 0x1f43b675, 0x1c53bb6b, 0xbb, 0xb7]);
130
+ function ebml(bytes, start = 0, end = bytes.length) {
131
+ const out = [];
132
+ for (let offset = start; offset < end;) {
133
+ const id = vint(bytes, offset, true);
134
+ const size = vint(bytes, offset + id.width);
135
+ const dataStart = offset + id.width + size.width;
136
+ assert.ok(dataStart + size.value <= end, `element ${id.value.toString(16)} fits its parent`);
137
+ const node = { id: id.value, offset, dataStart, data: bytes.subarray(dataStart, dataStart + size.value) };
138
+ if (MASTERS.has(id.value)) node.children = ebml(bytes, dataStart, dataStart + size.value);
139
+ out.push(node);
140
+ offset = dataStart + size.value;
141
+ }
142
+ return out;
143
+ }
144
+ const uintOf = data => data.reduce((value, byte) => value * 256 + byte, 0);
145
+
146
+ test('WebM has tracks, clusters at key frames, and cues that point at them', () => {
147
+ const fps = 12;
148
+ const video = videoChunks(60, fps, 24);
149
+ const audio = audioChunks(235);
150
+ const file = writeWebm({ width: 320, height: 240, video: { codec: 'vp9', chunks: video },
151
+ audio: { codec: 'opus', sampleRate: 48000, channels: 2, chunks: audio } });
152
+ const [header, segment] = ebml(file);
153
+ assert.equal(header.id, 0x1a45dfa3);
154
+ assert.equal(new TextDecoder().decode(header.children.find(node => node.id === 0x4282).data), 'webm');
155
+ const children = segment.children;
156
+ const clusters = children.filter(node => node.id === 0x1f43b675);
157
+ assert.equal(clusters.length, 3, 'one cluster per key frame');
158
+ const blocks = clusters.flatMap(cluster => cluster.children.filter(node => node.id === 0xa3));
159
+ assert.equal(blocks.length, video.length + audio.length);
160
+ const videoBlocks = blocks.filter(block => block.data[0] === 0x81);
161
+ assert.deepEqual(videoBlocks.map(block => [...block.data.subarray(4)]), video.map(chunk => [...chunk.data]));
162
+ assert.deepEqual(videoBlocks.map(block => Boolean(block.data[3] & 0x80)), video.map(chunk => chunk.key));
163
+ const info = children.find(node => node.id === 0x1549a966);
164
+ const duration = new DataView(info.children.find(node => node.id === 0x4489).data.buffer,
165
+ info.children.find(node => node.id === 0x4489).data.byteOffset).getFloat64(0);
166
+ assert.ok(Math.abs(duration - 235 * 1024 / 48) < 1, `duration ${duration} ms: the longer stream`);
167
+ const tracks = children.find(node => node.id === 0x1654ae6b).children;
168
+ const codecs = tracks.map(track => new TextDecoder().decode(track.children.find(node => node.id === 0x86).data));
169
+ assert.deepEqual(codecs, ['V_VP9', 'A_OPUS']);
170
+ assert.equal(new TextDecoder().decode(tracks[1].children.find(node => node.id === 0x63a2).data.subarray(0, 8)), 'OpusHead');
171
+ // Seek head and cue positions are relative to the segment data.
172
+ const seek = children.find(node => node.id === 0x114d9b74).children;
173
+ for (const entry of seek) {
174
+ const id = uintOf(entry.children.find(node => node.id === 0x53ab).data);
175
+ const position = uintOf(entry.children.find(node => node.id === 0x53ac).data);
176
+ assert.equal(children.find(node => node.offset === segment.dataStart + position)?.id, id);
177
+ }
178
+ const cues = children.find(node => node.id === 0x1c53bb6b).children;
179
+ assert.equal(cues.length, 3);
180
+ for (const cue of cues) {
181
+ const position = uintOf(cue.children.find(node => node.id === 0xb7).children.find(node => node.id === 0xf1).data);
182
+ assert.equal(children.find(node => node.offset === segment.dataStart + position)?.id, 0x1f43b675);
183
+ }
184
+ });
185
+
186
+ // ---- Encoder settings -------------------------------------------------------------------------
187
+
188
+ test('H.264 level follows the frame size and rate; sizes are even', () => {
189
+ assert.equal(avcCodec(640, 480, 30), 'avc1.64001e');
190
+ assert.equal(avcCodec(1280, 720, 30), 'avc1.64001f');
191
+ assert.equal(avcCodec(1920, 1080, 30), 'avc1.640028');
192
+ assert.equal(avcCodec(1920, 1080, 60), 'avc1.64002a');
193
+ assert.deepEqual(outputSize({ width: 551, height: 400 }, 1), { width: 552, height: 400 });
194
+ assert.deepEqual(outputSize({ width: 551, height: 401 }, 2), { width: 1102, height: 802 });
195
+ });
196
+
197
+ // ---- Headless playback ------------------------------------------------------------------------
198
+
199
+ function scene(id, durationFrames, extra = {}) {
200
+ return { id, name: id, durationFrames, layers: [], elements: [], ...extra };
201
+ }
202
+ async function play(project, { maxFrames = 1000, holdFrames = 2, audio } = {}) {
203
+ const shown = [];
204
+ let current;
205
+ const result = await playHeadless({
206
+ project, maxFrames, holdFrames, audio,
207
+ render: ({ scene: active, playhead }) => {
208
+ current = `${active.id}:${playhead}`;
209
+ return [{ timeline: active, frame: playhead, scope: [], parentFrame: playhead, exposure: '', repeatOnTick: false, audioActive: true }];
210
+ },
211
+ snapshot: () => {},
212
+ emit: transition => { shown.push(transition ? `${transition.type}:${transition.progress}` : current); },
213
+ });
214
+ return { ...result, shown };
215
+ }
216
+
217
+ test('a one-shot scene plays once, then holds its last frame', async () => {
218
+ const { shown, ending } = await play({ stage: { frameRate: 10 }, scenes: [scene('a', 3)] });
219
+ assert.deepEqual(shown, ['a:1', 'a:2', 'a:3', 'a:3', 'a:3']);
220
+ assert.equal(ending, 'stop');
221
+ });
222
+
223
+ test('a looping scene ends where it would repeat', async () => {
224
+ const { shown, ending } = await play({ stage: { frameRate: 10 }, scenes: [scene('a', 3, { loop: true, startFrame: 1 })] });
225
+ assert.deepEqual(shown, ['a:1', 'a:2', 'a:3']);
226
+ assert.equal(ending, 'repeat');
227
+ });
228
+
229
+ test('the maximum length ends the video', async () => {
230
+ const { shown, ending } = await play({ stage: { frameRate: 10 }, scenes: [scene('a', 100)] }, { maxFrames: 4 });
231
+ assert.equal(shown.length, 4);
232
+ assert.equal(ending, 'length');
233
+ });
234
+
235
+ test('frame actions stop, jump and change scene with a transition', async () => {
236
+ const project = { stage: { frameRate: 10 }, scenes: [
237
+ scene('a', 5, { events: [{ trigger: 'frameEnter', frame: 2, actions: [{ type: 'gotoScene', target: 'b', play: true }] }] }),
238
+ scene('b', 4, { transition: { type: 'crossfade', durationFrames: 2, easing: 'linear' },
239
+ events: [{ trigger: 'frameEnter', frame: 3, actions: [{ type: 'stop' }] }] }),
240
+ ] };
241
+ const { shown, ending } = await play(project);
242
+ assert.deepEqual(shown, ['a:1', 'crossfade:0', 'crossfade:0.5', 'b:1', 'b:2', 'b:3', 'b:3', 'b:3']);
243
+ assert.equal(ending, 'stop');
244
+ });
245
+
246
+ test('a jump back to an earlier frame ends at the repeat', async () => {
247
+ const project = { stage: { frameRate: 10 }, scenes: [
248
+ scene('a', 6, { events: [{ trigger: 'frameEnter', frame: 4, actions: [{ type: 'gotoFrame', target: 2, play: true }] }] }),
249
+ ] };
250
+ const { shown, ending } = await play(project);
251
+ assert.deepEqual(shown, ['a:1', 'a:2', 'a:3']);
252
+ assert.equal(ending, 'repeat');
253
+ });
254
+
255
+ test('circular frame actions stop the export with a message', async () => {
256
+ const project = { stage: { frameRate: 10 }, scenes: [
257
+ scene('a', 3, { events: [{ trigger: 'frameEnter', frame: 1, actions: [{ type: 'gotoFrame', target: 1, play: true }] }] }),
258
+ ] };
259
+ await assert.rejects(play(project), /Video export stopped/);
260
+ });
261
+
262
+ test('audio voices continue across frames, restart after a jump and stop with playback', async () => {
263
+ const clip = { id: 'c', assetId: 'boom', start: 1, end: 8, loop: false };
264
+ const project = { stage: { frameRate: 10 }, scenes: [
265
+ scene('a', 8, { audioClips: [clip], events: [{ trigger: 'frameEnter', frame: 5, actions: [{ type: 'gotoFrame', target: 3, play: false }] }] }),
266
+ ] };
267
+ const audio = createAudioSchedule({ fps: 10, durationOf: () => 2 });
268
+ const { shown } = await play(project, { audio, holdFrames: 2 });
269
+ audio.finish(shown.length / 10);
270
+ assert.deepEqual(shown, ['a:1', 'a:2', 'a:3', 'a:4', 'a:3', 'a:3', 'a:3']);
271
+ const rounded = audio.segments.map(segment => Object.fromEntries(Object.entries(segment).map(([key, value]) =>
272
+ [key, typeof value === 'number' ? Math.round(value * 1000) / 1000 : value])));
273
+ assert.deepEqual(rounded, [{ assetId: 'boom', start: 0, offset: 0, loop: false, end: 0.4 }]);
274
+ });
275
+
276
+ test('a short clip ends at its last frame and a looping clip runs until playback stops', async () => {
277
+ const project = { stage: { frameRate: 10 }, scenes: [scene('a', 6, {
278
+ audioClips: [{ id: 'short', assetId: 's', start: 2, end: 3 }, { id: 'loop', assetId: 'l', start: 1, end: 6, loop: true }] })] };
279
+ const audio = createAudioSchedule({ fps: 10, durationOf: id => id === 's' ? 5 : 0.25 });
280
+ const { shown } = await play(project, { audio, holdFrames: 0 });
281
+ audio.finish(shown.length / 10);
282
+ const short = audio.segments.find(segment => segment.assetId === 's');
283
+ const loop = audio.segments.filter(segment => segment.assetId === 'l');
284
+ assert.ok(Math.abs(short.start - 0.1) < 1e-9 && Math.abs(short.end - 0.3) < 1e-9);
285
+ assert.equal(loop.length, 1);
286
+ assert.ok(loop[0].loop && Math.abs(loop[0].end - 0.6) < 1e-9);
287
+ });
288
+
289
+ test('projects that need the SWF player are refused with their reasons', () => {
290
+ assert.equal(videoExportRefusal({ scenes: [scene('a', 1)] }), null);
291
+ assert.match(videoExportRefusal({ scenes: [scene('a', 1, { trackAsMenu: true, scalingGrid: {} })] }), /uses nine-slice scaling\./);
292
+ // Input-only features and Flash sound cues do not block a video.
293
+ assert.equal(videoExportRefusal({ scenes: [scene('a', 1, { trackAsMenu: true, buttonSounds: {},
294
+ audioClips: [{ id: 'c', assetId: 's', start: 1, end: 1, soundInfo: { syncStop: true } }] })] }), null);
295
+ });
296
+
297
+ test('Flash sound cues start on entering their frame and play through stops, until a syncStop', async () => {
298
+ const cue = (extra = {}) => ({ syncStop: false, syncNoMultiple: false, inPoint: null, outPoint: null, loopCount: null, envelope: [], ...extra });
299
+ const project = { stage: { frameRate: 10 }, scenes: [scene('a', 6, {
300
+ audioClips: [
301
+ { id: 'music', assetId: 'm', start: 1, end: 6, soundInfo: cue() },
302
+ { id: 'again', assetId: 'm', start: 2, end: 2, soundInfo: cue({ syncNoMultiple: true }) },
303
+ { id: 'blip', assetId: 'b', start: 2, end: 2, soundInfo: cue({ inPoint: 4410, outPoint: 8820, loopCount: 2 }) },
304
+ { id: 'cut', assetId: 'm', start: 5, end: 5, soundInfo: cue({ syncStop: true }) },
305
+ ],
306
+ events: [{ trigger: 'frameEnter', frame: 3, actions: [{ type: 'gotoFrame', target: 5, play: true }] }] })] };
307
+ const audio = createAudioSchedule({ fps: 10, durationOf: id => id === 'm' ? 2 : 1 });
308
+ const { shown } = await play(project, { audio, holdFrames: 2 });
309
+ audio.finish(shown.length / 10);
310
+ const music = audio.segments.filter(segment => segment.assetId === 'm');
311
+ assert.equal(music.length, 1, 'syncNoMultiple does not start a second copy');
312
+ // Frames 1, 2, then the jump at frame 3 shows frame 5, whose cue stops the music at 0.2 s.
313
+ assert.ok(Math.abs(music[0].end - 0.2) < 1e-9, `music ends at ${music[0].end}`);
314
+ const blip = audio.segments.find(segment => segment.assetId === 'b');
315
+ assert.deepEqual([blip.offset, blip.loopStart, blip.loopEnd, blip.loop], [0.1, 0.1, 0.2, true]);
316
+ assert.ok(Math.abs(blip.end - (0.1 + 3 * 0.1)) < 1e-9, 'loopCount 2 plays three times, through the stop');
317
+ });
318
+
319
+ test('a stopped movie holds while event sounds finish', async () => {
320
+ const project = { stage: { frameRate: 10 }, scenes: [scene('a', 2, {
321
+ audioClips: [{ id: 'music', assetId: 'm', start: 1, end: 1, soundInfo: { syncStop: false, envelope: [] } }] })] };
322
+ const audio = createAudioSchedule({ fps: 10, durationOf: () => 3 });
323
+ const { shown, ending } = await play(project, { audio, holdFrames: 10 });
324
+ assert.equal(ending, 'stop');
325
+ assert.equal(shown.length, 30, 'two frames, then held until the 3 s sound ends');
326
+ });
@@ -0,0 +1,88 @@
1
+ # ActionScript in Studio
2
+
3
+ Related: [file-support.md](./file-support.md) (SWF import and export), [architecture.md](./architecture.md), [tasks.md §12](./tasks.md).
4
+
5
+ ## Purpose
6
+
7
+ An imported SWF should play in Studio the way it plays as a swf2js bundle. Today the import keeps the artwork, timelines, symbols, and instance names, but drops every ActionScript block that is more than a constant `stop`, `play`, or `goto`. The six game demos keep all their behavior in one frame-1 script, so they import as a still picture.
8
+
9
+ Flash and Animate attach scripts in three places, and the SWF records each script where it was attached:
10
+
11
+ | Flash authoring | SWF | Studio |
12
+ |---|---|---|
13
+ | Actions layer, frame N | `DoAction` in a timeline (root or sprite) | Frame event on that timeline: `{ trigger: 'frameEnter', frame: N, actions: [{ type: 'script', script }] }` |
14
+ | Button instance `on (release) { … }` | `DefineButton2` condition actions (or `DefineButton` actions) | Event on the button symbol: `{ trigger: 'release', actions: [{ type: 'script', script }] }` |
15
+ | Clip instance `onClipEvent (enterFrame) { … }` | `PlaceObject2/3` clip actions | Event on the placed element: `{ trigger: 'clip:enterFrame', … }` |
16
+ | Symbol `#initclip` | `DoInitAction` for a sprite | `symbol.initScript` |
17
+
18
+ Studio adds one action type, **Run script**, and those attachment points. Scripts written in a frame's code, such as `cell.onRelease = function () { … }` or `this.onEnterFrame = …`, need no extra mapping: they run as part of the frame script, exactly as in Flash.
19
+
20
+ Swoof Studio already draws with swooflib, but the code that runs ActionScript lives outside it: the AVM1 runtime (`swf2js/runtime/avm1-runtime.js`) and the timeline engine (`swf2js/transpiler/timeline/timeline-codegen.js`). Studio's preview rebuilds the display tree from the document every frame, so scripts cannot keep state between frames there. Preview of a project with scripts therefore runs on the swf2js player.
21
+
22
+ To attach code to artwork, select the object and choose **Interaction → Interactive button → Run script**. Use **Clip event scripts** on a placed symbol for its instance handlers. Use **Library → Symbol scripts** to edit a shared button definition's handlers or a movie clip's initialization script. Each handler keeps its event choices, key code, and position in the original handler list.
23
+
24
+ ## Requirements
25
+
26
+ ### 1. Keep scripts on import
27
+
28
+ 1. THE import SHALL keep every AVM1 block (`DoAction`, `DoInitAction`, button condition actions, clip actions) as a script at its original attachment point. It SHALL NOT report kept scripts as dropped.
29
+ 2. Blocks that consist only of constant `stop`, `play`, and `goto` actions SHALL keep converting to typed actions, which stay editable in the event editor. All other blocks SHALL become scripts. No block SHALL be represented both ways, so nothing runs twice.
30
+ 3. Each script SHALL store the original bytecode and the SWF version it was compiled for, because the transpiler's identifier casing and number conversion depend on the version. Identical bytecode with the same version SHALL be stored once and referenced by ID (library-once).
31
+ 4. Each script SHALL also store a readable JavaScript rendering produced by the swf2js transpiler, for display only.
32
+ 5. AVM2 (`DoABC`) blocks and `SymbolClass` bindings from imported SWFs SHALL retain their bytecode and frame order. Preview and standalone HTML use the shared swf2js AVM2 runtime. Large class-linked libraries keep their native definitions and embedded media, with editable stage symbols reused by character ID. Native SWF uses the ActionScript 3 file flag. The Actions editor authors AS1/AS2 source.
33
+
34
+ ### 2. Project format
35
+
36
+ 1. The project SHALL have a `scripts` table with two kinds of entry:
37
+ - Imported, unedited: `{ id, language: 'avm1', swfVersion, bytecode (base64), source (readable JavaScript, display only) }`.
38
+ - Written or edited in Studio: `{ id, language: 'actionscript', swfVersion, code }`, where `code` is ActionScript 2 source text. It stores no bytecode.
39
+ 2. Timeline events, button symbol events, and element events SHALL accept the action `{ type: 'script', script: <id> }`.
40
+ 3. Button events SHALL support the Flash button triggers: `press`, `release`, `releaseOutside`, `rollOver`, `rollOut`, `dragOver`, `dragOut`, and `keyPress` with a key code.
41
+ 4. Element events SHALL support the clip triggers: `load`, `enterFrame`, `unload`, `mouseDown`, `mouseUp`, `mouseMove`, `keyDown`, `keyUp`, `data`, `initialize`, `construct`, `press`, `release`, `releaseOutside`, `rollOver`, `rollOut`, `dragOver`, `dragOut`, and `keyPress`.
42
+ 5. Validation SHALL reject a script action whose ID is missing from the table, and saving SHALL drop table entries nothing references.
43
+
44
+ ### 3. Preview with scripts
45
+
46
+ 1. WHEN a project contains scripts, Preview SHALL run the project itself, as it is in the editor (unsaved edits included), on the swf2js runtime. The editor posts the project to `POST /api/preview`. The server converts it (`studio/server/project-movie.js`) into a swf2js display list (shapes drawn by Studio's own geometry code, text with variable bindings, sprites, four-state buttons, per-frame placements) plus the tags the transpiler reads (frame `DoAction`s, sprite scripts, clip actions, `DoInitAction`). It then runs `transpileActionScript` and `emit` into a temporary folder served at `/api/preview/<token>/`, and the editor shows that in a frame.
47
+ 2. Typed actions in a project with scripts SHALL be compiled to equivalent AVM1 (`stop`, `play`, `gotoFrame`, `gotoScene`, `show`/`hide`/`toggleVisibility`), so both kinds run on the same engine.
48
+ 3. Projects without scripts SHALL keep the current preview.
49
+ 4. Shapes in that display list SHALL use whole twips (1/20 px), as SWF shapes do, so swf2js stores them in its compact geometry encoding. A Studio cubic segment within a twip of a quadratic SHALL become that one quadratic curve (imported SWF curves come back as they were), a straight one SHALL become a line, and other cubics are split into four quadratics. Bitmaps SHALL use the editor's layout (`bitmapLayout`), so crop-to-fill alignment and source rectangles look the same in both.
50
+ 5. Scripts find objects by instance name. WHEN an edit renames or deletes an object whose name appears in a script's constant pool or push strings, Studio SHALL warn and name the script.
51
+
52
+ ### 4. Viewing and editing scripts
53
+
54
+ 1. The Actions panel SHALL show every script as ActionScript: the `code` of an `actionscript` script, or ActionScript decompiled from the bytecode of an `avm1` script (`swf2js/decompiler/avm1-decompiler.js`). Bytecode with no ActionScript form (optimizer or obfuscator output that keeps values on the stack across statements, calls to functions named like global actions) SHALL be shown read-only as its JavaScript translation, with the reason; it keeps running as it is.
55
+ 2. Scripts SHALL be editable in ActionScript 2: frame scripts, button and clip event bodies, and `#initclip` blocks. The language is ActionScript 1 and 2 statements and expressions, with type annotations accepted and ignored, as Flash's compiler does. The script editor can open a local `.as` file. SWF 7+ scripts support class and interface declarations, packages, and imports. Imported classes are resolved from declarations supplied by the movie. External `#include` files remain a later phase.
56
+ 3. Saving an edit to an `avm1` script SHALL turn it into an `actionscript` script with the edited code, keeping its ID and SWF version. An imported script that is not edited SHALL keep its original bytecode, so import, Preview and export never change a game's behavior silently.
57
+ 4. THE compiler (`swf2js/compiler/`) SHALL turn ActionScript into AVM1 bytecode for the script's SWF version. It runs when the project is built for playback: scripted Preview, SWF export, and HTML export. Everything after it (the transpiler, `buildProjectMovie`, the SWF builder) still reads bytecode only.
58
+ 5. WHILE a script is edited, Studio SHALL check it with the same compiler and show errors with their line and column. A script with errors SHALL still save. Preview and export SHALL then stop with the error, naming the script.
59
+ 6. New scripts SHALL default to the project's SWF version (that of its other scripts, or 8 when there are none).
60
+
61
+ ### 5. Import fidelity beyond scripts
62
+
63
+ The import SHALL convert what Studio's format can hold, and the format SHALL grow where swooflib already renders the feature. In order of frequency in the demo and archive corpus:
64
+
65
+ 1. Gradients with more than two stops and per-stop transparency (`gradient.stops`), and where the gradient sits in the shape (`gradient.matrix`, relative to the object's box). Done.
66
+ 2. Mirrored placements (negative scale): keyframe `mirror`, a flip in the object's own space. Done.
67
+ 3. Button Over, Down, and Hit states: button symbols (`button: true`) with the four states as frames 1–4, as Flash authors them. Done.
68
+ 4. Registration points (`symbol.origin`), original depths (`element.depth`), frame labels (`timeline.labels`), and text field settings (`element.field`: variable binding, HTML, editing flags). Done.
69
+ 5. JPEG images with an alpha plane: merged into one PNG. Done.
70
+ 6. Shapes with holes: `subpaths` filled even-odd. Done.
71
+ 7. Color transforms (tints, brightness): keyframe `colorTransform`, tweened. Done.
72
+ 8. Masks keep their SWF clip depth (`element.clipDepth`) for Preview, including symbol masks and masks swapped at one depth. Done.
73
+ 9. Static text in embedded fonts as outlines; keyboard-only buttons; linkage names (`symbol.linkage`) for `attachMovie`. Done.
74
+ 10. Embedded fonts for dynamic text, blend modes, filters in Preview, and rotated or tiled bitmap fills.
75
+
76
+ ## Design notes
77
+
78
+ - **One runtime for scripted preview.** Preview converts the project to swf2js's display list rather than to SWF bytes, so it reuses every swf2js runtime fix with no second engine to keep in step. SWF export (task 11) can start from the same conversion and add the byte encoders.
79
+ - **Bytecode, not JavaScript, is the source of truth for imported scripts.** Re-transpiling on each preview picks up transpiler fixes, and export writes the bytecode back unchanged.
80
+ - **ActionScript is the source of truth for written scripts.** The compiled bytecode is a build product, like the transpiled JavaScript, so there is nothing to keep in sync. HTML export runs ActionScript → AVM1 → JavaScript, and SWF export stops at AVM1, so both outputs come from the same compiled code.
81
+ - **The decompiler's output must compile back** to equivalent bytecode, so that editing one line of an imported script keeps the rest of it working. Its acceptance test runs on every script of the archive games: decompiling, compiling and decompiling again gives the same text, and the compiled script traces the same values in the transpiler's test harness. Control flow it cannot structure falls back to a dispatcher loop (`var _pc`; `while`; `switch (_pc)`), which is plain ActionScript.
82
+ - **Kept scripts reference the import's instance names**, which the import already preserves (`cell0`–`cell8`, `winBeam` in Neon Grid).
83
+
84
+ ## Acceptance
85
+
86
+ Snake from `archive/flasharchive` keeps every button and clip handler (the test compares counts with the source SWF when the archive is present); Pacman keeps its clip action, linkage names, masks and tints, and its title screen and game match the swf2js bundle. For each of the six game demos: Open SWF in Studio, Preview, and interact. Neon Grid: clicking a cell marks it and the computer answers. The first preview frame matches the swf2js bundle of the same SWF. `swoof-intro` keeps playing as it does today. The import report lists no dropped ActionScript for the demos.
87
+
88
+ Editing: open Neon Grid, edit its frame script in the Actions panel to change the computer's reply, Preview, and see the change; export it as SWF and HTML and see the same change.