82 lines
33 KiB
JavaScript
82 lines
33 KiB
JavaScript
import{g as $e,r as d,j as C,aV as qe,df as de,B as Ge,dg as Xe,u as Ye,w as te,al as Ve}from"./index-B-sDl1ER.js";import{_ as Ke,d as M,a as ce,c as Je}from"./tslib.es6-BaFViOhq.js";import{U as Fe}from"./index-D3yl9SWR.js";var he,_e;function Qe(){if(_e)return he;_e=1;var s=!1,n,e,t,o,i,r,a,p,c,u,h,f,v,y,_;function w(){if(!s){s=!0;var R=navigator.userAgent,m=/(?:MSIE.(\d+\.\d+))|(?:(?:Firefox|GranParadiso|Iceweasel).(\d+\.\d+))|(?:Opera(?:.+Version.|.)(\d+\.\d+))|(?:AppleWebKit.(\d+(?:\.\d+)?))|(?:Trident\/\d+\.\d+.*rv:(\d+\.\d+))/.exec(R),l=/(Mac OS X)|(Windows)|(Linux)/.exec(R);if(f=/\b(iPhone|iP[ao]d)/.exec(R),v=/\b(iP[ao]d)/.exec(R),u=/Android/i.exec(R),y=/FBAN\/\w+;/i.exec(R),_=/Mobile/i.exec(R),h=!!/Win64/.exec(R),m){n=m[1]?parseFloat(m[1]):m[5]?parseFloat(m[5]):NaN,n&&document&&document.documentMode&&(n=document.documentMode);var g=/(?:Trident\/(\d+.\d+))/.exec(R);r=g?parseFloat(g[1])+4:n,e=m[2]?parseFloat(m[2]):NaN,t=m[3]?parseFloat(m[3]):NaN,o=m[4]?parseFloat(m[4]):NaN,o?(m=/(?:Chrome\/(\d+\.\d+))/.exec(R),i=m&&m[1]?parseFloat(m[1]):NaN):i=NaN}else n=e=t=i=o=NaN;if(l){if(l[1]){var b=/(?:Mac OS X (\d+(?:[._]\d+)?))/.exec(R);a=b?parseFloat(b[1].replace("_",".")):!0}else a=!1;p=!!l[2],c=!!l[3]}else a=p=c=!1}}var N={ie:function(){return w()||n},ieCompatibilityMode:function(){return w()||r>n},ie64:function(){return N.ie()&&h},firefox:function(){return w()||e},opera:function(){return w()||t},webkit:function(){return w()||o},safari:function(){return N.webkit()},chrome:function(){return w()||i},windows:function(){return w()||p},osx:function(){return w()||a},linux:function(){return w()||c},iphone:function(){return w()||f},mobile:function(){return w()||f||v||u||_},nativeApp:function(){return w()||y},android:function(){return w()||u},ipad:function(){return w()||v}};return he=N,he}var fe,Ee;function et(){if(Ee)return fe;Ee=1;var s=!!(typeof window<"u"&&window.document&&window.document.createElement),n={canUseDOM:s,canUseWorkers:typeof Worker<"u",canUseEventListeners:s&&!!(window.addEventListener||window.attachEvent),canUseViewport:s&&!!window.screen,isInWorker:!s};return fe=n,fe}var me,ze;function tt(){if(ze)return me;ze=1;var s=et(),n;s.canUseDOM&&(n=document.implementation&&document.implementation.hasFeature&&document.implementation.hasFeature("","")!==!0);function e(t,o){if(!s.canUseDOM||o&&!("addEventListener"in document))return!1;var i="on"+t,r=i in document;if(!r){var a=document.createElement("div");a.setAttribute(i,"return;"),r=typeof a[i]=="function"}return!r&&n&&t==="wheel"&&(r=document.implementation.hasFeature("Events.wheel","3.0")),r}return me=e,me}var ve,De;function ot(){if(De)return ve;De=1;var s=Qe(),n=tt(),e=10,t=40,o=800;function i(r){var a=0,p=0,c=0,u=0;return"detail"in r&&(p=r.detail),"wheelDelta"in r&&(p=-r.wheelDelta/120),"wheelDeltaY"in r&&(p=-r.wheelDeltaY/120),"wheelDeltaX"in r&&(a=-r.wheelDeltaX/120),"axis"in r&&r.axis===r.HORIZONTAL_AXIS&&(a=p,p=0),c=a*e,u=p*e,"deltaY"in r&&(u=r.deltaY),"deltaX"in r&&(c=r.deltaX),(c||u)&&r.deltaMode&&(r.deltaMode==1?(c*=t,u*=t):(c*=o,u*=o)),c&&!a&&(a=c<1?-1:1),u&&!p&&(p=u<1?-1:1),{spinX:a,spinY:p,pixelX:c,pixelY:u}}return i.getEventType=function(){return s.firefox()?"DOMMouseScroll":n("wheel")?"wheel":"mousewheel"},ve=i,ve}var ge,Pe;function rt(){return Pe||(Pe=1,ge=ot()),ge}var nt=rt();const it=$e(nt);function at(s,n,e,t,o,i){i===void 0&&(i=0);var r=V(s,n,i),a=r.width,p=r.height,c=Math.min(a,e),u=Math.min(p,t);return c>u*o?{width:u*o,height:u}:{width:c,height:c/o}}function st(s){return s.width>s.height?s.width/s.naturalWidth:s.height/s.naturalHeight}function oe(s,n,e,t,o){o===void 0&&(o=0);var i=V(n.width,n.height,o),r=i.width,a=i.height;return{x:Me(s.x,r,e.width,t),y:Me(s.y,a,e.height,t)}}function Me(s,n,e,t){var o=n*t/2-e/2;return le(s,-o,o)}function Ae(s,n){return Math.sqrt(Math.pow(s.y-n.y,2)+Math.pow(s.x-n.x,2))}function Te(s,n){return Math.atan2(n.y-s.y,n.x-s.x)*180/Math.PI}function ct(s,n,e,t,o,i,r){i===void 0&&(i=0),r===void 0&&(r=!0);var a=r?pt:ut,p=V(n.width,n.height,i),c=V(n.naturalWidth,n.naturalHeight,i),u={x:a(100,((p.width-e.width/o)/2-s.x/o)/p.width*100),y:a(100,((p.height-e.height/o)/2-s.y/o)/p.height*100),width:a(100,e.width/p.width*100/o),height:a(100,e.height/p.height*100/o)},h=Math.round(a(c.width,u.width*c.width/100)),f=Math.round(a(c.height,u.height*c.height/100)),v=c.width>=c.height*t,y=v?{width:Math.round(f*t),height:f}:{width:h,height:Math.round(h/t)},_=M(M({},y),{x:Math.round(a(c.width-y.width,u.x*c.width/100)),y:Math.round(a(c.height-y.height,u.y*c.height/100))});return{croppedAreaPercentages:u,croppedAreaPixels:_}}function pt(s,n){return Math.min(s,Math.max(0,n))}function ut(s,n){return n}function lt(s,n,e,t,o,i){var r=V(n.width,n.height,e),a=le(t.width/r.width*(100/s.width),o,i),p={x:a*r.width/2-t.width/2-r.width*a*(s.x/100),y:a*r.height/2-t.height/2-r.height*a*(s.y/100)};return{crop:p,zoom:a}}function dt(s,n,e){var t=st(n);return e.height>e.width?e.height/(s.height*t):e.width/(s.width*t)}function ht(s,n,e,t,o,i){e===void 0&&(e=0);var r=V(n.naturalWidth,n.naturalHeight,e),a=le(dt(s,n,t),o,i),p=t.height>t.width?t.height/s.height:t.width/s.width,c={x:((r.width-s.width)/2-s.x)*p,y:((r.height-s.height)/2-s.y)*p};return{crop:c,zoom:a}}function Ne(s,n){return{x:(n.x+s.x)/2,y:(n.y+s.y)/2}}function ft(s){return s*Math.PI/180}function V(s,n,e){var t=ft(e);return{width:Math.abs(Math.cos(t)*s)+Math.abs(Math.sin(t)*n),height:Math.abs(Math.sin(t)*s)+Math.abs(Math.cos(t)*n)}}function le(s,n,e){return Math.min(Math.max(s,n),e)}function pe(){for(var s=[],n=0;n<arguments.length;n++)s[n]=arguments[n];return s.filter(function(e){return typeof e=="string"&&e.length>0}).join(" ").trim()}var mt=`.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 */
|
||
}
|
||
|
||
.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;
|
||
}
|
||
`,vt=1,gt=3,wt=1,Ct=(function(s){Ke(n,s);function n(){var e=s!==null&&s.apply(this,arguments)||this;return e.cropperRef=d.createRef(),e.imageRef=d.createRef(),e.videoRef=d.createRef(),e.containerPosition={x:0,y:0},e.containerRef=null,e.styleRef=null,e.containerRect=null,e.mediaSize={width:0,height:0,naturalWidth:0,naturalHeight:0},e.dragStartPosition={x:0,y:0},e.dragStartCrop={x:0,y:0},e.gestureZoomStart=0,e.gestureRotationStart=0,e.isTouching=!1,e.lastPinchDistance=0,e.lastPinchRotation=0,e.rafDragTimeout=null,e.rafPinchTimeout=null,e.wheelTimer=null,e.currentDoc=typeof document<"u"?document:null,e.currentWindow=typeof window<"u"?window:null,e.resizeObserver=null,e.previousCropSize=null,e.isInitialized=!1,e.state={cropSize:null,hasWheelJustStarted:!1,mediaObjectFit:void 0},e.initResizeObserver=function(){if(!(typeof window.ResizeObserver>"u"||!e.containerRef)){var t=!0;e.resizeObserver=new window.ResizeObserver(function(o){if(t){t=!1;return}e.computeSizes()}),e.resizeObserver.observe(e.containerRef)}},e.preventZoomSafari=function(t){return t.preventDefault()},e.cleanEvents=function(){e.currentDoc&&(e.currentDoc.removeEventListener("mousemove",e.onMouseMove),e.currentDoc.removeEventListener("mouseup",e.onDragStopped),e.currentDoc.removeEventListener("touchmove",e.onTouchMove),e.currentDoc.removeEventListener("touchend",e.onDragStopped),e.currentDoc.removeEventListener("gesturechange",e.onGestureChange),e.currentDoc.removeEventListener("gestureend",e.onGestureEnd),e.currentDoc.removeEventListener("scroll",e.onScroll))},e.clearScrollEvent=function(){e.containerRef&&e.containerRef.removeEventListener("wheel",e.onWheel),e.wheelTimer&&clearTimeout(e.wheelTimer)},e.onMediaLoad=function(){var t=e.computeSizes();t&&(e.previousCropSize=t,e.emitCropData(),e.setInitialCrop(t),e.isInitialized=!0),e.props.onMediaLoaded&&e.props.onMediaLoaded(e.mediaSize)},e.setInitialCrop=function(t){if(e.props.initialCroppedAreaPercentages){var o=lt(e.props.initialCroppedAreaPercentages,e.mediaSize,e.props.rotation,t,e.props.minZoom,e.props.maxZoom),i=o.crop,r=o.zoom;e.props.onCropChange(i),e.props.onZoomChange&&e.props.onZoomChange(r)}else if(e.props.initialCroppedAreaPixels){var a=ht(e.props.initialCroppedAreaPixels,e.mediaSize,e.props.rotation,t,e.props.minZoom,e.props.maxZoom),i=a.crop,r=a.zoom;e.props.onCropChange(i),e.props.onZoomChange&&e.props.onZoomChange(r)}},e.computeSizes=function(){var t,o,i,r,a,p,c=e.imageRef.current||e.videoRef.current;if(c&&e.containerRef){e.containerRect=e.containerRef.getBoundingClientRect(),e.saveContainerPosition();var u=e.containerRect.width/e.containerRect.height,h=((t=e.imageRef.current)===null||t===void 0?void 0:t.naturalWidth)||((o=e.videoRef.current)===null||o===void 0?void 0:o.videoWidth)||0,f=((i=e.imageRef.current)===null||i===void 0?void 0:i.naturalHeight)||((r=e.videoRef.current)===null||r===void 0?void 0:r.videoHeight)||0,v=c.offsetWidth<h||c.offsetHeight<f,y=h/f,_=void 0;if(v)switch(e.state.mediaObjectFit){default:case"contain":_=u>y?{width:e.containerRect.height*y,height:e.containerRect.height}:{width:e.containerRect.width,height:e.containerRect.width/y};break;case"horizontal-cover":_={width:e.containerRect.width,height:e.containerRect.width/y};break;case"vertical-cover":_={width:e.containerRect.height*y,height:e.containerRect.height};break}else _={width:c.offsetWidth,height:c.offsetHeight};e.mediaSize=M(M({},_),{naturalWidth:h,naturalHeight:f}),e.props.setMediaSize&&e.props.setMediaSize(e.mediaSize);var w=e.props.cropSize?e.props.cropSize:at(e.mediaSize.width,e.mediaSize.height,e.containerRect.width,e.containerRect.height,e.props.aspect,e.props.rotation);return(((a=e.state.cropSize)===null||a===void 0?void 0:a.height)!==w.height||((p=e.state.cropSize)===null||p===void 0?void 0:p.width)!==w.width)&&e.props.onCropSizeChange&&e.props.onCropSizeChange(w),e.setState({cropSize:w},e.recomputeCropPosition),e.props.setCropSize&&e.props.setCropSize(w),w}},e.saveContainerPosition=function(){if(e.containerRef){var t=e.containerRef.getBoundingClientRect();e.containerPosition={x:t.left,y:t.top}}},e.onMouseDown=function(t){e.currentDoc&&(t.preventDefault(),e.currentDoc.addEventListener("mousemove",e.onMouseMove),e.currentDoc.addEventListener("mouseup",e.onDragStopped),e.saveContainerPosition(),e.onDragStart(n.getMousePoint(t)))},e.onMouseMove=function(t){return e.onDrag(n.getMousePoint(t))},e.onScroll=function(t){e.currentDoc&&(t.preventDefault(),e.saveContainerPosition())},e.onTouchStart=function(t){e.currentDoc&&(e.isTouching=!0,!(e.props.onTouchRequest&&!e.props.onTouchRequest(t))&&(e.currentDoc.addEventListener("touchmove",e.onTouchMove,{passive:!1}),e.currentDoc.addEventListener("touchend",e.onDragStopped),e.saveContainerPosition(),t.touches.length===2?e.onPinchStart(t):t.touches.length===1&&e.onDragStart(n.getTouchPoint(t.touches[0]))))},e.onTouchMove=function(t){t.preventDefault(),t.touches.length===2?e.onPinchMove(t):t.touches.length===1&&e.onDrag(n.getTouchPoint(t.touches[0]))},e.onGestureStart=function(t){e.currentDoc&&(t.preventDefault(),e.currentDoc.addEventListener("gesturechange",e.onGestureChange),e.currentDoc.addEventListener("gestureend",e.onGestureEnd),e.gestureZoomStart=e.props.zoom,e.gestureRotationStart=e.props.rotation)},e.onGestureChange=function(t){if(t.preventDefault(),!e.isTouching){var o=n.getMousePoint(t),i=e.gestureZoomStart-1+t.scale;if(e.setNewZoom(i,o,{shouldUpdatePosition:!0}),e.props.onRotationChange){var r=e.gestureRotationStart+t.rotation;e.props.onRotationChange(r)}}},e.onGestureEnd=function(t){e.cleanEvents()},e.onDragStart=function(t){var o,i,r=t.x,a=t.y;e.dragStartPosition={x:r,y:a},e.dragStartCrop=M({},e.props.crop),(i=(o=e.props).onInteractionStart)===null||i===void 0||i.call(o)},e.onDrag=function(t){var o=t.x,i=t.y;e.currentWindow&&(e.rafDragTimeout&&e.currentWindow.cancelAnimationFrame(e.rafDragTimeout),e.rafDragTimeout=e.currentWindow.requestAnimationFrame(function(){if(e.state.cropSize&&!(o===void 0||i===void 0)){var r=o-e.dragStartPosition.x,a=i-e.dragStartPosition.y,p={x:e.dragStartCrop.x+r,y:e.dragStartCrop.y+a},c=e.props.restrictPosition?oe(p,e.mediaSize,e.state.cropSize,e.props.zoom,e.props.rotation):p;e.props.onCropChange(c)}}))},e.onDragStopped=function(){var t,o;e.isTouching=!1,e.cleanEvents(),e.emitCropData(),(o=(t=e.props).onInteractionEnd)===null||o===void 0||o.call(t)},e.onWheel=function(t){if(e.currentWindow&&!(e.props.onWheelRequest&&!e.props.onWheelRequest(t))){t.preventDefault();var o=n.getMousePoint(t),i=it(t).pixelY,r=e.props.zoom-i*e.props.zoomSpeed/200;e.setNewZoom(r,o,{shouldUpdatePosition:!0}),e.state.hasWheelJustStarted||e.setState({hasWheelJustStarted:!0},function(){var a,p;return(p=(a=e.props).onInteractionStart)===null||p===void 0?void 0:p.call(a)}),e.wheelTimer&&clearTimeout(e.wheelTimer),e.wheelTimer=e.currentWindow.setTimeout(function(){return e.setState({hasWheelJustStarted:!1},function(){var a,p;return(p=(a=e.props).onInteractionEnd)===null||p===void 0?void 0:p.call(a)})},250)}},e.getPointOnContainer=function(t,o){var i=t.x,r=t.y;if(!e.containerRect)throw new Error("The Cropper is not mounted");return{x:e.containerRect.width/2-(i-o.x),y:e.containerRect.height/2-(r-o.y)}},e.getPointOnMedia=function(t){var o=t.x,i=t.y,r=e.props,a=r.crop,p=r.zoom;return{x:(o+a.x)/p,y:(i+a.y)/p}},e.setNewZoom=function(t,o,i){var r=i===void 0?{}:i,a=r.shouldUpdatePosition,p=a===void 0?!0:a;if(!(!e.state.cropSize||!e.props.onZoomChange)){var c=le(t,e.props.minZoom,e.props.maxZoom);if(p){var u=e.getPointOnContainer(o,e.containerPosition),h=e.getPointOnMedia(u),f={x:h.x*c-u.x,y:h.y*c-u.y},v=e.props.restrictPosition?oe(f,e.mediaSize,e.state.cropSize,c,e.props.rotation):f;e.props.onCropChange(v)}e.props.onZoomChange(c)}},e.getCropData=function(){if(!e.state.cropSize)return null;var t=e.props.restrictPosition?oe(e.props.crop,e.mediaSize,e.state.cropSize,e.props.zoom,e.props.rotation):e.props.crop;return ct(t,e.mediaSize,e.state.cropSize,e.getAspect(),e.props.zoom,e.props.rotation,e.props.restrictPosition)},e.emitCropData=function(){var t=e.getCropData();if(t){var o=t.croppedAreaPercentages,i=t.croppedAreaPixels;e.props.onCropComplete&&e.props.onCropComplete(o,i),e.props.onCropAreaChange&&e.props.onCropAreaChange(o,i)}},e.emitCropAreaChange=function(){var t=e.getCropData();if(t){var o=t.croppedAreaPercentages,i=t.croppedAreaPixels;e.props.onCropAreaChange&&e.props.onCropAreaChange(o,i)}},e.recomputeCropPosition=function(){var t,o;if(e.state.cropSize){var i=e.props.crop;if(e.isInitialized&&(!((t=e.previousCropSize)===null||t===void 0)&&t.width)&&(!((o=e.previousCropSize)===null||o===void 0)&&o.height)){var r=Math.abs(e.previousCropSize.width-e.state.cropSize.width)>1e-6||Math.abs(e.previousCropSize.height-e.state.cropSize.height)>1e-6;if(r){var a=e.state.cropSize.width/e.previousCropSize.width,p=e.state.cropSize.height/e.previousCropSize.height;i={x:e.props.crop.x*a,y:e.props.crop.y*p}}}var c=e.props.restrictPosition?oe(i,e.mediaSize,e.state.cropSize,e.props.zoom,e.props.rotation):i;e.previousCropSize=e.state.cropSize,e.props.onCropChange(c),e.emitCropData()}},e.onKeyDown=function(t){var o,i,r=e.props,a=r.crop,p=r.onCropChange,c=r.keyboardStep,u=r.zoom,h=r.rotation,f=c;if(e.state.cropSize){t.shiftKey&&(f*=.2);var v=M({},a);switch(t.key){case"ArrowUp":v.y-=f,t.preventDefault();break;case"ArrowDown":v.y+=f,t.preventDefault();break;case"ArrowLeft":v.x-=f,t.preventDefault();break;case"ArrowRight":v.x+=f,t.preventDefault();break;default:return}e.props.restrictPosition&&(v=oe(v,e.mediaSize,e.state.cropSize,u,h)),t.repeat||(i=(o=e.props).onInteractionStart)===null||i===void 0||i.call(o),p(v)}},e.onKeyUp=function(t){var o,i;switch(t.key){case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":t.preventDefault();break;default:return}e.emitCropData(),(i=(o=e.props).onInteractionEnd)===null||i===void 0||i.call(o)},e}return n.prototype.componentDidMount=function(){!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.computeSizes),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=mt,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))},n.prototype.componentWillUnmount=function(){var e,t;!this.currentDoc||!this.currentWindow||(typeof window.ResizeObserver>"u"&&this.currentWindow.removeEventListener("resize",this.computeSizes),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),this.containerRef&&this.containerRef.removeEventListener("gesturestart",this.preventZoomSafari),this.styleRef&&((t=this.styleRef.parentNode)===null||t===void 0||t.removeChild(this.styleRef)),this.cleanEvents(),this.props.zoomWithScroll&&this.clearScrollEvent())},n.prototype.componentDidUpdate=function(e){var t,o,i,r,a,p,c,u,h;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)!==((o=this.props.cropSize)===null||o===void 0?void 0:o.height)||((i=e.cropSize)===null||i===void 0?void 0:i.width)!==((r=this.props.cropSize)===null||r===void 0?void 0:r.width)?this.computeSizes():(((a=e.crop)===null||a===void 0?void 0:a.x)!==((p=this.props.crop)===null||p===void 0?void 0:p.x)||((c=e.crop)===null||c===void 0?void 0:c.y)!==((u=this.props.crop)===null||u===void 0?void 0:u.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&&((h=this.videoRef.current)===null||h===void 0||h.load());var f=this.getObjectFit();f!==this.state.mediaObjectFit&&this.setState({mediaObjectFit:f},this.computeSizes)},n.prototype.getAspect=function(){var e=this.props,t=e.cropSize,o=e.aspect;return t?t.width/t.height:o},n.prototype.getObjectFit=function(){var e,t,o,i;if(this.props.objectFit==="cover"){var r=this.imageRef.current||this.videoRef.current;if(r&&this.containerRef){this.containerRect=this.containerRef.getBoundingClientRect();var a=this.containerRect.width/this.containerRect.height,p=((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,c=((o=this.imageRef.current)===null||o===void 0?void 0:o.naturalHeight)||((i=this.videoRef.current)===null||i===void 0?void 0:i.videoHeight)||0,u=p/c;return u<a?"horizontal-cover":"vertical-cover"}return"horizontal-cover"}return this.props.objectFit},n.prototype.onPinchStart=function(e){var t=n.getTouchPoint(e.touches[0]),o=n.getTouchPoint(e.touches[1]);this.lastPinchDistance=Ae(t,o),this.lastPinchRotation=Te(t,o),this.onDragStart(Ne(t,o))},n.prototype.onPinchMove=function(e){var t=this;if(!(!this.currentDoc||!this.currentWindow)){var o=n.getTouchPoint(e.touches[0]),i=n.getTouchPoint(e.touches[1]),r=Ne(o,i);this.onDrag(r),this.rafPinchTimeout&&this.currentWindow.cancelAnimationFrame(this.rafPinchTimeout),this.rafPinchTimeout=this.currentWindow.requestAnimationFrame(function(){var a=Ae(o,i),p=t.props.zoom*(a/t.lastPinchDistance);t.setNewZoom(p,r,{shouldUpdatePosition:!1}),t.lastPinchDistance=a;var c=Te(o,i),u=t.props.rotation+(c-t.lastPinchRotation);t.props.onRotationChange&&t.props.onRotationChange(u),t.lastPinchRotation=c})}},n.prototype.render=function(){var e=this,t,o=this.props,i=o.image,r=o.video,a=o.mediaProps,p=o.cropperProps,c=o.transform,u=o.crop,h=u.x,f=u.y,v=o.rotation,y=o.zoom,_=o.cropShape,w=o.showGrid,N=o.roundCropAreaPixels,R=o.style,m=R.containerStyle,l=R.cropAreaStyle,g=R.mediaStyle,b=o.classes,E=b.containerClassName,L=b.cropAreaClassName,j=b.mediaClassName,O=(t=this.state.mediaObjectFit)!==null&&t!==void 0?t:this.getObjectFit();return d.createElement("div",{onMouseDown:this.onMouseDown,onTouchStart:this.onTouchStart,ref:function(F){return e.containerRef=F},"data-testid":"container",style:m,className:pe("reactEasyCrop_Container",E)},i?d.createElement("img",M({alt:"",className:pe("reactEasyCrop_Image",O==="contain"&&"reactEasyCrop_Contain",O==="horizontal-cover"&&"reactEasyCrop_Cover_Horizontal",O==="vertical-cover"&&"reactEasyCrop_Cover_Vertical",j)},a,{src:i,ref:this.imageRef,style:M(M({},g),{transform:c||"translate(".concat(h,"px, ").concat(f,"px) rotate(").concat(v,"deg) scale(").concat(y,")")}),onLoad:this.onMediaLoad})):r&&d.createElement("video",M({autoPlay:!0,playsInline:!0,loop:!0,muted:!0,className:pe("reactEasyCrop_Video",O==="contain"&&"reactEasyCrop_Contain",O==="horizontal-cover"&&"reactEasyCrop_Cover_Horizontal",O==="vertical-cover"&&"reactEasyCrop_Cover_Vertical",j)},a,{ref:this.videoRef,onLoadedMetadata:this.onMediaLoad,style:M(M({},g),{transform:c||"translate(".concat(h,"px, ").concat(f,"px) rotate(").concat(v,"deg) scale(").concat(y,")")}),controls:!1}),(Array.isArray(r)?r:[{src:r}]).map(function(S){return d.createElement("source",M({key:S.src},S))})),this.state.cropSize&&d.createElement("div",M({ref:this.cropperRef,style:M(M({},l),{width:N?Math.round(this.state.cropSize.width):this.state.cropSize.width,height:N?Math.round(this.state.cropSize.height):this.state.cropSize.height}),tabIndex:0,onKeyDown:this.onKeyDown,onKeyUp:this.onKeyUp,"data-testid":"cropper",className:pe("reactEasyCrop_CropArea",_==="round"&&"reactEasyCrop_CropAreaRound",w&&"reactEasyCrop_CropAreaGrid",L)},p)))},n.defaultProps={zoom:1,rotation:0,aspect:4/3,maxZoom:gt,minZoom:vt,cropShape:"rect",objectFit:"contain",showGrid:!0,style:{},classes:{},mediaProps:{},cropperProps:{},zoomSpeed:1,restrictPosition:!0,zoomWithScroll:!0,keyboardStep:wt},n.getMousePoint=function(e){return{x:Number(e.clientX),y:Number(e.clientY)}},n.getTouchPoint=function(e){return{x:Number(e.clientX),y:Number(e.clientY)}},n})(d.Component);const U="img-crop",we=1,re=.1,ue=0,Ie=-180,Oe=180,Ce=1,ne=.01,xt=d.forwardRef((s,n)=>{const{cropperRef:e,zoomSlider:t,rotationSlider:o,aspectSlider:i,showReset:r,resetBtnText:a,modalImage:p,aspect:c,minZoom:u,maxZoom:h,minAspect:f,maxAspect:v,cropShape:y,showGrid:_,cropperProps:w}=s,[N,R]=d.useState({x:0,y:0}),[m,l]=d.useState(we),[g,b]=d.useState(ue),[E,L]=d.useState(c),j=d.useRef({width:0,height:0,x:0,y:0}),O=d.useCallback((ie,ae)=>{j.current=ae},[]),S=d.useRef(c);S.current!==c&&(S.current=c,L(c));const F=m!==we||g!==ue||E!==c,X=()=>{l(we),b(ue),L(c)};d.useImperativeHandle(n,()=>({rotation:g,cropPixelsRef:j,onReset:X}));const K="[display:flex] [align-items:center] [width:60%] [margin-inline:auto]",Z="[display:flex] [align-items:center] [justify-content:center] [height:32px] [width:32px] [background:transparent] [border:0] [font-family:inherit] [font-size:18px] [cursor:pointer] disabled:[opacity:20%] disabled:[cursor:default]",J="[flex:1]";return C.jsxs(C.Fragment,{children:[C.jsx(Ct,Object.assign({},w,{ref:e,image:p,crop:N,zoom:m,rotation:g,aspect:E,minZoom:u,maxZoom:h,zoomWithScroll:t,cropShape:y,showGrid:_,onCropChange:R,onZoomChange:l,onRotationChange:b,onCropComplete:O,classes:{containerClassName:`${U}-container ![position:relative] [width:100%] [height:40vh] [&~section:first-of-type]:[margin-top:16px] [&~section:last-of-type]:[margin-bottom:16px]`,mediaClassName:`${U}-media`}})),t&&C.jsxs("section",{className:`${U}-control ${U}-control-zoom ${K}`,children:[C.jsx("button",{className:Z,onClick:()=>l(+(m-re).toFixed(1)),disabled:m-re<u,children:"-"}),C.jsx(de,{className:J,min:u,max:h,step:re,value:m,onChange:l}),C.jsx("button",{className:Z,onClick:()=>l(+(m+re).toFixed(1)),disabled:m+re>h,children:"+"})]}),o&&C.jsxs("section",{className:`${U}-control ${U}-control-rotation ${K}`,children:[C.jsx("button",{className:`${Z} [font-size:16px]`,onClick:()=>b(g-Ce),disabled:g===Ie,children:"↺"}),C.jsx(de,{className:J,min:Ie,max:Oe,step:Ce,value:g,onChange:b}),C.jsx("button",{className:`${Z} [font-size:16px]`,onClick:()=>b(g+Ce),disabled:g===Oe,children:"↻"})]}),i&&C.jsxs("section",{className:`${U}-control ${U}-control-aspect ${K}`,children:[C.jsx("button",{className:Z,onClick:()=>L(+(E-ne).toFixed(2)),disabled:E-ne<f,children:"↕"}),C.jsx(de,{className:J,min:f,max:v,step:ne,value:E,onChange:L}),C.jsx("button",{className:Z,onClick:()=>L(+(E+ne).toFixed(2)),disabled:E+ne>v,children:"↔"})]}),r&&(t||o||i)&&C.jsx(Ge,{className:"[position:absolute] [bottom:20px]",style:F?{}:{opacity:.3,pointerEvents:"none"},onClick:X,children:a})]})});var yt=d.memo(xt),bt="/*! tailwindcss v4.2.1 | MIT License | https://tailwindcss.com */.visible{visibility:visible}.\\!\\[position\\:relative\\]{position:relative!important}.\\[position\\:absolute\\]{position:absolute}.\\[bottom\\:20px\\]{bottom:20px}.container{width:100%}.\\[margin-inline\\:auto\\]{margin-inline:auto}.\\[display\\:flex\\]{display:flex}.grid{display:grid}.\\[height\\:32px\\]{height:32px}.\\[height\\:40vh\\]{height:40vh}.\\[width\\:32px\\]{width:32px}.\\[width\\:60\\%\\]{width:60%}.\\[width\\:100\\%\\]{width:100%}.\\[flex\\:1\\]{flex:1}.\\[cursor\\:pointer\\]{cursor:pointer}.\\[align-items\\:center\\]{align-items:center}.\\[justify-content\\:center\\]{justify-content:center}.\\[font-family\\:inherit\\]{font-family:inherit}.\\[font-size\\:16px\\]{font-size:16px}.\\[font-size\\:18px\\]{font-size:18px}.\\[background\\:transparent\\]{background:transparent}.\\[border\\:0\\]{border:0}.disabled\\:\\[cursor\\:default\\]{&:disabled{cursor:default}}.disabled\\:\\[opacity\\:20\\%\\]{&:disabled{opacity:20%}}.\\[\\&\\~section\\:first-of-type\\]\\:\\[margin-top\\:16px\\]{&~section:first-of-type{margin-top:16px}}.\\[\\&\\~section\\:last-of-type\\]\\:\\[margin-bottom\\:16px\\]{&~section:last-of-type{margin-bottom:16px}}";(function(){if(typeof document>"u")return;const s=document.createElement("style"),n=document.querySelector('meta[name="csp-nonce"]');n&&n.content&&s.setAttribute("nonce",n.content),s.textContent=bt,document.head.appendChild(s)})();const Rt=(s,n)=>{var e,t;const o=s.split(".").map(Number),i=n.split(".").map(Number),r=Math.max(o.length,i.length);for(let a=0;a<r;a++){const p=(e=o[a])!==null&&e!==void 0?e:0,c=(t=i[a])!==null&&t!==void 0?t:0;if(p>c)return!0;if(p<c)return!1}return!0},St=d.forwardRef((s,n)=>{const{quality:e=.4,fillColor:t="white",zoomSlider:o=!0,rotationSlider:i=!1,aspectSlider:r=!1,showReset:a=!1,resetText:p,aspect:c=1,minZoom:u=1,maxZoom:h=3,minAspect:f=.5,maxAspect:v=2,cropShape:y="rect",showGrid:_=!1,cropperProps:w,modalClassName:N,modalTitle:R,modalWidth:m,modalOk:l,modalCancel:g,onModalOk:b,onModalCancel:E,modalProps:L,beforeCrop:j,children:O}=s,S=d.useRef({});S.current.onModalOk=b,S.current.onModalCancel=E,S.current.beforeCrop=j;const F=d.useRef(null),X=d.useCallback(z=>{var A;const D=document.createElement("canvas"),x=D.getContext("2d"),W=(((A=z?.getRootNode)===null||A===void 0?void 0:A.call(z))||document).querySelector(`.${U}-media`),{width:P,height:T,x:$,y:q}=F.current.cropPixelsRef.current;if(i&&F.current.rotation!==ue){const{naturalWidth:B,naturalHeight:Y}=W,Q=F.current.rotation*(Math.PI/180),ee=Math.abs(Math.sin(Q)),G=Math.abs(Math.cos(Q)),k=B*G+Y*ee,I=Y*G+B*ee;D.width=k,D.height=I,x.fillStyle=t,x.fillRect(0,0,k,I);const Re=k/2,Se=I/2;x.translate(Re,Se),x.rotate(Q),x.translate(-Re,-Se);const Ue=(k-B)/2,Be=(I-Y)/2;x.drawImage(W,0,0,B,Y,Ue,Be,B,Y);const He=x.getImageData(0,0,k,I);D.width=P,D.height=T,x.putImageData(He,-$,-q)}else D.width=P,D.height=T,x.fillStyle=t,x.fillRect(0,0,P,T),x.drawImage(W,$,q,P,T,0,0,P,T);return D},[t,i]),[K,Z]=d.useState(!1),[J,ie]=d.useState(""),ae=d.useRef(void 0),xe=d.useRef(void 0),se=d.useCallback(z=>ce(void 0,[z],void 0,function*({beforeUpload:A,file:D,resolve:x,reject:H}){const W=D;if(typeof A!="function"){x(W);return}try{const P=yield A(D,[D]);x(P===!1?!1:P!==!0&&P||W)}catch(P){H(P)}}),[]),ye=d.useCallback(z=>((A,D)=>new Promise((x,H)=>ce(void 0,void 0,void 0,function*(){let W=A;if(typeof S.current.beforeCrop=="function")try{const T=yield S.current.beforeCrop(A,D);if(T===!1)return se({beforeUpload:z,file:A,resolve:x,reject:H});T!==!0&&(W=T||A)}catch{return se({beforeUpload:z,file:A,resolve:x,reject:H})}const P=new FileReader;P.addEventListener("load",()=>{typeof P.result=="string"&&(Z(!0),setTimeout(()=>{ie(P.result)},10))}),P.readAsDataURL(W),ae.current=()=>{var T,$;Z(!1),ie(""),F.current.onReset();let q=!1;($=(T=S.current).onModalCancel)===null||$===void 0||$.call(T,B=>{x(B),q=!0}),q||x(Fe.LIST_IGNORE)},xe.current=T=>ce(void 0,void 0,void 0,function*(){Z(!1),ie(""),F.current.onReset();const $=X(T.target),{type:q,name:B,uid:Y}=W;$.toBlob(Q=>ce(void 0,void 0,void 0,function*(){const ee=new File([Q],B,{type:q});Object.assign(ee,{uid:Y}),se({beforeUpload:z,file:ee,resolve:G=>{var k,I;x(G),(I=(k=S.current).onModalOk)===null||I===void 0||I.call(k,G)},reject:G=>{var k,I;H(G),(I=(k=S.current).onModalOk)===null||I===void 0||I.call(k,G)}})}),q,e)})}))),[X,e,se]),We=d.useCallback(z=>{const A=Array.isArray(z)?z[0]:z,D=A.props,{beforeUpload:x,accept:H}=D,W=Je(D,["beforeUpload","accept"]);return Object.assign(Object.assign({},A),{props:Object.assign(Object.assign({},W),{accept:H||"image/*",beforeUpload:ye(x)})})},[ye]),je=d.useMemo(()=>{const z={};return m!==void 0&&(z.width=m),l!==void 0&&(z.okText=l),g!==void 0&&(z.cancelText=g),z},[g,l,m]),ke=`${U}-modal${N?` ${N}`:""}`,be=(typeof window>"u"?"":window.navigator.language)==="zh-CN",Le=R||(be?"编辑图片":"Edit image"),Ze=p||(be?"重置":"Reset");return C.jsxs(C.Fragment,{children:[We(O),C.jsx(qe,Object.assign({},L,je,{open:K,title:Le,onCancel:ae.current,onOk:xe.current,wrapClassName:ke,destroyOnHidden:!0},Rt(Xe,"6.3.1")?{mask:{closable:!1}}:{maskClosable:!0},{children:C.jsx(yt,{ref:F,cropperRef:n,zoomSlider:o,rotationSlider:i,aspectSlider:r,showReset:a,resetBtnText:Ze,modalImage:J,aspect:c,minZoom:u,maxZoom:h,minAspect:f,maxAspect:v,cropShape:y,showGrid:_,cropperProps:w})}))]})}),Pt=({action:s,value:n,onChange:e,mode:t="single",disabled:o=!1,maxCount:i,maxWidth:r=1920,maxHeight:a=1080,maxSize:p=5,croppable:c=!1,cropperOptions:u})=>{const{t:h}=Ye(),[f,v]=d.useState([]),y=d.useMemo(()=>i||(t==="single"?1:9),[t,i]),_=l=>({uid:l.id?.toString()||`${l.id}`,name:l.file_name||`image-${l.id}`,status:"done",url:l.preview_url,response:{success:!0,data:l,message:"Upload success"}});d.useEffect(()=>{if(!n){v([]);return}const g=(Array.isArray(n)?n:[n]).map(_);v(g)},[n]);const w=d.useCallback(l=>new Promise((g,b)=>{if(!l.type.startsWith("image/")){te.error(h("xinForm.imageUploader.error.notImage")),b(!1);return}if(!(l.size/1024/1024<p)){te.error(h("xinForm.imageUploader.error.sizeExceeded",{maxSize:p})),b(!1);return}const j=new FileReader;j.readAsDataURL(l),j.onload=O=>{const S=document.createElement("img");S.src=O.target?.result,S.onload=()=>{const F=S.width<=r,X=S.height<=a;if(!F||!X){te.error(h("xinForm.imageUploader.error.dimensionExceeded",{maxWidth:r,maxHeight:a})),b(!1);return}g(!0)},S.onerror=()=>{te.error(h("xinForm.imageUploader.error.loadFailed")),b(!1)}},j.onerror=()=>{te.error(h("xinForm.imageUploader.error.readFailed")),b(!1)}}),[p,r,a]),N=({fileList:l})=>{if(l.length!==0&&(v(l),l.every(g=>g.status==="done"||g.status==="error"))){const g=l.filter(E=>E.status==="done"&&E.response).map(E=>E.response.data);e?.(t==="single"?g[0]:g);const b=l.filter(E=>E.status==="error");v([...g.map(_),...b])}},R=d.useMemo(()=>C.jsxs("button",{style:{border:0,background:"none"},type:"button",children:[C.jsx(Ve,{}),C.jsx("div",{style:{marginTop:8},children:h("xinForm.imageUploader.uploadText")})]}),[h]),m=C.jsx(Fe,{listType:"picture-card",name:"file",fileList:f,beforeUpload:w,onChange:N,disabled:o,maxCount:y,multiple:t==="multiple",headers:{Authorization:`Bearer ${localStorage.getItem("token")}`},onRemove:l=>{v(f.filter(g=>g.uid!=l.uid))},action:"/index.php"+s,accept:"image/*",children:f.length>=y?null:R});return C.jsx(C.Fragment,{children:c&&t==="single"?C.jsx(St,{...u,children:m}):m})};export{Pt as I};
|