@versini/ui-tooltip 2.0.3 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1046 +1,160 @@
1
- import { jsxs as vt, jsx as _t } from "react/jsx-runtime";
2
- import { useRef as J, useEffect as gt, useState as ut, useCallback as dt } from "react";
3
- import Y from "clsx";
4
- const jt = "av-tooltip", Yt = "av-tooltip-arrow", Q = Math.min, K = Math.max, it = Math.round, D = (t) => ({
5
- x: t,
6
- y: t
7
- }), zt = {
8
- left: "right",
9
- right: "left",
10
- bottom: "top",
11
- top: "bottom"
12
- }, Xt = {
13
- start: "end",
14
- end: "start"
15
- };
16
- function mt(t, e, o) {
17
- return K(t, Q(e, o));
18
- }
19
- function tt(t, e) {
20
- return typeof t == "function" ? t(e) : t;
21
- }
22
- function X(t) {
23
- return t.split("-")[0];
24
- }
25
- function et(t) {
26
- return t.split("-")[1];
27
- }
28
- function kt(t) {
29
- return t === "x" ? "y" : "x";
30
- }
31
- function ht(t) {
32
- return t === "y" ? "height" : "width";
33
- }
34
- function z(t) {
35
- return ["top", "bottom"].includes(X(t)) ? "y" : "x";
36
- }
37
- function wt(t) {
38
- return kt(z(t));
39
- }
40
- function Kt(t, e, o) {
41
- o === void 0 && (o = !1);
42
- const n = et(t), i = wt(t), s = ht(i);
43
- let r = i === "x" ? n === (o ? "end" : "start") ? "right" : "left" : n === "start" ? "bottom" : "top";
44
- return e.reference[s] > e.floating[s] && (r = st(r)), [r, st(r)];
45
- }
46
- function Ut(t) {
47
- const e = st(t);
48
- return [pt(t), e, pt(e)];
49
- }
50
- function pt(t) {
51
- return t.replace(/start|end/g, (e) => Xt[e]);
52
- }
53
- function qt(t, e, o) {
54
- const n = ["left", "right"], i = ["right", "left"], s = ["top", "bottom"], r = ["bottom", "top"];
55
- switch (t) {
56
- case "top":
57
- case "bottom":
58
- return o ? e ? i : n : e ? n : i;
59
- case "left":
60
- case "right":
61
- return e ? s : r;
62
- default:
63
- return [];
64
- }
65
- }
66
- function Gt(t, e, o, n) {
67
- const i = et(t);
68
- let s = qt(X(t), o === "start", n);
69
- return i && (s = s.map((r) => r + "-" + i), e && (s = s.concat(s.map(pt)))), s;
70
- }
71
- function st(t) {
72
- return t.replace(/left|right|bottom|top/g, (e) => zt[e]);
73
- }
74
- function Jt(t) {
75
- return {
76
- top: 0,
77
- right: 0,
78
- bottom: 0,
79
- left: 0,
80
- ...t
81
- };
82
- }
83
- function St(t) {
84
- return typeof t != "number" ? Jt(t) : {
85
- top: t,
86
- right: t,
87
- bottom: t,
88
- left: t
89
- };
90
- }
91
- function rt(t) {
92
- const {
93
- x: e,
94
- y: o,
95
- width: n,
96
- height: i
97
- } = t;
98
- return {
99
- width: n,
100
- height: i,
101
- top: o,
102
- left: e,
103
- right: e + n,
104
- bottom: o + i,
105
- x: e,
106
- y: o
107
- };
108
- }
109
- function At(t, e, o) {
110
- let {
111
- reference: n,
112
- floating: i
113
- } = t;
114
- const s = z(e), r = wt(e), c = ht(r), l = X(e), a = s === "y", d = n.x + n.width / 2 - i.width / 2, f = n.y + n.height / 2 - i.height / 2, p = n[c] / 2 - i[c] / 2;
115
- let u;
116
- switch (l) {
117
- case "top":
118
- u = {
119
- x: d,
120
- y: n.y - i.height
121
- };
122
- break;
123
- case "bottom":
124
- u = {
125
- x: d,
126
- y: n.y + n.height
127
- };
128
- break;
129
- case "right":
130
- u = {
131
- x: n.x + n.width,
132
- y: f
133
- };
134
- break;
135
- case "left":
136
- u = {
137
- x: n.x - i.width,
138
- y: f
139
- };
140
- break;
141
- default:
142
- u = {
143
- x: n.x,
144
- y: n.y
145
- };
146
- }
147
- switch (et(e)) {
148
- case "start":
149
- u[r] -= p * (o && a ? -1 : 1);
150
- break;
151
- case "end":
152
- u[r] += p * (o && a ? -1 : 1);
153
- break;
154
- }
155
- return u;
156
- }
157
- const Qt = async (t, e, o) => {
158
- const {
159
- placement: n = "bottom",
160
- strategy: i = "absolute",
161
- middleware: s = [],
162
- platform: r
163
- } = o, c = s.filter(Boolean), l = await (r.isRTL == null ? void 0 : r.isRTL(e));
164
- let a = await r.getElementRects({
165
- reference: t,
166
- floating: e,
167
- strategy: i
168
- }), {
169
- x: d,
170
- y: f
171
- } = At(a, n, l), p = n, u = {}, m = 0;
172
- for (let g = 0; g < c.length; g++) {
173
- const {
174
- name: h,
175
- fn: w
176
- } = c[g], {
177
- x,
178
- y,
179
- data: v,
180
- reset: b
181
- } = await w({
182
- x: d,
183
- y: f,
184
- initialPlacement: n,
185
- placement: p,
186
- strategy: i,
187
- middlewareData: u,
188
- rects: a,
189
- platform: r,
190
- elements: {
191
- reference: t,
192
- floating: e
193
- }
194
- });
195
- d = x ?? d, f = y ?? f, u = {
196
- ...u,
197
- [h]: {
198
- ...u[h],
199
- ...v
200
- }
201
- }, b && m <= 50 && (m++, typeof b == "object" && (b.placement && (p = b.placement), b.rects && (a = b.rects === !0 ? await r.getElementRects({
202
- reference: t,
203
- floating: e,
204
- strategy: i
205
- }) : b.rects), {
206
- x: d,
207
- y: f
208
- } = At(a, p, l)), g = -1);
209
- }
210
- return {
211
- x: d,
212
- y: f,
213
- placement: p,
214
- strategy: i,
215
- middlewareData: u
216
- };
217
- };
218
- async function Pt(t, e) {
219
- var o;
220
- e === void 0 && (e = {});
221
- const {
222
- x: n,
223
- y: i,
224
- platform: s,
225
- rects: r,
226
- elements: c,
227
- strategy: l
228
- } = t, {
229
- boundary: a = "clippingAncestors",
230
- rootBoundary: d = "viewport",
231
- elementContext: f = "floating",
232
- altBoundary: p = !1,
233
- padding: u = 0
234
- } = tt(e, t), m = St(u), h = c[p ? f === "floating" ? "reference" : "floating" : f], w = rt(await s.getClippingRect({
235
- element: (o = await (s.isElement == null ? void 0 : s.isElement(h))) == null || o ? h : h.contextElement || await (s.getDocumentElement == null ? void 0 : s.getDocumentElement(c.floating)),
236
- boundary: a,
237
- rootBoundary: d,
238
- strategy: l
239
- })), x = f === "floating" ? {
240
- x: n,
241
- y: i,
242
- width: r.floating.width,
243
- height: r.floating.height
244
- } : r.reference, y = await (s.getOffsetParent == null ? void 0 : s.getOffsetParent(c.floating)), v = await (s.isElement == null ? void 0 : s.isElement(y)) ? await (s.getScale == null ? void 0 : s.getScale(y)) || {
245
- x: 1,
246
- y: 1
247
- } : {
248
- x: 1,
249
- y: 1
250
- }, b = rt(s.convertOffsetParentRelativeRectToViewportRelativeRect ? await s.convertOffsetParentRelativeRectToViewportRelativeRect({
251
- elements: c,
252
- rect: x,
253
- offsetParent: y,
254
- strategy: l
255
- }) : x);
256
- return {
257
- top: (w.top - b.top + m.top) / v.y,
258
- bottom: (b.bottom - w.bottom + m.bottom) / v.y,
259
- left: (w.left - b.left + m.left) / v.x,
260
- right: (b.right - w.right + m.right) / v.x
261
- };
262
- }
263
- const Zt = (t) => ({
264
- name: "arrow",
265
- options: t,
266
- async fn(e) {
267
- const {
268
- x: o,
269
- y: n,
270
- placement: i,
271
- rects: s,
272
- platform: r,
273
- elements: c,
274
- middlewareData: l
275
- } = e, {
276
- element: a,
277
- padding: d = 0
278
- } = tt(t, e) || {};
279
- if (a == null)
280
- return {};
281
- const f = St(d), p = {
282
- x: o,
283
- y: n
284
- }, u = wt(i), m = ht(u), g = await r.getDimensions(a), h = u === "y", w = h ? "top" : "left", x = h ? "bottom" : "right", y = h ? "clientHeight" : "clientWidth", v = s.reference[m] + s.reference[u] - p[u] - s.floating[m], b = p[u] - s.reference[u], M = await (r.getOffsetParent == null ? void 0 : r.getOffsetParent(a));
285
- let E = M ? M[y] : 0;
286
- (!E || !await (r.isElement == null ? void 0 : r.isElement(M))) && (E = c.floating[y] || s.floating[m]);
287
- const V = v / 2 - b / 2, k = E / 2 - g[m] / 2 - 1, T = Q(f[w], k), I = Q(f[x], k), S = T, _ = E - g[m] - I, C = E / 2 - g[m] / 2 + V, O = mt(S, C, _), j = !l.arrow && et(i) != null && C !== O && s.reference[m] / 2 - (C < S ? T : I) - g[m] / 2 < 0, B = j ? C < S ? C - S : C - _ : 0;
288
- return {
289
- [u]: p[u] + B,
290
- data: {
291
- [u]: O,
292
- centerOffset: C - O - B,
293
- ...j && {
294
- alignmentOffset: B
295
- }
296
- },
297
- reset: j
298
- };
299
- }
300
- }), te = function(t) {
301
- return t === void 0 && (t = {}), {
302
- name: "flip",
303
- options: t,
304
- async fn(e) {
305
- var o, n;
306
- const {
307
- placement: i,
308
- middlewareData: s,
309
- rects: r,
310
- initialPlacement: c,
311
- platform: l,
312
- elements: a
313
- } = e, {
314
- mainAxis: d = !0,
315
- crossAxis: f = !0,
316
- fallbackPlacements: p,
317
- fallbackStrategy: u = "bestFit",
318
- fallbackAxisSideDirection: m = "none",
319
- flipAlignment: g = !0,
320
- ...h
321
- } = tt(t, e);
322
- if ((o = s.arrow) != null && o.alignmentOffset)
323
- return {};
324
- const w = X(i), x = z(c), y = X(c) === c, v = await (l.isRTL == null ? void 0 : l.isRTL(a.floating)), b = p || (y || !g ? [st(c)] : Ut(c)), M = m !== "none";
325
- !p && M && b.push(...Gt(c, g, m, v));
326
- const E = [c, ...b], V = await Pt(e, h), k = [];
327
- let T = ((n = s.flip) == null ? void 0 : n.overflows) || [];
328
- if (d && k.push(V[w]), f) {
329
- const O = Kt(i, r, v);
330
- k.push(V[O[0]], V[O[1]]);
331
- }
332
- if (T = [...T, {
333
- placement: i,
334
- overflows: k
335
- }], !k.every((O) => O <= 0)) {
336
- var I, S;
337
- const O = (((I = s.flip) == null ? void 0 : I.index) || 0) + 1, j = E[O];
338
- if (j) {
339
- var _;
340
- const W = f === "alignment" ? x !== z(j) : !1, P = ((_ = T[0]) == null ? void 0 : _.overflows[0]) > 0;
341
- if (!W || P)
342
- return {
343
- data: {
344
- index: O,
345
- overflows: T
346
- },
347
- reset: {
348
- placement: j
349
- }
350
- };
351
- }
352
- let B = (S = T.filter((W) => W.overflows[0] <= 0).sort((W, P) => W.overflows[1] - P.overflows[1])[0]) == null ? void 0 : S.placement;
353
- if (!B)
354
- switch (u) {
355
- case "bestFit": {
356
- var C;
357
- const W = (C = T.filter((P) => {
358
- if (M) {
359
- const $ = z(P.placement);
360
- return $ === x || // Create a bias to the `y` side axis due to horizontal
361
- // reading directions favoring greater width.
362
- $ === "y";
363
- }
364
- return !0;
365
- }).map((P) => [P.placement, P.overflows.filter(($) => $ > 0).reduce(($, It) => $ + It, 0)]).sort((P, $) => P[1] - $[1])[0]) == null ? void 0 : C[0];
366
- W && (B = W);
367
- break;
368
- }
369
- case "initialPlacement":
370
- B = c;
371
- break;
372
- }
373
- if (i !== B)
374
- return {
375
- reset: {
376
- placement: B
377
- }
378
- };
379
- }
380
- return {};
381
- }
382
- };
383
- };
384
- async function ee(t, e) {
385
- const {
386
- placement: o,
387
- platform: n,
388
- elements: i
389
- } = t, s = await (n.isRTL == null ? void 0 : n.isRTL(i.floating)), r = X(o), c = et(o), l = z(o) === "y", a = ["left", "top"].includes(r) ? -1 : 1, d = s && l ? -1 : 1, f = tt(e, t);
390
- let {
391
- mainAxis: p,
392
- crossAxis: u,
393
- alignmentAxis: m
394
- } = typeof f == "number" ? {
395
- mainAxis: f,
396
- crossAxis: 0,
397
- alignmentAxis: null
398
- } : {
399
- mainAxis: f.mainAxis || 0,
400
- crossAxis: f.crossAxis || 0,
401
- alignmentAxis: f.alignmentAxis
402
- };
403
- return c && typeof m == "number" && (u = c === "end" ? m * -1 : m), l ? {
404
- x: u * d,
405
- y: p * a
406
- } : {
407
- x: p * a,
408
- y: u * d
409
- };
410
- }
411
- const ne = function(t) {
412
- return t === void 0 && (t = 0), {
413
- name: "offset",
414
- options: t,
415
- async fn(e) {
416
- var o, n;
417
- const {
418
- x: i,
419
- y: s,
420
- placement: r,
421
- middlewareData: c
422
- } = e, l = await ee(e, t);
423
- return r === ((o = c.offset) == null ? void 0 : o.placement) && (n = c.arrow) != null && n.alignmentOffset ? {} : {
424
- x: i + l.x,
425
- y: s + l.y,
426
- data: {
427
- ...l,
428
- placement: r
429
- }
430
- };
431
- }
432
- };
433
- }, oe = function(t) {
434
- return t === void 0 && (t = {}), {
435
- name: "shift",
436
- options: t,
437
- async fn(e) {
438
- const {
439
- x: o,
440
- y: n,
441
- placement: i
442
- } = e, {
443
- mainAxis: s = !0,
444
- crossAxis: r = !1,
445
- limiter: c = {
446
- fn: (h) => {
447
- let {
448
- x: w,
449
- y: x
450
- } = h;
451
- return {
452
- x: w,
453
- y: x
454
- };
455
- }
456
- },
457
- ...l
458
- } = tt(t, e), a = {
459
- x: o,
460
- y: n
461
- }, d = await Pt(e, l), f = z(X(i)), p = kt(f);
462
- let u = a[p], m = a[f];
463
- if (s) {
464
- const h = p === "y" ? "top" : "left", w = p === "y" ? "bottom" : "right", x = u + d[h], y = u - d[w];
465
- u = mt(x, u, y);
466
- }
467
- if (r) {
468
- const h = f === "y" ? "top" : "left", w = f === "y" ? "bottom" : "right", x = m + d[h], y = m - d[w];
469
- m = mt(x, m, y);
470
- }
471
- const g = c.fn({
472
- ...e,
473
- [p]: u,
474
- [f]: m
475
- });
476
- return {
477
- ...g,
478
- data: {
479
- x: g.x - o,
480
- y: g.y - n,
481
- enabled: {
482
- [p]: s,
483
- [f]: r
484
- }
485
- }
486
- };
487
- }
488
- };
489
- };
490
- function ct() {
491
- return typeof window < "u";
492
- }
493
- function G(t) {
494
- return Dt(t) ? (t.nodeName || "").toLowerCase() : "#document";
495
- }
496
- function A(t) {
497
- var e;
498
- return (t == null || (e = t.ownerDocument) == null ? void 0 : e.defaultView) || window;
499
- }
500
- function F(t) {
501
- var e;
502
- return (e = (Dt(t) ? t.ownerDocument : t.document) || window.document) == null ? void 0 : e.documentElement;
503
- }
504
- function Dt(t) {
505
- return ct() ? t instanceof Node || t instanceof A(t).Node : !1;
506
- }
507
- function R(t) {
508
- return ct() ? t instanceof Element || t instanceof A(t).Element : !1;
509
- }
510
- function N(t) {
511
- return ct() ? t instanceof HTMLElement || t instanceof A(t).HTMLElement : !1;
512
- }
513
- function Ct(t) {
514
- return !ct() || typeof ShadowRoot > "u" ? !1 : t instanceof ShadowRoot || t instanceof A(t).ShadowRoot;
515
- }
516
- function nt(t) {
517
- const {
518
- overflow: e,
519
- overflowX: o,
520
- overflowY: n,
521
- display: i
522
- } = L(t);
523
- return /auto|scroll|overlay|hidden|clip/.test(e + n + o) && !["inline", "contents"].includes(i);
524
- }
525
- function ie(t) {
526
- return ["table", "td", "th"].includes(G(t));
527
- }
528
- function lt(t) {
529
- return [":popover-open", ":modal"].some((e) => {
530
- try {
531
- return t.matches(e);
532
- } catch {
533
- return !1;
534
- }
535
- });
536
- }
537
- function xt(t) {
538
- const e = yt(), o = R(t) ? L(t) : t;
539
- return ["transform", "translate", "scale", "rotate", "perspective"].some((n) => o[n] ? o[n] !== "none" : !1) || (o.containerType ? o.containerType !== "normal" : !1) || !e && (o.backdropFilter ? o.backdropFilter !== "none" : !1) || !e && (o.filter ? o.filter !== "none" : !1) || ["transform", "translate", "scale", "rotate", "perspective", "filter"].some((n) => (o.willChange || "").includes(n)) || ["paint", "layout", "strict", "content"].some((n) => (o.contain || "").includes(n));
540
- }
541
- function se(t) {
542
- let e = H(t);
543
- for (; N(e) && !q(e); ) {
544
- if (xt(e))
545
- return e;
546
- if (lt(e))
547
- return null;
548
- e = H(e);
549
- }
550
- return null;
551
- }
552
- function yt() {
553
- return typeof CSS > "u" || !CSS.supports ? !1 : CSS.supports("-webkit-backdrop-filter", "none");
554
- }
555
- function q(t) {
556
- return ["html", "body", "#document"].includes(G(t));
557
- }
558
- function L(t) {
559
- return A(t).getComputedStyle(t);
560
- }
561
- function at(t) {
562
- return R(t) ? {
563
- scrollLeft: t.scrollLeft,
564
- scrollTop: t.scrollTop
565
- } : {
566
- scrollLeft: t.scrollX,
567
- scrollTop: t.scrollY
568
- };
569
- }
570
- function H(t) {
571
- if (G(t) === "html")
572
- return t;
573
- const e = (
574
- // Step into the shadow DOM of the parent of a slotted node.
575
- t.assignedSlot || // DOM Element detected.
576
- t.parentNode || // ShadowRoot detected.
577
- Ct(t) && t.host || // Fallback.
578
- F(t)
579
- );
580
- return Ct(e) ? e.host : e;
581
- }
582
- function Nt(t) {
583
- const e = H(t);
584
- return q(e) ? t.ownerDocument ? t.ownerDocument.body : t.body : N(e) && nt(e) ? e : Nt(e);
585
- }
586
- function Mt(t, e, o) {
587
- var n;
588
- e === void 0 && (e = []);
589
- const i = Nt(t), s = i === ((n = t.ownerDocument) == null ? void 0 : n.body), r = A(i);
590
- return s ? e.concat(r, r.visualViewport || [], nt(i) ? i : [], []) : e.concat(i, Mt(i, []));
591
- }
592
- function Tt(t) {
593
- return t.parent && Object.getPrototypeOf(t.parent) ? t.frameElement : null;
594
- }
595
- function Bt(t) {
596
- const e = L(t);
597
- let o = parseFloat(e.width) || 0, n = parseFloat(e.height) || 0;
598
- const i = N(t), s = i ? t.offsetWidth : o, r = i ? t.offsetHeight : n, c = it(o) !== s || it(n) !== r;
599
- return c && (o = s, n = r), {
600
- width: o,
601
- height: n,
602
- $: c
603
- };
604
- }
605
- function Ft(t) {
606
- return R(t) ? t : t.contextElement;
607
- }
608
- function U(t) {
609
- const e = Ft(t);
610
- if (!N(e))
611
- return D(1);
612
- const o = e.getBoundingClientRect(), {
613
- width: n,
614
- height: i,
615
- $: s
616
- } = Bt(e);
617
- let r = (s ? it(o.width) : o.width) / n, c = (s ? it(o.height) : o.height) / i;
618
- return (!r || !Number.isFinite(r)) && (r = 1), (!c || !Number.isFinite(c)) && (c = 1), {
619
- x: r,
620
- y: c
621
- };
622
- }
623
- const re = /* @__PURE__ */ D(0);
624
- function Vt(t) {
625
- const e = A(t);
626
- return !yt() || !e.visualViewport ? re : {
627
- x: e.visualViewport.offsetLeft,
628
- y: e.visualViewport.offsetTop
629
- };
630
- }
631
- function ce(t, e, o) {
632
- return e === void 0 && (e = !1), !o || e && o !== A(t) ? !1 : e;
633
- }
634
- function Z(t, e, o, n) {
635
- e === void 0 && (e = !1), o === void 0 && (o = !1);
636
- const i = t.getBoundingClientRect(), s = Ft(t);
637
- let r = D(1);
638
- e && (n ? R(n) && (r = U(n)) : r = U(t));
639
- const c = ce(s, o, n) ? Vt(s) : D(0);
640
- let l = (i.left + c.x) / r.x, a = (i.top + c.y) / r.y, d = i.width / r.x, f = i.height / r.y;
641
- if (s) {
642
- const p = A(s), u = n && R(n) ? A(n) : n;
643
- let m = p, g = Tt(m);
644
- for (; g && n && u !== m; ) {
645
- const h = U(g), w = g.getBoundingClientRect(), x = L(g), y = w.left + (g.clientLeft + parseFloat(x.paddingLeft)) * h.x, v = w.top + (g.clientTop + parseFloat(x.paddingTop)) * h.y;
646
- l *= h.x, a *= h.y, d *= h.x, f *= h.y, l += y, a += v, m = A(g), g = Tt(m);
647
- }
648
- }
649
- return rt({
650
- width: d,
651
- height: f,
652
- x: l,
653
- y: a
654
- });
655
- }
656
- function bt(t, e) {
657
- const o = at(t).scrollLeft;
658
- return e ? e.left + o : Z(F(t)).left + o;
659
- }
660
- function Wt(t, e, o) {
661
- o === void 0 && (o = !1);
662
- const n = t.getBoundingClientRect(), i = n.left + e.scrollLeft - (o ? 0 : (
663
- // RTL <body> scrollbar.
664
- bt(t, n)
665
- )), s = n.top + e.scrollTop;
666
- return {
667
- x: i,
668
- y: s
669
- };
670
- }
671
- function le(t) {
672
- let {
673
- elements: e,
674
- rect: o,
675
- offsetParent: n,
676
- strategy: i
677
- } = t;
678
- const s = i === "fixed", r = F(n), c = e ? lt(e.floating) : !1;
679
- if (n === r || c && s)
680
- return o;
681
- let l = {
682
- scrollLeft: 0,
683
- scrollTop: 0
684
- }, a = D(1);
685
- const d = D(0), f = N(n);
686
- if ((f || !f && !s) && ((G(n) !== "body" || nt(r)) && (l = at(n)), N(n))) {
687
- const u = Z(n);
688
- a = U(n), d.x = u.x + n.clientLeft, d.y = u.y + n.clientTop;
689
- }
690
- const p = r && !f && !s ? Wt(r, l, !0) : D(0);
691
- return {
692
- width: o.width * a.x,
693
- height: o.height * a.y,
694
- x: o.x * a.x - l.scrollLeft * a.x + d.x + p.x,
695
- y: o.y * a.y - l.scrollTop * a.y + d.y + p.y
696
- };
697
- }
698
- function ae(t) {
699
- return Array.from(t.getClientRects());
700
- }
701
- function fe(t) {
702
- const e = F(t), o = at(t), n = t.ownerDocument.body, i = K(e.scrollWidth, e.clientWidth, n.scrollWidth, n.clientWidth), s = K(e.scrollHeight, e.clientHeight, n.scrollHeight, n.clientHeight);
703
- let r = -o.scrollLeft + bt(t);
704
- const c = -o.scrollTop;
705
- return L(n).direction === "rtl" && (r += K(e.clientWidth, n.clientWidth) - i), {
706
- width: i,
707
- height: s,
708
- x: r,
709
- y: c
710
- };
711
- }
712
- function ue(t, e) {
713
- const o = A(t), n = F(t), i = o.visualViewport;
714
- let s = n.clientWidth, r = n.clientHeight, c = 0, l = 0;
715
- if (i) {
716
- s = i.width, r = i.height;
717
- const a = yt();
718
- (!a || a && e === "fixed") && (c = i.offsetLeft, l = i.offsetTop);
719
- }
720
- return {
721
- width: s,
722
- height: r,
723
- x: c,
724
- y: l
725
- };
726
- }
727
- function de(t, e) {
728
- const o = Z(t, !0, e === "fixed"), n = o.top + t.clientTop, i = o.left + t.clientLeft, s = N(t) ? U(t) : D(1), r = t.clientWidth * s.x, c = t.clientHeight * s.y, l = i * s.x, a = n * s.y;
729
- return {
730
- width: r,
731
- height: c,
732
- x: l,
733
- y: a
734
- };
735
- }
736
- function Ot(t, e, o) {
737
- let n;
738
- if (e === "viewport")
739
- n = ue(t, o);
740
- else if (e === "document")
741
- n = fe(F(t));
742
- else if (R(e))
743
- n = de(e, o);
744
- else {
745
- const i = Vt(t);
746
- n = {
747
- x: e.x - i.x,
748
- y: e.y - i.y,
749
- width: e.width,
750
- height: e.height
1
+ import { jsxs as O, jsx as z } from "react/jsx-runtime";
2
+ import { computePosition as F, offset as H, flip as U, shift as V, arrow as W } from "@floating-ui/react";
3
+ import { useRef as f, useEffect as T, useState as w, useCallback as x } from "react";
4
+ import p from "clsx";
5
+ const Y = "av-tooltip", q = "av-tooltip-arrow", I = ["mousedown", "touchstart"];
6
+ function G(t, n, s) {
7
+ const a = f(null);
8
+ return T(() => {
9
+ const r = (e) => {
10
+ const o = e ? e.target : void 0;
11
+ if (Array.isArray(s)) {
12
+ const l = !document.body.contains(o) && o.tagName !== "HTML";
13
+ s.every(
14
+ (c) => !!c && !e.composedPath().includes(c)
15
+ ) && !l && t();
16
+ } else a.current && !a.current.contains(o) && t();
751
17
  };
752
- }
753
- return rt(n);
754
- }
755
- function $t(t, e) {
756
- const o = H(t);
757
- return o === e || !R(o) || q(o) ? !1 : L(o).position === "fixed" || $t(o, e);
758
- }
759
- function me(t, e) {
760
- const o = e.get(t);
761
- if (o)
762
- return o;
763
- let n = Mt(t, []).filter((c) => R(c) && G(c) !== "body"), i = null;
764
- const s = L(t).position === "fixed";
765
- let r = s ? H(t) : t;
766
- for (; R(r) && !q(r); ) {
767
- const c = L(r), l = xt(r);
768
- !l && c.position === "fixed" && (i = null), (s ? !l && !i : !l && c.position === "static" && !!i && ["absolute", "fixed"].includes(i.position) || nt(r) && !l && $t(t, r)) ? n = n.filter((d) => d !== r) : i = c, r = H(r);
769
- }
770
- return e.set(t, n), n;
771
- }
772
- function pe(t) {
773
- let {
774
- element: e,
775
- boundary: o,
776
- rootBoundary: n,
777
- strategy: i
778
- } = t;
779
- const r = [...o === "clippingAncestors" ? lt(e) ? [] : me(e, this._c) : [].concat(o), n], c = r[0], l = r.reduce((a, d) => {
780
- const f = Ot(e, d, i);
781
- return a.top = K(f.top, a.top), a.right = Q(f.right, a.right), a.bottom = Q(f.bottom, a.bottom), a.left = K(f.left, a.left), a;
782
- }, Ot(e, c, i));
783
- return {
784
- width: l.right - l.left,
785
- height: l.bottom - l.top,
786
- x: l.left,
787
- y: l.top
788
- };
789
- }
790
- function ge(t) {
791
- const {
792
- width: e,
793
- height: o
794
- } = Bt(t);
795
- return {
796
- width: e,
797
- height: o
798
- };
799
- }
800
- function he(t, e, o) {
801
- const n = N(e), i = F(e), s = o === "fixed", r = Z(t, !0, s, e);
802
- let c = {
803
- scrollLeft: 0,
804
- scrollTop: 0
805
- };
806
- const l = D(0);
807
- function a() {
808
- l.x = bt(i);
809
- }
810
- if (n || !n && !s)
811
- if ((G(e) !== "body" || nt(i)) && (c = at(e)), n) {
812
- const u = Z(e, !0, s, e);
813
- l.x = u.x + e.clientLeft, l.y = u.y + e.clientTop;
814
- } else i && a();
815
- s && !n && i && a();
816
- const d = i && !n && !s ? Wt(i, c) : D(0), f = r.left + c.scrollLeft - l.x - d.x, p = r.top + c.scrollTop - l.y - d.y;
817
- return {
818
- x: f,
819
- y: p,
820
- width: r.width,
821
- height: r.height
822
- };
823
- }
824
- function ft(t) {
825
- return L(t).position === "static";
826
- }
827
- function Rt(t, e) {
828
- if (!N(t) || L(t).position === "fixed")
829
- return null;
830
- if (e)
831
- return e(t);
832
- let o = t.offsetParent;
833
- return F(t) === o && (o = o.ownerDocument.body), o;
834
- }
835
- function Ht(t, e) {
836
- const o = A(t);
837
- if (lt(t))
838
- return o;
839
- if (!N(t)) {
840
- let i = H(t);
841
- for (; i && !q(i); ) {
842
- if (R(i) && !ft(i))
843
- return i;
844
- i = H(i);
845
- }
846
- return o;
847
- }
848
- let n = Rt(t, e);
849
- for (; n && ie(n) && ft(n); )
850
- n = Rt(n, e);
851
- return n && q(n) && ft(n) && !xt(n) ? o : n || se(t) || o;
852
- }
853
- const we = async function(t) {
854
- const e = this.getOffsetParent || Ht, o = this.getDimensions, n = await o(t.floating);
855
- return {
856
- reference: he(t.reference, await e(t.floating), t.strategy),
857
- floating: {
858
- x: 0,
859
- y: 0,
860
- width: n.width,
861
- height: n.height
862
- }
863
- };
864
- };
865
- function xe(t) {
866
- return L(t).direction === "rtl";
867
- }
868
- const ye = {
869
- convertOffsetParentRelativeRectToViewportRelativeRect: le,
870
- getDocumentElement: F,
871
- getClippingRect: pe,
872
- getOffsetParent: Ht,
873
- getElementRects: we,
874
- getClientRects: ae,
875
- getDimensions: ge,
876
- getScale: U,
877
- isElement: R,
878
- isRTL: xe
879
- }, be = ne, ve = oe, Ae = te, Ce = Zt, Te = (t, e, o) => {
880
- const n = /* @__PURE__ */ new Map(), i = {
881
- platform: ye,
882
- ...o
883
- }, s = {
884
- ...i.platform,
885
- _c: n
886
- };
887
- return Qt(t, e, {
888
- ...i,
889
- platform: s
890
- });
891
- }, Lt = ["mousedown", "touchstart"];
892
- function Oe(t, e, o) {
893
- const n = J(null);
894
- return gt(() => {
895
- const i = (s) => {
896
- const r = s ? s.target : void 0;
897
- if (Array.isArray(o)) {
898
- const c = !document.body.contains(r) && r.tagName !== "HTML";
899
- o.every(
900
- (l) => !!l && !s.composedPath().includes(l)
901
- ) && !c && t();
902
- } else n.current && !n.current.contains(r) && t();
903
- };
904
- return Lt.forEach(
905
- (s) => document.addEventListener(s, i)
18
+ return I.forEach(
19
+ (e) => document.addEventListener(e, r)
906
20
  ), () => {
907
- Lt.forEach(
908
- (s) => document.removeEventListener(s, i)
21
+ I.forEach(
22
+ (e) => document.removeEventListener(e, r)
909
23
  );
910
24
  };
911
- }, [t, o, e]), n;
25
+ }, [t, s, n]), a;
912
26
  }
913
- function Re(t, e) {
914
- const [o, n] = ut(!1), i = J(null), s = J(null), r = dt(() => {
915
- n((l) => (!l && (!i.current || i.current === -1) && (i.current = window.setInterval(s.current, e)), !0));
916
- }, [e]), c = dt(() => {
917
- n(!1), window.clearInterval(i.current || -1), i.current = -1;
27
+ function J(t, n) {
28
+ const [s, a] = w(!1), r = f(null), e = f(null), o = x(() => {
29
+ a((c) => (!c && (!r.current || r.current === -1) && (r.current = window.setInterval(e.current, n)), !0));
30
+ }, [n]), l = x(() => {
31
+ a(!1), window.clearInterval(r.current || -1), r.current = -1;
918
32
  }, []);
919
- return gt(() => (s.current = t, o && r(), c), [t, o, r, c]), { start: r, stop: c, active: o };
33
+ return T(() => (e.current = t, s && o(), l), [t, s, o, l]), { start: o, stop: l, active: s };
920
34
  }
921
- const ot = (t, e = "px") => typeof t > "u" ? "" : `${Math.round(t)}${e}`, Le = () => Y("absolute top-0 left-0 w-max py-1 px-2 rounded-sm text-sm z-50"), Et = ({
35
+ const d = (t, n = "px") => typeof t > "u" ? "" : `${Math.round(t)}${n}`, K = () => p("absolute top-0 left-0 w-max py-1 px-2 rounded-sm text-sm z-50"), N = ({
922
36
  mode: t
923
- }) => Y({
37
+ }) => p({
924
38
  "bg-surface-darker": t === "dark" || t === "system",
925
39
  "bg-surface-light": t === "light" || t === "alt-system",
926
40
  "dark:bg-surface-light": t === "system",
927
41
  "dark:bg-surface-darker": t === "alt-system"
928
- }), Ee = ({
42
+ }), Q = ({
929
43
  mode: t
930
- }) => Y({
44
+ }) => p({
931
45
  "text-copy-light": t === "dark" || t === "system",
932
46
  "text-copy-dark": t === "light" || t === "alt-system",
933
47
  "dark:text-copy-dark": t === "system",
934
48
  "dark:text-copy-light": t === "alt-system"
935
- }), ke = () => Y("absolute", "size-2", "transform rotate-45"), Se = ({
49
+ }), X = () => p("absolute", "size-2", "transform rotate-45"), Z = ({
936
50
  mode: t,
937
- className: e,
938
- tooltipClassName: o,
939
- arrowClassName: n
51
+ className: n,
52
+ tooltipClassName: s,
53
+ arrowClassName: a
940
54
  }) => {
941
- const i = Y("relative inline-block", e), s = Y(
942
- jt,
943
- Le(),
944
- Et({ mode: t }),
945
- Ee({ mode: t }),
946
- o
947
- ), r = Y(
948
- Yt,
949
- ke(),
950
- Et({ mode: t }),
951
- n
55
+ const r = p("relative inline-block", n), e = p(
56
+ Y,
57
+ K(),
58
+ N({ mode: t }),
59
+ Q({ mode: t }),
60
+ s
61
+ ), o = p(
62
+ q,
63
+ X(),
64
+ N({ mode: t }),
65
+ a
952
66
  );
953
- return { tooltip: s, arrow: r, wrapper: i };
954
- }, Pe = ({ delay: t = 300 }) => ({
67
+ return { tooltip: e, arrow: o, wrapper: r };
68
+ }, tt = ({ delay: t = 300 }) => ({
955
69
  animation: `av-tooltip-fade-in ${t}ms ease-in-out`
956
- }), De = 5e3, Fe = ({
70
+ }), et = 5e3, at = ({
957
71
  trigger: t,
958
- label: e,
959
- placement: o = "top",
960
- mode: n = "system",
961
- delay: i = 300,
962
- className: s,
963
- tooltipClassName: r,
964
- arrowClassName: c
72
+ label: n,
73
+ placement: s = "top",
74
+ mode: a = "system",
75
+ delay: r = 300,
76
+ className: e,
77
+ tooltipClassName: o,
78
+ arrowClassName: l
965
79
  }) => {
966
- const l = Oe(() => {
967
- g.stop(), m(!1);
968
- }), a = J(null), d = J(null), [f, p] = ut(!1), [u, m] = ut(!1), g = Re(() => {
969
- m(!1);
970
- }, De), h = Se({
971
- mode: n,
972
- className: s,
973
- tooltipClassName: r,
974
- arrowClassName: c
975
- }), w = Pe({ delay: i }), x = dt(async () => {
976
- var M, E, V, k;
977
- if (l.current && a.current && d.current) {
80
+ const c = G(() => {
81
+ k.stop(), g(!1);
82
+ }), i = f(null), u = f(null), [y, m] = w(!1), [b, g] = w(!1), k = J(() => {
83
+ g(!1);
84
+ }, et), h = Z({
85
+ mode: a,
86
+ className: e,
87
+ tooltipClassName: o,
88
+ arrowClassName: l
89
+ }), v = tt({ delay: r }), C = x(async () => {
90
+ var A, E, L, S;
91
+ if (c.current && i.current && u.current) {
978
92
  const {
979
- x: T,
980
- y: I,
981
- middlewareData: S,
982
- placement: _
983
- } = await Te(l.current, a.current, {
984
- placement: o,
93
+ x: j,
94
+ y: B,
95
+ middlewareData: M,
96
+ placement: R
97
+ } = await F(c.current, i.current, {
98
+ placement: s,
985
99
  middleware: [
986
- be(10),
987
- Ae({
988
- crossAxis: o.includes("-"),
100
+ H(10),
101
+ U({
102
+ crossAxis: s.includes("-"),
989
103
  fallbackAxisSideDirection: "start"
990
104
  }),
991
- ve({ padding: 5 }),
992
- Ce({ element: d.current })
105
+ V({ padding: 5 }),
106
+ W({ element: u.current })
993
107
  ]
994
108
  });
995
- (M = a == null ? void 0 : a.current) != null && M.style && Object.assign(a.current.style, {
996
- left: ot(T),
997
- top: ot(I),
998
- ...w
109
+ (A = i == null ? void 0 : i.current) != null && A.style && Object.assign(i.current.style, {
110
+ left: d(j),
111
+ top: d(B),
112
+ ...v
999
113
  });
1000
- const C = {
114
+ const $ = {
1001
115
  top: "bottom",
1002
116
  right: "left",
1003
117
  bottom: "top",
1004
118
  left: "right"
1005
- }[_.split("-")[0]];
1006
- (E = d == null ? void 0 : d.current) != null && E.style && Object.assign(d.current.style, {
1007
- left: ot((V = S.arrow) == null ? void 0 : V.x),
1008
- top: ot((k = S.arrow) == null ? void 0 : k.y),
119
+ }[R.split("-")[0]];
120
+ (E = u == null ? void 0 : u.current) != null && E.style && Object.assign(u.current.style, {
121
+ left: d((L = M.arrow) == null ? void 0 : L.x),
122
+ top: d((S = M.arrow) == null ? void 0 : S.y),
1009
123
  right: "",
1010
124
  bottom: "",
1011
- [C]: "-4px"
125
+ [$]: "-4px"
1012
126
  });
1013
127
  }
1014
- }, [o, w, l]);
1015
- gt(() => {
1016
- (async () => f && await x())();
1017
- }, [x, f]);
1018
- const y = () => {
1019
- p(!1), m(!0), g.start();
1020
- }, v = () => {
1021
- u || p(!0);
1022
- }, b = () => {
1023
- u || p(!1);
1024
- };
1025
- return /* @__PURE__ */ vt(
128
+ }, [s, v, c]);
129
+ T(() => {
130
+ (async () => y && await C())();
131
+ }, [C, y]);
132
+ const D = () => {
133
+ m(!1), g(!0), k.start();
134
+ }, P = () => {
135
+ b || m(!0);
136
+ }, _ = () => {
137
+ b || m(!1);
138
+ };
139
+ return /* @__PURE__ */ O(
1026
140
  "div",
1027
141
  {
1028
142
  className: h.wrapper,
1029
- ref: l,
1030
- onMouseEnter: v,
1031
- onMouseLeave: b,
1032
- onClick: y,
143
+ ref: c,
144
+ onMouseEnter: P,
145
+ onMouseLeave: _,
146
+ onClick: D,
1033
147
  children: [
1034
148
  t,
1035
- f && /* @__PURE__ */ vt(
149
+ y && /* @__PURE__ */ O(
1036
150
  "div",
1037
151
  {
1038
152
  role: "tooltip",
1039
- ref: a,
153
+ ref: i,
1040
154
  className: h.tooltip,
1041
155
  children: [
1042
- e,
1043
- /* @__PURE__ */ _t("div", { ref: d, className: h.arrow })
156
+ n,
157
+ /* @__PURE__ */ z("div", { ref: u, className: h.arrow })
1044
158
  ]
1045
159
  }
1046
160
  )
@@ -1049,7 +163,7 @@ const ot = (t, e = "px") => typeof t > "u" ? "" : `${Math.round(t)}${e}`, Le = (
1049
163
  );
1050
164
  };
1051
165
  export {
1052
- Yt as TOOLTIP_ARROW_CLASSNAME,
1053
- jt as TOOLTIP_CLASSNAME,
1054
- Fe as Tooltip
166
+ q as TOOLTIP_ARROW_CLASSNAME,
167
+ Y as TOOLTIP_CLASSNAME,
168
+ at as Tooltip
1055
169
  };
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { TOOLTIP_ARROW_CLASSNAME as T, TOOLTIP_CLASSNAME as I, Tooltip as e } from "./components/Tooltip/Tooltip.js";
2
2
  /*!
3
- @versini/ui-tooltip v2.0.3
3
+ @versini/ui-tooltip v2.1.0
4
4
  © 2025 gizmette.com
5
5
  */
6
6
  try {
7
7
  window.__VERSINI_UI_TOOLTIP__ || (window.__VERSINI_UI_TOOLTIP__ = {
8
- version: "2.0.3",
9
- buildTime: "05/26/2025 03:48 PM EDT",
8
+ version: "2.1.0",
9
+ buildTime: "06/28/2025 08:58 PM EDT",
10
10
  homepage: "https://github.com/aversini/ui-components",
11
11
  license: "MIT"
12
12
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/ui-tooltip",
3
- "version": "2.0.3",
3
+ "version": "2.1.0",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -39,17 +39,17 @@
39
39
  "react-dom": "^18.3.1 || ^19.0.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@versini/ui-types": "5.0.3"
42
+ "@versini/ui-types": "5.0.5"
43
43
  },
44
44
  "dependencies": {
45
- "@floating-ui/dom": "1.7.0",
45
+ "@floating-ui/react": "0.27.13",
46
46
  "@tailwindcss/typography": "0.5.16",
47
- "@versini/ui-hooks": "4.7.3",
47
+ "@versini/ui-hooks": "4.7.4",
48
48
  "clsx": "2.1.1",
49
- "tailwindcss": "4.1.7"
49
+ "tailwindcss": "4.1.11"
50
50
  },
51
51
  "sideEffects": [
52
52
  "**/*.css"
53
53
  ],
54
- "gitHead": "863a399128080a19f2668e458d495110aa0f68f8"
54
+ "gitHead": "1b9a792d10e1f67fc7af7cfdff718ef1e1c78633"
55
55
  }