Skip to content
Skip to content
Web playback

Use Chorono with Vue

Use @chorono/runtime in a Vue component to play a Chorono scene on a canvas. This is a lifecycle integration for the JavaScript package, not a separately published Vue SDK.

Prepare the scene#

Install version 0.1.0 using the JavaScript guide. Save the title-card runtime JSON in your public directory as /animation.runtime.json.

Mount and release#

Load the browser runtime after mounting. Abort a pending scene request when the component unmounts and destroy the owned player to stop its clock and listeners.

<script setup lang="ts">
import { onMounted, onBeforeUnmount, ref } from 'vue'
import type { ChronoPlayer } from '@chorono/runtime'

const canvas = ref<HTMLCanvasElement | null>(null)
const status = ref('Loading animation…')
const ready = ref(false)
const controller = new AbortController()
let player: ChronoPlayer | undefined

onMounted(async () => {
  try {
    const [{ ChronoPlayer, CanvasRenderAdapter }, response] = await Promise.all([
      import('@chorono/runtime'),
      fetch('/animation.runtime.json', { signal: controller.signal }),
    ])
    if (!response.ok) throw new Error('Scene could not load')
    const exported = await response.json()
    if (controller.signal.aborted || !canvas.value) return
    const context = canvas.value.getContext('2d')
    if (!context) throw new Error('Canvas 2D is unavailable')
    canvas.value.width = exported.runtime.composition.width
    canvas.value.height = exported.runtime.composition.height
    player = new ChronoPlayer(exported.runtime, new CanvasRenderAdapter(context), { loop: true })
    player.seek(0)
    status.value = 'Ready'
    ready.value = true
  } catch (error) {
    if (!controller.signal.aborted) status.value = String(error)
  }
})

onBeforeUnmount(() => {
  controller.abort()
  player?.destroy()
})
</script>

<template>
  <figure>
    <canvas ref="canvas" aria-label="Chorono animation" style="width: 100%; height: auto" />
    <figcaption role="status">{{ status }}</figcaption>
    <button :disabled="!ready" @click="player?.play()">Play</button>
    <button :disabled="!ready" @click="player?.pause()">Pause</button>
  </figure>
</template>

Extend the example#

If your component accepts a changing scene URL, dispose the old player and abort its request before loading the replacement. This example loads one fixed scene per mount.

The example waits for the visitor to start playback. Add visibility handling appropriate to your app and inspect your own export's warnings. See the JavaScript API for parameters, events and time controls, and SDK downloads for distribution files.

A good place to start
Getting started / Chorono documentationChorono documentationLearn Chorono with editable animation examples. Install the editor, edit keyframes, build loops and connect Claude Code or Codex through MCP. Cre…Getting started / Install ChoronoInstall ChoronoSet up the free, open-source animation editor on your computer and start a local browser session. This guide installs the browser editor, its loc…Getting started / Create your first editable animationCreate your first editable animationOpen an editable Chorono example, change its text and colors, inspect the timeline, then save and reopen your first 2D animation. Start with a re…Workspace / Chorono editor workspaceChorono editor workspaceFind the canvas, layers, properties, timeline and resource tools in the Chorono editor. Choose a guide for each part of your animation workflow.…Workspace / Canvas and drawing toolsCanvas and drawing toolsNavigate the canvas, draw shapes and splines, use snapping and edit motion keys in Chorono. Use the canvas to arrange the objects in your composi…Workspace / Choose a drawing or transform toolChoose a drawing or transform toolUse Select, Pan, Pen, Move, Rotate, Scale and Anchor tools without losing track of the active editing mode. Choose the tool that matches the edit…Workspace / Select exactly the objects you needSelect exactly the objects you needUse box, lasso, circle, paint and rule-based selection to work with several animation layers. When several objects overlap, clicking each one can…Workspace / Align objects with guides and snappingAlign objects with guides and snappingSet grid, object, point, guide, pixel, angle and scale snapping for precise placement in Chorono. Snapping helps a dragged object settle on an ex…Workspace / Edit Bézier points and spline curvesEdit Bézier points and spline curvesDraw editable paths, adjust points and handles, and extend or close a spline in Chorono. A curve is easier to control when you can see the points…Workspace / Edit animation positions on the canvasEdit animation positions on the canvasUse Motion Keys to adjust position keys, draw a movement and control how the path is timed. Motion Keys bring position editing onto the canvas. T…Workspace / Layers and scene hierarchyLayers and scene hierarchySelect, name, group and organize scene objects in Chorono using the Layers panel and Scene Explorer. A layer is an editable object in your Choron…Workspace / Draw and edit basic shapesDraw and edit basic shapesCreate rectangles, circles, polygons and procedural shapes, then adjust their geometry in Properties. Basic shapes are a useful starting point fo…
Explore the docs