motion-plus-vue 1.4.0 → 1.5.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +2 -2
- package/dist/components/Carousel/Carousel.d.ts +28 -0
- package/dist/components/Carousel/CarouselView.d.ts +32 -0
- package/dist/components/Carousel/const.d.ts +3 -0
- package/dist/components/Carousel/context.d.ts +15 -0
- package/dist/components/Carousel/index.d.ts +3 -0
- package/dist/components/Carousel/utils/calc-current-page.d.ts +1 -0
- package/dist/components/Carousel/utils/calc-page-insets.d.ts +5 -0
- package/dist/components/Carousel/utils/find-current-index.d.ts +2 -0
- package/dist/components/Carousel/utils/find-next-page.d.ts +3 -0
- package/dist/components/Carousel/utils/find-prev-page.d.ts +3 -0
- package/dist/components/Cursor/Cursor.d.ts +2 -2
- package/dist/components/Ticker/DefaultTickerItem.d.ts +14 -0
- package/dist/components/Ticker/Ticker.d.ts +60 -5
- package/dist/components/Ticker/TickerItem.d.ts +59 -13
- package/dist/components/Ticker/const.d.ts +3 -0
- package/dist/components/Ticker/context.d.ts +4259 -2
- package/dist/components/Ticker/index.d.ts +1 -1
- package/dist/components/Ticker/types.d.ts +16 -1
- package/dist/components/Ticker/utils/layout-strategy.d.ts +2 -0
- package/dist/components/Typewriter/Typewriter.d.ts +1 -1
- package/dist/es/components/Carousel/Carousel.vue.mjs +79 -0
- package/dist/es/components/Carousel/Carousel.vue2.mjs +4 -0
- package/dist/es/components/Carousel/CarouselView.vue.mjs +115 -0
- package/dist/es/components/Carousel/CarouselView.vue2.mjs +4 -0
- package/dist/es/components/Carousel/const.mjs +13 -0
- package/dist/es/components/Carousel/context.mjs +6 -0
- package/dist/es/components/Carousel/utils/calc-current-page.mjs +13 -0
- package/dist/es/components/Carousel/utils/calc-page-insets.mjs +42 -0
- package/dist/es/components/Carousel/utils/find-current-index.mjs +13 -0
- package/dist/es/components/Carousel/utils/find-next-page.mjs +26 -0
- package/dist/es/components/Carousel/utils/find-prev-page.mjs +31 -0
- package/dist/es/components/Ticker/Ticker.vue.mjs +270 -111
- package/dist/es/components/Ticker/TickerItem.vue.mjs +68 -36
- package/dist/es/components/Ticker/const.mjs +12 -3
- package/dist/es/components/Ticker/context.mjs +5 -3
- package/dist/es/components/Ticker/utils/layout-strategy.mjs +57 -0
- package/dist/es/index.mjs +21 -16
- package/dist/es/utils/flatten-slots.mjs +22 -16
- package/dist/index.d.ts +1 -0
- package/package.json +3 -3
- package/dist/es/components/Ticker/use-item-offset.mjs +0 -12
- package/dist/es/components/Ticker/utils/get-cumulative-offset.mjs +0 -9
|
@@ -4,6 +4,6 @@ import { MotionProps } from 'motion-v';
|
|
|
4
4
|
export { default as TickerItem } from './TickerItem';
|
|
5
5
|
export type { TickerItemProps } from './TickerItem';
|
|
6
6
|
export type { ItemPosition, TickerState, ItemSize } from './types';
|
|
7
|
-
export {
|
|
7
|
+
export { useTickerItem, useTicker } from './context';
|
|
8
8
|
export declare const Ticker: DefineComponent<MotionProps<"div"> & TickerProps>;
|
|
9
9
|
export type { TickerProps };
|
|
@@ -2,10 +2,25 @@ export interface ItemPosition {
|
|
|
2
2
|
start: number;
|
|
3
3
|
end: number;
|
|
4
4
|
}
|
|
5
|
-
export type ItemSize = 'auto' | 'fill';
|
|
5
|
+
export type ItemSize = 'auto' | 'fill' | 'manual';
|
|
6
|
+
export type Direction = 'ltr' | 'rtl';
|
|
7
|
+
export interface LayoutStrategy {
|
|
8
|
+
sign: 1 | -1;
|
|
9
|
+
direction: 'left' | 'top' | 'right' | 'bottom';
|
|
10
|
+
lengthProp: 'offsetWidth' | 'offsetHeight';
|
|
11
|
+
viewportLengthProp: 'innerWidth' | 'innerHeight';
|
|
12
|
+
paddingStartProp: 'paddingLeft' | 'paddingTop' | 'paddingRight';
|
|
13
|
+
measureItem: (item: HTMLElement, container: HTMLElement) => ItemPosition;
|
|
14
|
+
getCumulativeInset: (element: HTMLElement) => number;
|
|
15
|
+
}
|
|
6
16
|
export interface TickerState {
|
|
17
|
+
direction: Direction;
|
|
7
18
|
visibleLength: number;
|
|
8
19
|
inset: number;
|
|
9
20
|
totalItemLength: number;
|
|
21
|
+
containerLength: number;
|
|
10
22
|
itemPositions: ItemPosition[];
|
|
23
|
+
isMeasured: boolean;
|
|
24
|
+
maxInset: number | null;
|
|
11
25
|
}
|
|
26
|
+
export type Axis = 'x' | 'y';
|
|
@@ -87,7 +87,7 @@ declare const _default: <T extends AsTag>(__VLS_props: NonNullable<Awaited<typeo
|
|
|
87
87
|
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, never>, never> & TypewriterProps<T> & Partial<{}>> & import('vue').PublicProps;
|
|
88
88
|
expose(exposed: import('vue').ShallowUnwrapRef<{}>): void;
|
|
89
89
|
attrs: any;
|
|
90
|
-
slots:
|
|
90
|
+
slots: __VLS_PrettifyGlobal<__VLS_OmitStringIndex<any>>;
|
|
91
91
|
emit: {};
|
|
92
92
|
}>) => import('vue').VNode & {
|
|
93
93
|
__ctx?: Awaited<typeof __VLS_setup>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { defineComponent as d, createBlock as u, openBlock as m, unref as o, mergeProps as y, withCtx as t, renderSlot as i, createVNode as c } from "vue";
|
|
2
|
+
import { useMotionValue as r, useTransform as B, useDomRef as k } from "motion-v";
|
|
3
|
+
import { Ticker as O } from "../Ticker/index.mjs";
|
|
4
|
+
import { defaultTransition as C } from "./const.mjs";
|
|
5
|
+
import T from "./CarouselView.vue.mjs";
|
|
6
|
+
const M = /* @__PURE__ */ d({
|
|
7
|
+
name: "Carousel",
|
|
8
|
+
inheritAttrs: !1,
|
|
9
|
+
__name: "Carousel",
|
|
10
|
+
props: {
|
|
11
|
+
snap: { type: [String, Boolean], default: "page" },
|
|
12
|
+
transition: { default: () => ({
|
|
13
|
+
...C
|
|
14
|
+
}) },
|
|
15
|
+
axis: { default: "x" },
|
|
16
|
+
gap: {},
|
|
17
|
+
align: {},
|
|
18
|
+
itemSize: {},
|
|
19
|
+
overflow: { type: Boolean },
|
|
20
|
+
loop: { type: Boolean, default: !0 },
|
|
21
|
+
safeMargin: {},
|
|
22
|
+
fade: {},
|
|
23
|
+
fadeTransition: {},
|
|
24
|
+
pageTransition: {},
|
|
25
|
+
_dragX: { type: [Object, Boolean] },
|
|
26
|
+
_dragY: { type: [Object, Boolean] },
|
|
27
|
+
as: {},
|
|
28
|
+
style: {},
|
|
29
|
+
onDragEnd: {},
|
|
30
|
+
drag: { type: [Boolean, String] },
|
|
31
|
+
dragConstraints: { type: [Boolean, Object] },
|
|
32
|
+
dragMomentum: { type: Boolean }
|
|
33
|
+
},
|
|
34
|
+
setup(p) {
|
|
35
|
+
const l = p, a = r(0), s = r(0), n = r(0), g = B(() => n.get() + s.get()), f = k();
|
|
36
|
+
return (e, S) => (m(), u(o(O), y({
|
|
37
|
+
...l,
|
|
38
|
+
...e.$attrs
|
|
39
|
+
}, {
|
|
40
|
+
ref_key: "tickerRef",
|
|
41
|
+
ref: f,
|
|
42
|
+
role: "region",
|
|
43
|
+
"aria-roledescription": "carousel",
|
|
44
|
+
offset: o(g),
|
|
45
|
+
loop: e.loop,
|
|
46
|
+
axis: e.axis,
|
|
47
|
+
drag: e.axis,
|
|
48
|
+
"_drag-x": e.axis === "x" ? o(a) : !1,
|
|
49
|
+
"_drag-y": e.axis === "y" ? o(a) : !1,
|
|
50
|
+
snap: e.snap,
|
|
51
|
+
"page-transition": e.transition
|
|
52
|
+
}), {
|
|
53
|
+
after: t(() => [
|
|
54
|
+
c(T, {
|
|
55
|
+
"ticker-ref": o(f),
|
|
56
|
+
loop: e.loop,
|
|
57
|
+
offset: o(s),
|
|
58
|
+
"tug-offset": o(n),
|
|
59
|
+
"target-offset": o(a),
|
|
60
|
+
transition: e.transition,
|
|
61
|
+
snap: e.snap,
|
|
62
|
+
axis: e.axis
|
|
63
|
+
}, {
|
|
64
|
+
default: t(() => [
|
|
65
|
+
i(e.$slots, "after")
|
|
66
|
+
]),
|
|
67
|
+
_: 3
|
|
68
|
+
}, 8, ["ticker-ref", "loop", "offset", "tug-offset", "target-offset", "transition", "snap", "axis"])
|
|
69
|
+
]),
|
|
70
|
+
default: t(() => [
|
|
71
|
+
i(e.$slots, "default")
|
|
72
|
+
]),
|
|
73
|
+
_: 3
|
|
74
|
+
}, 16, ["offset", "loop", "axis", "drag", "_drag-x", "_drag-y", "snap", "page-transition"]));
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
export {
|
|
78
|
+
M as default
|
|
79
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { defineComponent as M, computed as u, ref as T, watch as _, onMounted as B, toRefs as b, renderSlot as j } from "vue";
|
|
2
|
+
import { useMotionValueEvent as E, clamp as k, JSAnimation as J, animate as V } from "motion-v";
|
|
3
|
+
import { wheel as W } from "motion-plus-dom";
|
|
4
|
+
import { calcPageInsets as $ } from "./utils/calc-page-insets.mjs";
|
|
5
|
+
import { getLayoutStrategy as q } from "../Ticker/utils/layout-strategy.mjs";
|
|
6
|
+
import { calcCurrentPage as z } from "./utils/calc-current-page.mjs";
|
|
7
|
+
import { findNextPageInset as D } from "./utils/find-next-page.mjs";
|
|
8
|
+
import { limitSpring as F } from "./const.mjs";
|
|
9
|
+
import { findPrevPageInset as G } from "./utils/find-prev-page.mjs";
|
|
10
|
+
import { provideCarousel as H } from "./context.mjs";
|
|
11
|
+
import { useTicker as K } from "../Ticker/context.mjs";
|
|
12
|
+
const it = /* @__PURE__ */ M({
|
|
13
|
+
__name: "CarouselView",
|
|
14
|
+
props: {
|
|
15
|
+
offset: {},
|
|
16
|
+
targetOffset: {},
|
|
17
|
+
tugOffset: {},
|
|
18
|
+
loop: { type: Boolean },
|
|
19
|
+
transition: {},
|
|
20
|
+
axis: { default: "x" },
|
|
21
|
+
snap: { type: [String, Boolean], default: "page" },
|
|
22
|
+
tickerRef: {}
|
|
23
|
+
},
|
|
24
|
+
setup(L) {
|
|
25
|
+
const t = L;
|
|
26
|
+
let c = !0;
|
|
27
|
+
const { state: o, gap: v, clampOffset: m } = K(), g = u(() => o.totalItemLength + v.value), l = u(
|
|
28
|
+
() => $(o.itemPositions, o.containerLength, o.maxInset)
|
|
29
|
+
), C = u(() => l.value.insets.length), n = u(() => q(t.axis, o.direction).sign);
|
|
30
|
+
function O(e) {
|
|
31
|
+
const a = z(
|
|
32
|
+
e * n.value,
|
|
33
|
+
l.value.insets,
|
|
34
|
+
g.value,
|
|
35
|
+
o.maxInset
|
|
36
|
+
), i = t.loop ? !0 : e * -n.value < o.maxInset, s = t.loop ? !0 : e * -n.value > 0;
|
|
37
|
+
return { current: a, isNextActive: i, isPrevActive: s };
|
|
38
|
+
}
|
|
39
|
+
const f = T(O(t.targetOffset.get()));
|
|
40
|
+
function d() {
|
|
41
|
+
const e = O(t.targetOffset.get());
|
|
42
|
+
(e.current !== f.value.current || e.isNextActive !== f.value.isNextActive || e.isPrevActive !== f.value.isPrevActive) && (f.value = e);
|
|
43
|
+
}
|
|
44
|
+
_([() => o.containerLength, () => o.totalItemLength], d, {
|
|
45
|
+
immediate: !0,
|
|
46
|
+
flush: "post"
|
|
47
|
+
}), E(t.targetOffset, "change", (e) => {
|
|
48
|
+
t.offset.set(e), d();
|
|
49
|
+
});
|
|
50
|
+
let r = null;
|
|
51
|
+
function P() {
|
|
52
|
+
r && (r.stop(), r = null);
|
|
53
|
+
}
|
|
54
|
+
B(() => {
|
|
55
|
+
t.offset.attach((e, a) => {
|
|
56
|
+
P(), c ? a(e) : r = new J({
|
|
57
|
+
keyframes: [t.offset.get(), e],
|
|
58
|
+
velocity: k(-2e3, 2e3, t.offset.getVelocity()),
|
|
59
|
+
...t.transition,
|
|
60
|
+
onUpdate: a,
|
|
61
|
+
onComplete: () => {
|
|
62
|
+
r = null;
|
|
63
|
+
}
|
|
64
|
+
}), c = !0;
|
|
65
|
+
}, P);
|
|
66
|
+
});
|
|
67
|
+
function h(e) {
|
|
68
|
+
const a = m(e);
|
|
69
|
+
t.targetOffset.stop(), c = !1, t.targetOffset.set(a * n.value);
|
|
70
|
+
}
|
|
71
|
+
function x(e, a) {
|
|
72
|
+
const i = -e(
|
|
73
|
+
-t.targetOffset.get() * n.value,
|
|
74
|
+
l.value.visibleLength,
|
|
75
|
+
o.itemPositions,
|
|
76
|
+
v.value
|
|
77
|
+
), s = m(i);
|
|
78
|
+
s * n.value === t.targetOffset.get() ? V(t.tugOffset, 0, {
|
|
79
|
+
velocity: a * n.value * 400,
|
|
80
|
+
...F
|
|
81
|
+
}) : h(s);
|
|
82
|
+
}
|
|
83
|
+
const I = () => x(D, -1), A = () => x(G, 1);
|
|
84
|
+
function R(e) {
|
|
85
|
+
const i = (t.loop ? Math.floor(-t.targetOffset.get() * n.value / g.value) : 0) * -g.value;
|
|
86
|
+
h(-l.value.insets[e] + i);
|
|
87
|
+
}
|
|
88
|
+
const { axis: S, snap: w, offset: y } = b(t);
|
|
89
|
+
return _([S, w, y, n, () => t.tickerRef], (e, a, i) => {
|
|
90
|
+
t.tickerRef && i(W(t.tickerRef, {
|
|
91
|
+
axis: S.value,
|
|
92
|
+
onSwipe: w.value ? (s) => {
|
|
93
|
+
s * n.value === 1 ? I() : A();
|
|
94
|
+
} : void 0,
|
|
95
|
+
onWheel: (s) => {
|
|
96
|
+
const p = y.value.get() + s, N = n.value > 0 ? m(p) : k(0, o.maxInset, p);
|
|
97
|
+
t.targetOffset.jump(o.maxInset ? N : p);
|
|
98
|
+
}
|
|
99
|
+
}));
|
|
100
|
+
}, {
|
|
101
|
+
immediate: !0,
|
|
102
|
+
flush: "post"
|
|
103
|
+
}), H({
|
|
104
|
+
paginationState: f,
|
|
105
|
+
totalPages: C,
|
|
106
|
+
nextPage: I,
|
|
107
|
+
prevPage: A,
|
|
108
|
+
gotoPage: R,
|
|
109
|
+
targetOffset: t.targetOffset
|
|
110
|
+
}), (e, a) => j(e.$slots, "default");
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
export {
|
|
114
|
+
it as default
|
|
115
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { wrap as s } from "motion-v";
|
|
2
|
+
function C(f, n, r, x) {
|
|
3
|
+
const e = -f, o = x === null ? Math.floor(e / r) : 0, a = o * r;
|
|
4
|
+
for (let t = n.length - 1; t >= 0; t--) {
|
|
5
|
+
const c = n[t] + a, h = s(0, n.length, t - 1), v = (t === 0 ? o - 1 : o) * r, i = n[h] + v, m = (c - i) / 2, u = s(0, n.length, t + 1), T = (t === n.length - 1 ? o + 1 : o) * r, l = n[u] + T, I = (l - c) / 2;
|
|
6
|
+
if (e < l - I && e >= i + m)
|
|
7
|
+
return t;
|
|
8
|
+
}
|
|
9
|
+
return 0;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
C as calcCurrentPage
|
|
13
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
function u(s, a, n, r = !0) {
|
|
2
|
+
const h = { insets: [], visibleLength: a };
|
|
3
|
+
if (s.length === 0)
|
|
4
|
+
return h;
|
|
5
|
+
const e = [s[0].start];
|
|
6
|
+
for (let g = 1; g < s.length; g++) {
|
|
7
|
+
const { start: t, end: f } = s[g];
|
|
8
|
+
if (e[e.length - 1] + a < f)
|
|
9
|
+
if (n !== null)
|
|
10
|
+
if (t <= n)
|
|
11
|
+
e.push(t);
|
|
12
|
+
else {
|
|
13
|
+
e.push(n);
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
else
|
|
17
|
+
e.push(t);
|
|
18
|
+
}
|
|
19
|
+
if (r && n !== null && e.length > 1) {
|
|
20
|
+
const g = e[e.length - 1], t = [];
|
|
21
|
+
for (let l = 0; l < e.length - 1; l++)
|
|
22
|
+
t.push(e[l + 1] - e[l]);
|
|
23
|
+
const f = t.reduce((l, i) => l + i, 0) / t.length;
|
|
24
|
+
if (n - g < f * 0.5) {
|
|
25
|
+
const l = u(
|
|
26
|
+
s,
|
|
27
|
+
a * 0.75,
|
|
28
|
+
n,
|
|
29
|
+
!1
|
|
30
|
+
);
|
|
31
|
+
if (l.insets.length === e.length)
|
|
32
|
+
return l;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
insets: e,
|
|
37
|
+
visibleLength: a
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
u as calcPageInsets
|
|
42
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function a(e, t, r) {
|
|
2
|
+
const o = Math.floor(e / r), l = o * r;
|
|
3
|
+
let f = 0;
|
|
4
|
+
for (let n = 0; n < t.length; n++) {
|
|
5
|
+
const { end: d } = t[n];
|
|
6
|
+
if (f = n, d + l > e)
|
|
7
|
+
break;
|
|
8
|
+
}
|
|
9
|
+
return f + o * t.length;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
a as findCurrentIndexFromInset
|
|
13
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { wrap as u } from "motion-v";
|
|
2
|
+
import { findCurrentIndexFromInset as g } from "./find-current-index.mjs";
|
|
3
|
+
function m(e, t, n, r) {
|
|
4
|
+
var o;
|
|
5
|
+
if (t.length === 0)
|
|
6
|
+
return 0;
|
|
7
|
+
const d = t[t.length - 1].end + n, h = r ?? e + (((o = t[0]) == null ? void 0 : o.end) ?? 0);
|
|
8
|
+
let a = g(
|
|
9
|
+
e,
|
|
10
|
+
t,
|
|
11
|
+
d
|
|
12
|
+
) + 1, l = 0, f = !1;
|
|
13
|
+
for (; !f; ) {
|
|
14
|
+
const { start: s, end: x } = t[u(0, t.length, a)], c = Math.floor(a / t.length) * d;
|
|
15
|
+
l = s + c, x + c > h ? f = !0 : a++;
|
|
16
|
+
}
|
|
17
|
+
return l;
|
|
18
|
+
}
|
|
19
|
+
function S(e, t, n, r) {
|
|
20
|
+
const I = e + t;
|
|
21
|
+
return m(e, n, r, I);
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
m as findNextItemInset,
|
|
25
|
+
S as findNextPageInset
|
|
26
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { wrap as p } from "motion-v";
|
|
2
|
+
import { findCurrentIndexFromInset as x } from "./find-current-index.mjs";
|
|
3
|
+
function v(t, e, f, d, r) {
|
|
4
|
+
if (e.length === 0)
|
|
5
|
+
return 0;
|
|
6
|
+
const s = e[e.length - 1].end + f, I = d ?? t - (r ?? 0);
|
|
7
|
+
let a = x(
|
|
8
|
+
t,
|
|
9
|
+
e,
|
|
10
|
+
s
|
|
11
|
+
), l = t, o = !1;
|
|
12
|
+
for (; !o; ) {
|
|
13
|
+
const { start: m, end: c } = e[p(0, e.length, a)], h = c - m, u = Math.floor(a / e.length) * s, n = m + u;
|
|
14
|
+
I <= n + f || n >= t ? (l = n, a--) : I <= n ? (l = n, o = !0) : ((r && h > r || l === t && I >= n) && (l = n), o = !0);
|
|
15
|
+
}
|
|
16
|
+
return l;
|
|
17
|
+
}
|
|
18
|
+
function C(t, e, f, d) {
|
|
19
|
+
const r = t - e;
|
|
20
|
+
return v(
|
|
21
|
+
t,
|
|
22
|
+
f,
|
|
23
|
+
d,
|
|
24
|
+
r,
|
|
25
|
+
e
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
v as findPrevItemInset,
|
|
30
|
+
C as findPrevPageInset
|
|
31
|
+
};
|