@rive-app/webgl-single 1.0.103 → 1.1.0

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-single",
3
- "version": "1.0.103",
3
+ "version": "1.1.0",
4
4
  "description": "Rive's webgl based web api with bundled wasm.",
5
5
  "main": "rive.js",
6
6
  "homepage": "https://rive.app",
package/rive.js CHANGED
@@ -167,7 +167,7 @@ if(h.preInit)for("function"==typeof h.preInit&&(h.preInit=[h.preInit]);0<h.preIn
167
167
  /* 2 */
168
168
  /***/ ((module) => {
169
169
 
170
- module.exports = JSON.parse('{"name":"@rive-app/webgl-single","version":"1.0.103","description":"Rive\'s webgl based web api with bundled wasm.","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.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
170
+ module.exports = JSON.parse('{"name":"@rive-app/webgl-single","version":"1.1.0","description":"Rive\'s webgl based web api with bundled wasm.","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.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
171
171
 
172
172
  /***/ }),
173
173
  /* 3 */
@@ -189,94 +189,128 @@ __webpack_require__.r(__webpack_exports__);
189
189
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
190
190
  /* harmony export */ "registerTouchInteractions": () => (/* binding */ registerTouchInteractions)
191
191
  /* harmony export */ });
192
+ var _this = undefined;
193
+ /**
194
+ * Returns the clientX and clientY properties from touch or mouse events. Also
195
+ * calls preventDefault() on the event if it is a touchstart or touchmove to prevent
196
+ * scrolling the page on mobile devices
197
+ * @param event - Either a TouchEvent or a MouseEvent
198
+ * @returns - Coordinates of the clientX and clientY properties from the touch/mouse event
199
+ */
200
+ var getClientCoordinates = function (event) {
201
+ var _a, _b;
202
+ if (["touchstart", "touchmove"].indexOf(event.type) > -1 &&
203
+ ((_a = event.touches) === null || _a === void 0 ? void 0 : _a.length)) {
204
+ event.preventDefault();
205
+ return {
206
+ clientX: event.touches[0].clientX,
207
+ clientY: event.touches[0].clientY,
208
+ };
209
+ }
210
+ else if (event.type === "touchend" &&
211
+ ((_b = event.changedTouches) === null || _b === void 0 ? void 0 : _b.length)) {
212
+ return {
213
+ clientX: event.changedTouches[0].clientX,
214
+ clientY: event.changedTouches[0].clientY,
215
+ };
216
+ }
217
+ else {
218
+ return {
219
+ clientX: event.clientX,
220
+ clientY: event.clientY,
221
+ };
222
+ }
223
+ };
192
224
  /**
193
225
  * Registers mouse move/up/down callback handlers on the canvas to send meaningful coordinates to
194
226
  * the state machine pointer move/up/down functions based on cursor interaction
195
227
  */
196
- const registerTouchInteractions = ({
197
- canvas,
198
- artboard,
199
- stateMachines = [],
200
- renderer,
201
- rive,
202
- fit,
203
- alignment,
204
- }) => {
205
- if (!canvas || !stateMachines.length || !renderer || !rive || !artboard) {
206
- return null;
207
- }
208
-
209
- const mouseCallback = (event) => {
210
- const boundingRect = event.currentTarget.getBoundingClientRect();
211
-
212
- const canvasX = event.clientX - boundingRect.left;
213
- const canvasY = event.clientY - boundingRect.top;
214
- const forwardMatrix = rive.computeAlignment(
215
- fit,
216
- alignment,
217
- {
218
- minX: 0,
219
- minY: 0,
220
- maxX: boundingRect.width,
221
- maxY: boundingRect.height,
222
- },
223
- artboard.bounds
224
- );
225
- let invertedMatrix = new rive.Mat2D();
226
- forwardMatrix.invert(invertedMatrix);
227
- const canvasCoordinatesVector = new rive.Vec2D(canvasX, canvasY);
228
- const transformedVector = rive.mapXY(
229
- invertedMatrix,
230
- canvasCoordinatesVector
231
- );
232
- const transformedX = transformedVector.x();
233
- const transformedY = transformedVector.y();
234
-
235
- transformedVector.delete();
236
- invertedMatrix.delete();
237
- canvasCoordinatesVector.delete();
238
- forwardMatrix.delete();
239
-
240
- switch (event.type) {
241
- // Pointer moving/hovering on the canvas
242
- case "mouseover":
243
- case "mouseout":
244
- case "mousemove": {
245
- for (const stateMachine of stateMachines) {
246
- stateMachine.pointerMove(transformedX, transformedY);
247
- }
248
- break;
249
- }
250
- // Pointer click initiated but not released yet on the canvas
251
- case "mousedown": {
252
- for (const stateMachine of stateMachines) {
253
- stateMachine.pointerDown(transformedX, transformedY);
228
+ var registerTouchInteractions = function (_a) {
229
+ 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;
230
+ if (!canvas ||
231
+ !stateMachines.length ||
232
+ !renderer ||
233
+ !rive ||
234
+ !artboard ||
235
+ typeof window === "undefined") {
236
+ return null;
237
+ }
238
+ var processEventCallback = function (event) {
239
+ var boundingRect = event.currentTarget.getBoundingClientRect();
240
+ var _a = getClientCoordinates(event), clientX = _a.clientX, clientY = _a.clientY;
241
+ if (!clientX && !clientY) {
242
+ return;
254
243
  }
255
- break;
256
- }
257
- // Pointer click released on the canvas
258
- case "mouseup": {
259
- for (const stateMachine of stateMachines) {
260
- stateMachine.pointerUp(transformedX, transformedY);
244
+ var canvasX = clientX - boundingRect.left;
245
+ var canvasY = clientY - boundingRect.top;
246
+ var forwardMatrix = rive.computeAlignment(fit, alignment, {
247
+ minX: 0,
248
+ minY: 0,
249
+ maxX: boundingRect.width,
250
+ maxY: boundingRect.height,
251
+ }, artboard.bounds);
252
+ var invertedMatrix = new rive.Mat2D();
253
+ forwardMatrix.invert(invertedMatrix);
254
+ var canvasCoordinatesVector = new rive.Vec2D(canvasX, canvasY);
255
+ var transformedVector = rive.mapXY(invertedMatrix, canvasCoordinatesVector);
256
+ var transformedX = transformedVector.x();
257
+ var transformedY = transformedVector.y();
258
+ transformedVector.delete();
259
+ invertedMatrix.delete();
260
+ canvasCoordinatesVector.delete();
261
+ forwardMatrix.delete();
262
+ switch (event.type) {
263
+ // Pointer moving/hovering on the canvas
264
+ case "touchmove":
265
+ case "mouseover":
266
+ case "mouseout":
267
+ case "mousemove": {
268
+ for (var _i = 0, stateMachines_1 = stateMachines; _i < stateMachines_1.length; _i++) {
269
+ var stateMachine = stateMachines_1[_i];
270
+ stateMachine.pointerMove(transformedX, transformedY);
271
+ }
272
+ break;
273
+ }
274
+ // Pointer click initiated but not released yet on the canvas
275
+ case "touchstart":
276
+ case "mousedown": {
277
+ for (var _b = 0, stateMachines_2 = stateMachines; _b < stateMachines_2.length; _b++) {
278
+ var stateMachine = stateMachines_2[_b];
279
+ stateMachine.pointerDown(transformedX, transformedY);
280
+ }
281
+ break;
282
+ }
283
+ // Pointer click released on the canvas
284
+ case "touchend":
285
+ case "mouseup": {
286
+ for (var _c = 0, stateMachines_3 = stateMachines; _c < stateMachines_3.length; _c++) {
287
+ var stateMachine = stateMachines_3[_c];
288
+ stateMachine.pointerUp(transformedX, transformedY);
289
+ }
290
+ break;
291
+ }
292
+ default:
261
293
  }
262
- break;
263
- }
264
- default:
265
- }
266
- };
267
- const callback = mouseCallback.bind(undefined);
268
- canvas.addEventListener("mouseover", callback);
269
- canvas.addEventListener("mouseout", callback);
270
- canvas.addEventListener("mousemove", callback);
271
- canvas.addEventListener("mousedown", callback);
272
- canvas.addEventListener("mouseup", callback);
273
- return () => {
274
- canvas.removeEventListener("mouseover", callback);
275
- canvas.removeEventListener("mouseout", callback);
276
- canvas.removeEventListener("mousemove", callback);
277
- canvas.removeEventListener("mousedown", callback);
278
- canvas.removeEventListener("mouseup", callback);
279
- };
294
+ };
295
+ var callback = processEventCallback.bind(_this);
296
+ canvas.addEventListener("mouseover", callback);
297
+ canvas.addEventListener("mouseout", callback);
298
+ canvas.addEventListener("mousemove", callback);
299
+ canvas.addEventListener("mousedown", callback);
300
+ canvas.addEventListener("mouseup", callback);
301
+ canvas.addEventListener("touchmove", callback);
302
+ canvas.addEventListener("touchstart", callback);
303
+ canvas.addEventListener("touchend", callback);
304
+ return function () {
305
+ canvas.removeEventListener("mouseover", callback);
306
+ canvas.removeEventListener("mouseout", callback);
307
+ canvas.removeEventListener("mousemove", callback);
308
+ canvas.removeEventListener("mousedown", callback);
309
+ canvas.removeEventListener("mouseup", callback);
310
+ canvas.removeEventListener("touchmove", callback);
311
+ canvas.removeEventListener("touchstart", callback);
312
+ canvas.removeEventListener("touchend", callback);
313
+ };
280
314
  };
281
315
 
282
316
 
@@ -1546,14 +1580,17 @@ var Rive = /** @class */ (function () {
1546
1580
  * Rive class
1547
1581
  */
1548
1582
  Rive.prototype.cleanup = function () {
1583
+ var _a, _b;
1549
1584
  // Stop the renderer if it hasn't already been stopped.
1550
1585
  this.stopRendering();
1551
1586
  // Clean up any artboard, animation or state machine instances.
1552
1587
  this.cleanupInstances();
1553
1588
  // Delete the renderer
1554
- this.renderer.delete();
1589
+ (_a = this.renderer) === null || _a === void 0 ? void 0 : _a.delete();
1590
+ this.renderer = null;
1555
1591
  // Delete the rive file
1556
- this.file.delete();
1592
+ (_b = this.file) === null || _b === void 0 ? void 0 : _b.delete();
1593
+ this.file = null;
1557
1594
  };
1558
1595
  /**
1559
1596
  * Cleans up any Wasm-generated objects that need to be manually destroyed: