in src/lib/spells/textarea-autosize.svelte.ts [34:73]
constructor(options: TextareaAutosizeOptions = {}) {
this.#options = options;
// Create hidden textarea for measurements
this.#createHiddenTextarea();
watch([() => this.input, () => this.element], () => {
tick().then(() => this.triggerResize());
});
watch(
() => this.textareaHeight,
() => options?.onResize?.()
);
useResizeObserver(
() => this.element,
([entry]) => {
if (!entry) return;
const { contentRect } = entry;
if (this.textareaOldWidth === contentRect.width) return;
this.textareaOldWidth = contentRect.width;
this.triggerResize();
}
);
onDestroy(() => {
// Clean up
if (this.#hiddenTextarea) {
this.#hiddenTextarea.remove();
this.#hiddenTextarea = null;
}
if (this.#resizeTimeout) {
window.cancelAnimationFrame(this.#resizeTimeout);
this.#resizeTimeout = null;
}
});
}