Skip to main content

alpha2_compose/
spec.rs

1//! The compose spec: a video described by intent, which [`crate::compile`] turns into a
2//! project document.
3//!
4//! Times are seconds, rounded to the nearest tick (1/120 000 s). Lengths are canvas pixels.
5//! Colors are CSS hex strings or the project's `{red, green, blue, alpha}` object. Nodes are
6//! tagged by `type`, and a node with an `id` can be named by another (a music bed ducks under
7//! it).
8
9use std::collections::BTreeMap;
10
11use alpha2_model::{
12    Animated, Composition, Easing, EffectValue, LayoutNode, MediaSource, Rgba, TextShadow,
13    TextStroke, Track,
14};
15use serde::{Deserialize, Serialize};
16
17/// The newest compose spec version this build reads.
18pub const COMPOSE_VERSION: u32 = 1;
19
20/// A whole video: a body, what is drawn over it, and what plays under it.
21#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
22#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
23#[serde(deny_unknown_fields)]
24pub struct VideoSpec {
25    /// The schema the spec follows (`https://alpha2.sh/schema/compose.v1.json`), for editors and
26    /// validators. The compiler does not read it.
27    #[serde(rename = "$schema", default, skip_serializing_if = "Option::is_none")]
28    pub schema: Option<String>,
29    /// Spec version. This build reads only [`COMPOSE_VERSION`].
30    #[serde(default = "compose_version")]
31    #[cfg_attr(feature = "schema", schemars(extend("const" = COMPOSE_VERSION)))]
32    pub compose_version: u32,
33    /// The project's name. Default `video`.
34    #[serde(default, skip_serializing_if = "Option::is_none")]
35    pub name: Option<String>,
36    /// Size, rate and background. Default `youtube-1080p`.
37    #[serde(default)]
38    pub canvas: Canvas,
39    /// Fonts, colors, sizes and default timings. Default `clean-dark`.
40    #[serde(default)]
41    pub theme: ThemeChoice,
42    /// The main picture, from time zero. Its length is the video's unless `duration` says
43    /// otherwise.
44    pub body: Node,
45    /// Nodes drawn over the body in order, placed by their own `at` (default 0) and lasting to
46    /// the end unless they say otherwise.
47    #[serde(default, skip_serializing_if = "Vec::is_empty")]
48    pub overlays: Vec<Node>,
49    /// Sound beside the body's: `audio` and `music_bed` nodes, placed as overlays are.
50    #[serde(default, skip_serializing_if = "Vec::is_empty")]
51    pub audio: Vec<Node>,
52    /// The video's length in seconds. Default: the body's.
53    #[serde(default, skip_serializing_if = "Option::is_none")]
54    pub duration: Option<f64>,
55    /// The loudness an export normalizes the mix to. Returned as an export option, not stored
56    /// in the project.
57    #[serde(default, skip_serializing_if = "Option::is_none")]
58    pub loudness: Option<Loudness>,
59}
60
61const fn compose_version() -> u32 {
62    COMPOSE_VERSION
63}
64
65/// The canvas: a preset name, or its parts.
66#[derive(Clone, Debug, PartialEq, Serialize)]
67#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
68#[serde(untagged)]
69pub enum Canvas {
70    /// A preset at 30 fps: `youtube-1080p` (1920x1080), `youtube-4k` (3840x2160), `youtube-720p`
71    /// (1280x720), `shorts` (1080x1920), `square` (1080x1080) or `portrait` (1080x1350).
72    Preset(String),
73    /// A preset with some parts replaced, or every part given.
74    Custom(CustomCanvas),
75}
76
77impl Default for Canvas {
78    fn default() -> Self {
79        Self::Preset("youtube-1080p".to_owned())
80    }
81}
82
83/// A canvas by its parts.
84#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
85#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
86#[serde(deny_unknown_fields)]
87pub struct CustomCanvas {
88    /// The preset the other parts replace parts of. Default `youtube-1080p`.
89    #[serde(default, skip_serializing_if = "Option::is_none")]
90    pub preset: Option<String>,
91    /// Width in pixels.
92    #[serde(default, skip_serializing_if = "Option::is_none")]
93    pub width: Option<u32>,
94    /// Height in pixels.
95    #[serde(default, skip_serializing_if = "Option::is_none")]
96    pub height: Option<u32>,
97    /// Frames per second: an integer, 23.976, 29.97 or 59.94, or the project's exact
98    /// `{num, den}`.
99    #[serde(default, skip_serializing_if = "Option::is_none")]
100    pub frame_rate: Option<FrameRateChoice>,
101    /// The opaque color under everything. Default: the theme's.
102    #[serde(default, skip_serializing_if = "Option::is_none")]
103    pub background: Option<Rgba>,
104}
105
106/// A frame rate, as a number or exactly.
107#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
108#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
109#[serde(untagged)]
110pub enum FrameRateChoice {
111    /// Frames per second: an integer, or 23.976, 29.97 or 59.94 for the NTSC rates.
112    Number(f64),
113    /// The project's exact rate.
114    Exact(alpha2_time::FrameRate),
115}
116
117/// A theme by name, or one built on a named theme.
118#[derive(Clone, Debug, PartialEq, Serialize)]
119#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
120#[serde(untagged)]
121pub enum ThemeChoice {
122    /// A built-in theme: `clean-dark` or `clean-light`.
123    Named(String),
124    /// A theme of its own.
125    Custom(Box<Theme>),
126}
127
128impl Default for ThemeChoice {
129    fn default() -> Self {
130        Self::Named("clean-dark".to_owned())
131    }
132}
133
134/// How text, panels and timings look. Parts left out come from the base theme. Sizes are
135/// fractions of the canvas's shorter side, so a theme looks the same on wide and tall canvases.
136#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
137#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
138#[serde(deny_unknown_fields)]
139pub struct Theme {
140    /// The built-in theme this one changes. Default `clean-dark`.
141    #[serde(default, skip_serializing_if = "Option::is_none")]
142    pub base: Option<String>,
143    /// Font family, as the font names it. Unset, text draws in the first font an export
144    /// registers.
145    #[serde(default, skip_serializing_if = "Option::is_none")]
146    pub font_family: Option<String>,
147    /// Text color.
148    #[serde(default, skip_serializing_if = "Option::is_none")]
149    pub text: Option<Rgba>,
150    /// The canvas background.
151    #[serde(default, skip_serializing_if = "Option::is_none")]
152    pub background: Option<Rgba>,
153    /// What title and end cards are drawn on.
154    #[serde(default, skip_serializing_if = "Option::is_none")]
155    pub surface: Option<Rgba>,
156    /// The boxes behind labels, lower thirds and boxed captions.
157    #[serde(default, skip_serializing_if = "Option::is_none")]
158    pub panel: Option<Rgba>,
159    /// A highlight: a lower third's bar.
160    #[serde(default, skip_serializing_if = "Option::is_none")]
161    pub accent: Option<Rgba>,
162    /// Title size.
163    #[serde(default, skip_serializing_if = "Option::is_none")]
164    pub title_size: Option<f32>,
165    /// Subtitle size.
166    #[serde(default, skip_serializing_if = "Option::is_none")]
167    pub subtitle_size: Option<f32>,
168    /// Body text size.
169    #[serde(default, skip_serializing_if = "Option::is_none")]
170    pub body_size: Option<f32>,
171    /// Caption size.
172    #[serde(default, skip_serializing_if = "Option::is_none")]
173    pub caption_size: Option<f32>,
174    /// Label size: a grid cell's.
175    #[serde(default, skip_serializing_if = "Option::is_none")]
176    pub label_size: Option<f32>,
177    /// The space kept clear at the canvas's edges.
178    #[serde(default, skip_serializing_if = "Option::is_none")]
179    pub margin: Option<f32>,
180    /// The transition a slideshow, or a sequence asking for `theme`, puts between children.
181    #[serde(default, skip_serializing_if = "Option::is_none")]
182    pub transition: Option<Transition>,
183    /// How long a still shows when nothing says, in seconds.
184    #[serde(default, skip_serializing_if = "Option::is_none")]
185    pub still_seconds: Option<f64>,
186    /// How long a card or text shows when nothing says, in seconds.
187    #[serde(default, skip_serializing_if = "Option::is_none")]
188    pub text_seconds: Option<f64>,
189    /// How long text and cards fade in and out, in seconds.
190    #[serde(default, skip_serializing_if = "Option::is_none")]
191    pub fade_seconds: Option<f64>,
192}
193
194/// The loudness an export normalizes to: a target, or a target and a ceiling.
195#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
196#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
197#[serde(untagged)]
198pub enum Loudness {
199    /// Integrated loudness in LUFS, under a -1 dBTP ceiling.
200    Lufs(f64),
201    /// Integrated loudness and a true-peak ceiling.
202    Target(crate::LoudnessTarget),
203}
204
205/// The transition between two neighbours of a sequence.
206#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
207#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
208#[serde(deny_unknown_fields)]
209pub struct Transition {
210    /// `crossfade`, a built-in transition's short name (`wipe-left`, `circle-open`, ...), or a
211    /// full effect id (`alpha2.transition.fade`).
212    #[serde(rename = "type")]
213    pub kind: String,
214    /// How long the neighbours overlap, in seconds.
215    pub duration: f64,
216    /// The timing curve. Default linear.
217    #[serde(default, skip_serializing_if = "Option::is_none")]
218    pub easing: Option<Easing>,
219    /// The effect's parameters by name.
220    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
221    pub params: BTreeMap<String, Animated<EffectValue>>,
222    /// The effect definition's version. Default 1.
223    #[serde(default, skip_serializing_if = "Option::is_none")]
224    pub version: Option<u32>,
225}
226
227/// A sequence's transitions: none, the theme's, or one given.
228#[derive(Clone, Debug, PartialEq, Serialize)]
229#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
230#[serde(untagged)]
231pub enum TransitionChoice {
232    /// `none` for cuts, `theme` for the theme's transition, or a transition name at the theme's
233    /// duration.
234    Named(String),
235    /// A transition.
236    Given(Transition),
237}
238
239/// Space kept clear inside an area.
240#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
241#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
242#[serde(untagged)]
243pub enum Inset {
244    /// The same on every side.
245    Uniform(f32),
246    /// `[top, right, bottom, left]`.
247    Sides([f32; 4]),
248}
249
250/// How a picture fills its area.
251#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
252#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
253#[serde(rename_all = "snake_case")]
254pub enum Fit {
255    /// All of it, as large as fits; the rest of the area stays empty.
256    #[default]
257    Contain,
258    /// All of the area, cropped to it.
259    Cover,
260    /// Stretched to the area.
261    Fill,
262    /// At its own size in pixels, cropped to the area.
263    None,
264}
265
266/// A point of an area: its center, an edge's middle or a corner.
267#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
268#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
269#[serde(rename_all = "kebab-case")]
270pub enum Align {
271    /// The center.
272    #[default]
273    Center,
274    /// The top edge's middle.
275    Top,
276    /// The bottom edge's middle.
277    Bottom,
278    /// The left edge's middle.
279    Left,
280    /// The right edge's middle.
281    Right,
282    /// The top-left corner.
283    TopLeft,
284    /// The top-right corner.
285    TopRight,
286    /// The bottom-left corner.
287    BottomLeft,
288    /// The bottom-right corner.
289    BottomRight,
290}
291
292/// What a media file holds, when its extension does not say.
293#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
294#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
295#[serde(rename_all = "snake_case")]
296pub enum FileKind {
297    /// Moving pictures, perhaps with sound.
298    Video,
299    /// A still picture.
300    Image,
301    /// Sound alone.
302    Audio,
303}
304
305/// What a video shorter than its node does once it ends.
306#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
307#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
308#[serde(rename_all = "snake_case")]
309pub enum WhenShort {
310    /// Holds its last frame.
311    Freeze,
312    /// Plays again from its start.
313    Loop,
314    /// Slows to fill the node.
315    Stretch,
316    /// Shows nothing.
317    Blank,
318    /// The spec does not compile.
319    Error,
320}
321
322/// What a video longer than its node does.
323#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
324#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
325#[serde(rename_all = "snake_case")]
326pub enum WhenLong {
327    /// Ends with the node.
328    Trim,
329    /// Speeds up to fit the node.
330    Stretch,
331    /// The spec does not compile.
332    Error,
333}
334
335/// One part of a video.
336#[derive(Clone, Debug, PartialEq, Serialize)]
337#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
338#[serde(tag = "type", rename_all = "snake_case", deny_unknown_fields)]
339pub enum Node {
340    /// Children one after another, with transitions between them.
341    Sequence(Sequence),
342    /// Children over each other, each over the ones before.
343    Stack(Stack),
344    /// Children in the cells of a grid, row by row.
345    Grid(Grid),
346    /// A video or still file.
347    Media(Media),
348    /// Text.
349    Text(Text),
350    /// An area painted one color.
351    Color(ColorFill),
352    /// Timed text from cues, a SubRip or WebVTT file, or word timestamps.
353    Captions(Captions),
354    /// A layout generator: boxes, text and shapes laid out by CSS flexbox and grid.
355    Layout(Layout),
356    /// A sound file.
357    Audio(Audio),
358    /// Part of a project (sources, tracks, compositions) at its own times. Overlays only.
359    Raw(Raw),
360    /// Stills or clips in turn, with transitions and slow zooms.
361    Slideshow(Slideshow),
362    /// A video under its captions.
363    CaptionedVideo(CaptionedVideo),
364    /// Music under the video, faded in and out and ducked under speech.
365    MusicBed(MusicBed),
366    /// A number counting from one value to another, as text.
367    Counter(Counter),
368    /// Children drawn together into one picture, which then takes an opacity, a blend mode,
369    /// effects and a transform as one layer.
370    Group(Group),
371    /// No picture of its own: its effects apply to everything under it.
372    Adjustment(Adjustment),
373    /// Shapes drawn with one fill and one stroke: bars, frames, dividers, badges, icons.
374    Shape(Shape),
375    /// A node shown only where another node's picture is.
376    Matte(Matte),
377    /// A node shown only inside outlines.
378    Mask(Mask),
379    /// Boxes laid out by CSS flexbox or grid around text, shapes and any other node.
380    Box(BoxNode),
381}
382
383/// Children drawn together as one layer. Unlike a stack, whose children each meet what is under
384/// them, a group composites its children first: its opacity, blend mode, effects and transform
385/// apply to that one picture.
386///
387/// A group's children share its time as one picture does: a video or animated picture in it
388/// starts with the group and plays at its own speed, and it holds no sequences, captions or
389/// sound nodes. A child's sound still plays, outside the picture.
390#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
391#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
392#[serde(deny_unknown_fields)]
393pub struct Group {
394    /// The node's name, for other nodes to refer to.
395    #[serde(default, skip_serializing_if = "Option::is_none")]
396    pub id: Option<String>,
397    /// The children, each over the ones before, placed in the group's area.
398    pub children: Vec<Node>,
399    /// Seconds from the parent's start (an overlay's: the video's). Ignored in a sequence.
400    #[serde(default, skip_serializing_if = "Option::is_none")]
401    pub at: Option<f64>,
402    /// Length in seconds. Default: the longest child's.
403    #[serde(default, skip_serializing_if = "Option::is_none")]
404    pub duration: Option<f64>,
405    /// Pixels kept clear inside the parent's area: the group's area.
406    #[serde(default, skip_serializing_if = "Option::is_none")]
407    pub inset: Option<Inset>,
408    /// Opacity of the whole, 0..=1. Default 1.
409    #[serde(default, skip_serializing_if = "Option::is_none")]
410    pub opacity: Option<Anim<f32>>,
411    /// How the whole meets what is under it. Default `normal`.
412    #[serde(default, skip_serializing_if = "Option::is_none")]
413    pub blend: Option<alpha2_model::ClipBlendMode>,
414    /// Effects on the whole, in order, before its transform.
415    #[serde(default, skip_serializing_if = "Vec::is_empty")]
416    pub effects: Vec<EffectUse>,
417    /// Moves, scales or turns the whole.
418    #[serde(default, skip_serializing_if = "Option::is_none")]
419    pub transform: Option<GroupTransform>,
420    /// How it comes in at its start.
421    #[serde(default, skip_serializing_if = "Option::is_none")]
422    pub enter: Option<Motion>,
423    /// How it goes out, ending at its end.
424    #[serde(default, skip_serializing_if = "Option::is_none")]
425    pub exit: Option<Motion>,
426}
427
428/// An adjustment layer: its effects apply to the picture of everything under it, mixed back in by
429/// its opacity and met with it by its blend mode. In a sequence or an overlay that is everything
430/// composited before it; in a group, the group's children before it, and the children after it
431/// are drawn over the result. Wrapped in a `mask`, it applies inside the outlines only; it takes
432/// no `matte`.
433#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
434#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
435#[serde(deny_unknown_fields)]
436pub struct Adjustment {
437    /// The node's name, for other nodes to refer to.
438    #[serde(default, skip_serializing_if = "Option::is_none")]
439    pub id: Option<String>,
440    /// Effects on the picture under it, in order. None changes nothing.
441    #[serde(default, skip_serializing_if = "Vec::is_empty")]
442    pub effects: Vec<EffectUse>,
443    /// How much of the result replaces the picture under it, 0..=1. Default 1.
444    #[serde(default, skip_serializing_if = "Option::is_none")]
445    pub opacity: Option<Anim<f32>>,
446    /// How the result meets the picture under it. Default `normal`.
447    #[serde(default, skip_serializing_if = "Option::is_none")]
448    pub blend: Option<alpha2_model::ClipBlendMode>,
449    /// Seconds from the parent's start (an overlay's: the video's). Ignored in a sequence.
450    #[serde(default, skip_serializing_if = "Option::is_none")]
451    pub at: Option<f64>,
452    /// Length in seconds. Default: what its parent gives it.
453    #[serde(default, skip_serializing_if = "Option::is_none")]
454    pub duration: Option<f64>,
455}
456
457/// One effect: a built-in by its short name (`gaussian-blur`) or any effect by its full id, with
458/// its parameters by name. A parameter is a constant, a ramp or keys; a named image input is a
459/// node.
460#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
461#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
462pub struct EffectUse {
463    /// The effect: a built-in's short name or a full id with its dots.
464    pub effect: String,
465    /// The version a full id names. Default: the built-in's, else 1.
466    #[serde(default, skip_serializing_if = "Option::is_none")]
467    pub version: Option<u32>,
468    /// Parameters and named inputs, as `schema/effects.v1.json` lists them.
469    #[serde(flatten)]
470    pub params: BTreeMap<String, serde_json::Value>,
471}
472
473/// A group's movement, about `anchor`.
474#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
475#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
476#[serde(deny_unknown_fields)]
477pub struct GroupTransform {
478    /// Offset in pixels, `[x, y]`. Default `[0, 0]`.
479    #[serde(default, skip_serializing_if = "Option::is_none")]
480    pub position: Option<Anim<[f32; 2]>>,
481    /// Size multiple. Default 1.
482    #[serde(default, skip_serializing_if = "Option::is_none")]
483    pub scale: Option<Anim<f32>>,
484    /// Clockwise turn in degrees. Default 0.
485    #[serde(default, skip_serializing_if = "Option::is_none")]
486    pub rotation: Option<Anim<f32>>,
487    /// The point it scales and turns about, `[0, 0]` the area's top left to `[1, 1]` its bottom
488    /// right. Default `[0.5, 0.5]`.
489    #[serde(default, skip_serializing_if = "Option::is_none")]
490    pub anchor: Option<[f32; 2]>,
491}
492
493/// Children one after another.
494#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
495#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
496#[serde(deny_unknown_fields)]
497pub struct Sequence {
498    /// The node's name, for other nodes to refer to.
499    #[serde(default, skip_serializing_if = "Option::is_none")]
500    pub id: Option<String>,
501    /// The children, in play order.
502    pub children: Vec<Node>,
503    /// What joins neighbours: a transition overlaps them by its duration, and their sound
504    /// crosses over it. Default `none`. Only single pictures (media, text, color, layout) can
505    /// transition into each other; anything else, or a part shorter than the transition,
506    /// joins by crossfade.
507    #[serde(default, skip_serializing_if = "Option::is_none")]
508    pub transition: Option<TransitionChoice>,
509    /// Seconds from the parent's start (an overlay's: the video's). Ignored in a sequence.
510    #[serde(default, skip_serializing_if = "Option::is_none")]
511    pub at: Option<f64>,
512    /// Length in seconds. Default: the node's own length, else what its parent gives it.
513    #[serde(default, skip_serializing_if = "Option::is_none")]
514    pub duration: Option<f64>,
515    /// How it comes in at its start.
516    #[serde(default, skip_serializing_if = "Option::is_none")]
517    pub enter: Option<Motion>,
518    /// How it goes out, ending at its end.
519    #[serde(default, skip_serializing_if = "Option::is_none")]
520    pub exit: Option<Motion>,
521}
522
523/// Children over each other.
524#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
525#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
526#[serde(deny_unknown_fields)]
527pub struct Stack {
528    /// The node's name, for other nodes to refer to.
529    #[serde(default, skip_serializing_if = "Option::is_none")]
530    pub id: Option<String>,
531    /// The children, each drawn over the ones before and starting at its own `at`.
532    pub children: Vec<Node>,
533    /// Seconds from the parent's start (an overlay's: the video's). Ignored in a sequence.
534    #[serde(default, skip_serializing_if = "Option::is_none")]
535    pub at: Option<f64>,
536    /// Length in seconds. Default: the node's own length, else what its parent gives it.
537    #[serde(default, skip_serializing_if = "Option::is_none")]
538    pub duration: Option<f64>,
539    /// Pixels kept clear inside the parent's area: one number, or `[top, right, bottom, left]`.
540    #[serde(default, skip_serializing_if = "Option::is_none")]
541    pub inset: Option<Inset>,
542    /// How it comes in at its start.
543    #[serde(default, skip_serializing_if = "Option::is_none")]
544    pub enter: Option<Motion>,
545    /// How it goes out, ending at its end.
546    #[serde(default, skip_serializing_if = "Option::is_none")]
547    pub exit: Option<Motion>,
548    /// Seconds between the children's entrances. With it, the node's `enter` and `exit` move
549    /// each child rather than the whole, and child `i`'s entrance (its own `enter` too) starts
550    /// `i * stagger` after the child does.
551    #[serde(default, skip_serializing_if = "Option::is_none")]
552    pub stagger: Option<f64>,
553}
554
555/// Children in grid cells.
556#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
557#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
558#[serde(deny_unknown_fields)]
559pub struct Grid {
560    /// The node's name, for other nodes to refer to.
561    #[serde(default, skip_serializing_if = "Option::is_none")]
562    pub id: Option<String>,
563    /// The cells' contents, row by row.
564    pub children: Vec<Node>,
565    /// Columns. Default: as square a grid as the children make.
566    #[serde(default, skip_serializing_if = "Option::is_none")]
567    pub columns: Option<u32>,
568    /// Pixels between cells.
569    #[serde(default)]
570    pub gap: f32,
571    /// How long the grid lasts when its cells differ, and what a cell that ends early shows.
572    /// Default `shortest`.
573    #[serde(default)]
574    pub length: GridLength,
575    /// Seconds from the parent's start (an overlay's: the video's). Ignored in a sequence.
576    #[serde(default, skip_serializing_if = "Option::is_none")]
577    pub at: Option<f64>,
578    /// Length in seconds. Default: the node's own length, else what its parent gives it.
579    #[serde(default, skip_serializing_if = "Option::is_none")]
580    pub duration: Option<f64>,
581    /// Pixels kept clear inside the parent's area: one number, or `[top, right, bottom, left]`.
582    #[serde(default, skip_serializing_if = "Option::is_none")]
583    pub inset: Option<Inset>,
584    /// How it comes in at its start.
585    #[serde(default, skip_serializing_if = "Option::is_none")]
586    pub enter: Option<Motion>,
587    /// How it goes out, ending at its end.
588    #[serde(default, skip_serializing_if = "Option::is_none")]
589    pub exit: Option<Motion>,
590    /// Seconds between the children's entrances. With it, the node's `enter` and `exit` move
591    /// each child rather than the whole, and child `i`'s entrance (its own `enter` too) starts
592    /// `i * stagger` after the child does.
593    #[serde(default, skip_serializing_if = "Option::is_none")]
594    pub stagger: Option<f64>,
595}
596
597/// How long a grid of clips of different lengths lasts.
598#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
599#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
600#[serde(rename_all = "snake_case")]
601pub enum GridLength {
602    /// As long as its shortest cell.
603    #[default]
604    Shortest,
605    /// As long as its longest; shorter clips hold their last frame.
606    LongestFreeze,
607    /// As long as its longest; shorter clips play again from their start.
608    LongestLoop,
609}
610
611/// A video or still file.
612#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
613#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
614#[serde(deny_unknown_fields)]
615pub struct Media {
616    /// The node's name, for other nodes to refer to.
617    #[serde(default, skip_serializing_if = "Option::is_none")]
618    pub id: Option<String>,
619    /// The file. It becomes the source's locator and the export's asset.
620    pub path: String,
621    /// What the file holds. Default: by its extension.
622    #[serde(default, skip_serializing_if = "Option::is_none")]
623    pub kind: Option<FileKind>,
624    /// Where in the file a video starts, in seconds.
625    #[serde(default, skip_serializing_if = "Option::is_none")]
626    pub trim_start: Option<f64>,
627    /// Where in the file a video ends, in seconds. Default: its end.
628    #[serde(default, skip_serializing_if = "Option::is_none")]
629    pub trim_end: Option<f64>,
630    /// Playback speed of a video: 2 plays it twice as fast. Default 1. A video that loops takes
631    /// only speed 1.
632    #[serde(default, skip_serializing_if = "Option::is_none")]
633    pub speed: Option<f64>,
634    /// Keeps a video's sound at its pitch when `speed` is not 1 (time-stretched instead of
635    /// resampled). Default true.
636    #[serde(default, skip_serializing_if = "Option::is_none")]
637    pub preserve_pitch: Option<bool>,
638    /// Plays a video again from its start while the node lasts. Its `speed` must be 1.
639    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
640    pub r#loop: bool,
641    /// What a video does when the node outlasts it. Default: what its parent asks (a grid's
642    /// length rule), else `freeze`.
643    #[serde(default, skip_serializing_if = "Option::is_none")]
644    pub when_short: Option<WhenShort>,
645    /// What a video does when it outlasts the node. Default `trim`.
646    #[serde(default, skip_serializing_if = "Option::is_none")]
647    pub when_long: Option<WhenLong>,
648    /// Linear gain of a video's sound. Default 1.
649    #[serde(default, skip_serializing_if = "Option::is_none")]
650    pub volume: Option<f32>,
651    /// Silences a video's sound.
652    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
653    pub muted: bool,
654    /// Opacity, 0..=1. Default 1.
655    #[serde(default, skip_serializing_if = "Option::is_none")]
656    pub opacity: Option<f32>,
657    /// Seconds of fade in from transparent.
658    #[serde(default, skip_serializing_if = "Option::is_none")]
659    pub fade_in: Option<f64>,
660    /// Seconds of fade out to transparent.
661    #[serde(default, skip_serializing_if = "Option::is_none")]
662    pub fade_out: Option<f64>,
663    /// How large it shows, as a multiple of its fitted size: a constant, a ramp
664    /// (`{"from": 1, "to": 1.2}` is a slow zoom over the node), or keys. Default 1.
665    #[serde(default, skip_serializing_if = "Option::is_none")]
666    pub zoom: Option<Anim<f32>>,
667    /// A Gaussian blur's radius, as a fraction of the picture's shorter side.
668    #[serde(default, skip_serializing_if = "Option::is_none")]
669    pub blur: Option<f32>,
670    /// A label a comparison grid shows on the cell.
671    #[serde(default, skip_serializing_if = "Option::is_none")]
672    pub label: Option<String>,
673    /// Seconds from the parent's start (an overlay's: the video's). Ignored in a sequence.
674    #[serde(default, skip_serializing_if = "Option::is_none")]
675    pub at: Option<f64>,
676    /// Length in seconds. Default: the node's own length, else what its parent gives it.
677    #[serde(default, skip_serializing_if = "Option::is_none")]
678    pub duration: Option<f64>,
679    /// Pixels kept clear inside the parent's area: one number, or `[top, right, bottom, left]`.
680    #[serde(default, skip_serializing_if = "Option::is_none")]
681    pub inset: Option<Inset>,
682    /// How a picture fills its area. Default `contain`.
683    #[serde(default, skip_serializing_if = "Option::is_none")]
684    pub fit: Option<Fit>,
685    /// Where in its area the picture or text lies. Default `center`.
686    #[serde(default, skip_serializing_if = "Option::is_none")]
687    pub align: Option<Align>,
688    /// How it comes in at its start.
689    #[serde(default, skip_serializing_if = "Option::is_none")]
690    pub enter: Option<Motion>,
691    /// How it goes out, ending at its end.
692    #[serde(default, skip_serializing_if = "Option::is_none")]
693    pub exit: Option<Motion>,
694}
695
696impl Media {
697    /// A node of the file at `path`, everything else by default.
698    #[must_use]
699    pub fn new(path: impl Into<String>) -> Self {
700        Self {
701            id: None,
702            path: path.into(),
703            kind: None,
704            trim_start: None,
705            trim_end: None,
706            speed: None,
707            preserve_pitch: None,
708            r#loop: false,
709            volume: None,
710            muted: false,
711            opacity: None,
712            fade_in: None,
713            fade_out: None,
714            zoom: None,
715            when_short: None,
716            when_long: None,
717            blur: None,
718            label: None,
719            at: None,
720            duration: None,
721            inset: None,
722            fit: None,
723            align: None,
724            enter: None,
725            exit: None,
726        }
727    }
728}
729
730/// A file given by its path alone, or a media node.
731#[derive(Clone, Debug, PartialEq, Serialize)]
732#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
733#[serde(untagged)]
734pub enum MediaItem {
735    /// The file, everything else by default.
736    Path(String),
737    /// A `media` node.
738    Node(Box<Node>),
739}
740
741/// Text in one of the theme's styles.
742#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
743#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
744#[serde(deny_unknown_fields)]
745pub struct Text {
746    /// The node's name, for other nodes to refer to.
747    #[serde(default, skip_serializing_if = "Option::is_none")]
748    pub id: Option<String>,
749    /// The text; `\n` starts a line.
750    pub text: String,
751    /// The theme style it starts from. Default `body`.
752    #[serde(default)]
753    pub style: TextRole,
754    /// Font size in pixels, or a theme length. Default: the style's.
755    #[serde(default, skip_serializing_if = "Option::is_none")]
756    pub font_size: Option<Size>,
757    /// Family. Default: the theme's.
758    #[serde(default, skip_serializing_if = "Option::is_none")]
759    pub font_family: Option<String>,
760    /// Color. Default: the theme's text color.
761    #[serde(default, skip_serializing_if = "Option::is_none")]
762    pub color: Option<SolidColor>,
763    /// A box of this color behind each line.
764    #[serde(default, skip_serializing_if = "Option::is_none")]
765    pub background: Option<SolidColor>,
766    /// Bands around the glyphs, innermost first, widths as fractions of the font size (as a
767    /// text style's `strokes`).
768    #[serde(default, skip_serializing_if = "Vec::is_empty")]
769    pub strokes: Vec<TextStroke>,
770    /// Shadows of the glyphs, the first on top, lengths as fractions of the font size (as a
771    /// text style's `shadows`).
772    #[serde(default, skip_serializing_if = "Vec::is_empty")]
773    pub shadows: Vec<TextShadow>,
774    /// The most lines it may take. It first shrinks within `fit`; text still longer is cut after
775    /// its last line, ended by `ellipsis`. Default: no limit.
776    #[serde(default, skip_serializing_if = "Option::is_none")]
777    pub max_lines: Option<u32>,
778    /// The font sizes in pixels it is fitted between, the largest at which it fits its area and
779    /// `max_lines`. Default with `max_lines`: 0.3 times its font size up to its font size;
780    /// otherwise its font size alone.
781    #[serde(default, skip_serializing_if = "Option::is_none")]
782    pub fit: Option<TextFit>,
783    /// What ends a line `max_lines` cuts: `true` an ellipsis, `false` nothing, or this text.
784    /// Default `true`.
785    #[serde(default, skip_serializing_if = "Option::is_none")]
786    pub ellipsis: Option<Ellipsis>,
787    /// Opacity, 0..=1. Default 1.
788    #[serde(default, skip_serializing_if = "Option::is_none")]
789    pub opacity: Option<f32>,
790    /// Seconds of fade in and out. Default none.
791    #[serde(default, skip_serializing_if = "Option::is_none")]
792    pub fade: Option<f64>,
793    /// Seconds from the parent's start (an overlay's: the video's). Ignored in a sequence.
794    #[serde(default, skip_serializing_if = "Option::is_none")]
795    pub at: Option<f64>,
796    /// Length in seconds. Default: the node's own length, else what its parent gives it.
797    #[serde(default, skip_serializing_if = "Option::is_none")]
798    pub duration: Option<f64>,
799    /// Pixels kept clear inside the parent's area: one number, or `[top, right, bottom, left]`.
800    #[serde(default, skip_serializing_if = "Option::is_none")]
801    pub inset: Option<Inset>,
802    /// Where in its area the picture or text lies. Default `center`.
803    #[serde(default, skip_serializing_if = "Option::is_none")]
804    pub align: Option<Align>,
805    /// How it comes in at its start.
806    #[serde(default, skip_serializing_if = "Option::is_none")]
807    pub enter: Option<Motion>,
808    /// How it goes out, ending at its end.
809    #[serde(default, skip_serializing_if = "Option::is_none")]
810    pub exit: Option<Motion>,
811    /// Reveals the text a word or a line at a time.
812    #[serde(default, skip_serializing_if = "Option::is_none")]
813    pub reveal: Option<Reveal>,
814}
815
816/// The font sizes a text is fitted between, in pixels.
817#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
818#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
819#[serde(deny_unknown_fields)]
820pub struct TextFit {
821    /// Smallest font size; when nothing larger fits, the text draws at this size.
822    pub min: f32,
823    /// Largest font size. Default: the text's font size, so it only shrinks.
824    #[serde(default, skip_serializing_if = "Option::is_none")]
825    pub max: Option<f32>,
826}
827
828/// What ends a cut line: an ellipsis or nothing (`true`, `false`), or a text.
829#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
830#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
831#[serde(untagged)]
832pub enum Ellipsis {
833    /// An ellipsis, or nothing.
834    Shown(bool),
835    /// This text, 1 to 64 bytes without line breaks or control characters.
836    Text(String),
837}
838
839/// A theme text style.
840#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
841#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
842#[serde(rename_all = "snake_case")]
843pub enum TextRole {
844    /// The largest.
845    Title,
846    /// Under a title.
847    Subtitle,
848    /// Running text.
849    #[default]
850    Body,
851    /// A cell's label.
852    Label,
853}
854
855/// Shapes in the node's area, filled and stroked as one compound path. Coordinates are fractions
856/// of the area, `[0, 0]` its top left to `[1, 1]` its bottom right; lengths are fractions of its
857/// shorter side.
858#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
859#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
860#[serde(deny_unknown_fields)]
861pub struct Shape {
862    /// The node's name, for other nodes to refer to.
863    #[serde(default, skip_serializing_if = "Option::is_none")]
864    pub id: Option<String>,
865    /// The outlines, at least one.
866    pub shapes: Vec<Geometry>,
867    /// What covers their inside. Default: nothing, unless there is no stroke, then the theme's
868    /// accent.
869    #[serde(default, skip_serializing_if = "Option::is_none")]
870    pub fill: Option<PaintChoice>,
871    /// A line along the outlines.
872    #[serde(default, skip_serializing_if = "Option::is_none")]
873    pub stroke: Option<Stroke>,
874    /// Keeps part of the outlines' length. A line that draws itself has
875    /// `{"end": {"from": 0, "to": 1}}`.
876    #[serde(default, skip_serializing_if = "Option::is_none")]
877    pub trim: Option<Trim>,
878    /// Opacity, 0..=1. Default 1.
879    #[serde(default, skip_serializing_if = "Option::is_none")]
880    pub opacity: Option<f32>,
881    /// Seconds from the parent's start (an overlay's: the video's). Ignored in a sequence.
882    #[serde(default, skip_serializing_if = "Option::is_none")]
883    pub at: Option<f64>,
884    /// Length in seconds. Default: what its parent gives it.
885    #[serde(default, skip_serializing_if = "Option::is_none")]
886    pub duration: Option<f64>,
887    /// Pixels kept clear inside the parent's area: the shapes' area.
888    #[serde(default, skip_serializing_if = "Option::is_none")]
889    pub inset: Option<Inset>,
890    /// How it comes in at its start.
891    #[serde(default, skip_serializing_if = "Option::is_none")]
892    pub enter: Option<Motion>,
893    /// How it goes out, ending at its end.
894    #[serde(default, skip_serializing_if = "Option::is_none")]
895    pub exit: Option<Motion>,
896}
897
898/// `content` shown where `by`'s picture is: by its alpha (text as a window onto video) or its
899/// luminance. `by` is never drawn itself. Both are placed in the node's area.
900#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
901#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
902#[serde(deny_unknown_fields)]
903pub struct Matte {
904    /// The node's name, for other nodes to refer to.
905    #[serde(default, skip_serializing_if = "Option::is_none")]
906    pub id: Option<String>,
907    /// What is shown.
908    pub content: Box<Node>,
909    /// Where it is shown. One picture: not a sequence.
910    pub by: Box<Node>,
911    /// What of `by` counts: `alpha` (default) or `luma`.
912    #[serde(rename = "use", default, skip_serializing_if = "Option::is_none")]
913    pub uses: Option<MatteUse>,
914    /// Shows `content` where `by` is not instead.
915    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
916    pub invert: bool,
917    /// Seconds from the parent's start (an overlay's: the video's). Ignored in a sequence.
918    #[serde(default, skip_serializing_if = "Option::is_none")]
919    pub at: Option<f64>,
920    /// Length in seconds. Default: the content's.
921    #[serde(default, skip_serializing_if = "Option::is_none")]
922    pub duration: Option<f64>,
923    /// Pixels kept clear inside the parent's area.
924    #[serde(default, skip_serializing_if = "Option::is_none")]
925    pub inset: Option<Inset>,
926}
927
928/// What of a matte's picture is coverage.
929#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
930#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
931#[serde(rename_all = "snake_case")]
932pub enum MatteUse {
933    /// Its opacity.
934    #[default]
935    Alpha,
936    /// Its brightness.
937    Luma,
938}
939
940/// `content` shown only inside outlines, combined in order. Outlines are in the node's area as a
941/// shape's are, and stay put while the content moves.
942#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
943#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
944#[serde(deny_unknown_fields)]
945pub struct Mask {
946    /// The node's name, for other nodes to refer to.
947    #[serde(default, skip_serializing_if = "Option::is_none")]
948    pub id: Option<String>,
949    /// What is shown.
950    pub content: Box<Node>,
951    /// The outlines, at least one.
952    pub shapes: Vec<MaskShape>,
953    /// Seconds from the parent's start (an overlay's: the video's). Ignored in a sequence.
954    #[serde(default, skip_serializing_if = "Option::is_none")]
955    pub at: Option<f64>,
956    /// Length in seconds. Default: the content's.
957    #[serde(default, skip_serializing_if = "Option::is_none")]
958    pub duration: Option<f64>,
959    /// Pixels kept clear inside the parent's area.
960    #[serde(default, skip_serializing_if = "Option::is_none")]
961    pub inset: Option<Inset>,
962}
963
964/// One mask outline and how it combines with those before it.
965#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
966#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
967pub struct MaskShape {
968    /// The outline.
969    #[serde(flatten)]
970    pub geometry: Geometry,
971    /// `add` (default; the first adds to nothing), `subtract` or `intersect`.
972    #[serde(default, skip_serializing_if = "Option::is_none")]
973    pub mode: Option<alpha2_model::MaskMode>,
974    /// Edge softness, as a fraction of the area's shorter side. Default 0.
975    #[serde(default, skip_serializing_if = "Option::is_none")]
976    pub feather: Option<Anim<f32>>,
977    /// Keeps the outside of the outline instead.
978    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
979    pub invert: bool,
980}
981
982/// A box laid out by CSS flexbox (the default) or grid, filling the node's area. Its fields are
983/// the engine layout's container fields as CSS writes them (`flex_direction`, `gap`,
984/// `"8px 16px"` paddings, `"repeat(3, 1fr)"` tracks); `background` and `border` take theme
985/// colors.
986///
987/// Text, shapes, colors and boxes among its children are drawn by the layout itself. Any other
988/// child (a video, a group, a sequence) gets a place in the layout and is drawn there, clipped to
989/// its rounded corners; such a place keeps still.
990#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
991#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
992pub struct BoxNode {
993    /// The node's name, for other nodes to refer to.
994    #[serde(default, skip_serializing_if = "Option::is_none")]
995    pub id: Option<String>,
996    /// The children, in paint order.
997    #[serde(default, skip_serializing_if = "Vec::is_empty")]
998    pub children: Vec<BoxChild>,
999    /// What covers the box, rounded by `border_radius`.
1000    #[serde(default, skip_serializing_if = "Option::is_none")]
1001    pub background: Option<PaintChoice>,
1002    /// A border inside the box.
1003    #[serde(default, skip_serializing_if = "Option::is_none")]
1004    pub border: Option<BoxBorder>,
1005    /// Seconds from the parent's start (an overlay's: the video's). Ignored in a sequence.
1006    #[serde(default, skip_serializing_if = "Option::is_none")]
1007    pub at: Option<f64>,
1008    /// Length in seconds. Default: the longest picture child's, else what its parent gives it.
1009    #[serde(default, skip_serializing_if = "Option::is_none")]
1010    pub duration: Option<f64>,
1011    /// Pixels kept clear inside the parent's area. A nested box places itself by its item fields.
1012    #[serde(default, skip_serializing_if = "Option::is_none")]
1013    pub inset: Option<Inset>,
1014    /// The other container fields of an engine layout box, by name. A length may be a theme
1015    /// length, `{"$theme": "margin", "scale": 2}`: `margin`, `title_size`, `subtitle_size`,
1016    /// `body_size`, `caption_size` or `label_size`, times `scale` (default 1).
1017    #[serde(flatten)]
1018    pub css: BTreeMap<String, serde_json::Value>,
1019}
1020
1021/// A box border.
1022#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1023#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1024#[serde(deny_unknown_fields)]
1025pub struct BoxBorder {
1026    /// Width, as a layout size: a fraction of the picture's shorter side or `"<n>px"`.
1027    pub width: LayoutSize,
1028    /// What covers it.
1029    pub paint: PaintChoice,
1030}
1031
1032/// A layout size: a number is a fraction of the picture's shorter side, `"<n>px"` canvas pixels.
1033#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1034#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1035#[serde(untagged)]
1036pub enum LayoutSize {
1037    /// A fraction of the picture's shorter side.
1038    Fraction(f32),
1039    /// Pixels, `"<n>px"`.
1040    Pixels(String),
1041}
1042
1043/// A box's child: a node, or `{"box": item fields, "node": node}` when it has item fields (size,
1044/// flex or grid placement, `aspect_ratio`, `border_radius`, `margin`).
1045#[derive(Clone, Debug, PartialEq, Serialize)]
1046#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1047#[serde(untagged)]
1048pub enum BoxChild {
1049    /// A node with its item fields.
1050    Placed(PlacedChild),
1051    /// A node.
1052    Plain(Node),
1053}
1054
1055/// A box child with item fields.
1056#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1057#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1058#[serde(deny_unknown_fields)]
1059pub struct PlacedChild {
1060    /// Item fields of an engine layout box, as it writes them; lengths may be theme lengths.
1061    #[serde(rename = "box")]
1062    pub item: BTreeMap<String, serde_json::Value>,
1063    /// The node.
1064    pub node: Node,
1065}
1066
1067impl BoxChild {
1068    /// The node.
1069    #[must_use]
1070    pub const fn node(&self) -> &Node {
1071        match self {
1072            Self::Placed(placed) => &placed.node,
1073            Self::Plain(node) => node,
1074        }
1075    }
1076
1077    /// Its item fields; none for a plain node.
1078    #[must_use]
1079    pub fn item(&self) -> BTreeMap<String, serde_json::Value> {
1080        match self {
1081            Self::Placed(placed) => placed.item.clone(),
1082            Self::Plain(_) => BTreeMap::new(),
1083        }
1084    }
1085}
1086
1087impl<'de> Deserialize<'de> for BoxChild {
1088    // An object with `node` is a placed child; anything else is a node, so a node's own errors
1089    // are reported as they are.
1090    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
1091        use serde::de::Error as _;
1092        let value = serde_json::Value::deserialize(deserializer)?;
1093        if value
1094            .as_object()
1095            .is_some_and(|object| object.contains_key("node"))
1096        {
1097            serde_json::from_value(value)
1098                .map(Self::Placed)
1099                .map_err(D::Error::custom)
1100        } else {
1101            Node::deserialize(value)
1102                .map(Self::Plain)
1103                .map_err(D::Error::custom)
1104        }
1105    }
1106}
1107
1108/// One outline, in its area's unit square. Masks take the same outlines.
1109#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1110#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1111#[serde(tag = "shape", rename_all = "snake_case", deny_unknown_fields)]
1112pub enum Geometry {
1113    /// A rectangle, optionally with rounded corners.
1114    Rect {
1115        /// Centre. Default `[0.5, 0.5]`.
1116        #[serde(default, skip_serializing_if = "Option::is_none")]
1117        center: Option<Anim<[f32; 2]>>,
1118        /// Width and height. Default `[1, 1]`.
1119        #[serde(default, skip_serializing_if = "Option::is_none")]
1120        size: Option<Anim<[f32; 2]>>,
1121        /// Corner radius. Default 0.
1122        #[serde(default, skip_serializing_if = "Option::is_none")]
1123        corner_radius: Option<Anim<f32>>,
1124        /// Clockwise turn in degrees. Default 0.
1125        #[serde(default, skip_serializing_if = "Option::is_none")]
1126        rotation: Option<Anim<f32>>,
1127    },
1128    /// An ellipse.
1129    Ellipse {
1130        /// Centre. Default `[0.5, 0.5]`.
1131        #[serde(default, skip_serializing_if = "Option::is_none")]
1132        center: Option<Anim<[f32; 2]>>,
1133        /// Width and height. Default `[1, 1]`.
1134        #[serde(default, skip_serializing_if = "Option::is_none")]
1135        size: Option<Anim<[f32; 2]>>,
1136        /// Clockwise turn in degrees. Default 0.
1137        #[serde(default, skip_serializing_if = "Option::is_none")]
1138        rotation: Option<Anim<f32>>,
1139    },
1140    /// A regular polygon.
1141    Polygon {
1142        /// Centre. Default `[0.5, 0.5]`.
1143        #[serde(default, skip_serializing_if = "Option::is_none")]
1144        center: Option<Anim<[f32; 2]>>,
1145        /// Corners, 3 or more.
1146        points: u32,
1147        /// Distance of the corners from the centre. Default 0.5.
1148        #[serde(default, skip_serializing_if = "Option::is_none")]
1149        radius: Option<Anim<f32>>,
1150        /// How round the corners are, 0..=1. Default 0.
1151        #[serde(default, skip_serializing_if = "Option::is_none")]
1152        roundness: Option<Anim<f32>>,
1153        /// Clockwise turn in degrees. Default 0.
1154        #[serde(default, skip_serializing_if = "Option::is_none")]
1155        rotation: Option<Anim<f32>>,
1156    },
1157    /// A star.
1158    Star {
1159        /// Centre. Default `[0.5, 0.5]`.
1160        #[serde(default, skip_serializing_if = "Option::is_none")]
1161        center: Option<Anim<[f32; 2]>>,
1162        /// Tips, 3 or more.
1163        points: u32,
1164        /// Distance of the tips from the centre. Default 0.5.
1165        #[serde(default, skip_serializing_if = "Option::is_none")]
1166        outer_radius: Option<Anim<f32>>,
1167        /// Distance of the inner corners from the centre. Default 0.25.
1168        #[serde(default, skip_serializing_if = "Option::is_none")]
1169        inner_radius: Option<Anim<f32>>,
1170        /// Clockwise turn in degrees. Default 0.
1171        #[serde(default, skip_serializing_if = "Option::is_none")]
1172        rotation: Option<Anim<f32>>,
1173    },
1174    /// An outline as SVG path data (`d`), in the area's unit square.
1175    Path {
1176        /// The path data: `M`, `L`, `H`, `V`, `C`, `S`, `Q`, `T`, `A` and `Z`, absolute or
1177        /// relative.
1178        d: String,
1179    },
1180}
1181
1182/// A color, a theme color, or a gradient.
1183#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1184#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1185#[serde(untagged)]
1186pub enum PaintChoice {
1187    /// A theme color by name.
1188    Theme(ThemeColor),
1189    /// Colors along a line across the area.
1190    Linear(LinearPaint),
1191    /// Colors out from a point.
1192    Radial(RadialPaint),
1193    /// Colors around a point.
1194    Conic(ConicPaint),
1195    /// One color: CSS hex or the project's color object.
1196    Color(Rgba),
1197}
1198
1199/// `{"linear": gradient}`.
1200#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1201#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1202#[serde(deny_unknown_fields)]
1203pub struct LinearPaint {
1204    /// The gradient.
1205    pub linear: Gradient,
1206}
1207
1208/// `{"radial": gradient}`.
1209#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1210#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1211#[serde(deny_unknown_fields)]
1212pub struct RadialPaint {
1213    /// The gradient.
1214    pub radial: Gradient,
1215}
1216
1217/// `{"conic": gradient}`.
1218#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1219#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1220#[serde(deny_unknown_fields)]
1221pub struct ConicPaint {
1222    /// The gradient.
1223    pub conic: Gradient,
1224}
1225
1226/// Where the compose schema is published.
1227pub const COMPOSE_SCHEMA_ID: &str = "https://alpha2.sh/schema/compose.v1.json";
1228
1229/// A size in pixels, or one of the theme's lengths.
1230#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
1231#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1232#[serde(untagged)]
1233pub enum Size {
1234    /// Pixels of the canvas.
1235    Pixels(f32),
1236    /// A theme length.
1237    Theme(ThemeLength),
1238}
1239
1240/// One of the theme's lengths times `scale`, as a fraction of the picture's shorter side.
1241#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
1242#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1243#[serde(deny_unknown_fields)]
1244pub struct ThemeLength {
1245    /// Which of the theme's lengths.
1246    #[serde(rename = "$theme")]
1247    pub token: LengthToken,
1248    /// What it is multiplied by. Default 1.
1249    #[serde(default, skip_serializing_if = "Option::is_none")]
1250    pub scale: Option<f32>,
1251}
1252
1253/// A theme's named lengths.
1254#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
1255#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1256#[serde(rename_all = "snake_case")]
1257pub enum LengthToken {
1258    /// Space kept from the edges.
1259    Margin,
1260    /// The title style's font size.
1261    TitleSize,
1262    /// The subtitle style's font size.
1263    SubtitleSize,
1264    /// The body style's font size.
1265    BodySize,
1266    /// Captions' font size.
1267    CaptionSize,
1268    /// The label style's font size.
1269    LabelSize,
1270}
1271
1272/// A theme color, so a design follows whatever theme it is drawn with.
1273#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
1274#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1275#[serde(deny_unknown_fields)]
1276pub struct ThemeColor {
1277    /// Which of the theme's colors.
1278    #[serde(rename = "$theme")]
1279    pub token: ThemeToken,
1280    /// Opacity multiplied into it, 0..=1. Default 1.
1281    #[serde(default, skip_serializing_if = "Option::is_none")]
1282    pub alpha: Option<f32>,
1283}
1284
1285/// A theme's named colors.
1286#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
1287#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1288#[serde(rename_all = "snake_case")]
1289pub enum ThemeToken {
1290    /// Text.
1291    Text,
1292    /// The canvas behind everything.
1293    Background,
1294    /// Cards and title cards.
1295    Surface,
1296    /// Bars behind text.
1297    Panel,
1298    /// Highlights.
1299    Accent,
1300}
1301
1302/// Colors spread over a gradient.
1303#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1304#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1305#[serde(deny_unknown_fields)]
1306pub struct Gradient {
1307    /// Two or more colors, evenly spaced unless each says its `offset` in 0..=1.
1308    pub stops: Vec<Stop>,
1309    /// A linear gradient's direction in degrees, as CSS: 0 upward, 90 rightward. A conic one's
1310    /// start. Default 180 for linear (downward), 0 for conic.
1311    #[serde(default, skip_serializing_if = "Option::is_none")]
1312    pub angle: Option<f32>,
1313    /// A radial or conic gradient's centre. Default `[0.5, 0.5]`.
1314    #[serde(default, skip_serializing_if = "Option::is_none")]
1315    pub center: Option<[f32; 2]>,
1316    /// A radial gradient's radius. Default 0.5.
1317    #[serde(default, skip_serializing_if = "Option::is_none")]
1318    pub radius: Option<f32>,
1319}
1320
1321/// One gradient color.
1322#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1323#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1324#[serde(untagged)]
1325pub enum Stop {
1326    /// A color at a set position.
1327    At(OffsetStop),
1328    /// A color, spaced evenly with the others.
1329    Even(SolidColor),
1330}
1331
1332/// A gradient color at a set position.
1333#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1334#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1335#[serde(deny_unknown_fields)]
1336pub struct OffsetStop {
1337    /// The color.
1338    pub color: SolidColor,
1339    /// Where along the gradient, 0..=1.
1340    pub offset: f32,
1341}
1342
1343/// One color: a theme color, CSS hex, or the project's color object.
1344#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
1345#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1346#[serde(untagged)]
1347pub enum SolidColor {
1348    /// A theme color by name.
1349    Theme(ThemeColor),
1350    /// CSS hex or the color object.
1351    Color(Rgba),
1352}
1353
1354/// A line along outlines.
1355#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1356#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1357#[serde(deny_unknown_fields)]
1358pub struct Stroke {
1359    /// What covers it. Default: the theme's text color.
1360    #[serde(default, skip_serializing_if = "Option::is_none")]
1361    pub paint: Option<PaintChoice>,
1362    /// Width, as a fraction of the area's shorter side.
1363    pub width: Anim<f32>,
1364    /// Dash and gap lengths, as fractions of the area's shorter side. Default: solid.
1365    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1366    pub dash: Vec<f32>,
1367    /// How open ends look. Default `butt`.
1368    #[serde(default, skip_serializing_if = "Option::is_none")]
1369    pub cap: Option<alpha2_model::LineCap>,
1370    /// How segments meet. Default `miter`.
1371    #[serde(default, skip_serializing_if = "Option::is_none")]
1372    pub join: Option<alpha2_model::LineJoin>,
1373}
1374
1375/// The part of outlines' length that is kept, from `start` to `end`, shifted by `offset` turns.
1376#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
1377#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1378#[serde(deny_unknown_fields)]
1379pub struct Trim {
1380    /// Default 0.
1381    #[serde(default, skip_serializing_if = "Option::is_none")]
1382    pub start: Option<Anim<f32>>,
1383    /// Default 1.
1384    #[serde(default, skip_serializing_if = "Option::is_none")]
1385    pub end: Option<Anim<f32>>,
1386    /// Default 0.
1387    #[serde(default, skip_serializing_if = "Option::is_none")]
1388    pub offset: Option<Anim<f32>>,
1389}
1390
1391/// An area painted one color.
1392#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1393#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1394#[serde(deny_unknown_fields)]
1395pub struct ColorFill {
1396    /// The node's name, for other nodes to refer to.
1397    #[serde(default, skip_serializing_if = "Option::is_none")]
1398    pub id: Option<String>,
1399    /// The color. Default: the theme's surface.
1400    #[serde(default, skip_serializing_if = "Option::is_none")]
1401    pub color: Option<SolidColor>,
1402    /// Seconds from the parent's start (an overlay's: the video's). Ignored in a sequence.
1403    #[serde(default, skip_serializing_if = "Option::is_none")]
1404    pub at: Option<f64>,
1405    /// Length in seconds. Default: the node's own length, else what its parent gives it.
1406    #[serde(default, skip_serializing_if = "Option::is_none")]
1407    pub duration: Option<f64>,
1408    /// Pixels kept clear inside the parent's area: one number, or `[top, right, bottom, left]`.
1409    #[serde(default, skip_serializing_if = "Option::is_none")]
1410    pub inset: Option<Inset>,
1411    /// How it comes in at its start.
1412    #[serde(default, skip_serializing_if = "Option::is_none")]
1413    pub enter: Option<Motion>,
1414    /// How it goes out, ending at its end.
1415    #[serde(default, skip_serializing_if = "Option::is_none")]
1416    pub exit: Option<Motion>,
1417}
1418
1419/// Timed text.
1420#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1421#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1422#[cfg_attr(feature = "schema", schemars(rename = "CaptionsNode"))]
1423#[serde(deny_unknown_fields)]
1424pub struct Captions {
1425    /// The node's name, for other nodes to refer to.
1426    #[serde(default, skip_serializing_if = "Option::is_none")]
1427    pub id: Option<String>,
1428    /// Cues as given, in seconds from the node's start.
1429    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1430    pub cues: Vec<Cue>,
1431    /// Words with their times, as speech recognition gives them, grouped into cues of up to
1432    /// `max_chars` characters.
1433    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1434    pub words: Vec<Cue>,
1435    /// A SubRip (`.srt`) or WebVTT (`.vtt`) file, read by the binding.
1436    #[serde(default, skip_serializing_if = "Option::is_none")]
1437    pub file: Option<String>,
1438    /// SubRip text.
1439    #[serde(default, skip_serializing_if = "Option::is_none")]
1440    pub srt: Option<String>,
1441    /// WebVTT text.
1442    #[serde(default, skip_serializing_if = "Option::is_none")]
1443    pub vtt: Option<String>,
1444    /// How the captions look. Default `outline`.
1445    #[serde(default)]
1446    pub style: CaptionStyle,
1447    /// The longest cue words are grouped into, in characters. Default 32 on a tall canvas, 42
1448    /// on a wide one.
1449    #[serde(default, skip_serializing_if = "Option::is_none")]
1450    pub max_chars: Option<u32>,
1451    /// Font size in pixels. Default: the theme's caption size.
1452    #[serde(default, skip_serializing_if = "Option::is_none")]
1453    pub font_size: Option<Size>,
1454    /// Text color. Default: the theme's.
1455    #[serde(default, skip_serializing_if = "Option::is_none")]
1456    pub color: Option<SolidColor>,
1457    /// The color `karaoke` and `pop` give the word being said. Default: the theme's accent.
1458    #[serde(default, skip_serializing_if = "Option::is_none")]
1459    pub highlight: Option<SolidColor>,
1460    /// Each speaker's look, keyed by a WebVTT voice or a cue's `speaker`; it overrides the
1461    /// style.
1462    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
1463    pub speakers: BTreeMap<String, SpeakerLook>,
1464    /// Where the text's middle lies, as a fraction of the canvas height. Default depends on the
1465    /// style and the canvas's shape.
1466    #[serde(default, skip_serializing_if = "Option::is_none")]
1467    pub position: Option<f32>,
1468    /// Seconds from the parent's start (an overlay's: the video's). Ignored in a sequence.
1469    #[serde(default, skip_serializing_if = "Option::is_none")]
1470    pub at: Option<f64>,
1471    /// Length in seconds. Default: the node's own length, else what its parent gives it.
1472    #[serde(default, skip_serializing_if = "Option::is_none")]
1473    pub duration: Option<f64>,
1474}
1475
1476/// Text over an interval.
1477#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1478#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1479#[serde(deny_unknown_fields)]
1480pub struct Cue {
1481    /// Start in seconds.
1482    pub start: f64,
1483    /// End in seconds.
1484    pub end: f64,
1485    /// The text.
1486    pub text: String,
1487    /// Who says it: a key of the captions' `speakers` gives the cue its look.
1488    #[serde(default, skip_serializing_if = "Option::is_none")]
1489    pub speaker: Option<String>,
1490}
1491
1492/// How one speaker's captions look.
1493#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
1494#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1495#[serde(deny_unknown_fields)]
1496pub struct SpeakerLook {
1497    /// Their text color.
1498    #[serde(default, skip_serializing_if = "Option::is_none")]
1499    pub color: Option<SolidColor>,
1500    /// Where their text's middle lies, as fractions of the canvas, `(0, 0)` top-left.
1501    #[serde(default, skip_serializing_if = "Option::is_none")]
1502    pub position: Option<alpha2_model::Vec2>,
1503}
1504
1505/// How captions look.
1506#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
1507#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1508#[serde(rename_all = "kebab-case")]
1509pub enum CaptionStyle {
1510    /// Text with a dark band around the glyphs, near the bottom.
1511    #[default]
1512    Outline,
1513    /// Text on a panel behind each line, near the bottom.
1514    Boxed,
1515    /// Text centered on a translucent bar across the canvas near the bottom, shown as long as
1516    /// the captions.
1517    BarBottom,
1518    /// Larger outlined text a little below the middle, as short-form video draws it.
1519    BoldCenter,
1520    /// White text with a black stroke and a soft shadow, near the bottom.
1521    Bold,
1522    /// `bold`, each word turning the highlight color as it is said. Needs word times (`words`
1523    /// or WebVTT inline timestamps), else draws as `bold`.
1524    Karaoke,
1525    /// `bold`, the word being said growing a little in the highlight color. Needs word times.
1526    Pop,
1527}
1528
1529/// A layout generator.
1530#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1531#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1532#[serde(deny_unknown_fields)]
1533pub struct Layout {
1534    /// The node's name, for other nodes to refer to.
1535    #[serde(default, skip_serializing_if = "Option::is_none")]
1536    pub id: Option<String>,
1537    /// The root box, as a project's layout generator writes it.
1538    pub root: Box<LayoutNode>,
1539    /// Seconds from the parent's start (an overlay's: the video's). Ignored in a sequence.
1540    #[serde(default, skip_serializing_if = "Option::is_none")]
1541    pub at: Option<f64>,
1542    /// Length in seconds. Default: the node's own length, else what its parent gives it.
1543    #[serde(default, skip_serializing_if = "Option::is_none")]
1544    pub duration: Option<f64>,
1545    /// Pixels kept clear inside the parent's area: one number, or `[top, right, bottom, left]`.
1546    #[serde(default, skip_serializing_if = "Option::is_none")]
1547    pub inset: Option<Inset>,
1548    /// Where in its area the picture or text lies. Default `center`.
1549    #[serde(default, skip_serializing_if = "Option::is_none")]
1550    pub align: Option<Align>,
1551    /// How it comes in at its start.
1552    #[serde(default, skip_serializing_if = "Option::is_none")]
1553    pub enter: Option<Motion>,
1554    /// How it goes out, ending at its end.
1555    #[serde(default, skip_serializing_if = "Option::is_none")]
1556    pub exit: Option<Motion>,
1557}
1558
1559/// A sound file.
1560#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1561#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1562#[serde(deny_unknown_fields)]
1563pub struct Audio {
1564    /// The node's name, for other nodes to refer to.
1565    #[serde(default, skip_serializing_if = "Option::is_none")]
1566    pub id: Option<String>,
1567    /// The file.
1568    pub path: String,
1569    /// Where in the file it starts, in seconds.
1570    #[serde(default, skip_serializing_if = "Option::is_none")]
1571    pub trim_start: Option<f64>,
1572    /// Where in the file it ends, in seconds. Default: its end.
1573    #[serde(default, skip_serializing_if = "Option::is_none")]
1574    pub trim_end: Option<f64>,
1575    /// Plays the file again from its start while the node lasts.
1576    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
1577    pub r#loop: bool,
1578    /// Linear gain. Default 1.
1579    #[serde(default, skip_serializing_if = "Option::is_none")]
1580    pub volume: Option<f32>,
1581    /// Seconds of fade in.
1582    #[serde(default, skip_serializing_if = "Option::is_none")]
1583    pub fade_in: Option<f64>,
1584    /// Seconds of fade out.
1585    #[serde(default, skip_serializing_if = "Option::is_none")]
1586    pub fade_out: Option<f64>,
1587    /// The `id` of a node (or `body`) whose sound this ducks under.
1588    #[serde(default, skip_serializing_if = "Option::is_none")]
1589    pub duck_under: Option<String>,
1590    /// How far ducking lowers it, in dB (negative). Default -12.
1591    #[serde(default, skip_serializing_if = "Option::is_none")]
1592    pub duck_depth_db: Option<f32>,
1593    /// Seconds from the parent's start (an overlay's: the video's). Ignored in a sequence.
1594    #[serde(default, skip_serializing_if = "Option::is_none")]
1595    pub at: Option<f64>,
1596    /// Length in seconds. Default: the node's own length, else what its parent gives it.
1597    #[serde(default, skip_serializing_if = "Option::is_none")]
1598    pub duration: Option<f64>,
1599}
1600
1601/// Part of a project at its own times.
1602#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1603#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1604#[serde(deny_unknown_fields)]
1605pub struct Raw {
1606    /// Sources its tracks read. Ids must not collide with the compiler's (`s1`, `s2`, ...); a
1607    /// `src-` prefix keeps them apart.
1608    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1609    pub sources: Vec<MediaSource>,
1610    /// Tracks drawn over what comes before, at timeline times.
1611    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1612    pub tracks: Vec<Track>,
1613    /// Compositions its clips show.
1614    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1615    pub compositions: Vec<Composition>,
1616    /// Each file a media source of the fragment reads, by source id: the export's assets.
1617    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
1618    pub assets: BTreeMap<String, String>,
1619}
1620
1621/// Stills or clips in turn.
1622#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1623#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1624#[serde(deny_unknown_fields)]
1625pub struct Slideshow {
1626    /// The node's name, for other nodes to refer to.
1627    #[serde(default, skip_serializing_if = "Option::is_none")]
1628    pub id: Option<String>,
1629    /// The slides.
1630    pub items: Vec<MediaItem>,
1631    /// How long each slide shows, transitions included, in seconds. Default: `fit_to`'s length
1632    /// shared out, else the theme's still length.
1633    #[serde(default, skip_serializing_if = "Option::is_none")]
1634    pub seconds: Option<f64>,
1635    /// A sound file whose length the slides share out. It is not played; add it as a music bed.
1636    #[serde(default, skip_serializing_if = "Option::is_none")]
1637    pub fit_to: Option<String>,
1638    /// What joins slides. Default `theme`.
1639    #[serde(default, skip_serializing_if = "Option::is_none")]
1640    pub transition: Option<TransitionChoice>,
1641    /// How far each slide zooms in over its time, as a multiple (1.15 ends 15% larger). Default
1642    /// none.
1643    #[serde(default, skip_serializing_if = "Option::is_none")]
1644    pub ken_burns: Option<f32>,
1645    /// How slides fill the canvas. Default `cover`.
1646    #[serde(default, skip_serializing_if = "Option::is_none")]
1647    pub fit: Option<Fit>,
1648    /// When it starts in its parent; its length is the slides'.
1649    #[serde(default, skip_serializing_if = "Option::is_none")]
1650    pub at: Option<f64>,
1651}
1652
1653/// A video under its captions.
1654#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1655#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1656#[serde(deny_unknown_fields)]
1657pub struct CaptionedVideo {
1658    /// The node's name, for other nodes to refer to. Its sound is the video's.
1659    #[serde(default, skip_serializing_if = "Option::is_none")]
1660    pub id: Option<String>,
1661    /// The video.
1662    pub video: MediaItem,
1663    /// The captions, timed from the video's start.
1664    pub captions: Box<Captions>,
1665    /// How the video fills the canvas. Default `cover`.
1666    #[serde(default, skip_serializing_if = "Option::is_none")]
1667    pub fit: Option<Fit>,
1668    /// When it starts in its parent; its length is the video's.
1669    #[serde(default, skip_serializing_if = "Option::is_none")]
1670    pub at: Option<f64>,
1671}
1672
1673/// Music under the video.
1674#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1675#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1676#[serde(deny_unknown_fields)]
1677pub struct MusicBed {
1678    /// The node's name, for other nodes to refer to.
1679    #[serde(default, skip_serializing_if = "Option::is_none")]
1680    pub id: Option<String>,
1681    /// The file.
1682    pub path: String,
1683    /// Linear gain. Default 1.
1684    #[serde(default, skip_serializing_if = "Option::is_none")]
1685    pub volume: Option<f32>,
1686    /// Seconds of fade in. Default 1.
1687    #[serde(default, skip_serializing_if = "Option::is_none")]
1688    pub fade_in: Option<f64>,
1689    /// Seconds of fade out at the end. Default 2.
1690    #[serde(default, skip_serializing_if = "Option::is_none")]
1691    pub fade_out: Option<f64>,
1692    /// The `id` of a node (or `body`) whose sound it ducks under.
1693    #[serde(default, skip_serializing_if = "Option::is_none")]
1694    pub duck_under: Option<String>,
1695    /// How far ducking lowers it, in dB (negative). Default -12.
1696    #[serde(default, skip_serializing_if = "Option::is_none")]
1697    pub duck_depth_db: Option<f32>,
1698    /// Plays the file again from its start while the video lasts. Default true.
1699    #[serde(default = "yes")]
1700    pub r#loop: bool,
1701    /// Seconds from the parent's start (an overlay's: the video's). Ignored in a sequence.
1702    #[serde(default, skip_serializing_if = "Option::is_none")]
1703    pub at: Option<f64>,
1704    /// Length in seconds. Default: the node's own length, else what its parent gives it.
1705    #[serde(default, skip_serializing_if = "Option::is_none")]
1706    pub duration: Option<f64>,
1707}
1708
1709const fn yes() -> bool {
1710    true
1711}
1712
1713/// A timing curve: `linear`, a CSS name (`ease`, `ease-in`, `ease-out`, `ease-in-out`) or a
1714/// project easing object.
1715#[derive(Clone, Debug, PartialEq, Serialize)]
1716#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1717#[serde(untagged)]
1718pub enum EasingChoice {
1719    /// `linear`, `ease`, `ease-in`, `ease-out` or `ease-in-out`, with the CSS curves.
1720    Named(String),
1721    /// A project easing.
1722    Curve(Easing),
1723}
1724
1725/// A value over a node's time: a constant, a ramp from one value to another, or keys. Times are
1726/// seconds from the node's start.
1727#[derive(Clone, Debug, PartialEq, Serialize)]
1728#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1729#[serde(untagged)]
1730pub enum Anim<T> {
1731    /// From `from` to `to`.
1732    Ramp(Ramp<T>),
1733    /// Through keyed values.
1734    Keys(Keys<T>),
1735    /// One value throughout.
1736    Value(T),
1737}
1738
1739impl<'de, T: serde::de::DeserializeOwned> Deserialize<'de> for Anim<T> {
1740    // An object with `keys` is keys and one with `from` a ramp; anything else is a value. Ramps
1741    // and keys are objects only, as the schema says, though serde reads a struct from an array.
1742    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
1743        use serde::de::Error as _;
1744        let value = serde_json::Value::deserialize(deserializer)?;
1745        let object = value.as_object();
1746        if object.is_some_and(|object| object.contains_key("keys")) {
1747            serde_json::from_value(value).map(Anim::Keys)
1748        } else if object.is_some_and(|object| object.contains_key("from")) {
1749            serde_json::from_value(value).map(Anim::Ramp)
1750        } else if value.is_array() && !accepts_array::<T>() {
1751            return Err(D::Error::custom(
1752                "expected a value, `{from, to}` or `{keys}`, not an array",
1753            ));
1754        } else {
1755            serde_json::from_value(value).map(Anim::Value)
1756        }
1757        .map_err(D::Error::custom)
1758    }
1759}
1760
1761/// Whether `T` itself is written as an array, as a vector value is.
1762fn accepts_array<T: serde::de::DeserializeOwned>() -> bool {
1763    serde_json::from_value::<T>(serde_json::json!([0, 0])).is_ok()
1764        || serde_json::from_value::<T>(serde_json::json!([0, 0, 0, 0])).is_ok()
1765}
1766
1767/// A change from one value to another; before it the value is `from`, after it `to`.
1768#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1769#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1770#[serde(deny_unknown_fields)]
1771pub struct Ramp<T> {
1772    /// The value at the start.
1773    pub from: T,
1774    /// The value at the end.
1775    pub to: T,
1776    /// The timing curve. Default linear.
1777    #[serde(default, skip_serializing_if = "Option::is_none")]
1778    pub ease: Option<EasingChoice>,
1779    /// When it starts. Default 0.
1780    #[serde(default, skip_serializing_if = "Option::is_none")]
1781    pub at: Option<f64>,
1782    /// How long it lasts. Default: to the node's end.
1783    #[serde(default, skip_serializing_if = "Option::is_none")]
1784    pub duration: Option<f64>,
1785}
1786
1787/// Values at times; the value holds before the first and after the last.
1788#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1789#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1790#[serde(deny_unknown_fields)]
1791pub struct Keys<T> {
1792    /// The keys, in increasing time; at least one.
1793    pub keys: Vec<Key<T>>,
1794}
1795
1796/// One keyed value.
1797#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1798#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1799#[serde(deny_unknown_fields)]
1800pub struct Key<T> {
1801    /// Seconds from the node's start.
1802    pub t: f64,
1803    /// The value.
1804    pub v: T,
1805    /// The timing curve to the next key. Default linear.
1806    #[serde(default, skip_serializing_if = "Option::is_none")]
1807    pub ease: Option<EasingChoice>,
1808}
1809
1810/// An entrance or exit, timed from the node's own start or back from its own end.
1811#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1812#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1813#[serde(deny_unknown_fields)]
1814pub struct Motion {
1815    /// What moves: `fade` (opacity alone), `rise` (a slide up), `slide` (toward `direction`) or
1816    /// `scale` (from `size` times its size). `rise`, `slide` and `scale` fade too unless `fade`
1817    /// is false.
1818    #[serde(rename = "type")]
1819    pub kind: MotionKind,
1820    /// Length in seconds; 0 is no motion. Default: the theme's fade length.
1821    #[serde(default, skip_serializing_if = "Option::is_none")]
1822    pub duration: Option<f64>,
1823    /// The timing curve. Default linear.
1824    #[serde(default, skip_serializing_if = "Option::is_none")]
1825    pub easing: Option<EasingChoice>,
1826    /// Which way a `slide` travels, entering into place and leaving out of it. Default `up`.
1827    #[serde(default, skip_serializing_if = "Option::is_none")]
1828    pub direction: Option<Direction>,
1829    /// How far a `rise` or `slide` travels, in pixels. Default: the theme's margin.
1830    #[serde(default, skip_serializing_if = "Option::is_none")]
1831    pub distance: Option<f32>,
1832    /// The size a `scale` enters from or exits to, as a multiple of its own. Default 0.
1833    #[serde(default, skip_serializing_if = "Option::is_none")]
1834    pub size: Option<f32>,
1835    /// Whether a `rise`, `slide` or `scale` also fades. Default true.
1836    #[serde(default, skip_serializing_if = "Option::is_none")]
1837    pub fade: Option<bool>,
1838}
1839
1840/// What an entrance or exit moves.
1841#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
1842#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1843#[serde(rename_all = "snake_case")]
1844pub enum MotionKind {
1845    /// Opacity alone.
1846    Fade,
1847    /// A slide up.
1848    Rise,
1849    /// A slide toward `direction`.
1850    Slide,
1851    /// A change of size about the node's own anchor.
1852    Scale,
1853}
1854
1855/// A direction of travel on the canvas.
1856#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
1857#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1858#[serde(rename_all = "snake_case")]
1859pub enum Direction {
1860    /// Toward the top.
1861    #[default]
1862    Up,
1863    /// Toward the bottom.
1864    Down,
1865    /// Toward the left.
1866    Left,
1867    /// Toward the right.
1868    Right,
1869}
1870
1871/// A text revealed a unit at a time. Each unit moves at a constant rate over `duration`.
1872#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1873#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1874#[serde(deny_unknown_fields)]
1875pub struct Reveal {
1876    /// The unit: `word` (words holding a letter or digit) or `line` (laid-out lines).
1877    pub by: RevealUnit,
1878    /// How each unit appears: `fade`, or `rise` (fading in while moving up). Default `fade`.
1879    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
1880    pub kind: Option<RevealKind>,
1881    /// Seconds between one unit's start and the next's. Default half the duration.
1882    #[serde(default, skip_serializing_if = "Option::is_none")]
1883    pub stagger: Option<f64>,
1884    /// Seconds each unit takes. Default: the theme's fade length.
1885    #[serde(default, skip_serializing_if = "Option::is_none")]
1886    pub duration: Option<f64>,
1887    /// How far a `rise` moves, in pixels. Default half the font size.
1888    #[serde(default, skip_serializing_if = "Option::is_none")]
1889    pub distance: Option<f32>,
1890}
1891
1892/// The unit a text is revealed by.
1893#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
1894#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1895#[serde(rename_all = "snake_case")]
1896pub enum RevealUnit {
1897    /// Words that hold a letter or digit; other characters show throughout.
1898    Word,
1899    /// Laid-out lines.
1900    Line,
1901}
1902
1903/// How a revealed unit appears.
1904#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
1905#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1906#[serde(rename_all = "snake_case")]
1907pub enum RevealKind {
1908    /// Opacity alone.
1909    Fade,
1910    /// Fading in while moving up.
1911    Rise,
1912}
1913
1914/// A number counting from `start` to `end`, shown as text that changes on the frame grid.
1915#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1916#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1917#[serde(deny_unknown_fields)]
1918pub struct Counter {
1919    /// The node's name, for other nodes to refer to.
1920    #[serde(default, skip_serializing_if = "Option::is_none")]
1921    pub id: Option<String>,
1922    /// The value it counts from.
1923    pub start: f64,
1924    /// The value it counts to.
1925    pub end: f64,
1926    /// Seconds the count takes from the node's start, at most 100,000 frames; it then holds
1927    /// `end`. Default: the node's whole length.
1928    #[serde(default, skip_serializing_if = "Option::is_none")]
1929    pub count_duration: Option<f64>,
1930    /// The timing curve of the count. Default linear.
1931    #[serde(default, skip_serializing_if = "Option::is_none")]
1932    pub easing: Option<EasingChoice>,
1933    /// How the number is written.
1934    #[serde(default, skip_serializing_if = "Option::is_none")]
1935    pub format: Option<NumberFormat>,
1936    /// The theme style it starts from. Default `title`.
1937    #[serde(default, skip_serializing_if = "Option::is_none")]
1938    pub style: Option<TextRole>,
1939    /// Font size in pixels, or a theme length. Default: the style's.
1940    #[serde(default, skip_serializing_if = "Option::is_none")]
1941    pub font_size: Option<Size>,
1942    /// Family. Default: the theme's.
1943    #[serde(default, skip_serializing_if = "Option::is_none")]
1944    pub font_family: Option<String>,
1945    /// Color. Default: the theme's text color.
1946    #[serde(default, skip_serializing_if = "Option::is_none")]
1947    pub color: Option<SolidColor>,
1948    /// Bands around the glyphs, as a text node's `strokes`.
1949    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1950    pub strokes: Vec<TextStroke>,
1951    /// Shadows of the glyphs, as a text node's `shadows`.
1952    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1953    pub shadows: Vec<TextShadow>,
1954    /// Opacity, 0..=1. Default 1.
1955    #[serde(default, skip_serializing_if = "Option::is_none")]
1956    pub opacity: Option<f32>,
1957    /// Seconds from the parent's start (an overlay's: the video's). Ignored in a sequence.
1958    #[serde(default, skip_serializing_if = "Option::is_none")]
1959    pub at: Option<f64>,
1960    /// Length in seconds. Default: the node's own length, else what its parent gives it.
1961    #[serde(default, skip_serializing_if = "Option::is_none")]
1962    pub duration: Option<f64>,
1963    /// Pixels kept clear inside the parent's area: one number, or `[top, right, bottom, left]`.
1964    #[serde(default, skip_serializing_if = "Option::is_none")]
1965    pub inset: Option<Inset>,
1966    /// Where in its area the number lies. Default `center`.
1967    #[serde(default, skip_serializing_if = "Option::is_none")]
1968    pub align: Option<Align>,
1969    /// How it comes in at its start.
1970    #[serde(default, skip_serializing_if = "Option::is_none")]
1971    pub enter: Option<Motion>,
1972    /// How it goes out, ending at its end.
1973    #[serde(default, skip_serializing_if = "Option::is_none")]
1974    pub exit: Option<Motion>,
1975}
1976
1977/// How a counter writes its number.
1978#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
1979#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1980#[serde(deny_unknown_fields)]
1981pub struct NumberFormat {
1982    /// Digits after the decimal point, at most 6. Default 0.
1983    #[serde(default, skip_serializing_if = "Option::is_none")]
1984    pub decimals: Option<u32>,
1985    /// Put between each group of three integer digits, as `,`. Default none.
1986    #[serde(default, skip_serializing_if = "Option::is_none")]
1987    pub thousands: Option<String>,
1988    /// The decimal point. Default `.`.
1989    #[serde(default, skip_serializing_if = "Option::is_none")]
1990    pub point: Option<String>,
1991    /// Text before the number.
1992    #[serde(default, skip_serializing_if = "Option::is_none")]
1993    pub prefix: Option<String>,
1994    /// Text after the number.
1995    #[serde(default, skip_serializing_if = "Option::is_none")]
1996    pub suffix: Option<String>,
1997}