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,10 @@
|
|
|
1
|
+
export function advancePlayhead(scene, frame, steps) {
|
|
2
|
+
const next = frame + steps;
|
|
3
|
+
if (next <= scene.durationFrames) return { frame: next, finished: false };
|
|
4
|
+
if (!scene.loop) return { frame: scene.durationFrames, finished: true };
|
|
5
|
+
|
|
6
|
+
const first = scene.startFrame ?? 1;
|
|
7
|
+
const length = scene.durationFrames - first + 1;
|
|
8
|
+
const framesAfterEnd = next - scene.durationFrames - 1;
|
|
9
|
+
return { frame: first + framesAfterEnd % length, finished: false };
|
|
10
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { resolveStreamAudioTime } from '../swooflib/stream-time.js';
|
|
2
|
+
import { decodedAsset } from './media-assets.js';
|
|
3
|
+
|
|
4
|
+
// Voices exist only during preview playback. The evaluated frame is the source of time.
|
|
5
|
+
export function createPreviewAudio(report) {
|
|
6
|
+
let context;
|
|
7
|
+
const voices = new Map();
|
|
8
|
+
function stop(key) {
|
|
9
|
+
const voice = voices.get(key);
|
|
10
|
+
if (voice) {
|
|
11
|
+
voice.source.stop();
|
|
12
|
+
voice.source.disconnect();
|
|
13
|
+
voices.delete(key);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function unlock(assets) {
|
|
17
|
+
if (!assets.some(asset => asset.kind === 'audio')) return;
|
|
18
|
+
try {
|
|
19
|
+
context ??= new AudioContext();
|
|
20
|
+
if (context.state === 'suspended') context.resume().catch(() => report('Allow sound in this browser to hear the preview'));
|
|
21
|
+
} catch { report('Audio playback is unavailable in this browser'); }
|
|
22
|
+
}
|
|
23
|
+
function sync(assets, timelines, fps, playing) {
|
|
24
|
+
const active = new Set();
|
|
25
|
+
if (playing) for (const entry of timelines) {
|
|
26
|
+
if (!entry.audioActive) continue;
|
|
27
|
+
for (const clip of entry.timeline.audioClips ?? []) {
|
|
28
|
+
if (entry.frame < clip.start || entry.frame > clip.end) continue;
|
|
29
|
+
const asset = assets.find(item => item.id === clip.assetId);
|
|
30
|
+
const buffer = decodedAsset(asset);
|
|
31
|
+
if (!buffer) continue;
|
|
32
|
+
const elapsed = clip.streamSync
|
|
33
|
+
? resolveStreamAudioTime(clip.streamSync, entry.frame - clip.start, fps)
|
|
34
|
+
: (entry.frame - clip.start) / fps;
|
|
35
|
+
if (elapsed == null) continue;
|
|
36
|
+
if (!clip.loop && elapsed >= buffer.duration) continue;
|
|
37
|
+
const key = JSON.stringify([entry.timeline.id, entry.scope, clip.id]);
|
|
38
|
+
active.add(key);
|
|
39
|
+
if (!context) continue;
|
|
40
|
+
const voice = voices.get(key);
|
|
41
|
+
const rootFrame = timelines[0].frame;
|
|
42
|
+
const wrapped = entry.repeatOnTick && voice?.lastFrame === entry.frame && voice.rootFrame !== rootFrame;
|
|
43
|
+
if (voice && !wrapped && voice.exposure === entry.exposure && entry.frame >= voice.lastFrame &&
|
|
44
|
+
Math.abs(context.currentTime - voice.origin - elapsed) < Math.max(0.12, 1.5 / fps)) {
|
|
45
|
+
voice.lastFrame = entry.frame;
|
|
46
|
+
voice.rootFrame = rootFrame;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
stop(key);
|
|
50
|
+
const source = context.createBufferSource();
|
|
51
|
+
source.buffer = buffer;
|
|
52
|
+
source.loop = clip.loop;
|
|
53
|
+
source.connect(context.destination);
|
|
54
|
+
source.start(0, elapsed % buffer.duration);
|
|
55
|
+
source.stop(context.currentTime + (clip.end - entry.frame + 1) / fps);
|
|
56
|
+
voices.set(key, { source, scope: entry.scope, rootFrame, origin: context.currentTime - elapsed, lastFrame: entry.frame, exposure: entry.exposure });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
for (const key of voices.keys()) if (!active.has(key)) stop(key);
|
|
60
|
+
}
|
|
61
|
+
return { sync, unlock, reset(scope = []) {
|
|
62
|
+
for (const [key, voice] of voices) if (scope.every((id, index) => id === voice.scope[index])) stop(key);
|
|
63
|
+
} };
|
|
64
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { acceptsPointer, eventKey, isKeyTrigger, matchesRelease } from './interaction-triggers.js';
|
|
2
|
+
|
|
3
|
+
// Resolve a release against the current display tree. Authored frames can hide
|
|
4
|
+
// a button or navigate away while a finger or key is still held.
|
|
5
|
+
export function bindPreviewInteractions({ mat, canvas, renderer, active, point, run, feedback }) {
|
|
6
|
+
const pointers = new Map();
|
|
7
|
+
const keys = new Map();
|
|
8
|
+
let hover = null;
|
|
9
|
+
const paint = () => feedback(hover, Array.from(pointers.values()).at(-1)?.id ?? null);
|
|
10
|
+
const at = event => {
|
|
11
|
+
const entry = renderer.buttonAt(point(event));
|
|
12
|
+
return entry && acceptsPointer(entry.element.buttonAction, event.pointerType) ? entry : null;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
mat.addEventListener('pointerdown', event => {
|
|
16
|
+
if (!active() || event.button !== 0) return;
|
|
17
|
+
const entry = at(event);
|
|
18
|
+
if (!entry) return;
|
|
19
|
+
// Keep a field's selection when an overlapping drawn button receives the hit.
|
|
20
|
+
if (event.target.matches('.preview-text-field')) event.preventDefault();
|
|
21
|
+
pointers.set(event.pointerId, { id: entry.id, x: event.clientX, y: event.clientY, travel: 0, pointerType: event.pointerType });
|
|
22
|
+
canvas.setPointerCapture(event.pointerId);
|
|
23
|
+
hover = entry.id;
|
|
24
|
+
paint();
|
|
25
|
+
});
|
|
26
|
+
mat.addEventListener('pointermove', event => {
|
|
27
|
+
if (!active()) return;
|
|
28
|
+
const press = pointers.get(event.pointerId);
|
|
29
|
+
if (press) press.travel = Math.max(press.travel, Math.hypot(event.clientX - press.x, event.clientY - press.y));
|
|
30
|
+
hover = at(event)?.id ?? null;
|
|
31
|
+
paint();
|
|
32
|
+
});
|
|
33
|
+
function release(event, cancelled) {
|
|
34
|
+
const press = pointers.get(event.pointerId);
|
|
35
|
+
if (!press) return;
|
|
36
|
+
pointers.delete(event.pointerId);
|
|
37
|
+
if (canvas.hasPointerCapture(event.pointerId)) canvas.releasePointerCapture(event.pointerId);
|
|
38
|
+
const hit = !cancelled && active() ? at(event) : null;
|
|
39
|
+
hover = event.pointerType === 'touch' ? null : hit?.id ?? null;
|
|
40
|
+
paint();
|
|
41
|
+
if (!active() || cancelled) return;
|
|
42
|
+
const entry = renderer.previewButton(press.id);
|
|
43
|
+
press.travel = Math.max(press.travel, Math.hypot(event.clientX - press.x, event.clientY - press.y));
|
|
44
|
+
if (entry && matchesRelease(entry.element.buttonAction, press, event, hit?.id === entry.id)) run(entry);
|
|
45
|
+
}
|
|
46
|
+
mat.addEventListener('pointerup', event => release(event, false));
|
|
47
|
+
mat.addEventListener('pointercancel', event => release(event, true));
|
|
48
|
+
canvas.addEventListener('lostpointercapture', event => release(event, true));
|
|
49
|
+
mat.addEventListener('pointerleave', () => {
|
|
50
|
+
if (!active()) return;
|
|
51
|
+
hover = null;
|
|
52
|
+
paint();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
mat.addEventListener('click', event => {
|
|
56
|
+
const id = event.target.dataset.previewButton;
|
|
57
|
+
const entry = active() && id && renderer.previewButton(id);
|
|
58
|
+
if (entry) run(entry);
|
|
59
|
+
});
|
|
60
|
+
mat.addEventListener('keydown', event => {
|
|
61
|
+
if (!active() || event.isComposing || event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
62
|
+
if (event.target.matches('.preview-text-field')) {
|
|
63
|
+
if (event.key !== 'Enter' || event.shiftKey || event.repeat) return;
|
|
64
|
+
const submit = renderer.submitFor(event.target.dataset.elementId);
|
|
65
|
+
if (submit) {
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
run(submit);
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const key = eventKey(event);
|
|
72
|
+
const focused = event.target.dataset.previewButton;
|
|
73
|
+
// Enter/Space on a focused button retain native button activation.
|
|
74
|
+
const local = focused && renderer.previewButton(focused);
|
|
75
|
+
const localAction = local?.element.buttonAction;
|
|
76
|
+
const localMatch = localAction && isKeyTrigger(localAction.trigger) && localAction.key === key;
|
|
77
|
+
if (focused && !localMatch && ['Space', 'Enter'].includes(key)) return;
|
|
78
|
+
const entry = localMatch ? local : renderer.buttonForKey(key);
|
|
79
|
+
if (!entry) return;
|
|
80
|
+
event.preventDefault();
|
|
81
|
+
if (event.repeat || keys.has(key)) return;
|
|
82
|
+
keys.set(key, entry.id);
|
|
83
|
+
if (entry.element.buttonAction.trigger === 'keyDown') run(entry);
|
|
84
|
+
});
|
|
85
|
+
mat.addEventListener('keyup', event => {
|
|
86
|
+
const key = eventKey(event), id = keys.get(key);
|
|
87
|
+
keys.delete(key);
|
|
88
|
+
if (!id || !active() || event.isComposing || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
const entry = renderer.previewButton(id);
|
|
91
|
+
const action = entry?.element.buttonAction;
|
|
92
|
+
if (action?.trigger === 'keyUp' && action.key === key) run(entry);
|
|
93
|
+
});
|
|
94
|
+
mat.addEventListener('focusout', () => keys.clear());
|
|
95
|
+
function reset() {
|
|
96
|
+
for (const id of pointers.keys()) if (canvas.hasPointerCapture(id)) canvas.releasePointerCapture(id);
|
|
97
|
+
pointers.clear();
|
|
98
|
+
keys.clear();
|
|
99
|
+
hover = null;
|
|
100
|
+
}
|
|
101
|
+
window.addEventListener('blur', () => {
|
|
102
|
+
reset();
|
|
103
|
+
if (active()) paint();
|
|
104
|
+
});
|
|
105
|
+
return { reset };
|
|
106
|
+
}
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
// Video recording of a movie on the swf2js player (studiospec/video-export.md §8.9). Loaded before
|
|
2
|
+
// the player in a Preview build made with `record: true`, inside the sandboxed movie frame, and
|
|
3
|
+
// active only when the page URL has `?swoofRecord=1`.
|
|
4
|
+
//
|
|
5
|
+
// Time is virtual once recording starts: requestAnimationFrame, timers, performance.now and Date
|
|
6
|
+
// advance only when the editor asks for the next frame, by exactly 1/frame rate. Media elements
|
|
7
|
+
// do not play: their play, pause, seeks and volume are logged as segments at video time, they
|
|
8
|
+
// report the position the virtual clock gives them and fire timeupdate and ended, and the
|
|
9
|
+
// segments are mixed offline at the end. The editor gets each frame as an ImageBitmap.
|
|
10
|
+
(function () {
|
|
11
|
+
'use strict';
|
|
12
|
+
if (!/[?&]swoofRecord=1(?:&|$)/.test(location.search)) return;
|
|
13
|
+
|
|
14
|
+
// The movie runtime defines Flash's own Event and Date classes on window later.
|
|
15
|
+
var DomEvent = window.Event;
|
|
16
|
+
var realNow = performance.now.bind(performance);
|
|
17
|
+
var realSetTimeout = window.setTimeout.bind(window);
|
|
18
|
+
var realClearTimeout = window.clearTimeout.bind(window);
|
|
19
|
+
var realSetInterval = window.setInterval.bind(window);
|
|
20
|
+
var realClearInterval = window.clearInterval.bind(window);
|
|
21
|
+
var RealDate = Date;
|
|
22
|
+
var epoch = RealDate.now() - realNow();
|
|
23
|
+
var recording = false;
|
|
24
|
+
var now = 0; // Virtual milliseconds since the page started, while recording.
|
|
25
|
+
|
|
26
|
+
var clock = function () { return recording ? now : realNow(); };
|
|
27
|
+
performance.now = clock;
|
|
28
|
+
function VirtualDate() {
|
|
29
|
+
var args = Array.prototype.slice.call(arguments);
|
|
30
|
+
if (!(this instanceof VirtualDate)) return new RealDate(epoch + clock()).toString();
|
|
31
|
+
return args.length ? new (Function.prototype.bind.apply(RealDate, [null].concat(args)))() : new RealDate(epoch + clock());
|
|
32
|
+
}
|
|
33
|
+
VirtualDate.prototype = RealDate.prototype;
|
|
34
|
+
VirtualDate.now = function () { return Math.floor(epoch + clock()); };
|
|
35
|
+
VirtualDate.parse = RealDate.parse;
|
|
36
|
+
VirtualDate.UTC = RealDate.UTC;
|
|
37
|
+
window.Date = VirtualDate;
|
|
38
|
+
|
|
39
|
+
// Timers: real until recording starts (loading needs them), virtual afterwards.
|
|
40
|
+
var timers = new Map(), nextTimer = 1;
|
|
41
|
+
function virtualTimer(callback, delay, args, repeat) {
|
|
42
|
+
if (!recording) {
|
|
43
|
+
return repeat ? realSetInterval.apply(null, [callback, delay].concat(args)) : realSetTimeout.apply(null, [callback, delay].concat(args));
|
|
44
|
+
}
|
|
45
|
+
var id = 1e9 + nextTimer++;
|
|
46
|
+
timers.set(id, { callback: callback, args: args, at: now + Math.max(0, +delay || 0), delay: Math.max(1, +delay || 0), repeat: repeat });
|
|
47
|
+
return id;
|
|
48
|
+
}
|
|
49
|
+
window.setTimeout = function (callback, delay) { return virtualTimer(callback, delay, Array.prototype.slice.call(arguments, 2), false); };
|
|
50
|
+
window.setInterval = function (callback, delay) { return virtualTimer(callback, delay, Array.prototype.slice.call(arguments, 2), true); };
|
|
51
|
+
window.clearTimeout = function (id) { if (timers.has(id)) timers.delete(id); else realClearTimeout(id); };
|
|
52
|
+
window.clearInterval = function (id) { if (timers.has(id)) timers.delete(id); else realClearInterval(id); };
|
|
53
|
+
function runTimers(until) {
|
|
54
|
+
for (;;) {
|
|
55
|
+
var due = null, dueId = 0;
|
|
56
|
+
timers.forEach(function (timer, id) { if (timer.at <= until && (!due || timer.at < due.at)) { due = timer; dueId = id; } });
|
|
57
|
+
if (!due) return;
|
|
58
|
+
now = due.at;
|
|
59
|
+
if (due.repeat) due.at += due.delay; else timers.delete(dueId);
|
|
60
|
+
try {
|
|
61
|
+
if (typeof due.callback === 'function') due.callback.apply(window, due.args);
|
|
62
|
+
} catch (error) { console.error(error); }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// requestAnimationFrame never runs on its own: the movie advances only when stepped.
|
|
67
|
+
var frameCallbacks = new Map(), nextFrameCallback = 1;
|
|
68
|
+
window.requestAnimationFrame = function (callback) { var id = nextFrameCallback++; frameCallbacks.set(id, callback); return id; };
|
|
69
|
+
window.cancelAnimationFrame = function (id) { frameCallbacks.delete(id); };
|
|
70
|
+
function runFrameCallbacks() {
|
|
71
|
+
var callbacks = Array.from(frameCallbacks.values());
|
|
72
|
+
frameCallbacks.clear();
|
|
73
|
+
callbacks.forEach(function (callback) { try { callback(now); } catch (error) { console.error(error); } });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Without an AudioContext, swooflib applies envelopes and transforms as element volume, which
|
|
77
|
+
// the segments record. Offline contexts stay available for decoding and the final mix.
|
|
78
|
+
try { delete window.AudioContext; delete window.webkitAudioContext; } catch (_) {}
|
|
79
|
+
window.AudioContext = undefined;
|
|
80
|
+
window.webkitAudioContext = undefined;
|
|
81
|
+
|
|
82
|
+
// --- Media elements ------------------------------------------------------------------
|
|
83
|
+
var media = window.HTMLMediaElement && HTMLMediaElement.prototype;
|
|
84
|
+
var native = {};
|
|
85
|
+
['currentTime', 'paused', 'ended', 'volume', 'duration'].forEach(function (name) {
|
|
86
|
+
native[name] = Object.getOwnPropertyDescriptor(media, name);
|
|
87
|
+
});
|
|
88
|
+
native.play = media.play;
|
|
89
|
+
native.pause = media.pause;
|
|
90
|
+
var states = new WeakMap();
|
|
91
|
+
var playing = new Set();
|
|
92
|
+
var segments = [];
|
|
93
|
+
var decoded = new Map(); // src → Promise<AudioBuffer | null>
|
|
94
|
+
var buffers = new Map(); // src → AudioBuffer
|
|
95
|
+
var decoder = null;
|
|
96
|
+
|
|
97
|
+
function decode(src) {
|
|
98
|
+
if (!src) return null;
|
|
99
|
+
if (!decoded.has(src)) {
|
|
100
|
+
decoder = decoder || new OfflineAudioContext(2, 1, 48000);
|
|
101
|
+
decoded.set(src, fetch(src).then(function (response) { return response.arrayBuffer(); })
|
|
102
|
+
.then(function (bytes) { return decoder.decodeAudioData(bytes); })
|
|
103
|
+
.then(function (buffer) { buffers.set(src, buffer); return buffer; })
|
|
104
|
+
.catch(function () { return null; }));
|
|
105
|
+
}
|
|
106
|
+
return decoded.get(src);
|
|
107
|
+
}
|
|
108
|
+
function state(element) {
|
|
109
|
+
var current = states.get(element);
|
|
110
|
+
if (!current) {
|
|
111
|
+
current = { playing: false, offset: 0, startedAt: 0, ended: false, segment: null };
|
|
112
|
+
try { current.offset = native.currentTime.get.call(element) || 0; } catch (_) {}
|
|
113
|
+
states.set(element, current);
|
|
114
|
+
}
|
|
115
|
+
return current;
|
|
116
|
+
}
|
|
117
|
+
function sourceOf(element) { return element.currentSrc || element.src || ''; }
|
|
118
|
+
function durationOf(element) {
|
|
119
|
+
var buffer = buffers.get(sourceOf(element));
|
|
120
|
+
if (buffer) return buffer.duration;
|
|
121
|
+
var value = native.duration.get.call(element);
|
|
122
|
+
return Number.isFinite(value) ? value : NaN;
|
|
123
|
+
}
|
|
124
|
+
function position(element, current) {
|
|
125
|
+
if (!current.playing) return current.offset;
|
|
126
|
+
var value = current.offset + (now - current.startedAt) / 1000;
|
|
127
|
+
var duration = durationOf(element);
|
|
128
|
+
if (element.loop && duration > 0 && value >= duration) value %= duration;
|
|
129
|
+
return value;
|
|
130
|
+
}
|
|
131
|
+
function openSegment(element, current) {
|
|
132
|
+
current.segment = { src: sourceOf(element), start: now / 1000, offset: current.offset, end: null,
|
|
133
|
+
volume: native.volume.get.call(element), loop: !!element.loop, muted: !!element.muted };
|
|
134
|
+
segments.push(current.segment);
|
|
135
|
+
}
|
|
136
|
+
function closeSegment(current) {
|
|
137
|
+
if (current.segment) current.segment.end = now / 1000;
|
|
138
|
+
current.segment = null;
|
|
139
|
+
}
|
|
140
|
+
function stopVirtual(element, current) {
|
|
141
|
+
current.offset = position(element, current);
|
|
142
|
+
closeSegment(current);
|
|
143
|
+
current.playing = false;
|
|
144
|
+
playing.delete(element);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
media.play = function () {
|
|
148
|
+
if (!recording) return native.play.call(this);
|
|
149
|
+
var current = state(this);
|
|
150
|
+
if (!current.playing) {
|
|
151
|
+
if (current.ended) { current.offset = 0; current.ended = false; }
|
|
152
|
+
current.playing = true;
|
|
153
|
+
current.startedAt = now;
|
|
154
|
+
openSegment(this, current);
|
|
155
|
+
playing.add(this);
|
|
156
|
+
decode(sourceOf(this));
|
|
157
|
+
var element = this;
|
|
158
|
+
Promise.resolve().then(function () { element.dispatchEvent(new DomEvent('play')); element.dispatchEvent(new DomEvent('playing')); });
|
|
159
|
+
}
|
|
160
|
+
return Promise.resolve();
|
|
161
|
+
};
|
|
162
|
+
media.pause = function () {
|
|
163
|
+
if (!recording) return native.pause.call(this);
|
|
164
|
+
var current = state(this);
|
|
165
|
+
if (current.playing) {
|
|
166
|
+
stopVirtual(this, current);
|
|
167
|
+
var element = this;
|
|
168
|
+
Promise.resolve().then(function () { element.dispatchEvent(new DomEvent('pause')); });
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
Object.defineProperty(media, 'currentTime', {
|
|
172
|
+
configurable: true,
|
|
173
|
+
get: function () { return recording ? position(this, state(this)) : native.currentTime.get.call(this); },
|
|
174
|
+
set: function (value) {
|
|
175
|
+
if (!recording) { native.currentTime.set.call(this, value); return; }
|
|
176
|
+
var current = state(this);
|
|
177
|
+
var playingNow = current.playing;
|
|
178
|
+
if (playingNow) closeSegment(current);
|
|
179
|
+
current.offset = Math.max(0, +value || 0);
|
|
180
|
+
current.startedAt = now;
|
|
181
|
+
current.ended = false;
|
|
182
|
+
if (playingNow) openSegment(this, current);
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
Object.defineProperty(media, 'paused', { configurable: true, get: function () { return recording ? !state(this).playing : native.paused.get.call(this); } });
|
|
186
|
+
Object.defineProperty(media, 'ended', { configurable: true, get: function () { return recording ? state(this).ended : native.ended.get.call(this); } });
|
|
187
|
+
Object.defineProperty(media, 'duration', { configurable: true, get: function () { return recording ? durationOf(this) : native.duration.get.call(this); } });
|
|
188
|
+
Object.defineProperty(media, 'volume', {
|
|
189
|
+
configurable: true,
|
|
190
|
+
get: function () { return native.volume.get.call(this); },
|
|
191
|
+
set: function (value) {
|
|
192
|
+
var before = native.volume.get.call(this);
|
|
193
|
+
native.volume.set.call(this, value);
|
|
194
|
+
if (!recording || before === native.volume.get.call(this)) return;
|
|
195
|
+
var current = state(this);
|
|
196
|
+
if (!current.playing) return;
|
|
197
|
+
current.offset = position(this, current);
|
|
198
|
+
current.startedAt = now;
|
|
199
|
+
closeSegment(current);
|
|
200
|
+
openSegment(this, current);
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// Advance playing elements to `now`: timeupdate every frame, ended at the end of the media.
|
|
205
|
+
function advanceMedia() {
|
|
206
|
+
Array.from(playing).forEach(function (element) {
|
|
207
|
+
var current = state(element);
|
|
208
|
+
var duration = durationOf(element);
|
|
209
|
+
if (!element.loop && duration > 0 && current.offset + (now - current.startedAt) / 1000 >= duration) {
|
|
210
|
+
var at = current.startedAt + (duration - current.offset) * 1000;
|
|
211
|
+
var stepNow = now;
|
|
212
|
+
now = Math.max(current.startedAt, at);
|
|
213
|
+
stopVirtual(element, current);
|
|
214
|
+
current.offset = duration;
|
|
215
|
+
current.ended = true;
|
|
216
|
+
now = stepNow;
|
|
217
|
+
element.dispatchEvent(new DomEvent('timeupdate'));
|
|
218
|
+
element.dispatchEvent(new DomEvent('ended'));
|
|
219
|
+
} else {
|
|
220
|
+
element.dispatchEvent(new DomEvent('timeupdate'));
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// --- Recording protocol ------------------------------------------------------------------
|
|
226
|
+
var fps = 24, frameMs = 1000 / 24, steps = 0, probe = null;
|
|
227
|
+
var origin = 0; // Virtual time (s) of the first video frame.
|
|
228
|
+
function stageCanvas() { return document.getElementById('stage'); }
|
|
229
|
+
function pictureKey(canvas) {
|
|
230
|
+
probe = probe || document.createElement('canvas');
|
|
231
|
+
probe.width = 32; probe.height = 18;
|
|
232
|
+
var ctx = probe.getContext('2d', { willReadFrequently: true });
|
|
233
|
+
ctx.clearRect(0, 0, 32, 18);
|
|
234
|
+
ctx.drawImage(canvas, 0, 0, 32, 18);
|
|
235
|
+
var data = ctx.getImageData(0, 0, 32, 18).data, hash = 0;
|
|
236
|
+
for (var i = 0; i < data.length; i++) hash = (hash * 31 + data[i]) | 0;
|
|
237
|
+
return hash;
|
|
238
|
+
}
|
|
239
|
+
function timeline() { return window.__swoof && window.__swoof.timeline; }
|
|
240
|
+
|
|
241
|
+
async function step() {
|
|
242
|
+
// Sounds being decoded hold the clock, so their length is known when they end.
|
|
243
|
+
await Promise.all(Array.from(playing).map(function (element) { return decode(sourceOf(element)); }));
|
|
244
|
+
if (steps === 0) {
|
|
245
|
+
// The first video frame is the movie as it opens: the player's first frame callback only
|
|
246
|
+
// records the time. Half a frame of slack then keeps exactly one movie tick per video frame.
|
|
247
|
+
runFrameCallbacks();
|
|
248
|
+
// Movie ticks happen half a frame after their video time (the slack below).
|
|
249
|
+
origin = (now + frameMs * 0.5) / 1000;
|
|
250
|
+
now += frameMs * 0.5;
|
|
251
|
+
steps++;
|
|
252
|
+
var first = stageCanvas(), opening = timeline();
|
|
253
|
+
return {
|
|
254
|
+
bitmap: await createImageBitmap(first),
|
|
255
|
+
state: { playing: !!(opening && opening.playing), frame: opening ? opening.frame : 0, frameCount: opening ? opening.frameCount : 0, sounds: playing.size, picture: pictureKey(first) },
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
now += frameMs;
|
|
259
|
+
var target = now;
|
|
260
|
+
runTimers(target);
|
|
261
|
+
now = target;
|
|
262
|
+
advanceMedia();
|
|
263
|
+
runFrameCallbacks();
|
|
264
|
+
steps++;
|
|
265
|
+
var canvas = stageCanvas();
|
|
266
|
+
var t = timeline();
|
|
267
|
+
var bitmap = await createImageBitmap(canvas);
|
|
268
|
+
return {
|
|
269
|
+
bitmap: bitmap,
|
|
270
|
+
state: { playing: !!(t && t.playing), frame: t ? t.frame : 0, frameCount: t ? t.frameCount : 0, sounds: playing.size, picture: pictureKey(canvas) },
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
async function mix(seconds) {
|
|
275
|
+
var rate = 48000;
|
|
276
|
+
var length = Math.max(1, Math.ceil(seconds * rate));
|
|
277
|
+
// Segment times are virtual page time; the video starts at `origin`.
|
|
278
|
+
var timed = segments.map(function (segment) {
|
|
279
|
+
var start = segment.start - origin, end = (segment.end == null ? origin + seconds : segment.end) - origin;
|
|
280
|
+
// A sound started before the first frame plays from where it would be at frame one.
|
|
281
|
+
var offset = segment.offset + Math.max(0, -start);
|
|
282
|
+
return Object.assign({}, segment, { start: Math.max(0, start), end: Math.min(seconds, end), offset: offset });
|
|
283
|
+
});
|
|
284
|
+
var used = timed.filter(function (segment) { return !segment.muted && segment.volume > 0 && segment.end > segment.start && segment.start < seconds; });
|
|
285
|
+
if (!used.length) return null;
|
|
286
|
+
await Promise.all(used.map(function (segment) { return decode(segment.src); }));
|
|
287
|
+
var context = new OfflineAudioContext(2, length, rate);
|
|
288
|
+
used.forEach(function (segment) {
|
|
289
|
+
var buffer = buffers.get(segment.src);
|
|
290
|
+
if (!buffer) return;
|
|
291
|
+
var source = context.createBufferSource();
|
|
292
|
+
source.buffer = buffer;
|
|
293
|
+
source.loop = segment.loop;
|
|
294
|
+
var gain = context.createGain();
|
|
295
|
+
gain.gain.value = segment.volume;
|
|
296
|
+
source.connect(gain).connect(context.destination);
|
|
297
|
+
source.start(segment.start, Math.min(segment.offset, buffer.duration));
|
|
298
|
+
source.stop(Math.min(seconds, segment.end));
|
|
299
|
+
});
|
|
300
|
+
var rendered = await context.startRendering();
|
|
301
|
+
return [rendered.getChannelData(0), rendered.getChannelData(1)];
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
async function ready() {
|
|
305
|
+
// The page, its scripts and fonts are loaded and the player is built.
|
|
306
|
+
while (document.readyState !== 'complete' || !timeline() || !stageCanvas()) await new Promise(function (resolve) { realSetTimeout(resolve, 50); });
|
|
307
|
+
if (document.fonts && document.fonts.ready) await document.fonts.ready;
|
|
308
|
+
await new Promise(function (resolve) { realSetTimeout(resolve, 300); });
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
window.addEventListener('message', async function (event) {
|
|
312
|
+
if (event.source !== window.parent || !event.data || typeof event.data.swoofRecord !== 'string') return;
|
|
313
|
+
var reply = function (message, transfer) { window.parent.postMessage(message, '*', transfer || []); };
|
|
314
|
+
try {
|
|
315
|
+
var command = event.data.swoofRecord;
|
|
316
|
+
if (command === 'start') {
|
|
317
|
+
fps = event.data.fps;
|
|
318
|
+
frameMs = 1000 / fps;
|
|
319
|
+
await ready();
|
|
320
|
+
now = realNow();
|
|
321
|
+
recording = true;
|
|
322
|
+
var t = timeline();
|
|
323
|
+
reply({ swoofRecorder: 'ready', width: stageCanvas().width, height: stageCanvas().height, frameCount: t ? t.frameCount : 0 });
|
|
324
|
+
} else if (command === 'step') {
|
|
325
|
+
var result = await step();
|
|
326
|
+
reply({ swoofRecorder: 'frame', bitmap: result.bitmap, state: result.state }, [result.bitmap]);
|
|
327
|
+
} else if (command === 'finish') {
|
|
328
|
+
var channels = event.data.sound ? await mix(event.data.seconds) : null;
|
|
329
|
+
reply({ swoofRecorder: 'audio', channels: channels, sampleRate: 48000 }, channels ? channels.map(function (data) { return data.buffer; }) : []);
|
|
330
|
+
}
|
|
331
|
+
} catch (error) {
|
|
332
|
+
reply({ swoofRecorder: 'error', message: String(error && error.message || error) });
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
})();
|