Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
LR10: the harness: the runs both sides make, and a Chrome that renders. An inline <svg>'s words are runs of their own, one per <text>, in the render manifest (from the svg's usvg tree, mapped onto the page) and in boxes.ts, where they had fallen into the nearest html box: drop-line's 'then ships the film t h e n t h e n'. Words hidden by visibility, a measuring copy, are skipped on Chrome's side as the manifest skips them. Chrome renders each frame in real time through Playwright (bench/layout-reads/chrome.ts, the same pinned Chrome for Testing): a headless --dump-dom under --virtual-time-budget runs no rendering step, so a component's requestAnimationFrame and ResizeObserver never ran on Chrome's side. probes/document.tsx (getComputedStyle, svg text, a Range, a node made and measured, word- and letter-spacing) and probes/observe.tsx (ResizeObserver) are new
shinyobjectz203c26621c58
diff --git a/Cargo.lock b/Cargo.lockindex 59fcaa80..31218599 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -14855,6 +14855,7 @@ dependencies = ["blitz-dom","raea-native","raea-sys-canvas",+ "raea-sys-fonts","serde_json",]diff --git a/bench/layout-reads/boxes.ts b/bench/layout-reads/boxes.tsindex cd0e2a3f..cb369767 100644--- a/bench/layout-reads/boxes.ts+++ b/bench/layout-reads/boxes.ts@@ -23,9 +23,13 @@ export function runs(root: Element): Run[] {for (let n = walk.nextNode() as Text | null; n; n = walk.nextNode() as Text | null) {if (!n.data || !n.parentElement) continue;if (n.parentElement.closest("style, script")) continue;- let up: Element | null = n.parentElement;- while (up && (getComputedStyle(up).display.startsWith("inline") || !sized(up))) up = up.parentElement;- if (!up || alpha(n.parentElement) <= 0.01) continue;+ // an svg's words belong to their <text>, as the manifest has them (the page draws an svg as one picture, usvg's)+ const svgText = n.parentElement.closest("svg text");+ let up: Element | null = svgText ?? n.parentElement;+ if (svgText && !sized(svgText)) continue;+ while (!svgText && up && (getComputedStyle(up).display.startsWith("inline") || !sized(up))) up = up.parentElement;+ // hidden words (a measuring copy under opacity 0 or visibility: hidden) aren't on the frame, as the manifest has it+ if (!up || alpha(n.parentElement) <= 0.01 || getComputedStyle(n.parentElement).visibility !== "visible") continue;owned.set(up, [...(owned.get(up) ?? []), n]);}const out: Run[] = [];@@ -46,7 +50,8 @@ export function runs(root: Element): Run[] {}}const run: Run = { text, box: [r(b.x), r(b.y), r(b.width), r(b.height)] };- if (x1 > x0) run.ink = [r(x0), r(b.y), r(x1 - x0), r(b.height)];+ if (owner.closest("svg")) run.ink = run.box;+ else if (x1 > x0) run.ink = [r(x0), r(b.y), r(x1 - x0), r(b.height)];out.push(run);}return out;diff --git a/bench/layout-reads/check.sh b/bench/layout-reads/check.shindex de0857eb..513db67d 100755--- a/bench/layout-reads/check.sh+++ b/bench/layout-reads/check.sh@@ -104,12 +104,10 @@ EOFprintf '<!doctype html><meta charset=utf-8><body style="background:#000"><div id=root></div><script type=module src="/lr/%s.js"></script>' "$n" > "$L/$n.html"line="" ok=1[ $rr = 0 ] && [ -z "$threw" ] || ok=0+ # Chrome renders each frame in real time (chrome.ts), so its requestAnimationFrame and ResizeObserver run+ bun "$BENCH/chrome.ts" "$CH" "http://127.0.0.1:$PORT/lr/$n.html" "$width" "$height" "$D" "${frames[@]}" > "$D/chrome.log" 2>&1for i in 0 1 2; dof=${frames[$i]}- url="http://127.0.0.1:$PORT/lr/$n.html"- "$CH" --headless --hide-scrollbars --window-size="$width,$height" --virtual-time-budget=8000 --screenshot="$D/chrome-$f.png" "$url#$f" > /dev/null 2>&1- "$CH" --headless --hide-scrollbars --window-size="$width,$height" --virtual-time-budget=8000 --dump-dom "$url#$f,dump" 2> /dev/null \- | sed -n 's/.*<script type="application\/json" id="lr-runs">\(.*\)<\/script>.*/\1/p' > "$D/chrome-$f.json"r=$D/raea/frame-0000$i.pngif [ $rr != 0 ] || [ ! -f "$r" ]; then line="$line @$f no frame"; ok=0; continue; fi[ -s "$D/chrome-$f.json" ] || { line="$line @$f no Chrome runs"; ok=0; continue; }diff --git a/bench/layout-reads/chrome.ts b/bench/layout-reads/chrome.tsnew file mode 100644index 00000000..b84d3779--- /dev/null+++ b/bench/layout-reads/chrome.ts@@ -0,0 +1,28 @@+// The Chrome side's frames (check.sh): the pinned Chrome for Testing, driven by Playwright, renders the composition's+// page at each frame in real time, so requestAnimationFrame and ResizeObserver run as they do in a browser (a headless+// --dump-dom under --virtual-time-budget runs neither: no rendering step ever comes). Each frame's page is loaded with+// `#FRAME,dump`; once boxes.ts's runs are on it (the page adds them a second after its fonts are ready), they're written+// to OUT/chrome-FRAME.json and the page to OUT/chrome-FRAME.png.+// bun bench/layout-reads/chrome.ts CHROME URL WIDTH HEIGHT OUT FRAME...++import { writeFileSync } from "node:fs";+import { chromium } from "../../apps/app/node_modules/@playwright/test";++const [exe, url, w, h, out, ...frames] = process.argv.slice(2);+if (!exe || !url || !out || !frames.length) {+ console.error("usage: chrome.ts CHROME URL WIDTH HEIGHT OUT FRAME...");+ process.exit(2);+}+const browser = await chromium.launch({ executablePath: exe, args: ["--hide-scrollbars"] });+try {+ for (const f of frames) {+ const page = await browser.newPage({ viewport: { width: Number(w), height: Number(h) } });+ await page.goto(`${url}#${f},dump`);+ const runs = await page.waitForSelector("#lr-runs", { state: "attached", timeout: 30000 }).then((s) => s.textContent());+ writeFileSync(`${out}/chrome-${f}.json`, runs ?? "");+ await page.screenshot({ path: `${out}/chrome-${f}.png` });+ await page.close();+ }+} finally {+ await browser.close();+}diff --git a/bench/layout-reads/probes/document.tsx b/bench/layout-reads/probes/document.tsxnew file mode 100644index 00000000..fd6c15af--- /dev/null+++ b/bench/layout-reads/probes/document.tsx@@ -0,0 +1,91 @@+// LR5 and LR7's reads as a probe (docs/layout-reads.feature): getComputedStyle, an svg <text>'s measures, a Range over a+// text node, and a node made with document.createElement and measured. Each length read places a word (its left at the+// value), so the harness's 1 px box check holds it to Chrome's; a computed value is printed as words, which must match.+import { AbsoluteFill } from "raea";+import { loadFont } from "raea/text";+import { useLayoutEffect, useRef, useState } from "react";++const { fontFamily } = loadFont("Inter");++export const conf = { width: 640, height: 360, fps: 30, durationInFrames: 3 };+export const props = {};++type Read = { size: string; weight: string; color: string; len: number; tracked: number; third: number; range: number; prefix: number; made: number };++export function Comp() {+ const styled = useRef<HTMLDivElement>(null);+ const svg = useRef<SVGTextElement>(null);+ const tracked = useRef<SVGTextElement>(null);+ const span = useRef<HTMLSpanElement>(null);+ const [r, setR] = useState<Read | null>(null);+ useLayoutEffect(() => {+ const cs = getComputedStyle(styled.current!);+ const t = svg.current!;+ const node = span.current!.firstChild!;+ const range = document.createRange();+ range.selectNodeContents(node);+ const whole = range.getBoundingClientRect().width;+ range.setStart(node, 0);+ range.setEnd(node, 5);+ const prefix = range.getBoundingClientRect().width;+ // a hidden copy made, measured and removed+ const m = document.createElement("span");+ m.style.fontFamily = fontFamily;+ m.style.fontSize = "40px";+ m.style.position = "absolute";+ m.textContent = "measured copy";+ document.body.appendChild(m);+ const made = m.getBoundingClientRect().width;+ m.remove();+ setR({+ size: cs.fontSize,+ weight: cs.getPropertyValue("font-weight"),+ color: cs.color,+ len: t.getComputedTextLength(),+ tracked: tracked.current!.getComputedTextLength(),+ third: t.getStartPositionOfChar(3).x,+ range: whole,+ prefix,+ made,+ });+ }, []);+ const at = (left: number, top: number, word: string) => (+ <div style={{ position: "absolute", left, top, fontSize: 16, lineHeight: "20px" }}>{word}</div>+ );+ return (+ <AbsoluteFill style={{ background: "#fff", color: "#111", fontFamily }}>+ <div ref={styled} style={{ position: "absolute", left: 20, top: 300, fontSize: 18, fontWeight: 600, color: "#3355aa" }}>+ styled+ </div>+ <svg width={640} height={360} style={{ position: "absolute", left: 0, top: 0 }}>+ <g opacity={0}>+ <text ref={svg} x={10} y={40} style={{ fontFamily, fontSize: 36 }}>+ Hidden width+ </text>+ <text ref={tracked} x={10} y={80} style={{ fontFamily, fontSize: 36, letterSpacing: 4 }}>+ Tracked+ </text>+ </g>+ </svg>+ {/* spacing as text-select sets its line: ink across the words, against Chrome's */}+ <div style={{ position: "absolute", left: 200, top: 230, fontSize: 32, wordSpacing: "-0.07em" }}>word gaps tight here</div>+ <div style={{ position: "absolute", left: 200, top: 270, fontSize: 32, wordSpacing: "-0.07em", letterSpacing: "-0.012em" }}>+ tracked and tight+ </div>+ <span ref={span} style={{ position: "absolute", left: 20, top: 330, fontSize: 24, whiteSpace: "pre" }}>+ Range over words+ </span>+ {r && (+ <>+ {at(r.len, 10, "svglength")}+ {at(r.tracked, 40, "tracked")}+ {at(r.third, 70, "third")}+ {at(r.range, 100, "range")}+ {at(r.prefix, 130, "prefix")}+ {at(r.made, 160, "made")}+ {at(20, 200, `computed ${r.size} ${r.weight} ${r.color}`)}+ </>+ )}+ </AbsoluteFill>+ );+}diff --git a/bench/layout-reads/probes/observe.tsx b/bench/layout-reads/probes/observe.tsxnew file mode 100644index 00000000..e293ec40--- /dev/null+++ b/bench/layout-reads/probes/observe.tsx@@ -0,0 +1,50 @@+// LR8's ResizeObserver as a probe (docs/layout-reads.feature): a box observed while its words change size. The+// observer's first call (on observe) and its call after the words grow each place a word at the width they report, so+// the harness's 1 px box check holds them to Chrome's; the frame is held until the second call, so both sides compare+// the frame after it. MutationObserver and IntersectionObserver are made, and must not throw.+import { AbsoluteFill, continueRender, delayRender } from "raea";+import { loadFont } from "raea/text";+import { useEffect, useLayoutEffect, useRef, useState } from "react";++const { fontFamily } = loadFont("Inter");++export const conf = { width: 640, height: 240, fps: 30, durationInFrames: 3 };+export const props = {};++type Seen = { content: number; border: number; height: number };++export function Comp() {+ const [handle] = useState(() => delayRender("resize observed"));+ const [words, setWords] = useState("short");+ const [seen, setSeen] = useState<Seen[]>([]);+ const box = useRef<HTMLDivElement>(null);+ useLayoutEffect(() => {+ const ro = new ResizeObserver((entries) => {+ const e = entries[0]!;+ setSeen((s) => [...s, { content: e.contentRect.width, border: e.borderBoxSize[0]!.inlineSize, height: e.contentBoxSize[0]!.blockSize }]);+ });+ ro.observe(box.current!);+ new MutationObserver(() => {}).observe(box.current!, { childList: true });+ new IntersectionObserver(() => {}).observe(box.current!);+ return () => ro.disconnect();+ }, []);+ useEffect(() => {+ if (seen.length === 1) setWords("a good deal longer now");+ if (seen.length >= 2) continueRender(handle);+ }, [seen, handle]);+ const at = (left: number, top: number, word: string) => (+ <div style={{ position: "absolute", left, top, fontSize: 16, lineHeight: "20px" }}>{word}</div>+ );+ const [a, b] = [seen[0], seen[1]];+ return (+ <AbsoluteFill style={{ background: "#fff", color: "#111", fontFamily }}>+ <div ref={box} style={{ position: "absolute", left: 20, top: 20, padding: 8, border: "3px solid #888", fontSize: 28 }}>+ {words}+ </div>+ {a && at(a.content, 100, "first")}+ {a && at(a.border, 130, "firstborder")}+ {b && at(b.content, 160, "second")}+ {b && at(b.height * 4, 190, "height")}+ </AbsoluteFill>+ );+}diff --git a/engine/page/Cargo.toml b/engine/page/Cargo.tomlindex 330aeb2e..109e6094 100644--- a/engine/page/Cargo.toml+++ b/engine/page/Cargo.toml@@ -30,6 +30,8 @@ raea-core-wire = { path = "../../core/wire" }# the GPU canary, bump and memory checks, and refusalsraea-gpu-device = { path = "../../gpu/device" }serde_json = "1"+# an inline svg's <text>s, as usvg set them (the render manifest's runs, layout-reads LR10)+usvg = { version = "=0.48.1", default-features = false, features = ["text"] }# HTML files parsed by Blitz (motion.rs open_html: an HTML page, WPT's tests), and their URLsblitz-html = "=0.3.0-beta.4"url = "2"diff --git a/engine/page/src/motion/manifest.rs b/engine/page/src/motion/manifest.rsindex 2f3be823..8f83dd01 100644--- a/engine/page/src/motion/manifest.rs+++ b/engine/page/src/motion/manifest.rs@@ -25,6 +25,19 @@ impl BlitzPage {if node.is_element() && matches!(node.element_data().map(|e| &*e.name.local), Some("style" | "script")) {continue;}+ // an inline <svg> is drawn as one picture (usvg's): its <text>s are runs of their own, where usvg set them+ if let Some(tree) = node.element_data().and_then(|e| e.svg_data()) {+ if let (Some(b), a) = (rect(n), alpha(n)) {+ let (sx, sy) = (b.width / tree.size().width().max(1e-6) as f64, b.height / tree.size().height().max(1e-6) as f64);+ for (words, t, o) in svg_runs(tree.root(), a) {+ let bb = [r(b.x + t.x() as f64 * sx), r(b.y + t.y() as f64 * sy), r(t.width() as f64 * sx), r(t.height() as f64 * sy)];+ let mut v = json!({"text": words, "box": bb, "ink": bb, "opacity": (o * 100.0).round() / 100.0, "svg": true});+ stamps(n, &mut v);+ text.push(v);+ }+ }+ continue;+ }stack.extend(node.children.iter().rev().copied());if let Some(src) = node.attr(LocalName::from("data-raea-src")) {let a = alpha(n);@@ -209,6 +222,29 @@ fn stamps(doc: &blitz_dom::BaseDocument, n: blitz_dom::NodeId, entry: &mut serde}}+/// An svg's shown <text>s, in document order: each one's words (as [`run_text`] joins its chunks), its box in the+/// svg's canvas, and its opacity times its groups' (from `a`, the svg element's own). One under 0.01 isn't shown.+fn svg_runs(g: &usvg::Group, a: f64) -> Vec<(String, usvg::Rect, f64)> {+ let a = a * g.opacity().get() as f64;+ let mut out = Vec::new();+ if a <= 0.01 {+ return out;+ }+ for c in g.children() {+ match c {+ usvg::Node::Group(g) => out.extend(svg_runs(g, a)),+ usvg::Node::Text(t) => {+ let pieces: Vec<String> = t.chunks().iter().map(|c| c.text().to_string()).collect();+ if let Some(words) = run_text(&pieces) {+ out.push((words, t.abs_bounding_box(), a));+ }+ }+ _ => {}+ }+ }+ out+}+/// A run's words from its text nodes, in order: joined by a space, as caption words set one a span are; or, when every/// one is a single letter (a word revealed letter by letter, its spaces spans of their own), as the letters read/// ("49 BC", not "4 9 B C"). None when the run is only white space.