@rive-app/webgl 2.25.7 → 2.26.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/webgl",
3
- "version": "2.25.7",
3
+ "version": "2.26.1",
4
4
  "description": "Rive's webgl based web api.",
5
5
  "main": "rive.js",
6
6
  "homepage": "https://rive.app",
package/rive.d.ts CHANGED
@@ -307,6 +307,7 @@ export declare class RiveFile {
307
307
  private enableRiveAssetCDN;
308
308
  private eventManager;
309
309
  private referenceCount;
310
+ private destroyed;
310
311
  constructor(params: RiveFileParameters);
311
312
  private initData;
312
313
  init(): Promise<void>;
@@ -358,6 +359,7 @@ export declare class Rive {
358
359
  private animator;
359
360
  private assetLoader;
360
361
  private static readonly missingErrorMessage;
362
+ private static readonly cleanupErrorMessage;
361
363
  private shouldDisableRiveListeners;
362
364
  private automaticallyHandleEvents;
363
365
  private enableRiveAssetCDN;
@@ -367,6 +369,7 @@ export declare class Rive {
367
369
  private _devicePixelRatioUsed;
368
370
  private _hasZeroSize;
369
371
  private _audioEventListener;
372
+ private _boundDraw;
370
373
  durations: number[];
371
374
  frameTimes: number[];
372
375
  frameCount: number;
package/rive.js CHANGED
@@ -408,7 +408,7 @@ function Qa(a, b) {
408
408
  return Pa(c, a, b);
409
409
  }));
410
410
  }
411
- var Ra, Sa, Wa = {701388:(a, b, c, d, e) => {
411
+ var Ra, Sa, Wa = {702412:(a, b, c, d, e) => {
412
412
  if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
413
413
  return 0;
414
414
  }
@@ -471,9 +471,9 @@ var Ra, Sa, Wa = {701388:(a, b, c, d, e) => {
471
471
  }
472
472
  window.h.Ea += 1;
473
473
  return 1;
474
- }, 703566:() => {
474
+ }, 704590:() => {
475
475
  "undefined" !== typeof window.h && (--window.h.Ea, 0 === window.h.Ea && delete window.h);
476
- }, 703730:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 703834:() => {
476
+ }, 704754:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 704858:() => {
477
477
  try {
478
478
  var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
479
479
  a.close();
@@ -481,7 +481,7 @@ var Ra, Sa, Wa = {701388:(a, b, c, d, e) => {
481
481
  } catch (c) {
482
482
  return 0;
483
483
  }
484
- }, 704005:(a, b, c, d, e, f) => {
484
+ }, 705029:(a, b, c, d, e, f) => {
485
485
  if ("undefined" === typeof window.h) {
486
486
  return -1;
487
487
  }
@@ -527,7 +527,7 @@ var Ra, Sa, Wa = {701388:(a, b, c, d, e) => {
527
527
  a == window.h.H.Ca && g.X.connect(g.I.destination);
528
528
  g.lb = f;
529
529
  return window.h.nc(g);
530
- }, 706882:a => window.h.ta(a).I.sampleRate, 706955:a => {
530
+ }, 707906:a => window.h.ta(a).I.sampleRate, 707979:a => {
531
531
  a = window.h.ta(a);
532
532
  void 0 !== a.X && (a.X.onaudioprocess = function() {
533
533
  }, a.X.disconnect(), a.X = void 0);
@@ -535,13 +535,13 @@ var Ra, Sa, Wa = {701388:(a, b, c, d, e) => {
535
535
  a.I.close();
536
536
  a.I = void 0;
537
537
  a.lb = void 0;
538
- }, 707355:a => {
538
+ }, 708379:a => {
539
539
  window.h.xb(a);
540
- }, 707405:a => {
540
+ }, 708429:a => {
541
541
  a = window.h.ta(a);
542
542
  a.I.resume();
543
543
  a.state = window.h.ha.sb;
544
- }, 707544:a => {
544
+ }, 708568:a => {
545
545
  a = window.h.ta(a);
546
546
  a.I.suspend();
547
547
  a.state = window.h.ha.stopped;
@@ -4061,7 +4061,7 @@ Je();
4061
4061
  /* 2 */
4062
4062
  /***/ ((module) => {
4063
4063
 
4064
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl","version":"2.25.7","description":"Rive\'s webgl 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.wasm","rive_fallback.wasm","rive.js.map","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
4064
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl","version":"2.26.1","description":"Rive\'s webgl 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.wasm","rive_fallback.wasm","rive.js.map","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
4065
4065
 
4066
4066
  /***/ }),
4067
4067
  /* 3 */
@@ -4594,6 +4594,21 @@ var __generator = (undefined && undefined.__generator) || function (thisArg, bod
4594
4594
 
4595
4595
 
4596
4596
 
4597
+ var RiveError = /** @class */ (function (_super) {
4598
+ __extends(RiveError, _super);
4599
+ function RiveError() {
4600
+ var _this = _super !== null && _super.apply(this, arguments) || this;
4601
+ _this.isHandledError = true;
4602
+ return _this;
4603
+ }
4604
+ return RiveError;
4605
+ }(Error));
4606
+ // #regions helpers
4607
+ var resolveErrorMessage = function (error) {
4608
+ return error && error.isHandledError
4609
+ ? error.message
4610
+ : "Problem loading file; may be corrupt!";
4611
+ };
4597
4612
  // #region layout
4598
4613
  // Fit options for the canvas
4599
4614
  var Fit;
@@ -5680,6 +5695,7 @@ var RiveFile = /** @class */ (function () {
5680
5695
  // Allow the runtime to automatically load assets hosted in Rive's runtime.
5681
5696
  this.enableRiveAssetCDN = true;
5682
5697
  this.referenceCount = 0;
5698
+ this.destroyed = false;
5683
5699
  this.src = params.src;
5684
5700
  this.buffer = params.buffer;
5685
5701
  if (params.assetLoader)
@@ -5698,16 +5714,20 @@ var RiveFile = /** @class */ (function () {
5698
5714
  RiveFile.prototype.initData = function () {
5699
5715
  return __awaiter(this, void 0, void 0, function () {
5700
5716
  var _a, loader, _b;
5701
- return __generator(this, function (_c) {
5702
- switch (_c.label) {
5717
+ var _c;
5718
+ return __generator(this, function (_d) {
5719
+ switch (_d.label) {
5703
5720
  case 0:
5704
5721
  if (!this.src) return [3 /*break*/, 2];
5705
5722
  _a = this;
5706
5723
  return [4 /*yield*/, loadRiveFile(this.src)];
5707
5724
  case 1:
5708
- _a.buffer = _c.sent();
5709
- _c.label = 2;
5725
+ _a.buffer = _d.sent();
5726
+ _d.label = 2;
5710
5727
  case 2:
5728
+ if (this.destroyed) {
5729
+ return [2 /*return*/];
5730
+ }
5711
5731
  if (this.assetLoader) {
5712
5732
  loader = new this.runtime.CustomFileAssetLoader({
5713
5733
  loadContents: this.assetLoader,
@@ -5718,7 +5738,12 @@ var RiveFile = /** @class */ (function () {
5718
5738
  return [4 /*yield*/, this.runtime.load(new Uint8Array(this.buffer), loader, this.enableRiveAssetCDN)];
5719
5739
  case 3:
5720
5740
  // Load the Rive file
5721
- _b.file = _c.sent();
5741
+ _b.file = _d.sent();
5742
+ if (this.destroyed) {
5743
+ (_c = this.file) === null || _c === void 0 ? void 0 : _c.delete();
5744
+ this.file = null;
5745
+ return [2 /*return*/];
5746
+ }
5722
5747
  if (this.file !== null) {
5723
5748
  this.eventManager.fire({
5724
5749
  type: EventType.Load,
@@ -5751,6 +5776,9 @@ var RiveFile = /** @class */ (function () {
5751
5776
  return [4 /*yield*/, RuntimeLoader.awaitInstance()];
5752
5777
  case 1:
5753
5778
  _a.runtime = _b.sent();
5779
+ if (this.destroyed) {
5780
+ return [2 /*return*/];
5781
+ }
5754
5782
  return [4 /*yield*/, this.initData()];
5755
5783
  case 2:
5756
5784
  _b.sent();
@@ -5787,6 +5815,8 @@ var RiveFile = /** @class */ (function () {
5787
5815
  if (this.referenceCount <= 0) {
5788
5816
  this.removeAllRiveEventListeners();
5789
5817
  (_a = this.file) === null || _a === void 0 ? void 0 : _a.delete();
5818
+ this.file = null;
5819
+ this.destroyed = true;
5790
5820
  }
5791
5821
  };
5792
5822
  /**
@@ -5847,14 +5877,22 @@ var Rive = /** @class */ (function () {
5847
5877
  this._hasZeroSize = false;
5848
5878
  // Audio event listener
5849
5879
  this._audioEventListener = null;
5880
+ // draw method bound to the class
5881
+ this._boundDraw = null;
5850
5882
  // Durations to generate a frame for the last second. Used for performance profiling.
5851
5883
  this.durations = [];
5852
5884
  this.frameTimes = [];
5853
5885
  this.frameCount = 0;
5854
5886
  this.isTouchScrollEnabled = false;
5855
5887
  this.onCanvasResize = function (hasZeroSize) {
5888
+ var toggledDisplay = _this._hasZeroSize !== hasZeroSize;
5856
5889
  _this._hasZeroSize = hasZeroSize;
5857
- if (!_this._layout.maxX || !_this._layout.maxY) {
5890
+ if (!hasZeroSize) {
5891
+ if (toggledDisplay) {
5892
+ _this.resizeDrawingSurfaceToCanvas();
5893
+ }
5894
+ }
5895
+ else if (!_this._layout.maxX || !_this._layout.maxY) {
5858
5896
  _this.resizeToCanvas();
5859
5897
  }
5860
5898
  };
@@ -5863,6 +5901,7 @@ var Rive = /** @class */ (function () {
5863
5901
  * Used for debugging purposes
5864
5902
  */
5865
5903
  this.renderSecondTimer = 0;
5904
+ this._boundDraw = this.draw.bind(this);
5866
5905
  this.canvas = params.canvas;
5867
5906
  if (params.canvas.constructor === HTMLCanvasElement) {
5868
5907
  this._observed = observers.add(this.canvas, this.onCanvasResize);
@@ -6073,6 +6112,10 @@ var Rive = /** @class */ (function () {
6073
6112
  _b.sent();
6074
6113
  _b.label = 2;
6075
6114
  case 2:
6115
+ // Check for riveFile in case it has been cleaned up while initializing;
6116
+ if (!this.riveFile) {
6117
+ throw new RiveError(Rive.cleanupErrorMessage);
6118
+ }
6076
6119
  this.file = this.riveFile.getInstance();
6077
6120
  // Initialize and draw frame
6078
6121
  this.initArtboard(artboardName, animationNames, stateMachineNames, autoplay);
@@ -6094,7 +6137,7 @@ var Rive = /** @class */ (function () {
6094
6137
  return [2 /*return*/, Promise.resolve()];
6095
6138
  case 3:
6096
6139
  error_1 = _b.sent();
6097
- msg = "Problem loading file; may be corrupt!";
6140
+ msg = resolveErrorMessage(error_1);
6098
6141
  console.warn(msg);
6099
6142
  this.eventManager.fire({ type: EventType.LoadError, data: msg });
6100
6143
  return [2 /*return*/, Promise.reject(msg)];
@@ -6152,7 +6195,15 @@ var Rive = /** @class */ (function () {
6152
6195
  };
6153
6196
  // Draws the current artboard frame
6154
6197
  Rive.prototype.drawFrame = function () {
6155
- this.startRendering();
6198
+ var _a;
6199
+ if ((_a = document === null || document === void 0 ? void 0 : document.timeline) === null || _a === void 0 ? void 0 : _a.currentTime) {
6200
+ if (this.loaded && this.artboard && !this.frameRequestId) {
6201
+ this._boundDraw(document.timeline.currentTime);
6202
+ }
6203
+ }
6204
+ else {
6205
+ this.startRendering();
6206
+ }
6156
6207
  };
6157
6208
  /**
6158
6209
  * Draw rendering loop; renders animation frames at the correct time interval.
@@ -6562,8 +6613,8 @@ var Rive = /** @class */ (function () {
6562
6613
  this.devicePixelRatioUsed = dpr;
6563
6614
  this.canvas.width = dpr * width;
6564
6615
  this.canvas.height = dpr * height;
6565
- this.startRendering();
6566
6616
  this.resizeToCanvas();
6617
+ this.drawFrame();
6567
6618
  if (this.layout.fit === Fit.Layout) {
6568
6619
  var scaleFactor = this._layout.layoutScaleFactor;
6569
6620
  this.artboard.width = width / scaleFactor;
@@ -6952,10 +7003,10 @@ var Rive = /** @class */ (function () {
6952
7003
  Rive.prototype.startRendering = function () {
6953
7004
  if (this.loaded && this.artboard && !this.frameRequestId) {
6954
7005
  if (this.runtime.requestAnimationFrame) {
6955
- this.frameRequestId = this.runtime.requestAnimationFrame(this.draw.bind(this));
7006
+ this.frameRequestId = this.runtime.requestAnimationFrame(this._boundDraw);
6956
7007
  }
6957
7008
  else {
6958
- this.frameRequestId = requestAnimationFrame(this.draw.bind(this));
7009
+ this.frameRequestId = requestAnimationFrame(this._boundDraw);
6959
7010
  }
6960
7011
  }
6961
7012
  };
@@ -7123,6 +7174,8 @@ var Rive = /** @class */ (function () {
7123
7174
  });
7124
7175
  // Error message for missing source or buffer
7125
7176
  Rive.missingErrorMessage = "Rive source file or data buffer required";
7177
+ // Error message for removed rive file
7178
+ Rive.cleanupErrorMessage = "Attempt to use file after calling cleanup.";
7126
7179
  return Rive;
7127
7180
  }());
7128
7181