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,431 @@
|
|
|
1
|
+
import { objectAction, removeEventTargets } from './frame-events.js';
|
|
2
|
+
import { removeMissingMasks } from './masks.js';
|
|
3
|
+
import { appearanceFields, appearanceKinds, hasVectorFill } from './vector-style.js';
|
|
4
|
+
import { groupMembers } from './groups.js';
|
|
5
|
+
import { lerpColorTransform } from './color-transform.js';
|
|
6
|
+
|
|
7
|
+
export const POSE_NUMERIC_FIELDS = [
|
|
8
|
+
'x',
|
|
9
|
+
'y',
|
|
10
|
+
'width',
|
|
11
|
+
'height',
|
|
12
|
+
'scaleX',
|
|
13
|
+
'scaleY',
|
|
14
|
+
'rotation',
|
|
15
|
+
'skew',
|
|
16
|
+
'opacity',
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
export const STYLE_NUMERIC_FIELDS = ['strokeWidth', 'fontSize'];
|
|
20
|
+
export const STYLE_COLOR_FIELDS = ['fill', 'stroke', 'textColor'];
|
|
21
|
+
export const STYLE_DISCRETE_FIELDS = ['text', 'fontFamily', 'textAlign', 'bold'];
|
|
22
|
+
export const ALL_STYLE_FIELDS = [
|
|
23
|
+
...STYLE_COLOR_FIELDS,
|
|
24
|
+
...STYLE_NUMERIC_FIELDS,
|
|
25
|
+
...STYLE_DISCRETE_FIELDS,
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
const HEX_COLOR_RE = /^#[0-9a-f]{6}$/i;
|
|
29
|
+
|
|
30
|
+
export function applyEasing(type, progress) {
|
|
31
|
+
if (type === 'easeIn') return progress * progress;
|
|
32
|
+
if (type === 'easeOut') return 1 - (1 - progress) ** 2;
|
|
33
|
+
if (type === 'easeInOut') {
|
|
34
|
+
return progress < 0.5
|
|
35
|
+
? 2 * progress * progress
|
|
36
|
+
: 1 - ((-2 * progress + 2) ** 2) / 2;
|
|
37
|
+
}
|
|
38
|
+
if (type === 'hold') return 0;
|
|
39
|
+
return progress;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function lerpHexColor(fromHex, toHex, t) {
|
|
43
|
+
if (!HEX_COLOR_RE.test(fromHex || '') || !HEX_COLOR_RE.test(toHex || '')) {
|
|
44
|
+
return t >= 1 ? toHex : fromHex;
|
|
45
|
+
}
|
|
46
|
+
if (t <= 0) return fromHex.toLowerCase();
|
|
47
|
+
if (t >= 1) return toHex.toLowerCase();
|
|
48
|
+
const a = Number.parseInt(fromHex.slice(1), 16);
|
|
49
|
+
const b = Number.parseInt(toHex.slice(1), 16);
|
|
50
|
+
const lerpChannel = (c1, c2) => Math.max(0, Math.min(255, Math.round(c1 + (c2 - c1) * t)));
|
|
51
|
+
const r = lerpChannel((a >> 16) & 0xff, (b >> 16) & 0xff);
|
|
52
|
+
const g = lerpChannel((a >> 8) & 0xff, (b >> 8) & 0xff);
|
|
53
|
+
const bl = lerpChannel(a & 0xff, b & 0xff);
|
|
54
|
+
return `#${((1 << 24) | (r << 16) | (g << 8) | bl).toString(16).slice(1)}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function readKeyframeValue(keyframe, element, field) {
|
|
58
|
+
return keyframe[field] !== undefined ? keyframe[field] : element[field];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function copyGeometrySettings(pose, key, element) {
|
|
62
|
+
for (const field of ['starPoints', 'starRadius', 'cornerRadius', 'erasures']) {
|
|
63
|
+
const value = readKeyframeValue(key, element, field);
|
|
64
|
+
if (value !== undefined) pose[field] = value;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function buildKeyframePose(keyframe, element) {
|
|
69
|
+
const pose = { frame: keyframe.frame };
|
|
70
|
+
copyGeometrySettings(pose, keyframe, element);
|
|
71
|
+
if (keyframe.filters) pose.filters = keyframe.filters;
|
|
72
|
+
if (keyframe.blendMode) pose.blendMode = keyframe.blendMode;
|
|
73
|
+
if (element.type === 'path') {
|
|
74
|
+
pose.points = keyframe.points ?? element.points;
|
|
75
|
+
const subpaths = keyframe.subpaths ?? element.subpaths;
|
|
76
|
+
if (subpaths) pose.subpaths = subpaths;
|
|
77
|
+
}
|
|
78
|
+
for (const field of POSE_NUMERIC_FIELDS) {
|
|
79
|
+
pose[field] = readKeyframeValue(keyframe, element, field);
|
|
80
|
+
}
|
|
81
|
+
for (const field of ALL_STYLE_FIELDS) {
|
|
82
|
+
pose[field] = readKeyframeValue(keyframe, element, field);
|
|
83
|
+
}
|
|
84
|
+
// `mirror` flips an object across its own horizontal axis before scale and rotation (SWF art
|
|
85
|
+
// placed with a negative scale); with rotation 180° that is a left–right flip. Set only when true.
|
|
86
|
+
if (readKeyframeValue(keyframe, element, 'mirror')) pose.mirror = true;
|
|
87
|
+
const colorTransform = readKeyframeValue(keyframe, element, 'colorTransform');
|
|
88
|
+
if (colorTransform) pose.colorTransform = colorTransform;
|
|
89
|
+
for (const field of Object.keys(appearanceKinds)) {
|
|
90
|
+
const value = readKeyframeValue(keyframe, element, field);
|
|
91
|
+
if (value !== undefined) pose[field] = value;
|
|
92
|
+
}
|
|
93
|
+
return pose;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function supportedStyleSet(element) {
|
|
97
|
+
if (element.type === 'text') {
|
|
98
|
+
return new Set(['text', 'fontFamily', 'fontSize', 'textColor', 'textAlign', 'bold']);
|
|
99
|
+
}
|
|
100
|
+
const labelFields = ['fontSize', 'textColor'];
|
|
101
|
+
return hasVectorFill(element) || element.type === 'symbol'
|
|
102
|
+
? new Set(['fill', 'stroke', 'strokeWidth', ...labelFields])
|
|
103
|
+
: new Set(['stroke', 'strokeWidth', ...labelFields]);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Project loading and timeline editing keep exposure keys in frame order.
|
|
107
|
+
function keyIndexAt(keys, frame) {
|
|
108
|
+
let low = 0, high = keys.length;
|
|
109
|
+
while (low < high) {
|
|
110
|
+
const mid = (low + high) >>> 1;
|
|
111
|
+
if (keys[mid].frame <= frame) low = mid + 1;
|
|
112
|
+
else high = mid;
|
|
113
|
+
}
|
|
114
|
+
return Math.max(0, low - 1);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Evaluate an element's transform and appearance properties at a 1-based frame.
|
|
119
|
+
*/
|
|
120
|
+
export function poseAt(element, frame, keys = [...(element.keyframes || [])].sort((a, b) => a.frame - b.frame)) {
|
|
121
|
+
if (keys.length === 0) {
|
|
122
|
+
return buildKeyframePose({ frame }, element);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (frame <= keys[0].frame) return buildKeyframePose(keys[0], element);
|
|
126
|
+
if (frame >= keys[keys.length - 1].frame) return buildKeyframePose(keys[keys.length - 1], element);
|
|
127
|
+
|
|
128
|
+
const index = keyIndexAt(keys, frame);
|
|
129
|
+
const from = keys[index];
|
|
130
|
+
const to = keys[index + 1];
|
|
131
|
+
if (frame === from.frame || from.blank || to.blank) return buildKeyframePose(from, element);
|
|
132
|
+
const supported = supportedStyleSet(element);
|
|
133
|
+
|
|
134
|
+
const span = to.frame - from.frame;
|
|
135
|
+
const rawT = span > 0 ? (frame - from.frame) / span : 1;
|
|
136
|
+
const tween = from.tween || 'linear';
|
|
137
|
+
const t = applyEasing(tween, rawT);
|
|
138
|
+
const discreteStep = tween === 'hold' ? 0 : rawT;
|
|
139
|
+
|
|
140
|
+
const pose = { frame };
|
|
141
|
+
copyGeometrySettings(pose, from, element);
|
|
142
|
+
if (from.filters) pose.filters = from.filters;
|
|
143
|
+
if (from.blendMode) pose.blendMode = from.blendMode;
|
|
144
|
+
if (element.type === 'path') {
|
|
145
|
+
pose.points = from.points ?? element.points;
|
|
146
|
+
const subpaths = from.subpaths ?? element.subpaths;
|
|
147
|
+
if (subpaths) pose.subpaths = subpaths;
|
|
148
|
+
}
|
|
149
|
+
for (const field of POSE_NUMERIC_FIELDS) {
|
|
150
|
+
const a = readKeyframeValue(from, element, field);
|
|
151
|
+
const b = readKeyframeValue(to, element, field);
|
|
152
|
+
pose[field] = a + (b - a) * t;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
for (const field of STYLE_COLOR_FIELDS) {
|
|
156
|
+
const a = readKeyframeValue(from, element, field);
|
|
157
|
+
const b = readKeyframeValue(to, element, field);
|
|
158
|
+
const bothSupported = supported.has(field) && from[field] !== undefined && to[field] !== undefined;
|
|
159
|
+
pose[field] = bothSupported ? lerpHexColor(a, b, t) : (discreteStep >= 1 ? b : a);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
for (const field of STYLE_NUMERIC_FIELDS) {
|
|
163
|
+
const a = readKeyframeValue(from, element, field);
|
|
164
|
+
const b = readKeyframeValue(to, element, field);
|
|
165
|
+
const bothSupported = supported.has(field) && typeof from[field] === 'number' && typeof to[field] === 'number';
|
|
166
|
+
pose[field] = bothSupported ? a + (b - a) * t : (discreteStep >= 1 ? b : a);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
for (const field of STYLE_DISCRETE_FIELDS) {
|
|
170
|
+
const a = readKeyframeValue(from, element, field);
|
|
171
|
+
const b = readKeyframeValue(to, element, field);
|
|
172
|
+
pose[field] = discreteStep >= 1 ? b : a;
|
|
173
|
+
}
|
|
174
|
+
if (readKeyframeValue(discreteStep >= 1 ? to : from, element, 'mirror')) pose.mirror = true;
|
|
175
|
+
const colorTransform = tween === 'hold'
|
|
176
|
+
? readKeyframeValue(from, element, 'colorTransform')
|
|
177
|
+
: lerpColorTransform(readKeyframeValue(from, element, 'colorTransform'), readKeyframeValue(to, element, 'colorTransform'), t);
|
|
178
|
+
if (colorTransform) pose.colorTransform = colorTransform;
|
|
179
|
+
|
|
180
|
+
for (const field of Object.keys(appearanceKinds)) {
|
|
181
|
+
const a = readKeyframeValue(from, element, field);
|
|
182
|
+
const b = readKeyframeValue(to, element, field);
|
|
183
|
+
if (a === undefined) continue;
|
|
184
|
+
if (!a || a.type !== b?.type || t === 0) {
|
|
185
|
+
pose[field] = a;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const value = { type: a.type };
|
|
189
|
+
for (const name of appearanceKinds[field][a.type].fields) {
|
|
190
|
+
if (typeof appearanceFields[name].value === 'boolean') { if (a[name]) value[name] = true; continue; }
|
|
191
|
+
value[name] = typeof a[name] === 'number'
|
|
192
|
+
? a[name] + (b[name] - a[name]) * t
|
|
193
|
+
: lerpHexColor(a[name], b[name], t);
|
|
194
|
+
}
|
|
195
|
+
if (a.stops) value.stops = a.stops;
|
|
196
|
+
if (a.matrix) value.matrix = a.matrix;
|
|
197
|
+
if (a.spreadMethod) value.spreadMethod = a.spreadMethod;
|
|
198
|
+
if (a.interpolationMethod) value.interpolationMethod = a.interpolationMethod;
|
|
199
|
+
pose[field] = value;
|
|
200
|
+
}
|
|
201
|
+
return pose;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Ensure a keyframe exists at `frame`, capturing the current evaluated pose and style.
|
|
206
|
+
*/
|
|
207
|
+
export function ensureKeyframe(element, frame) {
|
|
208
|
+
let keyframe = element.keyframes.find(item => item.frame === frame);
|
|
209
|
+
if (!keyframe) {
|
|
210
|
+
keyframe = { ...structuredClone(poseAt(element, frame)), frame, tween: 'linear' };
|
|
211
|
+
element.keyframes.push(keyframe);
|
|
212
|
+
element.keyframes.sort((a, b) => a.frame - b.frame);
|
|
213
|
+
}
|
|
214
|
+
return keyframe;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export function visibleAt(element, frame) {
|
|
218
|
+
const keys = element.keyframes;
|
|
219
|
+
const key = keys[keyIndexAt(keys, frame)];
|
|
220
|
+
return !key?.blank;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export function matrixComponents(pose) {
|
|
224
|
+
if (pose.matrix) return pose.matrix;
|
|
225
|
+
const rotation = (pose.rotation * Math.PI) / 180;
|
|
226
|
+
const skew = (pose.skew * Math.PI) / 180;
|
|
227
|
+
const flip = pose.mirror ? -1 : 1;
|
|
228
|
+
return {
|
|
229
|
+
a: Math.cos(rotation) * pose.scaleX,
|
|
230
|
+
b: Math.sin(rotation) * pose.scaleX,
|
|
231
|
+
c: -Math.sin(rotation + skew) * pose.scaleY * flip,
|
|
232
|
+
d: Math.cos(rotation + skew) * pose.scaleY * flip,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function selectionBounds(scene, members, frame) {
|
|
237
|
+
let left = Infinity, top = Infinity, right = -Infinity, bottom = -Infinity;
|
|
238
|
+
for (const element of members) {
|
|
239
|
+
if (!visibleAt(element, frame) || findElementLayer(scene, element)?.visible === false) continue;
|
|
240
|
+
const pose = poseAt(element, frame);
|
|
241
|
+
for (const x of [-pose.width / 2, pose.width / 2]) {
|
|
242
|
+
for (const y of [-pose.height / 2, pose.height / 2]) {
|
|
243
|
+
const point = pointToWorld({ x, y }, pose);
|
|
244
|
+
left = Math.min(left, point.x);
|
|
245
|
+
right = Math.max(right, point.x);
|
|
246
|
+
top = Math.min(top, point.y);
|
|
247
|
+
bottom = Math.max(bottom, point.y);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (left === Infinity) return null;
|
|
252
|
+
return { x:(left + right) / 2, y:(top + bottom) / 2, width:right-left, height:bottom-top,
|
|
253
|
+
scaleX:1, scaleY:1, rotation:0, skew:0 };
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export function pointToLocal(point, pose) {
|
|
257
|
+
const { a, b, c, d } = matrixComponents(pose);
|
|
258
|
+
const determinant = a * d - b * c;
|
|
259
|
+
if (Math.abs(determinant) < 1e-8) return { x: 0, y: 0 };
|
|
260
|
+
const x = point.x - pose.x;
|
|
261
|
+
const y = point.y - pose.y;
|
|
262
|
+
return {
|
|
263
|
+
x: (d * x - c * y) / determinant,
|
|
264
|
+
y: (-b * x + a * y) / determinant,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export function pointToWorld(point, pose) {
|
|
269
|
+
const { a, b, c, d } = matrixComponents(pose);
|
|
270
|
+
return {
|
|
271
|
+
x: pose.x + a * point.x + c * point.y,
|
|
272
|
+
y: pose.y + b * point.x + d * point.y,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Return scene layers sorted bottom-to-top by stacking order.
|
|
278
|
+
*/
|
|
279
|
+
export function orderedSceneLayers(scene) {
|
|
280
|
+
return [...(scene?.layers || [])].sort((a, b) => a.order - b.order);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Normalize layer ordering and ensure every element belongs to a valid layer.
|
|
285
|
+
*/
|
|
286
|
+
export function normalizeSceneLayers(scene, makeLayerId) {
|
|
287
|
+
if (!Array.isArray(scene.layers) || scene.layers.length === 0) {
|
|
288
|
+
scene.layers = [{
|
|
289
|
+
id: makeLayerId ? makeLayerId('layer') : 'layer-1',
|
|
290
|
+
name: 'Layer 1',
|
|
291
|
+
visible: true,
|
|
292
|
+
locked: false,
|
|
293
|
+
order: 0,
|
|
294
|
+
}];
|
|
295
|
+
}
|
|
296
|
+
scene.layers = orderedSceneLayers(scene).map((layer, index) => ({
|
|
297
|
+
...layer,
|
|
298
|
+
order: index,
|
|
299
|
+
visible: layer.visible !== false,
|
|
300
|
+
locked: Boolean(layer.locked),
|
|
301
|
+
}));
|
|
302
|
+
const validIds = new Set(scene.layers.map(layer => layer.id));
|
|
303
|
+
const fallbackId = scene.layers[0].id;
|
|
304
|
+
for (const element of scene.elements || []) {
|
|
305
|
+
if (!validIds.has(element.layerId)) {
|
|
306
|
+
element.layerId = fallbackId;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return scene.layers;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Return scene elements in stage draw order (bottom layer to top layer).
|
|
314
|
+
*/
|
|
315
|
+
export function orderedSceneElements(scene, { includeHidden = true, frame } = {}) {
|
|
316
|
+
if (!scene) return [];
|
|
317
|
+
const layers = orderedSceneLayers(scene);
|
|
318
|
+
if (layers.length === 0) return (scene.elements || []).filter(element => frame == null || visibleAt(element, frame));
|
|
319
|
+
|
|
320
|
+
const layerRank = new Map();
|
|
321
|
+
const visibleMap = new Map();
|
|
322
|
+
layers.forEach((layer, index) => {
|
|
323
|
+
layerRank.set(layer.id, index);
|
|
324
|
+
visibleMap.set(layer.id, layer.visible !== false);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
return scene.elements
|
|
328
|
+
.map((element, index) => ({ element, index }))
|
|
329
|
+
.filter(({ element }) => (includeHidden || visibleMap.get(element.layerId) !== false) &&
|
|
330
|
+
(frame == null || visibleAt(element, frame)))
|
|
331
|
+
.sort((a, b) => {
|
|
332
|
+
const rankDiff = (layerRank.get(a.element.layerId) ?? 0) - (layerRank.get(b.element.layerId) ?? 0);
|
|
333
|
+
return rankDiff !== 0 ? rankDiff : a.index - b.index;
|
|
334
|
+
})
|
|
335
|
+
.map(({ element }) => element);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export function findElementLayer(scene, element) {
|
|
339
|
+
if (!scene || !element) return null;
|
|
340
|
+
return scene.layers?.find(layer => layer.id === element.layerId) ?? null;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export function isElementLocked(scene, element) {
|
|
344
|
+
return Boolean(findElementLayer(scene, element)?.locked);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export function addLayerToScene(scene, id, name) {
|
|
348
|
+
const resolvedName = typeof name === 'string' && name.trim()
|
|
349
|
+
? name.trim().slice(0, 48)
|
|
350
|
+
: `Layer ${(scene.layers?.length ?? 0) + 1}`;
|
|
351
|
+
const layer = {
|
|
352
|
+
id,
|
|
353
|
+
name: resolvedName,
|
|
354
|
+
visible: true,
|
|
355
|
+
locked: false,
|
|
356
|
+
order: scene.layers.length,
|
|
357
|
+
};
|
|
358
|
+
scene.layers.push(layer);
|
|
359
|
+
normalizeSceneLayers(scene);
|
|
360
|
+
return layer;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export function renameSceneLayer(scene, layerId, name) {
|
|
364
|
+
const trimmed = typeof name === 'string' ? name.trim().slice(0, 48) : '';
|
|
365
|
+
if (!trimmed) throw new Error('Layer name cannot be empty');
|
|
366
|
+
const layer = scene.layers.find(item => item.id === layerId);
|
|
367
|
+
if (!layer) throw new Error(`Layer "${layerId}" does not exist`);
|
|
368
|
+
layer.name = trimmed;
|
|
369
|
+
return layer;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export function reorderSceneLayer(scene, layerId, direction) {
|
|
373
|
+
const ordered = orderedSceneLayers(scene);
|
|
374
|
+
const index = ordered.findIndex(layer => layer.id === layerId);
|
|
375
|
+
if (index < 0) throw new Error(`Layer "${layerId}" does not exist`);
|
|
376
|
+
const targetIndex = direction === 'up' ? index + 1 : index - 1;
|
|
377
|
+
if (targetIndex < 0 || targetIndex >= ordered.length) return false;
|
|
378
|
+
[ordered[index], ordered[targetIndex]] = [ordered[targetIndex], ordered[index]];
|
|
379
|
+
ordered.forEach((layer, idx) => {
|
|
380
|
+
layer.order = idx;
|
|
381
|
+
});
|
|
382
|
+
scene.layers = ordered;
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export function removeSceneLayer(scene, layerId, disposition = null) {
|
|
387
|
+
if (!scene.layers || scene.layers.length <= 1) {
|
|
388
|
+
throw new Error('A scene must keep at least one layer');
|
|
389
|
+
}
|
|
390
|
+
const exists = scene.layers.some(layer => layer.id === layerId);
|
|
391
|
+
if (!exists) throw new Error(`Layer "${layerId}" does not exist`);
|
|
392
|
+
|
|
393
|
+
const members = scene.elements.filter(element => element.layerId === layerId);
|
|
394
|
+
if (members.length > 0) {
|
|
395
|
+
if (disposition === 'delete') {
|
|
396
|
+
removeEventTargets(scene, new Set(members.map(item => item.id)), objectAction, true);
|
|
397
|
+
scene.elements = scene.elements.filter(element => element.layerId !== layerId);
|
|
398
|
+
removeMissingMasks(scene);
|
|
399
|
+
} else if (disposition && typeof disposition.moveToLayerId === 'string') {
|
|
400
|
+
const targetId = disposition.moveToLayerId;
|
|
401
|
+
if (targetId === layerId || !scene.layers.some(layer => layer.id === targetId)) {
|
|
402
|
+
throw new Error('Choose a different destination layer for the remaining elements');
|
|
403
|
+
}
|
|
404
|
+
const moving = new Set(members);
|
|
405
|
+
scene.elements = [...scene.elements.filter(item => !moving.has(item)), ...members];
|
|
406
|
+
members.forEach(element => {
|
|
407
|
+
element.layerId = targetId;
|
|
408
|
+
});
|
|
409
|
+
} else {
|
|
410
|
+
throw new Error(`Layer has ${members.length} element${members.length === 1 ? '' : 's'}; specify a move or delete disposition`);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
scene.layers = scene.layers.filter(layer => layer.id !== layerId);
|
|
415
|
+
normalizeSceneLayers(scene);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
export function moveElementToLayer(scene, elementId, targetLayerId) {
|
|
419
|
+
const element = scene?.elements.find(item => item.id === elementId);
|
|
420
|
+
if (!element) throw new Error(`Element "${elementId}" does not exist`);
|
|
421
|
+
const layer = scene.layers.find(item => item.id === targetLayerId);
|
|
422
|
+
if (!layer) throw new Error(`Layer "${targetLayerId}" does not exist`);
|
|
423
|
+
if (layer.locked || isElementLocked(scene, element)) throw new Error('Unlock the source and destination layers first');
|
|
424
|
+
if (element.layerId !== targetLayerId) {
|
|
425
|
+
const members = groupMembers(scene, element);
|
|
426
|
+
for (const member of members) member.layerId = targetLayerId;
|
|
427
|
+
const moving = new Set(members);
|
|
428
|
+
scene.elements = [...scene.elements.filter(item => !moving.has(item)), ...members];
|
|
429
|
+
}
|
|
430
|
+
return element;
|
|
431
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export function readNumber(value, label, min, max, fallback) {
|
|
2
|
+
const resolved = value === undefined ? fallback : value;
|
|
3
|
+
if (typeof resolved !== 'number' || !Number.isFinite(resolved)) {
|
|
4
|
+
throw new Error(`${label} must be a finite number`);
|
|
5
|
+
}
|
|
6
|
+
if (resolved < min || resolved > max) {
|
|
7
|
+
throw new Error(`${label} must be between ${min} and ${max}`);
|
|
8
|
+
}
|
|
9
|
+
return resolved;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function readInteger(value, label, min, max, fallback) {
|
|
13
|
+
const resolved = value === undefined ? fallback : value;
|
|
14
|
+
if (typeof resolved !== 'number' || !Number.isInteger(resolved)) {
|
|
15
|
+
throw new Error(`${label} must be an integer`);
|
|
16
|
+
}
|
|
17
|
+
if (resolved < min || resolved > max) {
|
|
18
|
+
throw new Error(`${label} must be between ${min} and ${max}`);
|
|
19
|
+
}
|
|
20
|
+
return resolved;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Positions may lie far off the stage: Flash movies park art and covers there, and scripts
|
|
24
|
+
// move it in. The bound matches path point coordinates.
|
|
25
|
+
export const POSITION_LIMIT = 100000;
|
|
26
|
+
// SWF headers and DefineSprite both store the timeline frame count as UI16.
|
|
27
|
+
export const MAX_TIMELINE_FRAMES = 0xffff;
|
|
28
|
+
|
|
29
|
+
export function numericPoseRange(property) {
|
|
30
|
+
if (property === 'x' || property === 'y') return [-POSITION_LIMIT, POSITION_LIMIT];
|
|
31
|
+
return staticRanges[property];
|
|
32
|
+
}
|
|
33
|
+
const staticRanges = {
|
|
34
|
+
width: [1, 10000],
|
|
35
|
+
height: [1, 10000],
|
|
36
|
+
scaleX: [0.01, 100],
|
|
37
|
+
scaleY: [0.01, 100],
|
|
38
|
+
rotation: [-36000, 36000],
|
|
39
|
+
skew: [-85, 85],
|
|
40
|
+
opacity: [0, 1],
|
|
41
|
+
strokeWidth: [0, 3276.75],
|
|
42
|
+
fontSize: [6, 240],
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Flash stores frames per second in an unsigned 8.8 fixed-point header field.
|
|
46
|
+
export const stageRanges = { width: [160, 2400], height: [120, 1600], frameRate: [1 / 256, 65535 / 256] };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { maskSources } from './masks.js';
|
|
2
|
+
import { displayUnits } from './groups.js';
|
|
3
|
+
import { findElementLayer, orderedSceneElements } from './model.js';
|
|
4
|
+
import { validateButtonAction } from './project-io.js';
|
|
5
|
+
|
|
6
|
+
export function renderObjects(panel, project, scene, selectedIds, select, locked) {
|
|
7
|
+
const previous = panel.contains(document.activeElement) ? document.activeElement.dataset.focusKey : null;
|
|
8
|
+
panel.replaceChildren();
|
|
9
|
+
const sources = maskSources(scene);
|
|
10
|
+
for (const unit of displayUnits(orderedSceneElements(scene)).reverse()) {
|
|
11
|
+
if (unit.length > 1) {
|
|
12
|
+
const group = document.createElement('button');
|
|
13
|
+
group.type = 'button';
|
|
14
|
+
group.dataset.focusKey = 'group:' + unit[0].groupId;
|
|
15
|
+
group.className = 'element-entry group-entry';
|
|
16
|
+
group.textContent = `Group · ${unit[0].name} + ${unit.length - 1}`;
|
|
17
|
+
group.setAttribute('aria-pressed', String(unit.every(item => selectedIds.includes(item.id))));
|
|
18
|
+
group.disabled = locked;
|
|
19
|
+
group.addEventListener('click', event => select(unit, event.shiftKey));
|
|
20
|
+
panel.append(group);
|
|
21
|
+
}
|
|
22
|
+
for (const element of [...unit].reverse()) {
|
|
23
|
+
const button = document.createElement('button');
|
|
24
|
+
button.type = 'button';
|
|
25
|
+
button.dataset.focusKey = 'object:' + element.id;
|
|
26
|
+
const active = selectedIds.includes(element.id);
|
|
27
|
+
button.className = `element-entry${active ? ' is-active' : ''}${unit.length > 1 ? ' group-member' : ''}`;
|
|
28
|
+
button.setAttribute('aria-pressed', String(active));
|
|
29
|
+
button.disabled = locked;
|
|
30
|
+
button.addEventListener('click', event => select([element], event.shiftKey));
|
|
31
|
+
const label = document.createElement('span');
|
|
32
|
+
label.className = 'entry-label';
|
|
33
|
+
label.textContent = element.name;
|
|
34
|
+
const layer = findElementLayer(scene, element);
|
|
35
|
+
const kind = document.createElement('span');
|
|
36
|
+
kind.className = 'entry-kind';
|
|
37
|
+
const type = element.control ?? element.type;
|
|
38
|
+
kind.textContent = layer ? `${type} · ${layer.name}` : type;
|
|
39
|
+
if (sources.has(element.id)) kind.textContent += ' · Mask';
|
|
40
|
+
if (element.maskId) kind.textContent += ' · Clipped';
|
|
41
|
+
button.append(label, kind);
|
|
42
|
+
if (element.buttonAction) {
|
|
43
|
+
const check = validateButtonAction(element.buttonAction, scene, project);
|
|
44
|
+
const badge = document.createElement('span');
|
|
45
|
+
badge.className = `entry-badge${check.valid ? '' : ' is-invalid'}`;
|
|
46
|
+
badge.textContent = check.valid ? 'BTN' : 'BTN!';
|
|
47
|
+
badge.title = check.valid ? `Button: ${element.buttonAction.type}` : check.message;
|
|
48
|
+
button.append(badge);
|
|
49
|
+
}
|
|
50
|
+
panel.append(button);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (previous) {
|
|
54
|
+
const next = [...panel.children].find(button => button.dataset.focusKey === previous);
|
|
55
|
+
(next ?? panel.firstElementChild ?? document.querySelector('#tab-objects')).focus();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { hasVectorFill, readAppearance } from './vector-style.js';
|
|
2
|
+
import { clippedGeometry } from './vector-geometry.js';
|
|
3
|
+
import { brushOutline, unionCuts, enclosedRegion, ringInPixels } from './vector-cut.js';
|
|
4
|
+
import { pointToLocal, pointToWorld, poseAt, visibleAt } from './model.js';
|
|
5
|
+
|
|
6
|
+
export const paintHints = {
|
|
7
|
+
pencil: 'Drag to draw a freehand path.',
|
|
8
|
+
brush: 'Drag to paint a filled brush stroke.',
|
|
9
|
+
eraser: 'Drag to erase vector artwork on the active layer.',
|
|
10
|
+
bucket: 'Click a closed shape or an area enclosed by strokes on the active layer.',
|
|
11
|
+
ink: 'Click a vector shape to apply the stroke color and size.',
|
|
12
|
+
eyedropper: 'Click to sample a fill. Shift-click to sample a stroke.',
|
|
13
|
+
gradientTransform: 'Drag from the gradient center to its edge. Shift-drag to move the gradient.',
|
|
14
|
+
};
|
|
15
|
+
export const isVector = element => element && !['text', 'bitmap', 'symbol', 'control'].includes(element.type);
|
|
16
|
+
|
|
17
|
+
export function paintStroke(points, size) {
|
|
18
|
+
const rings = brushOutline(points, size);
|
|
19
|
+
return rings.map(ring => ring.map(anchor));
|
|
20
|
+
}
|
|
21
|
+
export function anchor({ x, y }) {
|
|
22
|
+
return { x, y, handleIn: { x: 0, y: 0 }, handleOut: { x: 0, y: 0 } };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function fillEnclosedArea(scene, layer, frame, point) {
|
|
26
|
+
const strokes = [];
|
|
27
|
+
for (const element of scene.elements) {
|
|
28
|
+
if (element.layerId !== layer.id || !isVector(element) || !visibleAt(element, frame)) continue;
|
|
29
|
+
const pose = poseAt(element, frame);
|
|
30
|
+
if (!pose.strokeWidth) continue;
|
|
31
|
+
for (const ring of clippedGeometry(element, pose, pose.erasures ?? []).stroke) {
|
|
32
|
+
const world = ringInPixels(ring).map(p => pointToWorld(p, pose));
|
|
33
|
+
if (pose.mirror) world.reverse();
|
|
34
|
+
strokes.push(world);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return enclosedRegion(strokes, point).map(ring => ring.map(anchor));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function eraseArtwork(scene, layer, frame, points, diameter, set) {
|
|
41
|
+
const outline = brushOutline(points, diameter);
|
|
42
|
+
if (!outline.length) return;
|
|
43
|
+
for (const element of scene.elements) {
|
|
44
|
+
if (element.layerId !== layer.id || !isVector(element) || !visibleAt(element, frame)) continue;
|
|
45
|
+
const pose = poseAt(element, frame);
|
|
46
|
+
const cut = outline.map(ring => ring.map(point => pointToLocal(point, pose)));
|
|
47
|
+
// Restore the winding order after transforming into mirrored artwork.
|
|
48
|
+
if (pose.mirror) cut.forEach(ring => ring.reverse());
|
|
49
|
+
const x = pose.width / 2 + pose.strokeWidth / 2, y = pose.height / 2 + pose.strokeWidth / 2;
|
|
50
|
+
if (element.type !== 'path' && cut.every(ring => ring.every(p => p.x < -x) || ring.every(p => p.x > x)
|
|
51
|
+
|| ring.every(p => p.y < -y) || ring.every(p => p.y > y))) continue;
|
|
52
|
+
if (clippedGeometry(element, pose, cut).overlaps) set(element, 'erasures', unionCuts(pose.erasures ?? [], cut));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function gradientDrag(element, pose, start, end, translate) {
|
|
57
|
+
if (!pose.gradient || !hasVectorFill(element)) return null;
|
|
58
|
+
const a = pointToLocal(start, pose), b = pointToLocal(end, pose);
|
|
59
|
+
const dx = b.x - a.x, dy = b.y - a.y;
|
|
60
|
+
const { width, height, gradient } = pose;
|
|
61
|
+
let matrix;
|
|
62
|
+
if (translate) {
|
|
63
|
+
const angle = (gradient.angle ?? 0) * Math.PI / 180;
|
|
64
|
+
const x = Math.cos(angle), y = Math.sin(angle);
|
|
65
|
+
const span = width * Math.abs(x) + height * Math.abs(y);
|
|
66
|
+
matrix = { ...(gradient.matrix ?? (gradient.type === 'radial'
|
|
67
|
+
? { a: .5, b: 0, c: 0, d: .5, tx: 0, ty: 0 }
|
|
68
|
+
: { a: x*span/(2*width), b: y*span/(2*height), c: -y*span/(2*width), d: x*span/(2*height), tx: 0, ty: 0 })) };
|
|
69
|
+
matrix.tx += dx / width;
|
|
70
|
+
matrix.ty += dy / height;
|
|
71
|
+
} else {
|
|
72
|
+
if (Math.hypot(dx, dy) < .1) return null;
|
|
73
|
+
matrix = { a: dx / width, b: dy / height, c: -dy / width, d: dx / height, tx: a.x / width, ty: a.y / height };
|
|
74
|
+
}
|
|
75
|
+
return readAppearance('gradient', { ...gradient, matrix });
|
|
76
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// SWF placement effects are ordered. Keep the decoder's filter records so both canvas
|
|
2
|
+
// renderers receive the same values, including filter flags, strength and pass count.
|
|
3
|
+
export const blendModes = ['normal', 'normal', 'layer', 'multiply', 'screen', 'lighten', 'darken',
|
|
4
|
+
'difference', 'add', 'subtract', 'invert', 'alpha', 'erase', 'overlay', 'hardlight'];
|
|
5
|
+
|
|
6
|
+
export function readPlacementFilters(raw, label) {
|
|
7
|
+
const invalid = () => { throw new Error(`${label} must contain valid placement filters`); };
|
|
8
|
+
if (!Array.isArray(raw) || raw.length > 255) invalid();
|
|
9
|
+
return raw.map(filter => {
|
|
10
|
+
if (!filter || !['blur', 'glow', 'dropShadow', 'bevel', 'gradientGlow', 'gradientBevel', 'convolution', 'colorMatrix'].includes(filter.type)) invalid();
|
|
11
|
+
const result = { type: filter.type };
|
|
12
|
+
const numbers = (...keys) => {
|
|
13
|
+
for (const key of keys) {
|
|
14
|
+
if (!Number.isFinite(filter[key])) invalid();
|
|
15
|
+
result[key] = filter[key];
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const flags = (...keys) => {
|
|
19
|
+
for (const key of keys) {
|
|
20
|
+
if (typeof filter[key] !== 'boolean') invalid();
|
|
21
|
+
result[key] = filter[key];
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const color = value => {
|
|
25
|
+
if (!value || !['r', 'g', 'b', 'a'].every(key => Number.isInteger(value[key]) && value[key] >= 0 && value[key] <= 255)) invalid();
|
|
26
|
+
return { r: value.r, g: value.g, b: value.b, a: value.a };
|
|
27
|
+
};
|
|
28
|
+
if (filter.type === 'colorMatrix' || filter.type === 'convolution') {
|
|
29
|
+
let size = 20;
|
|
30
|
+
if (filter.type === 'convolution') {
|
|
31
|
+
numbers('matrixX', 'matrixY', 'bias', 'divisor');
|
|
32
|
+
if (![filter.matrixX, filter.matrixY].every(n => Number.isInteger(n) && n >= 0 && n <= 255)) invalid();
|
|
33
|
+
size = filter.matrixX * filter.matrixY;
|
|
34
|
+
flags('clamp', 'preserveAlpha');
|
|
35
|
+
result.defaultColor = color(filter.defaultColor);
|
|
36
|
+
}
|
|
37
|
+
if (!Array.isArray(filter.matrix) || filter.matrix.length !== size || !filter.matrix.every(Number.isFinite)) invalid();
|
|
38
|
+
result.matrix = [...filter.matrix];
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
numbers('blurX', 'blurY', 'passes');
|
|
42
|
+
if (filter.type === 'blur') return result;
|
|
43
|
+
numbers('strength');
|
|
44
|
+
flags('inner', 'knockout', 'compositeSource');
|
|
45
|
+
if (filter.type !== 'glow') numbers('angle', 'distance');
|
|
46
|
+
if (filter.type.startsWith('gradient')) {
|
|
47
|
+
flags('onTop');
|
|
48
|
+
if (!Array.isArray(filter.colors) || filter.colors.length > 255 || !Array.isArray(filter.ratios) ||
|
|
49
|
+
filter.colors.length !== filter.ratios.length || !filter.ratios.every(n => Number.isInteger(n) && n >= 0 && n <= 255)) invalid();
|
|
50
|
+
result.colors = filter.colors.map(color);
|
|
51
|
+
result.ratios = [...filter.ratios];
|
|
52
|
+
} else if (filter.type === 'bevel') {
|
|
53
|
+
flags('onTop');
|
|
54
|
+
result.shadowColor = color(filter.shadowColor);
|
|
55
|
+
result.highlightColor = color(filter.highlightColor);
|
|
56
|
+
} else result.color = color(filter.color);
|
|
57
|
+
return result;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Studio's editable vector effect is applied after any imported placement filters.
|
|
62
|
+
export function placementFilters(pose) {
|
|
63
|
+
const filters = pose.filters ?? [];
|
|
64
|
+
const effect = pose.effect;
|
|
65
|
+
if (!effect) return filters;
|
|
66
|
+
const filter = { type: effect.type === 'shadow' ? 'dropShadow' : effect.type, blurX: effect.blurX, blurY: effect.blurY, passes: 1 };
|
|
67
|
+
if (effect.type !== 'blur') {
|
|
68
|
+
const rgb = parseInt(effect.color.slice(1), 16);
|
|
69
|
+
Object.assign(filter, { color: { r: rgb >> 16, g: rgb >> 8 & 255, b: rgb & 255, a: Math.round(effect.alpha * 255) },
|
|
70
|
+
strength: 1, inner: Boolean(effect.inner), knockout: false, compositeSource: true });
|
|
71
|
+
if (effect.type === 'shadow') Object.assign(filter, { angle: effect.angle * Math.PI / 180, distance: effect.distance });
|
|
72
|
+
}
|
|
73
|
+
return [...filters, filter];
|
|
74
|
+
}
|