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,37 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { parseProjectJson, serializeProject } from './src/project-io.js';
|
|
4
|
+
import { acceptsPointer, eventKey, matchesRelease } from './src/interaction-triggers.js';
|
|
5
|
+
|
|
6
|
+
const doc = action => parseProjectJson(JSON.stringify({
|
|
7
|
+
stage: { width: 480, height: 320, frameRate: 24 },
|
|
8
|
+
scenes: [{ elements: [{ type: 'rectangle', buttonAction: { type: 'stop', ...action } }] }],
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
test('authored key and touch triggers round-trip with their typed action', () => {
|
|
12
|
+
for (const fields of [{ trigger: 'click' }, { trigger: 'keyDown', key: 'A' }, { trigger: 'keyUp', key: 'Space' },
|
|
13
|
+
{ trigger: 'touchTap' }, { trigger: 'swipe', direction: 'up' }]) {
|
|
14
|
+
const project = doc(fields);
|
|
15
|
+
assert.deepEqual(project.scenes[0].elements[0].buttonAction, { ...fields, type: 'stop', target: null });
|
|
16
|
+
assert.deepEqual(parseProjectJson(serializeProject(project)), project);
|
|
17
|
+
}
|
|
18
|
+
assert.equal(doc({}).scenes[0].elements[0].buttonAction.trigger, 'click');
|
|
19
|
+
for (const invalid of [{ trigger: 'invalid' }, { trigger: 'keyUp' }, { trigger: 'keyDown', key: 'Tab' },
|
|
20
|
+
{ trigger: 'swipe' }, { trigger: 'swipe', direction: 'elsewhere' }]) assert.throws(() => doc(invalid));
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('touch taps cancel after a drag and directional swipes require sufficient travel on their axis', () => {
|
|
24
|
+
const press = { x: 100, y: 100, travel: 0, pointerType: 'touch' };
|
|
25
|
+
const release = (trigger, x, y, sameTarget = true, travel = 0) => matchesRelease(trigger, { ...press, travel },
|
|
26
|
+
{ clientX: x, clientY: y, pointerType: 'touch' }, sameTarget);
|
|
27
|
+
assert.ok(release({ trigger: 'touchTap' }, 102, 103));
|
|
28
|
+
assert.equal(release({ trigger: 'touchTap' }, 100, 100, true, 16), false);
|
|
29
|
+
assert.equal(release({ trigger: 'touchTap' }, 102, 103, false), false);
|
|
30
|
+
const right = { trigger: 'swipe', direction: 'right' };
|
|
31
|
+
assert.ok(release(right, 142, 101, false));
|
|
32
|
+
for (const [x, y] of [[108, 100], [55, 100], [140, 160]]) assert.equal(release(right, x, y), false);
|
|
33
|
+
assert.equal(acceptsPointer(right, 'mouse'), false);
|
|
34
|
+
assert.equal(acceptsPointer({ trigger: 'keyDown' }, 'touch'), false);
|
|
35
|
+
assert.equal(eventKey({ key: ' ' }), 'Space');
|
|
36
|
+
assert.equal(eventKey({ key: 'q' }), 'Q');
|
|
37
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { decode } from '../swf2js/decoder/tag-decoder.js';
|
|
4
|
+
import { buildSwf } from '../swf2js/encoder/swf-builder.js';
|
|
5
|
+
import { parse } from '../swf2js/parser/swf-parser.js';
|
|
6
|
+
import { decodeButton } from '../swf2js/decoder/button-decoder.js';
|
|
7
|
+
import { transpileActionScript } from '../swf2js/transpiler/actionscript.js';
|
|
8
|
+
import { OP } from '../swf2js/transpiler/avm1/avm1-opcodes.js';
|
|
9
|
+
import { DiagnosticsCollector } from '../swf2js/util/diagnostics.js';
|
|
10
|
+
import { standaloneLinkedActions } from './server/linked-actions.js';
|
|
11
|
+
|
|
12
|
+
const jump = (start, target) => [OP.Jump, 2, 0, (target - start - 5) & 255, (target - start - 5) >> 8 & 255];
|
|
13
|
+
|
|
14
|
+
function execute(bytes) {
|
|
15
|
+
const diagnostics = new DiagnosticsCollector();
|
|
16
|
+
const { fullJs } = transpileActionScript([{ type: 'DoAction', bytecode: bytes }], diagnostics, { swfVersion: 8 });
|
|
17
|
+
assert.deepEqual(diagnostics.errors(), []);
|
|
18
|
+
return new Function(`var FRAME_SCRIPTS = [];
|
|
19
|
+
${fullJs}
|
|
20
|
+
FRAME_SCRIPTS[0][0].call(root); return root.count;`)();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
for (const entry of [40000, 140000]) {
|
|
24
|
+
it(`executes a button and clip handler with an entry at byte ${entry} after native export`, async () => {
|
|
25
|
+
const source = new Uint8Array(entry + 6);
|
|
26
|
+
// Start at the handler, follow jumps back through each 20 KB of the carrier,
|
|
27
|
+
// then execute the first assignment. Entering at zero would set count to 1.
|
|
28
|
+
const assign = value => [OP.Push, 12, 0, 0, 99, 111, 117, 110, 116, 0, 7, value, 0, 0, 0, OP.SetVariable];
|
|
29
|
+
source.set([...assign(1), OP.End]);
|
|
30
|
+
source.set([...assign(7), OP.End], 40);
|
|
31
|
+
for (let at = entry; at >= 20000; at -= 20000) source.set(jump(at, at === 20000 ? 40 : at - 20000), at);
|
|
32
|
+
const bytes = standaloneLinkedActions(source, entry);
|
|
33
|
+
assert.equal(execute(bytes), 7);
|
|
34
|
+
const place = { characterId: 9, depth: 1 };
|
|
35
|
+
const button = { type: 'button', buttonStates: {}, actions: [{ conditions: { overDownToOverUp: true }, bytes }] };
|
|
36
|
+
const frame = { places: [place], removes: [] };
|
|
37
|
+
const { bytes: swf } = buildSwf({ version: 8, frameSize: { xMin: 0, yMin: 0, xMax: 4000, yMax: 4000 }, frameRate: 12,
|
|
38
|
+
displayList: { frames: [frame], characters: { 9: button } }, compress: false,
|
|
39
|
+
tags: [{ type: 'PlaceObject2', ...place, clipActions: [{ eventFlags: 1, bytecode: bytes }] }, { type: 'ShowFrame' }] });
|
|
40
|
+
const diagnostics = new DiagnosticsCollector();
|
|
41
|
+
const { doc } = await parse(swf, diagnostics);
|
|
42
|
+
const { tags, symbolTable } = decode(doc, diagnostics);
|
|
43
|
+
const placed = tags.find(tag => tag.type === 'PlaceObject2');
|
|
44
|
+
assert.equal(execute(placed.clipActions[0].bytecode), 7);
|
|
45
|
+
const action = decodeButton(symbolTable.get(9).rawData).actions[0];
|
|
46
|
+
assert.equal(execute(action.bytecode), 7);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// Lottie export and import (studiospec/lottie.md): keyframes and eases, time remapping, the
|
|
2
|
+
// transform mapping, reading Lottie files, scene flow, and files that are not to be trusted.
|
|
3
|
+
import { describe, it } from 'node:test';
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
import { EASES, STEP, animatedProperty, gzipBase64, lottieHash, lottieTransformValues, timeRemap } from './src/lottie-export.js';
|
|
6
|
+
import { importLottie, readLottieText, studioPose, valueAt } from './src/lottie-import.js';
|
|
7
|
+
import { parseProjectJson } from './src/project-io.js';
|
|
8
|
+
import { applyEasing } from './src/model.js';
|
|
9
|
+
|
|
10
|
+
const close = (actual, expected, epsilon, label) => assert.ok(Math.abs(actual - expected) <= epsilon, `${label}: ${actual} is near ${expected}`);
|
|
11
|
+
const sv = value => ({ a: 0, k: value });
|
|
12
|
+
const ks = (fields = {}) => ({ a: sv([0, 0, 0]), p: sv([0, 0, 0]), s: sv([100, 100, 100]), r: sv(0), o: sv(100), ...fields });
|
|
13
|
+
const rect = (w, h, color = [1, 0, 0, 1]) => ({ ty: 'gr', it: [
|
|
14
|
+
{ ty: 'rc', d: 1, s: sv([w, h]), p: sv([0, 0]), r: sv(0) },
|
|
15
|
+
{ ty: 'fl', c: sv(color), o: sv(100), r: 1 },
|
|
16
|
+
{ ty: 'tr', p: sv([0, 0]), a: sv([0, 0]), s: sv([100, 100]), r: sv(0), o: sv(100), sk: sv(0), sa: sv(0) }] });
|
|
17
|
+
const shapeLayer = (name, shapes, fields = {}) => ({ ddd: 0, ty: 4, nm: name, sr: 1, ip: 0, op: 24, st: 0, bm: 0, ks: ks(), shapes, ...fields });
|
|
18
|
+
const movie = (layers, fields = {}) => ({ v: '5.7.4', fr: 24, ip: 0, op: 24, w: 400, h: 300, layers, assets: [], ...fields });
|
|
19
|
+
const load = async (lottie, options) => {
|
|
20
|
+
const result = await importLottie(JSON.stringify(lottie), options);
|
|
21
|
+
return { ...result, project: parseProjectJson(result.json) };
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
describe('Lottie keyframes', () => {
|
|
25
|
+
it('writes a value that never changes as a static property', () => {
|
|
26
|
+
assert.deepEqual(animatedProperty(() => [5], [{ frame: 1, tween: 'linear' }, { frame: 10 }], v => v[0]), { a: 0, k: 5 });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('writes each Studio ease as one keyframe whose curve reproduces every frame', () => {
|
|
30
|
+
for (const tween of ['linear', 'easeIn', 'easeOut', 'easeInOut']) {
|
|
31
|
+
const at = frame => [100 * applyEasing(tween, (frame - 1) / 20)];
|
|
32
|
+
const property = animatedProperty(at, [{ frame: 1, tween }, { frame: 21 }], v => v[0]);
|
|
33
|
+
assert.equal(property.k.length, tween === 'easeInOut' ? 3 : 2, tween);
|
|
34
|
+
if (tween !== 'easeInOut') assert.deepEqual(property.k[0].o, { x: EASES[tween].o[0], y: EASES[tween].o[1] });
|
|
35
|
+
for (let frame = 1; frame <= 21; frame++) close(valueAt(property, frame - 1), at(frame)[0], 0.05, `${tween} at ${frame}`);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('keeps a hold keyframe a jump, just before the next key', () => {
|
|
40
|
+
const at = frame => [frame < 6 ? 0 : 50];
|
|
41
|
+
const property = animatedProperty(at, [{ frame: 1, tween: 'hold' }, { frame: 6, tween: 'linear' }, { frame: 10 }], v => v[0]);
|
|
42
|
+
assert.ok(property.k.some(key => Math.abs(key.t - (5 - STEP)) < 1e-9 && key.h === 1));
|
|
43
|
+
assert.equal(valueAt(property, 4), 0);
|
|
44
|
+
assert.equal(valueAt(property, 5), 50);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('writes a span that follows no ease frame by frame', () => {
|
|
48
|
+
const values = [0, 9, 1, 8, 2, 7];
|
|
49
|
+
const property = animatedProperty(frame => [values[frame - 1]], [{ frame: 1, tween: 'linear' }, { frame: 6 }], v => v[0]);
|
|
50
|
+
values.forEach((value, k) => close(valueAt(property, k), value, 1e-6, `frame ${k + 1}`));
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('maps a symbol\'s frames to time remapping that gives them back, jumps and holds included', () => {
|
|
54
|
+
const frames = [1, 2, 3, 4, 2, 3, 3, 3, 9];
|
|
55
|
+
const tm = timeRemap(frames, 1, 24);
|
|
56
|
+
frames.forEach((frame, k) => assert.equal(Math.round(valueAt(tm, k) * 24) + 1, frame, `frame ${k + 1}`));
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('Lottie transforms', () => {
|
|
61
|
+
it('reads rotation, skew, scale and a flip back from a matrix', () => {
|
|
62
|
+
const pose = { x: 30, y: 40, rotation: 25, skew: 15, scaleX: 1.5, scaleY: 0.75, mirror: true };
|
|
63
|
+
const values = lottieTransformValues(pose);
|
|
64
|
+
const r = values.r * Math.PI / 180, sk = values.sk * Math.PI / 180;
|
|
65
|
+
// Lottie: translate, rotate, skew (sa 0), scale.
|
|
66
|
+
const R = [Math.cos(r), Math.sin(r), -Math.sin(r), Math.cos(r)];
|
|
67
|
+
const K = [1, 0, -Math.tan(sk), 1];
|
|
68
|
+
const S = [values.s[0] / 100, 0, 0, values.s[1] / 100];
|
|
69
|
+
const mul = (m, n) => [m[0] * n[0] + m[2] * n[1], m[1] * n[0] + m[3] * n[1], m[0] * n[2] + m[2] * n[3], m[1] * n[2] + m[3] * n[3]];
|
|
70
|
+
const [a, b, c, d] = mul(mul(R, K), S);
|
|
71
|
+
const back = studioPose([a, b, c, d, values.p[0], values.p[1]]);
|
|
72
|
+
for (const key of ['x', 'y', 'rotation', 'skew', 'scaleX', 'scaleY']) close(back[key], pose[key], 1e-6, key);
|
|
73
|
+
assert.equal(back.mirror, true);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('unwraps rotation against the previous frame', () => {
|
|
77
|
+
const turn = angle => [Math.cos(angle * Math.PI / 180), Math.sin(angle * Math.PI / 180), -Math.sin(angle * Math.PI / 180), Math.cos(angle * Math.PI / 180), 0, 0];
|
|
78
|
+
close(studioPose(turn(-170), { rotation: 175 }).rotation, 190, 1e-6, 'rotation');
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('Lottie import', () => {
|
|
83
|
+
it('tells Lottie from Studio projects and other JSON', () => {
|
|
84
|
+
assert.ok(readLottieText(JSON.stringify(movie([]))));
|
|
85
|
+
assert.equal(readLottieText('{"format":"swoof-studio","layers":[]}'), null);
|
|
86
|
+
assert.equal(readLottieText('{"layers": not json'), null);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('refuses JSON that is not a Lottie animation', async () => {
|
|
90
|
+
await assert.rejects(importLottie('{"w": 10}'), /not a Lottie animation/);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('reads shapes, keyframed motion, ellipses, opacity and the background solid', async () => {
|
|
94
|
+
const moving = shapeLayer('Box', [rect(40, 20)], {
|
|
95
|
+
ks: ks({ p: { a: 1, k: [{ t: 0, s: [100, 100, 0], o: { x: 0.3333, y: 0.3333 }, i: { x: 0.6667, y: 0.6667 } }, { t: 23, s: [300, 100, 0] }] }, o: sv(50) }) });
|
|
96
|
+
const ellipse = shapeLayer('Dot', [{ ty: 'gr', it: [{ ty: 'el', d: 1, s: sv([30, 30]), p: sv([0, 0]) }, { ty: 'fl', c: sv([0, 0, 1, 1]), o: sv(100) }, { ty: 'tr', p: sv([0, 0]), a: sv([0, 0]), s: sv([100, 100]), r: sv(0), o: sv(100) }] }],
|
|
97
|
+
{ ks: ks({ p: sv([50, 60, 0]) }) });
|
|
98
|
+
const solid = { ddd: 0, ty: 1, nm: 'Bg', sr: 1, ip: 0, op: 24, st: 0, bm: 0, ks: ks(), sw: 400, sh: 300, sc: '#123456' };
|
|
99
|
+
const { project, notes, exact } = await load(movie([moving, ellipse, solid]));
|
|
100
|
+
assert.equal(exact, false);
|
|
101
|
+
assert.deepEqual(notes, []);
|
|
102
|
+
assert.equal(project.stage.background, '#123456');
|
|
103
|
+
const [dot, box] = project.scenes[0].elements;
|
|
104
|
+
assert.equal(dot.type, 'ellipse');
|
|
105
|
+
assert.equal(dot.fill, '#0000ff');
|
|
106
|
+
assert.deepEqual([dot.x, dot.y, dot.width], [50, 60, 30]);
|
|
107
|
+
assert.equal(box.type, 'rectangle');
|
|
108
|
+
assert.equal(box.opacity, 0.5);
|
|
109
|
+
assert.deepEqual(box.keyframes.map(key => [key.frame, key.x]), [[1, 100], [24, 300]]);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('shows a layer only between its in and out points', async () => {
|
|
113
|
+
const { project } = await load(movie([shapeLayer('Late', [rect(10, 10)], { ip: 5, op: 12 })]));
|
|
114
|
+
const keys = project.scenes[0].elements[0].keyframes;
|
|
115
|
+
assert.deepEqual([keys[0].frame, keys[0].blank, keys[1].frame, keys[1].blank], [1, true, 6, undefined]);
|
|
116
|
+
assert.deepEqual([keys.at(-1).frame, keys.at(-1).blank], [13, true]);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('scales an animation smaller than Studio\'s stage up to fit it', async () => {
|
|
120
|
+
const { project, notes } = await load(movie([shapeLayer('Box', [rect(10, 10)], { ks: ks({ p: sv([50, 50, 0]) }) })], { w: 100, h: 100 }));
|
|
121
|
+
assert.deepEqual([project.stage.width, project.stage.height], [160, 160]);
|
|
122
|
+
const box = project.scenes[0].elements[0];
|
|
123
|
+
assert.deepEqual([box.x, box.y, box.scaleX], [80, 80, 1.6]);
|
|
124
|
+
assert.match(notes.join(), /scaled to 160 × 160/);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('turns precomps into symbols that loop as their time remapping says', async () => {
|
|
128
|
+
const inner = [shapeLayer('Spin', [rect(20, 20)], { op: 6, ks: ks({ r: { a: 1, k: [{ t: 0, s: [0], o: { x: 0.3333, y: 0.3333 }, i: { x: 0.6667, y: 0.6667 } }, { t: 5, s: [90] }] } }) })];
|
|
129
|
+
const loopFrames = Array.from({ length: 24 }, (_, k) => (k % 6) + 1);
|
|
130
|
+
const lottie = movie([{ ddd: 0, ty: 0, nm: 'Spinner', refId: 'comp_0', sr: 1, ip: 0, op: 24, st: 0, bm: 0, w: 200, h: 200, ks: ks({ p: sv([200, 150, 0]), a: sv([100, 100, 0]) }),
|
|
131
|
+
tm: timeRemap(loopFrames, 1, 24) }], { assets: [{ id: 'comp_0', nm: 'Spinner', layers: inner }] });
|
|
132
|
+
const { project } = await load(lottie);
|
|
133
|
+
const instance = project.scenes[0].elements[0];
|
|
134
|
+
assert.equal(instance.type, 'symbol');
|
|
135
|
+
assert.equal(instance.symbolMode, 'loop');
|
|
136
|
+
assert.deepEqual([instance.x, instance.y], [200, 150]);
|
|
137
|
+
assert.equal(project.symbols[0].durationFrames, 6);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('turns a track matte into a Studio mask', async () => {
|
|
141
|
+
const matte = shapeLayer('Matte', [rect(50, 50)], { td: 1, ind: 1 });
|
|
142
|
+
const target = shapeLayer('Target', [rect(200, 200, [0, 1, 0, 1])], { tt: 1, ind: 2 });
|
|
143
|
+
const { project } = await load(movie([matte, target]));
|
|
144
|
+
const [mask, shown] = project.scenes[0].elements;
|
|
145
|
+
assert.equal(shown.maskId, mask.id);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('reads blur and shadows, and a shadow that does not move as a glow', async () => {
|
|
149
|
+
const effect = (ty, values) => ({ ty, nm: 'fx', en: 1, ef: Object.entries(values).map(([nm, v]) => ({ nm, v: sv(v) })) });
|
|
150
|
+
const { project } = await load(movie([
|
|
151
|
+
shapeLayer('Blurred', [rect(10, 10)], { ef: [effect(29, { Blurriness: 10 })] }),
|
|
152
|
+
shapeLayer('Glowing', [rect(10, 10)], { ef: [effect(25, { 'Shadow Color': [1, 1, 0, 1], Opacity: 255, Direction: 135, Distance: 0, Softness: 8 })] }),
|
|
153
|
+
]));
|
|
154
|
+
const [glowing, blurred] = project.scenes[0].elements;
|
|
155
|
+
assert.equal(blurred.effect.type, 'blur');
|
|
156
|
+
assert.equal(glowing.effect.type, 'glow');
|
|
157
|
+
assert.equal(glowing.effect.color, '#ffff00');
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
describe('Lottie from Studio', () => {
|
|
162
|
+
it('rebuilds scene order, transitions and the loop from the main timeline', async () => {
|
|
163
|
+
const scene = name => ({ id: `scene_${name}`, nm: name, layers: [shapeLayer(name, [rect(10, 10)], { op: 10 })] });
|
|
164
|
+
const segment = (name, ip, op, st) => ({ ddd: 0, ty: 0, nm: name, refId: `scene_${name}`, sr: 1, ip, op, st, bm: 0, w: 400, h: 300, ks: ks() });
|
|
165
|
+
const transition = { ...segment('A', 10, 13, 0), nm: 'A (transition)', tm: sv(9 / 24),
|
|
166
|
+
ks: ks({ o: { a: 1, k: [0, 1, 2].map(k => ({ t: 10 + k, s: [(1 - applyEasing('easeOut', k / 3)) * 100], h: 1 })) } }) };
|
|
167
|
+
const lottie = movie([transition, segment('B', 10, 20, 10), segment('A', 0, 10, 0)], { op: 20, assets: [scene('A'), scene('B')] });
|
|
168
|
+
const { project } = await load(lottie);
|
|
169
|
+
const [a, b] = project.scenes;
|
|
170
|
+
assert.deepEqual(a.events, [{ trigger: 'frameEnter', frame: 11, actions: [{ type: 'gotoScene', target: b.id, play: true }] }]);
|
|
171
|
+
assert.equal(a.durationFrames, 11, 'scene A gets a frame for the jump after its last');
|
|
172
|
+
assert.deepEqual(b.transition, { type: 'crossfade', durationFrames: 3, easing: 'easeOut' });
|
|
173
|
+
assert.equal(b.events?.[0]?.actions[0].type, 'gotoScene', 'the movie loops back to the first scene');
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('reads Studio\'s own project back exactly, unless the Lottie was changed', async () => {
|
|
177
|
+
const project = JSON.stringify({ format: 'swoof-studio', version: 1, stage: { width: 400, height: 300, frameRate: 24, background: '#ffffff' }, assets: [],
|
|
178
|
+
scenes: [{ id: 's', name: 'S', durationFrames: 1, startFrame: 1, loop: false, layers: [{ id: 'l', name: 'L', visible: true, locked: false, order: 0 }], elements: [] }] });
|
|
179
|
+
const lottie = movie([shapeLayer('Box', [rect(10, 10)])]);
|
|
180
|
+
lottie.studio = { format: 'swoof-studio-lottie', version: 1, hash: lottieHash(lottie), project: await gzipBase64(project) };
|
|
181
|
+
const same = await importLottie(JSON.stringify(lottie));
|
|
182
|
+
assert.equal(same.exact, true);
|
|
183
|
+
assert.equal(same.json, project);
|
|
184
|
+
lottie.layers[0].nm = 'Edited';
|
|
185
|
+
const changed = await importLottie(JSON.stringify(lottie));
|
|
186
|
+
assert.equal(changed.exact, false);
|
|
187
|
+
assert.match(changed.notes.join(), /changed after Studio wrote it/);
|
|
188
|
+
assert.equal(JSON.parse(changed.json).scenes[0].elements[0].name, 'Edited');
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe('Untrusted Lottie files', () => {
|
|
193
|
+
it('stops at precomps that contain themselves', async () => {
|
|
194
|
+
const loop = { ddd: 0, ty: 0, nm: 'Self', refId: 'comp_0', sr: 1, ip: 0, op: 24, st: 0, bm: 0, w: 200, h: 200, ks: ks() };
|
|
195
|
+
const { notes } = await load(movie([loop], { assets: [{ id: 'comp_0', layers: [loop] }] }));
|
|
196
|
+
assert.match(notes.join(), /contain themselves/);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('never fetches linked images and never runs expressions', async () => {
|
|
200
|
+
const image = { ddd: 0, ty: 2, nm: 'Remote', refId: 'img', sr: 1, ip: 0, op: 24, st: 0, bm: 0, ks: ks() };
|
|
201
|
+
const scripted = shapeLayer('Scripted', [rect(10, 10)], { ks: ks({ p: { a: 0, k: [10, 20, 0], x: 'throw new Error("ran")' } }) });
|
|
202
|
+
const { project, notes } = await load(movie([image, scripted], { assets: [{ id: 'img', w: 10, h: 10, u: 'https://example.com/', p: 'a.png' }] }));
|
|
203
|
+
assert.equal(project.assets?.length ?? 0, 0);
|
|
204
|
+
assert.match(notes.join(), /linked from outside/);
|
|
205
|
+
assert.match(notes.join(), /Expressions/);
|
|
206
|
+
assert.deepEqual([project.scenes[0].elements[0].x, project.scenes[0].elements[0].y], [10, 20]);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { maskCandidates, maskSources, removeMissingMasks } from './src/masks.js';
|
|
4
|
+
import { removeSceneLayer, reorderSceneLayer } from './src/model.js';
|
|
5
|
+
import { parseProjectJson, serializeProject } from './src/project-io.js';
|
|
6
|
+
|
|
7
|
+
const stage = { width: 800, height: 450, frameRate: 24 };
|
|
8
|
+
function timeline(elements) {
|
|
9
|
+
return { layers: [{ id: 'paint', name: 'Paint' }, { id: 'masks', name: 'Masks' }],
|
|
10
|
+
elements: elements.map(item => ({ type: 'rectangle', layerId: 'paint', ...item })) };
|
|
11
|
+
}
|
|
12
|
+
function project(elements) {
|
|
13
|
+
return parseProjectJson(JSON.stringify({ stage, scenes: [timeline(elements)] }));
|
|
14
|
+
}
|
|
15
|
+
test('shared masks and mask chains survive layer reordering and a JSON round trip', () => {
|
|
16
|
+
const doc = project([{ id: 'a', maskId: 'inner' }, { id: 'inner', maskId: 'outer' },
|
|
17
|
+
{ id: 'outer', layerId: 'masks' }, { id: 'b', maskId: 'inner' }, { id: 'line', type: 'line' }]);
|
|
18
|
+
const scene = doc.scenes[0];
|
|
19
|
+
assert.deepEqual([...maskSources(scene)], ['inner', 'outer']);
|
|
20
|
+
assert.deepEqual(maskCandidates(scene, scene.elements[1]).map(item => item.id), ['outer']);
|
|
21
|
+
reorderSceneLayer(scene, 'masks', 'down');
|
|
22
|
+
assert.deepEqual(parseProjectJson(serializeProject(doc)), doc);
|
|
23
|
+
removeSceneLayer(scene, 'masks', 'delete');
|
|
24
|
+
assert.equal(scene.elements[1].maskId, undefined);
|
|
25
|
+
assert.equal(scene.elements[0].maskId, 'inner');
|
|
26
|
+
scene.elements = scene.elements.filter(item => item.id !== 'inner');
|
|
27
|
+
removeMissingMasks(scene);
|
|
28
|
+
assert.equal(maskSources(scene).size, 0);
|
|
29
|
+
assert.deepEqual(parseProjectJson(serializeProject(doc)), doc);
|
|
30
|
+
});
|
|
31
|
+
test('mask validation rejects cycles, missing sources, open shapes and references across timelines', () => {
|
|
32
|
+
for (const elements of [
|
|
33
|
+
[{ id: 'a', maskId: 'a' }],
|
|
34
|
+
[{ id: 'a', maskId: 'b' }, { id: 'b', maskId: 'c' }, { id: 'c', maskId: 'a' }],
|
|
35
|
+
]) assert.throws(() => project(elements), /mask cycle/i);
|
|
36
|
+
for (const source of [[], [{ id: 'b', type: 'line' }], [{ id: 'b', type: 'text' }]]) {
|
|
37
|
+
assert.throws(() => project([{ id: 'a', maskId: 'b' }, ...source]), /closed vector in the same timeline/);
|
|
38
|
+
}
|
|
39
|
+
assert.throws(() => parseProjectJson(JSON.stringify({ stage, scenes: [
|
|
40
|
+
timeline([{ id: 'a', maskId: 'b' }]), { elements: [{ id: 'b', type: 'rectangle' }] },
|
|
41
|
+
] })), /closed vector in the same timeline/);
|
|
42
|
+
assert.throws(() => project([{ id: 'a', maskId: 12 }]), /maskId/);
|
|
43
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { bitmapLayout } from './src/media-assets.js';
|
|
4
|
+
import { editSceneFrame, resizeScene } from './src/frame-editing.js';
|
|
5
|
+
import { parseProjectJson, serializeProject } from './src/project-io.js';
|
|
6
|
+
import { createHistory } from './src/history.js';
|
|
7
|
+
|
|
8
|
+
const assets = [
|
|
9
|
+
{ id: 'i', name: 'Picture', kind: 'image', data: 'data:image/png;base64,AQ==' },
|
|
10
|
+
{ id: 's', name: 'Sound', kind: 'audio', data: 'data:audio/wav;base64,AA==' },
|
|
11
|
+
];
|
|
12
|
+
const project = { stage: { width: 800, height: 450, frameRate: 24 }, assets, scenes: [{
|
|
13
|
+
durationFrames: 10, elements: [{ type: 'bitmap', assetId: 'i', fit: 'cover' }],
|
|
14
|
+
audioClips: [{ id: 'clip', assetId: 's', start: 2, end: 5, loop: true }],
|
|
15
|
+
}] };
|
|
16
|
+
const parse = raw => parseProjectJson(JSON.stringify(raw));
|
|
17
|
+
test('embedded assets round-trip and media references require the correct kind', () => {
|
|
18
|
+
const parsed = parse(project);
|
|
19
|
+
assert.deepEqual(parseProjectJson(serializeProject(parsed)), parsed);
|
|
20
|
+
for (const edit of [
|
|
21
|
+
p => p.assets.push(p.assets[0]), p => { p.assets[0].data = 'https://example.com/image.png'; },
|
|
22
|
+
p => { p.scenes[0].elements[0].assetId = 's'; }, p => { p.scenes[0].audioClips[0].assetId = 'i'; },
|
|
23
|
+
p => { p.scenes[0].audioClips[0].end = 20; }, p => { p.scenes[0].elements[0].fit = 'unknown'; },
|
|
24
|
+
]) {
|
|
25
|
+
const raw = structuredClone(project); edit(raw); assert.throws(() => parse(raw));
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
test('audio clips follow timeline frame edits including deleting the end or the entire clip', () => {
|
|
29
|
+
const scene = parse(project).scenes[0];
|
|
30
|
+
const clip = scene.audioClips[0];
|
|
31
|
+
assert.throws(() => resizeScene(scene, 3), /audio clips/);
|
|
32
|
+
editSceneFrame(scene, 2, true);
|
|
33
|
+
assert.deepEqual([clip.start, clip.end], [2, 6]);
|
|
34
|
+
editSceneFrame(scene, 6, false);
|
|
35
|
+
assert.equal(clip.end, 5);
|
|
36
|
+
clip.start = clip.end;
|
|
37
|
+
editSceneFrame(scene, 5, false);
|
|
38
|
+
assert.equal(scene.audioClips, undefined);
|
|
39
|
+
});
|
|
40
|
+
test('bitmap fit and crop preserve proportions and history shares immutable media bytes', () => {
|
|
41
|
+
assert.deepEqual(bitmapLayout(100, 100, 80, 40, 'contain'), { scaleX: 1.25, scaleY: 1.25, x: -50, y: -25, width: 100, height: 50 });
|
|
42
|
+
assert.deepEqual(bitmapLayout(100, 100, 80, 40, 'cover'), { scaleX: 2.5, scaleY: 2.5, x: -100, y: -50, width: 100, height: 100 });
|
|
43
|
+
// A source rectangle shows exactly that part of the image, stretched to the box.
|
|
44
|
+
assert.deepEqual(bitmapLayout(100, 50, 400, 300, 'contain', 50, 50, { x: 40, y: 20, width: 200, height: 100 }),
|
|
45
|
+
{ scaleX: 0.5, scaleY: 0.5, x: -70, y: -35, width: 100, height: 50 });
|
|
46
|
+
const history = createHistory();
|
|
47
|
+
history.record({ assets, scenes: [] }, {});
|
|
48
|
+
history.record({ assets, scenes: [{}] }, {});
|
|
49
|
+
const saved = history.move(-1).project;
|
|
50
|
+
assert.equal(saved.assets[0], assets[0]);
|
|
51
|
+
assert.notEqual(saved.assets, assets);
|
|
52
|
+
});
|
|
53
|
+
test('sounds keep their linkage name, and only sounds may have one', () => {
|
|
54
|
+
const raw = structuredClone(project);
|
|
55
|
+
raw.assets[1].linkage = 'Coin';
|
|
56
|
+
const parsed = parse(raw);
|
|
57
|
+
assert.equal(parsed.assets.find(asset => asset.id === 's').linkage, 'Coin');
|
|
58
|
+
assert.equal(parseProjectJson(serializeProject(parsed)).assets.find(asset => asset.id === 's').linkage, 'Coin');
|
|
59
|
+
for (const edit of [p => { p.assets[0].linkage = 'Picture'; }, p => { p.assets[1].linkage = ' '; }, p => { p.assets[1].linkage = 7; }]) {
|
|
60
|
+
const bad = structuredClone(project); edit(bad); assert.throws(() => parse(bad), /linkage/);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { DiagnosticsCollector } from '../swf2js/util/diagnostics.js';
|
|
4
|
+
import { parse } from '../swf2js/parser/swf-parser.js';
|
|
5
|
+
import { decode } from '../swf2js/decoder/tag-decoder.js';
|
|
6
|
+
import { buildDisplayList } from '../swf2js/transpiler/timeline/display-list.js';
|
|
7
|
+
import { exportProjectSwf } from './server/swf-export.js';
|
|
8
|
+
import { brushOutline, enclosedRegion } from './src/vector-cut.js';
|
|
9
|
+
import { gradientDrag } from './src/paint-tools.js';
|
|
10
|
+
import { regularPolygonPoints } from './src/vector-geometry.js';
|
|
11
|
+
import { parseProjectJson } from './src/project-io.js';
|
|
12
|
+
import { setPoseAtFrame } from './src/document-editing.js';
|
|
13
|
+
import { poseAt } from './src/model.js';
|
|
14
|
+
|
|
15
|
+
const project = elements => ({ stage: { width: 800, height: 450, frameRate: 12 }, scenes: [{ durationFrames: 4, elements }] });
|
|
16
|
+
|
|
17
|
+
test('the bucket finds a region enclosed by separate strokes only when the last gap closes', () => {
|
|
18
|
+
const corners = [{ x: 0, y: 0 }, { x: 50, y: 0 }, { x: 50, y: 50 }, { x: 0, y: 50 }];
|
|
19
|
+
const strokes = corners.map((corner, i) => brushOutline([corner, corners[(i + 1) % corners.length]], 4)[0]);
|
|
20
|
+
assert.equal(enclosedRegion(strokes, { x: 25, y: 25 }).length, 1);
|
|
21
|
+
assert.deepEqual(enclosedRegion(strokes.slice(1), { x: 25, y: 25 }), []);
|
|
22
|
+
assert.deepEqual(enclosedRegion(strokes, { x: 60, y: 25 }), []);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('shape options respect existing keys, default stars, and validation', () => {
|
|
26
|
+
const star = parseProjectJson(JSON.stringify(project([{ type: 'star', keyframes: [{frame:1}, {frame:3}] }]))).scenes[0].elements[0];
|
|
27
|
+
setPoseAtFrame(star, 1, 'starPoints', 9);
|
|
28
|
+
assert.equal(regularPolygonPoints('star', 100, 100, poseAt(star, 1)).length, 18);
|
|
29
|
+
assert.equal(regularPolygonPoints('star', 100, 100, poseAt(star, 3)).length, 10);
|
|
30
|
+
for (const bad of [{ type:'star', starPoints:3.5 }, { type:'star', starRadius:0 }, { type:'roundedRectangle', cornerRadius:-1 }]) {
|
|
31
|
+
assert.throws(() => parseProjectJson(JSON.stringify(project([bad]))));
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('gradient transform moves the center independently of its axes', () => {
|
|
36
|
+
const element = { type:'rectangle' }, pose = { x:0, y:0, width:100, height:80, rotation:0, skew:0,
|
|
37
|
+
scaleX:2, scaleY:1, gradient:{type:'radial', endColor:'#ffffff'} };
|
|
38
|
+
const end = { x:60, y:10 };
|
|
39
|
+
const gradient = gradientDrag(element, pose, {x:20,y:10}, end, false);
|
|
40
|
+
assert.deepEqual([gradient.matrix.tx, gradient.matrix.ty, gradient.matrix.a], [.1,.125,.2]);
|
|
41
|
+
const moved = gradientDrag(element, {...pose, gradient}, end, {x:100,y:30}, true);
|
|
42
|
+
assert.ok(Math.abs(moved.matrix.tx-.3) < 1e-10);
|
|
43
|
+
assert.deepEqual([moved.matrix.ty, moved.matrix.a], [.375,.2]);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('SWF publishes distinct star geometry and the hole cut out of a painted fill', async () => {
|
|
47
|
+
const erasures = brushOutline([{ x:0, y:0 }], 20);
|
|
48
|
+
const document = project([{type:'star', starPoints:8, strokeWidth:0}, {type:'star', strokeWidth:0},
|
|
49
|
+
{type:'rectangle', width:80, height:60, strokeWidth:0, erasures}]);
|
|
50
|
+
const result = await exportProjectSwf(document);
|
|
51
|
+
const diagnostic = new DiagnosticsCollector();
|
|
52
|
+
const { doc } = await parse(result.bytes, diagnostic);
|
|
53
|
+
const { tags, symbolTable } = decode(doc, diagnostic);
|
|
54
|
+
const { characters, frames } = buildDisplayList(tags, symbolTable, diagnostic, {swfVersion: doc.header.version});
|
|
55
|
+
const shapes = frames[0].places.map(place => characters[place.characterId].draws[0]);
|
|
56
|
+
assert.equal(shapes.length, 3);
|
|
57
|
+
assert.ok(shapes[0].path.length > shapes[1].path.length);
|
|
58
|
+
assert.equal(shapes[2].path.filter(command => command[0] === 'M').length, 2);
|
|
59
|
+
assert.deepEqual(diagnostic._items.filter(item => item.level !== 'info'), []);
|
|
60
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { advancePlayhead } from './src/playback.js';
|
|
4
|
+
|
|
5
|
+
test('a one-shot plays the final frame for its full duration, then holds', () => {
|
|
6
|
+
const scene = { durationFrames: 6, startFrame: 2 };
|
|
7
|
+
assert.deepEqual(advancePlayhead(scene, 5, 1), { frame: 6, finished: false });
|
|
8
|
+
assert.deepEqual(advancePlayhead(scene, 6, 1), { frame: 6, finished: true });
|
|
9
|
+
assert.deepEqual(advancePlayhead(scene, 2, 8), { frame: 6, finished: true });
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('loops wrap to the authored start, including skipped frames and one-frame loops', () => {
|
|
13
|
+
const scene = { durationFrames: 6, startFrame: 4, loop: true };
|
|
14
|
+
assert.deepEqual(advancePlayhead(scene, 6, 1), { frame: 4, finished: false });
|
|
15
|
+
assert.deepEqual(advancePlayhead(scene, 5, 8), { frame: 4, finished: false });
|
|
16
|
+
assert.deepEqual(advancePlayhead({ ...scene, startFrame: 6 }, 6, 8), { frame: 6, finished: false });
|
|
17
|
+
});
|