import{D as e,U as t,_ as n,b as r,et as i,s as a}from"./runtime-core.esm-bundler-Babufkcf.js";import{t as o}from"./runtime-dom.esm-bundler-Ce9t-RuK.js";import{t as s}from"./create-CGAkPJkS.js";import{m as ee,t as te,u as ne}from"./dom-BXiDqs7-.js";import{a as c}from"./QIcon-cTVL6ikA.js";import{t as l}from"./focus-manager-IyiFCKRs.js";import{n as u,t as d}from"./use-dark-B6e4te0z.js";import{A as f,C as re,M as p,N as m,O as ie,P as h,_ as ae,b as g,d as oe,f as _,j as v,k as y,m as b,p as se,w as ce}from"./index-uCtpzrM3.js";import{a as le,c as ue,i as x,l as S,n as de,o as C,r as w,s as fe,t as T}from"./position-engine-DZZAA7X-.js";var E=s({name:`QMenu`,inheritAttrs:!1,props:{...S,...p,...u,...y,persistent:Boolean,autoClose:Boolean,separateClosePopup:Boolean,noEscDismiss:Boolean,noRouteDismiss:Boolean,noRefocus:Boolean,noFocus:Boolean,fit:Boolean,cover:Boolean,square:Boolean,anchor:{type:String,validator:x},self:{type:String,validator:x},offset:{type:Array,validator:w},scrollTarget:g,touchPosition:Boolean,maxHeight:{type:String,default:null},maxWidth:{type:String,default:null}},emits:[...v,`click`,`escapeKey`],setup(s,{slots:u,emit:p,attrs:g}){let v=null,y,x,S,w=n(),{proxy:E}=w,{$q:D}=E,O=i(null),k=i(!1),A=a(()=>!s.persistent&&!s.noRouteDismiss),j=d(s,D),{registerTick:M,removeTick:N}=m(),{registerTimeout:P}=h(),{transitionProps:F,transitionStyle:I}=ie(s),{localScrollTarget:L,changeScrollEvent:R,unconfigureScrollTarget:z}=fe(s,X),{anchorEl:B,canShow:pe}=ue({showing:k}),{hide:V}=f({showing:k,canShow:pe,handleShow:J,handleHide:ve,hideOnRouteChange:A,processOnMount:!0}),{showPortal:H,hidePortal:U,renderPortal:me}=re(w,O,be,`menu`),W={anchorEl:B,innerRef:O,onClickOutside(e){if(!s.persistent&&k.value)return V(e),(e.type===`touchstart`||e.target.classList.contains(`q-dialog__backdrop`))&&ee(e),!0}},G=a(()=>T(s.anchor||(s.cover?`center middle`:`bottom start`),D.lang.rtl)),he=a(()=>s.cover?G.value:T(s.self||`top start`,D.lang.rtl)),ge=a(()=>(s.square?` q-menu--square`:``)+(j.value?` q-menu--dark q-dark`:``)),_e=a(()=>s.autoClose?{onClick:ye}:{}),K=a(()=>k.value&&!s.persistent);t(K,e=>{e?(se(Q),le(W)):(b(Q),C(W))});function q(){l(()=>{let e=O.value;e&&!e.contains(document.activeElement)&&(e=e.querySelector(`[autofocus][tabindex], [data-autofocus][tabindex]`)||e.querySelector(`[autofocus] [tabindex], [data-autofocus] [tabindex]`)||e.querySelector(`[autofocus], [data-autofocus]`)||e,e.focus({preventScroll:!0}))})}function J(e){if(v=s.noRefocus?null:document.activeElement,oe(Z),H(),X(),y=void 0,e!==void 0&&(s.touchPosition||s.contextMenu)){let t=ne(e);if(t.left!==void 0){let{top:e,left:n}=B.value.getBoundingClientRect();y={left:t.left-n,top:t.top-e}}}x===void 0&&(x=t(()=>D.screen.width+`|`+D.screen.height+`|`+s.self+`|`+s.anchor+`|`+D.lang.rtl,$)),s.noFocus||document.activeElement.blur(),M(()=>{$(),s.noFocus||q()}),P(()=>{D.platform.is.ios&&(S=s.autoClose,O.value.click()),$(),H(!0),p(`show`,e)},s.transitionDuration)}function ve(e){N(),U(),Y(!0),v!==null&&(e===void 0||!e.qClickOutside)&&(((e?.type.indexOf(`key`)===0?v.closest(`[tabindex]:not([tabindex^="-"])`):void 0)||v).focus(),v=null),P(()=>{U(!0),p(`hide`,e)},s.transitionDuration)}function Y(e){y=void 0,x!==void 0&&(x(),x=void 0),(e||k.value)&&(_(Z),z(),C(W),b(Q)),e||(v=null)}function X(){(B.value!==null||s.scrollTarget!==void 0)&&(L.value=ae(B.value,s.scrollTarget),R(L.value,$))}function ye(e){S?S=!1:(ce(E,e),p(`click`,e))}function Z(e){K.value&&!s.noFocus&&!te(O.value,e.target)&&q()}function Q(e){s.noEscDismiss||(p(`escapeKey`),V(e))}function $(){de({targetEl:O.value,offset:s.offset,anchorEl:B.value,anchorOrigin:G.value,selfOrigin:he.value,absoluteOffset:y,fit:s.fit,cover:s.cover,maxHeight:s.maxHeight,maxWidth:s.maxWidth})}function be(){return r(o,F.value,()=>k.value?r(`div`,{role:`menu`,...g,ref:O,tabindex:-1,class:[`q-menu q-position-engine scroll`+ge.value,g.class],style:[g.style,I.value],..._e.value},c(u.default)):null)}return e(()=>{Y()}),Object.assign(E,{focus:q,updatePosition:$}),me}});export{E as t};