Diorama

Made for a big screen.

This site is one 3D scene, built for a computer: a wide window and a mouse. Open dioramajs.dev on a desktop or a laptop to see it.This site is one 3D scene, built for a wide window. Make this one wider, or open dioramajs.dev on a larger screen.

GitHub

DioramaDocs

AssetsApi interface

The `assets` service: a shared cache of media and models with progress.

View as Markdown
import type { AssetsApi } from '@dioramajs/diorama/assets'
interface AssetsApi

Members

NameTypeDescription
readonly progressReadonlySignal<number>

Progress of the current wave of high and normal work, 0..1. Never goes back within a wave.

acquire
acquire<T>(
  key: string,
  make: (context: LoaderContext) => Promise<Loaded<T>>,
  options?: { readonly priority?: Priority; readonly weight?: number },
): Asset<T, unknown>

Get-or-create by key with a lease. Plugins share values they build this way (effects bitmaps). Errors of make reject ready unchanged and the owner reports them.

load
load<K extends keyof AssetTypes>(
  url: string,
  options: LoadOptions<K> & { readonly type: K },
): Asset<AssetTypes[K]>
load<T = unknown>(url: string, options?: LoadOptions<string>): Asset<T>

Loads a URL and returns a lease at once. The type comes from type or the extension. Never throws: ready rejects with an AssetError, ASSET_TYPE for an unknown type, ASSET_LOAD for a network or HTTP failure, ASSET_PARSE or ASSET_DECODER for bad data.

pause
pause(reason?: string): Off

Low-priority loads and decodes wait while any pause is held (a flight). reason labels the call, as in app.pause.

preload
preload(source: PreloadSource, options?: PreloadOptions): Preload

Next page's media and models: URLs, a parsed Document (Astro, Swup) or a container (Barba).

ready
ready(): Promise<void>

Settles when the current wave is done, or at once without one. Failures count as done.

stats
stats(): AssetsStats

Counters of the cache.

track
track(
  work: PromiseLike<unknown>,
  options?: { readonly priority?: Priority; readonly weight?: number },
): void

Counts outside work in the current wave, like first-screen effects, fonts or page HTML. weight: 0 holds ready() without moving progress or starting a wave of its own.

Also exported from @dioramajs/assets.

Defined in packages/assets/src/types.ts.