GitHub - rauchg/xeet: X posts rendered to PNG without a browser, in safe Rust and WebAssembly.

GitHub

16 min read Original article ↗

xeet-rs.vercel.app

xeet draws X posts exactly the way X draws them, without a browser. Hand it a post, or just an x.com link, and you get back a Retina PNG that matches what Chrome shows on x.com: the same line breaks, the same emoji, the same fallback fonts, and "Show more" in the same place.

Most preview tools boot headless Chromium and take a screenshot. xeet reimplements the parts a post actually depends on instead: X's client rules, Blink and HarfBuzz text layout, the flexbox geometry around the text, and Skia-style anti-aliasing. All of it is safe Rust (#![forbid(unsafe_code)]).

It ships as one native binary and one WebAssembly core, plus six font packs the host registers on first use. Once those are loaded, a text post renders in 2.8 ms (p50, 390 px at 3×), or 4.5 ms with four media placeholders. Rendering needs no network, no filesystem, no clock and no system fonts, and the native and WASM builds produce the same bytes. CI checks Linux x64, Linux arm64, macOS and WASM against each other on every run.

Gallery

Every image below is xeet's own output, rendered in both light and dark themes so GitHub matches your appearance setting.

Browse all 17 edge-case renders (Web & iOS, carousels, polls, video posters, CJK/RTL) in docs/GALLERY.md → — or try any post interactively in the playground.

Features

  • Matches Chrome, and proves it. Text, layout, cards and pixels are all checked against real headless Chrome: zero line-break and zero height mismatches on the text oracle, 147/147 frame rows per theme, 192/192 card rows, and 159/159 captured posts end to end. See How the tests work.
  • Follows X's own rules. SPEC.md records every rule along with its evidence (the JS chunk, the function, the captured payload) for x-web@55591fe0, the version X serves today. crates/xeet-core/rules/x-web.json is the machine-readable copy the renderer runs.
  • Resolves links without owning the network. xeet-resolve turns tweet text or an x.com URL into a complete Post, but the caller supplies every byte of I/O (Fetch, Lookup, Cache, Clock). The core stays a pure function, and the network policy stays yours.
  • Runs wherever you need the image. One core, three targets: a WebAssembly module for browsers and Node (packages/xeet), a native Rust library (crates/xeet-core, crates/xeet-resolve), and the xeet CLI (crates/xeet-cli, packaged for npm i -g @xeet/cli by tools/ship/package-cli.mjs).
  • Deterministic down to the byte. xeet-core does no I/O, no core crate uses unsafe, and native and WASM output have identical SHA-256 hashes on 24 of 24 cases.
  • Handles the long tail. Bidi, CJK, kaomoji, multi-codepoint emoji, nested quotes, cards, polls, video, the web/iOS differences, and safe link resolution. The full list is under What it handles.

Running it

vercel dev runs tools/ship/vercel-build.mjs and serves the WebAssembly playground locally. To build and test from source:

$ npm run build                  # runs the CI test gates, builds wasm, writes dist/
$ npm test                       # contract, unsafe, golden stamps, and wasm package tests
$ cargo test --workspace         # rules, text, layout, paint, resolver, iconic posts

$ cargo build --release --bin xeet
$ xeet render post.json --width 390 --theme dark --dpr 3 -o post.png

The Chrome parity oracle needs one dev dependency of its own: pnpm --dir tools install.

API

JavaScript & WebAssembly

import { loadXeet } from "@xeet/core/node";

const xeet = await loadXeet(); // Promise<Xeet> (singleton per process)

const report = xeet.explain(post, { width: 390, theme: "dark", dpr: 3 });
// → Report: { ruleset, verifiedFor, size: { width, height }, length, text, entities, hidden, attachment, warnings }

const { png, report: same } = xeet.render(post, { width: 390, theme: "dark", dpr: 3 });
// → { png: Uint8Array, report: Report }  (PNG dimensions: ceil(report.size.width * dpr) × ceil(report.size.height * dpr))

if (xeet.hasShowMore(post, { surface: "web-timeline", width: 390 })) {
  const expanded = xeet.render(post, { surface: "web-timeline", width: 390, expanded: true });
}
const sheet = xeet.sheet({ post, widths: [382, 390, 600], themes: ["light", "dark"], dpr: 2 });
// → Uint8Array (single labeled PNG grid)

In the browser, initialize the WebAssembly module and bind the same Xeet surface:

import init, * as wasm from "/wasm/xeet_wasm.js";
import { bind } from "@xeet/core";

await init();
const xeet = bind(wasm); // Xeet
const { png, report } = xeet.render(post, { width: 390, theme: "light", dpr: 2 });

Methods & return values (Xeet · abi.js)

Call Return type Description & source definition
loadXeet(options?) Promise<Xeet> Node/Bun/Deno async loader ({ lazy?: boolean }) — node.d.ts · node.js
loadXeetSync(options?) Xeet Synchronous Node singleton loader — node.d.ts · node.js
bind(wasm) Xeet Browser/worker wrapper over initialized wasm-bindgen exports — types.d.ts · abi.js
xeet.render(post, options?) RenderResult ({ png: Uint8Array, report: Report }) Encoded PNG bytes + layout Report — abi.js · render.rs
xeet.renderPng(post, options?) Uint8Array Encoded PNG bytes alone — types.d.ts · abi.js
xeet.renderRgba(post, options?) RgbaResult ({ width, height, rgba: Uint8Array, report: Report }) Device-pixel dimensions + straight-alpha RGBA8 (width × height × 4 bytes) + Report — abi.js · render.rs
xeet.renderMany(post, optionsList) BatchItem[] ({ png: Uint8Array, report: Report, paint: number }[]) Decodes post media once across multiple RenderOptions; paint is render ms — abi.js · render.rs
xeet.explain(post, options?) Report Layout boxes, character count, entities, and rule decisions with zero rasterization — abi.js · render.rs
xeet.hasShowMore(post, options?) boolean true when post renders with "Show more" collapsed under options — abi.js · render.rs
xeet.sheet({ post, widths?, themes?, dpr? }) Uint8Array Labeled widths × themes contact sheet PNG — abi.js · render.rs
xeet.resolve(input, options?, host?) Promise<Resolved> Hydrates text, an x.com URL, or JSON into { post, links, media, source, warnings } — resolve.js · xeet-resolve
xeet.resolveLinks(url, options?, host?) Promise<ResolvedLink> Crawls one URL as Twitterbot/1.0 → { meta, chain, finalUrl, tags, imageUrl, image?, notes, cached } — resolve.js · xeet-resolve
xeet.whatwgHost(parts?) Host Wraps fetch + optional DNS lookup & cache callbacks — resolve.js
xeet.upstream string Embedded X web-client revision hash (e.g. "55591fe0") — abi.js

Report shape (types.d.ts · model.rs)

  • ruleset: string — X ruleset version (e.g. "x-web@55591fe0").
  • verifiedFor: Surface[] — surfaces verified against Chrome for this ruleset.
  • size: { width: number, height: number } (Size) — frame box in CSS pixels; PNG pixel dimensions are Math.ceil(size.width * dpr) × Math.ceil(size.height * dpr).
  • length: { weighted: number, limit: number, valid: boolean } (Length) — X weighted character count (URL = 23, emoji/CJK = 2; standard limit = 280).
  • text: { lines: number, truncated: boolean, hasShowMore: boolean, showMore: "inline" | "clamped" | null, visible: string } (TextReport) — rendered line count, "Show more" mode ("inline" web UTF-16 cut vs "clamped" iOS 9-line clamp), and displayed text.
  • entities: { kind: "url" | "mention" | "hashtag" | "cashtag", range: [number, number], text: string, display?: string }[] (Entity) — UTF-16 [start, end] code-unit offsets into post.text.
  • hidden: { range: [number, number], why: string }[] (Hidden) — UTF-16 ranges stripped from visible text ("reply_mentions", "quote_url", "media_url").
  • attachment: { shown: "card" | "media" | "quote" | "poll", url?: string | null, why: string } | null (Attachment) — winning attachment and rule reason.
  • warnings: string[] — non-fatal notes (such as missing image bytes drawn as a placeholder).

A Post (types.d.ts) requires only text:

{
  "text": "We just shipped the thing.",
  "author": { "name": "Vercel", "handle": "vercel", "verified": "business", "squareAvatar": true },
  "media": [{ "kind": "video", "width": 1280, "height": 720, "duration": 11.7 }],
  "links": { "https://vercel.com/blog/x": { "card": "summary_large_image", "title": "…" } },
  "quote": { "text": "…", "author": { "name": "…", "handle": "…" } },
  "poll": { "choices": ["Yes", "No"], "votes": [58, 42] },
  "counts": { "replies": 131, "reposts": 55, "likes": 5264, "views": 37047269 },
  "createdAt": "2026-11-10T06:00:00Z",
  "now": "2026-11-10T09:00:00Z"
}

RenderOptions (types.d.ts) is { surface?: "web-timeline" | "web-detail" | "ios-timeline" | "ios-detail", width?: number, theme?: "light" | "dark", dpr?: number, fontScale?: number, expanded?: boolean }. Limits are enforced in limits.rs, published as JSON Schema in packages/xeet/src/schemas.js (with MCP tool descriptors in packages/xeet/src/mcp.js). Validation and limit failures throw XeetError (abi.js · render.rs) with { code: string, status: 400 | 413 | 500 | 503, fields: { path, message, suggestion? }[], notes: string[] }.

Resolution & Resolved shape (types.d.ts · xeet-resolve/src/lib.rs)

Resolution takes its network from the caller — fetch is externalized, never imported, and the library follows redirects itself:

// input: tweet text, an x.com status URL, or post JSON.
const resolved = await xeet.resolve(input, { media: true, width: 390, dpr: 2 }, {
  fetch: (request) => fetch(request.url, { redirect: "manual", headers: request.headers }),
  lookup: (host) => dns.resolve(host),         // optional: enables the DNS-hop SSRF guard
  cacheGet: async (key) => store.get(key),     // optional: { value, storedAt } | null
  cacheSet: async (key, value, storedAt) => store.set(key, { value, storedAt }),
});
// resolved: {
//   post: Post,                                // pass directly to xeet.render(resolved.post, options)
//   links: Record<string, ResolvedLink>,       // keyed by URL as written in post.text
//   media: Record<string, MediaAsset>,         // { variant, bytes, width, height, role, data? }
//   source: { url, id, appVersion, pinned },   // upstream status metadata
//   warnings: string[],
// }

const link = await xeet.resolveLinks("https://t.co/jO01BMGwXr", { media: false }, host);
// link: { meta: LinkMeta, chain: { url, status }[], finalUrl, tags, imageUrl, image?, notes, cached }

packages/xeet/src/resolve.js documents the Host contract (whatwgHost, memoryCache, noCache); failures throw ResolveError (resolve.js · xeet-resolve) with { code, status, fields }.

Rust & CLI

use xeet_core::render;

// Result<(Vec<u8>, model::Report), render::Error> — network-free; core fonts embedded
let (png, report) = render::render(&post, &opts)?;
// Result<(paint::Pixmap, model::Report), render::Error> — straight-alpha RGBA8
let (pixmap, report) = render::render_rgba(&post, &opts)?;
// Result<model::Report, render::Error>
let report = render::explain(&post, &opts)?;
// Result<bool, render::Error>
let can_expand = render::has_show_more(&post, &opts)?;
// Result<(DisplayList, model::Report), render::Error> — every box, before rasterizing
let (list, report) = render::display_list(&post, &opts)?;

See render.rs, model.rs, display.rs, and paint/mod.rs for the Rust types. The resolver (xeet-resolve) exposes the same Resolved / ResolvedLink types over injected traits (Fetch, Lookup, Cache, Clock), with xeet-resolve-net as the default ureq + rustls host:

// Result<xeet_resolve::Resolved, xeet_resolve::Error>
let resolved = xeet_resolve::resolve(input, options, &fetch, Some(&lookup), Some(&cache), Some(&clock)).await?;
npm i -g @xeet/cli               # or: cargo install --git https://github.com/rauchg/xeet xeet-cli

xeet render post.json --surface web-detail --width 390 --theme dark --dpr 3 -o post.png   # writes PNG (-o - for stdout)
xeet explain post.json --compact | jq .size                                               # prints Report JSON to stdout
xeet sheet post.json --widths 320,390,600 --themes light,dark -o sheet.png                # writes contact-sheet PNG
xeet resolve https://x.com/NASA/status/2119833829389041896 --media | xeet render - -o nasa.png # Resolved JSON → PNG
xeet-render serve --stdio        # JSONL server: { id, op: "render" | "explain" | "info", ... }

CLI exit codes (commands/mod.rs): 0 success, 2 bad usage, 3 invalid input or over limit, 4 render stage failure, 5 file/network I/O error.

How it imitates Chrome

1️⃣ Rules. SPEC.md and crates/xeet-core/src/rules/ mirror the JS X actually ships (rules/x-web.json). The ruleset is x-web@55591fe0, and each entry says whether it was read out of X's shipped client code, measured across 270 captured public payloads, or is still a prior. Entity extraction (twitter-text's rules, reimplemented and held to its own 2,119-case suite), the UTF-16 Show more cut and the display_text_range that decides it — landing mid-emoji moves the boundary to the next code point — attachment precedence, and the depth-2 nested quote: a self-quote at either hop is rejected, and so is a preview that would draw two attachments.

2️⃣ Text & shaping. inline.rs, shape.rs, fonts.rs, script.rs and linebreak.rs reproduce Blink plus HarfBuzz to 0 line-break mismatches: harfrust shapes each run and converts its advances the way Blink does, in 16.16 fixed point; Blink's ScriptRunIterator decides the runs, so a bracket that changes script takes the next script's run and loses the kerning; a per-character CSS unicode-range walk picks the face across X's 28 Chirp woff2 subsets, Arial, Apple Color Emoji and the symbol/math/Hiragino fallbacks. Breaking is UAX #14 (icu_segmenter) with Blink's 1/64 px fit arithmetic — a line may end 1/64 px into a hanging space — and bidi is UAX #9 (unicode-bidi) with rule L1 putting trailing whitespace back at the paragraph level.

3️⃣ Frame & attachments. frame/ and cards/ are CSS flexbox as Blink lays it out: the two-row header with truncated name and handle, the 40 px avatar (a 10% radius on a business account's square), action counts that abbreviate the way X abbreviates them, CSS superellipse(2) squircle media corners, the image carousel X draws now (one card per image, up to 20, cells clipped at the right edge as the "there is more" hint), video duration and "Post video" attribution pills, summary_large_image and summary link cards, one- and two-level quote cards, and polls.

4️⃣ Analytic paint & color emoji. paint/coverage.rs replaces tiny-skia's path AA — four sub-samples per row, 16 coverage levels — with exact horizontal span overlap over 64 vertical sub-rows per pixel, which lands within ≤ 4/255 of analytic area on a circle. Glyphs are unhinted skrifa outlines quantized to Skia's 1/4 px subpixel grid, with the baseline snapped to a whole CSS pixel the way Blink snaps it. Images scale over a premultiplied mipmap pyramid (images.rs). Emoji are Apple sbix PNG strikes (emoji.rs): dupe and flip records are followed, flip toggling a horizontal mirror, the em box is placed at CoreText's [-0.875em .. +0.125em] around the alphabetic baseline, and the strike is resampled with a two-pass premultiplied tent.

What it handles

These are the details that make a preview look like X rather than almost like X. Each item links to the code that implements it and, where there is one, the test that keeps it working.

Text and layout

Emoji and symbols

  • ZWJ, skin-tone, keycap and tag-flag sequences of any length draw as one glyph. The right-facing 🏃‍♂️‍➡️ comes from Apple sbix flip records, mirrored horizontally. (paint/emoji.rs, gallery)
  • VS15 and VS16 choose between text and emoji presentation: © in Chirp or Arial, ©️ in Apple Color Emoji. (fonts.rs)
  • The hairline ✓, ballot boxes, block arrows and chess pieces come from STIX Two Math rather than the brush-stroke Noto Sans Symbols 2, matching Chrome. (tools/sync-upstream.mjs, gallery)
  • Kaomoji built from Box Drawing (┻┳|, ╯) and halfwidth katakana (ノ) fall back to Hiragino Sans, while Simplified/Traditional Chinese (线, 亿, 视) and Korean Hangul (한글) fall through to SIL OFL Noto Sans SC and KR (with XEET_FONT_DIR runtime overrides and visible .notdef tofu boxes for unbundled scripts). (iconic_posts.rs, gallery)

X's client rules

Cards, media and the frame

Resolving links safely

Build

How the tests work

Every layer is compared against something that is not xeet.

Text, against Chrome. tools/oracle/text-parity.mjs lays the same strings out in headless Chrome and in xeet — corpus, fuzz, a 17 px detail set, emoji, bidi, math-styled letters, whitespace — and reports 0 line-break and 0 height mismatches across 13,440 layouts. The committed golden (tests/golden/text.json, 1,260 layouts of our own synthetic strings) lets CI re-check line boxes with no Chrome and no network (tools/ship/parity-check.mjs), widths inside 4/64 px.

Cards, frame, icons, against X's markup. cards-parity.mjs runs 192/192. examples/frame_parity.rs compares every box against geometry replica.mjs captured from X's real markup: 147/147 rows per theme. iconic-parity.mjs takes the four posts people use to break renderers — @NASAGoddard's space field, @MerriamWebster's emoji radio buttons, @MerriamWebster's ┻┳| brick wall, and @pizzahut's dancing figure — at 24/24.

End to end, against the captured site. tools/ship/e2e.mjs renders every post embedded in the captured x.com pages and compares it with Chrome rendering that page: 159/159 in tests/golden/e2e.json, under a 0.5% analytic pixel budget where the platform allows it (Linux) and 3% on macOS, where CoreText's stem darkening is a floor no renderer crosses.

Contracts, text rules, determinism, CI. xeet-text passes all 2,119 twitter-text conformance cases and agrees with the extracted X client code on 3,029 more (crates/xeet-text/tests/). check-contract.mjs keeps the Rust model, the JSON Schema and the MCP tool definitions in one shape; check-unsafe.mjs enforces #![forbid(unsafe_code)]; golden-stamp.mjs rejects a golden that changed without a new oracle stamp; determinism.mjs finds native and WASM SHA-256 identical on 24/24 cases, across Linux x64, Linux arm64 and macOS. The suite gates every push to main in Vercel CI (turbo.json, tools/ship/vercel-build.mjs), while tagged releases verify cross-OS determinism across macOS, Linux, Windows and WASM before publishing via GitHub OIDC Trusted Publishing (.github/workflows/release.yml).

License

The source code in this repository is licensed under the Apache License 2.0: use it, modify it, and redistribute it, keeping the license and attribution notices.

X's Chirp and the platform reference fonts in assets/vendor/fonts/ remain under their respective upstream terms and are not covered by the Apache-2.0 license above. They are vendored here for CI and parity verification. Redistribute public binaries only with fonts you are licensed to ship, or with fonts the host machine supplies.