const t=["top","right","bottom","left"],e=["start","end"],n=t.reduce(((t,n)=>t.concat(n,n+"-"+e[0],n+"-"+e[1])),[]),r=Math.min,i=Math.max,o={left:"right",right:"left",bottom:"top",top:"bottom"};function l(t,e,n){return i(t,r(e,n))}function a(t,e){return"function"==typeof t?t(e):t}function s(t){return t.split("-")[0]}function c(t){return t.split("-")[1]}function f(t){return"x"===t?"y":"x"}function u(t){return"y"===t?"height":"width"}function m(t){const e=t[0];return"t"===e||"b"===e?"y":"x"}function d(t){return f(m(t))}function g(t,e,n){void 0===n&&(n=!1);const r=c(t),i=d(t),o=u(i);let l="x"===i?r===(n?"end":"start")?"right":"left":"start"===r?"bottom":"top";return e.reference[o]>e.floating[o]&&(l=b(l)),[l,b(l)]}function p(t){return t.includes("start")?t.replace("start","end"):t.replace("end","start")}const h=["left","right"],y=["right","left"],w=["top","bottom"],x=["bottom","top"];function v(t,e,n,r){const i=c(t);let o=function(t,e,n){switch(t){case"top":case"bottom":return n?e?y:h:e?h:y;case"left":case"right":return e?w:x;default:return[]}}(s(t),"start"===n,r);return i&&(o=o.map((t=>t+"-"+i)),e&&(o=o.concat(o.map(p)))),o}function b(t){const e=s(t);return o[e]+t.slice(e.length)}function A(t){return"number"!=typeof t?function(t){var e,n,r,i;return{top:null!=(e=t.top)?e:0,right:null!=(n=t.right)?n:0,bottom:null!=(r=t.bottom)?r:0,left:null!=(i=t.left)?i:0}}(t):{top:t,right:t,bottom:t,left:t}}function R(t){const{x:e,y:n,width:r,height:i}=t;return{width:r,height:i,top:n,left:e,right:e+r,bottom:n+i,x:e,y:n}}function O(t,e,n){let{reference:r,floating:i}=t;const o=m(e),l=d(e),a=u(l),f=s(e),g="y"===o,p=r.x+r.width/2-i.width/2,h=r.y+r.height/2-i.height/2,y=r[a]/2-i[a]/2;let w;switch(f){case"top":w={x:p,y:r.y-i.height};break;case"bottom":w={x:p,y:r.y+r.height};break;case"right":w={x:r.x+r.width,y:h};break;case"left":w={x:r.x-i.width,y:h};break;default:w={x:r.x,y:r.y}}const x=c(e);return x&&(w[l]+=y*("end"===x?1:-1)*(n&&g?-1:1)),w}async function P(t,e){var n;void 0===e&&(e={});const{x:r,y:i,platform:o,rects:l,elements:s,strategy:c}=t,{boundary:f="clippingAncestors",rootBoundary:u="viewport",elementContext:m="floating",altBoundary:d=!1,padding:g=0}=a(e,t),p=A(g),h=s[d?"floating"===m?"reference":"floating":m],y=R(await o.getClippingRect({element:null==(n=await(null==o.isElement?void 0:o.isElement(h)))||n?h:h.contextElement||await(null==o.getDocumentElement?void 0:o.getDocumentElement(s.floating)),boundary:f,rootBoundary:u,strategy:c})),w="floating"===m?{x:r,y:i,width:l.floating.width,height:l.floating.height}:l.reference,x=await(null==o.getOffsetParent?void 0:o.getOffsetParent(s.floating)),v=await(null==o.isElement?void 0:o.isElement(x))&&await(null==o.getScale?void 0:o.getScale(x))||{x:1,y:1},b=R(o.convertOffsetParentRelativeRectToViewportRelativeRect?await o.convertOffsetParentRelativeRectToViewportRelativeRect({elements:s,rect:w,offsetParent:x,strategy:c}):w);return{top:(y.top-b.top+p.top)/v.y,bottom:(b.bottom-y.bottom+p.bottom)/v.y,left:(y.left-b.left+p.left)/v.x,right:(b.right-y.right+p.right)/v.x}}const D=async(t,e,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:o=[],platform:l}=n,a=l.detectOverflow?l:{...l,detectOverflow:P},s=await(null==l.isRTL?void 0:l.isRTL(e));let c=await l.getElementRects({reference:t,floating:e,strategy:i}),{x:f,y:u}=O(c,r,s),m=r,d=0;const g={};for(let n=0;n({name:"arrow",options:t,async fn(e){const{x:n,y:i,placement:o,rects:s,platform:f,elements:m,middlewareData:g}=e,{element:p,padding:h=0}=a(t,e)||{};if(null==p)return{};const y=A(h),w={x:n,y:i},x=d(o),v=u(x),b=await f.getDimensions(p),R="y"===x,O=R?"top":"left",P=R?"bottom":"right",D=R?"clientHeight":"clientWidth",E=s.reference[v]+s.reference[x]-w[x]-s.floating[v],T=w[x]-s.reference[x],L=await(null==f.getOffsetParent?void 0:f.getOffsetParent(p));let k=L?L[D]:0;k&&await(null==f.isElement?void 0:f.isElement(L))||(k=m.floating[D]||s.floating[v]);const C=E/2-T/2,H=k/2-b[v]/2-1,B=r(y[O],H),S=r(y[P],H),F=k-b[v]-S,M=k/2-b[v]/2+C,V=l(B,M,F),W=!g.arrow&&null!=c(o)&&M!==V&&s.reference[v]/2-(Mc(e)===t)),...n.filter((e=>c(e)!==t))]:n.filter((t=>s(t)===t))).filter((n=>!t||c(n)===t||!!e&&p(n)!==n))}(y||null,x,w):w,A=(null==(r=f.autoPlacement)?void 0:r.index)||0,R=b[A];if(null==R)return{};if(u!==R)return{reset:{placement:b[0]}};const O=await m.detectOverflow(e,v),P=g(R,l,await(null==m.isRTL?void 0:m.isRTL(d.floating))),D=[O[s(R)],O[P[0]],O[P[1]]],E=[...(null==(i=f.autoPlacement)?void 0:i.overflows)||[],{placement:R,overflows:D}],T=b[A+1];if(T)return{data:{index:A+1,overflows:E},reset:{placement:T}};const L=E.map((t=>{const e=c(t.placement);return[t.placement,e&&h?t.overflows.slice(0,2).reduce(((t,e)=>t+e),0):t.overflows[0],t.overflows]})).sort(((t,e)=>t[1]-e[1])),k=(null==(o=L.filter((t=>t[2].slice(0,c(t[0])?2:3).every((t=>t<=0))))[0])?void 0:o[0])||L[0][0];return k!==u?{data:{index:A+1,overflows:E},reset:{placement:k}}:{}}}},L=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(e){var n,r;const{placement:i,middlewareData:o,rects:l,initialPlacement:c,platform:f,elements:u}=e,{mainAxis:d=!0,crossAxis:h=!0,fallbackPlacements:y,fallbackStrategy:w="bestFit",fallbackAxisSideDirection:x="none",flipAlignment:A=!0,...R}=a(t,e);if(null!=(n=o.arrow)&&n.alignmentOffset)return{};const O=s(i),P=m(c),D=s(c)===c,E=await(null==f.isRTL?void 0:f.isRTL(u.floating)),T=y||(D||!A?[b(c)]:function(t){const e=b(t);return[p(t),e,p(e)]}(c)),L="none"!==x;!y&&L&&T.push(...v(c,A,x,E));const k=[c,...T],C=await f.detectOverflow(e,R),H=[];let B=(null==(r=o.flip)?void 0:r.overflows)||[];if(d&&H.push(C[O]),h){const t=g(i,l,E);H.push(C[t[0]],C[t[1]])}if(B=[...B,{placement:i,overflows:H}],!H.every((t=>t<=0))){var S,F;const t=((null==(S=o.flip)?void 0:S.index)||0)+1,e=k[t];if(e){if(!("alignment"===h&&P!==m(e))||B.every((t=>m(t.placement)!==P||t.overflows[0]>0)))return{data:{index:t,overflows:B},reset:{placement:e}}}let n=null==(F=B.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:F.placement;if(!n)switch(w){case"bestFit":{var M;const t=null==(M=B.filter((t=>{if(L){const e=m(t.placement);return e===P||"y"===e}return!0})).map((t=>[t.placement,t.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)])).sort(((t,e)=>t[1]-e[1]))[0])?void 0:M[0];t&&(n=t);break}case"initialPlacement":n=c}if(i!==n)return{reset:{placement:n}}}return{}}}};function k(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function C(e){return t.some((t=>e[t]>=0))}const H=function(t){return void 0===t&&(t={}),{name:"hide",options:t,async fn(e){const{rects:n,platform:r}=e,{strategy:i="referenceHidden",...o}=a(t,e);switch(i){case"referenceHidden":{const t=k(await r.detectOverflow(e,{...o,elementContext:"reference"}),n.reference);return{data:{referenceHiddenOffsets:t,referenceHidden:C(t)}}}case"escaped":{const t=k(await r.detectOverflow(e,{...o,altBoundary:!0}),n.floating);return{data:{escapedOffsets:t,escaped:C(t)}}}default:return{}}}}};function B(t){const e=r(...t.map((t=>t.left))),n=r(...t.map((t=>t.top)));return{x:e,y:n,width:i(...t.map((t=>t.right)))-e,height:i(...t.map((t=>t.bottom)))-n}}const S=function(t){return void 0===t&&(t={}),{name:"inline",options:t,async fn(e){const{placement:n,elements:o,rects:l,platform:c,strategy:f}=e,{padding:u=2,x:d,y:g}=a(t,e),p=Array.from(await(null==c.getClientRects?void 0:c.getClientRects(o.reference))||[]);if(!p.length)return{};const h=function(t){const e=t.slice().sort(((t,e)=>t.y-e.y)),n=[];let r=null;for(let t=0;tr.height/2?n.push([i]):n[n.length-1].push(i),r=i}return n.map((t=>R(B(t))))}(p),y=R(B(p)),w=A(u);const x=await c.getElementRects({reference:{getBoundingClientRect:function(){if(2===h.length&&(h[0].left>h[1].right||h[1].left>h[0].right)&&null!=d&&null!=g)return h.find((t=>d>t.left-w.left&&dt.top-w.top&&g=2){if("y"===m(n)){const t=h[0],e=h[h.length-1],r="top"===s(n),i=t.top,o=e.bottom,l=r?t.left:e.left;return R({x:l,y:i,width:(r?t.right:e.right)-l,height:o-i})}const t="left"===s(n),e=i(...h.map((t=>t.right))),o=r(...h.map((t=>t.left))),l=h.filter((n=>t?n.left===o:n.right===e)),a=l[0].top,c=l[l.length-1].bottom;return R({x:o,y:a,width:e-o,height:c-a})}return y}},floating:o.floating,strategy:f});return l.reference.x!==x.reference.x||l.reference.y!==x.reference.y||l.reference.width!==x.reference.width||l.reference.height!==x.reference.height?{reset:{rects:x}}:{}}}},F=new Set(["left","top"]);const M=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){var n,r;const{x:i,y:o,placement:l,middlewareData:f}=e,u=await async function(t,e){const{placement:n,platform:r,elements:i}=t,o=await(null==r.isRTL?void 0:r.isRTL(i.floating)),l=s(n),f=c(n),u="y"===m(n),d=F.has(l)?-1:1,g=o&&u?-1:1,p=a(e,t);let{mainAxis:h,crossAxis:y,alignmentAxis:w}="number"==typeof p?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return f&&"number"==typeof w&&(y="end"===f?-1*w:w),u?{x:y*g,y:h*d}:{x:h*d,y:y*g}}(e,t);return l===(null==(n=f.offset)?void 0:n.placement)&&null!=(r=f.arrow)&&r.alignmentOffset?{}:{x:i+u.x,y:o+u.y,data:{...u,placement:l}}}}},V=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:r,placement:i,platform:o}=e,{mainAxis:s=!0,crossAxis:c=!1,limiter:u={fn:t=>{let{x:e,y:n}=t;return{x:e,y:n}}},...d}=a(t,e),g={x:n,y:r},p=await o.detectOverflow(e,d),h=m(i),y=f(h);let w=g[y],x=g[h];const v=(t,e)=>l(e+p["y"===t?"top":"left"],e,e-p["y"===t?"bottom":"right"]);s&&(w=v(y,w)),c&&(x=v(h,x));const b=u.fn({...e,[y]:w,[h]:x});return{...b,data:{x:b.x-n,y:b.y-r,enabled:{[y]:s,[h]:c}}}}}},W=function(t){return void 0===t&&(t={}),{options:t,fn(e){var n,r;const{x:i,y:o,placement:l,rects:c,middlewareData:u}=e,{offset:d=0,mainAxis:g=!0,crossAxis:p=!0}=a(t,e),h={x:i,y:o},y=m(l),w=f(y);let x=h[w],v=h[y];const b=a(d,e),A="number"==typeof b?{mainAxis:b,crossAxis:0}:{mainAxis:null!=(n=b.mainAxis)?n:0,crossAxis:null!=(r=b.crossAxis)?r:0};if(g){const t="y"===w?"height":"width",e=c.reference[w]-c.floating[t]+A.mainAxis,n=c.reference[w]+c.reference[t]-A.mainAxis;xn&&(x=n)}if(p){var R,O;const t="y"===w?"width":"height",e=F.has(s(l)),n=c.reference[y]-c.floating[t]+(e&&(null==(R=u.offset)?void 0:R[y])||0)+(e?0:A.crossAxis),r=c.reference[y]+c.reference[t]+(e?0:(null==(O=u.offset)?void 0:O[y])||0)-(e?A.crossAxis:0);vr&&(v=r)}return{[w]:x,[y]:v}}}},j=function(t){return void 0===t&&(t={}),{name:"size",options:t,async fn(e){const{placement:n,rects:o,platform:l,elements:f}=e,{apply:u=()=>{},...d}=a(t,e),g=await l.detectOverflow(e,d),p=s(n),h=c(n),y="y"===m(n),{width:w,height:x}=o.floating;let v,b;"top"===p||"bottom"===p?(v=p,b=h===(await(null==l.isRTL?void 0:l.isRTL(f.floating))?"start":"end")?"left":"right"):(b=p,v="end"===h?"top":"bottom");const A=x-g.top-g.bottom,R=w-g.left-g.right,O=r(x-g[v],A),P=r(w-g[b],R),D=e.middlewareData.shift,E=!D;let T=O,L=P;null!=D&&D.enabled.x&&(L=R),null!=D&&D.enabled.y&&(T=A),E&&!h&&(y?L=w-2*i(g.left,g.right):T=x-2*i(g.top,g.bottom)),await u({...e,availableWidth:L,availableHeight:T});const k=await l.getDimensions(f.floating);return w!==k.width||x!==k.height?{reset:{rects:!0}}:{}}}};export{E as arrow,T as autoPlacement,D as computePosition,P as detectOverflow,L as flip,H as hide,S as inline,W as limitShift,M as offset,R as rectToClientRect,V as shift,j as size};