!function(){"use strict";var e={n:function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,{a:n}),n},d:function(t,n){for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Draggable:function(){return i}});var n=window.vendor.React,o=e.n(n),c=window.lodash,r=window.divi.window,s=window.vendor.ReactDOM;const a=()=>(0,s.createPortal)(o().createElement("div",{className:"et-vb-app-frame-draggable-overlay"}),(0,r.topWindowPortalDomTarget)()),i=e=>{const{children:t,className:s,isTopWindow:i,style:u,onContextMenu:l,onElementClick:d,onElementDrag:v,onElementRelease:h,type:m,disable:p,hasWrapper:g}=e,f=i?r.topWindow:window,w=(0,n.useRef)(null),b=(0,n.useRef)(null),[y,E]=(0,n.useState)(!1),X=e=>{const t=f.document.body;if("start"===e)return E(!0),void t.classList.add("et-vb-dragging");E(!1),t.classList.remove("et-vb-dragging")},Y=e=>{if(p)return;X("start");const t=e.clientX,n=e.clientY,o=w.current.getBoundingClientRect(),r=(0,c.now)();d({ref:w,domRect:o,event:e});const s=e=>{const c={x:e.clientX-t,y:e.clientY-n};0===c.x&&0===c.y||v({ref:w,sinceMouseDown:c,domRect:o,onClickTimestamp:r,event:e})},a=e=>{const c={x:e.clientX-t,y:e.clientY-n};X("end"),h({ref:w,sinceMouseDown:c,domRect:o,onClickTimestamp:r,event:e}),f.removeEventListener("mousemove",s),f.removeEventListener("mouseup",a)};f.addEventListener("mousemove",s),f.addEventListener("mouseup",a)},D=(0,n.useCallback)((e=>{if(p)return;if(e.cancelable&&e.preventDefault(),!e.touches||0===e.touches.length)return;X("start");const t=e.touches[0].clientX,n=e.touches[0].clientY,o=w.current.getBoundingClientRect(),r=(0,c.now)(),s={clientX:e.touches[0].clientX,clientY:e.touches[0].clientY,preventDefault:()=>e.preventDefault(),stopPropagation:()=>e.stopPropagation(),screenX:e.touches?.[0]?.screenX||e.touches?.[0]?.clientX,screenY:e.touches?.[0]?.screenY||e.touches?.[0]?.clientY,button:0,target:e.target};d({ref:w,domRect:o,event:s});const a=e=>{if(e.cancelable&&e.preventDefault(),!e.touches||0===e.touches.length)return;const c={x:e.touches[0].clientX-t,y:e.touches[0].clientY-n};if(0!==c.x||0!==c.y){const t={clientX:e.touches[0].clientX,clientY:e.touches[0].clientY,preventDefault:()=>e.preventDefault(),stopPropagation:()=>e.stopPropagation(),screenX:e.touches?.[0]?.screenX||e.touches?.[0]?.clientX,screenY:e.touches?.[0]?.screenY||e.touches?.[0]?.clientY,button:0,target:e.target};v({ref:w,sinceMouseDown:c,domRect:o,onClickTimestamp:r,event:t})}},i=e=>{if(e.cancelable&&e.preventDefault(),!e.changedTouches||0===e.changedTouches.length)return X("end"),f.removeEventListener("touchmove",a),void f.removeEventListener("touchend",i);const c={x:e.changedTouches[0].clientX-t,y:e.changedTouches[0].clientY-n};X("end");const s={clientX:e.changedTouches[0].clientX,clientY:e.changedTouches[0].clientY,preventDefault:()=>e.preventDefault(),stopPropagation:()=>e.stopPropagation(),screenX:e.changedTouches?.[0]?.screenX||e.changedTouches?.[0]?.clientX,screenY:e.changedTouches?.[0]?.screenY||e.changedTouches?.[0]?.clientY,button:0,target:e.target};h({ref:w,sinceMouseDown:c,domRect:o,onClickTimestamp:r,event:s}),f.removeEventListener("touchmove",a),f.removeEventListener("touchend",i)};f.addEventListener("touchmove",a,{passive:!1}),f.addEventListener("touchend",i,{passive:!1})}),[p,X,d,v,h,f]),T=(0,n.useCallback)((()=>"ontouchstart"in window||navigator.maxTouchPoints>0),[]),C=(0,n.useCallback)((e=>{e&&(b.current&&b.current(),e.addEventListener("touchstart",D,{passive:!1}),b.current=()=>{e.removeEventListener("touchstart",D),b.current=null})}),[D]),L=(0,n.useCallback)((e=>{w.current=e,e?T()&&C(e):b.current&&b.current()}),[T,C]);(0,n.useEffect)((()=>()=>{b.current&&b.current()}),[]);const P=i&&y?o().createElement(a,{key:"app-frame-overlay"}):"";return!g&&(0,n.isValidElement)(t)?(0,n.cloneElement)(t,{onContextMenu:l,onMouseDown:Y,ref:L,className:s,style:u},P):(0,n.createElement)(m,{onContextMenu:l,onMouseDown:Y,ref:L,className:s,style:u},[t,P])};i.defaultProps={isTopWindow:!0,className:"",onElementClick:c.noop,onElementDrag:c.noop,onElementRelease:c.noop,type:"div",disable:!1,style:{},hasWrapper:!0},(window.divi=window.divi||{}).draggable=t}();