@larva.io/webcomponents
Version:
Fentrica SmartUnits WebComponents package
56 lines (53 loc) • 1.95 kB
JavaScript
/*!
* (C) Fentrica http://fentrica.com - Seee LICENSE.md
*/
import { d as clamp } from './p-C3CE5OlV.js';
import { createGesture } from './p-Bg81B2hG.js';
const createSwipeBackGesture = (el, canStartHandler, onStartHandler, onMoveHandler, onEndHandler) => {
const win = el.ownerDocument.defaultView;
const canStart = (detail) => {
return detail.startY <= 100 && canStartHandler();
};
const onMove = (detail) => {
// set the transition animation's progress
const delta = detail.deltaY;
const stepValue = delta / win.innerHeight;
onMoveHandler(stepValue);
};
const onEnd = (detail) => {
// the swipe back gesture has ended
const delta = detail.deltaY;
const height = win.innerHeight;
const stepValue = delta / height;
const velocity = detail.velocityY;
const z = height / 2.0;
const shouldComplete = velocity >= 0 && (velocity > 0.2 || detail.deltaY > z);
const missing = shouldComplete ? 1 - stepValue : stepValue;
const missingDistance = missing * height;
let realDur = 0;
if (missingDistance > 5) {
const dur = missingDistance / Math.abs(velocity);
realDur = Math.min(dur, 540);
}
/**
* TODO: stepValue can sometimes return negative values
* or values greater than 1 which should not be possible.
* Need to investigate more to find where the issue is.
*/
onEndHandler(shouldComplete, (stepValue <= 0) ? 0.01 : clamp(0, stepValue, 0.9999), realDur);
};
return createGesture({
el,
gestureName: 'goback-down',
direction: 'y',
gesturePriority: 40,
threshold: 10,
canStart,
onStart: onStartHandler,
onMove,
onEnd
});
};
export { createSwipeBackGesture };
//# sourceMappingURL=p-BGScfV_K.js.map
//# sourceMappingURL=p-BGScfV_K.js.map