@rive-app/canvas 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
|
@@ -3409,7 +3409,7 @@ Zd();
|
|
|
3409
3409
|
/* 2 */
|
|
3410
3410
|
/***/ ((module) => {
|
|
3411
3411
|
|
|
3412
|
-
module.exports = JSON.parse('{"name":"@rive-app/canvas","version":"2.15.
|
|
3412
|
+
module.exports = JSON.parse('{"name":"@rive-app/canvas","version":"2.15.1","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.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
|
|
3413
3413
|
|
|
3414
3414
|
/***/ }),
|
|
3415
3415
|
/* 3 */
|
|
@@ -4832,6 +4832,51 @@ var AudioManager = /** @class */ (function (_super) {
|
|
|
4832
4832
|
return AudioManager;
|
|
4833
4833
|
}(EventManager));
|
|
4834
4834
|
var audioManager = new AudioManager();
|
|
4835
|
+
/**
|
|
4836
|
+
* This class takes care of any observers that will be attached to an animation.
|
|
4837
|
+
* It should be treated as a singleton because observers are much more performant
|
|
4838
|
+
* when used for observing multiple elements by a single instance.
|
|
4839
|
+
*/
|
|
4840
|
+
var ObjectObservers = /** @class */ (function () {
|
|
4841
|
+
function ObjectObservers() {
|
|
4842
|
+
var _this = this;
|
|
4843
|
+
this._elementsMap = new Map();
|
|
4844
|
+
/**
|
|
4845
|
+
* Resize observers trigger both when the element changes its size and also when the
|
|
4846
|
+
* element is added or removed from the document.
|
|
4847
|
+
*/
|
|
4848
|
+
this._onObservedEntry = function (entry) {
|
|
4849
|
+
var observed = _this._elementsMap.get(entry.target);
|
|
4850
|
+
if (observed !== null) {
|
|
4851
|
+
observed.onResize(entry.target.clientWidth == 0 || entry.target.clientHeight == 0);
|
|
4852
|
+
}
|
|
4853
|
+
else {
|
|
4854
|
+
_this._resizeObserver.unobserve(entry.target);
|
|
4855
|
+
}
|
|
4856
|
+
};
|
|
4857
|
+
this._onObserved = function (entries) {
|
|
4858
|
+
entries.forEach(_this._onObservedEntry);
|
|
4859
|
+
};
|
|
4860
|
+
this._resizeObserver = new ResizeObserver(this._onObserved);
|
|
4861
|
+
}
|
|
4862
|
+
// Adds an observable element
|
|
4863
|
+
ObjectObservers.prototype.add = function (element, onResize) {
|
|
4864
|
+
var observed = {
|
|
4865
|
+
onResize: onResize,
|
|
4866
|
+
element: element,
|
|
4867
|
+
};
|
|
4868
|
+
this._elementsMap.set(element, observed);
|
|
4869
|
+
this._resizeObserver.observe(element);
|
|
4870
|
+
return observed;
|
|
4871
|
+
};
|
|
4872
|
+
// Removes an observable element
|
|
4873
|
+
ObjectObservers.prototype.remove = function (observed) {
|
|
4874
|
+
this._resizeObserver.unobserve(observed.element);
|
|
4875
|
+
this._elementsMap.delete(observed.element);
|
|
4876
|
+
};
|
|
4877
|
+
return ObjectObservers;
|
|
4878
|
+
}());
|
|
4879
|
+
var observers = new ObjectObservers();
|
|
4835
4880
|
var Rive = /** @class */ (function () {
|
|
4836
4881
|
function Rive(params) {
|
|
4837
4882
|
var _this = this;
|
|
@@ -4856,17 +4901,28 @@ var Rive = /** @class */ (function () {
|
|
|
4856
4901
|
this.enableRiveAssetCDN = true;
|
|
4857
4902
|
// Keep a local value of the set volume to update it asynchronously
|
|
4858
4903
|
this._volume = 1;
|
|
4904
|
+
// Whether the canvas element's size is 0
|
|
4905
|
+
this._hasZeroSize = false;
|
|
4859
4906
|
// Durations to generate a frame for the last second. Used for performance profiling.
|
|
4860
4907
|
this.durations = [];
|
|
4861
4908
|
this.frameTimes = [];
|
|
4862
4909
|
this.frameCount = 0;
|
|
4863
4910
|
this.isTouchScrollEnabled = false;
|
|
4911
|
+
this.onCanvasResize = function (hasZeroSize) {
|
|
4912
|
+
_this._hasZeroSize = hasZeroSize;
|
|
4913
|
+
if (!_this._layout.maxX || !_this._layout.maxY) {
|
|
4914
|
+
_this.resizeToCanvas();
|
|
4915
|
+
}
|
|
4916
|
+
};
|
|
4864
4917
|
/**
|
|
4865
4918
|
* Used be draw to track when a second of active rendering time has passed.
|
|
4866
4919
|
* Used for debugging purposes
|
|
4867
4920
|
*/
|
|
4868
4921
|
this.renderSecondTimer = 0;
|
|
4869
4922
|
this.canvas = params.canvas;
|
|
4923
|
+
if (params.canvas.constructor === HTMLCanvasElement) {
|
|
4924
|
+
this._observed = observers.add(this.canvas, this.onCanvasResize);
|
|
4925
|
+
}
|
|
4870
4926
|
this.src = params.src;
|
|
4871
4927
|
this.buffer = params.buffer;
|
|
4872
4928
|
this.layout = (_a = params.layout) !== null && _a !== void 0 ? _a : new Layout();
|
|
@@ -4919,14 +4975,6 @@ var Rive = /** @class */ (function () {
|
|
|
4919
4975
|
this.assetLoader = params.assetLoader;
|
|
4920
4976
|
// Hook up the task queue
|
|
4921
4977
|
this.taskQueue = new TaskQueueManager(this.eventManager);
|
|
4922
|
-
// Initialize audio
|
|
4923
|
-
if (audioManager.status == SystemAudioStatus.UNAVAILABLE) {
|
|
4924
|
-
audioManager.add({
|
|
4925
|
-
type: EventType.AudioStatusChange,
|
|
4926
|
-
callback: function () { return _this.onSystemAudioChanged(); },
|
|
4927
|
-
});
|
|
4928
|
-
audioManager.establishAudio();
|
|
4929
|
-
}
|
|
4930
4978
|
this.init({
|
|
4931
4979
|
src: this.src,
|
|
4932
4980
|
buffer: this.buffer,
|
|
@@ -5022,6 +5070,24 @@ var Rive = /** @class */ (function () {
|
|
|
5022
5070
|
this.eventCleanup();
|
|
5023
5071
|
}
|
|
5024
5072
|
};
|
|
5073
|
+
/**
|
|
5074
|
+
* If the instance has audio and the system audio is not ready
|
|
5075
|
+
* we hook the instance to the audio manager
|
|
5076
|
+
*/
|
|
5077
|
+
Rive.prototype.initializeAudio = function () {
|
|
5078
|
+
var _this = this;
|
|
5079
|
+
var _a;
|
|
5080
|
+
// Initialize audio if needed
|
|
5081
|
+
if (audioManager.status == SystemAudioStatus.UNAVAILABLE) {
|
|
5082
|
+
if ((_a = this.artboard) === null || _a === void 0 ? void 0 : _a.hasAudio) {
|
|
5083
|
+
audioManager.add({
|
|
5084
|
+
type: EventType.AudioStatusChange,
|
|
5085
|
+
callback: function () { return _this.onSystemAudioChanged(); },
|
|
5086
|
+
});
|
|
5087
|
+
audioManager.establishAudio();
|
|
5088
|
+
}
|
|
5089
|
+
}
|
|
5090
|
+
};
|
|
5025
5091
|
// Initializes runtime with Rive data and preps for playing
|
|
5026
5092
|
Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay) {
|
|
5027
5093
|
var _a;
|
|
@@ -5051,6 +5117,8 @@ var Rive = /** @class */ (function () {
|
|
|
5051
5117
|
if (this.file) {
|
|
5052
5118
|
// Initialize and draw frame
|
|
5053
5119
|
this.initArtboard(artboardName, animationNames, stateMachineNames, autoplay);
|
|
5120
|
+
// Check for audio
|
|
5121
|
+
this.initializeAudio();
|
|
5054
5122
|
// Everything's set up, emit a load event
|
|
5055
5123
|
this.loaded = true;
|
|
5056
5124
|
this.eventManager.fire({
|
|
@@ -5128,9 +5196,9 @@ var Rive = /** @class */ (function () {
|
|
|
5128
5196
|
* @param time the time at which to render a frame
|
|
5129
5197
|
*/
|
|
5130
5198
|
Rive.prototype.draw = function (time, onSecond) {
|
|
5131
|
-
var before = performance.now();
|
|
5132
5199
|
// Clear the frameRequestId, as we're now rendering a fresh frame
|
|
5133
5200
|
this.frameRequestId = null;
|
|
5201
|
+
var before = performance.now();
|
|
5134
5202
|
// On the first pass, make sure lastTime has a valid value
|
|
5135
5203
|
if (!this.lastRenderTime) {
|
|
5136
5204
|
this.lastRenderTime = time;
|
|
@@ -5209,7 +5277,10 @@ var Rive = /** @class */ (function () {
|
|
|
5209
5277
|
renderer.save();
|
|
5210
5278
|
// Update the renderer alignment if necessary
|
|
5211
5279
|
this.alignRenderer();
|
|
5212
|
-
|
|
5280
|
+
// Do not draw on 0 canvas size
|
|
5281
|
+
if (!this._hasZeroSize) {
|
|
5282
|
+
this.artboard.draw(renderer);
|
|
5283
|
+
}
|
|
5213
5284
|
renderer.restore();
|
|
5214
5285
|
renderer.flush();
|
|
5215
5286
|
// Check for any animations that looped
|
|
@@ -5289,6 +5360,10 @@ var Rive = /** @class */ (function () {
|
|
|
5289
5360
|
this.stopRendering();
|
|
5290
5361
|
// Clean up any artboard, animation or state machine instances.
|
|
5291
5362
|
this.cleanupInstances();
|
|
5363
|
+
// Remove from observer
|
|
5364
|
+
if (this._observed !== null) {
|
|
5365
|
+
observers.remove(this._observed);
|
|
5366
|
+
}
|
|
5292
5367
|
// Delete the rive file
|
|
5293
5368
|
(_a = this.file) === null || _a === void 0 ? void 0 : _a.delete();
|
|
5294
5369
|
this.file = null;
|