snap-dnd 0.1.3 → 0.2.0

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/dist/snap.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Snap=(()=>{var k=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var N=(r,e)=>{for(var t in e)k(r,t,{get:e[t],enumerable:!0})},V=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of $(e))!W.call(r,o)&&o!==t&&k(r,o,{get:()=>e[o],enumerable:!(n=K(e,o))||n.enumerable});return r};var J=r=>V(k({},"__esModule",{value:!0}),r);var st={};N(st,{AutoScroll:()=>w,BoundsCache:()=>L,ConstraintAxis:()=>F,DragEngine:()=>y,DragState:()=>f,DropZone:()=>P,DropZoneManager:()=>S,EventEmitter:()=>_,FileDrop:()=>Z,FileSensor:()=>T,Kanban:()=>O,ObjectPool:()=>b,PointerSensor:()=>x,RAFThrottle:()=>E,Snap:()=>I,SnapDataTransfer:()=>m,SnapGrid:()=>R,Sortable:()=>A,boundsCache:()=>h,createFileDropZone:()=>U,default:()=>G,pointPool:()=>v,rafThrottle:()=>Y,rectPool:()=>j});var _=class{constructor(){this._listeners=new Map}on(e,t){let n=this._listeners.get(e);return n||(n=new Set,this._listeners.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&this._listeners.delete(e)}}once(e,t){let n=this.on(e,o=>{n(),t(o)});return n}emit(e,t){let n=this._listeners.get(e);if(n)for(let o of[...n])o(t)}off(e){e?this._listeners.delete(e):this._listeners.clear()}hasListeners(e){let t=this._listeners.get(e);return t!==void 0&&t.size>0}listenerCount(e){return this._listeners.get(e)?.size??0}destroy(){this._listeners.clear()}};var m=class r{constructor(){this._data=new Map}setData(e,t){this._data.set(e,t)}getData(e){return this._data.get(e)}hasType(e){return this._data.has(e)}get types(){return[...this._data.keys()]}clear(){this._data.clear()}clone(){let e=new r;for(let[t,n]of this._data)e.setData(t,n);return e}};var f=class extends _{constructor(){super(...arguments);this._session=null;this._idCounter=0}get session(){return this._session}isDragging(){return this._session!==null&&this._session.phase==="dragging"}getActiveElement(){return this._session?.element??null}getCurrentDropZone(){return this._session?.dropZone??null}startDrag(t,n,o){this._session&&this.cancelDrag();let i=new m;if(o)for(let[s,a]of Object.entries(o))i.setData(s,a);return this._session={id:`drag-${++this._idCounter}`,element:t,origin:{x:n.x,y:n.y},current:{x:n.x,y:n.y},delta:{x:0,y:0},data:i,dropZone:null,phase:"dragging"},this.emit("dragstart",this._session),this._session}updatePosition(t){!this._session||this._session.phase!=="dragging"||(this._session.current.x=t.x,this._session.current.y=t.y,this._session.delta.x=t.x-this._session.origin.x,this._session.delta.y=t.y-this._session.origin.y,this.emit("dragmove",this._session))}setDropTarget(t){if(!this._session)return;let n=this._session.dropZone;n!==t&&(n&&(this._session.dropZone=null,this.emit("dropzoneleave",this._session)),t&&(this._session.dropZone=t,this.emit("dropzoneenter",this._session)))}endDrag(){if(!this._session)return null;let t=this._session;return t.phase="dropping",t.dropZone&&this.emit("drop",t),this.emit("dragend",t),this._session=null,t}cancelDrag(){if(!this._session)return null;let t=this._session;return t.phase="cancelled",t.dropZone=null,this.emit("dragend",t),this._session=null,t}subscribe(t,n){return this.on(t,n)}reset(){this._session&&this.cancelDrag()}destroy(){this.reset(),super.destroy()}};var E=class{constructor(e){this._rafId=null;this._pending=null;this._process=()=>{if(this._rafId=null,this._pending!==null){let e=this._pending;this._pending=null,this._callback(e)}};this._callback=e}queue(e){this._pending=e,this._rafId===null&&(this._rafId=requestAnimationFrame(this._process))}cancel(){this._rafId!==null&&(cancelAnimationFrame(this._rafId),this._rafId=null),this._pending=null}flush(){this._pending!==null&&(this.cancel(),this._callback(this._pending),this._pending=null)}get isPending(){return this._rafId!==null}destroy(){this.cancel()}};function Y(r){let e=null,t=null,n=(...o)=>{t=o,e===null&&(e=requestAnimationFrame(()=>{e=null,t!==null&&(r(...t),t=null)}))};return n.cancel=()=>{e!==null&&(cancelAnimationFrame(e),e=null),t=null},n.flush=()=>{e!==null&&(cancelAnimationFrame(e),e=null),t!==null&&(r(...t),t=null)},n}var b=class{constructor(e,t,n=10,o=100){this._pool=[];this._factory=e,this._reset=t,this._maxSize=o;for(let i=0;i<n;i++)this._pool.push(e())}acquire(){return this._pool.pop()??this._factory()}release(e){this._pool.length<this._maxSize&&(this._reset(e),this._pool.push(e))}clear(){this._pool.length=0}get size(){return this._pool.length}},v=new b(()=>({x:0,y:0}),r=>{r.x=0,r.y=0}),j=new b(()=>({x:0,y:0,width:0,height:0}),r=>{r.x=0,r.y=0,r.width=0,r.height=0});function D(r,e){let t=v.acquire();return t.x=r,t.y=e,t}var x=class extends _{constructor(t){super();this._attached=!1;this._activePointerId=null;this._activeElement=null;this._startPosition=null;this._isDragging=!1;this._delayTimer=null;this._onPointerDown=t=>{if(!t.isPrimary||t.button!==0||this._activePointerId!==null)return;let n=this._findDraggable(t);if(!n||this._options.handleSelector&&!this._findHandle(t,n))return;t.preventDefault(),this._activePointerId=t.pointerId,this._activeElement=n,this._startPosition=D(t.clientX,t.clientY),this._isDragging=!1,t.target.setPointerCapture(t.pointerId);let o=this._getEventTarget();o.addEventListener("pointermove",this._onPointerMove,{passive:!0}),o.addEventListener("pointerup",this._onPointerUp),o.addEventListener("pointercancel",this._onPointerCancel);let i=this._options.delay??0;i>0?this._delayTimer=window.setTimeout(()=>{this._delayTimer=null,this._startDrag(t)},i):(this._options.distance??0)===0&&this._startDrag(t)};this._onPointerMove=t=>{t.pointerId===this._activePointerId&&this._moveThrottle.queue(t)};this._processMove=t=>{if(!this._startPosition||!this._activeElement)return;let n=D(t.clientX,t.clientY);if(!this._isDragging){let o=this._options.distance??0;if(o>0){let i=n.x-this._startPosition.x,s=n.y-this._startPosition.y;if(Math.sqrt(i*i+s*s)<o){v.release(n);return}this._clearDelayTimer(),this._startDrag(t)}}if(this._isDragging){let o=D(n.x-this._startPosition.x,n.y-this._startPosition.y);this.emit("pointermove",{position:n,delta:o,pointerId:t.pointerId,originalEvent:t})}else v.release(n)};this._onPointerUp=t=>{t.pointerId===this._activePointerId&&(this._moveThrottle.flush(),this._isDragging&&this.emit("pointerup",{position:D(t.clientX,t.clientY),pointerId:t.pointerId,originalEvent:t}),this._cleanup())};this._onPointerCancel=t=>{t.pointerId===this._activePointerId&&(this._moveThrottle.cancel(),this._isDragging&&this.emit("pointercancel",{position:D(t.clientX,t.clientY),pointerId:t.pointerId,originalEvent:t}),this._cleanup())};this._container=t.container,this._options=t,this._moveThrottle=new E(n=>this._processMove(n))}attach(){if(this._attached)return;this._getEventTarget().addEventListener("pointerdown",this._onPointerDown,{passive:!1}),this._attached=!0}detach(){if(!this._attached)return;this._getEventTarget().removeEventListener("pointerdown",this._onPointerDown),this._cleanup(),this._attached=!1}get isActive(){return this._activePointerId!==null}get isDragging(){return this._isDragging}_getEventTarget(){return this._container instanceof ShadowRoot?this._container.host:this._container}_startDrag(t){this._isDragging||!this._activeElement||!this._startPosition||(this._isDragging=!0,this.emit("pointerdown",{element:this._activeElement,position:{x:this._startPosition.x,y:this._startPosition.y},pointerId:t.pointerId,originalEvent:t}))}_findDraggable(t){let n=t.target,o=t.composedPath();for(let i of o)if(i instanceof HTMLElement){if(i.matches(this._options.draggableSelector))return i;if(i===this._container||i===this._container.host)break}return n.closest?.(this._options.draggableSelector)}_findHandle(t,n){if(!this._options.handleSelector)return n;let i=t.target.closest?.(this._options.handleSelector);return i&&n.contains(i)?i:null}_clearDelayTimer(){this._delayTimer!==null&&(clearTimeout(this._delayTimer),this._delayTimer=null)}_cleanup(){this._clearDelayTimer(),this._moveThrottle.cancel(),this._startPosition&&(v.release(this._startPosition),this._startPosition=null);let t=this._getEventTarget();t.removeEventListener("pointermove",this._onPointerMove),t.removeEventListener("pointerup",this._onPointerUp),t.removeEventListener("pointercancel",this._onPointerCancel),this._activePointerId=null,this._activeElement=null,this._isDragging=!1}destroy(){this.detach(),this._moveThrottle.destroy(),super.destroy()}};var L=class{constructor(){this._cache=new WeakMap;this._dirty=new WeakSet;this._invalidateAll=!1}get(e){if(this._invalidateAll||this._dirty.has(e))return this._update(e);let t=this._cache.get(e);return t||this._update(e)}invalidate(e){this._dirty.add(e)}invalidateAll(){this._invalidateAll=!0}update(e){return this._update(e)}remove(e){this._cache.delete(e)}clearDirty(){this._invalidateAll=!1}_update(e){let t=e.getBoundingClientRect();return this._cache.set(e,t),this._dirty.delete(e),t}},h=new L;function C(r,e,t){return r>=t.left&&r<=t.right&&e>=t.top&&e<=t.bottom}function g(r){return{x:r.left+r.width/2,y:r.top+r.height/2}}var y=class{constructor(e){this._enabled=!1;this._listenerUnsubscribers=[];this._ghost=null;this._ghostOffset={x:0,y:0};this._onPointerDown=e=>{let{element:t,position:n}=e,o=this._getItemData(t)??this._extractDataAttributes(t),i=this._state.startDrag(t,n,o),s={element:t,position:{x:n.x,y:n.y},data:i.data,cancel:()=>{this._state.cancelDrag()}};if(this._options.onDragStart?.(s)===!1){this._state.cancelDrag();return}this._createGhost(t,n),t.classList.add("snap-dragging"),this._options.ghostClass&&t.classList.add(this._options.ghostClass),h.invalidateAll()};this._onPointerMove=e=>{let t=this._state.session;if(!t)return;let{position:n}=e,o=this._getItemAxis(t.element)??this._options.axis??"both";o!=="both"&&(n=this._applyAxisConstraint(n,t.origin,o)),this._options.grid&&(n=this._applyGridSnap(n,this._options.grid)),this._state.updatePosition(n),this._updateGhost(n),this._updateDropZone(n),this._options.onDragMove?.({element:t.element,position:{x:t.current.x,y:t.current.y},delta:{x:t.delta.x,y:t.delta.y},dropZone:t.dropZone})};this._onPointerUp=e=>{if(!this._state.session)return;let n=this._state.endDrag();n&&(this._cleanup(n.element),n.dropZone&&this._options.onDrop?.({element:n.element,dropZone:n.dropZone,position:{x:n.current.x,y:n.current.y},data:n.data}),this._options.onDragEnd?.({element:n.element,position:{x:n.current.x,y:n.current.y},delta:{x:n.delta.x,y:n.delta.y},cancelled:!1}))};this._onPointerCancel=e=>{let t=this._state.session;if(!t)return;let n=t.element;this._state.cancelDrag(),this._cleanup(n),this._options.onDragEnd?.({element:n,position:e.position,delta:{x:0,y:0},cancelled:!0})};this._container=e.container,this._state=e.state,this._options=e.options,this._getDropZones=e.getDropZones,this._getItemData=e.getItemData,this._getItemAxis=e.getItemAxis,this._pointerSensor=new x({container:this._container,draggableSelector:this._options.draggableSelector??"[data-draggable]",handleSelector:this._options.handleSelector,delay:this._options.delay,distance:this._options.distance}),this._setupListeners()}enable(){this._enabled||(this._pointerSensor.attach(),this._enabled=!0)}disable(){this._enabled&&(this._pointerSensor.detach(),this._state.reset(),this._removeGhost(),this._enabled=!1)}get isEnabled(){return this._enabled}updateOptions(e){Object.assign(this._options,e)}_setupListeners(){this._listenerUnsubscribers.push(this._pointerSensor.on("pointerdown",this._onPointerDown),this._pointerSensor.on("pointermove",this._onPointerMove),this._pointerSensor.on("pointerup",this._onPointerUp),this._pointerSensor.on("pointercancel",this._onPointerCancel))}_applyAxisConstraint(e,t,n){return n==="x"?{x:e.x,y:t.y}:n==="y"?{x:t.x,y:e.y}:e}_applyGridSnap(e,t){return{x:Math.round(e.x/t.x)*t.x,y:Math.round(e.y/t.y)*t.y}}_updateDropZone(e){let t=this._getDropZones(),n=null;for(let i of t){let s=h.get(i);if(C(e.x,e.y,s)){n=i;break}}let o=this._state.session;o&&n!==o.dropZone&&(o.dropZone&&this._options.onDropZoneLeave?.({element:o.element,dropZone:o.dropZone}),this._state.setDropTarget(n),n&&this._options.onDropZoneEnter?.({element:o.element,dropZone:n,position:e}))}_createGhost(e,t){let n=e.getBoundingClientRect();this._ghostOffset={x:t.x-n.left,y:t.y-n.top},this._ghost=e.cloneNode(!0),this._ghost.style.cssText=`
1
+ "use strict";var Snap=(()=>{var $=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var ie=Object.prototype.hasOwnProperty;var oe=(r,t)=>{for(var e in t)$(r,e,{get:t[e],enumerable:!0})},re=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ne(t))!ie.call(r,o)&&o!==e&&$(r,o,{get:()=>t[o],enumerable:!(n=te(t,o))||n.enumerable});return r};var se=r=>re($({},"__esModule",{value:!0}),r);var me={};oe(me,{AutoScroll:()=>k,BoundsCache:()=>w,ConstraintAxis:()=>q,DragEngine:()=>T,DragState:()=>x,DropZone:()=>H,DropZoneManager:()=>L,EventEmitter:()=>f,FileDrop:()=>z,FileSensor:()=>P,Kanban:()=>R,ObjectPool:()=>D,PointerSensor:()=>S,RAFThrottle:()=>E,Snap:()=>C,SnapDataTransfer:()=>b,SnapGrid:()=>B,Sortable:()=>F,boundsCache:()=>c,createFileDropZone:()=>ee,createSafeEventData:()=>J,deepFreeze:()=>Y,default:()=>Q,extractSafeAttributes:()=>N,isValidSelector:()=>j,pointPool:()=>m,rafThrottle:()=>W,rectPool:()=>K,safeMerge:()=>_,sanitizeDataValue:()=>M,sanitizeSelector:()=>g,validateFiles:()=>Z});var f=class{constructor(){this._listeners=new Map}on(t,e){let n=this._listeners.get(t);return n||(n=new Set,this._listeners.set(t,n)),n.add(e),()=>{n.delete(e),n.size===0&&this._listeners.delete(t)}}once(t,e){let n=this.on(t,o=>{n(),e(o)});return n}emit(t,e){let n=this._listeners.get(t);if(n)for(let o of[...n])o(e)}off(t){t?this._listeners.delete(t):this._listeners.clear()}hasListeners(t){let e=this._listeners.get(t);return e!==void 0&&e.size>0}listenerCount(t){return this._listeners.get(t)?.size??0}destroy(){this._listeners.clear()}};var b=class r{constructor(){this._data=new Map}setData(t,e){this._data.set(t,e)}getData(t){return this._data.get(t)}hasType(t){return this._data.has(t)}get types(){return[...this._data.keys()]}clear(){this._data.clear()}clone(){let t=new r;for(let[e,n]of this._data)t.setData(e,n);return t}};var x=class extends f{constructor(){super(...arguments);this._session=null;this._idCounter=0}get session(){return this._session}isDragging(){return this._session!==null&&this._session.phase==="dragging"}getActiveElement(){return this._session?.element??null}getCurrentDropZone(){return this._session?.dropZone??null}startDrag(e,n,o){this._session&&this.cancelDrag();let i=new b;if(o)for(let[s,p]of Object.entries(o))i.setData(s,p);return this._session={id:`drag-${++this._idCounter}`,element:e,origin:{x:n.x,y:n.y},current:{x:n.x,y:n.y},delta:{x:0,y:0},data:i,dropZone:null,phase:"dragging"},this.emit("dragstart",this._session),this._session}updatePosition(e){!this._session||this._session.phase!=="dragging"||(this._session.current.x=e.x,this._session.current.y=e.y,this._session.delta.x=e.x-this._session.origin.x,this._session.delta.y=e.y-this._session.origin.y,this.emit("dragmove",this._session))}setDropTarget(e){if(!this._session)return;let n=this._session.dropZone;n!==e&&(n&&(this._session.dropZone=null,this.emit("dropzoneleave",this._session)),e&&(this._session.dropZone=e,this.emit("dropzoneenter",this._session)))}endDrag(){if(!this._session)return null;let e=this._session;return e.phase="dropping",e.dropZone&&this.emit("drop",e),this.emit("dragend",e),this._session=null,e}cancelDrag(){if(!this._session)return null;let e=this._session;return e.phase="cancelled",e.dropZone=null,this.emit("dragend",e),this._session=null,e}subscribe(e,n){return this.on(e,n)}reset(){this._session&&this.cancelDrag()}destroy(){this.reset(),super.destroy()}};var E=class{constructor(t){this._rafId=null;this._pending=null;this._process=()=>{if(this._rafId=null,this._pending!==null){let t=this._pending;this._pending=null,this._callback(t)}};this._callback=t}queue(t){this._pending=t,this._rafId===null&&(this._rafId=requestAnimationFrame(this._process))}cancel(){this._rafId!==null&&(cancelAnimationFrame(this._rafId),this._rafId=null),this._pending=null}flush(){this._pending!==null&&(this.cancel(),this._callback(this._pending),this._pending=null)}get isPending(){return this._rafId!==null}destroy(){this.cancel()}};function W(r){let t=null,e=null,n=(...o)=>{e=o,t===null&&(t=requestAnimationFrame(()=>{t=null,e!==null&&(r(...e),e=null)}))};return n.cancel=()=>{t!==null&&(cancelAnimationFrame(t),t=null),e=null},n.flush=()=>{t!==null&&(cancelAnimationFrame(t),t=null),e!==null&&(r(...e),e=null)},n}var D=class{constructor(t,e,n=10,o=100){this._pool=[];this._factory=t,this._reset=e,this._maxSize=o;for(let i=0;i<n;i++)this._pool.push(t())}acquire(){return this._pool.pop()??this._factory()}release(t){this._pool.length<this._maxSize&&(this._reset(t),this._pool.push(t))}clear(){this._pool.length=0}get size(){return this._pool.length}},m=new D(()=>({x:0,y:0}),r=>{r.x=0,r.y=0}),K=new D(()=>({x:0,y:0,width:0,height:0}),r=>{r.x=0,r.y=0,r.width=0,r.height=0});function y(r,t){let e=m.acquire();return e.x=r,e.y=t,e}var S=class extends f{constructor(e){super();this._attached=!1;this._activePointerId=null;this._activeElement=null;this._startPosition=null;this._isDragging=!1;this._delayTimer=null;this._onPointerDown=e=>{if(!e.isPrimary||e.button!==0||this._activePointerId!==null)return;let n=this._findDraggable(e);if(!n||this._options.handleSelector&&!this._findHandle(e,n))return;e.preventDefault(),this._activePointerId=e.pointerId,this._activeElement=n,this._startPosition=y(e.clientX,e.clientY),this._isDragging=!1,e.target.setPointerCapture(e.pointerId);let o=this._getEventTarget();o.addEventListener("pointermove",this._onPointerMove,{passive:!0}),o.addEventListener("pointerup",this._onPointerUp),o.addEventListener("pointercancel",this._onPointerCancel);let i=this._options.delay??0;i>0?this._delayTimer=window.setTimeout(()=>{this._delayTimer=null,this._startDrag(e)},i):(this._options.distance??0)===0&&this._startDrag(e)};this._onPointerMove=e=>{e.pointerId===this._activePointerId&&this._moveThrottle.queue(e)};this._processMove=e=>{if(!this._startPosition||!this._activeElement)return;let n=y(e.clientX,e.clientY);if(!this._isDragging){let o=this._options.distance??0;if(o>0){let i=n.x-this._startPosition.x,s=n.y-this._startPosition.y;if(Math.sqrt(i*i+s*s)<o){m.release(n);return}this._clearDelayTimer(),this._startDrag(e)}}if(this._isDragging){let o=y(n.x-this._startPosition.x,n.y-this._startPosition.y);this.emit("pointermove",{position:n,delta:o,pointerId:e.pointerId,originalEvent:e})}else m.release(n)};this._onPointerUp=e=>{e.pointerId===this._activePointerId&&(this._moveThrottle.flush(),this._isDragging&&this.emit("pointerup",{position:y(e.clientX,e.clientY),pointerId:e.pointerId,originalEvent:e}),this._cleanup())};this._onPointerCancel=e=>{e.pointerId===this._activePointerId&&(this._moveThrottle.cancel(),this._isDragging&&this.emit("pointercancel",{position:y(e.clientX,e.clientY),pointerId:e.pointerId,originalEvent:e}),this._cleanup())};this._container=e.container,this._options=e,this._moveThrottle=new E(n=>this._processMove(n))}attach(){if(this._attached)return;this._getEventTarget().addEventListener("pointerdown",this._onPointerDown,{passive:!1}),this._attached=!0}detach(){if(!this._attached)return;this._getEventTarget().removeEventListener("pointerdown",this._onPointerDown),this._cleanup(),this._attached=!1}get isActive(){return this._activePointerId!==null}get isDragging(){return this._isDragging}_getEventTarget(){return this._container instanceof ShadowRoot?this._container.host:this._container}_startDrag(e){this._isDragging||!this._activeElement||!this._startPosition||(this._isDragging=!0,this.emit("pointerdown",{element:this._activeElement,position:{x:this._startPosition.x,y:this._startPosition.y},pointerId:e.pointerId,originalEvent:e}))}_findDraggable(e){let n=e.target,o=e.composedPath();for(let i of o)if(i instanceof HTMLElement){if(i.matches(this._options.draggableSelector))return i;if(i===this._container||i===this._container.host)break}return n.closest?.(this._options.draggableSelector)}_findHandle(e,n){if(!this._options.handleSelector)return n;let i=e.target.closest?.(this._options.handleSelector);return i&&n.contains(i)?i:null}_clearDelayTimer(){this._delayTimer!==null&&(clearTimeout(this._delayTimer),this._delayTimer=null)}_cleanup(){this._clearDelayTimer(),this._moveThrottle.cancel(),this._startPosition&&(m.release(this._startPosition),this._startPosition=null);let e=this._getEventTarget();e.removeEventListener("pointermove",this._onPointerMove),e.removeEventListener("pointerup",this._onPointerUp),e.removeEventListener("pointercancel",this._onPointerCancel),this._activePointerId=null,this._activeElement=null,this._isDragging=!1}destroy(){this.detach(),this._moveThrottle.destroy(),super.destroy()}};var w=class{constructor(){this._cache=new WeakMap;this._dirty=new WeakSet;this._invalidateAll=!1}get(t){if(this._invalidateAll||this._dirty.has(t))return this._update(t);let e=this._cache.get(t);return e||this._update(t)}invalidate(t){this._dirty.add(t)}invalidateAll(){this._invalidateAll=!0}update(t){return this._update(t)}remove(t){this._cache.delete(t)}clearDirty(){this._invalidateAll=!1}_update(t){let e=t.getBoundingClientRect();return this._cache.set(t,e),this._dirty.delete(t),e}},c=new w;function A(r,t,e){return r>=e.left&&r<=e.right&&t>=e.top&&t<=e.bottom}function v(r){return{x:r.left+r.width/2,y:r.top+r.height/2}}function _(r,...t){let e=["__proto__","constructor","prototype"];for(let n of t)if(!(!n||typeof n!="object"))for(let o of Object.keys(n)){if(e.includes(o))continue;let i=n[o];i!==void 0&&(r[o]=i)}return r}function j(r){if(!r||typeof r!="string"||r.length>500)return!1;let t=[/javascript:/i,/expression\s*\(/i,/url\s*\(/i,/@import/i,/<script/i,/on\w+\s*=/i];for(let e of t)if(e.test(r))return!1;try{return document.createElement("div").matches(r),!0}catch{return!1}}function g(r,t){return j(r)?r:(console.warn(`[Snap] Invalid selector "${r}", using default`),t)}function M(r){return typeof r!="string"?"":r.replace(/<[^>]*>/g,"").slice(0,1e3)}function N(r,t=["data-drag-","data-draggable","data-droppable"]){let e={};for(let n of r.attributes){let o=n.name.toLowerCase();t.some(s=>o===s||o.startsWith(s))&&(e[o]=M(n.value))}return e}var ae={"application/pdf":[[37,80,68,70]],"image/jpeg":[[255,216,255]],"image/png":[[137,80,78,71]],"image/gif":[[71,73,70,56]],"application/zip":[[80,75,3,4],[80,75,5,6]],"application/vnd.openxmlformats-officedocument.wordprocessingml.document":[[80,75,3,4]],"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":[[80,75,3,4]]};async function le(r){let t=ae[r.type];if(!t)return!0;try{let e=await r.slice(0,8).arrayBuffer(),n=new Uint8Array(e);for(let o of t){let i=!0;for(let s=0;s<o.length;s++)if(n[s]!==o[s]){i=!1;break}if(i)return!0}return!1}catch{return!1}}async function Z(r,t={}){let e=[],{maxSize:n=50*1024*1024,minSize:o=1,accept:i=[],maxFiles:s=100,validateMagicBytes:p=!1}=t,l=r.slice(0,s);for(let a of l){if(a.size<o){e.push({valid:!1,file:a,error:"File too small"});continue}if(a.size>n){e.push({valid:!1,file:a,error:"File too large"});continue}if(i.length>0&&!ce(a,i)){e.push({valid:!1,file:a,error:"File type not allowed"});continue}if(p&&!await le(a)){e.push({valid:!1,file:a,error:"File content does not match extension (possible spoofing)"});continue}if(pe(a.name)){e.push({valid:!1,file:a,error:"Suspicious filename"});continue}e.push({valid:!0,file:a})}return e}function pe(r){return[/\.exe$/i,/\.bat$/i,/\.cmd$/i,/\.ps1$/i,/\.vbs$/i,/\.js$/i,/\.jse$/i,/\.wsf$/i,/\.wsh$/i,/\.msi$/i,/\.scr$/i,/\.pif$/i,/\.hta$/i,/\.\w+\.exe$/i,/\.\w+\.js$/i].some(e=>e.test(r))}function ce(r,t){for(let e of t)if(e.startsWith(".")){if(r.name.toLowerCase().endsWith(e.toLowerCase()))return!0}else if(e.endsWith("/*")){let n=e.slice(0,-1);if(r.type.startsWith(n))return!0}else if(r.type===e)return!0;return!1}function Y(r){Object.freeze(r);for(let t of Object.keys(r)){let e=r[t];e&&typeof e=="object"&&!Object.isFrozen(e)&&Y(e)}return r}function J(r){let t={...r};return Object.freeze(t)}var T=class{constructor(t){this._enabled=!1;this._listenerUnsubscribers=[];this._ghost=null;this._ghostOffset={x:0,y:0};this._onPointerDown=t=>{let{element:e,position:n}=t,o=this._getItemData(e)??this._extractDataAttributes(e),i=this._state.startDrag(e,n,o),s={element:e,position:{x:n.x,y:n.y},data:i.data,cancel:()=>{this._state.cancelDrag()}};if(this._options.onDragStart?.(s)===!1){this._state.cancelDrag();return}this._createGhost(e,n),e.classList.add("snap-dragging"),this._options.ghostClass&&e.classList.add(this._options.ghostClass),c.invalidateAll()};this._onPointerMove=t=>{let e=this._state.session;if(!e)return;let{position:n}=t,o=this._getItemAxis(e.element)??this._options.axis??"both";o!=="both"&&(n=this._applyAxisConstraint(n,e.origin,o)),this._options.grid&&(n=this._applyGridSnap(n,this._options.grid)),this._state.updatePosition(n),this._updateGhost(n),this._updateDropZone(n),this._options.onDragMove?.({element:e.element,position:{x:e.current.x,y:e.current.y},delta:{x:e.delta.x,y:e.delta.y},dropZone:e.dropZone})};this._onPointerUp=t=>{if(!this._state.session)return;let n=this._state.endDrag();n&&(this._cleanup(n.element),n.dropZone&&this._options.onDrop?.({element:n.element,dropZone:n.dropZone,position:{x:n.current.x,y:n.current.y},data:n.data}),this._options.onDragEnd?.({element:n.element,position:{x:n.current.x,y:n.current.y},delta:{x:n.delta.x,y:n.delta.y},cancelled:!1}))};this._onPointerCancel=t=>{let e=this._state.session;if(!e)return;let n=e.element;this._state.cancelDrag(),this._cleanup(n),this._options.onDragEnd?.({element:n,position:t.position,delta:{x:0,y:0},cancelled:!0})};this._container=t.container,this._state=t.state,this._options=t.options,this._getDropZones=t.getDropZones,this._getItemData=t.getItemData,this._getItemAxis=t.getItemAxis,this._pointerSensor=new S({container:this._container,draggableSelector:this._options.draggableSelector??"[data-draggable]",handleSelector:this._options.handleSelector,delay:this._options.delay,distance:this._options.distance}),this._setupListeners()}enable(){this._enabled||(this._pointerSensor.attach(),this._enabled=!0)}disable(){this._enabled&&(this._pointerSensor.detach(),this._state.reset(),this._removeGhost(),this._enabled=!1)}get isEnabled(){return this._enabled}updateOptions(t){_(this._options,t)}_setupListeners(){this._listenerUnsubscribers.push(this._pointerSensor.on("pointerdown",this._onPointerDown),this._pointerSensor.on("pointermove",this._onPointerMove),this._pointerSensor.on("pointerup",this._onPointerUp),this._pointerSensor.on("pointercancel",this._onPointerCancel))}_applyAxisConstraint(t,e,n){return n==="x"?{x:t.x,y:e.y}:n==="y"?{x:e.x,y:t.y}:t}_applyGridSnap(t,e){return{x:Math.round(t.x/e.x)*e.x,y:Math.round(t.y/e.y)*e.y}}_updateDropZone(t){let e=this._getDropZones(),n=null;for(let i of e){let s=c.get(i);if(A(t.x,t.y,s)){n=i;break}}let o=this._state.session;o&&n!==o.dropZone&&(o.dropZone&&this._options.onDropZoneLeave?.({element:o.element,dropZone:o.dropZone}),this._state.setDropTarget(n),n&&this._options.onDropZoneEnter?.({element:o.element,dropZone:n,position:t}))}_createGhost(t,e){let n=t.getBoundingClientRect();this._ghostOffset={x:e.x-n.left,y:e.y-n.top},this._ghost=t.cloneNode(!0),this._ghost.style.cssText=`
2
2
  position: fixed;
3
3
  left: ${n.left}px;
4
4
  top: ${n.top}px;
@@ -9,21 +9,21 @@
9
9
  z-index: 9999;
10
10
  opacity: 0.8;
11
11
  will-change: transform;
12
- `,this._ghost.classList.add("snap-ghost"),document.body.appendChild(this._ghost)}_updateGhost(e){if(!this._ghost)return;let t=e.x-this._ghostOffset.x,n=e.y-this._ghostOffset.y;this._ghost.style.transform=`translate(${t-parseFloat(this._ghost.style.left)}px, ${n-parseFloat(this._ghost.style.top)}px)`}_removeGhost(){this._ghost&&(this._ghost.remove(),this._ghost=null)}_cleanup(e){e.classList.remove("snap-dragging"),this._options.ghostClass&&e.classList.remove(this._options.ghostClass),this._removeGhost()}_extractDataAttributes(e){let t={};for(let o of e.attributes)if(o.name.startsWith("data-drag-")){let i=o.name.slice(10);t[i]=o.value}let n=e.dataset.draggable;return n&&n!==""&&(t.type=n),t}destroy(){this.disable();for(let e of this._listenerUnsubscribers)e();this._listenerUnsubscribers=[],this._pointerSensor.destroy()}};var P=class{constructor(e,t={}){this._isActive=!1;this._element=e,this._options=t}get element(){return this._element}get isActive(){return this._isActive}setOptions(e){Object.assign(this._options,e)}containsPoint(e,t){let n=h.get(this._element);return C(e,t,n)}accepts(e){let{accepts:t}=this._options;if(!t)return!0;if(typeof t=="function")return t(e);for(let o of t)if(e.hasType(o)||e.getData("type")===o)return!0;let n=this._element.dataset.accepts;if(n){let o=n.split(",").map(i=>i.trim());for(let i of o)if(e.hasType(i)||e.getData("type")===i)return!0}return!1}setActive(e){this._isActive!==e&&(this._isActive=e,e?this._element.classList.add("snap-drop-active"):this._element.classList.remove("snap-drop-active"))}getInsertionIndex(e,t,n,o){let i=Array.from(this._element.querySelectorAll(n)).filter(l=>l!==o);if(i.length===0)return 0;let s=h.get(i[0]),a=h.get(i[i.length-1]),p=Math.abs(a.top-s.top)>Math.abs(a.left-s.left);for(let l=0;l<i.length;l++){let d=h.get(i[l]),c=g(d);if(p){if(t<c.y)return l}else if(e<c.x)return l}return i.length}getClosestItem(e,t,n,o){let i=Array.from(this._element.querySelectorAll(n)).filter(u=>u!==o);if(i.length===0)return null;let s=null,a=1/0,p="after",l=h.get(i[0]),d=h.get(i[i.length-1]),c=Math.abs(d.top-l.top)>Math.abs(d.left-l.left);for(let u of i){let M=h.get(u),H=g(M),B=e-H.x,q=t-H.y,X=Math.sqrt(B*B+q*q);X<a&&(a=X,s=u,p=c?t<H.y?"before":"after":e<H.x?"before":"after")}return s?{element:s,position:p}:null}updateBounds(){h.update(this._element)}destroy(){this.setActive(!1),h.remove(this._element)}},S=class{constructor(){this._zones=new Map}register(e,t){let n=this._zones.get(e);return n?(t&&n.setOptions(t),n):(n=new P(e,t),this._zones.set(e,n),n)}unregister(e){let t=this._zones.get(e);t&&(t.destroy(),this._zones.delete(e))}get(e){return this._zones.get(e)}getElements(){return[...this._zones.keys()]}getAll(){return[...this._zones.values()]}findAtPoint(e,t){for(let n of this._zones.values())if(n.containsPoint(e,t))return n;return null}clear(){for(let e of this._zones.values())e.destroy();this._zones.clear()}updateAllBounds(){h.invalidateAll()}destroy(){this.clear()}};var Q={draggableSelector:"[data-draggable]",dropZoneSelector:"[data-droppable]",axis:"both",autoRefresh:!1},I=class{constructor(e,t={}){this._imperativeDraggables=new Map;this._imperativeDropZones=new Map;this._plugins=[];this._behaviors=[];this._stateUnsubscribers=[];this._observer=null;this._refreshScheduled=!1;this._destroyed=!1;this._scrollHandler=null;this._resizeHandler=null;this._container=e,this._options={...Q,...t},this._state=new f,this._dropZoneManager=new S,this._engine=new y({container:this._container,state:this._state,options:this._options,getDropZones:()=>this._getDropZones(),getItemData:n=>this._getItemData(n),getItemAxis:n=>this._getItemAxis(n)}),this._setupStateListeners(),this._scanDeclarativeElements(),this._options.autoRefresh&&this._setupAutoRefresh(),this._setupScrollResize(),this.enable()}get options(){return this._options}enable(){this._engine.enable()}disable(){this._engine.disable()}destroy(){this._destroyed=!0,this.disable();for(let e of this._stateUnsubscribers)e();this._stateUnsubscribers=[];for(let e of this._plugins)e.destroy();this._plugins=[];for(let e of this._behaviors)e.destroy();this._behaviors=[],this._engine.destroy(),this._state.destroy(),this._dropZoneManager.destroy(),this._observer?.disconnect(),this._observer=null,this._scrollHandler&&(window.removeEventListener("scroll",this._scrollHandler,!0),this._scrollHandler=null),this._resizeHandler&&(window.removeEventListener("resize",this._resizeHandler),this._resizeHandler=null),this._imperativeDraggables.clear(),this._imperativeDropZones.clear()}refresh(){this._scanDeclarativeElements(),h.invalidateAll()}addDraggable(e,t){this._imperativeDraggables.set(e,t??{})}removeDraggable(e){this._imperativeDraggables.delete(e)}addDropZone(e,t){this._imperativeDropZones.set(e,t??{}),this._dropZoneManager.register(e,t)}removeDropZone(e){this._imperativeDropZones.delete(e),this._dropZoneManager.unregister(e)}isDragging(){return this._state.isDragging()}getActiveElement(){return this._state.getActiveElement()}use(e){return this._plugins.push(e),e.init(this),this}addBehavior(e){return this._behaviors.push(e),this}setOptions(e){Object.assign(this._options,e),this._engine.updateOptions(this._options)}_getDropZones(){let e=this._options.dropZoneSelector??"[data-droppable]",t=this._container instanceof ShadowRoot?this._container:this._container,n=Array.from(t.querySelectorAll(e)),o=[...this._imperativeDropZones.keys()];return[...new Set([...n,...o])]}_getItemData(e){return this._imperativeDraggables.get(e)?.data}_getItemAxis(e){let t=this._imperativeDraggables.get(e);if(t?.axis)return t.axis;let n=e.dataset.dragAxis;if(n==="x"||n==="y"||n==="both")return n}_scanDeclarativeElements(){let e=this._options.dropZoneSelector??"[data-droppable]",n=(this._container instanceof ShadowRoot?this._container:this._container).querySelectorAll(e);for(let o of n)this._imperativeDropZones.has(o)||this._dropZoneManager.register(o)}_setupStateListeners(){this._stateUnsubscribers.push(this._state.subscribe("dragstart",e=>{for(let t of this._behaviors)t.onDragStart?.(e)})),this._stateUnsubscribers.push(this._state.subscribe("dragmove",e=>{for(let t of this._behaviors)t.onDragMove?.(e)})),this._stateUnsubscribers.push(this._state.subscribe("dragend",e=>{for(let t of this._behaviors)t.onDragEnd?.(e)}))}_setupAutoRefresh(){this._observer=new MutationObserver(t=>{if(this._destroyed)return;let n=!1;for(let o of t)if(o.type==="childList"){n=!0;break}n&&!this._refreshScheduled&&(this._refreshScheduled=!0,requestAnimationFrame(()=>{this._destroyed||(this._refreshScheduled=!1,this.refresh())}))});let e=this._container instanceof ShadowRoot?this._container:this._container;this._observer.observe(e,{childList:!0,subtree:!0})}_setupScrollResize(){this._scrollHandler=()=>{this._state.isDragging()&&h.invalidateAll()},window.addEventListener("scroll",this._scrollHandler,!0),this._resizeHandler=()=>{h.invalidateAll()},window.addEventListener("resize",this._resizeHandler)}},G=I;var tt={animation:150,ghostClass:"snap-sortable-ghost",placeholderClass:"snap-sortable-placeholder"},A=class{constructor(e={}){this.name="sortable";this._snap=null;this._placeholder=null;this._originalIndex=-1;this._currentIndex=-1;this._container=null;this._items=[];this._unsubscribers=[];this._options={...tt,...e}}init(e){this._snap=e;let t=e.options.onDragStart,n=e.options.onDragMove,o=e.options.onDrop,i=e.options.onDragEnd;e.setOptions({onDragStart:s=>(this._onDragStart(s.element),t?.(s)),onDragMove:s=>{this._onDragMove(s.position.x,s.position.y),n?.(s)},onDrop:s=>{let a={...s,insertionIndex:this._currentIndex,sourceContainer:this._container??void 0};o?.(a)},onDragEnd:s=>{this._onDragEnd(),i?.(s)}})}destroy(){this._cleanup();for(let e of this._unsubscribers)e();this._unsubscribers=[],this._snap=null}_onDragStart(e){if(this._container=e.parentElement,!this._container)return;let t=this._snap?.options.draggableSelector??"[data-draggable]";this._items=Array.from(this._container.querySelectorAll(t)),this._originalIndex=this._items.indexOf(e),this._currentIndex=this._originalIndex,this._originalIndex!==-1&&(this._createPlaceholder(e),this._options.ghostClass&&e.classList.add(this._options.ghostClass))}_onDragMove(e,t){if(!this._placeholder||!this._container)return;let n=this._snap?.options.draggableSelector??"[data-draggable]",o=this._snap?.getActiveElement(),i=Array.from(this._container.querySelectorAll(n)).filter(d=>d!==o&&d!==this._placeholder);if(i.length===0){this._currentIndex=0;return}let s=h.get(i[0]),a=h.get(i[i.length-1]),p=Math.abs(a.top-s.top)>Math.abs(a.left-s.left),l=i.length;for(let d=0;d<i.length;d++){let c=h.get(i[d]),u=g(c);if(p){if(t<u.y){l=d;break}}else if(e<u.x){l=d;break}}l>this._originalIndex&&l++,l!==this._currentIndex&&(this._currentIndex=l,this._movePlaceholder(l))}_onDragEnd(){this._cleanup()}_createPlaceholder(e){let t=e.getBoundingClientRect();this._placeholder=document.createElement("div"),this._placeholder.className=this._options.placeholderClass??"",this._placeholder.style.cssText=`
13
- width: ${t.width}px;
14
- height: ${t.height}px;
12
+ `,this._ghost.classList.add("snap-ghost"),document.body.appendChild(this._ghost)}_updateGhost(t){if(!this._ghost)return;let e=t.x-this._ghostOffset.x,n=t.y-this._ghostOffset.y;this._ghost.style.transform=`translate(${e-parseFloat(this._ghost.style.left)}px, ${n-parseFloat(this._ghost.style.top)}px)`}_removeGhost(){this._ghost&&(this._ghost.remove(),this._ghost=null)}_cleanup(t){t.classList.remove("snap-dragging"),this._options.ghostClass&&t.classList.remove(this._options.ghostClass),this._removeGhost()}_extractDataAttributes(t){let e={},n=["id","type","group","axis","disabled"];for(let i of t.attributes)if(i.name.startsWith("data-drag-")){let s=i.name.slice(10);if(!n.includes(s))continue;e[s]=M(i.value)}let o=t.dataset.draggable;return o&&o!==""&&(e.type=M(o)),e}destroy(){this.disable();for(let t of this._listenerUnsubscribers)t();this._listenerUnsubscribers=[],this._pointerSensor.destroy()}};var H=class{constructor(t,e={}){this._isActive=!1;this._element=t,this._options=e}get element(){return this._element}get isActive(){return this._isActive}setOptions(t){_(this._options,t)}containsPoint(t,e){let n=c.get(this._element);return A(t,e,n)}accepts(t){let{accepts:e}=this._options;if(!e)return!0;if(typeof e=="function")return e(t);for(let o of e)if(t.hasType(o)||t.getData("type")===o)return!0;let n=this._element.dataset.accepts;if(n){let o=n.split(",").map(i=>i.trim());for(let i of o)if(t.hasType(i)||t.getData("type")===i)return!0}return!1}setActive(t){this._isActive!==t&&(this._isActive=t,t?this._element.classList.add("snap-drop-active"):this._element.classList.remove("snap-drop-active"))}getInsertionIndex(t,e,n,o){let i=Array.from(this._element.querySelectorAll(n)).filter(a=>a!==o);if(i.length===0)return 0;let s=c.get(i[0]),p=c.get(i[i.length-1]),l=Math.abs(p.top-s.top)>Math.abs(p.left-s.left);for(let a=0;a<i.length;a++){let h=c.get(i[a]),d=v(h);if(l){if(e<d.y)return a}else if(t<d.x)return a}return i.length}getClosestItem(t,e,n,o){let i=Array.from(this._element.querySelectorAll(n)).filter(u=>u!==o);if(i.length===0)return null;let s=null,p=1/0,l="after",a=c.get(i[0]),h=c.get(i[i.length-1]),d=Math.abs(h.top-a.top)>Math.abs(h.left-a.left);for(let u of i){let I=c.get(u),O=v(I),X=t-O.x,G=e-O.y,U=Math.sqrt(X*X+G*G);U<p&&(p=U,s=u,l=d?e<O.y?"before":"after":t<O.x?"before":"after")}return s?{element:s,position:l}:null}updateBounds(){c.update(this._element)}destroy(){this.setActive(!1),c.remove(this._element)}},L=class{constructor(){this._zones=new Map}register(t,e){let n=this._zones.get(t);return n?(e&&n.setOptions(e),n):(n=new H(t,e),this._zones.set(t,n),n)}unregister(t){let e=this._zones.get(t);e&&(e.destroy(),this._zones.delete(t))}get(t){return this._zones.get(t)}getElements(){return[...this._zones.keys()]}getAll(){return[...this._zones.values()]}findAtPoint(t,e){for(let n of this._zones.values())if(n.containsPoint(t,e))return n;return null}clear(){for(let t of this._zones.values())t.destroy();this._zones.clear()}updateAllBounds(){c.invalidateAll()}destroy(){this.clear()}};var de={draggableSelector:"[data-draggable]",dropZoneSelector:"[data-droppable]",axis:"both",autoRefresh:!1},C=class{constructor(t,e={}){this._imperativeDraggables=new Map;this._imperativeDropZones=new Map;this._plugins=[];this._behaviors=[];this._stateUnsubscribers=[];this._observer=null;this._refreshScheduled=!1;this._destroyed=!1;this._scrollHandler=null;this._resizeHandler=null;this._container=t,this._options=_({},de,e),this._options.draggableSelector&&(this._options.draggableSelector=g(this._options.draggableSelector,"[data-draggable]")),this._options.dropZoneSelector&&(this._options.dropZoneSelector=g(this._options.dropZoneSelector,"[data-droppable]")),this._options.handleSelector&&(this._options.handleSelector=g(this._options.handleSelector,"[data-drag-handle]")),this._state=new x,this._dropZoneManager=new L,this._engine=new T({container:this._container,state:this._state,options:this._options,getDropZones:()=>this._getDropZones(),getItemData:n=>this._getItemData(n),getItemAxis:n=>this._getItemAxis(n)}),this._setupStateListeners(),this._scanDeclarativeElements(),this._options.autoRefresh&&this._setupAutoRefresh(),this._setupScrollResize(),this.enable()}get options(){return this._options}enable(){this._engine.enable()}disable(){this._engine.disable()}destroy(){this._destroyed=!0,this.disable();for(let t of this._stateUnsubscribers)t();this._stateUnsubscribers=[];for(let t of this._plugins)t.destroy();this._plugins=[];for(let t of this._behaviors)t.destroy();this._behaviors=[],this._engine.destroy(),this._state.destroy(),this._dropZoneManager.destroy(),this._observer?.disconnect(),this._observer=null,this._scrollHandler&&(window.removeEventListener("scroll",this._scrollHandler,!0),this._scrollHandler=null),this._resizeHandler&&(window.removeEventListener("resize",this._resizeHandler),this._resizeHandler=null),this._imperativeDraggables.clear(),this._imperativeDropZones.clear()}refresh(){this._scanDeclarativeElements(),c.invalidateAll()}addDraggable(t,e){this._imperativeDraggables.set(t,e??{})}removeDraggable(t){this._imperativeDraggables.delete(t)}addDropZone(t,e){this._imperativeDropZones.set(t,e??{}),this._dropZoneManager.register(t,e)}removeDropZone(t){this._imperativeDropZones.delete(t),this._dropZoneManager.unregister(t)}isDragging(){return this._state.isDragging()}getActiveElement(){return this._state.getActiveElement()}use(t){return this._plugins.push(t),t.init(this),this}addBehavior(t){return this._behaviors.push(t),this}setOptions(t){t.draggableSelector&&(t.draggableSelector=g(t.draggableSelector,this._options.draggableSelector??"[data-draggable]")),t.dropZoneSelector&&(t.dropZoneSelector=g(t.dropZoneSelector,this._options.dropZoneSelector??"[data-droppable]")),t.handleSelector&&(t.handleSelector=g(t.handleSelector,this._options.handleSelector??"[data-drag-handle]")),_(this._options,t),this._engine.updateOptions(this._options)}_getDropZones(){let t=this._options.dropZoneSelector??"[data-droppable]",e=this._container instanceof ShadowRoot?this._container:this._container,n=Array.from(e.querySelectorAll(t)),o=[...this._imperativeDropZones.keys()];return[...new Set([...n,...o])]}_getItemData(t){return this._imperativeDraggables.get(t)?.data}_getItemAxis(t){let e=this._imperativeDraggables.get(t);if(e?.axis)return e.axis;let n=t.dataset.dragAxis;if(n==="x"||n==="y"||n==="both")return n}_scanDeclarativeElements(){let t=this._options.dropZoneSelector??"[data-droppable]",n=(this._container instanceof ShadowRoot?this._container:this._container).querySelectorAll(t);for(let o of n)this._imperativeDropZones.has(o)||this._dropZoneManager.register(o)}_setupStateListeners(){this._stateUnsubscribers.push(this._state.subscribe("dragstart",t=>{for(let e of this._behaviors)e.onDragStart?.(t)})),this._stateUnsubscribers.push(this._state.subscribe("dragmove",t=>{for(let e of this._behaviors)e.onDragMove?.(t)})),this._stateUnsubscribers.push(this._state.subscribe("dragend",t=>{for(let e of this._behaviors)e.onDragEnd?.(t)}))}_setupAutoRefresh(){this._observer=new MutationObserver(e=>{if(this._destroyed)return;let n=!1;for(let o of e)if(o.type==="childList"){n=!0;break}n&&!this._refreshScheduled&&(this._refreshScheduled=!0,requestAnimationFrame(()=>{this._destroyed||(this._refreshScheduled=!1,this.refresh())}))});let t=this._container instanceof ShadowRoot?this._container:this._container;this._observer.observe(t,{childList:!0,subtree:!0})}_setupScrollResize(){this._scrollHandler=()=>{this._state.isDragging()&&c.invalidateAll()},window.addEventListener("scroll",this._scrollHandler,!0),this._resizeHandler=()=>{c.invalidateAll()},window.addEventListener("resize",this._resizeHandler)}},Q=C;var he={animation:150,ghostClass:"snap-sortable-ghost",placeholderClass:"snap-sortable-placeholder"},F=class{constructor(t={}){this.name="sortable";this._snap=null;this._placeholder=null;this._originalIndex=-1;this._currentIndex=-1;this._container=null;this._items=[];this._unsubscribers=[];this._options=_({},he,t)}init(t){this._snap=t;let e=t.options.onDragStart,n=t.options.onDragMove,o=t.options.onDrop,i=t.options.onDragEnd;t.setOptions({onDragStart:s=>(this._onDragStart(s.element),e?.(s)),onDragMove:s=>{this._onDragMove(s.position.x,s.position.y),n?.(s)},onDrop:s=>{let p={...s,insertionIndex:this._currentIndex,sourceContainer:this._container??void 0};o?.(p)},onDragEnd:s=>{this._onDragEnd(),i?.(s)}})}destroy(){this._cleanup();for(let t of this._unsubscribers)t();this._unsubscribers=[],this._snap=null}_onDragStart(t){if(this._container=t.parentElement,!this._container)return;let e=this._snap?.options.draggableSelector??"[data-draggable]";this._items=Array.from(this._container.querySelectorAll(e)),this._originalIndex=this._items.indexOf(t),this._currentIndex=this._originalIndex,this._originalIndex!==-1&&(this._createPlaceholder(t),this._options.ghostClass&&t.classList.add(this._options.ghostClass))}_onDragMove(t,e){if(!this._placeholder||!this._container)return;let n=this._snap?.options.draggableSelector??"[data-draggable]",o=this._snap?.getActiveElement(),i=Array.from(this._container.querySelectorAll(n)).filter(h=>h!==o&&h!==this._placeholder);if(i.length===0){this._currentIndex=0;return}let s=c.get(i[0]),p=c.get(i[i.length-1]),l=Math.abs(p.top-s.top)>Math.abs(p.left-s.left),a=i.length;for(let h=0;h<i.length;h++){let d=c.get(i[h]),u=v(d);if(l){if(e<u.y){a=h;break}}else if(t<u.x){a=h;break}}a>this._originalIndex&&a++,a!==this._currentIndex&&(this._currentIndex=a,this._movePlaceholder(a))}_onDragEnd(){this._cleanup()}_createPlaceholder(t){let e=t.getBoundingClientRect();this._placeholder=document.createElement("div"),this._placeholder.className=this._options.placeholderClass??"",this._placeholder.style.cssText=`
13
+ width: ${e.width}px;
14
+ height: ${e.height}px;
15
15
  margin: 0;
16
16
  box-sizing: border-box;
17
- `,e.parentNode?.insertBefore(this._placeholder,e)}_movePlaceholder(e){if(!this._placeholder||!this._container)return;let t=this._snap?.options.draggableSelector??"[data-draggable]",n=this._snap?.getActiveElement(),o=Array.from(this._container.querySelectorAll(t)).filter(i=>i!==n);if(this._placeholder.remove(),e>=o.length)this._container.appendChild(this._placeholder);else{let i=o[e];i===this._placeholder&&(i=o[e+1]),i?this._container.insertBefore(this._placeholder,i):this._container.appendChild(this._placeholder)}this._options.animation&&this._options.animation>0&&this._animateItems()}_animateItems(){if(!this._container)return;let e=this._snap?.options.draggableSelector??"[data-draggable]",t=this._snap?.getActiveElement(),n=Array.from(this._container.querySelectorAll(e)).filter(i=>i!==t&&i!==this._placeholder),o=new Map;for(let i of n)o.set(i,i.getBoundingClientRect());this._container.offsetHeight;for(let i of n){let s=o.get(i),a=i.getBoundingClientRect();if(!s)continue;let p=s.left-a.left,l=s.top-a.top;(p!==0||l!==0)&&(i.style.transform=`translate(${p}px, ${l}px)`,i.style.transition="none",requestAnimationFrame(()=>{i.style.transition=`transform ${this._options.animation}ms ease`,i.style.transform=""}))}}_cleanup(){this._placeholder?.remove(),this._placeholder=null;let e=this._snap?.getActiveElement();e&&this._options.ghostClass&&e.classList.remove(this._options.ghostClass),this._container=null,this._items=[],this._originalIndex=-1,this._currentIndex=-1,h.invalidateAll()}getCurrentIndex(){return this._currentIndex}getOriginalIndex(){return this._originalIndex}};var et={containers:"[data-droppable]",items:"[data-draggable]",animation:150},O=class{constructor(e={}){this.name="kanban";this._snap=null;this._sourceContainer=null;this._targetContainer=null;this._placeholder=null;this._originalIndex=-1;this._currentIndex=-1;this._options={...et,...e}}init(e){this._snap=e;let t=e.options.onDragStart,n=e.options.onDragMove,o=e.options.onDropZoneEnter,i=e.options.onDropZoneLeave,s=e.options.onDrop,a=e.options.onDragEnd;e.setOptions({onDragStart:p=>(this._onDragStart(p.element),t?.(p)),onDragMove:p=>{this._onDragMove(p.position),n?.(p)},onDropZoneEnter:p=>{this._onDropZoneEnter(p.dropZone),o?.(p)},onDropZoneLeave:p=>{this._onDropZoneLeave(p.dropZone),i?.(p)},onDrop:p=>{let l={...p,insertionIndex:this._currentIndex,sourceContainer:this._sourceContainer??void 0};s?.(l)},onDragEnd:p=>{this._onDragEnd(),a?.(p)}})}destroy(){this._cleanup(),this._snap=null}_onDragStart(e){if(this._sourceContainer=e.closest(this._options.containers),!this._sourceContainer)return;let t=Array.from(this._sourceContainer.querySelectorAll(this._options.items));this._originalIndex=t.indexOf(e),this._createPlaceholder(e)}_onDragMove(e){if(!this._targetContainer||!this._placeholder)return;let t=this._calculateInsertionIndex(this._targetContainer,e.x,e.y);t!==this._currentIndex&&(this._currentIndex=t,this._movePlaceholder(t))}_onDropZoneEnter(e){e.matches(this._options.containers)&&(this._targetContainer=e,this._targetContainer.classList.add("snap-kanban-target"),this._placeholder&&(this._targetContainer.appendChild(this._placeholder),this._currentIndex=this._getItemCount(this._targetContainer)))}_onDropZoneLeave(e){e===this._targetContainer&&(e.classList.remove("snap-kanban-target"),this._placeholder?.remove(),this._targetContainer=null,this._currentIndex=-1)}_onDragEnd(){this._cleanup()}_createPlaceholder(e){let t=e.getBoundingClientRect();this._placeholder=document.createElement("div"),this._placeholder.className="snap-kanban-placeholder",this._placeholder.style.cssText=`
18
- width: ${t.width}px;
19
- height: ${t.height}px;
17
+ `,t.parentNode?.insertBefore(this._placeholder,t)}_movePlaceholder(t){if(!this._placeholder||!this._container)return;let e=this._snap?.options.draggableSelector??"[data-draggable]",n=this._snap?.getActiveElement(),o=Array.from(this._container.querySelectorAll(e)).filter(i=>i!==n);if(this._placeholder.remove(),t>=o.length)this._container.appendChild(this._placeholder);else{let i=o[t];i===this._placeholder&&(i=o[t+1]),i?this._container.insertBefore(this._placeholder,i):this._container.appendChild(this._placeholder)}this._options.animation&&this._options.animation>0&&this._animateItems()}_animateItems(){if(!this._container)return;let t=this._snap?.options.draggableSelector??"[data-draggable]",e=this._snap?.getActiveElement(),n=Array.from(this._container.querySelectorAll(t)).filter(i=>i!==e&&i!==this._placeholder),o=new Map;for(let i of n)o.set(i,i.getBoundingClientRect());this._container.offsetHeight;for(let i of n){let s=o.get(i),p=i.getBoundingClientRect();if(!s)continue;let l=s.left-p.left,a=s.top-p.top;(l!==0||a!==0)&&(i.style.transform=`translate(${l}px, ${a}px)`,i.style.transition="none",requestAnimationFrame(()=>{i.style.transition=`transform ${this._options.animation}ms ease`,i.style.transform=""}))}}_cleanup(){this._placeholder?.remove(),this._placeholder=null;let t=this._snap?.getActiveElement();t&&this._options.ghostClass&&t.classList.remove(this._options.ghostClass),this._container=null,this._items=[],this._originalIndex=-1,this._currentIndex=-1,c.invalidateAll()}getCurrentIndex(){return this._currentIndex}getOriginalIndex(){return this._originalIndex}};var ue={containers:"[data-droppable]",items:"[data-draggable]",animation:150},R=class{constructor(t={}){this.name="kanban";this._snap=null;this._sourceContainer=null;this._targetContainer=null;this._placeholder=null;this._originalIndex=-1;this._currentIndex=-1;let e=_({},ue,t);e.containers=g(e.containers,"[data-droppable]"),e.items=g(e.items,"[data-draggable]"),this._options=e}init(t){this._snap=t;let e=t.options.onDragStart,n=t.options.onDragMove,o=t.options.onDropZoneEnter,i=t.options.onDropZoneLeave,s=t.options.onDrop,p=t.options.onDragEnd;t.setOptions({onDragStart:l=>(this._onDragStart(l.element),e?.(l)),onDragMove:l=>{this._onDragMove(l.position),n?.(l)},onDropZoneEnter:l=>{this._onDropZoneEnter(l.dropZone),o?.(l)},onDropZoneLeave:l=>{this._onDropZoneLeave(l.dropZone),i?.(l)},onDrop:l=>{let a={...l,insertionIndex:this._currentIndex,sourceContainer:this._sourceContainer??void 0};s?.(a)},onDragEnd:l=>{this._onDragEnd(),p?.(l)}})}destroy(){this._cleanup(),this._snap=null}_onDragStart(t){if(this._sourceContainer=t.closest(this._options.containers),!this._sourceContainer)return;let e=Array.from(this._sourceContainer.querySelectorAll(this._options.items));this._originalIndex=e.indexOf(t),this._createPlaceholder(t)}_onDragMove(t){if(!this._targetContainer||!this._placeholder)return;let e=this._calculateInsertionIndex(this._targetContainer,t.x,t.y);e!==this._currentIndex&&(this._currentIndex=e,this._movePlaceholder(e))}_onDropZoneEnter(t){t.matches(this._options.containers)&&(this._targetContainer=t,this._targetContainer.classList.add("snap-kanban-target"),this._placeholder&&(this._targetContainer.appendChild(this._placeholder),this._currentIndex=this._getItemCount(this._targetContainer)))}_onDropZoneLeave(t){t===this._targetContainer&&(t.classList.remove("snap-kanban-target"),this._placeholder?.remove(),this._targetContainer=null,this._currentIndex=-1)}_onDragEnd(){this._cleanup()}_createPlaceholder(t){let e=t.getBoundingClientRect();this._placeholder=document.createElement("div"),this._placeholder.className="snap-kanban-placeholder",this._placeholder.style.cssText=`
18
+ width: ${e.width}px;
19
+ height: ${e.height}px;
20
20
  margin: 0;
21
21
  box-sizing: border-box;
22
22
  opacity: 0.5;
23
23
  border: 2px dashed #ccc;
24
24
  border-radius: 4px;
25
25
  background: rgba(0, 0, 0, 0.05);
26
- `,e.parentNode?.insertBefore(this._placeholder,e)}_movePlaceholder(e){if(!this._placeholder||!this._targetContainer)return;let t=this._snap?.getActiveElement(),n=Array.from(this._targetContainer.querySelectorAll(this._options.items)).filter(o=>o!==t&&o!==this._placeholder);if(this._placeholder.remove(),e>=n.length)this._targetContainer.appendChild(this._placeholder);else{let o=n[e];o?this._targetContainer.insertBefore(this._placeholder,o):this._targetContainer.appendChild(this._placeholder)}this._options.animation>0&&this._animateItems(this._targetContainer)}_calculateInsertionIndex(e,t,n){let o=this._snap?.getActiveElement(),i=Array.from(e.querySelectorAll(this._options.items)).filter(l=>l!==o&&l!==this._placeholder);if(i.length===0)return 0;let s=h.get(i[0]),a=h.get(i[i.length-1]),p=Math.abs(a.top-s.top)>Math.abs(a.left-s.left);for(let l=0;l<i.length;l++){let d=h.get(i[l]),c=g(d);if(p){if(n<c.y)return l}else if(t<c.x)return l}return i.length}_getItemCount(e){let t=this._snap?.getActiveElement();return Array.from(e.querySelectorAll(this._options.items)).filter(n=>n!==t&&n!==this._placeholder).length}_animateItems(e){let t=this._snap?.getActiveElement(),n=Array.from(e.querySelectorAll(this._options.items)).filter(i=>i!==t&&i!==this._placeholder),o=new Map;for(let i of n)o.set(i,i.getBoundingClientRect());e.offsetHeight;for(let i of n){let s=o.get(i),a=i.getBoundingClientRect();if(!s)continue;let p=s.left-a.left,l=s.top-a.top;(p!==0||l!==0)&&(i.style.transform=`translate(${p}px, ${l}px)`,i.style.transition="none",requestAnimationFrame(()=>{i.style.transition=`transform ${this._options.animation}ms ease`,i.style.transform=""}))}}_cleanup(){this._placeholder?.remove(),this._placeholder=null,this._sourceContainer?.classList.remove("snap-kanban-source"),this._targetContainer?.classList.remove("snap-kanban-target"),this._sourceContainer=null,this._targetContainer=null,this._originalIndex=-1,this._currentIndex=-1,h.invalidateAll()}getSourceContainer(){return this._sourceContainer}getTargetContainer(){return this._targetContainer}getCurrentIndex(){return this._currentIndex}};var T=class extends _{constructor(t){super();this._attached=!1;this._dragCount=0;this._currentDropZone=null;this._onDragEnter=t=>{if(!this._hasFiles(t))return;this._dragCount++;let n=this._findDropZone(t);n&&(t.preventDefault(),n!==this._currentDropZone&&(this._currentDropZone&&this.emit("dragleave",{position:{x:t.clientX,y:t.clientY},dropZone:this._currentDropZone,originalEvent:t}),this._currentDropZone=n,this.emit("dragenter",{position:{x:t.clientX,y:t.clientY},dropZone:n,originalEvent:t})))};this._onDragOver=t=>{if(!this._hasFiles(t))return;let n=this._findDropZone(t);n&&(t.preventDefault(),t.dataTransfer&&(t.dataTransfer.dropEffect="copy"),this.emit("dragover",{position:{x:t.clientX,y:t.clientY},dropZone:n,originalEvent:t}))};this._onDragLeave=t=>{this._hasFiles(t)&&(this._dragCount--,this._dragCount===0&&this._currentDropZone&&(this.emit("dragleave",{position:{x:t.clientX,y:t.clientY},dropZone:this._currentDropZone,originalEvent:t}),this._currentDropZone=null))};this._onDrop=t=>{t.preventDefault(),this._dragCount=0;let n=this._findDropZone(t);if(!n)return;let o=this._getFiles(t);o.length!==0&&(this.emit("drop",{files:o,position:{x:t.clientX,y:t.clientY},dropZone:n,originalEvent:t}),this._currentDropZone=null)};this._container=t.container,this._options=t}attach(){if(this._attached)return;let t=this._getEventTarget();t.addEventListener("dragenter",this._onDragEnter,{passive:!1}),t.addEventListener("dragover",this._onDragOver,{passive:!1}),t.addEventListener("dragleave",this._onDragLeave,{passive:!1}),t.addEventListener("drop",this._onDrop,{passive:!1}),this._attached=!0}detach(){if(!this._attached)return;let t=this._getEventTarget();t.removeEventListener("dragenter",this._onDragEnter),t.removeEventListener("dragover",this._onDragOver),t.removeEventListener("dragleave",this._onDragLeave),t.removeEventListener("drop",this._onDrop),this._dragCount=0,this._currentDropZone=null,this._attached=!1}_getEventTarget(){return this._container instanceof ShadowRoot?this._container.host:this._container}_findDropZone(t){let n=t.target,o=t.composedPath();for(let i of o)if(i instanceof HTMLElement){if(i.matches(this._options.dropZoneSelector))return i;if(i===this._container||i===this._container.host)break}return n.closest?.(this._options.dropZoneSelector)}_hasFiles(t){if(!t.dataTransfer)return!1;let n=t.dataTransfer.types;return n.includes("Files")||n.includes("application/x-moz-file")}_getFiles(t){if(!t.dataTransfer?.files)return[];let n=Array.from(t.dataTransfer.files),o=this._options.accept;o&&o.length>0&&(n=n.filter(s=>this._matchesAccept(s,o)));let i=this._options.maxSize;return i&&i>0&&(n=n.filter(s=>s.size<=i)),!this._options.multiple&&n.length>1&&(n=[n[0]]),n}_matchesAccept(t,n){for(let o of n){if(o.startsWith(".")){if(t.name.toLowerCase().endsWith(o.toLowerCase()))return!0;continue}if(o.endsWith("/*")){let i=o.slice(0,-1);if(t.type.startsWith(i))return!0;continue}if(t.type===o)return!0}return!1}destroy(){this.detach(),super.destroy()}};var nt={multiple:!0},Z=class{constructor(e={}){this.name="file-drop";this._snap=null;this._sensor=null;this._onFileDrop=null;this._options={...nt,...e}}init(e){this._snap=e;let t=this._getContainer();t&&(this._sensor=new T({container:t,dropZoneSelector:e.options.dropZoneSelector??"[data-file-drop]",accept:this._options.accept,multiple:this._options.multiple,maxSize:this._options.maxSize}),this._setupEventHandlers(),this._sensor.attach())}destroy(){this._sensor?.destroy(),this._sensor=null,this._snap=null,this._onFileDrop=null}onFileDrop(e){return this._onFileDrop=e,this}setOptions(e){Object.assign(this._options,e)}_getContainer(){return this._snap?this._snap._container:null}_setupEventHandlers(){this._sensor&&(this._sensor.on("dragenter",e=>{e.dropZone.classList.add("snap-file-drag-over")}),this._sensor.on("dragleave",e=>{e.dropZone.classList.remove("snap-file-drag-over")}),this._sensor.on("drop",e=>{e.dropZone.classList.remove("snap-file-drag-over");let t={files:e.files,position:e.position,dropZone:e.dropZone};this._onFileDrop?.(t),this._snap?.options?.onFileDrop?.(t)}))}};function U(r,e){let{onDrop:t,onDragEnter:n,onDragLeave:o,...i}=e,s=0,a=c=>{z(c)&&(c.preventDefault(),s++,s===1&&(r.classList.add("snap-file-drag-over"),n?.()))},p=c=>{z(c)&&(c.preventDefault(),c.dataTransfer&&(c.dataTransfer.dropEffect="copy"))},l=c=>{z(c)&&(s--,s===0&&(r.classList.remove("snap-file-drag-over"),o?.()))},d=c=>{c.preventDefault(),s=0,r.classList.remove("snap-file-drag-over");let u=Array.from(c.dataTransfer?.files??[]);i.accept?.length&&(u=u.filter(M=>it(M,i.accept))),i.maxSize&&(u=u.filter(M=>M.size<=i.maxSize)),!i.multiple&&u.length>1&&(u=[u[0]]),u.length>0&&t(u)};return r.addEventListener("dragenter",a),r.addEventListener("dragover",p),r.addEventListener("dragleave",l),r.addEventListener("drop",d),()=>{r.removeEventListener("dragenter",a),r.removeEventListener("dragover",p),r.removeEventListener("dragleave",l),r.removeEventListener("drop",d),r.classList.remove("snap-file-drag-over")}}function z(r){if(!r.dataTransfer)return!1;let e=r.dataTransfer.types;return e.includes("Files")||e.includes("application/x-moz-file")}function it(r,e){for(let t of e){if(t.startsWith(".")){if(r.name.toLowerCase().endsWith(t.toLowerCase()))return!0;continue}if(t.endsWith("/*")){let n=t.slice(0,-1);if(r.type.startsWith(n))return!0;continue}if(r.type===t)return!0}return!1}var ot={threshold:40,maxSpeed:15,acceleration:2},w=class{constructor(e={}){this.name="auto-scroll";this._scrollableAncestors=[];this._rafId=null;this._active=!1;this._options={...ot,...e}}onDragStart(e){this._scrollableAncestors=this._findScrollableAncestors(e.element),this._active=!0}onDragMove(e){!this._active||this._rafId!==null||(this._rafId=requestAnimationFrame(()=>{this._rafId=null,this._performScroll(e.current.x,e.current.y)}))}onDragEnd(){this._active=!1,this._scrollableAncestors=[],this._rafId!==null&&(cancelAnimationFrame(this._rafId),this._rafId=null)}destroy(){this.onDragEnd()}_performScroll(e,t){for(let n of this._scrollableAncestors){let o=n.getBoundingClientRect(),i=this._calculateScrollSpeed(e,t,o);(i.x!==0||i.y!==0)&&n.scrollBy({left:i.x,top:i.y,behavior:"instant"})}}_calculateScrollSpeed(e,t,n){let{threshold:o,maxSpeed:i}=this._options,s=0,a=0;return e<n.left+o?s=-this._getSpeed(n.left+o-e):e>n.right-o&&(s=this._getSpeed(e-(n.right-o))),t<n.top+o?a=-this._getSpeed(n.top+o-t):t>n.bottom-o&&(a=this._getSpeed(t-(n.bottom-o))),{x:s,y:a}}_getSpeed(e){let{threshold:t,maxSpeed:n,acceleration:o}=this._options,i=Math.min(e/t,1);return Math.pow(i,o)*n}_findScrollableAncestors(e){let t=[],n=e.parentElement;for(;n&&n!==document.body;){let o=getComputedStyle(n),i=o.overflowX,s=o.overflowY,a=(i==="auto"||i==="scroll")&&n.scrollWidth>n.clientWidth,p=(s==="auto"||s==="scroll")&&n.scrollHeight>n.clientHeight;(a||p)&&t.push(n),n=n.parentElement}return(document.documentElement.scrollHeight>window.innerHeight||document.documentElement.scrollWidth>window.innerWidth)&&t.push(document.documentElement),t}};var R=class{constructor(e){this.name="snap-grid";this._guideContainer=null;this._options=e}onDragStart(e){this._options.showGuides&&this._createGuides(e.element)}onDragMove(e){}onDragEnd(){this._removeGuides()}destroy(){this._removeGuides()}snap(e,t){return{x:Math.round(e/this._options.x)*this._options.x,y:Math.round(t/this._options.y)*this._options.y}}snapWithThreshold(e,t,n){let o=n??this._options.threshold??5,i=this.snap(e,t);return{x:Math.abs(e-i.x)<o?i.x:e,y:Math.abs(t-i.y)<o?i.y:t}}_createGuides(e){let t=e.offsetParent||document.body,n=t.getBoundingClientRect();this._guideContainer=document.createElement("div"),this._guideContainer.style.cssText=`
26
+ `,t.parentNode?.insertBefore(this._placeholder,t)}_movePlaceholder(t){if(!this._placeholder||!this._targetContainer)return;let e=this._snap?.getActiveElement(),n=Array.from(this._targetContainer.querySelectorAll(this._options.items)).filter(o=>o!==e&&o!==this._placeholder);if(this._placeholder.remove(),t>=n.length)this._targetContainer.appendChild(this._placeholder);else{let o=n[t];o?this._targetContainer.insertBefore(this._placeholder,o):this._targetContainer.appendChild(this._placeholder)}this._options.animation>0&&this._animateItems(this._targetContainer)}_calculateInsertionIndex(t,e,n){let o=this._snap?.getActiveElement(),i=Array.from(t.querySelectorAll(this._options.items)).filter(a=>a!==o&&a!==this._placeholder);if(i.length===0)return 0;let s=c.get(i[0]),p=c.get(i[i.length-1]),l=Math.abs(p.top-s.top)>Math.abs(p.left-s.left);for(let a=0;a<i.length;a++){let h=c.get(i[a]),d=v(h);if(l){if(n<d.y)return a}else if(e<d.x)return a}return i.length}_getItemCount(t){let e=this._snap?.getActiveElement();return Array.from(t.querySelectorAll(this._options.items)).filter(n=>n!==e&&n!==this._placeholder).length}_animateItems(t){let e=this._snap?.getActiveElement(),n=Array.from(t.querySelectorAll(this._options.items)).filter(i=>i!==e&&i!==this._placeholder),o=new Map;for(let i of n)o.set(i,i.getBoundingClientRect());t.offsetHeight;for(let i of n){let s=o.get(i),p=i.getBoundingClientRect();if(!s)continue;let l=s.left-p.left,a=s.top-p.top;(l!==0||a!==0)&&(i.style.transform=`translate(${l}px, ${a}px)`,i.style.transition="none",requestAnimationFrame(()=>{i.style.transition=`transform ${this._options.animation}ms ease`,i.style.transform=""}))}}_cleanup(){this._placeholder?.remove(),this._placeholder=null,this._sourceContainer?.classList.remove("snap-kanban-source"),this._targetContainer?.classList.remove("snap-kanban-target"),this._sourceContainer=null,this._targetContainer=null,this._originalIndex=-1,this._currentIndex=-1,c.invalidateAll()}getSourceContainer(){return this._sourceContainer}getTargetContainer(){return this._targetContainer}getCurrentIndex(){return this._currentIndex}};var P=class extends f{constructor(e){super();this._attached=!1;this._dragCount=0;this._currentDropZone=null;this._onDragEnter=e=>{if(!this._hasFiles(e))return;this._dragCount++;let n=this._findDropZone(e);n&&(e.preventDefault(),n!==this._currentDropZone&&(this._currentDropZone&&this.emit("dragleave",{position:{x:e.clientX,y:e.clientY},dropZone:this._currentDropZone,originalEvent:e}),this._currentDropZone=n,this.emit("dragenter",{position:{x:e.clientX,y:e.clientY},dropZone:n,originalEvent:e})))};this._onDragOver=e=>{if(!this._hasFiles(e))return;let n=this._findDropZone(e);n&&(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect="copy"),this.emit("dragover",{position:{x:e.clientX,y:e.clientY},dropZone:n,originalEvent:e}))};this._onDragLeave=e=>{this._hasFiles(e)&&(this._dragCount--,this._dragCount===0&&this._currentDropZone&&(this.emit("dragleave",{position:{x:e.clientX,y:e.clientY},dropZone:this._currentDropZone,originalEvent:e}),this._currentDropZone=null))};this._onDrop=e=>{e.preventDefault(),this._dragCount=0;let n=this._findDropZone(e);if(!n)return;let o=this._getFiles(e);o.length!==0&&(this.emit("drop",{files:o,position:{x:e.clientX,y:e.clientY},dropZone:n,originalEvent:e}),this._currentDropZone=null)};this._container=e.container,this._options=e}attach(){if(this._attached)return;let e=this._getEventTarget();e.addEventListener("dragenter",this._onDragEnter,{passive:!1}),e.addEventListener("dragover",this._onDragOver,{passive:!1}),e.addEventListener("dragleave",this._onDragLeave,{passive:!1}),e.addEventListener("drop",this._onDrop,{passive:!1}),this._attached=!0}detach(){if(!this._attached)return;let e=this._getEventTarget();e.removeEventListener("dragenter",this._onDragEnter),e.removeEventListener("dragover",this._onDragOver),e.removeEventListener("dragleave",this._onDragLeave),e.removeEventListener("drop",this._onDrop),this._dragCount=0,this._currentDropZone=null,this._attached=!1}_getEventTarget(){return this._container instanceof ShadowRoot?this._container.host:this._container}_findDropZone(e){let n=e.target,o=e.composedPath();for(let i of o)if(i instanceof HTMLElement){if(i.matches(this._options.dropZoneSelector))return i;if(i===this._container||i===this._container.host)break}return n.closest?.(this._options.dropZoneSelector)}_hasFiles(e){if(!e.dataTransfer)return!1;let n=e.dataTransfer.types;return n.includes("Files")||n.includes("application/x-moz-file")}_getFiles(e){if(!e.dataTransfer?.files)return[];let n=Array.from(e.dataTransfer.files),o=this._options.accept;o&&o.length>0&&(n=n.filter(s=>this._matchesAccept(s,o)));let i=this._options.maxSize;return i&&i>0&&(n=n.filter(s=>s.size<=i)),!this._options.multiple&&n.length>1&&(n=[n[0]]),n}_matchesAccept(e,n){for(let o of n){if(o.startsWith(".")){if(e.name.toLowerCase().endsWith(o.toLowerCase()))return!0;continue}if(o.endsWith("/*")){let i=o.slice(0,-1);if(e.type.startsWith(i))return!0;continue}if(e.type===o)return!0}return!1}destroy(){this.detach(),super.destroy()}};var _e={multiple:!0,secureValidation:!1,validateMagicBytes:!1,minSize:1,maxFiles:100},z=class{constructor(t={}){this.name="file-drop";this._snap=null;this._sensor=null;this._onFileDrop=null;this._options=_({},_e,t)}init(t){this._snap=t;let e=this._getContainer();e&&(this._sensor=new P({container:e,dropZoneSelector:t.options.dropZoneSelector??"[data-file-drop]",accept:this._options.accept,multiple:this._options.multiple,maxSize:this._options.maxSize}),this._setupEventHandlers(),this._sensor.attach())}destroy(){this._sensor?.destroy(),this._sensor=null,this._snap=null,this._onFileDrop=null}onFileDrop(t){return this._onFileDrop=t,this}setOptions(t){_(this._options,t)}_getContainer(){return this._snap?this._snap._container:null}_setupEventHandlers(){this._sensor&&(this._sensor.on("dragenter",t=>{t.dropZone.classList.add("snap-file-drag-over")}),this._sensor.on("dragleave",t=>{t.dropZone.classList.remove("snap-file-drag-over")}),this._sensor.on("drop",async t=>{t.dropZone.classList.remove("snap-file-drag-over");let e=t.files;if(this._options.secureValidation){let i={maxSize:this._options.maxSize,minSize:this._options.minSize,accept:this._options.accept,maxFiles:this._options.maxFiles,validateMagicBytes:this._options.validateMagicBytes},s=await Z(t.files,i);e=s.filter(l=>l.valid).map(l=>l.file);let p=s.filter(l=>!l.valid);if(p.length>0&&this._options.onValidationError&&this._options.onValidationError(p.map(l=>({file:l.file,error:l.error??"Unknown error"}))),e.length===0)return}let n={files:e,position:t.position,dropZone:t.dropZone};this._onFileDrop?.(n),this._snap?.options?.onFileDrop?.(n)}))}};function ee(r,t){let{onDrop:e,onDragEnter:n,onDragLeave:o,...i}=t,s=0,p=d=>{V(d)&&(d.preventDefault(),s++,s===1&&(r.classList.add("snap-file-drag-over"),n?.()))},l=d=>{V(d)&&(d.preventDefault(),d.dataTransfer&&(d.dataTransfer.dropEffect="copy"))},a=d=>{V(d)&&(s--,s===0&&(r.classList.remove("snap-file-drag-over"),o?.()))},h=d=>{d.preventDefault(),s=0,r.classList.remove("snap-file-drag-over");let u=Array.from(d.dataTransfer?.files??[]);i.accept?.length&&(u=u.filter(I=>ge(I,i.accept))),i.maxSize&&(u=u.filter(I=>I.size<=i.maxSize)),!i.multiple&&u.length>1&&(u=[u[0]]),u.length>0&&e(u)};return r.addEventListener("dragenter",p),r.addEventListener("dragover",l),r.addEventListener("dragleave",a),r.addEventListener("drop",h),()=>{r.removeEventListener("dragenter",p),r.removeEventListener("dragover",l),r.removeEventListener("dragleave",a),r.removeEventListener("drop",h),r.classList.remove("snap-file-drag-over")}}function V(r){if(!r.dataTransfer)return!1;let t=r.dataTransfer.types;return t.includes("Files")||t.includes("application/x-moz-file")}function ge(r,t){for(let e of t){if(e.startsWith(".")){if(r.name.toLowerCase().endsWith(e.toLowerCase()))return!0;continue}if(e.endsWith("/*")){let n=e.slice(0,-1);if(r.type.startsWith(n))return!0;continue}if(r.type===e)return!0}return!1}var fe={threshold:40,maxSpeed:15,acceleration:2},k=class{constructor(t={}){this.name="auto-scroll";this._scrollableAncestors=[];this._rafId=null;this._active=!1;this._options={...fe,...t}}onDragStart(t){this._scrollableAncestors=this._findScrollableAncestors(t.element),this._active=!0}onDragMove(t){!this._active||this._rafId!==null||(this._rafId=requestAnimationFrame(()=>{this._rafId=null,this._performScroll(t.current.x,t.current.y)}))}onDragEnd(){this._active=!1,this._scrollableAncestors=[],this._rafId!==null&&(cancelAnimationFrame(this._rafId),this._rafId=null)}destroy(){this.onDragEnd()}_performScroll(t,e){for(let n of this._scrollableAncestors){let o=n.getBoundingClientRect(),i=this._calculateScrollSpeed(t,e,o);(i.x!==0||i.y!==0)&&n.scrollBy({left:i.x,top:i.y,behavior:"instant"})}}_calculateScrollSpeed(t,e,n){let{threshold:o,maxSpeed:i}=this._options,s=0,p=0;return t<n.left+o?s=-this._getSpeed(n.left+o-t):t>n.right-o&&(s=this._getSpeed(t-(n.right-o))),e<n.top+o?p=-this._getSpeed(n.top+o-e):e>n.bottom-o&&(p=this._getSpeed(e-(n.bottom-o))),{x:s,y:p}}_getSpeed(t){let{threshold:e,maxSpeed:n,acceleration:o}=this._options,i=Math.min(t/e,1);return Math.pow(i,o)*n}_findScrollableAncestors(t){let e=[],n=t.parentElement;for(;n&&n!==document.body;){let o=getComputedStyle(n),i=o.overflowX,s=o.overflowY,p=(i==="auto"||i==="scroll")&&n.scrollWidth>n.clientWidth,l=(s==="auto"||s==="scroll")&&n.scrollHeight>n.clientHeight;(p||l)&&e.push(n),n=n.parentElement}return(document.documentElement.scrollHeight>window.innerHeight||document.documentElement.scrollWidth>window.innerWidth)&&e.push(document.documentElement),e}};var B=class{constructor(t){this.name="snap-grid";this._guideContainer=null;this._options=t}onDragStart(t){this._options.showGuides&&this._createGuides(t.element)}onDragMove(t){}onDragEnd(){this._removeGuides()}destroy(){this._removeGuides()}snap(t,e){return{x:Math.round(t/this._options.x)*this._options.x,y:Math.round(e/this._options.y)*this._options.y}}snapWithThreshold(t,e,n){let o=n??this._options.threshold??5,i=this.snap(t,e);return{x:Math.abs(t-i.x)<o?i.x:t,y:Math.abs(e-i.y)<o?i.y:e}}_createGuides(t){let e=t.offsetParent||document.body,n=e.getBoundingClientRect();this._guideContainer=document.createElement("div"),this._guideContainer.style.cssText=`
27
27
  position: absolute;
28
28
  top: 0;
29
29
  left: 0;
@@ -31,19 +31,19 @@
31
31
  bottom: 0;
32
32
  pointer-events: none;
33
33
  z-index: 9998;
34
- `;let o=Math.ceil(n.width/this._options.x);for(let s=1;s<o;s++){let a=document.createElement("div");a.style.cssText=`
34
+ `;let o=Math.ceil(n.width/this._options.x);for(let s=1;s<o;s++){let p=document.createElement("div");p.style.cssText=`
35
35
  position: absolute;
36
36
  left: ${s*this._options.x}px;
37
37
  top: 0;
38
38
  bottom: 0;
39
39
  width: 1px;
40
40
  background: rgba(0, 120, 255, 0.2);
41
- `,this._guideContainer.appendChild(a)}let i=Math.ceil(n.height/this._options.y);for(let s=1;s<i;s++){let a=document.createElement("div");a.style.cssText=`
41
+ `,this._guideContainer.appendChild(p)}let i=Math.ceil(n.height/this._options.y);for(let s=1;s<i;s++){let p=document.createElement("div");p.style.cssText=`
42
42
  position: absolute;
43
43
  top: ${s*this._options.y}px;
44
44
  left: 0;
45
45
  right: 0;
46
46
  height: 1px;
47
47
  background: rgba(0, 120, 255, 0.2);
48
- `,this._guideContainer.appendChild(a)}t.appendChild(this._guideContainer)}_removeGuides(){this._guideContainer?.remove(),this._guideContainer=null}};var F=class{constructor(e={}){this.name="constraint-axis";this._bounds=null;this._options=e}onDragStart(e){this._options.containWithinParent?this._calculateParentBounds(e.element):this._options.bounds&&(this._bounds={minX:this._options.bounds.minX??-1/0,maxX:this._options.bounds.maxX??1/0,minY:this._options.bounds.minY??-1/0,maxY:this._options.bounds.maxY??1/0})}onDragMove(e){}onDragEnd(){this._bounds=null}destroy(){this._bounds=null}constrain(e,t){let{x:n,y:o}=e,i=this._options.axis??"both";return i==="x"?o=t.y:i==="y"&&(n=t.x),this._bounds&&(n=Math.max(this._bounds.minX,Math.min(this._bounds.maxX,n)),o=Math.max(this._bounds.minY,Math.min(this._bounds.maxY,o))),{x:n,y:o}}getBounds(){return this._bounds}_calculateParentBounds(e){let t=e.parentElement;if(!t)return;let n=t.getBoundingClientRect(),o=e.getBoundingClientRect();this._bounds={minX:n.left,maxX:n.right-o.width,minY:n.top,maxY:n.bottom-o.height}}};return J(st);})();
48
+ `,this._guideContainer.appendChild(p)}e.appendChild(this._guideContainer)}_removeGuides(){this._guideContainer?.remove(),this._guideContainer=null}};var q=class{constructor(t={}){this.name="constraint-axis";this._bounds=null;this._options=t}onDragStart(t){this._options.containWithinParent?this._calculateParentBounds(t.element):this._options.bounds&&(this._bounds={minX:this._options.bounds.minX??-1/0,maxX:this._options.bounds.maxX??1/0,minY:this._options.bounds.minY??-1/0,maxY:this._options.bounds.maxY??1/0})}onDragMove(t){}onDragEnd(){this._bounds=null}destroy(){this._bounds=null}constrain(t,e){let{x:n,y:o}=t,i=this._options.axis??"both";return i==="x"?o=e.y:i==="y"&&(n=e.x),this._bounds&&(n=Math.max(this._bounds.minX,Math.min(this._bounds.maxX,n)),o=Math.max(this._bounds.minY,Math.min(this._bounds.maxY,o))),{x:n,y:o}}getBounds(){return this._bounds}_calculateParentBounds(t){let e=t.parentElement;if(!e)return;let n=e.getBoundingClientRect(),o=t.getBoundingClientRect();this._bounds={minX:n.left,maxX:n.right-o.width,minY:n.top,maxY:n.bottom-o.height}}};return se(me);})();
49
49
  //# sourceMappingURL=snap.umd.js.map