tolltop 1.0.1 → 2.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/README.md +43 -11
- package/index.js +1 -1
- package/package.json +13 -5
- package/tolltop.css +31 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# tolltop
|
|
2
2
|
|
|
3
|
-
One-attribute
|
|
3
|
+
One-attribute CSS tooltips. No JavaScript required.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -10,33 +10,65 @@ npm install tolltop
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
###
|
|
13
|
+
### CDN (recommended)
|
|
14
14
|
|
|
15
15
|
```html
|
|
16
|
-
<
|
|
16
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tolltop/tolltop.css">
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
###
|
|
19
|
+
### CSS import
|
|
20
|
+
|
|
21
|
+
```css
|
|
22
|
+
@import 'tolltop/tolltop.css';
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### JS bundler
|
|
20
26
|
|
|
21
27
|
```js
|
|
22
28
|
import 'tolltop'
|
|
23
29
|
```
|
|
24
30
|
|
|
31
|
+
This auto-injects the stylesheet — a convenience wrapper, not a runtime dependency.
|
|
32
|
+
|
|
25
33
|
### Then just add the attribute
|
|
26
34
|
|
|
27
35
|
```html
|
|
28
36
|
<button data-tooltip="Save your work">Save</button>
|
|
29
37
|
```
|
|
30
38
|
|
|
31
|
-
|
|
39
|
+
## How it works
|
|
40
|
+
|
|
41
|
+
The entire library is CSS:
|
|
42
|
+
|
|
43
|
+
- `::after` pseudo-element with `content: attr(data-tooltip)`
|
|
44
|
+
- CSS Anchor Positioning (`position-area: top` + `position-try-fallbacks: flip-block`) for viewport flipping
|
|
45
|
+
- `light-dark()` for automatic color inversion based on `color-scheme`
|
|
46
|
+
- `:hover` for show/hide (works as tap on mobile)
|
|
47
|
+
|
|
48
|
+
## Customization
|
|
32
49
|
|
|
33
|
-
|
|
50
|
+
Override with CSS variables (globally or per-element):
|
|
51
|
+
|
|
52
|
+
```css
|
|
53
|
+
:root {
|
|
54
|
+
--tt-bg: #1e3a5f;
|
|
55
|
+
--tt-color: #fff;
|
|
56
|
+
--tt-radius: 8px;
|
|
57
|
+
--tt-font-size: 14px;
|
|
58
|
+
--tt-line-height: 1.5;
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Color inversion
|
|
63
|
+
|
|
64
|
+
Set `color-scheme` on your page or sections:
|
|
65
|
+
|
|
66
|
+
```css
|
|
67
|
+
body { color-scheme: dark; }
|
|
68
|
+
.light-section { color-scheme: light; }
|
|
69
|
+
```
|
|
34
70
|
|
|
35
|
-
-
|
|
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
|
|
71
|
+
Tooltips auto-invert based on the nearest `color-scheme`.
|
|
40
72
|
|
|
41
73
|
## License
|
|
42
74
|
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{
|
|
1
|
+
(()=>{(()=>{let t=document.createElement("style");t.textContent="[data-tooltip]:hover{anchor-name:--tt}[data-tooltip]:after{content:attr(data-tooltip);position:fixed;position-anchor:--tt;position-area:top;position-try-fallbacks:flip-block;inset:auto;margin:0 0 8px;padding:5px 9px;font-size:var(--tt-font-size, 12px);font-weight:500;line-height:var(--tt-line-height, 1.4);font-family:ui-monospace,monospace;border-radius:var(--tt-radius, 5px);max-width:240px;width:max-content;text-align:center;pointer-events:none;z-index:2147483647;background:var(--tt-bg, light-dark(#18181b, #fafafa));color:var(--tt-color, light-dark(#e4e4e7, #18181b));box-shadow:0 2px 10px light-dark(rgba(0,0,0,.45),rgba(0,0,0,.12)),0 0 0 1px light-dark(rgba(255,255,255,.06),rgba(0,0,0,.06));opacity:0;transition:opacity .1s ease}[data-tooltip]:hover:after{opacity:1}",document.head.appendChild(t)})();})();
|
package/package.json
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tolltop",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "One-attribute tooltips.
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "One-attribute CSS tooltips. CSS Anchor Positioning + light-dark().",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"style": "tolltop.css",
|
|
6
7
|
"types": "index.d.ts",
|
|
7
8
|
"files": [
|
|
8
9
|
"index.js",
|
|
9
|
-
"index.d.ts"
|
|
10
|
+
"index.d.ts",
|
|
11
|
+
"tolltop.css"
|
|
10
12
|
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "node build.js"
|
|
15
|
+
},
|
|
11
16
|
"keywords": [
|
|
12
17
|
"tooltip",
|
|
13
|
-
"popover",
|
|
14
|
-
"anchor-positioning",
|
|
15
18
|
"css",
|
|
19
|
+
"anchor-positioning",
|
|
20
|
+
"light-dark",
|
|
16
21
|
"lightweight"
|
|
17
22
|
],
|
|
18
23
|
"author": "David Miranda",
|
|
@@ -20,5 +25,8 @@
|
|
|
20
25
|
"repository": {
|
|
21
26
|
"type": "git",
|
|
22
27
|
"url": "https://github.com/davidmiranda/tolltop"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"esbuild": "^0.27.4"
|
|
23
31
|
}
|
|
24
32
|
}
|
package/tolltop.css
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[data-tooltip]:hover { anchor-name: --tt; }
|
|
2
|
+
|
|
3
|
+
[data-tooltip]::after {
|
|
4
|
+
content: attr(data-tooltip);
|
|
5
|
+
position: fixed;
|
|
6
|
+
position-anchor: --tt;
|
|
7
|
+
position-area: top;
|
|
8
|
+
position-try-fallbacks: flip-block;
|
|
9
|
+
inset: auto;
|
|
10
|
+
margin: 0 0 8px;
|
|
11
|
+
padding: 5px 9px;
|
|
12
|
+
font-size: var(--tt-font-size, 12px);
|
|
13
|
+
font-weight: 500;
|
|
14
|
+
line-height: var(--tt-line-height, 1.4);
|
|
15
|
+
font-family: ui-monospace, monospace;
|
|
16
|
+
border-radius: var(--tt-radius, 5px);
|
|
17
|
+
max-width: 240px;
|
|
18
|
+
width: max-content;
|
|
19
|
+
text-align: center;
|
|
20
|
+
pointer-events: none;
|
|
21
|
+
z-index: 2147483647;
|
|
22
|
+
background: var(--tt-bg, light-dark(#18181b, #fafafa));
|
|
23
|
+
color: var(--tt-color, light-dark(#e4e4e7, #18181b));
|
|
24
|
+
box-shadow:
|
|
25
|
+
0 2px 10px light-dark(rgba(0,0,0,.45), rgba(0,0,0,.12)),
|
|
26
|
+
0 0 0 1px light-dark(rgba(255,255,255,.06), rgba(0,0,0,.06));
|
|
27
|
+
opacity: 0;
|
|
28
|
+
transition: opacity .1s ease;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
[data-tooltip]:hover::after { opacity: 1; }
|