import{n as e}from"./rolldown-runtime-DAXXjFlN.js";import{An as t,Ar as n,Cn as r,Dn as i,En as a,Fn as o,Gn as s,Hn as c,Jn as l,Ln as u,On as d,Wn as f,Zn as p,dr as m,er as h,jn as g,kn as _,or as v,pr as y,rr as b,sn as x,un as S,zr as C}from"./vendor-Dcerr41Y.js";import{di as w,ui as T}from"./ws-DjAvcWfg.js";import{n as E,r as D}from"./windowing-B5kKC8VJ.js";var O,k,A=e((()=>{x(),E(),O={class:`c-tooltip__content`},k=u({inheritAttrs:!1,__name:`CTooltip`,props:{anchor:{default:`bottom middle`},self:{default:`top middle`},offset:{default:()=>[0,8]},delay:{default:0},hideOnPress:{type:Boolean,default:!0}},emits:[`hide`,`show`],setup(e,{expose:u,emit:x}){let w=e,T=x,E=v(),k=c(`windowContext`,null)||D(),A=n(null),j=n(null),M=n(null),N=n(!1),P=n(!1),F=n({}),I=null,L=i(()=>M.value?.ownerDocument?.defaultView??k??window),R=i(()=>M.value?.ownerDocument?.body??L.value.document.body),z=i(()=>Object.fromEntries(Object.entries(E).filter(([e])=>e!==`class`&&e!==`style`))),B=i(()=>{let e=E.style,t=[F.value,{visibility:P.value?`visible`:`hidden`}];return e?[...t,e]:t});function V(){I&&=(clearTimeout(I),null)}function H(e,t){let n=e.toLowerCase().split(/\s+/).filter(Boolean),r=null,i=null;for(let e of n)(e===`left`||e===`start`)&&(r=`left`),(e===`right`||e===`end`)&&(r=`right`),(e===`middle`||e===`center`)&&(i?r=`middle`:i=`center`),e===`top`&&(i=`top`),e===`bottom`&&(i=`bottom`);return{horizontal:r??t.horizontal,vertical:i??t.vertical}}function U(e,t){return t===`left`?e.left:t===`right`?e.right:e.left+e.width/2}function W(e,t){return t===`top`?e.top:t===`bottom`?e.bottom:e.top+e.height/2}function G(){if(!N.value||!M.value||!j.value)return!1;let e=L.value,t=M.value.getBoundingClientRect(),n=j.value.getBoundingClientRect(),r=H(w.anchor,{horizontal:`middle`,vertical:`bottom`}),i=H(w.self,{horizontal:`middle`,vertical:`top`}),a=U(t,r.horizontal),o=W(t,r.vertical);i.horizontal===`middle`&&(a-=n.width/2),i.horizontal===`right`&&(a-=n.width),i.vertical===`center`&&(o-=n.height/2),i.vertical===`bottom`&&(o-=n.height),a+=w.offset[0],o+=w.offset[1];let s=Math.abs(w.offset[1]);i.vertical===`bottom`&&o<6?o=t.bottom+s:i.vertical===`top`&&o+n.height>e.innerHeight-6&&(o=t.top-n.height-s);let c=e.innerWidth-n.width-6,l=e.innerHeight-n.height-6;return F.value={position:`fixed`,left:`${Math.max(6,Math.min(c,a))}px`,top:`${Math.max(6,Math.min(l,o))}px`,zIndex:99999},P.value=!0,!0}function K(){s(()=>{if(!G())return;let e=L.value;e.requestAnimationFrame(()=>{G(),e.requestAnimationFrame(()=>{G()})})})}function q(){V(),I=setTimeout(()=>{N.value||(P.value=!1,N.value=!0,T(`show`),K())},w.delay)}function J(){V(),N.value&&(N.value=!1,P.value=!1,T(`hide`))}function Y(e){e.addEventListener(`mouseenter`,q),e.addEventListener(`mouseleave`,J),e.addEventListener(`focusin`,q),e.addEventListener(`focusout`,J),e.addEventListener(`contextmenu`,J),w.hideOnPress&&e.addEventListener(`pointerdown`,J)}function X(e){e.removeEventListener(`mouseenter`,q),e.removeEventListener(`mouseleave`,J),e.removeEventListener(`focusin`,q),e.removeEventListener(`focusout`,J),e.removeEventListener(`contextmenu`,J),e.removeEventListener(`pointerdown`,J)}return u({hide:J,show:q,updatePosition:G}),m([N,L],([e,t],n,r)=>{e&&(t.addEventListener(`scroll`,G,!0),t.addEventListener(`resize`,G),r(()=>{t.removeEventListener(`scroll`,G,!0),t.removeEventListener(`resize`,G)}))}),m(j,e=>{!e||!N.value||K()}),p(()=>{M.value=A.value?.parentElement??null,M.value&&Y(M.value)}),l(()=>{V(),J(),M.value&&X(M.value);let e=L.value;e.removeEventListener(`scroll`,G,!0),e.removeEventListener(`resize`,G)}),(e,n)=>(h(),g(r,null,[d(`span`,{ref_key:`anchorRef`,ref:A,class:`c-tooltip-anchor`,"aria-hidden":`true`},null,512),C(N)?(h(),_(a,{key:0,to:C(R)},[o(S,{name:`c-tooltip-fade`},{default:y(()=>[d(`div`,f({ref_key:`tooltipRef`,ref:j,class:[`c-tooltip`,C(E).class],style:C(B)},C(z)),[d(`div`,O,[b(e.$slots,`default`,{},void 0,!0)])],16)]),_:3})],8,[`to`])):t(``,!0)],64))}})})),j=e((()=>{})),M,N=e((()=>{A(),A(),j(),w(),M=T(k,[[`__scopeId`,`data-v-1fee8633`]])}));export{N as n,M as t};