zero-tooltip 1.3.0 → 1.3.2
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/composables/useHideOnResize.d.ts +2 -2
- package/dist/zero-tooltip.js +146 -146
- package/dist/zero-tooltip.umd.cjs +1 -1
- package/package.json +3 -2
- package/src/composables/useHideOnResize.ts +16 -14
- package/src/tooltip.ts +15 -19
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export default function useHideOnResize(): {
|
|
2
|
-
handleHideOnResize: (anchorElement: HTMLElement, hideOverlay: () => void) => void;
|
|
3
|
-
resetResizeReferences: () => void;
|
|
2
|
+
handleHideOnResize: (tooltipUuid: string, anchorElement: HTMLElement, hideOverlay: () => void) => void;
|
|
3
|
+
resetResizeReferences: (tooltipUuid: string) => void;
|
|
4
4
|
};
|
package/dist/zero-tooltip.js
CHANGED
|
@@ -6,33 +6,33 @@ function X() {
|
|
|
6
6
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
7
7
|
return v(Q);
|
|
8
8
|
}
|
|
9
|
-
const
|
|
10
|
-
for (let
|
|
11
|
-
|
|
12
|
-
function Y(
|
|
13
|
-
return
|
|
9
|
+
const u = [];
|
|
10
|
+
for (let t = 0; t < 256; ++t)
|
|
11
|
+
u.push((t + 256).toString(16).slice(1));
|
|
12
|
+
function Y(t, e = 0) {
|
|
13
|
+
return u[t[e + 0]] + u[t[e + 1]] + u[t[e + 2]] + u[t[e + 3]] + "-" + u[t[e + 4]] + u[t[e + 5]] + "-" + u[t[e + 6]] + u[t[e + 7]] + "-" + u[t[e + 8]] + u[t[e + 9]] + "-" + u[t[e + 10]] + u[t[e + 11]] + u[t[e + 12]] + u[t[e + 13]] + u[t[e + 14]] + u[t[e + 15]];
|
|
14
14
|
}
|
|
15
|
-
const b = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto),
|
|
15
|
+
const b = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), _ = {
|
|
16
16
|
randomUUID: b
|
|
17
17
|
};
|
|
18
|
-
function C(
|
|
19
|
-
if (
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
const s =
|
|
23
|
-
if (s[6] = s[6] & 15 | 64, s[8] = s[8] & 63 | 128,
|
|
18
|
+
function C(t, e, r) {
|
|
19
|
+
if (_.randomUUID && !e && !t)
|
|
20
|
+
return _.randomUUID();
|
|
21
|
+
t = t || {};
|
|
22
|
+
const s = t.random || (t.rng || X)();
|
|
23
|
+
if (s[6] = s[6] & 15 | 64, s[8] = s[8] & 63 | 128, e) {
|
|
24
24
|
r = r || 0;
|
|
25
25
|
for (let o = 0; o < 16; ++o)
|
|
26
|
-
|
|
27
|
-
return
|
|
26
|
+
e[r + o] = s[o];
|
|
27
|
+
return e;
|
|
28
28
|
}
|
|
29
29
|
return Y(s);
|
|
30
30
|
}
|
|
31
31
|
function g() {
|
|
32
|
-
let
|
|
33
|
-
const
|
|
34
|
-
if (r(o),
|
|
35
|
-
for (const d of
|
|
32
|
+
let t = [];
|
|
33
|
+
const e = (o, i) => {
|
|
34
|
+
if (r(o), t.length > 0)
|
|
35
|
+
for (const d of t)
|
|
36
36
|
d.addEventListener("scroll", i);
|
|
37
37
|
window.addEventListener("scroll", () => {
|
|
38
38
|
i(), s(i);
|
|
@@ -42,247 +42,247 @@ function g() {
|
|
|
42
42
|
for (; i !== null && i.tagName !== "HTML"; ) {
|
|
43
43
|
if (i.scrollHeight !== i.clientHeight) {
|
|
44
44
|
const d = window.getComputedStyle(i);
|
|
45
|
-
(d.overflow === "auto" || d.overflow === "scroll") &&
|
|
45
|
+
(d.overflow === "auto" || d.overflow === "scroll") && t.push(i);
|
|
46
46
|
}
|
|
47
47
|
i = i.parentElement;
|
|
48
48
|
}
|
|
49
49
|
}, s = (o) => {
|
|
50
|
-
if (
|
|
51
|
-
for (const i of
|
|
50
|
+
if (t.length > 0) {
|
|
51
|
+
for (const i of t)
|
|
52
52
|
i.removeEventListener("scroll", o);
|
|
53
|
-
|
|
53
|
+
t = [];
|
|
54
54
|
}
|
|
55
55
|
window.removeEventListener("scroll", o);
|
|
56
56
|
};
|
|
57
|
-
return { handleHideOnScroll:
|
|
57
|
+
return { handleHideOnScroll: e };
|
|
58
58
|
}
|
|
59
|
-
function
|
|
60
|
-
|
|
61
|
-
return { handleHideOnResize: (o, i) => {
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
if (
|
|
65
|
-
|
|
59
|
+
function ee() {
|
|
60
|
+
const t = {}, e = {};
|
|
61
|
+
return { handleHideOnResize: (o, i, d) => {
|
|
62
|
+
let n = new ResizeObserver((p) => {
|
|
63
|
+
const m = p[0].target;
|
|
64
|
+
if (!e[o])
|
|
65
|
+
e[o] = i.getBoundingClientRect();
|
|
66
66
|
else {
|
|
67
|
-
const
|
|
68
|
-
(
|
|
67
|
+
const h = m.getBoundingClientRect();
|
|
68
|
+
(h.left !== e[o].left || h.top !== e[o].top || h.width !== e[o].width || h.height !== e[o].height) && d();
|
|
69
69
|
}
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
});
|
|
71
|
+
t[o] = n, n.observe(i);
|
|
72
|
+
}, resetResizeReferences: (o) => {
|
|
73
|
+
t[o] && t[o].disconnect(), delete t[o], delete e[o];
|
|
73
74
|
} };
|
|
74
75
|
}
|
|
75
|
-
const { handleHideOnScroll:
|
|
76
|
+
const { handleHideOnScroll: te } = g(), { handleHideOnResize: re, resetResizeReferences: se } = ee(), P = "zero-tooltip__container", k = "zero-tooltip__text", G = "zero-tooltip__arrow", O = {
|
|
76
77
|
left: ["left", "right", "top", "bottom"],
|
|
77
78
|
top: ["top", "bottom", "right", "left"],
|
|
78
79
|
right: ["right", "left", "top", "bottom"],
|
|
79
80
|
bottom: ["bottom", "top", "right", "left"]
|
|
80
|
-
},
|
|
81
|
-
created: (
|
|
81
|
+
}, oe = "body", ie = "top", de = 10, ne = 20, pe = 100, he = 250, we = 0, j = "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", R = "zt-text-sm zt-text-white zt-whitespace-pre-wrap zt-break-words", me = 5, ue = "zt-absolute zt-border-solid zt-border-[#495057]", ae = 6, ce = 1, ve = !0, Oe = 0, Te = 0, w = {}, xe = (t) => ({
|
|
82
|
+
created: (e, r, s) => {
|
|
82
83
|
const o = C();
|
|
83
|
-
s.el.$_tooltip = { uuid: o }, x(r.value,
|
|
84
|
-
|
|
84
|
+
s.el.$_tooltip = { uuid: o }, x(r.value, t, r.arg, e, o), typeof r.value != "string" && J(r.value) && K(r.value, (i) => {
|
|
85
|
+
w[o] && F(w[o]), x(i, t, r.arg, e, o);
|
|
85
86
|
});
|
|
86
87
|
},
|
|
87
|
-
updated: (
|
|
88
|
+
updated: (e, r, s) => {
|
|
88
89
|
const o = s.el.$_tooltip.uuid;
|
|
89
|
-
|
|
90
|
+
w[o] && F(w[o]), x(r.value, t, r.arg, e, o);
|
|
90
91
|
},
|
|
91
|
-
beforeUnmount: (
|
|
92
|
+
beforeUnmount: (e, r, s) => {
|
|
92
93
|
const o = s.el.$_tooltip.uuid;
|
|
93
|
-
|
|
94
|
+
w[o] && F(w[o]);
|
|
94
95
|
}
|
|
95
96
|
});
|
|
96
|
-
function x(
|
|
97
|
-
let i =
|
|
98
|
-
const d =
|
|
99
|
-
|
|
97
|
+
function x(t, e, r, s, o) {
|
|
98
|
+
let i = Fe(t, e, r);
|
|
99
|
+
const d = fe(s, i, o);
|
|
100
|
+
w[o] = d, s.matches(":hover") && s.dispatchEvent(new Event("mouseenter"));
|
|
100
101
|
}
|
|
101
|
-
function
|
|
102
|
-
var L, H, I, A, D, E,
|
|
103
|
-
let s = (
|
|
104
|
-
left: ((
|
|
105
|
-
top: ((
|
|
106
|
-
right: ((
|
|
107
|
-
bottom: ((
|
|
108
|
-
}, n = (
|
|
109
|
-
return typeof
|
|
102
|
+
function Fe(t, e, r) {
|
|
103
|
+
var B, L, H, I, A, D, E, $;
|
|
104
|
+
let s = (e == null ? void 0 : e.appendTo) ?? oe, o = ye(t), i = r ?? (e == null ? void 0 : e.defaultPosition) ?? ie, d = {
|
|
105
|
+
left: ((B = e == null ? void 0 : e.positions) == null ? void 0 : B.left) ?? O.left,
|
|
106
|
+
top: ((L = e == null ? void 0 : e.positions) == null ? void 0 : L.top) ?? O.top,
|
|
107
|
+
right: ((H = e == null ? void 0 : e.positions) == null ? void 0 : H.right) ?? O.right,
|
|
108
|
+
bottom: ((I = e == null ? void 0 : e.positions) == null ? void 0 : I.bottom) ?? O.bottom
|
|
109
|
+
}, n = (e == null ? void 0 : e.offsetFromSource) ?? de, p = (e == null ? void 0 : e.offsetFromViewport) ?? ne, m = (e == null ? void 0 : e.minWidth) ?? pe, h = (e == null ? void 0 : e.maxWidth) ?? he, a = (e == null ? void 0 : e.tooltipBorderWidth) ?? we, c = P + " " + j + " " + ((e == null ? void 0 : e.tooltipClasses) ?? ""), y = k + " " + R + " " + ((e == null ? void 0 : e.textClasses) ?? ""), f = (e == null ? void 0 : e.arrowSize) ?? me, M = (e == null ? void 0 : e.arrowClasses) ?? "", z = (e == null ? void 0 : e.arrowMinOffsetFromTooltipCorner) ?? ae, W = (e == null ? void 0 : e.zIndex) ?? ce, S = ve, l = (e == null ? void 0 : e.showDelay) ?? Oe, V = (e == null ? void 0 : e.hideDelay) ?? Te;
|
|
110
|
+
return typeof t != "string" && (t.appendTo !== void 0 && (s = t.appendTo), r === void 0 && t.defaultPosition !== void 0 && (i = t.defaultPosition), ((A = t.positions) == null ? void 0 : A.left) !== void 0 && (d.left = t.positions.left), ((D = t.positions) == null ? void 0 : D.top) !== void 0 && (d.top = t.positions.top), ((E = t.positions) == null ? void 0 : E.right) !== void 0 && (d.right = t.positions.right), (($ = t.positions) == null ? void 0 : $.bottom) !== void 0 && (d.bottom = t.positions.bottom), t.offsetFromSource !== void 0 && (n = t.offsetFromSource), t.offsetFromViewport !== void 0 && (p = t.offsetFromViewport), t.minWidth !== void 0 && (m = t.minWidth), t.maxWidth !== void 0 && (h = t.maxWidth), t.tooltipBorderWidth !== void 0 && (a = t.tooltipBorderWidth), t.tooltipClasses !== void 0 && (c = P + " " + j + " " + t.tooltipClasses), t.textClasses !== void 0 && (y = k + " " + R + " " + t.textClasses), t.arrowSize !== void 0 && (f = t.arrowSize), t.arrowClasses !== void 0 && (M = t.arrowClasses), t.arrowMinOffsetFromTooltipCorner !== void 0 && (z = t.arrowMinOffsetFromTooltipCorner), t.zIndex !== void 0 && (W = t.zIndex), t.show !== void 0 && (S = t.show), t.showDelay !== void 0 && (l = t.showDelay), t.hideDelay !== void 0 && (V = t.hideDelay)), {
|
|
110
111
|
appendTo: s,
|
|
111
112
|
tooltipText: o,
|
|
112
113
|
tooltipPosition: i,
|
|
113
114
|
tooltipPositions: d,
|
|
114
115
|
tooltipOffsetFromSource: n,
|
|
115
116
|
tooltipOffsetFromViewport: p,
|
|
116
|
-
tooltipMinWidth:
|
|
117
|
-
tooltipMaxWidth:
|
|
117
|
+
tooltipMinWidth: m,
|
|
118
|
+
tooltipMaxWidth: h,
|
|
118
119
|
tooltipBorderWidth: a,
|
|
119
120
|
tooltipClasses: c,
|
|
120
|
-
textClasses:
|
|
121
|
+
textClasses: y,
|
|
121
122
|
arrowSize: f,
|
|
122
123
|
arrowClasses: M,
|
|
123
124
|
arrowMinOffsetFromTooltipCorner: z,
|
|
124
125
|
zIndex: W,
|
|
125
126
|
shouldShow: S,
|
|
126
|
-
showDelay:
|
|
127
|
-
hideDelay:
|
|
127
|
+
showDelay: l,
|
|
128
|
+
hideDelay: V
|
|
128
129
|
};
|
|
129
130
|
}
|
|
130
|
-
function
|
|
131
|
-
const
|
|
132
|
-
if (!
|
|
131
|
+
function ye(t) {
|
|
132
|
+
const e = typeof t == "string" ? t : t.content;
|
|
133
|
+
if (!e)
|
|
133
134
|
throw new Error("Please enter valid tooltip value");
|
|
134
|
-
return
|
|
135
|
+
return e;
|
|
135
136
|
}
|
|
136
|
-
function
|
|
137
|
-
let s =
|
|
137
|
+
function fe(t, e, r) {
|
|
138
|
+
let s = t, o = Me(e.textClasses, e.tooltipText), i = ze(e.tooltipClasses, e.tooltipBorderWidth);
|
|
138
139
|
i.append(o), i.dataset.uuid = r;
|
|
139
140
|
const d = {
|
|
140
141
|
currentInstanceId: Date.now(),
|
|
141
142
|
isHoveringOverAnchorElement: !1,
|
|
142
|
-
lastTooltipMouseLeaveTimestamp:
|
|
143
|
+
lastTooltipMouseLeaveTimestamp: 0
|
|
143
144
|
}, n = {
|
|
144
145
|
anchorElementMouseEnter: new AbortController(),
|
|
145
146
|
anchorElementMouseLeave: new AbortController(),
|
|
146
147
|
tooltipElementMouseEnter: new AbortController(),
|
|
147
148
|
tooltipElementMouseLeave: new AbortController()
|
|
148
149
|
};
|
|
149
|
-
return s.addEventListener("mouseenter", () =>
|
|
150
|
+
return s.addEventListener("mouseenter", () => U(s, e, i, r), { signal: n.anchorElementMouseEnter.signal }), s.addEventListener("mouseleave", () => q(e, r), { signal: n.anchorElementMouseLeave.signal }), i.addEventListener("mouseenter", () => U(s, e, i, r, { isTooltip: !0 }), { signal: n.tooltipElementMouseEnter.signal }), i.addEventListener("mouseleave", () => q(e, r, { isTooltip: !0 }), { signal: n.tooltipElementMouseLeave.signal }), {
|
|
150
151
|
anchorElement: s,
|
|
151
|
-
tooltipConfig:
|
|
152
|
+
tooltipConfig: e,
|
|
152
153
|
tooltipElement: i,
|
|
153
154
|
mouseEnterEventControllers: n,
|
|
154
155
|
mouseEventState: d
|
|
155
156
|
};
|
|
156
157
|
}
|
|
157
|
-
function
|
|
158
|
+
function Me(t, e) {
|
|
158
159
|
let r = document.createElement("p");
|
|
159
|
-
return r.classList.add(...
|
|
160
|
+
return r.classList.add(...t.trim().split(" ")), r.innerHTML = e, r;
|
|
160
161
|
}
|
|
161
|
-
function
|
|
162
|
+
function ze(t, e) {
|
|
162
163
|
let r = document.createElement("div");
|
|
163
|
-
return r.classList.add(...
|
|
164
|
+
return r.classList.add(...t.trim().split(" ")), r.style.borderWidth = `${e}px`, r;
|
|
164
165
|
}
|
|
165
|
-
async function
|
|
166
|
-
if (!
|
|
166
|
+
async function U(t, e, r, s, o) {
|
|
167
|
+
if (!e.shouldShow)
|
|
167
168
|
return;
|
|
168
|
-
let i = o != null && o.isTooltip ? 0 :
|
|
169
|
+
let i = o != null && o.isTooltip ? 0 : e.showDelay;
|
|
169
170
|
const d = 100;
|
|
170
|
-
!(o != null && o.isTooltip) && Date.now() -
|
|
171
|
+
!(o != null && o.isTooltip) && Date.now() - w[s].mouseEventState.lastTooltipMouseLeaveTimestamp <= d && (i = 0);
|
|
171
172
|
const n = Date.now();
|
|
172
|
-
if (
|
|
173
|
+
if (w[s].mouseEventState.currentInstanceId = n, w[s].mouseEventState.isHoveringOverAnchorElement = !0, i > 0 && (await new Promise((c) => setTimeout(c, i)), !w[s].mouseEventState.isHoveringOverAnchorElement || w[s].mouseEventState.currentInstanceId !== n))
|
|
173
174
|
return;
|
|
174
|
-
const p =
|
|
175
|
-
|
|
176
|
-
let
|
|
177
|
-
for (let c = 0; c < 4 && (a =
|
|
175
|
+
const p = t.getBoundingClientRect(), m = document.querySelector(e.appendTo);
|
|
176
|
+
m == null || m.appendChild(r);
|
|
177
|
+
let h = !1, a = e.tooltipPosition;
|
|
178
|
+
for (let c = 0; c < 4 && (a = e.tooltipPositions[e.tooltipPosition][c], a === "left" ? h = We(p, e, r) : a === "top" ? h = le(p, e, r) : a === "right" ? h = Se(p, e, r) : a === "bottom" && (h = Ve(p, e, r)), !h); c++)
|
|
178
179
|
;
|
|
179
|
-
|
|
180
|
+
h && (Be(p, a, e, r), r.style.opacity = "1", r.style.zIndex = typeof e.zIndex == "string" ? e.zIndex : e.zIndex.toString(), te(t, () => T(s)), re(s, t, () => T(s)));
|
|
180
181
|
}
|
|
181
|
-
async function
|
|
182
|
-
r != null && r.isTooltip && (
|
|
183
|
-
const s =
|
|
184
|
-
|
|
182
|
+
async function q(t, e, r) {
|
|
183
|
+
r != null && r.isTooltip && (w[e].mouseEventState.lastTooltipMouseLeaveTimestamp = Date.now());
|
|
184
|
+
const s = Date.now();
|
|
185
|
+
w[e].mouseEventState.currentInstanceId = s, w[e].mouseEventState.isHoveringOverAnchorElement = !1, !(t.hideDelay > 0 && (await new Promise((o) => setTimeout(o, t.hideDelay)), w[e].mouseEventState.isHoveringOverAnchorElement || w[e].mouseEventState.currentInstanceId !== s)) && T(e);
|
|
185
186
|
}
|
|
186
|
-
function
|
|
187
|
-
const s = Math.min(
|
|
188
|
-
if (s <
|
|
187
|
+
function We(t, e, r) {
|
|
188
|
+
const s = Math.min(t.left - e.tooltipOffsetFromSource - e.tooltipOffsetFromViewport, e.tooltipMaxWidth), o = t.top >= e.tooltipOffsetFromViewport, i = window.innerHeight - t.bottom >= e.tooltipOffsetFromViewport;
|
|
189
|
+
if (s < e.tooltipMinWidth || !o || !i)
|
|
189
190
|
return !1;
|
|
190
191
|
r.style.maxWidth = `${s}px`;
|
|
191
192
|
const d = r.getBoundingClientRect();
|
|
192
|
-
let n =
|
|
193
|
-
n <
|
|
194
|
-
const p =
|
|
195
|
-
return
|
|
193
|
+
let n = t.top + t.height / 2 - d.height / 2;
|
|
194
|
+
n < e.tooltipOffsetFromViewport ? n = e.tooltipOffsetFromViewport : n + d.height > window.innerHeight - e.tooltipOffsetFromViewport && (n = window.innerHeight - e.tooltipOffsetFromViewport - d.height);
|
|
195
|
+
const p = t.left - e.tooltipOffsetFromSource - d.width;
|
|
196
|
+
return t.bottom < n + e.arrowMinOffsetFromTooltipCorner * 2 || t.top > n + d.height - e.arrowMinOffsetFromTooltipCorner * 2 ? !1 : (r.style.top = `${n}px`, r.style.left = `${p}px`, !0);
|
|
196
197
|
}
|
|
197
|
-
function
|
|
198
|
-
const s = Math.min(window.innerWidth - (
|
|
199
|
-
if (s <
|
|
198
|
+
function Se(t, e, r) {
|
|
199
|
+
const s = Math.min(window.innerWidth - (t.right + e.tooltipOffsetFromSource) - e.tooltipOffsetFromViewport, e.tooltipMaxWidth), o = t.top >= e.tooltipOffsetFromViewport, i = window.innerHeight - t.bottom >= e.tooltipOffsetFromViewport;
|
|
200
|
+
if (s < e.tooltipMinWidth || !o || !i)
|
|
200
201
|
return !1;
|
|
201
202
|
r.style.maxWidth = `${s}px`;
|
|
202
203
|
const d = r.getBoundingClientRect();
|
|
203
|
-
let n =
|
|
204
|
-
n <
|
|
205
|
-
const p =
|
|
206
|
-
return
|
|
204
|
+
let n = t.top + t.height / 2 - d.height / 2;
|
|
205
|
+
n < e.tooltipOffsetFromViewport ? n = e.tooltipOffsetFromViewport : n + d.height > window.innerHeight - e.tooltipOffsetFromViewport && (n = window.innerHeight - e.tooltipOffsetFromViewport - d.height);
|
|
206
|
+
const p = t.right + e.tooltipOffsetFromSource;
|
|
207
|
+
return t.bottom < n + e.arrowMinOffsetFromTooltipCorner * 2 || t.top > n + d.height - e.arrowMinOffsetFromTooltipCorner * 2 ? !1 : (r.style.top = `${n}px`, r.style.left = `${p}px`, !0);
|
|
207
208
|
}
|
|
208
|
-
function
|
|
209
|
-
const s = Math.min(window.innerWidth -
|
|
209
|
+
function le(t, e, r) {
|
|
210
|
+
const s = Math.min(window.innerWidth - e.tooltipOffsetFromViewport * 2, e.tooltipMaxWidth);
|
|
210
211
|
r.style.maxWidth = `${s}px`;
|
|
211
212
|
const o = r.getBoundingClientRect();
|
|
212
|
-
let i =
|
|
213
|
-
if (i <
|
|
213
|
+
let i = t.top - e.tooltipOffsetFromSource - o.height;
|
|
214
|
+
if (i < e.tooltipOffsetFromViewport)
|
|
214
215
|
return !1;
|
|
215
|
-
let d =
|
|
216
|
-
return d <
|
|
216
|
+
let d = t.left + t.width / 2 - o.width / 2;
|
|
217
|
+
return d < e.tooltipOffsetFromViewport ? d = e.tooltipOffsetFromViewport : d + o.width > window.innerWidth - e.tooltipOffsetFromViewport && (d = window.innerWidth - e.tooltipOffsetFromViewport - o.width), t.left > d + o.width - e.arrowMinOffsetFromTooltipCorner * 2 || t.right < d + e.arrowMinOffsetFromTooltipCorner * 2 ? !1 : (r.style.top = `${i}px`, r.style.left = `${d}px`, !0);
|
|
217
218
|
}
|
|
218
|
-
function
|
|
219
|
-
const s = Math.min(window.innerWidth -
|
|
219
|
+
function Ve(t, e, r) {
|
|
220
|
+
const s = Math.min(window.innerWidth - e.tooltipOffsetFromViewport * 2, e.tooltipMaxWidth);
|
|
220
221
|
r.style.maxWidth = `${s}px`;
|
|
221
222
|
const o = r.getBoundingClientRect();
|
|
222
|
-
let i =
|
|
223
|
-
if (i + o.height > window.innerHeight -
|
|
223
|
+
let i = t.bottom + e.tooltipOffsetFromSource;
|
|
224
|
+
if (i + o.height > window.innerHeight - e.tooltipOffsetFromViewport)
|
|
224
225
|
return !1;
|
|
225
|
-
let d =
|
|
226
|
-
return d <
|
|
226
|
+
let d = t.left + t.width / 2 - o.width / 2;
|
|
227
|
+
return d < e.tooltipOffsetFromViewport ? d = e.tooltipOffsetFromViewport : d + o.width > window.innerWidth - e.tooltipOffsetFromViewport && (d = window.innerWidth - e.tooltipOffsetFromViewport - o.width), t.left > d + o.width - e.arrowMinOffsetFromTooltipCorner * 2 || t.right < d + e.arrowMinOffsetFromTooltipCorner * 2 ? !1 : (r.style.top = `${i}px`, r.style.left = `${d}px`, !0);
|
|
227
228
|
}
|
|
228
|
-
function
|
|
229
|
-
var c;
|
|
229
|
+
function Be(t, e, r, s) {
|
|
230
230
|
const o = document.createElement("div"), i = s.getBoundingClientRect(), d = Math.sin(45 * (180 / Math.PI)) * r.arrowSize, n = 1;
|
|
231
|
-
let p = 0,
|
|
232
|
-
switch (
|
|
231
|
+
let p = 0, m = 0, h = "";
|
|
232
|
+
switch (e) {
|
|
233
233
|
case "left":
|
|
234
|
-
|
|
234
|
+
h = "!zt-border-y-transparent !zt-border-r-transparent", p = t.top - i.top + t.height / 2 - d - r.tooltipBorderWidth, m = i.width - r.tooltipBorderWidth - n;
|
|
235
235
|
break;
|
|
236
236
|
case "top":
|
|
237
|
-
|
|
237
|
+
h = "!zt-border-x-transparent !zt-border-b-transparent", p = i.height - r.tooltipBorderWidth - n, m = t.left - i.left + t.width / 2 - d - r.tooltipBorderWidth;
|
|
238
238
|
break;
|
|
239
239
|
case "right":
|
|
240
|
-
|
|
240
|
+
h = "!zt-border-y-transparent !zt-border-l-transparent", p = t.top - i.top + t.height / 2 - d - r.tooltipBorderWidth, m = -r.arrowSize * 2 - r.tooltipBorderWidth + n;
|
|
241
241
|
break;
|
|
242
242
|
case "bottom":
|
|
243
|
-
|
|
243
|
+
h = "!zt-border-x-transparent !zt-border-t-transparent", p = -r.arrowSize * 2 - r.tooltipBorderWidth + n, m = t.left - i.left + t.width / 2 - d - r.tooltipBorderWidth;
|
|
244
244
|
break;
|
|
245
245
|
}
|
|
246
|
-
|
|
247
|
-
const a = G + " " +
|
|
248
|
-
o.classList.add(...a.trim().split(" ")), o.style.top = `${p}px`, o.style.left = `${
|
|
246
|
+
e === "left" || e === "right" ? N(e, i, p, r) || (p = Z(e, i, p, r)) : N(e, i, m, r) || (m = Z(e, i, m, r));
|
|
247
|
+
const a = G + " " + ue + " " + h + " " + r.arrowClasses;
|
|
248
|
+
o.classList.add(...a.trim().split(" ")), o.style.top = `${p}px`, o.style.left = `${m}px`, o.style.borderWidth = `${r.arrowSize}px`, s.appendChild(o);
|
|
249
249
|
}
|
|
250
|
-
function N(
|
|
251
|
-
switch (
|
|
250
|
+
function N(t, e, r, s) {
|
|
251
|
+
switch (t) {
|
|
252
252
|
case "left":
|
|
253
253
|
case "right":
|
|
254
|
-
return r > s.arrowMinOffsetFromTooltipCorner - s.tooltipBorderWidth && r <
|
|
254
|
+
return r > s.arrowMinOffsetFromTooltipCorner - s.tooltipBorderWidth && r < e.height + s.tooltipBorderWidth - s.arrowMinOffsetFromTooltipCorner - s.arrowSize * 2;
|
|
255
255
|
case "top":
|
|
256
256
|
case "bottom":
|
|
257
|
-
return r > s.arrowMinOffsetFromTooltipCorner - s.tooltipBorderWidth && r <
|
|
257
|
+
return r > s.arrowMinOffsetFromTooltipCorner - s.tooltipBorderWidth && r < e.width + s.tooltipBorderWidth - s.arrowMinOffsetFromTooltipCorner - s.arrowSize * 2;
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
|
-
function Z(
|
|
261
|
-
switch (
|
|
260
|
+
function Z(t, e, r, s) {
|
|
261
|
+
switch (t) {
|
|
262
262
|
case "left":
|
|
263
263
|
case "right":
|
|
264
|
-
return r < s.arrowMinOffsetFromTooltipCorner - s.tooltipBorderWidth ? s.arrowMinOffsetFromTooltipCorner - s.tooltipBorderWidth :
|
|
264
|
+
return r < s.arrowMinOffsetFromTooltipCorner - s.tooltipBorderWidth ? s.arrowMinOffsetFromTooltipCorner - s.tooltipBorderWidth : e.height - s.tooltipBorderWidth - s.arrowMinOffsetFromTooltipCorner - s.arrowSize * 2;
|
|
265
265
|
case "top":
|
|
266
266
|
case "bottom":
|
|
267
|
-
return r < s.arrowMinOffsetFromTooltipCorner - s.tooltipBorderWidth ? s.arrowMinOffsetFromTooltipCorner - s.tooltipBorderWidth :
|
|
267
|
+
return r < s.arrowMinOffsetFromTooltipCorner - s.tooltipBorderWidth ? s.arrowMinOffsetFromTooltipCorner - s.tooltipBorderWidth : e.width - s.tooltipBorderWidth - s.arrowMinOffsetFromTooltipCorner - s.arrowSize * 2;
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
|
-
function
|
|
271
|
-
var
|
|
272
|
-
const
|
|
273
|
-
|
|
270
|
+
function T(t) {
|
|
271
|
+
var r, s;
|
|
272
|
+
const e = (r = w[t]) == null ? void 0 : r.tooltipElement;
|
|
273
|
+
se(t), (s = e.querySelector(`.${G}`)) == null || s.remove(), e.style.left = "0", e.style.top = "0", e.remove();
|
|
274
274
|
}
|
|
275
|
-
function
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
for (const r of Object.values(
|
|
275
|
+
function F(t) {
|
|
276
|
+
const e = t.tooltipElement.dataset.uuid;
|
|
277
|
+
e && (T(e), delete w[e]);
|
|
278
|
+
for (const r of Object.values(t.mouseEnterEventControllers))
|
|
279
279
|
r.abort();
|
|
280
280
|
}
|
|
281
|
-
const
|
|
282
|
-
install: (
|
|
283
|
-
|
|
281
|
+
const He = {
|
|
282
|
+
install: (t, e = {}) => {
|
|
283
|
+
t.directive("tooltip", xe(e));
|
|
284
284
|
}
|
|
285
285
|
};
|
|
286
286
|
export {
|
|
287
|
-
|
|
287
|
+
He as default
|
|
288
288
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(v,T){typeof exports=="object"&&typeof module<"u"?module.exports=T(require("vue")):typeof define=="function"&&define.amd?define(["vue"],T):(v=typeof globalThis<"u"?globalThis:v||self,v.ZeroTooltip=T(v.Vue))})(this,function(v){"use strict";const T="";let O;const Q=new Uint8Array(16);function X(){if(!O&&(O=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!O))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return O(Q)}const h=[];for(let t=0;t<256;++t)h.push((t+256).toString(16).slice(1));function Y(t,e=0){return h[t[e+0]]+h[t[e+1]]+h[t[e+2]]+h[t[e+3]]+"-"+h[t[e+4]]+h[t[e+5]]+"-"+h[t[e+6]]+h[t[e+7]]+"-"+h[t[e+8]]+h[t[e+9]]+"-"+h[t[e+10]]+h[t[e+11]]+h[t[e+12]]+h[t[e+13]]+h[t[e+14]]+h[t[e+15]]}const M={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function b(t,e,r){if(M.randomUUID&&!e&&!t)return M.randomUUID();t=t||{};const s=t.random||(t.rng||X)();if(s[6]=s[6]&15|64,s[8]=s[8]&63|128,e){r=r||0;for(let o=0;o<16;++o)e[r+o]=s[o];return e}return Y(s)}function C(){let t=[];const e=(o,i)=>{if(r(o),t.length>0)for(const d of t)d.addEventListener("scroll",i);window.addEventListener("scroll",()=>{i(),s(i)})},r=o=>{let i=o;for(;i!==null&&i.tagName!=="HTML";){if(i.scrollHeight!==i.clientHeight){const d=window.getComputedStyle(i);(d.overflow==="auto"||d.overflow==="scroll")&&t.push(i)}i=i.parentElement}},s=o=>{if(t.length>0){for(const i of t)i.removeEventListener("scroll",o);t=[]}window.removeEventListener("scroll",o)};return{handleHideOnScroll:e}}function g(){let t=null,e=null;return{handleHideOnResize:(o,i)=>{t=new ResizeObserver(d=>{const n=d[0].target;if(e===null)e=o.getBoundingClientRect();else{const p=n.getBoundingClientRect();(p.left!==e.left||p.top!==e.top||p.width!==e.width||p.height!==e.height)&&i()}}),t.observe(o)},resetResizeReferences:()=>{t!==null&&t.disconnect(),t=null,e=null}}}const{handleHideOnScroll:ee}=C(),{handleHideOnResize:te,resetResizeReferences:re}=g(),l="zero-tooltip__container",z="zero-tooltip__text",W="zero-tooltip__arrow",x={left:["left","right","top","bottom"],top:["top","bottom","right","left"],right:["right","left","top","bottom"],bottom:["bottom","top","right","left"]},se="body",oe="top",ie=10,de=20,ne=100,pe=250,ue=0,S="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",V="zt-text-sm zt-text-white zt-whitespace-pre-wrap zt-break-words",he=5,we="zt-absolute zt-border-solid zt-border-[#495057]",me=6,ae=1,ce=!0,ve=0,Te=0,u={},Oe=t=>({created:(e,r,s)=>{const o=b();s.el.$_tooltip={uuid:o},f(r.value,t,r.arg,e,o),typeof r.value!="string"&&v.isReactive(r.value)&&v.watch(r.value,i=>{u[o]&&F(u[o]),f(i,t,r.arg,e,o)})},updated:(e,r,s)=>{const o=s.el.$_tooltip.uuid;u[o]&&F(u[o]),f(r.value,t,r.arg,e,o)},beforeUnmount:(e,r,s)=>{const o=s.el.$_tooltip.uuid;u[o]&&F(u[o])}});function f(t,e,r,s,o){let i=le(t,e,r);const d=ye(s,i,o);u[o]=d,s.matches(":hover")&&s.dispatchEvent(new Event("mouseenter"))}function le(t,e,r){var j,q,R,Z,N,G,J,K;let s=(e==null?void 0:e.appendTo)??se,o=xe(t),i=r??(e==null?void 0:e.defaultPosition)??oe,d={left:((j=e==null?void 0:e.positions)==null?void 0:j.left)??x.left,top:((q=e==null?void 0:e.positions)==null?void 0:q.top)??x.top,right:((R=e==null?void 0:e.positions)==null?void 0:R.right)??x.right,bottom:((Z=e==null?void 0:e.positions)==null?void 0:Z.bottom)??x.bottom},n=(e==null?void 0:e.offsetFromSource)??ie,p=(e==null?void 0:e.offsetFromViewport)??de,w=(e==null?void 0:e.minWidth)??ne,m=(e==null?void 0:e.maxWidth)??pe,a=(e==null?void 0:e.tooltipBorderWidth)??ue,c=l+" "+S+" "+((e==null?void 0:e.tooltipClasses)??""),D=z+" "+V+" "+((e==null?void 0:e.textClasses)??""),A=(e==null?void 0:e.arrowSize)??he,E=(e==null?void 0:e.arrowClasses)??"",$=(e==null?void 0:e.arrowMinOffsetFromTooltipCorner)??me,_=(e==null?void 0:e.zIndex)??ae,U=ce,P=(e==null?void 0:e.showDelay)??ve,k=(e==null?void 0:e.hideDelay)??Te;return typeof t!="string"&&(t.appendTo!==void 0&&(s=t.appendTo),r===void 0&&t.defaultPosition!==void 0&&(i=t.defaultPosition),((N=t.positions)==null?void 0:N.left)!==void 0&&(d.left=t.positions.left),((G=t.positions)==null?void 0:G.top)!==void 0&&(d.top=t.positions.top),((J=t.positions)==null?void 0:J.right)!==void 0&&(d.right=t.positions.right),((K=t.positions)==null?void 0:K.bottom)!==void 0&&(d.bottom=t.positions.bottom),t.offsetFromSource!==void 0&&(n=t.offsetFromSource),t.offsetFromViewport!==void 0&&(p=t.offsetFromViewport),t.minWidth!==void 0&&(w=t.minWidth),t.maxWidth!==void 0&&(m=t.maxWidth),t.tooltipBorderWidth!==void 0&&(a=t.tooltipBorderWidth),t.tooltipClasses!==void 0&&(c=l+" "+S+" "+t.tooltipClasses),t.textClasses!==void 0&&(D=z+" "+V+" "+t.textClasses),t.arrowSize!==void 0&&(A=t.arrowSize),t.arrowClasses!==void 0&&(E=t.arrowClasses),t.arrowMinOffsetFromTooltipCorner!==void 0&&($=t.arrowMinOffsetFromTooltipCorner),t.zIndex!==void 0&&(_=t.zIndex),t.show!==void 0&&(U=t.show),t.showDelay!==void 0&&(P=t.showDelay),t.hideDelay!==void 0&&(k=t.hideDelay)),{appendTo:s,tooltipText:o,tooltipPosition:i,tooltipPositions:d,tooltipOffsetFromSource:n,tooltipOffsetFromViewport:p,tooltipMinWidth:w,tooltipMaxWidth:m,tooltipBorderWidth:a,tooltipClasses:c,textClasses:D,arrowSize:A,arrowClasses:E,arrowMinOffsetFromTooltipCorner:$,zIndex:_,shouldShow:U,showDelay:P,hideDelay:k}}function xe(t){const e=typeof t=="string"?t:t.content;if(!e)throw new Error("Please enter valid tooltip value");return e}function ye(t,e,r){let s=t,o=fe(e.textClasses,e.tooltipText),i=Fe(e.tooltipClasses,e.tooltipBorderWidth);i.append(o),i.dataset.uuid=r;const d={currentInstanceId:Date.now(),isHoveringOverAnchorElement:!1,lastTooltipMouseLeaveTimestamp:Date.now()},n={anchorElementMouseEnter:new AbortController,anchorElementMouseLeave:new AbortController,tooltipElementMouseEnter:new AbortController,tooltipElementMouseLeave:new AbortController};return s.addEventListener("mouseenter",()=>B(s,e,i,r),{signal:n.anchorElementMouseEnter.signal}),s.addEventListener("mouseleave",()=>L(e,r),{signal:n.anchorElementMouseLeave.signal}),i.addEventListener("mouseenter",()=>B(s,e,i,r,{isTooltip:!0}),{signal:n.tooltipElementMouseEnter.signal}),i.addEventListener("mouseleave",()=>L(e,r,{isTooltip:!0}),{signal:n.tooltipElementMouseLeave.signal}),{anchorElement:s,tooltipConfig:e,tooltipElement:i,mouseEnterEventControllers:n,mouseEventState:d}}function fe(t,e){let r=document.createElement("p");return r.classList.add(...t.trim().split(" ")),r.innerHTML=e,r}function Fe(t,e){let r=document.createElement("div");return r.classList.add(...t.trim().split(" ")),r.style.borderWidth=`${e}px`,r}async function B(t,e,r,s,o){if(!e.shouldShow)return;let i=o!=null&&o.isTooltip?0:e.showDelay;const d=100;!(o!=null&&o.isTooltip)&&Date.now()-u[s].mouseEventState.lastTooltipMouseLeaveTimestamp<=d&&(i=0);const n=Date.now();if(u[s].mouseEventState.currentInstanceId=n,u[s].mouseEventState.isHoveringOverAnchorElement=!0,i>0&&(await new Promise(c=>setTimeout(c,e.showDelay)),!u[s].mouseEventState.isHoveringOverAnchorElement||u[s].mouseEventState.currentInstanceId!==n))return;const p=t.getBoundingClientRect(),w=document.querySelector(e.appendTo);w==null||w.appendChild(r);let m=!1,a=e.tooltipPosition;for(let c=0;c<4&&(a=e.tooltipPositions[e.tooltipPosition][c],a==="left"?m=Me(p,e,r):a==="top"?m=We(p,e,r):a==="right"?m=ze(p,e,r):a==="bottom"&&(m=Se(p,e,r)),!m);c++);m&&(Ve(p,a,e,r),r.style.opacity="1",r.style.zIndex=typeof e.zIndex=="string"?e.zIndex:e.zIndex.toString(),ee(t,()=>y(s)),te(t,()=>y(s)))}async function L(t,e,r){r!=null&&r.isTooltip&&(u[e].mouseEventState.lastTooltipMouseLeaveTimestamp=Date.now());const s=r!=null&&r.isTooltip?0:t.hideDelay,o=Date.now();u[e].mouseEventState.currentInstanceId=o,u[e].mouseEventState.isHoveringOverAnchorElement=!1,!(s>0&&(await new Promise(i=>setTimeout(i,t.hideDelay)),u[e].mouseEventState.isHoveringOverAnchorElement||u[e].mouseEventState.currentInstanceId!==o))&&y(e)}function Me(t,e,r){const s=Math.min(t.left-e.tooltipOffsetFromSource-e.tooltipOffsetFromViewport,e.tooltipMaxWidth),o=t.top>=e.tooltipOffsetFromViewport,i=window.innerHeight-t.bottom>=e.tooltipOffsetFromViewport;if(s<e.tooltipMinWidth||!o||!i)return!1;r.style.maxWidth=`${s}px`;const d=r.getBoundingClientRect();let n=t.top+t.height/2-d.height/2;n<e.tooltipOffsetFromViewport?n=e.tooltipOffsetFromViewport:n+d.height>window.innerHeight-e.tooltipOffsetFromViewport&&(n=window.innerHeight-e.tooltipOffsetFromViewport-d.height);const p=t.left-e.tooltipOffsetFromSource-d.width;return t.bottom<n+e.arrowMinOffsetFromTooltipCorner*2||t.top>n+d.height-e.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${n}px`,r.style.left=`${p}px`,!0)}function ze(t,e,r){const s=Math.min(window.innerWidth-(t.right+e.tooltipOffsetFromSource)-e.tooltipOffsetFromViewport,e.tooltipMaxWidth),o=t.top>=e.tooltipOffsetFromViewport,i=window.innerHeight-t.bottom>=e.tooltipOffsetFromViewport;if(s<e.tooltipMinWidth||!o||!i)return!1;r.style.maxWidth=`${s}px`;const d=r.getBoundingClientRect();let n=t.top+t.height/2-d.height/2;n<e.tooltipOffsetFromViewport?n=e.tooltipOffsetFromViewport:n+d.height>window.innerHeight-e.tooltipOffsetFromViewport&&(n=window.innerHeight-e.tooltipOffsetFromViewport-d.height);const p=t.right+e.tooltipOffsetFromSource;return t.bottom<n+e.arrowMinOffsetFromTooltipCorner*2||t.top>n+d.height-e.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${n}px`,r.style.left=`${p}px`,!0)}function We(t,e,r){const s=Math.min(window.innerWidth-e.tooltipOffsetFromViewport*2,e.tooltipMaxWidth);r.style.maxWidth=`${s}px`;const o=r.getBoundingClientRect();let i=t.top-e.tooltipOffsetFromSource-o.height;if(i<e.tooltipOffsetFromViewport)return!1;let d=t.left+t.width/2-o.width/2;return d<e.tooltipOffsetFromViewport?d=e.tooltipOffsetFromViewport:d+o.width>window.innerWidth-e.tooltipOffsetFromViewport&&(d=window.innerWidth-e.tooltipOffsetFromViewport-o.width),t.left>d+o.width-e.arrowMinOffsetFromTooltipCorner*2||t.right<d+e.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${i}px`,r.style.left=`${d}px`,!0)}function Se(t,e,r){const s=Math.min(window.innerWidth-e.tooltipOffsetFromViewport*2,e.tooltipMaxWidth);r.style.maxWidth=`${s}px`;const o=r.getBoundingClientRect();let i=t.bottom+e.tooltipOffsetFromSource;if(i+o.height>window.innerHeight-e.tooltipOffsetFromViewport)return!1;let d=t.left+t.width/2-o.width/2;return d<e.tooltipOffsetFromViewport?d=e.tooltipOffsetFromViewport:d+o.width>window.innerWidth-e.tooltipOffsetFromViewport&&(d=window.innerWidth-e.tooltipOffsetFromViewport-o.width),t.left>d+o.width-e.arrowMinOffsetFromTooltipCorner*2||t.right<d+e.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${i}px`,r.style.left=`${d}px`,!0)}function Ve(t,e,r,s){var c;const o=document.createElement("div"),i=s.getBoundingClientRect(),d=Math.sin(45*(180/Math.PI))*r.arrowSize,n=1;let p=0,w=0,m="";switch(e){case"left":m="!zt-border-y-transparent !zt-border-r-transparent",p=t.top-i.top+t.height/2-d-r.tooltipBorderWidth,w=i.width-r.tooltipBorderWidth-n;break;case"top":m="!zt-border-x-transparent !zt-border-b-transparent",p=i.height-r.tooltipBorderWidth-n,w=t.left-i.left+t.width/2-d-r.tooltipBorderWidth;break;case"right":m="!zt-border-y-transparent !zt-border-l-transparent",p=t.top-i.top+t.height/2-d-r.tooltipBorderWidth,w=-r.arrowSize*2-r.tooltipBorderWidth+n;break;case"bottom":m="!zt-border-x-transparent !zt-border-t-transparent",p=-r.arrowSize*2-r.tooltipBorderWidth+n,w=t.left-i.left+t.width/2-d-r.tooltipBorderWidth;break}e==="left"||e==="right"?H(e,i,p,r)||(p=I(e,i,p,r)):H(e,i,w,r)||(w=I(e,i,w,r));const a=W+" "+we+" "+m+" "+r.arrowClasses;o.classList.add(...a.trim().split(" ")),o.style.top=`${p}px`,o.style.left=`${w}px`,o.style.borderWidth=`${r.arrowSize}px`,(c=document.querySelector(`.${l}`))==null||c.appendChild(o)}function H(t,e,r,s){switch(t){case"left":case"right":return r>s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth&&r<e.height+s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2;case"top":case"bottom":return r>s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth&&r<e.width+s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2}}function I(t,e,r,s){switch(t){case"left":case"right":return r<s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth?s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth:e.height-s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2;case"top":case"bottom":return r<s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth?s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth:e.width-s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2}}function y(t){var s,o;const e=document.querySelector(`.${l}`),r=(s=u[t])==null?void 0:s.tooltipElement;r&&e&&e instanceof HTMLElement&&e===r&&(re(),(o=e.querySelector(`.${W}`))==null||o.remove(),e.style.left="0",e.style.top="0",e.remove())}function F(t){const e=t.tooltipElement.dataset.uuid;e&&(y(e),delete u[e]);for(const r of Object.values(t.mouseEnterEventControllers))r.abort()}return{install:(t,e={})=>{t.directive("tooltip",Oe(e))}}});
|
|
1
|
+
(function(v,T){typeof exports=="object"&&typeof module<"u"?module.exports=T(require("vue")):typeof define=="function"&&define.amd?define(["vue"],T):(v=typeof globalThis<"u"?globalThis:v||self,v.ZeroTooltip=T(v.Vue))})(this,function(v){"use strict";const T="";let O;const Q=new Uint8Array(16);function X(){if(!O&&(O=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!O))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return O(Q)}const u=[];for(let t=0;t<256;++t)u.push((t+256).toString(16).slice(1));function Y(t,e=0){return u[t[e+0]]+u[t[e+1]]+u[t[e+2]]+u[t[e+3]]+"-"+u[t[e+4]]+u[t[e+5]]+"-"+u[t[e+6]]+u[t[e+7]]+"-"+u[t[e+8]]+u[t[e+9]]+"-"+u[t[e+10]]+u[t[e+11]]+u[t[e+12]]+u[t[e+13]]+u[t[e+14]]+u[t[e+15]]}const M={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function b(t,e,r){if(M.randomUUID&&!e&&!t)return M.randomUUID();t=t||{};const s=t.random||(t.rng||X)();if(s[6]=s[6]&15|64,s[8]=s[8]&63|128,e){r=r||0;for(let o=0;o<16;++o)e[r+o]=s[o];return e}return Y(s)}function C(){let t=[];const e=(o,i)=>{if(r(o),t.length>0)for(const d of t)d.addEventListener("scroll",i);window.addEventListener("scroll",()=>{i(),s(i)})},r=o=>{let i=o;for(;i!==null&&i.tagName!=="HTML";){if(i.scrollHeight!==i.clientHeight){const d=window.getComputedStyle(i);(d.overflow==="auto"||d.overflow==="scroll")&&t.push(i)}i=i.parentElement}},s=o=>{if(t.length>0){for(const i of t)i.removeEventListener("scroll",o);t=[]}window.removeEventListener("scroll",o)};return{handleHideOnScroll:e}}function g(){const t={},e={};return{handleHideOnResize:(o,i,d)=>{let n=new ResizeObserver(p=>{const m=p[0].target;if(!e[o])e[o]=i.getBoundingClientRect();else{const h=m.getBoundingClientRect();(h.left!==e[o].left||h.top!==e[o].top||h.width!==e[o].width||h.height!==e[o].height)&&d()}});t[o]=n,n.observe(i)},resetResizeReferences:o=>{t[o]&&t[o].disconnect(),delete t[o],delete e[o]}}}const{handleHideOnScroll:ee}=C(),{handleHideOnResize:te,resetResizeReferences:re}=g(),z="zero-tooltip__container",W="zero-tooltip__text",S="zero-tooltip__arrow",x={left:["left","right","top","bottom"],top:["top","bottom","right","left"],right:["right","left","top","bottom"],bottom:["bottom","top","right","left"]},se="body",oe="top",ie=10,de=20,ne=100,pe=250,he=0,l="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",V="zt-text-sm zt-text-white zt-whitespace-pre-wrap zt-break-words",we=5,ue="zt-absolute zt-border-solid zt-border-[#495057]",me=6,ae=1,ce=!0,ve=0,Te=0,w={},Oe=t=>({created:(e,r,s)=>{const o=b();s.el.$_tooltip={uuid:o},F(r.value,t,r.arg,e,o),typeof r.value!="string"&&v.isReactive(r.value)&&v.watch(r.value,i=>{w[o]&&y(w[o]),F(i,t,r.arg,e,o)})},updated:(e,r,s)=>{const o=s.el.$_tooltip.uuid;w[o]&&y(w[o]),F(r.value,t,r.arg,e,o)},beforeUnmount:(e,r,s)=>{const o=s.el.$_tooltip.uuid;w[o]&&y(w[o])}});function F(t,e,r,s,o){let i=xe(t,e,r);const d=Fe(s,i,o);w[o]=d,s.matches(":hover")&&s.dispatchEvent(new Event("mouseenter"))}function xe(t,e,r){var U,R,q,Z,N,G,J,K;let s=(e==null?void 0:e.appendTo)??se,o=fe(t),i=r??(e==null?void 0:e.defaultPosition)??oe,d={left:((U=e==null?void 0:e.positions)==null?void 0:U.left)??x.left,top:((R=e==null?void 0:e.positions)==null?void 0:R.top)??x.top,right:((q=e==null?void 0:e.positions)==null?void 0:q.right)??x.right,bottom:((Z=e==null?void 0:e.positions)==null?void 0:Z.bottom)??x.bottom},n=(e==null?void 0:e.offsetFromSource)??ie,p=(e==null?void 0:e.offsetFromViewport)??de,m=(e==null?void 0:e.minWidth)??ne,h=(e==null?void 0:e.maxWidth)??pe,a=(e==null?void 0:e.tooltipBorderWidth)??he,c=z+" "+l+" "+((e==null?void 0:e.tooltipClasses)??""),A=W+" "+V+" "+((e==null?void 0:e.textClasses)??""),D=(e==null?void 0:e.arrowSize)??we,E=(e==null?void 0:e.arrowClasses)??"",$=(e==null?void 0:e.arrowMinOffsetFromTooltipCorner)??me,_=(e==null?void 0:e.zIndex)??ae,P=ce,k=(e==null?void 0:e.showDelay)??ve,j=(e==null?void 0:e.hideDelay)??Te;return typeof t!="string"&&(t.appendTo!==void 0&&(s=t.appendTo),r===void 0&&t.defaultPosition!==void 0&&(i=t.defaultPosition),((N=t.positions)==null?void 0:N.left)!==void 0&&(d.left=t.positions.left),((G=t.positions)==null?void 0:G.top)!==void 0&&(d.top=t.positions.top),((J=t.positions)==null?void 0:J.right)!==void 0&&(d.right=t.positions.right),((K=t.positions)==null?void 0:K.bottom)!==void 0&&(d.bottom=t.positions.bottom),t.offsetFromSource!==void 0&&(n=t.offsetFromSource),t.offsetFromViewport!==void 0&&(p=t.offsetFromViewport),t.minWidth!==void 0&&(m=t.minWidth),t.maxWidth!==void 0&&(h=t.maxWidth),t.tooltipBorderWidth!==void 0&&(a=t.tooltipBorderWidth),t.tooltipClasses!==void 0&&(c=z+" "+l+" "+t.tooltipClasses),t.textClasses!==void 0&&(A=W+" "+V+" "+t.textClasses),t.arrowSize!==void 0&&(D=t.arrowSize),t.arrowClasses!==void 0&&(E=t.arrowClasses),t.arrowMinOffsetFromTooltipCorner!==void 0&&($=t.arrowMinOffsetFromTooltipCorner),t.zIndex!==void 0&&(_=t.zIndex),t.show!==void 0&&(P=t.show),t.showDelay!==void 0&&(k=t.showDelay),t.hideDelay!==void 0&&(j=t.hideDelay)),{appendTo:s,tooltipText:o,tooltipPosition:i,tooltipPositions:d,tooltipOffsetFromSource:n,tooltipOffsetFromViewport:p,tooltipMinWidth:m,tooltipMaxWidth:h,tooltipBorderWidth:a,tooltipClasses:c,textClasses:A,arrowSize:D,arrowClasses:E,arrowMinOffsetFromTooltipCorner:$,zIndex:_,shouldShow:P,showDelay:k,hideDelay:j}}function fe(t){const e=typeof t=="string"?t:t.content;if(!e)throw new Error("Please enter valid tooltip value");return e}function Fe(t,e,r){let s=t,o=ye(e.textClasses,e.tooltipText),i=Me(e.tooltipClasses,e.tooltipBorderWidth);i.append(o),i.dataset.uuid=r;const d={currentInstanceId:Date.now(),isHoveringOverAnchorElement:!1,lastTooltipMouseLeaveTimestamp:0},n={anchorElementMouseEnter:new AbortController,anchorElementMouseLeave:new AbortController,tooltipElementMouseEnter:new AbortController,tooltipElementMouseLeave:new AbortController};return s.addEventListener("mouseenter",()=>B(s,e,i,r),{signal:n.anchorElementMouseEnter.signal}),s.addEventListener("mouseleave",()=>L(e,r),{signal:n.anchorElementMouseLeave.signal}),i.addEventListener("mouseenter",()=>B(s,e,i,r,{isTooltip:!0}),{signal:n.tooltipElementMouseEnter.signal}),i.addEventListener("mouseleave",()=>L(e,r,{isTooltip:!0}),{signal:n.tooltipElementMouseLeave.signal}),{anchorElement:s,tooltipConfig:e,tooltipElement:i,mouseEnterEventControllers:n,mouseEventState:d}}function ye(t,e){let r=document.createElement("p");return r.classList.add(...t.trim().split(" ")),r.innerHTML=e,r}function Me(t,e){let r=document.createElement("div");return r.classList.add(...t.trim().split(" ")),r.style.borderWidth=`${e}px`,r}async function B(t,e,r,s,o){if(!e.shouldShow)return;let i=o!=null&&o.isTooltip?0:e.showDelay;const d=100;!(o!=null&&o.isTooltip)&&Date.now()-w[s].mouseEventState.lastTooltipMouseLeaveTimestamp<=d&&(i=0);const n=Date.now();if(w[s].mouseEventState.currentInstanceId=n,w[s].mouseEventState.isHoveringOverAnchorElement=!0,i>0&&(await new Promise(c=>setTimeout(c,i)),!w[s].mouseEventState.isHoveringOverAnchorElement||w[s].mouseEventState.currentInstanceId!==n))return;const p=t.getBoundingClientRect(),m=document.querySelector(e.appendTo);m==null||m.appendChild(r);let h=!1,a=e.tooltipPosition;for(let c=0;c<4&&(a=e.tooltipPositions[e.tooltipPosition][c],a==="left"?h=ze(p,e,r):a==="top"?h=Se(p,e,r):a==="right"?h=We(p,e,r):a==="bottom"&&(h=le(p,e,r)),!h);c++);h&&(Ve(p,a,e,r),r.style.opacity="1",r.style.zIndex=typeof e.zIndex=="string"?e.zIndex:e.zIndex.toString(),ee(t,()=>f(s)),te(s,t,()=>f(s)))}async function L(t,e,r){r!=null&&r.isTooltip&&(w[e].mouseEventState.lastTooltipMouseLeaveTimestamp=Date.now());const s=Date.now();w[e].mouseEventState.currentInstanceId=s,w[e].mouseEventState.isHoveringOverAnchorElement=!1,!(t.hideDelay>0&&(await new Promise(o=>setTimeout(o,t.hideDelay)),w[e].mouseEventState.isHoveringOverAnchorElement||w[e].mouseEventState.currentInstanceId!==s))&&f(e)}function ze(t,e,r){const s=Math.min(t.left-e.tooltipOffsetFromSource-e.tooltipOffsetFromViewport,e.tooltipMaxWidth),o=t.top>=e.tooltipOffsetFromViewport,i=window.innerHeight-t.bottom>=e.tooltipOffsetFromViewport;if(s<e.tooltipMinWidth||!o||!i)return!1;r.style.maxWidth=`${s}px`;const d=r.getBoundingClientRect();let n=t.top+t.height/2-d.height/2;n<e.tooltipOffsetFromViewport?n=e.tooltipOffsetFromViewport:n+d.height>window.innerHeight-e.tooltipOffsetFromViewport&&(n=window.innerHeight-e.tooltipOffsetFromViewport-d.height);const p=t.left-e.tooltipOffsetFromSource-d.width;return t.bottom<n+e.arrowMinOffsetFromTooltipCorner*2||t.top>n+d.height-e.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${n}px`,r.style.left=`${p}px`,!0)}function We(t,e,r){const s=Math.min(window.innerWidth-(t.right+e.tooltipOffsetFromSource)-e.tooltipOffsetFromViewport,e.tooltipMaxWidth),o=t.top>=e.tooltipOffsetFromViewport,i=window.innerHeight-t.bottom>=e.tooltipOffsetFromViewport;if(s<e.tooltipMinWidth||!o||!i)return!1;r.style.maxWidth=`${s}px`;const d=r.getBoundingClientRect();let n=t.top+t.height/2-d.height/2;n<e.tooltipOffsetFromViewport?n=e.tooltipOffsetFromViewport:n+d.height>window.innerHeight-e.tooltipOffsetFromViewport&&(n=window.innerHeight-e.tooltipOffsetFromViewport-d.height);const p=t.right+e.tooltipOffsetFromSource;return t.bottom<n+e.arrowMinOffsetFromTooltipCorner*2||t.top>n+d.height-e.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${n}px`,r.style.left=`${p}px`,!0)}function Se(t,e,r){const s=Math.min(window.innerWidth-e.tooltipOffsetFromViewport*2,e.tooltipMaxWidth);r.style.maxWidth=`${s}px`;const o=r.getBoundingClientRect();let i=t.top-e.tooltipOffsetFromSource-o.height;if(i<e.tooltipOffsetFromViewport)return!1;let d=t.left+t.width/2-o.width/2;return d<e.tooltipOffsetFromViewport?d=e.tooltipOffsetFromViewport:d+o.width>window.innerWidth-e.tooltipOffsetFromViewport&&(d=window.innerWidth-e.tooltipOffsetFromViewport-o.width),t.left>d+o.width-e.arrowMinOffsetFromTooltipCorner*2||t.right<d+e.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${i}px`,r.style.left=`${d}px`,!0)}function le(t,e,r){const s=Math.min(window.innerWidth-e.tooltipOffsetFromViewport*2,e.tooltipMaxWidth);r.style.maxWidth=`${s}px`;const o=r.getBoundingClientRect();let i=t.bottom+e.tooltipOffsetFromSource;if(i+o.height>window.innerHeight-e.tooltipOffsetFromViewport)return!1;let d=t.left+t.width/2-o.width/2;return d<e.tooltipOffsetFromViewport?d=e.tooltipOffsetFromViewport:d+o.width>window.innerWidth-e.tooltipOffsetFromViewport&&(d=window.innerWidth-e.tooltipOffsetFromViewport-o.width),t.left>d+o.width-e.arrowMinOffsetFromTooltipCorner*2||t.right<d+e.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${i}px`,r.style.left=`${d}px`,!0)}function Ve(t,e,r,s){const o=document.createElement("div"),i=s.getBoundingClientRect(),d=Math.sin(45*(180/Math.PI))*r.arrowSize,n=1;let p=0,m=0,h="";switch(e){case"left":h="!zt-border-y-transparent !zt-border-r-transparent",p=t.top-i.top+t.height/2-d-r.tooltipBorderWidth,m=i.width-r.tooltipBorderWidth-n;break;case"top":h="!zt-border-x-transparent !zt-border-b-transparent",p=i.height-r.tooltipBorderWidth-n,m=t.left-i.left+t.width/2-d-r.tooltipBorderWidth;break;case"right":h="!zt-border-y-transparent !zt-border-l-transparent",p=t.top-i.top+t.height/2-d-r.tooltipBorderWidth,m=-r.arrowSize*2-r.tooltipBorderWidth+n;break;case"bottom":h="!zt-border-x-transparent !zt-border-t-transparent",p=-r.arrowSize*2-r.tooltipBorderWidth+n,m=t.left-i.left+t.width/2-d-r.tooltipBorderWidth;break}e==="left"||e==="right"?I(e,i,p,r)||(p=H(e,i,p,r)):I(e,i,m,r)||(m=H(e,i,m,r));const a=S+" "+ue+" "+h+" "+r.arrowClasses;o.classList.add(...a.trim().split(" ")),o.style.top=`${p}px`,o.style.left=`${m}px`,o.style.borderWidth=`${r.arrowSize}px`,s.appendChild(o)}function I(t,e,r,s){switch(t){case"left":case"right":return r>s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth&&r<e.height+s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2;case"top":case"bottom":return r>s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth&&r<e.width+s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2}}function H(t,e,r,s){switch(t){case"left":case"right":return r<s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth?s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth:e.height-s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2;case"top":case"bottom":return r<s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth?s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth:e.width-s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2}}function f(t){var r,s;const e=(r=w[t])==null?void 0:r.tooltipElement;re(t),(s=e.querySelector(`.${S}`))==null||s.remove(),e.style.left="0",e.style.top="0",e.remove()}function y(t){const e=t.tooltipElement.dataset.uuid;e&&(f(e),delete w[e]);for(const r of Object.values(t.mouseEnterEventControllers))r.abort()}return{install:(t,e={})=>{t.directive("tooltip",Oe(e))}}});
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"dist",
|
|
19
19
|
"src"
|
|
20
20
|
],
|
|
21
|
-
"version": "1.3.
|
|
21
|
+
"version": "1.3.2",
|
|
22
22
|
"type": "module",
|
|
23
23
|
"scripts": {
|
|
24
24
|
"dev": "vite",
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
"vite": "4.4.5",
|
|
37
37
|
"vite-plugin-dts": "3.5.3",
|
|
38
38
|
"vue": "^3.0.0",
|
|
39
|
-
"vue-tsc": "1.8.5"
|
|
39
|
+
"vue-tsc": "1.8.5",
|
|
40
|
+
"primevue": "3.53.0"
|
|
40
41
|
},
|
|
41
42
|
"repository": {
|
|
42
43
|
"type": "git",
|
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
export default function useHideOnResize() {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const anchorElementResizeObservers: Record<string, ResizeObserver> = {}
|
|
3
|
+
const anchorElementRects: Record<string, DOMRect> = {}
|
|
4
4
|
|
|
5
|
-
const handleHideOnResize = (anchorElement: HTMLElement, hideOverlay: () => void) => {
|
|
6
|
-
anchorElementResizeObserver = new ResizeObserver((entries) => {
|
|
5
|
+
const handleHideOnResize = (tooltipUuid: string, anchorElement: HTMLElement, hideOverlay: () => void) => {
|
|
6
|
+
let anchorElementResizeObserver = new ResizeObserver((entries) => {
|
|
7
7
|
const targetElement = entries[0].target
|
|
8
8
|
|
|
9
|
-
if (
|
|
9
|
+
if (!anchorElementRects[tooltipUuid]) {
|
|
10
10
|
// On initial trigger set initial values
|
|
11
|
-
|
|
11
|
+
anchorElementRects[tooltipUuid] = anchorElement.getBoundingClientRect()
|
|
12
12
|
} else {
|
|
13
13
|
const targetElementRect = targetElement.getBoundingClientRect()
|
|
14
14
|
|
|
15
15
|
// Check if anchor element has moved or resized
|
|
16
|
-
if (targetElementRect.left !==
|
|
17
|
-
|| targetElementRect.top !==
|
|
18
|
-
|| targetElementRect.width !==
|
|
19
|
-
|| targetElementRect.height !==
|
|
16
|
+
if (targetElementRect.left !== anchorElementRects[tooltipUuid].left
|
|
17
|
+
|| targetElementRect.top !== anchorElementRects[tooltipUuid].top
|
|
18
|
+
|| targetElementRect.width !== anchorElementRects[tooltipUuid].width
|
|
19
|
+
|| targetElementRect.height !== anchorElementRects[tooltipUuid].height) {
|
|
20
20
|
hideOverlay()
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
+
anchorElementResizeObservers[tooltipUuid] = anchorElementResizeObserver
|
|
26
|
+
|
|
25
27
|
anchorElementResizeObserver.observe(anchorElement)
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
const resetResizeReferences = () => {
|
|
29
|
-
if (
|
|
30
|
+
const resetResizeReferences = (tooltipUuid: string) => {
|
|
31
|
+
if (anchorElementResizeObservers[tooltipUuid]) anchorElementResizeObservers[tooltipUuid].disconnect()
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
delete anchorElementResizeObservers[tooltipUuid]
|
|
34
|
+
delete anchorElementRects[tooltipUuid]
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
return { handleHideOnResize, resetResizeReferences }
|
package/src/tooltip.ts
CHANGED
|
@@ -187,7 +187,7 @@ function initTooltip(targetElement: HTMLElement, tooltipConfig: ReturnType<typeo
|
|
|
187
187
|
const mouseEventState = {
|
|
188
188
|
currentInstanceId: Date.now(),
|
|
189
189
|
isHoveringOverAnchorElement: false,
|
|
190
|
-
lastTooltipMouseLeaveTimestamp:
|
|
190
|
+
lastTooltipMouseLeaveTimestamp: 0,
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
const mouseEnterEventControllers = {
|
|
@@ -250,7 +250,7 @@ async function onMouseEnter(
|
|
|
250
250
|
tooltips[uuid].mouseEventState.isHoveringOverAnchorElement = true
|
|
251
251
|
|
|
252
252
|
if (_showDelay > 0) {
|
|
253
|
-
await new Promise(resolve => setTimeout(resolve,
|
|
253
|
+
await new Promise(resolve => setTimeout(resolve, _showDelay))
|
|
254
254
|
|
|
255
255
|
if (!tooltips[uuid].mouseEventState.isHoveringOverAnchorElement || tooltips[uuid].mouseEventState.currentInstanceId !== currentInstanceId) return
|
|
256
256
|
}
|
|
@@ -287,7 +287,7 @@ async function onMouseEnter(
|
|
|
287
287
|
tooltipElement.style.zIndex = typeof(tooltipConfig.zIndex) === 'string' ? tooltipConfig.zIndex : tooltipConfig.zIndex.toString();
|
|
288
288
|
|
|
289
289
|
handleHideOnScroll(anchorElement, () => hideTooltip(uuid))
|
|
290
|
-
handleHideOnResize(anchorElement, () => hideTooltip(uuid))
|
|
290
|
+
handleHideOnResize(uuid, anchorElement, () => hideTooltip(uuid))
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
293
|
|
|
@@ -296,12 +296,11 @@ async function onMouseLeave(tooltipConfig: ReturnType<typeof getTooltipConfig>,
|
|
|
296
296
|
tooltips[uuid].mouseEventState.lastTooltipMouseLeaveTimestamp = Date.now()
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
-
const _hideDelay = options?.isTooltip ? 0 : tooltipConfig.hideDelay
|
|
300
299
|
const currentInstanceId = Date.now()
|
|
301
300
|
tooltips[uuid].mouseEventState.currentInstanceId = currentInstanceId
|
|
302
301
|
tooltips[uuid].mouseEventState.isHoveringOverAnchorElement = false
|
|
303
302
|
|
|
304
|
-
if (
|
|
303
|
+
if (tooltipConfig.hideDelay > 0) {
|
|
305
304
|
await new Promise(resolve => setTimeout(resolve, tooltipConfig.hideDelay))
|
|
306
305
|
|
|
307
306
|
if (tooltips[uuid].mouseEventState.isHoveringOverAnchorElement || tooltips[uuid].mouseEventState.currentInstanceId !== currentInstanceId) return
|
|
@@ -504,7 +503,7 @@ function drawArrow(anchorElementRect: DOMRect, currentTooltipPosition: TooltipPo
|
|
|
504
503
|
arrowElement.style.borderWidth = `${tooltipConfig.arrowSize}px`
|
|
505
504
|
|
|
506
505
|
// Mount Arrow element
|
|
507
|
-
|
|
506
|
+
tooltipElement.appendChild(arrowElement)
|
|
508
507
|
}
|
|
509
508
|
|
|
510
509
|
function isArrowPositionWithinLimits(currentTooltipPosition: TooltipPosition, tooltipElementRect: DOMRect, arrowPosition: number, tooltipConfig: ReturnType<typeof getTooltipConfig>) {
|
|
@@ -544,21 +543,18 @@ function getArrowPositionMinLimit(currentTooltipPosition: TooltipPosition, toolt
|
|
|
544
543
|
}
|
|
545
544
|
|
|
546
545
|
function hideTooltip(uuid: string) {
|
|
547
|
-
const
|
|
548
|
-
const currentTooltipElement = tooltips[uuid]?.tooltipElement
|
|
546
|
+
const tooltipElement = tooltips[uuid]?.tooltipElement
|
|
549
547
|
|
|
550
|
-
|
|
551
|
-
resetResizeReferences()
|
|
548
|
+
resetResizeReferences(uuid)
|
|
552
549
|
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
}
|
|
550
|
+
// Remove Arrow element from Tooltip, because it needs to be rebuilt every time Tooltip is showed again
|
|
551
|
+
tooltipElement.querySelector(`.${arrowElementClass}`)?.remove()
|
|
552
|
+
|
|
553
|
+
// Reset position so that old position does not effect new position (when zooming old position could be off screen)
|
|
554
|
+
tooltipElement.style.left = '0'
|
|
555
|
+
tooltipElement.style.top = '0'
|
|
556
|
+
|
|
557
|
+
tooltipElement.remove()
|
|
562
558
|
}
|
|
563
559
|
|
|
564
560
|
function destroyTooltip(tooltip: ReturnType<typeof initTooltip>) {
|