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
LR3: a composition's refs have the geometry a web component reads, from the page that draws the frame: getBoundingClientRect (a DOMRect, transforms included), getClientRects, offset* and offsetParent (untransformed, whole px, from the positioned ancestor's padding edge), client* and scroll*, each as Chrome answers it. bevy-react 0.8.1 gets a patch (sdk/react/js/patches, applied by bun install) that makes its instances a tree, BevyElement and BevyTextNode with their parent, children and committed props; sdk/raea's dom-reads puts the reads on BevyElement from the entry. #54's repro now puts "here" where Chrome does (x 342, was 0), and probes/geometry.tsx prints every read and matches Chrome's words. The bundle crate's stylesheet url() rewriter moves to raea-runtime-cssurls to leave it under 2000 lines
shinyobjectz2d869d719b2c
diff --git a/Cargo.lock b/Cargo.lockindex 741c22ae..51cfa5ee 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -14808,6 +14808,7 @@ dependencies = ["raea-io-media","raea-native","raea-runtime-bundle-lib",+ "raea-runtime-cssurls","raea-sys-layers","regex","serde_json",@@ -14846,6 +14847,14 @@ dependencies = ["serde_json",]+[[package]]+name = "raea-runtime-cssurls"+version = "0.1.0"+dependencies = [+ "raea-core-scene",+ "raea-io-home",+]+[[package]]name = "raea-runtime-dom"version = "0.1.0"diff --git a/Cargo.toml b/Cargo.tomlindex 43366583..c697a804 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -138,6 +138,7 @@ members = ["runtime/react","runtime/track","runtime/pagestore",+ "runtime/cssurls","bench/bridge","bench/bevy-parity","bench/bridge/swatch",diff --git a/bench/layout-reads/check.sh b/bench/layout-reads/check.shindex efb355f9..de0857eb 100755--- a/bench/layout-reads/check.sh+++ b/bench/layout-reads/check.sh@@ -52,6 +52,7 @@ mkdir -p "$O"PORT=$((20000 + RANDOM % 20000))python3 -m http.server $PORT --bind 127.0.0.1 --directory "$C" > /dev/null 2>&1 &SRV=$!+disown $SRV 2> /dev/null # (its kill at the end says nothing)if [ -n "${KEEP:-}" ]; then trap 'kill $SRV 2> /dev/null' EXIT; else trap 'kill $SRV 2> /dev/null; rm -rf "$O"' EXIT; fipass=0 fail=0diff --git a/bench/layout-reads/probes/geometry.tsx b/bench/layout-reads/probes/geometry.tsxnew file mode 100644index 00000000..e751ab16--- /dev/null+++ b/bench/layout-reads/probes/geometry.tsx@@ -0,0 +1,52 @@+// LR3's reads as a probe (docs/layout-reads.feature): each value a ref reads is printed as words, so the harness's+// pairing by words fails on any value that differs from Chrome's. Covers getBoundingClientRect under a transform,+// offset* (untransformed, from the positioned offsetParent's padding edge), client* (padding box, 0 for an inline+// span) and scroll* of a scroller.+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 = {};++const r = (v: number) => Math.round(v * 10) / 10;++export function Comp() {+ const card = useRef<HTMLDivElement>(null);+ const turned = useRef<HTMLDivElement>(null);+ const word = useRef<HTMLSpanElement>(null);+ const scroller = useRef<HTMLDivElement>(null);+ const [lines, setLines] = useState<string[]>([]);+ useLayoutEffect(() => {+ const c = card.current!, t = turned.current!, w = word.current!, s = scroller.current!;+ const b = t.getBoundingClientRect();+ setLines([+ `card offset ${c.offsetLeft} ${c.offsetTop} ${c.offsetWidth} ${c.offsetHeight}`,+ `card client ${c.clientLeft} ${c.clientTop} ${c.clientWidth} ${c.clientHeight}`,+ `turned rect ${r(b.x)} ${r(b.y)} ${r(b.width)} ${r(b.height)}`,+ `turned offset ${t.offsetLeft} ${t.offsetTop} ${t.offsetWidth} ${t.offsetHeight} parent ${t.offsetParent === c ? "card" : "other"}`,+ `word offset ${w.offsetWidth} ${w.offsetHeight} client ${w.clientWidth}`,+ `scroller ${s.scrollWidth} ${s.scrollHeight} ${s.clientHeight}`,+ ]);+ }, []);+ return (+ <AbsoluteFill style={{ background: "#fff", color: "#111", fontFamily, fontSize: 14 }}>+ <div ref={card} style={{ position: "absolute", left: 24, top: 20, width: 260, height: 120, padding: 10, border: "3px solid #333" }}>+ <div ref={turned} style={{ position: "absolute", left: 40, top: 30, width: 100, height: 40, background: "#c33", transform: "rotate(30deg)" }} />+ <span ref={word} style={{ fontSize: 22 }}>+ measure me+ </span>+ </div>+ <div ref={scroller} style={{ position: "absolute", left: 340, top: 20, width: 200, height: 80, overflow: "hidden" }}>+ <div style={{ width: 300, height: 260, background: "#ddd" }} />+ </div>+ <div style={{ position: "absolute", left: 24, top: 180 }}>+ {lines.map((l) => (+ <div key={l}>{l}</div>+ ))}+ </div>+ </AbsoluteFill>+ );+}diff --git a/docs/layout-reads.feature b/docs/layout-reads.featureindex ff26bbc6..22107ba7 100644--- a/docs/layout-reads.feature+++ b/docs/layout-reads.feature@@ -126,7 +126,7 @@ Feature: Layout reads: a composition measures its text and layout as Chrome doesRule: a ref has the DOM a web component reads- @needs:LR1+ @needs:LR1 @doneScenario: LR3. Geometry on refsThen a ref's element has getBoundingClientRect() (a DOMRect: x, y, width, height, top, left, right, bottom andtoJSON) and getClientRects()@@ -134,7 +134,22 @@ Feature: Layout reads: a composition measures its text and layout as Chrome doesclientLeft and clientTop; scrollWidth, scrollHeight, scrollLeft and scrollTopAnd each value means what it means in Chrome: getBoundingClientRect includes transforms, offset* doesn't, andboth are in the composition's CSS px- And #54's repro logs `335 function`, as Chrome does+ And #54's repro measures its span as Chrome does (the issue's `335` was its own font; with the harness's Inter+ both put "here" at x 342)+ And 11-12, built:+ - bevy-react 0.8.1 gets a patch (sdk/react/js/patches, applied by bun install). Its instances become a tree:+ BevyElement and BevyTextNode, with parentNode, childNodes, props and text as React last committed them.+ That gives refs a class to carry the DOM, and it's LR4's tree.+ - sdk/raea/src/dom-reads.ts puts the reads on BevyElement's prototype, from the entry, as canvas2d.ts+ installs the 2D context. The values are Chrome's: offset*, client* and scroll* are whole px, a+ non-atomic inline's client* and scroll* are 0, an element that isn't displayed reads 0 with a null+ offsetParent, and offsetParent is the nearest positioned ancestor or the composition's root for the body.+ - getClientRects answers one rect, so an inline element's line fragments come joined. Per-line rects come+ with LR7's Range.+ - bench/layout-reads/probes/geometry.tsx prints every read as words, and they match Chrome's: offset, client+ and border of a padded, bordered box; the bounds of a rotated box; the offsets and offsetParent of a box+ inside it; a span's offsets with client 0; and a scroller's scroll sizes.+ - The bundle crate was at its 2000-line limit: the stylesheet url() rewriter moved to raea-runtime-cssurls.Scenario: LR4. The tree on refsThen a ref's element has children, childNodes, firstChild, lastChild, firstElementChild, lastElementChild,diff --git a/runtime/bundle/Cargo.toml b/runtime/bundle/Cargo.tomlindex 2367656d..da455e60 100644--- a/runtime/bundle/Cargo.toml+++ b/runtime/bundle/Cargo.toml@@ -15,6 +15,8 @@ modules = ["raea-native/modules"]dunce = "1"# raea's home (the checkout's, or an install's share/raea): the SDK packages, the bundler's library, Tailwind's packageraea-io-home = { path = "../../io/home" }+# a stylesheet's url()s as the page reads them (#28), its own crate+raea-runtime-cssurls = { path = "../../runtime/cssurls" }raea-core-scene = { path = "../../core/scene" }raea-native = { path = "../../engine/native", default-features = false }# an imported long-GOP source's optimized copy, named in the export cache's key (its probe: AVFoundation on Apple, thediff --git a/runtime/bundle/src/entry.rs b/runtime/bundle/src/entry.rsindex b6b30f1e..74013124 100644--- a/runtime/bundle/src/entry.rs+++ b/runtime/bundle/src/entry.rs@@ -13,9 +13,13 @@ pub fn entry(file: &str, o: &CompOpts) -> String {format!(r#"import {{ frameCallbacks, pureAgain, pureFrame, pureSession, seedOf }} from "./motion/pure";import {{ canvas2d }} from "./motion/canvas2d";+import * as BevyReact from "bevy-react";import {{ mount, addEventListener, BevyCanvasElement }} from "bevy-react";canvas2d(BevyCanvasElement); // a <canvas> ref's getContext("2d") is the web's (motion canvas2d.ts, #55)-import "./motion/page-layout"; // a composition reads its layout from its frame's page (page.layout, docs/layout-reads.feature LR1)+// a ref has the DOM a web component reads (getBoundingClientRect, offsetWidth ...), from the frame's page (page.layout):+// on bevy-react's BevyElement, which raea's patch adds (a bridge without it keeps plain handles; layout-reads LR1, LR3)+import {{ domReads }} from "./motion/dom-reads";+domReads((BevyReact as any).BevyElement);import {{ Component, useEffect, useMemo, useState }} from "react";import * as M from "./src/{file}";import {{ Clock, getCompositions, tickClocks }} from "./motion";diff --git a/runtime/bundle/src/lib.rs b/runtime/bundle/src/lib.rsindex 560e60bb..167f4748 100644--- a/runtime/bundle/src/lib.rs+++ b/runtime/bundle/src/lib.rs@@ -15,13 +15,12 @@ mod outside;mod pid;mod rewrite;pub mod styles;-mod urls;pub use cache::*;pub use entry::*;pub use fresh::*;pub use outside::*;pub use rewrite::*;-pub use urls::*;+pub use raea_runtime_cssurls::*;pub use raea_core_scene::media_path;#[cfg(test)]mod tests;@@ -41,7 +40,7 @@ pub fn brand_css(dir: &Path, w: u32) -> Option<String> {let f = here.join("brand").join("brand.css");if let Ok(css) = std::fs::read_to_string(&f) {let kept: Vec<&str> = css.lines().filter(|l| !l.trim_start().starts_with("@import")).collect();- // its fonts and images as files: /media/ from the edit, the rest from brand/ (urls.rs)+ // its fonts and images as files: /media/ from the edit, the rest from brand/ (raea-runtime-cssurls)let kept = css_file_urls(&kept.join("\n"), dir, &here.join("brand"), |_| ());return Some(format!("{kept}\n:root {{ --brand-scale: {}; }}\n", 2.5 * w as f64 / 1080.0));}@@ -59,7 +58,7 @@ pub fn bundle_css(js: &str) -> Option<String> {/// A page's own CSS: the space's brand kit (brand_css), then the CSS the bundle `js` imported (bundle_css)pub fn page_css(dir: &Path, w: u32, js: &Path) -> Option<String> {- // its url()s as files from the edit's folder (urls.rs), where the CSS files it imports are found+ // its url()s as files from the edit's folder (raea-runtime-cssurls), where the CSS files it imports are foundlet bundled = std::fs::read_to_string(js).ok().and_then(|t| bundle_css(&t)).map(|c| css_file_urls(&c, dir, dir, |_| ()));// then the layers RAEA_HIDE_LAYERS hides (the layer pass's oracle)let parts: Vec<String> = [brand_css(dir, w), bundled, raea_sys_layers::hidden_css()].into_iter().flatten().collect();diff --git a/runtime/cssurls/Cargo.toml b/runtime/cssurls/Cargo.tomlnew file mode 100644index 00000000..7e327975--- /dev/null+++ b/runtime/cssurls/Cargo.toml@@ -0,0 +1,12 @@+[package]+name = "raea-runtime-cssurls"+version = "0.1.0"+edition = "2024"+description = "A stylesheet's url()s that name a composition's files, written as the page reads them (a file URL on Windows, #28)"+license = "FSL-1.1-ALv2"++[dependencies]+# raea_io_home::src: a path on the Mac and Linux, a file URL on Windows+raea-io-home = { path = "../../io/home" }+# media_path: /media/ from the edit's folder+raea-core-scene = { path = "../../core/scene" }diff --git a/runtime/bundle/src/urls.rs b/runtime/cssurls/src/lib.rssimilarity index 100%rename from runtime/bundle/src/urls.rsrename to runtime/cssurls/src/lib.rsdiff --git a/sdk/raea/src/dom-reads.ts b/sdk/raea/src/dom-reads.tsnew file mode 100644index 00000000..6e94183f--- /dev/null+++ b/sdk/raea/src/dom-reads.ts@@ -0,0 +1,131 @@+// Geometry on a composition's refs (docs/layout-reads.feature LR3, #54): what a web component reads off an element, read+// from the page that draws the frame (page-layout.ts). Installed from the entry on bevy-react's BevyElement, the class+// every ref holds (raea's patch), as canvas2d.ts installs the 2D context on BevyCanvasElement.+// Each value means what it means in Chrome, in the composition's CSS px: getBoundingClientRect includes transforms,+// offset* doesn't (and is whole px, from the offsetParent's padding edge), client* is the padding box, scroll* the+// scrolled content.++import { boxOf, type Box } from "./page-layout";++/** The web's DOMRect, as getBoundingClientRect answers it. */+export class DOMRect {+ constructor(+ public x = 0,+ public y = 0,+ public width = 0,+ public height = 0,+ ) {}+ get left() {+ return Math.min(this.x, this.x + this.width);+ }+ get top() {+ return Math.min(this.y, this.y + this.height);+ }+ get right() {+ return Math.max(this.x, this.x + this.width);+ }+ get bottom() {+ return Math.max(this.y, this.y + this.height);+ }+ toJSON() {+ const { x, y, width, height, top, right, bottom, left } = this;+ return { x, y, width, height, top, right, bottom, left };+ }+ static fromRect(r: { x?: number; y?: number; width?: number; height?: number } = {}) {+ return new DOMRect(r.x, r.y, r.width, r.height);+ }+}++type El = { id: number; parentNode: El | null; childNodes?: El[] };++/** Chrome's integer offset*, client* and scroll*: rounded, as Chrome snaps its layout units. */+const px = (v: number) => Math.round(v);++const box = (el: El): Box | undefined => boxOf(el.id);++/** An element with no box: the zero rect Chrome answers for one that isn't displayed. */+const ZERO: Box = { rect: [0, 0, 0, 0], scroll: [0, 0, 0, 0], padding: [0, 0, 0, 0], border: [0, 0, 0, 0], layout: [0, 0, 0, 0], offsetParent: -2, inline: false };++/** The ancestor with React id `id` (offsetParent's element), or null. */+function ancestor(el: El, id: number): El | null {+ for (let p = el.parentNode; p; p = p.parentNode) if (p.id === id) return p;+ return null;+}++/** An inline element (a span in a line) has no padding box: its client* and scroll* are 0. */+const inline = (b: Box) => b.inline;++/** LR3's reads, on `Element`'s prototype (bevy-react's BevyElement). */+export function domReads(Element: { prototype: object } | undefined): void {+ if (!Element || (Element.prototype as any).__domReads) return;+ const define = (name: string, get: (this: El) => unknown) => Object.defineProperty(Element.prototype, name, { get, configurable: true });+ Object.defineProperty(Element.prototype, "__domReads", { value: true });+ Object.defineProperty(Element.prototype, "getBoundingClientRect", {+ configurable: true,+ writable: true,+ value(this: El) {+ const r = (box(this) ?? ZERO).rect;+ return new DOMRect(r[0], r[1], r[2], r[3]);+ },+ });+ Object.defineProperty(Element.prototype, "getClientRects", {+ configurable: true,+ writable: true,+ value(this: El) {+ const b = box(this);+ // an element that isn't displayed has no rects; an inline one's line fragments are joined in the snapshot+ return !b || b.offsetParent === -2 ? [] : [new DOMRect(b.rect[0], b.rect[1], b.rect[2], b.rect[3])];+ },+ });+ define("offsetLeft", function () {+ return px((box(this) ?? ZERO).layout[0]);+ });+ define("offsetTop", function () {+ return px((box(this) ?? ZERO).layout[1]);+ });+ define("offsetWidth", function () {+ return px((box(this) ?? ZERO).layout[2]);+ });+ define("offsetHeight", function () {+ return px((box(this) ?? ZERO).layout[3]);+ });+ define("offsetParent", function () {+ const b = box(this);+ if (!b || b.offsetParent === -2) return null;+ if (b.offsetParent >= 0) return ancestor(this, b.offsetParent);+ // the page's body: the composition's root element stands for it+ let top: El = this;+ while (top.parentNode && top.parentNode.parentNode) top = top.parentNode;+ return top === this ? null : top;+ });+ // the padding box: the border box less its borders (and, for an inline element, 0)+ const client = (b: Box, i: 0 | 1) => (inline(b) ? 0 : px(b.layout[2 + i] - b.border[i] - b.border[2 + i]));+ define("clientWidth", function () {+ return client(box(this) ?? ZERO, 0);+ });+ define("clientHeight", function () {+ return client(box(this) ?? ZERO, 1);+ });+ define("clientLeft", function () {+ const b = box(this) ?? ZERO;+ return inline(b) ? 0 : px(b.border[0]);+ });+ define("clientTop", function () {+ const b = box(this) ?? ZERO;+ return inline(b) ? 0 : px(b.border[1]);+ });+ define("scrollLeft", function () {+ return (box(this) ?? ZERO).scroll[0];+ });+ define("scrollTop", function () {+ return (box(this) ?? ZERO).scroll[1];+ });+ define("scrollWidth", function () {+ const b = box(this) ?? ZERO;+ return inline(b) ? 0 : px(b.scroll[2]);+ });+ define("scrollHeight", function () {+ const b = box(this) ?? ZERO;+ return inline(b) ? 0 : px(b.scroll[3]);+ });+}diff --git a/sdk/react/js/bun.lock b/sdk/react/js/bun.lockindex 4b0c2d39..0e8321f2 100644--- a/sdk/react/js/bun.lock+++ b/sdk/react/js/bun.lock@@ -17,6 +17,9 @@},},},+ "patchedDependencies": {+ "[email protected]": "patches/[email protected]",+ },"packages": {"@types/dom-mediacapture-transform": ["@types/[email protected]", "", { "dependencies": { "@types/dom-webcodecs": "*" } }, "sha512-d7/QsLRwF864A5mgIM/YrfiglHoYn7zgCcAoJgW404r+2DwnNr7EBbLnCWpmOMgH8y0te73L1AV6H1bmauaWFw=="],diff --git a/sdk/react/js/package.json b/sdk/react/js/package.jsonindex a1422e7d..c7cce451 100644--- a/sdk/react/js/package.json+++ b/sdk/react/js/package.json@@ -15,5 +15,8 @@},"devDependencies": {"@types/react": "19.2.0"+ },+ "patchedDependencies": {+ "[email protected]": "patches/[email protected]"}}\ No newline at end of filediff --git a/sdk/react/js/patches/[email protected] b/sdk/react/js/patches/[email protected]new file mode 100644index 00000000..d1eadec0--- /dev/null+++ b/sdk/react/js/patches/[email protected]@@ -0,0 +1,258 @@+diff --git a/src/canvas.ts b/src/canvas.ts+index 0bd05fcb2730a53ad4893f7d3cf0adad12a510db..5357f3fe7607697a81c88c807777bf9fa31a3a31 100644+--- a/src/canvas.ts++++ b/src/canvas.ts+@@ -37,6 +37,8 @@+ // ctx.beginPath();+ // ctx.arc(x, y, 4, 0, Math.PI * 2);+ // ctx.fill();++import { BevyElement } from "./nodes";++++ // Mirrors `protocol::DrawCmd` on the Rust side (tag = "cmd"). Coordinates are in+ // the canvas's own pixel space, top-left origin.+@@ -243,17 +245,17 @@ export interface CanvasHost {+ * handle to the element. Survives re-renders and Fast Refresh (node ids are+ * stable); drawing through a handle whose node has unmounted is a silent+ * no-op on the Bevy side. */+-export class BevyCanvasElement {+- /** The host-element type, `"canvas"` (the renderer's `Instance` shape). */+- readonly type = "canvas";++export class BevyCanvasElement extends BevyElement {+ readonly #host: CanvasHost;+ #ctx: RetainedCanvasContext | null = null;++ constructor(+ /** The element's reconciler node id. */+- readonly id: number,++ id: number,+ host: CanvasHost,+ ) {++ // its type is "canvas" (the renderer's `Instance` shape), its kind the same++ super(id, "canvas", undefined, {});+ this.#host = host;+ }++diff --git a/src/index.ts b/src/index.ts+index 329c833ef3cb6c8f938e7ebdf66862e87507c946..e36f26028eb19555608cefe12020570c398cb988 100644+--- a/src/index.ts++++ b/src/index.ts+@@ -84,6 +84,8 @@ export type * from "./jsx";+ // or imperatively through a `<canvas ref={…}>`'s persistent `BevyCanvasElement`+ // handle (`getContext()` → a `RetainedCanvasContext` that batches and+ // flushes at will; paint accumulates on the retained surface).++// The committed tree on the instances (raea's patch): what a ref holds is a BevyElement.++export { BevyElement, BevyNode, BevyTextNode, containerNode } from "./nodes";+ export {+ BevyCanvasElement,+ CanvasContext,+diff --git a/node_modules/bevy-react/src/nodes.ts b/src/nodes.ts+new file mode 100644+index 0000000000000000000000000000000000000000..3fb86d0779c0b2d9767097c460658443dc73cca7+--- /dev/null++++ b/src/nodes.ts+@@ -0,0 +1,64 @@++// The tree as React last committed it, kept on the instances themselves (raea's patch, docs/layout-reads.feature++// LR4): each element and text instance knows its parent, its children in order, and its latest props or text. A host++// can then answer DOM-shaped reads (children, querySelector, textContent) from the instances a ref already holds,++// without parsing the op stream. Containers get an element of their own, so a top-level instance has a parent.++++/** A node of the committed tree: an element or a text run. */++export class BevyNode {++ parentNode: BevyElement | null = null;++ constructor(++ /** The node's reconciler id (what its ops name). */++ readonly id: number,++ ) {}++}++++/** A host element: what a ref holds (a `<canvas>`'s is BevyCanvasElement, one of these too). */++export class BevyElement extends BevyNode {++ childNodes: BevyNode[] = [];++ constructor(++ id: number,++ /** The JSX type ("div", "span", "text" ...). */++ readonly type: string,++ /** The wire kind it was created as (`type`, except inside a `<text>`). */++ readonly kind: string | undefined,++ /** Its props as React last committed them. */++ public props: Record<string, unknown>,++ ) {++ super(id);++ }++}++++/** A text run: a bare string child. */++export class BevyTextNode extends BevyNode {++ constructor(++ id: number,++ public data: string,++ ) {++ super(id);++ }++}++++const containers = new Map<number, BevyElement>();++++/** The element standing for container `id` (the root a tree is mounted in). */++export function containerNode(id: number): BevyElement {++ let c = containers.get(id);++ if (!c) containers.set(id, (c = new BevyElement(id, "root", "root", {})));++ return c;++}++++/** `child` put under `parent`, before `before` (at the end without it), taken from wherever it was. */++export function link(parent: BevyElement, child: BevyNode, before?: BevyNode): void {++ if (child.parentNode) unlink(child.parentNode, child);++ const at = before ? parent.childNodes.indexOf(before) : -1;++ if (at < 0) parent.childNodes.push(child);++ else parent.childNodes.splice(at, 0, child);++ child.parentNode = parent;++}++++/** `child` taken out of `parent`. */++export function unlink(parent: BevyElement, child: BevyNode): void {++ const at = parent.childNodes.indexOf(child);++ if (at >= 0) parent.childNodes.splice(at, 1);++ if (child.parentNode === parent) child.parentNode = null;++}+diff --git a/src/renderer.ts b/src/renderer.ts+index 84aefa67ab2c6b886dce6445d305dd328a89c0a3..d97b868fd151c8c3bbd12e0e716c42859fb03a19 100644+--- a/src/renderer.ts++++ b/src/renderer.ts+@@ -23,6 +23,13 @@ import {+ } from "./bridge";+ import { installDevtools, noteOwner } from "./devtools";+ import { setupRefreshRuntime } from "./hmr";++import {++ BevyElement,++ BevyTextNode,++ containerNode,++ link,++ unlink,++} from "./nodes";++ // `process.env.NODE_ENV` is replaced at build time by esbuild's `define`; the+ // declaration is type-only (erased) and keeps tsc happy without @types/node.+@@ -34,19 +41,13 @@ const DEV = process.env.NODE_ENV !== "production";+ // refresh runtime has already patched. No-op in production builds.+ if (DEV) setupRefreshRuntime();++-interface Instance {+- id: number;+- type: string;+- /** The wire kind the node was created as (`type`, except inside a+- * `<text>`: a nested `<text>` is a `textSpan`, an `<image>` an+- * `inlineImage`) — every update op names it, since Rust decodes the props+- * against that element. Absent on a `<canvas>` handle (its kind is its+- * type). */+- kind?: string;+-}+-interface TextInstance {+- id: number;+-}++// An instance is a BevyElement (nodes.ts): its id, type and wire kind (`type`,++// except inside a `<text>`: a nested `<text>` is a `textSpan`, an `<image>` an++// `inlineImage`; every update op names it, since Rust decodes the props against++// that element; absent on a `<canvas>` handle, whose kind is its type), with++// the committed tree kept on it.++type Instance = BevyElement;++type TextInstance = BevyTextNode;+ interface Container {+ id: number;+ // Marks the devtools panel's own container: its commits flush with+@@ -194,8 +195,11 @@ const hostConfig: Reconciler.HostConfig<+ text,+ });+ // A `<canvas>`'s instance is its persistent element handle (what a ref+- // resolves to via `getPublicInstance`); it satisfies `Instance`.+- return type === "canvas" ? createCanvasElement(id) : { id, type, kind };++ // resolves to via `getPublicInstance`), a BevyElement too.++ if (type !== "canvas") return new BevyElement(id, type, kind, props);++ const canvas = createCanvasElement(id);++ canvas.props = props;++ return canvas;+ },++ createTextInstance(+@@ -213,19 +217,22 @@ const hostConfig: Reconciler.HostConfig<+ ? { op: "createTextSpan", id, text }+ : { op: "createText", id, text },+ );+- return { id };++ return new BevyTextNode(id, text);+ },++ appendInitialChild(parent: Instance, child: Instance | TextInstance) {+ push({ op: "append", parent: parent.id, child: child.id });++ link(parent, child);+ },+ finalizeInitialChildren: () => false,++ appendChild(parent: Instance, child: Instance | TextInstance) {+ push({ op: "append", parent: parent.id, child: child.id });++ link(parent, child);+ },+ appendChildToContainer(container: Container, child: Instance | TextInstance) {+ push({ op: "append", parent: container.id, child: child.id });++ link(containerNode(container.id), child);+ },++ insertBefore(+@@ -239,6 +246,7 @@ const hostConfig: Reconciler.HostConfig<+ child: child.id,+ before: before.id,+ });++ link(parent, child, before);+ },+ insertInContainerBefore(+ container: Container,+@@ -251,11 +259,13 @@ const hostConfig: Reconciler.HostConfig<+ child: child.id,+ before: before.id,+ });++ link(containerNode(container.id), child, before);+ },++ removeChild(parent: Instance, child: Instance | TextInstance) {+ push({ op: "remove", parent: parent.id, child: child.id });+ dropHandlers(child.id);++ unlink(parent, child);+ },+ removeChildFromContainer(+ container: Container,+@@ -263,6 +273,7 @@ const hostConfig: Reconciler.HostConfig<+ ) {+ push({ op: "remove", parent: container.id, child: child.id });+ dropHandlers(child.id);++ unlink(containerNode(container.id), child);+ },++ // react-reconciler 0.33 removed `prepareUpdate`; `commitUpdate` now receives both+@@ -278,6 +289,7 @@ const hostConfig: Reconciler.HostConfig<+ _internalHandle: unknown,+ ) {+ const id = instance.id;++ instance.props = newProps;+ const op = buildUpdateOp(+ id,+ oldProps,+@@ -302,6 +314,7 @@ const hostConfig: Reconciler.HostConfig<++ commitTextUpdate(textInstance: TextInstance, _old: string, next: string) {+ push({ op: "updateText", id: textInstance.id, text: next });++ textInstance.data = next;+ },++ // Clear an inline-text element's content (React calls this when a `<text>`+@@ -310,7 +323,9 @@ const hostConfig: Reconciler.HostConfig<+ push({ op: "updateText", id: instance.id, text: "" });+ },++- clearContainer: () => {},++ clearContainer: (container: Container) => {++ containerNode(container.id).childNodes = [];++ },+ detachDeletedInstance: (instance: Instance) => dropHandlers(instance.id),++ // No-op scope/blur hooks the reconciler still expects.diff --git a/tools/layers.toml b/tools/layers.tomlindex d100a3c4..07de515e 100644--- a/tools/layers.toml+++ b/tools/layers.toml@@ -132,6 +132,7 @@ raea-runtime-calls = "runtime"raea-runtime-shots = "runtime"raea-runtime-export = "runtime"raea-runtime-pagestore = "runtime"+raea-runtime-cssurls = "runtime"raea-runtime-page = "runtime"raea-runtime-sound = "runtime"raea-runtime-view = "runtime"