UNPKG

@vkm-js/popover

Version:

An Alpinejs plugin to add a x-popover on any tag element.

2 lines (1 loc) 21.8 kB
(()=>{var Ct=["top","right","bottom","left"],Rt=["start","end"],wt=Ct.reduce((t,e)=>t.concat(e,e+"-"+Rt[0],e+"-"+Rt[1]),[]),q=Math.min,I=Math.max,rt=Math.round,st=Math.floor,B=t=>({x:t,y:t}),ie={left:"right",right:"left",bottom:"top",top:"bottom"},re={start:"end",end:"start"};function ft(t,e,n){return I(t,q(e,n))}function J(t,e){return typeof t=="function"?t(e):t}function z(t){return t.split("-")[0]}function F(t){return t.split("-")[1]}function xt(t){return t==="x"?"y":"x"}function ut(t){return t==="y"?"height":"width"}function X(t){return["top","bottom"].includes(z(t))?"y":"x"}function dt(t){return xt(X(t))}function vt(t,e,n){n===void 0&&(n=!1);let o=F(t),i=dt(t),c=ut(i),s=i==="x"?o===(n?"end":"start")?"right":"left":o==="start"?"bottom":"top";return e.reference[c]>e.floating[c]&&(s=it(s)),[s,it(s)]}function Tt(t){let e=it(t);return[ot(t),e,ot(e)]}function ot(t){return t.replace(/start|end/g,e=>re[e])}function se(t,e,n){let o=["left","right"],i=["right","left"],c=["top","bottom"],s=["bottom","top"];switch(t){case"top":case"bottom":return n?e?i:o:e?o:i;case"left":case"right":return e?c:s;default:return[]}}function Et(t,e,n,o){let i=F(t),c=se(z(t),n==="start",o);return i&&(c=c.map(s=>s+"-"+i),e&&(c=c.concat(c.map(ot)))),c}function it(t){return t.replace(/left|right|bottom|top/g,e=>ie[e])}function ce(t){return{top:0,right:0,bottom:0,left:0,...t}}function yt(t){return typeof t!="number"?ce(t):{top:t,right:t,bottom:t,left:t}}function K(t){let{x:e,y:n,width:o,height:i}=t;return{width:o,height:i,top:n,left:e,right:e+o,bottom:n+i,x:e,y:n}}function Lt(t,e,n){let{reference:o,floating:i}=t,c=X(e),s=dt(e),r=ut(s),l=z(e),a=c==="y",m=o.x+o.width/2-i.width/2,f=o.y+o.height/2-i.height/2,d=o[r]/2-i[r]/2,u;switch(l){case"top":u={x:m,y:o.y-i.height};break;case"bottom":u={x:m,y:o.y+o.height};break;case"right":u={x:o.x+o.width,y:f};break;case"left":u={x:o.x-i.width,y:f};break;default:u={x:o.x,y:o.y}}switch(F(e)){case"start":u[s]-=d*(n&&a?-1:1);break;case"end":u[s]+=d*(n&&a?-1:1);break}return u}var St=async(t,e,n)=>{let{placement:o="bottom",strategy:i="absolute",middleware:c=[],platform:s}=n,r=c.filter(Boolean),l=await(s.isRTL==null?void 0:s.isRTL(e)),a=await s.getElementRects({reference:t,floating:e,strategy:i}),{x:m,y:f}=Lt(a,o,l),d=o,u={},g=0;for(let w=0;w<r.length;w++){let{name:h,fn:p}=r[w],{x,y:v,data:A,reset:y}=await p({x:m,y:f,initialPlacement:o,placement:d,strategy:i,middlewareData:u,rects:a,platform:s,elements:{reference:t,floating:e}});m=x??m,f=v??f,u={...u,[h]:{...u[h],...A}},y&&g<=50&&(g++,typeof y=="object"&&(y.placement&&(d=y.placement),y.rects&&(a=y.rects===!0?await s.getElementRects({reference:t,floating:e,strategy:i}):y.rects),{x:m,y:f}=Lt(a,d,l)),w=-1)}return{x:m,y:f,placement:d,strategy:i,middlewareData:u}};async function ct(t,e){var n;e===void 0&&(e={});let{x:o,y:i,platform:c,rects:s,elements:r,strategy:l}=t,{boundary:a="clippingAncestors",rootBoundary:m="viewport",elementContext:f="floating",altBoundary:d=!1,padding:u=0}=J(e,t),g=yt(u),h=r[d?f==="floating"?"reference":"floating":f],p=K(await c.getClippingRect({element:(n=await(c.isElement==null?void 0:c.isElement(h)))==null||n?h:h.contextElement||await(c.getDocumentElement==null?void 0:c.getDocumentElement(r.floating)),boundary:a,rootBoundary:m,strategy:l})),x=f==="floating"?{x:o,y:i,width:s.floating.width,height:s.floating.height}:s.reference,v=await(c.getOffsetParent==null?void 0:c.getOffsetParent(r.floating)),A=await(c.isElement==null?void 0:c.isElement(v))?await(c.getScale==null?void 0:c.getScale(v))||{x:1,y:1}:{x:1,y:1},y=K(c.convertOffsetParentRelativeRectToViewportRelativeRect?await c.convertOffsetParentRelativeRectToViewportRelativeRect({elements:r,rect:x,offsetParent:v,strategy:l}):x);return{top:(p.top-y.top+g.top)/A.y,bottom:(y.bottom-p.bottom+g.bottom)/A.y,left:(p.left-y.left+g.left)/A.x,right:(y.right-p.right+g.right)/A.x}}var Pt=t=>({name:"arrow",options:t,async fn(e){let{x:n,y:o,placement:i,rects:c,platform:s,elements:r,middlewareData:l}=e,{element:a,padding:m=0}=J(t,e)||{};if(a==null)return{};let f=yt(m),d={x:n,y:o},u=dt(i),g=ut(u),w=await s.getDimensions(a),h=u==="y",p=h?"top":"left",x=h?"bottom":"right",v=h?"clientHeight":"clientWidth",A=c.reference[g]+c.reference[u]-d[u]-c.floating[g],y=d[u]-c.reference[u],b=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a)),R=b?b[v]:0;(!R||!await(s.isElement==null?void 0:s.isElement(b)))&&(R=r.floating[v]||c.floating[g]);let T=A/2-y/2,C=R/2-w[g]/2-1,O=q(f[p],C),L=q(f[x],C),D=O,N=R-w[g]-L,S=R/2-w[g]/2+T,M=ft(D,S,N),U=!l.arrow&&F(i)!=null&&S!==M&&c.reference[g]/2-(S<D?O:L)-w[g]/2<0,V=U?S<D?S-D:S-N:0;return{[u]:d[u]+V,data:{[u]:M,centerOffset:S-M-V,...U&&{alignmentOffset:V}},reset:U}}});function le(t,e,n){return(t?[...n.filter(i=>F(i)===t),...n.filter(i=>F(i)!==t)]:n.filter(i=>z(i)===i)).filter(i=>t?F(i)===t||(e?ot(i)!==i:!1):!0)}var kt=function(t){return t===void 0&&(t={}),{name:"autoPlacement",options:t,async fn(e){var n,o,i;let{rects:c,middlewareData:s,placement:r,platform:l,elements:a}=e,{crossAxis:m=!1,alignment:f,allowedPlacements:d=wt,autoAlignment:u=!0,...g}=J(t,e),w=f!==void 0||d===wt?le(f||null,u,d):d,h=await ct(e,g),p=((n=s.autoPlacement)==null?void 0:n.index)||0,x=w[p];if(x==null)return{};let v=vt(x,c,await(l.isRTL==null?void 0:l.isRTL(a.floating)));if(r!==x)return{reset:{placement:w[0]}};let A=[h[z(x)],h[v[0]],h[v[1]]],y=[...((o=s.autoPlacement)==null?void 0:o.overflows)||[],{placement:x,overflows:A}],b=w[p+1];if(b)return{data:{index:p+1,overflows:y},reset:{placement:b}};let R=y.map(O=>{let L=F(O.placement);return[O.placement,L&&m?O.overflows.slice(0,2).reduce((D,N)=>D+N,0):O.overflows[0],O.overflows]}).sort((O,L)=>O[1]-L[1]),C=((i=R.filter(O=>O[2].slice(0,F(O[0])?2:3).every(L=>L<=0))[0])==null?void 0:i[0])||R[0][0];return C!==r?{data:{index:p+1,overflows:y},reset:{placement:C}}:{}}}},Dt=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,o;let{placement:i,middlewareData:c,rects:s,initialPlacement:r,platform:l,elements:a}=e,{mainAxis:m=!0,crossAxis:f=!0,fallbackPlacements:d,fallbackStrategy:u="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:w=!0,...h}=J(t,e);if((n=c.arrow)!=null&&n.alignmentOffset)return{};let p=z(i),x=X(r),v=z(r)===r,A=await(l.isRTL==null?void 0:l.isRTL(a.floating)),y=d||(v||!w?[it(r)]:Tt(r)),b=g!=="none";!d&&b&&y.push(...Et(r,w,g,A));let R=[r,...y],T=await ct(e,h),C=[],O=((o=c.flip)==null?void 0:o.overflows)||[];if(m&&C.push(T[p]),f){let M=vt(i,s,A);C.push(T[M[0]],T[M[1]])}if(O=[...O,{placement:i,overflows:C}],!C.every(M=>M<=0)){var L,D;let M=(((L=c.flip)==null?void 0:L.index)||0)+1,U=R[M];if(U){var N;let j=f==="alignment"?x!==X(U):!1,W=((N=O[0])==null?void 0:N.overflows[0])>0;if(!j||W)return{data:{index:M,overflows:O},reset:{placement:U}}}let V=(D=O.filter(j=>j.overflows[0]<=0).sort((j,W)=>j.overflows[1]-W.overflows[1])[0])==null?void 0:D.placement;if(!V)switch(u){case"bestFit":{var S;let j=(S=O.filter(W=>{if(b){let Y=X(W.placement);return Y===x||Y==="y"}return!0}).map(W=>[W.placement,W.overflows.filter(Y=>Y>0).reduce((Y,oe)=>Y+oe,0)]).sort((W,Y)=>W[1]-Y[1])[0])==null?void 0:S[0];j&&(V=j);break}case"initialPlacement":V=r;break}if(i!==V)return{reset:{placement:V}}}return{}}}};async function ae(t,e){let{placement:n,platform:o,elements:i}=t,c=await(o.isRTL==null?void 0:o.isRTL(i.floating)),s=z(n),r=F(n),l=X(n)==="y",a=["left","top"].includes(s)?-1:1,m=c&&l?-1:1,f=J(e,t),{mainAxis:d,crossAxis:u,alignmentAxis:g}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return r&&typeof g=="number"&&(u=r==="end"?g*-1:g),l?{x:u*m,y:d*a}:{x:d*a,y:u*m}}var Mt=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,o;let{x:i,y:c,placement:s,middlewareData:r}=e,l=await ae(e,t);return s===((n=r.offset)==null?void 0:n.placement)&&(o=r.arrow)!=null&&o.alignmentOffset?{}:{x:i+l.x,y:c+l.y,data:{...l,placement:s}}}}},Bt=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){let{x:n,y:o,placement:i}=e,{mainAxis:c=!0,crossAxis:s=!1,limiter:r={fn:h=>{let{x:p,y:x}=h;return{x:p,y:x}}},...l}=J(t,e),a={x:n,y:o},m=await ct(e,l),f=X(z(i)),d=xt(f),u=a[d],g=a[f];if(c){let h=d==="y"?"top":"left",p=d==="y"?"bottom":"right",x=u+m[h],v=u-m[p];u=ft(x,u,v)}if(s){let h=f==="y"?"top":"left",p=f==="y"?"bottom":"right",x=g+m[h],v=g-m[p];g=ft(x,g,v)}let w=r.fn({...e,[d]:u,[f]:g});return{...w,data:{x:w.x-n,y:w.y-o,enabled:{[d]:c,[f]:s}}}}}};function mt(){return typeof window<"u"}function G(t){return Ht(t)?(t.nodeName||"").toLowerCase():"#document"}function E(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function H(t){var e;return(e=(Ht(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function Ht(t){return mt()?t instanceof Node||t instanceof E(t).Node:!1}function P(t){return mt()?t instanceof Element||t instanceof E(t).Element:!1}function $(t){return mt()?t instanceof HTMLElement||t instanceof E(t).HTMLElement:!1}function Ft(t){return!mt()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof E(t).ShadowRoot}function et(t){let{overflow:e,overflowX:n,overflowY:o,display:i}=k(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+n)&&!["inline","contents"].includes(i)}function $t(t){return["table","td","th"].includes(G(t))}function lt(t){return[":popover-open",":modal"].some(e=>{try{return t.matches(e)}catch{return!1}})}function gt(t){let e=ht(),n=P(t)?k(t):t;return["transform","translate","scale","rotate","perspective"].some(o=>n[o]?n[o]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||["transform","translate","scale","rotate","perspective","filter"].some(o=>(n.willChange||"").includes(o))||["paint","layout","strict","content"].some(o=>(n.contain||"").includes(o))}function Nt(t){let e=_(t);for(;$(e)&&!Q(e);){if(gt(e))return e;if(lt(e))return null;e=_(e)}return null}function ht(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function Q(t){return["html","body","#document"].includes(G(t))}function k(t){return E(t).getComputedStyle(t)}function at(t){return P(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function _(t){if(G(t)==="html")return t;let e=t.assignedSlot||t.parentNode||Ft(t)&&t.host||H(t);return Ft(e)?e.host:e}function Wt(t){let e=_(t);return Q(e)?t.ownerDocument?t.ownerDocument.body:t.body:$(e)&&et(e)?e:Wt(e)}function tt(t,e,n){var o;e===void 0&&(e=[]),n===void 0&&(n=!0);let i=Wt(t),c=i===((o=t.ownerDocument)==null?void 0:o.body),s=E(i);if(c){let r=pt(s);return e.concat(s,s.visualViewport||[],et(i)?i:[],r&&n?tt(r):[])}return e.concat(i,tt(i,[],n))}function pt(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function It(t){let e=k(t),n=parseFloat(e.width)||0,o=parseFloat(e.height)||0,i=$(t),c=i?t.offsetWidth:n,s=i?t.offsetHeight:o,r=rt(n)!==c||rt(o)!==s;return r&&(n=c,o=s),{width:n,height:o,$:r}}function At(t){return P(t)?t:t.contextElement}function nt(t){let e=At(t);if(!$(e))return B(1);let n=e.getBoundingClientRect(),{width:o,height:i,$:c}=It(e),s=(c?rt(n.width):n.width)/o,r=(c?rt(n.height):n.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!r||!Number.isFinite(r))&&(r=1),{x:s,y:r}}var fe=B(0);function _t(t){let e=E(t);return!ht()||!e.visualViewport?fe:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function ue(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==E(t)?!1:e}function Z(t,e,n,o){e===void 0&&(e=!1),n===void 0&&(n=!1);let i=t.getBoundingClientRect(),c=At(t),s=B(1);e&&(o?P(o)&&(s=nt(o)):s=nt(t));let r=ue(c,n,o)?_t(c):B(0),l=(i.left+r.x)/s.x,a=(i.top+r.y)/s.y,m=i.width/s.x,f=i.height/s.y;if(c){let d=E(c),u=o&&P(o)?E(o):o,g=d,w=pt(g);for(;w&&o&&u!==g;){let h=nt(w),p=w.getBoundingClientRect(),x=k(w),v=p.left+(w.clientLeft+parseFloat(x.paddingLeft))*h.x,A=p.top+(w.clientTop+parseFloat(x.paddingTop))*h.y;l*=h.x,a*=h.y,m*=h.x,f*=h.y,l+=v,a+=A,g=E(w),w=pt(g)}}return K({width:m,height:f,x:l,y:a})}function Ot(t,e){let n=at(t).scrollLeft;return e?e.left+n:Z(H(t)).left+n}function jt(t,e,n){n===void 0&&(n=!1);let o=t.getBoundingClientRect(),i=o.left+e.scrollLeft-(n?0:Ot(t,o)),c=o.top+e.scrollTop;return{x:i,y:c}}function de(t){let{elements:e,rect:n,offsetParent:o,strategy:i}=t,c=i==="fixed",s=H(o),r=e?lt(e.floating):!1;if(o===s||r&&c)return n;let l={scrollLeft:0,scrollTop:0},a=B(1),m=B(0),f=$(o);if((f||!f&&!c)&&((G(o)!=="body"||et(s))&&(l=at(o)),$(o))){let u=Z(o);a=nt(o),m.x=u.x+o.clientLeft,m.y=u.y+o.clientTop}let d=s&&!f&&!c?jt(s,l,!0):B(0);return{width:n.width*a.x,height:n.height*a.y,x:n.x*a.x-l.scrollLeft*a.x+m.x+d.x,y:n.y*a.y-l.scrollTop*a.y+m.y+d.y}}function me(t){return Array.from(t.getClientRects())}function ge(t){let e=H(t),n=at(t),o=t.ownerDocument.body,i=I(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),c=I(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight),s=-n.scrollLeft+Ot(t),r=-n.scrollTop;return k(o).direction==="rtl"&&(s+=I(e.clientWidth,o.clientWidth)-i),{width:i,height:c,x:s,y:r}}function he(t,e){let n=E(t),o=H(t),i=n.visualViewport,c=o.clientWidth,s=o.clientHeight,r=0,l=0;if(i){c=i.width,s=i.height;let a=ht();(!a||a&&e==="fixed")&&(r=i.offsetLeft,l=i.offsetTop)}return{width:c,height:s,x:r,y:l}}function pe(t,e){let n=Z(t,!0,e==="fixed"),o=n.top+t.clientTop,i=n.left+t.clientLeft,c=$(t)?nt(t):B(1),s=t.clientWidth*c.x,r=t.clientHeight*c.y,l=i*c.x,a=o*c.y;return{width:s,height:r,x:l,y:a}}function zt(t,e,n){let o;if(e==="viewport")o=he(t,n);else if(e==="document")o=ge(H(t));else if(P(e))o=pe(e,n);else{let i=_t(t);o={x:e.x-i.x,y:e.y-i.y,width:e.width,height:e.height}}return K(o)}function Yt(t,e){let n=_(t);return n===e||!P(n)||Q(n)?!1:k(n).position==="fixed"||Yt(n,e)}function we(t,e){let n=e.get(t);if(n)return n;let o=tt(t,[],!1).filter(r=>P(r)&&G(r)!=="body"),i=null,c=k(t).position==="fixed",s=c?_(t):t;for(;P(s)&&!Q(s);){let r=k(s),l=gt(s);!l&&r.position==="fixed"&&(i=null),(c?!l&&!i:!l&&r.position==="static"&&!!i&&["absolute","fixed"].includes(i.position)||et(s)&&!l&&Yt(t,s))?o=o.filter(m=>m!==s):i=r,s=_(s)}return e.set(t,o),o}function xe(t){let{element:e,boundary:n,rootBoundary:o,strategy:i}=t,s=[...n==="clippingAncestors"?lt(e)?[]:we(e,this._c):[].concat(n),o],r=s[0],l=s.reduce((a,m)=>{let f=zt(e,m,i);return a.top=I(f.top,a.top),a.right=q(f.right,a.right),a.bottom=q(f.bottom,a.bottom),a.left=I(f.left,a.left),a},zt(e,r,i));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function ve(t){let{width:e,height:n}=It(t);return{width:e,height:n}}function ye(t,e,n){let o=$(e),i=H(e),c=n==="fixed",s=Z(t,!0,c,e),r={scrollLeft:0,scrollTop:0},l=B(0);function a(){l.x=Ot(i)}if(o||!o&&!c)if((G(e)!=="body"||et(i))&&(r=at(e)),o){let u=Z(e,!0,c,e);l.x=u.x+e.clientLeft,l.y=u.y+e.clientTop}else i&&a();c&&!o&&i&&a();let m=i&&!o&&!c?jt(i,r):B(0),f=s.left+r.scrollLeft-l.x-m.x,d=s.top+r.scrollTop-l.y-m.y;return{x:f,y:d,width:s.width,height:s.height}}function bt(t){return k(t).position==="static"}function Vt(t,e){if(!$(t)||k(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return H(t)===n&&(n=n.ownerDocument.body),n}function qt(t,e){let n=E(t);if(lt(t))return n;if(!$(t)){let i=_(t);for(;i&&!Q(i);){if(P(i)&&!bt(i))return i;i=_(i)}return n}let o=Vt(t,e);for(;o&&$t(o)&&bt(o);)o=Vt(o,e);return o&&Q(o)&&bt(o)&&!gt(o)?n:o||Nt(t)||n}var be=async function(t){let e=this.getOffsetParent||qt,n=this.getDimensions,o=await n(t.floating);return{reference:ye(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}};function Ae(t){return k(t).direction==="rtl"}var Oe={convertOffsetParentRelativeRectToViewportRelativeRect:de,getDocumentElement:H,getClippingRect:xe,getOffsetParent:qt,getElementRects:be,getClientRects:me,getDimensions:ve,getScale:nt,isElement:P,isRTL:Ae};function Xt(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function Re(t,e){let n=null,o,i=H(t);function c(){var r;clearTimeout(o),(r=n)==null||r.disconnect(),n=null}function s(r,l){r===void 0&&(r=!1),l===void 0&&(l=1),c();let a=t.getBoundingClientRect(),{left:m,top:f,width:d,height:u}=a;if(r||e(),!d||!u)return;let g=st(f),w=st(i.clientWidth-(m+d)),h=st(i.clientHeight-(f+u)),p=st(m),v={rootMargin:-g+"px "+-w+"px "+-h+"px "+-p+"px",threshold:I(0,q(1,l))||1},A=!0;function y(b){let R=b[0].intersectionRatio;if(R!==l){if(!A)return s();R?s(!1,R):o=setTimeout(()=>{s(!1,1e-7)},1e3)}R===1&&!Xt(a,t.getBoundingClientRect())&&s(),A=!1}try{n=new IntersectionObserver(y,{...v,root:i.ownerDocument})}catch{n=new IntersectionObserver(y,v)}n.observe(t)}return s(!0),c}function Ut(t,e,n,o){o===void 0&&(o={});let{ancestorScroll:i=!0,ancestorResize:c=!0,elementResize:s=typeof ResizeObserver=="function",layoutShift:r=typeof IntersectionObserver=="function",animationFrame:l=!1}=o,a=At(t),m=i||c?[...a?tt(a):[],...tt(e)]:[];m.forEach(p=>{i&&p.addEventListener("scroll",n,{passive:!0}),c&&p.addEventListener("resize",n)});let f=a&&r?Re(a,n):null,d=-1,u=null;s&&(u=new ResizeObserver(p=>{let[x]=p;x&&x.target===a&&u&&(u.unobserve(e),cancelAnimationFrame(d),d=requestAnimationFrame(()=>{var v;(v=u)==null||v.observe(e)})),n()}),a&&!l&&u.observe(a),u.observe(e));let g,w=l?Z(t):null;l&&h();function h(){let p=Z(t);w&&!Xt(w,p)&&n(),w=p,g=requestAnimationFrame(h)}return n(),()=>{var p;m.forEach(x=>{i&&x.removeEventListener("scroll",n),c&&x.removeEventListener("resize",n)}),f?.(),(p=u)==null||p.disconnect(),u=null,l&&cancelAnimationFrame(g)}}var Jt=ct,Kt=Mt,Gt=kt,Qt=Bt,Zt=Dt;var te=Pt;var ee=(t,e,n)=>{let o=new Map,i={platform:Oe,...n},c={...i.platform,_c:o};return St(t,e,{...i,platform:c})};function ne(t){function e(r,l){let a=r.querySelector("[data-trigger]"),m=r.querySelector("[data-popover]"),f=l.includes("hover"),d=n(l)||"bottom",u=o(l),g=i(l);return{triggerEl:a,popoverEl:m,isHoverable:f,position:d,transition:u,colorClass:g}}function n(r){return["top","top-start","top-end","right","right-start","right-end","bottom","bottom-start","bottom-end","left","left-start","left-end"].find(l=>r.includes(l))||""}function o(r){return["animate-none","animate-drop"].find(l=>r.includes(l))||"animate-fade"}function i(r){let l={danger:["bg-red-200/90","text-red-900"],success:["bg-emerald-200/90","text-emerald-900"],warning:["bg-yellow-200/90","text-yellow-900"],info:["bg-sky-200/90","text-sky-900"],primary:["bg-blue-600","text-blue-900"],secondary:["bg-gray-600","text-gray-900"],light:["bg-gray-300/90","text-black"],dark:["bg-black/90","text-white"]};return r.reduce((a,m)=>a||l[m],"")}let c=["text-black","bg-white","border","border-zinc-50","dark:bg-zinc-900/90","dark:border-black/50","dark:text-white"];t.data("popover",r=>({open:!1,isHoverable:r,show(){this.open?this.isHoverable||(this.open=!1):this.open=!0},hide(){this.open=!1}})),t.directive("popover",(r,{expression:l,modifiers:a},{cleanup:m})=>{r.id||(r.id="popover-"+Math.random().toString(36).substring(2,9));let{triggerEl:f,popoverEl:d,isHoverable:u,position:g,transition:w,colorClass:h}=e(r,a);if(l)try{let A=new DOMParser().parseFromString(l,"text/html"),y=b=>{if(b.nodeType===Node.TEXT_NODE)return;if([...b.children].forEach(y),["SCRIPT","IFRAME","OBJECT","EMBED","STYLE","META","LINK"].includes(b.tagName)){b.remove();return}[...b.attributes].forEach(T=>{let C=T.name.toLowerCase();(C.startsWith("on")||(C==="href"||C==="src")&&T.value.trim().toLowerCase().startsWith("javascript:"))&&b.removeAttribute(T.name)})};[...A.body.children].forEach(y),d.innerHTML=A.body.innerHTML}catch{d.textContent=l}if(!f||!d)return console.warn(f?"Popover JS: Attribute data-popover is not set!":"Popover JS: Attribute data-trigger is not set!");r.setAttribute("x-data",`popover(${u})`),f.setAttribute("x-ref","button"),d.id="popover-"+r.id,d.setAttribute("x-show","open");let p=["z-998","w-96","min-w-fit","max-w-full","sm:max-w-[320px]","md:max-w-sm","lg:max-w-md","xl:max-w-lg","rounded-lg","whitespace-normal","break-words","font-normal","text-sm","shadow-lg","shadow-black/20","focus:outline-hidden","dark:shadow-black/75",w];h?p.push(...h):p.push(...c),d.classList.add(...p),a.includes("hover")?(f.setAttribute("x-on:mouseenter.self","show"),f.setAttribute("x-on:mouseleave","hide")):(f.setAttribute("x-on:click","show"),d.setAttribute("x-on:click.outside","hide"));let x=null;t.nextTick(()=>{document.body.appendChild(d),x=s(f,d,r.id,g,"body",l,h,r)}),m(()=>{f.removeAttribute("x-on:mouseenter.self"),f.removeAttribute("x-on:mouseleave"),f.removeAttribute("x-on:click"),d.removeAttribute("x-on:click.outside"),x&&x();let v=document.getElementById(`arrow-${r.id}`);v&&v.remove(),d&&d.remove()})});function s(r,l,a,m,f,d,u,g){let w=`arrow-${a}`;l.insertAdjacentHTML("afterbegin",`<span id="${w}" class="popover-arrow absolute z-999 h-3 w-3 animate-fade" x-show="open"></span>`);let h=document.getElementById(w);if(!h)return;u?h.classList.add(...u):h.classList.add(...c);let p=h.offsetWidth||0,x=Math.sqrt(2*p**2)/2,v=m||"bottom",A={name:"overflowMiddleware",async fn(b){let R=await Jt(b,{boundary:f});return{}}},y=Ut(r,l,()=>{if(!r.isConnected||!g.isConnected){y&&y(),l.remove(),h&&h.remove();return}ee(r,l,{placement:v,middleware:[Kt(10),m?Zt():Gt(),Qt(),A,te({element:h})]}).then(({x:b,y:R,middlewareData:T,placement:C})=>{Object.assign(l.style,{position:"absolute",left:`${b}px`,top:`${R}px`});let O=C.split("-")[0],L={top:"bottom",right:"left",bottom:"top",left:"right"}[O],D={top:"rotate(225deg)",right:"rotate(315deg)",bottom:"rotate(45deg)",left:"rotate(135deg)"}[O];if(T.arrow){let{x:N,y:S}=T.arrow;Object.assign(h.style,{left:N!=null?`${N}px`:"",top:S!=null?`${S}px`:"",right:"",bottom:"",[L]:"-6px",transform:D})}})});return y}}document.addEventListener("alpine:init",()=>{window.Alpine.plugin(ne)});})();