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