Communitygithub.com

モーションアドバンスド

React / Next.js向け高度なモーションパターン — ドラッグ&ドロップ、ジェスチャー、テキストアニメーション、SVGパス描画、カスタムフック、命令型シーケンス(useAnimate)、ローダー、API決定木。motion-foundationsが必要です。

モーションアドバンスド とは?

このスキルは、ReactおよびNext.jsプロジェクトにおいて、複雑でインタラクティブな物理ベースのアニメーションパターンを実装するための包括的なガイドです。基本的なモーションパターンでは不十分な場合に有効で、ドラッグ操作、スワイプ検出、テキストアニメーション、SVG描画など、高度なアニメーション要件をカバーします。主な出力として、ドラッグ可能なカード、並べ替え可能なリスト、テキストリビール、カスタムフック(useScrollRevealなど)、スピナーやシマーなどのローダーコンポーネントが含まれます。このスキルはmotion-foundationsの上に構築されており、すべてのトークン値はそこからインポートされ、インライン数値は禁止されています。Framer Motionのコア概念(useMotionValue、useTransform、useAnimate)の使用法を詳しく説明し、パフォーマンス最適化のためのルール(無限アニメーションの一時停止、モーション値の再作成防止、イベントリスナーのクリーンアップ)を提供します。コード例も豊富に含まれており、すぐに実装に活用できます。

対応~Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/503496348-ops/mischief-production/tree/HEAD/skills/ecc-motion-advanced

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

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

ドキュメント

モーションアドバンスド は何をしますか?

複雑でインタラクティブな物理ベースのアニメーションパターン。 最初にmotion-foundationsのセットアップが必要です。 motion-patternsでは不十分な場合に使用します。

アクティベーションのタイミング

  • ドラッグで閉じるシート、スワイプジェスチャー、並べ替え可能なリストを構築する場合
  • テキストを単語ごと、文字ごとにアニメーション化する場合、またはライブカウンターとして使用する場合
  • SVGパスの描画、アイコンのモーフィング、円形プログレスのアニメーション化を行う場合
  • カスタムアニメーションフック(useScrollReveal、マグネティックボタン、カーソルフォロワー)を作成する場合
  • 複数ステップのアニメーションをuseAnimateで命令的にシーケンス化する場合
  • スピナー、シマースケルトン、パルスインジケーター、ローディングボタンの状態を構築する場合

出力

このスキルが生成するもの:

  • ドラッグインタラクション:ドラッグ可能なカード、ドラッグで閉じるシート、Reorder.Groupリスト
  • ジェスチャーフック:スワイプ検出、長押し、ピンチアウトライン
  • テキストアニメーションコンポーネント:単語リビール、文字タイプライター、数値カウンター
  • SVGアニメーション:パス描画、アイコンモーフ、ストロークプログレスリング
  • カスタムフック:useScrollReveal、useHoverScale、useNavigationDirection、useInViewOnce
  • 命令型シーケンス:useAnimateと割り込み安全なasync/await
  • ローダーコンポーネント:スピナー、シマー、パルスドット、プログレスバー、ボタンローディング状態

原則

  • 物理ベースのモーション(useSpring、springs.*)は、直接操作において、常に時間ベースのものよりも自然に感じられます。
  • useMotionValue + useTransformは、再レンダリングをトリガーせずに派生値を計算します。
  • useAnimateシーケンスは命令型で割り込み安全です。アニメーションの途中でanimate()を呼び出すと、前のアニメーションが自動的にキャンセルされます。
  • モーション値(useMotionValue、useSpring)はSSRセーフであり、ハイドレーションエラーを引き起こしません。

ルール

  1. ドラッグインタラクションはマウスだけでなく、タッチデバイスでもテストする必要があります。 dragプロップは両方で動作しますが、感触としきい値が異なります。
  2. 無限アニメーションは、document.visibilityState === "hidden"のときは一時停止する必要があります。 バックグラウンドタブはGPU/CPUを消費してはいけません。
  3. スワイプのしきい値は明示的に指定する必要があります。 速度のみから意図を推測してはいけません。offsetとvelocityのチェックを組み合わせます。
  4. useAnimateスコープrefは、マウントされたDOM要素にアタッチする必要があります。 マウント前にanimate()を呼び出すと、静かに失敗します。
  5. モーション値をレンダー内で再作成してはいけません。 コンポーネント本体内のuseMotionValue(0)は正しいです。レンダー内のnew MotionValue(0)は正しくありません。
  6. すべてのトークン値はmotion-foundationsからインポートされます。 インライン数値は禁止です。
  7. カスタムフックはクリーンアップを処理する必要があります。 すべてのwindow.addEventListenerには、useEffectのreturnに対応するremoveEventListenerが必要です。
  8. SVGモーフィングには、等しいパスコマンド数が必要です。 コマンド構造が異なるパスは、補間ではなくスナップします。

決定ガイダンス

適切な高度なAPIの選択

シナリオAPI
リリース時に物理ベースのドラッグdrag + dragTransition: springs.release
順序付きドラッグで並べ替え可能なリストReorder.Group + Reorder.Item
ドラッグオフセットで閉じるdrag="y" + onDragEndオフセットチェック
左/右へのスワイプdrag="x" + onDragEndオフセットチェック
長押しuseLongPressフック
時間経過で平滑化された値useSpring
別の値から派生した値useTransform
複数ステップのシーケンスuseAnimateとasync/await
1回限りの命令型アニメーションanimate()(motionから)
単語ごとにテキストを表示inline-blockスパンでstagger
SVG描画オンpathLength 0 → 1
SVGモーフd属性トゥイーン(等しいコマンド)
円形プログレスstrokeDashoffsetトゥイーン

useSpringとスプリングトランジションの使い分け

useSpringtransition: springs.*
使用する場面カーソルフォロワー、ポインター追跡値離散的な状態変化
更新方法連続的、すべてのフレームで状態変化によってトリガー
割り込みスムーズ — 物理法則が速度から拾う現在の値から再開

コアコンセプト

useMotionValue + useTransform

再レンダリングなしのリアクティブ計算:

const x = useMotionValue(0)
const opacity = useTransform(x, [-200, 0, 200], [0, 1, 0])
// opacityはxが変化するたびにすべてのフレームで更新 — setStateなし、再レンダリングなし

useAnimate

[scope, animate]を返します。スコープrefはDOM要素にアタッチする必要があります。 animate()呼び出しは割り込み安全です。途中で呼び出すと、前の実行がキャンセルされます。

const [scope, animate] = useAnimate()

async function play() {
  await animate(".step-1", { opacity: 1 }, { duration: 0.3 })
  await animate(".step-2", { x: 0 },       { duration: 0.4 })
        animate(".step-3", { scale: 1 },    { duration: 0.25 })  // 発行して忘れる
}

return <div ref={scope}>...</div>

コード例

ドラッグ可能なカード

"use client"
import { motion } from "motion/react"
import { springs, motionTokens } from "@/lib/motion-tokens"

<motion.div
  drag
  dragConstraints={{ left: -100, right: 100, top: -100, bottom: 100 }}
  dragElastic={0.1}
  whileDrag={{
    scale: motionTokens.scale.pop,
    boxShadow: "0 16px 40px rgba(0,0,0,0.2)",
  }}
  dragTransition={springs.release}
/>

ドラッグで閉じるシート

"use client"
import { motion, useMotionValue, useTransform } from "motion/react"

export function BottomSheet({ onClose }: { onClose: () => void }) {
  const y = useMotionValue(0)
  const opacity = useTransform(y, [0, 200], [1, 0])

  return (
    <motion.div
      drag="y"
      dragConstraints={{ top: 0 }}
      style={{ y, opacity }}
      onDragEnd={(_, info) => {
        // ルール3: offset + velocityを組み合わせる
        if (info.offset.y > 120 || info.velocity.y > 500) onClose()
      }}
    />
  )
}

並べ替え可能なリスト

"use client"
import { Reorder } from "motion/react"

export function SortableList() {
  const [items, setItems] = useState(initialItems)
  return (
    <Reorder.Group axis="y" values={items} onReorder={setItems}>
      {items.map((item) => (
        <Reorder.Item key={item.id} value={item}>
          {item.label}
        </Reorder.Item>
      ))}
    </Reorder.Group>
  )
}

スワイプ検出

"use client"
import { motion } from "motion/react"

const OFFSET_THRESHOLD  = 50
const VELOCITY_THRESHOLD = 300

<motion.div
  drag="x"
  dragConstraints={{ left: 0, right: 0 }}
  onDragEnd={(_, info) => {
    const swipedRight = info.offset.x > OFFSET_THRESHOLD  || info.velocity.x > VELOCITY_THRESHOLD
    const swipedLeft  = info.offset.x < -OFFSET_THRESHOLD || info.velocity.x < -VELOCITY_THRESHOLD
    if (swipedRight) onSwipeRight()
    if (swipedLeft)  onSwipeLeft()
  }}
/>

長押しフック

import { useRef } from "react"

export function useLongPress(callback: () => void, ms = 600) {
  const timerRef = useRef<ReturnType<typeof setTimeout>>()
  return {
    onPointerDown:  () => { timerRef.current = setTimeout(callback, ms) },
    onPointerUp:    () => clearTimeout(timerRef.current),
    onPointerLeave: () => clearTimeout(timerRef.current),
  }
}

単語ごとのリビール

"use client"
import { motion } from "motion/react"
import { springs } from "@/lib/motion-tokens"

export function AnimatedText({ text }: { text: string }) {
  return (
    <motion.p
      variants={{ visible: { transition: { staggerChildren: 0.05 } } }}
      initial="hidden"
      animate="visible"
    >
      {text.split(" ").map((word, i) => (
        <motion.span
          key={i}
          className="inline-block mr-1"
          variants={{
            hidden:  { opacity: 0, y: 12 },
            visible: { opacity: 1, y: 0, transition: springs.gentle },
          }}
        >
          {word}
        </motion.span>
      ))}
    </motion.p>
  )
}

数値カウンター

"use client"
import { useRef, useEffect } from "react"
import { animate } from "motion"
import { motionTokens } from "@/lib/motion-tokens"

export function Counter({ to }: { to: number }) {
  const nodeRef = useRef<HTMLSpanElement>(null)

  useEffect(() => {
    const controls = animate(0, to, {
      duration: motionTokens.duration.crawl,
      ease: motionTokens.easing.smooth,
      onUpdate: (v) => {
        if (nodeRef.current) nodeRef.current.textContent = Math.round(v).toString()
      },
    })
    return controls.stop   // ルール7: クリーンアップ
  }, [to])

  return <span ref={nodeRef} />
}

SVGパス描画オン

"use client"
import { motion } from "motion/react"
import { motionTokens } from "@/lib/motion-tokens"

<motion.path
  d="M 0 100 Q 50 0 100 100"
  initial={{ pathLength: 0, opacity: 0 }}
  animate={{ pathLength: 1, opacity: 1 }}
  transition={{ duration: motionTokens.duration.slow, ease: motionTokens.easing.smooth }}
/>

ストロークプログレスリング

"use client"
import { motion } from "motion/react"
import { motionTokens } from "@/lib/motion-tokens"

const CIRCUMFERENCE = 2 * Math.PI * 40   // r=40

export function ProgressRing({ progress }: { progress: number }) {
  return (
    <svg width="100" height="100" viewBox="0 0 100 100">
      <circle cx="50" cy="50" r="40" fill="none" stroke="#e5e7eb" strokeWidth="8" />
      <motion.circle
        cx="50" cy="50" r="40"
        fill="none" stroke="#6366f1" strokeWidth="8"
        strokeLinecap="round"
        strokeDasharray={CIRCUMFERENCE}
        animate={{ strokeDashoffset: CIRCUMFERENCE - (progress / 100) * CIRCUMFERENCE }}
        transition={{ duration: motionTokens.duration.normal, ease: motionTokens.easing.smooth }}
        style={{ rotate: -90, transformOrigin: "center" }}
      />
    </svg>
  )
}

useScrollRevealフック

"use client"
import { useRef } from "react"
import { useScroll, useTransform } from "motion/react"
import { motionTokens } from "@/lib/motion-tokens"

export function useScrollReveal() {
  const ref = useRef(null)
  const { scrollYProgress } = useScroll({ target: ref, offset: ["start end", "end start"] })
  const opacity = useTransform(scrollYProgress, [0, 0.3], [0, 1])
  const y       = useTransform(scrollYProgress, [0, 0.3], [motionTokens.distance.lg, 0])
  return { ref, style: { opacity, y } }
}

// 使用例
const { ref, style } = useScrollReveal()
<motion.section ref={ref} style={style} />

カーソルフォロワー

"use client"
import { useEffect } from "react"
import { motion, useMotionValue, useSpring } from "motion/react"
import { springs } from "@/lib/motion-tokens"

export function CursorFollower() {
  const x = useMotionValue(-100)
  const y = useMotionValue(-100)
  const sx = useSpring(x, springs.gentle)
  const sy = useSpring(y, springs.gentle)

  useEffect(() => {
    const move = (e: MouseEvent) => { x.set(e.clientX); y.set(e.clientY) }
    window.addEventListener("mousemove", move)
    return () => window.removeEventListener("mousemove", move)   // ルール7
  }, [])

  return (
    <motion.div
      className="fixed top-0 left-0 w-6 h-6 rounded-full bg-indigo-500
                 pointer-events-none -translate-x-1/2 -translate-y-1/2 z-50"
      style={{ x: sx, y: sy }}
    />
  )
}

シマースケルトン

"use client"
import { useEffect } from "react"
import { motion, useAnimation } from "motion/react"
import { motionTokens } from "@/lib/motion-tokens"

export function ShimmerSkeleton({ className = "" }: { className?: string }) {
  const controls = useAnimation()

  useEffect(() => {
    const play = () =>
      controls.start({
        x: ["-100%", "100%"],
        transition: {
          repeat: Infinity,
          duration: motionTokens.duration.crawl,
          ease: motionTokens.easing.linear,
        },
      })

    const handleVisibility = () => {
      if (document.visibilityState === "hidden") controls.stop()
      else void play()
    }

    void play()
    document.addEventListener("visibilitychange", handleVisibility)
    return () => {
      controls.stop()
      document.removeEventListener("visibilitychange", handleVisibility)
    }
  }, [controls])

  return (
    <div className={`relative overflow-hidden bg-gray-200 rounded ${className}`}>
      <motion.div
        className="absolute inset-0 bg-gradient-to-r from-transparent via-white/60 to-transparent"
        initial={{ x: "-100%" }}
        animate={controls}
      />
    </div>
  )
}

ボタンローディング状態

"use client"
import { motion, AnimatePresence } from "motion/react"
import { motionTokens, springs } from "@/lib/motion-tokens"

export function LoadingButton({
  loading,
  label,
  onClick,
}: {
  loading: boolean
  label: string
  onClick: () => void
}) {
  return (
    <motion.button
      onClick={onClick}
      animate={{ opacity: loading ? 0.7 : 1 }}
      whileTap={loading ? {} : { scale: motionTokens.scale.press }}
      transition={springs.snappy}
      disabled={loading}
    >
      <AnimatePresence mode="wait">
        {loading ? (
          <motion.span
            key="loading"
            initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }}
            transition={{ duration: motionTokens.duration.fast }}
          >
            …
          </motion.span>
        ) : (
          <motion.span
            key="label"
            initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }}
            transition={{ duration: motionTokens.duration.fast }}
          >
            {label}
          </motion.span>
        )}
      </AnimatePresence>
    </motion.button>
  )
}

可視性で一時停止する無限アニメーション

"use client"
import { useEffect } from "react"
import { motion, useAnimation } from "motion/react"
import { motionTokens } from "@/lib/motion-tokens"

export function PulseDot() {
  const controls = useAnimation()

  useEffect(() => {
    const pulse = () =>
      controls.start({
        scale: [1, 1.4, 1],
        opacity: [1, 0.6, 1],
        transition: { repeat: Infinity, duration: motionTokens.duration.crawl },
      })

    // ルール2: タブが非表示のときに一時停止
    const handleVisibility = () => {
      if (document.visibilityState === "hidden") controls.stop()
      else void pulse()
    }

    void pulse()
    document.addEventListener("visibilitychange", handleVisibility)
    return () => {
      controls.stop()
      document.removeEventListener("visibilitychange", handleVisibility)
    }
  }, [controls])

  return (
    <motion.div
      className="w-4 h-4 rounded-full bg-indigo-500"
      animate={controls}
    />
  )
}

Individual skills in this repo

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

503496348-ops/mischief-production

Use this skill when inspecting Blender characters, rigs, poses, animation retargeting, ground contact, facing direction, or model-vs-motion alignment where screenshots alone are not enough.

503496348-ops/mischief-production

Build reusable Manim explainers for technical concepts, graphs, system diagrams, and product walkthroughs, then hand off to the wider HCP video stack if needed. Use when the user wants a clean animated explainer rather than a generic talking-head script.

503496348-ops/mischief-production

Motion tokens, spring presets, performance rules, device adaptation, accessibility enforcement, and SSR safety for React / Next.js using motion/react. Foundation layer — all other motion skills depend on this.

503496348-ops/mischief-production

Production-ready animation patterns for React / Next.js — button, modal, toast, stagger, page transitions, exit animations, scroll, and layout — built on motion-foundations tokens and springs.

503496348-ops/mischief-production

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

503496348-ops/mischief-production

Best practices for Remotion - Video creation in React. 29 domain-specific rules covering 3D, animations, audio, captions, charts, transitions, and more.

503496348-ops/mischief-production

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

関連スキル