fix(anatomy): V1-2.2 the visible wins on the editor canvas

Owner decision 2026-11-01. The canvas paints and hits every point hitbox,
then every zone and trigger, then every visible twin, which captures on
what it paints; a junction's disc is no longer taken by the zone drawn
after it. The PDF view keeps the document order and its bytes. Click
spec: the five fixme run unmarked, six projects incl. a 320 px phone.
This commit is contained in:
bchanot committed 2026-11-01 00:56:11 +01:00
1 parent e67715025c
commit 9c606aa567
13 files changed
+504 -64

No files matched your search

+2 -2
View File
@@ -29,7 +29,7 @@
use std::collections::HashSet;
use super::frame::view_frame;
use super::layer::{LayerError, find_view, render_composed_layer};
use super::layer::{LayerError, find_view, render_canvas_layer, 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;
@@ -113,7 +113,7 @@ pub fn compose_canvas(
if !references_scoped(&root, &scope) {
return Err(ComposeError::UnscopedReference);
}
let layer = render_composed_layer(document, view_id, &HashSet::new())?;
let layer = render_canvas_layer(document, view_id, &HashSet::new())?;
root.children.push(Node::Element(checked(layer)?));
Ok(root)
}
+68 -19
View File
@@ -34,10 +34,10 @@ pub fn render_layer(
view_id: &str,
states: &HashSet<&str>,
) -> Result<Element, LayerError> {
layer(document, view_id, states, false)
layer(document, view_id, states, Form::Review)
}
/// The layer the composers draw (V1-2.2 owner brief 2026-10-30): the R3 tree with each point
/// The layer of the PDF view (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
@@ -47,18 +47,50 @@ pub fn render_composed_layer(
view_id: &str,
states: &HashSet<&str>,
) -> Result<Element, LayerError> {
layer(document, view_id, states, true)
layer(document, view_id, states, Form::Highlight)
}
/// The layer of the editor canvas: the PDF view's elements in three passes, each in document
/// order, every point hitbox, then every filled shape (zones and triggers), then every visible
/// twin, which captures on what it paints (`visiblePainted`). « The visible wins » (owner
/// decision 2026-11-01): a vertebral junction's disc is no longer taken by the zone drawn
/// after it, a zone keeps what no disc covers, a hitbox ring what neither covers.
pub fn render_canvas_layer(
document: &AnatomicalSheetDocument,
view_id: &str,
states: &HashSet<&str>,
) -> Result<Element, LayerError> {
layer(document, view_id, states, Form::Canvas)
}
/// Which product draws the layer.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum Form {
/// The R3 tree, for the seed review drawings.
Review,
/// Declared hitboxes, document order.
Highlight,
/// Declared hitboxes, three passes, capturing twins.
Canvas,
}
/// The pass an element is painted (and hit) in, on the canvas.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum Pass {
Hitbox,
Shape,
Twin,
}
fn layer(
document: &AnatomicalSheetDocument,
view_id: &str,
states: &HashSet<&str>,
declared_hitbox: bool,
form: Form,
) -> Result<Element, LayerError> {
let view = find_view(document, view_id).ok_or(LayerError::UnknownView)?;
let context = Context {
declared_hitbox,
form,
twin_opacity: if view.is_main() { "0.65" } else { "0.5" },
categories: document
.categories
@@ -68,13 +100,23 @@ fn layer(
view_names: document.views.iter().map(|v| (v.id(), v.name())).collect(),
states,
};
let children = document
let elements = document
.annotations
.iter()
.filter(|a| a.view_id() == view_id)
.flat_map(|a| context.elements(a))
.map(Node::Element)
.collect();
.flat_map(|a| context.elements(a));
let children = if form == Form::Canvas {
// Each pass keeps the document order.
let mut passes: [Vec<Node>; 3] = Default::default();
for (pass, element) in elements {
passes[pass as usize].push(Node::Element(element));
}
passes.concat()
} else {
elements
.map(|(_, element)| Node::Element(element))
.collect()
};
let attrs = vec![
("data-layer", "annotations".to_owned()),
("data-view-id", view_id.to_owned()),
@@ -83,8 +125,7 @@ fn layer(
}
struct Context<'a> {
/// The hitbox declares `stroke="none"` and captures on its circle only (composed form).
declared_hitbox: bool,
form: Form,
twin_opacity: &'static str,
/// Last duplicate wins, as a JavaScript `Map` built from the list.
categories: HashMap<&'a str, Option<&'a str>>,
@@ -95,7 +136,7 @@ struct Context<'a> {
type Attrs = Vec<(&'static str, String)>;
impl Context<'_> {
fn elements(&self, annotation: &Annotation) -> Vec<Element> {
fn elements(&self, annotation: &Annotation) -> Vec<(Pass, Element)> {
let (geometry, color) = match annotation {
Annotation::Observable(a) => (a.geometry.as_ref(), a.color.as_deref()),
Annotation::DetailTrigger(a) => (a.geometry.as_ref(), a.color.as_deref()),
@@ -119,11 +160,15 @@ impl Context<'_> {
value_of(&data, "data-anno-name-en")
);
if annotation.trigger().is_some() {
return vec![shape(geometry, &color, trigger_visual(), &data, &label)];
let trigger = shape(geometry, &color, trigger_visual(), &data, &label);
return vec![(Pass::Shape, trigger)];
}
match geometry {
Geometry::Circle(c) => self.point(c.cx, c.cy, c.r, &color, &data, &label),
_ => vec![shape(geometry, &color, zone_visual(), &data, &label)],
_ => vec![(
Pass::Shape,
shape(geometry, &color, zone_visual(), &data, &label),
)],
}
}
@@ -174,14 +219,14 @@ impl Context<'_> {
color: &str,
data: &Attrs,
label: &str,
) -> Vec<Element> {
) -> Vec<(Pass, Element)> {
let mut hitbox: Attrs = vec![
("cx", js_number(cx)),
("cy", js_number(cy)),
("r", js_number(r)),
("fill", "transparent".to_owned()),
];
if self.declared_hitbox {
if self.form != Form::Review {
hitbox.push(("stroke", "none".to_owned()));
hitbox.push(("pointer-events", "visibleFill".to_owned()));
} else {
@@ -197,12 +242,16 @@ impl Context<'_> {
("fill-opacity", self.twin_opacity.to_owned()),
("stroke", "#000".to_owned()),
("stroke-width", "1.5".to_owned()),
("pointer-events", "none".to_owned()),
];
let twin_capture = match self.form {
Form::Canvas => "visiblePainted",
Form::Review | Form::Highlight => "none",
};
visible.push(("pointer-events", twin_capture.to_owned()));
visible.extend(data.iter().cloned());
vec![
titled("circle", hitbox, label),
titled("circle", visible, label),
(Pass::Hitbox, titled("circle", hitbox, label)),
(Pass::Twin, titled("circle", visible, label)),
]
}
}
+2 -1
View File
@@ -5,7 +5,7 @@
mod common;
use common::svg_tree::{
tree_value, view_names, with_ids_scoped_per_view, with_isolated_layer,
tree_value, view_names, with_canvas_passes, with_ids_scoped_per_view, with_isolated_layer,
with_trigger_names_per_language,
};
use faunosteo_core::anatomy::svg::tree::parse_svg;
@@ -46,6 +46,7 @@ fn golden(view: &str, sheet: &LoadedSheet) -> Value {
with_trigger_names_per_language(&mut frozen, &view_names(&sheet.document));
with_ids_scoped_per_view(&mut frozen, view);
with_isolated_layer(&mut frozen);
with_canvas_passes(&mut frozen);
frozen
}
+3 -2
View File
@@ -12,8 +12,8 @@ mod common;
use std::collections::HashSet;
use common::svg_tree::{
reread, tree_value, view_names, with_ids_scoped_per_view, with_isolated_layer,
with_trigger_names_per_language,
reread, tree_value, view_names, with_canvas_passes, 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,
@@ -112,6 +112,7 @@ fn canvas_golden(view: &str) -> Value {
with_trigger_names_per_language(&mut frozen, &view_names(&draft()));
with_ids_scoped_per_view(&mut frozen, view);
with_isolated_layer(&mut frozen);
with_canvas_passes(&mut frozen);
frozen
}
+27
View File
@@ -175,3 +175,30 @@ fn take_from(node: &mut Value) -> Option<Value> {
}
kids.iter_mut().find_map(take_from)
}
/// Owner decision 2026-11-01 (V1-2.2, « the visible wins »), the editor canvas only: applied
/// after `with_isolated_layer` to a frozen canvas tree, written apart from the core. The layer's
/// markers are put in three passes, each keeping the frozen order: every point hitbox (a circle
/// with `fill="transparent"`), then every other shape, then every visible twin (a circle with
/// `pointer-events="none"`), which captures on `visiblePainted`.
pub fn with_canvas_passes(tree: &mut Value) {
let layer = tree["children"].as_array_mut().unwrap().last_mut().unwrap();
let markers = std::mem::take(layer["children"].as_array_mut().unwrap());
let pass = |m: &Value| match (&m["attrs"]["fill"], &m["attrs"]["pointer-events"]) {
(f, _) if m["name"] == "circle" && f == "transparent" => 0,
(_, p) if m["name"] == "circle" && p == "none" => 2,
_ => 1,
};
let mut ranked: Vec<(u8, Value)> = markers.into_iter().map(|m| (pass(&m), m)).collect();
ranked.sort_by_key(|(rank, _)| *rank);
let out: Vec<Value> = ranked
.into_iter()
.map(|(rank, mut marker)| {
if rank == 2 {
marker["attrs"]["pointer-events"] = json!("visiblePainted");
}
marker
})
.collect();
layer["children"] = Value::Array(out);
}
+72 -2
View File
@@ -170,7 +170,8 @@ fn the_halo_filter_lives_outside_the_drawing() {
/// 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.
/// stroke width; the visible twins capture on what they paint (« the visible wins », owner
/// decision 2026-11-01), with their declared stroke.
#[test]
fn every_interactive_surface_declares_its_geometry_and_capture() {
let draft = draft();
@@ -184,7 +185,9 @@ fn every_interactive_surface_declares_its_geometry_and_capture() {
assert_eq!(marker.attr("stroke"), Some("none"), "{marker:?}");
assert_eq!(capture, Some("visibleFill"), "{marker:?}");
}
(_, Some("none")) => {}
(_, Some("visiblePainted")) => {
assert_eq!(marker.attr("stroke-width"), Some("1.5"), "{marker:?}");
}
(_, Some("all")) => assert!(marker.attr("stroke-width").is_some(), "{marker:?}"),
other => panic!("unexpected capture {other:?}"),
}
@@ -300,3 +303,70 @@ fn nothing_the_reader_keeps_changes_the_layer_or_the_halo() {
}
}
}
/// The role of a marker element of a composed layer, by its capture rule (the PDF view
/// recolours the hitbox): 0 a point hitbox, 1 a zone or a trigger, 2 a visible twin.
fn pass(marker: &Element) -> u8 {
match marker.attr("pointer-events") {
Some("visibleFill") => 0,
Some("none" | "visiblePainted") => 2,
_ => 1,
}
}
/// « The visible wins » (owner decision 2026-11-01): the canvas paints every point hitbox, then
/// every zone and trigger, then every visible twin, each pass in document order; the PDF view
/// keeps the document order (its bytes, the R4 digests and the step6 goldens unchanged).
#[test]
fn the_canvas_paints_hitboxes_then_shapes_then_twins_and_the_pdf_keeps_document_order() {
let draft = draft();
for view in ["main", "head"] {
let canvas = compose_canvas(&draft, view, &horse()).unwrap();
let layer = canvas.element_children().last().unwrap();
let passes: Vec<u8> = layer.element_children().map(pass).collect();
let mut sorted = passes.clone();
sorted.sort_unstable();
assert_eq!(passes, sorted, "{view}: {passes:?}");
let ids = |p: u8| -> Vec<&str> {
layer
.element_children()
.filter(|m| pass(m) == p)
.map(|m| m.attr("data-anno-id").unwrap())
.collect()
};
let document_order: Vec<&str> = draft
.annotations
.iter()
.filter(|a| a.view_id() == view)
.map(|a| a.id())
.collect();
for p in 0..3 {
let mut expected = document_order.clone();
expected.retain(|id| ids(p).contains(id));
assert_eq!(ids(p), expected, "{view} pass {p} keeps document order");
}
assert_eq!(ids(0), ids(2), "{view}: one twin per hitbox");
}
let all: HashSet<&str> = draft.annotations.iter().map(|a| a.id()).collect();
let pdf = compose_highlight(&draft, "main", horse(), &all, false).unwrap();
let layer = pdf.element_children().last().unwrap();
let passes: Vec<u8> = layer.element_children().map(pass).collect();
assert_ne!(
passes,
{
let mut s = passes.clone();
s.sort_unstable();
s
},
"the PDF view keeps the interleaved document order"
);
let twin_captures: Vec<_> = layer
.element_children()
.filter(|m| pass(m) == 2)
.map(|m| m.attr("pointer-events"))
.collect();
assert!(
twin_captures.iter().all(|c| *c == Some("none")),
"{twin_captures:?}"
);
}