@rive-app/webgl2 2.33.3 → 2.34.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.33.3",
3
+ "version": "2.34.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
@@ -128,7 +128,9 @@ declare class Artboard extends BaseArtboard {
128
128
  declare class BindableArtboard extends BaseArtboard implements rc.FinalizableTarget {
129
129
  selfUnref: boolean;
130
130
  nativeArtboard: rc.BindableArtboard;
131
+ nativeViewModel: rc.ViewModelInstance | null;
131
132
  constructor(artboard: rc.BindableArtboard);
133
+ set viewModel(value: ViewModelInstance);
132
134
  destroy(): void;
133
135
  }
134
136
  /**
@@ -386,6 +388,7 @@ export declare class RiveFile implements rc.FinalizableTarget {
386
388
  getBindableArtboard(name: string): BindableArtboard | null;
387
389
  getDefaultBindableArtboard(): BindableArtboard | null;
388
390
  internalBindableArtboardFromArtboard(artboard: rc.Artboard): BindableArtboard | null;
391
+ viewModelByName(name: string): ViewModel | null;
389
392
  }
390
393
  export declare class Rive {
391
394
  private readonly canvas;
@@ -425,6 +428,9 @@ export declare class Rive {
425
428
  private _artboardHeight;
426
429
  private _devicePixelRatioUsed;
427
430
  private _hasZeroSize;
431
+ private _needsRedraw;
432
+ private _currentCanvasWidth;
433
+ private _currentCanvasHeight;
428
434
  private _audioEventListener;
429
435
  private _boundDraw;
430
436
  private _viewModelInstance;
@@ -460,6 +466,7 @@ export declare class Rive {
460
466
  private initData;
461
467
  private initArtboard;
462
468
  drawFrame(): void;
469
+ private _canvasSizeChanged;
463
470
  private lastRenderTime;
464
471
  private frameRequestId;
465
472
  /**
package/rive.js CHANGED
@@ -427,7 +427,7 @@ function Na(a, b) {
427
427
  return Ma(c, a, b);
428
428
  }));
429
429
  }
430
- var Oa, Pa, Ta = {570305:(a, b, c, d, e) => {
430
+ var Oa, Pa, Ta = {570833:(a, b, c, d, e) => {
431
431
  if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
432
432
  return 0;
433
433
  }
@@ -490,11 +490,11 @@ var Oa, Pa, Ta = {570305:(a, b, c, d, e) => {
490
490
  }
491
491
  window.h.Ea += 1;
492
492
  return 1;
493
- }, 572483:() => {
493
+ }, 573011:() => {
494
494
  "undefined" !== typeof window.h && (window.h.Xa.map(function(a) {
495
495
  document.removeEventListener(a, window.h.unlock, !0);
496
496
  }), --window.h.Ea, 0 === window.h.Ea && delete window.h);
497
- }, 572787:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 572891:() => {
497
+ }, 573315:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 573419:() => {
498
498
  try {
499
499
  var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
500
500
  a.close();
@@ -502,7 +502,7 @@ var Oa, Pa, Ta = {570305:(a, b, c, d, e) => {
502
502
  } catch (c) {
503
503
  return 0;
504
504
  }
505
- }, 573062:(a, b, c, d, e, f) => {
505
+ }, 573590:(a, b, c, d, e, f) => {
506
506
  if ("undefined" === typeof window.h) {
507
507
  return -1;
508
508
  }
@@ -548,7 +548,7 @@ var Oa, Pa, Ta = {570305:(a, b, c, d, e) => {
548
548
  a == window.h.I.Ca && g.Y.connect(g.K.destination);
549
549
  g.nb = f;
550
550
  return window.h.lc(g);
551
- }, 575939:a => window.h.ta(a).K.sampleRate, 576012:a => {
551
+ }, 576467:a => window.h.ta(a).K.sampleRate, 576540:a => {
552
552
  a = window.h.ta(a);
553
553
  void 0 !== a.Y && (a.Y.onaudioprocess = function() {
554
554
  }, a.Y.disconnect(), a.Y = void 0);
@@ -556,13 +556,13 @@ var Oa, Pa, Ta = {570305:(a, b, c, d, e) => {
556
556
  a.K.close();
557
557
  a.K = void 0;
558
558
  a.nb = void 0;
559
- }, 576412:a => {
559
+ }, 576940:a => {
560
560
  window.h.yb(a);
561
- }, 576462:a => {
561
+ }, 576990:a => {
562
562
  a = window.h.ta(a);
563
563
  a.K.resume();
564
564
  a.state = window.h.ia.ub;
565
- }, 576601:a => {
565
+ }, 577129:a => {
566
566
  a = window.h.ta(a);
567
567
  a.K.suspend();
568
568
  a.state = window.h.ia.stopped;
@@ -3546,7 +3546,7 @@ moduleRtn = ca;
3546
3546
  /* 2 */
3547
3547
  /***/ ((module) => {
3548
3548
 
3549
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl2","version":"2.33.3","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}}');
3549
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl2","version":"2.34.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}}');
3550
3550
 
3551
3551
  /***/ }),
3552
3552
  /* 3 */
@@ -4789,9 +4789,18 @@ var BindableArtboard = /** @class */ (function (_super) {
4789
4789
  _this.nativeArtboard = artboard;
4790
4790
  return _this;
4791
4791
  }
4792
+ Object.defineProperty(BindableArtboard.prototype, "viewModel", {
4793
+ set: function (value) {
4794
+ this.nativeViewModel = value.nativeInstance;
4795
+ },
4796
+ enumerable: false,
4797
+ configurable: true
4798
+ });
4792
4799
  BindableArtboard.prototype.destroy = function () {
4800
+ var _a;
4793
4801
  if (this.selfUnref) {
4794
4802
  this.nativeArtboard.unref();
4803
+ (_a = this.nativeViewModel) === null || _a === void 0 ? void 0 : _a.unref();
4795
4804
  }
4796
4805
  };
4797
4806
  return BindableArtboard;
@@ -5827,6 +5836,13 @@ var RiveFile = /** @class */ (function () {
5827
5836
  var nativeBindableArtboard = this.file.internalBindableArtboardFromArtboard(artboard);
5828
5837
  return this.createBindableArtboard(nativeBindableArtboard);
5829
5838
  };
5839
+ RiveFile.prototype.viewModelByName = function (name) {
5840
+ var viewModel = this.file.viewModelByName(name);
5841
+ if (viewModel !== null) {
5842
+ return new ViewModel(viewModel);
5843
+ }
5844
+ return null;
5845
+ };
5830
5846
  // Error message for missing source or buffer
5831
5847
  RiveFile.missingErrorMessage = "Rive source file or data buffer required";
5832
5848
  // Error message for file load error
@@ -5873,6 +5889,12 @@ var Rive = /** @class */ (function () {
5873
5889
  this._devicePixelRatioUsed = 1;
5874
5890
  // Whether the canvas element's size is 0
5875
5891
  this._hasZeroSize = false;
5892
+ // Whether a draw operation needs to be forced
5893
+ this._needsRedraw = false;
5894
+ // Canvas width and height. Values are lazily updated so they might
5895
+ // not be in sync with current canvas size.
5896
+ this._currentCanvasWidth = 0;
5897
+ this._currentCanvasHeight = 0;
5876
5898
  // Audio event listener
5877
5899
  this._audioEventListener = null;
5878
5900
  // draw method bound to the class
@@ -5907,6 +5929,8 @@ var Rive = /** @class */ (function () {
5907
5929
  if (params.canvas.constructor === HTMLCanvasElement) {
5908
5930
  this._observed = observers.add(this.canvas, this.onCanvasResize);
5909
5931
  }
5932
+ this._currentCanvasWidth = this.canvas.width;
5933
+ this._currentCanvasHeight = this.canvas.height;
5910
5934
  this.src = params.src;
5911
5935
  this.buffer = params.buffer;
5912
5936
  this.riveFile = params.riveFile;
@@ -6247,6 +6271,20 @@ var Rive = /** @class */ (function () {
6247
6271
  this.scheduleRendering();
6248
6272
  }
6249
6273
  };
6274
+ Rive.prototype._canvasSizeChanged = function () {
6275
+ var changed = false;
6276
+ if (this.canvas) {
6277
+ if (this.canvas.width !== this._currentCanvasWidth) {
6278
+ this._currentCanvasWidth = this.canvas.width;
6279
+ changed = true;
6280
+ }
6281
+ if (this.canvas.height !== this._currentCanvasHeight) {
6282
+ this._currentCanvasHeight = this.canvas.height;
6283
+ changed = true;
6284
+ }
6285
+ }
6286
+ return changed;
6287
+ };
6250
6288
  /**
6251
6289
  * Draw rendering loop; renders animation frames at the correct time interval.
6252
6290
  * @param time the time at which to render a frame
@@ -6335,7 +6373,9 @@ var Rive = /** @class */ (function () {
6335
6373
  if (!this._hasZeroSize) {
6336
6374
  // If there was no dirt on this frame, do not clear and draw
6337
6375
  if (this.drawOptimization == DrawOptimizationOptions.AlwaysDraw ||
6338
- this.artboard.didChange()) {
6376
+ this.artboard.didChange() ||
6377
+ this._needsRedraw ||
6378
+ this._canvasSizeChanged()) {
6339
6379
  // Canvas must be wiped to prevent artifacts
6340
6380
  renderer.clear();
6341
6381
  renderer.save();
@@ -6344,6 +6384,7 @@ var Rive = /** @class */ (function () {
6344
6384
  this.artboard.draw(renderer);
6345
6385
  renderer.restore();
6346
6386
  renderer.flush();
6387
+ this._needsRedraw = false;
6347
6388
  }
6348
6389
  }
6349
6390
  // Check for any animations that looped
@@ -6668,6 +6709,7 @@ var Rive = /** @class */ (function () {
6668
6709
  this.devicePixelRatioUsed = dpr;
6669
6710
  this.canvas.width = dpr * width;
6670
6711
  this.canvas.height = dpr * height;
6712
+ this._needsRedraw = true;
6671
6713
  this.resizeToCanvas();
6672
6714
  this.drawFrame();
6673
6715
  if (this.layout.fit === Fit.Layout) {
@@ -6964,7 +7006,8 @@ var Rive = /** @class */ (function () {
6964
7006
  * @returns true if no animations are playing or paused
6965
7007
  */
6966
7008
  get: function () {
6967
- return this.animator.isStopped;
7009
+ var _a, _b;
7010
+ return (_b = (_a = this.animator) === null || _a === void 0 ? void 0 : _a.isStopped) !== null && _b !== void 0 ? _b : true;
6968
7011
  },
6969
7012
  enumerable: false,
6970
7013
  configurable: true
@@ -7266,11 +7309,8 @@ var Rive = /** @class */ (function () {
7266
7309
  return null;
7267
7310
  };
7268
7311
  Rive.prototype.viewModelByName = function (name) {
7269
- var viewModel = this.file.viewModelByName(name);
7270
- if (viewModel !== null) {
7271
- return new ViewModel(viewModel);
7272
- }
7273
- return null;
7312
+ var _a;
7313
+ return (_a = this.riveFile) === null || _a === void 0 ? void 0 : _a.viewModelByName(name);
7274
7314
  };
7275
7315
  Rive.prototype.enums = function () {
7276
7316
  if (this._dataEnums === null) {
@@ -8113,7 +8153,7 @@ var ViewModelInstanceArtboard = /** @class */ (function (_super) {
8113
8153
  }
8114
8154
  Object.defineProperty(ViewModelInstanceArtboard.prototype, "value", {
8115
8155
  set: function (artboard) {
8116
- var _a;
8156
+ var _a, _b;
8117
8157
  var bindableArtboard;
8118
8158
  if (artboard.isBindableArtboard) {
8119
8159
  bindableArtboard = artboard;
@@ -8122,6 +8162,9 @@ var ViewModelInstanceArtboard = /** @class */ (function (_super) {
8122
8162
  bindableArtboard = artboard.file.internalBindableArtboardFromArtboard(artboard.nativeArtboard);
8123
8163
  }
8124
8164
  this._viewModelInstanceValue.value((_a = bindableArtboard === null || bindableArtboard === void 0 ? void 0 : bindableArtboard.nativeArtboard) !== null && _a !== void 0 ? _a : null);
8165
+ if (bindableArtboard === null || bindableArtboard === void 0 ? void 0 : bindableArtboard.nativeViewModel) {
8166
+ this._viewModelInstanceValue.viewModelInstance((_b = bindableArtboard === null || bindableArtboard === void 0 ? void 0 : bindableArtboard.nativeViewModel) !== null && _b !== void 0 ? _b : null);
8167
+ }
8125
8168
  },
8126
8169
  enumerable: false,
8127
8170
  configurable: true