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,1151 @@
|
|
|
1
|
+
import { runInNewContext } from 'node:vm';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { decodeTag } from '../decoder/tag-decoder.js';
|
|
4
|
+
import { TAG } from '../decoder/tag-types.js';
|
|
5
|
+
import { transpileActionScript } from '../transpiler/actionscript.js';
|
|
6
|
+
import { AVM1_RUNTIME_STUB, transpileAvm1 } from '../transpiler/avm1/avm1-transpiler.js';
|
|
7
|
+
import { hitTestAvm1ClipGeometry } from '../transpiler/avm1/avm1-transpiler.js';
|
|
8
|
+
import { buildFramesFromTags } from '../transpiler/timeline/display-list.js';
|
|
9
|
+
import { generateTimelineEngine, timelineEngineFactorySource, timelineHelpersSource } from '../transpiler/timeline/timeline-codegen.js';
|
|
10
|
+
import { AVM1_RUNTIME_BOOTSTRAP, AVM1_RUNTIME_FACTORY_SOURCE } from '../runtime/avm1-runtime.js';
|
|
11
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
12
|
+
import { DiagnosticsCollector } from '../util/diagnostics.js';
|
|
13
|
+
|
|
14
|
+
function createRuntime() {
|
|
15
|
+
const displayList = Object.create(null);
|
|
16
|
+
const create = new Function('displayList', 'EXPORT_ASSETS', 'CHARACTERS',
|
|
17
|
+
`${AVM1_RUNTIME_STUB}\nreturn { root, displayList };`);
|
|
18
|
+
return create(displayList, [{ id: 7, name: 'linked.Symbol' }], {
|
|
19
|
+
7: { type: 'sprite', frames: [{}], bounds: { w: 100, h: 80 } },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function createDrawingBundle(ctx, loaded = {}, authored = { frames: [{ places: [] }], characters: {} }) {
|
|
24
|
+
const engine = generateTimelineEngine({ frames: authored.frames, characters: {
|
|
25
|
+
7: { type: 'sprite', frames: [{}], bounds: { w: 100, h: 80 } },
|
|
26
|
+
...authored.characters,
|
|
27
|
+
} }, { frameCount: 1 });
|
|
28
|
+
return new Function('ctx', 'loaded', 'EXPORT_ASSETS', 'window',
|
|
29
|
+
`var BACKGROUND = '#fff', STAGE_WIDTH = 100, STAGE_HEIGHT = 100;\n${AVM1_RUNTIME_STUB}\n${engine}\nreturn { root, timeline, displayList, ensureNamedClip: _ensureNamedClip };`)(
|
|
30
|
+
ctx, loaded, [{ id: 7, name: 'linked.Symbol' }], { __swoof: {} });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function drawingContext() {
|
|
34
|
+
const fills = [], strokes = [];
|
|
35
|
+
const ctx = {
|
|
36
|
+
globalAlpha: 1, imageSmoothingEnabled: true, fillStyle: null,
|
|
37
|
+
save() {}, restore() {}, setTransform(...transform) { this.transform = transform; }, fillRect() {}, fillText() {},
|
|
38
|
+
fill(path) { fills.push({ fillStyle: this.fillStyle, path, transform: this.transform }); },
|
|
39
|
+
stroke(path) {
|
|
40
|
+
strokes.push({
|
|
41
|
+
strokeStyle: this.strokeStyle, lineWidth: this.lineWidth, path, transform: this.transform,
|
|
42
|
+
lineCap: this.lineCap, lineJoin: this.lineJoin, miterLimit: this.miterLimit,
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
createLinearGradient(...coordinates) {
|
|
46
|
+
return { coordinates, stops: [], addColorStop(position, color) { this.stops.push({ position, color }); } };
|
|
47
|
+
},
|
|
48
|
+
createRadialGradient(...coordinates) {
|
|
49
|
+
return { coordinates, stops: [], addColorStop(position, color) { this.stops.push({ position, color }); } };
|
|
50
|
+
},
|
|
51
|
+
createPattern(image, repeat) {
|
|
52
|
+
return { image, repeat, transform: null, setTransform(matrix) { this.transform = matrix.values; } };
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
return { ctx, fills, strokes };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
describe('AVM1 attachMovie', () => {
|
|
59
|
+
it('inherits movie clip prototype mixins without overwriting authored accessor storage', () => {
|
|
60
|
+
const { root, factoryCalls, provider } = runInNewContext(`
|
|
61
|
+
${AVM1_RUNTIME_STUB}
|
|
62
|
+
var factoryCalls = [];
|
|
63
|
+
Avm1MovieClip.prototype.createClassObject = function (klass) { factoryCalls.push([this.name, klass]); };
|
|
64
|
+
var created = root.createEmptyMovieClip('created', 1);
|
|
65
|
+
root.createClassObject('Menu');
|
|
66
|
+
created.createClassObject('Menu');
|
|
67
|
+
var provider = { entries: ['File'] };
|
|
68
|
+
created.__dataProvider = ['row'];
|
|
69
|
+
created.addProperty('dataProvider',
|
|
70
|
+
function () { return this.menuDataProvider; },
|
|
71
|
+
function (value) { this.menuDataProvider = value; });
|
|
72
|
+
created.dataProvider = provider;
|
|
73
|
+
({ root, factoryCalls, provider });
|
|
74
|
+
`);
|
|
75
|
+
expect(factoryCalls).toEqual([['root', 'Menu'], ['created', 'Menu']]);
|
|
76
|
+
expect(root.created.dataProvider).toBe(provider);
|
|
77
|
+
expect(root.created.__dataProvider).toEqual(['row']);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('dispatches authored unload and script-defined descendant unloads after display-list removal', () => {
|
|
81
|
+
const operands = [0, ...Buffer.from('unloaded'), 0, 5, 1];
|
|
82
|
+
const bytecode = [0x96, operands.length, 0, ...operands, 0x1d, 0];
|
|
83
|
+
const placement = decodeTag({ code: TAG.PlaceObject2, data: Uint8Array.from([
|
|
84
|
+
0xa2, 1, 0, 7, 0, ...Buffer.from('placed\0'),
|
|
85
|
+
0, 0, 4, 0, 0, 0, 4, 0, 0, 0, bytecode.length, 0, 0, 0, ...bytecode, 0, 0, 0, 0,
|
|
86
|
+
]) }, { header: { version: 6 } });
|
|
87
|
+
const remove = decodeTag({ code: TAG.RemoveObject2, data: Uint8Array.of(1, 0) });
|
|
88
|
+
const showFrame = { type: 'ShowFrame' };
|
|
89
|
+
const tags = [placement, showFrame, remove, showFrame];
|
|
90
|
+
const { fullJs } = transpileActionScript(tags, undefined, { swfVersion: 6 });
|
|
91
|
+
const engine = generateTimelineEngine({
|
|
92
|
+
frames: buildFramesFromTags(tags),
|
|
93
|
+
characters: { 7: { type: 'sprite', frames: [{}] } },
|
|
94
|
+
}, { frameCount: 2 });
|
|
95
|
+
|
|
96
|
+
const { root, timeline, placed, descendant, calls } = runInNewContext(`
|
|
97
|
+
var BACKGROUND = '#fff', STAGE_WIDTH = 100, STAGE_HEIGHT = 100, FRAME_RATE = 24;
|
|
98
|
+
var ctx = null, loaded = {};
|
|
99
|
+
${engine}
|
|
100
|
+
var __swoof_root = timeline;
|
|
101
|
+
${fullJs}
|
|
102
|
+
timeline.enter();
|
|
103
|
+
var placed = root.placed;
|
|
104
|
+
var descendant = placed.createEmptyMovieClip('descendant', 3), calls = [];
|
|
105
|
+
descendant.onUnload = function () {
|
|
106
|
+
calls.push([this === descendant, root.placed, this.parent]);
|
|
107
|
+
root.createEmptyMovieClip('createdOnUnload', 1);
|
|
108
|
+
};
|
|
109
|
+
({ root, timeline, placed, descendant, calls });
|
|
110
|
+
`, { window: {}, requestAnimationFrame: () => 1 });
|
|
111
|
+
|
|
112
|
+
expect(typeof placed.onUnload).toBe('function');
|
|
113
|
+
expect(placed.unloaded).toBeUndefined();
|
|
114
|
+
timeline.gotoAndStop(2);
|
|
115
|
+
expect(root.placed).toBeUndefined();
|
|
116
|
+
expect(descendant.parent).toBeNull();
|
|
117
|
+
timeline.tick();
|
|
118
|
+
expect(placed.unloaded).toBe(true);
|
|
119
|
+
expect(calls).toEqual([[true, undefined, null]]);
|
|
120
|
+
expect(root.getInstanceAtDepth(1)).toBe(root.createdOnUnload);
|
|
121
|
+
timeline.tick();
|
|
122
|
+
expect(calls).toHaveLength(1);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('paints an attached bitmap as a live unnamed leaf at its nested depth', () => {
|
|
126
|
+
const { ctx, fills } = drawingContext();
|
|
127
|
+
const images = [];
|
|
128
|
+
ctx.drawImage = function (image) {
|
|
129
|
+
images.push([image, this.transform.map(value => value || 0), this.imageSmoothingEnabled, fills.length]);
|
|
130
|
+
};
|
|
131
|
+
const engine = generateTimelineEngine({ frames: [{ places: [] }], characters: {} }, { frameCount: 1 });
|
|
132
|
+
const { bitmap, render, snapshot, replace, detach } = runInNewContext(`
|
|
133
|
+
var BACKGROUND = '#fff', STAGE_WIDTH = 100, STAGE_HEIGHT = 100, loaded = {};
|
|
134
|
+
${SWFLIB_SOURCE}
|
|
135
|
+
${AVM1_RUNTIME_STUB}
|
|
136
|
+
${engine}
|
|
137
|
+
const bitmap = new globals.flash.display.BitmapData(10, 6);
|
|
138
|
+
const parent = root.createEmptyMovieClip('owner', 4);
|
|
139
|
+
parent.x = 12.25;
|
|
140
|
+
parent.y = 20.5;
|
|
141
|
+
function paint(clip) { clip.beginFill(0x123456); clip.drawRect(0, 0, 3, 3); clip.endFill(); }
|
|
142
|
+
paint(parent);
|
|
143
|
+
const lower = parent.createEmptyMovieClip('lower', 0);
|
|
144
|
+
paint(lower);
|
|
145
|
+
const old = parent.createEmptyMovieClip('old', 1);
|
|
146
|
+
const higher = parent.createEmptyMovieClip('higher', 2);
|
|
147
|
+
paint(higher);
|
|
148
|
+
parent.attachBitmap(bitmap, 1, 'always', true);
|
|
149
|
+
({
|
|
150
|
+
bitmap, render: () => timeline.render(),
|
|
151
|
+
snapshot: [
|
|
152
|
+
parent.getInstanceAtDepth(1), parent.old, old._swoofDetached, parent.getNextHighestDepth(),
|
|
153
|
+
parent.hitTest(19, 25, true), parent.hitTest(19, 25, false),
|
|
154
|
+
],
|
|
155
|
+
replace: () => parent.createEmptyMovieClip('replacement', 1),
|
|
156
|
+
detach: () => parent.removeMovieClip(),
|
|
157
|
+
});
|
|
158
|
+
`, {
|
|
159
|
+
ctx, window: { __swoof: {} }, Path2D: class { moveTo() {} lineTo() {} closePath() {} },
|
|
160
|
+
document: {
|
|
161
|
+
createElement() {
|
|
162
|
+
return { getContext() { return this.width === 100 ? null : { drawImage() {} }; } };
|
|
163
|
+
},
|
|
164
|
+
getElementById: () => null,
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
expect(snapshot).toEqual([undefined, undefined, true, 3, true, true]);
|
|
168
|
+
render();
|
|
169
|
+
expect(fills).toHaveLength(3);
|
|
170
|
+
expect(images).toEqual([[bitmap._canvas, [1, 0, 0, 1, 12, 21], true, 2]]);
|
|
171
|
+
bitmap.lock();
|
|
172
|
+
render();
|
|
173
|
+
expect(images.at(-1)[0]).toBe(bitmap._lockedDisplayImage);
|
|
174
|
+
bitmap.unlock();
|
|
175
|
+
render();
|
|
176
|
+
expect(images.at(-1)[0]).toBe(bitmap._canvas);
|
|
177
|
+
replace();
|
|
178
|
+
render();
|
|
179
|
+
expect(images).toHaveLength(3);
|
|
180
|
+
detach();
|
|
181
|
+
const fillCount = fills.length;
|
|
182
|
+
render();
|
|
183
|
+
expect(fills).toHaveLength(fillCount);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('runs registered constructors and inherited onLoad once per authored placement after siblings exist', () => {
|
|
187
|
+
const actions = { depth: 1, characterId: 7, name: 'player',
|
|
188
|
+
matrix: { a: 1, b: 0, c: 0, d: 1, tx: 240, ty: 0 } };
|
|
189
|
+
const sibling = { depth: 4, characterId: 8, name: 'hint' };
|
|
190
|
+
const timeline = generateTimelineEngine({
|
|
191
|
+
frames: [
|
|
192
|
+
{ places: [actions, sibling], removes: [] },
|
|
193
|
+
{ places: [], removes: [1] },
|
|
194
|
+
{ places: [actions], removes: [] },
|
|
195
|
+
],
|
|
196
|
+
characters: {
|
|
197
|
+
7: { type: 'sprite', frames: [{ places: [], removes: [] }] },
|
|
198
|
+
8: { type: 'sprite', frames: [{ places: [], removes: [] }] },
|
|
199
|
+
},
|
|
200
|
+
}, { frameCount: 3, stageW: 100, stageH: 100, backgroundColor: '#fff' });
|
|
201
|
+
const { ctx } = drawingContext();
|
|
202
|
+
const { root, timeline: engine, events, Linked } = new Function('ctx', 'EXPORT_ASSETS', 'requestAnimationFrame', `
|
|
203
|
+
var loaded = {};
|
|
204
|
+
var FRAME_RATE = 24, STAGE_WIDTH = 100, STAGE_HEIGHT = 100, BACKGROUND = '#fff';
|
|
205
|
+
${AVM1_RUNTIME_STUB}
|
|
206
|
+
${timeline}
|
|
207
|
+
var events = [];
|
|
208
|
+
function Base() {}
|
|
209
|
+
Base.prototype = Object.create(globals.MovieClip.prototype);
|
|
210
|
+
Base.prototype.onLoad = function () {
|
|
211
|
+
events.push(['load', this.x, this.parent.hint.name, this.parent.started, this.ready]);
|
|
212
|
+
};
|
|
213
|
+
function Linked() {
|
|
214
|
+
globals.MovieClip.call(this);
|
|
215
|
+
events.push(['constructor', this.parent.player === this, this.parent.hint.name]);
|
|
216
|
+
this.constructed = true;
|
|
217
|
+
}
|
|
218
|
+
Linked.prototype = Object.create(Base.prototype);
|
|
219
|
+
globals.Object.registerClass('linked.Symbol', Linked);
|
|
220
|
+
FRAME_SCRIPTS[0] = [function () {
|
|
221
|
+
events.push(['root frame', this.player.constructed, this.player.ready]);
|
|
222
|
+
this.started = true;
|
|
223
|
+
}];
|
|
224
|
+
SPRITE_FRAME_SCRIPTS[7] = [ [function () { this.ready = true; }] ];
|
|
225
|
+
timeline.enter();
|
|
226
|
+
timeline.stop();
|
|
227
|
+
return { root, timeline, events, Linked };
|
|
228
|
+
`)(ctx, [{ id: 7, name: 'linked.Symbol' }], () => 1);
|
|
229
|
+
const first = root.player;
|
|
230
|
+
expect(first).toBeInstanceOf(Linked);
|
|
231
|
+
expect(typeof first.gotoAndStop).toBe('function');
|
|
232
|
+
expect(events).toEqual([
|
|
233
|
+
['constructor', true, 'hint'], ['root frame', true, undefined], ['load', 12, 'hint', true, true],
|
|
234
|
+
]);
|
|
235
|
+
engine.tick();
|
|
236
|
+
expect(events).toHaveLength(3);
|
|
237
|
+
engine.gotoAndStop(2);
|
|
238
|
+
engine.gotoAndStop(3);
|
|
239
|
+
expect(root.player).toBeInstanceOf(Linked);
|
|
240
|
+
expect(root.player).not.toBe(first);
|
|
241
|
+
expect(events).toEqual([
|
|
242
|
+
['constructor', true, 'hint'], ['root frame', true, undefined], ['load', 12, 'hint', true, true],
|
|
243
|
+
['constructor', true, 'hint'], ['load', 12, 'hint', true, true],
|
|
244
|
+
]);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it('returns undefined for missing and unsupported linkages without replacing the occupied depth', () => {
|
|
248
|
+
const displayList = {};
|
|
249
|
+
const root = new Function('displayList', 'EXPORT_ASSETS', 'CHARACTERS', `${AVM1_RUNTIME_STUB}\nreturn root;`)(
|
|
250
|
+
displayList,
|
|
251
|
+
[{ id: 7, name: 'valid' }, { id: 8, name: 'font' }, { id: 9, name: 'missingData' }],
|
|
252
|
+
{ 7: { type: 'sprite', frames: [{}] }, 8: { type: 'font' } },
|
|
253
|
+
);
|
|
254
|
+
const original = root.attachMovie('valid', 'original', 2);
|
|
255
|
+
for (const linkage of ['unknown', 'font', 'missingData', 'Math', 'Array', 1234]) {
|
|
256
|
+
expect(root.attachMovie(linkage, 'replacement', 2)).toBeUndefined();
|
|
257
|
+
}
|
|
258
|
+
expect(root.attachMovie('valid', 'tooLow', -16385)).toBeUndefined();
|
|
259
|
+
expect(root.replacement).toBeUndefined();
|
|
260
|
+
expect(root.original).toBe(original);
|
|
261
|
+
expect(displayList[2]._clip).toBe(original);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('initializes a registered constructor on the named instance and keeps its exported sprite', () => {
|
|
265
|
+
const displayList = {}, events = [];
|
|
266
|
+
const child = new Function('displayList', 'EXPORT_ASSETS', 'CHARACTERS', 'runSpriteFrameScripts', 'events', `
|
|
267
|
+
${AVM1_RUNTIME_STUB}
|
|
268
|
+
function Linked() {
|
|
269
|
+
Avm1MovieClip.call(this);
|
|
270
|
+
events.push([this.parent.copy === this, this.name, this.x, this.seed]);
|
|
271
|
+
this.initialized = true;
|
|
272
|
+
}
|
|
273
|
+
Linked.prototype = Object.create(Avm1MovieClip.prototype);
|
|
274
|
+
globals.Object.registerClass('linked.Symbol', Linked);
|
|
275
|
+
return root.attachMovie('linked.Symbol', 'copy', 2, { _x: 24, seed: 7 });
|
|
276
|
+
`)(displayList, [{ id: 7, name: 'linked.Symbol' }], { 7: { type: 'sprite', frames: [{}] } },
|
|
277
|
+
(id, frame, instance) => events.push([id, frame, instance.initialized]), events);
|
|
278
|
+
expect(events).toEqual([[true, 'copy', 24, 7], [7, 0, true]]);
|
|
279
|
+
expect(child._swoofCharacterId).toBe(7);
|
|
280
|
+
expect(displayList[2]._clip).toBe(child);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('measures registered linked sprites with script-created artwork and retains explicit dimensions', () => {
|
|
284
|
+
const { root, panel, fixed, drawRectangle, addChildArtwork, readSize, setMember, setProperty } =
|
|
285
|
+
new Function('EXPORT_ASSETS', 'CHARACTERS', `
|
|
286
|
+
var displayList = {}, SWF_VERSION = 7;
|
|
287
|
+
${AVM1_RUNTIME_STUB}
|
|
288
|
+
function Panel() {}
|
|
289
|
+
Panel.prototype = new globals.MovieClip();
|
|
290
|
+
function Fixed() { this.height = 15; }
|
|
291
|
+
Fixed.prototype = new globals.MovieClip();
|
|
292
|
+
globals.Object.registerClass('panel', Panel);
|
|
293
|
+
globals.Object.registerClass('fixed', Fixed);
|
|
294
|
+
function drawRectangle(clip, x, y, width, height) {
|
|
295
|
+
clip.beginFill(0x123456);
|
|
296
|
+
clip.drawRect(x, y, width, height);
|
|
297
|
+
clip.endFill();
|
|
298
|
+
}
|
|
299
|
+
function addChildArtwork(parent) {
|
|
300
|
+
var child = parent.createEmptyMovieClip('branch', 1);
|
|
301
|
+
child.x = 20;
|
|
302
|
+
child.y = 6;
|
|
303
|
+
drawRectangle(child, 0, 0, 6, 4);
|
|
304
|
+
return child;
|
|
305
|
+
}
|
|
306
|
+
function readSize(clip) {
|
|
307
|
+
return [_member(clip, '_width'), _member(clip, '_height'), _getProperty(clip, 8), _getProperty(clip, 9)];
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
root, drawRectangle, addChildArtwork, readSize, setMember: _setMember, setProperty: _setProperty,
|
|
311
|
+
panel: root.attachMovie('panel', 'panel', 1),
|
|
312
|
+
fixed: root.attachMovie('fixed', 'fixed', 2, { _width: 0 }),
|
|
313
|
+
};
|
|
314
|
+
`)([{ id: 7, name: 'panel' }, { id: 8, name: 'fixed' }], {
|
|
315
|
+
7: { type: 'sprite', frames: [{}] }, 8: { type: 'sprite', frames: [{}] },
|
|
316
|
+
});
|
|
317
|
+
expect(readSize(panel)).toEqual([0, 0, 0, 0]);
|
|
318
|
+
drawRectangle(panel, 2, -3, 12, 8);
|
|
319
|
+
const child = addChildArtwork(panel);
|
|
320
|
+
expect(readSize(panel)).toEqual([24, 13, 24, 13]);
|
|
321
|
+
setMember(root, '_yscale', 300);
|
|
322
|
+
expect(readSize(panel)).toEqual([24, 13, 24, 13]);
|
|
323
|
+
setMember(panel, '_xscale', -150);
|
|
324
|
+
setMember(panel, '_yscale', 200);
|
|
325
|
+
expect(readSize(panel)).toEqual([36, 26, 36, 26]);
|
|
326
|
+
setMember(panel, '_rotation', 90);
|
|
327
|
+
expect(readSize(panel)).toEqual([26, 36, 26, 36]);
|
|
328
|
+
child.removeMovieClip();
|
|
329
|
+
expect(readSize(panel)).toEqual([16, 18, 16, 18]);
|
|
330
|
+
|
|
331
|
+
setMember(panel, '_width', 0);
|
|
332
|
+
expect(readSize(panel)).toEqual([0, 18, 0, 18]);
|
|
333
|
+
setProperty(panel, 9, 11);
|
|
334
|
+
addChildArtwork(panel);
|
|
335
|
+
expect(readSize(panel)).toEqual([0, 11, 0, 11]);
|
|
336
|
+
setProperty(panel, 8, 17);
|
|
337
|
+
setMember(panel, '_height', 0);
|
|
338
|
+
expect(readSize(panel)).toEqual([17, 0, 17, 0]);
|
|
339
|
+
drawRectangle(fixed, 0, 0, 50, 30);
|
|
340
|
+
expect(readSize(fixed)).toEqual([0, 15, 0, 15]);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it('binds attached sprite children before its constructor and runs their actions in order', () => {
|
|
344
|
+
const engine = generateTimelineEngine({
|
|
345
|
+
frames: [{ places: [] }],
|
|
346
|
+
characters: {
|
|
347
|
+
7: { type: 'sprite', frames: [{ places: [
|
|
348
|
+
{ depth: 1, characterId: 8, name: 'logo' },
|
|
349
|
+
{ depth: 2, characterId: 9, name: 'otherLogo' },
|
|
350
|
+
] }] },
|
|
351
|
+
8: { type: 'sprite', frames: [{ places: [{ depth: 1, characterId: 9, name: 'art' }] }] },
|
|
352
|
+
9: { type: 'sprite', frames: [{ places: [] }] },
|
|
353
|
+
},
|
|
354
|
+
}, { frameCount: 1, sharedFactory: true });
|
|
355
|
+
const { events, beforeTick, child, root } = runInNewContext(`
|
|
356
|
+
${SWFLIB_SOURCE}
|
|
357
|
+
__swoof_swflib.timelineHelpers = ${timelineHelpersSource()};
|
|
358
|
+
__swoof_swflib.createTimelineEngine = ${timelineEngineFactorySource()};
|
|
359
|
+
__swoof_swflib.createAvm1Runtime = ${AVM1_RUNTIME_FACTORY_SOURCE};
|
|
360
|
+
var STAGE_WIDTH = 100, STAGE_HEIGHT = 100, FRAME_RATE = 24, BACKGROUND = '#fff';
|
|
361
|
+
var ctx = null, loaded = {}, ASSETS = [], SYMBOL_CLASSES = [];
|
|
362
|
+
var EXPORT_ASSETS = [{ id: 7, name: 'Intro' }, { id: 8, name: 'Logo' }];
|
|
363
|
+
var __swoof_root = {};
|
|
364
|
+
${engine}
|
|
365
|
+
${AVM1_RUNTIME_BOOTSTRAP}
|
|
366
|
+
var events = [];
|
|
367
|
+
function Intro() {
|
|
368
|
+
globals.MovieClip.call(this);
|
|
369
|
+
events.push(['parent constructor', this.logo instanceof Logo,
|
|
370
|
+
this.logo?.art?.parent === this.logo && Boolean(this.logo), this.otherLogo?.name,
|
|
371
|
+
this.logo?.initialized, this.frameAction]);
|
|
372
|
+
this.initialized = true;
|
|
373
|
+
}
|
|
374
|
+
Intro.prototype = Object.create(globals.MovieClip.prototype);
|
|
375
|
+
function Logo() {
|
|
376
|
+
globals.MovieClip.call(this);
|
|
377
|
+
events.push(['child constructor', this.parent.frameAction, this.art?.name, this.parent.otherLogo?.name]);
|
|
378
|
+
this.initialized = true;
|
|
379
|
+
}
|
|
380
|
+
Logo.prototype = Object.create(globals.MovieClip.prototype);
|
|
381
|
+
Logo.prototype.onLoad = function () { events.push(['child load', this.frameAction]); };
|
|
382
|
+
globals.Object.registerClass('Intro', Intro);
|
|
383
|
+
globals.Object.registerClass('Logo', Logo);
|
|
384
|
+
SPRITE_FRAME_SCRIPTS[7] = [[function () {
|
|
385
|
+
events.push(['parent frame', this.initialized, this.logo.initialized]);
|
|
386
|
+
this.frameAction = true;
|
|
387
|
+
}]];
|
|
388
|
+
SPRITE_FRAME_SCRIPTS[8] = [[function () {
|
|
389
|
+
events.push(['child frame', this.initialized]);
|
|
390
|
+
this.frameAction = true;
|
|
391
|
+
}]];
|
|
392
|
+
timeline.enter();
|
|
393
|
+
timeline.stop();
|
|
394
|
+
const child = root.attachMovie('Intro', 'intro', 4);
|
|
395
|
+
const beforeTick = events.slice();
|
|
396
|
+
timeline.tick();
|
|
397
|
+
timeline.tick();
|
|
398
|
+
({ events, beforeTick, child, root });
|
|
399
|
+
`, { requestAnimationFrame: () => 1 });
|
|
400
|
+
|
|
401
|
+
expect(root.intro).toBe(child);
|
|
402
|
+
expect(beforeTick).toEqual([
|
|
403
|
+
['parent constructor', true, true, 'otherLogo', undefined, undefined],
|
|
404
|
+
['parent frame', true, undefined],
|
|
405
|
+
]);
|
|
406
|
+
expect(events).toEqual([
|
|
407
|
+
...beforeTick,
|
|
408
|
+
['child constructor', true, 'art', 'otherLogo'],
|
|
409
|
+
['child frame', true],
|
|
410
|
+
['child load', true],
|
|
411
|
+
]);
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
it('resolves ExportAssets and composes nested parent-local transforms', () => {
|
|
415
|
+
const { root, displayList } = createRuntime();
|
|
416
|
+
const parent = root.attachMovie('linked.Symbol', 'holder', 4,
|
|
417
|
+
{ x: 10, y: 20, rotation: 90, scaleX: 200, scaleY: 200 });
|
|
418
|
+
expect(parent.parent).toBe(root);
|
|
419
|
+
expect(root.parent).toBeNull();
|
|
420
|
+
const child = parent.attachMovie('linked.Symbol', 'child', 3, { x: 2, y: 3 });
|
|
421
|
+
expect([parent.x, parent.y, parent.rotation, parent.scaleX, parent.scaleY, child.x, child.y, child.scaleX, child.scaleY])
|
|
422
|
+
.toEqual([10, 20, 90, 200, 200, 2, 3, 100, 100]);
|
|
423
|
+
|
|
424
|
+
const entry = displayList[child._swoofDisplayDepth];
|
|
425
|
+
expect(child._swoofCharacterId).toBe(7);
|
|
426
|
+
expect(entry._clip).toBe(child);
|
|
427
|
+
expect(entry.matrix.a).toBeCloseTo(0);
|
|
428
|
+
expect(entry.matrix.b).toBe(2);
|
|
429
|
+
expect(entry.matrix.c).toBe(-2);
|
|
430
|
+
expect(entry.matrix.d).toBeCloseTo(0);
|
|
431
|
+
expect([entry.matrix.tx, entry.matrix.ty]).toEqual([80, 480]);
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
it('keeps same-depth children under different parents distinct', () => {
|
|
435
|
+
const { root, displayList } = createRuntime();
|
|
436
|
+
const left = root.attachMovie('linked.Symbol', 'left', 10);
|
|
437
|
+
const right = root.attachMovie('linked.Symbol', 'right', 20);
|
|
438
|
+
const leftChild = left.attachMovie('linked.Symbol', 'item', 5);
|
|
439
|
+
const rightChild = right.attachMovie('linked.Symbol', 'item', 5);
|
|
440
|
+
|
|
441
|
+
expect(displayList[leftChild._swoofDisplayDepth]._clip).toBe(leftChild);
|
|
442
|
+
expect(displayList[rightChild._swoofDisplayDepth]._clip).toBe(rightChild);
|
|
443
|
+
expect(left._swoofChildren[5]).toBe(leftChild);
|
|
444
|
+
expect(right._swoofChildren[5]).toBe(rightChild);
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it('replaces the existing clip at a reused depth and clears its old name', () => {
|
|
448
|
+
const { root, displayList } = createRuntime();
|
|
449
|
+
const first = root.attachMovie('linked.Symbol', 'first', 10);
|
|
450
|
+
const second = root.attachMovie('linked.Symbol', 'second', 10);
|
|
451
|
+
|
|
452
|
+
expect(root._swoofChildren[10]).toBe(second);
|
|
453
|
+
expect(root.first).not.toBe(first);
|
|
454
|
+
expect(first.parent).toBeNull();
|
|
455
|
+
expect(first.visible).toBe(false);
|
|
456
|
+
expect(displayList[10]._clip).toBe(second);
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
it('paints nested createEmptyMovieClip drawing in parent space and hit tests it', () => {
|
|
460
|
+
const { root, displayList } = createRuntime();
|
|
461
|
+
const parent = root.attachMovie('linked.Symbol', 'holder', 4,
|
|
462
|
+
{ x: 10, y: 20, rotation: 90, scaleX: 200, scaleY: 200 });
|
|
463
|
+
const ink = parent.createEmptyMovieClip('ink', 3);
|
|
464
|
+
ink.beginFill(0xff0000, 100);
|
|
465
|
+
ink.moveTo(0, 0); ink.lineTo(10, 0); ink.lineTo(10, 10); ink.lineTo(0, 10); ink.endFill();
|
|
466
|
+
|
|
467
|
+
const entry = displayList[ink._swoofDisplayDepth];
|
|
468
|
+
expect(entry._clip).toBe(ink);
|
|
469
|
+
expect(entry._dynamicDraws).toBe(ink._swoofDraws);
|
|
470
|
+
expect(entry.matrix.a).toBeCloseTo(0);
|
|
471
|
+
expect(entry.matrix.b).toBe(2);
|
|
472
|
+
expect([entry.matrix.tx, entry.matrix.ty]).toEqual([200, 400]);
|
|
473
|
+
expect(hitTestAvm1ClipGeometry({}, ink, 8, 24)).toBe(true);
|
|
474
|
+
expect(hitTestAvm1ClipGeometry({}, ink, 20, 20)).toBe(false);
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
it('keeps nested empty clips distinct across parent branches and replaces reused child depth', () => {
|
|
478
|
+
const { root, displayList } = createRuntime();
|
|
479
|
+
const left = root.attachMovie('linked.Symbol', 'left', 10);
|
|
480
|
+
const right = root.attachMovie('linked.Symbol', 'right', 20);
|
|
481
|
+
const leftInk = left.createEmptyMovieClip('ink', 5);
|
|
482
|
+
const rightInk = right.createEmptyMovieClip('ink', 5);
|
|
483
|
+
expect(displayList[leftInk._swoofDisplayDepth]._clip).toBe(leftInk);
|
|
484
|
+
expect(displayList[rightInk._swoofDisplayDepth]._clip).toBe(rightInk);
|
|
485
|
+
|
|
486
|
+
const replacement = left.createEmptyMovieClip('replacement', 5);
|
|
487
|
+
expect(left._swoofChildren[5]).toBe(replacement);
|
|
488
|
+
expect(leftInk.parent).toBeNull();
|
|
489
|
+
expect(leftInk.visible).toBe(false);
|
|
490
|
+
expect(displayList[replacement._swoofDisplayDepth]._clip).toBe(replacement);
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
it('keeps depth zero, signed depths, and deep branches independent', () => {
|
|
494
|
+
const { root, displayList } = createRuntime();
|
|
495
|
+
let parent = root.createEmptyMovieClip('parent', 0);
|
|
496
|
+
const rootEntry = displayList[0];
|
|
497
|
+
for (let depth = 0; depth < 70; depth++) {
|
|
498
|
+
parent.x = 1;
|
|
499
|
+
parent = parent.createEmptyMovieClip('child', 0);
|
|
500
|
+
}
|
|
501
|
+
const left = parent.attachMovie(7, 'left', 65536);
|
|
502
|
+
const right = parent.attachMovie(7, 'right', -1);
|
|
503
|
+
expect(displayList[0]).toBe(rootEntry);
|
|
504
|
+
expect(displayList[left._swoofDisplayDepth]._clip).toBe(left);
|
|
505
|
+
expect(displayList[right._swoofDisplayDepth]._clip).toBe(right);
|
|
506
|
+
expect(displayList[left._swoofDisplayDepth].matrix.tx).toBe(1400);
|
|
507
|
+
|
|
508
|
+
const leftKey = left._swoofDisplayDepth;
|
|
509
|
+
left.swapDepths(right);
|
|
510
|
+
expect(left.getDepth()).toBe(-1);
|
|
511
|
+
expect(right.getDepth()).toBe(65536);
|
|
512
|
+
expect(displayList[leftKey]._clip).toBe(left);
|
|
513
|
+
left.swapDepths(root._swoofChildren[0]);
|
|
514
|
+
expect(left.getDepth()).toBe(-1);
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
it('moves both occupied root slots atomically and removes only the owned subtree', () => {
|
|
518
|
+
const { root, displayList } = createRuntime();
|
|
519
|
+
const front = root.createEmptyMovieClip('front', 3);
|
|
520
|
+
const back = root.attachMovie(7, 'back', 2);
|
|
521
|
+
const ink = front.createEmptyMovieClip('ink', 1);
|
|
522
|
+
const child = ink.attachMovie(7, 'art', 2);
|
|
523
|
+
const nestedKeys = [ink._swoofDisplayDepth, child._swoofDisplayDepth];
|
|
524
|
+
front.swapDepths(back);
|
|
525
|
+
expect(displayList[2]._clip).toBe(front);
|
|
526
|
+
expect(displayList[3]._clip).toBe(back);
|
|
527
|
+
expect(root._swoofChildren[2]).toBe(front);
|
|
528
|
+
expect(root._swoofChildren[3]).toBe(back);
|
|
529
|
+
|
|
530
|
+
// A reference to an old clip can't erase its replacement or redraw its subtree.
|
|
531
|
+
const replacement = root.createEmptyMovieClip('replacement', 2);
|
|
532
|
+
front.removeMovieClip();
|
|
533
|
+
child.drawRect(0, 0, 5, 5);
|
|
534
|
+
for (const key of nestedKeys) expect(displayList[key]).toBeUndefined();
|
|
535
|
+
expect(ink.parent).toBeNull();
|
|
536
|
+
expect(child.parent).toBeNull();
|
|
537
|
+
expect(displayList[2]._clip).toBe(replacement);
|
|
538
|
+
expect(displayList[3]._clip).toBe(back);
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
it('draws descendants with their parent before the next depth, including after rebuild', () => {
|
|
542
|
+
const previousPath2D = globalThis.Path2D;
|
|
543
|
+
globalThis.Path2D = class { moveTo() {} lineTo() {} closePath() {} };
|
|
544
|
+
try {
|
|
545
|
+
const { ctx, fills } = drawingContext();
|
|
546
|
+
const { root, timeline } = createDrawingBundle(ctx);
|
|
547
|
+
const back = root.createEmptyMovieClip('back', 2);
|
|
548
|
+
const nested = back.createEmptyMovieClip('nested', 80000);
|
|
549
|
+
const front = root.createEmptyMovieClip('front', 3);
|
|
550
|
+
nested.beginFill(0xff0000);
|
|
551
|
+
nested.drawRect(0, 0, 10, 10);
|
|
552
|
+
front.beginFill(0x0000ff);
|
|
553
|
+
front.drawRect(0, 0, 10, 10);
|
|
554
|
+
timeline.rebuild();
|
|
555
|
+
timeline.render();
|
|
556
|
+
expect(fills.map(fill => fill.fillStyle)).toEqual(['rgba(255,0,0,1)', 'rgba(0,0,255,1)']);
|
|
557
|
+
|
|
558
|
+
fills.length = 0;
|
|
559
|
+
back.swapDepths(front);
|
|
560
|
+
timeline.render();
|
|
561
|
+
expect(fills.map(fill => fill.fillStyle)).toEqual(['rgba(0,0,255,1)', 'rgba(255,0,0,1)']);
|
|
562
|
+
|
|
563
|
+
fills.length = 0;
|
|
564
|
+
back.visible = false;
|
|
565
|
+
timeline.render();
|
|
566
|
+
expect(fills.map(fill => fill.fillStyle)).toEqual(['rgba(0,0,255,1)']);
|
|
567
|
+
} finally {
|
|
568
|
+
globalThis.Path2D = previousPath2D;
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
it('orders children of named timeline proxies at their authored root depth', () => {
|
|
573
|
+
const previousPath2D = globalThis.Path2D;
|
|
574
|
+
globalThis.Path2D = class { moveTo() {} lineTo() {} closePath() {} };
|
|
575
|
+
try {
|
|
576
|
+
const { ctx, fills } = drawingContext();
|
|
577
|
+
const { root, timeline, displayList, ensureNamedClip } = createDrawingBundle(ctx);
|
|
578
|
+
displayList[8] = { name: 'authoredHolder' };
|
|
579
|
+
const authored = ensureNamedClip('authoredHolder');
|
|
580
|
+
const nested = authored.createEmptyMovieClip('nested', 1);
|
|
581
|
+
const earlier = root.createEmptyMovieClip('earlier', 7 - 16384);
|
|
582
|
+
nested.beginFill(0xff0000);
|
|
583
|
+
nested.drawRect(0, 0, 10, 10);
|
|
584
|
+
earlier.beginFill(0x0000ff);
|
|
585
|
+
earlier.drawRect(0, 0, 10, 10);
|
|
586
|
+
timeline.render();
|
|
587
|
+
expect(fills.map(fill => fill.fillStyle)).toEqual(['rgba(0,0,255,1)', 'rgba(255,0,0,1)']);
|
|
588
|
+
} finally {
|
|
589
|
+
globalThis.Path2D = previousPath2D;
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
it('interleaves nested dynamic branches with authored siblings across depth swaps', () => {
|
|
594
|
+
const previousPath2D = globalThis.Path2D;
|
|
595
|
+
globalThis.Path2D = class { moveTo() {} lineTo() {} closePath() {} };
|
|
596
|
+
const shape = color => ({ type: 'shape', draws: [{ fill: { type: 'solid', color },
|
|
597
|
+
path: [['M', 0, 0], ['L', 20, 0], ['L', 20, 20], ['L', 0, 20], ['Z']] }] });
|
|
598
|
+
try {
|
|
599
|
+
const { ctx, fills } = drawingContext();
|
|
600
|
+
const { root, timeline } = createDrawingBundle(ctx, {}, {
|
|
601
|
+
frames: [{ places: [{ depth: 1, characterId: 8, name: 'holder', matrix: { a: 1, b: 0, c: 0, d: 1, tx: 200, ty: 0 } }] }],
|
|
602
|
+
characters: {
|
|
603
|
+
8: { type: 'sprite', frames: [{ places: [{ depth: 1, characterId: 9, name: 'red' }, { depth: 3, characterId: 10 }] }] },
|
|
604
|
+
9: shape('#f00'), 10: shape('#0f0'),
|
|
605
|
+
},
|
|
606
|
+
});
|
|
607
|
+
timeline.enter();
|
|
608
|
+
const holder = root.holder;
|
|
609
|
+
holder.beginFill(0x0f0f0f);
|
|
610
|
+
holder.drawRect(0, 0, 10, 10);
|
|
611
|
+
const branch = holder.createEmptyMovieClip('branch', 5);
|
|
612
|
+
branch.x = 4;
|
|
613
|
+
const ink = branch.createEmptyMovieClip('ink', 2);
|
|
614
|
+
ink.x = 2;
|
|
615
|
+
ink.beginFill(0x0000ff);
|
|
616
|
+
ink.drawRect(0, 0, 20, 20);
|
|
617
|
+
const front = root.createEmptyMovieClip('front', 4);
|
|
618
|
+
front.beginFill(0xffff00);
|
|
619
|
+
front.drawRect(0, 0, 20, 20);
|
|
620
|
+
const rendered = () => fills.map(fill => [fill.fillStyle, fill.transform[4]]);
|
|
621
|
+
fills.length = 0;
|
|
622
|
+
timeline.render();
|
|
623
|
+
expect(rendered()).toEqual([['rgba(15,15,15,1)', 10], ['#f00', 10], ['#0f0', 10], ['rgba(0,0,255,1)', 16], ['rgba(255,255,0,1)', 0]]);
|
|
624
|
+
holder.red.swapDepths(branch);
|
|
625
|
+
fills.length = 0;
|
|
626
|
+
timeline.render();
|
|
627
|
+
expect(rendered()).toEqual([['rgba(15,15,15,1)', 10], ['rgba(0,0,255,1)', 16], ['#0f0', 10], ['#f00', 10], ['rgba(255,255,0,1)', 0]]);
|
|
628
|
+
} finally {
|
|
629
|
+
globalThis.Path2D = previousPath2D;
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
it('renders beginGradientFill stops and its matrix in the dynamic painter', () => {
|
|
634
|
+
const previousPath2D = globalThis.Path2D;
|
|
635
|
+
globalThis.Path2D = class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} };
|
|
636
|
+
try {
|
|
637
|
+
const { ctx, fills } = drawingContext();
|
|
638
|
+
const { root, timeline } = createDrawingBundle(ctx);
|
|
639
|
+
const clip = root.createEmptyMovieClip('gradient', 1);
|
|
640
|
+
clip.beginGradientFill('linear', [0xff0000, 0x0000ff], [1, 0.5], [0, 255],
|
|
641
|
+
{ a: 1, b: 0, c: 0, d: 1, tx: 5, ty: 7 }, 'reflect', 'rgb');
|
|
642
|
+
expect(clip._swoofFill.stops[0].color).toBe('rgba(255,0,0,1)');
|
|
643
|
+
clip.moveTo(-10, -10); clip.lineTo(10, -10); clip.lineTo(10, 10); clip.endFill();
|
|
644
|
+
timeline.render();
|
|
645
|
+
|
|
646
|
+
const fill = fills[0].fillStyle;
|
|
647
|
+
expect(fill.coordinates[0]).toBeCloseTo(-7367.8);
|
|
648
|
+
expect(fill.coordinates[1]).toBe(7);
|
|
649
|
+
expect(fill.stops.length).toBeGreaterThan(2);
|
|
650
|
+
expect(fill.stops.map((stop) => stop.color)).toContain('rgba(255,0,0,1)');
|
|
651
|
+
} finally {
|
|
652
|
+
if (previousPath2D === undefined) delete globalThis.Path2D;
|
|
653
|
+
else globalThis.Path2D = previousPath2D;
|
|
654
|
+
}
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
it('keeps painting after non-finite dynamic gradient endpoints', () => {
|
|
658
|
+
const previousPath2D = globalThis.Path2D;
|
|
659
|
+
globalThis.Path2D = class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} };
|
|
660
|
+
try {
|
|
661
|
+
const { ctx, fills } = drawingContext();
|
|
662
|
+
const { root, timeline } = createDrawingBundle(ctx);
|
|
663
|
+
const clip = root.createEmptyMovieClip('gradient', 1);
|
|
664
|
+
const createLinearGradient = ctx.createLinearGradient;
|
|
665
|
+
const createRadialGradient = ctx.createRadialGradient;
|
|
666
|
+
ctx.createLinearGradient = (...coordinates) => {
|
|
667
|
+
if (!coordinates.every(Number.isFinite)) throw new TypeError('Non-finite linear gradient coordinates');
|
|
668
|
+
return createLinearGradient(...coordinates);
|
|
669
|
+
};
|
|
670
|
+
ctx.createRadialGradient = (...coordinates) => {
|
|
671
|
+
if (!coordinates.every(Number.isFinite)) throw new TypeError('Non-finite radial gradient coordinates');
|
|
672
|
+
return createRadialGradient(...coordinates);
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
clip.beginGradientFill('linear', [0xff0000, 0x0000ff], [1, 1], [0, 255], { a: NaN });
|
|
676
|
+
clip.drawRect(0, 0, 6, 6);
|
|
677
|
+
clip.endFill();
|
|
678
|
+
clip.beginGradientFill('radial', [0xff0000, 0x0000ff], [1, 1], [0, 255], { a: Infinity });
|
|
679
|
+
clip.drawRect(10, 0, 6, 6);
|
|
680
|
+
clip.endFill();
|
|
681
|
+
clip.beginGradientFill('linear', [0x004400, 0x008800], [1, 1], [0, 255], { a: 0.01, tx: 23 });
|
|
682
|
+
clip.drawRect(20, 0, 6, 6);
|
|
683
|
+
clip.endFill();
|
|
684
|
+
|
|
685
|
+
timeline.render();
|
|
686
|
+
expect(fills.map(fill => fill.fillStyle)).toEqual([
|
|
687
|
+
'rgba(0,0,0,0)', 'rgba(0,0,0,0)',
|
|
688
|
+
expect.objectContaining({ coordinates: [14.808, 0, 31.192, 0] }),
|
|
689
|
+
]);
|
|
690
|
+
} finally {
|
|
691
|
+
if (previousPath2D === undefined) delete globalThis.Path2D;
|
|
692
|
+
else globalThis.Path2D = previousPath2D;
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
it('renders beginBitmapFill from BitmapData with repeat and pattern transform', () => {
|
|
697
|
+
const previousPath2D = globalThis.Path2D;
|
|
698
|
+
const previousDOMMatrix = globalThis.DOMMatrix;
|
|
699
|
+
globalThis.Path2D = class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} };
|
|
700
|
+
globalThis.DOMMatrix = class { constructor(values) { this.values = values; } };
|
|
701
|
+
try {
|
|
702
|
+
const { ctx, fills } = drawingContext();
|
|
703
|
+
const { root, timeline } = createDrawingBundle(ctx);
|
|
704
|
+
const image = { width: 2, height: 2 };
|
|
705
|
+
const bitmapData = { _canvas: image };
|
|
706
|
+
const clip = root.createEmptyMovieClip('bitmap', 2);
|
|
707
|
+
clip.beginBitmapFill(bitmapData, { a: 0, b: 1, c: -1, d: 0, tx: 4, ty: 6 }, false, false);
|
|
708
|
+
clip.moveTo(0, 0); clip.lineTo(8, 0); clip.lineTo(8, 8); clip.endFill();
|
|
709
|
+
timeline.render();
|
|
710
|
+
|
|
711
|
+
expect(fills[0].fillStyle.image).toBe(image);
|
|
712
|
+
expect(fills[0].fillStyle.repeat).toBe('no-repeat');
|
|
713
|
+
expect(fills[0].fillStyle.transform).toEqual([0, 1, -1, 0, 4, 6]);
|
|
714
|
+
expect(ctx.imageSmoothingEnabled).toBe(true);
|
|
715
|
+
} finally {
|
|
716
|
+
if (previousPath2D === undefined) delete globalThis.Path2D;
|
|
717
|
+
else globalThis.Path2D = previousPath2D;
|
|
718
|
+
if (previousDOMMatrix === undefined) delete globalThis.DOMMatrix;
|
|
719
|
+
else globalThis.DOMMatrix = previousDOMMatrix;
|
|
720
|
+
}
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
it('paints and hit tests a nested pixel-hinted non-scaling stroke with square caps', () => {
|
|
724
|
+
const previousPath2D = globalThis.Path2D;
|
|
725
|
+
globalThis.Path2D = class {
|
|
726
|
+
commands = [];
|
|
727
|
+
moveTo(...point) { this.commands.push(['M', ...point]); }
|
|
728
|
+
lineTo(...point) { this.commands.push(['L', ...point]); }
|
|
729
|
+
};
|
|
730
|
+
try {
|
|
731
|
+
const { ctx, strokes } = drawingContext();
|
|
732
|
+
const { root, timeline } = createDrawingBundle(ctx);
|
|
733
|
+
const parent = root.attachMovie('linked.Symbol', 'holder', 8,
|
|
734
|
+
{ x: 10.4, y: 20.6, scaleX: 200, scaleY: 300 });
|
|
735
|
+
const clip = parent.createEmptyMovieClip('stroke', 2);
|
|
736
|
+
clip.lineStyle(2, 0xff0000, 100, true, 'none', 'square', 'bevel', 5);
|
|
737
|
+
clip.moveTo(0, 0); clip.lineTo(10, 0);
|
|
738
|
+
timeline.render();
|
|
739
|
+
|
|
740
|
+
expect(strokes).toHaveLength(1);
|
|
741
|
+
expect(strokes[0]).toMatchObject({
|
|
742
|
+
lineWidth: 2, lineCap: 'square', lineJoin: 'bevel', miterLimit: 5,
|
|
743
|
+
transform: [1, 0, 0, 1, 0, 0],
|
|
744
|
+
path: { commands: [['M', 10, 21], ['L', 30, 21]] },
|
|
745
|
+
});
|
|
746
|
+
expect(clip.hitTest(9.1, 21.9, true)).toBe(true);
|
|
747
|
+
expect(clip.hitTest(8.9, 21, true)).toBe(false);
|
|
748
|
+
expect(clip.hitTest(20, 19.9, true)).toBe(false);
|
|
749
|
+
expect(clip.hitTest(20, 21.9, true)).toBe(true);
|
|
750
|
+
} finally {
|
|
751
|
+
if (previousPath2D === undefined) delete globalThis.Path2D;
|
|
752
|
+
else globalThis.Path2D = previousPath2D;
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
|
|
756
|
+
it('keeps an AVM1 hairline one output pixel wide and disables it when lineStyle is omitted', () => {
|
|
757
|
+
const previousPath2D = globalThis.Path2D;
|
|
758
|
+
globalThis.Path2D = class {
|
|
759
|
+
commands = [];
|
|
760
|
+
moveTo(...point) { this.commands.push(['M', ...point]); }
|
|
761
|
+
lineTo(...point) { this.commands.push(['L', ...point]); }
|
|
762
|
+
};
|
|
763
|
+
try {
|
|
764
|
+
const { ctx, strokes } = drawingContext();
|
|
765
|
+
const { root, timeline } = createDrawingBundle(ctx);
|
|
766
|
+
const clip = root.createEmptyMovieClip('hairline', 2);
|
|
767
|
+
Object.assign(clip, { x: 10.4, y: 20.6, scaleX: 200, scaleY: 300 });
|
|
768
|
+
clip.lineStyle(0, 0, 100, true, 'normal', 'none');
|
|
769
|
+
clip.moveTo(0, 0); clip.lineTo(10, 0);
|
|
770
|
+
clip.lineStyle();
|
|
771
|
+
clip.lineTo(20, 0);
|
|
772
|
+
timeline.render();
|
|
773
|
+
expect(strokes).toHaveLength(1);
|
|
774
|
+
expect(strokes[0]).toMatchObject({
|
|
775
|
+
lineWidth: 1, transform: [1, 0, 0, 1, 0, 0],
|
|
776
|
+
path: { commands: [['M', 10, 20.5], ['L', 30, 20.5]] },
|
|
777
|
+
});
|
|
778
|
+
expect(clip.hitTest(20, 20.9, true)).toBe(true);
|
|
779
|
+
expect(clip.hitTest(20, 21.15, true)).toBe(false);
|
|
780
|
+
expect(clip.hitTest(35, 20.5, true)).toBe(false);
|
|
781
|
+
} finally {
|
|
782
|
+
if (previousPath2D === undefined) delete globalThis.Path2D;
|
|
783
|
+
else globalThis.Path2D = previousPath2D;
|
|
784
|
+
}
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
it.each([
|
|
788
|
+
['normal', [2, 0, 0, 3, 10, 20], true, true],
|
|
789
|
+
['horizontal', [1, 0, 0, 3, 10, 20], true, false],
|
|
790
|
+
['vertical', [2, 0, 0, 1, 10, 20], false, true],
|
|
791
|
+
['none', [1, 0, 0, 1, 0, 0], false, false],
|
|
792
|
+
])('uses %s scaling for the pen while keeping the path in stage coordinates',
|
|
793
|
+
(mode, transform, wideHorizontal, wideVertical) => {
|
|
794
|
+
const previousPath2D = globalThis.Path2D;
|
|
795
|
+
globalThis.Path2D = class { moveTo() {} lineTo() {} };
|
|
796
|
+
try {
|
|
797
|
+
const { ctx, strokes } = drawingContext();
|
|
798
|
+
const { root, timeline } = createDrawingBundle(ctx);
|
|
799
|
+
const clip = root.createEmptyMovieClip('stroke', 2);
|
|
800
|
+
Object.assign(clip, { x: 10, y: 20, scaleX: 200, scaleY: 300 });
|
|
801
|
+
clip.lineStyle(2, 0, 100, false, mode, 'none');
|
|
802
|
+
clip.moveTo(0, 0); clip.lineTo(10, 0);
|
|
803
|
+
clip.moveTo(10, 0); clip.lineTo(10, 10);
|
|
804
|
+
timeline.render();
|
|
805
|
+
|
|
806
|
+
expect(strokes).toHaveLength(2);
|
|
807
|
+
expect(strokes[0].transform.map(value => value || 0)).toEqual(transform);
|
|
808
|
+
expect(strokes[0]).toMatchObject({ lineWidth: 2, lineCap: 'butt', lineJoin: 'round', miterLimit: 3 });
|
|
809
|
+
expect(clip.hitTest(20, 22, true)).toBe(wideHorizontal);
|
|
810
|
+
expect(clip.hitTest(31.5, 35, true)).toBe(wideVertical);
|
|
811
|
+
expect(clip.hitTest(30, 49, true)).toBe(true);
|
|
812
|
+
expect(clip.hitTest(9.5, 20, true)).toBe(false);
|
|
813
|
+
} finally {
|
|
814
|
+
if (previousPath2D === undefined) delete globalThis.Path2D;
|
|
815
|
+
else globalThis.Path2D = previousPath2D;
|
|
816
|
+
}
|
|
817
|
+
});
|
|
818
|
+
|
|
819
|
+
it.each([
|
|
820
|
+
['round', undefined, false],
|
|
821
|
+
['bevel', undefined, false],
|
|
822
|
+
['miter', 1, false],
|
|
823
|
+
['miter', 2, true],
|
|
824
|
+
])('uses the %s join and its miter limit for hit testing', (join, limit, hit) => {
|
|
825
|
+
const { root } = createRuntime();
|
|
826
|
+
const clip = root.createEmptyMovieClip('corner', 2);
|
|
827
|
+
clip.lineStyle(4, 0, 100, false, 'normal', 'none', join, limit);
|
|
828
|
+
clip.moveTo(0, 4); clip.lineTo(10, 4); clip.lineTo(10, 14);
|
|
829
|
+
expect(hitTestAvm1ClipGeometry({}, clip, 11.7, 2.3)).toBe(hit);
|
|
830
|
+
expect(hitTestAvm1ClipGeometry({}, clip, 5, 9)).toBe(false);
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
it('renders root lineGradientStyle with gradient stops, alpha, spread, and matrix', () => {
|
|
834
|
+
const previousPath2D = globalThis.Path2D;
|
|
835
|
+
globalThis.Path2D = class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} };
|
|
836
|
+
try {
|
|
837
|
+
const { ctx, strokes } = drawingContext();
|
|
838
|
+
const { root, timeline } = createDrawingBundle(ctx);
|
|
839
|
+
const clip = root.createEmptyMovieClip('gradientStroke', 4);
|
|
840
|
+
clip.lineGradientStyle(3, 'linear', [0xff0000, 0x0000ff], [1, 0.25], [0, 255],
|
|
841
|
+
{ a: 1, b: 0, c: 0, d: 1, tx: 5, ty: 7 }, 'reflect', 'rgb');
|
|
842
|
+
clip.moveTo(0, 0); clip.lineTo(20, 10);
|
|
843
|
+
timeline.render();
|
|
844
|
+
|
|
845
|
+
expect(strokes).toHaveLength(1);
|
|
846
|
+
expect(strokes[0].lineWidth).toBe(3);
|
|
847
|
+
expect(strokes[0].strokeStyle.coordinates[0]).toBeCloseTo(-7367.8);
|
|
848
|
+
expect(strokes[0].strokeStyle.coordinates[1]).toBe(7);
|
|
849
|
+
expect(strokes[0].strokeStyle.stops.some((stop) => stop.color === 'rgba(255,0,0,1)')).toBe(true);
|
|
850
|
+
expect(strokes[0].strokeStyle.stops.some((stop) => stop.color === 'rgba(0,0,255,0.25)')).toBe(true);
|
|
851
|
+
} finally {
|
|
852
|
+
if (previousPath2D === undefined) delete globalThis.Path2D;
|
|
853
|
+
else globalThis.Path2D = previousPath2D;
|
|
854
|
+
}
|
|
855
|
+
});
|
|
856
|
+
|
|
857
|
+
it('renders nested radial lineGradientStyle in composed parent coordinates', () => {
|
|
858
|
+
const previousPath2D = globalThis.Path2D;
|
|
859
|
+
globalThis.Path2D = class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} };
|
|
860
|
+
try {
|
|
861
|
+
const { ctx, strokes } = drawingContext();
|
|
862
|
+
const { root, timeline, displayList } = createDrawingBundle(ctx);
|
|
863
|
+
const parent = root.attachMovie('linked.Symbol', 'holder', 4,
|
|
864
|
+
{ x: 10, y: 20, rotation: 90, scaleX: 200, scaleY: 200 });
|
|
865
|
+
expect([parent.x, parent.y, parent.rotation, parent.scaleX, parent.scaleY]).toEqual([10, 20, 90, 200, 200]);
|
|
866
|
+
const clip = parent.createEmptyMovieClip('radialStroke', 3);
|
|
867
|
+
clip.lineStyle(2, 0, 100, false, 'normal', 'none', 'bevel');
|
|
868
|
+
clip.lineGradientStyle(4, 'radial', [0x00ff00, 0x000000], [0.75, 1], [0, 255],
|
|
869
|
+
{ a: 1, b: 0, c: 0, d: 1, tx: 2, ty: 3 }, 'pad', 'rgb', 0.25);
|
|
870
|
+
clip.moveTo(0, 0); clip.lineTo(8, 8);
|
|
871
|
+
timeline.render();
|
|
872
|
+
|
|
873
|
+
const entry = displayList[clip._swoofDisplayDepth];
|
|
874
|
+
expect(entry.matrix.tx).toBe(200);
|
|
875
|
+
expect(entry.matrix.ty).toBe(400);
|
|
876
|
+
expect(strokes[0]).toMatchObject({ lineWidth: 4, lineCap: 'butt', lineJoin: 'bevel' });
|
|
877
|
+
expect(strokes[0].strokeStyle.coordinates.slice(0, 2)).toEqual([206.8, 3]);
|
|
878
|
+
expect(strokes[0].strokeStyle.stops[0].color).toBe('rgba(0,255,0,0.75)');
|
|
879
|
+
} finally {
|
|
880
|
+
if (previousPath2D === undefined) delete globalThis.Path2D;
|
|
881
|
+
else globalThis.Path2D = previousPath2D;
|
|
882
|
+
}
|
|
883
|
+
});
|
|
884
|
+
|
|
885
|
+
it('renders root lineBitmapStyle with BitmapData repeat and smoothing options', () => {
|
|
886
|
+
const previousPath2D = globalThis.Path2D;
|
|
887
|
+
const previousDOMMatrix = globalThis.DOMMatrix;
|
|
888
|
+
globalThis.Path2D = class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} };
|
|
889
|
+
globalThis.DOMMatrix = class { constructor(values) { this.values = values; } };
|
|
890
|
+
try {
|
|
891
|
+
const { ctx, strokes } = drawingContext();
|
|
892
|
+
const { root, timeline } = createDrawingBundle(ctx);
|
|
893
|
+
const image = { width: 4, height: 4 };
|
|
894
|
+
const clip = root.createEmptyMovieClip('bitmapStroke', 6);
|
|
895
|
+
clip.lineStyle(5, 0xffffff, 100, false, 'normal', 'square', 'miter', 7);
|
|
896
|
+
clip.lineBitmapStyle({ _canvas: image }, { a: 2, b: 0, c: 0, d: 2, tx: 4, ty: 8 }, true, false);
|
|
897
|
+
clip.moveTo(0, 0); clip.lineTo(10, 10);
|
|
898
|
+
timeline.render();
|
|
899
|
+
|
|
900
|
+
expect(strokes).toHaveLength(1);
|
|
901
|
+
expect(strokes[0]).toMatchObject({ lineWidth: 5, lineCap: 'square', lineJoin: 'miter', miterLimit: 7 });
|
|
902
|
+
expect(strokes[0].strokeStyle.image).toBe(image);
|
|
903
|
+
expect(strokes[0].strokeStyle.repeat).toBe('repeat');
|
|
904
|
+
expect(strokes[0].strokeStyle.transform).toEqual([2, 0, 0, 2, 4, 8]);
|
|
905
|
+
expect(ctx.imageSmoothingEnabled).toBe(true);
|
|
906
|
+
} finally {
|
|
907
|
+
if (previousPath2D === undefined) delete globalThis.Path2D;
|
|
908
|
+
else globalThis.Path2D = previousPath2D;
|
|
909
|
+
if (previousDOMMatrix === undefined) delete globalThis.DOMMatrix;
|
|
910
|
+
else globalThis.DOMMatrix = previousDOMMatrix;
|
|
911
|
+
}
|
|
912
|
+
});
|
|
913
|
+
|
|
914
|
+
it('renders nested lineBitmapStyle by asset id with parent transform', () => {
|
|
915
|
+
const previousPath2D = globalThis.Path2D;
|
|
916
|
+
const previousDOMMatrix = globalThis.DOMMatrix;
|
|
917
|
+
globalThis.Path2D = class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} };
|
|
918
|
+
globalThis.DOMMatrix = class { constructor(values) { this.values = values; } };
|
|
919
|
+
try {
|
|
920
|
+
const { ctx, strokes } = drawingContext();
|
|
921
|
+
const image = { width: 8, height: 8 };
|
|
922
|
+
const { root, timeline, displayList } = createDrawingBundle(ctx, { 19: image });
|
|
923
|
+
const parent = root.attachMovie('linked.Symbol', 'holder', 8,
|
|
924
|
+
{ x: 7, y: 11, rotation: 90, scaleX: 150, scaleY: 150 });
|
|
925
|
+
const clip = parent.createEmptyMovieClip('bitmapStroke', 2);
|
|
926
|
+
clip.lineStyle(2, 0xffffff);
|
|
927
|
+
clip.lineBitmapStyle(19, { a: 0, b: 1, c: -1, d: 0, tx: 3, ty: 4 }, false, true);
|
|
928
|
+
clip.moveTo(0, 0); clip.lineTo(10, 0);
|
|
929
|
+
timeline.render();
|
|
930
|
+
|
|
931
|
+
const entry = displayList[clip._swoofDisplayDepth];
|
|
932
|
+
expect(entry.matrix.tx).toBe(140);
|
|
933
|
+
expect(entry.matrix.ty).toBe(220);
|
|
934
|
+
expect(strokes[0].strokeStyle.image).toBe(image);
|
|
935
|
+
expect(strokes[0].strokeStyle.repeat).toBe('no-repeat');
|
|
936
|
+
expect(strokes[0].strokeStyle.transform).toEqual([0, 1, -1, 0, 3, 4]);
|
|
937
|
+
expect(strokes[0].lineWidth).toBe(2);
|
|
938
|
+
} finally {
|
|
939
|
+
if (previousPath2D === undefined) delete globalThis.Path2D;
|
|
940
|
+
else globalThis.Path2D = previousPath2D;
|
|
941
|
+
if (previousDOMMatrix === undefined) delete globalThis.DOMMatrix;
|
|
942
|
+
else globalThis.DOMMatrix = previousDOMMatrix;
|
|
943
|
+
}
|
|
944
|
+
});
|
|
945
|
+
|
|
946
|
+
it('repaints compiled bitmap fills and strokes from the same BitmapData display snapshot', () => {
|
|
947
|
+
function push(value) {
|
|
948
|
+
const data = typeof value === 'string'
|
|
949
|
+
? [0, ...Buffer.from(value), 0]
|
|
950
|
+
: [7, value & 255, value >> 8 & 255, value >> 16 & 255, value >>> 24];
|
|
951
|
+
return [0x96, data.length, 0, ...data];
|
|
952
|
+
}
|
|
953
|
+
const source = [...push('source'), 0x1c];
|
|
954
|
+
const call = (name, ...args) => [
|
|
955
|
+
...args.reverse().flatMap(arg => arg === 'source' ? source : push(arg)),
|
|
956
|
+
...push(args.length), ...push('this'), 0x1c, ...push(name), 0x52, 0x17,
|
|
957
|
+
];
|
|
958
|
+
const diagnostics = new DiagnosticsCollector();
|
|
959
|
+
const code = transpileAvm1(Uint8Array.from([
|
|
960
|
+
...call('beginBitmapFill', 'source'), ...call('drawRect', 0, 0, 10, 8), ...call('endFill'),
|
|
961
|
+
...call('lineStyle', 2), ...call('lineBitmapStyle', 'source'),
|
|
962
|
+
...call('moveTo', 0, 12), ...call('lineTo', 10, 12), 0,
|
|
963
|
+
]), diagnostics);
|
|
964
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
965
|
+
|
|
966
|
+
const { ctx, fills, strokes } = drawingContext();
|
|
967
|
+
const engine = generateTimelineEngine({ frames: [{ places: [] }], characters: {} }, { frameCount: 1 });
|
|
968
|
+
const { bitmap, render } = runInNewContext(`
|
|
969
|
+
var BACKGROUND = '#fff', STAGE_WIDTH = 100, STAGE_HEIGHT = 100, loaded = {};
|
|
970
|
+
${SWFLIB_SOURCE}
|
|
971
|
+
${AVM1_RUNTIME_STUB}
|
|
972
|
+
${engine}
|
|
973
|
+
var bitmap = new __swoof_swflib.builtins.BitmapData(4, 4, true, 0xffff0000);
|
|
974
|
+
var clip = root.createEmptyMovieClip('bitmapStyles', 6);
|
|
975
|
+
clip.source = bitmap;
|
|
976
|
+
runClipScript(clip, function () { ${code} });
|
|
977
|
+
({ bitmap, render: () => timeline.render() });
|
|
978
|
+
`, {
|
|
979
|
+
ctx, window: { __swoof: {} }, Path2D: class { moveTo() {} lineTo() {} closePath() {} },
|
|
980
|
+
document: {
|
|
981
|
+
createElement() {
|
|
982
|
+
return { getContext() { return this.width === 100 ? null : { fillRect() {}, drawImage() {} }; } };
|
|
983
|
+
},
|
|
984
|
+
getElementById: () => null,
|
|
985
|
+
},
|
|
986
|
+
});
|
|
987
|
+
render();
|
|
988
|
+
expect(fills.at(-1)?.fillStyle.image).toBe(bitmap._canvas);
|
|
989
|
+
expect(strokes.at(-1)?.strokeStyle.image).toBe(bitmap._canvas);
|
|
990
|
+
bitmap.lock();
|
|
991
|
+
render();
|
|
992
|
+
expect(bitmap._lockedDisplayImage).not.toBe(bitmap._canvas);
|
|
993
|
+
expect(fills.at(-1).fillStyle.image).toBe(bitmap._lockedDisplayImage);
|
|
994
|
+
expect(strokes.at(-1).strokeStyle.image).toBe(bitmap._lockedDisplayImage);
|
|
995
|
+
bitmap.unlock();
|
|
996
|
+
render();
|
|
997
|
+
expect(fills.at(-1).fillStyle.image).toBe(bitmap._canvas);
|
|
998
|
+
expect(strokes.at(-1).strokeStyle.image).toBe(bitmap._canvas);
|
|
999
|
+
});
|
|
1000
|
+
|
|
1001
|
+
it('draws, renders, and hit tests a rectangle with negative dimensions', () => {
|
|
1002
|
+
const previousPath2D = globalThis.Path2D;
|
|
1003
|
+
globalThis.Path2D = class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} };
|
|
1004
|
+
try {
|
|
1005
|
+
const { ctx, fills } = drawingContext();
|
|
1006
|
+
const { root, timeline } = createDrawingBundle(ctx);
|
|
1007
|
+
const clip = root.createEmptyMovieClip('rect', 9);
|
|
1008
|
+
clip.beginFill(0x123456, 100);
|
|
1009
|
+
clip.drawRect(10, 20, -8, -6);
|
|
1010
|
+
expect(clip._swoofDraws[0].path).toEqual([
|
|
1011
|
+
['M', 2, 14], ['L', 10, 14], ['L', 10, 20], ['L', 2, 20], ['Z'],
|
|
1012
|
+
]);
|
|
1013
|
+
expect(hitTestAvm1ClipGeometry({}, clip, 5, 17)).toBe(true);
|
|
1014
|
+
expect(hitTestAvm1ClipGeometry({}, clip, 12, 17)).toBe(false);
|
|
1015
|
+
timeline.render();
|
|
1016
|
+
expect(fills).toHaveLength(1);
|
|
1017
|
+
expect(fills[0].fillStyle).toBe('rgba(18,52,86,1)');
|
|
1018
|
+
} finally {
|
|
1019
|
+
if (previousPath2D === undefined) delete globalThis.Path2D;
|
|
1020
|
+
else globalThis.Path2D = previousPath2D;
|
|
1021
|
+
}
|
|
1022
|
+
});
|
|
1023
|
+
|
|
1024
|
+
it('draws nested rounded rectangles with clamped radii and parent transforms', () => {
|
|
1025
|
+
const previousPath2D = globalThis.Path2D;
|
|
1026
|
+
globalThis.Path2D = class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} };
|
|
1027
|
+
try {
|
|
1028
|
+
const { ctx, fills } = drawingContext();
|
|
1029
|
+
const { root, timeline, displayList } = createDrawingBundle(ctx);
|
|
1030
|
+
const parent = root.attachMovie('linked.Symbol', 'holder', 12,
|
|
1031
|
+
{ x: 10, y: 20, scaleX: 150, scaleY: 150 });
|
|
1032
|
+
const clip = parent.createEmptyMovieClip('rounded', 4);
|
|
1033
|
+
clip.beginFill(0xabcdef, 100);
|
|
1034
|
+
clip.drawRoundRect(10, 20, -8, -6, 100, 100);
|
|
1035
|
+
|
|
1036
|
+
expect(clip._swoofDraws[0].path).toEqual([
|
|
1037
|
+
['M', 6, 14], ['L', 6, 14], ['Q', 10, 14, 10, 17],
|
|
1038
|
+
['L', 10, 17], ['Q', 10, 20, 6, 20], ['L', 6, 20],
|
|
1039
|
+
['Q', 2, 20, 2, 17], ['L', 2, 17], ['Q', 2, 14, 6, 14], ['Z'],
|
|
1040
|
+
]);
|
|
1041
|
+
expect(hitTestAvm1ClipGeometry({}, clip, 17.5, 45.5)).toBe(true);
|
|
1042
|
+
expect(hitTestAvm1ClipGeometry({}, clip, 13.15, 41.15)).toBe(false);
|
|
1043
|
+
timeline.render();
|
|
1044
|
+
expect(displayList[clip._swoofDisplayDepth].matrix).toMatchObject({ tx: 200, ty: 400 });
|
|
1045
|
+
expect(fills).toHaveLength(1);
|
|
1046
|
+
} finally {
|
|
1047
|
+
if (previousPath2D === undefined) delete globalThis.Path2D;
|
|
1048
|
+
else globalThis.Path2D = previousPath2D;
|
|
1049
|
+
}
|
|
1050
|
+
});
|
|
1051
|
+
|
|
1052
|
+
it('draws and hit tests circles through the dynamic path painter', () => {
|
|
1053
|
+
const previousPath2D = globalThis.Path2D;
|
|
1054
|
+
globalThis.Path2D = class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} };
|
|
1055
|
+
try {
|
|
1056
|
+
const { ctx, fills } = drawingContext();
|
|
1057
|
+
const { root, timeline } = createDrawingBundle(ctx);
|
|
1058
|
+
const clip = root.createEmptyMovieClip('circle', 15);
|
|
1059
|
+
clip.beginFill(0x336699, 100);
|
|
1060
|
+
clip.drawCircle(10, 10, -5);
|
|
1061
|
+
|
|
1062
|
+
expect(clip._swoofDraws[0].path).toHaveLength(10);
|
|
1063
|
+
expect(clip._swoofDraws[0].path[0]).toEqual(['M', 15, 10]);
|
|
1064
|
+
expect(clip._swoofDraws[0].path.filter((command) => command[0] === 'Q')).toHaveLength(8);
|
|
1065
|
+
expect(hitTestAvm1ClipGeometry({}, clip, 10, 10)).toBe(true);
|
|
1066
|
+
expect(hitTestAvm1ClipGeometry({}, clip, 16, 10)).toBe(false);
|
|
1067
|
+
timeline.render();
|
|
1068
|
+
expect(fills).toHaveLength(1);
|
|
1069
|
+
} finally {
|
|
1070
|
+
if (previousPath2D === undefined) delete globalThis.Path2D;
|
|
1071
|
+
else globalThis.Path2D = previousPath2D;
|
|
1072
|
+
}
|
|
1073
|
+
});
|
|
1074
|
+
|
|
1075
|
+
it('draws and hit tests nested ellipses with negative dimensions', () => {
|
|
1076
|
+
const previousPath2D = globalThis.Path2D;
|
|
1077
|
+
globalThis.Path2D = class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} };
|
|
1078
|
+
try {
|
|
1079
|
+
const { ctx, fills } = drawingContext();
|
|
1080
|
+
const { root, timeline, displayList } = createDrawingBundle(ctx);
|
|
1081
|
+
const parent = root.attachMovie('linked.Symbol', 'holder', 18,
|
|
1082
|
+
{ x: 10, y: 20, rotation: 90, scaleX: 150, scaleY: 150 });
|
|
1083
|
+
const clip = parent.createEmptyMovieClip('ellipse', 6);
|
|
1084
|
+
clip.beginFill(0xcc6633, 100);
|
|
1085
|
+
clip.drawEllipse(10, 10, -8, 4);
|
|
1086
|
+
|
|
1087
|
+
expect(clip._swoofDraws[0].path[0]).toEqual(['M', 10, 12]);
|
|
1088
|
+
expect(clip._swoofDraws[0].path.filter((command) => command[0] === 'Q')).toHaveLength(8);
|
|
1089
|
+
expect(hitTestAvm1ClipGeometry({}, clip, -8, 29)).toBe(true);
|
|
1090
|
+
expect(hitTestAvm1ClipGeometry({}, clip, 10, 29)).toBe(false);
|
|
1091
|
+
timeline.render();
|
|
1092
|
+
expect(displayList[clip._swoofDisplayDepth].matrix).toMatchObject({ tx: 200, ty: 400 });
|
|
1093
|
+
expect(fills).toHaveLength(1);
|
|
1094
|
+
} finally {
|
|
1095
|
+
if (previousPath2D === undefined) delete globalThis.Path2D;
|
|
1096
|
+
else globalThis.Path2D = previousPath2D;
|
|
1097
|
+
}
|
|
1098
|
+
});
|
|
1099
|
+
|
|
1100
|
+
it('draws root complex rounded rectangles with four independent corner radii', () => {
|
|
1101
|
+
const previousPath2D = globalThis.Path2D;
|
|
1102
|
+
globalThis.Path2D = class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} };
|
|
1103
|
+
try {
|
|
1104
|
+
const { ctx, fills } = drawingContext();
|
|
1105
|
+
const { root, timeline } = createDrawingBundle(ctx);
|
|
1106
|
+
const clip = root.createEmptyMovieClip('complexRound', 22);
|
|
1107
|
+
clip.beginFill(0x778899, 100);
|
|
1108
|
+
clip.drawRoundRectComplex(0, 0, 100, 60, 10, 20, 30, 5);
|
|
1109
|
+
|
|
1110
|
+
expect(clip._swoofDraws[0].path).toEqual([
|
|
1111
|
+
['M', 10, 0], ['L', 80, 0], ['Q', 100, 0, 100, 20], ['L', 100, 55],
|
|
1112
|
+
['Q', 100, 60, 95, 60], ['L', 30, 60], ['Q', 0, 60, 0, 30],
|
|
1113
|
+
['L', 0, 10], ['Q', 0, 0, 10, 0], ['Z'],
|
|
1114
|
+
]);
|
|
1115
|
+
expect(hitTestAvm1ClipGeometry({}, clip, 50, 30)).toBe(true);
|
|
1116
|
+
expect(hitTestAvm1ClipGeometry({}, clip, 0.5, 0.5)).toBe(false);
|
|
1117
|
+
timeline.render();
|
|
1118
|
+
expect(fills).toHaveLength(1);
|
|
1119
|
+
} finally {
|
|
1120
|
+
if (previousPath2D === undefined) delete globalThis.Path2D;
|
|
1121
|
+
else globalThis.Path2D = previousPath2D;
|
|
1122
|
+
}
|
|
1123
|
+
});
|
|
1124
|
+
|
|
1125
|
+
it('normalizes oversized roundRectComplex radii and keeps nested transforms', () => {
|
|
1126
|
+
const previousPath2D = globalThis.Path2D;
|
|
1127
|
+
globalThis.Path2D = class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} };
|
|
1128
|
+
try {
|
|
1129
|
+
const { ctx, fills } = drawingContext();
|
|
1130
|
+
const { root, timeline, displayList } = createDrawingBundle(ctx);
|
|
1131
|
+
const parent = root.attachMovie('linked.Symbol', 'holder', 24,
|
|
1132
|
+
{ x: 5, y: 7, scaleX: 200, scaleY: 200 });
|
|
1133
|
+
const clip = parent.createEmptyMovieClip('complexRound', 3);
|
|
1134
|
+
clip.beginFill(0x998877, 100);
|
|
1135
|
+
clip.drawRoundRectComplex(20, 10, -40, 20, 40, 40, 40, 40);
|
|
1136
|
+
|
|
1137
|
+
expect(clip._swoofDraws[0].path).toEqual([
|
|
1138
|
+
['M', -10, 10], ['L', 10, 10], ['Q', 20, 10, 20, 20], ['L', 20, 20],
|
|
1139
|
+
['Q', 20, 30, 10, 30], ['L', -10, 30], ['Q', -20, 30, -20, 20],
|
|
1140
|
+
['L', -20, 20], ['Q', -20, 10, -10, 10], ['Z'],
|
|
1141
|
+
]);
|
|
1142
|
+
expect(hitTestAvm1ClipGeometry({}, clip, 5, 47)).toBe(true);
|
|
1143
|
+
timeline.render();
|
|
1144
|
+
expect(displayList[clip._swoofDisplayDepth].matrix).toMatchObject({ tx: 100, ty: 140 });
|
|
1145
|
+
expect(fills).toHaveLength(1);
|
|
1146
|
+
} finally {
|
|
1147
|
+
if (previousPath2D === undefined) delete globalThis.Path2D;
|
|
1148
|
+
else globalThis.Path2D = previousPath2D;
|
|
1149
|
+
}
|
|
1150
|
+
});
|
|
1151
|
+
});
|