1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
// =============================================================================
// #######
// ### ### F: source.rs
// ## ## ## ## P: AppCore-Runtime
// ## ##
// C: 2026/08/30 05:00:00 by dnettoRaw
// ## ## ## ## U: 2026/08/30 05:00:00 by dnettoRaw
// ########### S: 1.0.2-rc
// =============================================================================
//! Defines bounded source contracts and behavior for this crate.
use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use crate::source_layout::default_gap;
pub use crate::source_layout::ExclusionSource;
pub use crate::source_page::{EdgeSource, PageLayerSource, PageSource};
pub use crate::source_table::{TableSource, TableStyleRuleSource};
pub use crate::source_text::TextSourceOptions;
pub use crate::source_transform::{MirrorSource, TransformSource};
use crate::{
Alignment, CollisionBounds, Color, Distribution, ImageOptions, LayoutConstraints, LayoutMode,
Length,
};
/// Top-level source model.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ModelKind {
/// Paginated document/report.
Document,
/// Free-form vector canvas.
Canvas,
/// Tabular dataset.
Dataset,
}
/// Version-one YAML frontend. This is never renderer input.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct TemplateSourceV1 {
/// Must equal `"1.0"`.
pub filemaker: String,
/// Source model.
pub model: ModelKind,
/// Stable logical template ID.
pub id: String,
/// Optional page/canvas declaration.
#[serde(default)]
pub page: Option<PageSource>,
/// Document-wide collision policy inherited by every page.
#[serde(default)]
pub collision: Option<CollisionSource>,
/// Explicit includes expanded before IR construction.
#[serde(default)]
pub includes: Vec<IncludeSource>,
/// Reusable component declarations.
#[serde(default)]
pub components: BTreeMap<String, ComponentSource>,
/// Theme token declarations.
#[serde(default)]
pub themes: BTreeMap<String, ThemeSource>,
/// Explicit active theme name.
#[serde(default)]
pub theme: Option<String>,
/// Template-level style applied after the active theme.
#[serde(default)]
pub style: StyleSource,
/// Named styles.
#[serde(default)]
pub styles: BTreeMap<String, StyleSource>,
/// Named guides.
#[serde(default)]
pub guides: BTreeMap<String, Length>,
/// Named layout regions.
#[serde(default)]
pub regions: BTreeMap<String, RegionSource>,
/// Named non-painted collision geometry repeated on every page.
#[serde(default)]
pub exclusions: BTreeMap<String, ExclusionSource>,
/// Typed input data schema.
#[serde(default)]
pub data_schema: BTreeMap<String, DataFieldSource>,
/// Root elements in stable source order.
#[serde(default)]
pub elements: Vec<ElementSource>,
/// Optional author intent for AI adapters. Core does not interpret it.
#[serde(default)]
pub ai: Option<AiSourcePolicy>,
}
/// Sandboxed include declaration.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct IncludeSource {
/// Logical resolver path.
pub path: String,
/// Optional namespace preventing ID collisions.
#[serde(default)]
pub namespace: Option<String>,
}
/// Component with typed/default props and element body.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ComponentSource {
/// Default prop values as frontend values.
#[serde(default)]
pub props: BTreeMap<String, serde_json::Value>,
/// Named replaceable slots.
#[serde(default)]
pub slots: BTreeMap<String, Vec<ElementSource>>,
/// Component body.
#[serde(default)]
pub elements: Vec<ElementSource>,
}
/// Theme tokens and optional parent.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ThemeSource {
/// Parent theme name.
#[serde(default)]
pub extends: Option<String>,
/// Token values.
#[serde(default)]
pub tokens: BTreeMap<String, serde_json::Value>,
/// Theme style layer.
#[serde(default)]
pub style: StyleSource,
}
/// Frontend style declaration. Typed conversion happens during expansion.
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct StyleSource {
/// Fill color expression or token.
pub fill: Option<ColorSource>,
/// Stroke color expression or token.
pub stroke: Option<ColorSource>,
/// Stroke width.
pub stroke_width: Option<Length>,
/// Opacity in millionths.
pub opacity: Option<u32>,
/// Font family reference.
pub font: Option<String>,
/// Font size.
pub font_size: Option<Length>,
/// Text color expression or token.
pub color: Option<ColorSource>,
}
/// String/token or explicit typed color accepted by the YAML frontend.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ColorSource {
/// Named, hex, functional, or `$token` spelling.
Text(String),
/// Tagged `Color` value such as `{ space: cmyk, ... }`.
Typed(Color),
}
/// Conditional style layer evaluated against the active binding context.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ElementStyleRuleSource {
/// Deterministic boolean expression.
pub when: String,
/// Partial style overlaid when the expression is truthy.
pub style: StyleSource,
}
/// Named rectangular layout region.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct RegionSource {
/// Horizontal position.
pub x: Length,
/// Vertical position.
pub y: Length,
/// Width.
pub width: Length,
/// Height.
pub height: Length,
/// Optional inherited collision policy.
#[serde(default)]
pub collision: Option<CollisionSource>,
}
/// Supported typed data kinds.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum DataTypeSource {
/// UTF-8 string.
String,
/// Signed integer.
Integer,
/// Exact decimal.
Decimal,
/// Boolean.
Boolean,
/// ISO date.
Date,
/// ISO date-time.
DateTime,
/// Duration.
Duration,
/// Exact decimal plus currency code object.
Currency,
/// Array.
Array,
/// Object.
Object,
/// Explicit null.
Null,
}
/// Typed input field declaration.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct DataFieldSource {
/// Required type.
#[serde(rename = "type")]
pub data_type: DataTypeSource,
/// Whether null is accepted.
#[serde(default)]
pub nullable: bool,
/// Optional deterministic computed expression.
#[serde(default)]
pub computed: Option<String>,
}
/// Declarative element frontend.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ElementSource {
/// Unique stable ID.
pub id: String,
/// Element type.
#[serde(rename = "type")]
pub element_type: String,
/// Optional component to instantiate.
#[serde(default)]
pub component: Option<String>,
/// Component props.
#[serde(default)]
pub props: BTreeMap<String, serde_json::Value>,
/// Named slot content supplied to a component instance.
#[serde(default)]
pub slots: BTreeMap<String, Vec<ElementSource>>,
/// Horizontal source coordinate.
#[serde(default)]
pub x: Option<Length>,
/// Vertical source coordinate.
#[serde(default)]
pub y: Option<Length>,
/// Source width.
#[serde(default)]
pub width: Option<Length>,
/// Source height.
#[serde(default)]
pub height: Option<Length>,
/// Minimum, preferred, maximum, and aspect-ratio size intent.
#[serde(default)]
pub constraints: LayoutConstraints,
/// Optional horizontal alignment inside the resolved container.
#[serde(default)]
pub align_x: Option<Alignment>,
/// Optional vertical alignment inside the resolved container.
#[serde(default)]
pub align_y: Option<Alignment>,
/// Literal text before binding evaluation.
#[serde(default)]
pub text: Option<String>,
/// Text overflow, line, minimum-size, and writing-mode intent.
#[serde(default)]
pub text_options: TextSourceOptions,
/// First-class table declaration, valid only for `type: table`.
#[serde(default)]
pub table: Option<TableSource>,
/// Asset reference.
#[serde(default)]
pub asset: Option<String>,
/// Image crop, fit, focal-point, and EXIF behavior.
#[serde(default)]
pub image: ImageOptions,
/// Simple vector path commands.
#[serde(default)]
pub path: Vec<PathCommandSource>,
/// Named style references in cascade order.
#[serde(default)]
pub styles: Vec<String>,
/// Inline style.
#[serde(default)]
pub style: StyleSource,
/// Ordered conditional styles evaluated after the compiled style layers.
#[serde(default)]
pub style_rules: Vec<ElementStyleRuleSource>,
/// Translation, rotation, scale, flip, mirror, and origin intent.
#[serde(default)]
pub transform: TransformSource,
/// Layout strategy.
#[serde(default)]
pub layout: LayoutMode,
/// Distribution of children on a flow's primary axis.
#[serde(default)]
pub distribute: Distribution,
/// Gap between flow children.
#[serde(default = "default_gap")]
pub gap: Length,
/// Data binding expression.
#[serde(default)]
pub binding: Option<String>,
/// Visibility condition expression.
#[serde(default)]
pub when: Option<String>,
/// Repeat array expression.
#[serde(default)]
pub repeat: Option<String>,
/// Named anchors.
#[serde(default)]
pub anchors: BTreeMap<String, String>,
/// Named containing region.
#[serde(default)]
pub region: Option<String>,
/// Child nodes.
#[serde(default)]
pub children: Vec<ElementSource>,
/// Whether runtime patches may modify this node.
#[serde(default)]
pub locked: bool,
/// Whether the node is initially hidden.
#[serde(default)]
pub hidden: bool,
/// Visual layer.
#[serde(default)]
pub layer: String,
/// Visual order within a layer.
#[serde(default)]
pub z_index: i32,
/// Collision declaration independent from layer ordering.
#[serde(default)]
pub collision: Option<CollisionSource>,
/// Expansion provenance populated by the compiler and absent from YAML.
#[serde(skip)]
#[doc(hidden)]
pub provenance_components: Vec<String>,
/// Logical include path populated by the compiler and absent from YAML.
#[serde(skip)]
#[doc(hidden)]
pub provenance_source: Option<String>,
}
/// Geometry-first collision declaration or the shorthand `collision: false`.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CollisionSource {
/// Enables or disables collision using the default policy.
Enabled(bool),
/// Supplies the complete collision policy.
Advanced(CollisionAdvancedSource),
}
impl Default for CollisionSource {
fn default() -> Self {
Self::Advanced(CollisionAdvancedSource::default())
}
}
/// Advanced geometry-first collision declaration.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct CollisionAdvancedSource {
/// Whether this node participates.
pub enabled: bool,
/// Collision group.
pub group: String,
/// Groups this node collides with; empty means all.
pub collides_with: Vec<String>,
/// Element IDs ignored by this node.
pub ignore: Vec<String>,
/// Higher values win movement conflicts.
pub priority: i32,
/// Whether the resolver may move this node.
pub movable: bool,
/// Resolved box used by the spatial index.
pub bounds: CollisionBounds,
/// Policy name: `push/error/overlay/next_page/shrink`.
pub policy: String,
}
impl Default for CollisionAdvancedSource {
fn default() -> Self {
Self {
enabled: true,
group: "default".to_owned(),
collides_with: Vec::new(),
ignore: Vec::new(),
priority: 0,
movable: true,
bounds: CollisionBounds::Layout,
policy: "push".to_owned(),
}
}
}
/// Vector path source commands.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "command", rename_all = "snake_case", deny_unknown_fields)]
pub enum PathCommandSource {
/// Move current position.
Move {
/// Horizontal coordinate.
x: Length,
/// Vertical coordinate.
y: Length,
},
/// Draw line.
Line {
/// Horizontal coordinate.
x: Length,
/// Vertical coordinate.
y: Length,
},
/// Draw cubic Bézier curve.
Curve {
/// First control x.
x1: Length,
/// First control y.
y1: Length,
/// Second control x.
x2: Length,
/// Second control y.
y2: Length,
/// End x.
x: Length,
/// End y.
y: Length,
},
/// Close current contour.
Close,
}
/// Author-provided policy consumed only by the optional AI bridge.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct AiSourcePolicy {
/// Compact statement of document purpose.
#[serde(default)]
pub purpose: String,
/// Bounded textual edit rules.
#[serde(default)]
pub rules: Vec<String>,
/// IDs the bridge may edit. Empty means policy default.
#[serde(default)]
pub editable: Vec<String>,
/// IDs the bridge must never edit.
#[serde(default)]
pub locked: Vec<String>,
}