@rive-app/canvas-lite 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/canvas-lite",
3
- "version": "2.12.1",
3
+ "version": "2.12.2",
4
4
  "description": "A lite version of Rive's canvas 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
@@ -2252,7 +2252,7 @@ Pc();
2252
2252
  /* 2 */
2253
2253
  /***/ ((module) => {
2254
2254
 
2255
- module.exports = JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.12.1","description":"A lite version of 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}}');
2255
+ module.exports = JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.12.2","description":"A lite version of 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}}');
2256
2256
 
2257
2257
  /***/ }),
2258
2258
  /* 3 */
@@ -2286,11 +2286,15 @@ var _this = undefined;
2286
2286
  * @param event - Either a TouchEvent or a MouseEvent
2287
2287
  * @returns - Coordinates of the clientX and clientY properties from the touch/mouse event
2288
2288
  */
2289
- var getClientCoordinates = function (event) {
2289
+ var getClientCoordinates = function (event, isTouchScrollEnabled) {
2290
2290
  var _a, _b;
2291
2291
  if (["touchstart", "touchmove"].indexOf(event.type) > -1 &&
2292
2292
  ((_a = event.touches) === null || _a === void 0 ? void 0 : _a.length)) {
2293
- event.preventDefault();
2293
+ // This flag, if false, prevents touch events on the canvas default behavior
2294
+ // which may prevent scrolling if a drag motion on the canvas is performed
2295
+ if (!isTouchScrollEnabled) {
2296
+ event.preventDefault();
2297
+ }
2294
2298
  return {
2295
2299
  clientX: event.touches[0].clientX,
2296
2300
  clientY: event.touches[0].clientY,
@@ -2315,7 +2319,7 @@ var getClientCoordinates = function (event) {
2315
2319
  * the state machine pointer move/up/down functions based on cursor interaction
2316
2320
  */
2317
2321
  var registerTouchInteractions = function (_a) {
2318
- 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;
2322
+ 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;
2319
2323
  if (!canvas ||
2320
2324
  !stateMachines.length ||
2321
2325
  !renderer ||
@@ -2326,7 +2330,7 @@ var registerTouchInteractions = function (_a) {
2326
2330
  }
2327
2331
  var processEventCallback = function (event) {
2328
2332
  var boundingRect = event.currentTarget.getBoundingClientRect();
2329
- var _a = getClientCoordinates(event), clientX = _a.clientX, clientY = _a.clientY;
2333
+ var _a = getClientCoordinates(event, isTouchScrollEnabled), clientX = _a.clientX, clientY = _a.clientY;
2330
2334
  if (!clientX && !clientY) {
2331
2335
  return;
2332
2336
  }
@@ -3512,6 +3516,7 @@ var Rive = /** @class */ (function () {
3512
3516
  this.durations = [];
3513
3517
  this.frameTimes = [];
3514
3518
  this.frameCount = 0;
3519
+ this.isTouchScrollEnabled = false;
3515
3520
  /**
3516
3521
  * Used be draw to track when a second of active rendering time has passed.
3517
3522
  * Used for debugging purposes
@@ -3522,6 +3527,7 @@ var Rive = /** @class */ (function () {
3522
3527
  this.buffer = params.buffer;
3523
3528
  this.layout = (_a = params.layout) !== null && _a !== void 0 ? _a : new Layout();
3524
3529
  this.shouldDisableRiveListeners = !!params.shouldDisableRiveListeners;
3530
+ this.isTouchScrollEnabled = !!params.isTouchScrollEnabled;
3525
3531
  this.automaticallyHandleEvents = !!params.automaticallyHandleEvents;
3526
3532
  this.enableRiveAssetCDN =
3527
3533
  params.enableRiveAssetCDN === undefined
@@ -3623,12 +3629,22 @@ var Rive = /** @class */ (function () {
3623
3629
  console.error(e);
3624
3630
  });
3625
3631
  };
3626
- Rive.prototype.setupRiveListeners = function () {
3632
+ /**
3633
+ * Setup Rive Listeners on the canvas
3634
+ * @param riveListenerOptions - Enables TouchEvent events on the canvas. Set to true to allow
3635
+ * touch scrolling on the canvas element on touch-enabled devices
3636
+ * i.e. { isTouchScrollEnabled: true }
3637
+ */
3638
+ Rive.prototype.setupRiveListeners = function (riveListenerOptions) {
3627
3639
  var _this = this;
3628
3640
  if (!this.shouldDisableRiveListeners) {
3629
3641
  var activeStateMachines = (this.animator.stateMachines || [])
3630
3642
  .filter(function (sm) { return sm.playing && _this.runtime.hasListeners(sm.instance); })
3631
3643
  .map(function (sm) { return sm.instance; });
3644
+ var touchScrollEnabledOption = this.isTouchScrollEnabled;
3645
+ if (riveListenerOptions && 'isTouchScrollEnabled' in riveListenerOptions) {
3646
+ touchScrollEnabledOption = riveListenerOptions.isTouchScrollEnabled;
3647
+ }
3632
3648
  this.eventCleanup = (0,_utils__WEBPACK_IMPORTED_MODULE_2__.registerTouchInteractions)({
3633
3649
  canvas: this.canvas,
3634
3650
  artboard: this.artboard,
@@ -3637,9 +3653,18 @@ var Rive = /** @class */ (function () {
3637
3653
  rive: this.runtime,
3638
3654
  fit: this._layout.runtimeFit(this.runtime),
3639
3655
  alignment: this._layout.runtimeAlignment(this.runtime),
3656
+ isTouchScrollEnabled: touchScrollEnabledOption,
3640
3657
  });
3641
3658
  }
3642
3659
  };
3660
+ /**
3661
+ * Remove Rive Listeners setup on the canvas
3662
+ */
3663
+ Rive.prototype.removeRiveListeners = function () {
3664
+ if (this.eventCleanup) {
3665
+ this.eventCleanup();
3666
+ }
3667
+ };
3643
3668
  // Initializes runtime with Rive data and preps for playing
3644
3669
  Rive.prototype.initData = function (artboardName, animationNames, stateMachineNames, autoplay) {
3645
3670
  var _a;