import{Ic as p,La as w,Ma as m,Qb as A,Ta as x,Wa as c,xa as h}from"./chunk-O7RN3KYY.js";import{a as f}from"./chunk-ZE2KCNEA.js";f();var R=3,S=(()=>{class n{set minRows(t){this._minRows=t,this.textAreaEl&&(this.textAreaEl.rows=t)}onInput(t){t&&this.adjust()}constructor(){this.element=h(c),this._zone=h(m),this.onlyGrow=!1,this.useImportant=!1,this.resized=new w,this.retries=0,this._destroyed=!1,this.element.nativeElement.tagName!=="TEXTAREA"?this._findNestedTextArea():(this.textAreaEl=this.element.nativeElement,this.textAreaEl.style.overflow="hidden",this._onTextAreaFound())}ngOnDestroy(){this._destroyed=!0,this._windowResizeHandler&&window.removeEventListener("resize",this._windowResizeHandler,!1)}ngAfterContentChecked(){this.adjust()}ngOnChanges(t){this.adjust(!0)}_findNestedTextArea(){if(this.textAreaEl=this.element.nativeElement.querySelector("TEXTAREA"),!this.textAreaEl&&this.element.nativeElement.shadowRoot&&(this.textAreaEl=this.element.nativeElement.shadowRoot.querySelector("TEXTAREA")),!this.textAreaEl){this.retries>=R?console.warn("ngx-autosize: textarea not found"):(this.retries++,setTimeout(()=>{this._findNestedTextArea()},100));return}this.textAreaEl.style.overflow="hidden",this._onTextAreaFound()}_onTextAreaFound(){this._addWindowResizeHandler(),requestAnimationFrame(()=>{this.adjust()})}_addWindowResizeHandler(){this._windowResizeHandler=v(()=>{this._zone.run(()=>{this.adjust()})},200),this._zone.runOutsideAngular(()=>{window.addEventListener("resize",this._windowResizeHandler,!1)})}adjust(t=!1){if(!this._destroyed&&this.textAreaEl){let e=this.textAreaEl.value;if(t===!1&&e===this._oldContent&&this.textAreaEl.offsetWidth===this._oldWidth)return;this._oldContent=e,this._oldWidth=this.textAreaEl.offsetWidth;let i=this.textAreaEl.cloneNode(!0),o=this.textAreaEl.parentNode;i.style.width=this.textAreaEl.offsetWidth+"px",i.style.visibility="hidden",i.style.position="fixed",i.textContent=e,o.appendChild(i),i.style["overflow-y"]="hidden",i.style.height="auto",requestAnimationFrame(()=>{let s=i.scrollHeight,a=window.getComputedStyle(i,null);s+=parseInt(a.getPropertyValue("border-top-width")),s+=parseInt(a.getPropertyValue("border-bottom-width"));let d=this.textAreaEl.offsetHeight,E=s>d;if(this.onlyGrow===!1||E){let l=this._getLineHeight(),u=s/l;if(this._minRows&&this._minRows>=u)s=this._minRows*l;else if(this.maxRows&&this.maxRows<=u){let r=this.maxRows*l;s=this.onlyGrow?Math.max(r,d):r,this.textAreaEl.style.overflow="auto"}else{let r=parseFloat(window.getComputedStyle(this.textAreaEl).maxHeight);!isNaN(r)&&s>r?this.textAreaEl.style.overflow="auto":this.textAreaEl.style.overflow="hidden"}let y=s+"px",_=this.useImportant?"important":"";this.textAreaEl.style.setProperty("height",y,_),this.resized.emit(s)}o.removeChild(i)})}}_getLineHeight(){let t=parseInt(this.textAreaEl.style.lineHeight,10);if(isNaN(t)&&window.getComputedStyle){let e=window.getComputedStyle(this.textAreaEl);t=parseInt(e.lineHeight,10)}if(isNaN(t)){let e=window.getComputedStyle(this.textAreaEl,null).getPropertyValue("font-size");t=Math.floor(parseFloat(e)*1.5)}return t}static{this.\u0275fac=function(e){return new(e||n)}}static{this.\u0275dir=A({type:n,selectors:[["","textareaAutosize",""]],hostBindings:function(e,i){e&1&&p("input",function(s){return i.onInput(s.target)})},inputs:{minRows:"minRows",maxRows:"maxRows",onlyGrow:"onlyGrow",useImportant:"useImportant"},outputs:{resized:"resized"},features:[x]})}}return n})();function v(n,g,t=!1){let e;return function(){let i=this,o=arguments,s=function(){e=null,t||n.apply(i,o)},a=t&&!e;clearTimeout(e),e=setTimeout(s,g),a&&n.apply(i,o)}}export{S as a};