@rive-app/webgl 2.12.1 → 2.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rive-app/webgl",
3
- "version": "2.12.1",
3
+ "version": "2.12.2",
4
4
  "description": "Rive's webgl based web api.",
5
5
  "main": "rive.js",
6
6
  "homepage": "https://rive.app",
package/rive.d.ts CHANGED
@@ -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
@@ -395,7 +395,7 @@ function Ra(a, b) {
395
395
  return Qa(c, a, b);
396
396
  }));
397
397
  }
398
- var E, F, Va = {491468:(a, b, c, d, e) => {
398
+ var E, F, Va = {491948:(a, b, c, d, e) => {
399
399
  if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
400
400
  return 0;
401
401
  }
@@ -458,9 +458,9 @@ var E, F, Va = {491468:(a, b, c, d, e) => {
458
458
  }
459
459
  window.h.Ea += 1;
460
460
  return 1;
461
- }, 493646:() => {
461
+ }, 494126:() => {
462
462
  "undefined" !== typeof window.h && (--window.h.Ea, 0 === window.h.Ea && delete window.h);
463
- }, 493810:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 493914:() => {
463
+ }, 494290:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 494394:() => {
464
464
  try {
465
465
  var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
466
466
  a.close();
@@ -468,7 +468,7 @@ var E, F, Va = {491468:(a, b, c, d, e) => {
468
468
  } catch (c) {
469
469
  return 0;
470
470
  }
471
- }, 494085:(a, b, c, d, e, f) => {
471
+ }, 494565:(a, b, c, d, e, f) => {
472
472
  if ("undefined" === typeof window.h) {
473
473
  return -1;
474
474
  }
@@ -514,7 +514,7 @@ var E, F, Va = {491468:(a, b, c, d, e) => {
514
514
  a == window.h.H.Da && g.Y.connect(g.I.destination);
515
515
  g.mb = f;
516
516
  return window.h.vc(g);
517
- }, 496962:a => window.h.ua(a).I.sampleRate, 497035:a => {
517
+ }, 497442:a => window.h.ua(a).I.sampleRate, 497515:a => {
518
518
  a = window.h.ua(a);
519
519
  void 0 !== a.Y && (a.Y.onaudioprocess = function() {
520
520
  }, a.Y.disconnect(), a.Y = void 0);
@@ -522,13 +522,13 @@ var E, F, Va = {491468:(a, b, c, d, e) => {
522
522
  a.I.close();
523
523
  a.I = void 0;
524
524
  a.mb = void 0;
525
- }, 497435:a => {
525
+ }, 497915:a => {
526
526
  window.h.yb(a);
527
- }, 497485:a => {
527
+ }, 497965:a => {
528
528
  a = window.h.ua(a);
529
529
  a.I.resume();
530
530
  a.state = window.h.ha.tb;
531
- }, 497624:a => {
531
+ }, 498104:a => {
532
532
  a = window.h.ua(a);
533
533
  a.I.suspend();
534
534
  a.state = window.h.ha.stopped;
@@ -4104,7 +4104,7 @@ Ie();
4104
4104
  /* 2 */
4105
4105
  /***/ ((module) => {
4106
4106
 
4107
- module.exports = JSON.parse('{"name":"@rive-app/webgl","version":"2.12.1","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.js.map","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
4107
+ module.exports = JSON.parse('{"name":"@rive-app/webgl","version":"2.12.2","description":"Rive\'s webgl based web api.","main":"rive.js","homepage":"https://rive.app","repository":{"type":"git","url":"https://github.com/rive-app/rive-wasm/tree/master/js"},"keywords":["rive","animation"],"author":"Rive","contributors":["Luigi Rosso <luigi@rive.app> (https://rive.app)","Maxwell Talbot <max@rive.app> (https://rive.app)","Arthur Vivian <arthur@rive.app> (https://rive.app)","Umberto Sonnino <umberto@rive.app> (https://rive.app)","Matthew Sullivan <matt.j.sullivan@gmail.com> (mailto:matt.j.sullivan@gmail.com)"],"license":"MIT","files":["rive.js","rive.wasm","rive.js.map","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
4108
4108
 
4109
4109
  /***/ }),
4110
4110
  /* 3 */
@@ -4138,11 +4138,15 @@ var _this = undefined;
4138
4138
  * @param event - Either a TouchEvent or a MouseEvent
4139
4139
  * @returns - Coordinates of the clientX and clientY properties from the touch/mouse event
4140
4140
  */
4141
- var getClientCoordinates = function (event) {
4141
+ var getClientCoordinates = function (event, isTouchScrollEnabled) {
4142
4142
  var _a, _b;
4143
4143
  if (["touchstart", "touchmove"].indexOf(event.type) > -1 &&
4144
4144
  ((_a = event.touches) === null || _a === void 0 ? void 0 : _a.length)) {
4145
- event.preventDefault();
4145
+ // This flag, if false, prevents touch events on the canvas default behavior
4146
+ // which may prevent scrolling if a drag motion on the canvas is performed
4147
+ if (!isTouchScrollEnabled) {
4148
+ event.preventDefault();
4149
+ }
4146
4150
  return {
4147
4151
  clientX: event.touches[0].clientX,
4148
4152
  clientY: event.touches[0].clientY,
@@ -4167,7 +4171,7 @@ var getClientCoordinates = function (event) {
4167
4171
  * the state machine pointer move/up/down functions based on cursor interaction
4168
4172
  */
4169
4173
  var registerTouchInteractions = function (_a) {
4170
- 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;
4174
+ 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;
4171
4175
  if (!canvas ||
4172
4176
  !stateMachines.length ||
4173
4177
  !renderer ||
@@ -4178,7 +4182,7 @@ var registerTouchInteractions = function (_a) {
4178
4182
  }
4179
4183
  var processEventCallback = function (event) {
4180
4184
  var boundingRect = event.currentTarget.getBoundingClientRect();
4181
- var _a = getClientCoordinates(event), clientX = _a.clientX, clientY = _a.clientY;
4185
+ var _a = getClientCoordinates(event, isTouchScrollEnabled), clientX = _a.clientX, clientY = _a.clientY;
4182
4186
  if (!clientX && !clientY) {
4183
4187
  return;
4184
4188
  }
@@ -5364,6 +5368,7 @@ var Rive = /** @class */ (function () {
5364
5368
  this.durations = [];
5365
5369
  this.frameTimes = [];
5366
5370
  this.frameCount = 0;
5371
+ this.isTouchScrollEnabled = false;
5367
5372
  /**
5368
5373
  * Used be draw to track when a second of active rendering time has passed.
5369
5374
  * Used for debugging purposes
@@ -5374,6 +5379,7 @@ var Rive = /** @class */ (function () {
5374
5379
  this.buffer = params.buffer;
5375
5380
  this.layout = (_a = params.layout) !== null && _a !== void 0 ? _a : new Layout();
5376
5381
  this.shouldDisableRiveListeners = !!params.shouldDisableRiveListeners;
5382
+ this.isTouchScrollEnabled = !!params.isTouchScrollEnabled;
5377
5383
  this.automaticallyHandleEvents = !!params.automaticallyHandleEvents;
5378
5384
  this.enableRiveAssetCDN =
5379
5385
  params.enableRiveAssetCDN === undefined
@@ -5475,12 +5481,22 @@ var Rive = /** @class */ (function () {
5475
5481
  console.error(e);
5476
5482
  });
5477
5483
  };
5478
- Rive.prototype.setupRiveListeners = function () {
5484
+ /**
5485
+ * Setup Rive Listeners on the canvas
5486
+ * @param riveListenerOptions - Enables TouchEvent events on the canvas. Set to true to allow
5487
+ * touch scrolling on the canvas element on touch-enabled devices
5488
+ * i.e. { isTouchScrollEnabled: true }
5489
+ */
5490
+ Rive.prototype.setupRiveListeners = function (riveListenerOptions) {
5479
5491
  var _this = this;
5480
5492
  if (!this.shouldDisableRiveListeners) {
5481
5493
  var activeStateMachines = (this.animator.stateMachines || [])
5482
5494
  .filter(function (sm) { return sm.playing && _this.runtime.hasListeners(sm.instance); })
5483
5495
  .map(function (sm) { return sm.instance; });
5496
+ var touchScrollEnabledOption = this.isTouchScrollEnabled;
5497
+ if (riveListenerOptions && 'isTouchScrollEnabled' in riveListenerOptions) {
5498
+ touchScrollEnabledOption = riveListenerOptions.isTouchScrollEnabled;
5499
+ }
5484
5500
  this.eventCleanup = (0,_utils__WEBPACK_IMPORTED_MODULE_2__.registerTouchInteractions)({
5485
5501
  canvas: this.canvas,
5486
5502
  artboard: this.artboard,
@@ -5489,9 +5505,18 @@ var Rive = /** @class */ (function () {
5489
5505
  rive: this.runtime,
5490
5506
  fit: this._layout.runtimeFit(this.runtime),
5491
5507
  alignment: this._layout.runtimeAlignment(this.runtime),
5508
+ isTouchScrollEnabled: touchScrollEnabledOption,
5492
5509
  });
5493
5510
  }
5494
5511
  };
5512
+ /**
5513
+ * Remove Rive Listeners setup on the canvas
5514
+ */
5515
+ Rive.prototype.removeRiveListeners = function () {
5516
+ if (this.eventCleanup) {
5517
+ this.eventCleanup();
5518
+ }
5519
+ };
5495
5520
  // Initializes runtime with Rive data and preps for playing
5496
5521
  Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay) {
5497
5522
  var _a;