@awcodes/alpine-floating-ui
Version:
Add Floating UI functionality to Alpine 3.x components.
2 lines (1 loc) • 25.5 kB
JavaScript
(()=>{var vt=["top","right","bottom","left"],Pt=["start","end"],At=vt.reduce((t,e)=>t.concat(e,e+"-"+Pt[0],e+"-"+Pt[1]),[]),$=Math.min,P=Math.max,it=Math.round,ot=Math.floor,I=t=>({x:t,y:t}),ce={left:"right",right:"left",bottom:"top",top:"bottom"},le={start:"end",end:"start"};function lt(t,e,i){return P(t,$(e,i))}function N(t,e){return typeof t=="function"?t(e):t}function D(t){return t.split("-")[0]}function W(t){return t.split("-")[1]}function Ot(t){return t==="x"?"y":"x"}function at(t){return t==="y"?"height":"width"}function q(t){return["top","bottom"].includes(D(t))?"y":"x"}function ft(t){return Ot(q(t))}function Rt(t,e,i){i===void 0&&(i=!1);let n=W(t),o=ft(t),s=at(o),r=o==="x"?n===(i?"end":"start")?"right":"left":n==="start"?"bottom":"top";return e.reference[s]>e.floating[s]&&(r=nt(r)),[r,nt(r)]}function Tt(t){let e=nt(t);return[et(t),e,et(e)]}function et(t){return t.replace(/start|end/g,e=>le[e])}function ae(t,e,i){let n=["left","right"],o=["right","left"],s=["top","bottom"],r=["bottom","top"];switch(t){case"top":case"bottom":return i?e?o:n:e?n:o;case"left":case"right":return e?s:r;default:return[]}}function Lt(t,e,i,n){let o=W(t),s=ae(D(t),i==="start",n);return o&&(s=s.map(r=>r+"-"+o),e&&(s=s.concat(s.map(et)))),s}function nt(t){return t.replace(/left|right|bottom|top/g,e=>ce[e])}function fe(t){return{top:0,right:0,bottom:0,left:0,...t}}function ut(t){return typeof t!="number"?fe(t):{top:t,right:t,bottom:t,left:t}}function X(t){return{...t,top:t.y,left:t.x,right:t.x+t.width,bottom:t.y+t.height}}function kt(t,e,i){let{reference:n,floating:o}=t,s=q(e),r=ft(e),l=at(r),c=D(e),a=s==="y",d=n.x+n.width/2-o.width/2,f=n.y+n.height/2-o.height/2,h=n[l]/2-o[l]/2,u;switch(c){case"top":u={x:d,y:n.y-o.height};break;case"bottom":u={x:d,y:n.y+n.height};break;case"right":u={x:n.x+n.width,y:f};break;case"left":u={x:n.x-o.width,y:f};break;default:u={x:n.x,y:n.y}}switch(W(e)){case"start":u[r]-=h*(i&&a?-1:1);break;case"end":u[r]+=h*(i&&a?-1:1);break}return u}var Ft=async(t,e,i)=>{let{placement:n="bottom",strategy:o="absolute",middleware:s=[],platform:r}=i,l=s.filter(Boolean),c=await(r.isRTL==null?void 0:r.isRTL(e)),a=await r.getElementRects({reference:t,floating:e,strategy:o}),{x:d,y:f}=kt(a,n,c),h=n,u={},g=0;for(let p=0;p<l.length;p++){let{name:m,fn:x}=l[p],{x:w,y:b,data:v,reset:A}=await x({x:d,y:f,initialPlacement:n,placement:h,strategy:o,middlewareData:u,rects:a,platform:r,elements:{reference:t,floating:e}});d=w??d,f=b??f,u={...u,[m]:{...u[m],...v}},A&&g<=50&&(g++,typeof A=="object"&&(A.placement&&(h=A.placement),A.rects&&(a=A.rects===!0?await r.getElementRects({reference:t,floating:e,strategy:o}):A.rects),{x:d,y:f}=kt(a,h,c)),p=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:u}};async function U(t,e){var i;e===void 0&&(e={});let{x:n,y:o,platform:s,rects:r,elements:l,strategy:c}=t,{boundary:a="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:u=0}=N(e,t),g=ut(u),m=l[h?f==="floating"?"reference":"floating":f],x=X(await s.getClippingRect({element:(i=await(s.isElement==null?void 0:s.isElement(m)))==null||i?m:m.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:a,rootBoundary:d,strategy:c})),w=f==="floating"?{...r.floating,x:n,y:o}:r.reference,b=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),v=await(s.isElement==null?void 0:s.isElement(b))?await(s.getScale==null?void 0:s.getScale(b))||{x:1,y:1}:{x:1,y:1},A=X(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:w,offsetParent:b,strategy:c}):w);return{top:(x.top-A.top+g.top)/v.y,bottom:(A.bottom-x.bottom+g.bottom)/v.y,left:(x.left-A.left+g.left)/v.x,right:(A.right-x.right+g.right)/v.x}}var $t=t=>({name:"arrow",options:t,async fn(e){let{x:i,y:n,placement:o,rects:s,platform:r,elements:l,middlewareData:c}=e,{element:a,padding:d=0}=N(t,e)||{};if(a==null)return{};let f=ut(d),h={x:i,y:n},u=ft(o),g=at(u),p=await r.getDimensions(a),m=u==="y",x=m?"top":"left",w=m?"bottom":"right",b=m?"clientHeight":"clientWidth",v=s.reference[g]+s.reference[u]-h[u]-s.floating[g],A=h[u]-s.reference[u],O=await(r.getOffsetParent==null?void 0:r.getOffsetParent(a)),y=O?O[b]:0;(!y||!await(r.isElement==null?void 0:r.isElement(O)))&&(y=l.floating[b]||s.floating[g]);let E=v/2-A/2,k=y/2-p[g]/2-1,R=$(f[x],k),T=$(f[w],k),C=R,_=y-p[g]-T,S=y/2-p[g]/2+E,L=lt(C,S,_),M=!c.arrow&&W(o)!=null&&S!==L&&s.reference[g]/2-(S<C?R:T)-p[g]/2<0,B=M?S<C?S-C:S-_:0;return{[u]:h[u]+B,data:{[u]:L,centerOffset:S-L-B,...M&&{alignmentOffset:B}},reset:M}}});function ue(t,e,i){return(t?[...i.filter(o=>W(o)===t),...i.filter(o=>W(o)!==t)]:i.filter(o=>D(o)===o)).filter(o=>t?W(o)===t||(e?et(o)!==o:!1):!0)}var Dt=function(t){return t===void 0&&(t={}),{name:"autoPlacement",options:t,async fn(e){var i,n,o;let{rects:s,middlewareData:r,placement:l,platform:c,elements:a}=e,{crossAxis:d=!1,alignment:f,allowedPlacements:h=At,autoAlignment:u=!0,...g}=N(t,e),p=f!==void 0||h===At?ue(f||null,u,h):h,m=await U(e,g),x=((i=r.autoPlacement)==null?void 0:i.index)||0,w=p[x];if(w==null)return{};let b=Rt(w,s,await(c.isRTL==null?void 0:c.isRTL(a.floating)));if(l!==w)return{reset:{placement:p[0]}};let v=[m[D(w)],m[b[0]],m[b[1]]],A=[...((n=r.autoPlacement)==null?void 0:n.overflows)||[],{placement:w,overflows:v}],O=p[x+1];if(O)return{data:{index:x+1,overflows:A},reset:{placement:O}};let y=A.map(R=>{let T=W(R.placement);return[R.placement,T&&d?R.overflows.slice(0,2).reduce((C,_)=>C+_,0):R.overflows[0],R.overflows]}).sort((R,T)=>R[1]-T[1]),k=((o=y.filter(R=>R[2].slice(0,W(R[0])?2:3).every(T=>T<=0))[0])==null?void 0:o[0])||y[0][0];return k!==l?{data:{index:x+1,overflows:A},reset:{placement:k}}:{}}}},Ht=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var i,n;let{placement:o,middlewareData:s,rects:r,initialPlacement:l,platform:c,elements:a}=e,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:u="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:p=!0,...m}=N(t,e);if((i=s.arrow)!=null&&i.alignmentOffset)return{};let x=D(o),w=D(l)===l,b=await(c.isRTL==null?void 0:c.isRTL(a.floating)),v=h||(w||!p?[nt(l)]:Tt(l));!h&&g!=="none"&&v.push(...Lt(l,p,g,b));let A=[l,...v],O=await U(e,m),y=[],E=((n=s.flip)==null?void 0:n.overflows)||[];if(d&&y.push(O[x]),f){let C=Rt(o,r,b);y.push(O[C[0]],O[C[1]])}if(E=[...E,{placement:o,overflows:y}],!y.every(C=>C<=0)){var k,R;let C=(((k=s.flip)==null?void 0:k.index)||0)+1,_=A[C];if(_)return{data:{index:C,overflows:E},reset:{placement:_}};let S=(R=E.filter(L=>L.overflows[0]<=0).sort((L,M)=>L.overflows[1]-M.overflows[1])[0])==null?void 0:R.placement;if(!S)switch(u){case"bestFit":{var T;let L=(T=E.map(M=>[M.placement,M.overflows.filter(B=>B>0).reduce((B,bt)=>B+bt,0)]).sort((M,B)=>M[1]-B[1])[0])==null?void 0:T[0];L&&(S=L);break}case"initialPlacement":S=l;break}if(o!==S)return{reset:{placement:S}}}return{}}}};function Mt(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function _t(t){return vt.some(e=>t[e]>=0)}var Wt=function(t){return t===void 0&&(t={}),{name:"hide",options:t,async fn(e){let{rects:i}=e,{strategy:n="referenceHidden",...o}=N(t,e);switch(n){case"referenceHidden":{let s=await U(e,{...o,elementContext:"reference"}),r=Mt(s,i.reference);return{data:{referenceHiddenOffsets:r,referenceHidden:_t(r)}}}case"escaped":{let s=await U(e,{...o,altBoundary:!0}),r=Mt(s,i.floating);return{data:{escapedOffsets:r,escaped:_t(r)}}}default:return{}}}}};function Bt(t){let e=$(...t.map(s=>s.left)),i=$(...t.map(s=>s.top)),n=P(...t.map(s=>s.right)),o=P(...t.map(s=>s.bottom));return{x:e,y:i,width:n-e,height:o-i}}function de(t){let e=t.slice().sort((o,s)=>o.y-s.y),i=[],n=null;for(let o=0;o<e.length;o++){let s=e[o];!n||s.y-n.y>n.height/2?i.push([s]):i[i.length-1].push(s),n=s}return i.map(o=>X(Bt(o)))}var zt=function(t){return t===void 0&&(t={}),{name:"inline",options:t,async fn(e){let{placement:i,elements:n,rects:o,platform:s,strategy:r}=e,{padding:l=2,x:c,y:a}=N(t,e),d=Array.from(await(s.getClientRects==null?void 0:s.getClientRects(n.reference))||[]),f=de(d),h=X(Bt(d)),u=ut(l);function g(){if(f.length===2&&f[0].left>f[1].right&&c!=null&&a!=null)return f.find(m=>c>m.left-u.left&&c<m.right+u.right&&a>m.top-u.top&&a<m.bottom+u.bottom)||h;if(f.length>=2){if(q(i)==="y"){let R=f[0],T=f[f.length-1],C=D(i)==="top",_=R.top,S=T.bottom,L=C?R.left:T.left,M=C?R.right:T.right,B=M-L,bt=S-_;return{top:_,bottom:S,left:L,right:M,width:B,height:bt,x:L,y:_}}let m=D(i)==="left",x=P(...f.map(R=>R.right)),w=$(...f.map(R=>R.left)),b=f.filter(R=>m?R.left===w:R.right===x),v=b[0].top,A=b[b.length-1].bottom,O=w,y=x,E=y-O,k=A-v;return{top:v,bottom:A,left:O,right:y,width:E,height:k,x:O,y:v}}return h}let p=await s.getElementRects({reference:{getBoundingClientRect:g},floating:n.floating,strategy:r});return o.reference.x!==p.reference.x||o.reference.y!==p.reference.y||o.reference.width!==p.reference.width||o.reference.height!==p.reference.height?{reset:{rects:p}}:{}}}};async function me(t,e){let{placement:i,platform:n,elements:o}=t,s=await(n.isRTL==null?void 0:n.isRTL(o.floating)),r=D(i),l=W(i),c=q(i)==="y",a=["left","top"].includes(r)?-1:1,d=s&&c?-1:1,f=N(e,t),{mainAxis:h,crossAxis:u,alignmentAxis:g}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...f};return l&&typeof g=="number"&&(u=l==="end"?g*-1:g),c?{x:u*d,y:h*a}:{x:h*a,y:u*d}}var st=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var i,n;let{x:o,y:s,placement:r,middlewareData:l}=e,c=await me(e,t);return r===((i=l.offset)==null?void 0:i.placement)&&(n=l.arrow)!=null&&n.alignmentOffset?{}:{x:o+c.x,y:s+c.y,data:{...c,placement:r}}}}},Nt=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){let{x:i,y:n,placement:o}=e,{mainAxis:s=!0,crossAxis:r=!1,limiter:l={fn:m=>{let{x,y:w}=m;return{x,y:w}}},...c}=N(t,e),a={x:i,y:n},d=await U(e,c),f=q(D(o)),h=Ot(f),u=a[h],g=a[f];if(s){let m=h==="y"?"top":"left",x=h==="y"?"bottom":"right",w=u+d[m],b=u-d[x];u=lt(w,u,b)}if(r){let m=f==="y"?"top":"left",x=f==="y"?"bottom":"right",w=g+d[m],b=g-d[x];g=lt(w,g,b)}let p=l.fn({...e,[h]:u,[f]:g});return{...p,data:{x:p.x-i,y:p.y-n}}}}};var Vt=function(t){return t===void 0&&(t={}),{name:"size",options:t,async fn(e){let{placement:i,rects:n,platform:o,elements:s}=e,{apply:r=()=>{},...l}=N(t,e),c=await U(e,l),a=D(i),d=W(i),f=q(i)==="y",{width:h,height:u}=n.floating,g,p;a==="top"||a==="bottom"?(g=a,p=d===(await(o.isRTL==null?void 0:o.isRTL(s.floating))?"start":"end")?"left":"right"):(p=a,g=d==="end"?"top":"bottom");let m=u-c[g],x=h-c[p],w=!e.middlewareData.shift,b=m,v=x;if(f){let O=h-c.left-c.right;v=d||w?$(x,O):O}else{let O=u-c.top-c.bottom;b=d||w?$(m,O):O}if(w&&!d){let O=P(c.left,0),y=P(c.right,0),E=P(c.top,0),k=P(c.bottom,0);f?v=h-2*(O!==0||y!==0?O+y:P(c.left,c.right)):b=u-2*(E!==0||k!==0?E+k:P(c.top,c.bottom))}await r({...e,availableWidth:v,availableHeight:b});let A=await o.getDimensions(s.floating);return h!==A.width||u!==A.height?{reset:{rects:!0}}:{}}}};function Y(t){return It(t)?(t.nodeName||"").toLowerCase():"#document"}function F(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function V(t){var e;return(e=(It(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function It(t){return t instanceof Node||t instanceof F(t).Node}function j(t){return t instanceof Element||t instanceof F(t).Element}function z(t){return t instanceof HTMLElement||t instanceof F(t).HTMLElement}function jt(t){return typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof F(t).ShadowRoot}function Q(t){let{overflow:e,overflowX:i,overflowY:n,display:o}=H(t);return/auto|scroll|overlay|hidden|clip/.test(e+n+i)&&!["inline","contents"].includes(o)}function Xt(t){return["table","td","th"].includes(Y(t))}function dt(t){let e=mt(),i=H(t);return i.transform!=="none"||i.perspective!=="none"||(i.containerType?i.containerType!=="normal":!1)||!e&&(i.backdropFilter?i.backdropFilter!=="none":!1)||!e&&(i.filter?i.filter!=="none":!1)||["transform","perspective","filter"].some(n=>(i.willChange||"").includes(n))||["paint","layout","strict","content"].some(n=>(i.contain||"").includes(n))}function Yt(t){let e=K(t);for(;z(e)&&!rt(e);){if(dt(e))return e;e=K(e)}return null}function mt(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function rt(t){return["html","body","#document"].includes(Y(t))}function H(t){return F(t).getComputedStyle(t)}function ct(t){return j(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.pageXOffset,scrollTop:t.pageYOffset}}function K(t){if(Y(t)==="html")return t;let e=t.assignedSlot||t.parentNode||jt(t)&&t.host||V(t);return jt(e)?e.host:e}function qt(t){let e=K(t);return rt(e)?t.ownerDocument?t.ownerDocument.body:t.body:z(e)&&Q(e)?e:qt(e)}function J(t,e,i){var n;e===void 0&&(e=[]),i===void 0&&(i=!0);let o=qt(t),s=o===((n=t.ownerDocument)==null?void 0:n.body),r=F(o);return s?e.concat(r,r.visualViewport||[],Q(o)?o:[],r.frameElement&&i?J(r.frameElement):[]):e.concat(o,J(o,[],i))}function Gt(t){let e=H(t),i=parseFloat(e.width)||0,n=parseFloat(e.height)||0,o=z(t),s=o?t.offsetWidth:i,r=o?t.offsetHeight:n,l=it(i)!==s||it(n)!==r;return l&&(i=s,n=r),{width:i,height:n,$:l}}function Ct(t){return j(t)?t:t.contextElement}function Z(t){let e=Ct(t);if(!z(e))return I(1);let i=e.getBoundingClientRect(),{width:n,height:o,$:s}=Gt(e),r=(s?it(i.width):i.width)/n,l=(s?it(i.height):i.height)/o;return(!r||!Number.isFinite(r))&&(r=1),(!l||!Number.isFinite(l))&&(l=1),{x:r,y:l}}var ge=I(0);function Jt(t){let e=F(t);return!mt()||!e.visualViewport?ge:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function pe(t,e,i){return e===void 0&&(e=!1),!i||e&&i!==F(t)?!1:e}function G(t,e,i,n){e===void 0&&(e=!1),i===void 0&&(i=!1);let o=t.getBoundingClientRect(),s=Ct(t),r=I(1);e&&(n?j(n)&&(r=Z(n)):r=Z(t));let l=pe(s,i,n)?Jt(s):I(0),c=(o.left+l.x)/r.x,a=(o.top+l.y)/r.y,d=o.width/r.x,f=o.height/r.y;if(s){let h=F(s),u=n&&j(n)?F(n):n,g=h,p=g.frameElement;for(;p&&n&&u!==g;){let m=Z(p),x=p.getBoundingClientRect(),w=H(p),b=x.left+(p.clientLeft+parseFloat(w.paddingLeft))*m.x,v=x.top+(p.clientTop+parseFloat(w.paddingTop))*m.y;c*=m.x,a*=m.y,d*=m.x,f*=m.y,c+=b,a+=v,g=F(p),p=g.frameElement}}return X({width:d,height:f,x:c,y:a})}var he=[":popover-open",":modal"];function Qt(t){return he.some(e=>{try{return t.matches(e)}catch{return!1}})}function xe(t){let{elements:e,rect:i,offsetParent:n,strategy:o}=t,s=o==="fixed",r=V(n),l=e?Qt(e.floating):!1;if(n===r||l&&s)return i;let c={scrollLeft:0,scrollTop:0},a=I(1),d=I(0),f=z(n);if((f||!f&&!s)&&((Y(n)!=="body"||Q(r))&&(c=ct(n)),z(n))){let h=G(n);a=Z(n),d.x=h.x+n.clientLeft,d.y=h.y+n.clientTop}return{width:i.width*a.x,height:i.height*a.y,x:i.x*a.x-c.scrollLeft*a.x+d.x,y:i.y*a.y-c.scrollTop*a.y+d.y}}function we(t){return Array.from(t.getClientRects())}function Zt(t){return G(V(t)).left+ct(t).scrollLeft}function ye(t){let e=V(t),i=ct(t),n=t.ownerDocument.body,o=P(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),s=P(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),r=-i.scrollLeft+Zt(t),l=-i.scrollTop;return H(n).direction==="rtl"&&(r+=P(e.clientWidth,n.clientWidth)-o),{width:o,height:s,x:r,y:l}}function be(t,e){let i=F(t),n=V(t),o=i.visualViewport,s=n.clientWidth,r=n.clientHeight,l=0,c=0;if(o){s=o.width,r=o.height;let a=mt();(!a||a&&e==="fixed")&&(l=o.offsetLeft,c=o.offsetTop)}return{width:s,height:r,x:l,y:c}}function ve(t,e){let i=G(t,!0,e==="fixed"),n=i.top+t.clientTop,o=i.left+t.clientLeft,s=z(t)?Z(t):I(1),r=t.clientWidth*s.x,l=t.clientHeight*s.y,c=o*s.x,a=n*s.y;return{width:r,height:l,x:c,y:a}}function Ut(t,e,i){let n;if(e==="viewport")n=be(t,i);else if(e==="document")n=ye(V(t));else if(j(e))n=ve(e,i);else{let o=Jt(t);n={...e,x:e.x-o.x,y:e.y-o.y}}return X(n)}function te(t,e){let i=K(t);return i===e||!j(i)||rt(i)?!1:H(i).position==="fixed"||te(i,e)}function Ae(t,e){let i=e.get(t);if(i)return i;let n=J(t,[],!1).filter(l=>j(l)&&Y(l)!=="body"),o=null,s=H(t).position==="fixed",r=s?K(t):t;for(;j(r)&&!rt(r);){let l=H(r),c=dt(r);!c&&l.position==="fixed"&&(o=null),(s?!c&&!o:!c&&l.position==="static"&&!!o&&["absolute","fixed"].includes(o.position)||Q(r)&&!c&&te(t,r))?n=n.filter(d=>d!==r):o=l,r=K(r)}return e.set(t,n),n}function Oe(t){let{element:e,boundary:i,rootBoundary:n,strategy:o}=t,r=[...i==="clippingAncestors"?Ae(e,this._c):[].concat(i),n],l=r[0],c=r.reduce((a,d)=>{let f=Ut(e,d,o);return a.top=P(f.top,a.top),a.right=$(f.right,a.right),a.bottom=$(f.bottom,a.bottom),a.left=P(f.left,a.left),a},Ut(e,l,o));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function Re(t){let{width:e,height:i}=Gt(t);return{width:e,height:i}}function Ce(t,e,i){let n=z(e),o=V(e),s=i==="fixed",r=G(t,!0,s,e),l={scrollLeft:0,scrollTop:0},c=I(0);if(n||!n&&!s)if((Y(e)!=="body"||Q(o))&&(l=ct(e)),n){let f=G(e,!0,s,e);c.x=f.x+e.clientLeft,c.y=f.y+e.clientTop}else o&&(c.x=Zt(o));let a=r.left+l.scrollLeft-c.x,d=r.top+l.scrollTop-c.y;return{x:a,y:d,width:r.width,height:r.height}}function Kt(t,e){return!z(t)||H(t).position==="fixed"?null:e?e(t):t.offsetParent}function ee(t,e){let i=F(t);if(!z(t)||Qt(t))return i;let n=Kt(t,e);for(;n&&Xt(n)&&H(n).position==="static";)n=Kt(n,e);return n&&(Y(n)==="html"||Y(n)==="body"&&H(n).position==="static"&&!dt(n))?i:n||Yt(t)||i}var Ee=async function(t){let e=this.getOffsetParent||ee,i=this.getDimensions;return{reference:Ce(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,...await i(t.floating)}}};function Se(t){return H(t).direction==="rtl"}var Pe={convertOffsetParentRelativeRectToViewportRelativeRect:xe,getDocumentElement:V,getClippingRect:Oe,getOffsetParent:ee,getElementRects:Ee,getClientRects:we,getDimensions:Re,getScale:Z,isElement:j,isRTL:Se};function Te(t,e){let i=null,n,o=V(t);function s(){var l;clearTimeout(n),(l=i)==null||l.disconnect(),i=null}function r(l,c){l===void 0&&(l=!1),c===void 0&&(c=1),s();let{left:a,top:d,width:f,height:h}=t.getBoundingClientRect();if(l||e(),!f||!h)return;let u=ot(d),g=ot(o.clientWidth-(a+f)),p=ot(o.clientHeight-(d+h)),m=ot(a),w={rootMargin:-u+"px "+-g+"px "+-p+"px "+-m+"px",threshold:P(0,$(1,c))||1},b=!0;function v(A){let O=A[0].intersectionRatio;if(O!==c){if(!b)return r();O?r(!1,O):n=setTimeout(()=>{r(!1,1e-7)},100)}b=!1}try{i=new IntersectionObserver(v,{...w,root:o.ownerDocument})}catch{i=new IntersectionObserver(v,w)}i.observe(t)}return r(!0),s}function Et(t,e,i,n){n===void 0&&(n={});let{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:r=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:c=!1}=n,a=Ct(t),d=o||s?[...a?J(a):[],...J(e)]:[];d.forEach(x=>{o&&x.addEventListener("scroll",i,{passive:!0}),s&&x.addEventListener("resize",i)});let f=a&&l?Te(a,i):null,h=-1,u=null;r&&(u=new ResizeObserver(x=>{let[w]=x;w&&w.target===a&&u&&(u.unobserve(e),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var b;(b=u)==null||b.observe(e)})),i()}),a&&!c&&u.observe(a),u.observe(e));let g,p=c?G(t):null;c&&m();function m(){let x=G(t);p&&(x.x!==p.x||x.y!==p.y||x.width!==p.width||x.height!==p.height)&&i(),p=x,g=requestAnimationFrame(m)}return i(),()=>{var x;d.forEach(w=>{o&&w.removeEventListener("scroll",i),s&&w.removeEventListener("resize",i)}),f?.(),(x=u)==null||x.disconnect(),u=null,c&&cancelAnimationFrame(g)}}var tt=Dt,gt=Nt,pt=Ht,ht=Vt,xt=Wt,wt=$t,yt=zt;var St=(t,e,i)=>{let n=new Map,o={platform:Pe,...i},s={...o.platform,_c:n};return Ft(t,e,{...o,platform:s})};var ne=t=>{let e={placement:"bottom",strategy:"absolute",middleware:[]},i=Object.keys(t),n=o=>t[o];return i.includes("offset")&&e.middleware.push(st(n("offset"))),i.includes("teleport")&&(e.strategy="fixed"),i.includes("placement")&&(e.placement=n("placement")),i.includes("autoPlacement")&&!i.includes("flip")&&e.middleware.push(tt(n("autoPlacement"))),i.includes("flip")&&e.middleware.push(pt(n("flip"))),i.includes("shift")&&e.middleware.push(gt(n("shift"))),i.includes("inline")&&e.middleware.push(yt(n("inline"))),i.includes("arrow")&&e.middleware.push(wt(n("arrow"))),i.includes("hide")&&e.middleware.push(xt(n("hide"))),i.includes("size")&&e.middleware.push(ht(n("size"))),e};var ie=(t,e)=>{let i={component:{trap:!1},float:{placement:"bottom",strategy:"absolute",middleware:[]}},n=o=>t[t.indexOf(o)+1];if(t.includes("trap")&&(i.component.trap=!0),t.includes("teleport")&&(i.float.strategy="fixed"),t.includes("offset")&&i.float.middleware.push(st(e.offset||10)),t.includes("placement")&&(i.float.placement=n("placement")),t.includes("autoPlacement")&&!t.includes("flip")&&i.float.middleware.push(tt(e.autoPlacement)),t.includes("flip")&&i.float.middleware.push(pt(e.flip)),t.includes("shift")&&i.float.middleware.push(gt(e.shift)),t.includes("inline")&&i.float.middleware.push(yt(e.inline)),t.includes("arrow")&&i.float.middleware.push(wt(e.arrow)),t.includes("hide")&&i.float.middleware.push(xt(e.hide)),t.includes("size")){let o=e.size?.availableWidth??null,s=e.size?.availableHeight??null;o&&delete e.size.availableWidth,s&&delete e.size.availableHeight,i.float.middleware.push(ht({...e.size,apply({availableWidth:r,availableHeight:l,elements:c}){Object.assign(c.floating.style,{maxWidth:`${o??r}px`,maxHeight:`${s??l}px`})}}))}return i};var oe=t=>{var e="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz".split(""),i="";t||(t=Math.floor(Math.random()*e.length));for(var n=0;n<t;n++)i+=e[Math.floor(Math.random()*e.length)];return i};function se(t,e=()=>{}){let i=!1;return function(){i?e.apply(this,arguments):(i=!0,t.apply(this,arguments))}}function re(t){let e={dismissable:!0,trap:!1};function i(n,o=null){if(!!n){if(n.hasAttribute("aria-expanded")||n.setAttribute("aria-expanded",!1),o.hasAttribute("id"))n.setAttribute("aria-controls",o.getAttribute("id"));else{let s=`panel-${oe(8)}`;n.setAttribute("aria-controls",s),o.setAttribute("id",s)}o.setAttribute("aria-modal",!0),o.setAttribute("role","dialog")}}t.magic("float",n=>(o={},s={})=>{let r={...e,...s},l=Object.keys(o).length>0?ne(o):{middleware:[tt()]},c=n,a=n.parentElement.closest("[x-data]"),d=a.querySelector('[x-ref="panel"]');i(c,d);function f(){return d.style.display=="block"}function h(){d.style.display="none",c.setAttribute("aria-expanded","false"),r.trap&&d.setAttribute("x-trap","false"),Et(n,d,p)}function u(){d.style.display="block",c.setAttribute("aria-expanded","true"),r.trap&&d.setAttribute("x-trap","true"),p()}function g(){f()?h():u()}async function p(){return await St(n,d,l).then(({middlewareData:m,placement:x,x:w,y:b})=>{if(m.arrow){let v=m.arrow?.x,A=m.arrow?.y,O=l.middleware.filter(E=>E.name=="arrow")[0].options.element,y={top:"bottom",right:"left",bottom:"top",left:"right"}[x.split("-")[0]];Object.assign(O.style,{left:v!=null?`${v}px`:"",top:A!=null?`${A}px`:"",right:"",bottom:"",[y]:"-4px"})}if(m.hide){let{referenceHidden:v}=m.hide;Object.assign(d.style,{visibility:v?"hidden":"visible"})}Object.assign(d.style,{left:`${w}px`,top:`${b}px`})})}r.dismissable&&(window.addEventListener("click",m=>{!a.contains(m.target)&&f()&&g()}),window.addEventListener("keydown",m=>{m.key==="Escape"&&f()&&g()},!0)),g()}),t.directive("float",(n,{modifiers:o,expression:s},{evaluate:r,effect:l})=>{let c=s?r(s):{},a=o.length>0?ie(o,c):{},d=null;a.float.strategy=="fixed"&&(n.style.position="fixed");let f=y=>n.parentElement&&!n.parentElement.closest("[x-data]").contains(y.target)?n.close():null,h=y=>y.key==="Escape"?n.close():null,u=n.getAttribute("x-ref"),g=n.parentElement.closest("[x-data]"),p=g.querySelectorAll(`[\\@click^="$refs.${u}"]`),m=g.querySelectorAll(`[x-on\\:click^="$refs.${u}"]`);n.style.setProperty("display","none"),i([...p,...m][0],n),n._x_isShown=!1,n.trigger=null,n._x_doHide||(n._x_doHide=()=>{n.style.setProperty("display","none",o.includes("important")?"important":void 0)}),n._x_doShow||(n._x_doShow=()=>{n.style.setProperty("display","block",o.includes("important")?"important":void 0)});let x=()=>{n._x_doHide(),n._x_isShown=!1},w=()=>{n._x_doShow(),n._x_isShown=!0},b=()=>setTimeout(w),v=se(y=>y?w():x(),y=>{typeof n._x_toggleAndCascadeWithTransitions=="function"?n._x_toggleAndCascadeWithTransitions(n,y,w,x):y?b():x()}),A,O=!0;l(()=>r(y=>{!O&&y===A||(o.includes("immediate")&&(y?b():x()),v(y),A=y,O=!1)})),n.open=async function(y){n.trigger=y.currentTarget?y.currentTarget:y,v(!0),n.trigger.setAttribute("aria-expanded","true"),a.component.trap&&n.setAttribute("x-trap","true"),d=Et(n.trigger,n,()=>{St(n.trigger,n,a.float).then(({middlewareData:E,placement:k,x:R,y:T})=>{if(E.arrow){let C=E.arrow?.x,_=E.arrow?.y,S=a.float.middleware.filter(M=>M.name=="arrow")[0].options.element,L={top:"bottom",right:"left",bottom:"top",left:"right"}[k.split("-")[0]];Object.assign(S.style,{left:C!=null?`${C}px`:"",top:_!=null?`${_}px`:"",right:"",bottom:"",[L]:"-4px"})}if(E.hide){let{referenceHidden:C}=E.hide;Object.assign(n.style,{visibility:C?"hidden":"visible"})}Object.assign(n.style,{left:`${R}px`,top:`${T}px`})})}),window.addEventListener("click",f),window.addEventListener("keydown",h,!0)},n.close=function(){if(!n._x_isShown)return!1;v(!1),n.trigger.setAttribute("aria-expanded","false"),a.component.trap&&n.setAttribute("x-trap","false"),d(),window.removeEventListener("click",f),window.removeEventListener("keydown",h,!1)},n.toggle=function(y){n._x_isShown?n.close():n.open(y)}})}document.addEventListener("alpine:init",()=>{re(window.Alpine)});})();