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,475 @@
1
+ // Preview builds a swf2js movie from the Studio project itself (studiospec/actionscript.md §3).
2
+ import { after, before, describe, it } from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+ import { inspect } from 'node:util';
5
+ import { once } from 'node:events';
6
+ import { existsSync } from 'node:fs';
7
+ import { mkdtemp, readFile, rm } from 'node:fs/promises';
8
+ import { tmpdir } from 'node:os';
9
+ import path from 'node:path';
10
+ import { fileURLToPath } from 'node:url';
11
+ import { parse } from '../swf2js/parser/swf-parser.js';
12
+ import { encodeSoundStreamSegments } from '../swf2js/emitter/asset-encoder.js';
13
+ import { decode, decodeTag } from '../swf2js/decoder/tag-decoder.js';
14
+ import { buildDisplayList } from '../swf2js/transpiler/timeline/display-list.js';
15
+ import { linkedActionSource } from '../swf2js/transpiler/actionscript.js';
16
+ import { DiagnosticsCollector } from '../swf2js/util/diagnostics.js';
17
+ import { isEncodablePath } from '../swooflib/path-stream.js';
18
+ import { createStudioServer } from './server.js';
19
+ import { convertSwf } from './server/swf-import.js';
20
+ import { buildProjectMovie } from './server/project-movie.js';
21
+ import { buildPreview } from './server/project-preview.js';
22
+ import { exportProjectSwf } from './server/swf-export.js';
23
+ import { parseProjectJson, serializeProject } from './src/project-io.js';
24
+
25
+ const demos = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../demos');
26
+ const GAMES = ['lane-relay', 'neon-grid', 'relic-match', 'signal-sequence', 'target-circuit', 'vesper-patrol'];
27
+ let counter = 0;
28
+ const storeMedia = async (data, { name, type }) => {
29
+ const hash = String(++counter).padStart(64, '0');
30
+ return { name, type, kind: type.startsWith('audio/') ? 'audio' : 'image', hash, bytes: data.length, src: `assets/${hash}.bin` };
31
+ };
32
+ const importDemo = async name => {
33
+ const { project } = await convertSwf(new Uint8Array(await readFile(path.join(demos, `${name}.swf`))), { name, storeMedia, idPrefix: 't' });
34
+ return parseProjectJson(JSON.stringify(project));
35
+ };
36
+ const original = async name => {
37
+ const diagnostics = new DiagnosticsCollector();
38
+ const { doc } = await parse(new Uint8Array(await readFile(path.join(demos, `${name}.swf`))), diagnostics);
39
+ const { tags, symbolTable } = decode(doc, diagnostics);
40
+ return buildDisplayList(tags, symbolTable, diagnostics, { swfVersion: doc.header.version });
41
+ };
42
+ const noAssets = { readAsset: async () => null };
43
+
44
+ const artThief = new URL('../archive/Kongregate-Archiver/art-thief.swf', import.meta.url);
45
+ it('keeps Art Thief’s long frame action entry and both original records in Preview and native SWF', { skip: !existsSync(artThief) }, async () => {
46
+ const bytes = await readFile(artThief);
47
+ const diagnostics = new DiagnosticsCollector();
48
+ const decodeMovie = async data => decode((await parse(data, diagnostics)).doc, diagnostics);
49
+ function longAction(tags) {
50
+ const i = tags.findIndex((tag, index) => tag.type === 'DoAction' && tags[index - 1]?.code === 253 && tags[index - 1].data.length > 32767);
51
+ assert.ok(i > 0);
52
+ const action = linkedActionSource(tags[i].bytecode, tags[i - 1]);
53
+ return { entryOffset: action.entryOffset, bytes: Buffer.from(action.bytecode) };
54
+ }
55
+ const original = longAction((await decodeMovie(bytes)).tags);
56
+ assert.equal(original.entryOffset, 33569);
57
+ const { project } = await convertSwf(bytes, { name: 'Art Thief', storeMedia });
58
+ const saved = parseProjectJson(serializeProject(project));
59
+ const preview = await buildProjectMovie(saved, noAssets);
60
+ assert.deepEqual(longAction(preview.tags), original);
61
+ const published = await exportProjectSwf(saved);
62
+ assert.deepEqual(longAction((await decodeMovie(published.bytes)).tags), original);
63
+ });
64
+
65
+ /** Named instances, sprite frame counts, and text variables of a display list. */
66
+ function outline(displayList) {
67
+ const names = new Set(), variables = new Set(), spriteFrames = [];
68
+ const visit = frames => frames.forEach(frame => frame.places.forEach(place => place.name && names.add(place.name)));
69
+ visit(displayList.frames);
70
+ for (const character of Object.values(displayList.characters)) {
71
+ if (character.type === 'sprite') { visit(character.frames); spriteFrames.push(character.frameCount); }
72
+ if (character.type === 'text' && character.variableName) variables.add(character.variableName);
73
+ }
74
+ return { names: [...names].sort(), variables: [...variables].sort(), spriteFrames: spriteFrames.filter(count => count > 1).sort((a, b) => a - b) };
75
+ }
76
+
77
+ describe('project preview movie', () => {
78
+ for (const name of GAMES) {
79
+ it(`${name}: same instance names, clip timelines, and text variables as the SWF`, async () => {
80
+ const project = await importDemo(name);
81
+ const movie = await buildProjectMovie(project, noAssets);
82
+ const built = outline(movie.displayList), source = outline(await original(name));
83
+ assert.deepEqual(built.names, source.names);
84
+ assert.deepEqual(built.variables, source.variables);
85
+ assert.deepEqual(built.spriteFrames, source.spriteFrames);
86
+ assert.ok(movie.tags.some(tag => tag.type === 'DoAction'), 'frame scripts');
87
+ });
88
+ }
89
+
90
+ it('places objects where the SWF does, mirrored ones included', async () => {
91
+ const project = await importDemo('lane-relay');
92
+ const movie = await buildProjectMovie(project, noAssets);
93
+ const source = await original('lane-relay');
94
+ const named = frames => new Map(frames[0].places.filter(place => place.name).map(place => [place.name, place.matrix]));
95
+ const built = named(movie.displayList.frames);
96
+ for (const [name, matrix] of named(source.frames)) {
97
+ const mine = built.get(name);
98
+ assert.ok(Math.abs(mine.tx - matrix.tx) <= 20 && Math.abs(mine.ty - matrix.ty) <= 20, `${name} at ${mine.tx},${mine.ty} not ${matrix.tx},${matrix.ty}`);
99
+ }
100
+ });
101
+
102
+ it('keeps the visible part of partly shown images, in the editor and in Preview', async () => {
103
+ const project = await importDemo('swoof-intro');
104
+ const cropped = project.scenes.flatMap(scene => scene.elements).find(element => element.name === 'Image 103' && element.crop);
105
+ // Shape 103 shows 162.1 × 375 px of a 1536 px tall image scaled to 24.4%, from 44.2 px left of the image's edge.
106
+ assert.deepEqual([cropped.width, cropped.height], [162.1, 375]);
107
+ assert.ok(Math.abs(cropped.crop.x - 44.2 / 0.24412612915039061) < 0.01 && cropped.crop.y === 0);
108
+ assert.ok(Math.abs(cropped.crop.height - 1536) < 0.01);
109
+ assert.deepEqual(parseProjectJson(serializeProject(project)).scenes[0].elements.find(element => element.id === cropped.id).crop, cropped.crop);
110
+ // The crop alone places the image, so any bytes stand in for it.
111
+ const movie = await buildProjectMovie(project, { readAsset: async () => ({ bytes: Buffer.alloc(8), ext: 'png', mimeType: 'image/png' }) });
112
+ assert.ok(Object.values(movie.displayList.characters).some(character => character.type === 'shape'
113
+ && character.draws.some(draw => draw.fill?.type === 'bitmap' && Math.abs(draw.fill.matrix.tx - (-162.1 / 2 - cropped.crop.x * 162.1 / cropped.crop.width)) < 0.01)));
114
+ assert.throws(() => parseProjectJson(JSON.stringify({ ...JSON.parse(serializeProject(project)), scenes: [{ ...project.scenes[0], elements: [{ ...cropped, crop: { x: 0, y: 0, width: 0, height: 1 } }] }] })), /crop\.width/);
115
+ });
116
+
117
+ it('hides objects Flash scales to almost nothing instead of showing a 1% speck', async () => {
118
+ const project = await importDemo('swoof-intro');
119
+ const keys = project.scenes.flatMap(scene => scene.elements).flatMap(element => element.keyframes)
120
+ .filter(key => !key.blank && (key.scaleX === 0.01 || key.scaleY === 0.01));
121
+ assert.ok(keys.length > 0);
122
+ assert.ok(keys.every(key => key.opacity === 0));
123
+ });
124
+
125
+ it('keeps mirrored placements as mirror, not as a rotation', async () => {
126
+ const project = await importDemo('swoof-intro');
127
+ const mirrored = project.scenes.flatMap(scene => scene.elements).filter(element => element.keyframes.some(key => key.mirror));
128
+ assert.ok(mirrored.length > 0);
129
+ const again = parseProjectJson(serializeProject(project));
130
+ assert.equal(again.scenes.flatMap(scene => scene.elements).filter(element => element.keyframes.some(key => key.mirror)).length, mirrored.length);
131
+ });
132
+
133
+ it('shows Studio edits: changed text and a moved object', async () => {
134
+ const project = await importDemo('lane-relay');
135
+ const text = project.scenes[0].elements.find(element => element.type === 'text' && /Steer through/.test(element.text));
136
+ text.text = 'Edited in Studio';
137
+ for (const key of text.keyframes) delete key.text;
138
+ const clip = project.scenes[0].elements.find(element => element.type === 'symbol' && /^[A-Za-z_]\w*$/.test(element.name));
139
+ const before = (await buildProjectMovie(project, noAssets)).displayList.frames[0].places.find(place => place.name === clip.name).matrix;
140
+ for (const key of clip.keyframes) key.x += 10;
141
+ const movie = await buildProjectMovie(project, noAssets);
142
+ assert.ok(Object.values(movie.displayList.characters).some(character => character.type === 'text' && character.text === 'Edited in Studio'));
143
+ assert.equal(movie.displayList.frames[0].places.find(place => place.name === clip.name).matrix.tx, before.tx + 200);
144
+ });
145
+
146
+ it('turns typed actions into ActionScript for projects that mix both', async () => {
147
+ const project = await importDemo('neon-grid');
148
+ project.scenes[0].events.push({ frame: 1, trigger: 'frameEnter', actions: [{ type: 'stop', target: null }] });
149
+ const movie = await buildProjectMovie(project, noAssets);
150
+ assert.ok(movie.tags.some(tag => tag.type === 'DoAction' && tag.bytecode[0] === 0x07));
151
+ });
152
+
153
+ it('emits a playable bundle', async () => {
154
+ const dir = await mkdtemp(path.join(tmpdir(), 'studio-preview-'));
155
+ try {
156
+ const { folder } = await buildPreview(JSON.parse(serializeProject(await importDemo('neon-grid'))), { outDir: dir });
157
+ const data = await readFile(path.join(folder, 'movie-data.js'), 'utf8');
158
+ assert.match(data, /__swoofMovieData/);
159
+ assert.match(await readFile(path.join(folder, 'bundle.js'), 'utf8'), /winBeam/);
160
+ } finally {
161
+ await rm(dir, { recursive: true, force: true });
162
+ }
163
+ });
164
+
165
+ it('adds the video recorder before the player only when recording', async () => {
166
+ const project = JSON.parse(serializeProject(await importDemo('neon-grid')));
167
+ const dir = await mkdtemp(path.join(tmpdir(), 'studio-preview-'));
168
+ try {
169
+ const plain = await buildPreview(project, { outDir: path.join(dir, 'plain') });
170
+ const recorded = await buildPreview(project, { outDir: path.join(dir, 'recorded'), record: true });
171
+ const page = async folder => readFile(path.join(folder, 'index.html'), 'utf8');
172
+ assert.doesNotMatch(await page(plain.folder), /recorder\.js/);
173
+ const html = await page(recorded.folder);
174
+ assert.ok(html.indexOf('recorder.js') >= 0 && html.indexOf('recorder.js') < html.indexOf('bundle.js'), 'The recorder runs before the player');
175
+ assert.match(await readFile(path.join(recorded.folder, 'recorder.js'), 'utf8'), /swoofRecord/);
176
+ } finally {
177
+ await rm(dir, { recursive: true, force: true });
178
+ }
179
+ });
180
+ });
181
+
182
+ const archive = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../archive/flasharchive');
183
+ const importFile = async file => {
184
+ const { project } = await convertSwf(new Uint8Array(await readFile(file)), { name: 'game', storeMedia, idPrefix: 't' });
185
+ return parseProjectJson(JSON.stringify(project));
186
+ };
187
+ const sourceTags = async file => {
188
+ const diagnostics = new DiagnosticsCollector();
189
+ const { doc } = await parse(new Uint8Array(await readFile(file)), diagnostics);
190
+ return { ...decode(doc, diagnostics), version: doc.header.version };
191
+ };
192
+ /** Button handlers and clip-event handlers in a display list and its tags. */
193
+ function events(displayList, tags) {
194
+ const buttons = Object.values(displayList.characters).filter(character => character.type === 'button');
195
+ let clipEvents = 0;
196
+ const count = tag => { clipEvents += tag?.clipActions?.length ?? 0; };
197
+ tags.forEach(count);
198
+ for (const tag of tags) if (tag.type === 'Sprite') tag.tags.forEach(raw => count(raw.decoded));
199
+ return { buttonActions: buttons.reduce((sum, button) => sum + (button.actions?.length ?? 0), 0), clipEvents };
200
+ }
201
+
202
+ describe('Flash games keep their events', { skip: !existsSync(archive) && 'archive/flasharchive is not present' }, () => {
203
+ it('Snake keeps its keyboard-only buttons and every handler', async () => {
204
+ const file = path.join(archive, 'Snake.swf');
205
+ const movie = await buildProjectMovie(await importFile(file), noAssets);
206
+ const { tags, symbolTable, version } = await sourceTags(file);
207
+ const source = buildDisplayList(tags, symbolTable, new DiagnosticsCollector(), { swfVersion: version });
208
+ assert.deepEqual(events(movie.displayList, movie.tags), events(source, []));
209
+ const keyButtons = Object.values(movie.displayList.characters).filter(character => character.type === 'button' && character.actions.some(action => action.conditions.keyPress));
210
+ assert.ok(keyButtons.length >= 2);
211
+ });
212
+
213
+ it('Minesweeper runs component init code base class first', async () => {
214
+ const file = path.join(archive, 'Minesweeper.swf');
215
+ const project = await importFile(file);
216
+ const withInit = project.symbols.filter(symbol => symbol.initScript).map(symbol => symbol.linkage);
217
+ assert.deepEqual(withInit, ['FUIComponentSymbol', 'FLabelSymbol', 'FRadioButtonSymbol']);
218
+ const movie = await buildProjectMovie(project, noAssets);
219
+ const exported = new Map(movie.tags.find(tag => tag.type === 'ExportAssets').assets.map(asset => [asset.id, asset.name]));
220
+ const order = movie.tags.filter(tag => tag.type === 'DoInitAction').map(tag => exported.get(tag.spriteId));
221
+ assert.deepEqual(order, ['FUIComponentSymbol', 'FLabelSymbol', 'FRadioButtonSymbol']);
222
+ });
223
+
224
+ it('Pacman keeps clip actions, linkage names, masks, and tints', async () => {
225
+ const project = await importFile(path.join(archive, 'Pacman.swf'));
226
+ assert.ok(project.symbols.some(symbol => symbol.linkage === 'Ghost'));
227
+ const movie = await buildProjectMovie(project, noAssets);
228
+ assert.ok(movie.tags.some(tag => tag.type === 'ExportAssets' && tag.assets.some(asset => asset.name === 'Ghost')));
229
+ assert.equal(events(movie.displayList, movie.tags).clipEvents, 1);
230
+ const places = [movie.displayList.frames, ...Object.values(movie.displayList.characters).filter(c => c.type === 'sprite').map(c => c.frames)]
231
+ .flatMap(frames => frames.flatMap(frame => frame.places));
232
+ // Pac-Man's mouth is a mask swapped every frame at the same depth: every swap is still a
233
+ // mask, as in the SWF (one placement per mask shape there and here).
234
+ const diagnostics = new DiagnosticsCollector();
235
+ const { tags, symbolTable } = decode((await parse(new Uint8Array(await readFile(path.join(archive, 'Pacman.swf'))), diagnostics)).doc, diagnostics);
236
+ const original = buildDisplayList(tags, symbolTable, diagnostics, { swfVersion: 6 });
237
+ const masks = list => [list.frames, ...Object.values(list.characters).filter(c => c.type === 'sprite').map(c => c.frames)]
238
+ .flatMap(frames => frames.flatMap(frame => frame.places)).filter(place => place.clipDepth).map(place => place.clipDepth).sort();
239
+ assert.deepEqual(masks(movie.displayList), masks(original));
240
+ assert.ok(places.some(place => place.colorTransform?.rAdd === 255 && place.colorTransform.rMult === 0));
241
+ });
242
+
243
+ it('Minecraft TD keeps the menu footer crop, placement filters and blend modes after saving', async () => {
244
+ const file = path.join(archive, 'Minecraft TD.swf');
245
+ const project = parseProjectJson(serializeProject(await importFile(file)));
246
+ const { tags, symbolTable, version } = await sourceTags(file);
247
+ const source = buildDisplayList(tags, symbolTable, new DiagnosticsCollector(), { swfVersion: version });
248
+ const root = project.scenes[0];
249
+ const footer = root.elements.find(element => element.name === 'Image 560');
250
+ assert.deepEqual(footer.crop, { x: 0, y: 419, width: 640, height: 61 });
251
+ const movie = await buildProjectMovie(project, { readAsset: async asset => ({ bytes: Buffer.alloc(8), mimeType: asset.type, ext: 'bin' }) });
252
+ const effects = display => [display, ...Object.values(display.characters)].flatMap(timeline =>
253
+ (timeline.frames ?? []).flatMap(frame => frame.places.filter(place => place.filters?.length || place.blendMode > 1)
254
+ .map(place => inspect([place.depth, place.filters ?? [], place.blendMode ?? 1], { sorted: true, depth: null }))))
255
+ .sort();
256
+ assert.deepEqual(effects(movie.displayList), effects(source));
257
+ assert.ok(effects(source).length > 300);
258
+ });
259
+
260
+ it('Age of War attaches its MP3 stream to the owning sprite and retains the sample seek map', async () => {
261
+ const file = path.join(archive, 'Age of War.swf');
262
+ const { tags } = await sourceTags(file);
263
+ const original = tags.filter(tag => tag.type === 'Sprite').flatMap(sprite =>
264
+ encodeSoundStreamSegments(sprite.tags.map(tag => decodeTag(tag, null, new DiagnosticsCollector())))
265
+ .map(segment => segment.encoded?.streamSync).filter(Boolean));
266
+ assert.equal(original.length, 1);
267
+ const project = parseProjectJson(serializeProject(await importFile(file)));
268
+ const movie = await buildProjectMovie(project, { readAsset: async asset => ({ bytes: Buffer.alloc(8), mimeType: asset.type, ext: 'bin' }) });
269
+ const streams = movie.assetManifest.filter(asset => asset.stream);
270
+ assert.equal(streams.length, 1);
271
+ const [stream] = streams;
272
+ assert.ok(movie.displayList.characters[stream.spriteStream].hasStream);
273
+ assert.deepEqual(stream.streamSync, original[0]);
274
+ assert.equal(stream.streamSync.seekMap.length, 51);
275
+ });
276
+
277
+ it('Pacman keeps its sounds: clips in symbols, linkage names, and Preview plays both', async () => {
278
+ const stored = new Map();
279
+ const keep = async (data, info) => { const entry = await storeMedia(data, info); stored.set(entry.hash, data); return entry; };
280
+ const { project: raw, report } = await convertSwf(new Uint8Array(await readFile(path.join(archive, 'Pacman.swf'))), { name: 'game', storeMedia: keep, idPrefix: 't' });
281
+ // Flash writes an empty stream header into most sprites: nothing to convert or report.
282
+ assert.ok(!report.entries.some(entry => /Streaming sound/.test(entry.feature)));
283
+ const project = parseProjectJson(JSON.stringify(raw));
284
+ assert.equal(project.assets.filter(asset => asset.kind === 'audio').length, 13);
285
+ const linkage = project.assets.filter(asset => asset.linkage).map(asset => asset.linkage).sort();
286
+ assert.deepEqual(linkage, ['BG1', 'BG2', 'BG3', 'BGEyes', 'BGGhost', 'ExLife', 'NewLev']);
287
+ assert.ok(project.symbols.filter(symbol => symbol.audioClips?.length).length >= 1);
288
+
289
+ const readAsset = async asset => ({ bytes: stored.get(asset.hash), ext: asset.name.split('.').pop() || 'mp3', mimeType: asset.type });
290
+ const movie = await buildProjectMovie(project, { readAsset });
291
+ const audio = movie.assetManifest.filter(entry => entry.type === 'audio');
292
+ assert.equal(audio.length, 13);
293
+ assert.ok(audio.every(entry => entry.sampleRate > 0 && entry.sampleCount > 0 && movie.files.some(file => entry.path === `assets/${file.name}`)));
294
+ const exported = movie.tags.filter(tag => tag.type === 'ExportAssets').flatMap(tag => tag.assets);
295
+ for (const name of linkage) assert.ok(audio.some(entry => exported.some(asset => asset.id === entry.id && asset.name === name)), name);
296
+ // A symbol's original StartSound plays once when the source supplied no loop count.
297
+ const symbolCues = Object.values(movie.displayList.characters).filter(c => c.type === 'sprite')
298
+ .flatMap(sprite => sprite.frames.flatMap(frame => frame.sounds ?? []));
299
+ assert.ok(symbolCues.some(cue => audio.some(entry => entry.id === cue.soundId) && !cue.soundInfo.syncStop && cue.soundInfo.loopCount === null));
300
+ });
301
+
302
+ it('Motherload keeps clips scaled to almost nothing visible to its scripts', async () => {
303
+ const project = await importFile(path.join(archive, 'Motherload.swf'));
304
+ const tiny = type => [...project.scenes, ...project.symbols].flatMap(timeline => timeline.elements).filter(element => element.type === type)
305
+ .flatMap(element => element.keyframes).filter(key => !key.blank && (key.scaleX === 0.01 || key.scaleY === 0.01));
306
+ // A script may grow a clip from scale 0 without touching its opacity; shapes cannot be scripted.
307
+ assert.ok(tiny('symbol').length > 0 && tiny('symbol').every(key => key.opacity > 0));
308
+ assert.ok(tiny('path').length > 0 && tiny('path').every(key => key.opacity === 0));
309
+ });
310
+
311
+ it('Pacman shapes come back as whole-twip quadratic curves, as in the SWF', async () => {
312
+ const project = await importFile(path.join(archive, 'Pacman.swf'));
313
+ const movie = await buildProjectMovie(project, noAssets);
314
+ const draws = Object.values(movie.displayList.characters).filter(c => c.type === 'shape').flatMap(c => c.draws);
315
+ // Whole twips: swf2js stores every shape in its compact geometry encoding.
316
+ assert.ok(draws.length > 0);
317
+ assert.ok(draws.every(draw => isEncodablePath(draw.path)));
318
+ // Imported curves are elevated quadratics: each converts back to one curve, not four, and
319
+ // straight edges (drawn by Studio as cubics without handles) back to lines.
320
+ const seen = new Set();
321
+ let curved = 0;
322
+ for (const element of [...project.scenes, ...project.symbols].flatMap(timeline => timeline.elements)) {
323
+ if (element.type !== 'path') continue;
324
+ for (const key of element.keyframes) {
325
+ const contours = [key.points ?? element.points, ...(key.subpaths ?? element.subpaths ?? [])].filter(Boolean);
326
+ const shape = JSON.stringify([contours, key.width ?? element.width, key.height ?? element.height]);
327
+ if (seen.has(shape)) continue;
328
+ seen.add(shape);
329
+ for (const contour of contours) contour.forEach((point, index) => {
330
+ const next = contour[(index + 1) % contour.length];
331
+ if (point.handleOut.x || point.handleOut.y || next.handleIn.x || next.handleIn.y) curved++;
332
+ });
333
+ }
334
+ }
335
+ const curves = draws.flatMap(draw => draw.path).filter(command => command[0] === 'Q').length;
336
+ assert.ok(curves <= curved * 1.1, `${curves} curves in Preview for ${curved} curved segments`);
337
+ });
338
+ });
339
+
340
+ describe('Studio model features in playback', () => {
341
+ it('draws compound paths even-odd and keeps them through save', async () => {
342
+ const project = await importFile(path.join(archive, 'Snake.swf')).catch(() => null) ?? await importDemo('swoof-intro');
343
+ const compound = [...project.scenes, ...(project.symbols ?? [])].flatMap(timeline => timeline.elements).find(element => element.subpaths?.length);
344
+ assert.ok(compound, 'an imported shape with holes');
345
+ const again = parseProjectJson(serializeProject(project));
346
+ assert.equal([...again.scenes, ...(again.symbols ?? [])].flatMap(t => t.elements).find(e => e.id === compound.id).subpaths.length, compound.subpaths.length);
347
+ const movie = await buildProjectMovie(project, noAssets);
348
+ assert.ok(Object.values(movie.displayList.characters).some(c => c.type === 'shape' && c.draws.some(d => d.evenOdd)));
349
+ });
350
+
351
+ it('follows Studio layer order for new objects and plays instances as set', async () => {
352
+ const project = await importDemo('neon-grid');
353
+ const scene = project.scenes[0];
354
+ const clip = scene.elements.find(element => element.type === 'symbol' && project.symbols.find(s => s.id === element.symbolId)?.durationFrames > 1);
355
+ clip.symbolMode = 'single';
356
+ clip.firstFrame = 2;
357
+ const pose = { frame: 1, x: 0, y: 0, width: 50, height: 50, scaleX: 1, scaleY: 1, rotation: 0, skew: 0, opacity: 1, tween: 'hold' };
358
+ const bottom = { id: 'new-shape', name: 'Backdrop', type: 'rectangle', layerId: scene.layers[0].id, fill: '#336699', ...pose, keyframes: [pose] };
359
+ delete bottom.frame; delete bottom.tween;
360
+ scene.elements.unshift(bottom);
361
+ const parsed = parseProjectJson(serializeProject(project));
362
+ const movie = await buildProjectMovie(parsed, noAssets);
363
+ const first = movie.displayList.frames[0].places;
364
+ const clipPlace = movie.tags.find(tag => tag.type === 'PlaceObject2' && tag.name === clip.name);
365
+ assert.deepEqual(clipPlace.clipActions[0].bytecode.slice(0, 3), new Uint8Array([0x81, 2, 0]));
366
+ assert.equal(clipPlace.clipActions[0].bytecode[3], 1); // gotoAndStop(2)
367
+ const depths = first.filter(place => !place.remove).map(place => place.depth);
368
+ assert.deepEqual(depths, [...depths].sort((a, b) => a - b));
369
+ });
370
+
371
+ it('turns embedded-font static text into outlines', async () => {
372
+ const project = await importFile(path.join(archive, 'Snake.swf')).catch(() => null);
373
+ if (!project) return;
374
+ const texts = [...project.scenes, ...(project.symbols ?? [])].flatMap(t => t.elements).filter(e => e.type === 'text');
375
+ const outlined = [...project.scenes, ...(project.symbols ?? [])].flatMap(t => t.elements).filter(e => e.type === 'path' && e.subpaths?.length > 3);
376
+ assert.ok(outlined.length > 0);
377
+ assert.ok(texts.every(text => text.field), 'remaining text is dynamic or input text');
378
+ });
379
+
380
+ it('applies color transforms in poses and tweens them', async () => {
381
+ const { poseAt } = await import('./src/model.js');
382
+ const element = { type: 'rectangle', x: 0, y: 0, width: 10, height: 10, scaleX: 1, scaleY: 1, rotation: 0, skew: 0, opacity: 1,
383
+ keyframes: [{ frame: 1, x: 0, y: 0, width: 10, height: 10, scaleX: 1, scaleY: 1, rotation: 0, skew: 0, opacity: 1, tween: 'linear' },
384
+ { frame: 3, x: 0, y: 0, width: 10, height: 10, scaleX: 1, scaleY: 1, rotation: 0, skew: 0, opacity: 1, tween: 'linear',
385
+ colorTransform: { redMultiplier: 0, greenMultiplier: 0, blueMultiplier: 0, redOffset: 255, greenOffset: 0, blueOffset: 0 } }] };
386
+ assert.equal(poseAt(element, 1).colorTransform, undefined);
387
+ assert.deepEqual(poseAt(element, 2).colorTransform, { redMultiplier: 0.5, greenMultiplier: 0.5, blueMultiplier: 0.5, redOffset: 127.5, greenOffset: 0, blueOffset: 0 });
388
+ });
389
+ });
390
+
391
+ describe('preview route', () => {
392
+ let dir, server, base;
393
+ before(async () => {
394
+ dir = await mkdtemp(path.join(tmpdir(), 'studio-preview-route-'));
395
+ server = createStudioServer({ projectsDir: dir });
396
+ server.listen(0, '127.0.0.1');
397
+ await once(server, 'listening');
398
+ base = `http://127.0.0.1:${server.address().port}`;
399
+ });
400
+ after(async () => {
401
+ server.close();
402
+ await rm(dir, { recursive: true, force: true });
403
+ });
404
+
405
+ it('builds the posted project and serves it', async () => {
406
+ const project = JSON.parse(serializeProject(await importDemo('neon-grid')));
407
+ const response = await fetch(`${base}/api/preview`, { method: 'POST', body: JSON.stringify({ project }), headers: { 'Content-Type': 'application/json' } });
408
+ assert.equal(response.status, 201);
409
+ const { url } = await response.json();
410
+ const page = await fetch(base + url);
411
+ assert.equal(page.status, 200);
412
+ assert.match(await page.text(), /<canvas|bundle\.js/);
413
+ assert.equal((await fetch(`${base}/api/preview/abcdef/`)).status, 404);
414
+ });
415
+
416
+ it('keeps a preview audio URL readable after a server restart, including byte ranges', async () => {
417
+ const project = JSON.parse(serializeProject(await importDemo('neon-grid')));
418
+ const data = Buffer.from('ID3 audio transport test');
419
+ project.assets = [{ id: 'tone', kind: 'audio', name: 'tone.mp3', data: 'data:audio/mpeg;base64,' + data.toString('base64') }];
420
+ project.scenes[0].audioClips = [{ id: 'cue', assetId: 'tone', start: 1, end: 1 }];
421
+ const options = { method: 'POST', body: JSON.stringify({ project }), headers: { 'Content-Type': 'application/json' } };
422
+ const built = await fetch(base + '/api/preview', options);
423
+ assert.equal(built.status, 201);
424
+ const { url } = await built.json();
425
+ const runtime = await buildProjectMovie(parseProjectJson(JSON.stringify(project)), {
426
+ readAsset: async () => ({ bytes: data, mimeType: 'audio/mpeg', ext: 'mp3' }),
427
+ });
428
+ const soundUrl = url + runtime.assetManifest.find(asset => asset.type === 'audio').path;
429
+ const getAudio = host => fetch(host + soundUrl, { headers: { Range: 'bytes=1-3' } });
430
+ assert.equal((await getAudio(base)).status, 206);
431
+ const restarted = createStudioServer({ projectsDir: dir });
432
+ restarted.listen(0, '127.0.0.1');
433
+ await once(restarted, 'listening');
434
+ try {
435
+ const response = await getAudio(`http://127.0.0.1:${restarted.address().port}`);
436
+ assert.equal(response.status, 206);
437
+ assert.equal(response.headers.get('content-type'), 'audio/mpeg');
438
+ assert.equal(response.headers.get('content-range'), `bytes 1-3/${data.length}`);
439
+ assert.deepEqual(Buffer.from(await response.arrayBuffer()), data.subarray(1, 4));
440
+ } finally {
441
+ restarted.close();
442
+ }
443
+ });
444
+
445
+ it('rejects an invalid project', async () => {
446
+ const response = await fetch(`${base}/api/preview`, { method: 'POST', body: JSON.stringify({ project: { scenes: 3 } }) });
447
+ assert.equal(response.status, 400);
448
+ });
449
+
450
+ it('downloads HTML with unsaved edits and stored media embedded', async () => {
451
+ const audio = 'data:audio/mpeg;base64,' + Buffer.from('ID3 audio transport test').toString('base64');
452
+ const project = { stage: { width: 400, height: 300, frameRate: 12 },
453
+ scenes: [{ id: 'main', durationFrames: 1, elements: [], audioClips: [{ id: 'clip', assetId: 'tone', start: 1, end: 1 }] }],
454
+ assets: [{ id: 'tone', name: 'tone.mp3', kind: 'audio', data: audio }] };
455
+ const post = (url, body) => fetch(base + url, { method: 'POST', body: JSON.stringify(body), headers: { 'Content-Type': 'application/json' } });
456
+ const created = await post('/api/projects', { name: 'Demo', project });
457
+ assert.equal(created.status, 201);
458
+ const { id } = await created.json();
459
+ const { project: edited } = await (await fetch(base + '/api/projects/' + id)).json();
460
+ assert.ok(edited.assets[0].hash);
461
+ edited.stage.width = 640;
462
+ const response = await post('/api/export/html', { project: edited, projectId: id, name: 'Café: <Cut>' });
463
+ assert.equal(response.status, 200);
464
+ assert.match(response.headers.get('content-type'), /^text\/html/);
465
+ assert.equal(decodeURIComponent(response.headers.get('content-disposition')), "attachment; filename*=UTF-8''Café- -Cut-.html");
466
+ const html = await response.text();
467
+ assert.match(html, /<title>Café: &lt;Cut&gt;<\/title>/);
468
+ assert.match(html, /<canvas id="stage" width="640"/);
469
+ const scripts = [...html.matchAll(/<script src="([^"]+)"><\/script>/g)].map(match => {
470
+ assert.ok(match[1].startsWith('data:text/javascript;base64,'));
471
+ return Buffer.from(match[1].split(',')[1], 'base64').toString();
472
+ });
473
+ assert.ok(scripts.some(script => script.includes(audio)));
474
+ });
475
+ });
@@ -0,0 +1,32 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { parseProjectJson, serializeProject } from './src/project-io.js';
4
+ import { readTransition, transitionProgress } from './src/scene-transition.js';
5
+
6
+ const stage = { width: 800, height: 450, frameRate: 24 };
7
+ const scene = { id: 'intro', elements: [] };
8
+ const settings = { type: 'crossfade', durationFrames: 12, easing: 'easeIn' };
9
+ const parse = doc => parseProjectJson(JSON.stringify(doc));
10
+
11
+ test('legacy scenes cut immediately and typed entry transitions survive a project round trip', () => {
12
+ const doc = parse({ stage, scenes: [scene, { ...scene, id: 'end', transition: settings }] });
13
+ assert.equal(doc.scenes[0].transition, undefined);
14
+ assert.deepEqual(doc.scenes[1].transition, settings);
15
+ assert.deepEqual(parseProjectJson(serializeProject(doc)), doc);
16
+ assert.deepEqual(readTransition({ ...settings, type: 'wipe' }), { ...settings, type: 'wipe' });
17
+ });
18
+
19
+ test('entry transitions reject unsupported effects, invalid timing and symbol attachments', () => {
20
+ for (const transition of [null, '', {}, { ...settings, type: 'spin' }, { ...settings, easing: 'hold' },
21
+ ...[undefined, 1.5, -1, 0, 601, '12'].map(durationFrames => ({ ...settings, durationFrames }))]) {
22
+ assert.throws(() => parse({ stage, scenes: [{ ...scene, transition }] }));
23
+ }
24
+ assert.throws(() => parse({ stage, scenes: [scene], symbols: [{ id: 'symbol', elements: [], transition: settings }] }), /Only movie scenes/);
25
+ });
26
+
27
+ test('transition easing advances on authored frame boundaries and ends exactly at duration', () => {
28
+ assert.equal(transitionProgress(settings, -1, 24), 0);
29
+ assert.equal(transitionProgress(settings, 249, 24), (5 / 12) ** 2);
30
+ assert.equal(transitionProgress(settings, 250, 24), 0.25);
31
+ assert.equal(transitionProgress(settings, 5000, 24), 1);
32
+ });
@@ -0,0 +1,27 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { readdir, readFile } from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { precompileCompanionSwfs } from '../../swf2js/emitter/embedded-swf.js';
6
+
7
+ const installedArchive = fileURLToPath(new URL('../../archive/Swf/', import.meta.url));
8
+
9
+ // An uploaded file has no neighboring files. Match its original bytes to installed
10
+ // archive packages so the CLI and Studio can share their local companion movies.
11
+ export async function archivedCompanions(hash, diagnostics, archive = installedArchive) {
12
+ if (!hash) return [];
13
+ const entries = await readdir(archive).catch(error => {
14
+ if (error.code === 'ENOENT') return [];
15
+ throw error;
16
+ });
17
+ const suffix = '.companions.json';
18
+ for (const manifest of entries.filter(entry => entry.endsWith(suffix))) {
19
+ const filename = manifest.slice(0, -suffix.length) + '.swf';
20
+ if (!entries.includes(filename)) continue;
21
+ const source = path.join(archive, filename);
22
+ if (createHash('sha256').update(await readFile(source)).digest('hex') === hash) {
23
+ return precompileCompanionSwfs(source, [], diagnostics);
24
+ }
25
+ }
26
+ return [];
27
+ }
@@ -0,0 +1,91 @@
1
+ // AS3 constructs library classes that may never appear on an editable timeline. Keep their
2
+ // native definitions and dependencies, including binary assets and font/scale-grid metadata.
3
+ import { deflateSync, inflateSync } from 'node:zlib';
4
+ import { TAG } from '../../swf2js/decoder/tag-types.js';
5
+ import { decode } from '../../swf2js/decoder/tag-decoder.js';
6
+ import { SymbolTable } from '../../swf2js/decoder/symbol-table.js';
7
+ import { encodeTag, writeSwf } from '../../swf2js/encoder/swf-writer.js';
8
+ import { parse } from '../../swf2js/parser/swf-parser.js';
9
+ import { DiagnosticsCollector } from '../../swf2js/util/diagnostics.js';
10
+ import { badRequest } from './http.js';
11
+
12
+ const definitions = new Set(Object.entries(TAG).filter(([name]) => name.startsWith('Define') &&
13
+ name !== 'DefineSceneAndFrameLabelData').map(([, code]) => code));
14
+ const metadata = new Set([TAG.JPEGTables, TAG.CSMTextSettings, TAG.VideoFrame]);
15
+ const isLibraryTag = tag => definitions.has(tag.code) || metadata.has(tag.code);
16
+
17
+ const FONT_TAGS = new Set([TAG.DefineFont, TAG.DefineFont2, TAG.DefineFont3, TAG.DefineFont4, TAG.DefineFontInfo,
18
+ TAG.DefineFontInfo2, TAG.DefineFontAlignZones, TAG.DefineFontName]);
19
+
20
+ export function packClassLibrary(doc, fontIds = null) {
21
+ const tags = doc.tags.filter(tag => fontIds
22
+ ? FONT_TAGS.has(tag.code) && fontIds.has(tag.data[0] | tag.data[1] << 8)
23
+ : isLibraryTag(tag)).map(tag => encodeTag(tag.code, tag.data));
24
+ return Buffer.from(writeSwf({ ...doc.header, frameCount: 1, tags, deflate: deflateSync })).toString('base64');
25
+ }
26
+
27
+ async function readLibrary(script) {
28
+ const packed = Buffer.from(script.bytecode, 'base64');
29
+ if (packed.length < 8 || packed.toString('ascii', 0, 3) !== 'CWS') throw badRequest('Invalid AS3 class library');
30
+ const limit = 256 * 1024 * 1024;
31
+ const length = packed.readUInt32LE(4);
32
+ if (length < 8 || length > limit) throw badRequest('Invalid AS3 library size');
33
+ let body;
34
+ try { body = inflateSync(packed.subarray(8), { maxOutputLength: length - 8 }); }
35
+ catch { throw badRequest('Invalid compressed AS3 library'); }
36
+ if (body.length !== length - 8) throw badRequest('Invalid AS3 library length');
37
+ const diagnostics = new DiagnosticsCollector();
38
+ const { doc } = await parse(Buffer.concat([Buffer.from('FWS'), packed.subarray(3, 8), body]), diagnostics);
39
+ return { doc, diagnostics };
40
+ }
41
+
42
+ async function openNativeClasses(project, record) {
43
+ const script = project.scripts.find(item => item.id === record.library);
44
+ const { doc, diagnostics } = await readLibrary(script);
45
+ const { tags, symbolTable } = decode(doc, diagnostics);
46
+ // A Studio symbol already on the stage remains editable everywhere its original ID is used.
47
+ const live = new Set((project.symbols ?? []).map(symbol => symbol.id));
48
+ const ids = new Map(record.symbols.filter(ref => live.has(ref.symbol)).map(ref => [ref.symbol, ref.id]));
49
+ const editing = new Set(ids.values());
50
+ const native = new SymbolTable();
51
+ for (const id of symbolTable.ids()) if (!editing.has(id)) native.set(id, symbolTable.get(id));
52
+ const rawTags = doc.tags.filter((raw, i) => isLibraryTag(raw) &&
53
+ !(editing.has(tags[i]?.characterId) && (symbolTable.get(tags[i].characterId) === tags[i] || raw.code === TAG.DefineScalingGrid)));
54
+ return { ids, maxId: Math.max(0, ...symbolTable.ids()), rawTags, tags: tags.filter(tag => !editing.has(tag?.characterId)),
55
+ symbolTable: native, sourceLength: record.sourceLength, sourceHash: record.sourceHash };
56
+ }
57
+
58
+ /** Imported font libraries can be merged into another project. Allocate a fresh native ID
59
+ * for each source font, including its name and alignment records. */
60
+ export async function openClassLibrary(project) {
61
+ const record = project.scenes.flatMap(scene => scene.avm2 ?? []).find(record => record.library);
62
+ let library = record ? await openNativeClasses(project, record) : null;
63
+ const fontIds = new Map();
64
+ if (record) fontIds.set(record.library, new Map(library.symbolTable.ids().filter(id => library.symbolTable.get(id)?.type === 'Font').map(id => [id, id])));
65
+ const references = new Set([...project.scenes, ...(project.symbols ?? [])]
66
+ .flatMap(timeline => timeline.elements.map(element => element.field?.fontLibrary)).filter(Boolean));
67
+ for (const reference of references) {
68
+ if (fontIds.has(reference)) continue;
69
+ const script = project.scripts.find(item => item.id === reference);
70
+ const { doc, diagnostics } = await readLibrary(script);
71
+ if (!library) library = { ids: new Map(), maxId: 0, rawTags: [], tags: [], symbolTable: new SymbolTable() };
72
+ const remap = new Map();
73
+ const mapped = doc.tags.filter(tag => FONT_TAGS.has(tag.code)).map(tag => {
74
+ const from = tag.data[0] | tag.data[1] << 8;
75
+ if (!remap.has(from)) remap.set(from, ++library.maxId);
76
+ const to = remap.get(from);
77
+ if (to > 65535) throw badRequest('Font library exceeds SWF character IDs');
78
+ const data = Uint8Array.from(tag.data);
79
+ data[0] = to & 255;
80
+ data[1] = to >> 8;
81
+ return { ...tag, data };
82
+ });
83
+ const { tags, symbolTable } = decode({ ...doc, tags: mapped }, diagnostics);
84
+ for (const id of symbolTable.ids()) library.symbolTable.set(id, symbolTable.get(id));
85
+ library.rawTags.push(...mapped);
86
+ library.tags.push(...tags);
87
+ fontIds.set(reference, remap);
88
+ }
89
+ if (library) library.fontIds = fontIds;
90
+ return library;
91
+ }