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,1477 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
3
|
+
|
|
4
|
+
function createHarness(pointerEvents) {
|
|
5
|
+
const canvasListeners = Object.create(null);
|
|
6
|
+
const windowListeners = Object.create(null);
|
|
7
|
+
const canvas = {
|
|
8
|
+
width: 100,
|
|
9
|
+
height: 100,
|
|
10
|
+
style: {},
|
|
11
|
+
addEventListener(type, fn) { (canvasListeners[type] || (canvasListeners[type] = [])).push(fn); },
|
|
12
|
+
getBoundingClientRect() { return { left: 0, top: 0, width: 100, height: 100 }; },
|
|
13
|
+
setPointerCapture(id) { this.capturedPointer = id; },
|
|
14
|
+
};
|
|
15
|
+
const fakeWindow = {
|
|
16
|
+
addEventListener(type, fn) { (windowListeners[type] || (windowListeners[type] = [])).push(fn); },
|
|
17
|
+
};
|
|
18
|
+
if (pointerEvents) fakeWindow.PointerEvent = function PointerEvent() {};
|
|
19
|
+
const stageWrap = { style: {} };
|
|
20
|
+
const body = { style: { cursor: 'crosshair' } };
|
|
21
|
+
const fakeDocument = {
|
|
22
|
+
readyState: 'complete', body,
|
|
23
|
+
getElementById(id) {
|
|
24
|
+
if (id === 'stage-wrap') return stageWrap;
|
|
25
|
+
return id === 'stage' ? canvas : null;
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
const previousWindow = Object.getOwnPropertyDescriptor(globalThis, 'window');
|
|
29
|
+
const previousDocument = Object.getOwnPropertyDescriptor(globalThis, 'document');
|
|
30
|
+
globalThis.window = fakeWindow;
|
|
31
|
+
globalThis.document = fakeDocument;
|
|
32
|
+
try {
|
|
33
|
+
const runtime = new Function(`${SWFLIB_SOURCE}\nreturn __swoof_swflib;`)();
|
|
34
|
+
const { stage, builtins } = runtime;
|
|
35
|
+
const button = new builtins.SimpleButton();
|
|
36
|
+
button.width = 20;
|
|
37
|
+
button.height = 20;
|
|
38
|
+
stage.addChild(button);
|
|
39
|
+
const events = [];
|
|
40
|
+
button.addEventListener(builtins.MouseEvent.MOUSE_DOWN, () => events.push('down'));
|
|
41
|
+
button.addEventListener(builtins.MouseEvent.MOUSE_UP, () => events.push('up'));
|
|
42
|
+
button.addEventListener(builtins.MouseEvent.CLICK, () => events.push('click'));
|
|
43
|
+
return {
|
|
44
|
+
canvas, stageWrap, body, canvasListeners, windowListeners, events, stage, builtins, button, runtime,
|
|
45
|
+
restore() {
|
|
46
|
+
if (previousWindow) Object.defineProperty(globalThis, 'window', previousWindow);
|
|
47
|
+
else delete globalThis.window;
|
|
48
|
+
if (previousDocument) Object.defineProperty(globalThis, 'document', previousDocument);
|
|
49
|
+
else delete globalThis.document;
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (previousWindow) Object.defineProperty(globalThis, 'window', previousWindow);
|
|
54
|
+
else delete globalThis.window;
|
|
55
|
+
if (previousDocument) Object.defineProperty(globalThis, 'document', previousDocument);
|
|
56
|
+
else delete globalThis.document;
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function event(extra = {}) {
|
|
62
|
+
return {
|
|
63
|
+
clientX: 5, clientY: 5, button: 0, buttons: 1,
|
|
64
|
+
preventDefault() { this.prevented = true; },
|
|
65
|
+
...extra,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
describe('AS3 SimpleButton pointer input', () => {
|
|
70
|
+
it('sizes a button from its visible state and picks the transformed children of its separate hit state', () => {
|
|
71
|
+
const harness = createHarness(true);
|
|
72
|
+
try {
|
|
73
|
+
const { stage, builtins: { SimpleButton, Shape, Sprite }, canvasListeners, windowListeners } = harness;
|
|
74
|
+
const state = (left, width) => {
|
|
75
|
+
const container = new Sprite();
|
|
76
|
+
const shape = container.addChild(new Shape());
|
|
77
|
+
shape.x = left;
|
|
78
|
+
shape.graphics.beginFill(0x224466);
|
|
79
|
+
shape.graphics.drawRect(0, 0, width, 10);
|
|
80
|
+
shape.graphics.endFill();
|
|
81
|
+
return container;
|
|
82
|
+
};
|
|
83
|
+
const up = state(2, 30), over = state(2, 20), hit = state(4, 9);
|
|
84
|
+
hit.x = 3;
|
|
85
|
+
const button = stage.addChild(new SimpleButton(up, over, null, hit));
|
|
86
|
+
button.x = 30;
|
|
87
|
+
button.y = 30;
|
|
88
|
+
button.scaleX = 2;
|
|
89
|
+
expect([button.width, button.height]).toEqual([60, 10]);
|
|
90
|
+
expect(button.hitTestPoint(40, 35, true)).toBe(false);
|
|
91
|
+
expect(button.hitTestPoint(50, 35, true)).toBe(true);
|
|
92
|
+
const presses = [];
|
|
93
|
+
button.addEventListener('mouseDown', e => presses.push(e.currentTarget));
|
|
94
|
+
const pointer = event({ clientX: 50, clientY: 35, pointerId: 1, pointerType: 'mouse' });
|
|
95
|
+
canvasListeners.pointermove[0](pointer);
|
|
96
|
+
expect(button.width).toBe(40);
|
|
97
|
+
canvasListeners.pointerdown[0](pointer);
|
|
98
|
+
windowListeners.pointerup[0]({ ...pointer, buttons: 0 });
|
|
99
|
+
expect(presses).toEqual([button]);
|
|
100
|
+
expect(hit.parent).toBeNull();
|
|
101
|
+
} finally {
|
|
102
|
+
harness.restore();
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('drags an AS3 Sprite in parent coordinates until stopped or replaced', () => {
|
|
107
|
+
const harness = createHarness(true);
|
|
108
|
+
try {
|
|
109
|
+
const { stage, builtins: { Sprite, Rectangle }, canvasListeners, windowListeners } = harness;
|
|
110
|
+
const parent = stage.addChild(new Sprite());
|
|
111
|
+
Object.assign(parent, { x: 10, y: 20, scaleX: 2, scaleY: 2 });
|
|
112
|
+
const sprite = parent.addChild(new Sprite());
|
|
113
|
+
Object.assign(sprite, { x: 6, y: 8 });
|
|
114
|
+
const move = (x, y) => canvasListeners.pointermove[0](event({
|
|
115
|
+
clientX: x, clientY: y, pointerId: 1, pointerType: 'mouse', buttons: 0,
|
|
116
|
+
}));
|
|
117
|
+
|
|
118
|
+
move(26, 42);
|
|
119
|
+
const bounds = new Rectangle(5, 6, 15, 14);
|
|
120
|
+
sprite.startDrag(false, bounds);
|
|
121
|
+
bounds.width = 0;
|
|
122
|
+
move(42, 56);
|
|
123
|
+
expect([sprite.x, sprite.y]).toEqual([14, 15]);
|
|
124
|
+
windowListeners.pointerup[0](event({ clientX: 42, clientY: 56, pointerId: 1, pointerType: 'mouse', buttons: 0 }));
|
|
125
|
+
move(89, 92);
|
|
126
|
+
expect([sprite.x, sprite.y]).toEqual([20, 20]);
|
|
127
|
+
|
|
128
|
+
const replacement = parent.addChild(new Sprite());
|
|
129
|
+
replacement.startDrag(true);
|
|
130
|
+
expect([replacement.x, replacement.y]).toEqual([39.5, 36]);
|
|
131
|
+
move(30, 40);
|
|
132
|
+
expect([sprite.x, sprite.y]).toEqual([20, 20]);
|
|
133
|
+
expect([replacement.x, replacement.y]).toEqual([10, 10]);
|
|
134
|
+
replacement.stopDrag();
|
|
135
|
+
move(34, 44);
|
|
136
|
+
expect([replacement.x, replacement.y]).toEqual([10, 10]);
|
|
137
|
+
|
|
138
|
+
replacement.startDrag(true);
|
|
139
|
+
parent.removeChild(replacement);
|
|
140
|
+
parent.addChild(replacement);
|
|
141
|
+
move(50, 60);
|
|
142
|
+
expect([replacement.x, replacement.y]).toEqual([12, 12]);
|
|
143
|
+
} finally {
|
|
144
|
+
harness.restore();
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('keeps Sprite.startDrag tracking after the pointer leaves the canvas', () => {
|
|
149
|
+
const harness = createHarness(true);
|
|
150
|
+
try {
|
|
151
|
+
const { stage, builtins: { Sprite }, canvasListeners, windowListeners, canvas } = harness;
|
|
152
|
+
const sprite = stage.addChild(new Sprite());
|
|
153
|
+
Object.assign(sprite, { x: 10, y: 12 });
|
|
154
|
+
canvasListeners.pointermove[0](event({
|
|
155
|
+
clientX: 20, clientY: 24, pointerId: 1, pointerType: 'mouse', buttons: 0, target: canvas,
|
|
156
|
+
}));
|
|
157
|
+
sprite.startDrag(true);
|
|
158
|
+
expect([sprite.x, sprite.y]).toEqual([20, 24]);
|
|
159
|
+
windowListeners.pointermove[0](event({
|
|
160
|
+
clientX: 70, clientY: 55, pointerId: 1, pointerType: 'mouse', buttons: 0, target: {},
|
|
161
|
+
}));
|
|
162
|
+
expect([sprite.x, sprite.y]).toEqual([70, 55]);
|
|
163
|
+
sprite.stopDrag();
|
|
164
|
+
windowListeners.pointermove[0](event({
|
|
165
|
+
clientX: 5, clientY: 5, pointerId: 1, pointerType: 'mouse', buttons: 0, target: {},
|
|
166
|
+
}));
|
|
167
|
+
expect([sprite.x, sprite.y]).toEqual([70, 55]);
|
|
168
|
+
} finally {
|
|
169
|
+
harness.restore();
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('routes pointer hits through InteractiveObject.hitArea even when that Sprite is invisible', () => {
|
|
174
|
+
const harness = createHarness(true);
|
|
175
|
+
try {
|
|
176
|
+
const { stage, builtins: { Sprite }, canvasListeners, windowListeners, events } = harness;
|
|
177
|
+
const fill = (display, color, w = 40, h = 40) => {
|
|
178
|
+
display.graphics.beginFill(color);
|
|
179
|
+
display.graphics.drawRect(0, 0, w, h);
|
|
180
|
+
display.graphics.endFill();
|
|
181
|
+
};
|
|
182
|
+
const control = stage.addChild(new Sprite());
|
|
183
|
+
control.name = 'control';
|
|
184
|
+
control.x = 10;
|
|
185
|
+
control.y = 10;
|
|
186
|
+
fill(control, 0xff0000, 20, 20);
|
|
187
|
+
const area = stage.addChild(new Sprite());
|
|
188
|
+
area.name = 'area';
|
|
189
|
+
area.x = 60;
|
|
190
|
+
area.y = 10;
|
|
191
|
+
fill(area, 0x00ff00);
|
|
192
|
+
area.visible = false;
|
|
193
|
+
const clicks = [];
|
|
194
|
+
control.addEventListener('click', () => clicks.push('control'));
|
|
195
|
+
area.addEventListener('click', () => clicks.push('area'));
|
|
196
|
+
const click = (x, y) => {
|
|
197
|
+
canvasListeners.pointermove[0](event({
|
|
198
|
+
clientX: x, clientY: y, pointerId: 1, pointerType: 'mouse', buttons: 0,
|
|
199
|
+
}));
|
|
200
|
+
canvasListeners.pointerdown[0](event({
|
|
201
|
+
clientX: x, clientY: y, pointerId: 1, pointerType: 'mouse', buttons: 1,
|
|
202
|
+
}));
|
|
203
|
+
windowListeners.pointerup[0](event({
|
|
204
|
+
clientX: x, clientY: y, pointerId: 1, pointerType: 'mouse', buttons: 0,
|
|
205
|
+
}));
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
click(15, 15);
|
|
209
|
+
expect(clicks).toEqual(['control']);
|
|
210
|
+
|
|
211
|
+
control.hitArea = area;
|
|
212
|
+
click(15, 15);
|
|
213
|
+
expect(clicks).toEqual(['control']);
|
|
214
|
+
click(70, 20);
|
|
215
|
+
expect(clicks).toEqual(['control', 'control']);
|
|
216
|
+
expect(area.visible).toBe(false);
|
|
217
|
+
|
|
218
|
+
area.x = 20;
|
|
219
|
+
click(70, 20);
|
|
220
|
+
expect(clicks).toHaveLength(2);
|
|
221
|
+
click(30, 20);
|
|
222
|
+
expect(clicks).toHaveLength(3);
|
|
223
|
+
|
|
224
|
+
control.hitArea = null;
|
|
225
|
+
click(15, 15);
|
|
226
|
+
expect(clicks).toHaveLength(4);
|
|
227
|
+
click(30, 20);
|
|
228
|
+
expect(clicks).toHaveLength(4);
|
|
229
|
+
} finally {
|
|
230
|
+
harness.restore();
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('updates Sprite.dropTarget under the pointer during startDrag and keeps it after stopDrag', () => {
|
|
235
|
+
const harness = createHarness(true);
|
|
236
|
+
try {
|
|
237
|
+
const { stage, builtins: { Sprite, Shape }, canvasListeners } = harness;
|
|
238
|
+
const fill = (display, color) => {
|
|
239
|
+
display.graphics.beginFill(color);
|
|
240
|
+
display.graphics.drawRect(0, 0, 40, 40);
|
|
241
|
+
display.graphics.endFill();
|
|
242
|
+
};
|
|
243
|
+
const targetA = stage.addChild(new Sprite());
|
|
244
|
+
targetA.name = 'targetA';
|
|
245
|
+
targetA.x = 10;
|
|
246
|
+
targetA.y = 10;
|
|
247
|
+
fill(targetA, 0xff0000);
|
|
248
|
+
const targetB = stage.addChild(new Sprite());
|
|
249
|
+
targetB.name = 'targetB';
|
|
250
|
+
targetB.x = 60;
|
|
251
|
+
targetB.y = 10;
|
|
252
|
+
fill(targetB, 0x00ff00);
|
|
253
|
+
const dragged = stage.addChild(new Sprite());
|
|
254
|
+
dragged.name = 'dragged';
|
|
255
|
+
dragged.x = 0;
|
|
256
|
+
dragged.y = 0;
|
|
257
|
+
fill(dragged, 0x0000ff);
|
|
258
|
+
const move = (x, y) => canvasListeners.pointermove[0](event({
|
|
259
|
+
clientX: x, clientY: y, pointerId: 1, pointerType: 'mouse', buttons: 0,
|
|
260
|
+
}));
|
|
261
|
+
|
|
262
|
+
expect(dragged.dropTarget).toBe(null);
|
|
263
|
+
move(20, 20);
|
|
264
|
+
dragged.startDrag(true);
|
|
265
|
+
expect(dragged.dropTarget).toBe(targetA);
|
|
266
|
+
expect(dragged.dropTarget).not.toBe(dragged);
|
|
267
|
+
|
|
268
|
+
move(70, 20);
|
|
269
|
+
expect(dragged.dropTarget).toBe(targetB);
|
|
270
|
+
|
|
271
|
+
move(5, 80);
|
|
272
|
+
expect(dragged.dropTarget).toBe(null);
|
|
273
|
+
|
|
274
|
+
move(25, 25);
|
|
275
|
+
expect(dragged.dropTarget).toBe(targetA);
|
|
276
|
+
dragged.stopDrag();
|
|
277
|
+
move(70, 20);
|
|
278
|
+
expect(dragged.dropTarget).toBe(targetA);
|
|
279
|
+
|
|
280
|
+
const shapeSkin = stage.addChild(new Shape());
|
|
281
|
+
shapeSkin.x = 100;
|
|
282
|
+
shapeSkin.y = 10;
|
|
283
|
+
fill(shapeSkin, 0xffff00);
|
|
284
|
+
dragged.startDrag(true);
|
|
285
|
+
move(110, 20);
|
|
286
|
+
expect(dragged.dropTarget).toBe(shapeSkin);
|
|
287
|
+
} finally {
|
|
288
|
+
harness.restore();
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it('routes tip and eraser contacts with stable touch intent while leaving pen hover out', () => {
|
|
293
|
+
const harness = createHarness(true);
|
|
294
|
+
try {
|
|
295
|
+
const { button, builtins, canvasListeners, windowListeners, events } = harness;
|
|
296
|
+
const { Multitouch, TouchEventIntent } = builtins;
|
|
297
|
+
const contacts = [];
|
|
298
|
+
for (const type of ['touchBegin', 'touchMove', 'touchEnd']) {
|
|
299
|
+
button.addEventListener(type, touch => contacts.push(touch));
|
|
300
|
+
}
|
|
301
|
+
function send(type, id, buttons, extra = {}) {
|
|
302
|
+
const callbacks = type === 'pointerup' ? windowListeners : canvasListeners;
|
|
303
|
+
callbacks[type][0](event({ pointerType: 'pen', pointerId: id, buttons, ...extra }));
|
|
304
|
+
}
|
|
305
|
+
send('pointerdown', 9, 1);
|
|
306
|
+
send('pointerup', 9, 0);
|
|
307
|
+
expect(events.splice(0)).toEqual(['down', 'up', 'click']);
|
|
308
|
+
expect(contacts).toEqual([]);
|
|
309
|
+
|
|
310
|
+
Multitouch.inputMode = 'touchPoint';
|
|
311
|
+
Multitouch.mapTouchToMouse = false;
|
|
312
|
+
send('pointermove', 9, 0);
|
|
313
|
+
send('pointerdown', 9, 2, { button: 2 });
|
|
314
|
+
send('pointerup', 9, 0, { button: 2 });
|
|
315
|
+
send('pointerdown', 9, 1, { pressure: 0.25 });
|
|
316
|
+
send('pointermove', 9, 3, { pressure: 0.75 });
|
|
317
|
+
send('pointerup', 9, 0, { pressure: 0 });
|
|
318
|
+
send('pointerdown', 10, 32, { button: 5 });
|
|
319
|
+
send('pointerup', 10, 0, { button: 5 });
|
|
320
|
+
expect(events).toEqual([]);
|
|
321
|
+
expect(contacts.map(e => [e.type, e.touchPointID, e.touchIntent])).toEqual([
|
|
322
|
+
['touchBegin', 9, TouchEventIntent.PEN], ['touchMove', 9, TouchEventIntent.PEN],
|
|
323
|
+
['touchEnd', 9, TouchEventIntent.PEN], ['touchBegin', 10, TouchEventIntent.ERASER],
|
|
324
|
+
['touchEnd', 10, TouchEventIntent.ERASER],
|
|
325
|
+
]);
|
|
326
|
+
expect(contacts[1].pressure).toBe(0.75);
|
|
327
|
+
expect(contacts[4].clone().touchIntent).toBe(TouchEventIntent.ERASER);
|
|
328
|
+
} finally {
|
|
329
|
+
harness.restore();
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('routes stylus proximity hover separately from tip contact in touchPoint mode', () => {
|
|
334
|
+
const harness = createHarness(true);
|
|
335
|
+
try {
|
|
336
|
+
const { button, builtins, canvasListeners, windowListeners } = harness;
|
|
337
|
+
const { Multitouch, TouchEvent, TouchEventIntent } = builtins;
|
|
338
|
+
const proximity = [];
|
|
339
|
+
const contacts = [];
|
|
340
|
+
for (const type of [
|
|
341
|
+
TouchEvent.PROXIMITY_BEGIN, TouchEvent.PROXIMITY_MOVE, TouchEvent.PROXIMITY_END,
|
|
342
|
+
TouchEvent.PROXIMITY_OVER, TouchEvent.PROXIMITY_OUT,
|
|
343
|
+
]) {
|
|
344
|
+
button.addEventListener(type, event => proximity.push(event));
|
|
345
|
+
}
|
|
346
|
+
for (const type of [TouchEvent.TOUCH_BEGIN, TouchEvent.TOUCH_END]) {
|
|
347
|
+
button.addEventListener(type, event => contacts.push(event.type));
|
|
348
|
+
}
|
|
349
|
+
function send(type, buttons, extra = {}) {
|
|
350
|
+
const callbacks = type === 'pointerup' || type === 'pointerleave' ? windowListeners : canvasListeners;
|
|
351
|
+
const list = callbacks[type] || canvasListeners[type];
|
|
352
|
+
list[0](event({ pointerType: 'pen', pointerId: 3, buttons, ...extra }));
|
|
353
|
+
}
|
|
354
|
+
Multitouch.inputMode = 'touchPoint';
|
|
355
|
+
Multitouch.mapTouchToMouse = false;
|
|
356
|
+
send('pointermove', 0);
|
|
357
|
+
send('pointermove', 0, { pressure: 0.1 });
|
|
358
|
+
send('pointerdown', 1, { pressure: 0.4 });
|
|
359
|
+
send('pointerup', 0, { pressure: 0 });
|
|
360
|
+
canvasListeners.pointerleave[0](event({ pointerType: 'pen', pointerId: 3, buttons: 0 }));
|
|
361
|
+
expect(contacts).toEqual(['touchBegin', 'touchEnd']);
|
|
362
|
+
expect(proximity.map(e => [e.type, e.touchPointID, e.touchIntent])).toEqual([
|
|
363
|
+
[TouchEvent.PROXIMITY_OVER, 3, TouchEventIntent.PEN],
|
|
364
|
+
[TouchEvent.PROXIMITY_BEGIN, 3, TouchEventIntent.PEN],
|
|
365
|
+
[TouchEvent.PROXIMITY_MOVE, 3, TouchEventIntent.PEN],
|
|
366
|
+
[TouchEvent.PROXIMITY_END, 3, TouchEventIntent.PEN],
|
|
367
|
+
[TouchEvent.PROXIMITY_OUT, 3, TouchEventIntent.PEN],
|
|
368
|
+
[TouchEvent.PROXIMITY_OVER, 3, TouchEventIntent.PEN],
|
|
369
|
+
[TouchEvent.PROXIMITY_BEGIN, 3, TouchEventIntent.PEN],
|
|
370
|
+
[TouchEvent.PROXIMITY_END, 3, TouchEventIntent.PEN],
|
|
371
|
+
[TouchEvent.PROXIMITY_OUT, 3, TouchEventIntent.PEN],
|
|
372
|
+
]);
|
|
373
|
+
} finally {
|
|
374
|
+
harness.restore();
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it('writes coalesced touch samples as stage-position and pressure float triples', () => {
|
|
379
|
+
const harness = createHarness(true);
|
|
380
|
+
try {
|
|
381
|
+
const { button, builtins, canvas, canvasListeners } = harness;
|
|
382
|
+
const { Multitouch, TouchEvent, ByteArray, Endian } = builtins;
|
|
383
|
+
Multitouch.inputMode = 'touchPoint';
|
|
384
|
+
Multitouch.mapTouchToMouse = false;
|
|
385
|
+
canvas.getBoundingClientRect = () => ({ left: 10, top: 20, width: 200, height: 200 });
|
|
386
|
+
button.x = 2;
|
|
387
|
+
const moves = [], begins = [];
|
|
388
|
+
button.addEventListener('touchMove', event => moves.push(event));
|
|
389
|
+
button.addEventListener('touchBegin', event => begins.push(event));
|
|
390
|
+
const contact = (x, y, extra) => event({ pointerType: 'touch', pointerId: 5, clientX: x, clientY: y, ...extra });
|
|
391
|
+
canvasListeners.pointerdown[0](contact(18, 28));
|
|
392
|
+
const intermediate = { pointerId: 5, clientX: 20, clientY: 30, pressure: 0.25 };
|
|
393
|
+
canvasListeners.pointermove[0](contact(30, 40, {
|
|
394
|
+
pressure: 0.5,
|
|
395
|
+
getCoalescedEvents: () => [intermediate, { pointerId: 6, clientX: 22, clientY: 32, pressure: 0.75 }],
|
|
396
|
+
}));
|
|
397
|
+
intermediate.clientX = 150;
|
|
398
|
+
canvasListeners.pointermove[0](contact(31, 40));
|
|
399
|
+
canvasListeners.pointermove[0](contact(32, 42, {
|
|
400
|
+
pressure: 0.75, getCoalescedEvents: () => [contact(32, 42, { pressure: 0.75 })],
|
|
401
|
+
}));
|
|
402
|
+
expect(moves[0]).toMatchObject({ target: button, stageX: 10, localX: 8, touchPointID: 5 });
|
|
403
|
+
const result = new ByteArray();
|
|
404
|
+
result.endian = Endian.LITTLE_ENDIAN;
|
|
405
|
+
result.writeByte(0xa5);
|
|
406
|
+
expect(moves[0].clone().getSamples(result, true)).toBe(2);
|
|
407
|
+
expect([result.position, result.length]).toEqual([25, 25]);
|
|
408
|
+
expect(Array.from(result._getU8().slice(1, 5))).toEqual([0, 0, 160, 64]);
|
|
409
|
+
result.position = 0;
|
|
410
|
+
expect(result.readUnsignedByte()).toBe(0xa5);
|
|
411
|
+
const read = count => Array.from({ length: count }, () => result.readFloat());
|
|
412
|
+
expect(read(6)).toEqual([5, 5, 0.25, 10, 10, 0.5]);
|
|
413
|
+
expect(moves[1].getSamples(result)).toBe(1);
|
|
414
|
+
expect([result.position, result.length]).toEqual([12, 12]);
|
|
415
|
+
result.position = 0;
|
|
416
|
+
expect(read(3)).toEqual([10.5, 10, 1]);
|
|
417
|
+
expect(moves[2].getSamples(result)).toBe(1);
|
|
418
|
+
result.position = 0;
|
|
419
|
+
expect(read(3)).toEqual([11, 11, 0.75]);
|
|
420
|
+
expect(begins[0].getSamples(result)).toBe(0);
|
|
421
|
+
expect([result.position, result.length]).toEqual([0, 0]);
|
|
422
|
+
|
|
423
|
+
result.writeFloat(12);
|
|
424
|
+
result.writeFloat(16);
|
|
425
|
+
result.writeFloat(0.5);
|
|
426
|
+
const scripted = new TouchEvent('touchMove', true, false, 7, true, 12, 16, 1, 1, 0.5,
|
|
427
|
+
null, false, false, false, false, false, 0, null, result, false);
|
|
428
|
+
expect(result.position).toBe(12);
|
|
429
|
+
result.clear();
|
|
430
|
+
expect(scripted.clone().getSamples(result)).toBe(1);
|
|
431
|
+
result.position = 0;
|
|
432
|
+
expect(read(3)).toEqual([12, 16, 0.5]);
|
|
433
|
+
} finally {
|
|
434
|
+
harness.restore();
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it('reports separate press and tap positions and rejects conflicts and cancellation', () => {
|
|
439
|
+
const harness = createHarness(true);
|
|
440
|
+
try {
|
|
441
|
+
const { button, builtins, stage, canvasListeners, windowListeners } = harness;
|
|
442
|
+
const { Multitouch, GestureEvent, PressAndTapGestureEvent } = builtins;
|
|
443
|
+
Multitouch.mapTouchToMouse = false;
|
|
444
|
+
button.x = 2;
|
|
445
|
+
button.scaleX = 2;
|
|
446
|
+
const taps = [], otherGestures = [];
|
|
447
|
+
stage.addEventListener(PressAndTapGestureEvent.GESTURE_PRESS_AND_TAP, event => taps.push(event));
|
|
448
|
+
for (const type of ['gestureTwoFingerTap', 'gesturePan', 'gestureZoom']) {
|
|
449
|
+
stage.addEventListener(type, event => otherGestures.push(event.type));
|
|
450
|
+
}
|
|
451
|
+
function contact(type, id, x, timeStamp) {
|
|
452
|
+
const listeners = type === 'pointerdown' || type === 'pointermove' ? canvasListeners : windowListeners;
|
|
453
|
+
listeners[type][0](event({ pointerType: 'touch', pointerId: id, clientX: x, timeStamp, isPrimary: id === 1 }));
|
|
454
|
+
}
|
|
455
|
+
contact('pointerdown', 1, 10, 100);
|
|
456
|
+
contact('pointerdown', 2, 22, 420);
|
|
457
|
+
contact('pointerup', 2, 24, 450);
|
|
458
|
+
expect(taps).toHaveLength(1);
|
|
459
|
+
expect(taps[0]).toBeInstanceOf(GestureEvent);
|
|
460
|
+
expect(taps[0].clone()).toBeInstanceOf(PressAndTapGestureEvent);
|
|
461
|
+
expect(taps[0]).toMatchObject({ phase: 'all', target: button, bubbles: true, stageX: 10,
|
|
462
|
+
localX: 4, tapStageX: 24, tapLocalX: 11 });
|
|
463
|
+
contact('pointerup', 1, 10, 490);
|
|
464
|
+
expect(otherGestures).toEqual([]);
|
|
465
|
+
|
|
466
|
+
contact('pointerdown', 1, 10, 1000);
|
|
467
|
+
contact('pointerdown', 2, 22, 1320);
|
|
468
|
+
contact('pointerup', 1, 10, 1350);
|
|
469
|
+
contact('pointerup', 2, 22, 1380);
|
|
470
|
+
contact('pointerdown', 1, 10, 2000);
|
|
471
|
+
contact('pointerdown', 2, 22, 2320);
|
|
472
|
+
contact('pointercancel', 2, 22, 2340);
|
|
473
|
+
contact('pointerup', 1, 10, 2350);
|
|
474
|
+
contact('pointerdown', 1, 10, 3000);
|
|
475
|
+
contact('pointerdown', 2, 22, 3320);
|
|
476
|
+
contact('pointermove', 2, 35, 3350);
|
|
477
|
+
contact('pointerup', 2, 22, 3380);
|
|
478
|
+
contact('pointerup', 1, 10, 3400);
|
|
479
|
+
expect(otherGestures).toContain('gesturePan');
|
|
480
|
+
expect(otherGestures).not.toContain('gestureTwoFingerTap');
|
|
481
|
+
expect(taps).toHaveLength(1);
|
|
482
|
+
} finally {
|
|
483
|
+
harness.restore();
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
it('reports a cardinal single-contact swipe on its initial target and excludes multi-contact gestures', () => {
|
|
488
|
+
const harness = createHarness(true);
|
|
489
|
+
try {
|
|
490
|
+
const { button, builtins, stage, canvasListeners, windowListeners } = harness;
|
|
491
|
+
const { Multitouch, TransformGestureEvent } = builtins;
|
|
492
|
+
Multitouch.mapTouchToMouse = false;
|
|
493
|
+
button.width = button.height = 100;
|
|
494
|
+
const seen = [];
|
|
495
|
+
stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE, event => seen.push(event));
|
|
496
|
+
function contact(type, id, x, y, timeStamp) {
|
|
497
|
+
const listeners = type === 'pointerdown' || type === 'pointermove' ? canvasListeners : windowListeners;
|
|
498
|
+
listeners[type][0](event({ pointerType: 'touch', pointerId: id, clientX: x, clientY: y, timeStamp, isPrimary: id === 1 }));
|
|
499
|
+
}
|
|
500
|
+
const samples = [[50, 5, 110, 5], [80, 10, 10, 10], [15, 10, 15, 70], [15, 90, 15, 30]];
|
|
501
|
+
for (const [sx, sy, ex, ey] of samples) {
|
|
502
|
+
contact('pointerdown', 1, sx, sy, 100);
|
|
503
|
+
contact('pointerup', 1, ex, ey, 200);
|
|
504
|
+
}
|
|
505
|
+
expect(seen.map(e => [e.offsetX, e.offsetY])).toEqual([[1, 0], [-1, 0], [0, 1], [0, -1]]);
|
|
506
|
+
expect(seen[0]).toBeInstanceOf(TransformGestureEvent);
|
|
507
|
+
expect(seen[0]).toMatchObject({ phase: 'all', target: button, stageX: 110, localX: 110,
|
|
508
|
+
scaleX: 1, scaleY: 1, rotation: 0, velocity: 600, bubbles: true, cancelable: false });
|
|
509
|
+
|
|
510
|
+
contact('pointerdown', 1, 10, 20, 1000);
|
|
511
|
+
contact('pointerup', 1, 80, 20, 1600);
|
|
512
|
+
contact('pointerdown', 1, 10, 20, 2000);
|
|
513
|
+
contact('pointerup', 1, 80, 90, 2100);
|
|
514
|
+
contact('pointerdown', 1, 10, 20, 3000);
|
|
515
|
+
contact('pointermove', 1, 80, 20, 3100);
|
|
516
|
+
contact('pointercancel', 1, 80, 20, 3200);
|
|
517
|
+
contact('pointerdown', 1, 10, 20, 4000);
|
|
518
|
+
contact('pointerdown', 2, 20, 20, 4020);
|
|
519
|
+
contact('pointerup', 2, 20, 20, 4050);
|
|
520
|
+
contact('pointermove', 1, 80, 20, 4080);
|
|
521
|
+
contact('pointerup', 1, 80, 20, 4090);
|
|
522
|
+
expect(seen).toHaveLength(4);
|
|
523
|
+
} finally {
|
|
524
|
+
harness.restore();
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
it('reports one bubbling gesture for a short two-finger tap and ignores invalid pairs', () => {
|
|
529
|
+
const harness = createHarness(true);
|
|
530
|
+
try {
|
|
531
|
+
const { button, builtins, stage, canvasListeners, windowListeners } = harness;
|
|
532
|
+
const { GestureEvent, Multitouch } = builtins;
|
|
533
|
+
Multitouch.mapTouchToMouse = false;
|
|
534
|
+
const seen = [];
|
|
535
|
+
stage.addEventListener(GestureEvent.GESTURE_TWO_FINGER_TAP, gesture => seen.push(gesture));
|
|
536
|
+
function contact(type, id, x, timeStamp) {
|
|
537
|
+
const listeners = type === 'pointerdown' || type === 'pointermove' ? canvasListeners : windowListeners;
|
|
538
|
+
listeners[type][0](event({ pointerType: 'touch', pointerId: id, clientX: x, timeStamp, isPrimary: id === 1 }));
|
|
539
|
+
}
|
|
540
|
+
contact('pointerdown', 1, 4, 0);
|
|
541
|
+
contact('pointerdown', 2, 12, 20);
|
|
542
|
+
contact('pointermove', 1, 5, 40);
|
|
543
|
+
contact('pointerup', 2, 12, 60);
|
|
544
|
+
expect(seen).toEqual([]);
|
|
545
|
+
contact('pointerup', 1, 6, 80);
|
|
546
|
+
expect(seen).toHaveLength(1);
|
|
547
|
+
expect(seen[0]).toBeInstanceOf(GestureEvent);
|
|
548
|
+
expect(seen[0]).toMatchObject({ phase: 'all', target: button, bubbles: true, stageX: 9, localX: 9 });
|
|
549
|
+
expect(seen[0].clone().stageX).toBe(9);
|
|
550
|
+
|
|
551
|
+
contact('pointerdown', 1, 4, 100);
|
|
552
|
+
contact('pointerdown', 2, 12, 110);
|
|
553
|
+
contact('pointermove', 1, 15, 130);
|
|
554
|
+
contact('pointerup', 1, 4, 140);
|
|
555
|
+
contact('pointerup', 2, 12, 150);
|
|
556
|
+
contact('pointerdown', 1, 4, 200);
|
|
557
|
+
contact('pointerdown', 2, 12, 220);
|
|
558
|
+
contact('pointerup', 2, 12, 230);
|
|
559
|
+
contact('pointercancel', 1, 4, 250);
|
|
560
|
+
contact('pointerdown', 1, 4, 300);
|
|
561
|
+
contact('pointerdown', 2, 12, 500);
|
|
562
|
+
contact('pointerup', 1, 4, 530);
|
|
563
|
+
contact('pointerup', 2, 12, 550);
|
|
564
|
+
contact('pointerdown', 1, 4, 600);
|
|
565
|
+
contact('pointerdown', 2, 12, 620);
|
|
566
|
+
contact('pointerup', 1, 4, 650);
|
|
567
|
+
contact('pointerup', 2, 12, 1300);
|
|
568
|
+
contact('pointerdown', 1, 4, 1400);
|
|
569
|
+
contact('pointerdown', 2, 12, 1410);
|
|
570
|
+
contact('pointerdown', 3, 16, 1420);
|
|
571
|
+
contact('pointerup', 3, 16, 1430);
|
|
572
|
+
contact('pointerup', 2, 12, 1440);
|
|
573
|
+
contact('pointerup', 1, 4, 1450);
|
|
574
|
+
contact('pointerdown', 1, 4, 1500);
|
|
575
|
+
contact('pointerdown', 2, 12, 1510);
|
|
576
|
+
Multitouch.inputMode = 'touchPoint';
|
|
577
|
+
contact('pointerup', 1, 4, 1520);
|
|
578
|
+
contact('pointerup', 2, 12, 1530);
|
|
579
|
+
expect(seen).toHaveLength(1);
|
|
580
|
+
} finally {
|
|
581
|
+
harness.restore();
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
it('drags one sprite by its active touch ID within transformed parent bounds', () => {
|
|
586
|
+
const harness = createHarness(true);
|
|
587
|
+
try {
|
|
588
|
+
const { stage, builtins, canvasListeners, windowListeners } = harness;
|
|
589
|
+
const { Sprite, Rectangle, Multitouch } = builtins;
|
|
590
|
+
Multitouch.inputMode = 'touchPoint';
|
|
591
|
+
Multitouch.mapTouchToMouse = false;
|
|
592
|
+
const parent = stage.addChild(new Sprite());
|
|
593
|
+
parent.x = 20;
|
|
594
|
+
parent.scaleX = 2;
|
|
595
|
+
const sprite = parent.addChild(new Sprite());
|
|
596
|
+
sprite.x = 10;
|
|
597
|
+
sprite.y = 10;
|
|
598
|
+
const other = parent.addChild(new Sprite());
|
|
599
|
+
function contact(type, id, x, y) {
|
|
600
|
+
const listeners = type === 'pointerdown' || type === 'pointermove' ? canvasListeners : windowListeners;
|
|
601
|
+
listeners[type][0](event({ pointerId: id, pointerType: 'touch', clientX: x, clientY: y }));
|
|
602
|
+
}
|
|
603
|
+
stage.addEventListener('touchBegin', event => {
|
|
604
|
+
if (event.touchPointID === 1) sprite.startTouchDrag(event.touchPointID, false, new Rectangle(5, 6, 25, 20));
|
|
605
|
+
});
|
|
606
|
+
contact('pointerdown', 1, 45, 12);
|
|
607
|
+
expect([sprite.x, sprite.y]).toEqual([10, 10]);
|
|
608
|
+
contact('pointermove', 1, 60, 22);
|
|
609
|
+
expect([sprite.x, sprite.y]).toEqual([17.5, 20]);
|
|
610
|
+
contact('pointermove', 1, 90, 40);
|
|
611
|
+
expect([sprite.x, sprite.y]).toEqual([30, 26]);
|
|
612
|
+
contact('pointerdown', 2, 50, 7);
|
|
613
|
+
contact('pointermove', 2, 55, 12);
|
|
614
|
+
expect([sprite.x, sprite.y]).toEqual([30, 26]);
|
|
615
|
+
sprite.stopTouchDrag(2);
|
|
616
|
+
contact('pointermove', 1, 42, 9);
|
|
617
|
+
expect([sprite.x, sprite.y]).toEqual([8.5, 7]);
|
|
618
|
+
other.startTouchDrag(2, true);
|
|
619
|
+
expect([other.x, other.y]).toEqual([17.5, 12]);
|
|
620
|
+
contact('pointermove', 1, 70, 50);
|
|
621
|
+
expect([sprite.x, sprite.y]).toEqual([8.5, 7]);
|
|
622
|
+
contact('pointercancel', 2, 90, 45);
|
|
623
|
+
contact('pointermove', 2, 65, 15);
|
|
624
|
+
expect([other.x, other.y]).toEqual([17.5, 12]);
|
|
625
|
+
other.startTouchDrag(1, true);
|
|
626
|
+
other.stopTouchDrag(1);
|
|
627
|
+
contact('pointermove', 1, 44, 11);
|
|
628
|
+
expect([other.x, other.y]).toEqual([25, 50]);
|
|
629
|
+
} finally {
|
|
630
|
+
harness.restore();
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
it('dispatches touch roll transitions per contact without bubbling and taps only a short same-target contact', () => {
|
|
635
|
+
const harness = createHarness(true);
|
|
636
|
+
try {
|
|
637
|
+
const { button, builtins, canvasListeners, windowListeners, stage } = harness;
|
|
638
|
+
const { Multitouch, SimpleButton } = builtins;
|
|
639
|
+
Multitouch.inputMode = 'touchPoint';
|
|
640
|
+
Multitouch.mapTouchToMouse = false;
|
|
641
|
+
button.name = 'first';
|
|
642
|
+
const other = stage.addChild(new SimpleButton());
|
|
643
|
+
other.name = 'other';
|
|
644
|
+
other.x = 30;
|
|
645
|
+
other.width = other.height = 20;
|
|
646
|
+
const events = [];
|
|
647
|
+
const record = e => events.push([e.type, e.touchPointID, e.target.name, e.relatedObject?.name, e.bubbles]);
|
|
648
|
+
for (const type of ['touchOver', 'touchOut', 'touchRollOver', 'touchRollOut', 'touchTap']) {
|
|
649
|
+
stage.addEventListener(type, record);
|
|
650
|
+
}
|
|
651
|
+
for (const clip of [button, other]) {
|
|
652
|
+
clip.addEventListener('touchRollOver', record);
|
|
653
|
+
clip.addEventListener('touchRollOut', record);
|
|
654
|
+
}
|
|
655
|
+
function contact(type, id, x, timeStamp) {
|
|
656
|
+
const handlers = type === 'pointerdown' || type === 'pointermove' ? canvasListeners : windowListeners;
|
|
657
|
+
handlers[type][0](event({ pointerType: 'touch', pointerId: id, clientX: x, timeStamp }));
|
|
658
|
+
}
|
|
659
|
+
contact('pointerdown', 1, 5, 0);
|
|
660
|
+
contact('pointerdown', 2, 35, 0);
|
|
661
|
+
contact('pointermove', 1, 35, 10);
|
|
662
|
+
expect(events.splice(0)).toEqual([
|
|
663
|
+
['touchRollOver', 1, 'first', undefined, false], ['touchOver', 1, 'first', undefined, true],
|
|
664
|
+
['touchRollOver', 2, 'other', undefined, false], ['touchOver', 2, 'other', undefined, true],
|
|
665
|
+
['touchOut', 1, 'first', 'other', true], ['touchRollOut', 1, 'first', 'other', false],
|
|
666
|
+
['touchRollOver', 1, 'other', 'first', false], ['touchOver', 1, 'other', 'first', true],
|
|
667
|
+
]);
|
|
668
|
+
contact('pointercancel', 2, 35, 20);
|
|
669
|
+
contact('pointerup', 1, 5, 30);
|
|
670
|
+
contact('pointerdown', 3, 5, 100);
|
|
671
|
+
contact('pointerup', 3, 6, 150);
|
|
672
|
+
contact('pointerdown', 4, 5, 200);
|
|
673
|
+
contact('pointerup', 4, 5, 1000);
|
|
674
|
+
expect(events.filter(e => e[0] === 'touchTap')).toEqual([['touchTap', 3, 'first', undefined, true]]);
|
|
675
|
+
expect(events.slice(0, 2)).toEqual([
|
|
676
|
+
['touchOut', 2, 'other', undefined, true], ['touchRollOut', 2, 'other', undefined, false],
|
|
677
|
+
]);
|
|
678
|
+
expect(stage.focus).toBeNull();
|
|
679
|
+
} finally {
|
|
680
|
+
harness.restore();
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
it('keeps a two-contact gesture targeted and uses incremental transform phases', () => {
|
|
685
|
+
const harness = createHarness(true);
|
|
686
|
+
try {
|
|
687
|
+
const { button, stage, builtins, canvasListeners, windowListeners, events } = harness;
|
|
688
|
+
const { GestureEvent, Multitouch, TransformGestureEvent } = builtins;
|
|
689
|
+
button.width = 27;
|
|
690
|
+
Multitouch.mapTouchToMouse = false;
|
|
691
|
+
const samples = [];
|
|
692
|
+
const types = ['gesturePan', 'gestureZoom', 'gestureRotate'];
|
|
693
|
+
for (const type of types) stage.addEventListener(type, gesture => samples.push(gesture));
|
|
694
|
+
function contact(type, id, x, y) {
|
|
695
|
+
const listeners = type === 'pointerup' ? windowListeners : canvasListeners;
|
|
696
|
+
listeners[type][0](event({ pointerType: 'touch', pointerId: id, isPrimary: id === 1, clientX: x, clientY: y }));
|
|
697
|
+
}
|
|
698
|
+
contact('pointerdown', 1, 5, 5);
|
|
699
|
+
contact('pointerdown', 2, 15, 5);
|
|
700
|
+
expect(samples).toEqual([]);
|
|
701
|
+
contact('pointermove', 2, 25, 5);
|
|
702
|
+
contact('pointermove', 2, 5, 25);
|
|
703
|
+
contact('pointermove', 2, 5, 45);
|
|
704
|
+
contact('pointerup', 1, 5, 5);
|
|
705
|
+
contact('pointerup', 2, 5, 45);
|
|
706
|
+
expect(samples.every(e => e.target === button && e instanceof TransformGestureEvent && e instanceof GestureEvent)).toBe(true);
|
|
707
|
+
expect(samples.map(e => [e.type, e.phase, e.scaleX, e.rotation, e.offsetX, e.offsetY])).toEqual([
|
|
708
|
+
['gesturePan', 'begin', 1, 0, 5, 0], ['gestureZoom', 'begin', 2, 0, 0, 0],
|
|
709
|
+
['gesturePan', 'update', 1, 0, -10, 10], ['gestureRotate', 'begin', 1, 90, 0, 0],
|
|
710
|
+
['gesturePan', 'update', 1, 0, 0, 10], ['gestureZoom', 'update', 2, 0, 0, 0],
|
|
711
|
+
['gesturePan', 'end', 1, 0, 0, 0], ['gestureZoom', 'end', 1, 0, 0, 0], ['gestureRotate', 'end', 1, 0, 0, 0],
|
|
712
|
+
]);
|
|
713
|
+
expect(samples[5].clone()).toMatchObject({ stageX: 5, stageY: 25, scaleY: 2, phase: 'update' });
|
|
714
|
+
expect(events).toEqual([]);
|
|
715
|
+
expect(stage.focus).toBeNull();
|
|
716
|
+
} finally {
|
|
717
|
+
harness.restore();
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
|
|
721
|
+
it('routes simultaneous touch IDs by current position and flags canceled touch ends', () => {
|
|
722
|
+
const harness = createHarness(true);
|
|
723
|
+
try {
|
|
724
|
+
const { button, builtins, stage, canvasListeners, windowListeners, events } = harness;
|
|
725
|
+
const { Multitouch, MultitouchInputMode, SimpleButton, TouchEvent } = builtins;
|
|
726
|
+
const other = stage.addChild(new SimpleButton());
|
|
727
|
+
other.x = 30;
|
|
728
|
+
other.width = other.height = 20;
|
|
729
|
+
const collected = [];
|
|
730
|
+
for (const type of [TouchEvent.TOUCH_BEGIN, TouchEvent.TOUCH_MOVE, TouchEvent.TOUCH_END]) {
|
|
731
|
+
stage.addEventListener(type, touch => collected.push(touch));
|
|
732
|
+
}
|
|
733
|
+
const sample = (id, x, extra) => event({
|
|
734
|
+
pointerId: id, pointerType: 'touch', isPrimary: id === 11,
|
|
735
|
+
clientX: x, width: 9, height: 6, pressure: 0.75, ...extra,
|
|
736
|
+
});
|
|
737
|
+
expect(Multitouch.inputMode).toBe(MultitouchInputMode.GESTURE);
|
|
738
|
+
canvasListeners.pointerdown[0](sample(11, 5));
|
|
739
|
+
windowListeners.pointerup[0](sample(11, 5));
|
|
740
|
+
expect(collected).toEqual([]);
|
|
741
|
+
expect(events.splice(0)).toEqual(['down', 'up', 'click']);
|
|
742
|
+
|
|
743
|
+
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
|
|
744
|
+
Multitouch.mapTouchToMouse = false;
|
|
745
|
+
canvasListeners.pointerdown[0](sample(11, 5));
|
|
746
|
+
canvasListeners.pointerdown[0](sample(21, 34, { shiftKey: true }));
|
|
747
|
+
canvasListeners.pointermove[0](sample(11, 38));
|
|
748
|
+
windowListeners.pointercancel[0](sample(21, 99));
|
|
749
|
+
windowListeners.pointerup[0](sample(21, 34));
|
|
750
|
+
windowListeners.pointerup[0](sample(11, 80));
|
|
751
|
+
expect(events).toEqual([]);
|
|
752
|
+
expect(collected.map(touch => [
|
|
753
|
+
touch.type, touch.touchPointID, touch.isPrimaryTouchPoint, touch.target, touch.stageX,
|
|
754
|
+
touch.localX, touch.sizeX, touch.pressure, touch.isTouchPointCanceled,
|
|
755
|
+
])).toEqual([
|
|
756
|
+
['touchBegin', 11, true, button, 5, 5, 9, 0.75, false],
|
|
757
|
+
['touchBegin', 21, false, other, 34, 4, 9, 0.75, false],
|
|
758
|
+
['touchMove', 11, true, other, 38, 8, 9, 0.75, false],
|
|
759
|
+
['touchEnd', 21, false, other, 34, 4, 9, 0.75, true],
|
|
760
|
+
['touchEnd', 11, true, stage, 80, 80, 9, 0.75, false],
|
|
761
|
+
]);
|
|
762
|
+
const clone = collected[3].clone();
|
|
763
|
+
expect(clone).toBeInstanceOf(TouchEvent);
|
|
764
|
+
expect([clone.shiftKey, clone.stageX, clone.isTouchPointCanceled]).toEqual([true, 34, true]);
|
|
765
|
+
|
|
766
|
+
Multitouch.mapTouchToMouse = true;
|
|
767
|
+
canvasListeners.pointerdown[0](sample(11, 6));
|
|
768
|
+
canvasListeners.lostpointercapture[0](sample(11, 0));
|
|
769
|
+
expect(collected.at(-1)).toMatchObject({ touchPointID: 11, isTouchPointCanceled: true, stageX: 6 });
|
|
770
|
+
expect(events.splice(0)).toEqual(['down', 'up']);
|
|
771
|
+
canvasListeners.pointerdown[0](sample(11, 7));
|
|
772
|
+
windowListeners.pointerup[0](sample(11, 7));
|
|
773
|
+
expect(events.splice(0)).toEqual(['down', 'up', 'click']);
|
|
774
|
+
|
|
775
|
+
canvasListeners.pointerdown[0](sample(21, 35));
|
|
776
|
+
Multitouch.inputMode = MultitouchInputMode.NONE;
|
|
777
|
+
expect(collected.at(-1)).toMatchObject({ touchPointID: 21, isTouchPointCanceled: true });
|
|
778
|
+
const count = collected.length;
|
|
779
|
+
windowListeners.pointerup[0](sample(21, 35));
|
|
780
|
+
expect(collected).toHaveLength(count);
|
|
781
|
+
} finally {
|
|
782
|
+
harness.restore();
|
|
783
|
+
}
|
|
784
|
+
});
|
|
785
|
+
|
|
786
|
+
it.each(['Sprite', 'MovieClip'])('uses dynamic tab defaults and activates a focused button-mode %s', (className) => {
|
|
787
|
+
const harness = createHarness(true);
|
|
788
|
+
try {
|
|
789
|
+
const { stage, button, builtins, canvasListeners, windowListeners } = harness;
|
|
790
|
+
const sprite = new builtins[className]();
|
|
791
|
+
sprite.graphics.beginFill(0xff3300);
|
|
792
|
+
sprite.graphics.drawRect(0, 0, 20, 20);
|
|
793
|
+
sprite.graphics.endFill();
|
|
794
|
+
sprite.x = 30;
|
|
795
|
+
stage.addChild(sprite);
|
|
796
|
+
|
|
797
|
+
const key = (type, key, flags = {}) => windowListeners[type][0]({ key, ...flags });
|
|
798
|
+
expect(sprite.tabEnabled).toBe(false);
|
|
799
|
+
sprite.buttonMode = true;
|
|
800
|
+
expect(sprite.tabEnabled).toBe(true);
|
|
801
|
+
sprite.buttonMode = false;
|
|
802
|
+
expect(sprite.tabEnabled).toBe(false);
|
|
803
|
+
sprite.buttonMode = true;
|
|
804
|
+
key('keydown', 'Tab');
|
|
805
|
+
expect(stage.focus).toBe(button);
|
|
806
|
+
key('keydown', 'Tab');
|
|
807
|
+
expect(stage.focus).toBe(sprite);
|
|
808
|
+
|
|
809
|
+
const input = [];
|
|
810
|
+
for (const type of ['mouseDown', 'mouseUp', 'click']) sprite.addEventListener(type, () => input.push(type));
|
|
811
|
+
key('keydown', ' ');
|
|
812
|
+
key('keydown', ' ', { repeat: true });
|
|
813
|
+
key('keyup', 'Enter');
|
|
814
|
+
expect(input).toEqual(['mouseDown']);
|
|
815
|
+
key('keyup', ' ');
|
|
816
|
+
expect(input.splice(0)).toEqual(['mouseDown', 'mouseUp', 'click']);
|
|
817
|
+
|
|
818
|
+
key('keydown', 'Enter');
|
|
819
|
+
stage.focus = button;
|
|
820
|
+
stage.focus = sprite;
|
|
821
|
+
key('keyup', 'Enter');
|
|
822
|
+
expect(input.splice(0)).toEqual(['mouseDown', 'mouseUp']);
|
|
823
|
+
key('keydown', 'Enter');
|
|
824
|
+
sprite.buttonMode = false;
|
|
825
|
+
key('keyup', 'Enter');
|
|
826
|
+
expect(input.splice(0)).toEqual(['mouseDown', 'mouseUp']);
|
|
827
|
+
|
|
828
|
+
sprite.tabEnabled = false;
|
|
829
|
+
sprite.buttonMode = true;
|
|
830
|
+
expect(sprite.tabEnabled).toBe(false);
|
|
831
|
+
stage.focus = button;
|
|
832
|
+
const pointer = event({ clientX: 35, pointerType: 'mouse', pointerId: 1 });
|
|
833
|
+
canvasListeners.pointerdown[0](pointer);
|
|
834
|
+
windowListeners.pointerup[0](pointer);
|
|
835
|
+
expect(stage.focus).toBeNull();
|
|
836
|
+
expect(input.splice(0)).toEqual(['mouseDown', 'mouseUp', 'click']);
|
|
837
|
+
sprite.tabEnabled = true;
|
|
838
|
+
canvasListeners.pointerdown[0](pointer);
|
|
839
|
+
windowListeners.pointerup[0](pointer);
|
|
840
|
+
expect(stage.focus).toBe(sprite);
|
|
841
|
+
expect(input).toEqual(['mouseDown', 'mouseUp', 'click']);
|
|
842
|
+
} finally {
|
|
843
|
+
harness.restore();
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
it('updates the native cursor from hovered button and sprite flags', () => {
|
|
848
|
+
const harness = createHarness(true);
|
|
849
|
+
try {
|
|
850
|
+
const { button, stage, canvas, stageWrap, body, canvasListeners, builtins } = harness;
|
|
851
|
+
const { Mouse, MouseCursor, Sprite } = builtins;
|
|
852
|
+
const move = (extra) => canvasListeners.pointermove[0](event({ pointerType: 'mouse', ...extra }));
|
|
853
|
+
expect(button.useHandCursor).toBe(true);
|
|
854
|
+
move();
|
|
855
|
+
expect(canvas.style.cursor).toBe('pointer');
|
|
856
|
+
button.useHandCursor = false;
|
|
857
|
+
expect(canvas.style.cursor).toBe('auto');
|
|
858
|
+
button.useHandCursor = true;
|
|
859
|
+
Mouse.cursor = MouseCursor.IBEAM;
|
|
860
|
+
expect(canvas.style.cursor).toBe('text');
|
|
861
|
+
Mouse.hide();
|
|
862
|
+
Mouse.cursor = MouseCursor.HAND;
|
|
863
|
+
expect(canvas.style.cursor).toBe('none');
|
|
864
|
+
expect(stageWrap.style.cursor).toBe('none');
|
|
865
|
+
expect(body.style.cursor).toBe('crosshair');
|
|
866
|
+
Mouse.show();
|
|
867
|
+
expect(canvas.style.cursor).toBe('grab');
|
|
868
|
+
expect(stageWrap.style.cursor).toBe('grab');
|
|
869
|
+
expect(body.style.cursor).toBe('crosshair');
|
|
870
|
+
Mouse.cursor = MouseCursor.AUTO;
|
|
871
|
+
expect(canvas.style.cursor).toBe('pointer');
|
|
872
|
+
canvasListeners.pointerleave[0](event({ pointerType: 'mouse' }));
|
|
873
|
+
expect(canvas.style.cursor).toBe('auto');
|
|
874
|
+
move({ pointerType: 'touch' });
|
|
875
|
+
expect(canvas.style.cursor).toBe('auto');
|
|
876
|
+
|
|
877
|
+
const sprite = new Sprite();
|
|
878
|
+
sprite.graphics.beginFill(0xff3300);
|
|
879
|
+
sprite.graphics.drawRect(0, 0, 20, 20);
|
|
880
|
+
sprite.graphics.endFill();
|
|
881
|
+
stage.addChild(sprite);
|
|
882
|
+
move();
|
|
883
|
+
expect(canvas.style.cursor).toBe('auto');
|
|
884
|
+
sprite.buttonMode = true;
|
|
885
|
+
expect(canvas.style.cursor).toBe('pointer');
|
|
886
|
+
sprite.useHandCursor = false;
|
|
887
|
+
expect(canvas.style.cursor).toBe('auto');
|
|
888
|
+
} finally {
|
|
889
|
+
harness.restore();
|
|
890
|
+
}
|
|
891
|
+
});
|
|
892
|
+
|
|
893
|
+
it('dispatches touch pointer events and suppresses click after pointercancel', () => {
|
|
894
|
+
const harness = createHarness(true);
|
|
895
|
+
try {
|
|
896
|
+
const down = event({ pointerId: 3, pointerType: 'touch' });
|
|
897
|
+
harness.canvasListeners.pointerdown[0](down);
|
|
898
|
+
expect(harness.canvas.style.touchAction).toBe('none');
|
|
899
|
+
expect(harness.canvas.capturedPointer).toBe(3);
|
|
900
|
+
expect(down.prevented).toBe(true);
|
|
901
|
+
expect(harness.events).toEqual(['down']);
|
|
902
|
+
|
|
903
|
+
harness.windowListeners.pointercancel[0](event({ pointerId: 3, pointerType: 'touch', buttons: 0 }));
|
|
904
|
+
expect(harness.events).toEqual(['down', 'up']);
|
|
905
|
+
|
|
906
|
+
harness.canvasListeners.pointerdown[0](event({ pointerId: 4, pointerType: 'touch' }));
|
|
907
|
+
harness.windowListeners.pointerup[0](event({ pointerId: 4, pointerType: 'touch', buttons: 0 }));
|
|
908
|
+
expect(harness.events).toEqual(['down', 'up', 'down', 'up', 'click']);
|
|
909
|
+
} finally {
|
|
910
|
+
harness.restore();
|
|
911
|
+
}
|
|
912
|
+
});
|
|
913
|
+
|
|
914
|
+
it('uses transformed ancestor mask fills for Sprite and SimpleButton pointer picks', () => {
|
|
915
|
+
const harness = createHarness(true);
|
|
916
|
+
const oldPath = globalThis.Path2D;
|
|
917
|
+
globalThis.Path2D = class {
|
|
918
|
+
points = [];
|
|
919
|
+
moveTo(x, y) { this.points.push([x, y]); }
|
|
920
|
+
lineTo(x, y) { this.points.push([x, y]); }
|
|
921
|
+
closePath() {}
|
|
922
|
+
};
|
|
923
|
+
globalThis.document.createElement = () => ({
|
|
924
|
+
getContext: () => ({
|
|
925
|
+
isPointInStroke: () => true,
|
|
926
|
+
isPointInPath(path, x, y) {
|
|
927
|
+
let inside = false;
|
|
928
|
+
for (let i = 0, j = path.points.length - 1; i < path.points.length; j = i++) {
|
|
929
|
+
const [a, b] = path.points[i], [c, d] = path.points[j];
|
|
930
|
+
if ((b > y) !== (d > y) && x < (c - a) * (y - b) / (d - b) + a) inside = !inside;
|
|
931
|
+
}
|
|
932
|
+
return inside;
|
|
933
|
+
},
|
|
934
|
+
}),
|
|
935
|
+
});
|
|
936
|
+
try {
|
|
937
|
+
const { stage, button, builtins, canvasListeners, windowListeners } = harness;
|
|
938
|
+
const container = stage.addChild(new builtins.Sprite());
|
|
939
|
+
container.x = 20; container.y = 10;
|
|
940
|
+
container.addChild(button);
|
|
941
|
+
const target = container.addChild(new builtins.Sprite());
|
|
942
|
+
target.x = 20;
|
|
943
|
+
target.graphics.beginFill(0);
|
|
944
|
+
target.graphics.drawRect(0, 0, 20, 20);
|
|
945
|
+
target.graphics.endFill();
|
|
946
|
+
const stencil = stage.addChild(new builtins.Sprite());
|
|
947
|
+
stencil.x = 24; stencil.y = 12;
|
|
948
|
+
stencil.scaleX = 3;
|
|
949
|
+
const shape = stencil.addChild(new builtins.Shape());
|
|
950
|
+
shape.graphics.beginFill(0);
|
|
951
|
+
shape.graphics.moveTo(0, 0);
|
|
952
|
+
shape.graphics.lineTo(12, 0);
|
|
953
|
+
shape.graphics.lineTo(0, 12);
|
|
954
|
+
shape.graphics.endFill();
|
|
955
|
+
container.mask = stencil;
|
|
956
|
+
const hits = [];
|
|
957
|
+
stage.addEventListener(builtins.MouseEvent.CLICK, e => hits.push(e.target));
|
|
958
|
+
function click(x, y) {
|
|
959
|
+
canvasListeners.pointerdown[0](event({ clientX: x, clientY: y, pointerId: 4 }));
|
|
960
|
+
windowListeners.pointerup[0](event({ clientX: x, clientY: y, pointerId: 4, buttons: 0 }));
|
|
961
|
+
}
|
|
962
|
+
click(27, 14);
|
|
963
|
+
click(44, 14);
|
|
964
|
+
click(52, 22); // Inside the stencil bounds but outside its triangle.
|
|
965
|
+
click(21, 14); // Inside the button but outside the stencil bounds.
|
|
966
|
+
expect(hits).toEqual([button, target, stage, stage]);
|
|
967
|
+
shape.graphics.clear();
|
|
968
|
+
shape.graphics.lineStyle(8, 0);
|
|
969
|
+
shape.graphics.moveTo(0, 0);
|
|
970
|
+
shape.graphics.lineTo(12, 0);
|
|
971
|
+
click(27, 14);
|
|
972
|
+
expect(hits).toEqual([button, target, stage, stage, stage]);
|
|
973
|
+
} finally {
|
|
974
|
+
harness.restore();
|
|
975
|
+
if (oldPath === undefined) delete globalThis.Path2D;
|
|
976
|
+
else globalThis.Path2D = oldPath;
|
|
977
|
+
}
|
|
978
|
+
});
|
|
979
|
+
|
|
980
|
+
it('keeps click behavior with the mouse fallback when Pointer Events are unavailable', () => {
|
|
981
|
+
const harness = createHarness(false);
|
|
982
|
+
try {
|
|
983
|
+
harness.canvasListeners.mousedown[0](event());
|
|
984
|
+
harness.windowListeners.mouseup[0](event({ buttons: 0 }));
|
|
985
|
+
expect(harness.events).toEqual(['down', 'up', 'click']);
|
|
986
|
+
} finally {
|
|
987
|
+
harness.restore();
|
|
988
|
+
}
|
|
989
|
+
});
|
|
990
|
+
|
|
991
|
+
it.each([false, true])('routes independent middle and right sequences with Pointer Events %s', (pointerEvents) => {
|
|
992
|
+
const { canvasListeners, windowListeners, stage, button, builtins, events, restore } = createHarness(pointerEvents);
|
|
993
|
+
try {
|
|
994
|
+
const { MouseEvent } = builtins;
|
|
995
|
+
const seen = [];
|
|
996
|
+
for (const type of [MouseEvent.MIDDLE_MOUSE_DOWN, MouseEvent.MIDDLE_MOUSE_UP, MouseEvent.MIDDLE_CLICK,
|
|
997
|
+
MouseEvent.RIGHT_MOUSE_DOWN, MouseEvent.RIGHT_MOUSE_UP, MouseEvent.RIGHT_CLICK]) {
|
|
998
|
+
stage.addEventListener(type, (e) => seen.push([e.type, e.target, e.buttonDown, e.ctrlKey]));
|
|
999
|
+
}
|
|
1000
|
+
canvasListeners.mousedown[0](event({ button: 1, buttons: 4 }));
|
|
1001
|
+
windowListeners.mouseup[0](event({ button: 1, buttons: 0, clientX: 140 }));
|
|
1002
|
+
canvasListeners.mousedown[0](event({ button: 1, buttons: 4 }));
|
|
1003
|
+
windowListeners.mouseup[0](event({ button: 1, buttons: 0 }));
|
|
1004
|
+
canvasListeners.mousedown[0](event({ button: 2, buttons: 2, ctrlKey: true }));
|
|
1005
|
+
const contextMenu = event({ button: 2, buttons: 2 });
|
|
1006
|
+
canvasListeners.contextmenu[0](contextMenu);
|
|
1007
|
+
windowListeners.mouseup[0](event({ button: 2, buttons: 0 }));
|
|
1008
|
+
|
|
1009
|
+
expect(contextMenu.prevented).toBe(true);
|
|
1010
|
+
expect(seen).toEqual([
|
|
1011
|
+
[MouseEvent.MIDDLE_MOUSE_DOWN, button, true, false],
|
|
1012
|
+
[MouseEvent.MIDDLE_MOUSE_DOWN, button, true, false],
|
|
1013
|
+
[MouseEvent.MIDDLE_MOUSE_UP, button, false, false],
|
|
1014
|
+
[MouseEvent.MIDDLE_CLICK, button, false, false],
|
|
1015
|
+
[MouseEvent.RIGHT_MOUSE_DOWN, button, true, true],
|
|
1016
|
+
[MouseEvent.RIGHT_MOUSE_UP, button, false, false],
|
|
1017
|
+
[MouseEvent.RIGHT_CLICK, button, false, false],
|
|
1018
|
+
]);
|
|
1019
|
+
expect(events).toEqual([]);
|
|
1020
|
+
expect(stage.focus).toBeNull();
|
|
1021
|
+
} finally {
|
|
1022
|
+
restore();
|
|
1023
|
+
}
|
|
1024
|
+
});
|
|
1025
|
+
|
|
1026
|
+
it('routes secondary presses, releases, and clicks over authored content and empty Stage', () => {
|
|
1027
|
+
const { canvasListeners, windowListeners, stage, runtime, builtins, restore } = createHarness(true);
|
|
1028
|
+
try {
|
|
1029
|
+
const { MouseEvent, MovieClip } = builtins;
|
|
1030
|
+
const authored = stage.addChild(new MovieClip());
|
|
1031
|
+
authored.name = 'authored';
|
|
1032
|
+
runtime.setCanvasAuthoredTarget(target => target === authored);
|
|
1033
|
+
runtime.setCanvasAuthoredTouchPick((x, y, touch) => !touch && x >= 30 && x < 60 ? { target: authored } : null);
|
|
1034
|
+
const seen = [];
|
|
1035
|
+
for (const type of [MouseEvent.RIGHT_MOUSE_DOWN, MouseEvent.RIGHT_MOUSE_UP, MouseEvent.RIGHT_CLICK]) {
|
|
1036
|
+
stage.addEventListener(type, e => seen.push([e.type, e.target === stage ? 'stage' : e.target.name]));
|
|
1037
|
+
}
|
|
1038
|
+
const press = x => canvasListeners.mousedown[0](event({ clientX: x, button: 2, buttons: 2 }));
|
|
1039
|
+
const release = x => windowListeners.mouseup[0](event({ clientX: x, button: 2, buttons: 0 }));
|
|
1040
|
+
press(40);
|
|
1041
|
+
release(80);
|
|
1042
|
+
press(40);
|
|
1043
|
+
release(40);
|
|
1044
|
+
press(80);
|
|
1045
|
+
const menu = event({ clientX: 80, button: 2, buttons: 2 });
|
|
1046
|
+
canvasListeners.contextmenu[0](menu);
|
|
1047
|
+
release(80);
|
|
1048
|
+
press(80);
|
|
1049
|
+
release(100);
|
|
1050
|
+
|
|
1051
|
+
expect(seen).toEqual([
|
|
1052
|
+
['rightMouseDown', 'authored'], ['rightMouseUp', 'stage'],
|
|
1053
|
+
['rightMouseDown', 'authored'], ['rightMouseUp', 'authored'], ['rightClick', 'authored'],
|
|
1054
|
+
['rightMouseDown', 'stage'], ['rightMouseUp', 'stage'], ['rightClick', 'stage'],
|
|
1055
|
+
['rightMouseDown', 'stage'],
|
|
1056
|
+
]);
|
|
1057
|
+
expect(menu.prevented).toBe(true);
|
|
1058
|
+
} finally {
|
|
1059
|
+
restore();
|
|
1060
|
+
}
|
|
1061
|
+
});
|
|
1062
|
+
|
|
1063
|
+
it('retains a primary release when another mouse button stays held', () => {
|
|
1064
|
+
const { canvasListeners, windowListeners, events, restore } = createHarness(true);
|
|
1065
|
+
try {
|
|
1066
|
+
canvasListeners.pointerdown[0](event({ pointerId: 4, pointerType: 'mouse' }));
|
|
1067
|
+
canvasListeners.mousedown[0](event({ button: 2, buttons: 3 }));
|
|
1068
|
+
windowListeners.mouseup[0](event({ button: 0, buttons: 2 }));
|
|
1069
|
+
windowListeners.pointerup[0](event({ pointerId: 4, pointerType: 'mouse', button: 2, buttons: 0 }));
|
|
1070
|
+
windowListeners.mouseup[0](event({ button: 2, buttons: 0 }));
|
|
1071
|
+
expect(events).toEqual(['down', 'up', 'click']);
|
|
1072
|
+
} finally {
|
|
1073
|
+
restore();
|
|
1074
|
+
}
|
|
1075
|
+
});
|
|
1076
|
+
|
|
1077
|
+
it('recognizes an enabled primary double click while preserving ordinary and touch clicks', () => {
|
|
1078
|
+
const { canvasListeners, windowListeners, button, builtins, events, restore } = createHarness(true);
|
|
1079
|
+
try {
|
|
1080
|
+
const { MouseEvent } = builtins;
|
|
1081
|
+
const gesture = (timeStamp, pointerType = 'mouse', clientX = 5) => {
|
|
1082
|
+
canvasListeners.pointerdown[0](event({ pointerId: 4, pointerType, timeStamp, clientX }));
|
|
1083
|
+
windowListeners.pointerup[0](event({ pointerId: 4, pointerType, timeStamp: timeStamp + 10, clientX, buttons: 0 }));
|
|
1084
|
+
};
|
|
1085
|
+
expect(button.doubleClickEnabled).toBe(false);
|
|
1086
|
+
button.addEventListener(MouseEvent.DOUBLE_CLICK, () => events.push('double'));
|
|
1087
|
+
gesture(100);
|
|
1088
|
+
gesture(200);
|
|
1089
|
+
button.doubleClickEnabled = true;
|
|
1090
|
+
gesture(700);
|
|
1091
|
+
gesture(810);
|
|
1092
|
+
gesture(1000, 'touch');
|
|
1093
|
+
gesture(1110, 'touch');
|
|
1094
|
+
gesture(1500);
|
|
1095
|
+
gesture(1600, 'mouse', 15);
|
|
1096
|
+
expect(events).toEqual([
|
|
1097
|
+
'down', 'up', 'click', 'down', 'up', 'click',
|
|
1098
|
+
'down', 'up', 'click', 'down', 'up', 'double',
|
|
1099
|
+
'down', 'up', 'click', 'down', 'up', 'click',
|
|
1100
|
+
'down', 'up', 'click', 'down', 'up', 'click',
|
|
1101
|
+
]);
|
|
1102
|
+
} finally {
|
|
1103
|
+
restore();
|
|
1104
|
+
}
|
|
1105
|
+
});
|
|
1106
|
+
|
|
1107
|
+
it('bubbles vertical wheel deltas from the hit button and targets Stage over empty space', () => {
|
|
1108
|
+
const { canvasListeners, stage, button, builtins, restore } = createHarness(true);
|
|
1109
|
+
try {
|
|
1110
|
+
button.x = 2;
|
|
1111
|
+
const wheel = [];
|
|
1112
|
+
stage.addEventListener(builtins.MouseEvent.MOUSE_WHEEL, (e) => {
|
|
1113
|
+
wheel.push([e.target === button ? 'button' : e.target === stage ? 'stage' : 'other',
|
|
1114
|
+
e.stageX, e.localX, e.delta, e.cancelable]);
|
|
1115
|
+
});
|
|
1116
|
+
canvasListeners.wheel[0](event({ buttons: 0, deltaMode: 1, deltaY: -3 }));
|
|
1117
|
+
canvasListeners.wheel[0](event({ buttons: 0, deltaMode: 0, deltaY: 80 }));
|
|
1118
|
+
canvasListeners.wheel[0](event({ buttons: 0, deltaMode: 0, deltaY: 0, deltaX: 30 }));
|
|
1119
|
+
canvasListeners.wheel[0](event({ buttons: 0, deltaMode: 1, deltaY: 3, clientX: 40 }));
|
|
1120
|
+
canvasListeners.wheel[0](event({ buttons: 0, deltaMode: 1, deltaY: 3, clientX: 100 }));
|
|
1121
|
+
expect(wheel).toEqual([
|
|
1122
|
+
['button', 5, 3, 3, false],
|
|
1123
|
+
['button', 5, 3, -2, false],
|
|
1124
|
+
['stage', 40, 40, -3, false],
|
|
1125
|
+
]);
|
|
1126
|
+
} finally {
|
|
1127
|
+
restore();
|
|
1128
|
+
}
|
|
1129
|
+
});
|
|
1130
|
+
|
|
1131
|
+
it('dispatches mouseWheelHorizontal for browser deltaX with the same hit target as vertical wheel', () => {
|
|
1132
|
+
const { canvasListeners, stage, button, builtins, restore } = createHarness(true);
|
|
1133
|
+
try {
|
|
1134
|
+
button.x = 2;
|
|
1135
|
+
const horizontal = [];
|
|
1136
|
+
const vertical = [];
|
|
1137
|
+
stage.addEventListener(builtins.MouseEvent.MOUSE_WHEEL_HORIZONTAL, (e) => {
|
|
1138
|
+
horizontal.push([e.target === button ? 'button' : e.target === stage ? 'stage' : 'other',
|
|
1139
|
+
e.type, e.stageX, e.localX, e.delta, e.bubbles]);
|
|
1140
|
+
});
|
|
1141
|
+
stage.addEventListener(builtins.MouseEvent.MOUSE_WHEEL, (e) => {
|
|
1142
|
+
vertical.push([e.type, e.delta]);
|
|
1143
|
+
});
|
|
1144
|
+
canvasListeners.wheel[0](event({ buttons: 0, deltaMode: 1, deltaY: 0, deltaX: -2 }));
|
|
1145
|
+
canvasListeners.wheel[0](event({ buttons: 0, deltaMode: 0, deltaY: 0, deltaX: 80 }));
|
|
1146
|
+
canvasListeners.wheel[0](event({ buttons: 0, deltaMode: 1, deltaY: -1, deltaX: 3, clientX: 40 }));
|
|
1147
|
+
expect(horizontal).toEqual([
|
|
1148
|
+
['button', 'mouseWheelHorizontal', 5, 3, 2, true],
|
|
1149
|
+
['button', 'mouseWheelHorizontal', 5, 3, -2, true],
|
|
1150
|
+
['stage', 'mouseWheelHorizontal', 40, 40, -3, true],
|
|
1151
|
+
]);
|
|
1152
|
+
expect(vertical).toEqual([['mouseWheel', 1]]);
|
|
1153
|
+
} finally {
|
|
1154
|
+
restore();
|
|
1155
|
+
}
|
|
1156
|
+
});
|
|
1157
|
+
|
|
1158
|
+
it('routes wheel input through the authored pointer pick in display order', () => {
|
|
1159
|
+
const { canvas, canvasListeners, stage, button, runtime, builtins, restore } = createHarness(true);
|
|
1160
|
+
try {
|
|
1161
|
+
const { MouseEvent, MovieClip } = builtins;
|
|
1162
|
+
const authored = stage.addChild(new MovieClip());
|
|
1163
|
+
Object.assign(authored, { x: 4, y: 8 });
|
|
1164
|
+
authored.name = 'authored';
|
|
1165
|
+
button.name = 'programmatic';
|
|
1166
|
+
runtime.setCanvasAuthoredTarget(target => target === authored);
|
|
1167
|
+
runtime.setCanvasAuthoredTouchPick((x, y, touch) => !touch && x < 30 ? { target: authored } : null);
|
|
1168
|
+
const hits = [];
|
|
1169
|
+
const record = e => hits.push([e.target.name, e.currentTarget === stage ? 'stage' : e.currentTarget.name,
|
|
1170
|
+
e.localX, e.localY, e.delta]);
|
|
1171
|
+
authored.addEventListener(MouseEvent.MOUSE_WHEEL, record);
|
|
1172
|
+
stage.addEventListener(MouseEvent.MOUSE_WHEEL, record);
|
|
1173
|
+
const wheel = x => canvasListeners.wheel[0](event({ clientX: x, clientY: 10, deltaMode: 1, deltaY: 2 }));
|
|
1174
|
+
wheel(8);
|
|
1175
|
+
runtime.setCanvasTimelineOrder((x, y, touch, target) => target === button);
|
|
1176
|
+
wheel(8);
|
|
1177
|
+
canvas._swoofAvm1Pointer = true;
|
|
1178
|
+
const avm1Wheel = vi.fn();
|
|
1179
|
+
canvas._swoofAvm1Wheel = avm1Wheel;
|
|
1180
|
+
wheel(40);
|
|
1181
|
+
|
|
1182
|
+
expect(hits).toEqual([
|
|
1183
|
+
['programmatic', 'stage', 8, 10, -2],
|
|
1184
|
+
['authored', 'authored', 4, 2, -2],
|
|
1185
|
+
['authored', 'stage', 4, 2, -2],
|
|
1186
|
+
]);
|
|
1187
|
+
expect(avm1Wheel).toHaveBeenCalledWith(expect.objectContaining({ clientX: 40 }), -2);
|
|
1188
|
+
} finally {
|
|
1189
|
+
restore();
|
|
1190
|
+
}
|
|
1191
|
+
});
|
|
1192
|
+
|
|
1193
|
+
it('clears held input on lost capture and ignores unrelated pointers and buttons', () => {
|
|
1194
|
+
const { canvasListeners, windowListeners, events, restore } = createHarness(true);
|
|
1195
|
+
try {
|
|
1196
|
+
canvasListeners.pointerdown[0](event({ pointerId: 3 }));
|
|
1197
|
+
canvasListeners.pointerdown[0](event({ pointerId: 4, isPrimary: false }));
|
|
1198
|
+
windowListeners.pointerup[0](event({ pointerId: 4, buttons: 0 }));
|
|
1199
|
+
windowListeners.pointerup[0](event({ pointerId: 3, button: 2 }));
|
|
1200
|
+
expect(events).toEqual(['down']);
|
|
1201
|
+
|
|
1202
|
+
canvasListeners.lostpointercapture[0]({ pointerId: 3 });
|
|
1203
|
+
windowListeners.pointerup[0](event({ pointerId: 3, buttons: 0 }));
|
|
1204
|
+
expect(events).toEqual(['down', 'up', 'up']);
|
|
1205
|
+
|
|
1206
|
+
canvasListeners.pointerdown[0](event({ pointerId: 5 }));
|
|
1207
|
+
for (const blur of windowListeners.blur) blur();
|
|
1208
|
+
expect(events).toEqual(['down', 'up', 'up', 'down', 'up']);
|
|
1209
|
+
} finally {
|
|
1210
|
+
restore();
|
|
1211
|
+
}
|
|
1212
|
+
});
|
|
1213
|
+
|
|
1214
|
+
it('sends releaseOutside to the pressed button and mouseUp to the button under the pointer', () => {
|
|
1215
|
+
const { canvasListeners, windowListeners, events, button, stage, builtins, restore } = createHarness(false);
|
|
1216
|
+
try {
|
|
1217
|
+
const { MouseEvent, SimpleButton } = builtins;
|
|
1218
|
+
const other = new SimpleButton();
|
|
1219
|
+
other.x = 20;
|
|
1220
|
+
other.width = other.height = 20;
|
|
1221
|
+
stage.addChild(other);
|
|
1222
|
+
button.addEventListener(MouseEvent.RELEASE_OUTSIDE, () => events.push('outside'));
|
|
1223
|
+
other.addEventListener(MouseEvent.MOUSE_UP, () => events.push('other up'));
|
|
1224
|
+
canvasListeners.mousedown[0](event());
|
|
1225
|
+
windowListeners.mouseup[0](event({ clientX: 25, buttons: 0 }));
|
|
1226
|
+
expect(events).toEqual(['down', 'other up', 'outside']);
|
|
1227
|
+
} finally {
|
|
1228
|
+
restore();
|
|
1229
|
+
}
|
|
1230
|
+
});
|
|
1231
|
+
|
|
1232
|
+
it('supplies mouse and roll transition data to both neighboring buttons', () => {
|
|
1233
|
+
const { canvasListeners, stage, button, builtins, restore } = createHarness(false);
|
|
1234
|
+
try {
|
|
1235
|
+
const { MouseEvent, SimpleButton, Sprite } = builtins;
|
|
1236
|
+
const parent = new Sprite();
|
|
1237
|
+
stage.addChild(parent);
|
|
1238
|
+
stage.removeChild(button);
|
|
1239
|
+
parent.addChild(button);
|
|
1240
|
+
const other = new SimpleButton();
|
|
1241
|
+
other.x = 20;
|
|
1242
|
+
other.width = other.height = 20;
|
|
1243
|
+
parent.addChild(other);
|
|
1244
|
+
const received = [];
|
|
1245
|
+
const record = (e) => received.push(e.clone());
|
|
1246
|
+
button.addEventListener(MouseEvent.MOUSE_OUT, record);
|
|
1247
|
+
other.addEventListener(MouseEvent.ROLL_OVER, record);
|
|
1248
|
+
const parentRolls = [];
|
|
1249
|
+
parent.addEventListener(MouseEvent.ROLL_OVER, (e) => parentRolls.push(e.target));
|
|
1250
|
+
parent.addEventListener(MouseEvent.ROLL_OUT, (e) => parentRolls.push(e.target));
|
|
1251
|
+
stage.addEventListener(MouseEvent.ROLL_OVER, record);
|
|
1252
|
+
canvasListeners.mousemove[0](event({ buttons: 0 }));
|
|
1253
|
+
canvasListeners.mousemove[0](event({ clientX: 25, buttons: 0, ctrlKey: true, shiftKey: true }));
|
|
1254
|
+
expect(parentRolls).toEqual([parent]);
|
|
1255
|
+
expect(received).toMatchObject([
|
|
1256
|
+
{ type: MouseEvent.MOUSE_OUT, relatedObject: other, localX: 25, stageX: 25, buttonDown: false, ctrlKey: true, shiftKey: true, bubbles: true },
|
|
1257
|
+
{ type: MouseEvent.ROLL_OVER, relatedObject: button, localX: 5, stageX: 25, buttonDown: false, ctrlKey: true, shiftKey: true, bubbles: false },
|
|
1258
|
+
]);
|
|
1259
|
+
canvasListeners.mouseleave[0](event({ clientX: 100, buttons: 0 }));
|
|
1260
|
+
expect(parentRolls).toEqual([parent, parent]);
|
|
1261
|
+
} finally {
|
|
1262
|
+
restore();
|
|
1263
|
+
}
|
|
1264
|
+
});
|
|
1265
|
+
|
|
1266
|
+
it('sends nested roll-over from the outside in and roll-out from the inside out', () => {
|
|
1267
|
+
const { canvasListeners, stage, button, builtins, restore } = createHarness(false);
|
|
1268
|
+
try {
|
|
1269
|
+
const { MouseEvent, Sprite } = builtins;
|
|
1270
|
+
const parent = new Sprite();
|
|
1271
|
+
stage.addChild(parent);
|
|
1272
|
+
stage.removeChild(button);
|
|
1273
|
+
parent.addChild(button);
|
|
1274
|
+
const order = [];
|
|
1275
|
+
parent.addEventListener(MouseEvent.ROLL_OVER, () => order.push('parent-over'));
|
|
1276
|
+
parent.addEventListener(MouseEvent.ROLL_OUT, () => order.push('parent-out'));
|
|
1277
|
+
button.addEventListener(MouseEvent.ROLL_OVER, () => order.push('child-over'));
|
|
1278
|
+
button.addEventListener(MouseEvent.ROLL_OUT, () => order.push('child-out'));
|
|
1279
|
+
canvasListeners.mousemove[0](event({ buttons: 0 }));
|
|
1280
|
+
expect(order).toEqual(['parent-over', 'child-over']);
|
|
1281
|
+
canvasListeners.mouseleave[0](event({ clientX: 100, buttons: 0 }));
|
|
1282
|
+
expect(order).toEqual(['parent-over', 'child-over', 'child-out', 'parent-out']);
|
|
1283
|
+
} finally {
|
|
1284
|
+
restore();
|
|
1285
|
+
}
|
|
1286
|
+
});
|
|
1287
|
+
|
|
1288
|
+
it('sends nested touch roll-over from the outside in and roll-out from the inside out', () => {
|
|
1289
|
+
const harness = createHarness(true);
|
|
1290
|
+
try {
|
|
1291
|
+
const { canvasListeners, windowListeners, stage, button, builtins } = harness;
|
|
1292
|
+
const { Multitouch, Sprite } = builtins;
|
|
1293
|
+
Multitouch.inputMode = 'touchPoint';
|
|
1294
|
+
Multitouch.mapTouchToMouse = false;
|
|
1295
|
+
const parent = stage.addChild(new Sprite());
|
|
1296
|
+
stage.removeChild(button);
|
|
1297
|
+
parent.addChild(button);
|
|
1298
|
+
parent.name = 'parent';
|
|
1299
|
+
button.name = 'child';
|
|
1300
|
+
const order = [];
|
|
1301
|
+
const record = e => order.push(`${e.currentTarget.name}:${e.type}:${e.bubbles}`);
|
|
1302
|
+
for (const type of ['touchRollOver', 'touchRollOut', 'touchOver', 'touchOut']) {
|
|
1303
|
+
parent.addEventListener(type, record);
|
|
1304
|
+
button.addEventListener(type, record);
|
|
1305
|
+
}
|
|
1306
|
+
function contact(type, x) {
|
|
1307
|
+
const handlers = type === 'pointerup' || type === 'pointercancel' ? windowListeners : canvasListeners;
|
|
1308
|
+
handlers[type][0](event({ pointerType: 'touch', pointerId: 1, clientX: x, clientY: 5 }));
|
|
1309
|
+
}
|
|
1310
|
+
contact('pointerdown', 5);
|
|
1311
|
+
expect(order).toEqual([
|
|
1312
|
+
'parent:touchRollOver:false', 'child:touchRollOver:false',
|
|
1313
|
+
'child:touchOver:true', 'parent:touchOver:true',
|
|
1314
|
+
]);
|
|
1315
|
+
contact('pointerup', 80);
|
|
1316
|
+
expect(order.slice(4)).toEqual([
|
|
1317
|
+
'child:touchOut:true', 'parent:touchOut:true',
|
|
1318
|
+
'child:touchRollOut:false', 'parent:touchRollOut:false',
|
|
1319
|
+
]);
|
|
1320
|
+
} finally {
|
|
1321
|
+
harness.restore();
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1324
|
+
|
|
1325
|
+
it('picks a programmatic control through Shape and linked skins under layout scale overrides', () => {
|
|
1326
|
+
const harness = createHarness(true);
|
|
1327
|
+
try {
|
|
1328
|
+
const { canvasListeners, windowListeners, stage, button, builtins, runtime } = harness;
|
|
1329
|
+
stage.removeChild(button);
|
|
1330
|
+
const { Sprite, Shape, MouseEvent } = builtins;
|
|
1331
|
+
class LayoutControl extends Sprite {
|
|
1332
|
+
get scaleX() { return this.layoutScaleX ?? 1; }
|
|
1333
|
+
set scaleX(value) { this.layoutScaleX = value; }
|
|
1334
|
+
get scaleY() { return this.layoutScaleY ?? 1; }
|
|
1335
|
+
set scaleY(value) { this.layoutScaleY = value; }
|
|
1336
|
+
}
|
|
1337
|
+
const control = stage.addChild(new LayoutControl());
|
|
1338
|
+
control.x = 10;
|
|
1339
|
+
control.y = 4;
|
|
1340
|
+
control.scaleX = 3;
|
|
1341
|
+
control.scaleY = 2;
|
|
1342
|
+
const skin = control.addChild(new Shape());
|
|
1343
|
+
skin.graphics.beginFill(0xff0000);
|
|
1344
|
+
skin.graphics.drawRect(0, 0, 16, 10);
|
|
1345
|
+
skin.graphics.endFill();
|
|
1346
|
+
skin.x = 2;
|
|
1347
|
+
skin.y = 1;
|
|
1348
|
+
const events = [];
|
|
1349
|
+
control.addEventListener(MouseEvent.CLICK, e => events.push(e.target));
|
|
1350
|
+
function click(x, y) {
|
|
1351
|
+
canvasListeners.pointerdown[0](event({
|
|
1352
|
+
clientX: x, clientY: y, pointerId: 1, pointerType: 'mouse', isPrimary: true, buttons: 1,
|
|
1353
|
+
}));
|
|
1354
|
+
windowListeners.pointerup[0](event({
|
|
1355
|
+
clientX: x, clientY: y, pointerId: 1, pointerType: 'mouse', isPrimary: true, buttons: 0,
|
|
1356
|
+
}));
|
|
1357
|
+
}
|
|
1358
|
+
click(14, 7);
|
|
1359
|
+
expect(events).toEqual([control]);
|
|
1360
|
+
events.length = 0;
|
|
1361
|
+
click(40, 7);
|
|
1362
|
+
expect(events).toEqual([]);
|
|
1363
|
+
|
|
1364
|
+
control.removeChild(skin);
|
|
1365
|
+
const linked = control.addChild(new Sprite());
|
|
1366
|
+
linked.mouseEnabled = false;
|
|
1367
|
+
linked.x = 20;
|
|
1368
|
+
linked.y = 0;
|
|
1369
|
+
linked.graphics.beginFill(0x00ff00);
|
|
1370
|
+
linked.graphics.drawRect(0, 0, 8, 8);
|
|
1371
|
+
linked.graphics.endFill();
|
|
1372
|
+
click(32, 6);
|
|
1373
|
+
expect(events).toEqual([control]);
|
|
1374
|
+
events.length = 0;
|
|
1375
|
+
click(14, 7);
|
|
1376
|
+
expect(events).toEqual([]);
|
|
1377
|
+
|
|
1378
|
+
linked.mouseEnabled = true;
|
|
1379
|
+
linked._swoofStandaloneArtworkId = 'skin';
|
|
1380
|
+
const { Point } = builtins;
|
|
1381
|
+
runtime.registerAuthoredMaskSource(linked, {
|
|
1382
|
+
hitArtwork(clip, x, y) {
|
|
1383
|
+
const local = clip.globalToLocal(new Point(x, y));
|
|
1384
|
+
return local.x >= 0 && local.y >= 0 && local.x < 8 && local.y < 8;
|
|
1385
|
+
},
|
|
1386
|
+
});
|
|
1387
|
+
// mouseEnabled skins still route to the control through the linked-artwork helper.
|
|
1388
|
+
linked.mouseEnabled = false;
|
|
1389
|
+
click(32, 6);
|
|
1390
|
+
expect(events).toEqual([control]);
|
|
1391
|
+
} finally {
|
|
1392
|
+
harness.restore();
|
|
1393
|
+
}
|
|
1394
|
+
});
|
|
1395
|
+
|
|
1396
|
+
it('clears mouse focus on blank or non-tabbable hits with cancelable attempts', () => {
|
|
1397
|
+
const { canvasListeners, windowListeners, stage, button, builtins, restore } = createHarness(false);
|
|
1398
|
+
try {
|
|
1399
|
+
const { FocusEvent, SimpleButton } = builtins;
|
|
1400
|
+
const plain = new SimpleButton();
|
|
1401
|
+
plain.tabEnabled = false;
|
|
1402
|
+
plain.x = 30;
|
|
1403
|
+
plain.width = plain.height = 20;
|
|
1404
|
+
stage.addChild(plain);
|
|
1405
|
+
const attempts = [], losses = [];
|
|
1406
|
+
let cancel = true;
|
|
1407
|
+
stage.addEventListener(FocusEvent.MOUSE_FOCUS_CHANGE, e => {
|
|
1408
|
+
attempts.push([e.target, e.relatedObject, e.cancelable]);
|
|
1409
|
+
if (cancel) e.preventDefault();
|
|
1410
|
+
});
|
|
1411
|
+
button.addEventListener(FocusEvent.FOCUS_OUT, e => losses.push(e.relatedObject));
|
|
1412
|
+
function click(x) {
|
|
1413
|
+
canvasListeners.mousedown[0](event({ clientX: x }));
|
|
1414
|
+
windowListeners.mouseup[0](event({ clientX: x, buttons: 0 }));
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
stage.focus = button;
|
|
1418
|
+
click(80);
|
|
1419
|
+
expect(attempts.splice(0)).toEqual([[button, null, true]]);
|
|
1420
|
+
expect(stage.focus).toBe(button);
|
|
1421
|
+
click(35);
|
|
1422
|
+
expect(attempts.splice(0)).toEqual([[button, plain, true]]);
|
|
1423
|
+
expect(stage.focus).toBe(button);
|
|
1424
|
+
expect(losses).toEqual([]);
|
|
1425
|
+
|
|
1426
|
+
cancel = false;
|
|
1427
|
+
click(35);
|
|
1428
|
+
expect(attempts.splice(0)).toEqual([[button, plain, true]]);
|
|
1429
|
+
expect(losses).toEqual([null]);
|
|
1430
|
+
expect(stage.focus).toBeNull();
|
|
1431
|
+
click(35);
|
|
1432
|
+
expect(attempts.splice(0)).toEqual([[stage, plain, true]]);
|
|
1433
|
+
expect(stage.focus).toBeNull();
|
|
1434
|
+
|
|
1435
|
+
stage.focus = plain;
|
|
1436
|
+
click(80);
|
|
1437
|
+
expect(attempts).toEqual([]);
|
|
1438
|
+
expect(stage.focus).toBe(plain);
|
|
1439
|
+
stage.focus = stage;
|
|
1440
|
+
click(80);
|
|
1441
|
+
expect(attempts).toEqual([]);
|
|
1442
|
+
expect(stage.focus).toBe(stage);
|
|
1443
|
+
|
|
1444
|
+
stage.focus = button;
|
|
1445
|
+
click(5);
|
|
1446
|
+
expect(attempts).toEqual([]);
|
|
1447
|
+
click(80);
|
|
1448
|
+
expect(attempts).toEqual([[button, null, true]]);
|
|
1449
|
+
expect(stage.focus).toBeNull();
|
|
1450
|
+
} finally {
|
|
1451
|
+
restore();
|
|
1452
|
+
}
|
|
1453
|
+
});
|
|
1454
|
+
|
|
1455
|
+
it('allows cancellation of button focus and reports a noncancelable click', () => {
|
|
1456
|
+
const { canvasListeners, windowListeners, stage, button, builtins, restore } = createHarness(false);
|
|
1457
|
+
try {
|
|
1458
|
+
const { FocusEvent, MouseEvent } = builtins;
|
|
1459
|
+
const focusChanges = [], clicks = [];
|
|
1460
|
+
stage.addEventListener(FocusEvent.MOUSE_FOCUS_CHANGE, (e) => {
|
|
1461
|
+
focusChanges.push(e.relatedObject);
|
|
1462
|
+
e.preventDefault();
|
|
1463
|
+
});
|
|
1464
|
+
button.addEventListener(MouseEvent.CLICK, (e) => {
|
|
1465
|
+
e.preventDefault();
|
|
1466
|
+
clicks.push(e);
|
|
1467
|
+
});
|
|
1468
|
+
canvasListeners.mousedown[0](event());
|
|
1469
|
+
windowListeners.mouseup[0](event({ buttons: 0 }));
|
|
1470
|
+
expect(stage.focus).toBeNull();
|
|
1471
|
+
expect(focusChanges).toEqual([button]);
|
|
1472
|
+
expect(clicks).toMatchObject([{ cancelable: false, defaultPrevented: false }]);
|
|
1473
|
+
} finally {
|
|
1474
|
+
restore();
|
|
1475
|
+
}
|
|
1476
|
+
});
|
|
1477
|
+
});
|