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,103 @@
|
|
|
1
|
+
// Boolean operations use 1/1024 px integer coordinates. The project stores ordinary
|
|
2
|
+
// local coordinates, so cuts follow the artwork through transforms and keyframes.
|
|
3
|
+
import Clipper from 'clipper-lib';
|
|
4
|
+
import { hasVectorFill } from './vector-style.js';
|
|
5
|
+
|
|
6
|
+
const units = 1024;
|
|
7
|
+
const integer = ({ x, y }) => ({ X: Math.round(x * units), Y: Math.round(y * units) });
|
|
8
|
+
const pixels = ({ X, Y }) => ({ x: X / units, y: Y / units });
|
|
9
|
+
const { ptSubject, ptClip } = Clipper.PolyType;
|
|
10
|
+
const { pftEvenOdd, pftNonZero } = Clipper.PolyFillType;
|
|
11
|
+
|
|
12
|
+
function combine(subject, clip, operation, subjectRule = pftEvenOdd) {
|
|
13
|
+
const engine = new Clipper.Clipper();
|
|
14
|
+
engine.AddPaths(subject, ptSubject, true);
|
|
15
|
+
engine.AddPaths(clip, ptClip, true);
|
|
16
|
+
const output = [];
|
|
17
|
+
engine.Execute(operation, output, subjectRule, pftNonZero);
|
|
18
|
+
return output;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function expand(lines, radius, closed) {
|
|
22
|
+
const offset = new Clipper.ClipperOffset(2, units * .08);
|
|
23
|
+
offset.AddPaths(lines, Clipper.JoinType.jtRound, closed ? Clipper.EndType.etClosedLine : Clipper.EndType.etOpenRound);
|
|
24
|
+
const result = [];
|
|
25
|
+
offset.Execute(result, radius * units);
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function brushOutline(points, diameter) {
|
|
30
|
+
return expand([points.map(integer)], diameter / 2, false).map(ring => ring.map(pixels));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function unionCuts(previous, added) {
|
|
34
|
+
return combine(previous.map(ring => ring.map(integer)), added.map(ring => ring.map(integer)), Clipper.ClipType.ctUnion, pftNonZero)
|
|
35
|
+
.map(ring => ring.map(pixels));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function flattenContours(replay) {
|
|
39
|
+
const lines = [];
|
|
40
|
+
let line, cursor;
|
|
41
|
+
function to(x, y) {
|
|
42
|
+
cursor = { x, y };
|
|
43
|
+
const point = integer(cursor);
|
|
44
|
+
if (point.X !== line.at(-1)?.X || point.Y !== line.at(-1)?.Y) line.push(point);
|
|
45
|
+
}
|
|
46
|
+
function curve(x1, y1, x2, y2, x, y) {
|
|
47
|
+
const { x: x0, y: y0 } = cursor;
|
|
48
|
+
// Bound the chord error by the cubic's second differences.
|
|
49
|
+
const curvature = Math.max(Math.hypot(x2 - 2*x1 + x0, y2 - 2*y1 + y0),
|
|
50
|
+
Math.hypot(x - 2*x2 + x1, y - 2*y2 + y1));
|
|
51
|
+
const steps = Math.max(1, Math.ceil(Math.sqrt(0.75 * curvature / .12)));
|
|
52
|
+
for (let step = 1; step <= steps; step++) {
|
|
53
|
+
const t = step / steps, u = 1 - t;
|
|
54
|
+
to(u*u*u*x0 + 3*u*u*t*x1 + 3*u*t*t*x2 + t*t*t*x,
|
|
55
|
+
u*u*u*y0 + 3*u*u*t*y1 + 3*u*t*t*y2 + t*t*t*y);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
replay((x, y) => { line = []; lines.push(line); to(x, y); }, to, curve, () => {});
|
|
59
|
+
return lines;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function subtractCuts(replay, element, pose, cuts) {
|
|
63
|
+
const contours = flattenContours(replay);
|
|
64
|
+
const closed = hasVectorFill(element);
|
|
65
|
+
const clip = cuts.map(ring => ring.map(integer));
|
|
66
|
+
const fill = closed ? contours : [];
|
|
67
|
+
const stroke = pose.strokeWidth > 0 ? expand(contours, pose.strokeWidth / 2, closed) : [];
|
|
68
|
+
const cut = region => combine(region, clip, Clipper.ClipType.ctDifference);
|
|
69
|
+
const overlaps = region => region.length && combine(region, clip, Clipper.ClipType.ctIntersection).length > 0;
|
|
70
|
+
return { fill: cut(fill), stroke: cut(stroke), get overlaps() { return !!(overlaps(fill) || overlaps(stroke)); } };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function replayRings(graphics, rings) {
|
|
74
|
+
if (rings.length > 1) graphics.drawPath?.([], [], 'evenOdd');
|
|
75
|
+
for (const ring of rings) {
|
|
76
|
+
const first = ring[0];
|
|
77
|
+
graphics.moveTo(first.X / units, first.Y / units);
|
|
78
|
+
for (let i = 1; i < ring.length; i++) graphics.lineTo(ring[i].X / units, ring[i].Y / units);
|
|
79
|
+
graphics.lineTo(first.X / units, first.Y / units);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// The empty regions inside joined strokes are holes of the union. Child contours
|
|
84
|
+
// are islands of ink inside the chosen region and stay unpainted.
|
|
85
|
+
export function enclosedRegion(strokes, point) {
|
|
86
|
+
const engine = new Clipper.Clipper();
|
|
87
|
+
engine.AddPaths(strokes.map(ring => ring.map(integer)), Clipper.PolyType.ptSubject, true);
|
|
88
|
+
const tree = new Clipper.PolyTree();
|
|
89
|
+
engine.Execute(Clipper.ClipType.ctUnion, tree, pftNonZero, pftNonZero);
|
|
90
|
+
let node = tree;
|
|
91
|
+
const at = integer(point);
|
|
92
|
+
while (true) {
|
|
93
|
+
const child = node.Childs().find(item => Clipper.Clipper.PointInPolygon(at, item.Contour()) === 1);
|
|
94
|
+
if (!child) break;
|
|
95
|
+
node = child;
|
|
96
|
+
}
|
|
97
|
+
if (node === tree || !node.IsHole()) return [];
|
|
98
|
+
return [node, ...node.Childs()].map(item => item.Contour().map(pixels));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function ringInPixels(ring) {
|
|
102
|
+
return ring.map(pixels);
|
|
103
|
+
}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { subtractCuts, replayRings } from './vector-cut.js';
|
|
2
|
+
|
|
3
|
+
import { beginVectorFill, shapePropertyValue } from './vector-style.js';
|
|
4
|
+
|
|
5
|
+
export function regularPolygonPoints(type, width, height, settings = {}) {
|
|
6
|
+
const isStar = type === 'star';
|
|
7
|
+
const count = isStar ? 2 * shapePropertyValue('starPoints', settings) : ({ triangle: 3, diamond: 4, pentagon: 5 }[type] ?? 6);
|
|
8
|
+
return Array.from({ length: count }, (_, index) => {
|
|
9
|
+
const angle = -Math.PI / 2 + (index * Math.PI * 2) / count;
|
|
10
|
+
const radius = isStar && index % 2 ? 0.88 * shapePropertyValue('starRadius', settings) / 100 : 0.88;
|
|
11
|
+
return {
|
|
12
|
+
x: Math.cos(angle) * width * 0.5 * radius,
|
|
13
|
+
y: Math.sin(angle) * height * 0.5 * radius,
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function drawOriginalGeometry(graphics, element, pose) {
|
|
19
|
+
const { width, height } = pose;
|
|
20
|
+
const left = -width / 2;
|
|
21
|
+
const top = -height / 2;
|
|
22
|
+
if (element.type === 'rectangle') {
|
|
23
|
+
graphics.drawRect(left, top, width, height);
|
|
24
|
+
} else if (element.type === 'roundedRectangle') {
|
|
25
|
+
graphics.drawRoundRect(left, top, width, height, Math.min(width, height, 2 * shapePropertyValue('cornerRadius', pose)));
|
|
26
|
+
} else if (element.type === 'circle') {
|
|
27
|
+
graphics.drawCircle(0, 0, Math.min(width, height) / 2);
|
|
28
|
+
} else if (element.type === 'ellipse') {
|
|
29
|
+
graphics.drawEllipse(left, top, width, height);
|
|
30
|
+
} else if (element.type === 'line') {
|
|
31
|
+
graphics.moveTo(left, 0);
|
|
32
|
+
graphics.lineTo(-left, 0);
|
|
33
|
+
} else if (element.type === 'curve') {
|
|
34
|
+
graphics.moveTo(left, height * 0.2);
|
|
35
|
+
graphics.cubicCurveTo(-width * 0.15, -height * 0.7, width * 0.15, height * 0.7, -left, -height * 0.2);
|
|
36
|
+
} else if (element.type === 'path') {
|
|
37
|
+
const points = pose.points;
|
|
38
|
+
if (!points?.length) return;
|
|
39
|
+
const subpaths = element.closed ? pose.subpaths ?? [] : [];
|
|
40
|
+
// Compound paths (holes) fill with the even-odd rule, like SWF shapes and glyphs, unless the
|
|
41
|
+
// path says otherwise (SVG's nonzero, or even-odd for one self-crossing outline).
|
|
42
|
+
const rule = element.fillRule ?? (subpaths.length ? 'evenodd' : 'nonzero');
|
|
43
|
+
if (graphics.drawPath && (rule === 'evenodd' || subpaths.length)) graphics.drawPath([], [], rule === 'evenodd' ? 'evenOdd' : 'nonZero');
|
|
44
|
+
drawContour(graphics, points, element.closed);
|
|
45
|
+
for (const contour of subpaths) drawContour(graphics, contour, true);
|
|
46
|
+
} else {
|
|
47
|
+
const points = regularPolygonPoints(element.type, width, height, pose);
|
|
48
|
+
graphics.moveTo(points[0].x, points[0].y);
|
|
49
|
+
points.slice(1).forEach(point => graphics.lineTo(point.x, point.y));
|
|
50
|
+
graphics.lineTo(points[0].x, points[0].y);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function drawContour(graphics, points, closed) {
|
|
55
|
+
graphics.moveTo(points[0].x, points[0].y);
|
|
56
|
+
for (let index = 1; index < points.length; index += 1) {
|
|
57
|
+
const previous = points[index - 1];
|
|
58
|
+
const current = points[index];
|
|
59
|
+
graphics.cubicCurveTo(
|
|
60
|
+
previous.x + previous.handleOut.x, previous.y + previous.handleOut.y,
|
|
61
|
+
current.x + current.handleIn.x, current.y + current.handleIn.y,
|
|
62
|
+
current.x, current.y,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
if (closed && points.length > 1) {
|
|
66
|
+
const last = points[points.length - 1];
|
|
67
|
+
const first = points[0];
|
|
68
|
+
graphics.cubicCurveTo(
|
|
69
|
+
last.x + last.handleOut.x, last.y + last.handleOut.y,
|
|
70
|
+
first.x + first.handleIn.x, first.y + first.handleIn.y,
|
|
71
|
+
first.x, first.y,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const KAPPA = 0.5522847498307936; // Cubic control distance for a quarter ellipse.
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The authored geometry as absolute SVG path data with `transform` applied to every point.
|
|
80
|
+
* Rectangles and ellipses are written as lines and cubics, so any affine transform is exact.
|
|
81
|
+
* Used to combine several shapes (a symbol used as a mask) into one clip path.
|
|
82
|
+
*/
|
|
83
|
+
export function transformedVectorPathData(element, pose, transform) {
|
|
84
|
+
const parts = [];
|
|
85
|
+
const point = (x, y) => `${transform.a * x + transform.c * y + transform.tx} ${transform.b * x + transform.d * y + transform.ty}`;
|
|
86
|
+
const moveTo = (x, y) => parts.push(`M${point(x, y)}`);
|
|
87
|
+
const lineTo = (x, y) => parts.push(`L${point(x, y)}`);
|
|
88
|
+
const cubicCurveTo = (x1, y1, x2, y2, x, y) => parts.push(`C${point(x1, y1)} ${point(x2, y2)} ${point(x, y)}`);
|
|
89
|
+
replayAsCurves(drawVectorGeometry, element, pose, moveTo, lineTo, cubicCurveTo, () => parts.push('Z'));
|
|
90
|
+
return parts.join(' ');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Path data like `transformedVectorPathData`, with contours turned so that several shapes joined
|
|
95
|
+
* into one nonzero path (a symbol used as a mask) cover what each fills: holes of even-odd
|
|
96
|
+
* shapes wind against their outlines, every other outline winds forwards, so overlapping shapes
|
|
97
|
+
* add up instead of cancelling.
|
|
98
|
+
*/
|
|
99
|
+
export function orientedVectorPathData(element, pose, transform) {
|
|
100
|
+
const contours = [];
|
|
101
|
+
let current = null, x = 0, y = 0;
|
|
102
|
+
const point = (px, py) => [transform.a * px + transform.c * py + transform.tx, transform.b * px + transform.d * py + transform.ty];
|
|
103
|
+
const moveTo = (px, py) => { [x, y] = point(px, py); current = { start: [x, y], segments: [] }; contours.push(current); };
|
|
104
|
+
const lineTo = (px, py) => { const to = point(px, py); current?.segments.push({ c1: [x, y], c2: to, to }); [x, y] = to; };
|
|
105
|
+
const cubicCurveTo = (x1, y1, x2, y2, px, py) => { const to = point(px, py); current?.segments.push({ c1: point(x1, y1), c2: point(x2, y2), to }); [x, y] = to; };
|
|
106
|
+
replayAsCurves(drawVectorGeometry, element, pose, moveTo, lineTo, cubicCurveTo, () => {});
|
|
107
|
+
const shapes = contours.filter(contour => contour.segments.length);
|
|
108
|
+
// Each outline flattened, for its area and for containment.
|
|
109
|
+
const polygons = shapes.map(contour => {
|
|
110
|
+
const points = [contour.start];
|
|
111
|
+
let from = contour.start;
|
|
112
|
+
for (const { c1, c2, to } of contour.segments) {
|
|
113
|
+
for (let k = 1; k <= 8; k++) {
|
|
114
|
+
const t = k / 8, u = 1 - t;
|
|
115
|
+
points.push([0, 1].map(i => u * u * u * from[i] + 3 * u * u * t * c1[i] + 3 * u * t * t * c2[i] + t * t * t * to[i]));
|
|
116
|
+
}
|
|
117
|
+
from = to;
|
|
118
|
+
}
|
|
119
|
+
return points;
|
|
120
|
+
});
|
|
121
|
+
const area = points => points.reduce((sum, [px, py], k) => { const [qx, qy] = points[(k + 1) % points.length]; return sum + px * qy - qx * py; }, 0) / 2;
|
|
122
|
+
const inside = ([px, py], points) => {
|
|
123
|
+
let hit = false;
|
|
124
|
+
for (let k = 0, j = points.length - 1; k < points.length; j = k++) {
|
|
125
|
+
const [ax, ay] = points[k], [bx, by] = points[j];
|
|
126
|
+
if ((ay > py) !== (by > py) && px < (bx - ax) * (py - ay) / (by - ay) + ax) hit = !hit;
|
|
127
|
+
}
|
|
128
|
+
return hit;
|
|
129
|
+
};
|
|
130
|
+
const areas = polygons.map(area);
|
|
131
|
+
const compound = element.type === 'path' && element.closed && (pose.subpaths ?? []).length > 0;
|
|
132
|
+
const evenOdd = (element.fillRule ?? (compound ? 'evenodd' : 'nonzero')) === 'evenodd';
|
|
133
|
+
const largest = areas.reduce((best, value, k) => Math.abs(value) > Math.abs(areas[best]) ? k : best, 0);
|
|
134
|
+
const forwards = shapes.map((_, k) => {
|
|
135
|
+
if (!evenOdd) return areas[largest] >= 0 ? areas[k] >= 0 : areas[k] < 0;
|
|
136
|
+
const depth = polygons.filter((other, j) => j !== k && inside(polygons[k][0], other)).length;
|
|
137
|
+
return depth % 2 === 0;
|
|
138
|
+
});
|
|
139
|
+
const text = ([px, py]) => `${px} ${py}`;
|
|
140
|
+
return shapes.map((contour, k) => {
|
|
141
|
+
const flip = (areas[k] >= 0) !== forwards[k];
|
|
142
|
+
if (!flip) return `M${text(contour.start)} ${contour.segments.map(({ c1, c2, to }) => `C${text(c1)} ${text(c2)} ${text(to)}`).join(' ')} Z`;
|
|
143
|
+
// Reversed: the same curves from the end back to the start.
|
|
144
|
+
const ends = [contour.start, ...contour.segments.map(segment => segment.to)];
|
|
145
|
+
const back = contour.segments.map((segment, i) => `C${text(segment.c2)} ${text(segment.c1)} ${text(ends[i])}`).reverse();
|
|
146
|
+
return `M${text(ends.at(-1))} ${back.join(' ')} Z`;
|
|
147
|
+
}).join(' ');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function replayAsCurves(draw, element, pose, moveTo, lineTo, cubicCurveTo, close) {
|
|
151
|
+
// A quarter ellipse from (x0, y0) to (x1, y1), turning around the corner (cornerX, cornerY).
|
|
152
|
+
const quarter = (x0, y0, cornerX, cornerY, x1, y1) => cubicCurveTo(
|
|
153
|
+
x0 + (cornerX - x0) * KAPPA, y0 + (cornerY - y0) * KAPPA, x1 + (cornerX - x1) * KAPPA, y1 + (cornerY - y1) * KAPPA, x1, y1);
|
|
154
|
+
const ellipse = (cx, cy, rx, ry) => {
|
|
155
|
+
moveTo(cx + rx, cy);
|
|
156
|
+
quarter(cx + rx, cy, cx + rx, cy + ry, cx, cy + ry);
|
|
157
|
+
quarter(cx, cy + ry, cx - rx, cy + ry, cx - rx, cy);
|
|
158
|
+
quarter(cx - rx, cy, cx - rx, cy - ry, cx, cy - ry);
|
|
159
|
+
quarter(cx, cy - ry, cx + rx, cy - ry, cx + rx, cy);
|
|
160
|
+
close();
|
|
161
|
+
};
|
|
162
|
+
draw({
|
|
163
|
+
moveTo, lineTo, cubicCurveTo,
|
|
164
|
+
drawRect(x, y, w, h) {
|
|
165
|
+
moveTo(x, y); lineTo(x + w, y); lineTo(x + w, y + h); lineTo(x, y + h); close();
|
|
166
|
+
},
|
|
167
|
+
drawCircle: (x, y, r) => ellipse(x, y, r, r),
|
|
168
|
+
drawEllipse: (x, y, w, h) => ellipse(x + w / 2, y + h / 2, w / 2, h / 2),
|
|
169
|
+
drawRoundRect(x, y, w, h, diameter) {
|
|
170
|
+
const r = diameter / 2;
|
|
171
|
+
moveTo(x + r, y);
|
|
172
|
+
lineTo(x + w - r, y); quarter(x + w - r, y, x + w, y, x + w, y + r);
|
|
173
|
+
lineTo(x + w, y + h - r); quarter(x + w, y + h - r, x + w, y + h, x + w - r, y + h);
|
|
174
|
+
lineTo(x + r, y + h); quarter(x + r, y + h, x, y + h, x, y + h - r);
|
|
175
|
+
lineTo(x, y + r); quarter(x, y + r, x, y, x + r, y);
|
|
176
|
+
close();
|
|
177
|
+
},
|
|
178
|
+
}, element, pose);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function clippedGeometry(element, pose, cuts = pose.erasures) {
|
|
182
|
+
return subtractCuts((move, line, cubic, close) =>
|
|
183
|
+
replayAsCurves(drawOriginalGeometry, element, pose, move, line, cubic, close), element, pose, cuts);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function drawVectorGeometry(graphics, element, pose) {
|
|
187
|
+
if (pose.erasures?.length) replayRings(graphics, clippedGeometry(element, pose).fill);
|
|
188
|
+
else drawOriginalGeometry(graphics, element, pose);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Line caps, joins and dashes are the element's; Flash's names for caps ('none' for butt).
|
|
192
|
+
const FLASH_CAPS = { butt: 'none', round: 'round', square: 'square' };
|
|
193
|
+
export function setStrokeStyle(graphics, element, pose) {
|
|
194
|
+
graphics._setLineStyle(pose.strokeWidth, parseInt(pose.stroke.slice(1), 16), undefined, false, 'normal',
|
|
195
|
+
FLASH_CAPS[element.lineCap] ?? 'round', element.lineJoin ?? 'round', element.miterLimit ?? 3);
|
|
196
|
+
if (element.strokeDash?.length) graphics.lineDashStyle?.(element.strokeDash, element.strokeDashOffset ?? 0);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// When the eraser cuts a stroke, its surviving outline is a filled region.
|
|
200
|
+
export function paintVectorGeometry(graphics, element, pose, filled, strokeBitmap) {
|
|
201
|
+
const bitmap = element.bitmapStroke;
|
|
202
|
+
const strokePaint = pose.strokeGradient && { ...pose, fill: pose.stroke, gradient: pose.strokeGradient };
|
|
203
|
+
if (!pose.erasures?.length) {
|
|
204
|
+
if (pose.strokeWidth > 0) {
|
|
205
|
+
setStrokeStyle(graphics, element, pose);
|
|
206
|
+
if (strokeBitmap != null) graphics.lineBitmapStyle(strokeBitmap, bitmap.matrix, bitmap.repeat, bitmap.smoothed);
|
|
207
|
+
else if (strokePaint) beginVectorFill(graphics, strokePaint, true);
|
|
208
|
+
}
|
|
209
|
+
drawOriginalGeometry(graphics, element, pose);
|
|
210
|
+
if (filled) graphics.endFill();
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const { fill, stroke } = clippedGeometry(element, pose);
|
|
214
|
+
if (filled) {
|
|
215
|
+
replayRings(graphics, fill);
|
|
216
|
+
graphics.endFill();
|
|
217
|
+
}
|
|
218
|
+
if (stroke.length) {
|
|
219
|
+
if (strokeBitmap != null) graphics.beginBitmapFill(strokeBitmap, bitmap.matrix, bitmap.repeat, bitmap.smoothed);
|
|
220
|
+
else if (strokePaint) beginVectorFill(graphics, strokePaint);
|
|
221
|
+
else graphics.beginFill(parseInt(pose.stroke.slice(1), 16));
|
|
222
|
+
replayRings(graphics, stroke);
|
|
223
|
+
graphics.endFill();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Replay the authored geometry as SVG path data for Canvas clipping and native inputs.
|
|
228
|
+
export function vectorMaskPath(element, pose, matrix) {
|
|
229
|
+
const parts = [];
|
|
230
|
+
function ellipse(cx, cy, rx, ry) {
|
|
231
|
+
parts.push(`M${cx - rx} ${cy}a${rx} ${ry} 0 1 0 ${2 * rx} 0a${rx} ${ry} 0 1 0 ${-2 * rx} 0Z`);
|
|
232
|
+
}
|
|
233
|
+
drawVectorGeometry({
|
|
234
|
+
moveTo: (x, y) => parts.push(`M${x} ${y}`),
|
|
235
|
+
lineTo: (x, y) => parts.push(`L${x} ${y}`),
|
|
236
|
+
cubicCurveTo: (...coords) => parts.push('C' + coords.join(' ')),
|
|
237
|
+
drawRect: (x, y, w, h) => parts.push(`M${x} ${y}h${w}v${h}h${-w}Z`),
|
|
238
|
+
drawCircle: (x, y, r) => ellipse(x, y, r, r),
|
|
239
|
+
drawEllipse: (x, y, w, h) => ellipse(x + w / 2, y + h / 2, w / 2, h / 2),
|
|
240
|
+
drawRoundRect(x, y, w, h, diameter) {
|
|
241
|
+
const r = diameter / 2;
|
|
242
|
+
const arc = `a${r} ${r} 0 0 1 `;
|
|
243
|
+
parts.push(`M${x + r} ${y}h${w - diameter}${arc}${r} ${r}v${h - diameter}${arc}${-r} ${r}`,
|
|
244
|
+
`h${diameter - w}${arc}${-r} ${-r}v${diameter - h}${arc}${r} ${-r}Z`);
|
|
245
|
+
},
|
|
246
|
+
}, element, pose);
|
|
247
|
+
const data = parts.join(' ');
|
|
248
|
+
const stagePath = new Path2D();
|
|
249
|
+
stagePath.addPath(new Path2D(data), { a: matrix.a, b: matrix.b, c: matrix.c, d: matrix.d, e: matrix.tx, f: matrix.ty });
|
|
250
|
+
// A mask clips as its shape fills: compound paths even-odd unless the path says nonzero.
|
|
251
|
+
const compound = element.type === 'path' && element.closed && (pose.subpaths ?? []).length > 0;
|
|
252
|
+
const rule = element.type === 'path' && element.closed && (element.fillRule ?? (compound ? 'evenodd' : 'nonzero')) === 'evenodd' ? 'evenodd' : 'nonzero';
|
|
253
|
+
return { data, matrix, stagePath, rule };
|
|
254
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { Matrix } from '../../swooflib/geom.js';
|
|
2
|
+
|
|
3
|
+
const gradients = {
|
|
4
|
+
linear: { label: 'Linear gradient', fields: ['endColor', 'angle'] },
|
|
5
|
+
radial: { label: 'Radial gradient', fields: ['endColor', 'focus'] },
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// Each kind lists the parameters persisted in project JSON and shown in Properties.
|
|
9
|
+
export const appearanceKinds = {
|
|
10
|
+
gradient: gradients,
|
|
11
|
+
strokeGradient: gradients,
|
|
12
|
+
effect: {
|
|
13
|
+
blur: { label: 'Blur', fields: ['blurX', 'blurY'] },
|
|
14
|
+
glow: { label: 'Glow', fields: ['blurX', 'blurY', 'color', 'alpha', 'inner'] },
|
|
15
|
+
shadow: { label: 'Drop shadow', fields: ['blurX', 'blurY', 'color', 'alpha', 'distance', 'angle', 'inner'] },
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const appearanceFields = {
|
|
20
|
+
endColor: { label: 'End color', value: '#ffffff' },
|
|
21
|
+
angle: { label: 'Angle (°)', value: 0, min: -360, max: 360 },
|
|
22
|
+
focus: { label: 'Focal point', value: 0, min: -1, max: 1 },
|
|
23
|
+
blurX: { label: 'Blur X (px)', value: 8, min: 0, max: 255 },
|
|
24
|
+
blurY: { label: 'Blur Y (px)', value: 8, min: 0, max: 255 },
|
|
25
|
+
color: { label: 'Color', value: '#ffffff' },
|
|
26
|
+
alpha: { label: 'Opacity', value: 1, min: 0, max: 1 },
|
|
27
|
+
distance: { label: 'Distance (px)', value: 8, min: 0, max: 255 },
|
|
28
|
+
inner: { label: 'Inner', value: false },
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export function hasVectorFill(element) {
|
|
32
|
+
return !['text', 'symbol', 'bitmap', 'control', 'line', 'curve'].includes(element.type) &&
|
|
33
|
+
(element.type !== 'path' || element.closed);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function readAppearance(property, raw, label = property) {
|
|
37
|
+
if (raw === null) return null;
|
|
38
|
+
const kinds = appearanceKinds[property];
|
|
39
|
+
if (typeof raw !== 'object' || typeof raw.type !== 'string' || !Object.hasOwn(kinds, raw.type)) {
|
|
40
|
+
throw new Error(`${label} has an unsupported type`);
|
|
41
|
+
}
|
|
42
|
+
const result = { type: raw.type };
|
|
43
|
+
for (const name of kinds[raw.type].fields) {
|
|
44
|
+
const field = appearanceFields[name];
|
|
45
|
+
let fallback = field.value;
|
|
46
|
+
if (raw.type === 'shadow' && name === 'color') fallback = '#000000';
|
|
47
|
+
if (raw.type === 'shadow' && name === 'angle') fallback = 45;
|
|
48
|
+
let value = raw[name] === undefined ? fallback : raw[name];
|
|
49
|
+
if (typeof fallback === 'boolean') {
|
|
50
|
+
if (typeof value !== 'boolean') throw new Error(`${label}.${name} must be true or false`);
|
|
51
|
+
if (!value) continue;
|
|
52
|
+
} else if (typeof fallback === 'string') {
|
|
53
|
+
if (typeof value !== 'string' || !/^#[\da-f]{6}$/i.test(value)) {
|
|
54
|
+
throw new Error(`${label}.${name} must be a 6-digit hex color`);
|
|
55
|
+
}
|
|
56
|
+
value = value.toLowerCase();
|
|
57
|
+
} else if (!Number.isFinite(value) || value < field.min || value > field.max) {
|
|
58
|
+
throw new Error(`${label}.${name} must be between ${field.min} and ${field.max}`);
|
|
59
|
+
}
|
|
60
|
+
result[name] = value;
|
|
61
|
+
}
|
|
62
|
+
if (kinds === gradients && raw.stops !== undefined) result.stops = readGradientStops(raw.stops, `${label}.stops`);
|
|
63
|
+
if (kinds === gradients && raw.matrix !== undefined) {
|
|
64
|
+
const matrix = raw.matrix;
|
|
65
|
+
if (typeof matrix !== 'object' || matrix === null || ['a', 'b', 'c', 'd', 'tx', 'ty'].some(key => !Number.isFinite(matrix[key]) || Math.abs(matrix[key]) > 1e4)) {
|
|
66
|
+
throw new Error(`${label}.matrix must hold numbers a, b, c, d, tx, ty`);
|
|
67
|
+
}
|
|
68
|
+
result.matrix = { a: matrix.a, b: matrix.b, c: matrix.c, d: matrix.d, tx: matrix.tx, ty: matrix.ty };
|
|
69
|
+
}
|
|
70
|
+
if (kinds === gradients) {
|
|
71
|
+
for (const [name, values] of [['spreadMethod', ['pad', 'reflect', 'repeat']], ['interpolationMethod', ['rgb', 'linearRGB']]]) {
|
|
72
|
+
if (raw[name] === undefined) continue;
|
|
73
|
+
if (!values.includes(raw[name])) throw new Error(`${label}.${name} is invalid`);
|
|
74
|
+
result[name] = raw[name];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Optional color stops kept from imported art: ratio 0–1, color, and alpha per stop. The first
|
|
81
|
+
// and last colors follow the gradient's start and end colors, so editing those stays visible.
|
|
82
|
+
function readGradientStops(raw, label) {
|
|
83
|
+
if (!Array.isArray(raw) || raw.length < 2 || raw.length > 15) throw new Error(`${label} must list 2–15 stops`);
|
|
84
|
+
let previous = 0;
|
|
85
|
+
return raw.map((stop, index) => {
|
|
86
|
+
const at = `${label}[${index}]`;
|
|
87
|
+
if (typeof stop !== 'object' || stop === null) throw new Error(`${at} must be an object`);
|
|
88
|
+
if (!Number.isFinite(stop.ratio) || stop.ratio < previous || stop.ratio > 1) throw new Error(`${at}.ratio must be 0–1, in order`);
|
|
89
|
+
previous = stop.ratio;
|
|
90
|
+
if (typeof stop.color !== 'string' || !/^#[\da-f]{6}$/i.test(stop.color)) throw new Error(`${at}.color must be a 6-digit hex color`);
|
|
91
|
+
const alpha = stop.alpha ?? 1;
|
|
92
|
+
if (!Number.isFinite(alpha) || alpha < 0 || alpha > 1) throw new Error(`${at}.alpha must be between 0 and 1`);
|
|
93
|
+
return { ratio: stop.ratio, color: stop.color.toLowerCase(), alpha };
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Gradient placement for `pose` in Flash's convention (the ±819.2 gradient square mapped into the
|
|
99
|
+
* object's own space), or null for Studio's default box. `gradient.matrix` (kept from imported
|
|
100
|
+
* art) is relative to the object's box: a, c, tx scale with its width; b, d, ty with its height.
|
|
101
|
+
*/
|
|
102
|
+
export function gradientPlacement(pose) {
|
|
103
|
+
const m = pose.gradient?.matrix;
|
|
104
|
+
if (!m) return null;
|
|
105
|
+
const w = pose.width, h = pose.height;
|
|
106
|
+
return { a: m.a * w / 819.2, b: m.b * h / 819.2, c: m.c * w / 819.2, d: m.d * h / 819.2, tx: m.tx * w, ty: m.ty * h };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Colors, alphas, and ratios (0–255) for a gradient fill at `pose`. */
|
|
110
|
+
export function gradientStops(pose) {
|
|
111
|
+
const gradient = pose.gradient;
|
|
112
|
+
const stops = gradient.stops ?? [{ ratio: 0, color: pose.fill, alpha: 1 }, { ratio: 1, color: gradient.endColor, alpha: 1 }];
|
|
113
|
+
const last = stops.length - 1;
|
|
114
|
+
return {
|
|
115
|
+
colors: stops.map((stop, index) => parseInt((index === 0 ? pose.fill : index === last ? gradient.endColor : stop.color).slice(1), 16)),
|
|
116
|
+
alphas: stops.map(stop => stop.alpha),
|
|
117
|
+
ratios: stops.map(stop => Math.round(stop.ratio * 255)),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
export function beginVectorFill(graphics, pose, asLine = false) {
|
|
123
|
+
const start = parseInt(pose.fill.slice(1), 16);
|
|
124
|
+
const gradient = pose.gradient;
|
|
125
|
+
if (!gradient) return graphics.beginFill(start);
|
|
126
|
+
const placed = gradientPlacement(pose);
|
|
127
|
+
const box = placed ? new Matrix(placed.a, placed.b, placed.c, placed.d, placed.tx, placed.ty) : new Matrix();
|
|
128
|
+
if (!placed && gradient.type === 'linear') {
|
|
129
|
+
const angle = gradient.angle * Math.PI / 180;
|
|
130
|
+
const span = pose.width * Math.abs(Math.cos(angle)) + pose.height * Math.abs(Math.sin(angle));
|
|
131
|
+
box.createGradientBox(span, span, angle, -span / 2, -span / 2);
|
|
132
|
+
} else if (!placed) {
|
|
133
|
+
box.createGradientBox(pose.width, pose.height, 0, -pose.width / 2, -pose.height / 2);
|
|
134
|
+
}
|
|
135
|
+
const { colors, alphas, ratios } = gradientStops(pose);
|
|
136
|
+
const method = asLine ? 'lineGradientStyle' : 'beginGradientFill';
|
|
137
|
+
graphics[method](gradient.type, colors, alphas, ratios, box, gradient.spreadMethod, gradient.interpolationMethod, gradient.focus ?? 0);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Older projects omit these shape options. Their defaults reproduce the original geometry.
|
|
141
|
+
export function shapePropertyValue(property, pose) {
|
|
142
|
+
if (pose[property] !== undefined) return pose[property];
|
|
143
|
+
if (property === 'starPoints') return 5;
|
|
144
|
+
if (property === 'starRadius') return 100 * .42 / .88;
|
|
145
|
+
if (property === 'cornerRadius') return Math.min(10, pose.width * .075, pose.height * .075);
|
|
146
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// WebCodecs setup for video export (studiospec/video-export.md §8.5): codec strings, support
|
|
2
|
+
// detection and encoder settings. MP4 carries H.264 with AAC (Opus when this browser has no AAC
|
|
3
|
+
// encoder); WebM carries VP9 with Opus.
|
|
4
|
+
|
|
5
|
+
export const AUDIO_RATE = 48000;
|
|
6
|
+
export const AUDIO_CHANNELS = 2;
|
|
7
|
+
|
|
8
|
+
// H.264 levels by maximum macroblocks per frame and per second (ITU-T H.264 Table A-1).
|
|
9
|
+
const AVC_LEVELS = [
|
|
10
|
+
[0x1e, 1620, 40500], [0x1f, 3600, 108000], [0x20, 5120, 216000], [0x28, 8192, 245760],
|
|
11
|
+
[0x2a, 8704, 522240], [0x32, 22080, 589824], [0x33, 36864, 983040], [0x34, 36864, 2073600],
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
export function avcCodec(width, height, fps, profile = '6400') {
|
|
15
|
+
const perFrame = Math.ceil(width / 16) * Math.ceil(height / 16);
|
|
16
|
+
const level = AVC_LEVELS.find(([, frame, second]) => perFrame <= frame && perFrame * fps <= second)?.[0] ?? 0x34;
|
|
17
|
+
return `avc1.${profile}${level.toString(16).padStart(2, '0')}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Even output dimensions: H.264 and VP9 in 4:2:0 need them. */
|
|
21
|
+
export function outputSize(stage, scale) {
|
|
22
|
+
const even = value => Math.ceil(value * scale / 2) * 2;
|
|
23
|
+
return { width: even(stage.width), height: even(stage.height) };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function videoBitrate(width, height, fps) {
|
|
27
|
+
return Math.round(Math.min(40e6, Math.max(1e6, width * height * fps * 0.12)));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function videoConfigs(format, width, height, fps) {
|
|
31
|
+
const common = { width, height, framerate: fps, bitrate: videoBitrate(width, height, fps) };
|
|
32
|
+
if (format === 'webm') return [{ ...common, codec: 'vp09.00.40.08' }, { ...common, codec: 'vp8' }];
|
|
33
|
+
// High, then Main, then Constrained Baseline.
|
|
34
|
+
return ['6400', '4d00', '42e0'].map(profile => ({ ...common, codec: avcCodec(width, height, fps, profile), avc: { format: 'avc' } }));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function audioConfigs(format) {
|
|
38
|
+
const common = { sampleRate: AUDIO_RATE, numberOfChannels: AUDIO_CHANNELS, bitrate: 160000 };
|
|
39
|
+
const opus = { ...common, codec: 'opus' };
|
|
40
|
+
return format === 'webm' ? [opus] : [{ ...common, codec: 'mp4a.40.2', aac: { format: 'aac' } }, opus];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function firstSupported(Encoder, configs) {
|
|
44
|
+
for (const config of configs) {
|
|
45
|
+
try {
|
|
46
|
+
const result = await Encoder.isConfigSupported(config);
|
|
47
|
+
if (result.supported) return result.config ?? config;
|
|
48
|
+
} catch { /* an unknown codec string throws in some browsers */ }
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function hasWebCodecs() {
|
|
54
|
+
return typeof VideoEncoder === 'function' && typeof VideoFrame === 'function';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The encoder settings for `format` at this size, or null when this browser cannot encode it. */
|
|
58
|
+
export async function encoderSettings(format, width, height, fps, withAudio) {
|
|
59
|
+
if (!hasWebCodecs()) return null;
|
|
60
|
+
const video = await firstSupported(VideoEncoder, videoConfigs(format, width, height, fps));
|
|
61
|
+
if (!video) return null;
|
|
62
|
+
let audio = null;
|
|
63
|
+
if (withAudio && typeof AudioEncoder === 'function') audio = await firstSupported(AudioEncoder, audioConfigs(format));
|
|
64
|
+
return { video, audio };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Formats this browser can encode at the stage size, MP4 first. Probing starts encoders, so results are cached. */
|
|
68
|
+
const formatCache = new Map();
|
|
69
|
+
export function supportedFormats(stage) {
|
|
70
|
+
const { width, height } = outputSize(stage, 1);
|
|
71
|
+
const key = `${width}x${height}@${stage.frameRate}`;
|
|
72
|
+
if (!formatCache.has(key)) {
|
|
73
|
+
formatCache.set(key, (async () => {
|
|
74
|
+
const formats = [];
|
|
75
|
+
for (const format of ['mp4', 'webm']) if (await encoderSettings(format, width, height, stage.frameRate, false)) formats.push(format);
|
|
76
|
+
return formats;
|
|
77
|
+
})());
|
|
78
|
+
}
|
|
79
|
+
return formatCache.get(key);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const muxCodec = config => config.codec.startsWith('avc1') ? 'avc'
|
|
83
|
+
: config.codec.startsWith('vp09') ? 'vp9' : config.codec === 'vp8' ? 'vp8'
|
|
84
|
+
: config.codec.startsWith('mp4a') ? 'aac' : 'opus';
|