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,281 @@
|
|
|
1
|
+
// Headless playback for video export (studiospec/video-export.md §8.2–8.4). It keeps Preview's
|
|
2
|
+
// state (scene, playhead, playing, hidden objects, symbol clocks, event visits) and applies the
|
|
3
|
+
// rules of studio/src/index.js frame by frame: change those rules there and here together.
|
|
4
|
+
// Rendering is injected, so these rules run in Node tests without a canvas.
|
|
5
|
+
import { resolveStreamAudioTime } from '../../swooflib/stream-time.js';
|
|
6
|
+
import { createEventDispatcher, objectAction } from './frame-events.js';
|
|
7
|
+
import { applyEasing } from './model.js';
|
|
8
|
+
import { advancePlayhead } from './playback.js';
|
|
9
|
+
import { hasScripts } from './scripts.js';
|
|
10
|
+
import { scopedId } from './symbols.js';
|
|
11
|
+
|
|
12
|
+
/** The features that make Preview play this project on the swf2js player (studiospec/actionscript.md §3). */
|
|
13
|
+
export function swfPlayerReasons(project) {
|
|
14
|
+
const timelines = [...project.scenes, ...(project.symbols ?? [])];
|
|
15
|
+
const reasons = [];
|
|
16
|
+
if (hasScripts(project)) reasons.push('ActionScript');
|
|
17
|
+
if (timelines.some(timeline => timeline.scalingGrid)) reasons.push('nine-slice scaling');
|
|
18
|
+
if (timelines.some(timeline => timeline.trackAsMenu)) reasons.push('menu buttons');
|
|
19
|
+
if (timelines.some(timeline => timeline.buttonSounds)) reasons.push('button sounds');
|
|
20
|
+
if (timelines.some(timeline => timeline.audioClips?.some(clip => clip.soundInfo))) reasons.push('sound envelopes');
|
|
21
|
+
return reasons;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Button sounds and menu tracking need input, which a video has none of, and Flash sound cues
|
|
25
|
+
// are mixed by the audio schedule. Scripts and nine-slice scaling need the swf2js player.
|
|
26
|
+
const VIDEO_BLOCKERS = new Set(['ActionScript', 'nine-slice scaling']);
|
|
27
|
+
|
|
28
|
+
/** Whether a project has sound to include: audio clips, or (on the SWF player) audio that scripts can play. */
|
|
29
|
+
export function projectHasSound(project) {
|
|
30
|
+
const timelines = [...project.scenes, ...(project.symbols ?? [])];
|
|
31
|
+
if (timelines.some(timeline => timeline.audioClips?.length)) return true;
|
|
32
|
+
return Boolean(videoExportRefusal(project)) && (project.assets ?? []).some(asset => asset.kind === 'audio' || asset.type?.startsWith?.('audio/'));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Why Studio's renderer cannot draw this project for video, or null. Video export then records
|
|
37
|
+
* the swf2js player instead (swf-recording.js); without a recorder, this is the refusal message.
|
|
38
|
+
*/
|
|
39
|
+
export function videoExportRefusal(project) {
|
|
40
|
+
const reasons = swfPlayerReasons(project).filter(reason => VIDEO_BLOCKERS.has(reason));
|
|
41
|
+
if (!reasons.length) return null;
|
|
42
|
+
const list = reasons.length > 1 ? `${reasons.slice(0, -1).join(', ')} and ${reasons.at(-1)}` : reasons[0];
|
|
43
|
+
return `Video export does not support movies that play on the SWF player yet. This project uses ${list}. Export it as SWF or HTML instead.`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Flash sound cue positions are in samples at 44.1 kHz (the decoded buffers' rate).
|
|
47
|
+
const CUE_RATE = 44100;
|
|
48
|
+
// After playback stops, the video holds its last frame while event sounds finish, up to this long.
|
|
49
|
+
export const EVENT_TAIL_SECONDS = 30;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Audio voices as Preview plays them, recorded as segments on the video's time line instead of
|
|
53
|
+
* played: { assetId, start, offset, loop, end } in seconds, plus loopStart, loopEnd and envelope
|
|
54
|
+
* for Flash event sounds.
|
|
55
|
+
* - Studio clips follow preview-audio.js: they play while their timeline shows their frames.
|
|
56
|
+
* - Clips with a Flash sound cue (`soundInfo`) follow the SWF player (swooflib/sound.js): they start
|
|
57
|
+
* when their timeline enters the start frame and then play on their own, through stops and jumps,
|
|
58
|
+
* until they end, a `syncStop` cue stops that sound, or a cut-at-end clip is left.
|
|
59
|
+
*/
|
|
60
|
+
export function createAudioSchedule({ fps, durationOf }) {
|
|
61
|
+
const voices = new Map();
|
|
62
|
+
const segments = [];
|
|
63
|
+
const events = [];
|
|
64
|
+
const eventVisits = new Map();
|
|
65
|
+
function stopEvents(assetId, time) {
|
|
66
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
67
|
+
if (events[i].assetId !== assetId) continue;
|
|
68
|
+
events[i].end = Math.max(events[i].start, Math.min(events[i].end, time));
|
|
69
|
+
events.splice(i, 1);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function startEvent(clip, time) {
|
|
73
|
+
const info = clip.soundInfo;
|
|
74
|
+
if (info.syncStop) return stopEvents(clip.assetId, time);
|
|
75
|
+
for (let i = events.length - 1; i >= 0; i--) if (events[i].end <= time) events.splice(i, 1);
|
|
76
|
+
if (info.syncNoMultiple && events.some(event => event.assetId === clip.assetId)) return;
|
|
77
|
+
const duration = durationOf(clip.assetId);
|
|
78
|
+
if (!duration) return;
|
|
79
|
+
const from = info.inPoint == null ? 0 : Math.min(duration, info.inPoint / CUE_RATE);
|
|
80
|
+
const to = info.outPoint == null ? duration : Math.min(duration, info.outPoint / CUE_RATE);
|
|
81
|
+
if (to <= from) return;
|
|
82
|
+
const plays = 1 + (info.loopCount ?? 0);
|
|
83
|
+
const segment = { assetId: clip.assetId, start: time, offset: from, loop: plays > 1, loopStart: from, loopEnd: to,
|
|
84
|
+
end: time + plays * (to - from), envelope: info.envelope?.length ? info.envelope : null };
|
|
85
|
+
segments.push(segment);
|
|
86
|
+
events.push(segment);
|
|
87
|
+
}
|
|
88
|
+
function cue(timelines, time) {
|
|
89
|
+
const present = new Set();
|
|
90
|
+
for (const entry of timelines) {
|
|
91
|
+
const clips = (entry.timeline.audioClips ?? []).filter(clip => clip.soundInfo);
|
|
92
|
+
if (!clips.length) continue;
|
|
93
|
+
const key = JSON.stringify([entry.timeline.id, entry.scope, entry.exposure]);
|
|
94
|
+
present.add(key);
|
|
95
|
+
if (eventVisits.get(key) === entry.frame) continue;
|
|
96
|
+
eventVisits.set(key, entry.frame);
|
|
97
|
+
for (const clip of clips) {
|
|
98
|
+
if (clip.cutAtEnd && clip.end + 1 === entry.frame) stopEvents(clip.assetId, time);
|
|
99
|
+
if (clip.start === entry.frame) startEvent(clip, time);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
for (const key of [...eventVisits.keys()]) if (!present.has(key)) eventVisits.delete(key);
|
|
103
|
+
}
|
|
104
|
+
function end(key, time) {
|
|
105
|
+
const voice = voices.get(key);
|
|
106
|
+
voice.segment.end = Math.min(voice.segment.end, time);
|
|
107
|
+
voices.delete(key);
|
|
108
|
+
}
|
|
109
|
+
function sync(timelines, time, playing) {
|
|
110
|
+
cue(timelines, time);
|
|
111
|
+
const active = new Set();
|
|
112
|
+
if (playing) for (const entry of timelines) {
|
|
113
|
+
if (!entry.audioActive) continue;
|
|
114
|
+
for (const clip of entry.timeline.audioClips ?? []) {
|
|
115
|
+
if (clip.soundInfo || entry.frame < clip.start || entry.frame > clip.end) continue;
|
|
116
|
+
const duration = durationOf(clip.assetId);
|
|
117
|
+
if (!duration) continue;
|
|
118
|
+
const elapsed = clip.streamSync
|
|
119
|
+
? resolveStreamAudioTime(clip.streamSync, entry.frame - clip.start, fps)
|
|
120
|
+
: (entry.frame - clip.start) / fps;
|
|
121
|
+
if (elapsed == null) continue;
|
|
122
|
+
if (!clip.loop && elapsed >= duration) continue;
|
|
123
|
+
const key = JSON.stringify([entry.timeline.id, entry.scope, clip.id]);
|
|
124
|
+
active.add(key);
|
|
125
|
+
const voice = voices.get(key);
|
|
126
|
+
const rootFrame = timelines[0].frame;
|
|
127
|
+
const wrapped = entry.repeatOnTick && voice?.lastFrame === entry.frame && voice.rootFrame !== rootFrame;
|
|
128
|
+
if (voice && !wrapped && voice.exposure === entry.exposure && entry.frame >= voice.lastFrame &&
|
|
129
|
+
Math.abs(time - voice.origin - elapsed) < Math.max(0.12, 1.5 / fps)) {
|
|
130
|
+
voice.lastFrame = entry.frame;
|
|
131
|
+
voice.rootFrame = rootFrame;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (voice) end(key, time);
|
|
135
|
+
const segment = { assetId: clip.assetId, start: time, offset: elapsed % duration, loop: Boolean(clip.loop),
|
|
136
|
+
end: time + (clip.end - entry.frame + 1) / fps };
|
|
137
|
+
segments.push(segment);
|
|
138
|
+
voices.set(key, { segment, scope: entry.scope, rootFrame, origin: time - elapsed, lastFrame: entry.frame, exposure: entry.exposure });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
for (const key of [...voices.keys()]) if (!active.has(key)) end(key, time);
|
|
142
|
+
}
|
|
143
|
+
function reset(scope, time) {
|
|
144
|
+
for (const [key, voice] of [...voices]) if (scope.every((id, index) => id === voice.scope[index])) end(key, time);
|
|
145
|
+
}
|
|
146
|
+
// When the event sounds still playing end, if within EVENT_TAIL_SECONDS of `time`.
|
|
147
|
+
function tail(time) {
|
|
148
|
+
const ends = events.map(event => event.end).filter(end => end > time && end - time <= EVENT_TAIL_SECONDS);
|
|
149
|
+
return ends.length ? Math.max(...ends) : time;
|
|
150
|
+
}
|
|
151
|
+
function finish(time) {
|
|
152
|
+
reset([], time);
|
|
153
|
+
for (const event of events) event.end = Math.min(event.end, time);
|
|
154
|
+
events.length = 0;
|
|
155
|
+
}
|
|
156
|
+
return { sync, reset, finish, tail, segments };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Plays the project from its first scene and calls `emit` once per video frame.
|
|
161
|
+
* - `render({ scene, playhead, hiddenIds, clocks })` draws the frame and returns its active timelines.
|
|
162
|
+
* - `snapshot()` keeps the drawn frame as the outgoing image of a scene transition.
|
|
163
|
+
* - `emit(transition)` records the drawn frame; during a transition it gets `{ type, progress }`
|
|
164
|
+
* to composite the outgoing image over it.
|
|
165
|
+
* Ends at a stop (then holds `holdFrames`), when the movie repeats a state it has shown, or at `maxFrames`.
|
|
166
|
+
* Returns { frames, ending } where ending is 'stop', 'repeat' or 'length'.
|
|
167
|
+
*/
|
|
168
|
+
export async function playHeadless({ project, render, snapshot, emit, maxFrames, holdFrames, audio }) {
|
|
169
|
+
const fps = project.stage.frameRate;
|
|
170
|
+
let scene = project.scenes[0];
|
|
171
|
+
let playhead = scene.startFrame ?? 1;
|
|
172
|
+
let playing = true;
|
|
173
|
+
let transition = null;
|
|
174
|
+
let timelines = [];
|
|
175
|
+
let frames = 0;
|
|
176
|
+
const hiddenIds = new Set();
|
|
177
|
+
const clocks = new Map();
|
|
178
|
+
const dispatcher = createEventDispatcher();
|
|
179
|
+
const seen = new Map(); // state → the frame that showed it
|
|
180
|
+
const draw = () => { timelines = render({ scene, playhead, hiddenIds, clocks }); };
|
|
181
|
+
|
|
182
|
+
function navigate(target) {
|
|
183
|
+
if (target.transition && target.id !== scene.id) {
|
|
184
|
+
draw();
|
|
185
|
+
snapshot();
|
|
186
|
+
transition = { ...target.transition, frame: 0 };
|
|
187
|
+
}
|
|
188
|
+
audio?.reset([], frames / fps);
|
|
189
|
+
hiddenIds.clear();
|
|
190
|
+
clocks.clear();
|
|
191
|
+
dispatcher.reset();
|
|
192
|
+
scene = target;
|
|
193
|
+
playhead = target.startFrame ?? 1;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function execute(action, ctx) {
|
|
197
|
+
if (action.type === 'script') return;
|
|
198
|
+
if (objectAction(action.type)) {
|
|
199
|
+
const id = scopedId(ctx.scope, action.target);
|
|
200
|
+
if (action.type === 'hide' || (action.type === 'toggleVisibility' && !hiddenIds.has(id))) hiddenIds.add(id);
|
|
201
|
+
else hiddenIds.delete(id);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (action.type === 'gotoScene') {
|
|
205
|
+
const target = project.scenes.find(item => item.id === action.target);
|
|
206
|
+
if (!target) return;
|
|
207
|
+
navigate(target);
|
|
208
|
+
playing = Boolean(action.play);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const jump = action.type === 'gotoFrame';
|
|
212
|
+
const play = action.type === 'play' || (jump && Boolean(action.play));
|
|
213
|
+
if (jump) dispatcher.reenter(ctx.scope);
|
|
214
|
+
if (jump) audio?.reset(ctx.scope, frames / fps);
|
|
215
|
+
if (ctx.scope.length) {
|
|
216
|
+
const id = scopedId(ctx.scope.slice(0, -1), ctx.scope.at(-1));
|
|
217
|
+
clocks.set(id, { anchor: ctx.parentFrame, lastFrame: ctx.parentFrame, frame: jump ? action.target : ctx.frame, play });
|
|
218
|
+
} else {
|
|
219
|
+
if (jump) playhead = action.target;
|
|
220
|
+
playing = play;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function settle(tick) {
|
|
225
|
+
if (tick) dispatcher.tick(timelines);
|
|
226
|
+
try {
|
|
227
|
+
dispatcher.settle(() => transition ? [] : timelines, execute, draw);
|
|
228
|
+
} catch (error) {
|
|
229
|
+
throw new Error(`Video export stopped: ${error.message.replace(/^Preview paused/, 'the movie loops')}`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const stateKey = () => JSON.stringify([scene.id, playhead, playing, [...hiddenIds].sort(),
|
|
234
|
+
[...clocks].sort(([a], [b]) => a.localeCompare(b))]);
|
|
235
|
+
|
|
236
|
+
async function frame(transitionState) {
|
|
237
|
+
audio?.sync(timelines, frames / fps, playing && !transition);
|
|
238
|
+
await emit(transitionState, { scene, playhead });
|
|
239
|
+
frames++;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
draw();
|
|
243
|
+
settle(false);
|
|
244
|
+
for (;;) {
|
|
245
|
+
if (frames >= maxFrames) return { frames, ending: 'length' };
|
|
246
|
+
if (transition) {
|
|
247
|
+
const progress = applyEasing(transition.easing, Math.min(1, transition.frame / transition.durationFrames));
|
|
248
|
+
await frame({ type: transition.type, progress });
|
|
249
|
+
if (++transition.frame >= transition.durationFrames) {
|
|
250
|
+
transition = null;
|
|
251
|
+
draw();
|
|
252
|
+
settle(false);
|
|
253
|
+
}
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
const key = stateKey();
|
|
257
|
+
// `repeatFrom`: the frame the movie returns to, where a loop of the recording starts.
|
|
258
|
+
if (seen.has(key)) return { frames, ending: 'repeat', repeatFrom: seen.get(key) };
|
|
259
|
+
seen.set(key, frames);
|
|
260
|
+
await frame(null);
|
|
261
|
+
if (!playing) break;
|
|
262
|
+
const next = advancePlayhead(scene, playhead, 1);
|
|
263
|
+
if (next.finished) {
|
|
264
|
+
playing = false;
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
if (scene.loop && playhead + 1 > scene.durationFrames) {
|
|
268
|
+
clocks.clear();
|
|
269
|
+
audio?.reset([], frames / fps);
|
|
270
|
+
dispatcher.reenter([]);
|
|
271
|
+
}
|
|
272
|
+
playhead = next.frame;
|
|
273
|
+
draw();
|
|
274
|
+
settle(true);
|
|
275
|
+
}
|
|
276
|
+
// Stopped: hold the last frame so the ending is visible. Studio clips stop, as in Preview; the
|
|
277
|
+
// hold lasts until Flash event sounds finish, if they end soon.
|
|
278
|
+
const hold = Math.max(holdFrames, Math.ceil(((audio?.tail(frames / fps) ?? 0) - frames / fps) * fps - 1e-6));
|
|
279
|
+
for (let i = 0; i < hold && frames < maxFrames; i++) await frame(null);
|
|
280
|
+
return { frames, ending: 'stop' };
|
|
281
|
+
}
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import { installStageGuides } from './stage-guides.js';
|
|
2
|
+
|
|
3
|
+
// Workspace preferences are local to the current editor view.
|
|
4
|
+
const viewport = document.querySelector('.stage-viewport');
|
|
5
|
+
const pasteboard = document.querySelector('.stage-pasteboard');
|
|
6
|
+
const mat = document.querySelector('.stage-mat');
|
|
7
|
+
const canvas = document.querySelector('#stage');
|
|
8
|
+
const zoom = document.querySelector('#stage-zoom');
|
|
9
|
+
const dock = document.querySelector('#workspace-dock');
|
|
10
|
+
const dockToggle = document.querySelector('#toggle-dock');
|
|
11
|
+
const divider = document.querySelector('#timeline-divider');
|
|
12
|
+
const center = document.querySelector('.center-panel');
|
|
13
|
+
const tabs = [...dock.querySelectorAll('[role=tab]')];
|
|
14
|
+
const sceneSwitcher = document.querySelector('#scene-switcher');
|
|
15
|
+
const toolMenus = [...document.querySelectorAll('.more-tools')];
|
|
16
|
+
const documentProperties = document.querySelector('#document-properties');
|
|
17
|
+
const elementForm = document.querySelector('#element-form');
|
|
18
|
+
|
|
19
|
+
const toolbar = document.querySelector('.toolbar');
|
|
20
|
+
const tools = [...toolbar.querySelectorAll('.tool-group button, .more-tools summary')];
|
|
21
|
+
function setToolTabStop(active) {
|
|
22
|
+
for (const tool of tools) tool.tabIndex = tool === active ? 0 : -1;
|
|
23
|
+
}
|
|
24
|
+
setToolTabStop(tools[0]);
|
|
25
|
+
toolbar.addEventListener('focusin', event => {
|
|
26
|
+
if (tools.includes(event.target)) setToolTabStop(event.target);
|
|
27
|
+
});
|
|
28
|
+
toolbar.addEventListener('keydown', event => {
|
|
29
|
+
const enabled = tools.filter(tool => !tool.disabled);
|
|
30
|
+
const index = enabled.indexOf(event.target);
|
|
31
|
+
if (index < 0) return;
|
|
32
|
+
const next = { ArrowDown: index + 1, ArrowUp: index - 1, Home: 0, End: enabled.length - 1 }[event.key];
|
|
33
|
+
if (next === undefined) return;
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
enabled[(next + enabled.length) % enabled.length].focus();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
function selectTab(tab, focus = false) {
|
|
39
|
+
for (const item of tabs) {
|
|
40
|
+
const selected = item === tab;
|
|
41
|
+
item.setAttribute('aria-selected', String(selected));
|
|
42
|
+
item.tabIndex = selected ? 0 : -1;
|
|
43
|
+
document.getElementById(item.getAttribute('aria-controls')).hidden = !selected;
|
|
44
|
+
}
|
|
45
|
+
if (focus) tab.focus();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
for (const [index, tab] of tabs.entries()) {
|
|
49
|
+
tab.addEventListener('click', () => selectTab(tab));
|
|
50
|
+
tab.addEventListener('keydown', event => {
|
|
51
|
+
const next = { ArrowRight: index + 1, ArrowLeft: index - 1, Home: 0, End: tabs.length - 1 }[event.key];
|
|
52
|
+
if (next === undefined) return;
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
event.stopPropagation();
|
|
55
|
+
selectTab(tabs[(next + tabs.length) % tabs.length], true);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function setDrawer(open, focus = false) {
|
|
60
|
+
document.body.classList.toggle('dock-open', open);
|
|
61
|
+
dockToggle.setAttribute('aria-expanded', String(open));
|
|
62
|
+
if (focus) (open ? tabs.find(tab => tab.tabIndex === 0) : dockToggle).focus();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const compact = matchMedia('(max-width:800px)');
|
|
66
|
+
dockToggle.addEventListener('click', () => setDrawer(!document.body.classList.contains('dock-open'), true));
|
|
67
|
+
compact.addEventListener('change', () => setDrawer(false));
|
|
68
|
+
document.addEventListener('pointerdown', event => {
|
|
69
|
+
if (compact.matches && document.body.classList.contains('dock-open') &&
|
|
70
|
+
!dock.contains(event.target) && !dockToggle.contains(event.target) && !event.target.closest('dialog')) {
|
|
71
|
+
setDrawer(false);
|
|
72
|
+
if (viewport.contains(event.target)) {
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
event.stopPropagation();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (!sceneSwitcher.contains(event.target)) sceneSwitcher.open = false;
|
|
78
|
+
for (const menu of toolMenus) if (!menu.contains(event.target)) menu.open = false;
|
|
79
|
+
}, true);
|
|
80
|
+
|
|
81
|
+
sceneSwitcher.addEventListener('click', event => {
|
|
82
|
+
if (!event.target.closest('button')) return;
|
|
83
|
+
sceneSwitcher.open = false;
|
|
84
|
+
if (sceneSwitcher.contains(document.activeElement) || document.activeElement === document.body) {
|
|
85
|
+
sceneSwitcher.querySelector('summary').focus();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
document.addEventListener('keydown', event => {
|
|
90
|
+
if (event.key !== 'Escape' || document.querySelector('dialog[open]')) return;
|
|
91
|
+
const popup = [sceneSwitcher, ...toolMenus].find(item => item.open);
|
|
92
|
+
if (popup) {
|
|
93
|
+
popup.open = false;
|
|
94
|
+
popup.querySelector('summary').focus();
|
|
95
|
+
event.stopImmediatePropagation();
|
|
96
|
+
} else if (compact.matches && document.body.classList.contains('dock-open')) {
|
|
97
|
+
setDrawer(false, true);
|
|
98
|
+
event.stopImmediatePropagation();
|
|
99
|
+
}
|
|
100
|
+
}, true);
|
|
101
|
+
|
|
102
|
+
function openDocumentProperties() {
|
|
103
|
+
selectTab(tabs[0]);
|
|
104
|
+
documentProperties.open = true;
|
|
105
|
+
if (compact.matches) setDrawer(true);
|
|
106
|
+
}
|
|
107
|
+
document.querySelector('#new-symbol').addEventListener('click', openDocumentProperties, true);
|
|
108
|
+
document.querySelector('#edit-symbol').addEventListener('click', openDocumentProperties, true);
|
|
109
|
+
document.querySelector('#add-scene').addEventListener('click', openDocumentProperties, true);
|
|
110
|
+
document.querySelector('#place-symbol').addEventListener('click', () => {
|
|
111
|
+
selectTab(tabs[0]);
|
|
112
|
+
if (compact.matches) setDrawer(false);
|
|
113
|
+
});
|
|
114
|
+
// File imports use the same validation and undo history as pasted projects.
|
|
115
|
+
const projectDialog = document.querySelector('#project-io-dialog');
|
|
116
|
+
const projectForm = document.querySelector('#project-io-form');
|
|
117
|
+
const projectJson = document.querySelector('#project-io-textarea');
|
|
118
|
+
const projectFile = document.querySelector('#project-file');
|
|
119
|
+
let fileRequest = 0;
|
|
120
|
+
function cancelPendingFile() { fileRequest++; }
|
|
121
|
+
for (const opener of document.querySelectorAll('#import-project, #export-project, #browse-examples')) {
|
|
122
|
+
opener.addEventListener('click', cancelPendingFile, true);
|
|
123
|
+
}
|
|
124
|
+
projectDialog.addEventListener('close', () => { if (!projectDialog.open) cancelPendingFile(); });
|
|
125
|
+
projectJson.addEventListener('input', cancelPendingFile);
|
|
126
|
+
document.querySelector('#project-io-examples').addEventListener('click', cancelPendingFile);
|
|
127
|
+
projectForm.addEventListener('submit', cancelPendingFile, true);
|
|
128
|
+
// Any file Import reads, told apart by its content: a SWF (FWS, CWS or ZWS) is converted on the
|
|
129
|
+
// server; an image or sound goes to the library, as Upload files does; gzip is unpacked (.svgz);
|
|
130
|
+
// text (a Studio project, Lottie JSON, SVG) goes through the form like pasted text.
|
|
131
|
+
const LIBRARY_FILE = /\.(png|jpe?g|webp|gif|avif|bmp|wav|mp3|m4a|aac|ogg|oga|opus|flac)$/i;
|
|
132
|
+
async function openImportFile(file) {
|
|
133
|
+
const request = ++fileRequest;
|
|
134
|
+
const current = () => request === fileRequest && projectDialog.open && projectDialog.dataset.mode === 'import';
|
|
135
|
+
try {
|
|
136
|
+
const head = new Uint8Array(await file.slice(0, 3).arrayBuffer());
|
|
137
|
+
if (!current()) return;
|
|
138
|
+
if (['FWS', 'CWS', 'ZWS'].includes(String.fromCharCode(...head))) {
|
|
139
|
+
projectDialog.dispatchEvent(new CustomEvent('import-swf-file', { detail: file }));
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const svg = file.type === 'image/svg+xml' || /\.svgz?$/i.test(file.name);
|
|
143
|
+
if (!svg && (/^(image|audio)\//.test(file.type) || LIBRARY_FILE.test(file.name))) {
|
|
144
|
+
projectDialog.dispatchEvent(new CustomEvent('import-media-file', { detail: file }));
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const json = head[0] === 0x1f && head[1] === 0x8b
|
|
148
|
+
? await new Response(file.stream().pipeThrough(new DecompressionStream('gzip'))).text()
|
|
149
|
+
: await file.text();
|
|
150
|
+
if (!current()) return;
|
|
151
|
+
projectJson.value = json;
|
|
152
|
+
projectForm.requestSubmit();
|
|
153
|
+
} catch (error) {
|
|
154
|
+
if (!current()) return;
|
|
155
|
+
const message = document.querySelector('#project-io-error');
|
|
156
|
+
message.textContent = `Could not open ${file.name}. ${error.message}`;
|
|
157
|
+
message.hidden = false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
projectFile.addEventListener('change', () => {
|
|
161
|
+
const file = projectFile.files[0];
|
|
162
|
+
projectFile.value = '';
|
|
163
|
+
if (file) openImportFile(file);
|
|
164
|
+
});
|
|
165
|
+
// A file dropped on the Import dialog opens as if chosen.
|
|
166
|
+
projectDialog.addEventListener('dragover', event => {
|
|
167
|
+
if (projectDialog.dataset.mode !== 'import' || ![...event.dataTransfer.types].includes('Files')) return;
|
|
168
|
+
event.preventDefault();
|
|
169
|
+
event.dataTransfer.dropEffect = 'copy';
|
|
170
|
+
});
|
|
171
|
+
projectDialog.addEventListener('drop', event => {
|
|
172
|
+
if (projectDialog.dataset.mode !== 'import') return;
|
|
173
|
+
const file = event.dataTransfer.files[0];
|
|
174
|
+
if (!file) return;
|
|
175
|
+
event.preventDefault();
|
|
176
|
+
openImportFile(file);
|
|
177
|
+
});
|
|
178
|
+
let hadSelection;
|
|
179
|
+
function syncProperties() {
|
|
180
|
+
const selected = !elementForm.hidden;
|
|
181
|
+
if (selected === hadSelection) return;
|
|
182
|
+
hadSelection = selected;
|
|
183
|
+
documentProperties.open = !selected;
|
|
184
|
+
if (tabs[0].getAttribute('aria-selected') === 'true') document.querySelector('#properties-panel').scrollTop = 0;
|
|
185
|
+
}
|
|
186
|
+
new MutationObserver(syncProperties).observe(elementForm, { attributeFilter: ['hidden'] });
|
|
187
|
+
syncProperties();
|
|
188
|
+
|
|
189
|
+
const toolHints = {
|
|
190
|
+
select: 'Drag to move. Shift-click to select more.',
|
|
191
|
+
scale: 'Drag a selection handle to resize.',
|
|
192
|
+
rotate: 'Drag the handle above a selection to rotate.',
|
|
193
|
+
pen: 'Click to add points. Drag for curves.',
|
|
194
|
+
polygon: 'Click to place points, then finish or close the path.',
|
|
195
|
+
text: 'Click or drag to create a text box.',
|
|
196
|
+
};
|
|
197
|
+
function updateToolStatus() {
|
|
198
|
+
const name = canvas.dataset.tool;
|
|
199
|
+
const button = document.querySelector(`button[data-tool="${CSS.escape(name || 'select')}"]`);
|
|
200
|
+
const label = button?.getAttribute('aria-label')?.split(' (')[0] || button?.textContent.trim() || 'Select';
|
|
201
|
+
const preview = !document.querySelector('#preview-badge').hidden;
|
|
202
|
+
document.querySelector('#tool-status').textContent = preview ? 'Interactive preview' : `${label} tool`;
|
|
203
|
+
document.querySelector('#tool-hint').textContent = preview ? 'Press Esc to return to editing.' : (toolHints[name] || 'Click or drag on the stage to draw.');
|
|
204
|
+
}
|
|
205
|
+
const toolObserver = new MutationObserver(updateToolStatus);
|
|
206
|
+
toolObserver.observe(canvas, { attributeFilter: ['data-tool'] });
|
|
207
|
+
toolObserver.observe(document.querySelector('#preview-badge'), { attributeFilter: ['hidden'] });
|
|
208
|
+
updateToolStatus();
|
|
209
|
+
|
|
210
|
+
function fitStage() {
|
|
211
|
+
const style = getComputedStyle(pasteboard);
|
|
212
|
+
const horizontal = parseFloat(style.paddingLeft) + parseFloat(style.paddingRight);
|
|
213
|
+
const vertical = parseFloat(style.paddingTop) + parseFloat(style.paddingBottom);
|
|
214
|
+
const fit = Math.min((viewport.clientWidth - horizontal) / canvas.width, (viewport.clientHeight - vertical) / canvas.height);
|
|
215
|
+
const scale = zoom.value === 'fit' ? Math.max(.01, fit) : Number(zoom.value);
|
|
216
|
+
// Leave room to pan even when a manually zoomed artboard is smaller than the viewport.
|
|
217
|
+
mat.style.margin = zoom.value === 'fit' ? '' : `${viewport.clientHeight}px ${viewport.clientWidth}px`;
|
|
218
|
+
mat.style.width = `${Math.max(1, canvas.width * scale)}px`;
|
|
219
|
+
mat.style.height = `${Math.max(1, canvas.height * scale)}px`;
|
|
220
|
+
// Overlays sized from the stage (preview fields) refit now rather than at the next observer
|
|
221
|
+
// delivery, so a click right after a resize lands on them.
|
|
222
|
+
document.dispatchEvent(new Event('swoof:stage-fit'));
|
|
223
|
+
zoom.options[0].textContent = `Fit · ${Math.round(Math.max(.01, fit) * 100)}%`;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
installStageGuides(viewport, canvas);
|
|
227
|
+
|
|
228
|
+
function zoomAround(x, y) {
|
|
229
|
+
const oldMat = mat.getBoundingClientRect();
|
|
230
|
+
const fractionX = (x - oldMat.left) / oldMat.width;
|
|
231
|
+
const fractionY = (y - oldMat.top) / oldMat.height;
|
|
232
|
+
fitStage();
|
|
233
|
+
const newMat = mat.getBoundingClientRect();
|
|
234
|
+
viewport.scrollLeft += newMat.left + fractionX * newMat.width - x;
|
|
235
|
+
viewport.scrollTop += newMat.top + fractionY * newMat.height - y;
|
|
236
|
+
}
|
|
237
|
+
const presets = [...zoom.options].filter(option => option.value !== 'fit');
|
|
238
|
+
const wheelZoom = new Option();
|
|
239
|
+
zoom.addEventListener('change', () => {
|
|
240
|
+
if (!wheelZoom.selected) wheelZoom.remove();
|
|
241
|
+
const bounds = viewport.getBoundingClientRect();
|
|
242
|
+
zoomAround(bounds.left + viewport.clientWidth / 2, bounds.top + viewport.clientHeight / 2);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
mat.addEventListener('wheel', event => {
|
|
246
|
+
if (!event.deltaY || event.defaultPrevented || event.shiftKey || event.metaKey || event.ctrlKey ||
|
|
247
|
+
event.target.closest('textarea, input, select')) return;
|
|
248
|
+
event.preventDefault();
|
|
249
|
+
const unit = event.deltaMode === WheelEvent.DOM_DELTA_LINE ? 16 :
|
|
250
|
+
event.deltaMode === WheelEvent.DOM_DELTA_PAGE ? viewport.clientHeight : 1;
|
|
251
|
+
const current = zoom.value === 'fit' ? mat.getBoundingClientRect().width / canvas.width : Number(zoom.value);
|
|
252
|
+
const factor = Math.exp(-event.deltaY * unit * .002);
|
|
253
|
+
// Fit can already be outside the manual range on unusually small or large screens.
|
|
254
|
+
const next = Math.max(Math.min(current, .1), Math.min(Math.max(current, 8), current * factor));
|
|
255
|
+
if (next === current) return;
|
|
256
|
+
const preset = presets.find(option => Math.abs(Number(option.value) - next) < .000001);
|
|
257
|
+
if (preset) {
|
|
258
|
+
wheelZoom.remove();
|
|
259
|
+
zoom.value = preset.value;
|
|
260
|
+
} else {
|
|
261
|
+
wheelZoom.value = String(next);
|
|
262
|
+
wheelZoom.textContent = `${Math.round(next * 100)}%`;
|
|
263
|
+
if (!wheelZoom.isConnected) zoom.append(wheelZoom);
|
|
264
|
+
wheelZoom.selected = true;
|
|
265
|
+
}
|
|
266
|
+
zoomAround(event.clientX, event.clientY);
|
|
267
|
+
}, { passive: false });
|
|
268
|
+
new ResizeObserver(fitStage).observe(viewport);
|
|
269
|
+
new MutationObserver(fitStage).observe(canvas, { attributeFilter: ['width', 'height'] });
|
|
270
|
+
fitStage();
|
|
271
|
+
|
|
272
|
+
let pan;
|
|
273
|
+
viewport.addEventListener('pointerdown', event => {
|
|
274
|
+
if (event.button !== 1) return;
|
|
275
|
+
event.preventDefault();
|
|
276
|
+
event.stopPropagation();
|
|
277
|
+
pan = { id: event.pointerId, x: event.clientX, y: event.clientY, left: viewport.scrollLeft, top: viewport.scrollTop };
|
|
278
|
+
viewport.setPointerCapture(event.pointerId);
|
|
279
|
+
viewport.classList.add('is-panning');
|
|
280
|
+
}, true);
|
|
281
|
+
viewport.addEventListener('pointermove', event => {
|
|
282
|
+
if (event.pointerId !== pan?.id) return;
|
|
283
|
+
viewport.scrollLeft = pan.left + pan.x - event.clientX;
|
|
284
|
+
viewport.scrollTop = pan.top + pan.y - event.clientY;
|
|
285
|
+
});
|
|
286
|
+
viewport.addEventListener('lostpointercapture', () => {
|
|
287
|
+
pan = null;
|
|
288
|
+
viewport.classList.remove('is-panning');
|
|
289
|
+
});
|
|
290
|
+
viewport.addEventListener('auxclick', event => { if (event.button === 1) event.preventDefault(); });
|
|
291
|
+
|
|
292
|
+
function positionMoreTools() {
|
|
293
|
+
for (const tools of toolMenus) {
|
|
294
|
+
if (!tools.open) continue;
|
|
295
|
+
const menu = tools.querySelector('.more-tools-menu');
|
|
296
|
+
const rect = tools.getBoundingClientRect();
|
|
297
|
+
menu.style.left = `${rect.right + 5}px`;
|
|
298
|
+
menu.style.top = `${Math.max(4, Math.min(rect.top, innerHeight - menu.offsetHeight - 5))}px`;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
for (const menu of toolMenus) menu.addEventListener('toggle', positionMoreTools);
|
|
302
|
+
document.querySelector('.toolbar').addEventListener('scroll', positionMoreTools);
|
|
303
|
+
window.addEventListener('resize', positionMoreTools);
|
|
304
|
+
|
|
305
|
+
let resizeOrigin;
|
|
306
|
+
let customHeight;
|
|
307
|
+
const timeline = document.querySelector('.timeline-panel');
|
|
308
|
+
function timelineLimits() {
|
|
309
|
+
const max = Math.max(48, Math.floor(center.clientHeight * .64));
|
|
310
|
+
return { min: Math.min(110, max), max };
|
|
311
|
+
}
|
|
312
|
+
function setTimelineHeight(height) {
|
|
313
|
+
const { min, max } = timelineLimits();
|
|
314
|
+
customHeight = Math.round(Math.min(max, Math.max(min, height)));
|
|
315
|
+
center.style.setProperty('--dock-height', `${customHeight}px`);
|
|
316
|
+
}
|
|
317
|
+
function updateDivider() {
|
|
318
|
+
const { min, max } = timelineLimits();
|
|
319
|
+
divider.setAttribute('aria-valuemin', String(min));
|
|
320
|
+
divider.setAttribute('aria-valuemax', String(max));
|
|
321
|
+
divider.setAttribute('aria-valuenow', String(timeline.offsetHeight));
|
|
322
|
+
divider.setAttribute('aria-valuetext', `${timeline.offsetHeight} pixels`);
|
|
323
|
+
}
|
|
324
|
+
divider.addEventListener('pointerdown', event => {
|
|
325
|
+
if (event.button !== 0) return;
|
|
326
|
+
event.preventDefault();
|
|
327
|
+
divider.focus();
|
|
328
|
+
resizeOrigin = { id: event.pointerId, height: timeline.offsetHeight, y: event.clientY };
|
|
329
|
+
divider.setPointerCapture(event.pointerId);
|
|
330
|
+
});
|
|
331
|
+
divider.addEventListener('pointermove', event => {
|
|
332
|
+
if (resizeOrigin?.id === event.pointerId) setTimelineHeight(resizeOrigin.height + resizeOrigin.y - event.clientY);
|
|
333
|
+
});
|
|
334
|
+
divider.addEventListener('lostpointercapture', () => { resizeOrigin = null; });
|
|
335
|
+
divider.addEventListener('keydown', event => {
|
|
336
|
+
if (!['ArrowUp', 'ArrowDown', 'Home', 'End'].includes(event.key)) return;
|
|
337
|
+
event.preventDefault();
|
|
338
|
+
event.stopPropagation();
|
|
339
|
+
const { min, max } = timelineLimits();
|
|
340
|
+
const heights = { ArrowUp: timeline.offsetHeight + 16, ArrowDown: timeline.offsetHeight - 16, Home: min, End: max };
|
|
341
|
+
setTimelineHeight(heights[event.key]);
|
|
342
|
+
});
|
|
343
|
+
new ResizeObserver(updateDivider).observe(timeline);
|
|
344
|
+
new ResizeObserver(() => { if (customHeight !== undefined) setTimelineHeight(customHeight); }).observe(center);
|