UNPKG

@vkm-js/popover

Version:

An Alpinejs plugin to add a popover on any element.

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