fix(anatomy): V1-2.2 marker layer and halo outside the drawing's group

Owner-approved lot B (brief 2026-11-01). The composition root is the
engine's (namespaces and frame); the drawing's root becomes a group and
the marker layer and halo are its siblings, so no root property reaches
a marker. Point hitboxes declare stroke none and visibleFill. Census over
the reader's whole allowlist; R3 references compared under the declared
transform; click proofs in three engines.
This commit is contained in:
bchanot committed 2026-11-01 00:39:57 +01:00
1 parent f1bb19b30b
commit 4f52f5e1c4
23 files changed
+933 -112

No files matched your search

+3 -1
View File
@@ -5,7 +5,8 @@
mod common;
use common::svg_tree::{
tree_value, view_names, with_ids_scoped_per_view, with_trigger_names_per_language,
tree_value, view_names, with_ids_scoped_per_view, with_isolated_layer,
with_trigger_names_per_language,
};
use faunosteo_core::anatomy::svg::tree::parse_svg;
use faunosteo_core::domain::js::parse_json;
@@ -44,6 +45,7 @@ fn golden(view: &str, sheet: &LoadedSheet) -> Value {
let mut frozen: Value = serde_json::from_str(&text).unwrap();
with_trigger_names_per_language(&mut frozen, &view_names(&sheet.document));
with_ids_scoped_per_view(&mut frozen, view);
with_isolated_layer(&mut frozen);
frozen
}
+4 -1
View File
@@ -12,7 +12,8 @@ mod common;
use std::collections::HashSet;
use common::svg_tree::{
reread, tree_value, view_names, with_ids_scoped_per_view, with_trigger_names_per_language,
reread, tree_value, view_names, with_ids_scoped_per_view, with_isolated_layer,
with_trigger_names_per_language,
};
use faunosteo_core::anatomy::compose::{
ComposeError, asset_id_of_view, compose_canvas, compose_highlight,
@@ -96,6 +97,7 @@ fn every_highlighted_view_equals_the_engine_tree() {
let label = format!("{} {} {view}", case["sheet"], case["observation"]["id"]);
let mut frozen = expected(case, &oracle);
with_trigger_names_per_language(&mut frozen, &view_names(document));
with_isolated_layer(&mut frozen);
assert_eq!(reread(&composed), frozen, "{label}");
}
}
@@ -109,6 +111,7 @@ fn canvas_golden(view: &str) -> Value {
let mut frozen: Value = serde_json::from_str(&text).unwrap();
with_trigger_names_per_language(&mut frozen, &view_names(&draft()));
with_ids_scoped_per_view(&mut frozen, view);
with_isolated_layer(&mut frozen);
frozen
}
+74
View File
@@ -101,3 +101,77 @@ pub fn view_names(
.map(|v| (v.id().to_owned(), v.name().fr.clone(), v.name().en.clone()))
.collect()
}
/// Owner brief 2026-10-30 (V1-2.2, three MEDIUM): the composition root is the engine's. Applied
/// to a frozen view tree before comparing, written apart from the core: the root keeps its
/// namespaces and `viewBox`; its other attributes and every child before the layer go into a
/// `<g>`; the halo filter leaves the drawing for an engine `<defs>` placed before the layer;
/// each point hitbox (a circle capturing on `all` with no stroke of its own) declares
/// `stroke="none"` and `pointer-events="visibleFill"`.
pub fn with_isolated_layer(tree: &mut Value) {
let root = tree.as_object_mut().unwrap();
let mut children = root["children"].as_array().unwrap().clone();
let mut layer = children.pop().unwrap();
let halo = take_halo(&mut children);
let attrs = root["attrs"].as_object().unwrap().clone();
let (kept, moved): (Vec<_>, Vec<_>) = attrs
.into_iter()
.partition(|(name, _)| ["xmlns", "xmlns:xlink", "viewBox"].contains(&name.as_str()));
let group = json!({
"ns": root["ns"], "name": "g",
"attrs": moved.into_iter().collect::<serde_json::Map<_, _>>(),
"children": children,
});
let mut out = vec![group];
if let Some(halo) = halo {
out.push(json!({ "ns": SVG_NS, "name": "defs", "attrs": {}, "children": [halo] }));
}
for marker in layer["children"].as_array_mut().unwrap() {
let circle = marker["name"] == "circle";
let attrs = marker["attrs"].as_object_mut().unwrap();
let hitbox = circle
&& attrs.get("pointer-events") == Some(&json!("all"))
&& !attrs.contains_key("stroke");
if hitbox {
attrs.insert("stroke".to_owned(), json!("none"));
attrs.insert("pointer-events".to_owned(), json!("visibleFill"));
}
}
out.push(layer);
root.insert(
"attrs".to_owned(),
Value::Object(kept.into_iter().collect()),
);
root.insert("children".to_owned(), Value::Array(out));
}
/// Removes `filter#osteo-halo` from the frozen drawing (and the `<defs>` the engine created for
/// it alone, placed first), answering it.
fn take_halo(children: &mut Vec<Value>) -> Option<Value> {
let first_is_engine_defs = children.first().is_some_and(|c| {
c["name"] == "defs"
&& c["children"]
.as_array()
.is_some_and(|k| k.len() == 1 && k[0]["attrs"]["id"] == "osteo-halo")
});
if first_is_engine_defs {
return Some(children.remove(0)["children"][0].clone());
}
for child in children.iter_mut() {
if let Some(found) = take_from(child) {
return Some(found);
}
}
None
}
fn take_from(node: &mut Value) -> Option<Value> {
let kids = node.get_mut("children")?.as_array_mut()?;
if let Some(at) = kids
.iter()
.position(|k| k["name"] == "filter" && k["attrs"]["id"] == "osteo-halo")
{
return Some(kids.remove(at));
}
kids.iter_mut().find_map(take_from)
}
+302
View File
@@ -0,0 +1,302 @@
//! V1-2.2 owner brief « arbitrages propriétaire sur les trois MEDIUM » (2026-10-30), defects 1
//! and 2: nothing the drawing sets reaches the engine's markers. Until then both composers
//! appended the marker layer to the drawing's own root, so the root's presentation attributes
//! reached every marker: inherited ones (`stroke-opacity="0"` or `stroke-dasharray` erased the
//! zone outlines and the detail trigger, `stroke-width` widened the point hitbox until the last
//! one took 13 of the 19 equine clicks) and whole-group ones (`opacity`, `display`). The
//! composition root is now the engine's (namespaces and frame only), the drawing sits in a
//! group of its own, and the layer and the halo filter are that group's siblings. The point
//! hitbox declares its paint and its capture rule (`stroke="none"`, `pointer-events=
//! "visibleFill"`), so its clickable area is its circle, whatever the page or the drawing set.
#![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)]
mod common;
use std::collections::HashSet;
use common::sheet_readers::{OPEN, sheet};
use faunosteo_core::anatomy::compose::{compose_canvas, compose_highlight};
use faunosteo_core::anatomy::svg::{Element, read_svg, sanitize};
use faunosteo_core::domain::sheet::AnatomicalSheetDocument;
use serde::Deserialize;
/// The attributes the composition root may carry: namespaces and the frame.
const ROOT_ATTRIBUTES: [&str; 3] = ["xmlns", "xmlns:xlink", "viewBox"];
/// Every presentation attribute the reader keeps on a drawing's root, with a value that would
/// change a marker if it reached one (the reader removes `class`, `style`, `transform`,
/// `filter`, `mask` and `clip-path` from the root, and refuses a root `visibility` other than
/// `visible`).
const ROOT_PROPERTIES: [&str; 22] = [
"stroke=\"#ff00ff\"",
"stroke-width=\"400\"",
"stroke-opacity=\"0\"",
"stroke-dasharray=\"0 1000\"",
"stroke-dashoffset=\"7\"",
"stroke-linecap=\"square\"",
"stroke-linejoin=\"miter\"",
"stroke-miterlimit=\"100\"",
"fill=\"none\"",
"fill-opacity=\"0\"",
"fill-rule=\"evenodd\"",
"opacity=\"0\"",
"display=\"none\"",
"visibility=\"visible\"",
"color=\"#00ff00\"",
"clip-rule=\"evenodd\"",
"color-interpolation-filters=\"sRGB\"",
"font-family=\"serif\"",
"font-size=\"90\"",
"font-weight=\"bold\"",
"systemLanguage=\"xx\"",
"id=\"drawing\"",
];
const BODY: &str = "<g><path d=\"M0 0h10v10z\"/></g>";
fn rooted(attrs: &str) -> String {
let root = OPEN.replace("viewBox", &format!("{attrs} viewBox"));
format!("{root}{BODY}</svg>")
}
fn horse() -> Element {
let text = common::repo_file("supabase/seed/anatomical-sheets/equine/draft/assets/horse.svg");
read_svg(&text).unwrap().root
}
fn draft() -> AnatomicalSheetDocument {
let text = common::repo_file("supabase/seed/anatomical-sheets/equine/draft/document.json");
AnatomicalSheetDocument::deserialize(serde_json::from_str::<serde_json::Value>(&text).unwrap())
.unwrap()
}
/// The composed views of `tree`'s `main` view: the canvas, and the PDF view of `hock`.
fn composed(tree: &Element) -> [Element; 2] {
let ids: HashSet<&str> = ["hock"].into_iter().collect();
[
compose_canvas(&sheet(), "main", tree).unwrap(),
compose_highlight(&sheet(), "main", tree.clone(), &ids, true).unwrap(),
]
}
fn names(element: &Element) -> Vec<&str> {
element.attrs.iter().map(|a| a.qname.as_str()).collect()
}
/// The marker layer is a child of the composition root, which carries no drawing attribute;
/// the drawing's root attributes and children live in a group the layer is not part of.
fn assert_isolated(composed: &Element, drawing: &Element, label: &str) {
let root_names = names(composed);
assert!(
root_names.iter().all(|n| ROOT_ATTRIBUTES.contains(n)),
"{label}: composition root carries {root_names:?}"
);
let layer = composed.element_children().last().unwrap();
assert_eq!(layer.qname, "g", "{label}");
assert!(layer.element_children().count() > 0, "{label}");
let group = composed.element_children().next().unwrap();
assert_eq!(group.qname, "g", "{label}: the drawing's group comes first");
assert!(!std::ptr::eq(group, layer), "{label}");
for attr in &drawing.attrs {
let framing = ["xmlns", "xmlns:xlink", "viewBox"].contains(&attr.qname.as_str());
if !framing && attr.qname != "id" {
assert_eq!(
group.attr(&attr.qname),
Some(attr.value.as_str()),
"{label}: the drawing keeps its own {}",
attr.qname
);
}
}
assert_eq!(
group.element_children().count(),
drawing.element_children().count(),
"{label}: the drawing's children stay in its group"
);
}
#[test]
fn no_root_property_of_the_drawing_reaches_a_marker() {
for property in ROOT_PROPERTIES {
let read = read_svg(&rooted(property)).unwrap_or_else(|e| panic!("{property}: {e:?}"));
assert!(read.removed.is_empty(), "{property}: {:?}", read.removed);
let [canvas, highlight] = composed(&read.root);
assert_isolated(&canvas, &read.root, &format!("canvas {property}"));
assert_isolated(&highlight, &read.root, &format!("pdf {property}"));
}
}
#[test]
fn every_root_property_at_once_stays_with_the_drawing() {
let all = ROOT_PROPERTIES.join(" ");
let read = read_svg(&rooted(&all)).unwrap();
let [canvas, highlight] = composed(&read.root);
assert_isolated(&canvas, &read.root, "canvas");
assert_isolated(&highlight, &read.root, "pdf");
}
/// The equine drawing keeps its root attributes (`font-family`, `font-size`) on its group and
/// its frame on the composition root, in both forms.
#[test]
fn the_equine_drawing_is_isolated_in_both_forms() {
let horse = horse();
let draft = draft();
let ids: HashSet<&str> = ["hock", "hip"].into_iter().collect();
let canvas = compose_canvas(&draft, "main", &horse).unwrap();
let highlight = compose_highlight(&draft, "main", horse.clone(), &ids, true).unwrap();
for (label, view) in [("canvas", &canvas), ("pdf", &highlight)] {
assert_isolated(view, &horse, label);
assert_eq!(view.attr("viewBox"), Some("0 0 2073.4 1629.4"), "{label}");
}
}
/// The halo filter is the engine's: outside the drawing's group, so no property of the
/// drawing (`color-interpolation-filters` on its root or its `<defs>`) changes the halo.
#[test]
fn the_halo_filter_lives_outside_the_drawing() {
let read = read_svg(&rooted(
"color-interpolation-filters=\"sRGB\" stroke-width=\"400\"",
))
.unwrap();
let [_, highlight] = composed(&read.root);
let group = highlight.element_children().next().unwrap();
let mut inside = Vec::new();
common::sheet_readers::holders(group, "osteo-halo", &mut inside);
assert!(inside.is_empty(), "the halo is not in the drawing's group");
let mut everywhere = Vec::new();
common::sheet_readers::holders(&highlight, "osteo-halo", &mut everywhere);
assert_eq!(everywhere.len(), 1);
}
/// Every interactive surface of the canvas: the point hitboxes declare `stroke="none"` and
/// capture on their circle only (`visibleFill`), the zones and the trigger declare their
/// stroke width; the visible twins never capture.
#[test]
fn every_interactive_surface_declares_its_geometry_and_capture() {
let draft = draft();
let canvas = compose_canvas(&draft, "main", &horse()).unwrap();
let layer = canvas.element_children().last().unwrap();
let mut hitboxes = 0;
for marker in layer.element_children() {
match (marker.attr("fill"), marker.attr("pointer-events")) {
(Some("transparent"), capture) => {
hitboxes += 1;
assert_eq!(marker.attr("stroke"), Some("none"), "{marker:?}");
assert_eq!(capture, Some("visibleFill"), "{marker:?}");
}
(_, Some("none")) => {}
(_, Some("all")) => assert!(marker.attr("stroke-width").is_some(), "{marker:?}"),
other => panic!("unexpected capture {other:?}"),
}
}
assert_eq!(hitboxes, 13, "the 13 points of the main view");
}
/// A value for each attribute the reader keeps, chosen to change a marker if it reached one.
fn hostile_value(name: &str) -> &'static str {
match name {
"fill" | "stroke" | "color" | "stop-color" | "flood-color" => "#ff00ff",
"opacity" | "fill-opacity" | "stroke-opacity" | "stop-opacity" | "flood-opacity" => "0",
"display" => "none",
"visibility" => "visible",
"fill-rule" | "clip-rule" => "evenodd",
"stroke-dasharray" => "0 1000",
"stroke-linecap" => "square",
"stroke-linejoin" => "miter",
"preserveAspectRatio" => "xMinYMin slice",
"maskUnits" | "maskContentUnits" | "clipPathUnits" => "userSpaceOnUse",
"color-interpolation-filters" => "sRGB",
"font-family" => "serif",
"font-weight" => "bold",
"systemLanguage" => "xx",
"points" => "0,0 9,9 0,9",
"d" => "M0 0h9",
_ => "400",
}
}
/// CSS a drawing's descendant may carry in `style`, including what could act outside its own
/// subtree in an HTML page (stacking, positioning, compositing, outlines, view transitions).
/// The browser probe of 2026-11-01 drew a full-frame opaque rectangle with each of them below
/// the layer: no marker pixel changed and every point kept its click, in the three engines.
const DESCENDANT_STYLES: [&str; 17] = [
"position:relative;z-index:2147483647",
"position:fixed;inset:0;z-index:9999",
"mix-blend-mode:normal;isolation:isolate",
"view-transition-name:hijack",
"outline:4000px solid #ff00ff;outline-offset:0",
"contain:strict;content-visibility:visible",
"paint-order:markers stroke fill",
"stroke:#ff00ff;stroke-width:100000",
"pointer-events:all;cursor:pointer",
"opacity:0",
"display:none",
"visibility:hidden",
"translate:0 0 9999px",
"order:-1;float:right",
"anchor-name:--x;position-anchor:--x",
"fill-opacity:0;stroke-opacity:0",
"font-size:900px",
];
fn layer_and_defs(composed: &Element) -> String {
composed
.element_children()
.skip(1)
.map(faunosteo_core::anatomy::svg::serialize::serialize)
.collect()
}
/// Census over the reader's whole attribute allowlist (owner brief 2026-11-01): whatever the
/// drawing's root or descendants keep, the composition root carries only namespaces and the
/// frame, and the layer and the halo serialise byte for byte as with a plain drawing.
#[test]
fn nothing_the_reader_keeps_changes_the_layer_or_the_halo() {
let plain = read_svg(&rooted("")).unwrap().root;
let expected = composed(&plain).map(|view| layer_and_defs(&view));
let structural = [
"xmlns",
"xmlns:xlink",
"viewBox",
"id",
"href",
"xlink:href",
"style",
];
let mut root_cases: Vec<String> = sanitize::ALLOWED_ATTRIBUTES
.iter()
.filter(|name| !structural.contains(name))
.map(|name| format!("{name}=\"{}\"", hostile_value(name)))
.collect();
root_cases.push(String::new());
for attrs in &root_cases {
let text = rooted(attrs).replace(BODY, &format!("<g {attrs}>{BODY}</g>"));
let read = read_svg(&text).unwrap_or_else(|e| panic!("{attrs}: {e:?}"));
for (view, want) in composed(&read.root).iter().zip(&expected) {
assert!(
names(view).iter().all(|n| ROOT_ATTRIBUTES.contains(n)),
"{attrs}"
);
assert_eq!(&layer_and_defs(view), want, "{attrs}");
}
}
for style in DESCENDANT_STYLES {
let body = format!(
"<g style=\"{style}\">{BODY}<rect width=\"9\" height=\"9\" style=\"{style}\"/></g>"
);
let read = read_svg(&rooted("").replace(BODY, &body)).unwrap();
let kept = faunosteo_core::anatomy::svg::serialize::serialize(&read.root);
assert!(
kept.contains(style),
"{style}: the reader keeps it, {:?}",
read.removed
);
for (view, want) in composed(&read.root).iter().zip(&expected) {
assert!(
names(view).iter().all(|n| ROOT_ATTRIBUTES.contains(n)),
"{style}"
);
assert_eq!(&layer_and_defs(view), want, "{style}");
}
}
}
+7 -9
View File
@@ -1,7 +1,7 @@
//! V1-2.2 owner brief 2026-10-30: the drawing's root never decides whether the engine's markers
//! show. Both composers append the marker layer as the root's last child (the PDF view keeps the
//! drawing's root, the canvas copies its attributes), so the layer inherits the root's
//! `visibility`; a drawing `<svg visibility="hidden">` whose children set `visible` back read
//! show. Both composers appended the marker layer as the root's last child, so the layer
//! inherited the root's `visibility` (the composition root is the engine's since the three-MEDIUM
//! brief, `svg_marker_isolation`); a drawing `<svg visibility="hidden">` whose children set `visible` back read
//! clean before and showed its drawing without a single marker (security review, MEDIUM). The
//! reader refuses a root `visibility` other than `visible` (`root_visibility`); the cleaning,
//! the preview, the verdict and the PDF snapshot gate answer it; both composers refuse such a
@@ -189,12 +189,10 @@ fn equivalent_styles_never_hide_the_layer() {
assert!(layer_shows(&canvas.unwrap()) && layer_shows(&highlight.unwrap()));
}
/// The other root properties that reach the layer. Removed by the reader before V1-2.2: the
/// paint servers and effects (`filter`, `mask`, `clip-path`), `transform`, `class`, `style`.
/// Kept: `opacity` and `display` act on the whole root, drawing and markers alike (the
/// browser proofs of RUST.md §12.10 show both); `fill` and `fill-opacity` are set on every PDF
/// marker. The stroke properties no marker sets (`stroke-opacity`, `stroke-dasharray`,
/// `stroke-width` on the hitbox) are an open owner decision, not covered here.
/// The other root properties. Removed by the reader before V1-2.2: the paint servers and
/// effects (`filter`, `mask`, `clip-path`), `transform`, `class`, `style`. Kept: `opacity`,
/// `display` and the paint, which since the three-MEDIUM brief stay on the drawing's group and
/// never reach a marker (`svg_marker_isolation`); every PDF marker still sets its fill.
#[test]
fn other_root_properties_are_removed_or_act_on_the_whole_view() {
for name in ["filter", "mask", "clip-path"] {