5 lines
5.0 KiB
JavaScript
5 lines
5.0 KiB
JavaScript
/* interact.js 1.10.27 | https://raw.github.com/taye/interact.js/main/LICENSE */
|
|
|
|
import clone from"../utils/clone.prod.js";import extend from"../utils/extend.prod.js";import*as rectUtils from"../utils/rect.prod.js";class Modification{constructor(t){this.states=[],this.startOffset={left:0,right:0,top:0,bottom:0},this.startDelta=void 0,this.result=void 0,this.endResult=void 0,this.startEdges=void 0,this.edges=void 0,this.interaction=void 0,this.interaction=t,this.result=createResult(),this.edges={left:!1,right:!1,top:!1,bottom:!1}}start(t,e){let{phase:s}=t;const{interaction:o}=this,r=getModifierList(o);this.prepareStates(r),this.startEdges=extend({},o.edges),this.edges=extend({},this.startEdges),this.startOffset=getRectOffset(o.rect,e),this.startDelta={x:0,y:0};const i=this.fillArg({phase:s,pageCoords:e,preEnd:!1});this.result=createResult(),this.startAll(i);return this.result=this.setAll(i)}fillArg(t){const{interaction:e}=this;return t.interaction=e,t.interactable=e.interactable,t.element=e.element,t.rect||(t.rect=e.rect),t.edges||(t.edges=this.startEdges),t.startOffset=this.startOffset,t}startAll(t){for(const e of this.states)e.methods.start&&(t.state=e,e.methods.start(t))}setAll(t){const{phase:e,preEnd:s,skipModifiers:o,rect:r,edges:i}=t;t.coords=extend({},t.pageCoords),t.rect=extend({},r),t.edges=extend({},i);const n=o?this.states.slice(o):this.states,a=createResult(t.coords,t.rect);for(const o of n){var d;const{options:r}=o,i=extend({},t.coords);let n=null;null!=(d=o.methods)&&d.set&&this.shouldDo(r,s,e)&&(t.state=o,n=o.methods.set(t),rectUtils.addEdges(t.edges,t.rect,{x:t.coords.x-i.x,y:t.coords.y-i.y})),a.eventProps.push(n)}extend(this.edges,t.edges),a.delta.x=t.coords.x-t.pageCoords.x,a.delta.y=t.coords.y-t.pageCoords.y,a.rectDelta.left=t.rect.left-r.left,a.rectDelta.right=t.rect.right-r.right,a.rectDelta.top=t.rect.top-r.top,a.rectDelta.bottom=t.rect.bottom-r.bottom;const c=this.result.coords,l=this.result.rect;if(c&&l){const t=a.rect.left!==l.left||a.rect.right!==l.right||a.rect.top!==l.top||a.rect.bottom!==l.bottom;a.changed=t||c.x!==a.coords.x||c.y!==a.coords.y}return a}applyToInteraction(t){const{interaction:e}=this,{phase:s}=t,o=e.coords.cur,r=e.coords.start,{result:i,startDelta:n}=this,a=i.delta;"start"===s&&extend(this.startDelta,i.delta);for(const[t,e]of[[r,n],[o,a]])t.page.x+=e.x,t.page.y+=e.y,t.client.x+=e.x,t.client.y+=e.y;const{rectDelta:d}=this.result,c=t.rect||e.rect;c.left+=d.left,c.right+=d.right,c.top+=d.top,c.bottom+=d.bottom,c.width=c.right-c.left,c.height=c.bottom-c.top}setAndApply(t){const{interaction:e}=this,{phase:s,preEnd:o,skipModifiers:r}=t,i=this.setAll(this.fillArg({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:e}=t;if(!this.states||!this.states.length)return;const s=extend({states:this.states,interactable:e.interactable,element:e.element,rect:null},t);this.fillArg(s);for(const t of this.states)s.state=t,t.methods.stop&&t.methods.stop(s);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];this.states.push({options:s,methods:o,index:e,name:r})}return this.states}restoreInteractionCoords(t){let{interaction:{coords:e,rect:s,modification:o}}=t;if(!o.result)return;const{startDelta:r}=o,{delta:i,rectDelta:n}=o.result,a=[[e.start,r],[e.cur,i]];for(const[t,e]of a)t.page.x-=e.x,t.page.y-=e.y,t.client.x-=e.x,t.client.y-=e.y;s.left-=n.left,s.right-=n.right,s.top-=n.top,s.bottom-=n.bottom}shouldDo(t,e,s,o){return!(!t||!1===t.enabled||o&&!t.endOnly||t.endOnly&&!e||"start"===s&&!t.setStart)}copyFrom(t){this.startOffset=t.startOffset,this.startDelta=t.startDelta,this.startEdges=t.startEdges,this.edges=t.edges,this.states=t.states.map((t=>clone(t))),this.result=createResult(extend({},t.result.coords),extend({},t.result.rect))}destroy(){for(const t in this)this[t]=null}}function createResult(t,e){return{rect:e,coords:t,delta:{x:0,y:0},rectDelta:{left:0,right:0,top:0,bottom:0},eventProps:[],changed:!0}}function getModifierList(t){const e=t.interactable.options[t.prepared.name],s=e.modifiers;return s&&s.length?s:["snap","snapSize","snapEdges","restrict","restrictEdges","restrictSize"].map((t=>{const s=e[t];return s&&s.enabled&&{options:s,methods:s._methods}})).filter((t=>!!t))}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}}export{Modification,getRectOffset};
|
|
//# sourceMappingURL=Modification.prod.js.map
|