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,714 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
3
|
+
import { runInNewContext } from 'node:vm';
|
|
4
|
+
import { generateTimelineEngine } from '../transpiler/timeline/timeline-codegen.js';
|
|
5
|
+
|
|
6
|
+
import { SymbolTable } from '../decoder/symbol-table.js';
|
|
7
|
+
import { decodeTag } from '../decoder/tag-decoder.js';
|
|
8
|
+
import { TAG } from '../decoder/tag-types.js';
|
|
9
|
+
import { buildDisplayList } from '../transpiler/timeline/display-list.js';
|
|
10
|
+
|
|
11
|
+
describe('AS3 bitmap cursors', () => {
|
|
12
|
+
it('registers and animates snapshots on the stage with the authored hotspot', () => {
|
|
13
|
+
const canvas = { style: {}, addEventListener() {} };
|
|
14
|
+
const wrap = { style: {} };
|
|
15
|
+
const body = { style: {} };
|
|
16
|
+
const timers = new Map();
|
|
17
|
+
let nextTimer = 0, nextImage = 0;
|
|
18
|
+
const sandbox = {
|
|
19
|
+
document: {
|
|
20
|
+
body,
|
|
21
|
+
getElementById: id => id === 'stage' ? canvas : id === 'stage-wrap' ? wrap : null,
|
|
22
|
+
createElement() {
|
|
23
|
+
const image = ++nextImage;
|
|
24
|
+
return { getContext: () => ({}), toDataURL: () => `data:image/png;base64,frame${image}` };
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
addEventListener() {},
|
|
28
|
+
CSS: { supports: () => true },
|
|
29
|
+
matchMedia: () => ({ matches: true }),
|
|
30
|
+
setInterval(callback, delay) {
|
|
31
|
+
const id = ++nextTimer;
|
|
32
|
+
timers.set(id, { callback, delay });
|
|
33
|
+
return id;
|
|
34
|
+
},
|
|
35
|
+
clearInterval: id => timers.delete(id),
|
|
36
|
+
};
|
|
37
|
+
sandbox.window = sandbox;
|
|
38
|
+
runInNewContext(SWFLIB_SOURCE, sandbox);
|
|
39
|
+
const { packages: { ui: { Mouse, MouseCursorData } }, builtins: { BitmapData, Point, Vector } } = sandbox.__swoof_swflib;
|
|
40
|
+
const cursor = new MouseCursorData();
|
|
41
|
+
cursor.hotSpot = new Point(4, 6);
|
|
42
|
+
cursor.data = new Vector(0, false);
|
|
43
|
+
cursor.data.push(new BitmapData(20, 20), new BitmapData(20, 20));
|
|
44
|
+
cursor.frameRate = 8;
|
|
45
|
+
const first = 'url("data:image/png;base64,frame1") 4 6, auto';
|
|
46
|
+
const second = 'url("data:image/png;base64,frame2") 4 6, auto';
|
|
47
|
+
|
|
48
|
+
expect(Mouse.supportsNativeCursor).toBe(true);
|
|
49
|
+
Mouse.registerCursor('spinner', cursor);
|
|
50
|
+
expect(canvas.style.cursor).toBe('auto');
|
|
51
|
+
Mouse.cursor = 'spinner';
|
|
52
|
+
expect(canvas.style.cursor).toBe(first);
|
|
53
|
+
expect(wrap.style.cursor).toBe(first);
|
|
54
|
+
expect(body.style.cursor).toBeUndefined();
|
|
55
|
+
const [timer] = timers.values();
|
|
56
|
+
expect(timer.delay).toBe(125);
|
|
57
|
+
cursor.data[0].dispose();
|
|
58
|
+
cursor.hotSpot.x = 1;
|
|
59
|
+
timer.callback();
|
|
60
|
+
expect(canvas.style.cursor).toBe(second);
|
|
61
|
+
timer.callback();
|
|
62
|
+
expect(canvas.style.cursor).toBe(first);
|
|
63
|
+
|
|
64
|
+
const oversized = new MouseCursorData();
|
|
65
|
+
oversized.data = [new BitmapData(33, 10)];
|
|
66
|
+
expect(() => Mouse.registerCursor('spinner', oversized)).toThrow(/32 by 32/);
|
|
67
|
+
expect(canvas.style.cursor).toBe(first);
|
|
68
|
+
Mouse.hide();
|
|
69
|
+
expect(canvas.style.cursor).toBe('none');
|
|
70
|
+
expect(timers.size).toBe(0);
|
|
71
|
+
Mouse.show();
|
|
72
|
+
expect(canvas.style.cursor).toBe(first);
|
|
73
|
+
expect(timers.size).toBe(1);
|
|
74
|
+
Mouse.unregisterCursor('spinner');
|
|
75
|
+
expect([Mouse.cursor, canvas.style.cursor, wrap.style.cursor, timers.size]).toEqual(['auto', 'auto', 'auto', 0]);
|
|
76
|
+
timer.callback();
|
|
77
|
+
expect(canvas.style.cursor).toBe('auto');
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe('browser Stage activation', () => {
|
|
82
|
+
it('publishes each window or tab activation change without reacting to control focus', () => {
|
|
83
|
+
const windowListeners = {}, pageListeners = {};
|
|
84
|
+
const document = {
|
|
85
|
+
activeElement: null, hidden: false, hasFocus: () => true, getElementById: () => null,
|
|
86
|
+
addEventListener(type, listener) { (pageListeners[type] ||= []).push(listener); },
|
|
87
|
+
};
|
|
88
|
+
const sandbox = {
|
|
89
|
+
document,
|
|
90
|
+
addEventListener(type, listener, capture) { (windowListeners[type] ||= []).push({ listener, capture }); },
|
|
91
|
+
};
|
|
92
|
+
sandbox.window = sandbox;
|
|
93
|
+
runInNewContext(SWFLIB_SOURCE, sandbox);
|
|
94
|
+
const { stage, builtins: { Event, EventDispatcher, TextField, Sprite } } = sandbox.__swoof_swflib;
|
|
95
|
+
const seen = [];
|
|
96
|
+
for (const type of [Event.ACTIVATE, Event.DEACTIVATE]) {
|
|
97
|
+
stage.addEventListener(type, e => seen.push([e.type, e.target === stage, e.bubbles, e.cancelable]));
|
|
98
|
+
}
|
|
99
|
+
const listener = stage.addChild(new Sprite());
|
|
100
|
+
const offstage = new Sprite();
|
|
101
|
+
const plain = new EventDispatcher();
|
|
102
|
+
const broadcast = [];
|
|
103
|
+
for (const type of [Event.ACTIVATE, Event.DEACTIVATE]) {
|
|
104
|
+
listener.addEventListener(type, e => broadcast.push(['on', e.type, e.target === listener, e.bubbles]));
|
|
105
|
+
offstage.addEventListener(type, e => broadcast.push(['off', e.type, e.target === offstage, e.bubbles]));
|
|
106
|
+
plain.addEventListener(type, e => broadcast.push(['plain', e.type, e.target === plain, e.bubbles]));
|
|
107
|
+
}
|
|
108
|
+
const windowEvent = (type, target = sandbox) => {
|
|
109
|
+
for (const { listener, capture } of windowListeners[type] ?? []) {
|
|
110
|
+
if (target === sandbox || capture) listener({ type, target });
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const setHidden = hidden => {
|
|
114
|
+
document.hidden = hidden;
|
|
115
|
+
for (const listener of pageListeners.visibilitychange ?? []) listener({ type: 'visibilitychange' });
|
|
116
|
+
};
|
|
117
|
+
const field = stage.addChild(new TextField());
|
|
118
|
+
stage.focus = field;
|
|
119
|
+
windowEvent('blur', { tagName: 'CANVAS' });
|
|
120
|
+
windowEvent('focus', { tagName: 'INPUT' });
|
|
121
|
+
windowEvent('focus');
|
|
122
|
+
expect(seen).toEqual([]);
|
|
123
|
+
expect(broadcast).toEqual([]);
|
|
124
|
+
|
|
125
|
+
setHidden(true);
|
|
126
|
+
windowEvent('blur');
|
|
127
|
+
windowEvent('focus');
|
|
128
|
+
expect(seen).toEqual([['deactivate', true, false, false]]);
|
|
129
|
+
expect(broadcast).toEqual([
|
|
130
|
+
['on', 'deactivate', true, false], ['off', 'deactivate', true, false],
|
|
131
|
+
['plain', 'deactivate', true, false],
|
|
132
|
+
]);
|
|
133
|
+
setHidden(false);
|
|
134
|
+
windowEvent('blur');
|
|
135
|
+
windowEvent('blur');
|
|
136
|
+
windowEvent('focus');
|
|
137
|
+
expect(seen).toEqual([
|
|
138
|
+
['deactivate', true, false, false], ['activate', true, false, false],
|
|
139
|
+
['deactivate', true, false, false], ['activate', true, false, false],
|
|
140
|
+
]);
|
|
141
|
+
expect(broadcast).toEqual([
|
|
142
|
+
['on', 'deactivate', true, false], ['off', 'deactivate', true, false],
|
|
143
|
+
['plain', 'deactivate', true, false],
|
|
144
|
+
['on', 'activate', true, false], ['off', 'activate', true, false],
|
|
145
|
+
['plain', 'activate', true, false],
|
|
146
|
+
['on', 'deactivate', true, false], ['off', 'deactivate', true, false],
|
|
147
|
+
['plain', 'deactivate', true, false],
|
|
148
|
+
['on', 'activate', true, false], ['off', 'activate', true, false],
|
|
149
|
+
['plain', 'activate', true, false],
|
|
150
|
+
]);
|
|
151
|
+
expect(stage.focus).toBe(field);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe('Stage render invalidation', () => {
|
|
156
|
+
it('coalesces requests into a Stage render event before the next actual root paint', () => {
|
|
157
|
+
const engine = generateTimelineEngine({ frames: [{ places: [] }], characters: {} }, { frameCount: 1 });
|
|
158
|
+
const sandbox = { ctx: null, FRAME_RATE: 24, STAGE_WIDTH: 20, STAGE_HEIGHT: 10, BACKGROUND: '#000', loaded: {} };
|
|
159
|
+
const { stage, timeline, Event, EventDispatcher, Sprite } = runInNewContext(`${SWFLIB_SOURCE}\n${engine}\n({
|
|
160
|
+
stage: __swoof_swflib.stage, timeline, Event: __swoof_swflib.builtins.Event,
|
|
161
|
+
EventDispatcher: __swoof_swflib.builtins.EventDispatcher,
|
|
162
|
+
Sprite: __swoof_swflib.builtins.Sprite
|
|
163
|
+
});`, sandbox);
|
|
164
|
+
const visits = [];
|
|
165
|
+
const paint = () => visits.push(['paint']);
|
|
166
|
+
stage.addEventListener(Event.RENDER, event => {
|
|
167
|
+
visits.push([event.type, event.target === stage, event.bubbles, event.cancelable]);
|
|
168
|
+
if (visits.length === 1) stage.invalidate();
|
|
169
|
+
});
|
|
170
|
+
const onStage = stage.addChild(new Sprite());
|
|
171
|
+
const offStage = new Sprite();
|
|
172
|
+
const plain = new EventDispatcher();
|
|
173
|
+
onStage.addEventListener(Event.RENDER, event => {
|
|
174
|
+
visits.push(['on', event.target === onStage, event.bubbles]);
|
|
175
|
+
});
|
|
176
|
+
offStage.addEventListener(Event.RENDER, event => {
|
|
177
|
+
visits.push(['off', event.target === offStage, event.bubbles]);
|
|
178
|
+
});
|
|
179
|
+
plain.addEventListener(Event.RENDER, event => {
|
|
180
|
+
visits.push(['plain', event.target === plain, event.bubbles]);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
stage.invalidate();
|
|
184
|
+
stage.invalidate();
|
|
185
|
+
timeline.render();
|
|
186
|
+
expect(visits).toEqual([]);
|
|
187
|
+
sandbox.ctx = { setTransform() {}, fillRect: paint, save() {}, restore() {}, transform() {} };
|
|
188
|
+
timeline.render();
|
|
189
|
+
timeline.render();
|
|
190
|
+
timeline.render();
|
|
191
|
+
expect(visits).toEqual([
|
|
192
|
+
['render', true, false, false], ['on', true, false], ['off', true, false], ['plain', true, false], ['paint'],
|
|
193
|
+
['render', true, false, false], ['on', true, false], ['off', true, false], ['plain', true, false], ['paint'], ['paint'],
|
|
194
|
+
]);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
describe('browser keyboard input', () => {
|
|
199
|
+
it('consumes native Tab when ActionScript cancels or redirects a focus change', () => {
|
|
200
|
+
const listeners = {};
|
|
201
|
+
const document = { activeElement: null, getElementById: () => null };
|
|
202
|
+
const sandbox = { document, addEventListener(type, listener) { (listeners[type] ||= []).push(listener); } };
|
|
203
|
+
sandbox.window = sandbox;
|
|
204
|
+
runInNewContext(SWFLIB_SOURCE, sandbox);
|
|
205
|
+
const { stage, builtins: { FocusEvent, TextField } } = sandbox.__swoof_swflib;
|
|
206
|
+
const makeEditor = tabIndex => {
|
|
207
|
+
const field = stage.addChild(new TextField());
|
|
208
|
+
field.type = 'input';
|
|
209
|
+
field.tabIndex = tabIndex;
|
|
210
|
+
field._swoofOverlayElement = { _swoofTextField: field, focus() { document.activeElement = this; } };
|
|
211
|
+
return field;
|
|
212
|
+
};
|
|
213
|
+
const first = makeEditor(1), second = makeEditor(2), redirect = makeEditor(3);
|
|
214
|
+
const pressTab = (shiftKey = false) => {
|
|
215
|
+
const event = { key: 'Tab', shiftKey, defaultPrevented: false, preventDefault() { this.defaultPrevented = true; } };
|
|
216
|
+
listeners.keydown[0](event);
|
|
217
|
+
return event.defaultPrevented;
|
|
218
|
+
};
|
|
219
|
+
const activeEditor = () => document.activeElement?._swoofTextField;
|
|
220
|
+
const proposed = [];
|
|
221
|
+
const veto = event => {
|
|
222
|
+
proposed.push([event.target === first, event.relatedObject === second, event.cancelable, event.keyCode]);
|
|
223
|
+
event.preventDefault();
|
|
224
|
+
};
|
|
225
|
+
stage.focus = first;
|
|
226
|
+
first.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, veto);
|
|
227
|
+
expect(pressTab()).toBe(true);
|
|
228
|
+
expect(proposed).toEqual([[true, true, true, 9]]);
|
|
229
|
+
expect(stage.focus).toBe(first);
|
|
230
|
+
expect(activeEditor()).toBe(first);
|
|
231
|
+
|
|
232
|
+
first.removeEventListener(FocusEvent.KEY_FOCUS_CHANGE, veto);
|
|
233
|
+
first.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, event => {
|
|
234
|
+
stage.focus = redirect;
|
|
235
|
+
event.preventDefault();
|
|
236
|
+
});
|
|
237
|
+
expect(pressTab()).toBe(true);
|
|
238
|
+
expect(stage.focus).toBe(redirect);
|
|
239
|
+
expect(activeEditor()).toBe(redirect);
|
|
240
|
+
|
|
241
|
+
expect(pressTab(true)).toBe(true);
|
|
242
|
+
expect(stage.focus).toBe(second);
|
|
243
|
+
expect(activeEditor()).toBe(second);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('respects tabChildren while traversing generated authored containers in both directions', () => {
|
|
247
|
+
const listeners = {};
|
|
248
|
+
const sandbox = {
|
|
249
|
+
ctx: null, FRAME_RATE: 24, loaded: [], requestAnimationFrame: () => 1,
|
|
250
|
+
addEventListener: (type, fn) => { (listeners[type] ||= []).push(fn); },
|
|
251
|
+
};
|
|
252
|
+
sandbox.window = sandbox;
|
|
253
|
+
const hold = { depth: 1, characterId: 1, name: 'holder' };
|
|
254
|
+
const authored = { depth: 2, characterId: 2, name: 'nested' };
|
|
255
|
+
const timeline = generateTimelineEngine({
|
|
256
|
+
frames: [{ places: [hold, { ...authored, name: 'after' }] }],
|
|
257
|
+
characters: { 1: { type: 'sprite', frames: [{ places: [authored] }] },
|
|
258
|
+
2: { type: 'sprite', frames: [{ places: [] }] } },
|
|
259
|
+
}, { frameCount: 1 });
|
|
260
|
+
const result = runInNewContext(SWFLIB_SOURCE + `
|
|
261
|
+
var { stage, builtins } = __swoof_swflib;
|
|
262
|
+
var main = stage.addChild(new builtins.MovieClip());
|
|
263
|
+
main._swoofHostTimeline = true;
|
|
264
|
+
var root = main;
|
|
265
|
+
window.__swoof = { main, root };
|
|
266
|
+
${timeline}
|
|
267
|
+
timeline.enter();
|
|
268
|
+
var { holder, after } = main;
|
|
269
|
+
var nested = holder.nested;
|
|
270
|
+
holder.buttonMode = nested.buttonMode = after.buttonMode = true;
|
|
271
|
+
({ stage, main, holder, nested, after, Event: builtins.Event });
|
|
272
|
+
`, sandbox);
|
|
273
|
+
const { stage, main, holder, nested, after, Event } = result;
|
|
274
|
+
const tab = (shiftKey = false) => listeners.keydown[0]({ key: 'Tab', shiftKey });
|
|
275
|
+
expect(holder.tabChildren).toBe(true);
|
|
276
|
+
stage.focus = holder;
|
|
277
|
+
tab();
|
|
278
|
+
expect(stage.focus).toBe(nested);
|
|
279
|
+
|
|
280
|
+
const changes = [];
|
|
281
|
+
main.addEventListener(Event.TAB_CHILDREN_CHANGE, event => changes.push(event));
|
|
282
|
+
holder.tabChildren = false;
|
|
283
|
+
holder.tabChildren = false;
|
|
284
|
+
expect(changes).toHaveLength(1);
|
|
285
|
+
expect(changes[0]).toMatchObject({ target: holder, bubbles: true, cancelable: false });
|
|
286
|
+
expect(stage.focus).toBe(nested);
|
|
287
|
+
stage.focus = holder;
|
|
288
|
+
tab();
|
|
289
|
+
expect(stage.focus).toBe(after);
|
|
290
|
+
tab(true);
|
|
291
|
+
expect(stage.focus).toBe(holder);
|
|
292
|
+
stage.focus = nested;
|
|
293
|
+
expect(stage.focus).toBe(nested);
|
|
294
|
+
|
|
295
|
+
holder.tabChildren = true;
|
|
296
|
+
stage.focus = after;
|
|
297
|
+
tab(true);
|
|
298
|
+
expect(stage.focus).toBe(nested);
|
|
299
|
+
stage.tabChildren = false;
|
|
300
|
+
tab();
|
|
301
|
+
expect(stage.focus).toBe(nested);
|
|
302
|
+
|
|
303
|
+
stage.tabChildren = true;
|
|
304
|
+
after.tabIndex = 0;
|
|
305
|
+
nested.tabIndex = 0;
|
|
306
|
+
stage.focus = null;
|
|
307
|
+
tab();
|
|
308
|
+
expect(stage.focus).toBe(nested);
|
|
309
|
+
tab();
|
|
310
|
+
expect(stage.focus).toBe(after);
|
|
311
|
+
tab();
|
|
312
|
+
expect(stage.focus).toBe(nested);
|
|
313
|
+
tab(true);
|
|
314
|
+
expect(stage.focus).toBe(after);
|
|
315
|
+
nested.tabEnabled = false;
|
|
316
|
+
stage.focus = null;
|
|
317
|
+
tab();
|
|
318
|
+
expect(stage.focus).toBe(after);
|
|
319
|
+
after.tabIndex = -1;
|
|
320
|
+
stage.focus = null;
|
|
321
|
+
tab();
|
|
322
|
+
expect(stage.focus).toBe(holder);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it('clears focus when a nested authored target is replaced and when its ancestor leaves', () => {
|
|
326
|
+
const sandbox = {
|
|
327
|
+
ctx: null, FRAME_RATE: 24, loaded: [], requestAnimationFrame: () => 1,
|
|
328
|
+
addEventListener() {},
|
|
329
|
+
};
|
|
330
|
+
sandbox.window = sandbox;
|
|
331
|
+
const control = { depth: 1, characterId: 2, name: 'control' };
|
|
332
|
+
const timeline = generateTimelineEngine({
|
|
333
|
+
frames: [
|
|
334
|
+
{ places: [{ depth: 1, characterId: 1, name: 'holder' }] },
|
|
335
|
+
{ places: [], removes: [1] },
|
|
336
|
+
],
|
|
337
|
+
characters: {
|
|
338
|
+
1: { type: 'sprite', frames: [
|
|
339
|
+
{ places: [control] },
|
|
340
|
+
{ places: [{ ...control, characterId: 3 }] },
|
|
341
|
+
] },
|
|
342
|
+
2: { type: 'sprite', frames: [{ places: [] }] },
|
|
343
|
+
3: { type: 'sprite', frames: [{ places: [] }] },
|
|
344
|
+
},
|
|
345
|
+
}, { frameCount: 2 });
|
|
346
|
+
const result = runInNewContext(SWFLIB_SOURCE + `
|
|
347
|
+
var { stage, builtins } = __swoof_swflib;
|
|
348
|
+
var main = stage.addChild(new builtins.MovieClip());
|
|
349
|
+
main._swoofHostTimeline = true;
|
|
350
|
+
var root = main;
|
|
351
|
+
window.__swoof = { main, root };
|
|
352
|
+
${timeline}
|
|
353
|
+
timeline.enter();
|
|
354
|
+
({ stage, main, timeline });
|
|
355
|
+
`, sandbox);
|
|
356
|
+
const { stage, main } = result;
|
|
357
|
+
const holder = main.holder, old = holder.control;
|
|
358
|
+
const order = [];
|
|
359
|
+
old.addEventListener('removed', () => order.push('removed'));
|
|
360
|
+
old.addEventListener('removedFromStage', () => order.push('removedFromStage'));
|
|
361
|
+
holder.addEventListener('focusOut', event => {
|
|
362
|
+
order.push('focusOut');
|
|
363
|
+
expect(event.relatedObject).toBeNull();
|
|
364
|
+
expect(stage.focus).toBeNull();
|
|
365
|
+
stage.focus = event.target;
|
|
366
|
+
});
|
|
367
|
+
stage.focus = old;
|
|
368
|
+
holder.gotoAndStop(2);
|
|
369
|
+
const replacement = holder.control;
|
|
370
|
+
expect(replacement).not.toBe(old);
|
|
371
|
+
expect(order).toEqual(['removed', 'focusOut', 'removedFromStage']);
|
|
372
|
+
expect(stage.focus).toBeNull();
|
|
373
|
+
|
|
374
|
+
stage.focus = replacement;
|
|
375
|
+
result.timeline.gotoAndStop(2);
|
|
376
|
+
expect(order).toEqual(['removed', 'focusOut', 'removedFromStage', 'focusOut']);
|
|
377
|
+
expect(stage.focus).toBeNull();
|
|
378
|
+
expect(replacement.stage).toBeNull();
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
it('orders authored and programmatic controls by stage-space focus bounds', () => {
|
|
382
|
+
const listeners = {};
|
|
383
|
+
const sandbox = {
|
|
384
|
+
ctx: null, FRAME_RATE: 24, loaded: [], requestAnimationFrame: () => 1,
|
|
385
|
+
addEventListener: (type, fn) => { (listeners[type] ||= []).push(fn); },
|
|
386
|
+
};
|
|
387
|
+
sandbox.window = sandbox;
|
|
388
|
+
const matrix = (x, y) => ({ a: 1, b: 0, c: 0, d: 1, tx: x * 20, ty: y * 20 });
|
|
389
|
+
const timeline = generateTimelineEngine({
|
|
390
|
+
frames: [{ places: [{ depth: 1, characterId: 1, name: 'holder', matrix: matrix(10, 10) }] }],
|
|
391
|
+
characters: {
|
|
392
|
+
1: { type: 'sprite', frames: [{ places: [
|
|
393
|
+
{ depth: 1, characterId: 2, name: 'authored', matrix: matrix(0, 0) },
|
|
394
|
+
] }] },
|
|
395
|
+
2: { type: 'sprite', frames: [{ places: [{ depth: 1, characterId: 3 }] }] },
|
|
396
|
+
3: { type: 'shape', bounds: { x: 10, y: 0, w: 5, h: 5 } },
|
|
397
|
+
},
|
|
398
|
+
}, { frameCount: 1 });
|
|
399
|
+
const result = runInNewContext(SWFLIB_SOURCE + `
|
|
400
|
+
var { stage, builtins } = __swoof_swflib;
|
|
401
|
+
var main = stage.addChild(new builtins.MovieClip());
|
|
402
|
+
main._swoofHostTimeline = true;
|
|
403
|
+
var root = main;
|
|
404
|
+
window.__swoof = { main, root };
|
|
405
|
+
${timeline}
|
|
406
|
+
timeline.enter();
|
|
407
|
+
var authored = main.holder.authored;
|
|
408
|
+
authored.buttonMode = true;
|
|
409
|
+
function buttonAt(x, y) {
|
|
410
|
+
var clip = main.addChild(new builtins.Sprite());
|
|
411
|
+
clip.buttonMode = true;
|
|
412
|
+
clip.x = x;
|
|
413
|
+
clip.y = y;
|
|
414
|
+
clip.graphics.beginFill(0);
|
|
415
|
+
clip.graphics.drawRect(0, 0, 5, 5);
|
|
416
|
+
return clip;
|
|
417
|
+
}
|
|
418
|
+
var earlier = main.addChild(new builtins.SimpleButton());
|
|
419
|
+
earlier.x = 100;
|
|
420
|
+
earlier.hitTestState = new builtins.Shape();
|
|
421
|
+
earlier.hitTestState.graphics.beginFill(0);
|
|
422
|
+
earlier.hitTestState.graphics.drawRect(-25, 0, 5, 5);
|
|
423
|
+
var equal = buttonAt(80, 0);
|
|
424
|
+
var later = buttonAt(85, 0);
|
|
425
|
+
({ stage, authored, earlier, equal, later });
|
|
426
|
+
`, sandbox);
|
|
427
|
+
const { stage, authored, earlier, equal, later } = result;
|
|
428
|
+
const tab = (shiftKey = false) => listeners.keydown[0]({ key: 'Tab', shiftKey });
|
|
429
|
+
tab();
|
|
430
|
+
expect(stage.focus).toBe(earlier);
|
|
431
|
+
tab();
|
|
432
|
+
expect(stage.focus).toBe(authored);
|
|
433
|
+
tab();
|
|
434
|
+
expect(stage.focus).toBe(later);
|
|
435
|
+
tab(true);
|
|
436
|
+
expect(stage.focus).toBe(authored);
|
|
437
|
+
|
|
438
|
+
equal.tabIndex = 0;
|
|
439
|
+
tab();
|
|
440
|
+
expect(stage.focus).toBe(equal);
|
|
441
|
+
equal.tabIndex = -1;
|
|
442
|
+
authored.parent.tabChildren = false;
|
|
443
|
+
stage.focus = null;
|
|
444
|
+
tab();
|
|
445
|
+
expect(stage.focus).toBe(earlier);
|
|
446
|
+
tab();
|
|
447
|
+
expect(stage.focus).toBe(equal);
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
it('applies SetTabIndex at root and sprite depths and preserves script edits on unchanged frames', () => {
|
|
451
|
+
const tag = (code, ...bytes) => ({ code, data: Uint8Array.of(...bytes) });
|
|
452
|
+
const place = (depth, character, name) => tag(TAG.PlaceObject2, 0x22,
|
|
453
|
+
depth, 0, character, 0, ...Array.from(name, ch => ch.charCodeAt(0)), 0);
|
|
454
|
+
const index = (depth, value) => tag(TAG.SetTabIndex, depth, 0, value & 255, value >> 8);
|
|
455
|
+
const frame = tag(TAG.ShowFrame);
|
|
456
|
+
const symbols = new SymbolTable();
|
|
457
|
+
symbols.set(7, { type: 'Sprite', characterId: 7, frameCount: 3,
|
|
458
|
+
tags: [place(5, 8, 'nested'), index(5, 0), frame, frame, index(5, 2), frame] });
|
|
459
|
+
symbols.set(8, { type: 'Sprite', characterId: 8, frameCount: 1, tags: [frame] });
|
|
460
|
+
const raw = [place(1, 7, 'holder'), place(5, 8, 'peer'), index(5, 259), frame,
|
|
461
|
+
frame, index(5, 4), frame];
|
|
462
|
+
const timeline = generateTimelineEngine(buildDisplayList(raw.map(record => decodeTag(record)), symbols),
|
|
463
|
+
{ frameCount: 3 });
|
|
464
|
+
const listeners = {};
|
|
465
|
+
const sandbox = {
|
|
466
|
+
ctx: null, FRAME_RATE: 24, loaded: [], requestAnimationFrame: () => 1,
|
|
467
|
+
addEventListener: (type, fn) => { (listeners[type] ||= []).push(fn); },
|
|
468
|
+
};
|
|
469
|
+
sandbox.window = sandbox;
|
|
470
|
+
const result = runInNewContext(SWFLIB_SOURCE + `
|
|
471
|
+
var { stage, builtins } = __swoof_swflib;
|
|
472
|
+
var main = stage.addChild(new builtins.MovieClip());
|
|
473
|
+
main._swoofHostTimeline = true;
|
|
474
|
+
var root = main;
|
|
475
|
+
window.__swoof = { main, root };
|
|
476
|
+
${timeline}
|
|
477
|
+
timeline.enter();
|
|
478
|
+
var { holder, peer } = main;
|
|
479
|
+
holder.stop();
|
|
480
|
+
var nested = holder.nested;
|
|
481
|
+
nested.buttonMode = peer.buttonMode = true;
|
|
482
|
+
({ stage, holder, nested, peer, timeline });
|
|
483
|
+
`, sandbox);
|
|
484
|
+
const { stage, holder, nested, peer } = result;
|
|
485
|
+
const tab = () => listeners.keydown[0]({ key: 'Tab' });
|
|
486
|
+
expect([nested.tabIndex, peer.tabIndex]).toEqual([0, 259]);
|
|
487
|
+
tab();
|
|
488
|
+
expect(stage.focus).toBe(nested);
|
|
489
|
+
tab();
|
|
490
|
+
expect(stage.focus).toBe(peer);
|
|
491
|
+
|
|
492
|
+
peer.tabIndex = 8;
|
|
493
|
+
nested.tabIndex = 9;
|
|
494
|
+
result.timeline.gotoAndStop(2);
|
|
495
|
+
holder.gotoAndStop(2);
|
|
496
|
+
expect([nested.tabIndex, peer.tabIndex]).toEqual([9, 8]);
|
|
497
|
+
result.timeline.gotoAndStop(3);
|
|
498
|
+
expect([nested.tabIndex, peer.tabIndex]).toEqual([9, 4]);
|
|
499
|
+
holder.gotoAndStop(3);
|
|
500
|
+
expect([nested.tabIndex, peer.tabIndex]).toEqual([2, 4]);
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
it('bubbles tabIndex and tabEnabled changes only when effective values change', () => {
|
|
504
|
+
const { stage, builtins } = new Function(`${SWFLIB_SOURCE}\nreturn __swoof_swflib;`)();
|
|
505
|
+
const parent = stage.addChild(new builtins.Sprite());
|
|
506
|
+
const button = parent.addChild(new builtins.SimpleButton());
|
|
507
|
+
const received = [];
|
|
508
|
+
for (const type of [builtins.Event.TAB_INDEX_CHANGE, builtins.Event.TAB_ENABLED_CHANGE]) {
|
|
509
|
+
parent.addEventListener(type, event => received.push([
|
|
510
|
+
event.type, event.target, event.bubbles, event.cancelable, button.tabIndex, button.tabEnabled,
|
|
511
|
+
]));
|
|
512
|
+
}
|
|
513
|
+
button.tabIndex = 0;
|
|
514
|
+
button.tabIndex = 0;
|
|
515
|
+
button.tabEnabled = false;
|
|
516
|
+
button.tabEnabled = false;
|
|
517
|
+
button.tabEnabled = true;
|
|
518
|
+
button.tabIndex = -1;
|
|
519
|
+
expect(received).toEqual([
|
|
520
|
+
['tabIndexChange', button, true, false, 0, true],
|
|
521
|
+
['tabEnabledChange', button, true, false, 0, false],
|
|
522
|
+
['tabEnabledChange', button, true, false, 0, true],
|
|
523
|
+
['tabIndexChange', button, true, false, -1, true],
|
|
524
|
+
]);
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
it('updates AVM1 Key and dispatches AS3 KeyboardEvents on the stage', () => {
|
|
528
|
+
const previousWindow = Object.getOwnPropertyDescriptor(globalThis, 'window');
|
|
529
|
+
const listeners = Object.create(null);
|
|
530
|
+
globalThis.window = {
|
|
531
|
+
addEventListener(type, fn) {
|
|
532
|
+
(listeners[type] || (listeners[type] = [])).push(fn);
|
|
533
|
+
},
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
try {
|
|
537
|
+
const runtime = new Function(`${SWFLIB_SOURCE}\nreturn __swoof_swflib;`)();
|
|
538
|
+
const { stage, builtins } = runtime;
|
|
539
|
+
const { Key, KeyboardEvent } = builtins;
|
|
540
|
+
const received = [];
|
|
541
|
+
stage.addEventListener(KeyboardEvent.KEY_DOWN, (event) => received.push(event));
|
|
542
|
+
stage.addEventListener(KeyboardEvent.KEY_UP, (event) => received.push(event));
|
|
543
|
+
|
|
544
|
+
listeners.keydown[0]({ keyCode: 65, key: 'A', shiftKey: true, ctrlKey: false, altKey: false, location: 0 });
|
|
545
|
+
expect(Key.isDown(65)).toBe(true);
|
|
546
|
+
expect(Key.getCode()).toBe(65);
|
|
547
|
+
expect(Key.getAscii()).toBe(65);
|
|
548
|
+
expect(received[0]).toMatchObject({
|
|
549
|
+
type: KeyboardEvent.KEY_DOWN, target: stage,
|
|
550
|
+
keyCode: 65, charCode: 65, shiftKey: true, ctrlKey: false, altKey: false,
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
listeners.keyup[0]({ keyCode: 65, key: 'A', shiftKey: false, ctrlKey: false, altKey: false, location: 0 });
|
|
554
|
+
expect(Key.isDown(65)).toBe(false);
|
|
555
|
+
expect(received[1]).toMatchObject({ type: KeyboardEvent.KEY_UP, keyCode: 65, charCode: 65 });
|
|
556
|
+
|
|
557
|
+
for (const [input, keyCode, charCode] of [
|
|
558
|
+
[{ key: 'ArrowRight', code: 'ArrowRight' }, 39, 0],
|
|
559
|
+
[{ key: 'Space', code: 'Space' }, 32, 32],
|
|
560
|
+
[{ key: '!', code: 'Digit1', shiftKey: true }, 49, 33],
|
|
561
|
+
[{ key: '1', code: 'Numpad1', location: 3 }, 97, 49],
|
|
562
|
+
[{ code: 'KeyZ' }, 90, 0],
|
|
563
|
+
[{ key: '!', code: 'Digit1', keyCode: 88 }, 88, 33],
|
|
564
|
+
[{ key: 'ArrowLeft', keyCode: 0, which: 37 }, 37, 0],
|
|
565
|
+
]) {
|
|
566
|
+
listeners.keydown[0](input);
|
|
567
|
+
expect(Key.isDown(keyCode)).toBe(true);
|
|
568
|
+
expect(Key.getCode()).toBe(keyCode);
|
|
569
|
+
expect(Key.getAscii()).toBe(charCode);
|
|
570
|
+
expect(received.at(-1)).toMatchObject({
|
|
571
|
+
type: KeyboardEvent.KEY_DOWN, keyCode, charCode, keyLocation: input.location ?? 0,
|
|
572
|
+
});
|
|
573
|
+
listeners.keyup[0](input);
|
|
574
|
+
expect(Key.isDown(keyCode)).toBe(false);
|
|
575
|
+
expect(received.at(-1)).toMatchObject({ type: KeyboardEvent.KEY_UP, keyCode, charCode });
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
listeners.keydown[0]({ keyCode: 32, key: ' ', shiftKey: false, ctrlKey: false, altKey: false, location: 0 });
|
|
579
|
+
listeners.blur[0]();
|
|
580
|
+
expect(Key.isDown(32)).toBe(false);
|
|
581
|
+
} finally {
|
|
582
|
+
if (previousWindow) Object.defineProperty(globalThis, 'window', previousWindow);
|
|
583
|
+
else delete globalThis.window;
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
it('paints a yellow keyboard focus rect unless focusRect or stageFocusRect disables it', () => {
|
|
588
|
+
const previousWindow = Object.getOwnPropertyDescriptor(globalThis, 'window');
|
|
589
|
+
globalThis.window = { addEventListener() {} };
|
|
590
|
+
try {
|
|
591
|
+
const runtime = new Function(`${SWFLIB_SOURCE}\nreturn __swoof_swflib;`)();
|
|
592
|
+
const { stage, builtins, renderDisplayTree } = runtime;
|
|
593
|
+
const button = stage.addChild(new builtins.SimpleButton());
|
|
594
|
+
button.width = 40;
|
|
595
|
+
button.height = 20;
|
|
596
|
+
button.x = 8;
|
|
597
|
+
button.y = 12;
|
|
598
|
+
stage.focus = button;
|
|
599
|
+
const strokes = [];
|
|
600
|
+
const ctx = new Proxy({
|
|
601
|
+
canvas: { width: 100, height: 100 },
|
|
602
|
+
globalAlpha: 1,
|
|
603
|
+
strokeRect(x, y, w, h) { strokes.push([x, y, w, h]); },
|
|
604
|
+
}, {
|
|
605
|
+
get(target, key) {
|
|
606
|
+
if (key in target) return target[key];
|
|
607
|
+
if (key === 'strokeStyle' || key === 'lineWidth' || key === 'fillStyle') return '';
|
|
608
|
+
return () => {};
|
|
609
|
+
},
|
|
610
|
+
set(target, key, value) {
|
|
611
|
+
target[key] = value;
|
|
612
|
+
return true;
|
|
613
|
+
},
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
renderDisplayTree(ctx, stage);
|
|
617
|
+
expect(strokes).toEqual([[8, 12, 40, 20]]);
|
|
618
|
+
|
|
619
|
+
strokes.length = 0;
|
|
620
|
+
button.focusRect = false;
|
|
621
|
+
renderDisplayTree(ctx, stage);
|
|
622
|
+
expect(strokes).toEqual([]);
|
|
623
|
+
|
|
624
|
+
button.focusRect = null;
|
|
625
|
+
stage.stageFocusRect = false;
|
|
626
|
+
renderDisplayTree(ctx, stage);
|
|
627
|
+
expect(strokes).toEqual([]);
|
|
628
|
+
|
|
629
|
+
stage.stageFocusRect = true;
|
|
630
|
+
button.focusRect = true;
|
|
631
|
+
renderDisplayTree(ctx, stage);
|
|
632
|
+
expect(strokes).toEqual([[8, 12, 40, 20]]);
|
|
633
|
+
} finally {
|
|
634
|
+
if (previousWindow) Object.defineProperty(globalThis, 'window', previousWindow);
|
|
635
|
+
else delete globalThis.window;
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
it('routes key events through Stage.focus, advances tab focus, and activates buttons', () => {
|
|
640
|
+
const previousWindow = Object.getOwnPropertyDescriptor(globalThis, 'window');
|
|
641
|
+
const listeners = Object.create(null);
|
|
642
|
+
globalThis.window = {
|
|
643
|
+
addEventListener(type, fn) { (listeners[type] || (listeners[type] = [])).push(fn); },
|
|
644
|
+
};
|
|
645
|
+
try {
|
|
646
|
+
const runtime = new Function(`${SWFLIB_SOURCE}\nreturn __swoof_swflib;`)();
|
|
647
|
+
const { stage, builtins } = runtime;
|
|
648
|
+
const first = new builtins.SimpleButton();
|
|
649
|
+
const second = new builtins.SimpleButton();
|
|
650
|
+
stage.addChild(first);
|
|
651
|
+
stage.addChild(second);
|
|
652
|
+
stage.focus = first;
|
|
653
|
+
const keyTargets = [];
|
|
654
|
+
const focusChanges = [];
|
|
655
|
+
first.addEventListener(builtins.KeyboardEvent.KEY_DOWN, event => keyTargets.push(event.target));
|
|
656
|
+
stage.addEventListener(builtins.KeyboardEvent.KEY_DOWN, event => keyTargets.push(event.target));
|
|
657
|
+
first.addEventListener(builtins.FocusEvent.FOCUS_OUT, event => focusChanges.push([event.type, event.target]));
|
|
658
|
+
second.addEventListener(builtins.FocusEvent.FOCUS_IN, event => focusChanges.push([event.type, event.target]));
|
|
659
|
+
|
|
660
|
+
listeners.keydown[0]({ keyCode: 65, key: 'A', preventDefault() {} });
|
|
661
|
+
expect(keyTargets).toEqual([first, first]);
|
|
662
|
+
|
|
663
|
+
keyTargets.length = 0;
|
|
664
|
+
first.mouseEnabled = false;
|
|
665
|
+
listeners.keydown[0]({ keyCode: 66, key: 'B', preventDefault() {} });
|
|
666
|
+
expect(stage.focus).toBe(first);
|
|
667
|
+
expect(keyTargets).toEqual([stage]);
|
|
668
|
+
first.mouseEnabled = true;
|
|
669
|
+
|
|
670
|
+
let prevented = false;
|
|
671
|
+
listeners.keydown[0]({ keyCode: 9, key: 'Tab', preventDefault() { prevented = true; } });
|
|
672
|
+
expect(stage.focus).toBe(second);
|
|
673
|
+
expect(prevented).toBe(true);
|
|
674
|
+
expect(focusChanges).toEqual([
|
|
675
|
+
[builtins.FocusEvent.FOCUS_OUT, first],
|
|
676
|
+
[builtins.FocusEvent.FOCUS_IN, second],
|
|
677
|
+
]);
|
|
678
|
+
|
|
679
|
+
const clicks = [];
|
|
680
|
+
second.addEventListener(builtins.MouseEvent.CLICK, event => clicks.push(event.type));
|
|
681
|
+
listeners.keydown[0]({ key: 'Enter', preventDefault() {} });
|
|
682
|
+
listeners.keyup[0]({ key: 'Enter', preventDefault() {} });
|
|
683
|
+
expect(clicks).toEqual([builtins.MouseEvent.CLICK]);
|
|
684
|
+
|
|
685
|
+
const presses = [];
|
|
686
|
+
second.addEventListener(builtins.MouseEvent.MOUSE_DOWN, () => presses.push('down'));
|
|
687
|
+
second.addEventListener(builtins.MouseEvent.MOUSE_UP, () => presses.push('up'));
|
|
688
|
+
listeners.keydown[0]({ key: ' ' });
|
|
689
|
+
listeners.keydown[0]({ key: ' ', repeat: true });
|
|
690
|
+
listeners.keydown[0]({ key: 'Enter' });
|
|
691
|
+
listeners.keyup[0]({ key: 'Enter' });
|
|
692
|
+
expect(presses).toEqual(['down']);
|
|
693
|
+
listeners.keyup[0]({ key: ' ' });
|
|
694
|
+
expect(presses).toEqual(['down', 'up']);
|
|
695
|
+
expect(clicks).toHaveLength(2);
|
|
696
|
+
|
|
697
|
+
listeners.keydown[0]({ key: 'Enter' });
|
|
698
|
+
stage.focus = first;
|
|
699
|
+
stage.focus = second;
|
|
700
|
+
listeners.keyup[0]({ key: 'Enter' });
|
|
701
|
+
expect(presses).toEqual(['down', 'up', 'down', 'up']);
|
|
702
|
+
expect(clicks).toHaveLength(2);
|
|
703
|
+
|
|
704
|
+
listeners.keydown[0]({ key: 'Enter' });
|
|
705
|
+
listeners.blur[0]();
|
|
706
|
+
listeners.keyup[0]({ key: 'Enter' });
|
|
707
|
+
expect(presses).toEqual(['down', 'up', 'down', 'up', 'down', 'up']);
|
|
708
|
+
expect(clicks).toHaveLength(2);
|
|
709
|
+
} finally {
|
|
710
|
+
if (previousWindow) Object.defineProperty(globalThis, 'window', previousWindow);
|
|
711
|
+
else delete globalThis.window;
|
|
712
|
+
}
|
|
713
|
+
});
|
|
714
|
+
});
|