{"id":47709931,"url":"https://github.com/razroo/textura","last_synced_at":"2026-04-05T21:01:15.303Z","repository":{"id":347886030,"uuid":"1195612875","full_name":"razroo/textura","owner":"razroo","description":"Pretext x Yoga = Textura. DOM-free layout engine for the web","archived":false,"fork":false,"pushed_at":"2026-03-31T09:18:38.000Z","size":262,"stargazers_count":135,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-03T04:50:31.790Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://razroo.github.io/textura","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/razroo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-03-29T21:46:46.000Z","updated_at":"2026-04-02T01:07:33.000Z","dependencies_parsed_at":"2026-04-03T19:00:55.704Z","dependency_job_id":null,"html_url":"https://github.com/razroo/textura","commit_stats":null,"previous_names":["razroo/textura"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/razroo/textura","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/razroo%2Ftextura","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/razroo%2Ftextura/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/razroo%2Ftextura/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/razroo%2Ftextura/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/razroo","download_url":"https://codeload.github.com/razroo/textura/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/razroo%2Ftextura/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31371633,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-03T17:53:18.093Z","status":"ssl_error","status_checked_at":"2026-04-03T17:53:17.617Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":[],"created_at":"2026-04-02T18:29:18.781Z","updated_at":"2026-04-03T19:01:10.525Z","avatar_url":"https://github.com/razroo.png","language":"TypeScript","funding_links":[],"categories":["Community Projects","TypeScript"],"sub_categories":["Live Demos"],"readme":"# Textura\n\n**[Live Demo \u0026 Interactive Examples](https://razroo.github.io/textura/)**\n\nhttps://github.com/user-attachments/assets/bd67d28e-1841-474e-8d3c-8a7e76f272ba\n\nDOM-free layout engine for the web. Combines [Yoga](https://github.com/facebook/yoga) (flexbox) with [Pretext](https://github.com/chenglou/pretext) (text measurement) to compute complete UI geometry — positions, sizes, and text line breaks — without ever touching the DOM.\n\n## Why\n\nThe browser's layout engine is a black box that blocks the main thread. Every `getBoundingClientRect()` or `offsetHeight` call triggers synchronous layout reflow. When components independently measure text, each measurement triggers a reflow of the entire document.\n\nYoga solves box layout (flexbox) in pure JS/WASM, but punts on text — it requires you to supply a `MeasureFunction` callback externally. Pretext solves text measurement with canvas `measureText`, but doesn't do box layout. **Textura joins them**: declare a tree of flex containers and text nodes, get back exact pixel geometry for everything.\n\nThis unlocks:\n- **Worker-thread UI layout** — compute layout off the main thread, send only coordinates for painting\n- **Zero-estimation virtualization** — know exact heights for 100K items before mounting a single DOM node\n- **Canvas/WebGL/SVG rendering** — full layout engine for non-DOM renderers\n- **Server-side layout** — generate pixel positions server-side (once Pretext gets server canvas)\n\n## Installation\n\n```sh\nnpm install textura\n```\n\n## Quick Start\n\n```ts\nimport { init, computeLayout } from 'textura'\n\n// Initialize Yoga WASM (call once)\nawait init()\n\n// Describe your UI as a tree\nconst result = computeLayout({\n  width: 400,\n  padding: 16,\n  flexDirection: 'column',\n  gap: 12,\n  children: [\n    {\n      text: 'Hello World',\n      font: '24px Inter',\n      lineHeight: 32,\n    },\n    {\n      flexDirection: 'row',\n      gap: 8,\n      children: [\n        { width: 80, height: 80 },                              // avatar\n        {\n          text: 'This is a message that will wrap to multiple lines based on available width.',\n          font: '16px Inter',\n          lineHeight: 22,\n          flexGrow: 1,\n        },\n      ],\n    },\n  ],\n})\n\n// result is a tree of computed layouts:\n// {\n//   x: 0, y: 0, width: 400, height: ...,\n//   children: [\n//     { x: 16, y: 16, width: 368, height: 32, text: 'Hello World', lineCount: 1 },\n//     { x: 16, y: 60, width: 368, height: ...,\n//       children: [\n//         { x: 0, y: 0, width: 80, height: 80 },\n//         { x: 88, y: 0, width: 280, height: ..., text: '...', lineCount: ... },\n//       ]\n//     },\n//   ]\n// }\n```\n\n## API\n\n### `init(): Promise\u003cvoid\u003e`\n\nInitialize the Yoga WASM runtime. Must be called once before `computeLayout`.\n\n### `computeLayout(tree, options?): ComputedLayout`\n\nCompute layout for a declarative UI tree. Returns positions, sizes, and text metadata for every node.\n\n**Options:**\n- `width?: number` — available width for the root\n- `height?: number` — available height for the root\n- `direction?: 'ltr' | 'rtl'` — text direction (default: `'ltr'`)\n\n### Node types\n\n**Box nodes** — flex containers with children:\n```ts\n{\n  flexDirection: 'row',\n  gap: 8,\n  padding: 16,\n  children: [...]\n}\n```\n\n**Text nodes** — leaf nodes with measured text content:\n```ts\n{\n  text: 'Hello world',\n  font: '16px Inter',      // canvas font shorthand\n  lineHeight: 22,           // line height in px\n  whiteSpace: 'pre-wrap',   // optional: preserve spaces/tabs/newlines\n}\n```\n\nBoth node types accept all flexbox properties: `flexDirection`, `flexWrap`, `justifyContent`, `alignItems`, `alignSelf`, `alignContent`, `flexGrow`, `flexShrink`, `flexBasis`, `width`, `height`, `minWidth`, `maxWidth`, `minHeight`, `maxHeight`, `padding*`, `margin*`, `border*`, `gap`, `position`, `top/right/bottom/left`, `aspectRatio`, `overflow`, `display`.\n\n### `ComputedLayout`\n\n```ts\ninterface ComputedLayout {\n  x: number\n  y: number\n  width: number\n  height: number\n  children: ComputedLayout[]\n  text?: string        // present on text nodes\n  lineCount?: number   // present on text nodes\n}\n```\n\n### `clearCache(): void`\n\nClear Pretext's internal measurement caches.\n\n### `destroy(): void`\n\nRelease Yoga resources. Mostly useful for tests.\n\n## MCP Server — AI Layout Analysis\n\nThe Textura MCP server gives AI coding agents (Claude Code, Codex) layout vision — compute geometry, detect issues, validate responsive breakpoints, and auto-fix problems. Works with any framework.\n\n### Install\n\n\u003cdetails\u003e\n\u003csummary\u003eClaude Code\u003c/summary\u003e\n\n**One-line install:**\n```bash\nclaude mcp add textura npx @razroo/textura-mcp\n```\n\n**Uninstall:**\n```bash\nclaude mcp remove textura\n```\n\nOr manually add to `.mcp.json` (project-level) or `~/.claude/settings.json` (global):\n```json\n{\n  \"mcpServers\": {\n    \"textura\": {\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"@razroo/textura-mcp\"]\n    }\n  }\n}\n```\n\nTo uninstall manually, remove the `textura` entry from the config file.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eOpenAI Codex\u003c/summary\u003e\n\nAdd to your Codex MCP configuration:\n\n```json\n{\n  \"mcpServers\": {\n    \"textura\": {\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"@razroo/textura-mcp\"]\n    }\n  }\n}\n```\n\nTo uninstall, remove the `textura` entry from the config file.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eCursor\u003c/summary\u003e\n\nOpen Settings → MCP → Add new MCP server, or add to `.cursor/mcp.json`:\n\n```json\n{\n  \"mcpServers\": {\n    \"textura\": {\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"@razroo/textura-mcp\"]\n    }\n  }\n}\n```\n\nTo uninstall, remove the entry from MCP settings.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eWindsurf\u003c/summary\u003e\n\nAdd to `~/.codeium/windsurf/mcp_config.json`:\n\n```json\n{\n  \"mcpServers\": {\n    \"textura\": {\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"@razroo/textura-mcp\"]\n    }\n  }\n}\n```\n\nTo uninstall, remove the entry from the config file.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eVS Code / Copilot\u003c/summary\u003e\n\n**One-line install:**\n```bash\ncode --add-mcp '{\"name\":\"textura\",\"command\":\"npx\",\"args\":[\"-y\",\"@razroo/textura-mcp\"]}'\n```\n\nOr add to `.vscode/mcp.json`:\n```json\n{\n  \"servers\": {\n    \"textura\": {\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"@razroo/textura-mcp\"]\n    }\n  }\n}\n```\n\nTo uninstall, remove the entry from MCP settings or delete the server from the MCP panel.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eOther MCP clients\u003c/summary\u003e\n\nAny MCP client that supports stdio transport can use Textura. The server config is:\n\n```json\n{\n  \"command\": \"npx\",\n  \"args\": [\"-y\", \"@razroo/textura-mcp\"]\n}\n```\n\nTo uninstall, remove the server entry from your client's MCP configuration.\n\n\u003c/details\u003e\n\n### Tools\n\n| Tool | What it does |\n|---|---|\n| `compute_layout` | Compute exact pixel positions and sizes for a layout tree |\n| `analyze_layout` | Find text overflow, element overlap, small touch targets, cramped spacing |\n| `validate_responsive` | Check a layout at mobile/tablet/desktop/wide in one call |\n| `fix_layout` | Auto-fix detected issues, return corrected tree + change descriptions |\n\n### How it works with your code\n\nYou ask the agent to check your layout. The agent reads your component code (React, Vue, Svelte, Tailwind, etc.), translates the layout structure into a Textura tree, and calls the MCP:\n\n```jsx\n// Your component:\n\u003cdiv className=\"flex flex-col gap-4 p-6\"\u003e\n  \u003ch1 className=\"text-2xl font-bold\"\u003eDashboard\u003c/h1\u003e\n  \u003cdiv className=\"flex gap-4\"\u003e\n    \u003cCard\u003eRevenue: $12.4M\u003c/Card\u003e\n    \u003cCard\u003eUsers: 847K\u003c/Card\u003e\n  \u003c/div\u003e\n\u003c/div\u003e\n```\n\n```json\n// Agent translates to Textura tree:\n{\n  \"flexDirection\": \"column\", \"gap\": 16, \"padding\": 24,\n  \"children\": [\n    { \"text\": \"Dashboard\", \"font\": \"700 24px Inter\", \"lineHeight\": 32 },\n    { \"flexDirection\": \"row\", \"gap\": 16, \"children\": [\n      { \"padding\": 16, \"children\": [{ \"text\": \"Revenue: $12.4M\", \"font\": \"16px Inter\", \"lineHeight\": 24 }] },\n      { \"padding\": 16, \"children\": [{ \"text\": \"Users: 847K\", \"font\": \"16px Inter\", \"lineHeight\": 24 }] }\n    ]}\n  ]\n}\n```\n\nThe MCP returns exact geometry and issues. The agent applies fixes back to your actual code. No browser needed.\n\n## How it works\n\n1. You describe a UI tree using plain objects with CSS-like flex properties\n2. `computeLayout` builds a Yoga node tree from your description\n3. For text nodes, it wires Pretext's `prepare()` + `layout()` into Yoga's `MeasureFunction` — when Yoga asks \"how tall is this text at width X?\", Pretext answers using canvas-based measurement with cached segment widths\n4. Yoga runs its flexbox algorithm over the tree\n5. The computed positions and sizes are read back into a plain object tree\n\nThe text measurement is the key piece: Pretext handles Unicode segmentation, CJK character breaking, Arabic/bidi text, emoji, soft hyphens, and browser-specific quirks — all via `Intl.Segmenter` and canvas `measureText`, with 7680/7680 accuracy across Chrome/Safari/Firefox.\n\n## Limitations\n\n- Requires a browser environment (or `OffscreenCanvas` in a worker) for text measurement\n- Text nodes use the same CSS target as Pretext: `white-space: normal`, `word-break: normal`, `overflow-wrap: break-word`, `line-break: auto`\n- Use named fonts (`Inter`, `Helvetica`) — `system-ui` can produce inaccurate measurements on macOS\n\n## Credits\n\nBuilt on [Yoga](https://github.com/facebook/yoga) by Meta and [Pretext](https://github.com/chenglou/pretext) by Cheng Lou.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frazroo%2Ftextura","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frazroo%2Ftextura","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frazroo%2Ftextura/lists"}