Liferay.Loader.define("item-selector-taglib@5.2.21/image_selector/js/ImageSelectorImage",["module","exports","require","liferay!frontend-js-react-web$classnames","frontend-js-web","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=f(r("liferay!frontend-js-react-web$classnames")),o=r("frontend-js-web"),a=(f(r("liferay!frontend-js-react-web$prop-types")),function(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=i();if(t&&t.has(e))return t.get(e);var r={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o)){var a=n?Object.getOwnPropertyDescriptor(e,o):null;a&&(a.get||a.set)?Object.defineProperty(r,o,a):r[o]=e[o]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react")));function i(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return i=function(){return e},e}function f(e){return e&&e.__esModule?e:{default:e}}const e="both",u="horizontal",c="vertical",l=()=>{};var s=({direction:t=c,imageSrc:r,isCroppable:i,onImageCrop:f=l,portletNamespace:s})=>{const p=(0,a.useRef)(),d=(0,a.useRef)(),[g,m]=(0,a.useState)({x:0,y:0}),[y,v]=(0,a.useState)(),[b,j]=(0,a.useState)(),w=r=>{r.stopPropagation(),r.preventDefault();const n=p.current,o=d.current,a=n.getBoundingClientRect();let i=g.x,f=g.y;if(t===u||t===e){if(i+=r.pageX-a.left-y.x,i>=0||i<n.offsetWidth-o.offsetWidth)return void r.preventDefault()}if(t===c||t===e){if(f+=r.pageY-a.top-y.y,f>=0||f<n.offsetHeight-o.offsetHeight)return void r.preventDefault()}m({x:i,y:f})},h=e=>{e.stopPropagation(),e.preventDefault(),j(!1);const t=(0,o.getCropRegion)(d.current,{height:p.current.offsetHeight,x:Math.abs(g.x),y:Math.abs(g.y)});f(t)};return(0,a.useEffect)((()=>(b&&(document.addEventListener("mousemove",w),document.addEventListener("mouseup",h)),()=>{document.removeEventListener("mousemove",w),document.removeEventListener("mouseup",h)})),[b]),a.default.createElement("div",{className:(0,n.default)("image-wrapper",{cropper:i}),ref:p},a.default.createElement("img",{alt:Liferay.Language.get("current-image"),className:"current-image",id:"".concat(s,"image"),onMouseDown:e=>{e.stopPropagation(),e.preventDefault();const t=p.current.getBoundingClientRect();v({x:e.pageX-t.left,y:e.pageY-t.top}),j(!0)},ref:d,src:r,style:(()=>{let e={};return i&&(e={cursor:b?"move":"unset",left:g.x,position:"relative",top:g.y}),e})()}))};t.default=s}}));
//# sourceMappingURL=ImageSelectorImage.js.map