{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "core-auto-grow",
  "type": "registry:lib",
  "title": "core/auto-grow",
  "description": "Framework-free behaviour shared by the ui-* components (auto-grow); no DOM, no lit. Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/core/auto-grow.ts",
      "type": "registry:lib",
      "target": "components/ui/core/auto-grow.ts",
      "content": "/**\n * A text area that sizes itself to its text (no Carbon counterpart; MUI TextareaAutosize, CSS\n * `field-sizing: content`): from its `rows` up to `maxRows` lines, then it scrolls; it shrinks back\n * as text goes. Browser only.\n */\n/** What is read from the text area's computed style. */\ninterface FieldStyle {\n    display: string;\n    fontSize: string;\n    lineHeight: string;\n    paddingTop: string;\n    paddingBottom: string;\n    borderTopWidth: string;\n    borderBottomWidth: string;\n}\n\n/** A `<textarea>`, typed here: the core compiles without the DOM lib (tsconfig.core.json). */\nexport interface GrowingField {\n    scrollHeight: number;\n    style: { height: string; overflowY: string; removeProperty(name: string): unknown };\n}\n\nconst host = globalThis as unknown as { getComputedStyle(el: GrowingField): FieldStyle };\n\n/** `line-height: normal` reads as no number: about 1.2 × the font size, as browsers draw it for most fonts. */\nconst NORMAL_LINE_HEIGHT = 1.2;\n\nexport function fitTextArea(el: GrowingField, maxRows?: number) {\n    const cs = host.getComputedStyle(el);\n    if (cs.display === 'none') return;\n    const px = (v: string) => Number.parseFloat(v) || 0;\n    const borders = px(cs.borderTopWidth) + px(cs.borderBottomWidth);\n    const lineHeight = cs.lineHeight === 'normal' ? px(cs.fontSize) * NORMAL_LINE_HEIGHT : px(cs.lineHeight);\n    const max = maxRows ? maxRows * lineHeight + px(cs.paddingTop) + px(cs.paddingBottom) + borders : Infinity;\n    // back to `rows` (the shortest it gets), then as tall as the text\n    el.style.height = 'auto';\n    const content = el.scrollHeight + borders;\n    el.style.height = `${Math.min(content, max)}px`;\n    el.style.overflowY = content > max ? 'auto' : 'hidden';\n}\n\n/** Hands the text area its own size back (auto-grow turned off). */\nexport function unfitTextArea(el: GrowingField) {\n    el.style.removeProperty('height');\n    el.style.removeProperty('overflow-y');\n}\n"
    }
  ]
}
