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,2506 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { runInNewContext } from 'node:vm';
|
|
4
|
+
import { parse } from '../parser/swf-parser.js';
|
|
5
|
+
import { decode } from '../decoder/tag-decoder.js';
|
|
6
|
+
import { SymbolTable } from '../decoder/symbol-table.js';
|
|
7
|
+
import { SWFLIB_SOURCE, AVM1_RUNTIME_FACTORY_SOURCE, AVM1_RUNTIME_BOOTSTRAP } from '../runtime/index.js';
|
|
8
|
+
import { buildDisplayList } from '../transpiler/timeline/display-list.js';
|
|
9
|
+
import { generateTimelineEngine, timelineEngineFactorySource, timelineHelpersSource } from '../transpiler/timeline/timeline-codegen.js';
|
|
10
|
+
|
|
11
|
+
function mountMovie(avm1 = false, authored = { frames: [{ places: [] }], characters: {} }, { pointerEvents = false, keyboardEvents = false } = {}) {
|
|
12
|
+
const width = 200, height = 100;
|
|
13
|
+
const draws = [];
|
|
14
|
+
const textColors = [];
|
|
15
|
+
const rect = () => ({ left: 0, top: 0, width, height });
|
|
16
|
+
const canvasListeners = new Map();
|
|
17
|
+
const canvas = { width, height, style: {}, getBoundingClientRect: rect, focus() {},
|
|
18
|
+
addEventListener(type, listener) {
|
|
19
|
+
const listeners = canvasListeners.get(type) ?? [];
|
|
20
|
+
listeners.push(listener);
|
|
21
|
+
canvasListeners.set(type, listeners);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
function dispatchCanvas(type, options) {
|
|
25
|
+
const event = { target: canvas, clientX: 20, clientY: 20, button: 0, pointerId: 1,
|
|
26
|
+
isPrimary: true, defaultPrevented: false, preventDefault() { this.defaultPrevented = true; }, ...options };
|
|
27
|
+
for (const listener of canvasListeners.get(type) ?? []) listener(event);
|
|
28
|
+
return event;
|
|
29
|
+
}
|
|
30
|
+
let transform = [1, 0, 0, 1, 0, 0];
|
|
31
|
+
const states = [];
|
|
32
|
+
const ctx = {
|
|
33
|
+
canvas, globalAlpha: 1,
|
|
34
|
+
setTransform(...next) { transform = next; },
|
|
35
|
+
getTransform() {
|
|
36
|
+
const [a, b, c, d, e, f] = transform;
|
|
37
|
+
return { a, b, c, d, e, f };
|
|
38
|
+
},
|
|
39
|
+
transform(a, b, c, d, e, f) {
|
|
40
|
+
const [u, v, w, x, y, z] = transform;
|
|
41
|
+
transform = [u * a + w * b, v * a + x * b, u * c + w * d, v * c + x * d, u * e + w * f + y, v * e + x * f + z];
|
|
42
|
+
},
|
|
43
|
+
translate(x, y) { this.transform(1, 0, 0, 1, x, y); },
|
|
44
|
+
rotate(angle) { this.transform(Math.cos(angle), Math.sin(angle), -Math.sin(angle), Math.cos(angle), 0, 0); },
|
|
45
|
+
scale(x, y) { this.transform(x, 0, 0, y, 0, 0); },
|
|
46
|
+
save() { states.push([transform, this.globalAlpha]); },
|
|
47
|
+
restore() { [transform, this.globalAlpha] = states.pop(); },
|
|
48
|
+
beginPath() {}, rect() {}, clip() {}, fillRect() {}, strokeRect() {}, fill() {}, stroke() {},
|
|
49
|
+
measureText: text => ({ width: text.length * 6 }),
|
|
50
|
+
fillText(text) { draws.push(text); textColors.push(this.fillStyle); },
|
|
51
|
+
};
|
|
52
|
+
const hud = { style: {}, isConnected: true, children: [], appendChild(el) { this.children.push(el); } };
|
|
53
|
+
const document = {
|
|
54
|
+
activeElement: null,
|
|
55
|
+
getElementById: id => id === 'stage' ? canvas : id === 'stage-hud' ? hud : null,
|
|
56
|
+
createElement(tag) {
|
|
57
|
+
if (tag === 'canvas') return { getContext: () => null };
|
|
58
|
+
const listeners = {};
|
|
59
|
+
return {
|
|
60
|
+
tag, style: {}, dataset: {}, value: '', isConnected: true, tabIndex: tag === 'div' ? -1 : 0,
|
|
61
|
+
selectionStart: 0, selectionEnd: 0, selectionDirection: 'none', scrollLeft: 0, scrollTop: 0,
|
|
62
|
+
addEventListener(type, listener) { (listeners[type] ||= []).push(listener); },
|
|
63
|
+
dispatch(type, payload = {}) {
|
|
64
|
+
const event = { type, defaultPrevented: false, preventDefault() { this.defaultPrevented = true; }, ...payload };
|
|
65
|
+
for (const listener of listeners[type] || []) listener.call(this, event);
|
|
66
|
+
return event;
|
|
67
|
+
},
|
|
68
|
+
focus() {
|
|
69
|
+
if (document.activeElement === this) return;
|
|
70
|
+
document.activeElement?.blur();
|
|
71
|
+
document.activeElement = this;
|
|
72
|
+
this.dispatch('focus');
|
|
73
|
+
},
|
|
74
|
+
blur() {
|
|
75
|
+
if (document.activeElement !== this) return;
|
|
76
|
+
document.activeElement = null;
|
|
77
|
+
this.dispatch('blur');
|
|
78
|
+
},
|
|
79
|
+
remove() { this.blur(); this.isConnected = false; },
|
|
80
|
+
removeAttribute(name) { if (name === 'maxlength') delete this.maxLength; },
|
|
81
|
+
setSelectionRange(start, end, direction = 'none') {
|
|
82
|
+
this.selectionStart = start; this.selectionEnd = end; this.selectionDirection = direction;
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
const sandbox = { console, ctx, document, requestAnimationFrame: () => 1,
|
|
88
|
+
PointerEvent: pointerEvents ? class {} : undefined,
|
|
89
|
+
Path2D: class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} rect() {} } };
|
|
90
|
+
const keydownListeners = [];
|
|
91
|
+
if (keyboardEvents) sandbox.addEventListener = (type, listener) => {
|
|
92
|
+
if (type === 'keydown') keydownListeners.push(listener);
|
|
93
|
+
};
|
|
94
|
+
const pressTab = () => {
|
|
95
|
+
const event = { key: 'Tab', target: document.activeElement || canvas, defaultPrevented: false,
|
|
96
|
+
preventDefault() { this.defaultPrevented = true; } };
|
|
97
|
+
for (const listener of keydownListeners) listener(event);
|
|
98
|
+
return event.defaultPrevented;
|
|
99
|
+
};
|
|
100
|
+
sandbox.window = sandbox;
|
|
101
|
+
runInNewContext(SWFLIB_SOURCE, sandbox);
|
|
102
|
+
const runtime = sandbox.__swoof_swflib;
|
|
103
|
+
const engine = generateTimelineEngine(authored, {
|
|
104
|
+
frameCount: 1, sharedFactory: true,
|
|
105
|
+
});
|
|
106
|
+
const movie = runInNewContext(`
|
|
107
|
+
__swoof_swflib.timelineHelpers = ${timelineHelpersSource()};
|
|
108
|
+
__swoof_swflib.createTimelineEngine = ${timelineEngineFactorySource()};
|
|
109
|
+
__swoof_swflib.createAvm1Runtime = ${AVM1_RUNTIME_FACTORY_SOURCE};
|
|
110
|
+
var STAGE_WIDTH = ${width}, STAGE_HEIGHT = ${height}, FRAME_RATE = 30, BACKGROUND = '#fff';
|
|
111
|
+
var loaded = ${JSON.stringify(authored.loaded || [])}, ASSETS = [], SYMBOL_CLASSES = [], EXPORT_ASSETS = [];
|
|
112
|
+
var root = ${avm1 ? '{}' : 'new __swoof_swflib.builtins.MovieClip()'};
|
|
113
|
+
var __swoof_root = root;
|
|
114
|
+
window.__swoof = { root };
|
|
115
|
+
${engine}
|
|
116
|
+
${avm1 ? AVM1_RUNTIME_BOOTSTRAP : ''}
|
|
117
|
+
if (!${avm1}) __swoof_swflib.stage.addChild(root);
|
|
118
|
+
({ root, timeline, selection: ${avm1 ? 'Selection' : 'null'},
|
|
119
|
+
member: ${avm1 ? '_member' : 'null'}, getProperty: ${avm1 ? '_getProperty' : 'null'} });
|
|
120
|
+
`, sandbox);
|
|
121
|
+
return { ...movie, runtime, document, canvas, ctx, hud, draws, textColors, dispatchCanvas, pressTab,
|
|
122
|
+
controls: () => hud.children.filter(el => el.isConnected) };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
describe('programmatic editable text overlays', () => {
|
|
126
|
+
it('keeps the AVM1 new-text style separate until the next plain assignment', () => {
|
|
127
|
+
const { root, runtime, timeline, document, controls } = mountMovie(true);
|
|
128
|
+
root.createTextField('editor', 1, 10, 10, 120, 32);
|
|
129
|
+
const field = root.editor;
|
|
130
|
+
field.type = 'input';
|
|
131
|
+
field.text = 'Current label';
|
|
132
|
+
timeline.enter();
|
|
133
|
+
const [editor] = controls();
|
|
134
|
+
editor.focus();
|
|
135
|
+
const oldStyle = { fontSize: editor.style.fontSize, color: editor.style.color };
|
|
136
|
+
const next = new runtime.builtins.TextFormat('Arial', 24, 0xd83221);
|
|
137
|
+
field.setNewTextFormat(next);
|
|
138
|
+
next.size = 36;
|
|
139
|
+
timeline.render();
|
|
140
|
+
expect(editor.style).toMatchObject(oldStyle);
|
|
141
|
+
expect(editor.value).toBe('Current label');
|
|
142
|
+
expect(document.activeElement).toBe(editor);
|
|
143
|
+
|
|
144
|
+
editor.blur();
|
|
145
|
+
field.text = 'New label';
|
|
146
|
+
timeline.render();
|
|
147
|
+
expect(controls()[0]).toBe(editor);
|
|
148
|
+
expect(editor.value).toBe('New label');
|
|
149
|
+
expect(editor.style).toMatchObject({ fontSize: '24px', color: '#d83221' });
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('paints styled input fields on Canvas and removes their editable controls', () => {
|
|
153
|
+
const { root, runtime, timeline, controls, draws } = mountMovie();
|
|
154
|
+
const field = root.addChild(new runtime.builtins.TextField());
|
|
155
|
+
field.type = 'input';
|
|
156
|
+
timeline.enter();
|
|
157
|
+
expect(controls()).toHaveLength(1);
|
|
158
|
+
|
|
159
|
+
const sheet = new runtime.builtins.StyleSheet();
|
|
160
|
+
sheet.parseCSS('.message { color: #aa3300; }');
|
|
161
|
+
field.styleSheet = sheet;
|
|
162
|
+
field.htmlText = '<span class="message">Styled</span>';
|
|
163
|
+
timeline.render();
|
|
164
|
+
expect(controls()).toEqual([]);
|
|
165
|
+
expect(draws).toContain('Styled');
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('aligns the editable layer with resized and cropped stage canvases', () => {
|
|
169
|
+
const { root, runtime, timeline, canvas, hud, controls } = mountMovie();
|
|
170
|
+
const field = root.addChild(new runtime.builtins.TextField());
|
|
171
|
+
Object.assign(field, { type: 'input', x: 20, y: 30, width: 80, height: 15 });
|
|
172
|
+
Object.assign(canvas, {
|
|
173
|
+
width: 360, height: 150,
|
|
174
|
+
getBoundingClientRect: () => ({ left: 0, top: 0, width: 360, height: 150 }),
|
|
175
|
+
});
|
|
176
|
+
timeline.enter();
|
|
177
|
+
const [input] = controls();
|
|
178
|
+
expect(hud.style).toMatchObject({ width: '360px', height: '150px', transform: 'scale(1,1)' });
|
|
179
|
+
expect(input.style.transform).toBe('matrix(1,0,0,1,20,30)');
|
|
180
|
+
|
|
181
|
+
Object.assign(canvas, {
|
|
182
|
+
width: 200, height: 100, style: { marginLeft: '-60px', marginTop: '0px' },
|
|
183
|
+
getBoundingClientRect: () => ({ left: -60, top: 0, width: 400, height: 200 }),
|
|
184
|
+
});
|
|
185
|
+
timeline.render();
|
|
186
|
+
expect(hud.style).toMatchObject({
|
|
187
|
+
width: '200px', height: '100px', left: '-60px', top: '0px', transform: 'scale(2,2)',
|
|
188
|
+
});
|
|
189
|
+
expect(controls()).toEqual([input]);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('hydrates Nv2 authored AS3 HTML inputs from plain text while preserving literal user edits', async () => {
|
|
193
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/Nv2.swf'));
|
|
194
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
195
|
+
const ids = [184, 299, 1162];
|
|
196
|
+
const selected = new SymbolTable();
|
|
197
|
+
for (const id of ids) selected.set(id, symbolTable.get(id));
|
|
198
|
+
const { characters } = buildDisplayList([], selected, diagnostics);
|
|
199
|
+
const { root, timeline, controls } = mountMovie(false, {
|
|
200
|
+
characters,
|
|
201
|
+
frames: [{ places: ids.map((id, index) => ({
|
|
202
|
+
characterId: id, depth: index + 1, name: 'field' + id,
|
|
203
|
+
matrix: { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: index * 560 },
|
|
204
|
+
})) }],
|
|
205
|
+
});
|
|
206
|
+
timeline.enter();
|
|
207
|
+
timeline.render();
|
|
208
|
+
const [search, login, editor] = controls();
|
|
209
|
+
expect([search.value, login.value, editor.value]).toEqual(['', '', 'some really long level name here...']);
|
|
210
|
+
expect(root.field299.htmlText).toBe('<p align="left"></p>');
|
|
211
|
+
|
|
212
|
+
login.value = '<b>literal</b>';
|
|
213
|
+
login.dispatch('input');
|
|
214
|
+
timeline.render();
|
|
215
|
+
expect(root.field299.text).toBe('<b>literal</b>');
|
|
216
|
+
expect(login.value).toBe('<b>literal</b>');
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('exposes the original Line Rider HTML mode to AVM1 text components', async () => {
|
|
220
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/linerider1.swf'));
|
|
221
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
222
|
+
const selected = new SymbolTable();
|
|
223
|
+
const plainId = 62, htmlId = 229;
|
|
224
|
+
for (const id of [plainId, htmlId]) {
|
|
225
|
+
const field = symbolTable.get(id);
|
|
226
|
+
selected.set(id, field);
|
|
227
|
+
if (field.fontId != null) selected.set(field.fontId, symbolTable.get(field.fontId));
|
|
228
|
+
}
|
|
229
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
230
|
+
const { root, timeline, member } = mountMovie(true, { characters, frames: [{ places: [
|
|
231
|
+
{ characterId: htmlId, depth: 1, name: 'promptField' },
|
|
232
|
+
{ characterId: plainId, depth: 2, name: 'saveField' },
|
|
233
|
+
] }] });
|
|
234
|
+
timeline.enter();
|
|
235
|
+
expect(member(root.promptField, 'html')).toBe(true);
|
|
236
|
+
expect(root.promptField.htmlText).toContain('<font');
|
|
237
|
+
expect(root.promptField.text).toContain('Are you sure you want to delete the track?');
|
|
238
|
+
expect(member(root.saveField, 'html')).toBe(false);
|
|
239
|
+
expect(member(root.createTextField('created', 6, 0, 0, 50, 20), 'html')).toBe(false);
|
|
240
|
+
root.saveField.html = true;
|
|
241
|
+
root.saveField.htmlText = '<b>Track name</b>';
|
|
242
|
+
expect(member(root.saveField, 'html')).toBe(true);
|
|
243
|
+
expect(root.saveField.text).toBe('Track name');
|
|
244
|
+
root.saveField.html = false;
|
|
245
|
+
expect(member(root.saveField, 'html')).toBe(false);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('keeps Motherload’s authored AVM1 password mode in sync across native input and Canvas', async () => {
|
|
249
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/flasharchive/Motherload.swf'));
|
|
250
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
251
|
+
const id = 176, dialog = 202;
|
|
252
|
+
const selected = new SymbolTable();
|
|
253
|
+
for (const characterId of [id, dialog, symbolTable.get(id).fontId]) {
|
|
254
|
+
selected.set(characterId, symbolTable.get(characterId));
|
|
255
|
+
}
|
|
256
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
257
|
+
const placement = characters[dialog].frames[0].places.find(place => place.characterId === id);
|
|
258
|
+
const { root, timeline, controls, member, draws } = mountMovie(true, {
|
|
259
|
+
characters, frames: [{ places: [placement] }],
|
|
260
|
+
});
|
|
261
|
+
timeline.enter();
|
|
262
|
+
root._x = -120;
|
|
263
|
+
root._y = -160;
|
|
264
|
+
timeline.render();
|
|
265
|
+
const field = root.passInput;
|
|
266
|
+
expect(member(field, 'password')).toBe(true);
|
|
267
|
+
expect(controls()[0].type).toBe('password');
|
|
268
|
+
field.text = 'Sample';
|
|
269
|
+
field.password = false;
|
|
270
|
+
timeline.render();
|
|
271
|
+
expect(field.displayAsPassword).toBe(false);
|
|
272
|
+
expect(controls()[0].type).toBe('text');
|
|
273
|
+
|
|
274
|
+
field.type = 'dynamic';
|
|
275
|
+
field.embedFonts = false;
|
|
276
|
+
timeline.render();
|
|
277
|
+
expect(draws.splice(0)).toContain('Sample');
|
|
278
|
+
field.password = true;
|
|
279
|
+
timeline.render();
|
|
280
|
+
expect(field.displayAsPassword).toBe(true);
|
|
281
|
+
expect(draws).toContain('******');
|
|
282
|
+
expect(field.text).toBe('Sample');
|
|
283
|
+
expect(member(root.createTextField('created', 20, 0, 0, 40, 20), 'password')).toBe(false);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('paints the Nv2 level-name editor background in the native control and its Canvas fallback', async () => {
|
|
287
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/Nv2.swf'));
|
|
288
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
289
|
+
const selected = new SymbolTable();
|
|
290
|
+
const id = 1162;
|
|
291
|
+
selected.set(id, symbolTable.get(id));
|
|
292
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
293
|
+
const { root, timeline, controls, document, ctx } = mountMovie(false, {
|
|
294
|
+
characters,
|
|
295
|
+
frames: [{ places: [{ characterId: id, depth: 2, name: 'textfield_levelname' }] }],
|
|
296
|
+
});
|
|
297
|
+
timeline.enter();
|
|
298
|
+
const [editor] = controls();
|
|
299
|
+
const field = root.textfield_levelname;
|
|
300
|
+
expect(editor.style.background).toBe('transparent');
|
|
301
|
+
editor.focus();
|
|
302
|
+
editor.setSelectionRange(1, 5, 'backward');
|
|
303
|
+
|
|
304
|
+
// The original Editor constructor enables this field’s background.
|
|
305
|
+
field.background = true;
|
|
306
|
+
timeline.render();
|
|
307
|
+
expect(editor.style.background).toBe('#ffffff');
|
|
308
|
+
field.backgroundColor = 0x445566;
|
|
309
|
+
timeline.render();
|
|
310
|
+
expect(editor.style.background).toBe('#445566');
|
|
311
|
+
field.background = false;
|
|
312
|
+
timeline.render();
|
|
313
|
+
expect(editor.style.background).toBe('transparent');
|
|
314
|
+
expect(controls()[0] === editor).toBe(true);
|
|
315
|
+
expect(document.activeElement === editor).toBe(true);
|
|
316
|
+
expect([editor.selectionStart, editor.selectionEnd, editor.selectionDirection]).toEqual([1, 5, 'backward']);
|
|
317
|
+
|
|
318
|
+
const fills = [];
|
|
319
|
+
ctx.fillRect = (...bounds) => fills.push([ctx.fillStyle, ...bounds]);
|
|
320
|
+
Object.assign(field, { mouseEnabled: false, background: true, width: 120, height: 33 });
|
|
321
|
+
timeline.render();
|
|
322
|
+
expect(field.type).toBe('input');
|
|
323
|
+
expect(controls()).toHaveLength(0);
|
|
324
|
+
expect(fills.splice(0)).toContainEqual(['#445566', 0, 0, 120, 33]);
|
|
325
|
+
field.background = false;
|
|
326
|
+
timeline.render();
|
|
327
|
+
expect(fills).not.toContainEqual(['#445566', 0, 0, 120, 33]);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it.each([true, false])('routes authored AS3 editor movement through the stage with pointer events=%s', async pointerEvents => {
|
|
331
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/Nv2.swf'));
|
|
332
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
333
|
+
const id = 1162;
|
|
334
|
+
const selected = new SymbolTable();
|
|
335
|
+
selected.set(id, symbolTable.get(id));
|
|
336
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
337
|
+
const { root, timeline, controls, dispatchCanvas, runtime, document } = mountMovie(false, {
|
|
338
|
+
characters,
|
|
339
|
+
frames: [{ places: [{ characterId: id, depth: 2, name: 'textfield_levelname',
|
|
340
|
+
matrix: { a: 1, b: 0.1, c: 0.2, d: 1, tx: 300, ty: 600 } }] }],
|
|
341
|
+
}, { pointerEvents });
|
|
342
|
+
timeline.enter();
|
|
343
|
+
const [editor] = controls();
|
|
344
|
+
const field = root.textfield_levelname;
|
|
345
|
+
const { Point, Mouse, MouseEvent, Multitouch } = runtime.builtins;
|
|
346
|
+
const move = pointerEvents ? 'pointermove' : 'mousemove';
|
|
347
|
+
const down = pointerEvents ? 'pointerdown' : 'mousedown';
|
|
348
|
+
const point = (x, y) => field.localToGlobal(new Point(x, y));
|
|
349
|
+
const options = position => ({ clientX: position.x, clientY: position.y });
|
|
350
|
+
dispatchCanvas(move, options(point(3, 3)));
|
|
351
|
+
editor.focus();
|
|
352
|
+
editor.setSelectionRange(1, 5, 'backward');
|
|
353
|
+
|
|
354
|
+
const moves = [];
|
|
355
|
+
let presses = 0;
|
|
356
|
+
runtime.stage.addEventListener(MouseEvent.MOUSE_MOVE, event => moves.push(event));
|
|
357
|
+
runtime.stage.addEventListener(MouseEvent.MOUSE_DOWN, () => { presses++; });
|
|
358
|
+
editor.dispatch(move, options(point(8, 8)));
|
|
359
|
+
const updated = point(13, 12);
|
|
360
|
+
editor.dispatch(move, { ...options(updated), buttons: 1, shiftKey: true });
|
|
361
|
+
expect(field.mouseX).toBeCloseTo(13, 8);
|
|
362
|
+
expect(field.mouseY).toBeCloseTo(12, 8);
|
|
363
|
+
expect(runtime.stage.mouseX).toBeCloseTo(updated.x, 8);
|
|
364
|
+
expect(runtime.stage.mouseY).toBeCloseTo(updated.y, 8);
|
|
365
|
+
expect(moves).toHaveLength(2);
|
|
366
|
+
expect(moves[1].target).toBe(field);
|
|
367
|
+
expect(moves[1].bubbles).toBe(true);
|
|
368
|
+
expect(moves[1].localX).toBeCloseTo(13, 8);
|
|
369
|
+
expect(moves[1].localY).toBeCloseTo(12, 8);
|
|
370
|
+
expect(moves[1].stageX).toBeCloseTo(updated.x, 8);
|
|
371
|
+
expect(moves[1].stageY).toBeCloseTo(updated.y, 8);
|
|
372
|
+
expect(moves[1].buttonDown).toBe(true);
|
|
373
|
+
expect(moves[1].shiftKey).toBe(true);
|
|
374
|
+
|
|
375
|
+
editor.dispatch(move, { ...options(point(21, 10)), isPrimary: false });
|
|
376
|
+
Multitouch.mapTouchToMouse = false;
|
|
377
|
+
editor.dispatch(move, { ...options(point(21, 10)), isPrimary: true, pointerType: 'touch' });
|
|
378
|
+
expect(field.mouseX).toBeCloseTo(13, 8);
|
|
379
|
+
const press = editor.dispatch(down, { ...options(point(15, 14)), button: 0, buttons: 1 });
|
|
380
|
+
expect(field.mouseX).toBeCloseTo(15, 8);
|
|
381
|
+
expect(field.mouseY).toBeCloseTo(14, 8);
|
|
382
|
+
expect(press.defaultPrevented).toBe(false);
|
|
383
|
+
expect(Mouse._isDown).toBe(false);
|
|
384
|
+
expect(moves).toHaveLength(2);
|
|
385
|
+
expect(presses).toBe(0);
|
|
386
|
+
expect(document.activeElement).toBe(editor);
|
|
387
|
+
expect([editor.selectionStart, editor.selectionEnd, editor.selectionDirection]).toEqual([1, 5, 'backward']);
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
it.each([true, false])('resizes the authored Nv2 text viewport in place and on Canvas with AVM1=%s', async avm1 => {
|
|
391
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/Nv2.swf'));
|
|
392
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
393
|
+
const selected = new SymbolTable();
|
|
394
|
+
const id = 1162;
|
|
395
|
+
selected.set(id, symbolTable.get(id));
|
|
396
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
397
|
+
const { root, timeline, controls, document, ctx, draws, dispatchCanvas } = mountMovie(avm1, {
|
|
398
|
+
characters,
|
|
399
|
+
frames: [{ places: [{ characterId: id, depth: 2, name: 'textfield_levelname' }] }],
|
|
400
|
+
}, { pointerEvents: true });
|
|
401
|
+
timeline.enter();
|
|
402
|
+
const [editor] = controls();
|
|
403
|
+
const field = root.textfield_levelname;
|
|
404
|
+
expect([editor.style.width, editor.style.height]).toEqual(['360.95px', '15px']);
|
|
405
|
+
const transform = editor.style.transform;
|
|
406
|
+
editor.focus();
|
|
407
|
+
editor.setSelectionRange(1, 5, 'backward');
|
|
408
|
+
field.width = 120;
|
|
409
|
+
field.height = 33;
|
|
410
|
+
timeline.render();
|
|
411
|
+
expect([editor.style.width, editor.style.height, editor.style.transform]).toEqual(['120px', '33px', transform]);
|
|
412
|
+
expect(controls()[0] === editor).toBe(true);
|
|
413
|
+
expect(document.activeElement === editor).toBe(true);
|
|
414
|
+
expect([editor.selectionStart, editor.selectionEnd, editor.selectionDirection]).toEqual([1, 5, 'backward']);
|
|
415
|
+
|
|
416
|
+
const paintRects = [];
|
|
417
|
+
ctx.rect = (...values) => paintRects.push(values);
|
|
418
|
+
Object.assign(field, { type: 'dynamic', multiline: true, text: 'one\ntwo\nthree\nfour\nfive' });
|
|
419
|
+
timeline.render();
|
|
420
|
+
expect(paintRects).toContainEqual([0, 0, 120, 33]);
|
|
421
|
+
expect(controls()).toHaveLength(0);
|
|
422
|
+
if (avm1) {
|
|
423
|
+
expect(timeline.pickAvm1CanvasText(100, 25) === field).toBe(true);
|
|
424
|
+
expect(timeline.pickAvm1CanvasText(130, 5)).toBeNull();
|
|
425
|
+
} else {
|
|
426
|
+
dispatchCanvas('pointerdown', { clientX: 100, clientY: 25 });
|
|
427
|
+
expect(dispatchCanvas('wheel', { clientX: 100, clientY: 25, deltaY: 1, deltaMode: 1 }).defaultPrevented).toBe(true);
|
|
428
|
+
expect(field.scrollV).toBe(2);
|
|
429
|
+
dispatchCanvas('pointerdown', { clientX: 130, clientY: 5 });
|
|
430
|
+
expect(dispatchCanvas('wheel', { clientX: 130, clientY: 5, deltaY: 1, deltaMode: 1 }).defaultPrevented).toBe(false);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
field.width = 0;
|
|
434
|
+
draws.length = 0;
|
|
435
|
+
timeline.render();
|
|
436
|
+
expect(draws).toEqual([]);
|
|
437
|
+
field.type = 'input';
|
|
438
|
+
timeline.render();
|
|
439
|
+
expect(controls()).toHaveLength(0);
|
|
440
|
+
field.width = 40;
|
|
441
|
+
timeline.render();
|
|
442
|
+
const [restored] = controls();
|
|
443
|
+
expect([restored.style.width, restored.style.height, restored.style.transform]).toEqual(['40px', '33px', transform]);
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
it.each([true, false])('uses live alignment on the authored Nv2 text field with AVM1=%s', async avm1 => {
|
|
447
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/Nv2.swf'));
|
|
448
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
449
|
+
const selected = new SymbolTable();
|
|
450
|
+
const id = 1162;
|
|
451
|
+
selected.set(id, symbolTable.get(id));
|
|
452
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
453
|
+
const { root, timeline, controls, document, ctx } = mountMovie(avm1, {
|
|
454
|
+
characters,
|
|
455
|
+
frames: [{ places: [{ characterId: id, depth: 2, name: 'textfield_levelname' }] }],
|
|
456
|
+
});
|
|
457
|
+
timeline.enter();
|
|
458
|
+
const field = root.textfield_levelname;
|
|
459
|
+
Object.assign(field, { text: 'ABC', width: 120, height: 40 });
|
|
460
|
+
timeline.render();
|
|
461
|
+
const [editor] = controls();
|
|
462
|
+
expect(editor.style.textAlign).toBe('left');
|
|
463
|
+
editor.focus();
|
|
464
|
+
const applyAlign = align => field.setTextFormat(Object.assign(field.getTextFormat(), { align }));
|
|
465
|
+
applyAlign('center');
|
|
466
|
+
timeline.render();
|
|
467
|
+
expect(editor.style.textAlign).toBe('center');
|
|
468
|
+
expect(document.activeElement === editor).toBe(true);
|
|
469
|
+
|
|
470
|
+
const draws = [];
|
|
471
|
+
ctx.fillText = (text, x) => draws.push([text, x]);
|
|
472
|
+
field.type = 'dynamic';
|
|
473
|
+
timeline.render();
|
|
474
|
+
expect(draws.splice(0)).toEqual([['ABC', 51]]);
|
|
475
|
+
field.htmlText = '<p align="right">ABC</p>';
|
|
476
|
+
timeline.render();
|
|
477
|
+
expect(draws.splice(0)).toEqual([['ABC', 102]]);
|
|
478
|
+
field.defaultTextFormat = Object.assign(field.getTextFormat(), { align: null });
|
|
479
|
+
field.text = 'ABC';
|
|
480
|
+
timeline.render();
|
|
481
|
+
expect(draws).toEqual([['ABC', 0]]);
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
it.each([true, false])('applies live Nv2 paragraph spacing while retaining measured scrolling with AVM1=%s', async avm1 => {
|
|
485
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/Nv2.swf'));
|
|
486
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
487
|
+
const selected = new SymbolTable();
|
|
488
|
+
const id = 1162;
|
|
489
|
+
selected.set(id, symbolTable.get(id));
|
|
490
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
491
|
+
const { root, timeline, controls, document, ctx } = mountMovie(avm1, {
|
|
492
|
+
characters,
|
|
493
|
+
frames: [{ places: [{ characterId: id, depth: 2, name: 'textfield_levelname' }] }],
|
|
494
|
+
});
|
|
495
|
+
timeline.enter();
|
|
496
|
+
const field = root.textfield_levelname;
|
|
497
|
+
Object.assign(field, { width: 120, height: 52 });
|
|
498
|
+
const [editor] = controls();
|
|
499
|
+
Object.assign(editor, { clientWidth: 118, scrollWidth: 154 });
|
|
500
|
+
editor.focus();
|
|
501
|
+
editor.setSelectionRange(1, 5, 'backward');
|
|
502
|
+
const scroll = avm1 ? 'hscroll' : 'scrollH';
|
|
503
|
+
const setSpacing = (leftMargin, rightMargin, indent) => {
|
|
504
|
+
field.setTextFormat(Object.assign(field.getTextFormat(), { leftMargin, rightMargin, indent }));
|
|
505
|
+
};
|
|
506
|
+
field[scroll] = 26;
|
|
507
|
+
timeline.render();
|
|
508
|
+
expect([field.maxScrollH, editor.scrollLeft]).toEqual([36, 26]);
|
|
509
|
+
|
|
510
|
+
setSpacing(12, 15, 7);
|
|
511
|
+
editor.scrollWidth = 181;
|
|
512
|
+
timeline.render();
|
|
513
|
+
expect([editor.style.paddingLeft, editor.style.paddingRight, editor.style.textIndent]).toEqual(['13px', '16px', '7px']);
|
|
514
|
+
expect([field.maxScrollH, field[scroll], editor.scrollLeft]).toEqual([63, 26, 26]);
|
|
515
|
+
field[scroll] = 1000;
|
|
516
|
+
timeline.render();
|
|
517
|
+
expect(editor.scrollLeft).toBe(63);
|
|
518
|
+
|
|
519
|
+
setSpacing(0, 0, 0);
|
|
520
|
+
editor.scrollWidth = 154;
|
|
521
|
+
timeline.render();
|
|
522
|
+
expect([editor.style.paddingLeft, editor.style.paddingRight, editor.style.textIndent]).toEqual(['1px', '1px', '0px']);
|
|
523
|
+
expect([field.maxScrollH, field[scroll], editor.scrollLeft]).toEqual([36, 36, 36]);
|
|
524
|
+
expect(controls()[0] === editor).toBe(true);
|
|
525
|
+
expect(document.activeElement === editor).toBe(true);
|
|
526
|
+
expect([editor.selectionStart, editor.selectionEnd, editor.selectionDirection]).toEqual([1, 5, 'backward']);
|
|
527
|
+
|
|
528
|
+
const draws = [];
|
|
529
|
+
ctx.fillText = (text, x) => draws.push([text, x]);
|
|
530
|
+
Object.assign(field, { type: 'dynamic', wordWrap: true, text: 'ABCDEFGHIJKLMNO' });
|
|
531
|
+
setSpacing(12, 15, 7);
|
|
532
|
+
timeline.render();
|
|
533
|
+
expect(draws).toEqual([['ABCDEFGHIJKLMN', 19], ['O', 12]]);
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
it.each([true, false])('uses the authored Nv2 border and live border color with AVM1=%s', async avm1 => {
|
|
537
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/Nv2.swf'));
|
|
538
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
539
|
+
const selected = new SymbolTable();
|
|
540
|
+
const id = 1162;
|
|
541
|
+
selected.set(id, symbolTable.get(id));
|
|
542
|
+
expect(selected.get(id).border).toBe(true);
|
|
543
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
544
|
+
const { root, timeline, controls, document, ctx } = mountMovie(avm1, {
|
|
545
|
+
characters,
|
|
546
|
+
frames: [{ places: [{ characterId: id, depth: 2, name: 'textfield_levelname' }] }],
|
|
547
|
+
});
|
|
548
|
+
timeline.enter();
|
|
549
|
+
const field = root.textfield_levelname;
|
|
550
|
+
const [editor] = controls();
|
|
551
|
+
expect([field.border, field.borderColor, editor.style.border]).toEqual([true, 0, '1px solid #000000']);
|
|
552
|
+
editor.focus();
|
|
553
|
+
editor.setSelectionRange(1, 5, 'backward');
|
|
554
|
+
field.setTextFormat(Object.assign(field.getTextFormat(), { leftMargin: 5, rightMargin: 7 }));
|
|
555
|
+
timeline.render();
|
|
556
|
+
expect([editor.style.paddingLeft, editor.style.paddingRight]).toEqual(['6px', '8px']);
|
|
557
|
+
|
|
558
|
+
Object.assign(field, { border: false, borderColor: 0x445566 });
|
|
559
|
+
timeline.render();
|
|
560
|
+
expect([editor.style.border, editor.style.paddingLeft, editor.style.paddingRight]).toEqual(['none', '5px', '7px']);
|
|
561
|
+
field.border = true;
|
|
562
|
+
timeline.render();
|
|
563
|
+
expect([editor.style.border, editor.style.paddingLeft, editor.style.paddingRight]).toEqual(['1px solid #445566', '6px', '8px']);
|
|
564
|
+
expect(controls()[0] === editor).toBe(true);
|
|
565
|
+
expect(document.activeElement === editor).toBe(true);
|
|
566
|
+
expect([editor.selectionStart, editor.selectionEnd, editor.selectionDirection]).toEqual([1, 5, 'backward']);
|
|
567
|
+
|
|
568
|
+
const strokes = [];
|
|
569
|
+
editor.blur();
|
|
570
|
+
ctx.strokeRect = () => strokes.push(ctx.strokeStyle);
|
|
571
|
+
field.type = 'dynamic';
|
|
572
|
+
timeline.render();
|
|
573
|
+
expect(strokes.splice(0)).toEqual(['#445566']);
|
|
574
|
+
field.border = false;
|
|
575
|
+
timeline.render();
|
|
576
|
+
expect(strokes).toEqual([]);
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
it.each([true, false])('keeps live device fonts when an authored Nv2 field moves to Canvas with AVM1=%s', async avm1 => {
|
|
580
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/Nv2.swf'));
|
|
581
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
582
|
+
const selected = new SymbolTable();
|
|
583
|
+
const id = 1162;
|
|
584
|
+
const edit = symbolTable.get(id);
|
|
585
|
+
const font = symbolTable.get(edit.fontId);
|
|
586
|
+
selected.set(id, edit);
|
|
587
|
+
selected.set(edit.fontId, font);
|
|
588
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
589
|
+
const { root, timeline, controls, ctx } = mountMovie(avm1, {
|
|
590
|
+
characters,
|
|
591
|
+
frames: [{ places: [{ characterId: id, depth: 2, name: 'textfield_levelname' }] }],
|
|
592
|
+
});
|
|
593
|
+
timeline.enter();
|
|
594
|
+
const field = root.textfield_levelname;
|
|
595
|
+
const applyFont = family => field.setTextFormat(Object.assign(field.getTextFormat(), { font: family }));
|
|
596
|
+
Object.assign(field, { embedFonts: false, text: 'ABC' });
|
|
597
|
+
applyFont('Courier New');
|
|
598
|
+
timeline.render();
|
|
599
|
+
expect(controls()[0].style.fontFamily).toBe('"Courier New", Arial, sans-serif');
|
|
600
|
+
|
|
601
|
+
const device = [], outlines = [];
|
|
602
|
+
ctx.fillText = text => device.push([text, ctx.font]);
|
|
603
|
+
ctx.fill = outline => outlines.push(outline);
|
|
604
|
+
field.type = 'dynamic';
|
|
605
|
+
timeline.render();
|
|
606
|
+
expect(device.splice(0)).toEqual([['ABC', '16px "Courier New"']]);
|
|
607
|
+
|
|
608
|
+
field.htmlText = '<font face="Georgia">ABC</font>';
|
|
609
|
+
timeline.render();
|
|
610
|
+
expect(device.splice(0)).toEqual([['ABC', '16px "Georgia"']]);
|
|
611
|
+
expect(outlines).toHaveLength(0);
|
|
612
|
+
|
|
613
|
+
field.text = 'ABC';
|
|
614
|
+
field.defaultTextFormat = Object.assign(field.getTextFormat(), { font: null });
|
|
615
|
+
timeline.render();
|
|
616
|
+
expect(device.splice(0)).toEqual([['ABC', `16px "${font.name}"`]]);
|
|
617
|
+
field.embedFonts = true;
|
|
618
|
+
timeline.render();
|
|
619
|
+
expect(device).toEqual([]);
|
|
620
|
+
expect(outlines).toHaveLength(3);
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
it('maps the original N editor device font to monospace in native and Canvas text', async () => {
|
|
624
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/flasharchive/N.swf'));
|
|
625
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
626
|
+
const selected = new SymbolTable();
|
|
627
|
+
for (const id of [591, 593]) {
|
|
628
|
+
const edit = symbolTable.get(id);
|
|
629
|
+
const font = symbolTable.get(edit.fontId);
|
|
630
|
+
expect(edit.useOutlines).toBe(false);
|
|
631
|
+
expect(font.name).toBe('_typewriter');
|
|
632
|
+
selected.set(id, edit);
|
|
633
|
+
selected.set(edit.fontId, font);
|
|
634
|
+
}
|
|
635
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
636
|
+
const { root, timeline, controls, ctx } = mountMovie(true, {
|
|
637
|
+
characters,
|
|
638
|
+
frames: [{ places: [
|
|
639
|
+
{ characterId: 591, depth: 1, name: 'editor' },
|
|
640
|
+
{ characterId: 593, depth: 2, name: 'label' },
|
|
641
|
+
] }],
|
|
642
|
+
});
|
|
643
|
+
timeline.enter();
|
|
644
|
+
const painted = [];
|
|
645
|
+
ctx.fillText = text => painted.push([text, ctx.font]);
|
|
646
|
+
timeline.render();
|
|
647
|
+
const [editor] = controls();
|
|
648
|
+
expect(root.editor.defaultTextFormat.font).toBe('_typewriter');
|
|
649
|
+
expect(editor.style.fontFamily).toBe('monospace');
|
|
650
|
+
expect(painted.splice(0)).toContainEqual([' demo data', '8px monospace']);
|
|
651
|
+
|
|
652
|
+
root.editor.defaultTextFormat.font = '_serif';
|
|
653
|
+
root.label.defaultTextFormat.font = '_sans';
|
|
654
|
+
timeline.render();
|
|
655
|
+
expect(controls()[0]).toBe(editor);
|
|
656
|
+
expect(editor.style.fontFamily).toBe('serif');
|
|
657
|
+
expect(painted).toContainEqual([' demo data', '8px sans-serif']);
|
|
658
|
+
});
|
|
659
|
+
|
|
660
|
+
it('preserves the original Boxhead 2Play username spacing in the native input', async () => {
|
|
661
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/boxhead_2play.swf'));
|
|
662
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
663
|
+
const textId = 373;
|
|
664
|
+
const edit = symbolTable.get(textId);
|
|
665
|
+
expect(edit).toMatchObject({ readOnly: false, html: true });
|
|
666
|
+
expect(edit.initialText).toContain('letterSpacing="-2.000000"');
|
|
667
|
+
const selected = new SymbolTable();
|
|
668
|
+
for (const id of [textId, edit.fontId]) selected.set(id, symbolTable.get(id));
|
|
669
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
670
|
+
const { root, timeline, document, controls } = mountMovie(true, {
|
|
671
|
+
characters,
|
|
672
|
+
frames: [{ places: [{ characterId: textId, depth: 2, name: 'mUsername' }] }],
|
|
673
|
+
});
|
|
674
|
+
timeline.enter();
|
|
675
|
+
timeline.render();
|
|
676
|
+
const field = root.mUsername;
|
|
677
|
+
const [editor] = controls();
|
|
678
|
+
expect(editor.value).toBe('<ENTER NAME>');
|
|
679
|
+
expect(editor.style.letterSpacing).toBe('-2px');
|
|
680
|
+
editor.focus();
|
|
681
|
+
editor.setSelectionRange(1, 6, 'backward');
|
|
682
|
+
|
|
683
|
+
field.defaultTextFormat.letterSpacing = -3;
|
|
684
|
+
timeline.render();
|
|
685
|
+
expect(editor.style.letterSpacing).toBe('-2px');
|
|
686
|
+
field.htmlText = '<font letterSpacing="-2"><ENTER</font> NAME>';
|
|
687
|
+
timeline.render();
|
|
688
|
+
expect(editor.style.letterSpacing).toBe('-3px');
|
|
689
|
+
field.text = field.text;
|
|
690
|
+
timeline.render();
|
|
691
|
+
expect(editor.style.letterSpacing).toBe('-3px');
|
|
692
|
+
field.defaultTextFormat.letterSpacing = null;
|
|
693
|
+
timeline.render();
|
|
694
|
+
expect(editor.style.letterSpacing).toBe('');
|
|
695
|
+
expect(controls()[0]).toBe(editor);
|
|
696
|
+
expect(document.activeElement).toBe(editor);
|
|
697
|
+
expect([editor.selectionStart, editor.selectionEnd, editor.selectionDirection]).toEqual([1, 6, 'backward']);
|
|
698
|
+
});
|
|
699
|
+
|
|
700
|
+
it.each([
|
|
701
|
+
['archive/Swf/boxhead_2play.swf', 373, true, '<ENTER NAME>'],
|
|
702
|
+
['archive/flasharchive/Avalanche.swf', 95, false, 'Press Space to Continue'],
|
|
703
|
+
])('applies authored kerning in the native and device Canvas paths for %s EditText %i', async (file, textId, kerning, label) => {
|
|
704
|
+
const { doc, diagnostics } = await parse(readFileSync(file));
|
|
705
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
706
|
+
const edit = symbolTable.get(textId);
|
|
707
|
+
expect(edit).toMatchObject({ readOnly: false, html: true });
|
|
708
|
+
expect(edit.initialText).toContain(`kerning="${kerning ? 1 : 0}"`);
|
|
709
|
+
const font = symbolTable.get(edit.fontId);
|
|
710
|
+
if (kerning) expect(font.layout.kerning).toContainEqual([78, 65, -280]);
|
|
711
|
+
const selected = new SymbolTable();
|
|
712
|
+
selected.set(textId, edit);
|
|
713
|
+
selected.set(edit.fontId, font);
|
|
714
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
715
|
+
const { root, timeline, controls, ctx } = mountMovie(true, {
|
|
716
|
+
characters,
|
|
717
|
+
frames: [{ places: [{ characterId: textId, depth: 2, name: 'field' }] }],
|
|
718
|
+
});
|
|
719
|
+
timeline.enter();
|
|
720
|
+
timeline.render();
|
|
721
|
+
const field = root.field;
|
|
722
|
+
const [editor] = controls();
|
|
723
|
+
const authored = kerning ? 'normal' : 'none';
|
|
724
|
+
const replacement = kerning ? 'none' : 'normal';
|
|
725
|
+
expect(editor.value).toBe(label);
|
|
726
|
+
expect(editor.style.fontKerning).toBe(authored);
|
|
727
|
+
|
|
728
|
+
field.defaultTextFormat.kerning = !kerning;
|
|
729
|
+
timeline.render();
|
|
730
|
+
expect(editor.style.fontKerning).toBe(authored);
|
|
731
|
+
field.htmlText = `<font kerning="${kerning ? 1 : 0}">first</font> second`;
|
|
732
|
+
timeline.render();
|
|
733
|
+
expect(editor.style.fontKerning).toBe(replacement);
|
|
734
|
+
field.htmlText = edit.initialText;
|
|
735
|
+
field.type = 'dynamic';
|
|
736
|
+
field.embedFonts = false;
|
|
737
|
+
|
|
738
|
+
ctx.fontKerning = 'auto';
|
|
739
|
+
ctx.letterSpacing = '0px';
|
|
740
|
+
const measured = [], painted = [];
|
|
741
|
+
ctx.measureText = text => {
|
|
742
|
+
if (text === label) measured.push(ctx.fontKerning);
|
|
743
|
+
return { width: text.length * 6 };
|
|
744
|
+
};
|
|
745
|
+
ctx.fillText = text => painted.push([text, ctx.fontKerning]);
|
|
746
|
+
function expectCanvasMode(mode) {
|
|
747
|
+
measured.length = painted.length = 0;
|
|
748
|
+
timeline.render();
|
|
749
|
+
expect(measured).toContain(mode);
|
|
750
|
+
expect(painted).toContainEqual([label, mode]);
|
|
751
|
+
}
|
|
752
|
+
expectCanvasMode(authored);
|
|
753
|
+
field.text = field.text;
|
|
754
|
+
expectCanvasMode(replacement);
|
|
755
|
+
field.defaultTextFormat.kerning = null;
|
|
756
|
+
expectCanvasMode('auto');
|
|
757
|
+
field.type = 'input';
|
|
758
|
+
timeline.render();
|
|
759
|
+
expect(controls()[0].style.fontKerning).toBe('');
|
|
760
|
+
});
|
|
761
|
+
|
|
762
|
+
it.each([
|
|
763
|
+
['archive/Swf/plazma-burst-2.swf', 1107, false, 1, 'pixel', -104, 400],
|
|
764
|
+
['archive/Swf/raze-3.swf', 3091, false, 2, 'subpixel', -200, 400],
|
|
765
|
+
['archive/Swf/boxhead_2play.swf', 373, true, 2, 'subpixel', 0, 0],
|
|
766
|
+
])('exposes authored CSMTextSettings from %s EditText %i before paint', async (file, textId, avm1, gridFit, gridFitType, thickness, sharpness) => {
|
|
767
|
+
const { doc, diagnostics } = await parse(readFileSync(file));
|
|
768
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
769
|
+
const edit = symbolTable.get(textId);
|
|
770
|
+
expect(edit.csmTextSettings).toEqual({ useFlashType: 1, gridFit, thickness, sharpness });
|
|
771
|
+
const selected = new SymbolTable();
|
|
772
|
+
selected.set(textId, edit);
|
|
773
|
+
selected.set(edit.fontId, symbolTable.get(edit.fontId));
|
|
774
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
775
|
+
const { root, timeline, runtime } = mountMovie(avm1, {
|
|
776
|
+
characters,
|
|
777
|
+
frames: [{ places: [{ characterId: textId, depth: 2, name: 'field' }] }],
|
|
778
|
+
});
|
|
779
|
+
timeline.enter();
|
|
780
|
+
const field = root.field;
|
|
781
|
+
const { AntiAliasType, GridFitType } = runtime.packages.text;
|
|
782
|
+
expect(typeof AntiAliasType).toBe('function');
|
|
783
|
+
expect(typeof GridFitType).toBe('function');
|
|
784
|
+
expect([AntiAliasType.NORMAL, AntiAliasType.ADVANCED]).toEqual(['normal', 'advanced']);
|
|
785
|
+
expect([GridFitType.NONE, GridFitType.PIXEL, GridFitType.SUBPIXEL]).toEqual(['none', 'pixel', 'subpixel']);
|
|
786
|
+
expect(field).toMatchObject({ antiAliasType: AntiAliasType.ADVANCED, gridFitType, thickness, sharpness });
|
|
787
|
+
expect(new runtime.builtins.TextField()).toMatchObject({
|
|
788
|
+
antiAliasType: AntiAliasType.NORMAL, gridFitType: GridFitType.PIXEL, thickness: 0, sharpness: 0,
|
|
789
|
+
});
|
|
790
|
+
|
|
791
|
+
const edits = { antiAliasType: AntiAliasType.NORMAL, gridFitType: GridFitType.NONE, thickness: 10, sharpness: -20 };
|
|
792
|
+
Object.assign(field, edits);
|
|
793
|
+
timeline.render();
|
|
794
|
+
expect(field).toMatchObject(edits);
|
|
795
|
+
expect(edit.csmTextSettings).toEqual({ useFlashType: 1, gridFit, thickness, sharpness });
|
|
796
|
+
});
|
|
797
|
+
|
|
798
|
+
it.each([true, false])('fits the authored Nv2 news ticker from its left edge with AVM1=%s', async avm1 => {
|
|
799
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/Nv2.swf'));
|
|
800
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
801
|
+
const selected = new SymbolTable();
|
|
802
|
+
const id = 899;
|
|
803
|
+
const edit = symbolTable.get(id);
|
|
804
|
+
expect(edit).toMatchObject({ autoSize: false, wordWrap: false, readOnly: true });
|
|
805
|
+
selected.set(id, edit);
|
|
806
|
+
selected.set(edit.fontId, symbolTable.get(edit.fontId));
|
|
807
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
808
|
+
const { root, timeline, runtime, ctx } = mountMovie(avm1, {
|
|
809
|
+
characters,
|
|
810
|
+
frames: [{ places: [{ characterId: id, depth: 1, name: 'textfield' }] }],
|
|
811
|
+
});
|
|
812
|
+
timeline.enter();
|
|
813
|
+
const field = root.textfield;
|
|
814
|
+
const clips = [];
|
|
815
|
+
ctx.rect = (...bounds) => clips.push(bounds);
|
|
816
|
+
expect([field.width, field.height]).toEqual([10, 36]);
|
|
817
|
+
|
|
818
|
+
// NewsTicker applies LEFT before assigning the item description.
|
|
819
|
+
Object.assign(field, { autoSize: runtime.builtins.TextFieldAutoSize.LEFT, text: 'New levels are available', selectable: false });
|
|
820
|
+
const longWidth = field.width;
|
|
821
|
+
expect(longWidth).toBeGreaterThan(10);
|
|
822
|
+
expect(longWidth).toBe(field.textWidth);
|
|
823
|
+
expect(field.height).toBe(field.textHeight);
|
|
824
|
+
timeline.render();
|
|
825
|
+
expect(clips.splice(0)).toContainEqual([0, 0, longWidth, field.height]);
|
|
826
|
+
expect(field.x).toBe(0);
|
|
827
|
+
|
|
828
|
+
field.text = 'Next';
|
|
829
|
+
const shortWidth = field.width;
|
|
830
|
+
expect(shortWidth).toBeLessThan(longWidth);
|
|
831
|
+
expect(shortWidth).toBe(field.textWidth);
|
|
832
|
+
timeline.render();
|
|
833
|
+
expect(clips.splice(0)).toContainEqual([0, 0, shortWidth, field.height]);
|
|
834
|
+
|
|
835
|
+
field.autoSize = runtime.builtins.TextFieldAutoSize.NONE;
|
|
836
|
+
expect([field.width, field.height]).toEqual([10, 36]);
|
|
837
|
+
timeline.render();
|
|
838
|
+
expect(clips).toContainEqual([0, 0, 10, 36]);
|
|
839
|
+
});
|
|
840
|
+
|
|
841
|
+
it('grows the authored Raze 3 changelog height while keeping its wrapping width', async () => {
|
|
842
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/raze-3.swf'));
|
|
843
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
844
|
+
const selected = new SymbolTable();
|
|
845
|
+
const id = 3597;
|
|
846
|
+
const edit = symbolTable.get(id);
|
|
847
|
+
expect(edit).toMatchObject({ autoSize: false, wordWrap: true, readOnly: true });
|
|
848
|
+
selected.set(id, edit);
|
|
849
|
+
selected.set(edit.fontId, symbolTable.get(edit.fontId));
|
|
850
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
851
|
+
const { root, timeline, runtime, ctx } = mountMovie(false, {
|
|
852
|
+
characters,
|
|
853
|
+
frames: [{ places: [{ characterId: id, depth: 1, name: 'txt_versiontext' }] }],
|
|
854
|
+
});
|
|
855
|
+
timeline.enter();
|
|
856
|
+
const field = root.txt_versiontext;
|
|
857
|
+
const original = [field.width, field.height];
|
|
858
|
+
const { LEFT, NONE } = runtime.builtins.TextFieldAutoSize;
|
|
859
|
+
expect(field.autoSize).toBe(NONE);
|
|
860
|
+
expect(original).toEqual([687.95, 51.2]);
|
|
861
|
+
|
|
862
|
+
// The title enables LEFT before it assigns the version history.
|
|
863
|
+
field.autoSize = LEFT;
|
|
864
|
+
field.text = 'v1.0\n- Game is released!\n\nv1.1\n- Lower default graphics\n- Added premium content status';
|
|
865
|
+
const fittedHeight = field.height;
|
|
866
|
+
expect(field.width).toBe(original[0]);
|
|
867
|
+
expect(fittedHeight).toBeGreaterThan(original[1]);
|
|
868
|
+
expect(fittedHeight).toBe(field.textHeight);
|
|
869
|
+
expect(field.maxScrollV).toBe(1);
|
|
870
|
+
|
|
871
|
+
const clips = [];
|
|
872
|
+
ctx.rect = (...bounds) => clips.push(bounds);
|
|
873
|
+
timeline.render();
|
|
874
|
+
expect(clips.splice(0)).toContainEqual([0, 0, original[0], fittedHeight]);
|
|
875
|
+
field.width = 100;
|
|
876
|
+
expect(field.height).toBeGreaterThan(fittedHeight);
|
|
877
|
+
const narrowerHeight = field.height;
|
|
878
|
+
timeline.render();
|
|
879
|
+
expect(clips.splice(0)).toContainEqual([0, 0, 100, narrowerHeight]);
|
|
880
|
+
|
|
881
|
+
field.text = 'v1.0';
|
|
882
|
+
expect(field.height).toBeLessThan(narrowerHeight);
|
|
883
|
+
timeline.render();
|
|
884
|
+
expect(clips.splice(0)).toContainEqual([0, 0, 100, field.height]);
|
|
885
|
+
|
|
886
|
+
field.autoSize = NONE;
|
|
887
|
+
expect([field.width, field.height]).toEqual([100, original[1]]);
|
|
888
|
+
timeline.render();
|
|
889
|
+
expect(clips).toContainEqual([0, 0, 100, original[1]]);
|
|
890
|
+
});
|
|
891
|
+
|
|
892
|
+
it('sizes the authored Nv2 DynamicPrompt around its original center', async () => {
|
|
893
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/Nv2.swf'));
|
|
894
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
895
|
+
const selected = new SymbolTable();
|
|
896
|
+
const edit = symbolTable.get(490);
|
|
897
|
+
expect(edit).toMatchObject({ autoSize: false, wordWrap: false, readOnly: true });
|
|
898
|
+
for (const id of [492, 491, 490, edit.fontId]) selected.set(id, symbolTable.get(id));
|
|
899
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
900
|
+
const { root, timeline, runtime, ctx, pressTab } = mountMovie(false, {
|
|
901
|
+
characters,
|
|
902
|
+
frames: [{ places: [{ depth: 1, characterId: 492, name: 'prompt' }] }],
|
|
903
|
+
}, { keyboardEvents: true });
|
|
904
|
+
timeline.enter();
|
|
905
|
+
const field = root.prompt.message.field;
|
|
906
|
+
const clips = [];
|
|
907
|
+
ctx.rect = (x, y, width, height) => {
|
|
908
|
+
const transform = ctx.getTransform();
|
|
909
|
+
clips.push({ width, height, left: transform.e, top: transform.f, center: transform.e + width * transform.a / 2 });
|
|
910
|
+
};
|
|
911
|
+
timeline.render();
|
|
912
|
+
const originalClip = clips.pop();
|
|
913
|
+
const original = [field.width, field.height, field.x];
|
|
914
|
+
expect(original[0]).toBe(10.2);
|
|
915
|
+
|
|
916
|
+
// DynamicPromptMediator sets CENTER, writes the message, and reads its width to size the backdrop.
|
|
917
|
+
field.autoSize = runtime.builtins.TextFieldAutoSize.CENTER;
|
|
918
|
+
field.text = 'publishing level';
|
|
919
|
+
const longWidth = field.width;
|
|
920
|
+
expect(longWidth).toBeGreaterThan(original[0]);
|
|
921
|
+
expect(longWidth).toBe(field.textWidth);
|
|
922
|
+
timeline.render();
|
|
923
|
+
const expanded = clips.pop();
|
|
924
|
+
expect(expanded.width).toBe(longWidth);
|
|
925
|
+
expect(expanded.left).toBeLessThan(originalClip.left);
|
|
926
|
+
expect(expanded.center).toBeCloseTo(originalClip.center);
|
|
927
|
+
expect(field.x).toBe(original[2]);
|
|
928
|
+
|
|
929
|
+
const paintedOrigin = field.globalToLocal({ x: expanded.left, y: expanded.top });
|
|
930
|
+
const local = field.getBounds(field);
|
|
931
|
+
expect(local.x).toBeCloseTo(paintedOrigin.x);
|
|
932
|
+
expect(local.y).toBeCloseTo(paintedOrigin.y);
|
|
933
|
+
expect(local.width).toBeCloseTo(expanded.width);
|
|
934
|
+
expect(local.height).toBeCloseTo(expanded.height);
|
|
935
|
+
const firstCharacter = field.getCharBoundaries(0);
|
|
936
|
+
expect(firstCharacter.x).toBeCloseTo(local.x);
|
|
937
|
+
expect(field.getCharIndexAtPoint(firstCharacter.x + firstCharacter.width / 2,
|
|
938
|
+
firstCharacter.y + firstCharacter.height / 2)).toBe(0);
|
|
939
|
+
const { stage } = runtime;
|
|
940
|
+
const stageRect = field.getRect(stage);
|
|
941
|
+
expect(stageRect.x).toBeCloseTo(expanded.left);
|
|
942
|
+
expect(stageRect.y).toBeCloseTo(expanded.top);
|
|
943
|
+
expect(stageRect.width).toBeCloseTo(expanded.width);
|
|
944
|
+
expect(stageRect.height).toBeCloseTo(expanded.height);
|
|
945
|
+
expect(field.hitTestPoint(expanded.left + 1, expanded.top + 1)).toBe(true);
|
|
946
|
+
expect(field.hitTestPoint(expanded.left - 1, expanded.top + 1)).toBe(false);
|
|
947
|
+
|
|
948
|
+
const nearby = root.addChild(new runtime.builtins.TextField());
|
|
949
|
+
Object.assign(nearby, { x: expanded.left - 10, y: expanded.top, width: 5, height: 5, tabEnabled: true });
|
|
950
|
+
field.tabEnabled = true;
|
|
951
|
+
expect(field.hitTestObject(nearby)).toBe(false);
|
|
952
|
+
expect(pressTab()).toBe(true);
|
|
953
|
+
expect(stage.focus === nearby).toBe(true);
|
|
954
|
+
expect(pressTab()).toBe(true);
|
|
955
|
+
expect(stage.focus === field).toBe(true);
|
|
956
|
+
root.removeChild(nearby);
|
|
957
|
+
|
|
958
|
+
field.text = 'saved';
|
|
959
|
+
expect(field.width).toBeLessThan(longWidth);
|
|
960
|
+
timeline.render();
|
|
961
|
+
const shrunk = clips.pop();
|
|
962
|
+
expect(shrunk.width).toBe(field.width);
|
|
963
|
+
expect(shrunk.left).toBeGreaterThan(expanded.left);
|
|
964
|
+
expect(shrunk.center).toBeCloseTo(originalClip.center);
|
|
965
|
+
|
|
966
|
+
field.autoSize = runtime.builtins.TextFieldAutoSize.NONE;
|
|
967
|
+
expect([field.width, field.height, field.x]).toEqual(original);
|
|
968
|
+
timeline.render();
|
|
969
|
+
expect(clips.pop()).toEqual(originalClip);
|
|
970
|
+
});
|
|
971
|
+
|
|
972
|
+
it('uses the offset of the original N v2 credits field for local character queries', async () => {
|
|
973
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/Nv2.swf'));
|
|
974
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
975
|
+
const textId = 71;
|
|
976
|
+
const edit = symbolTable.get(textId);
|
|
977
|
+
const selected = new SymbolTable();
|
|
978
|
+
for (const id of [textId, edit.fontId]) selected.set(id, symbolTable.get(id));
|
|
979
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
980
|
+
const matrix = { a: 1, b: 0, c: 0, d: 1, tx: 400, ty: 300 };
|
|
981
|
+
const { root, timeline, ctx } = mountMovie(false, {
|
|
982
|
+
characters,
|
|
983
|
+
frames: [{ places: [{ depth: 1, name: 'credits', characterId: textId, matrix }] }],
|
|
984
|
+
});
|
|
985
|
+
timeline.enter();
|
|
986
|
+
const field = root.credits;
|
|
987
|
+
const paintedGlyphs = [];
|
|
988
|
+
ctx.fill = () => {
|
|
989
|
+
const { e, f } = ctx.getTransform();
|
|
990
|
+
paintedGlyphs.push(field.globalToLocal({ x: e, y: f }));
|
|
991
|
+
};
|
|
992
|
+
timeline.render();
|
|
993
|
+
|
|
994
|
+
const bounds = field.getBounds(field);
|
|
995
|
+
expect(bounds.x).toBe(59.9);
|
|
996
|
+
expect(bounds.y).toBe(-2);
|
|
997
|
+
const line = field.getLineMetrics(0);
|
|
998
|
+
const glyph = field.getCharBoundaries(0);
|
|
999
|
+
const firstPaint = paintedGlyphs[0];
|
|
1000
|
+
expect(line.x).toBeCloseTo(firstPaint.x);
|
|
1001
|
+
expect(glyph.x).toBeCloseTo(firstPaint.x);
|
|
1002
|
+
expect(glyph.y).toBeCloseTo(firstPaint.y - line.ascent);
|
|
1003
|
+
expect(field.getCharIndexAtPoint(firstPaint.x + glyph.width / 2,
|
|
1004
|
+
firstPaint.y - line.ascent + glyph.height / 2)).toBe(0);
|
|
1005
|
+
expect(field.getLineIndexAtPoint(bounds.x + 1, bounds.y + 0.5)).toBe(0);
|
|
1006
|
+
expect(field.getLineIndexAtPoint(bounds.x - 1, bounds.y + 0.5)).toBe(-1);
|
|
1007
|
+
});
|
|
1008
|
+
|
|
1009
|
+
it('keeps authored hero-list formatting when Plazma Burst 2 applies a size-only TextFormat', async () => {
|
|
1010
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/plazma-burst-2.swf'));
|
|
1011
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
1012
|
+
const selected = new SymbolTable();
|
|
1013
|
+
for (const id of [1100, 1085, 1086, symbolTable.get(1085).fontId]) selected.set(id, symbolTable.get(id));
|
|
1014
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
1015
|
+
const { root, timeline, runtime } = mountMovie(false, {
|
|
1016
|
+
characters,
|
|
1017
|
+
frames: [{ places: [{ depth: 1, characterId: 1100, name: 'hero' }] }],
|
|
1018
|
+
});
|
|
1019
|
+
timeline.enter();
|
|
1020
|
+
const { f1, f2 } = root.hero;
|
|
1021
|
+
const { TextFormat } = runtime.builtins;
|
|
1022
|
+
const sizeOnly = new TextFormat();
|
|
1023
|
+
sizeOnly.size = 10;
|
|
1024
|
+
expect(f1.getTextFormat()).toMatchObject({ font: 'DejaVu Sans Mono', align: 'left', leading: 2 });
|
|
1025
|
+
expect(f2.getTextFormat()).toMatchObject({ font: 'DejaVu Sans Mono', align: 'center', leading: 2 });
|
|
1026
|
+
|
|
1027
|
+
// The original hero list clears the labels and reuses one size-only TextFormat.
|
|
1028
|
+
f1.text = f2.text = '';
|
|
1029
|
+
f1.setTextFormat(sizeOnly);
|
|
1030
|
+
f2.setTextFormat(sizeOnly);
|
|
1031
|
+
expect(f1.getTextFormat()).toMatchObject({ size: 10, font: 'DejaVu Sans Mono', align: 'left', leading: 2 });
|
|
1032
|
+
expect(f2.getTextFormat()).toMatchObject({ size: 10, font: 'DejaVu Sans Mono', align: 'center', leading: 2 });
|
|
1033
|
+
expect(sizeOnly).toMatchObject({ size: 10, font: null, align: null, leading: null });
|
|
1034
|
+
|
|
1035
|
+
const initial = new TextFormat();
|
|
1036
|
+
Object.assign(initial, { bold: true, color: 0xffffff });
|
|
1037
|
+
f1.setTextFormat(initial);
|
|
1038
|
+
const override = new TextFormat();
|
|
1039
|
+
Object.assign(override, { align: 'right', leading: 0, bold: false, color: 0 });
|
|
1040
|
+
f1.setTextFormat(override);
|
|
1041
|
+
expect(f1.getTextFormat()).toMatchObject({ size: 10, font: 'DejaVu Sans Mono', align: 'right', leading: 0, bold: false, color: 0 });
|
|
1042
|
+
expect(f2.getTextFormat()).toMatchObject({ align: 'center', leading: 2, bold: null, color: null });
|
|
1043
|
+
|
|
1044
|
+
f1.defaultTextFormat = new TextFormat();
|
|
1045
|
+
expect(f1.getTextFormat()).toMatchObject({ size: null, font: null, align: null, leading: null });
|
|
1046
|
+
});
|
|
1047
|
+
|
|
1048
|
+
it('switches the focused Nv2 password field to a masked input using its live mode', async () => {
|
|
1049
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/Nv2.swf'));
|
|
1050
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
1051
|
+
const selected = new SymbolTable();
|
|
1052
|
+
selected.set(299, symbolTable.get(299));
|
|
1053
|
+
const { characters } = buildDisplayList([], selected, diagnostics);
|
|
1054
|
+
const { root, timeline, controls, document, runtime } = mountMovie(false, {
|
|
1055
|
+
characters,
|
|
1056
|
+
frames: [{ places: [
|
|
1057
|
+
{ characterId: 299, depth: 1, name: 'accountName' },
|
|
1058
|
+
{ characterId: 299, depth: 2, name: 'password', matrix: { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 560 } },
|
|
1059
|
+
] }],
|
|
1060
|
+
});
|
|
1061
|
+
timeline.enter();
|
|
1062
|
+
const [name, oldPassword] = controls();
|
|
1063
|
+
const field = root.password;
|
|
1064
|
+
expect([name.tag, oldPassword.tag]).toEqual(['textarea', 'textarea']);
|
|
1065
|
+
oldPassword.focus();
|
|
1066
|
+
oldPassword.value = 'sample';
|
|
1067
|
+
oldPassword.dispatch('input');
|
|
1068
|
+
oldPassword.setSelectionRange(1, 4, 'backward');
|
|
1069
|
+
oldPassword.dispatch('select');
|
|
1070
|
+
field.scrollH = 7;
|
|
1071
|
+
timeline.render();
|
|
1072
|
+
|
|
1073
|
+
// The movie's InputPasswordMediator sets both properties on registration.
|
|
1074
|
+
field.displayAsPassword = true;
|
|
1075
|
+
field.multiline = false;
|
|
1076
|
+
timeline.render();
|
|
1077
|
+
|
|
1078
|
+
const [nameAfter, password] = controls();
|
|
1079
|
+
expect(nameAfter).toBe(name);
|
|
1080
|
+
expect(oldPassword.isConnected).toBe(false);
|
|
1081
|
+
expect(password).toMatchObject({ tag: 'input', type: 'password', value: 'sample', scrollLeft: 7 });
|
|
1082
|
+
expect(document.activeElement).toBe(password);
|
|
1083
|
+
expect(runtime.stage.focus).toBe(field);
|
|
1084
|
+
expect([password.selectionStart, password.selectionEnd, password.selectionDirection]).toEqual([1, 4, 'backward']);
|
|
1085
|
+
expect([field.selectionBeginIndex, field.selectionEndIndex, field.caretIndex]).toEqual([1, 4, 1]);
|
|
1086
|
+
const pastedBreak = password.dispatch('beforeinput', { inputType: 'insertFromPaste', data: '\r\n' });
|
|
1087
|
+
expect(pastedBreak.defaultPrevented).toBe(true);
|
|
1088
|
+
expect(field.text).toBe('sample');
|
|
1089
|
+
});
|
|
1090
|
+
|
|
1091
|
+
it('shows both original Avalanche instruction lines and keeps single-line input rules', async () => {
|
|
1092
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/flasharchive/Avalanche.swf'));
|
|
1093
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
1094
|
+
const id = 96;
|
|
1095
|
+
const edit = symbolTable.get(id);
|
|
1096
|
+
expect(edit).toMatchObject({ readOnly: false, multiline: false, wordWrap: false });
|
|
1097
|
+
const first = 'Move: Left/Right';
|
|
1098
|
+
const second = 'Jump/Wall Jump: Up';
|
|
1099
|
+
expect(edit.initialText).toBe(first + '\r' + second);
|
|
1100
|
+
const selected = new SymbolTable();
|
|
1101
|
+
selected.set(id, edit);
|
|
1102
|
+
selected.set(edit.fontId, symbolTable.get(edit.fontId));
|
|
1103
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
1104
|
+
const { root, timeline, document, controls } = mountMovie(true, {
|
|
1105
|
+
characters,
|
|
1106
|
+
frames: [{ places: [{ characterId: id, depth: 1, name: 'instructions' }] }],
|
|
1107
|
+
});
|
|
1108
|
+
timeline.enter();
|
|
1109
|
+
const model = root.instructions;
|
|
1110
|
+
const [editor] = controls();
|
|
1111
|
+
const instructions = first + '\n' + second;
|
|
1112
|
+
expect(model.multiline).toBe(false);
|
|
1113
|
+
expect(editor.tag).toBe('textarea');
|
|
1114
|
+
expect(editor.wrap).toBe('off');
|
|
1115
|
+
expect(editor.style.whiteSpace).toBe('pre');
|
|
1116
|
+
expect(editor.value).toBe(instructions);
|
|
1117
|
+
|
|
1118
|
+
const transform = () => editor.style.transform.slice(7, -1).split(',').map(Number);
|
|
1119
|
+
const [a, b, c, d, x, y] = transform();
|
|
1120
|
+
root._x = 30;
|
|
1121
|
+
root._y = 15;
|
|
1122
|
+
root._xscale = 150;
|
|
1123
|
+
root._yscale = 200;
|
|
1124
|
+
timeline.render();
|
|
1125
|
+
expect(controls()[0]).toBe(editor);
|
|
1126
|
+
expect(transform()).toEqual([a * 1.5, b * 2, c * 1.5, d * 2, x * 1.5 + 30, y * 2 + 15]);
|
|
1127
|
+
|
|
1128
|
+
editor.focus();
|
|
1129
|
+
editor.setSelectionRange(instructions.length, instructions.length);
|
|
1130
|
+
expect(editor.dispatch('beforeinput', { inputType: 'insertLineBreak' }).defaultPrevented).toBe(true);
|
|
1131
|
+
expect(model.text).toBe(instructions);
|
|
1132
|
+
const paste = editor.dispatch('beforeinput', { inputType: 'insertFromPaste', data: '!\r\nOK' });
|
|
1133
|
+
expect(paste.defaultPrevented).toBe(true);
|
|
1134
|
+
timeline.render();
|
|
1135
|
+
expect(controls()[0]).toBe(editor);
|
|
1136
|
+
expect(document.activeElement).toBe(editor);
|
|
1137
|
+
expect(model.text).toBe(instructions + '!OK');
|
|
1138
|
+
expect(editor.value).toBe(model.text);
|
|
1139
|
+
expect(editor.selectionStart).toBe(model.text.length);
|
|
1140
|
+
});
|
|
1141
|
+
|
|
1142
|
+
it.each([true, false])('samples the original Avalanche text field through its AVM1 camera with pointer events=%s', async pointerEvents => {
|
|
1143
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/flasharchive/Avalanche.swf'));
|
|
1144
|
+
const { symbolTable, tags } = decode(doc, diagnostics);
|
|
1145
|
+
const id = 96;
|
|
1146
|
+
const selected = new SymbolTable();
|
|
1147
|
+
for (const characterId of [id, symbolTable.get(id).fontId, 107, 112]) {
|
|
1148
|
+
selected.set(characterId, symbolTable.get(characterId));
|
|
1149
|
+
}
|
|
1150
|
+
const { frames, characters } = buildDisplayList(tags, selected, diagnostics, { swfVersion: doc.header.version });
|
|
1151
|
+
const camera = frames[6].places.find(place => place.characterId === 112);
|
|
1152
|
+
const { root, timeline, controls, dispatchCanvas, document, runtime, member, getProperty } = mountMovie(true, {
|
|
1153
|
+
characters, frames: [{ places: [camera] }],
|
|
1154
|
+
}, { pointerEvents });
|
|
1155
|
+
timeline.enter();
|
|
1156
|
+
root._x = 20;
|
|
1157
|
+
root._y = 70;
|
|
1158
|
+
root._xscale = 90;
|
|
1159
|
+
root._yscale = 115;
|
|
1160
|
+
timeline.render();
|
|
1161
|
+
|
|
1162
|
+
const editor = controls().find(control => control.value.includes('Jump/Wall Jump'));
|
|
1163
|
+
const field = editor._swoofTextField;
|
|
1164
|
+
expect(field._swoofCharacterId).toBe(id);
|
|
1165
|
+
expect(field.parent._swoofCharacterId).toBe(107);
|
|
1166
|
+
expect(field.parent.parent).toBe(root.vcam);
|
|
1167
|
+
const [a, b, c, d, tx, ty] = editor.style.transform.slice(7, -1).split(',').map(Number);
|
|
1168
|
+
const { x, y } = characters[id].bounds;
|
|
1169
|
+
const { Point, Matrix } = runtime.builtins;
|
|
1170
|
+
const local = new Point(x + 5, y + 5);
|
|
1171
|
+
const stage = new Point((a + c) * 5 + tx, (b + d) * 5 + ty);
|
|
1172
|
+
function expectPoint(actual, expected) {
|
|
1173
|
+
expect(actual).toBeInstanceOf(Point);
|
|
1174
|
+
expect(actual.x).toBeCloseTo(expected.x, 8);
|
|
1175
|
+
expect(actual.y).toBeCloseTo(expected.y, 8);
|
|
1176
|
+
}
|
|
1177
|
+
const moveEvent = pointerEvents ? 'pointermove' : 'mousemove';
|
|
1178
|
+
dispatchCanvas(moveEvent, { clientX: stage.x, clientY: stage.y });
|
|
1179
|
+
expectPoint(field.localToGlobal(local), stage);
|
|
1180
|
+
expectPoint(field.globalToLocal(stage), local);
|
|
1181
|
+
expect(member(field, '_xmouse')).toBeCloseTo(local.x, 8);
|
|
1182
|
+
expect(member(field, '_ymouse')).toBeCloseTo(local.y, 8);
|
|
1183
|
+
expect(getProperty(field, 20)).toBeCloseTo(local.x, 8);
|
|
1184
|
+
expect(getProperty(field, 21)).toBeCloseTo(local.y, 8);
|
|
1185
|
+
|
|
1186
|
+
editor.focus();
|
|
1187
|
+
editor.setSelectionRange(0, 3);
|
|
1188
|
+
let broadcasts = 0;
|
|
1189
|
+
root.onMouseMove = () => { broadcasts++; };
|
|
1190
|
+
root.onMouseDown = () => { broadcasts++; };
|
|
1191
|
+
const editorPoint = new Point(stage.x + a * 10 + c * 5, stage.y + b * 10 + d * 5);
|
|
1192
|
+
editor.dispatch(moveEvent, { clientX: editorPoint.x, clientY: editorPoint.y });
|
|
1193
|
+
expect(member(field, '_xmouse')).toBeCloseTo(local.x + 10, 8);
|
|
1194
|
+
expect(member(field, '_ymouse')).toBeCloseTo(local.y + 5, 8);
|
|
1195
|
+
const rootPoint = root.globalToLocal({ x: editorPoint.x, y: editorPoint.y });
|
|
1196
|
+
expect(member(root, '_xmouse')).toBeCloseTo(rootPoint.x, 8);
|
|
1197
|
+
expect(member(root, '_ymouse')).toBeCloseTo(rootPoint.y, 8);
|
|
1198
|
+
|
|
1199
|
+
editor.dispatch(moveEvent, { isPrimary: false, clientX: stage.x, clientY: stage.y });
|
|
1200
|
+
expect(member(field, '_xmouse')).toBeCloseTo(local.x + 10, 8);
|
|
1201
|
+
const down = editor.dispatch(pointerEvents ? 'pointerdown' : 'mousedown', {
|
|
1202
|
+
button: 0, clientX: stage.x, clientY: stage.y,
|
|
1203
|
+
});
|
|
1204
|
+
expect(down.defaultPrevented).toBe(false);
|
|
1205
|
+
expect(member(field, '_xmouse')).toBeCloseTo(local.x, 8);
|
|
1206
|
+
expect(member(field, '_ymouse')).toBeCloseTo(local.y, 8);
|
|
1207
|
+
expect(broadcasts).toBe(0);
|
|
1208
|
+
expect(document.activeElement).toBe(editor);
|
|
1209
|
+
expect([editor.selectionStart, editor.selectionEnd]).toEqual([0, 3]);
|
|
1210
|
+
|
|
1211
|
+
const created = root.vcam.createTextField('created', 100, 2, 3, 20, 20);
|
|
1212
|
+
const skew = new Matrix(1, 0.3, 0.4, 1.2, 2, 3);
|
|
1213
|
+
created.transform.matrix = skew;
|
|
1214
|
+
const expected = root.vcam.localToGlobal(skew.transformPoint(local));
|
|
1215
|
+
expectPoint(created.localToGlobal(local), expected);
|
|
1216
|
+
expectPoint(created.globalToLocal(expected), local);
|
|
1217
|
+
expectPoint(local, new Point(x + 5, y + 5));
|
|
1218
|
+
});
|
|
1219
|
+
|
|
1220
|
+
it.each([true, false])('accepts line breaks after switching a Plazma Burst 2 input to multiline with AVM1=%s', async avm1 => {
|
|
1221
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/plazma-burst-2.swf'));
|
|
1222
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
1223
|
+
const selected = new SymbolTable();
|
|
1224
|
+
const id = 1151;
|
|
1225
|
+
selected.set(id, symbolTable.get(id));
|
|
1226
|
+
expect(selected.get(id)).toMatchObject({ readOnly: false, multiline: false });
|
|
1227
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
1228
|
+
const { root, timeline, controls, document } = mountMovie(avm1, {
|
|
1229
|
+
characters,
|
|
1230
|
+
frames: [{ places: [{ characterId: id, depth: 1, name: 'editor' }] }],
|
|
1231
|
+
});
|
|
1232
|
+
timeline.enter();
|
|
1233
|
+
const [input] = controls();
|
|
1234
|
+
expect(input.tag).toBe('input');
|
|
1235
|
+
input.focus();
|
|
1236
|
+
root.editor.multiline = true;
|
|
1237
|
+
timeline.render();
|
|
1238
|
+
const [textarea] = controls();
|
|
1239
|
+
expect(textarea.tag).toBe('textarea');
|
|
1240
|
+
expect(document.activeElement).toBe(textarea);
|
|
1241
|
+
|
|
1242
|
+
const enter = textarea.dispatch('beforeinput', { inputType: 'insertLineBreak' });
|
|
1243
|
+
expect(enter.defaultPrevented).toBe(false);
|
|
1244
|
+
textarea.value = '\n';
|
|
1245
|
+
textarea.setSelectionRange(1, 1);
|
|
1246
|
+
textarea.dispatch('input', { inputType: 'insertLineBreak' });
|
|
1247
|
+
expect(root.editor.text).toBe('\n');
|
|
1248
|
+
});
|
|
1249
|
+
|
|
1250
|
+
it.each([true, false])('lets ActionScript veto native mouse focus in N v2 with pointer events=%s', async pointerEvents => {
|
|
1251
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/Nv2.swf'));
|
|
1252
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
1253
|
+
const selected = new SymbolTable();
|
|
1254
|
+
const id = 299;
|
|
1255
|
+
selected.set(id, symbolTable.get(id));
|
|
1256
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
1257
|
+
const { root, runtime, timeline, controls, document } = mountMovie(false, {
|
|
1258
|
+
characters,
|
|
1259
|
+
frames: [{ places: [
|
|
1260
|
+
{ characterId: id, depth: 1, name: 'first' },
|
|
1261
|
+
{ characterId: id, depth: 2, name: 'second', matrix: { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 560 } },
|
|
1262
|
+
] }],
|
|
1263
|
+
}, { pointerEvents });
|
|
1264
|
+
timeline.enter();
|
|
1265
|
+
const [first, second] = controls();
|
|
1266
|
+
const focusEvent = runtime.builtins.FocusEvent.MOUSE_FOCUS_CHANGE;
|
|
1267
|
+
const requests = [];
|
|
1268
|
+
const record = event => requests.push([event.target === root.first, event.relatedObject === root.second,
|
|
1269
|
+
event.bubbles, event.cancelable, event.keyCode]);
|
|
1270
|
+
root.addEventListener(focusEvent, record);
|
|
1271
|
+
const veto = event => event.preventDefault();
|
|
1272
|
+
root.first.addEventListener(focusEvent, veto);
|
|
1273
|
+
first.focus();
|
|
1274
|
+
|
|
1275
|
+
const press = (element, options) => element.dispatch(pointerEvents ? 'pointerdown' : 'mousedown', {
|
|
1276
|
+
button: 0, isPrimary: true, ...options,
|
|
1277
|
+
});
|
|
1278
|
+
expect(press(second, { button: 2 }).defaultPrevented).toBe(false);
|
|
1279
|
+
expect(press(second, { isPrimary: false }).defaultPrevented).toBe(false);
|
|
1280
|
+
expect(press(first).defaultPrevented).toBe(false);
|
|
1281
|
+
expect(requests).toEqual([]);
|
|
1282
|
+
|
|
1283
|
+
expect(press(second).defaultPrevented).toBe(true);
|
|
1284
|
+
expect(requests).toEqual([[true, true, true, true, 0]]);
|
|
1285
|
+
expect(document.activeElement).toBe(first);
|
|
1286
|
+
expect(runtime.stage.focus).toBe(root.first);
|
|
1287
|
+
|
|
1288
|
+
runtime.stage.focus = root.second;
|
|
1289
|
+
expect(document.activeElement).toBe(second);
|
|
1290
|
+
runtime.stage.focus = root.first;
|
|
1291
|
+
expect(requests).toHaveLength(1);
|
|
1292
|
+
root.first.removeEventListener(focusEvent, veto);
|
|
1293
|
+
expect(press(second).defaultPrevented).toBe(false);
|
|
1294
|
+
if (pointerEvents) second.dispatch('mousedown', { button: 0 });
|
|
1295
|
+
second.focus();
|
|
1296
|
+
expect(requests).toEqual([[true, true, true, true, 0], [true, true, true, true, 0]]);
|
|
1297
|
+
expect(document.activeElement).toBe(second);
|
|
1298
|
+
expect(runtime.stage.focus).toBe(root.second);
|
|
1299
|
+
});
|
|
1300
|
+
|
|
1301
|
+
it.each([true, false])('keeps native text editors in Flash tab order with AVM1=%s', async avm1 => {
|
|
1302
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/Nv2.swf'));
|
|
1303
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
1304
|
+
const selected = new SymbolTable();
|
|
1305
|
+
const id = 299;
|
|
1306
|
+
selected.set(id, symbolTable.get(id));
|
|
1307
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
1308
|
+
const { root, timeline, controls, document, pressTab } = mountMovie(avm1, {
|
|
1309
|
+
characters,
|
|
1310
|
+
frames: [{ places: [
|
|
1311
|
+
{ characterId: id, depth: 1, name: 'first' },
|
|
1312
|
+
{ characterId: id, depth: 2, name: 'second', matrix: { a: 1, b: 0, c: 0, tx: 0, d: 1, ty: 560 } },
|
|
1313
|
+
] }],
|
|
1314
|
+
}, { keyboardEvents: true });
|
|
1315
|
+
timeline.enter();
|
|
1316
|
+
const [first, second] = controls();
|
|
1317
|
+
root.first.tabEnabled = root.second.tabEnabled = false;
|
|
1318
|
+
timeline.render();
|
|
1319
|
+
expect(pressTab()).toBe(false);
|
|
1320
|
+
expect([first.tabIndex, second.tabIndex]).toEqual([-1, -1]);
|
|
1321
|
+
expect(document.activeElement).toBeNull();
|
|
1322
|
+
|
|
1323
|
+
root.second.tabEnabled = true;
|
|
1324
|
+
expect(pressTab()).toBe(true);
|
|
1325
|
+
expect(document.activeElement).toBe(second);
|
|
1326
|
+
second.blur();
|
|
1327
|
+
root.tabChildren = false;
|
|
1328
|
+
expect(pressTab()).toBe(false);
|
|
1329
|
+
expect(second.tabIndex).toBe(-1);
|
|
1330
|
+
|
|
1331
|
+
first.focus();
|
|
1332
|
+
expect(document.activeElement).toBe(first);
|
|
1333
|
+
});
|
|
1334
|
+
|
|
1335
|
+
it('skips a mouse-disabled AS3 editor when choosing the next native input', async () => {
|
|
1336
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/Nv2.swf'));
|
|
1337
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
1338
|
+
const selected = new SymbolTable();
|
|
1339
|
+
const id = 299;
|
|
1340
|
+
selected.set(id, symbolTable.get(id));
|
|
1341
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
1342
|
+
const { root, runtime, timeline, controls, document, pressTab } = mountMovie(false, {
|
|
1343
|
+
characters,
|
|
1344
|
+
frames: [{ places: [
|
|
1345
|
+
{ characterId: id, depth: 1, name: 'first' },
|
|
1346
|
+
{ characterId: id, depth: 2, name: 'second', matrix: { a: 1, b: 0, c: 0, tx: 0, ty: 560 } },
|
|
1347
|
+
] }],
|
|
1348
|
+
}, { keyboardEvents: true });
|
|
1349
|
+
timeline.enter();
|
|
1350
|
+
const [first, second] = controls();
|
|
1351
|
+
root.first.tabIndex = 1;
|
|
1352
|
+
root.first.mouseEnabled = false;
|
|
1353
|
+
root.mouseEnabled = false;
|
|
1354
|
+
root.tabEnabled = true;
|
|
1355
|
+
timeline.render();
|
|
1356
|
+
|
|
1357
|
+
expect(first.isConnected).toBe(false);
|
|
1358
|
+
expect(second.isConnected).toBe(true);
|
|
1359
|
+
expect(pressTab()).toBe(true);
|
|
1360
|
+
expect(runtime.stage.focus === root.second).toBe(true);
|
|
1361
|
+
expect(document.activeElement === second).toBe(true);
|
|
1362
|
+
|
|
1363
|
+
runtime.stage.focus = null;
|
|
1364
|
+
root.first.mouseEnabled = true;
|
|
1365
|
+
timeline.render();
|
|
1366
|
+
expect(pressTab()).toBe(true);
|
|
1367
|
+
expect(runtime.stage.focus === root.first).toBe(true);
|
|
1368
|
+
expect(document.activeElement === root.first._swoofOverlayElement).toBe(true);
|
|
1369
|
+
});
|
|
1370
|
+
|
|
1371
|
+
it('keeps the authored Nv2 field on Canvas while its own or its parent’s input is disabled', async () => {
|
|
1372
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/Nv2.swf'));
|
|
1373
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
1374
|
+
const selected = new SymbolTable();
|
|
1375
|
+
const id = 299;
|
|
1376
|
+
selected.set(id, symbolTable.get(id));
|
|
1377
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
1378
|
+
const { root, runtime, timeline, controls, document, draws } = mountMovie(false, {
|
|
1379
|
+
characters,
|
|
1380
|
+
frames: [{ places: [{ characterId: id, depth: 1, name: 'editor' }] }],
|
|
1381
|
+
});
|
|
1382
|
+
timeline.enter();
|
|
1383
|
+
const field = root.editor;
|
|
1384
|
+
field.text = 'Focus me';
|
|
1385
|
+
timeline.render();
|
|
1386
|
+
const [initial] = controls();
|
|
1387
|
+
initial.focus();
|
|
1388
|
+
expect(runtime.stage.focus).toBe(field);
|
|
1389
|
+
|
|
1390
|
+
root.mouseEnabled = false;
|
|
1391
|
+
timeline.render();
|
|
1392
|
+
expect(initial.isConnected).toBe(true);
|
|
1393
|
+
|
|
1394
|
+
field.mouseEnabled = false;
|
|
1395
|
+
draws.length = 0;
|
|
1396
|
+
timeline.render();
|
|
1397
|
+
expect(controls()).toHaveLength(0);
|
|
1398
|
+
expect(document.activeElement).toBeNull();
|
|
1399
|
+
expect(runtime.stage.focus).toBeNull();
|
|
1400
|
+
expect(draws.join('')).toBe('Focus me');
|
|
1401
|
+
|
|
1402
|
+
field.mouseEnabled = true;
|
|
1403
|
+
timeline.render();
|
|
1404
|
+
const [restored] = controls();
|
|
1405
|
+
expect(restored.value).toBe('Focus me');
|
|
1406
|
+
restored.focus();
|
|
1407
|
+
root.mouseChildren = false;
|
|
1408
|
+
timeline.render();
|
|
1409
|
+
expect(controls()).toHaveLength(0);
|
|
1410
|
+
expect(runtime.stage.focus).toBeNull();
|
|
1411
|
+
|
|
1412
|
+
root.mouseChildren = true;
|
|
1413
|
+
timeline.render();
|
|
1414
|
+
expect(controls()[0].value).toBe('Focus me');
|
|
1415
|
+
expect(field.type).toBe('input');
|
|
1416
|
+
});
|
|
1417
|
+
|
|
1418
|
+
it.each(['AVM1', 'AS3'])('applies live %s native font size and recalculates authored leading in place', mode => {
|
|
1419
|
+
const avm1 = mode === 'AVM1';
|
|
1420
|
+
const { root, runtime, timeline, controls, document } = mountMovie(avm1, {
|
|
1421
|
+
frames: [{ places: [{ depth: 1, characterId: 1, name: 'entry' }] }],
|
|
1422
|
+
characters: {
|
|
1423
|
+
1: { type: 'text', kind: 'edit', editable: true, text: 'Long text beyond the native viewport',
|
|
1424
|
+
font: 'Linked Native', outlineFontId: 2, fontSize: 12, multiline: true, leading: -2,
|
|
1425
|
+
bounds: { x: 0, y: 0, w: 42, h: 30 } },
|
|
1426
|
+
2: { type: 'font', name: 'Linked Native', codes: [116], layout: { advances: [640], ascent: 896, descent: 128 } },
|
|
1427
|
+
},
|
|
1428
|
+
loaded: { 2: { family: 'swoof-linked-native' } },
|
|
1429
|
+
});
|
|
1430
|
+
timeline.enter();
|
|
1431
|
+
const field = root.entry;
|
|
1432
|
+
const [input] = controls();
|
|
1433
|
+
input.focus();
|
|
1434
|
+
input.setSelectionRange(1, 4, 'backward');
|
|
1435
|
+
input.dispatch('select');
|
|
1436
|
+
expect(input.style.fontSize).toBe('12px');
|
|
1437
|
+
expect(parseFloat(input.style.lineHeight)).toBeCloseTo(11.8);
|
|
1438
|
+
|
|
1439
|
+
field.scrollH = 12;
|
|
1440
|
+
timeline.render();
|
|
1441
|
+
expect(input.scrollLeft).toBe(12);
|
|
1442
|
+
input.scrollLeft = 7;
|
|
1443
|
+
input.dispatch('scroll');
|
|
1444
|
+
|
|
1445
|
+
field.setTextFormat({ font: 'Linked Native', size: 18 });
|
|
1446
|
+
timeline.render();
|
|
1447
|
+
expect(input.style.fontSize).toBe('18px');
|
|
1448
|
+
expect(parseFloat(input.style.lineHeight)).toBeCloseTo(18.7);
|
|
1449
|
+
expect(input.style.fontFamily).toBe('"swoof-linked-native", "Linked Native", Arial, sans-serif');
|
|
1450
|
+
expect([input.style.width, input.style.height]).toEqual(['42px', '30px']);
|
|
1451
|
+
expect([field.scrollH, input.scrollLeft]).toEqual([7, 7]);
|
|
1452
|
+
expect(controls()).toEqual([input]);
|
|
1453
|
+
expect(document.activeElement).toBe(input);
|
|
1454
|
+
expect([input.selectionStart, input.selectionEnd, input.selectionDirection]).toEqual([1, 4, 'backward']);
|
|
1455
|
+
|
|
1456
|
+
field.setTextFormat({ font: 'Linked Native', size: Infinity });
|
|
1457
|
+
const programmatic = avm1 ? root.createTextField('other', 2, 0, 40, 42, 30) : root.addChild(new runtime.builtins.TextField());
|
|
1458
|
+
Object.assign(programmatic, { type: 'input', y: 40, width: 42, height: 30, multiline: true });
|
|
1459
|
+
programmatic.setTextFormat({ size: 18.5, leading: 3 });
|
|
1460
|
+
timeline.render();
|
|
1461
|
+
const other = controls().find(control => control !== input);
|
|
1462
|
+
expect(input.style.fontSize).toBe('12px');
|
|
1463
|
+
expect(parseFloat(input.style.lineHeight)).toBeCloseTo(11.8);
|
|
1464
|
+
expect(other.style.fontSize).toBe('18.5px');
|
|
1465
|
+
expect(parseFloat(other.style.lineHeight)).toBeCloseTo(25.2);
|
|
1466
|
+
});
|
|
1467
|
+
|
|
1468
|
+
it.each([
|
|
1469
|
+
['archive/Swf/raze-3.swf', 3668, -2, 15.25],
|
|
1470
|
+
['archive/flasharchive/N.swf', 591, 2, 11.2],
|
|
1471
|
+
])('applies signed native multiline leading in %s EditText %i', async (file, id, leading, height) => {
|
|
1472
|
+
const { doc, diagnostics } = await parse(readFileSync(file));
|
|
1473
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
1474
|
+
const selected = new SymbolTable();
|
|
1475
|
+
selected.set(id, symbolTable.get(id));
|
|
1476
|
+
const { characters } = buildDisplayList([], selected, diagnostics);
|
|
1477
|
+
const info = characters[id];
|
|
1478
|
+
expect(info).toMatchObject({ editable: true, multiline: true, leading });
|
|
1479
|
+
characters[1] = { ...info, multiline: false };
|
|
1480
|
+
const { timeline, controls } = mountMovie(false, {
|
|
1481
|
+
characters,
|
|
1482
|
+
frames: [{ places: [
|
|
1483
|
+
{ depth: 1, characterId: id, name: 'multiline' },
|
|
1484
|
+
{ depth: 2, characterId: 1, name: 'singleLine' },
|
|
1485
|
+
] }],
|
|
1486
|
+
});
|
|
1487
|
+
timeline.enter();
|
|
1488
|
+
|
|
1489
|
+
const multiline = controls().find(control => control.tag === 'textarea');
|
|
1490
|
+
const singleLine = controls().find(control => control.tag === 'input');
|
|
1491
|
+
expect(multiline.style.lineHeight).toBe(height + 'px');
|
|
1492
|
+
expect(singleLine.style.lineHeight || '').toBe('');
|
|
1493
|
+
expect(multiline.style.height).toBe(info.bounds.h + 'px');
|
|
1494
|
+
});
|
|
1495
|
+
|
|
1496
|
+
it.each([true, false])('applies live Raze 3 text leading to native and Canvas rows with AVM1=%s', async avm1 => {
|
|
1497
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/raze-3.swf'));
|
|
1498
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
1499
|
+
const selected = new SymbolTable();
|
|
1500
|
+
const id = 3668;
|
|
1501
|
+
selected.set(id, symbolTable.get(id));
|
|
1502
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
1503
|
+
const { root, timeline, controls, document, ctx } = mountMovie(avm1, {
|
|
1504
|
+
characters,
|
|
1505
|
+
frames: [{ places: [{ characterId: id, depth: 1, name: 'txt_inputname' }] }],
|
|
1506
|
+
});
|
|
1507
|
+
timeline.enter();
|
|
1508
|
+
const field = root.txt_inputname;
|
|
1509
|
+
Object.assign(field, { text: 'one\ntwo\nthree', width: 120, height: 25 });
|
|
1510
|
+
timeline.render();
|
|
1511
|
+
const [textarea] = controls();
|
|
1512
|
+
expect(textarea.style.lineHeight).toBe('15.25px');
|
|
1513
|
+
textarea.focus();
|
|
1514
|
+
textarea.setSelectionRange(1, 5, 'backward');
|
|
1515
|
+
const applyLeading = leading => field.setTextFormat(Object.assign(field.getTextFormat(), { leading }));
|
|
1516
|
+
|
|
1517
|
+
applyLeading(8);
|
|
1518
|
+
Object.assign(textarea, { clientHeight: 25, scrollHeight: 76 });
|
|
1519
|
+
timeline.render();
|
|
1520
|
+
expect(textarea.style.lineHeight).toBe('25.25px');
|
|
1521
|
+
const scroll = avm1 ? 'scroll' : 'scrollV';
|
|
1522
|
+
field[scroll] = 2;
|
|
1523
|
+
timeline.render();
|
|
1524
|
+
expect(textarea.scrollTop).toBe(25.25);
|
|
1525
|
+
|
|
1526
|
+
applyLeading(0);
|
|
1527
|
+
textarea.scrollHeight = 52;
|
|
1528
|
+
timeline.render();
|
|
1529
|
+
expect(textarea.style.lineHeight).toBe('17.25px');
|
|
1530
|
+
expect([field[scroll], textarea.scrollTop]).toEqual([2, 17.25]);
|
|
1531
|
+
expect(controls()[0] === textarea).toBe(true);
|
|
1532
|
+
expect(document.activeElement === textarea).toBe(true);
|
|
1533
|
+
expect([textarea.selectionStart, textarea.selectionEnd, textarea.selectionDirection]).toEqual([1, 5, 'backward']);
|
|
1534
|
+
|
|
1535
|
+
const rows = [];
|
|
1536
|
+
ctx.fillText = (text, x, y) => rows.push([text, y]);
|
|
1537
|
+
Object.assign(field, { type: 'dynamic', height: 100 });
|
|
1538
|
+
applyLeading(8);
|
|
1539
|
+
timeline.render();
|
|
1540
|
+
expect(rows.splice(0)).toEqual([['one', 0], ['two', 26], ['three', 52]]);
|
|
1541
|
+
applyLeading(0);
|
|
1542
|
+
timeline.render();
|
|
1543
|
+
expect(rows).toEqual([['one', 0], ['two', 18], ['three', 36]]);
|
|
1544
|
+
});
|
|
1545
|
+
|
|
1546
|
+
it.each([true, false])('keeps live textColor on the authored Plazma Burst 2 nickname field with AVM1=%s', async avm1 => {
|
|
1547
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/plazma-burst-2.swf'));
|
|
1548
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
1549
|
+
const selected = new SymbolTable();
|
|
1550
|
+
const id = 1151;
|
|
1551
|
+
selected.set(id, symbolTable.get(id));
|
|
1552
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
1553
|
+
const { root, timeline, controls, document, ctx } = mountMovie(avm1, {
|
|
1554
|
+
characters,
|
|
1555
|
+
frames: [{ places: [{ characterId: id, depth: 1, name: 'nickname' }] }],
|
|
1556
|
+
});
|
|
1557
|
+
timeline.enter();
|
|
1558
|
+
const field = root.nickname;
|
|
1559
|
+
field.text = 'Coder';
|
|
1560
|
+
timeline.render();
|
|
1561
|
+
const [editor] = controls();
|
|
1562
|
+
expect(editor.style.color).toBe('rgba(255,255,255,1)');
|
|
1563
|
+
editor.focus();
|
|
1564
|
+
editor.setSelectionRange(1, 4, 'backward');
|
|
1565
|
+
field.textColor = 0;
|
|
1566
|
+
timeline.render();
|
|
1567
|
+
expect(editor.style.color).toBe('#000000');
|
|
1568
|
+
field.textColor = 0x445566;
|
|
1569
|
+
timeline.render();
|
|
1570
|
+
expect(editor.style.color).toBe('#445566');
|
|
1571
|
+
expect(controls()[0] === editor).toBe(true);
|
|
1572
|
+
expect(document.activeElement === editor).toBe(true);
|
|
1573
|
+
expect([editor.selectionStart, editor.selectionEnd, editor.selectionDirection]).toEqual([1, 4, 'backward']);
|
|
1574
|
+
|
|
1575
|
+
const paints = [];
|
|
1576
|
+
ctx.fillText = text => paints.push([text, ctx.fillStyle]);
|
|
1577
|
+
field.type = 'dynamic';
|
|
1578
|
+
timeline.render();
|
|
1579
|
+
expect(paints).toEqual([['Coder', '#445566']]);
|
|
1580
|
+
});
|
|
1581
|
+
|
|
1582
|
+
it('applies authored horizontal margins within a Plazma Burst 2 native input’s bounds', async () => {
|
|
1583
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/plazma-burst-2.swf'));
|
|
1584
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
1585
|
+
const selected = new SymbolTable();
|
|
1586
|
+
const inputId = 1151;
|
|
1587
|
+
const edit = symbolTable.get(inputId);
|
|
1588
|
+
selected.set(inputId, edit);
|
|
1589
|
+
if (edit.fontId) selected.set(edit.fontId, symbolTable.get(edit.fontId));
|
|
1590
|
+
expect([edit.leftMargin, edit.rightMargin]).toEqual([100, 100]);
|
|
1591
|
+
const { characters } = buildDisplayList([], selected, diagnostics);
|
|
1592
|
+
const info = characters[inputId];
|
|
1593
|
+
characters[2] = { ...info, border: true, leftMargin: 0, rightMargin: 0, bounds: { ...info.bounds, w: 80 } };
|
|
1594
|
+
characters[3] = { ...info, border: true, leftMargin: 10, rightMargin: 20, bounds: { ...info.bounds, w: 10 } };
|
|
1595
|
+
const matrixAt = y => ({ a: 1, b: 0, c: 0, d: 1, tx: 0, ty: y * 20 });
|
|
1596
|
+
const { root, runtime, timeline, controls } = mountMovie(false, {
|
|
1597
|
+
characters,
|
|
1598
|
+
frames: [{ places: [
|
|
1599
|
+
{ depth: 1, characterId: inputId, name: 'authored', matrix: matrixAt(4) },
|
|
1600
|
+
{ depth: 2, characterId: 2, name: 'zero', matrix: matrixAt(26) },
|
|
1601
|
+
{ depth: 3, characterId: 3, name: 'narrow', matrix: matrixAt(48) },
|
|
1602
|
+
] }],
|
|
1603
|
+
});
|
|
1604
|
+
const field = root.addChild(new runtime.builtins.TextField());
|
|
1605
|
+
field.type = 'input';
|
|
1606
|
+
field.width = 120;
|
|
1607
|
+
field.height = 18;
|
|
1608
|
+
field.y = 70;
|
|
1609
|
+
field.border = true;
|
|
1610
|
+
field.defaultTextFormat.leftMargin = 6;
|
|
1611
|
+
field.defaultTextFormat.rightMargin = 2;
|
|
1612
|
+
timeline.enter();
|
|
1613
|
+
|
|
1614
|
+
const controlWithWidth = width => controls().find(control => control.style.width === width + 'px');
|
|
1615
|
+
const authored = controlWithWidth(info.bounds.w);
|
|
1616
|
+
const narrow = controlWithWidth(10);
|
|
1617
|
+
const programmatic = controlWithWidth(120);
|
|
1618
|
+
expect([authored.style.paddingLeft, authored.style.paddingRight]).toEqual(['5px', '5px']);
|
|
1619
|
+
expect(controlWithWidth(80).style.padding).toBe('1px');
|
|
1620
|
+
expect([narrow.style.paddingLeft, narrow.style.paddingRight]).toEqual(['3px', '5px']);
|
|
1621
|
+
expect([programmatic.style.paddingLeft, programmatic.style.paddingRight]).toEqual(['6px', '2px']);
|
|
1622
|
+
});
|
|
1623
|
+
|
|
1624
|
+
it('binds authored AVM1 fields to parent-relative and root-absolute target paths through rebinding', () => {
|
|
1625
|
+
const { root, timeline, controls, draws } = mountMovie(true, {
|
|
1626
|
+
frames: [{ places: [{ depth: 1, characterId: 1, name: 'panel' }] }],
|
|
1627
|
+
characters: {
|
|
1628
|
+
1: { type: 'sprite', frameCount: 1, frames: [{ places: [
|
|
1629
|
+
{ depth: 1, characterId: 2, name: 'relative' },
|
|
1630
|
+
{ depth: 2, characterId: 3, name: 'absolute', matrix: { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 440 } },
|
|
1631
|
+
{ depth: 3, characterId: 4, name: 'label', matrix: { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 880 } },
|
|
1632
|
+
] }] },
|
|
1633
|
+
2: { type: 'text', kind: 'edit', editable: true, text: 'fallback A', variableName: '../:counter',
|
|
1634
|
+
bounds: { x: 0, y: 0, w: 100, h: 20 } },
|
|
1635
|
+
3: { type: 'text', kind: 'edit', editable: true, text: 'fallback B', variableName: '/panel:counter',
|
|
1636
|
+
bounds: { x: 0, y: 0, w: 100, h: 20 } },
|
|
1637
|
+
4: { type: 'text', kind: 'edit', editable: false, text: 'fallback label', variableName: '/panel:counter',
|
|
1638
|
+
bounds: { x: 0, y: 0, w: 100, h: 20 } },
|
|
1639
|
+
},
|
|
1640
|
+
});
|
|
1641
|
+
root.counter = 'root value';
|
|
1642
|
+
timeline.enter();
|
|
1643
|
+
root.panel.counter = 'panel value';
|
|
1644
|
+
timeline.render();
|
|
1645
|
+
const [relative, absolute] = controls();
|
|
1646
|
+
expect([relative.value, absolute.value]).toEqual(['root value', 'panel value']);
|
|
1647
|
+
expect(draws.at(-1)).toBe('panel value');
|
|
1648
|
+
|
|
1649
|
+
relative.value = 'typed parent';
|
|
1650
|
+
relative.dispatch('input');
|
|
1651
|
+
absolute.value = 'typed absolute';
|
|
1652
|
+
absolute.dispatch('input');
|
|
1653
|
+
expect([root.counter, root.panel.counter]).toEqual(['typed parent', 'typed absolute']);
|
|
1654
|
+
expect(root.panel[':counter']).toBeUndefined();
|
|
1655
|
+
expect(root.panel['panel:counter']).toBeUndefined();
|
|
1656
|
+
|
|
1657
|
+
root.alt = 'alternate root';
|
|
1658
|
+
root.panel.absolute.variable = root.panel.label.variable = '../:alt';
|
|
1659
|
+
timeline.render();
|
|
1660
|
+
expect(absolute.value).toBe('alternate root');
|
|
1661
|
+
expect(draws.at(-1)).toBe('alternate root');
|
|
1662
|
+
absolute.value = 'edited alternate';
|
|
1663
|
+
absolute.dispatch('input');
|
|
1664
|
+
expect([root.panel.counter, root.alt]).toEqual(['typed absolute', 'edited alternate']);
|
|
1665
|
+
|
|
1666
|
+
root.panel.absolute.variable = root.panel.label.variable = '';
|
|
1667
|
+
timeline.render();
|
|
1668
|
+
expect(draws.at(-1)).toBe('fallback label');
|
|
1669
|
+
absolute.value = 'unbound edit';
|
|
1670
|
+
absolute.dispatch('input');
|
|
1671
|
+
expect(root.panel.absolute.text).toBe('unbound edit');
|
|
1672
|
+
expect([root.panel.counter, root.alt]).toEqual(['typed absolute', 'edited alternate']);
|
|
1673
|
+
});
|
|
1674
|
+
|
|
1675
|
+
it('synchronizes the native horizontal viewport without resetting selection or a newer script write', () => {
|
|
1676
|
+
const { root, timeline, controls, document } = mountMovie(true);
|
|
1677
|
+
const field = root.createTextField('entry', 1, 0, 0, 20, 20);
|
|
1678
|
+
field.type = 'input';
|
|
1679
|
+
field.text = 'This input is wider than its viewport';
|
|
1680
|
+
timeline.render();
|
|
1681
|
+
const [input] = controls();
|
|
1682
|
+
input.focus();
|
|
1683
|
+
input.setSelectionRange(1, 4, 'backward');
|
|
1684
|
+
input.scrollTop = 5;
|
|
1685
|
+
const notifications = [];
|
|
1686
|
+
field.onScroller = function (source) {
|
|
1687
|
+
expect(this).toBe(field);
|
|
1688
|
+
expect(source).toBe(field);
|
|
1689
|
+
notifications.push(['field', source.hscroll]);
|
|
1690
|
+
};
|
|
1691
|
+
const scrollbar = {
|
|
1692
|
+
onScroller(source) {
|
|
1693
|
+
expect(this).toBe(scrollbar);
|
|
1694
|
+
expect(source).toBe(field);
|
|
1695
|
+
notifications.push(['scrollbar', source.hscroll]);
|
|
1696
|
+
},
|
|
1697
|
+
};
|
|
1698
|
+
expect(field.addListener(scrollbar)).toBe(true);
|
|
1699
|
+
expect(field.addListener(scrollbar)).toBe(false);
|
|
1700
|
+
|
|
1701
|
+
field.hscroll = 12;
|
|
1702
|
+
timeline.render();
|
|
1703
|
+
expect(input.scrollLeft).toBe(12);
|
|
1704
|
+
|
|
1705
|
+
input.scrollLeft = 7;
|
|
1706
|
+
input.dispatch('select');
|
|
1707
|
+
timeline.render();
|
|
1708
|
+
expect(input.scrollLeft).toBe(7);
|
|
1709
|
+
input.dispatch('scroll');
|
|
1710
|
+
expect(field.hscroll).toBe(7);
|
|
1711
|
+
expect(notifications).toEqual([['field', 12], ['scrollbar', 12], ['field', 7], ['scrollbar', 7]]);
|
|
1712
|
+
|
|
1713
|
+
expect(field.removeListener(scrollbar)).toBe(true);
|
|
1714
|
+
expect(field.removeListener(scrollbar)).toBe(false);
|
|
1715
|
+
|
|
1716
|
+
field.hscroll = 18;
|
|
1717
|
+
input.scrollLeft = 8;
|
|
1718
|
+
input.dispatch('scroll');
|
|
1719
|
+
timeline.render();
|
|
1720
|
+
expect([field.hscroll, input.scrollLeft]).toEqual([18, 18]);
|
|
1721
|
+
|
|
1722
|
+
input.dir = 'rtl';
|
|
1723
|
+
input.scrollLeft = -3;
|
|
1724
|
+
input.dispatch('scroll');
|
|
1725
|
+
timeline.render();
|
|
1726
|
+
expect([field.hscroll, input.scrollLeft]).toEqual([18, -3]);
|
|
1727
|
+
expect(notifications.at(-1)).toEqual(['field', 18]);
|
|
1728
|
+
expect(notifications).toHaveLength(5);
|
|
1729
|
+
expect(input.scrollTop).toBe(5);
|
|
1730
|
+
expect(document.activeElement).toBe(input);
|
|
1731
|
+
expect([input.selectionStart, input.selectionEnd, input.selectionDirection]).toEqual([1, 4, 'backward']);
|
|
1732
|
+
});
|
|
1733
|
+
|
|
1734
|
+
it.each([true, false])('reports native horizontal and diagonal scrolling once per viewport change with AVM1=%s', avm1 => {
|
|
1735
|
+
const { root, runtime, timeline, controls } = mountMovie(avm1);
|
|
1736
|
+
const field = avm1 ? root.createTextField('entry', 1, 0, 0, 20, 20) : root.addChild(new runtime.builtins.TextField());
|
|
1737
|
+
Object.assign(field, { type: 'input', width: 20, height: 20, multiline: true,
|
|
1738
|
+
text: 'one long line\nsecond line\nthird line\nfourth line' });
|
|
1739
|
+
timeline.enter();
|
|
1740
|
+
const [textarea] = controls();
|
|
1741
|
+
Object.assign(textarea, { clientHeight: 20, scrollHeight: 58 });
|
|
1742
|
+
timeline.render();
|
|
1743
|
+
textarea.focus();
|
|
1744
|
+
const changes = [];
|
|
1745
|
+
const horizontal = avm1 ? 'hscroll' : 'scrollH';
|
|
1746
|
+
const vertical = avm1 ? 'scroll' : 'scrollV';
|
|
1747
|
+
const recordScroll = source => {
|
|
1748
|
+
expect(source).toBe(field);
|
|
1749
|
+
changes.push([source[horizontal], source[vertical]]);
|
|
1750
|
+
};
|
|
1751
|
+
if (avm1) {
|
|
1752
|
+
field.onScroller = recordScroll;
|
|
1753
|
+
} else {
|
|
1754
|
+
field.addEventListener(runtime.builtins.Event.SCROLL, event => {
|
|
1755
|
+
expect(event.bubbles).toBe(false);
|
|
1756
|
+
recordScroll(event.target);
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
field[horizontal] = 9;
|
|
1761
|
+
field[vertical] = 2;
|
|
1762
|
+
expect(changes.splice(0)).toEqual(avm1 ? [[9, 1], [9, 2]] : []);
|
|
1763
|
+
timeline.render();
|
|
1764
|
+
textarea.dispatch('scroll');
|
|
1765
|
+
expect(changes).toEqual([]);
|
|
1766
|
+
textarea.scrollLeft = 6;
|
|
1767
|
+
textarea.dispatch('scroll');
|
|
1768
|
+
expect(changes).toEqual([[6, 2]]);
|
|
1769
|
+
Object.assign(textarea, { scrollLeft: 3, scrollTop: 29 });
|
|
1770
|
+
textarea.dispatch('scroll');
|
|
1771
|
+
textarea.dispatch('scroll');
|
|
1772
|
+
expect(changes).toEqual([[6, 2], [3, 3]]);
|
|
1773
|
+
});
|
|
1774
|
+
|
|
1775
|
+
it.each([true, false])('clamps attached LTR horizontal scroll to the native range with AVM1=%s', avm1 => {
|
|
1776
|
+
const { root, runtime, timeline, controls, document } = mountMovie(avm1);
|
|
1777
|
+
const field = avm1 ? root.createTextField('entry', 1, 0, 0, 20, 30) : root.addChild(new runtime.builtins.TextField());
|
|
1778
|
+
Object.assign(field, { type: 'input', width: 20, height: 30, multiline: true, text: 'a long unwrapped line' });
|
|
1779
|
+
timeline.enter();
|
|
1780
|
+
const [textarea] = controls();
|
|
1781
|
+
Object.assign(textarea, { scrollWidth: 58, clientWidth: 20 });
|
|
1782
|
+
let nativeLeft = 0;
|
|
1783
|
+
Object.defineProperty(textarea, 'scrollLeft', {
|
|
1784
|
+
get() { return nativeLeft = Math.min(nativeLeft, this.scrollWidth - this.clientWidth); },
|
|
1785
|
+
set(value) { nativeLeft = Math.max(0, Math.min(value, this.scrollWidth - this.clientWidth)); },
|
|
1786
|
+
});
|
|
1787
|
+
timeline.render();
|
|
1788
|
+
textarea.focus();
|
|
1789
|
+
textarea.setSelectionRange(1, 4, 'backward');
|
|
1790
|
+
const offset = avm1 ? 'hscroll' : 'scrollH';
|
|
1791
|
+
const maximum = avm1 ? 'maxhscroll' : 'maxScrollH';
|
|
1792
|
+
const changes = [];
|
|
1793
|
+
if (avm1) field.onScroller = source => changes.push(source[offset]);
|
|
1794
|
+
else field.addEventListener(runtime.builtins.Event.SCROLL, () => changes.push(field[offset]));
|
|
1795
|
+
|
|
1796
|
+
field[offset] = 1000;
|
|
1797
|
+
expect([field[offset], field[maximum]]).toEqual([38, 38]);
|
|
1798
|
+
timeline.render();
|
|
1799
|
+
textarea.dispatch('scroll');
|
|
1800
|
+
expect([field[offset], textarea.scrollLeft]).toEqual([38, 38]);
|
|
1801
|
+
|
|
1802
|
+
textarea.scrollWidth = 32;
|
|
1803
|
+
timeline.render();
|
|
1804
|
+
textarea.dispatch('scroll');
|
|
1805
|
+
expect([field[offset], field[maximum], textarea.scrollLeft]).toEqual([12, 12, 12]);
|
|
1806
|
+
|
|
1807
|
+
textarea.scrollWidth = 58;
|
|
1808
|
+
timeline.render();
|
|
1809
|
+
expect([field[offset], field[maximum], textarea.scrollLeft]).toEqual([12, 38, 12]);
|
|
1810
|
+
textarea.scrollLeft = 6;
|
|
1811
|
+
textarea.dispatch('scroll');
|
|
1812
|
+
expect([field[offset], textarea.scrollLeft]).toEqual([6, 6]);
|
|
1813
|
+
|
|
1814
|
+
field[offset] = 11;
|
|
1815
|
+
textarea.scrollLeft = 8;
|
|
1816
|
+
textarea.dispatch('scroll');
|
|
1817
|
+
expect(field[offset]).toBe(11);
|
|
1818
|
+
timeline.render();
|
|
1819
|
+
textarea.dispatch('scroll');
|
|
1820
|
+
expect([field[offset], textarea.scrollLeft]).toEqual([11, 11]);
|
|
1821
|
+
expect(changes).toEqual(avm1 ? [38, 12, 6, 11] : [6]);
|
|
1822
|
+
expect(document.activeElement).toBe(textarea);
|
|
1823
|
+
expect([textarea.selectionStart, textarea.selectionEnd, textarea.selectionDirection]).toEqual([1, 4, 'backward']);
|
|
1824
|
+
});
|
|
1825
|
+
|
|
1826
|
+
it.each([true, false])('synchronizes native scrolling and wheel input for wrapped Super Smash Flash text with AVM1=%s', async avm1 => {
|
|
1827
|
+
const source = readFileSync(new URL('../../archive/flasharchive/Super Smash Flash.swf', import.meta.url));
|
|
1828
|
+
const { doc, diagnostics } = await parse(source);
|
|
1829
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
1830
|
+
const selected = new SymbolTable();
|
|
1831
|
+
selected.set(3559, symbolTable.get(3559));
|
|
1832
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
1833
|
+
const { root, timeline, controls, document, runtime, draws } = mountMovie(avm1, {
|
|
1834
|
+
frames: [{ places: [{ depth: 1, characterId: 3559, name: 'notes' }] }], characters,
|
|
1835
|
+
});
|
|
1836
|
+
timeline.enter();
|
|
1837
|
+
const field = root.notes;
|
|
1838
|
+
field.text = 'Use down arrow to duck. '.repeat(12);
|
|
1839
|
+
timeline.render();
|
|
1840
|
+
const [textarea] = controls();
|
|
1841
|
+
expect(textarea.tag).toBe('textarea');
|
|
1842
|
+
expect(textarea.style.whiteSpace).toBe('pre-wrap');
|
|
1843
|
+
expect(parseFloat(textarea.style.lineHeight)).toBeCloseTo(27.3);
|
|
1844
|
+
Object.assign(textarea, { clientHeight: 25, scrollHeight: 164 });
|
|
1845
|
+
timeline.render();
|
|
1846
|
+
expect(field.maxScrollV).toBe(6);
|
|
1847
|
+
textarea.focus();
|
|
1848
|
+
textarea.setSelectionRange(2, 8, 'backward');
|
|
1849
|
+
|
|
1850
|
+
const position = () => avm1 ? field.scroll : field.scrollV;
|
|
1851
|
+
const setPosition = line => { field[avm1 ? 'scroll' : 'scrollV'] = line; };
|
|
1852
|
+
const changes = [];
|
|
1853
|
+
if (avm1) field.onScroller = source => changes.push(source.scroll);
|
|
1854
|
+
else field.addEventListener(runtime.builtins.Event.SCROLL, event => changes.push([event.target, event.bubbles]));
|
|
1855
|
+
|
|
1856
|
+
setPosition(3);
|
|
1857
|
+
timeline.render();
|
|
1858
|
+
expect(textarea.scrollTop).toBeCloseTo(54.6);
|
|
1859
|
+
|
|
1860
|
+
textarea.scrollTop = 111.2;
|
|
1861
|
+
timeline.render();
|
|
1862
|
+
expect(textarea.scrollTop).toBeCloseTo(111.2);
|
|
1863
|
+
textarea.dispatch('scroll');
|
|
1864
|
+
textarea.dispatch('scroll');
|
|
1865
|
+
expect(position()).toBe(5);
|
|
1866
|
+
|
|
1867
|
+
setPosition(4);
|
|
1868
|
+
textarea.scrollTop = 0;
|
|
1869
|
+
textarea.dispatch('scroll');
|
|
1870
|
+
expect(position()).toBe(4);
|
|
1871
|
+
timeline.render();
|
|
1872
|
+
expect(textarea.scrollTop).toBeCloseTo(81.9);
|
|
1873
|
+
setPosition(99);
|
|
1874
|
+
timeline.render();
|
|
1875
|
+
expect(position()).toBe(6);
|
|
1876
|
+
expect(textarea.scrollTop).toBeCloseTo(136.5);
|
|
1877
|
+
|
|
1878
|
+
Object.assign(textarea, { scrollHeight: 250, scrollTop: 192.1 });
|
|
1879
|
+
textarea.dispatch('scroll');
|
|
1880
|
+
expect(position()).toBe(8);
|
|
1881
|
+
Object.assign(textarea, { scrollHeight: 300, scrollTop: 247.9 });
|
|
1882
|
+
timeline.render();
|
|
1883
|
+
expect(textarea.scrollTop).toBeCloseTo(247.9);
|
|
1884
|
+
textarea.dispatch('scroll');
|
|
1885
|
+
expect(position()).toBe(10);
|
|
1886
|
+
Object.assign(textarea, { scrollHeight: 27, scrollTop: 0 });
|
|
1887
|
+
timeline.render();
|
|
1888
|
+
textarea.dispatch('scroll');
|
|
1889
|
+
expect(position()).toBe(1);
|
|
1890
|
+
expect(changes).toEqual(avm1 ? [3, 5, 4, 6, 8, 10, 1] : [
|
|
1891
|
+
[field, false], [field, false], [field, false], [field, false],
|
|
1892
|
+
]);
|
|
1893
|
+
|
|
1894
|
+
textarea.scrollHeight = 164;
|
|
1895
|
+
let pixelOffset = textarea.scrollTop;
|
|
1896
|
+
Object.defineProperty(textarea, 'scrollTop', {
|
|
1897
|
+
get: () => pixelOffset,
|
|
1898
|
+
set: value => { pixelOffset = Math.floor(value); },
|
|
1899
|
+
});
|
|
1900
|
+
timeline.render();
|
|
1901
|
+
changes.length = 0;
|
|
1902
|
+
const wheel = (deltaY, deltaMode = 1) => textarea.dispatch('wheel', { deltaY, deltaMode }).defaultPrevented;
|
|
1903
|
+
textarea.blur();
|
|
1904
|
+
expect(wheel(2)).toBe(false);
|
|
1905
|
+
textarea.focus();
|
|
1906
|
+
field.mouseWheelEnabled = false;
|
|
1907
|
+
expect(wheel(2)).toBe(false);
|
|
1908
|
+
field.mouseWheelEnabled = true;
|
|
1909
|
+
field.selectable = false;
|
|
1910
|
+
expect(wheel(2)).toBe(false);
|
|
1911
|
+
field.selectable = true;
|
|
1912
|
+
textarea.disabled = true;
|
|
1913
|
+
expect(wheel(2)).toBe(false);
|
|
1914
|
+
textarea.disabled = false;
|
|
1915
|
+
expect(wheel(0)).toBe(false);
|
|
1916
|
+
expect(position()).toBe(1);
|
|
1917
|
+
|
|
1918
|
+
expect(wheel(80, 0)).toBe(true);
|
|
1919
|
+
expect([position(), textarea.scrollTop]).toEqual([3, 54]);
|
|
1920
|
+
textarea.dispatch('scroll');
|
|
1921
|
+
expect(wheel(-1)).toBe(true);
|
|
1922
|
+
expect([position(), textarea.scrollTop]).toEqual([2, 27]);
|
|
1923
|
+
expect(wheel(99)).toBe(true);
|
|
1924
|
+
expect([position(), textarea.scrollTop]).toEqual([6, 136]);
|
|
1925
|
+
textarea.scrollTop = 139;
|
|
1926
|
+
textarea.dispatch('scroll');
|
|
1927
|
+
expect(avm1 ? field.bottomScroll : field.bottomScrollV).toBe(6);
|
|
1928
|
+
expect(wheel(1)).toBe(false);
|
|
1929
|
+
expect(changes).toEqual(avm1 ? [3, 2, 6] : [[field, false], [field, false], [field, false]]);
|
|
1930
|
+
|
|
1931
|
+
setPosition(4);
|
|
1932
|
+
expect(wheel(-1)).toBe(false);
|
|
1933
|
+
timeline.render();
|
|
1934
|
+
expect([position(), textarea.scrollTop]).toEqual([4, 81]);
|
|
1935
|
+
|
|
1936
|
+
field.wordWrap = false;
|
|
1937
|
+
Object.assign(textarea, { clientWidth: 80, scrollWidth: 120 });
|
|
1938
|
+
timeline.render();
|
|
1939
|
+
expect(textarea.style.whiteSpace).toBe('pre');
|
|
1940
|
+
const horizontal = avm1 ? 'hscroll' : 'scrollH';
|
|
1941
|
+
const maximum = avm1 ? 'maxhscroll' : 'maxScrollH';
|
|
1942
|
+
field[horizontal] = 20;
|
|
1943
|
+
timeline.render();
|
|
1944
|
+
expect([field[horizontal], field[maximum], textarea.scrollLeft]).toEqual([20, 40, 20]);
|
|
1945
|
+
field.wordWrap = true;
|
|
1946
|
+
Object.assign(textarea, { scrollWidth: 80, scrollLeft: 0 });
|
|
1947
|
+
timeline.render();
|
|
1948
|
+
expect(textarea.style.whiteSpace).toBe('pre-wrap');
|
|
1949
|
+
expect(field[maximum]).toBe(0);
|
|
1950
|
+
expect(controls()).toEqual([textarea]);
|
|
1951
|
+
expect(document.activeElement).toBe(textarea);
|
|
1952
|
+
expect([textarea.selectionStart, textarea.selectionEnd, textarea.selectionDirection]).toEqual([2, 8, 'backward']);
|
|
1953
|
+
|
|
1954
|
+
field.text = 'Duck';
|
|
1955
|
+
field.type = 'dynamic';
|
|
1956
|
+
timeline.render();
|
|
1957
|
+
expect(controls()).toHaveLength(0);
|
|
1958
|
+
expect(document.activeElement).toBeNull();
|
|
1959
|
+
expect(runtime.stage.focus).toBeNull();
|
|
1960
|
+
expect(draws.at(-1)).toBe('Duck');
|
|
1961
|
+
|
|
1962
|
+
const firstWord = 'A'.repeat(28);
|
|
1963
|
+
const longLine = firstWord + ' ' + 'B'.repeat(16);
|
|
1964
|
+
field.text = longLine;
|
|
1965
|
+
setPosition(1);
|
|
1966
|
+
draws.length = 0;
|
|
1967
|
+
timeline.render();
|
|
1968
|
+
expect(draws).toEqual([firstWord]);
|
|
1969
|
+
|
|
1970
|
+
field.wordWrap = false;
|
|
1971
|
+
draws.length = 0;
|
|
1972
|
+
timeline.render();
|
|
1973
|
+
expect(draws).toEqual([longLine]);
|
|
1974
|
+
|
|
1975
|
+
field.text = 'Duck';
|
|
1976
|
+
field.wordWrap = true;
|
|
1977
|
+
field.type = 'input';
|
|
1978
|
+
timeline.render();
|
|
1979
|
+
const [newTextarea] = controls();
|
|
1980
|
+
expect(newTextarea).not.toBe(textarea);
|
|
1981
|
+
expect(newTextarea).toMatchObject({ tag: 'textarea', value: 'Duck' });
|
|
1982
|
+
});
|
|
1983
|
+
|
|
1984
|
+
it.each([true, false])('scrolls a programmatic multiline textarea with default leading and AVM1=%s', avm1 => {
|
|
1985
|
+
const { root, runtime, timeline, controls, document } = mountMovie(avm1);
|
|
1986
|
+
const field = avm1 ? root.createTextField('notes', 1, 0, 0, 100, 20) : root.addChild(new runtime.builtins.TextField());
|
|
1987
|
+
Object.assign(field, { type: 'input', width: 100, height: 20, multiline: true, wordWrap: true,
|
|
1988
|
+
text: 'one\ntwo\nthree\nfour\nfive' });
|
|
1989
|
+
timeline.enter();
|
|
1990
|
+
const [textarea] = controls();
|
|
1991
|
+
expect(textarea.tag).toBe('textarea');
|
|
1992
|
+
expect(field.defaultTextFormat.leading).toBeNull();
|
|
1993
|
+
expect(parseFloat(textarea.style.lineHeight)).toBeCloseTo(14.4);
|
|
1994
|
+
Object.assign(textarea, { clientHeight: 20, scrollHeight: 72 });
|
|
1995
|
+
timeline.render();
|
|
1996
|
+
textarea.focus();
|
|
1997
|
+
textarea.setSelectionRange(1, 5, 'backward');
|
|
1998
|
+
|
|
1999
|
+
const scroll = avm1 ? 'scroll' : 'scrollV';
|
|
2000
|
+
const bottomScroll = avm1 ? 'bottomScroll' : 'bottomScrollV';
|
|
2001
|
+
const changes = [];
|
|
2002
|
+
if (avm1) field.onScroller = source => changes.push(source.scroll);
|
|
2003
|
+
else field.addEventListener(runtime.builtins.Event.SCROLL, () => changes.push(field.scrollV));
|
|
2004
|
+
expect(field[bottomScroll]).toBe(2);
|
|
2005
|
+
textarea.scrollTop = 13.8;
|
|
2006
|
+
textarea.dispatch('scroll');
|
|
2007
|
+
expect(field[scroll]).toBe(1);
|
|
2008
|
+
expect(field[bottomScroll]).toBe(3);
|
|
2009
|
+
field[scroll] = 3;
|
|
2010
|
+
expect(field[bottomScroll]).toBe(4);
|
|
2011
|
+
timeline.render();
|
|
2012
|
+
expect(textarea.scrollTop).toBeCloseTo(28.8);
|
|
2013
|
+
textarea.scrollTop = 44;
|
|
2014
|
+
textarea.dispatch('scroll');
|
|
2015
|
+
expect(field[scroll]).toBe(4);
|
|
2016
|
+
expect(textarea.dispatch('wheel', { deltaY: -2, deltaMode: 1 }).defaultPrevented).toBe(true);
|
|
2017
|
+
expect(field[scroll]).toBe(2);
|
|
2018
|
+
expect(textarea.scrollTop).toBeCloseTo(14.4);
|
|
2019
|
+
expect(changes).toEqual(avm1 ? [3, 4, 2] : [4, 2]);
|
|
2020
|
+
|
|
2021
|
+
field.defaultTextFormat.size = 24;
|
|
2022
|
+
textarea.scrollHeight = 144;
|
|
2023
|
+
timeline.render();
|
|
2024
|
+
expect(field[scroll]).toBe(2);
|
|
2025
|
+
expect(textarea.scrollTop).toBeCloseTo(28.8);
|
|
2026
|
+
expect(changes).toEqual(avm1 ? [3, 4, 2] : [4, 2]);
|
|
2027
|
+
|
|
2028
|
+
field.defaultTextFormat.size = 30;
|
|
2029
|
+
Object.assign(textarea, { scrollHeight: 180, scrollTop: 91 });
|
|
2030
|
+
timeline.render();
|
|
2031
|
+
expect(textarea.scrollTop).toBe(91);
|
|
2032
|
+
textarea.dispatch('scroll');
|
|
2033
|
+
expect(field[scroll]).toBe(3);
|
|
2034
|
+
expect(changes).toEqual(avm1 ? [3, 4, 2, 3] : [4, 2, 3]);
|
|
2035
|
+
expect(document.activeElement).toBe(textarea);
|
|
2036
|
+
expect([textarea.selectionStart, textarea.selectionEnd, textarea.selectionDirection]).toEqual([1, 5, 'backward']);
|
|
2037
|
+
});
|
|
2038
|
+
|
|
2039
|
+
it('wheel-scrolls the authored Plazma Burst 2 read-only Canvas field after a primary press', async () => {
|
|
2040
|
+
const source = readFileSync(new URL('../../archive/Swf/plazma-burst-2.swf', import.meta.url));
|
|
2041
|
+
const { doc, diagnostics } = await parse(source);
|
|
2042
|
+
const { symbolTable } = decode(doc, diagnostics);
|
|
2043
|
+
const selected = new SymbolTable();
|
|
2044
|
+
selected.set(1213, symbolTable.get(1213));
|
|
2045
|
+
const { characters } = buildDisplayList([], selected, diagnostics, { swfVersion: doc.header.version });
|
|
2046
|
+
const { root, timeline, draws, dispatchCanvas, runtime } = mountMovie(false, {
|
|
2047
|
+
frames: [{ places: [{ depth: 1, characterId: 1213, name: 'notice' }] }], characters,
|
|
2048
|
+
}, { pointerEvents: true });
|
|
2049
|
+
timeline.enter();
|
|
2050
|
+
const field = root.notice;
|
|
2051
|
+
field.embedFonts = false;
|
|
2052
|
+
field.text = Array.from({ length: 24 }, (_, index) => 'row' + (index + 1)).join('\n');
|
|
2053
|
+
const changes = [];
|
|
2054
|
+
field.addEventListener(runtime.builtins.Event.SCROLL, event => changes.push([event.target, field.scrollV]));
|
|
2055
|
+
|
|
2056
|
+
field.scrollV = 3;
|
|
2057
|
+
draws.length = 0;
|
|
2058
|
+
timeline.render();
|
|
2059
|
+
expect(draws[0]).toBe('row3');
|
|
2060
|
+
expect(changes).toEqual([]);
|
|
2061
|
+
field.scrollV = 1;
|
|
2062
|
+
timeline.render();
|
|
2063
|
+
|
|
2064
|
+
const wheel = (deltaY = 2) => dispatchCanvas('wheel', { deltaY, deltaMode: 1 }).defaultPrevented;
|
|
2065
|
+
expect(wheel()).toBe(false);
|
|
2066
|
+
dispatchCanvas('pointerdown');
|
|
2067
|
+
field.mouseWheelEnabled = false;
|
|
2068
|
+
expect(wheel()).toBe(false);
|
|
2069
|
+
field.mouseWheelEnabled = true;
|
|
2070
|
+
draws.length = 0;
|
|
2071
|
+
expect(wheel()).toBe(true);
|
|
2072
|
+
expect(field.scrollV).toBe(3);
|
|
2073
|
+
expect(draws[0]).toBe('row3');
|
|
2074
|
+
expect(changes).toEqual([[field, 3]]);
|
|
2075
|
+
dispatchCanvas('pointerdown', { clientY: 0, clientX: 205 });
|
|
2076
|
+
expect(wheel()).toBe(false);
|
|
2077
|
+
});
|
|
2078
|
+
|
|
2079
|
+
it('wheel-scrolls a script-created AS3 Canvas text field through the mouse fallback', () => {
|
|
2080
|
+
const { root, timeline, dispatchCanvas, draws, runtime } = mountMovie();
|
|
2081
|
+
const field = root.addChild(new runtime.builtins.TextField());
|
|
2082
|
+
Object.assign(field, { width: 80, height: 15, multiline: true, text: 'one\ntwo\nthree\nfour' });
|
|
2083
|
+
timeline.enter();
|
|
2084
|
+
dispatchCanvas('mousedown', { clientY: 8 });
|
|
2085
|
+
draws.length = 0;
|
|
2086
|
+
expect(dispatchCanvas('wheel', { clientY: 8, deltaY: 1, deltaMode: 1 }).defaultPrevented).toBe(true);
|
|
2087
|
+
expect(field.scrollV).toBe(2);
|
|
2088
|
+
expect(draws[0]).toBe('two');
|
|
2089
|
+
});
|
|
2090
|
+
|
|
2091
|
+
it('keeps an authored button above a read-only Canvas text field in the wheel hit order', () => {
|
|
2092
|
+
const matrix = { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 };
|
|
2093
|
+
const record = { characterId: 3, depth: 1, matrix };
|
|
2094
|
+
const bounds = { x: 0, y: 0, w: 80, h: 22 };
|
|
2095
|
+
const { root, timeline, dispatchCanvas } = mountMovie(false, {
|
|
2096
|
+
frames: [{ places: [
|
|
2097
|
+
{ depth: 1, characterId: 1, name: 'text', matrix },
|
|
2098
|
+
{ depth: 2, characterId: 2, name: 'button', matrix },
|
|
2099
|
+
] }],
|
|
2100
|
+
characters: {
|
|
2101
|
+
1: { type: 'text', kind: 'edit', readOnly: true, multiline: true, bounds, text: 'one\ntwo\nthree\nfour' },
|
|
2102
|
+
2: { type: 'button', buttonStates: { up: [record] }, buttonHitStates: [record] },
|
|
2103
|
+
3: { type: 'shape', bounds, draws: [{ fill: { type: 'solid', color: '#f00' },
|
|
2104
|
+
path: [['M', 0, 0], ['L', 80, 0], ['L', 80, 22], ['L', 0, 22], ['Z']] }] },
|
|
2105
|
+
},
|
|
2106
|
+
}, { pointerEvents: true });
|
|
2107
|
+
timeline.enter();
|
|
2108
|
+
const click = () => {
|
|
2109
|
+
const press = dispatchCanvas('pointerdown', { clientY: 8 });
|
|
2110
|
+
dispatchCanvas('pointerup', { clientY: 8 });
|
|
2111
|
+
return press.defaultPrevented;
|
|
2112
|
+
};
|
|
2113
|
+
const wheel = () => dispatchCanvas('wheel', { clientY: 8, deltaY: 1, deltaMode: 1 }).defaultPrevented;
|
|
2114
|
+
expect(click()).toBe(true);
|
|
2115
|
+
expect(wheel()).toBe(false);
|
|
2116
|
+
expect(root.text.scrollV).toBe(1);
|
|
2117
|
+
|
|
2118
|
+
root.button.visible = false;
|
|
2119
|
+
timeline.render();
|
|
2120
|
+
expect(wheel()).toBe(false);
|
|
2121
|
+
click();
|
|
2122
|
+
expect(wheel()).toBe(true);
|
|
2123
|
+
expect(root.text.scrollV).toBe(2);
|
|
2124
|
+
root.button.visible = true;
|
|
2125
|
+
timeline.render();
|
|
2126
|
+
expect(wheel()).toBe(false);
|
|
2127
|
+
expect(root.text.scrollV).toBe(2);
|
|
2128
|
+
});
|
|
2129
|
+
|
|
2130
|
+
it('updates an authored input’s family in place and restores its linked embedded face', () => {
|
|
2131
|
+
const { root, timeline, controls, document } = mountMovie(true, {
|
|
2132
|
+
frames: [{ places: [{ depth: 1, characterId: 1, name: 'entry' }] }],
|
|
2133
|
+
characters: {
|
|
2134
|
+
1: { type: 'text', kind: 'edit', editable: true, text: 'typed', font: 'Linked Native', outlineFontId: 2,
|
|
2135
|
+
fontSize: 12, bounds: { x: 0, y: 0, w: 130, h: 30 } },
|
|
2136
|
+
2: { type: 'font', name: 'Linked Native', codes: [116], layout: { advances: [640], ascent: 896, descent: 128 } },
|
|
2137
|
+
},
|
|
2138
|
+
loaded: { 2: { family: 'swoof-linked-native' } },
|
|
2139
|
+
});
|
|
2140
|
+
timeline.enter();
|
|
2141
|
+
const [input] = controls();
|
|
2142
|
+
const linkedFamily = '"swoof-linked-native", "Linked Native", Arial, sans-serif';
|
|
2143
|
+
expect(input.style.fontFamily).toBe(linkedFamily);
|
|
2144
|
+
input.focus();
|
|
2145
|
+
input.setSelectionRange(1, 4, 'backward');
|
|
2146
|
+
|
|
2147
|
+
root.entry.setTextFormat({ font: 'Courier New' });
|
|
2148
|
+
timeline.render();
|
|
2149
|
+
expect(input.style.fontFamily).toBe('"Courier New", Arial, sans-serif');
|
|
2150
|
+
|
|
2151
|
+
root.entry.setTextFormat({ font: 'Linked Native' });
|
|
2152
|
+
timeline.render();
|
|
2153
|
+
expect(input.style.fontFamily).toBe(linkedFamily);
|
|
2154
|
+
|
|
2155
|
+
root.entry.embedFonts = false;
|
|
2156
|
+
timeline.render();
|
|
2157
|
+
expect(input.style.fontFamily).toBe('"Linked Native", Arial, sans-serif');
|
|
2158
|
+
expect(controls()).toEqual([input]);
|
|
2159
|
+
expect(document.activeElement).toBe(input);
|
|
2160
|
+
expect([input.selectionStart, input.selectionEnd, input.selectionDirection]).toEqual([1, 4, 'backward']);
|
|
2161
|
+
});
|
|
2162
|
+
|
|
2163
|
+
it('transforms an authored input’s local field bounds with its placement', () => {
|
|
2164
|
+
const { root, timeline, controls } = mountMovie(true, {
|
|
2165
|
+
frames: [{ places: [{ depth: 1, characterId: 1, name: 'field', matrix: { a: 0, b: 2, c: -3, d: 0, tx: 400, ty: 600 } }] }],
|
|
2166
|
+
characters: {
|
|
2167
|
+
1: { type: 'text', kind: 'edit', editable: true, text: 'typed', fontSize: 6.5, bounds: { x: 4, y: -2, w: 7, h: 5 } },
|
|
2168
|
+
},
|
|
2169
|
+
});
|
|
2170
|
+
timeline.enter();
|
|
2171
|
+
const [input] = controls();
|
|
2172
|
+
expect(input.value).toBe('typed');
|
|
2173
|
+
expect(input.style).toMatchObject({ left: '0px', top: '0px', width: '7px', height: '5px', fontSize: '6.5px',
|
|
2174
|
+
transform: 'matrix(0,2,-3,0,26,38)', opacity: '1' });
|
|
2175
|
+
root.field.alpha = 0;
|
|
2176
|
+
timeline.render();
|
|
2177
|
+
expect(controls()).toHaveLength(0);
|
|
2178
|
+
});
|
|
2179
|
+
|
|
2180
|
+
it('clips an authored input to its exposed area under later Button artwork and clears stale focus', () => {
|
|
2181
|
+
const rect = (width, height) => ({
|
|
2182
|
+
type: 'shape',
|
|
2183
|
+
draws: [{ fill: { type: 'solid', color: '#fff' },
|
|
2184
|
+
path: [['M', 0, 0], ['L', width, 0], ['L', width, height], ['L', 0, height], ['Z']] }],
|
|
2185
|
+
});
|
|
2186
|
+
const { root, timeline, controls, document, selection } = mountMovie(true, {
|
|
2187
|
+
frames: [{ places: [
|
|
2188
|
+
{ depth: 1, characterId: 1 },
|
|
2189
|
+
{ depth: 2, characterId: 2, name: 'field' },
|
|
2190
|
+
{ depth: 3, characterId: 3, name: 'button' },
|
|
2191
|
+
] }],
|
|
2192
|
+
characters: {
|
|
2193
|
+
1: rect(100, 20),
|
|
2194
|
+
2: { type: 'text', kind: 'edit', editable: true, text: 'shown', bounds: { x: 4, y: 0, w: 70, h: 20 } },
|
|
2195
|
+
3: { type: 'button', buttonUp: { characterId: 4 }, buttonHitStates: [{ characterId: 1 }] },
|
|
2196
|
+
4: rect(40, 20),
|
|
2197
|
+
},
|
|
2198
|
+
});
|
|
2199
|
+
timeline.enter();
|
|
2200
|
+
const [input] = controls();
|
|
2201
|
+
expect(input.style.clipPath).toBe('path("M36 0H70V20H36Z")');
|
|
2202
|
+
input.focus();
|
|
2203
|
+
expect(selection.getFocus()).toBe('_level0.field');
|
|
2204
|
+
|
|
2205
|
+
const cover = root.createEmptyMovieClip('cover', 4);
|
|
2206
|
+
cover.beginFill(0x000000, 100);
|
|
2207
|
+
cover.drawRect(0, 0, 100, 20);
|
|
2208
|
+
timeline.render();
|
|
2209
|
+
expect(controls()).toHaveLength(0);
|
|
2210
|
+
expect(document.activeElement).toBeNull();
|
|
2211
|
+
expect(selection.getFocus()).toBeNull();
|
|
2212
|
+
|
|
2213
|
+
cover.alpha = 50;
|
|
2214
|
+
root.button.visible = false;
|
|
2215
|
+
timeline.render();
|
|
2216
|
+
const [uncovered] = controls();
|
|
2217
|
+
expect(uncovered.style.clipPath).toBe('');
|
|
2218
|
+
expect(uncovered.value).toBe('shown');
|
|
2219
|
+
});
|
|
2220
|
+
|
|
2221
|
+
it('clips stage-created input under a later programmatic button but keeps it under translucent artwork', () => {
|
|
2222
|
+
const { root, runtime, timeline, controls } = mountMovie();
|
|
2223
|
+
const { TextField, SimpleButton, Shape } = runtime.builtins;
|
|
2224
|
+
const field = root.addChild(new TextField());
|
|
2225
|
+
field.type = 'input'; field.width = 50; field.height = 10;
|
|
2226
|
+
const art = new Shape();
|
|
2227
|
+
art.graphics.beginFill(0x000000);
|
|
2228
|
+
art.graphics.drawRect(10, 0, 20, 10);
|
|
2229
|
+
const button = root.addChild(new SimpleButton());
|
|
2230
|
+
button.upState = art;
|
|
2231
|
+
timeline.render();
|
|
2232
|
+
const [input] = controls();
|
|
2233
|
+
expect(input.style.clipPath).toBe('path("M0 0H10V10H0Z M30 0H50V10H30Z")');
|
|
2234
|
+
|
|
2235
|
+
button.alpha = 0.5;
|
|
2236
|
+
timeline.render();
|
|
2237
|
+
expect(controls()).toEqual([input]);
|
|
2238
|
+
expect(input.style.clipPath).toBe('');
|
|
2239
|
+
});
|
|
2240
|
+
|
|
2241
|
+
it('paints read-only AVM1 fields with their authored content and live bindings on Canvas', () => {
|
|
2242
|
+
const bounds = { x: 0, y: 0, w: 130, h: 22 };
|
|
2243
|
+
const { root, timeline, controls, draws, textColors } = mountMovie(true, {
|
|
2244
|
+
frames: [{ places: [{ depth: 1, characterId: 1 }, { depth: 2, characterId: 2, name: 'caption' }] }],
|
|
2245
|
+
characters: {
|
|
2246
|
+
1: { type: 'text', kind: 'edit', editable: false, text: 'Title', color: '#ac1500', bounds },
|
|
2247
|
+
2: { type: 'text', kind: 'edit', editable: false, html: true, text: '<b>Caption</b>', color: '#5040ac', bounds, variableName: 'label' },
|
|
2248
|
+
},
|
|
2249
|
+
});
|
|
2250
|
+
timeline.enter();
|
|
2251
|
+
expect(draws).toContain('Title');
|
|
2252
|
+
expect(draws).toContain('Caption');
|
|
2253
|
+
expect(textColors[draws.indexOf('Title')]).toBe('#ac1500');
|
|
2254
|
+
expect(textColors[draws.indexOf('Caption')]).toBe('#5040ac');
|
|
2255
|
+
expect(controls()).toHaveLength(0);
|
|
2256
|
+
expect(root.caption.text).toBe('Caption');
|
|
2257
|
+
root.caption.text = 'Updated';
|
|
2258
|
+
timeline.render();
|
|
2259
|
+
expect(draws).toContain('Updated');
|
|
2260
|
+
root.label = '<i>Variable</i>';
|
|
2261
|
+
timeline.render();
|
|
2262
|
+
expect(draws).toContain('Variable');
|
|
2263
|
+
});
|
|
2264
|
+
|
|
2265
|
+
it('mounts AS3 input, applies pending focus and selection, and keeps the overlay through reordering', () => {
|
|
2266
|
+
const { runtime, root, timeline, document, controls, draws } = mountMovie();
|
|
2267
|
+
const { Sprite, TextField, TextEvent } = runtime.builtins;
|
|
2268
|
+
const parent = root.addChild(new Sprite());
|
|
2269
|
+
parent.x = 20;
|
|
2270
|
+
parent.scaleX = 2;
|
|
2271
|
+
const field = parent.addChild(new TextField());
|
|
2272
|
+
field.type = 'input';
|
|
2273
|
+
field.x = 4; field.y = 5; field.width = 60; field.height = 20;
|
|
2274
|
+
field.text = 'name';
|
|
2275
|
+
field.maxChars = 8;
|
|
2276
|
+
field.setSelection(1, 3);
|
|
2277
|
+
runtime.stage.focus = field;
|
|
2278
|
+
timeline.render();
|
|
2279
|
+
|
|
2280
|
+
const [input] = controls();
|
|
2281
|
+
expect(input.style.transform).toBe('matrix(2,0,0,1,28,5)');
|
|
2282
|
+
expect(input.value).toBe('name');
|
|
2283
|
+
expect(field.maxChars).toBe(8);
|
|
2284
|
+
expect(document.activeElement).toBe(input);
|
|
2285
|
+
expect([input.selectionStart, input.selectionEnd]).toEqual([1, 3]);
|
|
2286
|
+
expect(draws).not.toContain('name');
|
|
2287
|
+
|
|
2288
|
+
const cancelTyping = event => event.preventDefault();
|
|
2289
|
+
field.addEventListener(TextEvent.TEXT_INPUT, cancelTyping);
|
|
2290
|
+
expect(input.dispatch('beforeinput', { data: 'x' }).defaultPrevented).toBe(true);
|
|
2291
|
+
field.removeEventListener(TextEvent.TEXT_INPUT, cancelTyping);
|
|
2292
|
+
input.value = 'saved';
|
|
2293
|
+
input.setSelectionRange(5, 5);
|
|
2294
|
+
input.dispatch('input');
|
|
2295
|
+
expect(field.text).toBe('saved');
|
|
2296
|
+
expect(field.caretIndex).toBe(5);
|
|
2297
|
+
|
|
2298
|
+
const extra = new TextField();
|
|
2299
|
+
extra.type = 'input';
|
|
2300
|
+
expect([extra.width, extra.height]).toEqual([100, 100]);
|
|
2301
|
+
parent.addChildAt(extra, 0);
|
|
2302
|
+
timeline.render();
|
|
2303
|
+
expect(field._swoofOverlayElement).toBe(input);
|
|
2304
|
+
expect(document.activeElement).toBe(input);
|
|
2305
|
+
|
|
2306
|
+
field.multiline = true;
|
|
2307
|
+
timeline.render();
|
|
2308
|
+
const textarea = field._swoofOverlayElement;
|
|
2309
|
+
expect(textarea.tag).toBe('textarea');
|
|
2310
|
+
expect(textarea.selectionStart).toBe(5);
|
|
2311
|
+
expect(document.activeElement).toBe(textarea);
|
|
2312
|
+
expect(runtime.stage.focus).toBe(field);
|
|
2313
|
+
|
|
2314
|
+
field.type = 'dynamic';
|
|
2315
|
+
timeline.render();
|
|
2316
|
+
expect(controls()).not.toContain(textarea);
|
|
2317
|
+
expect(document.activeElement).toBeNull();
|
|
2318
|
+
expect(runtime.stage.focus).toBeNull();
|
|
2319
|
+
expect(draws).toContain('saved');
|
|
2320
|
+
});
|
|
2321
|
+
|
|
2322
|
+
it('filters paste before insertion and counts UTF-16 length without splitting characters', () => {
|
|
2323
|
+
const { runtime, root, timeline, controls } = mountMovie();
|
|
2324
|
+
const { TextField, TextEvent, Event } = runtime.builtins;
|
|
2325
|
+
const field = root.addChild(new TextField());
|
|
2326
|
+
field.type = 'input';
|
|
2327
|
+
field.restrict = 'A-Z0-9^4-6';
|
|
2328
|
+
field.maxChars = 4;
|
|
2329
|
+
const events = [];
|
|
2330
|
+
field.addEventListener(TextEvent.TEXT_INPUT, event => events.push(['input', event.text]));
|
|
2331
|
+
field.addEventListener(Event.CHANGE, () => events.push(['change', field.text]));
|
|
2332
|
+
timeline.render();
|
|
2333
|
+
const [input] = controls();
|
|
2334
|
+
const paste = input.dispatch('beforeinput', {
|
|
2335
|
+
inputType: 'insertFromPaste',
|
|
2336
|
+
dataTransfer: { getData: () => 'ab4🚀9c' },
|
|
2337
|
+
});
|
|
2338
|
+
expect(paste.defaultPrevented).toBe(true);
|
|
2339
|
+
expect(field.text).toBe('AB9C');
|
|
2340
|
+
expect(input.selectionStart).toBe(4);
|
|
2341
|
+
expect(events).toEqual([['input', 'ab4🚀9c'], ['change', 'AB9C']]);
|
|
2342
|
+
|
|
2343
|
+
field.restrict = '😀-🙏';
|
|
2344
|
+
field.maxChars = 3;
|
|
2345
|
+
field.text = 'SCRIPT TOO LONG!';
|
|
2346
|
+
timeline.render();
|
|
2347
|
+
expect(input.value).toBe('SCRIPT TOO LONG!');
|
|
2348
|
+
input.setSelectionRange(0, input.value.length);
|
|
2349
|
+
input.dispatch('beforeinput', { data: '😀😎', inputType: 'insertText' });
|
|
2350
|
+
expect(input.value).toBe('😀');
|
|
2351
|
+
expect(field.length).toBe(2);
|
|
2352
|
+
expect(input.selectionStart).toBe(2);
|
|
2353
|
+
|
|
2354
|
+
field.restrict = '';
|
|
2355
|
+
input.setSelectionRange(0, 2);
|
|
2356
|
+
input.dispatch('beforeinput', { data: 'z', inputType: 'insertText' });
|
|
2357
|
+
expect(input.value).toBe('😀');
|
|
2358
|
+
expect([input.selectionStart, input.selectionEnd]).toEqual([0, 2]);
|
|
2359
|
+
expect(events.at(-1)).toEqual(['input', 'z']);
|
|
2360
|
+
|
|
2361
|
+
field.restrict = '0-9';
|
|
2362
|
+
field.maxChars = 4;
|
|
2363
|
+
field.text = 'X€Y';
|
|
2364
|
+
timeline.render();
|
|
2365
|
+
input.setSelectionRange(1, 2);
|
|
2366
|
+
input.dispatch('beforeinput', { data: '314', inputType: 'insertText' });
|
|
2367
|
+
expect(field.text).toBe('X31Y');
|
|
2368
|
+
expect(input.selectionStart).toBe(3);
|
|
2369
|
+
});
|
|
2370
|
+
|
|
2371
|
+
it('handles escaped restriction operators and accepts unrestricted deletion', () => {
|
|
2372
|
+
const { runtime, root, timeline, controls } = mountMovie();
|
|
2373
|
+
const field = root.addChild(new runtime.builtins.TextField());
|
|
2374
|
+
field.type = 'input';
|
|
2375
|
+
field.restrict = String.raw`\^\-\\é`;
|
|
2376
|
+
timeline.render();
|
|
2377
|
+
const [input] = controls();
|
|
2378
|
+
input.dispatch('beforeinput', { data: 'a^-\\é😀', inputType: 'insertText' });
|
|
2379
|
+
expect(field.text).toBe('^-\\é');
|
|
2380
|
+
field.text = 'script text';
|
|
2381
|
+
field.maxChars = 1;
|
|
2382
|
+
timeline.render();
|
|
2383
|
+
input.value = 'script tex';
|
|
2384
|
+
input.setSelectionRange(10, 10);
|
|
2385
|
+
input.dispatch('input', { inputType: 'deleteContentBackward' });
|
|
2386
|
+
expect(field.text).toBe('script tex');
|
|
2387
|
+
});
|
|
2388
|
+
|
|
2389
|
+
it('rolls back a canceled edit when beforeinput cannot be canceled natively', () => {
|
|
2390
|
+
const { runtime, root, timeline, controls } = mountMovie();
|
|
2391
|
+
const { TextField, TextEvent, Event } = runtime.builtins;
|
|
2392
|
+
const field = root.addChild(new TextField());
|
|
2393
|
+
field.type = 'input';
|
|
2394
|
+
field.text = 'safe';
|
|
2395
|
+
timeline.render();
|
|
2396
|
+
const [input] = controls();
|
|
2397
|
+
input.setSelectionRange(1, 3, 'backward');
|
|
2398
|
+
field.addEventListener(TextEvent.TEXT_INPUT, event => event.preventDefault());
|
|
2399
|
+
const changes = [];
|
|
2400
|
+
field.addEventListener(Event.CHANGE, () => changes.push(field.text));
|
|
2401
|
+
input.dispatch('beforeinput', { data: 'z', inputType: 'insertReplacementText', cancelable: false });
|
|
2402
|
+
input.value = 'sze';
|
|
2403
|
+
input.setSelectionRange(2, 2);
|
|
2404
|
+
input.dispatch('input', { inputType: 'insertReplacementText' });
|
|
2405
|
+
expect(input.value).toBe('safe');
|
|
2406
|
+
expect(field.text).toBe('safe');
|
|
2407
|
+
expect([input.selectionStart, input.selectionEnd, input.selectionDirection]).toEqual([1, 3, 'backward']);
|
|
2408
|
+
expect(changes).toEqual([]);
|
|
2409
|
+
});
|
|
2410
|
+
|
|
2411
|
+
it('keeps filtered, hidden, and detached fields out of the native overlay', () => {
|
|
2412
|
+
const { runtime, root, timeline, controls, draws } = mountMovie();
|
|
2413
|
+
const { TextField, BlurFilter } = runtime.builtins;
|
|
2414
|
+
const field = root.addChild(new TextField());
|
|
2415
|
+
field.type = 'input';
|
|
2416
|
+
field.text = 'fallback';
|
|
2417
|
+
field.filters = [new BlurFilter(4, 4)];
|
|
2418
|
+
timeline.render();
|
|
2419
|
+
expect(controls()).toHaveLength(0);
|
|
2420
|
+
expect(draws).toContain('fallback');
|
|
2421
|
+
|
|
2422
|
+
field.filters = [];
|
|
2423
|
+
timeline.render();
|
|
2424
|
+
const [input] = controls();
|
|
2425
|
+
expect(input.value).toBe('fallback');
|
|
2426
|
+
field.visible = false;
|
|
2427
|
+
timeline.render();
|
|
2428
|
+
expect(controls()).toHaveLength(0);
|
|
2429
|
+
|
|
2430
|
+
field.visible = true;
|
|
2431
|
+
timeline.render();
|
|
2432
|
+
const [visibleInput] = controls();
|
|
2433
|
+
visibleInput.focus();
|
|
2434
|
+
root.removeChild(field);
|
|
2435
|
+
timeline.render();
|
|
2436
|
+
expect(controls()).toHaveLength(0);
|
|
2437
|
+
expect(runtime.stage.focus).toBeNull();
|
|
2438
|
+
});
|
|
2439
|
+
|
|
2440
|
+
it('renders an AVM1-created field in its owned depth and bridges Selection and relative variables', () => {
|
|
2441
|
+
const { root, timeline, selection, controls, document, draws } = mountMovie(true);
|
|
2442
|
+
const owner = root.createEmptyMovieClip('panel', 2);
|
|
2443
|
+
owner.x = 7;
|
|
2444
|
+
owner.scaleX = 200;
|
|
2445
|
+
const field = owner.createTextField('entry', 3, 5, 3, 80, 24);
|
|
2446
|
+
expect(owner.entry).toBe(field);
|
|
2447
|
+
expect(field.getDepth()).toBe(3);
|
|
2448
|
+
expect(field.type).toBe('dynamic');
|
|
2449
|
+
field.text = 'canvas';
|
|
2450
|
+
timeline.render();
|
|
2451
|
+
expect(draws).toContain('canvas');
|
|
2452
|
+
expect(controls()).toHaveLength(0);
|
|
2453
|
+
|
|
2454
|
+
field.type = 'input';
|
|
2455
|
+
field.variable = 'stored';
|
|
2456
|
+
owner.stored = 'preset';
|
|
2457
|
+
expect(selection.setFocus('_root.panel.entry')).toBe(true);
|
|
2458
|
+
timeline.render();
|
|
2459
|
+
const [input] = controls();
|
|
2460
|
+
expect(input.style.transform).toBe('matrix(2,0,0,1,17,3)');
|
|
2461
|
+
expect(input.value).toBe('preset');
|
|
2462
|
+
expect(field.text).toBe('preset');
|
|
2463
|
+
timeline.render();
|
|
2464
|
+
expect(owner.stored).toBe('preset');
|
|
2465
|
+
expect(document.activeElement).toBe(input);
|
|
2466
|
+
|
|
2467
|
+
input.value = 'typed';
|
|
2468
|
+
input.setSelectionRange(1, 4, 'backward');
|
|
2469
|
+
input.dispatch('input');
|
|
2470
|
+
expect(owner.stored).toBe('typed');
|
|
2471
|
+
expect(field.text).toBe('typed');
|
|
2472
|
+
expect(selection.getCaretIndex()).toBe(1);
|
|
2473
|
+
selection.setSelection(0, 2);
|
|
2474
|
+
expect([input.selectionStart, input.selectionEnd]).toEqual([0, 2]);
|
|
2475
|
+
|
|
2476
|
+
field.restrict = '^0-9';
|
|
2477
|
+
field.maxChars = 7;
|
|
2478
|
+
const composed = [];
|
|
2479
|
+
field.onChanged = model => composed.push(['field', model.text]);
|
|
2480
|
+
field.addListener({ onChanged: model => composed.push(['listener', model.text]) });
|
|
2481
|
+
input.setSelectionRange(5, 5);
|
|
2482
|
+
input.dispatch('compositionstart');
|
|
2483
|
+
input.value = 'typed9あ';
|
|
2484
|
+
input.setSelectionRange(7, 7);
|
|
2485
|
+
input.dispatch('input', { inputType: 'insertCompositionText', isComposing: true });
|
|
2486
|
+
expect(field.text).toBe('typed');
|
|
2487
|
+
expect(owner.stored).toBe('typed');
|
|
2488
|
+
input.value = 'typed9あé';
|
|
2489
|
+
input.setSelectionRange(8, 8);
|
|
2490
|
+
input.dispatch('compositionend', { data: '9あé' });
|
|
2491
|
+
input.dispatch('input', { inputType: 'insertFromComposition' });
|
|
2492
|
+
expect(input.value).toBe('typedあé');
|
|
2493
|
+
expect(owner.stored).toBe('typedあé');
|
|
2494
|
+
expect(composed).toEqual([['field', 'typedあé'], ['listener', 'typedあé']]);
|
|
2495
|
+
|
|
2496
|
+
const replacement = owner.createTextField('other', 3, 0, 0, 80, 24);
|
|
2497
|
+
timeline.render();
|
|
2498
|
+
expect(field.parent).toBeNull();
|
|
2499
|
+
expect(document.activeElement).toBeNull();
|
|
2500
|
+
expect(controls()).toHaveLength(0);
|
|
2501
|
+
expect(selection.getFocus()).toBeNull();
|
|
2502
|
+
expect(owner.other).toBe(replacement);
|
|
2503
|
+
replacement.removeTextField();
|
|
2504
|
+
expect(replacement.parent).toBeNull();
|
|
2505
|
+
});
|
|
2506
|
+
});
|