react-mobile-cropper
Version:
The react mobile cropper inspired by Android mobile croppers
3 lines (2 loc) • 31.2 kB
JavaScript
var ReactMobileCropper=function(t,e,i){"use strict";function a(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=a(i),o=function(){return o=Object.assign||function(t){for(var e,i=1,a=arguments.length;i<a;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},o.apply(this,arguments)};function n(t,e){var i="function"==typeof Symbol&&t[Symbol.iterator];if(!i)return t;var a,r,o=i.call(t),n=[];try{for(;(void 0===e||e-- >0)&&!(a=o.next()).done;)n.push(a.value)}catch(t){r={error:t}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(r)throw r.error}}return n}function h(t,e,i){if(i||2===arguments.length)for(var a,r=0,o=e.length;r<o;r++)!a&&r in e||(a||(a=Array.prototype.slice.call(e,0,r)),a[r]=e[r]);return t.concat(a||Array.prototype.slice.call(e))}var s,l={exports:{}};s=l,function(){var t={}.hasOwnProperty;function e(){for(var i=[],a=0;a<arguments.length;a++){var r=arguments[a];if(r){var o=typeof r;if("string"===o||"number"===o)i.push(r);else if(Array.isArray(r)){if(r.length){var n=e.apply(null,r);n&&i.push(n)}}else if("object"===o)if(r.toString===Object.prototype.toString)for(var h in r)t.call(r,h)&&r[h]&&i.push(h);else i.push(r.toString())}}return i.join(" ")}s.exports?(e.default=e,s.exports=e):window.classNames=e}();var c=l.exports,m=function(t){var e=t.className;return r.default.createElement("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16"},r.default.createElement("path",{fill:"#FFF",d:"M8 15.9c-.6 0-1-.4-1-1V1c0-.6.4-1 1-1s1 .4 1 1v13.9c0 .6-.4 1-1 1zm4-2.4h-.5c-.4 0-.8-.3-.8-.8s.3-.8.8-.8h.5c.4 0 .8.3.8.8s-.4.8-.8.8zm2.7 0h-.5c-.4 0-.8-.3-.8-.8 0-.3.2-.6.5-.7.1-.3.4-.5.7-.5.4 0 .8.3.8.8v.5c.1.4-.3.7-.7.7zm0-2.8c-.4 0-.8-.3-.8-.8v-.8c0-.4.3-.8.8-.8s.8.3.8.8v.8c0 .4-.4.8-.8.8zm0-3.3c-.4 0-.8-.3-.8-.8v-.7c0-.4.3-.8.8-.8s.8.3.8.8v.8c0 .4-.4.7-.8.7zm0-3.3c-.3 0-.6-.2-.7-.5-.3-.1-.5-.4-.5-.7 0-.4.3-.8.8-.8h.5c.4 0 .8.3.8.8v.5c-.1.4-.5.7-.9.7zM12 3.6h-.5c-.4 0-.8-.3-.8-.8s.3-.8.8-.8h.5c.4 0 .8.3.8.8s-.4.8-.8.8zM4.5 13.5H1.3c-.4 0-.8-.3-.8-.8V2.9c0-.4.3-.8.8-.8h3.2v1.5H2V12h2.5v1.5z"}))},d=function(t){var e=t.className;return r.default.createElement("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16"},r.default.createElement("path",{fill:"#FFF",d:"M12.5 11.8c.2.2.2.6 0 .9-1.1 1.1-2.8 1.8-4.5 1.8-3.7 0-6.5-2.8-6.5-6.5s3-6.5 6.5-6.5c1.7 0 3.3.7 4.5 1.8l1-1c.4-.4 1-.1 1 .4v3.8c0 .3-.3.6-.6.6h-3.7c-.5 0-.8-.7-.4-1L11 4.9c-.9-.9-1.9-1.3-3-1.3-3 0-5.4 3.1-4 6.2.7 1.6 2.3 2.6 4 2.6 1.2 0 2.2-.4 3-1.3.2-.2.6-.2.8 0l.7.7z"}))},f=function(t){var e=t.className;return r.default.createElement("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16"},r.default.createElement("path",{fill:"#FFF",d:"M3.5 11.8c-.2.2-.2.6 0 .9 1.1 1.1 2.8 1.8 4.5 1.8 3.7 0 6.5-2.8 6.5-6.5s-3-6.5-6.5-6.5c-1.7 0-3.3.7-4.5 1.8l-1-1c-.4-.4-1-.1-1 .4v3.8c0 .3.3.6.6.6h3.7c.5 0 .8-.7.4-1L5 4.9c.9-.9 1.9-1.3 3-1.3 3 0 5.4 3.1 4 6.2-.7 1.6-2.3 2.6-4 2.6-1.2 0-2.2-.4-3-1.3-.2-.2-.6-.2-.8 0l-.7.7z"}))},u=function(t){var e=t.className;return r.default.createElement("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16"},r.default.createElement("path",{fill:"#FFF",d:"M15 9H1c-.5 0-1-.5-1-1s.4-1 1-1h14c.6 0 1 .4 1 1s-.5 1-1 1zM3.1 12.7c-.4 0-.8-.3-.8-.8v-.5c0-.4.3-.8.8-.8s.8.3.8.8v.6c0 .4-.3.7-.8.7zM3.6 15.4h-.5c-.4 0-.8-.3-.8-.8v-.5c0-.4.3-.8.8-.8.3 0 .6.2.7.5.3.1.5.4.5.7.1.6-.2.9-.7.9zM10.1 15.4h-.8c-.4 0-.8-.3-.8-.8s.3-.8.8-.8h.8c.4 0 .8.3.8.8s-.4.8-.8.8zm-3.2 0H6c-.4 0-.8-.3-.8-.8s.3-.8.8-.8h.8c.4 0 .8.3.8.8s-.3.8-.7.8zM13 15.4h-.5c-.4 0-.8-.3-.8-.8 0-.3.2-.6.5-.7.1-.3.4-.5.7-.5.4 0 .8.3.8.8v.5c.1.4-.2.7-.7.7zM13 12.7c-.4 0-.8-.3-.8-.8v-.5c0-.4.3-.8.8-.8s.8.3.8.8v.6c0 .4-.3.7-.8.7z"}),r.default.createElement("g",null,r.default.createElement("path",{fill:"#FFF",d:"M13.8 4.5h-1.5V2H3.9v2.5H2.4V1.3c0-.4.3-.8.8-.8H13c.4 0 .8.3.8.8v3.2z"})))};function g(t,e,i){void 0===i&&(i=1);for(var a=-1,r=Math.max(Math.ceil((e-t)/(i||1)),0),o=new Array(r);r--;)o[++a]=t,t+=i;return o}var p=i.forwardRef((function(t,a){var o=t.from,s=t.to,l=t.value,m=t.step,d=void 0===m?2.5:m,f=t.thickness,u=void 0===f?2:f,p=t.onBlur,v=t.onChange,b=t.className,w=t.valueBarClassName,x=t.barsClassName,M=t.barClassName,A=t.highlightedBarClassName,H=t.zeroBarClassName,y=t.density,W=void 0===y?10:y,R=i.useRef(null),N=n(i.useState(!1),2),z=N[0],E=N[1],C=n(i.useState([]),2),O=C[0],_=C[1],S=function(){if(R.current){var t=R.current.clientWidth,e=t/W,i=Math.max(0,Math.floor(e/2)-Math.round((l-o)/d)),a=Math.max(0,Math.floor(e/2)-Math.round((s-l)/d)),r=h(h(h([],n(g(o-i*d,o,d)),!1),n(g(o,s+d,d)),!1),n(g(s+d,s+d+a*d,d)),!1),c=Math.abs(Math.ceil(e/2)*d);_(r.map((function(i){var a,r=Math.sign(i-l);if(Math.abs(i-l)/d<=Math.ceil(e/2)){var o=Math.sqrt(Math.pow(c,2)-Math.pow(l+r*c-i,2))/c;a=t/2+r*(t/2)*Math.pow(o,2.5)}else a=t/2+r*t/2;var n=0;return e>0&&Math.abs(i-l)/d<=Math.ceil(e/2)&&(n=Math.pow(Math.sqrt(Math.pow(c,2)-Math.pow(l-i,2))/c,4)),{value:i,highlighted:l<0&&i>=l&&i<=0||l>0&&i<=l&&i>=0,zero:0===i,opacity:n,translate:a-u/2}})))}};i.useEffect((function(){S()}),[W,u,o,s,l,d]),i.useImperativeHandle(a,(function(){return{refresh:S}}));return r.default.createElement("div",{className:c("rmc-rotate-component",b)},r.default.createElement(e.DraggableArea,{onMoveStart:function(){document.body.classList.add("dragging"),E(!0)},onMove:function(t){if(R.current){var e=R.current.clientWidth/W,i=-t.left/R.current.clientWidth*e*d;v&&v(l+i>s?s-l:l+i<o?o-l:i)}},onMoveEnd:function(){document.body.classList.remove("dragging"),E(!1),null==p||p()},useAnchor:!1},r.default.createElement("div",{className:c("rmc-rotate-component__bars",z&&"rmc-rotate-component__bars--dragging",x),ref:R},O.map((function(t){return r.default.createElement("div",{className:c("rmc-rotate-component__bar",t.zero&&"rmc-rotate-component__bar--zero",t.highlighted&&"rmc-rotate-component__bar--highlighted",M,t.highlighted&&A,t.zero&&H),key:t.value,style:{width:t.opacity?u:0,opacity:t.opacity,transform:"translate("+t.translate+"px, -50%)"}})})),r.default.createElement("div",{className:c("rmc-rotate-component__value",w)},r.default.createElement("div",{className:"rmc-rotate-component__value-number"},l.toFixed(1),"°")))))}));p.displayName="RotateComponent";var v=i.forwardRef((function(t,e){var a=t.className,o=t.buttonClassName,h=t.rotateComponentClassName,s=t.barClassName,l=t.highlightedBarClassName,g=t.zeroBarClassName,v=t.valueBarClassName,b=t.disabled,w=t.value,x=t.onRotate,M=t.onRotateEnd,A=t.onFlip,H=n(i.useState(0),2),y=H[0],W=H[1],R=n(i.useState(0),2),N=R[0],z=R[1],E=i.useRef(null);i.useLayoutEffect((function(){var t,e=Math.abs(w);t=e%90>45?(e-e%90+90)/90:e%90<45?(e-e%90)/90:y,(t=Math.sign(t)*t)!==y&&W(t),z(Math.sign(w)*(Math.abs(w)-90*Math.abs(t)))}),[w]),i.useImperativeHandle(e,(function(){return{refresh:function(){E.current&&E.current.refresh()}}}));return r.default.createElement("div",{className:c("rmc-navigation",a)},r.default.createElement("button",{type:"button",className:c("rmc-navigation__button",o),onClick:function(){A&&!b&&A(!0)}},r.default.createElement(m,null)),r.default.createElement("button",{type:"button",className:c("rmc-navigation__button",o),onClick:function(){x&&!b&&x(N>0?90-N:N<0?-N:90)}},r.default.createElement(d,null)),r.default.createElement(p,{ref:E,className:c("rmc-navigation__rotator",h),barClassName:s,zeroBarClassName:g,valueBarClassName:v,highlightedBarClassName:l,onChange:function(t){x&&!b&&x(t,{transitions:!1,interaction:!0,immediately:!0})},onBlur:M,from:-45,to:45,value:N}),r.default.createElement("button",{type:"button",className:c("rmc-navigation__button",o),onClick:function(){x&&!b&&x(N>0?-N:N<0?-90-N:-90)}},r.default.createElement(f,null)),r.default.createElement("button",{type:"button",className:c("rmc-navigation__button",o),onClick:function(){A&&!b&&A(!1,!0)}},r.default.createElement(u,null)))}));function b(t){return"function"==typeof t}function w(t){return void 0===t}v.displayName="Navigation";function x(t){var e=Number(t);return Number.isNaN(e)?t:e}function M(t){return"number"==typeof t}function A(t){return M(t)&&!function(t){return t!=t}(t)||function(t){return"string"==typeof t}(t)&&!Number.isNaN(parseFloat(t))&&isFinite(parseFloat(t))}function H(t,e,i){return void 0===i&&(i=.001),Math.abs(e-t)<i}function y(t,e,i){return!H(t,e,i)&&t>e}function W(t,e,i){return!H(t,e,i)&&t<e}function R(t){if(null===(e=t)||"object"!=typeof e)return t;var e,i={};return Array.isArray(t)?i=t.map((function(t){return R(t)})):Object.keys(t).forEach((function(e){return i[e]=R(t[e])})),i}function N(t,e,i){if(void 0===i&&(i=.001),M(t)&&M(e)&&H(t,e,i))return!0;if(t===e)return!0;if(t&&e&&"object"==typeof t&&"object"==typeof e){if(t.constructor!==e.constructor)return!1;var a,r=void 0;if(Array.isArray(t)){if((a=t.length)!=e.length)return!1;for(r=a;0!=r--;)if(!N(t[r],e[r],i))return!1;return!0}if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===e.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===e.toString();var o=Object.keys(t);if((a=o.length)!==Object.keys(e).length)return!1;for(r=a;0!=r--;)if(!Object.prototype.hasOwnProperty.call(e,o[r]))return!1;for(r=a;0!=r--;){var n=o[r];if(!N(t[n],e[n],i))return!1}return!0}return t!=t&&e!=e}var z,E,C,O,_=["left","right","top","bottom"],S=["left","right"],B=["top","bottom"];function j(t,e){return{left:t.left-e.left,top:t.top-e.top}}function P(t){return{left:t.left+t.width/2,top:t.top+t.height/2}}function F(t,e){return Math.pow(t.width-e.width,2)+Math.pow(t.height-e.height,2)}function I(t,e){return{left:t.left-e.left,top:t.top-e.top,width:t.width+e.left+e.right,height:t.height+e.top+e.bottom}}function k(t){return{left:-t.left,top:-t.top}}function L(t,e){return o(o({},t),{left:t.left+e.left,top:t.top+e.top})}function D(t){return{left:t.left,top:t.top,right:t.left+t.width,bottom:t.top+t.height}}function V(t,e,i,a){if(1!==e){if("left"in t||"top"in t){if(i){var r=P(t);return{width:t.width*e,height:t.height*e,left:t.left+t.width*(1-e)/2+(i.left-r.left)*(a||1-e),top:t.top+t.height*(1-e)/2+(i.top-r.top)*(a||1-e)}}return{width:t.width*e,height:t.height*e,left:t.left+t.width*(1-e)/2,top:t.top+t.height*(1-e)/2}}return{width:t.width*e,height:t.height*e}}return t}function T(t){return t.width/t.height}function q(t,e){return Math.min(e.maxWidth?e.maxWidth/t.width:1/0,e.maxHeight?e.maxHeight/t.height:1/0)}function G(t,e){var i;return e.minimum&&W(t,e.minimum)?i=e.minimum:e.maximum&&y(t,e.maximum)&&(i=e.maximum),i}function J(t,e){var i={left:0,top:0,right:0,bottom:0};return _.forEach((function(a){var r=e[a],o=D(t)[a];i[a]=void 0!==r&&void 0!==o?"left"===a||"top"===a?Math.max(0,r-o):Math.max(0,o-r):0})),i}function K(t,e){return V(t,function(t,e){var i=T(t),a=1;return e.minWidth>0&&e.minHeight>0?i>e.minWidth/e.minHeight?t.height<e.minHeight&&(a=e.minHeight/t.height):t.width<e.minWidth&&(a=e.minWidth/t.width):e.minWidth>0?t.width<e.minWidth&&(a=e.minWidth/t.width):e.minHeight>0&&t.height<e.minHeight&&(a=e.minHeight/t.height),e.maxWidth<1/0&&e.maxHeight<1/0?i>e.maxWidth/e.maxHeight?t.width>e.maxWidth&&(a=e.maxWidth/t.width):t.height>e.maxHeight&&(a=e.maxHeight/t.height):e.maxWidth<1/0?t.width>e.maxWidth&&(a=e.maxWidth/t.width):e.maxHeight<1/0&&t.height>e.maxHeight&&(a=e.maxHeight/t.height),a}(t,e))}function Q(t,e){var i=e*Math.PI/180;return{width:Math.abs(t.width*Math.cos(i))+Math.abs(t.height*Math.sin(i)),height:Math.abs(t.width*Math.sin(i))+Math.abs(t.height*Math.cos(i))}}function U(t,e,i){var a=e*Math.PI/180;return i?{left:(t.left-i.left)*Math.cos(a)-(t.top-i.top)*Math.sin(a)+i.left,top:(t.left-i.left)*Math.sin(a)+(t.top-i.top)*Math.cos(a)+i.top}:{left:t.left*Math.cos(a)-t.top*Math.sin(a),top:t.left*Math.sin(a)+t.top*Math.cos(a)}}function X(t){return{minWidth:0,minHeight:0,maxWidth:void 0!==t.right&&void 0!==t.left?t.right-t.left:1/0,maxHeight:void 0!==t.bottom&&void 0!==t.top?t.bottom-t.top:1/0}}function Y(t,e){var i={};return _.forEach((function(a){var r=t[a],o=e[a];void 0!==r&&void 0!==o?i[a]="left"===a||"top"===a?Math.max(r,o):Math.min(r,o):void 0!==o?i[a]=o:void 0!==r&&(i[a]=r)})),i}function Z(t,e){var i={left:0,top:0},a=J(t,e);return a.left&&a.left>0?i.left=a.left:a.right&&a.right>0&&(i.left=-a.right),a.top&&a.top>0?i.top=a.top:a.bottom&&a.bottom>0&&(i.top=-a.bottom),i}function $(t,e){return L(t,Z(t,e))}function tt(t){return void 0===t&&(t={}),M(t)?{minimum:t,maximum:t}:{minimum:A(t.minimum)?t.minimum:0,maximum:A(t.maximum)?t.maximum:1/0}}function et(t,e,i,a){var r=function(r){return t.reduce((function(t,o){var n=b(i)?i(o):i,h=n.maxHeight,s=n.maxWidth,l=n.minWidth,c=n.minHeight,m=tt(b(a)?a(o):a);return function(t,e){return(w(e.maxWidth)||!y(t.width,e.maxWidth))&&(w(e.maxHeight)||!y(t.height,e.maxHeight))&&(w(e.minHeight)||!W(t.height,e.minHeight))&&(w(e.minWidth)||!W(t.width,e.minWidth))}(o,r?{maxWidth:s,maxHeight:h}:{maxWidth:s,maxHeight:h,minWidth:l,minHeight:c})&&!G(T(o),m)&&o.width&&o.height&&(!t||W(F(o,e),F(t,e)))?o:t}),null)};return r()||r(!0)}function it(t){var e=o({},t);return e.minWidth>e.maxWidth&&(e.minWidth=e.maxWidth),e.minHeight>e.maxHeight&&(e.minHeight=e.maxHeight),e}function at(t,e){var i=t,a=o({minWidth:0,minHeight:0,maxWidth:1/0,maxHeight:1/0},e);return it({maxHeight:Math.min(i.maxHeight,a.maxHeight),minHeight:Math.max(i.minHeight,a.minHeight),maxWidth:Math.min(i.maxWidth,a.maxWidth),minWidth:Math.max(i.minWidth,a.minWidth)})}function rt(t){return Boolean(t&&t.visibleArea&&t.coordinates)}function ot(t,e){return function(t,e){var i=b(e.areaSizeRestrictions)?e.areaSizeRestrictions(t,e):e.areaSizeRestrictions;return i.maxWidth<1/0&&i.maxHeight<1/0&&(T(t.boundary)>i.maxWidth/i.maxHeight?i.maxHeight=i.maxWidth/T(t.boundary):i.maxWidth=i.maxHeight*T(t.boundary)),it(i)}(t,e)}function nt(t,e){return b(e.areaPositionRestrictions)?e.areaPositionRestrictions(t,e):e.areaPositionRestrictions}function ht(t,e){return function(t,e){var i=b(e.sizeRestrictions)?e.sizeRestrictions(t,e):e.sizeRestrictions,a=st(t,e),r={minWidth:A(i.minWidth)?x(i.minWidth):0,minHeight:A(i.minHeight)?x(i.minHeight):0,maxWidth:A(i.maxWidth)?x(i.maxWidth):1/0,maxHeight:A(i.maxHeight)?x(i.maxHeight):1/0};return void 0!==a.left&&void 0!==a.right&&(r.maxWidth=Math.min(r.maxWidth,a.right-a.left)),void 0!==a.bottom&&void 0!==a.top&&(r.maxHeight=Math.min(r.maxHeight,a.bottom-a.top)),it(r)}(t,e)}function st(t,e){return b(e.positionRestrictions)?e.positionRestrictions(t,e):e.positionRestrictions}function lt(t,e){return tt(b(e.aspectRatio)?e.aspectRatio(t,e):e.aspectRatio)}function ct(t){return t.imageSize&&t.imageSize.width&&t.imageSize.height?Q(t.imageSize,t.transforms.rotate):{width:0,height:0}}function mt(t){return R(t)}function dt(t,e,i){if(rt(t)){var a=mt(t),r=M(i)?i:i.angle,n=U(P(o({left:0,top:0},ct(t))),r);a.transforms.rotate+=r,a.coordinates=o(o({},(c={sizeRestrictions:ht(a,e),aspectRatio:lt(a,e),width:a.coordinates.width,height:a.coordinates.height},m=c.width,d=c.height,f=c.sizeRestrictions||{minWidth:0,minHeight:0,maxWidth:1/0,maxHeight:1/0},u=tt(c.aspectRatio),g={width:Math.max(f.minWidth,Math.min(f.maxWidth,m)),height:Math.max(f.minHeight,Math.min(f.maxHeight,d))},p=[g],u&&[u.minimum,u.maximum].forEach((function(t){t&&p.push({width:g.width,height:g.width/t},{width:g.height*t,height:g.height})})),et(p=p.map((function(t){return K(t,f)})),{width:m,height:d},f,u))),U(P(a.coordinates),r));var h=!M(i)&&i.center?i.center:P(t.coordinates),s=j(P(t.coordinates),U(P(t.coordinates),r,h)),l=ct(a);return a.coordinates.left-=n.left-l.width/2+a.coordinates.width/2-s.left,a.coordinates.top-=n.top-l.height/2+a.coordinates.height/2-s.top,a.visibleArea=K(a.visibleArea,at(ot(a,e),{minWidth:a.coordinates.width,minHeight:a.coordinates.height})),a.coordinates=$(a.coordinates,st(a,e)),a.visibleArea=L(a.visibleArea,j(P(a.coordinates),P(t.coordinates))),a.visibleArea=$(a.visibleArea,nt(a,e)),a}var c,m,d,f,u,g,p;return t}function ft(t,e,i){return i.rotate&&(t=dt(t,e,i.rotate)),i.flip&&(t=function(t,e,i,a){if(rt(t)){var r=mt(t),o=t.transforms.rotate,n=ct(t),h={horizontal:i,vertical:a};if(h.horizontal||h.vertical){var s=U({left:n.width/2,top:n.height/2},-o),l=U(P(r.coordinates),-o),c=U({left:h.horizontal?s.left-(l.left-s.left):l.left,top:h.vertical?s.top-(l.top-s.top):l.top},o);r.coordinates=L(r.coordinates,j(c,P(r.coordinates))),l=U(P(r.visibleArea),-o),c=U({left:h.horizontal?s.left-(l.left-s.left):l.left,top:h.vertical?s.top-(l.top-s.top):l.top},o),r.visibleArea=L(r.visibleArea,j(c,P(r.visibleArea))),r.visibleArea=$(r.visibleArea,nt(r,e))}return h.horizontal&&(r.transforms.flip.horizontal=!t.transforms.flip.horizontal),h.vertical&&(r.transforms.flip.vertical=!t.transforms.flip.vertical),r}return t}(t,e,i.flip.horizontal,i.flip.vertical)),(i.move||i.scale)&&(t=function(t,e,i){var a,r,o,n=i.scale,h=void 0===n?1:n,s=i.move,l=void 0===s?{}:s;if(rt(t)){var c=mt(t),m=1/(M(h)?h:h.factor),d=M(h)?void 0:h.center,f=!H(m,1),u=1,g=1;c.visibleArea=L(c.visibleArea,{left:l.left||0,top:l.top||0});var p=ht(c,e),v=st(c,e),b=ot(c,e),w={stencil:{minimum:Math.max(p.minWidth?p.minWidth/c.coordinates.width:0,p.minHeight?p.minHeight/c.coordinates.height:0),maximum:Math.min(p.maxWidth?p.maxWidth/c.coordinates.width:1/0,p.maxHeight?p.maxHeight/c.coordinates.height:1/0,q(c.coordinates,X(v)))},area:{maximum:q(c.visibleArea,b),minimum:(r=c.visibleArea,o=b,Math.max(o.minWidth?o.minWidth/r.width:0,o.minHeight?o.minHeight/r.height:0))}};m&&f&&(m<1?(g=Math.max(m,Math.max(w.area.minimum,w.stencil.minimum)))>1&&(g=1):m>1&&(g=Math.min(m,Math.min(w.area.maximum,w.stencil.maximum)))<1&&(g=1)),g&&(c.visibleArea=V(c.visibleArea,g,d));var x={left:t.coordinates.left-t.visibleArea.left,right:t.visibleArea.width+t.visibleArea.left-(t.coordinates.width+t.coordinates.left),top:t.coordinates.top-t.visibleArea.top,bottom:t.visibleArea.height+t.visibleArea.top-(t.coordinates.height+t.coordinates.top)};return c.visibleArea=$(c.visibleArea,{left:void 0!==v.left?v.left-x.left*g:void 0,top:void 0!==v.top?v.top-x.top*g:void 0,bottom:void 0!==v.bottom?v.bottom+x.bottom*g:void 0,right:void 0!==v.right?v.right+x.right*g:void 0}),c.visibleArea=$(c.visibleArea,nt(c,e)),c.coordinates.width=c.coordinates.width*g,c.coordinates.height=c.coordinates.height*g,c.coordinates.left=c.visibleArea.left+x.left*g,c.coordinates.top=c.visibleArea.top+x.top*g,c.coordinates=$(c.coordinates,Y(D(c.visibleArea),v)),f&&m&&(null===(a=e.transformImage)||void 0===a?void 0:a.adjustStencil)&&(m>1?u=Math.min(w.area.maximum,m)/g:m<1&&(u=Math.max(c.coordinates.height/c.visibleArea.height,c.coordinates.width/c.visibleArea.width,m/g)),1!==u&&(c.visibleArea=V(c.visibleArea,u,m>1?d:P(c.coordinates)),c.visibleArea=$(c.visibleArea,nt(c,e)),c.visibleArea=L(c.visibleArea,k(Z(c.coordinates,D(c.visibleArea)))))),c}return t}(t,e,i)),t}function ut(t){var e=t.coordinates,i=t.directions,a=t.positionRestrictions,r=t.sizeRestrictions,n=t.preserveRatio,h=t.allowedDirections,s=t.compensate,l=void 0===s||s,c=o({},i),m=I(e,c).width,d=I(e,c).height;m<0&&(c.left<0&&c.right<0?(c.left=-(e.width-r.minWidth)/(c.left/c.right),c.right=-(e.width-r.minWidth)/(c.right/c.left)):c.left<0?c.left=-(e.width-r.minWidth):c.right<0&&(c.right=-(e.width-r.minWidth))),d<0&&(c.top<0&&c.bottom<0?(c.top=-(e.height-r.minHeight)/(c.top/c.bottom),c.bottom=-(e.height-r.minHeight)/(c.bottom/c.top)):c.top<0?c.top=-(e.height-r.minHeight):c.bottom<0&&(c.bottom=-(e.height-r.minHeight)));var f=J(I(e,c),a),u=_.every((function(t){return!y(f[(e=t,{left:"right",top:"bottom",right:"left",bottom:"top"}[e])],0)||h[t];var e}));l&&u&&(f.left&&f.left>0&&0===f.right?(c.right+=f.left,c.left-=f.left):f.right&&f.right>0&&0===f.left&&(c.left+=f.right,c.right-=f.right),f.top&&f.top>0&&0===f.bottom?(c.bottom+=f.top,c.top-=f.top):f.bottom&&f.bottom>0&&0===f.top&&(c.top+=f.bottom,c.bottom-=f.bottom),f=J(I(e,c),a));var g={width:1/0,height:1/0,left:1/0,right:1/0,top:1/0,bottom:1/0};if(_.forEach((function(t){var e=f[t];e&&c[t]&&(g[t]=Math.max(0,1-e/c[t]))})),n){var p=Math.min.apply(Math,_.map((function(t){return g[t]})));p!==1/0&&_.forEach((function(t){c[t]*=p}))}else _.forEach((function(t){g[t]!==1/0&&(c[t]*=g[t])}));if(m=I(e,c).width,d=I(e,c).height,c.right+c.left&&(m>r.maxWidth?g.width=(r.maxWidth-e.width)/(c.right+c.left):m<r.minWidth&&(g.width=(r.minWidth-e.width)/(c.right+c.left))),c.bottom+c.top&&(d>r.maxHeight?g.height=(r.maxHeight-e.height)/(c.bottom+c.top):d<r.minHeight&&(g.height=(r.minHeight-e.height)/(c.bottom+c.top))),n){var v=Math.min(g.width,g.height);v!==1/0&&_.forEach((function(t){c[t]*=v}))}else g.width!==1/0&&S.forEach((function(t){c[t]*=g.width})),g.height!==1/0&&B.forEach((function(t){c[t]*=g.height}));return c}function gt(t,e,i){return H(e+i,0)?t/2:H(e,0)?0:H(i,0)?t:t*Math.abs(e/(e+i))}function pt(t,e,i,a){var r=a.aspectRatio,n=a.positionRestrictions,h=a.sizeRestrictions,s=o({},t);e=o({},e);var l=i.allowedDirections||{left:!0,right:!0,bottom:!0,top:!0};t.width<h.minWidth&&(e.left=0,e.right=0),t.height<h.minHeight&&(e.top=0,e.bottom=0),_.forEach((function(t){l[t]||(e[t]=0)}));var c=I(s,e=ut({coordinates:s,directions:e,sizeRestrictions:h,positionRestrictions:n,allowedDirections:l})).width,m=I(s,e).height,d=i.preserveAspectRatio?T(s):G(c/m,r);if(d){var f=i.respectDirection;if("width"!==f&&"height"!==f&&(f=s.width>=s.height||1===d?"width":"height"),"width"===f){var u=c/d-s.height;if(l.top&&l.bottom){var g=e.top,p=e.bottom;e.bottom=gt(u,p,g),e.top=gt(u,g,p)}else l.bottom?e.bottom=u:l.top?e.top=u:l.right?e.right=0:l.left&&(e.left=0)}else if("height"===f){var v=s.width-m*d;if(l.left&&l.right){var b=e.left,w=e.right;e.left=-gt(v,b,w),e.right=-gt(v,w,b)}else l.left?e.left=-v:l.right?e.right=-v:l.top?e.top=0:l.bottom&&(e.bottom=0)}e=ut({directions:e,coordinates:s,sizeRestrictions:h,positionRestrictions:n,preserveRatio:!0,compensate:i.compensate,allowedDirections:l})}return c=I(s,e).width,m=I(s,e).height,(d=i.preserveAspectRatio?T(s):G(c/m,r))&&y(Math.abs(d-c/m),0)&&_.forEach((function(t){e[t]=0})),function(t,e,i){var a=L(t,e);return i?$(a,i):a}({width:t.width+e.right+e.left,height:t.height+e.top+e.bottom,left:t.left,top:t.top},{left:-e.left,top:-e.top},n)}function vt(t,e){var i=e.toLowerCase();return{left:t.left+t.width*(-1!==i.indexOf("west")?1:-1!==i.indexOf("east")?0:.5),top:t.top+t.height*(-1!==i.indexOf("north")?1:-1!==i.indexOf("south")?0:.5)}}function bt(t){var e=t.toLowerCase();return{left:-1===e.indexOf("east"),top:-1===e.indexOf("south"),right:-1===e.indexOf("west"),bottom:-1===e.indexOf("north")}}function wt(t,e,i,a,r){var n=a.reference,h=function(t,e){var i=t.toLowerCase(),a={left:-1===i.indexOf("west")?e.left:-e.left,top:-e.top,right:e.left,bottom:e.top};["north","south","center"].every((function(t){return-1===i.indexOf(t)}))&&(a.top=0,a.bottom=0),["west","east","center"].every((function(t){return-1===i.indexOf(t)}))&&(a.left=0,a.right=0);var r=bt(t);return _.forEach((function(t){r[t]||(a[t]=0)})),a}(e,i),s=bt(e),l=pt(t,h,o(o({},a),{allowedDirections:s}),r);return n&&(l=L(l,j(vt(n,e),vt(l,e)))),$(l,r.positionRestrictions)}function xt(t,e,i){return i===O.Circle?function(t,e){return t}(t):function(t,e){return Q(t,e)}(t,e)}function Mt(t,e,i){var a=xt({width:e,height:1},t.angle,i);return T(t)>=T(a)?{minWidth:0,minHeight:0,maxHeight:t.height/a.height,maxWidth:t.height/a.height*e}:{minWidth:0,minHeight:0,maxHeight:t.width/a.width,maxWidth:t.width/a.width*e}}function At(t){var e=t.width,i=t.height,a=t.image,r=t.sizeRestrictions,o=t.boundingBox,n=void 0===o?O.Rectangle:o,h=tt(t.aspectRatio),s={width:Math.max(r.minWidth,e),height:Math.max(r.minHeight,i)},l=Mt(a,Math.min(h.maximum,Math.max(h.minimum,T(s))),n),c=[s,{width:Math.min(r.maxWidth,l.maxWidth),height:Math.min(r.maxHeight,l.maxHeight)}];return[h.minimum,h.maximum].forEach((function(t){if(t&&t!==1/0){var e=at(r,Mt(a,t,n)),i=Math.min(s.width,e.maxWidth),o=Math.min(s.height,e.maxHeight);c.push({width:i,height:i/t},{width:o*t,height:o})}})),c=c.map((function(t){return K(t,at(Mt(a,T(t),n),r))})),et(c,{width:e,height:i},(function(t){return at(r,Mt(a,T(t),n))}),h)}function Ht(t,e,i){void 0===i&&(i=O.Rectangle);var a=P(o({left:0,top:0},Q(e,-e.angle))),r=U(P(t),-e.angle,a),n=xt(t,e.angle,i),h=Z(o(o({},n),{left:r.left-n.width/2,top:r.top-n.height/2}),{left:a.left-e.width/2,top:a.top-e.height/2,right:a.left+e.width/2,bottom:a.top+e.height/2}),s=U({left:h.left,top:0},e.angle),l=U({left:0,top:h.top},e.angle);return{left:s.left+l.left,top:s.top+l.top}}function yt(t){return{width:t.imageSize.width,height:t.imageSize.height,angle:t.transforms.rotate}}function Wt(t,e){var i=function(t,e){return t.aspectRatio?{}:{aspectRatio:tt(b(e.aspectRatio)?e.aspectRatio():e.aspectRatio)}}({},e);return o({stencilBoundingBox:e.boundingBox},i)}function Rt(t,e,i){var a=i.flip,r=i.rotate,n=i.scale,h=i.move;return a&&(t=o(o({},t),{transforms:o(o({},t.transforms),{flip:{horizontal:a.horizontal?!t.transforms.flip.horizontal:t.transforms.flip.horizontal,vertical:a.vertical?!t.transforms.flip.vertical:t.transforms.flip.vertical}})})),t.coordinates&&(t.basis=a||n||h?void 0:t.basis||o({},t.coordinates)),ft(t,e,{rotate:r,move:h,scale:n})}function Nt(t,e,i,a,r){if(rt(t)){var n=mt(t),h=function(t){return t.coordinates?Math.min(t.coordinates.width,t.coordinates.height,20*function(t){return t.visibleArea?t.visibleArea.width/t.boundary.width:0}(t)):1}(n),s=ct(n),l=ht(n,e);n.coordinates=wt(n.coordinates,i,a,o(o({},r),{compensate:!1}),{positionRestrictions:Y(st(n,e),D(n.visibleArea)),sizeRestrictions:{maxWidth:Math.min(l.maxWidth,s.width,n.visibleArea.width),maxHeight:Math.min(l.maxHeight,s.height,n.visibleArea.height),minWidth:Math.max(Math.min(l.minWidth,n.visibleArea.width),h),minHeight:Math.max(Math.min(l.minHeight,n.visibleArea.height),h)},aspectRatio:lt(n,e)});var c=o({},n.coordinates),m=At({width:n.coordinates.width,height:n.coordinates.height,image:yt(n),boundingBox:e.stencilBoundingBox,aspectRatio:lt(n,e),sizeRestrictions:ht(n,e)});n.coordinates=o({left:P(c).left-m.width/2,top:P(c).top-m.height/2},m),y(Math.abs(c.height-n.coordinates.height),0)&&(n.visibleArea=V(n.visibleArea,n.visibleArea.height/(n.visibleArea.height+c.height-n.coordinates.height)));var d=Ht(n.coordinates,yt(n),e.stencilBoundingBox);return n.coordinates=L(n.coordinates,d),n.visibleArea=L(n.visibleArea,d),n}return t}function zt(t,e){var i=ct(t);return{width:t.visibleArea?t.visibleArea.width:i.width,height:t.visibleArea?t.visibleArea.height:i.height}}function Et(t,e,i){if(rt(t)&&i.immediately){var a=mt(t);"transformImage"!==i.name&&"transformImageEnd"!==i.name&&(N(a.coordinates,a.basis)||(a.basis=void 0));var r=e.stencilBoundingBox,n=void 0===r?O.Rectangle:r,h=a.basis?a.basis:a.coordinates,s=At({width:h.width,height:h.height,image:yt(t),aspectRatio:lt(a,e),sizeRestrictions:ht(a,e),boundingBox:n}),l=P(a.coordinates),c=P(o(o({},a.coordinates),s));return a.coordinates=L(o(o({},a.coordinates),s),j(l,c)),a.coordinates=(m=a.coordinates,d=yt(a),void 0===(f=n)&&(f=O.Rectangle),L(m,Ht(m,d,f))),a.visibleArea=L(a.visibleArea,k(Z(a.coordinates,D(a.visibleArea)))),a}var m,d,f;return t}function Ct(t,e,i){if(rt(t)&&i.immediately){var a=mt(t),r={width:0,height:0};return T(a.boundary)>T(a.coordinates)?(r.height=a.boundary.height,r.width=r.height*T(a.coordinates)):(r.width=a.boundary.width,r.height=r.width*T(a.coordinates)),a.visibleArea=V(a.visibleArea,a.coordinates.width*a.boundary.width/(a.visibleArea.width*r.width)),T(a.boundary)>T(a.coordinates)?(a.visibleArea.top=a.coordinates.top,a.visibleArea.left=a.coordinates.left-a.visibleArea.width/2+a.coordinates.width/2):(a.visibleArea.left=a.coordinates.left,a.visibleArea.top=a.coordinates.top-a.visibleArea.height/2+a.coordinates.height/2),a}return t}!function(t){t.fillArea="fillArea",t.fitArea="fitArea",t.stencil="stencil",t.none="none"}(z||(z={})),function(t){t.coordinates="coordinates",t.visibleArea="visibleArea"}(E||(E={})),function(t){t.limit="limit",t.zoom="zoom",t.unsafe="unsafe"}(C||(C={})),function(t){t.Circle="circle",t.Rectangle="rectangle"}(O||(O={}));var Ot=function(t){var e=t.className;return r.default.createElement("svg",{className:e,width:"38",height:"38",viewBox:"0 0 38 38",xmlns:"http://www.w3.org/2000/svg"},r.default.createElement("g",{fill:"none",fillRule:"evenodd"},r.default.createElement("g",{transform:"translate(1 1)",strokeWidth:"2"},r.default.createElement("circle",{strokeOpacity:".5",cx:"18",cy:"18",r:"18"}),r.default.createElement("path",{d:"M36 18c0-9.94-8.06-18-18-18"},r.default.createElement("animateTransform",{attributeName:"transform",type:"rotate",from:"0 18 18",to:"360 18 18",dur:"1s",repeatCount:"indefinite"})))))},_t=function(t){var a=t.cropper,o=t.children,n=t.loaded,h=t.loading,s=t.className,l=t.spinnerClassName,m=t.navigation,d=t.navigationProps,f=void 0===d?{}:d,u=i.useRef(null),g=a.getState(),p=a.getTransitions(),b=a.getTransforms().rotate;return i.useEffect((function(){var t;null===(t=u.current)||void 0===t||t.refresh()}),[null==g?void 0:g.boundary.width,null==g?void 0:g.boundary.height]),r.default.createElement("div",{className:c("rmc-cropper-wrapper",m&&"rmc-cropper-wrapper--with-navigation",s)},r.default.createElement(e.CropperFade,{className:"rmc-cropper-wrapper__fade",visible:n},o,m&&r.default.createElement(v,{ref:u,value:b,onRotate:a.rotateImage,onRotateEnd:a.transformImageEnd,onFlip:a.flipImage,className:c("rmc-cropper-wrapper__navigation",f.className),buttonClassName:f.buttonClassName,barClassName:f.barClassName,valueBarClassName:f.valueBarClassName,zeroBarClassName:f.zeroBarClassName,highlightedBarClassName:f.highlightedBarClassName,disabled:p.active})),r.default.createElement(Ot,{className:c("rmc-cropper-wrapper__spinner",h&&"rmc-cropper-wrapper__spinner--visible",l)}))},St=i.forwardRef((function(t,a){var n=t.className,h=t.spinnerClassName,s=t.navigation,l=void 0===s||s,m=t.stencilProps,d=void 0===m?{}:m,f=t.navigationProps,u=void 0===f?{}:f,g=t.wrapperComponent,p=t.imageRestriction,v=void 0===p?e.ImageRestriction.stencil:p,b=function(t,e){var i={};for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&e.indexOf(a)<0&&(i[a]=t[a]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(a=Object.getOwnPropertySymbols(t);r<a.length;r++)e.indexOf(a[r])<0&&Object.prototype.propertyIsEnumerable.call(t,a[r])&&(i[a[r]]=t[a[r]])}return i}(t,["className","spinnerClassName","navigation","stencilProps","navigationProps","wrapperComponent","imageRestriction"]),w=i.useRef(null),x=g||_t;return r.default.createElement(e.Cropper,o({},b,{ref:e.mergeRefs([a,w]),stencilConstraints:Wt,stencilProps:o(o({grid:!0},d),{movable:!1}),wrapperComponent:x,wrapperProps:{navigationProps:u,navigation:l,spinnerClassName:h},imageRestriction:e.ImageRestriction.none,className:c("rmc-cropper",n),defaultSize:zt,transformImageAlgorithm:Rt,transitions:!0,postProcess:v===e.ImageRestriction.none?Ct:[Et,Ct],resizeCoordinatesAlgorithm:v===e.ImageRestriction.none?void 0:Nt}))}));return St.displayName="Cropper",Object.defineProperty(t,"CircleStencil",{enumerable:!0,get:function(){return e.CircleStencil}}),Object.defineProperty(t,"RectangleStencil",{enumerable:!0,get:function(){return e.RectangleStencil}}),t.Cropper=St,t.Navigation=v,t.RotateComponent=p,Object.defineProperty(t,"__esModule",{value:!0}),t}({},ReactAdvancedCropper,React);
//# sourceMappingURL=index.global.js.map