openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
2 lines • 3.87 kB
JavaScript
import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{d as t,u as n}from"./control-ui-core-YphAl4aM.js";var r,i,a,o,s,c;function l(){return(l=e((()=>{n(),r=44,i=.15,a=7,o=1.25,s=`a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex='-1'])`,c=class{constructor(e,t){this.host=e,this.requestOpen=t,this.swipe=null,this.handleStart=e=>{if(this.reset(),!this.canOpen()||e.touches.length!==1)return;let t=e.composedPath(),n=t.find(e=>e instanceof HTMLElement&&e.classList.contains(`content`));if(!n)return;let r=t.slice(0,t.indexOf(n)).some(e=>e instanceof Element?e.matches(`a, button, input, textarea, select, pre, [role='slider'], [contenteditable]:not([contenteditable='false'])`)?!0:e instanceof HTMLElement&&e.scrollWidth>e.clientWidth+1:!1),i=e.touches[0];r||!i||(this.swipe={identifier:i.identifier,startX:i.clientX,startY:i.clientY,lockedHorizontal:!1,drawerWidth:0,drawer:null,backdrop:null})},this.handleMove=e=>{let t=this.swipe,n=t?Array.from(e.touches).find(e=>e.identifier===t.identifier):void 0;if(!t||e.touches.length!==1||!n){this.cancel();return}let r=n.clientX-t.startX,i=n.clientY-t.startY;if(t.lockedHorizontal){e.preventDefault(),this.paint(t,r);return}let s=Math.abs(r),c=Math.abs(i);Math.max(s,c)<a||(r>0&&s>=c*o?(t.lockedHorizontal=!0,e.preventDefault(),this.paint(t,r)):(r<=-7||c>=s*o)&&this.reset())},this.handleEnd=e=>{let t=this.swipe,n=t?Array.from(e.changedTouches).find(e=>e.identifier===t.identifier):void 0;if(!t||!n||!t.lockedHorizontal||!this.canOpen()){this.reset();return}let a=n.clientX-t.startX;this.paint(t,a);let o=a>=Math.max(r,t.drawerWidth*i);this.swipe=null,o?this.requestOpen():requestAnimationFrame(()=>this.reset())},this.handleCancel=()=>this.cancel()}canOpen(){return t()&&!this.host.navDrawerOpen&&!this.host.onboardingMode}connect(){this.host.addEventListener(`touchstart`,this.handleStart,{passive:!0}),this.host.addEventListener(`touchmove`,this.handleMove,{passive:!1}),this.host.addEventListener(`touchend`,this.handleEnd,{passive:!0}),this.host.addEventListener(`touchcancel`,this.handleCancel,{passive:!0}),this.host.navDrawerOpen&&this.opened()}disconnect(){this.host.removeEventListener(`touchstart`,this.handleStart),this.host.removeEventListener(`touchmove`,this.handleMove),this.host.removeEventListener(`touchend`,this.handleEnd),this.host.removeEventListener(`touchcancel`,this.handleCancel),this.closed()}reset(){this.swipe=null;let e=this.host.querySelector(`.shell-nav`),t=this.host.querySelector(`.shell-nav-backdrop`);e?.removeAttribute(`data-nav-drawer-dragging`),e?.style.removeProperty(`transform`),e?.style.removeProperty(`opacity`),t?.removeAttribute(`data-nav-drawer-dragging`),t?.style.removeProperty(`visibility`),t?.style.removeProperty(`opacity`)}opened(){this.host.updateComplete.then(()=>{if(!this.host.isConnected||!this.host.navDrawerOpen)return;this.reset();let e=this.host.querySelector(`.shell-nav`);(this.focusable()[0]??e)?.focus({preventScroll:!0})})}closed(){this.reset()}focusable(){let e=this.host.querySelector(`.shell-nav`);return e?[...e.querySelectorAll(s)].filter(e=>e.checkVisibility()):[]}paint(e,t){let n=e.drawer??this.host.querySelector(`.shell-nav`),r=e.backdrop??this.host.querySelector(`.shell-nav-backdrop`);if(!n||!r)return;e.drawer=n,e.backdrop=r,e.drawerWidth===0&&(e.drawerWidth=n.getBoundingClientRect().width,n.setAttribute(`data-nav-drawer-dragging`,``),r.setAttribute(`data-nav-drawer-dragging`,``));let i=Math.min(e.drawerWidth,Math.max(0,t));n.style.transform=`translateX(${i-e.drawerWidth}px)`,n.style.opacity=`1`,r.style.visibility=`visible`,r.style.opacity=String(e.drawerWidth>0?i/e.drawerWidth:0)}cancel(){this.swipe=null,requestAnimationFrame(()=>this.reset())}}})))()}l();export{c as NavDrawerSwipeOwner};
//# sourceMappingURL=nav-drawer-swipe.runtime-BJvyGdY6.js.map