mcpField
T
theatre-js

theatre-js

github.com/jbmanllrデザイン・UI199 回インストール39 週間前に更新
リポジトリ

theatre-js について

theatre-jsは、Web向けのモーション制作を行う開発者のためのTheatre.jsガイドです。ビジュアルタイムラインのStudioとプログラム制御を解説し、ReactやReact Three Fiberとの連携、プロダクション運用も扱います。

主な機能

  1. 01Studioによるビジュアルタイムライン編集
  2. 02プロジェクト、オブジェクト、シーケンス管理
  3. 03キーフレームアニメーションの再生制御
  4. 04ReactとR3Fの連携パターン
  5. 05状態の書き出しと本番運用ガイド

活用シーン

  1. 01DOM要素のタイムラインアニメーション制作
  2. 02Reactコンポーネントでのアニメーション値取得
  3. 03React Three Fiberシーンの編集
  4. 04本番向けアニメーション状態の書き出し

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/jbmanllr/agent-skills --skill theatre-js

インストール後、Claude Code で/theatre-jsを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

README.md
references/
01-core.md
02-prop-types.md
03-studio.md
04-react-integration.md
05-r3f-integration.md
06-production.md

詳細

Theatre.js のベストプラクティス

Web 向けのモーションデザインエディター兼アニメーションライブラリです。プログラムから操作できるビジュアルタイムラインエディター(Studio)を提供します。

インストール

# Core + Studio (development)
npm install @theatre/[email protected] @theatre/[email protected]

# React Three Fiber integration
npm install @theatre/[email protected]

# React utilities
npm install @theatre/react

# Theatric (simplified controls)
npm install theatric

クイックスタート

import * as core from '@theatre/core'
import studio from '@theatre/studio'

// Initialize Studio (dev only)
if (import.meta.env.DEV) {
  studio.initialize()
}

// Create project → sheet → object
const project = core.getProject('My Project')
const sheet = project.sheet('Main')
const obj = sheet.object('Box', {
  position: { x: 0, y: 0 },
  opacity: 1
})

// Read values
console.log(obj.value.position.x)

// Listen to changes
obj.onValuesChange((values) => {
  element.style.opacity = values.opacity
  element.style.transform = `translate(${values.position.x}px, ${values.position.y}px)`
})

// Play animation
sheet.sequence.play({ iterationCount: Infinity })

主な概念

概念説明
Projectすべてのアニメーションデータを格納するコンテナです。エクスポートされた JSON の状態に対応します
Sheetシーンまたはコンポーネントです。オブジェクトと 1 つのシーケンスを含みます
Object型付きプロパティを持つ、アニメーション可能なエンティティです
Sequenceキーフレームを含むタイムラインです。再生を制御します
Props型付きの値です(number、compound、rgba など)

リファレンス一覧

リファレンス使用する場面
references/01-core.mdプロジェクトのセットアップ、シート、オブジェクト、シーケンス、再生制御
references/02-prop-types.mdプロパティの定義、カスタム型、複合プロパティ、制約
references/03-studio.mdStudio の UI、キーボードショートカット、拡張機能、パネル
references/04-react-integration.mduseVal、usePrism、@theatre/react フック
references/05-r3f-integration.mdReact Three Fiber、編集可能なコンポーネント、SheetProvider
references/06-production.md状態のエクスポート、アセット、デプロイ、ツリーシェイキング

よくあるパターン

DOM 要素のアニメーション
const obj = sheet.object('Card', {
  x: 0,
  y: 0,
  rotation: 0,
  scale: 1,
  opacity: 1
})

obj.onValuesChange(({ x, y, rotation, scale, opacity }) => {
  element.style.transform = `translate(${x}px, ${y}px) rotate(${rotation}deg) scale(${scale})`
  element.style.opacity = opacity
})
シーケンスの再生制御
const seq = sheet.sequence

// Play once
seq.play()

// Play with options
seq.play({
  iterationCount: Infinity,  // loop forever
  range: [0, 2],             // play seconds 0-2
  rate: 1.5,                 // 1.5x speed
  direction: 'alternate'     // ping-pong
})

// Pause and seek
seq.pause()
seq.position = 1.5  // jump to 1.5s

// Await completion
await seq.play({ iterationCount: 1 })
console.log('Animation complete')
React Three Fiber のシーン
import { Canvas } from '@react-three/fiber'
import { editable as e, SheetProvider } from '@theatre/r3f'
import { getProject } from '@theatre/core'
import studio from '@theatre/studio'
import extension from '@theatre/r3f/dist/extension'

// Dev setup
if (import.meta.env.DEV) {
  studio.initialize()
  studio.extend(extension)
}

const sheet = getProject('R3F Demo').sheet('Scene')

function App() {
  return (
    <Canvas>
      <SheetProvider sheet={sheet}>
        <e.mesh theatreKey="Cube">
          <boxGeometry />
          <meshStandardMaterial color="orange" />
        </e.mesh>
        <e.pointLight theatreKey="Light" position={[10, 10, 10]} />
      </SheetProvider>
    </Canvas>
  )
}
Theatre のコントロール(シンプル)
import { useControls, types } from 'theatric'

function Component() {
  const { color, intensity, position } = useControls({
    color: '#ff0000',
    intensity: types.number(1, { range: [0, 2] }),
    position: { x: 0, y: 0, z: 0 }
  })

  return <mesh position={[position.x, position.y, position.z]} />
}

避けるべき重大なミス

1. 本番環境での Studio
// ❌ Includes studio in bundle
import studio from '@theatre/studio'
studio.initialize()

// ✅ Dev-only initialization
if (import.meta.env.DEV) {
  studio.initialize()
}
2. 本番環境での状態の欠落
// ❌ No animations without state
const project = core.getProject('My Project')

// ✅ Load exported state
import state from './state.json'
const project = core.getProject('My Project', { state })
3. オブジェクトキーの衝突
// ❌ Same key = same object (shared state)
sheet.object('Box', { x: 0 })
sheet.object('Box', { y: 0 })  // Overwrites!

// ✅ Unique keys per object
sheet.object('Box1', { x: 0 })
sheet.object('Box2', { y: 0 })
4. R3F 拡張機能の欠落
// ❌ No 3D controls in Studio
studio.initialize()

// ✅ Extend with R3F extension
import extension from '@theatre/r3f/dist/extension'
studio.initialize()
studio.extend(extension)
5. theatreKey の指定忘れ
// ❌ Not editable
<e.mesh>

// ✅ Requires theatreKey
<e.mesh theatreKey="MyCube">

クイックリファレンス

タスク解決方法
プロジェクトの作成getProject('Name', { state? })
シートの作成project.sheet('Name')
オブジェクトの作成sheet.object('Key', { props })
値の変更を監視obj.onValuesChange(cb)
値の読み取りobj.value.propName
アニメーションの再生sheet.sequence.play(opts?)
アニメーションの一時停止sheet.sequence.pause()
位置のシークsheet.sequence.position = 1.5
R3F で編集可能にする<e.mesh theatreKey="Key">
React の値フックuseVal(obj.props.x)
状態のエクスポートStudio → Project → Export (JSON)

コメント