@rive-app/webgl 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
|
@@ -4109,7 +4109,7 @@ Ie();
|
|
|
4109
4109
|
/* 2 */
|
|
4110
4110
|
/***/ ((module) => {
|
|
4111
4111
|
|
|
4112
|
-
module.exports = JSON.parse('{"name":"@rive-app/webgl","version":"2.15.
|
|
4112
|
+
module.exports = JSON.parse('{"name":"@rive-app/webgl","version":"2.15.1","description":"Rive\'s webgl 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.wasm","rive.js.map","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
|
|
4113
4113
|
|
|
4114
4114
|
/***/ }),
|
|
4115
4115
|
/* 3 */
|
|
@@ -5532,6 +5532,51 @@ var AudioManager = /** @class */ (function (_super) {
|
|
|
5532
5532
|
return AudioManager;
|
|
5533
5533
|
}(EventManager));
|
|
5534
5534
|
var audioManager = new AudioManager();
|
|
5535
|
+
/**
|
|
5536
|
+
* This class takes care of any observers that will be attached to an animation.
|
|
5537
|
+
* It should be treated as a singleton because observers are much more performant
|
|
5538
|
+
* when used for observing multiple elements by a single instance.
|
|
5539
|
+
*/
|
|
5540
|
+
var ObjectObservers = /** @class */ (function () {
|
|
5541
|
+
function ObjectObservers() {
|
|
5542
|
+
var _this = this;
|
|
5543
|
+
this._elementsMap = new Map();
|
|
5544
|
+
/**
|
|
5545
|
+
* Resize observers trigger both when the element changes its size and also when the
|
|
5546
|
+
* element is added or removed from the document.
|
|
5547
|
+
*/
|
|
5548
|
+
this._onObservedEntry = function (entry) {
|
|
5549
|
+
var observed = _this._elementsMap.get(entry.target);
|
|
5550
|
+
if (observed !== null) {
|
|
5551
|
+
observed.onResize(entry.target.clientWidth == 0 || entry.target.clientHeight == 0);
|
|
5552
|
+
}
|
|
5553
|
+
else {
|
|
5554
|
+
_this._resizeObserver.unobserve(entry.target);
|
|
5555
|
+
}
|
|
5556
|
+
};
|
|
5557
|
+
this._onObserved = function (entries) {
|
|
5558
|
+
entries.forEach(_this._onObservedEntry);
|
|
5559
|
+
};
|
|
5560
|
+
this._resizeObserver = new ResizeObserver(this._onObserved);
|
|
5561
|
+
}
|
|
5562
|
+
// Adds an observable element
|
|
5563
|
+
ObjectObservers.prototype.add = function (element, onResize) {
|
|
5564
|
+
var observed = {
|
|
5565
|
+
onResize: onResize,
|
|
5566
|
+
element: element,
|
|
5567
|
+
};
|
|
5568
|
+
this._elementsMap.set(element, observed);
|
|
5569
|
+
this._resizeObserver.observe(element);
|
|
5570
|
+
return observed;
|
|
5571
|
+
};
|
|
5572
|
+
// Removes an observable element
|
|
5573
|
+
ObjectObservers.prototype.remove = function (observed) {
|
|
5574
|
+
this._resizeObserver.unobserve(observed.element);
|
|
5575
|
+
this._elementsMap.delete(observed.element);
|
|
5576
|
+
};
|
|
5577
|
+
return ObjectObservers;
|
|
5578
|
+
}());
|
|
5579
|
+
var observers = new ObjectObservers();
|
|
5535
5580
|
var Rive = /** @class */ (function () {
|
|
5536
5581
|
function Rive(params) {
|
|
5537
5582
|
var _this = this;
|
|
@@ -5556,17 +5601,28 @@ var Rive = /** @class */ (function () {
|
|
|
5556
5601
|
this.enableRiveAssetCDN = true;
|
|
5557
5602
|
// Keep a local value of the set volume to update it asynchronously
|
|
5558
5603
|
this._volume = 1;
|
|
5604
|
+
// Whether the canvas element's size is 0
|
|
5605
|
+
this._hasZeroSize = false;
|
|
5559
5606
|
// Durations to generate a frame for the last second. Used for performance profiling.
|
|
5560
5607
|
this.durations = [];
|
|
5561
5608
|
this.frameTimes = [];
|
|
5562
5609
|
this.frameCount = 0;
|
|
5563
5610
|
this.isTouchScrollEnabled = false;
|
|
5611
|
+
this.onCanvasResize = function (hasZeroSize) {
|
|
5612
|
+
_this._hasZeroSize = hasZeroSize;
|
|
5613
|
+
if (!_this._layout.maxX || !_this._layout.maxY) {
|
|
5614
|
+
_this.resizeToCanvas();
|
|
5615
|
+
}
|
|
5616
|
+
};
|
|
5564
5617
|
/**
|
|
5565
5618
|
* Used be draw to track when a second of active rendering time has passed.
|
|
5566
5619
|
* Used for debugging purposes
|
|
5567
5620
|
*/
|
|
5568
5621
|
this.renderSecondTimer = 0;
|
|
5569
5622
|
this.canvas = params.canvas;
|
|
5623
|
+
if (params.canvas.constructor === HTMLCanvasElement) {
|
|
5624
|
+
this._observed = observers.add(this.canvas, this.onCanvasResize);
|
|
5625
|
+
}
|
|
5570
5626
|
this.src = params.src;
|
|
5571
5627
|
this.buffer = params.buffer;
|
|
5572
5628
|
this.layout = (_a = params.layout) !== null && _a !== void 0 ? _a : new Layout();
|
|
@@ -5619,14 +5675,6 @@ var Rive = /** @class */ (function () {
|
|
|
5619
5675
|
this.assetLoader = params.assetLoader;
|
|
5620
5676
|
// Hook up the task queue
|
|
5621
5677
|
this.taskQueue = new TaskQueueManager(this.eventManager);
|
|
5622
|
-
// Initialize audio
|
|
5623
|
-
if (audioManager.status == SystemAudioStatus.UNAVAILABLE) {
|
|
5624
|
-
audioManager.add({
|
|
5625
|
-
type: EventType.AudioStatusChange,
|
|
5626
|
-
callback: function () { return _this.onSystemAudioChanged(); },
|
|
5627
|
-
});
|
|
5628
|
-
audioManager.establishAudio();
|
|
5629
|
-
}
|
|
5630
5678
|
this.init({
|
|
5631
5679
|
src: this.src,
|
|
5632
5680
|
buffer: this.buffer,
|
|
@@ -5722,6 +5770,24 @@ var Rive = /** @class */ (function () {
|
|
|
5722
5770
|
this.eventCleanup();
|
|
5723
5771
|
}
|
|
5724
5772
|
};
|
|
5773
|
+
/**
|
|
5774
|
+
* If the instance has audio and the system audio is not ready
|
|
5775
|
+
* we hook the instance to the audio manager
|
|
5776
|
+
*/
|
|
5777
|
+
Rive.prototype.initializeAudio = function () {
|
|
5778
|
+
var _this = this;
|
|
5779
|
+
var _a;
|
|
5780
|
+
// Initialize audio if needed
|
|
5781
|
+
if (audioManager.status == SystemAudioStatus.UNAVAILABLE) {
|
|
5782
|
+
if ((_a = this.artboard) === null || _a === void 0 ? void 0 : _a.hasAudio) {
|
|
5783
|
+
audioManager.add({
|
|
5784
|
+
type: EventType.AudioStatusChange,
|
|
5785
|
+
callback: function () { return _this.onSystemAudioChanged(); },
|
|
5786
|
+
});
|
|
5787
|
+
audioManager.establishAudio();
|
|
5788
|
+
}
|
|
5789
|
+
}
|
|
5790
|
+
};
|
|
5725
5791
|
// Initializes runtime with Rive data and preps for playing
|
|
5726
5792
|
Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay) {
|
|
5727
5793
|
var _a;
|
|
@@ -5751,6 +5817,8 @@ var Rive = /** @class */ (function () {
|
|
|
5751
5817
|
if (this.file) {
|
|
5752
5818
|
// Initialize and draw frame
|
|
5753
5819
|
this.initArtboard(artboardName, animationNames, stateMachineNames, autoplay);
|
|
5820
|
+
// Check for audio
|
|
5821
|
+
this.initializeAudio();
|
|
5754
5822
|
// Everything's set up, emit a load event
|
|
5755
5823
|
this.loaded = true;
|
|
5756
5824
|
this.eventManager.fire({
|
|
@@ -5828,9 +5896,9 @@ var Rive = /** @class */ (function () {
|
|
|
5828
5896
|
* @param time the time at which to render a frame
|
|
5829
5897
|
*/
|
|
5830
5898
|
Rive.prototype.draw = function (time, onSecond) {
|
|
5831
|
-
var before = performance.now();
|
|
5832
5899
|
// Clear the frameRequestId, as we're now rendering a fresh frame
|
|
5833
5900
|
this.frameRequestId = null;
|
|
5901
|
+
var before = performance.now();
|
|
5834
5902
|
// On the first pass, make sure lastTime has a valid value
|
|
5835
5903
|
if (!this.lastRenderTime) {
|
|
5836
5904
|
this.lastRenderTime = time;
|
|
@@ -5909,7 +5977,10 @@ var Rive = /** @class */ (function () {
|
|
|
5909
5977
|
renderer.save();
|
|
5910
5978
|
// Update the renderer alignment if necessary
|
|
5911
5979
|
this.alignRenderer();
|
|
5912
|
-
|
|
5980
|
+
// Do not draw on 0 canvas size
|
|
5981
|
+
if (!this._hasZeroSize) {
|
|
5982
|
+
this.artboard.draw(renderer);
|
|
5983
|
+
}
|
|
5913
5984
|
renderer.restore();
|
|
5914
5985
|
renderer.flush();
|
|
5915
5986
|
// Check for any animations that looped
|
|
@@ -5989,6 +6060,10 @@ var Rive = /** @class */ (function () {
|
|
|
5989
6060
|
this.stopRendering();
|
|
5990
6061
|
// Clean up any artboard, animation or state machine instances.
|
|
5991
6062
|
this.cleanupInstances();
|
|
6063
|
+
// Remove from observer
|
|
6064
|
+
if (this._observed !== null) {
|
|
6065
|
+
observers.remove(this._observed);
|
|
6066
|
+
}
|
|
5992
6067
|
// Delete the rive file
|
|
5993
6068
|
(_a = this.file) === null || _a === void 0 ? void 0 : _a.delete();
|
|
5994
6069
|
this.file = null;
|