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,152 @@
|
|
|
1
|
+
// Preview builds: the editor posts its current project (unsaved edits included); the server
|
|
2
|
+
// converts it with project-movie.js, transpiles its ActionScript, and emits a swf2js movie
|
|
3
|
+
// into a temporary folder that the editor shows in a frame.
|
|
4
|
+
import { build } from 'esbuild';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
7
|
+
import { mkdir, mkdtemp, readdir, readFile, rename, rm, stat, utimes, writeFile } from 'node:fs/promises';
|
|
8
|
+
import { tmpdir } from 'node:os';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { SymbolTable } from '../../swf2js/decoder/symbol-table.js';
|
|
11
|
+
import { transpileActionScript } from '../../swf2js/transpiler/actionscript.js';
|
|
12
|
+
import { buildDisplayList } from '../../swf2js/transpiler/timeline/display-list.js';
|
|
13
|
+
import { precompileEmbeddedSwfs } from '../../swf2js/emitter/embedded-swf.js';
|
|
14
|
+
import { emit, resolveBundleDir } from '../../swf2js/emitter/bundle-emitter.js';
|
|
15
|
+
import { DiagnosticsCollector } from '../../swf2js/util/diagnostics.js';
|
|
16
|
+
import { parseProjectJson } from '../src/project-io.js';
|
|
17
|
+
import { badRequest, HttpError } from './http.js';
|
|
18
|
+
import { archivedCompanions } from './archive-companions.js';
|
|
19
|
+
import { buildProjectMovie } from './project-movie.js';
|
|
20
|
+
|
|
21
|
+
const EXTENSIONS = { 'image/png': 'png', 'image/jpeg': 'jpg', 'image/gif': 'gif', 'image/webp': 'webp', 'audio/mpeg': 'mp3', 'audio/wav': 'wav' };
|
|
22
|
+
|
|
23
|
+
/** Convert and emit `document`. Returns the folder that holds index.html. */
|
|
24
|
+
export async function buildPreview(document, { readStoredAsset, outDir, standalone = false, title, externalResources, projectId, record = false }) {
|
|
25
|
+
let project, movieSaveId;
|
|
26
|
+
try {
|
|
27
|
+
const json = JSON.stringify(document);
|
|
28
|
+
project = parseProjectJson(json);
|
|
29
|
+
movieSaveId = createHash('sha256').update(projectId ? 'studio-project:' + projectId : 'studio-document:' + json).digest('hex');
|
|
30
|
+
} catch (error) {
|
|
31
|
+
throw badRequest(error.message);
|
|
32
|
+
}
|
|
33
|
+
const readAsset = async asset => {
|
|
34
|
+
let bytes;
|
|
35
|
+
let mimeType = asset.type;
|
|
36
|
+
if (typeof asset.data === 'string' && asset.data.startsWith('data:')) {
|
|
37
|
+
mimeType = asset.data.slice(5, asset.data.indexOf(';'));
|
|
38
|
+
bytes = Buffer.from(asset.data.slice(asset.data.indexOf(',') + 1), 'base64');
|
|
39
|
+
} else if (asset.hash && readStoredAsset) {
|
|
40
|
+
bytes = await readStoredAsset(asset.hash);
|
|
41
|
+
}
|
|
42
|
+
if (!bytes) throw badRequest(`Preview could not load the media file “${asset.name}”`);
|
|
43
|
+
return { bytes, mimeType, ext: EXTENSIONS[mimeType] ?? 'bin' };
|
|
44
|
+
};
|
|
45
|
+
const movie = await buildProjectMovie(project, { readAsset });
|
|
46
|
+
const diagnostics = new DiagnosticsCollector();
|
|
47
|
+
const tags = [...(movie.nativeLibrary?.tags ?? []), ...movie.tags];
|
|
48
|
+
const actionScript = transpileActionScript(tags, diagnostics, {
|
|
49
|
+
sharedAvm1Runtime: true, sharedAvm2Runtime: true, swfVersion: movie.header.version,
|
|
50
|
+
});
|
|
51
|
+
const hasControls = Object.values(movie.displayList.characters).some(character => character.studioControl);
|
|
52
|
+
const moviePath = path.join(outDir, 'movie.swf');
|
|
53
|
+
// Video export records the movie in a frame with a virtual clock (studiospec/video-export.md §8.9).
|
|
54
|
+
if (record) {
|
|
55
|
+
await mkdir(resolveBundleDir(moviePath, outDir), { recursive: true });
|
|
56
|
+
await writeFile(path.join(resolveBundleDir(moviePath, outDir), 'recorder.js'),
|
|
57
|
+
await readFile(new URL('../src/preview-recorder.js', import.meta.url)));
|
|
58
|
+
}
|
|
59
|
+
if (hasControls) {
|
|
60
|
+
await build({ entryPoints: [fileURLToPath(new URL('../src/scripted-controls.js', import.meta.url))],
|
|
61
|
+
outfile: path.join(resolveBundleDir(moviePath, outDir), 'controls.js'), bundle: true, format: 'iife', globalName: 'swoofStudioControls' });
|
|
62
|
+
}
|
|
63
|
+
if (standalone) {
|
|
64
|
+
const files = new Map(movie.files.map(file => [`assets/${file.name}`, file.bytes]));
|
|
65
|
+
for (const asset of movie.assetManifest) {
|
|
66
|
+
asset.path = `data:${asset.mimeType};base64,${Buffer.from(files.get(asset.path)).toString('base64')}`;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const symbolTable = movie.nativeLibrary?.symbolTable ?? new SymbolTable();
|
|
70
|
+
const libraryDisplay = movie.nativeLibrary && buildDisplayList(tags, symbolTable, diagnostics,
|
|
71
|
+
{ sharedAvm1Runtime: true, swfVersion: movie.header.version, legacyButtonScripts: actionScript.legacyButtonScripts });
|
|
72
|
+
if (libraryDisplay) movie.displayList.characters = { ...libraryDisplay.characters, ...movie.displayList.characters };
|
|
73
|
+
for (const tag of movie.tags) {
|
|
74
|
+
if (tag.type === 'DefineBinaryData') symbolTable.set(tag.characterId, tag);
|
|
75
|
+
}
|
|
76
|
+
const result = emit({
|
|
77
|
+
header: movie.header, tags, symbolTable, actionScript, libraryDisplay,
|
|
78
|
+
displayList: movie.displayList, assetManifest: movie.assetManifest,
|
|
79
|
+
embeddedSwfs: await precompileEmbeddedSwfs(symbolTable, diagnostics),
|
|
80
|
+
companionSwfs: await archivedCompanions(movie.nativeLibrary?.sourceHash, diagnostics), backgroundColor: movie.backgroundColor,
|
|
81
|
+
}, moviePath, outDir, diagnostics, { title, externalResources, movieSaveId, inlineClassicScripts: standalone, externalTimelineData: true,
|
|
82
|
+
beforePlayerScripts: [...(record ? ['recorder.js'] : []), ...(hasControls ? ['controls.js'] : [])] });
|
|
83
|
+
if (!standalone) {
|
|
84
|
+
const assets = path.join(result.bundleDir, 'assets');
|
|
85
|
+
for (const file of movie.files) await writeFile(path.join(assets, file.name), file.bytes);
|
|
86
|
+
}
|
|
87
|
+
return { folder: result.bundleDir, notes: movie.report };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Publish the current project, including its runtime and media, in one HTML file. */
|
|
91
|
+
export async function exportProjectHtml(document, { readStoredAsset, name, externalResources, projectId }) {
|
|
92
|
+
const outDir = await mkdtemp(path.join(tmpdir(), 'swoof-html-'));
|
|
93
|
+
try {
|
|
94
|
+
const { folder, notes } = await buildPreview(document, { readStoredAsset, outDir, standalone: true, title: name, externalResources, projectId });
|
|
95
|
+
return { bytes: await readFile(path.join(folder, 'index.html')), notes };
|
|
96
|
+
} finally {
|
|
97
|
+
await rm(outDir, { recursive: true, force: true });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const STALE_MS = 24 * 60 * 60 * 1000;
|
|
102
|
+
const TOKEN = /^[0-9a-f]{32}$/;
|
|
103
|
+
|
|
104
|
+
// The URL identifies a published directory on disk. A restarted server can still serve
|
|
105
|
+
// a movie whose JavaScript is already running and whose sounds load later.
|
|
106
|
+
export function createPreviewStore(scope) {
|
|
107
|
+
const namespace = createHash('sha256').update(path.resolve(scope)).digest('hex').slice(0, 24);
|
|
108
|
+
const cache = path.join(tmpdir(), `swoof-movies-${namespace}`);
|
|
109
|
+
let lastSweep = 0;
|
|
110
|
+
|
|
111
|
+
async function sweep() {
|
|
112
|
+
if (Date.now() - lastSweep < 60 * 60 * 1000) return;
|
|
113
|
+
lastSweep = Date.now();
|
|
114
|
+
for (const name of await readdir(cache)) {
|
|
115
|
+
if (!TOKEN.test(name) && !name.startsWith('building-')) continue;
|
|
116
|
+
const dir = path.join(cache, name);
|
|
117
|
+
const info = await stat(dir).catch(() => null);
|
|
118
|
+
if (info?.isDirectory() && Date.now() - info.mtimeMs > STALE_MS) await rm(dir, { recursive: true, force: true });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
async create(document, readStoredAsset, externalResources, { record = false } = {}) {
|
|
124
|
+
await mkdir(cache, { recursive: true, mode: 0o700 });
|
|
125
|
+
await sweep();
|
|
126
|
+
const outDir = await mkdtemp(path.join(cache, 'building-'));
|
|
127
|
+
try {
|
|
128
|
+
const { folder, notes } = await buildPreview(document, { readStoredAsset, outDir, externalResources, record });
|
|
129
|
+
const token = randomBytes(16).toString('hex');
|
|
130
|
+
await rename(folder, path.join(cache, token));
|
|
131
|
+
return { token, notes };
|
|
132
|
+
} catch (error) {
|
|
133
|
+
if (error instanceof HttpError || error?.name === 'ScriptCompileError') throw error;
|
|
134
|
+
throw new HttpError(422, 'preview_failed', `Preview could not be built: ${error.message}`);
|
|
135
|
+
} finally {
|
|
136
|
+
await rm(outDir, { recursive: true, force: true });
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
async folder(token) {
|
|
140
|
+
if (!TOKEN.test(token)) return null;
|
|
141
|
+
const dir = path.join(cache, token);
|
|
142
|
+
const now = new Date();
|
|
143
|
+
try {
|
|
144
|
+
await utimes(dir, now, now);
|
|
145
|
+
return dir;
|
|
146
|
+
} catch (error) {
|
|
147
|
+
if (error.code === 'ENOENT') return null;
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
// Project folders: project.json is the commit point; scenes and symbols are immutable,
|
|
2
|
+
// content-hashed part files; edits between saves go to an append-only journal.
|
|
3
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
4
|
+
import { appendFile, mkdir, readdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { parseProjectJson, PROJECT_FORMAT, PROJECT_VERSION } from '../src/project-io.js';
|
|
7
|
+
import { collectAssets, findAsset, storeBytes, storeDataUrl, storeUpload } from './assets.js';
|
|
8
|
+
import { HttpError, notFound } from './http.js';
|
|
9
|
+
|
|
10
|
+
export const MANIFEST_FORMAT = 'swoof-studio-project';
|
|
11
|
+
export const MANIFEST_VERSION = 2;
|
|
12
|
+
const PROJECT_ID = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
13
|
+
const HASH = /^[0-9a-f]{64}$/;
|
|
14
|
+
const PART_KINDS = ['scenes', 'symbols', 'scripts'];
|
|
15
|
+
const DAY = 24 * 60 * 60 * 1000;
|
|
16
|
+
|
|
17
|
+
const sha256 = text => createHash('sha256').update(text).digest('hex');
|
|
18
|
+
|
|
19
|
+
async function writeAtomic(file, data) {
|
|
20
|
+
await mkdir(path.dirname(file), { recursive: true }); // Older projects lack newer part folders.
|
|
21
|
+
const temp = `${file}.${randomBytes(6).toString('hex')}.tmp`;
|
|
22
|
+
await writeFile(temp, data, { flag: 'wx' });
|
|
23
|
+
try {
|
|
24
|
+
await rename(temp, file);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
await rm(temp, { force: true });
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function slugify(name) {
|
|
32
|
+
const slug = name.normalize('NFKD').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 48);
|
|
33
|
+
return slug || 'project';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function readName(name) {
|
|
37
|
+
if (typeof name !== 'string' || !name.trim()) throw new HttpError(400, 'invalid_name', 'Give the project a name');
|
|
38
|
+
if (name.trim().length > 80) throw new HttpError(400, 'invalid_name', 'Project names can have up to 80 characters');
|
|
39
|
+
return name.trim();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function invalid(message) {
|
|
43
|
+
return new HttpError(422, 'invalid_project', message);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Validate a whole Studio document with the editor's own schema. */
|
|
47
|
+
export function validateDocument(document) {
|
|
48
|
+
try {
|
|
49
|
+
parseProjectJson(JSON.stringify(document));
|
|
50
|
+
} catch (error) {
|
|
51
|
+
throw invalid(error.message);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function createProjectStore(root, { assetLimit = 50 * 1024 * 1024, assetGraceMs = DAY } = {}) {
|
|
56
|
+
const base = path.resolve(root);
|
|
57
|
+
const locks = new Map();
|
|
58
|
+
|
|
59
|
+
function dirOf(id) {
|
|
60
|
+
if (typeof id !== 'string' || !PROJECT_ID.test(id)) throw notFound('Project not found');
|
|
61
|
+
return path.join(base, id);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Serialize every mutation of one project so revision checks and commits cannot interleave.
|
|
65
|
+
function locked(id, task) {
|
|
66
|
+
const previous = locks.get(id) ?? Promise.resolve();
|
|
67
|
+
const run = previous.then(task, task);
|
|
68
|
+
const tail = run.catch(() => {});
|
|
69
|
+
locks.set(id, tail);
|
|
70
|
+
tail.then(() => { if (locks.get(id) === tail) locks.delete(id); });
|
|
71
|
+
return run;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function readManifest(id) {
|
|
75
|
+
let text;
|
|
76
|
+
try {
|
|
77
|
+
text = await readFile(path.join(dirOf(id), 'project.json'), 'utf8');
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (error.code === 'ENOENT') throw notFound('Project not found');
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
const manifest = JSON.parse(text);
|
|
83
|
+
if (manifest.format !== MANIFEST_FORMAT || manifest.version !== MANIFEST_VERSION) {
|
|
84
|
+
throw new HttpError(500, 'unsupported_manifest', `Project ${id} uses an unsupported storage format`);
|
|
85
|
+
}
|
|
86
|
+
return manifest;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function readPart(id, kind, entry) {
|
|
90
|
+
if (!HASH.test(entry.hash)) throw new HttpError(500, 'corrupt_project', `Project ${id} lists an invalid part`);
|
|
91
|
+
const text = await readFile(path.join(dirOf(id), kind, `${entry.hash}.json`), 'utf8');
|
|
92
|
+
if (sha256(text) !== entry.hash) throw new HttpError(500, 'corrupt_project', `A ${kind.slice(0, -1)} file in ${id} is damaged`);
|
|
93
|
+
return JSON.parse(text);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function assemble(id, manifest) {
|
|
97
|
+
const document = { format: PROJECT_FORMAT, version: PROJECT_VERSION, stage: manifest.stage, scenes: [] };
|
|
98
|
+
const parts = {};
|
|
99
|
+
for (const kind of PART_KINDS) {
|
|
100
|
+
const entries = manifest[kind] ?? [];
|
|
101
|
+
parts[kind] = Object.fromEntries(entries.map(entry => [entry.id, entry.hash]));
|
|
102
|
+
const values = await Promise.all(entries.map(entry => readPart(id, kind, entry)));
|
|
103
|
+
if (kind === 'scenes' || values.length) document[kind] = values;
|
|
104
|
+
}
|
|
105
|
+
if (manifest.assets?.length) document.assets = manifest.assets;
|
|
106
|
+
return { document, parts };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function readJournal(id) {
|
|
110
|
+
const text = await readFile(path.join(dirOf(id), 'journal.ndjson'), 'utf8').catch(error => {
|
|
111
|
+
if (error.code === 'ENOENT') return '';
|
|
112
|
+
throw error;
|
|
113
|
+
});
|
|
114
|
+
const entries = [];
|
|
115
|
+
for (const line of text.split('\n')) {
|
|
116
|
+
if (!line.trim()) continue;
|
|
117
|
+
try { entries.push(JSON.parse(line)); } catch { break; } // A torn final write ends the journal.
|
|
118
|
+
}
|
|
119
|
+
return entries;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function readReports(id) {
|
|
123
|
+
return JSON.parse(await readFile(path.join(dirOf(id), 'reports.json'), 'utf8').catch(() => '[]'));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function summary(id, manifest, bytes = 0) {
|
|
127
|
+
return { id, name: manifest.name, revision: manifest.revision, modified: manifest.modified, bytes };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Write a new revision. `parts` lists every scene and symbol in order; each entry carries
|
|
132
|
+
* either `data` (changed) or `hash` (unchanged, already stored).
|
|
133
|
+
*/
|
|
134
|
+
async function commit(id, previous, { name, stage, assets = [], scenes, symbols = [], scripts = [] }) {
|
|
135
|
+
const dir = dirOf(id);
|
|
136
|
+
const known = new Map();
|
|
137
|
+
for (const kind of PART_KINDS) for (const entry of previous?.[kind] ?? []) known.set(`${kind}:${entry.hash}`, entry);
|
|
138
|
+
const writes = [];
|
|
139
|
+
const next = {};
|
|
140
|
+
const document = { format: PROJECT_FORMAT, version: PROJECT_VERSION, stage, scenes: [] };
|
|
141
|
+
for (const [kind, list] of [['scenes', scenes], ['symbols', symbols], ['scripts', scripts]]) {
|
|
142
|
+
if (!Array.isArray(list)) throw new HttpError(400, 'bad_request', `${kind} must be an array`);
|
|
143
|
+
next[kind] = [];
|
|
144
|
+
for (const part of list) {
|
|
145
|
+
if (!part || typeof part.id !== 'string') throw new HttpError(400, 'bad_request', `Each ${kind.slice(0, -1)} needs an id`);
|
|
146
|
+
let value, hash;
|
|
147
|
+
if (part.data !== undefined) {
|
|
148
|
+
const text = JSON.stringify(part.data);
|
|
149
|
+
hash = sha256(text);
|
|
150
|
+
value = part.data;
|
|
151
|
+
writes.push({ file: path.join(dir, kind, `${hash}.json`), text });
|
|
152
|
+
} else if (typeof part.hash === 'string' && known.has(`${kind}:${part.hash}`)) {
|
|
153
|
+
hash = part.hash;
|
|
154
|
+
value = await readPart(id, kind, { hash });
|
|
155
|
+
} else {
|
|
156
|
+
throw invalid(`The saved copy of ${kind.slice(0, -1)} ${part.id} is unknown. Reload the project`);
|
|
157
|
+
}
|
|
158
|
+
if (value?.id !== part.id) throw invalid(`Part ${part.id} does not match its content`);
|
|
159
|
+
next[kind].push({ id: part.id, hash });
|
|
160
|
+
if (kind === 'scenes' || list.length) document[kind] = document[kind] ?? [];
|
|
161
|
+
document[kind].push(value);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (!Array.isArray(assets)) throw new HttpError(400, 'bad_request', 'assets must be an array');
|
|
165
|
+
for (const asset of assets) {
|
|
166
|
+
if (asset?.data !== undefined) throw invalid('Upload media to the server before saving');
|
|
167
|
+
if (!asset || !HASH.test(asset.hash) || !await findAsset(path.join(dir, 'assets'), asset.hash)) {
|
|
168
|
+
throw invalid(`The media file for ${asset?.name ?? 'an asset'} is missing on the server`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (assets.length) document.assets = assets;
|
|
172
|
+
validateDocument(document);
|
|
173
|
+
|
|
174
|
+
for (const write of writes) {
|
|
175
|
+
const exists = await stat(write.file).then(() => true, () => false);
|
|
176
|
+
if (!exists) await writeAtomic(write.file, write.text);
|
|
177
|
+
}
|
|
178
|
+
const now = new Date().toISOString();
|
|
179
|
+
const manifest = {
|
|
180
|
+
format: MANIFEST_FORMAT, version: MANIFEST_VERSION, revision: (previous?.revision ?? 0) + 1,
|
|
181
|
+
name, created: previous?.created ?? now, modified: now, stage,
|
|
182
|
+
scenes: next.scenes, symbols: next.symbols, scripts: next.scripts, assets,
|
|
183
|
+
};
|
|
184
|
+
await writeAtomic(path.join(dir, 'project.json'), JSON.stringify(manifest, null, 2)); // Commit point.
|
|
185
|
+
await writeFile(path.join(dir, 'journal.ndjson'), '');
|
|
186
|
+
for (const kind of PART_KINDS) {
|
|
187
|
+
const keep = new Set(next[kind].map(entry => `${entry.hash}.json`));
|
|
188
|
+
for (const file of await readdir(path.join(dir, kind)).catch(() => [])) {
|
|
189
|
+
if (!keep.has(file)) await rm(path.join(dir, kind, file), { force: true });
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
await collectAssets(path.join(dir, 'assets'), new Set(assets.map(asset => asset.hash)), assetGraceMs);
|
|
193
|
+
return { manifest, parts: Object.fromEntries(PART_KINDS.map(kind =>
|
|
194
|
+
[kind, Object.fromEntries(next[kind].map(entry => [entry.id, entry.hash]))])) };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async function reserve(name) {
|
|
198
|
+
await mkdir(base, { recursive: true });
|
|
199
|
+
const slug = slugify(name);
|
|
200
|
+
for (let n = 1; n < 1000; n++) {
|
|
201
|
+
const id = n === 1 ? slug : `${slug}-${n}`;
|
|
202
|
+
try {
|
|
203
|
+
await mkdir(path.join(base, id));
|
|
204
|
+
for (const folder of [...PART_KINDS, 'assets']) await mkdir(path.join(base, id, folder));
|
|
205
|
+
return id;
|
|
206
|
+
} catch (error) {
|
|
207
|
+
if (error.code !== 'EEXIST') throw error;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
throw new HttpError(409, 'name_taken', 'Choose a different project name');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function splitDocument(document) {
|
|
214
|
+
const parts = kind => (document[kind] ?? []).map(data => ({ id: data?.id, data }));
|
|
215
|
+
return { stage: document.stage, assets: document.assets ?? [], scenes: parts('scenes'), symbols: parts('symbols'), scripts: parts('scripts') };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return {
|
|
219
|
+
root: base,
|
|
220
|
+
|
|
221
|
+
async list() {
|
|
222
|
+
const entries = await readdir(base, { withFileTypes: true }).catch(() => []);
|
|
223
|
+
const projects = [];
|
|
224
|
+
for (const entry of entries) {
|
|
225
|
+
if (!entry.isDirectory() || !PROJECT_ID.test(entry.name)) continue;
|
|
226
|
+
try {
|
|
227
|
+
const manifest = await readManifest(entry.name);
|
|
228
|
+
projects.push(summary(entry.name, manifest));
|
|
229
|
+
} catch {
|
|
230
|
+
// Skip folders that are not committed Studio projects.
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return projects.sort((a, b) => String(b.modified).localeCompare(String(a.modified)));
|
|
234
|
+
},
|
|
235
|
+
|
|
236
|
+
/** Create a project. With a document, its media must already use server asset entries. */
|
|
237
|
+
async create({ name, document, prepare }) {
|
|
238
|
+
name = readName(name);
|
|
239
|
+
if (!prepare && document) {
|
|
240
|
+
if (typeof document !== 'object' || Array.isArray(document)) throw new HttpError(400, 'bad_request', 'project must be an object');
|
|
241
|
+
// Portable documents embed media; store it as content-addressed files first.
|
|
242
|
+
prepare = async (id, dir) => {
|
|
243
|
+
const assets = [];
|
|
244
|
+
for (const asset of Array.isArray(document.assets) ? document.assets : []) {
|
|
245
|
+
if (asset?.data === undefined) throw invalid('New projects must embed their media');
|
|
246
|
+
const stored = await storeDataUrl(dir, asset.data, { name: String(asset.name ?? 'media'), limit: assetLimit });
|
|
247
|
+
assets.push({ id: asset.id, ...stored, name: asset.name, kind: stored.kind, ...(asset.linkage !== undefined ? { linkage: asset.linkage } : {}) });
|
|
248
|
+
}
|
|
249
|
+
return { ...document, assets };
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
const id = await reserve(name);
|
|
253
|
+
try {
|
|
254
|
+
return await locked(id, async () => {
|
|
255
|
+
const doc = prepare ? await prepare(id, path.join(base, id, 'assets')) : document;
|
|
256
|
+
if (!doc) throw new HttpError(400, 'bad_request', 'Provide a project document');
|
|
257
|
+
const { manifest, parts } = await commit(id, null, { name, ...splitDocument(doc) });
|
|
258
|
+
return { ...summary(id, manifest), parts, assets: manifest.assets };
|
|
259
|
+
});
|
|
260
|
+
} catch (error) {
|
|
261
|
+
await rm(path.join(base, id), { recursive: true, force: true });
|
|
262
|
+
throw error;
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
|
|
266
|
+
async part(id, hash) {
|
|
267
|
+
if (!HASH.test(hash)) throw notFound('Project part not found');
|
|
268
|
+
const dir = dirOf(id);
|
|
269
|
+
for (const kind of PART_KINDS) {
|
|
270
|
+
try {
|
|
271
|
+
const bytes = await readFile(path.join(dir, kind, hash + '.json'));
|
|
272
|
+
if (sha256(bytes) !== hash) throw new HttpError(500, 'corrupt_project', `A part in ${id} is damaged`);
|
|
273
|
+
return bytes;
|
|
274
|
+
} catch (error) {
|
|
275
|
+
if (error.code !== 'ENOENT') throw error;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
throw notFound('Project part not found');
|
|
279
|
+
},
|
|
280
|
+
|
|
281
|
+
async load(id, { manifestOnly = false } = {}) {
|
|
282
|
+
return locked(id, async () => {
|
|
283
|
+
const manifest = await readManifest(id);
|
|
284
|
+
const journal = (await readJournal(id)).filter(entry => entry.base === manifest.revision);
|
|
285
|
+
const info = { ...summary(id, manifest), journal, reports: await readReports(id) };
|
|
286
|
+
if (manifestOnly) {
|
|
287
|
+
const { stage, assets, scenes, symbols = [], scripts = [] } = manifest;
|
|
288
|
+
return { ...info, manifest: { format: PROJECT_FORMAT, version: PROJECT_VERSION, stage, assets, scenes, symbols, scripts } };
|
|
289
|
+
}
|
|
290
|
+
const { document, parts } = await assemble(id, manifest);
|
|
291
|
+
return { ...info, project: document, parts };
|
|
292
|
+
});
|
|
293
|
+
},
|
|
294
|
+
|
|
295
|
+
async save(id, revision, body) {
|
|
296
|
+
return locked(id, async () => {
|
|
297
|
+
const previous = await readManifest(id);
|
|
298
|
+
if (revision !== previous.revision) {
|
|
299
|
+
throw new HttpError(409, 'conflict', 'This project was saved elsewhere. Reload it before saving', { revision: previous.revision });
|
|
300
|
+
}
|
|
301
|
+
const name = body?.name === undefined ? previous.name : readName(body.name);
|
|
302
|
+
const { manifest, parts } = await commit(id, previous, { ...body, name });
|
|
303
|
+
return { ...summary(id, manifest), parts };
|
|
304
|
+
});
|
|
305
|
+
},
|
|
306
|
+
|
|
307
|
+
async appendJournal(id, entry) {
|
|
308
|
+
return locked(id, async () => {
|
|
309
|
+
const manifest = await readManifest(id);
|
|
310
|
+
if (!entry || !Number.isInteger(entry.base) || !Number.isInteger(entry.seq) || !Array.isArray(entry.ops)) {
|
|
311
|
+
throw new HttpError(400, 'bad_request', 'Journal entries need base, seq, and ops');
|
|
312
|
+
}
|
|
313
|
+
const entries = (await readJournal(id)).filter(item => item.base === manifest.revision);
|
|
314
|
+
const expected = (entries.at(-1)?.seq ?? 0) + 1;
|
|
315
|
+
if (entry.base !== manifest.revision || entry.seq !== expected) {
|
|
316
|
+
throw new HttpError(409, 'journal_conflict', 'The journal moved on. Reload the project', { revision: manifest.revision, seq: expected - 1 });
|
|
317
|
+
}
|
|
318
|
+
const line = JSON.stringify({ base: entry.base, seq: entry.seq, time: new Date().toISOString(), ops: entry.ops });
|
|
319
|
+
await appendFile(path.join(dirOf(id), 'journal.ndjson'), line + '\n');
|
|
320
|
+
return { seq: entry.seq };
|
|
321
|
+
});
|
|
322
|
+
},
|
|
323
|
+
|
|
324
|
+
async discardJournal(id) {
|
|
325
|
+
return locked(id, async () => {
|
|
326
|
+
await readManifest(id);
|
|
327
|
+
await writeFile(path.join(dirOf(id), 'journal.ndjson'), '');
|
|
328
|
+
});
|
|
329
|
+
},
|
|
330
|
+
|
|
331
|
+
async remove(id) {
|
|
332
|
+
return locked(id, async () => {
|
|
333
|
+
await readManifest(id);
|
|
334
|
+
await rm(dirOf(id), { recursive: true, force: true });
|
|
335
|
+
});
|
|
336
|
+
},
|
|
337
|
+
|
|
338
|
+
async upload(id, req, name) {
|
|
339
|
+
await readManifest(id);
|
|
340
|
+
return storeUpload(path.join(dirOf(id), 'assets'), req, { name, limit: assetLimit });
|
|
341
|
+
},
|
|
342
|
+
|
|
343
|
+
async storeMedia(id, data, info) {
|
|
344
|
+
return storeBytes(path.join(dirOf(id), 'assets'), data, info);
|
|
345
|
+
},
|
|
346
|
+
|
|
347
|
+
async assetFile(id, hash) {
|
|
348
|
+
return findAsset(path.join(dirOf(id), 'assets'), hash);
|
|
349
|
+
},
|
|
350
|
+
|
|
351
|
+
async addReport(id, report) {
|
|
352
|
+
return locked(id, async () => {
|
|
353
|
+
const reports = await readReports(id);
|
|
354
|
+
reports.push(report);
|
|
355
|
+
await writeAtomic(path.join(dirOf(id), 'reports.json'), JSON.stringify(reports.slice(-20), null, 2));
|
|
356
|
+
});
|
|
357
|
+
},
|
|
358
|
+
|
|
359
|
+
assetsDir(id) {
|
|
360
|
+
return path.join(dirOf(id), 'assets');
|
|
361
|
+
},
|
|
362
|
+
|
|
363
|
+
/** The project's folder, or a 404 when there is no such project. */
|
|
364
|
+
async folder(id) {
|
|
365
|
+
const dir = dirOf(id);
|
|
366
|
+
if (!await stat(path.join(dir, 'project.json')).then(() => true, () => false)) throw notFound('Project not found');
|
|
367
|
+
return dir;
|
|
368
|
+
},
|
|
369
|
+
};
|
|
370
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Conversion reports: every feature that was approximated or not converted, with counts
|
|
2
|
+
// and a few example locations. Shared by SWF import and, later, SWF export.
|
|
3
|
+
|
|
4
|
+
const MAX_LOCATIONS = 5;
|
|
5
|
+
|
|
6
|
+
export function createReport(source) {
|
|
7
|
+
const entries = new Map();
|
|
8
|
+
return {
|
|
9
|
+
/** Record one occurrence. `severity` is "approximated" or "dropped". */
|
|
10
|
+
add(severity, feature, where) {
|
|
11
|
+
const key = `${severity}:${feature}`;
|
|
12
|
+
let entry = entries.get(key);
|
|
13
|
+
if (!entry) entries.set(key, entry = { severity, feature, count: 0, where: [] });
|
|
14
|
+
entry.count++;
|
|
15
|
+
if (where && entry.where.length < MAX_LOCATIONS && !entry.where.includes(where)) entry.where.push(where);
|
|
16
|
+
},
|
|
17
|
+
approximated(feature, where) { this.add('approximated', feature, where); },
|
|
18
|
+
dropped(feature, where) { this.add('dropped', feature, where); },
|
|
19
|
+
finish(summary) {
|
|
20
|
+
const order = { dropped: 0, approximated: 1 };
|
|
21
|
+
return {
|
|
22
|
+
source,
|
|
23
|
+
time: new Date().toISOString(),
|
|
24
|
+
summary,
|
|
25
|
+
entries: [...entries.values()].sort((a, b) => order[a.severity] - order[b.severity] || b.count - a.count),
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// /api route table for createStudioServer. Handlers adapt HTTP to the project store.
|
|
2
|
+
import { createReadStream } from 'node:fs';
|
|
3
|
+
import { stat } from 'node:fs/promises';
|
|
4
|
+
import { badRequest, fileNameHeader, HttpError, readBuffer, readJson, sendJson, sendJsonBytes } from './http.js';
|
|
5
|
+
import { importSwfLibrary, openSwfProject } from './swf-routes.js';
|
|
6
|
+
|
|
7
|
+
function ifMatch(req) {
|
|
8
|
+
const match = /^"?(\d+)"?$/.exec(req.headers['if-match'] ?? '');
|
|
9
|
+
if (!match) throw new HttpError(428, 'precondition_required', 'Saving requires the revision you opened (If-Match)');
|
|
10
|
+
return Number(match[1]);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function createApiRoutes(store, { swfLimit = 100 * 1024 * 1024, decompressedLimit = 256 * 1024 * 1024, swfObjects = 50000, jsonLimit } = {}) {
|
|
14
|
+
const swfOptions = { swfLimit, decompressedLimit, maxObjects: swfObjects };
|
|
15
|
+
return {
|
|
16
|
+
'GET /api/projects': async (req, res) => sendJson(res, 200, { projects: await store.list() }),
|
|
17
|
+
|
|
18
|
+
'POST /api/projects': async (req, res) => {
|
|
19
|
+
const body = await readJson(req, jsonLimit);
|
|
20
|
+
const created = await store.create({ name: body?.name, document: body?.project });
|
|
21
|
+
return sendJson(res, 201, created, { ETag: `"${created.revision}"` });
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
'GET /api/projects/:id': async (req, res, url, { id }) => {
|
|
25
|
+
const project = await store.load(id, { manifestOnly: url.searchParams.get('view') === 'manifest' });
|
|
26
|
+
return sendJson(res, 200, project, { ETag: `"${project.revision}"` });
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
'GET /api/projects/:id/parts/:hash': async (req, res, url, { id, hash }) => {
|
|
30
|
+
const bytes = await store.part(id, hash);
|
|
31
|
+
const headers = { ETag: `W/"${hash}"`, 'Cache-Control': 'private, max-age=31536000, immutable' };
|
|
32
|
+
const validators = (req.headers['if-none-match'] ?? '').split(',').map(item => item.trim().replace(/^W\//, ''));
|
|
33
|
+
if (validators.includes(`"${hash}"`) || validators.includes('*')) {
|
|
34
|
+
res.writeHead(304, { ...headers, Vary: 'Accept-Encoding' });
|
|
35
|
+
return res.end();
|
|
36
|
+
}
|
|
37
|
+
return sendJsonBytes(res, 200, bytes, headers);
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
'PUT /api/projects/:id': async (req, res, url, { id }) => {
|
|
41
|
+
const revision = ifMatch(req);
|
|
42
|
+
const saved = await store.save(id, revision, await readJson(req, jsonLimit));
|
|
43
|
+
return sendJson(res, 200, saved, { ETag: `"${saved.revision}"` });
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
'DELETE /api/projects/:id': async (req, res, url, { id }) => {
|
|
47
|
+
await store.remove(id);
|
|
48
|
+
return sendJson(res, 200, { deleted: id });
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
'POST /api/projects/:id/journal': async (req, res, url, { id }) => {
|
|
52
|
+
return sendJson(res, 200, await store.appendJournal(id, await readJson(req, jsonLimit)));
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
'DELETE /api/projects/:id/journal': async (req, res, url, { id }) => {
|
|
56
|
+
await store.discardJournal(id);
|
|
57
|
+
return sendJson(res, 200, { discarded: true });
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
'POST /api/projects/:id/assets': async (req, res, url, { id }) => {
|
|
61
|
+
return sendJson(res, 201, await store.upload(id, req, fileNameHeader(req, 'media')));
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
'GET /api/projects/:id/assets/:hash': async (req, res, url, { id, hash }) => {
|
|
65
|
+
const asset = await store.assetFile(id, hash);
|
|
66
|
+
if (!asset) throw new HttpError(404, 'not_found', 'Media not found');
|
|
67
|
+
const info = await stat(asset.file);
|
|
68
|
+
res.writeHead(200, {
|
|
69
|
+
'Content-Type': asset.type,
|
|
70
|
+
'Content-Length': info.size,
|
|
71
|
+
'Cache-Control': 'private, max-age=31536000, immutable',
|
|
72
|
+
'X-Content-Type-Options': 'nosniff',
|
|
73
|
+
'Content-Security-Policy': "sandbox; default-src 'none'; img-src data:; style-src 'unsafe-inline'",
|
|
74
|
+
});
|
|
75
|
+
if (req.method === 'HEAD') return res.end();
|
|
76
|
+
createReadStream(asset.file).pipe(res);
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
'POST /api/swf/open': async (req, res) => {
|
|
80
|
+
const name = fileNameHeader(req, 'movie.swf');
|
|
81
|
+
const bytes = await readBuffer(req, swfLimit);
|
|
82
|
+
if (!bytes.length) throw badRequest(`${name} is empty`);
|
|
83
|
+
return sendJson(res, 201, await openSwfProject(store, bytes, name, swfOptions));
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
'POST /api/projects/:id/swf': async (req, res, url, { id }) => {
|
|
87
|
+
const name = fileNameHeader(req, 'movie.swf');
|
|
88
|
+
const bytes = await readBuffer(req, swfLimit);
|
|
89
|
+
if (!bytes.length) throw badRequest(`${name} is empty`);
|
|
90
|
+
return sendJson(res, 200, await importSwfLibrary(store, id, bytes, name, swfOptions));
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|