feat(anatomy): canvas and highlight composition in Rust (O1 + O3 tree-equal)
This commit is contained in:
1 parent
67d9af3f79
commit
1ec9316a73
8 files changed
+882
-33
No files matched your search
@@ -13,12 +13,10 @@
|
||||
|
||||
mod common;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use common::svg_tree::reread;
|
||||
use faunosteo_core::anatomy::svg::sanitize::is_reference_name;
|
||||
use faunosteo_core::anatomy::svg::serialize::serialize;
|
||||
use faunosteo_core::anatomy::svg::tree::{SVG_NS, parse_svg};
|
||||
use faunosteo_core::anatomy::svg::{Element, Node, SvgRejection, read_svg};
|
||||
use faunosteo_core::anatomy::svg::tree::SVG_NS;
|
||||
use faunosteo_core::anatomy::svg::{SvgRejection, read_svg};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
/// Rust outcomes that differ from the TS on purpose: file → expected Rust verdict.
|
||||
@@ -53,28 +51,6 @@ fn declared_spec(spec: &Value) -> Option<&'static str> {
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
})
|
||||
}
|
||||
|
||||
/// Removes the named attribute from every element of that local name (a declared removal).
|
||||
fn strip(tree: &mut Value, element: &str, attribute: &str) {
|
||||
if tree["name"] == element
|
||||
@@ -89,11 +65,6 @@ fn strip(tree: &mut Value, element: &str, attribute: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
/// The Rust output read again, as a tree.
|
||||
fn reread(element: &Element) -> Value {
|
||||
tree_value(&parse_svg(&serialize(element)).unwrap())
|
||||
}
|
||||
|
||||
fn is_space(text: &str) -> bool {
|
||||
text.chars().all(|c| matches!(c, ' ' | '\t' | '\n' | '\r'))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user