ngx-image-cropper-facet
Version:
An image cropper for Angular
3 lines (2 loc) • 37 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("rxjs/Observable"),require("@angular/common"),require("@angular/platform-browser")):"function"==typeof define&&define.amd?define(["exports","@angular/core","rxjs/Observable","@angular/common","@angular/platform-browser"],t):t(e["ngx-image-cropper-facet"]={},e.ng.core,e.Rx,e.ng.common,e.ng.platformBrowser)}(this,function(e,o,t,i,r){"use strict";var h=function(){function e(){this._debug=!1,this._isXmpEnabled=!1,this._fileType="image/jpg",this._errorMessage={imageFailedToLoad:"Could not load image",invalidImageFormat:"Invalid image format provided"},this.exifTags={36864:"ExifVersion",40960:"FlashpixVersion",40961:"ColorSpace",40962:"PixelXDimension",40963:"PixelYDimension",37121:"ComponentsConfiguration",37122:"CompressedBitsPerPixel",37500:"MakerNote",37510:"UserComment",40964:"RelatedSoundFile",36867:"DateTimeOriginal",36868:"DateTimeDigitized",37520:"SubsecTime",37521:"SubsecTimeOriginal",37522:"SubsecTimeDigitized",33434:"ExposureTime",33437:"FNumber",34850:"ExposureProgram",34852:"SpectralSensitivity",34855:"ISOSpeedRatings",34856:"OECF",37377:"ShutterSpeedValue",37378:"ApertureValue",37379:"BrightnessValue",37380:"ExposureBias",37381:"MaxApertureValue",37382:"SubjectDistance",37383:"MeteringMode",37384:"LightSource",37385:"Flash",37396:"SubjectArea",37386:"FocalLength",41483:"FlashEnergy",41484:"SpatialFrequencyResponse",41486:"FocalPlaneXResolution",41487:"FocalPlaneYResolution",41488:"FocalPlaneResolutionUnit",41492:"SubjectLocation",41493:"ExposureIndex",41495:"SensingMethod",41728:"FileSource",41729:"SceneType",41730:"CFAPattern",41985:"CustomRendered",41986:"ExposureMode",41987:"WhiteBalance",41988:"DigitalZoomRation",41989:"FocalLengthIn35mmFilm",41990:"SceneCaptureType",41991:"GainControl",41992:"Contrast",41993:"Saturation",41994:"Sharpness",41995:"DeviceSettingDescription",41996:"SubjectDistanceRange",40965:"InteroperabilityIFDPointer",42016:"ImageUniqueID"},this.tiffTags={256:"ImageWidth",257:"ImageHeight",34665:"ExifIFDPointer",34853:"GPSInfoIFDPointer",40965:"InteroperabilityIFDPointer",258:"BitsPerSample",259:"Compression",262:"PhotometricInterpretation",274:"Orientation",277:"SamplesPerPixel",284:"PlanarConfiguration",530:"YCbCrSubSampling",531:"YCbCrPositioning",282:"XResolution",283:"YResolution",296:"ResolutionUnit",273:"StripOffsets",278:"RowsPerStrip",279:"StripByteCounts",513:"JPEGInterchangeFormat",514:"JPEGInterchangeFormatLength",301:"TransferFunction",318:"WhitePoint",319:"PrimaryChromaticities",529:"YCbCrCoefficients",532:"ReferenceBlackWhite",306:"DateTime",270:"ImageDescription",271:"Make",272:"Model",305:"Software",315:"Artist",33432:"Copyright"},this.gpsTags={0:"GPSVersionID",1:"GPSLatitudeRef",2:"GPSLatitude",3:"GPSLongitudeRef",4:"GPSLongitude",5:"GPSAltitudeRef",6:"GPSAltitude",7:"GPSTimeStamp",8:"GPSSatellites",9:"GPSStatus",10:"GPSMeasureMode",11:"GPSDOP",12:"GPSSpeedRef",13:"GPSSpeed",14:"GPSTrackRef",15:"GPSTrack",16:"GPSImgDirectionRef",17:"GPSImgDirection",18:"GPSMapDatum",19:"GPSDestLatitudeRef",20:"GPSDestLatitude",21:"GPSDestLongitudeRef",22:"GPSDestLongitude",23:"GPSDestBearingRef",24:"GPSDestBearing",25:"GPSDestDistanceRef",26:"GPSDestDistance",27:"GPSProcessingMethod",28:"GPSAreaInformation",29:"GPSDateStamp",30:"GPSDifferential",31:"GPSHPositioningError"},this.ifd1Tags={256:"ImageWidth",257:"ImageHeight",258:"BitsPerSample",259:"Compression",262:"PhotometricInterpretation",273:"StripOffsets",274:"Orientation",277:"SamplesPerPixel",278:"RowsPerStrip",279:"StripByteCounts",282:"XResolution",283:"YResolution",284:"PlanarConfiguration",296:"ResolutionUnit",513:"JpegIFOffset",514:"JpegIFByteCount",529:"YCbCrCoefficients",530:"YCbCrSubSampling",531:"YCbCrPositioning",532:"ReferenceBlackWhite"},this.stringValues={ExposureProgram:{0:"Not defined",1:"Manual",2:"Normal program",3:"Aperture priority",4:"Shutter priority",5:"Creative program",6:"Action program",7:"Portrait mode",8:"Landscape mode"},MeteringMode:{0:"Unknown",1:"Average",2:"CenterWeightedAverage",3:"Spot",4:"MultiSpot",5:"Pattern",6:"Partial",255:"Other"},LightSource:{0:"Unknown",1:"Daylight",2:"Fluorescent",3:"Tungsten (incandescent light)",4:"Flash",9:"Fine weather",10:"Cloudy weather",11:"Shade",12:"Daylight fluorescent (D 5700 - 7100K)",13:"Day white fluorescent (N 4600 - 5400K)",14:"Cool white fluorescent (W 3900 - 4500K)",15:"White fluorescent (WW 3200 - 3700K)",17:"Standard light A",18:"Standard light B",19:"Standard light C",20:"D55",21:"D65",22:"D75",23:"D50",24:"ISO studio tungsten",255:"Other"},Flash:{0:"Flash did not fire",1:"Flash fired",5:"Strobe return light not detected",7:"Strobe return light detected",9:"Flash fired, compulsory flash mode",13:"Flash fired, compulsory flash mode, return light not detected",15:"Flash fired, compulsory flash mode, return light detected",16:"Flash did not fire, compulsory flash mode",24:"Flash did not fire, auto mode",25:"Flash fired, auto mode",29:"Flash fired, auto mode, return light not detected",31:"Flash fired, auto mode, return light detected",32:"No flash function",65:"Flash fired, red-eye reduction mode",69:"Flash fired, red-eye reduction mode, return light not detected",71:"Flash fired, red-eye reduction mode, return light detected",73:"Flash fired, compulsory flash mode, red-eye reduction mode",77:"Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected",79:"Flash fired, compulsory flash mode, red-eye reduction mode, return light detected",89:"Flash fired, auto mode, red-eye reduction mode",93:"Flash fired, auto mode, return light not detected, red-eye reduction mode",95:"Flash fired, auto mode, return light detected, red-eye reduction mode"},SensingMethod:{1:"Not defined",2:"One-chip color area sensor",3:"Two-chip color area sensor",4:"Three-chip color area sensor",5:"Color sequential area sensor",7:"Trilinear sensor",8:"Color sequential linear sensor"},SceneCaptureType:{0:"Standard",1:"Landscape",2:"Portrait",3:"Night scene"},SceneType:{1:"Directly photographed"},CustomRendered:{0:"Normal process",1:"Custom process"},WhiteBalance:{0:"Auto white balance",1:"Manual white balance"},GainControl:{0:"None",1:"Low gain up",2:"High gain up",3:"Low gain down",4:"High gain down"},Contrast:{0:"Normal",1:"Soft",2:"Hard"},Saturation:{0:"Normal",1:"Low saturation",2:"High saturation"},Sharpness:{0:"Normal",1:"Soft",2:"Hard"},SubjectDistanceRange:{0:"Unknown",1:"Macro",2:"Close view",3:"Distant view"},FileSource:{3:"DSC"},Components:{0:"",1:"Y",2:"Cb",3:"Cr",4:"R",5:"G",6:"B"}},this.iptcFieldMap={120:"caption",110:"credit",22:"fixtureID",25:"keywords",55:"dateCreated",80:"byline",85:"bylineTitle",122:"captionWriter",105:"headline",116:"copyright",15:"category"}}return e.prototype.enableXmp=function(){this._isXmpEnabled=!0},e.prototype.disableXmp=function(){this._isXmpEnabled=!1},e.prototype.fileType=function(e){this._fileType=e},e.prototype.getData=function(e){var i=this;return t.Observable.create(function(t){i.getImageData(e).subscribe(function(e){t.next(e)},function(e){t.error(e)})})},e.prototype.getTag=function(e,t){if(this.imageHasData(e))return e.exif[t]},e.prototype.getIptcTag=function(e,t){if(this.imageHasData(e))return e.iptc[t]},e.prototype.getAllTags=function(e){if(!this.imageHasData(e))return{};var t,i=e.exif,r={};for(t in i)i.hasOwnProperty(t)&&(r[t]=i[t]);return r},e.prototype.getAllIptcTags=function(e){if(!this.imageHasData(e))return{};var t,i=e.iptc,r={};for(t in i)i.hasOwnProperty(t)&&(r[t]=i[t]);return r},e.prototype.pretty=function(e){if(!this.imageHasData(e))return"";var t,i=e.exif,r="";for(t in i)i.hasOwnProperty(t)&&("object"==typeof i[t]?i[t]instanceof Number?r+=t+" : "+i[t]+" ["+i[t].numerator+"/"+i[t].denominator+"]\r\n":r+=t+" : ["+i[t].length+" values]\r\n":r+=t+" : "+i[t]+"\r\n");return r},e.prototype.getImageData=function(l){var g=this;return t.Observable.create(function(r){if(FileReader&&(l instanceof Blob||l instanceof File)){var e=new FileReader;e.onload=function(e){var t=e.target.result,i=g.findAndSetImageTagData(t);i.onload=function(){r.next(i)},i=g.addImageSourceFromArrayBuffer(i,t)},l instanceof Blob?e.readAsArrayBuffer(l):e.readAsDataURL(l)}else if(l instanceof ArrayBuffer){var t=g.findAndSetImageTagData(l);t.onload=function(){r.next(t)},t=g.addImageSourceFromArrayBuffer(t,l)}else if(l instanceof HTMLImageElement){var i=(p=l.src).slice(0,25);if(/^data\:/i.test(i)){var o=g.base64ToArrayBuffer(p),n=g.findAndSetImageTagData(o);n.onload=function(){r.next(n)},n=g.addImageSource(n,p)}else if(/^blob\:/i.test(i)){var a=new FileReader;a.onload=function(e){var t=e.target.result,i=g.findAndSetImageTagData(t);i.onload=function(){r.next(i)},i=g.addImageSourceFromArrayBuffer(i,t)},g.objectURLToBlob(p,function(e){a.readAsArrayBuffer(e)})}else{var s=new XMLHttpRequest;s.onload=function(){if(200==s.status||0===s.status){var e=s.response,t=g.findAndSetImageTagData(e);t.onload=function(){r.next(t)},t=g.addImageSourceFromArrayBuffer(t,e)}else r.error(g._errorMessage.imageFailedToLoad)},s.open("GET",p,!0),s.responseType="arraybuffer",s.send(null)}}else{var p,h=(p=l).slice(0,25);if(/^data\:/i.test(h)){o=g.base64ToArrayBuffer(p);var c=g.findAndSetImageTagData(o);c.onload=function(){r.next(c)},c=g.addImageSource(c,p)}else r.error(g._errorMessage.invalidImageFormat)}})},e.prototype.findAndSetImageTagData=function(e){var t=this.findEXIFinJPEG(e),i=this.findIPTCinJPEG(e),r=new Image;return r.exif=t||{},r.iptc=i||{},this._isXmpEnabled&&(r.xmp=this.findXMPinJPEG(e)),r},e.prototype.addImageSourceFromArrayBuffer=function(e,t){var i=this.arrayBufferToBase64(t),r="data:"+this._fileType+";base64,"+i;return this.addImageSource(e,r)},e.prototype.addImageSource=function(e,t){return e.src=t,e},e.prototype.arrayBufferToBase64=function(e){for(var t="",i=new Uint8Array(e),r=i.byteLength,o=0;o<r;o++)t+=String.fromCharCode(i[o]);return window.btoa(t)},e.prototype.base64ToArrayBuffer=function(e){e=e.replace(/^data\:([^\;]+)\;base64,/gim,"");for(var t=atob(e),i=t.length,r=new ArrayBuffer(i),o=new Uint8Array(r),n=0;n<i;n++)o[n]=t.charCodeAt(n);return r},e.prototype.objectURLToBlob=function(e,t){var i=new XMLHttpRequest;i.open("GET",e,!0),i.responseType="blob",i.onload=function(){200!=i.status&&0!==i.status||t(i.response)},i.send()},e.prototype.findEXIFinJPEG=function(e){var t=new DataView(e);if(this.log("Got file of length "+e.byteLength),255!=t.getUint8(0)||216!=t.getUint8(1))return this.log("Not a valid JPEG"),!1;for(var i,r=2,o=e.byteLength;r<o;){if(255!=t.getUint8(r))return this.log("Not a valid marker at offset "+r+", found: "+t.getUint8(r)),!1;if(i=t.getUint8(r+1),this.log(i),225==i)return this.log("Found 0xFFE1 marker"),this.readEXIFData(t,r+4);r+=2+t.getUint16(r+2)}},e.prototype.findIPTCinJPEG=function(e){var t=new DataView(e);if(this.log("Got file of length "+e.byteLength),255!=t.getUint8(0)||216!=t.getUint8(1))return this.log("Not a valid JPEG"),!1;for(var i,r,o=2,n=e.byteLength;o<n;){if(r=o,56===(i=t).getUint8(r)&&66===i.getUint8(r+1)&&73===i.getUint8(r+2)&&77===i.getUint8(r+3)&&4===i.getUint8(r+4)&&4===i.getUint8(r+5)){var a=t.getUint8(o+7);a%2!=0&&(a+=1),0===a&&(a=4);var s=o+8+a,p=t.getUint16(o+6+a);return this.readIPTCData(e,s,p)}o++}},e.prototype.readIPTCData=function(e,t,i){for(var r,o,n,a,s=new DataView(e),p={},h=t;h<t+i;)28===s.getUint8(h)&&2===s.getUint8(h+1)&&(a=s.getUint8(h+2))in this.iptcFieldMap&&(n=s.getInt16(h+3),o=this.iptcFieldMap[a],r=this.getStringFromDB(s,h+5,n),p.hasOwnProperty(o)?p[o]instanceof Array?p[o].push(r):p[o]=[p[o],r]:p[o]=r),h++;return p},e.prototype.readTags=function(e,t,i,r,o){for(var n,a,s=e.getUint16(i,!o),p={},h=0;h<s;h++)n=i+12*h+2,(a=r[e.getUint16(n,!o)])||this.log("Unknown tag: "+e.getUint16(n,!o)),p[a]=this.readTagValue(e,n,t,i,o);return p},e.prototype.readTagValue=function(e,t,i,r,o){var n,a,s,p,h,c=e.getUint16(t+2,!o),l=e.getUint32(t+4,!o),g=e.getUint32(t+8,!o)+i;switch(c){case 1:case 7:if(1===l)return e.getUint8(t+8,!o);for(n=4<l?g:t+8,a=[],s=0;s<l;s++)a[s]=e.getUint8(n+s);return a;case 2:return n=4<l?g:t+8,this.getStringFromDB(e,n,l-1);case 3:if(1===l)return e.getUint16(t+8,!o);for(n=2<l?g:t+8,a=[],s=0;s<l;s++)a[s]=e.getUint16(n+2*s,!o);return a;case 4:if(1===l)return e.getUint32(t+8,!o);for(a=[],s=0;s<l;s++)a[s]=e.getUint32(g+4*s,!o);return a;case 5:if(1===l)return{numerator:p=e.getUint32(g,!o),denominator:h=e.getUint32(g+4,!o),value:p/h};for(a=[],s=0;s<l;s++)p=e.getUint32(g+8*s,!o),h=e.getUint32(g+4+8*s,!o),a[s]={numerator:p,denominator:h,value:p/h};return a;case 9:if(1===l)return e.getInt32(t+8,!o);for(a=[],s=0;s<l;s++)a[s]=e.getInt32(g+4*s,!o);return a;case 10:if(1===l)return e.getInt32(g,!o)/e.getInt32(g+4,!o);for(a=[],s=0;s<l;s++){var m=e.getInt32(g+8*s,!o),u=e.getInt32(g+4+8*s,!o);a[s]=m/u}return a}},e.prototype.readThumbnailImage=function(e,t,i,r){var o=this.getNextIFDOffset(e,t+i,r);if(!o)return{};if(o>e.byteLength)return{};var n=this.readTags(e,t,t+o,this.ifd1Tags,r);if(n.Compression)switch(n.Compression){case 6:if(n.JpegIFOffset&&n.JpegIFByteCount){var a=t+n.JpegIFOffset,s=n.JpegIFByteCount;n.blob=new Blob([new Uint8Array(e.buffer,a,s)],{type:"image/jpeg"})}break;case 1:this.log("Thumbnail image format is TIFF, which is not implemented.");break;default:this.log("Unknown thumbnail image format: "+n.Compression)}else 2==n.PhotometricInterpretation&&this.log("Thumbnail image format is RGB, which is not implemented.");return n},e.prototype.getNextIFDOffset=function(e,t,i){var r=e.getUint16(t,!i);return e.getUint32(t+2+12*r,!i)},e.prototype.readEXIFData=function(e,t){if("Exif"!=this.getStringFromDB(e,t,4))return this.log("Not valid EXIF data! "+this.getStringFromDB(e,t,4)),!1;var i,r,o,n,a,s=t+6;if(18761==e.getUint16(s))i=!1;else{if(19789!=e.getUint16(s))return this.log("Not valid TIFF data! (no 0x4949 or 0x4D4D)"),!1;i=!0}if(42!=e.getUint16(s+2,!i))return this.log("Not valid TIFF data! (no 0x002A)"),!1;var p=e.getUint32(s+4,!i);if(p<8)return this.log("Not valid TIFF data! (First offset less than 8)",e.getUint32(s+4,!i)),!1;if((r=this.readTags(e,s,s+p,this.tiffTags,i)).ExifIFDPointer)for(o in n=this.readTags(e,s,s+r.ExifIFDPointer,this.exifTags,i)){switch(o){case"LightSource":case"Flash":case"MeteringMode":case"ExposureProgram":case"SensingMethod":case"SceneCaptureType":case"SceneType":case"CustomRendered":case"WhiteBalance":case"GainControl":case"Contrast":case"Saturation":case"Sharpness":case"SubjectDistanceRange":case"FileSource":n[o]=this.stringValues[o][n[o]];break;case"ExifVersion":case"FlashpixVersion":n[o]=String.fromCharCode(n[o][0],n[o][1],n[o][2],n[o][3]);break;case"ComponentsConfiguration":n[o]=this.stringValues.Components[n[o][0]]+this.stringValues.Components[n[o][1]]+this.stringValues.Components[n[o][2]]+this.stringValues.Components[n[o][3]]}r[o]=n[o]}if(r.GPSInfoIFDPointer)for(o in a=this.readTags(e,s,s+r.GPSInfoIFDPointer,this.gpsTags,i)){switch(o){case"GPSVersionID":a[o]&&(a[o]=a[o][0]+"."+a[o][1]+"."+a[o][2]+"."+a[o][3])}r[o]=a[o]}return r.thumbnail=this.readThumbnailImage(e,s,p,i),r},e.prototype.getStringFromDB=function(e,t,i){for(var r="",o=t;o<t+i;o++)r+=String.fromCharCode(e.getUint8(o));return r},e.prototype.findXMPinJPEG=function(e){if("DOMParser"in self){var t=new DataView(e);if(this.log("Got file of length "+e.byteLength),255!=t.getUint8(0)||216!=t.getUint8(1))return this.log("Not a valid JPEG"),!1;for(var i=2,r=e.byteLength,o=new DOMParser;i<r-4;){if("http"==this.getStringFromDB(t,i,4)){var n=i-1,a=t.getUint16(i-2)-1,s=this.getStringFromDB(t,n,a),p=s.indexOf("xmpmeta>")+8,h=(s=s.substring(s.indexOf("<x:xmpmeta"),p)).indexOf("x:xmpmeta")+10;s=s.slice(0,h)+'xmlns:Iptc4xmpCore="http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tiff="http://ns.adobe.com/tiff/1.0/" xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus" xmlns:ext="http://www.gettyimages.com/xsltExtension/1.0" xmlns:exif="http://ns.adobe.com/exif/1.0/" xmlns:stEvt="http://ns.adobe.com/xap/1.0/sType/ResourceEvent#" xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#" xmlns:crs="http://ns.adobe.com/camera-raw-settings/1.0/" xmlns:xapGImg="http://ns.adobe.com/xap/1.0/g/img/" xmlns:Iptc4xmpExt="http://iptc.org/std/Iptc4xmpExt/2008-02-29/" '+s.slice(h);var c=o.parseFromString(s,"text/xml");return this.xml2Object(c)}i++}}},e.prototype.xml2json=function(e){var t={};if(1==e.nodeType){if(0<e.attributes.length){t["@attributes"]={};for(var i=0;i<e.attributes.length;i++){var r=e.attributes.item(i);t["@attributes"][r.nodeName]=r.nodeValue}}}else if(3==e.nodeType)return e.nodeValue;if(e.hasChildNodes())for(var o=0;o<e.childNodes.length;o++){var n=e.childNodes.item(o),a=n.nodeName;if(null==t[a])t[a]=this.xml2json(n);else{if(null==t[a].push){var s=t[a];t[a]=[],t[a].push(s)}t[a].push(this.xml2json(n))}}return t},e.prototype.xml2Object=function(e){var t={};if(0<e.children.length)try{for(var i=0;i<e.children.length;i++){var r=e.children.item(i),o=r.attributes;for(var n in o){var a=o[n],s=a.nodeName,p=a.nodeValue;s!==undefined&&(t[s]=p)}var h=r.nodeName;if("undefined"==typeof t[h])t[h]=this.xml2json(r);else{if("undefined"==typeof t[h].push){var c=t[h];t[h]=[],t[h].push(c)}t[h].push(this.xml2json(r))}}}catch(l){this.log(l.message)}else t=e.textContent;return t},e.prototype.imageHasData=function(e){return!!e.exif},e.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._debug&&console.log(e)},e}();h.decorators=[{type:o.Injectable}],h.ctorParameters=function(){return[]};var n=function(){function e(){this.invalidImageFormatProvided="Invalid image format provided."}return e.prototype.getOrientedImage=function(e,s){var p=this;return t.Observable.create(function(n){if(e){var a=new h;a.fileType(s),a.getData(e).subscribe(function(e){var t=a.getTag(e,"Orientation");if(t&&1!==t){var i=e.width;0===i&&0<e.exif.ImageWidth&&(i=e.exif.ImageWidth,e.width=i);var r=e.height;0===r&&0<e.exif.ImageHeight&&(r=e.exif.ImageHeight,e.height=r);var o=p.destinationParameters(t,i,r);p.modifyImage(o,e,s).subscribe(function(e){n.next(e)},function(e){n.error(new Error(e))})}else n.next(e)},function(e){n.error(new Error(e))})}else n.error(new Error(p.invalidImageFormatProvided))})},e.prototype.destinationParameters=function(e,t,i){var r=0,o=0,n=t,a=i,s=0;switch(e){case 3:case 4:r=-t,o=-i,s=180;break;case 5:case 6:a=t,o=-(n=i),s=90;break;case 7:case 8:n=i,r=-(a=t),s=270}return{x:r,y:o,width:n,height:a,rotationDegree:s,imageOrientation:e}},e.prototype.modifyImage=function(o,n,a){return t.Observable.create(function(e){var t=document.createElement("canvas"),i=t.getContext("2d");if(t.width=o.width,t.height=o.height,i){-1<[2,4,5,7].indexOf(o.imageOrientation)&&(i.translate(o.width,0),i.scale(-1,1)),i.rotate(o.rotationDegree*Math.PI/180),i.drawImage(n,o.x,o.y);var r=new Image;r.width=o.width,r.height=o.height,r.onload=function(){e.next(r)},r.src=t.toDataURL(a,1)}else e.next(n)})},e}();n.decorators=[{type:o.Injectable}],n.ctorParameters=function(){return[]};var a=function(){function e(e,t,i,r){this.elementRef=e,this.sanitizer=t,this.cd=i,this.exifService=r,this.marginLeft="0px",this.imageVisible=!1,this.format="png",this.maintainAspectRatio=!0,this.aspectRatio=1,this.resizeToWidth=0,this.onlyScaleDown=!1,this.imageQuality=92,this.cropper={x1:-100,y1:-100,x2:1e4,y2:1e4},this.imageCropped=new o.EventEmitter,this.imageLoaded=new o.EventEmitter,this.loadImageFailed=new o.EventEmitter,this.initCropper()}return Object.defineProperty(e.prototype,"imageChangedEvent",{set:function(e){this.initCropper(),e&&e.target&&e.target.files&&0<e.target.files.length&&this.loadImage(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"imageBase64",{set:function(e){this.initCropper(),this.loadBase64Image(e)},enumerable:!0,configurable:!0}),e.prototype.ngOnChanges=function(e){var t=this;e.cropper&&setTimeout(function(){t.setMaxSize(),t.checkCropperPosition(!1),t.crop(),t.cd.markForCheck()})},e.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},e.prototype.loadImage=function(e){var i=this,r=e.target.files[0];if(!1!==/(jpe?g|png|gif)/i.test(r.type)){var t=new FileReader;t.onloadend=function(e){var t=e.target.result;i.exifService.getOrientedImage(t,r.type).subscribe(function(e){i.loadBase64Image(e.src)},function(e){i.loadImageFailed.emit()})},t.readAsArrayBuffer(r)}else this.loadImageFailed.emit()},e.prototype.loadBase64Image=function(e){var t=this;this.originalImage=new Image,this.originalImage.onload=function(){t.originalSize.width=t.originalImage.width,t.originalSize.height=t.originalImage.height,t.cd.markForCheck()},this.safeImgDataUrl=this.sanitizer.bypassSecurityTrustResourceUrl(e),this.originalImage.src=e},e.prototype.imageLoadedInView=function(){var e=this;null!=this.originalImage&&(this.imageLoaded.emit(),setTimeout(function(){e.setMaxSize(),e.resetCropperPosition(),e.cd.markForCheck()}))},e.prototype.imageResizedInView=function(e){this.resizeCropperPosition(),this.setMaxSize()},e.prototype.resizeCropperPosition=function(){var e=this.elementRef.nativeElement.querySelector(".source-image");this.maxSize.width===e.offsetWidth&&this.maxSize.height===e.offsetHeight||(this.cropper.x1=this.cropper.x1*e.offsetWidth/this.maxSize.width,this.cropper.x2=this.cropper.x2*e.offsetWidth/this.maxSize.width,this.cropper.y1=this.cropper.y1*e.offsetHeight/this.maxSize.height,this.cropper.y2=this.cropper.y2*e.offsetHeight/this.maxSize.height)},e.prototype.resetCropperPosition=function(){var e=this.elementRef.nativeElement.querySelector(".source-image");if(e.offsetWidth/this.aspectRatio<e.offsetHeight){this.cropper.x1=0,this.cropper.x2=e.offsetWidth;var t=e.offsetWidth/this.aspectRatio;this.cropper.y1=(e.offsetHeight-t)/2,this.cropper.y2=this.cropper.y1+t}else{this.cropper.y1=0,this.cropper.y2=e.offsetHeight;var i=e.offsetHeight*this.aspectRatio;this.cropper.x1=(e.offsetWidth-i)/2,this.cropper.x2=this.cropper.x1+i}this.crop(),this.imageVisible=!0},e.prototype.startMove=function(e,t,i){void 0===i&&(i=null),this.moveStart.active=!0,this.moveStart.type=t,this.moveStart.position=i,this.moveStart.clientX=this.getClientX(e),this.moveStart.clientY=this.getClientY(e),Object.assign(this.moveStart,this.cropper),this.cd.markForCheck()},e.prototype.moveImg=function(e){this.moveStart.active&&(e.stopPropagation(),e.preventDefault(),this.setMaxSize(),"move"===this.moveStart.type?(this.move(e),this.checkCropperPosition(!0)):"resize"===this.moveStart.type&&(this.resize(e),this.checkCropperPosition(!1)),this.cd.markForCheck())},e.prototype.setMaxSize=function(){var e=this.elementRef.nativeElement.querySelector(".source-image");this.maxSize.width=e.offsetWidth,this.maxSize.height=e.offsetHeight,this.marginLeft=this.sanitizer.bypassSecurityTrustStyle("calc(50% - "+this.maxSize.width/2+"px)")},e.prototype.checkCropperPosition=function(e){void 0===e&&(e=!1),this.cropper.x1<0&&(this.cropper.x2-=e?this.cropper.x1:0,this.cropper.x1=0),this.cropper.y1<0&&(this.cropper.y2-=e?this.cropper.y1:0,this.cropper.y1=0),this.cropper.x2>this.maxSize.width&&(this.cropper.x1-=e?this.cropper.x2-this.maxSize.width:0,this.cropper.x2=this.maxSize.width),this.cropper.y2>this.maxSize.height&&(this.cropper.y1-=e?this.cropper.y2-this.maxSize.height:0,this.cropper.y2=this.maxSize.height)},e.prototype.moveStop=function(e){this.moveStart.active&&(this.moveStart.active=!1,this.crop(),this.cd.markForCheck())},e.prototype.move=function(e){var t=this.getClientX(e)-this.moveStart.clientX,i=this.getClientY(e)-this.moveStart.clientY;this.cropper.x1=this.moveStart.x1+t,this.cropper.y1=this.moveStart.y1+i,this.cropper.x2=this.moveStart.x2+t,this.cropper.y2=this.moveStart.y2+i},e.prototype.resize=function(e){var t=this.getClientX(e)-this.moveStart.clientX,i=this.getClientY(e)-this.moveStart.clientY;switch(this.moveStart.position){case"left":this.cropper.x1=Math.min(this.moveStart.x1+t,this.cropper.x2-20);break;case"topleft":this.cropper.x1=Math.min(this.moveStart.x1+t,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+t,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+t,this.cropper.x1+20);break;case"bottomright":this.cropper.x2=Math.max(this.moveStart.x2+t,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+t,this.cropper.x2-20),this.cropper.y2=Math.max(this.moveStart.y2+i,this.cropper.y1+20)}this.maintainAspectRatio&&this.checkAspectRatio()},e.prototype.checkAspectRatio=function(){var e=0,t=0;switch(this.moveStart.position){case"top":this.cropper.x2=this.cropper.x1+(this.cropper.y2-this.cropper.y1)*this.aspectRatio,e=Math.max(this.cropper.x2-this.maxSize.width,0),t=Math.max(0-this.cropper.y1,0),(0<e||0<t)&&(this.cropper.x2-=t*this.aspectRatio>e?t*this.aspectRatio:e,this.cropper.y1+=t*this.aspectRatio>e?t:e/this.aspectRatio);break;case"bottom":this.cropper.x2=this.cropper.x1+(this.cropper.y2-this.cropper.y1)*this.aspectRatio,e=Math.max(this.cropper.x2-this.maxSize.width,0),t=Math.max(this.cropper.y2-this.maxSize.height,0),(0<e||0<t)&&(this.cropper.x2-=t*this.aspectRatio>e?t*this.aspectRatio:e,this.cropper.y2-=t*this.aspectRatio>e?t:e/this.aspectRatio);break;case"topleft":this.cropper.y1=this.cropper.y2-(this.cropper.x2-this.cropper.x1)/this.aspectRatio,e=Math.max(0-this.cropper.x1,0),t=Math.max(0-this.cropper.y1,0),(0<e||0<t)&&(this.cropper.x1+=t*this.aspectRatio>e?t*this.aspectRatio:e,this.cropper.y1+=t*this.aspectRatio>e?t:e/this.aspectRatio);break;case"topright":this.cropper.y1=this.cropper.y2-(this.cropper.x2-this.cropper.x1)/this.aspectRatio,e=Math.max(this.cropper.x2-this.maxSize.width,0),t=Math.max(0-this.cropper.y1,0),(0<e||0<t)&&(this.cropper.x2-=t*this.aspectRatio>e?t*this.aspectRatio:e,this.cropper.y1+=t*this.aspectRatio>e?t:e/this.aspectRatio);break;case"right":case"bottomright":this.cropper.y2=this.cropper.y1+(this.cropper.x2-this.cropper.x1)/this.aspectRatio,e=Math.max(this.cropper.x2-this.maxSize.width,0),t=Math.max(this.cropper.y2-this.maxSize.height,0),(0<e||0<t)&&(this.cropper.x2-=t*this.aspectRatio>e?t*this.aspectRatio:e,this.cropper.y2-=t*this.aspectRatio>e?t:e/this.aspectRatio);break;case"left":case"bottomleft":this.cropper.y2=this.cropper.y1+(this.cropper.x2-this.cropper.x1)/this.aspectRatio,e=Math.max(0-this.cropper.x1,0),t=Math.max(this.cropper.y2-this.maxSize.height,0),(0<e||0<t)&&(this.cropper.x1+=t*this.aspectRatio>e?t*this.aspectRatio:e,this.cropper.y2-=t*this.aspectRatio>e?t:e/this.aspectRatio)}},e.prototype.crop=function(){var e=this.elementRef.nativeElement.querySelector(".source-image");if(e&&null!=this.originalImage){var t=this.calculateRatio(this.originalImage,e),i=Math.round(this.cropper.x1*t),r=Math.round(this.cropper.y1*t),o=Math.round((this.cropper.x2-this.cropper.x1)*t),n=Math.round((this.cropper.y2-this.cropper.y1)*t),a=this.getResizeRatio(o),s=o*a,p=n*a,h=document.createElement("canvas");h.width=s,h.height=p;var c=h.getContext("2d");if(c){c.drawImage(this.originalImage,i,r,o,n,0,0,s,p);var l=Math.min(1,Math.max(0,this.imageQuality/100)),g=h.toDataURL("image/"+this.format,l);10<g.length&&this.imageCropped.emit(g)}}},e.prototype.getResizeRatio=function(e){return 0<this.resizeToWidth&&(!this.onlyScaleDown||e>this.resizeToWidth)?this.resizeToWidth/e:1},e.prototype.getClientX=function(e){return null!=e.clientX?e.clientX:e.touches[0].clientX},e.prototype.getClientY=function(e){return null!=e.clientY?e.clientY:e.touches[0].clientY},e.prototype.calculateRatio=function(e,t){return e.width/t.offsetWidth},e}();a.decorators=[{type:o.Component,args:[{selector:"image-cropper",template:'\n <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 [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:["\n :host {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n position: relative;\n width: 100%;\n max-width: 100%;\n max-height: 100%;\n overflow: hidden;\n padding: 5px;\n text-align: center;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none; }\n :host > div {\n position: relative;\n width: 100%; }\n :host > div .source-image {\n max-width: 100%;\n max-height: 100%; }\n :host .cropper {\n position: absolute;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n color: #53535C !important;\n background: transparent !important;\n outline-color: rgba(255, 255, 255, 0.3);\n outline-width: 1000px;\n outline-style: solid;\n -ms-touch-action: none;\n touch-action: none; }\n :host .cropper:after {\n position: absolute;\n content: '';\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n pointer-events: none;\n border: dashed 1px;\n opacity: .75;\n color: inherit;\n z-index: 1; }\n :host .cropper .move {\n width: 100%;\n cursor: move;\n border: 1px solid rgba(255, 255, 255, 0.5); }\n :host .cropper .resize {\n position: absolute;\n display: inline-block;\n line-height: 6px;\n padding: 8px;\n opacity: .85;\n z-index: 1; }\n :host .cropper .resize .square {\n display: inline-block;\n background: #53535C !important;\n width: 6px;\n height: 6px;\n border: 1px solid rgba(255, 255, 255, 0.5); }\n :host .cropper .resize.topleft {\n top: -12px;\n left: -12px;\n cursor: nw-resize; }\n :host .cropper .resize.top {\n top: -12px;\n left: calc(50% - 12px);\n cursor: n-resize; }\n :host .cropper .resize.topright {\n top: -12px;\n right: -12px;\n cursor: ne-resize; }\n :host .cropper .resize.right {\n top: calc(50% - 12px);\n right: -12px;\n cursor: e-resize; }\n :host .cropper .resize.bottomright {\n bottom: -12px;\n right: -12px;\n cursor: se-resize; }\n :host .cropper .resize.bottom {\n bottom: -12px;\n left: calc(50% - 12px);\n cursor: s-resize; }\n :host .cropper .resize.bottomleft {\n bottom: -12px;\n left: -12px;\n cursor: sw-resize; }\n :host .cropper .resize.left {\n top: calc(50% - 12px);\n left: -12px;\n cursor: w-resize; }\n :host .cropper .resize-bar {\n position: absolute;\n z-index: 1; }\n :host .cropper .resize-bar.top {\n top: -11px;\n left: 11px;\n width: calc(100% - 22px);\n height: 22px;\n cursor: n-resize; }\n :host .cropper .resize-bar.right {\n top: 11px;\n right: -11px;\n height: calc(100% - 22px);\n width: 22px;\n cursor: e-resize; }\n :host .cropper .resize-bar.bottom {\n bottom: -11px;\n left: 11px;\n width: calc(100% - 22px);\n height: 22px;\n cursor: s-resize; }\n :host .cropper .resize-bar.left {\n top: 11px;\n left: -11px;\n height: calc(100% - 22px);\n width: 22px;\n cursor: w-resize; }\n "],changeDetection:o.ChangeDetectionStrategy.OnPush}]}],a.ctorParameters=function(){return[{type:o.ElementRef},{type:r.DomSanitizer},{type:o.ChangeDetectorRef},{type:n}]},a.propDecorators={imageChangedEvent:[{type:o.Input}],imageBase64:[{type:o.Input}],format:[{type:o.Input}],maintainAspectRatio:[{type:o.Input}],aspectRatio:[{type:o.Input}],resizeToWidth:[{type:o.Input}],onlyScaleDown:[{type:o.Input}],imageQuality:[{type:o.Input}],cropper:[{type:o.Input}],imageCropped:[{type:o.Output}],imageLoaded:[{type:o.Output}],loadImageFailed:[{type:o.Output}],imageResizedInView:[{type:o.HostListener,args:["window:resize",["$event"]]}],moveImg:[{type:o.HostListener,args:["document:mousemove",["$event"]]},{type:o.HostListener,args:["document:touchmove",["$event"]]}],moveStop:[{type:o.HostListener,args:["document:mouseup",["$event"]]},{type:o.HostListener,args:["document:touchend",["$event"]]}]};var s=function(){};s.decorators=[{type:o.NgModule,args:[{imports:[i.CommonModule],declarations:[a],exports:[a],providers:[h,n]}]}],s.ctorParameters=function(){return[]},e.ExifService=h,e.ImageCropperModule=s,e.ImageCropperComponent=a,e.ImageCropperExifService=n,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=ngx-image-cropper-facet.umd.min.js.map