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,150 @@
|
|
|
1
|
+
import { controlDefinitions } from '../../swooflib/control-definitions.js';
|
|
2
|
+
import { authoredEventActions, normalizeEvents, objectAction } from './frame-events.js';
|
|
3
|
+
import { applyScriptDrafts, editAttachedScript } from './script-editor.js';
|
|
4
|
+
|
|
5
|
+
export function createEventEditor(context) {
|
|
6
|
+
const { project, commit } = context;
|
|
7
|
+
const dialog = document.querySelector('#event-editor');
|
|
8
|
+
const trigger = dialog.querySelector('#event-trigger');
|
|
9
|
+
const list = dialog.querySelector('#event-actions');
|
|
10
|
+
const error = dialog.querySelector('[role=alert]');
|
|
11
|
+
let timeline, frame, drafts, source;
|
|
12
|
+
// Script edits made in this dialog: script ID → the script as it will be saved.
|
|
13
|
+
let scriptDrafts = new Map();
|
|
14
|
+
const scriptFor = id => scriptDrafts.get(id) ?? project.scripts?.find(item => item.id === id);
|
|
15
|
+
|
|
16
|
+
function current() { return drafts[trigger.value]; }
|
|
17
|
+
function button(label, title, operation, disabled = false) {
|
|
18
|
+
const node = document.createElement('button');
|
|
19
|
+
node.type = 'button';
|
|
20
|
+
node.className = 'small-button';
|
|
21
|
+
node.textContent = label;
|
|
22
|
+
node.setAttribute('aria-label', title);
|
|
23
|
+
node.title = title;
|
|
24
|
+
node.disabled = disabled;
|
|
25
|
+
node.onclick = operation;
|
|
26
|
+
return node;
|
|
27
|
+
}
|
|
28
|
+
function select(label, choices, value, change) {
|
|
29
|
+
const node = document.createElement('select');
|
|
30
|
+
node.className = 'text-input';
|
|
31
|
+
node.setAttribute('aria-label', label);
|
|
32
|
+
node.replaceChildren(...choices.map(([id, name]) => new Option(name, id)));
|
|
33
|
+
node.value = value;
|
|
34
|
+
node.onchange = () => change(node.value);
|
|
35
|
+
return node;
|
|
36
|
+
}
|
|
37
|
+
function defaultAction(type) {
|
|
38
|
+
const action = { type };
|
|
39
|
+
if (objectAction(type)) action.target = timeline.elements[0]?.id ?? '';
|
|
40
|
+
if (type === 'gotoScene') action.target = project.scenes[0].id;
|
|
41
|
+
if (type === 'gotoFrame') action.target = frame;
|
|
42
|
+
return action;
|
|
43
|
+
}
|
|
44
|
+
function render(focusIndex) {
|
|
45
|
+
error.textContent = '';
|
|
46
|
+
const actions = current();
|
|
47
|
+
list.replaceChildren(...actions.map((action, index) => {
|
|
48
|
+
const row = document.createElement('li');
|
|
49
|
+
row.className = 'event-row';
|
|
50
|
+
if (action.type === 'script') {
|
|
51
|
+
// ActionScript: opened in the script editor; it can be reordered or removed.
|
|
52
|
+
const script = scriptFor(action.script);
|
|
53
|
+
const label = document.createElement('span');
|
|
54
|
+
label.className = 'event-script';
|
|
55
|
+
const name = script?.name ?? action.script;
|
|
56
|
+
label.textContent = `Run script: ${name}${scriptDrafts.has(action.script) ? ' (edited)' : ''}`;
|
|
57
|
+
row.append(label, button('Edit', `Edit script ${name}`, async () => {
|
|
58
|
+
const id = await editAttachedScript(context, scriptDrafts, action.script, name);
|
|
59
|
+
if (id) action.script = id;
|
|
60
|
+
render(index);
|
|
61
|
+
}, !script));
|
|
62
|
+
} else {
|
|
63
|
+
row.append(select('Action ' + (index + 1), Object.entries(authoredEventActions), action.type, type => {
|
|
64
|
+
actions[index] = defaultAction(type);
|
|
65
|
+
render(index);
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
if (objectAction(action.type) || action.type === 'gotoScene') {
|
|
69
|
+
const items = action.type === 'gotoScene' ? project.scenes : timeline.elements;
|
|
70
|
+
const options = items.map(item => [item.id, item.name]);
|
|
71
|
+
if (!options.length) options.push(['', 'No objects in this timeline']);
|
|
72
|
+
row.append(select('Destination', options, action.target, id => { action.target = id; }));
|
|
73
|
+
}
|
|
74
|
+
if (action.type === 'gotoFrame') {
|
|
75
|
+
const input = document.createElement('input');
|
|
76
|
+
Object.assign(input, { type: 'number', min: 1, max: timeline.durationFrames, value: action.target, className: 'text-input' });
|
|
77
|
+
input.setAttribute('aria-label', 'Destination frame');
|
|
78
|
+
input.oninput = () => { action.target = input.valueAsNumber; };
|
|
79
|
+
row.append(input);
|
|
80
|
+
}
|
|
81
|
+
if (action.type === 'gotoFrame' || action.type === 'gotoScene') {
|
|
82
|
+
row.append(select('Playback after jump', [['stop', 'Jump and stop'], ['play', 'Jump and play']],
|
|
83
|
+
action.play ? 'play' : 'stop', value => { action.play = value === 'play'; }));
|
|
84
|
+
}
|
|
85
|
+
const tools = document.createElement('div');
|
|
86
|
+
tools.className = 'event-row-tools';
|
|
87
|
+
function move(delta) {
|
|
88
|
+
actions.splice(index + delta, 0, actions.splice(index, 1)[0]);
|
|
89
|
+
render(index + delta);
|
|
90
|
+
}
|
|
91
|
+
tools.append(button('↑', 'Move action up', () => move(-1), !index),
|
|
92
|
+
button('↓', 'Move action down', () => move(1), index === actions.length - 1),
|
|
93
|
+
button('Remove', 'Remove action', () => { actions.splice(index, 1); render(Math.min(index, actions.length - 1)); }));
|
|
94
|
+
row.append(tools);
|
|
95
|
+
return row;
|
|
96
|
+
}));
|
|
97
|
+
dialog.querySelector('#event-empty').hidden = actions.length > 0;
|
|
98
|
+
if (Number.isInteger(focusIndex)) (list.children[focusIndex]?.firstElementChild ?? dialog.querySelector('#event-add')).focus();
|
|
99
|
+
}
|
|
100
|
+
trigger.onchange = render;
|
|
101
|
+
dialog.querySelector('#event-add').onclick = () => { current().push({ type: 'stop' }); render(current().length - 1); };
|
|
102
|
+
dialog.querySelector('#event-add-script').onclick = async () => {
|
|
103
|
+
const name = source ? `${source.name} ${trigger.value}` : `${timeline.name} frame ${frame}`;
|
|
104
|
+
const id = await editAttachedScript(context, scriptDrafts, null, name);
|
|
105
|
+
if (!id) return;
|
|
106
|
+
current().push({ type: 'script', script: id });
|
|
107
|
+
render(current().length - 1);
|
|
108
|
+
};
|
|
109
|
+
dialog.querySelector('#event-cancel').onclick = () => dialog.close();
|
|
110
|
+
dialog.querySelector('form').onsubmit = e => {
|
|
111
|
+
e.preventDefault();
|
|
112
|
+
const events = (timeline.events ?? []).filter(item => source
|
|
113
|
+
? item.source !== source.id
|
|
114
|
+
: item.trigger !== 'timelineStart' && item.frame !== frame);
|
|
115
|
+
for (const [type, actions] of Object.entries(drafts)) {
|
|
116
|
+
if (!actions.length) continue;
|
|
117
|
+
if (source) events.push({ trigger: type, source: source.id, actions });
|
|
118
|
+
else events.push(type === 'timelineStart' ? { trigger: type, actions } : { trigger: type, frame, actions });
|
|
119
|
+
}
|
|
120
|
+
const scripts = project.scripts;
|
|
121
|
+
applyScriptDrafts(project, scriptDrafts, new Set(Object.values(drafts).flat().map(action => action.script)));
|
|
122
|
+
try {
|
|
123
|
+
const next = normalizeEvents(events, timeline, project);
|
|
124
|
+
if (next.length) timeline.events = next;
|
|
125
|
+
else delete timeline.events;
|
|
126
|
+
dialog.close();
|
|
127
|
+
commit();
|
|
128
|
+
} catch (err) {
|
|
129
|
+
if (scripts) project.scripts = scripts;
|
|
130
|
+
else delete project.scripts;
|
|
131
|
+
error.textContent = err.message;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
return function open(owner, at, type = 'frameEnter', control = null) {
|
|
135
|
+
timeline = owner;
|
|
136
|
+
frame = at;
|
|
137
|
+
source = control;
|
|
138
|
+
scriptDrafts = new Map();
|
|
139
|
+
dialog.querySelector('h2').textContent = `${source?.name ?? timeline.name} · Actions`;
|
|
140
|
+
const kinds = source ? controlDefinitions[source.control].events : ['frameEnter', 'timelineStart'];
|
|
141
|
+
const names = { frameEnter: `On entering frame ${frame}`, timelineStart: 'On timeline start' };
|
|
142
|
+
trigger.replaceChildren(...kinds.map(kind => new Option(names[kind] ?? `On ${kind}`, kind)));
|
|
143
|
+
trigger.value = kinds.includes(type) ? type : kinds[0];
|
|
144
|
+
drafts = Object.fromEntries(kinds.map(kind => [kind,
|
|
145
|
+
structuredClone(timeline.events?.find(item => item.trigger === kind &&
|
|
146
|
+
(source ? item.source === source.id : kind === 'timelineStart' || item.frame === frame))?.actions ?? [])]));
|
|
147
|
+
render();
|
|
148
|
+
dialog.showModal();
|
|
149
|
+
};
|
|
150
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { MAX_TIMELINE_FRAMES } from './numeric-fields.js';
|
|
2
|
+
import { ensureKeyframe, isElementLocked, poseAt, visibleAt } from './model.js';
|
|
3
|
+
|
|
4
|
+
export function startTrack(element, frame) {
|
|
5
|
+
const key = { ...structuredClone(poseAt(element, frame)), frame, tween: 'linear' };
|
|
6
|
+
element.keyframes = frame === 1 ? [key] : [{ ...structuredClone(key), frame: 1, blank: true }, key];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function editTrack(scene, element, frame, operation) {
|
|
10
|
+
if (!element) throw new Error('Select an object track');
|
|
11
|
+
if (isElementLocked(scene, element)) throw new Error('Unlock the layer to edit its track');
|
|
12
|
+
const keys = element.keyframes;
|
|
13
|
+
const index = keys.findIndex(key => key.frame === frame);
|
|
14
|
+
if (operation === 'duplicate') {
|
|
15
|
+
if (index < 0) throw new Error('Select a keyframe to duplicate');
|
|
16
|
+
if (frame >= MAX_TIMELINE_FRAMES) throw new Error(`A scene can contain up to ${MAX_TIMELINE_FRAMES} frames`);
|
|
17
|
+
if (keys.some(key => key.frame === frame + 1)) throw new Error('The next frame already has a keyframe');
|
|
18
|
+
if (frame === scene.durationFrames) scene.durationFrames += 1;
|
|
19
|
+
keys.splice(index + 1, 0, { ...structuredClone(keys[index]), frame: frame + 1 });
|
|
20
|
+
return frame + 1;
|
|
21
|
+
}
|
|
22
|
+
if (operation === 'removeKey') {
|
|
23
|
+
if (index < 0) throw new Error('Select a keyframe to remove');
|
|
24
|
+
if (keys.length === 1) {
|
|
25
|
+
keys[0] = { ...keys[0], frame: 1, blank: true };
|
|
26
|
+
return frame;
|
|
27
|
+
}
|
|
28
|
+
const [removed] = keys.splice(index, 1);
|
|
29
|
+
// Before its first authored appearance a track remains blank.
|
|
30
|
+
if (index === 0 && !removed.blank && keys[0].frame > 1) keys.unshift({ ...structuredClone(keys[0]), frame: 1, blank: true });
|
|
31
|
+
} else {
|
|
32
|
+
const key = ensureKeyframe(element, frame);
|
|
33
|
+
if (operation === 'blank') key.blank = true;
|
|
34
|
+
else delete key.blank;
|
|
35
|
+
}
|
|
36
|
+
return frame;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function keyLayer(scene, layer, frame, blank) {
|
|
40
|
+
if (!layer || layer.locked) throw new Error('Choose an unlocked layer');
|
|
41
|
+
for (const element of scene.elements) {
|
|
42
|
+
if (element.layerId !== layer.id || !visibleAt(element, frame)) continue;
|
|
43
|
+
editTrack(scene, element, frame, blank ? 'blank' : 'key');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function instanceFrameReferences(project, timeline) {
|
|
48
|
+
if (!project?.symbols?.includes(timeline)) return [];
|
|
49
|
+
return [...project.scenes, ...project.symbols].flatMap(owner => owner.elements
|
|
50
|
+
.filter(item => item.symbolId === timeline.id && item.firstFrame !== undefined)
|
|
51
|
+
.map(item => ({ owner, item })));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function resizeScene(scene, duration, project) {
|
|
55
|
+
if (!Number.isInteger(duration) || duration < 1 || duration > MAX_TIMELINE_FRAMES) {
|
|
56
|
+
throw new Error(`Scene duration must be between 1 and ${MAX_TIMELINE_FRAMES} frames`);
|
|
57
|
+
}
|
|
58
|
+
if (scene.audioClips?.some(clip => clip.end > duration)) throw new Error('Shorten the audio clips before reducing the timeline duration');
|
|
59
|
+
for (const event of scene.events ?? []) {
|
|
60
|
+
if (event.frame > duration || event.actions.some(action => action.type === 'gotoFrame' && action.target > duration)) {
|
|
61
|
+
throw new Error('Move the frame event or its destination before shortening the timeline');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
for (const element of scene.elements) {
|
|
65
|
+
const key = element.keyframes.find(key => key.frame > duration);
|
|
66
|
+
if (key) throw new Error(`${element.name} has a keyframe at frame ${key.frame}. Remove it before shortening the scene.`);
|
|
67
|
+
const action = element.buttonAction;
|
|
68
|
+
if (action?.type === 'gotoFrame' && action.target <= scene.durationFrames && action.target > duration) {
|
|
69
|
+
throw new Error(`${element.name} targets frame ${action.target}. Change its target before shortening the scene.`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
for (const { item } of instanceFrameReferences(project, scene)) {
|
|
73
|
+
if (item.firstFrame > duration) throw new Error(`${item.name} starts at frame ${item.firstFrame}. Change its first frame before shortening the symbol.`);
|
|
74
|
+
}
|
|
75
|
+
for (const symbol of project?.symbols ?? []) {
|
|
76
|
+
if (symbol.initAt?.scene === scene.id) symbol.initAt.frame = Math.min(symbol.initAt.frame, duration);
|
|
77
|
+
}
|
|
78
|
+
scene.durationFrames = duration;
|
|
79
|
+
for (const record of scene.avm2 ?? []) record.frame = Math.min(record.frame, duration);
|
|
80
|
+
scene.startFrame = Math.min(scene.startFrame ?? 1, duration);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Insert after the playhead or remove its current frame across the whole scene.
|
|
84
|
+
// Navigation targets follow the same content; a deleted destination uses its successor.
|
|
85
|
+
export function editSceneFrame(scene, frame, insert, project) {
|
|
86
|
+
const duration = scene.durationFrames + (insert ? 1 : -1);
|
|
87
|
+
if (duration < 1 || duration > MAX_TIMELINE_FRAMES) throw new Error(`Scenes must have between 1 and ${MAX_TIMELINE_FRAMES} frames`);
|
|
88
|
+
const shift = position => {
|
|
89
|
+
if (position > frame) return position + (insert ? 1 : -1);
|
|
90
|
+
return Math.min(position, duration);
|
|
91
|
+
};
|
|
92
|
+
for (const element of scene.elements) {
|
|
93
|
+
if (!isElementLocked(scene, element)) continue;
|
|
94
|
+
const changesKeys = element.keyframes.some(key => insert ? key.frame > frame : key.frame >= frame);
|
|
95
|
+
const action = element.buttonAction;
|
|
96
|
+
if (changesKeys || (action?.type === 'gotoFrame' && shift(action.target) !== action.target)) {
|
|
97
|
+
throw new Error('Unlock the affected layers before shifting scene frames');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const references = instanceFrameReferences(project, scene);
|
|
101
|
+
for (const { owner, item } of references) {
|
|
102
|
+
if (isElementLocked(owner, item) && shift(item.firstFrame) !== item.firstFrame) {
|
|
103
|
+
throw new Error(`Unlock the layer containing ${item.name} before shifting its first frame`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
for (const { item } of references) item.firstFrame = shift(item.firstFrame);
|
|
107
|
+
for (const symbol of project?.symbols ?? []) {
|
|
108
|
+
if (symbol.initAt?.scene === scene.id) symbol.initAt.frame = shift(symbol.initAt.frame);
|
|
109
|
+
}
|
|
110
|
+
for (const element of scene.elements) {
|
|
111
|
+
const keys = element.keyframes;
|
|
112
|
+
if (!insert) {
|
|
113
|
+
const index = keys.findIndex(key => key.frame === frame);
|
|
114
|
+
if (index >= 0) {
|
|
115
|
+
if (frame < scene.durationFrames && keys[index + 1]?.frame !== frame + 1) {
|
|
116
|
+
const successor = { ...keys[index], ...structuredClone(poseAt(element, frame + 1)), frame: frame + 1 };
|
|
117
|
+
keys.splice(index, 1, successor);
|
|
118
|
+
} else {
|
|
119
|
+
keys.splice(index, 1);
|
|
120
|
+
}
|
|
121
|
+
if (!keys.length || (index === 0 && keys[0].frame > frame + 1)) {
|
|
122
|
+
keys.unshift({ ...structuredClone(poseAt(element, 1)), frame: 1, blank: true, tween: 'hold' });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
for (const key of keys) key.frame = shift(key.frame);
|
|
127
|
+
const action = element.buttonAction;
|
|
128
|
+
if (action?.type === 'gotoFrame' && Number.isInteger(action.target)) action.target = shift(action.target);
|
|
129
|
+
}
|
|
130
|
+
scene.durationFrames = duration;
|
|
131
|
+
for (const record of scene.avm2 ?? []) record.frame = shift(record.frame);
|
|
132
|
+
if (scene.events) {
|
|
133
|
+
scene.events = scene.events.filter(event => insert || event.frame !== frame);
|
|
134
|
+
for (const event of scene.events) {
|
|
135
|
+
if (event.frame !== undefined) event.frame = shift(event.frame);
|
|
136
|
+
for (const action of event.actions) if (action.type === 'gotoFrame') action.target = shift(action.target);
|
|
137
|
+
}
|
|
138
|
+
if (!scene.events.length) delete scene.events;
|
|
139
|
+
}
|
|
140
|
+
if (scene.audioClips) {
|
|
141
|
+
scene.audioClips = scene.audioClips.filter(clip => insert || clip.start !== frame || clip.end !== frame);
|
|
142
|
+
for (const clip of scene.audioClips) {
|
|
143
|
+
clip.start = shift(clip.start);
|
|
144
|
+
clip.end = !insert && clip.end === frame ? frame - 1 : shift(clip.end);
|
|
145
|
+
}
|
|
146
|
+
if (!scene.audioClips.length) delete scene.audioClips;
|
|
147
|
+
}
|
|
148
|
+
scene.startFrame = shift(scene.startFrame ?? 1);
|
|
149
|
+
return insert ? frame + 1 : Math.min(frame, duration);
|
|
150
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { controlDefinitions } from '../../swooflib/control-definitions.js';
|
|
2
|
+
|
|
3
|
+
export const eventActions = {
|
|
4
|
+
play: 'Play', stop: 'Stop', gotoFrame: 'Go to frame', gotoScene: 'Go to scene',
|
|
5
|
+
show: 'Show object', hide: 'Hide object', toggleVisibility: 'Toggle visibility',
|
|
6
|
+
script: 'Run script',
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/** Actions the event editor offers. Scripts come from SWF import and are not created by hand yet. */
|
|
10
|
+
export const authoredEventActions = Object.fromEntries(Object.entries(eventActions).filter(([type]) => type !== 'script'));
|
|
11
|
+
|
|
12
|
+
export function objectAction(type) {
|
|
13
|
+
return ['show', 'hide', 'toggleVisibility'].includes(type);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function normalizeEvents(events, timeline, project) {
|
|
17
|
+
if (!Array.isArray(events)) throw new Error('Timeline events must be an array');
|
|
18
|
+
const seen = new Set();
|
|
19
|
+
const validFrame = n => Number.isInteger(n) && n >= 1 && n <= timeline.durationFrames;
|
|
20
|
+
return events.map(raw => {
|
|
21
|
+
if (!raw) throw new Error('Unsupported timeline event trigger');
|
|
22
|
+
const event = { trigger: raw.trigger };
|
|
23
|
+
if (!['timelineStart', 'frameEnter'].includes(raw.trigger)) {
|
|
24
|
+
const source = timeline.elements.find(element => element.id === raw.source && element.type === 'control');
|
|
25
|
+
if (!source || !controlDefinitions[source.control]?.events.includes(raw.trigger)) throw new Error('Unsupported control event or source');
|
|
26
|
+
event.source = source.id;
|
|
27
|
+
}
|
|
28
|
+
if (raw.trigger === 'frameEnter') {
|
|
29
|
+
if (!validFrame(raw.frame)) throw new Error(`Event frame must be between 1 and ${timeline.durationFrames}`);
|
|
30
|
+
event.frame = raw.frame;
|
|
31
|
+
}
|
|
32
|
+
const key = event.source ? JSON.stringify([event.source, event.trigger]) : event.frame ?? event.trigger;
|
|
33
|
+
if (seen.has(key)) throw new Error(`Duplicate timeline event at ${key}`);
|
|
34
|
+
seen.add(key);
|
|
35
|
+
if (!Array.isArray(raw.actions) || !raw.actions.length) throw new Error('An event needs at least one action');
|
|
36
|
+
event.actions = raw.actions.map((item, index) => {
|
|
37
|
+
if (!item || typeof item.type !== 'string' || !Object.hasOwn(eventActions, item.type)) throw new Error('Unsupported frame action');
|
|
38
|
+
const action = { type: item.type };
|
|
39
|
+
if (action.type === 'script') {
|
|
40
|
+
if (!project.scripts?.some(script => script.id === item.script)) throw new Error('Missing script for a Run script action');
|
|
41
|
+
action.script = item.script;
|
|
42
|
+
return action;
|
|
43
|
+
}
|
|
44
|
+
if (objectAction(action.type)) {
|
|
45
|
+
if (!timeline.elements.some(el => el.id === item.target)) throw new Error('Choose an object from this timeline');
|
|
46
|
+
action.target = item.target;
|
|
47
|
+
}
|
|
48
|
+
if (action.type === 'gotoFrame' || action.type === 'gotoScene') {
|
|
49
|
+
if (index !== raw.actions.length - 1) throw new Error('Place the jump last so all preceding actions can run');
|
|
50
|
+
if (action.type === 'gotoFrame' && !validFrame(item.target)) throw new Error(`Destination frame must be between 1 and ${timeline.durationFrames}`);
|
|
51
|
+
if (action.type === 'gotoScene' && !project.scenes.some(scene => scene.id === item.target)) throw new Error('Choose a destination scene in this project');
|
|
52
|
+
if (item.play !== undefined && typeof item.play !== 'boolean') throw new Error('Play after jump must be a boolean');
|
|
53
|
+
action.target = item.target;
|
|
54
|
+
if (item.play) action.play = true;
|
|
55
|
+
}
|
|
56
|
+
return action;
|
|
57
|
+
});
|
|
58
|
+
return event;
|
|
59
|
+
}).sort((a, b) => (a.frame ?? 0) - (b.frame ?? 0));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Removing a target also removes instructions that would point to a missing ID.
|
|
63
|
+
export function removeEventTargets(timeline, ids, matches, removeSources = false) {
|
|
64
|
+
if (!timeline.events) return;
|
|
65
|
+
for (const event of timeline.events) {
|
|
66
|
+
event.actions = event.actions.filter(action => !matches(action.type) || !ids.has(action.target));
|
|
67
|
+
}
|
|
68
|
+
timeline.events = timeline.events.filter(event => event.actions.length && !(removeSources && ids.has(event.source)));
|
|
69
|
+
if (!timeline.events.length) delete timeline.events;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Track visits per mounted instance. Rendering and authoring never call this on their own.
|
|
73
|
+
export function createEventDispatcher() {
|
|
74
|
+
const visits = new Map();
|
|
75
|
+
function reenter(scope) {
|
|
76
|
+
const visit = visits.get(JSON.stringify(scope));
|
|
77
|
+
if (visit) visit.frame = null;
|
|
78
|
+
}
|
|
79
|
+
function tick(contexts) {
|
|
80
|
+
const advanced = new Set();
|
|
81
|
+
for (const ctx of contexts) {
|
|
82
|
+
const key = JSON.stringify(ctx.scope);
|
|
83
|
+
const parent = JSON.stringify(ctx.scope.slice(0, -1));
|
|
84
|
+
if (ctx.repeatOnTick && visits.get(key)?.frame === ctx.frame && advanced.has(parent)) reenter(ctx.scope);
|
|
85
|
+
if (visits.get(key)?.frame !== ctx.frame) advanced.add(key);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function settle(readTimelines, execute, refresh) {
|
|
89
|
+
const fired = new Set();
|
|
90
|
+
let changed = false;
|
|
91
|
+
for (;;) {
|
|
92
|
+
const contexts = readTimelines();
|
|
93
|
+
const active = new Set(contexts.map(ctx => JSON.stringify(ctx.scope)));
|
|
94
|
+
for (const key of visits.keys()) if (!active.has(key)) visits.delete(key);
|
|
95
|
+
let next;
|
|
96
|
+
for (const ctx of contexts) {
|
|
97
|
+
const key = JSON.stringify(ctx.scope);
|
|
98
|
+
let visit = visits.get(key);
|
|
99
|
+
if (!visit || visit.timeline !== ctx.timeline || visit.exposure !== ctx.exposure) {
|
|
100
|
+
visit = { timeline: ctx.timeline, exposure: ctx.exposure, started: false, frame: null };
|
|
101
|
+
visits.set(key, visit);
|
|
102
|
+
}
|
|
103
|
+
let event;
|
|
104
|
+
if (!visit.started) {
|
|
105
|
+
visit.started = true;
|
|
106
|
+
event = ctx.timeline.events?.find(item => item.trigger === 'timelineStart');
|
|
107
|
+
}
|
|
108
|
+
if (!event && visit.frame !== ctx.frame) {
|
|
109
|
+
visit.frame = ctx.frame;
|
|
110
|
+
event = ctx.timeline.events?.find(item => item.frame === ctx.frame);
|
|
111
|
+
}
|
|
112
|
+
if (event) {
|
|
113
|
+
next = { ctx, event };
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (!next) return changed;
|
|
118
|
+
const { ctx, event } = next;
|
|
119
|
+
const key = JSON.stringify([ctx.timeline.id, ctx.scope, ctx.exposure, event.trigger, event.frame]);
|
|
120
|
+
if (fired.has(key)) throw new Error(`Preview paused at ${ctx.timeline.name}, frame ${ctx.frame}: circular frame actions`);
|
|
121
|
+
fired.add(key);
|
|
122
|
+
for (const action of event.actions) execute(action, ctx);
|
|
123
|
+
changed = true;
|
|
124
|
+
refresh();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return { settle, reenter, tick, reset: () => visits.clear() };
|
|
128
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Frame image export (studiospec/video-export.md §9): the frame on the stage, without editor
|
|
2
|
+
// overlays, as a PNG, JPEG or WebP at a chosen scale. Nothing in the editor changes.
|
|
3
|
+
import { renderCaptureFrame } from './canvas.js';
|
|
4
|
+
import { decodeAsset } from './media-assets.js';
|
|
5
|
+
|
|
6
|
+
export const IMAGE_TYPES = { png: 'image/png', jpeg: 'image/jpeg', webp: 'image/webp' };
|
|
7
|
+
const MAX_SIDE = 16384;
|
|
8
|
+
const MAX_PIXELS = 100e6;
|
|
9
|
+
|
|
10
|
+
export async function renderFrameImage({ project, stage, scene, playhead, hiddenIds = new Set(), clocks = new Map(), scale = 1, format = 'png' }) {
|
|
11
|
+
const type = IMAGE_TYPES[format];
|
|
12
|
+
if (!type) throw new Error('Choose PNG, JPEG or WebP');
|
|
13
|
+
const width = Math.max(1, Math.round(stage.width * scale));
|
|
14
|
+
const height = Math.max(1, Math.round(stage.height * scale));
|
|
15
|
+
if (width > MAX_SIDE || height > MAX_SIDE || width * height > MAX_PIXELS) {
|
|
16
|
+
throw new Error(`${width} × ${height} is too large for an image: choose a smaller size`);
|
|
17
|
+
}
|
|
18
|
+
await Promise.all((project.assets ?? []).map(asset => decodeAsset(asset).catch(() => null)));
|
|
19
|
+
const canvas = document.createElement('canvas');
|
|
20
|
+
canvas.width = width;
|
|
21
|
+
canvas.height = height;
|
|
22
|
+
// Drawing updates and prunes the clocks it is given, so it gets copies of Preview's state.
|
|
23
|
+
renderCaptureFrame(canvas, { stage, scene, symbols: project.symbols ?? [], assets: project.assets ?? [], playhead, scale,
|
|
24
|
+
clocks: new Map([...clocks].map(([id, clock]) => [id, { ...clock }])), hiddenIds: new Set(hiddenIds) });
|
|
25
|
+
const blob = await new Promise(resolve => canvas.toBlob(resolve, type, 0.92));
|
|
26
|
+
if (!blob || blob.type !== type) throw new Error(`This browser cannot write ${format.toUpperCase()} images`);
|
|
27
|
+
return { blob, width, height };
|
|
28
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Layer-local display groups share a contiguous stacking position. Member IDs
|
|
2
|
+
// and tracks stay intact so actions and keyframes survive grouping/ungrouping.
|
|
3
|
+
export function groupMembers(scene, element) {
|
|
4
|
+
if (!element.groupId) return [element];
|
|
5
|
+
return scene.elements.filter(item => item.groupId === element.groupId);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function displayUnits(elements) {
|
|
9
|
+
const units = [];
|
|
10
|
+
const groups = new Map();
|
|
11
|
+
for (const element of elements) {
|
|
12
|
+
let unit = element.groupId && groups.get(element.groupId);
|
|
13
|
+
if (!unit) {
|
|
14
|
+
unit = [];
|
|
15
|
+
units.push(unit);
|
|
16
|
+
if (element.groupId) groups.set(element.groupId, unit);
|
|
17
|
+
}
|
|
18
|
+
unit.push(element);
|
|
19
|
+
}
|
|
20
|
+
return units;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function writeLayerOrder(scene, layerId, ordered) {
|
|
24
|
+
let index = 0;
|
|
25
|
+
scene.elements = scene.elements.map(item => item.layerId === layerId ? ordered[index++] : item);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function pruneGroups(scene) {
|
|
29
|
+
const counts = new Map();
|
|
30
|
+
for (const item of scene.elements) {
|
|
31
|
+
if (item.groupId) counts.set(item.groupId, (counts.get(item.groupId) ?? 0) + 1);
|
|
32
|
+
}
|
|
33
|
+
for (const item of scene.elements) {
|
|
34
|
+
if (counts.get(item.groupId) === 1) delete item.groupId;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function editableLayer(scene, members) {
|
|
39
|
+
const layer = scene.layers.find(item => item.id === members[0]?.layerId);
|
|
40
|
+
if (!layer || members.some(item => item.layerId !== layer.id)) throw new Error('Select objects on the same layer');
|
|
41
|
+
if (layer.locked) throw new Error('Unlock the layer before editing its objects');
|
|
42
|
+
return layer;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function groupElements(scene, members, groupId) {
|
|
46
|
+
const layer = editableLayer(scene, members);
|
|
47
|
+
if (members.length < 2) throw new Error('Select at least two objects to group');
|
|
48
|
+
const chosen = new Set(members);
|
|
49
|
+
const siblings = scene.elements.filter(item => item.layerId === layer.id);
|
|
50
|
+
const slot = siblings.findLastIndex(item => chosen.has(item));
|
|
51
|
+
const ordered = siblings.filter(item => chosen.has(item));
|
|
52
|
+
for (const item of ordered) item.groupId = groupId;
|
|
53
|
+
const rest = siblings.slice(0, slot).filter(item => !chosen.has(item));
|
|
54
|
+
const order = [...rest, ...ordered, ...siblings.slice(slot + 1)];
|
|
55
|
+
// If only part of another group was selected, keep its remaining members together.
|
|
56
|
+
writeLayerOrder(scene, layer.id, displayUnits(order).flat());
|
|
57
|
+
pruneGroups(scene);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function ungroupElements(scene, members) {
|
|
61
|
+
editableLayer(scene, members);
|
|
62
|
+
const ids = new Set(members.map(item => item.groupId).filter(Boolean));
|
|
63
|
+
for (const item of scene.elements) {
|
|
64
|
+
if (ids.has(item.groupId)) delete item.groupId;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// A selected group moves across its siblings as one unit. An individual
|
|
69
|
+
// member moves within its group. Return false when already at the boundary.
|
|
70
|
+
export function reorderElements(scene, members, direction) {
|
|
71
|
+
const layer = editableLayer(scene, members);
|
|
72
|
+
const siblings = scene.elements.filter(item => item.layerId === layer.id);
|
|
73
|
+
const chosen = new Set(members);
|
|
74
|
+
const units = displayUnits(siblings);
|
|
75
|
+
let order = units;
|
|
76
|
+
let selected = units.filter(unit => unit.some(item => chosen.has(item)));
|
|
77
|
+
if (selected.length === 1 && selected[0].length > members.length) {
|
|
78
|
+
order = selected[0];
|
|
79
|
+
selected = members;
|
|
80
|
+
} else if (selected.some(unit => !unit.every(item => chosen.has(item)))) {
|
|
81
|
+
throw new Error('Select complete groups to change their stacking order');
|
|
82
|
+
}
|
|
83
|
+
const moving = new Set(selected);
|
|
84
|
+
let changed = false;
|
|
85
|
+
for (let step = 0; step < order.length; step++) {
|
|
86
|
+
const i = direction === 1 ? order.length - 1 - step : step;
|
|
87
|
+
const next = i + direction;
|
|
88
|
+
if (next < 0 || next >= order.length || !moving.has(order[i]) || moving.has(order[next])) continue;
|
|
89
|
+
[order[i], order[next]] = [order[next], order[i]];
|
|
90
|
+
changed = true;
|
|
91
|
+
}
|
|
92
|
+
if (changed) writeLayerOrder(scene, layer.id, units.flat());
|
|
93
|
+
return changed;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function groupTransformSources(members) {
|
|
97
|
+
return members.flatMap(element => [element, ...element.keyframes].map(target => ({
|
|
98
|
+
target, x: target.x ?? element.x, y: target.y ?? element.y,
|
|
99
|
+
scaleX: target.scaleX ?? element.scaleX, scaleY: target.scaleY ?? element.scaleY,
|
|
100
|
+
rotation: target.rotation ?? element.rotation,
|
|
101
|
+
})));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Apply the same world-space similarity transform to every pose. A uniform
|
|
105
|
+
// scale and rotation preserve tween paths, including skewed or rotated art.
|
|
106
|
+
export function transformMembers(sources, center, offset, scale, angle, stage) {
|
|
107
|
+
const c = Math.cos(angle) * scale, s = Math.sin(angle) * scale;
|
|
108
|
+
const updates = [];
|
|
109
|
+
for (const source of sources) {
|
|
110
|
+
const dx = source.x - center.x, dy = source.y - center.y;
|
|
111
|
+
const pose = {
|
|
112
|
+
x: center.x + c * dx - s * dy + offset.x,
|
|
113
|
+
y: center.y + s * dx + c * dy + offset.y,
|
|
114
|
+
scaleX: source.scaleX * scale,
|
|
115
|
+
scaleY: source.scaleY * scale,
|
|
116
|
+
rotation: source.rotation + angle * 180 / Math.PI,
|
|
117
|
+
};
|
|
118
|
+
if (Math.abs(pose.x) > stage.width * 4 || Math.abs(pose.y) > stage.height * 4 ||
|
|
119
|
+
pose.scaleX < 0.01 || pose.scaleY < 0.01 || pose.scaleX > 100 || pose.scaleY > 100 ||
|
|
120
|
+
Math.abs(pose.rotation) > 36000) return false;
|
|
121
|
+
updates.push(pose);
|
|
122
|
+
}
|
|
123
|
+
updates.forEach((pose, i) => Object.assign(sources[i].target, pose));
|
|
124
|
+
return true;
|
|
125
|
+
}
|