@rive-app/canvas-lite 2.15.0 → 2.15.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 +1 -1
- package/rive.d.ts +8 -0
- package/rive.js +95 -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.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.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,60 @@ var AudioManager = /** @class */ (function (_super) {
|
|
|
3680
3680
|
return AudioManager;
|
|
3681
3681
|
}(EventManager));
|
|
3682
3682
|
var audioManager = new AudioManager();
|
|
3683
|
+
var FakeResizeObserver = /** @class */ (function () {
|
|
3684
|
+
function FakeResizeObserver() {
|
|
3685
|
+
}
|
|
3686
|
+
FakeResizeObserver.prototype.observe = function () { };
|
|
3687
|
+
FakeResizeObserver.prototype.unobserve = function () { };
|
|
3688
|
+
FakeResizeObserver.prototype.disconnect = function () { };
|
|
3689
|
+
return FakeResizeObserver;
|
|
3690
|
+
}());
|
|
3691
|
+
var MyResizeObserver = globalThis.ResizeObserver || FakeResizeObserver;
|
|
3692
|
+
/**
|
|
3693
|
+
* This class takes care of any observers that will be attached to an animation.
|
|
3694
|
+
* It should be treated as a singleton because observers are much more performant
|
|
3695
|
+
* when used for observing multiple elements by a single instance.
|
|
3696
|
+
*/
|
|
3697
|
+
var ObjectObservers = /** @class */ (function () {
|
|
3698
|
+
function ObjectObservers() {
|
|
3699
|
+
var _this = this;
|
|
3700
|
+
this._elementsMap = new Map();
|
|
3701
|
+
/**
|
|
3702
|
+
* Resize observers trigger both when the element changes its size and also when the
|
|
3703
|
+
* element is added or removed from the document.
|
|
3704
|
+
*/
|
|
3705
|
+
this._onObservedEntry = function (entry) {
|
|
3706
|
+
var observed = _this._elementsMap.get(entry.target);
|
|
3707
|
+
if (observed !== null) {
|
|
3708
|
+
observed.onResize(entry.target.clientWidth == 0 || entry.target.clientHeight == 0);
|
|
3709
|
+
}
|
|
3710
|
+
else {
|
|
3711
|
+
_this._resizeObserver.unobserve(entry.target);
|
|
3712
|
+
}
|
|
3713
|
+
};
|
|
3714
|
+
this._onObserved = function (entries) {
|
|
3715
|
+
entries.forEach(_this._onObservedEntry);
|
|
3716
|
+
};
|
|
3717
|
+
this._resizeObserver = new MyResizeObserver(this._onObserved);
|
|
3718
|
+
}
|
|
3719
|
+
// Adds an observable element
|
|
3720
|
+
ObjectObservers.prototype.add = function (element, onResize) {
|
|
3721
|
+
var observed = {
|
|
3722
|
+
onResize: onResize,
|
|
3723
|
+
element: element,
|
|
3724
|
+
};
|
|
3725
|
+
this._elementsMap.set(element, observed);
|
|
3726
|
+
this._resizeObserver.observe(element);
|
|
3727
|
+
return observed;
|
|
3728
|
+
};
|
|
3729
|
+
// Removes an observable element
|
|
3730
|
+
ObjectObservers.prototype.remove = function (observed) {
|
|
3731
|
+
this._resizeObserver.unobserve(observed.element);
|
|
3732
|
+
this._elementsMap.delete(observed.element);
|
|
3733
|
+
};
|
|
3734
|
+
return ObjectObservers;
|
|
3735
|
+
}());
|
|
3736
|
+
var observers = new ObjectObservers();
|
|
3683
3737
|
var Rive = /** @class */ (function () {
|
|
3684
3738
|
function Rive(params) {
|
|
3685
3739
|
var _this = this;
|
|
@@ -3704,17 +3758,28 @@ var Rive = /** @class */ (function () {
|
|
|
3704
3758
|
this.enableRiveAssetCDN = true;
|
|
3705
3759
|
// Keep a local value of the set volume to update it asynchronously
|
|
3706
3760
|
this._volume = 1;
|
|
3761
|
+
// Whether the canvas element's size is 0
|
|
3762
|
+
this._hasZeroSize = false;
|
|
3707
3763
|
// Durations to generate a frame for the last second. Used for performance profiling.
|
|
3708
3764
|
this.durations = [];
|
|
3709
3765
|
this.frameTimes = [];
|
|
3710
3766
|
this.frameCount = 0;
|
|
3711
3767
|
this.isTouchScrollEnabled = false;
|
|
3768
|
+
this.onCanvasResize = function (hasZeroSize) {
|
|
3769
|
+
_this._hasZeroSize = hasZeroSize;
|
|
3770
|
+
if (!_this._layout.maxX || !_this._layout.maxY) {
|
|
3771
|
+
_this.resizeToCanvas();
|
|
3772
|
+
}
|
|
3773
|
+
};
|
|
3712
3774
|
/**
|
|
3713
3775
|
* Used be draw to track when a second of active rendering time has passed.
|
|
3714
3776
|
* Used for debugging purposes
|
|
3715
3777
|
*/
|
|
3716
3778
|
this.renderSecondTimer = 0;
|
|
3717
3779
|
this.canvas = params.canvas;
|
|
3780
|
+
if (params.canvas.constructor === HTMLCanvasElement) {
|
|
3781
|
+
this._observed = observers.add(this.canvas, this.onCanvasResize);
|
|
3782
|
+
}
|
|
3718
3783
|
this.src = params.src;
|
|
3719
3784
|
this.buffer = params.buffer;
|
|
3720
3785
|
this.layout = (_a = params.layout) !== null && _a !== void 0 ? _a : new Layout();
|
|
@@ -3767,14 +3832,6 @@ var Rive = /** @class */ (function () {
|
|
|
3767
3832
|
this.assetLoader = params.assetLoader;
|
|
3768
3833
|
// Hook up the task queue
|
|
3769
3834
|
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
3835
|
this.init({
|
|
3779
3836
|
src: this.src,
|
|
3780
3837
|
buffer: this.buffer,
|
|
@@ -3870,6 +3927,24 @@ var Rive = /** @class */ (function () {
|
|
|
3870
3927
|
this.eventCleanup();
|
|
3871
3928
|
}
|
|
3872
3929
|
};
|
|
3930
|
+
/**
|
|
3931
|
+
* If the instance has audio and the system audio is not ready
|
|
3932
|
+
* we hook the instance to the audio manager
|
|
3933
|
+
*/
|
|
3934
|
+
Rive.prototype.initializeAudio = function () {
|
|
3935
|
+
var _this = this;
|
|
3936
|
+
var _a;
|
|
3937
|
+
// Initialize audio if needed
|
|
3938
|
+
if (audioManager.status == SystemAudioStatus.UNAVAILABLE) {
|
|
3939
|
+
if ((_a = this.artboard) === null || _a === void 0 ? void 0 : _a.hasAudio) {
|
|
3940
|
+
audioManager.add({
|
|
3941
|
+
type: EventType.AudioStatusChange,
|
|
3942
|
+
callback: function () { return _this.onSystemAudioChanged(); },
|
|
3943
|
+
});
|
|
3944
|
+
audioManager.establishAudio();
|
|
3945
|
+
}
|
|
3946
|
+
}
|
|
3947
|
+
};
|
|
3873
3948
|
// Initializes runtime with Rive data and preps for playing
|
|
3874
3949
|
Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay) {
|
|
3875
3950
|
var _a;
|
|
@@ -3899,6 +3974,8 @@ var Rive = /** @class */ (function () {
|
|
|
3899
3974
|
if (this.file) {
|
|
3900
3975
|
// Initialize and draw frame
|
|
3901
3976
|
this.initArtboard(artboardName, animationNames, stateMachineNames, autoplay);
|
|
3977
|
+
// Check for audio
|
|
3978
|
+
this.initializeAudio();
|
|
3902
3979
|
// Everything's set up, emit a load event
|
|
3903
3980
|
this.loaded = true;
|
|
3904
3981
|
this.eventManager.fire({
|
|
@@ -3976,9 +4053,9 @@ var Rive = /** @class */ (function () {
|
|
|
3976
4053
|
* @param time the time at which to render a frame
|
|
3977
4054
|
*/
|
|
3978
4055
|
Rive.prototype.draw = function (time, onSecond) {
|
|
3979
|
-
var before = performance.now();
|
|
3980
4056
|
// Clear the frameRequestId, as we're now rendering a fresh frame
|
|
3981
4057
|
this.frameRequestId = null;
|
|
4058
|
+
var before = performance.now();
|
|
3982
4059
|
// On the first pass, make sure lastTime has a valid value
|
|
3983
4060
|
if (!this.lastRenderTime) {
|
|
3984
4061
|
this.lastRenderTime = time;
|
|
@@ -4057,7 +4134,10 @@ var Rive = /** @class */ (function () {
|
|
|
4057
4134
|
renderer.save();
|
|
4058
4135
|
// Update the renderer alignment if necessary
|
|
4059
4136
|
this.alignRenderer();
|
|
4060
|
-
|
|
4137
|
+
// Do not draw on 0 canvas size
|
|
4138
|
+
if (!this._hasZeroSize) {
|
|
4139
|
+
this.artboard.draw(renderer);
|
|
4140
|
+
}
|
|
4061
4141
|
renderer.restore();
|
|
4062
4142
|
renderer.flush();
|
|
4063
4143
|
// Check for any animations that looped
|
|
@@ -4137,6 +4217,10 @@ var Rive = /** @class */ (function () {
|
|
|
4137
4217
|
this.stopRendering();
|
|
4138
4218
|
// Clean up any artboard, animation or state machine instances.
|
|
4139
4219
|
this.cleanupInstances();
|
|
4220
|
+
// Remove from observer
|
|
4221
|
+
if (this._observed !== null) {
|
|
4222
|
+
observers.remove(this._observed);
|
|
4223
|
+
}
|
|
4140
4224
|
// Delete the rive file
|
|
4141
4225
|
(_a = this.file) === null || _a === void 0 ? void 0 : _a.delete();
|
|
4142
4226
|
this.file = null;
|