@rive-app/canvas 2.25.7 → 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 +73 -20
- 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
|
@@ -746,7 +746,7 @@ function Ya(a, b) {
|
|
|
746
746
|
return Xa(c, a, b);
|
|
747
747
|
}));
|
|
748
748
|
}
|
|
749
|
-
var Za, $a, db = {
|
|
749
|
+
var Za, $a, db = {447260:(a, b, c, d, e) => {
|
|
750
750
|
if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
|
|
751
751
|
return 0;
|
|
752
752
|
}
|
|
@@ -809,9 +809,9 @@ var Za, $a, db = {446236:(a, b, c, d, e) => {
|
|
|
809
809
|
}
|
|
810
810
|
window.h.Aa += 1;
|
|
811
811
|
return 1;
|
|
812
|
-
},
|
|
812
|
+
}, 449438:() => {
|
|
813
813
|
"undefined" !== typeof window.h && (--window.h.Aa, 0 === window.h.Aa && delete window.h);
|
|
814
|
-
},
|
|
814
|
+
}, 449602:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 449706:() => {
|
|
815
815
|
try {
|
|
816
816
|
var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
|
|
817
817
|
a.close();
|
|
@@ -819,7 +819,7 @@ var Za, $a, db = {446236:(a, b, c, d, e) => {
|
|
|
819
819
|
} catch (c) {
|
|
820
820
|
return 0;
|
|
821
821
|
}
|
|
822
|
-
},
|
|
822
|
+
}, 449877:(a, b, c, d, e, f) => {
|
|
823
823
|
if ("undefined" === typeof window.h) {
|
|
824
824
|
return -1;
|
|
825
825
|
}
|
|
@@ -865,7 +865,7 @@ var Za, $a, db = {446236:(a, b, c, d, e) => {
|
|
|
865
865
|
a == window.h.I.ya && g.Z.connect(g.J.destination);
|
|
866
866
|
g.pb = f;
|
|
867
867
|
return window.h.yc(g);
|
|
868
|
-
},
|
|
868
|
+
}, 452754:a => window.h.ra(a).J.sampleRate, 452827:a => {
|
|
869
869
|
a = window.h.ra(a);
|
|
870
870
|
void 0 !== a.Z && (a.Z.onaudioprocess = function() {
|
|
871
871
|
}, a.Z.disconnect(), a.Z = void 0);
|
|
@@ -873,13 +873,13 @@ var Za, $a, db = {446236:(a, b, c, d, e) => {
|
|
|
873
873
|
a.J.close();
|
|
874
874
|
a.J = void 0;
|
|
875
875
|
a.pb = void 0;
|
|
876
|
-
},
|
|
876
|
+
}, 453227:a => {
|
|
877
877
|
window.h.Cb(a);
|
|
878
|
-
},
|
|
878
|
+
}, 453277:a => {
|
|
879
879
|
a = window.h.ra(a);
|
|
880
880
|
a.J.resume();
|
|
881
881
|
a.state = window.h.ga.xb;
|
|
882
|
-
},
|
|
882
|
+
}, 453416:a => {
|
|
883
883
|
a = window.h.ra(a);
|
|
884
884
|
a.J.suspend();
|
|
885
885
|
a.state = window.h.ga.stopped;
|
|
@@ -3365,7 +3365,7 @@ $d();
|
|
|
3365
3365
|
/* 2 */
|
|
3366
3366
|
/***/ ((module) => {
|
|
3367
3367
|
|
|
3368
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas","version":"2.
|
|
3368
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas","version":"2.26.0","description":"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}}');
|
|
3369
3369
|
|
|
3370
3370
|
/***/ }),
|
|
3371
3371
|
/* 3 */
|
|
@@ -3898,6 +3898,21 @@ var __generator = (undefined && undefined.__generator) || function (thisArg, bod
|
|
|
3898
3898
|
|
|
3899
3899
|
|
|
3900
3900
|
|
|
3901
|
+
var RiveError = /** @class */ (function (_super) {
|
|
3902
|
+
__extends(RiveError, _super);
|
|
3903
|
+
function RiveError() {
|
|
3904
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
3905
|
+
_this.isHandledError = true;
|
|
3906
|
+
return _this;
|
|
3907
|
+
}
|
|
3908
|
+
return RiveError;
|
|
3909
|
+
}(Error));
|
|
3910
|
+
// #regions helpers
|
|
3911
|
+
var resolveErrorMessage = function (error) {
|
|
3912
|
+
return error && error.isHandledError
|
|
3913
|
+
? error.message
|
|
3914
|
+
: "Problem loading file; may be corrupt!";
|
|
3915
|
+
};
|
|
3901
3916
|
// #region layout
|
|
3902
3917
|
// Fit options for the canvas
|
|
3903
3918
|
var Fit;
|
|
@@ -4984,6 +4999,7 @@ var RiveFile = /** @class */ (function () {
|
|
|
4984
4999
|
// Allow the runtime to automatically load assets hosted in Rive's runtime.
|
|
4985
5000
|
this.enableRiveAssetCDN = true;
|
|
4986
5001
|
this.referenceCount = 0;
|
|
5002
|
+
this.destroyed = false;
|
|
4987
5003
|
this.src = params.src;
|
|
4988
5004
|
this.buffer = params.buffer;
|
|
4989
5005
|
if (params.assetLoader)
|
|
@@ -5002,16 +5018,20 @@ var RiveFile = /** @class */ (function () {
|
|
|
5002
5018
|
RiveFile.prototype.initData = function () {
|
|
5003
5019
|
return __awaiter(this, void 0, void 0, function () {
|
|
5004
5020
|
var _a, loader, _b;
|
|
5005
|
-
|
|
5006
|
-
|
|
5021
|
+
var _c;
|
|
5022
|
+
return __generator(this, function (_d) {
|
|
5023
|
+
switch (_d.label) {
|
|
5007
5024
|
case 0:
|
|
5008
5025
|
if (!this.src) return [3 /*break*/, 2];
|
|
5009
5026
|
_a = this;
|
|
5010
5027
|
return [4 /*yield*/, loadRiveFile(this.src)];
|
|
5011
5028
|
case 1:
|
|
5012
|
-
_a.buffer =
|
|
5013
|
-
|
|
5029
|
+
_a.buffer = _d.sent();
|
|
5030
|
+
_d.label = 2;
|
|
5014
5031
|
case 2:
|
|
5032
|
+
if (this.destroyed) {
|
|
5033
|
+
return [2 /*return*/];
|
|
5034
|
+
}
|
|
5015
5035
|
if (this.assetLoader) {
|
|
5016
5036
|
loader = new this.runtime.CustomFileAssetLoader({
|
|
5017
5037
|
loadContents: this.assetLoader,
|
|
@@ -5022,7 +5042,12 @@ var RiveFile = /** @class */ (function () {
|
|
|
5022
5042
|
return [4 /*yield*/, this.runtime.load(new Uint8Array(this.buffer), loader, this.enableRiveAssetCDN)];
|
|
5023
5043
|
case 3:
|
|
5024
5044
|
// Load the Rive file
|
|
5025
|
-
_b.file =
|
|
5045
|
+
_b.file = _d.sent();
|
|
5046
|
+
if (this.destroyed) {
|
|
5047
|
+
(_c = this.file) === null || _c === void 0 ? void 0 : _c.delete();
|
|
5048
|
+
this.file = null;
|
|
5049
|
+
return [2 /*return*/];
|
|
5050
|
+
}
|
|
5026
5051
|
if (this.file !== null) {
|
|
5027
5052
|
this.eventManager.fire({
|
|
5028
5053
|
type: EventType.Load,
|
|
@@ -5055,6 +5080,9 @@ var RiveFile = /** @class */ (function () {
|
|
|
5055
5080
|
return [4 /*yield*/, RuntimeLoader.awaitInstance()];
|
|
5056
5081
|
case 1:
|
|
5057
5082
|
_a.runtime = _b.sent();
|
|
5083
|
+
if (this.destroyed) {
|
|
5084
|
+
return [2 /*return*/];
|
|
5085
|
+
}
|
|
5058
5086
|
return [4 /*yield*/, this.initData()];
|
|
5059
5087
|
case 2:
|
|
5060
5088
|
_b.sent();
|
|
@@ -5091,6 +5119,8 @@ var RiveFile = /** @class */ (function () {
|
|
|
5091
5119
|
if (this.referenceCount <= 0) {
|
|
5092
5120
|
this.removeAllRiveEventListeners();
|
|
5093
5121
|
(_a = this.file) === null || _a === void 0 ? void 0 : _a.delete();
|
|
5122
|
+
this.file = null;
|
|
5123
|
+
this.destroyed = true;
|
|
5094
5124
|
}
|
|
5095
5125
|
};
|
|
5096
5126
|
/**
|
|
@@ -5151,14 +5181,22 @@ var Rive = /** @class */ (function () {
|
|
|
5151
5181
|
this._hasZeroSize = false;
|
|
5152
5182
|
// Audio event listener
|
|
5153
5183
|
this._audioEventListener = null;
|
|
5184
|
+
// draw method bound to the class
|
|
5185
|
+
this._boundDraw = null;
|
|
5154
5186
|
// Durations to generate a frame for the last second. Used for performance profiling.
|
|
5155
5187
|
this.durations = [];
|
|
5156
5188
|
this.frameTimes = [];
|
|
5157
5189
|
this.frameCount = 0;
|
|
5158
5190
|
this.isTouchScrollEnabled = false;
|
|
5159
5191
|
this.onCanvasResize = function (hasZeroSize) {
|
|
5192
|
+
var toggledDisplay = _this._hasZeroSize !== hasZeroSize;
|
|
5160
5193
|
_this._hasZeroSize = hasZeroSize;
|
|
5161
|
-
if (!
|
|
5194
|
+
if (!hasZeroSize) {
|
|
5195
|
+
if (toggledDisplay) {
|
|
5196
|
+
_this.resizeDrawingSurfaceToCanvas();
|
|
5197
|
+
}
|
|
5198
|
+
}
|
|
5199
|
+
else if (!_this._layout.maxX || !_this._layout.maxY) {
|
|
5162
5200
|
_this.resizeToCanvas();
|
|
5163
5201
|
}
|
|
5164
5202
|
};
|
|
@@ -5167,6 +5205,7 @@ var Rive = /** @class */ (function () {
|
|
|
5167
5205
|
* Used for debugging purposes
|
|
5168
5206
|
*/
|
|
5169
5207
|
this.renderSecondTimer = 0;
|
|
5208
|
+
this._boundDraw = this.draw.bind(this);
|
|
5170
5209
|
this.canvas = params.canvas;
|
|
5171
5210
|
if (params.canvas.constructor === HTMLCanvasElement) {
|
|
5172
5211
|
this._observed = observers.add(this.canvas, this.onCanvasResize);
|
|
@@ -5377,6 +5416,10 @@ var Rive = /** @class */ (function () {
|
|
|
5377
5416
|
_b.sent();
|
|
5378
5417
|
_b.label = 2;
|
|
5379
5418
|
case 2:
|
|
5419
|
+
// Check for riveFile in case it has been cleaned up while initializing;
|
|
5420
|
+
if (!this.riveFile) {
|
|
5421
|
+
throw new RiveError(Rive.cleanupErrorMessage);
|
|
5422
|
+
}
|
|
5380
5423
|
this.file = this.riveFile.getInstance();
|
|
5381
5424
|
// Initialize and draw frame
|
|
5382
5425
|
this.initArtboard(artboardName, animationNames, stateMachineNames, autoplay);
|
|
@@ -5398,7 +5441,7 @@ var Rive = /** @class */ (function () {
|
|
|
5398
5441
|
return [2 /*return*/, Promise.resolve()];
|
|
5399
5442
|
case 3:
|
|
5400
5443
|
error_1 = _b.sent();
|
|
5401
|
-
msg =
|
|
5444
|
+
msg = resolveErrorMessage(error_1);
|
|
5402
5445
|
console.warn(msg);
|
|
5403
5446
|
this.eventManager.fire({ type: EventType.LoadError, data: msg });
|
|
5404
5447
|
return [2 /*return*/, Promise.reject(msg)];
|
|
@@ -5456,7 +5499,15 @@ var Rive = /** @class */ (function () {
|
|
|
5456
5499
|
};
|
|
5457
5500
|
// Draws the current artboard frame
|
|
5458
5501
|
Rive.prototype.drawFrame = function () {
|
|
5459
|
-
|
|
5502
|
+
var _a;
|
|
5503
|
+
if ((_a = document === null || document === void 0 ? void 0 : document.timeline) === null || _a === void 0 ? void 0 : _a.currentTime) {
|
|
5504
|
+
if (this.loaded && this.artboard && !this.frameRequestId) {
|
|
5505
|
+
this._boundDraw(document.timeline.currentTime);
|
|
5506
|
+
}
|
|
5507
|
+
}
|
|
5508
|
+
else {
|
|
5509
|
+
this.startRendering();
|
|
5510
|
+
}
|
|
5460
5511
|
};
|
|
5461
5512
|
/**
|
|
5462
5513
|
* Draw rendering loop; renders animation frames at the correct time interval.
|
|
@@ -5866,8 +5917,8 @@ var Rive = /** @class */ (function () {
|
|
|
5866
5917
|
this.devicePixelRatioUsed = dpr;
|
|
5867
5918
|
this.canvas.width = dpr * width;
|
|
5868
5919
|
this.canvas.height = dpr * height;
|
|
5869
|
-
this.startRendering();
|
|
5870
5920
|
this.resizeToCanvas();
|
|
5921
|
+
this.drawFrame();
|
|
5871
5922
|
if (this.layout.fit === Fit.Layout) {
|
|
5872
5923
|
var scaleFactor = this._layout.layoutScaleFactor;
|
|
5873
5924
|
this.artboard.width = width / scaleFactor;
|
|
@@ -6256,10 +6307,10 @@ var Rive = /** @class */ (function () {
|
|
|
6256
6307
|
Rive.prototype.startRendering = function () {
|
|
6257
6308
|
if (this.loaded && this.artboard && !this.frameRequestId) {
|
|
6258
6309
|
if (this.runtime.requestAnimationFrame) {
|
|
6259
|
-
this.frameRequestId = this.runtime.requestAnimationFrame(this.
|
|
6310
|
+
this.frameRequestId = this.runtime.requestAnimationFrame(this._boundDraw);
|
|
6260
6311
|
}
|
|
6261
6312
|
else {
|
|
6262
|
-
this.frameRequestId = requestAnimationFrame(this.
|
|
6313
|
+
this.frameRequestId = requestAnimationFrame(this._boundDraw);
|
|
6263
6314
|
}
|
|
6264
6315
|
}
|
|
6265
6316
|
};
|
|
@@ -6427,6 +6478,8 @@ var Rive = /** @class */ (function () {
|
|
|
6427
6478
|
});
|
|
6428
6479
|
// Error message for missing source or buffer
|
|
6429
6480
|
Rive.missingErrorMessage = "Rive source file or data buffer required";
|
|
6481
|
+
// Error message for removed rive file
|
|
6482
|
+
Rive.cleanupErrorMessage = "Attempt to use file after calling cleanup.";
|
|
6430
6483
|
return Rive;
|
|
6431
6484
|
}());
|
|
6432
6485
|
|