Communitygithub.com

運動基礎

為 React / Next.js 使用 motion/react 定義的運動令牌、彈簧預設、效能規則、裝置適應、無障礙強制與 SSR 安全性。基礎層 — 所有其他運動技能都依賴於此。在 React 或 Next.js 中設定運動令牌、彈簧預設、減少動作處理或 SSR 安全動畫時使用。

運動基礎 是什麼?

這個技能定義了運動系統的基礎層,提供所有下游技能(如 motion-patterns 和 motion-advanced)都將繼承的共享值、約束和規則。它包括一個 motionTokens 物件(涵蓋持續時間、緩動、距離和縮放)、一個帶有五個命名配置的 springs 預設映射,以及一個用於基於使用者偏好和裝置能力控制動畫的 shouldAnimate() 閘道。該技能強制執行嚴格的編碼標準以確保無障礙,例如在偏好減少動作時停用所有轉換,透過確保初始狀態與伺服器輸出相符來防止 SSR 水合警告,以及禁止使用 framer-motion 而支援新的 motion/react 套件。它還處理低階裝置檢測以限制非必要動畫,並為開發人員提供有關何時以及如何將動畫整合到 React 或 Next.js 應用程式中的明確指引和決策指南。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/ECC/tree/main/skills/motion-foundations

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

運動基礎 是做什麼的?

運動系統的基礎層。定義所有下游技能(motion-patterns、motion-advanced)繼承的每個值、約束和規則。請在任何動畫工作開始前載入此技能。

何時啟用

  • 從頭開始建立任何動畫元件
  • 設定令牌、彈簧預設或緩動值
  • 實作 prefers-reduced-motion 支援
  • 除錯因動畫初始狀態導致的水合不一致
  • 評估動畫是否應該存在

產出

此技能產出:

  • 一個共享的 motionTokens 物件(持續時間、緩動、距離、縮放)
  • 一個共享的 springs 預設映射(5 個命名配置)
  • 所有元件使用的 shouldAnimate() 閘道
  • 透過 useReducedMotion 實現無障礙合規的動畫預設值
  • 零水合警告的 SSR 安全初始狀態

原則

動畫必須至少執行以下其中一項,否則必須被移除:

  • 引導注意力
  • 溝通狀態
  • 保持空間連續性

回應性始終優先於流暢度。一個導致輸入延遲的 60 fps 動畫比沒有動畫更糟。

規則

這些是不可協商的。它們適用於系統中的每個元件。

  1. 僅使用 motion/react。永遠不要從 framer-motion 匯入。切勿在相同元件樹中混用兩者。
  2. initial 必須與伺服器輸出相符。如果伺服器渲染 opacity: 1,則 initial prop 也必須是 opacity: 1。沒有例外。
  3. 減少動作覆蓋一切。當 useReducedMotion() 回傳 true 或 prefersReduced 為 true 時,所有轉換都被停用。僅允許持續時間 ≤ 0.2s 的透明度淡化作為後備。
  4. 永遠不要動畫化佈局屬性。width、height、top、left、margin、padding 被禁止用於 animate。僅使用 transform 和 opacity。
  5. 所有令牌值都來自 motionTokens。禁止在元件檔案中使用硬編碼的持續時間和緩動。
  6. 所有彈簧配置都來自 springs 映射。禁止使用內聯的 stiffness/damping 值。
  7. 每個從 motion/react 匯入的檔案都必須有 "use client"。
  8. 永遠不要在模組層級讀取 window 或 navigator。始終使用 typeof window !== "undefined" 進行保護。

決策指南

選擇持續時間

令牌使用時機
instant工具提示顯示/隱藏、焦點環、徽章更新
fast按鈕反饋、圖示切換、標籤切換
normal模態框開啟、卡片展開、頁面元素進入
slow英雄區進入、全頁面過渡
crawl刻意敍事;謹慎使用

選擇彈簧

預設使用時機
snappy預設 UI — 按鈕、標籤、導航項目
gentle卡片、模態框、面板輕柔落地
bouncy俏皮的時刻 — 空狀態、入門導覽
instant工具提示、彈出視窗、下拉選單
release拖曳釋放 — 自然的物理感覺

何時完全停用動畫

在以下情況下停用(讓 shouldAnimate() 回傳 false):

  • prefersReduced 為 true
  • isLowEnd 為 true 且動畫非必要
  • 元素在畫面外且永遠不會進入視窗
  • 動畫純粹是裝飾性,沒有 UX 目的

核心概念

令牌系統

// lib/motion-tokens.ts
export const motionTokens = {
  duration: {
    instant: 0.08,
    fast:    0.18,
    normal:  0.35,
    slow:    0.6,
    crawl:   1.0,
  },
  easing: {
    smooth: [0.22, 1, 0.36, 1],
    sharp:  [0.4, 0, 0.2, 1],
    bounce: [0.34, 1.56, 0.64, 1],
    linear: [0, 0, 1, 1],
  },
  distance: {
    xs: 4,
    sm: 8,
    md: 16,
    lg: 24,
    xl: 48,
  },
  scale: {
    subtle: 0.98,
    press:  0.95,
    pop:    1.04,
  },
}

export const springs = {
  snappy:  { type: "spring", stiffness: 300, damping: 30 },
  gentle:  { type: "spring", stiffness: 120, damping: 14 },
  bouncy:  { type: "spring", stiffness: 400, damping: 10 },
  instant: { type: "spring", stiffness: 600, damping: 35 },
  release: { type: "spring", stiffness: 200, damping: 20, restDelta: 0.001 },
}

執行時期旗標

// lib/motion-config.ts
export const motionConfig = {
  isLowEnd() {
    return (
      typeof navigator !== "undefined" &&
      navigator.hardwareConcurrency <= 4
    )
  },

  prefersReduced() {
    return (
      typeof window !== "undefined" &&
      window.matchMedia("(prefers-reduced-motion: reduce)").matches
    )
  },

  shouldAnimate({ essential = false } = {}) {
    if (this.prefersReduced()) return false
    if (!essential && this.isLowEnd()) return false
    return true
  },

  duration() {
    return this.isLowEnd() || this.prefersReduced()
      ? motionTokens.duration.instant
      : motionTokens.duration.normal
  },
}

無障礙

優先順序(從高到低):

  1. prefers-reduced-motion: reduce — 停用所有轉換,將透明度過渡限制在 ≤ 0.2s
  2. 低階裝置檢測 — 縮短持續時間,移除非必要動畫
  3. 設計偏好 — 其他所有情況

動畫必須優雅降級。它絕不能突然消失,導致佈局位移或使使用者迷失方向。

// hooks/use-reduced-motion.tsx
"use client"
import { useReducedMotion } from "motion/react"

export function useSafeMotion(fullY: number = 16) {
  const reduce = useReducedMotion()
  return {
    initial: { opacity: 0, y: reduce ? 0 : fullY },
    animate: { opacity: 1, y: 0 },
    exit:    { opacity: 0, y: reduce ? 0 : -fullY },
  }
}
/* globals.css */
@media (prefers-reduced-motion: reduce) {
  .motion-safe-transition  { transition: opacity 0.15s; }
  .motion-reduce-transform { transform: none !important; }
}
<!-- Tailwind -->
<div class="motion-safe:animate-fade motion-reduce:opacity-100"></div>

SSR / 水合安全性

規則:initial 必須始終與伺服器渲染的內容相符。

// 錯誤 — 伺服器渲染 opacity:1 但 initial 設為 0 → 水合不一致
<motion.div initial={{ opacity: 0 }} animate={{ opacity: 1 }} />

// 正確 — 使用 AnimatePresence 或延遲到用戶端掛載
"use client"
const [mounted, setMounted] = useState(false)
useEffect(() => setMounted(true), [])

<motion.div
  initial={{ opacity: mounted ? 0 : 1 }}
  animate={{ opacity: 1 }}
/>

程式碼範例

端到端:令牌 + 彈簧 + 無障礙 + SSR 保護

// components/fade-in-card.tsx
"use client"

import { useState, useEffect } from "react"
import { motion } from "motion/react"
import { motionTokens, springs } from "@/lib/motion-tokens"
import { useSafeMotion } from "@/hooks/use-reduced-motion"
import { motionConfig } from "@/lib/motion-config"

interface FadeInCardProps {
  children: React.ReactNode
  delay?: number
}

export function FadeInCard({ children, delay = 0 }: FadeInCardProps) {
  // SSR 保護 — initial 必須與伺服器輸出相符(opacity: 1)
  const [mounted, setMounted] = useState(false)
  useEffect(() => setMounted(true), [])

  // 無障礙 — 當偏好減少動作時停用轉換
  const safeMotion = useSafeMotion(motionTokens.distance.md)

  // 裝置閘道 — 在低階硬體上跳過動畫
  if (!motionConfig.shouldAnimate() || !mounted) {
    return <div>{children}</div>
  }

  return (
    <motion.div
      initial={safeMotion.initial}
      animate={safeMotion.animate}
      exit={safeMotion.exit}
      transition={{
        ...springs.gentle,
        delay,
      }}
      whileHover={{ scale: motionTokens.scale.pop }}
      whileTap={{ scale: motionTokens.scale.press }}
    >
      {children}
    </motion.div>
  )
}

約束 / 非目標

此技能不涵蓋:

  • UI 元件模式(按鈕、模態框、階梯動畫)→ 請參閱 motion-patterns
  • 拖曳、手勢、SVG、文字動畫、自訂 Hook → 請參閱 motion-advanced
  • 純 CSS 動畫或沒有 motion/react 的 Tailwind animate-* 類別
  • 第三方動畫庫(GSAP、anime.js 等)
  • 動畫設計決策(何時動畫、強調什麼)— 這是設計問題,不是程式碼約束

反模式

反模式違反的規則修正
import { motion } from "framer-motion"規則 1使用 motion/react
initial={{ opacity: 0 }} 用於 SSR 元件規則 2添加掛載保護
跳過 useReducedMotion 檢查規則 3使用 useSafeMotion hook
animate={{ width: "100%" }}規則 4改用 scaleX 轉換
內聯 transition={{ duration: 0.4 }}規則 5使用 motionTokens.duration.normal
內聯 { stiffness: 300, damping: 30 }規則 6使用 springs.snappy
缺少 "use client" 指令規則 7添加到檔案頂部
在模組層級使用 navigator.hardwareConcurrency規則 8包裹在 typeof navigator !== "undefined" 中

相關技能

  • motion-patterns — 使用此處定義的令牌和彈簧來建構按鈕、模態框、階梯動畫、頁面過渡和捲動模式。不重新定義任何值。
  • motion-advanced — 使用此處定義的令牌和彈簧來實現拖曳、SVG、文字和手勢模式。在此基礎上添加 useAnimate 序列和自訂 Hook。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

相關技能