Skip to content

支持 Lottie、dotLottie 和动画 SVG 素材 - #87

Open
devin-ai-integration[bot] wants to merge 18 commits into
devin/1796518381-denoise-beatsfrom
devin/1796519234-lottie-svg
Open

devin-ai-integration[bot] wants to merge 18 commits into
devin/1796518381-denoise-beatsfrom
devin/1796519234-lottie-svg

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

支持把 Lottie(.json)、dotLottie(.lottie)和动画 SVG(SMIL 或 CSS 动画)导入素材库。导入时逐帧渲染成 APNG,之后按现有的动图素材处理,所以预览、MP4 导出、工程保存和剪映草稿都不用单独适配。代价是导入后不能再改矢量内容。静态 SVG 仍和以前一样栅格化成 WebP。

prepareImage(file)
  SVG  -> isAnimatedSvg(text) ? renderAnimatedSvg() : rasterizeSvg()
  Lottie (.json / .lottie / json MIME) -> renderLottie()
  -> encodeApng(pngFrames, fps)   // 新的 src/utils/apng.ts
  • 输出规格:长边 512 px,最高 30 fps,最长 10 秒(单轮动画时长:SMIL 取 getSimpleDuration(),CSS 取 getComputedTiming();都没有时按 3 秒)。
  • Lottie:使用 lottie-web 的 lottie_light_canvas 版本,按需动态加载,goToAndStop(frame, true) 逐帧绘制到 canvas。light 版本不带表达式引擎,导入文件里的表达式不会被当作脚本执行。dotLottie 用 fflate 解包,读取 manifest.json 里的第一个动画,images/ 或 i/ 下的图片内嵌为 data URL。
  • 动画 SVG:放进 shadow root(页面样式不影响计算),用 pauseAnimations()/setCurrentTime() 和 Animation.currentTime 定到每一帧,再把当前状态写进副本:
    • 计算样式(填充、描边、不透明度、transform 等,以及适用元素上的 d/cx/r/x…)写成行内样式
    • SMIL 改的非 CSS 属性(如 points、x1)从 animVal 读取
    • animateMotion 的位移换算成相对父元素的矩阵
    • 去掉动画元素,序列化后用 <img> 绘制
    • 插入页面前删除 <script>、foreignObject、on* 事件属性和 javascript: 链接
  • 导入入口:mediaAccept 新增 .svg,.json,.lottie,mediaKind 把这几类文件识别为图片;MCP import_file 新增对应 MIME,import_asset/import_file 的描述也已更新。
  • vite.config.ts 预构建 lottie_light_canvas,避免开发时首次导入 Lottie 触发页面重载。

测试:新增 apng.test.ts;e2e MCP imports Lottie, dotLottie and animated SVG as animated images 导入动画 SVG、静态 SVG、Lottie、dotLottie 和一个非法 JSON,导出 MP4 后按像素检查 SMIL 位移、CSS 淡入和 Lottie 位移,并确认 SVG 里的脚本没有执行。

Link to Devin session: https://app.devin.ai/sessions/a882af08b80c444280600c6cdc988c2e
Open in Devin Desktop: https://app.devin.ai/desktop/session/a882af08b80c444280600c6cdc988c2e?variant=devin
Requested by: @x007xyz


🟢 Devin Review found nothing to fix · View findings · Follow Devin's work

Devin Review

Co-Authored-By: zhangxiang chen <x007xyzabc@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@vercel

vercel Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
fly-cut Ready Ready Preview Dec 6, 2026 1:52am UTC

devin-ai-integration Bot and others added 7 commits December 6, 2026 01:28
Co-Authored-By: zhangxiang chen <x007xyzabc@gmail.com>
Co-Authored-By: zhangxiang chen <x007xyzabc@gmail.com>
Co-Authored-By: zhangxiang chen <x007xyzabc@gmail.com>
Co-Authored-By: zhangxiang chen <x007xyzabc@gmail.com>
Co-Authored-By: zhangxiang chen <x007xyzabc@gmail.com>
…the dev server

Co-Authored-By: zhangxiang chen <x007xyzabc@gmail.com>
Co-Authored-By: zhangxiang chen <x007xyzabc@gmail.com>
devin-ai-integration Bot and others added 3 commits December 6, 2026 01:36
Co-Authored-By: zhangxiang chen <x007xyzabc@gmail.com>
Co-Authored-By: zhangxiang chen <x007xyzabc@gmail.com>
Co-Authored-By: zhangxiang chen <x007xyzabc@gmail.com>
Co-Authored-By: zhangxiang chen <x007xyzabc@gmail.com>
Co-Authored-By: zhangxiang chen <x007xyzabc@gmail.com>
devin-ai-integration Bot and others added 3 commits December 6, 2026 01:45
…orever

Co-Authored-By: zhangxiang chen <x007xyzabc@gmail.com>
Co-Authored-By: zhangxiang chen <x007xyzabc@gmail.com>
Co-Authored-By: zhangxiang chen <x007xyzabc@gmail.com>
devin-ai-integration Bot and others added 2 commits December 6, 2026 01:51
Co-Authored-By: zhangxiang chen <x007xyzabc@gmail.com>
Co-Authored-By: zhangxiang chen <x007xyzabc@gmail.com>

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

Browser UI tested on 43e6121, covering the #83–#87 stack. Devin session

#87: Vector import, preview, and MP4 export passed

Lottie, dotLottie, SMIL, and CSS animations all moved in preview and in the decoded MP4. The cyan and magenta SVG <use> instances kept their own fills, the static SVG stayed still, and invalid JSON was rejected without adding an asset.

Browser preview at 0.00 and 1.50 seconds

Decoded MP4 at the same two times

#83–#86: Stack results and one persistence caveat

Canvas backgrounds, reverse, both tested speed curves, the 3-second freeze, stickers, and shapes all rendered in the saved MP4s. Five beat markers matched exported audio onsets within 34 ms. Exports with noise reduction enabled completed. The video clip's denoise toggle read off after the first reload but persisted on two retests; the audio toggle persisted on the first reload.

Decoded MP4 frames before, during, and after freeze

Written by Devin

This branch was successfully deployed

1 active deployment
Preview — 43e61210 Deployed Dec 6, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant