@kitn.ai/ui
Version:
Framework-agnostic, Shadow-DOM web components for building AI chat interfaces — works in React, Vue, Angular, Svelte, or plain HTML. Authored in SolidJS.
2 lines (1 loc) • 20.2 kB
JavaScript
import{s as qt,c as Xt,m as _t,D as jt,g as tt,h as ut,p as dt}from"./define-CNSKFZCd.js";const Yt=["top","right","bottom","left"],_=Math.min,$=Math.max,ot=Math.round,it=Math.floor,A=t=>({x:t,y:t}),Jt={left:"right",right:"left",bottom:"top",top:"bottom"};function mt(t,e,n){return $(t,_(e,n))}function j(t,e){return typeof t=="function"?t(e):t}function I(t){return t.split("-")[0]}function et(t){return t.split("-")[1]}function Et(t){return t==="x"?"y":"x"}function ht(t){return t==="y"?"height":"width"}function M(t){const e=t[0];return e==="t"||e==="b"?"y":"x"}function pt(t){return Et(M(t))}function Gt(t,e,n){n===void 0&&(n=!1);const o=et(t),i=pt(t),c=ht(i);let r=i==="x"?o===(n?"end":"start")?"right":"left":o==="start"?"bottom":"top";return e.reference[c]>e.floating[c]&&(r=rt(r)),[r,rt(r)]}function Kt(t){const e=rt(t);return[gt(t),e,gt(e)]}function gt(t){return t.includes("start")?t.replace("start","end"):t.replace("end","start")}const Lt=["left","right"],Ot=["right","left"],Ut=["top","bottom"],Qt=["bottom","top"];function Zt(t,e,n){switch(t){case"top":case"bottom":return n?e?Ot:Lt:e?Lt:Ot;case"left":case"right":return e?Ut:Qt;default:return[]}}function te(t,e,n,o){const i=et(t);let c=Zt(I(t),n==="start",o);return i&&(c=c.map(r=>r+"-"+i),e&&(c=c.concat(c.map(gt)))),c}function rt(t){const e=I(t);return Jt[e]+t.slice(e.length)}function ee(t){return{top:0,right:0,bottom:0,left:0,...t}}function Tt(t){return typeof t!="number"?ee(t):{top:t,right:t,bottom:t,left:t}}function ct(t){const{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 Dt(t,e,n){let{reference:o,floating:i}=t;const c=M(e),r=pt(e),s=ht(r),a=I(e),l=c==="y",u=o.x+o.width/2-i.width/2,d=o.y+o.height/2-i.height/2,m=o[s]/2-i[s]/2;let f;switch(a){case"top":f={x:u,y:o.y-i.height};break;case"bottom":f={x:u,y:o.y+o.height};break;case"right":f={x:o.x+o.width,y:d};break;case"left":f={x:o.x-i.width,y:d};break;default:f={x:o.x,y:o.y}}switch(et(e)){case"start":f[r]-=m*(n&&l?-1:1);break;case"end":f[r]+=m*(n&&l?-1:1);break}return f}async function ne(t,e){var n;e===void 0&&(e={});const{x:o,y:i,platform:c,rects:r,elements:s,strategy:a}=t,{boundary:l="clippingAncestors",rootBoundary:u="viewport",elementContext:d="floating",altBoundary:m=!1,padding:f=0}=j(e,t),h=Tt(f),p=s[m?d==="floating"?"reference":"floating":d],y=ct(await c.getClippingRect({element:(n=await(c.isElement==null?void 0:c.isElement(p)))==null||n?p:p.contextElement||await(c.getDocumentElement==null?void 0:c.getDocumentElement(s.floating)),boundary:l,rootBoundary:u,strategy:a})),g=d==="floating"?{x:o,y:i,width:r.floating.width,height:r.floating.height}:r.reference,w=await(c.getOffsetParent==null?void 0:c.getOffsetParent(s.floating)),x=await(c.isElement==null?void 0:c.isElement(w))?await(c.getScale==null?void 0:c.getScale(w))||{x:1,y:1}:{x:1,y:1},v=ct(c.convertOffsetParentRelativeRectToViewportRelativeRect?await c.convertOffsetParentRelativeRectToViewportRelativeRect({elements:s,rect:g,offsetParent:w,strategy:a}):g);return{top:(y.top-v.top+h.top)/x.y,bottom:(v.bottom-y.bottom+h.bottom)/x.y,left:(y.left-v.left+h.left)/x.x,right:(v.right-y.right+h.right)/x.x}}const oe=50,ie=async(t,e,n)=>{const{placement:o="bottom",strategy:i="absolute",middleware:c=[],platform:r}=n,s=r.detectOverflow?r:{...r,detectOverflow:ne},a=await(r.isRTL==null?void 0:r.isRTL(e));let l=await r.getElementRects({reference:t,floating:e,strategy:i}),{x:u,y:d}=Dt(l,o,a),m=o,f=0;const h={};for(let p=0;p<c.length;p++){const y=c[p];if(!y)continue;const{name:g,fn:w}=y,{x,y:v,data:E,reset:b}=await w({x:u,y:d,initialPlacement:o,placement:m,strategy:i,middlewareData:h,rects:l,platform:s,elements:{reference:t,floating:e}});u=x??u,d=v??d,h[g]={...h[g],...E},b&&f<oe&&(f++,typeof b=="object"&&(b.placement&&(m=b.placement),b.rects&&(l=b.rects===!0?await r.getElementRects({reference:t,floating:e,strategy:i}):b.rects),{x:u,y:d}=Dt(l,m,a)),p=-1)}return{x:u,y:d,placement:m,strategy:i,middlewareData:h}},re=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:o,placement:i,rects:c,platform:r,elements:s,middlewareData:a}=e,{element:l,padding:u=0}=j(t,e)||{};if(l==null)return{};const d=Tt(u),m={x:n,y:o},f=pt(i),h=ht(f),p=await r.getDimensions(l),y=f==="y",g=y?"top":"left",w=y?"bottom":"right",x=y?"clientHeight":"clientWidth",v=c.reference[h]+c.reference[f]-m[f]-c.floating[h],E=m[f]-c.reference[f],b=await(r.getOffsetParent==null?void 0:r.getOffsetParent(l));let B=b?b[x]:0;(!B||!await(r.isElement==null?void 0:r.isElement(b)))&&(B=s.floating[x]||c.floating[h]);const U=v/2-E/2,N=B/2-p[h]/2-1,S=_(d[g],N),Q=_(d[w],N),V=S,Z=B-p[h]-Q,R=B/2-p[h]/2+U,z=mt(V,R,Z),k=!a.arrow&&et(i)!=null&&R!==z&&c.reference[h]/2-(R<V?S:Q)-p[h]/2<0,L=k?R<V?R-V:R-Z:0;return{[f]:m[f]+L,data:{[f]:z,centerOffset:R-z-L,...k&&{alignmentOffset:L}},reset:k}}}),ce=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,o;const{placement:i,middlewareData:c,rects:r,initialPlacement:s,platform:a,elements:l}=e,{mainAxis:u=!0,crossAxis:d=!0,fallbackPlacements:m,fallbackStrategy:f="bestFit",fallbackAxisSideDirection:h="none",flipAlignment:p=!0,...y}=j(t,e);if((n=c.arrow)!=null&&n.alignmentOffset)return{};const g=I(i),w=M(s),x=I(s)===s,v=await(a.isRTL==null?void 0:a.isRTL(l.floating)),E=m||(x||!p?[rt(s)]:Kt(s)),b=h!=="none";!m&&b&&E.push(...te(s,p,h,v));const B=[s,...E],U=await a.detectOverflow(e,y),N=[];let S=((o=c.flip)==null?void 0:o.overflows)||[];if(u&&N.push(U[g]),d){const R=Gt(i,r,v);N.push(U[R[0]],U[R[1]])}if(S=[...S,{placement:i,overflows:N}],!N.every(R=>R<=0)){var Q,V;const R=(((Q=c.flip)==null?void 0:Q.index)||0)+1,z=B[R];if(z&&(!(d==="alignment"&&w!==M(z))||S.every(L=>M(L.placement)===w?L.overflows[0]>0:!0)))return{data:{index:R,overflows:S},reset:{placement:z}};let k=(V=S.filter(L=>L.overflows[0]<=0).sort((L,P)=>L.overflows[1]-P.overflows[1])[0])==null?void 0:V.placement;if(!k)switch(f){case"bestFit":{var Z;const L=(Z=S.filter(P=>{if(b){const H=M(P.placement);return H===w||H==="y"}return!0}).map(P=>[P.placement,P.overflows.filter(H=>H>0).reduce((H,It)=>H+It,0)]).sort((P,H)=>P[1]-H[1])[0])==null?void 0:Z[0];L&&(k=L);break}case"initialPlacement":k=s;break}if(i!==k)return{reset:{placement:k}}}return{}}}};function At(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function Ct(t){return Yt.some(e=>t[e]>=0)}const se=function(t){return t===void 0&&(t={}),{name:"hide",options:t,async fn(e){const{rects:n,platform:o}=e,{strategy:i="referenceHidden",...c}=j(t,e);switch(i){case"referenceHidden":{const r=await o.detectOverflow(e,{...c,elementContext:"reference"}),s=At(r,n.reference);return{data:{referenceHiddenOffsets:s,referenceHidden:Ct(s)}}}case"escaped":{const r=await o.detectOverflow(e,{...c,altBoundary:!0}),s=At(r,n.floating);return{data:{escapedOffsets:s,escaped:Ct(s)}}}default:return{}}}}},le=new Set(["left","top"]);async function ae(t,e){const{placement:n,platform:o,elements:i}=t,c=await(o.isRTL==null?void 0:o.isRTL(i.floating)),r=I(n),s=et(n),a=M(n)==="y",l=le.has(r)?-1:1,u=c&&a?-1:1,d=j(e,t);let{mainAxis:m,crossAxis:f,alignmentAxis:h}=typeof d=="number"?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof h=="number"&&(f=s==="end"?h*-1:h),a?{x:f*u,y:m*l}:{x:m*l,y:f*u}}const fe=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,o;const{x:i,y:c,placement:r,middlewareData:s}=e,a=await ae(e,t);return r===((n=s.offset)==null?void 0:n.placement)&&(o=s.arrow)!=null&&o.alignmentOffset?{}:{x:i+a.x,y:c+a.y,data:{...a,placement:r}}}}},ue=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:o,placement:i,platform:c}=e,{mainAxis:r=!0,crossAxis:s=!1,limiter:a={fn:g=>{let{x:w,y:x}=g;return{x:w,y:x}}},...l}=j(t,e),u={x:n,y:o},d=await c.detectOverflow(e,l),m=M(I(i)),f=Et(m);let h=u[f],p=u[m];if(r){const g=f==="y"?"top":"left",w=f==="y"?"bottom":"right",x=h+d[g],v=h-d[w];h=mt(x,h,v)}if(s){const g=m==="y"?"top":"left",w=m==="y"?"bottom":"right",x=p+d[g],v=p-d[w];p=mt(x,p,v)}const y=a.fn({...e,[f]:h,[m]:p});return{...y,data:{x:y.x-n,y:y.y-o,enabled:{[f]:r,[m]:s}}}}}};function st(){return typeof window<"u"}function Y(t){return St(t)?(t.nodeName||"").toLowerCase():"#document"}function O(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function C(t){var e;return(e=(St(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function St(t){return st()?t instanceof Node||t instanceof O(t).Node:!1}function T(t){return st()?t instanceof Element||t instanceof O(t).Element:!1}function F(t){return st()?t instanceof HTMLElement||t instanceof O(t).HTMLElement:!1}function kt(t){return!st()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof O(t).ShadowRoot}function nt(t){const{overflow:e,overflowX:n,overflowY:o,display:i}=D(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+n)&&i!=="inline"&&i!=="contents"}function de(t){return/^(table|td|th)$/.test(Y(t))}function lt(t){try{if(t.matches(":popover-open"))return!0}catch{}try{return t.matches(":modal")}catch{return!1}}const me=/transform|translate|scale|rotate|perspective|filter/,he=/paint|layout|strict|content/,q=t=>!!t&&t!=="none";let yt;function wt(t){const e=T(t)?D(t):t;return q(e.transform)||q(e.translate)||q(e.scale)||q(e.rotate)||q(e.perspective)||!xt()&&(q(e.backdropFilter)||q(e.filter))||me.test(e.willChange||"")||he.test(e.contain||"")}function pe(t){let e=W(t);for(;F(e)&&!J(e);){if(wt(e))return e;if(lt(e))return null;e=W(e)}return null}function xt(){return yt==null&&(yt=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),yt}function J(t){return/^(html|body|#document)$/.test(Y(t))}function D(t){return O(t).getComputedStyle(t)}function at(t){return T(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function W(t){if(Y(t)==="html")return t;const e=t.assignedSlot||t.parentNode||kt(t)&&t.host||C(t);return kt(e)?e.host:e}function Ft(t){const e=W(t);return J(e)?t.ownerDocument?t.ownerDocument.body:t.body:F(e)&&nt(e)?e:Ft(e)}function G(t,e,n){var o;e===void 0&&(e=[]),n===void 0&&(n=!0);const i=Ft(t),c=i===((o=t.ownerDocument)==null?void 0:o.body),r=O(i);if(c){const s=vt(r);return e.concat(r,r.visualViewport||[],nt(i)?i:[],s&&n?G(s):[])}else return e.concat(i,G(i,[],n))}function vt(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function Pt(t){const e=D(t);let n=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const i=F(t),c=i?t.offsetWidth:n,r=i?t.offsetHeight:o,s=ot(n)!==c||ot(o)!==r;return s&&(n=c,o=r),{width:n,height:o,$:s}}function bt(t){return T(t)?t:t.contextElement}function K(t){const e=bt(t);if(!F(e))return A(1);const n=e.getBoundingClientRect(),{width:o,height:i,$:c}=Pt(e);let r=(c?ot(n.width):n.width)/o,s=(c?ot(n.height):n.height)/i;return(!r||!Number.isFinite(r))&&(r=1),(!s||!Number.isFinite(s))&&(s=1),{x:r,y:s}}const ge=A(0);function Ht(t){const e=O(t);return!xt()||!e.visualViewport?ge:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function ye(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==O(t)?!1:e}function X(t,e,n,o){e===void 0&&(e=!1),n===void 0&&(n=!1);const i=t.getBoundingClientRect(),c=bt(t);let r=A(1);e&&(o?T(o)&&(r=K(o)):r=K(t));const s=ye(c,n,o)?Ht(c):A(0);let a=(i.left+s.x)/r.x,l=(i.top+s.y)/r.y,u=i.width/r.x,d=i.height/r.y;if(c){const m=O(c),f=o&&T(o)?O(o):o;let h=m,p=vt(h);for(;p&&o&&f!==h;){const y=K(p),g=p.getBoundingClientRect(),w=D(p),x=g.left+(p.clientLeft+parseFloat(w.paddingLeft))*y.x,v=g.top+(p.clientTop+parseFloat(w.paddingTop))*y.y;a*=y.x,l*=y.y,u*=y.x,d*=y.y,a+=x,l+=v,h=O(p),p=vt(h)}}return ct({width:u,height:d,x:a,y:l})}function ft(t,e){const n=at(t).scrollLeft;return e?e.left+n:X(C(t)).left+n}function Mt(t,e){const n=t.getBoundingClientRect(),o=n.left+e.scrollLeft-ft(t,n),i=n.top+e.scrollTop;return{x:o,y:i}}function we(t){let{elements:e,rect:n,offsetParent:o,strategy:i}=t;const c=i==="fixed",r=C(o),s=e?lt(e.floating):!1;if(o===r||s&&c)return n;let a={scrollLeft:0,scrollTop:0},l=A(1);const u=A(0),d=F(o);if((d||!d&&!c)&&((Y(o)!=="body"||nt(r))&&(a=at(o)),d)){const f=X(o);l=K(o),u.x=f.x+o.clientLeft,u.y=f.y+o.clientTop}const m=r&&!d&&!c?Mt(r,a):A(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-a.scrollLeft*l.x+u.x+m.x,y:n.y*l.y-a.scrollTop*l.y+u.y+m.y}}function xe(t){return Array.from(t.getClientRects())}function ve(t){const e=C(t),n=at(t),o=t.ownerDocument.body,i=$(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),c=$(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let r=-n.scrollLeft+ft(t);const s=-n.scrollTop;return D(o).direction==="rtl"&&(r+=$(e.clientWidth,o.clientWidth)-i),{width:i,height:c,x:r,y:s}}const Wt=25;function be(t,e){const n=O(t),o=C(t),i=n.visualViewport;let c=o.clientWidth,r=o.clientHeight,s=0,a=0;if(i){c=i.width,r=i.height;const u=xt();(!u||u&&e==="fixed")&&(s=i.offsetLeft,a=i.offsetTop)}const l=ft(o);if(l<=0){const u=o.ownerDocument,d=u.body,m=getComputedStyle(d),f=u.compatMode==="CSS1Compat"&&parseFloat(m.marginLeft)+parseFloat(m.marginRight)||0,h=Math.abs(o.clientWidth-d.clientWidth-f);h<=Wt&&(c-=h)}else l<=Wt&&(c+=l);return{width:c,height:r,x:s,y:a}}function Re(t,e){const n=X(t,!0,e==="fixed"),o=n.top+t.clientTop,i=n.left+t.clientLeft,c=F(t)?K(t):A(1),r=t.clientWidth*c.x,s=t.clientHeight*c.y,a=i*c.x,l=o*c.y;return{width:r,height:s,x:a,y:l}}function Bt(t,e,n){let o;if(e==="viewport")o=be(t,n);else if(e==="document")o=ve(C(t));else if(T(e))o=Re(e,n);else{const i=Ht(t);o={x:e.x-i.x,y:e.y-i.y,width:e.width,height:e.height}}return ct(o)}function Nt(t,e){const n=W(t);return n===e||!T(n)||J(n)?!1:D(n).position==="fixed"||Nt(n,e)}function Ee(t,e){const n=e.get(t);if(n)return n;let o=G(t,[],!1).filter(s=>T(s)&&Y(s)!=="body"),i=null;const c=D(t).position==="fixed";let r=c?W(t):t;for(;T(r)&&!J(r);){const s=D(r),a=wt(r);!a&&s.position==="fixed"&&(i=null),(c?!a&&!i:!a&&s.position==="static"&&i&&(i.position==="absolute"||i.position==="fixed")||nt(r)&&!a&&Nt(t,r))?o=o.filter(l=>l!==r):i=s,r=W(r)}return e.set(t,o),o}function Le(t){let{element:e,boundary:n,rootBoundary:o,strategy:i}=t;const c=[...n==="clippingAncestors"?lt(e)?[]:Ee(e,this._c):[].concat(n),o],r=Bt(e,c[0],i);let s=r.top,a=r.right,l=r.bottom,u=r.left;for(let d=1;d<c.length;d++){const m=Bt(e,c[d],i);s=$(m.top,s),a=_(m.right,a),l=_(m.bottom,l),u=$(m.left,u)}return{width:a-u,height:l-s,x:u,y:s}}function Oe(t){const{width:e,height:n}=Pt(t);return{width:e,height:n}}function Te(t,e,n){const o=F(e),i=C(e),c=n==="fixed",r=X(t,!0,c,e);let s={scrollLeft:0,scrollTop:0};const a=A(0);function l(){a.x=ft(i)}if(o||!o&&!c)if((Y(e)!=="body"||nt(i))&&(s=at(e)),o){const f=X(e,!0,c,e);a.x=f.x+e.clientLeft,a.y=f.y+e.clientTop}else i&&l();c&&!o&&i&&l();const u=i&&!o&&!c?Mt(i,s):A(0),d=r.left+s.scrollLeft-a.x-u.x,m=r.top+s.scrollTop-a.y-u.y;return{x:d,y:m,width:r.width,height:r.height}}function Rt(t){return D(t).position==="static"}function Vt(t,e){if(!F(t)||D(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return C(t)===n&&(n=n.ownerDocument.body),n}function zt(t,e){const n=O(t);if(lt(t))return n;if(!F(t)){let i=W(t);for(;i&&!J(i);){if(T(i)&&!Rt(i))return i;i=W(i)}return n}let o=Vt(t,e);for(;o&&de(o)&&Rt(o);)o=Vt(o,e);return o&&J(o)&&Rt(o)&&!wt(o)?n:o||pe(t)||n}const De=async function(t){const e=this.getOffsetParent||zt,n=this.getDimensions,o=await n(t.floating);return{reference:Te(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}};function Ae(t){return D(t).direction==="rtl"}const Ce={convertOffsetParentRelativeRectToViewportRelativeRect:we,getDocumentElement:C,getClippingRect:Le,getOffsetParent:zt,getElementRects:De,getClientRects:xe,getDimensions:Oe,getScale:K,isElement:T,isRTL:Ae};function $t(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function Se(t,e){let n=null,o;const i=C(t);function c(){var s;clearTimeout(o),(s=n)==null||s.disconnect(),n=null}function r(s,a){s===void 0&&(s=!1),a===void 0&&(a=1),c();const l=t.getBoundingClientRect(),{left:u,top:d,width:m,height:f}=l;if(s||e(),!m||!f)return;const h=it(d),p=it(i.clientWidth-(u+m)),y=it(i.clientHeight-(d+f)),g=it(u),w={rootMargin:-h+"px "+-p+"px "+-y+"px "+-g+"px",threshold:$(0,_(1,a))||1};let x=!0;function v(E){const b=E[0].intersectionRatio;if(b!==a){if(!x)return r();b?r(!1,b):o=setTimeout(()=>{r(!1,1e-7)},1e3)}b===1&&!$t(l,t.getBoundingClientRect())&&r(),x=!1}try{n=new IntersectionObserver(v,{...w,root:i.ownerDocument})}catch{n=new IntersectionObserver(v,w)}n.observe(t)}return r(!0),c}function ke(t,e,n,o){o===void 0&&(o={});const{ancestorScroll:i=!0,ancestorResize:c=!0,elementResize:r=typeof ResizeObserver=="function",layoutShift:s=typeof IntersectionObserver=="function",animationFrame:a=!1}=o,l=bt(t),u=i||c?[...l?G(l):[],...e?G(e):[]]:[];u.forEach(g=>{i&&g.addEventListener("scroll",n,{passive:!0}),c&&g.addEventListener("resize",n)});const d=l&&s?Se(l,n):null;let m=-1,f=null;r&&(f=new ResizeObserver(g=>{let[w]=g;w&&w.target===l&&f&&e&&(f.unobserve(e),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var x;(x=f)==null||x.observe(e)})),n()}),l&&!a&&f.observe(l),e&&f.observe(e));let h,p=a?X(t):null;a&&y();function y(){const g=X(t);p&&!$t(p,g)&&n(),p=g,h=requestAnimationFrame(y)}return n(),()=>{var g;u.forEach(w=>{i&&w.removeEventListener("scroll",n),c&&w.removeEventListener("resize",n)}),d?.(),(g=f)==null||g.disconnect(),f=null,a&&cancelAnimationFrame(h)}}const Fe=fe,Pe=ue,He=ce,Me=se,We=re,Be=(t,e,n)=>{const o=new Map,i={platform:Ce,...n},c={...i.platform,_c:o};return ie(t,e,{...i,platform:c})};function Ne(t){const[e,n]=tt(t()),[o,i]=tt(t()?"open":"closed");let c,r=0;const s=a=>{c=a};return ut(a=>{const l=t();if(l)r++,n(!0),i("open");else if(a){i("closed");const u=c,d=u&&(()=>{const h=getComputedStyle(u);return h.animationName!=="none"&&parseFloat(h.animationDuration||"0")>0})();if(!u||!d){const h=++r;return queueMicrotask(()=>{h===r&&n(!1)}),l}const m=u,f=h=>{h.target===m&&(m.removeEventListener("animationend",f),n(!1))};m.addEventListener("animationend",f),dt(()=>m.removeEventListener("animationend",f))}return l}),{present:e,state:o,setRef:s}}function Ve(t){const[e,n]=qt(t,["as"]);return typeof e.as=="function"?e.as(n):Xt(jt,_t({get component(){return e.as??"span"}},n))}function ze(t){let e=t;for(;e;){if(e instanceof Element&&e.closest("[inert]"))return!0;const n=e.getRootNode();e=n instanceof ShadowRoot?n.host:null}return!1}function $e(t,e){if(typeof MutationObserver!="function")return()=>{};let n=!1;const o=()=>t.isConnected&&!ze(t);let i=o();const c=()=>{if(!n){if(o()){i=!0;return}i&&(n=!0,r.disconnect(),e())}},r=new MutationObserver(c),s=new Set;typeof document<"u"&&s.add(document);const a=t.getRootNode();a&&s.add(a);for(const l of s)try{r.observe(l,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["inert"]})}catch{}return()=>r.disconnect()}function Ie(t,e,n={}){const[o,i]=tt({x:0,y:0,placement:n.placement??"bottom"}),[c,r]=tt({}),[s,a]=tt(!1);return ut(()=>{const l=t(),u=e();if(!l||!u)return;const d=()=>{var p;const y=[Fe(n.gutter??8),He(),Pe({padding:8})],g=(p=n.arrowEl)==null?void 0:p.call(n);g&&y.push(We({element:g})),y.push(Me()),Be(l,u,{placement:n.placement??"bottom",strategy:"fixed",middleware:y}).then(({x:w,y:x,placement:v,middlewareData:E})=>{var b;i({x:w,y:x,placement:v}),E.arrow&&r({x:E.arrow.x,y:E.arrow.y}),a(!!((b=E.hide)!=null&&b.referenceHidden))})},m=ke(l,u,d);let f;if(typeof ResizeObserver=="function"){f=new ResizeObserver(d),f.observe(l);for(const p of G(l))p instanceof Element&&f.observe(p)}const h=n.onDisconnect?$e(l,n.onDisconnect):void 0;dt(()=>{m(),f?.disconnect(),h?.()})}),{pos:o,arrowPos:c,hidden:s}}function qe(t){ut(()=>{if(!t.enabled())return;const e=o=>{o.key==="Escape"&&t.onDismiss("escape")},n=o=>{const i=o.target;t.refs().some(c=>c&&c.contains(i))||t.onDismiss("outside")};document.addEventListener("keydown",e),document.addEventListener("pointerdown",n,!0),dt(()=>{document.removeEventListener("keydown",e),document.removeEventListener("pointerdown",n,!0)})})}export{Ve as A,qe as a,Ne as c,Ie as u};