@rive-app/canvas-lite 2.15.0 → 2.15.1
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 +8 -0
- package/rive.js +86 -11
- package/rive.js.map +1 -1
- package/rive.wasm +0 -0
- package/rive_advanced.mjs.d.ts +1 -0
package/package.json
CHANGED
package/rive.d.ts
CHANGED
|
@@ -285,6 +285,7 @@ export declare class Rive {
|
|
|
285
285
|
private _layout;
|
|
286
286
|
private renderer;
|
|
287
287
|
private loaded;
|
|
288
|
+
private _observed;
|
|
288
289
|
/**
|
|
289
290
|
* Tracks if a Rive file is loaded; we need this in addition to loaded as some
|
|
290
291
|
* commands (e.g. contents) can be called as soon as the file is loaded.
|
|
@@ -306,6 +307,7 @@ export declare class Rive {
|
|
|
306
307
|
private automaticallyHandleEvents;
|
|
307
308
|
private enableRiveAssetCDN;
|
|
308
309
|
private _volume;
|
|
310
|
+
private _hasZeroSize;
|
|
309
311
|
durations: number[];
|
|
310
312
|
frameTimes: number[];
|
|
311
313
|
frameCount: number;
|
|
@@ -313,6 +315,7 @@ export declare class Rive {
|
|
|
313
315
|
constructor(params: RiveParameters);
|
|
314
316
|
static new(params: RiveParameters): Rive;
|
|
315
317
|
private onSystemAudioChanged;
|
|
318
|
+
private onCanvasResize;
|
|
316
319
|
private init;
|
|
317
320
|
/**
|
|
318
321
|
* Setup Rive Listeners on the canvas
|
|
@@ -325,6 +328,11 @@ export declare class Rive {
|
|
|
325
328
|
* Remove Rive Listeners setup on the canvas
|
|
326
329
|
*/
|
|
327
330
|
removeRiveListeners(): void;
|
|
331
|
+
/**
|
|
332
|
+
* If the instance has audio and the system audio is not ready
|
|
333
|
+
* we hook the instance to the audio manager
|
|
334
|
+
*/
|
|
335
|
+
private initializeAudio;
|
|
328
336
|
private initData;
|
|
329
337
|
private initArtboard;
|
|
330
338
|
drawFrame(): void;
|
package/rive.js
CHANGED
|
@@ -2257,7 +2257,7 @@ Pc();
|
|
|
2257
2257
|
/* 2 */
|
|
2258
2258
|
/***/ ((module) => {
|
|
2259
2259
|
|
|
2260
|
-
module.exports = JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.15.
|
|
2260
|
+
module.exports = JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.15.1","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.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
|
|
2261
2261
|
|
|
2262
2262
|
/***/ }),
|
|
2263
2263
|
/* 3 */
|
|
@@ -3680,6 +3680,51 @@ var AudioManager = /** @class */ (function (_super) {
|
|
|
3680
3680
|
return AudioManager;
|
|
3681
3681
|
}(EventManager));
|
|
3682
3682
|
var audioManager = new AudioManager();
|
|
3683
|
+
/**
|
|
3684
|
+
* This class takes care of any observers that will be attached to an animation.
|
|
3685
|
+
* It should be treated as a singleton because observers are much more performant
|
|
3686
|
+
* when used for observing multiple elements by a single instance.
|
|
3687
|
+
*/
|
|
3688
|
+
var ObjectObservers = /** @class */ (function () {
|
|
3689
|
+
function ObjectObservers() {
|
|
3690
|
+
var _this = this;
|
|
3691
|
+
this._elementsMap = new Map();
|
|
3692
|
+
/**
|
|
3693
|
+
* Resize observers trigger both when the element changes its size and also when the
|
|
3694
|
+
* element is added or removed from the document.
|
|
3695
|
+
*/
|
|
3696
|
+
this._onObservedEntry = function (entry) {
|
|
3697
|
+
var observed = _this._elementsMap.get(entry.target);
|
|
3698
|
+
if (observed !== null) {
|
|
3699
|
+
observed.onResize(entry.target.clientWidth == 0 || entry.target.clientHeight == 0);
|
|
3700
|
+
}
|
|
3701
|
+
else {
|
|
3702
|
+
_this._resizeObserver.unobserve(entry.target);
|
|
3703
|
+
}
|
|
3704
|
+
};
|
|
3705
|
+
this._onObserved = function (entries) {
|
|
3706
|
+
entries.forEach(_this._onObservedEntry);
|
|
3707
|
+
};
|
|
3708
|
+
this._resizeObserver = new ResizeObserver(this._onObserved);
|
|
3709
|
+
}
|
|
3710
|
+
// Adds an observable element
|
|
3711
|
+
ObjectObservers.prototype.add = function (element, onResize) {
|
|
3712
|
+
var observed = {
|
|
3713
|
+
onResize: onResize,
|
|
3714
|
+
element: element,
|
|
3715
|
+
};
|
|
3716
|
+
this._elementsMap.set(element, observed);
|
|
3717
|
+
this._resizeObserver.observe(element);
|
|
3718
|
+
return observed;
|
|
3719
|
+
};
|
|
3720
|
+
// Removes an observable element
|
|
3721
|
+
ObjectObservers.prototype.remove = function (observed) {
|
|
3722
|
+
this._resizeObserver.unobserve(observed.element);
|
|
3723
|
+
this._elementsMap.delete(observed.element);
|
|
3724
|
+
};
|
|
3725
|
+
return ObjectObservers;
|
|
3726
|
+
}());
|
|
3727
|
+
var observers = new ObjectObservers();
|
|
3683
3728
|
var Rive = /** @class */ (function () {
|
|
3684
3729
|
function Rive(params) {
|
|
3685
3730
|
var _this = this;
|
|
@@ -3704,17 +3749,28 @@ var Rive = /** @class */ (function () {
|
|
|
3704
3749
|
this.enableRiveAssetCDN = true;
|
|
3705
3750
|
// Keep a local value of the set volume to update it asynchronously
|
|
3706
3751
|
this._volume = 1;
|
|
3752
|
+
// Whether the canvas element's size is 0
|
|
3753
|
+
this._hasZeroSize = false;
|
|
3707
3754
|
// Durations to generate a frame for the last second. Used for performance profiling.
|
|
3708
3755
|
this.durations = [];
|
|
3709
3756
|
this.frameTimes = [];
|
|
3710
3757
|
this.frameCount = 0;
|
|
3711
3758
|
this.isTouchScrollEnabled = false;
|
|
3759
|
+
this.onCanvasResize = function (hasZeroSize) {
|
|
3760
|
+
_this._hasZeroSize = hasZeroSize;
|
|
3761
|
+
if (!_this._layout.maxX || !_this._layout.maxY) {
|
|
3762
|
+
_this.resizeToCanvas();
|
|
3763
|
+
}
|
|
3764
|
+
};
|
|
3712
3765
|
/**
|
|
3713
3766
|
* Used be draw to track when a second of active rendering time has passed.
|
|
3714
3767
|
* Used for debugging purposes
|
|
3715
3768
|
*/
|
|
3716
3769
|
this.renderSecondTimer = 0;
|
|
3717
3770
|
this.canvas = params.canvas;
|
|
3771
|
+
if (params.canvas.constructor === HTMLCanvasElement) {
|
|
3772
|
+
this._observed = observers.add(this.canvas, this.onCanvasResize);
|
|
3773
|
+
}
|
|
3718
3774
|
this.src = params.src;
|
|
3719
3775
|
this.buffer = params.buffer;
|
|
3720
3776
|
this.layout = (_a = params.layout) !== null && _a !== void 0 ? _a : new Layout();
|
|
@@ -3767,14 +3823,6 @@ var Rive = /** @class */ (function () {
|
|
|
3767
3823
|
this.assetLoader = params.assetLoader;
|
|
3768
3824
|
// Hook up the task queue
|
|
3769
3825
|
this.taskQueue = new TaskQueueManager(this.eventManager);
|
|
3770
|
-
// Initialize audio
|
|
3771
|
-
if (audioManager.status == SystemAudioStatus.UNAVAILABLE) {
|
|
3772
|
-
audioManager.add({
|
|
3773
|
-
type: EventType.AudioStatusChange,
|
|
3774
|
-
callback: function () { return _this.onSystemAudioChanged(); },
|
|
3775
|
-
});
|
|
3776
|
-
audioManager.establishAudio();
|
|
3777
|
-
}
|
|
3778
3826
|
this.init({
|
|
3779
3827
|
src: this.src,
|
|
3780
3828
|
buffer: this.buffer,
|
|
@@ -3870,6 +3918,24 @@ var Rive = /** @class */ (function () {
|
|
|
3870
3918
|
this.eventCleanup();
|
|
3871
3919
|
}
|
|
3872
3920
|
};
|
|
3921
|
+
/**
|
|
3922
|
+
* If the instance has audio and the system audio is not ready
|
|
3923
|
+
* we hook the instance to the audio manager
|
|
3924
|
+
*/
|
|
3925
|
+
Rive.prototype.initializeAudio = function () {
|
|
3926
|
+
var _this = this;
|
|
3927
|
+
var _a;
|
|
3928
|
+
// Initialize audio if needed
|
|
3929
|
+
if (audioManager.status == SystemAudioStatus.UNAVAILABLE) {
|
|
3930
|
+
if ((_a = this.artboard) === null || _a === void 0 ? void 0 : _a.hasAudio) {
|
|
3931
|
+
audioManager.add({
|
|
3932
|
+
type: EventType.AudioStatusChange,
|
|
3933
|
+
callback: function () { return _this.onSystemAudioChanged(); },
|
|
3934
|
+
});
|
|
3935
|
+
audioManager.establishAudio();
|
|
3936
|
+
}
|
|
3937
|
+
}
|
|
3938
|
+
};
|
|
3873
3939
|
// Initializes runtime with Rive data and preps for playing
|
|
3874
3940
|
Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay) {
|
|
3875
3941
|
var _a;
|
|
@@ -3899,6 +3965,8 @@ var Rive = /** @class */ (function () {
|
|
|
3899
3965
|
if (this.file) {
|
|
3900
3966
|
// Initialize and draw frame
|
|
3901
3967
|
this.initArtboard(artboardName, animationNames, stateMachineNames, autoplay);
|
|
3968
|
+
// Check for audio
|
|
3969
|
+
this.initializeAudio();
|
|
3902
3970
|
// Everything's set up, emit a load event
|
|
3903
3971
|
this.loaded = true;
|
|
3904
3972
|
this.eventManager.fire({
|
|
@@ -3976,9 +4044,9 @@ var Rive = /** @class */ (function () {
|
|
|
3976
4044
|
* @param time the time at which to render a frame
|
|
3977
4045
|
*/
|
|
3978
4046
|
Rive.prototype.draw = function (time, onSecond) {
|
|
3979
|
-
var before = performance.now();
|
|
3980
4047
|
// Clear the frameRequestId, as we're now rendering a fresh frame
|
|
3981
4048
|
this.frameRequestId = null;
|
|
4049
|
+
var before = performance.now();
|
|
3982
4050
|
// On the first pass, make sure lastTime has a valid value
|
|
3983
4051
|
if (!this.lastRenderTime) {
|
|
3984
4052
|
this.lastRenderTime = time;
|
|
@@ -4057,7 +4125,10 @@ var Rive = /** @class */ (function () {
|
|
|
4057
4125
|
renderer.save();
|
|
4058
4126
|
// Update the renderer alignment if necessary
|
|
4059
4127
|
this.alignRenderer();
|
|
4060
|
-
|
|
4128
|
+
// Do not draw on 0 canvas size
|
|
4129
|
+
if (!this._hasZeroSize) {
|
|
4130
|
+
this.artboard.draw(renderer);
|
|
4131
|
+
}
|
|
4061
4132
|
renderer.restore();
|
|
4062
4133
|
renderer.flush();
|
|
4063
4134
|
// Check for any animations that looped
|
|
@@ -4137,6 +4208,10 @@ var Rive = /** @class */ (function () {
|
|
|
4137
4208
|
this.stopRendering();
|
|
4138
4209
|
// Clean up any artboard, animation or state machine instances.
|
|
4139
4210
|
this.cleanupInstances();
|
|
4211
|
+
// Remove from observer
|
|
4212
|
+
if (this._observed !== null) {
|
|
4213
|
+
observers.remove(this._observed);
|
|
4214
|
+
}
|
|
4140
4215
|
// Delete the rive file
|
|
4141
4216
|
(_a = this.file) === null || _a === void 0 ? void 0 : _a.delete();
|
|
4142
4217
|
this.file = null;
|