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
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
3
|
+
|
|
4
|
+
function makeRuntime() {
|
|
5
|
+
return new Function(`${SWFLIB_SOURCE}\nreturn __swoof_swflib;`)();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
describe('native DisplayObject geometry initialization', () => {
|
|
9
|
+
it('initializes visibility without calling a subclass setter before construction', () => {
|
|
10
|
+
const { builtins: { MovieClip } } = makeRuntime();
|
|
11
|
+
class PriceTag extends MovieClip {
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
this.visibilityChanges = [];
|
|
15
|
+
}
|
|
16
|
+
get visible() { return super.visible; }
|
|
17
|
+
set visible(value) {
|
|
18
|
+
this.visibilityChanges.push(value);
|
|
19
|
+
super.visible = value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const price = new PriceTag();
|
|
24
|
+
price.graphics.beginFill(0);
|
|
25
|
+
price.graphics.drawRect(0, 0, 10, 10);
|
|
26
|
+
price.graphics.endFill();
|
|
27
|
+
expect(price.visible).toBe(true);
|
|
28
|
+
expect(price.visibilityChanges).toEqual([]);
|
|
29
|
+
expect(price.hitTestPoint(5, 5, true)).toBe(true);
|
|
30
|
+
|
|
31
|
+
price.visible = false;
|
|
32
|
+
expect(price.visible).toBe(false);
|
|
33
|
+
expect(price.visibilityChanges).toEqual([false]);
|
|
34
|
+
expect(price.hitTestPoint(5, 5, true)).toBe(false);
|
|
35
|
+
expect(new PriceTag().visible).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('seeds native geometry before subclass setters while keeping their scripted calls live', () => {
|
|
39
|
+
const { builtins: { Point, Sprite } } = makeRuntime();
|
|
40
|
+
class Component extends Sprite {
|
|
41
|
+
constructor() {
|
|
42
|
+
super();
|
|
43
|
+
this.layoutChanges = [];
|
|
44
|
+
}
|
|
45
|
+
get x() { return super.x; }
|
|
46
|
+
set x(value) {
|
|
47
|
+
this.layoutChanges.push(['x', value]);
|
|
48
|
+
super.x = value;
|
|
49
|
+
}
|
|
50
|
+
get scaleX() { return super.scaleX; }
|
|
51
|
+
set scaleX(value) {
|
|
52
|
+
this.layoutChanges.push(['scaleX', value]);
|
|
53
|
+
super.scaleX = value;
|
|
54
|
+
}
|
|
55
|
+
get width() { return super.width; }
|
|
56
|
+
set width(value) {
|
|
57
|
+
this.layoutChanges.push(['width', value]);
|
|
58
|
+
super.width = value;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
class Skin extends Component {}
|
|
62
|
+
const skin = new Skin();
|
|
63
|
+
const anotherSkin = new Skin();
|
|
64
|
+
expect([skin.x, skin.y, skin.scaleX, skin.scaleY, skin.width, skin.height]).toEqual([0, 0, 1, 1, 0, 0]);
|
|
65
|
+
expect(skin.layoutChanges).toEqual([]);
|
|
66
|
+
Object.assign(skin, { x: 4, scaleX: 2, width: 20 });
|
|
67
|
+
expect(skin.layoutChanges).toEqual([['x', 4], ['scaleX', 2], ['width', 20]]);
|
|
68
|
+
expect([skin.x, skin.scaleX, skin.width]).toEqual([4, 2, 20]);
|
|
69
|
+
expect([anotherSkin.x, anotherSkin.scaleX, anotherSkin.width]).toEqual([0, 1, 0]);
|
|
70
|
+
expect(skin.localToGlobal(new Point(3, 2))).toMatchObject({ x: 10, y: 2 });
|
|
71
|
+
|
|
72
|
+
const sprite = new Sprite();
|
|
73
|
+
expect(Object.getOwnPropertyDescriptor(sprite, 'width')).toMatchObject({ value: 0, writable: true });
|
|
74
|
+
expect(Object.getOwnPropertyDescriptor(sprite, 'scaleX')).toMatchObject({ value: 1, writable: true });
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('native DisplayObject matrix scale', () => {
|
|
79
|
+
it('keeps layout scale overrides independent of painting, point conversion, and matrix writes', () => {
|
|
80
|
+
const runtime = makeRuntime();
|
|
81
|
+
const { Matrix, Point, Sprite } = runtime.builtins;
|
|
82
|
+
class LayoutComponent extends Sprite {
|
|
83
|
+
get scaleX() { return this.layoutScaleX; }
|
|
84
|
+
set scaleX(value) { this.layoutScaleX = value; }
|
|
85
|
+
get scaleY() { return this.layoutScaleY; }
|
|
86
|
+
set scaleY(value) { this.layoutScaleY = value; }
|
|
87
|
+
setNativeScaleX(value) { super.scaleX = value; }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const component = new LayoutComponent();
|
|
91
|
+
component.scaleX = 2;
|
|
92
|
+
component.scaleY = 3;
|
|
93
|
+
expect(component.transform.matrix).toMatchObject({ a: 1, d: 1 });
|
|
94
|
+
expect(component.localToGlobal(new Point(3, 2))).toMatchObject({ x: 3, y: 2 });
|
|
95
|
+
const appliedScales = [];
|
|
96
|
+
runtime.renderDisplayTree({
|
|
97
|
+
globalAlpha: 1, save() {}, restore() {}, translate() {},
|
|
98
|
+
scale(...args) { appliedScales.push(args); },
|
|
99
|
+
}, component);
|
|
100
|
+
expect(appliedScales).toEqual([]);
|
|
101
|
+
|
|
102
|
+
component.transform.matrix = new Matrix(4, 0, 0, 5, 10, 20);
|
|
103
|
+
expect(component.transform.matrix).toMatchObject({ a: 4, b: 0, c: 0, d: 5, tx: 10, ty: 20 });
|
|
104
|
+
expect(component.localToGlobal(new Point(3, 2))).toMatchObject({ x: 22, y: 30 });
|
|
105
|
+
expect([component.scaleX, component.scaleY]).toEqual([2, 3]);
|
|
106
|
+
|
|
107
|
+
component.transform.matrix.a = 6;
|
|
108
|
+
expect(component.transform.matrix.a).toBe(6);
|
|
109
|
+
expect(component.scaleX).toBe(2);
|
|
110
|
+
component.setNativeScaleX(7);
|
|
111
|
+
expect(component.transform.matrix.a).toBe(7);
|
|
112
|
+
expect(component.scaleX).toBe(2);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe('DisplayObject.stage', () => {
|
|
117
|
+
it('inherits stage through nested display-list parents and clears on detachment', () => {
|
|
118
|
+
const runtime = makeRuntime();
|
|
119
|
+
const { builtins, stage } = runtime;
|
|
120
|
+
const container = new builtins.Sprite();
|
|
121
|
+
const nested = new builtins.Sprite();
|
|
122
|
+
const child = new builtins.Sprite();
|
|
123
|
+
|
|
124
|
+
expect(stage.stage).toBe(stage);
|
|
125
|
+
expect(child.stage).toBeNull();
|
|
126
|
+
stage.addChild(container);
|
|
127
|
+
container.addChild(nested);
|
|
128
|
+
nested.addChild(child);
|
|
129
|
+
expect(container.stage).toBe(stage);
|
|
130
|
+
expect(nested.stage).toBe(stage);
|
|
131
|
+
expect(child.stage).toBe(stage);
|
|
132
|
+
|
|
133
|
+
container.removeChild(nested);
|
|
134
|
+
expect(nested.stage).toBeNull();
|
|
135
|
+
expect(child.stage).toBeNull();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('honors an explicitly assigned stage until that override is cleared', () => {
|
|
139
|
+
const { builtins, stage } = makeRuntime();
|
|
140
|
+
const otherStage = new builtins.Stage();
|
|
141
|
+
const child = new builtins.Sprite();
|
|
142
|
+
stage.addChild(child);
|
|
143
|
+
|
|
144
|
+
child.stage = otherStage;
|
|
145
|
+
expect(child.stage).toBe(otherStage);
|
|
146
|
+
child.stage = null;
|
|
147
|
+
expect(child.stage).toBe(stage);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe('DisplayObject enterFrame broadcasts', () => {
|
|
152
|
+
it('delivers one direct frame event to a detached Shape through attachment and removal', () => {
|
|
153
|
+
const runtime = makeRuntime();
|
|
154
|
+
const { stage, builtins: { Event, EventDispatcher, Shape, Sprite } } = runtime;
|
|
155
|
+
const parent = new Sprite();
|
|
156
|
+
const clock = parent.addChild(new Shape());
|
|
157
|
+
const plain = new EventDispatcher();
|
|
158
|
+
const clockEvents = [], parentEvents = [], capturedEvents = [], plainEvents = [];
|
|
159
|
+
const onClock = event => clockEvents.push([event.target === clock, event.currentTarget === clock, event.eventPhase]);
|
|
160
|
+
clock.addEventListener(Event.ENTER_FRAME, onClock, false, 0, true);
|
|
161
|
+
parent.addEventListener(Event.ENTER_FRAME, event => parentEvents.push(event.target === parent));
|
|
162
|
+
parent.addEventListener(Event.ENTER_FRAME, event => capturedEvents.push(event), true);
|
|
163
|
+
plain.addEventListener(Event.ENTER_FRAME, event => plainEvents.push(event));
|
|
164
|
+
|
|
165
|
+
runtime.pulseFrameEvents();
|
|
166
|
+
stage.addChild(parent);
|
|
167
|
+
runtime.pulseFrameEvents();
|
|
168
|
+
stage.removeChild(parent);
|
|
169
|
+
runtime.pulseFrameEvents();
|
|
170
|
+
clock.removeEventListener(Event.ENTER_FRAME, onClock);
|
|
171
|
+
runtime.pulseFrameEvents();
|
|
172
|
+
|
|
173
|
+
expect(clockEvents).toEqual(Array(3).fill([true, true, Event.AT_TARGET]));
|
|
174
|
+
expect(parentEvents).toEqual([true, true, true, true]);
|
|
175
|
+
expect(capturedEvents).toHaveLength(0);
|
|
176
|
+
expect(plainEvents).toHaveLength(0);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('clears held descendant listeners when the Loader unloads and stops', () => {
|
|
180
|
+
const runtime = makeRuntime();
|
|
181
|
+
const { stage, builtins: { Event, Loader, MovieClip, Shape } } = runtime;
|
|
182
|
+
const loader = stage.addChild(new Loader());
|
|
183
|
+
const content = new MovieClip();
|
|
184
|
+
const clock = content.addChild(new Shape());
|
|
185
|
+
let pulses = 0;
|
|
186
|
+
clock.addEventListener(Event.ENTER_FRAME, () => pulses++);
|
|
187
|
+
loader._attachLoadedContent(content, loader._loadGeneration);
|
|
188
|
+
|
|
189
|
+
runtime.pulseFrameEvents();
|
|
190
|
+
loader.unloadAndStop(false);
|
|
191
|
+
runtime.pulseFrameEvents();
|
|
192
|
+
|
|
193
|
+
expect(clock.hasEventListener(Event.ENTER_FRAME)).toBe(false);
|
|
194
|
+
expect(pulses).toBe(1);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('broadcasts frameConstructed and exitFrame to a detached display object on every pulse', () => {
|
|
198
|
+
const runtime = makeRuntime();
|
|
199
|
+
const { stage, builtins: { Event, Shape, Sprite } } = runtime;
|
|
200
|
+
const parent = new Sprite();
|
|
201
|
+
const clock = parent.addChild(new Shape());
|
|
202
|
+
const seen = [];
|
|
203
|
+
for (const type of [Event.ENTER_FRAME, Event.FRAME_CONSTRUCTED, Event.EXIT_FRAME]) {
|
|
204
|
+
clock.addEventListener(type, event => seen.push([type, event.target === clock, event.eventPhase]));
|
|
205
|
+
}
|
|
206
|
+
runtime.pulseFrameEvents();
|
|
207
|
+
stage.addChild(parent);
|
|
208
|
+
runtime.pulseFrameEvents();
|
|
209
|
+
stage.removeChild(parent);
|
|
210
|
+
runtime.pulseFrameEvents();
|
|
211
|
+
const sample = [true, Event.AT_TARGET];
|
|
212
|
+
expect(seen).toEqual([
|
|
213
|
+
[Event.ENTER_FRAME, ...sample], [Event.FRAME_CONSTRUCTED, ...sample], [Event.EXIT_FRAME, ...sample],
|
|
214
|
+
[Event.ENTER_FRAME, ...sample], [Event.FRAME_CONSTRUCTED, ...sample], [Event.EXIT_FRAME, ...sample],
|
|
215
|
+
[Event.ENTER_FRAME, ...sample], [Event.FRAME_CONSTRUCTED, ...sample], [Event.EXIT_FRAME, ...sample],
|
|
216
|
+
]);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
describe('DisplayObjectContainer lifecycle events', () => {
|
|
221
|
+
it('dispatches ancestor and subtree events around stage attachment and detachment', () => {
|
|
222
|
+
const { builtins: { Event, Sprite }, stage } = makeRuntime();
|
|
223
|
+
const child = new Sprite();
|
|
224
|
+
const leaf = new Sprite();
|
|
225
|
+
child.addChild(leaf);
|
|
226
|
+
const seen = [];
|
|
227
|
+
for (const [name, object] of [['stage', stage], ['child', child], ['leaf', leaf]]) {
|
|
228
|
+
for (const type of [Event.ADDED, Event.ADDED_TO_STAGE, Event.REMOVED, Event.REMOVED_FROM_STAGE]) {
|
|
229
|
+
object.addEventListener(type, (event) => seen.push([name, type, event.target, child.parent, leaf.stage]));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
stage.addChildAt(child, 0);
|
|
234
|
+
stage.removeChildAt(0);
|
|
235
|
+
expect(seen).toEqual([
|
|
236
|
+
['child', Event.ADDED, child, stage, stage],
|
|
237
|
+
['stage', Event.ADDED, child, stage, stage],
|
|
238
|
+
['child', Event.ADDED_TO_STAGE, child, stage, stage],
|
|
239
|
+
['leaf', Event.ADDED_TO_STAGE, leaf, stage, stage],
|
|
240
|
+
['child', Event.REMOVED, child, stage, stage],
|
|
241
|
+
['stage', Event.REMOVED, child, stage, stage],
|
|
242
|
+
['child', Event.REMOVED_FROM_STAGE, child, stage, stage],
|
|
243
|
+
['leaf', Event.REMOVED_FROM_STAGE, leaf, stage, stage],
|
|
244
|
+
]);
|
|
245
|
+
expect(child.parent).toBeNull();
|
|
246
|
+
expect(leaf.stage).toBeNull();
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('dispatches both sides of a same-stage reparent and keeps same-parent reordering quiet', () => {
|
|
250
|
+
const { builtins: { Event, Sprite }, stage } = makeRuntime();
|
|
251
|
+
const source = stage.addChild(new Sprite());
|
|
252
|
+
const destination = stage.addChild(new Sprite());
|
|
253
|
+
const child = source.addChild(new Sprite());
|
|
254
|
+
const leaf = child.addChild(new Sprite());
|
|
255
|
+
const sibling = destination.addChild(new Sprite());
|
|
256
|
+
const seen = [];
|
|
257
|
+
for (const type of [Event.ADDED, Event.ADDED_TO_STAGE, Event.REMOVED, Event.REMOVED_FROM_STAGE]) {
|
|
258
|
+
child.addEventListener(type, () => seen.push([type, child.parent]));
|
|
259
|
+
leaf.addEventListener(type, () => seen.push([type, leaf.parent]));
|
|
260
|
+
}
|
|
261
|
+
destination.addChildAt(child, 0);
|
|
262
|
+
expect(seen).toEqual([
|
|
263
|
+
[Event.REMOVED, source],
|
|
264
|
+
[Event.REMOVED_FROM_STAGE, source],
|
|
265
|
+
[Event.REMOVED_FROM_STAGE, child],
|
|
266
|
+
[Event.ADDED, destination],
|
|
267
|
+
[Event.ADDED_TO_STAGE, destination],
|
|
268
|
+
[Event.ADDED_TO_STAGE, child],
|
|
269
|
+
]);
|
|
270
|
+
expect(source.numChildren).toBe(0);
|
|
271
|
+
destination.addChildAt(child, 1);
|
|
272
|
+
expect(destination.getChildAt(0)).toBe(sibling);
|
|
273
|
+
expect(destination.getChildAt(1)).toBe(child);
|
|
274
|
+
expect(seen).toHaveLength(6);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('handles child changes made inside lifecycle listeners without duplicating entries or stage events', () => {
|
|
278
|
+
const { builtins: { Event, Sprite }, stage } = makeRuntime();
|
|
279
|
+
const child = new Sprite();
|
|
280
|
+
const leaf = new Sprite();
|
|
281
|
+
const seen = [];
|
|
282
|
+
leaf.addEventListener(Event.ADDED_TO_STAGE, () => seen.push('leaf added'));
|
|
283
|
+
leaf.addEventListener(Event.REMOVED_FROM_STAGE, () => seen.push('leaf removed'));
|
|
284
|
+
child.addEventListener(Event.ADDED, (event) => {
|
|
285
|
+
if (event.target === child) child.addChild(leaf);
|
|
286
|
+
});
|
|
287
|
+
child.addEventListener(Event.REMOVED, () => stage.removeChild(child));
|
|
288
|
+
stage.addChild(child);
|
|
289
|
+
expect(seen).toEqual(['leaf added']);
|
|
290
|
+
expect(() => leaf.addChild(stage)).toThrow(/own subtree/);
|
|
291
|
+
stage.removeChild(child);
|
|
292
|
+
expect(seen).toEqual(['leaf added', 'leaf removed']);
|
|
293
|
+
expect(stage.numChildren).toBe(0);
|
|
294
|
+
expect(child.parent).toBeNull();
|
|
295
|
+
expect(leaf.parent).toBe(child);
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('removes a snapshot of an inclusive child range and dispatches each child lifecycle in order', () => {
|
|
300
|
+
const { builtins, stage } = makeRuntime();
|
|
301
|
+
const { Event, Sprite } = builtins;
|
|
302
|
+
const holder = stage.addChild(new Sprite());
|
|
303
|
+
const destination = stage.addChild(new Sprite());
|
|
304
|
+
const keep = holder.addChild(new Sprite());
|
|
305
|
+
const first = holder.addChild(new Sprite());
|
|
306
|
+
const second = holder.addChild(new Sprite());
|
|
307
|
+
const removed = [];
|
|
308
|
+
first.addEventListener(Event.REMOVED, () => {
|
|
309
|
+
removed.push(first);
|
|
310
|
+
destination.addChild(second);
|
|
311
|
+
});
|
|
312
|
+
second.addEventListener(Event.REMOVED, () => { removed.push(second); });
|
|
313
|
+
holder.removeChildren(1);
|
|
314
|
+
expect(holder.numChildren).toBe(1);
|
|
315
|
+
expect(holder.getChildAt(0)).toBe(keep);
|
|
316
|
+
expect(destination.numChildren).toBe(0);
|
|
317
|
+
expect(removed).toEqual([first, second, second]);
|
|
318
|
+
expect(() => holder.removeChildren(1)).not.toThrow();
|
|
319
|
+
expect(() => holder.removeChildren(0, 1)).toThrow(RangeError);
|
|
320
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { createContext, runInContext } from 'node:vm';
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { createEmbeddedMovieRuntime } from '../runtime/embedded-movie-runtime.js';
|
|
4
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
5
|
+
|
|
6
|
+
function defer() {
|
|
7
|
+
let resolve;
|
|
8
|
+
const promise = new Promise(done => { resolve = done; });
|
|
9
|
+
return { promise, resolve };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function audioFixture() {
|
|
13
|
+
const instances = [];
|
|
14
|
+
class Audio {
|
|
15
|
+
paused = true;
|
|
16
|
+
listeners = {};
|
|
17
|
+
constructor(url) { this.src = url || ''; instances.push(this); }
|
|
18
|
+
cloneNode() { return new Audio(this.src); }
|
|
19
|
+
play() { this.paused = false; return Promise.resolve(); }
|
|
20
|
+
pause() { this.paused = true; }
|
|
21
|
+
load() {}
|
|
22
|
+
removeAttribute(name) { if (name === 'src') this.src = ''; }
|
|
23
|
+
addEventListener(type, callback) { this.listeners[type] = callback; }
|
|
24
|
+
removeEventListener(type) { delete this.listeners[type]; }
|
|
25
|
+
}
|
|
26
|
+
const context = createContext({ Audio, atob, setTimeout, clearTimeout, setInterval, clearInterval, document: {
|
|
27
|
+
getElementById: () => null,
|
|
28
|
+
createElement: () => ({ getContext: () => null }),
|
|
29
|
+
} });
|
|
30
|
+
const runtime = runInContext(SWFLIB_SOURCE + '\n__swoof_swflib;', context);
|
|
31
|
+
const bytes = (id) => runInContext('Uint8Array.of(70,87,83,10,8,0,0,' + id + ')', context);
|
|
32
|
+
const assets = { stageW: 10, stageH: 10, frameRate: 24, assets: [], symbolClasses: [], linkedBinaryData: [] };
|
|
33
|
+
function register(id, onCreate) {
|
|
34
|
+
const file = bytes(id);
|
|
35
|
+
runtime.registerEmbeddedSwf(file, (environment) =>
|
|
36
|
+
createEmbeddedMovieRuntime(runtime, context, environment, assets, () => Promise.resolve(),
|
|
37
|
+
() => null, (movie) => {
|
|
38
|
+
const timeline = {
|
|
39
|
+
enter() {}, stop() {}, setStreamPlaybackSuspended: vi.fn(),
|
|
40
|
+
};
|
|
41
|
+
const setup = movie.bindTimeline(timeline, {}, {}, [], 1);
|
|
42
|
+
const root = setup.boot(null, () => null);
|
|
43
|
+
return onCreate({ root, timeline, movie });
|
|
44
|
+
}));
|
|
45
|
+
return file;
|
|
46
|
+
}
|
|
47
|
+
function load(loader, file) {
|
|
48
|
+
const complete = new Promise((resolve, reject) => {
|
|
49
|
+
loader.contentLoaderInfo.addEventListener('complete', resolve);
|
|
50
|
+
loader.contentLoaderInfo.addEventListener('ioError', (event) => reject(new Error(event.text)));
|
|
51
|
+
});
|
|
52
|
+
loader.loadBytes(file);
|
|
53
|
+
return complete;
|
|
54
|
+
}
|
|
55
|
+
return { runtime, register, instances, load };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
describe('embedded script-created Sound lifecycle', () => {
|
|
59
|
+
it('cancels pending media policy across a descendant and leaves the parent channel alone', async () => {
|
|
60
|
+
const { runtime, register, instances, load } = audioFixture();
|
|
61
|
+
const { Sound, Loader, Security } = runtime.builtins;
|
|
62
|
+
const policy = defer();
|
|
63
|
+
Security._checkPolicyFiles = (url) => url === 'pending.mp3' ? policy.promise : null;
|
|
64
|
+
const nested = new Loader();
|
|
65
|
+
const child = new Loader();
|
|
66
|
+
const parentChannel = new Sound('parent.mp3').play();
|
|
67
|
+
let pendingChannel, loading, media, createdMovie, nestedTimeline;
|
|
68
|
+
const complete = vi.fn();
|
|
69
|
+
const outerBytes = register(1, ({ root }) => { root.addChild(nested); return root; });
|
|
70
|
+
const innerBytes = register(2, ({ root, movie, timeline }) => {
|
|
71
|
+
createdMovie = movie;
|
|
72
|
+
nestedTimeline = timeline;
|
|
73
|
+
const MovieSound = movie.runtime.packages.media.Sound;
|
|
74
|
+
expect(movie.runtime.packages.utils.getDefinitionByName('flash.media::Sound')).toBe(MovieSound);
|
|
75
|
+
expect(new MovieSound()).toBeInstanceOf(Sound);
|
|
76
|
+
expect(new Sound()).toBeInstanceOf(MovieSound);
|
|
77
|
+
const waiting = new movie.global.Sound('pending.mp3', { checkPolicyFile: true });
|
|
78
|
+
pendingChannel = waiting.play();
|
|
79
|
+
loading = new MovieSound('loading.mp3');
|
|
80
|
+
media = instances.find(audio => audio.src === 'loading.mp3');
|
|
81
|
+
loading.addEventListener('complete', complete);
|
|
82
|
+
return root;
|
|
83
|
+
});
|
|
84
|
+
await load(child, outerBytes);
|
|
85
|
+
await load(nested, innerBytes);
|
|
86
|
+
const staleComplete = media.oncanplaythrough;
|
|
87
|
+
expect(pendingChannel._audio).toBeNull();
|
|
88
|
+
child.unloadAndStop();
|
|
89
|
+
expect(pendingChannel._stopped).toBe(true);
|
|
90
|
+
expect(nestedTimeline.setStreamPlaybackSuspended).toHaveBeenCalledWith(true);
|
|
91
|
+
expect(parentChannel._audio.paused).toBe(false);
|
|
92
|
+
expect(media.src).toBe('');
|
|
93
|
+
expect(media.oncanplaythrough).toBeNull();
|
|
94
|
+
|
|
95
|
+
staleComplete();
|
|
96
|
+
policy.resolve(true);
|
|
97
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
98
|
+
expect(complete).not.toHaveBeenCalled();
|
|
99
|
+
expect(instances.some(audio => audio.src === 'pending.mp3')).toBe(false);
|
|
100
|
+
expect(new createdMovie.global.Sound('stale.mp3').play()._audio).toBeNull();
|
|
101
|
+
expect(instances.some(audio => audio.src === 'stale.mp3')).toBe(false);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('cancels audio immediately when its compiled factory has not yet returned the child', async () => {
|
|
105
|
+
const { runtime, register } = audioFixture();
|
|
106
|
+
const loader = new runtime.builtins.Loader();
|
|
107
|
+
const started = defer(), finish = defer();
|
|
108
|
+
let earlyChannel, earlyMedia, earlyTimer;
|
|
109
|
+
const file = register(3, ({ root, movie }) => {
|
|
110
|
+
earlyChannel = new movie.runtime.builtins.Sound('early.mp3').play();
|
|
111
|
+
earlyMedia = earlyChannel._audio;
|
|
112
|
+
earlyTimer = new movie.runtime.builtins.Timer(1000);
|
|
113
|
+
earlyTimer.start();
|
|
114
|
+
started.resolve();
|
|
115
|
+
return finish.promise.then(() => root);
|
|
116
|
+
});
|
|
117
|
+
const failed = new Promise((_, reject) => loader.contentLoaderInfo.addEventListener('ioError', (event) => reject(new Error(event.text))));
|
|
118
|
+
loader.loadBytes(file);
|
|
119
|
+
await Promise.race([started.promise, failed]);
|
|
120
|
+
expect(loader.content).toBeNull();
|
|
121
|
+
expect(earlyMedia.paused).toBe(false);
|
|
122
|
+
expect(earlyTimer.running).toBe(true);
|
|
123
|
+
loader.unloadAndStop();
|
|
124
|
+
expect(earlyMedia.paused).toBe(true);
|
|
125
|
+
expect(earlyTimer.running).toBe(false);
|
|
126
|
+
finish.resolve();
|
|
127
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
128
|
+
expect(loader.content).toBeNull();
|
|
129
|
+
expect(earlyChannel._audio).toBeNull();
|
|
130
|
+
});
|
|
131
|
+
});
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { createContext, runInContext } from 'node:vm';
|
|
5
|
+
import { describe, expect, it } from 'vitest';
|
|
6
|
+
import { parse } from '../parser/swf-parser.js';
|
|
7
|
+
import { decode } from '../decoder/tag-decoder.js';
|
|
8
|
+
import { transpileActionScript } from '../transpiler/actionscript.js';
|
|
9
|
+
import { SymbolTable } from '../decoder/symbol-table.js';
|
|
10
|
+
import { emit } from '../emitter/bundle-emitter.js';
|
|
11
|
+
import { precompileEmbeddedSwfs } from '../emitter/embedded-swf.js';
|
|
12
|
+
import { DiagnosticsCollector } from '../util/diagnostics.js';
|
|
13
|
+
|
|
14
|
+
describe('embedded SWF bundle factories', () => {
|
|
15
|
+
it('ignores non-SWF payloads and reports broken embedded files without rejecting the parent', async () => {
|
|
16
|
+
const symbols = new SymbolTable();
|
|
17
|
+
symbols.set(12, { type: 'DefineBinaryData', rawData: Uint8Array.of(1, 2, 3) });
|
|
18
|
+
symbols.set(19, { type: 'DefineBinaryData', rawData: Uint8Array.of(0x43, 0x57, 0x53, 10, 8, 0, 0, 0) });
|
|
19
|
+
const diagnostics = new DiagnosticsCollector();
|
|
20
|
+
expect(await precompileEmbeddedSwfs(symbols, diagnostics)).toEqual([]);
|
|
21
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
22
|
+
expect(diagnostics.warnings()).toMatchObject([
|
|
23
|
+
{ stage: 'parse', context: { embeddedCharacterPath: [19] } },
|
|
24
|
+
]);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it.each([false, true])('boots the Age of War 2 preloader through compiled children (omit bytes %s)', async omitEmbeddedSwfBytes => {
|
|
28
|
+
const fixture = 'archive/Swf/age-of-war-2.swf';
|
|
29
|
+
const { doc, diagnostics } = await parse(new Uint8Array(readFileSync(fixture)));
|
|
30
|
+
const { tags, symbolTable } = decode(doc, diagnostics);
|
|
31
|
+
const actionScript = transpileActionScript(tags, diagnostics, { sharedAvm2Runtime: true });
|
|
32
|
+
const embeddedSwfs = await precompileEmbeddedSwfs(symbolTable, diagnostics);
|
|
33
|
+
expect(embeddedSwfs).toHaveLength(30);
|
|
34
|
+
|
|
35
|
+
const output = mkdtempSync(join(tmpdir(), 'swoof-embedded-'));
|
|
36
|
+
try {
|
|
37
|
+
const sidecar = join(output, 'age-of-war-2', 'binary-data.js');
|
|
38
|
+
if (omitEmbeddedSwfBytes) {
|
|
39
|
+
mkdirSync(join(output, 'age-of-war-2'));
|
|
40
|
+
writeFileSync(sidecar, 'stale output from a regular export');
|
|
41
|
+
}
|
|
42
|
+
const bundle = emit({ header: doc.header, tags, symbolTable, actionScript, embeddedSwfs },
|
|
43
|
+
fixture, output, diagnostics, { externalTimelineData: true, omitEmbeddedSwfBytes });
|
|
44
|
+
expect(existsSync(sidecar)).toBe(!omitEmbeddedSwfBytes);
|
|
45
|
+
expect(readFileSync(bundle.htmlPath, 'utf8').includes('src="binary-data.js"')).toBe(!omitEmbeddedSwfBytes);
|
|
46
|
+
const canvasOps = [];
|
|
47
|
+
const loadedScripts = [];
|
|
48
|
+
const stagedCanvases = [];
|
|
49
|
+
const decodedPayloads = [];
|
|
50
|
+
let context, boot;
|
|
51
|
+
const canvasContext = new Proxy({
|
|
52
|
+
clearRect(...args) { canvasOps.push(args); },
|
|
53
|
+
drawImage(image) { stagedCanvases.push(image); },
|
|
54
|
+
measureText() { return { width: 0 }; },
|
|
55
|
+
createLinearGradient() { return { addColorStop() {} }; },
|
|
56
|
+
createRadialGradient() { return { addColorStop() {} }; },
|
|
57
|
+
}, { get(target, key) { return key in target ? target[key] : () => {}; } });
|
|
58
|
+
const sandbox = {
|
|
59
|
+
console: { log() {}, warn() {}, error() {} },
|
|
60
|
+
atob(value) { decodedPayloads.push(value.length); return atob(value); },
|
|
61
|
+
setTimeout, clearTimeout, canvasContext,
|
|
62
|
+
addEventListener(type, handler) { if (type === 'load') boot = handler; },
|
|
63
|
+
removeEventListener() {}, requestAnimationFrame() { return 1; },
|
|
64
|
+
document: {
|
|
65
|
+
getElementById() { return null; },
|
|
66
|
+
createElement(tag) {
|
|
67
|
+
if (tag === 'script') return { remove() {} };
|
|
68
|
+
return { getContext() { return canvasContext; }, style: {} };
|
|
69
|
+
},
|
|
70
|
+
head: {
|
|
71
|
+
appendChild(script) {
|
|
72
|
+
loadedScripts.push(script.src);
|
|
73
|
+
sandbox.document.currentScript = script;
|
|
74
|
+
try {
|
|
75
|
+
runInContext(readFileSync(join(bundle.bundleDir, script.src), 'utf8'), context);
|
|
76
|
+
} finally {
|
|
77
|
+
sandbox.document.currentScript = null;
|
|
78
|
+
}
|
|
79
|
+
script.onload();
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
Image: class {
|
|
84
|
+
width = 1;
|
|
85
|
+
height = 1;
|
|
86
|
+
set src(value) { this.onload(); }
|
|
87
|
+
},
|
|
88
|
+
Path2D: class {
|
|
89
|
+
moveTo() {} lineTo() {} quadraticCurveTo() {} bezierCurveTo() {} closePath() {}
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
sandbox.window = sandbox;
|
|
93
|
+
context = createContext(sandbox);
|
|
94
|
+
const sharedRuntime = readFileSync(bundle.swflibPath, 'utf8');
|
|
95
|
+
const preloaderPath = 'assets/preloader/preloader.js';
|
|
96
|
+
const childSource = readFileSync(join(bundle.bundleDir, preloaderPath), 'utf8');
|
|
97
|
+
expect(readFileSync(join(bundle.bundleDir, 'assets/backgrounds/backgrounds.js'), 'utf8'))
|
|
98
|
+
.toContain('document.currentScript._swoofMovieFactory');
|
|
99
|
+
expect(sharedRuntime).toContain('function createEmbeddedMovieRuntime(');
|
|
100
|
+
expect(childSource).toContain('__swoof_swflib.createEmbeddedMovieRuntime(');
|
|
101
|
+
expect(childSource).not.toContain('function MovieDomain(');
|
|
102
|
+
expect(childSource).not.toContain('function bindConstructingDocument(instance)');
|
|
103
|
+
runInContext(sharedRuntime, context);
|
|
104
|
+
runInContext(readFileSync(bundle.movieDataPath, 'utf8'), context);
|
|
105
|
+
if (bundle.binaryDataPath) runInContext(readFileSync(bundle.binaryDataPath, 'utf8'), context);
|
|
106
|
+
const rootJs = readFileSync(bundle.jsPath, 'utf8');
|
|
107
|
+
expect(rootJs).not.toContain(Buffer.from(embeddedSwfs[0].bytes).toString('base64'));
|
|
108
|
+
runInContext(rootJs, context);
|
|
109
|
+
expect(sandbox.__swoofBinaryData).toBeUndefined();
|
|
110
|
+
expect(decodedPayloads).toEqual([]);
|
|
111
|
+
const result = await runInContext(`
|
|
112
|
+
(async function () {
|
|
113
|
+
const hostDomain = ApplicationDomain.currentDomain;
|
|
114
|
+
const Payload = hostDomain.getDefinition('net.louissi.Alpha1.Screens.Preloader_PRELOADER_SWF_dataClass');
|
|
115
|
+
function load() {
|
|
116
|
+
return new Promise(function (resolve, reject) {
|
|
117
|
+
const loader = new Loader();
|
|
118
|
+
const info = loader.contentLoaderInfo;
|
|
119
|
+
const events = [];
|
|
120
|
+
info.addEventListener('ioError', function (event) { reject(new Error(event.text)); });
|
|
121
|
+
info.addEventListener('init', function () { events.push('init'); });
|
|
122
|
+
info.addEventListener('complete', function () {
|
|
123
|
+
events.push('complete');
|
|
124
|
+
__swoof_swflib.renderDisplayTree(canvasContext, loader.content, 0);
|
|
125
|
+
resolve({ loader: loader, result: {
|
|
126
|
+
events: events,
|
|
127
|
+
owned: loader.content instanceof MovieClip && loader.content.parent === loader,
|
|
128
|
+
reflection: swoof.utils.getDefinitionByName('flash.display::Loader') === Loader,
|
|
129
|
+
domainIsolated: !hostDomain.hasDefinition('preloader_fla.MainTimeline') &&
|
|
130
|
+
info.applicationDomain.getDefinition('preloader_fla.MainTimeline') === loader.content.constructor,
|
|
131
|
+
metadata: [info.width, info.height, info.frameRate, loader.content.totalFrames],
|
|
132
|
+
constructor: loader.content.constructor.__swoofQualifiedName,
|
|
133
|
+
artworkInDisplayList: loader.content._children.some(function (child) {
|
|
134
|
+
return child.bitmapData && child.bitmapData._img === loader.content._swoofTimelineCanvas;
|
|
135
|
+
}),
|
|
136
|
+
qualifiedNames: [
|
|
137
|
+
swoof.utils.getQualifiedClassName(loader.content),
|
|
138
|
+
swoof.utils.getQualifiedClassName(loader.content.constructor),
|
|
139
|
+
swoof.utils.getQualifiedClassName(new Loader()),
|
|
140
|
+
swoof.utils.getQualifiedClassName('preloader'),
|
|
141
|
+
swoof.utils.getQualifiedClassName(30),
|
|
142
|
+
swoof.utils.getQualifiedClassName(null),
|
|
143
|
+
],
|
|
144
|
+
} });
|
|
145
|
+
});
|
|
146
|
+
loader.loadBytes(new Payload());
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
const first = await load();
|
|
150
|
+
const second = await load();
|
|
151
|
+
first.result.independent = first.loader.content !== second.loader.content &&
|
|
152
|
+
first.loader.content._swoofTimeline !== second.loader.content._swoofTimeline &&
|
|
153
|
+
first.loader.content.constructor !== second.loader.content.constructor &&
|
|
154
|
+
first.loader.contentLoaderInfo.applicationDomain !== second.loader.contentLoaderInfo.applicationDomain;
|
|
155
|
+
return first.result;
|
|
156
|
+
})()
|
|
157
|
+
`, context);
|
|
158
|
+
expect(result).toEqual({
|
|
159
|
+
events: ['init', 'complete'],
|
|
160
|
+
owned: true,
|
|
161
|
+
independent: true,
|
|
162
|
+
domainIsolated: true,
|
|
163
|
+
reflection: true,
|
|
164
|
+
metadata: [720, 480, 30, 1],
|
|
165
|
+
constructor: 'preloader_fla.MainTimeline',
|
|
166
|
+
artworkInDisplayList: false,
|
|
167
|
+
qualifiedNames: [
|
|
168
|
+
'preloader_fla::MainTimeline', 'preloader_fla::MainTimeline', 'flash.display::Loader',
|
|
169
|
+
'String', 'int', 'null',
|
|
170
|
+
],
|
|
171
|
+
});
|
|
172
|
+
const realBoot = runInContext(`
|
|
173
|
+
new Promise(function (resolve, reject) {
|
|
174
|
+
const loadBytes = Loader.prototype.loadBytes;
|
|
175
|
+
Loader.prototype.loadBytes = function (bytes, context) {
|
|
176
|
+
const info = this.contentLoaderInfo;
|
|
177
|
+
info.addEventListener('ioError', function (event) { reject(new Error(event.text)); });
|
|
178
|
+
info.addEventListener('complete', function () {
|
|
179
|
+
resolve([window.__swoof.main.constructor.__swoofQualifiedName, info.content.constructor.__swoofQualifiedName]);
|
|
180
|
+
});
|
|
181
|
+
return loadBytes.call(this, bytes, context);
|
|
182
|
+
};
|
|
183
|
+
})
|
|
184
|
+
`, context);
|
|
185
|
+
boot();
|
|
186
|
+
expect(await realBoot).toEqual(['net.louissi.Alpha1.EngineStart', 'preloader_fla.MainTimeline']);
|
|
187
|
+
expect(loadedScripts).toEqual([preloaderPath]);
|
|
188
|
+
expect(decodedPayloads).toEqual([]);
|
|
189
|
+
expect(canvasOps).toContainEqual([0, 0, 720, 480]);
|
|
190
|
+
expect(stagedCanvases.some(canvas => canvas.width === 720 && canvas.height === 480)).toBe(true);
|
|
191
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
192
|
+
if (omitEmbeddedSwfBytes) {
|
|
193
|
+
expect(() => runInContext(`
|
|
194
|
+
const type = ApplicationDomain.currentDomain.getDefinition('net.louissi.Alpha1.Screens.Preloader_PRELOADER_SWF_dataClass');
|
|
195
|
+
new type().readUnsignedByte();
|
|
196
|
+
`, context)).toThrow('This export omits original embedded SWF bytes');
|
|
197
|
+
}
|
|
198
|
+
} finally {
|
|
199
|
+
rmSync(output, { recursive: true, force: true });
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
});
|