@huluvu424242/honey-slideshow
Version:
Text to Speech component wich is reading texts from DOM elements.
49 lines (48 loc) • 1.9 kB
JavaScript
import { c as clamp } from './helpers-29d709d1.js';
import './gesture-controller-5bf8565e.js';
import { createGesture } from './index-82044e24.js';
var createSwipeBackGesture = function (el, canStartHandler, onStartHandler, onMoveHandler, onEndHandler) {
var win = el.ownerDocument.defaultView;
var canStart = function (detail) {
return detail.startX <= 50 && canStartHandler();
};
var onMove = function (detail) {
// set the transition animation's progress
var delta = detail.deltaX;
var stepValue = delta / win.innerWidth;
onMoveHandler(stepValue);
};
var onEnd = function (detail) {
// the swipe back gesture has ended
var delta = detail.deltaX;
var width = win.innerWidth;
var stepValue = delta / width;
var velocity = detail.velocityX;
var z = width / 2.0;
var shouldComplete = velocity >= 0 && (velocity > 0.2 || detail.deltaX > z);
var missing = shouldComplete ? 1 - stepValue : stepValue;
var missingDistance = missing * width;
var realDur = 0;
if (missingDistance > 5) {
var 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: el,
gestureName: 'goback-swipe',
gesturePriority: 40,
threshold: 10,
canStart: canStart,
onStart: onStartHandler,
onMove: onMove,
onEnd: onEnd
});
};
export { createSwipeBackGesture };