@rive-app/webgl2 2.37.2 → 2.37.4

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.37.2",
3
+ "version": "2.37.4",
4
4
  "description": "Rive's webgl2 based web api.",
5
5
  "main": "rive.js",
6
6
  "homepage": "https://rive.app",
package/rive.js CHANGED
@@ -746,7 +746,7 @@ function Na(a, b) {
746
746
  return Ma(c, a, b);
747
747
  }));
748
748
  }
749
- var Oa, Pa, Ta = {564429:(a, b, c, d, e) => {
749
+ var Oa, Pa, Ta = {564701:(a, b, c, d, e) => {
750
750
  if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
751
751
  return 0;
752
752
  }
@@ -809,11 +809,11 @@ var Oa, Pa, Ta = {564429:(a, b, c, d, e) => {
809
809
  }
810
810
  window.h.Ea += 1;
811
811
  return 1;
812
- }, 566607:() => {
812
+ }, 566879:() => {
813
813
  "undefined" !== typeof window.h && (window.h.Xa.map(function(a) {
814
814
  document.removeEventListener(a, window.h.unlock, !0);
815
815
  }), --window.h.Ea, 0 === window.h.Ea && delete window.h);
816
- }, 566911:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 567015:() => {
816
+ }, 567183:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 567287:() => {
817
817
  try {
818
818
  var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
819
819
  a.close();
@@ -821,7 +821,7 @@ var Oa, Pa, Ta = {564429:(a, b, c, d, e) => {
821
821
  } catch (c) {
822
822
  return 0;
823
823
  }
824
- }, 567186:(a, b, c, d, e, f) => {
824
+ }, 567458:(a, b, c, d, e, f) => {
825
825
  if ("undefined" === typeof window.h) {
826
826
  return -1;
827
827
  }
@@ -867,7 +867,7 @@ var Oa, Pa, Ta = {564429:(a, b, c, d, e) => {
867
867
  a == window.h.I.Ba && g.Y.connect(g.K.destination);
868
868
  g.nb = f;
869
869
  return window.h.lc(g);
870
- }, 570063:a => window.h.sa(a).K.sampleRate, 570136:a => {
870
+ }, 570335:a => window.h.sa(a).K.sampleRate, 570408:a => {
871
871
  a = window.h.sa(a);
872
872
  void 0 !== a.Y && (a.Y.onaudioprocess = function() {
873
873
  }, a.Y.disconnect(), a.Y = void 0);
@@ -875,13 +875,13 @@ var Oa, Pa, Ta = {564429:(a, b, c, d, e) => {
875
875
  a.K.close();
876
876
  a.K = void 0;
877
877
  a.nb = void 0;
878
- }, 570536:a => {
878
+ }, 570808:a => {
879
879
  window.h.yb(a);
880
- }, 570586:a => {
880
+ }, 570858:a => {
881
881
  a = window.h.sa(a);
882
882
  a.K.resume();
883
883
  a.state = window.h.ha.ub;
884
- }, 570725:a => {
884
+ }, 570997:a => {
885
885
  a = window.h.sa(a);
886
886
  a.K.suspend();
887
887
  a.state = window.h.ha.stopped;
@@ -3863,7 +3863,7 @@ moduleRtn = ca;
3863
3863
  /* 5 */
3864
3864
  /***/ ((module) => {
3865
3865
 
3866
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl2","version":"2.37.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","runtimeLoader.d.ts","utils"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
3866
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl2","version":"2.37.4","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","runtimeLoader.d.ts","utils"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
3867
3867
 
3868
3868
  /***/ }),
3869
3869
  /* 6 */
@@ -3907,60 +3907,70 @@ __webpack_require__.r(__webpack_exports__);
3907
3907
  /* harmony export */ });
3908
3908
  var _this = undefined;
3909
3909
  /**
3910
- * Returns the clientX and clientY properties from touch or mouse events. Also
3911
- * calls preventDefault() on the event if it is a touchstart or touchmove to prevent
3912
- * scrolling the page on mobile devices
3913
- * @param event - Either a TouchEvent or a MouseEvent
3914
- * @returns - Coordinates of the clientX and clientY properties from the touch/mouse event
3910
+ * Extracts ClientCoordinates from a TouchList, respecting multi-touch vs.
3911
+ * single-touch mode. In single-touch mode, only the touch matching
3912
+ * primaryTouchId is returned (or the first touch when primaryTouchId is null).
3915
3913
  */
3916
- var getClientCoordinates = function (event, isTouchScrollEnabled, enableMultiTouch) {
3917
- var _a, _b;
3914
+ var getTouchCoordinates = function (changedTouches, enableMultiTouch, primaryTouchId) {
3915
+ var _a;
3918
3916
  var coordinates = [];
3919
- if (["touchstart", "touchmove"].indexOf(event.type) > -1 &&
3920
- ((_a = event.changedTouches) === null || _a === void 0 ? void 0 : _a.length)) {
3921
- // This flag, if false, prevents touch events on the canvas default behavior
3922
- // which may prevent scrolling if a drag motion on the canvas is performed
3923
- if (!isTouchScrollEnabled) {
3924
- event.preventDefault();
3925
- }
3926
- var cnt = 0;
3927
- var totalTouches = enableMultiTouch
3928
- ? event.changedTouches.length
3929
- : 1;
3930
- while (cnt < totalTouches) {
3931
- var touch = event.changedTouches[cnt];
3917
+ if (enableMultiTouch) {
3918
+ for (var i = 0; i < changedTouches.length; i++) {
3919
+ var touch = changedTouches[i];
3932
3920
  coordinates.push({
3933
3921
  clientX: touch.clientX,
3934
3922
  clientY: touch.clientY,
3935
3923
  identifier: touch.identifier,
3936
3924
  });
3937
- cnt++;
3938
3925
  }
3939
3926
  }
3940
- else if (event.type === "touchend" &&
3941
- ((_b = event.changedTouches) === null || _b === void 0 ? void 0 : _b.length)) {
3942
- var cnt = 0;
3943
- var totalTouches = enableMultiTouch
3944
- ? event.changedTouches.length
3945
- : 1;
3946
- while (cnt < totalTouches) {
3947
- var touch = event.changedTouches[cnt];
3927
+ else {
3928
+ // In "single-touch mode", only track the primary finger identified at touchstart.
3929
+ // Search changedTouches for the touch matching the recorded primary touch identifier, or (on initial touchstart)
3930
+ // take the first available touch identifier.
3931
+ var primaryTouch = primaryTouchId !== null
3932
+ ? (_a = Array.from(changedTouches).find(function (t) { return t.identifier === primaryTouchId; })) !== null && _a !== void 0 ? _a : null
3933
+ : changedTouches[0];
3934
+ if (primaryTouch) {
3948
3935
  coordinates.push({
3949
- clientX: touch.clientX,
3950
- clientY: touch.clientY,
3951
- identifier: touch.identifier,
3936
+ clientX: primaryTouch.clientX,
3937
+ clientY: primaryTouch.clientY,
3938
+ identifier: primaryTouch.identifier,
3952
3939
  });
3953
- cnt++;
3954
3940
  }
3955
3941
  }
3956
- else {
3957
- coordinates.push({
3942
+ return coordinates;
3943
+ };
3944
+ /**
3945
+ * Returns the clientX and clientY properties from touch or mouse events. Also
3946
+ * calls preventDefault() on the event if it is a touchstart or touchmove to prevent
3947
+ * scrolling the page on mobile devices
3948
+ * @param event - Either a TouchEvent or a MouseEvent
3949
+ * @param isTouchScrollEnabled - Whether touch scrolling is enabled
3950
+ * @param enableMultiTouch - Whether to process multiple simultaneous touches
3951
+ * @param primaryTouchId - When working with single touches, only process the touch
3952
+ * with this identifier. Pass null to accept any touch (used during touchstart to
3953
+ * capture the first finger down).
3954
+ * @returns - Coordinates of the clientX and clientY properties from the touch/mouse event
3955
+ */
3956
+ var getClientCoordinates = function (event, isTouchScrollEnabled, enableMultiTouch, primaryTouchId) {
3957
+ var _a;
3958
+ var touchEvent = event;
3959
+ if ((_a = touchEvent.changedTouches) === null || _a === void 0 ? void 0 : _a.length) {
3960
+ // This flag, if false, prevents touch events on the canvas default behavior
3961
+ // which may prevent scrolling if a drag motion on the canvas is performed
3962
+ if (!isTouchScrollEnabled && ["touchstart", "touchmove"].includes(event.type)) {
3963
+ event.preventDefault();
3964
+ }
3965
+ return getTouchCoordinates(touchEvent.changedTouches, enableMultiTouch, primaryTouchId);
3966
+ }
3967
+ return [
3968
+ {
3958
3969
  clientX: event.clientX,
3959
3970
  clientY: event.clientY,
3960
3971
  identifier: 0,
3961
- });
3962
- }
3963
- return coordinates;
3972
+ },
3973
+ ];
3964
3974
  };
3965
3975
  /**
3966
3976
  * Registers mouse move/up/down callback handlers on the canvas to send meaningful coordinates to
@@ -3992,7 +4002,15 @@ var registerTouchInteractions = function (_a) {
3992
4002
  **/
3993
4003
  var _prevEventType = null;
3994
4004
  var _syntheticEventsActive = false;
4005
+ /**
4006
+ * When enableMultiTouch is false ("single-touch mode"), we track the identifier of the first finger that touched down.
4007
+ * All subsequent touch events are filtered to this identifier so that a second finger
4008
+ * moving cannot displace the tracked pointer position.
4009
+ * Reset to null when the primary finger lifts (or touchcancel is called)
4010
+ */
4011
+ var _primaryTouchId = null;
3995
4012
  var processEventCallback = function (event) {
4013
+ var _a;
3996
4014
  // Exit early out of all synthetic mouse events
3997
4015
  // https://stackoverflow.com/questions/9656990/how-to-prevent-simulated-mouse-events-in-mobile-browsers
3998
4016
  // https://stackoverflow.com/questions/25572070/javascript-touchend-versus-click-dilemma
@@ -4011,7 +4029,15 @@ var registerTouchInteractions = function (_a) {
4011
4029
  _prevEventType === "touchstart";
4012
4030
  _prevEventType = event.type;
4013
4031
  var boundingRect = event.currentTarget.getBoundingClientRect();
4014
- var coordinateSets = getClientCoordinates(event, isTouchScrollEnabled, enableMultiTouch);
4032
+ // On touchstart in single-touch mode, record the first new finger as the primary
4033
+ // touch if we aren't already tracking one.
4034
+ if (!enableMultiTouch && event.type === "touchstart" && _primaryTouchId === null) {
4035
+ var firstTouch = (_a = event.changedTouches) === null || _a === void 0 ? void 0 : _a[0];
4036
+ if (firstTouch) {
4037
+ _primaryTouchId = firstTouch.identifier;
4038
+ }
4039
+ }
4040
+ var coordinateSets = getClientCoordinates(event, isTouchScrollEnabled, enableMultiTouch, enableMultiTouch ? null : _primaryTouchId);
4015
4041
  var forwardMatrix = rive.computeAlignment(fit, alignment, {
4016
4042
  minX: 0,
4017
4043
  minY: 0,
@@ -4076,8 +4102,8 @@ var registerTouchInteractions = function (_a) {
4076
4102
  stateMachine.pointerMove(coordinateSet.transformedX, coordinateSet.transformedY, coordinateSet.identifier);
4077
4103
  });
4078
4104
  };
4079
- for (var _a = 0, stateMachines_2 = stateMachines; _a < stateMachines_2.length; _a++) {
4080
- var stateMachine = stateMachines_2[_a];
4105
+ for (var _b = 0, stateMachines_2 = stateMachines; _b < stateMachines_2.length; _b++) {
4106
+ var stateMachine = stateMachines_2[_b];
4081
4107
  _loop_2(stateMachine);
4082
4108
  }
4083
4109
  break;
@@ -4090,8 +4116,8 @@ var registerTouchInteractions = function (_a) {
4090
4116
  stateMachine.pointerDown(coordinateSet.transformedX, coordinateSet.transformedY, coordinateSet.identifier);
4091
4117
  });
4092
4118
  };
4093
- for (var _b = 0, stateMachines_3 = stateMachines; _b < stateMachines_3.length; _b++) {
4094
- var stateMachine = stateMachines_3[_b];
4119
+ for (var _c = 0, stateMachines_3 = stateMachines; _c < stateMachines_3.length; _c++) {
4120
+ var stateMachine = stateMachines_3[_c];
4095
4121
  _loop_3(stateMachine);
4096
4122
  }
4097
4123
  break;
@@ -4104,10 +4130,16 @@ var registerTouchInteractions = function (_a) {
4104
4130
  stateMachine.pointerExit(coordinateSet.transformedX, coordinateSet.transformedY, coordinateSet.identifier);
4105
4131
  });
4106
4132
  };
4107
- for (var _c = 0, stateMachines_4 = stateMachines; _c < stateMachines_4.length; _c++) {
4108
- var stateMachine = stateMachines_4[_c];
4133
+ for (var _d = 0, stateMachines_4 = stateMachines; _d < stateMachines_4.length; _d++) {
4134
+ var stateMachine = stateMachines_4[_d];
4109
4135
  _loop_4(stateMachine);
4110
4136
  }
4137
+ // Release the primary touch lock once that finger lifts so the next
4138
+ // touchstart can claim a new primary finger.
4139
+ if (!enableMultiTouch &&
4140
+ coordinateSets.some(function (c) { return c.identifier === _primaryTouchId; })) {
4141
+ _primaryTouchId = null;
4142
+ }
4111
4143
  break;
4112
4144
  }
4113
4145
  case "mouseup": {
@@ -4116,8 +4148,8 @@ var registerTouchInteractions = function (_a) {
4116
4148
  stateMachine.pointerUp(coordinateSet.transformedX, coordinateSet.transformedY, coordinateSet.identifier);
4117
4149
  });
4118
4150
  };
4119
- for (var _d = 0, stateMachines_5 = stateMachines; _d < stateMachines_5.length; _d++) {
4120
- var stateMachine = stateMachines_5[_d];
4151
+ for (var _e = 0, stateMachines_5 = stateMachines; _e < stateMachines_5.length; _e++) {
4152
+ var stateMachine = stateMachines_5[_e];
4121
4153
  _loop_5(stateMachine);
4122
4154
  }
4123
4155
  break;
@@ -4125,6 +4157,9 @@ var registerTouchInteractions = function (_a) {
4125
4157
  default:
4126
4158
  }
4127
4159
  };
4160
+ var touchCancelCallback = function () {
4161
+ _primaryTouchId = null;
4162
+ };
4128
4163
  var callback = processEventCallback.bind(_this);
4129
4164
  canvas.addEventListener("mouseover", callback);
4130
4165
  canvas.addEventListener("mouseout", callback);
@@ -4138,6 +4173,7 @@ var registerTouchInteractions = function (_a) {
4138
4173
  passive: isTouchScrollEnabled,
4139
4174
  });
4140
4175
  canvas.addEventListener("touchend", callback);
4176
+ canvas.addEventListener("touchcancel", touchCancelCallback);
4141
4177
  return function () {
4142
4178
  canvas.removeEventListener("mouseover", callback);
4143
4179
  canvas.removeEventListener("mouseout", callback);
@@ -4147,6 +4183,7 @@ var registerTouchInteractions = function (_a) {
4147
4183
  canvas.removeEventListener("touchmove", callback);
4148
4184
  canvas.removeEventListener("touchstart", callback);
4149
4185
  canvas.removeEventListener("touchend", callback);
4186
+ canvas.removeEventListener("touchcancel", touchCancelCallback);
4150
4187
  };
4151
4188
  };
4152
4189