@rive-app/canvas-lite 2.37.4 → 2.37.6
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 +1 -1
- package/rive.js +74 -33
- package/rive.js.map +1 -1
- package/rive.wasm +0 -0
- package/rive_fallback.wasm +0 -0
- package/runtimeLoader.d.ts +3 -1
package/package.json
CHANGED
package/rive.js
CHANGED
|
@@ -174,6 +174,16 @@ var RuntimeLoader = /** @class */ (function () {
|
|
|
174
174
|
// Class is never instantiated
|
|
175
175
|
function RuntimeLoader() {
|
|
176
176
|
}
|
|
177
|
+
// Rejects all pending awaitInstance() promises and resets loading state so
|
|
178
|
+
// the next call to getInstance() / awaitInstance() can retry with a new URL.
|
|
179
|
+
RuntimeLoader.notifyError = function (error) {
|
|
180
|
+
var _a;
|
|
181
|
+
RuntimeLoader.isLoading = false;
|
|
182
|
+
while (RuntimeLoader.errorCallbackQueue.length > 0) {
|
|
183
|
+
(_a = RuntimeLoader.errorCallbackQueue.shift()) === null || _a === void 0 ? void 0 : _a(error);
|
|
184
|
+
}
|
|
185
|
+
RuntimeLoader.callBackQueue = [];
|
|
186
|
+
};
|
|
177
187
|
// Loads the runtime
|
|
178
188
|
RuntimeLoader.loadRuntime = function () {
|
|
179
189
|
// Capture the URL at call time so the catch closure always refers to the
|
|
@@ -192,6 +202,7 @@ var RuntimeLoader = /** @class */ (function () {
|
|
|
192
202
|
performance.measure('rive:wasm-init', 'rive:wasm-init:start', 'rive:wasm-init:end');
|
|
193
203
|
}
|
|
194
204
|
RuntimeLoader.runtime = rive;
|
|
205
|
+
RuntimeLoader.errorCallbackQueue = [];
|
|
195
206
|
// Fire all the callbacks
|
|
196
207
|
while (RuntimeLoader.callBackQueue.length > 0) {
|
|
197
208
|
(_a = RuntimeLoader.callBackQueue.shift()) === null || _a === void 0 ? void 0 : _a(RuntimeLoader.runtime);
|
|
@@ -244,14 +255,15 @@ var RuntimeLoader = /** @class */ (function () {
|
|
|
244
255
|
"\nTo resolve, you may need to:",
|
|
245
256
|
"1. Check your network connection",
|
|
246
257
|
"2. Set a new WASM source via RuntimeLoader.setWasmUrl()",
|
|
247
|
-
"3. Call RuntimeLoader.
|
|
258
|
+
"3. Call RuntimeLoader.awaitInstance() again",
|
|
248
259
|
].join("\n");
|
|
249
260
|
console.error(errorMessage);
|
|
261
|
+
RuntimeLoader.notifyError(new Error(errorMessage));
|
|
250
262
|
}
|
|
251
263
|
});
|
|
252
264
|
};
|
|
253
265
|
// Provides a runtime instance via a callback
|
|
254
|
-
RuntimeLoader.getInstance = function (callback) {
|
|
266
|
+
RuntimeLoader.getInstance = function (callback, onError) {
|
|
255
267
|
// If it's not loading, start loading runtime
|
|
256
268
|
if (!RuntimeLoader.isLoading) {
|
|
257
269
|
RuntimeLoader.isLoading = true;
|
|
@@ -259,15 +271,18 @@ var RuntimeLoader = /** @class */ (function () {
|
|
|
259
271
|
}
|
|
260
272
|
if (!RuntimeLoader.runtime) {
|
|
261
273
|
RuntimeLoader.callBackQueue.push(callback);
|
|
274
|
+
if (onError) {
|
|
275
|
+
RuntimeLoader.errorCallbackQueue.push(onError);
|
|
276
|
+
}
|
|
262
277
|
}
|
|
263
278
|
else {
|
|
264
279
|
callback(RuntimeLoader.runtime);
|
|
265
280
|
}
|
|
266
281
|
};
|
|
267
|
-
// Provides a runtime instance via a promise
|
|
282
|
+
// Provides a runtime instance via a promise; rejects if WASM fails to load.
|
|
268
283
|
RuntimeLoader.awaitInstance = function () {
|
|
269
|
-
return new Promise(function (resolve) {
|
|
270
|
-
return RuntimeLoader.getInstance(
|
|
284
|
+
return new Promise(function (resolve, reject) {
|
|
285
|
+
return RuntimeLoader.getInstance(resolve, reject);
|
|
271
286
|
});
|
|
272
287
|
};
|
|
273
288
|
// Manually sets the wasm url
|
|
@@ -314,6 +329,8 @@ var RuntimeLoader = /** @class */ (function () {
|
|
|
314
329
|
// the fallback entirely. Defaults to pulling from the jsdelivr CDN.
|
|
315
330
|
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
331
|
RuntimeLoader.wasmBinary = null;
|
|
332
|
+
// Error callbacks enqueued from .getInstance()
|
|
333
|
+
RuntimeLoader.errorCallbackQueue = [];
|
|
317
334
|
/**
|
|
318
335
|
* When true, performance.mark / performance.measure entries are emitted for
|
|
319
336
|
* WASM initialization.
|
|
@@ -2529,7 +2546,7 @@ moduleRtn = da;
|
|
|
2529
2546
|
/* 5 */
|
|
2530
2547
|
/***/ ((module) => {
|
|
2531
2548
|
|
|
2532
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.37.
|
|
2549
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.37.6","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}}');
|
|
2533
2550
|
|
|
2534
2551
|
/***/ }),
|
|
2535
2552
|
/* 6 */
|
|
@@ -3883,7 +3900,8 @@ var Animator = /** @class */ (function () {
|
|
|
3883
3900
|
* @param animatables the name(s) of animations to add
|
|
3884
3901
|
* @param playing whether animations should play on instantiation
|
|
3885
3902
|
*/
|
|
3886
|
-
Animator.prototype.initLinearAnimations = function (animatables, playing) {
|
|
3903
|
+
Animator.prototype.initLinearAnimations = function (animatables, playing, isFallingBackFromStateMachines) {
|
|
3904
|
+
if (isFallingBackFromStateMachines === void 0) { isFallingBackFromStateMachines = false; }
|
|
3887
3905
|
// Play/pause already instanced items, or create new instances
|
|
3888
3906
|
// This validation is kept to maintain compatibility with current behavior.
|
|
3889
3907
|
// But given that it this is called during artboard initialization
|
|
@@ -3904,6 +3922,10 @@ var Animator = /** @class */ (function () {
|
|
|
3904
3922
|
newAnimation.apply(1.0);
|
|
3905
3923
|
this.animations.push(newAnimation);
|
|
3906
3924
|
}
|
|
3925
|
+
else if (isFallingBackFromStateMachines) { // Throw LoadError if we cannot load the state machine name at all
|
|
3926
|
+
var smInitializationMessage = "State Machine with name ".concat(animatables[i], " not found");
|
|
3927
|
+
throw new RiveError(smInitializationMessage);
|
|
3928
|
+
}
|
|
3907
3929
|
else {
|
|
3908
3930
|
console.error("Animation with name ".concat(animatables[i], " not found."));
|
|
3909
3931
|
}
|
|
@@ -3934,10 +3956,11 @@ var Animator = /** @class */ (function () {
|
|
|
3934
3956
|
this.stateMachines.push(newStateMachine);
|
|
3935
3957
|
}
|
|
3936
3958
|
else {
|
|
3937
|
-
console.warn("State Machine with name ".concat(animatables[i], " not found."));
|
|
3959
|
+
console.warn("State Machine with name ".concat(animatables[i], " not found. Falling back to find an animation with the same name."));
|
|
3960
|
+
// TODO: Remove this fallback in next major release as it complicates initialization.
|
|
3938
3961
|
// In order to maintain compatibility with current behavior, if a state machine is not found
|
|
3939
3962
|
// we look for an animation with the same name
|
|
3940
|
-
this.initLinearAnimations([animatables[i]], playing);
|
|
3963
|
+
this.initLinearAnimations([animatables[i]], playing, true);
|
|
3941
3964
|
}
|
|
3942
3965
|
}
|
|
3943
3966
|
}
|
|
@@ -4539,17 +4562,26 @@ var RiveFile = /** @class */ (function () {
|
|
|
4539
4562
|
};
|
|
4540
4563
|
RiveFile.prototype.initData = function () {
|
|
4541
4564
|
return __awaiter(this, void 0, void 0, function () {
|
|
4542
|
-
var _a, loader, loaderWrapper, _b, fileFinalizer;
|
|
4565
|
+
var _a, error_1, loader, loaderWrapper, _b, fileFinalizer;
|
|
4543
4566
|
return __generator(this, function (_c) {
|
|
4544
4567
|
switch (_c.label) {
|
|
4545
4568
|
case 0:
|
|
4546
|
-
if (!(this.src && !this.buffer)) return [3 /*break*/,
|
|
4569
|
+
if (!(this.src && !this.buffer)) return [3 /*break*/, 4];
|
|
4570
|
+
_c.label = 1;
|
|
4571
|
+
case 1:
|
|
4572
|
+
_c.trys.push([1, 3, , 4]);
|
|
4547
4573
|
_a = this;
|
|
4548
4574
|
return [4 /*yield*/, loadRiveFile(this.src)];
|
|
4549
|
-
case 1:
|
|
4550
|
-
_a.buffer = _c.sent();
|
|
4551
|
-
_c.label = 2;
|
|
4552
4575
|
case 2:
|
|
4576
|
+
_a.buffer = _c.sent();
|
|
4577
|
+
return [3 /*break*/, 4];
|
|
4578
|
+
case 3:
|
|
4579
|
+
error_1 = _c.sent();
|
|
4580
|
+
if (error_1 instanceof Error) {
|
|
4581
|
+
throw error_1;
|
|
4582
|
+
}
|
|
4583
|
+
throw new RiveError(RiveFile.fileLoadErrorMessage);
|
|
4584
|
+
case 4:
|
|
4553
4585
|
if (this.destroyed) {
|
|
4554
4586
|
return [2 /*return*/];
|
|
4555
4587
|
}
|
|
@@ -4562,7 +4594,7 @@ var RiveFile = /** @class */ (function () {
|
|
|
4562
4594
|
performance.mark('rive:file-load:start');
|
|
4563
4595
|
_b = this;
|
|
4564
4596
|
return [4 /*yield*/, this.runtime.load(new Uint8Array(this.buffer), loader, this.enableRiveAssetCDN)];
|
|
4565
|
-
case
|
|
4597
|
+
case 5:
|
|
4566
4598
|
_b.file = _c.sent();
|
|
4567
4599
|
if (this.enablePerfMarks) {
|
|
4568
4600
|
performance.mark('rive:file-load:end');
|
|
@@ -4626,7 +4658,7 @@ var RiveFile = /** @class */ (function () {
|
|
|
4626
4658
|
};
|
|
4627
4659
|
RiveFile.prototype.init = function () {
|
|
4628
4660
|
return __awaiter(this, void 0, void 0, function () {
|
|
4629
|
-
var _a, bufferResolved, runtimeResolved,
|
|
4661
|
+
var _a, bufferResolved, runtimeResolved, error_2;
|
|
4630
4662
|
return __generator(this, function (_b) {
|
|
4631
4663
|
switch (_b.label) {
|
|
4632
4664
|
case 0:
|
|
@@ -4658,8 +4690,8 @@ var RiveFile = /** @class */ (function () {
|
|
|
4658
4690
|
}
|
|
4659
4691
|
return [3 /*break*/, 5];
|
|
4660
4692
|
case 4:
|
|
4661
|
-
|
|
4662
|
-
this.fireLoadError(
|
|
4693
|
+
error_2 = _b.sent();
|
|
4694
|
+
this.fireLoadError(error_2 instanceof Error ? error_2.message : RiveFile.fileLoadErrorMessage);
|
|
4663
4695
|
return [3 /*break*/, 5];
|
|
4664
4696
|
case 5: return [2 /*return*/];
|
|
4665
4697
|
}
|
|
@@ -4671,7 +4703,7 @@ var RiveFile = /** @class */ (function () {
|
|
|
4671
4703
|
type: EventType.LoadError,
|
|
4672
4704
|
data: message,
|
|
4673
4705
|
});
|
|
4674
|
-
throw new
|
|
4706
|
+
throw new RiveError(message);
|
|
4675
4707
|
};
|
|
4676
4708
|
/**
|
|
4677
4709
|
* Subscribe to Rive-generated events
|
|
@@ -4995,11 +5027,13 @@ var Rive = /** @class */ (function () {
|
|
|
4995
5027
|
}
|
|
4996
5028
|
})
|
|
4997
5029
|
.catch(function (e) {
|
|
5030
|
+
// initData already catches RiveErrors for load issues like artboard/state machine initialization
|
|
5031
|
+
// failures, so just console error and catch here so we don't double-fire the LoadError event
|
|
4998
5032
|
console.error(e);
|
|
4999
5033
|
});
|
|
5000
5034
|
})
|
|
5001
5035
|
.catch(function (e) {
|
|
5002
|
-
|
|
5036
|
+
_this.eventManager.fire({ type: EventType.LoadError, data: e.message });
|
|
5003
5037
|
});
|
|
5004
5038
|
};
|
|
5005
5039
|
/**
|
|
@@ -5081,7 +5115,7 @@ var Rive = /** @class */ (function () {
|
|
|
5081
5115
|
// Returns true for successful initialization.
|
|
5082
5116
|
Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay, autoBind) {
|
|
5083
5117
|
return __awaiter(this, void 0, void 0, function () {
|
|
5084
|
-
var riveFile,
|
|
5118
|
+
var riveFile, error_3, msg;
|
|
5085
5119
|
var _a;
|
|
5086
5120
|
return __generator(this, function (_b) {
|
|
5087
5121
|
switch (_b.label) {
|
|
@@ -5115,11 +5149,19 @@ var Rive = /** @class */ (function () {
|
|
|
5115
5149
|
// Check for audio
|
|
5116
5150
|
this.initializeAudio();
|
|
5117
5151
|
// Everything's set up, emit a load event
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5152
|
+
try {
|
|
5153
|
+
this.loaded = true;
|
|
5154
|
+
this.eventManager.fire({
|
|
5155
|
+
type: EventType.Load,
|
|
5156
|
+
data: (_a = this.src) !== null && _a !== void 0 ? _a : "buffer",
|
|
5157
|
+
});
|
|
5158
|
+
}
|
|
5159
|
+
catch (e) {
|
|
5160
|
+
// If any synchronous errors surface from the user-supplied onLoad callback,
|
|
5161
|
+
// this will console.error the error but will not invoke LoadError (onLoadError).
|
|
5162
|
+
// Notably, this will not interfere with Rive rendering
|
|
5163
|
+
console.error(e);
|
|
5164
|
+
}
|
|
5123
5165
|
// Only initialize paused state machines after the load event has been fired
|
|
5124
5166
|
// to allow users to initialize inputs and view models before the first advance
|
|
5125
5167
|
this.animator.advanceIfPaused();
|
|
@@ -5130,9 +5172,8 @@ var Rive = /** @class */ (function () {
|
|
|
5130
5172
|
this.drawFrame();
|
|
5131
5173
|
return [2 /*return*/, true];
|
|
5132
5174
|
case 3:
|
|
5133
|
-
|
|
5134
|
-
msg = resolveErrorMessage(
|
|
5135
|
-
console.warn(msg);
|
|
5175
|
+
error_3 = _b.sent();
|
|
5176
|
+
msg = resolveErrorMessage(error_3);
|
|
5136
5177
|
this.eventManager.fire({ type: EventType.LoadError, data: msg });
|
|
5137
5178
|
return [2 /*return*/, Promise.reject(msg)];
|
|
5138
5179
|
case 4: return [2 /*return*/];
|
|
@@ -5151,10 +5192,7 @@ var Rive = /** @class */ (function () {
|
|
|
5151
5192
|
: this.file.defaultArtboard();
|
|
5152
5193
|
// Check we have a working artboard
|
|
5153
5194
|
if (!rootArtboard) {
|
|
5154
|
-
|
|
5155
|
-
console.warn(msg);
|
|
5156
|
-
this.eventManager.fire({ type: EventType.LoadError, data: msg });
|
|
5157
|
-
return;
|
|
5195
|
+
throw new RiveError("Invalid artboard name or no default artboard");
|
|
5158
5196
|
}
|
|
5159
5197
|
this.artboard = rootArtboard;
|
|
5160
5198
|
rootArtboard.volume = this._volume * audioManager.systemVolume;
|
|
@@ -7173,6 +7211,9 @@ var loadRiveFile = function (src) { return __awaiter(void 0, void 0, void 0, fun
|
|
|
7173
7211
|
return [4 /*yield*/, fetch(req)];
|
|
7174
7212
|
case 1:
|
|
7175
7213
|
res = _a.sent();
|
|
7214
|
+
if (!res.ok) {
|
|
7215
|
+
throw new Error("Failed to fetch the Rive file: HTTP ".concat(res.status));
|
|
7216
|
+
}
|
|
7176
7217
|
return [4 /*yield*/, res.arrayBuffer()];
|
|
7177
7218
|
case 2:
|
|
7178
7219
|
buffer = _a.sent();
|