import{t as mt,r as d,j as u,a as ft}from"./index-CuozEvUf.js";var V=!1,E,Z,k,_,N,rt,W,U,B,H,nt,G,X,st,at;function g(){if(!V){V=!0;var o=navigator.userAgent,e=/(?:MSIE.(\d+\.\d+))|(?:(?:Firefox|GranParadiso|Iceweasel).(\d+\.\d+))|(?:Opera(?:.+Version.|.)(\d+\.\d+))|(?:AppleWebKit.(\d+(?:\.\d+)?))|(?:Trident\/\d+\.\d+.*rv:(\d+\.\d+))/.exec(o),t=/(Mac OS X)|(Windows)|(Linux)/.exec(o);if(G=/\b(iPhone|iP[ao]d)/.exec(o),X=/\b(iP[ao]d)/.exec(o),H=/Android/i.exec(o),st=/FBAN\/\w+;/i.exec(o),at=/Mobile/i.exec(o),nt=!!/Win64/.exec(o),e){E=e[1]?parseFloat(e[1]):e[5]?parseFloat(e[5]):NaN,E&&document&&document.documentMode&&(E=document.documentMode);var i=/(?:Trident\/(\d+.\d+))/.exec(o);rt=i?parseFloat(i[1])+4:E,Z=e[2]?parseFloat(e[2]):NaN,k=e[3]?parseFloat(e[3]):NaN,_=e[4]?parseFloat(e[4]):NaN,_?(e=/(?:Chrome\/(\d+\.\d+))/.exec(o),N=e&&e[1]?parseFloat(e[1]):NaN):N=NaN}else E=Z=k=N=_=NaN;if(t){if(t[1]){var r=/(?:Mac OS X (\d+(?:[._]\d+)?))/.exec(o);W=r?parseFloat(r[1].replace("_",".")):!0}else W=!1;U=!!t[2],B=!!t[3]}else W=U=B=!1}}var Y={ie:function(){return g()||E},ieCompatibilityMode:function(){return g()||rt>E},ie64:function(){return Y.ie()&&nt},firefox:function(){return g()||Z},opera:function(){return g()||k},webkit:function(){return g()||_},safari:function(){return Y.webkit()},chrome:function(){return g()||N},windows:function(){return g()||U},osx:function(){return g()||W},linux:function(){return g()||B},iphone:function(){return g()||G},mobile:function(){return g()||G||X||H||at},nativeApp:function(){return g()||st},android:function(){return g()||H},ipad:function(){return g()||X}},gt=Y,vt=!!(typeof window<"u"&&window.document&&window.document.createElement),wt={canUseDOM:vt},bt=wt,ht=bt,ct;ht.canUseDOM&&(ct=document.implementation&&document.implementation.hasFeature&&document.implementation.hasFeature("","")!==!0);/** * Checks if an event is supported in the current execution environment. * * NOTE: This will not work correctly for non-generic events such as `change`, * `reset`, `load`, `error`, and `select`. * * Borrows from Modernizr. * * @param {string} eventNameSuffix Event name, e.g. "click". * @param {?boolean} capture Check if the capture phase is supported. * @return {boolean} True if the event is supported. * @internal * @license Modernizr 3.0.0pre (Custom Build) | MIT */function Ct(o,e){if(!ht.canUseDOM||e&&!("addEventListener"in document))return!1;var t="on"+o,i=t in document;if(!i){var r=document.createElement("div");r.setAttribute(t,"return;"),i=typeof r[t]=="function"}return!i&&ct&&o==="wheel"&&(i=document.implementation.hasFeature("Events.wheel","3.0")),i}var yt=Ct,xt=gt,St=yt,q=10,J=40,Q=800;function pt(o){var e=0,t=0,i=0,r=0;return"detail"in o&&(t=o.detail),"wheelDelta"in o&&(t=-o.wheelDelta/120),"wheelDeltaY"in o&&(t=-o.wheelDeltaY/120),"wheelDeltaX"in o&&(e=-o.wheelDeltaX/120),"axis"in o&&o.axis===o.HORIZONTAL_AXIS&&(e=t,t=0),i=e*q,r=t*q,"deltaY"in o&&(r=o.deltaY),"deltaX"in o&&(i=o.deltaX),(i||r)&&o.deltaMode&&(o.deltaMode==1?(i*=J,r*=J):(i*=Q,r*=Q)),i&&!e&&(e=i<1?-1:1),r&&!t&&(t=r<1?-1:1),{spinX:e,spinY:t,pixelX:i,pixelY:r}}pt.getEventType=function(){return xt.firefox()?"DOMMouseScroll":St("wheel")?"wheel":"mousewheel"};var zt=pt,Et=zt;const Dt=mt(Et);function j(o){"@babel/helpers - typeof";return j=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},j(o)}function Rt(o,e){if(j(o)!="object"||!o)return o;var t=o[Symbol.toPrimitive];if(t!==void 0){var i=t.call(o,e);if(j(i)!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(o)}function Pt(o){var e=Rt(o,"string");return j(e)=="symbol"?e:e+""}function Mt(o,e,t){return(e=Pt(e))in o?Object.defineProperty(o,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):o[e]=t,o}function $(o,e){var t=Object.keys(o);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(o);e&&(i=i.filter(function(r){return Object.getOwnPropertyDescriptor(o,r).enumerable})),t.push.apply(t,i)}return t}function l(o){for(var e=1;ec*r?{width:c*r,height:c}:{width:h,height:h/r}}function Tt(o){return o.width>o.height?o.width/o.naturalWidth:o.height/o.naturalHeight}function M(o,e,t,i,r=0){const{width:a,height:n}=R(e.width,e.height,r);return{x:tt(o.x,a,t.width,i),y:tt(o.y,n,t.height,i)}}function tt(o,e,t,i){const r=Math.abs(e*i/2-t/2);return I(o,-r,r)}function et(o,e){return Math.sqrt(Math.pow(o.y-e.y,2)+Math.pow(o.x-e.x,2))}function it(o,e){return Math.atan2(e.y-o.y,e.x-o.x)*180/Math.PI}function At(o,e,t,i,r,a=0,n=!0){const s=n?Ot:_t,h=R(e.width,e.height,a),c=R(e.naturalWidth,e.naturalHeight,a),p={x:s(100,((h.width-t.width/r)/2-o.x/r)/h.width*100),y:s(100,((h.height-t.height/r)/2-o.y/r)/h.height*100),width:s(100,t.width/h.width*100/r),height:s(100,t.height/h.height*100/r)},m=Math.round(s(c.width,p.width*c.width/100)),x=Math.round(s(c.height,p.height*c.height/100)),b=c.width>=c.height*i?{width:Math.round(x*i),height:x}:{width:m,height:Math.round(m/i)};return{croppedAreaPercentages:p,croppedAreaPixels:l(l({},b),{},{x:Math.round(s(c.width-b.width,p.x*c.width/100)),y:Math.round(s(c.height-b.height,p.y*c.height/100))})}}function Ot(o,e){return Math.min(o,Math.max(0,e))}function _t(o,e){return e}function Nt(o,e,t,i,r,a){const n=R(e.width,e.height,t),s=I(i.width/n.width*(100/o.width),r,a);return{crop:{x:s*n.width/2-i.width/2-n.width*s*(o.x/100),y:s*n.height/2-i.height/2-n.height*s*(o.y/100)},zoom:s}}function Wt(o,e,t){const i=Tt(e);return t.height>t.width?t.height/(o.height*i):t.width/(o.width*i)}function It(o,e,t=0,i,r,a){const n=R(e.naturalWidth,e.naturalHeight,t),s=I(Wt(o,e,i),r,a),h=i.height>i.width?i.height/o.height:i.width/o.width;return{crop:{x:((n.width-o.width)/2-o.x)*h,y:((n.height-o.height)/2-o.y)*h},zoom:s}}function ot(o,e){return{x:(e.x+o.x)/2,y:(e.y+o.y)/2}}function Ft(o){return o*Math.PI/180}function R(o,e,t){const i=Ft(t);return{width:Math.abs(Math.cos(i)*o)+Math.abs(Math.sin(i)*e),height:Math.abs(Math.sin(i)*o)+Math.abs(Math.cos(i)*e)}}function I(o,e,t){return Math.min(Math.max(o,e),t)}function O(...o){return o.filter(e=>typeof e=="string"&&e.length>0).join(" ").trim()}var Lt=`.reactEasyCrop_Container { position: absolute; top: 0; left: 0; right: 0; bottom: 0; overflow: hidden; user-select: none; touch-action: none; cursor: move; display: flex; justify-content: center; align-items: center; } .reactEasyCrop_Image, .reactEasyCrop_Video { will-change: transform; /* this improves performances and prevent painting issues on iOS Chrome */ max-width: unset; /* prevent global img/video reset rules from constraining the cropper media */ } .reactEasyCrop_Contain { max-width: 100%; max-height: 100%; margin: auto; position: absolute; top: 0; bottom: 0; left: 0; right: 0; } .reactEasyCrop_Cover_Horizontal { width: 100%; height: auto; } .reactEasyCrop_Cover_Vertical { width: auto; height: 100%; } .reactEasyCrop_CropArea { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); border: 1px solid rgba(255, 255, 255, 0.5); box-sizing: border-box; box-shadow: 0 0 0 9999em; color: rgba(0, 0, 0, 0.5); overflow: hidden; } .reactEasyCrop_CropAreaRound { border-radius: 50%; } .reactEasyCrop_CropAreaGrid::before { content: ' '; box-sizing: border-box; position: absolute; border: 1px solid rgba(255, 255, 255, 0.5); top: 0; bottom: 0; left: 33.33%; right: 33.33%; border-top: 0; border-bottom: 0; } .reactEasyCrop_CropAreaGrid::after { content: ' '; box-sizing: border-box; position: absolute; border: 1px solid rgba(255, 255, 255, 0.5); top: 33.33%; bottom: 33.33%; left: 0; right: 0; border-left: 0; border-right: 0; } `;const Zt=250,kt=1,Ut=3,Bt=1;var F=class y extends d.Component{constructor(...e){super(...e),this.cropperRef=d.createRef(),this.imageRef=d.createRef(),this.videoRef=d.createRef(),this.containerPosition={x:0,y:0},this.containerRef=null,this.styleRef=null,this.containerRect=null,this.mediaSize={width:0,height:0,naturalWidth:0,naturalHeight:0},this.dragStartPosition={x:0,y:0},this.dragStartCrop={x:0,y:0},this.gestureZoomStart=0,this.gestureRotationStart=0,this.isTouching=!1,this.lastPinchDistance=0,this.lastPinchRotation=0,this.rafDragTimeout=null,this.rafPinchTimeout=null,this.wheelTimer=null,this.resizeEmitTimer=null,this.currentDoc=typeof document<"u"?document:null,this.currentWindow=typeof window<"u"?window:null,this.resizeObserver=null,this.previousCropSize=null,this.isInitialized=!1,this.dragInteractionSource=null,this.state={cropSize:null,hasWheelJustStarted:!1,mediaObjectFit:void 0},this.initResizeObserver=()=>{if(typeof window.ResizeObserver>"u"||!this.containerRef)return;let t=!0;this.resizeObserver=new window.ResizeObserver(i=>{if(t){t=!1;return}this.computeSizes({isResizeTriggered:!0})}),this.resizeObserver.observe(this.containerRef)},this.onWindowResize=()=>{this.computeSizes({isResizeTriggered:!0})},this.preventZoomSafari=t=>t.preventDefault(),this.cleanEvents=()=>{this.currentDoc&&(this.currentDoc.removeEventListener("mousemove",this.onMouseMove),this.currentDoc.removeEventListener("mouseup",this.onDragStopped),this.currentDoc.removeEventListener("touchmove",this.onTouchMove),this.currentDoc.removeEventListener("touchend",this.onDragStopped),this.currentDoc.removeEventListener("gesturechange",this.onGestureChange),this.currentDoc.removeEventListener("gestureend",this.onGestureEnd),this.currentDoc.removeEventListener("scroll",this.onScroll))},this.clearScrollEvent=()=>{this.containerRef&&this.containerRef.removeEventListener("wheel",this.onWheel),this.wheelTimer&&clearTimeout(this.wheelTimer)},this.onMediaLoad=()=>{const t=this.computeSizes();t&&(this.previousCropSize=t,this.emitCropData(),this.setInitialCrop(t),this.isInitialized=!0),this.props.onMediaLoaded&&this.props.onMediaLoaded(this.mediaSize)},this.setInitialCrop=t=>{if(this.props.initialCroppedAreaPercentages){const{crop:i,zoom:r}=Nt(this.props.initialCroppedAreaPercentages,this.mediaSize,this.props.rotation,t,this.props.minZoom,this.props.maxZoom);this.props.onCropChange(i),this.props.onZoomChange&&this.props.onZoomChange(r)}else if(this.props.initialCroppedAreaPixels){const{crop:i,zoom:r}=It(this.props.initialCroppedAreaPixels,this.mediaSize,this.props.rotation,t,this.props.minZoom,this.props.maxZoom);this.props.onCropChange(i),this.props.onZoomChange&&this.props.onZoomChange(r)}},this.computeSizes=({isResizeTriggered:t=!1}={})=>{const i=this.imageRef.current||this.videoRef.current;if(i&&this.containerRef){var r,a,n,s,h,c;this.containerRect=this.containerRef.getBoundingClientRect(),this.saveContainerPosition();const p=this.containerRect.width/this.containerRect.height,m=((r=this.imageRef.current)===null||r===void 0?void 0:r.naturalWidth)||((a=this.videoRef.current)===null||a===void 0?void 0:a.videoWidth)||0,x=((n=this.imageRef.current)===null||n===void 0?void 0:n.naturalHeight)||((s=this.videoRef.current)===null||s===void 0?void 0:s.videoHeight)||0,b=i.offsetWidthS?{width:this.containerRect.height*S,height:this.containerRect.height}:{width:this.containerRect.width,height:this.containerRect.width/S};break;case"horizontal-cover":C={width:this.containerRect.width,height:this.containerRect.width/S};break;case"vertical-cover":C={width:this.containerRect.height*S,height:this.containerRect.height};break}else C={width:i.offsetWidth,height:i.offsetHeight};this.mediaSize=l(l({},C),{},{naturalWidth:m,naturalHeight:x}),this.props.setMediaSize&&this.props.setMediaSize(this.mediaSize);const v=this.props.cropSize?this.props.cropSize:jt(this.mediaSize.width,this.mediaSize.height,this.containerRect.width,this.containerRect.height,this.props.aspect,this.props.rotation);return(((h=this.state.cropSize)===null||h===void 0?void 0:h.height)!==v.height||((c=this.state.cropSize)===null||c===void 0?void 0:c.width)!==v.width)&&this.props.onCropSizeChange&&this.props.onCropSizeChange(v),this.setState({cropSize:v},()=>this.recomputeCropPosition({isResizeTriggered:t})),this.props.setCropSize&&this.props.setCropSize(v),v}},this.saveContainerPosition=()=>{if(this.containerRef){const t=this.containerRef.getBoundingClientRect();this.containerPosition={x:t.left,y:t.top}}},this.onMouseDown=t=>{this.currentDoc&&(t.preventDefault(),this.currentDoc.addEventListener("mousemove",this.onMouseMove),this.currentDoc.addEventListener("mouseup",this.onDragStopped),this.saveContainerPosition(),this.onDragStart(y.getMousePoint(t),"mouse"))},this.onMouseMove=t=>this.onDrag(y.getMousePoint(t)),this.onScroll=t=>{this.currentDoc&&(t.preventDefault(),this.saveContainerPosition())},this.onTouchStart=t=>{this.currentDoc&&(this.isTouching=!0,!(this.props.onTouchRequest&&!this.props.onTouchRequest(t))&&(this.currentDoc.addEventListener("touchmove",this.onTouchMove,{passive:!1}),this.currentDoc.addEventListener("touchend",this.onDragStopped),this.saveContainerPosition(),t.touches.length===2?this.onPinchStart(t):t.touches.length===1&&this.onDragStart(y.getTouchPoint(t.touches[0]),"touch")))},this.onTouchMove=t=>{t.preventDefault(),t.touches.length===2?this.onPinchMove(t):t.touches.length===1&&this.onDrag(y.getTouchPoint(t.touches[0]))},this.onGestureStart=t=>{this.currentDoc&&(t.preventDefault(),this.currentDoc.addEventListener("gesturechange",this.onGestureChange),this.currentDoc.addEventListener("gestureend",this.onGestureEnd),this.gestureZoomStart=this.props.zoom,this.gestureRotationStart=this.props.rotation)},this.onGestureChange=t=>{if(t.preventDefault(),this.isTouching)return;const i=y.getMousePoint(t),r=this.gestureZoomStart-1+t.scale;if(this.setNewZoom(r,i,{shouldUpdatePosition:!0}),this.props.onRotationChange){const a=this.gestureRotationStart+t.rotation;this.props.onRotationChange(a)}},this.onGestureEnd=t=>{this.cleanEvents()},this.onDragStart=({x:t,y:i},r)=>{var a,n;this.dragStartPosition={x:t,y:i},this.dragStartCrop=l({},this.props.crop),this.dragInteractionSource=r,(a=(n=this.props).onInteractionStart)===null||a===void 0||a.call(n,{source:r})},this.onDrag=({x:t,y:i})=>{this.currentWindow&&(this.rafDragTimeout&&this.currentWindow.cancelAnimationFrame(this.rafDragTimeout),this.rafDragTimeout=this.currentWindow.requestAnimationFrame(()=>{if(!this.state.cropSize||t===void 0||i===void 0)return;const r=t-this.dragStartPosition.x,a=i-this.dragStartPosition.y,n={x:this.dragStartCrop.x+r,y:this.dragStartCrop.y+a},s=this.props.restrictPosition?M(n,this.mediaSize,this.state.cropSize,this.props.zoom,this.props.rotation):n;this.props.onCropChange(s)}))},this.onDragStopped=()=>{var t,i,r;this.isTouching=!1,this.cleanEvents(),this.emitCropData(),(t=(i=this.props).onInteractionEnd)===null||t===void 0||t.call(i,{source:(r=this.dragInteractionSource)!==null&&r!==void 0?r:"mouse"}),this.dragInteractionSource=null},this.onWheel=t=>{if(!this.currentWindow||this.props.onWheelRequest&&!this.props.onWheelRequest(t))return;t.preventDefault();const i=y.getMousePoint(t),{pixelY:r}=Dt(t),a=this.props.zoom-r*this.props.zoomSpeed/200;this.setNewZoom(a,i,{shouldUpdatePosition:!0}),this.state.hasWheelJustStarted||this.setState({hasWheelJustStarted:!0},()=>{var n,s;return(n=(s=this.props).onInteractionStart)===null||n===void 0?void 0:n.call(s,{source:"wheel"})}),this.wheelTimer&&clearTimeout(this.wheelTimer),this.wheelTimer=this.currentWindow.setTimeout(()=>this.setState({hasWheelJustStarted:!1},()=>{var n,s;return(n=(s=this.props).onInteractionEnd)===null||n===void 0?void 0:n.call(s,{source:"wheel"})}),250)},this.getPointOnContainer=({x:t,y:i},r)=>{if(!this.containerRect)throw new Error("The Cropper is not mounted");return{x:this.containerRect.width/2-(t-r.x),y:this.containerRect.height/2-(i-r.y)}},this.getPointOnMedia=({x:t,y:i})=>{const{crop:r,zoom:a}=this.props;return{x:(t+r.x)/a,y:(i+r.y)/a}},this.setNewZoom=(t,i,{shouldUpdatePosition:r=!0}={})=>{if(!this.state.cropSize||!this.props.onZoomChange)return;const a=I(t,this.props.minZoom,this.props.maxZoom);if(r){const n=this.getPointOnContainer(i,this.containerPosition),s=this.getPointOnMedia(n),h={x:s.x*a-n.x,y:s.y*a-n.y},c=this.props.restrictPosition?M(h,this.mediaSize,this.state.cropSize,a,this.props.rotation):h;this.props.onCropChange(c)}this.props.onZoomChange(a)},this.getCropData=()=>this.state.cropSize?At(this.props.restrictPosition?M(this.props.crop,this.mediaSize,this.state.cropSize,this.props.zoom,this.props.rotation):this.props.crop,this.mediaSize,this.state.cropSize,this.getAspect(),this.props.zoom,this.props.rotation,this.props.restrictPosition):null,this.emitCropData=()=>{this.resizeEmitTimer&&(clearTimeout(this.resizeEmitTimer),this.resizeEmitTimer=null);const t=this.getCropData();if(!t)return;const{croppedAreaPercentages:i,croppedAreaPixels:r}=t;this.props.onCropComplete&&this.props.onCropComplete(i,r),this.props.onCropAreaChange&&this.props.onCropAreaChange(i,r)},this.emitCropAreaChange=()=>{const t=this.getCropData();if(!t)return;const{croppedAreaPercentages:i,croppedAreaPixels:r}=t;this.props.onCropAreaChange&&this.props.onCropAreaChange(i,r)},this.recomputeCropPosition=({isResizeTriggered:t=!1}={})=>{var i,r;if(!this.state.cropSize)return;let a=this.props.crop;if(this.isInitialized&&(!((i=this.previousCropSize)===null||i===void 0)&&i.width)&&(!((r=this.previousCropSize)===null||r===void 0)&&r.height)&&(Math.abs(this.previousCropSize.width-this.state.cropSize.width)>1e-6||Math.abs(this.previousCropSize.height-this.state.cropSize.height)>1e-6)){const s=this.state.cropSize.width/this.previousCropSize.width,h=this.state.cropSize.height/this.previousCropSize.height;a={x:this.props.crop.x*s,y:this.props.crop.y*h}}const n=this.props.restrictPosition?M(a,this.mediaSize,this.state.cropSize,this.props.zoom,this.props.rotation):a;this.previousCropSize=this.state.cropSize,this.props.onCropChange(n),t?this.debouncedEmitCropData():this.emitCropData()},this.debouncedEmitCropData=()=>{this.currentWindow&&(this.resizeEmitTimer&&clearTimeout(this.resizeEmitTimer),this.resizeEmitTimer=this.currentWindow.setTimeout(()=>{this.emitCropData()},Zt))},this.onKeyDown=t=>{const{crop:i,onCropChange:r,keyboardStep:a,zoom:n,rotation:s}=this.props;let h=a;if(!this.state.cropSize)return;t.shiftKey&&(h*=.2);let c=l({},i);switch(t.key){case"ArrowUp":c.y-=h,t.preventDefault();break;case"ArrowDown":c.y+=h,t.preventDefault();break;case"ArrowLeft":c.x-=h,t.preventDefault();break;case"ArrowRight":c.x+=h,t.preventDefault();break;default:return}if(this.props.restrictPosition&&(c=M(c,this.mediaSize,this.state.cropSize,n,s)),!t.repeat){var p,m;(p=(m=this.props).onInteractionStart)===null||p===void 0||p.call(m,{source:"keyboard"})}r(c)},this.onKeyUp=t=>{var i,r;switch(t.key){case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":t.preventDefault();break;default:return}this.emitCropData(),(i=(r=this.props).onInteractionEnd)===null||i===void 0||i.call(r,{source:"keyboard"})}}componentDidMount(){!this.currentDoc||!this.currentWindow||(this.containerRef&&(this.containerRef.ownerDocument&&(this.currentDoc=this.containerRef.ownerDocument),this.currentDoc.defaultView&&(this.currentWindow=this.currentDoc.defaultView),this.initResizeObserver(),typeof window.ResizeObserver>"u"&&this.currentWindow.addEventListener("resize",this.onWindowResize),this.props.zoomWithScroll&&this.containerRef.addEventListener("wheel",this.onWheel,{passive:!1}),this.containerRef.addEventListener("gesturestart",this.onGestureStart)),this.currentDoc.addEventListener("scroll",this.onScroll),this.props.disableAutomaticStylesInjection||(this.styleRef=this.currentDoc.createElement("style"),this.styleRef.setAttribute("type","text/css"),this.props.nonce&&this.styleRef.setAttribute("nonce",this.props.nonce),this.styleRef.innerHTML=Lt,this.currentDoc.head.appendChild(this.styleRef)),this.imageRef.current&&this.imageRef.current.complete&&this.onMediaLoad(),this.props.setImageRef&&this.props.setImageRef(this.imageRef),this.props.setVideoRef&&this.props.setVideoRef(this.videoRef),this.props.setCropperRef&&this.props.setCropperRef(this.cropperRef))}componentWillUnmount(){var e;if(!(!this.currentDoc||!this.currentWindow)){if(typeof window.ResizeObserver>"u"&&this.currentWindow.removeEventListener("resize",this.onWindowResize),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),this.resizeEmitTimer&&clearTimeout(this.resizeEmitTimer),this.containerRef&&this.containerRef.removeEventListener("gesturestart",this.preventZoomSafari),this.styleRef){var t;(t=this.styleRef.parentNode)===null||t===void 0||t.removeChild(this.styleRef)}this.cleanEvents(),this.props.zoomWithScroll&&this.clearScrollEvent()}}componentDidUpdate(e){var t,i,r,a,n,s,h,c;if(e.rotation!==this.props.rotation?(this.computeSizes(),this.recomputeCropPosition()):e.aspect!==this.props.aspect?this.computeSizes():e.objectFit!==this.props.objectFit?this.computeSizes():e.zoom!==this.props.zoom?this.recomputeCropPosition():((t=e.cropSize)===null||t===void 0?void 0:t.height)!==((i=this.props.cropSize)===null||i===void 0?void 0:i.height)||((r=e.cropSize)===null||r===void 0?void 0:r.width)!==((a=this.props.cropSize)===null||a===void 0?void 0:a.width)?this.computeSizes():(((n=e.crop)===null||n===void 0?void 0:n.x)!==((s=this.props.crop)===null||s===void 0?void 0:s.x)||((h=e.crop)===null||h===void 0?void 0:h.y)!==((c=this.props.crop)===null||c===void 0?void 0:c.y))&&this.emitCropAreaChange(),e.zoomWithScroll!==this.props.zoomWithScroll&&this.containerRef&&(this.props.zoomWithScroll?this.containerRef.addEventListener("wheel",this.onWheel,{passive:!1}):this.clearScrollEvent()),e.video!==this.props.video){var p;(p=this.videoRef.current)===null||p===void 0||p.load()}const m=this.getObjectFit();m!==this.state.mediaObjectFit&&this.setState({mediaObjectFit:m},this.computeSizes)}getAspect(){const{cropSize:e,aspect:t}=this.props;return e?e.width/e.height:t}getObjectFit(){if(this.props.objectFit==="cover"){if((this.imageRef.current||this.videoRef.current)&&this.containerRef){var e,t,i,r;this.containerRect=this.containerRef.getBoundingClientRect();const a=this.containerRect.width/this.containerRect.height;return(((e=this.imageRef.current)===null||e===void 0?void 0:e.naturalWidth)||((t=this.videoRef.current)===null||t===void 0?void 0:t.videoWidth)||0)/(((i=this.imageRef.current)===null||i===void 0?void 0:i.naturalHeight)||((r=this.videoRef.current)===null||r===void 0?void 0:r.videoHeight)||0){const a=et(t,i),n=this.props.zoom*(a/this.lastPinchDistance);this.setNewZoom(n,r,{shouldUpdatePosition:!1}),this.lastPinchDistance=a;const s=it(t,i),h=this.props.rotation+(s-this.lastPinchRotation);this.props.onRotationChange&&this.props.onRotationChange(h),this.lastPinchRotation=s})}render(){var e;const{image:t,video:i,mediaProps:r,cropperProps:a,transform:n,crop:{x:s,y:h},rotation:c,zoom:p,cropShape:m,showGrid:x,roundCropAreaPixels:b,style:{containerStyle:S,cropAreaStyle:C,mediaStyle:v},classes:{containerClassName:T,cropAreaClassName:L,mediaClassName:P}}=this.props,z=(e=this.state.mediaObjectFit)!==null&&e!==void 0?e:this.getObjectFit();return d.createElement("div",{onMouseDown:this.onMouseDown,onTouchStart:this.onTouchStart,ref:D=>this.containerRef=D,"data-testid":"container",style:S,className:O("reactEasyCrop_Container",T)},t?d.createElement("img",l(l({alt:"",className:O("reactEasyCrop_Image",z==="contain"&&"reactEasyCrop_Contain",z==="horizontal-cover"&&"reactEasyCrop_Cover_Horizontal",z==="vertical-cover"&&"reactEasyCrop_Cover_Vertical",P)},r),{},{src:t,ref:this.imageRef,style:l(l({},v),{},{transform:n||`translate(${s}px, ${h}px) rotate(${c}deg) scale(${p})`}),onLoad:this.onMediaLoad})):i&&d.createElement("video",l(l({autoPlay:!0,playsInline:!0,loop:!0,muted:!0,className:O("reactEasyCrop_Video",z==="contain"&&"reactEasyCrop_Contain",z==="horizontal-cover"&&"reactEasyCrop_Cover_Horizontal",z==="vertical-cover"&&"reactEasyCrop_Cover_Vertical",P)},r),{},{ref:this.videoRef,onLoadedMetadata:this.onMediaLoad,style:l(l({},v),{},{transform:n||`translate(${s}px, ${h}px) rotate(${c}deg) scale(${p})`}),controls:!1}),(Array.isArray(i)?i:[{src:i}]).map(D=>d.createElement("source",l({key:D.src},D)))),this.state.cropSize&&d.createElement("div",l({ref:this.cropperRef,style:l(l({},C),{},{width:b?Math.round(this.state.cropSize.width):this.state.cropSize.width,height:b?Math.round(this.state.cropSize.height):this.state.cropSize.height}),tabIndex:0,onKeyDown:this.onKeyDown,onKeyUp:this.onKeyUp,"data-testid":"cropper",className:O("reactEasyCrop_CropArea",m==="round"&&"reactEasyCrop_CropAreaRound",x&&"reactEasyCrop_CropAreaGrid",L)},a)))}};F.defaultProps={zoom:1,rotation:0,aspect:4/3,maxZoom:Ut,minZoom:kt,cropShape:"rect",objectFit:"contain",showGrid:!0,style:{},classes:{},mediaProps:{},cropperProps:{},zoomSpeed:1,restrictPosition:!0,zoomWithScroll:!0,keyboardStep:Bt};F.getMousePoint=o=>({x:Number(o.clientX),y:Number(o.clientY)});F.getTouchPoint=o=>({x:Number(o.clientX),y:Number(o.clientY)});var Ht=F;function Gt(o){return new Promise((e,t)=>{const i=new Image;i.addEventListener("load",()=>e(i)),i.addEventListener("error",r=>t(r)),i.crossOrigin="anonymous",i.src=o})}async function Xt(o,e,t="image/png"){const i=await Gt(o),r=document.createElement("canvas");return r.width=Math.round(e.width),r.height=Math.round(e.height),r.getContext("2d").drawImage(i,e.x,e.y,e.width,e.height,0,0,r.width,r.height),new Promise((n,s)=>{r.toBlob(h=>{if(!h){s(new Error("Zuschneiden fehlgeschlagen"));return}n(h)},t)})}function Yt(o){return o==="image/jpeg"?"jpg":o==="image/webp"?"webp":"png"}function Vt({value:o,onChange:e,label:t="Bild",aspect:i}){const[r,a]=d.useState(!1),[n,s]=d.useState(""),[h,c]=d.useState(null),[p,m]=d.useState("image/png"),[x,b]=d.useState({x:0,y:0}),[S,C]=d.useState(1),[v,T]=d.useState(null),[L,P]=d.useState(i||1),z=f=>{m(f.type||"image/png"),b({x:0,y:0}),C(1),T(null),P(i||1),c(URL.createObjectURL(f))},D=f=>{var A;const w=(A=f.target.files)==null?void 0:A[0];f.target.value="",w&&(s(""),z(w))},ut=async()=>{if(o){s("");try{const w=await(await fetch(o)).blob();z(w)}catch{s("Bild konnte nicht zum Zuschneiden geladen werden.")}}},lt=({width:f,height:w})=>{!i&&f&&w&&P(f/w)},K=()=>{h&&URL.revokeObjectURL(h),c(null)},dt=async()=>{if(!(!h||!v)){a(!0),s("");try{const f=await Xt(h,v,p),w=new FormData;w.append("file",f,`zugeschnitten.${Yt(p)}`);const A=await ft.post("/uploads",w);e(A.path),K()}catch(f){s(f.message)}finally{a(!1)}}};return u.jsxs("div",{children:[u.jsx("label",{className:"mb-1 block text-sm font-medium text-neutral-700 dark:text-neutral-300",children:t}),u.jsxs("div",{className:"flex items-center gap-3",children:[o&&u.jsxs("div",{className:"relative",children:[u.jsx("img",{src:o,alt:"",className:"h-12 w-12 rounded-md object-cover"}),u.jsx("button",{type:"button",onClick:()=>e(null),title:"Bild entfernen","aria-label":"Bild entfernen",className:"absolute -right-1.5 -top-1.5 flex h-5 w-5 items-center justify-center rounded-full bg-red-600 text-xs font-bold leading-none text-white shadow hover:bg-red-700",children:"×"})]}),u.jsx("input",{type:"file",accept:"image/png,image/jpeg,image/webp",onChange:D,className:"text-sm"}),o&&u.jsx("button",{type:"button",onClick:ut,className:"rounded-md border border-neutral-300 px-2 py-1 text-xs font-medium text-neutral-600 hover:bg-neutral-50 dark:border-neutral-700 dark:text-neutral-300 dark:hover:bg-neutral-800",children:"Zuschneiden"}),r&&u.jsx("span",{className:"text-sm text-neutral-500",children:"Lädt hoch…"})]}),n&&u.jsx("p",{className:"mt-1 text-sm text-red-600",children:n}),h&&u.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4",children:u.jsxs("div",{className:"w-full max-w-lg rounded-xl bg-white p-4 dark:bg-neutral-900",children:[u.jsx("p",{className:"mb-3 text-sm font-semibold text-neutral-900 dark:text-white",children:"Bild zuschneiden"}),u.jsx("div",{className:"relative h-80 w-full overflow-hidden rounded-md bg-neutral-800 sm:h-96",children:u.jsx(Ht,{image:h,crop:x,zoom:S,aspect:L,onCropChange:b,onZoomChange:C,onCropComplete:(f,w)=>T(w),onMediaLoaded:lt})}),u.jsx("input",{type:"range",min:1,max:3,step:.01,value:S,onChange:f=>C(Number(f.target.value)),className:"mt-4 w-full"}),n&&u.jsx("p",{className:"mt-2 text-sm text-red-600",children:n}),u.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[u.jsx("button",{type:"button",onClick:K,disabled:r,className:"rounded-md border border-neutral-300 px-4 py-2 text-sm dark:border-neutral-700",children:"Abbrechen"}),u.jsx("button",{type:"button",onClick:dt,disabled:r||!v,className:"rounded-md bg-brand-500 px-4 py-2 text-sm font-semibold text-white hover:bg-brand-600 disabled:opacity-50",children:r?"Lädt hoch…":"Übernehmen"})]})]})})]})}export{Vt as I};