motion-plus-vue 0.0.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 (66) hide show
  1. package/dist/cjs/index.js +9 -0
  2. package/dist/components/AnimateNumber/AnimateNumber.d.ts +15 -0
  3. package/dist/components/AnimateNumber/Mask.d.ts +22 -0
  4. package/dist/components/AnimateNumber/NumberDigit.d.ts +5 -0
  5. package/dist/components/AnimateNumber/NumberSection.d.ts +15 -0
  6. package/dist/components/AnimateNumber/NumberSymbol.d.ts +3 -0
  7. package/dist/components/AnimateNumber/config.d.ts +6 -0
  8. package/dist/components/AnimateNumber/context.d.ts +15 -0
  9. package/dist/components/AnimateNumber/hooks/use-is-initial-render.d.ts +3 -0
  10. package/dist/components/AnimateNumber/index.d.ts +5 -0
  11. package/dist/components/AnimateNumber/types.d.ts +55 -0
  12. package/dist/components/AnimateNumber/use-animate.d.ts +6 -0
  13. package/dist/components/AnimateNumber/utils/format-parts.d.ts +5 -0
  14. package/dist/components/AnimateNumber/utils/get-width-in-ems.d.ts +2 -0
  15. package/dist/components/AnimateNumber/utils/target-widths.d.ts +1 -0
  16. package/dist/components/Cursor/Cursor.d.ts +69 -0
  17. package/dist/components/Cursor/config.d.ts +23 -0
  18. package/dist/components/Cursor/get-cursor-size.d.ts +10 -0
  19. package/dist/components/Cursor/hooks/use-cursor-in-view.d.ts +1 -0
  20. package/dist/components/Cursor/hooks/use-cursor-state/find-target.d.ts +3 -0
  21. package/dist/components/Cursor/hooks/use-cursor-state/index.d.ts +3 -0
  22. package/dist/components/Cursor/hooks/use-cursor-state/types.d.ts +14 -0
  23. package/dist/components/Cursor/hooks/use-has-pointer-moved.d.ts +5 -0
  24. package/dist/components/Cursor/hooks/use-mixed.d.ts +2 -0
  25. package/dist/components/Cursor/hooks/use-offset.d.ts +10 -0
  26. package/dist/components/Cursor/hooks/use-pointer-position.d.ts +5 -0
  27. package/dist/components/Cursor/hooks/use-snap-to-target.d.ts +7 -0
  28. package/dist/components/Cursor/hooks/utils/only-mouse-events.d.ts +2 -0
  29. package/dist/components/Cursor/index.d.ts +5 -0
  30. package/dist/components/Cursor/use-cursor-styles.d.ts +1 -0
  31. package/dist/es/components/AnimateNumber/AnimateNumber.vue.mjs +111 -0
  32. package/dist/es/components/AnimateNumber/AnimateNumber.vue2.mjs +4 -0
  33. package/dist/es/components/AnimateNumber/Mask.vue.mjs +33 -0
  34. package/dist/es/components/AnimateNumber/Mask.vue2.mjs +4 -0
  35. package/dist/es/components/AnimateNumber/NumberDigit.vue.mjs +124 -0
  36. package/dist/es/components/AnimateNumber/NumberDigit.vue2.mjs +4 -0
  37. package/dist/es/components/AnimateNumber/NumberSection.vue.mjs +133 -0
  38. package/dist/es/components/AnimateNumber/NumberSection.vue2.mjs +4 -0
  39. package/dist/es/components/AnimateNumber/NumberSymbol.vue.mjs +73 -0
  40. package/dist/es/components/AnimateNumber/NumberSymbol.vue2.mjs +4 -0
  41. package/dist/es/components/AnimateNumber/config.mjs +21 -0
  42. package/dist/es/components/AnimateNumber/context.mjs +6 -0
  43. package/dist/es/components/AnimateNumber/hooks/use-is-initial-render.mjs +12 -0
  44. package/dist/es/components/AnimateNumber/index.mjs +5 -0
  45. package/dist/es/components/AnimateNumber/use-animate.mjs +24 -0
  46. package/dist/es/components/AnimateNumber/utils/format-parts.mjs +61 -0
  47. package/dist/es/components/AnimateNumber/utils/get-width-in-ems.mjs +7 -0
  48. package/dist/es/components/AnimateNumber/utils/target-widths.mjs +4 -0
  49. package/dist/es/components/Cursor/Cursor.vue.mjs +135 -0
  50. package/dist/es/components/Cursor/Cursor.vue2.mjs +4 -0
  51. package/dist/es/components/Cursor/config.mjs +8 -0
  52. package/dist/es/components/Cursor/get-cursor-size.mjs +16 -0
  53. package/dist/es/components/Cursor/hooks/use-cursor-in-view.mjs +41 -0
  54. package/dist/es/components/Cursor/hooks/use-cursor-state/find-target.mjs +18 -0
  55. package/dist/es/components/Cursor/hooks/use-cursor-state/index.mjs +67 -0
  56. package/dist/es/components/Cursor/hooks/use-has-pointer-moved.mjs +22 -0
  57. package/dist/es/components/Cursor/hooks/use-mixed.mjs +7 -0
  58. package/dist/es/components/Cursor/hooks/use-offset.mjs +10 -0
  59. package/dist/es/components/Cursor/hooks/use-pointer-position.mjs +22 -0
  60. package/dist/es/components/Cursor/hooks/use-snap-to-target.mjs +20 -0
  61. package/dist/es/components/Cursor/hooks/utils/only-mouse-events.mjs +14 -0
  62. package/dist/es/components/Cursor/index.mjs +5 -0
  63. package/dist/es/components/Cursor/use-cursor-styles.mjs +27 -0
  64. package/dist/es/index.mjs +6 -0
  65. package/dist/index.d.ts +2 -0
  66. package/package.json +62 -0
@@ -0,0 +1,124 @@
1
+ import { defineComponent as M, ref as u, watch as y, nextTick as W, createBlock as s, openBlock as o, unref as r, normalizeStyle as v, withCtx as j, createElementVNode as A, createElementBlock as m, createCommentVNode as B, Fragment as R, renderList as V, resolveDynamicComponent as g, createVNode as F } from "vue";
2
+ import { useMotionConfig as K, motion as S, animate as T } from "motion-v";
3
+ import { useIsInitialRender as z } from "./hooks/use-is-initial-render.mjs";
4
+ import { digitFillStyle as b, maskHeight as H } from "./config.mjs";
5
+ import { useAnimate as L } from "./use-animate.mjs";
6
+ import { getWidthInEm as Y } from "./utils/get-width-in-ems.mjs";
7
+ import { targetWidths as $ } from "./utils/target-widths.mjs";
8
+ const Z = /* @__PURE__ */ M({
9
+ __name: "NumberDigit",
10
+ props: {
11
+ value: {},
12
+ initialValue: {
13
+ default: void 0
14
+ },
15
+ isPresent: {
16
+ type: Boolean
17
+ },
18
+ partKey: {},
19
+ onRemove: {},
20
+ style: {}
21
+ },
22
+ setup(w) {
23
+ const a = w, c = a.initialValue ?? a.value, h = z(), I = K(), l = u(), k = u(Array(10).fill(null)), C = u(), {
24
+ getRoot: N,
25
+ handleComplete: _,
26
+ root: p
27
+ } = L(a);
28
+ let d = c;
29
+ const t = u(c);
30
+ y([() => a.value, () => a.isPresent], ([e, n]) => {
31
+ if (!n)
32
+ return t.value = 0;
33
+ if (h.current)
34
+ return W(() => {
35
+ t.value = e;
36
+ });
37
+ t.value = e;
38
+ }, {
39
+ immediate: !0
40
+ });
41
+ function D(e) {
42
+ var x;
43
+ if (!l.value || e === d) return;
44
+ const n = l.value.getBoundingClientRect(), i = (x = p.value) == null ? void 0 : x.getBoundingClientRect(), E = n.height * (e - d) + (n.top - (i ? i.top || 0 : n.top));
45
+ T(l.value, {
46
+ y: [E, 0]
47
+ }, I.value.transition);
48
+ }
49
+ function P(e) {
50
+ if (h.current && c === e || !k.value[e]) return;
51
+ const n = Y(k.value[e]);
52
+ p.value && $.set(p.value, n), C.value = n;
53
+ }
54
+ y(t, (e) => {
55
+ P(e);
56
+ }, {
57
+ immediate: !0,
58
+ flush: "post"
59
+ }), y(t, (e, n, i) => {
60
+ D(e), i(() => {
61
+ d = e;
62
+ });
63
+ }, {
64
+ immediate: !0,
65
+ flush: "pre"
66
+ });
67
+ function f(e) {
68
+ return () => F("span", {
69
+ key: e,
70
+ style: {
71
+ display: "inline-block",
72
+ padding: `calc(${H}/2) 0`
73
+ }
74
+ }, [e]);
75
+ }
76
+ return (e, n) => (o(), s(r(S).span, {
77
+ ref: r(N),
78
+ layout: "position",
79
+ "data-state": e.isPresent ? void 0 : "exiting",
80
+ "data-key": e.partKey,
81
+ style: v({
82
+ display: "inline-flex",
83
+ justifyContent: "center",
84
+ width: C.value
85
+ }),
86
+ "aria-hidden": !e.isPresent,
87
+ onMotioncomplete: r(_)
88
+ }, {
89
+ default: j(() => [A("span", {
90
+ ref_key: "scope",
91
+ ref: l,
92
+ style: {
93
+ display: "inline-flex",
94
+ justifyContent: "center",
95
+ flexDirection: "column",
96
+ alignItems: "center",
97
+ position: "relative"
98
+ }
99
+ }, [t.value !== 0 ? (o(), m("span", {
100
+ key: 0,
101
+ style: v({
102
+ ...r(b),
103
+ bottom: "100%",
104
+ left: 0
105
+ })
106
+ }, [(o(!0), m(R, null, V(t.value, (i) => (o(), s(g(f(i - 1)), {
107
+ key: i - 1
108
+ }))), 128))], 4)) : B("", !0), (o(), s(g(f(t.value)))), t.value !== 9 ? (o(), m("span", {
109
+ key: 1,
110
+ style: v({
111
+ ...r(b),
112
+ top: "100%",
113
+ left: 0
114
+ })
115
+ }, [(o(!0), m(R, null, V(9 - t.value, (i) => (o(), s(g(f(t.value + i)), {
116
+ key: t.value + i
117
+ }))), 128))], 4)) : B("", !0)], 512)]),
118
+ _: 1
119
+ }, 8, ["data-state", "data-key", "style", "aria-hidden", "onMotioncomplete"]));
120
+ }
121
+ });
122
+ export {
123
+ Z as default
124
+ };
@@ -0,0 +1,4 @@
1
+ import f from "./NumberDigit.vue.mjs";
2
+ export {
3
+ f as default
4
+ };
@@ -0,0 +1,133 @@
1
+ import { defineComponent as _, ref as y, watch as k, toRef as j, createBlock as p, openBlock as l, unref as f, normalizeStyle as C, normalizeClass as $, withCtx as x, createElementVNode as B, createTextVNode as E, createVNode as N, createElementBlock as g, Fragment as P, renderList as S } from "vue";
2
+ import { motion as W, AnimatePresence as M } from "motion-v";
3
+ import { injectSectionContext as V } from "./context.mjs";
4
+ import { useIsInitialRender as z } from "./hooks/use-is-initial-render.mjs";
5
+ import { getWidthInEm as h } from "./utils/get-width-in-ems.mjs";
6
+ import A from "./NumberSymbol.vue.mjs";
7
+ import L from "./NumberDigit.vue.mjs";
8
+ import { targetWidths as T } from "./utils/target-widths.mjs";
9
+ const O = /* @__PURE__ */ _({
10
+ __name: "NumberSection",
11
+ props: {
12
+ parts: {},
13
+ justify: { default: "left" },
14
+ mode: {},
15
+ name: {},
16
+ style: {}
17
+ },
18
+ setup(w) {
19
+ const u = w, c = y(), m = y();
20
+ function R(n) {
21
+ m.value = n == null ? void 0 : n.$el;
22
+ }
23
+ const r = y(), d = z();
24
+ k(() => u.parts.map((n) => n.value).join(""), () => {
25
+ if (!r.value)
26
+ return;
27
+ if (d.current) {
28
+ m.value && (m.value.style.width = h(r.value));
29
+ return;
30
+ }
31
+ const n = Array.from(r.value.children).map((e) => {
32
+ if (!(e instanceof HTMLElement))
33
+ return;
34
+ if (e.dataset.state === "exiting") {
35
+ const I = e.nextSibling;
36
+ return e.remove(), () => {
37
+ r.value && r.value.insertBefore(e, I);
38
+ };
39
+ }
40
+ const t = T.get(e);
41
+ if (!t)
42
+ return;
43
+ const s = e.style.width;
44
+ return e.style.width = t, () => {
45
+ e.style.width = s;
46
+ };
47
+ }), i = h(r.value);
48
+ c.value = i;
49
+ for (let e = n.length - 1; e >= 0; e--) {
50
+ const t = n[e];
51
+ t && t();
52
+ }
53
+ }, { immediate: !0, flush: "post" });
54
+ const o = j(u, "justify");
55
+ V({
56
+ justify: o
57
+ });
58
+ let a = u.parts;
59
+ k(() => u.parts, (n) => {
60
+ const i = new Map(n.map((t) => [t.key, { ...t, isPresent: !0 }]));
61
+ a = [...a.filter((t) => !i.get(t.key)).map(
62
+ (t) => ({ ...t, isPresent: !1 })
63
+ ), ...n].sort((t, s) => o.value === "right" ? t.isPresent === s.isPresent ? t.originalIndex - s.originalIndex : t.isPresent ? -1 : 1 : o.value === "left" ? t.isPresent === s.isPresent ? t.originalIndex - s.originalIndex : t.isPresent ? 1 : -1 : t.originalIndex - s.originalIndex);
64
+ });
65
+ function v(n) {
66
+ a = a.filter((i) => i.key !== n);
67
+ }
68
+ return (n, i) => (l(), p(f(W).span, {
69
+ ref: R,
70
+ class: $(`number-section-${n.name}`),
71
+ style: C({
72
+ ...n.style,
73
+ display: "inline-flex",
74
+ justifyContent: o.value,
75
+ width: c.value
76
+ }),
77
+ layout: "position"
78
+ }, {
79
+ default: x(() => [
80
+ B("span", {
81
+ ref_key: "measuredRef",
82
+ ref: r,
83
+ style: {
84
+ display: "inline-flex",
85
+ justifyContent: "inherit",
86
+ position: "relative"
87
+ }
88
+ }, [
89
+ i[0] || (i[0] = E(" ​ ")),
90
+ N(f(M), {
91
+ multiple: "",
92
+ mode: n.mode,
93
+ "anchor-x": o.value,
94
+ initial: !1
95
+ }, {
96
+ default: x(() => [
97
+ (l(!0), g(P, null, S(f(a), (e) => (l(), g(P, {
98
+ key: e.key
99
+ }, [
100
+ e.type === "integer" || e.type === "fraction" ? (l(), p(L, {
101
+ key: e.key,
102
+ "part-key": e.key,
103
+ initial: { opacity: 0 },
104
+ animate: { opacity: 1 },
105
+ exit: { opacity: 0 },
106
+ value: e.value,
107
+ "is-present": e.isPresent ?? !0,
108
+ "initial-value": f(d).current ? void 0 : 0,
109
+ onRemove: v
110
+ }, null, 8, ["part-key", "value", "is-present", "initial-value"])) : (l(), p(A, {
111
+ key: e.type === "literal" ? `${e.key}:${e.value}` : e.key,
112
+ type: e.type,
113
+ "part-key": e.key,
114
+ initial: { opacity: 0 },
115
+ animate: { opacity: 1 },
116
+ exit: { opacity: 0 },
117
+ value: e.value,
118
+ "is-present": e.isPresent ?? !0,
119
+ onRemove: v
120
+ }, null, 8, ["type", "part-key", "value", "is-present"]))
121
+ ], 64))), 128))
122
+ ]),
123
+ _: 1
124
+ }, 8, ["mode", "anchor-x"])
125
+ ], 512)
126
+ ]),
127
+ _: 1
128
+ }, 8, ["class", "style"]));
129
+ }
130
+ });
131
+ export {
132
+ O as default
133
+ };
@@ -0,0 +1,4 @@
1
+ import f from "./NumberSection.vue.mjs";
2
+ export {
3
+ f as default
4
+ };
@@ -0,0 +1,73 @@
1
+ import { defineComponent as u, createBlock as n, openBlock as a, unref as e, normalizeStyle as c, withCtx as i, createVNode as y, createTextVNode as d, toDisplayString as f } from "vue";
2
+ import { motion as l, AnimatePresence as h } from "motion-v";
3
+ import { maskHeight as g } from "./config.mjs";
4
+ import { useSectionContext as v } from "./context.mjs";
5
+ import { useAnimate as x } from "./use-animate.mjs";
6
+ const B = /* @__PURE__ */ u({
7
+ __name: "NumberSymbol",
8
+ props: {
9
+ partKey: {},
10
+ type: {},
11
+ value: {},
12
+ isPresent: { type: Boolean },
13
+ onRemove: { type: Function },
14
+ style: {}
15
+ },
16
+ setup(r) {
17
+ const s = r, { justify: o } = v(), { getRoot: p, handleComplete: m } = x(s);
18
+ return (t, k) => (a(), n(e(l).span, {
19
+ ref: e(p),
20
+ layout: "position",
21
+ "data-state": t.isPresent ? void 0 : "exiting",
22
+ style: c({
23
+ display: "inline-flex",
24
+ justifyContent: e(o),
25
+ padding: `calc(${e(g)}/2) 0`,
26
+ position: "relative"
27
+ }),
28
+ "aria-hidden": !t.isPresent,
29
+ onMotioncomplete: e(m)
30
+ }, {
31
+ default: i(() => [
32
+ y(e(h), {
33
+ multiple: "",
34
+ mode: "popLayout",
35
+ "anchor-x": e(o),
36
+ initial: !1
37
+ }, {
38
+ default: i(() => [
39
+ (a(), n(e(l).span, {
40
+ key: t.value,
41
+ layout: e(o) === "right" ? "position" : !1,
42
+ initial: { opacity: 0 },
43
+ animate: { opacity: [null, 1] },
44
+ exit: {
45
+ opacity: [null, 0],
46
+ transition: {
47
+ duration: 0.3
48
+ }
49
+ },
50
+ style: {
51
+ display: "inline-block",
52
+ whiteSpace: "pre"
53
+ },
54
+ transition: {
55
+ duration: 0.2
56
+ }
57
+ }, {
58
+ default: i(() => [
59
+ d(f(t.value), 1)
60
+ ]),
61
+ _: 1
62
+ }, 8, ["layout"]))
63
+ ]),
64
+ _: 1
65
+ }, 8, ["anchor-x"])
66
+ ]),
67
+ _: 1
68
+ }, 8, ["data-state", "style", "aria-hidden", "onMotioncomplete"]));
69
+ }
70
+ });
71
+ export {
72
+ B as default
73
+ };
@@ -0,0 +1,4 @@
1
+ import f from "./NumberSymbol.vue.mjs";
2
+ export {
3
+ f as default
4
+ };
@@ -0,0 +1,21 @@
1
+ import { addScaleCorrector as n } from "motion-v";
2
+ const t = "var(--mask-height, 0.15em)", o = "var(--mask-width, 0.5em)", a = `calc(${o} / var(--invert-x, 1))`, r = "#000 0, transparent 71%", s = `linear-gradient(to right, transparent 0, #000 ${a}, #000 calc(100% - ${a}), transparent),linear-gradient(to bottom, transparent 0, #000 ${t}, #000 calc(100% - ${t}), transparent 100%),radial-gradient(at bottom right, ${r}),radial-gradient(at bottom left, ${r}), radial-gradient(at top left, ${r}), radial-gradient(at top right, ${r})`, d = `100% calc(100% - ${t} * 2),calc(100% - ${a} * 2) 100%,${a} ${t},${a} ${t},${a} ${t},${a} ${t}`;
3
+ n({
4
+ "--invert-x": {
5
+ correct: (c, { treeScale: e, projectionDelta: i }) => i.x.scale * e.x
6
+ }
7
+ });
8
+ const $ = {
9
+ display: "flex",
10
+ flexDirection: "column",
11
+ alignItems: "center",
12
+ position: "absolute",
13
+ width: "100%"
14
+ };
15
+ export {
16
+ $ as digitFillStyle,
17
+ s as mask,
18
+ t as maskHeight,
19
+ d as maskSize,
20
+ o as maskWidth
21
+ };
@@ -0,0 +1,6 @@
1
+ import { createContext as t } from "motion-v";
2
+ const [o, n] = t("SectionContext");
3
+ export {
4
+ n as injectSectionContext,
5
+ o as useSectionContext
6
+ };
@@ -0,0 +1,12 @@
1
+ import { onMounted as n } from "vue";
2
+ function t() {
3
+ const e = {
4
+ current: !0
5
+ };
6
+ return n(() => {
7
+ e.current = !1;
8
+ }), e;
9
+ }
10
+ export {
11
+ t as useIsInitialRender
12
+ };
@@ -0,0 +1,5 @@
1
+ import m from "./AnimateNumber.vue.mjs";
2
+ const r = m;
3
+ export {
4
+ r as AnimateNumber
5
+ };
@@ -0,0 +1,24 @@
1
+ import { mountedStates as u } from "motion-v";
2
+ import { ref as f, watch as m } from "vue";
3
+ function v(e) {
4
+ const n = f();
5
+ function o(t) {
6
+ n.value = t == null ? void 0 : t.$el;
7
+ }
8
+ m(() => e.isPresent, (t) => {
9
+ var i;
10
+ n.value && ((i = u.get(n.value)) == null || i.setActive("exit", !t));
11
+ });
12
+ function a(t) {
13
+ var i;
14
+ t.detail.isExit && !e.isPresent && ((i = e.onRemove) == null || i.call(e, e.partKey));
15
+ }
16
+ return {
17
+ root: n,
18
+ getRoot: o,
19
+ handleComplete: a
20
+ };
21
+ }
22
+ export {
23
+ v as useAnimate
24
+ };
@@ -0,0 +1,61 @@
1
+ function b(y, {
2
+ locales: I,
3
+ format: d
4
+ }, u, i) {
5
+ const r = new Intl.NumberFormat(I, d).formatToParts(Number(y));
6
+ u && r.unshift({ type: "prefix", value: u }), i && r.push({ type: "suffix", value: i });
7
+ const p = [], a = [], s = [], c = [], f = {}, n = (e) => `${e}:${f[e] = (f[e] ?? -1) + 1}`;
8
+ let g = "", m = !1, v = !1, o = 0;
9
+ for (const e of r) {
10
+ g += e.value;
11
+ const t = e.type === "minusSign" || e.type === "plusSign" ? "sign" : e.type;
12
+ switch (t) {
13
+ case "integer":
14
+ m = !0, a.push(
15
+ ...e.value.split("").map((l) => ({ type: t, value: parseInt(l) }))
16
+ );
17
+ break;
18
+ case "group":
19
+ a.push({ type: t, value: e.value });
20
+ break;
21
+ case "decimal":
22
+ v = !0, s.push({
23
+ type: t,
24
+ value: e.value,
25
+ key: n(t),
26
+ originalIndex: o++
27
+ });
28
+ break;
29
+ case "fraction":
30
+ s.push(
31
+ ...e.value.split("").map((l) => ({
32
+ type: t,
33
+ value: parseInt(l),
34
+ key: n(t),
35
+ originalIndex: o++
36
+ }))
37
+ );
38
+ break;
39
+ default:
40
+ (m || v ? c : p).push({
41
+ type: t,
42
+ value: e.value,
43
+ key: n(t),
44
+ originalIndex: o++
45
+ });
46
+ }
47
+ }
48
+ const h = [];
49
+ for (let e = a.length - 1; e >= 0; e--) {
50
+ const t = n(a[e].type);
51
+ h.unshift({
52
+ ...a[e],
53
+ key: t,
54
+ originalIndex: e
55
+ });
56
+ }
57
+ return { pre: p, integer: h, fraction: s, post: c, formatted: g };
58
+ }
59
+ export {
60
+ b as formatToParts
61
+ };
@@ -0,0 +1,7 @@
1
+ function n(t) {
2
+ const { width: e, fontSize: o } = getComputedStyle(t);
3
+ return `${parseFloat(e) / parseFloat(o)}em`;
4
+ }
5
+ export {
6
+ n as getWidthInEm
7
+ };
@@ -0,0 +1,4 @@
1
+ const t = /* @__PURE__ */ new WeakMap();
2
+ export {
3
+ t as targetWidths
4
+ };
@@ -0,0 +1,135 @@
1
+ import { defineComponent as j, toRef as w, useSlots as k, computed as M, createBlock as v, openBlock as S, Teleport as X, createCommentVNode as Y, unref as o, withCtx as l, createVNode as c, mergeProps as H, renderSlot as L } from "vue";
2
+ import { useSpring as T, LayoutGroup as N, MotionConfig as O, motion as R, AnimatePresence as A } from "motion-v";
3
+ import { useCursorStyles as E } from "./use-cursor-styles.mjs";
4
+ import { usePointerPosition as F } from "./hooks/use-pointer-position.mjs";
5
+ import { useOffset as G } from "./hooks/use-offset.mjs";
6
+ import { useCursorState as _ } from "./hooks/use-cursor-state/index.mjs";
7
+ import { useCursorIsInView as q } from "./hooks/use-cursor-in-view.mjs";
8
+ import { useSnapToTarget as D } from "./hooks/use-snap-to-target.mjs";
9
+ import { defaultFollowSpring as J, topLeftPoint as x, centerPoint as K, autoSize as Q, defaultTransition as U } from "./config.mjs";
10
+ import { getCursorSize as W } from "./get-cursor-size.mjs";
11
+ import { useHasPointerMoved as Z } from "./hooks/use-has-pointer-moved.mjs";
12
+ const mt = /* @__PURE__ */ j({
13
+ __name: "Cursor",
14
+ props: {
15
+ follow: { type: Boolean, default: !1 },
16
+ center: { default: ({ follow: i }) => i ? x : K },
17
+ offset: { default: () => x },
18
+ spring: { type: [Boolean, Object], default: ({ follow: i }) => i ? J : !1 },
19
+ snapToTarget: { type: Boolean, default: !1 },
20
+ matchTextSize: { type: Boolean, default: !0 },
21
+ transition: {},
22
+ variants: {},
23
+ style: {}
24
+ },
25
+ setup(i) {
26
+ const e = i, z = w(e, "offset");
27
+ E(() => e.follow);
28
+ const f = F(), s = G(f, z), d = T(s.x, e.spring || void 0), y = T(s.y, e.spring || void 0);
29
+ function g() {
30
+ const t = s.x.on("change", (r) => {
31
+ d.jump(r), t();
32
+ }), n = s.y.on("change", (r) => {
33
+ y.jump(r), n();
34
+ });
35
+ }
36
+ const a = _(), C = q(g), { x: P, y: $ } = D(
37
+ e.spring ? { x: d, y } : f,
38
+ w(e, "snapToTarget"),
39
+ a
40
+ ), p = k(), u = M(() => {
41
+ var r, m;
42
+ const t = (m = (r = p.default) == null ? void 0 : r.call(p)) == null ? void 0 : m.filter(
43
+ (h) => h.type !== Symbol.for("v-cmt")
44
+ );
45
+ if (t != null && t.length)
46
+ return Q;
47
+ const n = W(a.value.type, a.value, {
48
+ matchPointerSize: e.snapToTarget,
49
+ matchTextSize: e.matchTextSize
50
+ });
51
+ return {
52
+ width: `${n.width}px`,
53
+ height: `${n.height}px`
54
+ };
55
+ }), B = Z(f, g);
56
+ function b(t) {
57
+ return (n, r) => `translate(-${t.x * 100}%, -${t.y * 100}%) ${r}`;
58
+ }
59
+ function I() {
60
+ const { follow: t, center: n, offset: r, spring: m, snapToTarget: h, matchTextSize: tt, ...V } = e;
61
+ return {
62
+ ...V
63
+ };
64
+ }
65
+ return (t, n) => (S(), v(X, { to: "body" }, [
66
+ o(B) ? (S(), v(o(N), { key: 0 }, {
67
+ default: l(() => [
68
+ c(o(O), {
69
+ transition: e.transition || o(U)
70
+ }, {
71
+ default: l(() => [
72
+ c(o(R).div, H({
73
+ layout: "",
74
+ "data-motion-cursor": t.follow ? "follow" : "pointer",
75
+ "data-framer-portal-id": "motion-cursor",
76
+ initial: "exit",
77
+ exit: "exit"
78
+ }, {
79
+ ...t.$attrs,
80
+ ...I()
81
+ }, {
82
+ variants: {
83
+ default: { opacity: 1, scale: 1 },
84
+ exit: { opacity: 0, scale: 0 },
85
+ pressed: t.follow ? { opacity: 1, scale: 1 } : { opacity: 1, scale: 0.9 },
86
+ ...t.variants
87
+ },
88
+ animate: [
89
+ "default",
90
+ o(a).type,
91
+ o(C) ? o(a).isPressed ? "pressed" : "" : "exit"
92
+ ],
93
+ "transform-template": b(t.center),
94
+ "data-w": u.value.width,
95
+ style: {
96
+ width: u.value.width,
97
+ height: u.value.height,
98
+ borderRadius: t.follow ? 0 : 20,
99
+ zIndex: t.follow ? 99998 : 99999,
100
+ willChange: "transform",
101
+ contain: "layout",
102
+ overflow: "hidden",
103
+ originX: t.center.x,
104
+ originY: t.center.y,
105
+ ...e.style,
106
+ x: o(P),
107
+ y: o($),
108
+ top: 0,
109
+ left: 0,
110
+ position: "fixed",
111
+ pointerEvents: "none"
112
+ }
113
+ }), {
114
+ default: l(() => [
115
+ c(o(A), { multiple: "" }, {
116
+ default: l(() => [
117
+ L(t.$slots, "default")
118
+ ]),
119
+ _: 3
120
+ })
121
+ ]),
122
+ _: 3
123
+ }, 16, ["data-motion-cursor", "variants", "animate", "transform-template", "data-w", "style"])
124
+ ]),
125
+ _: 3
126
+ }, 8, ["transition"])
127
+ ]),
128
+ _: 3
129
+ })) : Y("", !0)
130
+ ]));
131
+ }
132
+ });
133
+ export {
134
+ mt as default
135
+ };
@@ -0,0 +1,4 @@
1
+ import f from "./Cursor.vue.mjs";
2
+ export {
3
+ f as default
4
+ };
@@ -0,0 +1,8 @@
1
+ const t = { width: "auto", height: "auto" }, o = { x: 0, y: 0 }, n = { x: 0.5, y: 0.5 }, e = { stiffness: 1e3, damping: 100 }, i = { duration: 0.15, ease: [0.38, 0.12, 0.29, 1] };
2
+ export {
3
+ t as autoSize,
4
+ n as centerPoint,
5
+ e as defaultFollowSpring,
6
+ i as defaultTransition,
7
+ o as topLeftPoint
8
+ };
@@ -0,0 +1,16 @@
1
+ function i(T, t, {
2
+ matchPointerSize: E,
3
+ matchTextSize: e
4
+ }) {
5
+ switch (T) {
6
+ case "pointer":
7
+ return E && t.targetBoundingBox ? t.targetBoundingBox : { width: 30, height: 30 };
8
+ case "text":
9
+ return e && t.fontSize ? { width: 4, height: t.fontSize } : { width: 4, height: 20 };
10
+ default:
11
+ return { width: 16, height: 16 };
12
+ }
13
+ }
14
+ export {
15
+ i as getCursorSize
16
+ };