primeng
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primeng) [{"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common"),require("primeng/dom"),require("primeng/inputtext"),require("@angular/forms")):"function"==typeof define&&define.amd?define("primeng/inputmask",["exports","@angular/core","@angular/common","primeng/dom","primeng/inputtext","@angular/forms"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).primeng=t.primeng||{},t.primeng.inputmask={}),t.ng.core,t.ng.common,t.primeng.dom,t.primeng.inputtext,t.ng.forms)}(this,(function(t,e,i,n,s,o){"use strict";var a={provide:o.NG_VALUE_ACCESSOR,useExisting:e.forwardRef((function(){return r})),multi:!0},r=function(){function t(t,i){this.el=t,this.cd=i,this.type="text",this.slotChar="_",this.autoClear=!0,this.characterPattern="[A-Za-z]",this.onComplete=new e.EventEmitter,this.onFocus=new e.EventEmitter,this.onBlur=new e.EventEmitter,this.onInput=new e.EventEmitter,this.onKeydown=new e.EventEmitter,this.onModelChange=function(){},this.onModelTouched=function(){}}return t.prototype.ngOnInit=function(){var t=n.DomHandler.getUserAgent();this.androidChrome=/chrome/i.test(t)&&/android/i.test(t),this.initMask()},Object.defineProperty(t.prototype,"mask",{get:function(){return this._mask},set:function(t){this._mask=t,this.initMask(),this.writeValue(""),this.onModelChange(this.value)},enumerable:!1,configurable:!0}),t.prototype.initMask=function(){this.tests=[],this.partialPosition=this.mask.length,this.len=this.mask.length,this.firstNonMaskPos=null,this.defs={9:"[0-9]",a:this.characterPattern,"*":this.characterPattern+"|[0-9]"};for(var t=this.mask.split(""),e=0;e<t.length;e++){"?"==(i=t[e])?(this.len--,this.partialPosition=e):this.defs[i]?(this.tests.push(new RegExp(this.defs[i])),null===this.firstNonMaskPos&&(this.firstNonMaskPos=this.tests.length-1),e<this.partialPosition&&(this.lastRequiredNonMaskPos=this.tests.length-1)):this.tests.push(null)}this.buffer=[];for(e=0;e<t.length;e++){var i;"?"!=(i=t[e])&&(this.defs[i]?this.buffer.push(this.getPlaceholder(e)):this.buffer.push(i))}this.defaultBuffer=this.buffer.join("")},t.prototype.writeValue=function(t){this.value=t,this.inputViewChild&&this.inputViewChild.nativeElement&&(null==this.value||null==this.value?this.inputViewChild.nativeElement.value="":this.inputViewChild.nativeElement.value=this.value,this.checkVal(),this.focusText=this.inputViewChild.nativeElement.value,this.updateFilledState())},t.prototype.registerOnChange=function(t){this.onModelChange=t},t.prototype.registerOnTouched=function(t){this.onModelTouched=t},t.prototype.setDisabledState=function(t){this.disabled=t,this.cd.markForCheck()},t.prototype.caret=function(t,e){var i,n,s;if(this.inputViewChild.nativeElement.offsetParent&&this.inputViewChild.nativeElement===this.inputViewChild.nativeElement.ownerDocument.activeElement)return"number"!=typeof t?(this.inputViewChild.nativeElement.setSelectionRange?(n=this.inputViewChild.nativeElement.selectionStart,s=this.inputViewChild.nativeElement.selectionEnd):document.selection&&document.selection.createRange&&(s=(n=0-(i=document.selection.createRange()).duplicate().moveStart("character",-1e5))+i.text.length),{begin:n,end:s}):(n=t,s="number"==typeof e?e:n,void(this.inputViewChild.nativeElement.setSelectionRange?this.inputViewChild.nativeElement.setSelectionRange(n,s):this.inputViewChild.nativeElement.createTextRange&&((i=this.inputViewChild.nativeElement.createTextRange()).collapse(!0),i.moveEnd("character",s),i.moveStart("character",n),i.select())))},t.prototype.isCompleted=function(){for(var t=this.firstNonMaskPos;t<=this.lastRequiredNonMaskPos;t++)if(this.tests[t]&&this.buffer[t]===this.getPlaceholder(t))return!1;return!0},t.prototype.getPlaceholder=function(t){return t<this.slotChar.length?this.slotChar.charAt(t):this.slotChar.charAt(0)},t.prototype.seekNext=function(t){for(;++t<this.len&&!this.tests[t];);return t},t.prototype.seekPrev=function(t){for(;--t>=0&&!this.tests[t];);return t},t.prototype.shiftL=function(t,e){var i,n;if(!(t<0)){for(i=t,n=this.seekNext(e);i<this.len;i++)if(this.tests[i]){if(!(n<this.len&&this.tests[i].test(this.buffer[n])))break;this.buffer[i]=this.buffer[n],this.buffer[n]=this.getPlaceholder(n),n=this.seekNext(n)}this.writeBuffer(),this.caret(Math.max(this.firstNonMaskPos,t))}},t.prototype.shiftR=function(t){var e,i,n,s;for(e=t,i=this.getPlaceholder(t);e<this.len;e++)if(this.tests[e]){if(n=this.seekNext(e),s=this.buffer[e],this.buffer[e]=i,!(n<this.len&&this.tests[n].test(s)))break;i=s}},t.prototype.handleAndroidInput=function(t){var e=this,i=this.inputViewChild.nativeElement.value,n=this.caret();if(this.oldVal&&this.oldVal.length&&this.oldVal.length>i.length){for(this.checkVal(!0);n.begin>0&&!this.tests[n.begin-1];)n.begin--;if(0===n.begin)for(;n.begin<this.firstNonMaskPos&&!this.tests[n.begin];)n.begin++;setTimeout((function(){e.caret(n.begin,n.begin),e.updateModel(t),e.isCompleted()&&e.onComplete.emit()}),0)}else{for(this.checkVal(!0);n.begin<this.len&&!this.tests[n.begin];)n.begin++;setTimeout((function(){e.caret(n.begin,n.begin),e.updateModel(t),e.isCompleted()&&e.onComplete.emit()}),0)}},t.prototype.onInputBlur=function(t){if(this.focused=!1,this.onModelTouched(),this.checkVal(),this.updateFilledState(),this.onBlur.emit(t),this.inputViewChild.nativeElement.value!=this.focusText||this.inputViewChild.nativeElement.value!=this.value){this.updateModel(t);var e=document.createEvent("HTMLEvents");e.initEvent("change",!0,!1),this.inputViewChild.nativeElement.dispatchEvent(e)}},t.prototype.onInputKeydown=function(t){if(!this.readonly){var e,i,s,o=t.which||t.keyCode,a=/iphone/i.test(n.DomHandler.getUserAgent());this.oldVal=this.inputViewChild.nativeElement.value,this.onKeydown.emit(t),8===o||46===o||a&&127===o?(i=(e=this.caret()).begin,(s=e.end)-i==0&&(i=46!==o?this.seekPrev(i):s=this.seekNext(i-1),s=46===o?this.seekNext(s):s),this.clearBuffer(i,s),this.shiftL(i,s-1),this.updateModel(t),this.onInput.emit(t),t.preventDefault()):13===o?(this.onInputBlur(t),this.updateModel(t)):27===o&&(this.inputViewChild.nativeElement.value=this.focusText,this.caret(0,this.checkVal()),this.updateModel(t),t.preventDefault())}},t.prototype.onKeyPress=function(t){var e=this;if(!this.readonly){var i,s,o,a,r=t.which||t.keyCode,h=this.caret();if(!(t.ctrlKey||t.altKey||t.metaKey||r<32||r>34&&r<41)){if(r&&13!==r){if(h.end-h.begin!=0&&(this.clearBuffer(h.begin,h.end),this.shiftL(h.begin,h.end-1)),(i=this.seekNext(h.begin-1))<this.len&&(s=String.fromCharCode(r),this.tests[i].test(s))){if(this.shiftR(i),this.buffer[i]=s,this.writeBuffer(),o=this.seekNext(i),/android/i.test(n.DomHandler.getUserAgent())){setTimeout((function(){e.caret(o)}),0)}else this.caret(o);h.begin<=this.lastRequiredNonMaskPos&&(a=this.isCompleted()),this.onInput.emit(t)}t.preventDefault()}this.updateModel(t),this.updateFilledState(),a&&this.onComplete.emit()}}},t.prototype.clearBuffer=function(t,e){var i;for(i=t;i<e&&i<this.len;i++)this.tests[i]&&(this.buffer[i]=this.getPlaceholder(i))},t.prototype.writeBuffer=function(){this.inputViewChild.nativeElement.value=this.buffer.join("")},t.prototype.checkVal=function(t){var e,i,n,s=this.inputViewChild.nativeElement.value,o=-1;for(e=0,n=0;e<this.len;e++)if(this.tests[e]){for(this.buffer[e]=this.getPlaceholder(e);n++<s.length;)if(i=s.charAt(n-1),this.tests[e].test(i)){this.buffer[e]=i,o=e;break}if(n>s.length){this.clearBuffer(e+1,this.len);break}}else this.buffer[e]===s.charAt(n)&&n++,e<this.partialPosition&&(o=e);return t?this.writeBuffer():o+1<this.partialPosition?this.autoClear||this.buffer.join("")===this.defaultBuffer?(this.inputViewChild.nativeElement.value&&(this.inputViewChild.nativeElement.value=""),this.clearBuffer(0,this.len)):this.writeBuffer():(this.writeBuffer(),this.inputViewChild.nativeElement.value=this.inputViewChild.nativeElement.value.substring(0,o+1)),this.partialPosition?e:this.firstNonMaskPos},t.prototype.onInputFocus=function(t){var e,i=this;this.readonly||(this.focused=!0,clearTimeout(this.caretTimeoutId),this.focusText=this.inputViewChild.nativeElement.value,e=this.checkVal(),this.caretTimeoutId=setTimeout((function(){i.inputViewChild.nativeElement===i.inputViewChild.nativeElement.ownerDocument.activeElement&&(i.writeBuffer(),e==i.mask.replace("?","").length?i.caret(0,e):i.caret(e))}),10),this.onFocus.emit(t))},t.prototype.onInputChange=function(t){this.androidChrome?this.handleAndroidInput(t):this.handleInputChange(t),this.onInput.emit(t)},t.prototype.handleInputChange=function(t){var e=this;this.readonly||setTimeout((function(){var i=e.checkVal(!0);e.caret(i),e.updateModel(t),e.isCompleted()&&e.onComplete.emit()}),0)},t.prototype.getUnmaskedValue=function(){for(var t=[],e=0;e<this.buffer.length;e++){var i=this.buffer[e];this.tests[e]&&i!=this.getPlaceholder(e)&&t.push(i)}return t.join("")},t.prototype.updateModel=function(t){var e=this.unmask?this.getUnmaskedValue():t.target.value;null===e&&void 0===e||(this.value=e,this.onModelChange(this.value))},t.prototype.updateFilledState=function(){this.filled=this.inputViewChild.nativeElement&&""!=this.inputViewChild.nativeElement.value},t.prototype.focus=function(){this.inputViewChild.nativeElement.focus()},t.prototype.ngOnDestroy=function(){},t}();r.decorators=[{type:e.Component,args:[{selector:"p-inputMask",template:'<input #input pInputText class="p-inputmask" [attr.id]="inputId" [attr.type]="type" [attr.name]="name" [ngStyle]="style" [ngClass]="styleClass" [attr.placeholder]="placeholder" [attr.title]="title"\n [attr.size]="size" [attr.autocomplete]="autocomplete" [attr.maxlength]="maxlength" [attr.tabindex]="tabindex" [attr.aria-label]="ariaLabel" [attr.aria-required]="ariaRequired" [disabled]="disabled" [readonly]="readonly" [attr.required]="required"\n (focus)="onInputFocus($event)" (blur)="onInputBlur($event)" (keydown)="onInputKeydown($event)" (keypress)="onKeyPress($event)" [attr.autofocus]="autoFocus"\n (input)="onInputChange($event)" (paste)="handleInputChange($event)">',host:{"[class.p-inputwrapper-filled]":"filled","[class.p-inputwrapper-focus]":"focused"},providers:[a],changeDetection:e.ChangeDetectionStrategy.OnPush,encapsulation:e.ViewEncapsulation.None}]}],r.ctorParameters=function(){return[{type:e.ElementRef},{type:e.ChangeDetectorRef}]},r.propDecorators={type:[{type:e.Input}],slotChar:[{type:e.Input}],autoClear:[{type:e.Input}],style:[{type:e.Input}],inputId:[{type:e.Input}],styleClass:[{type:e.Input}],placeholder:[{type:e.Input}],size:[{type:e.Input}],maxlength:[{type:e.Input}],tabindex:[{type:e.Input}],title:[{type:e.Input}],ariaLabel:[{type:e.Input}],ariaRequired:[{type:e.Input}],disabled:[{type:e.Input}],readonly:[{type:e.Input}],unmask:[{type:e.Input}],name:[{type:e.Input}],required:[{type:e.Input}],characterPattern:[{type:e.Input}],autoFocus:[{type:e.Input}],autocomplete:[{type:e.Input}],inputViewChild:[{type:e.ViewChild,args:["input",{static:!0}]}],onComplete:[{type:e.Output}],onFocus:[{type:e.Output}],onBlur:[{type:e.Output}],onInput:[{type:e.Output}],onKeydown:[{type:e.Output}],mask:[{type:e.Input}]};var h=function(){};h.decorators=[{type:e.NgModule,args:[{imports:[i.CommonModule,s.InputTextModule],exports:[r],declarations:[r]}]}],t.INPUTMASK_VALUE_ACCESSOR=a,t.InputMask=r,t.InputMaskModule=h,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=primeng-inputmask.umd.min.js.map