tooltip-DS8L4mHj.mjs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. import { H as xt, ab as Dt, x as ct, M as jt, L as Q, P as zt, ac as It, o as P, m as G, ad as K, Z, p as Qt, ae as Gt, af as Kt, ag as Zt, ah as qt, a5 as j, Q as st, W as et, G as S, _ as I, ai as Jt, aj as Ut, ak as Vt, d as ft, B as Yt, t as Ht, al as Xt, T as te, C as Nt, a4 as ee, J as oe, h as W, s as ht, a as se, am as ie, U as ne, w as ae, A as le, g as St, v as dt, R as re, a9 as ce, aa as he, an as de, N as gt, K as pe, $ as Wt, ao as Lt, E as mt, r as ut, f as At } from "./base-component-BMXjNJAi.mjs";
  2. import { y as fe } from "./index-CnhA8i0D.mjs";
  3. import { d as me } from "./dataBsToggle-B84TS15h.mjs";
  4. import { s as pt } from "./showClass-C8hdJfjQ.mjs";
  5. import { a as ue, h as ge, m as bt, o as vt, r as be } from "./popupContainer-BY58HXTH.mjs";
  6. import { f as $t } from "./fadeClass-CLIYI_zn.mjs";
  7. const ot = "popover", ve = "Popover", v = "tooltip", $e = (s) => {
  8. const t = s === v, e = t ? `${s}-inner` : `${s}-body`, o = t ? "" : `<h3 class="${s}-header"></h3>`, n = `<div class="${s}-arrow"></div>`, a = `<div class="${e}"></div>`;
  9. return `<div class="${s}" role="${v}">${o + n + a}</div>`;
  10. }, _t = {
  11. top: "top",
  12. bottom: "bottom",
  13. left: "start",
  14. right: "end"
  15. }, wt = (s) => {
  16. requestAnimationFrame(() => {
  17. const t = /\b(top|bottom|start|end)+/, { element: e, tooltip: o, container: n, offsetParent: a, options: h, arrow: r } = s;
  18. if (!o) return;
  19. const p = xt(e), { x: $, y: c } = Dt(a);
  20. ct(o, {
  21. top: "",
  22. left: "",
  23. right: "",
  24. bottom: ""
  25. });
  26. const { offsetWidth: m, offsetHeight: f } = o, { clientWidth: u, clientHeight: E, offsetWidth: B } = jt(e);
  27. let { placement: i } = h;
  28. const { clientWidth: g, offsetWidth: q } = n, d = Q(
  29. n,
  30. "position"
  31. ) === "fixed", J = Math.abs(d ? g - q : u - B), x = p && d ? J : 0, w = u - (p ? 0 : J) - 1, it = s._observer.getEntry(e), {
  32. width: l,
  33. height: b,
  34. left: U,
  35. right: kt,
  36. top: V
  37. } = it?.boundingClientRect || zt(e, !0), {
  38. x: Y,
  39. y: A
  40. } = It(
  41. e,
  42. a,
  43. { x: $, y: c }
  44. );
  45. ct(r, {
  46. top: "",
  47. left: "",
  48. right: "",
  49. bottom: ""
  50. });
  51. let H = 0, R = "", T = 0, nt = "", _ = "", X = "", at = "";
  52. const N = r.offsetWidth || 0, y = r.offsetHeight || 0, lt = N / 2;
  53. let M = V - f - y < 0, k = V + f + b + y >= E, F = U - m - N < x, D = U + m + l + N >= w;
  54. const tt = ["left", "right"], rt = ["top", "bottom"];
  55. M = tt.includes(i) ? V + b / 2 - f / 2 - y < 0 : M, k = tt.includes(i) ? V + f / 2 + b / 2 + y >= E : k, F = rt.includes(i) ? U + l / 2 - m / 2 < x : F, D = rt.includes(i) ? U + m / 2 + l / 2 >= w : D, i = tt.includes(i) && F && D ? "top" : i, i = i === "top" && M ? "bottom" : i, i = i === "bottom" && k ? "top" : i, i = i === "left" && F ? "right" : i, i = i === "right" && D ? "left" : i, o.className.includes(i) || (o.className = o.className.replace(
  56. t,
  57. _t[i]
  58. )), tt.includes(i) ? (i === "left" ? T = Y - m - N : T = Y + l + N, M && k ? (H = 0, R = 0, _ = A + b / 2 - y / 2) : M ? (H = A, R = "", _ = b / 2 - N) : k ? (H = A - f + b, R = "", _ = f - b / 2 - N) : (H = A - f / 2 + b / 2, _ = f / 2 - y / 2)) : rt.includes(i) && (i === "top" ? H = A - f - y : H = A + b + y, F ? (T = 0, X = Y + l / 2 - lt) : D ? (T = "auto", nt = 0, at = l / 2 + w - kt - lt) : (T = Y - m / 2 + l / 2, X = m / 2 - lt)), ct(o, {
  59. top: `${H}px`,
  60. bottom: R === "" ? "" : `${R}px`,
  61. left: T === "auto" ? T : `${T}px`,
  62. right: nt !== "" ? `${nt}px` : ""
  63. }), P(r) && (_ !== "" && (r.style.top = `${_}px`), X !== "" ? r.style.left = `${X}px` : at !== "" && (r.style.right = `${at}px`));
  64. const Ft = G(
  65. `updated.bs.${K(s.name)}`
  66. );
  67. Z(e, Ft);
  68. });
  69. }, Tt = {
  70. template: $e(v),
  71. title: "",
  72. customClass: "",
  73. trigger: "hover focus",
  74. placement: "top",
  75. sanitizeFn: void 0,
  76. animation: !0,
  77. delay: 200,
  78. container: document.body,
  79. content: "",
  80. dismissible: !1,
  81. btnClose: ""
  82. }, Bt = "data-original-title", L = "Tooltip", C = (s, t, e) => {
  83. if (Qt(t) && t.length) {
  84. let o = t.trim();
  85. Gt(e) && (o = e(o));
  86. const a = new DOMParser().parseFromString(o, "text/html");
  87. s.append(...a.body.childNodes);
  88. } else P(t) ? s.append(t) : (Kt(t) || Zt(t) && t.every(qt)) && s.append(...t);
  89. }, we = (s) => {
  90. const t = s.name === L, { id: e, element: o, options: n } = s, {
  91. title: a,
  92. placement: h,
  93. template: r,
  94. animation: p,
  95. customClass: $,
  96. sanitizeFn: c,
  97. dismissible: m,
  98. content: f,
  99. btnClose: u
  100. } = n, E = t ? v : ot, B = { ..._t };
  101. let i = [], g = [];
  102. xt(o) && (B.left = "end", B.right = "start");
  103. const q = `bs-${E}-${B[h]}`;
  104. let O;
  105. if (P(r))
  106. O = r;
  107. else {
  108. const l = j("div");
  109. C(l, r, c), O = l.firstChild;
  110. }
  111. if (!P(O)) return;
  112. s.tooltip = O.cloneNode(!0);
  113. const { tooltip: d } = s;
  114. st(d, "id", e), st(d, "role", v);
  115. const J = t ? `${v}-inner` : `${ot}-body`, x = t ? null : et(`.${ot}-header`, d), w = et(`.${J}`, d);
  116. s.arrow = et(
  117. `.${E}-arrow`,
  118. d
  119. );
  120. const { arrow: it } = s;
  121. if (P(a)) i = [a.cloneNode(!0)];
  122. else {
  123. const l = j("div");
  124. C(l, a, c), i = [...l.childNodes];
  125. }
  126. if (P(f)) g = [f.cloneNode(!0)];
  127. else {
  128. const l = j("div");
  129. C(l, f, c), g = [...l.childNodes];
  130. }
  131. if (m)
  132. if (a)
  133. if (P(u))
  134. i = [...i, u.cloneNode(!0)];
  135. else {
  136. const l = j("div");
  137. C(l, u, c), i = [...i, l.firstChild];
  138. }
  139. else if (x && x.remove(), P(u))
  140. g = [...g, u.cloneNode(!0)];
  141. else {
  142. const l = j("div");
  143. C(l, u, c), g = [...g, l.firstChild];
  144. }
  145. t ? a && w && C(w, a, c) : (a && x && C(x, i, c), f && w && C(w, g, c), s.btn = et(".btn-close", d) || void 0), S(d, "position-absolute"), S(it, "position-absolute"), I(d, E) || S(d, E), p && !I(d, $t) && S(d, $t), $ && !I(d, $) && S(d, $), I(d, q) || S(d, q);
  146. }, Te = (s) => {
  147. const t = ["HTML", "BODY"], e = [];
  148. let { parentNode: o } = s;
  149. for (; o && !t.includes(o.nodeName); )
  150. o = Jt(o), Ut(o) || Vt(o) || e.push(o);
  151. return e.find((n, a) => (Q(n, "position") !== "relative" || Q(n, "position") === "relative" && n.offsetHeight !== n.scrollHeight) && e.slice(a + 1).every(
  152. (h) => Q(h, "position") === "static"
  153. ) ? n : null) || ft(s).body;
  154. }, ye = `[${me}="${v}"],[data-tip="${v}"]`, Ot = "title";
  155. let yt = (s) => Ht(s, L);
  156. const Ce = (s) => new xe(s), Pe = (s) => {
  157. const { element: t, tooltip: e, container: o } = s;
  158. Wt(t, Lt), be(
  159. e,
  160. o
  161. );
  162. }, z = (s) => {
  163. const { tooltip: t, container: e } = s;
  164. return t && ge(t, e);
  165. }, Ee = (s, t) => {
  166. const { element: e } = s;
  167. s._toggleEventListeners(), Nt(e, Bt) && s.name === L && Mt(s), t && t();
  168. }, Rt = (s, t) => {
  169. const e = t ? mt : ut, { element: o } = s;
  170. e(
  171. ft(o),
  172. St,
  173. s.handleTouch,
  174. At
  175. );
  176. }, Ct = (s) => {
  177. const { element: t } = s, e = G(
  178. `shown.bs.${K(s.name)}`
  179. );
  180. Rt(s, !0), Z(t, e), W.clear(t, "in");
  181. }, Pt = (s) => {
  182. const { element: t } = s, e = G(
  183. `hidden.bs.${K(s.name)}`
  184. );
  185. Rt(s), Pe(s), Z(t, e), W.clear(t, "out");
  186. }, Et = (s, t) => {
  187. const e = t ? mt : ut, { element: o, tooltip: n } = s, a = gt(o, `.${bt}`), h = gt(o, `.${vt}`);
  188. t ? [o, n].forEach((r) => s._observer.observe(r)) : s._observer.disconnect(), a && e(a, `hide.bs.${bt}`, s.handleHide), h && e(h, `hide.bs.${vt}`, s.handleHide);
  189. }, Mt = (s, t) => {
  190. const e = [Bt, Ot], { element: o } = s;
  191. st(
  192. o,
  193. e[t ? 0 : 1],
  194. t || pe(o, e[0]) || ""
  195. ), Wt(o, e[t ? 1 : 0]);
  196. };
  197. class xe extends Yt {
  198. static selector = ye;
  199. static init = Ce;
  200. static getInstance = yt;
  201. static styleTip = wt;
  202. constructor(t, e) {
  203. super(t, e);
  204. const { element: o } = this, n = this.name === L, a = n ? v : ot, h = n ? L : ve;
  205. yt = (c) => Ht(c, h), this.enabled = !0, this.id = `${a}-${Xt(o, a)}`;
  206. const { options: r } = this;
  207. if (!r.title && n || !n && !r.content)
  208. return;
  209. te(Tt, { titleAttr: "" }), Nt(o, Ot) && n && typeof r.title == "string" && Mt(this, r.title);
  210. const p = Te(o), $ = ["sticky", "fixed", "relative"].some(
  211. (c) => Q(p, "position") === c
  212. ) ? p : ee(o);
  213. this.container = p, this.offsetParent = $, we(this), this.tooltip && (this._observer = new fe(() => this.update()), this._toggleEventListeners(!0));
  214. }
  215. get name() {
  216. return L;
  217. }
  218. get defaults() {
  219. return Tt;
  220. }
  221. handleFocus = () => oe(this.element);
  222. handleShow = () => this.show();
  223. show() {
  224. const { options: t, tooltip: e, element: o, container: n, id: a } = this, { animation: h } = t, r = W.get(o, "out");
  225. W.clear(o, "out"), e && !r && !z(this) && W.set(
  226. o,
  227. () => {
  228. const p = G(
  229. `show.bs.${K(this.name)}`
  230. );
  231. Z(o, p), p.defaultPrevented || (ue(e, n), st(o, Lt, `#${a}`), this.update(), Et(this, !0), I(e, pt) || S(e, pt), h ? ht(e, () => Ct(this)) : Ct(this));
  232. },
  233. 17,
  234. "in"
  235. );
  236. }
  237. handleHide = () => this.hide();
  238. hide() {
  239. const { options: t, tooltip: e, element: o } = this, { animation: n, delay: a } = t;
  240. W.clear(o, "in"), e && z(this) && W.set(
  241. o,
  242. () => {
  243. const h = G(
  244. `hide.bs.${K(this.name)}`
  245. );
  246. Z(o, h), h.defaultPrevented || (this.update(), se(e, pt), Et(this), n ? ht(e, () => Pt(this)) : Pt(this));
  247. },
  248. a + 17,
  249. "out"
  250. );
  251. }
  252. update = () => {
  253. wt(this);
  254. };
  255. toggle = () => {
  256. const { tooltip: t } = this;
  257. t && !z(this) ? this.show() : this.hide();
  258. };
  259. enable() {
  260. const { enabled: t } = this;
  261. t || (this._toggleEventListeners(!0), this.enabled = !t);
  262. }
  263. disable() {
  264. const { tooltip: t, enabled: e } = this;
  265. e && (t && z(this) && this.hide(), this._toggleEventListeners(), this.enabled = !e);
  266. }
  267. toggleEnabled() {
  268. this.enabled ? this.disable() : this.enable();
  269. }
  270. handleTouch = ({ target: t }) => {
  271. const { tooltip: e, element: o } = this;
  272. e && e.contains(t) || t === o || t && o.contains(t) || this.hide();
  273. };
  274. _toggleEventListeners = (t) => {
  275. const e = t ? mt : ut, { element: o, options: n, btn: a } = this, { trigger: h } = n, p = !!(this.name !== L && n.dismissible);
  276. h.includes("manual") || (this.enabled = !!t, h.split(" ").forEach((c) => {
  277. c === ie ? (e(o, ne, this.handleShow), e(o, ae, this.handleShow), p || (e(o, le, this.handleHide), e(
  278. ft(o),
  279. St,
  280. this.handleTouch,
  281. At
  282. ))) : c === dt ? e(o, c, p ? this.handleShow : this.toggle) : c === re && (e(o, ce, this.handleShow), p || e(o, he, this.handleHide), de() && e(o, dt, this.handleFocus)), p && a && e(a, dt, this.handleHide);
  283. }));
  284. };
  285. dispose() {
  286. const { tooltip: t, options: e } = this, o = { ...this, name: this.name }, n = () => setTimeout(
  287. () => Ee(o, () => super.dispose()),
  288. 17
  289. );
  290. e.animation && z(o) ? (this.options.delay = 0, this.hide(), ht(t, n)) : n();
  291. }
  292. }
  293. export {
  294. xe as T,
  295. ot as a,
  296. $e as g,
  297. ve as p,
  298. wt as s,
  299. Tt as t
  300. };
  301. //# sourceMappingURL=tooltip-DS8L4mHj.mjs.map