import{__assign as t}from"../../../node_modules/tslib/tslib.es6.js";import{isMouseEvent as n,isTouchEvent as e}from"./utils/event-type.js";import{extractEventInfo as o}from"../events/event-info.js";import i,{getFrameData as s,cancelSync as r}from"../../../../framesync/dist/es/index.js";import{secondsToMilliseconds as a}from"../utils/time-conversion.js";import{addPointerEvent as v}from"../events/use-pointer-event.js";import{distance as p}from"../../../../popmotion/dist/es/utils/distance.js";import{pipe as l}from"../../../../popmotion/dist/es/utils/pipe.js";var m=function(){function a(r,a,m){var u=this,d=(void 0===m?{}:m).transformPagePoint;if(this.startEvent=null,this.lastMoveEvent=null,this.lastMoveEventInfo=null,this.handlers={},this.updatePoint=function(){if(u.lastMoveEvent&&u.lastMoveEventInfo){var n=h(u.lastMoveEventInfo,u.history),e=null!==u.startEvent,o=p(n.offset,{x:0,y:0})>=3;if(e||o){var i=n.point,r=s().timestamp;u.history.push(t(t({},i),{timestamp:r}));var a=u.handlers,v=a.onStart,l=a.onMove;e||(v&&v(u.lastMoveEvent,n),u.startEvent=u.lastMoveEvent),l&&l(u.lastMoveEvent,n)}}},this.handlePointerMove=function(t,e){u.lastMoveEvent=t,u.lastMoveEventInfo=f(e,u.transformPagePoint),n(t)&&0===t.buttons?u.handlePointerUp(t,e):i.update(u.updatePoint,!0)},this.handlePointerUp=function(t,n){u.end();var e=u.handlers.onEnd;if(e&&u.startEvent){var o=h(f(n,u.transformPagePoint),u.history);e&&e(t,o)}},!(e(r)&&r.touches.length>1)){this.handlers=a,this.transformPagePoint=d;var y=f(o(r),this.transformPagePoint),c=y.point,P=s().timestamp;this.history=[t(t({},c),{timestamp:P})];var E=a.onSessionStart;E&&E(r,h(y,this.history)),this.removeListeners=l(v(window,"pointermove",this.handlePointerMove),v(window,"pointerup",this.handlePointerUp),v(window,"pointercancel",this.handlePointerUp))}}return a.prototype.updateHandlers=function(t){this.handlers=t},a.prototype.end=function(){this.removeListeners&&this.removeListeners(),r.update(this.updatePoint)},a}();function f(t,n){return n?{point:n(t.point)}:t}function u(t,n){return{x:t.x-n.x,y:t.y-n.y}}function h(t,n){var e=t.point;return{point:e,delta:u(e,y(n)),offset:u(e,d(n)),velocity:c(n,.1)}}function d(t){return t[0]}function y(t){return t[t.length-1]}function c(t,n){if(t.length<2)return{x:0,y:0};for(var e=t.length-1,o=null,i=y(t);e>=0&&(o=t[e],!(i.timestamp-o.timestamp>a(n)));)e--;if(!o)return{x:0,y:0};var s=(i.timestamp-o.timestamp)/1e3;if(0===s)return{x:0,y:0};var r={x:(i.x-o.x)/s,y:(i.y-o.y)/s};return r.x===1/0&&(r.x=0),r.y===1/0&&(r.y=0),r}export{m as PanSession};
//# sourceMappingURL=PanSession.js.map
