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.
Files changed (416) hide show
  1. package/README.md +81 -14
  2. package/package.json +11 -7
  3. package/studio/actionscript-roundtrip.test.js +54 -0
  4. package/studio/actionscript-scripts.test.js +169 -0
  5. package/studio/animated-image.test.js +137 -0
  6. package/studio/arithmetic.test.js +16 -0
  7. package/studio/as3-import.test.js +110 -0
  8. package/studio/audio-info.test.js +44 -0
  9. package/studio/components.test.js +152 -0
  10. package/studio/document-editing.test.js +92 -0
  11. package/studio/examples/01-space-mission.json +1628 -0
  12. package/studio/examples/02-clockwork-vault.json +1079 -0
  13. package/studio/examples/03-neon-synth.json +1364 -0
  14. package/studio/examples/04-kinetic-poster.json +923 -0
  15. package/studio/examples/05-signal-relay.json +1131 -0
  16. package/studio/examples/06-calculator.json +564 -0
  17. package/studio/frame-editing.test.js +129 -0
  18. package/studio/frame-events.test.js +117 -0
  19. package/studio/groups.test.js +88 -0
  20. package/studio/index.html +962 -0
  21. package/studio/interaction-triggers.test.js +37 -0
  22. package/studio/linked-actions.test.js +48 -0
  23. package/studio/lottie.test.js +208 -0
  24. package/studio/masks.test.js +43 -0
  25. package/studio/media-assets.test.js +62 -0
  26. package/studio/paint-tools.test.js +60 -0
  27. package/studio/playback.test.js +17 -0
  28. package/studio/project-io.test.js +405 -0
  29. package/studio/project-preview.test.js +475 -0
  30. package/studio/scene-transition.test.js +32 -0
  31. package/studio/server/archive-companions.js +27 -0
  32. package/studio/server/as3-library.js +91 -0
  33. package/studio/server/assets.js +162 -0
  34. package/studio/server/audio-info.js +82 -0
  35. package/studio/server/font-files.js +332 -0
  36. package/studio/server/http.js +135 -0
  37. package/studio/server/linked-actions.js +93 -0
  38. package/studio/server/png-decode.js +1 -0
  39. package/studio/server/project-movie.js +1164 -0
  40. package/studio/server/project-preview.js +152 -0
  41. package/studio/server/projects.js +370 -0
  42. package/studio/server/report.js +29 -0
  43. package/studio/server/routes.js +93 -0
  44. package/studio/server/swf-authoring.js +90 -0
  45. package/studio/server/swf-control-runtime.as +513 -0
  46. package/studio/server/swf-controls.js +119 -0
  47. package/studio/server/swf-export.js +293 -0
  48. package/studio/server/swf-import.js +1675 -0
  49. package/studio/server/swf-morphs.js +64 -0
  50. package/studio/server/swf-routes.js +42 -0
  51. package/studio/server/swf-streams.js +80 -0
  52. package/studio/server/swf-transition-runtime.as +52 -0
  53. package/studio/server/tween-recovery.js +106 -0
  54. package/studio/server-api.test.js +283 -0
  55. package/studio/server.js +320 -0
  56. package/studio/src/animated-image.js +423 -0
  57. package/studio/src/appearance-inspector.js +63 -0
  58. package/studio/src/arithmetic.js +50 -0
  59. package/studio/src/authored-controls.js +42 -0
  60. package/studio/src/busy.js +41 -0
  61. package/studio/src/canvas.js +430 -0
  62. package/studio/src/clipper-browser.js +2 -0
  63. package/studio/src/color-transform.js +38 -0
  64. package/studio/src/component-inspector.js +126 -0
  65. package/studio/src/components.js +268 -0
  66. package/studio/src/display-frame.js +262 -0
  67. package/studio/src/document-editing.js +69 -0
  68. package/studio/src/event-editor.js +150 -0
  69. package/studio/src/frame-editing.js +150 -0
  70. package/studio/src/frame-events.js +128 -0
  71. package/studio/src/frame-image.js +28 -0
  72. package/studio/src/groups.js +125 -0
  73. package/studio/src/handler-editor.js +122 -0
  74. package/studio/src/history.js +83 -0
  75. package/studio/src/imported-paths.js +99 -0
  76. package/studio/src/index.js +3582 -0
  77. package/studio/src/interaction-triggers.js +42 -0
  78. package/studio/src/json-patch.js +77 -0
  79. package/studio/src/layer-icons.js +25 -0
  80. package/studio/src/lottie-export.js +948 -0
  81. package/studio/src/lottie-import.js +1138 -0
  82. package/studio/src/masks.js +69 -0
  83. package/studio/src/media-assets.js +188 -0
  84. package/studio/src/media-library.js +193 -0
  85. package/studio/src/model.js +431 -0
  86. package/studio/src/numeric-fields.js +46 -0
  87. package/studio/src/object-list.js +57 -0
  88. package/studio/src/paint-tools.js +76 -0
  89. package/studio/src/placement-effects.js +74 -0
  90. package/studio/src/playback.js +10 -0
  91. package/studio/src/preview-audio.js +64 -0
  92. package/studio/src/preview-interactions.js +106 -0
  93. package/studio/src/preview-recorder.js +335 -0
  94. package/studio/src/preview-surface.js +338 -0
  95. package/studio/src/project-io.js +905 -0
  96. package/studio/src/project-session.js +375 -0
  97. package/studio/src/projects-dialog.js +319 -0
  98. package/studio/src/scene-transition.js +129 -0
  99. package/studio/src/script-editor.js +175 -0
  100. package/studio/src/script-references.js +74 -0
  101. package/studio/src/scripted-controls.js +146 -0
  102. package/studio/src/scripts.js +185 -0
  103. package/studio/src/stage-guides.js +101 -0
  104. package/studio/src/svg-animation.js +416 -0
  105. package/studio/src/svg-context.js +522 -0
  106. package/studio/src/svg-frame.js +413 -0
  107. package/studio/src/svg-import.js +1208 -0
  108. package/studio/src/swf-recording.js +104 -0
  109. package/studio/src/symbol-library.js +39 -0
  110. package/studio/src/symbols.js +62 -0
  111. package/studio/src/text-fields.js +58 -0
  112. package/studio/src/theme.js +43 -0
  113. package/studio/src/timeline.js +321 -0
  114. package/studio/src/vector-cut.js +103 -0
  115. package/studio/src/vector-geometry.js +254 -0
  116. package/studio/src/vector-style.js +146 -0
  117. package/studio/src/video-encode.js +84 -0
  118. package/studio/src/video-export.js +331 -0
  119. package/studio/src/video-mux.js +339 -0
  120. package/studio/src/video-playback.js +281 -0
  121. package/studio/src/workspace.js +344 -0
  122. package/studio/stroke-style.test.js +119 -0
  123. package/studio/styles.css +1547 -0
  124. package/studio/svg-export.test.js +162 -0
  125. package/studio/svg-import.test.js +318 -0
  126. package/studio/swf-authoring.test.js +140 -0
  127. package/studio/swf-export.test.js +324 -0
  128. package/studio/swf-import.test.js +489 -0
  129. package/studio/symbols.test.js +68 -0
  130. package/studio/tests/accessibility-interactions.mjs +138 -0
  131. package/studio/tests/appearance-interactions.mjs +103 -0
  132. package/studio/tests/control-interactions.mjs +60 -0
  133. package/studio/tests/event-interactions.mjs +117 -0
  134. package/studio/tests/external-resources.mjs +174 -0
  135. package/studio/tests/frame-image.mjs +71 -0
  136. package/studio/tests/html-export.mjs +68 -0
  137. package/studio/tests/import-files.mjs +131 -0
  138. package/studio/tests/lottie.mjs +125 -0
  139. package/studio/tests/mask-interactions.mjs +148 -0
  140. package/studio/tests/media-interactions.mjs +109 -0
  141. package/studio/tests/paint-interactions.mjs +64 -0
  142. package/studio/tests/project-interactions.mjs +244 -0
  143. package/studio/tests/script-interactions.mjs +178 -0
  144. package/studio/tests/scripted-control-interactions.mjs +107 -0
  145. package/studio/tests/svg-export.mjs +149 -0
  146. package/studio/tests/text-field-interactions.mjs +64 -0
  147. package/studio/tests/theme-interactions.mjs +53 -0
  148. package/studio/tests/timeline-browser.mjs +507 -0
  149. package/studio/tests/transition-interactions.mjs +94 -0
  150. package/studio/tests/trigger-interactions.mjs +93 -0
  151. package/studio/tests/video-export.mjs +243 -0
  152. package/studio/tests/workspace-interactions.mjs +226 -0
  153. package/studio/tween-recovery.test.js +31 -0
  154. package/studio/vector-style.test.js +56 -0
  155. package/studio/video-export.test.js +326 -0
  156. package/studiospec/actionscript.md +88 -0
  157. package/studiospec/architecture.md +378 -0
  158. package/studiospec/controls.md +100 -0
  159. package/studiospec/file-support.md +268 -0
  160. package/studiospec/lottie.md +69 -0
  161. package/studiospec/requirements.md +135 -0
  162. package/studiospec/stroke-style.md +95 -0
  163. package/studiospec/svg-export.md +83 -0
  164. package/studiospec/svg-import.md +139 -0
  165. package/studiospec/swooflib-integration.md +115 -0
  166. package/studiospec/tasks.md +573 -0
  167. package/studiospec/video-export.md +127 -0
  168. package/swf2js/__tests__/actionscript.test.js +1609 -0
  169. package/swf2js/__tests__/adpcm-audio.test.js +43 -0
  170. package/swf2js/__tests__/as2-compiler.test.js +153 -0
  171. package/swf2js/__tests__/as3-mixed-depth.test.js +498 -0
  172. package/swf2js/__tests__/authored-sprite-hit.test.js +118 -0
  173. package/swf2js/__tests__/authored-sprite-sizing.test.js +164 -0
  174. package/swf2js/__tests__/avm1-action-prefix.test.js +134 -0
  175. package/swf2js/__tests__/avm1-attach-movie.test.js +1151 -0
  176. package/swf2js/__tests__/avm1-boxhead-budget.test.js +73 -0
  177. package/swf2js/__tests__/avm1-cfg-bubble-tanks.test.js +101 -0
  178. package/swf2js/__tests__/avm1-cfg-mario-kart.test.js +184 -0
  179. package/swf2js/__tests__/avm1-cfg-mario.test.js +31 -0
  180. package/swf2js/__tests__/avm1-cfg-pacman.test.js +49 -0
  181. package/swf2js/__tests__/avm1-checkers-gameplay.test.js +122 -0
  182. package/swf2js/__tests__/avm1-clip-actions.test.js +2002 -0
  183. package/swf2js/__tests__/avm1-clone-drag.test.js +626 -0
  184. package/swf2js/__tests__/avm1-decompiler.test.js +102 -0
  185. package/swf2js/__tests__/avm1-dynamic-locals.test.js +159 -0
  186. package/swf2js/__tests__/avm1-formal-parameters.test.js +71 -0
  187. package/swf2js/__tests__/avm1-key-events.test.js +52 -0
  188. package/swf2js/__tests__/avm1-load-bitmap.test.js +75 -0
  189. package/swf2js/__tests__/avm1-loading-host-actions.test.js +764 -0
  190. package/swf2js/__tests__/avm1-multibyte-strings.test.js +63 -0
  191. package/swf2js/__tests__/avm1-pacman-gameplay.test.js +115 -0
  192. package/swf2js/__tests__/avm1-shape-hittest.test.js +311 -0
  193. package/swf2js/__tests__/avm1-shared-bodies.test.js +57 -0
  194. package/swf2js/__tests__/avm1-shared-runtime.test.js +1364 -0
  195. package/swf2js/__tests__/avm1-snake-gameplay.test.js +139 -0
  196. package/swf2js/__tests__/avm1-super.test.js +70 -0
  197. package/swf2js/__tests__/avm1-target-path.test.js +325 -0
  198. package/swf2js/__tests__/avm1-try.test.js +229 -0
  199. package/swf2js/__tests__/avm2-activation-closures.test.js +65 -0
  200. package/swf2js/__tests__/avm2-applytype.test.js +180 -0
  201. package/swf2js/__tests__/avm2-call-ops.test.js +232 -0
  202. package/swf2js/__tests__/avm2-callsuperid.test.js +231 -0
  203. package/swf2js/__tests__/avm2-class-initializer.test.js +219 -0
  204. package/swf2js/__tests__/avm2-custom-namespace.test.js +139 -0
  205. package/swf2js/__tests__/avm2-describe-type.test.js +96 -0
  206. package/swf2js/__tests__/avm2-dictionary.test.js +96 -0
  207. package/swf2js/__tests__/avm2-domain-memory.test.js +332 -0
  208. package/swf2js/__tests__/avm2-e4x.test.js +326 -0
  209. package/swf2js/__tests__/avm2-exceptions.test.js +81 -0
  210. package/swf2js/__tests__/avm2-findprop.test.js +110 -0
  211. package/swf2js/__tests__/avm2-getlex.test.js +166 -0
  212. package/swf2js/__tests__/avm2-global-slot.test.js +106 -0
  213. package/swf2js/__tests__/avm2-interface.test.js +95 -0
  214. package/swf2js/__tests__/avm2-multiname-precedence.test.js +148 -0
  215. package/swf2js/__tests__/avm2-named-namespace-types.test.js +106 -0
  216. package/swf2js/__tests__/avm2-optional-args.test.js +100 -0
  217. package/swf2js/__tests__/avm2-outer-scopes.test.js +101 -0
  218. package/swf2js/__tests__/avm2-package-internal-class.test.js +106 -0
  219. package/swf2js/__tests__/avm2-protected-namespace.test.js +105 -0
  220. package/swf2js/__tests__/avm2-protected.test.js +214 -0
  221. package/swf2js/__tests__/avm2-qwop-gameplay.test.js +116 -0
  222. package/swf2js/__tests__/avm2-runtime-namespaces.test.js +159 -0
  223. package/swf2js/__tests__/avm2-script-traits.test.js +89 -0
  224. package/swf2js/__tests__/avm2-shared-runtime.test.js +52 -0
  225. package/swf2js/__tests__/avm2-slot-ops.test.js +117 -0
  226. package/swf2js/__tests__/avm2-type-ops.test.js +224 -0
  227. package/swf2js/__tests__/bevel-filter.test.js +116 -0
  228. package/swf2js/__tests__/bitmap-button-mask.test.js +106 -0
  229. package/swf2js/__tests__/bitmap-data-draw.test.js +388 -0
  230. package/swf2js/__tests__/bitmap-decoder.test.js +108 -0
  231. package/swf2js/__tests__/bitmapdata-color-bounds.test.js +70 -0
  232. package/swf2js/__tests__/bitmapdata-copy-channel.test.js +91 -0
  233. package/swf2js/__tests__/bitmapdata-copy-pixels.test.js +136 -0
  234. package/swf2js/__tests__/bitmapdata-fill-compare.test.js +241 -0
  235. package/swf2js/__tests__/bitmapdata-filter.test.js +232 -0
  236. package/swf2js/__tests__/bitmapdata-hit-test.test.js +71 -0
  237. package/swf2js/__tests__/bitmapdata-merge.test.js +84 -0
  238. package/swf2js/__tests__/bitmapdata-palette-map.test.js +92 -0
  239. package/swf2js/__tests__/bitmapdata-pixels-io.test.js +198 -0
  240. package/swf2js/__tests__/bitmapdata-threshold.test.js +97 -0
  241. package/swf2js/__tests__/bitmapdata-vector.test.js +82 -0
  242. package/swf2js/__tests__/blur-filter.test.js +48 -0
  243. package/swf2js/__tests__/bundle-emitter.test.js +394 -0
  244. package/swf2js/__tests__/button-actions.test.js +370 -0
  245. package/swf2js/__tests__/button-color-transform.test.js +48 -0
  246. package/swf2js/__tests__/button-decoder.test.js +106 -0
  247. package/swf2js/__tests__/button-hit-test.test.js +825 -0
  248. package/swf2js/__tests__/button-scaling-grid.test.js +124 -0
  249. package/swf2js/__tests__/button-sound.test.js +105 -0
  250. package/swf2js/__tests__/bytearray-coercion.test.js +23 -0
  251. package/swf2js/__tests__/bytearray-object-serialization.test.js +380 -0
  252. package/swf2js/__tests__/cfg-switch-loop.test.js +103 -0
  253. package/swf2js/__tests__/clip-depth-mask.test.js +119 -0
  254. package/swf2js/__tests__/clipped-bitmap-fill.test.js +118 -0
  255. package/swf2js/__tests__/companion-swf.test.js +638 -0
  256. package/swf2js/__tests__/context-menu.test.js +149 -0
  257. package/swf2js/__tests__/convolution-filter.test.js +74 -0
  258. package/swf2js/__tests__/definefont4.test.js +280 -0
  259. package/swf2js/__tests__/display-displacement.test.js +161 -0
  260. package/swf2js/__tests__/display-list.test.js +80 -0
  261. package/swf2js/__tests__/display-mask-render.test.js +656 -0
  262. package/swf2js/__tests__/displayobject-stage.test.js +320 -0
  263. package/swf2js/__tests__/embedded-script-audio.test.js +131 -0
  264. package/swf2js/__tests__/embedded-swf.test.js +202 -0
  265. package/swf2js/__tests__/embedded-textfield.test.js +107 -0
  266. package/swf2js/__tests__/embedded-timeline-audio.test.js +182 -0
  267. package/swf2js/__tests__/embedded-timeline-input.test.js +420 -0
  268. package/swf2js/__tests__/embedded-timer-lifecycle.test.js +145 -0
  269. package/swf2js/__tests__/event-priority-order.test.js +125 -0
  270. package/swf2js/__tests__/event-weak-listeners.test.js +53 -0
  271. package/swf2js/__tests__/event-will-trigger.test.js +43 -0
  272. package/swf2js/__tests__/flash-text-engine-content.test.js +115 -0
  273. package/swf2js/__tests__/flash-text-engine-format.test.js +95 -0
  274. package/swf2js/__tests__/flash-text-engine-line.test.js +314 -0
  275. package/swf2js/__tests__/font-encoder.test.js +95 -0
  276. package/swf2js/__tests__/font-outline-text.test.js +659 -0
  277. package/swf2js/__tests__/glow-shadow-filter.test.js +68 -0
  278. package/swf2js/__tests__/graphics-bitmap-smoothing.test.js +32 -0
  279. package/swf2js/__tests__/graphics-fill-lifetime.test.js +36 -0
  280. package/swf2js/__tests__/graphics-gradient-matrix.test.js +53 -0
  281. package/swf2js/__tests__/graphics-stroke-hit-test.test.js +457 -0
  282. package/swf2js/__tests__/hit-test-primitives.test.js +414 -0
  283. package/swf2js/__tests__/input-events.test.js +714 -0
  284. package/swf2js/__tests__/integration/corpus.test.js +41 -0
  285. package/swf2js/__tests__/loader-embedded-swf.test.js +210 -0
  286. package/swf2js/__tests__/loader-info.test.js +81 -0
  287. package/swf2js/__tests__/local-connection.test.js +122 -0
  288. package/swf2js/__tests__/morph-focal-gradient.test.js +51 -0
  289. package/swf2js/__tests__/morph-topology.test.js +267 -0
  290. package/swf2js/__tests__/movie-data-codec.test.js +128 -0
  291. package/swf2js/__tests__/nellymoser-audio.test.js +84 -0
  292. package/swf2js/__tests__/opaque-background-cache.test.js +352 -0
  293. package/swf2js/__tests__/path-stream.test.js +81 -0
  294. package/swf2js/__tests__/place-object-filters.test.js +88 -0
  295. package/swf2js/__tests__/place-object3-decoder.test.js +116 -0
  296. package/swf2js/__tests__/place-object3-image.test.js +85 -0
  297. package/swf2js/__tests__/player-version.test.js +46 -0
  298. package/swf2js/__tests__/root-textfield.test.js +287 -0
  299. package/swf2js/__tests__/scaling-grid.test.js +183 -0
  300. package/swf2js/__tests__/shape-decoder.test.js +361 -0
  301. package/swf2js/__tests__/shape-line-style2.test.js +138 -0
  302. package/swf2js/__tests__/shape-nonscaling-stroke.test.js +131 -0
  303. package/swf2js/__tests__/shape-pixel-hint.test.js +101 -0
  304. package/swf2js/__tests__/simplebutton-pointer.test.js +1477 -0
  305. package/swf2js/__tests__/socket-offline.test.js +67 -0
  306. package/swf2js/__tests__/sound-avm1-stop.test.js +99 -0
  307. package/swf2js/__tests__/sound-envelope.test.js +110 -0
  308. package/swf2js/__tests__/sound-extract.test.js +168 -0
  309. package/swf2js/__tests__/sound-id3.test.js +283 -0
  310. package/swf2js/__tests__/sound-load.test.js +259 -0
  311. package/swf2js/__tests__/sound-mixer-spectrum.test.js +261 -0
  312. package/swf2js/__tests__/sound-stream-sprite.test.js +624 -0
  313. package/swf2js/__tests__/sound-transform.test.js +104 -0
  314. package/swf2js/__tests__/speex-audio.test.js +77 -0
  315. package/swf2js/__tests__/stage-noscale.test.js +45 -0
  316. package/swf2js/__tests__/swf-encoder.test.js +134 -0
  317. package/swf2js/__tests__/swflib-assemble.test.js +20 -0
  318. package/swf2js/__tests__/textfield-html-text.test.js +368 -0
  319. package/swf2js/__tests__/textfield-line-layout.test.js +339 -0
  320. package/swf2js/__tests__/textfield-programmatic-overlay.test.js +2506 -0
  321. package/swf2js/__tests__/textfield-scroll.test.js +79 -0
  322. package/swf2js/__tests__/textfield-selection.test.js +383 -0
  323. package/swf2js/__tests__/timeline-effect-surfaces.test.js +295 -0
  324. package/swf2js/__tests__/timeline-named-anchor.test.js +139 -0
  325. package/swf2js/__tests__/timeline-scenes.test.js +1723 -0
  326. package/swf2js/__tests__/urlloader-http-status.test.js +236 -0
  327. package/{src → swf2js}/cli.js +43 -11
  328. package/swf2js/compiler/as2-classes.js +156 -0
  329. package/swf2js/compiler/as2-parser.js +598 -0
  330. package/swf2js/compiler/avm1-codegen.js +897 -0
  331. package/swf2js/compiler/index.js +28 -0
  332. package/{src → swf2js}/decoder/button-decoder.js +3 -1
  333. package/swf2js/decoder/png.js +114 -0
  334. package/{src → swf2js}/decoder/shape-decoder.js +20 -10
  335. package/{src → swf2js}/decoder/tag-decoder.js +5 -3
  336. package/{src → swf2js}/decoder/tag-types.js +4 -0
  337. package/swf2js/decompiler/avm1-decompiler.js +1138 -0
  338. package/{src → swf2js}/emitter/asset-encoder.js +66 -113
  339. package/{src → swf2js}/emitter/bundle-emitter.js +209 -78
  340. package/swf2js/emitter/external-resources.js +39 -0
  341. package/swf2js/emitter/movie-data-codec.js +91 -0
  342. package/swf2js/encoder/bit-writer.js +182 -0
  343. package/swf2js/encoder/shape-encoder.js +310 -0
  344. package/swf2js/encoder/swf-builder.js +639 -0
  345. package/swf2js/encoder/swf-writer.js +55 -0
  346. package/{src/runtime/swflib/assemble.js → swf2js/runtime/assemble-swooflib.js} +4 -3
  347. package/{src → swf2js}/runtime/avm1-runtime.js +102 -63
  348. package/{src → swf2js}/runtime/index.js +1 -1
  349. package/{src → swf2js}/runtime/movie-runtime.js +28 -2
  350. package/{src → swf2js}/transpiler/actionscript.js +82 -19
  351. package/{src → swf2js}/transpiler/avm1/avm1-opcodes.js +5 -3
  352. package/{src → swf2js}/transpiler/avm1/avm1-transpiler.js +69 -6
  353. package/{src → swf2js}/transpiler/avm2/avm2-transpiler.js +1 -1
  354. package/{src → swf2js}/transpiler/timeline/display-list.js +41 -22
  355. package/{src → swf2js}/transpiler/timeline/timeline-codegen.js +97 -36
  356. package/swooflib/README.md +569 -0
  357. package/swooflib/adpcm.js +147 -0
  358. package/{src/runtime/swflib → swooflib}/builtins.js +6 -0
  359. package/{src/runtime/swflib → swooflib}/context-menu.js +7 -1
  360. package/swooflib/control-definitions.js +42 -0
  361. package/swooflib/control-widget.js +763 -0
  362. package/swooflib/controls.js +300 -0
  363. package/{src/runtime/swflib → swooflib}/display.js +16 -10
  364. package/{src/runtime/swflib → swooflib}/events.js +11 -0
  365. package/{src/runtime/swflib → swooflib}/flash.js +6 -5
  366. package/{src/runtime/swflib → swooflib}/graphics.js +81 -19
  367. package/{src/runtime/swflib → swooflib}/input.js +12 -14
  368. package/{src/runtime/swflib → swooflib}/loader.js +52 -22
  369. package/swooflib/movie-network.js +86 -0
  370. package/swooflib/path-stream.js +169 -0
  371. package/{src/runtime/swflib → swooflib}/render.js +3 -13
  372. package/{src/runtime/swflib → swooflib}/sound.js +25 -2
  373. package/{src/runtime/swflib → swooflib}/stage.js +3 -3
  374. package/swooflib/stream-time.js +21 -0
  375. package/{src/runtime/swflib → swooflib}/system.js +88 -37
  376. package/{src/runtime/swflib → swooflib}/text-paint.js +14 -3
  377. package/{src/runtime/swflib → swooflib}/text.js +8 -0
  378. package/swooflib/xml-node.js +53 -0
  379. package/src/emitter/timeline-data-codec.js +0 -58
  380. /package/{src → swf2js}/decoder/symbol-table.js +0 -0
  381. /package/{src → swf2js}/emitter/embedded-swf.js +0 -0
  382. /package/{src → swf2js}/emitter/font-encoder.js +0 -0
  383. /package/{src → swf2js}/model/swf-document.js +0 -0
  384. /package/{src → swf2js}/model/transpile-result.js +0 -0
  385. /package/{src → swf2js}/parser/bit-reader.js +0 -0
  386. /package/{src → swf2js}/parser/decompressor.js +0 -0
  387. /package/{src → swf2js}/parser/swf-parser.js +0 -0
  388. /package/{src → swf2js}/pretty-printer/pretty-printer.js +0 -0
  389. /package/{src → swf2js}/runtime/avm2-runtime.js +0 -0
  390. /package/{src → swf2js}/runtime/embedded-movie-runtime.js +0 -0
  391. /package/{src → swf2js}/transpiler/avm1/avm1-ir.js +0 -0
  392. /package/{src → swf2js}/transpiler/avm1/avm1-rewrite.js +0 -0
  393. /package/{src → swf2js}/transpiler/avm2/abc-reader.js +0 -0
  394. /package/{src → swf2js}/transpiler/cfg-structurer.js +0 -0
  395. /package/{src → swf2js}/util/diagnostics.js +0 -0
  396. /package/{src → swf2js}/util/logger.js +0 -0
  397. /package/{src/runtime/swflib → swooflib}/bitmap-image.js +0 -0
  398. /package/{src/runtime/swflib → swooflib}/bitmap.js +0 -0
  399. /package/{src/runtime/swflib → swooflib}/bytearray.js +0 -0
  400. /package/{src/runtime/swflib → swooflib}/compiled-swf.js +0 -0
  401. /package/{src/runtime/swflib → swooflib}/cursor-flag.js +0 -0
  402. /package/{src/runtime/swflib → swooflib}/dictionary.js +0 -0
  403. /package/{src/runtime/swflib → swooflib}/filters.js +0 -0
  404. /package/{src/runtime/swflib → swooflib}/geom.js +0 -0
  405. /package/{src/runtime/swflib → swooflib}/glyph-metrics.js +0 -0
  406. /package/{src/runtime/swflib → swooflib}/host.js +0 -0
  407. /package/{src/runtime/swflib → swooflib}/inherit.js +0 -0
  408. /package/{src/runtime/swflib → swooflib}/marks.js +0 -0
  409. /package/{src/runtime/swflib → swooflib}/matrix3d.js +0 -0
  410. /package/{src/runtime/swflib → swooflib}/pointer-bridge.js +0 -0
  411. /package/{src/runtime/swflib → swooflib}/projection.js +0 -0
  412. /package/{src/runtime/swflib → swooflib}/sprite-drag.js +0 -0
  413. /package/{src/runtime/swflib → swooflib}/stage-ref.js +0 -0
  414. /package/{src/runtime/swflib → swooflib}/text-field.js +0 -0
  415. /package/{src/runtime/swflib → swooflib}/transform.js +0 -0
  416. /package/{src/runtime/swflib → swooflib}/xml.js +0 -0
@@ -0,0 +1,268 @@
1
+ # File Support
2
+
3
+ ## Purpose
4
+
5
+ Studio is served by `studio/server.js` (see [tasks.md](./tasks.md) §9). The server can therefore store projects and media on disk and convert SWF files with the existing parser and decoder. This section defines how users upload images and audio, save and open projects, open or import SWF movies, and export SWF movies.
6
+
7
+ Portable JSON import and export remain available. A served project folder and an exported JSON file describe the same document. They differ only in how the document is split and where media bytes live.
8
+
9
+ ## Requirements
10
+
11
+ ### 6. Files, storage, and SWF
12
+
13
+ 1. Users SHALL be able to upload image and audio files to the open project by choosing files or dropping them on the Library or stage. Each upload SHALL show its progress and report its outcome. A failed upload SHALL leave the project unchanged.
14
+ 2. The server SHALL store each uploaded file once per project and identify it by content hash. Uploading identical bytes again SHALL reuse the existing asset.
15
+ 3. The server SHALL accept only image and audio formats it can identify from the file's bytes, within configured size limits. Rejections SHALL name the file and the reason.
16
+ 4. Users SHALL be able to save the current project to the server, save it under a new name, and open a saved project from a list. Ctrl/Cmd+S SHALL save.
17
+ 5. The editor SHALL show when the project has unsaved changes and warn before an action or page unload would discard them.
18
+ 6. Saving SHALL be atomic. A save based on an outdated revision SHALL be rejected with a conflict instead of overwriting newer work.
19
+ A save SHALL write only the scenes and symbols that changed since the previous save.
20
+ Between explicit saves, the editor SHALL record edits progressively to a journal on the server. Opening a project with journal entries newer than its last save SHALL offer to recover them.
21
+ 7. Exporting a served project SHALL produce a self-contained JSON file with embedded media. Importing such a file SHALL store its media as server assets.
22
+ 8. Users SHALL be able to open a SWF file as a new project and import a SWF file's library into the current project.
23
+ 9. SWF conversion SHALL produce an ordinary editable Studio project. It SHALL NOT keep a dependency on the SWF file or on the transpiler's compiled timeline format.
24
+ 10. SWF conversion SHALL report every feature it approximated or dropped. The report SHALL list counts and examples and SHALL remain available after the import.
25
+ 11. Malformed, oversized, or unsupported files SHALL be rejected with a visible error and SHALL NOT affect the server or the open project.
26
+ 12. Project data SHALL be compressed in transfer, and reopening a project SHALL download only the scenes and symbols that changed since the copy the browser holds.
27
+
28
+ ## Storage layout
29
+
30
+ The server takes a projects directory with `--projects <dir>`. The default is `./studio-projects` under the current working directory.
31
+
32
+ Each project is a folder. The document is split into one file per scene and symbol, so a save writes only what changed and the files stay readable and diffable.
33
+
34
+ ```
35
+ <projects>/
36
+ <projectId>/
37
+ project.json # Commit point: stage, name, revision, scene/symbol order, asset entries, part hashes
38
+ scenes/
39
+ <sceneId>.<hash>.json # One scene: layers, elements, keyframes, events, audio clips
40
+ symbols/
41
+ <symbolId>.<hash>.json # One symbol definition
42
+ assets/
43
+ <sha256>.<ext> # Immutable media bytes
44
+ journal.ndjson # Edits recorded since the last save
45
+ ```
46
+
47
+ Project IDs are lowercase slugs (`[a-z0-9][a-z0-9-]{0,63}`). Scene and symbol IDs must match `[A-Za-z0-9_-]{1,64}` before they are used as file names. The server never builds a path from any other user input.
48
+
49
+ ### Parts and the commit point
50
+
51
+ `project.json` lists every part with its content hash:
52
+
53
+ ```js
54
+ {
55
+ format: 'swoof-studio-project', version: 2, revision: 14, name, stage,
56
+ scenes: [{ id, file: 'scenes/s1.<sha256>.json', hash: '<sha256>' }],
57
+ symbols: [{ id, file: 'symbols/sym1.<sha256>.json', hash: '<sha256>' }],
58
+ assets: [ /* asset entries, below */ ]
59
+ }
60
+ ```
61
+
62
+ A save runs in this order:
63
+
64
+ 1. Write each changed part to a temporary file and rename it into place under a new name, `scenes/<id>.<hash>.json`.
65
+ 2. Write the new `project.json` through a temporary file and `rename`. This step commits the save.
66
+ 3. Truncate the journal, then delete part files that the new `project.json` no longer references.
67
+
68
+ A crash before step 2 leaves the previous `project.json` pointing at its own unchanged part files. A crash after step 2 leaves only unreferenced files, which the next save removes. Reading a project loads `project.json` and then the parts it names, verifying each hash.
69
+
70
+ ### Journal
71
+
72
+ The editor computes a JSON Patch (RFC 6902) between the last recorded document and the current undo-history snapshot, excluding media. It appends the patch to `journal.ndjson` no more than once every two seconds, and also before the page unloads.
73
+
74
+ ```js
75
+ { base: 14, seq: 3, time: '2026-12-03T10:15:02Z', ops: [{ op: 'replace', path: '/scenes/0/elements/2/keyframes/1/x', value: 140 }] }
76
+ ```
77
+
78
+ Each entry names the revision it applies to and a sequence number. The server rejects an entry whose `base` is not the current revision or whose `seq` does not follow the previous entry. Entries are appended with a single `write` call per line. A truncated final line is ignored on replay.
79
+
80
+ An explicit Save commits the project and clears the journal. On open, the server reports any journal entries for the current revision. The editor offers to recover them, replays the patches onto the saved document, validates the result with `parseProjectJson`, and marks the project as unsaved. Discarding clears the journal.
81
+
82
+ Journal patches use paths into the whole-document form that `serializeProject` produces. The server never interprets their content beyond replay.
83
+
84
+ ### Portable formats
85
+
86
+ - **Export JSON** writes the whole document as one file with embedded `data:` media, as today. Import accepts it and stores its media as server assets.
87
+ - Importing reads both the single-file format (`version` 1) and project folders (`version` 2).
88
+ - A zipped project folder (`.swoof`) for sharing is deferred.
89
+
90
+ A stored asset entry replaces the embedded `data` URL with a reference:
91
+
92
+ ```js
93
+ { id, name, kind: 'image' | 'audio', type: 'image/png', hash: '<sha256>', bytes: 12345, src: 'assets/<sha256>.png' }
94
+ ```
95
+
96
+ An audio asset may also carry `linkage`, the name scripts use to attach it (`Sound.attachSound`).
97
+
98
+ `readAssets` SHALL accept either form: `src` + `hash` for served projects, or `data` for portable JSON. The editor decodes media from `/api/projects/<id>/assets/<hash>` and keeps the decoded-media cache keyed by asset.
99
+
100
+ Saving removes asset files that the saved project and the journal no longer reference. Bytes uploaded since the last save remain until the next save or until 24 hours have passed.
101
+
102
+ ## Server API
103
+
104
+ All routes are under `/api/` and exchange JSON, except for raw uploads and media downloads. Errors use `{ error: { code, message } }` with a matching HTTP status.
105
+
106
+ | Route | Purpose |
107
+ |---|---|
108
+ | `GET /api/projects` | List `{ id, name, revision, modified, bytes }` |
109
+ | `POST /api/projects` | Create a project from a body `{ name, project? }`. Returns `{ id, revision }` |
110
+ | `GET /api/projects/:id?view=manifest` | Open a saved project. Returns its revision, conversion reports, pending journal and a manifest with the stage, asset references and ordered `{ id, hash }` entries for scenes, symbols and scripts |
111
+ | `GET /api/projects/:id/parts/:hash` | Read one part as JSON. Its SHA-256 identifies the decoded response bytes. Browsers can cache this URL privately for one year |
112
+ | `GET /api/projects/:id` | Return the assembled document and part hashes for existing clients. Both project views set `ETag: "<revision>"` |
113
+ | `PUT /api/projects/:id` | Save. Requires `If-Match: "<revision>"`. The body is `{ project, parts }`: the `project.json` fields and the changed scenes and symbols only. Each unchanged part is listed by ID and its current hash. A stale revision returns 409 with the current revision. An unknown or mismatched hash returns 422 |
114
+ | `POST /api/projects/:id/journal` | Append one journal entry. Returns 409 when `base` or `seq` is out of date |
115
+ | `DELETE /api/projects/:id/journal` | Discard pending journal entries |
116
+ | `DELETE /api/projects/:id` | Delete a project after confirmation in the editor |
117
+ | `POST /api/projects/:id/assets` | Upload one file as the raw request body. Send the file name in `X-File-Name` (URI-encoded). Returns the asset entry |
118
+ | `GET /api/projects/:id/assets/:hash` | Serve immutable media bytes |
119
+ | `POST /api/swf/convert` | Upload a SWF as the raw body. Returns `{ project, report }` with assets already stored in a staging project |
120
+ | `POST /api/projects/:id/export/swf` | Export the saved revision as SWF. Returns the file, with the export report in `X-Swoof-Report`. Pass `?bundle=1` to also run swf2js and return the HTML bundle as a zip |
121
+
122
+ JSON responses negotiate zstd (when available in Node), Brotli and gzip using `Accept-Encoding`. They include `Vary: Accept-Encoding`. Ordinary project saves and journal writes use gzip in browsers that support `CompressionStream`. A page-unload journal flush dispatches immediately with an uncompressed keepalive body. The server also accepts plain JSON and applies its configurable `jsonLimit` (256 MiB by default) to the decoded project body.
123
+
124
+ Uploads use raw bodies, one file per request, so the server needs no multipart parser. The editor sends several files concurrently, up to four at a time.
125
+
126
+ ### Limits and validation
127
+
128
+ - Configurable limits, with defaults of 50 MB per media file, 100 MB per SWF, and 256 MB of decompressed SWF data. The server stops reading at the limit and responds with 413.
129
+ - Media is identified by magic bytes: PNG, JPEG, GIF, WebP, AVIF, BMP, WAV (RIFF/WAVE), MP3 (ID3 or a frame sync), Ogg, FLAC, and M4A/AAC (`ftyp`). The declared type and extension are hints only.
130
+ - SVG is accepted only after the server removes scripts, event-handler attributes, external references, and `foreignObject`. Every served asset carries `X-Content-Type-Options: nosniff` and `Content-Security-Policy: sandbox`.
131
+ - Writes go to a temporary file in the same directory followed by `rename`, so a crash never leaves a partial `project.json` or asset.
132
+ - The server listens on loopback by default. Binding a non-loopback `--host` prints a warning because the API has no authentication.
133
+
134
+ ## Editor workflow
135
+
136
+ - **Top bar:** Open, Save, and Save as join Import and Export. The title shows the project name and an unsaved-changes marker.
137
+ - **Dirty state:** the undo history records the revision at the last save. The project is dirty whenever the current history position differs from it. The editor tracks which scenes and symbols changed since the last save so Save sends only those parts.
138
+ - **Autosave:** edits are journaled in the background. The status line shows "Saved", "Unsaved changes (recoverable)", or a visible error when the journal cannot be written.
139
+ - **Recovery:** opening a project with pending journal entries shows Recover and Discard before the project becomes editable.
140
+ - **Library:** Upload files keeps the current picker and also accepts drag and drop. Dropping a file on the stage places an image at the drop point, or a sound at the playhead.
141
+ - **Unsaved projects:** uploading into a project that has never been saved first creates it on the server, using a generated name the user can change on first save.
142
+ - **Open SWF:** the import report appears in a dialog after conversion and stays available from the Library until the project is closed.
143
+ - **Import:** one file picker (or a drop on the dialog) for Studio projects, Lottie files, SWF movies and SVG images, told apart by content. A SWF is converted as Open SWF does; images and sounds join the library as Upload files does. See [svg-import.md](./svg-import.md) (requirement 13.1).
144
+
145
+ ## SWF conversion
146
+
147
+ The server runs the conversion with `swf2js/parser/swf-parser.js` and `swf2js/decoder/tag-decoder.js`. A new module, `studio/server/swf-import.js`, maps the decoded tags and symbol table to Studio's document model. It reuses the shape and button decoders. It calls the AVM1 transpiler only to store a readable copy of each kept script, and does not invoke the bundle emitter.
148
+
149
+ **Open SWF** creates a new project. **Import SWF** adds the converted symbols and assets to the current project's library without changing its scenes. Imported IDs are prefixed to avoid collisions.
150
+
151
+ | SWF | Studio |
152
+ |---|---|
153
+ | Header size, frame rate, `SetBackgroundColor` | Stage settings. Twips become pixels |
154
+ | Root timeline; `DefineSceneAndFrameLabelData` scenes | Scenes with their frame ranges, or one scene if none are declared |
155
+ | Depths in a timeline | Layers ordered by depth (`Depth N`, or the instance name) |
156
+ | `PlaceObject*` / `RemoveObject*` per frame | Element keyframes and blank keyframes. Repeated appearances of the same unmasked artwork at a depth can share one track, with a blank key between exposures. |
157
+ | Per-frame placements of a tween | Merged back into tweens (`studio/server/tween-recovery.js`): a run of per-frame changes becomes one linear, ease-in, ease-out or ease-in-out tween when that tween reproduces every frame of the run within 1/20 px, 0.1° and 1/255 opacity. Other changes stay hold keyframes |
158
+ | Matrix | Position, scale, rotation, and skew keys; negative scale becomes keyframe `mirror`. Positions may lie up to ±100000 px from the stage. Scales below 1% import as hidden (opacity 0) at Studio's smallest scale: always for shapes and bitmaps, and for movie clips and text only in movies without ActionScript, since a script may grow a clip from scale 0 without changing its opacity (those stay at 1% and are reported). Scales above 10000% are clamped and reported |
159
+ | Color transform | Opacity from the alpha multiplier; the other channels become the keyframe `colorTransform` (multipliers and offsets, tweened) |
160
+ | `DefineShape1–4` | One closed or open path element per fill or line style. A multi-style shape becomes a symbol that contains those paths. Contours inside another contour of the same fill are kept as `subpaths` and filled even-odd (holes), or nonzero when the shape sets `UsesFillWindingRule`. Line ends, corners and the miter limit are kept ([stroke-style.md](./stroke-style.md)) |
161
+ | Solid fills, strokes | Fill, stroke and native stroke widths up to 3276.75 pixels. Imported vector contours use compact anchor streams until opened for drawing or editing. |
162
+ | Gradients | Fill and stroke styles retain linear or radial gradients, stop colors and alpha, spread, interpolation and placement. Filled lines publish as native LINESTYLE2 in SWF 8 and later. |
163
+ | Bitmap fills | Bitmap elements when the fill is an axis-aligned rectangle. A rectangle that shows part of its image (a clipped fill larger than the shape) keeps that part as the bitmap's `crop` source rectangle. Tiled and non-rectangular fills keep their clip paths, bitmap placement, repeat and smoothing. Bitmap strokes keep the same settings on their line style |
164
+ | `DefineBits*` / `DefineBitsLossless*` | PNG or JPEG image assets. JPEG with alpha (`JPEG3/4`) is converted to PNG |
165
+ | `DefineMorphShape*` | Editable paths sampled at each placed ratio. Repeated ratios share artwork. SWF export preserves the original morph and ratio for unchanged artwork and writes edited exposures as ordinary shapes. |
166
+ | `DefineSprite` | Symbol definition with its own layers and complete timeline. Scenes and sprites support up to 65,535 frames. The aggregate root timeline of a native SWF has the same limit. |
167
+ | `DefineButton*` | A button symbol (`button: true`) with Up, Over, Down and Hit as frames 1–4. Buttons with no art (keyboard listeners) are kept |
168
+ | `DefineText`, `DefineEditText` | Static text with embedded glyphs becomes outline paths, one per run. Other text becomes text elements with the font's name, size, color, and alignment; field settings (variable, HTML, editing flags) go to `element.field`. Text fields with embedded fonts keep their native font ID and outline setting. Studio loads a browser font subset for editing when the embedded font supplies its glyph outlines and metrics. |
169
+ | `DefineSound`, `StartSound`, `StartSound2` | Imported event clips retain sample in/out points, exact repeats, stereo envelope points, overlap and stop flags. Class-linked cues retain their SymbolClass name. ADPCM and raw PCM become WAV. MP3 is kept. |
170
+ | `DefineButtonSound` | Up to four button transition sounds, each with its own sound settings, play on the shared Flash runtime and publish as native button sounds. |
171
+ | Sound streams | One MP3 or WAV asset per stream, with a clip over its frames, on the root timeline or in a symbol. Native export preserves the original stream header and frame blocks when the clip is unchanged. Flash writes an empty stream header into most symbols; only streams with sound data are converted or reported |
172
+ | `ExportAssets` on a sound | The audio asset keeps the export name as `linkage`, so scripts find it with `new Sound().attachSound(name)` |
173
+ | `FrameLabel` | Timeline `labels` |
174
+ | `ExportAssets` linkage names | Symbol `linkage`, so `attachMovie` finds the symbol in Preview |
175
+ | AVM1 `stop`, `play`, `gotoAndPlay` / `gotoAndStop` with a constant frame or label | Typed frame events (`stop`, `play`, `gotoFrame`) |
176
+ | Button `on (release)` with a single constant goto | `buttonAction` |
177
+ | Other AVM1 (frame, button, clip, and init actions) | Kept as scripts at their attachment point; Preview runs them with the swf2js player. See [actionscript.md](./actionscript.md) |
178
+ | AVM2 (`DoABC`), `SymbolClass` | Preserved at their root frames, including the document class and class-linked artwork, sounds, fonts and binary assets. Preview and HTML export run these classes on the swf2js player. Native SWF export retains the bytecode and AVM2 file flag. |
179
+ | Filters and blend modes | Imported placements retain Flash filter lists and blend modes for Preview and publishing. |
180
+ | Masks (`clipDepth`) | `maskId` on the elements in the clipped depth range, linked to the first closed vector placed as a mask at that depth. Masks swapped at the same depth and clip depth, shapes or symbols, keep clipping the same targets in the editor and in Preview (the mask slot, [swooflib-integration.md](./swooflib-integration.md)). Every mask keeps its SWF `clipDepth`, so Preview clips the same depth range as Flash. A depth whose masks are never a closed vector (text, bitmaps, only symbols) is masked in Preview only |
181
+ | Flash components (Flash MX `F*Symbol`, v2 `mx.controls`) | Symbols keep their code; `symbol.component` names the kind, and each instance's parameter handler becomes `element.component.parameters`, edited in the inspector. See [controls.md](./controls.md) |
182
+ | `DefineSprite` with no content | Kept as an empty symbol: scripts draw into it or attach symbols to it |
183
+ | Nine-slice scaling and menu buttons | Preview and native export retain the symbol’s scaling rectangle and the button’s menu tracking flag. |
184
+ | Embedded video | Listed in the conversion report. |
185
+
186
+ The report groups entries by severity: **approximated** (converted with visible differences) and **dropped** (not converted). Each entry carries the feature, an occurrence count, and up to five locations such as `Scene 1, frame 12, depth 3`.
187
+
188
+ ## SWF export
189
+
190
+ ### Standalone HTML export
191
+
192
+ In **Export project**, the **Web page (HTML)** format publishes the current document, including unsaved edits, with the swf2js player, compiled scripts and project media embedded in one HTML file. Authored controls use the same widgets as scripted Preview. The file can be opened locally or hosted as a static page. When an imported AS3 movie matches an installed package in `archive/Swf`, Preview and HTML use its `.companions.json` mappings, including Raze 2’s offline Armor Games component. Other external URLs still refer to their original resources.
193
+
194
+ ### 7. Requirements
195
+
196
+ 1. Users SHALL be able to export the project as a SWF file: the project as it is in the editor, unsaved edits included, as Preview shows it.
197
+ 1. Export SHALL be built from the same conversion as scripted Preview (`buildProjectMovie`), so what Preview shows is what the SWF contains. The encoder writes that display list and its script tags as SWF tags.
198
+ 2. Export preserves imported AVM1 bytecode and its linked action records, imported AVM2 blocks and their class bindings. It compiles authored actions and component parameters as Preview does.
199
+ 3. THE SWF version SHALL be the version of the project's scripts (at least 6), and 8 for projects without scripts. Features that need SWF 8 (line caps and joins, filters, blend modes) in an older movie SHALL be left out and reported.
200
+ 4. Sound SHALL be written from the same cues Preview plays: each audio asset in use as a `DefineSound`, each clip start and stop as a `StartSound` in the timeline that holds the clip, and linkage names in `ExportAssets`. SWF holds MP3 and PCM at 5.5, 11, 22 or 44 kHz only. PCM or float WAV at any other rate, depth or channel count SHALL be resampled to the nearest SWF rate at or above its own (44.1 kHz at most) as 16-bit PCM, mono or stereo, and reported as approximated. Other sounds (compressed audio at rates SWF cannot hold) SHALL be reported as dropped.
201
+ 5. Scenes SHALL play in order on the root timeline, as in Flash. Scene names are kept as frame labels where the frame has no label of its own, so AVM1 scripts can jump to them. AVM1 SWFs carry no scene table, so Studio SHALL record each scene's name, first frame and transition in its authoring metadata (`Metadata` tag, rows `['n', frame, name, transition]`), and SWF import SHALL split the root timeline into those scenes again when the metadata still matches the file.
202
+ 6. Text SHALL be written with embedded outlines (`DefineFont3`, fields set to use outlines) when the font is installed where the server runs, has TrueType (`glyf`) outlines and allows embedding (OS/2 `fsType` is not "restricted"). The embedded set holds the characters the project's text uses, printable ASCII (scripts can change any text), and Latin-1 for editable fields. Other fonts SHALL stay device fonts and be reported: not installed, PostScript (CFF) outlines, or licence. Rotated or skewed text SHALL be reported only when its font could not be embedded, because Flash Player does not draw turned device text.
203
+ 7. Scene entry transitions SHALL play in SWF 8 movies as Preview plays them: each Studio scene jump to a scene with a transition first calls a helper (`studio/server/swf-transition-runtime.as`, compiled into the first root frame) that draws the stage into a `BitmapData`, lays it over the incoming scene at the top depth, and fades it (crossfade) or slides a mask across it (wipe) over the transition's frames with its easing. A jump within the target scene has no transition. Movies whose scripts keep them below SWF 8 SHALL cut and report it; jumps made by ActionScript code SHALL be reported as cuts. Scripted Preview and HTML export do not use the helper.
204
+ 2. Users SHALL be able to publish the current project as a standalone HTML file. The server passes the project’s display list, scripts and media directly to the swf2js emitter.
205
+ 3. Export SHALL report every Studio feature it approximated or dropped, using the same report format as SWF import.
206
+ 4. Every exported SWF SHALL parse and decode with swf2js without errors. Re-importing it SHALL reproduce the stage, scenes, layer order, keyframe poses, and supported actions.
207
+
208
+ ### Where the code lives
209
+
210
+ SWF writing is a proper encoder in swf2js, built as the write-side mirror of the existing reader. swooflib is the browser runtime that ships in every generated bundle, so it stays free of authoring and encoding code. [architecture.md §8](./architecture.md#8-swf-encoder-in-swf2js-planned) defines the encoder's layering and design rules.
211
+
212
+ ```
213
+ swf2js/encoder/ # Generic SWF encoders. No knowledge of Studio, no Node built-ins
214
+ bit-writer.js # Mirror of bit-reader: UB/SB/FB, UI8–UI32, FIXED/FIXED8, EncodedU32, RECT, MATRIX, CXFORM(A), RGB(A), strings
215
+ swf-writer.js # Header, FWS/CWS framing with an injected deflate, tag headers, frame count, length
216
+ tag-encoder.js # Typed tag structures (decoder/tag-types.js) → tag bodies, dispatched by type
217
+ shape-encoder.js # SHAPEWITHSTYLE (DefineShape1–4, DefineMorphShape) from a path model with fill and line styles
218
+ button-encoder.js # DefineButton2 records, conditions, and action blocks
219
+ avm1-assembler.js # Action records from an instruction list, with labels resolved to branch offsets
220
+ swf-builder.js # Character IDs, depths, per-frame display-list diffing, sprites, labels, scenes
221
+ studio/server/
222
+ swf-export.js # Studio project → SwfBuilder calls
223
+ font-files.js # Installed TrueType fonts: folders, name/OS2 lookup, cmap, glyf outlines (no dependencies)
224
+ ```
225
+
226
+ The encoder accepts the same typed structures that the decoder produces and uses the same `TAG` codes. Where decoding is lossy (shapes become draw lists), `tag-types.js` documents an explicit encoder input. Every encoder is tested by writing a structure, reading it back with `swf2js/parser` and `swf2js/decoder`, and comparing the result. Bit-level primitives also get fast-check property tests.
227
+
228
+ `demos/source/swf-writer.mjs` and `compile-avm1.mjs` were one-time scripts. They are reference material only: they confirm working layouts for PlaceObject2 move semantics, clipped bitmap fills, JPEG3 alpha, uncompressed PCM sounds, and DefineButton2 key conditions. The seven demo SWFs they produced serve as decode and import fixtures.
229
+
230
+ ### Mapping
231
+
232
+ | Studio | SWF |
233
+ |---|---|
234
+ | Stage size, background, frame rate | Header RECT in twips, `SetBackgroundColor`, frame rate (8.8) |
235
+ | Scenes | One root timeline with consecutive frame ranges. Each scene's start frame becomes a frame label, and the scene table (names, starts, transitions) goes in the authoring metadata so re-import restores the scenes (requirement 7.1.5) |
236
+ | Layers and stacking order | Depths. Each element gets its own depth, and depths are ordered by layer order and then group order |
237
+ | Element exposures and blank keyframes | `PlaceObject2/3` when an exposure begins, `RemoveObject2` when it ends |
238
+ | Keyframe poses and tweens | A `PlaceObject` matrix and color transform on every frame of the span, with tweens sampled per frame. Hold spans write only at keys |
239
+ | Rectangles, ellipses, polygons, paths | `DefineShape3/4` with quadratic segments. Cubic segments are split into quadratics within 0.1 px |
240
+ | Linear and radial gradients | Gradient colors, stop positions and transparency, with a matrix from the object-local gradient |
241
+ | Fill/stroke style tweens | A new shape character for each distinct style, placed per frame |
242
+ | Text and editable text | `DefineEditText`. Editable fields remain editable and read-only text is set read-only. Fonts installed on the server are embedded as `DefineFont3` outlines (requirement 7.1.6), found by `studio/server/font-files.js` in the system font folders; other text uses device fonts. Known gap: Flash places a field's first baseline 2 px + the font ascent below its top, while the editor places it about 0.16 em higher, so exported text sits slightly lower in Flash Player and Ruffle |
243
+ | Shape labels (text on a rectangle, ellipse or path, such as a button caption) | A one-frame sprite: the shape, then a read-only `DefineEditText` with the label, centered vertically as the editor draws it. Scripted Preview and HTML export use the same characters |
244
+ | Bitmaps | `DefineBitsLossless2` for PNG and `DefineBitsJPEG2` for JPEG, used as clipped bitmap fills in fit, crop, or stretch layout |
245
+ | Audio clips | Event clips use `DefineSound` and `StartSound` or `StartSound2`. Imported synchronized clips write their stream header and packets on the owning root or sprite timeline. |
246
+ | Symbols and instances | `DefineSprite`. Inherited and looping playback follow SWF behavior. Play once and single-frame modes add `stop` actions |
247
+ | Groups | A `DefineSprite` with an identity matrix holding the members |
248
+ | Masks | A clipping depth for each mask source covering its targets. Targets that are not consecutive in depth are reported |
249
+ | Effects | Blur, glow, and drop-shadow filters with `PlaceObject3` |
250
+ | Frame events: `play`, `stop`, `gotoFrame`, `gotoScene` | `DoAction` with `ActionPlay`, `ActionStop`, and `ActionGotoFrame`/`ActionGotoLabel` followed by play or stop |
251
+ | `show`, `hide`, `toggleVisibility` | `DoAction` setting `_visible` on a named instance |
252
+ | Click buttons | `DefineButton2` with up, over, down, and hit states from the artwork, and an `OverDownToOverUp` action |
253
+ | Touch tap, swipe, key triggers | Key triggers map to button key conditions where SWF supports them. Swipes and touch-only taps are reported |
254
+ | Scene transitions | A bitmap snapshot of the outgoing stage that fades or wipes away (SWF 8, requirement 7.1.7). Needs a player with `BitmapData.draw` (Flash Player 8+, Ruffle's WebGL/wgpu renderers; Ruffle's canvas renderer draws it black). Reported where the movie cuts instead |
255
+ | Preview-only state (typed field values, overrides) | Not exported |
256
+
257
+ ## Verification
258
+
259
+ - **Server tests (`node --test`):** routes, revision conflicts, partial saves writing only changed parts, crash simulation between save steps, journal append order and recovery, truncated journal lines, atomic writes, path and ID rejection, size limits, magic-byte checks, SVG sanitizing, and asset deduplication and cleanup.
260
+ - **Conversion tests:** run on the seven SWFs in `demos/` and small fixture SWFs. Their build scripts in `demos/source/` say what each movie contains, which gives exact expectations: key-condition buttons, clip-depth masks, bitmap fills, JPEG alpha, PCM sound, bound text fields, and compiled AVM1 game scripts that retain their bytecode and attachment points. Each fixture asserts its project validates with `parseProjectJson`, its expected element and keyframe counts, and its report entries.
261
+ - **Encoder tests (vitest, `swf2js/__tests__/`):** round-trip every encoder through the parser and decoder, including bit-field edge cases, signed values, and long tag headers. Use fast-check for bit-writer, RECT, MATRIX, and CXFORM properties. Rebuild movies equivalent to the demo SWFs with `SwfBuilder` and compare decoded tag lists. Byte identity with the one-time scripts is not a goal.
262
+ - **Export tests:** export all six examples, decode them without diagnostics errors, re-import them, and compare stage, scenes, depth order, sampled poses, and actions. Transpile one exported movie to an HTML bundle and verify that it boots in Chromium.
263
+ - **Chromium suite:** uploads by picker and drop, save and reopen with embedded-media round trips, the dirty marker and unload warning, journal recovery after a killed tab, a save conflict from a second tab, opening a SWF, the import report, and SWF export.
264
+
265
+ ## Open questions
266
+
267
+ - **Glyph fonts:** should embedded glyph fonts in imported SWFs be converted to path outlines for fidelity, at the cost of losing editable text? On export, should text optionally embed a font instead of using device fonts?
268
+ - **Library-only import:** should Import SWF also offer to add the SWF's root timeline as a symbol?
@@ -0,0 +1,69 @@
1
+ # Lottie
2
+
3
+ ## Purpose
4
+
5
+ Lottie is the common format for vector animation on the web and in apps: a JSON file that players (lottie-web, ThorVG, rlottie, the iOS and Android libraries) draw at any size. Studio's own project JSON only opens in Studio. Lottie export lets a Studio movie play wherever Lottie does. Lottie import brings Lottie animations into Studio to edit. A file Studio exports comes back exactly, so Lottie can be the file a team passes around.
6
+
7
+ ## Scope
8
+
9
+ - **Export:** a new entry in the Video format menu, "Lottie (JSON)", in the "Vector animation (no sound)" group. The movie plays as it does in a video (8.2, 8.3) and is written as Lottie layers and keyframes, not as frames.
10
+ - **Import:** Import opens Lottie files as well as Studio projects. What Studio can hold becomes Studio objects, keyframes, symbols and scenes; what it cannot is reported.
11
+ - **Roundtrip:** export embeds Studio's project. Importing an unchanged file gives the project back exactly. A file changed after export (in another tool) is read from its Lottie content.
12
+
13
+ Out of scope: the `.lottie` (dotLottie) container and its state machines, expressions, sound.
14
+
15
+ ## Requirements
16
+
17
+ ### 12. Lottie
18
+
19
+ 1. The Video format menu SHALL offer **Lottie (JSON)** in the "Vector animation (no sound)" group. Maximum length applies. The size choice is disabled: Lottie is written at the stage size and players draw it at any size. The file is named `<project>-lottie.json`.
20
+ 2. Export SHALL write the movie as Lottie, at the same frame times as the video (8.2):
21
+ 1. Each Studio object SHALL be one Lottie layer. Its keyframes SHALL be Lottie keyframes: linear, ease in and ease out as Lottie eases with the same curve, ease in-out as two halves, hold keyframes as holds. A span that follows no ease is written frame by frame. Transforms map exactly: position, rotation, skew, scale and `mirror` (a negative y scale).
22
+ 2. Shapes SHALL be Lottie shape groups (rectangles and ellipses as Lottie rectangles and ellipses where they match), with solid and gradient fills and strokes. Text SHALL be Lottie text, one layer per field with its lines, font, size, colour and alignment. The fonts are named, not embedded, so the export report SHALL list them. Bitmaps SHALL be embedded image assets.
23
+ 3. Symbols SHALL be precomps sized to their artwork, played with Lottie's start time or time remapping as Studio plays them (loop, play once, single frame, first frame).
24
+ 4. Scenes SHALL be precomps placed one after another on the main timeline in the order the movie plays them, each named by a marker. Crossfades and wipes SHALL be drawn as in the video. A movie that repeats from a frame other than its first SHALL have `intro` and `loop` markers.
25
+ 5. Masks SHALL be track mattes. Blur and drop shadow SHALL be Lottie's Gaussian Blur and Drop Shadow effects; glows as an even drop shadow (reported). Colour transforms on shapes and text SHALL be baked into their colours; on symbols and bitmaps they are left out and reported. Blend modes Lottie lacks are reported.
26
+ 6. Scripts and frame actions SHALL NOT be refused: the movie is written as it plays without input, and the report says actions do not run in Lottie players. Sound SHALL be left out and reported.
27
+ 3. Export SHALL embed Studio's project (`studio`: format, version, a hash of the Lottie content, and the project gzipped as base64) when **Include the Studio project** is checked, as it is by default (svg-import.md 13.5). Players ignore it.
28
+ 4. Import SHALL accept Lottie JSON, recognised by `w`, `h`, `fr`, `op` and `layers`:
29
+ 1. When the embedded hash matches the Lottie content, the embedded project SHALL be opened exactly.
30
+ 2. Otherwise each layer's transform SHALL be evaluated at every frame, parents included, and reduced to Studio keyframes (linear, with holds on jumps). Shape layers become paths, rectangles and ellipses; a fill and a stroke of the same outline become one object; nested contours become compound paths. Precomps become symbols, with their mode read from the time remapping; any other time remapping becomes one placement per run that plays on or holds a frame (up to 60). Images become bitmaps, solids rectangles, text layers text. Alpha track mattes and single masks become Studio masks. A solid seen through masks becomes the masks' shapes as paths, with subtracting masks as holes, changing shape as the masks move; masks apply to matte layers as well. Inverted mattes are left out (a Studio mask cannot invert, and showing more is closer than showing the opposite). Gaussian Blur, Drop Shadow (a shadow at distance 0 as a glow) and Fill effects, and blend modes Studio has, are kept. Colours on bodymovin 4's 0–255 scale are read as such.
31
+ 3. A file from Studio (scene precomps on the main timeline) SHALL get its scenes back, with the jumps between them as frame events, their transitions, and the loop from its `loop` marker or a stop where the movie ends held.
32
+ 4. A Lottie animation outside Studio's stage limits SHALL be scaled to fit them.
33
+ 5. What Studio cannot hold SHALL be reported: expressions (their recorded values are used), trim paths, repeaters and other shape modifiers, 3D (drawn flat), time stretch, animated gradients and masks (their first frame), mask modes Studio lacks, text animators and tracking, animated dashes (their first lengths), gradient strokes, linked images. Line ends, corners, dashes, the fill rule and masks that subtract are kept ([stroke-style.md](./stroke-style.md)).
34
+ 5. Lottie files SHALL be treated as untrusted: expressions are never run, images are only read from data URIs, precomps that contain themselves and nesting deeper than 32 are cut off, a file asking for more than two million layer-frames is refused, and every value is checked and clamped to Studio's ranges before `parseProjectJson` checks the project as for any import.
35
+ 6. Lottie SHALL add no dependency. Compression uses the browser's `CompressionStream`.
36
+
37
+ ## Design
38
+
39
+ ### Where the code lives
40
+
41
+ ```
42
+ studio/src/
43
+ lottie-export.js # Headless playback → Lottie layers, keyframes, precomps; Studio's data; the hash
44
+ lottie-import.js # Lottie → Studio project JSON: evaluation, pose decomposition, shapes, scene flow
45
+ ```
46
+
47
+ ### Export
48
+
49
+ `exportLottie` runs `playHeadless` (video-playback.js) and records, for each frame, the scene and playhead and any transition. Each object's artwork is recorded through the SVG writers (`makeArtwork`, `createSvgWalker`) and turned into Lottie shapes and text, cached by pose so unchanged artwork is converted once. Keyframes come from Studio's own keyframes: each span is checked against its ease and written as one Lottie key when it fits. Lottie's transform is T(p)·R(r)·Shear(−tan sk)·S·T(−a); Studio's mirror flips y, written as a negative y scale.
50
+
51
+ Precomps clip to their size and Studio symbols do not, so each symbol's precomp is sized to its artwork's bounds, with a null layer shifting the content. Hold keyframes write the new value again just before the next key (at t − 0.001), because some players show the held value at the next key's exact time.
52
+
53
+ ### Import
54
+
55
+ Every property is evaluated as Lottie players do: cubic-bezier timing per dimension, spatial tangents by arc length, holds, separated position. Each layer's matrix (parents, anchor) is decomposed per frame into Studio's pose: rotation unwrapped against the previous frame, skew of the y axis, positive scales, a flip as `mirror`. Each field is reduced with the SVG writer's `reduceTrack`, so jumps stay jumps.
56
+
57
+ A paint (fill, stroke, gradient) applies to the shapes before it in its group and in groups before it, as in Lottie. A group transform the pose cannot hold (gradients drawn as a 1638.4-unit square scaled down) is baked into the points when it does not change. Gradients are mapped into Studio's box-relative gradient matrix.
58
+
59
+ Scene flow comes from the main timeline's segments. Where the playhead of a segment skips, or a segment hands over to the next, the scene gets a jump on the frame after the last one shown (a frame-enter jump happens before that frame is drawn). The transition's type, length and easing are read back from its opacity or wipe keys.
60
+
61
+ ## Verification
62
+
63
+ - **Node tests (`studio/lottie.test.js`):** each ease written as one key reproduces every frame; holds jump at the next key; off-curve spans are frame by frame; time remapping gives a symbol's frames back; transform decomposition with skew and flip; unwrapped rotation; import of shapes, motion, in and out points, the background solid, stage scaling, precomp loops, track mattes, blur and glow; scene flow (jump, crossfade easing, loop); the exact roundtrip and its fallback when the file was changed; precomp cycles, linked images and expressions.
64
+ - **Chromium (`studio/tests/lottie.mjs`, run by `timeline-browser.mjs`):** a two-scene project with a symbol, an ease, a hold and a crossfade is exported from the Export dialog, opened again exactly, and imported from its Lottie content alone; Studio's frames of that import match the original's.
65
+ - **Second renderers:** lottie-web 5.12 and ThorVG 1.1.4 render exported files for comparison with Studio's frames (scratch tools, not dependencies).
66
+ - **Studio's examples (00–09), fixtures and imported SWFs (gm, Checkers, Bloons, Avalanche, Minesweeper, Bloxorz):** the embedded project comes back exactly for every one. Imported from the Lottie content alone, frames match the original within 0.02–1.3 mean difference per channel (0–255); against lottie-web, within 0–3.5 (fonts, glows). Ghost Manor over its whole 60 s gets its seven scenes, crossfades and its loop from frame 97 back as frame events identical to the original's (0.02–0.31). Motherload is refused by Studio's playback (circular frame actions), as for video. Portal was not run (too large for the scratch harness).
67
+ - **lottie-web's demos (bodymovin 4 files):** adrock, gatin, happy2016, grunt within 0–1.9; banner 2.1 and bodymovin 1.2–3.2 (trim paths, text animators); catrim 0–6 and navidad 0–5.2 (trim paths, inverted mattes, mask modes). banner's and catrim's data is read from the JSON string their player bundle carries.
68
+ - **Third-party files (Samsung rlottie's samples, including After Effects feature tests and fuzzing repros):** 30 of 40 within 2.5 of lottie-web. The rest differ where the report says: expressions (night_own 24, windmill up to 44), animated gradients (up to 55), 3D (12), repeaters and trim paths (jolly_walker 10), mask modes (the masks feature test 6–9), inverted mattes (bell 3). The fuzzing repros import without errors. A few samples are white on white in both players and prove nothing.
69
+ - **Not yet verified:** other players (iOS, Android), dotLottie, fonts in players without them.
@@ -0,0 +1,135 @@
1
+ # Minimal Animation Editor Specification
2
+
3
+ ## Purpose
4
+
5
+ Define an initial browser-based, Adobe Animate-inspired editor for creating short 2D animations with swoof. The editor is an authoring tool, not an SWF editor or a replacement for the existing transpiler/runtime.
6
+
7
+ The current `swooflib/` and generated demos provide useful rendering and playback references. Their compiled timeline data is output-oriented; the editor SHALL use its own editable document model and SHALL NOT modify generated demo bundles.
8
+
9
+ System structure is described in [architecture.md](./architecture.md). Implementation progress is tracked in the checked task list at [tasks.md](./tasks.md). Treat it as the source of truth for completed work, remaining work, and verification steps.
10
+
11
+ ## Current browser-editor increment
12
+
13
+ Studio supports named layers and scenes, Swoof-rendered vectors and text, path editing, buttons with labels, interactive preview, undo/redo and editable JSON import/export. Examples opens any of six editable projects. Import accepts a JSON file or pasted text, and Export offers a file download or a copyable project.
14
+
15
+ The timeline uses object tracks. Shapes, paths and text first appear at their creation frame. A blank keyframe hides an object until its next content key. Authors can key or blank the active layer, duplicate or remove track keys, and insert or remove scene frames. Earlier JSON projects retain their original exposures.
16
+
17
+ ## MVP scope
18
+
19
+ The editor SHALL provide:
20
+
21
+ - A stage with configurable width, height, background color, and frame rate.
22
+ - Multiple named scenes, each with its own timeline.
23
+ - A canvas workspace with selection, move, scale, and rotation for selected objects.
24
+ - A timeline with layers, frame numbers, keyframes, and playhead controls.
25
+ - Creation and editing of text, rectangles, circles/ellipses, and freeform Bezier paths, including fill and stroke.
26
+ - Simple interactive buttons that link scenes or frames into a navigable flow.
27
+ - Frame-by-frame keyframes and simple linear property tweens for position, scale, rotation, and opacity.
28
+ - Play, pause, stop, and frame stepping in an editor preview.
29
+ - An in-memory project that remains editable during the current page session.
30
+
31
+ The interface SHALL make the stage, timeline, object properties, and playback controls available in one workspace. Selection and playhead changes SHALL stay synchronized between the stage, timeline, and properties panel.
32
+
33
+ ## Out of scope
34
+
35
+ The MVP does not require project loading or saving, SWF import/export, custom ActionScript or conditional logic, audio, bitmap import, symbols/nested clips, filters, masks, camera/3D effects, collaboration, or undo/redo. Generated bundles in `demos/` are playback references. The JSON samples in `studio/examples/` are editable projects.
36
+
37
+ ## Requirements
38
+
39
+ ### 1. Project and scenes
40
+
41
+ 1. A new editor session SHALL start with a usable blank project and at least one scene.
42
+ 2. Users SHALL be able to add, rename, select, and remove scenes. Removing the last scene SHALL be prevented.
43
+ 3. Each scene SHALL have an independent stage timeline and preserve its contents when the user switches scenes.
44
+ 4. Users SHALL be able to define a scene's starting frame and link interactive buttons to another scene or a frame in the current scene.
45
+ 5. Project state SHALL be held in memory. Refreshing or closing the page may discard unsaved changes.
46
+
47
+ ### 2. Stage and objects
48
+
49
+ 1. The stage SHALL display the active scene at its authored dimensions, scaled to fit the workspace without changing object coordinates.
50
+ 2. Users SHALL be able to create text, rectangle, and ellipse objects on the stage.
51
+ The ellipse tool SHALL support creating a circle by constraining its width and height equally.
52
+ 3. Users SHALL be able to draw and edit open or closed Bezier paths, including moving anchor points and adjusting curve handles.
53
+ 4. Selecting an object on the stage or its layer/timeline entry SHALL select the same object everywhere.
54
+ 5. Users SHALL be able to move, scale, and rotate a selected object on the stage, and edit its transform and opacity numerically.
55
+ 6. Text objects SHALL support editing their content, font family, size, color, and alignment.
56
+ 7. Rectangle, ellipse, and closed path objects SHALL support fill color; vector shapes SHALL support stroke color and width.
57
+ 8. An object SHALL have a stable identity within its scene so timeline keys continue to refer to it after edits.
58
+ 9. Users SHALL be able to mark a text or vector object as a button and assign it a click/tap action to go to a scene or frame.
59
+ 10. A button's hit area SHALL follow its visible object's bounds. The editor SHALL provide visible hover/pressed feedback in preview.
60
+
61
+ ### 3. Timeline and animation
62
+
63
+ 1. Each scene SHALL have one or more named layers with explicit stacking order. Users SHALL be able to add, rename, reorder, hide, lock, and remove layers.
64
+ 2. The timeline SHALL show frame positions and distinguish keyframes from spans; selecting a frame SHALL move the playhead.
65
+ 3. Users SHALL be able to insert blank frames, insert a keyframe that carries the current layer contents forward, duplicate a keyframe, and remove frames or keyframes.
66
+ 4. A keyframe SHALL store the layer's visible object state at that frame. Editing at a keyframe SHALL NOT silently change other keyframes.
67
+ 5. Users SHALL be able to create a linear tween between compatible keyframes for an object's position, scale, rotation, and opacity. Values between endpoints SHALL be interpolated during playback and scrubbing.
68
+ 6. The scene SHALL have a defined frame rate and duration. Scenes play once by default and hold their final frame. When Loop scene is enabled, the playhead wraps from the final frame to the scene's configured starting frame.
69
+ 7. Scrubbing and stepping SHALL update the stage preview deterministically without starting continuous playback.
70
+
71
+ ### 4. Scene flow and input
72
+
73
+ 1. The editor SHALL provide a distinct preview/play mode in which authored button interactions work without interfering with stage selection and editing.
74
+ 2. In preview mode, clicking or tapping a button SHALL perform its configured navigation action. Navigation to a scene SHALL start at that scene's configured starting frame; navigation to a frame SHALL stay in the current scene.
75
+ 3. Scene navigation SHALL stop playback of the previous scene and begin playback of the destination scene when preview playback is active.
76
+ 4. Preview SHALL keep buttons and input text fields interactive when the playhead is paused or reaches the final frame. An editable text field SHALL accept keyboard input during preview and preserve its value across loop iterations. The authored default text SHALL be restored for a new preview session.
77
+ 5. A button without a valid target SHALL be reported in the editor and SHALL NOT cause an unhandled preview error.
78
+
79
+ ### 5. Preview and feedback
80
+
81
+ 1. The editor SHALL render the active scene and its authored objects in the stage preview.
82
+ 2. Playback SHALL render the same object state that scrubbing displays at the corresponding frame.
83
+ 3. The editor SHALL evaluate its own authoring model and use an editor adapter to reuse `swooflib/` display, vector, text, rendering, and input capabilities where practical. The authoring model SHALL NOT depend on generated `timeline-data.js` mutation or the transpiler's compiled-timeline format.
84
+ 4. Invalid edits (for example, non-positive stage dimensions or frame rate) SHALL be rejected with visible feedback and SHALL not corrupt the current project state.
85
+
86
+ ### 6. Files, storage, and SWF
87
+
88
+ File upload, server-side saving and loading with progressive saves, SWF opening and import (requirements 6.x), and SWF export (requirements 7.x) are specified in [file-support.md](./file-support.md). These requirements supersede the MVP exclusions for project saving, bitmap and audio import, and SWF import and export.
89
+
90
+ ### 7. Video and image export
91
+
92
+ Exporting a project as an MP4 or WebM video (requirements 8.x), as an animated GIF, PNG or WebP (requirements 10.x) and the current frame as an image (requirements 9.x) is specified in [video-export.md](./video-export.md). SVG export, of a frame or as an animation (requirements 11.x), is specified in [svg-export.md](./svg-export.md). Lottie export and import (requirements 12.x) are specified in [lottie.md](./lottie.md). SVG import and the Import picker (requirements 13.x) are specified in [svg-import.md](./svg-import.md). Line ends, corners, dashes, the fill rule, italic text, inner effects and masks with holes (requirements 14.x) are specified in [stroke-style.md](./stroke-style.md).
93
+
94
+ ## Initial document model
95
+
96
+ The editable project has the following layout. JSON export also includes the format and version.
97
+
98
+ ```js
99
+ {
100
+ stage: { width, height, background, frameRate },
101
+ // Optional shared timelines. Instances reference their definition by ID.
102
+ symbols: [{ id, name, width, height, durationFrames, startFrame, loop, layers, elements }],
103
+ scenes: [{
104
+ id, name, durationFrames, startFrame, loop,
105
+ layers: [{ id, name, visible, locked, order }],
106
+ elements: [{
107
+ id, layerId, name, type,
108
+ // Optional groupId identifies a group on this layer.
109
+ // Symbol instances carry symbolId and optional symbolMode and firstFrame.
110
+ // Base geometry and style live on the element.
111
+ keyframes: [{ frame, x, y, width, height, scaleX, scaleY, rotation, skew, opacity, tween }],
112
+ // A key can also carry style, path points, or blank: true.
113
+ buttonAction: { trigger: "click", type: "gotoScene", target }
114
+ }]
115
+ }]
116
+ }
117
+ ```
118
+
119
+ Coordinates SHALL be expressed in stage pixels. Keyframe frames are one-based in the UI and in the authoring model. Tweens SHALL reference an object present at both endpoints. The implementation MAY refine the internal representation while preserving the behaviors above.
120
+
121
+ ## Acceptance criteria
122
+
123
+ The MVP is acceptable when a user can, in one editor session:
124
+
125
+ 1. Create a scene, add text, a rectangle, a circle, and a curved path, then edit their appearance and path points.
126
+ 2. Organize objects on separate layers and select each from either the stage or timeline.
127
+ 3. Insert, duplicate, and remove frames/keyframes; set different object transforms at two keyframes; create a linear tween; and observe intermediate values by scrubbing and playback.
128
+ 4. Link a button in one scene to another scene or frame, then verify it navigates correctly in preview without triggering while editing.
129
+ 5. Add and switch between scenes without losing either scene's in-memory contents.
130
+ 6. Change stage dimensions or frame rate and see the preview/timeline reflect the new values.
131
+ 7. Receive clear feedback for invalid stage settings or button targets, with the last valid project still usable.
132
+
133
+ ## Implementation tracking
134
+
135
+ Follow [tasks.md](./tasks.md) for the implementation checklist and remaining editor priorities. Check tasks only after the behavior is implemented and its stated validation has passed.
@@ -0,0 +1,95 @@
1
+ # Line ends, corners, dashes, fill rule, italic, inner effects and masks with holes
2
+
3
+ ## Purpose
4
+
5
+ Studio's objects held a stroke as a width and a colour, and filled every compound path even-odd. Flash 8 line styles also have line ends (caps), corners (joins) and a miter limit, and SWF 8 shapes can fill nonzero. SVG, Lottie and every drawing tool use these properties, so art imported from them lost its square corners, dashes and overlapping fills. Masks also ignored holes in their shape.
6
+
7
+ This adds those properties to Studio's objects. Studio draws them, edits them and writes them to every format it exports.
8
+
9
+ ## Scope
10
+
11
+ - **Object fields:** line ends, corners, miter limit, dashes and dash offset, the fill rule of a path, italic text, and an inner flag on glows and drop shadows.
12
+ - **Properties panel:** controls for all of them.
13
+ - **Drawing:** the editor, preview and video drawing honour them.
14
+ - **Exports:** SWF, SVG and Lottie write them. Video and image exports draw them as the editor does.
15
+ - **Imports:** SVG, Lottie and SWF import read them.
16
+ - **Masks:** a mask clips as its shape fills, holes included. This applies to vector masks and to symbols used as masks.
17
+
18
+ Out of scope:
19
+ - Animating dashes or line style. These belong to the object, not to keyframes, as in Flash.
20
+ - Different caps at each end of a line.
21
+
22
+ ## Requirements
23
+
24
+ ### 14. Stroke and fill style
25
+
26
+ 1. A path, rectangle, ellipse, star or line SHALL accept these optional fields:
27
+ - `lineCap`: `round` (the default, as Flash), `butt` or `square`;
28
+ - `lineJoin`: `round` (the default), `miter` or `bevel`;
29
+ - `miterLimit`: 1–255; Flash's default of 3 applies when it is left out;
30
+ - `strokeDash`: 1–64 lengths, each 0–10000. They are drawn on, off, on and so on, and an odd list repeats twice, as in canvas and SVG. A list of zeros is a solid line;
31
+ - `strokeDashOffset`: where along the pattern the stroke starts.
32
+
33
+ Values outside these SHALL be refused when a project is read.
34
+ 2. A closed path SHALL accept `fillRule`: `nonzero` or `evenodd`.
35
+ - Without it, a compound path fills even-odd (as before, and as SWF and glyphs do) and a single outline fills nonzero.
36
+ - `evenodd` on one self-crossing outline leaves its crossings empty.
37
+ - Known difference: a SWF of one self-crossing outline without `fillRule` is filled even-odd (the shape's flag is only set when a path asks for nonzero), where the editor fills it nonzero. This predates these fields.
38
+ 3. Text SHALL accept `italic`. It is drawn, measured, embedded in SWF fonts, and exported in SVG and Lottie font styles.
39
+ 4. A glow or drop shadow effect SHALL accept `inner: true`. It is drawn inside the shape, from its inverted alpha.
40
+ - A tween keeps the flag; it is never interpolated.
41
+ - Lottie has no inner effect: it is left out and reported.
42
+ 5. The Properties panel SHALL show:
43
+ - for vector objects: Line ends (Round, Flat, Square), Corners (Round, Sharp, Bevelled) and Dashes (lengths such as `6 3`; empty for solid);
44
+ - for closed paths: Overlapping outlines (Holes, Filled, Always holes);
45
+ - for text: Italic;
46
+ - for glows and shadows: Inner.
47
+
48
+ They are disabled when the object's layer is locked, and recorded for undo.
49
+ 6. **SWF export:**
50
+ - caps, joins and the miter limit SHALL be written in DefineShape4 line styles;
51
+ - dashes SHALL be cut into separate stroke pieces, since SWF has no dashes;
52
+ - a nonzero path SHALL set the shape's `UsesFillWindingRule` flag. Shapes without one are written as before.
53
+ 7. **Masks** SHALL clip as their shape fills:
54
+ - a compound path even-odd unless it says `nonzero`, so its holes are holes;
55
+ - a symbol used as a mask covers each of its shapes, holes included. Its contours are turned so overlapping shapes add up instead of cancelling.
56
+
57
+ This holds in the editor, in SVG export (`clip-rule`), and in Lottie export, where holes in an image's mask are written as subtracting masks.
58
+ 8. **Imports:**
59
+ - SVG import SHALL read `stroke-linecap`, `stroke-linejoin`, `stroke-miterlimit`, `stroke-dasharray`, `stroke-dashoffset`, `fill-rule`, `font-style` and inner shadows (as Inkscape, Figma and Studio write them);
60
+ - Lottie import SHALL read `lc`, `lj`, `ml`, dashes, the fill rule `r`, and masks that subtract from a single adding mask. A matte of several adding masks becomes one nonzero path, its outlines turned so they add up;
61
+ - SWF import SHALL read DefineShape4 line ends, corners and miter limits, and keep nonzero compound fills. A closed outline with sharp or bevelled corners redraws its first segment, so its start is a corner rather than two line ends.
62
+
63
+ ## Design
64
+
65
+ The fields live on the element (`project-io.js`, `readStrokeStyle`), like `bitmapFill`. Flash also keeps line style on the shape, not on the frame.
66
+
67
+ `vector-geometry.js`:
68
+ - `setStrokeStyle` passes caps, joins and the miter limit to swooflib's `_setLineStyle`, which already supported them;
69
+ - swooflib's new `Graphics.lineDashStyle` puts dashes on the current line style. `applyGraphicsLineStyle` hands them to canvas `setLineDash`, so the editor and Studio's SVG context (which writes `stroke-dasharray`) get them for free;
70
+ - the fill rule becomes a `drawPath` winding command.
71
+
72
+ `server/project-movie.js`:
73
+ - `dashedPath` cuts the recorded path into dashes. Quadratic pieces are split exactly, by blossoming;
74
+ - the winding command marks fill draws `nonZero`, and `swf2js/encoder/shape-encoder.js` sets the DefineShape4 flag from it.
75
+
76
+ Masks:
77
+ - `vectorMaskPath` returns the clip `rule`, which `display-frame.js`, `canvas.js` and `svg-frame.js` pass to `clip()`, `isPointInPath` and `clip-rule`;
78
+ - symbol masks use `orientedVectorPathData`. Each contour is flattened to find its area and nesting depth. Even-odd holes wind against their outlines and other outlines wind forwards, so the union under nonzero is what each shape fills.
79
+
80
+ ## Verification
81
+
82
+ - **Node (`studio/stroke-style.test.js`):**
83
+ - fields read, refused and written;
84
+ - an inner shadow tweening;
85
+ - dashes cut for SWF with an offset;
86
+ - a SWF decoded back: nonzero flag, flat ends, miter join and limit, dash pieces; a compound path still even-odd;
87
+ - symbol mask contours turned;
88
+ - a Lottie subtracting mask kept as a hole, and a matte of two overlapping adding masks kept nonzero;
89
+ - Studio → SWF → Studio keeping square ends, miter corners, the miter limit and a nonzero fill.
90
+ - **SVG import tests:** line style, dashes, fill rules, italic and inner shadows (see [svg-import.md](./svg-import.md)).
91
+ - **Chromium (`studio/tests/import-files.mjs`):** an SVG's dashes and sharp corners show in Properties. Clearing the dashes and choosing round ends changes the object.
92
+ - **Checked by hand in Chromium (scratch scripts):**
93
+ - nonzero and even-odd holes, dashes, an inner shadow, and SVG export attributes on the canvas;
94
+ - a path mask with a hole;
95
+ - a symbol mask of two opposite-direction squares and a ring.