xeet
X posts rendered to PNG without a browser, from WebAssembly, a Rust crate or the CLI.
There’s no browser inside. xeet rebuilds X’s post layout from scratch in Rust.
- X’s own rules. X’s fonts, emoji and line breaking, with its own text shaper, bidi engine and rasterizer.
- Small and fast. A WebAssembly core under 3 MB compressed paints a post in a few milliseconds. Emoji, Japanese, math, Arabic and Hebrew fonts load in parallel as six cached packs.
- Checked against Chrome. Zero line-break differences across 13,440 text layouts, all 192 card layouts matching, and byte-identical PNGs on Linux, macOS and WebAssembly.
Examples #
Post ID 20 (March 21, 2006) — The root post of X: twenty-year timestamp formatting across web and iOS, plus the Square affiliate badge.
Or write a custom quoted post (defaults to @vercel when handle is empty):
Downloading WebAssembly core…
The exact data behind the previews above. Image bytes are shortened here.
Use it #
Pass a post object to render() and get back PNG bytes plus a layout report — synchronous, deterministic, and offline. Starting from an x.com URL instead? Call resolve() first to fetch the post, link cards, and images through your own fetch.
Render a post #
// npm i @xeet/core
import { writeFileSync } from "node:fs";
import { loadXeet, type Post } from "@xeet/core/node";
// Load the WebAssembly module once per process. X's fonts, icons and layout
// rules are compiled into it, so there is nothing else to install.
const xeet = await loadXeet();
// A post is plain JSON. Only `text` is required; everything else is optional,
// and the types say what each field can be.
const post: Post = {
text: "We just shipped the thing. https://vercel.com/blog",
author: {
name: "Vercel",
handle: "vercel",
verified: "business", // gold check; "blue" and "government" also exist
squareAvatar: true, // organizations get square avatars on X
},
counts: { replies: 12, reposts: 148, likes: 2043 },
};
// Rendering is synchronous: text layout, line breaking and painting all
// happen inside this call, with no network and no browser.
const { png, report } = xeet.render(post, {
surface: "web-timeline", // the timeline cell, or "web-detail" for the post page
width: 390, // viewport width in CSS pixels
theme: "dark", // "light" or "dark"
dpr: 2, // device pixel ratio: the PNG is width × dpr wide
});
// `png` is a Uint8Array of PNG bytes. `report` explains what was drawn:
// its size, X's weighted character count, and where the text was cut.
writeFileSync("post.png", png);
console.log(report.size, report.length.weighted, report.text.showMore);
Turn a link into a post #
import { memoryCache } from "@xeet/core/resolve";
// `resolve` accepts post text, an x.com link or post JSON, and returns a
// complete post: t.co redirects followed, link cards read, avatars and
// images downloaded. xeet never opens a connection itself: every request
// goes through the `fetch` you hand it, and results can be cached.
const host = xeet.whatwgHost({ fetch, ...memoryCache() });
const { post, warnings } = await xeet.resolve(
"https://x.com/NASAGoddard/status/928356699043491842",
{ media: true }, // inline the image bytes, so rendering needs no network
host,
);
// From here on it is the same synchronous render as above.
const { png } = xeet.render(post, { width: 390, theme: "light", dpr: 2 });
In the browser #
import init, * as wasm from "/wasm/xeet_wasm.js";
import { bind } from "@xeet/core";
// Fetch and compile the .wasm, then wrap it in the same API as Node.
await init();
const xeet = bind(wasm);
// This page does exactly this: every image above came from render().
const { png } = xeet.render({ text: "rendered in your browser" }, { width: 390, dpr: 2 });
img.src = URL.createObjectURL(new Blob([png], { type: "image/png" }));
Add the crates #
# Cargo.toml: the renderer, and the resolver with its default network stack
[dependencies]
xeet-core = { git = "https://github.com/rauchg/xeet" }
xeet-resolve = { git = "https://github.com/rauchg/xeet" }
xeet-resolve-net = { git = "https://github.com/rauchg/xeet" }
serde_json = "1"
Render a post #
use xeet_core::model::{Post, RenderOptions, Surface, Theme};
use xeet_core::render;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// The same JSON shape as everywhere else; only `text` is required.
let post: Post = serde_json::from_str(r#"{
"text": "We just shipped the thing.",
"author": { "name": "Vercel", "handle": "vercel", "verified": "business" }
}"#)?;
let options = RenderOptions {
surface: Surface::WebTimeline,
width: 390.0, // viewport width in CSS pixels
theme: Theme::Dark,
dpr: 2.0, // the PNG is width × dpr wide
..RenderOptions::default()
};
// In-process and synchronous: no network, no browser, no font files.
let (png, report) = render::render(&post, &options)?;
std::fs::write("post.png", png)?;
println!("{} × {}", report.size.width, report.size.height);
Ok(())
}
Just the layout #
// Every box, line and glyph position, before anything is painted: useful for
// testing, or for drawing with your own rasterizer.
let (display_list, report) = render::display_list(&post, &options)?;
// Or only the decisions: weighted length, visible text, where it was cut.
let report = render::explain(&post, &options)?;
Install #
# A native binary for macOS, Linux and Windows, fonts included
npm i -g @xeet/cli
# Or build it from source
cargo install --git https://github.com/rauchg/xeet xeet-cli
Render #
# A post is JSON, from a file or stdin; only "text" is required
echo '{"text":"hello from the command line"}' | xeet render - -o post.png
# Pick the view, width, theme and pixel density
xeet render post.json --surface web-detail --width 390 --theme dark --dpr 3 -o post.png
# Every width and theme in one labelled image
xeet sheet post.json --widths 320,390,600 --themes light,dark -o sheet.png
From a link #
# Fetch a post with its avatar, images and link cards, then render it
xeet resolve https://x.com/NASAGoddard/status/928356699043491842 --media | xeet render - -o nasa.png
# Or keep the resolved JSON to edit and render later
xeet resolve https://x.com/NASAGoddard/status/928356699043491842 --media > nasa.json
Explain #
# What would be drawn, as JSON, without painting a pixel
xeet explain post.json
API #
Rendering methods are synchronous and offline; resolution methods are async and run every request through the fetch you supply.
Loads the bundled WebAssembly module and font packs once per Node process; pass { lazy: true } to defer packs.
Synchronous counterpart to loadXeet(), returning the same cached renderer.
Wraps an initialized wasm-bindgen module for browsers and workers.
Returns { png, report }: encoded PNG bytes (Uint8Array) and the layout Report.
Renders the post and returns only the encoded PNG bytes.
Returns { width, height, rgba, report } as straight-alpha RGBA8 pixels, skipping PNG encoding.
Renders one post across multiple option sets as { png, report, paint }[], decoding shared images once.
Runs rules and text layout without rasterizing pixels, returning the Report alone.
Returns true when the post cuts with “Show more” collapsed; pass { expanded: true } to expand it.
Renders a labeled widths × themes contact sheet into one PNG (defaults: [320, 390, 600] at 2×).
Turns post text, an x.com status URL, or JSON into { post, links, media, source, warnings }.
Crawls one URL as Twitterbot/1.0 and returns its card metadata, redirect hops, and optional image.
Adapts a WHATWG fetch (plus optional DNS lookup and memoryCache()) into a resolver host.
Embedded X web-client revision hash whose stylesheet tokens, Chirp fonts, and rules this build carries.
Render outputs #
types.d.ts:160 · render.rs:220interface RenderResult {
png: Uint8Array; // encoded PNG (report.size × dpr device pixels)
report: Report;
}
interface RgbaResult {
width: number; // device pixels
height: number; // device pixels
rgba: Uint8Array; // straight-alpha RGBA8 (width × height × 4 bytes)
report: Report;
}
interface BatchItem {
png: Uint8Array;
report: Report;
paint: number; // render duration in ms
}
Report #
types.d.ts:134 · model.rs:275interface Report {
ruleset: string; // e.g. "x-web@55591fe0"
verifiedFor: Surface[];
size: { // layout box in CSS pixels
width: number;
height: number;
};
length: { // URL = 23, emoji/CJK = 2, limit = 280
weighted: number;
limit: number;
valid: boolean;
};
text: {
lines: number;
truncated: boolean;
hasShowMore: boolean;
showMore: "inline" | "clamped" | null; // web cut vs. iOS 9-line clamp
visible: string;
};
entities: { // UTF-16 [start, end] offsets
kind: "url" | "mention" | "hashtag" | "cashtag";
range: [number, number];
text: string;
display?: string;
}[];
hidden: { range: [number, number]; why: string }[];
attachment: {
shown: "card" | "media" | "quote" | "poll";
url?: string | null;
why: string;
} | null;
warnings: string[];
}
Resolved & ResolvedLink #
types.d.ts:267 · xeet-resolve/lib.rs:322interface Resolved {
post: Post; // ready for xeet.render(post, opts)
links: Record<string, ResolvedLink>; // keyed by URL in post.text
media: Record<string, MediaAsset>; // fetched assets keyed by CDN URL
source: {
url: string | null;
id: string | null;
appVersion: string | null;
pinned: boolean;
};
warnings: string[];
}
interface ResolvedLink {
meta: LinkMeta;
chain: { url: string; status: number }[];
finalUrl: string;
tags: Record<string, string>;
imageUrl: string | null;
image?: MediaAsset; // populated when { media: true }
notes: string[];
cached: boolean;
}
RenderOptions & Post #
types.d.ts:9 · model.rs:16interface RenderOptions {
surface?: "web-timeline" | "web-detail" | "ios-timeline" | "ios-detail";
width?: number; // 100..1200 CSS px (column ≤ 600), default 600
theme?: "light" | "dark"; // default "light"
dpr?: number; // 1..4, default 2
fontScale?: number; // default 1
expanded?: boolean; // expand "Show more" in place, default false
}
interface Post {
text: string; // only required field
author?: Author; // { name?, handle?, verified?, avatar?, ... }
media?: Media[]; // up to 20 items ({ kind, width, height, data? })
links?: Record<string, LinkMeta>;
quote?: Post; // nests up to 2 levels deep
poll?: Poll; // { choices, votes?, secondsLeft? }
counts?: Counts; // { replies?, reposts?, likes?, views?, bookmarks? }
createdAt?: string; // ISO 8601
now?: string; // ISO 8601 reference clock
cardState?: "auto" | "dismissed";
}
Errors & CLI exit codes #
types.d.ts:316 · render.rs:50 · commands/mod.rs:11class XeetError extends Error {
readonly code: string; // "invalid_post" | "invalid_json" | "text_too_long"
readonly status: number; // 400 | 413 | 500 | 503 (ResolveError uses 502)
readonly fields: { path: string; message: string; suggestion?: string }[];
readonly notes: string[];
}
// CLI exit codes: 0 ok · 2 usage · 3 invalid input · 4 render failed · 5 I/O