@rive-app/webgl2 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 +96 -21
- 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
|
@@ -415,7 +415,7 @@ function Pa(a, b) {
|
|
|
415
415
|
return Oa(c, a, b);
|
|
416
416
|
}));
|
|
417
417
|
}
|
|
418
|
-
var J, K, Ta = {
|
|
418
|
+
var J, K, Ta = {474256:(a, b, c, d, e) => {
|
|
419
419
|
if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
|
|
420
420
|
return 0;
|
|
421
421
|
}
|
|
@@ -478,9 +478,9 @@ var J, K, Ta = {474240:(a, b, c, d, e) => {
|
|
|
478
478
|
}
|
|
479
479
|
window.h.Da += 1;
|
|
480
480
|
return 1;
|
|
481
|
-
},
|
|
481
|
+
}, 476434:() => {
|
|
482
482
|
"undefined" !== typeof window.h && (--window.h.Da, 0 === window.h.Da && delete window.h);
|
|
483
|
-
},
|
|
483
|
+
}, 476598:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 476702:() => {
|
|
484
484
|
try {
|
|
485
485
|
var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
|
|
486
486
|
a.close();
|
|
@@ -488,7 +488,7 @@ var J, K, Ta = {474240:(a, b, c, d, e) => {
|
|
|
488
488
|
} catch (c) {
|
|
489
489
|
return 0;
|
|
490
490
|
}
|
|
491
|
-
},
|
|
491
|
+
}, 476873:(a, b, c, d, e, f) => {
|
|
492
492
|
if ("undefined" === typeof window.h) {
|
|
493
493
|
return -1;
|
|
494
494
|
}
|
|
@@ -534,7 +534,7 @@ var J, K, Ta = {474240:(a, b, c, d, e) => {
|
|
|
534
534
|
a == window.h.I.Ca && g.Z.connect(g.J.destination);
|
|
535
535
|
g.kb = f;
|
|
536
536
|
return window.h.tc(g);
|
|
537
|
-
},
|
|
537
|
+
}, 479750:a => window.h.wa(a).J.sampleRate, 479823:a => {
|
|
538
538
|
a = window.h.wa(a);
|
|
539
539
|
void 0 !== a.Z && (a.Z.onaudioprocess = function() {
|
|
540
540
|
}, a.Z.disconnect(), a.Z = void 0);
|
|
@@ -542,13 +542,13 @@ var J, K, Ta = {474240:(a, b, c, d, e) => {
|
|
|
542
542
|
a.J.close();
|
|
543
543
|
a.J = void 0;
|
|
544
544
|
a.kb = void 0;
|
|
545
|
-
},
|
|
545
|
+
}, 480223:a => {
|
|
546
546
|
window.h.xb(a);
|
|
547
|
-
},
|
|
547
|
+
}, 480273:a => {
|
|
548
548
|
a = window.h.wa(a);
|
|
549
549
|
a.J.resume();
|
|
550
550
|
a.state = window.h.ha.sb;
|
|
551
|
-
},
|
|
551
|
+
}, 480412:a => {
|
|
552
552
|
a = window.h.wa(a);
|
|
553
553
|
a.J.suspend();
|
|
554
554
|
a.state = window.h.ha.stopped;
|
|
@@ -3553,8 +3553,8 @@ n.dynCall_viijii = (a, b, c, d, e, f, g) => (n.dynCall_viijii = y.dynCall_viijii
|
|
|
3553
3553
|
n.dynCall_iiiiij = (a, b, c, d, e, f, g) => (n.dynCall_iiiiij = y.dynCall_iiiiij)(a, b, c, d, e, f, g);
|
|
3554
3554
|
n.dynCall_iiiiijj = (a, b, c, d, e, f, g, m, p) => (n.dynCall_iiiiijj = y.dynCall_iiiiijj)(a, b, c, d, e, f, g, m, p);
|
|
3555
3555
|
n.dynCall_iiiiiijj = (a, b, c, d, e, f, g, m, p, l) => (n.dynCall_iiiiiijj = y.dynCall_iiiiiijj)(a, b, c, d, e, f, g, m, p, l);
|
|
3556
|
-
n.___start_em_js =
|
|
3557
|
-
n.___stop_em_js =
|
|
3556
|
+
n.___start_em_js = 471632;
|
|
3557
|
+
n.___stop_em_js = 474256;
|
|
3558
3558
|
var $d;
|
|
3559
3559
|
Ia = function ae() {
|
|
3560
3560
|
$d || be();
|
|
@@ -3614,7 +3614,7 @@ be();
|
|
|
3614
3614
|
/* 2 */
|
|
3615
3615
|
/***/ ((module) => {
|
|
3616
3616
|
|
|
3617
|
-
module.exports = JSON.parse('{"name":"@rive-app/webgl2","version":"2.15.
|
|
3617
|
+
module.exports = JSON.parse('{"name":"@rive-app/webgl2","version":"2.15.1","description":"Rive\'s webgl2 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)","Chris Dalton <chris@rive.app> (https://rive.app)"],"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}}');
|
|
3618
3618
|
|
|
3619
3619
|
/***/ }),
|
|
3620
3620
|
/* 3 */
|
|
@@ -5037,6 +5037,51 @@ var AudioManager = /** @class */ (function (_super) {
|
|
|
5037
5037
|
return AudioManager;
|
|
5038
5038
|
}(EventManager));
|
|
5039
5039
|
var audioManager = new AudioManager();
|
|
5040
|
+
/**
|
|
5041
|
+
* This class takes care of any observers that will be attached to an animation.
|
|
5042
|
+
* It should be treated as a singleton because observers are much more performant
|
|
5043
|
+
* when used for observing multiple elements by a single instance.
|
|
5044
|
+
*/
|
|
5045
|
+
var ObjectObservers = /** @class */ (function () {
|
|
5046
|
+
function ObjectObservers() {
|
|
5047
|
+
var _this = this;
|
|
5048
|
+
this._elementsMap = new Map();
|
|
5049
|
+
/**
|
|
5050
|
+
* Resize observers trigger both when the element changes its size and also when the
|
|
5051
|
+
* element is added or removed from the document.
|
|
5052
|
+
*/
|
|
5053
|
+
this._onObservedEntry = function (entry) {
|
|
5054
|
+
var observed = _this._elementsMap.get(entry.target);
|
|
5055
|
+
if (observed !== null) {
|
|
5056
|
+
observed.onResize(entry.target.clientWidth == 0 || entry.target.clientHeight == 0);
|
|
5057
|
+
}
|
|
5058
|
+
else {
|
|
5059
|
+
_this._resizeObserver.unobserve(entry.target);
|
|
5060
|
+
}
|
|
5061
|
+
};
|
|
5062
|
+
this._onObserved = function (entries) {
|
|
5063
|
+
entries.forEach(_this._onObservedEntry);
|
|
5064
|
+
};
|
|
5065
|
+
this._resizeObserver = new ResizeObserver(this._onObserved);
|
|
5066
|
+
}
|
|
5067
|
+
// Adds an observable element
|
|
5068
|
+
ObjectObservers.prototype.add = function (element, onResize) {
|
|
5069
|
+
var observed = {
|
|
5070
|
+
onResize: onResize,
|
|
5071
|
+
element: element,
|
|
5072
|
+
};
|
|
5073
|
+
this._elementsMap.set(element, observed);
|
|
5074
|
+
this._resizeObserver.observe(element);
|
|
5075
|
+
return observed;
|
|
5076
|
+
};
|
|
5077
|
+
// Removes an observable element
|
|
5078
|
+
ObjectObservers.prototype.remove = function (observed) {
|
|
5079
|
+
this._resizeObserver.unobserve(observed.element);
|
|
5080
|
+
this._elementsMap.delete(observed.element);
|
|
5081
|
+
};
|
|
5082
|
+
return ObjectObservers;
|
|
5083
|
+
}());
|
|
5084
|
+
var observers = new ObjectObservers();
|
|
5040
5085
|
var Rive = /** @class */ (function () {
|
|
5041
5086
|
function Rive(params) {
|
|
5042
5087
|
var _this = this;
|
|
@@ -5061,17 +5106,28 @@ var Rive = /** @class */ (function () {
|
|
|
5061
5106
|
this.enableRiveAssetCDN = true;
|
|
5062
5107
|
// Keep a local value of the set volume to update it asynchronously
|
|
5063
5108
|
this._volume = 1;
|
|
5109
|
+
// Whether the canvas element's size is 0
|
|
5110
|
+
this._hasZeroSize = false;
|
|
5064
5111
|
// Durations to generate a frame for the last second. Used for performance profiling.
|
|
5065
5112
|
this.durations = [];
|
|
5066
5113
|
this.frameTimes = [];
|
|
5067
5114
|
this.frameCount = 0;
|
|
5068
5115
|
this.isTouchScrollEnabled = false;
|
|
5116
|
+
this.onCanvasResize = function (hasZeroSize) {
|
|
5117
|
+
_this._hasZeroSize = hasZeroSize;
|
|
5118
|
+
if (!_this._layout.maxX || !_this._layout.maxY) {
|
|
5119
|
+
_this.resizeToCanvas();
|
|
5120
|
+
}
|
|
5121
|
+
};
|
|
5069
5122
|
/**
|
|
5070
5123
|
* Used be draw to track when a second of active rendering time has passed.
|
|
5071
5124
|
* Used for debugging purposes
|
|
5072
5125
|
*/
|
|
5073
5126
|
this.renderSecondTimer = 0;
|
|
5074
5127
|
this.canvas = params.canvas;
|
|
5128
|
+
if (params.canvas.constructor === HTMLCanvasElement) {
|
|
5129
|
+
this._observed = observers.add(this.canvas, this.onCanvasResize);
|
|
5130
|
+
}
|
|
5075
5131
|
this.src = params.src;
|
|
5076
5132
|
this.buffer = params.buffer;
|
|
5077
5133
|
this.layout = (_a = params.layout) !== null && _a !== void 0 ? _a : new Layout();
|
|
@@ -5124,14 +5180,6 @@ var Rive = /** @class */ (function () {
|
|
|
5124
5180
|
this.assetLoader = params.assetLoader;
|
|
5125
5181
|
// Hook up the task queue
|
|
5126
5182
|
this.taskQueue = new TaskQueueManager(this.eventManager);
|
|
5127
|
-
// Initialize audio
|
|
5128
|
-
if (audioManager.status == SystemAudioStatus.UNAVAILABLE) {
|
|
5129
|
-
audioManager.add({
|
|
5130
|
-
type: EventType.AudioStatusChange,
|
|
5131
|
-
callback: function () { return _this.onSystemAudioChanged(); },
|
|
5132
|
-
});
|
|
5133
|
-
audioManager.establishAudio();
|
|
5134
|
-
}
|
|
5135
5183
|
this.init({
|
|
5136
5184
|
src: this.src,
|
|
5137
5185
|
buffer: this.buffer,
|
|
@@ -5227,6 +5275,24 @@ var Rive = /** @class */ (function () {
|
|
|
5227
5275
|
this.eventCleanup();
|
|
5228
5276
|
}
|
|
5229
5277
|
};
|
|
5278
|
+
/**
|
|
5279
|
+
* If the instance has audio and the system audio is not ready
|
|
5280
|
+
* we hook the instance to the audio manager
|
|
5281
|
+
*/
|
|
5282
|
+
Rive.prototype.initializeAudio = function () {
|
|
5283
|
+
var _this = this;
|
|
5284
|
+
var _a;
|
|
5285
|
+
// Initialize audio if needed
|
|
5286
|
+
if (audioManager.status == SystemAudioStatus.UNAVAILABLE) {
|
|
5287
|
+
if ((_a = this.artboard) === null || _a === void 0 ? void 0 : _a.hasAudio) {
|
|
5288
|
+
audioManager.add({
|
|
5289
|
+
type: EventType.AudioStatusChange,
|
|
5290
|
+
callback: function () { return _this.onSystemAudioChanged(); },
|
|
5291
|
+
});
|
|
5292
|
+
audioManager.establishAudio();
|
|
5293
|
+
}
|
|
5294
|
+
}
|
|
5295
|
+
};
|
|
5230
5296
|
// Initializes runtime with Rive data and preps for playing
|
|
5231
5297
|
Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay) {
|
|
5232
5298
|
var _a;
|
|
@@ -5256,6 +5322,8 @@ var Rive = /** @class */ (function () {
|
|
|
5256
5322
|
if (this.file) {
|
|
5257
5323
|
// Initialize and draw frame
|
|
5258
5324
|
this.initArtboard(artboardName, animationNames, stateMachineNames, autoplay);
|
|
5325
|
+
// Check for audio
|
|
5326
|
+
this.initializeAudio();
|
|
5259
5327
|
// Everything's set up, emit a load event
|
|
5260
5328
|
this.loaded = true;
|
|
5261
5329
|
this.eventManager.fire({
|
|
@@ -5333,9 +5401,9 @@ var Rive = /** @class */ (function () {
|
|
|
5333
5401
|
* @param time the time at which to render a frame
|
|
5334
5402
|
*/
|
|
5335
5403
|
Rive.prototype.draw = function (time, onSecond) {
|
|
5336
|
-
var before = performance.now();
|
|
5337
5404
|
// Clear the frameRequestId, as we're now rendering a fresh frame
|
|
5338
5405
|
this.frameRequestId = null;
|
|
5406
|
+
var before = performance.now();
|
|
5339
5407
|
// On the first pass, make sure lastTime has a valid value
|
|
5340
5408
|
if (!this.lastRenderTime) {
|
|
5341
5409
|
this.lastRenderTime = time;
|
|
@@ -5414,7 +5482,10 @@ var Rive = /** @class */ (function () {
|
|
|
5414
5482
|
renderer.save();
|
|
5415
5483
|
// Update the renderer alignment if necessary
|
|
5416
5484
|
this.alignRenderer();
|
|
5417
|
-
|
|
5485
|
+
// Do not draw on 0 canvas size
|
|
5486
|
+
if (!this._hasZeroSize) {
|
|
5487
|
+
this.artboard.draw(renderer);
|
|
5488
|
+
}
|
|
5418
5489
|
renderer.restore();
|
|
5419
5490
|
renderer.flush();
|
|
5420
5491
|
// Check for any animations that looped
|
|
@@ -5494,6 +5565,10 @@ var Rive = /** @class */ (function () {
|
|
|
5494
5565
|
this.stopRendering();
|
|
5495
5566
|
// Clean up any artboard, animation or state machine instances.
|
|
5496
5567
|
this.cleanupInstances();
|
|
5568
|
+
// Remove from observer
|
|
5569
|
+
if (this._observed !== null) {
|
|
5570
|
+
observers.remove(this._observed);
|
|
5571
|
+
}
|
|
5497
5572
|
// Delete the rive file
|
|
5498
5573
|
(_a = this.file) === null || _a === void 0 ? void 0 : _a.delete();
|
|
5499
5574
|
this.file = null;
|