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,413 @@
|
|
|
1
|
+
// One frame as SVG (studiospec/svg-export.md §11): the display tree Studio's renderer draws,
|
|
2
|
+
// walked into SVG elements. Shapes, bitmaps and text are painted through a recording 2D context,
|
|
3
|
+
// so they have the canvas's geometry; groups keep their transform, opacity, filters and blend mode.
|
|
4
|
+
import { captureDisplayFrame } from './canvas.js';
|
|
5
|
+
import { decodeAsset } from './media-assets.js';
|
|
6
|
+
import { IDENTITY, SvgPath, SvgRecordingContext, fmt, idFor, invert, matrixAttr, multiply, parseColor } from './svg-context.js';
|
|
7
|
+
import { Bitmap } from '../swooflib/bitmap.js';
|
|
8
|
+
import { DisplayObject } from '../swooflib/display.js';
|
|
9
|
+
import { bitmapDisplayImage } from '../swooflib/bitmap-image.js';
|
|
10
|
+
import { SimpleButton } from '../swooflib/loader.js';
|
|
11
|
+
import { simpleButtonState } from '../swooflib/input.js';
|
|
12
|
+
import { effectShadowPlan } from '../swooflib/render.js';
|
|
13
|
+
import { TextField } from '../swooflib/text-field.js';
|
|
14
|
+
import { TextLine } from '../swooflib/text.js';
|
|
15
|
+
import { embeddedGlyphPaths, paintTextField } from '../swooflib/text-paint.js';
|
|
16
|
+
|
|
17
|
+
// While swooflib draws for SVG, `Path2D` is the recording path. Glyph outlines that swooflib
|
|
18
|
+
// caches between draws are kept apart, so canvas paths never reach the SVG and recorded paths
|
|
19
|
+
// never reach the canvas.
|
|
20
|
+
const recordedGlyphPaths = new WeakMap();
|
|
21
|
+
let recording = 0, realPath2D, realGlyphGet, realGlyphSet;
|
|
22
|
+
export function withRecordedPaths(fn) {
|
|
23
|
+
if (!recording++) {
|
|
24
|
+
realPath2D = globalThis.Path2D;
|
|
25
|
+
realGlyphGet = embeddedGlyphPaths.get;
|
|
26
|
+
realGlyphSet = embeddedGlyphPaths.set;
|
|
27
|
+
globalThis.Path2D = SvgPath;
|
|
28
|
+
embeddedGlyphPaths.get = key => recordedGlyphPaths.get(key);
|
|
29
|
+
embeddedGlyphPaths.set = (key, value) => { recordedGlyphPaths.set(key, value); return embeddedGlyphPaths; };
|
|
30
|
+
}
|
|
31
|
+
try { return fn(); }
|
|
32
|
+
finally {
|
|
33
|
+
if (!--recording) {
|
|
34
|
+
globalThis.Path2D = realPath2D;
|
|
35
|
+
delete embeddedGlyphPaths.get;
|
|
36
|
+
delete embeddedGlyphPaths.set;
|
|
37
|
+
if (embeddedGlyphPaths.get !== realGlyphGet) { embeddedGlyphPaths.get = realGlyphGet; embeddedGlyphPaths.set = realGlyphSet; }
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const BLEND = { multiply: 'multiply', screen: 'screen', lighten: 'lighten', darken: 'darken', difference: 'difference',
|
|
43
|
+
overlay: 'overlay', hardlight: 'hard-light', add: 'plus-lighter' };
|
|
44
|
+
|
|
45
|
+
/** Images used by one export: each is embedded once, in its own format where it can be read. */
|
|
46
|
+
export function createSvgImages() {
|
|
47
|
+
const sources = new Map();
|
|
48
|
+
return {
|
|
49
|
+
entries: sources,
|
|
50
|
+
use(source) {
|
|
51
|
+
if (!source) return null;
|
|
52
|
+
let entry = sources.get(source);
|
|
53
|
+
if (!entry) {
|
|
54
|
+
const width = source.naturalWidth || source.videoWidth || source.width || 0;
|
|
55
|
+
const height = source.naturalHeight || source.videoHeight || source.height || 0;
|
|
56
|
+
if (!width || !height) return null;
|
|
57
|
+
entry = { id: `img${sources.size}`, width, height, href: null };
|
|
58
|
+
sources.set(source, entry);
|
|
59
|
+
}
|
|
60
|
+
return entry;
|
|
61
|
+
},
|
|
62
|
+
async resolve() {
|
|
63
|
+
for (const [source, entry] of sources) {
|
|
64
|
+
if (entry.href) continue;
|
|
65
|
+
const src = source.currentSrc || source.src;
|
|
66
|
+
if (src?.startsWith('data:')) { entry.href = src; continue; }
|
|
67
|
+
if (src) {
|
|
68
|
+
try {
|
|
69
|
+
const blob = await (await fetch(src)).blob();
|
|
70
|
+
if (/^image\//.test(blob.type)) {
|
|
71
|
+
entry.href = await new Promise((resolve, reject) => {
|
|
72
|
+
const reader = new FileReader();
|
|
73
|
+
reader.onload = () => resolve(reader.result);
|
|
74
|
+
reader.onerror = reject;
|
|
75
|
+
reader.readAsDataURL(blob);
|
|
76
|
+
});
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
} catch {}
|
|
80
|
+
}
|
|
81
|
+
const canvas = document.createElement('canvas');
|
|
82
|
+
canvas.width = entry.width;
|
|
83
|
+
canvas.height = entry.height;
|
|
84
|
+
canvas.getContext('2d').drawImage(source, 0, 0);
|
|
85
|
+
entry.href = canvas.toDataURL('image/png');
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let measureContext;
|
|
92
|
+
/** Measures text with a real canvas context, as the canvas renderer does. */
|
|
93
|
+
export function measureText(font, text, letterSpacing, kerning, baseline = 'alphabetic') {
|
|
94
|
+
measureContext ??= document.createElement('canvas').getContext('2d');
|
|
95
|
+
measureContext.font = font;
|
|
96
|
+
if ('letterSpacing' in measureContext) measureContext.letterSpacing = letterSpacing || '0px';
|
|
97
|
+
if ('fontKerning' in measureContext) measureContext.fontKerning = kerning || 'auto';
|
|
98
|
+
measureContext.textBaseline = baseline;
|
|
99
|
+
return measureContext.measureText(text);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function localMatrix(node) {
|
|
103
|
+
const m = node.transform?.matrix;
|
|
104
|
+
if (m) return [m.a, m.b, m.c, m.d, m.tx, m.ty];
|
|
105
|
+
const angle = (+node.rotation || 0) * Math.PI / 180;
|
|
106
|
+
const sx = node.scaleX ?? 1, sy = node.scaleY ?? 1;
|
|
107
|
+
return [Math.cos(angle) * sx, Math.sin(angle) * sx, -Math.sin(angle) * sy, Math.cos(angle) * sy, +node.x || 0, +node.y || 0];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// As in renderDisplayTree: a display object's alpha multiplier up to 1 is its `alpha`, which is
|
|
111
|
+
// written as `opacity`, so the colour transform leaves it out.
|
|
112
|
+
function colorTransformOf(node) {
|
|
113
|
+
const ct = node.transform?._colorTransform || node.colorTransform;
|
|
114
|
+
if (!ct) return null;
|
|
115
|
+
const alphaMultiplier = node instanceof DisplayObject && (ct.alphaMultiplier ?? 1) <= 1 ? 1 : (ct.alphaMultiplier ?? 1);
|
|
116
|
+
const identity = ct.redMultiplier === 1 && ct.greenMultiplier === 1 && ct.blueMultiplier === 1 && alphaMultiplier === 1 &&
|
|
117
|
+
!ct.redOffset && !ct.greenOffset && !ct.blueOffset && !ct.alphaOffset;
|
|
118
|
+
return identity ? null : { redMultiplier: ct.redMultiplier, greenMultiplier: ct.greenMultiplier, blueMultiplier: ct.blueMultiplier,
|
|
119
|
+
alphaMultiplier, redOffset: ct.redOffset, greenOffset: ct.greenOffset, blueOffset: ct.blueOffset, alphaOffset: ct.alphaOffset };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Flash blurs are box blurs repeated `passes` times; the matching Gaussian has the same variance.
|
|
123
|
+
function sigma(radius, passes) {
|
|
124
|
+
const width = 2 * radius + 1;
|
|
125
|
+
return passes > 0 ? Math.sqrt(passes * (width * width - 1) / 12) : 0;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const parseMatrix = text => text?.startsWith('matrix(') ? text.slice(7, -1).split(',').map(Number) : IDENTITY;
|
|
129
|
+
|
|
130
|
+
/** The bounds of what an element tree draws, in its own space, or null. `sizeOf(href)` sizes images. */
|
|
131
|
+
export function elementBounds(element, sizeOf = () => null) {
|
|
132
|
+
let box = null;
|
|
133
|
+
const add = (m, x, y) => {
|
|
134
|
+
const [px, py] = [m[0] * x + m[2] * y + m[4], m[1] * x + m[3] * y + m[5]];
|
|
135
|
+
if (!Number.isFinite(px) || !Number.isFinite(py)) return;
|
|
136
|
+
box = box ? [Math.min(box[0], px), Math.min(box[1], py), Math.max(box[2], px), Math.max(box[3], py)] : [px, py, px, py];
|
|
137
|
+
};
|
|
138
|
+
const visit = (item, m) => {
|
|
139
|
+
if (['clipPath', 'filter', 'linearGradient', 'radialGradient', 'pattern'].includes(item.tag)) return;
|
|
140
|
+
const own = item.attrs.transform ? multiply(m, parseMatrix(item.attrs.transform)) : m;
|
|
141
|
+
if (item.tag === 'path') {
|
|
142
|
+
const numbers = (item.attrs.d.match(/-?\d*\.?\d+(?:e[-+]?\d+)?/gi) ?? []).map(Number);
|
|
143
|
+
const stroke = item.attrs.stroke && item.attrs.stroke !== 'none' ? (+item.attrs['stroke-width'] || 1) * 2 : 0;
|
|
144
|
+
for (let i = 0; i + 1 < numbers.length; i += 2) {
|
|
145
|
+
add(own, numbers[i] - stroke, numbers[i + 1] - stroke);
|
|
146
|
+
add(own, numbers[i] + stroke, numbers[i + 1] + stroke);
|
|
147
|
+
}
|
|
148
|
+
} else if (item.tag === 'use') {
|
|
149
|
+
const size = sizeOf(item.attrs.href);
|
|
150
|
+
if (size) { add(own, 0, 0); add(own, size.width, 0); add(own, 0, size.height); add(own, size.width, size.height); }
|
|
151
|
+
} else if (item.tag === 'text') {
|
|
152
|
+
const size = +(/(\d+(?:\.\d+)?)px/.exec(item.attrs.style ?? '')?.[1] ?? 12);
|
|
153
|
+
const x = +item.attrs.x, y = +item.attrs.y, width = item.text.length * size;
|
|
154
|
+
add(own, x - width, y - size * 1.5); add(own, x + width, y + size);
|
|
155
|
+
} else if (item.tag === 'rect') {
|
|
156
|
+
add(own, 0, 0); add(own, +item.attrs.width || 0, +item.attrs.height || 0);
|
|
157
|
+
}
|
|
158
|
+
for (const child of item.children) visit(child, own);
|
|
159
|
+
};
|
|
160
|
+
for (const child of element.children) visit(child, IDENTITY);
|
|
161
|
+
return box && { x: box[0], y: box[1], width: box[2] - box[0], height: box[3] - box[1] };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The SVG filter for a node's colour transform and filters, or null. Sizes are in stage pixels,
|
|
166
|
+
* converted to the node's own space (`world`). Returns `{ element, pad }`, `pad` in stage pixels.
|
|
167
|
+
*/
|
|
168
|
+
function filterFor(bounds, ct, filters, world, key, report) {
|
|
169
|
+
const primitives = [];
|
|
170
|
+
let current = 'SourceGraphic', count = 0, pad = 0;
|
|
171
|
+
const scaleX = Math.hypot(world[0], world[1]) || 1, scaleY = Math.hypot(world[2], world[3]) || 1;
|
|
172
|
+
const inverse = invert(world);
|
|
173
|
+
const add = (tag, attrs, children = []) => {
|
|
174
|
+
const result = `r${count}`;
|
|
175
|
+
primitives.push({ tag, key: `f${count++}`, attrs: { ...attrs, result }, children });
|
|
176
|
+
return result;
|
|
177
|
+
};
|
|
178
|
+
const deviation = plan => `${fmt(sigma(plan.radiusX, plan.passes) / scaleX)} ${fmt(sigma(plan.radiusY, plan.passes) / scaleY)}`;
|
|
179
|
+
if (ct) {
|
|
180
|
+
const am = ct.alphaMultiplier ?? 1;
|
|
181
|
+
current = add('feColorMatrix', { in: current, type: 'matrix', values: [
|
|
182
|
+
ct.redMultiplier, 0, 0, 0, (ct.redOffset || 0) / 255, 0, ct.greenMultiplier, 0, 0, (ct.greenOffset || 0) / 255,
|
|
183
|
+
0, 0, ct.blueMultiplier, 0, (ct.blueOffset || 0) / 255, 0, 0, 0, am, (ct.alphaOffset || 0) / 255].map(fmt).join(' ') });
|
|
184
|
+
}
|
|
185
|
+
for (const filter of filters ?? []) {
|
|
186
|
+
if (!filter) continue;
|
|
187
|
+
const kind = filter._swoofFilterKind || filter.type;
|
|
188
|
+
if (kind === 'blur') {
|
|
189
|
+
const passes = filter.passes ?? filter.quality ?? 1;
|
|
190
|
+
const plan = { passes: Math.max(0, Math.min(31, passes | 0)), radiusX: (Math.max(1, Math.min(255, +filter.blurX || 0)) - 1) / 2,
|
|
191
|
+
radiusY: (Math.max(1, Math.min(255, +filter.blurY || 0)) - 1) / 2 };
|
|
192
|
+
if (!plan.passes) continue;
|
|
193
|
+
current = add('feGaussianBlur', { in: current, stdDeviation: deviation(plan) });
|
|
194
|
+
pad = Math.max(pad, 3 * sigma(Math.max(plan.radiusX, plan.radiusY), plan.passes));
|
|
195
|
+
} else if (kind === 'glow' || kind === 'shadow' || kind === 'dropShadow') {
|
|
196
|
+
const plan = effectShadowPlan(filter, kind);
|
|
197
|
+
const { r, g, b, a } = plan.color;
|
|
198
|
+
const source = current;
|
|
199
|
+
// Shadows are offset in stage space, whatever the node's own rotation and scale.
|
|
200
|
+
const offset = inverse ? [inverse[0] * plan.dx + inverse[2] * plan.dy, inverse[1] * plan.dx + inverse[3] * plan.dy] : [plan.dx, plan.dy];
|
|
201
|
+
let shape = plan.inner
|
|
202
|
+
? add('feColorMatrix', { in: source, type: 'matrix', values: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 1' })
|
|
203
|
+
: source;
|
|
204
|
+
if (plan.blur.passes) shape = add('feGaussianBlur', { in: shape, stdDeviation: deviation(plan.blur) });
|
|
205
|
+
if (plan.dx || plan.dy) shape = add('feOffset', { in: shape, dx: fmt(offset[0]), dy: fmt(offset[1]) });
|
|
206
|
+
let effect = add('feColorMatrix', { in: shape, type: 'matrix',
|
|
207
|
+
values: `0 0 0 0 ${fmt(r / 255)} 0 0 0 0 ${fmt(g / 255)} 0 0 0 0 ${fmt(b / 255)} 0 0 0 ${fmt(plan.strength)} 0` });
|
|
208
|
+
if (a < 1) effect = add('feComponentTransfer', { in: effect }, [{ tag: 'feFuncA', key: 'a', attrs: { type: 'linear', slope: fmt(a) }, children: [] }]);
|
|
209
|
+
if (plan.inner) {
|
|
210
|
+
effect = add('feComposite', { in: effect, in2: source, operator: 'in' });
|
|
211
|
+
current = plan.showSource
|
|
212
|
+
? add('feMerge', {}, [{ tag: 'feMergeNode', key: 'a', attrs: { in: source }, children: [] }, { tag: 'feMergeNode', key: 'b', attrs: { in: effect }, children: [] }])
|
|
213
|
+
: effect;
|
|
214
|
+
} else {
|
|
215
|
+
if (plan.cutOuter) effect = add('feComposite', { in: effect, in2: source, operator: 'out' });
|
|
216
|
+
current = plan.showSource
|
|
217
|
+
? add('feMerge', {}, [{ tag: 'feMergeNode', key: 'a', attrs: { in: effect }, children: [] }, { tag: 'feMergeNode', key: 'b', attrs: { in: source }, children: [] }])
|
|
218
|
+
: effect;
|
|
219
|
+
}
|
|
220
|
+
pad = Math.max(pad, 3 * sigma(Math.max(plan.blur.radiusX, plan.blur.radiusY), plan.blur.passes) + Math.hypot(plan.dx, plan.dy));
|
|
221
|
+
} else if ((!filter.type || filter.type === 'colorMatrix') && Array.isArray(filter.matrix) && filter.matrix.length >= 20) {
|
|
222
|
+
current = add('feColorMatrix', { in: current, type: 'matrix',
|
|
223
|
+
values: filter.matrix.slice(0, 20).map((value, i) => fmt(i % 5 === 4 ? value / 255 : value)).join(' ') });
|
|
224
|
+
} else if (kind === 'convolution' && Array.isArray(filter.matrix) && filter.matrixX > 0 && filter.matrixY > 0) {
|
|
225
|
+
current = add('feConvolveMatrix', { in: current, order: `${filter.matrixX} ${filter.matrixY}`, kernelMatrix: filter.matrix.map(fmt).join(' '),
|
|
226
|
+
divisor: fmt(filter.divisor || 1), bias: fmt((filter.bias || 0) / 255), preserveAlpha: filter.preserveAlpha === false ? 'false' : 'true' });
|
|
227
|
+
} else report(`${kind ?? 'Unknown'} filters (left out)`);
|
|
228
|
+
}
|
|
229
|
+
if (!primitives.length) return null;
|
|
230
|
+
// The filter region holds the node and its effect: bounds in the node's space, plus the pad.
|
|
231
|
+
const padX = pad / scaleX + 2, padY = pad / scaleY + 2;
|
|
232
|
+
const region = bounds && Number.isFinite(bounds.width) && bounds.width >= 0
|
|
233
|
+
? { filterUnits: 'userSpaceOnUse', x: fmt(bounds.x - padX), y: fmt(bounds.y - padY), width: fmt(bounds.width + 2 * padX), height: fmt(bounds.height + 2 * padY) }
|
|
234
|
+
: { x: '-50%', y: '-50%', width: '200%', height: '200%' };
|
|
235
|
+
return { tag: 'filter', key, attrs: { id: idFor(key), 'color-interpolation-filters': 'sRGB', ...region }, children: primitives };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Walks display objects into SVG elements. `images` is a createSvgImages() registry; `report`
|
|
240
|
+
* collects what was left out or approximated; `fonts` collects the fonts text uses.
|
|
241
|
+
*/
|
|
242
|
+
export function createSvgWalker({ images, report = () => {}, fonts = new Set(), measure = measureText }) {
|
|
243
|
+
const sizeOf = href => [...images.entries.values()].find(entry => `#${entry.id}` === href);
|
|
244
|
+
function paintInto(element, path, world, paint) {
|
|
245
|
+
const ctx = new SvgRecordingContext({ base: world, prefix: `${path}/`, image: source => images.use(bitmapDisplayImage(source?.bitmapData || source) || source), measure, report });
|
|
246
|
+
try { withRecordedPaths(() => paint(ctx)); } catch (error) { report(`Artwork that could not be drawn (${error.message})`); }
|
|
247
|
+
for (const item of ctx.elements) {
|
|
248
|
+
element.children.push(item);
|
|
249
|
+
collectFonts(item);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function collectFonts(item) {
|
|
253
|
+
if (item.font) {
|
|
254
|
+
for (const family of item.font.replace(/^.*?\d+(?:\.\d+)?px\s*(?:\/\s*\S+\s*)?/, '').split(',')) {
|
|
255
|
+
const name = family.trim().replace(/^["']|["']$/g, '');
|
|
256
|
+
if (name && !/^(serif|sans-serif|monospace|cursive|fantasy|system-ui)$/.test(name)) fonts.add(name);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
for (const child of item.children ?? []) collectFonts(child);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function walk(node, parentWorld, parentPath, index) {
|
|
263
|
+
if (!node || node.visible === false) return null;
|
|
264
|
+
const key = node._svgKey ?? `n${index}`;
|
|
265
|
+
const path = `${parentPath}/${key}`;
|
|
266
|
+
const local = localMatrix(node);
|
|
267
|
+
const world = multiply(parentWorld, local);
|
|
268
|
+
const alpha = node.alpha == null ? 1 : Math.max(0, Math.min(1, +node.alpha));
|
|
269
|
+
const element = { tag: 'g', key, attrs: { transform: matrixAttr(local), opacity: fmt(alpha) }, children: [] };
|
|
270
|
+
if (node.transform?.matrix3D) report('3D perspective (drawn flat)');
|
|
271
|
+
if (node.mask) report('Masks set by scripts (left out)');
|
|
272
|
+
const blend = node.blendMode && node.blendMode !== 'normal' ? node.blendMode : null;
|
|
273
|
+
if (blend) {
|
|
274
|
+
if (BLEND[blend]) element.attrs.style = `mix-blend-mode:${BLEND[blend]}`;
|
|
275
|
+
else if (blend === 'subtract' || blend === 'invert') { element.attrs.style = 'mix-blend-mode:difference'; report(`The ${blend} blend mode (drawn as difference)`); }
|
|
276
|
+
else if (blend === 'layer') element.attrs.style = 'isolation:isolate';
|
|
277
|
+
else report(`The ${blend} blend mode (left out)`);
|
|
278
|
+
}
|
|
279
|
+
let content = element;
|
|
280
|
+
const scroll = node._scrollRect;
|
|
281
|
+
if (scroll && scroll.width > 0 && scroll.height > 0) {
|
|
282
|
+
const clipKey = `${path}#scroll`;
|
|
283
|
+
element.children.push({ tag: 'clipPath', key: 'scroll', attrs: { id: idFor(clipKey), clipPathUnits: 'userSpaceOnUse' }, children: [
|
|
284
|
+
{ tag: 'rect', key: 'r', attrs: { width: fmt(scroll.width), height: fmt(scroll.height) }, children: [] }] });
|
|
285
|
+
content = { tag: 'g', key: 'scrolled', attrs: { transform: matrixAttr([1, 0, 0, 1, -Math.trunc(scroll.x), -Math.trunc(scroll.y)]) }, children: [] };
|
|
286
|
+
element.children.push({ tag: 'g', key: 'scrollclip', attrs: { 'clip-path': `url(#${idFor(clipKey)})` }, children: [content] });
|
|
287
|
+
}
|
|
288
|
+
const contentWorld = content === element ? world : multiply(world, [1, 0, 0, 1, -Math.trunc(scroll.x), -Math.trunc(scroll.y)]);
|
|
289
|
+
const contentPath = content === element ? path : `${path}/scrollclip/scrolled`;
|
|
290
|
+
if (node._swoofTimelineCanvas) {
|
|
291
|
+
report('Artwork the player drew as a bitmap (embedded as an image)');
|
|
292
|
+
paintInto(content, contentPath, contentWorld, ctx => ctx.drawImage(node._swoofTimelineCanvas, 0, 0));
|
|
293
|
+
}
|
|
294
|
+
if (!node._swoofAuthoredLeaf && node.graphics && typeof node.graphics._paint === 'function') {
|
|
295
|
+
paintInto(content, contentPath, contentWorld, ctx => node.graphics._paint(ctx, false));
|
|
296
|
+
}
|
|
297
|
+
if (!node._swoofAuthoredLeaf && (node instanceof Bitmap || node.bitmapData?._img)) {
|
|
298
|
+
const image = bitmapDisplayImage(node.bitmapData) || node._img;
|
|
299
|
+
if (image) paintInto(content, contentPath, contentWorld, ctx => { ctx.imageSmoothingEnabled = !!node.smoothing; ctx.drawImage(image, 0, 0); });
|
|
300
|
+
}
|
|
301
|
+
if (node instanceof TextField) paintInto(content, contentPath, contentWorld, ctx => paintTextField(ctx, node));
|
|
302
|
+
if (node instanceof TextLine) report('Flash text engine lines (left out)');
|
|
303
|
+
if (node instanceof SimpleButton) {
|
|
304
|
+
const state = simpleButtonState(node);
|
|
305
|
+
const child = state && walk(state, contentWorld, contentPath, 'state');
|
|
306
|
+
if (child) content.children.push(child);
|
|
307
|
+
}
|
|
308
|
+
const kids = node._children ?? [];
|
|
309
|
+
const used = new Set();
|
|
310
|
+
for (let i = 0; i < kids.length; i++) {
|
|
311
|
+
const child = walk(kids[i], contentWorld, contentPath, i);
|
|
312
|
+
if (!child) continue;
|
|
313
|
+
// Keys are unique among siblings.
|
|
314
|
+
let childKey = child.key;
|
|
315
|
+
for (let n = 2; used.has(childKey); n++) childKey = `${child.key}*${n}`;
|
|
316
|
+
used.add(childKey);
|
|
317
|
+
child.key = childKey;
|
|
318
|
+
content.children.push(child);
|
|
319
|
+
}
|
|
320
|
+
const ct = colorTransformOf(node);
|
|
321
|
+
if (ct || node.filters?.length) {
|
|
322
|
+
const filter = filterFor(elementBounds(element, sizeOf), ct, node.filters, world, `${path}#filter`, report);
|
|
323
|
+
if (filter) {
|
|
324
|
+
element.children.unshift(filter);
|
|
325
|
+
element.attrs.filter = `url(#${filter.attrs.id})`;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return element;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/** A strip of the frame: its display objects inside its mask clips, all in stage space. */
|
|
332
|
+
function strip(root, clips, key) {
|
|
333
|
+
const element = { tag: 'g', key, attrs: {}, children: [] };
|
|
334
|
+
let content = element;
|
|
335
|
+
clips.forEach((clip, index) => {
|
|
336
|
+
const clipKey = `${key}/c${index}`;
|
|
337
|
+
const m = clip.matrix;
|
|
338
|
+
element.children.push({ tag: 'clipPath', key: `c${index}`, attrs: { id: idFor(clipKey), clipPathUnits: 'userSpaceOnUse' }, children: [
|
|
339
|
+
{ tag: 'path', key: 'p', attrs: { d: new SvgPath(clip.data).toString(), transform: matrixAttr(m ? [m.a, m.b, m.c, m.d, m.tx, m.ty] : IDENTITY),
|
|
340
|
+
...(clip.rule === 'evenodd' && { 'clip-rule': 'evenodd' }) }, children: [] }] });
|
|
341
|
+
const wrapper = { tag: 'g', key: `w${index}`, attrs: { 'clip-path': `url(#${idFor(clipKey)})` }, children: [] };
|
|
342
|
+
content.children.push(wrapper);
|
|
343
|
+
content = wrapper;
|
|
344
|
+
});
|
|
345
|
+
const path = `${key}${clips.map((_, i) => `/w${i}`).join('')}`;
|
|
346
|
+
const kids = root._children ?? [];
|
|
347
|
+
for (let i = 0; i < kids.length; i++) {
|
|
348
|
+
const child = walk(kids[i], IDENTITY, path, i);
|
|
349
|
+
if (child) content.children.push(child);
|
|
350
|
+
}
|
|
351
|
+
return element;
|
|
352
|
+
}
|
|
353
|
+
return { walk, strip };
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Captures one frame as an SVG element tree (the stage's content, in stage space). Arguments as
|
|
358
|
+
* for renderCaptureFrame, plus the walker. Returns `{ tree, timelines }`.
|
|
359
|
+
*/
|
|
360
|
+
export function captureSvgFrame(walker, { scene, symbols, assets, clocks, playhead, hiddenIds }) {
|
|
361
|
+
const tree = { tag: 'g', key: 'stage', attrs: {}, children: [] };
|
|
362
|
+
const counts = new Map();
|
|
363
|
+
// Mask paths are made while the frame is built; they are recorded too, and read as path data.
|
|
364
|
+
const timelines = withRecordedPaths(() => captureDisplayFrame({ scene, symbols, assets, clocks, playhead, hiddenIds, onFlush: (root, clips) => {
|
|
365
|
+
const signature = clips.map(clip => clip.key ?? '?').join('+') || 'none';
|
|
366
|
+
const n = (counts.get(signature) ?? 0) + 1;
|
|
367
|
+
counts.set(signature, n);
|
|
368
|
+
tree.children.push(walker.strip(root, clips, `strip:${signature}:${n}`));
|
|
369
|
+
} }));
|
|
370
|
+
return { tree, timelines };
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const DEFAULTS = { transform: 'matrix(1,0,0,1,0,0)', opacity: '1', 'fill-opacity': '1', 'stroke-opacity': '1', 'stop-opacity': '1' };
|
|
374
|
+
const escape = text => String(text).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
375
|
+
|
|
376
|
+
/** Writes an element tree as SVG markup. `extra(element)` adds markup inside an element (animations). */
|
|
377
|
+
export function writeElement(element, extra = () => '', dropDefaults = true) {
|
|
378
|
+
let out = `<${element.tag}`;
|
|
379
|
+
for (const [name, value] of Object.entries(element.attrs)) {
|
|
380
|
+
if (value == null || (dropDefaults && DEFAULTS[name] === value)) continue;
|
|
381
|
+
out += ` ${name}="${escape(value)}"`;
|
|
382
|
+
}
|
|
383
|
+
const inner = (element.text != null ? escape(element.text) : '') + extra(element) +
|
|
384
|
+
element.children.map(child => writeElement(child, extra, dropDefaults)).join('');
|
|
385
|
+
return inner ? `${out}>${inner}</${element.tag}>` : `${out}/>`;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/** The SVG document around `content` markup: the stage background, embedded images, size. */
|
|
389
|
+
export function svgDocument({ stage, scale = 1, images, content }) {
|
|
390
|
+
const width = Math.max(1, Math.round(stage.width * scale)), height = Math.max(1, Math.round(stage.height * scale));
|
|
391
|
+
const { rgb, alpha } = parseColor(stage.background ?? '#ffffff');
|
|
392
|
+
const defs = [...images.entries.values()].map(entry =>
|
|
393
|
+
`<image id="${entry.id}" width="${entry.width}" height="${entry.height}" xlink:href="${escape(entry.href ?? '')}"/>`).join('');
|
|
394
|
+
return `<?xml version="1.0" encoding="UTF-8"?>\n<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ` +
|
|
395
|
+
`width="${width}" height="${height}" viewBox="0 0 ${fmt(stage.width)} ${fmt(stage.height)}">` +
|
|
396
|
+
`<rect width="${fmt(stage.width)}" height="${fmt(stage.height)}" fill="${rgb}"${alpha < 1 ? ` fill-opacity="${fmt(alpha)}"` : ''}/>` +
|
|
397
|
+
(defs ? `<defs>${defs}</defs>` : '') +
|
|
398
|
+
`${content}</svg>\n`;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** The frame Preview shows, as an SVG Blob (requirement 11.1). Nothing in the editor changes. */
|
|
402
|
+
export async function renderFrameSvg({ project, stage, scene, playhead, hiddenIds = new Set(), clocks = new Map(), scale = 1 }) {
|
|
403
|
+
await Promise.all((project.assets ?? []).map(asset => decodeAsset(asset).catch(() => null)));
|
|
404
|
+
const images = createSvgImages();
|
|
405
|
+
const notes = new Set(), fonts = new Set();
|
|
406
|
+
const walker = createSvgWalker({ images, report: note => notes.add(note), fonts });
|
|
407
|
+
const { tree } = captureSvgFrame(walker, { scene, symbols: project.symbols ?? [], assets: project.assets ?? [], playhead,
|
|
408
|
+
clocks: new Map([...clocks].map(([id, clock]) => [id, { ...clock }])), hiddenIds: new Set(hiddenIds) });
|
|
409
|
+
await images.resolve();
|
|
410
|
+
const text = svgDocument({ stage, scale, images, content: writeElement(tree) });
|
|
411
|
+
return { blob: new Blob([text], { type: 'image/svg+xml' }), notes: [...notes], fonts: [...fonts].filter(Boolean),
|
|
412
|
+
width: Math.round(stage.width * scale), height: Math.round(stage.height * scale) };
|
|
413
|
+
}
|