zenith_core/ast/variant.rs
1//! Variant-set block declaration AST types.
2//!
3//! The top-level `variants` block declares named size/override variants derived
4//! from a source page. Each `variant` entry specifies a target page `id`, the
5//! `source` page it derives from, the target dimensions `w`/`h`, and an
6//! optional list of per-node property overrides. It is a sibling of the
7//! `provenance`/`document` blocks. Core round-trips and validates these records;
8//! variant generation itself is performed by the CLI engine (`zenith variant`).
9
10use std::collections::BTreeMap;
11
12use super::Span;
13use super::node::UnknownProperty;
14use super::value::{Dimension, PropertyValue};
15
16/// A single variant declaration within a `variants` block.
17#[derive(Debug, Clone, PartialEq)]
18pub struct VariantDef {
19 /// The variant's own stable id. Required.
20 pub id: String,
21 /// The canonical page id this variant derives from. Required; existence is
22 /// validated later, not by the parser.
23 pub source: String,
24 /// Target page width for this variant. Required.
25 pub w: Dimension,
26 /// Target page height for this variant. Required.
27 pub h: Dimension,
28 /// Per-node property overrides; empty when no `override` children are
29 /// present.
30 pub overrides: Vec<VariantOverride>,
31 /// Source declaration span, when available.
32 pub source_span: Option<Span>,
33 /// Forward-compat: unrecognized attributes preserved with typed values +
34 /// annotations.
35 pub unknown_props: BTreeMap<String, UnknownProperty>,
36}
37
38/// A single per-node property override within a [`VariantDef`].
39#[derive(Debug, Clone, PartialEq)]
40pub struct VariantOverride {
41 /// The target node id within the source page. Required.
42 pub node: String,
43 /// Override for the node's `visible` property.
44 pub visible: Option<bool>,
45 /// Override for the node's left edge (`x`), in document pixels or points.
46 pub x: Option<Dimension>,
47 /// Override for the node's top edge (`y`), in document pixels or points.
48 pub y: Option<Dimension>,
49 /// Override for the node's width (`w`), in document pixels or points.
50 pub w: Option<Dimension>,
51 /// Override for the node's height (`h`), in document pixels or points.
52 pub h: Option<Dimension>,
53 /// Override for the node's `fill` property (token ref or literal).
54 pub fill: Option<PropertyValue>,
55 /// Override for the node's `text` content.
56 pub text: Option<String>,
57 /// Source declaration span, when available.
58 pub source_span: Option<Span>,
59 /// Forward-compat: unrecognized attributes preserved with typed values +
60 /// annotations.
61 pub unknown_props: BTreeMap<String, UnknownProperty>,
62}