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,41 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import * as acorn from 'acorn';
|
|
3
|
+
import { readFileSync, readdirSync, statSync } from 'fs';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
import { parse } from '../../parser/swf-parser.js';
|
|
6
|
+
import { decode } from '../../decoder/tag-decoder.js';
|
|
7
|
+
import { transpileActionScript } from '../../transpiler/actionscript.js';
|
|
8
|
+
import { DiagnosticsCollector } from '../../util/diagnostics.js';
|
|
9
|
+
|
|
10
|
+
function collectSwfs(dir) {
|
|
11
|
+
const files = [];
|
|
12
|
+
for (const entry of readdirSync(dir)) {
|
|
13
|
+
const p = join(dir, entry);
|
|
14
|
+
if (statSync(p).isDirectory()) files.push(...collectSwfs(p));
|
|
15
|
+
else if (p.endsWith('.swf')) files.push(p);
|
|
16
|
+
}
|
|
17
|
+
return files.sort();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const swfFiles = collectSwfs('archive/Swf');
|
|
21
|
+
|
|
22
|
+
describe('SWF corpus parse, decode, and ActionScript transpilation', () => {
|
|
23
|
+
it.each(swfFiles)('parses, decodes, and emits valid ES2020 ActionScript for %s', async (filePath) => {
|
|
24
|
+
const bytes = new Uint8Array(readFileSync(filePath));
|
|
25
|
+
const diag = new DiagnosticsCollector();
|
|
26
|
+
|
|
27
|
+
const { doc } = await parse(bytes, diag);
|
|
28
|
+
expect(doc.header).toBeTruthy();
|
|
29
|
+
expect(doc.tags.length).toBeGreaterThan(0);
|
|
30
|
+
|
|
31
|
+
const { tags, symbolTable } = decode(doc, diag);
|
|
32
|
+
expect(tags.length).toBe(doc.tags.length);
|
|
33
|
+
expect(symbolTable.ids().length).toBeGreaterThanOrEqual(0);
|
|
34
|
+
|
|
35
|
+
const asResult = transpileActionScript(tags, diag);
|
|
36
|
+
expect(diag.errors()).toHaveLength(0);
|
|
37
|
+
expect(asResult.avm1Scripts.length + asResult.avm2Blocks.length).toBeGreaterThan(0);
|
|
38
|
+
|
|
39
|
+
expect(() => acorn.parse(asResult.fullJs, { ecmaVersion: 2020 })).not.toThrow();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
3
|
+
|
|
4
|
+
const swf = Uint8Array.of(0x43, 0x57, 0x53, 10, 8, 0, 0, 0);
|
|
5
|
+
|
|
6
|
+
function runtimeWithImage(Image, URL) {
|
|
7
|
+
return new Function('Image', 'URL', `${SWFLIB_SOURCE}\nreturn __swoof_swflib;`)(Image, URL);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function nextEvent(target, type) {
|
|
11
|
+
return new Promise(resolve => target.addEventListener(type, resolve));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe('Loader.loadBytes', () => {
|
|
15
|
+
it('uses the compiled linkage until the payload changes and materializes original bytes only on demand', async () => {
|
|
16
|
+
const decode = vi.fn(atob);
|
|
17
|
+
const runtime = new Function('atob', `${SWFLIB_SOURCE}\nreturn __swoof_swflib;`)(decode);
|
|
18
|
+
const { ByteArray, Event, IOErrorEvent, Loader, MovieClip } = runtime.builtins;
|
|
19
|
+
const factory = vi.fn(() => new MovieClip());
|
|
20
|
+
const entry = runtime.registerCompiledSwf(Buffer.from(swf).toString('base64'), swf.length, swf[3], factory);
|
|
21
|
+
class Payload extends ByteArray {}
|
|
22
|
+
Payload.__swoofQualifiedName = 'sample.Embedded';
|
|
23
|
+
runtime.setLinkedBinaryData([['sample.Embedded', entry]]);
|
|
24
|
+
const original = new Payload();
|
|
25
|
+
original.position = 3;
|
|
26
|
+
const loader = new Loader();
|
|
27
|
+
const info = loader.contentLoaderInfo;
|
|
28
|
+
const complete = nextEvent(info, Event.COMPLETE);
|
|
29
|
+
loader.loadBytes(original);
|
|
30
|
+
await complete;
|
|
31
|
+
expect(factory).toHaveBeenCalledOnce();
|
|
32
|
+
expect(info.bytes.length).toBe(swf.length);
|
|
33
|
+
expect(info.swfVersion).toBe(10);
|
|
34
|
+
expect(original.position).toBe(3);
|
|
35
|
+
expect(decode).not.toHaveBeenCalled();
|
|
36
|
+
|
|
37
|
+
expect(original.readUnsignedByte()).toBe(10);
|
|
38
|
+
expect(decode).toHaveBeenCalledOnce();
|
|
39
|
+
const changed = new Payload();
|
|
40
|
+
changed._getU8()[3] = 99;
|
|
41
|
+
expect(info.bytes[3]).toBe(10);
|
|
42
|
+
expect(new Payload()[3]).toBe(10);
|
|
43
|
+
const error = nextEvent(info, IOErrorEvent.IO_ERROR);
|
|
44
|
+
loader.loadBytes(changed);
|
|
45
|
+
expect((await error).text).toMatch(/No compiled embedded SWF/);
|
|
46
|
+
expect(factory).toHaveBeenCalledOnce();
|
|
47
|
+
|
|
48
|
+
const copied = new ByteArray();
|
|
49
|
+
copied.writeBytes(swf);
|
|
50
|
+
const copiedComplete = nextEvent(info, Event.COMPLETE);
|
|
51
|
+
loader.loadBytes(copied);
|
|
52
|
+
await copiedComplete;
|
|
53
|
+
expect(factory).toHaveBeenCalledTimes(2);
|
|
54
|
+
expect(decode).toHaveBeenCalledOnce();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('attaches an exactly matched SWF and exposes its definitions in the requested domain', async () => {
|
|
58
|
+
const runtime = runtimeWithImage();
|
|
59
|
+
const { ApplicationDomain, ByteArray, Event, Loader, LoaderContext, MovieClip } = runtime.builtins;
|
|
60
|
+
const main = ApplicationDomain.currentDomain;
|
|
61
|
+
const child = new ApplicationDomain(main);
|
|
62
|
+
const context = new LoaderContext(false, child);
|
|
63
|
+
context.parameters = { level: '2' };
|
|
64
|
+
const loader = new Loader();
|
|
65
|
+
const info = loader.contentLoaderInfo;
|
|
66
|
+
const events = [];
|
|
67
|
+
info.addEventListener(Event.OPEN, () => events.push('open'));
|
|
68
|
+
info.addEventListener(Event.INIT, () => events.push('init'));
|
|
69
|
+
info.addEventListener(Event.COMPLETE, () => events.push('complete'));
|
|
70
|
+
loader.addEventListener(Event.COMPLETE, () => events.push('loader complete'));
|
|
71
|
+
|
|
72
|
+
const bytes = new ByteArray();
|
|
73
|
+
bytes.writeBytes(swf);
|
|
74
|
+
bytes.position = 3;
|
|
75
|
+
class NestedSymbol extends MovieClip {}
|
|
76
|
+
const registrationBytes = swf.slice();
|
|
77
|
+
runtime.registerEmbeddedSwf(registrationBytes, ({ applicationDomain, loader: owner, loaderInfo }) => {
|
|
78
|
+
expect(applicationDomain).toBe(child);
|
|
79
|
+
expect(loaderInfo).toBe(info);
|
|
80
|
+
expect(owner).toBe(loader);
|
|
81
|
+
expect(loaderInfo.content).toBeNull();
|
|
82
|
+
expect(loaderInfo.parameters).toEqual({ level: '2' });
|
|
83
|
+
expect(loaderInfo.bytes._getU8()).toEqual(swf);
|
|
84
|
+
expect(loaderInfo.bytesLoaded).toBe(0);
|
|
85
|
+
expect(applicationDomain.getDefinition('flash.display.MovieClip')).toBe(MovieClip);
|
|
86
|
+
applicationDomain._registerDefinition('nested.Symbol', NestedSymbol);
|
|
87
|
+
return new NestedSymbol();
|
|
88
|
+
});
|
|
89
|
+
registrationBytes[3] = 99;
|
|
90
|
+
|
|
91
|
+
const complete = nextEvent(info, Event.COMPLETE);
|
|
92
|
+
loader.loadBytes(bytes, context);
|
|
93
|
+
expect(loader.content).toBeNull();
|
|
94
|
+
await complete;
|
|
95
|
+
expect(events).toEqual(['open', 'init', 'complete', 'loader complete']);
|
|
96
|
+
expect(loader.content).toBeInstanceOf(NestedSymbol);
|
|
97
|
+
expect(loader.content.parent).toBe(loader);
|
|
98
|
+
expect(loader.content.root).toBe(loader.content);
|
|
99
|
+
expect(loader.content.loaderInfo).toBe(info);
|
|
100
|
+
expect(loader.getChildAt(0)).toBe(loader.content);
|
|
101
|
+
expect(info.bytesLoaded).toBe(swf.length);
|
|
102
|
+
expect(info.swfVersion).toBe(10);
|
|
103
|
+
expect(info.applicationDomain.getDefinition('nested::Symbol')).toBe(NestedSymbol);
|
|
104
|
+
expect(main.hasDefinition('nested.Symbol')).toBe(false);
|
|
105
|
+
expect(new ApplicationDomain(main).hasDefinition('nested.Symbol')).toBe(false);
|
|
106
|
+
expect(bytes.position).toBe(3);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('signals IO_ERROR for unmatched bytes and factories that fail', async () => {
|
|
110
|
+
const runtime = runtimeWithImage();
|
|
111
|
+
const { Event, IOErrorEvent, Loader } = runtime.builtins;
|
|
112
|
+
const loader = new Loader();
|
|
113
|
+
const info = loader.contentLoaderInfo;
|
|
114
|
+
const complete = vi.fn();
|
|
115
|
+
info.addEventListener(Event.COMPLETE, complete);
|
|
116
|
+
runtime.registerEmbeddedSwf(swf, async () => { throw new Error('factory failed'); });
|
|
117
|
+
|
|
118
|
+
const unmatched = swf.slice();
|
|
119
|
+
unmatched[3]++;
|
|
120
|
+
const missing = nextEvent(info, IOErrorEvent.IO_ERROR);
|
|
121
|
+
loader.loadBytes(unmatched);
|
|
122
|
+
expect((await missing).text).toMatch(/no compiled embedded SWF/i);
|
|
123
|
+
const failed = nextEvent(info, IOErrorEvent.IO_ERROR);
|
|
124
|
+
loader.loadBytes(swf);
|
|
125
|
+
expect((await failed).text).toBe('factory failed');
|
|
126
|
+
expect(complete).not.toHaveBeenCalled();
|
|
127
|
+
expect(loader.content).toBeNull();
|
|
128
|
+
expect(loader.numChildren).toBe(0);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('uses the loading movie domain as the default parent and suppresses closed loads', async () => {
|
|
132
|
+
const runtime = runtimeWithImage();
|
|
133
|
+
const { ApplicationDomain, Event, IOErrorEvent, Loader, MovieClip } = runtime.builtins;
|
|
134
|
+
const archive = new MovieClip();
|
|
135
|
+
archive.root = archive;
|
|
136
|
+
const enclosingDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
|
|
137
|
+
archive.loaderInfo = { applicationDomain: enclosingDomain };
|
|
138
|
+
const loader = new Loader();
|
|
139
|
+
archive.addChild(loader);
|
|
140
|
+
const info = loader.contentLoaderInfo;
|
|
141
|
+
const finish = vi.fn();
|
|
142
|
+
info.addEventListener(Event.COMPLETE, finish);
|
|
143
|
+
info.addEventListener(IOErrorEvent.IO_ERROR, finish);
|
|
144
|
+
let resolveFactory;
|
|
145
|
+
runtime.registerEmbeddedSwf(swf, () => new Promise(resolve => { resolveFactory = resolve; }));
|
|
146
|
+
|
|
147
|
+
loader.loadBytes(swf);
|
|
148
|
+
expect(info.applicationDomain.parentDomain).toBe(enclosingDomain);
|
|
149
|
+
await Promise.resolve();
|
|
150
|
+
loader.close();
|
|
151
|
+
const staleContent = new MovieClip();
|
|
152
|
+
staleContent._swoofStopTimelineAudio = vi.fn();
|
|
153
|
+
resolveFactory(staleContent);
|
|
154
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
155
|
+
expect(staleContent._swoofStopTimelineAudio).toHaveBeenCalledOnce();
|
|
156
|
+
expect(finish).not.toHaveBeenCalled();
|
|
157
|
+
expect(loader.content).toBeNull();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('honors the code-import option while leaving image loading available', async () => {
|
|
161
|
+
const pendingImages = [];
|
|
162
|
+
class Image {
|
|
163
|
+
constructor() { pendingImages.push(this); this.naturalWidth = 2; this.naturalHeight = 5; }
|
|
164
|
+
}
|
|
165
|
+
const URL = { createObjectURL: vi.fn(() => 'blob:fixture'), revokeObjectURL: vi.fn() };
|
|
166
|
+
const runtime = runtimeWithImage(Image, URL);
|
|
167
|
+
const { Bitmap, Event, Loader, LoaderContext } = runtime.builtins;
|
|
168
|
+
const context = new LoaderContext();
|
|
169
|
+
context.allowLoadBytesCodeExecution = false;
|
|
170
|
+
expect(context.allowCodeImport).toBe(false);
|
|
171
|
+
const factory = vi.fn();
|
|
172
|
+
runtime.registerEmbeddedSwf(swf, factory);
|
|
173
|
+
const loader = new Loader();
|
|
174
|
+
expect(() => loader.loadBytes(swf, context)).toThrow(/prohibits importing SWF code/);
|
|
175
|
+
expect(factory).not.toHaveBeenCalled();
|
|
176
|
+
|
|
177
|
+
const loaded = nextEvent(loader.contentLoaderInfo, Event.COMPLETE);
|
|
178
|
+
loader.loadBytes(Uint8Array.of(0x89, 0x50), context);
|
|
179
|
+
expect(pendingImages[0].src).toBe('blob:fixture');
|
|
180
|
+
pendingImages[0].onload();
|
|
181
|
+
await loaded;
|
|
182
|
+
expect(loader.content).toBeInstanceOf(Bitmap);
|
|
183
|
+
expect(loader.content.bitmapData.height).toBe(5);
|
|
184
|
+
expect(URL.revokeObjectURL).toHaveBeenCalledWith('blob:fixture');
|
|
185
|
+
|
|
186
|
+
loader.load({ url: 'image.png' });
|
|
187
|
+
expect(pendingImages[1].src).toBe('image.png');
|
|
188
|
+
pendingImages[1].onload();
|
|
189
|
+
expect(loader.content.bitmapData._img).toBe(pendingImages[1]);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('keeps linked byte data on the local constructor when names are shared across domains', () => {
|
|
193
|
+
const runtime = runtimeWithImage();
|
|
194
|
+
const { ByteArray } = runtime.builtins;
|
|
195
|
+
class MainPayload extends ByteArray {}
|
|
196
|
+
class ChildPayload extends ByteArray {}
|
|
197
|
+
class OrdinarySubclass extends ChildPayload {}
|
|
198
|
+
MainPayload.__swoofQualifiedName = ChildPayload.__swoofQualifiedName = 'assets.Payload';
|
|
199
|
+
ChildPayload.__swoofBinaryData = 'AgM=';
|
|
200
|
+
runtime.setLinkedBinaryData([['assets.Payload', Uint8Array.of(1)]]);
|
|
201
|
+
|
|
202
|
+
const child = new ChildPayload();
|
|
203
|
+
expect(new MainPayload()._getU8()).toEqual(Uint8Array.of(1));
|
|
204
|
+
expect(child._getU8()).toEqual(Uint8Array.of(2, 3));
|
|
205
|
+
expect(ChildPayload.__swoofBinaryData).toBeInstanceOf(Uint8Array);
|
|
206
|
+
child[0] = 0;
|
|
207
|
+
expect(new ChildPayload()._getU8()).toEqual(Uint8Array.of(2, 3));
|
|
208
|
+
expect(new OrdinarySubclass().length).toBe(0);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { AVM1_RUNTIME_STUB, SWFLIB_SOURCE } from '../runtime/index.js';
|
|
3
|
+
import { decodeTag } from '../decoder/tag-decoder.js';
|
|
4
|
+
import { TAG } from '../decoder/tag-types.js';
|
|
5
|
+
import { SymbolTable } from '../decoder/symbol-table.js';
|
|
6
|
+
import { buildDisplayList } from '../transpiler/timeline/display-list.js';
|
|
7
|
+
|
|
8
|
+
function makeRuntime() {
|
|
9
|
+
return new Function(`${SWFLIB_SOURCE}\nreturn __swoof_swflib;`)();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe('root LoaderInfo', () => {
|
|
13
|
+
it('shares typed loader metadata with the document and its rooted descendants', () => {
|
|
14
|
+
const { builtins: { ApplicationDomain, LoaderInfo, MovieClip, Sprite }, stage } = makeRuntime();
|
|
15
|
+
const info = stage.loaderInfo;
|
|
16
|
+
const stageChild = stage.addChild(new Sprite());
|
|
17
|
+
expect(stage.root).toBe(stage);
|
|
18
|
+
expect(stageChild.loaderInfo).toBe(info);
|
|
19
|
+
const main = new MovieClip();
|
|
20
|
+
main.loaderInfo = info;
|
|
21
|
+
main.root = main;
|
|
22
|
+
stage.addChild(main);
|
|
23
|
+
const child = main.addChild(new Sprite());
|
|
24
|
+
info._configureRootLoad({ width: 720, height: 480, frameRate: 30, swfVersion: 10, bytesTotal: 0x12345678 });
|
|
25
|
+
|
|
26
|
+
expect(info).toBeInstanceOf(LoaderInfo);
|
|
27
|
+
expect(LoaderInfo(info)).toBe(info);
|
|
28
|
+
expect(main.loaderInfo).toBe(info);
|
|
29
|
+
expect(child.loaderInfo).toBe(info);
|
|
30
|
+
expect(child.root.loaderInfo).toBe(info);
|
|
31
|
+
expect(main.removeChild(child).loaderInfo).toBeNull();
|
|
32
|
+
expect(info).toMatchObject({
|
|
33
|
+
width: 720, height: 480, frameRate: 30, swfVersion: 10,
|
|
34
|
+
bytesLoaded: 0, bytesTotal: 0x12345678, applicationDomain: ApplicationDomain.currentDomain,
|
|
35
|
+
});
|
|
36
|
+
expect(Array.from(info.bytes._getU8())).toEqual([70, 87, 83, 10, 0x78, 0x56, 0x34, 0x12]);
|
|
37
|
+
expect(info.bytes.position).toBe(0);
|
|
38
|
+
expect(main.getBytesLoaded()).toBe(0);
|
|
39
|
+
expect(main.getBytesTotal()).toBe(0x12345678);
|
|
40
|
+
info._completeRootLoad(main);
|
|
41
|
+
expect(main.getBytesLoaded()).toBe(0x12345678);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('sends typed final progress, initialization and completion once with ready content', () => {
|
|
45
|
+
const { builtins: { Event, MovieClip, ProgressEvent }, stage } = makeRuntime();
|
|
46
|
+
const info = stage.loaderInfo;
|
|
47
|
+
const main = new MovieClip();
|
|
48
|
+
info._configureRootLoad({ width: 1, height: 1, frameRate: 24, bytesTotal: 0x80000000 });
|
|
49
|
+
const received = [];
|
|
50
|
+
const record = (event) => received.push({ type: event.type, target: event.target, content: info.content, event: event.clone() });
|
|
51
|
+
info.addEventListener(ProgressEvent.PROGRESS, record);
|
|
52
|
+
info.addEventListener(Event.INIT, record);
|
|
53
|
+
info.addEventListener(Event.COMPLETE, record);
|
|
54
|
+
info._completeRootLoad(main);
|
|
55
|
+
info._completeRootLoad(main);
|
|
56
|
+
|
|
57
|
+
expect(received.map(({ type }) => type)).toEqual([ProgressEvent.PROGRESS, Event.INIT, Event.COMPLETE]);
|
|
58
|
+
expect(received.every(({ target, content }) => target === info && content === main)).toBe(true);
|
|
59
|
+
expect(received[0].event).toBeInstanceOf(ProgressEvent);
|
|
60
|
+
expect(received[0].event).toMatchObject({ bytesLoaded: 0x80000000, bytesTotal: 0x80000000 });
|
|
61
|
+
expect(info.bytesLoaded).toBe(info.bytesTotal);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('reports the compiled AVM1 root and nested sprite byte lengths', () => {
|
|
65
|
+
const sprite = decodeTag({
|
|
66
|
+
code: TAG.DefineSprite,
|
|
67
|
+
data: Uint8Array.of(7, 0, 1, 0, 0x40, 0, 0, 0),
|
|
68
|
+
});
|
|
69
|
+
const symbols = new SymbolTable();
|
|
70
|
+
symbols.set(7, sprite);
|
|
71
|
+
const { characters } = buildDisplayList([{ type: 'ShowFrame' }], symbols);
|
|
72
|
+
const getCounts = new Function('CHARACTERS', '__swoof_root', `${AVM1_RUNTIME_STUB}
|
|
73
|
+
const sprite = _clip(7);
|
|
74
|
+
const empty = createMovieClip('empty');
|
|
75
|
+
return [root, sprite, empty].map(clip => [clip.getBytesLoaded(), clip.getBytesTotal(), clip.framesLoaded]);
|
|
76
|
+
`);
|
|
77
|
+
expect(getCounts(characters, { _swoofSourceBytes: 40000, totalFrames: 300 })).toEqual([
|
|
78
|
+
[40000, 40000, 300], [4, 4, 1], [0, 0, 1],
|
|
79
|
+
]);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { createContext, runInContext } from 'node:vm';
|
|
2
|
+
import { expect, it } from 'vitest';
|
|
3
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
4
|
+
import { AVM1_RUNTIME_STUB, transpileAvm1 } from '../transpiler/avm1/avm1-transpiler.js';
|
|
5
|
+
|
|
6
|
+
function mount(url = 'https://games.example.test/index.html') {
|
|
7
|
+
const pending = [];
|
|
8
|
+
const sandbox = createContext({ URL, location: new URL(url), setTimeout: callback => pending.push(callback) });
|
|
9
|
+
const runtime = runInContext(`${SWFLIB_SOURCE}\n__swoof_swflib;`, sandbox);
|
|
10
|
+
return { runtime, sandbox, drain() { while (pending.length) pending.shift()(); } };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
it('delivers AMF snapshots asynchronously to the assigned AS3 client and reports typed status', () => {
|
|
14
|
+
const { runtime, drain } = mount();
|
|
15
|
+
const { LocalConnection, StatusEvent, AsyncErrorEvent } = runtime.builtins;
|
|
16
|
+
expect(runtime.packages.net.LocalConnection).toBe(LocalConnection);
|
|
17
|
+
expect(runtime.packages.events.StatusEvent).toBe(StatusEvent);
|
|
18
|
+
const calls = [];
|
|
19
|
+
class Client {
|
|
20
|
+
receive(message, alias) { calls.push([this, message.label, message === alias, message === message.self]); }
|
|
21
|
+
fail() { throw new Error('client failure'); }
|
|
22
|
+
}
|
|
23
|
+
const receiver = new LocalConnection();
|
|
24
|
+
const sender = new LocalConnection();
|
|
25
|
+
receiver.client = new Client();
|
|
26
|
+
receiver.connect('messages');
|
|
27
|
+
expect(receiver.domain).toBe('games.example.test');
|
|
28
|
+
expect(() => sender.connect('messages')).toThrow(/already in use/);
|
|
29
|
+
const status = [], errors = [];
|
|
30
|
+
sender.addEventListener(StatusEvent.STATUS, event => status.push([event instanceof StatusEvent, event.level]));
|
|
31
|
+
receiver.addEventListener(AsyncErrorEvent.ASYNC_ERROR, event => errors.push(event.error.message));
|
|
32
|
+
const message = { label: 'before' };
|
|
33
|
+
message.self = message;
|
|
34
|
+
sender.send('GAMES.EXAMPLE.TEST:messages', 'receive', message, message);
|
|
35
|
+
message.label = 'after';
|
|
36
|
+
sender.send('messages', 'fail');
|
|
37
|
+
expect(calls).toEqual([]);
|
|
38
|
+
expect(status).toEqual([]);
|
|
39
|
+
drain();
|
|
40
|
+
expect(calls).toEqual([[receiver.client, 'before', true, true]]);
|
|
41
|
+
expect(errors).toEqual(['client failure']);
|
|
42
|
+
expect(status).toEqual([[true, 'status'], [true, 'status']]);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('separates page registries, validates names and payloads, and keeps queued calls off replacement connections', () => {
|
|
46
|
+
const { runtime, drain } = mount();
|
|
47
|
+
const { LocalConnection } = runtime.builtins;
|
|
48
|
+
const otherPage = mount();
|
|
49
|
+
const receiver = new LocalConnection(), sender = new LocalConnection(), replacement = new LocalConnection();
|
|
50
|
+
const levels = [], invoked = [];
|
|
51
|
+
sender.addEventListener('status', event => levels.push(event.level));
|
|
52
|
+
receiver.client = { get getter() { invoked.push('getter'); return () => {}; }, call() { invoked.push('receiver'); } };
|
|
53
|
+
receiver.connect('_channel');
|
|
54
|
+
expect(() => receiver.connect('another')).toThrow(/already in use/);
|
|
55
|
+
expect(() => replacement.connect('other.example.test:channel')).toThrow(/colon/);
|
|
56
|
+
expect(() => sender.send('_channel', 'constructor')).toThrow(/Restricted/);
|
|
57
|
+
expect(() => sender.send('_channel', 'call', 'x'.repeat(41000))).toThrow(/40 KiB/);
|
|
58
|
+
sender.send('_channel', 'getter');
|
|
59
|
+
sender.send('other.example.test:channel', 'call');
|
|
60
|
+
drain();
|
|
61
|
+
expect(levels).toEqual(['error', 'error']);
|
|
62
|
+
expect(invoked).toEqual([]);
|
|
63
|
+
sender.send('_channel', 'call');
|
|
64
|
+
receiver.close();
|
|
65
|
+
replacement.client = { call() { invoked.push('replacement'); } };
|
|
66
|
+
replacement.connect('_channel');
|
|
67
|
+
new otherPage.runtime.builtins.LocalConnection().connect('_channel');
|
|
68
|
+
drain();
|
|
69
|
+
expect(invoked).toEqual([]);
|
|
70
|
+
expect(levels.at(-1)).toBe('error');
|
|
71
|
+
sender.send('_channel', 'call');
|
|
72
|
+
drain();
|
|
73
|
+
expect(invoked).toEqual(['replacement']);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('shares AVM1-created registrations with AS3 and supports legacy callbacks and results', () => {
|
|
77
|
+
const { runtime, sandbox, drain } = mount('file:///game/index.html');
|
|
78
|
+
const push = [...Buffer.from([0, ...Buffer.from('receiver'), 0, 7, 0, 0, 0, 0, 0]), ...Buffer.from('LocalConnection'), 0];
|
|
79
|
+
const js = transpileAvm1(Uint8Array.from([0x96, push.length, 0, ...push, 0x40, 0x1d, 0]));
|
|
80
|
+
const receiver = runInContext(`${AVM1_RUNTIME_STUB}\n(function () { ${js} }).call(root);\nroot.receiver;`, sandbox);
|
|
81
|
+
const sender = new runtime.builtins.LocalConnection();
|
|
82
|
+
const legacySender = new runtime.Avm1LocalConnection();
|
|
83
|
+
const status = [], results = [], domains = [];
|
|
84
|
+
sender.addEventListener('status', event => status.push(event.level));
|
|
85
|
+
legacySender.onStatus = event => status.push(event.level);
|
|
86
|
+
receiver.read = value => results.push(value);
|
|
87
|
+
receiver.allowDomain = host => { domains.push(host); return false; };
|
|
88
|
+
expect(receiver.domain()).toBe('localhost');
|
|
89
|
+
expect(receiver.connect('_legacy')).toBe(true);
|
|
90
|
+
expect(legacySender.connect('_legacy')).toBe(false);
|
|
91
|
+
sender.send('_legacy', 'read', 'denied');
|
|
92
|
+
drain();
|
|
93
|
+
receiver.allowDomain = () => true;
|
|
94
|
+
expect(legacySender.send('_legacy', 'read', 'legacy')).toBe(true);
|
|
95
|
+
expect(legacySender.send('_missing', 'read')).toBe(true);
|
|
96
|
+
expect(legacySender.send('_legacy', 'onStatus')).toBe(false);
|
|
97
|
+
sender.send('_legacy', 'read', 'modern');
|
|
98
|
+
drain();
|
|
99
|
+
expect(domains).toEqual(['localhost']);
|
|
100
|
+
expect(status).toEqual(['error', 'status', 'error', 'status']);
|
|
101
|
+
expect(results).toEqual(['legacy', 'modern']);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('requires distinct authorization for a sender from an insecure or different domain', () => {
|
|
105
|
+
const { runtime, sandbox, drain } = mount();
|
|
106
|
+
const { LocalConnection } = runtime.builtins;
|
|
107
|
+
const receiver = new LocalConnection();
|
|
108
|
+
const calls = [], levels = [];
|
|
109
|
+
receiver.client = { receive: value => calls.push(value) };
|
|
110
|
+
receiver.connect('_insecure');
|
|
111
|
+
sandbox.location = new URL('http://sender.example.test/index.html');
|
|
112
|
+
const sender = new LocalConnection();
|
|
113
|
+
sender.addEventListener('status', event => levels.push(event.level));
|
|
114
|
+
receiver.allowDomain('*');
|
|
115
|
+
sender.send('_insecure', 'receive', 'denied');
|
|
116
|
+
drain();
|
|
117
|
+
receiver.allowInsecureDomain('sender.example.test');
|
|
118
|
+
sender.send('_insecure', 'receive', 'allowed');
|
|
119
|
+
drain();
|
|
120
|
+
expect(levels).toEqual(['error', 'status']);
|
|
121
|
+
expect(calls).toEqual(['allowed']);
|
|
122
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { decodeMorphShape } from '../decoder/shape-decoder.js';
|
|
3
|
+
|
|
4
|
+
function byteAligned(bits) {
|
|
5
|
+
return bits.match(/.{1,8}/g).map(part => parseInt(part.padEnd(8, '0'), 2));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function translation(x, y) {
|
|
9
|
+
const signedByte = value => (value & 255).toString(2).padStart(8, '0');
|
|
10
|
+
return byteAligned('00' + '01000' + signedByte(x) + signedByte(y));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function focalMorph({ stroke = false } = {}) {
|
|
14
|
+
const gradient = [
|
|
15
|
+
0x13, ...translation(40, -20), ...translation(-60, 80),
|
|
16
|
+
0x52, // reflect spread, linear RGB, two paired stops
|
|
17
|
+
5, 255, 0, 0, 255, 10, 0, 0, 255, 255,
|
|
18
|
+
240, 0, 255, 0, 255, 250, 255, 255, 0, 255,
|
|
19
|
+
0x80, 0xff, 0xc0, 0x00, // focal -0.5 to +0.75
|
|
20
|
+
];
|
|
21
|
+
const styles = stroke
|
|
22
|
+
? [0, 1, 20, 0, 40, 0, 0x08, 0, ...gradient]
|
|
23
|
+
: [1, ...gradient, 0];
|
|
24
|
+
const edge = (vertical, delta) => '11' + '0100' + '0' + vertical + (delta & 63).toString(2).padStart(6, '0');
|
|
25
|
+
const rectangle = edge(0, 20) + edge(1, 20) + edge(0, -20) + edge(1, -20);
|
|
26
|
+
const startEdges = [stroke ? 0x01 : 0x10, ...byteAligned((stroke ? '0010001' : '0001001') + rectangle + '000000')];
|
|
27
|
+
const endEdges = [0, ...byteAligned(rectangle + '000000')];
|
|
28
|
+
const offset = Buffer.alloc(4);
|
|
29
|
+
offset.writeUInt32LE(styles.length + startEdges.length);
|
|
30
|
+
return Uint8Array.from([
|
|
31
|
+
1, 0, 0x08, 0, 0x08, 0, 0x08, 0, 0x08, 0, 0,
|
|
32
|
+
...offset, ...styles, ...startEdges, ...endEdges,
|
|
33
|
+
]);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe('MorphShape2 focal radial gradient decoding', () => {
|
|
37
|
+
it.each([false, true])('preserves endpoint matrices, paired stops and signed focal points (stroke: %s)', stroke => {
|
|
38
|
+
const morph = decodeMorphShape(focalMorph({ stroke }), 2);
|
|
39
|
+
const start = stroke ? morph.startDraws[0].stroke.fill : morph.startDraws[0].fill;
|
|
40
|
+
const end = stroke ? morph.endDraws[0].stroke.fill : morph.endDraws[0].fill;
|
|
41
|
+
const common = { type: 'radial', spreadMode: 1, interpolationMode: 1 };
|
|
42
|
+
expect(start).toEqual({
|
|
43
|
+
...common, matrix: { a: 1, d: 1, b: 0, c: 0, tx: 2, ty: -1 }, focal: -0.5,
|
|
44
|
+
stops: [{ ratio: 5, color: '#ff0000' }, { ratio: 240, color: '#00ff00' }],
|
|
45
|
+
});
|
|
46
|
+
expect(end).toEqual({
|
|
47
|
+
...common, matrix: { a: 1, d: 1, b: 0, c: 0, tx: -3, ty: 4 }, focal: 0.75,
|
|
48
|
+
stops: [{ ratio: 10, color: '#0000ff' }, { ratio: 250, color: '#ffff00' }],
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|