@data-slot/tooltip 0.2.123 → 0.2.125
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 +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@data-slot/core`)
|
|
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{
|
|
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.
|
|
3
|
+
"version": "0.2.125",
|
|
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.
|
|
37
|
+
"@data-slot/core": "0.2.125"
|
|
38
38
|
}
|
|
39
39
|
}
|