import{n as e}from"./create-CGAkPJkS.js";import{n as t}from"./Platform-BxNC0BGj.js";import{a as n,d as r,f as i,i as a,l as o,m as s,p as c,s as l,u}from"./dom-BXiDqs7-.js";import{d}from"./position-engine-DZZAA7X-.js";import{n as f,t as p}from"./touch-BowB9tqj.js";function m(e,t,n){let r=u(e),i,a=r.left-t.event.x,o=r.top-t.event.y,s=Math.abs(a),c=Math.abs(o),l=t.direction;l.horizontal&&!l.vertical?i=a<0?`left`:`right`:!l.horizontal&&l.vertical?i=o<0?`up`:`down`:l.up&&o<0?(i=`up`,s>c&&(l.left&&a<0?i=`left`:l.right&&a>0&&(i=`right`))):l.down&&o>0?(i=`down`,s>c&&(l.left&&a<0?i=`left`:l.right&&a>0&&(i=`right`))):l.left&&a<0?(i=`left`,s<c&&(l.up&&o<0?i=`up`:l.down&&o>0&&(i=`down`))):l.right&&a>0&&(i=`right`,s<c&&(l.up&&o<0?i=`up`:l.down&&o>0&&(i=`down`)));let d=!1;if(i===void 0&&n===!1){if(t.event.isFirst||t.event.lastDir===void 0)return{};i=t.event.lastDir,d=!0,i===`left`||i===`right`?(r.left-=a,s=0,a=0):(r.top-=o,c=0,o=0)}return{synthetic:d,payload:{evt:e,touch:t.event.mouse!==!0,mouse:t.event.mouse===!0,position:r,direction:i,isFirst:t.event.isFirst,isFinal:n===!0,duration:Date.now()-t.event.time,distance:{x:s,y:c},offset:{x:a,y:o},delta:{x:r.left-t.event.lastX,y:r.top-t.event.lastY}}}}function h(){document.body.classList.remove(`no-pointer-events--children`)}var g=0,_=e({name:`touch-pan`,beforeMount(e,{value:_,modifiers:v}){if(!v.mouse&&!t.has.touch)return;function y(e,t){v.mouse&&t?s(e):(v.stop&&c(e),v.prevent&&r(e))}let b={uid:`qvtp_`+g++,handler:_,modifiers:v,direction:p(v),noop:o,mouseStart(e){f(e,b)&&l(e)&&(a(b,`temp`,[[document,`mousemove`,`move`,`notPassiveCapture`],[document,`mouseup`,`end`,`passiveCapture`]]),b.start(e,!0))},touchStart(e){if(f(e,b)){let t=e.target;a(b,`temp`,[[t,`touchmove`,`move`,`notPassiveCapture`],[t,`touchcancel`,`end`,`passiveCapture`],[t,`touchend`,`end`,`passiveCapture`]]),b.start(e)}},start(n,a){if(t.is.firefox&&i(e,!0),b.lastEvt=n,a||v.stop){if(!b.direction.all&&(!a||!b.modifiers.mouseAllDir&&!b.modifiers.mousealldir)){let e=n.type.includes(`mouse`)?new MouseEvent(n.type,n):new TouchEvent(n.type,n);n.defaultPrevented&&r(e),n.cancelBubble&&c(e),Object.assign(e,{qKeyEvent:n.qKeyEvent,qClickOutside:n.qClickOutside,qAnchorHandled:n.qAnchorHandled,qClonedBy:n.qClonedBy===void 0?[b.uid]:n.qClonedBy.concat(b.uid)}),b.initialEvent={target:n.target,event:e}}c(n)}let{left:o,top:s}=u(n);b.event={x:o,y:s,time:Date.now(),mouse:a===!0,detected:!1,isFirst:!0,isFinal:!1,lastX:o,lastY:s}},move(e){if(b.event===void 0)return;let t=u(e),n=t.left-b.event.x,r=t.top-b.event.y;if(n===0&&r===0)return;b.lastEvt=e;let i=b.event.mouse===!0,a=()=>{y(e,i);let t;!v.preserveCursor&&!v.preservecursor&&(t=document.documentElement.style.cursor||``,document.documentElement.style.cursor=`grabbing`),i&&document.body.classList.add(`no-pointer-events--children`),document.body.classList.add(`non-selectable`),d(),b.styleCleanup=e=>{b.styleCleanup=void 0,t!==void 0&&(document.documentElement.style.cursor=t),document.body.classList.remove(`non-selectable`),i?e===void 0?h():setTimeout(()=>{h(),e()},50):e!==void 0&&e()}};if(b.event.detected){b.event.isFirst||y(e,b.event.mouse);let{payload:t,synthetic:n}=m(e,b,!1);t!==void 0&&(b.handler(t)===!1?b.end(e):(b.styleCleanup===void 0&&b.event.isFirst&&a(),b.event.lastX=t.position.left,b.event.lastY=t.position.top,b.event.lastDir=n?void 0:t.direction,b.event.isFirst=!1));return}if(b.direction.all||i&&(b.modifiers.mouseAllDir||b.modifiers.mousealldir)){a(),b.event.detected=!0,b.move(e);return}let o=Math.abs(n),s=Math.abs(r);o!==s&&(b.direction.horizontal&&o>s||b.direction.vertical&&o<s||b.direction.up&&o<s&&r<0||b.direction.down&&o<s&&r>0||b.direction.left&&o>s&&n<0||b.direction.right&&o>s&&n>0?(b.event.detected=!0,b.move(e)):b.end(e,!0))},end(r,a){if(b.event!==void 0){if(n(b,`temp`),t.is.firefox&&i(e,!1),a)b.styleCleanup?.(),!b.event.detected&&b.initialEvent!==void 0&&b.initialEvent.target.dispatchEvent(b.initialEvent.event);else if(b.event.detected){b.event.isFirst&&b.handler(m(r===void 0?b.lastEvt:r,b).payload);let{payload:e}=m(r===void 0?b.lastEvt:r,b,!0),t=()=>{b.handler(e)};b.styleCleanup===void 0?t():b.styleCleanup(t)}b.event=void 0,b.initialEvent=void 0,b.lastEvt=void 0}}};if(e.__qtouchpan=b,v.mouse){let t=v.mouseCapture||v.mousecapture?`Capture`:``;a(b,`main`,[[e,`mousedown`,`mouseStart`,`passive${t}`]])}t.has.touch&&a(b,`main`,[[e,`touchstart`,`touchStart`,`passive${v.capture?`Capture`:``}`],[e,`touchmove`,`noop`,`notPassiveCapture`]])},updated(e,t){let n=e.__qtouchpan;n!==void 0&&(t.oldValue!==t.value&&(typeof value!=`function`&&n.end(),n.handler=t.value),n.direction=p(t.modifiers))},beforeUnmount(e){let r=e.__qtouchpan;r!==void 0&&(r.event!==void 0&&r.end(),n(r,`main`),n(r,`temp`),t.is.firefox&&i(e,!1),r.styleCleanup?.(),delete e.__qtouchpan)}});export{_ as t};