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,129 @@
|
|
|
1
|
+
import { applyEasing } from './model.js';
|
|
2
|
+
import { readInteger } from './numeric-fields.js';
|
|
3
|
+
|
|
4
|
+
export function readTransition(raw) {
|
|
5
|
+
if (raw === undefined) return;
|
|
6
|
+
if (!raw || !['crossfade', 'wipe'].includes(raw.type)) throw new Error('Choose a supported scene transition');
|
|
7
|
+
const durationFrames = readInteger(raw.durationFrames, 'Transition duration', 1, 600);
|
|
8
|
+
if (!['linear', 'easeIn', 'easeOut', 'easeInOut'].includes(raw.easing)) throw new Error('Choose a supported transition easing');
|
|
9
|
+
return { type: raw.type, durationFrames, easing: raw.easing };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function transitionProgress(transition, elapsedMs, fps) {
|
|
13
|
+
const frame = Math.floor(Math.max(0, elapsedMs) * fps / 1000);
|
|
14
|
+
return applyEasing(transition.easing, Math.min(1, frame / transition.durationFrames));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// A preview can interleave native fields with canvas strips. Capture all of them
|
|
18
|
+
// before navigating so the outgoing image includes the user's current field values.
|
|
19
|
+
function captureStage(canvas, surface) {
|
|
20
|
+
const frame = document.createElement('div');
|
|
21
|
+
frame.className = 'scene-transition-frame';
|
|
22
|
+
frame.style.width = canvas.width + 'px';
|
|
23
|
+
frame.style.height = canvas.height + 'px';
|
|
24
|
+
const base = document.createElement('canvas');
|
|
25
|
+
base.width = canvas.width;
|
|
26
|
+
base.height = canvas.height;
|
|
27
|
+
base.getContext('2d').drawImage(canvas, 0, 0);
|
|
28
|
+
const copy = surface.cloneNode(true);
|
|
29
|
+
copy.removeAttribute('id');
|
|
30
|
+
copy.style.transform = 'none';
|
|
31
|
+
const strips = [...surface.querySelectorAll('canvas')];
|
|
32
|
+
[...copy.querySelectorAll('canvas')].forEach((strip, index) => strip.getContext('2d').drawImage(strips[index], 0, 0));
|
|
33
|
+
const fields = [...surface.querySelectorAll('textarea,input')];
|
|
34
|
+
[...copy.querySelectorAll('textarea,input')].forEach((field, i) => {
|
|
35
|
+
field.removeAttribute('data-element-id');
|
|
36
|
+
field.value = fields[i].value;
|
|
37
|
+
});
|
|
38
|
+
// The incoming scene creates clip paths with the same IDs as the live surface.
|
|
39
|
+
for (const clip of copy.querySelectorAll('[id]')) clip.id = 'outgoing-' + clip.id;
|
|
40
|
+
for (const node of copy.querySelectorAll('[clip-path]')) {
|
|
41
|
+
node.setAttribute('clip-path', node.getAttribute('clip-path').replace('#studio-input-clip-', '#outgoing-studio-input-clip-'));
|
|
42
|
+
}
|
|
43
|
+
for (const field of copy.querySelectorAll('.preview-text-field')) {
|
|
44
|
+
if (field.style.clipPath) field.style.clipPath = field.style.clipPath.replace('#studio-input-clip-', '#outgoing-studio-input-clip-');
|
|
45
|
+
}
|
|
46
|
+
frame.append(base, copy);
|
|
47
|
+
return frame;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function createSceneTransition(canvas, surface, onFinish) {
|
|
51
|
+
const mat = canvas.parentElement;
|
|
52
|
+
let overlay;
|
|
53
|
+
let request;
|
|
54
|
+
let resize;
|
|
55
|
+
let restoreFocus;
|
|
56
|
+
function cancel() {
|
|
57
|
+
if (!overlay) return;
|
|
58
|
+
cancelAnimationFrame(request);
|
|
59
|
+
resize.disconnect();
|
|
60
|
+
overlay.remove();
|
|
61
|
+
overlay = null;
|
|
62
|
+
mat.inert = false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function begin(settings, fps) {
|
|
66
|
+
cancel();
|
|
67
|
+
const frame = captureStage(canvas, surface);
|
|
68
|
+
overlay = document.createElement('div');
|
|
69
|
+
overlay.className = 'scene-transition';
|
|
70
|
+
overlay.setAttribute('aria-hidden', 'true');
|
|
71
|
+
overlay.append(frame);
|
|
72
|
+
restoreFocus = mat.contains(document.activeElement);
|
|
73
|
+
mat.inert = true;
|
|
74
|
+
mat.append(overlay);
|
|
75
|
+
const fit = () => {
|
|
76
|
+
frame.style.transform = `scale(${mat.clientWidth / frame.offsetWidth}, ${mat.clientHeight / frame.offsetHeight})`;
|
|
77
|
+
};
|
|
78
|
+
fit();
|
|
79
|
+
resize = new ResizeObserver(fit);
|
|
80
|
+
resize.observe(mat);
|
|
81
|
+
let start;
|
|
82
|
+
function tick(now) {
|
|
83
|
+
start ??= now;
|
|
84
|
+
const progress = transitionProgress(settings, now - start, fps);
|
|
85
|
+
if (progress === 1) {
|
|
86
|
+
cancel();
|
|
87
|
+
if (restoreFocus && document.activeElement === document.body) canvas.focus({ preventScroll: true });
|
|
88
|
+
onFinish();
|
|
89
|
+
} else {
|
|
90
|
+
if (settings.type === 'crossfade') overlay.style.opacity = String(1 - progress);
|
|
91
|
+
else overlay.style.clipPath = `inset(0 0 0 ${progress * 100}%)`;
|
|
92
|
+
request = requestAnimationFrame(tick);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
request = requestAnimationFrame(tick);
|
|
96
|
+
}
|
|
97
|
+
return { begin, cancel, get active() { return Boolean(overlay); } };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function createTransitionInspector({ current, locked, commit, report }) {
|
|
101
|
+
const group = document.querySelector('#scene-transition-fields');
|
|
102
|
+
const type = group.querySelector('#scene-transition-type');
|
|
103
|
+
const timing = group.querySelector('.field-row');
|
|
104
|
+
const duration = group.querySelector('#scene-transition-duration');
|
|
105
|
+
const easing = group.querySelector('#scene-transition-easing');
|
|
106
|
+
function render() {
|
|
107
|
+
const scene = current();
|
|
108
|
+
group.hidden = !scene;
|
|
109
|
+
if (!scene) return;
|
|
110
|
+
type.value = scene.transition?.type ?? '';
|
|
111
|
+
duration.value = scene.transition?.durationFrames ?? 12;
|
|
112
|
+
easing.value = scene.transition?.easing ?? 'linear';
|
|
113
|
+
timing.hidden = !scene.transition;
|
|
114
|
+
for (const field of [type, duration, easing]) field.disabled = locked();
|
|
115
|
+
}
|
|
116
|
+
group.addEventListener('change', () => {
|
|
117
|
+
const scene = current();
|
|
118
|
+
if (!scene || locked()) return;
|
|
119
|
+
try {
|
|
120
|
+
if (type.value) scene.transition = readTransition({ type: type.value, durationFrames: duration.valueAsNumber, easing: easing.value });
|
|
121
|
+
else delete scene.transition;
|
|
122
|
+
commit();
|
|
123
|
+
} catch (error) {
|
|
124
|
+
render();
|
|
125
|
+
report(error.message, true);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return { render };
|
|
129
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// The script editor (studiospec/actionscript.md §4): every script is shown as ActionScript. An
|
|
2
|
+
// imported script is decompiled by the server; one whose bytecode has no ActionScript form is
|
|
3
|
+
// shown read-only as its JavaScript translation. Code is checked while it is typed, and a script
|
|
4
|
+
// with errors can still be kept: Preview and export then stop and name it.
|
|
5
|
+
|
|
6
|
+
import { scriptUseCount } from './scripts.js';
|
|
7
|
+
|
|
8
|
+
/** Edit one attachment. Imported bytecode stays intact until the author changes the code.
|
|
9
|
+
* A shared script becomes a private copy for the attachment being edited.
|
|
10
|
+
*/
|
|
11
|
+
export async function editAttachedScript({ project, editScript, makeId }, drafts, id, name) {
|
|
12
|
+
const existing = drafts.get(id) ?? project.scripts?.find(item => item.id === id);
|
|
13
|
+
const base = existing ?? { name, language: 'actionscript', code: '', swfVersion: defaultScriptVersion(project) };
|
|
14
|
+
const uses = existing && !drafts.has(id) ? scriptUseCount(project, id) : 0;
|
|
15
|
+
const title = `${base.name ?? id} · ActionScript${uses > 1 ? ` (used in ${uses} places; changes apply here only)` : ''}`;
|
|
16
|
+
const result = await editScript(base, title);
|
|
17
|
+
if (!result) return null;
|
|
18
|
+
const nextId = existing && uses <= 1 ? id : makeId('script');
|
|
19
|
+
drafts.set(nextId, { id: nextId, ...(base.name && { name: base.name }), language: 'actionscript',
|
|
20
|
+
swfVersion: base.swfVersion, code: result.code });
|
|
21
|
+
return nextId;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Publish only edits still used by this dialog when the author saves. */
|
|
25
|
+
export function applyScriptDrafts(project, drafts, used) {
|
|
26
|
+
const pending = new Map([...drafts].filter(([id]) => used.has(id)));
|
|
27
|
+
if (!pending.size) return;
|
|
28
|
+
const scripts = (project.scripts ?? []).map(script => {
|
|
29
|
+
const replacement = pending.get(script.id);
|
|
30
|
+
pending.delete(script.id);
|
|
31
|
+
return replacement ?? script;
|
|
32
|
+
});
|
|
33
|
+
project.scripts = [...scripts, ...pending.values()];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The SWF version for a new script: that of the project's other scripts, or 8. */
|
|
37
|
+
export function defaultScriptVersion(project) {
|
|
38
|
+
const versions = (project.scripts ?? []).map(script => script.swfVersion);
|
|
39
|
+
return versions.length ? Math.max(...versions) : 8;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function postJson(url, body) {
|
|
43
|
+
const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
|
|
44
|
+
const answer = await response.json().catch(() => ({}));
|
|
45
|
+
if (!response.ok) throw new Error(answer.error?.message ?? `The server answered ${response.status}`);
|
|
46
|
+
return answer;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** ActionScript for a script: its code, or its decompiled bytecode (`{ code: null, reason }` when there is none). */
|
|
50
|
+
export async function scriptText(script) {
|
|
51
|
+
if (script.language === 'actionscript') return { code: script.code };
|
|
52
|
+
if (script.linkedPrefix) return { code: null, reason: 'the original action spans two SWF records' };
|
|
53
|
+
return postJson('/api/script/decompile', { bytecode: script.bytecode, swfVersion: script.swfVersion });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function createScriptEditor({ project }) {
|
|
57
|
+
const dialog = document.querySelector('#script-editor');
|
|
58
|
+
const form = dialog.querySelector('form');
|
|
59
|
+
const code = dialog.querySelector('#script-code');
|
|
60
|
+
const note = dialog.querySelector('#script-editor-note');
|
|
61
|
+
const check = dialog.querySelector('#script-check');
|
|
62
|
+
const done = dialog.querySelector('#script-done');
|
|
63
|
+
const sourceFile = dialog.querySelector('#script-source-file');
|
|
64
|
+
const openSource = dialog.querySelector('#script-open-source');
|
|
65
|
+
let resolve = null, script = null, shown = '', checkTimer = 0, checkRequest = 0;
|
|
66
|
+
|
|
67
|
+
function showCheck(error) {
|
|
68
|
+
check.classList.toggle('has-error', !!error);
|
|
69
|
+
code.setAttribute('aria-invalid', error ? 'true' : 'false');
|
|
70
|
+
check.textContent = error
|
|
71
|
+
? `${error.line ? `Line ${error.line}, column ${error.column}: ` : ''}${error.message}`
|
|
72
|
+
: 'No errors.';
|
|
73
|
+
}
|
|
74
|
+
async function runCheck() {
|
|
75
|
+
const request = ++checkRequest;
|
|
76
|
+
try {
|
|
77
|
+
const { error } = await postJson('/api/script/check', {
|
|
78
|
+
code: code.value, swfVersion: script.swfVersion, scenes: project.scenes.map(scene => scene.name),
|
|
79
|
+
});
|
|
80
|
+
if (request === checkRequest) showCheck(error);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
if (request === checkRequest) check.textContent = `Could not check the script: ${error.message}`;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
code.addEventListener('input', () => {
|
|
86
|
+
clearTimeout(checkTimer);
|
|
87
|
+
checkTimer = setTimeout(runCheck, 300);
|
|
88
|
+
});
|
|
89
|
+
openSource.onclick = () => sourceFile.click();
|
|
90
|
+
sourceFile.onchange = async () => {
|
|
91
|
+
const file = sourceFile.files[0], current = script;
|
|
92
|
+
if (!file) return;
|
|
93
|
+
sourceFile.value = '';
|
|
94
|
+
try {
|
|
95
|
+
const text = await file.text();
|
|
96
|
+
if (!dialog.open || current !== script || code.readOnly) return;
|
|
97
|
+
code.value = text;
|
|
98
|
+
code.focus();
|
|
99
|
+
code.setSelectionRange(0, 0);
|
|
100
|
+
await runCheck();
|
|
101
|
+
} catch (error) { if (dialog.open && current === script) note.textContent = error.message; }
|
|
102
|
+
};
|
|
103
|
+
code.addEventListener('keydown', event => {
|
|
104
|
+
// Tab indents inside the editor; Escape still closes the dialog.
|
|
105
|
+
if (event.key !== 'Tab' || event.shiftKey || code.readOnly) return;
|
|
106
|
+
event.preventDefault();
|
|
107
|
+
code.setRangeText(' ', code.selectionStart, code.selectionEnd, 'end');
|
|
108
|
+
code.dispatchEvent(new Event('input'));
|
|
109
|
+
});
|
|
110
|
+
function finish(result) {
|
|
111
|
+
clearTimeout(checkTimer);
|
|
112
|
+
checkRequest++;
|
|
113
|
+
if (dialog.open) dialog.close();
|
|
114
|
+
const settle = resolve;
|
|
115
|
+
resolve = null;
|
|
116
|
+
settle?.(result);
|
|
117
|
+
}
|
|
118
|
+
dialog.querySelector('#script-cancel').onclick = () => finish(null);
|
|
119
|
+
dialog.addEventListener('cancel', () => finish(null));
|
|
120
|
+
form.onsubmit = event => {
|
|
121
|
+
event.preventDefault();
|
|
122
|
+
// Unchanged text keeps the script as it is (an imported script keeps its bytecode).
|
|
123
|
+
finish(code.readOnly || code.value === shown ? null : { code: code.value });
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Edit `current` (a script, or a pending `{ language: 'actionscript', code }` draft of it).
|
|
128
|
+
* Resolves to `{ code }` when the text changed, else null.
|
|
129
|
+
*/
|
|
130
|
+
return async function editScript(current, title, location) {
|
|
131
|
+
if (resolve) finish(null);
|
|
132
|
+
script = current;
|
|
133
|
+
dialog.querySelector('h2').textContent = title;
|
|
134
|
+
code.value = '';
|
|
135
|
+
code.readOnly = true;
|
|
136
|
+
note.textContent = 'Loading the script…';
|
|
137
|
+
check.textContent = '';
|
|
138
|
+
check.classList.remove('has-error');
|
|
139
|
+
done.disabled = true;
|
|
140
|
+
openSource.disabled = true;
|
|
141
|
+
const result = new Promise(next => { resolve = next; });
|
|
142
|
+
dialog.showModal();
|
|
143
|
+
let text;
|
|
144
|
+
try {
|
|
145
|
+
text = await scriptText(current);
|
|
146
|
+
} catch (error) {
|
|
147
|
+
text = { code: null, reason: error.message };
|
|
148
|
+
}
|
|
149
|
+
if (!dialog.open || script !== current) return result;
|
|
150
|
+
if (text.code === null) {
|
|
151
|
+
// No ActionScript form: show what runs, read-only.
|
|
152
|
+
code.value = current.source ?? '';
|
|
153
|
+
note.textContent = `This script can't be shown as ActionScript (${text.reason}). It keeps running as imported. Its JavaScript translation is shown below.`;
|
|
154
|
+
shown = code.value;
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
code.value = text.code;
|
|
158
|
+
shown = text.code;
|
|
159
|
+
code.readOnly = false;
|
|
160
|
+
done.disabled = false;
|
|
161
|
+
openSource.disabled = false;
|
|
162
|
+
note.textContent = current.language === 'avm1'
|
|
163
|
+
? `ActionScript ${current.swfVersion >= 6 ? '2' : '1'} for SWF ${current.swfVersion}. The imported bytecode is kept until you change the text.`
|
|
164
|
+
: `ActionScript for SWF ${current.swfVersion}. It is compiled when you preview or export.`;
|
|
165
|
+
code.focus();
|
|
166
|
+
const lines = code.value.split('\n');
|
|
167
|
+
const row = Math.min(lines.length - 1, Math.max(0, (location?.line ?? 1) - 1));
|
|
168
|
+
const column = Math.min(lines[row].length, Math.max(0, (location?.column ?? 1) - 1));
|
|
169
|
+
const offset = lines.slice(0, row).reduce((sum, line) => sum + line.length + 1, column);
|
|
170
|
+
code.setSelectionRange(offset, offset);
|
|
171
|
+
code.scrollTop = Math.max(0, row - 2) * (parseFloat(getComputedStyle(code).lineHeight) || 18);
|
|
172
|
+
runCheck();
|
|
173
|
+
return result;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { tokenize } from '../../swf2js/compiler/as2-parser.js';
|
|
2
|
+
import { referencedScripts } from './scripts.js';
|
|
3
|
+
|
|
4
|
+
const cache = new WeakMap();
|
|
5
|
+
|
|
6
|
+
function scriptNames(script) {
|
|
7
|
+
const contents = script.code ?? script.bytecode;
|
|
8
|
+
const previous = cache.get(script);
|
|
9
|
+
if (previous?.contents === contents) return previous.names;
|
|
10
|
+
const names = new Set();
|
|
11
|
+
function record(text) {
|
|
12
|
+
if (script.swfVersion <= 6) text = text.toLowerCase();
|
|
13
|
+
names.add(text);
|
|
14
|
+
for (const part of text.split(/[./:]/)) if (part) names.add(part);
|
|
15
|
+
}
|
|
16
|
+
if (script.language === 'actionscript') {
|
|
17
|
+
try {
|
|
18
|
+
for (const token of tokenize(contents)) if (token.type === 'name' || token.type === 'string') record(token.value);
|
|
19
|
+
} catch {
|
|
20
|
+
// An incomplete edit can still contain valid references before the syntax error.
|
|
21
|
+
for (const word of contents.match(/[\p{L}\p{N}_$]+/gu) ?? []) record(word);
|
|
22
|
+
}
|
|
23
|
+
} else if (script.language === 'avm1') {
|
|
24
|
+
const decoder = new TextDecoder(script.swfVersion >= 6 ? 'utf-8' : 'windows-1252');
|
|
25
|
+
const scan = encoded => {
|
|
26
|
+
const bytes = Uint8Array.from(atob(encoded), ch => ch.charCodeAt(0));
|
|
27
|
+
let i = 0;
|
|
28
|
+
while (i < bytes.length) {
|
|
29
|
+
const op = bytes[i++];
|
|
30
|
+
if (op < 0x80) continue;
|
|
31
|
+
const length = bytes[i] | bytes[i + 1] << 8;
|
|
32
|
+
i += 2;
|
|
33
|
+
const end = Math.min(i + length, bytes.length);
|
|
34
|
+
const string = () => {
|
|
35
|
+
const start = i;
|
|
36
|
+
while (i < end && bytes[i] !== 0) i++;
|
|
37
|
+
record(decoder.decode(bytes.subarray(start, i)));
|
|
38
|
+
i++;
|
|
39
|
+
};
|
|
40
|
+
if (op === 0x88) {
|
|
41
|
+
const count = bytes[i] | bytes[i + 1] << 8;
|
|
42
|
+
i += 2;
|
|
43
|
+
for (let n = 0; n < count && i < end; n++) string();
|
|
44
|
+
} else if (op === 0x96) {
|
|
45
|
+
while (i < end) {
|
|
46
|
+
const kind = bytes[i++];
|
|
47
|
+
if (kind === 0) string();
|
|
48
|
+
else i += [0, 4, 0, 0, 1, 1, 8, 4, 1, 2][kind] ?? end - i;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// DefineFunction, With, and Try bodies follow their headers as action lists.
|
|
52
|
+
i = end;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
if (script.linkedPrefix) scan(script.linkedPrefix);
|
|
56
|
+
scan(script.bytecode);
|
|
57
|
+
}
|
|
58
|
+
cache.set(script, { contents, names });
|
|
59
|
+
return names;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Match authored identifiers and literal Flash target paths against remaining script attachments. */
|
|
63
|
+
export function scriptReferenceWarnings(project, elements) {
|
|
64
|
+
const names = [...new Set(elements.map(element => element.name).filter(Boolean))];
|
|
65
|
+
const used = referencedScripts(project);
|
|
66
|
+
const warnings = [];
|
|
67
|
+
for (const script of project.scripts ?? []) {
|
|
68
|
+
if (!used.has(script.id) || !['actionscript', 'avm1'].includes(script.language)) continue;
|
|
69
|
+
const references = scriptNames(script);
|
|
70
|
+
const matches = names.filter(name => references.has(script.swfVersion <= 6 ? name.toLowerCase() : name));
|
|
71
|
+
if (matches.length) warnings.push(`${script.name || script.id} refers to ${matches.join(', ')}`);
|
|
72
|
+
}
|
|
73
|
+
return warnings;
|
|
74
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// Loaded before a scripted Preview starts, only when the movie contains Studio controls.
|
|
2
|
+
// The native widget owns input and focus. ActionScript sees the placed MovieClip as the
|
|
3
|
+
// component and can read/write its parameters before its first frame is painted.
|
|
4
|
+
import { createControlWidget } from '../../swooflib/control-widget.js';
|
|
5
|
+
|
|
6
|
+
const instances = new WeakMap();
|
|
7
|
+
const groups = new WeakMap();
|
|
8
|
+
let groupId = 0;
|
|
9
|
+
|
|
10
|
+
function ownerScope(owner) {
|
|
11
|
+
if (!groups.has(owner)) groups.set(owner, { id: `control-group-${++groupId}`, radios: new Set() });
|
|
12
|
+
return groups.get(owner);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function* liveRadios(scope) {
|
|
16
|
+
for (const ref of scope.radios) {
|
|
17
|
+
const member = ref.deref();
|
|
18
|
+
if (member && !member._swoofDetached) yield member;
|
|
19
|
+
else scope.radios.delete(ref);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function install(clip, definition, name, owner, runActions, resolveVariable, resolveContent) {
|
|
24
|
+
if (instances.has(clip)) return;
|
|
25
|
+
const scope = ownerScope(owner);
|
|
26
|
+
const parameters = structuredClone(definition.parameters);
|
|
27
|
+
const radio = definition.kind === 'RadioButton';
|
|
28
|
+
const listeners = new Map();
|
|
29
|
+
let boundValue;
|
|
30
|
+
let widget;
|
|
31
|
+
let syncing = false;
|
|
32
|
+
const writeVariable = () => {
|
|
33
|
+
const binding = definition.variable && resolveVariable();
|
|
34
|
+
if (binding && widget && !syncing && !clip._swoofDetached && binding.object !== clip)
|
|
35
|
+
binding.object[binding.key] = boundValue = widget.getValue();
|
|
36
|
+
};
|
|
37
|
+
function selectRadio() {
|
|
38
|
+
if (!radio || !widget.getProperties().selected) return;
|
|
39
|
+
for (const other of liveRadios(scope)) {
|
|
40
|
+
if (other !== clip && other.groupName === clip.groupName && other.selected) other.selected = false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function radioGroup(groupName) {
|
|
44
|
+
if (!groupName || groupName in owner) return;
|
|
45
|
+
const members = () => [...liveRadios(scope)].filter(member => member.groupName === groupName);
|
|
46
|
+
const group = {};
|
|
47
|
+
Object.defineProperty(group, 'selectedData', {
|
|
48
|
+
get() { return members().find(member => member.selected)?.data; },
|
|
49
|
+
set(data) { for (const member of members()) member.selected = member.data === data; },
|
|
50
|
+
});
|
|
51
|
+
owner[groupName] = group;
|
|
52
|
+
}
|
|
53
|
+
function onEvent(type, properties) {
|
|
54
|
+
if (clip._swoofDetached) return;
|
|
55
|
+
Object.assign(parameters, properties);
|
|
56
|
+
selectRadio();
|
|
57
|
+
writeVariable();
|
|
58
|
+
if (definition.kind === 'ScrollBar' && type === 'scroll') {
|
|
59
|
+
const target = owner[properties.scrollTargetName];
|
|
60
|
+
const field = instances.get(target)?.widget.node.querySelector('textarea,[data-scroll-content]') ?? target?._swoofOverlayElement;
|
|
61
|
+
if (field) field[properties.horizontal ? 'scrollLeft' : 'scrollTop'] = properties.scrollPosition;
|
|
62
|
+
}
|
|
63
|
+
const event = { type, target: clip };
|
|
64
|
+
for (const listener of [...(listeners.get(type) ?? [])]) {
|
|
65
|
+
if (typeof listener === 'function') listener.call(clip, event);
|
|
66
|
+
else listener?.[type]?.call(listener, event);
|
|
67
|
+
}
|
|
68
|
+
runActions(type);
|
|
69
|
+
}
|
|
70
|
+
widget = createControlWidget(definition.kind, parameters, { name, groupScope: scope.id, onEvent, resolveContent });
|
|
71
|
+
if (radio) scope.radios.add(new WeakRef(clip));
|
|
72
|
+
const setValue = value => {
|
|
73
|
+
widget.setValue(value);
|
|
74
|
+
Object.assign(parameters, widget.getProperties());
|
|
75
|
+
selectRadio();
|
|
76
|
+
writeVariable();
|
|
77
|
+
};
|
|
78
|
+
function syncVariable() {
|
|
79
|
+
if (!definition.variable || syncing || clip._swoofDetached) return;
|
|
80
|
+
const binding = resolveVariable();
|
|
81
|
+
if (!binding || binding.object === clip) return;
|
|
82
|
+
syncing = true;
|
|
83
|
+
try {
|
|
84
|
+
const value = binding.object[binding.key];
|
|
85
|
+
if (value === undefined) binding.object[binding.key] = boundValue = widget.getValue();
|
|
86
|
+
else if (!Object.is(value, boundValue)) {
|
|
87
|
+
boundValue = value;
|
|
88
|
+
widget.setValue(value);
|
|
89
|
+
Object.assign(parameters, widget.getProperties());
|
|
90
|
+
selectRadio();
|
|
91
|
+
}
|
|
92
|
+
} finally { syncing = false; }
|
|
93
|
+
}
|
|
94
|
+
// Reading through the widget exposes normalized selection/value to scripts immediately.
|
|
95
|
+
const keys = new Set([...Object.keys(parameters), ...Object.keys(widget.getProperties())]);
|
|
96
|
+
for (const key of keys) {
|
|
97
|
+
Object.defineProperty(clip, key, { enumerable: true, configurable: true,
|
|
98
|
+
get() {
|
|
99
|
+
syncVariable();
|
|
100
|
+
if (radio && key === 'selectedData') return owner[parameters.groupName]?.selectedData;
|
|
101
|
+
return widget.getProperties()[key];
|
|
102
|
+
},
|
|
103
|
+
set(value) {
|
|
104
|
+
if (radio && key === 'selectedData' && owner[parameters.groupName]) {
|
|
105
|
+
owner[parameters.groupName].selectedData = value;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
parameters[key] = value;
|
|
109
|
+
widget.setParameters(parameters);
|
|
110
|
+
Object.assign(parameters, widget.getProperties());
|
|
111
|
+
if (radio && key === 'groupName') radioGroup(value);
|
|
112
|
+
if (radio && (key === 'selected' || key === 'groupName')) selectRadio();
|
|
113
|
+
writeVariable();
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
clip.getValue = () => { syncVariable(); return widget.getValue(); };
|
|
118
|
+
clip.setValue = setValue;
|
|
119
|
+
clip.addEventListener = (type, listener) => {
|
|
120
|
+
if (!listeners.has(type)) listeners.set(type, new Set());
|
|
121
|
+
listeners.get(type).add(listener);
|
|
122
|
+
};
|
|
123
|
+
clip.removeEventListener = (type, listener) => listeners.get(type)?.delete(listener);
|
|
124
|
+
if (radio) {
|
|
125
|
+
radioGroup(parameters.groupName);
|
|
126
|
+
selectRadio();
|
|
127
|
+
}
|
|
128
|
+
function update() {
|
|
129
|
+
syncVariable();
|
|
130
|
+
if (definition.kind === 'ProgressBar' && parameters.source) {
|
|
131
|
+
const source = owner[parameters.source];
|
|
132
|
+
const total = source?.getBytesTotal?.();
|
|
133
|
+
const percent = source?.percentLoaded ?? (total > 0 ? 100 * source.getBytesLoaded() / total : undefined);
|
|
134
|
+
if (Number.isFinite(percent) && percent !== widget.getValue()) setValue(percent);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
instances.set(clip, { widget, update });
|
|
138
|
+
syncVariable();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function refresh(clip) {
|
|
142
|
+
const instance = instances.get(clip);
|
|
143
|
+
if (!instance) return null;
|
|
144
|
+
instance.update();
|
|
145
|
+
return instance.widget.node;
|
|
146
|
+
}
|