text: class TextareaCounter{constructor(t){this.$module=t,this.$textarea=t.querySelector("textarea"),this.$counter=this.buildCounterHtml(),this.updateCounter(),this.$textarea.addEventListener("input",()=>{this.updateCounter()})}buildCounterHtml(){if(this.$textarea.id){if(this.$textarea.maxLength){this.maxlength=this.$textarea.maxLength;var t,e=this.$textarea.id+"-Counter";this.$textarea.getAttribute("aria-describedby")?(t=this.$textarea.getAttribute("aria-describedby"),this.$textarea.setAttribute("aria-describedby",`${t} ${e}`)):this.$textarea.setAttribute("aria-describedby",e),this.$textarea.removeAttribute("maxlength");const a=document.createElement("div");return a.setAttribute("id",e),a.classList.add("fs-textarea-counter__counter"),this.$module.appendChild(a),a}console.error("TextareaCounter: Textarea must have a `maxlength` attribute set to attach a character counter.")}else console.error("TextareaCounter: Textarea must have a unique `id` attribute set to attach a character counter.")}updateCounter(){var t=this.count();let e="";t.tooLong?(e=1===t.charactersOver?`Limit reached. You're over by ${t.charactersOver} character.`:`Limit reached. You're over by ${t.charactersOver} characters.`,this.$counter.setAttribute("role","alert"),this.$textarea.setCustomValidity(`Input is too long. A maximum of ${t.maxlength} characters are allowed. You have used ${t.charactersUsed} characters.`)):(e=1===t.charactersRemaining?`You have ${t.charactersRemaining} character remaining.`:`You have ${t.charactersRemaining} characters remaining.`,this.$counter.removeAttribute("role"),this.$textarea.setCustomValidity("")),this.$counter.innerText=e,this.$counter.setAttribute("aria-live",t.charactersRemaining<1?"assertive":"polite")}count(){var t=this.maxlength-this.$textarea.value.length;return{maxlength:this.maxlength,charactersUsed:this.$textarea.value.length,charactersRemaining:t,charactersOver:t<0?Math.abs(t):0,tooLong:t<0}}}export default TextareaCounter;
  //# sourceMappingURL=textarea-counter.js.map
  