@rive-app/webgl2 2.13.0 → 2.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rive-app/webgl2",
3
- "version": "2.13.0",
3
+ "version": "2.13.2",
4
4
  "description": "Rive's webgl2 based web api.",
5
5
  "main": "rive.js",
6
6
  "homepage": "https://rive.app",
package/rive.d.ts CHANGED
@@ -5,6 +5,9 @@ export type { FileAsset, FontAsset, ImageAsset } from './rive_advanced.mjs';
5
5
  */
6
6
  export type VoidCallback = () => void;
7
7
  export type AssetLoadCallback = (asset: rc.FileAsset, bytes: Uint8Array) => Boolean;
8
+ interface SetupRiveListenersOptions {
9
+ isTouchScrollEnabled?: boolean;
10
+ }
8
11
  /**
9
12
  * Type for artboard bounds
10
13
  */
@@ -202,6 +205,12 @@ export interface RiveParameters {
202
205
  * will be attached to the <canvas> element
203
206
  */
204
207
  shouldDisableRiveListeners?: boolean;
208
+ /**
209
+ * For Rive Listeners, allows scrolling behavior to still occur on canvas elements
210
+ * when a touch/drag action is performed on touch-enabled devices. Otherwise,
211
+ * scroll behavior may be prevented on touch/drag actions on the canvas by default.
212
+ */
213
+ isTouchScrollEnabled?: boolean;
205
214
  /**
206
215
  * Enable Rive Events to be handled by the runtime. This means any special Rive Event may have
207
216
  * a side effect that takes place implicitly.
@@ -298,10 +307,21 @@ export declare class Rive {
298
307
  durations: number[];
299
308
  frameTimes: number[];
300
309
  frameCount: number;
310
+ isTouchScrollEnabled: boolean;
301
311
  constructor(params: RiveParameters);
302
312
  static new(params: RiveParameters): Rive;
303
313
  private init;
304
- private setupRiveListeners;
314
+ /**
315
+ * Setup Rive Listeners on the canvas
316
+ * @param riveListenerOptions - Enables TouchEvent events on the canvas. Set to true to allow
317
+ * touch scrolling on the canvas element on touch-enabled devices
318
+ * i.e. { isTouchScrollEnabled: true }
319
+ */
320
+ setupRiveListeners(riveListenerOptions?: SetupRiveListenersOptions): void;
321
+ /**
322
+ * Remove Rive Listeners setup on the canvas
323
+ */
324
+ removeRiveListeners(): void;
305
325
  private initData;
306
326
  private initArtboard;
307
327
  drawFrame(): void;
package/rive.js CHANGED
@@ -410,7 +410,7 @@ function Pa(a, b) {
410
410
  return Oa(c, a, b);
411
411
  }));
412
412
  }
413
- var J, K, Ta = {276936:(a, b, c, d, e) => {
413
+ var J, K, Ta = {473544:(a, b, c, d, e) => {
414
414
  if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
415
415
  return 0;
416
416
  }
@@ -473,9 +473,9 @@ var J, K, Ta = {276936:(a, b, c, d, e) => {
473
473
  }
474
474
  window.h.Da += 1;
475
475
  return 1;
476
- }, 279114:() => {
476
+ }, 475722:() => {
477
477
  "undefined" !== typeof window.h && (--window.h.Da, 0 === window.h.Da && delete window.h);
478
- }, 279278:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 279382:() => {
478
+ }, 475886:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 475990:() => {
479
479
  try {
480
480
  var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
481
481
  a.close();
@@ -483,7 +483,7 @@ var J, K, Ta = {276936:(a, b, c, d, e) => {
483
483
  } catch (c) {
484
484
  return 0;
485
485
  }
486
- }, 279553:(a, b, c, d, e, f) => {
486
+ }, 476161:(a, b, c, d, e, f) => {
487
487
  if ("undefined" === typeof window.h) {
488
488
  return -1;
489
489
  }
@@ -529,7 +529,7 @@ var J, K, Ta = {276936:(a, b, c, d, e) => {
529
529
  a == window.h.I.Ca && g.Z.connect(g.J.destination);
530
530
  g.kb = f;
531
531
  return window.h.tc(g);
532
- }, 282430:a => window.h.wa(a).J.sampleRate, 282503:a => {
532
+ }, 479038:a => window.h.wa(a).J.sampleRate, 479111:a => {
533
533
  a = window.h.wa(a);
534
534
  void 0 !== a.Z && (a.Z.onaudioprocess = function() {
535
535
  }, a.Z.disconnect(), a.Z = void 0);
@@ -537,13 +537,13 @@ var J, K, Ta = {276936:(a, b, c, d, e) => {
537
537
  a.J.close();
538
538
  a.J = void 0;
539
539
  a.kb = void 0;
540
- }, 282903:a => {
540
+ }, 479511:a => {
541
541
  window.h.xb(a);
542
- }, 282953:a => {
542
+ }, 479561:a => {
543
543
  a = window.h.wa(a);
544
544
  a.J.resume();
545
545
  a.state = window.h.ha.sb;
546
- }, 283092:a => {
546
+ }, 479700:a => {
547
547
  a = window.h.wa(a);
548
548
  a.J.suspend();
549
549
  a.state = window.h.ha.stopped;
@@ -3548,8 +3548,8 @@ n.dynCall_viijii = (a, b, c, d, e, f, g) => (n.dynCall_viijii = y.dynCall_viijii
3548
3548
  n.dynCall_iiiiij = (a, b, c, d, e, f, g) => (n.dynCall_iiiiij = y.dynCall_iiiiij)(a, b, c, d, e, f, g);
3549
3549
  n.dynCall_iiiiijj = (a, b, c, d, e, f, g, m, p) => (n.dynCall_iiiiijj = y.dynCall_iiiiijj)(a, b, c, d, e, f, g, m, p);
3550
3550
  n.dynCall_iiiiiijj = (a, b, c, d, e, f, g, m, p, l) => (n.dynCall_iiiiiijj = y.dynCall_iiiiiijj)(a, b, c, d, e, f, g, m, p, l);
3551
- n.___start_em_js = 274312;
3552
- n.___stop_em_js = 276936;
3551
+ n.___start_em_js = 470920;
3552
+ n.___stop_em_js = 473544;
3553
3553
  var $d;
3554
3554
  Ia = function ae() {
3555
3555
  $d || be();
@@ -3609,7 +3609,7 @@ be();
3609
3609
  /* 2 */
3610
3610
  /***/ ((module) => {
3611
3611
 
3612
- module.exports = JSON.parse('{"name":"@rive-app/webgl2","version":"2.13.0","description":"Rive\'s webgl2 based web api.","main":"rive.js","homepage":"https://rive.app","repository":{"type":"git","url":"https://github.com/rive-app/rive-wasm/tree/master/js"},"keywords":["rive","animation"],"author":"Rive","contributors":["Luigi Rosso <luigi@rive.app> (https://rive.app)","Maxwell Talbot <max@rive.app> (https://rive.app)","Arthur Vivian <arthur@rive.app> (https://rive.app)","Umberto Sonnino <umberto@rive.app> (https://rive.app)","Matthew Sullivan <matt.j.sullivan@gmail.com> (mailto:matt.j.sullivan@gmail.com)","Chris Dalton <chris@rive.app> (https://rive.app)"],"license":"MIT","files":["rive.js","rive.wasm","rive.js.map","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
3612
+ module.exports = JSON.parse('{"name":"@rive-app/webgl2","version":"2.13.2","description":"Rive\'s webgl2 based web api.","main":"rive.js","homepage":"https://rive.app","repository":{"type":"git","url":"https://github.com/rive-app/rive-wasm/tree/master/js"},"keywords":["rive","animation"],"author":"Rive","contributors":["Luigi Rosso <luigi@rive.app> (https://rive.app)","Maxwell Talbot <max@rive.app> (https://rive.app)","Arthur Vivian <arthur@rive.app> (https://rive.app)","Umberto Sonnino <umberto@rive.app> (https://rive.app)","Matthew Sullivan <matt.j.sullivan@gmail.com> (mailto:matt.j.sullivan@gmail.com)","Chris Dalton <chris@rive.app> (https://rive.app)"],"license":"MIT","files":["rive.js","rive.wasm","rive.js.map","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
3613
3613
 
3614
3614
  /***/ }),
3615
3615
  /* 3 */
@@ -3643,11 +3643,15 @@ var _this = undefined;
3643
3643
  * @param event - Either a TouchEvent or a MouseEvent
3644
3644
  * @returns - Coordinates of the clientX and clientY properties from the touch/mouse event
3645
3645
  */
3646
- var getClientCoordinates = function (event) {
3646
+ var getClientCoordinates = function (event, isTouchScrollEnabled) {
3647
3647
  var _a, _b;
3648
3648
  if (["touchstart", "touchmove"].indexOf(event.type) > -1 &&
3649
3649
  ((_a = event.touches) === null || _a === void 0 ? void 0 : _a.length)) {
3650
- event.preventDefault();
3650
+ // This flag, if false, prevents touch events on the canvas default behavior
3651
+ // which may prevent scrolling if a drag motion on the canvas is performed
3652
+ if (!isTouchScrollEnabled) {
3653
+ event.preventDefault();
3654
+ }
3651
3655
  return {
3652
3656
  clientX: event.touches[0].clientX,
3653
3657
  clientY: event.touches[0].clientY,
@@ -3672,7 +3676,7 @@ var getClientCoordinates = function (event) {
3672
3676
  * the state machine pointer move/up/down functions based on cursor interaction
3673
3677
  */
3674
3678
  var registerTouchInteractions = function (_a) {
3675
- var canvas = _a.canvas, artboard = _a.artboard, _b = _a.stateMachines, stateMachines = _b === void 0 ? [] : _b, renderer = _a.renderer, rive = _a.rive, fit = _a.fit, alignment = _a.alignment;
3679
+ var canvas = _a.canvas, artboard = _a.artboard, _b = _a.stateMachines, stateMachines = _b === void 0 ? [] : _b, renderer = _a.renderer, rive = _a.rive, fit = _a.fit, alignment = _a.alignment, _c = _a.isTouchScrollEnabled, isTouchScrollEnabled = _c === void 0 ? false : _c;
3676
3680
  if (!canvas ||
3677
3681
  !stateMachines.length ||
3678
3682
  !renderer ||
@@ -3683,7 +3687,7 @@ var registerTouchInteractions = function (_a) {
3683
3687
  }
3684
3688
  var processEventCallback = function (event) {
3685
3689
  var boundingRect = event.currentTarget.getBoundingClientRect();
3686
- var _a = getClientCoordinates(event), clientX = _a.clientX, clientY = _a.clientY;
3690
+ var _a = getClientCoordinates(event, isTouchScrollEnabled), clientX = _a.clientX, clientY = _a.clientY;
3687
3691
  if (!clientX && !clientY) {
3688
3692
  return;
3689
3693
  }
@@ -4869,6 +4873,7 @@ var Rive = /** @class */ (function () {
4869
4873
  this.durations = [];
4870
4874
  this.frameTimes = [];
4871
4875
  this.frameCount = 0;
4876
+ this.isTouchScrollEnabled = false;
4872
4877
  /**
4873
4878
  * Used be draw to track when a second of active rendering time has passed.
4874
4879
  * Used for debugging purposes
@@ -4879,6 +4884,7 @@ var Rive = /** @class */ (function () {
4879
4884
  this.buffer = params.buffer;
4880
4885
  this.layout = (_a = params.layout) !== null && _a !== void 0 ? _a : new Layout();
4881
4886
  this.shouldDisableRiveListeners = !!params.shouldDisableRiveListeners;
4887
+ this.isTouchScrollEnabled = !!params.isTouchScrollEnabled;
4882
4888
  this.automaticallyHandleEvents = !!params.automaticallyHandleEvents;
4883
4889
  this.enableRiveAssetCDN =
4884
4890
  params.enableRiveAssetCDN === undefined
@@ -4980,12 +4986,22 @@ var Rive = /** @class */ (function () {
4980
4986
  console.error(e);
4981
4987
  });
4982
4988
  };
4983
- Rive.prototype.setupRiveListeners = function () {
4989
+ /**
4990
+ * Setup Rive Listeners on the canvas
4991
+ * @param riveListenerOptions - Enables TouchEvent events on the canvas. Set to true to allow
4992
+ * touch scrolling on the canvas element on touch-enabled devices
4993
+ * i.e. { isTouchScrollEnabled: true }
4994
+ */
4995
+ Rive.prototype.setupRiveListeners = function (riveListenerOptions) {
4984
4996
  var _this = this;
4985
4997
  if (!this.shouldDisableRiveListeners) {
4986
4998
  var activeStateMachines = (this.animator.stateMachines || [])
4987
4999
  .filter(function (sm) { return sm.playing && _this.runtime.hasListeners(sm.instance); })
4988
5000
  .map(function (sm) { return sm.instance; });
5001
+ var touchScrollEnabledOption = this.isTouchScrollEnabled;
5002
+ if (riveListenerOptions && 'isTouchScrollEnabled' in riveListenerOptions) {
5003
+ touchScrollEnabledOption = riveListenerOptions.isTouchScrollEnabled;
5004
+ }
4989
5005
  this.eventCleanup = (0,_utils__WEBPACK_IMPORTED_MODULE_2__.registerTouchInteractions)({
4990
5006
  canvas: this.canvas,
4991
5007
  artboard: this.artboard,
@@ -4994,9 +5010,18 @@ var Rive = /** @class */ (function () {
4994
5010
  rive: this.runtime,
4995
5011
  fit: this._layout.runtimeFit(this.runtime),
4996
5012
  alignment: this._layout.runtimeAlignment(this.runtime),
5013
+ isTouchScrollEnabled: touchScrollEnabledOption,
4997
5014
  });
4998
5015
  }
4999
5016
  };
5017
+ /**
5018
+ * Remove Rive Listeners setup on the canvas
5019
+ */
5020
+ Rive.prototype.removeRiveListeners = function () {
5021
+ if (this.eventCleanup) {
5022
+ this.eventCleanup();
5023
+ }
5024
+ };
5000
5025
  // Initializes runtime with Rive data and preps for playing
5001
5026
  Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay) {
5002
5027
  var _a;