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,825 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { runInNewContext } from 'node:vm';
|
|
4
|
+
import * as acorn from 'acorn';
|
|
5
|
+
import { hitTestButtonGeometry, hitTestButtonRecords, dispatchAs3ClickToClip, resolveButtonRelease, buttonStateKey, generateTimelineEngine, timelineEngineFactorySource, timelineHelpersSource } from '../transpiler/timeline/timeline-codegen.js';
|
|
6
|
+
import { buildDisplayList } from '../transpiler/timeline/display-list.js';
|
|
7
|
+
import { transpileActionScript } from '../transpiler/actionscript.js';
|
|
8
|
+
import { parse } from '../parser/swf-parser.js';
|
|
9
|
+
import { decode } from '../decoder/tag-decoder.js';
|
|
10
|
+
import { SymbolTable } from '../decoder/symbol-table.js';
|
|
11
|
+
import { DiagnosticsCollector } from '../util/diagnostics.js';
|
|
12
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
13
|
+
|
|
14
|
+
function triangle() {
|
|
15
|
+
return {
|
|
16
|
+
type: 'shape',
|
|
17
|
+
bounds: { x: 0, y: 0, w: 10, h: 10 },
|
|
18
|
+
draws: [{
|
|
19
|
+
fill: { type: 'solid', color: '#fff' },
|
|
20
|
+
path: [['M', 0, 0], ['L', 10, 0], ['L', 0, 10], ['Z']],
|
|
21
|
+
}],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe('DefineButton2 hit-state geometry', () => {
|
|
26
|
+
it('rejects points inside the character bounds but outside the hit shape', () => {
|
|
27
|
+
const characters = { 1: triangle() };
|
|
28
|
+
expect(hitTestButtonGeometry(characters, 1, null, 2, 2)).toBe(true);
|
|
29
|
+
expect(hitTestButtonGeometry(characters, 1, null, 8, 8)).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('flattens sharply curved strokes adaptively instead of relying on a coarse fixed sample', () => {
|
|
33
|
+
const characters = {
|
|
34
|
+
1: {
|
|
35
|
+
type: 'shape',
|
|
36
|
+
bounds: { x: 0, y: 0, w: 10000, h: 5000 },
|
|
37
|
+
draws: [{ stroke: { width: 0.2 }, path: [['M', 0, 0], ['Q', 5000, 10000, 10000, 0]] }],
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
const t = 0.02, u = 1 - t;
|
|
41
|
+
const x = 2 * u * t * 5000 + t * t * 10000;
|
|
42
|
+
const y = 2 * u * t * 10000;
|
|
43
|
+
const tangentLength = Math.hypot(10000, 19200);
|
|
44
|
+
const outsideX = x - 19200 / tangentLength;
|
|
45
|
+
const outsideY = y + 10000 / tangentLength;
|
|
46
|
+
|
|
47
|
+
expect(hitTestButtonGeometry(characters, 1, null, x, y)).toBe(true);
|
|
48
|
+
expect(hitTestButtonGeometry(characters, 1, null, outsideX, outsideY)).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('matches round, butt, and square line caps at both stroke endpoints', () => {
|
|
52
|
+
const line = (startCap, endCap) => ({
|
|
53
|
+
type: 'shape', bounds: { x: 0, y: -2, w: 12, h: 4 },
|
|
54
|
+
draws: [{ stroke: { width: 2, startCap, endCap }, path: [['M', 0, 0], ['L', 10, 0]] }],
|
|
55
|
+
});
|
|
56
|
+
expect(hitTestButtonGeometry({ 1: line(0, 0) }, 1, null, -0.5, 0)).toBe(true);
|
|
57
|
+
expect(hitTestButtonGeometry({ 1: line(1, 1) }, 1, null, -0.5, 0)).toBe(false);
|
|
58
|
+
expect(hitTestButtonGeometry({ 1: line(2, 2) }, 1, null, -0.9, 0)).toBe(true);
|
|
59
|
+
expect(hitTestButtonGeometry({ 1: line(2, 2) }, 1, null, -1.1, 0)).toBe(false);
|
|
60
|
+
expect(hitTestButtonGeometry({ 1: line(1, 1) }, 1, null, 10.5, 0)).toBe(false);
|
|
61
|
+
expect(hitTestButtonGeometry({ 1: line(0, 0) }, 1, null, 10.5, 0)).toBe(true);
|
|
62
|
+
expect(hitTestButtonGeometry({ 1: line(2, 2) }, 1, null, 10.9, 0)).toBe(true);
|
|
63
|
+
expect(hitTestButtonGeometry({ 1: line(2, 2) }, 1, null, 11.1, 0)).toBe(false);
|
|
64
|
+
expect(hitTestButtonGeometry({ 1: line(0, 1) }, 1, null, -0.5, 0)).toBe(true);
|
|
65
|
+
expect(hitTestButtonGeometry({ 1: line(0, 1) }, 1, null, 10.5, 0)).toBe(false);
|
|
66
|
+
expect(hitTestButtonGeometry({ 1: line(1, 2) }, 1, null, -0.5, 0)).toBe(false);
|
|
67
|
+
expect(hitTestButtonGeometry({ 1: line(1, 2) }, 1, null, 10.5, 0.9)).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('uses round, bevel, and miter geometry at joins and honors the miter limit', () => {
|
|
71
|
+
const corner = (joinStyle, miterLimit = 10) => ({
|
|
72
|
+
type: 'shape', bounds: { x: 0, y: -2, w: 13, h: 13 },
|
|
73
|
+
draws: [{ stroke: { width: 2, startCap: 1, endCap: 1, joinStyle, miterLimit },
|
|
74
|
+
path: [['M', 0, 0], ['L', 10, 0], ['L', 10, 10]] }],
|
|
75
|
+
});
|
|
76
|
+
expect(hitTestButtonGeometry({ 1: corner(0) }, 1, null, 10.7, -0.7)).toBe(true);
|
|
77
|
+
expect(hitTestButtonGeometry({ 1: corner(1) }, 1, null, 10.8, -0.8)).toBe(false);
|
|
78
|
+
expect(hitTestButtonGeometry({ 1: corner(2, 10) }, 1, null, 10.8, -0.8)).toBe(true);
|
|
79
|
+
expect(hitTestButtonGeometry({ 1: corner(2, 1) }, 1, null, 10.8, -0.8)).toBe(false);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('applies the full state transform before testing shape geometry', () => {
|
|
83
|
+
const characters = { 1: triangle() };
|
|
84
|
+
// 90° rotation and 10px/20px translation (matrix translations are twips).
|
|
85
|
+
const matrix = { a: 0, b: 1, c: -1, d: 0, tx: 200, ty: 400 };
|
|
86
|
+
expect(hitTestButtonGeometry(characters, 1, matrix, 8, 22)).toBe(true);
|
|
87
|
+
expect(hitTestButtonGeometry(characters, 1, matrix, 1, 22)).toBe(false);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('recurses into the current hit-state sprite frame', () => {
|
|
91
|
+
const characters = {
|
|
92
|
+
1: triangle(),
|
|
93
|
+
2: {
|
|
94
|
+
type: 'sprite',
|
|
95
|
+
frames: [{ frameIndex: 0, places: [{ depth: 1, characterId: 1, matrix: { a: 1, b: 0, c: 0, d: 1, tx: 100, ty: 0 } }], removes: [] }],
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
expect(hitTestButtonGeometry(characters, 2, null, 7, 2)).toBe(true);
|
|
99
|
+
expect(hitTestButtonGeometry(characters, 2, null, 18, 8)).toBe(false);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('unions geometry from multiple hit-state records', () => {
|
|
103
|
+
const characters = { 1: triangle(), 2: triangle() };
|
|
104
|
+
const records = [
|
|
105
|
+
{ characterId: 1, matrix: { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 } },
|
|
106
|
+
{ characterId: 2, matrix: { a: 1, b: 0, c: 0, d: 1, tx: 200, ty: 0 } },
|
|
107
|
+
];
|
|
108
|
+
expect(hitTestButtonRecords(characters, records, null, 2, 2)).toBe(true);
|
|
109
|
+
expect(hitTestButtonRecords(characters, records, null, 12, 2)).toBe(true);
|
|
110
|
+
expect(hitTestButtonRecords(characters, records, null, 18, 8)).toBe(false);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('dispatches bubbling AS3 CLICK with local and stage coordinates', () => {
|
|
114
|
+
const runtime = new Function(`${SWFLIB_SOURCE}\nreturn __swoof_swflib;`)();
|
|
115
|
+
const { Sprite, MouseEvent } = runtime.builtins;
|
|
116
|
+
const clip = new Sprite();
|
|
117
|
+
let received = null;
|
|
118
|
+
clip.addEventListener(MouseEvent.CLICK, (event) => { received = event; });
|
|
119
|
+
const matrix = { a: 0, b: 1, c: -1, d: 0, tx: 200, ty: 400 };
|
|
120
|
+
|
|
121
|
+
expect(dispatchAs3ClickToClip(clip, MouseEvent, matrix, { x: 8, y: 22 })).toBe(true);
|
|
122
|
+
expect(received).toMatchObject({
|
|
123
|
+
type: MouseEvent.CLICK, target: clip, stageX: 8, stageY: 22, localX: 2, localY: 2,
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it.each([[false, 100], [true, 100], [true, 200]])(
|
|
128
|
+
'routes nested authored MovieClip and DefineButton events with shared factory %s and backing size %i', (sharedFactory, backingSize) => {
|
|
129
|
+
const canvasHandlers = {}, windowHandlers = {};
|
|
130
|
+
const canvas = {
|
|
131
|
+
width: backingSize, height: backingSize, style: {},
|
|
132
|
+
addEventListener(type, listener) { (canvasHandlers[type] ||= []).push(listener); },
|
|
133
|
+
getBoundingClientRect() { return { left: 10, top: 20, width: 200, height: 200 }; },
|
|
134
|
+
setPointerCapture() {},
|
|
135
|
+
};
|
|
136
|
+
const ctx = {
|
|
137
|
+
canvas, setTransform() {}, fillRect() {}, fillText() {}, clearRect() {}, drawImage() {},
|
|
138
|
+
save() {}, restore() {}, translate() {}, rotate() {}, scale() {}, transform() {}, fill() {},
|
|
139
|
+
};
|
|
140
|
+
const sandbox = {
|
|
141
|
+
ctx, STAGE_WIDTH: 100, STAGE_HEIGHT: 100, FRAME_RATE: 30, BACKGROUND: '#000',
|
|
142
|
+
ASSETS: [], SYMBOL_CLASSES: [], loaded: [],
|
|
143
|
+
Path2D: class { moveTo() {} lineTo() {} closePath() {} },
|
|
144
|
+
requestAnimationFrame: () => 1,
|
|
145
|
+
};
|
|
146
|
+
sandbox.window = sandbox;
|
|
147
|
+
sandbox.PointerEvent = function () {};
|
|
148
|
+
sandbox.document = {
|
|
149
|
+
getElementById: (id) => id === 'stage' ? canvas : null,
|
|
150
|
+
createElement: () => ({ getContext: () => null }),
|
|
151
|
+
};
|
|
152
|
+
sandbox.addEventListener = (type, listener) => { (windowHandlers[type] ||= []).push(listener); };
|
|
153
|
+
runInNewContext(SWFLIB_SOURCE, sandbox);
|
|
154
|
+
if (sharedFactory) {
|
|
155
|
+
runInNewContext(`
|
|
156
|
+
__swoof_swflib.timelineHelpers = ${timelineHelpersSource()};
|
|
157
|
+
__swoof_swflib.createTimelineEngine = ${timelineEngineFactorySource()};
|
|
158
|
+
`, sandbox);
|
|
159
|
+
}
|
|
160
|
+
const { stage, builtins: { MovieClip, MouseEvent, SimpleButton, Bitmap, BitmapData, Multitouch, TouchEvent } } = sandbox.__swoof_swflib;
|
|
161
|
+
const main = stage.addChild(new MovieClip());
|
|
162
|
+
main._swoofHostTimeline = true;
|
|
163
|
+
let legacyReleases = 0;
|
|
164
|
+
main.ClickPlay = () => { legacyReleases++; };
|
|
165
|
+
sandbox.root = main;
|
|
166
|
+
sandbox.__swoof = { main, root: main };
|
|
167
|
+
const translate = (x, y) => ({ a: 1, b: 0, c: 0, d: 1, tx: x * 20, ty: y * 20 });
|
|
168
|
+
const engine = generateTimelineEngine({
|
|
169
|
+
frames: [
|
|
170
|
+
{ frameIndex: 0, places: [
|
|
171
|
+
{ depth: 1, characterId: 2, name: 'preloader', matrix: translate(20, 10) },
|
|
172
|
+
{ depth: 2, characterId: 3, name: 'playButton_mc', matrix: translate(5, 70) },
|
|
173
|
+
] },
|
|
174
|
+
{ frameIndex: 1, removes: [2], places: [
|
|
175
|
+
{ depth: 2, characterId: 3, name: 'playButton_mc', matrix: translate(5, 70) },
|
|
176
|
+
] },
|
|
177
|
+
{ frameIndex: 2, places: [{ depth: 2, move: true, matrix: translate(5, 70) }] },
|
|
178
|
+
],
|
|
179
|
+
characters: {
|
|
180
|
+
1: triangle(),
|
|
181
|
+
2: { type: 'sprite', frames: [{ places: [
|
|
182
|
+
{ depth: 1, characterId: 3, name: 'startB', matrix: { a: 0, b: 1, c: -1, d: 0, tx: 200, ty: 200 } },
|
|
183
|
+
{ depth: 2, characterId: 3, name: 'logoB', matrix: translate(40, 10) },
|
|
184
|
+
{ depth: 3, characterId: 4, name: 'playGame', matrix: translate(40, 40) },
|
|
185
|
+
{ depth: 4, characterId: 3, name: 'hoverB', matrix: translate(15, 27) },
|
|
186
|
+
{ depth: 5, characterId: 4, matrix: translate(55, 75) },
|
|
187
|
+
] }] },
|
|
188
|
+
3: { type: 'sprite', frames: [
|
|
189
|
+
{ label: '_up', places: [{ depth: 1, characterId: 1 }] },
|
|
190
|
+
{ label: '_over', places: [{ depth: 1, characterId: 1 }] },
|
|
191
|
+
{ label: '_down', places: [{ depth: 1, characterId: 1 }] },
|
|
192
|
+
{ label: '_hit', places: [{ depth: 1, characterId: 1, matrix: translate(70, 70) }] },
|
|
193
|
+
] },
|
|
194
|
+
4: { type: 'button', buttonUp: { characterId: 1 }, buttonHitStates: [{ characterId: 1 }] },
|
|
195
|
+
},
|
|
196
|
+
}, { stageW: 100, stageH: 100, frameRate: 30, frameCount: 3, backgroundColor: '#000', sharedFactory });
|
|
197
|
+
runInNewContext(`${engine}\ntimeline.enter();`, sandbox);
|
|
198
|
+
const { startB, logoB, playGame, hoverB } = main.preloader;
|
|
199
|
+
const received = [];
|
|
200
|
+
startB.addEventListener(MouseEvent.MOUSE_UP, (event) => {
|
|
201
|
+
received.push(['up', event.target, event.stageX, event.stageY, event.localX, event.localY]);
|
|
202
|
+
});
|
|
203
|
+
startB.addEventListener(MouseEvent.CLICK, () => received.push(['click']));
|
|
204
|
+
startB.addEventListener(MouseEvent.RELEASE_OUTSIDE, () => received.push(['outside']));
|
|
205
|
+
logoB.addEventListener(MouseEvent.MOUSE_DOWN, (event) => {
|
|
206
|
+
received.push(['logo down', event.target, event.buttonDown, event.shiftKey]);
|
|
207
|
+
});
|
|
208
|
+
playGame.addEventListener(MouseEvent.CLICK, (event) => {
|
|
209
|
+
received.push(['play', event.target, event.localX, event.localY]);
|
|
210
|
+
});
|
|
211
|
+
sandbox.timeline.render();
|
|
212
|
+
const cssScale = 200 / backingSize;
|
|
213
|
+
const pointer = (type, x, y, extra = {}) => {
|
|
214
|
+
const event = { target: canvas, pointerId: 4, button: 0,
|
|
215
|
+
clientX: 10 + x * cssScale, clientY: 20 + y * cssScale, preventDefault() {}, ...extra };
|
|
216
|
+
for (const listener of windowHandlers[type] || []) listener(event);
|
|
217
|
+
for (const listener of canvasHandlers[type] || []) listener(event);
|
|
218
|
+
};
|
|
219
|
+
const touches = [];
|
|
220
|
+
const recordTouch = event => touches.push([
|
|
221
|
+
event.type, event.target.name, event.touchPointID, event.localX, event.localY, event.isTouchPointCanceled,
|
|
222
|
+
]);
|
|
223
|
+
const touchTypes = [TouchEvent.TOUCH_BEGIN, TouchEvent.TOUCH_MOVE, TouchEvent.TOUCH_END];
|
|
224
|
+
for (const type of touchTypes) main.preloader.addEventListener(type, recordTouch);
|
|
225
|
+
Multitouch.inputMode = 'touchPoint';
|
|
226
|
+
Multitouch.mapTouchToMouse = false;
|
|
227
|
+
sandbox.timeline.render();
|
|
228
|
+
const touch = (type, x, y, id) => pointer(type, x, y, { pointerType: 'touch', pointerId: id, isPrimary: id === 4 });
|
|
229
|
+
touch('pointerdown', 28, 22, 4);
|
|
230
|
+
touch('pointerdown', 37, 39, 9);
|
|
231
|
+
touch('pointermove', 62, 22, 4);
|
|
232
|
+
touch('pointercancel', 0, 0, 9);
|
|
233
|
+
touch('pointerup', 62, 22, 4);
|
|
234
|
+
expect(touches).toEqual([
|
|
235
|
+
['touchBegin', 'startB', 4, 2, 2, false],
|
|
236
|
+
['touchBegin', 'hoverB', 9, 2, 2, false],
|
|
237
|
+
['touchMove', 'logoB', 4, 2, 2, false],
|
|
238
|
+
['touchEnd', 'hoverB', 9, 2, 2, true],
|
|
239
|
+
['touchEnd', 'logoB', 4, 2, 2, false],
|
|
240
|
+
]);
|
|
241
|
+
expect(received).toEqual([]);
|
|
242
|
+
expect(stage.focus).toBeNull();
|
|
243
|
+
expect(canvas.style.cursor).toBe('auto');
|
|
244
|
+
for (const type of touchTypes) main.preloader.removeEventListener(type, recordTouch);
|
|
245
|
+
Multitouch.inputMode = 'gesture';
|
|
246
|
+
Multitouch.mapTouchToMouse = true;
|
|
247
|
+
hoverB.buttonMode = true;
|
|
248
|
+
sandbox.timeline.render();
|
|
249
|
+
const states = [];
|
|
250
|
+
const recordState = event => states.push([event.type, hoverB.currentFrameLabel]);
|
|
251
|
+
for (const type of ['mouseOver', 'mouseDown', 'mouseUp', 'click', 'releaseOutside']) {
|
|
252
|
+
hoverB.addEventListener(type, recordState);
|
|
253
|
+
}
|
|
254
|
+
pointer('pointermove', 37, 39);
|
|
255
|
+
expect(canvas.style.cursor).toBe('pointer');
|
|
256
|
+
expect(hoverB.currentFrameLabel).toBe('_over');
|
|
257
|
+
expect(logoB.currentFrameLabel).toBe('_up');
|
|
258
|
+
pointer('pointerdown', 37, 39);
|
|
259
|
+
expect(hoverB.currentFrameLabel).toBe('_down');
|
|
260
|
+
pointer('pointermove', 99, 99, { buttons: 1 });
|
|
261
|
+
expect(hoverB.currentFrameLabel).toBe('_over');
|
|
262
|
+
pointer('pointermove', 37, 39, { buttons: 1 });
|
|
263
|
+
expect(hoverB.currentFrameLabel).toBe('_down');
|
|
264
|
+
pointer('pointerup', 37, 39);
|
|
265
|
+
expect(states.splice(0)).toEqual([
|
|
266
|
+
['mouseOver', '_over'], ['mouseDown', '_down'], ['mouseOver', '_down'],
|
|
267
|
+
['mouseUp', '_over'], ['click', '_over'],
|
|
268
|
+
]);
|
|
269
|
+
expect(stage.focus).toBe(hoverB);
|
|
270
|
+
let keyClicks = 0;
|
|
271
|
+
const countKeyClick = () => keyClicks++;
|
|
272
|
+
hoverB.addEventListener(MouseEvent.CLICK, countKeyClick);
|
|
273
|
+
windowHandlers.keydown[0]({ key: 'Enter' });
|
|
274
|
+
expect(keyClicks).toBe(0);
|
|
275
|
+
expect(hoverB.currentFrameLabel).toBe('_down');
|
|
276
|
+
windowHandlers.keyup[0]({ key: 'Enter' });
|
|
277
|
+
expect(keyClicks).toBe(1);
|
|
278
|
+
expect(states.splice(0)).toEqual([['mouseDown', '_down'], ['mouseUp', '_over'], ['click', '_over']]);
|
|
279
|
+
hoverB.removeEventListener(MouseEvent.CLICK, countKeyClick);
|
|
280
|
+
pointer('pointerdown', 37, 39);
|
|
281
|
+
pointer('pointerup', 99, 99);
|
|
282
|
+
expect(states.splice(0)).toEqual([['mouseDown', '_down'], ['releaseOutside', '_up']]);
|
|
283
|
+
windowHandlers.keydown[0]({ key: ' ' });
|
|
284
|
+
expect(hoverB.currentFrameLabel).toBe('_down');
|
|
285
|
+
stage.focus = null;
|
|
286
|
+
windowHandlers.keyup[0]({ key: ' ' });
|
|
287
|
+
expect(states.splice(0)).toEqual([['mouseDown', '_down'], ['mouseUp', '_up']]);
|
|
288
|
+
hoverB.gotoAndStop('_hit');
|
|
289
|
+
expect(hoverB.currentFrameLabel).toBe('_hit');
|
|
290
|
+
sandbox.timeline.render();
|
|
291
|
+
pointer('pointermove', 37, 39);
|
|
292
|
+
expect(canvas.style.cursor).toBe('auto');
|
|
293
|
+
hoverB.gotoAndStop('_up');
|
|
294
|
+
sandbox.timeline.render();
|
|
295
|
+
hoverB.buttonMode = false;
|
|
296
|
+
expect(canvas.style.cursor).toBe('auto');
|
|
297
|
+
for (const type of ['mouseOver', 'mouseDown', 'mouseUp', 'click', 'releaseOutside']) {
|
|
298
|
+
hoverB.removeEventListener(type, recordState);
|
|
299
|
+
}
|
|
300
|
+
pointer('pointerleave', 101, 101);
|
|
301
|
+
sandbox.timeline.render();
|
|
302
|
+
hoverB.tabEnabled = true;
|
|
303
|
+
stage.focus = hoverB;
|
|
304
|
+
const mouseFocus = [];
|
|
305
|
+
stage.addEventListener('mouseFocusChange', event => mouseFocus.push([event.target, event.relatedObject]));
|
|
306
|
+
pointer('pointerdown', 22, 28); // Within bounds, outside the triangle
|
|
307
|
+
pointer('pointerup', 22, 28);
|
|
308
|
+
expect(received).toEqual([]);
|
|
309
|
+
expect(stage.focus).toBeNull();
|
|
310
|
+
expect(mouseFocus.splice(0)).toEqual([[hoverB, null]]);
|
|
311
|
+
|
|
312
|
+
stage.focus = hoverB;
|
|
313
|
+
pointer('pointerdown', 62, 22, { shiftKey: true });
|
|
314
|
+
pointer('pointerup', 62, 22);
|
|
315
|
+
expect(stage.focus).toBeNull();
|
|
316
|
+
expect(mouseFocus.splice(0)).toEqual([[hoverB, logoB]]);
|
|
317
|
+
pointer('pointerdown', 28, 22);
|
|
318
|
+
pointer('pointerup', 28, 22, { pointerId: 9 });
|
|
319
|
+
pointer('pointerup', 28, 22);
|
|
320
|
+
pointer('pointerdown', 28, 22);
|
|
321
|
+
pointer('pointerup', 90, 90);
|
|
322
|
+
pointer('pointerdown', 28, 22);
|
|
323
|
+
pointer('pointercancel', 28, 22);
|
|
324
|
+
pointer('pointerdown', 62, 52);
|
|
325
|
+
pointer('pointerup', 62, 52);
|
|
326
|
+
pointer('pointerdown', 7, 72);
|
|
327
|
+
pointer('pointerup', 7, 72);
|
|
328
|
+
expect(legacyReleases).toBe(1);
|
|
329
|
+
expect(received).toEqual([
|
|
330
|
+
['logo down', logoB, true, true],
|
|
331
|
+
['up', startB, 28, 22, 2, 2],
|
|
332
|
+
['click'],
|
|
333
|
+
['outside'],
|
|
334
|
+
['play', playGame, 2, 2],
|
|
335
|
+
]);
|
|
336
|
+
pointer('pointerleave', 101, 101);
|
|
337
|
+
const hover = [], moves = [];
|
|
338
|
+
logoB.addEventListener(MouseEvent.MOUSE_MOVE, event => moves.push([event.stageX, event.localX]));
|
|
339
|
+
for (const clip of [main.preloader, hoverB, logoB]) {
|
|
340
|
+
for (const type of [MouseEvent.ROLL_OVER, MouseEvent.ROLL_OUT, MouseEvent.MOUSE_OVER, MouseEvent.MOUSE_OUT]) {
|
|
341
|
+
clip.addEventListener(type, event => hover.push([
|
|
342
|
+
event.type, event.currentTarget.name, event.target.name, event.relatedObject?.name ?? null,
|
|
343
|
+
event.bubbles, event.buttonDown, event.shiftKey,
|
|
344
|
+
event.localX, event.localY, event.stageX, event.stageY,
|
|
345
|
+
]));
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
sandbox.timeline.render();
|
|
349
|
+
pointer('pointermove', 37, 39, { shiftKey: true });
|
|
350
|
+
expect(hover).toEqual([
|
|
351
|
+
['rollOver', 'preloader', 'preloader', null, false, false, true, 17, 29, 37, 39],
|
|
352
|
+
['rollOver', 'hoverB', 'hoverB', null, false, false, true, 2, 2, 37, 39],
|
|
353
|
+
['mouseOver', 'hoverB', 'hoverB', null, true, false, true, 2, 2, 37, 39],
|
|
354
|
+
['mouseOver', 'preloader', 'hoverB', null, true, false, true, 2, 2, 37, 39],
|
|
355
|
+
]);
|
|
356
|
+
hover.length = 0;
|
|
357
|
+
pointer('pointermove', 62, 22, { buttons: 1 });
|
|
358
|
+
expect(hover.map(event => event[5])).toEqual([true, true, true, true, true, true]);
|
|
359
|
+
expect(hover.map(event => event.slice(0, 5))).toEqual([
|
|
360
|
+
['mouseOut', 'hoverB', 'hoverB', 'logoB', true],
|
|
361
|
+
['mouseOut', 'preloader', 'hoverB', 'logoB', true],
|
|
362
|
+
['rollOut', 'hoverB', 'hoverB', 'logoB', false],
|
|
363
|
+
['rollOver', 'logoB', 'logoB', 'hoverB', false],
|
|
364
|
+
['mouseOver', 'logoB', 'logoB', 'hoverB', true],
|
|
365
|
+
['mouseOver', 'preloader', 'logoB', 'hoverB', true],
|
|
366
|
+
]);
|
|
367
|
+
hover.length = 0;
|
|
368
|
+
pointer('pointermove', 63, 22);
|
|
369
|
+
expect(hover).toEqual([]);
|
|
370
|
+
expect(moves).toEqual([[62, 2], [63, 3]]);
|
|
371
|
+
const otherPrimary = { pointerId: 7, pointerType: 'pen', isPrimary: true };
|
|
372
|
+
pointer('pointerleave', 101, 101, otherPrimary);
|
|
373
|
+
pointer('pointercancel', 101, 101, otherPrimary);
|
|
374
|
+
expect(hover).toEqual([]);
|
|
375
|
+
pointer('pointerleave', 101, 101);
|
|
376
|
+
expect(hover.map(event => event.slice(0, 5))).toEqual([
|
|
377
|
+
['mouseOut', 'logoB', 'logoB', null, true],
|
|
378
|
+
['mouseOut', 'preloader', 'logoB', null, true],
|
|
379
|
+
['rollOut', 'logoB', 'logoB', null, false],
|
|
380
|
+
['rollOut', 'preloader', 'preloader', null, false],
|
|
381
|
+
]);
|
|
382
|
+
const nativeButton = new SimpleButton();
|
|
383
|
+
nativeButton.name = 'programmatic';
|
|
384
|
+
nativeButton.x = 80;
|
|
385
|
+
nativeButton.y = 10;
|
|
386
|
+
nativeButton.width = 12;
|
|
387
|
+
nativeButton.height = 12;
|
|
388
|
+
main.preloader.addChild(nativeButton);
|
|
389
|
+
for (const type of [MouseEvent.ROLL_OVER, MouseEvent.ROLL_OUT, MouseEvent.MOUSE_OVER, MouseEvent.MOUSE_OUT]) {
|
|
390
|
+
nativeButton.addEventListener(type, event => hover.push([
|
|
391
|
+
event.type, event.currentTarget.name, event.target.name, event.relatedObject?.name ?? null, event.bubbles,
|
|
392
|
+
]));
|
|
393
|
+
}
|
|
394
|
+
let nativeClicks = 0, authoredClicks = 0;
|
|
395
|
+
nativeButton.addEventListener(MouseEvent.CLICK, () => { nativeClicks++; });
|
|
396
|
+
logoB.addEventListener(MouseEvent.CLICK, () => { authoredClicks++; });
|
|
397
|
+
pointer('pointermove', 62, 22);
|
|
398
|
+
hover.length = 0;
|
|
399
|
+
moves.length = 0;
|
|
400
|
+
|
|
401
|
+
nativeButton.x = 40;
|
|
402
|
+
sandbox.timeline.render();
|
|
403
|
+
expect(canvas.style.cursor).toBe('pointer');
|
|
404
|
+
expect(hover.map(event => event.slice(0, 5))).toEqual([
|
|
405
|
+
['mouseOut', 'logoB', 'logoB', 'programmatic', true],
|
|
406
|
+
['mouseOut', 'preloader', 'logoB', 'programmatic', true],
|
|
407
|
+
['rollOut', 'logoB', 'logoB', 'programmatic', false],
|
|
408
|
+
['rollOver', 'programmatic', 'programmatic', 'logoB', false],
|
|
409
|
+
['mouseOver', 'programmatic', 'programmatic', 'logoB', true],
|
|
410
|
+
['mouseOver', 'preloader', 'programmatic', 'logoB', true],
|
|
411
|
+
]);
|
|
412
|
+
pointer('pointerdown', 62, 22);
|
|
413
|
+
pointer('pointerup', 62, 22);
|
|
414
|
+
expect([nativeClicks, authoredClicks]).toEqual([1, 0]);
|
|
415
|
+
|
|
416
|
+
hover.length = 0;
|
|
417
|
+
nativeButton.x = 80;
|
|
418
|
+
sandbox.timeline.render();
|
|
419
|
+
expect(canvas.style.cursor).toBe('auto');
|
|
420
|
+
expect(hover.map(event => event.slice(0, 5))).toEqual([
|
|
421
|
+
['mouseOut', 'programmatic', 'programmatic', 'logoB', true],
|
|
422
|
+
['mouseOut', 'preloader', 'programmatic', 'logoB', true],
|
|
423
|
+
['rollOut', 'programmatic', 'programmatic', 'logoB', false],
|
|
424
|
+
['rollOver', 'logoB', 'logoB', 'programmatic', false],
|
|
425
|
+
['mouseOver', 'logoB', 'logoB', 'programmatic', true],
|
|
426
|
+
['mouseOver', 'preloader', 'logoB', 'programmatic', true],
|
|
427
|
+
]);
|
|
428
|
+
expect(moves).toEqual([]);
|
|
429
|
+
|
|
430
|
+
hover.length = 0;
|
|
431
|
+
main.preloader.x = 0;
|
|
432
|
+
sandbox.timeline.render();
|
|
433
|
+
expect(hover.map(event => event.slice(0, 5))).toEqual([
|
|
434
|
+
['mouseOut', 'logoB', 'logoB', null, true],
|
|
435
|
+
['mouseOut', 'preloader', 'logoB', null, true],
|
|
436
|
+
['rollOut', 'logoB', 'logoB', null, false],
|
|
437
|
+
['rollOut', 'preloader', 'preloader', null, false],
|
|
438
|
+
]);
|
|
439
|
+
hover.length = 0;
|
|
440
|
+
pointer('pointerleave', 101, 101);
|
|
441
|
+
main.preloader.x = 20;
|
|
442
|
+
sandbox.timeline.render();
|
|
443
|
+
expect(hover).toEqual([]);
|
|
444
|
+
const stencil = stage.addChild(new Bitmap(new BitmapData(3, 3, true, 0xffffffff)));
|
|
445
|
+
stencil.x = 61; stencil.y = 21;
|
|
446
|
+
logoB.mask = stencil;
|
|
447
|
+
pointer('pointermove', 62, 22);
|
|
448
|
+
expect(hover.some(event => event[0] === 'mouseOver' && event[2] === 'logoB')).toBe(true);
|
|
449
|
+
hover.length = 0;
|
|
450
|
+
pointer('pointermove', 66, 22);
|
|
451
|
+
expect(hover.map(event => event.slice(0, 5))).toEqual([
|
|
452
|
+
['mouseOut', 'logoB', 'logoB', null, true],
|
|
453
|
+
['mouseOut', 'preloader', 'logoB', null, true],
|
|
454
|
+
['rollOut', 'logoB', 'logoB', null, false],
|
|
455
|
+
['rollOut', 'preloader', 'preloader', null, false],
|
|
456
|
+
]);
|
|
457
|
+
pointer('pointerdown', 66, 22);
|
|
458
|
+
pointer('pointerup', 66, 22);
|
|
459
|
+
expect(authoredClicks).toBe(0);
|
|
460
|
+
Multitouch.mapTouchToMouse = false;
|
|
461
|
+
pointer('pointerdown', 62, 22, { pointerType: 'touch' });
|
|
462
|
+
pointer('pointerup', 62, 22, { pointerType: 'touch' });
|
|
463
|
+
expect(authoredClicks).toBe(0);
|
|
464
|
+
Multitouch.mapTouchToMouse = true;
|
|
465
|
+
pointer('pointerdown', 62, 22, { pointerType: 'touch' });
|
|
466
|
+
pointer('pointerup', 62, 22, { pointerType: 'touch' });
|
|
467
|
+
expect(authoredClicks).toBe(1);
|
|
468
|
+
|
|
469
|
+
pointer('pointerdown', 62, 22);
|
|
470
|
+
logoB.mouseEnabled = false;
|
|
471
|
+
pointer('pointerup', 62, 22);
|
|
472
|
+
expect(authoredClicks).toBe(1);
|
|
473
|
+
logoB.mouseEnabled = true;
|
|
474
|
+
sandbox.timeline.render();
|
|
475
|
+
pointer('pointerdown', 62, 22);
|
|
476
|
+
pointer('pointerup', 62, 22);
|
|
477
|
+
expect(authoredClicks).toBe(2);
|
|
478
|
+
|
|
479
|
+
let buttonPresses = 0, buttonClicks = 0;
|
|
480
|
+
playGame.addEventListener(MouseEvent.MOUSE_DOWN, () => buttonPresses++);
|
|
481
|
+
playGame.addEventListener(MouseEvent.CLICK, () => buttonClicks++);
|
|
482
|
+
for (const property of ['mouseEnabled', 'enabled']) {
|
|
483
|
+
playGame[property] = false;
|
|
484
|
+
pointer('pointerdown', 62, 52);
|
|
485
|
+
pointer('pointerup', 62, 52);
|
|
486
|
+
expect([buttonPresses, buttonClicks]).toEqual([0, 0]);
|
|
487
|
+
playGame[property] = true;
|
|
488
|
+
}
|
|
489
|
+
pointer('pointerdown', 62, 52);
|
|
490
|
+
playGame.enabled = false;
|
|
491
|
+
pointer('pointerup', 62, 52);
|
|
492
|
+
expect([buttonPresses, buttonClicks]).toEqual([1, 0]);
|
|
493
|
+
playGame.enabled = true;
|
|
494
|
+
pointer('pointerdown', 62, 52);
|
|
495
|
+
pointer('pointerup', 62, 52);
|
|
496
|
+
expect([buttonPresses, buttonClicks]).toEqual([2, 1]);
|
|
497
|
+
|
|
498
|
+
const oldPlay = main.playButton_mc;
|
|
499
|
+
const transitions = [];
|
|
500
|
+
const remember = event => transitions.push([event.type, event.target, event.relatedObject]);
|
|
501
|
+
oldPlay.buttonMode = true;
|
|
502
|
+
oldPlay.addEventListener(MouseEvent.MOUSE_OUT, remember);
|
|
503
|
+
oldPlay.addEventListener(MouseEvent.ROLL_OUT, remember);
|
|
504
|
+
main.addEventListener('added', event => {
|
|
505
|
+
if (event.target.name !== 'playButton_mc') return;
|
|
506
|
+
event.target.buttonMode = true;
|
|
507
|
+
event.target.addEventListener(MouseEvent.MOUSE_OVER, remember);
|
|
508
|
+
event.target.addEventListener(MouseEvent.ROLL_OVER, remember);
|
|
509
|
+
});
|
|
510
|
+
pointer('pointermove', 7, 72);
|
|
511
|
+
sandbox.timeline.gotoAndStop(2);
|
|
512
|
+
const newPlay = main.playButton_mc;
|
|
513
|
+
expect(newPlay).not.toBe(oldPlay);
|
|
514
|
+
expect(transitions).toEqual([
|
|
515
|
+
['mouseOut', oldPlay, newPlay],
|
|
516
|
+
['rollOut', oldPlay, newPlay],
|
|
517
|
+
['rollOver', newPlay, oldPlay],
|
|
518
|
+
['mouseOver', newPlay, oldPlay],
|
|
519
|
+
]);
|
|
520
|
+
sandbox.timeline.render();
|
|
521
|
+
sandbox.timeline.gotoAndStop(3);
|
|
522
|
+
expect(main.playButton_mc).toBe(newPlay);
|
|
523
|
+
expect(transitions).toHaveLength(4);
|
|
524
|
+
|
|
525
|
+
const unnamedEvents = [];
|
|
526
|
+
for (const type of ['mouseDown', 'mouseUp', 'click']) {
|
|
527
|
+
stage.addEventListener(type, event => unnamedEvents.push([
|
|
528
|
+
event.type, event.target, event.localX, event.localY, event.stageX, event.stageY,
|
|
529
|
+
]));
|
|
530
|
+
}
|
|
531
|
+
pointer('pointerdown', 77, 87);
|
|
532
|
+
pointer('pointerup', 77, 87);
|
|
533
|
+
expect(unnamedEvents).toEqual([
|
|
534
|
+
['mouseDown', main.preloader, 57, 77, 77, 87],
|
|
535
|
+
['mouseUp', main.preloader, 57, 77, 77, 87],
|
|
536
|
+
['click', main.preloader, 57, 77, 77, 87],
|
|
537
|
+
]);
|
|
538
|
+
|
|
539
|
+
const primary = [];
|
|
540
|
+
for (const type of ['mouseDown', 'mouseMove', 'mouseUp', 'click']) {
|
|
541
|
+
stage.addEventListener(type, event => primary.push([
|
|
542
|
+
event.type, event.target, event.stageX, event.stageY, event.buttonDown,
|
|
543
|
+
]));
|
|
544
|
+
}
|
|
545
|
+
pointer('pointermove', 95, 96, { buttons: 0 });
|
|
546
|
+
pointer('pointerdown', 95, 96, { buttons: 1 });
|
|
547
|
+
pointer('pointermove', 96, 97, { buttons: 1 });
|
|
548
|
+
pointer('pointerup', 96, 97, { buttons: 0 });
|
|
549
|
+
pointer('pointermove', 205, 205);
|
|
550
|
+
expect(primary.splice(0)).toEqual([
|
|
551
|
+
['mouseMove', stage, 95, 96, false],
|
|
552
|
+
['mouseDown', stage, 95, 96, true],
|
|
553
|
+
['mouseMove', stage, 96, 97, true],
|
|
554
|
+
['mouseUp', stage, 96, 97, false],
|
|
555
|
+
['click', stage, 96, 97, false],
|
|
556
|
+
]);
|
|
557
|
+
|
|
558
|
+
pointer('pointerdown', 95, 96);
|
|
559
|
+
pointer('pointercancel', 95, 96);
|
|
560
|
+
pointer('pointerup', 95, 96);
|
|
561
|
+
pointer('pointerdown', 95, 96);
|
|
562
|
+
pointer('pointerup', 205, 205);
|
|
563
|
+
expect(primary.splice(0)).toEqual([
|
|
564
|
+
['mouseDown', stage, 95, 96, true], ['mouseUp', stage, 95, 96, false],
|
|
565
|
+
['mouseDown', stage, 95, 96, true],
|
|
566
|
+
]);
|
|
567
|
+
|
|
568
|
+
// An earlier handler may reveal authored artwork during the same DOM event.
|
|
569
|
+
logoB.visible = false;
|
|
570
|
+
sandbox.timeline.render();
|
|
571
|
+
const revealLogo = event => {
|
|
572
|
+
if (event.target !== stage) return;
|
|
573
|
+
logoB.visible = true;
|
|
574
|
+
sandbox.timeline.render();
|
|
575
|
+
};
|
|
576
|
+
stage.addEventListener(MouseEvent.MOUSE_DOWN, revealLogo);
|
|
577
|
+
pointer('pointerdown', 62, 22);
|
|
578
|
+
expect(primary.splice(0)).toEqual([['mouseDown', stage, 62, 22, true]]);
|
|
579
|
+
stage.removeEventListener(MouseEvent.MOUSE_DOWN, revealLogo);
|
|
580
|
+
pointer('pointermove', 62, 22, { buttons: 1 });
|
|
581
|
+
pointer('pointerup', 62, 22);
|
|
582
|
+
expect(primary.splice(0)).toEqual([
|
|
583
|
+
['mouseMove', logoB, 62, 22, true], ['mouseUp', logoB, 62, 22, false],
|
|
584
|
+
]);
|
|
585
|
+
|
|
586
|
+
// A release originally sent to Stage cannot complete an authored button click.
|
|
587
|
+
const outside = [];
|
|
588
|
+
logoB.addEventListener(MouseEvent.RELEASE_OUTSIDE, event => outside.push(event.target));
|
|
589
|
+
pointer('pointerdown', 62, 22);
|
|
590
|
+
logoB.visible = false;
|
|
591
|
+
sandbox.timeline.render();
|
|
592
|
+
stage.addEventListener(MouseEvent.MOUSE_UP, revealLogo);
|
|
593
|
+
pointer('pointerup', 62, 22);
|
|
594
|
+
stage.removeEventListener(MouseEvent.MOUSE_UP, revealLogo);
|
|
595
|
+
expect(primary).toEqual([
|
|
596
|
+
['mouseDown', logoB, 62, 22, true], ['mouseUp', stage, 62, 22, false],
|
|
597
|
+
]);
|
|
598
|
+
expect(outside).toEqual([logoB]);
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
it('does not treat a cancelled touch/pointer sequence as a click release', () => {
|
|
602
|
+
expect(resolveButtonRelease('button-1', 'button-1')).toEqual({ capturedKey: 'button-1', releasedInside: true });
|
|
603
|
+
expect(resolveButtonRelease('button-1', null)).toEqual({ capturedKey: 'button-1', releasedInside: false });
|
|
604
|
+
expect(resolveButtonRelease('button-1', 'button-1', true)).toEqual({ capturedKey: 'button-1', releasedInside: false });
|
|
605
|
+
const timeline = generateTimelineEngine({ frames: [], characters: {} }, {
|
|
606
|
+
frameRate: 30, frameCount: 1, stageW: 100, stageH: 100, backgroundColor: '#000000',
|
|
607
|
+
});
|
|
608
|
+
expect(timeline).toContain("target.addEventListener('pointercancel', function (ev) { release(ev, true); });");
|
|
609
|
+
expect(timeline).toContain("if (cancelled) {\n _buttonInputStates[capturedKey] = 'idle';");
|
|
610
|
+
expect(timeline).toContain("fireHudEvent(pressed, 'releaseOutside', null, point)");
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
it('keeps unnamed instances of the same button on independent state keys', () => {
|
|
614
|
+
const first = buttonStateKey(42, '', '3:42');
|
|
615
|
+
const second = buttonStateKey(42, '', '9:42');
|
|
616
|
+
expect(first).not.toBe(second);
|
|
617
|
+
expect(buttonStateKey(42, 'renamed', '3:42')).toBe(first);
|
|
618
|
+
expect(buttonStateKey(42, '', '3:42', 1)).not.toBe(first);
|
|
619
|
+
const timeline = generateTimelineEngine({ frames: [], characters: {} }, {
|
|
620
|
+
frameRate: 30, frameCount: 1, stageW: 100, stageH: 100, backgroundColor: '#000000',
|
|
621
|
+
});
|
|
622
|
+
expect(timeline).toContain("item.key + ':' + e.characterId");
|
|
623
|
+
expect(timeline).toContain('buttonInstanceKey(clip, characterId, name, instancePath, placeEffects?.birthFrame)');
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
it('retains all decoded hit records in Button CharacterInfo', () => {
|
|
627
|
+
const bytes = [
|
|
628
|
+
7, 0, 0, 0, 0,
|
|
629
|
+
0x08, 1, 0, 1, 0, 0, 0, // hit record for shape 1, identity matrix/cxform
|
|
630
|
+
0x08, 2, 0, 2, 0, 0, 0, // hit record for shape 2
|
|
631
|
+
0,
|
|
632
|
+
];
|
|
633
|
+
const symbols = new SymbolTable();
|
|
634
|
+
symbols.set(7, { type: 'Button', characterId: 7, version: 2, rawData: Uint8Array.from(bytes) });
|
|
635
|
+
const { characters } = buildDisplayList([], symbols);
|
|
636
|
+
expect(characters['7'].buttonHitStates.map((record) => record.characterId)).toEqual([1, 2]);
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
it('paints each visual record in depth order and keeps hit-only art off the stage', () => {
|
|
640
|
+
const symbols = new SymbolTable();
|
|
641
|
+
const record = (flags, character, depth) => [flags, character, 0, depth, 0, 0, 0];
|
|
642
|
+
const bytes = [7, 0, 0, 0, 0, ...record(7, 2, 3), ...record(1, 1, 1),
|
|
643
|
+
...record(2, 3, 1), ...record(4, 4, 1), ...record(8, 5, 2), 0];
|
|
644
|
+
symbols.set(7, { type: 'Button', characterId: 7, version: 2, rawData: Uint8Array.from(bytes) });
|
|
645
|
+
const { characters } = buildDisplayList([], symbols);
|
|
646
|
+
for (let id = 1; id <= 5; id++) characters[id] = { ...triangle(), type: 'bitmap', assetId: id };
|
|
647
|
+
const handlers = {}, painted = [], animationFrames = [];
|
|
648
|
+
const canvas = { width: 100, height: 100, style: {}, setPointerCapture() {},
|
|
649
|
+
getBoundingClientRect: () => ({ left: 0, top: 0, width: 100, height: 100 }),
|
|
650
|
+
addEventListener(type, fn) { handlers[type] = fn; } };
|
|
651
|
+
const ctx = { canvas, globalAlpha: 1, save() {}, restore() {}, clearRect() {}, fillRect() {}, setTransform() {},
|
|
652
|
+
drawImage(image) { painted.push(image.id); } };
|
|
653
|
+
const sandbox = { ctx, STAGE_WIDTH: 100, STAGE_HEIGHT: 100, FRAME_RATE: 24, BACKGROUND: '#000',
|
|
654
|
+
requestAnimationFrame(callback) { return animationFrames.push(callback); }, PointerEvent: function () {},
|
|
655
|
+
document: { getElementById: id => id === 'stage' ? canvas : null, createElement: () => ({ getContext: () => null }) },
|
|
656
|
+
loaded: Object.fromEntries(Array.from({ length: 5 }, (_, i) => [i + 1, { id: i + 1 }])),
|
|
657
|
+
};
|
|
658
|
+
sandbox.window = sandbox;
|
|
659
|
+
sandbox.addEventListener = () => {};
|
|
660
|
+
const engine = generateTimelineEngine({ frames: [{ places: [{ depth: 1, characterId: 7 }] }], characters }, {});
|
|
661
|
+
runInNewContext(`${engine}\ntimeline.enter();`, sandbox);
|
|
662
|
+
expect(painted.splice(0)).toEqual([1, 2]);
|
|
663
|
+
const point = { clientX: 4, clientY: 4, pointerId: 1, button: 0, target: canvas, preventDefault() {} };
|
|
664
|
+
handlers.pointermove(point);
|
|
665
|
+
expect(painted.splice(0)).toEqual([3, 2]);
|
|
666
|
+
handlers.pointerdown(point);
|
|
667
|
+
expect(painted.splice(0)).toEqual([4, 2]);
|
|
668
|
+
|
|
669
|
+
runInNewContext('timeline.start();', sandbox);
|
|
670
|
+
handlers.pointermove(point);
|
|
671
|
+
handlers.pointermove(point);
|
|
672
|
+
handlers.pointermove(point);
|
|
673
|
+
expect(painted).toEqual([]);
|
|
674
|
+
animationFrames.shift()(0);
|
|
675
|
+
expect(painted.splice(0)).toEqual([4, 2]);
|
|
676
|
+
|
|
677
|
+
animationFrames.shift()(1000);
|
|
678
|
+
expect(runInNewContext('timeline._ticks', sandbox)).toBe(3);
|
|
679
|
+
expect(painted.splice(0)).toEqual([4, 2]);
|
|
680
|
+
animationFrames.shift()(1010);
|
|
681
|
+
expect(painted).toEqual([]);
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
it('advances instance-local visual records, preserves shared records, and freezes the hit timeline', () => {
|
|
685
|
+
const matrix = (x, y) => ({ a: 1, b: 0, c: 0, d: 1, tx: x * 20, ty: y * 20 });
|
|
686
|
+
const sprite = (ids) => ({ type: 'sprite', frames: ids.map((id, index) => ({
|
|
687
|
+
frameIndex: index, places: [{ depth: 1, characterId: id }],
|
|
688
|
+
})) });
|
|
689
|
+
const shared = { depth: 2, characterId: 17 };
|
|
690
|
+
const characters = {
|
|
691
|
+
8: sprite([1, 2, 3]),
|
|
692
|
+
9: { ...sprite([4, 5, 6]), buttonVisualStopFrame: 1 },
|
|
693
|
+
10: sprite([11, 12, 13]),
|
|
694
|
+
14: triangle(),
|
|
695
|
+
15: { type: 'sprite', frames: [
|
|
696
|
+
{ frameIndex: 0, places: [{ depth: 1, characterId: 14 }] },
|
|
697
|
+
{ frameIndex: 1, places: [{ depth: 1, move: true, matrix: matrix(200, 0) }] },
|
|
698
|
+
] },
|
|
699
|
+
16: { type: 'button', buttonStates: {
|
|
700
|
+
up: [{ depth: 1, characterId: 19 }, shared],
|
|
701
|
+
over: [{ depth: 1, characterId: 18 }, shared],
|
|
702
|
+
down: [{ depth: 1, characterId: 18 }, shared],
|
|
703
|
+
}, buttonHitStates: [{ depth: 1, characterId: 15 }] },
|
|
704
|
+
17: sprite([10]),
|
|
705
|
+
18: sprite([9]),
|
|
706
|
+
19: { type: 'sprite', frames: [
|
|
707
|
+
{ frameIndex: 0, places: [{ depth: 1, characterId: 8 }] },
|
|
708
|
+
{ frameIndex: 1 },
|
|
709
|
+
{ frameIndex: 2, places: [{ depth: 1, characterId: 8 }] },
|
|
710
|
+
{ frameIndex: 3 },
|
|
711
|
+
] },
|
|
712
|
+
};
|
|
713
|
+
const ids = [1, 2, 3, 4, 5, 6, 11, 12, 13];
|
|
714
|
+
for (const id of ids) characters[id] = { type: 'bitmap', assetId: id };
|
|
715
|
+
const handlers = {}, painted = [];
|
|
716
|
+
const canvas = { width: 100, height: 100, style: {}, setPointerCapture() {},
|
|
717
|
+
getBoundingClientRect: () => ({ left: 0, top: 0, width: 100, height: 100 }),
|
|
718
|
+
addEventListener(type, fn) { handlers[type] = fn; } };
|
|
719
|
+
const ctx = { canvas, globalAlpha: 1, save() {}, restore() {}, clearRect() {}, fillRect() {}, setTransform() {},
|
|
720
|
+
drawImage(image) { painted.push(image.id); } };
|
|
721
|
+
const sandbox = { ctx, STAGE_WIDTH: 100, STAGE_HEIGHT: 100, FRAME_RATE: 24, BACKGROUND: '#000',
|
|
722
|
+
requestAnimationFrame: () => 1, PointerEvent: function () {}, addEventListener() {},
|
|
723
|
+
document: { getElementById: id => id === 'stage' ? canvas : null, createElement: () => ({ getContext: () => null }) },
|
|
724
|
+
loaded: Object.fromEntries(ids.map(id => [id, { id }])),
|
|
725
|
+
};
|
|
726
|
+
sandbox.window = sandbox;
|
|
727
|
+
const engine = generateTimelineEngine({ frames: [{ places: [
|
|
728
|
+
{ depth: 1, characterId: 16, matrix: matrix(5, 5) },
|
|
729
|
+
{ depth: 2, characterId: 16, matrix: matrix(55, 5) },
|
|
730
|
+
] }], characters }, { frameCount: 1, stageW: 100, stageH: 100 });
|
|
731
|
+
runInNewContext(`${engine}\nensureSpritePlay(15, 2);\nensureSpritePlay(9, 3);\ntimeline.enter();`, sandbox);
|
|
732
|
+
const lastPaint = () => painted.slice(-4);
|
|
733
|
+
const pointer = (type, x, y) => handlers[type]({
|
|
734
|
+
target: canvas, pointerId: 1, button: 0, clientX: x, clientY: y, preventDefault() {},
|
|
735
|
+
});
|
|
736
|
+
expect(lastPaint()).toEqual([1, 11, 1, 11]);
|
|
737
|
+
sandbox.timeline.tick();
|
|
738
|
+
expect(lastPaint()).toEqual([2, 12, 2, 12]);
|
|
739
|
+
pointer('pointermove', 7, 7);
|
|
740
|
+
expect(lastPaint()).toEqual([4, 12, 2, 12]);
|
|
741
|
+
pointer('pointerdown', 7, 7);
|
|
742
|
+
sandbox.timeline.tick();
|
|
743
|
+
expect(lastPaint()).toEqual([5, 13, 1, 13]);
|
|
744
|
+
pointer('pointerup', 7, 7);
|
|
745
|
+
sandbox.timeline.tick();
|
|
746
|
+
expect(lastPaint()).toEqual([5, 11, 2, 11]);
|
|
747
|
+
pointer('pointermove', 30, 30);
|
|
748
|
+
expect(lastPaint()).toEqual([1, 11, 2, 11]);
|
|
749
|
+
sandbox.timeline.tick();
|
|
750
|
+
pointer('pointermove', 7, 7);
|
|
751
|
+
expect(lastPaint()).toEqual([4, 12, 1, 12]);
|
|
752
|
+
});
|
|
753
|
+
|
|
754
|
+
it('reads the stop frame of the real Learn to Fly button state sprites', async () => {
|
|
755
|
+
const { doc } = await parse(readFileSync('archive/Swf/learn-to-fly.swf'));
|
|
756
|
+
const { tags, symbolTable } = decode(doc);
|
|
757
|
+
const { characters } = buildDisplayList(tags, symbolTable);
|
|
758
|
+
expect(characters[138].buttonStates.up[0].characterId).toBe(132);
|
|
759
|
+
expect(characters[138].buttonStates.over[0].characterId).toBe(136);
|
|
760
|
+
expect([characters[132].buttonVisualStopFrame, characters[136].buttonVisualStopFrame]).toEqual([9, 4]);
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
it('retains the three authored Duck Life title labels above the button backgrounds', async () => {
|
|
764
|
+
const diagnostics = new DiagnosticsCollector();
|
|
765
|
+
const bytes = new Uint8Array(readFileSync('archive/flasharchive/Duck Life 1.swf'));
|
|
766
|
+
const { doc } = await parse(bytes, diagnostics);
|
|
767
|
+
const { tags, symbolTable } = decode(doc, diagnostics);
|
|
768
|
+
const { characters } = buildDisplayList(tags, symbolTable, diagnostics);
|
|
769
|
+
for (const [id, text] of [[40, 'Play'], [69, 'More Games'], [71, 'Download']]) {
|
|
770
|
+
const states = characters[id].buttonStates;
|
|
771
|
+
for (const records of Object.values(states)) {
|
|
772
|
+
expect(records).toHaveLength(2);
|
|
773
|
+
expect(characters[records[0].characterId].type).toBe('shape');
|
|
774
|
+
expect(characters[records[1].characterId].text).toBe(text);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
it('falls back to decoded bounds when shape geometry is unavailable', () => {
|
|
780
|
+
const characters = { 1: { type: 'shape', bounds: { x: 1, y: 2, w: 4, h: 5 }, draws: [] } };
|
|
781
|
+
expect(hitTestButtonGeometry(characters, 1, null, 2, 3)).toBe(true);
|
|
782
|
+
expect(hitTestButtonGeometry(characters, 1, null, 8, 8)).toBe(false);
|
|
783
|
+
});
|
|
784
|
+
|
|
785
|
+
it('falls back to bounds for path commands the geometry checker does not support', () => {
|
|
786
|
+
const characters = {
|
|
787
|
+
1: {
|
|
788
|
+
type: 'shape', bounds: { x: 0, y: 0, w: 10, h: 10 },
|
|
789
|
+
draws: [{ fill: { type: 'solid' }, path: [['M', 0, 0], ['C', 1, 1, 9, 9, 10, 10]] }],
|
|
790
|
+
},
|
|
791
|
+
};
|
|
792
|
+
expect(hitTestButtonGeometry(characters, 1, null, 8, 8)).toBe(true);
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
it('keeps Knightmare Tower named sprite `link_jbIntro` on the canvas click path', async () => {
|
|
796
|
+
const diagnostics = new DiagnosticsCollector();
|
|
797
|
+
const bytes = new Uint8Array(readFileSync('archive/Swf/knightmare-tower.swf'));
|
|
798
|
+
const { doc } = await parse(bytes, diagnostics);
|
|
799
|
+
const { tags, symbolTable } = decode(doc, diagnostics);
|
|
800
|
+
const displayList = buildDisplayList(tags, symbolTable, diagnostics);
|
|
801
|
+
const placed = displayList.frames[51].places.find((entry) => entry.name === 'link_jbIntro');
|
|
802
|
+
|
|
803
|
+
expect(placed).toMatchObject({ characterId: 66, name: 'link_jbIntro' });
|
|
804
|
+
expect(displayList.characters[String(placed.characterId)].type).toBe('sprite');
|
|
805
|
+
|
|
806
|
+
const actionscript = transpileActionScript(tags, diagnostics);
|
|
807
|
+
expect(actionscript.fullJs).toContain('swoof.events.MouseEvent');
|
|
808
|
+
const timeline = generateTimelineEngine(displayList, {
|
|
809
|
+
frameRate: doc.header.frameRate, frameCount: doc.header.frameCount,
|
|
810
|
+
stageW: 100, stageH: 100, backgroundColor: '#000000',
|
|
811
|
+
});
|
|
812
|
+
expect(timeline).toContain('clipHasPointerListener');
|
|
813
|
+
expect(timeline).toContain('dispatchAs3Click');
|
|
814
|
+
expect(timeline).toContain('event.stageX = point.x');
|
|
815
|
+
expect(timeline).toContain('if (eventName === \'release\') dispatchAs3Click(item, point, nativeEvent)');
|
|
816
|
+
expect(() => acorn.parse(`${actionscript.fullJs}\n${timeline}`, { ecmaVersion: 2020 })).not.toThrow();
|
|
817
|
+
});
|
|
818
|
+
|
|
819
|
+
it('defers nested SymbolClass frame-0 scripts until the instance is attached to Stage', () => {
|
|
820
|
+
const timeline = generateTimelineEngine({ frames: [], characters: {} }, {
|
|
821
|
+
frameRate: 30, frameCount: 1, stageW: 100, stageH: 100, backgroundColor: '#000000',
|
|
822
|
+
});
|
|
823
|
+
expect(timeline).toContain('as3DocumentReady() && clip.stage != null && !clip._swoofFrame0ScriptRun');
|
|
824
|
+
});
|
|
825
|
+
});
|