diff --git a/dist/swapy.js b/dist/swapy.js index 86d9ef8..1129895 100644 --- a/dist/swapy.js +++ b/dist/swapy.js @@ -11,8 +11,8 @@ function gt(t) { unit: "px" }; const n = e.map((s) => { - const [c, f, m] = s.match(/(\d+(?:\.\d+)?)(px|%)/) ?? []; - return { value: parseFloat(f), unit: m }; + const [c, f, y] = s.match(/(\d+(?:\.\d+)?)(px|%)/) ?? []; + return { value: parseFloat(f), unit: y }; }), o = ((h = n[0]) == null ? void 0 : h.unit) || "px"; if (n.some((s) => s.unit !== o)) throw new Error("Inconsistent units in border-radius string."); @@ -46,7 +46,7 @@ function ht({ x: t, y: e, unit: n }, o, l) { return { x: t, y: e, unit: "%" }; return { x: t, y: e, unit: n }; } -function z(t) { +function G(t) { return ` ${t.x.topLeft}${t.unit} ${t.x.topRight}${t.unit} ${t.x.bottomRight}${t.unit} ${t.x.bottomLeft}${t.unit} / @@ -68,14 +68,14 @@ function xt(t, e) { function vt(t, e) { return R(t.x - e.x, t.y - e.y); } -function It(t, e) { +function At(t, e) { return R(t.x * e, t.y * e); } function C(t, e, n) { return t + (e - t) * n; } -function At(t, e, n) { - return xt(t, It(vt(e, t), n)); +function It(t, e, n) { + return xt(t, At(vt(e, t), n)); } function pt(t, e, n) { return { @@ -95,19 +95,19 @@ function pt(t, e, n) { }; } function Et(t, e, n) { - return W((n - t) / (e - t), 0, 1); + return V((n - t) / (e - t), 0, 1); } -function V(t, e, n, o, l) { +function U(t, e, n, o, l) { return C(n, o, Et(t, e, l)); } -function W(t, e, n) { +function V(t, e, n) { return Math.min(Math.max(t, e), n); } const Xt = { duration: 350, easing: (t) => t }; -function yt(t, e, n, o) { +function mt(t, e, n, o) { let l = !1; const i = () => { l = !0; @@ -115,8 +115,8 @@ function yt(t, e, n, o) { let u; function a(h) { u === void 0 && (u = h); - const s = h - u, c = W(s / d.duration, 0, 1), f = Object.keys(t), m = Object.keys(e); - if (!f.every((g) => m.includes(g))) { + const s = h - u, c = V(s / d.duration, 0, 1), f = Object.keys(t), y = Object.keys(e); + if (!f.every((g) => y.includes(g))) { console.error("animate Error: `from` keys are different than `to`"); return; } @@ -130,7 +130,7 @@ function yt(t, e, n, o) { t[g], e[g], d.easing(c) - ) : at(t[g]) && at(e[g]) && (v[g] = At( + ) : at(t[g]) && at(e[g]) && (v[g] = It( t[g], e[g], d.easing(c) @@ -142,103 +142,103 @@ function yt(t, e, n, o) { const Tt = { startDelay: 0 }; -function Dt(t, e) { +function Mt(t, e) { const n = { ...Tt, ...e }; - let o = t.el(), l = !1, i = null, d = null, u = null, a = null, h = 0, s = 0, c = 0, f = 0, m = 0, v = 0, g = 0, T = 0, r = 0, I = 0, E = null, p; - o.addEventListener("pointerdown", w), document.body.addEventListener("pointerup", x), document.body.addEventListener("pointermove", X), document.body.addEventListener("touchmove", D, { passive: !1 }); - function w(y) { - if (l || !y.isPrimary) return; - n.startDelay > 0 ? (u == null || u({ el: y.target }), p = setTimeout(() => { + let o = t.el(), l = !1, i = null, d = null, u = null, a = null, h = 0, s = 0, c = 0, f = 0, y = 0, v = 0, g = 0, T = 0, r = 0, A = 0, E = null, p; + o.addEventListener("pointerdown", w), document.body.addEventListener("pointerup", x), document.body.addEventListener("pointermove", X), document.body.addEventListener("touchmove", M, { passive: !1 }); + function w(m) { + if (l || !m.isPrimary) return; + n.startDelay > 0 ? (u == null || u({ el: m.target }), p = setTimeout(() => { B(); }, n.startDelay)) : B(); function B() { - E = y.target; - const L = t.boundingRect(), q = t.layoutRect(); - m = q.x, v = q.y, c = L.x - m, f = L.y - v, h = y.clientX - c, s = y.clientY - f, g = y.clientX, T = y.clientY, r = (y.clientX - L.x) / L.width, I = (y.clientY - L.y) / L.height, l = !0, X(y); + E = m.target; + const L = t.boundingRect(), F = t.layoutRect(); + y = F.x, v = F.y, c = L.x - y, f = L.y - v, h = m.clientX - c, s = m.clientY - f, g = m.clientX, T = m.clientY, r = (m.clientX - L.x) / L.width, A = (m.clientY - L.y) / L.height, l = !0, X(m); } } - function A() { - const y = t.layoutRect(); - h -= m - y.x, s -= v - y.y, m = y.x, v = y.y; + function I() { + const m = t.layoutRect(); + h -= y - m.x, s -= v - m.y, y = m.x, v = m.y; } - function x(y) { + function x(m) { if (!l) { - p && (clearTimeout(p), p = null, a == null || a({ el: y.target })); + p && (clearTimeout(p), p = null, a == null || a({ el: m.target })); return; } - if (!y.isPrimary) return; + if (!m.isPrimary) return; l = !1; - const B = y.clientX - g, L = y.clientY - T; + const B = m.clientX - g, L = m.clientY - T; d == null || d({ x: c, y: f, - pointerX: y.clientX, - pointerY: y.clientY, + pointerX: m.clientX, + pointerY: m.clientY, width: B, height: L, relativeX: r, - relativeY: I, + relativeY: A, el: E }), E = null; } - function X(y) { + function X(m) { if (!l) { - p && (clearTimeout(p), p = null, a == null || a({ el: y.target })); + p && (clearTimeout(p), p = null, a == null || a({ el: m.target })); return; } - if (!y.isPrimary) return; - const B = y.clientX - g, L = y.clientY - T, q = c = y.clientX - h, U = f = y.clientY - s; + if (!m.isPrimary) return; + const B = m.clientX - g, L = m.clientY - T, F = c = m.clientX - h, Z = f = m.clientY - s; i == null || i({ width: B, height: L, - x: q, - y: U, - pointerX: y.clientX, - pointerY: y.clientY, + x: F, + y: Z, + pointerX: m.clientX, + pointerY: m.clientY, relativeX: r, - relativeY: I, + relativeY: A, el: E }); } - function D(y) { + function M(m) { if (!l) return !0; - y.preventDefault(); + m.preventDefault(); } - function M(y) { - i = y; + function D(m) { + i = m; } - function H(y) { - d = y; + function H(m) { + d = m; } - function _(y) { - u = y; + function _(m) { + u = m; } - function P(y) { - a = y; + function P(m) { + a = m; } function $() { o.removeEventListener("pointerdown", w), o = t.el(), o.addEventListener("pointerdown", w); } function N() { - t.el().removeEventListener("pointerdown", w), document.body.removeEventListener("pointerup", x), document.body.removeEventListener("pointermove", X), document.body.removeEventListener("touchmove", D), i = null, d = null, u = null, a = null; + t.el().removeEventListener("pointerdown", w), document.body.removeEventListener("pointerup", x), document.body.removeEventListener("pointermove", X), document.body.removeEventListener("touchmove", M), i = null, d = null, u = null, a = null; } return { - onDrag: M, + onDrag: D, onDrop: H, onHold: _, onRelease: P, onElementUpdate: $, destroy: N, - readjust: A + readjust: I }; } -function Mt(t) { +function Dt(t) { return 1 + 2.70158 * Math.pow(t - 1, 3) + 1.70158 * Math.pow(t - 1, 2); } function bt(t) { return 1 - Math.pow(1 - t, 3); } -function k(t) { +function z(t) { return { x: t.x, y: t.y, @@ -246,7 +246,28 @@ function k(t) { height: t.height }; } -function Z(t) { +function Lt(t) { + const e = t.getBoundingClientRect(); + let n = 0, o = 0, l = t.parentElement; + for (; l; ) { + const d = getComputedStyle(l).transform; + if (d && d !== "none") { + const u = d.match(/matrix.*\((.+)\)/); + if (u) { + const a = u[1].split(", ").map(Number); + n += a[4] || 0, o += a[5] || 0; + } + } + l = l.parentElement; + } + return { + y: e.top - o, + x: e.left - n, + width: e.width, + height: e.height + }; +} +function J(t) { let e = t, n = 0, o = 0; for (; e; ) n += e.offsetTop, o += e.offsetLeft, e = e.offsetParent; @@ -260,7 +281,7 @@ function Z(t) { function st(t, e) { return t.x >= e.x && t.x <= e.x + e.width && t.y >= e.y && t.y <= e.y + e.height; } -function Lt(t) { +function Yt(t) { let e = t, n = 0, o = 0; for (; e; ) { const l = (i) => { @@ -277,20 +298,22 @@ function Lt(t) { } return { x: o, y: n }; } -function K(t) { +function Q(t) { let e = "unread", n, o, l, i, d, u, a, h, s, c, f; - function m() { - n = t.currentTransform(), o = t.boundingRect(), l = Lt(t.el()), f = ct(t.el()).map(({ parent: I, children: E }) => ({ + function y() { + n = t.currentTransform(), o = Lt(t.el()), l = Yt(t.el()), f = ct(t.el()).map(({ parent: A, children: E }) => ({ parent: { - el: I, - initialRect: k(I.getBoundingClientRect()) + el: A, + initialRect: z(A.getBoundingClientRect()) }, - children: E.map((p) => { + children: E.filter((p) => p instanceof HTMLElement).map((p) => { const w = p; return w.originalBorderRadius || (w.originalBorderRadius = getComputedStyle(p).borderRadius), { el: p, borderRadius: gt(w.originalBorderRadius), - initialRect: k(p.getBoundingClientRect()) + initialRect: z( + p.getBoundingClientRect() + ) }; }) })), e = "readInitial"; @@ -308,44 +331,44 @@ function K(t) { const r = ct(t.el()); f = f.map( ({ parent: E, children: p }, w) => { - const A = r[w].parent; + const I = r[w].parent; return { parent: { ...E, - el: A, - finalRect: Z(A) + el: I, + finalRect: J(I) }, children: p.map((x, X) => { - const D = r[w].children[X]; - let M = Z(D); - return D.hasAttribute("data-swapy-text") && (M = { - ...M, + const M = r[w].children[X]; + let D = J(M); + return M.hasAttribute("data-swapy-text") && (D = { + ...D, width: x.initialRect.width, height: x.initialRect.height }), { ...x, - el: D, - finalRect: M + el: M, + finalRect: D }; }) }; } ); - const I = { + const A = { translateX: i, translateY: d, scaleX: u, scaleY: a }; - t.el().style.transformOrigin = "0 0", t.el().style.borderRadius = z( + t.el().style.transformOrigin = "0 0", t.el().style.borderRadius = G( h - ), t.setTransform(I), c = [], f.forEach(({ parent: E, children: p }) => { + ), t.setTransform(A), c = [], f.forEach(({ parent: E, children: p }) => { const w = p.map( - ({ el: A, initialRect: x, finalRect: X, borderRadius: D }) => Yt( - A, + ({ el: I, initialRect: x, finalRect: X, borderRadius: M }) => Ct( + I, x, X, - D, + M, E.initialRect, E.finalRect ) @@ -381,20 +404,20 @@ function K(t) { return c; } return { - readInitial: m, + readInitial: y, readFinalAndReverse: v, transitionValues: g, childrenTransitionData: T }; } -function Yt(t, e, n, o, l, i) { +function Ct(t, e, n, o, l, i) { t.style.transformOrigin = "0 0"; const d = l.width / i.width, u = l.height / i.height, a = e.width / n.width, h = e.height / n.height, s = ht( o, a, h - ), c = e.x - l.x, f = n.x - i.x, m = e.y - l.y, v = n.y - i.y, g = (c - f * d) / d, T = (m - v * u) / u; - return t.style.transform = `translate(${g}px, ${T}px) scale(${a / d}, ${h / u})`, t.style.borderRadius = z(s), { + ), c = e.x - l.x, f = n.x - i.x, y = e.y - l.y, v = n.y - i.y, g = (c - f * d) / d, T = (y - v * u) / u; + return t.style.transform = `translate(${g}px, ${T}px) scale(${a / d}, ${h / u})`, t.style.borderRadius = G(s), { el: t, fromTranslate: R(g, T), fromScale: R(a, h), @@ -406,7 +429,9 @@ function Yt(t, e, n, o, l, i) { function ct(t) { const e = []; function n(o) { - const l = Array.from(o.children); + const l = Array.from(o.children).filter( + (i) => i instanceof HTMLElement + ); l.length > 0 && (e.push({ parent: o, children: l @@ -414,7 +439,7 @@ function ct(t) { } return n(t), e; } -function mt(t) { +function yt(t) { const e = []; let n = t, o = { dragX: 0, @@ -432,8 +457,8 @@ function mt(t) { clearTransform: u, currentTransform: () => o, borderRadius: () => l, - layoutRect: () => Z(n), - boundingRect: () => k(n.getBoundingClientRect()), + layoutRect: () => J(n), + boundingRect: () => z(n.getBoundingClientRect()), usePlugin: h, destroy: s, updateElement: c @@ -452,11 +477,11 @@ function mt(t) { }, a(); } function a() { - const { dragX: f, dragY: m, translateX: v, translateY: g, scaleX: T, scaleY: r } = o; - f === 0 && m === 0 && v === 0 && g === 0 && T === 1 && r === 1 ? n.style.transform = "" : n.style.transform = `translate(${f + v}px, ${m + g}px) scale(${T}, ${r})`; + const { dragX: f, dragY: y, translateX: v, translateY: g, scaleX: T, scaleY: r } = o; + f === 0 && y === 0 && v === 0 && g === 0 && T === 1 && r === 1 ? n.style.transform = "" : n.style.transform = `translate(${f + v}px, ${y + g}px) scale(${T}, ${r})`; } - function h(f, m) { - const v = f(i, m); + function h(f, y) { + const v = f(i, y); return e.push(v), v; } function s() { @@ -464,25 +489,25 @@ function mt(t) { } function c(f) { if (!f) return; - const m = n.style.cssText; - n = f, n.style.cssText = m, e.forEach((v) => v.onElementUpdate()); + const y = n.hasAttribute("data-swapy-dragging"), v = n.style.cssText; + n = f, y && n.setAttribute("data-swapy-dragging", ""), n.style.cssText = v, e.forEach((g) => g.onElementUpdate()); } return i; } -function Ct(t, e, n) { +function Rt(t, e, n) { return n.map((o) => ({ slotId: o.slot, itemId: o.item, item: o.item === "" ? null : t.find((l) => o.item === l[e]) })); } -function Rt(t, e) { +function Ht(t, e) { return t.map((n) => ({ item: n[e], slot: n[e] })); } -function Ht(t, e, n, o, l, i = !1) { +function $t(t, e, n, o, l, i = !1) { const d = e.filter( (h) => !o.some((s) => s.item === h[n]) ).map((h) => ({ @@ -503,10 +528,10 @@ function Ht(t, e, n, o, l, i = !1) { } const jt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, - dynamicSwapy: Ht, - initSlotItemMap: Rt, - toSlottedItems: Ct -}, Symbol.toStringTag, { value: "Module" })), $t = { + dynamicSwapy: $t, + initSlotItemMap: Ht, + toSlottedItems: Rt +}, Symbol.toStringTag, { value: "Module" })), Bt = { animation: "dynamic", enabled: !0, swapMode: "hover", @@ -520,34 +545,34 @@ function wt(t) { case "dynamic": return { easing: bt, duration: 300 }; case "spring": - return { easing: Mt, duration: 350 }; + return { easing: Dt, duration: 350 }; case "none": return { easing: (e) => e, duration: 1 }; } } -function Wt(t, e) { - const n = { ...$t, ...e }, o = Bt({ slots: [], items: [], config: n }); +function kt(t, e) { + const n = { ...Bt, ...e }, o = Ot({ slots: [], items: [], config: n }); let l = [], i = []; d(); function d() { - if (!Nt(t)) + if (!qt(t)) throw new Error( "Cannot create a Swapy instance because your HTML structure is invalid. Fix all above errors and then try!" ); l = Array.from(t.querySelectorAll("[data-swapy-slot]")).map( - (r) => Ot(r, o) - ), o.setSlots(l), i = Array.from(t.querySelectorAll("[data-swapy-item]")).map( (r) => _t(r, o) + ), o.setSlots(l), i = Array.from(t.querySelectorAll("[data-swapy-item]")).map( + (r) => Pt(r, o) ), o.setItems(i), o.syncSlotItemMap(), i.forEach((r) => { - r.onDrag(({ pointerX: I, pointerY: E }) => { + r.onDrag(({ pointerX: A, pointerY: E }) => { a(); let p = !1; l.forEach((w) => { - const A = w.rect(); - st({ x: I, y: E }, A) && (p = !0, w.isHighlighted() || w.highlight()); - }), !p && o.config().swapMode === "drop" && r.slot().highlight(), n.swapMode === "hover" && u(r, { pointerX: I, pointerY: E }); - }), r.onDrop(({ pointerX: I, pointerY: E }) => { - h(), n.swapMode === "drop" && u(r, { pointerX: I, pointerY: E }); + const I = w.rect(); + st({ x: A, y: E }, I) && (p = !0, w.isHighlighted() || w.highlight()); + }), !p && o.config().swapMode === "drop" && r.slot().highlight(), n.swapMode === "hover" && u(r, { pointerX: A, pointerY: E }); + }), r.onDrop(({ pointerX: A, pointerY: E }) => { + h(), n.swapMode === "drop" && u(r, { pointerX: A, pointerY: E }); }), r.onHold(() => { a(); }), r.onRelease(() => { @@ -555,15 +580,15 @@ function Wt(t, e) { }); }); } - function u(r, { pointerX: I, pointerY: E }) { + function u(r, { pointerX: A, pointerY: E }) { l.forEach((p) => { const w = p.rect(); - if (st({ x: I, y: E }, w)) { + if (st({ x: A, y: E }, w)) { if (r.id() === p.itemId()) return; o.config().swapMode === "hover" && r.setContinuousDrag(!0); - const A = r.slot(), x = p.item(); + const I = r.slot(), x = p.item(); if (!o.eventHandlers().onBeforeSwap({ - fromSlot: A.id(), + fromSlot: I.id(), toSlot: p.id(), draggingItem: r.id(), swapWithItem: (x == null ? void 0 : x.id()) || "" @@ -572,40 +597,40 @@ function Wt(t, e) { if (o.config().manualSwap) { const X = structuredClone(o.slotItemMap()); o.swapItems(r, p); - const D = o.slotItemMap(), M = K(r.view()); - M.readInitial(); - const H = x ? K(x.view()) : null; + const M = o.slotItemMap(), D = Q(r.view()); + D.readInitial(); + const H = x ? Q(x.view()) : null; H == null || H.readInitial(); let _ = 0, P = 0; - const $ = Q( + const $ = et( r.view().el() ); $ instanceof Window ? (_ = $.scrollY, P = $.scrollX) : (_ = $.scrollTop, P = $.scrollLeft), o.eventHandlers().onSwap({ oldSlotItemMap: X, - newSlotItemMap: D, - fromSlot: A.id(), + newSlotItemMap: M, + fromSlot: I.id(), toSlot: p.id(), draggingItem: r.id(), swappedWithItem: (x == null ? void 0 : x.id()) || "" }), requestAnimationFrame(() => { const N = t.querySelectorAll("[data-swapy-item]"); - o.items().forEach((y) => { + o.items().forEach((m) => { const B = Array.from(N).find( - (L) => L.dataset.swapyItem === y.id() + (L) => L.dataset.swapyItem === m.id() ); - y.view().updateElement(B); - }), o.syncSlotItemMap(), M.readFinalAndReverse(), H == null || H.readFinalAndReverse(), J(r, M), x && H && J(x, H), $.scrollTo({ + m.view().updateElement(B); + }), o.syncSlotItemMap(), D.readFinalAndReverse(), H == null || H.readFinalAndReverse(), tt(r, D), x && H && tt(x, H), $.scrollTo({ left: P, top: _ }); }); } else { - let X = 0, D = 0; - const M = Q( + let X = 0, M = 0; + const D = et( r.view().el() ); - M instanceof Window ? (X = M.scrollY, D = M.scrollX) : (X = M.scrollTop, D = M.scrollLeft), ft(r, p, !0), x && ft(x, A), M.scrollTo({ - left: D, + D instanceof Window ? (X = D.scrollY, M = D.scrollX) : (X = D.scrollTop, M = D.scrollLeft), ft(r, p, !0), x && ft(x, I), D.scrollTo({ + left: M, top: X }); const H = o.slotItemMap(); @@ -614,7 +639,7 @@ function Wt(t, e) { o.eventHandlers().onSwap({ oldSlotItemMap: H, newSlotItemMap: _, - fromSlot: A.id(), + fromSlot: I.id(), toSlot: p.id(), draggingItem: r.id(), swappedWithItem: (x == null ? void 0 : x.id()) || "" @@ -642,7 +667,7 @@ function Wt(t, e) { function f(r) { o.eventHandlers().onSwap = r; } - function m(r) { + function y(r) { o.eventHandlers().onSwapEnd = r; } function v(r) { @@ -661,13 +686,13 @@ function Wt(t, e) { slotItemMap: () => o.slotItemMap(), onSwapStart: c, onSwap: f, - onSwapEnd: m, + onSwapEnd: y, onBeforeSwap: v, update: g, destroy: T }; } -function Bt({ +function Ot({ slots: t, items: e, config: n @@ -705,23 +730,23 @@ function Bt({ return l.items.find((f) => f.id() === c); } function a() { - const c = {}, f = /* @__PURE__ */ new Map(), m = []; + const c = {}, f = /* @__PURE__ */ new Map(), y = []; l.slots.forEach((v) => { var r; const g = v.id(), T = ((r = v.item()) == null ? void 0 : r.id()) || ""; - c[g] = T, f.set(g, T), m.push({ slot: g, item: T }); - }), l.slotItemMap = { asObject: c, asMap: f, asArray: m }; + c[g] = T, f.set(g, T), y.push({ slot: g, item: T }); + }), l.slotItemMap = { asObject: c, asMap: f, asArray: y }; } function h(c, f) { var p; - const m = l.slotItemMap, v = c.id(), g = ((p = f.item()) == null ? void 0 : p.id()) || "", T = f.id(), r = c.slot().id(); - m.asObject[T] = v, m.asObject[r] = g, m.asMap.set(T, v), m.asMap.set(r, g); - const I = m.asArray.findIndex( + const y = l.slotItemMap, v = c.id(), g = ((p = f.item()) == null ? void 0 : p.id()) || "", T = f.id(), r = c.slot().id(); + y.asObject[T] = v, y.asObject[r] = g, y.asMap.set(T, v), y.asMap.set(r, g); + const A = y.asArray.findIndex( (w) => w.slot === T - ), E = m.asArray.findIndex( + ), E = y.asArray.findIndex( (w) => w.slot === r ); - m.asArray[I].item = v, m.asArray[E].item = g; + y.asArray[A].item = v, y.asArray[E].item = g; } function s() { window.removeEventListener("scroll", i), l = { ...o }; @@ -748,8 +773,8 @@ function Bt({ destroy: s }; } -function Ot(t, e) { - const n = mt(t); +function _t(t, e) { + const n = yt(t); function o() { return n.el().dataset.swapySlot; } @@ -758,7 +783,7 @@ function Ot(t, e) { return (s == null ? void 0 : s.dataset.swapyItem) || null; } function i() { - return k(n.el().getBoundingClientRect()); + return z(n.el().getBoundingClientRect()); } function d() { const s = n.el().children[0]; @@ -787,57 +812,59 @@ function Ot(t, e) { destroy: h }; } -function _t(t, e) { - const n = mt(t), o = {}; +function Pt(t, e) { + const n = yt(t), o = {}; let l = null, i = null, d = !1, u = !0, a; - const h = Pt(); + const h = Nt(); let s = () => { }, c = () => { }, f = () => { - }, m = () => { + }, y = () => { }; - const { onDrag: v, onDrop: g, onHold: T, onRelease: r } = n.usePlugin(Dt, { + const { onDrag: v, onDrop: g, onHold: T, onRelease: r } = n.usePlugin(Mt, { startDelay: e.config().dragOnHold ? 400 : 0 - }), I = R(0, 0), E = R(0, 0), p = R(0, 0), w = R(0, 0); - let A = null, x = null; + }), A = R(0, 0), E = R(0, 0), p = R(0, 0), w = R(0, 0); + let I = null, x = null; T((S) => { e.config().enabled && (N() && !$(S.el) || L() && B(S.el) || f == null || f(S)); }), r((S) => { - e.config().enabled && (N() && !$(S.el) || L() && B(S.el) || m == null || m(S)); + e.config().enabled && (N() && !$(S.el) || L() && B(S.el) || y == null || y(S)); }); function X(S) { - var Y; - q(), G().highlight(), (Y = o.drop) == null || Y.call(o), e.slots().forEach((O) => { - const F = O.view().boundingRect(); - O.view().el().style.width = `${F.width}px`, O.view().el().style.flexShrink = "0", O.view().el().style.height = `${F.height}px`; + var q; + F(), K().highlight(), (q = o.drop) == null || q.call(o); + const Y = e.slots().map((O) => O.view().boundingRect()); + e.slots().forEach((O, W) => { + const j = Y[W]; + O.view().el().style.width = `${j.width}px`, O.view().el().style.maxWidth = `${j.width}px`, O.view().el().style.flexShrink = "0", O.view().el().style.height = `${j.height}px`; }); const b = e.slotItemMap(); e.eventHandlers().onSwapStart({ - draggingItem: tt(), - fromSlot: et(), + draggingItem: nt(), + fromSlot: ot(), slotItemMap: b - }), i = b, n.el().style.position = "relative", n.el().style.zIndex = `${e.zIndex(!0)}`, A = Q(S.el), e.config().autoScrollOnDrag && (l = Ft( - A, + }), i = b, n.el().style.position = "relative", n.el().style.zIndex = `${e.zIndex(!0)}`, I = et(S.el), e.config().autoScrollOnDrag && (l = Wt( + I, e.config().dragAxis ), l.updatePointer({ x: S.pointerX, y: S.pointerY - })), I.x = window.scrollX, I.y = window.scrollY, p.x = 0, p.y = 0, A instanceof HTMLElement && (E.x = A.scrollLeft, E.y = A.scrollTop, x = () => { - w.x = A.scrollLeft - E.x, w.y = A.scrollTop - E.y, n.setTransform({ + })), A.x = window.scrollX, A.y = window.scrollY, p.x = 0, p.y = 0, I instanceof HTMLElement && (E.x = I.scrollLeft, E.y = I.scrollTop, x = () => { + w.x = I.scrollLeft - E.x, w.y = I.scrollTop - E.y, n.setTransform({ dragX: ((a == null ? void 0 : a.width) || 0) + p.x + w.x, dragY: ((a == null ? void 0 : a.height) || 0) + p.y + w.y }); - }, A.addEventListener("scroll", x)), e.onScroll(() => { - p.x = window.scrollX - I.x, p.y = window.scrollY - I.y; - const O = w.x || 0, F = w.y || 0; + }, I.addEventListener("scroll", x)), e.onScroll(() => { + p.x = window.scrollX - A.x, p.y = window.scrollY - A.y; + const O = w.x || 0, W = w.y || 0; n.setTransform({ dragX: ((a == null ? void 0 : a.width) || 0) + p.x + O, - dragY: ((a == null ? void 0 : a.height) || 0) + p.y + F + dragY: ((a == null ? void 0 : a.height) || 0) + p.y + W }); }); } v((S) => { - var b; + var Y; if (e.config().enabled) { if (!d) { if (N() && !$(S.el) || L() && B(S.el)) @@ -847,42 +874,42 @@ function _t(t, e) { d = !0, l && l.updatePointer({ x: S.pointerX, y: S.pointerY - }), a = S, (b = o.drop) == null || b.call(o), h(() => { + }), a = S, (Y = o.drop) == null || Y.call(o), h(() => { n.el().style.position = "relative"; - const Y = S.width + p.x + w.x, O = S.height + p.y + w.y; + const b = S.width + p.x + w.x, q = S.height + p.y + w.y; e.config().dragAxis === "y" ? n.setTransform({ - dragY: O + dragY: q }) : e.config().dragAxis === "x" ? n.setTransform({ - dragX: Y + dragX: b }) : n.setTransform({ - dragX: Y, - dragY: O + dragX: b, + dragY: q }), s == null || s(S); }); } }), g((S) => { if (!d) return; - U(), d = !1, u = !1, a = null, A && (A.removeEventListener("scroll", x), x = null), A = null, w.x = 0, w.y = 0, p.x = 0, p.y = 0, l && (l.destroy(), l = null), G().unhighlightAllSlots(), c == null || c(S), e.eventHandlers().onSwapEnd({ + Z(), d = !1, u = !1, a = null, I && (I.removeEventListener("scroll", x), x = null), I = null, w.x = 0, w.y = 0, p.x = 0, p.y = 0, l && (l.destroy(), l = null), K().unhighlightAllSlots(), c == null || c(S), e.eventHandlers().onSwapEnd({ slotItemMap: e.slotItemMap(), - hasChanged: i != null && i.asMap ? !qt( + hasChanged: i != null && i.asMap ? !Ft( i == null ? void 0 : i.asMap, e.slotItemMap().asMap ) : !1 - }), i = null, e.onScroll(null), e.slots().forEach((Y) => { - Y.view().el().style.width = "", Y.view().el().style.flexShrink = "", Y.view().el().style.height = ""; - }), e.config().manualSwap && e.config().swapMode === "drop" ? requestAnimationFrame(b) : b(); - function b() { - const Y = n.currentTransform(), O = Y.dragX + Y.translateX, F = Y.dragY + Y.translateY; - o.drop = yt( - { translate: R(O, F) }, + }), i = null, e.onScroll(null), e.slots().forEach((b) => { + b.view().el().style.width = "", b.view().el().style.maxWidth = "", b.view().el().style.flexShrink = "", b.view().el().style.height = ""; + }), e.config().manualSwap && e.config().swapMode === "drop" ? requestAnimationFrame(Y) : Y(); + function Y() { + const b = n.currentTransform(), q = b.dragX + b.translateX, O = b.dragY + b.translateY; + o.drop = mt( + { translate: R(q, O) }, { translate: R(0, 0) }, - ({ translate: nt }, ot) => { - ot ? d || (n.clearTransform(), n.el().style.transformOrigin = "") : n.setTransform({ + ({ translate: W }, j) => { + j ? d || (n.clearTransform(), n.el().style.transformOrigin = "") : n.setTransform({ dragX: 0, dragY: 0, - translateX: nt.x, - translateY: nt.y - }), ot && (e.items().forEach((lt) => { + translateX: W.x, + translateY: W.y + }), j && (e.items().forEach((lt) => { lt.isDragging() || (lt.view().el().style.zIndex = ""); }), e.resetZIndex(), n.el().style.position = "", u = !0); }, @@ -890,63 +917,63 @@ function _t(t, e) { ); } }); - function D(S) { + function M(S) { s = S; } - function M(S) { + function D(S) { c = S; } function H(S) { f = S; } function _(S) { - m = S; + y = S; } function P() { return n.el().querySelector("[data-swapy-handle]"); } function $(S) { - const b = P(); - return b ? b === S || b.contains(S) : !1; + const Y = P(); + return Y ? Y === S || Y.contains(S) : !1; } function N() { return P() !== null; } - function y() { + function m() { return Array.from(n.el().querySelectorAll("[data-swapy-no-drag]")); } function B(S) { - const b = y(); - return !b || b.length === 0 ? !1 : b.includes(S) || b.some((Y) => Y.contains(S)); + const Y = m(); + return !Y || Y.length === 0 ? !1 : Y.includes(S) || Y.some((b) => b.contains(S)); } function L() { - return y().length > 0; + return m().length > 0; } - function q() { + function F() { n.el().setAttribute("data-swapy-dragging", ""); } - function U() { + function Z() { n.el().removeAttribute("data-swapy-dragging"); } function St() { - s = null, c = null, f = null, m = null, a = null, i = null, l && (l.destroy(), l = null), A && x && A.removeEventListener("scroll", x), n.destroy(); + s = null, c = null, f = null, y = null, a = null, i = null, l && (l.destroy(), l = null), I && x && I.removeEventListener("scroll", x), n.destroy(); } - function tt() { + function nt() { return n.el().dataset.swapyItem; } - function G() { + function K() { return e.slotById(n.el().parentElement.dataset.swapySlot); } - function et() { + function ot() { return n.el().parentElement.dataset.swapySlot; } return { - id: tt, + id: nt, view: () => n, - slot: G, - slotId: et, - onDrag: D, - onDrop: M, + slot: K, + slotId: ot, + onDrag: M, + onDrop: D, onHold: H, onRelease: _, destroy: St, @@ -968,10 +995,10 @@ function ft(t, e, n = !1) { } if (!t) return; - const o = K(t.view()); - o.readInitial(), e.view().el().appendChild(t.view().el()), o.readFinalAndReverse(), J(t, o); + const o = Q(t.view()); + o.readInitial(), e.view().el().appendChild(t.view().el()), o.readFinalAndReverse(), tt(t, o); } -function Pt() { +function Nt() { let t = !1; return (e) => { t || (t = !0, requestAnimationFrame(() => { @@ -979,12 +1006,12 @@ function Pt() { })); }; } -function J(t, e) { +function tt(t, e) { var u, a, h, s; (a = (u = t.cancelAnimation()).moveToSlot) == null || a.call(u), (s = (h = t.cancelAnimation()).drop) == null || s.call(h); const n = wt(t.store().config().animation), o = e.transitionValues(); let l = t.view().currentTransform(), i = 0, d = !1; - t.cancelAnimation().moveToSlot = yt( + t.cancelAnimation().moveToSlot = mt( { translate: o.from.translate, scale: o.from.scale, @@ -995,10 +1022,10 @@ function J(t, e) { scale: o.to.scale, borderRadius: o.to.borderRadius }, - ({ translate: c, scale: f, borderRadius: m }, v, g) => { + ({ translate: c, scale: f, borderRadius: y }, v, g) => { if (t.isDragging()) { i !== 0 && (d = !0); - const r = t.dragEvent().relativeX, I = t.dragEvent().relativeY; + const r = t.dragEvent().relativeX, A = t.dragEvent().relativeY; t.continuousDrag() ? t.view().setTransform({ translateX: C( l.translateX, @@ -1007,7 +1034,7 @@ function J(t, e) { ), translateY: C( l.translateY, - l.translateY + (o.from.height - o.to.height) * I, + l.translateY + (o.from.height - o.to.height) * A, n.easing(g - i) ), scaleX: f.x, @@ -1029,22 +1056,22 @@ function J(t, e) { T.forEach( ({ el: r, - fromTranslate: I, + fromTranslate: A, fromScale: E, fromBorderRadius: p, toBorderRadius: w, - parentScale: A + parentScale: I }) => { const x = C( - A.x, + I.x, 1, n.easing(g) ), X = C( - A.y, + I.y, 1, n.easing(g) ); - r.style.transform = `translate(${I.x + (0 - I.x / x) * n.easing(g)}px, ${I.y + (0 - I.y / X) * n.easing(g)}px) scale(${C( + r.style.transform = `translate(${A.x + (0 - A.x / x) * n.easing(g)}px, ${A.y + (0 - A.y / X) * n.easing(g)}px) scale(${C( E.x / x, 1 / x, n.easing(g) @@ -1052,7 +1079,7 @@ function J(t, e) { E.y / X, 1 / X, n.easing(g) - )})`, it(p) || (r.style.borderRadius = z( + )})`, it(p) || (r.style.borderRadius = G( pt( p, w, @@ -1060,23 +1087,23 @@ function J(t, e) { ) )); } - ), it(m) || (t.view().el().style.borderRadius = z(m)), v && (t.isDragging() || (t.view().el().style.transformOrigin = "", t.view().clearTransform()), t.view().el().style.borderRadius = "", T.forEach(({ el: r }) => { + ), it(y) || (t.view().el().style.borderRadius = G(y)), v && (t.isDragging() || (t.view().el().style.transformOrigin = "", t.view().clearTransform()), t.view().el().style.borderRadius = "", T.forEach(({ el: r }) => { r.style.transform = "", r.style.transformOrigin = "", r.style.borderRadius = ""; })); }, n ); } -function j(...t) { +function k(...t) { console.error("Swapy Error:", ...t); } -function Nt(t) { +function qt(t) { const e = t; let n = !0; const o = e.querySelectorAll("[data-swapy-slot]"); - e || (j("container passed to createSwapy() is undefined or null"), n = !1), o.forEach((u) => { + e || (k("container passed to createSwapy() is undefined or null"), n = !1), o.forEach((u) => { const a = u, h = a.dataset.swapySlot, s = a.children, c = s[0]; - (!h || h.length === 0) && (j(a, "does not contain a slotId using data-swapy-slot"), n = !1), s.length > 1 && (j("slot:", `"${h}"`, "cannot contain more than one element"), n = !1), c && (!c.dataset.swapyItem || c.dataset.swapyItem.length === 0) && (j( + (!h || h.length === 0) && (k(a, "does not contain a slotId using data-swapy-slot"), n = !1), s.length > 1 && (k("slot:", `"${h}"`, "cannot contain more than one element"), n = !1), c && (!c.dataset.swapyItem || c.dataset.swapyItem.length === 0) && (k( "slot", `"${h}"`, "does not contain an element with an item id using data-swapy-item" @@ -1089,14 +1116,14 @@ function Nt(t) { ); if (ut(l)) { const u = dt(l); - j( + k( "your container has duplicate slot ids", `(${u.join(", ")})` ), n = !1; } if (ut(d)) { const u = dt(d); - j( + k( "your container has duplicate item ids", `(${u.join(", ")})` ), n = !1; @@ -1112,13 +1139,13 @@ function dt(t) { e.has(o) ? n.add(o) : e.add(o); return Array.from(n); } -function qt(t, e) { +function Ft(t, e) { if (t.size !== e.size) return !1; for (const [n, o] of t) if (e.get(n) !== o) return !1; return !0; } -function Q(t) { +function et(t) { let e = t; for (; e; ) { const n = window.getComputedStyle(e), o = n.overflowY, l = n.overflowX; @@ -1128,52 +1155,52 @@ function Q(t) { } return window; } -function Ft(t, e) { +function Wt(t, e) { let l = !1, i, d = 0, u = 0, a = 0, h = 0, s = 0, c = 0, f = null; - t instanceof HTMLElement ? (i = k(t.getBoundingClientRect()), d = t.scrollHeight - i.height, u = t.scrollWidth - i.width) : (i = { + t instanceof HTMLElement ? (i = z(t.getBoundingClientRect()), d = t.scrollHeight - i.height, u = t.scrollWidth - i.width) : (i = { x: 0, y: 0, width: window.innerWidth, height: window.innerHeight }, d = document.documentElement.scrollHeight - window.innerHeight, u = document.documentElement.scrollWidth - window.innerWidth); - function m() { + function y() { t instanceof HTMLElement ? (a = t.scrollTop, h = t.scrollLeft) : (a = window.scrollY, h = window.scrollX); } function v(r) { l = !1; - const I = i.y, E = i.y + i.height, p = i.x, w = i.x + i.width, A = Math.abs(I - r.y) < Math.abs(E - r.y), x = Math.abs(p - r.x) < Math.abs(w - r.x); - if (m(), e !== "x") - if (A) { - const X = I - r.y; + const A = i.y, E = i.y + i.height, p = i.x, w = i.x + i.width, I = Math.abs(A - r.y) < Math.abs(E - r.y), x = Math.abs(p - r.x) < Math.abs(w - r.x); + if (y(), e !== "x") + if (I) { + const X = A - r.y; if (X >= -100) { - const D = W(X, -100, 0); - s = -V(-100, 0, 0, 5, D), l = !0; + const M = V(X, -100, 0); + s = -U(-100, 0, 0, 5, M), l = !0; } } else { const X = E - r.y; if (X <= 100) { - const D = W(X, 0, 100); - s = V(100, 0, 0, 5, D), l = !0; + const M = V(X, 0, 100); + s = U(100, 0, 0, 5, M), l = !0; } } if (e !== "y") if (x) { const X = p - r.x; if (X >= -100) { - const D = W(X, -100, 0); - c = -V(-100, 0, 0, 5, D), l = !0; + const M = V(X, -100, 0); + c = -U(-100, 0, 0, 5, M), l = !0; } } else { const X = w - r.x; if (X <= 100) { - const D = W(X, 0, 100); - c = V(100, 0, 0, 5, D), l = !0; + const M = V(X, 0, 100); + c = U(100, 0, 0, 5, M), l = !0; } } l && (f && cancelAnimationFrame(f), g()); } function g() { - m(), e !== "x" && (s = a + s >= d ? 0 : s), e !== "y" && (c = h + c >= u ? 0 : c), t.scrollBy({ top: s, left: c }), l && (f = requestAnimationFrame(g)); + y(), e !== "x" && (s = a + s >= d ? 0 : s), e !== "y" && (c = h + c >= u ? 0 : c), t.scrollBy({ top: s, left: c }), l && (f = requestAnimationFrame(g)); } function T() { l = !1; @@ -1184,7 +1211,7 @@ function Ft(t, e) { }; } export { - Wt as createSwapy, - Q as getClosestScrollableContainer, + kt as createSwapy, + et as getClosestScrollableContainer, jt as utils }; diff --git a/dist/swapy.min.js b/dist/swapy.min.js index c676db3..764ecc5 100644 --- a/dist/swapy.min.js +++ b/dist/swapy.min.js @@ -1,5 +1,5 @@ -(function(P,F){typeof exports=="object"&&typeof module<"u"?F(exports):typeof define=="function"&&define.amd?define(["exports"],F):(P=typeof globalThis<"u"?globalThis:P||self,F(P.Swapy={}))})(this,function(P){"use strict";function F(t){return typeof t=="object"&&t!==null&&"x"in t&&"y"in t&&"unit"in t&&typeof t.unit=="string"&&typeof t.x=="object"&&typeof t.y=="object"&&"topLeft"in t.x&&"topRight"in t.x&&"bottomRight"in t.x&&"bottomLeft"in t.x&&"topLeft"in t.y&&"topRight"in t.y&&"bottomRight"in t.y&&"bottomLeft"in t.y}function nt(t){var h;const e=t.match(/(\d+(?:\.\d+)?)(px|%)/g);if(!e)return{x:{topLeft:0,topRight:0,bottomRight:0,bottomLeft:0},y:{topLeft:0,topRight:0,bottomRight:0,bottomLeft:0},unit:"px"};const n=e.map(a=>{const[c,f,m]=a.match(/(\d+(?:\.\d+)?)(px|%)/)??[];return{value:parseFloat(f),unit:m}}),o=((h=n[0])==null?void 0:h.unit)||"px";if(n.some(a=>a.unit!==o))throw new Error("Inconsistent units in border-radius string.");const[l,i,d,u]=n.map(a=>a.value),s={topLeft:l??0,topRight:i??l??0,bottomRight:d??l??0,bottomLeft:u??i??l??0};return{x:{...s},y:{...s},unit:o}}function ot({x:t,y:e,unit:n},o,l){if(n==="px"){const i={topLeft:t.topLeft/o,topRight:t.topRight/o,bottomLeft:t.bottomLeft/o,bottomRight:t.bottomRight/o},d={topLeft:e.topLeft/l,topRight:e.topRight/l,bottomLeft:e.bottomLeft/l,bottomRight:e.bottomRight/l};return{x:i,y:d,unit:"px"}}else if(n==="%")return{x:t,y:e,unit:"%"};return{x:t,y:e,unit:n}}function U(t){return` +(function(P,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(P=typeof globalThis<"u"?globalThis:P||self,j(P.Swapy={}))})(this,function(P){"use strict";function j(t){return typeof t=="object"&&t!==null&&"x"in t&&"y"in t&&"unit"in t&&typeof t.unit=="string"&&typeof t.x=="object"&&typeof t.y=="object"&&"topLeft"in t.x&&"topRight"in t.x&&"bottomRight"in t.x&&"bottomLeft"in t.x&&"topLeft"in t.y&&"topRight"in t.y&&"bottomRight"in t.y&&"bottomLeft"in t.y}function lt(t){var h;const e=t.match(/(\d+(?:\.\d+)?)(px|%)/g);if(!e)return{x:{topLeft:0,topRight:0,bottomRight:0,bottomLeft:0},y:{topLeft:0,topRight:0,bottomRight:0,bottomLeft:0},unit:"px"};const n=e.map(a=>{const[c,f,m]=a.match(/(\d+(?:\.\d+)?)(px|%)/)??[];return{value:parseFloat(f),unit:m}}),o=((h=n[0])==null?void 0:h.unit)||"px";if(n.some(a=>a.unit!==o))throw new Error("Inconsistent units in border-radius string.");const[l,r,d,u]=n.map(a=>a.value),s={topLeft:l??0,topRight:r??l??0,bottomRight:d??l??0,bottomLeft:u??r??l??0};return{x:{...s},y:{...s},unit:o}}function it({x:t,y:e,unit:n},o,l){if(n==="px"){const r={topLeft:t.topLeft/o,topRight:t.topRight/o,bottomLeft:t.bottomLeft/o,bottomRight:t.bottomRight/o},d={topLeft:e.topLeft/l,topRight:e.topRight/l,bottomLeft:e.bottomLeft/l,bottomRight:e.bottomRight/l};return{x:r,y:d,unit:"px"}}else if(n==="%")return{x:t,y:e,unit:"%"};return{x:t,y:e,unit:n}}function Z(t){return` ${t.x.topLeft}${t.unit} ${t.x.topRight}${t.unit} ${t.x.bottomRight}${t.unit} ${t.x.bottomLeft}${t.unit} / ${t.y.topLeft}${t.unit} ${t.y.topRight}${t.unit} ${t.y.bottomRight}${t.unit} ${t.y.bottomLeft}${t.unit} - `}function lt(t){return t.x.topLeft===0&&t.x.topRight===0&&t.x.bottomRight===0&&t.x.bottomLeft===0&&t.y.topLeft===0&&t.y.topRight===0&&t.y.bottomRight===0&&t.y.bottomLeft===0}function rt(t){return typeof t=="object"&&"x"in t&&"y"in t}function R(t,e){return{x:t,y:e}}function xt(t,e){return R(t.x+e.x,t.y+e.y)}function vt(t,e){return R(t.x-e.x,t.y-e.y)}function It(t,e){return R(t.x*e,t.y*e)}function L(t,e,n){return t+(e-t)*n}function At(t,e,n){return xt(t,It(vt(e,t),n))}function it(t,e,n){return{x:{topLeft:L(t.x.topLeft,e.x.topLeft,n),topRight:L(t.x.topRight,e.x.topRight,n),bottomRight:L(t.x.bottomRight,e.x.bottomRight,n),bottomLeft:L(t.x.bottomLeft,e.x.bottomLeft,n)},y:{topLeft:L(t.y.topLeft,e.y.topLeft,n),topRight:L(t.y.topRight,e.y.topRight,n),bottomRight:L(t.y.bottomRight,e.y.bottomRight,n),bottomLeft:L(t.y.bottomLeft,e.y.bottomLeft,n)},unit:t.unit}}function Et(t,e,n){return j((n-t)/(e-t),0,1)}function G(t,e,n,o,l){return L(n,o,Et(t,e,l))}function j(t,e,n){return Math.min(Math.max(t,e),n)}const Tt={duration:350,easing:t=>t};function st(t,e,n,o){let l=!1;const i=()=>{l=!0},d={...Tt,...o};let u;function s(h){u===void 0&&(u=h);const a=h-u,c=j(a/d.duration,0,1),f=Object.keys(t),m=Object.keys(e);if(!f.every(g=>m.includes(g))){console.error("animate Error: `from` keys are different than `to`");return}const v={};f.forEach(g=>{typeof t[g]=="number"&&typeof e[g]=="number"?v[g]=L(t[g],e[g],d.easing(c)):F(t[g])&&F(e[g])?v[g]=it(t[g],e[g],d.easing(c)):rt(t[g])&&rt(e[g])&&(v[g]=At(t[g],e[g],d.easing(c)))}),n(v,c>=1,c),c<1&&!l&&requestAnimationFrame(s)}return requestAnimationFrame(s),i}const Xt={startDelay:0};function Mt(t,e){const n={...Xt,...e};let o=t.el(),l=!1,i=null,d=null,u=null,s=null,h=0,a=0,c=0,f=0,m=0,v=0,g=0,X=0,r=0,I=0,E=null,p;o.addEventListener("pointerdown",w),document.body.addEventListener("pointerup",x),document.body.addEventListener("pointermove",T),document.body.addEventListener("touchmove",M,{passive:!1});function w(y){if(l||!y.isPrimary)return;n.startDelay>0?(u==null||u({el:y.target}),p=setTimeout(()=>{B()},n.startDelay)):B();function B(){E=y.target;const Y=t.boundingRect(),k=t.layoutRect();m=k.x,v=k.y,c=Y.x-m,f=Y.y-v,h=y.clientX-c,a=y.clientY-f,g=y.clientX,X=y.clientY,r=(y.clientX-Y.x)/Y.width,I=(y.clientY-Y.y)/Y.height,l=!0,T(y)}}function A(){const y=t.layoutRect();h-=m-y.x,a-=v-y.y,m=y.x,v=y.y}function x(y){if(!l){p&&(clearTimeout(p),p=null,s==null||s({el:y.target}));return}if(!y.isPrimary)return;l=!1;const B=y.clientX-g,Y=y.clientY-X;d==null||d({x:c,y:f,pointerX:y.clientX,pointerY:y.clientY,width:B,height:Y,relativeX:r,relativeY:I,el:E}),E=null}function T(y){if(!l){p&&(clearTimeout(p),p=null,s==null||s({el:y.target}));return}if(!y.isPrimary)return;const B=y.clientX-g,Y=y.clientY-X,k=c=y.clientX-h,tt=f=y.clientY-a;i==null||i({width:B,height:Y,x:k,y:tt,pointerX:y.clientX,pointerY:y.clientY,relativeX:r,relativeY:I,el:E})}function M(y){if(!l)return!0;y.preventDefault()}function D(y){i=y}function H(y){d=y}function _(y){u=y}function N(y){s=y}function $(){o.removeEventListener("pointerdown",w),o=t.el(),o.addEventListener("pointerdown",w)}function q(){t.el().removeEventListener("pointerdown",w),document.body.removeEventListener("pointerup",x),document.body.removeEventListener("pointermove",T),document.body.removeEventListener("touchmove",M),i=null,d=null,u=null,s=null}return{onDrag:D,onDrop:H,onHold:_,onRelease:N,onElementUpdate:$,destroy:q,readjust:A}}function Dt(t){return 1+2.70158*Math.pow(t-1,3)+1.70158*Math.pow(t-1,2)}function bt(t){return 1-Math.pow(1-t,3)}function z(t){return{x:t.x,y:t.y,width:t.width,height:t.height}}function K(t){let e=t,n=0,o=0;for(;e;)n+=e.offsetTop,o+=e.offsetLeft,e=e.offsetParent;return{x:o,y:n,width:t.offsetWidth,height:t.offsetHeight}}function at(t,e){return t.x>=e.x&&t.x<=e.x+e.width&&t.y>=e.y&&t.y<=e.y+e.height}function Lt(t){let e=t,n=0,o=0;for(;e;){const l=i=>{const d=getComputedStyle(i);return/(auto|scroll)/.test(d.overflow+d.overflowY+d.overflowX)};if(e===document.body){o+=window.scrollX,n+=window.scrollY;break}l(e)&&(o+=e.scrollLeft,n+=e.scrollTop),e=e.parentElement}return{x:o,y:n}}function J(t){let e="unread",n,o,l,i,d,u,s,h,a,c,f;function m(){n=t.currentTransform(),o=t.boundingRect(),l=Lt(t.el()),f=ct(t.el()).map(({parent:I,children:E})=>({parent:{el:I,initialRect:z(I.getBoundingClientRect())},children:E.map(p=>{const w=p;return w.originalBorderRadius||(w.originalBorderRadius=getComputedStyle(p).borderRadius),{el:p,borderRadius:nt(w.originalBorderRadius),initialRect:z(p.getBoundingClientRect())}})})),e="readInitial"}function v(){if(e!=="readInitial")throw new Error("FlipView: Cannot read final values before reading initial values");a=t.layoutRect(),u=o.width/a.width,s=o.height/a.height,i=o.x-a.x-n.dragX+l.x,d=o.y-a.y-n.dragY+l.y,h=ot(t.borderRadius(),u,s);const r=ct(t.el());f=f.map(({parent:E,children:p},w)=>{const A=r[w].parent;return{parent:{...E,el:A,finalRect:K(A)},children:p.map((x,T)=>{const M=r[w].children[T];let D=K(M);return M.hasAttribute("data-swapy-text")&&(D={...D,width:x.initialRect.width,height:x.initialRect.height}),{...x,el:M,finalRect:D}})}});const I={translateX:i,translateY:d,scaleX:u,scaleY:s};t.el().style.transformOrigin="0 0",t.el().style.borderRadius=U(h),t.setTransform(I),c=[],f.forEach(({parent:E,children:p})=>{const w=p.map(({el:A,initialRect:x,finalRect:T,borderRadius:M})=>Yt(A,x,T,M,E.initialRect,E.finalRect));c.push(...w)}),e="readFinal"}function g(){if(e!=="readFinal")throw new Error("FlipView: Cannot get transition values before reading");return{from:{width:o.width,height:o.height,translate:R(i,d),scale:R(u,s),borderRadius:h},to:{width:a.width,height:a.height,translate:R(0,0),scale:R(1,1),borderRadius:t.borderRadius()}}}function X(){if(e!=="readFinal")throw new Error("FlipView: Cannot get children transition values before reading");return c}return{readInitial:m,readFinalAndReverse:v,transitionValues:g,childrenTransitionData:X}}function Yt(t,e,n,o,l,i){t.style.transformOrigin="0 0";const d=l.width/i.width,u=l.height/i.height,s=e.width/n.width,h=e.height/n.height,a=ot(o,s,h),c=e.x-l.x,f=n.x-i.x,m=e.y-l.y,v=n.y-i.y,g=(c-f*d)/d,X=(m-v*u)/u;return t.style.transform=`translate(${g}px, ${X}px) scale(${s/d}, ${h/u})`,t.style.borderRadius=U(a),{el:t,fromTranslate:R(g,X),fromScale:R(s,h),fromBorderRadius:a,toBorderRadius:o,parentScale:{x:d,y:u}}}function ct(t){const e=[];function n(o){const l=Array.from(o.children);l.length>0&&(e.push({parent:o,children:l}),l.forEach(i=>n(i)))}return n(t),e}function ft(t){const e=[];let n=t,o={dragX:0,dragY:0,translateX:0,translateY:0,scaleX:1,scaleY:1};const l=nt(window.getComputedStyle(n).borderRadius),i={el:()=>n,setTransform:d,clearTransform:u,currentTransform:()=>o,borderRadius:()=>l,layoutRect:()=>K(n),boundingRect:()=>z(n.getBoundingClientRect()),usePlugin:h,destroy:a,updateElement:c};function d(f){o={...o,...f},s()}function u(){o={dragX:0,dragY:0,translateX:0,translateY:0,scaleX:1,scaleY:1},s()}function s(){const{dragX:f,dragY:m,translateX:v,translateY:g,scaleX:X,scaleY:r}=o;f===0&&m===0&&v===0&&g===0&&X===1&&r===1?n.style.transform="":n.style.transform=`translate(${f+v}px, ${m+g}px) scale(${X}, ${r})`}function h(f,m){const v=f(i,m);return e.push(v),v}function a(){e.forEach(f=>f.destroy())}function c(f){if(!f)return;const m=n.style.cssText;n=f,n.style.cssText=m,e.forEach(v=>v.onElementUpdate())}return i}function Ct(t,e,n){return n.map(o=>({slotId:o.slot,itemId:o.item,item:o.item===""?null:t.find(l=>o.item===l[e])}))}function Rt(t,e){return t.map(n=>({item:n[e],slot:n[e]}))}function Ht(t,e,n,o,l,i=!1){const d=e.filter(h=>!o.some(a=>a.item===h[n])).map(h=>({slot:h[n],item:h[n]}));let u;i?u=o.map(h=>e.some(a=>a[n]===h.item)?h:{slot:h.slot,item:""}):u=o.filter(h=>e.some(a=>a[n]===h.item)||!h.item);const s=[...u,...d];l(s),(d.length>0||u.length!==o.length)&&requestAnimationFrame(()=>{t==null||t.update()})}const $t=Object.freeze(Object.defineProperty({__proto__:null,dynamicSwapy:Ht,initSlotItemMap:Rt,toSlottedItems:Ct},Symbol.toStringTag,{value:"Module"})),Bt={animation:"dynamic",enabled:!0,swapMode:"hover",dragOnHold:!1,autoScrollOnDrag:!1,dragAxis:"both",manualSwap:!1};function ut(t){switch(t){case"dynamic":return{easing:bt,duration:300};case"spring":return{easing:Dt,duration:350};case"none":return{easing:e=>e,duration:1}}}function Ot(t,e){const n={...Bt,...e},o=_t({slots:[],items:[],config:n});let l=[],i=[];d();function d(){if(!Ft(t))throw new Error("Cannot create a Swapy instance because your HTML structure is invalid. Fix all above errors and then try!");l=Array.from(t.querySelectorAll("[data-swapy-slot]")).map(r=>Pt(r,o)),o.setSlots(l),i=Array.from(t.querySelectorAll("[data-swapy-item]")).map(r=>Nt(r,o)),o.setItems(i),o.syncSlotItemMap(),i.forEach(r=>{r.onDrag(({pointerX:I,pointerY:E})=>{s();let p=!1;l.forEach(w=>{const A=w.rect();at({x:I,y:E},A)&&(p=!0,w.isHighlighted()||w.highlight())}),!p&&o.config().swapMode==="drop"&&r.slot().highlight(),n.swapMode==="hover"&&u(r,{pointerX:I,pointerY:E})}),r.onDrop(({pointerX:I,pointerY:E})=>{h(),n.swapMode==="drop"&&u(r,{pointerX:I,pointerY:E})}),r.onHold(()=>{s()}),r.onRelease(()=>{h()})})}function u(r,{pointerX:I,pointerY:E}){l.forEach(p=>{const w=p.rect();if(at({x:I,y:E},w)){if(r.id()===p.itemId())return;o.config().swapMode==="hover"&&r.setContinuousDrag(!0);const A=r.slot(),x=p.item();if(!o.eventHandlers().onBeforeSwap({fromSlot:A.id(),toSlot:p.id(),draggingItem:r.id(),swapWithItem:(x==null?void 0:x.id())||""}))return;if(o.config().manualSwap){const T=structuredClone(o.slotItemMap());o.swapItems(r,p);const M=o.slotItemMap(),D=J(r.view());D.readInitial();const H=x?J(x.view()):null;H==null||H.readInitial();let _=0,N=0;const $=Z(r.view().el());$ instanceof Window?(_=$.scrollY,N=$.scrollX):(_=$.scrollTop,N=$.scrollLeft),o.eventHandlers().onSwap({oldSlotItemMap:T,newSlotItemMap:M,fromSlot:A.id(),toSlot:p.id(),draggingItem:r.id(),swappedWithItem:(x==null?void 0:x.id())||""}),requestAnimationFrame(()=>{const q=t.querySelectorAll("[data-swapy-item]");o.items().forEach(y=>{const B=Array.from(q).find(Y=>Y.dataset.swapyItem===y.id());y.view().updateElement(B)}),o.syncSlotItemMap(),D.readFinalAndReverse(),H==null||H.readFinalAndReverse(),Q(r,D),x&&H&&Q(x,H),$.scrollTo({left:N,top:_})})}else{let T=0,M=0;const D=Z(r.view().el());D instanceof Window?(T=D.scrollY,M=D.scrollX):(T=D.scrollTop,M=D.scrollLeft),dt(r,p,!0),x&&dt(x,A),D.scrollTo({left:M,top:T});const H=o.slotItemMap();o.syncSlotItemMap();const _=o.slotItemMap();o.eventHandlers().onSwap({oldSlotItemMap:H,newSlotItemMap:_,fromSlot:A.id(),toSlot:p.id(),draggingItem:r.id(),swappedWithItem:(x==null?void 0:x.id())||""})}}})}function s(){t.querySelectorAll("img").forEach(r=>{r.style.pointerEvents="none"}),t.style.userSelect="none",t.style.webkitUserSelect="none"}function h(){t.querySelectorAll("img").forEach(r=>{r.style.pointerEvents=""}),t.style.userSelect="",t.style.webkitUserSelect=""}function a(r){o.config().enabled=r}function c(r){o.eventHandlers().onSwapStart=r}function f(r){o.eventHandlers().onSwap=r}function m(r){o.eventHandlers().onSwapEnd=r}function v(r){o.eventHandlers().onBeforeSwap=r}function g(){X(),requestAnimationFrame(()=>{d()})}function X(){i.forEach(r=>r.destroy()),l.forEach(r=>r.destroy()),o.destroy(),i=[],l=[]}return{enable:a,slotItemMap:()=>o.slotItemMap(),onSwapStart:c,onSwap:f,onSwapEnd:m,onBeforeSwap:v,update:g,destroy:X}}function _t({slots:t,items:e,config:n}){const o={slots:t,items:e,config:n,slotItemMap:{asObject:{},asMap:new Map,asArray:[]},zIndexCount:1,eventHandlers:{onSwapStart:()=>{},onSwap:()=>{},onSwapEnd:()=>{},onBeforeSwap:()=>!0},scrollOffsetWhileDragging:{x:0,y:0},scrollHandler:null};let l={...o};const i=c=>{var f;(f=l.scrollHandler)==null||f.call(l,c)};window.addEventListener("scroll",i);function d(c){return l.slots.find(f=>f.id()===c)}function u(c){return l.items.find(f=>f.id()===c)}function s(){const c={},f=new Map,m=[];l.slots.forEach(v=>{var r;const g=v.id(),X=((r=v.item())==null?void 0:r.id())||"";c[g]=X,f.set(g,X),m.push({slot:g,item:X})}),l.slotItemMap={asObject:c,asMap:f,asArray:m}}function h(c,f){var p;const m=l.slotItemMap,v=c.id(),g=((p=f.item())==null?void 0:p.id())||"",X=f.id(),r=c.slot().id();m.asObject[X]=v,m.asObject[r]=g,m.asMap.set(X,v),m.asMap.set(r,g);const I=m.asArray.findIndex(w=>w.slot===X),E=m.asArray.findIndex(w=>w.slot===r);m.asArray[I].item=v,m.asArray[E].item=g}function a(){window.removeEventListener("scroll",i),l={...o}}return{slots:()=>l.slots,items:()=>l.items,config:()=>n,setItems:c=>l.items=c,setSlots:c=>l.slots=c,slotById:d,itemById:u,zIndex:(c=!1)=>c?++l.zIndexCount:l.zIndexCount,resetZIndex:()=>{l.zIndexCount=1},eventHandlers:()=>l.eventHandlers,syncSlotItemMap:s,slotItemMap:()=>l.slotItemMap,onScroll:c=>{l.scrollHandler=c},swapItems:h,destroy:a}}function Pt(t,e){const n=ft(t);function o(){return n.el().dataset.swapySlot}function l(){const a=n.el().children[0];return(a==null?void 0:a.dataset.swapyItem)||null}function i(){return z(n.el().getBoundingClientRect())}function d(){const a=n.el().children[0];if(a)return e.itemById(a.dataset.swapyItem)}function u(){e.slots().forEach(a=>{a.view().el().removeAttribute("data-swapy-highlighted")})}function s(){u(),n.el().setAttribute("data-swapy-highlighted","")}function h(){}return{id:o,view:()=>n,itemId:l,rect:i,item:d,highlight:s,unhighlightAllSlots:u,isHighlighted:()=>n.el().hasAttribute("data-swapy-highlighted"),destroy:h}}function Nt(t,e){const n=ft(t),o={};let l=null,i=null,d=!1,u=!0,s;const h=qt();let a=()=>{},c=()=>{},f=()=>{},m=()=>{};const{onDrag:v,onDrop:g,onHold:X,onRelease:r}=n.usePlugin(Mt,{startDelay:e.config().dragOnHold?400:0}),I=R(0,0),E=R(0,0),p=R(0,0),w=R(0,0);let A=null,x=null;X(S=>{e.config().enabled&&(q()&&!$(S.el)||Y()&&B(S.el)||f==null||f(S))}),r(S=>{e.config().enabled&&(q()&&!$(S.el)||Y()&&B(S.el)||m==null||m(S))});function T(S){var C;k(),et().highlight(),(C=o.drop)==null||C.call(o),e.slots().forEach(O=>{const V=O.view().boundingRect();O.view().el().style.width=`${V.width}px`,O.view().el().style.flexShrink="0",O.view().el().style.height=`${V.height}px`});const b=e.slotItemMap();e.eventHandlers().onSwapStart({draggingItem:pt(),fromSlot:yt(),slotItemMap:b}),i=b,n.el().style.position="relative",n.el().style.zIndex=`${e.zIndex(!0)}`,A=Z(S.el),e.config().autoScrollOnDrag&&(l=Wt(A,e.config().dragAxis),l.updatePointer({x:S.pointerX,y:S.pointerY})),I.x=window.scrollX,I.y=window.scrollY,p.x=0,p.y=0,A instanceof HTMLElement&&(E.x=A.scrollLeft,E.y=A.scrollTop,x=()=>{w.x=A.scrollLeft-E.x,w.y=A.scrollTop-E.y,n.setTransform({dragX:((s==null?void 0:s.width)||0)+p.x+w.x,dragY:((s==null?void 0:s.height)||0)+p.y+w.y})},A.addEventListener("scroll",x)),e.onScroll(()=>{p.x=window.scrollX-I.x,p.y=window.scrollY-I.y;const O=w.x||0,V=w.y||0;n.setTransform({dragX:((s==null?void 0:s.width)||0)+p.x+O,dragY:((s==null?void 0:s.height)||0)+p.y+V})})}v(S=>{var b;if(e.config().enabled){if(!d){if(q()&&!$(S.el)||Y()&&B(S.el))return;T(S)}d=!0,l&&l.updatePointer({x:S.pointerX,y:S.pointerY}),s=S,(b=o.drop)==null||b.call(o),h(()=>{n.el().style.position="relative";const C=S.width+p.x+w.x,O=S.height+p.y+w.y;e.config().dragAxis==="y"?n.setTransform({dragY:O}):e.config().dragAxis==="x"?n.setTransform({dragX:C}):n.setTransform({dragX:C,dragY:O}),a==null||a(S)})}}),g(S=>{if(!d)return;tt(),d=!1,u=!1,s=null,A&&(A.removeEventListener("scroll",x),x=null),A=null,w.x=0,w.y=0,p.x=0,p.y=0,l&&(l.destroy(),l=null),et().unhighlightAllSlots(),c==null||c(S),e.eventHandlers().onSwapEnd({slotItemMap:e.slotItemMap(),hasChanged:i!=null&&i.asMap?!jt(i==null?void 0:i.asMap,e.slotItemMap().asMap):!1}),i=null,e.onScroll(null),e.slots().forEach(C=>{C.view().el().style.width="",C.view().el().style.flexShrink="",C.view().el().style.height=""}),e.config().manualSwap&&e.config().swapMode==="drop"?requestAnimationFrame(b):b();function b(){const C=n.currentTransform(),O=C.dragX+C.translateX,V=C.dragY+C.translateY;o.drop=st({translate:R(O,V)},{translate:R(0,0)},({translate:mt},wt)=>{wt?d||(n.clearTransform(),n.el().style.transformOrigin=""):n.setTransform({dragX:0,dragY:0,translateX:mt.x,translateY:mt.y}),wt&&(e.items().forEach(St=>{St.isDragging()||(St.view().el().style.zIndex="")}),e.resetZIndex(),n.el().style.position="",u=!0)},ut(e.config().animation))}});function M(S){a=S}function D(S){c=S}function H(S){f=S}function _(S){m=S}function N(){return n.el().querySelector("[data-swapy-handle]")}function $(S){const b=N();return b?b===S||b.contains(S):!1}function q(){return N()!==null}function y(){return Array.from(n.el().querySelectorAll("[data-swapy-no-drag]"))}function B(S){const b=y();return!b||b.length===0?!1:b.includes(S)||b.some(C=>C.contains(S))}function Y(){return y().length>0}function k(){n.el().setAttribute("data-swapy-dragging","")}function tt(){n.el().removeAttribute("data-swapy-dragging")}function kt(){a=null,c=null,f=null,m=null,s=null,i=null,l&&(l.destroy(),l=null),A&&x&&A.removeEventListener("scroll",x),n.destroy()}function pt(){return n.el().dataset.swapyItem}function et(){return e.slotById(n.el().parentElement.dataset.swapySlot)}function yt(){return n.el().parentElement.dataset.swapySlot}return{id:pt,view:()=>n,slot:et,slotId:yt,onDrag:M,onDrop:D,onHold:H,onRelease:_,destroy:kt,isDragging:()=>d,cancelAnimation:()=>o,dragEvent:()=>s,store:()=>e,continuousDrag:()=>u,setContinuousDrag:S=>u=S}}function dt(t,e,n=!1){if(n){const l=e.item();l&&(e.view().el().style.position="relative",l.view().el().style.position="absolute")}else{const l=t.slot();l.view().el().style.position="",t.view().el().style.position=""}if(!t)return;const o=J(t.view());o.readInitial(),e.view().el().appendChild(t.view().el()),o.readFinalAndReverse(),Q(t,o)}function qt(){let t=!1;return e=>{t||(t=!0,requestAnimationFrame(()=>{e(),t=!1}))}}function Q(t,e){var u,s,h,a;(s=(u=t.cancelAnimation()).moveToSlot)==null||s.call(u),(a=(h=t.cancelAnimation()).drop)==null||a.call(h);const n=ut(t.store().config().animation),o=e.transitionValues();let l=t.view().currentTransform(),i=0,d=!1;t.cancelAnimation().moveToSlot=st({translate:o.from.translate,scale:o.from.scale,borderRadius:o.from.borderRadius},{translate:o.to.translate,scale:o.to.scale,borderRadius:o.to.borderRadius},({translate:c,scale:f,borderRadius:m},v,g)=>{if(t.isDragging()){i!==0&&(d=!0);const r=t.dragEvent().relativeX,I=t.dragEvent().relativeY;t.continuousDrag()?t.view().setTransform({translateX:L(l.translateX,l.translateX+(o.from.width-o.to.width)*r,n.easing(g-i)),translateY:L(l.translateY,l.translateY+(o.from.height-o.to.height)*I,n.easing(g-i)),scaleX:f.x,scaleY:f.y}):t.view().setTransform({scaleX:f.x,scaleY:f.y})}else l=t.view().currentTransform(),i=g,d?t.view().setTransform({scaleX:f.x,scaleY:f.y}):t.view().setTransform({dragX:0,dragY:0,translateX:c.x,translateY:c.y,scaleX:f.x,scaleY:f.y});const X=e.childrenTransitionData();X.forEach(({el:r,fromTranslate:I,fromScale:E,fromBorderRadius:p,toBorderRadius:w,parentScale:A})=>{const x=L(A.x,1,n.easing(g)),T=L(A.y,1,n.easing(g));r.style.transform=`translate(${I.x+(0-I.x/x)*n.easing(g)}px, ${I.y+(0-I.y/T)*n.easing(g)}px) scale(${L(E.x/x,1/x,n.easing(g))}, ${L(E.y/T,1/T,n.easing(g))})`,lt(p)||(r.style.borderRadius=U(it(p,w,n.easing(g))))}),lt(m)||(t.view().el().style.borderRadius=U(m)),v&&(t.isDragging()||(t.view().el().style.transformOrigin="",t.view().clearTransform()),t.view().el().style.borderRadius="",X.forEach(({el:r})=>{r.style.transform="",r.style.transformOrigin="",r.style.borderRadius=""}))},n)}function W(...t){console.error("Swapy Error:",...t)}function Ft(t){const e=t;let n=!0;const o=e.querySelectorAll("[data-swapy-slot]");e||(W("container passed to createSwapy() is undefined or null"),n=!1),o.forEach(u=>{const s=u,h=s.dataset.swapySlot,a=s.children,c=a[0];(!h||h.length===0)&&(W(s,"does not contain a slotId using data-swapy-slot"),n=!1),a.length>1&&(W("slot:",`"${h}"`,"cannot contain more than one element"),n=!1),c&&(!c.dataset.swapyItem||c.dataset.swapyItem.length===0)&&(W("slot",`"${h}"`,"does not contain an element with an item id using data-swapy-item"),n=!1)});const l=Array.from(o).map(u=>u.dataset.swapySlot),i=e.querySelectorAll("[data-swapy-item]"),d=Array.from(i).map(u=>u.dataset.swapyItem);if(gt(l)){const u=ht(l);W("your container has duplicate slot ids",`(${u.join(", ")})`),n=!1}if(gt(d)){const u=ht(d);W("your container has duplicate item ids",`(${u.join(", ")})`),n=!1}return n}function gt(t){return new Set(t).size!==t.length}function ht(t){const e=new Set,n=new Set;for(const o of t)e.has(o)?n.add(o):e.add(o);return Array.from(n)}function jt(t,e){if(t.size!==e.size)return!1;for(const[n,o]of t)if(e.get(n)!==o)return!1;return!0}function Z(t){let e=t;for(;e;){const n=window.getComputedStyle(e),o=n.overflowY,l=n.overflowX;if((o==="auto"||o==="scroll")&&e.scrollHeight>e.clientHeight||(l==="auto"||l==="scroll")&&e.scrollWidth>e.clientWidth)return e;e=e.parentElement}return window}function Wt(t,e){let l=!1,i,d=0,u=0,s=0,h=0,a=0,c=0,f=null;t instanceof HTMLElement?(i=z(t.getBoundingClientRect()),d=t.scrollHeight-i.height,u=t.scrollWidth-i.width):(i={x:0,y:0,width:window.innerWidth,height:window.innerHeight},d=document.documentElement.scrollHeight-window.innerHeight,u=document.documentElement.scrollWidth-window.innerWidth);function m(){t instanceof HTMLElement?(s=t.scrollTop,h=t.scrollLeft):(s=window.scrollY,h=window.scrollX)}function v(r){l=!1;const I=i.y,E=i.y+i.height,p=i.x,w=i.x+i.width,A=Math.abs(I-r.y)=-100){const M=j(T,-100,0);a=-G(-100,0,0,5,M),l=!0}}else{const T=E-r.y;if(T<=100){const M=j(T,0,100);a=G(100,0,0,5,M),l=!0}}if(e!=="y")if(x){const T=p-r.x;if(T>=-100){const M=j(T,-100,0);c=-G(-100,0,0,5,M),l=!0}}else{const T=w-r.x;if(T<=100){const M=j(T,0,100);c=G(100,0,0,5,M),l=!0}}l&&(f&&cancelAnimationFrame(f),g())}function g(){m(),e!=="x"&&(a=s+a>=d?0:a),e!=="y"&&(c=h+c>=u?0:c),t.scrollBy({top:a,left:c}),l&&(f=requestAnimationFrame(g))}function X(){l=!1}return{updatePointer:v,destroy:X}}P.createSwapy=Ot,P.getClosestScrollableContainer=Z,P.utils=$t,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})}); + `}function rt(t){return t.x.topLeft===0&&t.x.topRight===0&&t.x.bottomRight===0&&t.x.bottomLeft===0&&t.y.topLeft===0&&t.y.topRight===0&&t.y.bottomRight===0&&t.y.bottomLeft===0}function st(t){return typeof t=="object"&&"x"in t&&"y"in t}function R(t,e){return{x:t,y:e}}function xt(t,e){return R(t.x+e.x,t.y+e.y)}function vt(t,e){return R(t.x-e.x,t.y-e.y)}function At(t,e){return R(t.x*e,t.y*e)}function L(t,e,n){return t+(e-t)*n}function It(t,e,n){return xt(t,At(vt(e,t),n))}function at(t,e,n){return{x:{topLeft:L(t.x.topLeft,e.x.topLeft,n),topRight:L(t.x.topRight,e.x.topRight,n),bottomRight:L(t.x.bottomRight,e.x.bottomRight,n),bottomLeft:L(t.x.bottomLeft,e.x.bottomLeft,n)},y:{topLeft:L(t.y.topLeft,e.y.topLeft,n),topRight:L(t.y.topRight,e.y.topRight,n),bottomRight:L(t.y.bottomRight,e.y.bottomRight,n),bottomLeft:L(t.y.bottomLeft,e.y.bottomLeft,n)},unit:t.unit}}function Et(t,e,n){return W((n-t)/(e-t),0,1)}function K(t,e,n,o,l){return L(n,o,Et(t,e,l))}function W(t,e,n){return Math.min(Math.max(t,e),n)}const Tt={duration:350,easing:t=>t};function ct(t,e,n,o){let l=!1;const r=()=>{l=!0},d={...Tt,...o};let u;function s(h){u===void 0&&(u=h);const a=h-u,c=W(a/d.duration,0,1),f=Object.keys(t),m=Object.keys(e);if(!f.every(g=>m.includes(g))){console.error("animate Error: `from` keys are different than `to`");return}const v={};f.forEach(g=>{typeof t[g]=="number"&&typeof e[g]=="number"?v[g]=L(t[g],e[g],d.easing(c)):j(t[g])&&j(e[g])?v[g]=at(t[g],e[g],d.easing(c)):st(t[g])&&st(e[g])&&(v[g]=It(t[g],e[g],d.easing(c)))}),n(v,c>=1,c),c<1&&!l&&requestAnimationFrame(s)}return requestAnimationFrame(s),r}const Xt={startDelay:0};function Mt(t,e){const n={...Xt,...e};let o=t.el(),l=!1,r=null,d=null,u=null,s=null,h=0,a=0,c=0,f=0,m=0,v=0,g=0,X=0,i=0,A=0,E=null,p;o.addEventListener("pointerdown",w),document.body.addEventListener("pointerup",x),document.body.addEventListener("pointermove",T),document.body.addEventListener("touchmove",M,{passive:!1});function w(y){if(l||!y.isPrimary)return;n.startDelay>0?(u==null||u({el:y.target}),p=setTimeout(()=>{B()},n.startDelay)):B();function B(){E=y.target;const C=t.boundingRect(),V=t.layoutRect();m=V.x,v=V.y,c=C.x-m,f=C.y-v,h=y.clientX-c,a=y.clientY-f,g=y.clientX,X=y.clientY,i=(y.clientX-C.x)/C.width,A=(y.clientY-C.y)/C.height,l=!0,T(y)}}function I(){const y=t.layoutRect();h-=m-y.x,a-=v-y.y,m=y.x,v=y.y}function x(y){if(!l){p&&(clearTimeout(p),p=null,s==null||s({el:y.target}));return}if(!y.isPrimary)return;l=!1;const B=y.clientX-g,C=y.clientY-X;d==null||d({x:c,y:f,pointerX:y.clientX,pointerY:y.clientY,width:B,height:C,relativeX:i,relativeY:A,el:E}),E=null}function T(y){if(!l){p&&(clearTimeout(p),p=null,s==null||s({el:y.target}));return}if(!y.isPrimary)return;const B=y.clientX-g,C=y.clientY-X,V=c=y.clientX-h,nt=f=y.clientY-a;r==null||r({width:B,height:C,x:V,y:nt,pointerX:y.clientX,pointerY:y.clientY,relativeX:i,relativeY:A,el:E})}function M(y){if(!l)return!0;y.preventDefault()}function b(y){r=y}function H(y){d=y}function _(y){u=y}function N(y){s=y}function $(){o.removeEventListener("pointerdown",w),o=t.el(),o.addEventListener("pointerdown",w)}function q(){t.el().removeEventListener("pointerdown",w),document.body.removeEventListener("pointerup",x),document.body.removeEventListener("pointermove",T),document.body.removeEventListener("touchmove",M),r=null,d=null,u=null,s=null}return{onDrag:b,onDrop:H,onHold:_,onRelease:N,onElementUpdate:$,destroy:q,readjust:I}}function bt(t){return 1+2.70158*Math.pow(t-1,3)+1.70158*Math.pow(t-1,2)}function Dt(t){return 1-Math.pow(1-t,3)}function G(t){return{x:t.x,y:t.y,width:t.width,height:t.height}}function Lt(t){const e=t.getBoundingClientRect();let n=0,o=0,l=t.parentElement;for(;l;){const d=getComputedStyle(l).transform;if(d&&d!=="none"){const u=d.match(/matrix.*\((.+)\)/);if(u){const s=u[1].split(", ").map(Number);n+=s[4]||0,o+=s[5]||0}}l=l.parentElement}return{y:e.top-o,x:e.left-n,width:e.width,height:e.height}}function Q(t){let e=t,n=0,o=0;for(;e;)n+=e.offsetTop,o+=e.offsetLeft,e=e.offsetParent;return{x:o,y:n,width:t.offsetWidth,height:t.offsetHeight}}function ft(t,e){return t.x>=e.x&&t.x<=e.x+e.width&&t.y>=e.y&&t.y<=e.y+e.height}function Ct(t){let e=t,n=0,o=0;for(;e;){const l=r=>{const d=getComputedStyle(r);return/(auto|scroll)/.test(d.overflow+d.overflowY+d.overflowX)};if(e===document.body){o+=window.scrollX,n+=window.scrollY;break}l(e)&&(o+=e.scrollLeft,n+=e.scrollTop),e=e.parentElement}return{x:o,y:n}}function tt(t){let e="unread",n,o,l,r,d,u,s,h,a,c,f;function m(){n=t.currentTransform(),o=Lt(t.el()),l=Ct(t.el()),f=ut(t.el()).map(({parent:A,children:E})=>({parent:{el:A,initialRect:G(A.getBoundingClientRect())},children:E.filter(p=>p instanceof HTMLElement).map(p=>{const w=p;return w.originalBorderRadius||(w.originalBorderRadius=getComputedStyle(p).borderRadius),{el:p,borderRadius:lt(w.originalBorderRadius),initialRect:G(p.getBoundingClientRect())}})})),e="readInitial"}function v(){if(e!=="readInitial")throw new Error("FlipView: Cannot read final values before reading initial values");a=t.layoutRect(),u=o.width/a.width,s=o.height/a.height,r=o.x-a.x-n.dragX+l.x,d=o.y-a.y-n.dragY+l.y,h=it(t.borderRadius(),u,s);const i=ut(t.el());f=f.map(({parent:E,children:p},w)=>{const I=i[w].parent;return{parent:{...E,el:I,finalRect:Q(I)},children:p.map((x,T)=>{const M=i[w].children[T];let b=Q(M);return M.hasAttribute("data-swapy-text")&&(b={...b,width:x.initialRect.width,height:x.initialRect.height}),{...x,el:M,finalRect:b}})}});const A={translateX:r,translateY:d,scaleX:u,scaleY:s};t.el().style.transformOrigin="0 0",t.el().style.borderRadius=Z(h),t.setTransform(A),c=[],f.forEach(({parent:E,children:p})=>{const w=p.map(({el:I,initialRect:x,finalRect:T,borderRadius:M})=>Yt(I,x,T,M,E.initialRect,E.finalRect));c.push(...w)}),e="readFinal"}function g(){if(e!=="readFinal")throw new Error("FlipView: Cannot get transition values before reading");return{from:{width:o.width,height:o.height,translate:R(r,d),scale:R(u,s),borderRadius:h},to:{width:a.width,height:a.height,translate:R(0,0),scale:R(1,1),borderRadius:t.borderRadius()}}}function X(){if(e!=="readFinal")throw new Error("FlipView: Cannot get children transition values before reading");return c}return{readInitial:m,readFinalAndReverse:v,transitionValues:g,childrenTransitionData:X}}function Yt(t,e,n,o,l,r){t.style.transformOrigin="0 0";const d=l.width/r.width,u=l.height/r.height,s=e.width/n.width,h=e.height/n.height,a=it(o,s,h),c=e.x-l.x,f=n.x-r.x,m=e.y-l.y,v=n.y-r.y,g=(c-f*d)/d,X=(m-v*u)/u;return t.style.transform=`translate(${g}px, ${X}px) scale(${s/d}, ${h/u})`,t.style.borderRadius=Z(a),{el:t,fromTranslate:R(g,X),fromScale:R(s,h),fromBorderRadius:a,toBorderRadius:o,parentScale:{x:d,y:u}}}function ut(t){const e=[];function n(o){const l=Array.from(o.children).filter(r=>r instanceof HTMLElement);l.length>0&&(e.push({parent:o,children:l}),l.forEach(r=>n(r)))}return n(t),e}function dt(t){const e=[];let n=t,o={dragX:0,dragY:0,translateX:0,translateY:0,scaleX:1,scaleY:1};const l=lt(window.getComputedStyle(n).borderRadius),r={el:()=>n,setTransform:d,clearTransform:u,currentTransform:()=>o,borderRadius:()=>l,layoutRect:()=>Q(n),boundingRect:()=>G(n.getBoundingClientRect()),usePlugin:h,destroy:a,updateElement:c};function d(f){o={...o,...f},s()}function u(){o={dragX:0,dragY:0,translateX:0,translateY:0,scaleX:1,scaleY:1},s()}function s(){const{dragX:f,dragY:m,translateX:v,translateY:g,scaleX:X,scaleY:i}=o;f===0&&m===0&&v===0&&g===0&&X===1&&i===1?n.style.transform="":n.style.transform=`translate(${f+v}px, ${m+g}px) scale(${X}, ${i})`}function h(f,m){const v=f(r,m);return e.push(v),v}function a(){e.forEach(f=>f.destroy())}function c(f){if(!f)return;const m=n.hasAttribute("data-swapy-dragging"),v=n.style.cssText;n=f,m&&n.setAttribute("data-swapy-dragging",""),n.style.cssText=v,e.forEach(g=>g.onElementUpdate())}return r}function Rt(t,e,n){return n.map(o=>({slotId:o.slot,itemId:o.item,item:o.item===""?null:t.find(l=>o.item===l[e])}))}function Ht(t,e){return t.map(n=>({item:n[e],slot:n[e]}))}function $t(t,e,n,o,l,r=!1){const d=e.filter(h=>!o.some(a=>a.item===h[n])).map(h=>({slot:h[n],item:h[n]}));let u;r?u=o.map(h=>e.some(a=>a[n]===h.item)?h:{slot:h.slot,item:""}):u=o.filter(h=>e.some(a=>a[n]===h.item)||!h.item);const s=[...u,...d];l(s),(d.length>0||u.length!==o.length)&&requestAnimationFrame(()=>{t==null||t.update()})}const Bt=Object.freeze(Object.defineProperty({__proto__:null,dynamicSwapy:$t,initSlotItemMap:Ht,toSlottedItems:Rt},Symbol.toStringTag,{value:"Module"})),Ot={animation:"dynamic",enabled:!0,swapMode:"hover",dragOnHold:!1,autoScrollOnDrag:!1,dragAxis:"both",manualSwap:!1};function gt(t){switch(t){case"dynamic":return{easing:Dt,duration:300};case"spring":return{easing:bt,duration:350};case"none":return{easing:e=>e,duration:1}}}function _t(t,e){const n={...Ot,...e},o=Pt({slots:[],items:[],config:n});let l=[],r=[];d();function d(){if(!jt(t))throw new Error("Cannot create a Swapy instance because your HTML structure is invalid. Fix all above errors and then try!");l=Array.from(t.querySelectorAll("[data-swapy-slot]")).map(i=>Nt(i,o)),o.setSlots(l),r=Array.from(t.querySelectorAll("[data-swapy-item]")).map(i=>qt(i,o)),o.setItems(r),o.syncSlotItemMap(),r.forEach(i=>{i.onDrag(({pointerX:A,pointerY:E})=>{s();let p=!1;l.forEach(w=>{const I=w.rect();ft({x:A,y:E},I)&&(p=!0,w.isHighlighted()||w.highlight())}),!p&&o.config().swapMode==="drop"&&i.slot().highlight(),n.swapMode==="hover"&&u(i,{pointerX:A,pointerY:E})}),i.onDrop(({pointerX:A,pointerY:E})=>{h(),n.swapMode==="drop"&&u(i,{pointerX:A,pointerY:E})}),i.onHold(()=>{s()}),i.onRelease(()=>{h()})})}function u(i,{pointerX:A,pointerY:E}){l.forEach(p=>{const w=p.rect();if(ft({x:A,y:E},w)){if(i.id()===p.itemId())return;o.config().swapMode==="hover"&&i.setContinuousDrag(!0);const I=i.slot(),x=p.item();if(!o.eventHandlers().onBeforeSwap({fromSlot:I.id(),toSlot:p.id(),draggingItem:i.id(),swapWithItem:(x==null?void 0:x.id())||""}))return;if(o.config().manualSwap){const T=structuredClone(o.slotItemMap());o.swapItems(i,p);const M=o.slotItemMap(),b=tt(i.view());b.readInitial();const H=x?tt(x.view()):null;H==null||H.readInitial();let _=0,N=0;const $=J(i.view().el());$ instanceof Window?(_=$.scrollY,N=$.scrollX):(_=$.scrollTop,N=$.scrollLeft),o.eventHandlers().onSwap({oldSlotItemMap:T,newSlotItemMap:M,fromSlot:I.id(),toSlot:p.id(),draggingItem:i.id(),swappedWithItem:(x==null?void 0:x.id())||""}),requestAnimationFrame(()=>{const q=t.querySelectorAll("[data-swapy-item]");o.items().forEach(y=>{const B=Array.from(q).find(C=>C.dataset.swapyItem===y.id());y.view().updateElement(B)}),o.syncSlotItemMap(),b.readFinalAndReverse(),H==null||H.readFinalAndReverse(),et(i,b),x&&H&&et(x,H),$.scrollTo({left:N,top:_})})}else{let T=0,M=0;const b=J(i.view().el());b instanceof Window?(T=b.scrollY,M=b.scrollX):(T=b.scrollTop,M=b.scrollLeft),ht(i,p,!0),x&&ht(x,I),b.scrollTo({left:M,top:T});const H=o.slotItemMap();o.syncSlotItemMap();const _=o.slotItemMap();o.eventHandlers().onSwap({oldSlotItemMap:H,newSlotItemMap:_,fromSlot:I.id(),toSlot:p.id(),draggingItem:i.id(),swappedWithItem:(x==null?void 0:x.id())||""})}}})}function s(){t.querySelectorAll("img").forEach(i=>{i.style.pointerEvents="none"}),t.style.userSelect="none",t.style.webkitUserSelect="none"}function h(){t.querySelectorAll("img").forEach(i=>{i.style.pointerEvents=""}),t.style.userSelect="",t.style.webkitUserSelect=""}function a(i){o.config().enabled=i}function c(i){o.eventHandlers().onSwapStart=i}function f(i){o.eventHandlers().onSwap=i}function m(i){o.eventHandlers().onSwapEnd=i}function v(i){o.eventHandlers().onBeforeSwap=i}function g(){X(),requestAnimationFrame(()=>{d()})}function X(){r.forEach(i=>i.destroy()),l.forEach(i=>i.destroy()),o.destroy(),r=[],l=[]}return{enable:a,slotItemMap:()=>o.slotItemMap(),onSwapStart:c,onSwap:f,onSwapEnd:m,onBeforeSwap:v,update:g,destroy:X}}function Pt({slots:t,items:e,config:n}){const o={slots:t,items:e,config:n,slotItemMap:{asObject:{},asMap:new Map,asArray:[]},zIndexCount:1,eventHandlers:{onSwapStart:()=>{},onSwap:()=>{},onSwapEnd:()=>{},onBeforeSwap:()=>!0},scrollOffsetWhileDragging:{x:0,y:0},scrollHandler:null};let l={...o};const r=c=>{var f;(f=l.scrollHandler)==null||f.call(l,c)};window.addEventListener("scroll",r);function d(c){return l.slots.find(f=>f.id()===c)}function u(c){return l.items.find(f=>f.id()===c)}function s(){const c={},f=new Map,m=[];l.slots.forEach(v=>{var i;const g=v.id(),X=((i=v.item())==null?void 0:i.id())||"";c[g]=X,f.set(g,X),m.push({slot:g,item:X})}),l.slotItemMap={asObject:c,asMap:f,asArray:m}}function h(c,f){var p;const m=l.slotItemMap,v=c.id(),g=((p=f.item())==null?void 0:p.id())||"",X=f.id(),i=c.slot().id();m.asObject[X]=v,m.asObject[i]=g,m.asMap.set(X,v),m.asMap.set(i,g);const A=m.asArray.findIndex(w=>w.slot===X),E=m.asArray.findIndex(w=>w.slot===i);m.asArray[A].item=v,m.asArray[E].item=g}function a(){window.removeEventListener("scroll",r),l={...o}}return{slots:()=>l.slots,items:()=>l.items,config:()=>n,setItems:c=>l.items=c,setSlots:c=>l.slots=c,slotById:d,itemById:u,zIndex:(c=!1)=>c?++l.zIndexCount:l.zIndexCount,resetZIndex:()=>{l.zIndexCount=1},eventHandlers:()=>l.eventHandlers,syncSlotItemMap:s,slotItemMap:()=>l.slotItemMap,onScroll:c=>{l.scrollHandler=c},swapItems:h,destroy:a}}function Nt(t,e){const n=dt(t);function o(){return n.el().dataset.swapySlot}function l(){const a=n.el().children[0];return(a==null?void 0:a.dataset.swapyItem)||null}function r(){return G(n.el().getBoundingClientRect())}function d(){const a=n.el().children[0];if(a)return e.itemById(a.dataset.swapyItem)}function u(){e.slots().forEach(a=>{a.view().el().removeAttribute("data-swapy-highlighted")})}function s(){u(),n.el().setAttribute("data-swapy-highlighted","")}function h(){}return{id:o,view:()=>n,itemId:l,rect:r,item:d,highlight:s,unhighlightAllSlots:u,isHighlighted:()=>n.el().hasAttribute("data-swapy-highlighted"),destroy:h}}function qt(t,e){const n=dt(t),o={};let l=null,r=null,d=!1,u=!0,s;const h=Ft();let a=()=>{},c=()=>{},f=()=>{},m=()=>{};const{onDrag:v,onDrop:g,onHold:X,onRelease:i}=n.usePlugin(Mt,{startDelay:e.config().dragOnHold?400:0}),A=R(0,0),E=R(0,0),p=R(0,0),w=R(0,0);let I=null,x=null;X(S=>{e.config().enabled&&(q()&&!$(S.el)||C()&&B(S.el)||f==null||f(S))}),i(S=>{e.config().enabled&&(q()&&!$(S.el)||C()&&B(S.el)||m==null||m(S))});function T(S){var F;V(),ot().highlight(),(F=o.drop)==null||F.call(o);const Y=e.slots().map(O=>O.view().boundingRect());e.slots().forEach((O,z)=>{const U=Y[z];O.view().el().style.width=`${U.width}px`,O.view().el().style.maxWidth=`${U.width}px`,O.view().el().style.flexShrink="0",O.view().el().style.height=`${U.height}px`});const D=e.slotItemMap();e.eventHandlers().onSwapStart({draggingItem:mt(),fromSlot:wt(),slotItemMap:D}),r=D,n.el().style.position="relative",n.el().style.zIndex=`${e.zIndex(!0)}`,I=J(S.el),e.config().autoScrollOnDrag&&(l=kt(I,e.config().dragAxis),l.updatePointer({x:S.pointerX,y:S.pointerY})),A.x=window.scrollX,A.y=window.scrollY,p.x=0,p.y=0,I instanceof HTMLElement&&(E.x=I.scrollLeft,E.y=I.scrollTop,x=()=>{w.x=I.scrollLeft-E.x,w.y=I.scrollTop-E.y,n.setTransform({dragX:((s==null?void 0:s.width)||0)+p.x+w.x,dragY:((s==null?void 0:s.height)||0)+p.y+w.y})},I.addEventListener("scroll",x)),e.onScroll(()=>{p.x=window.scrollX-A.x,p.y=window.scrollY-A.y;const O=w.x||0,z=w.y||0;n.setTransform({dragX:((s==null?void 0:s.width)||0)+p.x+O,dragY:((s==null?void 0:s.height)||0)+p.y+z})})}v(S=>{var Y;if(e.config().enabled){if(!d){if(q()&&!$(S.el)||C()&&B(S.el))return;T(S)}d=!0,l&&l.updatePointer({x:S.pointerX,y:S.pointerY}),s=S,(Y=o.drop)==null||Y.call(o),h(()=>{n.el().style.position="relative";const D=S.width+p.x+w.x,F=S.height+p.y+w.y;e.config().dragAxis==="y"?n.setTransform({dragY:F}):e.config().dragAxis==="x"?n.setTransform({dragX:D}):n.setTransform({dragX:D,dragY:F}),a==null||a(S)})}}),g(S=>{if(!d)return;nt(),d=!1,u=!1,s=null,I&&(I.removeEventListener("scroll",x),x=null),I=null,w.x=0,w.y=0,p.x=0,p.y=0,l&&(l.destroy(),l=null),ot().unhighlightAllSlots(),c==null||c(S),e.eventHandlers().onSwapEnd({slotItemMap:e.slotItemMap(),hasChanged:r!=null&&r.asMap?!Wt(r==null?void 0:r.asMap,e.slotItemMap().asMap):!1}),r=null,e.onScroll(null),e.slots().forEach(D=>{D.view().el().style.width="",D.view().el().style.maxWidth="",D.view().el().style.flexShrink="",D.view().el().style.height=""}),e.config().manualSwap&&e.config().swapMode==="drop"?requestAnimationFrame(Y):Y();function Y(){const D=n.currentTransform(),F=D.dragX+D.translateX,O=D.dragY+D.translateY;o.drop=ct({translate:R(F,O)},{translate:R(0,0)},({translate:z},U)=>{U?d||(n.clearTransform(),n.el().style.transformOrigin=""):n.setTransform({dragX:0,dragY:0,translateX:z.x,translateY:z.y}),U&&(e.items().forEach(St=>{St.isDragging()||(St.view().el().style.zIndex="")}),e.resetZIndex(),n.el().style.position="",u=!0)},gt(e.config().animation))}});function M(S){a=S}function b(S){c=S}function H(S){f=S}function _(S){m=S}function N(){return n.el().querySelector("[data-swapy-handle]")}function $(S){const Y=N();return Y?Y===S||Y.contains(S):!1}function q(){return N()!==null}function y(){return Array.from(n.el().querySelectorAll("[data-swapy-no-drag]"))}function B(S){const Y=y();return!Y||Y.length===0?!1:Y.includes(S)||Y.some(D=>D.contains(S))}function C(){return y().length>0}function V(){n.el().setAttribute("data-swapy-dragging","")}function nt(){n.el().removeAttribute("data-swapy-dragging")}function Vt(){a=null,c=null,f=null,m=null,s=null,r=null,l&&(l.destroy(),l=null),I&&x&&I.removeEventListener("scroll",x),n.destroy()}function mt(){return n.el().dataset.swapyItem}function ot(){return e.slotById(n.el().parentElement.dataset.swapySlot)}function wt(){return n.el().parentElement.dataset.swapySlot}return{id:mt,view:()=>n,slot:ot,slotId:wt,onDrag:M,onDrop:b,onHold:H,onRelease:_,destroy:Vt,isDragging:()=>d,cancelAnimation:()=>o,dragEvent:()=>s,store:()=>e,continuousDrag:()=>u,setContinuousDrag:S=>u=S}}function ht(t,e,n=!1){if(n){const l=e.item();l&&(e.view().el().style.position="relative",l.view().el().style.position="absolute")}else{const l=t.slot();l.view().el().style.position="",t.view().el().style.position=""}if(!t)return;const o=tt(t.view());o.readInitial(),e.view().el().appendChild(t.view().el()),o.readFinalAndReverse(),et(t,o)}function Ft(){let t=!1;return e=>{t||(t=!0,requestAnimationFrame(()=>{e(),t=!1}))}}function et(t,e){var u,s,h,a;(s=(u=t.cancelAnimation()).moveToSlot)==null||s.call(u),(a=(h=t.cancelAnimation()).drop)==null||a.call(h);const n=gt(t.store().config().animation),o=e.transitionValues();let l=t.view().currentTransform(),r=0,d=!1;t.cancelAnimation().moveToSlot=ct({translate:o.from.translate,scale:o.from.scale,borderRadius:o.from.borderRadius},{translate:o.to.translate,scale:o.to.scale,borderRadius:o.to.borderRadius},({translate:c,scale:f,borderRadius:m},v,g)=>{if(t.isDragging()){r!==0&&(d=!0);const i=t.dragEvent().relativeX,A=t.dragEvent().relativeY;t.continuousDrag()?t.view().setTransform({translateX:L(l.translateX,l.translateX+(o.from.width-o.to.width)*i,n.easing(g-r)),translateY:L(l.translateY,l.translateY+(o.from.height-o.to.height)*A,n.easing(g-r)),scaleX:f.x,scaleY:f.y}):t.view().setTransform({scaleX:f.x,scaleY:f.y})}else l=t.view().currentTransform(),r=g,d?t.view().setTransform({scaleX:f.x,scaleY:f.y}):t.view().setTransform({dragX:0,dragY:0,translateX:c.x,translateY:c.y,scaleX:f.x,scaleY:f.y});const X=e.childrenTransitionData();X.forEach(({el:i,fromTranslate:A,fromScale:E,fromBorderRadius:p,toBorderRadius:w,parentScale:I})=>{const x=L(I.x,1,n.easing(g)),T=L(I.y,1,n.easing(g));i.style.transform=`translate(${A.x+(0-A.x/x)*n.easing(g)}px, ${A.y+(0-A.y/T)*n.easing(g)}px) scale(${L(E.x/x,1/x,n.easing(g))}, ${L(E.y/T,1/T,n.easing(g))})`,rt(p)||(i.style.borderRadius=Z(at(p,w,n.easing(g))))}),rt(m)||(t.view().el().style.borderRadius=Z(m)),v&&(t.isDragging()||(t.view().el().style.transformOrigin="",t.view().clearTransform()),t.view().el().style.borderRadius="",X.forEach(({el:i})=>{i.style.transform="",i.style.transformOrigin="",i.style.borderRadius=""}))},n)}function k(...t){console.error("Swapy Error:",...t)}function jt(t){const e=t;let n=!0;const o=e.querySelectorAll("[data-swapy-slot]");e||(k("container passed to createSwapy() is undefined or null"),n=!1),o.forEach(u=>{const s=u,h=s.dataset.swapySlot,a=s.children,c=a[0];(!h||h.length===0)&&(k(s,"does not contain a slotId using data-swapy-slot"),n=!1),a.length>1&&(k("slot:",`"${h}"`,"cannot contain more than one element"),n=!1),c&&(!c.dataset.swapyItem||c.dataset.swapyItem.length===0)&&(k("slot",`"${h}"`,"does not contain an element with an item id using data-swapy-item"),n=!1)});const l=Array.from(o).map(u=>u.dataset.swapySlot),r=e.querySelectorAll("[data-swapy-item]"),d=Array.from(r).map(u=>u.dataset.swapyItem);if(pt(l)){const u=yt(l);k("your container has duplicate slot ids",`(${u.join(", ")})`),n=!1}if(pt(d)){const u=yt(d);k("your container has duplicate item ids",`(${u.join(", ")})`),n=!1}return n}function pt(t){return new Set(t).size!==t.length}function yt(t){const e=new Set,n=new Set;for(const o of t)e.has(o)?n.add(o):e.add(o);return Array.from(n)}function Wt(t,e){if(t.size!==e.size)return!1;for(const[n,o]of t)if(e.get(n)!==o)return!1;return!0}function J(t){let e=t;for(;e;){const n=window.getComputedStyle(e),o=n.overflowY,l=n.overflowX;if((o==="auto"||o==="scroll")&&e.scrollHeight>e.clientHeight||(l==="auto"||l==="scroll")&&e.scrollWidth>e.clientWidth)return e;e=e.parentElement}return window}function kt(t,e){let l=!1,r,d=0,u=0,s=0,h=0,a=0,c=0,f=null;t instanceof HTMLElement?(r=G(t.getBoundingClientRect()),d=t.scrollHeight-r.height,u=t.scrollWidth-r.width):(r={x:0,y:0,width:window.innerWidth,height:window.innerHeight},d=document.documentElement.scrollHeight-window.innerHeight,u=document.documentElement.scrollWidth-window.innerWidth);function m(){t instanceof HTMLElement?(s=t.scrollTop,h=t.scrollLeft):(s=window.scrollY,h=window.scrollX)}function v(i){l=!1;const A=r.y,E=r.y+r.height,p=r.x,w=r.x+r.width,I=Math.abs(A-i.y)=-100){const M=W(T,-100,0);a=-K(-100,0,0,5,M),l=!0}}else{const T=E-i.y;if(T<=100){const M=W(T,0,100);a=K(100,0,0,5,M),l=!0}}if(e!=="y")if(x){const T=p-i.x;if(T>=-100){const M=W(T,-100,0);c=-K(-100,0,0,5,M),l=!0}}else{const T=w-i.x;if(T<=100){const M=W(T,0,100);c=K(100,0,0,5,M),l=!0}}l&&(f&&cancelAnimationFrame(f),g())}function g(){m(),e!=="x"&&(a=s+a>=d?0:a),e!=="y"&&(c=h+c>=u?0:c),t.scrollBy({top:a,left:c}),l&&(f=requestAnimationFrame(g))}function X(){l=!1}return{updatePointer:v,destroy:X}}P.createSwapy=_t,P.getClosestScrollableContainer=J,P.utils=Bt,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})}); diff --git a/package.json b/package.json index af59155..88c95aa 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "swapy", "author": "Taha Shashtari (taha@tahazsh.com)", "private": false, - "version": "1.0.1", + "version": "1.0.2", "type": "module", "main": "./dist/swapy.min.js", "module": "./dist/swapy.js",