mountFile
Copy as Markdown
constmountFile: <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).
Type Parameters
Section titled “Type Parameters”S extends string = string
Parameters
Section titled “Parameters”Element
The element to mount into (the export’s root, or a container for its markup).
Where the file comes from: a URL, its bytes, a Response or a file already parsed (see FileSource).
options?
Section titled “options?”markup, cloak, integrity (see MountFileOptions).
Returns
Section titled “Returns”Promise<MountFileResult<S>>
A promise of { player } or { error } (see FileErrorCode). It never rejects.
Throws
Section titled “Throws”When root is not an object (thrown by the call itself, not a rejection).
Example
Section titled “Example”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");