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,639 @@
|
|
|
1
|
+
// Write a movie in swf2js's display-list form (what the decoder and display-list builder
|
|
2
|
+
// produce, and what Studio's buildProjectMovie produces) as a SWF file.
|
|
3
|
+
//
|
|
4
|
+
// Input: the display list (`frames`, `characters`, `scenes`) plus the script tags that travel
|
|
5
|
+
// beside it (`DoAction`, `DoInitAction`, `ExportAssets`, sprites' tag lists and the
|
|
6
|
+
// `PlaceObject2 { clipActions }` entries that carry clip events), and bitmap data by character
|
|
7
|
+
// ID, and sound data by character ID (`DefineSound` fields, as the decoder reads them).
|
|
8
|
+
// Compression is injected (`zlib`), so this module has no Node dependencies.
|
|
9
|
+
import { BitWriter, parseColor } from './bit-writer.js';
|
|
10
|
+
import { encodeShape } from './shape-encoder.js';
|
|
11
|
+
import { concatBytes, encodeTag, writeSwf } from './swf-writer.js';
|
|
12
|
+
import { BUTTON_SOUND_TRANSITIONS, TAG } from '../decoder/tag-types.js';
|
|
13
|
+
|
|
14
|
+
const ALIGN = { left: 0, right: 1, center: 2, justify: 3 };
|
|
15
|
+
const IDENTITY_CXFORM = { rMult: 256, gMult: 256, bMult: 256, aMult: 256, rAdd: 0, gAdd: 0, bAdd: 0, aAdd: 0 };
|
|
16
|
+
|
|
17
|
+
/** True when an AVM1 action list ends with its ActionEndFlag (walking records, not bytes). */
|
|
18
|
+
function hasActionEnd(bytes) {
|
|
19
|
+
let at = 0;
|
|
20
|
+
while (at < bytes.length) {
|
|
21
|
+
const op = bytes[at];
|
|
22
|
+
if (op === 0) return at === bytes.length - 1;
|
|
23
|
+
at += op >= 0x80 ? 3 + (bytes[at + 1] | (bytes[at + 2] << 8)) : 1;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Action bytes ending with ActionEndFlag, as every action list in a SWF must. */
|
|
29
|
+
export function withActionEnd(bytes) {
|
|
30
|
+
const data = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes ?? []);
|
|
31
|
+
if (hasActionEnd(data)) return data;
|
|
32
|
+
const out = new Uint8Array(data.length + 1);
|
|
33
|
+
out.set(data);
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Split a tag list at ShowFrame (raw `{ code }` or typed `{ type }` tags) into per-frame lists. */
|
|
38
|
+
function splitFrames(tags) {
|
|
39
|
+
const frames = [[]];
|
|
40
|
+
for (const tag of tags ?? []) {
|
|
41
|
+
if (tag.code === TAG.ShowFrame || tag.type === 'ShowFrame') frames.push([]);
|
|
42
|
+
else frames.at(-1).push(tag);
|
|
43
|
+
}
|
|
44
|
+
return frames;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A raw or typed script tag as `{ kind: 'action', bytes }` or `{ kind: 'clip', place }`. */
|
|
48
|
+
function scriptTag(tag, previous) {
|
|
49
|
+
if (tag.type === 'DoABC') {
|
|
50
|
+
if (tag.legacy) return { kind: 'avm2', bytes: encodeTag(TAG.DoABCDefine, tag.abcData) };
|
|
51
|
+
const w = new BitWriter();
|
|
52
|
+
w.writeUI32(tag.flags);
|
|
53
|
+
w.writeString(tag.name);
|
|
54
|
+
w.writeBytes(tag.abcData);
|
|
55
|
+
return { kind: 'avm2', bytes: encodeTag(TAG.DoABC, w.toBytes()) };
|
|
56
|
+
}
|
|
57
|
+
if (tag.type === 'SymbolClass') {
|
|
58
|
+
if (tag.rawData) return { kind: 'avm2', bytes: encodeTag(TAG.SymbolClass, tag.rawData) };
|
|
59
|
+
const w = new BitWriter();
|
|
60
|
+
w.writeUI16(tag.classes.length);
|
|
61
|
+
for (const item of tag.classes) { w.writeUI16(item.id); w.writeString(item.name); }
|
|
62
|
+
return { kind: 'avm2', bytes: encodeTag(TAG.SymbolClass, w.toBytes()) };
|
|
63
|
+
}
|
|
64
|
+
if (tag.type === 'DoAction' || tag.code === TAG.DoAction) return { kind: 'action', bytes: tag.bytecode ?? tag.data,
|
|
65
|
+
prefix: previous?.code === 253 ? previous.data : null };
|
|
66
|
+
const place = tag.decoded ?? tag;
|
|
67
|
+
if ((place.type === 'PlaceObject2' || place.type === 'PlaceObject3') && place.clipActions?.length) return { kind: 'clip', place };
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Character IDs a character uses (definition order: these must come first). */
|
|
72
|
+
function dependencies(character) {
|
|
73
|
+
const ids = new Set();
|
|
74
|
+
if (character.type === 'shape') {
|
|
75
|
+
for (const id of character.nativeMorph?.dependencies ?? []) ids.add(id);
|
|
76
|
+
for (const draw of character.draws ?? []) {
|
|
77
|
+
for (const fill of [draw.fill, draw.stroke?.fill]) {
|
|
78
|
+
if (fill?.type === 'bitmap' && fill.bitmapId != null) ids.add(fill.bitmapId);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
} else if (character.type === 'sprite') {
|
|
82
|
+
for (const frame of character.frames ?? []) for (const place of frame.places ?? []) if (place.characterId != null) ids.add(place.characterId);
|
|
83
|
+
} else if (character.type === 'button') {
|
|
84
|
+
const states = character.buttonStates ?? {};
|
|
85
|
+
for (const record of [...(states.up ?? []), ...(states.over ?? []), ...(states.down ?? []), ...(character.buttonHitStates ?? [])]) ids.add(record.characterId);
|
|
86
|
+
}
|
|
87
|
+
return ids;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Inverse of the decoder's FILTERLIST, used by both PlaceObject3 and DefineButton2.
|
|
91
|
+
function writeFilters(w, filters) {
|
|
92
|
+
const types = ['dropShadow', 'blur', 'glow', 'bevel', 'gradientGlow', 'convolution', 'colorMatrix', 'gradientBevel'];
|
|
93
|
+
const buffer = new DataView(new ArrayBuffer(4));
|
|
94
|
+
const float = value => {
|
|
95
|
+
buffer.setFloat32(0, value);
|
|
96
|
+
w.writeUI32(buffer.getUint32(0));
|
|
97
|
+
};
|
|
98
|
+
const fixed = value => w.writeUI32(Math.round(value * 65536) >>> 0);
|
|
99
|
+
w.writeUI8(filters.length);
|
|
100
|
+
for (const f of filters) {
|
|
101
|
+
w.writeUI8(types.indexOf(f.type));
|
|
102
|
+
if (f.type === 'colorMatrix') {
|
|
103
|
+
f.matrix.forEach(float);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (f.type === 'convolution') {
|
|
107
|
+
w.writeUI8(f.matrixX);
|
|
108
|
+
w.writeUI8(f.matrixY);
|
|
109
|
+
float(f.divisor);
|
|
110
|
+
float(f.bias);
|
|
111
|
+
f.matrix.forEach(float);
|
|
112
|
+
w.writeRGBA(f.defaultColor);
|
|
113
|
+
w.writeUI8((f.clamp ? 2 : 0) | (f.preserveAlpha ? 1 : 0));
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const gradient = f.type === 'gradientGlow' || f.type === 'gradientBevel';
|
|
117
|
+
if (gradient) {
|
|
118
|
+
w.writeUI8(f.colors.length);
|
|
119
|
+
f.colors.forEach(color => w.writeRGBA(color));
|
|
120
|
+
f.ratios.forEach(ratio => w.writeUI8(ratio));
|
|
121
|
+
} else if (f.type === 'bevel') {
|
|
122
|
+
w.writeRGBA(f.shadowColor);
|
|
123
|
+
w.writeRGBA(f.highlightColor);
|
|
124
|
+
} else if (f.type !== 'blur') w.writeRGBA(f.color);
|
|
125
|
+
fixed(f.blurX);
|
|
126
|
+
fixed(f.blurY);
|
|
127
|
+
if (f.type === 'blur') {
|
|
128
|
+
w.writeUI8(f.passes << 3);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (f.type !== 'glow') {
|
|
132
|
+
fixed(f.angle);
|
|
133
|
+
fixed(f.distance);
|
|
134
|
+
}
|
|
135
|
+
w.writeFixed8(f.strength);
|
|
136
|
+
w.writeUI8((f.inner ? 128 : 0) | (f.knockout ? 64 : 0) | (f.compositeSource ? 32 : 0) |
|
|
137
|
+
(f.onTop ? 16 : 0) | f.passes);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Build the SWF. Returns `{ bytes, report }` where report lists features that were left out or
|
|
143
|
+
* approximated (strings, without repeats).
|
|
144
|
+
*
|
|
145
|
+
* @param {object} movie
|
|
146
|
+
* @param {number} movie.version SWF version
|
|
147
|
+
* @param {{xMin:number,xMax:number,yMin:number,yMax:number}} movie.frameSize twips
|
|
148
|
+
* @param {number} movie.frameRate
|
|
149
|
+
* @param {string} [movie.background] stage color
|
|
150
|
+
* @param {{frames:object[], characters:Record<string,object>, scenes?:object[]}} movie.displayList
|
|
151
|
+
* @param {object[]} [movie.tags] script tags beside the display list
|
|
152
|
+
* @param {Map<number,object>} [movie.bitmaps] id → `{ format: 'jpeg', bytes }` or
|
|
153
|
+
* `{ format: 'rgba', width, height, pixels }` (straight, not premultiplied, alpha)
|
|
154
|
+
* @param {(data: Uint8Array) => Uint8Array} movie.zlib zlib compression (bitmap data, CWS)
|
|
155
|
+
* @param {boolean} [movie.compress=true]
|
|
156
|
+
*/
|
|
157
|
+
/**
|
|
158
|
+
* `sounds` maps a character ID to `{ codecId, sampleRate, is16bit, isStereo, sampleCount, data }`:
|
|
159
|
+
* the `DefineSound` fields, with `data` as the tag stores it (MP3 starts with SeekSamples).
|
|
160
|
+
* Frames' `sounds` cues (`{ soundId, soundInfo }`) become `StartSound` tags.
|
|
161
|
+
*/
|
|
162
|
+
export const fontKey = (family, bold, italic) => `${family}|${bold ? 1 : 0}|${italic ? 1 : 0}`;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* DefineFont3 body. `font`: { name, bold, italic, ascent, descent, leading, glyphs: [{ code, advance,
|
|
166
|
+
* shape: { bytes, bounds } }] }, every length in the 20 × 1024 em square, glyphs sorted by code.
|
|
167
|
+
*/
|
|
168
|
+
export function encodeFont3(id, font) {
|
|
169
|
+
const w = new BitWriter();
|
|
170
|
+
w.writeUI16(id);
|
|
171
|
+
// HasLayout, WideOffsets, WideCodes, italic, bold.
|
|
172
|
+
w.writeUI8(0x80 | 0x08 | 0x04 | (font.italic ? 0x02 : 0) | (font.bold ? 0x01 : 0));
|
|
173
|
+
w.writeUI8(0);
|
|
174
|
+
const name = new TextEncoder().encode(font.name);
|
|
175
|
+
w.writeUI8(Math.min(255, name.length));
|
|
176
|
+
w.writeBytes(name.subarray(0, 255));
|
|
177
|
+
const glyphs = font.glyphs;
|
|
178
|
+
w.writeUI16(glyphs.length);
|
|
179
|
+
// Offsets count from the start of the offset table: glyph offsets, then the code table offset.
|
|
180
|
+
let offset = (glyphs.length + 1) * 4;
|
|
181
|
+
for (const glyph of glyphs) {
|
|
182
|
+
w.writeUI32(offset);
|
|
183
|
+
offset += glyph.shape.bytes.length;
|
|
184
|
+
}
|
|
185
|
+
w.writeUI32(offset);
|
|
186
|
+
for (const glyph of glyphs) w.writeBytes(glyph.shape.bytes);
|
|
187
|
+
for (const glyph of glyphs) w.writeUI16(glyph.code);
|
|
188
|
+
const clamp16 = value => Math.max(0, Math.min(65535, Math.round(value)));
|
|
189
|
+
w.writeUI16(clamp16(font.ascent));
|
|
190
|
+
w.writeUI16(clamp16(font.descent));
|
|
191
|
+
w.writeSI16(Math.max(-32768, Math.min(32767, Math.round(font.leading))));
|
|
192
|
+
for (const glyph of glyphs) w.writeUI16(clamp16(glyph.advance));
|
|
193
|
+
for (const glyph of glyphs) {
|
|
194
|
+
const b = glyph.shape.bounds;
|
|
195
|
+
w.writeRect({ xMin: Math.round(b.xMin), xMax: Math.round(b.xMax), yMin: Math.round(b.yMin), yMax: Math.round(b.yMax) });
|
|
196
|
+
}
|
|
197
|
+
w.writeUI16(0); // No kerning pairs.
|
|
198
|
+
return w.toBytes();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function buildSwf({ version, frameSize, frameRate, background = '#ffffff', displayList, tags = [], bitmaps = new Map(), sounds = new Map(), libraryTags = [], libraryMaxId = 0, embeddedFonts = new Map(), zlib, compress = true, makeMetadata = null }) {
|
|
202
|
+
const report = [];
|
|
203
|
+
const note = message => { if (!report.includes(message)) report.push(message); };
|
|
204
|
+
function effectFlags(place) {
|
|
205
|
+
const flags = (place.filters ? 1 : 0) | (place.blendMode !== undefined ? 2 : 0);
|
|
206
|
+
if (flags && version < 8) note('Placement filters and blend modes require SWF 8');
|
|
207
|
+
return version >= 8 ? flags : 0;
|
|
208
|
+
}
|
|
209
|
+
const writeEffects = (w, flags, place) => {
|
|
210
|
+
if (flags & 1) writeFilters(w, place.filters);
|
|
211
|
+
if (flags & 2) w.writeUI8(place.blendMode);
|
|
212
|
+
};
|
|
213
|
+
const shapeVersion = version >= 8 ? 4 : 3;
|
|
214
|
+
const characters = displayList.characters ?? {};
|
|
215
|
+
const out = [];
|
|
216
|
+
const avm2 = tags.some(tag => tag.type === 'DoABC' || tag.type === 'SymbolClass');
|
|
217
|
+
const binary = tags.filter(tag => tag.type === 'DefineBinaryData');
|
|
218
|
+
|
|
219
|
+
if (version >= 8) {
|
|
220
|
+
// FileAttributes selects the VM for the whole movie. Must be the first tag.
|
|
221
|
+
const w = new BitWriter();
|
|
222
|
+
w.writeUI32((avm2 ? 8 : 0) | (makeMetadata ? 16 : 0));
|
|
223
|
+
out.push(encodeTag(TAG.FileAttributes, w.toBytes()));
|
|
224
|
+
}
|
|
225
|
+
{
|
|
226
|
+
const w = new BitWriter();
|
|
227
|
+
w.writeRGB(parseColor(background));
|
|
228
|
+
out.push(encodeTag(TAG.SetBackgroundColor, w.toBytes()));
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Script tags beside the display list.
|
|
232
|
+
const spriteScripts = new Map(); // sprite id → per-frame script tags
|
|
233
|
+
const rootScripts = [];
|
|
234
|
+
const exports = [];
|
|
235
|
+
const rootTagFrames = splitFrames(tags.filter(tag => tag.type !== 'Sprite'));
|
|
236
|
+
for (const tag of tags) {
|
|
237
|
+
if (tag.type === 'Sprite') spriteScripts.set(tag.characterId, splitFrames(tag.tags).map(frame =>
|
|
238
|
+
frame.map((tag, i) => scriptTag(tag, frame[i - 1])).filter(Boolean)));
|
|
239
|
+
}
|
|
240
|
+
rootTagFrames.forEach((frame, index) => {
|
|
241
|
+
rootScripts[index] = [];
|
|
242
|
+
for (const [i, tag] of frame.entries()) {
|
|
243
|
+
const previous = frame[i - 1];
|
|
244
|
+
if (tag.type === 'DoInitAction') rootScripts[index].push({ kind: 'init', tag, prefix: previous?.code === 253 ? previous.data : null });
|
|
245
|
+
else if (tag.type === 'ExportAssets') exports.push(...(tag.assets ?? []));
|
|
246
|
+
else {
|
|
247
|
+
const entry = scriptTag(tag, previous);
|
|
248
|
+
if (entry) rootScripts[index].push(entry);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
// Fonts for text fields, one per family and weight: device fonts, or the outlines in
|
|
254
|
+
// `embeddedFonts` (keyed `family|bold|italic`, see fontKey) when the caller found them.
|
|
255
|
+
let nextId = Math.max(libraryMaxId, ...Object.keys(characters).map(Number), ...bitmaps.keys(), ...sounds.keys(), ...binary.map(tag => tag.characterId)) + 1;
|
|
256
|
+
const fonts = new Map();
|
|
257
|
+
const fontFor = (family, bold, italic) => {
|
|
258
|
+
const key = fontKey(family, bold, italic);
|
|
259
|
+
if (!fonts.has(key)) fonts.set(key, { id: nextId++, family, bold, italic, embedded: embeddedFonts.get(key) ?? null });
|
|
260
|
+
return fonts.get(key);
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
// --- Definitions, each after what it uses ----------------------------------------------
|
|
264
|
+
const definitions = new Map(); // id → encoded tag
|
|
265
|
+
const ordered = [];
|
|
266
|
+
const state = new Map(); // id → 'visiting' | 'done'
|
|
267
|
+
const visit = id => {
|
|
268
|
+
const key = Number(id);
|
|
269
|
+
if (state.get(key) === 'done') return;
|
|
270
|
+
if (state.get(key) === 'visiting') return; // Clips placing each other: Flash resolves at run time.
|
|
271
|
+
state.set(key, 'visiting');
|
|
272
|
+
const character = characters[key];
|
|
273
|
+
if (character) for (const dependency of dependencies(character)) visit(dependency);
|
|
274
|
+
state.set(key, 'done');
|
|
275
|
+
if (bitmaps.has(key) || character) ordered.push(key);
|
|
276
|
+
};
|
|
277
|
+
for (const id of [...bitmaps.keys(), ...Object.keys(characters).map(Number)].sort((a, b) => a - b)) visit(id);
|
|
278
|
+
|
|
279
|
+
const encodeBitmap = (id, bitmap) => {
|
|
280
|
+
const w = new BitWriter();
|
|
281
|
+
w.writeUI16(id);
|
|
282
|
+
if (bitmap.format === 'jpeg') {
|
|
283
|
+
w.writeBytes(bitmap.bytes);
|
|
284
|
+
return encodeTag(TAG.DefineBitsJPEG2, w.toBytes());
|
|
285
|
+
}
|
|
286
|
+
// DefineBitsLossless2 stores premultiplied ARGB.
|
|
287
|
+
const { width, height, pixels } = bitmap;
|
|
288
|
+
const argb = new Uint8Array(width * height * 4);
|
|
289
|
+
for (let i = 0; i < width * height; i++) {
|
|
290
|
+
const a = pixels[i * 4 + 3];
|
|
291
|
+
argb[i * 4] = a;
|
|
292
|
+
for (let channel = 0; channel < 3; channel++) argb[i * 4 + 1 + channel] = Math.round(pixels[i * 4 + channel] * a / 255);
|
|
293
|
+
}
|
|
294
|
+
w.writeUI8(5);
|
|
295
|
+
w.writeUI16(width);
|
|
296
|
+
w.writeUI16(height);
|
|
297
|
+
w.writeBytes(zlib(argb));
|
|
298
|
+
return encodeTag(TAG.DefineBitsLossless2, w.toBytes());
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
const encodeText = (id, text) => {
|
|
302
|
+
if (text.kind && text.kind !== 'edit') note('Static text with embedded glyphs (left out)');
|
|
303
|
+
const w = new BitWriter();
|
|
304
|
+
w.writeUI16(id);
|
|
305
|
+
const b = text.bounds ?? { x: 0, y: 0, w: 100, h: 20 };
|
|
306
|
+
w.writeRect({ xMin: Math.round(b.x * 20), xMax: Math.round((b.x + b.w) * 20), yMin: Math.round(b.y * 20), yMax: Math.round((b.y + b.h) * 20) });
|
|
307
|
+
const initial = String(text.text ?? '');
|
|
308
|
+
const maxLength = text.maxLength ?? 0;
|
|
309
|
+
let flags = 0x0001 | 0x0004 | 0x2000; // HasFont, HasTextColor, HasLayout
|
|
310
|
+
if (initial) flags |= 0x0080;
|
|
311
|
+
if (text.wordWrap) flags |= 0x0040;
|
|
312
|
+
if (text.multiline) flags |= 0x0020;
|
|
313
|
+
if (text.password) flags |= 0x0010;
|
|
314
|
+
if (text.readOnly ?? !text.editable) flags |= 0x0008;
|
|
315
|
+
if (maxLength) flags |= 0x0002;
|
|
316
|
+
if (text.autoSize) flags |= 0x4000;
|
|
317
|
+
if (!text.selectable) flags |= 0x1000;
|
|
318
|
+
if (text.border) flags |= 0x0800;
|
|
319
|
+
if (text.wasStatic) flags |= 0x0400;
|
|
320
|
+
if (text.html) flags |= 0x0200;
|
|
321
|
+
const font = text.fontId ?? text.outlineFontId ?? fontFor(text.font ?? '_sans', !!text.bold, !!text.italic);
|
|
322
|
+
if (text.outlineFontId || font.embedded) flags |= 0x0100;
|
|
323
|
+
w.writeUI16(flags);
|
|
324
|
+
w.writeUI16(typeof font === 'object' ? font.id : font);
|
|
325
|
+
w.writeUI16(Math.max(0, Math.min(65535, Math.round((text.fontSize ?? 12) * 20))));
|
|
326
|
+
w.writeRGBA(parseColor(text.color ?? '#000000'));
|
|
327
|
+
if (maxLength) w.writeUI16(maxLength);
|
|
328
|
+
w.writeUI8(ALIGN[text.align] ?? (typeof text.align === 'number' ? text.align : 0));
|
|
329
|
+
w.writeUI16(Math.round((text.leftMargin ?? 0) * 20));
|
|
330
|
+
w.writeUI16(Math.round((text.rightMargin ?? 0) * 20));
|
|
331
|
+
w.writeSI16(Math.round((text.indent ?? 0) * 20));
|
|
332
|
+
w.writeSI16(Math.round((text.leading ?? 0) * 20));
|
|
333
|
+
w.writeString(text.variableName ?? '');
|
|
334
|
+
if (initial) w.writeString(initial);
|
|
335
|
+
return encodeTag(TAG.DefineEditText, w.toBytes());
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
const encodeButton = (id, button) => {
|
|
339
|
+
const w = new BitWriter();
|
|
340
|
+
w.writeUI16(id);
|
|
341
|
+
w.writeUI8(button.trackAsMenu ? 1 : 0);
|
|
342
|
+
const records = new BitWriter();
|
|
343
|
+
const states = button.buttonStates ?? {};
|
|
344
|
+
const record = (flag, item) => {
|
|
345
|
+
const effects = effectFlags(item);
|
|
346
|
+
records.writeUI8(flag | (effects << 4));
|
|
347
|
+
records.writeUI16(item.characterId);
|
|
348
|
+
records.writeUI16(item.depth);
|
|
349
|
+
records.writeMatrix(item.matrix);
|
|
350
|
+
records.writeColorTransform(item.colorTransform ?? IDENTITY_CXFORM, true);
|
|
351
|
+
writeEffects(records, effects, item);
|
|
352
|
+
};
|
|
353
|
+
for (const item of states.up ?? []) record(0x01, item);
|
|
354
|
+
for (const item of states.over ?? []) record(0x02, item);
|
|
355
|
+
for (const item of states.down ?? []) record(0x04, item);
|
|
356
|
+
for (const item of button.buttonHitStates ?? []) record(0x08, item);
|
|
357
|
+
records.writeUI8(0);
|
|
358
|
+
const recordBytes = records.toBytes();
|
|
359
|
+
if (avm2 && button.actions?.length) note('AVM1 button actions cannot run in an ActionScript 3 movie');
|
|
360
|
+
const actions = (avm2 ? [] : button.actions ?? []).map(action => ({ conditions: action.conditions ?? {}, bytes: action.bytes ?? action.bytecode })).filter(action => {
|
|
361
|
+
if (action.bytes) return true;
|
|
362
|
+
note('Button actions without bytecode (left out)');
|
|
363
|
+
return false;
|
|
364
|
+
});
|
|
365
|
+
// ActionOffset counts from its own field to the first BUTTONCONDACTION.
|
|
366
|
+
w.writeUI16(actions.length ? 2 + recordBytes.length : 0);
|
|
367
|
+
w.writeBytes(recordBytes);
|
|
368
|
+
actions.forEach((action, index) => {
|
|
369
|
+
const body = withActionEnd(action.bytes);
|
|
370
|
+
const c = action.conditions;
|
|
371
|
+
const bits = (c.idleToOverDown ? 0x8000 : 0) | (c.outDownToIdle ? 0x4000 : 0) | (c.outDownToOverDown ? 0x2000 : 0)
|
|
372
|
+
| (c.overDownToOutDown ? 0x1000 : 0) | (c.overDownToOverUp ? 0x0800 : 0) | (c.overUpToOverDown ? 0x0400 : 0)
|
|
373
|
+
| (c.overUpToIdle ? 0x0200 : 0) | (c.idleToOverUp ? 0x0100 : 0) | (((c.keyPress ?? 0) & 0x7f) << 1) | (c.overDownToIdle ? 1 : 0);
|
|
374
|
+
w.writeUI16(index === actions.length - 1 ? 0 : 4 + body.length);
|
|
375
|
+
w.writeUB(bits, 16);
|
|
376
|
+
w.writeBytes(body);
|
|
377
|
+
});
|
|
378
|
+
return encodeTag(TAG.DefineButton2, w.toBytes());
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
// --- Timelines ---------------------------------------------------------------------------
|
|
382
|
+
const writePlace = (place, clipActions) => {
|
|
383
|
+
const w = new BitWriter();
|
|
384
|
+
const hasMatrix = !!place.matrix;
|
|
385
|
+
const hasCxform = !!place.colorTransform;
|
|
386
|
+
const hasChar = place.characterId != null;
|
|
387
|
+
const hasName = !!place.name;
|
|
388
|
+
const hasClip = place.clipDepth != null;
|
|
389
|
+
const hasRatio = place.ratio != null;
|
|
390
|
+
const hasActions = !!clipActions?.length && version >= 5;
|
|
391
|
+
const flags = (place.move ? 0x01 : 0) | (hasChar ? 0x02 : 0) | (hasMatrix ? 0x04 : 0) | (hasCxform ? 0x08 : 0)
|
|
392
|
+
| (hasRatio ? 0x10 : 0) | (hasName ? 0x20 : 0) | (hasClip ? 0x40 : 0) | (hasActions ? 0x80 : 0);
|
|
393
|
+
const effects = effectFlags(place);
|
|
394
|
+
w.writeUI8(flags);
|
|
395
|
+
if (effects) w.writeUI8(effects);
|
|
396
|
+
w.writeUI16(place.depth);
|
|
397
|
+
if (hasChar) w.writeUI16(place.characterId);
|
|
398
|
+
if (hasMatrix) w.writeMatrix(place.matrix);
|
|
399
|
+
if (hasCxform) w.writeColorTransform(place.colorTransform, true);
|
|
400
|
+
if (hasRatio) w.writeUI16(place.ratio);
|
|
401
|
+
if (hasName) w.writeString(place.name);
|
|
402
|
+
if (hasClip) w.writeUI16(place.clipDepth);
|
|
403
|
+
writeEffects(w, effects, place);
|
|
404
|
+
if (hasActions) {
|
|
405
|
+
const wide = version >= 6;
|
|
406
|
+
const writeFlags = value => (wide ? w.writeUI32(value >>> 0) : w.writeUI16(value & 0xffff));
|
|
407
|
+
w.writeUI16(0);
|
|
408
|
+
writeFlags(clipActions.reduce((all, action) => all | action.eventFlags, 0));
|
|
409
|
+
for (const action of clipActions) {
|
|
410
|
+
const body = withActionEnd(action.bytecode ?? action.bytes);
|
|
411
|
+
const key = action.eventFlags & 0x20000;
|
|
412
|
+
writeFlags(action.eventFlags);
|
|
413
|
+
w.writeUI32(body.length + (key ? 1 : 0));
|
|
414
|
+
if (key) w.writeUI8(action.keyCode ?? 0);
|
|
415
|
+
w.writeBytes(body);
|
|
416
|
+
}
|
|
417
|
+
writeFlags(0);
|
|
418
|
+
}
|
|
419
|
+
return encodeTag(effects ? TAG.PlaceObject3 : TAG.PlaceObject2, w.toBytes());
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
const writeSoundInfo = (w, info = {}) => {
|
|
423
|
+
const envelope = info.envelope ?? [];
|
|
424
|
+
w.writeUI8((info.syncStop ? 32 : 0) | (info.syncNoMultiple ? 16 : 0) | (envelope.length ? 8 : 0) |
|
|
425
|
+
(info.loopCount != null ? 4 : 0) | (info.outPoint != null ? 2 : 0) | (info.inPoint != null ? 1 : 0));
|
|
426
|
+
if (info.inPoint != null) w.writeUI32(info.inPoint);
|
|
427
|
+
if (info.outPoint != null) w.writeUI32(info.outPoint);
|
|
428
|
+
if (info.loopCount != null) w.writeUI16(Math.min(65535, info.loopCount));
|
|
429
|
+
if (envelope.length) {
|
|
430
|
+
w.writeUI8(envelope.length);
|
|
431
|
+
for (const { position, leftLevel, rightLevel } of envelope) {
|
|
432
|
+
w.writeUI32(position); w.writeUI16(leftLevel); w.writeUI16(rightLevel);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
const startSoundTag = ({ soundId, soundClassName, soundInfo }) => {
|
|
437
|
+
const w = new BitWriter();
|
|
438
|
+
if (soundClassName) w.writeString(soundClassName);
|
|
439
|
+
else w.writeUI16(soundId);
|
|
440
|
+
writeSoundInfo(w, soundInfo);
|
|
441
|
+
return encodeTag(soundClassName ? TAG.StartSound2 : TAG.StartSound, w.toBytes());
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
const removeTag = depth => {
|
|
445
|
+
const w = new BitWriter();
|
|
446
|
+
w.writeUI16(depth);
|
|
447
|
+
return encodeTag(TAG.RemoveObject2, w.toBytes());
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
const labelTag = name => {
|
|
451
|
+
const w = new BitWriter();
|
|
452
|
+
w.writeString(name);
|
|
453
|
+
return encodeTag(TAG.FrameLabel, w.toBytes());
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
/** Control tags of one timeline: per frame labels, removes, places, actions, ShowFrame. */
|
|
457
|
+
const timelineTags = (frames, scripts, frameLabels = new Map()) => {
|
|
458
|
+
const result = [];
|
|
459
|
+
let previousHead;
|
|
460
|
+
frames.forEach((frame, index) => {
|
|
461
|
+
let frameScripts = scripts?.[index] ?? [];
|
|
462
|
+
if (avm2 && frameScripts.some(entry => entry.kind !== 'avm2')) {
|
|
463
|
+
note('AVM1 actions cannot run in an ActionScript 3 movie');
|
|
464
|
+
frameScripts = frameScripts.filter(entry => entry.kind === 'avm2');
|
|
465
|
+
}
|
|
466
|
+
for (const entry of frameScripts) {
|
|
467
|
+
if (entry.kind === 'avm2') result.push(entry.bytes);
|
|
468
|
+
if (entry.kind !== 'init') continue;
|
|
469
|
+
const w = new BitWriter();
|
|
470
|
+
w.writeUI16(entry.tag.spriteId);
|
|
471
|
+
if (entry.prefix) result.push(encodeTag(253, entry.prefix));
|
|
472
|
+
w.writeBytes(entry.prefix ? entry.tag.bytecode : withActionEnd(entry.tag.bytecode));
|
|
473
|
+
result.push(encodeTag(TAG.DoInitAction, w.toBytes()));
|
|
474
|
+
}
|
|
475
|
+
const own = [...(frame.labels ?? (frame.label ? [frame.label] : []))];
|
|
476
|
+
for (const label of own.length ? own : frameLabels.has(index) ? [frameLabels.get(index)] : []) result.push(labelTag(label));
|
|
477
|
+
for (const depth of frame.removes ?? []) result.push(removeTag(depth));
|
|
478
|
+
const clips = new Map(frameScripts.filter(entry => entry.kind === 'clip').map(entry => [entry.place.depth, entry.place.clipActions]));
|
|
479
|
+
for (const place of frame.places ?? []) {
|
|
480
|
+
if (place.remove) { result.push(removeTag(place.depth)); continue; }
|
|
481
|
+
const clipActions = !place.move ? clips.get(place.depth) : null;
|
|
482
|
+
if (clipActions) clips.delete(place.depth);
|
|
483
|
+
result.push(writePlace(place, clipActions));
|
|
484
|
+
}
|
|
485
|
+
if (clips.size) note('Clip events without a matching placement (left out)');
|
|
486
|
+
for (const entry of frameScripts) if (entry.kind === 'action' && entry.bytes?.length) {
|
|
487
|
+
if (entry.prefix) result.push(encodeTag(253, entry.prefix));
|
|
488
|
+
result.push(encodeTag(TAG.DoAction, entry.prefix ? entry.bytes : withActionEnd(entry.bytes)));
|
|
489
|
+
}
|
|
490
|
+
for (const cue of frame.sounds ?? []) {
|
|
491
|
+
if (cue.soundClassName && version < 9) note('Class-linked sound cues require SWF 9');
|
|
492
|
+
else if (cue.soundClassName || sounds.has(cue.soundId)) result.push(startSoundTag(cue));
|
|
493
|
+
else note('Sound (left out)');
|
|
494
|
+
}
|
|
495
|
+
if (frame.streamHead && frame.streamHead !== previousHead) {
|
|
496
|
+
const head = frame.streamHead;
|
|
497
|
+
result.push(encodeTag(head.code === TAG.SoundStreamHead ? TAG.SoundStreamHead : TAG.SoundStreamHead2, head.rawData));
|
|
498
|
+
previousHead = head;
|
|
499
|
+
}
|
|
500
|
+
for (const block of frame.streamBlocks ?? []) result.push(encodeTag(TAG.SoundStreamBlock, block.rawData));
|
|
501
|
+
result.push(encodeTag(TAG.ShowFrame));
|
|
502
|
+
});
|
|
503
|
+
return result;
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
for (const id of ordered) {
|
|
507
|
+
if (bitmaps.has(id) && !characters[id]) {
|
|
508
|
+
definitions.set(id, encodeBitmap(id, bitmaps.get(id)));
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
const character = characters[id];
|
|
512
|
+
if (character.type === 'shape') {
|
|
513
|
+
if (character.nativeMorph) {
|
|
514
|
+
const raw = Uint8Array.from(character.nativeMorph.rawData);
|
|
515
|
+
raw[0] = id & 255; raw[1] = id >> 8;
|
|
516
|
+
definitions.set(id, encodeTag(character.nativeMorph.version === 2 ? TAG.DefineMorphShape2 : TAG.DefineMorphShape, raw));
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
if (character.morph) note('Morph without source edges exported at its first exposure');
|
|
520
|
+
definitions.set(id, encodeTag(shapeVersion >= 4 ? TAG.DefineShape4 : TAG.DefineShape3, encodeShape(id, character.draws ?? [], { shapeVersion, report: note, hasBitmap: bitmapId => bitmaps.has(bitmapId) })));
|
|
521
|
+
} else if (character.type === 'text') {
|
|
522
|
+
definitions.set(id, encodeText(id, character));
|
|
523
|
+
} else if (character.type === 'button') {
|
|
524
|
+
definitions.set(id, encodeButton(id, character));
|
|
525
|
+
} else if (character.type === 'sprite') {
|
|
526
|
+
const w = new BitWriter();
|
|
527
|
+
w.writeUI16(id);
|
|
528
|
+
const frames = character.frames ?? [];
|
|
529
|
+
w.writeUI16(Math.max(1, frames.length));
|
|
530
|
+
w.writeBytes(concatBytes([...timelineTags(frames.length ? frames : [{ places: [] }], spriteScripts.get(id)), encodeTag(TAG.End)]));
|
|
531
|
+
definitions.set(id, encodeTag(TAG.DefineSprite, w.toBytes()));
|
|
532
|
+
} else {
|
|
533
|
+
note(`${character.type ?? 'Unknown'} characters (left out)`);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// Regenerated fields can use the original embedded fonts. The remaining native
|
|
538
|
+
// symbols come after the editable characters that they can place by original ID.
|
|
539
|
+
const earlyLibrary = new Set([TAG.JPEGTables, TAG.DefineBits, TAG.DefineBitsJPEG2, TAG.DefineBitsJPEG3, TAG.DefineBitsJPEG4,
|
|
540
|
+
TAG.DefineBitsLossless, TAG.DefineBitsLossless2, TAG.DefineFont, TAG.DefineFont2, TAG.DefineFont3, TAG.DefineFont4,
|
|
541
|
+
TAG.DefineFontInfo, TAG.DefineFontInfo2, TAG.DefineFontName, TAG.DefineFontAlignZones, TAG.DefineSound, TAG.DefineBinaryData]);
|
|
542
|
+
for (const tag of libraryTags) if (earlyLibrary.has(tag.code)) out.push(encodeTag(tag.code, tag.data));
|
|
543
|
+
// Fonts first: text fields refer to them.
|
|
544
|
+
for (const font of fonts.values()) {
|
|
545
|
+
if (font.embedded) {
|
|
546
|
+
out.push(encodeTag(TAG.DefineFont3, encodeFont3(font.id, font.embedded)));
|
|
547
|
+
continue;
|
|
548
|
+
}
|
|
549
|
+
const w = new BitWriter();
|
|
550
|
+
w.writeUI16(font.id);
|
|
551
|
+
// DefineFont2 without glyphs: a device font. Flags: WideCodes (required from SWF 6), italic, bold.
|
|
552
|
+
w.writeUI8(0x04 | (font.italic ? 0x02 : 0) | (font.bold ? 0x01 : 0));
|
|
553
|
+
w.writeUI8(0); // Language code.
|
|
554
|
+
const name = new TextEncoder().encode(font.family);
|
|
555
|
+
w.writeUI8(name.length);
|
|
556
|
+
w.writeBytes(name);
|
|
557
|
+
w.writeUI16(0); // No glyphs.
|
|
558
|
+
w.writeUI16(2); // Code table offset, as Flash writes for device fonts.
|
|
559
|
+
out.push(encodeTag(TAG.DefineFont2, w.toBytes()));
|
|
560
|
+
}
|
|
561
|
+
for (const [id, sound] of sounds) {
|
|
562
|
+
const w = new BitWriter();
|
|
563
|
+
w.writeUI16(id);
|
|
564
|
+
const rate = [5512, 11025, 22050, 44100].indexOf(sound.sampleRate);
|
|
565
|
+
w.writeUI8((sound.codecId & 0x0f) << 4 | Math.max(0, rate) << 2 | (sound.is16bit ? 0x02 : 0) | (sound.isStereo ? 0x01 : 0));
|
|
566
|
+
w.writeUI32(sound.sampleCount >>> 0);
|
|
567
|
+
w.writeBytes(sound.data);
|
|
568
|
+
out.push(encodeTag(TAG.DefineSound, w.toBytes()));
|
|
569
|
+
}
|
|
570
|
+
for (const id of ordered) {
|
|
571
|
+
if (definitions.has(id)) out.push(definitions.get(id));
|
|
572
|
+
const grid = characters[id]?.scalingGrid;
|
|
573
|
+
if (grid && version >= 8) {
|
|
574
|
+
const w = new BitWriter();
|
|
575
|
+
w.writeUI16(id);
|
|
576
|
+
w.writeRect({ xMin: Math.round(grid.x * 20), xMax: Math.round((grid.x + grid.w) * 20),
|
|
577
|
+
yMin: Math.round(grid.y * 20), yMax: Math.round((grid.y + grid.h) * 20) });
|
|
578
|
+
out.push(encodeTag(TAG.DefineScalingGrid, w.toBytes()));
|
|
579
|
+
} else if (grid) note('Nine-slice scaling requires SWF 8');
|
|
580
|
+
const transitions = characters[id]?.buttonSounds;
|
|
581
|
+
if (!transitions) continue;
|
|
582
|
+
const w = new BitWriter();
|
|
583
|
+
w.writeUI16(id);
|
|
584
|
+
for (const name of BUTTON_SOUND_TRANSITIONS) {
|
|
585
|
+
const cue = transitions[name];
|
|
586
|
+
if (cue && sounds.has(cue.soundId)) {
|
|
587
|
+
w.writeUI16(cue.soundId);
|
|
588
|
+
writeSoundInfo(w, cue.soundInfo);
|
|
589
|
+
} else {
|
|
590
|
+
if (cue) note('Button transition sound could not be published');
|
|
591
|
+
w.writeUI16(0);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
out.push(encodeTag(TAG.DefineButtonSound, w.toBytes()));
|
|
595
|
+
}
|
|
596
|
+
for (const tag of libraryTags) if (!earlyLibrary.has(tag.code)) out.push(encodeTag(tag.code, tag.data));
|
|
597
|
+
for (const tag of binary) {
|
|
598
|
+
const w = new BitWriter();
|
|
599
|
+
w.writeUI16(tag.characterId);
|
|
600
|
+
w.writeUI32(0);
|
|
601
|
+
w.writeBytes(tag.rawData);
|
|
602
|
+
out.push(encodeTag(TAG.DefineBinaryData, w.toBytes()));
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
if (exports.length) {
|
|
606
|
+
const w = new BitWriter();
|
|
607
|
+
w.writeUI16(exports.length);
|
|
608
|
+
for (const asset of exports) {
|
|
609
|
+
w.writeUI16(asset.id);
|
|
610
|
+
w.writeString(asset.name);
|
|
611
|
+
}
|
|
612
|
+
out.push(encodeTag(TAG.ExportAssets, w.toBytes()));
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// Scene names label the frame each scene starts on, when that frame has no label of its own
|
|
616
|
+
// and the name is not already a label (AVM1 movies keep no scene table).
|
|
617
|
+
const rootFrames = displayList.frames ?? [];
|
|
618
|
+
const sceneLabels = new Map();
|
|
619
|
+
const scenes = displayList.scenes ?? [];
|
|
620
|
+
if (scenes.length > 1) {
|
|
621
|
+
const used = new Set(rootFrames.flatMap(frame => frame.labels ?? (frame.label ? [frame.label] : [])));
|
|
622
|
+
for (const scene of scenes) {
|
|
623
|
+
const frame = rootFrames[scene.offset];
|
|
624
|
+
if (frame && !frame.label && !frame.labels?.length && scene.name && !used.has(scene.name)) {
|
|
625
|
+
sceneLabels.set(scene.offset, scene.name);
|
|
626
|
+
used.add(scene.name);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
for (const tag of timelineTags(rootFrames.length ? rootFrames : [{ places: [] }], rootScripts, sceneLabels)) out.push(tag);
|
|
631
|
+
|
|
632
|
+
if (makeMetadata && version >= 8) {
|
|
633
|
+
const metadata = new BitWriter();
|
|
634
|
+
metadata.writeString(makeMetadata(out));
|
|
635
|
+
out.splice(1, 0, encodeTag(TAG.Metadata, metadata.toBytes()));
|
|
636
|
+
}
|
|
637
|
+
const bytes = writeSwf({ version, frameSize, frameRate, frameCount: Math.max(1, rootFrames.length), tags: out, deflate: compress ? zlib : null });
|
|
638
|
+
return { bytes, report };
|
|
639
|
+
}
|