@rive-app/canvas-lite 2.25.6 → 2.26.0
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.d.ts +3 -0
- package/rive.js +65 -12
- package/rive.js.map +1 -1
- package/rive.wasm +0 -0
- package/rive_fallback.wasm +0 -0
package/package.json
CHANGED
package/rive.d.ts
CHANGED
|
@@ -307,6 +307,7 @@ export declare class RiveFile {
|
|
|
307
307
|
private enableRiveAssetCDN;
|
|
308
308
|
private eventManager;
|
|
309
309
|
private referenceCount;
|
|
310
|
+
private destroyed;
|
|
310
311
|
constructor(params: RiveFileParameters);
|
|
311
312
|
private initData;
|
|
312
313
|
init(): Promise<void>;
|
|
@@ -358,6 +359,7 @@ export declare class Rive {
|
|
|
358
359
|
private animator;
|
|
359
360
|
private assetLoader;
|
|
360
361
|
private static readonly missingErrorMessage;
|
|
362
|
+
private static readonly cleanupErrorMessage;
|
|
361
363
|
private shouldDisableRiveListeners;
|
|
362
364
|
private automaticallyHandleEvents;
|
|
363
365
|
private enableRiveAssetCDN;
|
|
@@ -367,6 +369,7 @@ export declare class Rive {
|
|
|
367
369
|
private _devicePixelRatioUsed;
|
|
368
370
|
private _hasZeroSize;
|
|
369
371
|
private _audioEventListener;
|
|
372
|
+
private _boundDraw;
|
|
370
373
|
durations: number[];
|
|
371
374
|
frameTimes: number[];
|
|
372
375
|
frameCount: number;
|
package/rive.js
CHANGED
|
@@ -2269,7 +2269,7 @@ Qc();
|
|
|
2269
2269
|
/* 2 */
|
|
2270
2270
|
/***/ ((module) => {
|
|
2271
2271
|
|
|
2272
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.
|
|
2272
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.26.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}}');
|
|
2273
2273
|
|
|
2274
2274
|
/***/ }),
|
|
2275
2275
|
/* 3 */
|
|
@@ -2802,6 +2802,21 @@ var __generator = (undefined && undefined.__generator) || function (thisArg, bod
|
|
|
2802
2802
|
|
|
2803
2803
|
|
|
2804
2804
|
|
|
2805
|
+
var RiveError = /** @class */ (function (_super) {
|
|
2806
|
+
__extends(RiveError, _super);
|
|
2807
|
+
function RiveError() {
|
|
2808
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
2809
|
+
_this.isHandledError = true;
|
|
2810
|
+
return _this;
|
|
2811
|
+
}
|
|
2812
|
+
return RiveError;
|
|
2813
|
+
}(Error));
|
|
2814
|
+
// #regions helpers
|
|
2815
|
+
var resolveErrorMessage = function (error) {
|
|
2816
|
+
return error && error.isHandledError
|
|
2817
|
+
? error.message
|
|
2818
|
+
: "Problem loading file; may be corrupt!";
|
|
2819
|
+
};
|
|
2805
2820
|
// #region layout
|
|
2806
2821
|
// Fit options for the canvas
|
|
2807
2822
|
var Fit;
|
|
@@ -3888,6 +3903,7 @@ var RiveFile = /** @class */ (function () {
|
|
|
3888
3903
|
// Allow the runtime to automatically load assets hosted in Rive's runtime.
|
|
3889
3904
|
this.enableRiveAssetCDN = true;
|
|
3890
3905
|
this.referenceCount = 0;
|
|
3906
|
+
this.destroyed = false;
|
|
3891
3907
|
this.src = params.src;
|
|
3892
3908
|
this.buffer = params.buffer;
|
|
3893
3909
|
if (params.assetLoader)
|
|
@@ -3906,16 +3922,20 @@ var RiveFile = /** @class */ (function () {
|
|
|
3906
3922
|
RiveFile.prototype.initData = function () {
|
|
3907
3923
|
return __awaiter(this, void 0, void 0, function () {
|
|
3908
3924
|
var _a, loader, _b;
|
|
3909
|
-
|
|
3910
|
-
|
|
3925
|
+
var _c;
|
|
3926
|
+
return __generator(this, function (_d) {
|
|
3927
|
+
switch (_d.label) {
|
|
3911
3928
|
case 0:
|
|
3912
3929
|
if (!this.src) return [3 /*break*/, 2];
|
|
3913
3930
|
_a = this;
|
|
3914
3931
|
return [4 /*yield*/, loadRiveFile(this.src)];
|
|
3915
3932
|
case 1:
|
|
3916
|
-
_a.buffer =
|
|
3917
|
-
|
|
3933
|
+
_a.buffer = _d.sent();
|
|
3934
|
+
_d.label = 2;
|
|
3918
3935
|
case 2:
|
|
3936
|
+
if (this.destroyed) {
|
|
3937
|
+
return [2 /*return*/];
|
|
3938
|
+
}
|
|
3919
3939
|
if (this.assetLoader) {
|
|
3920
3940
|
loader = new this.runtime.CustomFileAssetLoader({
|
|
3921
3941
|
loadContents: this.assetLoader,
|
|
@@ -3926,7 +3946,12 @@ var RiveFile = /** @class */ (function () {
|
|
|
3926
3946
|
return [4 /*yield*/, this.runtime.load(new Uint8Array(this.buffer), loader, this.enableRiveAssetCDN)];
|
|
3927
3947
|
case 3:
|
|
3928
3948
|
// Load the Rive file
|
|
3929
|
-
_b.file =
|
|
3949
|
+
_b.file = _d.sent();
|
|
3950
|
+
if (this.destroyed) {
|
|
3951
|
+
(_c = this.file) === null || _c === void 0 ? void 0 : _c.delete();
|
|
3952
|
+
this.file = null;
|
|
3953
|
+
return [2 /*return*/];
|
|
3954
|
+
}
|
|
3930
3955
|
if (this.file !== null) {
|
|
3931
3956
|
this.eventManager.fire({
|
|
3932
3957
|
type: EventType.Load,
|
|
@@ -3959,6 +3984,9 @@ var RiveFile = /** @class */ (function () {
|
|
|
3959
3984
|
return [4 /*yield*/, RuntimeLoader.awaitInstance()];
|
|
3960
3985
|
case 1:
|
|
3961
3986
|
_a.runtime = _b.sent();
|
|
3987
|
+
if (this.destroyed) {
|
|
3988
|
+
return [2 /*return*/];
|
|
3989
|
+
}
|
|
3962
3990
|
return [4 /*yield*/, this.initData()];
|
|
3963
3991
|
case 2:
|
|
3964
3992
|
_b.sent();
|
|
@@ -3995,6 +4023,8 @@ var RiveFile = /** @class */ (function () {
|
|
|
3995
4023
|
if (this.referenceCount <= 0) {
|
|
3996
4024
|
this.removeAllRiveEventListeners();
|
|
3997
4025
|
(_a = this.file) === null || _a === void 0 ? void 0 : _a.delete();
|
|
4026
|
+
this.file = null;
|
|
4027
|
+
this.destroyed = true;
|
|
3998
4028
|
}
|
|
3999
4029
|
};
|
|
4000
4030
|
/**
|
|
@@ -4055,14 +4085,22 @@ var Rive = /** @class */ (function () {
|
|
|
4055
4085
|
this._hasZeroSize = false;
|
|
4056
4086
|
// Audio event listener
|
|
4057
4087
|
this._audioEventListener = null;
|
|
4088
|
+
// draw method bound to the class
|
|
4089
|
+
this._boundDraw = null;
|
|
4058
4090
|
// Durations to generate a frame for the last second. Used for performance profiling.
|
|
4059
4091
|
this.durations = [];
|
|
4060
4092
|
this.frameTimes = [];
|
|
4061
4093
|
this.frameCount = 0;
|
|
4062
4094
|
this.isTouchScrollEnabled = false;
|
|
4063
4095
|
this.onCanvasResize = function (hasZeroSize) {
|
|
4096
|
+
var toggledDisplay = _this._hasZeroSize !== hasZeroSize;
|
|
4064
4097
|
_this._hasZeroSize = hasZeroSize;
|
|
4065
|
-
if (!
|
|
4098
|
+
if (!hasZeroSize) {
|
|
4099
|
+
if (toggledDisplay) {
|
|
4100
|
+
_this.resizeDrawingSurfaceToCanvas();
|
|
4101
|
+
}
|
|
4102
|
+
}
|
|
4103
|
+
else if (!_this._layout.maxX || !_this._layout.maxY) {
|
|
4066
4104
|
_this.resizeToCanvas();
|
|
4067
4105
|
}
|
|
4068
4106
|
};
|
|
@@ -4071,6 +4109,7 @@ var Rive = /** @class */ (function () {
|
|
|
4071
4109
|
* Used for debugging purposes
|
|
4072
4110
|
*/
|
|
4073
4111
|
this.renderSecondTimer = 0;
|
|
4112
|
+
this._boundDraw = this.draw.bind(this);
|
|
4074
4113
|
this.canvas = params.canvas;
|
|
4075
4114
|
if (params.canvas.constructor === HTMLCanvasElement) {
|
|
4076
4115
|
this._observed = observers.add(this.canvas, this.onCanvasResize);
|
|
@@ -4281,6 +4320,10 @@ var Rive = /** @class */ (function () {
|
|
|
4281
4320
|
_b.sent();
|
|
4282
4321
|
_b.label = 2;
|
|
4283
4322
|
case 2:
|
|
4323
|
+
// Check for riveFile in case it has been cleaned up while initializing;
|
|
4324
|
+
if (!this.riveFile) {
|
|
4325
|
+
throw new RiveError(Rive.cleanupErrorMessage);
|
|
4326
|
+
}
|
|
4284
4327
|
this.file = this.riveFile.getInstance();
|
|
4285
4328
|
// Initialize and draw frame
|
|
4286
4329
|
this.initArtboard(artboardName, animationNames, stateMachineNames, autoplay);
|
|
@@ -4302,7 +4345,7 @@ var Rive = /** @class */ (function () {
|
|
|
4302
4345
|
return [2 /*return*/, Promise.resolve()];
|
|
4303
4346
|
case 3:
|
|
4304
4347
|
error_1 = _b.sent();
|
|
4305
|
-
msg =
|
|
4348
|
+
msg = resolveErrorMessage(error_1);
|
|
4306
4349
|
console.warn(msg);
|
|
4307
4350
|
this.eventManager.fire({ type: EventType.LoadError, data: msg });
|
|
4308
4351
|
return [2 /*return*/, Promise.reject(msg)];
|
|
@@ -4360,7 +4403,15 @@ var Rive = /** @class */ (function () {
|
|
|
4360
4403
|
};
|
|
4361
4404
|
// Draws the current artboard frame
|
|
4362
4405
|
Rive.prototype.drawFrame = function () {
|
|
4363
|
-
|
|
4406
|
+
var _a;
|
|
4407
|
+
if ((_a = document === null || document === void 0 ? void 0 : document.timeline) === null || _a === void 0 ? void 0 : _a.currentTime) {
|
|
4408
|
+
if (this.loaded && this.artboard && !this.frameRequestId) {
|
|
4409
|
+
this._boundDraw(document.timeline.currentTime);
|
|
4410
|
+
}
|
|
4411
|
+
}
|
|
4412
|
+
else {
|
|
4413
|
+
this.startRendering();
|
|
4414
|
+
}
|
|
4364
4415
|
};
|
|
4365
4416
|
/**
|
|
4366
4417
|
* Draw rendering loop; renders animation frames at the correct time interval.
|
|
@@ -4770,8 +4821,8 @@ var Rive = /** @class */ (function () {
|
|
|
4770
4821
|
this.devicePixelRatioUsed = dpr;
|
|
4771
4822
|
this.canvas.width = dpr * width;
|
|
4772
4823
|
this.canvas.height = dpr * height;
|
|
4773
|
-
this.startRendering();
|
|
4774
4824
|
this.resizeToCanvas();
|
|
4825
|
+
this.drawFrame();
|
|
4775
4826
|
if (this.layout.fit === Fit.Layout) {
|
|
4776
4827
|
var scaleFactor = this._layout.layoutScaleFactor;
|
|
4777
4828
|
this.artboard.width = width / scaleFactor;
|
|
@@ -5160,10 +5211,10 @@ var Rive = /** @class */ (function () {
|
|
|
5160
5211
|
Rive.prototype.startRendering = function () {
|
|
5161
5212
|
if (this.loaded && this.artboard && !this.frameRequestId) {
|
|
5162
5213
|
if (this.runtime.requestAnimationFrame) {
|
|
5163
|
-
this.frameRequestId = this.runtime.requestAnimationFrame(this.
|
|
5214
|
+
this.frameRequestId = this.runtime.requestAnimationFrame(this._boundDraw);
|
|
5164
5215
|
}
|
|
5165
5216
|
else {
|
|
5166
|
-
this.frameRequestId = requestAnimationFrame(this.
|
|
5217
|
+
this.frameRequestId = requestAnimationFrame(this._boundDraw);
|
|
5167
5218
|
}
|
|
5168
5219
|
}
|
|
5169
5220
|
};
|
|
@@ -5331,6 +5382,8 @@ var Rive = /** @class */ (function () {
|
|
|
5331
5382
|
});
|
|
5332
5383
|
// Error message for missing source or buffer
|
|
5333
5384
|
Rive.missingErrorMessage = "Rive source file or data buffer required";
|
|
5385
|
+
// Error message for removed rive file
|
|
5386
|
+
Rive.cleanupErrorMessage = "Attempt to use file after calling cleanup.";
|
|
5334
5387
|
return Rive;
|
|
5335
5388
|
}());
|
|
5336
5389
|
|