Skip to content

majiayu000/spellbook / skills/form-motion

form-motion

Verified

FORM UI 动效词典:10 个克制、跟手、可访问的界面微交互,每个都配原始提示词、可改项、验收标准和自动验收脚本——连续形变按钮、液体标签指示器、弹性滑块、柔性开关、原位展开卡片、层叠通知、命令面板、拖动排序、跟随提示、自绘折线图。共用一个从当前位置和速度重定向的阻尼弹簧。当用户说「按钮自己变成加载和完成」「选中条像软糖追过去」「拖到头还能拽一点」「开关圆点拉长」「卡片原位展开」「通知层叠」「Cmd+K 命令面板」「拖动排序」「提示跟随鼠标」「折线自己画出来」,或点名 FORM 动效库、要把某个样例用到自己的页面时使用。只在明确请求时触发,忽略顺带提及。

FileKindSize
SKILL.mdskill md9.3 KB
assets/motion.jsscript3.1 KB
assets/reference.htmlother96.6 KB
assets/skins/hud.cssother4.2 KB
references/catalog.jsonconfig14.6 KB
references/samples.mdmarkdown18.7 KB
scripts/build_samples_md.pyscript5.2 KB
scripts/lib/env.mjsscript3.5 KB
scripts/package.jsonmanifest285 B
scripts/verify.mjsscript35.2 KB

assets/motion.js

View on GitHub
// FORM motion kit: an exact damped spring that retargets from the current position and velocity.
// Every sample uses it. Plain script, no dependencies; exposes window.FormMotion.
// Also works as an ES module: `import './motion.js'` then read globalThis.FormMotion.
(function (root) {
  const reduced = root.matchMedia ? root.matchMedia('(prefers-reduced-motion: reduce)') : { matches: false };
  const clamp = (v, a, b) => Math.min(b, Math.max(a, v));

  // One Motion drives several named values. `w` is the spring's angular frequency (higher = faster);
  // damping ratio 0.84 gives a small overshoot (~1–2 %). Values are a pure function of time since the last
  // retarget, so interrupting a motion never jumps: set() samples the current trajectory first.
  class Motion {
    constructor(initial, render, { w = 22, zeta = 0.84 } = {}) {
      this.s = {}; this.render = render; this.raf = 0; this.zeta = zeta;
      for (const [k, v] of Object.entries(initial)) this.s[k] = { x: v, v: 0, to: v, t: performance.now(), w };
      this.draw();
    }
    sample(s, now) {
      const t = (now - s.t) / 1000, z = this.zeta, w = s.w, a = z * w, b = w * Math.sqrt(1 - z * z);
      const d = s.x - s.to, c = (s.v + a * d) / b, e = Math.exp(-a * t), co = Math.cos(b * t), si = Math.sin(b * t);
      return { x: s.to + e * (d * co + c * si), v: e * ((-a * d + b * c) * co + (-a * c - b * d) * si) };
    }
    values() { const now = performance.now(); return Object.fromEntries(Object.entries(this.s).map(([k, s]) => [k, this.sample(s, now).x])); }
    velocities() { const now = performance.now(); return Object.fromEntries(Object.entries(this.s).map(([k, s]) => [k, this.sample(s, now).v])); }
    draw() { this.render(this.values()); }
    // targets: {key: to}; speeds: {key: w} to give one value a different spring (e.g. leading vs trailing edge);
    // velocities: {key: v} to hand over a release velocity (e.g. after a drag).
    set(targets, speeds = {}, velocities = {}) {
      const now = performance.now();
      for (const [k, to] of Object.entries(targets)) {
        const old = this.s[k], p = this.sample(old, now);
        this.s[k] = { x: reduced.matches ? to : p.x, v: reduced.matches ? 0 : (velocities[k] ?? p.v), to, t: now, w: speeds[k] || old.w };
      }
      reduced.matches ? this.draw() : this.start();
    }
    // Jump without animation (direct manipulation while dragging, or reduced motion).
    snap(targets) { const now = performance.now(); for (const [k, to] of Object.entries(targets)) this.s[k] = { ...this.s[k], x: to, to, v: 0, t: now }; this.draw(); }
    settled() { const now = performance.now(); return Object.values(this.s).every(s => { const p = this.sample(s, now); return Math.abs(p.x - s.to) <= 0.01 && Math.abs(p.v) <= 0.05; }); }
    start() {
      if (this.raf) return;
      const tick = () => { this.raf = 0; this.draw(); if (!this.settled()) this.raf = requestAnimationFrame(tick); };
      this.raf = requestAnimationFrame(tick);
    }
    dispose() { cancelAnimationFrame(this.raf); this.raf = 0; }
  }

  root.FormMotion = { Motion, reduced, clamp };
})(typeof window !== 'undefined' ? window : globalThis);
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 198kUpdated Claude CodeCodexVerifiedInstall