@interactjs/modifiers
Advanced tools
Comparing version 1.9.17 to 1.9.18
@@ -1,2 +0,2 @@ | ||
import t from"../utils/clone.min.js";import e from"../utils/extend.min.js";import*as s from"../utils/rect.min.js";export default class o{constructor(t){this.states=[],this.startOffset={left:0,right:0,top:0,bottom:0},this.startDelta=null,this.result=null,this.endResult=null,this.edges=void 0,this.interaction=void 0,this.interaction=t,this.result=r()}start({phase:t},s){const{interaction:o}=this,i=function(t){const e=t.interactable.options[t.prepared.name],s=e.modifiers;if(s&&s.length)return s.filter(t=>!t.options||!1!==t.options.enabled);return["snap","snapSize","snapEdges","restrict","restrictEdges","restrictSize"].map(t=>{const s=e[t];return s&&s.enabled&&{options:s,methods:s._methods}}).filter(t=>!!t)}(o);this.prepareStates(i),this.edges=e({},o.edges),this.startOffset=getRectOffset(o.rect,s),this.startDelta={x:0,y:0};const n={phase:t,pageCoords:s,preEnd:!1};return this.result=r(),this.startAll(n),this.result=this.setAll(n)}fillArg(t){const{interaction:e}=this;t.interaction=e,t.interactable=e.interactable,t.element=e.element,t.rect=t.rect||e.rect,t.edges=this.edges,t.startOffset=this.startOffset}startAll(t){this.fillArg(t);for(const e of this.states)e.methods.start&&(t.state=e,e.methods.start(t))}setAll(t){this.fillArg(t);const{phase:o,preEnd:i,skipModifiers:n,rect:a}=t;t.coords=e({},t.pageCoords),t.rect=e({},a);const l=n?this.states.slice(n):this.states,c=r(t.coords,t.rect);for(const r of l){const{options:n}=r,a=e({},t.coords);let l=null;r.methods.set&&this.shouldDo(n,i,o)&&(t.state=r,l=r.methods.set(t),s.addEdges(this.interaction.edges,t.rect,{x:t.coords.x-a.x,y:t.coords.y-a.y})),c.eventProps.push(l)}c.delta.x=t.coords.x-t.pageCoords.x,c.delta.y=t.coords.y-t.pageCoords.y,c.rectDelta.left=t.rect.left-a.left,c.rectDelta.right=t.rect.right-a.right,c.rectDelta.top=t.rect.top-a.top,c.rectDelta.bottom=t.rect.bottom-a.bottom;const h=this.result.coords,d=this.result.rect;if(h&&d){const t=c.rect.left!==d.left||c.rect.right!==d.right||c.rect.top!==d.top||c.rect.bottom!==d.bottom;c.changed=t||h.x!==c.coords.x||h.y!==c.coords.y}return c}applyToInteraction(t){const{interaction:s}=this,{phase:o}=t,r=s.coords.cur,i=s.coords.start,{result:n,startDelta:a}=this,l=n.delta;"start"===o&&e(this.startDelta,n.delta);for(const[t,e]of[[i,a],[r,l]])t.page.x+=e.x,t.page.y+=e.y,t.client.x+=e.x,t.client.y+=e.y;const{rectDelta:c}=this.result,h=t.rect||s.rect;h.left+=c.left,h.right+=c.right,h.top+=c.top,h.bottom+=c.bottom,h.width=h.right-h.left,h.height=h.bottom-h.top}setAndApply(t){const{interaction:e}=this,{phase:s,preEnd:o,skipModifiers:r}=t,i=this.setAll({preEnd:o,phase:s,pageCoords:t.modifiedCoords||e.coords.cur.page});if(this.result=i,!i.changed&&(!r||r<this.states.length)&&e.interacting())return!1;if(t.modifiedCoords){const{page:s}=e.coords.cur,o={x:t.modifiedCoords.x-s.x,y:t.modifiedCoords.y-s.y};i.coords.x+=o.x,i.coords.y+=o.y,i.delta.x+=o.x,i.delta.y+=o.y}this.applyToInteraction(t)}beforeEnd(t){const{interaction:e,event:s}=t,o=this.states;if(!o||!o.length)return;let r=!1;for(const e of o){t.state=e;const{options:s,methods:o}=e,i=o.beforeEnd&&o.beforeEnd(t);if(i)return this.endResult=i,!1;r=r||!r&&this.shouldDo(s,!0,t.phase,!0)}r&&e.move({event:s,preEnd:!0})}stop(t){const{interaction:s}=t;if(!this.states||!this.states.length)return;const o=e({states:this.states,interactable:s.interactable,element:s.element,rect:null},t);this.fillArg(o);for(const t of this.states)o.state=t,t.methods.stop&&t.methods.stop(o);this.states=null,this.endResult=null}prepareStates(t){this.states=[];for(let e=0;e<t.length;e++){const{options:s,methods:o,name:r}=t[e];s&&!1===s.enabled||this.states.push({options:s,methods:o,index:e,name:r})}return this.states}restoreInteractionCoords({interaction:{coords:t,rect:e,modification:s}}){if(!s.result)return;const{startDelta:o}=s,{delta:r,rectDelta:i}=s.result,n=[[t.start,o],[t.cur,r]];for(const[t,e]of n)t.page.x-=e.x,t.page.y-=e.y,t.client.x-=e.x,t.client.y-=e.y;e.left-=i.left,e.right-=i.right,e.top-=i.top,e.bottom-=i.bottom}shouldDo(t,e,s,o){return!(!t||!1===t.enabled||o&&!t.endOnly||t.endOnly&&!e||"start"===s&&!t.setStart)}copyFrom(s){this.startOffset=s.startOffset,this.startDelta=s.startDelta,this.edges=s.edges,this.states=s.states.map(e=>t(e)),this.result=r(e({},s.result.coords),e({},s.result.rect))}destroy(){for(const t in this)this[t]=null}}function r(t,e){return{rect:e,coords:t,delta:{x:0,y:0},rectDelta:{left:0,right:0,top:0,bottom:0},eventProps:[],changed:!0}}export function getRectOffset(t,e){return t?{left:e.x-t.left,top:e.y-t.top,right:t.right-e.x,bottom:t.bottom-e.y}:{left:0,top:0,right:0,bottom:0}} | ||
import t from"../utils/clone.min.js";import e from"../utils/extend.min.js";import*as s from"../utils/rect.min.js";export default class o{constructor(t){this.states=[],this.startOffset={left:0,right:0,top:0,bottom:0},this.startDelta=null,this.result=null,this.endResult=null,this.edges=void 0,this.interaction=void 0,this.interaction=t,this.result=r()}start({phase:t},s){const{interaction:o}=this,i=function(t){const e=t.interactable.options[t.prepared.name],s=e.modifiers;if(s&&s.length)return s.filter(t=>!t.options||!1!==t.options.enabled);return["snap","snapSize","snapEdges","restrict","restrictEdges","restrictSize"].map(t=>{const s=e[t];return s&&s.enabled&&{options:s,methods:s._methods}}).filter(t=>!!t)}(o);this.prepareStates(i),this.edges=e({},o.edges),this.startOffset=getRectOffset(o.rect,s),this.startDelta={x:0,y:0};const n={phase:t,pageCoords:s,preEnd:!1};this.result=r(),this.startAll(n);return this.result=this.setAll(n)}fillArg(t){const{interaction:e}=this;t.interaction=e,t.interactable=e.interactable,t.element=e.element,t.rect=t.rect||e.rect,t.edges=this.edges,t.startOffset=this.startOffset}startAll(t){this.fillArg(t);for(const e of this.states)e.methods.start&&(t.state=e,e.methods.start(t))}setAll(t){this.fillArg(t);const{phase:o,preEnd:i,skipModifiers:n,rect:a}=t;t.coords=e({},t.pageCoords),t.rect=e({},a);const l=n?this.states.slice(n):this.states,c=r(t.coords,t.rect);for(const r of l){const{options:n}=r,a=e({},t.coords);let l=null;r.methods.set&&this.shouldDo(n,i,o)&&(t.state=r,l=r.methods.set(t),s.addEdges(this.interaction.edges,t.rect,{x:t.coords.x-a.x,y:t.coords.y-a.y})),c.eventProps.push(l)}c.delta.x=t.coords.x-t.pageCoords.x,c.delta.y=t.coords.y-t.pageCoords.y,c.rectDelta.left=t.rect.left-a.left,c.rectDelta.right=t.rect.right-a.right,c.rectDelta.top=t.rect.top-a.top,c.rectDelta.bottom=t.rect.bottom-a.bottom;const h=this.result.coords,d=this.result.rect;if(h&&d){const t=c.rect.left!==d.left||c.rect.right!==d.right||c.rect.top!==d.top||c.rect.bottom!==d.bottom;c.changed=t||h.x!==c.coords.x||h.y!==c.coords.y}return c}applyToInteraction(t){const{interaction:s}=this,{phase:o}=t,r=s.coords.cur,i=s.coords.start,{result:n,startDelta:a}=this,l=n.delta;"start"===o&&e(this.startDelta,n.delta);for(const[t,e]of[[i,a],[r,l]])t.page.x+=e.x,t.page.y+=e.y,t.client.x+=e.x,t.client.y+=e.y;const{rectDelta:c}=this.result,h=t.rect||s.rect;h.left+=c.left,h.right+=c.right,h.top+=c.top,h.bottom+=c.bottom,h.width=h.right-h.left,h.height=h.bottom-h.top}setAndApply(t){const{interaction:e}=this,{phase:s,preEnd:o,skipModifiers:r}=t,i=this.setAll({preEnd:o,phase:s,pageCoords:t.modifiedCoords||e.coords.cur.page});if(this.result=i,!i.changed&&(!r||r<this.states.length)&&e.interacting())return!1;if(t.modifiedCoords){const{page:s}=e.coords.cur,o={x:t.modifiedCoords.x-s.x,y:t.modifiedCoords.y-s.y};i.coords.x+=o.x,i.coords.y+=o.y,i.delta.x+=o.x,i.delta.y+=o.y}this.applyToInteraction(t)}beforeEnd(t){const{interaction:e,event:s}=t,o=this.states;if(!o||!o.length)return;let r=!1;for(const e of o){t.state=e;const{options:s,methods:o}=e,i=o.beforeEnd&&o.beforeEnd(t);if(i)return this.endResult=i,!1;r=r||!r&&this.shouldDo(s,!0,t.phase,!0)}r&&e.move({event:s,preEnd:!0})}stop(t){const{interaction:s}=t;if(!this.states||!this.states.length)return;const o=e({states:this.states,interactable:s.interactable,element:s.element,rect:null},t);this.fillArg(o);for(const t of this.states)o.state=t,t.methods.stop&&t.methods.stop(o);this.states=null,this.endResult=null}prepareStates(t){this.states=[];for(let e=0;e<t.length;e++){const{options:s,methods:o,name:r}=t[e];s&&!1===s.enabled||this.states.push({options:s,methods:o,index:e,name:r})}return this.states}restoreInteractionCoords({interaction:{coords:t,rect:e,modification:s}}){if(!s.result)return;const{startDelta:o}=s,{delta:r,rectDelta:i}=s.result,n=[[t.start,o],[t.cur,r]];for(const[t,e]of n)t.page.x-=e.x,t.page.y-=e.y,t.client.x-=e.x,t.client.y-=e.y;e.left-=i.left,e.right-=i.right,e.top-=i.top,e.bottom-=i.bottom}shouldDo(t,e,s,o){return!(!t||!1===t.enabled||o&&!t.endOnly||t.endOnly&&!e||"start"===s&&!t.setStart)}copyFrom(s){this.startOffset=s.startOffset,this.startDelta=s.startDelta,this.edges=s.edges,this.states=s.states.map(e=>t(e)),this.result=r(e({},s.result.coords),e({},s.result.rect))}destroy(){for(const t in this)this[t]=null}}function r(t,e){return{rect:e,coords:t,delta:{x:0,y:0},rectDelta:{left:0,right:0,top:0,bottom:0},eventProps:[],changed:!0}}export function getRectOffset(t,e){return t?{left:e.x-t.left,top:e.y-t.top,right:t.right-e.x,bottom:t.bottom-e.y}:{left:0,top:0,right:0,bottom:0}} | ||
//# sourceMappingURL=Modification.min.js.map |
{ | ||
"name": "@interactjs/modifiers", | ||
"version": "1.9.17", | ||
"version": "1.9.18", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@interactjs/snappers": "1.9.17" | ||
"@interactjs/snappers": "1.9.18" | ||
}, | ||
"peerDependencies": { | ||
"@interactjs/core": "1.9.17", | ||
"@interactjs/utils": "1.9.17" | ||
"@interactjs/core": "1.9.18", | ||
"@interactjs/utils": "1.9.18" | ||
}, | ||
"optionalDependencies": { | ||
"@interactjs/interact": "1.9.17" | ||
"@interactjs/interact": "1.9.18" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"gitHead": "1f894f19" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import t from"../../utils/extend.min.js";import e from"../../utils/getOriginXY.min.js";import n from"../../utils/hypot.min.js";import r from"../../utils/is.min.js";import{resolveRectLike as i,rectToXY as o}from"../../utils/rect.min.js";import{makeModifier as s}from"../base";const a={start(n){const{interaction:r,interactable:s,element:a,rect:l,state:f,startOffset:g}=n,{options:c}=f,x=c.offsetWithOrigin?function(t){const{element:n}=t.interaction;return o(i(t.state.options.origin,null,null,[n]))||e(t.interactable,n,t.interaction.prepared.name)}(n):{x:0,y:0};let m;if("startCoords"===c.offset)m={x:r.coords.start.page.x,y:r.coords.start.page.y};else{const t=i(c.offset,s,a,[r]);m=o(t)||{x:0,y:0},m.x+=x.x,m.y+=x.y}const{relativePoints:y}=c;f.offsets=l&&y&&y.length?y.map((t,e)=>({index:e,relativePoint:t,x:g.left-l.width*t.x+m.x,y:g.top-l.height*t.y+m.y})):[t({index:0,relativePoint:null},m)]},set(i){const{interaction:o,coords:s,state:a}=i,{options:l,offsets:f}=a,g=e(o.interactable,o.element,o.prepared.name),c=t({},s),x=[];l.offsetWithOrigin||(c.x-=g.x,c.y-=g.y);for(const t of f){const e=c.x-t.x,n=c.y-t.y;for(let i=0,s=l.targets.length;i<s;i++){const s=l.targets[i];let a;a=r.func(s)?s(e,n,o._proxy,t,i):s,a&&x.push({x:(r.number(a.x)?a.x:e)+t.x,y:(r.number(a.y)?a.y:n)+t.y,range:r.number(a.range)?a.range:l.range,source:s,index:i,offset:t})}}const m={target:null,inRange:!1,distance:0,range:0,delta:{x:0,y:0}};for(const t of x){const e=t.range,r=t.x-c.x,i=t.y-c.y,o=n(r,i);let s=o<=e;e===1/0&&m.inRange&&m.range!==1/0&&(s=!1),m.target&&!(s?m.inRange&&e!==1/0?o/e<m.distance/m.range:e===1/0&&m.range!==1/0||o<m.distance:!m.inRange&&o<m.distance)||(m.target=t,m.distance=o,m.range=e,m.inRange=s,m.delta.x=r,m.delta.y=i)}return m.inRange&&(s.x=m.target.x,s.y=m.target.y),a.closest=m,m},defaults:{range:1/0,targets:null,offset:null,offsetWithOrigin:!0,origin:null,relativePoints:null,endOnly:!1,enabled:!1}};export default s(a,"snap");export{a as snap}; | ||
import t from"../../utils/extend.min.js";import e from"../../utils/getOriginXY.min.js";import n from"../../utils/hypot.min.js";import r from"../../utils/is.min.js";import{resolveRectLike as i,rectToXY as o}from"../../utils/rect.min.js";import{makeModifier as s}from"../base";const a={start(n){const{interaction:r,interactable:s,element:a,rect:l,state:f,startOffset:g}=n,{options:c}=f,x=c.offsetWithOrigin?function(t){const{element:n}=t.interaction,r=o(i(t.state.options.origin,null,null,[n]));return r||e(t.interactable,n,t.interaction.prepared.name)}(n):{x:0,y:0};let m;if("startCoords"===c.offset)m={x:r.coords.start.page.x,y:r.coords.start.page.y};else{const t=i(c.offset,s,a,[r]);m=o(t)||{x:0,y:0},m.x+=x.x,m.y+=x.y}const{relativePoints:y}=c;f.offsets=l&&y&&y.length?y.map((t,e)=>({index:e,relativePoint:t,x:g.left-l.width*t.x+m.x,y:g.top-l.height*t.y+m.y})):[t({index:0,relativePoint:null},m)]},set(i){const{interaction:o,coords:s,state:a}=i,{options:l,offsets:f}=a,g=e(o.interactable,o.element,o.prepared.name),c=t({},s),x=[];l.offsetWithOrigin||(c.x-=g.x,c.y-=g.y);for(const t of f){const e=c.x-t.x,n=c.y-t.y;for(let i=0,s=l.targets.length;i<s;i++){const s=l.targets[i];let a;a=r.func(s)?s(e,n,o._proxy,t,i):s,a&&x.push({x:(r.number(a.x)?a.x:e)+t.x,y:(r.number(a.y)?a.y:n)+t.y,range:r.number(a.range)?a.range:l.range,source:s,index:i,offset:t})}}const m={target:null,inRange:!1,distance:0,range:0,delta:{x:0,y:0}};for(const t of x){const e=t.range,r=t.x-c.x,i=t.y-c.y,o=n(r,i);let s=o<=e;e===1/0&&m.inRange&&m.range!==1/0&&(s=!1),m.target&&!(s?m.inRange&&e!==1/0?o/e<m.distance/m.range:e===1/0&&m.range!==1/0||o<m.distance:!m.inRange&&o<m.distance)||(m.target=t,m.distance=o,m.range=e,m.inRange=s,m.delta.x=r,m.delta.y=i)}return m.inRange&&(s.x=m.target.x,s.y=m.target.y),a.closest=m,m},defaults:{range:1/0,targets:null,offset:null,offsetWithOrigin:!0,origin:null,relativePoints:null,endOnly:!1,enabled:!1}};export default s(a,"snap");export{a as snap}; | ||
//# sourceMappingURL=pointer.min.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
210259
+ Added@interactjs/core@1.9.18(transitive)
+ Added@interactjs/interact@1.9.18(transitive)
+ Added@interactjs/snappers@1.9.18(transitive)
+ Added@interactjs/utils@1.9.18(transitive)
- Removed@interactjs/core@1.9.17(transitive)
- Removed@interactjs/interact@1.9.17(transitive)
- Removed@interactjs/snappers@1.9.17(transitive)
- Removed@interactjs/utils@1.9.17(transitive)
Updated@interactjs/snappers@1.9.18