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,420 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { runInNewContext } from 'node:vm';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { SymbolTable } from '../decoder/symbol-table.js';
|
|
5
|
+
import { decodeTag } from '../decoder/tag-decoder.js';
|
|
6
|
+
import { TAG } from '../decoder/tag-types.js';
|
|
7
|
+
import { embeddedSwfFactorySource } from '../emitter/embedded-swf.js';
|
|
8
|
+
import { parse } from '../parser/swf-parser.js';
|
|
9
|
+
import { createEmbeddedMovieRuntime } from '../runtime/embedded-movie-runtime.js';
|
|
10
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
11
|
+
import { buildDisplayList } from '../transpiler/timeline/display-list.js';
|
|
12
|
+
import { generateTimelineEngine, timelineEngineFactorySource, timelineHelpersSource } from '../transpiler/timeline/timeline-codegen.js';
|
|
13
|
+
|
|
14
|
+
describe('embedded timeline input', () => {
|
|
15
|
+
it('routes native clicks to the imported Age of War 2 tutorial artwork on the host stage', async () => {
|
|
16
|
+
const { doc } = await parse(readFileSync('archive/Swf/age-of-war-2.swf'));
|
|
17
|
+
const hudPayload = doc.tags.find(tag => tag.code === TAG.DefineBinaryData && tag.data[0] === 81 && tag.data[1] === 0);
|
|
18
|
+
const { doc: hud, diagnostics } = await parse(hudPayload.data.subarray(6));
|
|
19
|
+
const symbolTable = new SymbolTable();
|
|
20
|
+
for (const id of [332, 331, 291, 40]) {
|
|
21
|
+
const tag = hud.tags.find(entry => [TAG.DefineSprite, TAG.DefineShape, TAG.DefineShape2, TAG.DefineShape3, TAG.DefineShape4].includes(entry.code) &&
|
|
22
|
+
(entry.data[0] | (entry.data[1] << 8)) === id);
|
|
23
|
+
symbolTable.set(id, decodeTag(tag, hud, diagnostics));
|
|
24
|
+
}
|
|
25
|
+
const { characters } = buildDisplayList([], symbolTable, diagnostics, { swfVersion: hud.header.version });
|
|
26
|
+
const canvasListeners = {}, windowListeners = {};
|
|
27
|
+
const canvas = {
|
|
28
|
+
width: 800, height: 620, style: {},
|
|
29
|
+
getBoundingClientRect: () => ({ left: 0, top: 0, width: 800, height: 620 }),
|
|
30
|
+
addEventListener: (name, listener) => { (canvasListeners[name] ||= []).push(listener); },
|
|
31
|
+
};
|
|
32
|
+
const ctx = new Proxy({
|
|
33
|
+
canvas, globalAlpha: 1,
|
|
34
|
+
getTransform: () => ({ a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }),
|
|
35
|
+
}, { get: (obj, key) => obj[key] ?? (() => {}) });
|
|
36
|
+
const sandbox = {
|
|
37
|
+
ctx,
|
|
38
|
+
PointerEvent: class {}, Path2D: class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} },
|
|
39
|
+
addEventListener: (name, listener) => { (windowListeners[name] ||= []).push(listener); },
|
|
40
|
+
document: {
|
|
41
|
+
readyState: 'complete', getElementById: id => id === 'stage' ? canvas : null,
|
|
42
|
+
createElement: () => ({ getContext: () => null }),
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
sandbox.window = sandbox;
|
|
46
|
+
const { host, clip, blocker, events, onClick, runtime } = runInNewContext(`
|
|
47
|
+
${SWFLIB_SOURCE}
|
|
48
|
+
const runtime = __swoof_swflib;
|
|
49
|
+
runtime.timelineHelpers = ${timelineHelpersSource()};
|
|
50
|
+
const factory = ${timelineEngineFactorySource()};
|
|
51
|
+
function makeTimeline(main, characters, symbolClasses) {
|
|
52
|
+
const namespace = { __swoof: { main } };
|
|
53
|
+
const engine = factory({ characters, frames: [{}], frameCount: 1 },
|
|
54
|
+
{ symbolClasses, frameRate: 30, assets: [] },
|
|
55
|
+
{ global: namespace, window: namespace, runtime, loaded: {} }, {});
|
|
56
|
+
main._swoofHostTimeline = true;
|
|
57
|
+
main._swoofTimeline = engine.timeline;
|
|
58
|
+
return namespace;
|
|
59
|
+
}
|
|
60
|
+
const host = runtime.stage.addChild(new MovieClip());
|
|
61
|
+
makeTimeline(host, {}, []);
|
|
62
|
+
host.x = 40;
|
|
63
|
+
host.y = 25;
|
|
64
|
+
host.scaleX = 0.5;
|
|
65
|
+
const library = makeTimeline(new MovieClip(), ${JSON.stringify(characters)}, [{ id: 332, name: 'HudFixture' }]);
|
|
66
|
+
class HudFixture extends MovieClip {
|
|
67
|
+
constructor() {
|
|
68
|
+
super();
|
|
69
|
+
library.__swoof_bindAs3SymbolInstance(this);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
HudFixture.__swoofQualifiedName = 'HudFixture';
|
|
73
|
+
const clip = host.addChild(new HudFixture());
|
|
74
|
+
const blocker = clip.tutorial.clickBlocker;
|
|
75
|
+
const events = [];
|
|
76
|
+
const onClick = event => {
|
|
77
|
+
events.push(event);
|
|
78
|
+
clip.tutorial.mouseChildren = false;
|
|
79
|
+
};
|
|
80
|
+
blocker.addEventListener('click', onClick);
|
|
81
|
+
runtime.renderDisplayTree(ctx, host);
|
|
82
|
+
({ host, clip, blocker, events, onClick, runtime });
|
|
83
|
+
`, sandbox);
|
|
84
|
+
expect(blocker._swoofCharacterId).toBe(291);
|
|
85
|
+
expect(blocker.hitTestPoint(220, 265, true)).toBe(true);
|
|
86
|
+
function click(x, y) {
|
|
87
|
+
for (const type of ['pointerdown', 'pointerup']) {
|
|
88
|
+
const handlers = type === 'pointerup' ? windowListeners : canvasListeners;
|
|
89
|
+
for (const listener of handlers[type] || []) {
|
|
90
|
+
listener({ clientX: x, clientY: y, pointerId: 1, pointerType: 'mouse', isPrimary: true,
|
|
91
|
+
button: 0, buttons: type === 'pointerdown' ? 1 : 0, preventDefault() {} });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
click(220, 265);
|
|
96
|
+
expect(events.map(event => [event.type, event.stageX, event.stageY, event.localX, event.localY]))
|
|
97
|
+
.toEqual([['click', 220, 265, 360, 240]]);
|
|
98
|
+
expect(events[0].target).toBe(blocker);
|
|
99
|
+
// A live change suppresses descendant hits before another render pulse.
|
|
100
|
+
click(220, 265);
|
|
101
|
+
expect(events).toHaveLength(1);
|
|
102
|
+
expect(runtime.canvasProgrammaticPointerAt(220, 265)).not.toBe(blocker);
|
|
103
|
+
|
|
104
|
+
clip.tutorial.mouseChildren = true;
|
|
105
|
+
blocker.removeEventListener('click', onClick);
|
|
106
|
+
blocker.addEventListener('mouseWheel', event => events.push(event));
|
|
107
|
+
runtime.renderDisplayTree(ctx, host);
|
|
108
|
+
expect(runtime.canvasProgrammaticPointerAt(220, 265)).toBe(blocker);
|
|
109
|
+
for (const listener of canvasListeners.wheel || []) {
|
|
110
|
+
listener({ clientX: 220, clientY: 265, deltaMode: 1, deltaY: -2, preventDefault() {} });
|
|
111
|
+
}
|
|
112
|
+
expect(events).toHaveLength(2);
|
|
113
|
+
expect(events[1]).toMatchObject({ type: 'mouseWheel', target: blocker, stageX: 220, stageY: 265, delta: 2 });
|
|
114
|
+
expect(events[1].localX).toBeCloseTo(360);
|
|
115
|
+
expect(events[1].localY).toBeCloseTo(240);
|
|
116
|
+
host.removeChild(clip);
|
|
117
|
+
expect(runtime.canvasProgrammaticPointerAt(220, 265)).toBeNull();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('picks transformed authored mouse and touch targets and cancels capture on unload', async () => {
|
|
121
|
+
const translate = (x, y) => ({ a: 1, b: 0, c: 0, d: 1, tx: 20 * x, ty: 20 * y });
|
|
122
|
+
const timelineJs = generateTimelineEngine({
|
|
123
|
+
frames: [{ places: [{ depth: 1, characterId: 2, name: 'outer', matrix: translate(10, 0) }] }],
|
|
124
|
+
characters: {
|
|
125
|
+
1: { type: 'shape', bounds: { x: 0, y: 0, w: 10, h: 10 },
|
|
126
|
+
draws: [{ fill: { type: 'solid', color: '#fff' }, path: [['M', 0, 0], ['L', 10, 0], ['L', 10, 10], ['Z']] }] },
|
|
127
|
+
2: { type: 'sprite', frames: [{ places: [{ depth: 1, characterId: 3, name: 'inner', matrix: translate(5, 10) }] }] },
|
|
128
|
+
3: { type: 'sprite', frames: [{ places: [{ depth: 1, characterId: 1 }] }] },
|
|
129
|
+
},
|
|
130
|
+
}, { stageW: 60, stageH: 50, frameRate: 24, frameCount: 1, embedded: true, sharedFactory: true });
|
|
131
|
+
const factory = embeddedSwfFactorySource({
|
|
132
|
+
stageW: 60, stageH: 50, frameRate: 24, sourceBytes: 8,
|
|
133
|
+
assetManifest: [], symbolClasses: [], linkedBinaryData: [], exportAssets: [], timelineJs, actionScriptJs: '',
|
|
134
|
+
});
|
|
135
|
+
const windowHandlers = {}, canvasHandlers = {}, releasedIds = [];
|
|
136
|
+
const canvas = {
|
|
137
|
+
width: 200, height: 150, style: {},
|
|
138
|
+
getBoundingClientRect: () => ({ left: 0, top: 0, width: 200, height: 150 }),
|
|
139
|
+
addEventListener: (name, listener) => { (canvasHandlers[name] ||= []).push(listener); },
|
|
140
|
+
setPointerCapture() {},
|
|
141
|
+
releasePointerCapture: id => releasedIds.push(id),
|
|
142
|
+
};
|
|
143
|
+
const context = new Proxy({}, { get: (value, key) => value[key] || (() => {}) });
|
|
144
|
+
const sandbox = {
|
|
145
|
+
atob, setTimeout, clearTimeout,
|
|
146
|
+
PointerEvent: class {}, Path2D: class { moveTo() {} lineTo() {} closePath() {} },
|
|
147
|
+
addEventListener: (name, listener) => { (windowHandlers[name] ||= []).push(listener); },
|
|
148
|
+
document: {
|
|
149
|
+
readyState: 'complete',
|
|
150
|
+
getElementById: id => id === 'stage' ? canvas : null,
|
|
151
|
+
createElement: () => ({ getContext: () => context }),
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
sandbox.window = sandbox;
|
|
155
|
+
const runtime = runInNewContext(`${SWFLIB_SOURCE}
|
|
156
|
+
__swoof_swflib.createEmbeddedMovieRuntime = ${createEmbeddedMovieRuntime.toString()};
|
|
157
|
+
__swoof_swflib.timelineHelpers = ${timelineHelpersSource()};
|
|
158
|
+
__swoof_swflib.createTimelineEngine = ${timelineEngineFactorySource()};
|
|
159
|
+
const factory = ${factory};
|
|
160
|
+
__swoof_swflib.registerCompiledSwf('RldTCggAAAA=', 8, 10,
|
|
161
|
+
environment => factory(environment, () => Promise.resolve(), () => null));
|
|
162
|
+
__swoof_swflib;
|
|
163
|
+
`, sandbox);
|
|
164
|
+
const { stage, builtins: { ByteArray, DisplayObject, Loader, Multitouch, SimpleButton, Sprite } } = runtime;
|
|
165
|
+
const wrapper = stage.addChild(new Sprite());
|
|
166
|
+
wrapper.x = 70;
|
|
167
|
+
wrapper.y = 60;
|
|
168
|
+
wrapper.rotation = 90;
|
|
169
|
+
const loader = wrapper.addChild(new Loader());
|
|
170
|
+
loader.scaleX = 2;
|
|
171
|
+
const completed = new Promise((resolve, reject) => {
|
|
172
|
+
loader.contentLoaderInfo.addEventListener('complete', resolve);
|
|
173
|
+
loader.contentLoaderInfo.addEventListener('ioError', event => reject(new Error(event.text)));
|
|
174
|
+
});
|
|
175
|
+
const bytes = new ByteArray();
|
|
176
|
+
for (const byte of [0x46, 0x57, 0x53, 10, 8, 0, 0, 0]) bytes.writeByte(byte);
|
|
177
|
+
loader.loadBytes(bytes);
|
|
178
|
+
await completed;
|
|
179
|
+
const main = loader.content, inner = main.outer.inner;
|
|
180
|
+
const wheelEvents = [];
|
|
181
|
+
const recordWheel = event => wheelEvents.push(event);
|
|
182
|
+
inner.addEventListener('mouseWheel', recordWheel);
|
|
183
|
+
main._swoofTimeline.render();
|
|
184
|
+
expect(runtime.canvasProgrammaticPointerAt(58, 98)).toBeNull();
|
|
185
|
+
for (const listener of canvasHandlers.wheel || []) {
|
|
186
|
+
listener({ clientX: 58, clientY: 98, deltaMode: 1, deltaY: 2, preventDefault() {} });
|
|
187
|
+
}
|
|
188
|
+
expect(wheelEvents).toHaveLength(1);
|
|
189
|
+
expect(wheelEvents[0]).toMatchObject({ target: inner, stageX: 58, stageY: 98, delta: -2 });
|
|
190
|
+
expect(wheelEvents[0].localX).toBeCloseTo(4);
|
|
191
|
+
expect(wheelEvents[0].localY).toBeCloseTo(2);
|
|
192
|
+
inner.removeEventListener('mouseWheel', recordWheel);
|
|
193
|
+
inner.buttonMode = true;
|
|
194
|
+
stage.frameRate = 24;
|
|
195
|
+
runtime.pulseFrameEvents();
|
|
196
|
+
const attachedTick = main._swoofTimeline._ticks;
|
|
197
|
+
expect(attachedTick).toBe(1);
|
|
198
|
+
wrapper.removeChild(loader);
|
|
199
|
+
runtime.pulseFrameEvents();
|
|
200
|
+
expect(main._swoofTimeline._ticks).toBe(attachedTick);
|
|
201
|
+
wrapper.addChild(loader);
|
|
202
|
+
runtime.pulseFrameEvents();
|
|
203
|
+
expect(main._swoofTimeline._ticks).toBe(attachedTick + 1);
|
|
204
|
+
const events = [];
|
|
205
|
+
for (const type of ['mouseDown', 'mouseUp', 'click', 'releaseOutside', 'touchBegin', 'touchMove', 'touchEnd']) {
|
|
206
|
+
inner.addEventListener(type, event => events.push(event));
|
|
207
|
+
}
|
|
208
|
+
main._swoofTimeline.render();
|
|
209
|
+
function pointer(type, x, y, pointerId, pointerType = 'mouse', timeStamp) {
|
|
210
|
+
const event = { clientX: x, clientY: y, pointerId, pointerType,
|
|
211
|
+
timeStamp, isPrimary: true, button: 0, buttons: type === 'pointerup' ? 0 : 1, preventDefault() {} };
|
|
212
|
+
for (const listener of (type === 'pointerup' ? windowHandlers : canvasHandlers)[type] || []) listener(event);
|
|
213
|
+
}
|
|
214
|
+
// Child point (19,12), transformed once by the scaled Loader and rotated wrapper.
|
|
215
|
+
pointer('pointerdown', 58, 98, 1);
|
|
216
|
+
pointer('pointerup', 58, 98, 1);
|
|
217
|
+
expect(events.map(event => event.type)).toEqual(['mouseDown', 'mouseUp', 'click']);
|
|
218
|
+
expect(events[0].localX).toBeCloseTo(4);
|
|
219
|
+
expect(events[0].localY).toBeCloseTo(2);
|
|
220
|
+
expect(events[0].stageX).toBe(58);
|
|
221
|
+
expect(stage.focus).toBe(inner);
|
|
222
|
+
|
|
223
|
+
const scripted = new SimpleButton();
|
|
224
|
+
scripted.x = inner.x;
|
|
225
|
+
scripted.y = inner.y;
|
|
226
|
+
scripted.width = scripted.height = 10;
|
|
227
|
+
main.outer.addChildAt(scripted, 0);
|
|
228
|
+
main._swoofTimeline.render();
|
|
229
|
+
expect(runtime.canvasProgrammaticPointerAt(58, 98)).toBe(inner);
|
|
230
|
+
main.outer.setChildIndex(scripted, 1);
|
|
231
|
+
main._swoofTimeline.render();
|
|
232
|
+
expect(runtime.canvasProgrammaticPointerAt(58, 98)).toBe(scripted);
|
|
233
|
+
main.outer.removeChild(scripted);
|
|
234
|
+
main._swoofTimeline.render();
|
|
235
|
+
|
|
236
|
+
const mask = wrapper.addChild(new DisplayObject());
|
|
237
|
+
mask.x = 36;
|
|
238
|
+
mask.y = 10;
|
|
239
|
+
mask.width = mask.height = 4;
|
|
240
|
+
inner.mask = mask;
|
|
241
|
+
events.length = 0;
|
|
242
|
+
pointer('pointerdown', 57, 104, 1);
|
|
243
|
+
pointer('pointerup', 57, 104, 1);
|
|
244
|
+
expect(events).toEqual([]);
|
|
245
|
+
pointer('pointerdown', 58, 98, 1);
|
|
246
|
+
pointer('pointerup', 58, 98, 1);
|
|
247
|
+
expect(events.map(event => event.type)).toEqual(['mouseDown', 'mouseUp', 'click']);
|
|
248
|
+
inner.mask = null;
|
|
249
|
+
|
|
250
|
+
events.length = 0;
|
|
251
|
+
pointer('pointerdown', 58, 98, 2);
|
|
252
|
+
pointer('pointerup', 180, 140, 2);
|
|
253
|
+
expect(events.map(event => event.type)).toEqual(['mouseDown', 'releaseOutside']);
|
|
254
|
+
|
|
255
|
+
const gestures = [];
|
|
256
|
+
inner.addEventListener('gestureZoom', event => gestures.push(event));
|
|
257
|
+
Multitouch.mapTouchToMouse = false;
|
|
258
|
+
const swipes = [];
|
|
259
|
+
inner.addEventListener('gestureSwipe', event => swipes.push(event));
|
|
260
|
+
pointer('pointerdown', 58, 98, 18, 'touch', 1000);
|
|
261
|
+
pointer('pointerup', 115, 98, 18, 'touch', 1100);
|
|
262
|
+
expect(swipes).toHaveLength(1);
|
|
263
|
+
expect(swipes[0]).toMatchObject({ phase: 'all', target: inner, offsetX: 1, offsetY: 0, stageX: 115 });
|
|
264
|
+
const twoFingerTaps = [];
|
|
265
|
+
inner.addEventListener('gestureTwoFingerTap', event => twoFingerTaps.push(event));
|
|
266
|
+
pointer('pointerdown', 58, 98, 19, 'touch');
|
|
267
|
+
pointer('pointerdown', 58, 100, 20, 'touch');
|
|
268
|
+
pointer('pointerup', 58, 100, 20, 'touch');
|
|
269
|
+
pointer('pointerup', 58, 98, 19, 'touch');
|
|
270
|
+
expect(twoFingerTaps).toHaveLength(1);
|
|
271
|
+
expect(twoFingerTaps[0]).toMatchObject({ phase: 'all', target: inner, stageY: 99 });
|
|
272
|
+
expect(twoFingerTaps[0].localX).toBeCloseTo(4.5);
|
|
273
|
+
pointer('pointerdown', 58, 98, 21, 'touch');
|
|
274
|
+
pointer('pointerdown', 58, 100, 22, 'touch');
|
|
275
|
+
pointer('pointermove', 58, 104, 22, 'touch');
|
|
276
|
+
expect(gestures.map(event => [event.phase, event.scaleX])).toEqual([['begin', 3]]);
|
|
277
|
+
expect(gestures[0].target).toBe(inner);
|
|
278
|
+
expect(gestures[0].localX).toBeCloseTo(5.5);
|
|
279
|
+
Multitouch.inputMode = 'touchPoint';
|
|
280
|
+
expect(gestures.map(event => event.phase)).toEqual(['begin', 'end']);
|
|
281
|
+
pointer('pointerup', 58, 98, 21, 'touch');
|
|
282
|
+
pointer('pointerup', 58, 104, 22, 'touch');
|
|
283
|
+
|
|
284
|
+
const taps = [];
|
|
285
|
+
inner.addEventListener('touchTap', event => taps.push(event));
|
|
286
|
+
pointer('pointerdown', 58, 98, 23, 'touch');
|
|
287
|
+
pointer('pointerup', 58, 98, 23, 'touch');
|
|
288
|
+
expect(taps).toHaveLength(1);
|
|
289
|
+
expect(taps[0].target).toBe(inner);
|
|
290
|
+
expect(taps[0].localX).toBeCloseTo(4);
|
|
291
|
+
|
|
292
|
+
events.length = 0;
|
|
293
|
+
stage.focus = null;
|
|
294
|
+
pointer('pointerdown', 58, 98, 3, 'touch');
|
|
295
|
+
pointer('pointermove', 57, 100, 3, 'touch');
|
|
296
|
+
expect(events.map(event => event.type)).toEqual(['touchBegin', 'touchMove']);
|
|
297
|
+
expect(events[1].localX).toBeCloseTo(5);
|
|
298
|
+
expect(events[1].localY).toBeCloseTo(3);
|
|
299
|
+
expect(stage.focus).toBeNull();
|
|
300
|
+
|
|
301
|
+
const unrelatedEnds = [];
|
|
302
|
+
stage.addEventListener('touchEnd', event => {
|
|
303
|
+
if (event.touchPointID === 5) unrelatedEnds.push(event.isTouchPointCanceled);
|
|
304
|
+
});
|
|
305
|
+
pointer('pointerdown', 180, 140, 5, 'touch');
|
|
306
|
+
inner.startTouchDrag(5);
|
|
307
|
+
const dragX = inner.x;
|
|
308
|
+
pointer('pointerdown', 58, 98, 4);
|
|
309
|
+
loader.unload();
|
|
310
|
+
expect(events.map(event => event.type)).toEqual(['touchBegin', 'touchMove', 'mouseDown', 'mouseUp', 'touchEnd']);
|
|
311
|
+
expect(events[4]).toMatchObject({ touchPointID: 3, isTouchPointCanceled: true });
|
|
312
|
+
expect(releasedIds).toEqual([4, 3]);
|
|
313
|
+
expect(stage.focus).toBeNull();
|
|
314
|
+
expect(unrelatedEnds).toEqual([]);
|
|
315
|
+
pointer('pointerup', 58, 98, 3, 'touch');
|
|
316
|
+
pointer('pointerup', 58, 98, 4);
|
|
317
|
+
pointer('pointermove', 190, 140, 5, 'touch');
|
|
318
|
+
pointer('pointerup', 180, 140, 5, 'touch');
|
|
319
|
+
expect(inner.x).toBe(dragX);
|
|
320
|
+
expect(events).toHaveLength(5);
|
|
321
|
+
expect(taps).toHaveLength(1);
|
|
322
|
+
expect(unrelatedEnds).toEqual([false]);
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
function mountEmbeddedAvm1Host() {
|
|
327
|
+
const canvasListeners = {};
|
|
328
|
+
const windowListeners = {};
|
|
329
|
+
const focuses = [];
|
|
330
|
+
const stageCanvas = {
|
|
331
|
+
width: 200, height: 100, style: {}, tabIndex: -1,
|
|
332
|
+
getBoundingClientRect: () => ({ left: 0, top: 0, width: 200, height: 100 }),
|
|
333
|
+
addEventListener: (type, listener) => { (canvasListeners[type] ||= []).push(listener); },
|
|
334
|
+
setPointerCapture() {},
|
|
335
|
+
focus(options) { focuses.push(options || true); },
|
|
336
|
+
};
|
|
337
|
+
const movieCanvas = { width: 80, height: 40, style: {} };
|
|
338
|
+
const calls = [];
|
|
339
|
+
movieCanvas._swoofAvm1Embed = {
|
|
340
|
+
move: (x, y) => calls.push(['move', x, y]),
|
|
341
|
+
down: (x, y) => calls.push(['down', x, y]),
|
|
342
|
+
up: (x, y, _event, cancelled) => calls.push(['up', x, y, !!cancelled]),
|
|
343
|
+
wheel: (x, y, delta) => calls.push(['wheel', x, y, delta]),
|
|
344
|
+
keyDown: event => calls.push(['keyDown', event.key]),
|
|
345
|
+
keyUp: event => calls.push(['keyUp', event.key]),
|
|
346
|
+
};
|
|
347
|
+
const sandbox = {
|
|
348
|
+
PointerEvent: class {},
|
|
349
|
+
KeyboardEvent: class {},
|
|
350
|
+
document: {
|
|
351
|
+
readyState: 'complete',
|
|
352
|
+
activeElement: null,
|
|
353
|
+
getElementById: id => id === 'stage' ? stageCanvas : null,
|
|
354
|
+
createElement: () => ({ getContext: () => null }),
|
|
355
|
+
},
|
|
356
|
+
addEventListener: (type, listener) => { (windowListeners[type] ||= []).push(listener); },
|
|
357
|
+
};
|
|
358
|
+
sandbox.window = sandbox;
|
|
359
|
+
const { stage, MovieClip } = runInNewContext(`
|
|
360
|
+
${SWFLIB_SOURCE}
|
|
361
|
+
({ stage: __swoof_swflib.stage, MovieClip });
|
|
362
|
+
`, sandbox);
|
|
363
|
+
const clip = stage.addChild(new MovieClip());
|
|
364
|
+
clip.x = 30;
|
|
365
|
+
clip.y = 10;
|
|
366
|
+
clip._swoofTimelineCanvas = movieCanvas;
|
|
367
|
+
const pointer = (type, x, y, extra) => {
|
|
368
|
+
const handlers = type === 'pointerup' || type === 'pointercancel' ? windowListeners : canvasListeners;
|
|
369
|
+
handlers[type][0]({
|
|
370
|
+
clientX: x, clientY: y, button: 0, buttons: type === 'pointerdown' ? 1 : 0,
|
|
371
|
+
pointerId: 1, pointerType: 'mouse', isPrimary: true, preventDefault() {}, ...extra,
|
|
372
|
+
});
|
|
373
|
+
};
|
|
374
|
+
const key = (type, keyName) => windowListeners[type][0]({
|
|
375
|
+
key: keyName, code: 'KeyA', keyCode: 65, location: 0, preventDefault() {},
|
|
376
|
+
});
|
|
377
|
+
return { stage, clip, movieCanvas, calls, focuses, stageCanvas, pointer, key, canvasListeners };
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
it('forwards a host pointer and later keys into an embedded AVM1 movie', () => {
|
|
381
|
+
const { calls, focuses, pointer, key, canvasListeners } = mountEmbeddedAvm1Host();
|
|
382
|
+
pointer('pointerdown', 40, 20);
|
|
383
|
+
expect(focuses.length).toBeGreaterThan(0);
|
|
384
|
+
pointer('pointermove', 45, 22);
|
|
385
|
+
pointer('pointerup', 45, 22);
|
|
386
|
+
canvasListeners.wheel[0]({ clientX: 40, clientY: 20, deltaMode: 1, deltaY: -2, preventDefault() {} });
|
|
387
|
+
key('keydown', 'a');
|
|
388
|
+
key('keyup', 'a');
|
|
389
|
+
expect(calls).toEqual([
|
|
390
|
+
['down', 10, 10],
|
|
391
|
+
['move', 15, 12],
|
|
392
|
+
['up', 15, 12, false],
|
|
393
|
+
['wheel', 10, 10, 2],
|
|
394
|
+
['keyDown', 'a'],
|
|
395
|
+
['keyUp', 'a'],
|
|
396
|
+
]);
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it('routes Space into the sole embedded AVM1 movie before any pointer hit', () => {
|
|
400
|
+
const { calls, key } = mountEmbeddedAvm1Host();
|
|
401
|
+
key('keydown', ' ');
|
|
402
|
+
key('keyup', ' ');
|
|
403
|
+
expect(calls).toEqual([
|
|
404
|
+
['keyDown', ' '],
|
|
405
|
+
['keyUp', ' '],
|
|
406
|
+
]);
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
it('keeps forwarding embedded AVM1 move and up after the pointer leaves the child canvas', () => {
|
|
410
|
+
const { calls, pointer } = mountEmbeddedAvm1Host();
|
|
411
|
+
pointer('pointerdown', 40, 20);
|
|
412
|
+
// Stage point (5, 5) is outside the child canvas at (30,10)-(110,50).
|
|
413
|
+
pointer('pointermove', 5, 5);
|
|
414
|
+
pointer('pointerup', 5, 5);
|
|
415
|
+
expect(calls).toEqual([
|
|
416
|
+
['down', 10, 10],
|
|
417
|
+
['move', -25, -5],
|
|
418
|
+
['up', -25, -5, false],
|
|
419
|
+
]);
|
|
420
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { mkdtempSync, readFileSync, rmSync } 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 { SymbolTable } from '../decoder/symbol-table.js';
|
|
7
|
+
import { emit } from '../emitter/bundle-emitter.js';
|
|
8
|
+
import { transpileActionScript } from '../transpiler/actionscript.js';
|
|
9
|
+
import { DiagnosticsCollector } from '../util/diagnostics.js';
|
|
10
|
+
|
|
11
|
+
function timerAbc() {
|
|
12
|
+
const bytes = [16, 0, 46, 0];
|
|
13
|
+
const u = (...values) => bytes.push(...values);
|
|
14
|
+
const str = (value) => { const chars = [...Buffer.from(value)]; u(chars.length, ...chars); };
|
|
15
|
+
u(0, 0, 0);
|
|
16
|
+
const names = ['flash.utils', '', 'Timer', 'start', 'recordTimer', 'setTimeout', 'setInterval', 'timerCallback'];
|
|
17
|
+
u(names.length + 1); names.forEach(str);
|
|
18
|
+
u(3, 0x16, 1, 0x16, 2, 0);
|
|
19
|
+
const qualified = [[1, 3], [2, 4], [2, 5], [1, 6], [1, 7], [2, 8]];
|
|
20
|
+
u(qualified.length + 1);
|
|
21
|
+
for (const [namespace, name] of qualified) u(7, namespace, name);
|
|
22
|
+
u(1, 0, 0, 0, 0); // one parameterless script initializer
|
|
23
|
+
u(0, 0, 1, 0, 0); // no metadata/classes, one script, no traits
|
|
24
|
+
const code = [
|
|
25
|
+
0x60, 1, 0x24, 10, 0x24, 0, 0x42, 2, 0xd5, // new Timer(10, 0) → local 1
|
|
26
|
+
0xd1, 0x4f, 2, 0, // timer.start()
|
|
27
|
+
0x5d, 3, 0xd1, 0x4f, 3, 1, // recordTimer(timer)
|
|
28
|
+
0x5d, 4, 0x60, 6, 0x24, 30, 0x24, 1, 0x4f, 4, 3, // setTimeout(timerCallback, 30, 1)
|
|
29
|
+
0x5d, 5, 0x60, 6, 0x24, 20, 0x24, 2, 0x4f, 5, 3, // setInterval(timerCallback, 20, 2)
|
|
30
|
+
0x47,
|
|
31
|
+
];
|
|
32
|
+
u(1, 0, 5, 2, 0, 1, code.length, ...code, 0, 0);
|
|
33
|
+
return Uint8Array.from(bytes);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe('Loader.unloadAndStop timer ownership', () => {
|
|
37
|
+
it('cancels a compiled child and nested movie while an ordinary unload and sibling remain live', async () => {
|
|
38
|
+
const output = mkdtempSync(join(tmpdir(), 'swoof-child-timers-'));
|
|
39
|
+
try {
|
|
40
|
+
const diagnostics = new DiagnosticsCollector();
|
|
41
|
+
const header = { version: 10, frameSize: { xMin: 0, xMax: 200, yMin: 0, yMax: 200 }, frameRate: 24, frameCount: 1 };
|
|
42
|
+
const bytes = Uint8Array.of(70, 87, 83, 10, 8, 0, 0, 0);
|
|
43
|
+
const show = { type: 'ShowFrame' };
|
|
44
|
+
const tags = [{ type: 'DoABC', abcData: timerAbc() }, show];
|
|
45
|
+
const actionScript = transpileActionScript(tags, diagnostics, { sharedAvm2Runtime: true });
|
|
46
|
+
expect(actionScript.avm2Blocks).toHaveLength(1);
|
|
47
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
48
|
+
const bundle = emit({
|
|
49
|
+
header, tags: [show], symbolTable: new SymbolTable(), actionScript: { fullJs: '' },
|
|
50
|
+
embeddedSwfs: [{ characterId: 42, bytes, header, tags, symbolTable: new SymbolTable(), actionScript, embeddedSwfs: [] }],
|
|
51
|
+
}, 'timers.swf', output, diagnostics, { externalTimelineData: true });
|
|
52
|
+
|
|
53
|
+
const tasks = new Map(), timers = [], callbacks = [];
|
|
54
|
+
let nextId = 0;
|
|
55
|
+
function register(repeat, callback, delay) {
|
|
56
|
+
const id = ++nextId;
|
|
57
|
+
tasks.set(id, { repeat, callback, delay });
|
|
58
|
+
return id;
|
|
59
|
+
}
|
|
60
|
+
let context;
|
|
61
|
+
const sandbox = {
|
|
62
|
+
atob, requestAnimationFrame: () => 1,
|
|
63
|
+
setInterval: (fn, delay) => register(true, fn, delay),
|
|
64
|
+
setTimeout: (fn, delay) => register(false, fn, delay),
|
|
65
|
+
clearInterval: id => tasks.delete(id), clearTimeout: id => tasks.delete(id),
|
|
66
|
+
recordTimer: timer => timers.push(timer), timerCallback: value => callbacks.push(value),
|
|
67
|
+
document: {
|
|
68
|
+
readyState: 'complete', getElementById: () => null,
|
|
69
|
+
createElement: tag => tag === 'script' ? { remove() {} } : { getContext: () => null },
|
|
70
|
+
head: { appendChild(script) {
|
|
71
|
+
sandbox.document.currentScript = script;
|
|
72
|
+
runInContext(readFileSync(join(bundle.bundleDir, script.src), 'utf8'), context);
|
|
73
|
+
sandbox.document.currentScript = null;
|
|
74
|
+
script.onload();
|
|
75
|
+
} },
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
sandbox.window = sandbox;
|
|
79
|
+
context = createContext(sandbox);
|
|
80
|
+
for (const path of [bundle.swflibPath, bundle.movieDataPath, bundle.binaryDataPath, bundle.jsPath]) {
|
|
81
|
+
runInContext(readFileSync(path, 'utf8'), context);
|
|
82
|
+
}
|
|
83
|
+
const { builtins, packages } = sandbox.__swoof_swflib;
|
|
84
|
+
const parent = new builtins.Timer(40);
|
|
85
|
+
parent.start();
|
|
86
|
+
const parentInterval = packages.utils.setInterval(() => callbacks.push(9), 50);
|
|
87
|
+
const file = runInContext('Uint8Array.of(' + bytes.join(',') + ')', context);
|
|
88
|
+
async function load(loader) {
|
|
89
|
+
const prior = new Set(tasks.keys());
|
|
90
|
+
await new Promise((resolve, reject) => {
|
|
91
|
+
loader.contentLoaderInfo.addEventListener('complete', resolve);
|
|
92
|
+
loader.contentLoaderInfo.addEventListener('ioError', event => reject(new Error(event.text)));
|
|
93
|
+
loader.loadBytes(file);
|
|
94
|
+
});
|
|
95
|
+
const owned = [...tasks].filter(([id, task]) => !prior.has(id) && [10, 20, 30].includes(task.delay));
|
|
96
|
+
expect(owned.map(([, task]) => task.delay)).toEqual([10, 30, 20]);
|
|
97
|
+
return owned;
|
|
98
|
+
}
|
|
99
|
+
const outer = new builtins.Loader(), nested = new builtins.Loader(), sibling = new builtins.Loader();
|
|
100
|
+
const firstTasks = await load(outer);
|
|
101
|
+
outer.content.addChild(nested);
|
|
102
|
+
const nestedTasks = await load(nested);
|
|
103
|
+
const siblingTasks = await load(sibling);
|
|
104
|
+
for (const [, task] of [...firstTasks, ...nestedTasks, ...siblingTasks]) {
|
|
105
|
+
if (task.repeat) task.callback();
|
|
106
|
+
}
|
|
107
|
+
expect(timers.map(timer => timer.currentCount)).toEqual([1, 1, 1]);
|
|
108
|
+
expect(callbacks.splice(0)).toEqual([2, 2, 2]);
|
|
109
|
+
|
|
110
|
+
outer.unloadAndStop();
|
|
111
|
+
expect(timers.map(timer => timer.running)).toEqual([false, false, true]);
|
|
112
|
+
const canceled = [...firstTasks, ...nestedTasks];
|
|
113
|
+
expect(canceled.every(([id]) => !tasks.has(id))).toBe(true);
|
|
114
|
+
for (const [, task] of canceled) task.callback();
|
|
115
|
+
expect(callbacks).toEqual([]);
|
|
116
|
+
expect(timers[0].currentCount).toBe(1);
|
|
117
|
+
expect(parent.running).toBe(true);
|
|
118
|
+
|
|
119
|
+
sibling.unload();
|
|
120
|
+
for (const [id, task] of siblingTasks) {
|
|
121
|
+
expect(tasks.has(id)).toBe(true);
|
|
122
|
+
task.callback();
|
|
123
|
+
}
|
|
124
|
+
expect(timers[2].running).toBe(true);
|
|
125
|
+
expect(timers[2].currentCount).toBe(2);
|
|
126
|
+
expect(callbacks.splice(0)).toEqual([1, 2]);
|
|
127
|
+
|
|
128
|
+
const reloadedTasks = await load(outer);
|
|
129
|
+
expect(timers[3].running).toBe(true);
|
|
130
|
+
expect(reloadedTasks.every(([id]) => tasks.has(id))).toBe(true);
|
|
131
|
+
let timerComplete = 0;
|
|
132
|
+
timers[3].repeatCount = 1;
|
|
133
|
+
timers[3].addEventListener('timerComplete', () => timerComplete++);
|
|
134
|
+
timers[3].addEventListener('timer', () => outer.unloadAndStop());
|
|
135
|
+
reloadedTasks.find(([, task]) => task.delay === 10)[1].callback();
|
|
136
|
+
expect(timerComplete).toBe(0);
|
|
137
|
+
expect(timers[3].running).toBe(false);
|
|
138
|
+
expect(reloadedTasks.every(([id]) => !tasks.has(id))).toBe(true);
|
|
139
|
+
packages.utils.clearInterval(parentInterval);
|
|
140
|
+
parent.stop();
|
|
141
|
+
} finally {
|
|
142
|
+
rmSync(output, { recursive: true, force: true });
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|