Skip to content

armgit / raea

Public Imported from GitHub
0

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.

LR10: getBoundingClientRect through a perspective is the box of the four corners as drawn, as Chrome's is. blitz-dom's transformed_bounds took each node's affine transform only, so a card turned under a perspective (its Projection) read at its flat size and place; one in a preserve-3d context maps from its context root's parent. A blitz-dom test holds Chrome's numbers for a 400x200 card under a 1000px perspective, rotateY(60deg), flat (379.05, 379.05, 206.19, 241.90) and in a world turned rotateX(10deg). transformed_rect maps any rect in a node's box, and a render manifest text's ink goes through it. snapcn 21 -> 23 of 33: card-rail 161.4 px off -> 0.6, announce-title 11504 -> 43.5, punch-lines and text-rewrite pass; P26 unchanged (185 of 215, every frame at the same SSIM)

shinyobjectz09eeb21fe9c9
diff --git a/docs/layout-reads.feature b/docs/layout-reads.feature
index d1a80430..5b1eb3ec 100644
--- a/docs/layout-reads.feature
+++ b/docs/layout-reads.feature
@@ -322,7 +322,7 @@ Feature: Layout reads: a composition measures its text and layout as Chrome does
And a composition that measures every frame (karaoke-captions, 300 frames) has its cost per read and per frame
measured and written here
And sdk/raea/conformance covers the JS side, and Rust tests cover the call, the wait and the hang guard
- And 11-12, in progress (snapcn: 3 of 33 before LR work, 7 after LR1-LR9, 12 after the usvg and font fixes, 17 with kerning and the manifest, 21 now):
+ And 11-12, in progress (snapcn: 3 of 33 before LR work, 7 after LR1-LR9, 12 after the usvg and font fixes, 17 with kerning and the manifest, 21 with the fonts, 23 now):
- Kerning across spans. blitz-dom gave every composition span a border edge: with `border-style: none` (the
initial style) a border's computed width is still `medium`, and inline_edges read the width alone, so each
plain span got a zero-width spacer box at both ends and parley split its shaping there. "AVAWATAVAWAT" in a
@@ -352,9 +352,15 @@ Feature: Layout reads: a composition measures its text and layout as Chrome does
and Google's never came: raea drew 300, 400 and 500 alike (345.45 px at 100px for "snapcn"; Chrome 340.39,
345.47, 350.45) and 600 as 700. Now 340.33, 345.45, 350.48, 355.38, 360.45. wordmark-cut (22 px narrow at 500),
text-select and hero-launch pass; punch-lines 18.1 -> 0.9, text-rewrite 7.4 -> 0.2 (box; ink 1.9).
- - Still off (12): announce-title (frame 0's runs), capture-reveal (3 runs only raea has), font-shuffle,
- portal-intro, prompt-send, punch-lines and text-rewrite (their ink, 1.3 to 1.9 px past Chrome's, the boxes
- within 1), search-typing (1.9), status-cycle, text-build (SF's trak), word-gather (1.2) and card-rail.
+ - getBoundingClientRect through a perspective is the box of the four corners as drawn (blitz-dom's
+ transformed_bounds took only the affine part, so a card turned under a perspective read at its flat size
+ and place); one in a preserve-3d context is mapped from its context root's parent. Chrome's numbers for a
+ 400x200 card under a 1000px perspective, flat and in a turned world, are a blitz-dom test. A manifest text's
+ ink goes through the same transforms. card-rail 161.4 px off -> 0.6 (ink 1.7), announce-title 11504 -> 43.5;
+ punch-lines and text-rewrite pass.
+ - Still off (10): announce-title (frame 0's runs), capture-reveal (3 runs only raea has), font-shuffle,
+ portal-intro, prompt-send (ink 1.8), search-typing (1.5), status-cycle, text-build (SF's trak),
+ word-gather and card-rail (ink 1.7).
- The cost, measured 11-12 on the M5 Pro (300 frames, 1280x720, 40 inline-blocks of Inter whose text changes
every frame, rendered to hashes, median of 6): no reads 2.034 s, one getBoundingClientRect a frame 2.151 s,
ten a frame 2.180 s. The first read in a frame costs about 0.39 ms (one layout synced); each further read in
diff --git a/engine/page/src/motion/manifest.rs b/engine/page/src/motion/manifest.rs
index f3e46495..c1e256eb 100644
--- a/engine/page/src/motion/manifest.rs
+++ b/engine/page/src/motion/manifest.rs
@@ -143,8 +143,14 @@ impl BlitzPage {
}
}
if x1 > x0 {
- let left = b.x + ((fl.border.left + fl.padding.left) as f64 + x0 / scale) * fx;
- t["ink"] = json!([r(left), r(b.y), r((x1 - x0) / scale * fx), r(h)]);
+ let lx = (fl.border.left + fl.padding.left) as f64 + x0 / scale;
+ // through the element's transforms as its box is (a card turned under a perspective draws its line
+ // narrower at the far end: a share of the box's width would put it where it isn't)
+ let local_h = (fl.size.height as f64).max((fl.border.top + fl.padding.top) as f64 + l.layout.height() as f64 / scale);
+ t["ink"] = match doc.transformed_rect(owner, [lx, 0.0, (x1 - x0) / scale, local_h]) {
+ Some(q) => json!([r(q.x), r(q.y), r(q.width), r(q.height)]),
+ None => json!([r(b.x + lx * fx), r(b.y), r((x1 - x0) / scale * fx), r(h)]),
+ };
}
}
// its first named face and how many lines it was set on (docs/direction.feature DR1's Text)
diff --git a/vendor/blitz-dom/src/document.rs b/vendor/blitz-dom/src/document.rs
index c4d3ce30..bf626462 100644
--- a/vendor/blitz-dom/src/document.rs
+++ b/vendor/blitz-dom/src/document.rs
@@ -2550,10 +2550,41 @@ impl BaseDocument {
/// raea: the bounds of a node's border box in the viewport through every transform on its containing block chain,
/// or None when there's none on it. Each node's transform is kept in device pixels (its translation scaled), so it
/// is taken back to CSS pixels here.
+ ///
+ /// A perspective's projection is taken as the painter draws it (the node's Projection `h`), so the bounds are its
+ /// four corners' box on the page, as Chrome's are: snapcn's card-rail (cards turned under a perspective) read
+ /// every card at its flat size and place (layout-reads LR10).
fn transformed_bounds(&self, node_id: NodeId) -> Option<BoundingRect> {
- use kurbo::{Affine, Rect};
+ let size = self.nodes.get(node_id)?.unrounded_layout().size;
+ self.transformed_rect(node_id, [0.0, 0.0, size.width as f64, size.height as f64])
+ }
+
+ /// raea: a rect in a node's own box (x, y, w, h from its border box's corner, CSS px) on the page through every transform
+ /// on its containing block chain, projections included, as transformed_bounds takes its border box; None when
+ /// there's no transform on it (the render manifest's ink: the span of a line's letters on a turned card)
+ pub fn transformed_rect(&self, node_id: NodeId, rect: [f64; 4]) -> Option<BoundingRect> {
+ // a 3x3 on column vectors (x, y, w), row-major, in CSS px
+ type H = [f64; 9];
+ fn mul(a: &H, b: &H) -> H {
+ let mut m = [0.0; 9];
+ for r in 0..3 {
+ for c in 0..3 {
+ m[r * 3 + c] = (0..3).map(|k| a[r * 3 + k] * b[k * 3 + c]).sum();
+ }
+ }
+ m
+ }
+ let translate = |x: f64, y: f64| -> H { [1.0, 0.0, x, 0.0, 1.0, y, 0.0, 0.0, 1.0] };
let scale = self.viewport.scale_f64();
- let mut m = Affine::IDENTITY;
+ // an affine kept in device pixels (its translation scaled), in CSS px
+ let affine = |t: &kurbo::Affine| -> H {
+ let [a, b, c, d, e, f] = t.as_coeffs();
+ [a, c, e / scale, b, d, f / scale, 0.0, 0.0, 1.0]
+ };
+ // a Projection's h is S * H * S^-1 with S = diag(scale, scale, 1): back to CSS px
+ let css = |h: &H| -> H { [h[0], h[1], h[2] / scale, h[3], h[4], h[5] / scale, h[6] * scale, h[7] * scale, h[8]] };
+ let preserves = |id: NodeId| self.nodes.get(id).and_then(|n| n.primary_styles()).is_some_and(|s| crate::stylo_to_kurbo::preserves_3d(&s));
+ let mut m: H = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0];
let mut any = false;
let mut current = Some(node_id);
while let Some(id) = current {
@@ -2561,27 +2592,64 @@ impl BaseDocument {
let Some(node) = self.nodes.get(id) else { break };
if id != node_id {
let s = node.scroll_offset();
- m = Affine::translate((-s.x, -s.y)) * m;
+ m = mul(&translate(-s.x, -s.y), &m);
}
- if let Some(t) = node.transform().as_deref() {
+ let projection = self.projections.get(&id);
+ if let Some(p) = projection.filter(|p| p.in_context) {
+ // in a 3D rendering context: h is from the context root's parent's space, the box's position included
+ let h = match (p.h, p.context) {
+ (Some(h), _) => Some(css(&h)),
+ (None, Some(a)) => Some(affine(&a)),
+ (None, None) => None,
+ };
+ if let Some(h) = h {
+ any = true;
+ m = mul(&h, &m);
+ // up to the context's root (the first ancestor whose parent doesn't preserve 3D), then on from its parent
+ let mut root = node.containing_block();
+ while let Some(r) = root {
+ match self.nodes.get(r).and_then(|n| n.containing_block()) {
+ Some(up) if preserves(up) => root = Some(up),
+ _ => break,
+ }
+ }
+ current = root.and_then(|r| self.nodes.get(r)).and_then(|n| n.containing_block());
+ continue;
+ }
+ }
+ if let Some(h) = projection.and_then(|p| p.h) {
+ any = true;
+ m = mul(&css(&h), &m);
+ } else if let Some(t) = node.transform().as_deref() {
any = true;
- let [a, b, c, d, e, f] = t.as_coeffs();
- m = Affine::new([a, b, c, d, e / scale, f / scale]) * m;
+ m = mul(&affine(t), &m);
}
let loc = node.unrounded_layout().location;
- m = Affine::translate((loc.x as f64, loc.y as f64)) * m;
+ m = mul(&translate(loc.x as f64, loc.y as f64), &m);
current = node.containing_block();
}
if !any {
return None;
}
- let size = self.nodes[node_id].unrounded_layout().size;
- let r = m.transform_rect_bbox(Rect::new(0.0, 0.0, size.width as f64, size.height as f64));
+ let [rx, ry, w, h] = rect;
+ let (mut x0, mut y0, mut x1, mut y1) = (f64::MAX, f64::MAX, f64::MIN, f64::MIN);
+ for (x, y) in [(rx, ry), (rx + w, ry), (rx + w, ry + h), (rx, ry + h)] {
+ let q = m[6] * x + m[7] * y + m[8];
+ // a corner at or behind the viewer has no place on the page
+ if q <= 1e-9 {
+ continue;
+ }
+ let (px, py) = ((m[0] * x + m[1] * y + m[2]) / q, (m[3] * x + m[4] * y + m[5]) / q);
+ (x0, y0, x1, y1) = (x0.min(px), y0.min(py), x1.max(px), y1.max(py));
+ }
+ if x0 > x1 {
+ return Some(BoundingRect { x: 0.0, y: 0.0, width: 0.0, height: 0.0 });
+ }
Some(BoundingRect {
- x: snap_to_layout_unit(r.x0 - self.viewport_scroll().x),
- y: snap_to_layout_unit(r.y0 - self.viewport_scroll().y),
- width: snap_to_layout_unit(r.width()),
- height: snap_to_layout_unit(r.height()),
+ x: snap_to_layout_unit(x0 - self.viewport_scroll().x),
+ y: snap_to_layout_unit(y0 - self.viewport_scroll().y),
+ width: snap_to_layout_unit(x1 - x0),
+ height: snap_to_layout_unit(y1 - y0),
})
}
diff --git a/vendor/blitz-dom/src/resolve.rs b/vendor/blitz-dom/src/resolve.rs
index e51044a4..6f424492 100644
--- a/vendor/blitz-dom/src/resolve.rs
+++ b/vendor/blitz-dom/src/resolve.rs
@@ -621,4 +621,34 @@ mod tests {
doc.resolve(0.0);
assert_eq!(doc.projections.get(&card).copied(), want);
}
+
+ /// raea: getBoundingClientRect through a perspective is the box of the four corners as drawn (layout-reads LR10:
+ /// snapcn's card-rail read every turned card at its flat size). Chrome 's numbers, for a 400x200 card at 300,400
+ /// under a 1000px perspective, turned rotateY(60deg): flat, and in a preserve-3d world turned rotateX(10deg).
+ #[test]
+ fn a_rect_under_a_perspective_is_its_corners_as_drawn() {
+ let rect = |world: Option<&str>| {
+ let mut doc = BaseDocument::new(DocumentConfig { viewport: Some(Viewport::new(1000, 1000, 1.0, ColorScheme::Light)), ..Default::default() });
+ let style = |v: &str| vec![Attribute { name: qual_name!("style"), value: v.to_string() }];
+ let root_id = doc.root_node().id;
+ let mut m = doc.mutate();
+ let root = m.create_element(qual_name!("div"), style("position:relative;width:1000px;height:1000px;perspective:1000px"));
+ let card = m.create_element(qual_name!("div"), style("position:absolute;left:300px;top:400px;width:400px;height:200px;transform:rotateY(60deg)"));
+ if let Some(w) = world {
+ let w = m.create_element(qual_name!("div"), style(&format!("position:absolute;inset:0;transform-style:preserve-3d;transform:{w}")));
+ m.append_children(w, &[card]);
+ m.append_children(root, &[w]);
+ } else {
+ m.append_children(root, &[card]);
+ }
+ m.append_children(root_id, &[root]);
+ drop(m);
+ doc.resolve(0.0);
+ let r = doc.get_client_bounding_rect(card).unwrap();
+ [r.x, r.y, r.width, r.height]
+ };
+ let near = |got: [f64; 4], want: [f64; 4]| assert!(got.iter().zip(want).all(|(g, w)| (g - w).abs() < 0.05), "{got:?}, Chrome {want:?}");
+ near(rect(None), [379.05, 379.05, 206.19, 241.90]);
+ near(rect(Some("rotateX(10deg)")), [376.86, 348.18, 209.86, 263.30]);
+ }
}
diff --git a/vendor/vendor.toml b/vendor/vendor.toml
index 06fbaf75..1b7ea35d 100644
--- a/vendor/vendor.toml
+++ b/vendor/vendor.toml
@@ -70,7 +70,7 @@ exit = "a Blitz release that draws these"
path = "vendor/blitz-dom"
upstream = "crates.io:0.3.0-beta.4"
kind = "patch"
-reason = "inline flex/grid baselines, auto table columns, table row rects, inline image load events, SVG text fonts, SVG non-scaling strokes, url() filters; Blitz main's #1244 and #1246; a node removed in a mutation batch dropped from the style, form and title nodes the batch flushes (raea #24); a node in a 3D rendering context (or with a projection) placed again on every resolve, so it follows a preserve-3d parent whose transform a script set (raea #19); a ParseErrorReporter (not_applied.rs) on every author parse, keeping what stylo drops for the render to say once (raea #34); a bevy_text box whose lines are no finite size (an Apple bitmap-only face, which parley scales by a units-per-em of 0) measures 0 by 0, as bevy_text does; a family list ending in ; getBoundingClientRect and the geometry walks stop at a freed containing-block link instead of panicking on its key, and an element in a display: none subtree answers a zero rect (raea #108)"raea-bevy fallback" (bevy_text's FontSource::Family) falls to the collection's fallback families, not to serif nor to the CoreText pick (parley: NO_HOOK_FAMILY); an out-of-flow box painted by the stacking context between it and its containing block, inside its opacity group (raea #39); an SVG's paint properties from CSS written into its serialized source for usvg (raea #45); transform-box: stroke-box as fill-box under non-scaling-stroke, a stylesheet's stroke in the stroke box, and the non-scaling mark on an element with its own id (raea #50); an SVG element's rewritten style attribute without a leading `;` when its own declarations were transforms alone; transform-box: view-box's reference box at the origin of user space, not at the viewBox's x and y; every inline box laid out in full while its line is only measured, since Taffy's measure cache keeps a box's size without its baseline (raea #109); an inline element has a border edge only where its border has a style, so a plain span (border-style none, its width still `medium`) doesn't split the shaping at its edges and lose the kerning across them (docs/layout-reads.feature LR10); an app-bundled svg face of a family the page already gave is left out, as one given before the page's is removed (raea/text loadFont fetches Google's faces at import, LR10)"
+reason = "inline flex/grid baselines, auto table columns, table row rects, inline image load events, SVG text fonts, SVG non-scaling strokes, url() filters; Blitz main's #1244 and #1246; a node removed in a mutation batch dropped from the style, form and title nodes the batch flushes (raea #24); a node in a 3D rendering context (or with a projection) placed again on every resolve, so it follows a preserve-3d parent whose transform a script set (raea #19); a ParseErrorReporter (not_applied.rs) on every author parse, keeping what stylo drops for the render to say once (raea #34); a bevy_text box whose lines are no finite size (an Apple bitmap-only face, which parley scales by a units-per-em of 0) measures 0 by 0, as bevy_text does; a family list ending in ; getBoundingClientRect and the geometry walks stop at a freed containing-block link instead of panicking on its key, and an element in a display: none subtree answers a zero rect (raea #108)"raea-bevy fallback" (bevy_text's FontSource::Family) falls to the collection's fallback families, not to serif nor to the CoreText pick (parley: NO_HOOK_FAMILY); an out-of-flow box painted by the stacking context between it and its containing block, inside its opacity group (raea #39); an SVG's paint properties from CSS written into its serialized source for usvg (raea #45); transform-box: stroke-box as fill-box under non-scaling-stroke, a stylesheet's stroke in the stroke box, and the non-scaling mark on an element with its own id (raea #50); an SVG element's rewritten style attribute without a leading `;` when its own declarations were transforms alone; transform-box: view-box's reference box at the origin of user space, not at the viewBox's x and y; every inline box laid out in full while its line is only measured, since Taffy's measure cache keeps a box's size without its baseline (raea #109); an inline element has a border edge only where its border has a style, so a plain span (border-style none, its width still `medium`) doesn't split the shaping at its edges and lose the kerning across them (docs/layout-reads.feature LR10); an app-bundled svg face of a family the page already gave is left out, as one given before the page's is removed (raea/text loadFont fetches Google's faces at import, LR10); getBoundingClientRect through a perspective's projection (the node's Projection), and transformed_rect for a rect inside a node's box (LR10)"
exit = "a Blitz release with #1244/#1246 and these"
[parley_engine]