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
#27: the regression test moves to raea-runtime-page, through the frame diff
James Dimachkie07908a430d30
diff --git a/runtime/page/src/elements.rs b/runtime/page/src/elements.rsindex 9c4e7273..eb7f8a3e 100644--- a/runtime/page/src/elements.rs+++ b/runtime/page/src/elements.rs@@ -288,6 +288,35 @@ mod svg_namespace_tests {assert!(!svg_owned("title", html), "a title under a <foreignObject> is HTML's");assert!(svg_inside("svg", html), "an <svg> in that HTML starts SVG again");}++ /// An SVG <text> keeps SVG's attribute names from frame to frame, as an animated `fontSize` changes them: the walk+ /// gives it `$ns`, and a later frame's diff sends only what changed, so the page tells it's SVG's by its namespace+ #[test]+ fn an_svg_texts_attributes_keep_their_svg_names_from_frame_to_frame() {+ use bevy::prelude::{Entity, UVec2};+ use raea_core_wire::tree::{Tree, Want};+ use serde_json::{Value, json};+ let mut docs = raea_sys_page::Docs::default();+ let doc = docs.open(Entity::PLACEHOLDER, raea_sys_page::Page { size: UVec2::new(640, 360), scale: 1.0 });+ let mut nodes = raea_sys_page::ops::Nodes::new(doc.root_node().id);+ let (mut tree, order) = (Tree::default(), std::collections::HashMap::from([(0, vec![1]), (1, vec![2]), (2, vec![3])]));+ let want = |id, parent, kind: &str, props: Value, text: Option<&str>| Want { id, parent, kind: kind.into(), props: props.as_object().unwrap().clone(), text: text.map(Into::into), path: String::new() };+ let mut attrs_at = |size: u32, anchor: &str| {+ let frame = [+ want(1, 0, "svg", json!({"width": 640, "height": 360}), None),+ want(2, 1, "text", json!({"$ns": "svg", "x": 320, "y": 190, "fontSize": size, "textAnchor": anchor}), None),+ want(3, 2, "text", json!({}), Some("Middle")),+ ];+ raea_sys_page::ops::apply(doc, &mut nodes, tree.diff(&frame, &order).0);+ let el = doc.get_node(nodes.by_id[&2]).unwrap().element_data().unwrap();+ el.attrs().iter().map(|a| format!("{}={}", a.name.local, a.value)).collect::<Vec<_>>()+ };+ let first = attrs_at(48, "middle");+ assert!(first.contains(&"font-size=48".into()) && first.contains(&"text-anchor=middle".into()), "{first:?}");+ let next = attrs_at(60, "end");+ assert!(next.contains(&"font-size=60".into()) && next.contains(&"text-anchor=end".into()), "{next:?}");+ assert!(!next.iter().any(|a| a.starts_with("fontsize=") || a.starts_with("textanchor=")), "lowercased as HTML: {next:?}");+ }}#[cfg(test)]diff --git a/systems/page-ops/src/lib.rs b/systems/page-ops/src/lib.rsindex 0ca04e9b..d65d4deb 100644--- a/systems/page-ops/src/lib.rs+++ b/systems/page-ops/src/lib.rs@@ -416,44 +416,6 @@ mod tests {assert_eq!(attr_name("strokeWidth", true).as_deref(), Some("stroke-width"));assert_eq!(attr_name("viewBox", true).as_deref(), Some("viewBox"));}-- /// An SVG <text> made in SVG's namespace (`$ns`) keeps SVG's attribute names when React changes them, as an animated- /// `fontSize` does every frame: `font-size`, never the lowercased `fontsize` usvg doesn't know.- #[test]- fn an_svg_texts_attributes_keep_their_svg_names_when_they_change() {- use blitz_dom::DocumentConfig;- use serde_json::json;- let mut doc = BaseDocument::new(DocumentConfig::default());- let body = {- let mut m = doc.mutate();- let root = m.doc.root_node().id;- let html = m.create_element(super::attrs::name("html", false), vec![]);- m.append_children(root, &[html]);- let body = m.create_element(super::attrs::name("body", false), vec![]);- m.append_children(html, &[body]);- body- };- let mut nodes = Nodes::new(body);- let props = |v: Value| v.as_object().unwrap().clone();- apply(&mut doc, &mut nodes, vec![- Op::Create { id: 1, kind: "svg".into(), props: props(json!({"width": 640, "height": 360})), text: None },- Op::Create { id: 2, kind: "text".into(), props: props(json!({"$ns": "svg", "x": 320, "y": 190, "fontSize": 48, "textAnchor": "middle"})), text: Some("Middle".into()) },- Op::Append { parent: 0, child: 1 },- Op::Append { parent: 1, child: 2 },- ]);- let text = nodes.by_id[&2];- let attrs = |doc: &BaseDocument| -> Vec<(String, String)> {- let el = doc.get_node(text).unwrap().element_data().unwrap();- el.attrs().iter().map(|a| (a.name.local.to_string(), a.value.to_string())).collect()- };- let has = |a: &[(String, String)], k: &str, v: &str| a.iter().any(|(n, x)| n == k && x == v);- let made = attrs(&doc);- assert!(has(&made, "font-size", "48") && has(&made, "text-anchor", "middle"), "{made:?}");- apply(&mut doc, &mut nodes, vec![Op::Update { id: 2, set: Some(props(json!({"fontSize": 60, "textAnchor": "end"}))), unset: None, text: None }]);- let changed = attrs(&doc);- assert!(has(&changed, "font-size", "60") && has(&changed, "text-anchor", "end"), "{changed:?}");- assert!(!changed.iter().any(|(n, _)| n == "fontsize" || n == "textanchor"), "lowercased as HTML: {changed:?}");- }}/// A menu's items (`menuItem`: a `menuitem` attribute), in document order.