@sidharth-anand/neodrag-svelte
Advanced tools
Comparing version 1.1.5 to 1.1.6
@@ -1,2 +0,2 @@ | ||
function e(e,t,n,o){var r,i=null==(r=o)||"number"==typeof r||"boolean"==typeof r?o:n(o),a=t.get(i);return void 0===a&&(a=e.call(this,o),t.set(i,a)),a}function t(e,t,n){var o=Array.prototype.slice.call(arguments,3),r=n(o),i=t.get(r);return void 0===i&&(i=e.apply(this,o),t.set(r,i)),i}function n(n,o){return function(e,t,n,o,r){return n.bind(t,e,o,r)}(n,this,1===n.length?e:t,o.cache.create(),o.serializer)}const o=JSON.stringify;function r(){this.cache=Object.create(null)}r.prototype.has=function(e){return e in this.cache},r.prototype.get=function(e){return this.cache[e]},r.prototype.set=function(e,t){this.cache[e]=t};var i={create:function(){return new r}};const a=(e,t={})=>{let{bounds:n,axis:o="both",gpuAcceleration:r=!0,applyUserSelectHack:i=!0,disabled:a=!1,ignoreMultitouch:d=!1,grid:h,position:f,cancel:g,handle:y,defaultClass:b="neodrag",defaultClassDragging:w="neodrag-dragging",defaultClassDragged:v="neodrag-dragged",defaultPosition:E={x:0,y:0},onDragStart:A,onDrag:x,onDragEnd:C}=t;const M=new Promise(requestAnimationFrame);let S,H,L=!1,D=0,N=0,R=0,T=0,B=0,q=0,{x:$,y:z}=f?{x:f?.x??0,y:f?.y??0}:E;m($,z,e,r);let X,Y,j,k,O="",P=!!f;const U=document.body.style,W=e.classList,F=(t,n)=>{const o={offsetX:D,offsetY:N,domRect:e.getBoundingClientRect()};e.dispatchEvent(new CustomEvent(t,{detail:o})),n?.(o)};const J=addEventListener;J("touchstart",I,!1),J("touchend",K,!1),J("touchmove",Q,!1),J("mousedown",I,!1),J("mouseup",K,!1),J("mousemove",Q,!1),e.style.touchAction="none";const G=()=>{let t=e.offsetWidth/Y.width;return isNaN(t)&&(t=1),t};function I(t){if(a)return;if(d&&"touchstart"===t.type&&t.touches.length>1)return;if(W.add(b),j=function(e,t){if(!e)return t;if(e instanceof HTMLElement||Array.isArray(e))return e;const n=t.querySelectorAll(e);if(null===n)throw new Error("Selector passed for `handle` option should be child of the element on which the action is applied");return Array.from(n.values())}(y,e),k=function(e,t){if(!e)return;if(e instanceof HTMLElement||Array.isArray(e))return e;const n=t.querySelectorAll(e);if(null===n)throw new Error("Selector passed for `cancel` option should be child of the element on which the action is applied");return Array.from(n.values())}(g,e),S=/(both|x)/.test(o),H=/(both|y)/.test(o),void 0!==n&&(X=function(e,t){if(e instanceof HTMLElement)return e.getBoundingClientRect();if("object"==typeof e){const{top:t=0,left:n=0,right:o=0,bottom:r=0}=e;return{top:t,right:window.innerWidth-o,bottom:window.innerHeight-r,left:n}}if("parent"===e)return t.parentNode.getBoundingClientRect();const n=document.querySelector(e);if(null===n)throw new Error("The selector provided for bound doesn't exists in the document.");return n.getBoundingClientRect()}(n,e)),Y=e.getBoundingClientRect(),l(y)&&l(g)&&y===g)throw new Error("`handle` selector can't be same as `cancel` selector");if(p(k,j))throw new Error("Element being dragged can't be a child of the element on which `cancel` is applied");if((j instanceof HTMLElement?j.contains(t.target):j.some((e=>e.contains(t.target))))&&!p(k,t.target)&&(L=!0),!L)return;i&&(O=U.userSelect,U.userSelect="none"),F("neodrag:start",A);const{clientX:r,clientY:c}=s(t)?t.touches[0]:t,u=G();S&&(R=r-$/u),H&&(T=c-z/u),X&&(B=r-Y.left,q=c-Y.top)}function K(){L&&(W.remove(w),W.add(v),i&&(U.userSelect=O),F("neodrag:end",C),S&&(R=D),S&&(T=N),L=!1)}function Q(t){if(!L)return;W.add(w),t.preventDefault(),Y=e.getBoundingClientRect();const{clientX:n,clientY:o}=s(t)?t.touches[0]:t;let i=n,a=o;const l=G();if(X){const e={left:X.left+B,top:X.top+q,right:X.right+B-Y.width,bottom:X.bottom+q-Y.height};i=c(i,e.left,e.right),a=c(a,e.top,e.bottom)}if(Array.isArray(h)){let[e,t]=h;if(isNaN(+e)||e<0)throw new Error("1st argument of `grid` must be a valid positive number");if(isNaN(+t)||t<0)throw new Error("2nd argument of `grid` must be a valid positive number");let n=i-R,o=a-T;[n,o]=u([Math.floor(e/l),Math.floor(t/l)],n,o),i=R+n,a=T+o}S&&(D=(i-R)*l),H&&(N=(a-T)*l),$=D,z=N,F("neodrag",x),M.then((()=>m(D,N,e,r)))}return{destroy:()=>{const e=removeEventListener;e("touchstart",I,!1),e("touchend",K,!1),e("touchmove",Q,!1),e("mousedown",I,!1),e("mouseup",K,!1),e("mousemove",Q,!1)},update:t=>{o=t.axis||"both",a=t.disabled??!1,d=t.ignoreMultitouch??!1,y=t.handle,n=t.bounds,g=t.cancel,i=t.applyUserSelectHack??!0,h=t.grid,r=t.gpuAcceleration??!0;const s=W.contains(v);W.remove(b,v),b=t.defaultClass??"neodrag",w=t.defaultClassDragging??"neodrag-dragging",v=t.defaultClassDragged??"neodrag-dragged",W.add(b),s&&W.add(v),P&&($=D=t.position?.x??D,z=N=t.position?.y??N,M.then((()=>m(D,N,e,r))))}}},s=e=>!!e.touches?.length,c=(e,t,n)=>Math.min(Math.max(e,t),n),l=e=>"string"==typeof e,u=(d=([e,t],n,o)=>{const r=(e,t)=>Math.round(e/t)*t;return[r(n||1,e),r(o||1,t)]},f=h?.cache??i,g=h?.serializer??o,(h?.strategy??n)(d,{cache:f,serializer:g}));var d,h,f,g;function p(e,t){const n=t instanceof HTMLElement?[t]:t;return e instanceof HTMLElement?n.some((t=>e.contains(t))):!!Array.isArray(e)&&e.some((e=>n.some((t=>e.contains(t)))))}function m(e,t,n,o){n.style.transform=o?`translate3d(${+e}px, ${+t}px, 0)`:`translate(${+e}px, ${+t}px)`}export{a as draggable}; | ||
function e(e,t,n,o){var r,i=null==(r=o)||"number"==typeof r||"boolean"==typeof r?o:n(o),a=t.get(i);return void 0===a&&(a=e.call(this,o),t.set(i,a)),a}function t(e,t,n){var o=Array.prototype.slice.call(arguments,3),r=n(o),i=t.get(r);return void 0===i&&(i=e.apply(this,o),t.set(r,i)),i}function n(n,o){return function(e,t,n,o,r){return n.bind(t,e,o,r)}(n,this,1===n.length?e:t,o.cache.create(),o.serializer)}const o=JSON.stringify;function r(){this.cache=Object.create(null)}r.prototype.has=function(e){return e in this.cache},r.prototype.get=function(e){return this.cache[e]},r.prototype.set=function(e,t){this.cache[e]=t};var i={create:function(){return new r}};const a=(e,t={})=>{let{bounds:n,axis:o="both",gpuAcceleration:r=!0,applyUserSelectHack:i=!0,disabled:a=!1,ignoreMultitouch:d=!1,grid:h,position:f,cancel:g,handle:y,defaultClass:b="neodrag",defaultClassDragging:w="neodrag-dragging",defaultClassDragged:v="neodrag-dragged",defaultPosition:E={x:0,y:0},onDragStart:A,onDrag:x,onDragEnd:C}=t;const M=new Promise(requestAnimationFrame);let S,H,L=!1,D=0,N=0,R=0,T=0,B=0,q=0,{x:$,y:z}=f?{x:f?.x??0,y:f?.y??0}:E;m($,z,e,r);let X,Y,j,k,O="",P=!!f;const U=document.body.style,W=e.classList,F=(t,n)=>{const o={offsetX:D,offsetY:N,domRect:e.getBoundingClientRect()};e.dispatchEvent(new CustomEvent(t,{detail:o})),n?.(o)};const J=addEventListener;J("touchstart",I,!1),J("touchend",K,!1),J("touchmove",Q,!1),J("mousedown",I,!1),J("mouseup",K,!1),J("mousemove",Q,!1),e.style.touchAction="none";const G=()=>{let t=e.offsetWidth/Y.width;return isNaN(t)&&(t=1),t};function I(t){if(a)return;if(d&&"touchstart"===t.type&&t.touches.length>1)return;if(W.add(b),j=function(e,t){if(!e)return t;if(e instanceof HTMLElement||Array.isArray(e))return e;const n=t.querySelectorAll(e);if(null===n)throw new Error("Selector passed for `handle` option should be child of the element on which the action is applied");return Array.from(n.values())}(y,e),k=function(e,t){if(!e)return;if(e instanceof HTMLElement||Array.isArray(e))return e;const n=t.querySelectorAll(e);if(null===n)throw new Error("Selector passed for `cancel` option should be child of the element on which the action is applied");return Array.from(n.values())}(g,e),S=/(both|x)/.test(o),H=/(both|y)/.test(o),void 0!==n&&(X=function(e,t){if(e instanceof HTMLElement)return e.getBoundingClientRect();if("object"==typeof e){const{top:t=0,left:n=0,right:o=0,bottom:r=0}=e;return{top:t,right:window.innerWidth-o,bottom:window.innerHeight-r,left:n}}if("parent"===e)return t.parentNode.getBoundingClientRect();const n=document.querySelector(e);if(null===n)throw new Error("The selector provided for bound doesn't exists in the document.");return n.getBoundingClientRect()}(n,e)),Y=e.getBoundingClientRect(),l(y)&&l(g)&&y===g)throw new Error("`handle` selector can't be same as `cancel` selector");if(p(k,j))throw new Error("Element being dragged can't be a child of the element on which `cancel` is applied");if((j instanceof HTMLElement?j.contains(t.target):j.some((e=>e.contains(t.target))))&&!p(k,t.target)&&(L=!0),!L)return;i&&(O=U.userSelect,U.userSelect="none"),F("neodrag:start",A);const{clientX:r,clientY:c}=s(t)?t.touches[0]:t,u=G();S&&(R=r-$/u),H&&(T=c-z/u),X&&(B=r-Y.left,q=c-Y.top)}function K(){L&&(W.remove(w),W.add(v),i&&(U.userSelect=O),F("neodrag:end",C),S&&(R=D),S&&(T=N),L=!1)}function Q(t){if(!L)return;W.add(w),t.preventDefault(),Y=e.getBoundingClientRect();const{clientX:n,clientY:o}=s(t)?t.touches[0]:t;let i=n,a=o;const l=G();if(X){const e={left:X.left+B,top:X.top+q,right:X.right+B-Y.width,bottom:X.bottom+q-Y.height};i=c(i,e.left,e.right),a=c(a,e.top,e.bottom)}if(Array.isArray(h)){let[e,t]=h;if(isNaN(+e)||e<0)throw new Error("1st argument of `grid` must be a valid positive number");if(isNaN(+t)||t<0)throw new Error("2nd argument of `grid` must be a valid positive number");let n=i-R,o=a-T;[n,o]=u([Math.floor(e/l),Math.floor(t/l)],n,o),i=R+n,a=T+o}S&&(D=(i-R)*l),H&&(N=(a-T)*l),$=D,z=N,F("neodrag",x),M.then((()=>m(D,N,e,r)))}return{destroy:()=>{const e=removeEventListener;e("touchstart",I,!1),e("touchend",K,!1),e("touchmove",Q,!1),e("mousedown",I,!1),e("mouseup",K,!1),e("mousemove",Q,!1)},update:t=>{o=t.axis||"both",a=t.disabled??!1,d=t.ignoreMultitouch??!1,y=t.handle,n=t.bounds,g=t.cancel,i=t.applyUserSelectHack??!0,h=t.grid,r=t.gpuAcceleration??!0;const s=W.contains(v);W.remove(b,v),b=t.defaultClass??"neodrag",w=t.defaultClassDragging??"neodrag-dragging",v=t.defaultClassDragged??"neodrag-dragged",W.add(b),s&&W.add(v),P&&($=D=t.position?.x??D,z=N=t.position?.y??N,M.then((()=>m(D,N,e,r))))}}},s=e=>!!e.touches?.length,c=(e,t,n)=>Math.min(Math.max(e,t),n),l=e=>"string"==typeof e,u=(d=([e,t],n,o)=>{const r=(e,t)=>Math.round(e/t)*t;return[r(n,e||1),r(o,t||1)]},f=h?.cache??i,g=h?.serializer??o,(h?.strategy??n)(d,{cache:f,serializer:g}));var d,h,f,g;function p(e,t){const n=t instanceof HTMLElement?[t]:t;return e instanceof HTMLElement?n.some((t=>e.contains(t))):!!Array.isArray(e)&&e.some((e=>n.some((t=>e.contains(t)))))}function m(e,t,n,o){n.style.transform=o?`translate3d(${+e}px, ${+t}px, 0)`:`translate(${+e}px, ${+t}px)`}export{a as draggable}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@sidharth-anand/neodrag-svelte", | ||
"version": "1.1.5", | ||
"version": "1.1.6", | ||
"description": "Svelte Action to add dragging to your apps 😉", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet