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