@rive-app/canvas-lite 2.37.0 → 2.37.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rive-app/canvas-lite",
3
- "version": "2.37.0",
3
+ "version": "2.37.2",
4
4
  "description": "A lite version of Rive's canvas based web api.",
5
5
  "main": "rive.js",
6
6
  "homepage": "https://rive.app",
@@ -27,7 +27,9 @@
27
27
  "rive.wasm",
28
28
  "rive_fallback.wasm",
29
29
  "rive.d.ts",
30
- "rive_advanced.mjs.d.ts"
30
+ "rive_advanced.mjs.d.ts",
31
+ "runtimeLoader.d.ts",
32
+ "utils"
31
33
  ],
32
34
  "typings": "rive.d.ts",
33
35
  "dependencies": {},
package/rive.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as rc from "./rive_advanced.mjs";
2
2
  import { RuntimeLoader, type RuntimeCallback } from "./runtimeLoader";
3
3
  import { ImageWrapper, AudioWrapper, FontWrapper, RiveFont as RiveFontClassUtil } from "./utils";
4
- export type AssetLoadCallback = (asset: rc.FileAsset, bytes: Uint8Array) => Boolean;
4
+ export type AssetLoadCallback = (asset: rc.FileAsset, bytes: Uint8Array) => boolean;
5
5
  export { RiveFontClassUtil as RiveFont };
6
6
  export type { FileAsset, AudioAsset, FontAsset, ImageAsset, } from "./rive_advanced.mjs";
7
7
  /**
@@ -285,7 +285,7 @@ export interface RiveParameters {
285
285
  */
286
286
  onloaderror?: EventCallback;
287
287
  /**
288
- * @deprecated Use `onPoad()` instead
288
+ * @deprecated Use `onPlay()` instead
289
289
  */
290
290
  onplay?: EventCallback;
291
291
  /**
package/rive.js CHANGED
@@ -155,6 +155,17 @@ __webpack_require__.r(__webpack_exports__);
155
155
  /* harmony export */ });
156
156
  /* harmony import */ var _rive_advanced_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4);
157
157
  /* harmony import */ var package_json__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5);
158
+ var __assign = (undefined && undefined.__assign) || function () {
159
+ __assign = Object.assign || function(t) {
160
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
161
+ s = arguments[i];
162
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
163
+ t[p] = s[p];
164
+ }
165
+ return t;
166
+ };
167
+ return __assign.apply(this, arguments);
168
+ };
158
169
 
159
170
 
160
171
  // Runtime singleton; use getInstance to provide a callback that returns the
@@ -165,12 +176,15 @@ var RuntimeLoader = /** @class */ (function () {
165
176
  }
166
177
  // Loads the runtime
167
178
  RuntimeLoader.loadRuntime = function () {
179
+ // Capture the URL at call time so the catch closure always refers to the
180
+ // URL this particular attempt used, even if wasmURL is mutated for a retry.
181
+ var attemptedUrl = RuntimeLoader.wasmURL;
182
+ var wasmBinary = RuntimeLoader.wasmBinary;
168
183
  if (RuntimeLoader.enablePerfMarks)
169
184
  performance.mark('rive:wasm-init:start');
170
- _rive_advanced_mjs__WEBPACK_IMPORTED_MODULE_0__["default"]({
185
+ _rive_advanced_mjs__WEBPACK_IMPORTED_MODULE_0__["default"](__assign({
171
186
  // Loads Wasm bundle
172
- locateFile: function () { return RuntimeLoader.wasmURL; },
173
- })
187
+ locateFile: function () { return attemptedUrl; } }, (wasmBinary ? { wasmBinary: wasmBinary } : {})))
174
188
  .then(function (rive) {
175
189
  var _a;
176
190
  if (RuntimeLoader.enablePerfMarks) {
@@ -195,18 +209,30 @@ var RuntimeLoader = /** @class */ (function () {
195
209
  };
196
210
  // Log detailed error for debugging
197
211
  console.debug("Rive WASM load error details:", errorDetails);
198
- // In case unpkg fails, or the wasm was not supported, we try to load the fallback module from jsdelivr.
199
- // This `rive_fallback.wasm` is compiled to support older architecture.
200
- // TODO: (Gordon): preemptively test browser support and load the correct wasm file. Then use jsdelvr only if unpkg fails.
201
- var backupJsdelivrUrl = "https://cdn.jsdelivr.net/npm/".concat(package_json__WEBPACK_IMPORTED_MODULE_1__.name, "@").concat(package_json__WEBPACK_IMPORTED_MODULE_1__.version, "/rive_fallback.wasm");
202
- if (RuntimeLoader.wasmURL.toLowerCase() !== backupJsdelivrUrl) {
203
- console.warn("Failed to load WASM from ".concat(RuntimeLoader.wasmURL, " (").concat(errorDetails.message, "), trying jsdelivr as a backup"));
204
- RuntimeLoader.setWasmUrl(backupJsdelivrUrl);
212
+ // In case the primary URL fails, or the wasm was not supported, try the
213
+ // fallback URL (a rive_fallback.wasm compiled for older architectures).
214
+ // The fallback can be customised or disabled via setWasmFallbackUrl().
215
+ // TODO: (Gordon): preemptively test browser support and load the correct wasm file. Then use the fallback only if the primary fails.
216
+ var fallbackUrl = RuntimeLoader.wasmFallbackURL;
217
+ var alreadyOnFallback = fallbackUrl !== null &&
218
+ attemptedUrl.toLowerCase() === fallbackUrl.toLowerCase();
219
+ if (fallbackUrl !== null && !alreadyOnFallback) {
220
+ console.warn("Failed to load WASM from ".concat(attemptedUrl, " (").concat(errorDetails.message, "), trying fallback URL: ").concat(fallbackUrl));
221
+ // Clear wasmBinary so the retry actually fetches via locateFile
222
+ // instead of re-using the same (failing) in-memory binary.
223
+ RuntimeLoader.wasmBinary = null;
224
+ RuntimeLoader.setWasmUrl(fallbackUrl);
205
225
  RuntimeLoader.loadRuntime();
206
226
  }
207
227
  else {
228
+ // When alreadyOnFallback is true, wasmURL has already been overwritten
229
+ // with the fallback URL, so we can no longer recover the original
230
+ // primary URL here. The primary URL was logged in the earlier warning.
231
+ var triedUrls = alreadyOnFallback
232
+ ? "the configured WASM URL or its fallback (".concat(fallbackUrl, ")")
233
+ : attemptedUrl;
208
234
  var errorMessage = [
209
- "Could not load Rive WASM file from ".concat(RuntimeLoader.wasmURL, " or ").concat(backupJsdelivrUrl, "."),
235
+ "Could not load Rive WASM file from ".concat(triedUrls, "."),
210
236
  "Possible reasons:",
211
237
  "- Network connection is down",
212
238
  "- WebAssembly is not supported in this environment",
@@ -252,6 +278,31 @@ var RuntimeLoader = /** @class */ (function () {
252
278
  RuntimeLoader.getWasmUrl = function () {
253
279
  return RuntimeLoader.wasmURL;
254
280
  };
281
+ /**
282
+ * Sets the URL used as a fallback when the primary WASM URL fails to load.
283
+ * Pass `null` to disable the fallback entirely.
284
+ *
285
+ * Defaults to pulling from the jsdelivr CDN.
286
+ */
287
+ RuntimeLoader.setWasmFallbackUrl = function (url) {
288
+ RuntimeLoader.wasmFallbackURL = url;
289
+ };
290
+ // Gets the current fallback wasm url (null means fallback is disabled)
291
+ RuntimeLoader.getWasmFallbackUrl = function () {
292
+ return RuntimeLoader.wasmFallbackURL;
293
+ };
294
+ // Manually sets the wasm binary or clears it with null
295
+ RuntimeLoader.setWasmBinary = function (value) {
296
+ if ((value instanceof ArrayBuffer) || value === null) {
297
+ RuntimeLoader.wasmBinary = value;
298
+ return;
299
+ }
300
+ console.error("setWasmBinary expects an ArrayBuffer or null");
301
+ };
302
+ // Gets the current wasm build as ArrayBuffer or null
303
+ RuntimeLoader.getWasmBinary = function () {
304
+ return RuntimeLoader.wasmBinary;
305
+ };
255
306
  // Flag to indicate that loading has started/completed
256
307
  RuntimeLoader.isLoading = false;
257
308
  // List of callbacks for the runtime that come in while loading
@@ -259,6 +310,10 @@ var RuntimeLoader = /** @class */ (function () {
259
310
  // Path to the Wasm file; default path works for testing only;
260
311
  // if embedded wasm is used then this is never used.
261
312
  RuntimeLoader.wasmURL = "https://unpkg.com/".concat(package_json__WEBPACK_IMPORTED_MODULE_1__.name, "@").concat(package_json__WEBPACK_IMPORTED_MODULE_1__.version, "/rive.wasm");
313
+ // Fallback WASM URL tried when the primary URL fails. Set to null to disable
314
+ // the fallback entirely. Defaults to pulling from the jsdelivr CDN.
315
+ RuntimeLoader.wasmFallbackURL = "https://cdn.jsdelivr.net/npm/".concat(package_json__WEBPACK_IMPORTED_MODULE_1__.name, "@").concat(package_json__WEBPACK_IMPORTED_MODULE_1__.version, "/rive_fallback.wasm");
316
+ RuntimeLoader.wasmBinary = null;
262
317
  /**
263
318
  * When true, performance.mark / performance.measure entries are emitted for
264
319
  * WASM initialization.
@@ -2474,7 +2529,7 @@ moduleRtn = da;
2474
2529
  /* 5 */
2475
2530
  /***/ ((module) => {
2476
2531
 
2477
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.37.0","description":"A lite version of Rive\'s canvas based web api.","main":"rive.js","homepage":"https://rive.app","repository":{"type":"git","url":"https://github.com/rive-app/rive-wasm/tree/master/js"},"keywords":["rive","animation"],"author":"Rive","contributors":["Luigi Rosso <luigi@rive.app> (https://rive.app)","Maxwell Talbot <max@rive.app> (https://rive.app)","Arthur Vivian <arthur@rive.app> (https://rive.app)","Umberto Sonnino <umberto@rive.app> (https://rive.app)","Matthew Sullivan <matt.j.sullivan@gmail.com> (mailto:matt.j.sullivan@gmail.com)"],"license":"MIT","files":["rive.js","rive.js.map","rive.wasm","rive_fallback.wasm","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
2532
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.37.2","description":"A lite version of Rive\'s canvas based web api.","main":"rive.js","homepage":"https://rive.app","repository":{"type":"git","url":"https://github.com/rive-app/rive-wasm/tree/master/js"},"keywords":["rive","animation"],"author":"Rive","contributors":["Luigi Rosso <luigi@rive.app> (https://rive.app)","Maxwell Talbot <max@rive.app> (https://rive.app)","Arthur Vivian <arthur@rive.app> (https://rive.app)","Umberto Sonnino <umberto@rive.app> (https://rive.app)","Matthew Sullivan <matt.j.sullivan@gmail.com> (mailto:matt.j.sullivan@gmail.com)"],"license":"MIT","files":["rive.js","rive.js.map","rive.wasm","rive_fallback.wasm","rive.d.ts","rive_advanced.mjs.d.ts","runtimeLoader.d.ts","utils"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
2478
2533
 
2479
2534
  /***/ }),
2480
2535
  /* 6 */