@gentleduck/motion

中文文档
1.0.1发布于 2026/10/13MITTypeScriptES Module零依赖近 30 天下载 3111

Motion primitives for gentleduck/ui components.

原始使用文档
文档目录4 节
  1. Quick Start
  2. Features
  3. Exports
  4. License

@gentleduck/motion

@gentleduck/motion

Motion primitives for gentleduck/ui components.

MIT - Changelog - Contributing - Docs

npm downloads MIT


Animation tokens, presets, and reduced motion support for the gentleduck ecosystem. Optionally integrates with the motion library for rich enter/exit animations.

Quick Start

bun add @gentleduck/motion
import { useDuckReducedMotion, motionTransition } from '@gentleduck/motion'

function Fade() {
  const reduced = useDuckReducedMotion()
  const transition = motionTransition(reduced, { duration: 200, easing: 'ease-out' })
  // ...
}

Features

  • Easing presets -- duckMotionEasing.standard, .exit, .expo, .easeOut, .spring
  • Duration tokens -- duckMotionDurationMs.fast (150ms), .normal (200ms), .slow (300ms), .exit (180ms fallback)
  • Spring transitions -- springDefault, springSnappy, springGentle, springBouncy, springStiff, springSmooth, springInstant
  • CSS custom properties -- --gentleduck-motion-dur, --gentleduck-motion-ease via @gentleduck/motion/css
  • Reduced motion -- useDuckReducedMotion(), motionTransition()
  • Animation presets -- tree-shakeable presets like fadeIn, scaleIn, slideUp with blur and asymmetric exits
  • Directional presets -- createDirectionalPreset('bottom') for menu/popover animations; createSlidePreset for pure slides
  • Motion library integration -- MotionProvider, LazyMotion feature loaders, useMotionPreset hook

Exports

Entry pointWhat it provides
@gentleduck/motionTokens, easing, reduced motion hooks, CVA animation variants
@gentleduck/motion/cssCSS file with motion custom properties and reduced motion fallback
@gentleduck/motion/transitionsDuration/easing mapped to motion Transition objects, spring presets
@gentleduck/motion/motion-presetsuseMotionPreset hook
@gentleduck/motion/motion-featuresloadDomAnimation, loadDomMax LazyMotion feature loaders
@gentleduck/motion/motion-providerMotionProvider wrapping LazyMotion + MotionConfig
@gentleduck/motion/presetsIndividual tree-shakeable preset exports (fadeIn, scaleIn, etc.)
@gentleduck/motion/presets/fade-inSingle preset import for best tree-shaking

License

MIT

版本与发布记录

@gentleduck/motion 共发布 24 个版本,首次发布于 2025/09/03;过去 12 个月发布了 15 个版本。

版本发布日期距今
1.0.1latest2026/10/131 个月前
1.0.02026/05/305 个月前
0.3.42026/05/205 个月前
0.3.32026/05/066 个月前
0.3.22026/05/036 个月前
0.3.12026/05/036 个月前

关于 @gentleduck/motion 的常见问题

@gentleduck/motion 是什么?

Motion primitives for gentleduck/ui components.

如何安装 @gentleduck/motion?

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

@gentleduck/motion 支持 TypeScript 吗?

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

@gentleduck/motion 支持 ESM 还是 CommonJS?

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

@gentleduck/motion 需要什么版本的 Node.js?

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

@gentleduck/motion 可以商用吗?

@gentleduck/motion 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gentleduck/motion 的下载量有多少?

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

@gentleduck/motion 还在维护吗?

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