motion-plus-vue 1.1.0 → 1.1.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 CHANGED
@@ -6,4 +6,4 @@
6
6
  [data-motion-cursor="pointer"] {
7
7
  background-color: #333;
8
8
  }
9
- `,document.head.appendChild(n),()=>{document.head.removeChild(n)}}function de(n){e.watch(n,(t,o,i)=>{const r=t?fe():s.noop;return i(()=>{r()})})}function R(n){return t=>{t.pointerType==="mouse"&&n(t)}}function F(n){return R(t=>{t.button===0&&n(t)})}let T,_;function pe(){T=s.motionValue(0),_=s.motionValue(0);let n=0,t=0;function o(){T.set(n),_.set(t)}typeof window<"u"&&window.addEventListener("pointermove",R(i=>{n=i.clientX,t=i.clientY,s.frame.update(o)}))}function j(){return T||pe(),{x:T,y:_}}function me(n,t){return{x:s.useTransform(()=>n.x.get()+t.value.x),y:s.useTransform(()=>n.y.get()+t.value.y)}}function ye(n){return n.closest("[data-cursor]")}function ge(n){return n.closest('a, button, input[type="button"]:not(:disabled)')}function ve(n){return window.getComputedStyle(n).userSelect==="none"?null:n.closest("p, textarea:not(:disabled), input[type='text']:not(:disabled), h1, h2, h3, h4, h5, h6")}function he(n){let t=ye(n);return t?[t.dataset.cursor,t]:(t=ge(n),t?["pointer",t]:(t=ve(n),t?["text",t]:["default",null]))}let M=null,C={type:"default",isPressed:!1,fontSize:null,targetBoundingBox:null,target:null,theme:null};function we(n){let t=null;if("closest"in n){const o=n.closest("[data-cursor-theme]");o instanceof HTMLElement&&(t=o.dataset.cursorTheme||null)}return t}function xe(){if(typeof window>"u")return{onChange:()=>()=>{}};const n=new Set;function t(f){C={...C,...f},n.forEach(h=>h(C))}const o=F(()=>{C.isPressed||t({isPressed:!0})}),i=F(()=>{C.isPressed&&t({isPressed:!1})}),r=R(({target:f})=>{if(!f)return;const[h,g]=he(f);let v=!1;const u={target:g,theme:we(f)};h!==C.type&&(u.type=h,v=!0),u.theme!==C.theme&&(C.theme=u.theme,v=!0);const l=h==="pointer"&&g?g.getBoundingClientRect():null;if(l!==C.targetBoundingBox&&(u.targetBoundingBox=l,v=!0),h==="text"){const{fontSize:p}=window.getComputedStyle(f),w=p?parseInt(p):null;w!==C.fontSize&&(u.fontSize=w,v=!0)}else C.fontSize&&(u.fontSize=null,v=!0);v&&t(u)});function a(){typeof window>"u"||(window.addEventListener("pointerover",r),window.addEventListener("pointerdown",o),window.addEventListener("pointerup",i))}function d(){window.removeEventListener("pointerover",r),window.removeEventListener("pointerdown",o),window.removeEventListener("pointerup",i)}return{onChange:f=>(n.size||a(),n.add(f),()=>{n.delete(f),n.size||d()})}}function ke(){return M||(M=xe()),M}function A(){const n=e.ref({...C});return e.watch(n,()=>ke().onChange(t=>{n.value=t}),{immediate:!0,flush:"post"}),n}let V=null;function Be(){const n=new Set;function t(){n.forEach(a=>a.show())}function o(){n.forEach(a=>a.hide())}function i(){document.body.addEventListener("mouseenter",t),document.body.addEventListener("mouseleave",o)}function r(){document.body.removeEventListener("mouseenter",t),document.body.removeEventListener("mouseleave",o)}return{on:a=>typeof window>"u"?s.noop:(n.size||i(),n.add(a),()=>{n.delete(a),n.size===0&&r()})}}function Ce(){return V||(V=Be()),V}function Q(n){const t=e.ref(!0);return e.watch(t,()=>Ce().on({show:()=>{t.value||(n(),t.value=!0)},hide:()=>t.value=!1}),{immediate:!0}),t}const H={x:0,y:0},Se={x:.5,y:.5},Pe={duration:0},be={stiffness:1e3,damping:100},$e={duration:.15,ease:[.38,.12,.29,1]},W={magneticOptions:{morph:!0,padding:5,snap:.8}},X=17,Y=31,K=4,Ee=20;function z(n,t,o){const i={width:(o==null?void 0:o.width)??n,height:(o==null?void 0:o.height)??t};return typeof i.width=="number"&&(i.width=`${i.width}px`),typeof i.height=="number"&&(i.height=`${i.height}px`),i}function Ie({type:n,state:t,hasChildren:o,style:i,isMagnetic:r,magneticOptions:a,matchTextSize:d}){const f=r&&t.targetBoundingBox;if(o&&!f)return z("auto","auto",i);const{padding:h,morph:g}=a;switch(n){case"pointer":if(r&&g&&t.targetBoundingBox){const{width:v,height:u}=t.targetBoundingBox;return{width:`${v+h*2}px`,height:`${u+h*2}px`}}return z(Y,Y,i);case"text":return d&&t.fontSize?{width:`${K}px`,height:`${t.fontSize}px`}:z(K,Ee,i);default:return z(X,X,i)}}function ze({x:n,y:t},o){const i=e.ref(n.prev!==void 0||t.prev!==void 0);return e.watch(i,()=>{if(i.value)return;const r=()=>{i.value=!0,o(),a()},a=s.pipe(n.on("change",r),t.on("change",r));return()=>a()},{immediate:!0}),i}function Te(n,t,o){return s.useTransform(()=>s.mix(n.value.get(),t.get(),o.get()))}function G(n,t,o){const i=s.useSpring(0,{stiffness:600,damping:50}),r=s.useMotionValue(0),a=Te(n,i,r);return e.watch(()=>o==null?void 0:o.value,(d,f)=>{d?(!f&&!r.isAnimating()?i.jump(d):i.set(d),s.animate(r,t.value||0)):s.animate(r,0)},{immediate:!0,flush:"sync"}),a}function Me(n,t,o,i){const r=G(e.computed(()=>n.value.x),i,e.computed(()=>o.value.targetBoundingBox?o.value.targetBoundingBox.left+o.value.targetBoundingBox.width/2:void 0)),a=G(e.computed(()=>n.value.y),i,e.computed(()=>o.value.targetBoundingBox?o.value.targetBoundingBox.top+o.value.targetBoundingBox.height/2:void 0));return e.computed(()=>t?{x:r,y:a}:n.value)}const Ve=e.defineComponent({name:"Cursor",inheritAttrs:!1,__name:"Cursor",props:{follow:{type:Boolean,default:!1},center:{default:({follow:n})=>n?H:Se},offset:{default:()=>H},spring:{type:[Boolean,Object],default:({follow:n})=>n?be:!1},matchTextSize:{type:Boolean,default:!0},magnetic:{type:[Boolean,Object],default:!1},transition:{},variants:{},style:{},show:{type:Boolean,default:!0}},setup(n){const t=n,{offset:o,magnetic:i}=e.toRefs(t),r=s.useReducedMotion();de(()=>!r.value&&!t.follow);const a=j(),d=me(a,o),f=s.useSpring(d.x,t.spring||void 0),h=s.useSpring(d.y,t.spring||void 0),g=e.computed(()=>typeof t.magnetic=="object"?{...W.magneticOptions,...t.magnetic}:W.magneticOptions);function v(){const c=d.x.on("change",B=>{f.jump(B),c()}),k=d.y.on("change",B=>{h.jump(B),k()})}const u=A(),l=Q(v),p=Me(e.computed(()=>t.spring?{x:f,y:h}:a),e.computed(()=>!!i.value),u,e.computed(()=>g.value&&g.value.snap)),w=e.useSlots(),P=e.computed(()=>{var B,$;const c=($=(B=w.default)==null?void 0:B.call(w))==null?void 0:$.filter(O=>O.type!==Symbol.for("v-cmt"));return Ie({type:u.value.type,state:u.value,hasChildren:!!(c!=null&&c.length),isMagnetic:!!t.magnetic,style:t.style,magneticOptions:g.value,matchTextSize:t.matchTextSize})}),y=ze(a,v);function x(c){return(k,B)=>`translate(-${c.x*100}%, -${c.y*100}%) ${B}`}function m(){const{follow:c,center:k,offset:B,spring:$,matchTextSize:O,magnetic:Ne,...ee}=t;return ee}return(c,k)=>(e.openBlock(),e.createBlock(e.Teleport,{to:"body"},[e.unref(y)?(e.openBlock(),e.createBlock(e.unref(s.LayoutGroup),{key:0},{default:e.withCtx(()=>[e.createVNode(e.unref(s.MotionConfig),{transition:e.unref(r)?e.unref(Pe):c.transition||e.unref($e)},{default:e.withCtx(()=>{var B,$;return[e.createVNode(e.unref(s.motion).div,e.mergeProps({layout:"","data-motion-cursor":c.follow?"follow":"pointer","data-framer-portal-id":"motion-cursor",initial:"exit",exit:"exit"},{...c.$attrs,...m()},{variants:{pressed:c.follow?{}:{scale:.9},...c.variants,default:{opacity:1,scale:1,...(B=c.variants)==null?void 0:B.default},exit:{opacity:0,scale:0,...($=c.variants)==null?void 0:$.exit}},animate:["default",e.unref(u).type,!e.unref(l)||!c.show?"exit":e.unref(u).isPressed?"pressed":""],"transform-template":x(c.center),style:{borderRadius:c.follow?0:20,zIndex:c.follow?99998:99999,willChange:"transform",contain:"layout",originX:c.center.x,originY:c.center.y,...c.style,width:P.value.width,height:P.value.height,x:e.unref(p).x,y:e.unref(p).y,top:0,left:0,position:"fixed",pointerEvents:"none"}}),{default:e.withCtx(()=>[e.renderSlot(c.$slots,"default")]),_:3},16,["data-motion-cursor","variants","animate","transform-template","style"])]}),_:3},8,["transition"])]),_:3})):e.createCommentVNode("",!0)]))}});function U(n,t,o){const i=s.useMotionValue(0),r=s.useMotionValue(0),a=s.useMotionValue(0);return e.watch(()=>o,d=>{if(typeof d=="number"){s.animate(a,1);const f=()=>{r.set(t*(n.get()-d))};return f(),n.on("change",f)}else s.animate(a,0)},{immediate:!0,flush:"post"}),s.useTransform(()=>s.mix(i.get(),r.get(),a.get()))}function Le(n,t=.1){const o=A(),i=j(),r=e.computed(()=>o.value.targetBoundingBox&&o.value.target===n.value),a=U(i.x,t,r.value?o.value.targetBoundingBox.left+o.value.targetBoundingBox.width/2:void 0),d=U(i.y,t,r.value?o.value.targetBoundingBox.top+o.value.targetBoundingBox.height/2:void 0);return{x:a,y:d}}exports.AnimateNumber=ce;exports.Cursor=Ve;exports.useCursorIsInView=Q;exports.useCursorState=A;exports.useMagneticPull=Le;exports.usePointerPosition=j;
9
+ `,document.head.appendChild(n),()=>{document.head.removeChild(n)}}function de(n){e.watch(n,(t,o,i)=>{const r=t?fe():s.noop;return i(()=>{r()})})}function R(n){return t=>{t.pointerType==="mouse"&&n(t)}}function F(n){return R(t=>{t.button===0&&n(t)})}let T,_;function pe(){T=s.motionValue(0),_=s.motionValue(0);let n=0,t=0;function o(){T.set(n),_.set(t)}typeof window<"u"&&window.addEventListener("pointermove",R(i=>{n=i.clientX,t=i.clientY,s.frame.update(o)}))}function j(){return T||pe(),{x:T,y:_}}function me(n,t){return{x:s.useTransform(()=>n.x.get()+t.value.x),y:s.useTransform(()=>n.y.get()+t.value.y)}}function ye(n){return n.closest("[data-cursor]")}function ge(n){return n.closest('a, button, input[type="button"]:not(:disabled)')}function ve(n){return window.getComputedStyle(n).userSelect==="none"?null:n.closest("p, textarea:not(:disabled), input[type='text']:not(:disabled), h1, h2, h3, h4, h5, h6")}function he(n){let t=ye(n);return t?[t.dataset.cursor,t]:(t=ge(n),t?["pointer",t]:(t=ve(n),t?["text",t]:["default",null]))}let M=null,C={type:"default",isPressed:!1,fontSize:null,targetBoundingBox:null,target:null,theme:null};function we(n){let t=null;if("closest"in n){const o=n.closest("[data-cursor-theme]");o instanceof HTMLElement&&(t=o.dataset.cursorTheme||null)}return t}function xe(){if(typeof window>"u")return{onChange:()=>()=>{}};const n=new Set;function t(f){C={...C,...f},n.forEach(h=>h(C))}const o=F(()=>{C.isPressed||t({isPressed:!0})}),i=F(()=>{C.isPressed&&t({isPressed:!1})}),r=R(({target:f})=>{if(!f)return;const[h,g]=he(f);let v=!1;const u={target:g,theme:we(f)};h!==C.type&&(u.type=h,v=!0),u.theme!==C.theme&&(C.theme=u.theme,v=!0);const l=h==="pointer"&&g?g.getBoundingClientRect():null;if(l!==C.targetBoundingBox&&(u.targetBoundingBox=l,v=!0),h==="text"){const{fontSize:p}=window.getComputedStyle(f),w=p?parseInt(p):null;w!==C.fontSize&&(u.fontSize=w,v=!0)}else C.fontSize&&(u.fontSize=null,v=!0);v&&t(u)});function a(){typeof window>"u"||(window.addEventListener("pointerover",r),window.addEventListener("pointerdown",o),window.addEventListener("pointerup",i))}function d(){window.removeEventListener("pointerover",r),window.removeEventListener("pointerdown",o),window.removeEventListener("pointerup",i)}return{onChange:f=>(n.size||a(),n.add(f),()=>{n.delete(f),n.size||d()})}}function ke(){return M||(M=xe()),M}function A(){const n=e.ref({...C});return e.watch(n,()=>ke().onChange(t=>{n.value=t}),{immediate:!0,flush:"post"}),n}let V=null;function Be(){const n=new Set;function t(){n.forEach(a=>a.show())}function o(){n.forEach(a=>a.hide())}function i(){document.body.addEventListener("mouseenter",t),document.body.addEventListener("mouseleave",o)}function r(){document.body.removeEventListener("mouseenter",t),document.body.removeEventListener("mouseleave",o)}return{on:a=>typeof window>"u"?s.noop:(n.size||i(),n.add(a),()=>{n.delete(a),n.size===0&&r()})}}function Ce(){return V||(V=Be()),V}function Q(n){const t=e.ref(!0);return e.watch(t,()=>Ce().on({show:()=>{t.value||(n(),t.value=!0)},hide:()=>t.value=!1}),{immediate:!0}),t}const H={x:0,y:0},Se={x:.5,y:.5},Pe={duration:0},be={stiffness:1e3,damping:100},$e={duration:.15,ease:[.38,.12,.29,1]},W={magneticOptions:{morph:!0,padding:5,snap:.8}},X=17,Y=31,K=4,Ee=20;function z(n,t,o){const i={width:(o==null?void 0:o.width)??n,height:(o==null?void 0:o.height)??t};return typeof i.width=="number"&&(i.width=`${i.width}px`),typeof i.height=="number"&&(i.height=`${i.height}px`),i}function Ie({type:n,state:t,hasChildren:o,style:i,isMagnetic:r,magneticOptions:a,matchTextSize:d}){const f=r&&t.targetBoundingBox;if(o&&!f)return z("auto","auto",i);const{padding:h,morph:g}=a;switch(n){case"pointer":if(r&&g&&t.targetBoundingBox){const{width:v,height:u}=t.targetBoundingBox;return{width:`${v+h*2}px`,height:`${u+h*2}px`}}return z(Y,Y,i);case"text":return d&&t.fontSize?{width:`${K}px`,height:`${t.fontSize}px`}:z(K,Ee,i);default:return z(X,X,i)}}function ze({x:n,y:t},o){const i=e.ref(n.prev!==void 0||t.prev!==void 0);return e.watch(i,()=>{if(i.value)return;const r=()=>{i.value=!0,o(),a()},a=s.pipe(n.on("change",r),t.on("change",r));return()=>a()},{immediate:!0}),i}function Te(n,t,o){return s.useTransform(()=>s.mix(n.value.get(),t.get(),o.get()))}function G(n,t,o){const i=s.useSpring(0,{stiffness:600,damping:50}),r=s.useMotionValue(0),a=Te(n,i,r);return e.watch(()=>o==null?void 0:o.value,(d,f)=>{d?(!f&&!r.isAnimating()?i.jump(d):i.set(d),s.animate(r,t.value||0)):s.animate(r,0)},{immediate:!0,flush:"sync"}),a}function Me(n,t,o,i){const r=G(e.computed(()=>n.value.x),i,e.computed(()=>o.value.targetBoundingBox?o.value.targetBoundingBox.left+o.value.targetBoundingBox.width/2:void 0)),a=G(e.computed(()=>n.value.y),i,e.computed(()=>o.value.targetBoundingBox?o.value.targetBoundingBox.top+o.value.targetBoundingBox.height/2:void 0));return e.computed(()=>t?{x:r,y:a}:n.value)}const Ve=e.defineComponent({name:"Cursor",inheritAttrs:!1,__name:"Cursor",props:{follow:{type:Boolean,default:!1},center:{default:({follow:n})=>n?H:Se},offset:{default:()=>H},spring:{type:[Boolean,Object],default:({follow:n})=>n?be:!1},matchTextSize:{type:Boolean,default:!0},magnetic:{type:[Boolean,Object],default:!1},transition:{},variants:{},style:{},show:{type:Boolean,default:!0}},setup(n){const t=n,{offset:o,magnetic:i}=e.toRefs(t),r=s.useReducedMotion();de(()=>!r.value&&!t.follow);const a=j(),d=me(a,o),f=s.useSpring(d.x,t.spring||void 0),h=s.useSpring(d.y,t.spring||void 0),g=e.computed(()=>typeof t.magnetic=="object"?{...W.magneticOptions,...t.magnetic}:W.magneticOptions);function v(){const c=d.x.on("change",B=>{f.jump(B),c()}),k=d.y.on("change",B=>{h.jump(B),k()})}const u=A(),l=Q(v),p=Me(e.computed(()=>t.spring?{x:f,y:h}:a),e.computed(()=>!!i.value),u,e.computed(()=>g.value&&g.value.snap)),w=e.useSlots(),P=e.computed(()=>{var B,$;const c=($=(B=w.default)==null?void 0:B.call(w))==null?void 0:$.filter(O=>O.type!==Symbol.for("v-cmt"));return Ie({type:u.value.type,state:u.value,hasChildren:!!(c!=null&&c.length),isMagnetic:!!t.magnetic,style:t.style,magneticOptions:g.value,matchTextSize:t.matchTextSize})}),y=ze(a,v);function x(c){return(k,B)=>`translate(-${c.x*100}%, -${c.y*100}%) ${B}`}function m(){const{follow:c,center:k,offset:B,spring:$,matchTextSize:O,magnetic:Ne,...ee}=t;return ee}return(c,k)=>(e.openBlock(),e.createBlock(e.Teleport,{to:"body"},[e.unref(y)?(e.openBlock(),e.createBlock(e.unref(s.LayoutGroup),{key:0},{default:e.withCtx(()=>[e.createVNode(e.unref(s.MotionConfig),{transition:e.unref(r)?e.unref(Pe):c.transition||e.unref($e)},{default:e.withCtx(()=>{var B,$;return[e.createVNode(e.unref(s.motion).div,e.mergeProps({layout:"","data-motion-cursor":c.follow?"follow":"pointer","data-framer-portal-id":"motion-cursor",initial:"exit",exit:"exit"},{...c.$attrs,...m()},{variants:{pressed:c.follow?{}:{scale:.9},...c.variants,default:{opacity:1,scale:1,...(B=c.variants)==null?void 0:B.default},exit:{opacity:0,scale:0,...($=c.variants)==null?void 0:$.exit}},animate:["default",e.unref(u).type,e.unref(i)&&e.unref(u).targetBoundingBox?"magnetic":"",!e.unref(l)||!c.show?"exit":e.unref(u).isPressed?"pressed":""],"transform-template":x(c.center),style:{borderRadius:c.follow?0:20,zIndex:c.follow?99998:99999,willChange:"transform",contain:"layout",originX:c.center.x,originY:c.center.y,...c.style,width:P.value.width,height:P.value.height,x:e.unref(p).x,y:e.unref(p).y,top:0,left:0,position:"fixed",pointerEvents:"none"}}),{default:e.withCtx(()=>[e.renderSlot(c.$slots,"default")]),_:3},16,["data-motion-cursor","variants","animate","transform-template","style"])]}),_:3},8,["transition"])]),_:3})):e.createCommentVNode("",!0)]))}});function U(n,t,o){const i=s.useMotionValue(0),r=s.useMotionValue(0),a=s.useMotionValue(0);return e.watch(()=>o==null?void 0:o.value,d=>{if(typeof d=="number"){s.animate(a,1);const f=()=>{r.set(t*(n.get()-d))};return f(),n.on("change",f)}else s.animate(a,0)},{immediate:!0,flush:"post"}),s.useTransform(()=>s.mix(i.get(),r.get(),a.get()))}function Le(n,t=.1){const o=A(),i=j(),r=e.computed(()=>o.value.targetBoundingBox&&o.value.target===n.value),a=U(i.x,t,e.computed(()=>r.value?o.value.targetBoundingBox.left+o.value.targetBoundingBox.width/2:void 0)),d=U(i.y,t,e.computed(()=>r.value?o.value.targetBoundingBox.top+o.value.targetBoundingBox.height/2:void 0));return{x:a,y:d}}exports.AnimateNumber=ce;exports.Cursor=Ve;exports.useCursorIsInView=Q;exports.useCursorState=A;exports.useMagneticPull=Le;exports.usePointerPosition=j;
@@ -14,6 +14,7 @@ export interface CursorProps extends HTMMotionProps {
14
14
  style?: MotionProps['style'];
15
15
  show?: boolean;
16
16
  }
17
+ declare const magnetic: import('vue').Ref<boolean | Partial<MagneticOptions>, boolean | Partial<MagneticOptions>>;
17
18
  declare const shouldReduceMotion: import('vue').Ref<boolean, boolean>;
18
19
  declare const state: import('vue').Ref<import('./hooks/use-cursor-state/types').CursorState, import('./hooks/use-cursor-state/types').CursorState>;
19
20
  declare const isInView: import('vue').Ref<boolean, boolean>;
@@ -36,6 +37,7 @@ declare const __VLS_self: import('vue').DefineComponent<CursorProps, {
36
37
  motion: typeof motion;
37
38
  defaultTransition: typeof defaultTransition;
38
39
  skipTransition: typeof skipTransition;
40
+ magnetic: typeof magnetic;
39
41
  shouldReduceMotion: typeof shouldReduceMotion;
40
42
  state: typeof state;
41
43
  isInView: typeof isInView;
@@ -1,11 +1,11 @@
1
- import { defineComponent as R, toRefs as V, computed as l, useSlots as X, createBlock as C, openBlock as z, Teleport as Y, createCommentVNode as H, unref as o, withCtx as c, createVNode as T, mergeProps as L, renderSlot as N } from "vue";
2
- import { useReducedMotion as A, useSpring as B, LayoutGroup as E, MotionConfig as F, motion as G } from "motion-v";
1
+ import { defineComponent as R, toRefs as V, computed as l, useSlots as X, createBlock as B, openBlock as z, Teleport as Y, createCommentVNode as H, unref as t, withCtx as c, createVNode as T, mergeProps as L, renderSlot as N } from "vue";
2
+ import { useReducedMotion as A, useSpring as x, LayoutGroup as E, MotionConfig as F, motion as G } from "motion-v";
3
3
  import { useCursorStyles as q } from "./use-cursor-styles.mjs";
4
4
  import { usePointerPosition as D } from "./hooks/use-pointer-position.mjs";
5
5
  import { useOffset as J } from "./hooks/use-offset.mjs";
6
6
  import { useCursorState as K } from "./hooks/use-cursor-state/index.mjs";
7
7
  import { useCursorIsInView as Q } from "./hooks/use-cursor-in-view.mjs";
8
- import { defaultFollowSpring as U, topLeftPoint as P, centerPoint as W, defaults as x, skipTransition as Z, defaultTransition as _ } from "./config.mjs";
8
+ import { defaultFollowSpring as U, topLeftPoint as P, centerPoint as W, defaults as M, skipTransition as Z, defaultTransition as _ } from "./config.mjs";
9
9
  import { getCursorSize as ee } from "./get-cursor-size.mjs";
10
10
  import { useHasPointerMoved as te } from "./hooks/use-has-pointer-moved.mjs";
11
11
  import { useMagneticTarget as oe } from "./magnetic/use-magnetic-target.mjs";
@@ -15,9 +15,9 @@ const ge = /* @__PURE__ */ R({
15
15
  __name: "Cursor",
16
16
  props: {
17
17
  follow: { type: Boolean, default: !1 },
18
- center: { default: ({ follow: i }) => i ? P : W },
18
+ center: { default: ({ follow: r }) => r ? P : W },
19
19
  offset: { default: () => P },
20
- spring: { type: [Boolean, Object], default: ({ follow: i }) => i ? U : !1 },
20
+ spring: { type: [Boolean, Object], default: ({ follow: r }) => r ? U : !1 },
21
21
  matchTextSize: { type: Boolean, default: !0 },
22
22
  magnetic: { type: [Boolean, Object], default: !1 },
23
23
  transition: {},
@@ -25,54 +25,54 @@ const ge = /* @__PURE__ */ R({
25
25
  style: {},
26
26
  show: { type: Boolean, default: !0 }
27
27
  },
28
- setup(i) {
29
- const n = i, { offset: M, magnetic: O } = V(n), d = A();
30
- q(() => !d.value && !n.follow);
31
- const u = D(), f = J(u, M), g = B(f.x, n.spring || void 0), y = B(f.y, n.spring || void 0), p = l(() => typeof n.magnetic == "object" ? { ...x.magneticOptions, ...n.magnetic } : x.magneticOptions);
32
- function v() {
33
- const e = f.x.on("change", (t) => {
34
- g.jump(t), e();
35
- }), a = f.y.on("change", (t) => {
36
- y.jump(t), a();
28
+ setup(r) {
29
+ const n = r, { offset: O, magnetic: d } = V(n), g = A();
30
+ q(() => !g.value && !n.follow);
31
+ const u = D(), f = J(u, O), y = x(f.x, n.spring || void 0), v = x(f.y, n.spring || void 0), p = l(() => typeof n.magnetic == "object" ? { ...M.magneticOptions, ...n.magnetic } : M.magneticOptions);
32
+ function h() {
33
+ const e = f.x.on("change", (o) => {
34
+ y.jump(o), e();
35
+ }), a = f.y.on("change", (o) => {
36
+ v.jump(o), a();
37
37
  });
38
38
  }
39
- const r = K(), b = Q(v), h = oe(
40
- l(() => n.spring ? { x: g, y } : u),
41
- l(() => !!O.value),
42
- r,
39
+ const i = K(), b = Q(h), w = oe(
40
+ l(() => n.spring ? { x: y, y: v } : u),
41
+ l(() => !!d.value),
42
+ i,
43
43
  l(() => p.value && p.value.snap)
44
- ), m = X(), w = l(() => {
45
- var t, s;
46
- const e = (s = (t = m.default) == null ? void 0 : t.call(m)) == null ? void 0 : s.filter(
47
- (S) => S.type !== Symbol.for("v-cmt")
44
+ ), m = X(), S = l(() => {
45
+ var o, s;
46
+ const e = (s = (o = m.default) == null ? void 0 : o.call(m)) == null ? void 0 : s.filter(
47
+ (C) => C.type !== Symbol.for("v-cmt")
48
48
  );
49
49
  return ee({
50
- type: r.value.type,
51
- state: r.value,
50
+ type: i.value.type,
51
+ state: i.value,
52
52
  hasChildren: !!(e != null && e.length),
53
53
  isMagnetic: !!n.magnetic,
54
54
  style: n.style,
55
55
  magneticOptions: p.value,
56
56
  matchTextSize: n.matchTextSize
57
57
  });
58
- }), j = te(u, v);
58
+ }), j = te(u, h);
59
59
  function $(e) {
60
- return (a, t) => `translate(-${e.x * 100}%, -${e.y * 100}%) ${t}`;
60
+ return (a, o) => `translate(-${e.x * 100}%, -${e.y * 100}%) ${o}`;
61
61
  }
62
62
  function k() {
63
- const { follow: e, center: a, offset: t, spring: s, matchTextSize: S, magnetic: ne, ...I } = n;
63
+ const { follow: e, center: a, offset: o, spring: s, matchTextSize: C, magnetic: ne, ...I } = n;
64
64
  return I;
65
65
  }
66
- return (e, a) => (z(), C(Y, { to: "body" }, [
67
- o(j) ? (z(), C(o(E), { key: 0 }, {
66
+ return (e, a) => (z(), B(Y, { to: "body" }, [
67
+ t(j) ? (z(), B(t(E), { key: 0 }, {
68
68
  default: c(() => [
69
- T(o(F), {
70
- transition: o(d) ? o(Z) : e.transition || o(_)
69
+ T(t(F), {
70
+ transition: t(g) ? t(Z) : e.transition || t(_)
71
71
  }, {
72
72
  default: c(() => {
73
- var t, s;
73
+ var o, s;
74
74
  return [
75
- T(o(G).div, L({
75
+ T(t(G).div, L({
76
76
  layout: "",
77
77
  "data-motion-cursor": e.follow ? "follow" : "pointer",
78
78
  "data-framer-portal-id": "motion-cursor",
@@ -88,14 +88,15 @@ const ge = /* @__PURE__ */ R({
88
88
  default: {
89
89
  opacity: 1,
90
90
  scale: 1,
91
- ...(t = e.variants) == null ? void 0 : t.default
91
+ ...(o = e.variants) == null ? void 0 : o.default
92
92
  },
93
93
  exit: { opacity: 0, scale: 0, ...(s = e.variants) == null ? void 0 : s.exit }
94
94
  },
95
95
  animate: [
96
96
  "default",
97
- o(r).type,
98
- !o(b) || !e.show ? "exit" : o(r).isPressed ? "pressed" : ""
97
+ t(i).type,
98
+ t(d) && t(i).targetBoundingBox ? "magnetic" : "",
99
+ !t(b) || !e.show ? "exit" : t(i).isPressed ? "pressed" : ""
99
100
  ],
100
101
  "transform-template": $(e.center),
101
102
  style: {
@@ -106,10 +107,10 @@ const ge = /* @__PURE__ */ R({
106
107
  originX: e.center.x,
107
108
  originY: e.center.y,
108
109
  ...e.style,
109
- width: w.value.width,
110
- height: w.value.height,
111
- x: o(h).x,
112
- y: o(h).y,
110
+ width: S.value.width,
111
+ height: S.value.height,
112
+ x: t(w).x,
113
+ y: t(w).y,
113
114
  top: 0,
114
115
  left: 0,
115
116
  position: "fixed",
@@ -1,34 +1,34 @@
1
- import { useMotionValue as i, animate as f, useTransform as g, mix as m } from "motion-v";
2
- import { computed as l, watch as d } from "vue";
3
- import { useCursorState as v } from "../hooks/use-cursor-state/index.mjs";
1
+ import { useMotionValue as r, animate as c, useTransform as l, mix as g } from "motion-v";
2
+ import { computed as a, watch as v } from "vue";
3
+ import { useCursorState as d } from "../hooks/use-cursor-state/index.mjs";
4
4
  import { usePointerPosition as B } from "../hooks/use-pointer-position.mjs";
5
- function c(n, u, t) {
6
- const r = i(0), e = i(0), o = i(0);
7
- return d(() => t, (s) => {
8
- if (typeof s == "number") {
9
- f(o, 1);
10
- const a = () => {
11
- e.set(u * (n.get() - s));
5
+ function m(n, u, t) {
6
+ const s = r(0), e = r(0), o = r(0);
7
+ return v(() => t == null ? void 0 : t.value, (i) => {
8
+ if (typeof i == "number") {
9
+ c(o, 1);
10
+ const f = () => {
11
+ e.set(u * (n.get() - i));
12
12
  };
13
- return a(), n.on("change", a);
13
+ return f(), n.on("change", f);
14
14
  } else
15
- f(o, 0);
15
+ c(o, 0);
16
16
  }, {
17
17
  immediate: !0,
18
18
  flush: "post"
19
- }), g(() => m(r.get(), e.get(), o.get()));
19
+ }), l(() => g(s.get(), e.get(), o.get()));
20
20
  }
21
21
  function P(n, u = 0.1) {
22
- const t = v(), r = B(), e = l(() => t.value.targetBoundingBox && t.value.target === n.value), o = c(
23
- r.x,
22
+ const t = d(), s = B(), e = a(() => t.value.targetBoundingBox && t.value.target === n.value), o = m(
23
+ s.x,
24
24
  u,
25
- e.value ? t.value.targetBoundingBox.left + t.value.targetBoundingBox.width / 2 : void 0
26
- ), s = c(
27
- r.y,
25
+ a(() => e.value ? t.value.targetBoundingBox.left + t.value.targetBoundingBox.width / 2 : void 0)
26
+ ), i = m(
27
+ s.y,
28
28
  u,
29
- e.value ? t.value.targetBoundingBox.top + t.value.targetBoundingBox.height / 2 : void 0
29
+ a(() => e.value ? t.value.targetBoundingBox.top + t.value.targetBoundingBox.height / 2 : void 0)
30
30
  );
31
- return { x: o, y: s };
31
+ return { x: o, y: i };
32
32
  }
33
33
  export {
34
34
  P as useMagneticPull
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "motion-plus-vue",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Motion Plus Vue",
5
5
  "author": "",
6
6
  "license": "ISC",