UNPKG

ngx-qrcode2

Version:

An Angular component for generating QRCodes

2 lines 4.27 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("qrcode")):"function"==typeof define&&define.amd?define("ngx-qrcode2",["exports","@angular/core","qrcode"],t):t((e=e||self)["ngx-qrcode2"]={},e.ng.core,e.QRCode)}(this,(function(e,t,r){"use strict";r=r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r;var o,n;function i(e,t,r,o){var n,i=arguments.length,l=i<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,r,o);else for(var c=e.length-1;c>=0;c--)(n=e[c])&&(l=(i<3?n(l):i>3?n(t,r,l):n(t,r))||l);return i>3&&l&&Object.defineProperty(t,r,l),l}function l(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],o=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&o>=e.length&&(e=void 0),{value:e&&e[o++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(o=e.NgxQrcodeElementTypes||(e.NgxQrcodeElementTypes={})).URL="url",o.IMG="img",o.CANVAS="canvas",(n=e.NgxQrcodeErrorCorrectionLevels||(e.NgxQrcodeErrorCorrectionLevels={})).LOW="L",n.MEDIUM="M",n.QUARTILE="Q",n.HIGH="H";var c={elementType:e.NgxQrcodeElementTypes.URL,cssClass:"qrcode",value:"https://www.techiediaries.com",version:"",errorCorrectionLevel:e.NgxQrcodeErrorCorrectionLevels.MEDIUM,margin:4,scale:4,width:10,colorDark:"#000",colorLight:"#FFF"},s=function(){function o(e){this.renderer=e,this.elementType=c.elementType,this.cssClass=c.cssClass,this.value=c.value,this.version=c.version,this.errorCorrectionLevel=c.errorCorrectionLevel,this.margin=c.margin,this.scale=c.scale,this.width=c.width,this.colorDark=c.colorDark,this.colorLight=c.colorLight}return o.prototype.ngOnChanges=function(){this.createQRCode()},o.prototype.createQRCode=function(){var t,r=this;if(this.value)switch(this.elementType){case e.NgxQrcodeElementTypes.CANVAS:t=this.renderer.createElement("canvas"),this.toCanvas(t).then((function(){r.renderElement(t)})).catch((function(e){r.removeElementChildren(),console.error(e)}));break;default:t=this.renderer.createElement("img"),this.toDataURL().then((function(e){t.setAttribute("src",e),r.alt&&t.setAttribute("alt",r.alt),r.renderElement(t)})).catch((function(e){r.removeElementChildren(),console.error(e)}))}},o.prototype.toDataURL=function(){return r.toDataURL(this.value,{version:this.version,errorCorrectionLevel:this.errorCorrectionLevel,margin:this.margin,scale:this.scale,width:this.width,color:{dark:this.colorDark,light:this.colorLight}})},o.prototype.toCanvas=function(e){return r.toCanvas(e,this.value,{version:this.version,errorCorrectionLevel:this.errorCorrectionLevel,margin:this.margin,scale:this.scale,width:this.width,color:{dark:this.colorDark,light:this.colorLight}})},o.prototype.renderElement=function(e){this.removeElementChildren(),this.renderer.appendChild(this.qrcElement.nativeElement,e)},o.prototype.removeElementChildren=function(){var e,t;try{for(var r=l(this.qrcElement.nativeElement.childNodes),o=r.next();!o.done;o=r.next()){var n=o.value;this.renderer.removeChild(this.qrcElement.nativeElement,n)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}},o.ctorParameters=function(){return[{type:t.Renderer2}]},i([t.Input()],o.prototype,"elementType",void 0),i([t.Input()],o.prototype,"cssClass",void 0),i([t.Input()],o.prototype,"alt",void 0),i([t.Input()],o.prototype,"value",void 0),i([t.Input()],o.prototype,"version",void 0),i([t.Input()],o.prototype,"errorCorrectionLevel",void 0),i([t.Input()],o.prototype,"margin",void 0),i([t.Input()],o.prototype,"scale",void 0),i([t.Input()],o.prototype,"width",void 0),i([t.Input()],o.prototype,"colorDark",void 0),i([t.Input()],o.prototype,"colorLight",void 0),i([t.ViewChild("qrcElement")],o.prototype,"qrcElement",void 0),o=i([t.Component({selector:"ngx-qrcode",template:'\n <div #qrcElement [class]="cssClass"></div>',changeDetection:t.ChangeDetectionStrategy.OnPush})],o)}(),a=function(){function e(){}return e=i([t.NgModule({declarations:[s],exports:[s]})],e)}();e.NgxQRCodeModule=a,e.QrcodeComponent=s,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=ngx-qrcode2.umd.min.js.map