@reelkit/core
Advanced tools
+321
-315
@@ -1,15 +0,15 @@ | ||
| const _ = (e) => e[0], w = (e) => e[e.length - 1], ve = (e) => e.length === 0, me = (e, n) => Array.from({ length: e }, (t, o) => n(o)), U = (e) => Math.abs(e), G = (e) => e < 0, C = (e, n, t) => Math.min(t, Math.max(n, e)), J = (e, n, t) => n * (1 - e) + t * e, Q = (e, n, t, o, r) => { | ||
| if (t ??= n, o ??= 1, r ??= !1, e <= 0 || t >= e) return []; | ||
| if (r && e === 1) return [0]; | ||
| const f = e - 1, u = Math.max(n - o, r ? 0 - o : 0), h = Math.min(t + o, r ? f + o : f), l = []; | ||
| for (let c = u; c <= h; c++) { | ||
| let D = c; | ||
| r && (c < 0 && (D = e + c), c > f && (D = c - e)), l.push(D); | ||
| const P = (e) => e[0], L = (e) => e[e.length - 1], me = (e) => e.length === 0, De = (e, n) => Array.from({ length: e }, (t, o) => n(o)), x = (e) => Math.abs(e), G = (e) => e < 0, C = (e, n, t) => Math.min(t, Math.max(n, e)), J = (e, n, t) => n * (1 - e) + t * e, Q = (e, n, t, o, a) => { | ||
| if (t ??= n, o ??= 1, a ??= !1, e <= 0 || t >= e) return []; | ||
| if (a && e === 1) return [0]; | ||
| const d = e - 1, c = Math.max(n - o, a ? 0 - o : 0), f = Math.min(t + o, a ? d + o : d), s = []; | ||
| for (let i = c; i <= f; i++) { | ||
| let S = i; | ||
| a && (i < 0 && (S = e + i), i > d && (S = i - e)), s.push(S); | ||
| } | ||
| return l; | ||
| }, x = (e, n, t, o) => (e.addEventListener(n, t, o), () => { | ||
| return s; | ||
| }, R = (e, n, t, o) => (e.addEventListener(n, t, o), () => { | ||
| e.removeEventListener(n, t, o); | ||
| }); | ||
| let z = 0; | ||
| const K = /* @__PURE__ */ new Set(), Z = (e) => { | ||
| const Y = /* @__PURE__ */ new Set(), j = (e) => { | ||
| z++; | ||
@@ -20,9 +20,9 @@ try { | ||
| if (z--, z === 0) { | ||
| const n = [...K]; | ||
| K.clear(), n.forEach((t) => t()); | ||
| const n = [...Y]; | ||
| Y.clear(), n.forEach((t) => t()); | ||
| } | ||
| } | ||
| }, V = (e) => { | ||
| }, B = (e) => { | ||
| let n = e; | ||
| const t = /* @__PURE__ */ new Set(), o = () => t.forEach((r) => r()); | ||
| const t = /* @__PURE__ */ new Set(), o = () => t.forEach((a) => a()); | ||
| return { | ||
@@ -32,7 +32,7 @@ get value() { | ||
| }, | ||
| set value(r) { | ||
| r !== n && (n = r, z > 0 ? K.add(o) : o()); | ||
| set value(a) { | ||
| a !== n && (n = a, z > 0 ? Y.add(o) : o()); | ||
| }, | ||
| observe(r) { | ||
| return t.add(r), () => t.delete(r); | ||
| observe(a) { | ||
| return t.add(a), () => t.delete(a); | ||
| } | ||
@@ -42,7 +42,7 @@ }; | ||
| let t = null; | ||
| const o = /* @__PURE__ */ new Set(), r = () => o.forEach((u) => u()), f = () => { | ||
| const o = /* @__PURE__ */ new Set(), a = () => o.forEach((c) => c()), d = () => { | ||
| if (t === null) { | ||
| const u = n().map((h) => h.observe(r)); | ||
| const c = n().map((f) => f.observe(a)); | ||
| t = () => { | ||
| u.forEach((h) => h()), t = null; | ||
| c.forEach((f) => f()), t = null; | ||
| }; | ||
@@ -55,12 +55,12 @@ } | ||
| }, | ||
| observe(u) { | ||
| return f(), o.add(u), () => { | ||
| o.delete(u), o.size === 0 && t && t(); | ||
| observe(c) { | ||
| return d(), o.add(c), () => { | ||
| o.delete(c), o.size === 0 && t && t(); | ||
| }; | ||
| } | ||
| }; | ||
| }, De = (e, n) => { | ||
| }, Se = (e, n) => { | ||
| const t = e().map((o) => o.observe(n)); | ||
| return () => t.forEach((o) => o()); | ||
| }, B = () => { | ||
| }, H = () => { | ||
| let e; | ||
@@ -82,8 +82,8 @@ return { promise: new Promise((t) => { | ||
| t !== -1 && (clearTimeout(t), t = -1); | ||
| }, r = (...f) => { | ||
| t = setTimeout(() => e(...f), n); | ||
| }, a = (...d) => { | ||
| t = setTimeout(() => e(...d), n); | ||
| }; | ||
| return r.cancel = o, r; | ||
| return a.cancel = o, a; | ||
| }, ne = () => { | ||
| }, Se = (e) => { | ||
| }, Te = (e) => { | ||
| try { | ||
@@ -97,3 +97,3 @@ const n = document.createElement("canvas"); | ||
| } | ||
| }, Te = (e) => { | ||
| }, Ie = (e) => { | ||
| let n = null; | ||
@@ -105,118 +105,120 @@ return { | ||
| }; | ||
| }, oe = 800, j = (e) => { | ||
| const [n, t] = [U(_(e)), U(w(e))]; | ||
| }, oe = 800, re = (e) => { | ||
| const [n, t] = [x(P(e)), x(L(e))]; | ||
| return n > 0 && n > t ? "horizontal" : t > 0 && t > n ? "vertical" : null; | ||
| }, H = (e, n) => n === "horizontal" ? _(e) : w(e), W = (e) => e !== null && typeof e == "object" && "changedTouches" in e, re = (e = {}, n = {}) => { | ||
| }, W = (e, n) => n === "horizontal" ? P(e) : L(e), X = (e) => e !== null && typeof e == "object" && "changedTouches" in e, ae = (e = {}, n = {}) => { | ||
| const { | ||
| useTouchEventsOnly: t = !1, | ||
| longPressDurationMs: o = oe | ||
| } = e, r = ee(); | ||
| let f = null, u = { ...n }, h = !1, l = null, c = null, D = null, I = [], O = !1; | ||
| const S = te((s) => { | ||
| c && _(c) === _(s.globalPosition) && w(c) === w(s.globalPosition) && (O = !0, u.onLongPress?.(s)); | ||
| }, o), L = () => { | ||
| l !== null && !h && (h = !0); | ||
| } = e, a = ee(); | ||
| let d = null, c = { ...n }, f = !1, s = null, i = null, S = null, I = [], y = null, v = !1; | ||
| const O = te((h) => { | ||
| i && P(i) === P(h.globalPosition) && L(i) === L(h.globalPosition) && (v = !0, c.onLongPress?.(h)); | ||
| }, o), U = () => { | ||
| s !== null && !f && (f = !0); | ||
| }, N = () => ({ | ||
| globalPosition: c, | ||
| globalPosition: i, | ||
| localPosition: [ | ||
| _(c) - _(D), | ||
| w(c) - w(D) | ||
| P(i) - P(S), | ||
| L(i) - L(S) | ||
| ], | ||
| sourceTimestamp: Date.now() | ||
| }), P = (s) => { | ||
| if (!f) return; | ||
| }), w = (h) => { | ||
| if (!d) return; | ||
| let g; | ||
| const E = f.getBoundingClientRect(); | ||
| if (D = [E.x, E.y], W(s)) { | ||
| const D = d.getBoundingClientRect(); | ||
| if (S = [D.x, D.y], X(h)) { | ||
| g = "touch"; | ||
| const T = s.changedTouches[0]; | ||
| c = [T.clientX, T.clientY]; | ||
| const A = h.changedTouches[0]; | ||
| i = [A.clientX, A.clientY]; | ||
| } else | ||
| g = "mouse", c = [s.clientX, s.clientY]; | ||
| l = N(); | ||
| const m = { ...l, kind: g }; | ||
| u.onLongPress && S(m), u.onTapDown?.(m); | ||
| }, A = (s) => { | ||
| if (l === null) return; | ||
| if (h) { | ||
| M(s), h = !1; | ||
| g = "mouse", i = [h.clientX, h.clientY]; | ||
| s = N(); | ||
| const T = { ...s, kind: g }; | ||
| c.onLongPress && O(T), c.onTapDown?.(T); | ||
| }, M = (h) => { | ||
| if (s === null) return; | ||
| if (f) { | ||
| u(h), f = !1; | ||
| return; | ||
| } | ||
| let g, E = [0, 0]; | ||
| if (W(s)) { | ||
| let g, D = [0, 0]; | ||
| if (X(h)) { | ||
| g = "touch"; | ||
| const y = s.changedTouches[0]; | ||
| E = [y.clientX, y.clientY]; | ||
| const E = h.changedTouches[0]; | ||
| D = [E.clientX, E.clientY]; | ||
| } else | ||
| g = "mouse", E = [s.clientX, s.clientY]; | ||
| const m = l.globalPosition, T = [ | ||
| _(E) - _(m), | ||
| w(E) - w(m) | ||
| ], a = [ | ||
| _(E) - _(c), | ||
| w(E) - w(c) | ||
| ], i = N(), v = j(a); | ||
| if (v !== null) { | ||
| const y = v === "horizontal" ? u.onHorizontalDragStart : u.onVerticalDragStart, b = v === "horizontal" ? u.onHorizontalDragUpdate : u.onVerticalDragUpdate; | ||
| I.length === 0 && y?.({ ...i, kind: g }); | ||
| const R = { | ||
| ...i, | ||
| delta: a, | ||
| primaryDelta: H(a, v), | ||
| distance: T, | ||
| primaryDistance: H(T, v), | ||
| cancel: L | ||
| g = "mouse", D = [h.clientX, h.clientY]; | ||
| const T = s.globalPosition, A = [ | ||
| P(D) - P(T), | ||
| L(D) - L(T) | ||
| ], r = [ | ||
| P(D) - P(i), | ||
| L(D) - L(i) | ||
| ], l = N(); | ||
| if (y === null && (y = re(r)), y !== null) { | ||
| const E = y === "horizontal" ? c.onHorizontalDragStart : c.onVerticalDragStart, _ = y === "horizontal" ? c.onHorizontalDragUpdate : c.onVerticalDragUpdate; | ||
| I.length === 0 && E?.({ ...l, kind: g }); | ||
| const b = { | ||
| ...l, | ||
| delta: r, | ||
| primaryDelta: W(r, y), | ||
| distance: A, | ||
| primaryDistance: W(A, y), | ||
| cancel: U | ||
| }; | ||
| I.push(R), b?.(R); | ||
| I.push(b), _?.(b); | ||
| } | ||
| c = E; | ||
| }, M = (s) => { | ||
| S.cancel(); | ||
| const g = W(s) ? "touch" : "mouse", E = l, m = w(I) ?? null; | ||
| I = [], l = null; | ||
| const T = N(); | ||
| if (u.onTapUp?.({ ...T, kind: g }), O && (O = !1, u.onLongPressEnd?.(T)), m !== null && E !== null) { | ||
| const a = m.delta, i = (T.sourceTimestamp - E.sourceTimestamp) / 1e3, v = [ | ||
| U(_(m.distance)) / i, | ||
| U(w(m.distance)) / i | ||
| ], y = { | ||
| ...T, | ||
| delta: m.delta, | ||
| distance: m.distance, | ||
| velocity: v | ||
| }, b = j(a); | ||
| b !== null && (b === "horizontal" ? u.onHorizontalDragEnd : u.onVerticalDragEnd)?.({ | ||
| ...y, | ||
| primaryDelta: m.primaryDelta, | ||
| primaryDistance: m.primaryDistance, | ||
| primaryVelocity: H(v, b) | ||
| }), u.onDragEnd?.(y); | ||
| i = D; | ||
| }, u = (h) => { | ||
| O.cancel(); | ||
| const g = X(h) ? "touch" : "mouse", D = s, T = L(I) ?? null; | ||
| I = [], s = null; | ||
| const A = N(); | ||
| if (c.onTapUp?.({ ...A, kind: g }), v && (v = !1, c.onLongPressEnd?.(A)), T !== null && D !== null) { | ||
| T.delta; | ||
| const r = (A.sourceTimestamp - D.sourceTimestamp) / 1e3, l = [ | ||
| x(P(T.distance)) / r, | ||
| x(L(T.distance)) / r | ||
| ], E = { | ||
| ...A, | ||
| delta: T.delta, | ||
| distance: T.distance, | ||
| velocity: l | ||
| }; | ||
| y !== null && (y === "horizontal" ? c.onHorizontalDragEnd : c.onVerticalDragEnd)?.({ | ||
| ...E, | ||
| primaryDelta: T.primaryDelta, | ||
| primaryDistance: T.primaryDistance, | ||
| primaryVelocity: W(l, y) | ||
| }), c.onDragEnd?.(E); | ||
| } | ||
| }, d = () => { | ||
| f && (r.push( | ||
| x(f, "touchstart", P, { passive: !0 }), | ||
| x(f, "touchmove", A, { passive: !0 }), | ||
| x(f, "touchend", M, { passive: !0 }) | ||
| ), t || r.push( | ||
| x(f, "mousedown", P), | ||
| x(f, "mousemove", A), | ||
| x(f, "mouseup", M) | ||
| y = null; | ||
| }, p = () => { | ||
| d && (a.push( | ||
| R(d, "touchstart", w, { passive: !0 }), | ||
| R(d, "touchmove", M, { passive: !0 }), | ||
| R(d, "touchend", u, { passive: !0 }) | ||
| ), t || a.push( | ||
| R(d, "mousedown", w), | ||
| R(d, "mousemove", M), | ||
| R(d, "mouseup", u) | ||
| )); | ||
| }, p = () => { | ||
| r.dispose(); | ||
| }, m = () => { | ||
| a.dispose(); | ||
| }; | ||
| return { | ||
| attach(s) { | ||
| f = s; | ||
| attach(h) { | ||
| d = h; | ||
| }, | ||
| detach() { | ||
| p(), f = null; | ||
| m(), d = null; | ||
| }, | ||
| observe: d, | ||
| unobserve: p, | ||
| updateEvents(s) { | ||
| u = { ...u, ...s }; | ||
| observe: p, | ||
| unobserve: m, | ||
| updateEvents(h) { | ||
| c = { ...c, ...h }; | ||
| } | ||
| }; | ||
| }, ae = /* @__PURE__ */ new Map([ | ||
| }, se = /* @__PURE__ */ new Map([ | ||
| ["ArrowUp", "up"], | ||
@@ -227,44 +229,44 @@ ["ArrowRight", "right"], | ||
| ["Escape", "escape"] | ||
| ]), se = (e = {}, n) => { | ||
| ]), le = (e = {}, n) => { | ||
| const { filter: t = [], throttleMs: o = 0 } = e; | ||
| let r = null, f = 0; | ||
| const u = (h) => { | ||
| const l = ae.get(h.key) ?? null; | ||
| if (l !== null) { | ||
| let a = null, d = 0; | ||
| const c = (f) => { | ||
| const s = se.get(f.key) ?? null; | ||
| if (s !== null) { | ||
| if (o > 0) { | ||
| const c = Date.now(); | ||
| if (c - f < o) | ||
| const i = Date.now(); | ||
| if (i - d < o) | ||
| return; | ||
| f = c; | ||
| d = i; | ||
| } | ||
| if (l === "escape") { | ||
| n.onKeyPress(l, h); | ||
| if (s === "escape") { | ||
| n.onKeyPress(s, f); | ||
| return; | ||
| } | ||
| (t.length === 0 || t.includes(l)) && n.onKeyPress(l, h); | ||
| (t.length === 0 || t.includes(s)) && n.onKeyPress(s, f); | ||
| } | ||
| }; | ||
| return { | ||
| attach(h = window) { | ||
| r && r(), r = x(h, "keydown", u); | ||
| attach(f = window) { | ||
| a && a(), a = R(f, "keydown", c); | ||
| }, | ||
| detach() { | ||
| r && (r(), r = null); | ||
| a && (a(), a = null); | ||
| } | ||
| }; | ||
| }, le = 200, ie = 10, ce = (e = {}, n) => { | ||
| }, ie = 200, ce = 10, ue = (e = {}, n) => { | ||
| const { | ||
| debounceMs: t = le, | ||
| deltaThreshold: o = ie | ||
| debounceMs: t = ie, | ||
| deltaThreshold: o = ce | ||
| } = e; | ||
| let r = null, f = null, u = null, h = null; | ||
| const l = (c) => { | ||
| let D = null; | ||
| Math.abs(c.deltaY) >= o ? D = c.deltaY > 0 ? "down" : "up" : Math.abs(c.deltaX) >= o && (D = c.deltaX > 0 ? "right" : "left"), D !== null && (c.preventDefault(), u = D, h = c, f && clearTimeout(f), f = setTimeout(() => { | ||
| u && h && (n.onWheel(u, h), u = null, h = null), f = null; | ||
| let a = null, d = null, c = null, f = null; | ||
| const s = (i) => { | ||
| let S = null; | ||
| x(i.deltaY) >= o ? S = i.deltaY > 0 ? "down" : "up" : x(i.deltaX) >= o && (S = i.deltaX > 0 ? "right" : "left"), S !== null && (i.preventDefault(), c = S, f = i, d && clearTimeout(d), d = setTimeout(() => { | ||
| c && f && (n.onWheel(c, f), c = null, f = null), d = null; | ||
| }, t)); | ||
| }; | ||
| return { | ||
| attach(c = window) { | ||
| r && r(), r = x(c, "wheel", l, { | ||
| attach(i = window) { | ||
| a && a(), a = R(i, "wheel", s, { | ||
| passive: !1 | ||
@@ -274,6 +276,6 @@ }); | ||
| detach() { | ||
| r && (r(), r = null), f && (clearTimeout(f), f = null), u = null, h = null; | ||
| a && (a(), a = null), d && (clearTimeout(d), d = null), c = null, f = null; | ||
| } | ||
| }; | ||
| }, q = 300, ue = 0.12, X = 3, de = q + 100, fe = 200, he = (e, n, t) => Q(n, e, e, 1, t), Ie = (e, n = {}) => { | ||
| }, q = 300, de = 0.12, k = 3, fe = q + 100, he = 200, pe = (e, n, t) => Q(n, e, e, 1, t), ye = (e, n = {}) => { | ||
| let t = { | ||
@@ -285,46 +287,46 @@ count: e.count, | ||
| transitionDuration: e.transitionDuration ?? q, | ||
| swipeDistanceFactor: e.swipeDistanceFactor ?? ue, | ||
| rangeExtractor: e.rangeExtractor ?? he, | ||
| swipeDistanceFactor: e.swipeDistanceFactor ?? de, | ||
| rangeExtractor: e.rangeExtractor ?? pe, | ||
| enableWheel: e.enableWheel ?? !1, | ||
| wheelDebounceMs: e.wheelDebounceMs ?? fe | ||
| }, o = { ...n }, r = 0, f = !0, u = !1, h = !1; | ||
| const l = V(t.initialIndex), c = V({ value: 0, duration: 0 }), D = V(null), I = $( | ||
| wheelDebounceMs: e.wheelDebounceMs ?? he | ||
| }, o = { ...n }, a = 0, d = !0, c = !1, f = !1; | ||
| const s = B(t.initialIndex), i = B({ value: 0, duration: 0 }), S = B(null), I = $( | ||
| () => { | ||
| const a = D.value; | ||
| if (a !== null) { | ||
| const b = l.value; | ||
| return a > b ? [b, a] : [a, b]; | ||
| const r = S.value; | ||
| if (r !== null) { | ||
| const b = s.value; | ||
| return r > b ? [b, r] : [r, b]; | ||
| } | ||
| const i = t.rangeExtractor( | ||
| l.value, | ||
| const l = t.rangeExtractor( | ||
| s.value, | ||
| t.count, | ||
| t.loop | ||
| ); | ||
| if (i.length <= X) return i; | ||
| const v = i.indexOf(l.value), y = C(v - 1, 0, i.length - X); | ||
| return i.slice(y, y + X); | ||
| if (l.length <= k) return l; | ||
| const E = l.indexOf(s.value), _ = C(E - 1, 0, l.length - k); | ||
| return l.slice(_, _ + k); | ||
| }, | ||
| () => [l, D] | ||
| ), O = { index: l, axisValue: c, indexes: I }, S = () => I.value.indexOf(l.value), L = (a = 0, i) => { | ||
| c.value = { | ||
| value: S() * r * -1, | ||
| duration: a, | ||
| done: i | ||
| () => [s, S] | ||
| ), y = { index: s, axisValue: i, indexes: I }, v = () => I.value.indexOf(s.value), O = (r = 0, l) => { | ||
| i.value = { | ||
| value: v() * a * -1, | ||
| duration: r, | ||
| done: l | ||
| }; | ||
| }, N = async (a) => { | ||
| const { promise: i } = a(); | ||
| await i; | ||
| }, P = (a, i) => a.length === 1 ? !0 : a.length === 2 && (S() === 0 && i === -1 || S() === 1 && i === 1), A = async (a) => { | ||
| h = !0, g.unobserve(); | ||
| const i = I.value, v = C( | ||
| S() + a, | ||
| }, U = async (r) => { | ||
| const { promise: l } = r(); | ||
| await l; | ||
| }, N = (r, l) => r.length === 1 ? !0 : r.length === 2 && (v() === 0 && l === -1 || v() === 1 && l === 1), w = async (r) => { | ||
| f = !0, g.unobserve(); | ||
| const l = I.value, E = C( | ||
| v() + r, | ||
| 0, | ||
| i.length - 1 | ||
| ), y = i[v]; | ||
| o.onBeforeChange?.(l.value, y, S()); | ||
| l.length - 1 | ||
| ), _ = l[E]; | ||
| o.onBeforeChange?.(s.value, _, v()); | ||
| try { | ||
| await N(() => { | ||
| const b = B(); | ||
| return c.value = { | ||
| value: v * r * -1, | ||
| await U(() => { | ||
| const b = H(); | ||
| return i.value = { | ||
| value: E * a * -1, | ||
| duration: t.transitionDuration, | ||
@@ -335,88 +337,92 @@ done: () => b.resolve() | ||
| } finally { | ||
| Z(() => { | ||
| l.value = y, c.value = { | ||
| value: S() * r * -1, | ||
| j(() => { | ||
| s.value = _, i.value = { | ||
| value: v() * a * -1, | ||
| duration: 0 | ||
| }; | ||
| }), g.observe(), h = !1; | ||
| }), g.observe(), f = !1; | ||
| } | ||
| }, M = (a) => { | ||
| c.value = { | ||
| value: c.value.value + a.primaryDelta, | ||
| }, M = (r) => { | ||
| i.value = { | ||
| value: i.value.value + r.primaryDelta, | ||
| duration: 0 | ||
| }; | ||
| }, d = () => { | ||
| o.onDragStart?.(l.value); | ||
| }, p = async (a) => { | ||
| const v = t.direction === "horizontal" ? 0 : 1, y = r * t.swipeDistanceFactor, b = v === 0 ? _(a.distance) : w(a.distance), R = v === 0 ? _(a.velocity) : w(a.velocity), F = G(b) ? 1 : -1; | ||
| !P(I.value, F) && (U(b) > y || R > 1400 && U(b) > y / 2) && (A(F).then(() => { | ||
| u && L(); | ||
| }), f = !1), o.onDragEnd?.(l.value), f && (await N(() => { | ||
| const Y = B(); | ||
| return L( | ||
| }; | ||
| let u = !1; | ||
| const p = () => { | ||
| u = !0, o.onDragStart?.(s.value); | ||
| }, m = async (r) => { | ||
| if (!u) return; | ||
| u = !1; | ||
| const E = t.direction === "horizontal" ? 0 : 1, _ = a * t.swipeDistanceFactor, b = E === 0 ? P(r.distance) : L(r.distance), V = E === 0 ? P(r.velocity) : L(r.velocity), F = G(b) ? 1 : -1; | ||
| !N(I.value, F) && (x(b) > _ || V > 1400 && x(b) > _ / 2) && (w(F).then(() => { | ||
| c && O(); | ||
| }), d = !1), o.onDragEnd?.(s.value), d && (await U(() => { | ||
| const Z = H(); | ||
| return O( | ||
| t.transitionDuration, | ||
| () => Y.resolve() | ||
| ), Y; | ||
| }), u && L(), o.onDragCanceled?.(l.value)), f = !0; | ||
| }, s = () => t.direction === "horizontal", g = re( | ||
| () => Z.resolve() | ||
| ), Z; | ||
| }), c && O(), o.onDragCanceled?.(s.value)), d = !0; | ||
| }, h = () => t.direction === "horizontal", g = ae( | ||
| { useTouchEventsOnly: !0 }, | ||
| { | ||
| onHorizontalDragStart: s() ? d : void 0, | ||
| onHorizontalDragUpdate: s() ? M : void 0, | ||
| onVerticalDragStart: s() ? void 0 : d, | ||
| onVerticalDragUpdate: s() ? void 0 : M, | ||
| onDragEnd: p | ||
| onHorizontalDragStart: h() ? p : void 0, | ||
| onHorizontalDragUpdate: h() ? M : void 0, | ||
| onVerticalDragStart: h() ? void 0 : p, | ||
| onVerticalDragUpdate: h() ? void 0 : M, | ||
| onDragEnd: m | ||
| } | ||
| ), E = se( | ||
| { throttleMs: de }, | ||
| ), D = le( | ||
| { throttleMs: fe }, | ||
| { | ||
| onKeyPress: (a) => { | ||
| let i = null; | ||
| s() ? (a === "left" && (i = -1), a === "right" && (i = 1)) : (a === "up" && (i = -1), a === "down" && (i = 1)), i !== null && (P(I.value, i) || A(i)); | ||
| onKeyPress: (r) => { | ||
| let l = null; | ||
| h() ? (r === "left" && (l = -1), r === "right" && (l = 1)) : (r === "up" && (l = -1), r === "down" && (l = 1)), l !== null && (N(I.value, l) || w(l)); | ||
| } | ||
| } | ||
| ), m = t.enableWheel ? ce( | ||
| ), T = t.enableWheel ? ue( | ||
| { debounceMs: t.wheelDebounceMs }, | ||
| { | ||
| onWheel: (a) => { | ||
| let i = null; | ||
| s() ? (a === "left" && (i = -1), a === "right" && (i = 1)) : (a === "up" && (i = -1), a === "down" && (i = 1)), i !== null && (P(I.value, i) || A(i)); | ||
| onWheel: (r) => { | ||
| let l = null; | ||
| h() ? (r === "left" && (l = -1), r === "right" && (l = 1)) : (r === "up" && (l = -1), r === "down" && (l = 1)), l !== null && (N(I.value, l) || w(l)); | ||
| } | ||
| } | ||
| ) : null; | ||
| let T = null; | ||
| return o.onAfterChange && (T = l.observe(() => { | ||
| o.onAfterChange?.(l.value, S()); | ||
| let A = null; | ||
| return o.onAfterChange && (A = s.observe(() => { | ||
| o.onAfterChange?.(s.value, v()); | ||
| })), { | ||
| state: O, | ||
| state: y, | ||
| config: t, | ||
| getRangeIndex: S, | ||
| getRangeIndex: v, | ||
| async next() { | ||
| h || P(I.value, 1) || await A(1); | ||
| f || N(I.value, 1) || await w(1); | ||
| }, | ||
| async prev() { | ||
| h || P(I.value, -1) || await A(-1); | ||
| f || N(I.value, -1) || await w(-1); | ||
| }, | ||
| async goTo(a, i = !1) { | ||
| if (h) return; | ||
| const v = C(a, 0, t.count - 1); | ||
| if (v === l.value) return; | ||
| if (g.unobserve(), !i) { | ||
| o.onBeforeChange?.(l.value, v, S()), l.value = v, L(0), o.onAfterChange?.(l.value, S()), g.observe(); | ||
| async goTo(r, l = !1) { | ||
| if (f) return; | ||
| const E = C(r, 0, t.count - 1); | ||
| if (E === s.value) return; | ||
| if (g.unobserve(), !l) { | ||
| o.onBeforeChange?.(s.value, E, v()), s.value = E, O(0), o.onAfterChange?.(s.value, v()), g.observe(); | ||
| return; | ||
| } | ||
| h = !0; | ||
| const y = v > l.value; | ||
| o.onBeforeChange?.(l.value, v, S()), D.value = v; | ||
| const b = y ? 0 : 1; | ||
| c.value = { | ||
| value: b * r * -1, | ||
| f = !0; | ||
| const _ = E > s.value; | ||
| o.onBeforeChange?.(s.value, E, v()), S.value = E; | ||
| const b = _ ? 0 : 1; | ||
| i.value = { | ||
| value: b * a * -1, | ||
| duration: 0 | ||
| }; | ||
| const R = y ? 1 : 0; | ||
| const V = _ ? 1 : 0; | ||
| try { | ||
| await N(() => { | ||
| const F = B(); | ||
| return c.value = { | ||
| value: R * r * -1, | ||
| await U(() => { | ||
| const F = H(); | ||
| return i.value = { | ||
| value: V * a * -1, | ||
| duration: t.transitionDuration, | ||
@@ -427,116 +433,116 @@ done: () => F.resolve() | ||
| } finally { | ||
| Z(() => { | ||
| D.value = null, l.value = v, L(0); | ||
| }), o.onAfterChange?.(l.value, S()), g.observe(), h = !1; | ||
| j(() => { | ||
| S.value = null, s.value = E, O(0); | ||
| }), o.onAfterChange?.(s.value, v()), g.observe(), f = !1; | ||
| } | ||
| }, | ||
| adjust(a = 0) { | ||
| h || L(a); | ||
| adjust(r = 0) { | ||
| f || O(r); | ||
| }, | ||
| setPrimarySize(a) { | ||
| a !== r && (u = !0, r = a, h || L()); | ||
| setPrimarySize(r) { | ||
| r !== a && (c = !0, a = r, f || O()); | ||
| }, | ||
| updateConfig(a) { | ||
| t = { ...t, ...a }; | ||
| const i = t.direction === "horizontal"; | ||
| updateConfig(r) { | ||
| t = { ...t, ...r }; | ||
| const l = t.direction === "horizontal"; | ||
| g.updateEvents({ | ||
| onHorizontalDragStart: i ? d : void 0, | ||
| onHorizontalDragUpdate: i ? M : void 0, | ||
| onVerticalDragStart: i ? void 0 : d, | ||
| onVerticalDragUpdate: i ? void 0 : M | ||
| onHorizontalDragStart: l ? p : void 0, | ||
| onHorizontalDragUpdate: l ? M : void 0, | ||
| onVerticalDragStart: l ? void 0 : p, | ||
| onVerticalDragUpdate: l ? void 0 : M | ||
| }); | ||
| }, | ||
| updateEvents(a) { | ||
| o = { ...o, ...a }, T && (T(), T = null), o.onAfterChange && (T = l.observe(() => { | ||
| o.onAfterChange?.(l.value, S()); | ||
| updateEvents(r) { | ||
| o = { ...o, ...r }, A && (A(), A = null), o.onAfterChange && (A = s.observe(() => { | ||
| o.onAfterChange?.(s.value, v()); | ||
| })); | ||
| }, | ||
| observe() { | ||
| g.observe(), E.attach(), m?.attach(); | ||
| g.observe(), D.attach(), T?.attach(); | ||
| }, | ||
| unobserve() { | ||
| g.unobserve(), E.detach(), m?.detach(); | ||
| g.unobserve(), D.detach(), T?.detach(); | ||
| }, | ||
| attach(a) { | ||
| g.attach(a); | ||
| attach(r) { | ||
| g.attach(r); | ||
| }, | ||
| detach() { | ||
| g.detach(), E.detach(), m?.detach(); | ||
| g.detach(), D.detach(), T?.detach(); | ||
| }, | ||
| dispose() { | ||
| g.detach(), E.detach(), m?.detach(), T && T(); | ||
| g.detach(), D.detach(), T?.detach(), A && A(); | ||
| } | ||
| }; | ||
| }, pe = (e, n, t, o) => { | ||
| const D = (d, p) => 1 - 3 * p + 3 * d, I = (d, p) => 3 * p - 6 * d, O = (d) => 3 * d, S = (d, p, s) => ((D(p, s) * d + I(p, s)) * d + O(p)) * d, L = (d, p, s) => 3 * D(p, s) * d * d + 2 * I(p, s) * d + O(p), N = (d, p, s) => { | ||
| let g, E, m = 0; | ||
| }, ge = (e, n, t, o) => { | ||
| const S = (u, p) => 1 - 3 * p + 3 * u, I = (u, p) => 3 * p - 6 * u, y = (u) => 3 * u, v = (u, p, m) => ((S(p, m) * u + I(p, m)) * u + y(p)) * u, O = (u, p, m) => 3 * S(p, m) * u * u + 2 * I(p, m) * u + y(p), U = (u, p, m) => { | ||
| let h, g, D = 0; | ||
| do | ||
| E = p + (s - p) / 2, g = S(E, e, t) - d, g > 0 ? s = E : p = E; | ||
| while (Math.abs(g) > 1e-7 && ++m < 10); | ||
| return E; | ||
| }, P = (d, p) => { | ||
| for (let s = 0; s < 4; ++s) { | ||
| const g = L(p, e, t); | ||
| if (g === 0) return p; | ||
| const E = S(p, e, t) - d; | ||
| p -= E / g; | ||
| g = p + (m - p) / 2, h = v(g, e, t) - u, h > 0 ? m = g : p = g; | ||
| while (x(h) > 1e-7 && ++D < 10); | ||
| return g; | ||
| }, N = (u, p) => { | ||
| for (let m = 0; m < 4; ++m) { | ||
| const h = O(p, e, t); | ||
| if (h === 0) return p; | ||
| const g = v(p, e, t) - u; | ||
| p -= g / h; | ||
| } | ||
| return p; | ||
| }, A = new Float32Array(11); | ||
| for (let d = 0; d < 11; ++d) | ||
| A[d] = S(d * 0.1, e, t); | ||
| const M = (d) => { | ||
| let p = 0, s = 1; | ||
| const g = 10; | ||
| for (; s !== g && A[s] <= d; ++s) | ||
| }, w = new Float32Array(11); | ||
| for (let u = 0; u < 11; ++u) | ||
| w[u] = v(u * 0.1, e, t); | ||
| const M = (u) => { | ||
| let p = 0, m = 1; | ||
| const h = 10; | ||
| for (; m !== h && w[m] <= u; ++m) | ||
| p += 0.1; | ||
| --s; | ||
| const E = (d - A[s]) / (A[s + 1] - A[s]), m = p + E * 0.1, T = L(m, e, t); | ||
| return T >= 1e-3 ? P(d, m) : T === 0 ? m : N(d, p, p + 0.1); | ||
| --m; | ||
| const g = (u - w[m]) / (w[m + 1] - w[m]), D = p + g * 0.1, T = O(D, e, t); | ||
| return T >= 1e-3 ? N(u, D) : T === 0 ? D : U(u, p, p + 0.1); | ||
| }; | ||
| return (d) => d === 0 || d === 1 ? d : S(M(d), n, o); | ||
| return (u) => u === 0 || u === 1 ? u : v(M(u), n, o); | ||
| }; | ||
| let k = null; | ||
| const ge = () => (k === null && (k = pe(0.4, 0, 0.2, 1)), k), ye = (e) => { | ||
| const { from: n, to: t, duration: o, onUpdate: r, onComplete: f } = e; | ||
| let K = null; | ||
| const Ee = () => (K === null && (K = ge(0.4, 0, 0.2, 1)), K), Ae = (e) => { | ||
| const { from: n, to: t, duration: o, onUpdate: a, onComplete: d } = e; | ||
| if (o <= 0) | ||
| return r(t), f?.(), ne; | ||
| let u = null, h, l = !1; | ||
| const c = (D) => { | ||
| if (l) return; | ||
| h ??= D; | ||
| const I = D - h, O = ge()(C(I / o, 0, 1)), S = J(O, n, t); | ||
| r(S), I < o ? u = requestAnimationFrame(c) : f?.(); | ||
| return a(t), d?.(), ne; | ||
| let c = null, f, s = !1; | ||
| const i = (S) => { | ||
| if (s) return; | ||
| f ??= S; | ||
| const I = S - f, y = Ee()(C(I / o, 0, 1)), v = J(y, n, t); | ||
| a(v), I < o ? c = requestAnimationFrame(i) : d?.(); | ||
| }; | ||
| return u = requestAnimationFrame(c), () => { | ||
| l = !0, u !== null && cancelAnimationFrame(u); | ||
| return c = requestAnimationFrame(i), () => { | ||
| s = !0, c !== null && cancelAnimationFrame(c); | ||
| }; | ||
| }; | ||
| export { | ||
| U as abs, | ||
| ye as animate, | ||
| Z as batch, | ||
| Se as captureFrame, | ||
| x as abs, | ||
| Ae as animate, | ||
| j as batch, | ||
| Te as captureFrame, | ||
| C as clamp, | ||
| $ as createComputed, | ||
| B as createDeferred, | ||
| H as createDeferred, | ||
| ee as createDisposableList, | ||
| re as createGestureController, | ||
| se as createKeyboardController, | ||
| Te as createSharedVideo, | ||
| V as createSignal, | ||
| Ie as createSliderController, | ||
| ce as createWheelController, | ||
| he as defaultRangeExtractor, | ||
| ae as createGestureController, | ||
| le as createKeyboardController, | ||
| Ie as createSharedVideo, | ||
| B as createSignal, | ||
| ye as createSliderController, | ||
| ue as createWheelController, | ||
| pe as defaultRangeExtractor, | ||
| Q as extractRange, | ||
| _ as first, | ||
| me as generate, | ||
| ve as isEmpty, | ||
| P as first, | ||
| De as generate, | ||
| me as isEmpty, | ||
| G as isNegative, | ||
| w as last, | ||
| L as last, | ||
| J as lerp, | ||
| ne as noop, | ||
| x as observeDomEvent, | ||
| De as reaction, | ||
| R as observeDomEvent, | ||
| Se as reaction, | ||
| te as timeout | ||
| }; |
+1
-1
| { | ||
| "name": "@reelkit/core", | ||
| "version": "0.2.1", | ||
| "version": "0.2.2", | ||
| "type": "module", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
+2
-2
@@ -5,3 +5,3 @@ # @reelkit/core | ||
| <a href="https://www.npmjs.com/package/@reelkit/core"><img src="https://img.shields.io/npm/v/@reelkit/core?color=6366f1&label=npm" alt="npm" /></a> | ||
| <img src="https://img.shields.io/badge/gzip-4.0%20kB-6366f1" alt="Bundle size" /> | ||
| <img src="https://img.shields.io/badge/gzip-4.1%20kB-6366f1" alt="Bundle size" /> | ||
| <a href="https://github.com/KonstantinKai/reelkit"><img src="https://img.shields.io/github/stars/KonstantinKai/reelkit?style=social" alt="Star on GitHub" /></a> | ||
@@ -45,3 +45,3 @@ </p> | ||
| - Renders only 3 slides at a time (virtualized), handles 10,000+ items | ||
| - Zero dependencies, ~4.0 kB gzip | ||
| - Zero dependencies, ~4.1 kB gzip | ||
| - Factory functions over classes — `createSliderController`, `createGestureController`, `createKeyboardController`, `createWheelController` | ||
@@ -48,0 +48,0 @@ - Built-in `Signal`, `ComputedSignal`, and `reaction` primitives for reactive state |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
55819
0.13%1394
0.43%