{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "field-autosize-textarea",
  "type": "registry:component",
  "title": "Autosize Textarea",
  "description": "A textarea that grows smoothly with its content up to a row limit, with a ring counter that turns amber near the limit and red past it. Characters over the limit are tinted in place, and Cmd or Ctrl plus Enter sends.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "forms",
    "textarea",
    "autosize",
    "counter",
    "composer",
    "limit",
    "input"
  ],
  "docs": "https://hyperblur.dev/effects/field-autosize-textarea",
  "files": [
    {
      "path": "registry/hyperblur/field-autosize-textarea.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/field-autosize-textarea.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface FieldAutosizeTextareaProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\" | \"onSubmit\"> {\n  label?: string;\n  placeholder?: string;\n  value?: string;\n  defaultValue?: string;\n  onChange?: (value: string) => void;\n  onSubmit?: (value: string) => void;\n  limit?: number;\n  minRows?: number;\n  maxRows?: number;\n  submitLabel?: string;\n  accent?: string;\n  disabled?: boolean;\n}\n\nconst css = `\n.hb-xg6 {\n  --hb-xg6-c: #2f7bff;\n  --hb-xg6-lh: 21px;\n  box-sizing: border-box;\n  width: 100%;\n  font-family: inherit;\n  color: #ededed;\n}\n.hb-xg6 *, .hb-xg6 *::before, .hb-xg6 *::after { box-sizing: border-box; }\n.hb-xg6-label { display: block; margin: 0 0 7px; font-size: 12.5px; font-weight: 500; color: #a1a1a1; }\n.hb-xg6-box {\n  border: 1px solid #262626;\n  border-radius: 14px;\n  background: linear-gradient(180deg, #151515, #0f0f0f);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.045), 0 1px 2px rgba(0, 0, 0, 0.5);\n  transition: border-color 0.2s ease, box-shadow 0.25s ease;\n}\n.hb-xg6-box:hover { border-color: #333; }\n.hb-xg6-box:focus-within {\n  border-color: var(--hb-xg6-c);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.045), 0 0 0 4px color-mix(in srgb, var(--hb-xg6-c) 16%, transparent);\n}\n.hb-xg6[data-over=\"true\"] .hb-xg6-box:focus-within { border-color: #ff5c5c; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.045), 0 0 0 4px rgba(255, 92, 92, 0.14); }\n.hb-xg6[data-disabled=\"true\"] { opacity: 0.5; pointer-events: none; }\n.hb-xg6-area { position: relative; }\n.hb-xg6-ta, .hb-xg6-back, .hb-xg6-mirror {\n  display: block;\n  width: 100%;\n  margin: 0;\n  padding: 12px 14px 4px;\n  border: 0;\n  font: inherit;\n  font-size: 14px;\n  line-height: var(--hb-xg6-lh);\n  letter-spacing: 0;\n  white-space: pre-wrap;\n  overflow-wrap: break-word;\n  word-break: break-word;\n}\n.hb-xg6-ta {\n  position: relative;\n  z-index: 1;\n  resize: none;\n  outline: 0;\n  background: transparent;\n  color: #ededed;\n  caret-color: var(--hb-xg6-c);\n  overflow-y: hidden;\n  transition: height 0.22s cubic-bezier(0.22, 1, 0.36, 1);\n  scrollbar-width: thin;\n}\n.hb-xg6-ta::placeholder { color: #5a5a5a; }\n.hb-xg6-ta[data-scroll=\"true\"] { overflow-y: auto; }\n.hb-xg6-back {\n  position: absolute;\n  inset: 0;\n  overflow: hidden;\n  color: transparent;\n  pointer-events: none;\n}\n.hb-xg6-back mark { color: transparent; background: rgba(255, 92, 92, 0.22); border-radius: 3px; box-shadow: 0 2px 0 -0.5px #ff5c5c; }\n.hb-xg6-mirror { position: absolute; top: 0; left: 0; visibility: hidden; pointer-events: none; height: auto; }\n.hb-xg6-foot { display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 8px 0 14px; }\n.hb-xg6-stats { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; color: #6f6f6f; font-variant-numeric: tabular-nums; }\n.hb-xg6-stats kbd { font-family: inherit; padding: 1px 4px; border: 1px solid #2a2a2a; border-radius: 4px; color: #8f8f8f; font-size: 10.5px; }\n.hb-xg6-ring { position: relative; display: grid; place-items: center; width: 26px; height: 26px; flex: none; }\n.hb-xg6-ring svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); }\n.hb-xg6-ring circle { fill: none; stroke-width: 2.4; }\n.hb-xg6-track { stroke: #262626; }\n.hb-xg6-fill { stroke: var(--hb-xg6-c); stroke-linecap: round; transition: stroke-dashoffset 0.25s cubic-bezier(0.22, 1, 0.36, 1), stroke 0.25s ease; }\n.hb-xg6[data-level=\"warn\"] .hb-xg6-fill { stroke: #f5a524; }\n.hb-xg6[data-level=\"over\"] .hb-xg6-fill { stroke: #ff5c5c; }\n.hb-xg6[data-level=\"warn\"] .hb-xg6-ring svg, .hb-xg6[data-level=\"over\"] .hb-xg6-ring svg { transform: rotate(-90deg) scale(1.18); }\n.hb-xg6-left { position: relative; font-size: 10px; font-weight: 600; font-variant-numeric: tabular-nums; color: #f5a524; opacity: 0; transform: scale(0.6); transition: opacity 0.2s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }\n.hb-xg6[data-level=\"warn\"] .hb-xg6-left, .hb-xg6[data-level=\"over\"] .hb-xg6-left { opacity: 1; transform: none; }\n.hb-xg6[data-level=\"over\"] .hb-xg6-left { color: #ff6b6b; }\n.hb-xg6[data-level=\"over\"] .hb-xg6-ring { animation: hb-xg6-nudge 0.35s cubic-bezier(0.36, 0.07, 0.19, 0.97); }\n.hb-xg6-div { width: 1px; height: 20px; background: #262626; flex: none; }\n.hb-xg6-send {\n  display: inline-flex;\n  align-items: center;\n  gap: 6px;\n  height: 30px;\n  margin: 0;\n  padding: 0 12px;\n  border: 0;\n  border-radius: 999px;\n  background: linear-gradient(180deg, #ffffff, #dcdcdc);\n  box-shadow: inset 0 1px 0 #fff, 0 4px 12px -6px rgba(255, 255, 255, 0.4);\n  color: #0a0a0a;\n  font: inherit;\n  font-size: 12.5px;\n  font-weight: 600;\n  cursor: pointer;\n  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease, filter 0.2s ease;\n}\n.hb-xg6-send:hover:not(:disabled) { filter: brightness(1.05); }\n.hb-xg6-send:active:not(:disabled) { transform: scale(0.95); }\n.hb-xg6-send:disabled { opacity: 0.3; cursor: not-allowed; }\n.hb-xg6-send:focus-visible { outline: 2px solid var(--hb-xg6-c); outline-offset: 2px; }\n.hb-xg6-send svg { width: 12px; height: 12px; }\n.hb-xg6[data-sent=\"a\"] .hb-xg6-send { animation: hb-xg6-sent-a 0.5s cubic-bezier(0.34, 1.56, 0.64, 1); }\n.hb-xg6[data-sent=\"b\"] .hb-xg6-send { animation: hb-xg6-sent-b 0.5s cubic-bezier(0.34, 1.56, 0.64, 1); }\n.hb-xg6-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }\n@keyframes hb-xg6-nudge { 25% { transform: translateX(-2px); } 75% { transform: translateX(2px); } }\n@keyframes hb-xg6-sent-a { 40% { transform: scale(1.08); } }\n@keyframes hb-xg6-sent-b { 40% { transform: scale(1.08); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xg6 *, .hb-xg6 * svg { transition: none !important; animation: none !important; }\n}\n`;\n\nexport function FieldAutosizeTextarea({\n  label = \"Message\",\n  placeholder = \"Write something worth reading…\",\n  value,\n  defaultValue = \"\",\n  onChange,\n  onSubmit,\n  limit = 280,\n  minRows = 2,\n  maxRows = 8,\n  submitLabel = \"Post\",\n  accent = \"#2f7bff\",\n  disabled = false,\n  className = \"\",\n  style,\n  ...rest\n}: FieldAutosizeTextareaProps) {\n  const id = React.useId();\n  const taRef = React.useRef<HTMLTextAreaElement>(null);\n  const backRef = React.useRef<HTMLDivElement>(null);\n  const mirrorRef = React.useRef<HTMLDivElement>(null);\n  const controlled = value !== undefined;\n  const [inner, setInner] = React.useState(defaultValue);\n  const [sent, setSent] = React.useState(0);\n  const text = controlled ? value : inner;\n  const len = [...text].length;\n  const left = limit - len;\n  const level = left < 0 ? \"over\" : left <= Math.max(10, Math.round(limit * 0.1)) ? \"warn\" : \"ok\";\n  const words = text.trim() ? text.trim().split(/\\s+/).length : 0;\n  const minutes = Math.max(1, Math.round(words / 230));\n\n  React.useLayoutEffect(() => {\n    const ta = taRef.current;\n    const mirror = mirrorRef.current;\n    if (!ta || !mirror) return;\n    const lh = 21;\n    const padY = 16;\n    const min = minRows * lh + padY;\n    const max = maxRows * lh + padY;\n    const h = Math.min(max, Math.max(min, mirror.scrollHeight));\n    ta.style.height = `${h}px`;\n    ta.dataset.scroll = mirror.scrollHeight > max ? \"true\" : \"false\";\n    if (backRef.current) backRef.current.scrollTop = ta.scrollTop;\n  }, [text, minRows, maxRows]);\n\n  function update(v: string) {\n    if (!controlled) setInner(v);\n    onChange?.(v);\n  }\n\n  function submit() {\n    if (!text.trim() || left < 0 || disabled) return;\n    onSubmit?.(text);\n    setSent((s) => s + 1);\n  }\n\n  const chars = [...text];\n  const within = chars.slice(0, limit).join(\"\");\n  const beyond = chars.slice(limit).join(\"\");\n  const r = 10;\n  const circ = 2 * Math.PI * r;\n  const offset = circ * (1 - Math.min(1, len / limit));\n  const vars = { \"--hb-xg6-c\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <div\n      className={`hb-xg6 ${className}`}\n      style={vars}\n      data-level={level}\n      data-over={left < 0}\n      data-sent={sent === 0 ? \"none\" : sent % 2 === 1 ? \"a\" : \"b\"}\n      data-disabled={disabled}\n      {...rest}\n    >\n      <style href=\"hb-field-autosize-textarea\" precedence=\"default\">{css}</style>\n      {label && (\n        <label className=\"hb-xg6-label\" htmlFor={`${id}-ta`}>\n          {label}\n        </label>\n      )}\n      <div className=\"hb-xg6-box\">\n        <div className=\"hb-xg6-area\">\n          <div ref={backRef} className=\"hb-xg6-back\" aria-hidden=\"true\">\n            {within}\n            {beyond && <mark>{beyond}</mark>}\n          </div>\n          <div ref={mirrorRef} className=\"hb-xg6-mirror\" aria-hidden=\"true\">\n            {text}\n            {\"​\"}\n          </div>\n          <textarea\n            ref={taRef}\n            id={`${id}-ta`}\n            className=\"hb-xg6-ta\"\n            rows={minRows}\n            value={text}\n            placeholder={placeholder}\n            disabled={disabled}\n            aria-invalid={left < 0}\n            aria-describedby={`${id}-st`}\n            onChange={(e) => update(e.target.value)}\n            onScroll={(e) => {\n              if (backRef.current) backRef.current.scrollTop = e.currentTarget.scrollTop;\n            }}\n            onKeyDown={(e) => {\n              if (e.key === \"Enter\" && (e.metaKey || e.ctrlKey)) {\n                e.preventDefault();\n                submit();\n              }\n            }}\n          />\n        </div>\n        <div className=\"hb-xg6-foot\">\n          <span className=\"hb-xg6-stats\" id={`${id}-st`}>\n            {words} {words === 1 ? \"word\" : \"words\"} · {minutes} min read · <kbd>⌘</kbd> <kbd>↵</kbd> to send\n          </span>\n          <span className=\"hb-xg6-ring\" aria-hidden=\"true\">\n            <svg viewBox=\"0 0 26 26\">\n              <circle className=\"hb-xg6-track\" cx=\"13\" cy=\"13\" r={r} />\n              <circle className=\"hb-xg6-fill\" cx=\"13\" cy=\"13\" r={r} strokeDasharray={circ.toFixed(2)} strokeDashoffset={offset.toFixed(2)} />\n            </svg>\n            <span className=\"hb-xg6-left\">{left < -99 ? \"-99\" : left}</span>\n          </span>\n          <span className=\"hb-xg6-sr\" aria-live=\"polite\">\n            {level === \"over\" ? `${-left} characters over the limit` : level === \"warn\" ? `${left} characters left` : \"\"}\n          </span>\n          <span className=\"hb-xg6-div\" aria-hidden=\"true\" />\n          <button type=\"button\" className=\"hb-xg6-send\" disabled={disabled || !text.trim() || left < 0} onClick={submit}>\n            {submitLabel}\n            <svg viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" aria-hidden=\"true\">\n              <path d=\"M2 6h7.5M6.5 3l3 3-3 3\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n            </svg>\n          </button>\n        </div>\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}