Get the FREE Ultimate OpenClaw Setup Guide →

theatre-js

npx machina-cli add skill noklip-io/agent-skills/theatre-js --openclaw
Files (1)
SKILL.md
5.9 KB

Theatre.js Best Practices

Motion design editor and animation library for the web. Provides a visual timeline editor (Studio) with programmatic control.

Installation

# Core + Studio (development)
npm install @theatre/core@0.7 @theatre/studio@0.7

# React Three Fiber integration
npm install @theatre/r3f@0.7

# React utilities
npm install @theatre/react

# Theatric (simplified controls)
npm install theatric

Quick Start

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 })

Core Concepts

ConceptDescription
ProjectContainer for all animation data; maps to exported JSON state
SheetA scene or component; contains objects and one sequence
ObjectAnimatable entity with typed props
SequenceTimeline with keyframes; controls playback
PropsTyped values (number, compound, rgba, etc.)

Reference Index

ReferenceUse When
references/01-core.mdProject setup, sheets, objects, sequences, playback control
references/02-prop-types.mdDefining props, custom types, compound props, constraints
references/03-studio.mdStudio UI, keyboard shortcuts, extensions, panels
references/04-react-integration.mduseVal, usePrism, @theatre/react hooks
references/05-r3f-integration.mdReact Three Fiber, editable components, SheetProvider
references/06-production.mdExport state, assets, deployment, tree-shaking

Common Patterns

Animate DOM Element

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
})

Sequence Playback Control

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 Scene

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>
  )
}

Theatric Controls (Simple)

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]} />
}

Critical Mistakes to Avoid

1. Studio in Production

// ❌ Includes studio in bundle
import studio from '@theatre/studio'
studio.initialize()

// ✅ Dev-only initialization
if (import.meta.env.DEV) {
  studio.initialize()
}

2. Missing State in Production

// ❌ 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. Object Key Collisions

// ❌ 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. Missing R3F Extension

// ❌ No 3D controls in Studio
studio.initialize()

// ✅ Extend with R3F extension
import extension from '@theatre/r3f/dist/extension'
studio.initialize()
studio.extend(extension)

5. Forgetting theatreKey

// ❌ Not editable
<e.mesh>

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

Quick Reference

TaskSolution
Create projectgetProject('Name', { state? })
Create sheetproject.sheet('Name')
Create objectsheet.object('Key', { props })
Listen to valuesobj.onValuesChange(cb)
Read valueobj.value.propName
Play animationsheet.sequence.play(opts?)
Pause animationsheet.sequence.pause()
Seek positionsheet.sequence.position = 1.5
R3F editable<e.mesh theatreKey="Key">
React value hookuseVal(obj.props.x)
Export stateStudio → Project → Export (JSON)

Source

git clone https://github.com/noklip-io/agent-skills/blob/main/skills/theatre-js/SKILL.mdView on GitHub

Overview

Theatre.js is a motion design editor and animation library for the web. It provides a visual timeline editor (Studio) with programmatic control, enabling precise keyframe animations across DOM, canvas, and 3D scenes. Core concepts like Project, Sheet, Object, Sequence, and Props organize animation data for React, R3F, and custom tooling.

How This Skill Works

Install the core Theatre.js packages and initialize Studio in development. Create a Project, a Sheet, and an Object with typed Props, then read and listen to value changes to drive rendering. Use the Sequence playback API to control timelines and keyframes across your animated elements.

When to Use It

  • Building a web-based motion design editor or visual timeline editor with Studio.
  • Animating Three.js or React Three Fiber scenes using Theatre.js keyframes.
  • Creating reusable keyframe animations for UI elements, SVGs, or DOM components.
  • Integrating Theatre.js with React (@theatre/react) or R3F (@theatre/r3f) workflows.
  • Developing custom animation tooling or exporting animation state for production deployment.

Quick Start

  1. Step 1: Install core and Studio packages plus React/R3F integrations (npm install @theatre/core@0.7 @theatre/studio@0.7 @theatre/r3f@0.7 @theatre/react open).
  2. Step 2: Initialize Studio in development: if (import.meta.env.DEV) { studio.initialize() }
  3. Step 3: Create project → sheet → object, read values, listen for changes, and control playback (e.g., sheet.sequence.play({ iterationCount: Infinity }))

Best Practices

  • Model your data with a Project → Sheet → Object hierarchy and strongly-typed Props to keep animations scalable.
  • Enable Studio only during development (initialize Studio in DEV) to keep production lean.
  • Bind UI directly to object values using onValuesChange to apply live updates to your rendering target.
  • Leverage Sequence playback options (range, rate, direction, iterationCount) for common patterns like looping or ping-pong.
  • Combine Theatre.js with React/R3F integrations to wire theatre keys to your 3D or UI components.

Example Use Cases

  • Animate a DOM card by updating transform and opacity in obj.onValuesChange and applying them to styles.
  • Play a looping UI animation with sheet.sequence.play({ iterationCount: Infinity }) for endless motion.
  • Wrap a Three.js cube with <e.mesh theatreKey="Cube"> inside a SheetProvider to drive 3D transforms.
  • Use Theatric controls to expose simple, high-level animation controls over Theatre.js timelines.
  • Dev Studio workflow: initialize studio in development and connect Studio state to your app during editing.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers