@rive-app/canvas-lite 2.37.2 → 2.37.4
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 +85 -48
- package/rive.js.map +1 -1
- package/rive.wasm +0 -0
- package/rive_fallback.wasm +0 -0
package/package.json
CHANGED
package/rive.js
CHANGED
|
@@ -2529,7 +2529,7 @@ moduleRtn = da;
|
|
|
2529
2529
|
/* 5 */
|
|
2530
2530
|
/***/ ((module) => {
|
|
2531
2531
|
|
|
2532
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.37.
|
|
2532
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.37.4","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_fallback.wasm","rive.d.ts","rive_advanced.mjs.d.ts","runtimeLoader.d.ts","utils"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
|
|
2533
2533
|
|
|
2534
2534
|
/***/ }),
|
|
2535
2535
|
/* 6 */
|
|
@@ -2573,60 +2573,70 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2573
2573
|
/* harmony export */ });
|
|
2574
2574
|
var _this = undefined;
|
|
2575
2575
|
/**
|
|
2576
|
-
*
|
|
2577
|
-
*
|
|
2578
|
-
*
|
|
2579
|
-
* @param event - Either a TouchEvent or a MouseEvent
|
|
2580
|
-
* @returns - Coordinates of the clientX and clientY properties from the touch/mouse event
|
|
2576
|
+
* Extracts ClientCoordinates from a TouchList, respecting multi-touch vs.
|
|
2577
|
+
* single-touch mode. In single-touch mode, only the touch matching
|
|
2578
|
+
* primaryTouchId is returned (or the first touch when primaryTouchId is null).
|
|
2581
2579
|
*/
|
|
2582
|
-
var
|
|
2583
|
-
var _a
|
|
2580
|
+
var getTouchCoordinates = function (changedTouches, enableMultiTouch, primaryTouchId) {
|
|
2581
|
+
var _a;
|
|
2584
2582
|
var coordinates = [];
|
|
2585
|
-
if (
|
|
2586
|
-
(
|
|
2587
|
-
|
|
2588
|
-
// which may prevent scrolling if a drag motion on the canvas is performed
|
|
2589
|
-
if (!isTouchScrollEnabled) {
|
|
2590
|
-
event.preventDefault();
|
|
2591
|
-
}
|
|
2592
|
-
var cnt = 0;
|
|
2593
|
-
var totalTouches = enableMultiTouch
|
|
2594
|
-
? event.changedTouches.length
|
|
2595
|
-
: 1;
|
|
2596
|
-
while (cnt < totalTouches) {
|
|
2597
|
-
var touch = event.changedTouches[cnt];
|
|
2583
|
+
if (enableMultiTouch) {
|
|
2584
|
+
for (var i = 0; i < changedTouches.length; i++) {
|
|
2585
|
+
var touch = changedTouches[i];
|
|
2598
2586
|
coordinates.push({
|
|
2599
2587
|
clientX: touch.clientX,
|
|
2600
2588
|
clientY: touch.clientY,
|
|
2601
2589
|
identifier: touch.identifier,
|
|
2602
2590
|
});
|
|
2603
|
-
cnt++;
|
|
2604
2591
|
}
|
|
2605
2592
|
}
|
|
2606
|
-
else
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
:
|
|
2612
|
-
|
|
2613
|
-
|
|
2593
|
+
else {
|
|
2594
|
+
// In "single-touch mode", only track the primary finger identified at touchstart.
|
|
2595
|
+
// Search changedTouches for the touch matching the recorded primary touch identifier, or (on initial touchstart)
|
|
2596
|
+
// take the first available touch identifier.
|
|
2597
|
+
var primaryTouch = primaryTouchId !== null
|
|
2598
|
+
? (_a = Array.from(changedTouches).find(function (t) { return t.identifier === primaryTouchId; })) !== null && _a !== void 0 ? _a : null
|
|
2599
|
+
: changedTouches[0];
|
|
2600
|
+
if (primaryTouch) {
|
|
2614
2601
|
coordinates.push({
|
|
2615
|
-
clientX:
|
|
2616
|
-
clientY:
|
|
2617
|
-
identifier:
|
|
2602
|
+
clientX: primaryTouch.clientX,
|
|
2603
|
+
clientY: primaryTouch.clientY,
|
|
2604
|
+
identifier: primaryTouch.identifier,
|
|
2618
2605
|
});
|
|
2619
|
-
cnt++;
|
|
2620
2606
|
}
|
|
2621
2607
|
}
|
|
2622
|
-
|
|
2623
|
-
|
|
2608
|
+
return coordinates;
|
|
2609
|
+
};
|
|
2610
|
+
/**
|
|
2611
|
+
* Returns the clientX and clientY properties from touch or mouse events. Also
|
|
2612
|
+
* calls preventDefault() on the event if it is a touchstart or touchmove to prevent
|
|
2613
|
+
* scrolling the page on mobile devices
|
|
2614
|
+
* @param event - Either a TouchEvent or a MouseEvent
|
|
2615
|
+
* @param isTouchScrollEnabled - Whether touch scrolling is enabled
|
|
2616
|
+
* @param enableMultiTouch - Whether to process multiple simultaneous touches
|
|
2617
|
+
* @param primaryTouchId - When working with single touches, only process the touch
|
|
2618
|
+
* with this identifier. Pass null to accept any touch (used during touchstart to
|
|
2619
|
+
* capture the first finger down).
|
|
2620
|
+
* @returns - Coordinates of the clientX and clientY properties from the touch/mouse event
|
|
2621
|
+
*/
|
|
2622
|
+
var getClientCoordinates = function (event, isTouchScrollEnabled, enableMultiTouch, primaryTouchId) {
|
|
2623
|
+
var _a;
|
|
2624
|
+
var touchEvent = event;
|
|
2625
|
+
if ((_a = touchEvent.changedTouches) === null || _a === void 0 ? void 0 : _a.length) {
|
|
2626
|
+
// This flag, if false, prevents touch events on the canvas default behavior
|
|
2627
|
+
// which may prevent scrolling if a drag motion on the canvas is performed
|
|
2628
|
+
if (!isTouchScrollEnabled && ["touchstart", "touchmove"].includes(event.type)) {
|
|
2629
|
+
event.preventDefault();
|
|
2630
|
+
}
|
|
2631
|
+
return getTouchCoordinates(touchEvent.changedTouches, enableMultiTouch, primaryTouchId);
|
|
2632
|
+
}
|
|
2633
|
+
return [
|
|
2634
|
+
{
|
|
2624
2635
|
clientX: event.clientX,
|
|
2625
2636
|
clientY: event.clientY,
|
|
2626
2637
|
identifier: 0,
|
|
2627
|
-
}
|
|
2628
|
-
|
|
2629
|
-
return coordinates;
|
|
2638
|
+
},
|
|
2639
|
+
];
|
|
2630
2640
|
};
|
|
2631
2641
|
/**
|
|
2632
2642
|
* Registers mouse move/up/down callback handlers on the canvas to send meaningful coordinates to
|
|
@@ -2658,7 +2668,15 @@ var registerTouchInteractions = function (_a) {
|
|
|
2658
2668
|
**/
|
|
2659
2669
|
var _prevEventType = null;
|
|
2660
2670
|
var _syntheticEventsActive = false;
|
|
2671
|
+
/**
|
|
2672
|
+
* When enableMultiTouch is false ("single-touch mode"), we track the identifier of the first finger that touched down.
|
|
2673
|
+
* All subsequent touch events are filtered to this identifier so that a second finger
|
|
2674
|
+
* moving cannot displace the tracked pointer position.
|
|
2675
|
+
* Reset to null when the primary finger lifts (or touchcancel is called)
|
|
2676
|
+
*/
|
|
2677
|
+
var _primaryTouchId = null;
|
|
2661
2678
|
var processEventCallback = function (event) {
|
|
2679
|
+
var _a;
|
|
2662
2680
|
// Exit early out of all synthetic mouse events
|
|
2663
2681
|
// https://stackoverflow.com/questions/9656990/how-to-prevent-simulated-mouse-events-in-mobile-browsers
|
|
2664
2682
|
// https://stackoverflow.com/questions/25572070/javascript-touchend-versus-click-dilemma
|
|
@@ -2677,7 +2695,15 @@ var registerTouchInteractions = function (_a) {
|
|
|
2677
2695
|
_prevEventType === "touchstart";
|
|
2678
2696
|
_prevEventType = event.type;
|
|
2679
2697
|
var boundingRect = event.currentTarget.getBoundingClientRect();
|
|
2680
|
-
|
|
2698
|
+
// On touchstart in single-touch mode, record the first new finger as the primary
|
|
2699
|
+
// touch if we aren't already tracking one.
|
|
2700
|
+
if (!enableMultiTouch && event.type === "touchstart" && _primaryTouchId === null) {
|
|
2701
|
+
var firstTouch = (_a = event.changedTouches) === null || _a === void 0 ? void 0 : _a[0];
|
|
2702
|
+
if (firstTouch) {
|
|
2703
|
+
_primaryTouchId = firstTouch.identifier;
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
var coordinateSets = getClientCoordinates(event, isTouchScrollEnabled, enableMultiTouch, enableMultiTouch ? null : _primaryTouchId);
|
|
2681
2707
|
var forwardMatrix = rive.computeAlignment(fit, alignment, {
|
|
2682
2708
|
minX: 0,
|
|
2683
2709
|
minY: 0,
|
|
@@ -2742,8 +2768,8 @@ var registerTouchInteractions = function (_a) {
|
|
|
2742
2768
|
stateMachine.pointerMove(coordinateSet.transformedX, coordinateSet.transformedY, coordinateSet.identifier);
|
|
2743
2769
|
});
|
|
2744
2770
|
};
|
|
2745
|
-
for (var
|
|
2746
|
-
var stateMachine = stateMachines_2[
|
|
2771
|
+
for (var _b = 0, stateMachines_2 = stateMachines; _b < stateMachines_2.length; _b++) {
|
|
2772
|
+
var stateMachine = stateMachines_2[_b];
|
|
2747
2773
|
_loop_2(stateMachine);
|
|
2748
2774
|
}
|
|
2749
2775
|
break;
|
|
@@ -2756,8 +2782,8 @@ var registerTouchInteractions = function (_a) {
|
|
|
2756
2782
|
stateMachine.pointerDown(coordinateSet.transformedX, coordinateSet.transformedY, coordinateSet.identifier);
|
|
2757
2783
|
});
|
|
2758
2784
|
};
|
|
2759
|
-
for (var
|
|
2760
|
-
var stateMachine = stateMachines_3[
|
|
2785
|
+
for (var _c = 0, stateMachines_3 = stateMachines; _c < stateMachines_3.length; _c++) {
|
|
2786
|
+
var stateMachine = stateMachines_3[_c];
|
|
2761
2787
|
_loop_3(stateMachine);
|
|
2762
2788
|
}
|
|
2763
2789
|
break;
|
|
@@ -2770,10 +2796,16 @@ var registerTouchInteractions = function (_a) {
|
|
|
2770
2796
|
stateMachine.pointerExit(coordinateSet.transformedX, coordinateSet.transformedY, coordinateSet.identifier);
|
|
2771
2797
|
});
|
|
2772
2798
|
};
|
|
2773
|
-
for (var
|
|
2774
|
-
var stateMachine = stateMachines_4[
|
|
2799
|
+
for (var _d = 0, stateMachines_4 = stateMachines; _d < stateMachines_4.length; _d++) {
|
|
2800
|
+
var stateMachine = stateMachines_4[_d];
|
|
2775
2801
|
_loop_4(stateMachine);
|
|
2776
2802
|
}
|
|
2803
|
+
// Release the primary touch lock once that finger lifts so the next
|
|
2804
|
+
// touchstart can claim a new primary finger.
|
|
2805
|
+
if (!enableMultiTouch &&
|
|
2806
|
+
coordinateSets.some(function (c) { return c.identifier === _primaryTouchId; })) {
|
|
2807
|
+
_primaryTouchId = null;
|
|
2808
|
+
}
|
|
2777
2809
|
break;
|
|
2778
2810
|
}
|
|
2779
2811
|
case "mouseup": {
|
|
@@ -2782,8 +2814,8 @@ var registerTouchInteractions = function (_a) {
|
|
|
2782
2814
|
stateMachine.pointerUp(coordinateSet.transformedX, coordinateSet.transformedY, coordinateSet.identifier);
|
|
2783
2815
|
});
|
|
2784
2816
|
};
|
|
2785
|
-
for (var
|
|
2786
|
-
var stateMachine = stateMachines_5[
|
|
2817
|
+
for (var _e = 0, stateMachines_5 = stateMachines; _e < stateMachines_5.length; _e++) {
|
|
2818
|
+
var stateMachine = stateMachines_5[_e];
|
|
2787
2819
|
_loop_5(stateMachine);
|
|
2788
2820
|
}
|
|
2789
2821
|
break;
|
|
@@ -2791,6 +2823,9 @@ var registerTouchInteractions = function (_a) {
|
|
|
2791
2823
|
default:
|
|
2792
2824
|
}
|
|
2793
2825
|
};
|
|
2826
|
+
var touchCancelCallback = function () {
|
|
2827
|
+
_primaryTouchId = null;
|
|
2828
|
+
};
|
|
2794
2829
|
var callback = processEventCallback.bind(_this);
|
|
2795
2830
|
canvas.addEventListener("mouseover", callback);
|
|
2796
2831
|
canvas.addEventListener("mouseout", callback);
|
|
@@ -2804,6 +2839,7 @@ var registerTouchInteractions = function (_a) {
|
|
|
2804
2839
|
passive: isTouchScrollEnabled,
|
|
2805
2840
|
});
|
|
2806
2841
|
canvas.addEventListener("touchend", callback);
|
|
2842
|
+
canvas.addEventListener("touchcancel", touchCancelCallback);
|
|
2807
2843
|
return function () {
|
|
2808
2844
|
canvas.removeEventListener("mouseover", callback);
|
|
2809
2845
|
canvas.removeEventListener("mouseout", callback);
|
|
@@ -2813,6 +2849,7 @@ var registerTouchInteractions = function (_a) {
|
|
|
2813
2849
|
canvas.removeEventListener("touchmove", callback);
|
|
2814
2850
|
canvas.removeEventListener("touchstart", callback);
|
|
2815
2851
|
canvas.removeEventListener("touchend", callback);
|
|
2852
|
+
canvas.removeEventListener("touchcancel", touchCancelCallback);
|
|
2816
2853
|
};
|
|
2817
2854
|
};
|
|
2818
2855
|
|