@rive-app/webgl2 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 +105 -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.2","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,60 @@ var AudioManager = /** @class */ (function (_super) {
|
|
|
5037
5037
|
return AudioManager;
|
|
5038
5038
|
}(EventManager));
|
|
5039
5039
|
var audioManager = new AudioManager();
|
|
5040
|
+
var FakeResizeObserver = /** @class */ (function () {
|
|
5041
|
+
function FakeResizeObserver() {
|
|
5042
|
+
}
|
|
5043
|
+
FakeResizeObserver.prototype.observe = function () { };
|
|
5044
|
+
FakeResizeObserver.prototype.unobserve = function () { };
|
|
5045
|
+
FakeResizeObserver.prototype.disconnect = function () { };
|
|
5046
|
+
return FakeResizeObserver;
|
|
5047
|
+
}());
|
|
5048
|
+
var MyResizeObserver = globalThis.ResizeObserver || FakeResizeObserver;
|
|
5049
|
+
/**
|
|
5050
|
+
* This class takes care of any observers that will be attached to an animation.
|
|
5051
|
+
* It should be treated as a singleton because observers are much more performant
|
|
5052
|
+
* when used for observing multiple elements by a single instance.
|
|
5053
|
+
*/
|
|
5054
|
+
var ObjectObservers = /** @class */ (function () {
|
|
5055
|
+
function ObjectObservers() {
|
|
5056
|
+
var _this = this;
|
|
5057
|
+
this._elementsMap = new Map();
|
|
5058
|
+
/**
|
|
5059
|
+
* Resize observers trigger both when the element changes its size and also when the
|
|
5060
|
+
* element is added or removed from the document.
|
|
5061
|
+
*/
|
|
5062
|
+
this._onObservedEntry = function (entry) {
|
|
5063
|
+
var observed = _this._elementsMap.get(entry.target);
|
|
5064
|
+
if (observed !== null) {
|
|
5065
|
+
observed.onResize(entry.target.clientWidth == 0 || entry.target.clientHeight == 0);
|
|
5066
|
+
}
|
|
5067
|
+
else {
|
|
5068
|
+
_this._resizeObserver.unobserve(entry.target);
|
|
5069
|
+
}
|
|
5070
|
+
};
|
|
5071
|
+
this._onObserved = function (entries) {
|
|
5072
|
+
entries.forEach(_this._onObservedEntry);
|
|
5073
|
+
};
|
|
5074
|
+
this._resizeObserver = new MyResizeObserver(this._onObserved);
|
|
5075
|
+
}
|
|
5076
|
+
// Adds an observable element
|
|
5077
|
+
ObjectObservers.prototype.add = function (element, onResize) {
|
|
5078
|
+
var observed = {
|
|
5079
|
+
onResize: onResize,
|
|
5080
|
+
element: element,
|
|
5081
|
+
};
|
|
5082
|
+
this._elementsMap.set(element, observed);
|
|
5083
|
+
this._resizeObserver.observe(element);
|
|
5084
|
+
return observed;
|
|
5085
|
+
};
|
|
5086
|
+
// Removes an observable element
|
|
5087
|
+
ObjectObservers.prototype.remove = function (observed) {
|
|
5088
|
+
this._resizeObserver.unobserve(observed.element);
|
|
5089
|
+
this._elementsMap.delete(observed.element);
|
|
5090
|
+
};
|
|
5091
|
+
return ObjectObservers;
|
|
5092
|
+
}());
|
|
5093
|
+
var observers = new ObjectObservers();
|
|
5040
5094
|
var Rive = /** @class */ (function () {
|
|
5041
5095
|
function Rive(params) {
|
|
5042
5096
|
var _this = this;
|
|
@@ -5061,17 +5115,28 @@ var Rive = /** @class */ (function () {
|
|
|
5061
5115
|
this.enableRiveAssetCDN = true;
|
|
5062
5116
|
// Keep a local value of the set volume to update it asynchronously
|
|
5063
5117
|
this._volume = 1;
|
|
5118
|
+
// Whether the canvas element's size is 0
|
|
5119
|
+
this._hasZeroSize = false;
|
|
5064
5120
|
// Durations to generate a frame for the last second. Used for performance profiling.
|
|
5065
5121
|
this.durations = [];
|
|
5066
5122
|
this.frameTimes = [];
|
|
5067
5123
|
this.frameCount = 0;
|
|
5068
5124
|
this.isTouchScrollEnabled = false;
|
|
5125
|
+
this.onCanvasResize = function (hasZeroSize) {
|
|
5126
|
+
_this._hasZeroSize = hasZeroSize;
|
|
5127
|
+
if (!_this._layout.maxX || !_this._layout.maxY) {
|
|
5128
|
+
_this.resizeToCanvas();
|
|
5129
|
+
}
|
|
5130
|
+
};
|
|
5069
5131
|
/**
|
|
5070
5132
|
* Used be draw to track when a second of active rendering time has passed.
|
|
5071
5133
|
* Used for debugging purposes
|
|
5072
5134
|
*/
|
|
5073
5135
|
this.renderSecondTimer = 0;
|
|
5074
5136
|
this.canvas = params.canvas;
|
|
5137
|
+
if (params.canvas.constructor === HTMLCanvasElement) {
|
|
5138
|
+
this._observed = observers.add(this.canvas, this.onCanvasResize);
|
|
5139
|
+
}
|
|
5075
5140
|
this.src = params.src;
|
|
5076
5141
|
this.buffer = params.buffer;
|
|
5077
5142
|
this.layout = (_a = params.layout) !== null && _a !== void 0 ? _a : new Layout();
|
|
@@ -5124,14 +5189,6 @@ var Rive = /** @class */ (function () {
|
|
|
5124
5189
|
this.assetLoader = params.assetLoader;
|
|
5125
5190
|
// Hook up the task queue
|
|
5126
5191
|
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
5192
|
this.init({
|
|
5136
5193
|
src: this.src,
|
|
5137
5194
|
buffer: this.buffer,
|
|
@@ -5227,6 +5284,24 @@ var Rive = /** @class */ (function () {
|
|
|
5227
5284
|
this.eventCleanup();
|
|
5228
5285
|
}
|
|
5229
5286
|
};
|
|
5287
|
+
/**
|
|
5288
|
+
* If the instance has audio and the system audio is not ready
|
|
5289
|
+
* we hook the instance to the audio manager
|
|
5290
|
+
*/
|
|
5291
|
+
Rive.prototype.initializeAudio = function () {
|
|
5292
|
+
var _this = this;
|
|
5293
|
+
var _a;
|
|
5294
|
+
// Initialize audio if needed
|
|
5295
|
+
if (audioManager.status == SystemAudioStatus.UNAVAILABLE) {
|
|
5296
|
+
if ((_a = this.artboard) === null || _a === void 0 ? void 0 : _a.hasAudio) {
|
|
5297
|
+
audioManager.add({
|
|
5298
|
+
type: EventType.AudioStatusChange,
|
|
5299
|
+
callback: function () { return _this.onSystemAudioChanged(); },
|
|
5300
|
+
});
|
|
5301
|
+
audioManager.establishAudio();
|
|
5302
|
+
}
|
|
5303
|
+
}
|
|
5304
|
+
};
|
|
5230
5305
|
// Initializes runtime with Rive data and preps for playing
|
|
5231
5306
|
Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay) {
|
|
5232
5307
|
var _a;
|
|
@@ -5256,6 +5331,8 @@ var Rive = /** @class */ (function () {
|
|
|
5256
5331
|
if (this.file) {
|
|
5257
5332
|
// Initialize and draw frame
|
|
5258
5333
|
this.initArtboard(artboardName, animationNames, stateMachineNames, autoplay);
|
|
5334
|
+
// Check for audio
|
|
5335
|
+
this.initializeAudio();
|
|
5259
5336
|
// Everything's set up, emit a load event
|
|
5260
5337
|
this.loaded = true;
|
|
5261
5338
|
this.eventManager.fire({
|
|
@@ -5333,9 +5410,9 @@ var Rive = /** @class */ (function () {
|
|
|
5333
5410
|
* @param time the time at which to render a frame
|
|
5334
5411
|
*/
|
|
5335
5412
|
Rive.prototype.draw = function (time, onSecond) {
|
|
5336
|
-
var before = performance.now();
|
|
5337
5413
|
// Clear the frameRequestId, as we're now rendering a fresh frame
|
|
5338
5414
|
this.frameRequestId = null;
|
|
5415
|
+
var before = performance.now();
|
|
5339
5416
|
// On the first pass, make sure lastTime has a valid value
|
|
5340
5417
|
if (!this.lastRenderTime) {
|
|
5341
5418
|
this.lastRenderTime = time;
|
|
@@ -5414,7 +5491,10 @@ var Rive = /** @class */ (function () {
|
|
|
5414
5491
|
renderer.save();
|
|
5415
5492
|
// Update the renderer alignment if necessary
|
|
5416
5493
|
this.alignRenderer();
|
|
5417
|
-
|
|
5494
|
+
// Do not draw on 0 canvas size
|
|
5495
|
+
if (!this._hasZeroSize) {
|
|
5496
|
+
this.artboard.draw(renderer);
|
|
5497
|
+
}
|
|
5418
5498
|
renderer.restore();
|
|
5419
5499
|
renderer.flush();
|
|
5420
5500
|
// Check for any animations that looped
|
|
@@ -5494,6 +5574,10 @@ var Rive = /** @class */ (function () {
|
|
|
5494
5574
|
this.stopRendering();
|
|
5495
5575
|
// Clean up any artboard, animation or state machine instances.
|
|
5496
5576
|
this.cleanupInstances();
|
|
5577
|
+
// Remove from observer
|
|
5578
|
+
if (this._observed !== null) {
|
|
5579
|
+
observers.remove(this._observed);
|
|
5580
|
+
}
|
|
5497
5581
|
// Delete the rive file
|
|
5498
5582
|
(_a = this.file) === null || _a === void 0 ? void 0 : _a.delete();
|
|
5499
5583
|
this.file = null;
|