feat(anatomy): canvas and highlight composition in Rust (O1 + O3 tree-equal)

This commit is contained in:
bchanot committed 2026-10-14 23:50:14 +02:00
1 parent 67d9af3f79
commit 1ec9316a73
8 files changed
+882 -33

No files matched your search

+2
View File
@@ -6,6 +6,8 @@
clippy::expect_used
)]
pub mod svg_tree;
use faunosteo_core::domain::js::{find_lone_surrogate, parse_json};
use serde_json::Value;
+37
View File
@@ -0,0 +1,37 @@
//! SVG trees as structure for the R3 oracles: namespace, local name, attributes by qualified
//! name (sorted), children with text, the shape the TypeScript generators freeze.
#![allow(dead_code, clippy::unwrap_used)]
use std::collections::BTreeMap;
use faunosteo_core::anatomy::svg::serialize::serialize;
use faunosteo_core::anatomy::svg::tree::{SVG_NS, parse_svg};
use faunosteo_core::anatomy::svg::{Element, Node};
use serde_json::{Value, json};
pub fn tree_value(element: &Element) -> Value {
let attrs: BTreeMap<&str, &str> = element
.attrs
.iter()
.map(|a| (a.qname.as_str(), a.value.as_str()))
.collect();
let children: Vec<Value> = element
.children
.iter()
.map(|n| match n {
Node::Element(e) => tree_value(e),
Node::Text(t) => json!({ "text": t }),
})
.collect();
json!({
"ns": element.namespace.as_deref().unwrap_or(SVG_NS),
"name": element.local_name(),
"attrs": attrs,
"children": children,
})
}
/// The element serialised and read again by the core, as a tree.
pub fn reread(element: &Element) -> Value {
tree_value(&parse_svg(&serialize(element)).unwrap())
}