tolltop 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 David Miranda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # tolltop
2
+
3
+ One-attribute tooltips. Popover API + CSS Anchor Positioning. Auto-inverts color based on page background.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install tolltop
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Script tag (CDN)
14
+
15
+ ```html
16
+ <script src="https://unpkg.com/tolltop"></script>
17
+ ```
18
+
19
+ ### ES module
20
+
21
+ ```js
22
+ import 'tolltop'
23
+ ```
24
+
25
+ ### Then just add the attribute
26
+
27
+ ```html
28
+ <button data-tooltip="Save your work">Save</button>
29
+ ```
30
+
31
+ That's it. No init, no config, no dependencies.
32
+
33
+ ## What it does
34
+
35
+ - **Positions** tooltips above the trigger using CSS Anchor Positioning, flips to bottom when clipped
36
+ - **300ms delay** before showing — no accidental flashes
37
+ - **Auto-detects** background luminance and picks light or dark tooltip style
38
+ - **Event delegation** — works on dynamically added elements
39
+ - **Escape** key dismisses
40
+
41
+ ## License
42
+
43
+ MIT
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ declare module 'tolltop' {}
package/index.js ADDED
@@ -0,0 +1 @@
1
+ (()=>{const s=document.createElement('style');s.textContent=`[popover].tt{position:fixed;position-anchor:--tt;position-area:top;position-try-fallbacks:flip-block;inset:auto;margin:0 0 8px;padding:5px 9px;font:500 12px/1.4 ui-monospace,monospace;border-radius:5px;border:none;max-width:240px;pointer-events:none;z-index:2147483647;opacity:0;transition:opacity .1s ease}[popover].tt:popover-open{opacity:1}@starting-style{[popover].tt:popover-open{opacity:0}}[popover].tt.tt-light{background:#fff;color:#18181b;box-shadow:0 2px 10px rgba(0,0,0,.18),0 0 0 1px rgba(0,0,0,.06)}[popover].tt.tt-dark{background:#18181b;color:#e4e4e7;box-shadow:0 2px 10px rgba(0,0,0,.45),0 0 0 1px rgba(255,255,255,.06)}`;document.head.appendChild(s);const D=300;let tip=null,timer=null,anchor=null;function init(){if(tip)return tip;tip=document.createElement('div');tip.classList.add('tt');tip.setAttribute('popover','manual');document.body.appendChild(tip);return tip}function isDark(el){let n=el;while(n&&n!==document){const bg=getComputedStyle(n).backgroundColor;const m=bg.match(/\d+/g);if(m&&(m.length<4||+m[3]>0)){const[r,g,b]=m.map(Number);return r*.299+g*.587+b*.114<128}n=n.parentElement}return true}function show(el){const text=el.getAttribute('data-tooltip');if(!text)return;el.style.anchorName='--tt';const t=init();t.textContent=text;t.classList.toggle('tt-light',isDark(el));t.classList.toggle('tt-dark',!isDark(el));t.showPopover();anchor=el}function hide(){clearTimeout(timer);if(tip)try{tip.hidePopover()}catch{}if(anchor){anchor.style.anchorName='';anchor=null}}document.addEventListener('pointerenter',e=>{if(!e.target||!e.target.closest)return;const el=e.target.closest('[data-tooltip]');if(!el)return;hide();timer=setTimeout(()=>show(el),D)},true);document.addEventListener('pointerleave',e=>{if(!e.target||!e.target.closest)return;if(e.target.closest('[data-tooltip]'))hide()},true);document.addEventListener('keydown',e=>{if(e.key==='Escape')hide()})})();
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "tolltop",
3
+ "version": "1.0.0",
4
+ "description": "One-attribute tooltips. Popover API + CSS Anchor Positioning. Auto-inverts color based on page background.",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "files": [
8
+ "index.js",
9
+ "index.d.ts"
10
+ ],
11
+ "keywords": [
12
+ "tooltip",
13
+ "popover",
14
+ "anchor-positioning",
15
+ "css",
16
+ "lightweight"
17
+ ],
18
+ "author": "David Miranda",
19
+ "license": "MIT",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/davidmiranda/tolltop"
23
+ }
24
+ }