Skip to content

The full snippet

Copy as Markdown

Export the snippet with the “npm / CDN” runtime. It is markup, CSS and a <script type="application/json"> table, with no code. Add the player once:

<script type="module" src="https://cdn.jsdelivr.net/npm/@rupamotion/player@0.1.0/dist/element.js"></script>

Importing @rupamotion/player/element mounts every snippet root of the page. In a bundler, mount a root yourself:

import { mount } from "@rupamotion/player";
const player = mount(document.querySelector(".hero-root")); // reads the table of the page
// the same player: document.querySelector(".hero-root").rupa
player.on("statechange", (event) => console.log(event.state));

This snippet replays its highlight each time it scrolls into view:

PRINCIPLE 03
Ship the work that
matters most
, not the
work that’s
loudest.
Maya Chen Founder, Northwind Studio
import { mount } from "@rupamotion/player";

const player = mount(document.querySelector(".marker-highlight"));
player.play("replay");

The files mode of the export writes the same table as <base>.player.json (data only: the package has the code and the types). Import it and name the states with the generic:

import { mount } from "@rupamotion/player";
import data from "./hero.player.json";
const player = mount<"enter" | "hover">(document.querySelector(".hero-root")!, data);
player.play("hover"); // a state name TypeScript checks

data takes the JSON as TypeScript reads it. The player checks the table when it mounts and leaves out a part that fails.

With the “Inline” runtime the snippet carries the same core itself, and root.rupa is the same object.