0===document.querySelectorAll('link[href*="resizer.css"], style[src*="resizer.css"]').length&&fetch("https://raw.githubusercontent.com/developergovindgupta/move-rotate-resizer/master/resizer.css").then(e=>{e.ok?e.text().then(e=>{let t=document.createElement("style");t.setAttribute("type","text/css"),t.setAttribute("src","resizer.css"),t.innerHTML=e,document.head.appendChild(t)}):console.info("download resizer.css and include in index.html")}).catch(e=>{console.log(e)});const resizer={target:null,resizer:null,hoverLine:null,add(e,t){if(this.target=e,e){let s={minWidth:30,minHeight:30,aspectRatio:!0,resizeFromCenter:!1,onDragStart:null,onDragging:null,onDragEnd:null,onResizeStart:null,onResizing:null,onResizeEnd:null,onRotateStart:null,onRotating:null,onRotateEnd:null,onResizerShown:null,onResizerHide:null,isHideOnResize:!0,isHoverLine:!0,boundWithContainer:!1,resizers:{n:!0,s:!0,e:!0,w:!0,ne:!0,nw:!0,se:!0,sw:!0,r:!0}},r=e=>{let t=0;if(e){if(t=parseFloat(e.angle),isNaN(t)){t=0;let s=window.getComputedStyle(e).transform;if(s&&"none"!=s){let e=s.split("(")[1].split(")")[0].split(","),r=e[0],i=e[1],o=Math.atan2(i,r);(t=parseInt(o*(180/Math.PI)))<0&&(t=360+t)}}e.angle=t}return t};t=t||{},e.options={...s,...t},e.options.resizers={...e.options.resizers},e.style.position="absolute",e.style.left=e.offsetLeft+"px",e.style.top=e.offsetTop+"px",e.style.width=e.offsetWidth+"px",e.style.height=e.offsetHeight+"px",e.angle=r(e),e.resizer=!0,e.isDisabled="true"===e.getAttribute("isDisabled"),e.isDisabled&&(e.resizer=!1);let i=this.show(e);e.bBox=i,e.scale=i.width/e.offsetWidth,e.moveCounter=0,e.resizer=this.resizer,document.querySelector(".resizer-container")||document.body.appendChild(e.resizer);let o=t=>{if("mousedown"===t.type&&(t.preventDefault(),0!=t.button))return;if(t.stopPropagation(),e.isDisabled="true"===e.getAttribute("isDisabled"),e.isDisabled&&(e.resizer=!1,this.hide()),e.isLocked="true"===e.getAttribute("islocked"),e.startPos={x:t.clientX+document.body.scrollLeft,y:t.clientY+document.body.scrollTop},e.size={left:e.offsetLeft,top:e.offsetTop,width:e.offsetWidth,height:e.offsetHeight},e.isLocked||e.isDisabled||(document.addEventListener("mousemove",n),document.addEventListener("mouseup",a),document.addEventListener("touchmove",n),document.addEventListener("touchend",a)),"touchstart"===t.type){if(t.touches.length>1)return;e.startPos={x:t.touches[0].clientX+document.body.scrollLeft,y:t.touches[0].clientY+document.body.scrollTop}}e.resizer&&(e.resizer.visibile=!1),this.show(e),this.target=e;let s=t=>{t.stopPropagation(),t.preventDefault(),this.show(e),window.removeEventListener("click",s,!0)};window.addEventListener("click",s,!0),e.moveCounter=0,this.hoverLine&&(this.hoverLine.style.opacity="0")},n=s=>{s.stopPropagation(),"mousemove"===s.type&&s.preventDefault(),e.moveCounter++,1===e.moveCounter&&(s.size={...e.size},s.angle=e.angle,s.evtTarget=e,s.handler=this.resizer,e.options.onDragStart&&e.options.onDragStart(s),e.resizer&&e.resizer.showHideResizer&&e.resizer.showHideResizer(!0));let r=s.clientX+document.body.scrollLeft-e.startPos.x,i=s.clientY+document.body.scrollTop-e.startPos.y;"touchmove"===s.type&&(r=s.touches[0].clientX+document.body.scrollLeft-e.startPos.x,i=s.touches[0].clientY+document.body.scrollTop-e.startPos.y);let o=e.size.left+r/e.scale,n=e.size.top+i/e.scale;if(e.style.left=o+"px",e.style.top=n+"px",t.boundWithContainer){let s=t.boundWithContainer instanceof HTMLDivElement?t.boundWithContainer:e.offsetParent;if(s){let t=s.getBoundingClientRect(),r=e.getBoundingClientRect();if(r.leftt.right){o+=(t.right-r.right)/e.scale}if(r.bottom>t.bottom){n+=(t.bottom-r.bottom)/e.scale}e.style.left=o+"px",e.style.top=n+"px"}}e.newSize={...e.size,left:o,top:n},e.options.onDragging&&(s.size={...e.newSize},s.angle=e.angle,s.evtTarget=e,s.handler=this.resizer,e.options.onDragging(s)),this.show(e)},a=t=>{t.stopPropagation(),"mouseup"===t.type&&t.preventDefault(),document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",a),document.removeEventListener("touchmove",n),document.removeEventListener("touchend",a),e.resizer.showHideResizer(!1),e.moveCounter&&e.options.onDragEnd&&(t.size={...e.newSize},t.angle=e.angle,t.evtTarget=e,t.handler=this.resizer,e.options.onDragEnd(t)),this.show(e),e.dispatchEvent(new MouseEvent("click"))};e.handleMouseEnter=(e=>{if(this.target!=e.target&&e.target.options.isHoverLine){let t=e=>{let t=e.cloneNode();t.innerHTML="",t.style.cssText=e.style.cssText,t.style.opacity="0",t.style.pointerEvents="none";let s=t.style.transform;s&&s.indexOf("rotate")>=0?t.style.transform=s.replace(/rotate\(\w*\)/gi,""):e.angle&&(t.style.transform=s+" rotate(0deg)"),e.parentNode.appendChild(t);let r=t.getBoundingClientRect();return t.remove(),r},s=document.querySelector(".resizer-target-hover-line");!s&&(s=document.createElement("div")),s.className="resizer-target-hover-line",s.style.position="absolute",document.body.appendChild(s),this.hoverLine=s;let r=t(e.target);s.style.left=parseInt(r.left+window.scrollX)+"px",s.style.top=parseInt(r.top+window.scrollY)+"px",s.style.width=parseInt(r.width+2)+"px",s.style.height=parseInt(r.height+2)+"px",s.style.opacity="1",s.style.transform="rotate("+(e.target.angle||0)+"deg)",s.target=e.target}}),e.handleMouseLeave=(e=>{this.hoverLine&&(this.hoverLine.style.opacity="0")}),e.handleMousedown||(e.handleMousedown=o,e.removeEventListener("mousedown",o),e.addEventListener("mousedown",o),e.removeEventListener("touchstart",o),e.addEventListener("touchstart",o),e.handleClick=(e=>{e.stopPropagation()}),e.removeEventListener("click",e.handleClick),e.addEventListener("click",e.handleClick),e.addEventListener("mouseenter",e.handleMouseEnter),e.addEventListener("mouseleave",e.handleMouseLeave))}},show(e){if(e&&e.resizer){if(!this.resizer){let e=document.querySelector(".resizer-container");e&&e.remove(),(e=document.createElement("div")).className="resizer-container",e.style.position="absolute",document.body.appendChild(e),this.resizer=e;let t=document.createElement("div");t.className="resizer-border",t.actionName="resizer-border",e.resizer_border=t,e.appendChild(t);let s=document.createElement("div");s.className="nw-resizer",s.actionName="nw-resizer",e.nw_resizer=s,e.appendChild(s);let r=document.createElement("div");r.className="ne-resizer",r.actionName="ne-resizer",e.ne_resizer=r,e.appendChild(r);let i=document.createElement("div");i.className="sw-resizer",i.actionName="sw-resizer",e.sw_resizer=i,e.appendChild(i);let o=document.createElement("div");o.className="se-resizer",o.actionName="se-resizer",e.se_resizer=o,e.appendChild(o);let n=document.createElement("div");n.className="n-resizer",n.actionName="n-resizer",e.n_resizer=n,e.appendChild(n);let a=document.createElement("div");a.className="e-resizer",a.actionName="e-resizer",e.e_resizer=a,e.appendChild(a);let l=document.createElement("div");l.className="s-resizer",l.actionName="s-resizer",e.s_resizer=l,e.appendChild(l);let d=document.createElement("div");d.className="w-resizer",d.actionName="w-resizer",e.w_resizer=d,e.appendChild(d);let c=document.createElement("div");c.className="r-resizer",c.actionName="r-resizer",e.r_resizer=c,e.appendChild(c);let h=document.createElement("div");h.className="rotator-angle-div",h.style.display="none",document.body.appendChild(h),e.showHideResizer=function(t,s){this.target.isLocked&&(t=!1),e.querySelectorAll("*").forEach(e=>{e!==s&&(e.style.opacity=t?0:1)})};let p=(e,t,s)=>{h.style.display="",h.style.left=e+"px",h.style.top=t+"px",h.innerHTML=s},u=()=>{h.style.display="none"},z=(e,t,s,r,i)=>{let o=Math.PI/180*i,n=Math.cos(o),a=Math.sin(o);return{x:n*(s-e)+a*(r-t)+e,y:n*(r-t)-a*(s-e)+t}},m=(e,t)=>{let s=Math.PI/-180*t,r=Math.cos(s),i=Math.sin(s),o=e.left,n=e.top,a=o+e.width,l=n,d=o+e.width,c=n+e.height,h=o,p=n+e.height,u=o+e.width/2,z=n+e.height/2;return{ax:parseInt(r*(o-u)+i*(n-z)+u),ay:parseInt(r*(n-z)-i*(o-u)+z),bx:parseInt(r*(a-u)+i*(l-z)+u),by:parseInt(r*(l-z)-i*(a-u)+z),cx:parseInt(r*(d-u)+i*(c-z)+u),cy:parseInt(r*(c-z)-i*(d-u)+z),dx:parseInt(r*(h-u)+i*(p-z)+u),dy:parseInt(r*(p-z)-i*(h-u)+z),px:u,py:z}},g=(e,t,s,r)=>{let i=m(t,s),o=m(e,s),n=0,a=0;switch(r){case 1:case"TopLeft":n=e.left+i.ax-o.ax,a=e.top+i.ay-o.ay;break;case 2:case"TopRight":n=e.left+i.bx-o.bx,a=e.top+i.by-o.by;break;case 3:case"BottomRight":n=e.left+i.cx-o.cx,a=e.top+i.cy-o.cy;break;case 4:case"BottomLeft":n=e.left+i.dx-o.dx,a=e.top+i.dy-o.dy;break;default:n=e.left+i.ax-o.ax,a=e.top+i.ay-o.ay}return{x:n,y:a}},y=t=>{if("mousedown"===t.type){if(0!=t.button)return;t.preventDefault()}t.stopPropagation();let s=this.target;if(s.isLocked="true"===s.getAttribute("islocked"),s.isLocked||(window.addEventListener("mousemove",f),window.addEventListener("mouseup",w),window.addEventListener("touchmove",f),window.addEventListener("touchend",w)),e.current=t.target,v=0,e.current.classList.add("active"),e.startPos={x:t.clientX+document.body.scrollLeft,y:t.clientY+document.body.scrollTop},s.size={left:s.offsetLeft,top:s.offsetTop,width:s.offsetWidth,height:s.offsetHeight,cx:s.offsetLeft+s.offsetWidth/2,cy:s.offsetTop+s.offsetHeight/2,angle:s.angle},s.prevSize={...s.size},"touchstart"===t.type){if(t.touches.length>1)return;e.startPos={x:t.touches[0].clientX+document.body.scrollLeft,y:t.touches[0].clientY+document.body.scrollTop}}if(s.bBox=s.getBoundingClientRect(),s.angle){let t=s.bBox,r=t.left+t.width/2,i=t.top+t.height/2;e.startPos=z(r,i,e.startPos.x,e.startPos.y,s.angle)}if(s.angle&&!s.options.resizeFromCenter){let t=m(s.size,s.angle);switch(s.coord=t,e.current.actionName){case"se-resizer":case"e-resizer":case"s-resizer":e.style.transformOrigin="top left",s.style.transformOrigin="top left",s.style.left=t.ax+"px",s.style.top=t.ay+"px";break;case"sw-resizer":case"w-resizer":e.style.transformOrigin="top right",s.style.transformOrigin="top right",s.style.left=t.bx-s.size.width+"px",s.style.top=t.by+"px";break;case"ne-resizer":e.style.transformOrigin="bottom left",s.style.transformOrigin="bottom left",s.style.left=t.dx+"px",s.style.top=t.dy-s.size.height+"px";break;case"nw-resizer":case"n-resizer":e.style.transformOrigin="bottom right",s.style.transformOrigin="bottom right",s.style.left=t.cx-s.size.width+"px",s.style.top=t.cy-s.size.height+"px"}}this.show(s);let r=e=>{e.stopPropagation(),e.preventDefault(),window.removeEventListener("click",r,!0)};window.addEventListener("click",r,!0),e.showHideResizer(!0,e.current)},f=e=>{e.stopPropagation(),"mousemove"===e.type&&e.preventDefault();let t=this.target,s=this.resizer,r=t.options.resizeFromCenter,{minWidth:i,minHeight:o,aspectRatio:n}=t.options,a=e.clientX+document.body.scrollLeft,l=e.clientY+document.body.scrollTop,d=e.clientX+document.body.scrollLeft-s.startPos.x,c=e.clientY+document.body.scrollTop-s.startPos.y,h=t.size.left,u=t.size.top,g=t.size.width,y=t.size.height,f=t.bBox,w=f.left+f.width/2,b=f.top+f.height/2,x=t.angle;if(0===v&&("r-resizer"===this.resizer.current.actionName?t.options&&t.options.onRotateStart&&(e.size={...t.size},e.angle=t.angle,e.evtTarget=t,e.handler=s.current,t.options.onRotateStart(e)):t.options&&t.options.onResizeStart&&(e.size={...t.size},e.angle=t.angle,e.evtTarget=t,e.handler=s.current,t.options.onResizeStart(e))),v++,"touchmove"===e.type&&(d=e.touches[0].clientX+document.body.scrollLeft-s.startPos.x,c=e.touches[0].clientY+document.body.scrollTop-s.startPos.y,a=e.touches[0].clientX+document.body.scrollLeft,l=e.touches[0].clientY+document.body.scrollTop),x){let e=f.left+f.width/2,t=f.top+f.height/2,r=z(e,t,a,l,x);d=r.x-s.startPos.x,c=r.y-s.startPos.y}switch(r&&(d*=2,c*=2),this.resizer.current.actionName){case"se-resizer":if((g=t.size.width+d/t.scale)=0?x:360+x),t.angle=x,t.style.transform.indexOf("rotate")>=0?t.style.transform=t.style.transform.replace(/rotate\(\w*\)/gi,"rotate("+x+"deg)"):t.style.transform+=" rotate("+x+"deg)",p(a,l,x)}if(t.angle&&"r-resizer"!==this.resizer.current.actionName&&!r){switch(this.resizer.current.actionName){case"se-resizer":case"e-resizer":case"s-resizer":h=t.coord.ax,u=t.coord.ay;break;case"sw-resizer":case"w-resizer":h=t.coord.bx-g,u=t.coord.by;m({left:h,top:u,width:g,height:y},0);break;case"ne-resizer":h=t.coord.dx,u=t.coord.dy-y;break;case"nw-resizer":case"n-resizer":h=t.coord.cx-g,u=t.coord.cy-y}}r&&(h=t.size.cx-g/2,u=t.size.cy-y/2);let L={left:h,top:u,width:g,height:y};if(t.newSize=L,t.style.left=h+"px",t.style.top=u+"px",t.style.width=g+"px",t.style.height=y+"px",t.options.boundWithContainer){let e=t.options.boundWithContainer instanceof HTMLDivElement?t.options.boundWithContainer:t.offsetParent;if(e){let s=e.getBoundingClientRect(),r=t.getBoundingClientRect();r.lefts.right||r.bottom>s.bottom?(h=t.prevSize.left,u=t.prevSize.top,g=t.prevSize.width,y=t.prevSize.height,x=t.prevSize.angle,L={left:h,top:u,width:g,height:y},t.newSize=L,t.style.left=h+"px",t.style.top=u+"px",t.style.width=g+"px",t.style.height=y+"px",t.angle=x,t.style.transform.indexOf("rotate")>=0?t.style.transform=t.style.transform.replace(/rotate\(\w*\)/gi,"rotate("+x+"deg)"):t.style.transform+=" rotate("+x+"deg)",p(a,l,x)):t.prevSize={left:h,top:u,width:g,height:y,angle:x}}}"r-resizer"===this.resizer.current.actionName?t.options&&t.options.onRotating&&(e.size={...t.newSize},e.angle=t.angle,e.evtTarget=t,e.handler=s.current,t.options.onRotating(e)):t.options&&t.options.onResizing&&(e.size={...t.newSize},e.angle=t.angle,e.evtTarget=t,e.handler=s.current,t.options.onResizing(e)),this.show(t)},w=t=>{t.stopPropagation(),"mouseup"===t.type&&t.preventDefault(),window.removeEventListener("mousemove",f),window.removeEventListener("mouseup",w),window.removeEventListener("touchmove",f),window.removeEventListener("touchend",w),u(),e.showHideResizer(!1,e.current);let s=this.target,r=s.options.resizeFromCenter;if(s.angle&&"r-resizer"!==e.current.actionName&&!r){let t,r,i="TopLeft";switch(e.style.transformOrigin="",s.style.transformOrigin="",this.resizer.current.actionName){case"se-resizer":i="TopLeft";break;case"sw-resizer":i="TopRight";break;case"ne-resizer":i="BottomLeft";break;case"nw-resizer":case"n-resizer":i="BottomRight";break;case"e-resizer":case"s-resizer":i="TopLeft";break;case"w-resizer":i="TopRight"}t={left:s.size.left,top:s.size.top,width:s.newSize.width,height:s.newSize.height},r=g(t,s.size,s.angle,i),s.style.left=r.x+"px",s.style.top=r.y+"px",s.newSize={...t,left:r.x,top:r.y}}v&&("r-resizer"===e.current.actionName?s.options&&s.options.onRotateEnd&&(t.size={...s.newSize},t.angle=s.angle,t.evtTarget=s,t.handler=e.current,s.options.onRotateEnd(t)):s.options&&s.options.onResizeEnd&&(t.size={...s.newSize},t.angle=s.angle,t.evtTarget=s,t.handler=e.current,s.options.onResizeEnd(t))),e.current.classList.remove("active"),this.show(s)},v=0;e.removeEventListener("mousedown",y),e.addEventListener("mousedown",y),e.removeEventListener("touchstart",y),e.addEventListener("touchstart",y);let b=t=>{e.visibile&&this.show(this.target)};window.removeEventListener("resize",b,!0),window.addEventListener("resize",b,!0);let x=t=>{e.visibile&&this.show(this.target)};window.removeEventListener("scroll",x,!0),window.addEventListener("scroll",x,!0)}let t=this.resizer,s=e=>{let s=t._target;s||((s=e.cloneNode()).innerHTML="",e.parentNode.appendChild(s),t._target=s),s.style.cssText=e.style.cssText,s.style.opacity="0",s.style.pointerEvents="none";let r=s.style.transform;return r&&r.indexOf("rotate")>=0?s.style.transform=r.replace(/rotate\(\w*\)/gi,""):e.angle&&(s.style.transform=r+" rotate(0deg)"),s.timeOut&&window.clearTimeout(s.timeOut),s.timeOut=window.setTimeout(()=>{window.clearTimeout(s.timeOut),s.remove(),t._target=null},1e3),s.getBoundingClientRect()},r=e=>{if(e!=this.resizer.angle){let t=(e-(e+7)%15+7)%180,s=this.resizer;s.angle=e,s.ne_resizer.className=s.ne_resizer.className.replace(/ cursor_(\d)+d/gi,"")+" cursor_"+(t+45)%180+"d",s.sw_resizer.className=s.sw_resizer.className.replace(/ cursor_(\d)+d/gi,"")+" cursor_"+(t+45)%180+"d",s.nw_resizer.className=s.nw_resizer.className.replace(/ cursor_(\d)+d/gi,"")+" cursor_"+(t+135)%180+"d",s.se_resizer.className=s.se_resizer.className.replace(/ cursor_(\d)+d/gi,"")+" cursor_"+(t+135)%180+"d",s.n_resizer.className=s.n_resizer.className.replace(/ cursor_(\d)+d/gi,"")+" cursor_"+(t+0)%180+"d",s.s_resizer.className=s.s_resizer.className.replace(/ cursor_(\d)+d/gi,"")+" cursor_"+(t+0)%180+"d",s.w_resizer.className=s.w_resizer.className.replace(/ cursor_(\d)+d/gi,"")+" cursor_"+(t+90)%180+"d",s.e_resizer.className=s.e_resizer.className.replace(/ cursor_(\d)+d/gi,"")+" cursor_"+(t+90)%180+"d"}};if(!t.visibile){let s=e.options&&e.options.resizers;s&&(t.nw_resizer.style.display=s.nw?"":"none",t.ne_resizer.style.display=s.ne?"":"none",t.sw_resizer.style.display=s.sw?"":"none",t.se_resizer.style.display=s.se?"":"none",t.n_resizer.style.display=s.n?"":"none",t.e_resizer.style.display=s.e?"":"none",t.s_resizer.style.display=s.s?"":"none",t.w_resizer.style.display=s.w?"":"none",t.r_resizer.style.display=s.r?"":"none")}let i=s(e);return t.style.left=parseInt(i.left+window.scrollX)+"px",t.style.top=parseInt(i.top+window.scrollY)+"px",t.style.width=parseInt(i.width+1)+"px",t.style.height=parseInt(i.height+1)+"px",t.style.display="",t.style.transform="rotate("+(e.angle||0)+"deg)",t.visibile=!0,t.target=e,r(e.angle),i}return e.getBoundingClientRect()},hide(){this.target=null,this.resizer.style.display="none",this.resizer.visibile=!1},remove(e){e&&e.handleMousedown&&(e.removeEventListener("mousedown",e.handleMousedown),e.removeEventListener("touchstart",e.handleMousedown),e.removeEventListener("mouseenter",e.handleMouseEnter),e.removeEventListener("mouseleave",e.handleMouseLeave),e.options&&(e.options=null),e.resizer=null,this.hide())}};export default resizer;