@rive-app/canvas-lite 2.45.0 → 2.45.1
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 +149 -23
- 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
|
@@ -460,7 +460,7 @@ Cc=await (async function(){function b(c){c=Cc=c.exports;kb=c.free;Ac=c.malloc;jb
|
|
|
460
460
|
/* 5 */
|
|
461
461
|
/***/ ((module) => {
|
|
462
462
|
|
|
463
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.45.
|
|
463
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.45.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_fallback.wasm","rive.d.ts","rive_advanced.mjs.d.ts","runtimeLoader.d.ts","utils","semantics"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
|
|
464
464
|
|
|
465
465
|
/***/ }),
|
|
466
466
|
/* 6 */
|
|
@@ -2636,6 +2636,12 @@ var PIXELS_PER_LINE = 16;
|
|
|
2636
2636
|
// ScrollPhase.update. The DOM reports no gesture phase, so every wheel event
|
|
2637
2637
|
// is an update and the runtime closes the gesture once it goes quiet.
|
|
2638
2638
|
var SCROLL_PHASE_UPDATE = 1;
|
|
2639
|
+
/**
|
|
2640
|
+
* Touch state per canvas. It outlives a single registration, because Rive
|
|
2641
|
+
* re-registers the listeners (on play and pause) while a finger can still be
|
|
2642
|
+
* down.
|
|
2643
|
+
*/
|
|
2644
|
+
var touchStateByCanvas = new WeakMap();
|
|
2639
2645
|
/**
|
|
2640
2646
|
* Extracts ClientCoordinates from a TouchList, respecting multi-touch vs.
|
|
2641
2647
|
* single-touch mode. In single-touch mode, only the touch matching
|
|
@@ -2708,7 +2714,8 @@ var getClientCoordinates = function (event, isTouchScrollEnabled, enableMultiTou
|
|
|
2708
2714
|
* interaction
|
|
2709
2715
|
*/
|
|
2710
2716
|
var registerTouchInteractions = function (_a) {
|
|
2711
|
-
var
|
|
2717
|
+
var _b;
|
|
2718
|
+
var canvas = _a.canvas, artboard = _a.artboard, _c = _a.stateMachines, stateMachines = _c === void 0 ? [] : _c, renderer = _a.renderer, rive = _a.rive, fit = _a.fit, alignment = _a.alignment, _d = _a.isTouchScrollEnabled, isTouchScrollEnabled = _d === void 0 ? false : _d, _e = _a.dispatchPointerExit, dispatchPointerExit = _e === void 0 ? true : _e, _f = _a.enableMultiTouch, enableMultiTouch = _f === void 0 ? false : _f, _g = _a.layoutScaleFactor, layoutScaleFactor = _g === void 0 ? 1.0 : _g, advanceAndDrain = _a.advanceAndDrain, summonKeyboard = _a.summonKeyboard, isTextProxyFocused = _a.isTextProxyFocused;
|
|
2712
2719
|
if (!canvas ||
|
|
2713
2720
|
!stateMachines.length ||
|
|
2714
2721
|
!renderer ||
|
|
@@ -2743,12 +2750,49 @@ var registerTouchInteractions = function (_a) {
|
|
|
2743
2750
|
var _prevEventType = null;
|
|
2744
2751
|
var _syntheticEventsActive = false;
|
|
2745
2752
|
/**
|
|
2746
|
-
*
|
|
2747
|
-
*
|
|
2748
|
-
*
|
|
2749
|
-
*
|
|
2753
|
+
* primaryTouchId: when enableMultiTouch is false ("single-touch mode"),
|
|
2754
|
+
* we track the identifier of the first finger that touched down. All
|
|
2755
|
+
* subsequent touch events are filtered to this identifier so that a second
|
|
2756
|
+
* finger moving cannot displace the tracked pointer position. Reset to null
|
|
2757
|
+
* when the primary finger lifts (or touchcancel is called).
|
|
2758
|
+
*
|
|
2759
|
+
* touches: a cancel may report no position, or none at all for some
|
|
2760
|
+
* touches, so it ends them where they were last seen.
|
|
2761
|
+
*/
|
|
2762
|
+
var _touchState = (_b = touchStateByCanvas.get(canvas)) !== null && _b !== void 0 ? _b : {
|
|
2763
|
+
touches: new Map(),
|
|
2764
|
+
primaryTouchId: null,
|
|
2765
|
+
};
|
|
2766
|
+
touchStateByCanvas.set(canvas, _touchState);
|
|
2767
|
+
var _activeTouches = _touchState.touches;
|
|
2768
|
+
/**
|
|
2769
|
+
* A finger can lift while no listeners are registered (after stop(), say),
|
|
2770
|
+
* so its touchend never arrives. A touchstart or touchmove lists every
|
|
2771
|
+
* finger still down in `touches`; forget the rest.
|
|
2750
2772
|
*/
|
|
2751
|
-
var
|
|
2773
|
+
var forgetLiftedTouches = function (_a) {
|
|
2774
|
+
var _b;
|
|
2775
|
+
var touches = _a.touches, changedTouches = _a.changedTouches;
|
|
2776
|
+
if (!touches) {
|
|
2777
|
+
return;
|
|
2778
|
+
}
|
|
2779
|
+
var down = new Set();
|
|
2780
|
+
for (var i = 0; i < touches.length; i++) {
|
|
2781
|
+
down.add(touches[i].identifier);
|
|
2782
|
+
}
|
|
2783
|
+
for (var i = 0; i < ((_b = changedTouches === null || changedTouches === void 0 ? void 0 : changedTouches.length) !== null && _b !== void 0 ? _b : 0); i++) {
|
|
2784
|
+
down.add(changedTouches[i].identifier);
|
|
2785
|
+
}
|
|
2786
|
+
_activeTouches.forEach(function (_, identifier) {
|
|
2787
|
+
if (!down.has(identifier)) {
|
|
2788
|
+
_activeTouches.delete(identifier);
|
|
2789
|
+
}
|
|
2790
|
+
});
|
|
2791
|
+
if (_touchState.primaryTouchId !== null &&
|
|
2792
|
+
!down.has(_touchState.primaryTouchId)) {
|
|
2793
|
+
_touchState.primaryTouchId = null;
|
|
2794
|
+
}
|
|
2795
|
+
};
|
|
2752
2796
|
/**
|
|
2753
2797
|
* Maps client-space points into Artboard space through the fit and alignment
|
|
2754
2798
|
* of the canvas.
|
|
@@ -2778,7 +2822,7 @@ var registerTouchInteractions = function (_a) {
|
|
|
2778
2822
|
return mapped;
|
|
2779
2823
|
};
|
|
2780
2824
|
var processEventCallback = function (event) {
|
|
2781
|
-
var _a;
|
|
2825
|
+
var _a, _b;
|
|
2782
2826
|
// Exit early out of all synthetic mouse events
|
|
2783
2827
|
// https://stackoverflow.com/questions/9656990/how-to-prevent-simulated-mouse-events-in-mobile-browsers
|
|
2784
2828
|
// https://stackoverflow.com/questions/25572070/javascript-touchend-versus-click-dilemma
|
|
@@ -2800,20 +2844,44 @@ var registerTouchInteractions = function (_a) {
|
|
|
2800
2844
|
_prevEventType === "touchstart";
|
|
2801
2845
|
_prevEventType = event.type;
|
|
2802
2846
|
var boundingRect = event.currentTarget.getBoundingClientRect();
|
|
2847
|
+
if (event.type === "touchstart" || event.type === "touchmove") {
|
|
2848
|
+
forgetLiftedTouches(event);
|
|
2849
|
+
}
|
|
2803
2850
|
// On touchstart in single-touch mode, record the first new finger as the primary
|
|
2804
2851
|
// touch if we aren't already tracking one.
|
|
2805
|
-
if (!enableMultiTouch && event.type === "touchstart" &&
|
|
2852
|
+
if (!enableMultiTouch && event.type === "touchstart" && _touchState.primaryTouchId === null) {
|
|
2806
2853
|
var firstTouch = (_a = event.changedTouches) === null || _a === void 0 ? void 0 : _a[0];
|
|
2807
2854
|
if (firstTouch) {
|
|
2808
|
-
|
|
2855
|
+
_touchState.primaryTouchId = firstTouch.identifier;
|
|
2809
2856
|
}
|
|
2810
2857
|
}
|
|
2811
|
-
var coordinateSets = getClientCoordinates(event, isTouchScrollEnabled, enableMultiTouch, enableMultiTouch ? null :
|
|
2858
|
+
var coordinateSets = getClientCoordinates(event, isTouchScrollEnabled, enableMultiTouch, enableMultiTouch ? null : _touchState.primaryTouchId);
|
|
2812
2859
|
var positionedSets = coordinateSets.filter(function (coordinateSet) { return coordinateSet.clientX || coordinateSet.clientY; });
|
|
2813
2860
|
mapToArtboard(boundingRect, positionedSets).forEach(function (point, i) {
|
|
2814
2861
|
positionedSets[i].transformedX = point.x;
|
|
2815
2862
|
positionedSets[i].transformedY = point.y;
|
|
2816
2863
|
});
|
|
2864
|
+
// Only a touchstart the scene saw starts tracking a touch, so a finger
|
|
2865
|
+
// that single-touch mode ignored can never be ended by a cancel. Any
|
|
2866
|
+
// finger that lifts stops being tracked, whether or not the scene saw it.
|
|
2867
|
+
if (event.type === "touchend") {
|
|
2868
|
+
var lifted = (_b = event.changedTouches) !== null && _b !== void 0 ? _b : [];
|
|
2869
|
+
for (var i = 0; i < lifted.length; i++) {
|
|
2870
|
+
_activeTouches.delete(lifted[i].identifier);
|
|
2871
|
+
}
|
|
2872
|
+
}
|
|
2873
|
+
else if (event.type === "touchstart" || event.type === "touchmove") {
|
|
2874
|
+
coordinateSets.forEach(function (_a) {
|
|
2875
|
+
var clientX = _a.clientX, clientY = _a.clientY, identifier = _a.identifier;
|
|
2876
|
+
var tracked = _activeTouches.has(identifier);
|
|
2877
|
+
if (event.type === "touchstart" && !tracked) {
|
|
2878
|
+
_activeTouches.set(identifier, { clientX: clientX, clientY: clientY });
|
|
2879
|
+
}
|
|
2880
|
+
else if (tracked && (clientX || clientY)) {
|
|
2881
|
+
_activeTouches.set(identifier, { clientX: clientX, clientY: clientY });
|
|
2882
|
+
}
|
|
2883
|
+
});
|
|
2884
|
+
}
|
|
2817
2885
|
switch (event.type) {
|
|
2818
2886
|
/**
|
|
2819
2887
|
* There's a 2px buffer for a hitRadius when translating the pointer coordinates
|
|
@@ -2851,8 +2919,8 @@ var registerTouchInteractions = function (_a) {
|
|
|
2851
2919
|
stateMachine.pointerMove(coordinateSet.transformedX, coordinateSet.transformedY, coordinateSet.identifier);
|
|
2852
2920
|
});
|
|
2853
2921
|
};
|
|
2854
|
-
for (var
|
|
2855
|
-
var stateMachine = stateMachines_3[
|
|
2922
|
+
for (var _c = 0, stateMachines_3 = stateMachines; _c < stateMachines_3.length; _c++) {
|
|
2923
|
+
var stateMachine = stateMachines_3[_c];
|
|
2856
2924
|
_loop_2(stateMachine);
|
|
2857
2925
|
}
|
|
2858
2926
|
break;
|
|
@@ -2865,8 +2933,8 @@ var registerTouchInteractions = function (_a) {
|
|
|
2865
2933
|
stateMachine.pointerDown(coordinateSet.transformedX, coordinateSet.transformedY, coordinateSet.identifier);
|
|
2866
2934
|
});
|
|
2867
2935
|
};
|
|
2868
|
-
for (var
|
|
2869
|
-
var stateMachine = stateMachines_4[
|
|
2936
|
+
for (var _d = 0, stateMachines_4 = stateMachines; _d < stateMachines_4.length; _d++) {
|
|
2937
|
+
var stateMachine = stateMachines_4[_d];
|
|
2870
2938
|
_loop_3(stateMachine);
|
|
2871
2939
|
}
|
|
2872
2940
|
// Advance the state machine immediately so pointer down(s) takes effect synchronously
|
|
@@ -2881,8 +2949,8 @@ var registerTouchInteractions = function (_a) {
|
|
|
2881
2949
|
stateMachine.pointerExit(coordinateSet.transformedX, coordinateSet.transformedY, coordinateSet.identifier);
|
|
2882
2950
|
});
|
|
2883
2951
|
};
|
|
2884
|
-
for (var
|
|
2885
|
-
var stateMachine = stateMachines_5[
|
|
2952
|
+
for (var _e = 0, stateMachines_5 = stateMachines; _e < stateMachines_5.length; _e++) {
|
|
2953
|
+
var stateMachine = stateMachines_5[_e];
|
|
2886
2954
|
_loop_4(stateMachine);
|
|
2887
2955
|
}
|
|
2888
2956
|
// Advance the state machine immediately so pointer up(s) takes effect synchronously
|
|
@@ -2893,8 +2961,8 @@ var registerTouchInteractions = function (_a) {
|
|
|
2893
2961
|
// Release the primary touch lock once that finger lifts so the next
|
|
2894
2962
|
// touchstart can claim a new primary finger.
|
|
2895
2963
|
if (!enableMultiTouch &&
|
|
2896
|
-
coordinateSets.some(function (c) { return c.identifier ===
|
|
2897
|
-
|
|
2964
|
+
coordinateSets.some(function (c) { return c.identifier === _touchState.primaryTouchId; })) {
|
|
2965
|
+
_touchState.primaryTouchId = null;
|
|
2898
2966
|
}
|
|
2899
2967
|
break;
|
|
2900
2968
|
}
|
|
@@ -2904,8 +2972,8 @@ var registerTouchInteractions = function (_a) {
|
|
|
2904
2972
|
stateMachine.pointerUp(coordinateSet.transformedX, coordinateSet.transformedY, coordinateSet.identifier);
|
|
2905
2973
|
});
|
|
2906
2974
|
};
|
|
2907
|
-
for (var
|
|
2908
|
-
var stateMachine = stateMachines_6[
|
|
2975
|
+
for (var _f = 0, stateMachines_6 = stateMachines; _f < stateMachines_6.length; _f++) {
|
|
2976
|
+
var stateMachine = stateMachines_6[_f];
|
|
2909
2977
|
_loop_5(stateMachine);
|
|
2910
2978
|
}
|
|
2911
2979
|
// Advance the state machine immediately so pointer up(s) takes effect synchronously
|
|
@@ -2916,8 +2984,66 @@ var registerTouchInteractions = function (_a) {
|
|
|
2916
2984
|
default:
|
|
2917
2985
|
}
|
|
2918
2986
|
};
|
|
2919
|
-
|
|
2920
|
-
|
|
2987
|
+
/**
|
|
2988
|
+
* The browser cancels a touch when the system takes the gesture: a home
|
|
2989
|
+
* indicator or edge swipe, an app switch, an alert. Each cancelled touch
|
|
2990
|
+
* gets pointerUp then pointerExit, like a lifted finger, so anything
|
|
2991
|
+
* waiting for the release doesn't stay pressed. It skips the tap-only side
|
|
2992
|
+
* effects (keyboard, emulated mouse events). A page scroll does not cancel
|
|
2993
|
+
* the touch in iOS Safari or Android Chrome (it ends with a touchend), so
|
|
2994
|
+
* this holds with touch scrolling enabled too.
|
|
2995
|
+
*/
|
|
2996
|
+
var touchCancelCallback = function (event) {
|
|
2997
|
+
var _a, _b;
|
|
2998
|
+
var cancelled = new Set();
|
|
2999
|
+
var changedTouches = (_a = event.changedTouches) !== null && _a !== void 0 ? _a : [];
|
|
3000
|
+
for (var i = 0; i < changedTouches.length; i++) {
|
|
3001
|
+
var _c = changedTouches[i], identifier = _c.identifier, clientX = _c.clientX, clientY = _c.clientY;
|
|
3002
|
+
// Touches the scene never saw (a secondary finger in single-touch
|
|
3003
|
+
// mode, or one that already ended) are not tracked.
|
|
3004
|
+
if (!_activeTouches.has(identifier)) {
|
|
3005
|
+
continue;
|
|
3006
|
+
}
|
|
3007
|
+
cancelled.add(identifier);
|
|
3008
|
+
if (clientX || clientY) {
|
|
3009
|
+
_activeTouches.set(identifier, { clientX: clientX, clientY: clientY });
|
|
3010
|
+
}
|
|
3011
|
+
}
|
|
3012
|
+
// A cancel can name only some of the touches, or none. `touches` lists
|
|
3013
|
+
// every finger still down, so end any tracked touch missing from it.
|
|
3014
|
+
var down = new Set();
|
|
3015
|
+
var touches = (_b = event.touches) !== null && _b !== void 0 ? _b : [];
|
|
3016
|
+
for (var i = 0; i < touches.length; i++) {
|
|
3017
|
+
down.add(touches[i].identifier);
|
|
3018
|
+
}
|
|
3019
|
+
_activeTouches.forEach(function (_, identifier) {
|
|
3020
|
+
if (!down.has(identifier)) {
|
|
3021
|
+
cancelled.add(identifier);
|
|
3022
|
+
}
|
|
3023
|
+
});
|
|
3024
|
+
if (_touchState.primaryTouchId === null ||
|
|
3025
|
+
cancelled.has(_touchState.primaryTouchId)) {
|
|
3026
|
+
_touchState.primaryTouchId = null;
|
|
3027
|
+
}
|
|
3028
|
+
if (!cancelled.size) {
|
|
3029
|
+
return;
|
|
3030
|
+
}
|
|
3031
|
+
var identifiers = Array.from(cancelled);
|
|
3032
|
+
var points = mapToArtboard(event.currentTarget.getBoundingClientRect(), identifiers.map(function (identifier) { return _activeTouches.get(identifier); }));
|
|
3033
|
+
identifiers.forEach(function (identifier) { return _activeTouches.delete(identifier); });
|
|
3034
|
+
var _loop_6 = function (stateMachine) {
|
|
3035
|
+
identifiers.forEach(function (identifier, i) {
|
|
3036
|
+
var _a = points[i], x = _a.x, y = _a.y;
|
|
3037
|
+
stateMachine.pointerUp(x, y, identifier);
|
|
3038
|
+
stateMachine.pointerExit(x, y, identifier);
|
|
3039
|
+
});
|
|
3040
|
+
};
|
|
3041
|
+
for (var _i = 0, stateMachines_7 = stateMachines; _i < stateMachines_7.length; _i++) {
|
|
3042
|
+
var stateMachine = stateMachines_7[_i];
|
|
3043
|
+
_loop_6(stateMachine);
|
|
3044
|
+
}
|
|
3045
|
+
// Advance immediately so the release takes effect synchronously
|
|
3046
|
+
advanceAndDrain(0);
|
|
2921
3047
|
};
|
|
2922
3048
|
/**
|
|
2923
3049
|
* Forwards wheel and trackpad scrolling to the state machines. The page keeps
|