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:
1 parent
f1bb19b30b
commit
4f52f5e1c4
23 files changed
+933
-112
No files matched your search
@@ -1,9 +1,9 @@
|
||||
//! Composition of one view (`docs/ANNOTATION-RENDERING.md`): the sanitised drawing framed on
|
||||
//! the view, with its annotation layer last. Two forms, as the TypeScript has them: the
|
||||
//! editor canvas (`apps/app/src/anatomy/drawing.ts`: a fresh root, `0 0 100 100` when no box
|
||||
//! is known, the interactive layer) and the PDF highlight (`packages/anatomy/src/render/
|
||||
//! compose.ts`: the asset's root framed in place, the selected markers only, recoloured, the
|
||||
//! halo filter on request). Both take a sanitised tree, never text.
|
||||
//! editor canvas (`apps/app/src/anatomy/drawing.ts`: `0 0 100 100` when no frame is known, the
|
||||
//! interactive layer) and the PDF highlight (`packages/anatomy/src/render/compose.ts`: no
|
||||
//! `viewBox` when no frame is known, the selected markers only, recoloured, the halo filter on
|
||||
//! request). Both take a sanitised tree, never text.
|
||||
//!
|
||||
//! The canvas is inlined into the page, where `#id` resolves against the whole document: its
|
||||
//! ids and the references to them are scoped to the view (`fv.<view id>.<id>`, owner decision
|
||||
@@ -13,19 +13,23 @@
|
||||
//! own and keeps the drawing's ids, so it never holds one the composition writes
|
||||
//! (`svg::refs::RESERVED_IDS`, the halo filter): the reader refuses such a drawing and both
|
||||
//! composers refuse such a tree.
|
||||
//! Both forms append the marker layer as the root's last child, so the root never hides it: a
|
||||
//! root `visibility` other than `visible` is refused by the reader and by both composers.
|
||||
//! Both frame the view on `frame::view_frame` (the view's box, else the drawing's `viewBox` read
|
||||
//! as a browser reads it), the frame the verdict and the preview measure the annotations against
|
||||
//! (V1-2.2 owner brief 2026-10-30, defect 3); the canvas falls back to `0 0 100 100`, the PDF
|
||||
//! view to no `viewBox`. The drawing's `preserveAspectRatio` is dropped: the default
|
||||
//! `xMidYMid meet` shows the whole frame whatever the box (a `slice` would crop it where the
|
||||
//! raster's aspect is clamped or the canvas box is not the frame's).
|
||||
//!
|
||||
//! The composition root is the engine's (V1-2.2 owner brief 2026-10-30): the namespaces and the
|
||||
//! frame only. The frame is `frame::view_frame` (the view's box, else the drawing's `viewBox` read
|
||||
//! as a browser reads it), the one the verdict and the preview measure the annotations against;
|
||||
//! with no `preserveAspectRatio` the default `xMidYMid meet` shows the whole frame whatever the
|
||||
//! box. The drawing's root becomes a
|
||||
//! `<g>` keeping its other attributes and its children, and the marker layer (and the PDF's halo
|
||||
//! filter, in a `<defs>` of the engine) are appended as that group's siblings: no property the
|
||||
//! drawing sets, inherited (`stroke-width`, `stroke-opacity`, `stroke-dasharray`, `fill-rule`,
|
||||
//! `visibility`…) or acting on a whole group (`opacity`, `display`), reaches a marker or the
|
||||
//! halo. A root `visibility` other than `visible` stays refused by the reader and by both
|
||||
//! composers (accepted fix of 2026-10-30).
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use super::frame::view_frame;
|
||||
use super::layer::{LayerError, find_view, render_layer};
|
||||
use super::layer::{LayerError, find_view, render_composed_layer};
|
||||
pub use super::svg::refs::HALO_FILTER_ID;
|
||||
use super::svg::refs::holds_reserved_id;
|
||||
use super::svg::sanitize::check_root_visibility;
|
||||
@@ -54,8 +58,9 @@ pub enum ComposeError {
|
||||
/// composes it. Fail-closed: the reader refuses it (`reserved_id`), so only a tree that did
|
||||
/// not come out of `read_svg` reaches it, a composed view given back included.
|
||||
ReservedId,
|
||||
/// The drawing's root carries a `visibility` other than `visible`, which the marker layer
|
||||
/// would inherit. Fail-closed: the reader refuses it (`root_visibility`).
|
||||
/// The drawing's root carries a `visibility` other than `visible` (the marker layer inherited
|
||||
/// it before the root became the engine's). Fail-closed: the reader refuses it
|
||||
/// (`root_visibility`).
|
||||
RootVisibility,
|
||||
}
|
||||
|
||||
@@ -98,32 +103,62 @@ pub fn compose_canvas(
|
||||
if check_root_visibility(asset).is_err() {
|
||||
return Err(ComposeError::RootVisibility);
|
||||
}
|
||||
let mut root = Element {
|
||||
qname: "svg".to_owned(),
|
||||
namespace: asset.namespace.clone(),
|
||||
attrs: asset
|
||||
.attrs
|
||||
.iter()
|
||||
.filter(|a| !matches!(a.qname.as_str(), "width" | "height" | "preserveAspectRatio"))
|
||||
.cloned()
|
||||
.collect(),
|
||||
children: asset.children.clone(),
|
||||
};
|
||||
let view_box = view_frame(view, asset).map_or_else(
|
||||
|| CANVAS_FALLBACK_VIEW_BOX.to_owned(),
|
||||
|frame| frame.view_box(),
|
||||
);
|
||||
root.set_attr("viewBox", view_box);
|
||||
let mut root = isolated(asset.clone(), Some(view_box));
|
||||
let scope = id_scope(view_id);
|
||||
scope_ids(&mut root, &scope);
|
||||
if !references_scoped(&root, &scope) {
|
||||
return Err(ComposeError::UnscopedReference);
|
||||
}
|
||||
let layer = render_layer(document, view_id, &HashSet::new())?;
|
||||
let layer = render_composed_layer(document, view_id, &HashSet::new())?;
|
||||
root.children.push(Node::Element(checked(layer)?));
|
||||
Ok(root)
|
||||
}
|
||||
|
||||
/// Root attributes with no meaning on a `<g>`: the frame is the engine's, the size is the
|
||||
/// page's or the raster's.
|
||||
const ROOT_ONLY: [&str; 7] = [
|
||||
"viewBox",
|
||||
"preserveAspectRatio",
|
||||
"version",
|
||||
"width",
|
||||
"height",
|
||||
"x",
|
||||
"y",
|
||||
];
|
||||
|
||||
/// The composition root framed on `view_box`, holding the drawing as its one child: a `<g>`
|
||||
/// with the drawing root's attributes (namespace declarations and `ROOT_ONLY` aside) and its
|
||||
/// children. The caller appends the engine's elements after it.
|
||||
fn isolated(asset: Element, view_box: Option<String>) -> Element {
|
||||
let (namespaces, attrs): (Vec<_>, Vec<_>) = asset
|
||||
.attrs
|
||||
.into_iter()
|
||||
.partition(|a| a.qname == "xmlns" || a.qname == "xmlns:xlink");
|
||||
let drawing = Element {
|
||||
qname: "g".to_owned(),
|
||||
namespace: asset.namespace.clone(),
|
||||
attrs: attrs
|
||||
.into_iter()
|
||||
.filter(|a| !ROOT_ONLY.contains(&a.qname.as_str()))
|
||||
.collect(),
|
||||
children: asset.children,
|
||||
};
|
||||
let mut root = Element {
|
||||
qname: "svg".to_owned(),
|
||||
namespace: asset.namespace,
|
||||
attrs: namespaces,
|
||||
children: vec![Node::Element(drawing)],
|
||||
};
|
||||
if let Some(view_box) = view_box {
|
||||
root.set_attr("viewBox", view_box);
|
||||
}
|
||||
root
|
||||
}
|
||||
|
||||
/// The prefix of a view's ids in its canvas. Stable ids hold no `.`, so the scope of one view
|
||||
/// is never the start of another's, and no page id starts with `fv.`.
|
||||
pub fn id_scope(view_id: &str) -> String {
|
||||
@@ -180,7 +215,7 @@ fn scope_ids(element: &mut Element, scope: &str) {
|
||||
pub fn compose_highlight(
|
||||
document: &AnatomicalSheetDocument,
|
||||
view_id: &str,
|
||||
mut asset: Element,
|
||||
asset: Element,
|
||||
annotation_ids: &HashSet<&str>,
|
||||
halo: bool,
|
||||
) -> Result<Element, ComposeError> {
|
||||
@@ -191,20 +226,16 @@ pub fn compose_highlight(
|
||||
if check_root_visibility(&asset).is_err() {
|
||||
return Err(ComposeError::RootVisibility);
|
||||
}
|
||||
match view_frame(view, &asset) {
|
||||
Some(frame) => asset.set_attr("viewBox", frame.view_box()),
|
||||
None => asset.remove_attr("viewBox"),
|
||||
}
|
||||
asset.remove_attr("width");
|
||||
asset.remove_attr("height");
|
||||
asset.remove_attr("preserveAspectRatio");
|
||||
let view_box = view_frame(view, &asset).map(|frame| frame.view_box());
|
||||
let mut root = isolated(asset, view_box);
|
||||
if halo {
|
||||
add_halo_filter(&mut asset);
|
||||
let defs = Element::svg("defs", Vec::new(), vec![Node::Element(halo_filter())]);
|
||||
root.children.push(Node::Element(defs));
|
||||
}
|
||||
let layer = render_layer(document, view_id, &HashSet::new())?;
|
||||
let layer = render_composed_layer(document, view_id, &HashSet::new())?;
|
||||
let layer = highlight_layer(layer, annotation_ids, halo);
|
||||
asset.children.push(Node::Element(checked(layer)?));
|
||||
Ok(asset)
|
||||
root.children.push(Node::Element(checked(layer)?));
|
||||
Ok(root)
|
||||
}
|
||||
|
||||
/// The layer reduced to the selected annotations, recoloured, every `data-*` dropped.
|
||||
@@ -235,31 +266,6 @@ fn highlight_element(mut element: Element, halo: bool) -> Element {
|
||||
element
|
||||
}
|
||||
|
||||
/// The halo filter in the first `<defs>` of the drawing, else in a new `<defs>` placed first.
|
||||
fn add_halo_filter(root: &mut Element) {
|
||||
if !append_to_first_defs(root) {
|
||||
let defs = Element::svg("defs", Vec::new(), vec![Node::Element(halo_filter())]);
|
||||
root.children.insert(0, Node::Element(defs));
|
||||
}
|
||||
}
|
||||
|
||||
/// Appends the halo to the first `<defs>` below `element` (document order).
|
||||
fn append_to_first_defs(element: &mut Element) -> bool {
|
||||
for child in &mut element.children {
|
||||
let Node::Element(child) = child else {
|
||||
continue;
|
||||
};
|
||||
if child.qname == "defs" {
|
||||
child.children.push(Node::Element(halo_filter()));
|
||||
return true;
|
||||
}
|
||||
if append_to_first_defs(child) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
fn halo_filter() -> Element {
|
||||
let blur = |std: &str, result: &str| {
|
||||
Node::Element(Element::svg(
|
||||
|
||||
@@ -27,14 +27,38 @@ pub fn find_view<'a>(
|
||||
}
|
||||
|
||||
/// `renderAnnotationLayer({ document, viewId, states })`: `states` holds the ids marked
|
||||
/// `data-state="current"`.
|
||||
/// `data-state="current"`. The R3 tree, kept for the seed review drawings
|
||||
/// (`curation::draft::app_review`); the composers draw `render_composed_layer`.
|
||||
pub fn render_layer(
|
||||
document: &AnatomicalSheetDocument,
|
||||
view_id: &str,
|
||||
states: &HashSet<&str>,
|
||||
) -> Result<Element, LayerError> {
|
||||
layer(document, view_id, states, false)
|
||||
}
|
||||
|
||||
/// The layer the composers draw (V1-2.2 owner brief 2026-10-30): the R3 tree with each point
|
||||
/// hitbox declaring its paint and its capture rule, `stroke="none"` and
|
||||
/// `pointer-events="visibleFill"`, so its clickable area is its circle whatever stroke the page
|
||||
/// or a drawing would give it (under `pointer-events="all"` a stroke widens the hit area even
|
||||
/// when nothing paints it). The zones and the trigger already declare theirs.
|
||||
pub fn render_composed_layer(
|
||||
document: &AnatomicalSheetDocument,
|
||||
view_id: &str,
|
||||
states: &HashSet<&str>,
|
||||
) -> Result<Element, LayerError> {
|
||||
layer(document, view_id, states, true)
|
||||
}
|
||||
|
||||
fn layer(
|
||||
document: &AnatomicalSheetDocument,
|
||||
view_id: &str,
|
||||
states: &HashSet<&str>,
|
||||
declared_hitbox: bool,
|
||||
) -> Result<Element, LayerError> {
|
||||
let view = find_view(document, view_id).ok_or(LayerError::UnknownView)?;
|
||||
let context = Context {
|
||||
declared_hitbox,
|
||||
twin_opacity: if view.is_main() { "0.65" } else { "0.5" },
|
||||
categories: document
|
||||
.categories
|
||||
@@ -59,6 +83,8 @@ pub fn render_layer(
|
||||
}
|
||||
|
||||
struct Context<'a> {
|
||||
/// The hitbox declares `stroke="none"` and captures on its circle only (composed form).
|
||||
declared_hitbox: bool,
|
||||
twin_opacity: &'static str,
|
||||
/// Last duplicate wins, as a JavaScript `Map` built from the list.
|
||||
categories: HashMap<&'a str, Option<&'a str>>,
|
||||
@@ -154,9 +180,14 @@ impl Context<'_> {
|
||||
("cy", js_number(cy)),
|
||||
("r", js_number(r)),
|
||||
("fill", "transparent".to_owned()),
|
||||
("pointer-events", "all".to_owned()),
|
||||
("style", "cursor:pointer".to_owned()),
|
||||
];
|
||||
if self.declared_hitbox {
|
||||
hitbox.push(("stroke", "none".to_owned()));
|
||||
hitbox.push(("pointer-events", "visibleFill".to_owned()));
|
||||
} else {
|
||||
hitbox.push(("pointer-events", "all".to_owned()));
|
||||
}
|
||||
hitbox.push(("style", "cursor:pointer".to_owned()));
|
||||
hitbox.extend(data.iter().cloned());
|
||||
let mut visible: Attrs = vec![
|
||||
("cx", js_number(cx)),
|
||||
|
||||
@@ -14,7 +14,7 @@ pub use tree::{Element, Node, SvgRejection};
|
||||
|
||||
/// Bounds, parses, sanitises and checks the references of an SVG text: no cycle, within the
|
||||
/// expansion budget, each naming an id the drawing defines; no id the composition writes and
|
||||
/// no root `visibility` the marker layer would inherit.
|
||||
/// no root `visibility` other than `visible`.
|
||||
pub fn read_svg(text: &str) -> Result<Sanitized, SvgRejection> {
|
||||
let root = tree::parse_svg(text)?;
|
||||
let sanitized = sanitize::sanitize(root)?;
|
||||
|
||||
@@ -18,8 +18,8 @@ use super::tree::{Element, Node, SvgRejection};
|
||||
/// Expanded elements a drawing may instantiate (the product's drawing: a few thousand).
|
||||
pub const MAX_EXPANDED_ELEMENTS: u64 = 50_000;
|
||||
|
||||
/// The PDF highlight's filter (`compose::compose_highlight`), written into the drawing's own
|
||||
/// document: the PDF view keeps the drawing's ids.
|
||||
/// The PDF highlight's filter (`compose::compose_highlight`), written in an engine `<defs>` of
|
||||
/// the composed document next to the drawing: the PDF view keeps the drawing's ids.
|
||||
pub const HALO_FILTER_ID: &str = "osteo-halo";
|
||||
|
||||
/// Every id the composition writes next to the drawing's ids. A drawing defining one would
|
||||
|
||||
@@ -44,7 +44,8 @@ const ALLOWED_ELEMENTS: [&str; 28] = [
|
||||
"use",
|
||||
];
|
||||
|
||||
const ALLOWED_ATTRIBUTES: [&str; 77] = [
|
||||
/// Public for the marker isolation census (`tests/svg_marker_isolation.rs`).
|
||||
pub const ALLOWED_ATTRIBUTES: [&str; 77] = [
|
||||
"id",
|
||||
"class",
|
||||
"d",
|
||||
@@ -435,10 +436,10 @@ fn value_acceptable(qname: &str, value: &str) -> bool {
|
||||
}
|
||||
|
||||
/// The root lets the engine's marker layer show: no `visibility`, or `visible` (CSS whitespace
|
||||
/// and letter case aside). Both composers append the layer as the root's last child, so it
|
||||
/// inherits the root's `visibility`, which the drawing's own children can set back to
|
||||
/// `visible`: any other value, `hidden`, `collapse`, a CSS-wide keyword or an unreadable one,
|
||||
/// is refused (V1-2.2 security review, owner brief 2026-10-30). The root's `style` and `class`
|
||||
/// and letter case aside). Until the composition root became the engine's, the layer inherited
|
||||
/// the root's `visibility`, which the drawing's own children can set back to `visible`: any
|
||||
/// other value, `hidden`, `collapse`, a CSS-wide keyword or an unreadable one, stays refused
|
||||
/// (V1-2.2 security review, owner brief 2026-10-30), the composers checking it too. The root's `style` and `class`
|
||||
/// are removed by `sanitize`, so this attribute is the one way left to set it.
|
||||
pub fn check_root_visibility(root: &Element) -> Result<(), SvgRejection> {
|
||||
let visible = root.attr("visibility").is_none_or(|value| {
|
||||
|
||||
@@ -111,9 +111,9 @@ pub enum SvgRejection {
|
||||
/// An id the composition writes into the drawing's own document (`refs::RESERVED_IDS`):
|
||||
/// the drawing's element would stand in for the engine's (V1-2.2, owner brief 2026-10-30).
|
||||
ReservedId,
|
||||
/// A `visibility` on the root other than `visible`: the engine's marker layer, appended as
|
||||
/// the root's last child, inherits it, while the drawing's own children can set `visible`
|
||||
/// back (V1-2.2 security review, owner brief 2026-10-30).
|
||||
/// A `visibility` on the root other than `visible`: until the composition root became the
|
||||
/// engine's, the marker layer inherited it while the drawing's own children set `visible`
|
||||
/// back (V1-2.2 security review, owner brief 2026-10-30); kept as a reader rule.
|
||||
RootVisibility,
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
//! uses. Written under `draft/review/app-<view>.svg` so the markers and the framing can be
|
||||
//! compared outside the browser.
|
||||
//!
|
||||
//! Declared difference (V1-2.2, owner brief 2026-10-30): the application draws the drawing in a
|
||||
//! group of its own under an engine root and declares each point hitbox's stroke and capture
|
||||
//! (`compose`, `layer::render_composed_layer`); this review drawing keeps the R5 form, a seed
|
||||
//! resource never regenerated without the owner.
|
||||
//!
|
||||
//! Declared difference: the R3 owner decision (2026-10-15) gives a trigger without a name of
|
||||
//! its own the opened view's name in each language; the TypeScript renderer wrote the French
|
||||
//! name twice (`svg_compare::TriggerNames`).
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"] {
|
||||
|
||||
Reference in new issue
Block a user