@rive-app/webgl2 2.30.0 → 2.30.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rive-app/webgl2",
3
- "version": "2.30.0",
3
+ "version": "2.30.2",
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
@@ -112,6 +112,10 @@ export declare enum RiveEventType {
112
112
  General = 128,
113
113
  OpenUrl = 131
114
114
  }
115
+ declare class Artboard {
116
+ nativeArtboard: rc.Artboard;
117
+ constructor(artboard: rc.Artboard);
118
+ }
115
119
  /**
116
120
  * Supported event types triggered in Rive
117
121
  */
@@ -339,6 +343,8 @@ export declare class RiveFile {
339
343
  */
340
344
  removeAllRiveEventListeners(type?: EventType): void;
341
345
  getInstance(): rc.File;
346
+ destroyIfUnused(): void;
347
+ getArtboard(name: string): Artboard | null;
342
348
  }
343
349
  export declare class Rive {
344
350
  private readonly canvas;
@@ -724,6 +730,7 @@ export declare class Rive {
724
730
  viewModelByName(name: string): ViewModel | null;
725
731
  enums(): DataEnum[];
726
732
  defaultViewModel(): ViewModel | null;
733
+ getArtboard(name: string): Artboard | null;
727
734
  }
728
735
  export declare class ViewModel {
729
736
  private _viewModel;
@@ -812,6 +819,12 @@ export declare class ViewModelInstance {
812
819
  * @param path - path to the image property
813
820
  */
814
821
  image(path: string): ViewModelInstanceAssetImage | null;
822
+ /**
823
+ * method to access an artboard property instance belonging
824
+ * to the view model instance or to a nested view model instance
825
+ * @param path - path to the image property
826
+ */
827
+ artboard(path: string): ViewModelInstanceArtboard | null;
815
828
  /**
816
829
  * method to access a view model property instance belonging
817
830
  * to the view model instance or to a nested view model instance
@@ -903,6 +916,11 @@ export declare class ViewModelInstanceAssetImage extends ViewModelInstanceValue
903
916
  set value(image: rc.Image | null);
904
917
  internalHandleCallback(callback: Function): void;
905
918
  }
919
+ export declare class ViewModelInstanceArtboard extends ViewModelInstanceValue {
920
+ constructor(instance: rc.ViewModelInstanceArtboard, root: ViewModelInstance);
921
+ set value(artboard: Artboard | null);
922
+ internalHandleCallback(callback: Function): void;
923
+ }
906
924
  /**
907
925
  * Contents of a state machine input
908
926
  */
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 = {526071:(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
+ }, 528249:() => {
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
+ }, 528553:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 528657:() => {
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
+ }, 528828:(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
+ }, 531705:a => window.h.va(a).J.sampleRate, 531778: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
+ }, 532178:a => {
575
575
  window.h.yb(a);
576
- }, 528772:a => {
576
+ }, 532228: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
+ }, 532367: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 = 523316;
3505
+ k.___stop_em_js = 526071;
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.30.0","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.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}}');
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
  });
@@ -4299,6 +4299,7 @@ __webpack_require__.r(__webpack_exports__);
4299
4299
  /* harmony export */ Testing: () => (/* binding */ Testing),
4300
4300
  /* harmony export */ ViewModel: () => (/* binding */ ViewModel),
4301
4301
  /* harmony export */ ViewModelInstance: () => (/* binding */ ViewModelInstance),
4302
+ /* harmony export */ ViewModelInstanceArtboard: () => (/* binding */ ViewModelInstanceArtboard),
4302
4303
  /* harmony export */ ViewModelInstanceAssetImage: () => (/* binding */ ViewModelInstanceAssetImage),
4303
4304
  /* harmony export */ ViewModelInstanceBoolean: () => (/* binding */ ViewModelInstanceBoolean),
4304
4305
  /* harmony export */ ViewModelInstanceColor: () => (/* binding */ ViewModelInstanceColor),
@@ -4681,6 +4682,12 @@ var RiveEventType;
4681
4682
  RiveEventType[RiveEventType["General"] = 128] = "General";
4682
4683
  RiveEventType[RiveEventType["OpenUrl"] = 131] = "OpenUrl";
4683
4684
  })(RiveEventType || (RiveEventType = {}));
4685
+ var Artboard = /** @class */ (function () {
4686
+ function Artboard(artboard) {
4687
+ this.nativeArtboard = artboard;
4688
+ }
4689
+ return Artboard;
4690
+ }());
4684
4691
  var StateMachine = /** @class */ (function () {
4685
4692
  /**
4686
4693
  * @constructor
@@ -5654,6 +5661,18 @@ var RiveFile = /** @class */ (function () {
5654
5661
  return this.file;
5655
5662
  }
5656
5663
  };
5664
+ RiveFile.prototype.destroyIfUnused = function () {
5665
+ if (this.referenceCount <= 0) {
5666
+ this.cleanup();
5667
+ }
5668
+ };
5669
+ RiveFile.prototype.getArtboard = function (name) {
5670
+ var nativeArtboard = this.file.artboardByName(name);
5671
+ if (nativeArtboard != null) {
5672
+ return new Artboard(nativeArtboard);
5673
+ }
5674
+ return null;
5675
+ };
5657
5676
  // Error message for missing source or buffer
5658
5677
  RiveFile.missingErrorMessage = "Rive source file or data buffer required";
5659
5678
  // Error message for file load error
@@ -5937,28 +5956,31 @@ var Rive = /** @class */ (function () {
5937
5956
  // Returns true for successful initialization.
5938
5957
  Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay, autoBind) {
5939
5958
  return __awaiter(this, void 0, void 0, function () {
5940
- var error_2, msg;
5959
+ var riveFile, error_2, msg;
5941
5960
  var _a;
5942
5961
  return __generator(this, function (_b) {
5943
5962
  switch (_b.label) {
5944
5963
  case 0:
5945
5964
  _b.trys.push([0, 3, , 4]);
5946
5965
  if (!(this.riveFile == null)) return [3 /*break*/, 2];
5947
- this.riveFile = new RiveFile({
5966
+ riveFile = new RiveFile({
5948
5967
  src: this.src,
5949
5968
  buffer: this.buffer,
5950
5969
  enableRiveAssetCDN: this.enableRiveAssetCDN,
5951
5970
  assetLoader: this.assetLoader,
5952
5971
  });
5953
- return [4 /*yield*/, this.riveFile.init()];
5972
+ this.riveFile = riveFile;
5973
+ return [4 /*yield*/, riveFile.init()];
5954
5974
  case 1:
5955
5975
  _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) {
5976
+ if (this.destroyed) {
5977
+ // In the very unlikely scenario where the rive file created by this Rive is shared by
5978
+ // another rive file, we only want to destroy it if this file is the only owner.
5979
+ riveFile.destroyIfUnused();
5960
5980
  return [2 /*return*/, false];
5961
5981
  }
5982
+ _b.label = 2;
5983
+ case 2:
5962
5984
  this.file = this.riveFile.getInstance();
5963
5985
  // Initialize and draw frame
5964
5986
  this.initArtboard(artboardName, animationNames, stateMachineNames, autoplay, autoBind);
@@ -7095,6 +7117,10 @@ var Rive = /** @class */ (function () {
7095
7117
  }
7096
7118
  return null;
7097
7119
  };
7120
+ Rive.prototype.getArtboard = function (name) {
7121
+ var _a, _b;
7122
+ return (_b = (_a = this.riveFile) === null || _a === void 0 ? void 0 : _a.getArtboard(name)) !== null && _b !== void 0 ? _b : null;
7123
+ };
7098
7124
  // Error message for missing source or buffer
7099
7125
  Rive.missingErrorMessage = "Rive source file or data buffer required";
7100
7126
  // Error message for removed rive file
@@ -7196,6 +7222,7 @@ var PropertyType;
7196
7222
  PropertyType["Enum"] = "enum";
7197
7223
  PropertyType["List"] = "list";
7198
7224
  PropertyType["Image"] = "image";
7225
+ PropertyType["Artboard"] = "artboard";
7199
7226
  })(PropertyType || (PropertyType = {}));
7200
7227
  var ViewModelInstance = /** @class */ (function () {
7201
7228
  function ViewModelInstance(runtimeInstance, parent) {
@@ -7322,7 +7349,7 @@ var ViewModelInstance = /** @class */ (function () {
7322
7349
  return null;
7323
7350
  };
7324
7351
  ViewModelInstance.prototype.propertyFromPathSegments = function (pathSegments, index, type) {
7325
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
7352
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
7326
7353
  if (index < pathSegments.length - 1) {
7327
7354
  var viewModelInstance = this.internalViewModelInstance(pathSegments[index]);
7328
7355
  if (viewModelInstance !== null) {
@@ -7382,6 +7409,12 @@ var ViewModelInstance = /** @class */ (function () {
7382
7409
  return new ViewModelInstanceAssetImage(instance, this);
7383
7410
  }
7384
7411
  break;
7412
+ case PropertyType.Artboard:
7413
+ instance = (_t = (_s = this._runtimeInstance) === null || _s === void 0 ? void 0 : _s.artboard(pathSegments[index])) !== null && _t !== void 0 ? _t : null;
7414
+ if (instance !== null) {
7415
+ return new ViewModelInstanceArtboard(instance, this);
7416
+ }
7417
+ break;
7385
7418
  }
7386
7419
  return null;
7387
7420
  };
@@ -7471,6 +7504,15 @@ var ViewModelInstance = /** @class */ (function () {
7471
7504
  var viewmodelInstanceValue = this.propertyFromPath(path, PropertyType.Image);
7472
7505
  return viewmodelInstanceValue;
7473
7506
  };
7507
+ /**
7508
+ * method to access an artboard property instance belonging
7509
+ * to the view model instance or to a nested view model instance
7510
+ * @param path - path to the image property
7511
+ */
7512
+ ViewModelInstance.prototype.artboard = function (path) {
7513
+ var viewmodelInstanceValue = this.propertyFromPath(path, PropertyType.Artboard);
7514
+ return viewmodelInstanceValue;
7515
+ };
7474
7516
  /**
7475
7517
  * method to access a view model property instance belonging
7476
7518
  * to the view model instance or to a nested view model instance
@@ -7855,6 +7897,24 @@ var ViewModelInstanceAssetImage = /** @class */ (function (_super) {
7855
7897
  return ViewModelInstanceAssetImage;
7856
7898
  }(ViewModelInstanceValue));
7857
7899
 
7900
+ var ViewModelInstanceArtboard = /** @class */ (function (_super) {
7901
+ __extends(ViewModelInstanceArtboard, _super);
7902
+ function ViewModelInstanceArtboard(instance, root) {
7903
+ return _super.call(this, instance, root) || this;
7904
+ }
7905
+ Object.defineProperty(ViewModelInstanceArtboard.prototype, "value", {
7906
+ set: function (artboard) {
7907
+ this._viewModelInstanceValue.value(artboard.nativeArtboard);
7908
+ },
7909
+ enumerable: false,
7910
+ configurable: true
7911
+ });
7912
+ ViewModelInstanceArtboard.prototype.internalHandleCallback = function (callback) {
7913
+ callback();
7914
+ };
7915
+ return ViewModelInstanceArtboard;
7916
+ }(ViewModelInstanceValue));
7917
+
7858
7918
  // Loads Rive data from a URI via fetch.
7859
7919
  var loadRiveFile = function (src) { return __awaiter(void 0, void 0, void 0, function () {
7860
7920
  var req, res, buffer;