{"version":3,"sources":["../../src/app/components/password/password.ts"],"names":["Password","el","zone","this","promptLabel","weakLabel","mediumLabel","strongLabel","feedback","Object","defineProperty","prototype","show","nativeElement","type","ngDoCheck","updateFilledState","onInput","e","filled","value","length","createPanel","panel","document","createElement","className","meter","info","textContent","appendChild","style","minWidth","DomHandler","getOuterWidth","body","showOverlay","_this","zIndex","String","zindex","display","runOutsideAngular","setTimeout","addClass","bindScrollListener","bindDocumentResizeListener","absolutePosition","hideOverlay","removeClass","unbindScrollListener","unbindDocumentResizeListener","ngOnDestroy","onFocus","onBlur","onKeyup","target","label","meterPos","score","testStrength","hasClass","backgroundPosition","str","val","grade","match","normalize","x","y","disabled","scrollHandler","ConnectedOverlayScrollHandler","documentResizeListener","onWindowResize","bind","window","addEventListener","removeEventListener","destroy","removeChild","Directive","args","selector","host","[class.p-inputtext]","[class.p-component]","[class.p-filled]","ElementRef","NgZone","Input","HostListener","NgModule","imports","CommonModule","exports","declarations"],"mappings":"2dAwCI,SAAAA,EAAmBC,EAAuBC,GAAvBC,KAAAF,GAAAA,EAAuBE,KAAAD,KAAAA,EA1BjCC,KAAAC,YAAsB,mBAEtBD,KAAAE,UAAoB,OAEpBF,KAAAG,YAAsB,SAEtBH,KAAAI,YAAsB,SAEtBJ,KAAAK,UAAoB,SAE7BC,OAAAC,eAAaV,EAAAW,UAAA,eAAY,KAAzB,SAA0BC,GACtBT,KAAKF,GAAGY,cAAcC,KAAOF,EAAO,OAAS,4CAiBjDZ,EAAAW,UAAAI,UAAA,WACIZ,KAAKa,qBAIThB,EAAAW,UAAAM,QAAA,SAAQC,GACJf,KAAKa,qBAGThB,EAAAW,UAAAK,kBAAA,WACIb,KAAKgB,OAAShB,KAAKF,GAAGY,cAAcO,OAASjB,KAAKF,GAAGY,cAAcO,MAAMC,QAG7ErB,EAAAW,UAAAW,YAAA,WACInB,KAAKoB,MAAQC,SAASC,cAAc,OACpCtB,KAAKoB,MAAMG,UAAY,4EACvBvB,KAAKwB,MAAQH,S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C,QAAS,CAAC/F,GACVgG,aAAc,CAAChG","sourcesContent":["import {NgModule,Directive,ElementRef,HostListener,Input,OnDestroy,DoCheck,NgZone} from '@angular/core';\nimport {CommonModule} from '@angular/common';\nimport {DomHandler, ConnectedOverlayScrollHandler} from 'primeng/dom';\n\n@Directive({\n selector: '[pPassword]',\n host: {\n '[class.p-inputtext]': 'true',\n '[class.p-component]': 'true',\n '[class.p-filled]': 'filled'\n }\n})\nexport class Password implements OnDestroy,DoCheck {\n\n @Input() promptLabel: string = 'Enter a password';\n\n @Input() weakLabel: string = 'Weak';\n\n @Input() mediumLabel: string = 'Medium';\n\n @Input() strongLabel: string = 'Strong';\n\n @Input() feedback: boolean = true;\n\n @Input() set showPassword(show: boolean) {\n this.el.nativeElement.type = show ? 'text' : 'password';\n }\n\n panel: HTMLDivElement;\n\n meter: any;\n\n info: any;\n\n filled: boolean;\n\n scrollHandler: any;\n\n documentResizeListener: any;\n\n constructor(public el: ElementRef, public zone: NgZone) {}\n\n ngDoCheck() {\n this.updateFilledState();\n }\n\n @HostListener('input', ['$event'])\n onInput(e) {\n this.updateFilledState();\n }\n\n updateFilledState() {\n this.filled = this.el.nativeElement.value && this.el.nativeElement.value.length;\n }\n\n createPanel() {\n this.panel = document.createElement('div');\n this.panel.className = 'p-password-panel p-component p-password-panel-overlay p-connected-overlay';\n this.meter = document.createElement('div');\n this.meter.className = 'p-password-meter';\n this.info = document.createElement('div');\n this.info.className = 'p-password-info';\n this.info.textContent = this.promptLabel;\n this.panel.appendChild(this.meter);\n this.panel.appendChild(this.info);\n this.panel.style.minWidth = DomHandler.getOuterWidth(this.el.nativeElement) + 'px';\n document.body.appendChild(this.panel);\n }\n\n showOverlay() {\n if (this.feedback) {\n if (!this.panel) {\n this.createPanel();\n }\n\n this.panel.style.zIndex = String(++DomHandler.zindex);\n this.panel.style.display = 'block';\n this.zone.runOutsideAngular(() => {\n\n setTimeout(() => {\n DomHandler.addClass(this.panel, 'p-connected-overlay-visible');\n this.bindScrollListener();\n this.bindDocumentResizeListener();\n }, 1);\n });\n DomHandler.absolutePosition(this.panel, this.el.nativeElement);\n }\n }\n\n hideOverlay() {\n if (this.feedback && this.panel) {\n DomHandler.addClass(this.panel, 'p-connected-overlay-hidden');\n DomHandler.removeClass(this.panel, 'p-connected-overlay-visible');\n this.unbindScrollListener();\n this.unbindDocumentResizeListener();\n\n this.zone.runOutsideAngular(() => {\n setTimeout(() => {\n this.ngOnDestroy();\n }, 150);\n });\n }\n }\n\n @HostListener('focus')\n onFocus() {\n this.showOverlay();\n }\n\n @HostListener('blur')\n onBlur() {\n this.hideOverlay();\n }\n\n @HostListener('keyup', ['$event'])\n onKeyup(e) {\n if (this.feedback) {\n let value = e.target.value,\n label = null,\n meterPos = null;\n\n if (value.length === 0) {\n label = this.promptLabel;\n meterPos = '0px 0px';\n }\n else {\n var score = this.testStrength(value);\n\n if (score < 30) {\n label = this.weakLabel;\n meterPos = '0px -10px';\n }\n else if (score >= 30 && score < 80) {\n label = this.mediumLabel;\n meterPos = '0px -20px';\n }\n else if (score >= 80) {\n label = this.strongLabel;\n meterPos = '0px -30px';\n }\n }\n\n if (!this.panel || !DomHandler.hasClass(this.panel, 'p-connected-overlay-visible')) {\n this.showOverlay();\n }\n\n this.meter.style.backgroundPosition = meterPos;\n this.info.textContent = label;\n }\n }\n\n testStrength(str: string) {\n let grade: number = 0;\n let val: RegExpMatchArray;\n\n val = str.match('[0-9]');\n grade += this.normalize(val ? val.length : 1/4, 1) * 25;\n\n val = str.match('[a-zA-Z]');\n grade += this.normalize(val ? val.length : 1/2, 3) * 10;\n\n val = str.match('[!@#$%^&*?_~.,;=]');\n grade += this.normalize(val ? val.length : 1/6, 1) * 35;\n\n val = str.match('[A-Z]');\n grade += this.normalize(val ? val.length : 1/6, 1) * 30;\n\n grade *= str.length / 8;\n\n return grade > 100 ? 100 : grade;\n }\n\n normalize(x, y) {\n let diff = x - y;\n\n if (diff <= 0)\n return x / y;\n else\n return 1 + 0.5 * (x / (x + y/4));\n }\n\n get disabled(): boolean {\n return this.el.nativeElement.disabled;\n }\n\n bindScrollListener() {\n if (!this.scrollHandler) {\n this.scrollHandler = new ConnectedOverlayScrollHandler(this.el.nativeElement, () => {\n if (DomHandler.hasClass(this.panel, 'p-connected-overlay-visible')) {\n this.hideOverlay();\n }\n });\n }\n\n this.scrollHandler.bindScrollListener();\n }\n\n unbindScrollListener() {\n if (this.scrollHandler) {\n this.scrollHandler.unbindScrollListener();\n }\n }\n\n bindDocumentResizeListener() {\n this.documentResizeListener = this.onWindowResize.bind(this);\n window.addEventListener('resize', this.documentResizeListener);\n }\n\n unbindDocumentResizeListener() {\n if (this.documentResizeListener) {\n window.removeEventListener('resize', this.documentResizeListener);\n this.documentResizeListener = null;\n }\n }\n\n onWindowResize() {\n this.hideOverlay();\n }\n\n ngOnDestroy() {\n if (this.panel) {\n if (this.scrollHandler) {\n this.scrollHandler.destroy();\n this.scrollHandler = null;\n }\n\n this.unbindDocumentResizeListener();\n\n document.body.removeChild(this.panel);\n this.panel = null;\n this.meter = null;\n this.info = null;\n }\n }\n}\n\n@NgModule({\n imports: [CommonModule],\n exports: [Password],\n declarations: [Password]\n})\nexport class PasswordModule { }\n"]}