From d89eaf018ec497d342196b3e3ec6848a6d71ec25 Mon Sep 17 00:00:00 2001 From: Dominic Tobias Date: Tue, 13 Nov 2018 19:30:29 +0000 Subject: [PATCH] Build --- demo/demo.js | 11 ++++++++--- dist/ReactCrop.js | 39 +++++++++++++++++++++++++++------------ dist/ReactCrop.min.js | 2 +- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/demo/demo.js b/demo/demo.js index 5dc2cdb..61ca2c3 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -15,9 +15,10 @@ function loadEditView(dataUrl) { x: 20, y: 10, width: 40, - aspect: 16 / 9, + height: 40, + // aspect: 16 / 9, }, - maxHeight: 80, + disabled: false, } onButtonClick = () => { @@ -70,7 +71,11 @@ function loadEditView(dataUrl) { return (
100&&(r.height=100-e.y,r.width=r.height*e.aspect/t),e.x+(r.width||e.width)>100&&(r.width=100-e.x,r.height=r.width/e.aspect*t),r}function f(e,t){return e&&e.aspect&&(!e.width&&e.height||e.width&&!e.height)?p(e,t.naturalWidth/t.naturalHeight):e}function l(e,t){if(!e||!t)return null;var r=Math.round(e.naturalWidth*(t.x/100)),o=Math.round(e.naturalHeight*(t.y/100)),a=Math.round(e.naturalWidth*(t.width/100)),n=Math.round(e.naturalHeight*(t.height/100));return{x:r,y:o,width:d(a,0,e.naturalWidth-r),height:d(n,0,e.naturalHeight-o)}}function g(e,t,r){var o=m({},t),a=!1;o.x+o.width>100?(o.width=t.width+(100-(t.x+t.width)),o.x=t.x+(100-(t.x+o.width)),a=!0):o.x<0&&(o.width=t.x+t.width,o.x=0,a=!0),a&&t.aspect&&(o.height=o.width/t.aspect*r,e.y>o.y&&(o.y=t.y+(t.height-o.height)));var n=!1;return o.y+o.height>100?(o.height=t.height+(100-(t.y+t.height)),o.y=t.y+(100-(t.y+o.height)),n=!0):o.y<0&&(o.height=t.y+t.height,o.y=0,n=!0),n&&t.aspect&&(o.width=o.height*t.aspect/r,o.x-1?(e.x=c.x,e.y=c.y,e.width=c.width,e.height=c.height):t.xOrds.indexOf(o)>-1?(e.x=c.x,e.width=c.width):t.yOrds.indexOf(o)>-1&&(e.y=c.y,e.height=c.height),r.lastYCrossover=r.yCrossOver,this.crossOverCheck(),e}},{key:"straightenYPath",value:function(e){var t=this.evData,r=t.ord,o=t.cropOffset,a=t.cropStartWidth/100*this.imageRef.width,n=t.cropStartHeight/100*this.imageRef.height,i=void 0,s=void 0;return"nw"===r||"se"===r?(i=n/a,s=o.top-o.left*i):(i=-n/a,s=o.top+(n-o.left*i)),i*e+s}},{key:"createCropSelection",value:function(){var e=this,t=this.props.disabled,r=this.getCropStyle();return w.default.createElement("div",{ref:function(t){e.cropSelectRef=t},style:r,className:"ReactCrop__crop-selection",onMouseDown:this.onCropMouseTouchDown,onTouchStart:this.onCropMouseTouchDown,role:"presentation"},!t&&w.default.createElement("div",{className:"ReactCrop__drag-elements"},w.default.createElement("div",{className:"ReactCrop__drag-bar ord-n","data-ord":"n"}),w.default.createElement("div",{className:"ReactCrop__drag-bar ord-e","data-ord":"e"}),w.default.createElement("div",{className:"ReactCrop__drag-bar ord-s","data-ord":"s"}),w.default.createElement("div",{className:"ReactCrop__drag-bar ord-w","data-ord":"w"}),w.default.createElement("div",{className:"ReactCrop__drag-handle ord-nw","data-ord":"nw"}),w.default.createElement("div",{className:"ReactCrop__drag-handle ord-n","data-ord":"n"}),w.default.createElement("div",{className:"ReactCrop__drag-handle ord-ne","data-ord":"ne"}),w.default.createElement("div",{className:"ReactCrop__drag-handle ord-e","data-ord":"e"}),w.default.createElement("div",{className:"ReactCrop__drag-handle ord-se","data-ord":"se"}),w.default.createElement("div",{className:"ReactCrop__drag-handle ord-s","data-ord":"s"}),w.default.createElement("div",{className:"ReactCrop__drag-handle ord-sw","data-ord":"sw"}),w.default.createElement("div",{className:"ReactCrop__drag-handle ord-w","data-ord":"w"})))}},{key:"makeNewCrop",value:function(){return m({},t.defaultCrop,this.props.crop)}},{key:"crossOverCheck",value:function(){var e=this.evData;(!e.xCrossOver&&-Math.abs(e.cropStartWidth)-e.xDiffPc>=0||e.xCrossOver&&-Math.abs(e.cropStartWidth)-e.xDiffPc<=0)&&(e.xCrossOver=!e.xCrossOver),(!e.yCrossOver&&-Math.abs(e.cropStartHeight)-e.yDiffPc>=0||e.yCrossOver&&-Math.abs(e.cropStartHeight)-e.yDiffPc<=0)&&(e.yCrossOver=!e.yCrossOver);var t=e.xCrossOver!==e.startXCrossOver,r=e.yCrossOver!==e.startYCrossOver;e.inversedXOrd=!!t&&u(e.ord),e.inversedYOrd=!!r&&u(e.ord)}},{key:"render",value:function(){var e=this,t=this.props,r=t.children,o=t.className,n=t.crossorigin,i=t.crop,s=t.disabled,c=t.imageAlt,d=t.onImageError,u=t.src,p=t.style,f=t.imageStyle,l=this.state.cropIsActive,g=void 0;h(i)&&(g=this.createCropSelection());var v=["ReactCrop"];return l&&v.push("ReactCrop--active"),i&&(i.aspect&&v.push("ReactCrop--fixed-aspect"),!l||i.width&&i.height||v.push("ReactCrop--crop-invisible")),s&&v.push("ReactCrop--disabled"),o&&v.push.apply(v,a(o.split(" "))),w.default.createElement("div",{ref:function(t){e.componentRef=t},className:v.join(" "),style:p,onTouchStart:this.onComponentMouseTouchDown,onMouseDown:this.onComponentMouseTouchDown,role:"presentation",tabIndex:"1",onKeyDown:this.onComponentKeyDown},w.default.createElement("img",{ref:function(t){e.imageRef=t},crossOrigin:n,className:"ReactCrop__image",style:f,src:u,onLoad:function(t){return e.onImageLoad(t.target)},onError:d,alt:c}),g,r)}}]),t}(y.PureComponent);R.xOrds=["e","w"],R.yOrds=["n","s"],R.xyOrds=["nw","ne","se","sw"],R.arrowKey={left:37,up:38,right:39,down:40},R.nudgeStep=.2,R.defaultCrop={x:0,y:0,width:0,height:0},R.propTypes={className:x.default.string,crossorigin:x.default.string,children:x.default.oneOfType([x.default.arrayOf(x.default.node),x.default.node]),crop:x.default.shape({aspect:x.default.number,x:x.default.number,y:x.default.number,width:x.default.number,height:x.default.number}),disabled:x.default.bool,imageAlt:x.default.string,imageStyle:x.default.shape({}),keepSelection:x.default.bool,minWidth:x.default.number,minHeight:x.default.number,maxWidth:x.default.number,maxHeight:x.default.number,onChange:x.default.func.isRequired,onImageError:x.default.func,onComplete:x.default.func,onImageLoaded:x.default.func,onDragStart:x.default.func,onDragEnd:x.default.func,src:x.default.string.isRequired,style:x.default.shape({})},R.defaultProps={className:void 0,crop:void 0,crossorigin:void 0,disabled:!1,imageAlt:"",maxWidth:100,maxHeight:100,minWidth:0,minHeight:0,keepSelection:!1,onComplete:function(){},onImageError:function(){},onImageLoaded:function(){},onDragStart:function(){},onDragEnd:function(){},children:void 0,style:void 0,imageStyle:void 0},t.default=R,t.Component=R,t.getPixelCrop=l,t.makeAspectCrop=p,t.containCrop=g},function(t,r){t.exports=e},function(e,r){e.exports=t}])}); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["react","prop-types"],t):"object"==typeof exports?exports.ReactCrop=t(require("react"),require("prop-types")):e.ReactCrop=t(e.React,e.PropTypes)}("undefined"!=typeof self?self:this,function(e,t){return function(e){function t(o){if(r[o])return r[o].exports;var a=r[o]={i:o,l:!1,exports:{}};return e[o].call(a.exports,a,a.exports,t),a.l=!0,a.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,o){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,r){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function a(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t100&&(r.height=100-e.y,r.width=r.height*e.aspect/t),e.x+(r.width||e.width)>100&&(r.width=100-e.x,r.height=r.width/e.aspect*t),r}function f(e,t){return e&&e.aspect&&(!e.width&&e.height||e.width&&!e.height)?p(e,t.naturalWidth/t.naturalHeight):e}function l(e,t){if(!e||!t)return null;var r=Math.round(e.naturalWidth*(t.x/100)),o=Math.round(e.naturalHeight*(t.y/100)),a=Math.round(e.naturalWidth*(t.width/100)),n=Math.round(e.naturalHeight*(t.height/100));return{x:r,y:o,width:h(a,0,e.naturalWidth-r),height:h(n,0,e.naturalHeight-o)}}function g(e,t,r){var o=m({},t),a=!1;o.x+o.width>100?(o.width=t.width+(100-(t.x+t.width)),o.x=t.x+(100-(t.x+o.width)),a=!0):o.x<0&&(o.width=t.x+t.width,o.x=0,a=!0),a&&t.aspect&&(o.height=o.width/t.aspect*r,e.y>o.y&&(o.y=t.y+(t.height-o.height)));var n=!1;return o.y+o.height>100?(o.height=t.height+(100-(t.y+t.height)),o.y=t.y+(100-(t.y+o.height)),n=!0):o.y<0&&(o.height=t.y+t.height,o.y=0,n=!0),n&&t.aspect&&(o.width=o.height*t.aspect/r,o.x-1?(e.x=p.x,e.y=p.y,e.width=p.width,e.height=p.height):t.xOrds.indexOf(s)>-1?(e.x=p.x,e.width=p.width):t.yOrds.indexOf(s)>-1&&(e.y=p.y,e.height=p.height),n&&e.width=0||e.xCrossOver&&-Math.abs(e.cropStartWidth)-e.xDiffPc<=0)&&(e.xCrossOver=!e.xCrossOver),(!e.yCrossOver&&-Math.abs(e.cropStartHeight)-e.yDiffPc>=0||e.yCrossOver&&-Math.abs(e.cropStartHeight)-e.yDiffPc<=0)&&(e.yCrossOver=!e.yCrossOver);var t=e.xCrossOver!==e.startXCrossOver,r=e.yCrossOver!==e.startYCrossOver;e.inversedXOrd=!!t&&u(e.ord),e.inversedYOrd=!!r&&u(e.ord)}},{key:"render",value:function(){var e=this,t=this.props,r=t.children,o=t.className,n=t.crossorigin,i=t.crop,s=t.disabled,c=t.imageAlt,h=t.onImageError,u=t.src,p=t.style,f=t.imageStyle,l=this.state.cropIsActive,g=void 0;d(i)&&(g=this.createCropSelection());var v=["ReactCrop"];return l&&v.push("ReactCrop--active"),i&&(i.aspect&&v.push("ReactCrop--fixed-aspect"),!l||i.width&&i.height||v.push("ReactCrop--crop-invisible")),s&&v.push("ReactCrop--disabled"),o&&v.push.apply(v,a(o.split(" "))),w.default.createElement("div",{ref:function(t){e.componentRef=t},className:v.join(" "),style:p,onTouchStart:this.onComponentMouseTouchDown,onMouseDown:this.onComponentMouseTouchDown,role:"presentation",tabIndex:"1",onKeyDown:this.onComponentKeyDown},w.default.createElement("img",{ref:function(t){e.imageRef=t},crossOrigin:n,className:"ReactCrop__image",style:f,src:u,onLoad:function(t){return e.onImageLoad(t.target)},onError:h,alt:c}),g,r)}}]),t}(y.PureComponent);R.xOrds=["e","w"],R.yOrds=["n","s"],R.xyOrds=["nw","ne","se","sw"],R.arrowKey={left:37,up:38,right:39,down:40},R.nudgeStep=.2,R.defaultCrop={x:0,y:0,width:0,height:0},R.propTypes={className:x.default.string,crossorigin:x.default.string,children:x.default.oneOfType([x.default.arrayOf(x.default.node),x.default.node]),crop:x.default.shape({aspect:x.default.number,x:x.default.number,y:x.default.number,width:x.default.number,height:x.default.number}),disabled:x.default.bool,imageAlt:x.default.string,imageStyle:x.default.shape({}),keepSelection:x.default.bool,minWidth:x.default.number,minHeight:x.default.number,maxWidth:x.default.number,maxHeight:x.default.number,onChange:x.default.func.isRequired,onImageError:x.default.func,onComplete:x.default.func,onImageLoaded:x.default.func,onDragStart:x.default.func,onDragEnd:x.default.func,src:x.default.string.isRequired,style:x.default.shape({})},R.defaultProps={className:void 0,crop:void 0,crossorigin:void 0,disabled:!1,imageAlt:"",maxWidth:100,maxHeight:100,minWidth:0,minHeight:0,keepSelection:!1,onComplete:function(){},onImageError:function(){},onImageLoaded:function(){},onDragStart:function(){},onDragEnd:function(){},children:void 0,style:void 0,imageStyle:void 0},t.default=R,t.Component=R,t.getPixelCrop=l,t.makeAspectCrop=p,t.containCrop=g},function(t,r){t.exports=e},function(e,r){e.exports=t}])}); \ No newline at end of file