From 6aac45cd688ca530104c6fbfe3961360e165e899 Mon Sep 17 00:00:00 2001 From: naugtur Date: Thu, 30 Oct 2025 14:36:46 +0100 Subject: [PATCH] feat: expose wasmBinary to allow Rive being used in environments without fetch and XHR --- js/src/rive.ts | 12 ++++++++++++ js/src/rive_advanced.mjs.d.ts | 1 + 2 files changed, 13 insertions(+) diff --git a/js/src/rive.ts b/js/src/rive.ts index 90b45447..89ec12e0 100644 --- a/js/src/rive.ts +++ b/js/src/rive.ts @@ -222,6 +222,8 @@ export class RuntimeLoader { // if embedded wasm is used then this is never used. private static wasmURL = `https://unpkg.com/${packageData.name}@${packageData.version}/rive.wasm`; + private static wasmBinary: ArrayBuffer; + // Class is never instantiated private constructor() {} @@ -230,6 +232,7 @@ export class RuntimeLoader { rc.default({ // Loads Wasm bundle locateFile: () => RuntimeLoader.wasmURL, + wasmBinary: RuntimeLoader.wasmBinary }) .then((rive: rc.RiveCanvas) => { RuntimeLoader.runtime = rive; @@ -315,6 +318,15 @@ export class RuntimeLoader { public static getWasmUrl(): string { return RuntimeLoader.wasmURL; } + // Manually sets the wasm binary + public static setWasmBinary(ab: ArrayBuffer): void { + RuntimeLoader.wasmBinary = ab; + } + + // Gets the current wasm url + public static getWasmBinary(): ArrayBuffer { + return RuntimeLoader.wasmBinary; + } } // #endregion diff --git a/js/src/rive_advanced.mjs.d.ts b/js/src/rive_advanced.mjs.d.ts index 6ae26014..4d7bb140 100644 --- a/js/src/rive_advanced.mjs.d.ts +++ b/js/src/rive_advanced.mjs.d.ts @@ -1,5 +1,6 @@ interface RiveOptions { locateFile(file: string): string; + wasmBinary?: ArrayBuffer; } declare function Rive(options?: RiveOptions): Promise;