Skip to content

const mount: <S>(root, data?, options?) => Player<S>

Mounts a player on an exported root and returns it (root.rupa holds it too).

With data, the table is checked first: a part that fails is left out (the development build warns), a table of an unknown version is ignored. Without data, the page’s <script type="application/json" data-rupa-data="<class>"> whose class the root has is read; without one the player controls the root’s animations alone, with no state. A root that a player holds already (of this copy of the player or another) returns that player.

S extends string = string

Element

The export’s root element (the one with data-rupa).

PlayerDataInput

The flow’s table (PlayerData, e.g. imported from the export’s <base>.player.json); none to read it from the page.

Readonly<Record<never, never>>

None yet.

Player<S>

The root’s player. Only when reading data itself throws (a hostile getter) is nothing mounted: undefined.

When root is not an object. Nothing else throws: an internal error makes the player inert.

import { mount } from "@rupamotion/player";
import data from "./hero.player.json";
const player = mount<"idle" | "hover">(document.querySelector(".hero")!, data);
player.on("statechange", ({ state }) => console.log(state));