Communitygithub.com

motion-foundations

React/Next.js向けのモーションの基礎レイヤー。モーショントークン、スプリングプリセット、パフォーマンスルール、デバイス適応、アクセシビリティ対応、SSR安全性を提供します。

motion-foundations とは?

motion-foundationsは、ReactおよびNext.jsアプリケーションにおけるアニメーションシステムの基盤となるスキルです。`motion/react`を利用し、モーショントークン(持続時間、イージング、距離、スケール)、5つの定義済みスプリングプリセット、`shouldAnimate()`ゲート、`useReducedMotion`フックによるアクセシビリティ準拠のアニメーションデフォルト、SSRセーフな初期状態を提供します。このスキルは、すべての下流スキル(motion-patterns、motion-advanced)が継承するルールと制約を定義します。主なルールには、`initial`プロパティとサーバー出力の一致、`prefers-reduced-motion`による全トランスフォームの無効化、レイアウトプロパティのアニメーション禁止、トークンとスプリングの一元管理、`

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/ECC/tree/main/skills/motion-foundations

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Motion Foundations

モーションシステムの基本層。下流のスキル(motion-patterns、motion-advanced)が継承するすべての値、制約、ルールを定義します。アニメーション作業を開始する前にこのスキルをロードしてください。

アクティブにするタイミング

  • アニメーションコンポーネントを一から作成する場合
  • トークン、スプリングプリセット、イージング値を設定する場合
  • prefers-reduced-motion サポートを実装する場合
  • アニメーションの初期状態によるハイドレーションの不一致をデバッグする場合
  • アニメーションがそもそも存在すべきかどうかを評価する場合

出力

このスキルは以下を生成します:

  • 共有 motionTokens オブジェクト(duration、easing、distance、scale)
  • 共有 springs プリセットマップ(5つの名前付き設定)
  • すべてのコンポーネントで使用される shouldAnimate() ゲート
  • useReducedMotion によるアクセシビリティ準拠のアニメーションデフォルト
  • ハイドレーション警告がゼロのSSRセーフな初期状態

原則

モーションは以下の少なくとも1つを実行する必要があります。そうでない場合は削除しなければなりません。

  • 注意を誘導する
  • 状態を伝える
  • 空間的連続性を維持する

応答性は常に滑らかさよりも優先されます。入力遅延を引き起こす60fpsのアニメーションは、アニメーションがないよりも悪いです。

ルール

これらは譲歩できません。システム内のすべてのコンポーネントに適用されます。

  1. motion/react のみを使用すること。 framer-motion からインポートしないでください。同じツリー内で2つを混在させないでください。
  2. initial はサーバーの出力と一致しなければなりません。 サーバーが opacity: 1 をレンダリングする場合、initial プロパティも opacity: 1 でなければなりません。例外はありません。
  3. 縮小モーションがすべてを上書きします。 useReducedMotion() が true を返すか、prefersReduced が true の場合、すべてのトランスフォームが無効になります。不透明度のみのフェード(≤ 0.2秒)のみが許可されたフォールバックです。
  4. レイアウトプロパティをアニメーション化しないでください。 width、height、top、left、margin、padding は animate での使用が禁止されています。transform と opacity のみを使用してください。
  5. すべてのトークン値は motionTokens から取得されます。 コンポーネントファイル内でのハードコードされたdurationやeasingは禁止されています。
  6. すべてのスプリング設定は springs マップから取得されます。 インラインの stiffness/damping 値は禁止されています。
  7. "use client" は必須です。motion/react からインポートするすべてのファイルに必要です。
  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.2秒に制限
  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、テキストアニメーション、カスタムフック → motion-advanced を参照
  • motion/react を使用しないCSSのみのアニメーションやTailwindの animate-* クラス
  • サードパーティのアニメーションライブラリ(GSAP、anime.jsなど)
  • モーションデザインの決定(いつアニメーションするか、何を強調するか)— それはコードの制約ではなく、デザインの問題です

アンチパターン

アンチパターン違反するルール修正
import { motion } from "framer-motion"ルール1motion/react を使用する
SSRコンポーネントでの initial={{ opacity: 0 }}ルール2マウントガードを追加する
useReducedMotion チェックの省略ルール3useSafeMotion フックを使用する
animate={{ width: "100%" }}ルール4代わりに scaleX トランスフォームを使用する
インラインの transition={{ duration: 0.4 }}ルール5motionTokens.duration.normal を使用する
インラインの { stiffness: 300, damping: 30 }ルール6springs.snappy を使用する
"use client" ディレクティブの欠落ルール7ファイルの先頭に追加する
モジュールレベルでの navigator.hardwareConcurrencyルール8typeof navigator !== "undefined" でラップする

関連スキル

  • motion-patterns — ここで定義されたトークンとスプリングを使用して、ボタン、モーダル、スタッガー、ページトランジション、スクロールパターンを構築します。値を再定義しません。
  • motion-advanced — ここで定義されたトークンとスプリングを使用して、ドラッグ、SVG、テキスト、ジェスチャーパターンを構築します。この基盤の上に useAnimate シーケンスとカスタムフックを追加します。

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.

関連スキル