{"id":49060598,"url":"https://github.com/ShipItAndPray/pretext-forms","last_synced_at":"2026-05-06T06:01:36.794Z","repository":{"id":348053300,"uuid":"1196298524","full_name":"ShipItAndPray/pretext-forms","owner":"ShipItAndPray","description":"Auto-sizing textarea, input, select components using Pretext. No DOM reflow.","archived":false,"fork":false,"pushed_at":"2026-04-02T06:16:54.000Z","size":77,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-04-04T17:14:23.682Z","etag":null,"topics":["pretext","text-layout","typescript","typography"],"latest_commit_sha":null,"homepage":"https://shipitandpray.github.io/pretext-forms/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ShipItAndPray.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-30T15:04:36.000Z","updated_at":"2026-04-02T06:16:58.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ShipItAndPray/pretext-forms","commit_stats":null,"previous_names":["shipitandpray/pretext-forms"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ShipItAndPray/pretext-forms","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShipItAndPray%2Fpretext-forms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShipItAndPray%2Fpretext-forms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShipItAndPray%2Fpretext-forms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShipItAndPray%2Fpretext-forms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ShipItAndPray","download_url":"https://codeload.github.com/ShipItAndPray/pretext-forms/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShipItAndPray%2Fpretext-forms/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32680890,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-06T02:33:58.958Z","status":"ssl_error","status_checked_at":"2026-05-06T02:33:39.611Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pretext","text-layout","typescript","typography"],"created_at":"2026-04-20T02:00:28.099Z","updated_at":"2026-05-06T06:01:36.577Z","avatar_url":"https://github.com/ShipItAndPray.png","language":"TypeScript","funding_links":[],"categories":["Ecosystem Catalog"],"sub_categories":["Foundations and UI Primitives"],"readme":"# @shipitandpray/pretext-forms\n\n[![Live Demo](https://img.shields.io/badge/demo-live-brightgreen)](https://shipitandpray.github.io/pretext-forms/) [![npm](https://img.shields.io/npm/v/@shipitandpray/pretext-forms?color=blue)](https://www.npmjs.com/package/@shipitandpray/pretext-forms)\n\n\u003e **[View Live Demo](https://shipitandpray.github.io/pretext-forms/)**\nAuto-sizing form fields that know their height before render. Zero CLS. Zero flash.\n\nBuilt on [@chenglou/pretext](https://github.com/chenglou/pretext) -- a pure JavaScript text measurement and layout engine. No hidden divs, no `scrollHeight` hacks, no post-render reflow.\n\n## Install\n\n```bash\nnpm install @shipitandpray/pretext-forms @chenglou/pretext\n```\n\n## Quick Start\n\n```tsx\nimport { AutoTextarea } from '@shipitandpray/pretext-forms';\n\nfunction ChatInput() {\n  const [text, setText] = useState('');\n  return (\n    \u003cAutoTextarea\n      value={text}\n      onChange={(e) =\u003e setText(e.target.value)}\n      placeholder=\"Type a message...\"\n      minRows={1}\n      maxRows={8}\n    /\u003e\n  );\n}\n```\n\nThat's it. The textarea calculates its exact height before the browser paints. No flash, no reflow.\n\n## Components\n\n### `\u003cAutoTextarea /\u003e`\n\nDrop-in replacement for `\u003ctextarea\u003e` with auto-height.\n\n| Prop | Type | Default | Description |\n|------|------|---------|-------------|\n| `minRows` | `number` | `1` | Minimum visible rows |\n| `maxRows` | `number` | `Infinity` | Maximum rows before scrolling |\n| `onHeightChange` | `(height: number) =\u003e void` | -- | Called when computed height changes |\n| `style` | `React.CSSProperties` | -- | Merged with computed height |\n| ...rest | `TextareaHTMLAttributes` | -- | All standard textarea props |\n\n```tsx\n\u003cAutoTextarea\n  value={text}\n  onChange={(e) =\u003e setText(e.target.value)}\n  minRows={2}\n  maxRows={10}\n  onHeightChange={(h) =\u003e console.log('height:', h)}\n  className=\"my-textarea\"\n/\u003e\n```\n\n### `\u003cAutoInput /\u003e`\n\nAuto-width input that grows with its content.\n\n| Prop | Type | Default | Description |\n|------|------|---------|-------------|\n| `minWidth` | `number` | `40` | Minimum width in px |\n| `maxWidth` | `number` | `Infinity` | Maximum width in px |\n| `style` | `React.CSSProperties` | -- | Merged with computed width |\n| ...rest | `InputHTMLAttributes` | -- | All standard input props |\n\n```tsx\n\u003cAutoInput\n  placeholder=\"Add tag...\"\n  minWidth={80}\n  maxWidth={300}\n/\u003e\n```\n\n### `\u003cAutoSelect /\u003e`\n\nSelect that auto-sizes to fit the selected option text.\n\n| Prop | Type | Default | Description |\n|------|------|---------|-------------|\n| `style` | `React.CSSProperties` | -- | Merged with computed width |\n| ...rest | `SelectHTMLAttributes` | -- | All standard select props |\n\n```tsx\n\u003cAutoSelect value={val} onChange={(e) =\u003e setVal(e.target.value)}\u003e\n  \u003coption value=\"sm\"\u003eSmall\u003c/option\u003e\n  \u003coption value=\"lg\"\u003eA Much Longer Option\u003c/option\u003e\n\u003c/AutoSelect\u003e\n```\n\n### `\u003cAutoLabel /\u003e`\n\nLabel that measures its text content for width transitions.\n\n| Prop | Type | Default | Description |\n|------|------|---------|-------------|\n| `style` | `React.CSSProperties` | -- | Merged with computed width |\n| ...rest | `LabelHTMLAttributes` | -- | All standard label props |\n\n## Hook: `useAutoSize`\n\nFor custom components that need pre-render text measurement.\n\n```tsx\nimport { useAutoSize } from '@shipitandpray/pretext-forms';\n\nfunction CustomField({ text }) {\n  const { height, lineCount, style } = useAutoSize(\n    text,\n    { font: '400 14px / 20px Inter', fontSize: 14, lineHeight: 20 },\n    400, // maxWidth\n    { minRows: 2, maxRows: 10, padding: { top: 8, right: 12, bottom: 8, left: 12 } },\n  );\n  return \u003cdiv style={{ ...style, overflow: 'auto' }}\u003e{text}\u003c/div\u003e;\n}\n```\n\n### `useAutoSize` Return Value\n\n```ts\ninterface AutoSizeResult {\n  height: number;        // Total height including padding\n  width: number;         // Measured width\n  lineCount: number;     // Number of wrapped lines\n  style: {               // Ready-to-spread style object\n    height: string;\n    width?: string;\n  };\n}\n```\n\n## Utility: `measureTextWidth`\n\nMeasures the width of single-line text using pretext layout.\n\n```ts\nimport { measureTextWidth } from '@shipitandpray/pretext-forms';\n\nconst width = measureTextWidth('hello world', '400 14px Inter', 20);\n```\n\n## How It Works\n\n1. Reads the element's computed font styles on mount (font-family, font-size, line-height, etc.)\n2. On every value change, passes the text + font config to `@chenglou/pretext`'s `prepare()` + `layout()`\n3. Gets back exact `lineCount` and `height` -- calculated in pure JS with no DOM measurement\n4. Sets the element's `style.height` in the same render, before the browser paints\n5. Result: correct dimensions on first paint, zero layout shift\n\n## Comparison\n\n| Feature | pretext-forms | react-textarea-autosize | CSS field-sizing |\n|---------|--------------|------------------------|-----------------|\n| Zero reflow | Yes | No (1 frame) | Yes |\n| Safari support | Yes | Yes | No |\n| Firefox support | Yes | Yes | No |\n| Input auto-width | Yes | No | Partial |\n| Select auto-width | Yes | No | Yes |\n| SSR compatible | Yes | No (needs DOM) | Yes |\n| Bundle size | ~8KB | ~4KB | 0KB |\n\n## Browser Support\n\nChrome 90+, Firefox 90+, Safari 14+, Edge 90+.\n\nAll browsers that support `Intl.Segmenter` and `OffscreenCanvas` (or fallback to `\u003ccanvas\u003e`).\n\n## Development\n\n```bash\nnpm install\nnpm run dev          # Watch mode build\nnpm test             # Run tests\nnpm run demo         # Interactive demo\nnpm run build        # Production build (ESM + CJS)\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShipItAndPray%2Fpretext-forms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FShipItAndPray%2Fpretext-forms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShipItAndPray%2Fpretext-forms/lists"}