@rive-app/webgl 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/webgl",
3
- "version": "2.30.0",
3
+ "version": "2.30.2",
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
@@ -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
@@ -408,7 +408,7 @@ function Qa(a, b) {
408
408
  return Pa(c, a, b);
409
409
  }));
410
410
  }
411
- var Ra, Sa, Wa = {711388:(a, b, c, d, e) => {
411
+ var Ra, Sa, Wa = {713580:(a, b, c, d, e) => {
412
412
  if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
413
413
  return 0;
414
414
  }
@@ -471,11 +471,11 @@ var Ra, Sa, Wa = {711388:(a, b, c, d, e) => {
471
471
  }
472
472
  window.h.Ea += 1;
473
473
  return 1;
474
- }, 713566:() => {
474
+ }, 715758:() => {
475
475
  "undefined" !== typeof window.h && (window.h.Ta.map(function(a) {
476
476
  document.removeEventListener(a, window.h.unlock, !0);
477
477
  }), --window.h.Ea, 0 === window.h.Ea && delete window.h);
478
- }, 713870:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 713974:() => {
478
+ }, 716062:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 716166:() => {
479
479
  try {
480
480
  var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
481
481
  a.close();
@@ -483,7 +483,7 @@ var Ra, Sa, Wa = {711388:(a, b, c, d, e) => {
483
483
  } catch (c) {
484
484
  return 0;
485
485
  }
486
- }, 714145:(a, b, c, d, e, f) => {
486
+ }, 716337:(a, b, c, d, e, f) => {
487
487
  if ("undefined" === typeof window.h) {
488
488
  return -1;
489
489
  }
@@ -529,7 +529,7 @@ var Ra, Sa, Wa = {711388:(a, b, c, d, e) => {
529
529
  a == window.h.H.Ca && g.X.connect(g.I.destination);
530
530
  g.mb = f;
531
531
  return window.h.nc(g);
532
- }, 717022:a => window.h.ta(a).I.sampleRate, 717095:a => {
532
+ }, 719214:a => window.h.ta(a).I.sampleRate, 719287:a => {
533
533
  a = window.h.ta(a);
534
534
  void 0 !== a.X && (a.X.onaudioprocess = function() {
535
535
  }, a.X.disconnect(), a.X = void 0);
@@ -537,13 +537,13 @@ var Ra, Sa, Wa = {711388:(a, b, c, d, e) => {
537
537
  a.I.close();
538
538
  a.I = void 0;
539
539
  a.mb = void 0;
540
- }, 717495:a => {
540
+ }, 719687:a => {
541
541
  window.h.xb(a);
542
- }, 717545:a => {
542
+ }, 719737:a => {
543
543
  a = window.h.ta(a);
544
544
  a.I.resume();
545
545
  a.state = window.h.ha.tb;
546
- }, 717684:a => {
546
+ }, 719876:a => {
547
547
  a = window.h.ta(a);
548
548
  a.I.suspend();
549
549
  a.state = window.h.ha.stopped;
@@ -4065,7 +4065,7 @@ Je();
4065
4065
  /* 2 */
4066
4066
  /***/ ((module) => {
4067
4067
 
4068
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl","version":"2.30.0","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}}');
4068
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl","version":"2.30.2","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}}');
4069
4069
 
4070
4070
  /***/ }),
4071
4071
  /* 3 */
@@ -4707,18 +4707,18 @@ var FontAssetWrapper = /** @class */ (function (_super) {
4707
4707
  };
4708
4708
  return FontAssetWrapper;
4709
4709
  }(FileAssetWrapper));
4710
- var FakeFinalizationRegistry = /** @class */ (function (_super) {
4711
- __extends(FakeFinalizationRegistry, _super);
4712
- function FakeFinalizationRegistry(fn) {
4713
- return _super.call(this, fn) || this;
4710
+ var FakeFinalizationRegistry = /** @class */ (function () {
4711
+ function FakeFinalizationRegistry(_) {
4714
4712
  }
4715
4713
  FakeFinalizationRegistry.prototype.register = function (object) {
4716
4714
  object.selfUnref = true;
4717
4715
  };
4718
4716
  FakeFinalizationRegistry.prototype.unregister = function (_) { };
4719
4717
  return FakeFinalizationRegistry;
4720
- }(FinalizationRegistry));
4721
- var MyFinalizationRegistry = FinalizationRegistry || FakeFinalizationRegistry;
4718
+ }());
4719
+ var MyFinalizationRegistry = typeof FinalizationRegistry !== "undefined"
4720
+ ? FinalizationRegistry
4721
+ : FakeFinalizationRegistry;
4722
4722
  var finalizationRegistry = new MyFinalizationRegistry(function (ob) {
4723
4723
  ob.unref();
4724
4724
  });
@@ -4802,6 +4802,7 @@ __webpack_require__.r(__webpack_exports__);
4802
4802
  /* harmony export */ Testing: () => (/* binding */ Testing),
4803
4803
  /* harmony export */ ViewModel: () => (/* binding */ ViewModel),
4804
4804
  /* harmony export */ ViewModelInstance: () => (/* binding */ ViewModelInstance),
4805
+ /* harmony export */ ViewModelInstanceArtboard: () => (/* binding */ ViewModelInstanceArtboard),
4805
4806
  /* harmony export */ ViewModelInstanceAssetImage: () => (/* binding */ ViewModelInstanceAssetImage),
4806
4807
  /* harmony export */ ViewModelInstanceBoolean: () => (/* binding */ ViewModelInstanceBoolean),
4807
4808
  /* harmony export */ ViewModelInstanceColor: () => (/* binding */ ViewModelInstanceColor),
@@ -5184,6 +5185,12 @@ var RiveEventType;
5184
5185
  RiveEventType[RiveEventType["General"] = 128] = "General";
5185
5186
  RiveEventType[RiveEventType["OpenUrl"] = 131] = "OpenUrl";
5186
5187
  })(RiveEventType || (RiveEventType = {}));
5188
+ var Artboard = /** @class */ (function () {
5189
+ function Artboard(artboard) {
5190
+ this.nativeArtboard = artboard;
5191
+ }
5192
+ return Artboard;
5193
+ }());
5187
5194
  var StateMachine = /** @class */ (function () {
5188
5195
  /**
5189
5196
  * @constructor
@@ -6157,6 +6164,18 @@ var RiveFile = /** @class */ (function () {
6157
6164
  return this.file;
6158
6165
  }
6159
6166
  };
6167
+ RiveFile.prototype.destroyIfUnused = function () {
6168
+ if (this.referenceCount <= 0) {
6169
+ this.cleanup();
6170
+ }
6171
+ };
6172
+ RiveFile.prototype.getArtboard = function (name) {
6173
+ var nativeArtboard = this.file.artboardByName(name);
6174
+ if (nativeArtboard != null) {
6175
+ return new Artboard(nativeArtboard);
6176
+ }
6177
+ return null;
6178
+ };
6160
6179
  // Error message for missing source or buffer
6161
6180
  RiveFile.missingErrorMessage = "Rive source file or data buffer required";
6162
6181
  // Error message for file load error
@@ -6440,28 +6459,31 @@ var Rive = /** @class */ (function () {
6440
6459
  // Returns true for successful initialization.
6441
6460
  Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay, autoBind) {
6442
6461
  return __awaiter(this, void 0, void 0, function () {
6443
- var error_2, msg;
6462
+ var riveFile, error_2, msg;
6444
6463
  var _a;
6445
6464
  return __generator(this, function (_b) {
6446
6465
  switch (_b.label) {
6447
6466
  case 0:
6448
6467
  _b.trys.push([0, 3, , 4]);
6449
6468
  if (!(this.riveFile == null)) return [3 /*break*/, 2];
6450
- this.riveFile = new RiveFile({
6469
+ riveFile = new RiveFile({
6451
6470
  src: this.src,
6452
6471
  buffer: this.buffer,
6453
6472
  enableRiveAssetCDN: this.enableRiveAssetCDN,
6454
6473
  assetLoader: this.assetLoader,
6455
6474
  });
6456
- return [4 /*yield*/, this.riveFile.init()];
6475
+ this.riveFile = riveFile;
6476
+ return [4 /*yield*/, riveFile.init()];
6457
6477
  case 1:
6458
6478
  _b.sent();
6459
- _b.label = 2;
6460
- case 2:
6461
- // Check for riveFile in case it has been cleaned up while initializing;
6462
- if (!this.riveFile) {
6479
+ if (this.destroyed) {
6480
+ // In the very unlikely scenario where the rive file created by this Rive is shared by
6481
+ // another rive file, we only want to destroy it if this file is the only owner.
6482
+ riveFile.destroyIfUnused();
6463
6483
  return [2 /*return*/, false];
6464
6484
  }
6485
+ _b.label = 2;
6486
+ case 2:
6465
6487
  this.file = this.riveFile.getInstance();
6466
6488
  // Initialize and draw frame
6467
6489
  this.initArtboard(artboardName, animationNames, stateMachineNames, autoplay, autoBind);
@@ -7598,6 +7620,10 @@ var Rive = /** @class */ (function () {
7598
7620
  }
7599
7621
  return null;
7600
7622
  };
7623
+ Rive.prototype.getArtboard = function (name) {
7624
+ var _a, _b;
7625
+ return (_b = (_a = this.riveFile) === null || _a === void 0 ? void 0 : _a.getArtboard(name)) !== null && _b !== void 0 ? _b : null;
7626
+ };
7601
7627
  // Error message for missing source or buffer
7602
7628
  Rive.missingErrorMessage = "Rive source file or data buffer required";
7603
7629
  // Error message for removed rive file
@@ -7699,6 +7725,7 @@ var PropertyType;
7699
7725
  PropertyType["Enum"] = "enum";
7700
7726
  PropertyType["List"] = "list";
7701
7727
  PropertyType["Image"] = "image";
7728
+ PropertyType["Artboard"] = "artboard";
7702
7729
  })(PropertyType || (PropertyType = {}));
7703
7730
  var ViewModelInstance = /** @class */ (function () {
7704
7731
  function ViewModelInstance(runtimeInstance, parent) {
@@ -7825,7 +7852,7 @@ var ViewModelInstance = /** @class */ (function () {
7825
7852
  return null;
7826
7853
  };
7827
7854
  ViewModelInstance.prototype.propertyFromPathSegments = function (pathSegments, index, type) {
7828
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
7855
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
7829
7856
  if (index < pathSegments.length - 1) {
7830
7857
  var viewModelInstance = this.internalViewModelInstance(pathSegments[index]);
7831
7858
  if (viewModelInstance !== null) {
@@ -7885,6 +7912,12 @@ var ViewModelInstance = /** @class */ (function () {
7885
7912
  return new ViewModelInstanceAssetImage(instance, this);
7886
7913
  }
7887
7914
  break;
7915
+ case PropertyType.Artboard:
7916
+ instance = (_t = (_s = this._runtimeInstance) === null || _s === void 0 ? void 0 : _s.artboard(pathSegments[index])) !== null && _t !== void 0 ? _t : null;
7917
+ if (instance !== null) {
7918
+ return new ViewModelInstanceArtboard(instance, this);
7919
+ }
7920
+ break;
7888
7921
  }
7889
7922
  return null;
7890
7923
  };
@@ -7974,6 +8007,15 @@ var ViewModelInstance = /** @class */ (function () {
7974
8007
  var viewmodelInstanceValue = this.propertyFromPath(path, PropertyType.Image);
7975
8008
  return viewmodelInstanceValue;
7976
8009
  };
8010
+ /**
8011
+ * method to access an artboard property instance belonging
8012
+ * to the view model instance or to a nested view model instance
8013
+ * @param path - path to the image property
8014
+ */
8015
+ ViewModelInstance.prototype.artboard = function (path) {
8016
+ var viewmodelInstanceValue = this.propertyFromPath(path, PropertyType.Artboard);
8017
+ return viewmodelInstanceValue;
8018
+ };
7977
8019
  /**
7978
8020
  * method to access a view model property instance belonging
7979
8021
  * to the view model instance or to a nested view model instance
@@ -8358,6 +8400,24 @@ var ViewModelInstanceAssetImage = /** @class */ (function (_super) {
8358
8400
  return ViewModelInstanceAssetImage;
8359
8401
  }(ViewModelInstanceValue));
8360
8402
 
8403
+ var ViewModelInstanceArtboard = /** @class */ (function (_super) {
8404
+ __extends(ViewModelInstanceArtboard, _super);
8405
+ function ViewModelInstanceArtboard(instance, root) {
8406
+ return _super.call(this, instance, root) || this;
8407
+ }
8408
+ Object.defineProperty(ViewModelInstanceArtboard.prototype, "value", {
8409
+ set: function (artboard) {
8410
+ this._viewModelInstanceValue.value(artboard.nativeArtboard);
8411
+ },
8412
+ enumerable: false,
8413
+ configurable: true
8414
+ });
8415
+ ViewModelInstanceArtboard.prototype.internalHandleCallback = function (callback) {
8416
+ callback();
8417
+ };
8418
+ return ViewModelInstanceArtboard;
8419
+ }(ViewModelInstanceValue));
8420
+
8361
8421
  // Loads Rive data from a URI via fetch.
8362
8422
  var loadRiveFile = function (src) { return __awaiter(void 0, void 0, void 0, function () {
8363
8423
  var req, res, buffer;