{"version":3,"file":"autogrow.umd.cjs","sources":["../src/vAutogrow.ts"],"sourcesContent":["import { nextTick, type DirectiveBinding } from 'vue';\n\nconst STYLE_ATTRIBUTES: (keyof CSSStyleDeclaration)[] = [\n    'font',\n    'fontFamily',\n    'fontKerning',\n    'fontSize',\n    'fontStretch',\n    'fontStyle',\n    'fontVariant',\n    'fontVariantLigatures',\n    'fontVariantCaps',\n    'fontVariantNumeric',\n    'fontVariantEastAsian',\n    'fontWeight',\n    'lineHeight',\n    'letterSpacing',\n    'padding',\n    'margin',\n    'textAlign',\n    'textAlignLast',\n    'textDecoration',\n    'textDecorationLine',\n    'textDecorationStyle',\n    'textDecorationColor',\n    'textDecorationSkipInk',\n    'textIndent',\n    'textRendering',\n    'textShadow',\n    'textOverflow',\n    'textTransform',\n    'width',\n    'wordBreak',\n    'wordSpacing',\n    'wordWrap'\n];\n  \nfunction escape(html: string): string {\n    const el = document.createElement('textarea');    \n    el.textContent = html;\n    return el.innerHTML;\n}\n  \nfunction int(str: number|string): number {\n    if(typeof str === 'number') {\n        return str;\n    } else if(!str || !str.replace) {\n        return 0;\n    }\n    \n    return parseInt(str.replace(/[^\\d.]+/g, '')) || 0;\n}\n  \nfunction input(div: HTMLElement, el: HTMLInputElement, minHeight: number, maxHeight: number): void {\n    const value = el.value;\n    \n    // Handle empty input\n    if(!value) {\n        div.innerHTML = '&nbsp;';\n    } else {\n        // Replace line breaks with <br> tags\n        div.innerHTML = escape(value).replace(/(?:\\r\\n|\\r|\\n)/g, '<br />');\n        \n        // Add a non-breaking space only if the text ends with a newline\n        // This ensures proper height calculation for trailing newlines\n        if(value.endsWith('\\n') || value.endsWith('\\r\\n') || value.endsWith('\\r')) {\n            div.innerHTML += '<br />';\n        } else {\n            div.innerHTML += '&nbsp;';\n        }\n    }\n  \n    const dynamicHeight = Math.max(minHeight, height(div));\n  \n    el.style.overflow = 'hidden';\n    el.style.height = (\n        (!maxHeight || dynamicHeight < maxHeight) ? dynamicHeight : maxHeight\n    ) + 'px';\n}\n  \nfunction height(el: HTMLElement): number {\n    return int(style(el, 'height') as string|number);\n}\n  \nfunction style(el: HTMLElement, attr: keyof CSSStyleDeclaration) {\n    return window.getComputedStyle(el)[attr];\n}\n  \nfunction mimic(el: HTMLElement): HTMLElement {\n    const div = document.createElement('div');\n    const styles = window.getComputedStyle(el);\n  \n    div.style.position = 'absolute';\n    div.style.zIndex = '-1';\n    div.style.visibility = 'hidden';\n    div.style.top = '0px';\n    div.style.whiteSpace = 'pre-wrap'; // Important: preserve whitespace and wrapping\n    div.style.wordWrap = 'break-word';\n    \n    el.parentNode?.insertBefore(div, el.nextSibling);\n  \n    STYLE_ATTRIBUTES.forEach(key => {\n        if(key in div.style) {\n            // eslint-disable-next-line @typescript-eslint/no-explicit-any\n            div.style[key as any] = styles[key as any];\n        }\n    });\n  \n    return div;\n}\n  \nfunction init(el: HTMLInputElement, binding: DirectiveBinding): void {\n    const minHeight = height(el);\n    const div = mimic(el);\n    const maxHeight = binding.value !== true ? binding.value : 0;\n  \n    el.addEventListener('input', event => {\n        input(div, event.target as HTMLInputElement, minHeight, maxHeight);\n    });\n  \n    // Initial calculation\n    input(div, el, minHeight, maxHeight);\n}\n  \nexport default {\n    mounted(el: HTMLInputElement, binding: DirectiveBinding): void {\n        if(binding.value === false) {\n            return;\n        }\n      \n        init(el, binding);\n      \n        el.addEventListener('resize', () => {\n            nextTick(() => {\n                el.dispatchEvent(new Event('input'));\n            });\n        });\n    }\n};"],"names":["STYLE_ATTRIBUTES","escape","html","el","int","str","input","div","minHeight","maxHeight","value","dynamicHeight","height","style","attr","mimic","styles","key","init","binding","event","vAutogrow","nextTick"],"mappings":"8PAEA,MAAMA,EAAkD,CACpD,OACA,aACA,cACA,WACA,cACA,YACA,cACA,uBACA,kBACA,qBACA,uBACA,aACA,aACA,gBACA,UACA,SACA,YACA,gBACA,iBACA,qBACA,sBACA,sBACA,wBACA,aACA,gBACA,aACA,eACA,gBACA,QACA,YACA,cACA,UACJ,EAEA,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