mcpField
W
waapi

waapi

github.com/heygen-com安全74.7k69.0k 次安装今天更新
代码仓库

关于 waapi

面向 HyperFrames 的技能,可将 Web Animations API 动画定位到合成时间线。它指导开发者同步创建有限时长的动画,并验证渲染结果。

主要功能

  1. 01将动画定位到 HyperFrames 时间
  2. 02使用 element.animate 创建动画
  3. 03设置有限时长和迭代次数
  4. 04在定位时间暂停动画
  5. 05验证合成

适用场景

  1. 01制作轻量级 DOM 动效
  2. 02根据结构化数据生成动画
  3. 03用关键帧和偏移构建时间线

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/heygen-com/hyperframes --skill waapi

安装后在 Claude Code 中输入/waapi确认已加载。

详细介绍

HyperFrames 的 Web Animations API

HyperFrames 可以通过其 waapi 运行时适配器对 Web Animations API 动画进行时间跳转。如果你想使用原生浏览器关键帧,并通过 JavaScript 创建时间设置,同时不依赖 GSAP,WAAPI 会很有用。

契约

  • 在合成初始化期间同步创建动画。
  • 使用 element.animate(...),并设置有限的 duration 和 iterations。
  • 使用 fill: "both",以便跳转后的状态持续保留。
  • 创建动画后暂停它们,或让适配器在首次跳转时暂停它们。
  • 避免使用回调和 Promise 来处理渲染关键状态。

适配器会调用 document.getAnimations(),将每个动画的 currentTime 设置为 HyperFrames 的毫秒级时间,然后暂停动画。

基本模式

<div id="orb" class="clip orb" data-start="2" data-duration="3" data-track-index="2"></div>

<script>
  const orb = document.getElementById("orb");
  const animation = orb.animate(
    [
      { transform: "translate3d(-160px, 0, 0) scale(0.8)", opacity: 0 },
      { transform: "translate3d(0, 0, 0) scale(1)", opacity: 1, offset: 0.35 },
      { transform: "translate3d(120px, 0, 0) scale(1.08)", opacity: 1 },
    ],
    {
      duration: 3000,
      delay: 2000,
      easing: "cubic-bezier(0.2, 0, 0, 1)",
      fill: "both",
      iterations: 1,
    },
  );

  animation.pause();
</script>

交错模式

document.querySelectorAll(".token").forEach((token, index) => {
  const animation = token.animate(
    [
      { transform: "translateY(24px)", opacity: 0 },
      { transform: "translateY(0)", opacity: 1 },
    ],
    {
      duration: 620,
      delay: index * 80,
      easing: "cubic-bezier(0.2, 0, 0, 1)",
      fill: "both",
      iterations: 1,
    },
  );
  animation.pause();
});

适用场景

  • 轻量级 DOM 动效:CSS 关键帧过于僵化,且不需要 GSAP。
  • 根据结构化数据生成动画。
  • 可用关键帧、延迟和偏移量表示的简单时间线。

避免

  • 使用无限的 iterations。
  • 依赖 animation.finished 来修改渲染关键 DOM。
  • 使用 requestAnimationFrame、计时器或 performance.now() 运行独立时钟。
  • 动画化布局属性,而变换和透明度就能实现所需效果。
  • 假设剪辑的本地起始时间会自动处理。WAAPI 适配器会跳转文档级动画时间;请使用 delay 模拟剪辑偏移,或在可见性由 HyperFrames 计时控制的元素上创建动画。

验证

编辑 WAAPI 合成后:

npx hyperframes lint
npx hyperframes validate

致谢与参考资料

评论

支持 Markdown