@erain20029/tooltips 2.0.26 → 2.0.27
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/package.json
CHANGED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
const x = ".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}", s = {
|
|
2
|
-
tooltips: [],
|
|
3
|
-
ready: !1
|
|
4
|
-
}, m = /* @__PURE__ */ new Set();
|
|
5
|
-
let r = null, f = null, h = !1;
|
|
6
|
-
function y(t) {
|
|
7
|
-
return m.has(t) ? Promise.resolve() : new Promise((e, n) => {
|
|
8
|
-
const o = document.createElement("script");
|
|
9
|
-
o.src = t, o.async = !0, o.onload = () => {
|
|
10
|
-
m.add(t), e();
|
|
11
|
-
}, o.onerror = () => n(new Error(`Failed to load script: ${t}`)), document.head.appendChild(o);
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
async function v() {
|
|
15
|
-
if (s.ready) return;
|
|
16
|
-
const t = localStorage.getItem("product");
|
|
17
|
-
if (!t) return;
|
|
18
|
-
const e = JSON.parse(t).id;
|
|
19
|
-
if (await y(
|
|
20
|
-
`http://localhost:3000/documentation/${e}/tooltip.js`
|
|
21
|
-
), typeof window.tooltipGetter != "function") {
|
|
22
|
-
console.warn("tooltipGetter not ready");
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
s.tooltips = await window.tooltipGetter(), s.ready = !0;
|
|
26
|
-
}
|
|
27
|
-
document.addEventListener(
|
|
28
|
-
"mouseenter",
|
|
29
|
-
async (t) => {
|
|
30
|
-
if (t.target.closest(".tooltip-overlay") || (await v(), !s.ready)) return;
|
|
31
|
-
const e = t.target;
|
|
32
|
-
if (!(e instanceof Element)) return;
|
|
33
|
-
const n = s.tooltips.find(
|
|
34
|
-
(d) => e.closest(d.selector)
|
|
35
|
-
);
|
|
36
|
-
if (!n) return;
|
|
37
|
-
const o = e.closest(n.selector), i = o.getBoundingClientRect(), a = T(i), { x: l, y: u } = b(
|
|
38
|
-
a,
|
|
39
|
-
i
|
|
40
|
-
);
|
|
41
|
-
S({
|
|
42
|
-
tooltip: n,
|
|
43
|
-
x: l,
|
|
44
|
-
y: u,
|
|
45
|
-
target: o
|
|
46
|
-
});
|
|
47
|
-
},
|
|
48
|
-
!0
|
|
49
|
-
);
|
|
50
|
-
document.addEventListener(
|
|
51
|
-
"mouseleave",
|
|
52
|
-
(t) => {
|
|
53
|
-
if (!r || !f) return;
|
|
54
|
-
const e = t.relatedTarget;
|
|
55
|
-
e && !r.contains(e) && !f.contains(e) && g();
|
|
56
|
-
},
|
|
57
|
-
!0
|
|
58
|
-
);
|
|
59
|
-
const c = 500, p = 200;
|
|
60
|
-
function w() {
|
|
61
|
-
if (h) return;
|
|
62
|
-
const t = document.createElement("style");
|
|
63
|
-
t.textContent = x, document.head.appendChild(t), h = !0;
|
|
64
|
-
}
|
|
65
|
-
function g() {
|
|
66
|
-
r && (r.remove(), r = null, f = null);
|
|
67
|
-
}
|
|
68
|
-
function b(t, e) {
|
|
69
|
-
let n = 0, o = 0;
|
|
70
|
-
const i = 16;
|
|
71
|
-
switch (t) {
|
|
72
|
-
case "left-bottom":
|
|
73
|
-
n = e.left, o = e.bottom + i;
|
|
74
|
-
break;
|
|
75
|
-
case "right-bottom":
|
|
76
|
-
n = e.right - c, o = e.bottom + i;
|
|
77
|
-
break;
|
|
78
|
-
case "left-top":
|
|
79
|
-
n = e.left, o = e.top - p - i;
|
|
80
|
-
break;
|
|
81
|
-
case "right-top":
|
|
82
|
-
n = e.right - c, o = e.top - p - i;
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
return n = Math.max(8, Math.min(n, window.innerWidth - c - 8)), o = Math.max(8, Math.min(o, window.innerHeight - p - 8)), { x: n, y: o };
|
|
86
|
-
}
|
|
87
|
-
function T(t) {
|
|
88
|
-
const e = t.left + t.width / 2, n = t.top + t.height / 2, o = e < window.innerWidth / 2, i = n < window.innerHeight / 2;
|
|
89
|
-
return o && i ? "left-bottom" : !o && i ? "right-bottom" : o && !i ? "left-top" : "right-top";
|
|
90
|
-
}
|
|
91
|
-
function $({ title: t, description: e }) {
|
|
92
|
-
return {
|
|
93
|
-
title: t === "large" ? 20 : t === "small" ? 14 : 16,
|
|
94
|
-
description: e === "large" ? 16 : e === "small" ? 12 : 14
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
function E({ title: t, description: e, image: n }) {
|
|
98
|
-
return {
|
|
99
|
-
title: t || "left",
|
|
100
|
-
description: e || "left",
|
|
101
|
-
image: n || "left"
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
function S({ tooltip: t, x: e, y: n, target: o }) {
|
|
105
|
-
g(), w();
|
|
106
|
-
const i = document.createElement("div");
|
|
107
|
-
i.className = "tooltip-overlay", i.style.position = "fixed", i.style.width = `${c}px`, i.style.height = `${p}px`, i.style.left = `${e}px`, i.style.top = `${n}px`, i.style.zIndex = "999999";
|
|
108
|
-
const a = $(t.size || {}), l = E(t.position || {}), d = t.image ? `<img class="tooltip-image" src="http://localhost:3000${t.image}" />` : "";
|
|
109
|
-
i.innerHTML = `
|
|
110
|
-
<div class="tooltip-card">
|
|
111
|
-
${l.image === "left" ? `<div>${d}</div>` : ""}
|
|
112
|
-
<div class="tooltip-text">
|
|
113
|
-
<div class="tooltip-title" style="font-size:${a.title}px;text-align:${l.title}">
|
|
114
|
-
${t.title}
|
|
115
|
-
</div>
|
|
116
|
-
<div class="tooltip-desc" style="font-size:${a.description}px;text-align:${l.description}">
|
|
117
|
-
${t.description}
|
|
118
|
-
</div>
|
|
119
|
-
</div>
|
|
120
|
-
${l.image === "right" ? `<div>${d}</div>` : ""}
|
|
121
|
-
</div>
|
|
122
|
-
`, document.body.appendChild(i), r = i, f = o;
|
|
123
|
-
}
|
|
File without changes
|