@rive-app/webgl 2.26.3 → 2.26.5

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/rive.js CHANGED
@@ -187,9 +187,9 @@ l.onRuntimeInitialized = function() {
187
187
  function b(r) {
188
188
  var u = {alpha:1, depth:0, stencil:8, antialias:0, premultipliedAlpha:1, preserveDrawingBuffer:0, powerPreference:"high-performance", failIfMajorPerformanceCaveat:0, enableExtensionsByDefault:1, explicitSwapControl:0, renderViaOffscreenBackBuffer:0,}, z = r.getContext("webgl2", u);
189
189
  z || (z = r.getContext("webgl", u));
190
- var B = z, C = ha(ja), O = {handle:C, attributes:u, version:u.Dc, Ta:B};
190
+ var B = z, C = ha(ia), O = {handle:C, attributes:u, version:u.Dc, Ta:B};
191
191
  B.canvas && (B.canvas.pc = O);
192
- ja[C] = O;
192
+ ia[C] = O;
193
193
  ("undefined" == typeof u.Jb || u.Jb) && ka(O);
194
194
  la(C);
195
195
  u = g(r.width, r.height);
@@ -214,7 +214,7 @@ l.onRuntimeInitialized = function() {
214
214
  }
215
215
  u = Math.min(u, r);
216
216
  u = Math.min(z, r);
217
- C.sort((ia, Gb) => Gb.Ja - ia.Ja);
217
+ C.sort((ja, Gb) => Gb.Ja - ja.Ja);
218
218
  B = new l.DynamicRectanizer(r);
219
219
  for (M = 0; M < C.length;) {
220
220
  B.reset(u, z);
@@ -239,13 +239,13 @@ l.onRuntimeInitialized = function() {
239
239
  for (P = M; P < O; ++P) {
240
240
  J = C[P];
241
241
  e.saveClipRect(J.pa, J.qa, J.pa + J.da, J.qa + J.ca);
242
- let ia = new l.Mat2D();
243
- ia.xx = J.da / J.F.width;
244
- ia.yy = J.ca / J.F.height;
245
- ia.xy = ia.yx = 0;
246
- ia.tx = J.pa;
247
- ia.ty = J.qa;
248
- e.transform(ia);
242
+ let ja = new l.Mat2D();
243
+ ja.xx = J.da / J.F.width;
244
+ ja.yy = J.ca / J.F.height;
245
+ ja.xy = ja.yx = 0;
246
+ ja.tx = J.pa;
247
+ ja.ty = J.qa;
248
+ e.transform(ja);
249
249
  for (const Gb of J.R) {
250
250
  Gb();
251
251
  }
@@ -408,7 +408,7 @@ function Qa(a, b) {
408
408
  return Pa(c, a, b);
409
409
  }));
410
410
  }
411
- var Ra, Sa, Wa = {702476:(a, b, c, d, e) => {
411
+ var Ra, Sa, Wa = {704636:(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 = {702476:(a, b, c, d, e) => {
471
471
  }
472
472
  window.h.Ea += 1;
473
473
  return 1;
474
- }, 704654:() => {
474
+ }, 706814:() => {
475
475
  "undefined" !== typeof window.h && (--window.h.Ea, 0 === window.h.Ea && delete window.h);
476
- }, 704818:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 704922:() => {
476
+ }, 706978:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 707082:() => {
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 = {702476:(a, b, c, d, e) => {
481
481
  } catch (c) {
482
482
  return 0;
483
483
  }
484
- }, 705093:(a, b, c, d, e, f) => {
484
+ }, 707253:(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 = {702476:(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
- }, 707970:a => window.h.ta(a).I.sampleRate, 708043:a => {
530
+ }, 710130:a => window.h.ta(a).I.sampleRate, 710203: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 = {702476:(a, b, c, d, e) => {
535
535
  a.I.close();
536
536
  a.I = void 0;
537
537
  a.lb = void 0;
538
- }, 708443:a => {
538
+ }, 710603:a => {
539
539
  window.h.xb(a);
540
- }, 708493:a => {
540
+ }, 710653:a => {
541
541
  a = window.h.ta(a);
542
542
  a.I.resume();
543
543
  a.state = window.h.ha.sb;
544
- }, 708632:a => {
544
+ }, 710792:a => {
545
545
  a = window.h.ta(a);
546
546
  a.I.suspend();
547
547
  a.state = window.h.ha.stopped;
@@ -1820,7 +1820,7 @@ function Bd(a) {
1820
1820
  b.drawBuffersWEBGL(c, d);
1821
1821
  });
1822
1822
  }
1823
- var Cd = 1, Dd = [], Ed = [], Fd = [], Gd = [], Hd = [], Id = [], Jd = [], ja = [], Kd = [], Ld = [], Md = {}, Nd = {}, Od = 4;
1823
+ var Cd = 1, Dd = [], Ed = [], Fd = [], Gd = [], Hd = [], Id = [], Jd = [], ia = [], Kd = [], Ld = [], Md = {}, Nd = {}, Od = 4;
1824
1824
  function S(a) {
1825
1825
  Pd || (Pd = a);
1826
1826
  }
@@ -1831,7 +1831,7 @@ function ha(a) {
1831
1831
  return b;
1832
1832
  }
1833
1833
  function la(a) {
1834
- T = ja[a];
1834
+ T = ia[a];
1835
1835
  l.yc = U = T && T.Ta;
1836
1836
  return !(a && !U);
1837
1837
  }
@@ -2930,6 +2930,8 @@ var Ge = {__syscall_fcntl64:function(a, b, c) {
2930
2930
  return ic(a[b]);
2931
2931
  }, _emval_incref:function(a) {
2932
2932
  4 < a && (I.get(a).pb += 1);
2933
+ }, _emval_new_array:function() {
2934
+ return ic([]);
2933
2935
  }, _emval_new_cstring:function(a) {
2934
2936
  return ic(td(a));
2935
2937
  }, _emval_new_object:function() {
@@ -4061,7 +4063,7 @@ Je();
4061
4063
  /* 2 */
4062
4064
  /***/ ((module) => {
4063
4065
 
4064
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl","version":"2.26.3","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}}');
4066
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl","version":"2.26.5","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
4067
 
4066
4068
  /***/ }),
4067
4069
  /* 3 */
@@ -4520,6 +4522,7 @@ var __webpack_exports__ = {};
4520
4522
  __webpack_require__.r(__webpack_exports__);
4521
4523
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
4522
4524
  /* harmony export */ Alignment: () => (/* binding */ Alignment),
4525
+ /* harmony export */ DataEnum: () => (/* binding */ DataEnum),
4523
4526
  /* harmony export */ EventType: () => (/* binding */ EventType),
4524
4527
  /* harmony export */ Fit: () => (/* binding */ Fit),
4525
4528
  /* harmony export */ Layout: () => (/* binding */ Layout),
@@ -4531,6 +4534,15 @@ __webpack_require__.r(__webpack_exports__);
4531
4534
  /* harmony export */ StateMachineInput: () => (/* binding */ StateMachineInput),
4532
4535
  /* harmony export */ StateMachineInputType: () => (/* binding */ StateMachineInputType),
4533
4536
  /* harmony export */ Testing: () => (/* binding */ Testing),
4537
+ /* harmony export */ ViewModel: () => (/* binding */ ViewModel),
4538
+ /* harmony export */ ViewModelInstance: () => (/* binding */ ViewModelInstance),
4539
+ /* harmony export */ ViewModelInstanceBoolean: () => (/* binding */ ViewModelInstanceBoolean),
4540
+ /* harmony export */ ViewModelInstanceColor: () => (/* binding */ ViewModelInstanceColor),
4541
+ /* harmony export */ ViewModelInstanceEnum: () => (/* binding */ ViewModelInstanceEnum),
4542
+ /* harmony export */ ViewModelInstanceNumber: () => (/* binding */ ViewModelInstanceNumber),
4543
+ /* harmony export */ ViewModelInstanceString: () => (/* binding */ ViewModelInstanceString),
4544
+ /* harmony export */ ViewModelInstanceTrigger: () => (/* binding */ ViewModelInstanceTrigger),
4545
+ /* harmony export */ ViewModelInstanceValue: () => (/* binding */ ViewModelInstanceValue),
4534
4546
  /* harmony export */ decodeAudio: () => (/* binding */ decodeAudio),
4535
4547
  /* harmony export */ decodeFont: () => (/* binding */ decodeFont),
4536
4548
  /* harmony export */ decodeImage: () => (/* binding */ decodeImage)
@@ -4554,6 +4566,17 @@ var __extends = (undefined && undefined.__extends) || (function () {
4554
4566
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
4555
4567
  };
4556
4568
  })();
4569
+ var __assign = (undefined && undefined.__assign) || function () {
4570
+ __assign = Object.assign || function(t) {
4571
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4572
+ s = arguments[i];
4573
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
4574
+ t[p] = s[p];
4575
+ }
4576
+ return t;
4577
+ };
4578
+ return __assign.apply(this, arguments);
4579
+ };
4557
4580
  var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
4558
4581
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4559
4582
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -4990,6 +5013,11 @@ var StateMachine = /** @class */ (function () {
4990
5013
  this.inputs.length = 0;
4991
5014
  this.instance.delete();
4992
5015
  };
5016
+ StateMachine.prototype.bindViewModelInstance = function (viewModelInstance) {
5017
+ if (viewModelInstance.runtimeInstance != null) {
5018
+ this.instance.bindViewModelInstance(viewModelInstance.runtimeInstance);
5019
+ }
5020
+ };
4993
5021
  return StateMachine;
4994
5022
  }());
4995
5023
  // #endregion
@@ -5136,6 +5164,9 @@ var Animator = /** @class */ (function () {
5136
5164
  if (sm) {
5137
5165
  var newStateMachine = new StateMachine(sm, this.runtime, playing, this.artboard);
5138
5166
  this.stateMachines.push(newStateMachine);
5167
+ if (!playing) {
5168
+ newStateMachine.advanceAndApply(0);
5169
+ }
5139
5170
  }
5140
5171
  else {
5141
5172
  // In order to maintain compatibility with current behavior, if a state machine is not found
@@ -5881,6 +5912,8 @@ var Rive = /** @class */ (function () {
5881
5912
  this._audioEventListener = null;
5882
5913
  // draw method bound to the class
5883
5914
  this._boundDraw = null;
5915
+ this._viewModelInstance = null;
5916
+ this._dataEnums = null;
5884
5917
  // Durations to generate a frame for the last second. Used for performance profiling.
5885
5918
  this.durations = [];
5886
5919
  this.frameTimes = [];
@@ -5966,6 +5999,7 @@ var Rive = /** @class */ (function () {
5966
5999
  buffer: this.buffer,
5967
6000
  riveFile: this.riveFile,
5968
6001
  autoplay: params.autoplay,
6002
+ autoBind: params.autoBind,
5969
6003
  animations: params.animations,
5970
6004
  stateMachines: params.stateMachines,
5971
6005
  artboard: params.artboard,
@@ -5984,7 +6018,7 @@ var Rive = /** @class */ (function () {
5984
6018
  // Initializes the Rive object either from constructor or load()
5985
6019
  Rive.prototype.init = function (_a) {
5986
6020
  var _this = this;
5987
- var src = _a.src, buffer = _a.buffer, riveFile = _a.riveFile, animations = _a.animations, stateMachines = _a.stateMachines, artboard = _a.artboard, _b = _a.autoplay, autoplay = _b === void 0 ? false : _b, _c = _a.useOffscreenRenderer, useOffscreenRenderer = _c === void 0 ? false : _c;
6021
+ var src = _a.src, buffer = _a.buffer, riveFile = _a.riveFile, animations = _a.animations, stateMachines = _a.stateMachines, artboard = _a.artboard, _b = _a.autoplay, autoplay = _b === void 0 ? false : _b, _c = _a.useOffscreenRenderer, useOffscreenRenderer = _c === void 0 ? false : _c, _d = _a.autoBind, autoBind = _d === void 0 ? false : _d;
5988
6022
  if (this.destroyed) {
5989
6023
  return;
5990
6024
  }
@@ -6019,7 +6053,7 @@ var Rive = /** @class */ (function () {
6019
6053
  _this.resizeDrawingSurfaceToCanvas();
6020
6054
  }
6021
6055
  // Load Rive data from a source uri or a data buffer
6022
- _this.initData(artboard, startingAnimationNames, startingStateMachineNames, autoplay)
6056
+ _this.initData(artboard, startingAnimationNames, startingStateMachineNames, autoplay, autoBind)
6023
6057
  .then(function () { return _this.setupRiveListeners(); })
6024
6058
  .catch(function (e) {
6025
6059
  console.error(e);
@@ -6100,7 +6134,7 @@ var Rive = /** @class */ (function () {
6100
6134
  this._artboardHeight || this.artboard.height;
6101
6135
  };
6102
6136
  // Initializes runtime with Rive data and preps for playing
6103
- Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay) {
6137
+ Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay, autoBind) {
6104
6138
  return __awaiter(this, void 0, void 0, function () {
6105
6139
  var error_1, msg;
6106
6140
  var _a;
@@ -6126,7 +6160,7 @@ var Rive = /** @class */ (function () {
6126
6160
  }
6127
6161
  this.file = this.riveFile.getInstance();
6128
6162
  // Initialize and draw frame
6129
- this.initArtboard(artboardName, animationNames, stateMachineNames, autoplay);
6163
+ this.initArtboard(artboardName, animationNames, stateMachineNames, autoplay, autoBind);
6130
6164
  // Initialize the artboard size
6131
6165
  this.initArtboardSize();
6132
6166
  // Check for audio
@@ -6155,7 +6189,7 @@ var Rive = /** @class */ (function () {
6155
6189
  });
6156
6190
  };
6157
6191
  // Initialize for playback
6158
- Rive.prototype.initArtboard = function (artboardName, animationNames, stateMachineNames, autoplay) {
6192
+ Rive.prototype.initArtboard = function (artboardName, animationNames, stateMachineNames, autoplay, autoBind) {
6159
6193
  if (!this.file) {
6160
6194
  return;
6161
6195
  }
@@ -6200,13 +6234,24 @@ var Rive = /** @class */ (function () {
6200
6234
  data: instanceNames,
6201
6235
  },
6202
6236
  });
6237
+ if (autoBind) {
6238
+ var viewModel = this.file.defaultArtboardViewModel(rootArtboard);
6239
+ if (viewModel !== null) {
6240
+ var runtimeInstance = viewModel.defaultInstance();
6241
+ if (runtimeInstance !== null) {
6242
+ var viewModelInstance = new ViewModelInstance(runtimeInstance, null);
6243
+ this.bindViewModelInstance(viewModelInstance);
6244
+ }
6245
+ }
6246
+ }
6203
6247
  };
6204
6248
  // Draws the current artboard frame
6205
6249
  Rive.prototype.drawFrame = function () {
6206
- var _a;
6250
+ var _a, _b;
6207
6251
  if ((_a = document === null || document === void 0 ? void 0 : document.timeline) === null || _a === void 0 ? void 0 : _a.currentTime) {
6208
6252
  if (this.loaded && this.artboard && !this.frameRequestId) {
6209
6253
  this._boundDraw(document.timeline.currentTime);
6254
+ (_b = this.runtime) === null || _b === void 0 ? void 0 : _b.resolveAnimationFrame();
6210
6255
  }
6211
6256
  }
6212
6257
  else {
@@ -6218,6 +6263,7 @@ var Rive = /** @class */ (function () {
6218
6263
  * @param time the time at which to render a frame
6219
6264
  */
6220
6265
  Rive.prototype.draw = function (time, onSecond) {
6266
+ var _a;
6221
6267
  // Clear the frameRequestId, as we're now rendering a fresh frame
6222
6268
  this.frameRequestId = null;
6223
6269
  var before = performance.now();
@@ -6253,8 +6299,8 @@ var Rive = /** @class */ (function () {
6253
6299
  // - Advance non-paused state machines by the elapsed number of seconds
6254
6300
  // - Advance to the first frame even when autoplay is false
6255
6301
  var activeStateMachines = this.animator.stateMachines.filter(function (a) { return a.playing; });
6256
- for (var _a = 0, activeStateMachines_1 = activeStateMachines; _a < activeStateMachines_1.length; _a++) {
6257
- var stateMachine = activeStateMachines_1[_a];
6302
+ for (var _b = 0, activeStateMachines_1 = activeStateMachines; _b < activeStateMachines_1.length; _b++) {
6303
+ var stateMachine = activeStateMachines_1[_b];
6258
6304
  // Check for events before the current frame's state machine advance
6259
6305
  var numEventsReported = stateMachine.reportedEventCount();
6260
6306
  if (numEventsReported) {
@@ -6269,7 +6315,7 @@ var Rive = /** @class */ (function () {
6269
6315
  // Handle the event side effect if explicitly enabled
6270
6316
  if (this.automaticallyHandleEvents) {
6271
6317
  var newAnchorTag = document.createElement("a");
6272
- var _b = event_1, url = _b.url, target = _b.target;
6318
+ var _c = event_1, url = _c.url, target = _c.target;
6273
6319
  var sanitizedUrl = (0,_utils__WEBPACK_IMPORTED_MODULE_3__.sanitizeUrl)(url);
6274
6320
  url && newAnchorTag.setAttribute("href", sanitizedUrl);
6275
6321
  target && newAnchorTag.setAttribute("target", target);
@@ -6322,6 +6368,7 @@ var Rive = /** @class */ (function () {
6322
6368
  this.frameTimes.shift();
6323
6369
  this.durations.shift();
6324
6370
  }
6371
+ (_a = this._viewModelInstance) === null || _a === void 0 ? void 0 : _a.handleCallbacks();
6325
6372
  // Calling requestAnimationFrame will rerun draw() at the correct rate:
6326
6373
  // https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Basic_animations
6327
6374
  if (this.animator.isPlaying) {
@@ -6379,7 +6426,7 @@ var Rive = /** @class */ (function () {
6379
6426
  * Rive class
6380
6427
  */
6381
6428
  Rive.prototype.cleanup = function () {
6382
- var _a;
6429
+ var _a, _b;
6383
6430
  this.destroyed = true;
6384
6431
  // Stop the renderer if it hasn't already been stopped.
6385
6432
  this.stopRendering();
@@ -6400,6 +6447,9 @@ var Rive = /** @class */ (function () {
6400
6447
  audioManager.remove(this._audioEventListener);
6401
6448
  this._audioEventListener = null;
6402
6449
  }
6450
+ (_b = this._viewModelInstance) === null || _b === void 0 ? void 0 : _b.cleanup();
6451
+ this._viewModelInstance = null;
6452
+ this._dataEnums = null;
6403
6453
  };
6404
6454
  /**
6405
6455
  * Cleans up the Renderer object. Only call this API if you no longer
@@ -6551,16 +6601,17 @@ var Rive = /** @class */ (function () {
6551
6601
  *
6552
6602
  */
6553
6603
  Rive.prototype.reset = function (params) {
6554
- var _a;
6604
+ var _a, _b;
6555
6605
  // Get the current artboard, animations, state machines, and playback states
6556
6606
  var artBoardName = params === null || params === void 0 ? void 0 : params.artboard;
6557
6607
  var animationNames = mapToStringArray(params === null || params === void 0 ? void 0 : params.animations);
6558
6608
  var stateMachineNames = mapToStringArray(params === null || params === void 0 ? void 0 : params.stateMachines);
6559
6609
  var autoplay = (_a = params === null || params === void 0 ? void 0 : params.autoplay) !== null && _a !== void 0 ? _a : false;
6610
+ var autoBind = (_b = params === null || params === void 0 ? void 0 : params.autoBind) !== null && _b !== void 0 ? _b : false;
6560
6611
  // Stop everything and clean up
6561
6612
  this.cleanupInstances();
6562
6613
  // Reinitialize an artboard instance with the state
6563
- this.initArtboard(artBoardName, animationNames, stateMachineNames, autoplay);
6614
+ this.initArtboard(artBoardName, animationNames, stateMachineNames, autoplay, autoBind);
6564
6615
  this.taskQueue.process();
6565
6616
  };
6566
6617
  // Loads a new Rive file, keeping listeners in place
@@ -7183,6 +7234,62 @@ var Rive = /** @class */ (function () {
7183
7234
  enumerable: false,
7184
7235
  configurable: true
7185
7236
  });
7237
+ /**
7238
+ * Initialize the data context with the view model instance.
7239
+ */
7240
+ Rive.prototype.bindViewModelInstance = function (viewModelInstance) {
7241
+ var _a;
7242
+ if (this.artboard && !this.destroyed) {
7243
+ if (viewModelInstance && viewModelInstance.runtimeInstance) {
7244
+ viewModelInstance.internalIncrementReferenceCount();
7245
+ (_a = this._viewModelInstance) === null || _a === void 0 ? void 0 : _a.cleanup();
7246
+ this._viewModelInstance = viewModelInstance;
7247
+ this.artboard.bindViewModelInstance(viewModelInstance.runtimeInstance);
7248
+ this.animator.stateMachines.forEach(function (stateMachine) {
7249
+ return stateMachine.bindViewModelInstance(viewModelInstance);
7250
+ });
7251
+ }
7252
+ }
7253
+ };
7254
+ Object.defineProperty(Rive.prototype, "viewModelInstance", {
7255
+ get: function () {
7256
+ return this._viewModelInstance;
7257
+ },
7258
+ enumerable: false,
7259
+ configurable: true
7260
+ });
7261
+ Rive.prototype.viewModelByIndex = function (index) {
7262
+ var viewModel = this.file.viewModelByIndex(index);
7263
+ if (viewModel !== null) {
7264
+ return new ViewModel(viewModel);
7265
+ }
7266
+ return null;
7267
+ };
7268
+ 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;
7274
+ };
7275
+ Rive.prototype.enums = function () {
7276
+ if (this._dataEnums === null) {
7277
+ var dataEnums = this.file.enums();
7278
+ this._dataEnums = dataEnums.map(function (dataEnum) {
7279
+ return new DataEnum(dataEnum);
7280
+ });
7281
+ }
7282
+ return this._dataEnums;
7283
+ };
7284
+ Rive.prototype.defaultViewModel = function () {
7285
+ if (this.artboard) {
7286
+ var viewModel = this.file.defaultArtboardViewModel(this.artboard);
7287
+ if (viewModel) {
7288
+ return new ViewModel(viewModel);
7289
+ }
7290
+ }
7291
+ return null;
7292
+ };
7186
7293
  // Error message for missing source or buffer
7187
7294
  Rive.missingErrorMessage = "Rive source file or data buffer required";
7188
7295
  // Error message for removed rive file
@@ -7190,6 +7297,481 @@ var Rive = /** @class */ (function () {
7190
7297
  return Rive;
7191
7298
  }());
7192
7299
 
7300
+ var ViewModel = /** @class */ (function () {
7301
+ function ViewModel(viewModel) {
7302
+ this._viewModel = viewModel;
7303
+ }
7304
+ Object.defineProperty(ViewModel.prototype, "instanceCount", {
7305
+ get: function () {
7306
+ return this._viewModel.instanceCount;
7307
+ },
7308
+ enumerable: false,
7309
+ configurable: true
7310
+ });
7311
+ Object.defineProperty(ViewModel.prototype, "name", {
7312
+ get: function () {
7313
+ return this._viewModel.name;
7314
+ },
7315
+ enumerable: false,
7316
+ configurable: true
7317
+ });
7318
+ ViewModel.prototype.instanceByIndex = function (index) {
7319
+ var instance = this._viewModel.instanceByIndex(index);
7320
+ if (instance !== null) {
7321
+ return new ViewModelInstance(instance, null);
7322
+ }
7323
+ return null;
7324
+ };
7325
+ ViewModel.prototype.instanceByName = function (name) {
7326
+ var instance = this._viewModel.instanceByName(name);
7327
+ if (instance !== null) {
7328
+ return new ViewModelInstance(instance, null);
7329
+ }
7330
+ return null;
7331
+ };
7332
+ ViewModel.prototype.defaultInstance = function () {
7333
+ var runtimeInstance = this._viewModel.defaultInstance();
7334
+ if (runtimeInstance !== null) {
7335
+ return new ViewModelInstance(runtimeInstance, null);
7336
+ }
7337
+ return null;
7338
+ };
7339
+ ViewModel.prototype.instance = function () {
7340
+ var runtimeInstance = this._viewModel.instance();
7341
+ if (runtimeInstance !== null) {
7342
+ return new ViewModelInstance(runtimeInstance, null);
7343
+ }
7344
+ return null;
7345
+ };
7346
+ Object.defineProperty(ViewModel.prototype, "properties", {
7347
+ get: function () {
7348
+ return this._viewModel.getProperties();
7349
+ },
7350
+ enumerable: false,
7351
+ configurable: true
7352
+ });
7353
+ Object.defineProperty(ViewModel.prototype, "instanceNames", {
7354
+ get: function () {
7355
+ return this._viewModel.getInstanceNames();
7356
+ },
7357
+ enumerable: false,
7358
+ configurable: true
7359
+ });
7360
+ return ViewModel;
7361
+ }());
7362
+
7363
+ var DataEnum = /** @class */ (function () {
7364
+ function DataEnum(dataEnum) {
7365
+ this._dataEnum = dataEnum;
7366
+ }
7367
+ Object.defineProperty(DataEnum.prototype, "name", {
7368
+ get: function () {
7369
+ return this._dataEnum.name;
7370
+ },
7371
+ enumerable: false,
7372
+ configurable: true
7373
+ });
7374
+ Object.defineProperty(DataEnum.prototype, "values", {
7375
+ get: function () {
7376
+ return this._dataEnum.values;
7377
+ },
7378
+ enumerable: false,
7379
+ configurable: true
7380
+ });
7381
+ return DataEnum;
7382
+ }());
7383
+
7384
+ var ViewModelInstance = /** @class */ (function () {
7385
+ function ViewModelInstance(runtimeInstance, root) {
7386
+ this._propertiesWithCallbacks = [];
7387
+ this._referenceCount = 0;
7388
+ this._runtimeInstance = runtimeInstance;
7389
+ this._root = root || this;
7390
+ }
7391
+ Object.defineProperty(ViewModelInstance.prototype, "runtimeInstance", {
7392
+ get: function () {
7393
+ return this._runtimeInstance;
7394
+ },
7395
+ enumerable: false,
7396
+ configurable: true
7397
+ });
7398
+ ViewModelInstance.prototype.handleCallbacks = function () {
7399
+ if (this._propertiesWithCallbacks.length !== 0) {
7400
+ this._propertiesWithCallbacks.forEach(function (property) {
7401
+ property.handleCallbacks();
7402
+ });
7403
+ }
7404
+ };
7405
+ ViewModelInstance.prototype.clearCallbacks = function () {
7406
+ this._propertiesWithCallbacks.forEach(function (property) {
7407
+ property.clearCallbacks();
7408
+ });
7409
+ };
7410
+ /**
7411
+ * method to access a property instance of type number belonging
7412
+ * to the view model instance or to a nested view model instance
7413
+ * @param path - path to the number property
7414
+ */
7415
+ ViewModelInstance.prototype.number = function (path) {
7416
+ var _a;
7417
+ var instance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.number(path);
7418
+ if (instance) {
7419
+ return new ViewModelInstanceNumber(instance, this._root);
7420
+ }
7421
+ return null;
7422
+ };
7423
+ /**
7424
+ * method to access a property instance of type string belonging
7425
+ * to the view model instance or to a nested view model instance
7426
+ * @param path - path to the number property
7427
+ */
7428
+ ViewModelInstance.prototype.string = function (path) {
7429
+ var _a;
7430
+ var instance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.string(path);
7431
+ if (instance) {
7432
+ return new ViewModelInstanceString(instance, this._root);
7433
+ }
7434
+ return null;
7435
+ };
7436
+ /**
7437
+ * method to access a property instance of type boolean belonging
7438
+ * to the view model instance or to a nested view model instance
7439
+ * @param path - path to the number property
7440
+ */
7441
+ ViewModelInstance.prototype.boolean = function (path) {
7442
+ var _a;
7443
+ var instance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.boolean(path);
7444
+ if (instance) {
7445
+ return new ViewModelInstanceBoolean(instance, this._root);
7446
+ }
7447
+ return null;
7448
+ };
7449
+ /**
7450
+ * method to access a property instance of type color belonging
7451
+ * to the view model instance or to a nested view model instance
7452
+ * @param path - path to the number property
7453
+ */
7454
+ ViewModelInstance.prototype.color = function (path) {
7455
+ var _a;
7456
+ var instance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.color(path);
7457
+ if (instance) {
7458
+ return new ViewModelInstanceColor(instance, this._root);
7459
+ }
7460
+ return null;
7461
+ };
7462
+ /**
7463
+ * method to access a property instance of type trigger belonging
7464
+ * to the view model instance or to a nested view model instance
7465
+ * @param path - path to the number property
7466
+ */
7467
+ ViewModelInstance.prototype.trigger = function (path) {
7468
+ var _a;
7469
+ var instance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.trigger(path);
7470
+ if (instance) {
7471
+ return new ViewModelInstanceTrigger(instance, this._root);
7472
+ }
7473
+ return null;
7474
+ };
7475
+ /**
7476
+ * method to access a property instance of type enum belonging
7477
+ * to the view model instance or to a nested view model instance
7478
+ * @param path - path to the number property
7479
+ */
7480
+ ViewModelInstance.prototype.enum = function (path) {
7481
+ var _a;
7482
+ var instance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.enum(path);
7483
+ if (instance) {
7484
+ return new ViewModelInstanceEnum(instance, this._root);
7485
+ }
7486
+ return null;
7487
+ };
7488
+ /**
7489
+ * method to access a view model property instance belonging
7490
+ * to the view model instance or to a nested view model instance
7491
+ * @param path - path to the number property
7492
+ */
7493
+ ViewModelInstance.prototype.viewModel = function (path) {
7494
+ var _a;
7495
+ var viewModelInstance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.viewModel(path);
7496
+ if (viewModelInstance) {
7497
+ return new ViewModelInstance(viewModelInstance, this._root);
7498
+ }
7499
+ return null;
7500
+ };
7501
+ /**
7502
+ * method to replace a view model property with another view model value
7503
+ * @param path - path to the view model property
7504
+ * @param value - view model that will replace the original
7505
+ */
7506
+ ViewModelInstance.prototype.replaceViewModel = function (path, value) {
7507
+ var _a;
7508
+ if (value.runtimeInstance !== null) {
7509
+ return (((_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.replaceViewModel(path, value.runtimeInstance)) ||
7510
+ false);
7511
+ }
7512
+ return false;
7513
+ };
7514
+ /*
7515
+ * method for internal use, it shouldn't be called externally
7516
+ */
7517
+ ViewModelInstance.prototype.addToCallbacks = function (property) {
7518
+ if (!this._propertiesWithCallbacks.includes(property)) {
7519
+ this._propertiesWithCallbacks.push(property);
7520
+ }
7521
+ };
7522
+ /*
7523
+ * method for internal use, it shouldn't be called externally
7524
+ */
7525
+ ViewModelInstance.prototype.removeFromCallbacks = function (property) {
7526
+ if (this._propertiesWithCallbacks.includes(property)) {
7527
+ this._propertiesWithCallbacks = this._propertiesWithCallbacks.filter(function (prop) { return prop !== property; });
7528
+ }
7529
+ };
7530
+ /*
7531
+ * method to add one to the reference counter of the instance.
7532
+ * Use if the file owning the reference is destroyed but the instance needs to stay around
7533
+ */
7534
+ ViewModelInstance.prototype.incrementReferenceCount = function () {
7535
+ var _a;
7536
+ this._referenceCount++;
7537
+ (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.incrementReferenceCount();
7538
+ };
7539
+ /*
7540
+ * method to subtract one to the reference counter of the instance.
7541
+ * Use if incrementReferenceCount has been called
7542
+ */
7543
+ ViewModelInstance.prototype.decrementReferenceCount = function () {
7544
+ var _a;
7545
+ this._referenceCount--;
7546
+ (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.decrementReferenceCount();
7547
+ };
7548
+ Object.defineProperty(ViewModelInstance.prototype, "properties", {
7549
+ get: function () {
7550
+ var _a;
7551
+ return (((_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.getProperties().map(function (prop) { return (__assign({}, prop)); })) || []);
7552
+ },
7553
+ enumerable: false,
7554
+ configurable: true
7555
+ });
7556
+ ViewModelInstance.prototype.internalIncrementReferenceCount = function () {
7557
+ this._referenceCount++;
7558
+ };
7559
+ ViewModelInstance.prototype.cleanup = function () {
7560
+ this._referenceCount--;
7561
+ if (this._referenceCount <= 0) {
7562
+ this._runtimeInstance = null;
7563
+ this.clearCallbacks();
7564
+ this._propertiesWithCallbacks = [];
7565
+ }
7566
+ };
7567
+ return ViewModelInstance;
7568
+ }());
7569
+
7570
+ var ViewModelInstanceValue = /** @class */ (function () {
7571
+ function ViewModelInstanceValue(instance, root) {
7572
+ this.callbacks = [];
7573
+ this._viewModelInstanceValue = instance;
7574
+ this._rootViewModel = root;
7575
+ }
7576
+ ViewModelInstanceValue.prototype.on = function (callback) {
7577
+ // Since we don't clean the changed flag for properties that don't have listeners,
7578
+ // we clean it the first time we add a listener to it
7579
+ if (this.callbacks.length === 0) {
7580
+ this._viewModelInstanceValue.clearChanges();
7581
+ }
7582
+ if (!this.callbacks.includes(callback)) {
7583
+ this.callbacks.push(callback);
7584
+ this._rootViewModel.addToCallbacks(this);
7585
+ }
7586
+ };
7587
+ ViewModelInstanceValue.prototype.off = function (callback) {
7588
+ if (!callback) {
7589
+ this.callbacks.length = 0;
7590
+ }
7591
+ else {
7592
+ this.callbacks = this.callbacks.filter(function (cb) { return cb !== callback; });
7593
+ }
7594
+ if (this.callbacks.length === 0) {
7595
+ this._rootViewModel.removeFromCallbacks(this);
7596
+ }
7597
+ };
7598
+ ViewModelInstanceValue.prototype.internalHandleCallback = function (callback) { };
7599
+ ViewModelInstanceValue.prototype.handleCallbacks = function () {
7600
+ var _this = this;
7601
+ if (this._viewModelInstanceValue.hasChanged) {
7602
+ this._viewModelInstanceValue.clearChanges();
7603
+ this.callbacks.forEach(function (callback) {
7604
+ _this.internalHandleCallback(callback);
7605
+ });
7606
+ }
7607
+ };
7608
+ ViewModelInstanceValue.prototype.clearCallbacks = function () {
7609
+ this.callbacks.length = 0;
7610
+ };
7611
+ Object.defineProperty(ViewModelInstanceValue.prototype, "name", {
7612
+ get: function () {
7613
+ return this._viewModelInstanceValue.name;
7614
+ },
7615
+ enumerable: false,
7616
+ configurable: true
7617
+ });
7618
+ return ViewModelInstanceValue;
7619
+ }());
7620
+
7621
+ var ViewModelInstanceString = /** @class */ (function (_super) {
7622
+ __extends(ViewModelInstanceString, _super);
7623
+ function ViewModelInstanceString(instance, root) {
7624
+ return _super.call(this, instance, root) || this;
7625
+ }
7626
+ Object.defineProperty(ViewModelInstanceString.prototype, "value", {
7627
+ get: function () {
7628
+ return this._viewModelInstanceValue.value;
7629
+ },
7630
+ set: function (val) {
7631
+ this._viewModelInstanceValue.value = val;
7632
+ },
7633
+ enumerable: false,
7634
+ configurable: true
7635
+ });
7636
+ ViewModelInstanceString.prototype.internalHandleCallback = function (callback) {
7637
+ callback(this.value);
7638
+ };
7639
+ return ViewModelInstanceString;
7640
+ }(ViewModelInstanceValue));
7641
+
7642
+ var ViewModelInstanceNumber = /** @class */ (function (_super) {
7643
+ __extends(ViewModelInstanceNumber, _super);
7644
+ function ViewModelInstanceNumber(instance, root) {
7645
+ return _super.call(this, instance, root) || this;
7646
+ }
7647
+ Object.defineProperty(ViewModelInstanceNumber.prototype, "value", {
7648
+ get: function () {
7649
+ return this._viewModelInstanceValue.value;
7650
+ },
7651
+ set: function (val) {
7652
+ this._viewModelInstanceValue.value = val;
7653
+ },
7654
+ enumerable: false,
7655
+ configurable: true
7656
+ });
7657
+ ViewModelInstanceNumber.prototype.internalHandleCallback = function (callback) {
7658
+ callback(this.value);
7659
+ };
7660
+ return ViewModelInstanceNumber;
7661
+ }(ViewModelInstanceValue));
7662
+
7663
+ var ViewModelInstanceBoolean = /** @class */ (function (_super) {
7664
+ __extends(ViewModelInstanceBoolean, _super);
7665
+ function ViewModelInstanceBoolean(instance, root) {
7666
+ return _super.call(this, instance, root) || this;
7667
+ }
7668
+ Object.defineProperty(ViewModelInstanceBoolean.prototype, "value", {
7669
+ get: function () {
7670
+ return this._viewModelInstanceValue.value;
7671
+ },
7672
+ set: function (val) {
7673
+ this._viewModelInstanceValue.value = val;
7674
+ },
7675
+ enumerable: false,
7676
+ configurable: true
7677
+ });
7678
+ ViewModelInstanceBoolean.prototype.internalHandleCallback = function (callback) {
7679
+ callback(this.value);
7680
+ };
7681
+ return ViewModelInstanceBoolean;
7682
+ }(ViewModelInstanceValue));
7683
+
7684
+ var ViewModelInstanceTrigger = /** @class */ (function (_super) {
7685
+ __extends(ViewModelInstanceTrigger, _super);
7686
+ function ViewModelInstanceTrigger(instance, root) {
7687
+ return _super.call(this, instance, root) || this;
7688
+ }
7689
+ ViewModelInstanceTrigger.prototype.trigger = function () {
7690
+ return this._viewModelInstanceValue.trigger();
7691
+ };
7692
+ ViewModelInstanceTrigger.prototype.internalHandleCallback = function (callback) {
7693
+ callback();
7694
+ };
7695
+ return ViewModelInstanceTrigger;
7696
+ }(ViewModelInstanceValue));
7697
+
7698
+ var ViewModelInstanceEnum = /** @class */ (function (_super) {
7699
+ __extends(ViewModelInstanceEnum, _super);
7700
+ function ViewModelInstanceEnum(instance, root) {
7701
+ return _super.call(this, instance, root) || this;
7702
+ }
7703
+ Object.defineProperty(ViewModelInstanceEnum.prototype, "value", {
7704
+ get: function () {
7705
+ return this._viewModelInstanceValue.value;
7706
+ },
7707
+ set: function (val) {
7708
+ this._viewModelInstanceValue.value = val;
7709
+ },
7710
+ enumerable: false,
7711
+ configurable: true
7712
+ });
7713
+ Object.defineProperty(ViewModelInstanceEnum.prototype, "valueIndex", {
7714
+ get: function () {
7715
+ return this._viewModelInstanceValue
7716
+ .valueIndex;
7717
+ },
7718
+ set: function (val) {
7719
+ this._viewModelInstanceValue.valueIndex = val;
7720
+ },
7721
+ enumerable: false,
7722
+ configurable: true
7723
+ });
7724
+ Object.defineProperty(ViewModelInstanceEnum.prototype, "values", {
7725
+ get: function () {
7726
+ return this._viewModelInstanceValue.values;
7727
+ },
7728
+ enumerable: false,
7729
+ configurable: true
7730
+ });
7731
+ ViewModelInstanceEnum.prototype.internalHandleCallback = function (callback) {
7732
+ callback(this.value);
7733
+ };
7734
+ return ViewModelInstanceEnum;
7735
+ }(ViewModelInstanceValue));
7736
+
7737
+ var ViewModelInstanceColor = /** @class */ (function (_super) {
7738
+ __extends(ViewModelInstanceColor, _super);
7739
+ function ViewModelInstanceColor(instance, root) {
7740
+ return _super.call(this, instance, root) || this;
7741
+ }
7742
+ Object.defineProperty(ViewModelInstanceColor.prototype, "value", {
7743
+ get: function () {
7744
+ return this._viewModelInstanceValue.value;
7745
+ },
7746
+ set: function (val) {
7747
+ this._viewModelInstanceValue.value = val;
7748
+ },
7749
+ enumerable: false,
7750
+ configurable: true
7751
+ });
7752
+ ViewModelInstanceColor.prototype.rgb = function (r, g, b) {
7753
+ this._viewModelInstanceValue.rgb(r, g, b);
7754
+ };
7755
+ ViewModelInstanceColor.prototype.rgba = function (r, g, b, a) {
7756
+ this._viewModelInstanceValue.argb(a, r, g, b);
7757
+ };
7758
+ ViewModelInstanceColor.prototype.argb = function (a, r, g, b) {
7759
+ this._viewModelInstanceValue.argb(a, r, g, b);
7760
+ };
7761
+ // Value 0 to 255
7762
+ ViewModelInstanceColor.prototype.alpha = function (a) {
7763
+ this._viewModelInstanceValue.alpha(a);
7764
+ };
7765
+ // Value 0 to 1
7766
+ ViewModelInstanceColor.prototype.opacity = function (o) {
7767
+ this._viewModelInstanceValue.alpha(Math.round(Math.max(0, Math.min(1, o)) * 255));
7768
+ };
7769
+ ViewModelInstanceColor.prototype.internalHandleCallback = function (callback) {
7770
+ callback(this.value);
7771
+ };
7772
+ return ViewModelInstanceColor;
7773
+ }(ViewModelInstanceValue));
7774
+
7193
7775
  // Loads Rive data from a URI via fetch.
7194
7776
  var loadRiveFile = function (src) { return __awaiter(void 0, void 0, void 0, function () {
7195
7777
  var req, res, buffer;