mount
Copy as Markdown
constmount: <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.
Type Parameters
Section titled “Type Parameters”S extends string = string
Parameters
Section titled “Parameters”Element
The export’s root element (the one with data-rupa).
The flow’s table (PlayerData, e.g. imported from the export’s <base>.player.json); none to read it
from the page.
options?
Section titled “options?”Readonly<Record<never, never>>
None yet.
Returns
Section titled “Returns”Player<S>
The root’s player. Only when reading data itself throws (a hostile getter) is nothing mounted: undefined.
Throws
Section titled “Throws”When root is not an object. Nothing else throws: an internal error makes the player inert.
Example
Section titled “Example”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));