@viselect/vanilla
Advanced tools
Comparing version 3.2.0 to 3.2.1
@@ -1,3 +0,3 @@ | ||
/*! @viselect/vanilla 3.2.0 MIT | https://github.com/Simonwep/selection */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).SelectionArea=e()}(this,(function(){"use strict";class EventTarget{constructor(){this.t=new Map,this.on=this.addEventListener,this.off=this.removeEventListener,this.emit=this.dispatchEvent}addEventListener(t,e){const s=this.t.get(t)||new Set;return this.t.set(t,s),s.add(e),this}removeEventListener(t,e){return this.t.get(t)?.delete(e),this}dispatchEvent(t,...e){let s=!0;for(const i of this.t.get(t)||[])s=!1!==i(...e)&&s;return s}unbindAllListeners(){this.t.clear()}}const t=(t,e="px")=>"number"==typeof t?t+e:t;function e({style:e},s,i){if("object"==typeof s)for(const[i,o]of Object.entries(s))void 0!==o&&e.setProperty(i,t(o));else void 0!==i&&e.setProperty(s,t(i))}function s(t){return(e,s,i,o={})=>{e instanceof HTMLCollection||e instanceof NodeList?e=Array.from(e):Array.isArray(e)||(e=[e]),Array.isArray(s)||(s=[s]);for(const n of e)for(const e of s)n[t](e,i,{capture:!1,...o});return[e,s,i,o]}}const i=s("addEventListener"),o=s("removeEventListener"),n=t=>{const{clientX:e,clientY:s,target:i}=t.touches&&t.touches[0]||t;return{x:e,y:s,target:i}};function h(t,e,s="touch"){switch(s){case"center":{const s=e.left+e.width/2,i=e.top+e.height/2;return s>=t.left&&s<=t.right&&i>=t.top&&i<=t.bottom}case"cover":return e.left>=t.left&&e.top>=t.top&&e.right<=t.right&&e.bottom<=t.bottom;case"touch":return t.right>=e.left&&t.left<=e.right&&t.bottom>=e.top&&t.top<=e.bottom}}function r(t,e=document){const s=Array.isArray(t)?t:[t];let i=[];for(let t=0,o=s.length;t<o;t++){const o=s[t];"string"==typeof o?i=i.concat(Array.from(e.querySelectorAll(o))):o instanceof Element&&i.push(o)}return i}const c=(t,e)=>{for(const[s,i]of Object.entries(t)){const o=e[s];t[s]=void 0===o?t[s]:"object"!=typeof o||"object"!=typeof i||null===i||Array.isArray(i)?o:c(i,o)}return t},{abs:l,max:a,min:d,ceil:u}=Math;class SelectionArea extends EventTarget{constructor(t){super(),this.i={stored:[],selected:[],touched:[],changed:{added:[],removed:[]}},this.o=[],this.h=new DOMRect,this.l={y1:0,x2:0,y2:0,x1:0},this.u=!0,this.p=!0,this.m=!1,this.v={x:0,y:0},this.g={x:0,y:0},this.disable=this._.bind(this,!1),this.enable=this._,this.S=c({selectionAreaClass:"selection-area",selectionContainerClass:void 0,selectables:[],document:window.document,behaviour:{overlap:"invert",intersect:"touch",startThreshold:{x:10,y:10},scrolling:{speedDivider:10,manualSpeed:750,startScrollMargins:{x:0,y:0}}},features:{range:!0,touch:!0,singleTap:{allow:!0,intersect:"native"}},startAreas:["html"],boundaries:["html"],container:"body"},t);for(const t of Object.getOwnPropertyNames(Object.getPrototypeOf(this)))"function"==typeof this[t]&&(this[t]=this[t].bind(this));const{document:s,selectionAreaClass:i,selectionContainerClass:o}=this.S;this.A=s.createElement("div"),this.T=s.createElement("div"),this.T.appendChild(this.A),this.A.classList.add(i),o&&this.T.classList.add(o),e(this.A,{willChange:"top, left, bottom, right, width, height",top:0,left:0,position:"fixed"}),e(this.T,{overflow:"hidden",position:"fixed",transform:"translate3d(0, 0, 0)",pointerEvents:"none",zIndex:"1"}),this.L=(t=>{let e,s=-1,i=!1;return{next(...o){e=o,i||(i=!0,s=requestAnimationFrame((()=>{t(...e),i=!1})))},cancel(){cancelAnimationFrame(s),i=!1}}})((t=>{this.M(),this.j(),this.C("move",t),this.k()})),this.enable()}_(t=!0){const{document:e,features:s}=this.S,n=t?i:o;n(e,"mousedown",this.O),s.touch&&n(e,"touchstart",this.O,{passive:!1})}O(t,e=!1){const{x:s,y:o,target:c}=n(t),{S:l}=this,{document:a}=this.S,d=c.getBoundingClientRect(),u=r(l.startAreas,l.document),f=r(l.boundaries,l.document);this.D=f.find((t=>h(t.getBoundingClientRect(),d)));const p=t.composedPath();if(!this.D||!u.find((t=>p.includes(t)))||!f.find((t=>p.includes(t))))return;if(!e&&!1===this.C("beforestart",t))return;this.l={x1:s,y1:o,x2:0,y2:0};const m=a.scrollingElement||a.body;this.g={x:m.scrollLeft,y:m.scrollTop},this.u=!0,this.clearSelection(!1),i(a,["touchmove","mousemove"],this.F,{passive:!1}),i(a,["mouseup","touchcancel","touchend"],this.R),i(a,"scroll",this.$)}q(t){const{singleTap:{intersect:e},range:s}=this.S.features,i=n(t);let o;if("native"===e)o=i.target;else if("touch"===e){this.resolveSelectables();const{x:t,y:e}=i;o=this.o.find((s=>{const{right:i,left:o,top:n,bottom:h}=s.getBoundingClientRect();return t<i&&t>o&&e<h&&e>n}))}if(!o)return;for(this.resolveSelectables();!this.o.includes(o);){if(!o.parentElement)return;o=o.parentElement}const{stored:h}=this.i;if(this.C("start",t),t.shiftKey&&h.length&&s){const t=this.H??h[0],[e,s]=4&t.compareDocumentPosition(o)?[o,t]:[t,o],i=[...this.o.filter((t=>4&t.compareDocumentPosition(e)&&2&t.compareDocumentPosition(s))),e,s];this.select(i)}else h.includes(o)&&(1===h.length||t.ctrlKey||h.every((t=>this.i.stored.includes(t))))?this.deselect(o):(this.H=o,this.select(o));this.C("stop",t)}F(t){const{container:s,document:h,behaviour:{startThreshold:c}}=this.S,{x1:a,y1:d}=this.l,{x:u,y:f}=n(t),p=typeof c;if("number"===p&&l(u+f-(a+d))>=c||"object"===p&&l(u-a)>=c.x||l(f-d)>=c.y){if(o(h,["mousemove","touchmove"],this.F,{passive:!1}),!1===this.C("beforedrag",t))return void o(h,["mouseup","touchcancel","touchend"],this.R);i(h,["mousemove","touchmove"],this.W,{passive:!1}),e(this.A,"display","block"),r(s,h)[0].appendChild(this.T),this.resolveSelectables(),this.u=!1,this.I=this.D.getBoundingClientRect(),this.p=this.D.scrollHeight!==this.D.clientHeight||this.D.scrollWidth!==this.D.clientWidth,this.p&&(i(h,"wheel",this.N,{passive:!1}),this.o=this.o.filter((t=>this.D.contains(t)))),this.X(),this.C("start",t),this.W(t)}this.Y(t)}X(){const{T:t,D:s,A:i}=this,o=this.I=s.getBoundingClientRect();this.p?(e(t,{top:o.top,left:o.left,width:o.width,height:o.height}),e(i,{marginTop:-o.top,marginLeft:-o.left})):(e(t,{top:0,left:0,width:"100%",height:"100%"}),e(i,{marginTop:0,marginLeft:0}))}W(t){const{x:e,y:s}=n(t),{v:i,l:o,S:h,L:r}=this,{speedDivider:c}=h.behaviour.scrolling,l=this.D;if(o.x2=e,o.y2=s,this.p&&!this.m&&(i.y||i.x)){this.m=!0;const e=()=>{if(i.x||i.y){if(i.y){const t=u(i.y/c);l.scrollTop+=t,o.y1-=t}if(i.x){const t=u(i.x/c);l.scrollLeft+=t,o.x1-=t}r.next(t),requestAnimationFrame(e)}else this.m=!1};requestAnimationFrame(e)}else r.next(t);this.Y(t)}Y(t){const{features:e}=this.S;(e.touch&&matchMedia("(hover: none), (pointer: coarse)").matches||this.p&&"safari"in window)&&t.preventDefault()}$(){const{g:t,S:{document:e}}=this,{scrollTop:s,scrollLeft:i}=e.scrollingElement||e.body;this.l.x1+=t.x-i,this.l.y1+=t.y-s,t.x=i,t.y=s,this.X(),this.L.next(null)}N(t){const{manualSpeed:e}=this.S.behaviour.scrolling,s=t.deltaY?t.deltaY>0?1:-1:0,i=t.deltaX?t.deltaX>0?1:-1:0;this.v.y+=s*e,this.v.x+=i*e,this.W(t),t.preventDefault()}M(){const{v:t,l:e,h:s,D:i,S:o}=this,{scrollTop:n,scrollHeight:h,clientHeight:r,scrollLeft:c,scrollWidth:u,clientWidth:f}=i,p=this.I,{x1:m,y1:v}=e;let{x2:g,y2:y}=e;const{behaviour:{scrolling:{startScrollMargins:_}}}=o;g<p.left+_.x?(t.x=c?-l(p.left-g+_.x):0,g=g<p.left?p.left:g):g>p.right-_.x?(t.x=u-c-f?l(p.left+p.width-g-_.x):0,g=g>p.right?p.right:g):t.x=0,y<p.top+_.y?(t.y=n?-l(p.top-y+_.y):0,y=y<p.top?p.top:y):y>p.bottom-_.y?(t.y=h-n-r?l(p.top+p.height-y-_.y):0,y=y>p.bottom?p.bottom:y):t.y=0;const b=d(m,g),x=d(v,y),S=a(m,g),A=a(v,y);s.x=b,s.y=x,s.width=S-b,s.height=A-x}k(){const{x:t,y:e,width:s,height:i}=this.h,{style:o}=this.A;o.left=`${t}px`,o.top=`${e}px`,o.width=`${s}px`,o.height=`${i}px`}R(t,s){const{document:i,features:n}=this.S,{u:h}=this;o(i,["mousemove","touchmove"],this.F),o(i,["touchmove","mousemove"],this.W),o(i,["mouseup","touchcancel","touchend"],this.R),o(i,"scroll",this.$),this.B(),t&&h&&n.singleTap.allow?this.q(t):h||s||(this.j(),this.C("stop",t)),this.v.x=0,this.v.y=0,this.p&&o(i,"wheel",this.N,{passive:!0}),this.T.remove(),this.L?.cancel(),e(this.A,"display","none")}j(){const{o:t,S:e,i:s,h:i}=this,{stored:o,selected:n,touched:r}=s,{intersect:c,overlap:l}=e.behaviour,a="invert"===l,d=[],u=[],f=[];for(let e=0;e<t.length;e++){const s=t[e];if(h(i,s.getBoundingClientRect(),c)){if(n.includes(s))o.includes(s)&&!r.includes(s)&&r.push(s);else{if(a&&o.includes(s)){f.push(s);continue}u.push(s)}d.push(s)}}a&&u.push(...o.filter((t=>!n.includes(t))));const p="keep"===l;for(let t=0;t<n.length;t++){const e=n[t];d.includes(e)||p&&o.includes(e)||f.push(e)}s.selected=d,s.changed={added:u,removed:f},this.H=d[d.length-1]}C(t,e){return this.emit(t,{event:e,store:this.i,selection:this})}B(){const{S:t,i:e}=this,{selected:s,changed:i,touched:o,stored:n}=e,h=s.filter((t=>!n.includes(t)));switch(t.behaviour.overlap){case"drop":e.stored=[...h,...n.filter((t=>!o.includes(t)))];break;case"invert":e.stored=[...h,...n.filter((t=>!i.removed.includes(t)))];break;case"keep":e.stored=[...n,...s.filter((t=>!n.includes(t)))]}}resolveSelectables(){this.o=r(this.S.selectables,this.S.document)}clearSelection(t=!0,e=!1){const{selected:s,stored:i,changed:o}=this.i;o.added=[],o.removed.push(...s,...t?i:[]),e||(this.C("move",null),this.C("stop",null)),this.H=void 0,this.i={stored:t?[]:i,selected:[],touched:[],changed:{added:[],removed:[]}}}getSelection(){return this.i.stored}getSelectionArea(){return this.A}cancel(t=!1){this.R(null,!t)}destroy(){this.cancel(),this.disable(),this.T.remove(),super.unbindAllListeners()}select(t,e=!1){const{changed:s,selected:i,stored:o}=this.i,n=r(t,this.S.document).filter((t=>!i.includes(t)&&!o.includes(t)));return o.push(...n),i.push(...n),s.added.push(...n),s.removed=[],this.H=void 0,e||(this.C("move",null),this.C("stop",null)),n}deselect(t,e=!1){const{selected:s,stored:i,changed:o}=this.i,n=r(t,this.S.document).filter((t=>s.includes(t)||i.includes(t)));n.length&&(this.i.stored=i.filter((t=>!n.includes(t))),this.i.selected=s.filter((t=>!n.includes(t))),this.i.changed.added=[],this.i.changed.removed.push(...n.filter((t=>!o.removed.includes(t)))),this.H=void 0,e||(this.C("move",null),this.C("stop",null)))}}return SelectionArea.version="3.2.0",SelectionArea})); | ||
/*! @viselect/vanilla 3.2.1 MIT | https://github.com/Simonwep/selection */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).SelectionArea=e()}(this,(function(){"use strict";class EventTarget{constructor(){this.t=new Map,this.on=this.addEventListener,this.off=this.removeEventListener,this.emit=this.dispatchEvent}addEventListener(t,e){const s=this.t.get(t)||new Set;return this.t.set(t,s),s.add(e),this}removeEventListener(t,e){return this.t.get(t)?.delete(e),this}dispatchEvent(t,...e){let s=!0;for(const i of this.t.get(t)||[])s=!1!==i(...e)&&s;return s}unbindAllListeners(){this.t.clear()}}const t=(t,e="px")=>"number"==typeof t?t+e:t;function e({style:e},s,i){if("object"==typeof s)for(const[i,o]of Object.entries(s))void 0!==o&&(e[i]=t(o));else void 0!==i&&(e[s]=t(i))}function s(t){return(e,s,i,o={})=>{e instanceof HTMLCollection||e instanceof NodeList?e=Array.from(e):Array.isArray(e)||(e=[e]),Array.isArray(s)||(s=[s]);for(const n of e)for(const e of s)n[t](e,i,{capture:!1,...o});return[e,s,i,o]}}const i=s("addEventListener"),o=s("removeEventListener"),n=t=>{const{clientX:e,clientY:s,target:i}=t.touches&&t.touches[0]||t;return{x:e,y:s,target:i}};function h(t,e,s="touch"){switch(s){case"center":{const s=e.left+e.width/2,i=e.top+e.height/2;return s>=t.left&&s<=t.right&&i>=t.top&&i<=t.bottom}case"cover":return e.left>=t.left&&e.top>=t.top&&e.right<=t.right&&e.bottom<=t.bottom;case"touch":return t.right>=e.left&&t.left<=e.right&&t.bottom>=e.top&&t.top<=e.bottom}}function r(t,e=document){const s=Array.isArray(t)?t:[t];let i=[];for(let t=0,o=s.length;t<o;t++){const o=s[t];"string"==typeof o?i=i.concat(Array.from(e.querySelectorAll(o))):o instanceof Element&&i.push(o)}return i}const c=(t,e)=>{for(const[s,i]of Object.entries(t)){const o=e[s];t[s]=void 0===o?t[s]:"object"!=typeof o||"object"!=typeof i||null===i||Array.isArray(i)?o:c(i,o)}return t},{abs:l,max:a,min:d,ceil:u}=Math;class SelectionArea extends EventTarget{constructor(t){super(),this.i={stored:[],selected:[],touched:[],changed:{added:[],removed:[]}},this.o=[],this.h=new DOMRect,this.l={y1:0,x2:0,y2:0,x1:0},this.u=!0,this.p=!0,this.m=!1,this.v={x:0,y:0},this.g={x:0,y:0},this.disable=this._.bind(this,!1),this.enable=this._,this.S=c({selectionAreaClass:"selection-area",selectionContainerClass:void 0,selectables:[],document:window.document,behaviour:{overlap:"invert",intersect:"touch",startThreshold:{x:10,y:10},scrolling:{speedDivider:10,manualSpeed:750,startScrollMargins:{x:0,y:0}}},features:{range:!0,touch:!0,singleTap:{allow:!0,intersect:"native"}},startAreas:["html"],boundaries:["html"],container:"body"},t);for(const t of Object.getOwnPropertyNames(Object.getPrototypeOf(this)))"function"==typeof this[t]&&(this[t]=this[t].bind(this));const{document:s,selectionAreaClass:i,selectionContainerClass:o}=this.S;this.A=s.createElement("div"),this.T=s.createElement("div"),this.T.appendChild(this.A),this.A.classList.add(i),o&&this.T.classList.add(o),e(this.A,{willChange:"top, left, bottom, right, width, height",top:0,left:0,position:"fixed"}),e(this.T,{overflow:"hidden",position:"fixed",transform:"translate3d(0, 0, 0)",pointerEvents:"none",zIndex:"1"}),this.L=(t=>{let e,s=-1,i=!1;return{next(...o){e=o,i||(i=!0,s=requestAnimationFrame((()=>{t(...e),i=!1})))},cancel(){cancelAnimationFrame(s),i=!1}}})((t=>{this.M(),this.j(),this.C("move",t),this.k()})),this.enable()}_(t=!0){const{document:e,features:s}=this.S,n=t?i:o;n(e,"mousedown",this.O),s.touch&&n(e,"touchstart",this.O,{passive:!1})}O(t,e=!1){const{x:s,y:o,target:c}=n(t),{S:l}=this,{document:a}=this.S,d=c.getBoundingClientRect(),u=r(l.startAreas,l.document),f=r(l.boundaries,l.document);this.D=f.find((t=>h(t.getBoundingClientRect(),d)));const p=t.composedPath();if(!this.D||!u.find((t=>p.includes(t)))||!f.find((t=>p.includes(t))))return;if(!e&&!1===this.C("beforestart",t))return;this.l={x1:s,y1:o,x2:0,y2:0};const m=a.scrollingElement||a.body;this.g={x:m.scrollLeft,y:m.scrollTop},this.u=!0,this.clearSelection(!1),i(a,["touchmove","mousemove"],this.F,{passive:!1}),i(a,["mouseup","touchcancel","touchend"],this.R),i(a,"scroll",this.$)}q(t){const{singleTap:{intersect:e},range:s}=this.S.features,i=n(t);let o;if("native"===e)o=i.target;else if("touch"===e){this.resolveSelectables();const{x:t,y:e}=i;o=this.o.find((s=>{const{right:i,left:o,top:n,bottom:h}=s.getBoundingClientRect();return t<i&&t>o&&e<h&&e>n}))}if(!o)return;for(this.resolveSelectables();!this.o.includes(o);){if(!o.parentElement)return;o=o.parentElement}const{stored:h}=this.i;if(this.C("start",t),t.shiftKey&&h.length&&s){const t=this.H??h[0],[e,s]=4&t.compareDocumentPosition(o)?[o,t]:[t,o],i=[...this.o.filter((t=>4&t.compareDocumentPosition(e)&&2&t.compareDocumentPosition(s))),e,s];this.select(i)}else h.includes(o)&&(1===h.length||t.ctrlKey||h.every((t=>this.i.stored.includes(t))))?this.deselect(o):(this.H=o,this.select(o));this.C("stop",t)}F(t){const{container:s,document:h,behaviour:{startThreshold:c}}=this.S,{x1:a,y1:d}=this.l,{x:u,y:f}=n(t),p=typeof c;if("number"===p&&l(u+f-(a+d))>=c||"object"===p&&l(u-a)>=c.x||l(f-d)>=c.y){if(o(h,["mousemove","touchmove"],this.F,{passive:!1}),!1===this.C("beforedrag",t))return void o(h,["mouseup","touchcancel","touchend"],this.R);i(h,["mousemove","touchmove"],this.W,{passive:!1}),e(this.A,"display","block"),r(s,h)[0].appendChild(this.T),this.resolveSelectables(),this.u=!1,this.I=this.D.getBoundingClientRect(),this.p=this.D.scrollHeight!==this.D.clientHeight||this.D.scrollWidth!==this.D.clientWidth,this.p&&(i(h,"wheel",this.N,{passive:!1}),this.o=this.o.filter((t=>this.D.contains(t)))),this.X(),this.C("start",t),this.W(t)}this.Y(t)}X(){const{T:t,D:s,A:i}=this,o=this.I=s.getBoundingClientRect();this.p?(e(t,{top:o.top,left:o.left,width:o.width,height:o.height}),e(i,{marginTop:-o.top,marginLeft:-o.left})):(e(t,{top:0,left:0,width:"100%",height:"100%"}),e(i,{marginTop:0,marginLeft:0}))}W(t){const{x:e,y:s}=n(t),{v:i,l:o,S:h,L:r}=this,{speedDivider:c}=h.behaviour.scrolling,l=this.D;if(o.x2=e,o.y2=s,this.p&&!this.m&&(i.y||i.x)){this.m=!0;const e=()=>{if(i.x||i.y){if(i.y){const t=u(i.y/c);l.scrollTop+=t,o.y1-=t}if(i.x){const t=u(i.x/c);l.scrollLeft+=t,o.x1-=t}r.next(t),requestAnimationFrame(e)}else this.m=!1};requestAnimationFrame(e)}else r.next(t);this.Y(t)}Y(t){const{features:e}=this.S;(e.touch&&matchMedia("(hover: none), (pointer: coarse)").matches||this.p&&"safari"in window)&&t.preventDefault()}$(){const{g:t,S:{document:e}}=this,{scrollTop:s,scrollLeft:i}=e.scrollingElement||e.body;this.l.x1+=t.x-i,this.l.y1+=t.y-s,t.x=i,t.y=s,this.X(),this.L.next(null)}N(t){const{manualSpeed:e}=this.S.behaviour.scrolling,s=t.deltaY?t.deltaY>0?1:-1:0,i=t.deltaX?t.deltaX>0?1:-1:0;this.v.y+=s*e,this.v.x+=i*e,this.W(t),t.preventDefault()}M(){const{v:t,l:e,h:s,D:i,S:o}=this,{scrollTop:n,scrollHeight:h,clientHeight:r,scrollLeft:c,scrollWidth:u,clientWidth:f}=i,p=this.I,{x1:m,y1:v}=e;let{x2:g,y2:y}=e;const{behaviour:{scrolling:{startScrollMargins:_}}}=o;g<p.left+_.x?(t.x=c?-l(p.left-g+_.x):0,g=g<p.left?p.left:g):g>p.right-_.x?(t.x=u-c-f?l(p.left+p.width-g-_.x):0,g=g>p.right?p.right:g):t.x=0,y<p.top+_.y?(t.y=n?-l(p.top-y+_.y):0,y=y<p.top?p.top:y):y>p.bottom-_.y?(t.y=h-n-r?l(p.top+p.height-y-_.y):0,y=y>p.bottom?p.bottom:y):t.y=0;const b=d(m,g),x=d(v,y),S=a(m,g),A=a(v,y);s.x=b,s.y=x,s.width=S-b,s.height=A-x}k(){const{x:t,y:e,width:s,height:i}=this.h,{style:o}=this.A;o.left=`${t}px`,o.top=`${e}px`,o.width=`${s}px`,o.height=`${i}px`}R(t,s){const{document:i,features:n}=this.S,{u:h}=this;o(i,["mousemove","touchmove"],this.F),o(i,["touchmove","mousemove"],this.W),o(i,["mouseup","touchcancel","touchend"],this.R),o(i,"scroll",this.$),this.B(),t&&h&&n.singleTap.allow?this.q(t):h||s||(this.j(),this.C("stop",t)),this.v.x=0,this.v.y=0,this.p&&o(i,"wheel",this.N,{passive:!0}),this.T.remove(),this.L?.cancel(),e(this.A,"display","none")}j(){const{o:t,S:e,i:s,h:i}=this,{stored:o,selected:n,touched:r}=s,{intersect:c,overlap:l}=e.behaviour,a="invert"===l,d=[],u=[],f=[];for(let e=0;e<t.length;e++){const s=t[e];if(h(i,s.getBoundingClientRect(),c)){if(n.includes(s))o.includes(s)&&!r.includes(s)&&r.push(s);else{if(a&&o.includes(s)){f.push(s);continue}u.push(s)}d.push(s)}}a&&u.push(...o.filter((t=>!n.includes(t))));const p="keep"===l;for(let t=0;t<n.length;t++){const e=n[t];d.includes(e)||p&&o.includes(e)||f.push(e)}s.selected=d,s.changed={added:u,removed:f},this.H=d[d.length-1]}C(t,e){return this.emit(t,{event:e,store:this.i,selection:this})}B(){const{S:t,i:e}=this,{selected:s,changed:i,touched:o,stored:n}=e,h=s.filter((t=>!n.includes(t)));switch(t.behaviour.overlap){case"drop":e.stored=[...h,...n.filter((t=>!o.includes(t)))];break;case"invert":e.stored=[...h,...n.filter((t=>!i.removed.includes(t)))];break;case"keep":e.stored=[...n,...s.filter((t=>!n.includes(t)))]}}resolveSelectables(){this.o=r(this.S.selectables,this.S.document)}clearSelection(t=!0,e=!1){const{selected:s,stored:i,changed:o}=this.i;o.added=[],o.removed.push(...s,...t?i:[]),e||(this.C("move",null),this.C("stop",null)),this.H=void 0,this.i={stored:t?[]:i,selected:[],touched:[],changed:{added:[],removed:[]}}}getSelection(){return this.i.stored}getSelectionArea(){return this.A}cancel(t=!1){this.R(null,!t)}destroy(){this.cancel(),this.disable(),this.T.remove(),super.unbindAllListeners()}select(t,e=!1){const{changed:s,selected:i,stored:o}=this.i,n=r(t,this.S.document).filter((t=>!i.includes(t)&&!o.includes(t)));return o.push(...n),i.push(...n),s.added.push(...n),s.removed=[],this.H=void 0,e||(this.C("move",null),this.C("stop",null)),n}deselect(t,e=!1){const{selected:s,stored:i,changed:o}=this.i,n=r(t,this.S.document).filter((t=>s.includes(t)||i.includes(t)));n.length&&(this.i.stored=i.filter((t=>!n.includes(t))),this.i.selected=s.filter((t=>!n.includes(t))),this.i.changed.added=[],this.i.changed.removed.push(...n.filter((t=>!o.removed.includes(t)))),this.H=void 0,e||(this.C("move",null),this.C("stop",null)))}}return SelectionArea.version="3.2.1",SelectionArea})); | ||
//# sourceMappingURL=viselect.cjs.js.map |
@@ -1,3 +0,3 @@ | ||
/*! @viselect/vanilla 3.2.0 MIT | https://github.com/Simonwep/selection */ | ||
class EventTarget{constructor(){this.t=new Map,this.on=this.addEventListener,this.off=this.removeEventListener,this.emit=this.dispatchEvent}addEventListener(t,e){const s=this.t.get(t)||new Set;return this.t.set(t,s),s.add(e),this}removeEventListener(t,e){return this.t.get(t)?.delete(e),this}dispatchEvent(t,...e){let s=!0;for(const i of this.t.get(t)||[])s=!1!==i(...e)&&s;return s}unbindAllListeners(){this.t.clear()}}const t=(t,e="px")=>"number"==typeof t?t+e:t;function e({style:e},s,i){if("object"==typeof s)for(const[i,o]of Object.entries(s))void 0!==o&&e.setProperty(i,t(o));else void 0!==i&&e.setProperty(s,t(i))}function s(t){return(e,s,i,o={})=>{e instanceof HTMLCollection||e instanceof NodeList?e=Array.from(e):Array.isArray(e)||(e=[e]),Array.isArray(s)||(s=[s]);for(const n of e)for(const e of s)n[t](e,i,{capture:!1,...o});return[e,s,i,o]}}const i=s("addEventListener"),o=s("removeEventListener"),n=t=>{const{clientX:e,clientY:s,target:i}=t.touches&&t.touches[0]||t;return{x:e,y:s,target:i}};function h(t,e,s="touch"){switch(s){case"center":{const s=e.left+e.width/2,i=e.top+e.height/2;return s>=t.left&&s<=t.right&&i>=t.top&&i<=t.bottom}case"cover":return e.left>=t.left&&e.top>=t.top&&e.right<=t.right&&e.bottom<=t.bottom;case"touch":return t.right>=e.left&&t.left<=e.right&&t.bottom>=e.top&&t.top<=e.bottom}}function r(t,e=document){const s=Array.isArray(t)?t:[t];let i=[];for(let t=0,o=s.length;t<o;t++){const o=s[t];"string"==typeof o?i=i.concat(Array.from(e.querySelectorAll(o))):o instanceof Element&&i.push(o)}return i}const c=(t,e)=>{for(const[s,i]of Object.entries(t)){const o=e[s];t[s]=void 0===o?t[s]:"object"!=typeof o||"object"!=typeof i||null===i||Array.isArray(i)?o:c(i,o)}return t},{abs:l,max:a,min:d,ceil:u}=Math;class SelectionArea extends EventTarget{constructor(t){super(),this.i={stored:[],selected:[],touched:[],changed:{added:[],removed:[]}},this.o=[],this.h=new DOMRect,this.l={y1:0,x2:0,y2:0,x1:0},this.u=!0,this.p=!0,this.m=!1,this.v={x:0,y:0},this.g={x:0,y:0},this.disable=this._.bind(this,!1),this.enable=this._,this.S=c({selectionAreaClass:"selection-area",selectionContainerClass:void 0,selectables:[],document:window.document,behaviour:{overlap:"invert",intersect:"touch",startThreshold:{x:10,y:10},scrolling:{speedDivider:10,manualSpeed:750,startScrollMargins:{x:0,y:0}}},features:{range:!0,touch:!0,singleTap:{allow:!0,intersect:"native"}},startAreas:["html"],boundaries:["html"],container:"body"},t);for(const t of Object.getOwnPropertyNames(Object.getPrototypeOf(this)))"function"==typeof this[t]&&(this[t]=this[t].bind(this));const{document:s,selectionAreaClass:i,selectionContainerClass:o}=this.S;this.A=s.createElement("div"),this.T=s.createElement("div"),this.T.appendChild(this.A),this.A.classList.add(i),o&&this.T.classList.add(o),e(this.A,{willChange:"top, left, bottom, right, width, height",top:0,left:0,position:"fixed"}),e(this.T,{overflow:"hidden",position:"fixed",transform:"translate3d(0, 0, 0)",pointerEvents:"none",zIndex:"1"}),this.L=(t=>{let e,s=-1,i=!1;return{next(...o){e=o,i||(i=!0,s=requestAnimationFrame((()=>{t(...e),i=!1})))},cancel(){cancelAnimationFrame(s),i=!1}}})((t=>{this.M(),this.C(),this.j("move",t),this.k()})),this.enable()}_(t=!0){const{document:e,features:s}=this.S,n=t?i:o;n(e,"mousedown",this.O),s.touch&&n(e,"touchstart",this.O,{passive:!1})}O(t,e=!1){const{x:s,y:o,target:c}=n(t),{S:l}=this,{document:a}=this.S,d=c.getBoundingClientRect(),u=r(l.startAreas,l.document),p=r(l.boundaries,l.document);this.D=p.find((t=>h(t.getBoundingClientRect(),d)));const f=t.composedPath();if(!this.D||!u.find((t=>f.includes(t)))||!p.find((t=>f.includes(t))))return;if(!e&&!1===this.j("beforestart",t))return;this.l={x1:s,y1:o,x2:0,y2:0};const m=a.scrollingElement||a.body;this.g={x:m.scrollLeft,y:m.scrollTop},this.u=!0,this.clearSelection(!1),i(a,["touchmove","mousemove"],this.F,{passive:!1}),i(a,["mouseup","touchcancel","touchend"],this.R),i(a,"scroll",this.$)}q(t){const{singleTap:{intersect:e},range:s}=this.S.features,i=n(t);let o;if("native"===e)o=i.target;else if("touch"===e){this.resolveSelectables();const{x:t,y:e}=i;o=this.o.find((s=>{const{right:i,left:o,top:n,bottom:h}=s.getBoundingClientRect();return t<i&&t>o&&e<h&&e>n}))}if(!o)return;for(this.resolveSelectables();!this.o.includes(o);){if(!o.parentElement)return;o=o.parentElement}const{stored:h}=this.i;if(this.j("start",t),t.shiftKey&&h.length&&s){const t=this.H??h[0],[e,s]=4&t.compareDocumentPosition(o)?[o,t]:[t,o],i=[...this.o.filter((t=>4&t.compareDocumentPosition(e)&&2&t.compareDocumentPosition(s))),e,s];this.select(i)}else h.includes(o)&&(1===h.length||t.ctrlKey||h.every((t=>this.i.stored.includes(t))))?this.deselect(o):(this.H=o,this.select(o));this.j("stop",t)}F(t){const{container:s,document:h,behaviour:{startThreshold:c}}=this.S,{x1:a,y1:d}=this.l,{x:u,y:p}=n(t),f=typeof c;if("number"===f&&l(u+p-(a+d))>=c||"object"===f&&l(u-a)>=c.x||l(p-d)>=c.y){if(o(h,["mousemove","touchmove"],this.F,{passive:!1}),!1===this.j("beforedrag",t))return void o(h,["mouseup","touchcancel","touchend"],this.R);i(h,["mousemove","touchmove"],this.W,{passive:!1}),e(this.A,"display","block"),r(s,h)[0].appendChild(this.T),this.resolveSelectables(),this.u=!1,this.I=this.D.getBoundingClientRect(),this.p=this.D.scrollHeight!==this.D.clientHeight||this.D.scrollWidth!==this.D.clientWidth,this.p&&(i(h,"wheel",this.N,{passive:!1}),this.o=this.o.filter((t=>this.D.contains(t)))),this.X(),this.j("start",t),this.W(t)}this.Y(t)}X(){const{T:t,D:s,A:i}=this,o=this.I=s.getBoundingClientRect();this.p?(e(t,{top:o.top,left:o.left,width:o.width,height:o.height}),e(i,{marginTop:-o.top,marginLeft:-o.left})):(e(t,{top:0,left:0,width:"100%",height:"100%"}),e(i,{marginTop:0,marginLeft:0}))}W(t){const{x:e,y:s}=n(t),{v:i,l:o,S:h,L:r}=this,{speedDivider:c}=h.behaviour.scrolling,l=this.D;if(o.x2=e,o.y2=s,this.p&&!this.m&&(i.y||i.x)){this.m=!0;const e=()=>{if(i.x||i.y){if(i.y){const t=u(i.y/c);l.scrollTop+=t,o.y1-=t}if(i.x){const t=u(i.x/c);l.scrollLeft+=t,o.x1-=t}r.next(t),requestAnimationFrame(e)}else this.m=!1};requestAnimationFrame(e)}else r.next(t);this.Y(t)}Y(t){const{features:e}=this.S;(e.touch&&matchMedia("(hover: none), (pointer: coarse)").matches||this.p&&"safari"in window)&&t.preventDefault()}$(){const{g:t,S:{document:e}}=this,{scrollTop:s,scrollLeft:i}=e.scrollingElement||e.body;this.l.x1+=t.x-i,this.l.y1+=t.y-s,t.x=i,t.y=s,this.X(),this.L.next(null)}N(t){const{manualSpeed:e}=this.S.behaviour.scrolling,s=t.deltaY?t.deltaY>0?1:-1:0,i=t.deltaX?t.deltaX>0?1:-1:0;this.v.y+=s*e,this.v.x+=i*e,this.W(t),t.preventDefault()}M(){const{v:t,l:e,h:s,D:i,S:o}=this,{scrollTop:n,scrollHeight:h,clientHeight:r,scrollLeft:c,scrollWidth:u,clientWidth:p}=i,f=this.I,{x1:m,y1:v}=e;let{x2:g,y2:y}=e;const{behaviour:{scrolling:{startScrollMargins:_}}}=o;g<f.left+_.x?(t.x=c?-l(f.left-g+_.x):0,g=g<f.left?f.left:g):g>f.right-_.x?(t.x=u-c-p?l(f.left+f.width-g-_.x):0,g=g>f.right?f.right:g):t.x=0,y<f.top+_.y?(t.y=n?-l(f.top-y+_.y):0,y=y<f.top?f.top:y):y>f.bottom-_.y?(t.y=h-n-r?l(f.top+f.height-y-_.y):0,y=y>f.bottom?f.bottom:y):t.y=0;const x=d(m,g),b=d(v,y),S=a(m,g),A=a(v,y);s.x=x,s.y=b,s.width=S-x,s.height=A-b}k(){const{x:t,y:e,width:s,height:i}=this.h,{style:o}=this.A;o.left=`${t}px`,o.top=`${e}px`,o.width=`${s}px`,o.height=`${i}px`}R(t,s){const{document:i,features:n}=this.S,{u:h}=this;o(i,["mousemove","touchmove"],this.F),o(i,["touchmove","mousemove"],this.W),o(i,["mouseup","touchcancel","touchend"],this.R),o(i,"scroll",this.$),this.B(),t&&h&&n.singleTap.allow?this.q(t):h||s||(this.C(),this.j("stop",t)),this.v.x=0,this.v.y=0,this.p&&o(i,"wheel",this.N,{passive:!0}),this.T.remove(),this.L?.cancel(),e(this.A,"display","none")}C(){const{o:t,S:e,i:s,h:i}=this,{stored:o,selected:n,touched:r}=s,{intersect:c,overlap:l}=e.behaviour,a="invert"===l,d=[],u=[],p=[];for(let e=0;e<t.length;e++){const s=t[e];if(h(i,s.getBoundingClientRect(),c)){if(n.includes(s))o.includes(s)&&!r.includes(s)&&r.push(s);else{if(a&&o.includes(s)){p.push(s);continue}u.push(s)}d.push(s)}}a&&u.push(...o.filter((t=>!n.includes(t))));const f="keep"===l;for(let t=0;t<n.length;t++){const e=n[t];d.includes(e)||f&&o.includes(e)||p.push(e)}s.selected=d,s.changed={added:u,removed:p},this.H=d[d.length-1]}j(t,e){return this.emit(t,{event:e,store:this.i,selection:this})}B(){const{S:t,i:e}=this,{selected:s,changed:i,touched:o,stored:n}=e,h=s.filter((t=>!n.includes(t)));switch(t.behaviour.overlap){case"drop":e.stored=[...h,...n.filter((t=>!o.includes(t)))];break;case"invert":e.stored=[...h,...n.filter((t=>!i.removed.includes(t)))];break;case"keep":e.stored=[...n,...s.filter((t=>!n.includes(t)))]}}resolveSelectables(){this.o=r(this.S.selectables,this.S.document)}clearSelection(t=!0,e=!1){const{selected:s,stored:i,changed:o}=this.i;o.added=[],o.removed.push(...s,...t?i:[]),e||(this.j("move",null),this.j("stop",null)),this.H=void 0,this.i={stored:t?[]:i,selected:[],touched:[],changed:{added:[],removed:[]}}}getSelection(){return this.i.stored}getSelectionArea(){return this.A}cancel(t=!1){this.R(null,!t)}destroy(){this.cancel(),this.disable(),this.T.remove(),super.unbindAllListeners()}select(t,e=!1){const{changed:s,selected:i,stored:o}=this.i,n=r(t,this.S.document).filter((t=>!i.includes(t)&&!o.includes(t)));return o.push(...n),i.push(...n),s.added.push(...n),s.removed=[],this.H=void 0,e||(this.j("move",null),this.j("stop",null)),n}deselect(t,e=!1){const{selected:s,stored:i,changed:o}=this.i,n=r(t,this.S.document).filter((t=>s.includes(t)||i.includes(t)));n.length&&(this.i.stored=i.filter((t=>!n.includes(t))),this.i.selected=s.filter((t=>!n.includes(t))),this.i.changed.added=[],this.i.changed.removed.push(...n.filter((t=>!o.removed.includes(t)))),this.H=void 0,e||(this.j("move",null),this.j("stop",null)))}}SelectionArea.version="3.2.0";export{SelectionArea as default}; | ||
/*! @viselect/vanilla 3.2.1 MIT | https://github.com/Simonwep/selection */ | ||
class EventTarget{constructor(){this.t=new Map,this.on=this.addEventListener,this.off=this.removeEventListener,this.emit=this.dispatchEvent}addEventListener(t,e){const s=this.t.get(t)||new Set;return this.t.set(t,s),s.add(e),this}removeEventListener(t,e){return this.t.get(t)?.delete(e),this}dispatchEvent(t,...e){let s=!0;for(const i of this.t.get(t)||[])s=!1!==i(...e)&&s;return s}unbindAllListeners(){this.t.clear()}}const t=(t,e="px")=>"number"==typeof t?t+e:t;function e({style:e},s,i){if("object"==typeof s)for(const[i,o]of Object.entries(s))void 0!==o&&(e[i]=t(o));else void 0!==i&&(e[s]=t(i))}function s(t){return(e,s,i,o={})=>{e instanceof HTMLCollection||e instanceof NodeList?e=Array.from(e):Array.isArray(e)||(e=[e]),Array.isArray(s)||(s=[s]);for(const n of e)for(const e of s)n[t](e,i,{capture:!1,...o});return[e,s,i,o]}}const i=s("addEventListener"),o=s("removeEventListener"),n=t=>{const{clientX:e,clientY:s,target:i}=t.touches&&t.touches[0]||t;return{x:e,y:s,target:i}};function h(t,e,s="touch"){switch(s){case"center":{const s=e.left+e.width/2,i=e.top+e.height/2;return s>=t.left&&s<=t.right&&i>=t.top&&i<=t.bottom}case"cover":return e.left>=t.left&&e.top>=t.top&&e.right<=t.right&&e.bottom<=t.bottom;case"touch":return t.right>=e.left&&t.left<=e.right&&t.bottom>=e.top&&t.top<=e.bottom}}function r(t,e=document){const s=Array.isArray(t)?t:[t];let i=[];for(let t=0,o=s.length;t<o;t++){const o=s[t];"string"==typeof o?i=i.concat(Array.from(e.querySelectorAll(o))):o instanceof Element&&i.push(o)}return i}const c=(t,e)=>{for(const[s,i]of Object.entries(t)){const o=e[s];t[s]=void 0===o?t[s]:"object"!=typeof o||"object"!=typeof i||null===i||Array.isArray(i)?o:c(i,o)}return t},{abs:l,max:a,min:d,ceil:u}=Math;class SelectionArea extends EventTarget{constructor(t){super(),this.i={stored:[],selected:[],touched:[],changed:{added:[],removed:[]}},this.o=[],this.h=new DOMRect,this.l={y1:0,x2:0,y2:0,x1:0},this.u=!0,this.p=!0,this.m=!1,this.v={x:0,y:0},this.g={x:0,y:0},this.disable=this._.bind(this,!1),this.enable=this._,this.S=c({selectionAreaClass:"selection-area",selectionContainerClass:void 0,selectables:[],document:window.document,behaviour:{overlap:"invert",intersect:"touch",startThreshold:{x:10,y:10},scrolling:{speedDivider:10,manualSpeed:750,startScrollMargins:{x:0,y:0}}},features:{range:!0,touch:!0,singleTap:{allow:!0,intersect:"native"}},startAreas:["html"],boundaries:["html"],container:"body"},t);for(const t of Object.getOwnPropertyNames(Object.getPrototypeOf(this)))"function"==typeof this[t]&&(this[t]=this[t].bind(this));const{document:s,selectionAreaClass:i,selectionContainerClass:o}=this.S;this.A=s.createElement("div"),this.T=s.createElement("div"),this.T.appendChild(this.A),this.A.classList.add(i),o&&this.T.classList.add(o),e(this.A,{willChange:"top, left, bottom, right, width, height",top:0,left:0,position:"fixed"}),e(this.T,{overflow:"hidden",position:"fixed",transform:"translate3d(0, 0, 0)",pointerEvents:"none",zIndex:"1"}),this.L=(t=>{let e,s=-1,i=!1;return{next(...o){e=o,i||(i=!0,s=requestAnimationFrame((()=>{t(...e),i=!1})))},cancel(){cancelAnimationFrame(s),i=!1}}})((t=>{this.M(),this.C(),this.j("move",t),this.k()})),this.enable()}_(t=!0){const{document:e,features:s}=this.S,n=t?i:o;n(e,"mousedown",this.O),s.touch&&n(e,"touchstart",this.O,{passive:!1})}O(t,e=!1){const{x:s,y:o,target:c}=n(t),{S:l}=this,{document:a}=this.S,d=c.getBoundingClientRect(),u=r(l.startAreas,l.document),p=r(l.boundaries,l.document);this.D=p.find((t=>h(t.getBoundingClientRect(),d)));const f=t.composedPath();if(!this.D||!u.find((t=>f.includes(t)))||!p.find((t=>f.includes(t))))return;if(!e&&!1===this.j("beforestart",t))return;this.l={x1:s,y1:o,x2:0,y2:0};const m=a.scrollingElement||a.body;this.g={x:m.scrollLeft,y:m.scrollTop},this.u=!0,this.clearSelection(!1),i(a,["touchmove","mousemove"],this.F,{passive:!1}),i(a,["mouseup","touchcancel","touchend"],this.R),i(a,"scroll",this.$)}q(t){const{singleTap:{intersect:e},range:s}=this.S.features,i=n(t);let o;if("native"===e)o=i.target;else if("touch"===e){this.resolveSelectables();const{x:t,y:e}=i;o=this.o.find((s=>{const{right:i,left:o,top:n,bottom:h}=s.getBoundingClientRect();return t<i&&t>o&&e<h&&e>n}))}if(!o)return;for(this.resolveSelectables();!this.o.includes(o);){if(!o.parentElement)return;o=o.parentElement}const{stored:h}=this.i;if(this.j("start",t),t.shiftKey&&h.length&&s){const t=this.H??h[0],[e,s]=4&t.compareDocumentPosition(o)?[o,t]:[t,o],i=[...this.o.filter((t=>4&t.compareDocumentPosition(e)&&2&t.compareDocumentPosition(s))),e,s];this.select(i)}else h.includes(o)&&(1===h.length||t.ctrlKey||h.every((t=>this.i.stored.includes(t))))?this.deselect(o):(this.H=o,this.select(o));this.j("stop",t)}F(t){const{container:s,document:h,behaviour:{startThreshold:c}}=this.S,{x1:a,y1:d}=this.l,{x:u,y:p}=n(t),f=typeof c;if("number"===f&&l(u+p-(a+d))>=c||"object"===f&&l(u-a)>=c.x||l(p-d)>=c.y){if(o(h,["mousemove","touchmove"],this.F,{passive:!1}),!1===this.j("beforedrag",t))return void o(h,["mouseup","touchcancel","touchend"],this.R);i(h,["mousemove","touchmove"],this.W,{passive:!1}),e(this.A,"display","block"),r(s,h)[0].appendChild(this.T),this.resolveSelectables(),this.u=!1,this.I=this.D.getBoundingClientRect(),this.p=this.D.scrollHeight!==this.D.clientHeight||this.D.scrollWidth!==this.D.clientWidth,this.p&&(i(h,"wheel",this.N,{passive:!1}),this.o=this.o.filter((t=>this.D.contains(t)))),this.X(),this.j("start",t),this.W(t)}this.Y(t)}X(){const{T:t,D:s,A:i}=this,o=this.I=s.getBoundingClientRect();this.p?(e(t,{top:o.top,left:o.left,width:o.width,height:o.height}),e(i,{marginTop:-o.top,marginLeft:-o.left})):(e(t,{top:0,left:0,width:"100%",height:"100%"}),e(i,{marginTop:0,marginLeft:0}))}W(t){const{x:e,y:s}=n(t),{v:i,l:o,S:h,L:r}=this,{speedDivider:c}=h.behaviour.scrolling,l=this.D;if(o.x2=e,o.y2=s,this.p&&!this.m&&(i.y||i.x)){this.m=!0;const e=()=>{if(i.x||i.y){if(i.y){const t=u(i.y/c);l.scrollTop+=t,o.y1-=t}if(i.x){const t=u(i.x/c);l.scrollLeft+=t,o.x1-=t}r.next(t),requestAnimationFrame(e)}else this.m=!1};requestAnimationFrame(e)}else r.next(t);this.Y(t)}Y(t){const{features:e}=this.S;(e.touch&&matchMedia("(hover: none), (pointer: coarse)").matches||this.p&&"safari"in window)&&t.preventDefault()}$(){const{g:t,S:{document:e}}=this,{scrollTop:s,scrollLeft:i}=e.scrollingElement||e.body;this.l.x1+=t.x-i,this.l.y1+=t.y-s,t.x=i,t.y=s,this.X(),this.L.next(null)}N(t){const{manualSpeed:e}=this.S.behaviour.scrolling,s=t.deltaY?t.deltaY>0?1:-1:0,i=t.deltaX?t.deltaX>0?1:-1:0;this.v.y+=s*e,this.v.x+=i*e,this.W(t),t.preventDefault()}M(){const{v:t,l:e,h:s,D:i,S:o}=this,{scrollTop:n,scrollHeight:h,clientHeight:r,scrollLeft:c,scrollWidth:u,clientWidth:p}=i,f=this.I,{x1:m,y1:v}=e;let{x2:g,y2:y}=e;const{behaviour:{scrolling:{startScrollMargins:_}}}=o;g<f.left+_.x?(t.x=c?-l(f.left-g+_.x):0,g=g<f.left?f.left:g):g>f.right-_.x?(t.x=u-c-p?l(f.left+f.width-g-_.x):0,g=g>f.right?f.right:g):t.x=0,y<f.top+_.y?(t.y=n?-l(f.top-y+_.y):0,y=y<f.top?f.top:y):y>f.bottom-_.y?(t.y=h-n-r?l(f.top+f.height-y-_.y):0,y=y>f.bottom?f.bottom:y):t.y=0;const x=d(m,g),b=d(v,y),S=a(m,g),A=a(v,y);s.x=x,s.y=b,s.width=S-x,s.height=A-b}k(){const{x:t,y:e,width:s,height:i}=this.h,{style:o}=this.A;o.left=`${t}px`,o.top=`${e}px`,o.width=`${s}px`,o.height=`${i}px`}R(t,s){const{document:i,features:n}=this.S,{u:h}=this;o(i,["mousemove","touchmove"],this.F),o(i,["touchmove","mousemove"],this.W),o(i,["mouseup","touchcancel","touchend"],this.R),o(i,"scroll",this.$),this.B(),t&&h&&n.singleTap.allow?this.q(t):h||s||(this.C(),this.j("stop",t)),this.v.x=0,this.v.y=0,this.p&&o(i,"wheel",this.N,{passive:!0}),this.T.remove(),this.L?.cancel(),e(this.A,"display","none")}C(){const{o:t,S:e,i:s,h:i}=this,{stored:o,selected:n,touched:r}=s,{intersect:c,overlap:l}=e.behaviour,a="invert"===l,d=[],u=[],p=[];for(let e=0;e<t.length;e++){const s=t[e];if(h(i,s.getBoundingClientRect(),c)){if(n.includes(s))o.includes(s)&&!r.includes(s)&&r.push(s);else{if(a&&o.includes(s)){p.push(s);continue}u.push(s)}d.push(s)}}a&&u.push(...o.filter((t=>!n.includes(t))));const f="keep"===l;for(let t=0;t<n.length;t++){const e=n[t];d.includes(e)||f&&o.includes(e)||p.push(e)}s.selected=d,s.changed={added:u,removed:p},this.H=d[d.length-1]}j(t,e){return this.emit(t,{event:e,store:this.i,selection:this})}B(){const{S:t,i:e}=this,{selected:s,changed:i,touched:o,stored:n}=e,h=s.filter((t=>!n.includes(t)));switch(t.behaviour.overlap){case"drop":e.stored=[...h,...n.filter((t=>!o.includes(t)))];break;case"invert":e.stored=[...h,...n.filter((t=>!i.removed.includes(t)))];break;case"keep":e.stored=[...n,...s.filter((t=>!n.includes(t)))]}}resolveSelectables(){this.o=r(this.S.selectables,this.S.document)}clearSelection(t=!0,e=!1){const{selected:s,stored:i,changed:o}=this.i;o.added=[],o.removed.push(...s,...t?i:[]),e||(this.j("move",null),this.j("stop",null)),this.H=void 0,this.i={stored:t?[]:i,selected:[],touched:[],changed:{added:[],removed:[]}}}getSelection(){return this.i.stored}getSelectionArea(){return this.A}cancel(t=!1){this.R(null,!t)}destroy(){this.cancel(),this.disable(),this.T.remove(),super.unbindAllListeners()}select(t,e=!1){const{changed:s,selected:i,stored:o}=this.i,n=r(t,this.S.document).filter((t=>!i.includes(t)&&!o.includes(t)));return o.push(...n),i.push(...n),s.added.push(...n),s.removed=[],this.H=void 0,e||(this.j("move",null),this.j("stop",null)),n}deselect(t,e=!1){const{selected:s,stored:i,changed:o}=this.i,n=r(t,this.S.document).filter((t=>s.includes(t)||i.includes(t)));n.length&&(this.i.stored=i.filter((t=>!n.includes(t))),this.i.selected=s.filter((t=>!n.includes(t))),this.i.changed.added=[],this.i.changed.removed.push(...n.filter((t=>!o.removed.includes(t)))),this.H=void 0,e||(this.j("move",null),this.j("stop",null)))}}SelectionArea.version="3.2.1";export{SelectionArea as default}; | ||
//# sourceMappingURL=viselect.esm.js.map |
{ | ||
"name": "@viselect/vanilla", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"description": "Simple, lightweight and modern library library for making visual DOM Selections.", | ||
@@ -41,3 +41,3 @@ "main": "./lib/viselect.cjs.js", | ||
}, | ||
"gitHead": "7585eee6a353abef375595385c8193e1735f8e72" | ||
"gitHead": "bd955decacd183bf19d75182cca7d7d23852543b" | ||
} |
@@ -16,3 +16,3 @@ const unitify = (val: string | number, unit = 'px'): string => { | ||
{style}: HTMLElement, | ||
attr: Partial<Record<string, string | number>> | string, | ||
attr: Partial<Record<keyof CSSStyleDeclaration, string | number>> | string, | ||
val?: string | number | ||
@@ -23,7 +23,7 @@ ): void { | ||
for (const [key, value] of Object.entries(attr)) { | ||
value !== undefined && style.setProperty(key, unitify(value)); | ||
value !== undefined && (style[key as any] = unitify(value)); | ||
} | ||
} else if (val !== undefined) { | ||
style.setProperty(attr, unitify(val)); | ||
style[attr as any] = unitify(val); | ||
} | ||
@@ -30,0 +30,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
194611