@aarsteinmedia/lottie-web

中文文档
1.6.9发布于 2026/11/03GPL-2.0-or-laterTypeScriptES Module零依赖近 30 天下载 1.4万

Play animations generated in After Effects in the browser

原始使用文档
文档目录9 节
  1. Why this fork exists
  2. Installation
  3. Entry points
  4. Basic usage
  5. Inline animation data
  6. SVG-only bundle (smaller)
  7. Events
  8. Development
  9. License

AM Lottie Web

A TypeScript fork of Airbnb's lottie-web, maintained for the Aarstein Media dotLottie player ecosystem.

Why this fork exists

  • Safer expressions — After Effects expressions are evaluated with new Function instead of eval, which slightly improves security and performance. For untrusted input, however, /light is recommended.
  • Economic imports – This package adheres to a modular design philosophy, and offers granular imports so that you don't get any unneeded bloat in your application – provided that you keep on reading.
  • Better Canvas rendering – While Canvas rendering isn't as versatile as SVG rendering, it's more performant and more conducive to how visual elements are handled in most browsers. This fork has better better DPR handling and broader feature support for Canvas renderer.
  • SSR-friendly — Browser and Web API usage is guarded for Node and server rendering.
  • Better errors — Failures surface through typed events instead of failing silently.

This package is primarily built for @aarsteinmedia/dotlottie-player and @aarsteinmedia/dotlottie-react. Other use cases are supported, but inherited from upstream lottie-web behavior.

Installation

pnpm add @aarsteinmedia/lottie-web

If you use the dotLottie entry point, install the peer dependency as well:

pnpm add fflate

Entry points

Here is where reading this whole thing pays off. Remember what I said about modular design? Well, this is that.

ImportDescription
@aarsteinmedia/lottie-webFull build: SVG + canvas renderers, effects, and expressions
@aarsteinmedia/lottie-web/lightSVG renderer only, no expressions
@aarsteinmedia/lottie-web/svgSVG renderer with expressions
@aarsteinmedia/lottie-web/canvasCanvas renderer with expressions
@aarsteinmedia/lottie-web/utilsShared helpers and enums
@aarsteinmedia/lottie-web/dotlottiedotLottie archive utilities

Basic usage

import lottie, { loadAnimation } from '@aarsteinmedia/lottie-web'
import type { AnimationItem } from '@aarsteinmedia/lottie-web'
import { PlayerEvent } from '@aarsteinmedia/lottie-web/utils'

const container = document.getElementById('animation')

const animation: AnimationItem = loadAnimation({
  container,
  renderer: 'svg',
  loop: true,
  autoplay: true,
  path: '/animations/hero.json',
})

animation.addEventListener(PlayerEvent.Complete, () => {
  console.log('Animation finished')
})

// Later
animation.destroy()

Inline animation data

import animationData from './animation.json'

const animation = loadAnimation({
  container: document.getElementById('animation'),
  renderer: 'svg',
  animationData,
  autoplay: false,
})

SVG-only bundle (smaller)

import lottie from '@aarsteinmedia/lottie-web/svg'

Events

AnimationItem extends a small event emitter. Common events include:

EventWhen it fires
DOMLoadedAnimation is ready to play
enterFrameEach rendered frame
completePlayback reached the end
loopCompleteA loop iteration finished
configErrorInvalid configuration or data
renderFrameErrorA frame failed to render
destroyAnimation is being torn down

Import event names from @aarsteinmedia/lottie-web/utils:

import { PlayerEvent } from '@aarsteinmedia/lottie-web/utils'

animation.addEventListener(PlayerEvent.RenderFrameError, (event) => {
  console.error(event?.nativeError)
})

Development

pnpm install
pnpm dev        # preview player with live reload
pnpm lint       # eslint
pnpm test       # vitest
pnpm prod       # typecheck + production build
pnpm check      # lint, test, build, and verify version injection

pnpm dev expects a local assets/ directory of sample .json / .lottie files (this repo tracks a symlink to a sibling lottie-fixtures folder). Tests use fixtures under tests/lottie-fixtures/ and do not depend on assets/.

License

GPL-2.0-or-later. See upstream lottie-web licensing implications if you distribute combined or derivative works.

版本与发布记录

@aarsteinmedia/lottie-web 共发布 105 个版本,首次发布于 2025/03/24;过去 12 个月发布了 40 个版本。

版本发布日期距今
1.6.9latest2026/11/033 天前
1.6.82026/11/033 天前
1.6.72026/11/033 天前
1.6.62026/10/2412 天前
1.6.52026/10/0729 天前
1.6.42026/10/0730 天前

关于 @aarsteinmedia/lottie-web 的常见问题

@aarsteinmedia/lottie-web 是什么?

Play animations generated in After Effects in the browser

如何安装 @aarsteinmedia/lottie-web?

在项目目录运行 npm install @aarsteinmedia/lottie-web,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:fflate(^0.8.3)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aarsteinmedia/lottie-web 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aarsteinmedia/lottie-web 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@aarsteinmedia/lottie-web 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@aarsteinmedia/lottie-web 可以商用吗?

@aarsteinmedia/lottie-web 使用 GPL-2.0-or-later 许可。强 Copyleft:分发包含该代码的软件时,整个作品需以兼容的 GPL 许可开源。仅在内部使用、不对外分发时不触发此义务。以上为概括,不构成法律意见,请以许可原文为准。

@aarsteinmedia/lottie-web 的下载量有多少?

根据 npm 官方下载统计,@aarsteinmedia/lottie-web 在 2026/10/05 – 2026/11/03 这 30 天内被下载 13,593 次,日均约 453 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aarsteinmedia/lottie-web 还在维护吗?

最新版本 1.6.9 发布于 2026/11/03(3 天前);至今共发布 105 个版本,其中过去 12 个月发布了 40 个;首次发布于 2025/03/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。