motion-plus-vue 1.3.1 → 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.
Files changed (49) hide show
  1. package/dist/cjs/index.js +2 -2
  2. package/dist/components/Carousel/Carousel.d.ts +28 -0
  3. package/dist/components/Carousel/CarouselView.d.ts +32 -0
  4. package/dist/components/Carousel/const.d.ts +3 -0
  5. package/dist/components/Carousel/context.d.ts +15 -0
  6. package/dist/components/Carousel/index.d.ts +3 -0
  7. package/dist/components/Carousel/utils/calc-current-page.d.ts +1 -0
  8. package/dist/components/Carousel/utils/calc-page-insets.d.ts +5 -0
  9. package/dist/components/Carousel/utils/find-current-index.d.ts +2 -0
  10. package/dist/components/Carousel/utils/find-next-page.d.ts +3 -0
  11. package/dist/components/Carousel/utils/find-prev-page.d.ts +3 -0
  12. package/dist/components/Cursor/Cursor.d.ts +2 -2
  13. package/dist/components/Ticker/DefaultTickerItem.d.ts +14 -0
  14. package/dist/components/Ticker/Ticker.d.ts +60 -5
  15. package/dist/components/Ticker/TickerItem.d.ts +59 -13
  16. package/dist/components/Ticker/const.d.ts +3 -0
  17. package/dist/components/Ticker/context.d.ts +4259 -2
  18. package/dist/components/Ticker/index.d.ts +1 -1
  19. package/dist/components/Ticker/types.d.ts +16 -1
  20. package/dist/components/Ticker/utils/layout-strategy.d.ts +2 -0
  21. package/dist/components/Typewriter/Typewriter.d.ts +98 -0
  22. package/dist/components/Typewriter/index.d.ts +1 -0
  23. package/dist/components/Typewriter/types.d.ts +6 -0
  24. package/dist/es/components/Carousel/Carousel.vue.mjs +79 -0
  25. package/dist/es/components/Carousel/Carousel.vue2.mjs +4 -0
  26. package/dist/es/components/Carousel/CarouselView.vue.mjs +115 -0
  27. package/dist/es/components/Carousel/CarouselView.vue2.mjs +4 -0
  28. package/dist/es/components/Carousel/const.mjs +13 -0
  29. package/dist/es/components/Carousel/context.mjs +6 -0
  30. package/dist/es/components/Carousel/utils/calc-current-page.mjs +13 -0
  31. package/dist/es/components/Carousel/utils/calc-page-insets.mjs +42 -0
  32. package/dist/es/components/Carousel/utils/find-current-index.mjs +13 -0
  33. package/dist/es/components/Carousel/utils/find-next-page.mjs +26 -0
  34. package/dist/es/components/Carousel/utils/find-prev-page.mjs +31 -0
  35. package/dist/es/components/Ticker/Ticker.vue.mjs +270 -111
  36. package/dist/es/components/Ticker/TickerItem.vue.mjs +68 -36
  37. package/dist/es/components/Ticker/const.mjs +12 -3
  38. package/dist/es/components/Ticker/context.mjs +5 -3
  39. package/dist/es/components/Ticker/utils/layout-strategy.mjs +57 -0
  40. package/dist/es/components/Typewriter/Typewriter.vue.mjs +129 -0
  41. package/dist/es/components/Typewriter/Typewriter.vue2.mjs +4 -0
  42. package/dist/es/components/Typewriter/types.mjs +8 -0
  43. package/dist/es/index.mjs +23 -16
  44. package/dist/es/utils/flatten-slots.mjs +22 -16
  45. package/dist/index.d.ts +2 -0
  46. package/dist/utils/types.d.ts +0 -0
  47. package/package.json +5 -2
  48. package/dist/es/components/Ticker/use-item-offset.mjs +0 -12
  49. 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 { useItemOffset } from './use-item-offset';
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';
@@ -0,0 +1,2 @@
1
+ import { Axis, Direction, LayoutStrategy } from '../types';
2
+ export declare function getLayoutStrategy(axis: Axis, direction: Direction): LayoutStrategy;
@@ -0,0 +1,98 @@
1
+ import { CSSProperties, IntrinsicElementAttributes } from 'vue';
2
+ import { AsTag, ComponentProps, ElementType } from 'motion-v';
3
+ type TypewriterOwnProps<T extends AsTag = 'span'> = {
4
+ /**
5
+ * The HTML element or component to render as (defaults to "span")
6
+ *
7
+ * @default "span"
8
+ */
9
+ as?: T;
10
+ /**
11
+ * Typing speed preset (default: "normal")
12
+ * - slow: 130ms per character
13
+ * - normal: 75ms per character
14
+ * - fast: 30ms per character
15
+ *
16
+ * @default "normal"
17
+ */
18
+ speed?: number | 'slow' | 'normal' | 'fast';
19
+ /**
20
+ * Amount of variance in timing between characters as a factor of the speed.
21
+ * Defaults to "natural" for realistic human typing patterns.
22
+ *
23
+ * @default "natural"
24
+ */
25
+ variance?: number | 'natural';
26
+ /**
27
+ * Whether the animation should be playing (default: true)
28
+ * This is useful to manually start the animation
29
+ * when the component enters the viewport.
30
+ *
31
+ * @default true
32
+ */
33
+ play?: boolean;
34
+ /**
35
+ * Custom className for the cursor element
36
+ */
37
+ cursorClassName?: string;
38
+ /**
39
+ * Custom styles for the cursor element
40
+ */
41
+ cursorStyle?: CSSProperties;
42
+ /**
43
+ * Custom className for the text element
44
+ */
45
+ textClassName?: string;
46
+ /**
47
+ * Custom styles for the text element
48
+ */
49
+ textStyle?: CSSProperties;
50
+ /**
51
+ * The duration of the cursor blink animation in seconds (default: 0.5)
52
+ *
53
+ * @default 0.5
54
+ */
55
+ cursorBlinkDuration?: number;
56
+ /**
57
+ * Callback when typing animation completes
58
+ *
59
+ * @default undefined
60
+ */
61
+ onComplete?: () => void;
62
+ /**
63
+ * Replacement method for changed content:
64
+ * - "all": Replace all text instantly
65
+ * - "type": Type from current text to new text
66
+ *
67
+ * @default "type"
68
+ */
69
+ replace?: 'all' | 'type';
70
+ /**
71
+ * When using replace: "type", how to backspace to the common prefix.
72
+ * - "character": Backspace one character at a time
73
+ * - "word": Backspace one word at a time (like option-backspace)
74
+ * - "all": Jump immediately to the common prefix
75
+ *
76
+ * @default "character"
77
+ */
78
+ backspace?: 'character' | 'word' | 'all';
79
+ /**
80
+ * The speed factor for backspacing relative to typing speed
81
+ * @default 0.2 - backspace 5x faster than typing
82
+ */
83
+ backspaceFactor?: number;
84
+ };
85
+ export type TypewriterProps<T extends AsTag = 'span'> = TypewriterOwnProps<T> & /** @vue-ignore */ (T extends ElementType ? IntrinsicElementAttributes[T] : ComponentProps<T>);
86
+ declare const _default: <T extends AsTag>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
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
+ expose(exposed: import('vue').ShallowUnwrapRef<{}>): void;
89
+ attrs: any;
90
+ slots: __VLS_PrettifyGlobal<__VLS_OmitStringIndex<any>>;
91
+ emit: {};
92
+ }>) => import('vue').VNode & {
93
+ __ctx?: Awaited<typeof __VLS_setup>;
94
+ };
95
+ export default _default;
96
+ type __VLS_PrettifyLocal<T> = {
97
+ [K in keyof T]: T[K];
98
+ } & {};
@@ -0,0 +1 @@
1
+ export { default as Typewriter, type TypewriterProps } from './Typewriter';
@@ -0,0 +1,6 @@
1
+ export declare const TYPING_SPEEDS: {
2
+ readonly slow: 130;
3
+ readonly normal: 75;
4
+ readonly fast: 30;
5
+ };
6
+ export type TypingSpeed = keyof typeof TYPING_SPEEDS;
@@ -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,4 @@
1
+ import f from "./Carousel.vue.mjs";
2
+ export {
3
+ f as default
4
+ };
@@ -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,4 @@
1
+ import f from "./CarouselView.vue.mjs";
2
+ export {
3
+ f as default
4
+ };
@@ -0,0 +1,13 @@
1
+ const i = {
2
+ type: "spring",
3
+ stiffness: 200,
4
+ damping: 40
5
+ }, n = {
6
+ type: "spring",
7
+ stiffness: 80,
8
+ damping: 10
9
+ };
10
+ export {
11
+ i as defaultTransition,
12
+ n as limitSpring
13
+ };
@@ -0,0 +1,6 @@
1
+ import { createContext as e } from "motion-v";
2
+ const [r, t] = e("CarouselContext");
3
+ export {
4
+ t as provideCarousel,
5
+ r as useCarousel
6
+ };
@@ -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
+ };