toast.mjs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { B as k, _ as p, G as l, a as r, W as x, c as G, d as H, Z as m, a9 as S, aa as P, w as b, A as W, h as a, t as Z, m as g, e as D, s as _, E as N, r as j, v as T } from "./base-component-BMXjNJAi.mjs";
  2. import { f as d } from "./fadeClass-CLIYI_zn.mjs";
  3. import { s as f } from "./showClass-C8hdJfjQ.mjs";
  4. import { d as q } from "./dataBsDismiss-DdNPQYa-.mjs";
  5. import { d as z } from "./dataBsToggle-B84TS15h.mjs";
  6. import { g as y } from "./getTargetElement-px782XHx.mjs";
  7. import { i as F } from "./isDisabled-BG5MoQVt.mjs";
  8. const o = "toast", B = "Toast", J = `.${o}`, K = `[${q}="${o}"]`, M = `[${z}="${o}"]`, c = "showing", A = "hide", O = {
  9. animation: !0,
  10. autohide: !0,
  11. delay: 5e3
  12. }, w = (e) => Z(e, B), Q = (e) => new st(e), v = g(
  13. `show.bs.${o}`
  14. ), R = g(
  15. `shown.bs.${o}`
  16. ), E = g(
  17. `hide.bs.${o}`
  18. ), U = g(
  19. `hidden.bs.${o}`
  20. ), C = (e) => {
  21. const { element: t, options: s } = e;
  22. r(t, c), a.clear(t, c), m(t, R), s.autohide && a.set(t, () => e.hide(), s.delay, o);
  23. }, $ = (e) => {
  24. const { element: t } = e;
  25. r(t, c), r(t, f), l(t, A), a.clear(t, o), m(t, U);
  26. }, V = (e) => {
  27. const { element: t, options: s } = e;
  28. l(t, c), s.animation ? (D(t), _(t, () => $(e))) : $(e);
  29. }, X = (e) => {
  30. const { element: t, options: s } = e;
  31. a.set(
  32. t,
  33. () => {
  34. r(t, A), D(t), l(t, f), l(t, c), s.animation ? _(t, () => C(e)) : C(e);
  35. },
  36. 17,
  37. c
  38. );
  39. };
  40. function Y(e) {
  41. const t = y(this), s = t && w(t);
  42. F(this) || s && (this.tagName === "A" && e.preventDefault(), s.relatedTarget = this, s.show());
  43. }
  44. const tt = (e) => {
  45. const t = e.target, s = w(t), { type: n, relatedTarget: i } = e;
  46. !s || t === i || t.contains(i) || ([b, S].includes(n) ? a.clear(t, o) : a.set(t, () => s.hide(), s.options.delay, o));
  47. };
  48. class st extends k {
  49. static selector = J;
  50. static init = Q;
  51. static getInstance = w;
  52. constructor(t, s) {
  53. super(t, s);
  54. const { element: n, options: i } = this;
  55. i.animation && !p(n, d) ? l(n, d) : !i.animation && p(n, d) && r(n, d), this.dismiss = x(K, n), this.triggers = [
  56. ...G(
  57. M,
  58. H(n)
  59. )
  60. ].filter(
  61. (h) => y(h) === n
  62. ), this._toggleEventListeners(!0);
  63. }
  64. get name() {
  65. return B;
  66. }
  67. get defaults() {
  68. return O;
  69. }
  70. get isShown() {
  71. return p(this.element, f);
  72. }
  73. show = () => {
  74. const { element: t, isShown: s } = this;
  75. !t || s || (m(t, v), v.defaultPrevented || X(this));
  76. };
  77. hide = () => {
  78. const { element: t, isShown: s } = this;
  79. !t || !s || (m(t, E), E.defaultPrevented || V(this));
  80. };
  81. _toggleEventListeners = (t) => {
  82. const s = t ? N : j, { element: n, triggers: i, dismiss: h, options: I, hide: L } = this;
  83. h && s(h, T, L), I.autohide && [S, P, b, W].forEach(
  84. (u) => s(n, u, tt)
  85. ), i.length && i.forEach((u) => {
  86. s(u, T, Y);
  87. });
  88. };
  89. dispose() {
  90. const { element: t, isShown: s } = this;
  91. this._toggleEventListeners(), a.clear(t, o), s && r(t, f), super.dispose();
  92. }
  93. }
  94. export {
  95. st as default
  96. };
  97. //# sourceMappingURL=toast.mjs.map