@rive-app/canvas 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/canvas",
3
- "version": "2.29.4",
3
+ "version": "2.30.1",
4
4
  "description": "Rive's canvas 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
@@ -747,7 +747,7 @@ function Xa(a, b) {
747
747
  return Wa(c, a, b);
748
748
  }));
749
749
  }
750
- var Ya, Za, cb = {456364:(a, b, c, d, e) => {
750
+ var Ya, Za, cb = {458140:(a, b, c, d, e) => {
751
751
  if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
752
752
  return 0;
753
753
  }
@@ -810,11 +810,11 @@ var Ya, Za, cb = {456364:(a, b, c, d, e) => {
810
810
  }
811
811
  window.h.Aa += 1;
812
812
  return 1;
813
- }, 458542:() => {
813
+ }, 460318:() => {
814
814
  "undefined" !== typeof window.h && (window.h.Ta.map(function(a) {
815
815
  document.removeEventListener(a, window.h.unlock, !0);
816
816
  }), --window.h.Aa, 0 === window.h.Aa && delete window.h);
817
- }, 458846:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 458950:() => {
817
+ }, 460622:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 460726:() => {
818
818
  try {
819
819
  var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
820
820
  a.close();
@@ -822,7 +822,7 @@ var Ya, Za, cb = {456364:(a, b, c, d, e) => {
822
822
  } catch (c) {
823
823
  return 0;
824
824
  }
825
- }, 459121:(a, b, c, d, e, f) => {
825
+ }, 460897:(a, b, c, d, e, f) => {
826
826
  if ("undefined" === typeof window.h) {
827
827
  return -1;
828
828
  }
@@ -868,7 +868,7 @@ var Ya, Za, cb = {456364:(a, b, c, d, e) => {
868
868
  a == window.h.I.ya && g.Z.connect(g.J.destination);
869
869
  g.qb = f;
870
870
  return window.h.yc(g);
871
- }, 461998:a => window.h.ra(a).J.sampleRate, 462071:a => {
871
+ }, 463774:a => window.h.ra(a).J.sampleRate, 463847:a => {
872
872
  a = window.h.ra(a);
873
873
  void 0 !== a.Z && (a.Z.onaudioprocess = function() {
874
874
  }, a.Z.disconnect(), a.Z = void 0);
@@ -876,13 +876,13 @@ var Ya, Za, cb = {456364:(a, b, c, d, e) => {
876
876
  a.J.close();
877
877
  a.J = void 0;
878
878
  a.qb = void 0;
879
- }, 462471:a => {
879
+ }, 464247:a => {
880
880
  window.h.Cb(a);
881
- }, 462521:a => {
881
+ }, 464297:a => {
882
882
  a = window.h.ra(a);
883
883
  a.J.resume();
884
884
  a.state = window.h.ga.yb;
885
- }, 462660:a => {
885
+ }, 464436:a => {
886
886
  a = window.h.ra(a);
887
887
  a.J.suspend();
888
888
  a.state = window.h.ga.stopped;
@@ -3370,7 +3370,7 @@ $d();
3370
3370
  /* 2 */
3371
3371
  /***/ ((module) => {
3372
3372
 
3373
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas","version":"2.29.4","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_fallback.wasm","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
3373
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas","version":"2.30.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_fallback.wasm","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
3374
3374
 
3375
3375
  /***/ }),
3376
3376
  /* 3 */
@@ -4012,18 +4012,18 @@ var FontAssetWrapper = /** @class */ (function (_super) {
4012
4012
  };
4013
4013
  return FontAssetWrapper;
4014
4014
  }(FileAssetWrapper));
4015
- var FakeFinalizationRegistry = /** @class */ (function (_super) {
4016
- __extends(FakeFinalizationRegistry, _super);
4017
- function FakeFinalizationRegistry(fn) {
4018
- return _super.call(this, fn) || this;
4015
+ var FakeFinalizationRegistry = /** @class */ (function () {
4016
+ function FakeFinalizationRegistry(_) {
4019
4017
  }
4020
4018
  FakeFinalizationRegistry.prototype.register = function (object) {
4021
4019
  object.selfUnref = true;
4022
4020
  };
4023
4021
  FakeFinalizationRegistry.prototype.unregister = function (_) { };
4024
4022
  return FakeFinalizationRegistry;
4025
- }(FinalizationRegistry));
4026
- var MyFinalizationRegistry = FinalizationRegistry || FakeFinalizationRegistry;
4023
+ }());
4024
+ var MyFinalizationRegistry = typeof FinalizationRegistry !== "undefined"
4025
+ ? FinalizationRegistry
4026
+ : FakeFinalizationRegistry;
4027
4027
  var finalizationRegistry = new MyFinalizationRegistry(function (ob) {
4028
4028
  ob.unref();
4029
4029
  });
@@ -5462,6 +5462,11 @@ var RiveFile = /** @class */ (function () {
5462
5462
  return this.file;
5463
5463
  }
5464
5464
  };
5465
+ RiveFile.prototype.destroyIfUnused = function () {
5466
+ if (this.referenceCount <= 0) {
5467
+ this.cleanup();
5468
+ }
5469
+ };
5465
5470
  // Error message for missing source or buffer
5466
5471
  RiveFile.missingErrorMessage = "Rive source file or data buffer required";
5467
5472
  // Error message for file load error
@@ -5745,28 +5750,31 @@ var Rive = /** @class */ (function () {
5745
5750
  // Returns true for successful initialization.
5746
5751
  Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay, autoBind) {
5747
5752
  return __awaiter(this, void 0, void 0, function () {
5748
- var error_2, msg;
5753
+ var riveFile, error_2, msg;
5749
5754
  var _a;
5750
5755
  return __generator(this, function (_b) {
5751
5756
  switch (_b.label) {
5752
5757
  case 0:
5753
5758
  _b.trys.push([0, 3, , 4]);
5754
5759
  if (!(this.riveFile == null)) return [3 /*break*/, 2];
5755
- this.riveFile = new RiveFile({
5760
+ riveFile = new RiveFile({
5756
5761
  src: this.src,
5757
5762
  buffer: this.buffer,
5758
5763
  enableRiveAssetCDN: this.enableRiveAssetCDN,
5759
5764
  assetLoader: this.assetLoader,
5760
5765
  });
5761
- return [4 /*yield*/, this.riveFile.init()];
5766
+ this.riveFile = riveFile;
5767
+ return [4 /*yield*/, riveFile.init()];
5762
5768
  case 1:
5763
5769
  _b.sent();
5764
- _b.label = 2;
5765
- case 2:
5766
- // Check for riveFile in case it has been cleaned up while initializing;
5767
- if (!this.riveFile) {
5770
+ if (this.destroyed) {
5771
+ // In the very unlikely scenario where the rive file created by this Rive is shared by
5772
+ // another rive file, we only want to destroy it if this file is the only owner.
5773
+ riveFile.destroyIfUnused();
5768
5774
  return [2 /*return*/, false];
5769
5775
  }
5776
+ _b.label = 2;
5777
+ case 2:
5770
5778
  this.file = this.riveFile.getInstance();
5771
5779
  // Initialize and draw frame
5772
5780
  this.initArtboard(artboardName, animationNames, stateMachineNames, autoplay, autoBind);