@rive-app/webgl2 2.29.4 → 2.30.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rive-app/webgl2",
3
- "version": "2.29.4",
3
+ "version": "2.30.1",
4
4
  "description": "Rive's webgl2 based web api.",
5
5
  "main": "rive.js",
6
6
  "homepage": "https://rive.app",
package/rive.d.ts CHANGED
@@ -339,6 +339,7 @@ export declare class RiveFile {
339
339
  */
340
340
  removeAllRiveEventListeners(type?: EventType): void;
341
341
  getInstance(): rc.File;
342
+ destroyIfUnused(): void;
342
343
  }
343
344
  export declare class Rive {
344
345
  private readonly canvas;
package/rive.js CHANGED
@@ -442,7 +442,7 @@ function Oa(a, b) {
442
442
  return Na(c, a, b);
443
443
  }));
444
444
  }
445
- var Pa, Qa, Ua = {522615:(a, b, c, d, e) => {
445
+ var Pa, Qa, Ua = {524823:(a, b, c, d, e) => {
446
446
  if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
447
447
  return 0;
448
448
  }
@@ -505,11 +505,11 @@ var Pa, Qa, Ua = {522615:(a, b, c, d, e) => {
505
505
  }
506
506
  window.h.Da += 1;
507
507
  return 1;
508
- }, 524793:() => {
508
+ }, 527001:() => {
509
509
  "undefined" !== typeof window.h && (window.h.Va.map(function(a) {
510
510
  document.removeEventListener(a, window.h.unlock, !0);
511
511
  }), --window.h.Da, 0 === window.h.Da && delete window.h);
512
- }, 525097:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 525201:() => {
512
+ }, 527305:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 527409:() => {
513
513
  try {
514
514
  var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
515
515
  a.close();
@@ -517,7 +517,7 @@ var Pa, Qa, Ua = {522615:(a, b, c, d, e) => {
517
517
  } catch (c) {
518
518
  return 0;
519
519
  }
520
- }, 525372:(a, b, c, d, e, f) => {
520
+ }, 527580:(a, b, c, d, e, f) => {
521
521
  if ("undefined" === typeof window.h) {
522
522
  return -1;
523
523
  }
@@ -563,7 +563,7 @@ var Pa, Qa, Ua = {522615:(a, b, c, d, e) => {
563
563
  a == window.h.I.Ba && g.Z.connect(g.J.destination);
564
564
  g.mb = f;
565
565
  return window.h.oc(g);
566
- }, 528249:a => window.h.va(a).J.sampleRate, 528322:a => {
566
+ }, 530457:a => window.h.va(a).J.sampleRate, 530530:a => {
567
567
  a = window.h.va(a);
568
568
  void 0 !== a.Z && (a.Z.onaudioprocess = function() {
569
569
  }, a.Z.disconnect(), a.Z = void 0);
@@ -571,13 +571,13 @@ var Pa, Qa, Ua = {522615:(a, b, c, d, e) => {
571
571
  a.J.close();
572
572
  a.J = void 0;
573
573
  a.mb = void 0;
574
- }, 528722:a => {
574
+ }, 530930:a => {
575
575
  window.h.yb(a);
576
- }, 528772:a => {
576
+ }, 530980:a => {
577
577
  a = window.h.va(a);
578
578
  a.J.resume();
579
579
  a.state = window.h.ja.ub;
580
- }, 528911:a => {
580
+ }, 531119:a => {
581
581
  a = window.h.va(a);
582
582
  a.J.suspend();
583
583
  a.state = window.h.ja.stopped;
@@ -3501,8 +3501,8 @@ k.dynCall_viijii = (a, b, c, d, e, f, g) => (k.dynCall_viijii = C.dynCall_viijii
3501
3501
  k.dynCall_iiiiij = (a, b, c, d, e, f, g) => (k.dynCall_iiiiij = C.dynCall_iiiiij)(a, b, c, d, e, f, g);
3502
3502
  k.dynCall_iiiiijj = (a, b, c, d, e, f, g, l, p) => (k.dynCall_iiiiijj = C.dynCall_iiiiijj)(a, b, c, d, e, f, g, l, p);
3503
3503
  k.dynCall_iiiiiijj = (a, b, c, d, e, f, g, l, p, m) => (k.dynCall_iiiiiijj = C.dynCall_iiiiiijj)(a, b, c, d, e, f, g, l, p, m);
3504
- k.___start_em_js = 519860;
3505
- k.___stop_em_js = 522615;
3504
+ k.___start_em_js = 522068;
3505
+ k.___stop_em_js = 524823;
3506
3506
  var Zd;
3507
3507
  Ha = function $d() {
3508
3508
  Zd || ae();
@@ -3562,7 +3562,7 @@ ae();
3562
3562
  /* 2 */
3563
3563
  /***/ ((module) => {
3564
3564
 
3565
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl2","version":"2.29.4","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}}');
3565
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl2","version":"2.30.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}}');
3566
3566
 
3567
3567
  /***/ }),
3568
3568
  /* 3 */
@@ -4204,18 +4204,18 @@ var FontAssetWrapper = /** @class */ (function (_super) {
4204
4204
  };
4205
4205
  return FontAssetWrapper;
4206
4206
  }(FileAssetWrapper));
4207
- var FakeFinalizationRegistry = /** @class */ (function (_super) {
4208
- __extends(FakeFinalizationRegistry, _super);
4209
- function FakeFinalizationRegistry(fn) {
4210
- return _super.call(this, fn) || this;
4207
+ var FakeFinalizationRegistry = /** @class */ (function () {
4208
+ function FakeFinalizationRegistry(_) {
4211
4209
  }
4212
4210
  FakeFinalizationRegistry.prototype.register = function (object) {
4213
4211
  object.selfUnref = true;
4214
4212
  };
4215
4213
  FakeFinalizationRegistry.prototype.unregister = function (_) { };
4216
4214
  return FakeFinalizationRegistry;
4217
- }(FinalizationRegistry));
4218
- var MyFinalizationRegistry = FinalizationRegistry || FakeFinalizationRegistry;
4215
+ }());
4216
+ var MyFinalizationRegistry = typeof FinalizationRegistry !== "undefined"
4217
+ ? FinalizationRegistry
4218
+ : FakeFinalizationRegistry;
4219
4219
  var finalizationRegistry = new MyFinalizationRegistry(function (ob) {
4220
4220
  ob.unref();
4221
4221
  });
@@ -5654,6 +5654,11 @@ var RiveFile = /** @class */ (function () {
5654
5654
  return this.file;
5655
5655
  }
5656
5656
  };
5657
+ RiveFile.prototype.destroyIfUnused = function () {
5658
+ if (this.referenceCount <= 0) {
5659
+ this.cleanup();
5660
+ }
5661
+ };
5657
5662
  // Error message for missing source or buffer
5658
5663
  RiveFile.missingErrorMessage = "Rive source file or data buffer required";
5659
5664
  // Error message for file load error
@@ -5937,28 +5942,31 @@ var Rive = /** @class */ (function () {
5937
5942
  // Returns true for successful initialization.
5938
5943
  Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay, autoBind) {
5939
5944
  return __awaiter(this, void 0, void 0, function () {
5940
- var error_2, msg;
5945
+ var riveFile, error_2, msg;
5941
5946
  var _a;
5942
5947
  return __generator(this, function (_b) {
5943
5948
  switch (_b.label) {
5944
5949
  case 0:
5945
5950
  _b.trys.push([0, 3, , 4]);
5946
5951
  if (!(this.riveFile == null)) return [3 /*break*/, 2];
5947
- this.riveFile = new RiveFile({
5952
+ riveFile = new RiveFile({
5948
5953
  src: this.src,
5949
5954
  buffer: this.buffer,
5950
5955
  enableRiveAssetCDN: this.enableRiveAssetCDN,
5951
5956
  assetLoader: this.assetLoader,
5952
5957
  });
5953
- return [4 /*yield*/, this.riveFile.init()];
5958
+ this.riveFile = riveFile;
5959
+ return [4 /*yield*/, riveFile.init()];
5954
5960
  case 1:
5955
5961
  _b.sent();
5956
- _b.label = 2;
5957
- case 2:
5958
- // Check for riveFile in case it has been cleaned up while initializing;
5959
- if (!this.riveFile) {
5962
+ if (this.destroyed) {
5963
+ // In the very unlikely scenario where the rive file created by this Rive is shared by
5964
+ // another rive file, we only want to destroy it if this file is the only owner.
5965
+ riveFile.destroyIfUnused();
5960
5966
  return [2 /*return*/, false];
5961
5967
  }
5968
+ _b.label = 2;
5969
+ case 2:
5962
5970
  this.file = this.riveFile.getInstance();
5963
5971
  // Initialize and draw frame
5964
5972
  this.initArtboard(artboardName, animationNames, stateMachineNames, autoplay, autoBind);