carousel.mjs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. import { B as it, H as C, j as nt, b as ot, d as T, c as I, W as N, G as u, _ as S, h as d, a as $, D as Q, T as _, Z as K, u as at, e as rt, s as k, t as ct, m as U, E as q, r as F, w as lt, A as dt, f as L, O as ht, g as ft, i as ut, v as R, k as gt, N as J, K as V, z as mt, I as pt, l as j, n as z } from "./base-component-BMXjNJAi.mjs";
  2. import { a as g } from "./activeClass-iqaD75Su.mjs";
  3. import { d as G, g as Y } from "./getTargetElement-px782XHx.mjs";
  4. import { i as tt } from "./isDisabled-BG5MoQVt.mjs";
  5. const P = "carousel", et = "Carousel", A = `[data-bs-ride="${P}"]`, h = `${P}-item`, O = "data-bs-slide-to", v = "data-bs-slide", x = "paused", M = {
  6. pause: "hover",
  7. keyboard: !1,
  8. touch: !0,
  9. interval: 5e3
  10. }, m = (i) => ct(i, et), vt = (i) => new Ct(i);
  11. let y = 0, b = 0, E = 0;
  12. const w = U(`slide.bs.${P}`), X = U(`slid.bs.${P}`), W = (i) => {
  13. const { index: s, direction: t, element: e, slides: o, options: a } = i;
  14. if (i.isAnimating) {
  15. const r = B(i), n = t === "left" ? "next" : "prev", l = t === "left" ? "start" : "end";
  16. u(o[s], g), $(o[s], `${h}-${n}`), $(o[s], `${h}-${l}`), $(o[r], g), $(o[r], `${h}-${l}`), K(e, X), d.clear(e, v), i.cycle && !T(e).hidden && a.interval && !i.isPaused && i.cycle();
  17. }
  18. };
  19. function xt() {
  20. const i = m(this);
  21. i && !i.isPaused && !d.get(this, x) && u(this, x);
  22. }
  23. function $t() {
  24. const i = m(this);
  25. i && i.isPaused && !d.get(this, x) && i.cycle();
  26. }
  27. function Pt(i) {
  28. i.preventDefault();
  29. const s = J(this, A) || Y(this), t = s && m(s);
  30. if (tt(this) || !t || t.isAnimating) return;
  31. const e = +(V(this, O) || 0);
  32. this && !S(this, g) && !Number.isNaN(e) && t.to(e);
  33. }
  34. function Tt(i) {
  35. i.preventDefault();
  36. const s = J(this, A) || Y(this), t = s && m(s);
  37. if (tt(this) || !t || t.isAnimating) return;
  38. const e = V(this, v);
  39. e === "next" ? t.next() : e === "prev" && t.prev();
  40. }
  41. const It = ({ code: i, target: s }) => {
  42. const t = T(s), [e] = [...I(A, t)].filter((l) => Q(l)), o = m(e);
  43. if (!o || o.isAnimating || /textarea|input|select/i.test(s.nodeName)) return;
  44. const a = C(e);
  45. i === (a ? j : z) ? o.prev() : i === (a ? z : j) && o.next();
  46. };
  47. function Z(i) {
  48. const { target: s } = i, t = m(this);
  49. t && t.isTouch && (t.indicator && !t.indicator.contains(s) || !t.controls.includes(s)) && (i.stopImmediatePropagation(), i.stopPropagation(), i.preventDefault());
  50. }
  51. function yt(i) {
  52. const { target: s } = i, t = m(this);
  53. if (!t || t.isAnimating || t.isTouch) return;
  54. const { controls: e, indicators: o } = t;
  55. [...e, ...o].every(
  56. (a) => a === s || a.contains(s)
  57. ) || (y = i.pageX, this.contains(s) && (t.isTouch = !0, st(t, !0)));
  58. }
  59. const At = (i) => {
  60. b = i.pageX;
  61. }, bt = (i) => {
  62. const { target: s } = i, t = T(s), e = [...I(A, t)].map((n) => m(n)).find((n) => n.isTouch);
  63. if (!e) return;
  64. const { element: o, index: a } = e, r = C(o);
  65. E = i.pageX, e.isTouch = !1, st(e), !t.getSelection()?.toString().length && o.contains(s) && Math.abs(y - E) > 120 && (b < y ? e.to(a + (r ? -1 : 1)) : b > y && e.to(a + (r ? 1 : -1))), y = 0, b = 0, E = 0;
  66. }, D = (i, s) => {
  67. const { indicators: t } = i;
  68. [...t].forEach((e) => $(e, g)), i.indicators[s] && u(t[s], g);
  69. }, st = (i, s) => {
  70. const { element: t } = i, e = s ? q : F;
  71. e(
  72. T(t),
  73. mt,
  74. At,
  75. L
  76. ), e(
  77. T(t),
  78. pt,
  79. bt,
  80. L
  81. );
  82. }, B = (i) => {
  83. const { slides: s, element: t } = i, e = N(
  84. `.${h}.${g}`,
  85. t
  86. );
  87. return e ? [...s].indexOf(e) : -1;
  88. };
  89. class Ct extends it {
  90. static selector = A;
  91. static init = vt;
  92. static getInstance = m;
  93. constructor(s, t) {
  94. super(s, t);
  95. const { element: e } = this;
  96. this.direction = C(e) ? "right" : "left", this.isTouch = !1, this.slides = nt(h, e);
  97. const { slides: o } = this;
  98. if (o.length < 2) return;
  99. const a = B(this), r = [...o].find(
  100. (f) => ot(f, `.${h}-next`)
  101. );
  102. this.index = a;
  103. const n = T(e);
  104. this.controls = [
  105. ...I(`[${v}]`, e),
  106. ...I(
  107. `[${v}][${G}="#${e.id}"]`,
  108. n
  109. )
  110. ].filter((f, p, c) => p === c.indexOf(f)), this.indicator = N(
  111. `.${P}-indicators`,
  112. e
  113. ), this.indicators = [
  114. ...this.indicator ? I(`[${O}]`, this.indicator) : [],
  115. ...I(
  116. `[${O}][${G}="#${e.id}"]`,
  117. n
  118. )
  119. ].filter((f, p, c) => p === c.indexOf(f));
  120. const { options: l } = this;
  121. this.options.interval = l.interval === !0 ? M.interval : l.interval, r ? this.index = [...o].indexOf(r) : a < 0 && (this.index = 0, u(o[0], g), this.indicators.length && D(this, 0)), this.indicators.length && D(this, this.index), this._toggleEventListeners(!0), l.interval && this.cycle();
  122. }
  123. get name() {
  124. return et;
  125. }
  126. get defaults() {
  127. return M;
  128. }
  129. get isPaused() {
  130. return S(this.element, x);
  131. }
  132. get isAnimating() {
  133. return N(
  134. `.${h}-next,.${h}-prev`,
  135. this.element
  136. ) !== null;
  137. }
  138. cycle() {
  139. const { element: s, options: t, isPaused: e, index: o } = this;
  140. d.clear(s, P), e && (d.clear(s, x), $(s, x)), d.set(
  141. s,
  142. () => {
  143. this.element && !this.isPaused && !this.isTouch && Q(s) && this.to(o + 1);
  144. },
  145. t.interval,
  146. P
  147. );
  148. }
  149. pause() {
  150. const { element: s, options: t } = this;
  151. this.isPaused || !t.interval || (u(s, x), d.set(
  152. s,
  153. () => {
  154. },
  155. 1,
  156. x
  157. ));
  158. }
  159. next() {
  160. this.isAnimating || this.to(this.index + 1);
  161. }
  162. prev() {
  163. this.isAnimating || this.to(this.index - 1);
  164. }
  165. to(s) {
  166. const { element: t, slides: e, options: o } = this, a = B(this), r = C(t);
  167. let n = s;
  168. if (this.isAnimating || a === n || d.get(t, v)) return;
  169. a < n || a === 0 && n === e.length - 1 ? this.direction = r ? "right" : "left" : (a > n || a === e.length - 1 && n === 0) && (this.direction = r ? "left" : "right");
  170. const { direction: l } = this;
  171. n < 0 ? n = e.length - 1 : n >= e.length && (n = 0);
  172. const f = l === "left" ? "next" : "prev", p = l === "left" ? "start" : "end", c = {
  173. relatedTarget: e[n],
  174. from: a,
  175. to: n,
  176. direction: l
  177. };
  178. _(w, c), _(X, c), K(t, w), !w.defaultPrevented && (this.index = n, D(this, n), at(e[n]) && S(t, "slide") ? d.set(
  179. t,
  180. () => {
  181. u(e[n], `${h}-${f}`), rt(e[n]), u(e[n], `${h}-${p}`), u(e[a], `${h}-${p}`), k(
  182. e[n],
  183. () => this.slides && this.slides.length && W(this)
  184. );
  185. },
  186. 0,
  187. v
  188. ) : (u(e[n], g), $(e[a], g), d.set(
  189. t,
  190. () => {
  191. d.clear(t, v), t && o.interval && !this.isPaused && this.cycle(), K(t, X);
  192. },
  193. 0,
  194. v
  195. )));
  196. }
  197. _toggleEventListeners = (s) => {
  198. const { element: t, options: e, slides: o, controls: a, indicators: r } = this, { touch: n, pause: l, interval: f, keyboard: p } = e, c = s ? q : F;
  199. l && f && (c(t, lt, xt), c(t, dt, $t)), n && o.length > 2 && (c(
  200. t,
  201. ht,
  202. yt,
  203. L
  204. ), c(t, ft, Z, { passive: !1 }), c(t, ut, Z, { passive: !1 })), a.length && a.forEach((H) => {
  205. c(H, R, Tt);
  206. }), r.length && r.forEach((H) => {
  207. c(H, R, Pt);
  208. }), p && c(T(t), gt, It);
  209. };
  210. dispose() {
  211. const { isAnimating: s } = this, t = {
  212. ...this,
  213. isAnimating: s
  214. };
  215. this._toggleEventListeners(), super.dispose(), t.isAnimating && k(t.slides[t.index], () => {
  216. W(t);
  217. });
  218. }
  219. }
  220. export {
  221. Ct as default
  222. };
  223. //# sourceMappingURL=carousel.mjs.map