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.
- package/README.md +81 -14
- package/package.json +11 -7
- package/studio/actionscript-roundtrip.test.js +54 -0
- package/studio/actionscript-scripts.test.js +169 -0
- package/studio/animated-image.test.js +137 -0
- package/studio/arithmetic.test.js +16 -0
- package/studio/as3-import.test.js +110 -0
- package/studio/audio-info.test.js +44 -0
- package/studio/components.test.js +152 -0
- package/studio/document-editing.test.js +92 -0
- package/studio/examples/01-space-mission.json +1628 -0
- package/studio/examples/02-clockwork-vault.json +1079 -0
- package/studio/examples/03-neon-synth.json +1364 -0
- package/studio/examples/04-kinetic-poster.json +923 -0
- package/studio/examples/05-signal-relay.json +1131 -0
- package/studio/examples/06-calculator.json +564 -0
- package/studio/frame-editing.test.js +129 -0
- package/studio/frame-events.test.js +117 -0
- package/studio/groups.test.js +88 -0
- package/studio/index.html +962 -0
- package/studio/interaction-triggers.test.js +37 -0
- package/studio/linked-actions.test.js +48 -0
- package/studio/lottie.test.js +208 -0
- package/studio/masks.test.js +43 -0
- package/studio/media-assets.test.js +62 -0
- package/studio/paint-tools.test.js +60 -0
- package/studio/playback.test.js +17 -0
- package/studio/project-io.test.js +405 -0
- package/studio/project-preview.test.js +475 -0
- package/studio/scene-transition.test.js +32 -0
- package/studio/server/archive-companions.js +27 -0
- package/studio/server/as3-library.js +91 -0
- package/studio/server/assets.js +162 -0
- package/studio/server/audio-info.js +82 -0
- package/studio/server/font-files.js +332 -0
- package/studio/server/http.js +135 -0
- package/studio/server/linked-actions.js +93 -0
- package/studio/server/png-decode.js +1 -0
- package/studio/server/project-movie.js +1164 -0
- package/studio/server/project-preview.js +152 -0
- package/studio/server/projects.js +370 -0
- package/studio/server/report.js +29 -0
- package/studio/server/routes.js +93 -0
- package/studio/server/swf-authoring.js +90 -0
- package/studio/server/swf-control-runtime.as +513 -0
- package/studio/server/swf-controls.js +119 -0
- package/studio/server/swf-export.js +293 -0
- package/studio/server/swf-import.js +1675 -0
- package/studio/server/swf-morphs.js +64 -0
- package/studio/server/swf-routes.js +42 -0
- package/studio/server/swf-streams.js +80 -0
- package/studio/server/swf-transition-runtime.as +52 -0
- package/studio/server/tween-recovery.js +106 -0
- package/studio/server-api.test.js +283 -0
- package/studio/server.js +320 -0
- package/studio/src/animated-image.js +423 -0
- package/studio/src/appearance-inspector.js +63 -0
- package/studio/src/arithmetic.js +50 -0
- package/studio/src/authored-controls.js +42 -0
- package/studio/src/busy.js +41 -0
- package/studio/src/canvas.js +430 -0
- package/studio/src/clipper-browser.js +2 -0
- package/studio/src/color-transform.js +38 -0
- package/studio/src/component-inspector.js +126 -0
- package/studio/src/components.js +268 -0
- package/studio/src/display-frame.js +262 -0
- package/studio/src/document-editing.js +69 -0
- package/studio/src/event-editor.js +150 -0
- package/studio/src/frame-editing.js +150 -0
- package/studio/src/frame-events.js +128 -0
- package/studio/src/frame-image.js +28 -0
- package/studio/src/groups.js +125 -0
- package/studio/src/handler-editor.js +122 -0
- package/studio/src/history.js +83 -0
- package/studio/src/imported-paths.js +99 -0
- package/studio/src/index.js +3582 -0
- package/studio/src/interaction-triggers.js +42 -0
- package/studio/src/json-patch.js +77 -0
- package/studio/src/layer-icons.js +25 -0
- package/studio/src/lottie-export.js +948 -0
- package/studio/src/lottie-import.js +1138 -0
- package/studio/src/masks.js +69 -0
- package/studio/src/media-assets.js +188 -0
- package/studio/src/media-library.js +193 -0
- package/studio/src/model.js +431 -0
- package/studio/src/numeric-fields.js +46 -0
- package/studio/src/object-list.js +57 -0
- package/studio/src/paint-tools.js +76 -0
- package/studio/src/placement-effects.js +74 -0
- package/studio/src/playback.js +10 -0
- package/studio/src/preview-audio.js +64 -0
- package/studio/src/preview-interactions.js +106 -0
- package/studio/src/preview-recorder.js +335 -0
- package/studio/src/preview-surface.js +338 -0
- package/studio/src/project-io.js +905 -0
- package/studio/src/project-session.js +375 -0
- package/studio/src/projects-dialog.js +319 -0
- package/studio/src/scene-transition.js +129 -0
- package/studio/src/script-editor.js +175 -0
- package/studio/src/script-references.js +74 -0
- package/studio/src/scripted-controls.js +146 -0
- package/studio/src/scripts.js +185 -0
- package/studio/src/stage-guides.js +101 -0
- package/studio/src/svg-animation.js +416 -0
- package/studio/src/svg-context.js +522 -0
- package/studio/src/svg-frame.js +413 -0
- package/studio/src/svg-import.js +1208 -0
- package/studio/src/swf-recording.js +104 -0
- package/studio/src/symbol-library.js +39 -0
- package/studio/src/symbols.js +62 -0
- package/studio/src/text-fields.js +58 -0
- package/studio/src/theme.js +43 -0
- package/studio/src/timeline.js +321 -0
- package/studio/src/vector-cut.js +103 -0
- package/studio/src/vector-geometry.js +254 -0
- package/studio/src/vector-style.js +146 -0
- package/studio/src/video-encode.js +84 -0
- package/studio/src/video-export.js +331 -0
- package/studio/src/video-mux.js +339 -0
- package/studio/src/video-playback.js +281 -0
- package/studio/src/workspace.js +344 -0
- package/studio/stroke-style.test.js +119 -0
- package/studio/styles.css +1547 -0
- package/studio/svg-export.test.js +162 -0
- package/studio/svg-import.test.js +318 -0
- package/studio/swf-authoring.test.js +140 -0
- package/studio/swf-export.test.js +324 -0
- package/studio/swf-import.test.js +489 -0
- package/studio/symbols.test.js +68 -0
- package/studio/tests/accessibility-interactions.mjs +138 -0
- package/studio/tests/appearance-interactions.mjs +103 -0
- package/studio/tests/control-interactions.mjs +60 -0
- package/studio/tests/event-interactions.mjs +117 -0
- package/studio/tests/external-resources.mjs +174 -0
- package/studio/tests/frame-image.mjs +71 -0
- package/studio/tests/html-export.mjs +68 -0
- package/studio/tests/import-files.mjs +131 -0
- package/studio/tests/lottie.mjs +125 -0
- package/studio/tests/mask-interactions.mjs +148 -0
- package/studio/tests/media-interactions.mjs +109 -0
- package/studio/tests/paint-interactions.mjs +64 -0
- package/studio/tests/project-interactions.mjs +244 -0
- package/studio/tests/script-interactions.mjs +178 -0
- package/studio/tests/scripted-control-interactions.mjs +107 -0
- package/studio/tests/svg-export.mjs +149 -0
- package/studio/tests/text-field-interactions.mjs +64 -0
- package/studio/tests/theme-interactions.mjs +53 -0
- package/studio/tests/timeline-browser.mjs +507 -0
- package/studio/tests/transition-interactions.mjs +94 -0
- package/studio/tests/trigger-interactions.mjs +93 -0
- package/studio/tests/video-export.mjs +243 -0
- package/studio/tests/workspace-interactions.mjs +226 -0
- package/studio/tween-recovery.test.js +31 -0
- package/studio/vector-style.test.js +56 -0
- package/studio/video-export.test.js +326 -0
- package/studiospec/actionscript.md +88 -0
- package/studiospec/architecture.md +378 -0
- package/studiospec/controls.md +100 -0
- package/studiospec/file-support.md +268 -0
- package/studiospec/lottie.md +69 -0
- package/studiospec/requirements.md +135 -0
- package/studiospec/stroke-style.md +95 -0
- package/studiospec/svg-export.md +83 -0
- package/studiospec/svg-import.md +139 -0
- package/studiospec/swooflib-integration.md +115 -0
- package/studiospec/tasks.md +573 -0
- package/studiospec/video-export.md +127 -0
- package/swf2js/__tests__/actionscript.test.js +1609 -0
- package/swf2js/__tests__/adpcm-audio.test.js +43 -0
- package/swf2js/__tests__/as2-compiler.test.js +153 -0
- package/swf2js/__tests__/as3-mixed-depth.test.js +498 -0
- package/swf2js/__tests__/authored-sprite-hit.test.js +118 -0
- package/swf2js/__tests__/authored-sprite-sizing.test.js +164 -0
- package/swf2js/__tests__/avm1-action-prefix.test.js +134 -0
- package/swf2js/__tests__/avm1-attach-movie.test.js +1151 -0
- package/swf2js/__tests__/avm1-boxhead-budget.test.js +73 -0
- package/swf2js/__tests__/avm1-cfg-bubble-tanks.test.js +101 -0
- package/swf2js/__tests__/avm1-cfg-mario-kart.test.js +184 -0
- package/swf2js/__tests__/avm1-cfg-mario.test.js +31 -0
- package/swf2js/__tests__/avm1-cfg-pacman.test.js +49 -0
- package/swf2js/__tests__/avm1-checkers-gameplay.test.js +122 -0
- package/swf2js/__tests__/avm1-clip-actions.test.js +2002 -0
- package/swf2js/__tests__/avm1-clone-drag.test.js +626 -0
- package/swf2js/__tests__/avm1-decompiler.test.js +102 -0
- package/swf2js/__tests__/avm1-dynamic-locals.test.js +159 -0
- package/swf2js/__tests__/avm1-formal-parameters.test.js +71 -0
- package/swf2js/__tests__/avm1-key-events.test.js +52 -0
- package/swf2js/__tests__/avm1-load-bitmap.test.js +75 -0
- package/swf2js/__tests__/avm1-loading-host-actions.test.js +764 -0
- package/swf2js/__tests__/avm1-multibyte-strings.test.js +63 -0
- package/swf2js/__tests__/avm1-pacman-gameplay.test.js +115 -0
- package/swf2js/__tests__/avm1-shape-hittest.test.js +311 -0
- package/swf2js/__tests__/avm1-shared-bodies.test.js +57 -0
- package/swf2js/__tests__/avm1-shared-runtime.test.js +1364 -0
- package/swf2js/__tests__/avm1-snake-gameplay.test.js +139 -0
- package/swf2js/__tests__/avm1-super.test.js +70 -0
- package/swf2js/__tests__/avm1-target-path.test.js +325 -0
- package/swf2js/__tests__/avm1-try.test.js +229 -0
- package/swf2js/__tests__/avm2-activation-closures.test.js +65 -0
- package/swf2js/__tests__/avm2-applytype.test.js +180 -0
- package/swf2js/__tests__/avm2-call-ops.test.js +232 -0
- package/swf2js/__tests__/avm2-callsuperid.test.js +231 -0
- package/swf2js/__tests__/avm2-class-initializer.test.js +219 -0
- package/swf2js/__tests__/avm2-custom-namespace.test.js +139 -0
- package/swf2js/__tests__/avm2-describe-type.test.js +96 -0
- package/swf2js/__tests__/avm2-dictionary.test.js +96 -0
- package/swf2js/__tests__/avm2-domain-memory.test.js +332 -0
- package/swf2js/__tests__/avm2-e4x.test.js +326 -0
- package/swf2js/__tests__/avm2-exceptions.test.js +81 -0
- package/swf2js/__tests__/avm2-findprop.test.js +110 -0
- package/swf2js/__tests__/avm2-getlex.test.js +166 -0
- package/swf2js/__tests__/avm2-global-slot.test.js +106 -0
- package/swf2js/__tests__/avm2-interface.test.js +95 -0
- package/swf2js/__tests__/avm2-multiname-precedence.test.js +148 -0
- package/swf2js/__tests__/avm2-named-namespace-types.test.js +106 -0
- package/swf2js/__tests__/avm2-optional-args.test.js +100 -0
- package/swf2js/__tests__/avm2-outer-scopes.test.js +101 -0
- package/swf2js/__tests__/avm2-package-internal-class.test.js +106 -0
- package/swf2js/__tests__/avm2-protected-namespace.test.js +105 -0
- package/swf2js/__tests__/avm2-protected.test.js +214 -0
- package/swf2js/__tests__/avm2-qwop-gameplay.test.js +116 -0
- package/swf2js/__tests__/avm2-runtime-namespaces.test.js +159 -0
- package/swf2js/__tests__/avm2-script-traits.test.js +89 -0
- package/swf2js/__tests__/avm2-shared-runtime.test.js +52 -0
- package/swf2js/__tests__/avm2-slot-ops.test.js +117 -0
- package/swf2js/__tests__/avm2-type-ops.test.js +224 -0
- package/swf2js/__tests__/bevel-filter.test.js +116 -0
- package/swf2js/__tests__/bitmap-button-mask.test.js +106 -0
- package/swf2js/__tests__/bitmap-data-draw.test.js +388 -0
- package/swf2js/__tests__/bitmap-decoder.test.js +108 -0
- package/swf2js/__tests__/bitmapdata-color-bounds.test.js +70 -0
- package/swf2js/__tests__/bitmapdata-copy-channel.test.js +91 -0
- package/swf2js/__tests__/bitmapdata-copy-pixels.test.js +136 -0
- package/swf2js/__tests__/bitmapdata-fill-compare.test.js +241 -0
- package/swf2js/__tests__/bitmapdata-filter.test.js +232 -0
- package/swf2js/__tests__/bitmapdata-hit-test.test.js +71 -0
- package/swf2js/__tests__/bitmapdata-merge.test.js +84 -0
- package/swf2js/__tests__/bitmapdata-palette-map.test.js +92 -0
- package/swf2js/__tests__/bitmapdata-pixels-io.test.js +198 -0
- package/swf2js/__tests__/bitmapdata-threshold.test.js +97 -0
- package/swf2js/__tests__/bitmapdata-vector.test.js +82 -0
- package/swf2js/__tests__/blur-filter.test.js +48 -0
- package/swf2js/__tests__/bundle-emitter.test.js +394 -0
- package/swf2js/__tests__/button-actions.test.js +370 -0
- package/swf2js/__tests__/button-color-transform.test.js +48 -0
- package/swf2js/__tests__/button-decoder.test.js +106 -0
- package/swf2js/__tests__/button-hit-test.test.js +825 -0
- package/swf2js/__tests__/button-scaling-grid.test.js +124 -0
- package/swf2js/__tests__/button-sound.test.js +105 -0
- package/swf2js/__tests__/bytearray-coercion.test.js +23 -0
- package/swf2js/__tests__/bytearray-object-serialization.test.js +380 -0
- package/swf2js/__tests__/cfg-switch-loop.test.js +103 -0
- package/swf2js/__tests__/clip-depth-mask.test.js +119 -0
- package/swf2js/__tests__/clipped-bitmap-fill.test.js +118 -0
- package/swf2js/__tests__/companion-swf.test.js +638 -0
- package/swf2js/__tests__/context-menu.test.js +149 -0
- package/swf2js/__tests__/convolution-filter.test.js +74 -0
- package/swf2js/__tests__/definefont4.test.js +280 -0
- package/swf2js/__tests__/display-displacement.test.js +161 -0
- package/swf2js/__tests__/display-list.test.js +80 -0
- package/swf2js/__tests__/display-mask-render.test.js +656 -0
- package/swf2js/__tests__/displayobject-stage.test.js +320 -0
- package/swf2js/__tests__/embedded-script-audio.test.js +131 -0
- package/swf2js/__tests__/embedded-swf.test.js +202 -0
- package/swf2js/__tests__/embedded-textfield.test.js +107 -0
- package/swf2js/__tests__/embedded-timeline-audio.test.js +182 -0
- package/swf2js/__tests__/embedded-timeline-input.test.js +420 -0
- package/swf2js/__tests__/embedded-timer-lifecycle.test.js +145 -0
- package/swf2js/__tests__/event-priority-order.test.js +125 -0
- package/swf2js/__tests__/event-weak-listeners.test.js +53 -0
- package/swf2js/__tests__/event-will-trigger.test.js +43 -0
- package/swf2js/__tests__/flash-text-engine-content.test.js +115 -0
- package/swf2js/__tests__/flash-text-engine-format.test.js +95 -0
- package/swf2js/__tests__/flash-text-engine-line.test.js +314 -0
- package/swf2js/__tests__/font-encoder.test.js +95 -0
- package/swf2js/__tests__/font-outline-text.test.js +659 -0
- package/swf2js/__tests__/glow-shadow-filter.test.js +68 -0
- package/swf2js/__tests__/graphics-bitmap-smoothing.test.js +32 -0
- package/swf2js/__tests__/graphics-fill-lifetime.test.js +36 -0
- package/swf2js/__tests__/graphics-gradient-matrix.test.js +53 -0
- package/swf2js/__tests__/graphics-stroke-hit-test.test.js +457 -0
- package/swf2js/__tests__/hit-test-primitives.test.js +414 -0
- package/swf2js/__tests__/input-events.test.js +714 -0
- package/swf2js/__tests__/integration/corpus.test.js +41 -0
- package/swf2js/__tests__/loader-embedded-swf.test.js +210 -0
- package/swf2js/__tests__/loader-info.test.js +81 -0
- package/swf2js/__tests__/local-connection.test.js +122 -0
- package/swf2js/__tests__/morph-focal-gradient.test.js +51 -0
- package/swf2js/__tests__/morph-topology.test.js +267 -0
- package/swf2js/__tests__/movie-data-codec.test.js +128 -0
- package/swf2js/__tests__/nellymoser-audio.test.js +84 -0
- package/swf2js/__tests__/opaque-background-cache.test.js +352 -0
- package/swf2js/__tests__/path-stream.test.js +81 -0
- package/swf2js/__tests__/place-object-filters.test.js +88 -0
- package/swf2js/__tests__/place-object3-decoder.test.js +116 -0
- package/swf2js/__tests__/place-object3-image.test.js +85 -0
- package/swf2js/__tests__/player-version.test.js +46 -0
- package/swf2js/__tests__/root-textfield.test.js +287 -0
- package/swf2js/__tests__/scaling-grid.test.js +183 -0
- package/swf2js/__tests__/shape-decoder.test.js +361 -0
- package/swf2js/__tests__/shape-line-style2.test.js +138 -0
- package/swf2js/__tests__/shape-nonscaling-stroke.test.js +131 -0
- package/swf2js/__tests__/shape-pixel-hint.test.js +101 -0
- package/swf2js/__tests__/simplebutton-pointer.test.js +1477 -0
- package/swf2js/__tests__/socket-offline.test.js +67 -0
- package/swf2js/__tests__/sound-avm1-stop.test.js +99 -0
- package/swf2js/__tests__/sound-envelope.test.js +110 -0
- package/swf2js/__tests__/sound-extract.test.js +168 -0
- package/swf2js/__tests__/sound-id3.test.js +283 -0
- package/swf2js/__tests__/sound-load.test.js +259 -0
- package/swf2js/__tests__/sound-mixer-spectrum.test.js +261 -0
- package/swf2js/__tests__/sound-stream-sprite.test.js +624 -0
- package/swf2js/__tests__/sound-transform.test.js +104 -0
- package/swf2js/__tests__/speex-audio.test.js +77 -0
- package/swf2js/__tests__/stage-noscale.test.js +45 -0
- package/swf2js/__tests__/swf-encoder.test.js +134 -0
- package/swf2js/__tests__/swflib-assemble.test.js +20 -0
- package/swf2js/__tests__/textfield-html-text.test.js +368 -0
- package/swf2js/__tests__/textfield-line-layout.test.js +339 -0
- package/swf2js/__tests__/textfield-programmatic-overlay.test.js +2506 -0
- package/swf2js/__tests__/textfield-scroll.test.js +79 -0
- package/swf2js/__tests__/textfield-selection.test.js +383 -0
- package/swf2js/__tests__/timeline-effect-surfaces.test.js +295 -0
- package/swf2js/__tests__/timeline-named-anchor.test.js +139 -0
- package/swf2js/__tests__/timeline-scenes.test.js +1723 -0
- package/swf2js/__tests__/urlloader-http-status.test.js +236 -0
- package/{src → swf2js}/cli.js +43 -11
- package/swf2js/compiler/as2-classes.js +156 -0
- package/swf2js/compiler/as2-parser.js +598 -0
- package/swf2js/compiler/avm1-codegen.js +897 -0
- package/swf2js/compiler/index.js +28 -0
- package/{src → swf2js}/decoder/button-decoder.js +3 -1
- package/swf2js/decoder/png.js +114 -0
- package/{src → swf2js}/decoder/shape-decoder.js +20 -10
- package/{src → swf2js}/decoder/tag-decoder.js +5 -3
- package/{src → swf2js}/decoder/tag-types.js +4 -0
- package/swf2js/decompiler/avm1-decompiler.js +1138 -0
- package/{src → swf2js}/emitter/asset-encoder.js +66 -113
- package/{src → swf2js}/emitter/bundle-emitter.js +209 -78
- package/swf2js/emitter/external-resources.js +39 -0
- package/swf2js/emitter/movie-data-codec.js +91 -0
- package/swf2js/encoder/bit-writer.js +182 -0
- package/swf2js/encoder/shape-encoder.js +310 -0
- package/swf2js/encoder/swf-builder.js +639 -0
- package/swf2js/encoder/swf-writer.js +55 -0
- package/{src/runtime/swflib/assemble.js → swf2js/runtime/assemble-swooflib.js} +4 -3
- package/{src → swf2js}/runtime/avm1-runtime.js +102 -63
- package/{src → swf2js}/runtime/index.js +1 -1
- package/{src → swf2js}/runtime/movie-runtime.js +28 -2
- package/{src → swf2js}/transpiler/actionscript.js +82 -19
- package/{src → swf2js}/transpiler/avm1/avm1-opcodes.js +5 -3
- package/{src → swf2js}/transpiler/avm1/avm1-transpiler.js +69 -6
- package/{src → swf2js}/transpiler/avm2/avm2-transpiler.js +1 -1
- package/{src → swf2js}/transpiler/timeline/display-list.js +41 -22
- package/{src → swf2js}/transpiler/timeline/timeline-codegen.js +97 -36
- package/swooflib/README.md +569 -0
- package/swooflib/adpcm.js +147 -0
- package/{src/runtime/swflib → swooflib}/builtins.js +6 -0
- package/{src/runtime/swflib → swooflib}/context-menu.js +7 -1
- package/swooflib/control-definitions.js +42 -0
- package/swooflib/control-widget.js +763 -0
- package/swooflib/controls.js +300 -0
- package/{src/runtime/swflib → swooflib}/display.js +16 -10
- package/{src/runtime/swflib → swooflib}/events.js +11 -0
- package/{src/runtime/swflib → swooflib}/flash.js +6 -5
- package/{src/runtime/swflib → swooflib}/graphics.js +81 -19
- package/{src/runtime/swflib → swooflib}/input.js +12 -14
- package/{src/runtime/swflib → swooflib}/loader.js +52 -22
- package/swooflib/movie-network.js +86 -0
- package/swooflib/path-stream.js +169 -0
- package/{src/runtime/swflib → swooflib}/render.js +3 -13
- package/{src/runtime/swflib → swooflib}/sound.js +25 -2
- package/{src/runtime/swflib → swooflib}/stage.js +3 -3
- package/swooflib/stream-time.js +21 -0
- package/{src/runtime/swflib → swooflib}/system.js +88 -37
- package/{src/runtime/swflib → swooflib}/text-paint.js +14 -3
- package/{src/runtime/swflib → swooflib}/text.js +8 -0
- package/swooflib/xml-node.js +53 -0
- package/src/emitter/timeline-data-codec.js +0 -58
- /package/{src → swf2js}/decoder/symbol-table.js +0 -0
- /package/{src → swf2js}/emitter/embedded-swf.js +0 -0
- /package/{src → swf2js}/emitter/font-encoder.js +0 -0
- /package/{src → swf2js}/model/swf-document.js +0 -0
- /package/{src → swf2js}/model/transpile-result.js +0 -0
- /package/{src → swf2js}/parser/bit-reader.js +0 -0
- /package/{src → swf2js}/parser/decompressor.js +0 -0
- /package/{src → swf2js}/parser/swf-parser.js +0 -0
- /package/{src → swf2js}/pretty-printer/pretty-printer.js +0 -0
- /package/{src → swf2js}/runtime/avm2-runtime.js +0 -0
- /package/{src → swf2js}/runtime/embedded-movie-runtime.js +0 -0
- /package/{src → swf2js}/transpiler/avm1/avm1-ir.js +0 -0
- /package/{src → swf2js}/transpiler/avm1/avm1-rewrite.js +0 -0
- /package/{src → swf2js}/transpiler/avm2/abc-reader.js +0 -0
- /package/{src → swf2js}/transpiler/cfg-structurer.js +0 -0
- /package/{src → swf2js}/util/diagnostics.js +0 -0
- /package/{src → swf2js}/util/logger.js +0 -0
- /package/{src/runtime/swflib → swooflib}/bitmap-image.js +0 -0
- /package/{src/runtime/swflib → swooflib}/bitmap.js +0 -0
- /package/{src/runtime/swflib → swooflib}/bytearray.js +0 -0
- /package/{src/runtime/swflib → swooflib}/compiled-swf.js +0 -0
- /package/{src/runtime/swflib → swooflib}/cursor-flag.js +0 -0
- /package/{src/runtime/swflib → swooflib}/dictionary.js +0 -0
- /package/{src/runtime/swflib → swooflib}/filters.js +0 -0
- /package/{src/runtime/swflib → swooflib}/geom.js +0 -0
- /package/{src/runtime/swflib → swooflib}/glyph-metrics.js +0 -0
- /package/{src/runtime/swflib → swooflib}/host.js +0 -0
- /package/{src/runtime/swflib → swooflib}/inherit.js +0 -0
- /package/{src/runtime/swflib → swooflib}/marks.js +0 -0
- /package/{src/runtime/swflib → swooflib}/matrix3d.js +0 -0
- /package/{src/runtime/swflib → swooflib}/pointer-bridge.js +0 -0
- /package/{src/runtime/swflib → swooflib}/projection.js +0 -0
- /package/{src/runtime/swflib → swooflib}/sprite-drag.js +0 -0
- /package/{src/runtime/swflib → swooflib}/stage-ref.js +0 -0
- /package/{src/runtime/swflib → swooflib}/text-field.js +0 -0
- /package/{src/runtime/swflib → swooflib}/transform.js +0 -0
- /package/{src/runtime/swflib → swooflib}/xml.js +0 -0
package/README.md
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
# swoof — SWF-to-Browser Transpiler
|
|
1
|
+
# swoof — Animation Studio & SWF-to-Browser Transpiler
|
|
2
|
+
|
|
3
|
+
Welcome to Swoof, aka swf2js.
|
|
4
|
+
|
|
5
|
+
Swoof has 3 components:
|
|
6
|
+
- swf2js command line transpiler from swf to js"
|
|
7
|
+
- swooflib runtime to used by converted animations to run in the browser
|
|
8
|
+
- studio converts, runs swf files and exports as videos, images, swf, lottie, svg
|
|
2
9
|
|
|
3
10
|
**swoof** statically transpiles Adobe Flash `.swf` files into plain JavaScript that runs in modern browsers — no Flash plugin required.
|
|
4
11
|
|
|
5
12
|
It parses the binary SWF format, decodes tags (shapes, timelines, sounds, fonts), and transpiles embedded ActionScript bytecode (AVM1 and AVM2) to ES2020 class-based JavaScript with structured control flow (`while`, `if/else`).
|
|
6
13
|
|
|
14
|
+
Try the demo of Swoof Studio here:
|
|
15
|
+
https://opensitez.github.io/swoof/studio-demo/
|
|
16
|
+
|
|
7
17
|
---
|
|
8
18
|
|
|
9
19
|
## Install and run
|
|
@@ -28,6 +38,16 @@ Convert a demo SWF from the source checkout to try the full workflow:
|
|
|
28
38
|
npm start -- -o out demos/neon-grid.swf
|
|
29
39
|
```
|
|
30
40
|
|
|
41
|
+
### Swoof Studio
|
|
42
|
+
|
|
43
|
+
Swoof Studio, the browser-based animation editor, ships in the same package. Start it without installing anything (the `-p` option names the package that holds the `studio` command):
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npx -p swf2js studio
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
From a source checkout, run `npm run studio`. Studio opens at `http://localhost:4810` and keeps projects in `studio-projects/` under the directory you start it from; pass `--projects <dir>` (or set `SWOOF_PROJECTS`) to keep them elsewhere, and `--port <n>` to change the port.
|
|
50
|
+
|
|
31
51
|
Open `out/neon-grid/index.html` in a browser. Click a square to make your move. The computer takes the next turn.
|
|
32
52
|
|
|
33
53
|
To convert your own movie from the source checkout, run `npm start -- -o out "path/to/game.swf"` and open `out/game/index.html`. If you omit `-o`, Swoof creates the output folder next to the source SWF.
|
|
@@ -94,7 +114,7 @@ npx swf2js [options] <file.swf> [file.swf ...]
|
|
|
94
114
|
See what's inside the file before transpiling:
|
|
95
115
|
|
|
96
116
|
```bash
|
|
97
|
-
node
|
|
117
|
+
node swf2js/cli.js game.swf --inspect
|
|
98
118
|
```
|
|
99
119
|
|
|
100
120
|
This prints a tree of parsed tags — frames, shapes, sounds, embedded scripts — without generating any output files.
|
|
@@ -104,13 +124,13 @@ This prints a tree of parsed tags — frames, shapes, sounds, embedded scripts
|
|
|
104
124
|
Print the transpiled ActionScript (AVM1 + AVM2) to your terminal:
|
|
105
125
|
|
|
106
126
|
```bash
|
|
107
|
-
node
|
|
127
|
+
node swf2js/cli.js game.swf --actionscript
|
|
108
128
|
```
|
|
109
129
|
|
|
110
130
|
Redirect to a file for review:
|
|
111
131
|
|
|
112
132
|
```bash
|
|
113
|
-
node
|
|
133
|
+
node swf2js/cli.js game.swf --actionscript > game.js
|
|
114
134
|
```
|
|
115
135
|
|
|
116
136
|
The output is self-contained ES2020 — class definitions, method bodies, and runtime stubs — parsed and validated against `acorn`.
|
|
@@ -118,24 +138,41 @@ The output is self-contained ES2020 — class definitions, method bodies, and ru
|
|
|
118
138
|
### 3. Convert multiple movies for the browser
|
|
119
139
|
|
|
120
140
|
```bash
|
|
121
|
-
node
|
|
141
|
+
node swf2js/cli.js -o out archive/Swf/*.swf
|
|
122
142
|
```
|
|
123
143
|
|
|
124
144
|
---
|
|
125
145
|
|
|
126
146
|
## Running the Output
|
|
127
147
|
|
|
128
|
-
Open the generated `index.html` in a browser and keep
|
|
148
|
+
Open the generated `index.html` in a browser and keep the movie folder's files together (and, after a batch conversion, next to the shared `swoof.js`). Use `--actionscript` when you want to inspect the compiled script.
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
out/
|
|
152
|
+
swoof.js player, shared when one run converts several movies into out/
|
|
153
|
+
<movie>/index.html
|
|
154
|
+
<movie>/swoof.js player, when the movie was converted on its own or with --standalone
|
|
155
|
+
<movie>/movie-data.js
|
|
156
|
+
<movie>/bundle.js
|
|
157
|
+
<movie>/binary-data.js only when the movie links ByteArray data
|
|
158
|
+
<movie>/assets/
|
|
159
|
+
```
|
|
129
160
|
|
|
130
161
|
| File | Contents |
|
|
131
162
|
|---|---|
|
|
132
|
-
| `swoof.js` |
|
|
133
|
-
| `
|
|
163
|
+
| `swoof.js` | The player: `__swoof_swflib.mountMovie(...)`, the `swoof.*` API, AVM1 and AVM2 helpers, Canvas rendering, effects, input, and audio. In the movie folder for a single movie; once in the output folder for a batch |
|
|
164
|
+
| `movie-data.js` | Movie descriptor (stage, assets, symbol classes) plus frames, scene labels, and symbols. Shape geometry is a compact binary path stream. Data from 512 KiB is gzip-packed when that saves at least a quarter |
|
|
134
165
|
| `binary-data.js` | Original linked ByteArray payloads, retained for ActionScript code that reads or changes them |
|
|
135
|
-
| `bundle.js` |
|
|
136
|
-
| `assets/` | Images, sounds, and compiled embedded movies loaded on demand. Named children use paths such as `assets/preloader/preloader.js
|
|
166
|
+
| `bundle.js` | Compiled ActionScript and the installer only. ActionScript bodies used more than once are emitted once |
|
|
167
|
+
| `assets/` | Images, sounds, fonts, and compiled embedded movies loaded on demand. Named children use paths such as `assets/preloader/preloader.js` |
|
|
168
|
+
|
|
169
|
+
**Shared or standalone player.** A movie converted on its own is self-contained: its folder holds its own `swoof.js`. When one run converts several movies into the same folder (`swf2js -o out a.swf b.swf`, or a glob), they all load one `../swoof.js`, so the copies cannot drift apart. `--standalone` gives each movie its own copy even in a batch. A later batch run into the folder rewrites the shared `swoof.js` with the current build. Each movie records the player build it was converted with, and logs a console warning if it loads a different one; reconvert it, or convert it on its own (or with `--standalone`) so it keeps its own copy.
|
|
170
|
+
|
|
171
|
+
**Generated code size.** Output JavaScript is minified with esbuild (names are kept, so stack traces stay readable). The sources in `swf2js/` and `swooflib/` are never changed. `--readable` writes unminified output for debugging.
|
|
137
172
|
|
|
138
|
-
|
|
173
|
+
**Audio.** MP3 sounds are copied as they are. ADPCM sounds stay compressed in `assets/sound_*.js` and are decoded to WAV in the browser while the movie loads (about 4× smaller than WAV). Nellymoser and Speex sounds are re-encoded as MP3 with FFmpeg. `--wav-audio` writes WAV files instead.
|
|
174
|
+
|
|
175
|
+
The player source is the ES modules in `swooflib/`, which Swoof Studio also serves. The default output bundles them into one `swoof.js` with no import statements, so a generated folder still opens from disk. `--swoof split` copies those modules into a `swoof/` folder and loads them from each movie's `boot.js`; that form needs a web server. Packed movie data opens directly from disk in browsers with `DecompressionStream` support. Use `--plain-timeline` for older browsers or to inspect the data as text.
|
|
139
176
|
|
|
140
177
|
The shared AVM2 runtime registers classes and methods, initializes activation slots, and caches ordered property keys from each compiled block's namespace table. Compiled AVM1 scripts use shared enumeration and string helpers.
|
|
141
178
|
|
|
@@ -154,12 +191,36 @@ These options are repeatable. Explicit mappings also accept complete HTTP(S) URL
|
|
|
154
191
|
A source SWF can carry its local mappings in a sibling `<movie>.companions.json` file. The JSON object maps requested SWF URLs to paths inside the source directory. Explicit CLI mappings take precedence. Raze 2 uses this manifest to preserve its offline companion on ordinary rebuilds.
|
|
155
192
|
|
|
156
193
|
```sh
|
|
157
|
-
node
|
|
194
|
+
node swf2js/cli.js archive/Swf/raze-2.swf
|
|
158
195
|
```
|
|
159
196
|
|
|
160
197
|
AS3 `Loader.load` and AVM1 clip loading use these compiled companions, including with `--omit-embedded-swf-bytes`.
|
|
161
198
|
|
|
162
|
-
An unregistered SWF URL
|
|
199
|
+
An unregistered SWF URL completes with a transparent two-frame movie. Its loader reports zero source bytes and the clip stops on frame 2. Package a companion to provide the original movie and its application events.
|
|
200
|
+
|
|
201
|
+
### Allow networking in Studio and swf2js
|
|
202
|
+
|
|
203
|
+
**Allow networking** controls movie requests to other websites and defaults to **Disallow**. In Studio, choose **Properties → Document properties → Preview → Allow networking**. The Export dialog copies that choice into **Allow networking in exported HTML**, where you can change it for that download. In swf2js, set the mode with `--allow-networking`. The existing `--external-resources` flag is an alias.
|
|
204
|
+
|
|
205
|
+
```sh
|
|
206
|
+
node swf2js/cli.js game.swf --allow-networking prompt
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
| Mode | What happens when the movie plays |
|
|
210
|
+
| --- | --- |
|
|
211
|
+
| `disallow` (default) | Starts immediately. External loads finish locally. The developer console logs the resource type and destination origin. |
|
|
212
|
+
| `prompt` | **Prompt at startup** asks once before any movie script runs. **Play offline** or Escape uses Disallow. **Allow networking** uses Allow for this playback. |
|
|
213
|
+
| `allow` | Starts immediately with external HTTP(S) resource requests enabled. Browser rules such as CORS and mixed-content restrictions still apply. |
|
|
214
|
+
|
|
215
|
+
**Opening websites** has a separate permission in all three modes. The first external HTTP(S) link from AS2 `getURL`, AS3 `navigateToURL`, or linked text displays its destination. **Allow links** opens it in a new tab and authorizes later external links for this playback. **Block links** or Escape dismisses it and blocks later links. Calls made while the question is open are discarded. Reloading or restarting Preview clears the choice. Local links keep working, and external form submissions also require external resource access.
|
|
216
|
+
|
|
217
|
+
**Clipboard and saves.** The Flash clipboard API requires a browser-recognized user interaction to write text. Flash `SharedObject` reads, writes, clears, and disk-usage queries are scoped to the current game. A saved Studio project's HTML exports keep the same identity across edits. For swf2js the identity comes from the source SWF, and for an unsaved Studio export it comes from the project contents. Earlier unscoped entries stay in the browser and are excluded from the new save system. Studio Preview keeps saves in memory for the current playback.
|
|
218
|
+
|
|
219
|
+
All three modes can use embedded assets, packaged companion movies, and files served inside the movie’s directory. In a hosted export, other files on the same origin are local. A different scheme, host, or port is external. Studio isolates the running movie from the editor and limits its local file access to its own preview directory. In Disallow mode, data requests complete with empty data, images become transparent, unregistered SWFs complete with a blank clip, and blocked sounds complete silently. Games that require an actual server reply, such as a login token or level data, still need that service. Remote SWF code always needs a packaged companion and the browser JavaScript bridge is disabled in the generated player.
|
|
220
|
+
|
|
221
|
+
Studio Preview also disables camera, microphone, screen capture, location, clipboard reads, payments, and USB access through the browser's Permissions Policy. For a public archive, serve converted HTML on an origin dedicated to games, separate from accounts and editor APIs. Standalone exports run JavaScript with their hosting origin's privileges, and the ActionScript runtime can resolve browser globals. The movie settings govern the supported Flash APIs.
|
|
222
|
+
|
|
223
|
+
Re-export existing HTML to apply the setting. **Download SWF** produces a Flash file whose network permissions are controlled by its player.
|
|
163
224
|
|
|
164
225
|
---
|
|
165
226
|
|
|
@@ -169,6 +230,12 @@ An unregistered SWF URL loads a small unavailable-movie animation from the share
|
|
|
169
230
|
# Unit + property tests
|
|
170
231
|
npm test
|
|
171
232
|
|
|
233
|
+
# Studio project, import and export tests
|
|
234
|
+
node --test studio/*.test.js
|
|
235
|
+
|
|
236
|
+
# Studio editor interactions in Chromium
|
|
237
|
+
node studio/tests/timeline-browser.mjs
|
|
238
|
+
|
|
172
239
|
# SWF corpus integration tests
|
|
173
240
|
npm run test:integration
|
|
174
241
|
```
|
|
@@ -178,7 +245,7 @@ npm run test:integration
|
|
|
178
245
|
## Project Layout
|
|
179
246
|
|
|
180
247
|
```
|
|
181
|
-
|
|
248
|
+
swf2js/
|
|
182
249
|
cli.js # Entry point
|
|
183
250
|
parser/ # Binary SWF parser (bit-reader, swf-parser)
|
|
184
251
|
decoder/ # Tag decoder (shapes, fonts, sounds, DoABC, DoAction)
|
package/package.json
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swf2js",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "SWF-to-browser transpiler —
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "SWF-to-browser transpiler & Studio — Convert SWF files to HTML/JS and Create/Edit Animations",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE-GPL",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
|
-
"swf2js": "
|
|
8
|
+
"swf2js": "swf2js/cli.js",
|
|
9
|
+
"studio": "studio/server.js"
|
|
9
10
|
},
|
|
10
11
|
"scripts": {
|
|
11
|
-
"start": "node
|
|
12
|
-
"
|
|
12
|
+
"start": "node swf2js/cli.js",
|
|
13
|
+
"studio": "node studio/server.js",
|
|
14
|
+
"test": "vitest --run swf2js/__tests__",
|
|
13
15
|
"test:integration": "vitest --run --config vitest.integration.config.js"
|
|
14
16
|
},
|
|
15
17
|
"devDependencies": {
|
|
16
18
|
"fast-check": "^3.0.0",
|
|
17
|
-
"vitest": "^
|
|
19
|
+
"vitest": "^5.1.2"
|
|
18
20
|
},
|
|
19
21
|
"engines": {
|
|
20
22
|
"node": ">=20.0.0"
|
|
21
23
|
},
|
|
22
24
|
"dependencies": {
|
|
23
25
|
"acorn": "^8.19.0",
|
|
24
|
-
"
|
|
26
|
+
"clipper-lib": "^6.4.2",
|
|
27
|
+
"esbuild": "^0.28.2",
|
|
28
|
+
"jpeg-js": "^0.4.4",
|
|
25
29
|
"lzma-js": "^1.0.1"
|
|
26
30
|
}
|
|
27
31
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Imported scripts shown as ActionScript must compile back: decompile → compile → decompile gives
|
|
2
|
+
// the same text for every script the decompiler can express (studiospec/actionscript.md, design notes).
|
|
3
|
+
import { describe, it } from 'node:test';
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
import { existsSync } from 'node:fs';
|
|
6
|
+
import { readFile } from 'node:fs/promises';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
import { compileActionScript } from '../swf2js/compiler/index.js';
|
|
10
|
+
import { decompileAvm1, DecompileError } from '../swf2js/decompiler/avm1-decompiler.js';
|
|
11
|
+
import { convertSwf } from './server/swf-import.js';
|
|
12
|
+
|
|
13
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
14
|
+
|
|
15
|
+
async function scriptsOf(file) {
|
|
16
|
+
let count = 0;
|
|
17
|
+
const storeMedia = async (data, { name, type }) => ({
|
|
18
|
+
name, type, kind: type.startsWith('audio/') ? 'audio' : 'image', hash: String(++count).padStart(64, '0'), bytes: data.length, src: 'a',
|
|
19
|
+
});
|
|
20
|
+
const { project } = await convertSwf(new Uint8Array(await readFile(file)), { name: path.basename(file), storeMedia });
|
|
21
|
+
return project.scripts ?? [];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// [file, scripts the decompiler must express at least]
|
|
25
|
+
const games = [
|
|
26
|
+
['demos/neon-grid.swf', 2],
|
|
27
|
+
['archive/flasharchive/Snake.swf', 17],
|
|
28
|
+
['archive/flasharchive/Minesweeper.swf', 23],
|
|
29
|
+
['archive/flasharchive/Pacman.swf', 30],
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
describe('ActionScript round trip of imported scripts', () => {
|
|
33
|
+
for (const [file, minimum] of games) {
|
|
34
|
+
const full = path.join(root, file);
|
|
35
|
+
it(path.basename(file), { skip: !existsSync(full) && 'not in this checkout' }, async () => {
|
|
36
|
+
let expressed = 0;
|
|
37
|
+
for (const script of await scriptsOf(full)) {
|
|
38
|
+
const bytes = new Uint8Array(Buffer.from(script.bytecode, 'base64'));
|
|
39
|
+
let text;
|
|
40
|
+
try {
|
|
41
|
+
text = decompileAvm1(bytes, { swfVersion: script.swfVersion });
|
|
42
|
+
} catch (error) {
|
|
43
|
+
// Bytecode with no ActionScript form stays bytecode; anything else is a bug.
|
|
44
|
+
assert.ok(error instanceof DecompileError, `${script.id}: ${error.stack}`);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const again = decompileAvm1(compileActionScript(text, { swfVersion: script.swfVersion }), { swfVersion: script.swfVersion });
|
|
48
|
+
assert.equal(again, text, `${script.id} is not a fixpoint`);
|
|
49
|
+
expressed++;
|
|
50
|
+
}
|
|
51
|
+
assert.ok(expressed >= minimum, `${expressed} scripts decompiled, expected at least ${minimum}`);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
});
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// Written ActionScript scripts (studiospec/actionscript.md §4.3–4.5): stored as code, compiled
|
|
2
|
+
// when the project is built for Preview and export, errors named with their line and column.
|
|
3
|
+
import { describe, it } from 'node:test';
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
import { once } from 'node:events';
|
|
6
|
+
import { readFile } from 'node:fs/promises';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
import { compileActionScript } from '../swf2js/compiler/index.js';
|
|
10
|
+
import { decompileAvm1 } from '../swf2js/decompiler/avm1-decompiler.js';
|
|
11
|
+
import { createStudioServer } from './server.js';
|
|
12
|
+
import { convertSwf } from './server/swf-import.js';
|
|
13
|
+
import { buildProjectMovie } from './server/project-movie.js';
|
|
14
|
+
import { exportProjectSwf } from './server/swf-export.js';
|
|
15
|
+
import { hasScripts, scriptUseCount } from './src/scripts.js';
|
|
16
|
+
import { scriptReferenceWarnings } from './src/script-references.js';
|
|
17
|
+
import { parseProjectJson, serializeProject } from './src/project-io.js';
|
|
18
|
+
|
|
19
|
+
const demos = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../demos');
|
|
20
|
+
const noAssets = { readAsset: async () => null };
|
|
21
|
+
|
|
22
|
+
it('finds referenced instance names in imported push strings, constant pools and written scripts', () => {
|
|
23
|
+
const entry = (id, code, version) => ({ id, name: id, language: 'avm1', swfVersion: version,
|
|
24
|
+
bytecode: Buffer.from(compileActionScript(code, { swfVersion: version })).toString('base64') });
|
|
25
|
+
const scripts = [entry('Button', 'trace("_root.hero");', 8), entry('Legacy', 'function show() { trace(HERO); trace(HERO); }', 6),
|
|
26
|
+
{ id: 'Frame', language: 'actionscript', code: '/* hero */ trace(heroic);', swfVersion: 8 },
|
|
27
|
+
entry('Detached', 'trace(hero);', 8)];
|
|
28
|
+
const project = { scripts, scenes: [{ elements: [], events: [{ actions: scripts.slice(0, 3).map(s => ({ type: 'script', script: s.id })) }] }] };
|
|
29
|
+
assert.deepEqual(scriptReferenceWarnings(project, [{ name: 'hero' }]), ['Button refers to hero', 'Legacy refers to hero']);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('exports a class initializer and a separately authored consumer as native AVM1', async () => {
|
|
33
|
+
const scripts = [
|
|
34
|
+
{ id: 'class', code: 'class game.Counter { function answer() { return 42; } }' },
|
|
35
|
+
{ id: 'use', code: 'import game.Counter; ifFrameLoaded(1) _root.answer = new Counter().answer();' },
|
|
36
|
+
].map(s => ({ ...s, language: 'actionscript', swfVersion: 8 }));
|
|
37
|
+
const doc = { stage: { width: 320, height: 240, frameRate: 12 }, scripts,
|
|
38
|
+
scenes: [{ id: 'main', durationFrames: 2, elements: [{ id: 'host', type: 'symbol', symbolId: 'classHost' }],
|
|
39
|
+
events: [{ trigger: 'frameEnter', frame: 2, actions: [{ type: 'script', script: 'use' }] }] }],
|
|
40
|
+
symbols: [{ id: 'classHost', elements: [], initScript: 'class', initAt: { scene: 'main', frame: 1 } }] };
|
|
41
|
+
const { bytes } = await exportProjectSwf(doc);
|
|
42
|
+
const { project } = await convertSwf(bytes, { idPrefix: 'classes' });
|
|
43
|
+
const sourceBytes = id => project.scripts.find(s => s.id === id).bytecode;
|
|
44
|
+
const classHost = project.symbols.find(symbol => symbol.initScript);
|
|
45
|
+
assert.equal(sourceBytes(classHost.initScript), Buffer.from(compileActionScript(scripts[0].code)).toString('base64'));
|
|
46
|
+
const consumer = project.scenes[0].events.find(event => event.frame === 2).actions[0];
|
|
47
|
+
assert.equal(sourceBytes(consumer.script), Buffer.from(compileActionScript(scripts[1].code)).toString('base64'));
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
async function neonGrid() {
|
|
51
|
+
let count = 0;
|
|
52
|
+
const storeMedia = async (data, { name, type }) => ({
|
|
53
|
+
name, type, kind: type.startsWith('audio/') ? 'audio' : 'image', hash: String(++count).padStart(64, '0'), bytes: data.length, src: 'a',
|
|
54
|
+
});
|
|
55
|
+
const { project } = await convertSwf(new Uint8Array(await readFile(path.join(demos, 'neon-grid.swf'))), { name: 'neon-grid', storeMedia, idPrefix: 't' });
|
|
56
|
+
return JSON.parse(JSON.stringify(project));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The first frame script of the main scene, rewritten as ActionScript with `edit`. */
|
|
60
|
+
function editFrameScript(project, edit) {
|
|
61
|
+
const action = project.scenes[0].events.flatMap(event => event.actions).find(entry => entry.type === 'script');
|
|
62
|
+
const script = project.scripts.find(entry => entry.id === action.script);
|
|
63
|
+
const code = edit(decompileAvm1(new Uint8Array(Buffer.from(script.bytecode, 'base64')), { swfVersion: script.swfVersion }));
|
|
64
|
+
Object.assign(script, { language: 'actionscript', code });
|
|
65
|
+
delete script.bytecode;
|
|
66
|
+
delete script.source;
|
|
67
|
+
return script;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function withServer(test) {
|
|
71
|
+
const server = createStudioServer();
|
|
72
|
+
server.listen(0, '127.0.0.1');
|
|
73
|
+
await once(server, 'listening');
|
|
74
|
+
const post = (route, body) => fetch(`http://127.0.0.1:${server.address().port}${route}`, {
|
|
75
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body),
|
|
76
|
+
});
|
|
77
|
+
try {
|
|
78
|
+
await test(post);
|
|
79
|
+
} finally {
|
|
80
|
+
server.close();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
describe('ActionScript scripts', () => {
|
|
85
|
+
it('saves and reopens a written script as code', async () => {
|
|
86
|
+
const project = await neonGrid();
|
|
87
|
+
const script = editFrameScript(project, code => `${code}\ntrace("edited");`);
|
|
88
|
+
const reopened = parseProjectJson(serializeProject(parseProjectJson(JSON.stringify(project))));
|
|
89
|
+
const saved = reopened.scripts.find(entry => entry.id === script.id);
|
|
90
|
+
assert.deepEqual(saved, { id: script.id, language: 'actionscript', swfVersion: script.swfVersion, code: script.code, ...(script.name ? { name: script.name } : {}) });
|
|
91
|
+
assert.throws(() => parseProjectJson(JSON.stringify({ ...project, scripts: [{ ...script, code: 5 }] })), /code must be text/);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('compiles written scripts when the movie is built, and keeps imported ones as they were', async () => {
|
|
95
|
+
const project = await neonGrid();
|
|
96
|
+
const untouched = project.scripts.map(entry => entry.bytecode);
|
|
97
|
+
const script = editFrameScript(project, code => `${code}\ntrace("edited");`);
|
|
98
|
+
const movie = await buildProjectMovie(parseProjectJson(JSON.stringify(project)), noAssets);
|
|
99
|
+
const expected = compileActionScript(script.code, { swfVersion: script.swfVersion });
|
|
100
|
+
const frameScripts = movie.tags.filter(tag => tag.type === 'DoAction').map(tag => Buffer.from(tag.bytecode));
|
|
101
|
+
assert.ok(frameScripts.some(bytes => bytes.equals(Buffer.from(expected))), 'the compiled script is the frame script');
|
|
102
|
+
// The other scripts keep their bytecode.
|
|
103
|
+
for (const [index, entry] of project.scripts.entries()) {
|
|
104
|
+
if (entry.language === 'avm1') assert.equal(entry.bytecode, untouched[index]);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('keeps artwork, clip, button definition and initializer scripts at their SWF attachment points', async () => {
|
|
109
|
+
const script = id => ({ language: 'actionscript', swfVersion: 8, id, code: `_root.${id} = 1;` });
|
|
110
|
+
const art = { id: 'art', type: 'star', buttonAction: { trigger: 'click', type: 'script', script: 'clicked' } };
|
|
111
|
+
const shape = { id: 'skin', type: 'rectangle' };
|
|
112
|
+
const doc = { stage: { width: 300, height: 200, frameRate: 12 },
|
|
113
|
+
scripts: ['clicked', 'loaded', 'keyed', 'initialized'].map(script),
|
|
114
|
+
scenes: [{ id: 'scene', durationFrames: 2, elements: [art,
|
|
115
|
+
{ id: 'panelInstance', type: 'symbol', symbolId: 'panel', scriptEvents: [{ on: ['load'], script: 'loaded' }] },
|
|
116
|
+
{ id: 'btnInstance', type: 'symbol', symbolId: 'btn' }] }],
|
|
117
|
+
symbols: [{ id: 'panel', initScript: 'initialized', initAt: { scene: 'scene', frame: 2 }, elements: [shape] },
|
|
118
|
+
{ id: 'btn', button: true, elements: [{ ...shape, id: 'buttonSkin' }], scriptEvents: [{ on: ['release', 'keyPress'], key: 32, script: 'keyed' }] }] };
|
|
119
|
+
const project = parseProjectJson(JSON.stringify(doc));
|
|
120
|
+
assert.equal(hasScripts(project), true);
|
|
121
|
+
assert.equal(scriptUseCount(project, 'clicked'), 1);
|
|
122
|
+
assert.deepEqual(parseProjectJson(serializeProject(project)).scenes[0].elements[0].buttonAction, art.buttonAction);
|
|
123
|
+
const bad = { ...doc, scripts: doc.scripts.slice(1) };
|
|
124
|
+
assert.throws(() => parseProjectJson(JSON.stringify(bad)), /Missing script "clicked"/);
|
|
125
|
+
const { bytes } = await exportProjectSwf(doc);
|
|
126
|
+
const { project: imported } = await convertSwf(bytes, { name: 'Script handlers', idPrefix: 't' });
|
|
127
|
+
const bytesOf = id => imported.scripts.find(script => script.id === id)?.bytecode;
|
|
128
|
+
const expected = (id, button = false) => {
|
|
129
|
+
const bytes = compileActionScript(script(id).code, { swfVersion: 8 });
|
|
130
|
+
// The button decoder returns the body without its ActionEnd record.
|
|
131
|
+
return Buffer.from(button ? bytes.subarray(0, -1) : bytes).toString('base64');
|
|
132
|
+
};
|
|
133
|
+
const handlers = imported.symbols.flatMap(symbol => symbol.scriptEvents ?? []);
|
|
134
|
+
assert.ok(handlers.some(handler => handler.on.includes('release') && bytesOf(handler.script) === expected('clicked', true)));
|
|
135
|
+
assert.ok(handlers.some(handler => handler.on.includes('release') && handler.key === 32 && bytesOf(handler.script) === expected('keyed', true)));
|
|
136
|
+
assert.ok(imported.scenes[0].elements.flatMap(element => element.scriptEvents ?? [])
|
|
137
|
+
.some(handler => handler.on.includes('load') && bytesOf(handler.script) === expected('loaded')));
|
|
138
|
+
assert.ok(imported.symbols.some(symbol => symbol.initAt?.frame === 2 && bytesOf(symbol.initScript) === expected('initialized')));
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('stops Preview and export with the error, naming the script', async () => {
|
|
142
|
+
const project = await neonGrid();
|
|
143
|
+
const script = editFrameScript(project, code => `${code}\ntrace(`);
|
|
144
|
+
const line = script.code.split('\n').length;
|
|
145
|
+
await assert.rejects(buildProjectMovie(parseProjectJson(JSON.stringify(project)), noAssets),
|
|
146
|
+
error => error.name === 'ScriptCompileError' && error.scriptId === script.id && error.line === line && /line \d+, column \d+/.test(error.message));
|
|
147
|
+
await withServer(async post => {
|
|
148
|
+
for (const route of ['/api/preview', '/api/export/swf', '/api/export/html']) {
|
|
149
|
+
const response = await post(route, { project });
|
|
150
|
+
assert.equal(response.status, 422, route);
|
|
151
|
+
const { error } = await response.json();
|
|
152
|
+
assert.equal(error.code, 'script_error');
|
|
153
|
+
assert.equal(error.script, script.id);
|
|
154
|
+
assert.equal(error.line, line);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('checks a script while it is edited', async () => {
|
|
160
|
+
await withServer(async post => {
|
|
161
|
+
const good = await (await post('/api/script/check', { code: 'stop();\ntrace(1);', swfVersion: 8 })).json();
|
|
162
|
+
assert.deepEqual(good, { error: null });
|
|
163
|
+
const bad = await (await post('/api/script/check', { code: 'var a = 1;\ntrace(a', swfVersion: 8 })).json();
|
|
164
|
+
assert.deepEqual(bad.error, { message: 'Expected "," or ")" but found end of script', line: 2, column: 8 });
|
|
165
|
+
const scenes = await (await post('/api/script/check', { code: 'gotoAndPlay("Level 2", 1);', scenes: ['Intro', 'Level 2'] })).json();
|
|
166
|
+
assert.equal(scenes.error, null);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
});
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { describe, it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { inflateSync } from 'node:zlib';
|
|
4
|
+
import { changedRect, crc32, createAnimatedWriter, lzwEncode, medianCutPalette } from './src/animated-image.js';
|
|
5
|
+
|
|
6
|
+
// GIF LZW decoder (minimum code size from the data), for checking the encoder.
|
|
7
|
+
function lzwDecode(bytes, at = 0) {
|
|
8
|
+
const minimum = bytes[at++];
|
|
9
|
+
const data = [];
|
|
10
|
+
for (let size = bytes[at++]; size; size = bytes[at++]) { data.push(...bytes.subarray(at, at + size)); at += size; }
|
|
11
|
+
const clear = 1 << minimum, end = clear + 1;
|
|
12
|
+
let size = minimum + 1, table = [], bits = 0, count = 0, previous = null;
|
|
13
|
+
const out = [];
|
|
14
|
+
const reset = () => { table = Array.from({ length: clear }, (_, i) => [i]); table.push(null, null); size = minimum + 1; previous = null; };
|
|
15
|
+
reset();
|
|
16
|
+
for (const byte of data) {
|
|
17
|
+
bits |= byte << count; count += 8;
|
|
18
|
+
while (count >= size) {
|
|
19
|
+
const code = bits & ((1 << size) - 1);
|
|
20
|
+
bits >>>= size; count -= size;
|
|
21
|
+
if (code === clear) { reset(); continue; }
|
|
22
|
+
if (code === end) return { indices: out, next: at };
|
|
23
|
+
let entry = table[code];
|
|
24
|
+
if (!entry) entry = [...table[previous], table[previous][0]];
|
|
25
|
+
out.push(...entry);
|
|
26
|
+
if (previous !== null && table.length < 4096) table.push([...table[previous], entry[0]]);
|
|
27
|
+
previous = code;
|
|
28
|
+
if (table.length === 1 << size && size < 12) size++;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return { indices: out, next: at };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function parseGif(bytes) {
|
|
35
|
+
assert.equal(Buffer.from(bytes.subarray(0, 6)).toString(), 'GIF89a');
|
|
36
|
+
const width = bytes[6] | bytes[7] << 8, height = bytes[8] | bytes[9] << 8;
|
|
37
|
+
const frames = [];
|
|
38
|
+
let at = 13, delay = 0, loops = false;
|
|
39
|
+
while (bytes[at] !== 0x3b) {
|
|
40
|
+
if (bytes[at] === 0x21) {
|
|
41
|
+
if (bytes[at + 1] === 0xf9) delay = bytes[at + 4] | bytes[at + 5] << 8;
|
|
42
|
+
if (bytes[at + 1] === 0xff) loops = true;
|
|
43
|
+
at += 2;
|
|
44
|
+
for (let size = bytes[at++]; size; size = bytes[at++]) at += size;
|
|
45
|
+
} else if (bytes[at] === 0x2c) {
|
|
46
|
+
const u16 = offset => bytes[offset] | bytes[offset + 1] << 8;
|
|
47
|
+
const frame = { x: u16(at + 1), y: u16(at + 3), width: u16(at + 5), height: u16(at + 7), delay };
|
|
48
|
+
const colors = 2 << (bytes[at + 9] & 7);
|
|
49
|
+
frame.palette = bytes.subarray(at + 10, at + 10 + colors * 3);
|
|
50
|
+
at += 10 + colors * 3;
|
|
51
|
+
const { indices, next } = lzwDecode(bytes, at);
|
|
52
|
+
frame.indices = indices;
|
|
53
|
+
at = next;
|
|
54
|
+
frames.push(frame);
|
|
55
|
+
} else throw new Error(`Unexpected GIF block ${bytes[at]}`);
|
|
56
|
+
}
|
|
57
|
+
return { width, height, frames, loops };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const solid = (width, height, color) => {
|
|
61
|
+
const pixels = new Uint8Array(width * height * 4);
|
|
62
|
+
for (let i = 0; i < width * height; i++) pixels.set([...color, 255], i * 4);
|
|
63
|
+
return pixels;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
describe('Animated image export', () => {
|
|
67
|
+
it('LZW codes decode back to the same indexes, across table resets', () => {
|
|
68
|
+
let seed = 7;
|
|
69
|
+
const random = () => (seed = (seed * 1103515245 + 12345) & 0x7fffffff) / 0x7fffffff;
|
|
70
|
+
const indices = Uint8Array.from({ length: 60000 }, (_, i) => i % 300 < 150 ? Math.floor(random() * 256) : i % 7);
|
|
71
|
+
assert.deepEqual(lzwDecode(lzwEncode(indices)).indices, [...indices]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('finds the changed rectangle', () => {
|
|
75
|
+
const a = solid(5, 4, [0, 0, 0]), b = a.slice();
|
|
76
|
+
b.set([9, 9, 9, 255], (2 * 5 + 1) * 4);
|
|
77
|
+
b.set([9, 9, 9, 255], (3 * 5 + 3) * 4);
|
|
78
|
+
assert.deepEqual(changedRect(a, b, 5, 4), { x: 1, y: 2, width: 3, height: 2 });
|
|
79
|
+
assert.equal(changedRect(a, a.slice(), 5, 4), null);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('builds a palette with the image colors', () => {
|
|
83
|
+
const pixels = new Uint8Array([...solid(4, 1, [255, 0, 0]), ...solid(4, 1, [0, 0, 255])]);
|
|
84
|
+
assert.deepEqual(medianCutPalette(pixels).sort(), [[0, 0, 255], [255, 0, 0]]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('writes a looping GIF that stores only changes, holds unchanged frames and drops frames under 20 ms', async () => {
|
|
88
|
+
const writer = createAnimatedWriter('gif', 4, 3);
|
|
89
|
+
const red = solid(4, 3, [255, 0, 0]);
|
|
90
|
+
const changed = red.slice();
|
|
91
|
+
changed.set([0, 0, 255, 255], (1 * 4 + 2) * 4);
|
|
92
|
+
await writer.add(red, 0);
|
|
93
|
+
await writer.add(red.slice(), 100); // Unchanged: the first frame lasts 200 ms.
|
|
94
|
+
await writer.add(changed, 200);
|
|
95
|
+
const later = changed.slice();
|
|
96
|
+
later.set([0, 255, 0, 255], 0);
|
|
97
|
+
await writer.add(later, 210); // 10 ms after the previous one: replaces it.
|
|
98
|
+
const gif = parseGif(await writer.finish(400));
|
|
99
|
+
assert.equal(gif.loops, true);
|
|
100
|
+
assert.deepEqual([gif.width, gif.height], [4, 3]);
|
|
101
|
+
assert.deepEqual(gif.frames.map(frame => [frame.x, frame.y, frame.width, frame.height, frame.delay]),
|
|
102
|
+
[[0, 0, 4, 3, 20], [0, 0, 3, 2, 20]]);
|
|
103
|
+
const color = (frame, i) => [...frame.palette.subarray(frame.indices[i] * 3, frame.indices[i] * 3 + 3)];
|
|
104
|
+
assert.deepEqual(color(gif.frames[0], 5), [255, 0, 0]);
|
|
105
|
+
assert.deepEqual(color(gif.frames[1], 0), [0, 255, 0]);
|
|
106
|
+
assert.deepEqual(color(gif.frames[1], 1 * 3 + 2), [0, 0, 255]);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('writes an APNG whose chunks check out, with ordered sequence numbers and the frames as drawn', async () => {
|
|
110
|
+
const writer = createAnimatedWriter('apng', 3, 2);
|
|
111
|
+
const frames = [solid(3, 2, [10, 20, 30]), solid(3, 2, [10, 20, 30]), solid(3, 2, [10, 20, 30])];
|
|
112
|
+
frames[1].set([200, 100, 50, 255], 4);
|
|
113
|
+
frames[2].set([1, 2, 3, 255], 20);
|
|
114
|
+
for (const [i, pixels] of frames.entries()) await writer.add(pixels, i * 125);
|
|
115
|
+
const png = Buffer.from(await writer.finish(375));
|
|
116
|
+
const chunks = [];
|
|
117
|
+
for (let at = 8; at < png.length;) {
|
|
118
|
+
const length = png.readUInt32BE(at), type = png.toString('latin1', at + 4, at + 8);
|
|
119
|
+
const data = png.subarray(at + 8, at + 8 + length);
|
|
120
|
+
assert.equal(png.readUInt32BE(at + 8 + length), (crc32(png.subarray(at + 4, at + 8 + length)) ^ 0xffffffff) >>> 0, `${type} CRC`);
|
|
121
|
+
chunks.push({ type, data });
|
|
122
|
+
at += 12 + length;
|
|
123
|
+
}
|
|
124
|
+
assert.deepEqual(chunks.map(chunk => chunk.type), ['IHDR', 'acTL', 'fcTL', 'IDAT', 'fcTL', 'fdAT', 'fcTL', 'fdAT', 'IEND']);
|
|
125
|
+
assert.equal(chunks[1].data.readUInt32BE(0), 3);
|
|
126
|
+
const sequences = chunks.filter(chunk => chunk.type === 'fcTL' || chunk.type === 'fdAT').map(chunk => chunk.data.readUInt32BE(0));
|
|
127
|
+
assert.deepEqual(sequences, [0, 1, 2, 3, 4]);
|
|
128
|
+
const controls = chunks.filter(chunk => chunk.type === 'fcTL').map(chunk =>
|
|
129
|
+
[chunk.data.readUInt32BE(4), chunk.data.readUInt32BE(8), chunk.data.readUInt32BE(12), chunk.data.readUInt32BE(16), chunk.data.readUInt16BE(20)]);
|
|
130
|
+
// Frame 3 restores the pixel frame 2 changed and changes another, so its rectangle covers both.
|
|
131
|
+
assert.deepEqual(controls, [[3, 2, 0, 0, 125], [1, 1, 1, 0, 125], [2, 2, 1, 0, 125]]);
|
|
132
|
+
// The first frame decodes to the color (Paeth-filtered rows).
|
|
133
|
+
const raw = inflateSync(chunks[3].data);
|
|
134
|
+
assert.equal(raw.length, 2 * (1 + 9));
|
|
135
|
+
assert.deepEqual([...raw.subarray(0, 4)], [4, 10, 20, 30]);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { evaluateArithmetic } from './src/arithmetic.js';
|
|
4
|
+
|
|
5
|
+
test('calculator supports precedence, grouping, unary signs, decimals and displayed operators', () => {
|
|
6
|
+
for (const [input, expected] of [
|
|
7
|
+
['8÷2×(2+2)', '16'], ['7−3*2', '1'], ['-(4 + -2) / .5', '-4'], ['0.1+0.2', '0.3'],
|
|
8
|
+
['1e+21 / 2', '500000000000000000000'], ['0', '0'],
|
|
9
|
+
]) assert.equal(evaluateArithmetic(input), expected, input);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('invalid expressions and division by zero report an error', () => {
|
|
13
|
+
for (const input of ['', '1 / 0', '(2+3', '2 +', '1 2', '8..2', '2(3)', 'abc', '1e999', '1e308*1e308', '1'.repeat(513)]) {
|
|
14
|
+
assert.throws(() => evaluateArithmetic(input), Error, input);
|
|
15
|
+
}
|
|
16
|
+
});
|