dragselect 3.1.5 → 3.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 3.1.6
2
+
3
+ - Fix auto-scroll up (and left) doing nothing when the document is scrolled to its very end. The scrolling element was detected by nudging `scrollTop` by one, which can not change at the end, so the body was scrolled instead of the document.
4
+ - Fix scroll detection on pages with `scroll-behavior: smooth`, browser zoom, or a body that is its own scroll container (`html { overflow: hidden } body { overflow: auto }`). The 1px scroll probe now uses `behavior: 'instant'`, accepts rounded values, and skips probing when the element is already scrolled. `canScroll` also really returns `false` now for areas that can not scroll (it always returned `true` before).
5
+ - Fix auto-scroll in areas whose scroll position goes negative: right-to-left (`dir="rtl"`) areas scrolling left, and `flex-direction: column-reverse` areas scrolling up.
6
+
1
7
  # 3.1.5
2
8
 
3
9
  - Fix `unsubscribe`: subscription ids are now unique and stable. Before, ids were array positions, so after one unsubscribe the other ids pointed to the wrong subscriber (or none).
@@ -1,6 +1,6 @@
1
1
  /***
2
2
 
3
- ~~~ Version 3.1.5 ~~~
3
+ ~~~ Version 3.1.6 ~~~
4
4
 
5
5
  ******************************************
6
6
 
@@ -131,42 +131,63 @@ const handleElementPositionAttribute = ({ computedStyle, node, }) => {
131
131
  node.style.position = 'relative';
132
132
  };
133
133
 
134
- let DOC_ELEMENT; // we store this in the module cache as it is highly unlikely the user to change document
134
+ const canScroll = (area) => {
135
+ if (!(area instanceof Document))
136
+ return canScrollElement(area);
137
+ // the document scrolls via html (body in quirks mode), or body as its own scroll container
138
+ const main = area.scrollingElement || area.documentElement;
139
+ return canScrollElement(main) || (!!area.body && canScrollElement(area.body));
140
+ };
141
+ /**
142
+ * Whether the element can scroll: probe it by 1px, read it back, restore.
143
+ * Already scrolled means it can (at the very end the probe could not move).
144
+ * Probes +1 then -1, since scrolling can also go negative
145
+ * (RTL scrollLeft, column-reverse scrollTop).
146
+ * `behavior: 'instant'` ignores `scroll-behavior: smooth`,
147
+ * and "did it change" (not `=== 1`) survives zoom rounding.
148
+ */
149
+ const canScrollElement = (el) => {
150
+ const { scrollTop: top, scrollLeft: left } = el;
151
+ if (top || left)
152
+ return true;
153
+ const moved = () => el.scrollTop !== top || el.scrollLeft !== left;
154
+ el.scrollTo({ top: top + 1, left: left + 1, behavior: 'instant' });
155
+ if (!moved())
156
+ el.scrollTo({ top: top - 1, left: left - 1, behavior: 'instant' });
157
+ const canScroll = moved();
158
+ el.scrollTo({ top, left, behavior: 'instant' });
159
+ return canScroll;
160
+ };
161
+
162
+ /**
163
+ * Returns the element that scrolls the document.
164
+ * Usually `document.scrollingElement` (html in standards mode, body in quirks mode).
165
+ * The body can also be its own scroll container,
166
+ * i.e. `html { overflow: hidden } body { overflow: auto }`.
167
+ */
168
+ const getDocumentScroller = (doc = document) => {
169
+ const main = (doc.scrollingElement || doc.documentElement);
170
+ const { body } = doc;
171
+ if (body && body !== main && !canScrollElement(main) && canScrollElement(body))
172
+ return body;
173
+ return main;
174
+ };
175
+
135
176
  /** Scroll the element in the specified direction */
136
177
  const scrollElement = (element, directions, multiplier = 1) => {
137
178
  if (!directions?.length || !element)
138
179
  return;
139
- let _element = element; // we are typecasting because if it's of type Document we grab the corresponding HTMLElement anyhow
140
- if (element instanceof Document) {
141
- if (DOC_ELEMENT)
142
- _element = DOC_ELEMENT; // cached
143
- // either the document is scrollable or the body is scrollable
144
- if (Number.isFinite(document?.documentElement?.scrollTop)) {
145
- const prev = document.documentElement.scrollTop;
146
- document.documentElement.scrollTop += 1;
147
- if (document.documentElement.scrollTop === prev) {
148
- _element = document.body;
149
- DOC_ELEMENT = document.body;
150
- }
151
- else {
152
- document.documentElement.scrollTop = prev;
153
- _element = document.documentElement;
154
- DOC_ELEMENT = document.documentElement;
155
- }
156
- }
157
- }
158
- const scrollTop = directions.includes('top') && _element.scrollTop > 0;
159
- const scrollBot = directions.includes('bottom') && _element.scrollTop < _element.scrollHeight;
160
- const scrollLeft = directions.includes('left') && _element.scrollLeft > 0;
161
- const scrollRight = directions.includes('right') && _element.scrollLeft < _element.scrollWidth;
162
- if (scrollTop)
163
- _element.scrollTop -= 1 * multiplier;
164
- if (scrollBot)
165
- _element.scrollTop += 1 * multiplier;
166
- if (scrollLeft)
167
- _element.scrollLeft -= 1 * multiplier;
168
- if (scrollRight)
169
- _element.scrollLeft += 1 * multiplier;
180
+ const _element = element instanceof Document ? getDocumentScroller(element) : element;
181
+ // no bounds checks: the browser clamps scrollTop/Left to the valid range,
182
+ // which can also be negative (RTL scrollLeft, column-reverse scrollTop)
183
+ if (directions.includes('top'))
184
+ _element.scrollTop -= multiplier;
185
+ if (directions.includes('bottom'))
186
+ _element.scrollTop += multiplier;
187
+ if (directions.includes('left'))
188
+ _element.scrollLeft -= multiplier;
189
+ if (directions.includes('right'))
190
+ _element.scrollLeft += multiplier;
170
191
  };
171
192
 
172
193
  class Area {
@@ -1425,25 +1446,6 @@ const getCurrentScroll = area => {
1425
1446
  };
1426
1447
  };
1427
1448
 
1428
- const canScroll = area => {
1429
- const scroll = getCurrentScroll(area);
1430
- if (scroll.x || scroll.y)
1431
- return true;
1432
- if (area instanceof Document) {
1433
- if (area.body)
1434
- return _canScroll(area.body);
1435
- return _canScroll(area.documentElement);
1436
- }
1437
- return _canScroll(area);
1438
- };
1439
- // @TODO: Determine if there is a better way to test scrollability
1440
- const _canScroll = (el) => {
1441
- const currentScrollTop = el.scrollTop;
1442
- const canScroll = Boolean(el.scrollTop = 1);
1443
- el.scrollTop = currentScrollTop;
1444
- return canScroll;
1445
- };
1446
-
1447
1449
  class ScrollStore {
1448
1450
  _initialVal = { x: 0, y: 0 };
1449
1451
  _currentVal = { x: 0, y: 0 };
@@ -1,6 +1,6 @@
1
1
  /***
2
2
 
3
- ~~~ Version 3.1.5 ~~~
3
+ ~~~ Version 3.1.6 ~~~
4
4
 
5
5
  ******************************************
6
6
 
@@ -137,42 +137,63 @@
137
137
  node.style.position = 'relative';
138
138
  };
139
139
 
140
- let DOC_ELEMENT; // we store this in the module cache as it is highly unlikely the user to change document
140
+ const canScroll = (area) => {
141
+ if (!(area instanceof Document))
142
+ return canScrollElement(area);
143
+ // the document scrolls via html (body in quirks mode), or body as its own scroll container
144
+ const main = area.scrollingElement || area.documentElement;
145
+ return canScrollElement(main) || (!!area.body && canScrollElement(area.body));
146
+ };
147
+ /**
148
+ * Whether the element can scroll: probe it by 1px, read it back, restore.
149
+ * Already scrolled means it can (at the very end the probe could not move).
150
+ * Probes +1 then -1, since scrolling can also go negative
151
+ * (RTL scrollLeft, column-reverse scrollTop).
152
+ * `behavior: 'instant'` ignores `scroll-behavior: smooth`,
153
+ * and "did it change" (not `=== 1`) survives zoom rounding.
154
+ */
155
+ const canScrollElement = (el) => {
156
+ const { scrollTop: top, scrollLeft: left } = el;
157
+ if (top || left)
158
+ return true;
159
+ const moved = () => el.scrollTop !== top || el.scrollLeft !== left;
160
+ el.scrollTo({ top: top + 1, left: left + 1, behavior: 'instant' });
161
+ if (!moved())
162
+ el.scrollTo({ top: top - 1, left: left - 1, behavior: 'instant' });
163
+ const canScroll = moved();
164
+ el.scrollTo({ top, left, behavior: 'instant' });
165
+ return canScroll;
166
+ };
167
+
168
+ /**
169
+ * Returns the element that scrolls the document.
170
+ * Usually `document.scrollingElement` (html in standards mode, body in quirks mode).
171
+ * The body can also be its own scroll container,
172
+ * i.e. `html { overflow: hidden } body { overflow: auto }`.
173
+ */
174
+ const getDocumentScroller = (doc = document) => {
175
+ const main = (doc.scrollingElement || doc.documentElement);
176
+ const { body } = doc;
177
+ if (body && body !== main && !canScrollElement(main) && canScrollElement(body))
178
+ return body;
179
+ return main;
180
+ };
181
+
141
182
  /** Scroll the element in the specified direction */
142
183
  const scrollElement = (element, directions, multiplier = 1) => {
143
184
  if (!directions?.length || !element)
144
185
  return;
145
- let _element = element; // we are typecasting because if it's of type Document we grab the corresponding HTMLElement anyhow
146
- if (element instanceof Document) {
147
- if (DOC_ELEMENT)
148
- _element = DOC_ELEMENT; // cached
149
- // either the document is scrollable or the body is scrollable
150
- if (Number.isFinite(document?.documentElement?.scrollTop)) {
151
- const prev = document.documentElement.scrollTop;
152
- document.documentElement.scrollTop += 1;
153
- if (document.documentElement.scrollTop === prev) {
154
- _element = document.body;
155
- DOC_ELEMENT = document.body;
156
- }
157
- else {
158
- document.documentElement.scrollTop = prev;
159
- _element = document.documentElement;
160
- DOC_ELEMENT = document.documentElement;
161
- }
162
- }
163
- }
164
- const scrollTop = directions.includes('top') && _element.scrollTop > 0;
165
- const scrollBot = directions.includes('bottom') && _element.scrollTop < _element.scrollHeight;
166
- const scrollLeft = directions.includes('left') && _element.scrollLeft > 0;
167
- const scrollRight = directions.includes('right') && _element.scrollLeft < _element.scrollWidth;
168
- if (scrollTop)
169
- _element.scrollTop -= 1 * multiplier;
170
- if (scrollBot)
171
- _element.scrollTop += 1 * multiplier;
172
- if (scrollLeft)
173
- _element.scrollLeft -= 1 * multiplier;
174
- if (scrollRight)
175
- _element.scrollLeft += 1 * multiplier;
186
+ const _element = element instanceof Document ? getDocumentScroller(element) : element;
187
+ // no bounds checks: the browser clamps scrollTop/Left to the valid range,
188
+ // which can also be negative (RTL scrollLeft, column-reverse scrollTop)
189
+ if (directions.includes('top'))
190
+ _element.scrollTop -= multiplier;
191
+ if (directions.includes('bottom'))
192
+ _element.scrollTop += multiplier;
193
+ if (directions.includes('left'))
194
+ _element.scrollLeft -= multiplier;
195
+ if (directions.includes('right'))
196
+ _element.scrollLeft += multiplier;
176
197
  };
177
198
 
178
199
  class Area {
@@ -1431,25 +1452,6 @@
1431
1452
  };
1432
1453
  };
1433
1454
 
1434
- const canScroll = area => {
1435
- const scroll = getCurrentScroll(area);
1436
- if (scroll.x || scroll.y)
1437
- return true;
1438
- if (area instanceof Document) {
1439
- if (area.body)
1440
- return _canScroll(area.body);
1441
- return _canScroll(area.documentElement);
1442
- }
1443
- return _canScroll(area);
1444
- };
1445
- // @TODO: Determine if there is a better way to test scrollability
1446
- const _canScroll = (el) => {
1447
- const currentScrollTop = el.scrollTop;
1448
- const canScroll = Boolean(el.scrollTop = 1);
1449
- el.scrollTop = currentScrollTop;
1450
- return canScroll;
1451
- };
1452
-
1453
1455
  class ScrollStore {
1454
1456
  _initialVal = { x: 0, y: 0 };
1455
1457
  _currentVal = { x: 0, y: 0 };
@@ -1 +1 @@
1
- const t=(t,e)=>{const s=e;window.addEventListener("resize",s),window.addEventListener("scroll",s);const i=new MutationObserver(s),r=new ResizeObserver(s);t.forEach(((t,e)=>{i.observe(t,{childList:0!==e,attributes:!0}),t instanceof Element&&r.observe(t)}));return{observer:i,resizeObserver:r,callback:s,cleanup:()=>{window.removeEventListener("resize",s),window.removeEventListener("scroll",s),i.disconnect(),r.disconnect()}}},e=(t,e)=>{let s;return(...i)=>{clearTimeout(s),s=setTimeout((()=>{s=void 0,t(...i)}),e)}},s=t=>{const e=(t,s=0)=>{const i=t[s]?.parentNode;return i?(t.push(i),s++,e(t,s)):t};return e([t])},i=({computedStyle:t,node:e})=>{const{position:s}=t;e instanceof Document||("absolute"===s||"relative"===s||"fixed"===s)||(e.style.position="relative")};let r;class n{DS;PS;Settings;_observers;_node;_parentNodes;_computedStyle;_computedBorder;_rect;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this._node=this.Settings.area,this.setArea(this.Settings.area),this.PS.subscribe("Settings:updated:area",(({settings:{area:t}})=>this.setArea(t))),this.PS.subscribe("Interaction:init",this.init),this.PS.subscribe("Interaction:end",this.reset)}setArea=t=>{this.reset(),this._node=t,i({computedStyle:this.computedStyle,node:this._node}),setTimeout((()=>{this.PS.publish("Area:modified:pre",{item:this.HTMLNode}),this.reset(),this.PS.publish("Area:modified",{item:this.HTMLNode})}))};init=()=>{this._observers=t(this.parentNodes,e((t=>{this.hasRelevantBeenModified()&&(this.PS.publish("Area:modified:pre",{event:t,item:this.HTMLNode}),this.reset(),this.PS.publish("Area:modified",{event:t,item:this.HTMLNode}))}),60))};hasRelevantBeenModified=()=>{const t=this.computedStyle,e=this.rect,s=this.computedBorder,i=this.parentNodes;return this.reset(),JSON.stringify(t)!==JSON.stringify(this.computedStyle)||(JSON.stringify(e)!==JSON.stringify(this.rect)||(JSON.stringify(s)!==JSON.stringify(this.computedBorder)||!(i.length===this.parentNodes.length||!i.some((t=>!this.parentNodes.includes(t))))))};reset=()=>{this._computedStyle=void 0,this._rect=void 0,this._computedBorder=void 0,this._parentNodes=void 0};stop=()=>{this._observers?.cleanup(),this.reset()};scroll=(t,e)=>{const s={scroll_directions:t,scroll_multiplier:e};this.PS.publish("Area:scroll:pre",s),((t,e,s=1)=>{if(!e?.length||!t)return;let i=t;if(t instanceof Document&&(r&&(i=r),Number.isFinite(document?.documentElement?.scrollTop))){const t=document.documentElement.scrollTop;document.documentElement.scrollTop+=1,document.documentElement.scrollTop===t?(i=document.body,r=document.body):(document.documentElement.scrollTop=t,i=document.documentElement,r=document.documentElement)}const n=e.includes("top")&&i.scrollTop>0,o=e.includes("bottom")&&i.scrollTop<i.scrollHeight,l=e.includes("left")&&i.scrollLeft>0,a=e.includes("right")&&i.scrollLeft<i.scrollWidth;n&&(i.scrollTop-=1*s),o&&(i.scrollTop+=1*s),l&&(i.scrollLeft-=1*s),a&&(i.scrollLeft+=1*s)})(this._node,t,e),this.PS.publish("Area:scroll",s)};get HTMLNode(){return this._node}get computedBorder(){return this._computedBorder?this._computedBorder:{top:parseInt(this.computedStyle.borderTopWidth),bottom:parseInt(this.computedStyle.borderBottomWidth),left:parseInt(this.computedStyle.borderLeftWidth),right:parseInt(this.computedStyle.borderRightWidth)}}get computedStyle(){if(this._computedStyle)return this._computedStyle;let t;return t=this.HTMLNode instanceof Document?window.getComputedStyle(this.HTMLNode.body||this.HTMLNode.documentElement):window.getComputedStyle(this.HTMLNode),this._computedStyle={borderTopWidth:t.borderTopWidth,borderBottomWidth:t.borderBottomWidth,borderLeftWidth:t.borderLeftWidth,borderRightWidth:t.borderRightWidth,position:t.position}}get rect(){return this._rect?this._rect:this._rect=((t,e)=>{if(t instanceof Document)return{top:0,left:0,bottom:0,right:0,width:window.innerWidth,height:window.innerHeight};const s=t.getBoundingClientRect();return{top:s.top,left:s.left,bottom:s.bottom,right:s.right,width:(t.clientWidth||s.width)*e,height:(t.clientHeight||s.height)*e}})(this.HTMLNode,this.DS.stores.SettingsStore.s.zoom)}get parentNodes(){return this._parentNodes?this._parentNodes:this._parentNodes=s(this.HTMLNode)}}const o=({x:t,y:e},s,{x:i,y:r})=>({"+":{x:t+i,y:e+r},"-":{x:t-i,y:e-r},"*":{x:t*i,y:e*r},"/":{x:t/i,y:e/r}}[s]),l=t=>({x:t.left,y:t.top}),a=(t,e=0)=>({left:t.x,top:t.y,right:t.x,bottom:t.y,width:e,height:e}),h=t=>({x:t,y:t}),c=t=>{const e={x:0,y:0},s=window.getComputedStyle(t);if(!s.transform||"none"===s.transform)return e;if(s.transform.indexOf("3d")>=0){const t=s.transform.trim().match(/matrix3d\((.*?)\)/);if(t&&t.length){const s=t[1]?.split(",");e.x=parseInt(s[12])||0,e.y=parseInt(s[13])||0}return e}const i=s.transform.trim().match(/matrix\((.*?)\)/);if(i&&i.length){const t=i[1]?.split(",");e.x=parseInt(t[4])||0,e.y=parseInt(t[5])||0}return e},d=(t,e)=>e?(t=>{const{transform:e}=t.style;if(!e||e.indexOf("translate")<0)return c(t);const s={x:0,y:0},i=e.trim().match(/translate[3dD]*?\(.*?\)/);if(i){const t=i[0]?.split("(");if(t){const e=t[1]?.split(",");s.x=parseInt(e[0])||0,s.y=parseInt(e[1])||0}}return s.x||s.x?s:c(t)})(t):(t=>{const{style:e}=t,s={x:parseInt(e.left)||0,y:parseInt(e.top)||0};if(!s.x&&!s.x){const e=window.getComputedStyle(t);return{x:parseInt(e.left)||0,y:parseInt(e.top)||0}}return s})(t),S=({containerRect:t,selectionRect:e,direction:s,scrollAmount:i})=>{const r={top:t.top-e.top+i.y,left:t.left-e.left+i.x,bottom:t.bottom-e.bottom+i.y,right:t.right-e.right+i.x};return 0===s.x&&0===s.y||(s.y<0&&(s.y=Math.max(s.y,r.top)),s.x<0&&(s.x=Math.max(s.x,r.left)),s.y>0&&(s.y=Math.min(s.y,r.bottom)),s.x>0&&(s.x=Math.min(s.x,r.right)),e.top+=s.y,e.bottom+=s.y,e.left+=s.x,e.right+=s.x),s};class u{_prevCursorPos;_prevScrollPos;_elements=[];_dragKeys;_dragKeysFlat=[];_selectionRect=a(h(0));DS;PS;Settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Settings:updated:dragKeys",this.assignDragKeys),this.assignDragKeys(),this.PS.subscribe("Interaction:start",this.start),this.PS.subscribe("Interaction:end",this.stop),this.PS.subscribe("Interaction:update",this.update),this.PS.subscribe("KeyStore:down",this.keyboardDrag),this.PS.subscribe("KeyStore:up",this.keyboardEnd)}assignDragKeys=()=>{this._dragKeys={up:this.Settings.dragKeys.up.map((t=>t.toLowerCase())),down:this.Settings.dragKeys.down.map((t=>t.toLowerCase())),left:this.Settings.dragKeys.left.map((t=>t.toLowerCase())),right:this.Settings.dragKeys.right.map((t=>t.toLowerCase()))},this._dragKeysFlat=[...this._dragKeys.up,...this._dragKeys.down,...this._dragKeys.left,...this._dragKeys.right]};keyboardDrag=({event:t,key:e})=>{const s=e.toLowerCase();if(!this.Settings.keyboardDrag||!this._dragKeysFlat.includes(s)||!this.DS.SelectedSet.size||!this.Settings.draggability||this.DS.continue)return;const i={event:t,isDragging:!0,isDraggingKeyboard:!0,key:e};this.PS.publish(["Interaction:start:pre","Interaction:start"],i),this._elements=this.DS.getSelection(),this._selectionRect=this.DS.Selection.boundingRect,this.handleZIndex(!0);let r=(({shiftKey:t,keyboardDragSpeed:e,zoom:s,key:i,dragKeys:r,scrollDiff:n})=>{const o={x:0,y:0},l=t?4*e*s:e*s;return r?.left.includes(i)&&(o.x=n.x||-l),r?.right.includes(i)&&(o.x=n.x||l),r?.up.includes(i)&&(o.y=n.y||-l),r?.down.includes(i)&&(o.y=n.y||l),o})({shiftKey:this.DS.stores.KeyStore.currentValues.includes("shift"),keyboardDragSpeed:this.Settings.keyboardDragSpeed,zoom:this.Settings.zoom,key:s,scrollDiff:this._scrollDiff,dragKeys:this._dragKeys});r=S({direction:r,containerRect:this.DS.SelectorArea.rect,scrollAmount:this.DS.stores.ScrollStore.scrollAmount,selectionRect:this._selectionRect}),this.moveElements(r),this.PS.publish(["Interaction:update:pre","Interaction:update"],i)};keyboardEnd=({event:t,key:e})=>{const s=e.toLowerCase();if(!(this.Settings.keyboardDrag&&this._dragKeysFlat.includes(s)&&this.DS.SelectedSet.size&&this.Settings.draggability))return;const i={event:t,isDragging:this.Settings.draggability,isDraggingKeyboard:!0,key:e};this.PS.publish(["Interaction:end:pre","Interaction:end"],i)};start=({isDragging:t,isDraggingKeyboard:e})=>{t&&!e&&(this._prevCursorPos=void 0,this._prevScrollPos=void 0,this._elements=this.DS.getSelection(),this._selectionRect=this.DS.Selection.boundingRect,this.handleZIndex(!0))};stop=()=>{this._prevCursorPos=void 0,this._prevScrollPos=void 0,this.handleZIndex(!1),this._elements=[]};update=({isDragging:t,isDraggingKeyboard:e})=>{if(!t||!this._elements.length||e||this.DS.continue)return;let s=o(this._cursorDiff,"+",this._scrollDiff);s=S({direction:s,containerRect:this.DS.SelectorArea.rect,scrollAmount:this.DS.stores.ScrollStore.scrollAmount,selectionRect:this._selectionRect}),this.moveElements(s)};handleZIndex=t=>{this.Settings.useLayers&&this._elements.forEach((e=>e.style.zIndex=`${(parseInt(e.style.zIndex)||0)+(t?9999:-9998)}`))};moveElements=t=>{const{elements:e,direction:s}=this.filterDragElements({elements:this._elements,direction:t});e.forEach((t=>{(({element:t,posDirection:e,useTransform:s})=>{const i=d(t,s);((t,e,s)=>{if(s){const s=t.style.transform;t.style.transform=`translate3d(${e.x}px,${e.y}px,1px) ${s.replace(/translate.*?\)/g,"")}`}else t.style.left=`${e.x}px`,t.style.top=`${e.y}px`})(t,o(i,"+",e),s)})({element:t,posDirection:s,containerRect:this.DS.SelectorArea.rect,useTransform:this.Settings.useTransform})}))};get _cursorDiff(){const t=this.DS.stores.PointerStore.currentVal,e=this._prevCursorPos?o(t,"-",this._prevCursorPos):{x:0,y:0};return this._prevCursorPos=t,e}get _scrollDiff(){const t=this.DS.stores.ScrollStore.currentVal,e=this._prevScrollPos?o(t,"-",this._prevScrollPos):{x:0,y:0};return this._prevScrollPos=t,e}filterDragElements=({elements:t,direction:e})=>({elements:t,direction:e})}const p=(t,e,s=0)=>{if(!t||!e)return!1;let i=t;if(s>0){const e=(t.right-t.left)*s,r=(t.bottom-t.top)*s;i={left:t.left+e,right:t.right-e,top:t.top+r,bottom:t.bottom-r}}return i.left<e.right&&i.right>e.left&&i.top<e.bottom&&i.bottom>e.top},g=t=>t?Array.isArray(t)||"function"==typeof t[Symbol.iterator]?[...new Set([...t])]:[t]:[];class m{id;element;_droppables;_rect;_observers;_timeout;_itemsDropped=[];_itemsInside;DS;PS;Settings;isDestroyed=!1;_parentNodes;constructor({DS:s,PS:i,id:r,element:n,droppables:o}){this.DS=s,this.PS=i,this.Settings=this.DS.stores.SettingsStore.s,this.id=r,this.element=n,o&&(this.droppables=g(o)),this.element.classList.add(`${this.Settings.dropZoneClass}`),this.PS.subscribe("Settings:updated:dropZoneClass",(({settings:t})=>{this.element&&(this.element.classList.remove(t["dropZoneClass:pre"]),this.element.classList.add(t.dropZoneClass))})),this._observers=t(this.parentNodes,e((()=>this._rect=void 0),this.Settings.refreshMemoryRate)),this.PS.subscribe("Interaction:start",this.start),this.PS.subscribe("Interaction:end",this.stop)}setReadyClasses=t=>{if(this.isDestroyed)return;const e=this.droppables.filter((t=>this.DS.SelectedSet.has(t)));e.length&&(e.forEach((e=>{e.classList[t](`${this.Settings.droppableClass}`),e.classList[t](`${this.Settings.droppableClass}-${this.id}`)})),this.element.classList[t](`${this.Settings.dropZoneReadyClass}`))};handleNoDrop=()=>{this.isDestroyed||(this.DS.SelectedSet.forEach((t=>{t.classList.remove(this.Settings.droppedTargetClass),t.classList.remove(`${this.Settings.droppedTargetClass}-${this.id}`)})),this._itemsDropped=this._itemsDropped.filter((t=>!this.DS.SelectedSet.has(t))),this._itemsDropped?.length||this.element.classList.remove(`${this.Settings.dropZoneTargetClass}`))};handleDrop=()=>{this.isDestroyed||(this._itemsDropped=[...new Set([...this._itemsDropped,...this.droppables?.filter((t=>this.DS.SelectedSet.has(t)))])],this._itemsDropped?.forEach((t=>{t.classList.add(`${this.Settings.droppedTargetClass}`),t.classList.add(`${this.Settings.droppedTargetClass}-${this.id}`)})),this._itemsDropped?.length&&this.element.classList.add(`${this.Settings.dropZoneTargetClass}`))};handleItemsInsideClasses=()=>{let t=!1;this.droppables.forEach((e=>{this.itemsInside?.includes(e)?(e.classList.add(`${this.Settings.droppedInsideClass}`),e.classList.add(`${this.Settings.droppedInsideClass}-${this.id}`),t=!0):(e.classList.remove(`${this.Settings.droppedInsideClass}-${this.id}`),e.className.includes(`${this.Settings.droppedInsideClass}-`)||e.classList.remove(`${this.Settings.droppedInsideClass}`))})),t?this.element.classList.add(`${this.Settings.dropZoneInsideClass}`):this.element.classList.remove(`${this.Settings.dropZoneInsideClass}`)};start=({isDragging:t})=>{t&&!this.isDestroyed&&this.setReadyClasses("add")};stop=({isDragging:t})=>{t&&!this.isDestroyed&&(this.setReadyClasses("remove"),this.handleItemsInsideClasses())};destroy(){this._observers?.cleanup(),this.element.classList.remove(`${this.Settings.dropZoneClass}`),this.element.classList.remove(`${this.Settings.dropZoneTargetClass}`),this.element.classList.remove(`${this.Settings.dropZoneReadyClass}`),this.droppables.forEach((t=>{t.classList.remove(`${this.Settings.droppedTargetClass}`),t.classList.remove(`${this.Settings.droppedTargetClass}-${this.id}`),t.classList.remove(`${this.Settings.droppableClass}`),t.classList.remove(`${this.Settings.droppableClass}-${this.id}`)})),this.PS.unsubscribe("Interaction:start",this.start),this.PS.unsubscribe("Interaction:end",this.stop),this.isDestroyed=!0}toObject=()=>({id:this.id,element:this.element,droppables:this.droppables,itemsDropped:this.itemsDropped,itemsInside:this.itemsInside});get rect(){if(!this.isDestroyed)return this._rect?this._rect:this._rect=this.element.getBoundingClientRect()}get itemsDropped(){if(!this.isDestroyed)return this._itemsDropped}get itemsInside(){if(!this.isDestroyed)return this._itemsInside||(this._itemsInside=this.droppables.flatMap((t=>{const e=this.DS.SelectableSet.rects.get(t);return this.rect&&p(e,this.rect,this.Settings.dropInsideThreshold)?[t]:[]})),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout((()=>this._itemsInside=void 0),this.Settings.refreshMemoryRate)),this._itemsInside}get parentNodes(){return this._parentNodes?this._parentNodes:this._parentNodes=s(this.element)}get droppables(){return this._droppables?this._droppables:this.DS.SelectableSet.elements}set droppables(t){this._droppables=t}}class b{_zoneByElement=new Map;_zoneById=new Map;_zonesByDroppable=new Map;_zones;DS;PS;Settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Settings:updated:dropZones",(({settings:t})=>this.setDropZones(t))),this.setDropZones({dropZones:this.Settings.dropZones}),this.PS.subscribe("Interaction:end",this.stop)}setDropZones=({dropZones:t})=>{t&&(this._zones&&this._zones.forEach((t=>t.destroy())),this._zones=t.map((t=>new m({DS:this.DS,PS:this.PS,...t}))),this._zones.forEach((t=>{this._zoneByElement.set(t.element,t),this._zoneById.set(t.id,t),t.droppables.forEach((e=>{const s=this._zonesByDroppable.get(e);if(!s?.length)return this._zonesByDroppable.set(e,[t]);this._zonesByDroppable.set(e,[...new Set([...s,t])])}))})))};_handleDrops=t=>{this._zones?.forEach((e=>{e!==t&&e.handleNoDrop()})),t&&t.handleDrop()};_getZoneByElementsFromPoint=(t,{x:e,y:s})=>{for(let i=0,r=t.length;i<r;i++){const r=this._zoneByElement.get(t[i]);if(p(r?.rect,{left:e,right:e,top:s,bottom:s},Math.min(this.Settings.dropTargetThreshold,.5)))return r}};stop=({isDragging:t,isDraggingKeyboard:e,event:s})=>{if(!t)return;const i=this.getTarget({isDraggingKeyboard:e,event:s});this._handleDrops(i)};getItemsDroppedById=t=>{const e=this._zoneById.get(t);return e?e.itemsDropped:console.warn(`[DragSelect] No zone found (id: ${t})`)};getItemsInsideById=(t,e)=>{const s=this._zoneById.get(t);return s?(e&&s.handleItemsInsideClasses(),s.itemsInside):console.warn(`[DragSelect] No zone found (id: ${t})`)};getKeyboardItemCenter=(t,e)=>{if(!t||!e)return;const s=e.target?.getBoundingClientRect();return{x:s.left+s.width/2,y:s.top+s.height/2}};getTarget=({coordinates:t,isDraggingKeyboard:e,event:s})=>{if(!this._zones?.length)return;let i;!t&&e&&s&&(i=this.getKeyboardItemCenter(e,s));const r=t?.x||i?.x||this.DS.stores.PointerStore.currentVal.x,n=t?.y||i?.y||this.DS.stores.PointerStore.currentVal.y,o=document.elementsFromPoint(r,n);return this._getZoneByElementsFromPoint(o,{x:r,y:n})}}class y{isInteracting;isDragging=!1;DS;PS;Settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Settings:updated:area",(({settings:t})=>{this.removeAreaEventListeners(t["area:pre"]),this.setAreaEventListeners(t.area)})),this.PS.subscribe("PointerStore:updated",(({event:t})=>this.update({event:t}))),this.PS.subscribe("Selectable:click",this.onClick),this.PS.subscribe("Selectable:pointer",(({event:t})=>this.start(t))),this.PS.subscribe("Interaction:start:pre",(({event:t})=>this._start(t))),this.PS.subscribe("Interaction:init:pre",this._init),this.PS.subscribe("Interaction:end:pre",(({event:t})=>this._reset(t))),this.PS.subscribe("Area:scroll",this.update)}init=()=>this.PS.publish("Interaction:init:pre",{init:!0});_init=()=>{this.stop(),this.setAreaEventListeners(),this.PS.publish("Interaction:init",{init:!0})};_canInteract(t){const e="clientX"in t&&0===t.clientX&&0===t.clientY&&0===t.detail&&t.target;return!("button"in t&&2===t.button||this.isInteracting||t.target&&!this.DS.SelectorArea.isInside(t.target)||!e&&!this.DS.SelectorArea.isClicked(t))}start=t=>this.PS.publish("Interaction:start:pre",{event:t,isDragging:this.isDragging});_start=t=>{"touchstart"===t.type&&t.preventDefault(),this._canInteract(t)&&(this.isInteracting=!0,this.isDragging=this.isDragEvent(t),this.PS.publish("Interaction:start",{event:t,isDragging:this.isDragging}),this.setDocEventListeners())};isDragEvent=t=>{let e=null;return t.target&&"closest"in t.target&&(e=t.target.closest(`.${this.Settings.selectableClass}`)),!(!this.Settings.draggability||this.DS.stores.KeyStore.isMultiSelectKeyPressed(t)||!e)&&(this.Settings.immediateDrag&&(this.DS.SelectedSet.size?this.DS.SelectedSet.has(e)||(this.DS.SelectedSet.clear(),this.DS.SelectedSet.add(e)):this.DS.SelectedSet.add(e)),!!this.DS.SelectedSet.has(e))};onClick=({event:t})=>{if(!this._canInteract(t))return;if(t.detail>0)return;const{stores:{PointerStore:e,KeyStore:s},SelectableSet:i,SelectedSet:r}=this.DS;e.start(t);const n=t.target;n&&!i.has(n)||(s.isMultiSelectKeyPressed(t)||r.clear(),n&&r.toggle(n),this.reset(t))};stop=(t=this.DS.Area.HTMLNode)=>{this.removeAreaEventListeners(t),this.removeDocEventListeners()};update=({event:t,scroll_directions:e,scroll_multiplier:s})=>{this.isInteracting&&this.PS.publish(["Interaction:update:pre","Interaction:update"],{event:t,scroll_directions:e,scroll_multiplier:s,isDragging:this.isDragging})};reset=t=>this.PS.publish("Interaction:end:pre",{event:t,isDragging:this.isDragging});_reset=t=>{const{isDragging:e}=this;this.isInteracting=!1,this.isDragging=!1,this.removeDocEventListeners(),this.PS.publish("Interaction:end",{event:t,isDragging:e})};setAreaEventListeners=(t=this.DS.Area.HTMLNode)=>{this.Settings.usePointerEvents?t.addEventListener("pointerdown",this.start,{passive:!1}):t.addEventListener("mousedown",this.start),t.addEventListener("touchstart",this.start,{passive:!1})};removeAreaEventListeners=(t=this.DS.Area.HTMLNode)=>{this.Settings.usePointerEvents?t.removeEventListener("pointerdown",this.start,{passive:!1}):t.removeEventListener("mousedown",this.start),t.removeEventListener("touchstart",this.start,{passive:!1})};setDocEventListeners=()=>{this.Settings.usePointerEvents?(document.addEventListener("pointerup",this.reset),document.addEventListener("pointercancel",this.reset)):document.addEventListener("mouseup",this.reset),document.addEventListener("touchend",this.reset)};removeDocEventListeners=()=>{this.Settings.usePointerEvents?(document.removeEventListener("pointerup",this.reset),document.removeEventListener("pointercancel",this.reset)):document.removeEventListener("mouseup",this.reset),document.removeEventListener("touchend",this.reset)}}class D{_currentValues=new Set;_keyMapping={control:"ctrlKey",shift:"shiftKey",meta:"metaKey"};DS;PS;settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Interaction:init",this.init)}init=()=>{document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup),window.addEventListener("blur",this.reset)};keydown=t=>{if(!t.key?.toLocaleLowerCase)return;const e=t.key.toLowerCase();this.PS.publish("KeyStore:down:pre",{event:t,key:e}),this._currentValues.add(e),this.PS.publish("KeyStore:down",{event:t,key:e})};keyup=t=>{if(!t.key?.toLocaleLowerCase)return;const e=t.key.toLowerCase();this.PS.publish("KeyStore:up:pre",{event:t,key:e}),this._currentValues.delete(e),this.PS.publish("KeyStore:up",{event:t,key:e})};stop=()=>{document.removeEventListener("keydown",this.keydown),document.removeEventListener("keyup",this.reset),window.removeEventListener("blur",this.reset),this.reset()};reset=()=>this._currentValues.clear();isMultiSelectKeyPressed(t){if(this.settings.multiSelectMode)return!0;const e=this.settings.multiSelectKeys?.map((t=>t.toLocaleLowerCase()))??[];return!!this.currentValues.some((t=>e.includes(t)))||!(!t||!e.some((e=>t[this._keyMapping[e]])))}get currentValues(){return Array.from(this._currentValues.values())}}class _{_isMouseInteraction=!1;_initialValArea={x:0,y:0};_currentValArea={x:0,y:0};_lastValArea={x:0,y:0};_initialVal={x:0,y:0};_currentVal={x:0,y:0};_lastVal={x:0,y:0};_lastTouch;DS;PS;settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Interaction:init",this.init),this.PS.subscribe("Interaction:start",(({event:t})=>this.start(t))),this.PS.subscribe("Interaction:end",(({event:t})=>this.reset(t)))}init=()=>{this.settings.usePointerEvents?document.addEventListener("pointermove",this.update,{passive:!1}):document.addEventListener("mousemove",this.update),document.addEventListener("touchmove",this.update,{passive:!1})};start(t){t&&(this._isMouseInteraction=!0,this.currentVal=this.initialVal=this.getPointerPosition(t))}getPointerPosition=t=>(({event:t})=>({x:t.clientX,y:t.clientY}))({event:this._normalizedEvent(t)});update=t=>{t&&(this.PS.publish("PointerStore:updated:pre",{event:t}),this.currentVal=this.getPointerPosition(t),this._isMouseInteraction&&this.PS.publish("PointerStore:updated",{event:t}))};stop=()=>{this.settings.usePointerEvents?document.removeEventListener("pointermove",this.update,{passive:!1}):document.removeEventListener("mousemove",this.update),document.removeEventListener("touchmove",this.update,{passive:!1}),this.reset()};reset=t=>{this.currentVal=this.lastVal=this.getPointerPosition(t),setTimeout((()=>this._isMouseInteraction=!1),100)};_normalizedEvent(t){return!t||t instanceof KeyboardEvent?{clientX:0,clientY:0}:"touches"in t?("touchend"!==t.type&&(this._lastTouch=t),this._lastTouch?.touches[0]||t.touches[0]):t}get initialValArea(){return this._initialValArea?this._initialValArea:{x:0,y:0}}get currentValArea(){return this._currentValArea?this._currentValArea:{x:0,y:0}}get lastValArea(){return this._lastValArea?this._lastValArea:{x:0,y:0}}get initialVal(){return this._initialVal?this._initialVal:{x:0,y:0}}get currentVal(){return this._currentVal?this._currentVal:{x:0,y:0}}get lastVal(){return this._lastVal?this._lastVal:{x:0,y:0}}set initialVal(t){this._initialVal=t,this._initialValArea=t&&o(t,"-",o(l(this.DS.Area.rect),"+",l(this.DS.Area.computedBorder)))}set currentVal(t){this._currentVal=t,this._currentValArea=t&&o(t,"-",o(l(this.DS.Area.rect),"+",l(this.DS.Area.computedBorder)))}set lastVal(t){this._lastVal=t,this._lastValArea=t&&o(t,"-",o(l(this.DS.Area.rect),"+",l(this.DS.Area.computedBorder)))}}class v{subscribers={};_ids={};_nextId=0;DS;constructor({DS:t}){this.DS=t}subscribe=(t,e)=>{this.subscribers[t]||(this.subscribers[t]=[]),this._ids[t]||(this._ids[t]=[]);const s=this.subscribers[t],i=this._ids[t],r=this._nextId++;return s.push(e),i.push(r),r};unsubscribe=(t,e,s)=>{const i=this.subscribers[t],r=this._ids[t];if(!i||!r)return;const n=null!=s?r.indexOf(s):e?i.indexOf(e):-1;-1!==n&&(i.splice(n,1),r.splice(n,1))};publish=(t,e)=>{Array.isArray(t)?t.forEach((t=>this._publish(t,e))):this._publish(t,e)};_publish=(t,e)=>{const s=[...this.subscribers[t]??[]];t.includes(":pre")?this._handlePrePublish(s,e):this._handlePublish(s,e)};_handlePublish=(t,e)=>{for(let s=0,i=t.length;s<i;s++){if(this.DS.stopped)return;t[s]?.(e)}};_handlePrePublish=(t,e)=>{let s=t.length;for(;s--;){if(this.DS.stopped)return;t[s]?.(e)}}}const P=()=>({y:document.body?.scrollTop||document.documentElement?.scrollTop||0,x:document.body?.scrollLeft||document.documentElement?.scrollLeft||0}),f=t=>!t||t instanceof Document?P():{x:t.scrollLeft>=0?t.scrollLeft:P().x,y:t.scrollTop>=0?t.scrollTop:P().y},I=t=>{const e=t.scrollTop,s=Boolean(t.scrollTop=1);return t.scrollTop=e,s};class L{_initialVal={x:0,y:0};_currentVal={x:0,y:0};_canScroll;DS;PS;Settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Area:modified",(()=>{this.stop(),this.init()})),this.PS.subscribe("Interaction:init",this.init),this.PS.subscribe("Interaction:start",(()=>this.start())),this.PS.subscribe("Interaction:end",(()=>this.reset()))}init=()=>this.addListeners();addListeners=()=>this.DS.Area.HTMLNode.addEventListener("scroll",this.update);removeListeners=()=>this.DS.Area.HTMLNode.removeEventListener("scroll",this.update);start=()=>{this._currentVal=this._initialVal=f(this.DS.Area.HTMLNode)};update=()=>this._currentVal=f(this.DS.Area.HTMLNode);stop=()=>{this.reset(),this.removeListeners()};reset=()=>{this._initialVal={x:0,y:0},this._canScroll=void 0};get canScroll(){return"boolean"==typeof this._canScroll?this._canScroll:this._canScroll=(t=>{const e=f(t);return!(!e.x&&!e.y)||(t instanceof Document?t.body?I(t.body):I(t.documentElement):I(t))})(this.DS.Area.HTMLNode)}get scrollAmount(){const t=o(this.currentVal,"-",this.initialVal),e=h(this.Settings.zoom),s=o(o(t,"*",e),"-",t);return{x:t.x+s.x,y:t.y+s.y}}get initialVal(){return this._initialVal?this._initialVal:{x:0,y:0}}get currentVal(){return this._currentVal||(this._currentVal=f(this.DS.Area.HTMLNode)),this._currentVal}}class T extends Set{_rects;_timeout;DS;PS;Settings;constructor({DS:t,PS:e}){super(),this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Interaction:init",this.init),this.PS.subscribe("Settings:updated:selectables",(()=>{this.clear(),this.init()})),this.PS.subscribe("Settings:updated:selectableClass",(({settings:t})=>{this.forEach((e=>{e.classList.remove(t["selectableClass:pre"]),e.classList.add(t.selectableClass)}))}))}init=()=>g(this.Settings.selectables).forEach((t=>this.add(t)));add(t){if(!t||super.has(t))return this;const e={items:this.elements,item:t};return this.PS.publish("Selectable:added:pre",e),t.classList.add(this.Settings.selectableClass),t.addEventListener("click",this._onClick),this.Settings.usePointerEvents?t.addEventListener("pointerdown",this._onPointer,{passive:!1}):t.addEventListener("mousedown",this._onPointer),t.addEventListener("touchstart",this._onPointer,{passive:!1}),this.Settings.draggability&&!this.Settings.useTransform&&i({computedStyle:window.getComputedStyle(t),node:t}),this.PS.publish("Selectable:added",e),super.add(t)}delete(t){if(!t||!super.has(t))return!0;const e={items:this.elements,item:t};return this.PS.publish("Selectable:removed:pre",e),t.classList.remove(this.Settings.selectableClass),t.classList.remove(this.Settings.hoverClass),t.removeEventListener("click",this._onClick),this.Settings.usePointerEvents?t.removeEventListener("pointerdown",this._onPointer,{passive:!1}):t.removeEventListener("mousedown",this._onPointer),t.removeEventListener("touchstart",this._onPointer,{passive:!1}),this.PS.publish("Selectable:removed",e),super.delete(t)}clear=()=>this.forEach((t=>this.delete(t)));_onClick=t=>this.PS.publish(["Selectable:click:pre","Selectable:click"],{event:t});_onPointer=t=>this.PS.publish(["Selectable:pointer:pre","Selectable:pointer"],{event:t});addAll=t=>t.forEach((t=>this.add(t)));deleteAll=t=>t.forEach((t=>this.delete(t)));getElementRect=t=>this._rects?this._rects.get(t):t.getBoundingClientRect();get elements(){return Array.from(this.values())}get rects(){return this._rects||(this._rects=new Map,this.forEach((t=>this._rects?.set(t,t.getBoundingClientRect()))),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout((()=>this._rects=void 0),this.Settings.refreshMemoryRate)),this._rects}}class E extends Set{_rects;_timeout;DS;PS;Settings;constructor({DS:t,PS:e}){super(),this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s}add(t){if(!t||super.has(t))return this;const e={items:this.elements,item:t};return this.PS.publish("Selected:added:pre",e),super.add(t),t.classList.add(this.Settings.selectedClass),this.Settings.useLayers&&(t.style.zIndex=`${(parseInt(t.style.zIndex)||0)+1}`),this.PS.publish("Selected:added",e),this}delete(t){if(!t||!super.has(t))return!0;const e={items:this.elements,item:t};this.PS.publish("Selected:removed:pre",e);const s=super.delete(t);return t.classList.remove(this.Settings.selectedClass),this.Settings.useLayers&&(t.style.zIndex=""+((parseInt(t.style.zIndex)||0)-1)),this.PS.publish("Selected:removed",e),s}clear=()=>this.forEach((t=>this.delete(t)));toggle(t){return this.has(t)?this.delete(t):this.add(t),t}addAll=t=>t.forEach((t=>this.add(t)));deleteAll=t=>t.forEach((t=>this.delete(t)));get elements(){return Array.from(this.values())}get rects(){return this._rects||(this._rects=new Map,this.forEach((t=>this._rects?.set(t,t.getBoundingClientRect()))),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout((()=>this._rects=void 0),this.Settings.refreshMemoryRate)),this._rects}}var C=(t,e)=>{e.left&&(t.style.left=`${e.left}px`),e.top&&(t.style.top=`${e.top}px`),e.width&&(t.style.width=`${e.width}px`),e.height&&(t.style.height=`${e.height}px`)};class x{_rect;DS;PS;Settings;HTMLNode;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.HTMLNode=this.Settings.selector,this.PS.subscribe("Settings:updated:selectorClass",(({settings:t})=>{this.HTMLNode.classList.remove(t["selectorClass:pre"]),this.HTMLNode.classList.add(t.selectorClass)})),this.PS.subscribe("Settings:updated:selector",this.attachSelector),this.PS.subscribe("Settings:updated:customStyles",this.attachSelector),this.attachSelector(),this.PS.subscribe("Interaction:start",this.start),this.PS.subscribe("Interaction:update",this.update),this.PS.subscribe("Interaction:end",this.stop)}attachSelector=()=>{this.HTMLNode&&this.DS.SelectorArea?.HTMLNode&&this.DS.SelectorArea.HTMLNode.removeChild(this.HTMLNode),this.HTMLNode=this.Settings.selector||(t=>{const e=document.createElement("div");return e.style.position="absolute",t||(e.style.background="rgba(0, 175, 255, 0.2)",e.style.border="1px solid rgba(0, 175, 255, 0.8)",e.style.display="none",e.style.pointerEvents="none"),e})(this.Settings.customStyles),this.HTMLNode.classList.add(this.Settings.selectorClass),this.HTMLNode&&this.DS.SelectorArea?.HTMLNode&&this.DS.SelectorArea.HTMLNode.appendChild(this.HTMLNode)};start=({isDragging:t})=>{if(t)return;const{stores:{PointerStore:e}}=this.DS,s=e.initialValArea;C(this.HTMLNode,a(s,1)),this.HTMLNode.style.display="block",this._rect=void 0};stop=()=>{this.HTMLNode.style.width="0",this.HTMLNode.style.height="0",this.HTMLNode.style.display="none"};update=({isDragging:t})=>{if(t||this.DS.continue)return;const{stores:{ScrollStore:e,PointerStore:s}}=this.DS,i=(({scrollAmount:t,initialPointerPos:e,pointerPos:s})=>{const i={};return s.x>e.x-t.x?(i.left=e.x-t.x,i.width=s.x-e.x+t.x):(i.left=s.x,i.width=e.x-s.x-t.x),s.y>e.y-t.y?(i.top=e.y-t.y,i.height=s.y-e.y+t.y):(i.top=s.y,i.height=e.y-s.y-t.y),i})({scrollAmount:e.scrollAmount,initialPointerPos:s.initialValArea,pointerPos:s.currentValArea});C(this.HTMLNode,i),this._rect=void 0};get rect(){return this._rect?this._rect:this._rect=this.HTMLNode.getBoundingClientRect()}}class A{_prevSelectedSet=new Set;_boundingRect;_timeout;DS;PS;Settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Interaction:start",this.start),this.PS.subscribe("Interaction:update",this.update)}_storePrevious(t){const{stores:{KeyStore:e},SelectedSet:s}=this.DS;e.isMultiSelectKeyPressed(t)?this._prevSelectedSet=new Set(s):this._prevSelectedSet=new Set}start=({event:t,isDragging:e})=>{e||(this._storePrevious(t),this._handleInsideSelection(!0,t))};update=({isDragging:t})=>{t||this.DS.continue||this._handleInsideSelection()};_handleInsideSelection=(t,e)=>{const{SelectableSet:s,SelectorArea:i,Selector:r}=this.DS,n=this.DS.stores.KeyStore.isMultiSelectKeyPressed(e)&&this.Settings.multiSelectToggling,o=this.Settings.selectionThreshold,l=s.rects,a=r.rect,h=new Map,c=new Map;for(const[t,e]of l)i.isInside(t,e)&&(p(e,a,o)?h.set(t,e):c.set(t,e));if(this.DS.continue)return;const{select:d,unselect:S}=this.filterSelected({select:h,unselect:c,selectorRect:a});d.forEach(((e,s)=>(({element:t,force:e,multiSelectionToggle:s,SelectedSet:i,hoverClassName:r})=>{t.classList.contains(r)&&!e||(i.has(t)?s&&i.delete(t):i.add(t),t.classList.add(r))})({element:s,force:t,multiSelectionToggle:n,SelectedSet:this.DS.SelectedSet,hoverClassName:this.Settings.hoverClass}))),S.forEach(((e,s)=>(({element:t,force:e,SelectedSet:s,PrevSelectedSet:i,hoverClassName:r})=>{if(!t.classList.contains(r)&&!e)return;const n=s.has(t),o=i.has(t);n&&!o?s.delete(t):!n&&o&&s.add(t),t.classList.remove(r)})({element:s,force:t,SelectedSet:this.DS.SelectedSet,hoverClassName:this.Settings.hoverClass,PrevSelectedSet:this._prevSelectedSet})))};get boundingRect(){return this._boundingRect||(this._boundingRect=(t=>{const e={top:Number.POSITIVE_INFINITY,left:Number.POSITIVE_INFINITY,bottom:Number.NEGATIVE_INFINITY,right:Number.NEGATIVE_INFINITY,width:Number.NEGATIVE_INFINITY,height:Number.NEGATIVE_INFINITY};return t.rects.forEach((t=>{e.top=Math.min(e.top,t.top||e.top),e.left=Math.min(e.left,t.left||e.left),e.bottom=Math.max(e.bottom,t.bottom||e.bottom),e.right=Math.max(e.right,t.right||e.right)})),e.height=e.bottom-e.top,e.width=e.right-e.left,e})(this.DS.SelectedSet),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout((()=>this._boundingRect=void 0),this.Settings.refreshMemoryRate)),this._boundingRect}filterSelected=({select:t,unselect:e,selectorRect:s})=>({select:t,unselect:e})}class w{_scrollInterval;_rect;currentEdges=[];DS;PS;Settings;HTMLNode;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.HTMLNode=(()=>{const t=document.createElement("div");return t.style.position="fixed",t.style.overflow="hidden",t.style.pointerEvents="none",t.style.zIndex="999999999999999999",t})(),this.PS.subscribe("Settings:updated:selectorAreaClass",(({settings:t})=>{this.HTMLNode.classList.remove(t["selectorAreaClass:pre"]),this.HTMLNode.classList.add(t.selectorAreaClass)})),this.HTMLNode.classList.add(this.Settings.selectorAreaClass),this.PS.subscribe("Area:modified",this.updateParent),this.PS.subscribe("Area:modified",this.updatePos),this.PS.subscribe("Interaction:init",this.init),this.PS.subscribe("Interaction:start",(({isDraggingKeyboard:t})=>this.startAutoScroll({isDraggingKeyboard:t}))),this.PS.subscribe("Interaction:end",(()=>{this.updatePos(),this.stopAutoScroll()}))}init=()=>{this.applyElements("append"),this.updatePos()};get parentNode(){const t=this.DS.Area.HTMLNode;return(t instanceof Element?t.closest("dialog, [popover]"):null)||document.body||document.documentElement}applyElements=t=>{"append"===t?(this.HTMLNode.appendChild(this.DS.Selector.HTMLNode),this.parentNode.appendChild(this.HTMLNode)):(this.DS.Selector.HTMLNode.remove(),this.HTMLNode.remove())};updateParent=()=>{if(!this.HTMLNode.isConnected)return;const t=this.parentNode;this.HTMLNode.parentNode!==t&&t.appendChild(this.HTMLNode)};updatePos=()=>{this._rect=void 0;const t=this.DS.Area.rect,e=this.DS.Area.computedBorder,s=t.top+e.top,i=t.left+e.left;if(this.setPos(s,i,t.width,t.height),!this.HTMLNode.getClientRects().length)return;const r=this.HTMLNode.getBoundingClientRect(),n=r.top-s,o=r.left-i;(Math.abs(n)>.01||Math.abs(o)>.01)&&this.setPos(s-n,i-o,t.width,t.height),this._rect=void 0};setPos=(t,e,s,i)=>{const{style:r}=this.HTMLNode,n=`${t}px`,o=`${e}px`,l=`${s}px`,a=`${i}px`;r.top!==n&&(r.top=n),r.left!==o&&(r.left=o),r.width!==l&&(r.width=l),r.height!==a&&(r.height=a)};stop=t=>{this.stopAutoScroll(),t&&this.applyElements("remove")};startAutoScroll=({isDraggingKeyboard:t})=>{t||(this.currentEdges=[],this._scrollInterval=setInterval((()=>this.handleAutoScroll()),16))};handleAutoScroll=()=>{if(this.DS.continue)return;const{stores:{PointerStore:t},Area:e}=this.DS;this.currentEdges=(({elementRect:t,containerRect:e,tolerance:s={x:0,y:0}})=>{const i=[];return t.top-s.y<e.top&&i.push("top"),t.left-s.x<e.left&&i.push("left"),t.bottom+s.y>e.bottom&&i.push("bottom"),t.right+s.y>e.right&&i.push("right"),i})({elementRect:a(t.currentVal),containerRect:this.rect,tolerance:this.Settings.overflowTolerance}),this.currentEdges.length&&e.scroll(this.currentEdges,this.Settings.autoScrollSpeed)};stopAutoScroll=()=>{this.currentEdges=[],clearInterval(this._scrollInterval)};isInside=(t,e)=>!(!this.DS.Area.HTMLNode.contains(t)||!this.DS.stores.ScrollStore.canScroll)||p(this.rect,e||t.getBoundingClientRect());isClicked(t){const{stores:{PointerStore:e}}=this.DS,s=t?e.getPointerPosition(t):e.initialVal;return p({left:s.x,top:s.y,right:s.x,bottom:s.y},this.rect)}get rect(){return this._rect?this._rect:this._rect=this.HTMLNode.getBoundingClientRect()}}const N=(t,e)=>console.warn(`[DragSelect] TypeIssue: setting "${t}" is not of type "${e}".`),M=(t,e,s,i)=>{if(void 0===e)return s?{[t]:i}:{};if(null===e)return{[t]:null};let r=!0,n=!1;const o="string"==typeof i;o&&(r="string"==typeof e||e instanceof String),o&&!r&&(n=!0,N(t,"string"));const l=!Number.isNaN(i)&&"number"==typeof i;l&&(r=!Number.isNaN(e)&&"number"==typeof e),l&&!r&&(n=!0,N(t,"number"));const a="[object Object]"===Object.prototype.toString.call(i);a&&(r="[object Object]"===Object.prototype.toString.call(e)),a&&!r&&(n=!0,N(t,"object"));const h="boolean"==typeof i;h&&(r="boolean"==typeof e),h&&!r&&(n=!0,N(t,"boolean"));const c=Array.isArray(i);c&&(r=Array.isArray(e)),c&&!r&&(n=!0,N(t,"array"));const d=n||s;return"dragKeys"===t&&r?{[t]:Object.assign(i,e)}:"dragKeys"!==t||r?("dropZones"===t&&r&&Array.isArray(e)&&new Set(e.map((t=>t.id))).size!==e.length&&console.warn('[DragSelect] UniqueConstraintsIssue: setting "dropZones" contains duplicate ids.'),r?{[t]:e}:d?{[t]:i}:{}):d?{[t]:i}:{}};class V{_settings={};s={};PS;constructor({PS:t,settings:e}){this.PS=t,this.update({settings:e,init:!0})}update=({settings:t,init:e})=>{this.PS.publish("Settings:updated:pre",{settings:this._settings,"settings:init":Boolean(e),"settings:new":t}),this._update({settings:t,init:e})};_update=({settings:t={},init:e=!1})=>{const s=((t,e)=>({...M("area",t.area,e,document),...M("selectables",t.selectables,e,null),...M("autoScrollSpeed",t.autoScrollSpeed,e,5),...M("overflowTolerance",t.overflowTolerance,e,{x:25,y:25}),...M("zoom",t.zoom,e,1),...M("customStyles",t.customStyles,e,!1),...M("multiSelectMode",t.multiSelectMode,e,!1),...M("multiSelectToggling",t.multiSelectToggling,e,!0),...M("multiSelectKeys",t.multiSelectKeys,e,["Control","Shift","Meta"]),...M("selector",t.selector,e,null),...M("selectionThreshold",t.selectionThreshold,e,0),...M("draggability",t.draggability,e,!0),...M("immediateDrag",t.immediateDrag,e,!0),...M("keyboardDrag",t.keyboardDrag,e,!0),...M("dragKeys",t.dragKeys,e,{up:["ArrowUp"],down:["ArrowDown"],left:["ArrowLeft"],right:["ArrowRight"]}),...M("keyboardDragSpeed",t.keyboardDragSpeed,e,10),...M("useTransform",t.useTransform,e,!0),...M("refreshMemoryRate",t.refreshMemoryRate,e,80),...M("dropZones",t.dropZones,e,[]),...M("dropInsideThreshold",t.dropInsideThreshold,e,1),...M("dropTargetThreshold",t.dropTargetThreshold,e,0),...M("usePointerEvents",t.usePointerEvents,e,!1),...M("hoverClass",t.hoverClass,e,"ds-hover"),...M("selectableClass",t.selectableClass,e,"ds-selectable"),...M("selectedClass",t.selectedClass,e,"ds-selected"),...M("selectorClass",t.selectorClass,e,"ds-selector"),...M("selectorAreaClass",t.selectorAreaClass,e,"ds-selector-area"),...M("droppedTargetClass",t.droppedTargetClass,e,"ds-dropped-target"),...M("droppedInsideClass",t.droppedInsideClass,e,"ds-dropped-inside"),...M("droppableClass",t.droppableClass,e,"ds-droppable"),...M("dropZoneClass",t.dropZoneClass,e,"ds-dropzone"),...M("dropZoneReadyClass",t.dropZoneReadyClass,e,"ds-dropzone-ready"),...M("dropZoneTargetClass",t.dropZoneTargetClass,e,"ds-dropzone-target"),...M("dropZoneInsideClass",t.dropZoneInsideClass,e,"ds-dropzone-inside"),...M("useLayers",t.useLayers,e,!0)}))(t,e);for(const[i,r]of Object.entries(s))((s,i)=>{s in this._settings||Object.defineProperty(this.s,s,{get:()=>this._settings[s],set:t=>this.update({settings:{[s]:t}})}),this._settings[`${s}:pre`]=this._settings[s],this._settings[s]=i;const r={settings:this._settings,"settings:init":e,"settings:new":t};this.PS.publish("Settings:updated",r),this.PS.publish(`Settings:updated:${s}`,r)})(i,r)}}const K={elementselect:"DS:select",elementunselect:"DS:unselect",autoscroll:"DS:scroll",dragstart:"DS:start",dragmove:"DS:update",callback:"DS:end",preelementselect:"DS:select:pre",preelementunselect:"DS:unselect:pre",preautoscroll:"DS:scroll:pre",predragstart:"DS:start:pre",predragmove:"DS:update:pre",precallback:"DS:end:pre"},H=(t,e)=>{const s=e.DropZones.getTarget(t);return{...t,...s?{dropTarget:s.toObject()}:{}}},R=({sub_name:t,DS:e,PS:s,sub_pubs:i})=>{s.subscribe(t,(t=>i.forEach((s=>k({sub_pub:s,data:t,DS:e})))))},k=({sub_pub:t,data:e,DS:s})=>{const i=t.condition?t.condition(e,s):e;if(i){const r=t.extraData&&t.extraData(e,s)||{};s.publish(t.name,{items:s.SelectedSet.elements,isDragging:s.Interaction.isDragging,...i,...r})}};class ${continue=!1;PubSub;stores;Area;Selector;SelectorArea;SelectableSet;SelectedSet;Selection;Drag;DropZones;Interaction;stopped;constructor(t){this.stopped=!1,this.PubSub=new v({DS:this}),this.stores={},this.stores.SettingsStore=new V({settings:t,PS:this.PubSub}),this.stores.PointerStore=new _({DS:this,PS:this.PubSub}),this.stores.ScrollStore=new L({DS:this,PS:this.PubSub}),this.stores.KeyStore=new D({DS:this,PS:this.PubSub}),this.Area=new n({DS:this,PS:this.PubSub}),this.Selector=new x({DS:this,PS:this.PubSub}),this.SelectorArea=new w({DS:this,PS:this.PubSub}),this.SelectableSet=new T({DS:this,PS:this.PubSub}),this.SelectedSet=new E({DS:this,PS:this.PubSub}),this.Selection=new A({DS:this,PS:this.PubSub}),this.Drag=new u({DS:this,PS:this.PubSub}),this.DropZones=new b({DS:this,PS:this.PubSub}),this.Interaction=new y({DS:this,PS:this.PubSub}),(({PS:t,DS:e})=>{const s={"Selected:added":[{name:"preelementselect"},{name:"elementselect"},{name:"DS:select:pre"},{name:"DS:select"}],"Selected:removed":[{name:"preelementunselect"},{name:"elementunselect"},{name:"DS:unselect:pre"},{name:"DS:unselect"}],"Selectable:added":[{name:"DS:added:pre"},{name:"DS:added"}],"Selectable:removed":[{name:"DS:removed:pre"},{name:"DS:removed"}],"Area:scroll":[{name:"preautoscroll"},{name:"autoscroll"},{name:"DS:scroll:pre"},{name:"DS:scroll"}],"Interaction:start":[{name:"predragstart"},{name:"dragstart"},{name:"DS:start:pre"},{name:"DS:start"}],"Interaction:update":[{name:"predragmove",condition:t=>t.event?t:null},{name:"dragmove",condition:t=>t.event?t:null},{name:"DS:update:pre",condition:t=>t.event?t:null},{name:"DS:update",condition:t=>t.event?t:null}],"Interaction:end":[{name:"precallback",extraData:(t,e)=>H(t,e)},{name:"callback",extraData:(t,e)=>H(t,e)},{name:"DS:end:pre",extraData:(t,e)=>H(t,e)},{name:"DS:end",extraData:(t,e)=>H(t,e)}]};for(const[i,r]of Object.entries(s))R({sub_name:i,sub_pubs:r,DS:e,PS:t})})({DS:this,PS:this.PubSub}),this.PubSub.subscribe("Interaction:end",(()=>this.continue=!1)),this.PubSub.subscribe("DS:end",(({items:t})=>this.continue=!1)),this.start()}static isCollision;subscribe=(t,e)=>(K[t]&&console.warn(`[DragSelect]: The event name "${t}" is deprecated and was/will be removed in a future version. Please use the new event name "${K[t]}" instead.`),this.PubSub.subscribe(t,e));unsubscribe=(t,e,s)=>this.PubSub.unsubscribe(t,e,s);publish=(t,e)=>this.PubSub.publish(t,e);start=()=>{this.stopped=!1,this.Interaction.init()};stop(t=!0,e=!0,s=!1){s&&this.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),this.Interaction.stop(),this.Area.stop(),this.Drag.stop(),this.Selector.stop(),this.SelectorArea.stop(t),this.stores.KeyStore.stop(),this.stores.PointerStore.stop(),this.stores.ScrollStore.stop(),t&&this.SelectableSet.clear(),e&&this.SelectedSet.clear(),this.stopped=!0}break=()=>this.continue=!0;setSettings=t=>this.stores.SettingsStore.update({settings:t});getSelection=()=>this.SelectedSet.elements;addSelection(t,e=!1,s=!1){const i=g(t);return this.SelectedSet.addAll(i),s||this.addSelectables(t,!1,!1),e&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),this.getSelection()}removeSelection(t,e=!1,s=!1){const i=g(t);return this.SelectedSet.deleteAll(i),s&&this.removeSelectables(t,!1,!1),e&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),this.getSelection()}toggleSelection(t,e=!1,s=!1){return g(t).forEach((i=>this.SelectedSet.has(i)?this.removeSelection(t,e,s):this.addSelection(t,e,s))),e&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),this.getSelection()}setSelection(t,e=!1,s=!1){return this.clearSelection(),this.addSelection(t,e,s),this.getSelection()}clearSelection(t=!1){return this.SelectedSet.clear(),t&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),this.getSelection()}addSelectables(t,e,s){const i=g(t);return this.SelectableSet.addAll(i),e&&this.SelectedSet.addAll(i),s&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),i}getSelectables=()=>this.SelectableSet.elements;removeSelectables(t,e,s){const i=g(t);return this.SelectableSet.deleteAll(i),e&&this.removeSelection(t),s&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),i}getInitialCursorPosition=()=>this.stores.PointerStore.initialVal;getCurrentCursorPosition=()=>this.stores.PointerStore.currentVal;getPreviousCursorPosition=()=>this.stores.PointerStore.lastVal;getInitialCursorPositionArea=()=>this.stores.PointerStore.initialValArea;getCurrentCursorPositionArea=()=>this.stores.PointerStore.currentValArea;getPreviousCursorPositionArea=()=>this.stores.PointerStore.lastValArea;isMultiSelect=t=>this.stores.KeyStore.isMultiSelectKeyPressed(t);isDragging=()=>this.Interaction.isDragging;getZoneByCoordinates=t=>this.DropZones.getTarget({coordinates:t})?.toObject();getItemsDroppedByZoneId=t=>this.DropZones.getItemsDroppedById(t);getItemsInsideByZoneId=(t,e)=>this.DropZones.getItemsInsideById(t,e)}$.isCollision=p;export{$ as default};
1
+ const t=(t,e)=>{const s=e;window.addEventListener("resize",s),window.addEventListener("scroll",s);const i=new MutationObserver(s),r=new ResizeObserver(s);t.forEach(((t,e)=>{i.observe(t,{childList:0!==e,attributes:!0}),t instanceof Element&&r.observe(t)}));return{observer:i,resizeObserver:r,callback:s,cleanup:()=>{window.removeEventListener("resize",s),window.removeEventListener("scroll",s),i.disconnect(),r.disconnect()}}},e=(t,e)=>{let s;return(...i)=>{clearTimeout(s),s=setTimeout((()=>{s=void 0,t(...i)}),e)}},s=t=>{const e=(t,s=0)=>{const i=t[s]?.parentNode;return i?(t.push(i),s++,e(t,s)):t};return e([t])},i=({computedStyle:t,node:e})=>{const{position:s}=t;e instanceof Document||("absolute"===s||"relative"===s||"fixed"===s)||(e.style.position="relative")},r=t=>{const{scrollTop:e,scrollLeft:s}=t;if(e||s)return!0;const i=()=>t.scrollTop!==e||t.scrollLeft!==s;t.scrollTo({top:e+1,left:s+1,behavior:"instant"}),i()||t.scrollTo({top:e-1,left:s-1,behavior:"instant"});const r=i();return t.scrollTo({top:e,left:s,behavior:"instant"}),r},n=(t,e,s=1)=>{if(!e?.length||!t)return;const i=t instanceof Document?((t=document)=>{const e=t.scrollingElement||t.documentElement,{body:s}=t;return s&&s!==e&&!r(e)&&r(s)?s:e})(t):t;e.includes("top")&&(i.scrollTop-=s),e.includes("bottom")&&(i.scrollTop+=s),e.includes("left")&&(i.scrollLeft-=s),e.includes("right")&&(i.scrollLeft+=s)};class o{DS;PS;Settings;_observers;_node;_parentNodes;_computedStyle;_computedBorder;_rect;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this._node=this.Settings.area,this.setArea(this.Settings.area),this.PS.subscribe("Settings:updated:area",(({settings:{area:t}})=>this.setArea(t))),this.PS.subscribe("Interaction:init",this.init),this.PS.subscribe("Interaction:end",this.reset)}setArea=t=>{this.reset(),this._node=t,i({computedStyle:this.computedStyle,node:this._node}),setTimeout((()=>{this.PS.publish("Area:modified:pre",{item:this.HTMLNode}),this.reset(),this.PS.publish("Area:modified",{item:this.HTMLNode})}))};init=()=>{this._observers=t(this.parentNodes,e((t=>{this.hasRelevantBeenModified()&&(this.PS.publish("Area:modified:pre",{event:t,item:this.HTMLNode}),this.reset(),this.PS.publish("Area:modified",{event:t,item:this.HTMLNode}))}),60))};hasRelevantBeenModified=()=>{const t=this.computedStyle,e=this.rect,s=this.computedBorder,i=this.parentNodes;return this.reset(),JSON.stringify(t)!==JSON.stringify(this.computedStyle)||(JSON.stringify(e)!==JSON.stringify(this.rect)||(JSON.stringify(s)!==JSON.stringify(this.computedBorder)||!(i.length===this.parentNodes.length||!i.some((t=>!this.parentNodes.includes(t))))))};reset=()=>{this._computedStyle=void 0,this._rect=void 0,this._computedBorder=void 0,this._parentNodes=void 0};stop=()=>{this._observers?.cleanup(),this.reset()};scroll=(t,e)=>{const s={scroll_directions:t,scroll_multiplier:e};this.PS.publish("Area:scroll:pre",s),n(this._node,t,e),this.PS.publish("Area:scroll",s)};get HTMLNode(){return this._node}get computedBorder(){return this._computedBorder?this._computedBorder:{top:parseInt(this.computedStyle.borderTopWidth),bottom:parseInt(this.computedStyle.borderBottomWidth),left:parseInt(this.computedStyle.borderLeftWidth),right:parseInt(this.computedStyle.borderRightWidth)}}get computedStyle(){if(this._computedStyle)return this._computedStyle;let t;return t=this.HTMLNode instanceof Document?window.getComputedStyle(this.HTMLNode.body||this.HTMLNode.documentElement):window.getComputedStyle(this.HTMLNode),this._computedStyle={borderTopWidth:t.borderTopWidth,borderBottomWidth:t.borderBottomWidth,borderLeftWidth:t.borderLeftWidth,borderRightWidth:t.borderRightWidth,position:t.position}}get rect(){return this._rect?this._rect:this._rect=((t,e)=>{if(t instanceof Document)return{top:0,left:0,bottom:0,right:0,width:window.innerWidth,height:window.innerHeight};const s=t.getBoundingClientRect();return{top:s.top,left:s.left,bottom:s.bottom,right:s.right,width:(t.clientWidth||s.width)*e,height:(t.clientHeight||s.height)*e}})(this.HTMLNode,this.DS.stores.SettingsStore.s.zoom)}get parentNodes(){return this._parentNodes?this._parentNodes:this._parentNodes=s(this.HTMLNode)}}const a=({x:t,y:e},s,{x:i,y:r})=>({"+":{x:t+i,y:e+r},"-":{x:t-i,y:e-r},"*":{x:t*i,y:e*r},"/":{x:t/i,y:e/r}}[s]),l=t=>({x:t.left,y:t.top}),h=(t,e=0)=>({left:t.x,top:t.y,right:t.x,bottom:t.y,width:e,height:e}),c=t=>({x:t,y:t}),d=t=>{const e={x:0,y:0},s=window.getComputedStyle(t);if(!s.transform||"none"===s.transform)return e;if(s.transform.indexOf("3d")>=0){const t=s.transform.trim().match(/matrix3d\((.*?)\)/);if(t&&t.length){const s=t[1]?.split(",");e.x=parseInt(s[12])||0,e.y=parseInt(s[13])||0}return e}const i=s.transform.trim().match(/matrix\((.*?)\)/);if(i&&i.length){const t=i[1]?.split(",");e.x=parseInt(t[4])||0,e.y=parseInt(t[5])||0}return e},S=(t,e)=>e?(t=>{const{transform:e}=t.style;if(!e||e.indexOf("translate")<0)return d(t);const s={x:0,y:0},i=e.trim().match(/translate[3dD]*?\(.*?\)/);if(i){const t=i[0]?.split("(");if(t){const e=t[1]?.split(",");s.x=parseInt(e[0])||0,s.y=parseInt(e[1])||0}}return s.x||s.x?s:d(t)})(t):(t=>{const{style:e}=t,s={x:parseInt(e.left)||0,y:parseInt(e.top)||0};if(!s.x&&!s.x){const e=window.getComputedStyle(t);return{x:parseInt(e.left)||0,y:parseInt(e.top)||0}}return s})(t),u=({containerRect:t,selectionRect:e,direction:s,scrollAmount:i})=>{const r={top:t.top-e.top+i.y,left:t.left-e.left+i.x,bottom:t.bottom-e.bottom+i.y,right:t.right-e.right+i.x};return 0===s.x&&0===s.y||(s.y<0&&(s.y=Math.max(s.y,r.top)),s.x<0&&(s.x=Math.max(s.x,r.left)),s.y>0&&(s.y=Math.min(s.y,r.bottom)),s.x>0&&(s.x=Math.min(s.x,r.right)),e.top+=s.y,e.bottom+=s.y,e.left+=s.x,e.right+=s.x),s};class p{_prevCursorPos;_prevScrollPos;_elements=[];_dragKeys;_dragKeysFlat=[];_selectionRect=h(c(0));DS;PS;Settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Settings:updated:dragKeys",this.assignDragKeys),this.assignDragKeys(),this.PS.subscribe("Interaction:start",this.start),this.PS.subscribe("Interaction:end",this.stop),this.PS.subscribe("Interaction:update",this.update),this.PS.subscribe("KeyStore:down",this.keyboardDrag),this.PS.subscribe("KeyStore:up",this.keyboardEnd)}assignDragKeys=()=>{this._dragKeys={up:this.Settings.dragKeys.up.map((t=>t.toLowerCase())),down:this.Settings.dragKeys.down.map((t=>t.toLowerCase())),left:this.Settings.dragKeys.left.map((t=>t.toLowerCase())),right:this.Settings.dragKeys.right.map((t=>t.toLowerCase()))},this._dragKeysFlat=[...this._dragKeys.up,...this._dragKeys.down,...this._dragKeys.left,...this._dragKeys.right]};keyboardDrag=({event:t,key:e})=>{const s=e.toLowerCase();if(!this.Settings.keyboardDrag||!this._dragKeysFlat.includes(s)||!this.DS.SelectedSet.size||!this.Settings.draggability||this.DS.continue)return;const i={event:t,isDragging:!0,isDraggingKeyboard:!0,key:e};this.PS.publish(["Interaction:start:pre","Interaction:start"],i),this._elements=this.DS.getSelection(),this._selectionRect=this.DS.Selection.boundingRect,this.handleZIndex(!0);let r=(({shiftKey:t,keyboardDragSpeed:e,zoom:s,key:i,dragKeys:r,scrollDiff:n})=>{const o={x:0,y:0},a=t?4*e*s:e*s;return r?.left.includes(i)&&(o.x=n.x||-a),r?.right.includes(i)&&(o.x=n.x||a),r?.up.includes(i)&&(o.y=n.y||-a),r?.down.includes(i)&&(o.y=n.y||a),o})({shiftKey:this.DS.stores.KeyStore.currentValues.includes("shift"),keyboardDragSpeed:this.Settings.keyboardDragSpeed,zoom:this.Settings.zoom,key:s,scrollDiff:this._scrollDiff,dragKeys:this._dragKeys});r=u({direction:r,containerRect:this.DS.SelectorArea.rect,scrollAmount:this.DS.stores.ScrollStore.scrollAmount,selectionRect:this._selectionRect}),this.moveElements(r),this.PS.publish(["Interaction:update:pre","Interaction:update"],i)};keyboardEnd=({event:t,key:e})=>{const s=e.toLowerCase();if(!(this.Settings.keyboardDrag&&this._dragKeysFlat.includes(s)&&this.DS.SelectedSet.size&&this.Settings.draggability))return;const i={event:t,isDragging:this.Settings.draggability,isDraggingKeyboard:!0,key:e};this.PS.publish(["Interaction:end:pre","Interaction:end"],i)};start=({isDragging:t,isDraggingKeyboard:e})=>{t&&!e&&(this._prevCursorPos=void 0,this._prevScrollPos=void 0,this._elements=this.DS.getSelection(),this._selectionRect=this.DS.Selection.boundingRect,this.handleZIndex(!0))};stop=()=>{this._prevCursorPos=void 0,this._prevScrollPos=void 0,this.handleZIndex(!1),this._elements=[]};update=({isDragging:t,isDraggingKeyboard:e})=>{if(!t||!this._elements.length||e||this.DS.continue)return;let s=a(this._cursorDiff,"+",this._scrollDiff);s=u({direction:s,containerRect:this.DS.SelectorArea.rect,scrollAmount:this.DS.stores.ScrollStore.scrollAmount,selectionRect:this._selectionRect}),this.moveElements(s)};handleZIndex=t=>{this.Settings.useLayers&&this._elements.forEach((e=>e.style.zIndex=`${(parseInt(e.style.zIndex)||0)+(t?9999:-9998)}`))};moveElements=t=>{const{elements:e,direction:s}=this.filterDragElements({elements:this._elements,direction:t});e.forEach((t=>{(({element:t,posDirection:e,useTransform:s})=>{const i=S(t,s);((t,e,s)=>{if(s){const s=t.style.transform;t.style.transform=`translate3d(${e.x}px,${e.y}px,1px) ${s.replace(/translate.*?\)/g,"")}`}else t.style.left=`${e.x}px`,t.style.top=`${e.y}px`})(t,a(i,"+",e),s)})({element:t,posDirection:s,containerRect:this.DS.SelectorArea.rect,useTransform:this.Settings.useTransform})}))};get _cursorDiff(){const t=this.DS.stores.PointerStore.currentVal,e=this._prevCursorPos?a(t,"-",this._prevCursorPos):{x:0,y:0};return this._prevCursorPos=t,e}get _scrollDiff(){const t=this.DS.stores.ScrollStore.currentVal,e=this._prevScrollPos?a(t,"-",this._prevScrollPos):{x:0,y:0};return this._prevScrollPos=t,e}filterDragElements=({elements:t,direction:e})=>({elements:t,direction:e})}const g=(t,e,s=0)=>{if(!t||!e)return!1;let i=t;if(s>0){const e=(t.right-t.left)*s,r=(t.bottom-t.top)*s;i={left:t.left+e,right:t.right-e,top:t.top+r,bottom:t.bottom-r}}return i.left<e.right&&i.right>e.left&&i.top<e.bottom&&i.bottom>e.top},m=t=>t?Array.isArray(t)||"function"==typeof t[Symbol.iterator]?[...new Set([...t])]:[t]:[];class b{id;element;_droppables;_rect;_observers;_timeout;_itemsDropped=[];_itemsInside;DS;PS;Settings;isDestroyed=!1;_parentNodes;constructor({DS:s,PS:i,id:r,element:n,droppables:o}){this.DS=s,this.PS=i,this.Settings=this.DS.stores.SettingsStore.s,this.id=r,this.element=n,o&&(this.droppables=m(o)),this.element.classList.add(`${this.Settings.dropZoneClass}`),this.PS.subscribe("Settings:updated:dropZoneClass",(({settings:t})=>{this.element&&(this.element.classList.remove(t["dropZoneClass:pre"]),this.element.classList.add(t.dropZoneClass))})),this._observers=t(this.parentNodes,e((()=>this._rect=void 0),this.Settings.refreshMemoryRate)),this.PS.subscribe("Interaction:start",this.start),this.PS.subscribe("Interaction:end",this.stop)}setReadyClasses=t=>{if(this.isDestroyed)return;const e=this.droppables.filter((t=>this.DS.SelectedSet.has(t)));e.length&&(e.forEach((e=>{e.classList[t](`${this.Settings.droppableClass}`),e.classList[t](`${this.Settings.droppableClass}-${this.id}`)})),this.element.classList[t](`${this.Settings.dropZoneReadyClass}`))};handleNoDrop=()=>{this.isDestroyed||(this.DS.SelectedSet.forEach((t=>{t.classList.remove(this.Settings.droppedTargetClass),t.classList.remove(`${this.Settings.droppedTargetClass}-${this.id}`)})),this._itemsDropped=this._itemsDropped.filter((t=>!this.DS.SelectedSet.has(t))),this._itemsDropped?.length||this.element.classList.remove(`${this.Settings.dropZoneTargetClass}`))};handleDrop=()=>{this.isDestroyed||(this._itemsDropped=[...new Set([...this._itemsDropped,...this.droppables?.filter((t=>this.DS.SelectedSet.has(t)))])],this._itemsDropped?.forEach((t=>{t.classList.add(`${this.Settings.droppedTargetClass}`),t.classList.add(`${this.Settings.droppedTargetClass}-${this.id}`)})),this._itemsDropped?.length&&this.element.classList.add(`${this.Settings.dropZoneTargetClass}`))};handleItemsInsideClasses=()=>{let t=!1;this.droppables.forEach((e=>{this.itemsInside?.includes(e)?(e.classList.add(`${this.Settings.droppedInsideClass}`),e.classList.add(`${this.Settings.droppedInsideClass}-${this.id}`),t=!0):(e.classList.remove(`${this.Settings.droppedInsideClass}-${this.id}`),e.className.includes(`${this.Settings.droppedInsideClass}-`)||e.classList.remove(`${this.Settings.droppedInsideClass}`))})),t?this.element.classList.add(`${this.Settings.dropZoneInsideClass}`):this.element.classList.remove(`${this.Settings.dropZoneInsideClass}`)};start=({isDragging:t})=>{t&&!this.isDestroyed&&this.setReadyClasses("add")};stop=({isDragging:t})=>{t&&!this.isDestroyed&&(this.setReadyClasses("remove"),this.handleItemsInsideClasses())};destroy(){this._observers?.cleanup(),this.element.classList.remove(`${this.Settings.dropZoneClass}`),this.element.classList.remove(`${this.Settings.dropZoneTargetClass}`),this.element.classList.remove(`${this.Settings.dropZoneReadyClass}`),this.droppables.forEach((t=>{t.classList.remove(`${this.Settings.droppedTargetClass}`),t.classList.remove(`${this.Settings.droppedTargetClass}-${this.id}`),t.classList.remove(`${this.Settings.droppableClass}`),t.classList.remove(`${this.Settings.droppableClass}-${this.id}`)})),this.PS.unsubscribe("Interaction:start",this.start),this.PS.unsubscribe("Interaction:end",this.stop),this.isDestroyed=!0}toObject=()=>({id:this.id,element:this.element,droppables:this.droppables,itemsDropped:this.itemsDropped,itemsInside:this.itemsInside});get rect(){if(!this.isDestroyed)return this._rect?this._rect:this._rect=this.element.getBoundingClientRect()}get itemsDropped(){if(!this.isDestroyed)return this._itemsDropped}get itemsInside(){if(!this.isDestroyed)return this._itemsInside||(this._itemsInside=this.droppables.flatMap((t=>{const e=this.DS.SelectableSet.rects.get(t);return this.rect&&g(e,this.rect,this.Settings.dropInsideThreshold)?[t]:[]})),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout((()=>this._itemsInside=void 0),this.Settings.refreshMemoryRate)),this._itemsInside}get parentNodes(){return this._parentNodes?this._parentNodes:this._parentNodes=s(this.element)}get droppables(){return this._droppables?this._droppables:this.DS.SelectableSet.elements}set droppables(t){this._droppables=t}}class y{_zoneByElement=new Map;_zoneById=new Map;_zonesByDroppable=new Map;_zones;DS;PS;Settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Settings:updated:dropZones",(({settings:t})=>this.setDropZones(t))),this.setDropZones({dropZones:this.Settings.dropZones}),this.PS.subscribe("Interaction:end",this.stop)}setDropZones=({dropZones:t})=>{t&&(this._zones&&this._zones.forEach((t=>t.destroy())),this._zones=t.map((t=>new b({DS:this.DS,PS:this.PS,...t}))),this._zones.forEach((t=>{this._zoneByElement.set(t.element,t),this._zoneById.set(t.id,t),t.droppables.forEach((e=>{const s=this._zonesByDroppable.get(e);if(!s?.length)return this._zonesByDroppable.set(e,[t]);this._zonesByDroppable.set(e,[...new Set([...s,t])])}))})))};_handleDrops=t=>{this._zones?.forEach((e=>{e!==t&&e.handleNoDrop()})),t&&t.handleDrop()};_getZoneByElementsFromPoint=(t,{x:e,y:s})=>{for(let i=0,r=t.length;i<r;i++){const r=this._zoneByElement.get(t[i]);if(g(r?.rect,{left:e,right:e,top:s,bottom:s},Math.min(this.Settings.dropTargetThreshold,.5)))return r}};stop=({isDragging:t,isDraggingKeyboard:e,event:s})=>{if(!t)return;const i=this.getTarget({isDraggingKeyboard:e,event:s});this._handleDrops(i)};getItemsDroppedById=t=>{const e=this._zoneById.get(t);return e?e.itemsDropped:console.warn(`[DragSelect] No zone found (id: ${t})`)};getItemsInsideById=(t,e)=>{const s=this._zoneById.get(t);return s?(e&&s.handleItemsInsideClasses(),s.itemsInside):console.warn(`[DragSelect] No zone found (id: ${t})`)};getKeyboardItemCenter=(t,e)=>{if(!t||!e)return;const s=e.target?.getBoundingClientRect();return{x:s.left+s.width/2,y:s.top+s.height/2}};getTarget=({coordinates:t,isDraggingKeyboard:e,event:s})=>{if(!this._zones?.length)return;let i;!t&&e&&s&&(i=this.getKeyboardItemCenter(e,s));const r=t?.x||i?.x||this.DS.stores.PointerStore.currentVal.x,n=t?.y||i?.y||this.DS.stores.PointerStore.currentVal.y,o=document.elementsFromPoint(r,n);return this._getZoneByElementsFromPoint(o,{x:r,y:n})}}class D{isInteracting;isDragging=!1;DS;PS;Settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Settings:updated:area",(({settings:t})=>{this.removeAreaEventListeners(t["area:pre"]),this.setAreaEventListeners(t.area)})),this.PS.subscribe("PointerStore:updated",(({event:t})=>this.update({event:t}))),this.PS.subscribe("Selectable:click",this.onClick),this.PS.subscribe("Selectable:pointer",(({event:t})=>this.start(t))),this.PS.subscribe("Interaction:start:pre",(({event:t})=>this._start(t))),this.PS.subscribe("Interaction:init:pre",this._init),this.PS.subscribe("Interaction:end:pre",(({event:t})=>this._reset(t))),this.PS.subscribe("Area:scroll",this.update)}init=()=>this.PS.publish("Interaction:init:pre",{init:!0});_init=()=>{this.stop(),this.setAreaEventListeners(),this.PS.publish("Interaction:init",{init:!0})};_canInteract(t){const e="clientX"in t&&0===t.clientX&&0===t.clientY&&0===t.detail&&t.target;return!("button"in t&&2===t.button||this.isInteracting||t.target&&!this.DS.SelectorArea.isInside(t.target)||!e&&!this.DS.SelectorArea.isClicked(t))}start=t=>this.PS.publish("Interaction:start:pre",{event:t,isDragging:this.isDragging});_start=t=>{"touchstart"===t.type&&t.preventDefault(),this._canInteract(t)&&(this.isInteracting=!0,this.isDragging=this.isDragEvent(t),this.PS.publish("Interaction:start",{event:t,isDragging:this.isDragging}),this.setDocEventListeners())};isDragEvent=t=>{let e=null;return t.target&&"closest"in t.target&&(e=t.target.closest(`.${this.Settings.selectableClass}`)),!(!this.Settings.draggability||this.DS.stores.KeyStore.isMultiSelectKeyPressed(t)||!e)&&(this.Settings.immediateDrag&&(this.DS.SelectedSet.size?this.DS.SelectedSet.has(e)||(this.DS.SelectedSet.clear(),this.DS.SelectedSet.add(e)):this.DS.SelectedSet.add(e)),!!this.DS.SelectedSet.has(e))};onClick=({event:t})=>{if(!this._canInteract(t))return;if(t.detail>0)return;const{stores:{PointerStore:e,KeyStore:s},SelectableSet:i,SelectedSet:r}=this.DS;e.start(t);const n=t.target;n&&!i.has(n)||(s.isMultiSelectKeyPressed(t)||r.clear(),n&&r.toggle(n),this.reset(t))};stop=(t=this.DS.Area.HTMLNode)=>{this.removeAreaEventListeners(t),this.removeDocEventListeners()};update=({event:t,scroll_directions:e,scroll_multiplier:s})=>{this.isInteracting&&this.PS.publish(["Interaction:update:pre","Interaction:update"],{event:t,scroll_directions:e,scroll_multiplier:s,isDragging:this.isDragging})};reset=t=>this.PS.publish("Interaction:end:pre",{event:t,isDragging:this.isDragging});_reset=t=>{const{isDragging:e}=this;this.isInteracting=!1,this.isDragging=!1,this.removeDocEventListeners(),this.PS.publish("Interaction:end",{event:t,isDragging:e})};setAreaEventListeners=(t=this.DS.Area.HTMLNode)=>{this.Settings.usePointerEvents?t.addEventListener("pointerdown",this.start,{passive:!1}):t.addEventListener("mousedown",this.start),t.addEventListener("touchstart",this.start,{passive:!1})};removeAreaEventListeners=(t=this.DS.Area.HTMLNode)=>{this.Settings.usePointerEvents?t.removeEventListener("pointerdown",this.start,{passive:!1}):t.removeEventListener("mousedown",this.start),t.removeEventListener("touchstart",this.start,{passive:!1})};setDocEventListeners=()=>{this.Settings.usePointerEvents?(document.addEventListener("pointerup",this.reset),document.addEventListener("pointercancel",this.reset)):document.addEventListener("mouseup",this.reset),document.addEventListener("touchend",this.reset)};removeDocEventListeners=()=>{this.Settings.usePointerEvents?(document.removeEventListener("pointerup",this.reset),document.removeEventListener("pointercancel",this.reset)):document.removeEventListener("mouseup",this.reset),document.removeEventListener("touchend",this.reset)}}class _{_currentValues=new Set;_keyMapping={control:"ctrlKey",shift:"shiftKey",meta:"metaKey"};DS;PS;settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Interaction:init",this.init)}init=()=>{document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup),window.addEventListener("blur",this.reset)};keydown=t=>{if(!t.key?.toLocaleLowerCase)return;const e=t.key.toLowerCase();this.PS.publish("KeyStore:down:pre",{event:t,key:e}),this._currentValues.add(e),this.PS.publish("KeyStore:down",{event:t,key:e})};keyup=t=>{if(!t.key?.toLocaleLowerCase)return;const e=t.key.toLowerCase();this.PS.publish("KeyStore:up:pre",{event:t,key:e}),this._currentValues.delete(e),this.PS.publish("KeyStore:up",{event:t,key:e})};stop=()=>{document.removeEventListener("keydown",this.keydown),document.removeEventListener("keyup",this.reset),window.removeEventListener("blur",this.reset),this.reset()};reset=()=>this._currentValues.clear();isMultiSelectKeyPressed(t){if(this.settings.multiSelectMode)return!0;const e=this.settings.multiSelectKeys?.map((t=>t.toLocaleLowerCase()))??[];return!!this.currentValues.some((t=>e.includes(t)))||!(!t||!e.some((e=>t[this._keyMapping[e]])))}get currentValues(){return Array.from(this._currentValues.values())}}class v{_isMouseInteraction=!1;_initialValArea={x:0,y:0};_currentValArea={x:0,y:0};_lastValArea={x:0,y:0};_initialVal={x:0,y:0};_currentVal={x:0,y:0};_lastVal={x:0,y:0};_lastTouch;DS;PS;settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Interaction:init",this.init),this.PS.subscribe("Interaction:start",(({event:t})=>this.start(t))),this.PS.subscribe("Interaction:end",(({event:t})=>this.reset(t)))}init=()=>{this.settings.usePointerEvents?document.addEventListener("pointermove",this.update,{passive:!1}):document.addEventListener("mousemove",this.update),document.addEventListener("touchmove",this.update,{passive:!1})};start(t){t&&(this._isMouseInteraction=!0,this.currentVal=this.initialVal=this.getPointerPosition(t))}getPointerPosition=t=>(({event:t})=>({x:t.clientX,y:t.clientY}))({event:this._normalizedEvent(t)});update=t=>{t&&(this.PS.publish("PointerStore:updated:pre",{event:t}),this.currentVal=this.getPointerPosition(t),this._isMouseInteraction&&this.PS.publish("PointerStore:updated",{event:t}))};stop=()=>{this.settings.usePointerEvents?document.removeEventListener("pointermove",this.update,{passive:!1}):document.removeEventListener("mousemove",this.update),document.removeEventListener("touchmove",this.update,{passive:!1}),this.reset()};reset=t=>{this.currentVal=this.lastVal=this.getPointerPosition(t),setTimeout((()=>this._isMouseInteraction=!1),100)};_normalizedEvent(t){return!t||t instanceof KeyboardEvent?{clientX:0,clientY:0}:"touches"in t?("touchend"!==t.type&&(this._lastTouch=t),this._lastTouch?.touches[0]||t.touches[0]):t}get initialValArea(){return this._initialValArea?this._initialValArea:{x:0,y:0}}get currentValArea(){return this._currentValArea?this._currentValArea:{x:0,y:0}}get lastValArea(){return this._lastValArea?this._lastValArea:{x:0,y:0}}get initialVal(){return this._initialVal?this._initialVal:{x:0,y:0}}get currentVal(){return this._currentVal?this._currentVal:{x:0,y:0}}get lastVal(){return this._lastVal?this._lastVal:{x:0,y:0}}set initialVal(t){this._initialVal=t,this._initialValArea=t&&a(t,"-",a(l(this.DS.Area.rect),"+",l(this.DS.Area.computedBorder)))}set currentVal(t){this._currentVal=t,this._currentValArea=t&&a(t,"-",a(l(this.DS.Area.rect),"+",l(this.DS.Area.computedBorder)))}set lastVal(t){this._lastVal=t,this._lastValArea=t&&a(t,"-",a(l(this.DS.Area.rect),"+",l(this.DS.Area.computedBorder)))}}class P{subscribers={};_ids={};_nextId=0;DS;constructor({DS:t}){this.DS=t}subscribe=(t,e)=>{this.subscribers[t]||(this.subscribers[t]=[]),this._ids[t]||(this._ids[t]=[]);const s=this.subscribers[t],i=this._ids[t],r=this._nextId++;return s.push(e),i.push(r),r};unsubscribe=(t,e,s)=>{const i=this.subscribers[t],r=this._ids[t];if(!i||!r)return;const n=null!=s?r.indexOf(s):e?i.indexOf(e):-1;-1!==n&&(i.splice(n,1),r.splice(n,1))};publish=(t,e)=>{Array.isArray(t)?t.forEach((t=>this._publish(t,e))):this._publish(t,e)};_publish=(t,e)=>{const s=[...this.subscribers[t]??[]];t.includes(":pre")?this._handlePrePublish(s,e):this._handlePublish(s,e)};_handlePublish=(t,e)=>{for(let s=0,i=t.length;s<i;s++){if(this.DS.stopped)return;t[s]?.(e)}};_handlePrePublish=(t,e)=>{let s=t.length;for(;s--;){if(this.DS.stopped)return;t[s]?.(e)}}}const f=()=>({y:document.body?.scrollTop||document.documentElement?.scrollTop||0,x:document.body?.scrollLeft||document.documentElement?.scrollLeft||0}),I=t=>!t||t instanceof Document?f():{x:t.scrollLeft>=0?t.scrollLeft:f().x,y:t.scrollTop>=0?t.scrollTop:f().y};class L{_initialVal={x:0,y:0};_currentVal={x:0,y:0};_canScroll;DS;PS;Settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Area:modified",(()=>{this.stop(),this.init()})),this.PS.subscribe("Interaction:init",this.init),this.PS.subscribe("Interaction:start",(()=>this.start())),this.PS.subscribe("Interaction:end",(()=>this.reset()))}init=()=>this.addListeners();addListeners=()=>this.DS.Area.HTMLNode.addEventListener("scroll",this.update);removeListeners=()=>this.DS.Area.HTMLNode.removeEventListener("scroll",this.update);start=()=>{this._currentVal=this._initialVal=I(this.DS.Area.HTMLNode)};update=()=>this._currentVal=I(this.DS.Area.HTMLNode);stop=()=>{this.reset(),this.removeListeners()};reset=()=>{this._initialVal={x:0,y:0},this._canScroll=void 0};get canScroll(){return"boolean"==typeof this._canScroll?this._canScroll:this._canScroll=(t=>{if(!(t instanceof Document))return r(t);const e=t.scrollingElement||t.documentElement;return r(e)||!!t.body&&r(t.body)})(this.DS.Area.HTMLNode)}get scrollAmount(){const t=a(this.currentVal,"-",this.initialVal),e=c(this.Settings.zoom),s=a(a(t,"*",e),"-",t);return{x:t.x+s.x,y:t.y+s.y}}get initialVal(){return this._initialVal?this._initialVal:{x:0,y:0}}get currentVal(){return this._currentVal||(this._currentVal=I(this.DS.Area.HTMLNode)),this._currentVal}}class T extends Set{_rects;_timeout;DS;PS;Settings;constructor({DS:t,PS:e}){super(),this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Interaction:init",this.init),this.PS.subscribe("Settings:updated:selectables",(()=>{this.clear(),this.init()})),this.PS.subscribe("Settings:updated:selectableClass",(({settings:t})=>{this.forEach((e=>{e.classList.remove(t["selectableClass:pre"]),e.classList.add(t.selectableClass)}))}))}init=()=>m(this.Settings.selectables).forEach((t=>this.add(t)));add(t){if(!t||super.has(t))return this;const e={items:this.elements,item:t};return this.PS.publish("Selectable:added:pre",e),t.classList.add(this.Settings.selectableClass),t.addEventListener("click",this._onClick),this.Settings.usePointerEvents?t.addEventListener("pointerdown",this._onPointer,{passive:!1}):t.addEventListener("mousedown",this._onPointer),t.addEventListener("touchstart",this._onPointer,{passive:!1}),this.Settings.draggability&&!this.Settings.useTransform&&i({computedStyle:window.getComputedStyle(t),node:t}),this.PS.publish("Selectable:added",e),super.add(t)}delete(t){if(!t||!super.has(t))return!0;const e={items:this.elements,item:t};return this.PS.publish("Selectable:removed:pre",e),t.classList.remove(this.Settings.selectableClass),t.classList.remove(this.Settings.hoverClass),t.removeEventListener("click",this._onClick),this.Settings.usePointerEvents?t.removeEventListener("pointerdown",this._onPointer,{passive:!1}):t.removeEventListener("mousedown",this._onPointer),t.removeEventListener("touchstart",this._onPointer,{passive:!1}),this.PS.publish("Selectable:removed",e),super.delete(t)}clear=()=>this.forEach((t=>this.delete(t)));_onClick=t=>this.PS.publish(["Selectable:click:pre","Selectable:click"],{event:t});_onPointer=t=>this.PS.publish(["Selectable:pointer:pre","Selectable:pointer"],{event:t});addAll=t=>t.forEach((t=>this.add(t)));deleteAll=t=>t.forEach((t=>this.delete(t)));getElementRect=t=>this._rects?this._rects.get(t):t.getBoundingClientRect();get elements(){return Array.from(this.values())}get rects(){return this._rects||(this._rects=new Map,this.forEach((t=>this._rects?.set(t,t.getBoundingClientRect()))),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout((()=>this._rects=void 0),this.Settings.refreshMemoryRate)),this._rects}}class C extends Set{_rects;_timeout;DS;PS;Settings;constructor({DS:t,PS:e}){super(),this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s}add(t){if(!t||super.has(t))return this;const e={items:this.elements,item:t};return this.PS.publish("Selected:added:pre",e),super.add(t),t.classList.add(this.Settings.selectedClass),this.Settings.useLayers&&(t.style.zIndex=`${(parseInt(t.style.zIndex)||0)+1}`),this.PS.publish("Selected:added",e),this}delete(t){if(!t||!super.has(t))return!0;const e={items:this.elements,item:t};this.PS.publish("Selected:removed:pre",e);const s=super.delete(t);return t.classList.remove(this.Settings.selectedClass),this.Settings.useLayers&&(t.style.zIndex=""+((parseInt(t.style.zIndex)||0)-1)),this.PS.publish("Selected:removed",e),s}clear=()=>this.forEach((t=>this.delete(t)));toggle(t){return this.has(t)?this.delete(t):this.add(t),t}addAll=t=>t.forEach((t=>this.add(t)));deleteAll=t=>t.forEach((t=>this.delete(t)));get elements(){return Array.from(this.values())}get rects(){return this._rects||(this._rects=new Map,this.forEach((t=>this._rects?.set(t,t.getBoundingClientRect()))),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout((()=>this._rects=void 0),this.Settings.refreshMemoryRate)),this._rects}}var E=(t,e)=>{e.left&&(t.style.left=`${e.left}px`),e.top&&(t.style.top=`${e.top}px`),e.width&&(t.style.width=`${e.width}px`),e.height&&(t.style.height=`${e.height}px`)};class x{_rect;DS;PS;Settings;HTMLNode;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.HTMLNode=this.Settings.selector,this.PS.subscribe("Settings:updated:selectorClass",(({settings:t})=>{this.HTMLNode.classList.remove(t["selectorClass:pre"]),this.HTMLNode.classList.add(t.selectorClass)})),this.PS.subscribe("Settings:updated:selector",this.attachSelector),this.PS.subscribe("Settings:updated:customStyles",this.attachSelector),this.attachSelector(),this.PS.subscribe("Interaction:start",this.start),this.PS.subscribe("Interaction:update",this.update),this.PS.subscribe("Interaction:end",this.stop)}attachSelector=()=>{this.HTMLNode&&this.DS.SelectorArea?.HTMLNode&&this.DS.SelectorArea.HTMLNode.removeChild(this.HTMLNode),this.HTMLNode=this.Settings.selector||(t=>{const e=document.createElement("div");return e.style.position="absolute",t||(e.style.background="rgba(0, 175, 255, 0.2)",e.style.border="1px solid rgba(0, 175, 255, 0.8)",e.style.display="none",e.style.pointerEvents="none"),e})(this.Settings.customStyles),this.HTMLNode.classList.add(this.Settings.selectorClass),this.HTMLNode&&this.DS.SelectorArea?.HTMLNode&&this.DS.SelectorArea.HTMLNode.appendChild(this.HTMLNode)};start=({isDragging:t})=>{if(t)return;const{stores:{PointerStore:e}}=this.DS,s=e.initialValArea;E(this.HTMLNode,h(s,1)),this.HTMLNode.style.display="block",this._rect=void 0};stop=()=>{this.HTMLNode.style.width="0",this.HTMLNode.style.height="0",this.HTMLNode.style.display="none"};update=({isDragging:t})=>{if(t||this.DS.continue)return;const{stores:{ScrollStore:e,PointerStore:s}}=this.DS,i=(({scrollAmount:t,initialPointerPos:e,pointerPos:s})=>{const i={};return s.x>e.x-t.x?(i.left=e.x-t.x,i.width=s.x-e.x+t.x):(i.left=s.x,i.width=e.x-s.x-t.x),s.y>e.y-t.y?(i.top=e.y-t.y,i.height=s.y-e.y+t.y):(i.top=s.y,i.height=e.y-s.y-t.y),i})({scrollAmount:e.scrollAmount,initialPointerPos:s.initialValArea,pointerPos:s.currentValArea});E(this.HTMLNode,i),this._rect=void 0};get rect(){return this._rect?this._rect:this._rect=this.HTMLNode.getBoundingClientRect()}}class A{_prevSelectedSet=new Set;_boundingRect;_timeout;DS;PS;Settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Interaction:start",this.start),this.PS.subscribe("Interaction:update",this.update)}_storePrevious(t){const{stores:{KeyStore:e},SelectedSet:s}=this.DS;e.isMultiSelectKeyPressed(t)?this._prevSelectedSet=new Set(s):this._prevSelectedSet=new Set}start=({event:t,isDragging:e})=>{e||(this._storePrevious(t),this._handleInsideSelection(!0,t))};update=({isDragging:t})=>{t||this.DS.continue||this._handleInsideSelection()};_handleInsideSelection=(t,e)=>{const{SelectableSet:s,SelectorArea:i,Selector:r}=this.DS,n=this.DS.stores.KeyStore.isMultiSelectKeyPressed(e)&&this.Settings.multiSelectToggling,o=this.Settings.selectionThreshold,a=s.rects,l=r.rect,h=new Map,c=new Map;for(const[t,e]of a)i.isInside(t,e)&&(g(e,l,o)?h.set(t,e):c.set(t,e));if(this.DS.continue)return;const{select:d,unselect:S}=this.filterSelected({select:h,unselect:c,selectorRect:l});d.forEach(((e,s)=>(({element:t,force:e,multiSelectionToggle:s,SelectedSet:i,hoverClassName:r})=>{t.classList.contains(r)&&!e||(i.has(t)?s&&i.delete(t):i.add(t),t.classList.add(r))})({element:s,force:t,multiSelectionToggle:n,SelectedSet:this.DS.SelectedSet,hoverClassName:this.Settings.hoverClass}))),S.forEach(((e,s)=>(({element:t,force:e,SelectedSet:s,PrevSelectedSet:i,hoverClassName:r})=>{if(!t.classList.contains(r)&&!e)return;const n=s.has(t),o=i.has(t);n&&!o?s.delete(t):!n&&o&&s.add(t),t.classList.remove(r)})({element:s,force:t,SelectedSet:this.DS.SelectedSet,hoverClassName:this.Settings.hoverClass,PrevSelectedSet:this._prevSelectedSet})))};get boundingRect(){return this._boundingRect||(this._boundingRect=(t=>{const e={top:Number.POSITIVE_INFINITY,left:Number.POSITIVE_INFINITY,bottom:Number.NEGATIVE_INFINITY,right:Number.NEGATIVE_INFINITY,width:Number.NEGATIVE_INFINITY,height:Number.NEGATIVE_INFINITY};return t.rects.forEach((t=>{e.top=Math.min(e.top,t.top||e.top),e.left=Math.min(e.left,t.left||e.left),e.bottom=Math.max(e.bottom,t.bottom||e.bottom),e.right=Math.max(e.right,t.right||e.right)})),e.height=e.bottom-e.top,e.width=e.right-e.left,e})(this.DS.SelectedSet),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout((()=>this._boundingRect=void 0),this.Settings.refreshMemoryRate)),this._boundingRect}filterSelected=({select:t,unselect:e,selectorRect:s})=>({select:t,unselect:e})}class w{_scrollInterval;_rect;currentEdges=[];DS;PS;Settings;HTMLNode;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.HTMLNode=(()=>{const t=document.createElement("div");return t.style.position="fixed",t.style.overflow="hidden",t.style.pointerEvents="none",t.style.zIndex="999999999999999999",t})(),this.PS.subscribe("Settings:updated:selectorAreaClass",(({settings:t})=>{this.HTMLNode.classList.remove(t["selectorAreaClass:pre"]),this.HTMLNode.classList.add(t.selectorAreaClass)})),this.HTMLNode.classList.add(this.Settings.selectorAreaClass),this.PS.subscribe("Area:modified",this.updateParent),this.PS.subscribe("Area:modified",this.updatePos),this.PS.subscribe("Interaction:init",this.init),this.PS.subscribe("Interaction:start",(({isDraggingKeyboard:t})=>this.startAutoScroll({isDraggingKeyboard:t}))),this.PS.subscribe("Interaction:end",(()=>{this.updatePos(),this.stopAutoScroll()}))}init=()=>{this.applyElements("append"),this.updatePos()};get parentNode(){const t=this.DS.Area.HTMLNode;return(t instanceof Element?t.closest("dialog, [popover]"):null)||document.body||document.documentElement}applyElements=t=>{"append"===t?(this.HTMLNode.appendChild(this.DS.Selector.HTMLNode),this.parentNode.appendChild(this.HTMLNode)):(this.DS.Selector.HTMLNode.remove(),this.HTMLNode.remove())};updateParent=()=>{if(!this.HTMLNode.isConnected)return;const t=this.parentNode;this.HTMLNode.parentNode!==t&&t.appendChild(this.HTMLNode)};updatePos=()=>{this._rect=void 0;const t=this.DS.Area.rect,e=this.DS.Area.computedBorder,s=t.top+e.top,i=t.left+e.left;if(this.setPos(s,i,t.width,t.height),!this.HTMLNode.getClientRects().length)return;const r=this.HTMLNode.getBoundingClientRect(),n=r.top-s,o=r.left-i;(Math.abs(n)>.01||Math.abs(o)>.01)&&this.setPos(s-n,i-o,t.width,t.height),this._rect=void 0};setPos=(t,e,s,i)=>{const{style:r}=this.HTMLNode,n=`${t}px`,o=`${e}px`,a=`${s}px`,l=`${i}px`;r.top!==n&&(r.top=n),r.left!==o&&(r.left=o),r.width!==a&&(r.width=a),r.height!==l&&(r.height=l)};stop=t=>{this.stopAutoScroll(),t&&this.applyElements("remove")};startAutoScroll=({isDraggingKeyboard:t})=>{t||(this.currentEdges=[],this._scrollInterval=setInterval((()=>this.handleAutoScroll()),16))};handleAutoScroll=()=>{if(this.DS.continue)return;const{stores:{PointerStore:t},Area:e}=this.DS;this.currentEdges=(({elementRect:t,containerRect:e,tolerance:s={x:0,y:0}})=>{const i=[];return t.top-s.y<e.top&&i.push("top"),t.left-s.x<e.left&&i.push("left"),t.bottom+s.y>e.bottom&&i.push("bottom"),t.right+s.y>e.right&&i.push("right"),i})({elementRect:h(t.currentVal),containerRect:this.rect,tolerance:this.Settings.overflowTolerance}),this.currentEdges.length&&e.scroll(this.currentEdges,this.Settings.autoScrollSpeed)};stopAutoScroll=()=>{this.currentEdges=[],clearInterval(this._scrollInterval)};isInside=(t,e)=>!(!this.DS.Area.HTMLNode.contains(t)||!this.DS.stores.ScrollStore.canScroll)||g(this.rect,e||t.getBoundingClientRect());isClicked(t){const{stores:{PointerStore:e}}=this.DS,s=t?e.getPointerPosition(t):e.initialVal;return g({left:s.x,top:s.y,right:s.x,bottom:s.y},this.rect)}get rect(){return this._rect?this._rect:this._rect=this.HTMLNode.getBoundingClientRect()}}const N=(t,e)=>console.warn(`[DragSelect] TypeIssue: setting "${t}" is not of type "${e}".`),M=(t,e,s,i)=>{if(void 0===e)return s?{[t]:i}:{};if(null===e)return{[t]:null};let r=!0,n=!1;const o="string"==typeof i;o&&(r="string"==typeof e||e instanceof String),o&&!r&&(n=!0,N(t,"string"));const a=!Number.isNaN(i)&&"number"==typeof i;a&&(r=!Number.isNaN(e)&&"number"==typeof e),a&&!r&&(n=!0,N(t,"number"));const l="[object Object]"===Object.prototype.toString.call(i);l&&(r="[object Object]"===Object.prototype.toString.call(e)),l&&!r&&(n=!0,N(t,"object"));const h="boolean"==typeof i;h&&(r="boolean"==typeof e),h&&!r&&(n=!0,N(t,"boolean"));const c=Array.isArray(i);c&&(r=Array.isArray(e)),c&&!r&&(n=!0,N(t,"array"));const d=n||s;return"dragKeys"===t&&r?{[t]:Object.assign(i,e)}:"dragKeys"!==t||r?("dropZones"===t&&r&&Array.isArray(e)&&new Set(e.map((t=>t.id))).size!==e.length&&console.warn('[DragSelect] UniqueConstraintsIssue: setting "dropZones" contains duplicate ids.'),r?{[t]:e}:d?{[t]:i}:{}):d?{[t]:i}:{}};class V{_settings={};s={};PS;constructor({PS:t,settings:e}){this.PS=t,this.update({settings:e,init:!0})}update=({settings:t,init:e})=>{this.PS.publish("Settings:updated:pre",{settings:this._settings,"settings:init":Boolean(e),"settings:new":t}),this._update({settings:t,init:e})};_update=({settings:t={},init:e=!1})=>{const s=((t,e)=>({...M("area",t.area,e,document),...M("selectables",t.selectables,e,null),...M("autoScrollSpeed",t.autoScrollSpeed,e,5),...M("overflowTolerance",t.overflowTolerance,e,{x:25,y:25}),...M("zoom",t.zoom,e,1),...M("customStyles",t.customStyles,e,!1),...M("multiSelectMode",t.multiSelectMode,e,!1),...M("multiSelectToggling",t.multiSelectToggling,e,!0),...M("multiSelectKeys",t.multiSelectKeys,e,["Control","Shift","Meta"]),...M("selector",t.selector,e,null),...M("selectionThreshold",t.selectionThreshold,e,0),...M("draggability",t.draggability,e,!0),...M("immediateDrag",t.immediateDrag,e,!0),...M("keyboardDrag",t.keyboardDrag,e,!0),...M("dragKeys",t.dragKeys,e,{up:["ArrowUp"],down:["ArrowDown"],left:["ArrowLeft"],right:["ArrowRight"]}),...M("keyboardDragSpeed",t.keyboardDragSpeed,e,10),...M("useTransform",t.useTransform,e,!0),...M("refreshMemoryRate",t.refreshMemoryRate,e,80),...M("dropZones",t.dropZones,e,[]),...M("dropInsideThreshold",t.dropInsideThreshold,e,1),...M("dropTargetThreshold",t.dropTargetThreshold,e,0),...M("usePointerEvents",t.usePointerEvents,e,!1),...M("hoverClass",t.hoverClass,e,"ds-hover"),...M("selectableClass",t.selectableClass,e,"ds-selectable"),...M("selectedClass",t.selectedClass,e,"ds-selected"),...M("selectorClass",t.selectorClass,e,"ds-selector"),...M("selectorAreaClass",t.selectorAreaClass,e,"ds-selector-area"),...M("droppedTargetClass",t.droppedTargetClass,e,"ds-dropped-target"),...M("droppedInsideClass",t.droppedInsideClass,e,"ds-dropped-inside"),...M("droppableClass",t.droppableClass,e,"ds-droppable"),...M("dropZoneClass",t.dropZoneClass,e,"ds-dropzone"),...M("dropZoneReadyClass",t.dropZoneReadyClass,e,"ds-dropzone-ready"),...M("dropZoneTargetClass",t.dropZoneTargetClass,e,"ds-dropzone-target"),...M("dropZoneInsideClass",t.dropZoneInsideClass,e,"ds-dropzone-inside"),...M("useLayers",t.useLayers,e,!0)}))(t,e);for(const[i,r]of Object.entries(s))((s,i)=>{s in this._settings||Object.defineProperty(this.s,s,{get:()=>this._settings[s],set:t=>this.update({settings:{[s]:t}})}),this._settings[`${s}:pre`]=this._settings[s],this._settings[s]=i;const r={settings:this._settings,"settings:init":e,"settings:new":t};this.PS.publish("Settings:updated",r),this.PS.publish(`Settings:updated:${s}`,r)})(i,r)}}const K={elementselect:"DS:select",elementunselect:"DS:unselect",autoscroll:"DS:scroll",dragstart:"DS:start",dragmove:"DS:update",callback:"DS:end",preelementselect:"DS:select:pre",preelementunselect:"DS:unselect:pre",preautoscroll:"DS:scroll:pre",predragstart:"DS:start:pre",predragmove:"DS:update:pre",precallback:"DS:end:pre"},H=(t,e)=>{const s=e.DropZones.getTarget(t);return{...t,...s?{dropTarget:s.toObject()}:{}}},R=({sub_name:t,DS:e,PS:s,sub_pubs:i})=>{s.subscribe(t,(t=>i.forEach((s=>k({sub_pub:s,data:t,DS:e})))))},k=({sub_pub:t,data:e,DS:s})=>{const i=t.condition?t.condition(e,s):e;if(i){const r=t.extraData&&t.extraData(e,s)||{};s.publish(t.name,{items:s.SelectedSet.elements,isDragging:s.Interaction.isDragging,...i,...r})}};class ${continue=!1;PubSub;stores;Area;Selector;SelectorArea;SelectableSet;SelectedSet;Selection;Drag;DropZones;Interaction;stopped;constructor(t){this.stopped=!1,this.PubSub=new P({DS:this}),this.stores={},this.stores.SettingsStore=new V({settings:t,PS:this.PubSub}),this.stores.PointerStore=new v({DS:this,PS:this.PubSub}),this.stores.ScrollStore=new L({DS:this,PS:this.PubSub}),this.stores.KeyStore=new _({DS:this,PS:this.PubSub}),this.Area=new o({DS:this,PS:this.PubSub}),this.Selector=new x({DS:this,PS:this.PubSub}),this.SelectorArea=new w({DS:this,PS:this.PubSub}),this.SelectableSet=new T({DS:this,PS:this.PubSub}),this.SelectedSet=new C({DS:this,PS:this.PubSub}),this.Selection=new A({DS:this,PS:this.PubSub}),this.Drag=new p({DS:this,PS:this.PubSub}),this.DropZones=new y({DS:this,PS:this.PubSub}),this.Interaction=new D({DS:this,PS:this.PubSub}),(({PS:t,DS:e})=>{const s={"Selected:added":[{name:"preelementselect"},{name:"elementselect"},{name:"DS:select:pre"},{name:"DS:select"}],"Selected:removed":[{name:"preelementunselect"},{name:"elementunselect"},{name:"DS:unselect:pre"},{name:"DS:unselect"}],"Selectable:added":[{name:"DS:added:pre"},{name:"DS:added"}],"Selectable:removed":[{name:"DS:removed:pre"},{name:"DS:removed"}],"Area:scroll":[{name:"preautoscroll"},{name:"autoscroll"},{name:"DS:scroll:pre"},{name:"DS:scroll"}],"Interaction:start":[{name:"predragstart"},{name:"dragstart"},{name:"DS:start:pre"},{name:"DS:start"}],"Interaction:update":[{name:"predragmove",condition:t=>t.event?t:null},{name:"dragmove",condition:t=>t.event?t:null},{name:"DS:update:pre",condition:t=>t.event?t:null},{name:"DS:update",condition:t=>t.event?t:null}],"Interaction:end":[{name:"precallback",extraData:(t,e)=>H(t,e)},{name:"callback",extraData:(t,e)=>H(t,e)},{name:"DS:end:pre",extraData:(t,e)=>H(t,e)},{name:"DS:end",extraData:(t,e)=>H(t,e)}]};for(const[i,r]of Object.entries(s))R({sub_name:i,sub_pubs:r,DS:e,PS:t})})({DS:this,PS:this.PubSub}),this.PubSub.subscribe("Interaction:end",(()=>this.continue=!1)),this.PubSub.subscribe("DS:end",(({items:t})=>this.continue=!1)),this.start()}static isCollision;subscribe=(t,e)=>(K[t]&&console.warn(`[DragSelect]: The event name "${t}" is deprecated and was/will be removed in a future version. Please use the new event name "${K[t]}" instead.`),this.PubSub.subscribe(t,e));unsubscribe=(t,e,s)=>this.PubSub.unsubscribe(t,e,s);publish=(t,e)=>this.PubSub.publish(t,e);start=()=>{this.stopped=!1,this.Interaction.init()};stop(t=!0,e=!0,s=!1){s&&this.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),this.Interaction.stop(),this.Area.stop(),this.Drag.stop(),this.Selector.stop(),this.SelectorArea.stop(t),this.stores.KeyStore.stop(),this.stores.PointerStore.stop(),this.stores.ScrollStore.stop(),t&&this.SelectableSet.clear(),e&&this.SelectedSet.clear(),this.stopped=!0}break=()=>this.continue=!0;setSettings=t=>this.stores.SettingsStore.update({settings:t});getSelection=()=>this.SelectedSet.elements;addSelection(t,e=!1,s=!1){const i=m(t);return this.SelectedSet.addAll(i),s||this.addSelectables(t,!1,!1),e&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),this.getSelection()}removeSelection(t,e=!1,s=!1){const i=m(t);return this.SelectedSet.deleteAll(i),s&&this.removeSelectables(t,!1,!1),e&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),this.getSelection()}toggleSelection(t,e=!1,s=!1){return m(t).forEach((i=>this.SelectedSet.has(i)?this.removeSelection(t,e,s):this.addSelection(t,e,s))),e&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),this.getSelection()}setSelection(t,e=!1,s=!1){return this.clearSelection(),this.addSelection(t,e,s),this.getSelection()}clearSelection(t=!1){return this.SelectedSet.clear(),t&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),this.getSelection()}addSelectables(t,e,s){const i=m(t);return this.SelectableSet.addAll(i),e&&this.SelectedSet.addAll(i),s&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),i}getSelectables=()=>this.SelectableSet.elements;removeSelectables(t,e,s){const i=m(t);return this.SelectableSet.deleteAll(i),e&&this.removeSelection(t),s&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),i}getInitialCursorPosition=()=>this.stores.PointerStore.initialVal;getCurrentCursorPosition=()=>this.stores.PointerStore.currentVal;getPreviousCursorPosition=()=>this.stores.PointerStore.lastVal;getInitialCursorPositionArea=()=>this.stores.PointerStore.initialValArea;getCurrentCursorPositionArea=()=>this.stores.PointerStore.currentValArea;getPreviousCursorPositionArea=()=>this.stores.PointerStore.lastValArea;isMultiSelect=t=>this.stores.KeyStore.isMultiSelectKeyPressed(t);isDragging=()=>this.Interaction.isDragging;getZoneByCoordinates=t=>this.DropZones.getTarget({coordinates:t})?.toObject();getItemsDroppedByZoneId=t=>this.DropZones.getItemsDroppedById(t);getItemsInsideByZoneId=(t,e)=>this.DropZones.getItemsInsideById(t,e)}$.isCollision=g;export{$ as default};
package/dist/ds.min.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).DragSelect=t()}(this,(function(){"use strict";const e=(e,t)=>{const s=t;window.addEventListener("resize",s),window.addEventListener("scroll",s);const i=new MutationObserver(s),r=new ResizeObserver(s);e.forEach(((e,t)=>{i.observe(e,{childList:0!==t,attributes:!0}),e instanceof Element&&r.observe(e)}));return{observer:i,resizeObserver:r,callback:s,cleanup:()=>{window.removeEventListener("resize",s),window.removeEventListener("scroll",s),i.disconnect(),r.disconnect()}}},t=(e,t)=>{let s;return(...i)=>{clearTimeout(s),s=setTimeout((()=>{s=void 0,e(...i)}),t)}},s=e=>{const t=(e,s=0)=>{const i=e[s]?.parentNode;return i?(e.push(i),s++,t(e,s)):e};return t([e])},i=({computedStyle:e,node:t})=>{const{position:s}=e;t instanceof Document||("absolute"===s||"relative"===s||"fixed"===s)||(t.style.position="relative")};let r;class n{DS;PS;Settings;_observers;_node;_parentNodes;_computedStyle;_computedBorder;_rect;constructor({DS:e,PS:t}){this.DS=e,this.PS=t,this.Settings=this.DS.stores.SettingsStore.s,this._node=this.Settings.area,this.setArea(this.Settings.area),this.PS.subscribe("Settings:updated:area",(({settings:{area:e}})=>this.setArea(e))),this.PS.subscribe("Interaction:init",this.init),this.PS.subscribe("Interaction:end",this.reset)}setArea=e=>{this.reset(),this._node=e,i({computedStyle:this.computedStyle,node:this._node}),setTimeout((()=>{this.PS.publish("Area:modified:pre",{item:this.HTMLNode}),this.reset(),this.PS.publish("Area:modified",{item:this.HTMLNode})}))};init=()=>{this._observers=e(this.parentNodes,t((e=>{this.hasRelevantBeenModified()&&(this.PS.publish("Area:modified:pre",{event:e,item:this.HTMLNode}),this.reset(),this.PS.publish("Area:modified",{event:e,item:this.HTMLNode}))}),60))};hasRelevantBeenModified=()=>{const e=this.computedStyle,t=this.rect,s=this.computedBorder,i=this.parentNodes;return this.reset(),JSON.stringify(e)!==JSON.stringify(this.computedStyle)||(JSON.stringify(t)!==JSON.stringify(this.rect)||(JSON.stringify(s)!==JSON.stringify(this.computedBorder)||!(i.length===this.parentNodes.length||!i.some((e=>!this.parentNodes.includes(e))))))};reset=()=>{this._computedStyle=void 0,this._rect=void 0,this._computedBorder=void 0,this._parentNodes=void 0};stop=()=>{this._observers?.cleanup(),this.reset()};scroll=(e,t)=>{const s={scroll_directions:e,scroll_multiplier:t};this.PS.publish("Area:scroll:pre",s),((e,t,s=1)=>{if(!t?.length||!e)return;let i=e;if(e instanceof Document&&(r&&(i=r),Number.isFinite(document?.documentElement?.scrollTop))){const e=document.documentElement.scrollTop;document.documentElement.scrollTop+=1,document.documentElement.scrollTop===e?(i=document.body,r=document.body):(document.documentElement.scrollTop=e,i=document.documentElement,r=document.documentElement)}const n=t.includes("top")&&i.scrollTop>0,o=t.includes("bottom")&&i.scrollTop<i.scrollHeight,l=t.includes("left")&&i.scrollLeft>0,a=t.includes("right")&&i.scrollLeft<i.scrollWidth;n&&(i.scrollTop-=1*s),o&&(i.scrollTop+=1*s),l&&(i.scrollLeft-=1*s),a&&(i.scrollLeft+=1*s)})(this._node,e,t),this.PS.publish("Area:scroll",s)};get HTMLNode(){return this._node}get computedBorder(){return this._computedBorder?this._computedBorder:{top:parseInt(this.computedStyle.borderTopWidth),bottom:parseInt(this.computedStyle.borderBottomWidth),left:parseInt(this.computedStyle.borderLeftWidth),right:parseInt(this.computedStyle.borderRightWidth)}}get computedStyle(){if(this._computedStyle)return this._computedStyle;let e;return e=this.HTMLNode instanceof Document?window.getComputedStyle(this.HTMLNode.body||this.HTMLNode.documentElement):window.getComputedStyle(this.HTMLNode),this._computedStyle={borderTopWidth:e.borderTopWidth,borderBottomWidth:e.borderBottomWidth,borderLeftWidth:e.borderLeftWidth,borderRightWidth:e.borderRightWidth,position:e.position}}get rect(){return this._rect?this._rect:this._rect=((e,t)=>{if(e instanceof Document)return{top:0,left:0,bottom:0,right:0,width:window.innerWidth,height:window.innerHeight};const s=e.getBoundingClientRect();return{top:s.top,left:s.left,bottom:s.bottom,right:s.right,width:(e.clientWidth||s.width)*t,height:(e.clientHeight||s.height)*t}})(this.HTMLNode,this.DS.stores.SettingsStore.s.zoom)}get parentNodes(){return this._parentNodes?this._parentNodes:this._parentNodes=s(this.HTMLNode)}}const o=({x:e,y:t},s,{x:i,y:r})=>({"+":{x:e+i,y:t+r},"-":{x:e-i,y:t-r},"*":{x:e*i,y:t*r},"/":{x:e/i,y:t/r}}[s]),l=e=>({x:e.left,y:e.top}),a=(e,t=0)=>({left:e.x,top:e.y,right:e.x,bottom:e.y,width:t,height:t}),h=e=>({x:e,y:e}),c=e=>{const t={x:0,y:0},s=window.getComputedStyle(e);if(!s.transform||"none"===s.transform)return t;if(s.transform.indexOf("3d")>=0){const e=s.transform.trim().match(/matrix3d\((.*?)\)/);if(e&&e.length){const s=e[1]?.split(",");t.x=parseInt(s[12])||0,t.y=parseInt(s[13])||0}return t}const i=s.transform.trim().match(/matrix\((.*?)\)/);if(i&&i.length){const e=i[1]?.split(",");t.x=parseInt(e[4])||0,t.y=parseInt(e[5])||0}return t},d=(e,t)=>t?(e=>{const{transform:t}=e.style;if(!t||t.indexOf("translate")<0)return c(e);const s={x:0,y:0},i=t.trim().match(/translate[3dD]*?\(.*?\)/);if(i){const e=i[0]?.split("(");if(e){const t=e[1]?.split(",");s.x=parseInt(t[0])||0,s.y=parseInt(t[1])||0}}return s.x||s.x?s:c(e)})(e):(e=>{const{style:t}=e,s={x:parseInt(t.left)||0,y:parseInt(t.top)||0};if(!s.x&&!s.x){const t=window.getComputedStyle(e);return{x:parseInt(t.left)||0,y:parseInt(t.top)||0}}return s})(e),S=({containerRect:e,selectionRect:t,direction:s,scrollAmount:i})=>{const r={top:e.top-t.top+i.y,left:e.left-t.left+i.x,bottom:e.bottom-t.bottom+i.y,right:e.right-t.right+i.x};return 0===s.x&&0===s.y||(s.y<0&&(s.y=Math.max(s.y,r.top)),s.x<0&&(s.x=Math.max(s.x,r.left)),s.y>0&&(s.y=Math.min(s.y,r.bottom)),s.x>0&&(s.x=Math.min(s.x,r.right)),t.top+=s.y,t.bottom+=s.y,t.left+=s.x,t.right+=s.x),s};class u{_prevCursorPos;_prevScrollPos;_elements=[];_dragKeys;_dragKeysFlat=[];_selectionRect=a(h(0));DS;PS;Settings;constructor({DS:e,PS:t}){this.DS=e,this.PS=t,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Settings:updated:dragKeys",this.assignDragKeys),this.assignDragKeys(),this.PS.subscribe("Interaction:start",this.start),this.PS.subscribe("Interaction:end",this.stop),this.PS.subscribe("Interaction:update",this.update),this.PS.subscribe("KeyStore:down",this.keyboardDrag),this.PS.subscribe("KeyStore:up",this.keyboardEnd)}assignDragKeys=()=>{this._dragKeys={up:this.Settings.dragKeys.up.map((e=>e.toLowerCase())),down:this.Settings.dragKeys.down.map((e=>e.toLowerCase())),left:this.Settings.dragKeys.left.map((e=>e.toLowerCase())),right:this.Settings.dragKeys.right.map((e=>e.toLowerCase()))},this._dragKeysFlat=[...this._dragKeys.up,...this._dragKeys.down,...this._dragKeys.left,...this._dragKeys.right]};keyboardDrag=({event:e,key:t})=>{const s=t.toLowerCase();if(!this.Settings.keyboardDrag||!this._dragKeysFlat.includes(s)||!this.DS.SelectedSet.size||!this.Settings.draggability||this.DS.continue)return;const i={event:e,isDragging:!0,isDraggingKeyboard:!0,key:t};this.PS.publish(["Interaction:start:pre","Interaction:start"],i),this._elements=this.DS.getSelection(),this._selectionRect=this.DS.Selection.boundingRect,this.handleZIndex(!0);let r=(({shiftKey:e,keyboardDragSpeed:t,zoom:s,key:i,dragKeys:r,scrollDiff:n})=>{const o={x:0,y:0},l=e?4*t*s:t*s;return r?.left.includes(i)&&(o.x=n.x||-l),r?.right.includes(i)&&(o.x=n.x||l),r?.up.includes(i)&&(o.y=n.y||-l),r?.down.includes(i)&&(o.y=n.y||l),o})({shiftKey:this.DS.stores.KeyStore.currentValues.includes("shift"),keyboardDragSpeed:this.Settings.keyboardDragSpeed,zoom:this.Settings.zoom,key:s,scrollDiff:this._scrollDiff,dragKeys:this._dragKeys});r=S({direction:r,containerRect:this.DS.SelectorArea.rect,scrollAmount:this.DS.stores.ScrollStore.scrollAmount,selectionRect:this._selectionRect}),this.moveElements(r),this.PS.publish(["Interaction:update:pre","Interaction:update"],i)};keyboardEnd=({event:e,key:t})=>{const s=t.toLowerCase();if(!(this.Settings.keyboardDrag&&this._dragKeysFlat.includes(s)&&this.DS.SelectedSet.size&&this.Settings.draggability))return;const i={event:e,isDragging:this.Settings.draggability,isDraggingKeyboard:!0,key:t};this.PS.publish(["Interaction:end:pre","Interaction:end"],i)};start=({isDragging:e,isDraggingKeyboard:t})=>{e&&!t&&(this._prevCursorPos=void 0,this._prevScrollPos=void 0,this._elements=this.DS.getSelection(),this._selectionRect=this.DS.Selection.boundingRect,this.handleZIndex(!0))};stop=()=>{this._prevCursorPos=void 0,this._prevScrollPos=void 0,this.handleZIndex(!1),this._elements=[]};update=({isDragging:e,isDraggingKeyboard:t})=>{if(!e||!this._elements.length||t||this.DS.continue)return;let s=o(this._cursorDiff,"+",this._scrollDiff);s=S({direction:s,containerRect:this.DS.SelectorArea.rect,scrollAmount:this.DS.stores.ScrollStore.scrollAmount,selectionRect:this._selectionRect}),this.moveElements(s)};handleZIndex=e=>{this.Settings.useLayers&&this._elements.forEach((t=>t.style.zIndex=`${(parseInt(t.style.zIndex)||0)+(e?9999:-9998)}`))};moveElements=e=>{const{elements:t,direction:s}=this.filterDragElements({elements:this._elements,direction:e});t.forEach((e=>{(({element:e,posDirection:t,useTransform:s})=>{const i=d(e,s);((e,t,s)=>{if(s){const s=e.style.transform;e.style.transform=`translate3d(${t.x}px,${t.y}px,1px) ${s.replace(/translate.*?\)/g,"")}`}else e.style.left=`${t.x}px`,e.style.top=`${t.y}px`})(e,o(i,"+",t),s)})({element:e,posDirection:s,containerRect:this.DS.SelectorArea.rect,useTransform:this.Settings.useTransform})}))};get _cursorDiff(){const e=this.DS.stores.PointerStore.currentVal,t=this._prevCursorPos?o(e,"-",this._prevCursorPos):{x:0,y:0};return this._prevCursorPos=e,t}get _scrollDiff(){const e=this.DS.stores.ScrollStore.currentVal,t=this._prevScrollPos?o(e,"-",this._prevScrollPos):{x:0,y:0};return this._prevScrollPos=e,t}filterDragElements=({elements:e,direction:t})=>({elements:e,direction:t})}const p=(e,t,s=0)=>{if(!e||!t)return!1;let i=e;if(s>0){const t=(e.right-e.left)*s,r=(e.bottom-e.top)*s;i={left:e.left+t,right:e.right-t,top:e.top+r,bottom:e.bottom-r}}return i.left<t.right&&i.right>t.left&&i.top<t.bottom&&i.bottom>t.top},g=e=>e?Array.isArray(e)||"function"==typeof e[Symbol.iterator]?[...new Set([...e])]:[e]:[];class m{id;element;_droppables;_rect;_observers;_timeout;_itemsDropped=[];_itemsInside;DS;PS;Settings;isDestroyed=!1;_parentNodes;constructor({DS:s,PS:i,id:r,element:n,droppables:o}){this.DS=s,this.PS=i,this.Settings=this.DS.stores.SettingsStore.s,this.id=r,this.element=n,o&&(this.droppables=g(o)),this.element.classList.add(`${this.Settings.dropZoneClass}`),this.PS.subscribe("Settings:updated:dropZoneClass",(({settings:e})=>{this.element&&(this.element.classList.remove(e["dropZoneClass:pre"]),this.element.classList.add(e.dropZoneClass))})),this._observers=e(this.parentNodes,t((()=>this._rect=void 0),this.Settings.refreshMemoryRate)),this.PS.subscribe("Interaction:start",this.start),this.PS.subscribe("Interaction:end",this.stop)}setReadyClasses=e=>{if(this.isDestroyed)return;const t=this.droppables.filter((e=>this.DS.SelectedSet.has(e)));t.length&&(t.forEach((t=>{t.classList[e](`${this.Settings.droppableClass}`),t.classList[e](`${this.Settings.droppableClass}-${this.id}`)})),this.element.classList[e](`${this.Settings.dropZoneReadyClass}`))};handleNoDrop=()=>{this.isDestroyed||(this.DS.SelectedSet.forEach((e=>{e.classList.remove(this.Settings.droppedTargetClass),e.classList.remove(`${this.Settings.droppedTargetClass}-${this.id}`)})),this._itemsDropped=this._itemsDropped.filter((e=>!this.DS.SelectedSet.has(e))),this._itemsDropped?.length||this.element.classList.remove(`${this.Settings.dropZoneTargetClass}`))};handleDrop=()=>{this.isDestroyed||(this._itemsDropped=[...new Set([...this._itemsDropped,...this.droppables?.filter((e=>this.DS.SelectedSet.has(e)))])],this._itemsDropped?.forEach((e=>{e.classList.add(`${this.Settings.droppedTargetClass}`),e.classList.add(`${this.Settings.droppedTargetClass}-${this.id}`)})),this._itemsDropped?.length&&this.element.classList.add(`${this.Settings.dropZoneTargetClass}`))};handleItemsInsideClasses=()=>{let e=!1;this.droppables.forEach((t=>{this.itemsInside?.includes(t)?(t.classList.add(`${this.Settings.droppedInsideClass}`),t.classList.add(`${this.Settings.droppedInsideClass}-${this.id}`),e=!0):(t.classList.remove(`${this.Settings.droppedInsideClass}-${this.id}`),t.className.includes(`${this.Settings.droppedInsideClass}-`)||t.classList.remove(`${this.Settings.droppedInsideClass}`))})),e?this.element.classList.add(`${this.Settings.dropZoneInsideClass}`):this.element.classList.remove(`${this.Settings.dropZoneInsideClass}`)};start=({isDragging:e})=>{e&&!this.isDestroyed&&this.setReadyClasses("add")};stop=({isDragging:e})=>{e&&!this.isDestroyed&&(this.setReadyClasses("remove"),this.handleItemsInsideClasses())};destroy(){this._observers?.cleanup(),this.element.classList.remove(`${this.Settings.dropZoneClass}`),this.element.classList.remove(`${this.Settings.dropZoneTargetClass}`),this.element.classList.remove(`${this.Settings.dropZoneReadyClass}`),this.droppables.forEach((e=>{e.classList.remove(`${this.Settings.droppedTargetClass}`),e.classList.remove(`${this.Settings.droppedTargetClass}-${this.id}`),e.classList.remove(`${this.Settings.droppableClass}`),e.classList.remove(`${this.Settings.droppableClass}-${this.id}`)})),this.PS.unsubscribe("Interaction:start",this.start),this.PS.unsubscribe("Interaction:end",this.stop),this.isDestroyed=!0}toObject=()=>({id:this.id,element:this.element,droppables:this.droppables,itemsDropped:this.itemsDropped,itemsInside:this.itemsInside});get rect(){if(!this.isDestroyed)return this._rect?this._rect:this._rect=this.element.getBoundingClientRect()}get itemsDropped(){if(!this.isDestroyed)return this._itemsDropped}get itemsInside(){if(!this.isDestroyed)return this._itemsInside||(this._itemsInside=this.droppables.flatMap((e=>{const t=this.DS.SelectableSet.rects.get(e);return this.rect&&p(t,this.rect,this.Settings.dropInsideThreshold)?[e]:[]})),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout((()=>this._itemsInside=void 0),this.Settings.refreshMemoryRate)),this._itemsInside}get parentNodes(){return this._parentNodes?this._parentNodes:this._parentNodes=s(this.element)}get droppables(){return this._droppables?this._droppables:this.DS.SelectableSet.elements}set droppables(e){this._droppables=e}}class b{_zoneByElement=new Map;_zoneById=new Map;_zonesByDroppable=new Map;_zones;DS;PS;Settings;constructor({DS:e,PS:t}){this.DS=e,this.PS=t,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Settings:updated:dropZones",(({settings:e})=>this.setDropZones(e))),this.setDropZones({dropZones:this.Settings.dropZones}),this.PS.subscribe("Interaction:end",this.stop)}setDropZones=({dropZones:e})=>{e&&(this._zones&&this._zones.forEach((e=>e.destroy())),this._zones=e.map((e=>new m({DS:this.DS,PS:this.PS,...e}))),this._zones.forEach((e=>{this._zoneByElement.set(e.element,e),this._zoneById.set(e.id,e),e.droppables.forEach((t=>{const s=this._zonesByDroppable.get(t);if(!s?.length)return this._zonesByDroppable.set(t,[e]);this._zonesByDroppable.set(t,[...new Set([...s,e])])}))})))};_handleDrops=e=>{this._zones?.forEach((t=>{t!==e&&t.handleNoDrop()})),e&&e.handleDrop()};_getZoneByElementsFromPoint=(e,{x:t,y:s})=>{for(let i=0,r=e.length;i<r;i++){const r=this._zoneByElement.get(e[i]);if(p(r?.rect,{left:t,right:t,top:s,bottom:s},Math.min(this.Settings.dropTargetThreshold,.5)))return r}};stop=({isDragging:e,isDraggingKeyboard:t,event:s})=>{if(!e)return;const i=this.getTarget({isDraggingKeyboard:t,event:s});this._handleDrops(i)};getItemsDroppedById=e=>{const t=this._zoneById.get(e);return t?t.itemsDropped:console.warn(`[DragSelect] No zone found (id: ${e})`)};getItemsInsideById=(e,t)=>{const s=this._zoneById.get(e);return s?(t&&s.handleItemsInsideClasses(),s.itemsInside):console.warn(`[DragSelect] No zone found (id: ${e})`)};getKeyboardItemCenter=(e,t)=>{if(!e||!t)return;const s=t.target?.getBoundingClientRect();return{x:s.left+s.width/2,y:s.top+s.height/2}};getTarget=({coordinates:e,isDraggingKeyboard:t,event:s})=>{if(!this._zones?.length)return;let i;!e&&t&&s&&(i=this.getKeyboardItemCenter(t,s));const r=e?.x||i?.x||this.DS.stores.PointerStore.currentVal.x,n=e?.y||i?.y||this.DS.stores.PointerStore.currentVal.y,o=document.elementsFromPoint(r,n);return this._getZoneByElementsFromPoint(o,{x:r,y:n})}}class y{isInteracting;isDragging=!1;DS;PS;Settings;constructor({DS:e,PS:t}){this.DS=e,this.PS=t,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Settings:updated:area",(({settings:e})=>{this.removeAreaEventListeners(e["area:pre"]),this.setAreaEventListeners(e.area)})),this.PS.subscribe("PointerStore:updated",(({event:e})=>this.update({event:e}))),this.PS.subscribe("Selectable:click",this.onClick),this.PS.subscribe("Selectable:pointer",(({event:e})=>this.start(e))),this.PS.subscribe("Interaction:start:pre",(({event:e})=>this._start(e))),this.PS.subscribe("Interaction:init:pre",this._init),this.PS.subscribe("Interaction:end:pre",(({event:e})=>this._reset(e))),this.PS.subscribe("Area:scroll",this.update)}init=()=>this.PS.publish("Interaction:init:pre",{init:!0});_init=()=>{this.stop(),this.setAreaEventListeners(),this.PS.publish("Interaction:init",{init:!0})};_canInteract(e){const t="clientX"in e&&0===e.clientX&&0===e.clientY&&0===e.detail&&e.target;return!("button"in e&&2===e.button||this.isInteracting||e.target&&!this.DS.SelectorArea.isInside(e.target)||!t&&!this.DS.SelectorArea.isClicked(e))}start=e=>this.PS.publish("Interaction:start:pre",{event:e,isDragging:this.isDragging});_start=e=>{"touchstart"===e.type&&e.preventDefault(),this._canInteract(e)&&(this.isInteracting=!0,this.isDragging=this.isDragEvent(e),this.PS.publish("Interaction:start",{event:e,isDragging:this.isDragging}),this.setDocEventListeners())};isDragEvent=e=>{let t=null;return e.target&&"closest"in e.target&&(t=e.target.closest(`.${this.Settings.selectableClass}`)),!(!this.Settings.draggability||this.DS.stores.KeyStore.isMultiSelectKeyPressed(e)||!t)&&(this.Settings.immediateDrag&&(this.DS.SelectedSet.size?this.DS.SelectedSet.has(t)||(this.DS.SelectedSet.clear(),this.DS.SelectedSet.add(t)):this.DS.SelectedSet.add(t)),!!this.DS.SelectedSet.has(t))};onClick=({event:e})=>{if(!this._canInteract(e))return;if(e.detail>0)return;const{stores:{PointerStore:t,KeyStore:s},SelectableSet:i,SelectedSet:r}=this.DS;t.start(e);const n=e.target;n&&!i.has(n)||(s.isMultiSelectKeyPressed(e)||r.clear(),n&&r.toggle(n),this.reset(e))};stop=(e=this.DS.Area.HTMLNode)=>{this.removeAreaEventListeners(e),this.removeDocEventListeners()};update=({event:e,scroll_directions:t,scroll_multiplier:s})=>{this.isInteracting&&this.PS.publish(["Interaction:update:pre","Interaction:update"],{event:e,scroll_directions:t,scroll_multiplier:s,isDragging:this.isDragging})};reset=e=>this.PS.publish("Interaction:end:pre",{event:e,isDragging:this.isDragging});_reset=e=>{const{isDragging:t}=this;this.isInteracting=!1,this.isDragging=!1,this.removeDocEventListeners(),this.PS.publish("Interaction:end",{event:e,isDragging:t})};setAreaEventListeners=(e=this.DS.Area.HTMLNode)=>{this.Settings.usePointerEvents?e.addEventListener("pointerdown",this.start,{passive:!1}):e.addEventListener("mousedown",this.start),e.addEventListener("touchstart",this.start,{passive:!1})};removeAreaEventListeners=(e=this.DS.Area.HTMLNode)=>{this.Settings.usePointerEvents?e.removeEventListener("pointerdown",this.start,{passive:!1}):e.removeEventListener("mousedown",this.start),e.removeEventListener("touchstart",this.start,{passive:!1})};setDocEventListeners=()=>{this.Settings.usePointerEvents?(document.addEventListener("pointerup",this.reset),document.addEventListener("pointercancel",this.reset)):document.addEventListener("mouseup",this.reset),document.addEventListener("touchend",this.reset)};removeDocEventListeners=()=>{this.Settings.usePointerEvents?(document.removeEventListener("pointerup",this.reset),document.removeEventListener("pointercancel",this.reset)):document.removeEventListener("mouseup",this.reset),document.removeEventListener("touchend",this.reset)}}class D{_currentValues=new Set;_keyMapping={control:"ctrlKey",shift:"shiftKey",meta:"metaKey"};DS;PS;settings;constructor({DS:e,PS:t}){this.DS=e,this.PS=t,this.settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Interaction:init",this.init)}init=()=>{document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup),window.addEventListener("blur",this.reset)};keydown=e=>{if(!e.key?.toLocaleLowerCase)return;const t=e.key.toLowerCase();this.PS.publish("KeyStore:down:pre",{event:e,key:t}),this._currentValues.add(t),this.PS.publish("KeyStore:down",{event:e,key:t})};keyup=e=>{if(!e.key?.toLocaleLowerCase)return;const t=e.key.toLowerCase();this.PS.publish("KeyStore:up:pre",{event:e,key:t}),this._currentValues.delete(t),this.PS.publish("KeyStore:up",{event:e,key:t})};stop=()=>{document.removeEventListener("keydown",this.keydown),document.removeEventListener("keyup",this.reset),window.removeEventListener("blur",this.reset),this.reset()};reset=()=>this._currentValues.clear();isMultiSelectKeyPressed(e){if(this.settings.multiSelectMode)return!0;const t=this.settings.multiSelectKeys?.map((e=>e.toLocaleLowerCase()))??[];return!!this.currentValues.some((e=>t.includes(e)))||!(!e||!t.some((t=>e[this._keyMapping[t]])))}get currentValues(){return Array.from(this._currentValues.values())}}class _{_isMouseInteraction=!1;_initialValArea={x:0,y:0};_currentValArea={x:0,y:0};_lastValArea={x:0,y:0};_initialVal={x:0,y:0};_currentVal={x:0,y:0};_lastVal={x:0,y:0};_lastTouch;DS;PS;settings;constructor({DS:e,PS:t}){this.DS=e,this.PS=t,this.settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Interaction:init",this.init),this.PS.subscribe("Interaction:start",(({event:e})=>this.start(e))),this.PS.subscribe("Interaction:end",(({event:e})=>this.reset(e)))}init=()=>{this.settings.usePointerEvents?document.addEventListener("pointermove",this.update,{passive:!1}):document.addEventListener("mousemove",this.update),document.addEventListener("touchmove",this.update,{passive:!1})};start(e){e&&(this._isMouseInteraction=!0,this.currentVal=this.initialVal=this.getPointerPosition(e))}getPointerPosition=e=>(({event:e})=>({x:e.clientX,y:e.clientY}))({event:this._normalizedEvent(e)});update=e=>{e&&(this.PS.publish("PointerStore:updated:pre",{event:e}),this.currentVal=this.getPointerPosition(e),this._isMouseInteraction&&this.PS.publish("PointerStore:updated",{event:e}))};stop=()=>{this.settings.usePointerEvents?document.removeEventListener("pointermove",this.update,{passive:!1}):document.removeEventListener("mousemove",this.update),document.removeEventListener("touchmove",this.update,{passive:!1}),this.reset()};reset=e=>{this.currentVal=this.lastVal=this.getPointerPosition(e),setTimeout((()=>this._isMouseInteraction=!1),100)};_normalizedEvent(e){return!e||e instanceof KeyboardEvent?{clientX:0,clientY:0}:"touches"in e?("touchend"!==e.type&&(this._lastTouch=e),this._lastTouch?.touches[0]||e.touches[0]):e}get initialValArea(){return this._initialValArea?this._initialValArea:{x:0,y:0}}get currentValArea(){return this._currentValArea?this._currentValArea:{x:0,y:0}}get lastValArea(){return this._lastValArea?this._lastValArea:{x:0,y:0}}get initialVal(){return this._initialVal?this._initialVal:{x:0,y:0}}get currentVal(){return this._currentVal?this._currentVal:{x:0,y:0}}get lastVal(){return this._lastVal?this._lastVal:{x:0,y:0}}set initialVal(e){this._initialVal=e,this._initialValArea=e&&o(e,"-",o(l(this.DS.Area.rect),"+",l(this.DS.Area.computedBorder)))}set currentVal(e){this._currentVal=e,this._currentValArea=e&&o(e,"-",o(l(this.DS.Area.rect),"+",l(this.DS.Area.computedBorder)))}set lastVal(e){this._lastVal=e,this._lastValArea=e&&o(e,"-",o(l(this.DS.Area.rect),"+",l(this.DS.Area.computedBorder)))}}class v{subscribers={};_ids={};_nextId=0;DS;constructor({DS:e}){this.DS=e}subscribe=(e,t)=>{this.subscribers[e]||(this.subscribers[e]=[]),this._ids[e]||(this._ids[e]=[]);const s=this.subscribers[e],i=this._ids[e],r=this._nextId++;return s.push(t),i.push(r),r};unsubscribe=(e,t,s)=>{const i=this.subscribers[e],r=this._ids[e];if(!i||!r)return;const n=null!=s?r.indexOf(s):t?i.indexOf(t):-1;-1!==n&&(i.splice(n,1),r.splice(n,1))};publish=(e,t)=>{Array.isArray(e)?e.forEach((e=>this._publish(e,t))):this._publish(e,t)};_publish=(e,t)=>{const s=[...this.subscribers[e]??[]];e.includes(":pre")?this._handlePrePublish(s,t):this._handlePublish(s,t)};_handlePublish=(e,t)=>{for(let s=0,i=e.length;s<i;s++){if(this.DS.stopped)return;e[s]?.(t)}};_handlePrePublish=(e,t)=>{let s=e.length;for(;s--;){if(this.DS.stopped)return;e[s]?.(t)}}}const P=()=>({y:document.body?.scrollTop||document.documentElement?.scrollTop||0,x:document.body?.scrollLeft||document.documentElement?.scrollLeft||0}),f=e=>!e||e instanceof Document?P():{x:e.scrollLeft>=0?e.scrollLeft:P().x,y:e.scrollTop>=0?e.scrollTop:P().y},I=e=>{const t=e.scrollTop,s=Boolean(e.scrollTop=1);return e.scrollTop=t,s};class L{_initialVal={x:0,y:0};_currentVal={x:0,y:0};_canScroll;DS;PS;Settings;constructor({DS:e,PS:t}){this.DS=e,this.PS=t,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Area:modified",(()=>{this.stop(),this.init()})),this.PS.subscribe("Interaction:init",this.init),this.PS.subscribe("Interaction:start",(()=>this.start())),this.PS.subscribe("Interaction:end",(()=>this.reset()))}init=()=>this.addListeners();addListeners=()=>this.DS.Area.HTMLNode.addEventListener("scroll",this.update);removeListeners=()=>this.DS.Area.HTMLNode.removeEventListener("scroll",this.update);start=()=>{this._currentVal=this._initialVal=f(this.DS.Area.HTMLNode)};update=()=>this._currentVal=f(this.DS.Area.HTMLNode);stop=()=>{this.reset(),this.removeListeners()};reset=()=>{this._initialVal={x:0,y:0},this._canScroll=void 0};get canScroll(){return"boolean"==typeof this._canScroll?this._canScroll:this._canScroll=(e=>{const t=f(e);return!(!t.x&&!t.y)||(e instanceof Document?e.body?I(e.body):I(e.documentElement):I(e))})(this.DS.Area.HTMLNode)}get scrollAmount(){const e=o(this.currentVal,"-",this.initialVal),t=h(this.Settings.zoom),s=o(o(e,"*",t),"-",e);return{x:e.x+s.x,y:e.y+s.y}}get initialVal(){return this._initialVal?this._initialVal:{x:0,y:0}}get currentVal(){return this._currentVal||(this._currentVal=f(this.DS.Area.HTMLNode)),this._currentVal}}class T extends Set{_rects;_timeout;DS;PS;Settings;constructor({DS:e,PS:t}){super(),this.DS=e,this.PS=t,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Interaction:init",this.init),this.PS.subscribe("Settings:updated:selectables",(()=>{this.clear(),this.init()})),this.PS.subscribe("Settings:updated:selectableClass",(({settings:e})=>{this.forEach((t=>{t.classList.remove(e["selectableClass:pre"]),t.classList.add(e.selectableClass)}))}))}init=()=>g(this.Settings.selectables).forEach((e=>this.add(e)));add(e){if(!e||super.has(e))return this;const t={items:this.elements,item:e};return this.PS.publish("Selectable:added:pre",t),e.classList.add(this.Settings.selectableClass),e.addEventListener("click",this._onClick),this.Settings.usePointerEvents?e.addEventListener("pointerdown",this._onPointer,{passive:!1}):e.addEventListener("mousedown",this._onPointer),e.addEventListener("touchstart",this._onPointer,{passive:!1}),this.Settings.draggability&&!this.Settings.useTransform&&i({computedStyle:window.getComputedStyle(e),node:e}),this.PS.publish("Selectable:added",t),super.add(e)}delete(e){if(!e||!super.has(e))return!0;const t={items:this.elements,item:e};return this.PS.publish("Selectable:removed:pre",t),e.classList.remove(this.Settings.selectableClass),e.classList.remove(this.Settings.hoverClass),e.removeEventListener("click",this._onClick),this.Settings.usePointerEvents?e.removeEventListener("pointerdown",this._onPointer,{passive:!1}):e.removeEventListener("mousedown",this._onPointer),e.removeEventListener("touchstart",this._onPointer,{passive:!1}),this.PS.publish("Selectable:removed",t),super.delete(e)}clear=()=>this.forEach((e=>this.delete(e)));_onClick=e=>this.PS.publish(["Selectable:click:pre","Selectable:click"],{event:e});_onPointer=e=>this.PS.publish(["Selectable:pointer:pre","Selectable:pointer"],{event:e});addAll=e=>e.forEach((e=>this.add(e)));deleteAll=e=>e.forEach((e=>this.delete(e)));getElementRect=e=>this._rects?this._rects.get(e):e.getBoundingClientRect();get elements(){return Array.from(this.values())}get rects(){return this._rects||(this._rects=new Map,this.forEach((e=>this._rects?.set(e,e.getBoundingClientRect()))),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout((()=>this._rects=void 0),this.Settings.refreshMemoryRate)),this._rects}}class E extends Set{_rects;_timeout;DS;PS;Settings;constructor({DS:e,PS:t}){super(),this.DS=e,this.PS=t,this.Settings=this.DS.stores.SettingsStore.s}add(e){if(!e||super.has(e))return this;const t={items:this.elements,item:e};return this.PS.publish("Selected:added:pre",t),super.add(e),e.classList.add(this.Settings.selectedClass),this.Settings.useLayers&&(e.style.zIndex=`${(parseInt(e.style.zIndex)||0)+1}`),this.PS.publish("Selected:added",t),this}delete(e){if(!e||!super.has(e))return!0;const t={items:this.elements,item:e};this.PS.publish("Selected:removed:pre",t);const s=super.delete(e);return e.classList.remove(this.Settings.selectedClass),this.Settings.useLayers&&(e.style.zIndex=""+((parseInt(e.style.zIndex)||0)-1)),this.PS.publish("Selected:removed",t),s}clear=()=>this.forEach((e=>this.delete(e)));toggle(e){return this.has(e)?this.delete(e):this.add(e),e}addAll=e=>e.forEach((e=>this.add(e)));deleteAll=e=>e.forEach((e=>this.delete(e)));get elements(){return Array.from(this.values())}get rects(){return this._rects||(this._rects=new Map,this.forEach((e=>this._rects?.set(e,e.getBoundingClientRect()))),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout((()=>this._rects=void 0),this.Settings.refreshMemoryRate)),this._rects}}var C=(e,t)=>{t.left&&(e.style.left=`${t.left}px`),t.top&&(e.style.top=`${t.top}px`),t.width&&(e.style.width=`${t.width}px`),t.height&&(e.style.height=`${t.height}px`)};class x{_rect;DS;PS;Settings;HTMLNode;constructor({DS:e,PS:t}){this.DS=e,this.PS=t,this.Settings=this.DS.stores.SettingsStore.s,this.HTMLNode=this.Settings.selector,this.PS.subscribe("Settings:updated:selectorClass",(({settings:e})=>{this.HTMLNode.classList.remove(e["selectorClass:pre"]),this.HTMLNode.classList.add(e.selectorClass)})),this.PS.subscribe("Settings:updated:selector",this.attachSelector),this.PS.subscribe("Settings:updated:customStyles",this.attachSelector),this.attachSelector(),this.PS.subscribe("Interaction:start",this.start),this.PS.subscribe("Interaction:update",this.update),this.PS.subscribe("Interaction:end",this.stop)}attachSelector=()=>{this.HTMLNode&&this.DS.SelectorArea?.HTMLNode&&this.DS.SelectorArea.HTMLNode.removeChild(this.HTMLNode),this.HTMLNode=this.Settings.selector||(e=>{const t=document.createElement("div");return t.style.position="absolute",e||(t.style.background="rgba(0, 175, 255, 0.2)",t.style.border="1px solid rgba(0, 175, 255, 0.8)",t.style.display="none",t.style.pointerEvents="none"),t})(this.Settings.customStyles),this.HTMLNode.classList.add(this.Settings.selectorClass),this.HTMLNode&&this.DS.SelectorArea?.HTMLNode&&this.DS.SelectorArea.HTMLNode.appendChild(this.HTMLNode)};start=({isDragging:e})=>{if(e)return;const{stores:{PointerStore:t}}=this.DS,s=t.initialValArea;C(this.HTMLNode,a(s,1)),this.HTMLNode.style.display="block",this._rect=void 0};stop=()=>{this.HTMLNode.style.width="0",this.HTMLNode.style.height="0",this.HTMLNode.style.display="none"};update=({isDragging:e})=>{if(e||this.DS.continue)return;const{stores:{ScrollStore:t,PointerStore:s}}=this.DS,i=(({scrollAmount:e,initialPointerPos:t,pointerPos:s})=>{const i={};return s.x>t.x-e.x?(i.left=t.x-e.x,i.width=s.x-t.x+e.x):(i.left=s.x,i.width=t.x-s.x-e.x),s.y>t.y-e.y?(i.top=t.y-e.y,i.height=s.y-t.y+e.y):(i.top=s.y,i.height=t.y-s.y-e.y),i})({scrollAmount:t.scrollAmount,initialPointerPos:s.initialValArea,pointerPos:s.currentValArea});C(this.HTMLNode,i),this._rect=void 0};get rect(){return this._rect?this._rect:this._rect=this.HTMLNode.getBoundingClientRect()}}class A{_prevSelectedSet=new Set;_boundingRect;_timeout;DS;PS;Settings;constructor({DS:e,PS:t}){this.DS=e,this.PS=t,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Interaction:start",this.start),this.PS.subscribe("Interaction:update",this.update)}_storePrevious(e){const{stores:{KeyStore:t},SelectedSet:s}=this.DS;t.isMultiSelectKeyPressed(e)?this._prevSelectedSet=new Set(s):this._prevSelectedSet=new Set}start=({event:e,isDragging:t})=>{t||(this._storePrevious(e),this._handleInsideSelection(!0,e))};update=({isDragging:e})=>{e||this.DS.continue||this._handleInsideSelection()};_handleInsideSelection=(e,t)=>{const{SelectableSet:s,SelectorArea:i,Selector:r}=this.DS,n=this.DS.stores.KeyStore.isMultiSelectKeyPressed(t)&&this.Settings.multiSelectToggling,o=this.Settings.selectionThreshold,l=s.rects,a=r.rect,h=new Map,c=new Map;for(const[e,t]of l)i.isInside(e,t)&&(p(t,a,o)?h.set(e,t):c.set(e,t));if(this.DS.continue)return;const{select:d,unselect:S}=this.filterSelected({select:h,unselect:c,selectorRect:a});d.forEach(((t,s)=>(({element:e,force:t,multiSelectionToggle:s,SelectedSet:i,hoverClassName:r})=>{e.classList.contains(r)&&!t||(i.has(e)?s&&i.delete(e):i.add(e),e.classList.add(r))})({element:s,force:e,multiSelectionToggle:n,SelectedSet:this.DS.SelectedSet,hoverClassName:this.Settings.hoverClass}))),S.forEach(((t,s)=>(({element:e,force:t,SelectedSet:s,PrevSelectedSet:i,hoverClassName:r})=>{if(!e.classList.contains(r)&&!t)return;const n=s.has(e),o=i.has(e);n&&!o?s.delete(e):!n&&o&&s.add(e),e.classList.remove(r)})({element:s,force:e,SelectedSet:this.DS.SelectedSet,hoverClassName:this.Settings.hoverClass,PrevSelectedSet:this._prevSelectedSet})))};get boundingRect(){return this._boundingRect||(this._boundingRect=(e=>{const t={top:Number.POSITIVE_INFINITY,left:Number.POSITIVE_INFINITY,bottom:Number.NEGATIVE_INFINITY,right:Number.NEGATIVE_INFINITY,width:Number.NEGATIVE_INFINITY,height:Number.NEGATIVE_INFINITY};return e.rects.forEach((e=>{t.top=Math.min(t.top,e.top||t.top),t.left=Math.min(t.left,e.left||t.left),t.bottom=Math.max(t.bottom,e.bottom||t.bottom),t.right=Math.max(t.right,e.right||t.right)})),t.height=t.bottom-t.top,t.width=t.right-t.left,t})(this.DS.SelectedSet),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout((()=>this._boundingRect=void 0),this.Settings.refreshMemoryRate)),this._boundingRect}filterSelected=({select:e,unselect:t,selectorRect:s})=>({select:e,unselect:t})}class w{_scrollInterval;_rect;currentEdges=[];DS;PS;Settings;HTMLNode;constructor({DS:e,PS:t}){this.DS=e,this.PS=t,this.Settings=this.DS.stores.SettingsStore.s,this.HTMLNode=(()=>{const e=document.createElement("div");return e.style.position="fixed",e.style.overflow="hidden",e.style.pointerEvents="none",e.style.zIndex="999999999999999999",e})(),this.PS.subscribe("Settings:updated:selectorAreaClass",(({settings:e})=>{this.HTMLNode.classList.remove(e["selectorAreaClass:pre"]),this.HTMLNode.classList.add(e.selectorAreaClass)})),this.HTMLNode.classList.add(this.Settings.selectorAreaClass),this.PS.subscribe("Area:modified",this.updateParent),this.PS.subscribe("Area:modified",this.updatePos),this.PS.subscribe("Interaction:init",this.init),this.PS.subscribe("Interaction:start",(({isDraggingKeyboard:e})=>this.startAutoScroll({isDraggingKeyboard:e}))),this.PS.subscribe("Interaction:end",(()=>{this.updatePos(),this.stopAutoScroll()}))}init=()=>{this.applyElements("append"),this.updatePos()};get parentNode(){const e=this.DS.Area.HTMLNode;return(e instanceof Element?e.closest("dialog, [popover]"):null)||document.body||document.documentElement}applyElements=e=>{"append"===e?(this.HTMLNode.appendChild(this.DS.Selector.HTMLNode),this.parentNode.appendChild(this.HTMLNode)):(this.DS.Selector.HTMLNode.remove(),this.HTMLNode.remove())};updateParent=()=>{if(!this.HTMLNode.isConnected)return;const e=this.parentNode;this.HTMLNode.parentNode!==e&&e.appendChild(this.HTMLNode)};updatePos=()=>{this._rect=void 0;const e=this.DS.Area.rect,t=this.DS.Area.computedBorder,s=e.top+t.top,i=e.left+t.left;if(this.setPos(s,i,e.width,e.height),!this.HTMLNode.getClientRects().length)return;const r=this.HTMLNode.getBoundingClientRect(),n=r.top-s,o=r.left-i;(Math.abs(n)>.01||Math.abs(o)>.01)&&this.setPos(s-n,i-o,e.width,e.height),this._rect=void 0};setPos=(e,t,s,i)=>{const{style:r}=this.HTMLNode,n=`${e}px`,o=`${t}px`,l=`${s}px`,a=`${i}px`;r.top!==n&&(r.top=n),r.left!==o&&(r.left=o),r.width!==l&&(r.width=l),r.height!==a&&(r.height=a)};stop=e=>{this.stopAutoScroll(),e&&this.applyElements("remove")};startAutoScroll=({isDraggingKeyboard:e})=>{e||(this.currentEdges=[],this._scrollInterval=setInterval((()=>this.handleAutoScroll()),16))};handleAutoScroll=()=>{if(this.DS.continue)return;const{stores:{PointerStore:e},Area:t}=this.DS;this.currentEdges=(({elementRect:e,containerRect:t,tolerance:s={x:0,y:0}})=>{const i=[];return e.top-s.y<t.top&&i.push("top"),e.left-s.x<t.left&&i.push("left"),e.bottom+s.y>t.bottom&&i.push("bottom"),e.right+s.y>t.right&&i.push("right"),i})({elementRect:a(e.currentVal),containerRect:this.rect,tolerance:this.Settings.overflowTolerance}),this.currentEdges.length&&t.scroll(this.currentEdges,this.Settings.autoScrollSpeed)};stopAutoScroll=()=>{this.currentEdges=[],clearInterval(this._scrollInterval)};isInside=(e,t)=>!(!this.DS.Area.HTMLNode.contains(e)||!this.DS.stores.ScrollStore.canScroll)||p(this.rect,t||e.getBoundingClientRect());isClicked(e){const{stores:{PointerStore:t}}=this.DS,s=e?t.getPointerPosition(e):t.initialVal;return p({left:s.x,top:s.y,right:s.x,bottom:s.y},this.rect)}get rect(){return this._rect?this._rect:this._rect=this.HTMLNode.getBoundingClientRect()}}const N=(e,t)=>console.warn(`[DragSelect] TypeIssue: setting "${e}" is not of type "${t}".`),M=(e,t,s,i)=>{if(void 0===t)return s?{[e]:i}:{};if(null===t)return{[e]:null};let r=!0,n=!1;const o="string"==typeof i;o&&(r="string"==typeof t||t instanceof String),o&&!r&&(n=!0,N(e,"string"));const l=!Number.isNaN(i)&&"number"==typeof i;l&&(r=!Number.isNaN(t)&&"number"==typeof t),l&&!r&&(n=!0,N(e,"number"));const a="[object Object]"===Object.prototype.toString.call(i);a&&(r="[object Object]"===Object.prototype.toString.call(t)),a&&!r&&(n=!0,N(e,"object"));const h="boolean"==typeof i;h&&(r="boolean"==typeof t),h&&!r&&(n=!0,N(e,"boolean"));const c=Array.isArray(i);c&&(r=Array.isArray(t)),c&&!r&&(n=!0,N(e,"array"));const d=n||s;return"dragKeys"===e&&r?{[e]:Object.assign(i,t)}:"dragKeys"!==e||r?("dropZones"===e&&r&&Array.isArray(t)&&new Set(t.map((e=>e.id))).size!==t.length&&console.warn('[DragSelect] UniqueConstraintsIssue: setting "dropZones" contains duplicate ids.'),r?{[e]:t}:d?{[e]:i}:{}):d?{[e]:i}:{}};class V{_settings={};s={};PS;constructor({PS:e,settings:t}){this.PS=e,this.update({settings:t,init:!0})}update=({settings:e,init:t})=>{this.PS.publish("Settings:updated:pre",{settings:this._settings,"settings:init":Boolean(t),"settings:new":e}),this._update({settings:e,init:t})};_update=({settings:e={},init:t=!1})=>{const s=((e,t)=>({...M("area",e.area,t,document),...M("selectables",e.selectables,t,null),...M("autoScrollSpeed",e.autoScrollSpeed,t,5),...M("overflowTolerance",e.overflowTolerance,t,{x:25,y:25}),...M("zoom",e.zoom,t,1),...M("customStyles",e.customStyles,t,!1),...M("multiSelectMode",e.multiSelectMode,t,!1),...M("multiSelectToggling",e.multiSelectToggling,t,!0),...M("multiSelectKeys",e.multiSelectKeys,t,["Control","Shift","Meta"]),...M("selector",e.selector,t,null),...M("selectionThreshold",e.selectionThreshold,t,0),...M("draggability",e.draggability,t,!0),...M("immediateDrag",e.immediateDrag,t,!0),...M("keyboardDrag",e.keyboardDrag,t,!0),...M("dragKeys",e.dragKeys,t,{up:["ArrowUp"],down:["ArrowDown"],left:["ArrowLeft"],right:["ArrowRight"]}),...M("keyboardDragSpeed",e.keyboardDragSpeed,t,10),...M("useTransform",e.useTransform,t,!0),...M("refreshMemoryRate",e.refreshMemoryRate,t,80),...M("dropZones",e.dropZones,t,[]),...M("dropInsideThreshold",e.dropInsideThreshold,t,1),...M("dropTargetThreshold",e.dropTargetThreshold,t,0),...M("usePointerEvents",e.usePointerEvents,t,!1),...M("hoverClass",e.hoverClass,t,"ds-hover"),...M("selectableClass",e.selectableClass,t,"ds-selectable"),...M("selectedClass",e.selectedClass,t,"ds-selected"),...M("selectorClass",e.selectorClass,t,"ds-selector"),...M("selectorAreaClass",e.selectorAreaClass,t,"ds-selector-area"),...M("droppedTargetClass",e.droppedTargetClass,t,"ds-dropped-target"),...M("droppedInsideClass",e.droppedInsideClass,t,"ds-dropped-inside"),...M("droppableClass",e.droppableClass,t,"ds-droppable"),...M("dropZoneClass",e.dropZoneClass,t,"ds-dropzone"),...M("dropZoneReadyClass",e.dropZoneReadyClass,t,"ds-dropzone-ready"),...M("dropZoneTargetClass",e.dropZoneTargetClass,t,"ds-dropzone-target"),...M("dropZoneInsideClass",e.dropZoneInsideClass,t,"ds-dropzone-inside"),...M("useLayers",e.useLayers,t,!0)}))(e,t);for(const[i,r]of Object.entries(s))((s,i)=>{s in this._settings||Object.defineProperty(this.s,s,{get:()=>this._settings[s],set:e=>this.update({settings:{[s]:e}})}),this._settings[`${s}:pre`]=this._settings[s],this._settings[s]=i;const r={settings:this._settings,"settings:init":t,"settings:new":e};this.PS.publish("Settings:updated",r),this.PS.publish(`Settings:updated:${s}`,r)})(i,r)}}const K={elementselect:"DS:select",elementunselect:"DS:unselect",autoscroll:"DS:scroll",dragstart:"DS:start",dragmove:"DS:update",callback:"DS:end",preelementselect:"DS:select:pre",preelementunselect:"DS:unselect:pre",preautoscroll:"DS:scroll:pre",predragstart:"DS:start:pre",predragmove:"DS:update:pre",precallback:"DS:end:pre"},H=(e,t)=>{const s=t.DropZones.getTarget(e);return{...e,...s?{dropTarget:s.toObject()}:{}}},R=({sub_name:e,DS:t,PS:s,sub_pubs:i})=>{s.subscribe(e,(e=>i.forEach((s=>k({sub_pub:s,data:e,DS:t})))))},k=({sub_pub:e,data:t,DS:s})=>{const i=e.condition?e.condition(t,s):t;if(i){const r=e.extraData&&e.extraData(t,s)||{};s.publish(e.name,{items:s.SelectedSet.elements,isDragging:s.Interaction.isDragging,...i,...r})}};class ${continue=!1;PubSub;stores;Area;Selector;SelectorArea;SelectableSet;SelectedSet;Selection;Drag;DropZones;Interaction;stopped;constructor(e){this.stopped=!1,this.PubSub=new v({DS:this}),this.stores={},this.stores.SettingsStore=new V({settings:e,PS:this.PubSub}),this.stores.PointerStore=new _({DS:this,PS:this.PubSub}),this.stores.ScrollStore=new L({DS:this,PS:this.PubSub}),this.stores.KeyStore=new D({DS:this,PS:this.PubSub}),this.Area=new n({DS:this,PS:this.PubSub}),this.Selector=new x({DS:this,PS:this.PubSub}),this.SelectorArea=new w({DS:this,PS:this.PubSub}),this.SelectableSet=new T({DS:this,PS:this.PubSub}),this.SelectedSet=new E({DS:this,PS:this.PubSub}),this.Selection=new A({DS:this,PS:this.PubSub}),this.Drag=new u({DS:this,PS:this.PubSub}),this.DropZones=new b({DS:this,PS:this.PubSub}),this.Interaction=new y({DS:this,PS:this.PubSub}),(({PS:e,DS:t})=>{const s={"Selected:added":[{name:"preelementselect"},{name:"elementselect"},{name:"DS:select:pre"},{name:"DS:select"}],"Selected:removed":[{name:"preelementunselect"},{name:"elementunselect"},{name:"DS:unselect:pre"},{name:"DS:unselect"}],"Selectable:added":[{name:"DS:added:pre"},{name:"DS:added"}],"Selectable:removed":[{name:"DS:removed:pre"},{name:"DS:removed"}],"Area:scroll":[{name:"preautoscroll"},{name:"autoscroll"},{name:"DS:scroll:pre"},{name:"DS:scroll"}],"Interaction:start":[{name:"predragstart"},{name:"dragstart"},{name:"DS:start:pre"},{name:"DS:start"}],"Interaction:update":[{name:"predragmove",condition:e=>e.event?e:null},{name:"dragmove",condition:e=>e.event?e:null},{name:"DS:update:pre",condition:e=>e.event?e:null},{name:"DS:update",condition:e=>e.event?e:null}],"Interaction:end":[{name:"precallback",extraData:(e,t)=>H(e,t)},{name:"callback",extraData:(e,t)=>H(e,t)},{name:"DS:end:pre",extraData:(e,t)=>H(e,t)},{name:"DS:end",extraData:(e,t)=>H(e,t)}]};for(const[i,r]of Object.entries(s))R({sub_name:i,sub_pubs:r,DS:t,PS:e})})({DS:this,PS:this.PubSub}),this.PubSub.subscribe("Interaction:end",(()=>this.continue=!1)),this.PubSub.subscribe("DS:end",(({items:e})=>this.continue=!1)),this.start()}static isCollision;subscribe=(e,t)=>(K[e]&&console.warn(`[DragSelect]: The event name "${e}" is deprecated and was/will be removed in a future version. Please use the new event name "${K[e]}" instead.`),this.PubSub.subscribe(e,t));unsubscribe=(e,t,s)=>this.PubSub.unsubscribe(e,t,s);publish=(e,t)=>this.PubSub.publish(e,t);start=()=>{this.stopped=!1,this.Interaction.init()};stop(e=!0,t=!0,s=!1){s&&this.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),this.Interaction.stop(),this.Area.stop(),this.Drag.stop(),this.Selector.stop(),this.SelectorArea.stop(e),this.stores.KeyStore.stop(),this.stores.PointerStore.stop(),this.stores.ScrollStore.stop(),e&&this.SelectableSet.clear(),t&&this.SelectedSet.clear(),this.stopped=!0}break=()=>this.continue=!0;setSettings=e=>this.stores.SettingsStore.update({settings:e});getSelection=()=>this.SelectedSet.elements;addSelection(e,t=!1,s=!1){const i=g(e);return this.SelectedSet.addAll(i),s||this.addSelectables(e,!1,!1),t&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),this.getSelection()}removeSelection(e,t=!1,s=!1){const i=g(e);return this.SelectedSet.deleteAll(i),s&&this.removeSelectables(e,!1,!1),t&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),this.getSelection()}toggleSelection(e,t=!1,s=!1){return g(e).forEach((i=>this.SelectedSet.has(i)?this.removeSelection(e,t,s):this.addSelection(e,t,s))),t&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),this.getSelection()}setSelection(e,t=!1,s=!1){return this.clearSelection(),this.addSelection(e,t,s),this.getSelection()}clearSelection(e=!1){return this.SelectedSet.clear(),e&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),this.getSelection()}addSelectables(e,t,s){const i=g(e);return this.SelectableSet.addAll(i),t&&this.SelectedSet.addAll(i),s&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),i}getSelectables=()=>this.SelectableSet.elements;removeSelectables(e,t,s){const i=g(e);return this.SelectableSet.deleteAll(i),t&&this.removeSelection(e),s&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),i}getInitialCursorPosition=()=>this.stores.PointerStore.initialVal;getCurrentCursorPosition=()=>this.stores.PointerStore.currentVal;getPreviousCursorPosition=()=>this.stores.PointerStore.lastVal;getInitialCursorPositionArea=()=>this.stores.PointerStore.initialValArea;getCurrentCursorPositionArea=()=>this.stores.PointerStore.currentValArea;getPreviousCursorPositionArea=()=>this.stores.PointerStore.lastValArea;isMultiSelect=e=>this.stores.KeyStore.isMultiSelectKeyPressed(e);isDragging=()=>this.Interaction.isDragging;getZoneByCoordinates=e=>this.DropZones.getTarget({coordinates:e})?.toObject();getItemsDroppedByZoneId=e=>this.DropZones.getItemsDroppedById(e);getItemsInsideByZoneId=(e,t)=>this.DropZones.getItemsInsideById(e,t)}return $.isCollision=p,$}));
1
+ !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).DragSelect=e()}(this,(function(){"use strict";const t=(t,e)=>{const s=e;window.addEventListener("resize",s),window.addEventListener("scroll",s);const i=new MutationObserver(s),r=new ResizeObserver(s);t.forEach(((t,e)=>{i.observe(t,{childList:0!==e,attributes:!0}),t instanceof Element&&r.observe(t)}));return{observer:i,resizeObserver:r,callback:s,cleanup:()=>{window.removeEventListener("resize",s),window.removeEventListener("scroll",s),i.disconnect(),r.disconnect()}}},e=(t,e)=>{let s;return(...i)=>{clearTimeout(s),s=setTimeout((()=>{s=void 0,t(...i)}),e)}},s=t=>{const e=(t,s=0)=>{const i=t[s]?.parentNode;return i?(t.push(i),s++,e(t,s)):t};return e([t])},i=({computedStyle:t,node:e})=>{const{position:s}=t;e instanceof Document||("absolute"===s||"relative"===s||"fixed"===s)||(e.style.position="relative")},r=t=>{const{scrollTop:e,scrollLeft:s}=t;if(e||s)return!0;const i=()=>t.scrollTop!==e||t.scrollLeft!==s;t.scrollTo({top:e+1,left:s+1,behavior:"instant"}),i()||t.scrollTo({top:e-1,left:s-1,behavior:"instant"});const r=i();return t.scrollTo({top:e,left:s,behavior:"instant"}),r},n=(t,e,s=1)=>{if(!e?.length||!t)return;const i=t instanceof Document?((t=document)=>{const e=t.scrollingElement||t.documentElement,{body:s}=t;return s&&s!==e&&!r(e)&&r(s)?s:e})(t):t;e.includes("top")&&(i.scrollTop-=s),e.includes("bottom")&&(i.scrollTop+=s),e.includes("left")&&(i.scrollLeft-=s),e.includes("right")&&(i.scrollLeft+=s)};class o{DS;PS;Settings;_observers;_node;_parentNodes;_computedStyle;_computedBorder;_rect;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this._node=this.Settings.area,this.setArea(this.Settings.area),this.PS.subscribe("Settings:updated:area",(({settings:{area:t}})=>this.setArea(t))),this.PS.subscribe("Interaction:init",this.init),this.PS.subscribe("Interaction:end",this.reset)}setArea=t=>{this.reset(),this._node=t,i({computedStyle:this.computedStyle,node:this._node}),setTimeout((()=>{this.PS.publish("Area:modified:pre",{item:this.HTMLNode}),this.reset(),this.PS.publish("Area:modified",{item:this.HTMLNode})}))};init=()=>{this._observers=t(this.parentNodes,e((t=>{this.hasRelevantBeenModified()&&(this.PS.publish("Area:modified:pre",{event:t,item:this.HTMLNode}),this.reset(),this.PS.publish("Area:modified",{event:t,item:this.HTMLNode}))}),60))};hasRelevantBeenModified=()=>{const t=this.computedStyle,e=this.rect,s=this.computedBorder,i=this.parentNodes;return this.reset(),JSON.stringify(t)!==JSON.stringify(this.computedStyle)||(JSON.stringify(e)!==JSON.stringify(this.rect)||(JSON.stringify(s)!==JSON.stringify(this.computedBorder)||!(i.length===this.parentNodes.length||!i.some((t=>!this.parentNodes.includes(t))))))};reset=()=>{this._computedStyle=void 0,this._rect=void 0,this._computedBorder=void 0,this._parentNodes=void 0};stop=()=>{this._observers?.cleanup(),this.reset()};scroll=(t,e)=>{const s={scroll_directions:t,scroll_multiplier:e};this.PS.publish("Area:scroll:pre",s),n(this._node,t,e),this.PS.publish("Area:scroll",s)};get HTMLNode(){return this._node}get computedBorder(){return this._computedBorder?this._computedBorder:{top:parseInt(this.computedStyle.borderTopWidth),bottom:parseInt(this.computedStyle.borderBottomWidth),left:parseInt(this.computedStyle.borderLeftWidth),right:parseInt(this.computedStyle.borderRightWidth)}}get computedStyle(){if(this._computedStyle)return this._computedStyle;let t;return t=this.HTMLNode instanceof Document?window.getComputedStyle(this.HTMLNode.body||this.HTMLNode.documentElement):window.getComputedStyle(this.HTMLNode),this._computedStyle={borderTopWidth:t.borderTopWidth,borderBottomWidth:t.borderBottomWidth,borderLeftWidth:t.borderLeftWidth,borderRightWidth:t.borderRightWidth,position:t.position}}get rect(){return this._rect?this._rect:this._rect=((t,e)=>{if(t instanceof Document)return{top:0,left:0,bottom:0,right:0,width:window.innerWidth,height:window.innerHeight};const s=t.getBoundingClientRect();return{top:s.top,left:s.left,bottom:s.bottom,right:s.right,width:(t.clientWidth||s.width)*e,height:(t.clientHeight||s.height)*e}})(this.HTMLNode,this.DS.stores.SettingsStore.s.zoom)}get parentNodes(){return this._parentNodes?this._parentNodes:this._parentNodes=s(this.HTMLNode)}}const a=({x:t,y:e},s,{x:i,y:r})=>({"+":{x:t+i,y:e+r},"-":{x:t-i,y:e-r},"*":{x:t*i,y:e*r},"/":{x:t/i,y:e/r}}[s]),l=t=>({x:t.left,y:t.top}),h=(t,e=0)=>({left:t.x,top:t.y,right:t.x,bottom:t.y,width:e,height:e}),c=t=>({x:t,y:t}),d=t=>{const e={x:0,y:0},s=window.getComputedStyle(t);if(!s.transform||"none"===s.transform)return e;if(s.transform.indexOf("3d")>=0){const t=s.transform.trim().match(/matrix3d\((.*?)\)/);if(t&&t.length){const s=t[1]?.split(",");e.x=parseInt(s[12])||0,e.y=parseInt(s[13])||0}return e}const i=s.transform.trim().match(/matrix\((.*?)\)/);if(i&&i.length){const t=i[1]?.split(",");e.x=parseInt(t[4])||0,e.y=parseInt(t[5])||0}return e},S=(t,e)=>e?(t=>{const{transform:e}=t.style;if(!e||e.indexOf("translate")<0)return d(t);const s={x:0,y:0},i=e.trim().match(/translate[3dD]*?\(.*?\)/);if(i){const t=i[0]?.split("(");if(t){const e=t[1]?.split(",");s.x=parseInt(e[0])||0,s.y=parseInt(e[1])||0}}return s.x||s.x?s:d(t)})(t):(t=>{const{style:e}=t,s={x:parseInt(e.left)||0,y:parseInt(e.top)||0};if(!s.x&&!s.x){const e=window.getComputedStyle(t);return{x:parseInt(e.left)||0,y:parseInt(e.top)||0}}return s})(t),u=({containerRect:t,selectionRect:e,direction:s,scrollAmount:i})=>{const r={top:t.top-e.top+i.y,left:t.left-e.left+i.x,bottom:t.bottom-e.bottom+i.y,right:t.right-e.right+i.x};return 0===s.x&&0===s.y||(s.y<0&&(s.y=Math.max(s.y,r.top)),s.x<0&&(s.x=Math.max(s.x,r.left)),s.y>0&&(s.y=Math.min(s.y,r.bottom)),s.x>0&&(s.x=Math.min(s.x,r.right)),e.top+=s.y,e.bottom+=s.y,e.left+=s.x,e.right+=s.x),s};class p{_prevCursorPos;_prevScrollPos;_elements=[];_dragKeys;_dragKeysFlat=[];_selectionRect=h(c(0));DS;PS;Settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Settings:updated:dragKeys",this.assignDragKeys),this.assignDragKeys(),this.PS.subscribe("Interaction:start",this.start),this.PS.subscribe("Interaction:end",this.stop),this.PS.subscribe("Interaction:update",this.update),this.PS.subscribe("KeyStore:down",this.keyboardDrag),this.PS.subscribe("KeyStore:up",this.keyboardEnd)}assignDragKeys=()=>{this._dragKeys={up:this.Settings.dragKeys.up.map((t=>t.toLowerCase())),down:this.Settings.dragKeys.down.map((t=>t.toLowerCase())),left:this.Settings.dragKeys.left.map((t=>t.toLowerCase())),right:this.Settings.dragKeys.right.map((t=>t.toLowerCase()))},this._dragKeysFlat=[...this._dragKeys.up,...this._dragKeys.down,...this._dragKeys.left,...this._dragKeys.right]};keyboardDrag=({event:t,key:e})=>{const s=e.toLowerCase();if(!this.Settings.keyboardDrag||!this._dragKeysFlat.includes(s)||!this.DS.SelectedSet.size||!this.Settings.draggability||this.DS.continue)return;const i={event:t,isDragging:!0,isDraggingKeyboard:!0,key:e};this.PS.publish(["Interaction:start:pre","Interaction:start"],i),this._elements=this.DS.getSelection(),this._selectionRect=this.DS.Selection.boundingRect,this.handleZIndex(!0);let r=(({shiftKey:t,keyboardDragSpeed:e,zoom:s,key:i,dragKeys:r,scrollDiff:n})=>{const o={x:0,y:0},a=t?4*e*s:e*s;return r?.left.includes(i)&&(o.x=n.x||-a),r?.right.includes(i)&&(o.x=n.x||a),r?.up.includes(i)&&(o.y=n.y||-a),r?.down.includes(i)&&(o.y=n.y||a),o})({shiftKey:this.DS.stores.KeyStore.currentValues.includes("shift"),keyboardDragSpeed:this.Settings.keyboardDragSpeed,zoom:this.Settings.zoom,key:s,scrollDiff:this._scrollDiff,dragKeys:this._dragKeys});r=u({direction:r,containerRect:this.DS.SelectorArea.rect,scrollAmount:this.DS.stores.ScrollStore.scrollAmount,selectionRect:this._selectionRect}),this.moveElements(r),this.PS.publish(["Interaction:update:pre","Interaction:update"],i)};keyboardEnd=({event:t,key:e})=>{const s=e.toLowerCase();if(!(this.Settings.keyboardDrag&&this._dragKeysFlat.includes(s)&&this.DS.SelectedSet.size&&this.Settings.draggability))return;const i={event:t,isDragging:this.Settings.draggability,isDraggingKeyboard:!0,key:e};this.PS.publish(["Interaction:end:pre","Interaction:end"],i)};start=({isDragging:t,isDraggingKeyboard:e})=>{t&&!e&&(this._prevCursorPos=void 0,this._prevScrollPos=void 0,this._elements=this.DS.getSelection(),this._selectionRect=this.DS.Selection.boundingRect,this.handleZIndex(!0))};stop=()=>{this._prevCursorPos=void 0,this._prevScrollPos=void 0,this.handleZIndex(!1),this._elements=[]};update=({isDragging:t,isDraggingKeyboard:e})=>{if(!t||!this._elements.length||e||this.DS.continue)return;let s=a(this._cursorDiff,"+",this._scrollDiff);s=u({direction:s,containerRect:this.DS.SelectorArea.rect,scrollAmount:this.DS.stores.ScrollStore.scrollAmount,selectionRect:this._selectionRect}),this.moveElements(s)};handleZIndex=t=>{this.Settings.useLayers&&this._elements.forEach((e=>e.style.zIndex=`${(parseInt(e.style.zIndex)||0)+(t?9999:-9998)}`))};moveElements=t=>{const{elements:e,direction:s}=this.filterDragElements({elements:this._elements,direction:t});e.forEach((t=>{(({element:t,posDirection:e,useTransform:s})=>{const i=S(t,s);((t,e,s)=>{if(s){const s=t.style.transform;t.style.transform=`translate3d(${e.x}px,${e.y}px,1px) ${s.replace(/translate.*?\)/g,"")}`}else t.style.left=`${e.x}px`,t.style.top=`${e.y}px`})(t,a(i,"+",e),s)})({element:t,posDirection:s,containerRect:this.DS.SelectorArea.rect,useTransform:this.Settings.useTransform})}))};get _cursorDiff(){const t=this.DS.stores.PointerStore.currentVal,e=this._prevCursorPos?a(t,"-",this._prevCursorPos):{x:0,y:0};return this._prevCursorPos=t,e}get _scrollDiff(){const t=this.DS.stores.ScrollStore.currentVal,e=this._prevScrollPos?a(t,"-",this._prevScrollPos):{x:0,y:0};return this._prevScrollPos=t,e}filterDragElements=({elements:t,direction:e})=>({elements:t,direction:e})}const g=(t,e,s=0)=>{if(!t||!e)return!1;let i=t;if(s>0){const e=(t.right-t.left)*s,r=(t.bottom-t.top)*s;i={left:t.left+e,right:t.right-e,top:t.top+r,bottom:t.bottom-r}}return i.left<e.right&&i.right>e.left&&i.top<e.bottom&&i.bottom>e.top},m=t=>t?Array.isArray(t)||"function"==typeof t[Symbol.iterator]?[...new Set([...t])]:[t]:[];class b{id;element;_droppables;_rect;_observers;_timeout;_itemsDropped=[];_itemsInside;DS;PS;Settings;isDestroyed=!1;_parentNodes;constructor({DS:s,PS:i,id:r,element:n,droppables:o}){this.DS=s,this.PS=i,this.Settings=this.DS.stores.SettingsStore.s,this.id=r,this.element=n,o&&(this.droppables=m(o)),this.element.classList.add(`${this.Settings.dropZoneClass}`),this.PS.subscribe("Settings:updated:dropZoneClass",(({settings:t})=>{this.element&&(this.element.classList.remove(t["dropZoneClass:pre"]),this.element.classList.add(t.dropZoneClass))})),this._observers=t(this.parentNodes,e((()=>this._rect=void 0),this.Settings.refreshMemoryRate)),this.PS.subscribe("Interaction:start",this.start),this.PS.subscribe("Interaction:end",this.stop)}setReadyClasses=t=>{if(this.isDestroyed)return;const e=this.droppables.filter((t=>this.DS.SelectedSet.has(t)));e.length&&(e.forEach((e=>{e.classList[t](`${this.Settings.droppableClass}`),e.classList[t](`${this.Settings.droppableClass}-${this.id}`)})),this.element.classList[t](`${this.Settings.dropZoneReadyClass}`))};handleNoDrop=()=>{this.isDestroyed||(this.DS.SelectedSet.forEach((t=>{t.classList.remove(this.Settings.droppedTargetClass),t.classList.remove(`${this.Settings.droppedTargetClass}-${this.id}`)})),this._itemsDropped=this._itemsDropped.filter((t=>!this.DS.SelectedSet.has(t))),this._itemsDropped?.length||this.element.classList.remove(`${this.Settings.dropZoneTargetClass}`))};handleDrop=()=>{this.isDestroyed||(this._itemsDropped=[...new Set([...this._itemsDropped,...this.droppables?.filter((t=>this.DS.SelectedSet.has(t)))])],this._itemsDropped?.forEach((t=>{t.classList.add(`${this.Settings.droppedTargetClass}`),t.classList.add(`${this.Settings.droppedTargetClass}-${this.id}`)})),this._itemsDropped?.length&&this.element.classList.add(`${this.Settings.dropZoneTargetClass}`))};handleItemsInsideClasses=()=>{let t=!1;this.droppables.forEach((e=>{this.itemsInside?.includes(e)?(e.classList.add(`${this.Settings.droppedInsideClass}`),e.classList.add(`${this.Settings.droppedInsideClass}-${this.id}`),t=!0):(e.classList.remove(`${this.Settings.droppedInsideClass}-${this.id}`),e.className.includes(`${this.Settings.droppedInsideClass}-`)||e.classList.remove(`${this.Settings.droppedInsideClass}`))})),t?this.element.classList.add(`${this.Settings.dropZoneInsideClass}`):this.element.classList.remove(`${this.Settings.dropZoneInsideClass}`)};start=({isDragging:t})=>{t&&!this.isDestroyed&&this.setReadyClasses("add")};stop=({isDragging:t})=>{t&&!this.isDestroyed&&(this.setReadyClasses("remove"),this.handleItemsInsideClasses())};destroy(){this._observers?.cleanup(),this.element.classList.remove(`${this.Settings.dropZoneClass}`),this.element.classList.remove(`${this.Settings.dropZoneTargetClass}`),this.element.classList.remove(`${this.Settings.dropZoneReadyClass}`),this.droppables.forEach((t=>{t.classList.remove(`${this.Settings.droppedTargetClass}`),t.classList.remove(`${this.Settings.droppedTargetClass}-${this.id}`),t.classList.remove(`${this.Settings.droppableClass}`),t.classList.remove(`${this.Settings.droppableClass}-${this.id}`)})),this.PS.unsubscribe("Interaction:start",this.start),this.PS.unsubscribe("Interaction:end",this.stop),this.isDestroyed=!0}toObject=()=>({id:this.id,element:this.element,droppables:this.droppables,itemsDropped:this.itemsDropped,itemsInside:this.itemsInside});get rect(){if(!this.isDestroyed)return this._rect?this._rect:this._rect=this.element.getBoundingClientRect()}get itemsDropped(){if(!this.isDestroyed)return this._itemsDropped}get itemsInside(){if(!this.isDestroyed)return this._itemsInside||(this._itemsInside=this.droppables.flatMap((t=>{const e=this.DS.SelectableSet.rects.get(t);return this.rect&&g(e,this.rect,this.Settings.dropInsideThreshold)?[t]:[]})),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout((()=>this._itemsInside=void 0),this.Settings.refreshMemoryRate)),this._itemsInside}get parentNodes(){return this._parentNodes?this._parentNodes:this._parentNodes=s(this.element)}get droppables(){return this._droppables?this._droppables:this.DS.SelectableSet.elements}set droppables(t){this._droppables=t}}class y{_zoneByElement=new Map;_zoneById=new Map;_zonesByDroppable=new Map;_zones;DS;PS;Settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Settings:updated:dropZones",(({settings:t})=>this.setDropZones(t))),this.setDropZones({dropZones:this.Settings.dropZones}),this.PS.subscribe("Interaction:end",this.stop)}setDropZones=({dropZones:t})=>{t&&(this._zones&&this._zones.forEach((t=>t.destroy())),this._zones=t.map((t=>new b({DS:this.DS,PS:this.PS,...t}))),this._zones.forEach((t=>{this._zoneByElement.set(t.element,t),this._zoneById.set(t.id,t),t.droppables.forEach((e=>{const s=this._zonesByDroppable.get(e);if(!s?.length)return this._zonesByDroppable.set(e,[t]);this._zonesByDroppable.set(e,[...new Set([...s,t])])}))})))};_handleDrops=t=>{this._zones?.forEach((e=>{e!==t&&e.handleNoDrop()})),t&&t.handleDrop()};_getZoneByElementsFromPoint=(t,{x:e,y:s})=>{for(let i=0,r=t.length;i<r;i++){const r=this._zoneByElement.get(t[i]);if(g(r?.rect,{left:e,right:e,top:s,bottom:s},Math.min(this.Settings.dropTargetThreshold,.5)))return r}};stop=({isDragging:t,isDraggingKeyboard:e,event:s})=>{if(!t)return;const i=this.getTarget({isDraggingKeyboard:e,event:s});this._handleDrops(i)};getItemsDroppedById=t=>{const e=this._zoneById.get(t);return e?e.itemsDropped:console.warn(`[DragSelect] No zone found (id: ${t})`)};getItemsInsideById=(t,e)=>{const s=this._zoneById.get(t);return s?(e&&s.handleItemsInsideClasses(),s.itemsInside):console.warn(`[DragSelect] No zone found (id: ${t})`)};getKeyboardItemCenter=(t,e)=>{if(!t||!e)return;const s=e.target?.getBoundingClientRect();return{x:s.left+s.width/2,y:s.top+s.height/2}};getTarget=({coordinates:t,isDraggingKeyboard:e,event:s})=>{if(!this._zones?.length)return;let i;!t&&e&&s&&(i=this.getKeyboardItemCenter(e,s));const r=t?.x||i?.x||this.DS.stores.PointerStore.currentVal.x,n=t?.y||i?.y||this.DS.stores.PointerStore.currentVal.y,o=document.elementsFromPoint(r,n);return this._getZoneByElementsFromPoint(o,{x:r,y:n})}}class D{isInteracting;isDragging=!1;DS;PS;Settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Settings:updated:area",(({settings:t})=>{this.removeAreaEventListeners(t["area:pre"]),this.setAreaEventListeners(t.area)})),this.PS.subscribe("PointerStore:updated",(({event:t})=>this.update({event:t}))),this.PS.subscribe("Selectable:click",this.onClick),this.PS.subscribe("Selectable:pointer",(({event:t})=>this.start(t))),this.PS.subscribe("Interaction:start:pre",(({event:t})=>this._start(t))),this.PS.subscribe("Interaction:init:pre",this._init),this.PS.subscribe("Interaction:end:pre",(({event:t})=>this._reset(t))),this.PS.subscribe("Area:scroll",this.update)}init=()=>this.PS.publish("Interaction:init:pre",{init:!0});_init=()=>{this.stop(),this.setAreaEventListeners(),this.PS.publish("Interaction:init",{init:!0})};_canInteract(t){const e="clientX"in t&&0===t.clientX&&0===t.clientY&&0===t.detail&&t.target;return!("button"in t&&2===t.button||this.isInteracting||t.target&&!this.DS.SelectorArea.isInside(t.target)||!e&&!this.DS.SelectorArea.isClicked(t))}start=t=>this.PS.publish("Interaction:start:pre",{event:t,isDragging:this.isDragging});_start=t=>{"touchstart"===t.type&&t.preventDefault(),this._canInteract(t)&&(this.isInteracting=!0,this.isDragging=this.isDragEvent(t),this.PS.publish("Interaction:start",{event:t,isDragging:this.isDragging}),this.setDocEventListeners())};isDragEvent=t=>{let e=null;return t.target&&"closest"in t.target&&(e=t.target.closest(`.${this.Settings.selectableClass}`)),!(!this.Settings.draggability||this.DS.stores.KeyStore.isMultiSelectKeyPressed(t)||!e)&&(this.Settings.immediateDrag&&(this.DS.SelectedSet.size?this.DS.SelectedSet.has(e)||(this.DS.SelectedSet.clear(),this.DS.SelectedSet.add(e)):this.DS.SelectedSet.add(e)),!!this.DS.SelectedSet.has(e))};onClick=({event:t})=>{if(!this._canInteract(t))return;if(t.detail>0)return;const{stores:{PointerStore:e,KeyStore:s},SelectableSet:i,SelectedSet:r}=this.DS;e.start(t);const n=t.target;n&&!i.has(n)||(s.isMultiSelectKeyPressed(t)||r.clear(),n&&r.toggle(n),this.reset(t))};stop=(t=this.DS.Area.HTMLNode)=>{this.removeAreaEventListeners(t),this.removeDocEventListeners()};update=({event:t,scroll_directions:e,scroll_multiplier:s})=>{this.isInteracting&&this.PS.publish(["Interaction:update:pre","Interaction:update"],{event:t,scroll_directions:e,scroll_multiplier:s,isDragging:this.isDragging})};reset=t=>this.PS.publish("Interaction:end:pre",{event:t,isDragging:this.isDragging});_reset=t=>{const{isDragging:e}=this;this.isInteracting=!1,this.isDragging=!1,this.removeDocEventListeners(),this.PS.publish("Interaction:end",{event:t,isDragging:e})};setAreaEventListeners=(t=this.DS.Area.HTMLNode)=>{this.Settings.usePointerEvents?t.addEventListener("pointerdown",this.start,{passive:!1}):t.addEventListener("mousedown",this.start),t.addEventListener("touchstart",this.start,{passive:!1})};removeAreaEventListeners=(t=this.DS.Area.HTMLNode)=>{this.Settings.usePointerEvents?t.removeEventListener("pointerdown",this.start,{passive:!1}):t.removeEventListener("mousedown",this.start),t.removeEventListener("touchstart",this.start,{passive:!1})};setDocEventListeners=()=>{this.Settings.usePointerEvents?(document.addEventListener("pointerup",this.reset),document.addEventListener("pointercancel",this.reset)):document.addEventListener("mouseup",this.reset),document.addEventListener("touchend",this.reset)};removeDocEventListeners=()=>{this.Settings.usePointerEvents?(document.removeEventListener("pointerup",this.reset),document.removeEventListener("pointercancel",this.reset)):document.removeEventListener("mouseup",this.reset),document.removeEventListener("touchend",this.reset)}}class _{_currentValues=new Set;_keyMapping={control:"ctrlKey",shift:"shiftKey",meta:"metaKey"};DS;PS;settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Interaction:init",this.init)}init=()=>{document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup),window.addEventListener("blur",this.reset)};keydown=t=>{if(!t.key?.toLocaleLowerCase)return;const e=t.key.toLowerCase();this.PS.publish("KeyStore:down:pre",{event:t,key:e}),this._currentValues.add(e),this.PS.publish("KeyStore:down",{event:t,key:e})};keyup=t=>{if(!t.key?.toLocaleLowerCase)return;const e=t.key.toLowerCase();this.PS.publish("KeyStore:up:pre",{event:t,key:e}),this._currentValues.delete(e),this.PS.publish("KeyStore:up",{event:t,key:e})};stop=()=>{document.removeEventListener("keydown",this.keydown),document.removeEventListener("keyup",this.reset),window.removeEventListener("blur",this.reset),this.reset()};reset=()=>this._currentValues.clear();isMultiSelectKeyPressed(t){if(this.settings.multiSelectMode)return!0;const e=this.settings.multiSelectKeys?.map((t=>t.toLocaleLowerCase()))??[];return!!this.currentValues.some((t=>e.includes(t)))||!(!t||!e.some((e=>t[this._keyMapping[e]])))}get currentValues(){return Array.from(this._currentValues.values())}}class v{_isMouseInteraction=!1;_initialValArea={x:0,y:0};_currentValArea={x:0,y:0};_lastValArea={x:0,y:0};_initialVal={x:0,y:0};_currentVal={x:0,y:0};_lastVal={x:0,y:0};_lastTouch;DS;PS;settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Interaction:init",this.init),this.PS.subscribe("Interaction:start",(({event:t})=>this.start(t))),this.PS.subscribe("Interaction:end",(({event:t})=>this.reset(t)))}init=()=>{this.settings.usePointerEvents?document.addEventListener("pointermove",this.update,{passive:!1}):document.addEventListener("mousemove",this.update),document.addEventListener("touchmove",this.update,{passive:!1})};start(t){t&&(this._isMouseInteraction=!0,this.currentVal=this.initialVal=this.getPointerPosition(t))}getPointerPosition=t=>(({event:t})=>({x:t.clientX,y:t.clientY}))({event:this._normalizedEvent(t)});update=t=>{t&&(this.PS.publish("PointerStore:updated:pre",{event:t}),this.currentVal=this.getPointerPosition(t),this._isMouseInteraction&&this.PS.publish("PointerStore:updated",{event:t}))};stop=()=>{this.settings.usePointerEvents?document.removeEventListener("pointermove",this.update,{passive:!1}):document.removeEventListener("mousemove",this.update),document.removeEventListener("touchmove",this.update,{passive:!1}),this.reset()};reset=t=>{this.currentVal=this.lastVal=this.getPointerPosition(t),setTimeout((()=>this._isMouseInteraction=!1),100)};_normalizedEvent(t){return!t||t instanceof KeyboardEvent?{clientX:0,clientY:0}:"touches"in t?("touchend"!==t.type&&(this._lastTouch=t),this._lastTouch?.touches[0]||t.touches[0]):t}get initialValArea(){return this._initialValArea?this._initialValArea:{x:0,y:0}}get currentValArea(){return this._currentValArea?this._currentValArea:{x:0,y:0}}get lastValArea(){return this._lastValArea?this._lastValArea:{x:0,y:0}}get initialVal(){return this._initialVal?this._initialVal:{x:0,y:0}}get currentVal(){return this._currentVal?this._currentVal:{x:0,y:0}}get lastVal(){return this._lastVal?this._lastVal:{x:0,y:0}}set initialVal(t){this._initialVal=t,this._initialValArea=t&&a(t,"-",a(l(this.DS.Area.rect),"+",l(this.DS.Area.computedBorder)))}set currentVal(t){this._currentVal=t,this._currentValArea=t&&a(t,"-",a(l(this.DS.Area.rect),"+",l(this.DS.Area.computedBorder)))}set lastVal(t){this._lastVal=t,this._lastValArea=t&&a(t,"-",a(l(this.DS.Area.rect),"+",l(this.DS.Area.computedBorder)))}}class P{subscribers={};_ids={};_nextId=0;DS;constructor({DS:t}){this.DS=t}subscribe=(t,e)=>{this.subscribers[t]||(this.subscribers[t]=[]),this._ids[t]||(this._ids[t]=[]);const s=this.subscribers[t],i=this._ids[t],r=this._nextId++;return s.push(e),i.push(r),r};unsubscribe=(t,e,s)=>{const i=this.subscribers[t],r=this._ids[t];if(!i||!r)return;const n=null!=s?r.indexOf(s):e?i.indexOf(e):-1;-1!==n&&(i.splice(n,1),r.splice(n,1))};publish=(t,e)=>{Array.isArray(t)?t.forEach((t=>this._publish(t,e))):this._publish(t,e)};_publish=(t,e)=>{const s=[...this.subscribers[t]??[]];t.includes(":pre")?this._handlePrePublish(s,e):this._handlePublish(s,e)};_handlePublish=(t,e)=>{for(let s=0,i=t.length;s<i;s++){if(this.DS.stopped)return;t[s]?.(e)}};_handlePrePublish=(t,e)=>{let s=t.length;for(;s--;){if(this.DS.stopped)return;t[s]?.(e)}}}const f=()=>({y:document.body?.scrollTop||document.documentElement?.scrollTop||0,x:document.body?.scrollLeft||document.documentElement?.scrollLeft||0}),I=t=>!t||t instanceof Document?f():{x:t.scrollLeft>=0?t.scrollLeft:f().x,y:t.scrollTop>=0?t.scrollTop:f().y};class L{_initialVal={x:0,y:0};_currentVal={x:0,y:0};_canScroll;DS;PS;Settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Area:modified",(()=>{this.stop(),this.init()})),this.PS.subscribe("Interaction:init",this.init),this.PS.subscribe("Interaction:start",(()=>this.start())),this.PS.subscribe("Interaction:end",(()=>this.reset()))}init=()=>this.addListeners();addListeners=()=>this.DS.Area.HTMLNode.addEventListener("scroll",this.update);removeListeners=()=>this.DS.Area.HTMLNode.removeEventListener("scroll",this.update);start=()=>{this._currentVal=this._initialVal=I(this.DS.Area.HTMLNode)};update=()=>this._currentVal=I(this.DS.Area.HTMLNode);stop=()=>{this.reset(),this.removeListeners()};reset=()=>{this._initialVal={x:0,y:0},this._canScroll=void 0};get canScroll(){return"boolean"==typeof this._canScroll?this._canScroll:this._canScroll=(t=>{if(!(t instanceof Document))return r(t);const e=t.scrollingElement||t.documentElement;return r(e)||!!t.body&&r(t.body)})(this.DS.Area.HTMLNode)}get scrollAmount(){const t=a(this.currentVal,"-",this.initialVal),e=c(this.Settings.zoom),s=a(a(t,"*",e),"-",t);return{x:t.x+s.x,y:t.y+s.y}}get initialVal(){return this._initialVal?this._initialVal:{x:0,y:0}}get currentVal(){return this._currentVal||(this._currentVal=I(this.DS.Area.HTMLNode)),this._currentVal}}class T extends Set{_rects;_timeout;DS;PS;Settings;constructor({DS:t,PS:e}){super(),this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Interaction:init",this.init),this.PS.subscribe("Settings:updated:selectables",(()=>{this.clear(),this.init()})),this.PS.subscribe("Settings:updated:selectableClass",(({settings:t})=>{this.forEach((e=>{e.classList.remove(t["selectableClass:pre"]),e.classList.add(t.selectableClass)}))}))}init=()=>m(this.Settings.selectables).forEach((t=>this.add(t)));add(t){if(!t||super.has(t))return this;const e={items:this.elements,item:t};return this.PS.publish("Selectable:added:pre",e),t.classList.add(this.Settings.selectableClass),t.addEventListener("click",this._onClick),this.Settings.usePointerEvents?t.addEventListener("pointerdown",this._onPointer,{passive:!1}):t.addEventListener("mousedown",this._onPointer),t.addEventListener("touchstart",this._onPointer,{passive:!1}),this.Settings.draggability&&!this.Settings.useTransform&&i({computedStyle:window.getComputedStyle(t),node:t}),this.PS.publish("Selectable:added",e),super.add(t)}delete(t){if(!t||!super.has(t))return!0;const e={items:this.elements,item:t};return this.PS.publish("Selectable:removed:pre",e),t.classList.remove(this.Settings.selectableClass),t.classList.remove(this.Settings.hoverClass),t.removeEventListener("click",this._onClick),this.Settings.usePointerEvents?t.removeEventListener("pointerdown",this._onPointer,{passive:!1}):t.removeEventListener("mousedown",this._onPointer),t.removeEventListener("touchstart",this._onPointer,{passive:!1}),this.PS.publish("Selectable:removed",e),super.delete(t)}clear=()=>this.forEach((t=>this.delete(t)));_onClick=t=>this.PS.publish(["Selectable:click:pre","Selectable:click"],{event:t});_onPointer=t=>this.PS.publish(["Selectable:pointer:pre","Selectable:pointer"],{event:t});addAll=t=>t.forEach((t=>this.add(t)));deleteAll=t=>t.forEach((t=>this.delete(t)));getElementRect=t=>this._rects?this._rects.get(t):t.getBoundingClientRect();get elements(){return Array.from(this.values())}get rects(){return this._rects||(this._rects=new Map,this.forEach((t=>this._rects?.set(t,t.getBoundingClientRect()))),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout((()=>this._rects=void 0),this.Settings.refreshMemoryRate)),this._rects}}class C extends Set{_rects;_timeout;DS;PS;Settings;constructor({DS:t,PS:e}){super(),this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s}add(t){if(!t||super.has(t))return this;const e={items:this.elements,item:t};return this.PS.publish("Selected:added:pre",e),super.add(t),t.classList.add(this.Settings.selectedClass),this.Settings.useLayers&&(t.style.zIndex=`${(parseInt(t.style.zIndex)||0)+1}`),this.PS.publish("Selected:added",e),this}delete(t){if(!t||!super.has(t))return!0;const e={items:this.elements,item:t};this.PS.publish("Selected:removed:pre",e);const s=super.delete(t);return t.classList.remove(this.Settings.selectedClass),this.Settings.useLayers&&(t.style.zIndex=""+((parseInt(t.style.zIndex)||0)-1)),this.PS.publish("Selected:removed",e),s}clear=()=>this.forEach((t=>this.delete(t)));toggle(t){return this.has(t)?this.delete(t):this.add(t),t}addAll=t=>t.forEach((t=>this.add(t)));deleteAll=t=>t.forEach((t=>this.delete(t)));get elements(){return Array.from(this.values())}get rects(){return this._rects||(this._rects=new Map,this.forEach((t=>this._rects?.set(t,t.getBoundingClientRect()))),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout((()=>this._rects=void 0),this.Settings.refreshMemoryRate)),this._rects}}var E=(t,e)=>{e.left&&(t.style.left=`${e.left}px`),e.top&&(t.style.top=`${e.top}px`),e.width&&(t.style.width=`${e.width}px`),e.height&&(t.style.height=`${e.height}px`)};class x{_rect;DS;PS;Settings;HTMLNode;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.HTMLNode=this.Settings.selector,this.PS.subscribe("Settings:updated:selectorClass",(({settings:t})=>{this.HTMLNode.classList.remove(t["selectorClass:pre"]),this.HTMLNode.classList.add(t.selectorClass)})),this.PS.subscribe("Settings:updated:selector",this.attachSelector),this.PS.subscribe("Settings:updated:customStyles",this.attachSelector),this.attachSelector(),this.PS.subscribe("Interaction:start",this.start),this.PS.subscribe("Interaction:update",this.update),this.PS.subscribe("Interaction:end",this.stop)}attachSelector=()=>{this.HTMLNode&&this.DS.SelectorArea?.HTMLNode&&this.DS.SelectorArea.HTMLNode.removeChild(this.HTMLNode),this.HTMLNode=this.Settings.selector||(t=>{const e=document.createElement("div");return e.style.position="absolute",t||(e.style.background="rgba(0, 175, 255, 0.2)",e.style.border="1px solid rgba(0, 175, 255, 0.8)",e.style.display="none",e.style.pointerEvents="none"),e})(this.Settings.customStyles),this.HTMLNode.classList.add(this.Settings.selectorClass),this.HTMLNode&&this.DS.SelectorArea?.HTMLNode&&this.DS.SelectorArea.HTMLNode.appendChild(this.HTMLNode)};start=({isDragging:t})=>{if(t)return;const{stores:{PointerStore:e}}=this.DS,s=e.initialValArea;E(this.HTMLNode,h(s,1)),this.HTMLNode.style.display="block",this._rect=void 0};stop=()=>{this.HTMLNode.style.width="0",this.HTMLNode.style.height="0",this.HTMLNode.style.display="none"};update=({isDragging:t})=>{if(t||this.DS.continue)return;const{stores:{ScrollStore:e,PointerStore:s}}=this.DS,i=(({scrollAmount:t,initialPointerPos:e,pointerPos:s})=>{const i={};return s.x>e.x-t.x?(i.left=e.x-t.x,i.width=s.x-e.x+t.x):(i.left=s.x,i.width=e.x-s.x-t.x),s.y>e.y-t.y?(i.top=e.y-t.y,i.height=s.y-e.y+t.y):(i.top=s.y,i.height=e.y-s.y-t.y),i})({scrollAmount:e.scrollAmount,initialPointerPos:s.initialValArea,pointerPos:s.currentValArea});E(this.HTMLNode,i),this._rect=void 0};get rect(){return this._rect?this._rect:this._rect=this.HTMLNode.getBoundingClientRect()}}class A{_prevSelectedSet=new Set;_boundingRect;_timeout;DS;PS;Settings;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.PS.subscribe("Interaction:start",this.start),this.PS.subscribe("Interaction:update",this.update)}_storePrevious(t){const{stores:{KeyStore:e},SelectedSet:s}=this.DS;e.isMultiSelectKeyPressed(t)?this._prevSelectedSet=new Set(s):this._prevSelectedSet=new Set}start=({event:t,isDragging:e})=>{e||(this._storePrevious(t),this._handleInsideSelection(!0,t))};update=({isDragging:t})=>{t||this.DS.continue||this._handleInsideSelection()};_handleInsideSelection=(t,e)=>{const{SelectableSet:s,SelectorArea:i,Selector:r}=this.DS,n=this.DS.stores.KeyStore.isMultiSelectKeyPressed(e)&&this.Settings.multiSelectToggling,o=this.Settings.selectionThreshold,a=s.rects,l=r.rect,h=new Map,c=new Map;for(const[t,e]of a)i.isInside(t,e)&&(g(e,l,o)?h.set(t,e):c.set(t,e));if(this.DS.continue)return;const{select:d,unselect:S}=this.filterSelected({select:h,unselect:c,selectorRect:l});d.forEach(((e,s)=>(({element:t,force:e,multiSelectionToggle:s,SelectedSet:i,hoverClassName:r})=>{t.classList.contains(r)&&!e||(i.has(t)?s&&i.delete(t):i.add(t),t.classList.add(r))})({element:s,force:t,multiSelectionToggle:n,SelectedSet:this.DS.SelectedSet,hoverClassName:this.Settings.hoverClass}))),S.forEach(((e,s)=>(({element:t,force:e,SelectedSet:s,PrevSelectedSet:i,hoverClassName:r})=>{if(!t.classList.contains(r)&&!e)return;const n=s.has(t),o=i.has(t);n&&!o?s.delete(t):!n&&o&&s.add(t),t.classList.remove(r)})({element:s,force:t,SelectedSet:this.DS.SelectedSet,hoverClassName:this.Settings.hoverClass,PrevSelectedSet:this._prevSelectedSet})))};get boundingRect(){return this._boundingRect||(this._boundingRect=(t=>{const e={top:Number.POSITIVE_INFINITY,left:Number.POSITIVE_INFINITY,bottom:Number.NEGATIVE_INFINITY,right:Number.NEGATIVE_INFINITY,width:Number.NEGATIVE_INFINITY,height:Number.NEGATIVE_INFINITY};return t.rects.forEach((t=>{e.top=Math.min(e.top,t.top||e.top),e.left=Math.min(e.left,t.left||e.left),e.bottom=Math.max(e.bottom,t.bottom||e.bottom),e.right=Math.max(e.right,t.right||e.right)})),e.height=e.bottom-e.top,e.width=e.right-e.left,e})(this.DS.SelectedSet),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout((()=>this._boundingRect=void 0),this.Settings.refreshMemoryRate)),this._boundingRect}filterSelected=({select:t,unselect:e,selectorRect:s})=>({select:t,unselect:e})}class w{_scrollInterval;_rect;currentEdges=[];DS;PS;Settings;HTMLNode;constructor({DS:t,PS:e}){this.DS=t,this.PS=e,this.Settings=this.DS.stores.SettingsStore.s,this.HTMLNode=(()=>{const t=document.createElement("div");return t.style.position="fixed",t.style.overflow="hidden",t.style.pointerEvents="none",t.style.zIndex="999999999999999999",t})(),this.PS.subscribe("Settings:updated:selectorAreaClass",(({settings:t})=>{this.HTMLNode.classList.remove(t["selectorAreaClass:pre"]),this.HTMLNode.classList.add(t.selectorAreaClass)})),this.HTMLNode.classList.add(this.Settings.selectorAreaClass),this.PS.subscribe("Area:modified",this.updateParent),this.PS.subscribe("Area:modified",this.updatePos),this.PS.subscribe("Interaction:init",this.init),this.PS.subscribe("Interaction:start",(({isDraggingKeyboard:t})=>this.startAutoScroll({isDraggingKeyboard:t}))),this.PS.subscribe("Interaction:end",(()=>{this.updatePos(),this.stopAutoScroll()}))}init=()=>{this.applyElements("append"),this.updatePos()};get parentNode(){const t=this.DS.Area.HTMLNode;return(t instanceof Element?t.closest("dialog, [popover]"):null)||document.body||document.documentElement}applyElements=t=>{"append"===t?(this.HTMLNode.appendChild(this.DS.Selector.HTMLNode),this.parentNode.appendChild(this.HTMLNode)):(this.DS.Selector.HTMLNode.remove(),this.HTMLNode.remove())};updateParent=()=>{if(!this.HTMLNode.isConnected)return;const t=this.parentNode;this.HTMLNode.parentNode!==t&&t.appendChild(this.HTMLNode)};updatePos=()=>{this._rect=void 0;const t=this.DS.Area.rect,e=this.DS.Area.computedBorder,s=t.top+e.top,i=t.left+e.left;if(this.setPos(s,i,t.width,t.height),!this.HTMLNode.getClientRects().length)return;const r=this.HTMLNode.getBoundingClientRect(),n=r.top-s,o=r.left-i;(Math.abs(n)>.01||Math.abs(o)>.01)&&this.setPos(s-n,i-o,t.width,t.height),this._rect=void 0};setPos=(t,e,s,i)=>{const{style:r}=this.HTMLNode,n=`${t}px`,o=`${e}px`,a=`${s}px`,l=`${i}px`;r.top!==n&&(r.top=n),r.left!==o&&(r.left=o),r.width!==a&&(r.width=a),r.height!==l&&(r.height=l)};stop=t=>{this.stopAutoScroll(),t&&this.applyElements("remove")};startAutoScroll=({isDraggingKeyboard:t})=>{t||(this.currentEdges=[],this._scrollInterval=setInterval((()=>this.handleAutoScroll()),16))};handleAutoScroll=()=>{if(this.DS.continue)return;const{stores:{PointerStore:t},Area:e}=this.DS;this.currentEdges=(({elementRect:t,containerRect:e,tolerance:s={x:0,y:0}})=>{const i=[];return t.top-s.y<e.top&&i.push("top"),t.left-s.x<e.left&&i.push("left"),t.bottom+s.y>e.bottom&&i.push("bottom"),t.right+s.y>e.right&&i.push("right"),i})({elementRect:h(t.currentVal),containerRect:this.rect,tolerance:this.Settings.overflowTolerance}),this.currentEdges.length&&e.scroll(this.currentEdges,this.Settings.autoScrollSpeed)};stopAutoScroll=()=>{this.currentEdges=[],clearInterval(this._scrollInterval)};isInside=(t,e)=>!(!this.DS.Area.HTMLNode.contains(t)||!this.DS.stores.ScrollStore.canScroll)||g(this.rect,e||t.getBoundingClientRect());isClicked(t){const{stores:{PointerStore:e}}=this.DS,s=t?e.getPointerPosition(t):e.initialVal;return g({left:s.x,top:s.y,right:s.x,bottom:s.y},this.rect)}get rect(){return this._rect?this._rect:this._rect=this.HTMLNode.getBoundingClientRect()}}const N=(t,e)=>console.warn(`[DragSelect] TypeIssue: setting "${t}" is not of type "${e}".`),M=(t,e,s,i)=>{if(void 0===e)return s?{[t]:i}:{};if(null===e)return{[t]:null};let r=!0,n=!1;const o="string"==typeof i;o&&(r="string"==typeof e||e instanceof String),o&&!r&&(n=!0,N(t,"string"));const a=!Number.isNaN(i)&&"number"==typeof i;a&&(r=!Number.isNaN(e)&&"number"==typeof e),a&&!r&&(n=!0,N(t,"number"));const l="[object Object]"===Object.prototype.toString.call(i);l&&(r="[object Object]"===Object.prototype.toString.call(e)),l&&!r&&(n=!0,N(t,"object"));const h="boolean"==typeof i;h&&(r="boolean"==typeof e),h&&!r&&(n=!0,N(t,"boolean"));const c=Array.isArray(i);c&&(r=Array.isArray(e)),c&&!r&&(n=!0,N(t,"array"));const d=n||s;return"dragKeys"===t&&r?{[t]:Object.assign(i,e)}:"dragKeys"!==t||r?("dropZones"===t&&r&&Array.isArray(e)&&new Set(e.map((t=>t.id))).size!==e.length&&console.warn('[DragSelect] UniqueConstraintsIssue: setting "dropZones" contains duplicate ids.'),r?{[t]:e}:d?{[t]:i}:{}):d?{[t]:i}:{}};class V{_settings={};s={};PS;constructor({PS:t,settings:e}){this.PS=t,this.update({settings:e,init:!0})}update=({settings:t,init:e})=>{this.PS.publish("Settings:updated:pre",{settings:this._settings,"settings:init":Boolean(e),"settings:new":t}),this._update({settings:t,init:e})};_update=({settings:t={},init:e=!1})=>{const s=((t,e)=>({...M("area",t.area,e,document),...M("selectables",t.selectables,e,null),...M("autoScrollSpeed",t.autoScrollSpeed,e,5),...M("overflowTolerance",t.overflowTolerance,e,{x:25,y:25}),...M("zoom",t.zoom,e,1),...M("customStyles",t.customStyles,e,!1),...M("multiSelectMode",t.multiSelectMode,e,!1),...M("multiSelectToggling",t.multiSelectToggling,e,!0),...M("multiSelectKeys",t.multiSelectKeys,e,["Control","Shift","Meta"]),...M("selector",t.selector,e,null),...M("selectionThreshold",t.selectionThreshold,e,0),...M("draggability",t.draggability,e,!0),...M("immediateDrag",t.immediateDrag,e,!0),...M("keyboardDrag",t.keyboardDrag,e,!0),...M("dragKeys",t.dragKeys,e,{up:["ArrowUp"],down:["ArrowDown"],left:["ArrowLeft"],right:["ArrowRight"]}),...M("keyboardDragSpeed",t.keyboardDragSpeed,e,10),...M("useTransform",t.useTransform,e,!0),...M("refreshMemoryRate",t.refreshMemoryRate,e,80),...M("dropZones",t.dropZones,e,[]),...M("dropInsideThreshold",t.dropInsideThreshold,e,1),...M("dropTargetThreshold",t.dropTargetThreshold,e,0),...M("usePointerEvents",t.usePointerEvents,e,!1),...M("hoverClass",t.hoverClass,e,"ds-hover"),...M("selectableClass",t.selectableClass,e,"ds-selectable"),...M("selectedClass",t.selectedClass,e,"ds-selected"),...M("selectorClass",t.selectorClass,e,"ds-selector"),...M("selectorAreaClass",t.selectorAreaClass,e,"ds-selector-area"),...M("droppedTargetClass",t.droppedTargetClass,e,"ds-dropped-target"),...M("droppedInsideClass",t.droppedInsideClass,e,"ds-dropped-inside"),...M("droppableClass",t.droppableClass,e,"ds-droppable"),...M("dropZoneClass",t.dropZoneClass,e,"ds-dropzone"),...M("dropZoneReadyClass",t.dropZoneReadyClass,e,"ds-dropzone-ready"),...M("dropZoneTargetClass",t.dropZoneTargetClass,e,"ds-dropzone-target"),...M("dropZoneInsideClass",t.dropZoneInsideClass,e,"ds-dropzone-inside"),...M("useLayers",t.useLayers,e,!0)}))(t,e);for(const[i,r]of Object.entries(s))((s,i)=>{s in this._settings||Object.defineProperty(this.s,s,{get:()=>this._settings[s],set:t=>this.update({settings:{[s]:t}})}),this._settings[`${s}:pre`]=this._settings[s],this._settings[s]=i;const r={settings:this._settings,"settings:init":e,"settings:new":t};this.PS.publish("Settings:updated",r),this.PS.publish(`Settings:updated:${s}`,r)})(i,r)}}const K={elementselect:"DS:select",elementunselect:"DS:unselect",autoscroll:"DS:scroll",dragstart:"DS:start",dragmove:"DS:update",callback:"DS:end",preelementselect:"DS:select:pre",preelementunselect:"DS:unselect:pre",preautoscroll:"DS:scroll:pre",predragstart:"DS:start:pre",predragmove:"DS:update:pre",precallback:"DS:end:pre"},H=(t,e)=>{const s=e.DropZones.getTarget(t);return{...t,...s?{dropTarget:s.toObject()}:{}}},R=({sub_name:t,DS:e,PS:s,sub_pubs:i})=>{s.subscribe(t,(t=>i.forEach((s=>k({sub_pub:s,data:t,DS:e})))))},k=({sub_pub:t,data:e,DS:s})=>{const i=t.condition?t.condition(e,s):e;if(i){const r=t.extraData&&t.extraData(e,s)||{};s.publish(t.name,{items:s.SelectedSet.elements,isDragging:s.Interaction.isDragging,...i,...r})}};class ${continue=!1;PubSub;stores;Area;Selector;SelectorArea;SelectableSet;SelectedSet;Selection;Drag;DropZones;Interaction;stopped;constructor(t){this.stopped=!1,this.PubSub=new P({DS:this}),this.stores={},this.stores.SettingsStore=new V({settings:t,PS:this.PubSub}),this.stores.PointerStore=new v({DS:this,PS:this.PubSub}),this.stores.ScrollStore=new L({DS:this,PS:this.PubSub}),this.stores.KeyStore=new _({DS:this,PS:this.PubSub}),this.Area=new o({DS:this,PS:this.PubSub}),this.Selector=new x({DS:this,PS:this.PubSub}),this.SelectorArea=new w({DS:this,PS:this.PubSub}),this.SelectableSet=new T({DS:this,PS:this.PubSub}),this.SelectedSet=new C({DS:this,PS:this.PubSub}),this.Selection=new A({DS:this,PS:this.PubSub}),this.Drag=new p({DS:this,PS:this.PubSub}),this.DropZones=new y({DS:this,PS:this.PubSub}),this.Interaction=new D({DS:this,PS:this.PubSub}),(({PS:t,DS:e})=>{const s={"Selected:added":[{name:"preelementselect"},{name:"elementselect"},{name:"DS:select:pre"},{name:"DS:select"}],"Selected:removed":[{name:"preelementunselect"},{name:"elementunselect"},{name:"DS:unselect:pre"},{name:"DS:unselect"}],"Selectable:added":[{name:"DS:added:pre"},{name:"DS:added"}],"Selectable:removed":[{name:"DS:removed:pre"},{name:"DS:removed"}],"Area:scroll":[{name:"preautoscroll"},{name:"autoscroll"},{name:"DS:scroll:pre"},{name:"DS:scroll"}],"Interaction:start":[{name:"predragstart"},{name:"dragstart"},{name:"DS:start:pre"},{name:"DS:start"}],"Interaction:update":[{name:"predragmove",condition:t=>t.event?t:null},{name:"dragmove",condition:t=>t.event?t:null},{name:"DS:update:pre",condition:t=>t.event?t:null},{name:"DS:update",condition:t=>t.event?t:null}],"Interaction:end":[{name:"precallback",extraData:(t,e)=>H(t,e)},{name:"callback",extraData:(t,e)=>H(t,e)},{name:"DS:end:pre",extraData:(t,e)=>H(t,e)},{name:"DS:end",extraData:(t,e)=>H(t,e)}]};for(const[i,r]of Object.entries(s))R({sub_name:i,sub_pubs:r,DS:e,PS:t})})({DS:this,PS:this.PubSub}),this.PubSub.subscribe("Interaction:end",(()=>this.continue=!1)),this.PubSub.subscribe("DS:end",(({items:t})=>this.continue=!1)),this.start()}static isCollision;subscribe=(t,e)=>(K[t]&&console.warn(`[DragSelect]: The event name "${t}" is deprecated and was/will be removed in a future version. Please use the new event name "${K[t]}" instead.`),this.PubSub.subscribe(t,e));unsubscribe=(t,e,s)=>this.PubSub.unsubscribe(t,e,s);publish=(t,e)=>this.PubSub.publish(t,e);start=()=>{this.stopped=!1,this.Interaction.init()};stop(t=!0,e=!0,s=!1){s&&this.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),this.Interaction.stop(),this.Area.stop(),this.Drag.stop(),this.Selector.stop(),this.SelectorArea.stop(t),this.stores.KeyStore.stop(),this.stores.PointerStore.stop(),this.stores.ScrollStore.stop(),t&&this.SelectableSet.clear(),e&&this.SelectedSet.clear(),this.stopped=!0}break=()=>this.continue=!0;setSettings=t=>this.stores.SettingsStore.update({settings:t});getSelection=()=>this.SelectedSet.elements;addSelection(t,e=!1,s=!1){const i=m(t);return this.SelectedSet.addAll(i),s||this.addSelectables(t,!1,!1),e&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),this.getSelection()}removeSelection(t,e=!1,s=!1){const i=m(t);return this.SelectedSet.deleteAll(i),s&&this.removeSelectables(t,!1,!1),e&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),this.getSelection()}toggleSelection(t,e=!1,s=!1){return m(t).forEach((i=>this.SelectedSet.has(i)?this.removeSelection(t,e,s):this.addSelection(t,e,s))),e&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),this.getSelection()}setSelection(t,e=!1,s=!1){return this.clearSelection(),this.addSelection(t,e,s),this.getSelection()}clearSelection(t=!1){return this.SelectedSet.clear(),t&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),this.getSelection()}addSelectables(t,e,s){const i=m(t);return this.SelectableSet.addAll(i),e&&this.SelectedSet.addAll(i),s&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),i}getSelectables=()=>this.SelectableSet.elements;removeSelectables(t,e,s){const i=m(t);return this.SelectableSet.deleteAll(i),e&&this.removeSelection(t),s&&this.PubSub.publish("DS:end",{items:this.SelectedSet.elements,isDragging:this.Interaction.isDragging}),i}getInitialCursorPosition=()=>this.stores.PointerStore.initialVal;getCurrentCursorPosition=()=>this.stores.PointerStore.currentVal;getPreviousCursorPosition=()=>this.stores.PointerStore.lastVal;getInitialCursorPositionArea=()=>this.stores.PointerStore.initialValArea;getCurrentCursorPositionArea=()=>this.stores.PointerStore.currentValArea;getPreviousCursorPositionArea=()=>this.stores.PointerStore.lastValArea;isMultiSelect=t=>this.stores.KeyStore.isMultiSelectKeyPressed(t);isDragging=()=>this.Interaction.isDragging;getZoneByCoordinates=t=>this.DropZones.getTarget({coordinates:t})?.toObject();getItemsDroppedByZoneId=t=>this.DropZones.getItemsDroppedById(t);getItemsInsideByZoneId=(t,e)=>this.DropZones.getItemsInsideById(t,e)}return $.isCollision=g,$}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dragselect",
3
- "version": "3.1.5",
3
+ "version": "3.1.6",
4
4
  "description": "Easy JavaScript library for selecting and moving elements. With no dependencies. Drag-Select & Drag-And-Drop.",
5
5
  "main": "./dist/DragSelect.js",
6
6
  "module": "./dist/DragSelect.esm.js",