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,423 @@
|
|
|
1
|
+
// Animated GIF, APNG and animated WebP writers for video export (studiospec/video-export.md §10).
|
|
2
|
+
// No dependencies: GIF has its own palette and LZW coder, APNG uses the browser's deflate
|
|
3
|
+
// (CompressionStream), and WebP frames come from the browser's own WebP encoder (canvas.toBlob)
|
|
4
|
+
// wrapped in animation chunks. Each frame stores only the rectangle that changed; images loop.
|
|
5
|
+
|
|
6
|
+
export const ANIMATED_FORMATS = {
|
|
7
|
+
gif: { extension: 'gif', type: 'image/gif', label: 'GIF' },
|
|
8
|
+
apng: { extension: 'png', type: 'image/png', label: 'Animated PNG' },
|
|
9
|
+
webp: { extension: 'webp', type: 'image/webp', label: 'Animated WebP' },
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/** Animated formats this browser can write. */
|
|
13
|
+
export function supportedAnimatedFormats() {
|
|
14
|
+
const formats = ['gif'];
|
|
15
|
+
if (typeof CompressionStream === 'function') formats.push('apng');
|
|
16
|
+
try {
|
|
17
|
+
const canvas = document.createElement('canvas');
|
|
18
|
+
canvas.width = canvas.height = 2;
|
|
19
|
+
if (canvas.toDataURL('image/webp').startsWith('data:image/webp')) formats.push('webp');
|
|
20
|
+
} catch { /* no WebP encoder */ }
|
|
21
|
+
return formats;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class ByteSink {
|
|
25
|
+
constructor() { this.parts = []; this.length = 0; }
|
|
26
|
+
push(bytes) { this.parts.push(bytes); this.length += bytes.length; }
|
|
27
|
+
bytes() {
|
|
28
|
+
const out = new Uint8Array(this.length);
|
|
29
|
+
let at = 0;
|
|
30
|
+
for (const part of this.parts) { out.set(part, at); at += part.length; }
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The rectangle where two RGBA buffers differ, or null when they are the same. */
|
|
36
|
+
export function changedRect(previous, pixels, width, height) {
|
|
37
|
+
if (!previous) return { x: 0, y: 0, width, height };
|
|
38
|
+
const a = new Uint32Array(previous.buffer, previous.byteOffset, width * height);
|
|
39
|
+
const b = new Uint32Array(pixels.buffer, pixels.byteOffset, width * height);
|
|
40
|
+
let top = -1, bottom = -1, left = width, right = -1;
|
|
41
|
+
for (let y = 0; y < height; y++) {
|
|
42
|
+
const row = y * width;
|
|
43
|
+
let first = -1, last = -1;
|
|
44
|
+
for (let x = 0; x < width; x++) if (a[row + x] !== b[row + x]) { first = x; break; }
|
|
45
|
+
if (first < 0) continue;
|
|
46
|
+
for (let x = width - 1; x >= first; x--) if (a[row + x] !== b[row + x]) { last = x; break; }
|
|
47
|
+
if (top < 0) top = y;
|
|
48
|
+
bottom = y;
|
|
49
|
+
left = Math.min(left, first);
|
|
50
|
+
right = Math.max(right, last);
|
|
51
|
+
}
|
|
52
|
+
return top < 0 ? null : { x: left, y: top, width: right - left + 1, height: bottom - top + 1 };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function crop(pixels, width, rect) {
|
|
56
|
+
const out = new Uint8Array(rect.width * rect.height * 4);
|
|
57
|
+
for (let y = 0; y < rect.height; y++) {
|
|
58
|
+
const from = ((rect.y + y) * width + rect.x) * 4;
|
|
59
|
+
out.set(pixels.subarray(from, from + rect.width * 4), y * rect.width * 4);
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Frame timing shared by every writer: a frame is written once the next one arrives, with the
|
|
65
|
+
// time between them; a frame shorter than `minimum` ms is replaced by the next (dropped).
|
|
66
|
+
function createTimeline(minimum, write) {
|
|
67
|
+
let pending = null;
|
|
68
|
+
return {
|
|
69
|
+
async add(frame, time) {
|
|
70
|
+
if (pending && time - pending.time < minimum) {
|
|
71
|
+
// The dropped frame was never written, so the next one covers both changes.
|
|
72
|
+
const a = pending.rect, b = frame.rect;
|
|
73
|
+
const x = Math.min(a.x, b.x), y = Math.min(a.y, b.y);
|
|
74
|
+
const rect = { x, y, width: Math.max(a.x + a.width, b.x + b.width) - x, height: Math.max(a.y + a.height, b.y + b.height) - y };
|
|
75
|
+
pending = { ...frame, rect, time: pending.time };
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (pending) await write(pending, time - pending.time);
|
|
79
|
+
pending = { ...frame, time };
|
|
80
|
+
},
|
|
81
|
+
async finish(end) {
|
|
82
|
+
if (pending) await write(pending, Math.max(minimum, end - pending.time));
|
|
83
|
+
pending = null;
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// --- GIF ------------------------------------------------------------------------------
|
|
89
|
+
|
|
90
|
+
/** Up to 256 colors for `pixels` (RGBA) by median cut over a sample. */
|
|
91
|
+
export function medianCutPalette(pixels, size = 256) {
|
|
92
|
+
const count = pixels.length / 4;
|
|
93
|
+
const step = Math.max(1, Math.floor(count / 40000));
|
|
94
|
+
const colors = [];
|
|
95
|
+
for (let i = 0; i < count; i += step) colors.push(pixels[i * 4] << 16 | pixels[i * 4 + 1] << 8 | pixels[i * 4 + 2]);
|
|
96
|
+
let boxes = [colors];
|
|
97
|
+
const channel = (color, c) => (color >> (16 - c * 8)) & 255;
|
|
98
|
+
while (boxes.length < size) {
|
|
99
|
+
let best = -1, bestRange = 0, bestChannel = 0;
|
|
100
|
+
boxes.forEach((box, index) => {
|
|
101
|
+
if (box.length < 2) return;
|
|
102
|
+
for (let c = 0; c < 3; c++) {
|
|
103
|
+
let min = 255, max = 0;
|
|
104
|
+
for (const color of box) { const v = channel(color, c); if (v < min) min = v; if (v > max) max = v; }
|
|
105
|
+
// Wide boxes with many pixels split first.
|
|
106
|
+
const range = (max - min) * Math.sqrt(box.length);
|
|
107
|
+
if (range > bestRange) { bestRange = range; best = index; bestChannel = c; }
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
if (best < 0) break;
|
|
111
|
+
const box = boxes[best].sort((x, y) => channel(x, bestChannel) - channel(y, bestChannel));
|
|
112
|
+
const half = box.length >> 1;
|
|
113
|
+
boxes.splice(best, 1, box.slice(0, half), box.slice(half));
|
|
114
|
+
}
|
|
115
|
+
boxes = boxes.filter(box => box.length);
|
|
116
|
+
return boxes.map(box => {
|
|
117
|
+
let r = 0, g = 0, b = 0;
|
|
118
|
+
for (const color of box) { r += color >> 16 & 255; g += color >> 8 & 255; b += color & 255; }
|
|
119
|
+
return [Math.round(r / box.length), Math.round(g / box.length), Math.round(b / box.length)];
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Palette indexes for `pixels`, through a 6-bit-per-channel cache of nearest colors. */
|
|
124
|
+
export function mapToPalette(pixels, palette) {
|
|
125
|
+
const cache = new Int16Array(1 << 18).fill(-1);
|
|
126
|
+
const out = new Uint8Array(pixels.length / 4);
|
|
127
|
+
for (let i = 0; i < out.length; i++) {
|
|
128
|
+
const r = pixels[i * 4], g = pixels[i * 4 + 1], b = pixels[i * 4 + 2];
|
|
129
|
+
const key = (r >> 2) << 12 | (g >> 2) << 6 | (b >> 2);
|
|
130
|
+
let index = cache[key];
|
|
131
|
+
if (index < 0) {
|
|
132
|
+
let best = Infinity;
|
|
133
|
+
for (let p = 0; p < palette.length; p++) {
|
|
134
|
+
const [pr, pg, pb] = palette[p];
|
|
135
|
+
const d = (pr - r) ** 2 * 3 + (pg - g) ** 2 * 4 + (pb - b) ** 2 * 2;
|
|
136
|
+
if (d < best) { best = d; index = p; }
|
|
137
|
+
}
|
|
138
|
+
cache[key] = index;
|
|
139
|
+
}
|
|
140
|
+
out[i] = index;
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** GIF LZW image data (minimum code size 8) as sub-blocks, ending with the block terminator. */
|
|
146
|
+
export function lzwEncode(indices) {
|
|
147
|
+
const sink = new ByteSink();
|
|
148
|
+
let block = new Uint8Array(255), blockLength = 0;
|
|
149
|
+
const byte = value => {
|
|
150
|
+
block[blockLength++] = value;
|
|
151
|
+
if (blockLength === 255) { sink.push(Uint8Array.of(255)); sink.push(block); block = new Uint8Array(255); blockLength = 0; }
|
|
152
|
+
};
|
|
153
|
+
let bitBuffer = 0, bitCount = 0;
|
|
154
|
+
const emit = (code, size) => {
|
|
155
|
+
bitBuffer |= code << bitCount;
|
|
156
|
+
bitCount += size;
|
|
157
|
+
while (bitCount >= 8) { byte(bitBuffer & 255); bitBuffer >>>= 8; bitCount -= 8; }
|
|
158
|
+
};
|
|
159
|
+
const CLEAR = 256, END = 257, HASH = 5003;
|
|
160
|
+
const keys = new Int32Array(HASH), codes = new Int16Array(HASH);
|
|
161
|
+
let next, size;
|
|
162
|
+
const reset = () => { keys.fill(-1); next = 258; size = 9; };
|
|
163
|
+
sink.push(Uint8Array.of(8));
|
|
164
|
+
reset();
|
|
165
|
+
emit(CLEAR, size);
|
|
166
|
+
let prefix = indices[0];
|
|
167
|
+
for (let i = 1; i < indices.length; i++) {
|
|
168
|
+
const k = indices[i];
|
|
169
|
+
const key = prefix << 8 | k;
|
|
170
|
+
let h = (k << 4 ^ prefix) % HASH;
|
|
171
|
+
let found = -1;
|
|
172
|
+
while (keys[h] !== -1) {
|
|
173
|
+
if (keys[h] === key) { found = codes[h]; break; }
|
|
174
|
+
h = (h + 1) % HASH;
|
|
175
|
+
}
|
|
176
|
+
if (found >= 0) { prefix = found; continue; }
|
|
177
|
+
emit(prefix, size);
|
|
178
|
+
if (next < 4096) {
|
|
179
|
+
keys[h] = key;
|
|
180
|
+
codes[h] = next++;
|
|
181
|
+
if (next > (1 << size) && size < 12) size++;
|
|
182
|
+
} else {
|
|
183
|
+
emit(CLEAR, size);
|
|
184
|
+
reset();
|
|
185
|
+
}
|
|
186
|
+
prefix = k;
|
|
187
|
+
}
|
|
188
|
+
emit(prefix, size);
|
|
189
|
+
emit(END, size);
|
|
190
|
+
if (bitCount > 0) byte(bitBuffer & 255);
|
|
191
|
+
if (blockLength) { sink.push(Uint8Array.of(blockLength)); sink.push(block.subarray(0, blockLength)); }
|
|
192
|
+
sink.push(Uint8Array.of(0));
|
|
193
|
+
return sink.bytes();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function createGifWriter(width, height) {
|
|
197
|
+
const sink = new ByteSink();
|
|
198
|
+
const ascii = text => Uint8Array.from(text, c => c.charCodeAt(0));
|
|
199
|
+
const u16 = value => Uint8Array.of(value & 255, value >> 8 & 255);
|
|
200
|
+
sink.push(ascii('GIF89a'));
|
|
201
|
+
sink.push(u16(width)); sink.push(u16(height));
|
|
202
|
+
sink.push(Uint8Array.of(0, 0, 0)); // No global color table.
|
|
203
|
+
sink.push(Uint8Array.of(0x21, 0xff, 11, ...ascii('NETSCAPE2.0'), 3, 1, 0, 0, 0)); // Loop forever.
|
|
204
|
+
let previous = null;
|
|
205
|
+
// GIF delays are centiseconds and browsers treat delays under 2 cs as 10 cs: frames under 20 ms are dropped.
|
|
206
|
+
const timeline = createTimeline(20, async (frame, duration) => {
|
|
207
|
+
const rect = frame.rect;
|
|
208
|
+
const pixels = crop(frame.pixels, width, rect);
|
|
209
|
+
const palette = medianCutPalette(pixels);
|
|
210
|
+
while (palette.length < 2) palette.push([0, 0, 0]);
|
|
211
|
+
const bits = Math.max(1, Math.ceil(Math.log2(palette.length)));
|
|
212
|
+
const delay = Math.max(2, Math.round(duration / 10));
|
|
213
|
+
sink.push(Uint8Array.of(0x21, 0xf9, 4, 0x04, delay & 255, delay >> 8, 0, 0)); // Do not dispose.
|
|
214
|
+
sink.push(Uint8Array.of(0x2c)); sink.push(u16(rect.x)); sink.push(u16(rect.y)); sink.push(u16(rect.width)); sink.push(u16(rect.height));
|
|
215
|
+
sink.push(Uint8Array.of(0x80 | (bits - 1)));
|
|
216
|
+
const table = new Uint8Array(3 << bits);
|
|
217
|
+
palette.forEach((color, i) => table.set(color, i * 3));
|
|
218
|
+
sink.push(table);
|
|
219
|
+
sink.push(lzwEncode(mapToPalette(pixels, palette)));
|
|
220
|
+
});
|
|
221
|
+
return {
|
|
222
|
+
async add(pixels, time) {
|
|
223
|
+
const rect = changedRect(previous, pixels, width, height);
|
|
224
|
+
if (!rect) return; // Unchanged: the previous frame lasts longer.
|
|
225
|
+
previous = pixels;
|
|
226
|
+
await timeline.add({ pixels, rect }, time);
|
|
227
|
+
},
|
|
228
|
+
async finish(end) {
|
|
229
|
+
await timeline.finish(end);
|
|
230
|
+
sink.push(Uint8Array.of(0x3b));
|
|
231
|
+
return sink.bytes();
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// --- APNG ------------------------------------------------------------------------------
|
|
237
|
+
|
|
238
|
+
const CRC_TABLE = (() => {
|
|
239
|
+
const table = new Uint32Array(256);
|
|
240
|
+
for (let n = 0; n < 256; n++) {
|
|
241
|
+
let c = n;
|
|
242
|
+
for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
243
|
+
table[n] = c >>> 0;
|
|
244
|
+
}
|
|
245
|
+
return table;
|
|
246
|
+
})();
|
|
247
|
+
|
|
248
|
+
export function crc32(bytes, crc = 0xffffffff) {
|
|
249
|
+
for (let i = 0; i < bytes.length; i++) crc = CRC_TABLE[(crc ^ bytes[i]) & 255] ^ (crc >>> 8);
|
|
250
|
+
return crc;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function pngChunk(type, data) {
|
|
254
|
+
const out = new Uint8Array(12 + data.length);
|
|
255
|
+
const view = new DataView(out.buffer);
|
|
256
|
+
view.setUint32(0, data.length);
|
|
257
|
+
for (let i = 0; i < 4; i++) out[4 + i] = type.charCodeAt(i);
|
|
258
|
+
out.set(data, 8);
|
|
259
|
+
view.setUint32(8 + data.length, (crc32(out.subarray(4, 8 + data.length)) ^ 0xffffffff) >>> 0);
|
|
260
|
+
return out;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** RGB scanlines with the Paeth filter, ready to deflate. */
|
|
264
|
+
function filteredRows(pixels, width, height) {
|
|
265
|
+
const stride = width * 3;
|
|
266
|
+
const out = new Uint8Array(height * (stride + 1));
|
|
267
|
+
const rgb = new Uint8Array(stride), above = new Uint8Array(stride);
|
|
268
|
+
for (let y = 0; y < height; y++) {
|
|
269
|
+
for (let x = 0; x < width; x++) {
|
|
270
|
+
const from = (y * width + x) * 4;
|
|
271
|
+
rgb[x * 3] = pixels[from]; rgb[x * 3 + 1] = pixels[from + 1]; rgb[x * 3 + 2] = pixels[from + 2];
|
|
272
|
+
}
|
|
273
|
+
const row = y * (stride + 1);
|
|
274
|
+
out[row] = 4; // Paeth
|
|
275
|
+
for (let i = 0; i < stride; i++) {
|
|
276
|
+
const a = i >= 3 ? rgb[i - 3] : 0, b = y ? above[i] : 0, c = i >= 3 && y ? above[i - 3] : 0;
|
|
277
|
+
const p = a + b - c, pa = Math.abs(p - a), pb = Math.abs(p - b), pc = Math.abs(p - c);
|
|
278
|
+
out[row + 1 + i] = rgb[i] - (pa <= pb && pa <= pc ? a : pb <= pc ? b : c);
|
|
279
|
+
}
|
|
280
|
+
above.set(rgb);
|
|
281
|
+
}
|
|
282
|
+
return out;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
async function deflate(bytes) {
|
|
286
|
+
const stream = new Blob([bytes]).stream().pipeThrough(new CompressionStream('deflate'));
|
|
287
|
+
return new Uint8Array(await new Response(stream).arrayBuffer());
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function createApngWriter(width, height) {
|
|
291
|
+
const frames = [];
|
|
292
|
+
let previous = null;
|
|
293
|
+
const u32 = (view, at, value) => view.setUint32(at, value);
|
|
294
|
+
const timeline = createTimeline(1, async (frame, duration) => {
|
|
295
|
+
const { rect } = frame;
|
|
296
|
+
const control = new Uint8Array(26);
|
|
297
|
+
const view = new DataView(control.buffer);
|
|
298
|
+
u32(view, 4, rect.width); u32(view, 8, rect.height); u32(view, 12, rect.x); u32(view, 16, rect.y);
|
|
299
|
+
view.setUint16(20, Math.min(65535, Math.round(duration))); view.setUint16(22, 1000); // Delay in ms.
|
|
300
|
+
control[24] = 0; control[25] = 0; // Keep the canvas; replace the rectangle.
|
|
301
|
+
const data = await deflate(filteredRows(crop(frame.pixels, width, rect), rect.width, rect.height));
|
|
302
|
+
frames.push({ control, data });
|
|
303
|
+
});
|
|
304
|
+
return {
|
|
305
|
+
async add(pixels, time) {
|
|
306
|
+
const rect = changedRect(previous, pixels, width, height);
|
|
307
|
+
if (!rect) return;
|
|
308
|
+
previous = pixels;
|
|
309
|
+
await timeline.add({ pixels, rect }, time);
|
|
310
|
+
},
|
|
311
|
+
async finish(end) {
|
|
312
|
+
await timeline.finish(end);
|
|
313
|
+
const sink = new ByteSink();
|
|
314
|
+
sink.push(Uint8Array.of(0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a));
|
|
315
|
+
const header = new Uint8Array(13);
|
|
316
|
+
const view = new DataView(header.buffer);
|
|
317
|
+
u32(view, 0, width); u32(view, 4, height);
|
|
318
|
+
header[8] = 8; header[9] = 2; // 8-bit RGB.
|
|
319
|
+
sink.push(pngChunk('IHDR', header));
|
|
320
|
+
const animation = new Uint8Array(8);
|
|
321
|
+
u32(new DataView(animation.buffer), 0, frames.length); // num_plays 0: loop forever.
|
|
322
|
+
sink.push(pngChunk('acTL', animation));
|
|
323
|
+
// The first frame is also the default image (IDAT); the rest are fdAT. fcTL and fdAT share
|
|
324
|
+
// one sequence that increases in file order.
|
|
325
|
+
let sequence = 0;
|
|
326
|
+
frames.forEach((frame, index) => {
|
|
327
|
+
u32(new DataView(frame.control.buffer), 0, sequence++);
|
|
328
|
+
sink.push(pngChunk('fcTL', frame.control));
|
|
329
|
+
if (index === 0) sink.push(pngChunk('IDAT', frame.data));
|
|
330
|
+
else {
|
|
331
|
+
const data = new Uint8Array(4 + frame.data.length);
|
|
332
|
+
u32(new DataView(data.buffer), 0, sequence++);
|
|
333
|
+
data.set(frame.data, 4);
|
|
334
|
+
sink.push(pngChunk('fdAT', data));
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
sink.push(pngChunk('IEND', new Uint8Array(0)));
|
|
338
|
+
return sink.bytes();
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// --- WebP ------------------------------------------------------------------------------
|
|
344
|
+
|
|
345
|
+
/** The image chunks (ALPH, VP8, VP8L) of a still WebP file. */
|
|
346
|
+
export function webpImageChunks(bytes) {
|
|
347
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
348
|
+
const chunks = [];
|
|
349
|
+
for (let at = 12; at + 8 <= bytes.length;) {
|
|
350
|
+
const type = String.fromCharCode(...bytes.subarray(at, at + 4));
|
|
351
|
+
const size = view.getUint32(at + 4, true);
|
|
352
|
+
const end = at + 8 + size + (size & 1);
|
|
353
|
+
if (type === 'ALPH' || type === 'VP8 ' || type === 'VP8L') chunks.push(bytes.subarray(at, Math.min(end, bytes.length)));
|
|
354
|
+
at = end;
|
|
355
|
+
}
|
|
356
|
+
return chunks;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function riffChunk(type, data) {
|
|
360
|
+
const out = new Uint8Array(8 + data.length + (data.length & 1));
|
|
361
|
+
for (let i = 0; i < 4; i++) out[i] = type.charCodeAt(i);
|
|
362
|
+
new DataView(out.buffer).setUint32(4, data.length, true);
|
|
363
|
+
out.set(data, 8);
|
|
364
|
+
return out;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const u24 = (out, at, value) => { out[at] = value & 255; out[at + 1] = value >> 8 & 255; out[at + 2] = value >> 16 & 255; };
|
|
368
|
+
|
|
369
|
+
function createWebpWriter(width, height, quality = 0.9) {
|
|
370
|
+
const frames = new ByteSink();
|
|
371
|
+
let previous = null;
|
|
372
|
+
const scratch = document.createElement('canvas');
|
|
373
|
+
const timeline = createTimeline(1, async (frame, duration) => {
|
|
374
|
+
// Frame offsets are stored halved, so the rectangle starts on even coordinates.
|
|
375
|
+
const x = frame.rect.x & ~1, y = frame.rect.y & ~1;
|
|
376
|
+
const rect = { x, y, width: frame.rect.width + frame.rect.x - x, height: frame.rect.height + frame.rect.y - y };
|
|
377
|
+
scratch.width = rect.width;
|
|
378
|
+
scratch.height = rect.height;
|
|
379
|
+
scratch.getContext('2d').putImageData(new ImageData(new Uint8ClampedArray(crop(frame.pixels, width, rect).buffer), rect.width, rect.height), 0, 0);
|
|
380
|
+
const blob = await new Promise(resolve => scratch.toBlob(resolve, 'image/webp', quality));
|
|
381
|
+
if (!blob || blob.type !== 'image/webp') throw new Error('This browser cannot write WebP images');
|
|
382
|
+
const image = webpImageChunks(new Uint8Array(await blob.arrayBuffer()));
|
|
383
|
+
const header = new Uint8Array(16);
|
|
384
|
+
u24(header, 0, x / 2); u24(header, 3, y / 2); u24(header, 6, rect.width - 1); u24(header, 9, rect.height - 1);
|
|
385
|
+
u24(header, 12, Math.min(0xffffff, Math.round(duration)));
|
|
386
|
+
header[15] = 0x02; // Do not blend: the rectangle replaces what is under it; do not dispose.
|
|
387
|
+
const length = image.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
388
|
+
const body = new Uint8Array(16 + length);
|
|
389
|
+
body.set(header);
|
|
390
|
+
let at = 16;
|
|
391
|
+
for (const chunk of image) { body.set(chunk, at); at += chunk.length; }
|
|
392
|
+
frames.push(riffChunk('ANMF', body));
|
|
393
|
+
});
|
|
394
|
+
return {
|
|
395
|
+
async add(pixels, time) {
|
|
396
|
+
const rect = changedRect(previous, pixels, width, height);
|
|
397
|
+
if (!rect) return;
|
|
398
|
+
previous = pixels;
|
|
399
|
+
await timeline.add({ pixels, rect }, time);
|
|
400
|
+
},
|
|
401
|
+
async finish(end) {
|
|
402
|
+
await timeline.finish(end);
|
|
403
|
+
const extended = new Uint8Array(10);
|
|
404
|
+
extended[0] = 0x02; // Animation.
|
|
405
|
+
u24(extended, 4, width - 1); u24(extended, 7, height - 1);
|
|
406
|
+
const animation = new Uint8Array(6); // Background 0 (BGRA), loop count 0: forever.
|
|
407
|
+
const body = new ByteSink();
|
|
408
|
+
body.push(Uint8Array.from('WEBP', c => c.charCodeAt(0)));
|
|
409
|
+
body.push(riffChunk('VP8X', extended));
|
|
410
|
+
body.push(riffChunk('ANIM', animation));
|
|
411
|
+
body.push(frames.bytes());
|
|
412
|
+
return riffChunk('RIFF', body.bytes());
|
|
413
|
+
},
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/** A writer for `format`: `add(rgbaPixels, timeMs)` per frame, then `finish(endMs)` → bytes. */
|
|
418
|
+
export function createAnimatedWriter(format, width, height) {
|
|
419
|
+
if (format === 'gif') return createGifWriter(width, height);
|
|
420
|
+
if (format === 'apng') return createApngWriter(width, height);
|
|
421
|
+
if (format === 'webp') return createWebpWriter(width, height);
|
|
422
|
+
throw new Error(`Unknown animated image format: ${format}`);
|
|
423
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { appearanceFields, appearanceKinds, hasVectorFill } from './vector-style.js';
|
|
2
|
+
|
|
3
|
+
export function createAppearanceInspector(root, onEdit) {
|
|
4
|
+
const controls = [];
|
|
5
|
+
const fillColorLabel = root.querySelector('#fill-color-label');
|
|
6
|
+
for (const [property, kinds] of Object.entries(appearanceKinds)) {
|
|
7
|
+
const section = root.querySelector(`[data-appearance="${property}"]`);
|
|
8
|
+
const type = section.querySelector('select');
|
|
9
|
+
for (const [value, kind] of Object.entries(kinds)) type.add(new Option(kind.label, value));
|
|
10
|
+
const fields = section.querySelector('.field-row');
|
|
11
|
+
const names = new Set(Object.values(kinds).flatMap(kind => kind.fields));
|
|
12
|
+
const inputs = new Map();
|
|
13
|
+
for (const name of names) {
|
|
14
|
+
const field = appearanceFields[name];
|
|
15
|
+
const label = document.createElement('label');
|
|
16
|
+
label.className = 'field-label';
|
|
17
|
+
label.textContent = field.label;
|
|
18
|
+
const input = document.createElement('input');
|
|
19
|
+
input.id = `${property}-${name}`;
|
|
20
|
+
const numeric = typeof field.value === 'number', flag = typeof field.value === 'boolean';
|
|
21
|
+
input.className = numeric ? 'text-input' : flag ? '' : 'color-input';
|
|
22
|
+
input.type = numeric ? 'number' : flag ? 'checkbox' : 'color';
|
|
23
|
+
input.dataset.field = name;
|
|
24
|
+
if (numeric) {
|
|
25
|
+
input.min = field.min;
|
|
26
|
+
input.max = field.max;
|
|
27
|
+
input.step = 'any';
|
|
28
|
+
}
|
|
29
|
+
label.append(input);
|
|
30
|
+
fields.append(label);
|
|
31
|
+
inputs.set(name, input);
|
|
32
|
+
}
|
|
33
|
+
const control = { property, kinds, type, section, inputs, current: null };
|
|
34
|
+
section.addEventListener('change', event => {
|
|
35
|
+
if (event.target.disabled || event.target.dataset.property) return;
|
|
36
|
+
if (!type.value) return onEdit(property, null);
|
|
37
|
+
if (type === event.target) return onEdit(property, { ...control.current, type: type.value });
|
|
38
|
+
const input = event.target;
|
|
39
|
+
const value = input.type === 'number' ? input.valueAsNumber : input.type === 'checkbox' ? input.checked : input.value;
|
|
40
|
+
onEdit(property, { ...control.current, [input.dataset.field]: value });
|
|
41
|
+
});
|
|
42
|
+
controls.push(control);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return function render(element, pose) {
|
|
46
|
+
fillColorLabel.textContent = pose.gradient ? 'Start color' : 'Fill color';
|
|
47
|
+
for (const control of controls) {
|
|
48
|
+
const { property, kinds, type, section, inputs } = control;
|
|
49
|
+
section.hidden = property === 'gradient' && !hasVectorFill(element);
|
|
50
|
+
const current = pose[property];
|
|
51
|
+
control.current = current;
|
|
52
|
+
type.value = current?.type ?? '';
|
|
53
|
+
const names = current ? kinds[current.type].fields : [];
|
|
54
|
+
for (const [name, input] of inputs) {
|
|
55
|
+
const visible = names.includes(name);
|
|
56
|
+
input.parentElement.hidden = !visible;
|
|
57
|
+
input.required = visible && input.type === 'number';
|
|
58
|
+
if (visible && input.type === 'checkbox') input.checked = Boolean(current[name]);
|
|
59
|
+
else if (visible) input.value = current[name];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Parse the four arithmetic operators, decimal numbers and parentheses.
|
|
2
|
+
export function evaluateArithmetic(source) {
|
|
3
|
+
if (source.length > 512) throw new Error('Use an expression of 512 characters or fewer');
|
|
4
|
+
const tokens = source.trim().match(/(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?|[^\s]/gu) ?? [];
|
|
5
|
+
let index = 0;
|
|
6
|
+
|
|
7
|
+
function operand() {
|
|
8
|
+
const token = tokens[index++];
|
|
9
|
+
if (token === '+') return operand();
|
|
10
|
+
if (token === '-' || token === '−') return -operand();
|
|
11
|
+
if (token === '(') {
|
|
12
|
+
const value = sum();
|
|
13
|
+
if (tokens[index++] !== ')') throw new Error('Close the parenthesis');
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
if (!token || !/^[\d.]/.test(token) || !Number.isFinite(Number(token))) {
|
|
17
|
+
throw new Error('Enter a number or a parenthesized expression');
|
|
18
|
+
}
|
|
19
|
+
return Number(token);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function product() {
|
|
23
|
+
let value = operand();
|
|
24
|
+
while (['*', '×', '/', '÷'].includes(tokens[index])) {
|
|
25
|
+
const operator = tokens[index++];
|
|
26
|
+
const right = operand();
|
|
27
|
+
if (operator === '*' || operator === '×') value *= right;
|
|
28
|
+
else {
|
|
29
|
+
if (right === 0) throw new Error('Cannot divide by zero');
|
|
30
|
+
value /= right;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function sum() {
|
|
37
|
+
let value = product();
|
|
38
|
+
while (['+', '-', '−'].includes(tokens[index])) {
|
|
39
|
+
const operator = tokens[index++];
|
|
40
|
+
const right = product();
|
|
41
|
+
value = operator === '+' ? value + right : value - right;
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const value = sum();
|
|
47
|
+
if (index !== tokens.length) throw new Error('Check the operators and parentheses');
|
|
48
|
+
if (!Number.isFinite(value)) throw new Error('Result is outside the supported range');
|
|
49
|
+
return String(Number(value.toPrecision(15)));
|
|
50
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { controlDefinitions, defaultControlParameters } from '../../swooflib/control-definitions.js';
|
|
2
|
+
|
|
3
|
+
function readValue(value, label, depth = 0) {
|
|
4
|
+
if (value === null || typeof value === 'boolean' || typeof value === 'string' || Number.isFinite(value)) return value;
|
|
5
|
+
if (depth > 16 || !value || typeof value !== 'object') throw new Error(`${label} must be component data`);
|
|
6
|
+
if (Array.isArray(value)) return value.map(item => readValue(item, label, depth + 1));
|
|
7
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, readValue(item, label, depth + 1)]));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function readControl(raw, label) {
|
|
11
|
+
if (!Object.hasOwn(controlDefinitions, raw.control)) throw new Error(`${label} has an unsupported control kind`);
|
|
12
|
+
const control = raw.control;
|
|
13
|
+
const parameters = defaultControlParameters(control);
|
|
14
|
+
if (raw.parameters !== undefined && (!raw.parameters || typeof raw.parameters !== 'object' || Array.isArray(raw.parameters))) {
|
|
15
|
+
throw new Error(`${label}.parameters must be an object`);
|
|
16
|
+
}
|
|
17
|
+
for (const [key, value] of Object.entries(raw.parameters ?? {})) {
|
|
18
|
+
const field = `${control} ${key}`;
|
|
19
|
+
if (!Object.hasOwn(parameters, key)) throw new Error(`${field} is not a control parameter`);
|
|
20
|
+
const fallback = parameters[key];
|
|
21
|
+
const xmlProvider = key === 'dataProvider' && ['Menu', 'MenuBar', 'Tree', 'Accordion'].includes(control) && typeof value === 'string' && value.trimStart().startsWith('<');
|
|
22
|
+
const radioData = key === 'data' && control === 'RadioButton' && (Number.isFinite(value) || typeof value === 'boolean');
|
|
23
|
+
if (!xmlProvider && !radioData && (Array.isArray(fallback) ? !Array.isArray(value) : typeof value !== typeof fallback)) {
|
|
24
|
+
throw new Error(`${field} must be ${Array.isArray(fallback) ? 'a list' : typeof fallback}`);
|
|
25
|
+
}
|
|
26
|
+
parameters[key] = readValue(value, field);
|
|
27
|
+
}
|
|
28
|
+
if (parameters.minimum > parameters.maximum) throw new Error('Maximum must be at least the minimum');
|
|
29
|
+
for (const key of ['stepSize', 'snapInterval', 'rowHeight', 'rowCount']) {
|
|
30
|
+
if (key in parameters && !(parameters[key] > 0)) throw new Error(`${key} must be greater than zero`);
|
|
31
|
+
}
|
|
32
|
+
if (parameters.minScrollPosition > parameters.maxScrollPosition) throw new Error('Maximum scroll position must be at least the minimum');
|
|
33
|
+
if (parameters.selectedColor !== undefined && (!Number.isInteger(parameters.selectedColor) || parameters.selectedColor < 0 || parameters.selectedColor > 0xffffff)) throw new Error('Choose an RGB color');
|
|
34
|
+
if (parameters.selectedIndices?.some(index => !Number.isInteger(index) || index < 0)) throw new Error('Selected indices must be nonnegative integers');
|
|
35
|
+
if (parameters.firstDayOfWeek !== undefined && (!Number.isInteger(parameters.firstDayOfWeek) || parameters.firstDayOfWeek < 0 || parameters.firstDayOfWeek > 6)) throw new Error('First day of week must be between 0 and 6');
|
|
36
|
+
const result = { control, parameters };
|
|
37
|
+
if (raw.variable !== undefined && raw.variable !== '') {
|
|
38
|
+
if (typeof raw.variable !== 'string' || !raw.variable.trim()) throw new Error(`${label}.variable must be a variable name`);
|
|
39
|
+
result.variable = raw.variable.trim();
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// App-wide busy indicator for long operations (converting a SWF, opening a project, building a
|
|
2
|
+
// preview). The spinner turns with a CSS transform animation, which the browser runs off the main
|
|
3
|
+
// thread, so it keeps moving while the editor is busy building a large project.
|
|
4
|
+
const indicator = document.querySelector('#busy-indicator');
|
|
5
|
+
const label = document.querySelector('#busy-label');
|
|
6
|
+
const active = [];
|
|
7
|
+
|
|
8
|
+
function update() {
|
|
9
|
+
const current = active.at(-1);
|
|
10
|
+
indicator.hidden = !current;
|
|
11
|
+
label.textContent = current?.message ?? '';
|
|
12
|
+
document.body.toggleAttribute('aria-busy', !!current);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Show `message` until the returned function is called. Calls may nest. */
|
|
16
|
+
export function startBusy(message) {
|
|
17
|
+
const entry = { message };
|
|
18
|
+
active.push(entry);
|
|
19
|
+
update();
|
|
20
|
+
return () => {
|
|
21
|
+
const index = active.indexOf(entry);
|
|
22
|
+
if (index >= 0) active.splice(index, 1);
|
|
23
|
+
update();
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Run `task` with the indicator shown, after letting the browser paint it first. */
|
|
28
|
+
export async function whileBusy(message, task) {
|
|
29
|
+
const stop = startBusy(message);
|
|
30
|
+
try {
|
|
31
|
+
await nextPaint();
|
|
32
|
+
return await task();
|
|
33
|
+
} finally {
|
|
34
|
+
stop();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Resolve after the browser has painted, so heavy synchronous work starts with the indicator visible. */
|
|
39
|
+
export function nextPaint() {
|
|
40
|
+
return new Promise(resolve => requestAnimationFrame(() => setTimeout(resolve, 0)));
|
|
41
|
+
}
|