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,656 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { runInNewContext } from 'node:vm';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { SymbolTable } from '../decoder/symbol-table.js';
|
|
5
|
+
import { decodeTag } from '../decoder/tag-decoder.js';
|
|
6
|
+
import { TAG } from '../decoder/tag-types.js';
|
|
7
|
+
import { parse } from '../parser/swf-parser.js';
|
|
8
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
9
|
+
import { AVM1_RUNTIME_BOOTSTRAP, AVM1_RUNTIME_FACTORY_SOURCE } from '../runtime/avm1-runtime.js';
|
|
10
|
+
import { buildDisplayList } from '../transpiler/timeline/display-list.js';
|
|
11
|
+
import { generateTimelineEngine, timelineEngineFactorySource, timelineHelpersSource } from '../transpiler/timeline/timeline-codegen.js';
|
|
12
|
+
|
|
13
|
+
function recordCanvases() {
|
|
14
|
+
const fills = [];
|
|
15
|
+
const strokes = [];
|
|
16
|
+
const blits = [];
|
|
17
|
+
const croppedBlits = [];
|
|
18
|
+
const filteredPixels = [];
|
|
19
|
+
class Path2D {
|
|
20
|
+
moveTo() {}
|
|
21
|
+
lineTo() {}
|
|
22
|
+
closePath() {}
|
|
23
|
+
}
|
|
24
|
+
class Canvas {
|
|
25
|
+
constructor(width, height) {
|
|
26
|
+
this.width = width;
|
|
27
|
+
this.height = height;
|
|
28
|
+
const stack = [];
|
|
29
|
+
let transform = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 };
|
|
30
|
+
this.ctx = {
|
|
31
|
+
canvas: this,
|
|
32
|
+
globalAlpha: 1,
|
|
33
|
+
globalCompositeOperation: 'source-over',
|
|
34
|
+
getTransform: () => transform,
|
|
35
|
+
setTransform(a, b, c, d, e, f) { transform = { a, b, c, d, e, f }; },
|
|
36
|
+
transform(a, b, c, d, e, f) {
|
|
37
|
+
const prev = transform;
|
|
38
|
+
this.setTransform(
|
|
39
|
+
prev.a * a + prev.c * b, prev.b * a + prev.d * b,
|
|
40
|
+
prev.a * c + prev.c * d, prev.b * c + prev.d * d,
|
|
41
|
+
prev.a * e + prev.c * f + prev.e, prev.b * e + prev.d * f + prev.f,
|
|
42
|
+
);
|
|
43
|
+
},
|
|
44
|
+
translate(x, y) {
|
|
45
|
+
this.transform(1, 0, 0, 1, x, y);
|
|
46
|
+
},
|
|
47
|
+
save() { stack.push([transform, this.globalAlpha, this.globalCompositeOperation]); },
|
|
48
|
+
restore() { [transform, this.globalAlpha, this.globalCompositeOperation] = stack.pop(); },
|
|
49
|
+
fill() { fills.push([transform.e, this.globalAlpha, this.fillStyle]); },
|
|
50
|
+
stroke() { strokes.push(transform.e); },
|
|
51
|
+
beginPath() {}, rect() {}, clip() {},
|
|
52
|
+
drawImage(source, ...area) {
|
|
53
|
+
blits.push([this.globalCompositeOperation, transform.e]);
|
|
54
|
+
if (area.length === 8) croppedBlits.push([this.globalCompositeOperation, ...area]);
|
|
55
|
+
},
|
|
56
|
+
getImageData() { return { data: new Uint8ClampedArray([0, 0, 0, 0, 10, 20, 30, 100]) }; },
|
|
57
|
+
putImageData(image) { filteredPixels.push([...image.data]); },
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
getContext() { return this.ctx; }
|
|
61
|
+
}
|
|
62
|
+
return { fills, strokes, blits, croppedBlits, filteredPixels, Path2D, Canvas };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
describe('programmatic display masks', () => {
|
|
66
|
+
it('renders nested masks in destination space and hides the stencil itself', () => {
|
|
67
|
+
const { fills, strokes, blits, filteredPixels, Path2D, Canvas } = recordCanvases();
|
|
68
|
+
const runtime = runInNewContext(`${SWFLIB_SOURCE}\n__swoof_swflib;`, { Path2D, OffscreenCanvas: Canvas });
|
|
69
|
+
const { Shape, Sprite, ColorTransform } = runtime.builtins;
|
|
70
|
+
const root = new Sprite();
|
|
71
|
+
root.x = 50;
|
|
72
|
+
const filteredParent = root.addChild(new Sprite());
|
|
73
|
+
filteredParent.x = 10;
|
|
74
|
+
filteredParent.transform.colorTransform = new ColorTransform(1, 1, 1, 1, 0, 0, 0, 20);
|
|
75
|
+
const target = filteredParent.addChild(new Shape());
|
|
76
|
+
target.x = -40;
|
|
77
|
+
target.graphics.beginFill(0x123456);
|
|
78
|
+
target.graphics.drawRect(0, 0, 10, 10);
|
|
79
|
+
const stencilParent = root.addChild(new Sprite());
|
|
80
|
+
stencilParent.x = -32;
|
|
81
|
+
const stencil = stencilParent.addChild(new Shape());
|
|
82
|
+
stencil.x = 4;
|
|
83
|
+
stencil.alpha = 0;
|
|
84
|
+
stencil.graphics.lineStyle(8, 0xff0000);
|
|
85
|
+
stencil.graphics.beginFill(0xabcdef);
|
|
86
|
+
stencil.graphics.drawRect(0, 0, 10, 10);
|
|
87
|
+
target.mask = stencil;
|
|
88
|
+
|
|
89
|
+
const ctx = new Canvas(100, 100).getContext('2d');
|
|
90
|
+
ctx.translate(3, 0);
|
|
91
|
+
runtime.renderDisplayTree(ctx, root, 0);
|
|
92
|
+
|
|
93
|
+
expect(fills).toEqual([[23, 1, expect.any(String)], [25, 1, '#fff']]);
|
|
94
|
+
expect(strokes).toEqual([]);
|
|
95
|
+
expect(blits).toEqual([['destination-in', 0], ['source-over', 0], ['source-over', 0]]);
|
|
96
|
+
expect(filteredPixels).toEqual([[0, 0, 0, 0, 10, 20, 30, 120]]);
|
|
97
|
+
expect(ctx.getTransform().e).toBe(3);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('transfers and clears mask ownership', () => {
|
|
101
|
+
const { Shape } = runInNewContext(`${SWFLIB_SOURCE}\n__swoof_swflib.builtins;`);
|
|
102
|
+
const first = new Shape();
|
|
103
|
+
const second = new Shape();
|
|
104
|
+
const stencil = new Shape();
|
|
105
|
+
first.mask = stencil;
|
|
106
|
+
second.mask = stencil;
|
|
107
|
+
expect(first.mask).toBeNull();
|
|
108
|
+
expect(second.mask).toBe(stencil);
|
|
109
|
+
second.mask = null;
|
|
110
|
+
first.mask = stencil;
|
|
111
|
+
expect(second.mask).toBeNull();
|
|
112
|
+
expect(first.mask).toBe(stencil);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe('authored timeline masks', () => {
|
|
117
|
+
it('preserves the original Blocks mask placement through removal, reattachment and explicit unset', async () => {
|
|
118
|
+
const { doc, diagnostics } = await parse(readFileSync('archive/Swf/blocks.swf'));
|
|
119
|
+
const symbolTable = new SymbolTable();
|
|
120
|
+
for (const [id, tagCode] of [[67, TAG.DefineSprite], [50, TAG.DefineSprite], [49, TAG.DefineShape]]) {
|
|
121
|
+
const tag = doc.tags.find(entry => entry.code === tagCode && (entry.data[0] | (entry.data[1] << 8)) === id);
|
|
122
|
+
symbolTable.set(id, decodeTag(tag, doc, diagnostics));
|
|
123
|
+
}
|
|
124
|
+
const { characters } = buildDisplayList([], symbolTable, diagnostics, { swfVersion: doc.header.version });
|
|
125
|
+
const engine = generateTimelineEngine({
|
|
126
|
+
characters, frames: [{ places: [{ depth: 1, characterId: 67, name: 'preloader',
|
|
127
|
+
matrix: { a: 1, b: 0, c: 0, d: 1, tx: 6400, ty: 4800 } }] }],
|
|
128
|
+
}, { frameCount: 1, stageW: 640, stageH: 480 });
|
|
129
|
+
class StencilPath {
|
|
130
|
+
points = [];
|
|
131
|
+
moveTo(x, y) { this.points.push([x, y]); }
|
|
132
|
+
lineTo(x, y) { this.points.push([x, y]); }
|
|
133
|
+
closePath() {}
|
|
134
|
+
}
|
|
135
|
+
const sandbox = { Path2D: StencilPath, loaded: {}, requestAnimationFrame: () => 1 };
|
|
136
|
+
sandbox.window = sandbox;
|
|
137
|
+
const { runtime, preloader, mask } = runInNewContext(`
|
|
138
|
+
${SWFLIB_SOURCE}
|
|
139
|
+
${engine}
|
|
140
|
+
var runtime = __swoof_swflib;
|
|
141
|
+
var main = runtime.stage.addChild(new MovieClip());
|
|
142
|
+
main._swoofHostTimeline = true;
|
|
143
|
+
window.__swoof = { main, timeline };
|
|
144
|
+
timeline.enter();
|
|
145
|
+
var preloader = main.preloader;
|
|
146
|
+
var mask = preloader.maska;
|
|
147
|
+
preloader.mask = mask;
|
|
148
|
+
mask.x = -320;
|
|
149
|
+
mask.y = -240;
|
|
150
|
+
({ runtime, preloader, mask });
|
|
151
|
+
`, sandbox);
|
|
152
|
+
const { Canvas } = recordCanvases();
|
|
153
|
+
const ctx = new Canvas(860, 740).getContext('2d');
|
|
154
|
+
const paint = [];
|
|
155
|
+
ctx.fill = function (path) {
|
|
156
|
+
const { a, b, c, d, e, f } = this.getTransform();
|
|
157
|
+
const xs = path.points.map(([x, y]) => a * x + c * y + e);
|
|
158
|
+
const ys = path.points.map(([x, y]) => b * x + d * y + f);
|
|
159
|
+
paint.push([Math.min(...xs), Math.min(...ys), Math.max(...xs), Math.max(...ys)].map(Math.round));
|
|
160
|
+
};
|
|
161
|
+
function expectStencil(bounds, hits) {
|
|
162
|
+
paint.length = 0;
|
|
163
|
+
expect(preloader.mask).toBe(mask);
|
|
164
|
+
runtime.paintStageMask(ctx, mask);
|
|
165
|
+
expect(paint).toEqual([bounds]);
|
|
166
|
+
const points = [[50, 50], [320, 360], [650, 450]];
|
|
167
|
+
expect(points.map(([x, y]) => runtime.pointerPassesDisplayMasks(preloader, x, y))).toEqual(hits);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
preloader.gotoAndStop(141);
|
|
171
|
+
expect(mask.parent).toBe(preloader);
|
|
172
|
+
expectStencil([0, 0, 640, 480], [true, true, false]);
|
|
173
|
+
preloader.gotoAndStop(142);
|
|
174
|
+
expect(mask.parent).toBeNull();
|
|
175
|
+
expectStencil([0, 0, 640, 480], [true, true, false]);
|
|
176
|
+
|
|
177
|
+
const holder = runtime.stage.addChild(new runtime.builtins.Sprite());
|
|
178
|
+
holder.x = 500;
|
|
179
|
+
holder.y = 480;
|
|
180
|
+
holder.addChild(mask);
|
|
181
|
+
expectStencil([180, 240, 820, 720], [false, true, true]);
|
|
182
|
+
holder.removeChild(mask);
|
|
183
|
+
expect(mask.parent).toBeNull();
|
|
184
|
+
expectStencil([180, 240, 820, 720], [false, true, true]);
|
|
185
|
+
|
|
186
|
+
preloader.mask = null;
|
|
187
|
+
expect(preloader.mask).toBeNull();
|
|
188
|
+
expect(runtime.pointerPassesDisplayMasks(preloader, 50, 50)).toBe(true);
|
|
189
|
+
preloader.mask = mask;
|
|
190
|
+
expectStencil([-320, -240, 320, 240], [true, false, false]);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('recycles older assigned stencils while compositing every mask in order', () => {
|
|
194
|
+
const { Canvas } = recordCanvases();
|
|
195
|
+
const ctx = new Canvas(80, 50).getContext('2d');
|
|
196
|
+
const stencils = Array.from({ length: 12 }, (_, id) => ({ displayObject: { id } }));
|
|
197
|
+
const masks = stencils.flatMap(stencil => [stencil, stencil]).concat(stencils[0]);
|
|
198
|
+
const painted = [];
|
|
199
|
+
const composited = [];
|
|
200
|
+
let allocations = 0;
|
|
201
|
+
ctx.drawImage = function (source) {
|
|
202
|
+
composited.push([source.stencilId, this.globalCompositeOperation]);
|
|
203
|
+
};
|
|
204
|
+
const document = {
|
|
205
|
+
createElement() {
|
|
206
|
+
allocations++;
|
|
207
|
+
return new Canvas(80, 50);
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
const runtime = {
|
|
211
|
+
paintStageMask(context, mask) {
|
|
212
|
+
painted.push(mask.id);
|
|
213
|
+
context.canvas.stencilId = mask.id;
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
const engine = generateTimelineEngine({}, { stageW: 80, stageH: 50, frameCount: 1 });
|
|
217
|
+
const composite = new Function('document', '__swoof_swflib', `
|
|
218
|
+
var STAGE_WIDTH = 80, STAGE_HEIGHT = 50;
|
|
219
|
+
${engine}
|
|
220
|
+
stencilSurfaces = new Map();
|
|
221
|
+
return compositeTimelineMasks;
|
|
222
|
+
`)(document, runtime);
|
|
223
|
+
|
|
224
|
+
composite(ctx, masks, 0);
|
|
225
|
+
|
|
226
|
+
expect(allocations).toBeLessThanOrEqual(5);
|
|
227
|
+
expect(painted).toEqual([...stencils.map(stencil => stencil.displayObject.id), 0]);
|
|
228
|
+
expect(composited).toEqual(masks.map(stencil => [stencil.displayObject.id, 'destination-in']));
|
|
229
|
+
expect(ctx.globalCompositeOperation).toBe('source-over');
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('paints root and nested AS3 placement matrices through timeline moves and script edits', () => {
|
|
233
|
+
const { Path2D, Canvas } = recordCanvases();
|
|
234
|
+
const ctx = new Canvas(100, 80).getContext('2d');
|
|
235
|
+
ctx.fillRect = ctx.clearRect = () => {};
|
|
236
|
+
const paints = [];
|
|
237
|
+
ctx.fill = () => paints.push(ctx.getTransform());
|
|
238
|
+
const placeAt = x => ({ a: 1, b: 0, c: 1, d: 1, tx: x * 20, ty: 0 });
|
|
239
|
+
const engine = generateTimelineEngine({
|
|
240
|
+
frames: [
|
|
241
|
+
{ frameIndex: 0, places: [{ characterId: 1, depth: 1, name: 'holder', matrix: placeAt(10) }] },
|
|
242
|
+
{ frameIndex: 1, places: [{ move: true, depth: 1, matrix: placeAt(20) }] },
|
|
243
|
+
{ frameIndex: 2, places: [{ move: true, depth: 1, matrix: placeAt(30) }] },
|
|
244
|
+
],
|
|
245
|
+
characters: {
|
|
246
|
+
1: { type: 'sprite', frames: [{ places: [{ characterId: 2, depth: 1, name: 'art', matrix: placeAt(4) }] }] },
|
|
247
|
+
2: { type: 'shape', bounds: { x: 0, y: 0, w: 10, h: 10 },
|
|
248
|
+
draws: [{ path: [['M', 0, 0], ['L', 10, 0], ['L', 0, 10], ['Z']],
|
|
249
|
+
fill: { type: 'solid', color: '#f00' } }] },
|
|
250
|
+
},
|
|
251
|
+
}, { stageW: 100, stageH: 80, frameCount: 3 });
|
|
252
|
+
const sandbox = {
|
|
253
|
+
ctx, Path2D, loaded: {}, STAGE_WIDTH: 100, STAGE_HEIGHT: 80, FRAME_RATE: 30, BACKGROUND: '#000',
|
|
254
|
+
document: { getElementById: () => null, createElement: () => null }, requestAnimationFrame: () => 1,
|
|
255
|
+
};
|
|
256
|
+
sandbox.window = sandbox;
|
|
257
|
+
const { main, timeline } = runInNewContext(`
|
|
258
|
+
${SWFLIB_SOURCE}
|
|
259
|
+
${engine}
|
|
260
|
+
var main = __swoof_swflib.stage.addChild(new __swoof_swflib.builtins.MovieClip());
|
|
261
|
+
main._swoofHostTimeline = true;
|
|
262
|
+
window.__swoof = { main };
|
|
263
|
+
timeline.enter();
|
|
264
|
+
({ main, timeline });
|
|
265
|
+
`, sandbox);
|
|
266
|
+
|
|
267
|
+
timeline.render();
|
|
268
|
+
expect(paints.at(-1)).toEqual({ a: 1, b: 0, c: 2, d: 1, e: 14, f: 0 });
|
|
269
|
+
expect(main.holder.transform.pixelBounds).toMatchObject({ x: 14, y: 0, width: 30, height: 10 });
|
|
270
|
+
timeline.gotoAndStop(2);
|
|
271
|
+
expect(main.holder.x).toBe(20);
|
|
272
|
+
expect(paints.at(-1)).toEqual({ a: 1, b: 0, c: 2, d: 1, e: 24, f: 0 });
|
|
273
|
+
|
|
274
|
+
main.holder.x = 40;
|
|
275
|
+
main.holder.art.scaleX = 2;
|
|
276
|
+
timeline.gotoAndStop(3);
|
|
277
|
+
expect(main.holder.x).toBe(40);
|
|
278
|
+
expect(paints.at(-1)).toEqual({ a: 2, b: 0, c: 2, d: 1, e: 44, f: 0 });
|
|
279
|
+
expect(main.holder.art.transform.pixelBounds).toMatchObject({ x: 44, y: 0, width: 40, height: 10 });
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it('paints an assigned authored stencil from another branch and shares its fill geometry with pointer hits', () => {
|
|
283
|
+
const { fills, strokes, blits, Path2D, Canvas } = recordCanvases();
|
|
284
|
+
const canvas = new Canvas(80, 50);
|
|
285
|
+
const ctx = canvas.getContext('2d');
|
|
286
|
+
ctx.fillRect = ctx.clearRect = () => {};
|
|
287
|
+
const translate = (x, y) => ({ a: 1, b: 0, c: 0, d: 1, tx: x * 20, ty: y * 20 });
|
|
288
|
+
const path = [['M', 0, 0], ['L', 10, 0], ['L', 0, 10], ['Z']];
|
|
289
|
+
const engine = generateTimelineEngine({
|
|
290
|
+
frames: [{ places: [
|
|
291
|
+
{ characterId: 1, depth: 1, name: 'target', matrix: translate(10, 4) },
|
|
292
|
+
{ characterId: 2, depth: 2, name: 'holder', matrix: translate(7, 3) },
|
|
293
|
+
] }],
|
|
294
|
+
characters: {
|
|
295
|
+
1: { type: 'sprite', frames: [{ places: [{ characterId: 4, depth: 1 }] }] },
|
|
296
|
+
2: { type: 'sprite', frames: [{ places: [{ characterId: 3, depth: 1, name: 'stencil', matrix: translate(4, 5) }] }] },
|
|
297
|
+
3: { type: 'sprite', frames: [{ places: [{ characterId: 5, depth: 1, matrix: translate(2, 0) }] }] },
|
|
298
|
+
4: { type: 'shape', draws: [{ path, fill: { type: 'solid', color: '#f00' } }] },
|
|
299
|
+
5: { type: 'shape', draws: [{ path, fill: { type: 'solid', color: '#0f0' }, stroke: { width: 4, color: '#f0f' } }] },
|
|
300
|
+
},
|
|
301
|
+
}, { stageW: 80, stageH: 50, frameCount: 1 });
|
|
302
|
+
const sandbox = {
|
|
303
|
+
ctx, Path2D, loaded: [], STAGE_WIDTH: 80, STAGE_HEIGHT: 50, FRAME_RATE: 30, BACKGROUND: '#000',
|
|
304
|
+
document: {
|
|
305
|
+
getElementById: () => null,
|
|
306
|
+
createElement() {
|
|
307
|
+
const scratch = new Canvas(80, 50);
|
|
308
|
+
scratch.ctx.fillRect = scratch.ctx.clearRect = () => {};
|
|
309
|
+
return scratch;
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
requestAnimationFrame: () => 1,
|
|
313
|
+
};
|
|
314
|
+
sandbox.window = sandbox;
|
|
315
|
+
const { runtime, main, timeline } = runInNewContext(`
|
|
316
|
+
${SWFLIB_SOURCE}
|
|
317
|
+
${engine}
|
|
318
|
+
var runtime = __swoof_swflib;
|
|
319
|
+
var main = runtime.stage.addChild(new runtime.builtins.MovieClip());
|
|
320
|
+
main._swoofHostTimeline = true;
|
|
321
|
+
window.__swoof = { main };
|
|
322
|
+
timeline.enter();
|
|
323
|
+
({ runtime, main, timeline });
|
|
324
|
+
`, sandbox);
|
|
325
|
+
|
|
326
|
+
fills.length = strokes.length = blits.length = 0;
|
|
327
|
+
main.target.mask = main.holder.stencil;
|
|
328
|
+
timeline.render();
|
|
329
|
+
expect(fills).toEqual([[10, 1, '#f00'], [13, 1, '#fff']]);
|
|
330
|
+
expect(strokes).toEqual([]);
|
|
331
|
+
expect(blits.filter(([op]) => op === 'destination-in')).toHaveLength(1);
|
|
332
|
+
expect(runtime.pointerPassesDisplayMasks(main.target, 14, 9)).toBe(true);
|
|
333
|
+
expect(runtime.pointerPassesDisplayMasks(main.target, 20, 15)).toBe(false);
|
|
334
|
+
expect(runtime.pointerPassesDisplayMasks(main.holder.stencil, 14, 9)).toBe(false);
|
|
335
|
+
|
|
336
|
+
fills.length = strokes.length = blits.length = 0;
|
|
337
|
+
main.holder.stencil.x = 6;
|
|
338
|
+
timeline.render();
|
|
339
|
+
expect(fills).toEqual([[10, 1, '#f00'], [15, 1, '#fff']]);
|
|
340
|
+
expect(runtime.pointerPassesDisplayMasks(main.target, 14, 9)).toBe(false);
|
|
341
|
+
|
|
342
|
+
fills.length = strokes.length = blits.length = 0;
|
|
343
|
+
main.target.mask = null;
|
|
344
|
+
timeline.render();
|
|
345
|
+
expect(fills.map(([, , color]) => color)).toEqual(['#f00', '#0f0']);
|
|
346
|
+
expect(strokes).toHaveLength(1);
|
|
347
|
+
expect(blits.some(([op]) => op === 'destination-in')).toBe(false);
|
|
348
|
+
|
|
349
|
+
fills.length = strokes.length = blits.length = 0;
|
|
350
|
+
const nativeStencil = main.holder.addChild(new runtime.builtins.Shape());
|
|
351
|
+
nativeStencil.x = 3;
|
|
352
|
+
nativeStencil.graphics.beginFill(0x0000ff);
|
|
353
|
+
nativeStencil.graphics.drawRect(0, 0, 5, 5);
|
|
354
|
+
main.holder.stencil.visible = false;
|
|
355
|
+
main.target.mask = nativeStencil;
|
|
356
|
+
timeline.render();
|
|
357
|
+
expect(fills).toEqual([[10, 1, '#f00'], [10, 1, '#fff']]);
|
|
358
|
+
expect(strokes).toEqual([]);
|
|
359
|
+
expect(blits.filter(([op]) => op === 'destination-in')).toHaveLength(1);
|
|
360
|
+
|
|
361
|
+
fills.length = strokes.length = blits.length = 0;
|
|
362
|
+
main.target.mask = null;
|
|
363
|
+
main.holder.stencil.visible = true;
|
|
364
|
+
nativeStencil.mask = main.holder.stencil;
|
|
365
|
+
timeline.render();
|
|
366
|
+
expect(fills.map(([x, , color]) => [x, color])).toEqual([[10, '#f00'], [10, '#0000ff'], [15, '#fff']]);
|
|
367
|
+
expect(strokes).toEqual([]);
|
|
368
|
+
expect(blits.filter(([op]) => op === 'destination-in')).toHaveLength(1);
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it('shares an AVM1 root transform between static paint, timeline masks, pointer hits and dragging', () => {
|
|
372
|
+
const { fills, Path2D, Canvas } = recordCanvases();
|
|
373
|
+
const handlers = {};
|
|
374
|
+
const stage = new Canvas(180, 100);
|
|
375
|
+
stage.getBoundingClientRect = () => ({ left: 0, top: 0, width: 180, height: 100 });
|
|
376
|
+
stage.style = {};
|
|
377
|
+
stage.focus = () => {};
|
|
378
|
+
stage.addEventListener = (type, handler) => { (handlers[type] ||= []).push(handler); };
|
|
379
|
+
const canvas = () => {
|
|
380
|
+
const canvas = new Canvas(180, 100);
|
|
381
|
+
canvas.ctx.fillRect = canvas.ctx.clearRect = () => {};
|
|
382
|
+
return canvas;
|
|
383
|
+
};
|
|
384
|
+
const shape = (color, size) => ({ type: 'shape', bounds: { x: 0, y: 0, w: size, h: size },
|
|
385
|
+
draws: [{ fill: { type: 'solid', color },
|
|
386
|
+
path: [['M', 0, 0], ['L', size, 0], ['L', 0, size], ['Z']] }] });
|
|
387
|
+
const place = (depth, characterId, x, y, props) => ({
|
|
388
|
+
depth, characterId, matrix: { a: 1, b: 0, c: 0, d: 1, tx: x * 20, ty: y * 20 }, ...props,
|
|
389
|
+
});
|
|
390
|
+
const engine = generateTimelineEngine({
|
|
391
|
+
frames: [{ places: [
|
|
392
|
+
place(1, 1, 8, 4, { name: 'stencil', clipDepth: 2 }),
|
|
393
|
+
place(2, 4, 7, 4, { name: 'target' }),
|
|
394
|
+
place(3, 3, 60, 14),
|
|
395
|
+
] }],
|
|
396
|
+
characters: {
|
|
397
|
+
1: shape('#00ff00', 5), 2: shape('#ff0000', 10), 3: shape('#aabbcc', 10),
|
|
398
|
+
4: { type: 'sprite', frames: [{ places: [{ depth: 1, characterId: 2 }] }] },
|
|
399
|
+
},
|
|
400
|
+
}, { stageW: 180, stageH: 100, frameCount: 1, sharedFactory: true });
|
|
401
|
+
const context = {
|
|
402
|
+
ctx: stage.getContext('2d'), Path2D, loaded: {}, ASSETS: [], SYMBOL_CLASSES: [], EXPORT_ASSETS: [],
|
|
403
|
+
STAGE_WIDTH: 180, STAGE_HEIGHT: 100, FRAME_RATE: 30, BACKGROUND: '#000', PointerEvent: class {},
|
|
404
|
+
document: { readyState: 'complete', getElementById: id => id === 'stage' ? stage : null, createElement: canvas },
|
|
405
|
+
requestAnimationFrame: () => 1,
|
|
406
|
+
};
|
|
407
|
+
context.ctx.fillRect = context.ctx.clearRect = () => {};
|
|
408
|
+
context.window = context;
|
|
409
|
+
const { root, timeline } = runInNewContext(`
|
|
410
|
+
${SWFLIB_SOURCE}
|
|
411
|
+
__swoof_swflib.timelineHelpers = ${timelineHelpersSource()};
|
|
412
|
+
__swoof_swflib.createTimelineEngine = ${timelineEngineFactorySource()};
|
|
413
|
+
__swoof_swflib.createAvm1Runtime = ${AVM1_RUNTIME_FACTORY_SOURCE};
|
|
414
|
+
var __swoof_root = {};
|
|
415
|
+
${engine}
|
|
416
|
+
${AVM1_RUNTIME_BOOTSTRAP}
|
|
417
|
+
window.__swoof = { root };
|
|
418
|
+
timeline.enter();
|
|
419
|
+
({ root, timeline });
|
|
420
|
+
`, context);
|
|
421
|
+
root._x = 30;
|
|
422
|
+
root._y = 15;
|
|
423
|
+
root._xscale = 150;
|
|
424
|
+
root._yscale = 200;
|
|
425
|
+
let presses = 0;
|
|
426
|
+
root.target.onPress = () => presses++;
|
|
427
|
+
fills.length = 0;
|
|
428
|
+
timeline.render();
|
|
429
|
+
expect(fills).toContainEqual([40.5, 1, '#ff0000']);
|
|
430
|
+
expect(fills).toContainEqual([42, 1, '#fff']);
|
|
431
|
+
expect(fills).toContainEqual([120, 1, '#aabbcc']);
|
|
432
|
+
|
|
433
|
+
expect(root.target.localToGlobal({ x: 2, y: 2 })).toEqual({ x: 43.5, y: 27 });
|
|
434
|
+
expect(root.target.globalToLocal({ x: 43.5, y: 27 })).toEqual({ x: 2, y: 2 });
|
|
435
|
+
expect(root.target.hitTest(9, 6, true)).toBe(true);
|
|
436
|
+
const click = (x, y) => {
|
|
437
|
+
for (const type of ['pointerdown', 'pointerup']) {
|
|
438
|
+
const event = { clientX: x, clientY: y, button: 0, pointerId: 1, isPrimary: true,
|
|
439
|
+
buttons: type === 'pointerdown' ? 1 : 0, preventDefault() {} };
|
|
440
|
+
for (const handler of handlers[type] || []) handler(event);
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
click(48, 31); // Inside the target fill, outside the stencil.
|
|
444
|
+
expect(presses).toBe(0);
|
|
445
|
+
click(43.5, 27);
|
|
446
|
+
expect(presses).toBe(1);
|
|
447
|
+
expect([root._xmouse, root._ymouse]).toEqual([9, 6]);
|
|
448
|
+
|
|
449
|
+
root.target.startDrag(true);
|
|
450
|
+
expect([root.target._x, root.target._y]).toEqual([9, 6]);
|
|
451
|
+
root.target.stopDrag();
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
it('clips an AVM1 authored target and its dynamic descendants to a moving script stencil', () => {
|
|
455
|
+
const { fills, strokes, blits, croppedBlits, Path2D, Canvas } = recordCanvases();
|
|
456
|
+
const handlers = {};
|
|
457
|
+
const stage = new Canvas(80, 50);
|
|
458
|
+
stage.getBoundingClientRect = () => ({ left: 0, top: 0, width: 80, height: 50 });
|
|
459
|
+
stage.style = {};
|
|
460
|
+
stage.focus = () => {};
|
|
461
|
+
stage.addEventListener = (type, handler) => { (handlers[type] ||= []).push(handler); };
|
|
462
|
+
const ctx = stage.getContext('2d');
|
|
463
|
+
ctx.fillRect = ctx.clearRect = () => {};
|
|
464
|
+
const engine = generateTimelineEngine({
|
|
465
|
+
frames: [
|
|
466
|
+
{ frameIndex: 0, places: [{ characterId: 1, depth: 1, name: 'target' }] },
|
|
467
|
+
{ frameIndex: 1, removes: [1], places: [
|
|
468
|
+
{ characterId: 3, depth: 1, name: 'timelineStencil', clipDepth: 2 },
|
|
469
|
+
{ characterId: 1, depth: 2, name: 'behind' },
|
|
470
|
+
] },
|
|
471
|
+
],
|
|
472
|
+
characters: {
|
|
473
|
+
1: { type: 'sprite', frames: [{ places: [{ characterId: 2, depth: 1 }] }] },
|
|
474
|
+
2: { type: 'shape', draws: [{ fill: { type: 'solid', color: '#f00' },
|
|
475
|
+
path: [['M', 0, 0], ['L', 40, 0], ['L', 40, 40], ['L', 0, 40], ['Z']] }] },
|
|
476
|
+
3: { type: 'sprite', frames: [{ places: [{ characterId: 4, depth: 1 }] }] },
|
|
477
|
+
4: { type: 'shape', draws: [{ fill: { type: 'solid', color: '#0f0' },
|
|
478
|
+
path: [['M', 0, 0], ['L', 10, 0], ['L', 0, 10], ['Z']] }] },
|
|
479
|
+
},
|
|
480
|
+
}, { stageW: 80, stageH: 50, frameCount: 2, sharedFactory: true });
|
|
481
|
+
const sandbox = {
|
|
482
|
+
ctx, Path2D, loaded: {}, ASSETS: [], SYMBOL_CLASSES: [], EXPORT_ASSETS: [],
|
|
483
|
+
STAGE_WIDTH: 80, STAGE_HEIGHT: 50, FRAME_RATE: 30, BACKGROUND: '#000',
|
|
484
|
+
document: {
|
|
485
|
+
readyState: 'complete',
|
|
486
|
+
getElementById: id => id === 'stage' ? stage : null,
|
|
487
|
+
createElement() {
|
|
488
|
+
const scratch = new Canvas(80, 50);
|
|
489
|
+
scratch.ctx.fillRect = scratch.ctx.clearRect = () => {};
|
|
490
|
+
return scratch;
|
|
491
|
+
},
|
|
492
|
+
},
|
|
493
|
+
requestAnimationFrame: () => 1,
|
|
494
|
+
};
|
|
495
|
+
sandbox.window = sandbox;
|
|
496
|
+
const { root, timeline, stencil, dynamic, clicks } = runInNewContext(`
|
|
497
|
+
${SWFLIB_SOURCE}
|
|
498
|
+
__swoof_swflib.timelineHelpers = ${timelineHelpersSource()};
|
|
499
|
+
__swoof_swflib.createTimelineEngine = ${timelineEngineFactorySource()};
|
|
500
|
+
__swoof_swflib.createAvm1Runtime = ${AVM1_RUNTIME_FACTORY_SOURCE};
|
|
501
|
+
var __swoof_root = {};
|
|
502
|
+
${engine}
|
|
503
|
+
${AVM1_RUNTIME_BOOTSTRAP}
|
|
504
|
+
window.__swoof = { root };
|
|
505
|
+
timeline.enter();
|
|
506
|
+
var clicks = [];
|
|
507
|
+
root.target.onPress = function () { clicks.push('target'); };
|
|
508
|
+
var dynamic = root.target.createEmptyMovieClip('dynamic', 2);
|
|
509
|
+
dynamic.x = 4;
|
|
510
|
+
dynamic.beginFill(0x0000ff);
|
|
511
|
+
dynamic.drawRect(0, 0, 40, 40);
|
|
512
|
+
var holder = root.createEmptyMovieClip('holder', 5);
|
|
513
|
+
holder.x = 11;
|
|
514
|
+
holder.scaleX = 200;
|
|
515
|
+
var stencil = holder.createEmptyMovieClip('stencil', 1);
|
|
516
|
+
stencil.x = 3;
|
|
517
|
+
stencil.y = 10;
|
|
518
|
+
stencil._visible = false;
|
|
519
|
+
stencil.alpha = 0;
|
|
520
|
+
stencil.lineStyle(8, 0x00ff00);
|
|
521
|
+
stencil.beginFill(0x00ff00);
|
|
522
|
+
stencil.moveTo(0, 0);
|
|
523
|
+
stencil.lineTo(10, 0);
|
|
524
|
+
stencil.lineTo(0, 10);
|
|
525
|
+
stencil.endFill();
|
|
526
|
+
var hiddenChild = stencil.createEmptyMovieClip('hiddenChild', 2);
|
|
527
|
+
hiddenChild.x = 9;
|
|
528
|
+
hiddenChild._visible = false;
|
|
529
|
+
hiddenChild.beginFill(0xffff00);
|
|
530
|
+
hiddenChild.drawRect(0, 0, 2, 8);
|
|
531
|
+
hiddenChild.endFill();
|
|
532
|
+
root.target.setMask('/holder/stencil');
|
|
533
|
+
({ root, timeline, stencil, dynamic, clicks });
|
|
534
|
+
`, sandbox);
|
|
535
|
+
const press = (x, y) => handlers.mousedown.forEach(listener => listener({ clientX: x, clientY: y, button: 0 }));
|
|
536
|
+
const reset = () => { fills.length = strokes.length = blits.length = 0; };
|
|
537
|
+
|
|
538
|
+
reset();
|
|
539
|
+
timeline.render();
|
|
540
|
+
expect(fills).toEqual([[0, 1, '#f00'], [4, 1, 'rgba(0,0,255,1)'], [17, 1, '#fff']]);
|
|
541
|
+
expect(strokes).toEqual([]);
|
|
542
|
+
expect(blits.filter(([op]) => op === 'destination-in')).toHaveLength(1);
|
|
543
|
+
press(19, 13);
|
|
544
|
+
press(29, 17); // Within the stencil bounds and stroke, outside its fill.
|
|
545
|
+
press(36, 13); // Inside the hidden descendant but outside the stencil's own fill.
|
|
546
|
+
expect(clicks).toEqual(['target']);
|
|
547
|
+
|
|
548
|
+
reset();
|
|
549
|
+
stencil.x = 5;
|
|
550
|
+
dynamic.setMask(stencil); // Transfer ownership away from the authored target.
|
|
551
|
+
expect(root.target._swoofMask).toBeUndefined();
|
|
552
|
+
timeline.render();
|
|
553
|
+
expect(fills).toEqual([[0, 1, '#f00'], [4, 1, 'rgba(0,0,255,1)'], [21, 1, '#fff']]);
|
|
554
|
+
expect(blits.filter(([op]) => op === 'destination-in')).toHaveLength(1);
|
|
555
|
+
|
|
556
|
+
reset();
|
|
557
|
+
stencil.removeMovieClip();
|
|
558
|
+
expect(dynamic._swoofMask).toBeUndefined();
|
|
559
|
+
timeline.render();
|
|
560
|
+
expect(fills).toEqual([[0, 1, '#f00'], [4, 1, 'rgba(0,0,255,1)']]);
|
|
561
|
+
expect(blits.some(([op]) => op === 'destination-in')).toBe(false);
|
|
562
|
+
|
|
563
|
+
const authoredStencil = root.attachMovie(3, 'authoredStencil', 9);
|
|
564
|
+
authoredStencil.x = 7;
|
|
565
|
+
authoredStencil._visible = false;
|
|
566
|
+
root.target.setMask(authoredStencil);
|
|
567
|
+
reset();
|
|
568
|
+
timeline.render();
|
|
569
|
+
expect(fills).toEqual([[0, 1, '#f00'], [4, 1, 'rgba(0,0,255,1)'], [7, 1, '#fff']]);
|
|
570
|
+
expect(root.target.hitTest(8, 1, true)).toBe(true);
|
|
571
|
+
expect(root.target.hitTest(16, 7, true)).toBe(false);
|
|
572
|
+
authoredStencil.removeMovieClip();
|
|
573
|
+
|
|
574
|
+
const rectMask = root.createEmptyMovieClip('rectMask', 9);
|
|
575
|
+
rectMask.x = 17.25;
|
|
576
|
+
rectMask.y = 10.5;
|
|
577
|
+
rectMask.beginFill(0xffffff);
|
|
578
|
+
rectMask.drawRect(0, 0, 8, 2);
|
|
579
|
+
rectMask.endFill();
|
|
580
|
+
root.target.setMask(rectMask);
|
|
581
|
+
reset();
|
|
582
|
+
croppedBlits.length = 0;
|
|
583
|
+
timeline.render();
|
|
584
|
+
expect(fills).toEqual([[0, 1, '#f00'], [4, 1, 'rgba(0,0,255,1)'], [17.25, 1, '#fff']]);
|
|
585
|
+
expect(croppedBlits).toEqual([
|
|
586
|
+
['destination-in', 16, 9, 11, 5, 16, 9, 11, 5],
|
|
587
|
+
['source-over', 16, 9, 11, 5, 16, 9, 11, 5],
|
|
588
|
+
]);
|
|
589
|
+
rectMask.removeMovieClip();
|
|
590
|
+
|
|
591
|
+
timeline.gotoAndStop(2);
|
|
592
|
+
reset();
|
|
593
|
+
timeline.render();
|
|
594
|
+
expect(fills).toEqual([[0, 1, '#f00'], [0, 1, '#fff']]);
|
|
595
|
+
expect(blits.filter(([op]) => op === 'destination-in')).toHaveLength(1);
|
|
596
|
+
|
|
597
|
+
reset();
|
|
598
|
+
const replacement = root.createEmptyMovieClip('replacement', 8);
|
|
599
|
+
replacement.beginFill(0xff0000);
|
|
600
|
+
replacement.drawRect(0, 0, 5, 5);
|
|
601
|
+
root.timelineStencil.setMask(replacement);
|
|
602
|
+
timeline.render();
|
|
603
|
+
expect(fills).toEqual([[0, 1, '#0f0'], [0, 1, '#fff'], [0, 1, '#f00']]);
|
|
604
|
+
expect(blits.filter(([op]) => op === 'destination-in')).toHaveLength(1);
|
|
605
|
+
|
|
606
|
+
reset();
|
|
607
|
+
replacement.removeMovieClip();
|
|
608
|
+
timeline.render();
|
|
609
|
+
expect(fills).toEqual([[0, 1, '#0f0'], [0, 1, '#f00']]);
|
|
610
|
+
expect(blits.some(([op]) => op === 'destination-in')).toBe(false);
|
|
611
|
+
});
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
it('paints a programmatically mounted linked MovieClip alongside one tag-placed instance', () => {
|
|
615
|
+
const { fills, Path2D, Canvas } = recordCanvases();
|
|
616
|
+
const ctx = new Canvas(80, 50).getContext('2d');
|
|
617
|
+
ctx.fillRect = ctx.clearRect = ctx.beginPath = ctx.rect = ctx.clip = () => {};
|
|
618
|
+
const path = [['M', 0, 0], ['L', 15, 0], ['L', 0, 15], ['Z']];
|
|
619
|
+
const engine = generateTimelineEngine({
|
|
620
|
+
frames: [{ places: [{ characterId: 1, depth: 1, name: 'authored' }] }],
|
|
621
|
+
characters: {
|
|
622
|
+
1: { type: 'sprite', frames: [{ places: [{ characterId: 2, depth: 1 },
|
|
623
|
+
{ characterId: 3, depth: 2, name: 'field' }] }] },
|
|
624
|
+
2: { type: 'shape', draws: [{ path, fill: { type: 'solid', color: '#f00' } }] },
|
|
625
|
+
3: { type: 'text', kind: 'edit', bounds: { x: 0, y: 0, w: 30, h: 12 },
|
|
626
|
+
editable: false, text: '', font: 'Arial', fontSize: 12 },
|
|
627
|
+
},
|
|
628
|
+
}, { stageW: 80, stageH: 50, frameCount: 1 });
|
|
629
|
+
const sandbox = {
|
|
630
|
+
ctx, Path2D, STAGE_WIDTH: 80, STAGE_HEIGHT: 50, FRAME_RATE: 30, BACKGROUND: '#000',
|
|
631
|
+
SYMBOL_CLASSES: [{ id: 1, name: 'Fixture' }], loaded: [],
|
|
632
|
+
};
|
|
633
|
+
sandbox.window = sandbox;
|
|
634
|
+
const result = runInNewContext(`
|
|
635
|
+
${SWFLIB_SOURCE}
|
|
636
|
+
class Fixture extends MovieClip {
|
|
637
|
+
constructor() { super(); globalThis.__swoof_bindAs3SymbolInstance(this); }
|
|
638
|
+
}
|
|
639
|
+
Fixture.__swoofQualifiedName = 'Fixture';
|
|
640
|
+
globalThis.Fixture = Fixture;
|
|
641
|
+
${engine}
|
|
642
|
+
const main = __swoof_swflib.stage.addChild(new MovieClip());
|
|
643
|
+
main._swoofHostTimeline = true;
|
|
644
|
+
window.__swoof = { main };
|
|
645
|
+
timeline.enter();
|
|
646
|
+
const card = new Fixture();
|
|
647
|
+
card.x = 14;
|
|
648
|
+
main.addChild(card);
|
|
649
|
+
({ timeline, card, nativeTextField: card.field instanceof TextField, initialText: card.field.text });
|
|
650
|
+
`, sandbox);
|
|
651
|
+
expect(result.nativeTextField).toBe(true);
|
|
652
|
+
expect(result.initialText).toBe('');
|
|
653
|
+
fills.length = 0;
|
|
654
|
+
result.timeline.render();
|
|
655
|
+
expect(fills).toEqual([[0, 1, '#f00'], [14, 1, '#f00']]);
|
|
656
|
+
});
|