@rive-app/canvas 1.0.72 → 1.0.75

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/canvas",
3
- "version": "1.0.72",
3
+ "version": "1.0.75",
4
4
  "description": "Rive's canvas based web api.",
5
5
  "main": "rive.js",
6
6
  "homepage": "https://rive.app",
package/rive.d.ts CHANGED
@@ -46,11 +46,11 @@ export declare class Layout {
46
46
  readonly maxX: number;
47
47
  readonly maxY: number;
48
48
  constructor(params?: LayoutParameters);
49
- static new({ fit, alignment, minX, minY, maxX, maxY }: LayoutParameters): Layout;
49
+ static new({ fit, alignment, minX, minY, maxX, maxY, }: LayoutParameters): Layout;
50
50
  /**
51
51
  * Makes a copy of the layout, replacing any specified parameters
52
52
  */
53
- copyWith({ fit, alignment, minX, minY, maxX, maxY }: LayoutParameters): Layout;
53
+ copyWith({ fit, alignment, minX, minY, maxX, maxY, }: LayoutParameters): Layout;
54
54
  runtimeFit(rive: rc.RiveCanvas): rc.Fit;
55
55
  runtimeAlignment(rive: rc.RiveCanvas): rc.Alignment;
56
56
  }
@@ -256,6 +256,7 @@ export declare class Rive {
256
256
  private readyForPlaying;
257
257
  private runtime;
258
258
  private artboard;
259
+ private eventCleanup;
259
260
  private file;
260
261
  private eventManager;
261
262
  private taskQueue;
package/rive.js CHANGED
@@ -117,7 +117,7 @@ Fa;var e=Ia;var f=Ja;var n=function(){return Ga};var g=1}else 4===a&&(d=Ka,e=La,
117
117
  readValueFromPointer:Hb,da:function(m){vb(m)}})},L:function(b,a,c,d,e,f){Fb[b]={name:R(a),Ba:Z(c,d),ja:Z(e,f),Na:[]}},I:function(b,a,c,d,e,f,n,g,m,h){Fb[b].Na.push({hb:R(a),nb:c,lb:Z(d,e),mb:f,yb:n,xb:Z(g,m),zb:h})},G:function(b,a){a=R(a);X(b,{qb:!0,name:a,argPackAdvance:0,fromWireType:function(){},toWireType:function(){}})},m:function(b,a,c){b=kb(b);a=Ab(a,"emval::as");var d=[],e=Q(d);J[c>>2]=e;return a.toWireType(d,b)},u:function(b,a,c,d,e){b=qc[b];a=kb(a);c=pc(c);var f=[];J[d>>2]=Q(f);return b(a,
118
118
  c,f,e)},e:function(b,a,c,d){b=qc[b];a=kb(a);c=pc(c);b(a,c,null,d)},M:kc,d:function(b,a){var c=sc(b,a),d=c[0];a=d.name+"_$"+c.slice(1).map(function(p){return p.name}).join("_")+"$";var e=tc[a];if(void 0!==e)return e;e=["retType"];for(var f=[d],n="",g=0;g<b-1;++g)n+=(0!==g?", ":"")+"arg"+g,e.push("argType"+g),f.push(c[1+g]);var m="return function "+eb("methodCaller_"+a)+"(handle, name, destructors, args) {\n",h=0;for(g=0;g<b-1;++g)m+=" var arg"+g+" = argType"+g+".readValueFromPointer(args"+(h?"+"+
119
119
  h:"")+");\n",h+=c[g+1].argPackAdvance;m+=" var rv = handle[name]("+n+");\n";for(g=0;g<b-1;++g)c[g+1].deleteObject&&(m+=" argType"+g+".deleteObject(arg"+g+");\n");d.qb||(m+=" return retType.toWireType(destructors, rv);\n");e.push(m+"};\n");b=gc(e).apply(null,f);e=rc(b);return tc[a]=e},H:function(b){b=pc(b);return Q(k[b])},J:function(b,a){b=kb(b);a=kb(a);return Q(b[a])},w:function(b){4<b&&(O[b].Ca+=1)},D:function(b){return Q(pc(b))},x:function(b){var a=kb(b);Gb(a);kc(b)},o:function(b,a){b=
120
- Ab(b,"_emval_take_value");b=b.readValueFromPointer(a);return Q(b)},v:function(){ta("")},p:function(b){var a=D.length;b>>>=0;if(2147483648<b)return!1;for(var c=1;4>=c;c*=2){var d=a*(1+.2/c);d=Math.min(d,b+100663296);d=Math.max(b,d);0<d%65536&&(d+=65536-d%65536);a:{try{za.grow(Math.min(2147483648,d)-Na.byteLength+65535>>>16);Ra();var e=1;break a}catch(f){}e=void 0}if(e)return!0}return!1},B:function(){return 0},y:function(){},C:function(b,a,c,d){for(var e=0,f=0;f<c;f++){var n=J[a>>2],g=J[a+4>>2];a+=
120
+ Ab(b,"_emval_take_value");b=b.readValueFromPointer(a);return Q(b)},v:function(){ta("")},p:function(b){var a=D.length;b>>>=0;if(2147483648<b)return!1;for(var c=1;4>=c;c*=2){var d=a*(1+.2/c);d=Math.min(d,b+100663296);d=Math.max(b,d);0<d%65536&&(d+=65536-d%65536);a:{try{za.grow(Math.min(2147483648,d)-Na.byteLength+65535>>>16);Ra();var e=1;break a}catch(f){}e=void 0}if(e)return!0}return!1},C:function(){return 0},y:function(){},B:function(b,a,c,d){for(var e=0,f=0;f<c;f++){var n=J[a>>2],g=J[a+4>>2];a+=
121
121
  8;for(var m=0;m<g;m++){var h=D[n+m],p=uc[b];0===h||10===h?((1===b?ua:va)(Ca(p,0)),p.length=0):p.push(h)}e+=g}J[d>>2]=e;return 0},A:function(){}};
122
122
  (function(){function b(e){k.asm=e.exports;za=k.asm.N;Ra();Sa=k.asm.T;Ua.unshift(k.asm.O);Xa--;k.monitorRunDependencies&&k.monitorRunDependencies(Xa);0==Xa&&(null!==Ya&&(clearInterval(Ya),Ya=null),Za&&(e=Za,Za=null,e()))}function a(e){b(e.instance)}function c(e){return cb().then(function(f){return WebAssembly.instantiate(f,d)}).then(function(f){return f}).then(e,function(f){va("failed to asynchronously prepare wasm: "+f);ta(f)})}var d={a:yc};Xa++;k.monitorRunDependencies&&k.monitorRunDependencies(Xa);
123
123
  if(k.instantiateWasm)try{return k.instantiateWasm(d,b)}catch(e){return va("Module.instantiateWasm callback failed with error: "+e),!1}(function(){return ya||"function"!==typeof WebAssembly.instantiateStreaming||$a()||M.startsWith("file://")||"function"!==typeof fetch?c(a):fetch(M,{credentials:"same-origin"}).then(function(e){return WebAssembly.instantiateStreaming(e,d).then(a,function(f){va("wasm streaming compile failed: "+f);va("falling back to ArrayBuffer instantiation");return c(a)})})})().catch(ba);
@@ -137,7 +137,7 @@ k.run=Bc;if(k.preInit)for("function"==typeof k.preInit&&(k.preInit=[k.preInit]);
137
137
  /* 2 */
138
138
  /***/ ((module) => {
139
139
 
140
- module.exports = JSON.parse('{"name":"@rive-app/canvas","version":"1.0.72","description":"Rive\'s canvas 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.js.map","rive.wasm","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
140
+ module.exports = JSON.parse('{"name":"@rive-app/canvas","version":"1.0.75","description":"Rive\'s canvas 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.js.map","rive.wasm","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
141
141
 
142
142
  /***/ }),
143
143
  /* 3 */
@@ -173,56 +173,69 @@ const registerTouchInteractions = ({
173
173
  alignment,
174
174
  }) => {
175
175
  if (!canvas || !stateMachines.length || !renderer || !rive || !artboard) {
176
- return;
176
+ return null;
177
177
  }
178
178
 
179
- const mouseCallback = (event) => {
180
- const boundingRect = event.currentTarget.getBoundingClientRect();
179
+ const mouseCallback = (event) => {
180
+ const boundingRect = event.currentTarget.getBoundingClientRect();
181
181
 
182
- const canvasX = event.clientX - boundingRect.left;
183
- const canvasY = event.clientY - boundingRect.top;
184
- const forwardMatrix = rive.computeAlignment(fit, alignment, {
182
+ const canvasX = event.clientX - boundingRect.left;
183
+ const canvasY = event.clientY - boundingRect.top;
184
+ const forwardMatrix = rive.computeAlignment(
185
+ fit,
186
+ alignment,
187
+ {
185
188
  minX: 0,
186
189
  minY: 0,
187
190
  maxX: boundingRect.width,
188
191
  maxY: boundingRect.height,
189
- }, artboard.bounds);
190
- let invertedMatrix = new rive.Mat2D();
191
- forwardMatrix.invert(invertedMatrix);
192
- const canvasCoordinatesVector = new rive.Vec2D(canvasX, canvasY);
193
- const transformedVector = rive.mapXY(invertedMatrix, canvasCoordinatesVector);
194
- const transformedX = transformedVector.x();
195
- const transformedY = transformedVector.y();
192
+ },
193
+ artboard.bounds
194
+ );
195
+ let invertedMatrix = new rive.Mat2D();
196
+ forwardMatrix.invert(invertedMatrix);
197
+ const canvasCoordinatesVector = new rive.Vec2D(canvasX, canvasY);
198
+ const transformedVector = rive.mapXY(
199
+ invertedMatrix,
200
+ canvasCoordinatesVector
201
+ );
202
+ const transformedX = transformedVector.x();
203
+ const transformedY = transformedVector.y();
196
204
 
197
- switch (event.type) {
198
- // Pointer moving/hovering on the canvas
199
- case 'mousemove': {
200
- for (const stateMachine of stateMachines) {
201
- stateMachine.pointerMove(transformedX, transformedY);
202
- }
203
- break;
205
+ switch (event.type) {
206
+ // Pointer moving/hovering on the canvas
207
+ case 'mousemove': {
208
+ for (const stateMachine of stateMachines) {
209
+ stateMachine.pointerMove(transformedX, transformedY);
204
210
  }
205
- // Pointer click initiated but not released yet on the canvas
206
- case 'mousedown': {
207
- for (const stateMachine of stateMachines) {
208
- stateMachine.pointerDown(transformedX, transformedY);
209
- }
210
- break;
211
+ break;
212
+ }
213
+ // Pointer click initiated but not released yet on the canvas
214
+ case 'mousedown': {
215
+ for (const stateMachine of stateMachines) {
216
+ stateMachine.pointerDown(transformedX, transformedY);
211
217
  }
212
- // Pointer click released on the canvas
213
- case 'mouseup': {
214
- for (const stateMachine of stateMachines) {
215
- stateMachine.pointerUp(transformedX, transformedY);
216
- }
217
- break;
218
+ break;
219
+ }
220
+ // Pointer click released on the canvas
221
+ case 'mouseup': {
222
+ for (const stateMachine of stateMachines) {
223
+ stateMachine.pointerUp(transformedX, transformedY);
218
224
  }
219
- default:
225
+ break;
220
226
  }
221
- };
222
-
223
- canvas.addEventListener("mousemove", mouseCallback.bind(undefined));
224
- canvas.addEventListener("mousedown", mouseCallback.bind(undefined));
225
- canvas.addEventListener("mouseup", mouseCallback.bind(undefined));
227
+ default:
228
+ }
229
+ };
230
+ const callback = mouseCallback.bind(undefined);
231
+ canvas.addEventListener('mousemove', callback);
232
+ canvas.addEventListener('mousedown', callback);
233
+ canvas.addEventListener('mouseup', callback);
234
+ return () => {
235
+ canvas.removeEventListener('mousemove', callback);
236
+ canvas.removeEventListener('mousedown', callback);
237
+ canvas.removeEventListener('mouseup', callback);
238
+ };
226
239
  };
227
240
 
228
241
 
@@ -402,7 +415,7 @@ var Layout = /** @class */ (function () {
402
415
  minX: minX !== null && minX !== void 0 ? minX : this.minX,
403
416
  minY: minY !== null && minY !== void 0 ? minY : this.minY,
404
417
  maxX: maxX !== null && maxX !== void 0 ? maxX : this.maxX,
405
- maxY: maxY !== null && maxY !== void 0 ? maxY : this.maxY
418
+ maxY: maxY !== null && maxY !== void 0 ? maxY : this.maxY,
406
419
  });
407
420
  };
408
421
  // Returns fit for the Wasm runtime format
@@ -466,7 +479,7 @@ var RuntimeLoader = /** @class */ (function () {
466
479
  RuntimeLoader.loadRuntime = function () {
467
480
  _rive_advanced_mjs__WEBPACK_IMPORTED_MODULE_0__.default({
468
481
  // Loads Wasm bundle
469
- locateFile: function (_) { return RuntimeLoader.wasmURL; }
482
+ locateFile: function (_) { return RuntimeLoader.wasmURL; },
470
483
  }).then(function (rive) {
471
484
  var _a;
472
485
  RuntimeLoader.runtime = rive;
@@ -767,8 +780,8 @@ var Animator = /** @class */ (function () {
767
780
  animatables = mapToStringArray(animatables);
768
781
  // If animatables is empty, play or pause everything
769
782
  if (animatables.length === 0) {
770
- this.animations.forEach(function (a) { return a.playing = playing; });
771
- this.stateMachines.forEach(function (m) { return m.playing = playing; });
783
+ this.animations.forEach(function (a) { return (a.playing = playing); });
784
+ this.stateMachines.forEach(function (m) { return (m.playing = playing); });
772
785
  }
773
786
  else {
774
787
  // Play/pause already instanced items, or create new instances
@@ -834,11 +847,11 @@ var Animator = /** @class */ (function () {
834
847
  return this.add(animatables, true);
835
848
  };
836
849
  /**
837
- * Pauses named animations and state machines, or everything if nothing is
838
- * specified
839
- * @param animatables names of the animations and state machines to pause
840
- * @returns a list of names of the animations and state machines paused
841
- */
850
+ * Pauses named animations and state machines, or everything if nothing is
851
+ * specified
852
+ * @param animatables names of the animations and state machines to pause
853
+ * @returns a list of names of the animations and state machines paused
854
+ */
842
855
  Animator.prototype.pause = function (animatables) {
843
856
  return this.add(animatables, false);
844
857
  };
@@ -849,8 +862,10 @@ var Animator = /** @class */ (function () {
849
862
  * @returns a list of names of the animations that were scrubbed
850
863
  */
851
864
  Animator.prototype.scrub = function (animatables, value) {
852
- var forScrubbing = this.animations.filter(function (a) { return animatables.includes(a.name); });
853
- forScrubbing.forEach(function (a) { return a.scrubTo = value; });
865
+ var forScrubbing = this.animations.filter(function (a) {
866
+ return animatables.includes(a.name);
867
+ });
868
+ forScrubbing.forEach(function (a) { return (a.scrubTo = value); });
854
869
  return forScrubbing.map(function (a) { return a.name; });
855
870
  };
856
871
  Object.defineProperty(Animator.prototype, "playing", {
@@ -859,7 +874,10 @@ var Animator = /** @class */ (function () {
859
874
  * playing
860
875
  */
861
876
  get: function () {
862
- return this.animations.filter(function (a) { return a.playing; }).map(function (a) { return a.name; }).concat(this.stateMachines.filter(function (m) { return m.playing; }).map(function (m) { return m.name; }));
877
+ return this.animations
878
+ .filter(function (a) { return a.playing; })
879
+ .map(function (a) { return a.name; })
880
+ .concat(this.stateMachines.filter(function (m) { return m.playing; }).map(function (m) { return m.name; }));
863
881
  },
864
882
  enumerable: false,
865
883
  configurable: true
@@ -870,7 +888,10 @@ var Animator = /** @class */ (function () {
870
888
  * paused
871
889
  */
872
890
  get: function () {
873
- return this.animations.filter(function (a) { return !a.playing; }).map(function (a) { return a.name; }).concat(this.stateMachines.filter(function (m) { return !m.playing; }).map(function (m) { return m.name; }));
891
+ return this.animations
892
+ .filter(function (a) { return !a.playing; })
893
+ .map(function (a) { return a.name; })
894
+ .concat(this.stateMachines.filter(function (m) { return !m.playing; }).map(function (m) { return m.name; }));
874
895
  },
875
896
  enumerable: false,
876
897
  configurable: true
@@ -887,7 +908,9 @@ var Animator = /** @class */ (function () {
887
908
  var removedNames = [];
888
909
  // Stop everything
889
910
  if (animatables.length === 0) {
890
- removedNames = this.animations.map(function (a) { return a.name; }).concat(this.stateMachines.map(function (m) { return m.name; }));
911
+ removedNames = this.animations
912
+ .map(function (a) { return a.name; })
913
+ .concat(this.stateMachines.map(function (m) { return m.name; }));
891
914
  // Clean up before emptying the arrays
892
915
  this.animations.forEach(function (a) { return a.cleanup(); });
893
916
  this.stateMachines.forEach(function (m) { return m.cleanup(); });
@@ -897,17 +920,23 @@ var Animator = /** @class */ (function () {
897
920
  }
898
921
  else {
899
922
  // Remove only the named animations/state machines
900
- var animationsToRemove = this.animations.filter(function (a) { return animatables.includes(a.name); });
923
+ var animationsToRemove = this.animations.filter(function (a) {
924
+ return animatables.includes(a.name);
925
+ });
901
926
  animationsToRemove.forEach(function (a) {
902
927
  a.cleanup();
903
928
  _this.animations.splice(_this.animations.indexOf(a), 1);
904
929
  });
905
- var machinesToRemove = this.stateMachines.filter(function (m) { return animatables.includes(m.name); });
930
+ var machinesToRemove = this.stateMachines.filter(function (m) {
931
+ return animatables.includes(m.name);
932
+ });
906
933
  machinesToRemove.forEach(function (m) {
907
934
  m.cleanup();
908
935
  _this.stateMachines.splice(_this.stateMachines.indexOf(m), 1);
909
936
  });
910
- removedNames = animationsToRemove.map(function (a) { return a.name; }).concat(machinesToRemove.map(function (m) { return m.name; }));
937
+ removedNames = animationsToRemove
938
+ .map(function (a) { return a.name; })
939
+ .concat(machinesToRemove.map(function (m) { return m.name; }));
911
940
  }
912
941
  this.eventManager.fire({
913
942
  type: EventType.Stop,
@@ -921,8 +950,8 @@ var Animator = /** @class */ (function () {
921
950
  * Returns true if at least one animation is active
922
951
  */
923
952
  get: function () {
924
- return this.animations.reduce(function (acc, curr) { return acc || curr.playing; }, false)
925
- || this.stateMachines.reduce(function (acc, curr) { return acc || curr.playing; }, false);
953
+ return (this.animations.reduce(function (acc, curr) { return acc || curr.playing; }, false) ||
954
+ this.stateMachines.reduce(function (acc, curr) { return acc || curr.playing; }, false));
926
955
  },
927
956
  enumerable: false,
928
957
  configurable: true
@@ -932,8 +961,8 @@ var Animator = /** @class */ (function () {
932
961
  * Returns true if all animations are paused and there's at least one animation
933
962
  */
934
963
  get: function () {
935
- return !this.isPlaying &&
936
- (this.animations.length > 0 || this.stateMachines.length > 0);
964
+ return (!this.isPlaying &&
965
+ (this.animations.length > 0 || this.stateMachines.length > 0));
937
966
  },
938
967
  enumerable: false,
939
968
  configurable: true
@@ -958,11 +987,11 @@ var Animator = /** @class */ (function () {
958
987
  if (this.animations.length === 0 && this.stateMachines.length === 0) {
959
988
  if (this.artboard.animationCount() > 0) {
960
989
  // Add the first animation
961
- this.add([instancedName = this.artboard.animationByIndex(0).name], playing, fireEvent);
990
+ this.add([(instancedName = this.artboard.animationByIndex(0).name)], playing, fireEvent);
962
991
  }
963
992
  else if (this.artboard.stateMachineCount() > 0) {
964
993
  // Add the first state machine
965
- this.add([instancedName = this.artboard.stateMachineByIndex(0).name], playing, fireEvent);
994
+ this.add([(instancedName = this.artboard.stateMachineByIndex(0).name)], playing, fireEvent);
966
995
  }
967
996
  }
968
997
  return instancedName;
@@ -982,7 +1011,7 @@ var Animator = /** @class */ (function () {
982
1011
  else if (animation.loopValue === 1 && animation.loopCount) {
983
1012
  this.eventManager.fire({
984
1013
  type: EventType.Loop,
985
- data: { animation: animation.name, type: LoopType.Loop }
1014
+ data: { animation: animation.name, type: LoopType.Loop },
986
1015
  });
987
1016
  animation.loopCount = 0;
988
1017
  }
@@ -992,7 +1021,7 @@ var Animator = /** @class */ (function () {
992
1021
  else if (animation.loopValue === 2 && animation.loopCount > 1) {
993
1022
  this.eventManager.fire({
994
1023
  type: EventType.Loop,
995
- data: { animation: animation.name, type: LoopType.PingPong }
1024
+ data: { animation: animation.name, type: LoopType.PingPong },
996
1025
  });
997
1026
  animation.loopCount = 0;
998
1027
  }
@@ -1040,7 +1069,7 @@ var LoopType;
1040
1069
  (function (LoopType) {
1041
1070
  LoopType["OneShot"] = "oneshot";
1042
1071
  LoopType["Loop"] = "loop";
1043
- LoopType["PingPong"] = "pingpong"; // has value 2 in runtime
1072
+ LoopType["PingPong"] = "pingpong";
1044
1073
  })(LoopType || (LoopType = {}));
1045
1074
  // Manages Rive events and listeners
1046
1075
  var EventManager = /** @class */ (function () {
@@ -1144,6 +1173,8 @@ var Rive = /** @class */ (function () {
1144
1173
  this.readyForPlaying = false;
1145
1174
  // Runtime artboard
1146
1175
  this.artboard = null;
1176
+ // place to clear up event listeners
1177
+ this.eventCleanup = null;
1147
1178
  // Durations to generate a frame for the last second. Used for performance profiling.
1148
1179
  this.durations = [];
1149
1180
  this.frameTimes = [];
@@ -1224,7 +1255,8 @@ var Rive = /** @class */ (function () {
1224
1255
  this.loaded = false;
1225
1256
  this.readyForPlaying = false;
1226
1257
  // Ensure the runtime is loaded
1227
- RuntimeLoader.awaitInstance().then(function (runtime) {
1258
+ RuntimeLoader.awaitInstance()
1259
+ .then(function (runtime) {
1228
1260
  _this.runtime = runtime;
1229
1261
  // Get the canvas where you want to render the animation and create a renderer
1230
1262
  _this.renderer = _this.runtime.makeRenderer(_this.canvas, useOffscreenRenderer);
@@ -1238,7 +1270,7 @@ var Rive = /** @class */ (function () {
1238
1270
  var activeStateMachineInstances = (_this.animator.stateMachines || [])
1239
1271
  .filter(function (sm) { return sm.playing; })
1240
1272
  .map(function (sm) { return sm.instance; });
1241
- (0,_utils__WEBPACK_IMPORTED_MODULE_2__.registerTouchInteractions)({
1273
+ _this.eventCleanup = (0,_utils__WEBPACK_IMPORTED_MODULE_2__.registerTouchInteractions)({
1242
1274
  canvas: _this.canvas,
1243
1275
  artboard: _this.artboard,
1244
1276
  stateMachines: activeStateMachineInstances,
@@ -1251,7 +1283,8 @@ var Rive = /** @class */ (function () {
1251
1283
  .catch(function (e) {
1252
1284
  console.error(e);
1253
1285
  });
1254
- }).catch(function (e) {
1286
+ })
1287
+ .catch(function (e) {
1255
1288
  console.error(e);
1256
1289
  });
1257
1290
  };
@@ -1283,7 +1316,7 @@ var Rive = /** @class */ (function () {
1283
1316
  this.loaded = true;
1284
1317
  this.eventManager.fire({
1285
1318
  type: EventType.Load,
1286
- data: (_a = this.src) !== null && _a !== void 0 ? _a : 'buffer'
1319
+ data: (_a = this.src) !== null && _a !== void 0 ? _a : 'buffer',
1287
1320
  });
1288
1321
  // Flag ready for playback commands and clear the task queue; this order
1289
1322
  // is important or it may infinitely recurse
@@ -1306,9 +1339,9 @@ var Rive = /** @class */ (function () {
1306
1339
  // Initialize for playback
1307
1340
  Rive.prototype.initArtboard = function (artboardName, animationNames, stateMachineNames, autoplay) {
1308
1341
  // Fetch the artboard
1309
- var rootArtboard = artboardName ?
1310
- this.file.artboardByName(artboardName) :
1311
- this.file.defaultArtboard();
1342
+ var rootArtboard = artboardName
1343
+ ? this.file.artboardByName(artboardName)
1344
+ : this.file.defaultArtboard();
1312
1345
  // Check we have a working artboard
1313
1346
  if (!rootArtboard) {
1314
1347
  var msg = 'Invalid artboard name or no default artboard';
@@ -1343,7 +1376,7 @@ var Rive = /** @class */ (function () {
1343
1376
  event: {
1344
1377
  type: autoplay ? EventType.Play : EventType.Pause,
1345
1378
  data: instanceNames,
1346
- }
1379
+ },
1347
1380
  });
1348
1381
  };
1349
1382
  // Draws the current artboard frame
@@ -1363,7 +1396,7 @@ var Rive = /** @class */ (function () {
1363
1396
  this.lastRenderTime = time;
1364
1397
  }
1365
1398
  // Handle the onSecond callback
1366
- this.renderSecondTimer += (time - this.lastRenderTime);
1399
+ this.renderSecondTimer += time - this.lastRenderTime;
1367
1400
  if (this.renderSecondTimer > 5000) {
1368
1401
  this.renderSecondTimer = 0;
1369
1402
  onSecond === null || onSecond === void 0 ? void 0 : onSecond();
@@ -1374,10 +1407,11 @@ var Rive = /** @class */ (function () {
1374
1407
  // - Advance non-paused animations by the elapsed number of seconds
1375
1408
  // - Advance any animations that require scrubbing
1376
1409
  // - Advance to the first frame even when autoplay is false
1377
- var activeAnimations = this.animator.animations.filter(function (a) { return a.playing || a.needsScrub; })
1410
+ var activeAnimations = this.animator.animations
1411
+ .filter(function (a) { return a.playing || a.needsScrub; })
1378
1412
  // The scrubbed animations must be applied first to prevent weird artifacts
1379
1413
  // if the playing animations conflict with the scrubbed animating attribuates.
1380
- .sort(function (first, second) { return first.needsScrub ? -1 : 1; });
1414
+ .sort(function (first, second) { return (first.needsScrub ? -1 : 1); });
1381
1415
  for (var _i = 0, activeAnimations_1 = activeAnimations; _i < activeAnimations_1.length; _i++) {
1382
1416
  var animation = activeAnimations_1[_i];
1383
1417
  animation.advance(elapsedTime);
@@ -1447,7 +1481,7 @@ var Rive = /** @class */ (function () {
1447
1481
  minX: _layout.minX,
1448
1482
  minY: _layout.minY,
1449
1483
  maxX: _layout.maxX,
1450
- maxY: _layout.maxY
1484
+ maxY: _layout.maxY,
1451
1485
  }, artboard.bounds);
1452
1486
  };
1453
1487
  Object.defineProperty(Rive.prototype, "fps", {
@@ -1475,6 +1509,9 @@ var Rive = /** @class */ (function () {
1475
1509
  * might happen.
1476
1510
  */
1477
1511
  Rive.prototype.cleanup = function () {
1512
+ if (this.eventCleanup !== null) {
1513
+ this.eventCleanup();
1514
+ }
1478
1515
  this.artboard.delete();
1479
1516
  // TODO: delete animation and state machine instances
1480
1517
  };
@@ -1553,6 +1590,7 @@ var Rive = /** @class */ (function () {
1553
1590
  this.cleanup();
1554
1591
  // Reinitialize an artboard instance with the state
1555
1592
  this.initArtboard(artBoardName, animationNames, stateMachineNames, autoplay);
1593
+ this.taskQueue.process();
1556
1594
  };
1557
1595
  // Loads a new Rive file, keeping listeners in place
1558
1596
  Rive.prototype.load = function (params) {
@@ -1593,7 +1631,7 @@ var Rive = /** @class */ (function () {
1593
1631
  minX: 0,
1594
1632
  minY: 0,
1595
1633
  maxX: this.canvas.width,
1596
- maxY: this.canvas.height
1634
+ maxY: this.canvas.height,
1597
1635
  });
1598
1636
  };
1599
1637
  /**
@@ -1699,9 +1737,7 @@ var Rive = /** @class */ (function () {
1699
1737
  if (!this.loaded) {
1700
1738
  return [];
1701
1739
  }
1702
- return this.animator.animations
1703
- .filter(function (a) { return a.playing; })
1704
- .map(function (a) { return a.name; });
1740
+ return this.animator.animations.filter(function (a) { return a.playing; }).map(function (a) { return a.name; });
1705
1741
  },
1706
1742
  enumerable: false,
1707
1743
  configurable: true
@@ -1887,7 +1923,10 @@ var Rive = /** @class */ (function () {
1887
1923
  var input = instance.input(l);
1888
1924
  inputContents.push({ name: input.name, type: input.type });
1889
1925
  }
1890
- artboardContents.stateMachines.push({ name: name_1, inputs: inputContents });
1926
+ artboardContents.stateMachines.push({
1927
+ name: name_1,
1928
+ inputs: inputContents,
1929
+ });
1891
1930
  }
1892
1931
  riveContents.artboards.push(artboardContents);
1893
1932
  }