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