import * as rc from "./rive_advanced.mjs"; export type RuntimeCallback = (rive: rc.RiveCanvas) => void; /** * @experimental Why {@link RuntimeLoader.threadsRefusal} says no threads. * `notIsolated`: the browser could isolate this context but didn't (headers, * framing or policy). `isolationUnsupported`: the browser can't isolate any. */ export type ThreadsRefusal = "noThreadedBuild" | "threadsOff" | "wasmBinary" | "notIsolated" | "isolationUnsupported" | "noSharedMemory" | "noWasmThreads" | "loadFailed"; /** * @experimental Options for {@link RuntimeLoader.setScriptFetch}. Requests * sent from this page, or through the reference proxy page, never carry * cookies or other credentials, a referrer or the HTTP cache, and redirects * fail with "policy". A proxy page of your own decides these itself. Either * way, the runtime allows only https: URLs on public hosts, and checks the * URL a response came from against `allowedHosts`. */ export interface ScriptFetchOptions { /** * URL of a script fetch proxy page, hosted on a cookie-less domain, that * accepts this page's origin. It loads in a hidden iframe added to the * page's ``. Requests then leave from the proxy's origin * under its CSP. On a cross origin isolated page, the proxy page must be * served with `Cross-Origin-Embedder-Policy: require-corp` and * `Cross-Origin-Resource-Policy: cross-origin`. Without it, requests leave * from this page with `fetch()`. */ proxyUrl?: string; /** * Hosts scripts may fetch from: exact (`"api.example.com"`), any subdomain * (`"*.example.com"`, which doesn't match `"example.com"`) or any host * (`"*"`). Omitted is `["*"]`; empty allows none. This page's own host is * only allowed when named, e.g. `["*", "www.example.com"]`. */ allowedHosts?: string[]; /** * Largest response body, in bytes, up to 64 MiB. 0 keeps the default of * 16 MiB. */ maxResponseBytes?: number; } export declare class RuntimeLoader { private static runtime; private static isLoading; private static callBackQueue; private static rive; private static wasmURL; private static wasmFallbackURL; private static wasmBinary; private static wasmThreadsURL; private static triedThreads; private static threadsOutcome; private static parallelParts; private static replayWorker; private static replayCapsArrived; private static readonly replayCapsTimeoutMs; private static scriptFetch; private static warnedNoScriptFetch; private static errorCallbackQueue; private constructor(); /** * When true, performance.mark / performance.measure entries are emitted for * WASM initialization. */ static enablePerfMarks: boolean; private static notifyError; private static systemLanguages; private static listeningForLanguageChange; static setSystemLanguages(languages: readonly string[] | null): void; private static applySystemLanguages; private static loaded; private static loadRuntime; private static decideThreads; private static loadUnthreaded; static getInstance(callback: RuntimeCallback, onError?: (error: Error) => void): void; static awaitInstance(): Promise; /** * @internal Resolves once the replay worker's device caps reach the page, * so scripts init against them. Null when there is nothing left to wait * for, which keeps every later instance's load synchronous. */ static awaitReplayCaps(): Promise | null; static setWasmUrl(url: string): void; static getWasmUrl(): string; /** * Sets the URL used as a fallback when the primary WASM URL fails to load. * Pass `null` to disable the fallback entirely. * * Defaults to pulling from the jsdelivr CDN. */ static setWasmFallbackUrl(url: string | null): void; static getWasmFallbackUrl(): string | null; /** * Sets the URL of the threaded build's wasm, which * `@rive-app/webgl2-threads` loads on a cross origin isolated page. Pass * `null` to always load the build without threads. Other packages have no * threaded build and ignore it. * * Defaults to pulling from the unpkg CDN. */ static setWasmThreadsUrl(url: string | null): void; static getWasmThreadsUrl(): string | null; /** * @experimental Why this page doesn't run the threaded build, or null when * it does. Before load, what the loader would do with the current settings; * after, what it did. Never loads or logs. */ static threadsRefusal(): ThreadsRefusal | null; /** * Sets how many parts a script's parallel call gets on a page that runs * the threaded build, the page's thread and one worker thread for each * other part. 1 turns parallel calls off, and null leaves the runtime's * default of one part per core, up to 8. Set it before the first file * loads. */ static setParallelParts(parts: number | null): void; static getParallelParts(): number | null; private static applyParallelParts; /** * @experimental When the threaded build loads, instances with * `enableGPUCanvas` hand their canvas to one worker that replays every * instance's frames while the page records the next ones. Pass `false` * before the runtime loads to keep replay on the page's thread; a single * instance can opt out with `useReplayWorker: false`. Pages where the * browser cannot draw WebGL2 on a transferred canvas stay on the page's * thread regardless. * * True by default. */ static setReplayWorker(enabled: boolean): void; static getReplayWorker(): boolean; /** * @experimental Lets scripts in Rive files call `fetch()`. Pass `true` or * options to enable it for every file on the page, `false` to disable it. * Only `@rive-app/webgl2-threads` running its threaded build has it; * elsewhere this warns once and does nothing. * * Enabling it lets any script in any file this page loads send what it * can read to the hosts it may reach. Limit them with `allowedHosts`. * Scripts can't fetch this page's own host unless `allowedHosts` names it. * * Each call replaces the previous options, and any option left out goes * back to its default (an omitted `allowedHosts` allows every host). To * change one option, spread the current ones: * * ```ts * RuntimeLoader.setScriptFetch({ * ...RuntimeLoader.getScriptFetch(), * maxResponseBytes: 32 * 1024 * 1024, * }); * ``` * * Disabled by default. */ static setScriptFetch(options: ScriptFetchOptions | boolean): void; static getScriptFetch(): ScriptFetchOptions | null; private static applyScriptFetch; static setWasmBinary(value: ArrayBuffer | null): void; static getWasmBinary(): ArrayBuffer | null; }