Skip to content

mountFile

Copy as Markdown

const mountFile: <S>(root, src, options?) => Promise<MountFileResult<S>>

Loads a .rupaplay file and mounts its player on root: the file’s CSS and fonts installed (once per root class, taken away when the last of its players is destroyed), its markup kept or written into root (options.markup, sanitised), then mount.

The player’s root is root itself when it has the file’s root class, else its first element with that class, else root (where the file’s markup is written). A root a player holds already resolves to that player, the file installed once. A failure leaves root as it was (nothing written or installed, not hidden) and root dispatches the event rupaerror (detail.error, detail.src) as well. The root must be in the player’s own document (not an iframe’s).

S extends string = string

Element

The element to mount into (the export’s root, or a container for its markup).

FileSource

Where the file comes from: a URL, its bytes, a Response or a file already parsed (see FileSource).

MountFileOptions

markup, cloak, integrity (see MountFileOptions).

Promise<MountFileResult<S>>

A promise of { player } or { error } (see FileErrorCode). It never rejects.

When root is not an object (thrown by the call itself, not a rejection).

import { mountFile } from "@rupamotion/player/file";
const { player, error } = await mountFile(document.querySelector("#hero")!, "/hero.rupaplay", {
markup: "auto",
cloak: true,
});
if (error) console.warn(error.code, error.message);
else player.play("intro");