1实现原理 · 为什么它能做到
定位为 After Effects 到产品的桥:把矢量动效编成 JSON 或 zip 容器,由运行时播放,从而与分辨率和平台解耦
The bridge from After Effects to product: vector animation shipped as JSON (or zipped `.lottie`), tiny and resolution-independent, played by a runtime on web, iOS, Android, and React Native.
播控以帧、段、模式三件套为核心 API,并用 load/complete/frame 事件做状态机式编排
dotLottie.setSegment(30, 90); // constrain playback to a frame range (e.g. a "loading" loop)
滚动驱动不需要动画库:autoplay:false 加滚动进度映射到帧(clamp 0..1 后乘 total-1),或交给 lottie-interactivity 声明式配置
dotLottie.setFrame(p * (total - 1));
运行时换肤两条路:.lottie 内嵌命名主题(setTheme/loadTheme,无需重导)与手动遍历 layers[].shapes[] 改色值的脆弱补丁
load the JSON, walk `layers[].shapes[]` and patch `c.k` color arrays (normalized 0–1 RGBA), then init the player with the modified object. Brittle
导出侧给清单:Bodymovin 导出流程与 AE 表达式、多数效果不被支持的已知缺口,解释了预览对但进产品就不对的主因
**Expressions** — not evaluated by runtimes. Bake expression-driven motion to keyframes (Bodymovin can pre-render some) or remove. Heavy-expression rigs are the #1 source of "looks wrong in product".
2核心能力
3外部依赖
| Kind | Dependency / Endpoint |
|---|---|
| package | @lottiefiles/dotlottie-web(首选现代运行时:canvas 加 WASM) |
| package | @lottiefiles/lottie-interactivity(声明式交互模式) |
| package | lottie-web(遗留 .json 加 SVG 渲染器路径) |
| network | 交付页从 CDN 取 dotLottie 运行时(产物期引用,不判级;正文未点名具体域) |
| package | 移动端运行时:lottie-ios / lottie-android / lottie-react-native |
| cli | npx / Playwright(宿主侧截图工具)与仓库根 scripts/ 助手(seek-shot.sh、contact-sheet.sh 依赖 ffmpeg) |
4管控建议与判定依据
- 网络端点: 声明外部网络访问: 执行期零外发;正文示例含 fetch("/icon.json")(相对路径取本地资产,不是外发)
- 本地工作目录: 文件读写与工件输出: 本 skill 目录零写盘;交付物 1 个自包含 .html(运行时加 canvas 加 .lottie/.json 相对文件或 data URL)
5第二遍独立确认
- [unlocatable] .lottie 比 .json 小 60–80% 这一数字 — SKILL.md 写 .lottie often 60–80% smaller,但源码内无基准、无样例文件(本 skill 目录不含任何 .lottie/.json 资产),属外部经验值,记为文档声明,不作已验证事实。
- [ok] 唯一的 fetch( 命中是否构成外发 — references/integration-and-export.md 的 const json = await fetch("/icon.json").then((r) => r.json()); 使用相对路径,取同源本地资产(用于手动改色),不构成网络外发;该写法位于 Manual color patching (last resort) 小节,正文亦标注为脆弱手段。
- [ok] 运行时 API 名称是否自洽(setFrame/setSegment/setMode/totalFrames) — SKILL.md 的 Playback control 段、Quick reference 表、冻结 harness 段与 references 第 1、3 节对同一组方法名(setFrame/setSegment/setSpeed/setMode/setTheme/totalFrames/play/pause/stop)表述一致,并明确区分 lottie-web 的 goToAndStop(N, true) 等价写法。
- [discrepancy] Packaged helper 的路径基准与语义 — SKILL.md 写 scripts/seek-shot.sh anim.html 0 1.5 3,scripts/ 在仓库根;且本 skill 的冻结单位是帧(?t=42),而 seek-shot.sh 把 ?t= 当秒数传参——即使路径正确,语义也需按帧自行换算。
6结论
d36e9095939adbd5…