@rive-app/canvas-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 +1 -1
- package/rive.js +122 -85
- package/rive.js.map +1 -1
- package/rive_advanced.mjs.d.ts +10 -0
package/package.json
CHANGED
package/rive.js
CHANGED
|
@@ -134,7 +134,7 @@ if(m.preInit)for("function"==typeof m.preInit&&(m.preInit=[m.preInit]);0<m.preIn
|
|
|
134
134
|
/* 2 */
|
|
135
135
|
/***/ ((module) => {
|
|
136
136
|
|
|
137
|
-
module.exports = JSON.parse('{"name":"@rive-app/canvas-single","version":"1.0
|
|
137
|
+
module.exports = JSON.parse('{"name":"@rive-app/canvas-single","version":"1.1.0","description":"Rive\'s high-level canvas based web api all in one js file.","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}}');
|
|
138
138
|
|
|
139
139
|
/***/ }),
|
|
140
140
|
/* 3 */
|
|
@@ -156,94 +156,128 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
156
156
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
157
157
|
/* harmony export */ "registerTouchInteractions": () => (/* binding */ registerTouchInteractions)
|
|
158
158
|
/* harmony export */ });
|
|
159
|
+
var _this = undefined;
|
|
160
|
+
/**
|
|
161
|
+
* Returns the clientX and clientY properties from touch or mouse events. Also
|
|
162
|
+
* calls preventDefault() on the event if it is a touchstart or touchmove to prevent
|
|
163
|
+
* scrolling the page on mobile devices
|
|
164
|
+
* @param event - Either a TouchEvent or a MouseEvent
|
|
165
|
+
* @returns - Coordinates of the clientX and clientY properties from the touch/mouse event
|
|
166
|
+
*/
|
|
167
|
+
var getClientCoordinates = function (event) {
|
|
168
|
+
var _a, _b;
|
|
169
|
+
if (["touchstart", "touchmove"].indexOf(event.type) > -1 &&
|
|
170
|
+
((_a = event.touches) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
171
|
+
event.preventDefault();
|
|
172
|
+
return {
|
|
173
|
+
clientX: event.touches[0].clientX,
|
|
174
|
+
clientY: event.touches[0].clientY,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
else if (event.type === "touchend" &&
|
|
178
|
+
((_b = event.changedTouches) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
179
|
+
return {
|
|
180
|
+
clientX: event.changedTouches[0].clientX,
|
|
181
|
+
clientY: event.changedTouches[0].clientY,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
return {
|
|
186
|
+
clientX: event.clientX,
|
|
187
|
+
clientY: event.clientY,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
};
|
|
159
191
|
/**
|
|
160
192
|
* Registers mouse move/up/down callback handlers on the canvas to send meaningful coordinates to
|
|
161
193
|
* the state machine pointer move/up/down functions based on cursor interaction
|
|
162
194
|
*/
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const canvasX = event.clientX - boundingRect.left;
|
|
180
|
-
const canvasY = event.clientY - boundingRect.top;
|
|
181
|
-
const forwardMatrix = rive.computeAlignment(
|
|
182
|
-
fit,
|
|
183
|
-
alignment,
|
|
184
|
-
{
|
|
185
|
-
minX: 0,
|
|
186
|
-
minY: 0,
|
|
187
|
-
maxX: boundingRect.width,
|
|
188
|
-
maxY: boundingRect.height,
|
|
189
|
-
},
|
|
190
|
-
artboard.bounds
|
|
191
|
-
);
|
|
192
|
-
let invertedMatrix = new rive.Mat2D();
|
|
193
|
-
forwardMatrix.invert(invertedMatrix);
|
|
194
|
-
const canvasCoordinatesVector = new rive.Vec2D(canvasX, canvasY);
|
|
195
|
-
const transformedVector = rive.mapXY(
|
|
196
|
-
invertedMatrix,
|
|
197
|
-
canvasCoordinatesVector
|
|
198
|
-
);
|
|
199
|
-
const transformedX = transformedVector.x();
|
|
200
|
-
const transformedY = transformedVector.y();
|
|
201
|
-
|
|
202
|
-
transformedVector.delete();
|
|
203
|
-
invertedMatrix.delete();
|
|
204
|
-
canvasCoordinatesVector.delete();
|
|
205
|
-
forwardMatrix.delete();
|
|
206
|
-
|
|
207
|
-
switch (event.type) {
|
|
208
|
-
// Pointer moving/hovering on the canvas
|
|
209
|
-
case "mouseover":
|
|
210
|
-
case "mouseout":
|
|
211
|
-
case "mousemove": {
|
|
212
|
-
for (const stateMachine of stateMachines) {
|
|
213
|
-
stateMachine.pointerMove(transformedX, transformedY);
|
|
214
|
-
}
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
217
|
-
// Pointer click initiated but not released yet on the canvas
|
|
218
|
-
case "mousedown": {
|
|
219
|
-
for (const stateMachine of stateMachines) {
|
|
220
|
-
stateMachine.pointerDown(transformedX, transformedY);
|
|
195
|
+
var registerTouchInteractions = function (_a) {
|
|
196
|
+
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;
|
|
197
|
+
if (!canvas ||
|
|
198
|
+
!stateMachines.length ||
|
|
199
|
+
!renderer ||
|
|
200
|
+
!rive ||
|
|
201
|
+
!artboard ||
|
|
202
|
+
typeof window === "undefined") {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
var processEventCallback = function (event) {
|
|
206
|
+
var boundingRect = event.currentTarget.getBoundingClientRect();
|
|
207
|
+
var _a = getClientCoordinates(event), clientX = _a.clientX, clientY = _a.clientY;
|
|
208
|
+
if (!clientX && !clientY) {
|
|
209
|
+
return;
|
|
221
210
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
211
|
+
var canvasX = clientX - boundingRect.left;
|
|
212
|
+
var canvasY = clientY - boundingRect.top;
|
|
213
|
+
var forwardMatrix = rive.computeAlignment(fit, alignment, {
|
|
214
|
+
minX: 0,
|
|
215
|
+
minY: 0,
|
|
216
|
+
maxX: boundingRect.width,
|
|
217
|
+
maxY: boundingRect.height,
|
|
218
|
+
}, artboard.bounds);
|
|
219
|
+
var invertedMatrix = new rive.Mat2D();
|
|
220
|
+
forwardMatrix.invert(invertedMatrix);
|
|
221
|
+
var canvasCoordinatesVector = new rive.Vec2D(canvasX, canvasY);
|
|
222
|
+
var transformedVector = rive.mapXY(invertedMatrix, canvasCoordinatesVector);
|
|
223
|
+
var transformedX = transformedVector.x();
|
|
224
|
+
var transformedY = transformedVector.y();
|
|
225
|
+
transformedVector.delete();
|
|
226
|
+
invertedMatrix.delete();
|
|
227
|
+
canvasCoordinatesVector.delete();
|
|
228
|
+
forwardMatrix.delete();
|
|
229
|
+
switch (event.type) {
|
|
230
|
+
// Pointer moving/hovering on the canvas
|
|
231
|
+
case "touchmove":
|
|
232
|
+
case "mouseover":
|
|
233
|
+
case "mouseout":
|
|
234
|
+
case "mousemove": {
|
|
235
|
+
for (var _i = 0, stateMachines_1 = stateMachines; _i < stateMachines_1.length; _i++) {
|
|
236
|
+
var stateMachine = stateMachines_1[_i];
|
|
237
|
+
stateMachine.pointerMove(transformedX, transformedY);
|
|
238
|
+
}
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
// Pointer click initiated but not released yet on the canvas
|
|
242
|
+
case "touchstart":
|
|
243
|
+
case "mousedown": {
|
|
244
|
+
for (var _b = 0, stateMachines_2 = stateMachines; _b < stateMachines_2.length; _b++) {
|
|
245
|
+
var stateMachine = stateMachines_2[_b];
|
|
246
|
+
stateMachine.pointerDown(transformedX, transformedY);
|
|
247
|
+
}
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
// Pointer click released on the canvas
|
|
251
|
+
case "touchend":
|
|
252
|
+
case "mouseup": {
|
|
253
|
+
for (var _c = 0, stateMachines_3 = stateMachines; _c < stateMachines_3.length; _c++) {
|
|
254
|
+
var stateMachine = stateMachines_3[_c];
|
|
255
|
+
stateMachine.pointerUp(transformedX, transformedY);
|
|
256
|
+
}
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
default:
|
|
228
260
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
261
|
+
};
|
|
262
|
+
var callback = processEventCallback.bind(_this);
|
|
263
|
+
canvas.addEventListener("mouseover", callback);
|
|
264
|
+
canvas.addEventListener("mouseout", callback);
|
|
265
|
+
canvas.addEventListener("mousemove", callback);
|
|
266
|
+
canvas.addEventListener("mousedown", callback);
|
|
267
|
+
canvas.addEventListener("mouseup", callback);
|
|
268
|
+
canvas.addEventListener("touchmove", callback);
|
|
269
|
+
canvas.addEventListener("touchstart", callback);
|
|
270
|
+
canvas.addEventListener("touchend", callback);
|
|
271
|
+
return function () {
|
|
272
|
+
canvas.removeEventListener("mouseover", callback);
|
|
273
|
+
canvas.removeEventListener("mouseout", callback);
|
|
274
|
+
canvas.removeEventListener("mousemove", callback);
|
|
275
|
+
canvas.removeEventListener("mousedown", callback);
|
|
276
|
+
canvas.removeEventListener("mouseup", callback);
|
|
277
|
+
canvas.removeEventListener("touchmove", callback);
|
|
278
|
+
canvas.removeEventListener("touchstart", callback);
|
|
279
|
+
canvas.removeEventListener("touchend", callback);
|
|
280
|
+
};
|
|
247
281
|
};
|
|
248
282
|
|
|
249
283
|
|
|
@@ -1513,14 +1547,17 @@ var Rive = /** @class */ (function () {
|
|
|
1513
1547
|
* Rive class
|
|
1514
1548
|
*/
|
|
1515
1549
|
Rive.prototype.cleanup = function () {
|
|
1550
|
+
var _a, _b;
|
|
1516
1551
|
// Stop the renderer if it hasn't already been stopped.
|
|
1517
1552
|
this.stopRendering();
|
|
1518
1553
|
// Clean up any artboard, animation or state machine instances.
|
|
1519
1554
|
this.cleanupInstances();
|
|
1520
1555
|
// Delete the renderer
|
|
1521
|
-
this.renderer.delete();
|
|
1556
|
+
(_a = this.renderer) === null || _a === void 0 ? void 0 : _a.delete();
|
|
1557
|
+
this.renderer = null;
|
|
1522
1558
|
// Delete the rive file
|
|
1523
|
-
this.file.delete();
|
|
1559
|
+
(_b = this.file) === null || _b === void 0 ? void 0 : _b.delete();
|
|
1560
|
+
this.file = null;
|
|
1524
1561
|
};
|
|
1525
1562
|
/**
|
|
1526
1563
|
* Cleans up any Wasm-generated objects that need to be manually destroyed:
|