ngx-image-cropper
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/platform-browser"),require("@angular/common")):"function"==typeof define&&define.amd?define("ngx-image-cropper",["exports","@angular/core","@angular/platform-browser","@angular/common"],e):e(t["ngx-image-cropper"]={},t.ng.core,t.ng.platformBrowser,t.ng.common)}(this,function(t,r,e,i){"use strict";var o=function(){function n(){}return n.getOrientation=function(t){var e=new DataView(this.base64ToArrayBuffer(t));if(65496!=e.getUint16(0,!1))return-2;for(var i=e.byteLength,r=2;r<i;){if(e.getUint16(r+2,!1)<=8)return-1;var o=e.getUint16(r,!1);if(r+=2,65505==o){if(1165519206!=e.getUint32(r+=2,!1))return-1;var s=18761==e.getUint16(r+=6,!1);r+=e.getUint32(r+4,s);var a=e.getUint16(r,s);r+=2;for(var p=0;p<a;p++)if(274==e.getUint16(r+12*p,s))return e.getUint16(r+12*p+8,s)}else{if(65280!=(65280&o))break;r+=e.getUint16(r,!1)}}return-1},n.base64ToArrayBuffer=function(t){t=t.replace(/^data\:([^\;]+)\;base64,/gim,"");for(var e=atob(t),i=e.length,r=new Uint8Array(i),o=0;o<i;o++)r[o]=e.charCodeAt(o);return r.buffer},n.resetOrientation=function(o,s,a){var p=new Image;p.onload=function(){var t=p.width,e=p.height,i=document.createElement("canvas"),r=i.getContext("2d");r?(4<s&&s<9?(i.width=e,i.height=t):(i.width=t,i.height=e),n.transformCanvas(r,s,t,e),r.drawImage(p,0,0),a(i.toDataURL())):a(o)},p.src=o},n.transformCanvas=function(t,e,i,r){switch(e){case 2:t.transform(-1,0,0,1,i,0);break;case 3:t.transform(-1,0,0,-1,i,r);break;case 4:t.transform(1,0,0,-1,0,r);break;case 5:t.transform(0,1,1,0,0,0);break;case 6:t.transform(0,1,-1,0,r,0);break;case 7:t.transform(0,-1,-1,0,r,i);break;case 8:t.transform(0,-1,1,0,0,i)}},n}(),s=function(){function t(t,e,i){this.elementRef=t,this.sanitizer=e,this.cd=i,this.marginLeft="0px",this.imageVisible=!1,this.format="png",this.maintainAspectRatio=!0,this.aspectRatio=1,this.resizeToWidth=0,this.roundCropper=!1,this.onlyScaleDown=!1,this.imageQuality=92,this.cropper={x1:-100,y1:-100,x2:1e4,y2:1e4},this.imageCroppedBase64=new r.EventEmitter,this.imageCroppedFile=new r.EventEmitter,this.imageLoaded=new r.EventEmitter,this.loadImageFailed=new r.EventEmitter,this.initCropper()}return Object.defineProperty(t.prototype,"imageFileChanged",{set:function(t){this.initCropper(),t&&this.loadImageFile(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"imageChangedEvent",{set:function(t){this.initCropper(),t&&t.target&&t.target.files&&0<t.target.files.length&&this.loadImageFile(t.target.files[0])},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"imageBase64",{set:function(t){this.initCropper(),this.loadBase64Image(t)},enumerable:!0,configurable:!0}),t.prototype.ngOnChanges=function(t){var e=this;t.cropper&&setTimeout(function(){e.setMaxSize(),e.checkCropperPosition(!1),e.crop(),e.cd.markForCheck()})},t.prototype.initCropper=function(){this.imageVisible=!1,this.originalImage=null,this.safeImgDataUrl="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYV2NgAAIAAAUAAarVyFEAAAAASUVORK5CYII=",this.moveStart={active:!1,type:null,position:null,x1:0,y1:0,x2:0,y2:0,clientX:0,clientY:0},this.maxSize={width:0,height:0},this.originalSize={width:0,height:0},this.cropper.x1=-100,this.cropper.y1=-100,this.cropper.x2=1e4,this.cropper.y2=1e4},t.prototype.loadImageFile=function(i){var r=this,t=new FileReader;t.onload=function(t){var e=i.type;r.isValidImageType(e)?r.checkExifRotationAndLoadImage(t.target.result):r.loadImageFailed.emit()},t.readAsDataURL(i)},t.prototype.isValidImageType=function(t){return"image/jpeg"===t||"image/jpg"===t||"image/png"===t||"image/gif"===t},t.prototype.checkExifRotationAndLoadImage=function(t){var e=this,i=o.getOrientation(t);1<i?o.resetOrientation(t,i,function(t){return e.loadBase64Image(t)}):this.loadBase64Image(t)},t.prototype.loadBase64Image=function(t){var e=this;this.originalImage=new Image,this.originalImage.onload=function(){e.originalSize.width=e.originalImage.width,e.originalSize.height=e.originalImage.height,e.cd.markForCheck()},this.safeImgDataUrl=this.sanitizer.bypassSecurityTrustResourceUrl(t),this.originalImage.src=t},t.prototype.imageLoadedInView=function(){var t=this;null!=this.originalImage&&(this.imageLoaded.emit(),setTimeout(function(){t.setMaxSize(),t.resetCropperPosition(),t.cd.markForCheck()}))},t.prototype.onResize=function(t){this.resizeCropperPosition(),this.setMaxSize()},t.prototype.resizeCropperPosition=function(){var t=this.elementRef.nativeElement.querySelector(".source-image");this.maxSize.width===t.offsetWidth&&this.maxSize.height===t.offsetHeight||(this.cropper.x1=this.cropper.x1*t.offsetWidth/this.maxSize.width,this.cropper.x2=this.cropper.x2*t.offsetWidth/this.maxSize.width,this.cropper.y1=this.cropper.y1*t.offsetHeight/this.maxSize.height,this.cropper.y2=this.cropper.y2*t.offsetHeight/this.maxSize.height)},t.prototype.resetCropperPosition=function(){var t=this.elementRef.nativeElement.querySelector(".source-image");if(t.offsetWidth/this.aspectRatio<t.offsetHeight){this.cropper.x1=0,this.cropper.x2=t.offsetWidth;var e=t.offsetWidth/this.aspectRatio;this.cropper.y1=(t.offsetHeight-e)/2,this.cropper.y2=this.cropper.y1+e}else{this.cropper.y1=0,this.cropper.y2=t.offsetHeight;var i=t.offsetHeight*this.aspectRatio;this.cropper.x1=(t.offsetWidth-i)/2,this.cropper.x2=this.cropper.x1+i}this.crop(),this.imageVisible=!0},t.prototype.startMove=function(t,e,i){void 0===i&&(i=null),this.moveStart.active=!0,this.moveStart.type=e,this.moveStart.position=i,this.moveStart.clientX=this.getClientX(t),this.moveStart.clientY=this.getClientY(t),Object.assign(this.moveStart,this.cropper),this.cd.markForCheck()},t.prototype.moveImg=function(t){this.moveStart.active&&(t.stopPropagation(),t.preventDefault(),this.setMaxSize(),"move"===this.moveStart.type?(this.move(t),this.checkCropperPosition(!0)):"resize"===this.moveStart.type&&(this.resize(t),this.checkCropperPosition(!1)),this.cd.markForCheck())},t.prototype.setMaxSize=function(){var t=this.elementRef.nativeElement.querySelector(".source-image");this.maxSize.width=t.offsetWidth,this.maxSize.height=t.offsetHeight,this.marginLeft=this.sanitizer.bypassSecurityTrustStyle("calc(50% - "+this.maxSize.width/2+"px)")},t.prototype.checkCropperPosition=function(t){void 0===t&&(t=!1),this.cropper.x1<0&&(this.cropper.x2-=t?this.cropper.x1:0,this.cropper.x1=0),this.cropper.y1<0&&(this.cropper.y2-=t?this.cropper.y1:0,this.cropper.y1=0),this.cropper.x2>this.maxSize.width&&(this.cropper.x1-=t?this.cropper.x2-this.maxSize.width:0,this.cropper.x2=this.maxSize.width),this.cropper.y2>this.maxSize.height&&(this.cropper.y1-=t?this.cropper.y2-this.maxSize.height:0,this.cropper.y2=this.maxSize.height)},t.prototype.moveStop=function(t){this.moveStart.active&&(this.moveStart.active=!1,this.crop(),this.cd.markForCheck())},t.prototype.move=function(t){var e=this.getClientX(t)-this.moveStart.clientX,i=this.getClientY(t)-this.moveStart.clientY;this.cropper.x1=this.moveStart.x1+e,this.cropper.y1=this.moveStart.y1+i,this.cropper.x2=this.moveStart.x2+e,this.cropper.y2=this.moveStart.y2+i},t.prototype.resize=function(t){var e=this.getClientX(t)-this.moveStart.clientX,i=this.getClientY(t)-this.moveStart.clientY;switch(this.moveStart.position){case"left":this.cropper.x1=Math.min(this.moveStart.x1+e,this.cropper.x2-20);break;case"topleft":this.cropper.x1=Math.min(this.moveStart.x1+e,this.cropper.x2-20),this.cropper.y1=Math.min(this.moveStart.y1+i,this.cropper.y2-20);break;case"top":this.cropper.y1=Math.min(this.moveStart.y1+i,this.cropper.y2-20);break;case"topright":this.cropper.x2=Math.max(this.moveStart.x2+e,this.cropper.x1+20),this.cropper.y1=Math.min(this.moveStart.y1+i,this.cropper.y2-20);break;case"right":this.cropper.x2=Math.max(this.moveStart.x2+e,this.cropper.x1+20);break;case"bottomright":this.cropper.x2=Math.max(this.moveStart.x2+e,this.cropper.x1+20),this.cropper.y2=Math.max(this.moveStart.y2+i,this.cropper.y1+20);break;case"bottom":this.cropper.y2=Math.max(this.moveStart.y2+i,this.cropper.y1+20);break;case"bottomleft":this.cropper.x1=Math.min(this.moveStart.x1+e,this.cropper.x2-20),this.cropper.y2=Math.max(this.moveStart.y2+i,this.cropper.y1+20)}this.maintainAspectRatio&&this.checkAspectRatio()},t.prototype.checkAspectRatio=function(){var t=0,e=0;switch(this.moveStart.position){case"top":this.cropper.x2=this.cropper.x1+(this.cropper.y2-this.cropper.y1)*this.aspectRatio,t=Math.max(this.cropper.x2-this.maxSize.width,0),e=Math.max(0-this.cropper.y1,0),(0<t||0<e)&&(this.cropper.x2-=e*this.aspectRatio>t?e*this.aspectRatio:t,this.cropper.y1+=e*this.aspectRatio>t?e:t/this.aspectRatio);break;case"bottom":this.cropper.x2=this.cropper.x1+(this.cropper.y2-this.cropper.y1)*this.aspectRatio,t=Math.max(this.cropper.x2-this.maxSize.width,0),e=Math.max(this.cropper.y2-this.maxSize.height,0),(0<t||0<e)&&(this.cropper.x2-=e*this.aspectRatio>t?e*this.aspectRatio:t,this.cropper.y2-=e*this.aspectRatio>t?e:t/this.aspectRatio);break;case"topleft":this.cropper.y1=this.cropper.y2-(this.cropper.x2-this.cropper.x1)/this.aspectRatio,t=Math.max(0-this.cropper.x1,0),e=Math.max(0-this.cropper.y1,0),(0<t||0<e)&&(this.cropper.x1+=e*this.aspectRatio>t?e*this.aspectRatio:t,this.cropper.y1+=e*this.aspectRatio>t?e:t/this.aspectRatio);break;case"topright":this.cropper.y1=this.cropper.y2-(this.cropper.x2-this.cropper.x1)/this.aspectRatio,t=Math.max(this.cropper.x2-this.maxSize.width,0),e=Math.max(0-this.cropper.y1,0),(0<t||0<e)&&(this.cropper.x2-=e*this.aspectRatio>t?e*this.aspectRatio:t,this.cropper.y1+=e*this.aspectRatio>t?e:t/this.aspectRatio);break;case"right":case"bottomright":this.cropper.y2=this.cropper.y1+(this.cropper.x2-this.cropper.x1)/this.aspectRatio,t=Math.max(this.cropper.x2-this.maxSize.width,0),e=Math.max(this.cropper.y2-this.maxSize.height,0),(0<t||0<e)&&(this.cropper.x2-=e*this.aspectRatio>t?e*this.aspectRatio:t,this.cropper.y2-=e*this.aspectRatio>t?e:t/this.aspectRatio);break;case"left":case"bottomleft":this.cropper.y2=this.cropper.y1+(this.cropper.x2-this.cropper.x1)/this.aspectRatio,t=Math.max(0-this.cropper.x1,0),e=Math.max(this.cropper.y2-this.maxSize.height,0),(0<t||0<e)&&(this.cropper.x1+=e*this.aspectRatio>t?e*this.aspectRatio:t,this.cropper.y2-=e*this.aspectRatio>t?e:t/this.aspectRatio)}},t.prototype.crop=function(){var e=this,t=this.elementRef.nativeElement.querySelector(".source-image");if(t&&null!=this.originalImage){var i=this.originalSize.width/t.offsetWidth,r=Math.round(this.cropper.x1*i),o=Math.round(this.cropper.y1*i),s=Math.round((this.cropper.x2-this.cropper.x1)*i),a=Math.round((this.cropper.y2-this.cropper.y1)*i),p=this.getResizeRatio(s),n=document.createElement("canvas");n.width=s*p,n.height=a*p;var h=n.getContext("2d");if(h){h.drawImage(this.originalImage,r,o,s,a,0,0,s*p,a*p);var c=Math.min(1,Math.max(0,this.imageQuality/100)),m=n.toDataURL("image/"+this.format,c);10<m.length&&this.imageCroppedBase64.emit(m),n.toBlob(function(t){return e.imageCroppedFile.emit(t)},"image/"+this.format,c)}}},t.prototype.getResizeRatio=function(t){return 0<this.resizeToWidth&&(!this.onlyScaleDown||t>this.resizeToWidth)?this.resizeToWidth/t:1},t.prototype.getClientX=function(t){return null!=t.clientX?t.clientX:t.touches[0].clientX},t.prototype.getClientY=function(t){return null!=t.clientY?t.clientY:t.touches[0].clientY},t.decorators=[{type:r.Component,args:[{selector:"image-cropper",template:'<div>\n <img\n [src]="safeImgDataUrl"\n [style.visibility]="imageVisible ? \'visible\' : \'hidden\'"\n (load)="imageLoadedInView()"\n class="source-image"\n />\n <div class="cropper"\n [class.rounded]="roundCropper"\n [style.top.px]="cropper.y1"\n [style.left.px]="cropper.x1"\n [style.width.px]="cropper.x2 - cropper.x1"\n [style.height.px]="cropper.y2 - cropper.y1"\n [style.margin-left]="marginLeft"\n [style.visibility]="imageVisible ? \'visible\' : \'hidden\'"\n >\n <div\n (mousedown)="startMove($event, \'move\')"\n (touchstart)="startMove($event, \'move\')"\n class="move"\n > </div>\n <span\n class="resize topleft"\n (mousedown)="startMove($event, \'resize\', \'topleft\')"\n (touchstart)="startMove($event, \'resize\', \'topleft\')"\n ><span class="square"></span></span>\n <span\n class="resize top"\n ><span class="square"></span></span>\n <span\n class="resize topright"\n (mousedown)="startMove($event, \'resize\', \'topright\')"\n (touchstart)="startMove($event, \'resize\', \'topright\')"\n ><span class="square"></span></span>\n <span\n class="resize right"\n ><span class="square"></span></span>\n <span\n class="resize bottomright"\n (mousedown)="startMove($event, \'resize\', \'bottomright\')"\n (touchstart)="startMove($event, \'resize\', \'bottomright\')"\n ><span class="square"></span></span>\n <span\n class="resize bottom"\n ><span class="square"></span></span>\n <span\n class="resize bottomleft"\n (mousedown)="startMove($event, \'resize\', \'bottomleft\')"\n (touchstart)="startMove($event, \'resize\', \'bottomleft\')"\n ><span class="square"></span></span>\n <span\n class="resize left"\n ><span class="square"></span></span>\n <span\n class="resize-bar top"\n (mousedown)="startMove($event, \'resize\', \'top\')"\n (touchstart)="startMove($event, \'resize\', \'top\')"\n ></span>\n <span\n class="resize-bar right"\n (mousedown)="startMove($event, \'resize\', \'right\')"\n (touchstart)="startMove($event, \'resize\', \'right\')"\n ></span>\n <span\n class="resize-bar bottom"\n (mousedown)="startMove($event, \'resize\', \'bottom\')"\n (touchstart)="startMove($event, \'resize\', \'bottom\')"\n ></span>\n <span\n class="resize-bar left"\n (mousedown)="startMove($event, \'resize\', \'left\')"\n (touchstart)="startMove($event, \'resize\', \'left\')"\n ></span>\n </div>\n</div>\n',changeDetection:r.ChangeDetectionStrategy.OnPush,styles:[":host{display:flex;position:relative;width:100%;max-width:100%;max-height:100%;overflow:hidden;padding:5px;text-align:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}:host>div{position:relative;width:100%}:host>div .source-image{max-width:100%;max-height:100%}:host .cropper{position:absolute;display:flex;color:#53535c!important;background:0 0!important;touch-action:none;outline:rgba(255,255,255,.3) solid 1000px}:host .cropper:after{position:absolute;content:'';top:0;bottom:0;left:0;right:0;pointer-events:none;border:1px dashed;opacity:.75;color:inherit;z-index:1}:host .cropper .move{width:100%;cursor:move;border:1px solid rgba(255,255,255,.5)}:host .cropper .resize{position:absolute;display:inline-block;line-height:6px;padding:8px;opacity:.85;z-index:1}:host .cropper .resize .square{display:inline-block;background:#53535c!important;width:6px;height:6px;border:1px solid rgba(255,255,255,.5)}:host .cropper .resize.topleft{top:-12px;left:-12px;cursor:nw-resize}:host .cropper .resize.top{top:-12px;left:calc(50% - 12px);cursor:n-resize}:host .cropper .resize.topright{top:-12px;right:-12px;cursor:ne-resize}:host .cropper .resize.right{top:calc(50% - 12px);right:-12px;cursor:e-resize}:host .cropper .resize.bottomright{bottom:-12px;right:-12px;cursor:se-resize}:host .cropper .resize.bottom{bottom:-12px;left:calc(50% - 12px);cursor:s-resize}:host .cropper .resize.bottomleft{bottom:-12px;left:-12px;cursor:sw-resize}:host .cropper .resize.left{top:calc(50% - 12px);left:-12px;cursor:w-resize}:host .cropper .resize-bar{position:absolute;z-index:1}:host .cropper .resize-bar.top{top:-11px;left:11px;width:calc(100% - 22px);height:22px;cursor:n-resize}:host .cropper .resize-bar.right{top:11px;right:-11px;height:calc(100% - 22px);width:22px;cursor:e-resize}:host .cropper .resize-bar.bottom{bottom:-11px;left:11px;width:calc(100% - 22px);height:22px;cursor:s-resize}:host .cropper .resize-bar.left{top:11px;left:-11px;height:calc(100% - 22px);width:22px;cursor:w-resize}:host .cropper.rounded{outline-color:transparent}:host .cropper.rounded:after{box-shadow:0 0 0 100vw rgba(255,255,255,.3);border-radius:100%}:host .cropper.rounded .move{border-radius:100%}"]}]}],t.ctorParameters=function(){return[{type:r.ElementRef},{type:e.DomSanitizer},{type:r.ChangeDetectorRef}]},t.propDecorators={imageFileChanged:[{type:r.Input}],imageChangedEvent:[{type:r.Input}],imageBase64:[{type:r.Input}],format:[{type:r.Input}],maintainAspectRatio:[{type:r.Input}],aspectRatio:[{type:r.Input}],resizeToWidth:[{type:r.Input}],roundCropper:[{type:r.Input}],onlyScaleDown:[{type:r.Input}],imageQuality:[{type:r.Input}],cropper:[{type:r.Input}],imageCroppedBase64:[{type:r.Output}],imageCroppedFile:[{type:r.Output}],imageLoaded:[{type:r.Output}],loadImageFailed:[{type:r.Output}],onResize:[{type:r.HostListener,args:["window:resize",["$event"]]}],moveImg:[{type:r.HostListener,args:["document:mousemove",["$event"]]},{type:r.HostListener,args:["document:touchmove",["$event"]]}],moveStop:[{type:r.HostListener,args:["document:mouseup",["$event"]]},{type:r.HostListener,args:["document:touchend",["$event"]]}]},t}(),a=function(){function t(){}return t.decorators=[{type:r.NgModule,args:[{imports:[i.CommonModule],declarations:[s],exports:[s]}]}],t}();t.ImageCropperModule=a,t.ImageCropperComponent=s,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/platform-browser"),require("@angular/common")):"function"==typeof define&&define.amd?define("ngx-image-cropper",["exports","@angular/core","@angular/platform-browser","@angular/common"],e):e(t["ngx-image-cropper"]={},t.ng.core,t.ng.platformBrowser,t.ng.common)}(this,function(t,r,e,i){"use strict";var o=function(){function n(){}return n.getOrientation=function(t){var e=new DataView(this.base64ToArrayBuffer(t));if(65496!=e.getUint16(0,!1))return-2;for(var i=e.byteLength,r=2;r<i;){if(e.getUint16(r+2,!1)<=8)return-1;var o=e.getUint16(r,!1);if(r+=2,65505==o){if(1165519206!=e.getUint32(r+=2,!1))return-1;var s=18761==e.getUint16(r+=6,!1);r+=e.getUint32(r+4,s);var a=e.getUint16(r,s);r+=2;for(var p=0;p<a;p++)if(274==e.getUint16(r+12*p,s))return e.getUint16(r+12*p+8,s)}else{if(65280!=(65280&o))break;r+=e.getUint16(r,!1)}}return-1},n.base64ToArrayBuffer=function(t){t=t.replace(/^data\:([^\;]+)\;base64,/gim,"");for(var e=atob(t),i=e.length,r=new Uint8Array(i),o=0;o<i;o++)r[o]=e.charCodeAt(o);return r.buffer},n.resetOrientation=function(o,s,a){var p=new Image;p.onload=function(){var t=p.width,e=p.height,i=document.createElement("canvas"),r=i.getContext("2d");r?(4<s&&s<9?(i.width=e,i.height=t):(i.width=t,i.height=e),n.transformCanvas(r,s,t,e),r.drawImage(p,0,0),a(i.toDataURL())):a(o)},p.src=o},n.transformCanvas=function(t,e,i,r){switch(e){case 2:t.transform(-1,0,0,1,i,0);break;case 3:t.transform(-1,0,0,-1,i,r);break;case 4:t.transform(1,0,0,-1,0,r);break;case 5:t.transform(0,1,1,0,0,0);break;case 6:t.transform(0,1,-1,0,r,0);break;case 7:t.transform(0,-1,-1,0,r,i);break;case 8:t.transform(0,-1,1,0,0,i)}},n}(),s=function(){function t(t,e,i){this.elementRef=t,this.sanitizer=e,this.cd=i,this.marginLeft="0px",this.imageVisible=!1,this.format="png",this.maintainAspectRatio=!0,this.aspectRatio=1,this.resizeToWidth=0,this.roundCropper=!1,this.onlyScaleDown=!1,this.imageQuality=92,this.cropper={x1:-100,y1:-100,x2:1e4,y2:1e4},this.imageCropped=new r.EventEmitter,this.imageCroppedBase64=new r.EventEmitter,this.imageCroppedFile=new r.EventEmitter,this.imageLoaded=new r.EventEmitter,this.loadImageFailed=new r.EventEmitter,this.initCropper()}return Object.defineProperty(t.prototype,"imageFileChanged",{set:function(t){this.initCropper(),t&&this.loadImageFile(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"imageChangedEvent",{set:function(t){this.initCropper(),t&&t.target&&t.target.files&&0<t.target.files.length&&this.loadImageFile(t.target.files[0])},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"imageBase64",{set:function(t){this.initCropper(),this.loadBase64Image(t)},enumerable:!0,configurable:!0}),t.prototype.ngOnChanges=function(t){var e=this;t.cropper&&setTimeout(function(){e.setMaxSize(),e.checkCropperPosition(!1),e.crop(),e.cd.markForCheck()}),t.aspectRatio&&this.resetCropperPosition()},t.prototype.initCropper=function(){this.imageVisible=!1,this.originalImage=null,this.safeImgDataUrl="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYV2NgAAIAAAUAAarVyFEAAAAASUVORK5CYII=",this.moveStart={active:!1,type:null,position:null,x1:0,y1:0,x2:0,y2:0,clientX:0,clientY:0},this.maxSize={width:0,height:0},this.originalSize={width:0,height:0},this.cropper.x1=-100,this.cropper.y1=-100,this.cropper.x2=1e4,this.cropper.y2=1e4},t.prototype.loadImageFile=function(i){var r=this,t=new FileReader;t.onload=function(t){var e=i.type;r.isValidImageType(e)?r.checkExifRotationAndLoadImage(t.target.result):r.loadImageFailed.emit()},t.readAsDataURL(i)},t.prototype.isValidImageType=function(t){return"image/jpeg"===t||"image/jpg"===t||"image/png"===t||"image/gif"===t},t.prototype.checkExifRotationAndLoadImage=function(t){var e=this,i=o.getOrientation(t);1<i?o.resetOrientation(t,i,function(t){return e.loadBase64Image(t)}):this.loadBase64Image(t)},t.prototype.loadBase64Image=function(t){var e=this;this.originalImage=new Image,this.originalImage.onload=function(){e.originalSize.width=e.originalImage.width,e.originalSize.height=e.originalImage.height,e.cd.markForCheck()},this.safeImgDataUrl=this.sanitizer.bypassSecurityTrustResourceUrl(t),this.originalImage.src=t},t.prototype.imageLoadedInView=function(){var t=this;null!=this.originalImage&&(this.imageLoaded.emit(),setTimeout(function(){t.setMaxSize(),t.resetCropperPosition(),t.cd.markForCheck()}))},t.prototype.onResize=function(t){this.resizeCropperPosition(),this.setMaxSize()},t.prototype.resizeCropperPosition=function(){var t=this.elementRef.nativeElement.querySelector(".source-image");this.maxSize.width===t.offsetWidth&&this.maxSize.height===t.offsetHeight||(this.cropper.x1=this.cropper.x1*t.offsetWidth/this.maxSize.width,this.cropper.x2=this.cropper.x2*t.offsetWidth/this.maxSize.width,this.cropper.y1=this.cropper.y1*t.offsetHeight/this.maxSize.height,this.cropper.y2=this.cropper.y2*t.offsetHeight/this.maxSize.height)},t.prototype.resetCropperPosition=function(){var t=this.elementRef.nativeElement.querySelector(".source-image");if(t.offsetWidth/this.aspectRatio<t.offsetHeight){this.cropper.x1=0,this.cropper.x2=t.offsetWidth;var e=t.offsetWidth/this.aspectRatio;this.cropper.y1=(t.offsetHeight-e)/2,this.cropper.y2=this.cropper.y1+e}else{this.cropper.y1=0,this.cropper.y2=t.offsetHeight;var i=t.offsetHeight*this.aspectRatio;this.cropper.x1=(t.offsetWidth-i)/2,this.cropper.x2=this.cropper.x1+i}this.crop(),this.imageVisible=!0},t.prototype.startMove=function(t,e,i){void 0===i&&(i=null),this.moveStart.active=!0,this.moveStart.type=e,this.moveStart.position=i,this.moveStart.clientX=this.getClientX(t),this.moveStart.clientY=this.getClientY(t),Object.assign(this.moveStart,this.cropper),this.cd.markForCheck()},t.prototype.moveImg=function(t){this.moveStart.active&&(t.stopPropagation(),t.preventDefault(),this.setMaxSize(),"move"===this.moveStart.type?(this.move(t),this.checkCropperPosition(!0)):"resize"===this.moveStart.type&&(this.resize(t),this.checkCropperPosition(!1)),this.cd.markForCheck())},t.prototype.setMaxSize=function(){var t=this.elementRef.nativeElement.querySelector(".source-image");this.maxSize.width=t.offsetWidth,this.maxSize.height=t.offsetHeight,this.marginLeft=this.sanitizer.bypassSecurityTrustStyle("calc(50% - "+this.maxSize.width/2+"px)")},t.prototype.checkCropperPosition=function(t){void 0===t&&(t=!1),this.cropper.x1<0&&(this.cropper.x2-=t?this.cropper.x1:0,this.cropper.x1=0),this.cropper.y1<0&&(this.cropper.y2-=t?this.cropper.y1:0,this.cropper.y1=0),this.cropper.x2>this.maxSize.width&&(this.cropper.x1-=t?this.cropper.x2-this.maxSize.width:0,this.cropper.x2=this.maxSize.width),this.cropper.y2>this.maxSize.height&&(this.cropper.y1-=t?this.cropper.y2-this.maxSize.height:0,this.cropper.y2=this.maxSize.height)},t.prototype.moveStop=function(t){this.moveStart.active&&(this.moveStart.active=!1,this.crop(),this.cd.markForCheck())},t.prototype.move=function(t){var e=this.getClientX(t)-this.moveStart.clientX,i=this.getClientY(t)-this.moveStart.clientY;this.cropper.x1=this.moveStart.x1+e,this.cropper.y1=this.moveStart.y1+i,this.cropper.x2=this.moveStart.x2+e,this.cropper.y2=this.moveStart.y2+i},t.prototype.resize=function(t){var e=this.getClientX(t)-this.moveStart.clientX,i=this.getClientY(t)-this.moveStart.clientY;switch(this.moveStart.position){case"left":this.cropper.x1=Math.min(this.moveStart.x1+e,this.cropper.x2-20);break;case"topleft":this.cropper.x1=Math.min(this.moveStart.x1+e,this.cropper.x2-20),this.cropper.y1=Math.min(this.moveStart.y1+i,this.cropper.y2-20);break;case"top":this.cropper.y1=Math.min(this.moveStart.y1+i,this.cropper.y2-20);break;case"topright":this.cropper.x2=Math.max(this.moveStart.x2+e,this.cropper.x1+20),this.cropper.y1=Math.min(this.moveStart.y1+i,this.cropper.y2-20);break;case"right":this.cropper.x2=Math.max(this.moveStart.x2+e,this.cropper.x1+20);break;case"bottomright":this.cropper.x2=Math.max(this.moveStart.x2+e,this.cropper.x1+20),this.cropper.y2=Math.max(this.moveStart.y2+i,this.cropper.y1+20);break;case"bottom":this.cropper.y2=Math.max(this.moveStart.y2+i,this.cropper.y1+20);break;case"bottomleft":this.cropper.x1=Math.min(this.moveStart.x1+e,this.cropper.x2-20),this.cropper.y2=Math.max(this.moveStart.y2+i,this.cropper.y1+20)}this.maintainAspectRatio&&this.checkAspectRatio()},t.prototype.checkAspectRatio=function(){var t=0,e=0;switch(this.moveStart.position){case"top":this.cropper.x2=this.cropper.x1+(this.cropper.y2-this.cropper.y1)*this.aspectRatio,t=Math.max(this.cropper.x2-this.maxSize.width,0),e=Math.max(0-this.cropper.y1,0),(0<t||0<e)&&(this.cropper.x2-=e*this.aspectRatio>t?e*this.aspectRatio:t,this.cropper.y1+=e*this.aspectRatio>t?e:t/this.aspectRatio);break;case"bottom":this.cropper.x2=this.cropper.x1+(this.cropper.y2-this.cropper.y1)*this.aspectRatio,t=Math.max(this.cropper.x2-this.maxSize.width,0),e=Math.max(this.cropper.y2-this.maxSize.height,0),(0<t||0<e)&&(this.cropper.x2-=e*this.aspectRatio>t?e*this.aspectRatio:t,this.cropper.y2-=e*this.aspectRatio>t?e:t/this.aspectRatio);break;case"topleft":this.cropper.y1=this.cropper.y2-(this.cropper.x2-this.cropper.x1)/this.aspectRatio,t=Math.max(0-this.cropper.x1,0),e=Math.max(0-this.cropper.y1,0),(0<t||0<e)&&(this.cropper.x1+=e*this.aspectRatio>t?e*this.aspectRatio:t,this.cropper.y1+=e*this.aspectRatio>t?e:t/this.aspectRatio);break;case"topright":this.cropper.y1=this.cropper.y2-(this.cropper.x2-this.cropper.x1)/this.aspectRatio,t=Math.max(this.cropper.x2-this.maxSize.width,0),e=Math.max(0-this.cropper.y1,0),(0<t||0<e)&&(this.cropper.x2-=e*this.aspectRatio>t?e*this.aspectRatio:t,this.cropper.y1+=e*this.aspectRatio>t?e:t/this.aspectRatio);break;case"right":case"bottomright":this.cropper.y2=this.cropper.y1+(this.cropper.x2-this.cropper.x1)/this.aspectRatio,t=Math.max(this.cropper.x2-this.maxSize.width,0),e=Math.max(this.cropper.y2-this.maxSize.height,0),(0<t||0<e)&&(this.cropper.x2-=e*this.aspectRatio>t?e*this.aspectRatio:t,this.cropper.y2-=e*this.aspectRatio>t?e:t/this.aspectRatio);break;case"left":case"bottomleft":this.cropper.y2=this.cropper.y1+(this.cropper.x2-this.cropper.x1)/this.aspectRatio,t=Math.max(0-this.cropper.x1,0),e=Math.max(this.cropper.y2-this.maxSize.height,0),(0<t||0<e)&&(this.cropper.x1+=e*this.aspectRatio>t?e*this.aspectRatio:t,this.cropper.y2-=e*this.aspectRatio>t?e:t/this.aspectRatio)}},t.prototype.crop=function(){var e=this,t=this.elementRef.nativeElement.querySelector(".source-image");if(t&&null!=this.originalImage){var i=this.originalSize.width/t.offsetWidth,r=Math.round(this.cropper.x1*i),o=Math.round(this.cropper.y1*i),s=Math.round((this.cropper.x2-this.cropper.x1)*i),a=Math.round((this.cropper.y2-this.cropper.y1)*i),p=this.getResizeRatio(s),n=Math.floor(s*p),h=Math.floor(a*p),c=document.createElement("canvas");c.width=n,c.height=h;var m=c.getContext("2d");if(m){m.drawImage(this.originalImage,r,o,s,a,0,0,s*p,a*p);var l=Math.min(1,Math.max(0,this.imageQuality/100)),g=c.toDataURL("image/"+this.format,l);10<g.length&&this.imageCroppedBase64.emit(g);c.toBlob(function(t){null!=t&&(e.imageCroppedFile.emit(t),e.imageCropped.emit({base64:g,file:t,width:n,height:h,cropperPosition:Object.assign({},e.cropper)}))},"image/"+this.format,l)}}},t.prototype.getResizeRatio=function(t){return 0<this.resizeToWidth&&(!this.onlyScaleDown||t>this.resizeToWidth)?this.resizeToWidth/t:1},t.prototype.getClientX=function(t){return null!=t.clientX?t.clientX:t.touches[0].clientX},t.prototype.getClientY=function(t){return null!=t.clientY?t.clientY:t.touches[0].clientY},t.decorators=[{type:r.Component,args:[{selector:"image-cropper",template:'<div>\n <img\n [src]="safeImgDataUrl"\n [style.visibility]="imageVisible ? \'visible\' : \'hidden\'"\n (load)="imageLoadedInView()"\n class="source-image"\n />\n <div class="cropper"\n [class.rounded]="roundCropper"\n [style.top.px]="cropper.y1"\n [style.left.px]="cropper.x1"\n [style.width.px]="cropper.x2 - cropper.x1"\n [style.height.px]="cropper.y2 - cropper.y1"\n [style.margin-left]="marginLeft"\n [style.visibility]="imageVisible ? \'visible\' : \'hidden\'"\n >\n <div\n (mousedown)="startMove($event, \'move\')"\n (touchstart)="startMove($event, \'move\')"\n class="move"\n > </div>\n <span\n class="resize topleft"\n (mousedown)="startMove($event, \'resize\', \'topleft\')"\n (touchstart)="startMove($event, \'resize\', \'topleft\')"\n ><span class="square"></span></span>\n <span\n class="resize top"\n ><span class="square"></span></span>\n <span\n class="resize topright"\n (mousedown)="startMove($event, \'resize\', \'topright\')"\n (touchstart)="startMove($event, \'resize\', \'topright\')"\n ><span class="square"></span></span>\n <span\n class="resize right"\n ><span class="square"></span></span>\n <span\n class="resize bottomright"\n (mousedown)="startMove($event, \'resize\', \'bottomright\')"\n (touchstart)="startMove($event, \'resize\', \'bottomright\')"\n ><span class="square"></span></span>\n <span\n class="resize bottom"\n ><span class="square"></span></span>\n <span\n class="resize bottomleft"\n (mousedown)="startMove($event, \'resize\', \'bottomleft\')"\n (touchstart)="startMove($event, \'resize\', \'bottomleft\')"\n ><span class="square"></span></span>\n <span\n class="resize left"\n ><span class="square"></span></span>\n <span\n class="resize-bar top"\n (mousedown)="startMove($event, \'resize\', \'top\')"\n (touchstart)="startMove($event, \'resize\', \'top\')"\n ></span>\n <span\n class="resize-bar right"\n (mousedown)="startMove($event, \'resize\', \'right\')"\n (touchstart)="startMove($event, \'resize\', \'right\')"\n ></span>\n <span\n class="resize-bar bottom"\n (mousedown)="startMove($event, \'resize\', \'bottom\')"\n (touchstart)="startMove($event, \'resize\', \'bottom\')"\n ></span>\n <span\n class="resize-bar left"\n (mousedown)="startMove($event, \'resize\', \'left\')"\n (touchstart)="startMove($event, \'resize\', \'left\')"\n ></span>\n </div>\n</div>\n',changeDetection:r.ChangeDetectionStrategy.OnPush,styles:[":host{display:flex;position:relative;width:100%;max-width:100%;max-height:100%;overflow:hidden;padding:5px;text-align:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}:host>div{position:relative;width:100%}:host>div .source-image{max-width:100%;max-height:100%}:host .cropper{position:absolute;display:flex;color:#53535c!important;background:0 0!important;touch-action:none;outline:rgba(255,255,255,.3) solid 1000px}:host .cropper:after{position:absolute;content:'';top:0;bottom:0;left:0;right:0;pointer-events:none;border:1px dashed;opacity:.75;color:inherit;z-index:1}:host .cropper .move{width:100%;cursor:move;border:1px solid rgba(255,255,255,.5)}:host .cropper .resize{position:absolute;display:inline-block;line-height:6px;padding:8px;opacity:.85;z-index:1}:host .cropper .resize .square{display:inline-block;background:#53535c!important;width:6px;height:6px;border:1px solid rgba(255,255,255,.5)}:host .cropper .resize.topleft{top:-12px;left:-12px;cursor:nw-resize}:host .cropper .resize.top{top:-12px;left:calc(50% - 12px);cursor:n-resize}:host .cropper .resize.topright{top:-12px;right:-12px;cursor:ne-resize}:host .cropper .resize.right{top:calc(50% - 12px);right:-12px;cursor:e-resize}:host .cropper .resize.bottomright{bottom:-12px;right:-12px;cursor:se-resize}:host .cropper .resize.bottom{bottom:-12px;left:calc(50% - 12px);cursor:s-resize}:host .cropper .resize.bottomleft{bottom:-12px;left:-12px;cursor:sw-resize}:host .cropper .resize.left{top:calc(50% - 12px);left:-12px;cursor:w-resize}:host .cropper .resize-bar{position:absolute;z-index:1}:host .cropper .resize-bar.top{top:-11px;left:11px;width:calc(100% - 22px);height:22px;cursor:n-resize}:host .cropper .resize-bar.right{top:11px;right:-11px;height:calc(100% - 22px);width:22px;cursor:e-resize}:host .cropper .resize-bar.bottom{bottom:-11px;left:11px;width:calc(100% - 22px);height:22px;cursor:s-resize}:host .cropper .resize-bar.left{top:11px;left:-11px;height:calc(100% - 22px);width:22px;cursor:w-resize}:host .cropper.rounded{outline-color:transparent}:host .cropper.rounded:after{box-shadow:0 0 0 100vw rgba(255,255,255,.3);border-radius:100%}:host .cropper.rounded .move{border-radius:100%}"]}]}],t.ctorParameters=function(){return[{type:r.ElementRef},{type:e.DomSanitizer},{type:r.ChangeDetectorRef}]},t.propDecorators={imageFileChanged:[{type:r.Input}],imageChangedEvent:[{type:r.Input}],imageBase64:[{type:r.Input}],format:[{type:r.Input}],maintainAspectRatio:[{type:r.Input}],aspectRatio:[{type:r.Input}],resizeToWidth:[{type:r.Input}],roundCropper:[{type:r.Input}],onlyScaleDown:[{type:r.Input}],imageQuality:[{type:r.Input}],cropper:[{type:r.Input}],imageCropped:[{type:r.Output}],imageCroppedBase64:[{type:r.Output}],imageCroppedFile:[{type:r.Output}],imageLoaded:[{type:r.Output}],loadImageFailed:[{type:r.Output}],onResize:[{type:r.HostListener,args:["window:resize",["$event"]]}],moveImg:[{type:r.HostListener,args:["document:mousemove",["$event"]]},{type:r.HostListener,args:["document:touchmove",["$event"]]}],moveStop:[{type:r.HostListener,args:["document:mouseup",["$event"]]},{type:r.HostListener,args:["document:touchend",["$event"]]}]},t}(),a=function(){function t(){}return t.decorators=[{type:r.NgModule,args:[{imports:[i.CommonModule],declarations:[s],exports:[s]}]}],t}();t.ImageCropperModule=a,t.ImageCropperComponent=s,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=ngx-image-cropper.umd.min.js.map |
@@ -1,1 +0,1 @@ | ||
{"__symbolic":"module","version":4,"metadata":{"ImageCropperModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":4,"character":1},"arguments":[{"imports":[{"__symbolic":"reference","module":"@angular/common","name":"CommonModule","line":6,"character":8}],"declarations":[{"__symbolic":"reference","name":"ImageCropperComponent"}],"exports":[{"__symbolic":"reference","name":"ImageCropperComponent"}]}]}],"members":{}},"ImageCropperComponent":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component","line":39,"character":1},"arguments":[{"selector":"image-cropper","changeDetection":{"__symbolic":"select","expression":{"__symbolic":"reference","module":"@angular/core","name":"ChangeDetectionStrategy","line":43,"character":21},"member":"OnPush"},"template":"<div>\n <img\n [src]=\"safeImgDataUrl\"\n [style.visibility]=\"imageVisible ? 'visible' : 'hidden'\"\n (load)=\"imageLoadedInView()\"\n class=\"source-image\"\n />\n <div class=\"cropper\"\n [class.rounded]=\"roundCropper\"\n [style.top.px]=\"cropper.y1\"\n [style.left.px]=\"cropper.x1\"\n [style.width.px]=\"cropper.x2 - cropper.x1\"\n [style.height.px]=\"cropper.y2 - cropper.y1\"\n [style.margin-left]=\"marginLeft\"\n [style.visibility]=\"imageVisible ? 'visible' : 'hidden'\"\n >\n <div\n (mousedown)=\"startMove($event, 'move')\"\n (touchstart)=\"startMove($event, 'move')\"\n class=\"move\"\n > </div>\n <span\n class=\"resize topleft\"\n (mousedown)=\"startMove($event, 'resize', 'topleft')\"\n (touchstart)=\"startMove($event, 'resize', 'topleft')\"\n ><span class=\"square\"></span></span>\n <span\n class=\"resize top\"\n ><span class=\"square\"></span></span>\n <span\n class=\"resize topright\"\n (mousedown)=\"startMove($event, 'resize', 'topright')\"\n (touchstart)=\"startMove($event, 'resize', 'topright')\"\n ><span class=\"square\"></span></span>\n <span\n class=\"resize right\"\n ><span class=\"square\"></span></span>\n <span\n class=\"resize bottomright\"\n (mousedown)=\"startMove($event, 'resize', 'bottomright')\"\n (touchstart)=\"startMove($event, 'resize', 'bottomright')\"\n ><span class=\"square\"></span></span>\n <span\n class=\"resize bottom\"\n ><span class=\"square\"></span></span>\n <span\n class=\"resize bottomleft\"\n (mousedown)=\"startMove($event, 'resize', 'bottomleft')\"\n (touchstart)=\"startMove($event, 'resize', 'bottomleft')\"\n ><span class=\"square\"></span></span>\n <span\n class=\"resize left\"\n ><span class=\"square\"></span></span>\n <span\n class=\"resize-bar top\"\n (mousedown)=\"startMove($event, 'resize', 'top')\"\n (touchstart)=\"startMove($event, 'resize', 'top')\"\n ></span>\n <span\n class=\"resize-bar right\"\n (mousedown)=\"startMove($event, 'resize', 'right')\"\n (touchstart)=\"startMove($event, 'resize', 'right')\"\n ></span>\n <span\n class=\"resize-bar bottom\"\n (mousedown)=\"startMove($event, 'resize', 'bottom')\"\n (touchstart)=\"startMove($event, 'resize', 'bottom')\"\n ></span>\n <span\n class=\"resize-bar left\"\n (mousedown)=\"startMove($event, 'resize', 'left')\"\n (touchstart)=\"startMove($event, 'resize', 'left')\"\n ></span>\n </div>\n</div>\n","styles":[":host{display:flex;position:relative;width:100%;max-width:100%;max-height:100%;overflow:hidden;padding:5px;text-align:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}:host>div{position:relative;width:100%}:host>div .source-image{max-width:100%;max-height:100%}:host .cropper{position:absolute;display:flex;color:#53535c!important;background:0 0!important;touch-action:none;outline:rgba(255,255,255,.3) solid 1000px}:host .cropper:after{position:absolute;content:'';top:0;bottom:0;left:0;right:0;pointer-events:none;border:1px dashed;opacity:.75;color:inherit;z-index:1}:host .cropper .move{width:100%;cursor:move;border:1px solid rgba(255,255,255,.5)}:host .cropper .resize{position:absolute;display:inline-block;line-height:6px;padding:8px;opacity:.85;z-index:1}:host .cropper .resize .square{display:inline-block;background:#53535c!important;width:6px;height:6px;border:1px solid rgba(255,255,255,.5)}:host .cropper .resize.topleft{top:-12px;left:-12px;cursor:nw-resize}:host .cropper .resize.top{top:-12px;left:calc(50% - 12px);cursor:n-resize}:host .cropper .resize.topright{top:-12px;right:-12px;cursor:ne-resize}:host .cropper .resize.right{top:calc(50% - 12px);right:-12px;cursor:e-resize}:host .cropper .resize.bottomright{bottom:-12px;right:-12px;cursor:se-resize}:host .cropper .resize.bottom{bottom:-12px;left:calc(50% - 12px);cursor:s-resize}:host .cropper .resize.bottomleft{bottom:-12px;left:-12px;cursor:sw-resize}:host .cropper .resize.left{top:calc(50% - 12px);left:-12px;cursor:w-resize}:host .cropper .resize-bar{position:absolute;z-index:1}:host .cropper .resize-bar.top{top:-11px;left:11px;width:calc(100% - 22px);height:22px;cursor:n-resize}:host .cropper .resize-bar.right{top:11px;right:-11px;height:calc(100% - 22px);width:22px;cursor:e-resize}:host .cropper .resize-bar.bottom{bottom:-11px;left:11px;width:calc(100% - 22px);height:22px;cursor:s-resize}:host .cropper .resize-bar.left{top:11px;left:-11px;height:calc(100% - 22px);width:22px;cursor:w-resize}:host .cropper.rounded{outline-color:transparent}:host .cropper.rounded:after{box-shadow:0 0 0 100vw rgba(255,255,255,.3);border-radius:100%}:host .cropper.rounded .move{border-radius:100%}"]}]}],"members":{"imageFileChanged":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":55,"character":5}}]}],"imageChangedEvent":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":63,"character":5}}]}],"imageBase64":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":71,"character":5}}]}],"format":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":77,"character":5}}]}],"maintainAspectRatio":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":78,"character":5}}]}],"aspectRatio":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":79,"character":5}}]}],"resizeToWidth":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":80,"character":5}}]}],"roundCropper":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":81,"character":5}}]}],"onlyScaleDown":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":82,"character":5}}]}],"imageQuality":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":83,"character":5}}]}],"cropper":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":84,"character":5}}]}],"imageCroppedBase64":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":91,"character":5}}]}],"imageCroppedFile":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":92,"character":5}}]}],"imageLoaded":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":93,"character":5}}]}],"loadImageFailed":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":94,"character":5}}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"ElementRef","line":96,"character":36},{"__symbolic":"reference","module":"@angular/platform-browser","name":"DomSanitizer","line":96,"character":67},{"__symbolic":"reference","module":"@angular/core","name":"ChangeDetectorRef","line":96,"character":93}]}],"ngOnChanges":[{"__symbolic":"method"}],"initCropper":[{"__symbolic":"method"}],"loadImageFile":[{"__symbolic":"method"}],"isValidImageType":[{"__symbolic":"method"}],"checkExifRotationAndLoadImage":[{"__symbolic":"method"}],"loadBase64Image":[{"__symbolic":"method"}],"imageLoadedInView":[{"__symbolic":"method"}],"onResize":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"HostListener","line":197,"character":5},"arguments":["window:resize",["$event"]]}]}],"resizeCropperPosition":[{"__symbolic":"method"}],"resetCropperPosition":[{"__symbolic":"method"}],"startMove":[{"__symbolic":"method"}],"moveImg":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"HostListener","line":242,"character":5},"arguments":["document:mousemove",["$event"]]},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"HostListener","line":243,"character":5},"arguments":["document:touchmove",["$event"]]}]}],"setMaxSize":[{"__symbolic":"method"}],"checkCropperPosition":[{"__symbolic":"method"}],"moveStop":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"HostListener","line":286,"character":5},"arguments":["document:mouseup",["$event"]]},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"HostListener","line":287,"character":5},"arguments":["document:touchend",["$event"]]}]}],"move":[{"__symbolic":"method"}],"resize":[{"__symbolic":"method"}],"checkAspectRatio":[{"__symbolic":"method"}],"crop":[{"__symbolic":"method"}],"getResizeRatio":[{"__symbolic":"method"}],"getClientX":[{"__symbolic":"method"}],"getClientY":[{"__symbolic":"method"}]}}},"origins":{"ImageCropperModule":"./src/image-cropper.module","ImageCropperComponent":"./src/image-cropper.component"},"importAs":"ngx-image-cropper"} | ||
{"__symbolic":"module","version":4,"metadata":{"ImageCropperModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":4,"character":1},"arguments":[{"imports":[{"__symbolic":"reference","module":"@angular/common","name":"CommonModule","line":6,"character":8}],"declarations":[{"__symbolic":"reference","name":"ImageCropperComponent"}],"exports":[{"__symbolic":"reference","name":"ImageCropperComponent"}]}]}],"members":{}},"ImageCropperComponent":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component","line":39,"character":1},"arguments":[{"selector":"image-cropper","changeDetection":{"__symbolic":"select","expression":{"__symbolic":"reference","module":"@angular/core","name":"ChangeDetectionStrategy","line":43,"character":21},"member":"OnPush"},"template":"<div>\n <img\n [src]=\"safeImgDataUrl\"\n [style.visibility]=\"imageVisible ? 'visible' : 'hidden'\"\n (load)=\"imageLoadedInView()\"\n class=\"source-image\"\n />\n <div class=\"cropper\"\n [class.rounded]=\"roundCropper\"\n [style.top.px]=\"cropper.y1\"\n [style.left.px]=\"cropper.x1\"\n [style.width.px]=\"cropper.x2 - cropper.x1\"\n [style.height.px]=\"cropper.y2 - cropper.y1\"\n [style.margin-left]=\"marginLeft\"\n [style.visibility]=\"imageVisible ? 'visible' : 'hidden'\"\n >\n <div\n (mousedown)=\"startMove($event, 'move')\"\n (touchstart)=\"startMove($event, 'move')\"\n class=\"move\"\n > </div>\n <span\n class=\"resize topleft\"\n (mousedown)=\"startMove($event, 'resize', 'topleft')\"\n (touchstart)=\"startMove($event, 'resize', 'topleft')\"\n ><span class=\"square\"></span></span>\n <span\n class=\"resize top\"\n ><span class=\"square\"></span></span>\n <span\n class=\"resize topright\"\n (mousedown)=\"startMove($event, 'resize', 'topright')\"\n (touchstart)=\"startMove($event, 'resize', 'topright')\"\n ><span class=\"square\"></span></span>\n <span\n class=\"resize right\"\n ><span class=\"square\"></span></span>\n <span\n class=\"resize bottomright\"\n (mousedown)=\"startMove($event, 'resize', 'bottomright')\"\n (touchstart)=\"startMove($event, 'resize', 'bottomright')\"\n ><span class=\"square\"></span></span>\n <span\n class=\"resize bottom\"\n ><span class=\"square\"></span></span>\n <span\n class=\"resize bottomleft\"\n (mousedown)=\"startMove($event, 'resize', 'bottomleft')\"\n (touchstart)=\"startMove($event, 'resize', 'bottomleft')\"\n ><span class=\"square\"></span></span>\n <span\n class=\"resize left\"\n ><span class=\"square\"></span></span>\n <span\n class=\"resize-bar top\"\n (mousedown)=\"startMove($event, 'resize', 'top')\"\n (touchstart)=\"startMove($event, 'resize', 'top')\"\n ></span>\n <span\n class=\"resize-bar right\"\n (mousedown)=\"startMove($event, 'resize', 'right')\"\n (touchstart)=\"startMove($event, 'resize', 'right')\"\n ></span>\n <span\n class=\"resize-bar bottom\"\n (mousedown)=\"startMove($event, 'resize', 'bottom')\"\n (touchstart)=\"startMove($event, 'resize', 'bottom')\"\n ></span>\n <span\n class=\"resize-bar left\"\n (mousedown)=\"startMove($event, 'resize', 'left')\"\n (touchstart)=\"startMove($event, 'resize', 'left')\"\n ></span>\n </div>\n</div>\n","styles":[":host{display:flex;position:relative;width:100%;max-width:100%;max-height:100%;overflow:hidden;padding:5px;text-align:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}:host>div{position:relative;width:100%}:host>div .source-image{max-width:100%;max-height:100%}:host .cropper{position:absolute;display:flex;color:#53535c!important;background:0 0!important;touch-action:none;outline:rgba(255,255,255,.3) solid 1000px}:host .cropper:after{position:absolute;content:'';top:0;bottom:0;left:0;right:0;pointer-events:none;border:1px dashed;opacity:.75;color:inherit;z-index:1}:host .cropper .move{width:100%;cursor:move;border:1px solid rgba(255,255,255,.5)}:host .cropper .resize{position:absolute;display:inline-block;line-height:6px;padding:8px;opacity:.85;z-index:1}:host .cropper .resize .square{display:inline-block;background:#53535c!important;width:6px;height:6px;border:1px solid rgba(255,255,255,.5)}:host .cropper .resize.topleft{top:-12px;left:-12px;cursor:nw-resize}:host .cropper .resize.top{top:-12px;left:calc(50% - 12px);cursor:n-resize}:host .cropper .resize.topright{top:-12px;right:-12px;cursor:ne-resize}:host .cropper .resize.right{top:calc(50% - 12px);right:-12px;cursor:e-resize}:host .cropper .resize.bottomright{bottom:-12px;right:-12px;cursor:se-resize}:host .cropper .resize.bottom{bottom:-12px;left:calc(50% - 12px);cursor:s-resize}:host .cropper .resize.bottomleft{bottom:-12px;left:-12px;cursor:sw-resize}:host .cropper .resize.left{top:calc(50% - 12px);left:-12px;cursor:w-resize}:host .cropper .resize-bar{position:absolute;z-index:1}:host .cropper .resize-bar.top{top:-11px;left:11px;width:calc(100% - 22px);height:22px;cursor:n-resize}:host .cropper .resize-bar.right{top:11px;right:-11px;height:calc(100% - 22px);width:22px;cursor:e-resize}:host .cropper .resize-bar.bottom{bottom:-11px;left:11px;width:calc(100% - 22px);height:22px;cursor:s-resize}:host .cropper .resize-bar.left{top:11px;left:-11px;height:calc(100% - 22px);width:22px;cursor:w-resize}:host .cropper.rounded{outline-color:transparent}:host .cropper.rounded:after{box-shadow:0 0 0 100vw rgba(255,255,255,.3);border-radius:100%}:host .cropper.rounded .move{border-radius:100%}"]}]}],"members":{"imageFileChanged":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":55,"character":5}}]}],"imageChangedEvent":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":63,"character":5}}]}],"imageBase64":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":71,"character":5}}]}],"format":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":77,"character":5}}]}],"maintainAspectRatio":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":78,"character":5}}]}],"aspectRatio":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":79,"character":5}}]}],"resizeToWidth":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":80,"character":5}}]}],"roundCropper":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":81,"character":5}}]}],"onlyScaleDown":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":82,"character":5}}]}],"imageQuality":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":83,"character":5}}]}],"cropper":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":84,"character":5}}]}],"imageCropped":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":92,"character":5}}]}],"imageCroppedBase64":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":93,"character":5}}]}],"imageCroppedFile":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":94,"character":5}}]}],"imageLoaded":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":95,"character":5}}]}],"loadImageFailed":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":96,"character":5}}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"ElementRef","line":98,"character":36},{"__symbolic":"reference","module":"@angular/platform-browser","name":"DomSanitizer","line":98,"character":67},{"__symbolic":"reference","module":"@angular/core","name":"ChangeDetectorRef","line":98,"character":93}]}],"ngOnChanges":[{"__symbolic":"method"}],"initCropper":[{"__symbolic":"method"}],"loadImageFile":[{"__symbolic":"method"}],"isValidImageType":[{"__symbolic":"method"}],"checkExifRotationAndLoadImage":[{"__symbolic":"method"}],"loadBase64Image":[{"__symbolic":"method"}],"imageLoadedInView":[{"__symbolic":"method"}],"onResize":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"HostListener","line":202,"character":5},"arguments":["window:resize",["$event"]]}]}],"resizeCropperPosition":[{"__symbolic":"method"}],"resetCropperPosition":[{"__symbolic":"method"}],"startMove":[{"__symbolic":"method"}],"moveImg":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"HostListener","line":247,"character":5},"arguments":["document:mousemove",["$event"]]},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"HostListener","line":248,"character":5},"arguments":["document:touchmove",["$event"]]}]}],"setMaxSize":[{"__symbolic":"method"}],"checkCropperPosition":[{"__symbolic":"method"}],"moveStop":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"HostListener","line":291,"character":5},"arguments":["document:mouseup",["$event"]]},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"HostListener","line":292,"character":5},"arguments":["document:touchend",["$event"]]}]}],"move":[{"__symbolic":"method"}],"resize":[{"__symbolic":"method"}],"checkAspectRatio":[{"__symbolic":"method"}],"crop":[{"__symbolic":"method"}],"getResizeRatio":[{"__symbolic":"method"}],"getClientX":[{"__symbolic":"method"}],"getClientY":[{"__symbolic":"method"}]}}},"origins":{"ImageCropperModule":"./src/image-cropper.module","ImageCropperComponent":"./src/image-cropper.component"},"importAs":"ngx-image-cropper"} |
{ | ||
"name": "ngx-image-cropper", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "An image cropper for Angular", | ||
@@ -5,0 +5,0 @@ "main": "bundles/ngx-image-cropper.umd.js", |
@@ -44,3 +44,3 @@ # Image cropper for Angular | ||
format="png" | ||
(imageCroppedBase64)="imageCropped($event)" | ||
(imageCropped)="imageCropped($event)" | ||
(imageLoaded)="imageLoaded()" | ||
@@ -61,4 +61,4 @@ (loadImageFailed)="loadImageFailed()" | ||
} | ||
imageCropped(image: string) { | ||
this.croppedImage = image; | ||
imageCropped(event: ImageCroppedEvent) { | ||
this.croppedImage = event.base64; | ||
} | ||
@@ -82,3 +82,3 @@ imageLoaded() { | ||
| `imageChangedEvent` | FileEvent | | The change event from your file input (set to `null` to reset the cropper) | | ||
| `imageFileChanged` | File | | The file you want to change (set to `null` to reset the cropper) | | ||
| `imageFileChanged` | Blob(File)| | The file you want to change (set to `null` to reset the cropper) | | ||
| `imageBase64` | string | | If you don't want to use a file input, you can set a base64 image directly and it will be loaded into the cropper | | ||
@@ -94,7 +94,26 @@ | `format` | string | png | Output format (png, jpeg, webp, bmp, ico) (not all browsers support all types, png is always supported, others are optional) | | ||
### Outputs | ||
| Name | Type | Description | | ||
| ----------------------- | ------ | ----------- | | ||
| `imageCroppedBase64` | string | Emits a Base64 string of the cropped image each time it is cropped | | ||
| `imageCroppedFile` | File | Emits the cropped image as a file each time it is cropped | | ||
| `imageLoaded` | void | Emits when the image was loaded into the cropper | | ||
| `loadImageFailed` | void | Emits when a wrong file type was selected (only png, gif and jpg are allowed) | | ||
| Name | Type | Description | | ||
| ----------------------- | ----------------- | ----------- | | ||
| `imageCropped` | ImageCroppedEvent | Emits a ImageCroppedEvent image each time it is cropped | | ||
| **(DEPRECATED)** `imageCroppedBase64` | string | Emits a Base64 string of the cropped image each time it is cropped | | ||
| **(DEPRECATED)** `imageCroppedFile` | File | Emits the cropped image as a file each time it is cropped | | ||
| `imageLoaded` | void | Emits when the image was loaded into the cropper | | ||
| `loadImageFailed` | void | Emits when a wrong file type was selected (only png, gif and jpg are allowed) | | ||
### Interfaces | ||
#### CropperPosition | ||
| Property | Type | Description | | ||
| -------- | ------ | ----------- | | ||
| x1 | number | X position of first coordinate (in px) | | ||
| y1 | number | Y position of first coordinate (in px) | | ||
| x2 | number | X position of second coordinate (in px) | | ||
| y2 | number | Y position of second coordinate (in px) | | ||
#### ImageCroppedEvent | ||
| Property | Type | Description | | ||
| --------------- | ------ | ----------- | | ||
| base64 | string | Base64 string of the cropped image | | ||
| file | Blob(File) | Blob of the cropped image | | ||
| width | number | Width of the cropped image | | ||
| height | number | Height of the cropped image | | ||
| croppedPosition | CropperPosition | Position of the cropper when it was cropped | |
@@ -9,2 +9,9 @@ import { ElementRef, EventEmitter, OnChanges, SimpleChanges, ChangeDetectorRef } from '@angular/core'; | ||
} | ||
export interface ImageCroppedEvent { | ||
base64: string; | ||
file: Blob; | ||
width: number; | ||
height: number; | ||
cropperPosition: CropperPosition; | ||
} | ||
export declare class ImageCropperComponent implements OnChanges { | ||
@@ -32,4 +39,5 @@ private elementRef; | ||
cropper: CropperPosition; | ||
imageCropped: EventEmitter<ImageCroppedEvent>; | ||
imageCroppedBase64: EventEmitter<string>; | ||
imageCroppedFile: EventEmitter<File>; | ||
imageCroppedFile: EventEmitter<Blob>; | ||
imageLoaded: EventEmitter<void>; | ||
@@ -36,0 +44,0 @@ loadImageFailed: EventEmitter<void>; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
699685
4421
116
0