@data-slot/tooltip 0.1.0 → 0.1.2

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
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=s(require(`@data-slot/core`));let l=0;const u=300;function d(e,t={}){let{delay:n=300,skipDelayDuration:r=u,onOpenChange:i}=t,a=(0,c.getPart)(e,`tooltip-trigger`),o=(0,c.getPart)(e,`tooltip-content`);if(!a||!o)throw Error(`Tooltip requires trigger and content slots`);let s=t.position??o.dataset.position??`top`,d=!1,f=null,p=[],m=(0,c.ensureId)(o,`tooltip-content`);a.setAttribute(`aria-describedby`,m),o.setAttribute(`role`,`tooltip`),o.setAttribute(`data-position`,s);let h=(t,n=!1)=>{d!==t&&(d=t,o.hidden=!d,e.setAttribute(`data-state`,d?`open`:`closed`),n&&d?o.setAttribute(`data-instant`,``):o.removeAttribute(`data-instant`),(0,c.emit)(e,`tooltip:change`,{open:d}),i?.(d))},g=()=>{if(f)return;let e=Date.now();if(e<l){h(!0,!0);return}f=setTimeout(()=>{h(!0,!1),f=null},n)},_=()=>{f&&(clearTimeout(f),f=null),d&&r>0&&(l=Date.now()+r),h(!1)};o.hidden=!0,e.setAttribute(`data-state`,`closed`),p.push((0,c.on)(a,`mouseenter`,g),(0,c.on)(a,`mouseleave`,_),(0,c.on)(a,`focus`,g),(0,c.on)(a,`blur`,_)),p.push((0,c.on)(document,`keydown`,e=>{d&&e.key===`Escape`&&_()}));let v={show:()=>{f&&(clearTimeout(f),f=null),h(!0)},hide:_,get isOpen(){return d},destroy:()=>{f&&clearTimeout(f),p.forEach(e=>e()),p.length=0}};return v}const f=new WeakSet;function p(e=document){let t=[];for(let n of(0,c.getRoots)(e,`tooltip`)){if(f.has(n))continue;f.add(n),t.push(d(n))}return t}exports.create=p,exports.createTooltip=d;
1
+ const e=(e,t)=>e.querySelector(`[data-slot="${t}"]`),t=(e,t)=>[...e.querySelectorAll(`[data-slot="${t}"]`)];let n=0;const r=(e,t)=>e.id||=`${t}-${++n}`,i=(e,t,n,r)=>(e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)),a=(e,t,n)=>e.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:n}));let o=0;const s=300;function c(t,n={}){let{delay:c=300,skipDelayDuration:l=s,onOpenChange:u}=n,d=e(t,`tooltip-trigger`),f=e(t,`tooltip-content`);if(!d||!f)throw Error(`Tooltip requires trigger and content slots`);let p=n.position??f.dataset.position??`top`,m=!1,h=null,g=[],_=r(f,`tooltip-content`);d.setAttribute(`aria-describedby`,_),f.setAttribute(`role`,`tooltip`),f.setAttribute(`data-position`,p);let v=(e,n=!1)=>{m!==e&&(m=e,f.hidden=!m,t.setAttribute(`data-state`,m?`open`:`closed`),n&&m?f.setAttribute(`data-instant`,``):f.removeAttribute(`data-instant`),a(t,`tooltip:change`,{open:m}),u?.(m))},y=()=>{if(h)return;let e=Date.now();if(e<o){v(!0,!0);return}h=setTimeout(()=>{v(!0,!1),h=null},c)},b=()=>{h&&(clearTimeout(h),h=null),m&&l>0&&(o=Date.now()+l),v(!1)};f.hidden=!0,t.setAttribute(`data-state`,`closed`),g.push(i(d,`mouseenter`,y),i(d,`mouseleave`,b),i(d,`focus`,y),i(d,`blur`,b)),g.push(i(document,`keydown`,e=>{m&&e.key===`Escape`&&b()}));let x={show:()=>{h&&(clearTimeout(h),h=null),v(!0)},hide:b,get isOpen(){return m},destroy:()=>{h&&clearTimeout(h),g.forEach(e=>e()),g.length=0}};return x}const l=new WeakSet;function u(e=document){let n=[];for(let r of t(e,`tooltip`)){if(l.has(r))continue;l.add(r),n.push(c(r))}return n}exports.create=u,exports.createTooltip=c;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{emit as e,ensureId as t,getPart as n,getRoots as r,on as i}from"@data-slot/core";let a=0;const o=300;function s(r,s={}){let{delay:c=300,skipDelayDuration:l=o,onOpenChange:u}=s,d=n(r,`tooltip-trigger`),f=n(r,`tooltip-content`);if(!d||!f)throw Error(`Tooltip requires trigger and content slots`);let p=s.position??f.dataset.position??`top`,m=!1,h=null,g=[],_=t(f,`tooltip-content`);d.setAttribute(`aria-describedby`,_),f.setAttribute(`role`,`tooltip`),f.setAttribute(`data-position`,p);let v=(t,n=!1)=>{m!==t&&(m=t,f.hidden=!m,r.setAttribute(`data-state`,m?`open`:`closed`),n&&m?f.setAttribute(`data-instant`,``):f.removeAttribute(`data-instant`),e(r,`tooltip:change`,{open:m}),u?.(m))},y=()=>{if(h)return;let e=Date.now();if(e<a){v(!0,!0);return}h=setTimeout(()=>{v(!0,!1),h=null},c)},b=()=>{h&&(clearTimeout(h),h=null),m&&l>0&&(a=Date.now()+l),v(!1)};f.hidden=!0,r.setAttribute(`data-state`,`closed`),g.push(i(d,`mouseenter`,y),i(d,`mouseleave`,b),i(d,`focus`,y),i(d,`blur`,b)),g.push(i(document,`keydown`,e=>{m&&e.key===`Escape`&&b()}));let x={show:()=>{h&&(clearTimeout(h),h=null),v(!0)},hide:b,get isOpen(){return m},destroy:()=>{h&&clearTimeout(h),g.forEach(e=>e()),g.length=0}};return x}const c=new WeakSet;function l(e=document){let t=[];for(let n of r(e,`tooltip`)){if(c.has(n))continue;c.add(n),t.push(s(n))}return t}export{l as create,s as createTooltip};
1
+ const e=(e,t)=>e.querySelector(`[data-slot="${t}"]`),t=(e,t)=>[...e.querySelectorAll(`[data-slot="${t}"]`)];let n=0;const r=(e,t)=>e.id||=`${t}-${++n}`,i=(e,t,n,r)=>(e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)),a=(e,t,n)=>e.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:n}));let o=0;const s=300;function c(t,n={}){let{delay:c=300,skipDelayDuration:l=s,onOpenChange:u}=n,d=e(t,`tooltip-trigger`),f=e(t,`tooltip-content`);if(!d||!f)throw Error(`Tooltip requires trigger and content slots`);let p=n.position??f.dataset.position??`top`,m=!1,h=null,g=[],_=r(f,`tooltip-content`);d.setAttribute(`aria-describedby`,_),f.setAttribute(`role`,`tooltip`),f.setAttribute(`data-position`,p);let v=(e,n=!1)=>{m!==e&&(m=e,f.hidden=!m,t.setAttribute(`data-state`,m?`open`:`closed`),n&&m?f.setAttribute(`data-instant`,``):f.removeAttribute(`data-instant`),a(t,`tooltip:change`,{open:m}),u?.(m))},y=()=>{if(h)return;let e=Date.now();if(e<o){v(!0,!0);return}h=setTimeout(()=>{v(!0,!1),h=null},c)},b=()=>{h&&(clearTimeout(h),h=null),m&&l>0&&(o=Date.now()+l),v(!1)};f.hidden=!0,t.setAttribute(`data-state`,`closed`),g.push(i(d,`mouseenter`,y),i(d,`mouseleave`,b),i(d,`focus`,y),i(d,`blur`,b)),g.push(i(document,`keydown`,e=>{m&&e.key===`Escape`&&b()}));let x={show:()=>{h&&(clearTimeout(h),h=null),v(!0)},hide:b,get isOpen(){return m},destroy:()=>{h&&clearTimeout(h),g.forEach(e=>e()),g.length=0}};return x}const l=new WeakSet;function u(e=document){let n=[];for(let r of t(e,`tooltip`)){if(l.has(r))continue;l.add(r),n.push(c(r))}return n}export{u as create,c as createTooltip};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-slot/tooltip",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.cjs",
@@ -18,13 +18,26 @@
18
18
  }
19
19
  }
20
20
  },
21
- "files": ["dist"],
21
+ "files": [
22
+ "dist"
23
+ ],
22
24
  "scripts": {
23
25
  "build": "tsdown"
24
26
  },
25
- "dependencies": {
27
+ "devDependencies": {
26
28
  "@data-slot/core": "workspace:*"
27
29
  },
28
- "keywords": ["headless", "ui", "tooltip", "vanilla", "data-slot"],
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/bejamas/data-slot",
33
+ "directory": "packages/tooltip"
34
+ },
35
+ "keywords": [
36
+ "headless",
37
+ "ui",
38
+ "tooltip",
39
+ "vanilla",
40
+ "data-slot"
41
+ ],
29
42
  "license": "MIT"
30
43
  }