UNPKG

@larva.io/webcomponents

Version:

Fentrica SmartUnits WebComponents package

58 lines (54 loc) 2.02 kB
/*! * (C) Fentrica http://fentrica.com - Seee LICENSE.md */ 'use strict'; var helpers = require('./helpers-DNl8-cDE.js'); var index = require('./index-eReWClpK.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 : helpers.clamp(0, stepValue, 0.9999), realDur); }; return index.createGesture({ el, gestureName: 'goback-down', direction: 'y', gesturePriority: 40, threshold: 10, canStart, onStart: onStartHandler, onMove, onEnd }); }; exports.createSwipeBackGesture = createSwipeBackGesture; //# sourceMappingURL=swipe-down-B9z7l8Ns.js.map //# sourceMappingURL=swipe-down-B9z7l8Ns.js.map