zero-tooltip 1.0.6 → 1.0.8
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 +2 -2
- package/dist/zero-tooltip.js +87 -90
- package/dist/zero-tooltip.umd.cjs +1 -1
- package/package.json +1 -1
- package/src/tooltip.ts +35 -34
package/README.md
CHANGED
|
@@ -87,7 +87,7 @@ Tooltip can be customizable also for each usage (locally) using same config as f
|
|
|
87
87
|
<script setup lang="ts">
|
|
88
88
|
import ZeroTooltipLocalConfig from 'zero-tooltip'
|
|
89
89
|
|
|
90
|
-
const tooltipConfig: ZeroTooltipLocalConfig = {
|
|
90
|
+
const tooltipConfig: ZeroTooltipLocalConfig = reactive({
|
|
91
91
|
content: 'This is tooltip'
|
|
92
92
|
defaultPosition: ... ,
|
|
93
93
|
positions: ... ,
|
|
@@ -103,7 +103,7 @@ const tooltipConfig: ZeroTooltipLocalConfig = {
|
|
|
103
103
|
arrowMinOffsetFromTooltipCorner: ... ,
|
|
104
104
|
zIndex: ... ,
|
|
105
105
|
show: ...
|
|
106
|
-
}
|
|
106
|
+
})
|
|
107
107
|
</script>
|
|
108
108
|
```
|
|
109
109
|
|
package/dist/zero-tooltip.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isReactive as et, watch as rt } from "vue";
|
|
2
2
|
let M;
|
|
3
|
-
const
|
|
4
|
-
function
|
|
3
|
+
const st = new Uint8Array(16);
|
|
4
|
+
function dt() {
|
|
5
5
|
if (!M && (M = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !M))
|
|
6
6
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
7
|
-
return M(
|
|
7
|
+
return M(st);
|
|
8
8
|
}
|
|
9
|
-
const
|
|
9
|
+
const w = [];
|
|
10
10
|
for (let e = 0; e < 256; ++e)
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
return
|
|
11
|
+
w.push((e + 256).toString(16).slice(1));
|
|
12
|
+
function it(e, t = 0) {
|
|
13
|
+
return w[e[t + 0]] + w[e[t + 1]] + w[e[t + 2]] + w[e[t + 3]] + "-" + w[e[t + 4]] + w[e[t + 5]] + "-" + w[e[t + 6]] + w[e[t + 7]] + "-" + w[e[t + 8]] + w[e[t + 9]] + "-" + w[e[t + 10]] + w[e[t + 11]] + w[e[t + 12]] + w[e[t + 13]] + w[e[t + 14]] + w[e[t + 15]];
|
|
14
14
|
}
|
|
15
|
-
const
|
|
16
|
-
randomUUID:
|
|
15
|
+
const ot = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), q = {
|
|
16
|
+
randomUUID: ot
|
|
17
17
|
};
|
|
18
|
-
function
|
|
19
|
-
if (
|
|
20
|
-
return
|
|
18
|
+
function pt(e, t, r) {
|
|
19
|
+
if (q.randomUUID && !t && !e)
|
|
20
|
+
return q.randomUUID();
|
|
21
21
|
e = e || {};
|
|
22
|
-
const s = e.random || (e.rng ||
|
|
22
|
+
const s = e.random || (e.rng || dt)();
|
|
23
23
|
if (s[6] = s[6] & 15 | 64, s[8] = s[8] & 63 | 128, t) {
|
|
24
24
|
r = r || 0;
|
|
25
25
|
for (let d = 0; d < 16; ++d)
|
|
26
26
|
t[r + d] = s[d];
|
|
27
27
|
return t;
|
|
28
28
|
}
|
|
29
|
-
return
|
|
29
|
+
return it(s);
|
|
30
30
|
}
|
|
31
|
-
function
|
|
31
|
+
function ht() {
|
|
32
32
|
let e = [];
|
|
33
33
|
const t = (d, i) => {
|
|
34
34
|
if (r(d), e.length > 0)
|
|
@@ -56,7 +56,7 @@ function pt() {
|
|
|
56
56
|
};
|
|
57
57
|
return { handleHideOnScroll: t };
|
|
58
58
|
}
|
|
59
|
-
function
|
|
59
|
+
function wt() {
|
|
60
60
|
let e = null, t = null;
|
|
61
61
|
return { handleHideOnResize: (d, i) => {
|
|
62
62
|
e = new ResizeObserver((o) => {
|
|
@@ -64,66 +64,64 @@ function ut() {
|
|
|
64
64
|
if (t === null)
|
|
65
65
|
t = d.getBoundingClientRect();
|
|
66
66
|
else {
|
|
67
|
-
const
|
|
68
|
-
(
|
|
67
|
+
const h = p.getBoundingClientRect();
|
|
68
|
+
(h.left !== t.left || h.top !== t.top || h.width !== t.width || h.height !== t.height) && i();
|
|
69
69
|
}
|
|
70
70
|
}), e.observe(d);
|
|
71
71
|
}, resetResizeReferences: () => {
|
|
72
72
|
e !== null && e.disconnect(), e = null, t = null;
|
|
73
73
|
} };
|
|
74
74
|
}
|
|
75
|
-
const { handleHideOnScroll:
|
|
75
|
+
const { handleHideOnScroll: ut } = ht(), { handleHideOnResize: mt, resetResizeReferences: nt } = wt(), y = "zero-tooltip__container", j = "zero-tooltip__text", tt = "zero-tooltip__arrow", c = {
|
|
76
76
|
left: ["left", "right", "top", "bottom"],
|
|
77
77
|
top: ["top", "bottom", "right", "left"],
|
|
78
78
|
right: ["right", "left", "top", "bottom"],
|
|
79
79
|
bottom: ["bottom", "top", "right", "left"]
|
|
80
|
-
},
|
|
80
|
+
}, R = "top", N = 10, Z = 20, G = 100, J = 250, K = 0, Q = "zt-fixed zt-opacity-0 zt-inline-block zt-w-fit zt-py-1.5 zt-px-2.5 zt-rounded-md zt-bg-[#495057] zt-shadow-[0_2px_12px_0_rgba(0,0,0,0.1)] zt-box-border", X = "zt-text-sm zt-text-white zt-whitespace-pre-wrap zt-break-words", Y = 5, ct = "zt-absolute zt-border-solid zt-border-[#495057]", E = 6, l = 1, b = !0, n = {}, Lt = (e) => ({
|
|
81
81
|
created: (t, r, s) => {
|
|
82
|
-
const d =
|
|
83
|
-
s.el.$_tooltip = { uuid: d }, V(r.value, e, r.arg, t, d), typeof r.value != "string" && et(r.value, (i) => {
|
|
84
|
-
|
|
82
|
+
const d = pt();
|
|
83
|
+
s.el.$_tooltip = { uuid: d }, V(r.value, e, r.arg, t, d), typeof r.value != "string" && et(r.value) && rt(r.value, (i) => {
|
|
84
|
+
n[d] && B(n[d]), V(i, e, r.arg, t, d);
|
|
85
85
|
});
|
|
86
86
|
},
|
|
87
87
|
updated: (t, r, s) => {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
O[d] && B(O[d]), V(r.value, e, r.arg, t, d);
|
|
91
|
-
}
|
|
88
|
+
const d = s.el.$_tooltip.uuid;
|
|
89
|
+
n[d] && B(n[d]), V(r.value, e, r.arg, t, d);
|
|
92
90
|
},
|
|
93
|
-
beforeUnmount: () => {
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
beforeUnmount: (t, r, s) => {
|
|
92
|
+
const d = s.el.$_tooltip.uuid;
|
|
93
|
+
n[d] && B(n[d]);
|
|
96
94
|
}
|
|
97
95
|
});
|
|
98
96
|
function V(e, t, r, s, d) {
|
|
99
|
-
let i =
|
|
100
|
-
const o =
|
|
101
|
-
s.matches(":hover") && s.dispatchEvent(new Event("mouseenter"))
|
|
97
|
+
let i = Ot(e, t, r);
|
|
98
|
+
const o = Ft(s, i, d);
|
|
99
|
+
n[d] = o, s.matches(":hover") && s.dispatchEvent(new Event("mouseenter"));
|
|
102
100
|
}
|
|
103
|
-
function
|
|
104
|
-
var a, L, H, $, A,
|
|
105
|
-
let s, d, i, o, p,
|
|
106
|
-
return s =
|
|
107
|
-
left: ((a = e.positions) == null ? void 0 : a.left) ?? ((L = t == null ? void 0 : t.positions) == null ? void 0 : L.left) ??
|
|
108
|
-
top: ((H = e.positions) == null ? void 0 : H.top) ?? (($ = t == null ? void 0 : t.positions) == null ? void 0 : $.top) ??
|
|
109
|
-
right: ((A = e.positions) == null ? void 0 : A.right) ?? ((
|
|
110
|
-
bottom: ((I = e.positions) == null ? void 0 : I.bottom) ?? ((U = t == null ? void 0 : t.positions) == null ? void 0 : U.bottom) ??
|
|
111
|
-
}, o = e.offsetFromSource ?? (t == null ? void 0 : t.offsetFromSource) ??
|
|
112
|
-
left: ((
|
|
113
|
-
top: ((k = t == null ? void 0 : t.positions) == null ? void 0 : k.top) ??
|
|
114
|
-
right: ((D = t == null ? void 0 : t.positions) == null ? void 0 : D.right) ??
|
|
115
|
-
bottom: ((P = t == null ? void 0 : t.positions) == null ? void 0 : P.bottom) ??
|
|
116
|
-
}), o === void 0 && (o = (t == null ? void 0 : t.offsetFromSource) ??
|
|
101
|
+
function Ot(e, t, r) {
|
|
102
|
+
var a, L, H, $, A, _, I, U, f, k, D, P;
|
|
103
|
+
let s, d, i, o, p, h, u, m, x, O, F, T, W, z, v;
|
|
104
|
+
return s = xt(e), typeof e != "string" && (d = r ?? e.defaultPosition ?? (t == null ? void 0 : t.defaultPosition) ?? R, i = {
|
|
105
|
+
left: ((a = e.positions) == null ? void 0 : a.left) ?? ((L = t == null ? void 0 : t.positions) == null ? void 0 : L.left) ?? c.left,
|
|
106
|
+
top: ((H = e.positions) == null ? void 0 : H.top) ?? (($ = t == null ? void 0 : t.positions) == null ? void 0 : $.top) ?? c.top,
|
|
107
|
+
right: ((A = e.positions) == null ? void 0 : A.right) ?? ((_ = t == null ? void 0 : t.positions) == null ? void 0 : _.right) ?? c.right,
|
|
108
|
+
bottom: ((I = e.positions) == null ? void 0 : I.bottom) ?? ((U = t == null ? void 0 : t.positions) == null ? void 0 : U.bottom) ?? c.bottom
|
|
109
|
+
}, o = e.offsetFromSource ?? (t == null ? void 0 : t.offsetFromSource) ?? N, p = e.offsetFromViewport ?? (t == null ? void 0 : t.offsetFromViewport) ?? Z, h = e.minWidth ?? (t == null ? void 0 : t.minWidth) ?? G, u = e.maxWidth ?? (t == null ? void 0 : t.maxWidth) ?? J, m = e.tooltipBorderWidth ?? (t == null ? void 0 : t.tooltipBorderWidth) ?? K, x = y + " " + Q + " " + (e.tooltipClasses ?? (t == null ? void 0 : t.tooltipClasses) ?? ""), O = j + " " + X + " " + (e.textClasses ?? (t == null ? void 0 : t.textClasses) ?? ""), F = e.arrowSize ?? (t == null ? void 0 : t.arrowSize) ?? Y, T = e.arrowClasses ?? (t == null ? void 0 : t.arrowClasses) ?? "", W = e.arrowMinOffsetFromTooltipCorner ?? (t == null ? void 0 : t.arrowMinOffsetFromTooltipCorner) ?? E, z = e.zIndex ?? (t == null ? void 0 : t.zIndex) ?? l, v = e.show ?? b), d === void 0 && (d = r ?? (t == null ? void 0 : t.defaultPosition) ?? R), i === void 0 && (i = {
|
|
110
|
+
left: ((f = t == null ? void 0 : t.positions) == null ? void 0 : f.left) ?? c.left,
|
|
111
|
+
top: ((k = t == null ? void 0 : t.positions) == null ? void 0 : k.top) ?? c.top,
|
|
112
|
+
right: ((D = t == null ? void 0 : t.positions) == null ? void 0 : D.right) ?? c.right,
|
|
113
|
+
bottom: ((P = t == null ? void 0 : t.positions) == null ? void 0 : P.bottom) ?? c.bottom
|
|
114
|
+
}), o === void 0 && (o = (t == null ? void 0 : t.offsetFromSource) ?? N), p === void 0 && (p = (t == null ? void 0 : t.offsetFromViewport) ?? Z), h === void 0 && (h = (t == null ? void 0 : t.minWidth) ?? G), u === void 0 && (u = (t == null ? void 0 : t.maxWidth) ?? J), m === void 0 && (m = (t == null ? void 0 : t.tooltipBorderWidth) ?? K), x === void 0 && (x = y + " " + Q + " " + ((t == null ? void 0 : t.tooltipClasses) ?? "")), O === void 0 && (O = j + " " + X + " " + ((t == null ? void 0 : t.textClasses) ?? "")), F === void 0 && (F = (t == null ? void 0 : t.arrowSize) ?? Y), T === void 0 && (T = (t == null ? void 0 : t.arrowClasses) ?? ""), W === void 0 && (W = (t == null ? void 0 : t.arrowMinOffsetFromTooltipCorner) ?? E), z === void 0 && (z = (t == null ? void 0 : t.zIndex) ?? l), v === void 0 && (v = b), {
|
|
117
115
|
tooltipText: s,
|
|
118
116
|
tooltipPosition: d,
|
|
119
117
|
tooltipPositions: i,
|
|
120
118
|
tooltipOffsetFromSource: o,
|
|
121
119
|
tooltipOffsetFromViewport: p,
|
|
122
|
-
tooltipMinWidth:
|
|
123
|
-
tooltipMaxWidth:
|
|
120
|
+
tooltipMinWidth: h,
|
|
121
|
+
tooltipMaxWidth: u,
|
|
124
122
|
tooltipBorderWidth: m,
|
|
125
123
|
tooltipClasses: x,
|
|
126
|
-
textClasses:
|
|
124
|
+
textClasses: O,
|
|
127
125
|
arrowSize: F,
|
|
128
126
|
arrowClasses: T,
|
|
129
127
|
arrowMinOffsetFromTooltipCorner: W,
|
|
@@ -131,17 +129,17 @@ function ct(e, t, r) {
|
|
|
131
129
|
shouldShow: v
|
|
132
130
|
};
|
|
133
131
|
}
|
|
134
|
-
function
|
|
132
|
+
function xt(e) {
|
|
135
133
|
const t = typeof e == "string" ? e : e.content;
|
|
136
134
|
if (!t)
|
|
137
135
|
throw new Error("Please enter valid tooltip value");
|
|
138
136
|
return t;
|
|
139
137
|
}
|
|
140
|
-
function
|
|
141
|
-
let s = e, d =
|
|
138
|
+
function Ft(e, t, r) {
|
|
139
|
+
let s = e, d = Tt(t.textClasses, t.tooltipText), i = Wt(t.tooltipClasses, t.tooltipBorderWidth);
|
|
142
140
|
i.append(d), i.dataset.uuid = r;
|
|
143
141
|
const o = new AbortController(), p = new AbortController();
|
|
144
|
-
return s.addEventListener("mouseenter", () =>
|
|
142
|
+
return s.addEventListener("mouseenter", () => zt(s, t, i, r), { signal: o.signal }), s.addEventListener("mouseleave", () => vt(r), { signal: p.signal }), {
|
|
145
143
|
anchorElement: s,
|
|
146
144
|
tooltipConfig: t,
|
|
147
145
|
tooltipElement: i,
|
|
@@ -149,28 +147,28 @@ function xt(e, t, r) {
|
|
|
149
147
|
mouseLeaveEventController: p
|
|
150
148
|
};
|
|
151
149
|
}
|
|
152
|
-
function
|
|
150
|
+
function Tt(e, t) {
|
|
153
151
|
let r = document.createElement("p");
|
|
154
152
|
return r.classList.add(...e.trim().split(" ")), r.innerHTML = t, r;
|
|
155
153
|
}
|
|
156
|
-
function
|
|
154
|
+
function Wt(e, t) {
|
|
157
155
|
let r = document.createElement("div");
|
|
158
156
|
return r.classList.add(...e.trim().split(" ")), r.style.borderWidth = `${t}px`, r;
|
|
159
157
|
}
|
|
160
|
-
function
|
|
158
|
+
function zt(e, t, r, s) {
|
|
161
159
|
if (!t.shouldShow)
|
|
162
160
|
return;
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
let
|
|
166
|
-
for (let
|
|
161
|
+
const d = e.getBoundingClientRect(), i = document.querySelector("body");
|
|
162
|
+
i == null || i.appendChild(r);
|
|
163
|
+
let o = !1, p = t.tooltipPosition;
|
|
164
|
+
for (let h = 0; h < 4 && (p = t.tooltipPositions[t.tooltipPosition][h], p === "left" ? o = Mt(d, t, r) : p === "top" ? o = St(d, t, r) : p === "right" ? o = yt(d, t, r) : p === "bottom" && (o = Vt(d, t, r)), !o); h++)
|
|
167
165
|
;
|
|
168
|
-
|
|
166
|
+
o && (Bt(d, p, t, r), r.style.opacity = "1", r.style.zIndex = t.zIndex.toString(), ut(e, () => S(s)), mt(e, () => S(s)));
|
|
169
167
|
}
|
|
170
|
-
function
|
|
171
|
-
S();
|
|
168
|
+
function vt(e) {
|
|
169
|
+
S(e);
|
|
172
170
|
}
|
|
173
|
-
function
|
|
171
|
+
function Mt(e, t, r) {
|
|
174
172
|
const s = Math.min(e.left - t.tooltipOffsetFromSource - t.tooltipOffsetFromViewport, t.tooltipMaxWidth), d = e.top >= t.tooltipOffsetFromViewport, i = window.innerHeight - e.bottom >= t.tooltipOffsetFromViewport;
|
|
175
173
|
if (s < t.tooltipMinWidth || !d || !i)
|
|
176
174
|
return !1;
|
|
@@ -178,10 +176,10 @@ function vt(e, t, r) {
|
|
|
178
176
|
const o = r.getBoundingClientRect();
|
|
179
177
|
let p = e.top + e.height / 2 - o.height / 2;
|
|
180
178
|
p < t.tooltipOffsetFromViewport ? p = t.tooltipOffsetFromViewport : p + o.height > window.innerHeight - t.tooltipOffsetFromViewport && (p = window.innerHeight - t.tooltipOffsetFromViewport - o.height);
|
|
181
|
-
const
|
|
182
|
-
return e.bottom < p + t.arrowMinOffsetFromTooltipCorner * 2 || e.top > p + o.height - t.arrowMinOffsetFromTooltipCorner * 2 ? !1 : (r.style.top = `${p}px`, r.style.left = `${
|
|
179
|
+
const h = e.left - t.tooltipOffsetFromSource - o.width;
|
|
180
|
+
return e.bottom < p + t.arrowMinOffsetFromTooltipCorner * 2 || e.top > p + o.height - t.arrowMinOffsetFromTooltipCorner * 2 ? !1 : (r.style.top = `${p}px`, r.style.left = `${h}px`, !0);
|
|
183
181
|
}
|
|
184
|
-
function
|
|
182
|
+
function yt(e, t, r) {
|
|
185
183
|
const s = Math.min(window.innerWidth - (e.right + t.tooltipOffsetFromSource) - t.tooltipOffsetFromViewport, t.tooltipMaxWidth), d = e.top >= t.tooltipOffsetFromViewport, i = window.innerHeight - e.bottom >= t.tooltipOffsetFromViewport;
|
|
186
184
|
if (s < t.tooltipMinWidth || !d || !i)
|
|
187
185
|
return !1;
|
|
@@ -189,10 +187,10 @@ function Mt(e, t, r) {
|
|
|
189
187
|
const o = r.getBoundingClientRect();
|
|
190
188
|
let p = e.top + e.height / 2 - o.height / 2;
|
|
191
189
|
p < t.tooltipOffsetFromViewport ? p = t.tooltipOffsetFromViewport : p + o.height > window.innerHeight - t.tooltipOffsetFromViewport && (p = window.innerHeight - t.tooltipOffsetFromViewport - o.height);
|
|
192
|
-
const
|
|
193
|
-
return e.bottom < p + t.arrowMinOffsetFromTooltipCorner * 2 || e.top > p + o.height - t.arrowMinOffsetFromTooltipCorner * 2 ? !1 : (r.style.top = `${p}px`, r.style.left = `${
|
|
190
|
+
const h = e.right + t.tooltipOffsetFromSource;
|
|
191
|
+
return e.bottom < p + t.arrowMinOffsetFromTooltipCorner * 2 || e.top > p + o.height - t.arrowMinOffsetFromTooltipCorner * 2 ? !1 : (r.style.top = `${p}px`, r.style.left = `${h}px`, !0);
|
|
194
192
|
}
|
|
195
|
-
function
|
|
193
|
+
function St(e, t, r) {
|
|
196
194
|
const s = Math.min(window.innerWidth - t.tooltipOffsetFromViewport * 2, t.tooltipMaxWidth);
|
|
197
195
|
r.style.maxWidth = `${s}px`;
|
|
198
196
|
const d = r.getBoundingClientRect();
|
|
@@ -202,7 +200,7 @@ function yt(e, t, r) {
|
|
|
202
200
|
let o = e.left + e.width / 2 - d.width / 2;
|
|
203
201
|
return o < t.tooltipOffsetFromViewport ? o = t.tooltipOffsetFromViewport : o + d.width > window.innerWidth - t.tooltipOffsetFromViewport && (o = window.innerWidth - t.tooltipOffsetFromViewport - d.width), e.left > o + d.width - t.arrowMinOffsetFromTooltipCorner * 2 || e.right < o + t.arrowMinOffsetFromTooltipCorner * 2 ? !1 : (r.style.top = `${i}px`, r.style.left = `${o}px`, !0);
|
|
204
202
|
}
|
|
205
|
-
function
|
|
203
|
+
function Vt(e, t, r) {
|
|
206
204
|
const s = Math.min(window.innerWidth - t.tooltipOffsetFromViewport * 2, t.tooltipMaxWidth);
|
|
207
205
|
r.style.maxWidth = `${s}px`;
|
|
208
206
|
const d = r.getBoundingClientRect();
|
|
@@ -212,27 +210,27 @@ function St(e, t, r) {
|
|
|
212
210
|
let o = e.left + e.width / 2 - d.width / 2;
|
|
213
211
|
return o < t.tooltipOffsetFromViewport ? o = t.tooltipOffsetFromViewport : o + d.width > window.innerWidth - t.tooltipOffsetFromViewport && (o = window.innerWidth - t.tooltipOffsetFromViewport - d.width), e.left > o + d.width - t.arrowMinOffsetFromTooltipCorner * 2 || e.right < o + t.arrowMinOffsetFromTooltipCorner * 2 ? !1 : (r.style.top = `${i}px`, r.style.left = `${o}px`, !0);
|
|
214
212
|
}
|
|
215
|
-
function
|
|
216
|
-
var
|
|
213
|
+
function Bt(e, t, r, s) {
|
|
214
|
+
var O;
|
|
217
215
|
const d = document.createElement("div"), i = s.getBoundingClientRect(), o = Math.sin(45 * (180 / Math.PI)) * r.arrowSize, p = 1;
|
|
218
|
-
let
|
|
216
|
+
let h = 0, u = 0, m = "";
|
|
219
217
|
switch (t) {
|
|
220
218
|
case "left":
|
|
221
|
-
m = "!zt-border-y-transparent !zt-border-r-transparent",
|
|
219
|
+
m = "!zt-border-y-transparent !zt-border-r-transparent", h = e.top - i.top + e.height / 2 - o - r.tooltipBorderWidth, u = i.width - r.tooltipBorderWidth - p;
|
|
222
220
|
break;
|
|
223
221
|
case "top":
|
|
224
|
-
m = "!zt-border-x-transparent !zt-border-b-transparent",
|
|
222
|
+
m = "!zt-border-x-transparent !zt-border-b-transparent", h = i.height - r.tooltipBorderWidth - p, u = e.left - i.left + e.width / 2 - o - r.tooltipBorderWidth;
|
|
225
223
|
break;
|
|
226
224
|
case "right":
|
|
227
|
-
m = "!zt-border-y-transparent !zt-border-l-transparent",
|
|
225
|
+
m = "!zt-border-y-transparent !zt-border-l-transparent", h = e.top - i.top + e.height / 2 - o - r.tooltipBorderWidth, u = -r.arrowSize * 2 - r.tooltipBorderWidth + p;
|
|
228
226
|
break;
|
|
229
227
|
case "bottom":
|
|
230
|
-
m = "!zt-border-x-transparent !zt-border-t-transparent",
|
|
228
|
+
m = "!zt-border-x-transparent !zt-border-t-transparent", h = -r.arrowSize * 2 - r.tooltipBorderWidth + p, u = e.left - i.left + e.width / 2 - o - r.tooltipBorderWidth;
|
|
231
229
|
break;
|
|
232
230
|
}
|
|
233
|
-
t === "left" || t === "right" ? C(t, i,
|
|
234
|
-
const x = tt + " " +
|
|
235
|
-
d.classList.add(...x.trim().split(" ")), d.style.top = `${
|
|
231
|
+
t === "left" || t === "right" ? C(t, i, h, r) || (h = g(t, i, h, r)) : C(t, i, u, r) || (u = g(t, i, u, r));
|
|
232
|
+
const x = tt + " " + ct + " " + m + " " + r.arrowClasses;
|
|
233
|
+
d.classList.add(...x.trim().split(" ")), d.style.top = `${h}px`, d.style.left = `${u}px`, d.style.borderWidth = `${r.arrowSize}px`, (O = document.querySelector(`.${y}`)) == null || O.appendChild(d);
|
|
236
234
|
}
|
|
237
235
|
function C(e, t, r, s) {
|
|
238
236
|
switch (e) {
|
|
@@ -254,16 +252,15 @@ function g(e, t, r, s) {
|
|
|
254
252
|
return r < s.arrowMinOffsetFromTooltipCorner - s.tooltipBorderWidth ? s.arrowMinOffsetFromTooltipCorner - s.tooltipBorderWidth : t.width - s.tooltipBorderWidth - s.arrowMinOffsetFromTooltipCorner - s.arrowSize * 2;
|
|
255
253
|
}
|
|
256
254
|
}
|
|
257
|
-
function S() {
|
|
258
|
-
var
|
|
259
|
-
const
|
|
260
|
-
|
|
255
|
+
function S(e) {
|
|
256
|
+
var s, d;
|
|
257
|
+
const t = document.querySelector(`.${y}`), r = (s = n[e]) == null ? void 0 : s.tooltipElement;
|
|
258
|
+
r && t && t instanceof HTMLElement && t === r && (nt(), (d = t.querySelector(`.${tt}`)) == null || d.remove(), t.style.left = "0", t.style.top = "0", t.remove());
|
|
261
259
|
}
|
|
262
260
|
function B(e) {
|
|
263
|
-
S(), e.mouseEnterEventController.abort(), e.mouseLeaveEventController.abort();
|
|
264
261
|
const t = e.tooltipElement.dataset.uuid;
|
|
265
|
-
t && delete
|
|
262
|
+
t && (S(t), delete n[t]), e.mouseEnterEventController.abort(), e.mouseLeaveEventController.abort();
|
|
266
263
|
}
|
|
267
264
|
export {
|
|
268
|
-
|
|
265
|
+
Lt as default
|
|
269
266
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(F,m){typeof exports=="object"&&typeof module<"u"?module.exports=m(require("vue")):typeof define=="function"&&define.amd?define(["vue"],m):(F=typeof globalThis<"u"?globalThis:F||self,F.ZeroTooltip=m(F.Vue))})(this,function(F){"use strict";let m;const rt=new Uint8Array(16);function st(){if(!m&&(m=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!m))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return m(rt)}const h=[];for(let e=0;e<256;++e)h.push((e+256).toString(16).slice(1));function dt(e,t=0){return h[e[t+0]]+h[e[t+1]]+h[e[t+2]]+h[e[t+3]]+"-"+h[e[t+4]]+h[e[t+5]]+"-"+h[e[t+6]]+h[e[t+7]]+"-"+h[e[t+8]]+h[e[t+9]]+"-"+h[e[t+10]]+h[e[t+11]]+h[e[t+12]]+h[e[t+13]]+h[e[t+14]]+h[e[t+15]]}const L={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function it(e,t,r){if(L.randomUUID&&!t&&!e)return L.randomUUID();e=e||{};const s=e.random||(e.rng||st)();if(s[6]=s[6]&15|64,s[8]=s[8]&63|128,t){r=r||0;for(let d=0;d<16;++d)t[r+d]=s[d];return t}return dt(s)}function ot(){let e=[];const t=(d,i)=>{if(r(d),e.length>0)for(const o of e)o.addEventListener("scroll",i);window.addEventListener("scroll",()=>{i(),s(i)})},r=d=>{let i=d;for(;i!==null&&i.tagName!=="HTML";){if(i.scrollHeight!==i.clientHeight){const o=window.getComputedStyle(i);(o.overflow==="auto"||o.overflow==="scroll")&&e.push(i)}i=i.parentElement}},s=d=>{if(e.length>0){for(const i of e)i.removeEventListener("scroll",d);e=[]}window.removeEventListener("scroll",d)};return{handleHideOnScroll:t}}function pt(){let e=null,t=null;return{handleHideOnResize:(d,i)=>{e=new ResizeObserver(o=>{const p=o[0].target;if(t===null)t=d.getBoundingClientRect();else{const u=p.getBoundingClientRect();(u.left!==t.left||u.top!==t.top||u.width!==t.width||u.height!==t.height)&&i()}}),e.observe(d)},resetResizeReferences:()=>{e!==null&&e.disconnect(),e=null,t=null}}}const{handleHideOnScroll:ut}=ot(),{handleHideOnResize:ht,resetResizeReferences:wt}=pt(),W="zero-tooltip__container",H="zero-tooltip__text",f="zero-tooltip__arrow",c={left:["left","right","top","bottom"],top:["top","bottom","right","left"],right:["right","left","top","bottom"],bottom:["bottom","top","right","left"]},$="top",A=10,I=20,U=100,_=250,k=0,D="zt-fixed zt-opacity-0 zt-inline-block zt-w-fit zt-py-1.5 zt-px-2.5 zt-rounded-md zt-bg-[#495057] zt-shadow-[0_2px_12px_0_rgba(0,0,0,0.1)] zt-box-border",P="zt-text-sm zt-text-white zt-whitespace-pre-wrap zt-break-words",j=5,nt="zt-absolute zt-border-solid zt-border-[#495057]",q=6,Z=1,N=!0,O={},mt=e=>({created:(t,r,s)=>{const d=it();s.el.$_tooltip={uuid:d},B(r.value,e,r.arg,t,d),typeof r.value!="string"&&F.watch(r.value,i=>{O[d]&&a(O[d]),B(i,e,r.arg,t,d)})},updated:(t,r,s)=>{if(typeof r.value=="string"){const d=s.el.$_tooltip.uuid;O[d]&&a(O[d]),B(r.value,e,r.arg,t,d)}},beforeUnmount:()=>{for(let t of Object.values(O))a(t)}});function B(e,t,r,s,d){let i=ct(e,t,r);const o=xt(s,i,d);s.matches(":hover")&&s.dispatchEvent(new Event("mouseenter")),O[d]=o}function ct(e,t,r){var J,K,Q,X,Y,E,l,b,C,g,tt,et;let s,d,i,o,p,u,w,n,T,x,z,y,M,S,V;return s=Ot(e),typeof e!="string"&&(d=r??e.defaultPosition??(t==null?void 0:t.defaultPosition)??$,i={left:((J=e.positions)==null?void 0:J.left)??((K=t==null?void 0:t.positions)==null?void 0:K.left)??c.left,top:((Q=e.positions)==null?void 0:Q.top)??((X=t==null?void 0:t.positions)==null?void 0:X.top)??c.top,right:((Y=e.positions)==null?void 0:Y.right)??((E=t==null?void 0:t.positions)==null?void 0:E.right)??c.right,bottom:((l=e.positions)==null?void 0:l.bottom)??((b=t==null?void 0:t.positions)==null?void 0:b.bottom)??c.bottom},o=e.offsetFromSource??(t==null?void 0:t.offsetFromSource)??A,p=e.offsetFromViewport??(t==null?void 0:t.offsetFromViewport)??I,u=e.minWidth??(t==null?void 0:t.minWidth)??U,w=e.maxWidth??(t==null?void 0:t.maxWidth)??_,n=e.tooltipBorderWidth??(t==null?void 0:t.tooltipBorderWidth)??k,T=W+" "+D+" "+(e.tooltipClasses??(t==null?void 0:t.tooltipClasses)??""),x=H+" "+P+" "+(e.textClasses??(t==null?void 0:t.textClasses)??""),z=e.arrowSize??(t==null?void 0:t.arrowSize)??j,y=e.arrowClasses??(t==null?void 0:t.arrowClasses)??"",M=e.arrowMinOffsetFromTooltipCorner??(t==null?void 0:t.arrowMinOffsetFromTooltipCorner)??q,S=e.zIndex??(t==null?void 0:t.zIndex)??Z,V=e.show??N),d===void 0&&(d=r??(t==null?void 0:t.defaultPosition)??$),i===void 0&&(i={left:((C=t==null?void 0:t.positions)==null?void 0:C.left)??c.left,top:((g=t==null?void 0:t.positions)==null?void 0:g.top)??c.top,right:((tt=t==null?void 0:t.positions)==null?void 0:tt.right)??c.right,bottom:((et=t==null?void 0:t.positions)==null?void 0:et.bottom)??c.bottom}),o===void 0&&(o=(t==null?void 0:t.offsetFromSource)??A),p===void 0&&(p=(t==null?void 0:t.offsetFromViewport)??I),u===void 0&&(u=(t==null?void 0:t.minWidth)??U),w===void 0&&(w=(t==null?void 0:t.maxWidth)??_),n===void 0&&(n=(t==null?void 0:t.tooltipBorderWidth)??k),T===void 0&&(T=W+" "+D+" "+((t==null?void 0:t.tooltipClasses)??"")),x===void 0&&(x=H+" "+P+" "+((t==null?void 0:t.textClasses)??"")),z===void 0&&(z=(t==null?void 0:t.arrowSize)??j),y===void 0&&(y=(t==null?void 0:t.arrowClasses)??""),M===void 0&&(M=(t==null?void 0:t.arrowMinOffsetFromTooltipCorner)??q),S===void 0&&(S=(t==null?void 0:t.zIndex)??Z),V===void 0&&(V=N),{tooltipText:s,tooltipPosition:d,tooltipPositions:i,tooltipOffsetFromSource:o,tooltipOffsetFromViewport:p,tooltipMinWidth:u,tooltipMaxWidth:w,tooltipBorderWidth:n,tooltipClasses:T,textClasses:x,arrowSize:z,arrowClasses:y,arrowMinOffsetFromTooltipCorner:M,zIndex:S,shouldShow:V}}function Ot(e){const t=typeof e=="string"?e:e.content;if(!t)throw new Error("Please enter valid tooltip value");return t}function xt(e,t,r){let s=e,d=Ft(t.textClasses,t.tooltipText),i=Tt(t.tooltipClasses,t.tooltipBorderWidth);i.append(d),i.dataset.uuid=r;const o=new AbortController,p=new AbortController;return s.addEventListener("mouseenter",()=>Wt(s,t,i),{signal:o.signal}),s.addEventListener("mouseleave",vt,{signal:p.signal}),{anchorElement:s,tooltipConfig:t,tooltipElement:i,mouseEnterEventController:o,mouseLeaveEventController:p}}function Ft(e,t){let r=document.createElement("p");return r.classList.add(...e.trim().split(" ")),r.innerHTML=t,r}function Tt(e,t){let r=document.createElement("div");return r.classList.add(...e.trim().split(" ")),r.style.borderWidth=`${t}px`,r}function Wt(e,t,r){if(!t.shouldShow)return;const s=e.getBoundingClientRect(),d=document.querySelector("body");d==null||d.appendChild(r);let i=!1,o=t.tooltipPosition;for(let p=0;p<4&&(o=t.tooltipPositions[t.tooltipPosition][p],o==="left"?i=zt(s,t,r):o==="top"?i=Mt(s,t,r):o==="right"?i=yt(s,t,r):o==="bottom"&&(i=St(s,t,r)),!i);p++);i&&(Vt(s,o,t,r),r.style.opacity="1",r.style.zIndex=t.zIndex.toString(),ut(e,()=>v()),ht(e,()=>v()))}function vt(){v()}function zt(e,t,r){const s=Math.min(e.left-t.tooltipOffsetFromSource-t.tooltipOffsetFromViewport,t.tooltipMaxWidth),d=e.top>=t.tooltipOffsetFromViewport,i=window.innerHeight-e.bottom>=t.tooltipOffsetFromViewport;if(s<t.tooltipMinWidth||!d||!i)return!1;r.style.maxWidth=`${s}px`;const o=r.getBoundingClientRect();let p=e.top+e.height/2-o.height/2;p<t.tooltipOffsetFromViewport?p=t.tooltipOffsetFromViewport:p+o.height>window.innerHeight-t.tooltipOffsetFromViewport&&(p=window.innerHeight-t.tooltipOffsetFromViewport-o.height);const u=e.left-t.tooltipOffsetFromSource-o.width;return e.bottom<p+t.arrowMinOffsetFromTooltipCorner*2||e.top>p+o.height-t.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${p}px`,r.style.left=`${u}px`,!0)}function yt(e,t,r){const s=Math.min(window.innerWidth-(e.right+t.tooltipOffsetFromSource)-t.tooltipOffsetFromViewport,t.tooltipMaxWidth),d=e.top>=t.tooltipOffsetFromViewport,i=window.innerHeight-e.bottom>=t.tooltipOffsetFromViewport;if(s<t.tooltipMinWidth||!d||!i)return!1;r.style.maxWidth=`${s}px`;const o=r.getBoundingClientRect();let p=e.top+e.height/2-o.height/2;p<t.tooltipOffsetFromViewport?p=t.tooltipOffsetFromViewport:p+o.height>window.innerHeight-t.tooltipOffsetFromViewport&&(p=window.innerHeight-t.tooltipOffsetFromViewport-o.height);const u=e.right+t.tooltipOffsetFromSource;return e.bottom<p+t.arrowMinOffsetFromTooltipCorner*2||e.top>p+o.height-t.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${p}px`,r.style.left=`${u}px`,!0)}function Mt(e,t,r){const s=Math.min(window.innerWidth-t.tooltipOffsetFromViewport*2,t.tooltipMaxWidth);r.style.maxWidth=`${s}px`;const d=r.getBoundingClientRect();let i=e.top-t.tooltipOffsetFromSource-d.height;if(i<t.tooltipOffsetFromViewport)return!1;let o=e.left+e.width/2-d.width/2;return o<t.tooltipOffsetFromViewport?o=t.tooltipOffsetFromViewport:o+d.width>window.innerWidth-t.tooltipOffsetFromViewport&&(o=window.innerWidth-t.tooltipOffsetFromViewport-d.width),e.left>o+d.width-t.arrowMinOffsetFromTooltipCorner*2||e.right<o+t.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${i}px`,r.style.left=`${o}px`,!0)}function St(e,t,r){const s=Math.min(window.innerWidth-t.tooltipOffsetFromViewport*2,t.tooltipMaxWidth);r.style.maxWidth=`${s}px`;const d=r.getBoundingClientRect();let i=e.bottom+t.tooltipOffsetFromSource;if(i+d.height>window.innerHeight-t.tooltipOffsetFromViewport)return!1;let o=e.left+e.width/2-d.width/2;return o<t.tooltipOffsetFromViewport?o=t.tooltipOffsetFromViewport:o+d.width>window.innerWidth-t.tooltipOffsetFromViewport&&(o=window.innerWidth-t.tooltipOffsetFromViewport-d.width),e.left>o+d.width-t.arrowMinOffsetFromTooltipCorner*2||e.right<o+t.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${i}px`,r.style.left=`${o}px`,!0)}function Vt(e,t,r,s){var x;const d=document.createElement("div"),i=s.getBoundingClientRect(),o=Math.sin(45*(180/Math.PI))*r.arrowSize,p=1;let u=0,w=0,n="";switch(t){case"left":n="!zt-border-y-transparent !zt-border-r-transparent",u=e.top-i.top+e.height/2-o-r.tooltipBorderWidth,w=i.width-r.tooltipBorderWidth-p;break;case"top":n="!zt-border-x-transparent !zt-border-b-transparent",u=i.height-r.tooltipBorderWidth-p,w=e.left-i.left+e.width/2-o-r.tooltipBorderWidth;break;case"right":n="!zt-border-y-transparent !zt-border-l-transparent",u=e.top-i.top+e.height/2-o-r.tooltipBorderWidth,w=-r.arrowSize*2-r.tooltipBorderWidth+p;break;case"bottom":n="!zt-border-x-transparent !zt-border-t-transparent",u=-r.arrowSize*2-r.tooltipBorderWidth+p,w=e.left-i.left+e.width/2-o-r.tooltipBorderWidth;break}t==="left"||t==="right"?R(t,i,u,r)||(u=G(t,i,u,r)):R(t,i,w,r)||(w=G(t,i,w,r));const T=f+" "+nt+" "+n+" "+r.arrowClasses;d.classList.add(...T.trim().split(" ")),d.style.top=`${u}px`,d.style.left=`${w}px`,d.style.borderWidth=`${r.arrowSize}px`,(x=document.querySelector(`.${W}`))==null||x.appendChild(d)}function R(e,t,r,s){switch(e){case"left":case"right":return r>s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth&&r<t.height+s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2;case"top":case"bottom":return r>s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth&&r<t.width+s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2}}function G(e,t,r,s){switch(e){case"left":case"right":return r<s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth?s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth:t.height-s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2;case"top":case"bottom":return r<s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth?s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth:t.width-s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2}}function v(){var t;const e=document.querySelector(`.${W}`);e&&e instanceof HTMLElement&&(wt(),(t=e.querySelector(`.${f}`))==null||t.remove(),e.style.left="0",e.style.top="0",e.remove())}function a(e){v(),e.mouseEnterEventController.abort(),e.mouseLeaveEventController.abort();const t=e.tooltipElement.dataset.uuid;t&&delete O[t]}return mt});
|
|
1
|
+
(function(x,c){typeof exports=="object"&&typeof module<"u"?module.exports=c(require("vue")):typeof define=="function"&&define.amd?define(["vue"],c):(x=typeof globalThis<"u"?globalThis:x||self,x.ZeroTooltip=c(x.Vue))})(this,function(x){"use strict";let c;const rt=new Uint8Array(16);function st(){if(!c&&(c=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!c))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return c(rt)}const h=[];for(let e=0;e<256;++e)h.push((e+256).toString(16).slice(1));function dt(e,t=0){return h[e[t+0]]+h[e[t+1]]+h[e[t+2]]+h[e[t+3]]+"-"+h[e[t+4]]+h[e[t+5]]+"-"+h[e[t+6]]+h[e[t+7]]+"-"+h[e[t+8]]+h[e[t+9]]+"-"+h[e[t+10]]+h[e[t+11]]+h[e[t+12]]+h[e[t+13]]+h[e[t+14]]+h[e[t+15]]}const L={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function it(e,t,r){if(L.randomUUID&&!t&&!e)return L.randomUUID();e=e||{};const s=e.random||(e.rng||st)();if(s[6]=s[6]&15|64,s[8]=s[8]&63|128,t){r=r||0;for(let d=0;d<16;++d)t[r+d]=s[d];return t}return dt(s)}function ot(){let e=[];const t=(d,i)=>{if(r(d),e.length>0)for(const o of e)o.addEventListener("scroll",i);window.addEventListener("scroll",()=>{i(),s(i)})},r=d=>{let i=d;for(;i!==null&&i.tagName!=="HTML";){if(i.scrollHeight!==i.clientHeight){const o=window.getComputedStyle(i);(o.overflow==="auto"||o.overflow==="scroll")&&e.push(i)}i=i.parentElement}},s=d=>{if(e.length>0){for(const i of e)i.removeEventListener("scroll",d);e=[]}window.removeEventListener("scroll",d)};return{handleHideOnScroll:t}}function pt(){let e=null,t=null;return{handleHideOnResize:(d,i)=>{e=new ResizeObserver(o=>{const p=o[0].target;if(t===null)t=d.getBoundingClientRect();else{const u=p.getBoundingClientRect();(u.left!==t.left||u.top!==t.top||u.width!==t.width||u.height!==t.height)&&i()}}),e.observe(d)},resetResizeReferences:()=>{e!==null&&e.disconnect(),e=null,t=null}}}const{handleHideOnScroll:ut}=ot(),{handleHideOnResize:ht,resetResizeReferences:wt}=pt(),W="zero-tooltip__container",H="zero-tooltip__text",$="zero-tooltip__arrow",O={left:["left","right","top","bottom"],top:["top","bottom","right","left"],right:["right","left","top","bottom"],bottom:["bottom","top","right","left"]},A="top",f=10,_=20,I=100,U=250,k=0,D="zt-fixed zt-opacity-0 zt-inline-block zt-w-fit zt-py-1.5 zt-px-2.5 zt-rounded-md zt-bg-[#495057] zt-shadow-[0_2px_12px_0_rgba(0,0,0,0.1)] zt-box-border",P="zt-text-sm zt-text-white zt-whitespace-pre-wrap zt-break-words",q=5,nt="zt-absolute zt-border-solid zt-border-[#495057]",j=6,R=1,Z=!0,m={},mt=e=>({created:(t,r,s)=>{const d=it();s.el.$_tooltip={uuid:d},B(r.value,e,r.arg,t,d),typeof r.value!="string"&&x.isReactive(r.value)&&x.watch(r.value,i=>{m[d]&&a(m[d]),B(i,e,r.arg,t,d)})},updated:(t,r,s)=>{const d=s.el.$_tooltip.uuid;m[d]&&a(m[d]),B(r.value,e,r.arg,t,d)},beforeUnmount:(t,r,s)=>{const d=s.el.$_tooltip.uuid;m[d]&&a(m[d])}});function B(e,t,r,s,d){let i=ct(e,t,r);const o=xt(s,i,d);m[d]=o,s.matches(":hover")&&s.dispatchEvent(new Event("mouseenter"))}function ct(e,t,r){var J,K,Q,X,Y,E,l,b,C,g,tt,et;let s,d,i,o,p,u,w,n,T,F,z,y,M,S,V;return s=Ot(e),typeof e!="string"&&(d=r??e.defaultPosition??(t==null?void 0:t.defaultPosition)??A,i={left:((J=e.positions)==null?void 0:J.left)??((K=t==null?void 0:t.positions)==null?void 0:K.left)??O.left,top:((Q=e.positions)==null?void 0:Q.top)??((X=t==null?void 0:t.positions)==null?void 0:X.top)??O.top,right:((Y=e.positions)==null?void 0:Y.right)??((E=t==null?void 0:t.positions)==null?void 0:E.right)??O.right,bottom:((l=e.positions)==null?void 0:l.bottom)??((b=t==null?void 0:t.positions)==null?void 0:b.bottom)??O.bottom},o=e.offsetFromSource??(t==null?void 0:t.offsetFromSource)??f,p=e.offsetFromViewport??(t==null?void 0:t.offsetFromViewport)??_,u=e.minWidth??(t==null?void 0:t.minWidth)??I,w=e.maxWidth??(t==null?void 0:t.maxWidth)??U,n=e.tooltipBorderWidth??(t==null?void 0:t.tooltipBorderWidth)??k,T=W+" "+D+" "+(e.tooltipClasses??(t==null?void 0:t.tooltipClasses)??""),F=H+" "+P+" "+(e.textClasses??(t==null?void 0:t.textClasses)??""),z=e.arrowSize??(t==null?void 0:t.arrowSize)??q,y=e.arrowClasses??(t==null?void 0:t.arrowClasses)??"",M=e.arrowMinOffsetFromTooltipCorner??(t==null?void 0:t.arrowMinOffsetFromTooltipCorner)??j,S=e.zIndex??(t==null?void 0:t.zIndex)??R,V=e.show??Z),d===void 0&&(d=r??(t==null?void 0:t.defaultPosition)??A),i===void 0&&(i={left:((C=t==null?void 0:t.positions)==null?void 0:C.left)??O.left,top:((g=t==null?void 0:t.positions)==null?void 0:g.top)??O.top,right:((tt=t==null?void 0:t.positions)==null?void 0:tt.right)??O.right,bottom:((et=t==null?void 0:t.positions)==null?void 0:et.bottom)??O.bottom}),o===void 0&&(o=(t==null?void 0:t.offsetFromSource)??f),p===void 0&&(p=(t==null?void 0:t.offsetFromViewport)??_),u===void 0&&(u=(t==null?void 0:t.minWidth)??I),w===void 0&&(w=(t==null?void 0:t.maxWidth)??U),n===void 0&&(n=(t==null?void 0:t.tooltipBorderWidth)??k),T===void 0&&(T=W+" "+D+" "+((t==null?void 0:t.tooltipClasses)??"")),F===void 0&&(F=H+" "+P+" "+((t==null?void 0:t.textClasses)??"")),z===void 0&&(z=(t==null?void 0:t.arrowSize)??q),y===void 0&&(y=(t==null?void 0:t.arrowClasses)??""),M===void 0&&(M=(t==null?void 0:t.arrowMinOffsetFromTooltipCorner)??j),S===void 0&&(S=(t==null?void 0:t.zIndex)??R),V===void 0&&(V=Z),{tooltipText:s,tooltipPosition:d,tooltipPositions:i,tooltipOffsetFromSource:o,tooltipOffsetFromViewport:p,tooltipMinWidth:u,tooltipMaxWidth:w,tooltipBorderWidth:n,tooltipClasses:T,textClasses:F,arrowSize:z,arrowClasses:y,arrowMinOffsetFromTooltipCorner:M,zIndex:S,shouldShow:V}}function Ot(e){const t=typeof e=="string"?e:e.content;if(!t)throw new Error("Please enter valid tooltip value");return t}function xt(e,t,r){let s=e,d=Ft(t.textClasses,t.tooltipText),i=Tt(t.tooltipClasses,t.tooltipBorderWidth);i.append(d),i.dataset.uuid=r;const o=new AbortController,p=new AbortController;return s.addEventListener("mouseenter",()=>Wt(s,t,i,r),{signal:o.signal}),s.addEventListener("mouseleave",()=>vt(r),{signal:p.signal}),{anchorElement:s,tooltipConfig:t,tooltipElement:i,mouseEnterEventController:o,mouseLeaveEventController:p}}function Ft(e,t){let r=document.createElement("p");return r.classList.add(...e.trim().split(" ")),r.innerHTML=t,r}function Tt(e,t){let r=document.createElement("div");return r.classList.add(...e.trim().split(" ")),r.style.borderWidth=`${t}px`,r}function Wt(e,t,r,s){if(!t.shouldShow)return;const d=e.getBoundingClientRect(),i=document.querySelector("body");i==null||i.appendChild(r);let o=!1,p=t.tooltipPosition;for(let u=0;u<4&&(p=t.tooltipPositions[t.tooltipPosition][u],p==="left"?o=zt(d,t,r):p==="top"?o=Mt(d,t,r):p==="right"?o=yt(d,t,r):p==="bottom"&&(o=St(d,t,r)),!o);u++);o&&(Vt(d,p,t,r),r.style.opacity="1",r.style.zIndex=t.zIndex.toString(),ut(e,()=>v(s)),ht(e,()=>v(s)))}function vt(e){v(e)}function zt(e,t,r){const s=Math.min(e.left-t.tooltipOffsetFromSource-t.tooltipOffsetFromViewport,t.tooltipMaxWidth),d=e.top>=t.tooltipOffsetFromViewport,i=window.innerHeight-e.bottom>=t.tooltipOffsetFromViewport;if(s<t.tooltipMinWidth||!d||!i)return!1;r.style.maxWidth=`${s}px`;const o=r.getBoundingClientRect();let p=e.top+e.height/2-o.height/2;p<t.tooltipOffsetFromViewport?p=t.tooltipOffsetFromViewport:p+o.height>window.innerHeight-t.tooltipOffsetFromViewport&&(p=window.innerHeight-t.tooltipOffsetFromViewport-o.height);const u=e.left-t.tooltipOffsetFromSource-o.width;return e.bottom<p+t.arrowMinOffsetFromTooltipCorner*2||e.top>p+o.height-t.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${p}px`,r.style.left=`${u}px`,!0)}function yt(e,t,r){const s=Math.min(window.innerWidth-(e.right+t.tooltipOffsetFromSource)-t.tooltipOffsetFromViewport,t.tooltipMaxWidth),d=e.top>=t.tooltipOffsetFromViewport,i=window.innerHeight-e.bottom>=t.tooltipOffsetFromViewport;if(s<t.tooltipMinWidth||!d||!i)return!1;r.style.maxWidth=`${s}px`;const o=r.getBoundingClientRect();let p=e.top+e.height/2-o.height/2;p<t.tooltipOffsetFromViewport?p=t.tooltipOffsetFromViewport:p+o.height>window.innerHeight-t.tooltipOffsetFromViewport&&(p=window.innerHeight-t.tooltipOffsetFromViewport-o.height);const u=e.right+t.tooltipOffsetFromSource;return e.bottom<p+t.arrowMinOffsetFromTooltipCorner*2||e.top>p+o.height-t.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${p}px`,r.style.left=`${u}px`,!0)}function Mt(e,t,r){const s=Math.min(window.innerWidth-t.tooltipOffsetFromViewport*2,t.tooltipMaxWidth);r.style.maxWidth=`${s}px`;const d=r.getBoundingClientRect();let i=e.top-t.tooltipOffsetFromSource-d.height;if(i<t.tooltipOffsetFromViewport)return!1;let o=e.left+e.width/2-d.width/2;return o<t.tooltipOffsetFromViewport?o=t.tooltipOffsetFromViewport:o+d.width>window.innerWidth-t.tooltipOffsetFromViewport&&(o=window.innerWidth-t.tooltipOffsetFromViewport-d.width),e.left>o+d.width-t.arrowMinOffsetFromTooltipCorner*2||e.right<o+t.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${i}px`,r.style.left=`${o}px`,!0)}function St(e,t,r){const s=Math.min(window.innerWidth-t.tooltipOffsetFromViewport*2,t.tooltipMaxWidth);r.style.maxWidth=`${s}px`;const d=r.getBoundingClientRect();let i=e.bottom+t.tooltipOffsetFromSource;if(i+d.height>window.innerHeight-t.tooltipOffsetFromViewport)return!1;let o=e.left+e.width/2-d.width/2;return o<t.tooltipOffsetFromViewport?o=t.tooltipOffsetFromViewport:o+d.width>window.innerWidth-t.tooltipOffsetFromViewport&&(o=window.innerWidth-t.tooltipOffsetFromViewport-d.width),e.left>o+d.width-t.arrowMinOffsetFromTooltipCorner*2||e.right<o+t.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${i}px`,r.style.left=`${o}px`,!0)}function Vt(e,t,r,s){var F;const d=document.createElement("div"),i=s.getBoundingClientRect(),o=Math.sin(45*(180/Math.PI))*r.arrowSize,p=1;let u=0,w=0,n="";switch(t){case"left":n="!zt-border-y-transparent !zt-border-r-transparent",u=e.top-i.top+e.height/2-o-r.tooltipBorderWidth,w=i.width-r.tooltipBorderWidth-p;break;case"top":n="!zt-border-x-transparent !zt-border-b-transparent",u=i.height-r.tooltipBorderWidth-p,w=e.left-i.left+e.width/2-o-r.tooltipBorderWidth;break;case"right":n="!zt-border-y-transparent !zt-border-l-transparent",u=e.top-i.top+e.height/2-o-r.tooltipBorderWidth,w=-r.arrowSize*2-r.tooltipBorderWidth+p;break;case"bottom":n="!zt-border-x-transparent !zt-border-t-transparent",u=-r.arrowSize*2-r.tooltipBorderWidth+p,w=e.left-i.left+e.width/2-o-r.tooltipBorderWidth;break}t==="left"||t==="right"?N(t,i,u,r)||(u=G(t,i,u,r)):N(t,i,w,r)||(w=G(t,i,w,r));const T=$+" "+nt+" "+n+" "+r.arrowClasses;d.classList.add(...T.trim().split(" ")),d.style.top=`${u}px`,d.style.left=`${w}px`,d.style.borderWidth=`${r.arrowSize}px`,(F=document.querySelector(`.${W}`))==null||F.appendChild(d)}function N(e,t,r,s){switch(e){case"left":case"right":return r>s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth&&r<t.height+s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2;case"top":case"bottom":return r>s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth&&r<t.width+s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2}}function G(e,t,r,s){switch(e){case"left":case"right":return r<s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth?s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth:t.height-s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2;case"top":case"bottom":return r<s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth?s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth:t.width-s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2}}function v(e){var s,d;const t=document.querySelector(`.${W}`),r=(s=m[e])==null?void 0:s.tooltipElement;r&&t&&t instanceof HTMLElement&&t===r&&(wt(),(d=t.querySelector(`.${$}`))==null||d.remove(),t.style.left="0",t.style.top="0",t.remove())}function a(e){const t=e.tooltipElement.dataset.uuid;t&&(v(t),delete m[t]),e.mouseEnterEventController.abort(),e.mouseLeaveEventController.abort()}return mt});
|
package/package.json
CHANGED
package/src/tooltip.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Directive, watch } from "vue"
|
|
1
|
+
import { Directive, isReactive, watch } from "vue"
|
|
2
2
|
import { v4 as uuidv4 } from 'uuid'
|
|
3
3
|
import TooltipConfig from "./types/tooltipConfig"
|
|
4
4
|
import TooltipPosition from "./types/tooltipPosition"
|
|
@@ -47,7 +47,7 @@ const ZeroTooltip = (globalConfig?: TooltipConfig): Directive => {
|
|
|
47
47
|
|
|
48
48
|
buildTooltip(binding.value, globalConfig, binding.arg, targetElement, uuid)
|
|
49
49
|
|
|
50
|
-
if (typeof(binding.value) !== 'string') {
|
|
50
|
+
if (typeof(binding.value) !== 'string' && isReactive(binding.value)) {
|
|
51
51
|
watch(binding.value, (newBindingValue) => {
|
|
52
52
|
if (tooltips[uuid]) {
|
|
53
53
|
destroyTooltip(tooltips[uuid])
|
|
@@ -59,20 +59,20 @@ const ZeroTooltip = (globalConfig?: TooltipConfig): Directive => {
|
|
|
59
59
|
},
|
|
60
60
|
|
|
61
61
|
updated: (targetElement: HTMLElement, binding, vnode) => {
|
|
62
|
-
|
|
63
|
-
const uuid = vnode.el.$_tooltip.uuid
|
|
62
|
+
const uuid = vnode.el.$_tooltip.uuid
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
buildTooltip(binding.value, globalConfig, binding.arg, targetElement, uuid)
|
|
64
|
+
if (tooltips[uuid]) {
|
|
65
|
+
destroyTooltip(tooltips[uuid])
|
|
70
66
|
}
|
|
67
|
+
|
|
68
|
+
buildTooltip(binding.value, globalConfig, binding.arg, targetElement, uuid)
|
|
71
69
|
},
|
|
72
70
|
|
|
73
|
-
beforeUnmount: () => {
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
beforeUnmount: (_, __, vnode) => {
|
|
72
|
+
const uuid = vnode.el.$_tooltip.uuid
|
|
73
|
+
|
|
74
|
+
if (tooltips[uuid]) {
|
|
75
|
+
destroyTooltip(tooltips[uuid])
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -82,11 +82,11 @@ function buildTooltip(bindingValue: any, globalConfig: TooltipConfig | undefined
|
|
|
82
82
|
let tooltipConfig = getTooltipConfig(bindingValue as string | TooltipLocalConfig, globalConfig, bindingArgument as TooltipPosition)
|
|
83
83
|
const tooltip = initTooltip(targetElement, tooltipConfig, uuid)
|
|
84
84
|
|
|
85
|
+
tooltips[uuid] = tooltip
|
|
86
|
+
|
|
85
87
|
if (targetElement.matches(':hover')) {
|
|
86
88
|
targetElement.dispatchEvent(new Event('mouseenter'))
|
|
87
89
|
}
|
|
88
|
-
|
|
89
|
-
tooltips[uuid] = tooltip
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
function getTooltipConfig(localConfig: string | TooltipLocalConfig, globalConfig?: TooltipConfig, position?: TooltipPosition) {
|
|
@@ -191,8 +191,8 @@ function initTooltip(targetElement: HTMLElement, tooltipConfig: ReturnType<typeo
|
|
|
191
191
|
const mouseEnterEventController = new AbortController()
|
|
192
192
|
const mouseLeaveEventController = new AbortController()
|
|
193
193
|
|
|
194
|
-
anchorElement.addEventListener('mouseenter', () => onMouseEnter(anchorElement, tooltipConfig, tooltipElement), { signal: mouseEnterEventController.signal})
|
|
195
|
-
anchorElement.addEventListener('mouseleave', onMouseLeave, { signal: mouseLeaveEventController.signal})
|
|
194
|
+
anchorElement.addEventListener('mouseenter', () => onMouseEnter(anchorElement, tooltipConfig, tooltipElement, uuid), { signal: mouseEnterEventController.signal})
|
|
195
|
+
anchorElement.addEventListener('mouseleave', () => onMouseLeave(uuid), { signal: mouseLeaveEventController.signal})
|
|
196
196
|
|
|
197
197
|
return {
|
|
198
198
|
anchorElement,
|
|
@@ -220,9 +220,10 @@ function createTooltipElement(tooltipClasses: string, tooltipBorderWidth: number
|
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
function onMouseEnter(
|
|
223
|
-
|
|
223
|
+
anchorElement: HTMLElement,
|
|
224
224
|
tooltipConfig: ReturnType<typeof getTooltipConfig>,
|
|
225
|
-
tooltipElement: HTMLDivElement
|
|
225
|
+
tooltipElement: HTMLDivElement,
|
|
226
|
+
uuid: string
|
|
226
227
|
) {
|
|
227
228
|
if (!tooltipConfig.shouldShow) return
|
|
228
229
|
|
|
@@ -257,13 +258,13 @@ function onMouseEnter(
|
|
|
257
258
|
tooltipElement.style.opacity = '1'
|
|
258
259
|
tooltipElement.style.zIndex = tooltipConfig.zIndex.toString()
|
|
259
260
|
|
|
260
|
-
handleHideOnScroll(anchorElement, () => hideTooltip())
|
|
261
|
-
handleHideOnResize(anchorElement, () => hideTooltip())
|
|
261
|
+
handleHideOnScroll(anchorElement, () => hideTooltip(uuid))
|
|
262
|
+
handleHideOnResize(anchorElement, () => hideTooltip(uuid))
|
|
262
263
|
}
|
|
263
264
|
}
|
|
264
265
|
|
|
265
|
-
function onMouseLeave() {
|
|
266
|
-
hideTooltip()
|
|
266
|
+
function onMouseLeave(uuid: string) {
|
|
267
|
+
hideTooltip(uuid)
|
|
267
268
|
}
|
|
268
269
|
|
|
269
270
|
function tryMountTooltipOnLeft(anchorElementRect: DOMRect, tooltipConfig: ReturnType<typeof getTooltipConfig>, tooltipElement: HTMLDivElement) {
|
|
@@ -499,34 +500,34 @@ function getArrowPositionMinLimit(currentTooltipPosition: TooltipPosition, toolt
|
|
|
499
500
|
}
|
|
500
501
|
}
|
|
501
502
|
|
|
502
|
-
function hideTooltip() {
|
|
503
|
-
const
|
|
503
|
+
function hideTooltip(uuid: string) {
|
|
504
|
+
const shownTooltipElement = document.querySelector(`.${tooltipElementClass}`)
|
|
505
|
+
const currentTooltipElement = tooltips[uuid]?.tooltipElement
|
|
504
506
|
|
|
505
|
-
if (
|
|
507
|
+
if (currentTooltipElement && shownTooltipElement && shownTooltipElement instanceof HTMLElement && shownTooltipElement === currentTooltipElement) {
|
|
506
508
|
resetResizeReferences()
|
|
507
509
|
|
|
508
510
|
// Remove Arrow element from Tooltip, because it needs to be rebuilt every time Tooltip is showed again
|
|
509
|
-
|
|
511
|
+
shownTooltipElement.querySelector(`.${arrowElementClass}`)?.remove()
|
|
510
512
|
|
|
511
513
|
// Reset position so that old position does not effect new position (when zooming old position could be off screen)
|
|
512
|
-
|
|
513
|
-
|
|
514
|
+
shownTooltipElement.style.left = '0'
|
|
515
|
+
shownTooltipElement.style.top = '0'
|
|
514
516
|
|
|
515
|
-
|
|
517
|
+
shownTooltipElement.remove()
|
|
516
518
|
}
|
|
517
519
|
}
|
|
518
520
|
|
|
519
521
|
function destroyTooltip(tooltip: ReturnType<typeof initTooltip>) {
|
|
520
|
-
hideTooltip()
|
|
521
|
-
|
|
522
|
-
tooltip.mouseEnterEventController.abort()
|
|
523
|
-
tooltip.mouseLeaveEventController.abort()
|
|
524
|
-
|
|
525
522
|
const uuid = tooltip.tooltipElement.dataset.uuid
|
|
526
523
|
|
|
527
524
|
if (uuid) {
|
|
525
|
+
hideTooltip(uuid)
|
|
528
526
|
delete tooltips[uuid]
|
|
529
527
|
}
|
|
528
|
+
|
|
529
|
+
tooltip.mouseEnterEventController.abort()
|
|
530
|
+
tooltip.mouseLeaveEventController.abort()
|
|
530
531
|
}
|
|
531
532
|
|
|
532
533
|
export default ZeroTooltip
|