@erain20029/tooltips 2.0.12 → 2.0.16
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/tooltip-overlay.es.js +149 -0
- package/package.json +9 -32
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
const w = ".overlay{background:#fff;color:#111;position:fixed;border-radius:10px;z-index:99999;box-shadow:0 0 34px #223c5033;overflow:hidden}.tooltip-card{display:flex;height:100%;align-items:center;gap:16px;padding:16px 20px;max-width:500px;box-sizing:border-box}.tooltip-media{display:flex;justify-content:center}.tooltip-image{width:120px;height:120px;object-fit:cover;border-radius:8px}.tooltip-text{flex:1;min-width:0;display:flex;flex-direction:column;gap:8px}.tooltip-text div{width:100%;display:block}.tooltip-title{font-weight:600;line-height:1.3}.tooltip-desc{line-height:1.5;overflow-wrap:anywhere}", p = {
|
|
2
|
+
tooltips: [],
|
|
3
|
+
ready: !1
|
|
4
|
+
}, m = /* @__PURE__ */ new Set();
|
|
5
|
+
function y(t) {
|
|
6
|
+
return m.has(t) ? Promise.resolve() : new Promise((e, o) => {
|
|
7
|
+
const i = document.createElement("script");
|
|
8
|
+
i.src = t, i.async = !0, i.onload = () => {
|
|
9
|
+
m.add(t), e();
|
|
10
|
+
}, i.onerror = () => o(new Error(`Failed to load script: ${t}`)), document.head.appendChild(i);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
async function h() {
|
|
14
|
+
if (p.ready) return;
|
|
15
|
+
const t = localStorage.getItem("product");
|
|
16
|
+
if (!t) return;
|
|
17
|
+
const e = JSON.parse(t).id;
|
|
18
|
+
await y(`http://localhost:3000/documentation/${e}/tooltip.js`), p.tooltips = await window.tooltipGetter(), p.ready = !0;
|
|
19
|
+
}
|
|
20
|
+
async function b(t) {
|
|
21
|
+
await h();
|
|
22
|
+
const e = t.target;
|
|
23
|
+
if (!(e instanceof Element)) return;
|
|
24
|
+
const o = p.tooltips.find(
|
|
25
|
+
(v) => e.matches(v.selector)
|
|
26
|
+
);
|
|
27
|
+
if (!o) return;
|
|
28
|
+
const i = e.getBoundingClientRect(), l = k(i), { x: n, y: s } = C(
|
|
29
|
+
l,
|
|
30
|
+
i.left,
|
|
31
|
+
i.top
|
|
32
|
+
);
|
|
33
|
+
H({
|
|
34
|
+
tooltip: o,
|
|
35
|
+
rect: i,
|
|
36
|
+
x: n,
|
|
37
|
+
y: s
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function $(t) {
|
|
41
|
+
r && (t.target === r || t.target === u) && x();
|
|
42
|
+
}
|
|
43
|
+
let g = !1;
|
|
44
|
+
async function L() {
|
|
45
|
+
g || (g = !0, await h(), document.addEventListener(
|
|
46
|
+
"mouseenter",
|
|
47
|
+
b,
|
|
48
|
+
!0
|
|
49
|
+
), document.addEventListener(
|
|
50
|
+
"mouseleave",
|
|
51
|
+
$,
|
|
52
|
+
!0
|
|
53
|
+
));
|
|
54
|
+
}
|
|
55
|
+
function T({ title: t, description: e, image: o }) {
|
|
56
|
+
const i = (n) => n === "center" || n === "right" ? n : "left", l = (n) => n === "top" || n === "right" ? n : "left";
|
|
57
|
+
return {
|
|
58
|
+
title: i(t),
|
|
59
|
+
description: i(e),
|
|
60
|
+
image: l(o)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function z({ title: t, description: e }) {
|
|
64
|
+
const o = {
|
|
65
|
+
small: 14,
|
|
66
|
+
medium: 16,
|
|
67
|
+
large: 20
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
title: o[t] ?? 16,
|
|
71
|
+
description: o[e] ?? 14
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const d = 500, f = 200;
|
|
75
|
+
let c = 0, a = 0, r = null, u = null;
|
|
76
|
+
function x() {
|
|
77
|
+
r && (r.remove(), r = null, u = null);
|
|
78
|
+
}
|
|
79
|
+
function C(t, e, o) {
|
|
80
|
+
switch (t) {
|
|
81
|
+
case "left-bottom":
|
|
82
|
+
c = e, a = o + 36;
|
|
83
|
+
break;
|
|
84
|
+
case "right-bottom":
|
|
85
|
+
c = e - d + 45, a = o + 36;
|
|
86
|
+
break;
|
|
87
|
+
case "left-top":
|
|
88
|
+
c = e, a = o - f - 18;
|
|
89
|
+
break;
|
|
90
|
+
case "right-top":
|
|
91
|
+
c = e - d + 45, a = o - f - 18;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
return { x: c, y: a };
|
|
95
|
+
}
|
|
96
|
+
function E() {
|
|
97
|
+
const t = document.createElement("style");
|
|
98
|
+
t.textContent = w, document.body.appendChild(t);
|
|
99
|
+
}
|
|
100
|
+
function S(t) {
|
|
101
|
+
const e = document.createElement("div");
|
|
102
|
+
return e.className = t, e;
|
|
103
|
+
}
|
|
104
|
+
function H(t) {
|
|
105
|
+
if (!t?.tooltip) return null;
|
|
106
|
+
x();
|
|
107
|
+
const e = t.tooltip, o = S("overlay");
|
|
108
|
+
o.style.position = "fixed", o.style.width = `${d}px`, o.style.height = `${f}px`, o.style.left = `${t.x}px`, o.style.top = `${t.y}px`;
|
|
109
|
+
const i = z({
|
|
110
|
+
title: e.size.title,
|
|
111
|
+
description: e.size.description
|
|
112
|
+
}), l = T({
|
|
113
|
+
title: e.position.title,
|
|
114
|
+
description: e.position.description,
|
|
115
|
+
image: e.position.image
|
|
116
|
+
});
|
|
117
|
+
console.log(e);
|
|
118
|
+
const s = e.image ? `<img class="tooltip-image" src="http://localhost:3000${e.image}" alt="" />` : "";
|
|
119
|
+
return o.innerHTML = `
|
|
120
|
+
${l.image === "top" ? `<div class="tooltip-media">
|
|
121
|
+
${s}
|
|
122
|
+
</div>` : ""}
|
|
123
|
+
<div class="tooltip-card">
|
|
124
|
+
${l.image === "left" ? `<div class="tooltip-media">
|
|
125
|
+
${s}
|
|
126
|
+
</div>` : ""}
|
|
127
|
+
|
|
128
|
+
<div class="tooltip-text">
|
|
129
|
+
<div class="tooltip-title" style="font-size: ${i.title}px; text-align: ${l.title}">
|
|
130
|
+
${e.title}
|
|
131
|
+
</div>
|
|
132
|
+
<div class="tooltip-desc" style="font-size: ${i.description}px; text-align: ${l.description}">
|
|
133
|
+
${e.description}
|
|
134
|
+
</div>
|
|
135
|
+
</div>
|
|
136
|
+
|
|
137
|
+
${l.image === "right" ? `<div class="tooltip-media">
|
|
138
|
+
${s}
|
|
139
|
+
</div>` : ""}
|
|
140
|
+
</div>
|
|
141
|
+
`, document.body.appendChild(o), E(), r = o, u = t.rect, o;
|
|
142
|
+
}
|
|
143
|
+
function k(t) {
|
|
144
|
+
const e = window.innerWidth / 2, o = window.innerHeight / 2, i = t.left + t.width / 2, l = t.top + t.height / 2, n = i < e, s = l < o;
|
|
145
|
+
return n && s ? "left-bottom" : !n && s ? "right-bottom" : n && !s ? "left-top" : "right-top";
|
|
146
|
+
}
|
|
147
|
+
export {
|
|
148
|
+
L as initTooltips
|
|
149
|
+
};
|
package/package.json
CHANGED
|
@@ -1,45 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@erain20029/tooltips",
|
|
3
|
-
"
|
|
4
|
-
"version": "2.0.12",
|
|
3
|
+
"version": "2.0.16",
|
|
5
4
|
"description": "Universal tooltip overlay for any HTML project",
|
|
6
|
-
"
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Erik",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
7
9
|
"style": "dist/tooltip.css",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./dist/index.js"
|
|
12
|
+
},
|
|
8
13
|
"files": [
|
|
9
14
|
"dist"
|
|
10
15
|
],
|
|
11
|
-
"keywords": [
|
|
12
|
-
"tooltip",
|
|
13
|
-
"overlay",
|
|
14
|
-
"html",
|
|
15
|
-
"js"
|
|
16
|
-
],
|
|
17
|
-
"author": "Erik",
|
|
18
|
-
"license": "MIT",
|
|
19
|
-
"type": "module",
|
|
20
16
|
"scripts": {
|
|
21
|
-
"
|
|
22
|
-
"build": "vite build && cp src/tooltip/tooltip.css dist/tooltip.css",
|
|
23
|
-
"lint": "eslint .",
|
|
24
|
-
"preview": "vite preview"
|
|
25
|
-
},
|
|
26
|
-
"dependencies": {
|
|
27
|
-
"react": "^19.2.0",
|
|
28
|
-
"react-dom": "^19.2.0"
|
|
17
|
+
"build": "vite build && cp src/tooltip/tooltip.css dist/tooltip.css"
|
|
29
18
|
},
|
|
30
19
|
"devDependencies": {
|
|
31
|
-
"@eslint/js": "^9.39.1",
|
|
32
|
-
"@types/node": "^24.10.1",
|
|
33
|
-
"@types/react": "^19.2.5",
|
|
34
|
-
"@types/react-dom": "^19.2.3",
|
|
35
|
-
"@vitejs/plugin-react": "^5.1.1",
|
|
36
|
-
"eslint": "^9.39.1",
|
|
37
|
-
"eslint-plugin-react-hooks": "^7.0.1",
|
|
38
|
-
"eslint-plugin-react-refresh": "^0.4.24",
|
|
39
|
-
"globals": "^16.5.0",
|
|
40
|
-
"tailwindcss": "^3.4.19",
|
|
41
|
-
"typescript": "~5.9.3",
|
|
42
|
-
"typescript-eslint": "^8.46.4",
|
|
43
20
|
"vite": "^7.2.4"
|
|
44
21
|
}
|
|
45
22
|
}
|