@cssints/motion

中文文档
0.35.1发布于 2026/11/07MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 7855

Animation presets for cssints: fade, slide, scale and blur in and out as one kernel over keyframes(), with prefers-reduced-motion

原始使用文档
文档目录3 节
  1. Rules
  2. Limits
  3. Credits

@cssints/motion

Animation presets for cssints: fade, slide, scale and blur, in and out, as one chain member of cssints/plugin scope(). In the composable way of tailwindcss-motion and tailwindcss-animate: a preset only sets custom properties, and one kernel over keyframes() runs them. No runtime.

import { cn, hover } from "cssints" with { type: "cssints" };
import { motion } from "@cssints/motion" with { type: "cssints" };

export const toast = motion()
  .preset("slide-in-up")
  .duration("500ms")
  .delay("100ms")
  .easing("linear");
export const leave = motion().preset("fade-out");
export const slow = cn(motion().preset("scale-in"), hover(motion().duration("1s")));
@layer _.k {
  @keyframes kf-7f473efd {
    from {
      opacity: var(--motion-o);
      translate: var(--motion-x) var(--motion-y);
      scale: var(--motion-s);
      filter: blur(var(--motion-b));
    }
  }
  @keyframes kf-eaeb1c11 {
    to {
      opacity: var(--motion-o);
      translate: var(--motion-x) var(--motion-y);
      scale: var(--motion-s);
      filter: blur(var(--motion-b));
    }
  }
  @keyframes kf-4f766ef7 {
    from {
      opacity: var(--motion-o);
    }
  }
  @keyframes kf-9b622913 {
    to {
      opacity: var(--motion-o);
    }
  }
  ._motion-core {
    animation: var(--motion-n) var(--motion-d) var(--motion-e) var(--motion-l) both;
    --motion-in: kf-7f473efd;
    --motion-out: kf-eaeb1c11;
    --motion-ri: kf-4f766ef7;
    --motion-ro: kf-9b622913;
    --motion-n: none;
    --motion-r: none;
    --motion-d: 300ms;
    --motion-l: 0s;
    --motion-e: ease-out;
    --motion-o: 1;
    --motion-x: 0;
    --motion-y: 0;
    --motion-s: 1;
    --motion-b: 0;
  }
  @media (prefers-reduced-motion: reduce) {
    ._motion-core {
      animation-name: var(--motion-r);
    }
  }
}
@layer _.a {
  ._13945js {
    --motion-n: var(--motion-in);
  }
  ._jddydc {
    --motion-r: var(--motion-ri);
  }
  ._knj5bv {
    --motion-o: 0;
  }
  ._1a9p5a9 {
    --motion-y: 25%;
  }
  ._46hkr9 {
    --motion-d: 500ms;
  }
  /* ... */
}

Rules

  • Methods, each once, in any order, all optional: preset(name), duration(<time [0s,∞]>) (300ms), delay(<time>) (0s), easing(<easing-function>) (ease-out). Each is one class that sets a custom property, so a method works under a condition (hover(motion().duration("1s"))).
  • Presets: fade-in, fade-out, slide-in-up, slide-in-down, slide-in-left, slide-in-right, slide-out-up, slide-out-down, slide-out-left, slide-out-right, scale-in, scale-out, blur-in, blur-out. Each fades; a slide moves 25% of the box, a scale starts (or ends) at 0.5, a blur at 5px (tailwindcss-motion's medium sizes). -in runs from those values to the element's own, -out from its own to those, and holds the end (both). slide-in-up moves up into place; slide-out-up moves up out of it.
  • The keyframes are four keyframes(): in and out, and their reduced-motion twins that move only the opacity. They read --motion-*, so all presets share them. The kernel is written as styles and names them in --motion-in, --motion-out, --motion-ri and --motion-ro (vars()), which puts their rules in the sheet with it; a preset picks one (--motion-n: var(--motion-in)).
  • Reduced motion. Under prefers-reduced-motion: reduce the kernel runs the opacity-only keyframes: a slide, scale or blur becomes a fade of the same duration, and animationend still fires.
  • No inheritance. The kernel resets every --motion-* on its class, so a motion inside another one starts from its own preset, not its parent's.
  • Conflicts. motion() sets the animation: a cn() that holds it and an animation* property is a build error, derived from the kernel: cssints: motion: kernel core sets animation, animation-name (this style also sets animation-duration).
  • Errors are the grammar's, in the types and at build time: motion.preset: unexpected "spin" in "spin", expected fade-in | ..., motion.duration: unexpected "-1s" in "-1s", expected <time [0s,∞]>.
  • For other members. presets (the table by name), PresetName, motionKeyframes, motionVars (the custom properties the keyframes read, by the field of a preset: motionVars.y is --motion-y) and motionScope (its kernel core) are exported, so a member built on these presets reuses them and never writes a --motion-* name.

Limits

  • One preset per element: preset() is used once, and presets do not stack (every slide, scale and blur already fades).
  • The keyframes set translate, scale and filter: during the animation (and after an -out one) they replace the element's own; transform is untouched.
  • No loop presets (pulse, spin, bounce), no spring easings, no per-preset sizes.
cd packages/motion && bun run test   # fixtures through the engine (output, conflicts, errors); bun run typecheck for the type test

Credits

The design (presets that only set custom properties, one kernel over keyframes()), the preset names and the medium sizes (25%, 0.5, 5px) follow tailwindcss-motion (MIT, Rombo Limited) and tailwindcss-animate (MIT, Jamie Kyle). No code is copied.

版本与发布记录

@cssints/motion 共发布 43 个版本,首次发布于 2026/10/11;过去 12 个月发布了 43 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.35.1latest2026/11/073 天前
0.35.02026/11/073 天前
0.34.02026/11/073 天前
0.33.02026/11/046 天前
0.32.02026/11/046 天前
0.31.02026/11/047 天前

关于 @cssints/motion 的常见问题

@cssints/motion 是什么?

Animation presets for cssints: fade, slide, scale and blur in and out as one kernel over keyframes(), with prefers-reduced-motion

如何安装 @cssints/motion?

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

@cssints/motion 支持 TypeScript 吗?

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

@cssints/motion 支持 ESM 还是 CommonJS?

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

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

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

@cssints/motion 可以商用吗?

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

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

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

@cssints/motion 还在维护吗?

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