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
A box that clips its overflow takes no pointer for what it cuts away, in both of the window's hit tests. A card zoomed past the edge of a canvas (React Flow at scale 2) was drawn clipped but took the presses on the sidebar and the header around the canvas. blitz-dom's hit_inner tested children wherever they overflowed to: it now skips a clipping box's children when the point is outside its padding box, and a hoisted (z-index) child is under its stacking-context root's clip and the clips of the boxes between along its containing blocks, the ones blitz-paint's hoisted_clips draws it under; a box painted from above (#39) is under none. sdk/ui's hit dropped the inherited clip at a child with its own z-index and replaced it at a child that clips: both now cut the child's clip to the one it is under; a fixed box is exempt. Proved by the app's e2e/canvas-layer.spec.ts in a headless window (fails with either half alone) and a unit test in sdk/ui/test/dom.test.tsx that fails on the old hit
shinyobjectz37846080a780
diff --git a/sdk/ui/src/dom/input.ts b/sdk/ui/src/dom/input.tsindex 459d9682..adb044a5 100644--- a/sdk/ui/src/dom/input.ts+++ b/sdk/ui/src/dom/input.ts@@ -160,6 +160,9 @@ export function focusTo(el: Element_, tellHost: boolean) {transition(el, tellHost);}+/** A clip rectangle [x0, y0, x1, y1] cut to the one it's under (none: itself). */+const within = (own: number[], under: number[] | null) => (under ? [Math.max(own[0], under[0]), Math.max(own[1], under[1]), Math.min(own[2], under[2]), Math.min(own[3], under[3])] : own);+/** The deepest element under (x, y), searched from `from` down: the topmost box that has the point (a higher z,* then the later in the tree), past what clips it and what takes no pointer events. */export function hit(from: Node_, x: number, y: number): Element_ | null {@@ -184,15 +187,25 @@ export function hit(from: Node_, x: number, y: number): Element_ | null {bestZ = kz;bestOrder = i;}- if (c.overflowX !== "visible" || c.overflowY !== "visible") kclip = [b[0], b[1], b[0] + b[2], b[1] + b[3]];+ // its own clip inside the one it's under, never in its place: a card that clips (rounded corners) and lies+ // past its canvas's edge would otherwise hand its children the whole of its own box+ if (c.overflowX !== "visible" || c.overflowY !== "visible") kclip = within([b[0], b[1], b[0] + b[2], b[1] + b[3]], clip);} else if (b && c && kz !== z) {+ // a box with its own z-index is still under the clips of the boxes it's in: without them a card zoomed past+ // its canvas's edge took the presses on the page around the canvas (its clip was dropped here). A fixed box+ // is placed against the viewport and is under none. Not read: an absolute box whose containing block is+ // above the clipping box escapes that clip in CSS and stays under it here; a fixed box under a transformed+ // ancestor is clipped in CSS and isn't here. The host's hit test (blitz-dom's hit_inner) reads both for a+ // z-indexed box, and its answer wins where the two differ (pointed, below).+ const under = c.position === "fixed" ? null : clip;const inside = x >= b[0] && x < b[0] + b[2] && y >= b[1] && y < b[1] + b[3];- if (inside && c.pointerEvents !== "none" && (kz > bestZ || (kz === bestZ && i > bestOrder))) {+ const inClip = !under || (x >= under[0] && x < under[2] && y >= under[1] && y < under[3]);+ if (inside && inClip && c.pointerEvents !== "none" && (kz > bestZ || (kz === bestZ && i > bestOrder))) {best = k;bestZ = kz;bestOrder = i;}- kclip = c.overflowX !== "visible" || c.overflowY !== "visible" ? [b[0], b[1], b[0] + b[2], b[1] + b[3]] : null;+ kclip = c.overflowX !== "visible" || c.overflowY !== "visible" ? within([b[0], b[1], b[0] + b[2], b[1] + b[3]], under) : under;}walk(k, kclip, kz);}diff --git a/sdk/ui/test/dom.test.tsx b/sdk/ui/test/dom.test.tsxindex 34fd01c7..c60fb575 100644--- a/sdk/ui/test/dom.test.tsx+++ b/sdk/ui/test/dom.test.tsx@@ -99,6 +99,38 @@ describe("P18 DOM surface", () => {expect(ops.some((o: any) => o.op === "update" && o.set?.scrollTop === 400)).toBe(true);});+ test("a box with its own z-index stays under the overflow clip of the box it's in; a fixed one doesn't", () => {+ const host = fresh();+ function App() {+ return (+ <div data-testid="root">+ <button data-testid="side" />+ <div data-testid="stage" style={{ overflow: "hidden" }}>+ <div data-testid="view" style={{ zIndex: 2 }}>+ <div data-testid="card" style={{ zIndex: 3, overflow: "hidden" }}>+ <img data-testid="pic" />+ </div>+ </div>+ <div data-testid="menu" style={{ position: "fixed", zIndex: 5 }} />+ </div>+ </div>+ );+ }+ mount(<App />, 0, { dom: true });+ // the card is zoomed past the stage's edge, over the button beside the stage; the menu is placed there on purpose+ const z = (n: number) => [...Array(12).fill(0), n];+ const boxes: Record<string, number[]> = { root: [0, 0, 800, 600], side: [0, 0, 200, 600], stage: [200, 0, 600, 600], view: [200, 0, 1600, 1200, ...z(2)], card: [100, 100, 400, 300, ...z(3)], pic: [100, 100, 400, 300, ...z(3)], menu: [20, 500, 100, 40, ...z(5)] };+ const n: number[] = [];+ for (const [t, b] of Object.entries(boxes)) n.push(host.tid(t), ...b, ...Array(17 - b.length).fill(0));+ layout(JSON.stringify({ vw: 800, vh: 600, dpr: 2, n }));+ const at = (x: number, y: number) => g.document.elementFromPoint(x, y)?.getAttribute("data-testid");+ expect(at(150, 150)).toBe("side");+ // nor do the card's own children, though the card clips too: its clip is cut to the stage's, not put in its place+ expect(at(300, 150)).toBe("pic");+ expect(at(700, 500)).toBe("view");+ expect(at(50, 510)).toBe("menu");+ });+test("a press goes where the host's cascade says: a child a stylesheet gives pointer events back, under a pointer-events-none layer", () => {const host = fresh();const log: string[] = [];diff --git a/vendor/blitz-dom/src/node/node.rs b/vendor/blitz-dom/src/node/node.rsindex ca2b23a4..f7ab68d7 100644--- a/vendor/blitz-dom/src/node/node.rs+++ b/vendor/blitz-dom/src/node/node.rs@@ -1556,6 +1556,61 @@ impl Node {self.hit_inner(x, y, scale, &mut None)}+ /// raea: whether this box's overflow clip cuts the point away (the point from its border box, unscrolled):+ /// outside its padding box on an axis it clips. The root element clips nothing (its overflow is the viewport's).+ fn clips_away(&self, x: f32, y: f32) -> bool {+ use style::values::computed::Overflow;+ let is_root_element = self.parent.and_then(|p| self.tree().get(p)).is_some_and(|p| p.parent.is_none());+ if is_root_element {+ return false;+ }+ let Some(styles) = self.primary_styles() else { return false };+ let cx = !matches!(styles.clone_overflow_x(), Overflow::Visible);+ let cy = !matches!(styles.clone_overflow_y(), Overflow::Visible);+ let (size, b) = (self.final_layout().size, self.final_layout().border);+ (cx && (x < b.left || x > size.width - b.right)) || (cy && (y < b.top || y > size.height - b.bottom))+ }++ /// raea: whether a hoisted child (a z-index's, hit from its stacking-context root, this node) is cut away at+ /// the point (in this node's coordinates, as the hoisted children's positions are): by this node's own clip+ /// (`cut`) or by one of the boxes between along its containing blocks, the clips blitz-paint draws it under+ /// (`hoisted_clips`). A box whose containing blocks never reach this node is painted from above it, under none+ /// of these clips (blitz-paint's `from_above`), and is never cut here. Transforms on the boxes between are not+ /// read, as the painter's clips don't read them.+ fn hoisted_cut(&self, child: NodeId, x: f32, y: f32, cut: bool) -> bool {+ let tree = self.tree();+ let mut between = Vec::new();+ let mut current = tree.get(child).and_then(|n| n.containing_block());+ loop {+ match current {+ Some(id) if id == self.id => break,+ Some(id) => {+ between.push(id);+ current = tree.get(id).and_then(|n| n.containing_block());+ }+ None => return false,+ }+ }+ if cut {+ return true;+ }+ between.iter().any(|&id| {+ let Some(node) = tree.get(id) else { return false };+ // its border box from this node: its place and those of the boxes it's in, less what they're scrolled by+ let at = node.final_layout().location;+ let (mut ax, mut ay) = (at.x, at.y);+ let mut up = node.containing_block();+ while let Some(a) = up.filter(|a| *a != self.id) {+ let Some(an) = tree.get(a) else { break };+ let (l, sc) = (an.final_layout().location, an.scroll_offset());+ ax += l.x - sc.x as f32;+ ay += l.y - sc.y as f32;+ up = an.containing_block();+ }+ node.clips_away(x - ax, y - ay)+ })+ }+/// [`hit`](Self::hit), also resolving the innermost overlay scrollbar/// thumb under the point into `scrollbar` during the same descent (so/// thumb hit-testing shares the exact coordinate handling — transforms@@ -1630,6 +1685,11 @@ impl Node {return None;}+ // raea: a box that clips its overflow takes no pointer for what it cuts away, as it draws none of it+ // (blitz-paint's `should_clip`). Blitz tested the children wherever they overflowed to, so a press on the+ // page around a zoomed canvas landed on the card that would have lain there.+ let cut = self.clips_away(x - self.scroll_offset().x as f32, y - self.scroll_offset().y as f32);+// Descendants overwrite, so the innermost scroll container's thumb// wins. Thumb coords are border-box relative (unscrolled).if matches_self@@ -1656,6 +1716,9 @@ impl Node {let Some(child) = self.tree().get(hoisted_child.node_id) else {continue;};+ if self.hoisted_cut(hoisted_child.node_id, x, y, cut) {+ continue;+ }let pos = hoisted_child.position(self.tree(), self.id);let x = x - pos.x;let y = y - pos.y;@@ -1668,6 +1731,9 @@ impl Node {// Call `.hit()` on each child in turn. If any return `Some` then return that value. Else return `Some(self.id).for child_id in self.paint_children.borrow().iter().flatten().rev() {+ if cut {+ break;+ }let Some(child) = self.tree().get(*child_id) else {continue;};@@ -1699,6 +1765,9 @@ impl Node {let Some(child) = self.tree().get(hoisted_child.node_id) else {continue;};+ if self.hoisted_cut(hoisted_child.node_id, x, y, cut) {+ continue;+ }let pos = hoisted_child.position(self.tree(), self.id);let x = x - pos.x;let y = y - pos.y;