@data-slot/tooltip 0.2.122 → 0.2.124

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@data-slot/core`),t=0;const n=new Set,r=new Set,i=(e,t)=>{if(!e)return!1;for(let r of n)if(r!==t&&r.contains(e))return!0;return!1},a=(e,t)=>{for(let n of r)n(e,t)},o=[`top`,`right`,`bottom`,`left`],s=[`start`,`center`,`end`];function c(c,l={}){let u=(0,e.getPart)(c,`tooltip-trigger`),d=(0,e.getPart)(c,`tooltip-content`),f=(0,e.getPart)(c,`tooltip-positioner`),p=f&&d&&f.contains(d)?f:null,m=(0,e.getPart)(c,`tooltip-portal`),h=m&&p&&m.contains(p)?m:null;if(!u||!d)throw Error(`Tooltip requires trigger and content slots`);let g=l.delay??(0,e.getDataNumber)(c,`delay`)??300,_=l.skipDelayDuration??(0,e.getDataNumber)(c,`skipDelayDuration`)??300,v=l.onOpenChange,y=l.portal??(0,e.getDataBool)(d,`portal`)??(0,e.getDataBool)(c,`portal`)??!0,b=(t,n)=>(0,e.getDataEnum)(d,t,n)??(p?(0,e.getDataEnum)(p,t,n):void 0)??(0,e.getDataEnum)(c,t,n),x=t=>(0,e.getDataNumber)(d,t)??(p?(0,e.getDataNumber)(p,t):void 0)??(0,e.getDataNumber)(c,t),S=t=>(0,e.getDataBool)(d,t)??(p?(0,e.getDataBool)(p,t):void 0)??(0,e.getDataBool)(c,t),C=l.side??b(`side`,o)??`top`,w=l.align??b(`align`,s)??`center`,T=l.sideOffset??x(`sideOffset`)??4,E=l.alignOffset??x(`alignOffset`)??0,D=l.avoidCollisions??S(`avoidCollisions`)??!0,O=l.collisionPadding??x(`collisionPadding`)??8,k=!1,A=!1,j=!1,M=!1,N=null,P=[],F=(0,e.createPortalLifecycle)({content:d,root:c,enabled:y,wrapperSlot:p?void 0:`tooltip-positioner`,container:p??void 0,mountTarget:p?h??p:void 0}),I=(0,e.ensureId)(d,`tooltip-content`);d.setAttribute(`role`,`tooltip`),d.setAttribute(`data-side`,C),d.setAttribute(`data-align`,w);let L=e=>{let t=F.container;if(c.setAttribute(`data-state`,e),d.setAttribute(`data-state`,e),t!==d&&t.setAttribute(`data-state`,e),e===`open`){c.setAttribute(`data-open`,``),d.setAttribute(`data-open`,``),t!==d&&t.setAttribute(`data-open`,``),A?(c.setAttribute(`data-instant`,``),d.setAttribute(`data-instant`,``),t!==d&&t.setAttribute(`data-instant`,``)):(c.removeAttribute(`data-instant`),d.removeAttribute(`data-instant`),t!==d&&t.removeAttribute(`data-instant`)),c.removeAttribute(`data-closed`),d.removeAttribute(`data-closed`),t!==d&&t.removeAttribute(`data-closed`);return}c.setAttribute(`data-closed`,``),d.setAttribute(`data-closed`,``),t!==d&&t.setAttribute(`data-closed`,``),A?(c.setAttribute(`data-instant`,``),d.setAttribute(`data-instant`,``),t!==d&&t.setAttribute(`data-instant`,``)):(c.removeAttribute(`data-instant`),d.removeAttribute(`data-instant`),t!==d&&t.removeAttribute(`data-instant`)),c.removeAttribute(`data-open`),d.removeAttribute(`data-open`),t!==d&&t.removeAttribute(`data-open`)},R=()=>{let t=F.container,n=c.ownerDocument.defaultView??window,r=u.getBoundingClientRect(),i=(0,e.computeFloatingPosition)({anchorRect:r,contentRect:(0,e.measurePopupContentRect)(d),side:C,align:w,sideOffset:T,alignOffset:E,avoidCollisions:D,collisionPadding:O}),a=(0,e.computeFloatingTransformOrigin)({side:i.side,align:i.align,anchorRect:r,popupX:i.x,popupY:i.y});t.style.position=`absolute`,t.style.top=`0px`,t.style.left=`0px`,t.style.transform=`translate3d(${i.x+n.scrollX}px, ${i.y+n.scrollY}px, 0)`,t.style.setProperty(`--transform-origin`,a),t.style.willChange=`transform`,t.style.margin=`0`,d.setAttribute(`data-side`,i.side),d.setAttribute(`data-align`,i.align),t!==d&&(t.setAttribute(`data-side`,i.side),t.setAttribute(`data-align`,i.align))},z=(0,e.createPresenceLifecycle)({element:d,onExitComplete:()=>{M||(F.restore(),d.hidden=!0)}}),B=(0,e.createPositionSync)({observedElements:[u,d],isActive:()=>k,ancestorScroll:!1,onUpdate:R}),V=()=>u.hasAttribute(`disabled`)||u.getAttribute(`aria-disabled`)===`true`,H=(n,r,i=!1)=>{k!==n&&(!n&&k&&_>0&&(t=Date.now()+_),A=i,k=n,k?(u.setAttribute(`aria-describedby`,I),d.setAttribute(`aria-hidden`,`false`),F.mount(),d.hidden=!1,L(`open`),z.enter(),R(),B.start(),B.update()):(L(`closed`),u.removeAttribute(`aria-describedby`),d.setAttribute(`aria-hidden`,`true`),z.exit(),B.stop()),(0,e.emit)(c,`tooltip:change`,{open:k,trigger:u,content:d,reason:r}),v?.(k))},U=e=>{if(N&&=(clearTimeout(N),null),Date.now()<t){H(!0,e,!0);return}N=setTimeout(()=>{H(!0,e),N=null},g)},W=(e,t=!1)=>{N&&=(clearTimeout(N),null),H(!1,e,t)},G=(e,t)=>{e===u||!k||(j=!1,W(t,!0))};return n.add(u),r.add(G),P.push(()=>{r.delete(G),n.delete(u)}),d.hidden=!0,d.setAttribute(`aria-hidden`,`true`),L(`closed`),P.push((0,e.on)(u,`pointerenter`,e=>{e.pointerType!==`touch`&&(V()||(a(u,`pointer`),U(`pointer`)))}),(0,e.on)(u,`pointerleave`,e=>{if(e.pointerType===`touch`||j)return;let t=e.relatedTarget;if(!(t&&d.contains(t))){if(i(t,u)){W(`pointer`,!0);return}W(`pointer`)}}),(0,e.on)(u,`click`,()=>{if(!V()){if(N){clearTimeout(N),N=null;return}k&&W(`pointer`,!0)}}),(0,e.on)(u,`focus`,()=>{j=!0,!V()&&(a(u,`focus`),U(`focus`))}),(0,e.on)(u,`blur`,e=>{j=!1;let t=e.relatedTarget;if(i(t,u)){W(`blur`,!0);return}W(`blur`)})),P.push((0,e.on)(d,`pointerleave`,e=>{if(e.pointerType===`touch`||j)return;let t=e.relatedTarget;if(!(t&&u.contains(t))){if(i(t,u)){W(`pointer`,!0);return}W(`pointer`)}})),P.push((0,e.on)(c,`tooltip:set`,e=>{let t=e.detail,n;if(t?.open===void 0?t?.value!==void 0&&(n=t.value):n=t.open,typeof n==`boolean`)if(n){if(V())return;N&&=(clearTimeout(N),null),H(!0,`api`)}else W(`api`)})),P.push((0,e.createDismissLayer)({root:c,isOpen:()=>k,onDismiss:()=>W(`escape`),closeOnClickOutside:!1,closeOnEscape:!0,preventEscapeDefault:!1})),{show:()=>{V()||(N&&=(clearTimeout(N),null),H(!0,`api`))},hide:()=>W(`api`),get isOpen(){return k},destroy:()=>{M=!0,N&&clearTimeout(N),B.stop(),z.cleanup(),F.cleanup(),P.forEach(e=>e()),P.length=0}}}const l=new WeakSet;function u(t=document){let n=[];for(let r of(0,e.getRoots)(t,`tooltip`))l.has(r)||(l.add(r),n.push(c(r)));return n}exports.create=u,exports.createTooltip=c;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@data-slot/core`);const t=`@data-slot/tooltip`;let n=0;const r=new Set,i=new Set,a=(e,t)=>{if(!e)return!1;for(let n of r)if(n!==t&&n.contains(e))return!0;return!1},o=(e,t)=>{for(let n of i)n(e,t)},s=[`top`,`right`,`bottom`,`left`],c=[`start`,`center`,`end`];function l(l,u={}){let d=(0,e.reuseRootBinding)(l,t,`[@data-slot/tooltip] createTooltip() called more than once for the same root. Returning the existing controller. Destroy it before rebinding with new options.`);if(d)return d;let f=(0,e.getPart)(l,`tooltip-trigger`),p=(0,e.getPart)(l,`tooltip-content`),m=(0,e.getPart)(l,`tooltip-positioner`),h=m&&p&&m.contains(p)?m:null,g=(0,e.getPart)(l,`tooltip-portal`),_=g&&h&&g.contains(h)?g:null;if(!f||!p)throw Error(`Tooltip requires trigger and content slots`);let v=u.delay??(0,e.getDataNumber)(l,`delay`)??300,y=u.skipDelayDuration??(0,e.getDataNumber)(l,`skipDelayDuration`)??300,b=u.onOpenChange,x=u.portal??(0,e.getDataBool)(p,`portal`)??(0,e.getDataBool)(l,`portal`)??!0,S=(t,n)=>(0,e.getDataEnum)(p,t,n)??(h?(0,e.getDataEnum)(h,t,n):void 0)??(0,e.getDataEnum)(l,t,n),C=t=>(0,e.getDataNumber)(p,t)??(h?(0,e.getDataNumber)(h,t):void 0)??(0,e.getDataNumber)(l,t),w=t=>(0,e.getDataBool)(p,t)??(h?(0,e.getDataBool)(h,t):void 0)??(0,e.getDataBool)(l,t),T=u.side??S(`side`,s)??`top`,E=u.align??S(`align`,c)??`center`,D=u.sideOffset??C(`sideOffset`)??4,O=u.alignOffset??C(`alignOffset`)??0,k=u.avoidCollisions??w(`avoidCollisions`)??!0,A=u.collisionPadding??C(`collisionPadding`)??8,j=!1,M=!1,N=!1,P=!1,F=null,I=[],L=(0,e.createPortalLifecycle)({content:p,root:l,enabled:x,wrapperSlot:h?void 0:`tooltip-positioner`,container:h??void 0,mountTarget:h?_??h:void 0}),R=(0,e.ensureId)(p,`tooltip-content`);p.setAttribute(`role`,`tooltip`),p.setAttribute(`data-side`,T),p.setAttribute(`data-align`,E);let z=e=>{let t=L.container;if(l.setAttribute(`data-state`,e),p.setAttribute(`data-state`,e),t!==p&&t.setAttribute(`data-state`,e),e===`open`){l.setAttribute(`data-open`,``),p.setAttribute(`data-open`,``),t!==p&&t.setAttribute(`data-open`,``),M?(l.setAttribute(`data-instant`,``),p.setAttribute(`data-instant`,``),t!==p&&t.setAttribute(`data-instant`,``)):(l.removeAttribute(`data-instant`),p.removeAttribute(`data-instant`),t!==p&&t.removeAttribute(`data-instant`)),l.removeAttribute(`data-closed`),p.removeAttribute(`data-closed`),t!==p&&t.removeAttribute(`data-closed`);return}l.setAttribute(`data-closed`,``),p.setAttribute(`data-closed`,``),t!==p&&t.setAttribute(`data-closed`,``),M?(l.setAttribute(`data-instant`,``),p.setAttribute(`data-instant`,``),t!==p&&t.setAttribute(`data-instant`,``)):(l.removeAttribute(`data-instant`),p.removeAttribute(`data-instant`),t!==p&&t.removeAttribute(`data-instant`)),l.removeAttribute(`data-open`),p.removeAttribute(`data-open`),t!==p&&t.removeAttribute(`data-open`)},B=()=>{let t=L.container,n=l.ownerDocument.defaultView??window,r=f.getBoundingClientRect(),i=(0,e.computeFloatingPosition)({anchorRect:r,contentRect:(0,e.measurePopupContentRect)(p),side:T,align:E,sideOffset:D,alignOffset:O,avoidCollisions:k,collisionPadding:A}),a=(0,e.computeFloatingTransformOrigin)({side:i.side,align:i.align,anchorRect:r,popupX:i.x,popupY:i.y});t.style.position=`absolute`,t.style.top=`0px`,t.style.left=`0px`,t.style.transform=`translate3d(${i.x+n.scrollX}px, ${i.y+n.scrollY}px, 0)`,t.style.setProperty(`--transform-origin`,a),t.style.willChange=`transform`,t.style.margin=`0`,p.setAttribute(`data-side`,i.side),p.setAttribute(`data-align`,i.align),t!==p&&(t.setAttribute(`data-side`,i.side),t.setAttribute(`data-align`,i.align))},V=(0,e.createPresenceLifecycle)({element:p,onExitComplete:()=>{P||(L.restore(),p.hidden=!0)}}),H=(0,e.createPositionSync)({observedElements:[f,p],isActive:()=>j,ancestorScroll:!1,onUpdate:B}),U=()=>f.hasAttribute(`disabled`)||f.getAttribute(`aria-disabled`)===`true`,W=(t,r,i=!1)=>{j!==t&&(!t&&j&&y>0&&(n=Date.now()+y),M=i,j=t,j?(f.setAttribute(`aria-describedby`,R),p.setAttribute(`aria-hidden`,`false`),L.mount(),p.hidden=!1,z(`open`),V.enter(),B(),H.start(),H.update()):(z(`closed`),f.removeAttribute(`aria-describedby`),p.setAttribute(`aria-hidden`,`true`),V.exit(),H.stop()),(0,e.emit)(l,`tooltip:change`,{open:j,trigger:f,content:p,reason:r}),b?.(j))},G=e=>{if(F&&=(clearTimeout(F),null),Date.now()<n){W(!0,e,!0);return}F=setTimeout(()=>{W(!0,e),F=null},v)},K=(e,t=!1)=>{F&&=(clearTimeout(F),null),W(!1,e,t)},q=(e,t)=>{e===f||!j||(N=!1,K(t,!0))};r.add(f),i.add(q),I.push(()=>{i.delete(q),r.delete(f)}),p.hidden=!0,p.setAttribute(`aria-hidden`,`true`),z(`closed`),I.push((0,e.on)(f,`pointerenter`,e=>{e.pointerType!==`touch`&&(U()||(o(f,`pointer`),G(`pointer`)))}),(0,e.on)(f,`pointerleave`,e=>{if(e.pointerType===`touch`||N)return;let t=e.relatedTarget;if(!(t&&p.contains(t))){if(a(t,f)){K(`pointer`,!0);return}K(`pointer`)}}),(0,e.on)(f,`click`,()=>{if(!U()){if(F){clearTimeout(F),F=null;return}j&&K(`pointer`,!0)}}),(0,e.on)(f,`focus`,()=>{N=!0,!U()&&(o(f,`focus`),G(`focus`))}),(0,e.on)(f,`blur`,e=>{N=!1;let t=e.relatedTarget;if(a(t,f)){K(`blur`,!0);return}K(`blur`)})),I.push((0,e.on)(p,`pointerleave`,e=>{if(e.pointerType===`touch`||N)return;let t=e.relatedTarget;if(!(t&&f.contains(t))){if(a(t,f)){K(`pointer`,!0);return}K(`pointer`)}})),I.push((0,e.on)(l,`tooltip:set`,e=>{let t=e.detail,n;if(t?.open===void 0?t?.value!==void 0&&(n=t.value):n=t.open,typeof n==`boolean`)if(n){if(U())return;F&&=(clearTimeout(F),null),W(!0,`api`)}else K(`api`)})),I.push((0,e.createDismissLayer)({root:l,isOpen:()=>j,onDismiss:()=>K(`escape`),closeOnClickOutside:!1,closeOnEscape:!0,preventEscapeDefault:!1}));let J={show:()=>{U()||(F&&=(clearTimeout(F),null),W(!0,`api`))},hide:()=>K(`api`),get isOpen(){return j},destroy:()=>{P=!0,F&&clearTimeout(F),H.stop(),V.cleanup(),L.cleanup(),I.forEach(e=>e()),I.length=0,(0,e.clearRootBinding)(l,t,J)}};return(0,e.setRootBinding)(l,t,J),J}function u(n=document){let r=[];for(let i of(0,e.getRoots)(n,`tooltip`))(0,e.hasRootBinding)(i,t)||r.push(l(i));return r}exports.create=u,exports.createTooltip=l;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{computeFloatingPosition as e,computeFloatingTransformOrigin as t,createDismissLayer as n,createPortalLifecycle as r,createPositionSync as i,createPresenceLifecycle as a,emit as o,ensureId as s,getDataBool as c,getDataEnum as l,getDataNumber as u,getPart as d,getRoots as f,measurePopupContentRect as p,on as m}from"@data-slot/core";let h=0;const g=new Set,_=new Set,v=(e,t)=>{if(!e)return!1;for(let n of g)if(n!==t&&n.contains(e))return!0;return!1},y=(e,t)=>{for(let n of _)n(e,t)},ee=[`top`,`right`,`bottom`,`left`],b=[`start`,`center`,`end`];function x(f,x={}){let S=d(f,`tooltip-trigger`),C=d(f,`tooltip-content`),w=d(f,`tooltip-positioner`),T=w&&C&&w.contains(C)?w:null,E=d(f,`tooltip-portal`),D=E&&T&&E.contains(T)?E:null;if(!S||!C)throw Error(`Tooltip requires trigger and content slots`);let te=x.delay??u(f,`delay`)??300,O=x.skipDelayDuration??u(f,`skipDelayDuration`)??300,ne=x.onOpenChange,re=x.portal??c(C,`portal`)??c(f,`portal`)??!0,k=(e,t)=>l(C,e,t)??(T?l(T,e,t):void 0)??l(f,e,t),A=e=>u(C,e)??(T?u(T,e):void 0)??u(f,e),j=e=>c(C,e)??(T?c(T,e):void 0)??c(f,e),M=x.side??k(`side`,ee)??`top`,N=x.align??k(`align`,b)??`center`,P=x.sideOffset??A(`sideOffset`)??4,F=x.alignOffset??A(`alignOffset`)??0,I=x.avoidCollisions??j(`avoidCollisions`)??!0,ie=x.collisionPadding??A(`collisionPadding`)??8,L=!1,R=!1,z=!1,B=!1,V=null,H=[],U=r({content:C,root:f,enabled:re,wrapperSlot:T?void 0:`tooltip-positioner`,container:T??void 0,mountTarget:T?D??T:void 0}),W=s(C,`tooltip-content`);C.setAttribute(`role`,`tooltip`),C.setAttribute(`data-side`,M),C.setAttribute(`data-align`,N);let G=e=>{let t=U.container;if(f.setAttribute(`data-state`,e),C.setAttribute(`data-state`,e),t!==C&&t.setAttribute(`data-state`,e),e===`open`){f.setAttribute(`data-open`,``),C.setAttribute(`data-open`,``),t!==C&&t.setAttribute(`data-open`,``),R?(f.setAttribute(`data-instant`,``),C.setAttribute(`data-instant`,``),t!==C&&t.setAttribute(`data-instant`,``)):(f.removeAttribute(`data-instant`),C.removeAttribute(`data-instant`),t!==C&&t.removeAttribute(`data-instant`)),f.removeAttribute(`data-closed`),C.removeAttribute(`data-closed`),t!==C&&t.removeAttribute(`data-closed`);return}f.setAttribute(`data-closed`,``),C.setAttribute(`data-closed`,``),t!==C&&t.setAttribute(`data-closed`,``),R?(f.setAttribute(`data-instant`,``),C.setAttribute(`data-instant`,``),t!==C&&t.setAttribute(`data-instant`,``)):(f.removeAttribute(`data-instant`),C.removeAttribute(`data-instant`),t!==C&&t.removeAttribute(`data-instant`)),f.removeAttribute(`data-open`),C.removeAttribute(`data-open`),t!==C&&t.removeAttribute(`data-open`)},K=()=>{let n=U.container,r=f.ownerDocument.defaultView??window,i=S.getBoundingClientRect(),a=e({anchorRect:i,contentRect:p(C),side:M,align:N,sideOffset:P,alignOffset:F,avoidCollisions:I,collisionPadding:ie}),o=t({side:a.side,align:a.align,anchorRect:i,popupX:a.x,popupY:a.y});n.style.position=`absolute`,n.style.top=`0px`,n.style.left=`0px`,n.style.transform=`translate3d(${a.x+r.scrollX}px, ${a.y+r.scrollY}px, 0)`,n.style.setProperty(`--transform-origin`,o),n.style.willChange=`transform`,n.style.margin=`0`,C.setAttribute(`data-side`,a.side),C.setAttribute(`data-align`,a.align),n!==C&&(n.setAttribute(`data-side`,a.side),n.setAttribute(`data-align`,a.align))},q=a({element:C,onExitComplete:()=>{B||(U.restore(),C.hidden=!0)}}),J=i({observedElements:[S,C],isActive:()=>L,ancestorScroll:!1,onUpdate:K}),Y=()=>S.hasAttribute(`disabled`)||S.getAttribute(`aria-disabled`)===`true`,X=(e,t,n=!1)=>{L!==e&&(!e&&L&&O>0&&(h=Date.now()+O),R=n,L=e,L?(S.setAttribute(`aria-describedby`,W),C.setAttribute(`aria-hidden`,`false`),U.mount(),C.hidden=!1,G(`open`),q.enter(),K(),J.start(),J.update()):(G(`closed`),S.removeAttribute(`aria-describedby`),C.setAttribute(`aria-hidden`,`true`),q.exit(),J.stop()),o(f,`tooltip:change`,{open:L,trigger:S,content:C,reason:t}),ne?.(L))},Z=e=>{if(V&&=(clearTimeout(V),null),Date.now()<h){X(!0,e,!0);return}V=setTimeout(()=>{X(!0,e),V=null},te)},Q=(e,t=!1)=>{V&&=(clearTimeout(V),null),X(!1,e,t)},$=(e,t)=>{e===S||!L||(z=!1,Q(t,!0))};return g.add(S),_.add($),H.push(()=>{_.delete($),g.delete(S)}),C.hidden=!0,C.setAttribute(`aria-hidden`,`true`),G(`closed`),H.push(m(S,`pointerenter`,e=>{e.pointerType!==`touch`&&(Y()||(y(S,`pointer`),Z(`pointer`)))}),m(S,`pointerleave`,e=>{if(e.pointerType===`touch`||z)return;let t=e.relatedTarget;if(!(t&&C.contains(t))){if(v(t,S)){Q(`pointer`,!0);return}Q(`pointer`)}}),m(S,`click`,()=>{if(!Y()){if(V){clearTimeout(V),V=null;return}L&&Q(`pointer`,!0)}}),m(S,`focus`,()=>{z=!0,!Y()&&(y(S,`focus`),Z(`focus`))}),m(S,`blur`,e=>{z=!1;let t=e.relatedTarget;if(v(t,S)){Q(`blur`,!0);return}Q(`blur`)})),H.push(m(C,`pointerleave`,e=>{if(e.pointerType===`touch`||z)return;let t=e.relatedTarget;if(!(t&&S.contains(t))){if(v(t,S)){Q(`pointer`,!0);return}Q(`pointer`)}})),H.push(m(f,`tooltip:set`,e=>{let t=e.detail,n;if(t?.open===void 0?t?.value!==void 0&&(n=t.value):n=t.open,typeof n==`boolean`)if(n){if(Y())return;V&&=(clearTimeout(V),null),X(!0,`api`)}else Q(`api`)})),H.push(n({root:f,isOpen:()=>L,onDismiss:()=>Q(`escape`),closeOnClickOutside:!1,closeOnEscape:!0,preventEscapeDefault:!1})),{show:()=>{Y()||(V&&=(clearTimeout(V),null),X(!0,`api`))},hide:()=>Q(`api`),get isOpen(){return L},destroy:()=>{B=!0,V&&clearTimeout(V),J.stop(),q.cleanup(),U.cleanup(),H.forEach(e=>e()),H.length=0}}}const S=new WeakSet;function C(e=document){let t=[];for(let n of f(e,`tooltip`))S.has(n)||(S.add(n),t.push(x(n)));return t}export{C as create,x as createTooltip};
1
+ import{clearRootBinding as e,computeFloatingPosition as t,computeFloatingTransformOrigin as n,createDismissLayer as r,createPortalLifecycle as i,createPositionSync as a,createPresenceLifecycle as o,emit as s,ensureId as ee,getDataBool as c,getDataEnum as l,getDataNumber as u,getPart as d,getRoots as f,hasRootBinding as p,measurePopupContentRect as m,on as h,reuseRootBinding as te,setRootBinding as g}from"@data-slot/core";const _=`@data-slot/tooltip`;let v=0;const y=new Set,b=new Set,x=(e,t)=>{if(!e)return!1;for(let n of y)if(n!==t&&n.contains(e))return!0;return!1},S=(e,t)=>{for(let n of b)n(e,t)},ne=[`top`,`right`,`bottom`,`left`],C=[`start`,`center`,`end`];function w(f,p={}){let w=te(f,_,`[@data-slot/tooltip] createTooltip() called more than once for the same root. Returning the existing controller. Destroy it before rebinding with new options.`);if(w)return w;let T=d(f,`tooltip-trigger`),E=d(f,`tooltip-content`),D=d(f,`tooltip-positioner`),O=D&&E&&D.contains(E)?D:null,k=d(f,`tooltip-portal`),re=k&&O&&k.contains(O)?k:null;if(!T||!E)throw Error(`Tooltip requires trigger and content slots`);let ie=p.delay??u(f,`delay`)??300,A=p.skipDelayDuration??u(f,`skipDelayDuration`)??300,ae=p.onOpenChange,j=p.portal??c(E,`portal`)??c(f,`portal`)??!0,M=(e,t)=>l(E,e,t)??(O?l(O,e,t):void 0)??l(f,e,t),N=e=>u(E,e)??(O?u(O,e):void 0)??u(f,e),oe=e=>c(E,e)??(O?c(O,e):void 0)??c(f,e),P=p.side??M(`side`,ne)??`top`,F=p.align??M(`align`,C)??`center`,se=p.sideOffset??N(`sideOffset`)??4,ce=p.alignOffset??N(`alignOffset`)??0,I=p.avoidCollisions??oe(`avoidCollisions`)??!0,le=p.collisionPadding??N(`collisionPadding`)??8,L=!1,R=!1,z=!1,B=!1,V=null,H=[],U=i({content:E,root:f,enabled:j,wrapperSlot:O?void 0:`tooltip-positioner`,container:O??void 0,mountTarget:O?re??O:void 0}),ue=ee(E,`tooltip-content`);E.setAttribute(`role`,`tooltip`),E.setAttribute(`data-side`,P),E.setAttribute(`data-align`,F);let W=e=>{let t=U.container;if(f.setAttribute(`data-state`,e),E.setAttribute(`data-state`,e),t!==E&&t.setAttribute(`data-state`,e),e===`open`){f.setAttribute(`data-open`,``),E.setAttribute(`data-open`,``),t!==E&&t.setAttribute(`data-open`,``),R?(f.setAttribute(`data-instant`,``),E.setAttribute(`data-instant`,``),t!==E&&t.setAttribute(`data-instant`,``)):(f.removeAttribute(`data-instant`),E.removeAttribute(`data-instant`),t!==E&&t.removeAttribute(`data-instant`)),f.removeAttribute(`data-closed`),E.removeAttribute(`data-closed`),t!==E&&t.removeAttribute(`data-closed`);return}f.setAttribute(`data-closed`,``),E.setAttribute(`data-closed`,``),t!==E&&t.setAttribute(`data-closed`,``),R?(f.setAttribute(`data-instant`,``),E.setAttribute(`data-instant`,``),t!==E&&t.setAttribute(`data-instant`,``)):(f.removeAttribute(`data-instant`),E.removeAttribute(`data-instant`),t!==E&&t.removeAttribute(`data-instant`)),f.removeAttribute(`data-open`),E.removeAttribute(`data-open`),t!==E&&t.removeAttribute(`data-open`)},G=()=>{let e=U.container,r=f.ownerDocument.defaultView??window,i=T.getBoundingClientRect(),a=t({anchorRect:i,contentRect:m(E),side:P,align:F,sideOffset:se,alignOffset:ce,avoidCollisions:I,collisionPadding:le}),o=n({side:a.side,align:a.align,anchorRect:i,popupX:a.x,popupY:a.y});e.style.position=`absolute`,e.style.top=`0px`,e.style.left=`0px`,e.style.transform=`translate3d(${a.x+r.scrollX}px, ${a.y+r.scrollY}px, 0)`,e.style.setProperty(`--transform-origin`,o),e.style.willChange=`transform`,e.style.margin=`0`,E.setAttribute(`data-side`,a.side),E.setAttribute(`data-align`,a.align),e!==E&&(e.setAttribute(`data-side`,a.side),e.setAttribute(`data-align`,a.align))},K=o({element:E,onExitComplete:()=>{B||(U.restore(),E.hidden=!0)}}),q=a({observedElements:[T,E],isActive:()=>L,ancestorScroll:!1,onUpdate:G}),J=()=>T.hasAttribute(`disabled`)||T.getAttribute(`aria-disabled`)===`true`,Y=(e,t,n=!1)=>{L!==e&&(!e&&L&&A>0&&(v=Date.now()+A),R=n,L=e,L?(T.setAttribute(`aria-describedby`,ue),E.setAttribute(`aria-hidden`,`false`),U.mount(),E.hidden=!1,W(`open`),K.enter(),G(),q.start(),q.update()):(W(`closed`),T.removeAttribute(`aria-describedby`),E.setAttribute(`aria-hidden`,`true`),K.exit(),q.stop()),s(f,`tooltip:change`,{open:L,trigger:T,content:E,reason:t}),ae?.(L))},X=e=>{if(V&&=(clearTimeout(V),null),Date.now()<v){Y(!0,e,!0);return}V=setTimeout(()=>{Y(!0,e),V=null},ie)},Z=(e,t=!1)=>{V&&=(clearTimeout(V),null),Y(!1,e,t)},Q=(e,t)=>{e===T||!L||(z=!1,Z(t,!0))};y.add(T),b.add(Q),H.push(()=>{b.delete(Q),y.delete(T)}),E.hidden=!0,E.setAttribute(`aria-hidden`,`true`),W(`closed`),H.push(h(T,`pointerenter`,e=>{e.pointerType!==`touch`&&(J()||(S(T,`pointer`),X(`pointer`)))}),h(T,`pointerleave`,e=>{if(e.pointerType===`touch`||z)return;let t=e.relatedTarget;if(!(t&&E.contains(t))){if(x(t,T)){Z(`pointer`,!0);return}Z(`pointer`)}}),h(T,`click`,()=>{if(!J()){if(V){clearTimeout(V),V=null;return}L&&Z(`pointer`,!0)}}),h(T,`focus`,()=>{z=!0,!J()&&(S(T,`focus`),X(`focus`))}),h(T,`blur`,e=>{z=!1;let t=e.relatedTarget;if(x(t,T)){Z(`blur`,!0);return}Z(`blur`)})),H.push(h(E,`pointerleave`,e=>{if(e.pointerType===`touch`||z)return;let t=e.relatedTarget;if(!(t&&T.contains(t))){if(x(t,T)){Z(`pointer`,!0);return}Z(`pointer`)}})),H.push(h(f,`tooltip:set`,e=>{let t=e.detail,n;if(t?.open===void 0?t?.value!==void 0&&(n=t.value):n=t.open,typeof n==`boolean`)if(n){if(J())return;V&&=(clearTimeout(V),null),Y(!0,`api`)}else Z(`api`)})),H.push(r({root:f,isOpen:()=>L,onDismiss:()=>Z(`escape`),closeOnClickOutside:!1,closeOnEscape:!0,preventEscapeDefault:!1}));let $={show:()=>{J()||(V&&=(clearTimeout(V),null),Y(!0,`api`))},hide:()=>Z(`api`),get isOpen(){return L},destroy:()=>{B=!0,V&&clearTimeout(V),q.stop(),K.cleanup(),U.cleanup(),H.forEach(e=>e()),H.length=0,e(f,_,$)}};return g(f,_,$),$}function T(e=document){let t=[];for(let n of f(e,`tooltip`))p(n,_)||t.push(w(n));return t}export{T as create,w as createTooltip};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-slot/tooltip",
3
- "version": "0.2.122",
3
+ "version": "0.2.124",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.cjs",
@@ -34,6 +34,6 @@
34
34
  ],
35
35
  "license": "MIT",
36
36
  "dependencies": {
37
- "@data-slot/core": "0.2.122"
37
+ "@data-slot/core": "0.2.124"
38
38
  }
39
39
  }