@reelkit/core
Advanced tools
+229
-222
@@ -1,25 +0,25 @@ | ||
| const _ = (e) => e[0], w = (e) => e[e.length - 1], ge = (e) => e.length === 0, ve = (e, n) => Array.from({ length: e }, (t, o) => n(o)), x = (e) => Math.abs(e), q = (e) => e < 0, X = (e, n, t) => Math.min(t, Math.max(n, e)), G = (e, n, t) => n * (1 - e) + t * e, J = (e, n, t, o, r) => { | ||
| 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 i = u; i <= h; i++) { | ||
| let D = i; | ||
| r && (i < 0 && (D = e + i), i > f && (D = i - e)), l.push(D); | ||
| for (let c = u; c <= h; c++) { | ||
| let D = c; | ||
| r && (c < 0 && (D = e + c), c > f && (D = c - e)), l.push(D); | ||
| } | ||
| return l; | ||
| }, R = (e, n, t, o) => (e.addEventListener(n, t, o), () => { | ||
| }, x = (e, n, t, o) => (e.addEventListener(n, t, o), () => { | ||
| e.removeEventListener(n, t, o); | ||
| }); | ||
| let C = 0; | ||
| const k = /* @__PURE__ */ new Set(), Y = (e) => { | ||
| C++; | ||
| let z = 0; | ||
| const K = /* @__PURE__ */ new Set(), Z = (e) => { | ||
| z++; | ||
| try { | ||
| e(); | ||
| } finally { | ||
| if (C--, C === 0) { | ||
| const n = [...k]; | ||
| k.clear(), n.forEach((t) => t()); | ||
| if (z--, z === 0) { | ||
| const n = [...K]; | ||
| K.clear(), n.forEach((t) => t()); | ||
| } | ||
| } | ||
| }, z = (e) => { | ||
| }, V = (e) => { | ||
| let n = e; | ||
@@ -32,3 +32,3 @@ const t = /* @__PURE__ */ new Set(), o = () => t.forEach((r) => r()); | ||
| set value(r) { | ||
| r !== n && (n = r, C > 0 ? k.add(o) : o()); | ||
| r !== n && (n = r, z > 0 ? K.add(o) : o()); | ||
| }, | ||
@@ -39,3 +39,3 @@ observe(r) { | ||
| }; | ||
| }, Q = (e, n) => { | ||
| }, $ = (e, n) => { | ||
| let t = null; | ||
@@ -60,6 +60,6 @@ const o = /* @__PURE__ */ new Set(), r = () => o.forEach((u) => u()), f = () => { | ||
| }; | ||
| }, me = (e, n) => { | ||
| }, De = (e, n) => { | ||
| const t = e().map((o) => o.observe(n)); | ||
| return () => t.forEach((o) => o()); | ||
| }, V = () => { | ||
| }, B = () => { | ||
| let e; | ||
@@ -69,3 +69,3 @@ return { promise: new Promise((t) => { | ||
| }), resolve: e }; | ||
| }, $ = () => { | ||
| }, ee = () => { | ||
| const e = []; | ||
@@ -78,3 +78,3 @@ return { | ||
| }; | ||
| }, ee = (e, n = 0) => { | ||
| }, te = (e, n = 0) => { | ||
| let t = -1; | ||
@@ -87,4 +87,4 @@ const o = () => { | ||
| return r.cancel = o, r; | ||
| }, te = () => { | ||
| }, De = (e) => { | ||
| }, ne = () => { | ||
| }, Se = (e) => { | ||
| try { | ||
@@ -98,3 +98,3 @@ const n = document.createElement("canvas"); | ||
| } | ||
| }, Se = (e) => { | ||
| }, Te = (e) => { | ||
| let n = null; | ||
@@ -106,36 +106,36 @@ return { | ||
| }; | ||
| }, ne = 800, Z = (e) => { | ||
| const [n, t] = [x(_(e)), x(w(e))]; | ||
| }, oe = 800, j = (e) => { | ||
| const [n, t] = [U(_(e)), U(w(e))]; | ||
| return n > 0 && n > t ? "horizontal" : t > 0 && t > n ? "vertical" : null; | ||
| }, B = (e, n) => n === "horizontal" ? _(e) : w(e), H = (e) => e !== null && typeof e == "object" && "changedTouches" in e, oe = (e = {}, n = {}) => { | ||
| }, H = (e, n) => n === "horizontal" ? _(e) : w(e), W = (e) => e !== null && typeof e == "object" && "changedTouches" in e, re = (e = {}, n = {}) => { | ||
| const { | ||
| useTouchEventsOnly: t = !1, | ||
| longPressDurationMs: o = ne | ||
| } = e, r = $(); | ||
| let f = null, u = { ...n }, h = !1, l = null, i = null, D = null, I = [], O = !1; | ||
| const S = ee((s) => { | ||
| i && _(i) === _(s.globalPosition) && w(i) === w(s.globalPosition) && (O = !0, u.onLongPress?.(s)); | ||
| }, o), P = () => { | ||
| 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); | ||
| }, N = () => ({ | ||
| globalPosition: i, | ||
| globalPosition: c, | ||
| localPosition: [ | ||
| _(i) - _(D), | ||
| w(i) - w(D) | ||
| _(c) - _(D), | ||
| w(c) - w(D) | ||
| ], | ||
| sourceTimestamp: Date.now() | ||
| }), L = (s) => { | ||
| }), P = (s) => { | ||
| if (!f) return; | ||
| let E; | ||
| const g = f.getBoundingClientRect(); | ||
| if (D = [g.x, g.y], H(s)) { | ||
| E = "touch"; | ||
| let g; | ||
| const E = f.getBoundingClientRect(); | ||
| if (D = [E.x, E.y], W(s)) { | ||
| g = "touch"; | ||
| const T = s.changedTouches[0]; | ||
| i = [T.clientX, T.clientY]; | ||
| c = [T.clientX, T.clientY]; | ||
| } else | ||
| E = "mouse", i = [s.clientX, s.clientY]; | ||
| g = "mouse", c = [s.clientX, s.clientY]; | ||
| l = N(); | ||
| const v = { ...l, kind: E }; | ||
| u.onLongPress && S(v), u.onTapDown?.(v); | ||
| }, b = (s) => { | ||
| const m = { ...l, kind: g }; | ||
| u.onLongPress && S(m), u.onTapDown?.(m); | ||
| }, A = (s) => { | ||
| if (l === null) return; | ||
@@ -146,50 +146,50 @@ if (h) { | ||
| } | ||
| let E, g = [0, 0]; | ||
| if (H(s)) { | ||
| E = "touch"; | ||
| let g, E = [0, 0]; | ||
| if (W(s)) { | ||
| g = "touch"; | ||
| const y = s.changedTouches[0]; | ||
| g = [y.clientX, y.clientY]; | ||
| E = [y.clientX, y.clientY]; | ||
| } else | ||
| E = "mouse", g = [s.clientX, s.clientY]; | ||
| const v = l.globalPosition, T = [ | ||
| _(g) - _(v), | ||
| w(g) - w(v) | ||
| g = "mouse", E = [s.clientX, s.clientY]; | ||
| const m = l.globalPosition, T = [ | ||
| _(E) - _(m), | ||
| w(E) - w(m) | ||
| ], a = [ | ||
| _(g) - _(i), | ||
| w(g) - w(i) | ||
| ], c = N(), m = Z(a); | ||
| if (m !== null) { | ||
| const y = m === "horizontal" ? u.onHorizontalDragStart : u.onVerticalDragStart, A = m === "horizontal" ? u.onHorizontalDragUpdate : u.onVerticalDragUpdate; | ||
| I.length === 0 && y?.({ ...c, kind: E }); | ||
| const U = { | ||
| ...c, | ||
| _(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: B(a, m), | ||
| primaryDelta: H(a, v), | ||
| distance: T, | ||
| primaryDistance: B(T, m), | ||
| cancel: P | ||
| primaryDistance: H(T, v), | ||
| cancel: L | ||
| }; | ||
| I.push(U), A?.(U); | ||
| I.push(R), b?.(R); | ||
| } | ||
| i = g; | ||
| c = E; | ||
| }, M = (s) => { | ||
| S.cancel(); | ||
| const E = H(s) ? "touch" : "mouse", g = l, v = w(I) ?? null; | ||
| const g = W(s) ? "touch" : "mouse", E = l, m = w(I) ?? null; | ||
| I = [], l = null; | ||
| const T = N(); | ||
| if (u.onTapUp?.({ ...T, kind: E }), O && (O = !1, u.onLongPressEnd?.(T)), v !== null && g !== null) { | ||
| const a = v.delta, c = (T.sourceTimestamp - g.sourceTimestamp) / 1e3, m = [ | ||
| x(_(v.distance)) / c, | ||
| x(w(v.distance)) / c | ||
| 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: v.delta, | ||
| distance: v.distance, | ||
| velocity: m | ||
| }, A = Z(a); | ||
| A !== null && (A === "horizontal" ? u.onHorizontalDragEnd : u.onVerticalDragEnd)?.({ | ||
| delta: m.delta, | ||
| distance: m.distance, | ||
| velocity: v | ||
| }, b = j(a); | ||
| b !== null && (b === "horizontal" ? u.onHorizontalDragEnd : u.onVerticalDragEnd)?.({ | ||
| ...y, | ||
| primaryDelta: v.primaryDelta, | ||
| primaryDistance: v.primaryDistance, | ||
| primaryVelocity: B(m, A) | ||
| primaryDelta: m.primaryDelta, | ||
| primaryDistance: m.primaryDistance, | ||
| primaryVelocity: H(v, b) | ||
| }), u.onDragEnd?.(y); | ||
@@ -199,9 +199,9 @@ } | ||
| f && (r.push( | ||
| R(f, "touchstart", L, { passive: !0 }), | ||
| R(f, "touchmove", b, { passive: !0 }), | ||
| R(f, "touchend", M, { passive: !0 }) | ||
| x(f, "touchstart", P, { passive: !0 }), | ||
| x(f, "touchmove", A, { passive: !0 }), | ||
| x(f, "touchend", M, { passive: !0 }) | ||
| ), t || r.push( | ||
| R(f, "mousedown", L), | ||
| R(f, "mousemove", b), | ||
| R(f, "mouseup", M) | ||
| x(f, "mousedown", P), | ||
| x(f, "mousemove", A), | ||
| x(f, "mouseup", M) | ||
| )); | ||
@@ -224,3 +224,3 @@ }, p = () => { | ||
| }; | ||
| }, re = /* @__PURE__ */ new Map([ | ||
| }, ae = /* @__PURE__ */ new Map([ | ||
| ["ArrowUp", "up"], | ||
@@ -231,13 +231,13 @@ ["ArrowRight", "right"], | ||
| ["Escape", "escape"] | ||
| ]), ae = (e = {}, n) => { | ||
| ]), se = (e = {}, n) => { | ||
| const { filter: t = [], throttleMs: o = 0 } = e; | ||
| let r = null, f = 0; | ||
| const u = (h) => { | ||
| const l = re.get(h.key) ?? null; | ||
| const l = ae.get(h.key) ?? null; | ||
| if (l !== null) { | ||
| if (o > 0) { | ||
| const i = Date.now(); | ||
| if (i - f < o) | ||
| const c = Date.now(); | ||
| if (c - f < o) | ||
| return; | ||
| f = i; | ||
| f = c; | ||
| } | ||
@@ -253,3 +253,3 @@ if (l === "escape") { | ||
| attach(h = window) { | ||
| r && r(), r = R(h, "keydown", u); | ||
| r && r(), r = x(h, "keydown", u); | ||
| }, | ||
@@ -260,11 +260,11 @@ detach() { | ||
| }; | ||
| }, se = 200, le = 10, ie = (e = {}, n) => { | ||
| }, le = 200, ie = 10, ce = (e = {}, n) => { | ||
| const { | ||
| debounceMs: t = se, | ||
| deltaThreshold: o = le | ||
| debounceMs: t = le, | ||
| deltaThreshold: o = ie | ||
| } = e; | ||
| let r = null, f = null, u = null, h = null; | ||
| const l = (i) => { | ||
| const l = (c) => { | ||
| let D = null; | ||
| Math.abs(i.deltaY) >= o ? D = i.deltaY > 0 ? "down" : "up" : Math.abs(i.deltaX) >= o && (D = i.deltaX > 0 ? "right" : "left"), D !== null && (i.preventDefault(), u = D, h = i, f && clearTimeout(f), f = setTimeout(() => { | ||
| 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; | ||
@@ -274,4 +274,4 @@ }, t)); | ||
| return { | ||
| attach(i = window) { | ||
| r && r(), r = R(i, "wheel", l, { | ||
| attach(c = window) { | ||
| r && r(), r = x(c, "wheel", l, { | ||
| passive: !1 | ||
@@ -284,3 +284,3 @@ }); | ||
| }; | ||
| }, j = 300, ce = 0.12, ue = j + 100, de = 200, fe = (e, n, t) => J(n, e, e, 1, t), Te = (e, n = {}) => { | ||
| }, 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 = {}) => { | ||
| let t = { | ||
@@ -291,55 +291,62 @@ count: e.count, | ||
| loop: e.loop ?? !1, | ||
| transitionDuration: e.transitionDuration ?? j, | ||
| swipeDistanceFactor: e.swipeDistanceFactor ?? ce, | ||
| rangeExtractor: e.rangeExtractor ?? fe, | ||
| transitionDuration: e.transitionDuration ?? q, | ||
| swipeDistanceFactor: e.swipeDistanceFactor ?? ue, | ||
| rangeExtractor: e.rangeExtractor ?? he, | ||
| enableWheel: e.enableWheel ?? !1, | ||
| wheelDebounceMs: e.wheelDebounceMs ?? de | ||
| wheelDebounceMs: e.wheelDebounceMs ?? fe | ||
| }, o = { ...n }, r = 0, f = !0, u = !1, h = !1; | ||
| const l = z(t.initialIndex), i = z({ value: 0, duration: 0 }), D = z(null), I = Q( | ||
| const l = V(t.initialIndex), c = V({ value: 0, duration: 0 }), D = V(null), I = $( | ||
| () => { | ||
| const a = D.value; | ||
| if (a !== null) { | ||
| const c = l.value; | ||
| return a > c ? [c, a] : [a, c]; | ||
| const b = l.value; | ||
| return a > b ? [b, a] : [a, b]; | ||
| } | ||
| return t.rangeExtractor(l.value, t.count, t.loop); | ||
| const i = t.rangeExtractor( | ||
| l.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); | ||
| }, | ||
| () => [l, D] | ||
| ), O = { index: l, axisValue: i, indexes: I }, S = () => I.value.indexOf(l.value), P = (a = 0, c) => { | ||
| i.value = { | ||
| ), 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: c | ||
| done: i | ||
| }; | ||
| }, N = async (a) => { | ||
| const { promise: c } = a(); | ||
| await c; | ||
| }, L = (a, c) => a.length === 1 ? !0 : a.length === 2 && (S() === 0 && c === -1 || S() === 1 && c === 1), b = async (a) => { | ||
| h = !0, E.unobserve(); | ||
| const c = I.value, m = X( | ||
| 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, | ||
| 0, | ||
| c.length - 1 | ||
| ), y = c[m]; | ||
| i.length - 1 | ||
| ), y = i[v]; | ||
| o.onBeforeChange?.(l.value, y, S()); | ||
| try { | ||
| await N(() => { | ||
| const A = V(); | ||
| return i.value = { | ||
| value: m * r * -1, | ||
| const b = B(); | ||
| return c.value = { | ||
| value: v * r * -1, | ||
| duration: t.transitionDuration, | ||
| done: () => A.resolve() | ||
| }, A; | ||
| done: () => b.resolve() | ||
| }, b; | ||
| }); | ||
| } finally { | ||
| Y(() => { | ||
| l.value = y, i.value = { | ||
| Z(() => { | ||
| l.value = y, c.value = { | ||
| value: S() * r * -1, | ||
| duration: 0 | ||
| }; | ||
| }), E.observe(), h = !1; | ||
| }), g.observe(), h = !1; | ||
| } | ||
| }, M = (a) => { | ||
| i.value = { | ||
| value: i.value.value + a.primaryDelta, | ||
| c.value = { | ||
| value: c.value.value + a.primaryDelta, | ||
| duration: 0 | ||
@@ -350,13 +357,13 @@ }; | ||
| }, p = async (a) => { | ||
| const m = t.direction === "horizontal" ? 0 : 1, y = r * t.swipeDistanceFactor, A = m === 0 ? _(a.distance) : w(a.distance), U = m === 0 ? _(a.velocity) : w(a.velocity), F = q(A) ? 1 : -1; | ||
| !L(I.value, F) && (x(A) > y || U > 1400 && x(A) > y / 2) && (b(F).then(() => { | ||
| u && P(); | ||
| 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 K = V(); | ||
| return P( | ||
| const Y = B(); | ||
| return L( | ||
| t.transitionDuration, | ||
| () => K.resolve() | ||
| ), K; | ||
| }), u && P(), o.onDragCanceled?.(l.value)), f = !0; | ||
| }, s = () => t.direction === "horizontal", E = oe( | ||
| () => Y.resolve() | ||
| ), Y; | ||
| }), u && L(), o.onDragCanceled?.(l.value)), f = !0; | ||
| }, s = () => t.direction === "horizontal", g = re( | ||
| { useTouchEventsOnly: !0 }, | ||
@@ -370,16 +377,16 @@ { | ||
| } | ||
| ), g = ae( | ||
| { throttleMs: ue }, | ||
| ), E = se( | ||
| { throttleMs: de }, | ||
| { | ||
| onKeyPress: (a) => { | ||
| let c = null; | ||
| s() ? (a === "left" && (c = -1), a === "right" && (c = 1)) : (a === "up" && (c = -1), a === "down" && (c = 1)), c !== null && (L(I.value, c) || b(c)); | ||
| 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)); | ||
| } | ||
| } | ||
| ), v = t.enableWheel ? ie( | ||
| ), m = t.enableWheel ? ce( | ||
| { debounceMs: t.wheelDebounceMs }, | ||
| { | ||
| onWheel: (a) => { | ||
| let c = null; | ||
| s() ? (a === "left" && (c = -1), a === "right" && (c = 1)) : (a === "up" && (c = -1), a === "down" && (c = 1)), c !== null && (L(I.value, c) || b(c)); | ||
| 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)); | ||
| } | ||
@@ -396,29 +403,29 @@ } | ||
| async next() { | ||
| h || L(I.value, 1) || await b(1); | ||
| h || P(I.value, 1) || await A(1); | ||
| }, | ||
| async prev() { | ||
| h || L(I.value, -1) || await b(-1); | ||
| h || P(I.value, -1) || await A(-1); | ||
| }, | ||
| async goTo(a, c = !1) { | ||
| async goTo(a, i = !1) { | ||
| if (h) return; | ||
| const m = X(a, 0, t.count - 1); | ||
| if (m === l.value) return; | ||
| if (E.unobserve(), !c) { | ||
| o.onBeforeChange?.(l.value, m, S()), l.value = m, P(0), o.onAfterChange?.(l.value, S()), E.observe(); | ||
| 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(); | ||
| return; | ||
| } | ||
| h = !0; | ||
| const y = m > l.value; | ||
| o.onBeforeChange?.(l.value, m, S()), D.value = m; | ||
| const A = y ? 0 : 1; | ||
| i.value = { | ||
| value: A * r * -1, | ||
| 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, | ||
| duration: 0 | ||
| }; | ||
| const U = y ? 1 : 0; | ||
| const R = y ? 1 : 0; | ||
| try { | ||
| await N(() => { | ||
| const F = V(); | ||
| return i.value = { | ||
| value: U * r * -1, | ||
| const F = B(); | ||
| return c.value = { | ||
| value: R * r * -1, | ||
| duration: t.transitionDuration, | ||
@@ -429,21 +436,21 @@ done: () => F.resolve() | ||
| } finally { | ||
| Y(() => { | ||
| D.value = null, l.value = m, P(0); | ||
| }), o.onAfterChange?.(l.value, S()), E.observe(), h = !1; | ||
| Z(() => { | ||
| D.value = null, l.value = v, L(0); | ||
| }), o.onAfterChange?.(l.value, S()), g.observe(), h = !1; | ||
| } | ||
| }, | ||
| adjust(a = 0) { | ||
| h || P(a); | ||
| h || L(a); | ||
| }, | ||
| setPrimarySize(a) { | ||
| a !== r && (u = !0, r = a, h || P()); | ||
| a !== r && (u = !0, r = a, h || L()); | ||
| }, | ||
| updateConfig(a) { | ||
| t = { ...t, ...a }; | ||
| const c = t.direction === "horizontal"; | ||
| E.updateEvents({ | ||
| onHorizontalDragStart: c ? d : void 0, | ||
| onHorizontalDragUpdate: c ? M : void 0, | ||
| onVerticalDragStart: c ? void 0 : d, | ||
| onVerticalDragUpdate: c ? void 0 : M | ||
| const i = 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 | ||
| }); | ||
@@ -457,59 +464,59 @@ }, | ||
| observe() { | ||
| E.observe(), g.attach(), v?.attach(); | ||
| g.observe(), E.attach(), m?.attach(); | ||
| }, | ||
| unobserve() { | ||
| E.unobserve(), g.detach(), v?.detach(); | ||
| g.unobserve(), E.detach(), m?.detach(); | ||
| }, | ||
| attach(a) { | ||
| E.attach(a); | ||
| g.attach(a); | ||
| }, | ||
| detach() { | ||
| E.detach(), g.detach(), v?.detach(); | ||
| g.detach(), E.detach(), m?.detach(); | ||
| }, | ||
| dispose() { | ||
| E.detach(), g.detach(), v?.detach(), T && T(); | ||
| g.detach(), E.detach(), m?.detach(), T && T(); | ||
| } | ||
| }; | ||
| }, he = (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, P = (d, p, s) => 3 * D(p, s) * d * d + 2 * I(p, s) * d + O(p), N = (d, p, s) => { | ||
| let E, g, v = 0; | ||
| }, 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; | ||
| do | ||
| g = p + (s - p) / 2, E = S(g, e, t) - d, E > 0 ? s = g : p = g; | ||
| while (Math.abs(E) > 1e-7 && ++v < 10); | ||
| return g; | ||
| }, L = (d, p) => { | ||
| 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 E = P(p, e, t); | ||
| if (E === 0) return p; | ||
| const g = S(p, e, t) - d; | ||
| p -= g / E; | ||
| const g = L(p, e, t); | ||
| if (g === 0) return p; | ||
| const E = S(p, e, t) - d; | ||
| p -= E / g; | ||
| } | ||
| return p; | ||
| }, b = new Float32Array(11); | ||
| }, A = new Float32Array(11); | ||
| for (let d = 0; d < 11; ++d) | ||
| b[d] = S(d * 0.1, e, t); | ||
| A[d] = S(d * 0.1, e, t); | ||
| const M = (d) => { | ||
| let p = 0, s = 1; | ||
| const E = 10; | ||
| for (; s !== E && b[s] <= d; ++s) | ||
| const g = 10; | ||
| for (; s !== g && A[s] <= d; ++s) | ||
| p += 0.1; | ||
| --s; | ||
| const g = (d - b[s]) / (b[s + 1] - b[s]), v = p + g * 0.1, T = P(v, e, t); | ||
| return T >= 1e-3 ? L(d, v) : T === 0 ? v : N(d, p, p + 0.1); | ||
| 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); | ||
| }; | ||
| return (d) => d === 0 || d === 1 ? d : S(M(d), n, o); | ||
| }; | ||
| let W = null; | ||
| const pe = () => (W === null && (W = he(0.4, 0, 0.2, 1)), W), Ie = (e) => { | ||
| 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; | ||
| if (o <= 0) | ||
| return r(t), f?.(), te; | ||
| return r(t), f?.(), ne; | ||
| let u = null, h, l = !1; | ||
| const i = (D) => { | ||
| const c = (D) => { | ||
| if (l) return; | ||
| h ??= D; | ||
| const I = D - h, O = pe()(X(I / o, 0, 1)), S = G(O, n, t); | ||
| r(S), I < o ? u = requestAnimationFrame(i) : f?.(); | ||
| 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 u = requestAnimationFrame(i), () => { | ||
| return u = requestAnimationFrame(c), () => { | ||
| l = !0, u !== null && cancelAnimationFrame(u); | ||
@@ -519,28 +526,28 @@ }; | ||
| export { | ||
| x as abs, | ||
| Ie as animate, | ||
| Y as batch, | ||
| De as captureFrame, | ||
| X as clamp, | ||
| Q as createComputed, | ||
| V as createDeferred, | ||
| $ as createDisposableList, | ||
| oe as createGestureController, | ||
| ae as createKeyboardController, | ||
| Se as createSharedVideo, | ||
| z as createSignal, | ||
| Te as createSliderController, | ||
| ie as createWheelController, | ||
| fe as defaultRangeExtractor, | ||
| J as extractRange, | ||
| U as abs, | ||
| ye as animate, | ||
| Z as batch, | ||
| Se as captureFrame, | ||
| C as clamp, | ||
| $ as createComputed, | ||
| B 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, | ||
| Q as extractRange, | ||
| _ as first, | ||
| ve as generate, | ||
| ge as isEmpty, | ||
| q as isNegative, | ||
| me as generate, | ||
| ve as isEmpty, | ||
| G as isNegative, | ||
| w as last, | ||
| G as lerp, | ||
| te as noop, | ||
| R as observeDomEvent, | ||
| me as reaction, | ||
| ee as timeout | ||
| J as lerp, | ||
| ne as noop, | ||
| x as observeDomEvent, | ||
| De as reaction, | ||
| te as timeout | ||
| }; |
@@ -13,3 +13,3 @@ import { RangeExtractor, SliderConfig, SliderEvents, SliderController } from './types'; | ||
| */ | ||
| declare const defaultRangeExtractor: RangeExtractor; | ||
| export declare const defaultRangeExtractor: RangeExtractor; | ||
| /** | ||
@@ -34,2 +34,1 @@ * Creates a centralized slider controller that manages slide navigation, | ||
| export declare const createSliderController: (initialConfig: SliderConfig, initialEvents?: SliderEvents) => SliderController; | ||
| export { defaultRangeExtractor }; |
@@ -62,2 +62,5 @@ import { Signal, ComputedSignal } from '../utils/signal'; | ||
| * Defaults to the built-in extractor that returns current ± 1 overscan. | ||
| * | ||
| * NOTE: The result is clamped to a maximum of 3 indices. If more are | ||
| * returned, the controller keeps 3 centered around the current slide. | ||
| */ | ||
@@ -64,0 +67,0 @@ rangeExtractor?: RangeExtractor; |
+1
-1
| { | ||
| "name": "@reelkit/core", | ||
| "version": "0.2.0", | ||
| "version": "0.2.1", | ||
| "type": "module", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
55744
0.56%1388
0.65%