svelte-repel-cursor
Version:
The svelte-repel-cursor provider a action of svelte that repel do it the element repel the cursor
1 lines • 1.59 kB
JavaScript
var t={d:(n,e)=>{for(var r in e)t.o(e,r)&&!t.o(n,r)&&Object.defineProperty(n,r,{enumerable:!0,get:e[r]})},o:(t,n)=>Object.prototype.hasOwnProperty.call(t,n)},n={};t.d(n,{Z:()=>i});var e=new Function("return window"),r=new Function("\n try {\n return this === window;\n } catch {\n return false;\n }\n");const i=function t(n,i){if(!r())return{};if(!i)return{update:function(e){return t(n,e)}};var o={active:!1};!function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=n.duration,r=n.timingFunction,i=n.property,o=t.style;o.setProperty("transition-duration","".concat(e||100,"ms")),o.setProperty("transition-timing-function",r||"linear"),o.setProperty("transition-property",i||"all")}(n,i);var a=i.duration,u=i.length,c=setInterval((function(){return o.active=!0}),function(t){return Math.ceil(.95*t)}(a)),v=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100,r=arguments.length>2?arguments[2]:void 0,i=t.style,o=t.getBoundingClientRect(),a=o.x,u=o.y,c=o.height,v=o.width,s=u+c/2,d=a+v/2,f=Math.round,l=e(),p=l.innerHeight,h=l.innerWidth;return function(t){var e=t.pageY,o=t.pageX;if(r.active){var a=f((s-e)/p*n),u=f((d-o)/h*n);i.setProperty("transform","translate(\n ".concat(u,"px,\n ").concat(a,"px\n )")),r.active=!1}}}(n,u,o);e().addEventListener("mousemove",v);var s=function(t,n){return function(){e().removeEventListener("mousemove",n),clearInterval(t)}}(c,v);return{update:function(e){return s(),t(n,e)},destroy:function(){return s()}}};var o=n.Z;export{o as default};