# The full snippet

Use the exported markup and CSS in your page and add the player from npm or a CDN to control it.

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:

```html
<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:

```js
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:

```js
import { mount } from "@rupamotion/player";

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

## 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:

```ts
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.

## The inline runtime

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