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.

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.

24 / 280

Downloading WebAssembly core…

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" }));

API #

Rendering methods are synchronous and offline; resolution methods are async and run every request through the fetch you supply.

loadXeet(options?) → Promise<Xeet> #
node.d.ts · node.js

Loads the bundled WebAssembly module and font packs once per Node process; pass { lazy: true } to defer packs.

loadXeetSync(options?) → Xeet #
node.d.ts · node.js

Synchronous counterpart to loadXeet(), returning the same cached renderer.

bind(wasm) → Xeet #
types.d.ts · abi.js

Wraps an initialized wasm-bindgen module for browsers and workers.

xeet.render(post, options?) → RenderResult #
types.d.ts · render.rs

Returns { png, report }: encoded PNG bytes (Uint8Array) and the layout Report.

xeet.renderPng(post, options?) → Uint8Array #
types.d.ts · abi.js

Renders the post and returns only the encoded PNG bytes.

xeet.renderRgba(post, options?) → RgbaResult #
types.d.ts · render.rs

Returns { width, height, rgba, report } as straight-alpha RGBA8 pixels, skipping PNG encoding.

xeet.renderMany(post, optionsList) → BatchItem[] #
types.d.ts · render.rs

Renders one post across multiple option sets as { png, report, paint }[], decoding shared images once.

xeet.explain(post, options?) → Report #
types.d.ts · render.rs

Runs rules and text layout without rasterizing pixels, returning the Report alone.

xeet.hasShowMore(post, options?) → boolean #
types.d.ts · render.rs

Returns true when the post cuts with “Show more” collapsed; pass { expanded: true } to expand it.

xeet.sheet({ post, widths?, themes?, dpr? }) → Uint8Array #
types.d.ts · render.rs

Renders a labeled widths × themes contact sheet into one PNG (defaults: [320, 390, 600] at 2×).

xeet.resolve(input, options?, host?) → Promise<Resolved> #
types.d.ts · xeet-resolve

Turns post text, an x.com status URL, or JSON into { post, links, media, source, warnings }.

xeet.whatwgHost({ fetch?, lookup?, cacheGet?, cacheSet? }) → Host #
types.d.ts · resolve.js

Adapts a WHATWG fetch (plus optional DNS lookup and memoryCache()) into a resolver host.

xeet.upstream : string #
types.d.ts · abi.js

Embedded X web-client revision hash whose stylesheet tokens, Chirp fonts, and rules this build carries.

Render outputs #

types.d.ts:160 · render.rs:220
interface 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
}
interface 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:322
interface 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:16
interface 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:11
class 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