UNPKG

sp-image-editor

Version:

React component version of filerobot image editor (FIE).

1 lines 2.57 kB
import _defineProperty from"@babel/runtime/helpers/defineProperty";import _slicedToArray from"@babel/runtime/helpers/slicedToArray";function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}import compareRatios from"../../../utils/compareRatios";import restrictNumber from"../../../utils/restrictNumber";import toPrecisedFloat from"../../../utils/toPrecisedFloat";export var boundDragging=function(a,b){var c=b.width-(2*a.radiusX||a.width),d=b.height-(2*a.radiusY||a.height);return{x:toPrecisedFloat(Math.min(Math.max(a.x,0),c)),y:toPrecisedFloat(Math.min(Math.max(a.y,0),d))}};export var getPositionByPlaceLabel=function(a,b,c){var d=a.split("-"),e=_slicedToArray(d,2),f=e[0],g=e[1],h={x:0,y:0};return"center"===f?h.y=b.height/2-c.height/2:"bottom"===f&&(h.y=b.height-c.height),"center"===g?h.x=b.width/2-c.width/2:"right"===g&&(h.x=b.width-c.width),h};export var boundResizing=function(a,b,c,d){var e=4<arguments.length&&void 0!==arguments[4]?arguments[4]:{},f={x:toPrecisedFloat(c.abstractX*c.scaledBy),y:toPrecisedFloat(c.abstractY*c.scaledBy),width:toPrecisedFloat(c.width*(e.noScale?1:c.scaledBy)),height:toPrecisedFloat(c.height*(e.noScale?1:c.scaledBy))},g=_objectSpread({},b);if(b.x<f.x&&(g.x=f.x,g.width=a.x-f.x+a.width),b.y<f.y&&(g.y=f.y,g.height=a.y-f.y+a.height),g.x+g.width>f.x+f.width&&(g.width=f.x+f.width-g.x),g.y+g.height>f.y+f.height&&(g.height=f.y+f.height-g.y),"number"==typeof d&&!compareRatios(g.width/g.height,d)){var h=g.height*d,i=g.width/d;toPrecisedFloat(g.y+i)<=f.y+f.height?g.height=i:g.width=h}if((e.minWidth&&g.width<=e.minWidth||e.maxWidth&&g.width>=e.maxWidth)&&(g.width=restrictNumber(g.width,e.minWidth,e.maxWidth),g.x=a.x,g.y=a.y,"number"==typeof d&&(g.height=g.width/d)),(e.minHeight&&b.height<=e.minHeight||e.maxHeight&&b.height>=e.maxHeight)&&(g.height=restrictNumber(g.height,e.minHeight,e.maxHeight),g.x=a.x,g.y=a.y,"number"==typeof d&&(g.width=g.height*d)),"string"==typeof e.lockCropAreaAt){var j=getPositionByPlaceLabel(e.lockCropAreaAt,f,g),k=j.x,l=j.y;g.x=k,g.y=l}return g};