(function(n){[window.GamefaceDnD,window.DataTransfer]=n(window)})(function(){class n{constructor(t,e){this._data=t,this._kind="string",this._type=e}get data(){return this._data}set data(t){this._data=t}get kind(){return this._kind}set kind(t){this._kind=t}get type(){return this._type}set type(t){this._type=t}getAsString(t){this.kind==="string"&&t(this._data.toString())}}class o extends Array{constructor(){super()}hasDataForType(t){return this.some(e=>e.type===t)}add(t,e="text/plain"){if(this.hasDataForType(e)){console.log(`Failed to execute 'add' on 'DataTransferItemList': An item already exists for type '${e}'`);return}const r=new n(t,e);return this.push(r),r}remove(t){t===-1||t>this._length-1||this.splice(t,1)}clear(){this.splice(0,this.length)}}class i{constructor(){this._dropEffect="",this._effectAllowed="",this._items=new o}get dropEffect(){return this._dropEffect}set dropEffect(t){this._dropEffect=t}get effectAllowed(){return this._effectAllowed}set effectAllowed(t){this._effectAllowed=t}get items(){return this._items}set items(t){console.error("Cannot set readonly property items!")}get types(){return this.items.map(t=>t.type)}set types(t){console.error("Cannot set readonly property types!")}clearData(t){const e=this.types.indexOf(t);e>-1&&this._items.splice(e,1)}setData(t,e){const r=this.types.indexOf(t);r>-1?this.items[r]=new n(e,t):this.items.push(new n(e,t))}getData(t){const e=this.types.indexOf(t);return e===-1||!this.items[e].data?"":this.items[e].data}}class d{constructor(){this.dragging=!1,this.dragTarget,this.overDropzone=!1,this.onMouseMoveBound=t=>this.onMouseMove(t),this.onMouseDownBound=t=>this.onMouseDown(t),this.onMouseUpBound=t=>this.onMouseUp(t)}createDragAndDropEvent(t){const e=new CustomEvent(t,{bubbles:!0});return e.dataTransfer=this.dataTransfer,e}callOnDragEventHandler(t,e){const r=`on${t.type}`;e.hasAttribute(r)&&typeof e[r]=="function"&&e[r](t)}isDraggable(t){return t.getAttribute("draggable")==="true"}cancelsEvent(t,e){return t.classList.contains("dropzone")}isDropzone(t){return this.cancelsEvent(t,"ondragover")||this.cancelsEvent(t,"ondragenter")}dragLeave(){this.overDropzone=!1;const t=this.createDragAndDropEvent("dragleave");this.dragoverTarget.dispatchEvent(t),this.callOnDragEventHandler(t,this.dragoverTarget),this.dragoverTarget=null}dragEnter(t){this.overDropzone=!0,this.dragoverTarget=t;const e=this.createDragAndDropEvent("dragenter");t.dispatchEvent(e),this.callOnDragEventHandler(e,t)}onMouseMove(t){if(!this.dragging){this.dataTransfer=new i;const s=this.createDragAndDropEvent("dragstart");this.dragTarget.dispatchEvent(s),this.callOnDragEventHandler(s,this.dragTarget)}this.dragging=this.dragging||!0;const e=t.target;if(!this.overDropzone&&this.isDropzone(e)&&this.dragEnter(e),this.overDropzone&&this.isDropzone(e)&&e!==this.dragoverTarget&&(this.dragLeave(),this.dragEnter(e)),this.overDropzone&&!this.isDropzone(e)&&this.dragLeave(),this.overDropzone){const s=this.createDragAndDropEvent("dragover");e.dispatchEvent(s),this.callOnDragEventHandler(s,e)}const r=this.createDragAndDropEvent("drag");this.dragTarget.dispatchEvent(r),this.callOnDragEventHandler(r,this.dragTarget)}onMouseDown(t){const e=t.target;this.isDraggable(e)&&(this.dragTarget=e,document.addEventListener("mousemove",this.onMouseMoveBound))}onMouseUp(t){const e=t.target;if(this.dragging){if(this.isDropzone(e)){const s=this.createDragAndDropEvent("drop");e.dispatchEvent(s),this.callOnDragEventHandler(s,e)}const r=this.createDragAndDropEvent("dragend");this.dragTarget.dispatchEvent(r),this.callOnDragEventHandler(r,this.dragTarget)}document.removeEventListener("mousemove",this.onMouseMoveBound),this.dragging=!1}enableDrag(t){t.addEventListener("mousedown",this.onMouseDownBound),document.addEventListener("mouseup",this.onMouseUpBound)}}return[new d,i]});
