The full snippet
Copy as MarkdownExport 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").rupaplayer.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.
import { mount } from "@rupamotion/player";
const player = mount(document.querySelector(".marker-highlight"));
player.play("replay"); Files mode
Section titled “Files mode”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 checksdata takes the JSON as TypeScript reads it. The player checks the table when it mounts and leaves out a part that
fails.
The inline runtime
Section titled “The inline runtime”With the “Inline” runtime the snippet carries the same core itself, and root.rupa is the same object.