blob: 2d32e57c3acc6cba35ce5e61d077d1e29cb12ce2 [file] [log] [blame]
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/cdk/platform"),require("@angular/core"),require("@angular/cdk/coercion"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@angular/cdk/text-field",["exports","@angular/cdk/platform","@angular/core","@angular/cdk/coercion","rxjs","rxjs/operators"],t):t((e.ng=e.ng||{},e.ng.cdk=e.ng.cdk||{},e.ng.cdk.textField={}),e.ng.cdk.platform,e.ng.core,e.ng.cdk.coercion,e.rxjs,e.rxjs.operators)}(this,function(e,t,i,n,o,r){"use strict";var s=t.normalizePassiveListenerOptions({passive:!0}),a=function(){function e(e,t){this._platform=e,this._ngZone=t,this._monitoredElements=new Map}return e.prototype.monitor=function(e){var t=this;if(!this._platform.isBrowser)return o.EMPTY;var i=n.coerceElement(e),r=this._monitoredElements.get(i);if(r)return r.subject.asObservable();var a=new o.Subject,l="cdk-text-field-autofilled",c=function(e){"cdk-text-field-autofill-start"!==e.animationName||i.classList.contains(l)?"cdk-text-field-autofill-end"===e.animationName&&i.classList.contains(l)&&(i.classList.remove(l),t._ngZone.run(function(){return a.next({target:e.target,isAutofilled:!1})})):(i.classList.add(l),t._ngZone.run(function(){return a.next({target:e.target,isAutofilled:!0})}))};return this._ngZone.runOutsideAngular(function(){i.addEventListener("animationstart",c,s),i.classList.add("cdk-text-field-autofill-monitored")}),this._monitoredElements.set(i,{subject:a,unlisten:function(){i.removeEventListener("animationstart",c,s)}}),a.asObservable()},e.prototype.stopMonitoring=function(e){var t=n.coerceElement(e),i=this._monitoredElements.get(t);i&&(i.unlisten(),i.subject.complete(),t.classList.remove("cdk-text-field-autofill-monitored"),t.classList.remove("cdk-text-field-autofilled"),this._monitoredElements.delete(t))},e.prototype.ngOnDestroy=function(){var e=this;this._monitoredElements.forEach(function(t,i){return e.stopMonitoring(i)})},e.decorators=[{type:i.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[{type:t.Platform},{type:i.NgZone}]},e.ngInjectableDef=i.ɵɵdefineInjectable({factory:function(){return new e(i.ɵɵinject(t.Platform),i.ɵɵinject(i.NgZone))},token:e,providedIn:"root"}),e}(),l=function(){function e(e,t){this._elementRef=e,this._autofillMonitor=t,this.cdkAutofill=new i.EventEmitter}return e.prototype.ngOnInit=function(){var e=this;this._autofillMonitor.monitor(this._elementRef).subscribe(function(t){return e.cdkAutofill.emit(t)})},e.prototype.ngOnDestroy=function(){this._autofillMonitor.stopMonitoring(this._elementRef)},e.decorators=[{type:i.Directive,args:[{selector:"[cdkAutofill]"}]}],e.ctorParameters=function(){return[{type:i.ElementRef},{type:a}]},e.propDecorators={cdkAutofill:[{type:i.Output}]},e}(),c=function(){function e(e,t,i){this._elementRef=e,this._platform=t,this._ngZone=i,this._destroyed=new o.Subject,this._enabled=!0,this._previousMinRows=-1,this._textareaElement=this._elementRef.nativeElement}return Object.defineProperty(e.prototype,"minRows",{get:function(){return this._minRows},set:function(e){this._minRows=e,this._setMinHeight()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"maxRows",{get:function(){return this._maxRows},set:function(e){this._maxRows=e,this._setMaxHeight()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(e){e=n.coerceBooleanProperty(e),this._enabled!==e&&((this._enabled=e)?this.resizeToFitContent(!0):this.reset())},enumerable:!0,configurable:!0}),e.prototype._setMinHeight=function(){var e=this.minRows&&this._cachedLineHeight?this.minRows*this._cachedLineHeight+"px":null;e&&(this._textareaElement.style.minHeight=e)},e.prototype._setMaxHeight=function(){var e=this.maxRows&&this._cachedLineHeight?this.maxRows*this._cachedLineHeight+"px":null;e&&(this._textareaElement.style.maxHeight=e)},e.prototype.ngAfterViewInit=function(){var e=this;this._platform.isBrowser&&(this._initialHeight=this._textareaElement.style.height,this.resizeToFitContent(),this._ngZone.runOutsideAngular(function(){o.fromEvent(window,"resize").pipe(r.auditTime(16),r.takeUntil(e._destroyed)).subscribe(function(){return e.resizeToFitContent(!0)})}))},e.prototype.ngOnDestroy=function(){this._destroyed.next(),this._destroyed.complete()},e.prototype._cacheTextareaLineHeight=function(){if(!this._cachedLineHeight){var e=this._textareaElement.cloneNode(!1);e.rows=1,e.style.position="absolute",e.style.visibility="hidden",e.style.border="none",e.style.padding="0",e.style.height="",e.style.minHeight="",e.style.maxHeight="",e.style.overflow="hidden",this._textareaElement.parentNode.appendChild(e),this._cachedLineHeight=e.clientHeight,this._textareaElement.parentNode.removeChild(e),this._setMinHeight(),this._setMaxHeight()}},e.prototype.ngDoCheck=function(){this._platform.isBrowser&&this.resizeToFitContent()},e.prototype.resizeToFitContent=function(e){var t=this;if(void 0===e&&(e=!1),this._enabled&&(this._cacheTextareaLineHeight(),this._cachedLineHeight)){var i=this._elementRef.nativeElement,n=i.value;if(e||this._minRows!==this._previousMinRows||n!==this._previousValue){var o=i.placeholder;i.classList.add("cdk-textarea-autosize-measuring"),i.placeholder="";var r=i.scrollHeight-4;i.style.height=r+"px",i.classList.remove("cdk-textarea-autosize-measuring"),i.placeholder=o,this._ngZone.runOutsideAngular(function(){"undefined"!=typeof requestAnimationFrame?requestAnimationFrame(function(){return t._scrollToCaretPosition(i)}):setTimeout(function(){return t._scrollToCaretPosition(i)})}),this._previousValue=n,this._previousMinRows=this._minRows}}},e.prototype.reset=function(){void 0!==this._initialHeight&&(this._textareaElement.style.height=this._initialHeight)},e.prototype._noopInputHandler=function(){},e.prototype._scrollToCaretPosition=function(e){var t=e.selectionStart,i=e.selectionEnd;this._destroyed.isStopped||document.activeElement!==e||e.setSelectionRange(t,i)},e.decorators=[{type:i.Directive,args:[{selector:"textarea[cdkTextareaAutosize]",exportAs:"cdkTextareaAutosize",host:{class:"cdk-textarea-autosize",rows:"1","(input)":"_noopInputHandler()"}}]}],e.ctorParameters=function(){return[{type:i.ElementRef},{type:t.Platform},{type:i.NgZone}]},e.propDecorators={minRows:[{type:i.Input,args:["cdkAutosizeMinRows"]}],maxRows:[{type:i.Input,args:["cdkAutosizeMaxRows"]}],enabled:[{type:i.Input,args:["cdkTextareaAutosize"]}]},e}(),u=function(){function e(){}return e.decorators=[{type:i.NgModule,args:[{declarations:[l,c],imports:[t.PlatformModule],exports:[l,c]}]}],e}();e.AutofillMonitor=a,e.CdkAutofill=l,e.CdkTextareaAutosize=c,e.TextFieldModule=u,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=cdk-text-field.umd.min.js.map