@interactjs/modifiers
Advanced tools
Comparing version 1.10.1 to 1.10.2
@@ -0,1 +1,3 @@ | ||
import { InteractEvent } from "../core/InteractEvent.js"; | ||
import Interaction from "../core/Interaction.js"; | ||
import Modification from "./Modification.js"; | ||
@@ -2,0 +4,0 @@ export function makeModifier(module, name) { |
@@ -1,2 +0,2 @@ | ||
import t from"./Modification.prod.js";export function makeModifier(t,i){const{defaults:e}=t,n={start:t.start,set:t.set,beforeEnd:t.beforeEnd,stop:t.stop},o=t=>{const o=t||{};o.enabled=!1!==o.enabled;for(const t in e)t in o||(o[t]=e[t]);const a={options:o,methods:n,name:i,enable:()=>(o.enabled=!0,a),disable:()=>(o.enabled=!1,a)};return a};return i&&"string"==typeof i&&(o._defaults=e,o._methods=n),o}export function addEventModifiers({iEvent:t,interaction:{modification:{result:i}}}){i&&(t.modifiers=i.eventProps)}const i={id:"modifiers/base",before:["actions"],install(t){t.defaults.perAction.modifiers=[]},listeners:{"interactions:new"({interaction:i}){i.modification=new t(i)},"interactions:before-action-start"(t){const{modification:i}=t.interaction;i.start(t,t.interaction.coords.start.page),t.interaction.edges=i.edges,i.applyToInteraction(t)},"interactions:before-action-move":t=>t.interaction.modification.setAndApply(t),"interactions:before-action-end":t=>t.interaction.modification.beforeEnd(t),"interactions:action-start":addEventModifiers,"interactions:action-move":addEventModifiers,"interactions:action-end":addEventModifiers,"interactions:after-action-start":t=>t.interaction.modification.restoreInteractionCoords(t),"interactions:after-action-move":t=>t.interaction.modification.restoreInteractionCoords(t),"interactions:stop":t=>t.interaction.modification.stop(t)}};export default i; | ||
import{InteractEvent as t}from"../core/InteractEvent.prod.js";import o from"../core/Interaction.prod.js";import i from"./Modification.prod.js";export function makeModifier(t,o){const{defaults:i}=t,e={start:t.start,set:t.set,beforeEnd:t.beforeEnd,stop:t.stop},n=t=>{const n=t||{};n.enabled=!1!==n.enabled;for(const t in i)t in n||(n[t]=i[t]);const r={options:n,methods:e,name:o,enable:()=>(n.enabled=!0,r),disable:()=>(n.enabled=!1,r)};return r};return o&&"string"==typeof o&&(n._defaults=i,n._methods=e),n}export function addEventModifiers({iEvent:t,interaction:{modification:{result:o}}}){o&&(t.modifiers=o.eventProps)}const e={id:"modifiers/base",before:["actions"],install(t){t.defaults.perAction.modifiers=[]},listeners:{"interactions:new"({interaction:t}){t.modification=new i(t)},"interactions:before-action-start"(t){const{modification:o}=t.interaction;o.start(t,t.interaction.coords.start.page),t.interaction.edges=o.edges,o.applyToInteraction(t)},"interactions:before-action-move":t=>t.interaction.modification.setAndApply(t),"interactions:before-action-end":t=>t.interaction.modification.beforeEnd(t),"interactions:action-start":addEventModifiers,"interactions:action-move":addEventModifiers,"interactions:action-end":addEventModifiers,"interactions:after-action-start":t=>t.interaction.modification.restoreInteractionCoords(t),"interactions:after-action-move":t=>t.interaction.modification.restoreInteractionCoords(t),"interactions:stop":t=>t.interaction.modification.stop(t)}};export default e; | ||
//# sourceMappingURL=base.prod.js.map |
@@ -1,2 +0,2 @@ | ||
import t from"../utils/clone.prod.js";import e from"../utils/extend.prod.js";import*as s from"../utils/rect.prod.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=(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)})(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];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.prod.js";import e from"../utils/extend.prod.js";import*as s from"../utils/rect.prod.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=(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))})(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];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.prod.js.map |
{ | ||
"name": "@interactjs/modifiers", | ||
"version": "1.10.1", | ||
"version": "1.10.2", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@interactjs/snappers": "1.10.1" | ||
"@interactjs/snappers": "1.10.2" | ||
}, | ||
"peerDependencies": { | ||
"@interactjs/core": "1.10.1", | ||
"@interactjs/utils": "1.10.1" | ||
"@interactjs/core": "1.10.2", | ||
"@interactjs/utils": "1.10.2" | ||
}, | ||
"optionalDependencies": { | ||
"@interactjs/interact": "1.10.1" | ||
"@interactjs/interact": "1.10.2" | ||
}, | ||
@@ -15,0 +15,0 @@ "publishConfig": { |
@@ -1,2 +0,2 @@ | ||
import t from"../../utils/extend.prod.js";import e from"../../utils/getOriginXY.prod.js";import n from"../../utils/hypot.prod.js";import r from"../../utils/is.prod.js";import{resolveRectLike as o,rectToXY as s}from"../../utils/rect.prod.js";import{makeModifier as a}from"../base.prod.js";const i={start(n){const{interaction:r,interactable:a,element:i,rect:l,state:g,startOffset:f}=n,{options:c}=g,x=c.offsetWithOrigin?(t=>{const{element:n}=t.interaction;return s(o(t.state.options.origin,null,null,[n]))||e(t.interactable,n,t.interaction.prepared.name)})(n):{x:0,y:0};let d;if("startCoords"===c.offset)d={x:r.coords.start.page.x,y:r.coords.start.page.y};else{const t=o(c.offset,a,i,[r]);d=s(t)||{x:0,y:0},d.x+=x.x,d.y+=x.y}const{relativePoints:p}=c;g.offsets=l&&p&&p.length?p.map((t,e)=>({index:e,relativePoint:t,x:f.left-l.width*t.x+d.x,y:f.top-l.height*t.y+d.y})):[t({index:0,relativePoint:null},d)]},set(o){const{interaction:s,coords:a,state:i}=o,{options:l,offsets:g}=i,f=e(s.interactable,s.element,s.prepared.name),c=t({},a),x=[];l.offsetWithOrigin||(c.x-=f.x,c.y-=f.y);for(const t of g){const e=c.x-t.x,n=c.y-t.y;for(let o=0,a=l.targets.length;o<a;o++){const a=l.targets[o];let i;i=r.func(a)?a(e,n,s._proxy,t,o):a,i&&x.push({x:(r.number(i.x)?i.x:e)+t.x,y:(r.number(i.y)?i.y:n)+t.y,range:r.number(i.range)?i.range:l.range,source:a,index:o,offset:t})}}const d={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,o=t.y-c.y,s=n(r,o);let a=s<=e;e===1/0&&d.inRange&&d.range!==1/0&&(a=!1),d.target&&!(a?d.inRange&&e!==1/0?s/e<d.distance/d.range:e===1/0&&d.range!==1/0||s<d.distance:!d.inRange&&s<d.distance)||(d.target=t,d.distance=s,d.range=e,d.inRange=a,d.delta.x=r,d.delta.y=o)}return d.inRange&&(a.x=d.target.x,a.y=d.target.y),i.closest=d,d},defaults:{range:1/0,targets:null,offset:null,offsetWithOrigin:!0,origin:null,relativePoints:null,endOnly:!1,enabled:!1}};export default a(i,"snap");export{i as snap}; | ||
import t from"../../utils/extend.prod.js";import e from"../../utils/getOriginXY.prod.js";import n from"../../utils/hypot.prod.js";import r from"../../utils/is.prod.js";import{resolveRectLike as o,rectToXY as s}from"../../utils/rect.prod.js";import{makeModifier as a}from"../base.prod.js";const i={start(n){const{interaction:r,interactable:a,element:i,rect:l,state:g,startOffset:f}=n,{options:c}=g,x=c.offsetWithOrigin?(t=>{const{element:n}=t.interaction;return s(o(t.state.options.origin,null,null,[n]))||e(t.interactable,n,t.interaction.prepared.name)})(n):{x:0,y:0};let d;if("startCoords"===c.offset)d={x:r.coords.start.page.x,y:r.coords.start.page.y};else{const t=o(c.offset,a,i,[r]);d=s(t)||{x:0,y:0},d.x+=x.x,d.y+=x.y}const{relativePoints:p}=c;g.offsets=l&&p&&p.length?p.map(((t,e)=>({index:e,relativePoint:t,x:f.left-l.width*t.x+d.x,y:f.top-l.height*t.y+d.y}))):[t({index:0,relativePoint:null},d)]},set(o){const{interaction:s,coords:a,state:i}=o,{options:l,offsets:g}=i,f=e(s.interactable,s.element,s.prepared.name),c=t({},a),x=[];l.offsetWithOrigin||(c.x-=f.x,c.y-=f.y);for(const t of g){const e=c.x-t.x,n=c.y-t.y;for(let o=0,a=l.targets.length;o<a;o++){const a=l.targets[o];let i;i=r.func(a)?a(e,n,s._proxy,t,o):a,i&&x.push({x:(r.number(i.x)?i.x:e)+t.x,y:(r.number(i.y)?i.y:n)+t.y,range:r.number(i.range)?i.range:l.range,source:a,index:o,offset:t})}}const d={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,o=t.y-c.y,s=n(r,o);let a=s<=e;e===1/0&&d.inRange&&d.range!==1/0&&(a=!1),d.target&&!(a?d.inRange&&e!==1/0?s/e<d.distance/d.range:e===1/0&&d.range!==1/0||s<d.distance:!d.inRange&&s<d.distance)||(d.target=t,d.distance=s,d.range=e,d.inRange=a,d.delta.x=r,d.delta.y=o)}return d.inRange&&(a.x=d.target.x,a.y=d.target.y),i.closest=d,d},defaults:{range:1/0,targets:null,offset:null,offsetWithOrigin:!0,origin:null,relativePoints:null,endOnly:!1,enabled:!1}};export default a(i,"snap");export{i as snap}; | ||
//# sourceMappingURL=pointer.prod.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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
209743
1273
+ Added@interactjs/core@1.10.2(transitive)
+ Added@interactjs/interact@1.10.2(transitive)
+ Added@interactjs/snappers@1.10.2(transitive)
+ Added@interactjs/types@1.10.2(transitive)
+ Added@interactjs/utils@1.10.2(transitive)
- Removed@interactjs/core@1.10.1(transitive)
- Removed@interactjs/interact@1.10.1(transitive)
- Removed@interactjs/snappers@1.10.1(transitive)
- Removed@interactjs/types@1.10.1(transitive)
- Removed@interactjs/utils@1.10.1(transitive)
Updated@interactjs/snappers@1.10.2