@data-slot/tooltip 0.2.92 → 0.2.94

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/README.md CHANGED
@@ -165,10 +165,10 @@ The component sets these attributes automatically:
165
165
  |---------|-----------|--------|
166
166
  | Root | `data-state` | `"open"` \| `"closed"` |
167
167
  | Root | `data-open` / `data-closed` | Present when matching state |
168
- | Root | `data-instant` | Present for warm-up opens (delay skipped) |
168
+ | Root | `data-instant` | Present for warm-up opens and warm-handoff instant closes |
169
169
  | Content | `data-state` | `"open"` \| `"closed"` |
170
170
  | Content | `data-open` / `data-closed` | Present when matching state |
171
- | Content | `data-instant` | Present for warm-up opens (delay skipped) |
171
+ | Content | `data-instant` | Present for warm-up opens and warm-handoff instant closes |
172
172
  | Content | `data-side` | `"top"` \| `"right"` \| `"bottom"` \| `"left"` |
173
173
  | Content | `data-align` | `"start"` \| `"center"` \| `"end"` |
174
174
  | Content | `role` | `"tooltip"` |
@@ -179,6 +179,7 @@ The component sets these attributes automatically:
179
179
 
180
180
  Position is computed in JavaScript and applied to the positioner as `position: absolute` + `transform: translate3d(...)`.
181
181
  By default, content is portaled to `document.body` while open.
182
+ The positioned element (`tooltip-positioner`, or `tooltip-content` when `portal` is disabled) gets `--transform-origin`, which `tooltip-content` can use for transform animations via CSS inheritance.
182
183
  Use `data-open` / `data-closed`, `data-side`, and `data-align` for styling and animations.
183
184
  Placement uses layout dimensions, so `scale`/`zoom` animations on `tooltip-content` remain stable without adding an extra wrapper.
184
185
 
@@ -192,7 +193,7 @@ The visibility transition trick keeps the tooltip visible during fade-out, then
192
193
  opacity: 0;
193
194
  visibility: hidden;
194
195
  pointer-events: none;
195
- transform-origin: center;
196
+ transform-origin: var(--transform-origin, center);
196
197
  transition: opacity 0.15s ease, visibility 0s linear 0.15s;
197
198
  }
198
199
 
@@ -242,7 +243,8 @@ When a user closes one tooltip and quickly hovers another, the second tooltip sh
242
243
 
243
244
  - Controlled by `skipDelayDuration` option
244
245
  - Set to `0` to disable this behavior
245
- - Warm-up adds `data-instant` on the open cycle so CSS can disable transitions
246
+ - Warm-up adds `data-instant` on instant open/close cycles so CSS can disable transitions
247
+ - During warm handoff to another tooltip trigger, the stale tooltip closes with `data-instant` so exit animation can be skipped
246
248
  - Warm window is set only when a tooltip actually closes (not when a pending open is cancelled)
247
249
 
248
250
  ## Accessibility
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=[`top`,`right`,`bottom`,`left`],r=[`start`,`center`,`end`];function i(i,a={}){let o=(0,e.getPart)(i,`tooltip-trigger`),s=(0,e.getPart)(i,`tooltip-content`),c=(0,e.getPart)(i,`tooltip-positioner`),l=c&&s&&c.contains(s)?c:null,u=(0,e.getPart)(i,`tooltip-portal`),d=u&&l&&u.contains(l)?u:null;if(!o||!s)throw Error(`Tooltip requires trigger and content slots`);let f=a.delay??(0,e.getDataNumber)(i,`delay`)??300,p=a.skipDelayDuration??(0,e.getDataNumber)(i,`skipDelayDuration`)??300,m=a.onOpenChange,h=a.portal??(0,e.getDataBool)(s,`portal`)??(0,e.getDataBool)(i,`portal`)??!0,g=(t,n)=>(0,e.getDataEnum)(s,t,n)??(l?(0,e.getDataEnum)(l,t,n):void 0)??(0,e.getDataEnum)(i,t,n),_=t=>(0,e.getDataNumber)(s,t)??(l?(0,e.getDataNumber)(l,t):void 0)??(0,e.getDataNumber)(i,t),v=t=>(0,e.getDataBool)(s,t)??(l?(0,e.getDataBool)(l,t):void 0)??(0,e.getDataBool)(i,t),y=a.side??g(`side`,n)??`top`,b=a.align??g(`align`,r)??`center`,x=a.sideOffset??_(`sideOffset`)??4,S=a.alignOffset??_(`alignOffset`)??0,C=a.avoidCollisions??v(`avoidCollisions`)??!0,w=a.collisionPadding??_(`collisionPadding`)??8,T=!1,E=!1,D=!1,O=!1,k=null,A=[],j=(0,e.createPortalLifecycle)({content:s,root:i,enabled:h,wrapperSlot:l?void 0:`tooltip-positioner`,container:l??void 0,mountTarget:l?d??l:void 0}),M=(0,e.ensureId)(s,`tooltip-content`);s.setAttribute(`role`,`tooltip`),s.setAttribute(`data-side`,y),s.setAttribute(`data-align`,b);let N=e=>{let t=j.container;if(i.setAttribute(`data-state`,e),s.setAttribute(`data-state`,e),t!==s&&t.setAttribute(`data-state`,e),e===`open`){i.setAttribute(`data-open`,``),s.setAttribute(`data-open`,``),t!==s&&t.setAttribute(`data-open`,``),E?(i.setAttribute(`data-instant`,``),s.setAttribute(`data-instant`,``),t!==s&&t.setAttribute(`data-instant`,``)):(i.removeAttribute(`data-instant`),s.removeAttribute(`data-instant`),t!==s&&t.removeAttribute(`data-instant`)),i.removeAttribute(`data-closed`),s.removeAttribute(`data-closed`),t!==s&&t.removeAttribute(`data-closed`);return}i.setAttribute(`data-closed`,``),s.setAttribute(`data-closed`,``),t!==s&&t.setAttribute(`data-closed`,``),i.removeAttribute(`data-instant`),s.removeAttribute(`data-instant`),t!==s&&t.removeAttribute(`data-instant`),i.removeAttribute(`data-open`),s.removeAttribute(`data-open`),t!==s&&t.removeAttribute(`data-open`)},P=()=>{let t=j.container,n=i.ownerDocument.defaultView??window,r=(0,e.computeFloatingPosition)({anchorRect:o.getBoundingClientRect(),contentRect:(0,e.measurePopupContentRect)(s),side:y,align:b,sideOffset:x,alignOffset:S,avoidCollisions:C,collisionPadding:w});t.style.position=`absolute`,t.style.top=`0px`,t.style.left=`0px`,t.style.transform=`translate3d(${r.x+n.scrollX}px, ${r.y+n.scrollY}px, 0)`,t.style.willChange=`transform`,t.style.margin=`0`,s.setAttribute(`data-side`,r.side),s.setAttribute(`data-align`,r.align),t!==s&&(t.setAttribute(`data-side`,r.side),t.setAttribute(`data-align`,r.align))},F=(0,e.createPresenceLifecycle)({element:s,onExitComplete:()=>{O||(j.restore(),s.hidden=!0)}}),I=(0,e.createPositionSync)({observedElements:[o,s],isActive:()=>T,ancestorScroll:!1,onUpdate:P}),L=()=>o.hasAttribute(`disabled`)||o.getAttribute(`aria-disabled`)===`true`,R=(n,r,a=!1)=>{T!==n&&(!n&&T&&p>0&&(t=Date.now()+p),E=n?a:!1,T=n,T?(o.setAttribute(`aria-describedby`,M),s.setAttribute(`aria-hidden`,`false`),j.mount(),s.hidden=!1,N(`open`),F.enter(),P(),I.start(),I.update()):(N(`closed`),o.removeAttribute(`aria-describedby`),s.setAttribute(`aria-hidden`,`true`),F.exit(),I.stop()),(0,e.emit)(i,`tooltip:change`,{open:T,trigger:o,content:s,reason:r}),m?.(T))},z=e=>{if(k&&=(clearTimeout(k),null),Date.now()<t){R(!0,e,!0);return}k=setTimeout(()=>{R(!0,e),k=null},f)},B=e=>{k&&=(clearTimeout(k),null),R(!1,e)};return s.hidden=!0,s.setAttribute(`aria-hidden`,`true`),N(`closed`),A.push((0,e.on)(o,`pointerenter`,e=>{e.pointerType!==`touch`&&(L()||z(`pointer`))}),(0,e.on)(o,`pointerleave`,e=>{if(e.pointerType===`touch`||D)return;let t=e.relatedTarget;t&&s.contains(t)||B(`pointer`)}),(0,e.on)(o,`focus`,()=>{D=!0,!L()&&z(`focus`)}),(0,e.on)(o,`blur`,()=>{D=!1,B(`blur`)})),A.push((0,e.on)(s,`pointerleave`,e=>{if(e.pointerType===`touch`||D)return;let t=e.relatedTarget;t&&o.contains(t)||B(`pointer`)})),A.push((0,e.on)(i,`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(L())return;k&&=(clearTimeout(k),null),R(!0,`api`)}else B(`api`)})),A.push((0,e.createDismissLayer)({root:i,isOpen:()=>T,onDismiss:()=>B(`escape`),closeOnClickOutside:!1,closeOnEscape:!0,preventEscapeDefault:!1})),{show:()=>{L()||(k&&=(clearTimeout(k),null),R(!0,`api`))},hide:()=>B(`api`),get isOpen(){return T},destroy:()=>{O=!0,k&&clearTimeout(k),I.stop(),F.cleanup(),j.cleanup(),A.forEach(e=>e()),A.length=0}}}const a=new WeakSet;function o(t=document){let n=[];for(let r of(0,e.getRoots)(t,`tooltip`))a.has(r)||(a.add(r),n.push(i(r)));return n}exports.create=o,exports.createTooltip=i;
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,`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;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{computeFloatingPosition as e,createDismissLayer as t,createPortalLifecycle as n,createPositionSync as r,createPresenceLifecycle as i,emit as a,ensureId as o,getDataBool as s,getDataEnum as c,getDataNumber as l,getPart as u,getRoots as d,measurePopupContentRect as f,on as p}from"@data-slot/core";let m=0;const h=[`top`,`right`,`bottom`,`left`],g=[`start`,`center`,`end`];function _(d,_={}){let v=u(d,`tooltip-trigger`),y=u(d,`tooltip-content`),b=u(d,`tooltip-positioner`),x=b&&y&&b.contains(y)?b:null,S=u(d,`tooltip-portal`),C=S&&x&&S.contains(x)?S:null;if(!v||!y)throw Error(`Tooltip requires trigger and content slots`);let w=_.delay??l(d,`delay`)??300,T=_.skipDelayDuration??l(d,`skipDelayDuration`)??300,E=_.onOpenChange,D=_.portal??s(y,`portal`)??s(d,`portal`)??!0,O=(e,t)=>c(y,e,t)??(x?c(x,e,t):void 0)??c(d,e,t),k=e=>l(y,e)??(x?l(x,e):void 0)??l(d,e),A=e=>s(y,e)??(x?s(x,e):void 0)??s(d,e),j=_.side??O(`side`,h)??`top`,M=_.align??O(`align`,g)??`center`,N=_.sideOffset??k(`sideOffset`)??4,P=_.alignOffset??k(`alignOffset`)??0,F=_.avoidCollisions??A(`avoidCollisions`)??!0,I=_.collisionPadding??k(`collisionPadding`)??8,L=!1,R=!1,z=!1,B=!1,V=null,H=[],U=n({content:y,root:d,enabled:D,wrapperSlot:x?void 0:`tooltip-positioner`,container:x??void 0,mountTarget:x?C??x:void 0}),W=o(y,`tooltip-content`);y.setAttribute(`role`,`tooltip`),y.setAttribute(`data-side`,j),y.setAttribute(`data-align`,M);let G=e=>{let t=U.container;if(d.setAttribute(`data-state`,e),y.setAttribute(`data-state`,e),t!==y&&t.setAttribute(`data-state`,e),e===`open`){d.setAttribute(`data-open`,``),y.setAttribute(`data-open`,``),t!==y&&t.setAttribute(`data-open`,``),R?(d.setAttribute(`data-instant`,``),y.setAttribute(`data-instant`,``),t!==y&&t.setAttribute(`data-instant`,``)):(d.removeAttribute(`data-instant`),y.removeAttribute(`data-instant`),t!==y&&t.removeAttribute(`data-instant`)),d.removeAttribute(`data-closed`),y.removeAttribute(`data-closed`),t!==y&&t.removeAttribute(`data-closed`);return}d.setAttribute(`data-closed`,``),y.setAttribute(`data-closed`,``),t!==y&&t.setAttribute(`data-closed`,``),d.removeAttribute(`data-instant`),y.removeAttribute(`data-instant`),t!==y&&t.removeAttribute(`data-instant`),d.removeAttribute(`data-open`),y.removeAttribute(`data-open`),t!==y&&t.removeAttribute(`data-open`)},K=()=>{let t=U.container,n=d.ownerDocument.defaultView??window,r=e({anchorRect:v.getBoundingClientRect(),contentRect:f(y),side:j,align:M,sideOffset:N,alignOffset:P,avoidCollisions:F,collisionPadding:I});t.style.position=`absolute`,t.style.top=`0px`,t.style.left=`0px`,t.style.transform=`translate3d(${r.x+n.scrollX}px, ${r.y+n.scrollY}px, 0)`,t.style.willChange=`transform`,t.style.margin=`0`,y.setAttribute(`data-side`,r.side),y.setAttribute(`data-align`,r.align),t!==y&&(t.setAttribute(`data-side`,r.side),t.setAttribute(`data-align`,r.align))},q=i({element:y,onExitComplete:()=>{B||(U.restore(),y.hidden=!0)}}),J=r({observedElements:[v,y],isActive:()=>L,ancestorScroll:!1,onUpdate:K}),Y=()=>v.hasAttribute(`disabled`)||v.getAttribute(`aria-disabled`)===`true`,X=(e,t,n=!1)=>{L!==e&&(!e&&L&&T>0&&(m=Date.now()+T),R=e?n:!1,L=e,L?(v.setAttribute(`aria-describedby`,W),y.setAttribute(`aria-hidden`,`false`),U.mount(),y.hidden=!1,G(`open`),q.enter(),K(),J.start(),J.update()):(G(`closed`),v.removeAttribute(`aria-describedby`),y.setAttribute(`aria-hidden`,`true`),q.exit(),J.stop()),a(d,`tooltip:change`,{open:L,trigger:v,content:y,reason:t}),E?.(L))},Z=e=>{if(V&&=(clearTimeout(V),null),Date.now()<m){X(!0,e,!0);return}V=setTimeout(()=>{X(!0,e),V=null},w)},Q=e=>{V&&=(clearTimeout(V),null),X(!1,e)};return y.hidden=!0,y.setAttribute(`aria-hidden`,`true`),G(`closed`),H.push(p(v,`pointerenter`,e=>{e.pointerType!==`touch`&&(Y()||Z(`pointer`))}),p(v,`pointerleave`,e=>{if(e.pointerType===`touch`||z)return;let t=e.relatedTarget;t&&y.contains(t)||Q(`pointer`)}),p(v,`focus`,()=>{z=!0,!Y()&&Z(`focus`)}),p(v,`blur`,()=>{z=!1,Q(`blur`)})),H.push(p(y,`pointerleave`,e=>{if(e.pointerType===`touch`||z)return;let t=e.relatedTarget;t&&v.contains(t)||Q(`pointer`)})),H.push(p(d,`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(t({root:d,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 v=new WeakSet;function y(e=document){let t=[];for(let n of d(e,`tooltip`))v.has(n)||(v.add(n),t.push(_(n)));return t}export{y as create,_ as createTooltip};
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,`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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-slot/tooltip",
3
- "version": "0.2.92",
3
+ "version": "0.2.94",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.cjs",
@@ -38,6 +38,6 @@
38
38
  ],
39
39
  "license": "MIT",
40
40
  "dependencies": {
41
- "@data-slot/core": "0.2.92"
41
+ "@data-slot/core": "0.2.94"
42
42
  }
43
43
  }