export default class FitText { constructor(el, defaultSize, increment) { this.element = el; this.defaultSize = defaultSize; this.increment = increment; } fit() { this.element.style.fontSize = this.defaultSize + "rem"; this.recalc(); } recalc(shouldRecalc) { if (shouldRecalc || this.element.clientHeight < this.element.scrollHeight) { this.element.style.fontSize = (parseFloat(this.element.style.fontSize.replace(/[^0-9.]/g,'')) - this.increment) + "rem"; this.recalc(); } } }