# mountFile

> `const` **mountFile**: <`S`>(`root`, `src`, `options?`) => `Promise`<[`MountFileResult`](/reference/api/rupamotion/player/file/type-aliases/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

### S

`S` _extends_ `string` = `string`

## Parameters

### root

`Element`

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

### src

[`FileSource`](/reference/api/rupamotion/player/file/type-aliases/filesource/)

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

### options?

[`MountFileOptions`](/reference/api/rupamotion/player/file/interfaces/mountfileoptions/)

`markup`, `cloak`, `integrity` (see `MountFileOptions`).

## Returns

`Promise`<[`MountFileResult`](/reference/api/rupamotion/player/file/type-aliases/mountfileresult/)<`S`>>

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

## Throws

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

## Example

```ts
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");
```
