{"id":49060594,"url":"https://github.com/ShipItAndPray/pretext-editor","last_synced_at":"2026-05-06T06:01:36.832Z","repository":{"id":348053242,"uuid":"1196304810","full_name":"ShipItAndPray/pretext-editor","owner":"ShipItAndPray","description":"Canvas-rendered text editor using Pretext for line measurement. No contenteditable. Handles 1M+ lines.","archived":false,"fork":false,"pushed_at":"2026-04-02T06:16:52.000Z","size":64,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-04-04T17:14:25.643Z","etag":null,"topics":["pretext","text-layout","typescript","typography"],"latest_commit_sha":null,"homepage":"https://shipitandpray.github.io/pretext-editor/","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:11:26.000Z","updated_at":"2026-04-02T06:16:55.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ShipItAndPray/pretext-editor","commit_stats":null,"previous_names":["shipitandpray/pretext-editor"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ShipItAndPray/pretext-editor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShipItAndPray%2Fpretext-editor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShipItAndPray%2Fpretext-editor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShipItAndPray%2Fpretext-editor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShipItAndPray%2Fpretext-editor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ShipItAndPray","download_url":"https://codeload.github.com/ShipItAndPray/pretext-editor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShipItAndPray%2Fpretext-editor/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.378Z","avatar_url":"https://github.com/ShipItAndPray.png","language":"TypeScript","funding_links":[],"categories":["Flagship Ecosystem Packages"],"sub_categories":[],"readme":"# @shipitandpray/pretext-editor\n\n[![Live Demo](https://img.shields.io/badge/demo-live-brightgreen)](https://shipitandpray.github.io/pretext-editor/) [![GitHub](https://img.shields.io/github/stars/ShipItAndPray/pretext-editor?style=social)](https://github.com/ShipItAndPray/pretext-editor)\n\n\u003e **[View Live Demo](https://shipitandpray.github.io/pretext-editor/)**\n\nCanvas text editor powered by [Pretext](https://github.com/chenglou/pretext) — no `contenteditable`, no DOM text nodes, handles millions of lines.\n\n## Why\n\nEvery web text editor (Monaco, CodeMirror, Ace) uses DOM nodes for text rendering:\n\n- Layout reflow on every keystroke\n- Sluggish with 100K+ lines\n- `contenteditable` is a nightmare of browser inconsistencies\n\nThis editor renders **entirely on Canvas** using Pretext for sub-pixel-accurate layout. A hidden `\u003ctextarea\u003e` captures keyboard/IME input (the same technique Monaco uses). The result: constant-time scroll, no reflow, and a clean architecture.\n\n## Install\n\n```bash\nnpm install @shipitandpray/pretext-editor @chenglou/pretext\n```\n\n## Usage (Vanilla)\n\n```ts\nimport { Editor } from '@shipitandpray/pretext-editor'\n\nconst container = document.getElementById('editor')!\nconst editor = new Editor(container, { width: 800, height: 600 })\neditor.setValue('Hello, world!\\nLine 2')\neditor.setOnChange((value) =\u003e console.log('Changed:', value))\n```\n\n## Usage (React)\n\n```tsx\nimport { PretextEditor } from '@shipitandpray/pretext-editor/react'\n\nfunction App() {\n  const [code, setCode] = useState('// type here...')\n  return (\n    \u003cPretextEditor\n      value={code}\n      onChange={setCode}\n      width={800}\n      height={600}\n    /\u003e\n  )\n}\n```\n\n## Theme Customization\n\nPass a partial theme to override colors:\n\n```ts\nconst editor = new Editor(container, {\n  width: 800,\n  height: 600,\n  theme: {\n    background: '#282c34',\n    foreground: '#abb2bf',\n    cursor: '#528bff',\n    selection: 'rgba(82, 139, 255, 0.3)',\n    lineNumber: '#636d83',\n    gutterBackground: '#282c34',\n    currentLine: 'rgba(255, 255, 255, 0.03)',\n  },\n})\n```\n\n### Default Theme (Dark)\n\n| Property           | Default                       |\n| ------------------ | ----------------------------- |\n| `background`       | `#1e1e1e`                     |\n| `foreground`       | `#d4d4d4`                     |\n| `selection`        | `rgba(38, 79, 120, 0.6)`     |\n| `cursor`           | `#aeafad`                     |\n| `lineNumber`       | `#858585`                     |\n| `gutterBackground` | `#1e1e1e`                     |\n| `currentLine`      | `rgba(255, 255, 255, 0.04)`  |\n\n## Options\n\n| Option        | Type      | Default | Description                     |\n| ------------- | --------- | ------- | ------------------------------- |\n| `width`       | `number`  | —       | Canvas width in pixels          |\n| `height`      | `number`  | —       | Canvas height in pixels         |\n| `font`        | `string`  | `14px \"JetBrains Mono\", ...`  | CSS font string    |\n| `lineHeight`  | `number`  | `20`    | Line height in pixels           |\n| `readOnly`    | `boolean` | `false` | Disable editing                 |\n| `wordWrap`    | `boolean` | `false` | Enable soft word wrap           |\n| `lineNumbers` | `boolean` | `true`  | Show line number gutter         |\n| `theme`       | `object`  | Dark    | Partial theme overrides         |\n\n## Performance\n\n| Metric                    | Target       |\n| ------------------------- | ------------ |\n| Keystroke to render       | \u003c 2ms        |\n| Scroll FPS (1M lines)     | 120fps       |\n| Initial load (100K lines) | \u003c 200ms      |\n| Memory (1M lines)         | \u003c 100MB      |\n| Cache hit rate             | \u003e 99%        |\n\nThe virtualizer only measures and renders visible lines plus a small overscan buffer. Line measurements are cached and only invalidated on edit. Cumulative heights use binary search for O(log n) scroll-to-line mapping.\n\n## Architecture\n\n```\nCanvas (rendering)  \u003c--  Virtualizer (visible range)  \u003c--  LineLayout (Pretext measurement)\n     ^                                                           ^\n     |                                                           |\nHidden \u003ctextarea\u003e  --\u003e  KeyboardHandler  --\u003e  Document (line model + undo/redo)\nMouse events       --\u003e  MouseHandler     --\u003e  Cursor (position + selection)\n```\n\n- **Document**: Array of lines, insert/delete with full undo/redo stack\n- **LineLayout**: Pretext-based line measurement, wrapping, cumulative heights\n- **Virtualizer**: Determines visible range with overscan, ensures cursor visibility\n- **CanvasRenderer**: Draws text, gutter, selections, cursor via Canvas 2D\n- **KeyboardHandler**: Hidden textarea for input capture (handles IME, autocorrect)\n- **MouseHandler**: Click-to-position, drag-to-select via hitTest\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShipItAndPray%2Fpretext-editor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FShipItAndPray%2Fpretext-editor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShipItAndPray%2Fpretext-editor/lists"}