1use crate::animation::visit_keyed;
13use crate::checks::{
14 Checked, ValueIssue, ValueProblem, animated, any, non_negative, scalar, unit, validate_paint,
15 vec2,
16};
17use crate::layout_values::{
18 GridEdge, GridPlacement, Insets, LayoutLength, LayoutOffset, LayoutSize, RepeatCount,
19 TrackComponent, TrackList,
20};
21use crate::{
22 Animated, FONT_WEIGHT_RANGE, Interpolation, LETTER_SPACING_RANGE, LINE_HEIGHT_RANGE,
23 MAX_FONT_FAMILY_BYTES, MAX_TEXT_CONTENT_BYTES, Paint, Rgba, ShapeIssue, ShapeItem, TextAlign,
24 TextShadow, TextStroke, Vec2,
25};
26use serde::{Deserialize, Serialize};
27use std::fmt;
28
29pub const MAX_LAYOUT_NODES: usize = 256;
31pub const MAX_LAYOUT_DEPTH: usize = 16;
33pub const MAX_LAYOUT_TEXTS: usize = 64;
35pub const MAX_LAYOUT_ISOLATED: usize = 16;
37pub const MAX_LAYOUT_FONT_SIZE: f32 = 1.0;
39pub const MAX_FLEX_FACTOR: f32 = 1e6;
41pub const ASPECT_RATIO_RANGE: std::ops::RangeInclusive<f32> = 1e-4..=1e4;
43pub const MAX_GRID_TRACKS: usize = 64;
45const MAX_GRID_LINE: i16 = 65;
47
48pub const LAYOUT_TEXT_DEFAULTS: LayoutTextStyle = LayoutTextStyle {
50 font_family: None,
51 font_size: 0.05,
52 fill: Paint::Solid {
53 color: Rgba::new(1.0, 1.0, 1.0, 1.0),
54 },
55 line_height: 1.2,
56 letter_spacing: 0.0,
57 font_weight: 400,
58 text_align: TextAlign::Start,
59 strokes: Vec::new(),
60 shadows: Vec::new(),
61};
62
63#[derive(Clone, Debug, PartialEq)]
65pub struct LayoutTextStyle {
66 pub font_family: Option<String>,
68 pub font_size: f32,
70 pub fill: Paint,
72 pub line_height: f32,
74 pub letter_spacing: f32,
76 pub font_weight: u16,
78 pub text_align: TextAlign,
80 pub strokes: Vec<TextStroke>,
82 pub shadows: Vec<TextShadow>,
85}
86
87#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
94#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
95#[serde(deny_unknown_fields)]
96pub struct LayoutNode {
97 #[serde(default, skip_serializing_if = "Vec::is_empty")]
99 #[serde(deserialize_with = "crate::bounded::seq::<_, _, { crate::MAX_LAYOUT_NODES }>")]
100 #[cfg_attr(feature = "schema", schemars(length(max = crate::MAX_LAYOUT_NODES)))]
101 pub children: Vec<LayoutNode>,
102 #[serde(default, skip_serializing_if = "Option::is_none")]
107 pub text: Option<Animated<crate::TextContent>>,
108 #[serde(default, skip_serializing_if = "Option::is_none")]
111 pub shape: Option<LayoutShape>,
112
113 #[serde(default, skip_serializing_if = "Option::is_none")]
116 pub display: Option<Display>,
117 #[serde(default, skip_serializing_if = "Option::is_none")]
119 pub flex_direction: Option<FlexDirection>,
120 #[serde(default, skip_serializing_if = "Option::is_none")]
122 pub flex_wrap: Option<FlexWrap>,
123 #[serde(default, skip_serializing_if = "Option::is_none")]
126 pub grid_template_columns: Option<TrackList>,
127 #[serde(default, skip_serializing_if = "Option::is_none")]
129 pub grid_template_rows: Option<TrackList>,
130 #[serde(default, skip_serializing_if = "Option::is_none")]
132 pub grid_auto_columns: Option<TrackList>,
133 #[serde(default, skip_serializing_if = "Option::is_none")]
135 pub grid_auto_rows: Option<TrackList>,
136 #[serde(default, skip_serializing_if = "Option::is_none")]
138 pub grid_auto_flow: Option<GridAutoFlow>,
139 #[serde(default, skip_serializing_if = "Option::is_none")]
141 pub gap: Option<Animated<LayoutSize>>,
142 #[serde(default, skip_serializing_if = "Option::is_none")]
145 pub row_gap: Option<Animated<LayoutSize>>,
146 #[serde(default, skip_serializing_if = "Option::is_none")]
148 pub column_gap: Option<Animated<LayoutSize>>,
149 #[serde(default, skip_serializing_if = "Option::is_none")]
151 pub justify_content: Option<JustifyContent>,
152 #[serde(default, skip_serializing_if = "Option::is_none")]
154 pub align_items: Option<AlignItems>,
155 #[serde(default, skip_serializing_if = "Option::is_none")]
158 pub align_content: Option<AlignContent>,
159 #[serde(default, skip_serializing_if = "Option::is_none")]
161 pub justify_items: Option<AlignItems>,
162
163 #[serde(default, skip_serializing_if = "Option::is_none")]
166 pub padding: Option<Animated<Insets>>,
167 #[serde(default, skip_serializing_if = "Option::is_none")]
170 pub background: Option<Animated<Paint>>,
171 #[serde(default, skip_serializing_if = "Option::is_none")]
173 pub border: Option<LayoutBorder>,
174 #[serde(default, skip_serializing_if = "Option::is_none")]
177 pub border_radius: Option<Animated<LayoutSize>>,
178 #[serde(default, skip_serializing_if = "Option::is_none")]
180 pub overflow: Option<Overflow>,
181
182 #[serde(default, skip_serializing_if = "Option::is_none")]
184 pub width: Option<Animated<LayoutLength>>,
185 #[serde(default, skip_serializing_if = "Option::is_none")]
187 pub height: Option<Animated<LayoutLength>>,
188 #[serde(default, skip_serializing_if = "Option::is_none")]
190 pub min_width: Option<Animated<LayoutLength>>,
191 #[serde(default, skip_serializing_if = "Option::is_none")]
193 pub min_height: Option<Animated<LayoutLength>>,
194 #[serde(default, skip_serializing_if = "Option::is_none")]
196 pub max_width: Option<Animated<LayoutLength>>,
197 #[serde(default, skip_serializing_if = "Option::is_none")]
199 pub max_height: Option<Animated<LayoutLength>>,
200 #[serde(default, skip_serializing_if = "Option::is_none")]
202 pub aspect_ratio: Option<f32>,
203 #[serde(default, skip_serializing_if = "Option::is_none")]
205 pub margin: Option<Animated<Insets>>,
206 #[serde(default, skip_serializing_if = "Option::is_none")]
209 pub flex_grow: Option<Animated<f32>>,
210 #[serde(default, skip_serializing_if = "Option::is_none")]
213 pub flex_shrink: Option<Animated<f32>>,
214 #[serde(default, skip_serializing_if = "Option::is_none")]
216 pub flex_basis: Option<Animated<LayoutLength>>,
217 #[serde(default, skip_serializing_if = "Option::is_none")]
220 pub align_self: Option<AlignItems>,
221 #[serde(default, skip_serializing_if = "Option::is_none")]
224 pub justify_self: Option<AlignItems>,
225 #[serde(default, skip_serializing_if = "Option::is_none")]
228 pub grid_column: Option<GridPlacement>,
229 #[serde(default, skip_serializing_if = "Option::is_none")]
231 pub grid_row: Option<GridPlacement>,
232 #[serde(default, skip_serializing_if = "Option::is_none")]
234 pub position: Option<Position>,
235 #[serde(default, skip_serializing_if = "Option::is_none")]
237 pub inset: Option<LayoutInset>,
238
239 #[serde(default, skip_serializing_if = "Option::is_none")]
242 pub font_family: Option<String>,
243 #[serde(default, skip_serializing_if = "Option::is_none")]
246 pub font_size: Option<Animated<LayoutSize>>,
247 #[serde(default, skip_serializing_if = "Option::is_none")]
249 pub fill: Option<Paint>,
250 #[serde(default, skip_serializing_if = "Option::is_none")]
253 pub line_height: Option<f32>,
254 #[serde(default, skip_serializing_if = "Option::is_none")]
257 pub letter_spacing: Option<f32>,
258 #[serde(default, skip_serializing_if = "Option::is_none")]
261 pub font_weight: Option<u16>,
262 #[serde(default, skip_serializing_if = "Option::is_none")]
264 pub text_align: Option<TextAlign>,
265 #[serde(default, skip_serializing_if = "Option::is_none")]
268 #[serde(deserialize_with = "crate::bounded::option_seq::<_, _, { crate::MAX_TEXT_STROKES }>")]
269 #[cfg_attr(feature = "schema", schemars(length(max = crate::MAX_TEXT_STROKES)))]
270 pub strokes: Option<Vec<TextStroke>>,
271 #[serde(default, skip_serializing_if = "Option::is_none")]
274 #[serde(deserialize_with = "crate::bounded::option_seq::<_, _, { crate::MAX_TEXT_SHADOWS }>")]
275 #[cfg_attr(feature = "schema", schemars(length(max = crate::MAX_TEXT_SHADOWS)))]
276 pub shadows: Option<Vec<TextShadow>>,
277 #[serde(default, skip_serializing_if = "Option::is_none")]
281 pub font_size_fit: Option<LayoutFontSizeFit>,
282 #[serde(default, skip_serializing_if = "Option::is_none")]
286 pub line_clamp: Option<crate::LineClamp>,
287 #[serde(default, skip_serializing_if = "Vec::is_empty")]
292 #[serde(deserialize_with = "crate::bounded::seq::<_, _, { crate::MAX_TEXT_ANIMATORS }>")]
293 #[cfg_attr(feature = "schema", schemars(length(max = crate::MAX_TEXT_ANIMATORS)))]
294 pub text_animators: Vec<crate::TextAnimator>,
295 #[serde(default, skip_serializing_if = "Option::is_none")]
298 pub text_animator_grouping: Option<crate::AnimatorGrouping>,
299 #[serde(default, skip_serializing_if = "Option::is_none")]
302 pub text_animator_pivot: Option<crate::Vec2>,
303
304 #[serde(default, skip_serializing_if = "Option::is_none")]
306 pub opacity: Option<Animated<f32>>,
307 #[serde(default, skip_serializing_if = "Option::is_none")]
310 pub translate: Option<Animated<LayoutOffset>>,
311 #[serde(default, skip_serializing_if = "Option::is_none")]
313 pub scale: Option<Animated<Vec2>>,
314 #[serde(default, skip_serializing_if = "Option::is_none")]
317 pub rotation_degrees: Option<Animated<f32>>,
318}
319
320#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Serialize)]
323#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
324#[serde(deny_unknown_fields)]
325pub struct LayoutFontSizeFit {
326 pub min: LayoutSize,
328 #[serde(default, skip_serializing_if = "Option::is_none")]
330 pub max: Option<LayoutSize>,
331}
332
333#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
336#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
337#[serde(deny_unknown_fields)]
338pub struct LayoutShape {
339 #[serde(deserialize_with = "crate::bounded::seq::<_, _, { crate::MAX_SHAPE_ITEMS }>")]
341 #[cfg_attr(feature = "schema", schemars(length(max = crate::MAX_SHAPE_ITEMS)))]
342 pub items: Vec<ShapeItem>,
343}
344
345#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
347#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
348#[serde(deny_unknown_fields)]
349pub struct LayoutBorder {
350 pub width: Animated<LayoutSize>,
352 pub paint: Animated<Paint>,
354}
355
356#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
359#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
360#[serde(deny_unknown_fields)]
361pub struct LayoutInset {
362 #[serde(default, skip_serializing_if = "Option::is_none")]
364 pub left: Option<Animated<LayoutLength>>,
365 #[serde(default, skip_serializing_if = "Option::is_none")]
367 pub top: Option<Animated<LayoutLength>>,
368 #[serde(default, skip_serializing_if = "Option::is_none")]
370 pub right: Option<Animated<LayoutLength>>,
371 #[serde(default, skip_serializing_if = "Option::is_none")]
373 pub bottom: Option<Animated<LayoutLength>>,
374}
375
376impl LayoutInset {
377 fn sides(&self) -> [(&'static str, Option<&Animated<LayoutLength>>); 4] {
378 [
379 ("left", self.left.as_ref()),
380 ("top", self.top.as_ref()),
381 ("right", self.right.as_ref()),
382 ("bottom", self.bottom.as_ref()),
383 ]
384 }
385}
386
387#[derive(Copy, Clone, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
389#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
390#[serde(rename_all = "snake_case")]
391pub enum Display {
392 #[default]
394 Flex,
395 Grid,
397}
398
399#[derive(Copy, Clone, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
401#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
402#[serde(rename_all = "snake_case")]
403pub enum FlexDirection {
404 #[default]
406 Row,
407 Column,
409 RowReverse,
411 ColumnReverse,
413}
414
415#[derive(Copy, Clone, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
417#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
418pub enum FlexWrap {
419 #[default]
421 #[serde(rename = "nowrap")]
422 NoWrap,
423 #[serde(rename = "wrap")]
425 Wrap,
426}
427
428#[derive(Copy, Clone, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
430#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
431#[serde(rename_all = "snake_case")]
432pub enum GridAutoFlow {
433 #[default]
435 Row,
436 Column,
438 RowDense,
440 ColumnDense,
442}
443
444#[derive(Copy, Clone, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
446#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
447#[serde(rename_all = "snake_case")]
448pub enum JustifyContent {
449 #[default]
451 Start,
452 Center,
454 End,
456 SpaceBetween,
458 SpaceAround,
460 SpaceEvenly,
462}
463
464#[derive(Copy, Clone, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
466#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
467#[serde(rename_all = "snake_case")]
468pub enum AlignContent {
469 Start,
471 Center,
473 End,
475 SpaceBetween,
477 SpaceAround,
479 SpaceEvenly,
481 #[default]
483 Stretch,
484}
485
486#[derive(Copy, Clone, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
488#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
489#[serde(rename_all = "snake_case")]
490pub enum AlignItems {
491 Start,
493 Center,
495 End,
497 #[default]
499 Stretch,
500}
501
502#[derive(Copy, Clone, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
504#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
505#[serde(rename_all = "snake_case")]
506pub enum Position {
507 #[default]
509 Relative,
510 Absolute,
512}
513
514#[derive(Copy, Clone, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
516#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
517#[serde(rename_all = "snake_case")]
518pub enum Overflow {
519 #[default]
521 Visible,
522 Hidden,
524}
525
526#[derive(Copy, Clone, Debug, Eq, PartialEq)]
528#[non_exhaustive]
529pub enum LayoutProblem {
530 TooManyNodes,
532 TooDeep,
534 TooManyTexts,
536 TooManyIsolated,
538 MixedContent,
540 DisplayOnLeaf,
542 ContainerFieldOnLeaf,
544 RootItemField,
546 GridFieldOnFlex(&'static str),
548 FlexFieldOnGrid(&'static str),
550 FlexItemFieldInGrid(&'static str),
552 GridItemFieldInFlex(&'static str),
554 TooManyTracks,
556 RepeatCount,
558 RepeatInAutoTracks,
560 AutoRepeatNeedsFixedTracks,
562 GridLineOutOfRange,
564 InvalidKeyframes,
566 OutOfRange,
568 LengthKeyframesDiffer,
570 PaintKeyframesDiffer,
572 TextKeyframesInterpolate,
574 TextRunNotStatic,
576}
577
578impl fmt::Display for LayoutProblem {
579 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
580 match self {
581 Self::GridFieldOnFlex(field) => {
582 return write!(
583 formatter,
584 "sets {field}, a grid container field, without display grid"
585 );
586 }
587 Self::FlexFieldOnGrid(field) => {
588 return write!(
589 formatter,
590 "sets {field}, a flex container field, on a grid container"
591 );
592 }
593 Self::FlexItemFieldInGrid(field) => {
594 return write!(
595 formatter,
596 "sets {field}, a flex item field, in a grid container"
597 );
598 }
599 Self::GridItemFieldInFlex(field) => {
600 return write!(
601 formatter,
602 "sets {field}, a grid item field, in a flex container"
603 );
604 }
605 _ => {}
606 }
607 formatter.write_str(match self {
608 Self::TooManyNodes => "has more nodes than a layout may hold",
609 Self::TooDeep => "nests nodes too deeply",
610 Self::TooManyTexts => "has more text nodes than a layout may hold",
611 Self::TooManyIsolated => {
612 "has more nodes with opacity, transforms, or hidden overflow than a layout may hold"
613 }
614 Self::MixedContent => "has more than one of children, text, and shape",
615 Self::DisplayOnLeaf => "sets display on a node with text or shape content",
616 Self::ContainerFieldOnLeaf => {
617 "sets a container field on a node with text or shape content"
618 }
619 Self::RootItemField => "sets a size, margin, position, or item field on the root",
620 Self::TooManyTracks => "has more than 64 tracks",
621 Self::RepeatCount => "repeats tracks a number of times outside 1 to 64",
622 Self::RepeatInAutoTracks => "uses repeat() in implicit track sizes",
623 Self::AutoRepeatNeedsFixedTracks => {
624 "repeats auto-fill or auto-fit beside another, or with a track without a fixed size"
625 }
626 Self::GridLineOutOfRange => {
627 "names a grid line outside -65 to 65 or line 0, or a span outside 1 to 64"
628 }
629 Self::InvalidKeyframes => "has invalid keyframes",
630 Self::OutOfRange => "has a value out of range",
631 Self::LengthKeyframesDiffer => "has size keyframes that differ in kind",
632 Self::PaintKeyframesDiffer => "has paint keyframes that differ in kind or stops",
633 Self::TextKeyframesInterpolate => "has text keyframes that do not hold",
634 Self::TextRunNotStatic => "has a run with a class, a time or a keyframed font scale",
635 Self::GridFieldOnFlex(_)
636 | Self::FlexFieldOnGrid(_)
637 | Self::FlexItemFieldInGrid(_)
638 | Self::GridItemFieldInFlex(_) => unreachable!("written above"),
639 })
640 }
641}
642
643#[derive(Clone, Debug, Eq, PartialEq)]
645pub struct LayoutIssue {
646 pub at: String,
648 pub problem: LayoutProblem,
650}
651
652impl LayoutIssue {
653 fn new(at: impl Into<String>, problem: LayoutProblem) -> Self {
654 Self {
655 at: at.into(),
656 problem,
657 }
658 }
659}
660
661impl From<ValueIssue> for LayoutIssue {
662 fn from(issue: ValueIssue) -> Self {
663 Self::new(
664 issue.at,
665 match issue.problem {
666 ValueProblem::InvalidKeyframes => LayoutProblem::InvalidKeyframes,
667 ValueProblem::OutOfRange => LayoutProblem::OutOfRange,
668 ValueProblem::PaintKeyframesDiffer => LayoutProblem::PaintKeyframesDiffer,
669 },
670 )
671 }
672}
673
674#[derive(Clone, Debug, Eq, PartialEq)]
676pub enum GeneratorIssue {
677 Invalid,
679 TextRun {
682 run: usize,
684 },
685 Shape(ShapeIssue),
688 Layout(LayoutIssue),
690}
691
692impl From<LayoutIssue> for GeneratorIssue {
693 fn from(issue: LayoutIssue) -> Self {
694 Self::Layout(issue)
695 }
696}
697
698impl From<ValueIssue> for GeneratorIssue {
699 fn from(issue: ValueIssue) -> Self {
700 Self::Layout(issue.into())
701 }
702}
703
704#[derive(Default)]
706struct Counts {
707 nodes: usize,
708 texts: usize,
709 isolated: usize,
710 shape_items: usize,
711}
712
713type LayoutChecked = Result<(), GeneratorIssue>;
714
715#[derive(Copy, Clone)]
718struct Context<'a> {
719 shorter_side: Option<f32>,
720 parent: Option<Display>,
721 family: Option<&'a str>,
722 weight: u16,
723}
724
725pub(crate) fn validate_layout(root: &LayoutNode, canvas: Option<(u32, u32)>) -> LayoutChecked {
732 let mut counts = Counts::default();
733 if root.has_item_field() {
734 return Err(LayoutIssue::new("root", LayoutProblem::RootItemField).into());
735 }
736 #[allow(clippy::cast_precision_loss)]
737 let shorter_side = canvas.map(|(width, height)| width.min(height) as f32);
738 let context = Context {
739 shorter_side,
740 parent: None,
741 family: None,
742 weight: crate::TextStyle::default().font_weight,
743 };
744 validate_node(root, "root", 1, context, &mut counts)
745}
746
747fn validate_node<'a>(
748 node: &'a LayoutNode,
749 at: &str,
750 depth: usize,
751 context: Context<'a>,
752 counts: &mut Counts,
753) -> LayoutChecked {
754 let issue = |problem| Err(LayoutIssue::new(at, problem).into());
755 counts.nodes += 1;
756 if counts.nodes > MAX_LAYOUT_NODES {
757 return issue(LayoutProblem::TooManyNodes);
758 }
759 if depth > MAX_LAYOUT_DEPTH {
760 return issue(LayoutProblem::TooDeep);
761 }
762 let contents = usize::from(!node.children.is_empty())
763 + usize::from(node.text.is_some())
764 + usize::from(node.shape.is_some());
765 if contents > 1 {
766 return issue(LayoutProblem::MixedContent);
767 }
768 let leaf = node.text.is_some() || node.shape.is_some();
769 if leaf && node.display.is_some() {
770 return issue(LayoutProblem::DisplayOnLeaf);
771 }
772 if leaf && node.has_container_field() {
773 return issue(LayoutProblem::ContainerFieldOnLeaf);
774 }
775 let display = node.display.unwrap_or_default();
776 let mismatch = match display {
777 Display::Flex => node
778 .grid_container_field()
779 .map(LayoutProblem::GridFieldOnFlex),
780 Display::Grid => node
781 .flex_container_field()
782 .map(LayoutProblem::FlexFieldOnGrid),
783 };
784 if let Some(problem) = mismatch {
785 return issue(problem);
786 }
787 let item_mismatch = match context.parent {
788 Some(Display::Flex) => node
789 .grid_item_field()
790 .map(LayoutProblem::GridItemFieldInFlex),
791 Some(Display::Grid) => node
792 .flex_item_field()
793 .map(LayoutProblem::FlexItemFieldInGrid),
794 None => None,
795 };
796 if let Some(problem) = item_mismatch {
797 return issue(problem);
798 }
799 if node.text.is_some() {
800 counts.texts += 1;
801 if counts.texts > MAX_LAYOUT_TEXTS {
802 return issue(LayoutProblem::TooManyTexts);
803 }
804 }
805 if node.is_isolated() {
806 counts.isolated += 1;
807 if counts.isolated > MAX_LAYOUT_ISOLATED {
808 return issue(LayoutProblem::TooManyIsolated);
809 }
810 }
811 validate_fields(node, at)?;
812 validate_grid(node, at)?;
813 validate_style(node, at, context.shorter_side)?;
814 let family = node.font_family.as_deref().or(context.family);
815 let weight = node.font_weight.unwrap_or(context.weight);
816 if let Some(text) = &node.text {
817 let base = crate::text_animation::FontSelection {
818 family,
819 weight,
820 style: crate::FontStyle::Normal,
821 };
822 validate_text(text, &format!("{at}.text"), base)?;
823 }
824 if let Some(shape) = &node.shape {
825 crate::shapes::validate_items(
826 &shape.items,
827 &format!("{at}.shape.items"),
828 1,
829 &mut counts.shape_items,
830 )
831 .map_err(GeneratorIssue::Shape)?;
832 }
833 let inner = Context {
834 shorter_side: context.shorter_side,
835 parent: Some(display),
836 family,
837 weight,
838 };
839 for (index, child) in node.children.iter().enumerate() {
840 validate_node(
841 child,
842 &format!("{at}.children[{index}]"),
843 depth + 1,
844 inner,
845 counts,
846 )?;
847 }
848 Ok(())
849}
850
851fn optional<T, E>(value: Option<&T>, check: impl FnOnce(&T) -> Result<(), E>) -> LayoutChecked
852where
853 GeneratorIssue: From<E>,
854{
855 Ok(value.map_or(Ok(()), check)?)
856}
857
858fn flex_factor(value: f32) -> bool {
859 (0.0..=MAX_FLEX_FACTOR).contains(&value)
860}
861
862fn validate_fields(node: &LayoutNode, at: &str) -> LayoutChecked {
863 let field = |name: &str| format!("{at}.{name}");
864 for (name, gap) in [
865 ("gap", &node.gap),
866 ("row_gap", &node.row_gap),
867 ("column_gap", &node.column_gap),
868 ] {
869 optional(gap.as_ref(), |gap| size(gap, &field(name), non_negative))?;
870 }
871 optional(node.padding.as_ref(), |padding| {
872 insets(padding, &field("padding"), non_negative)
873 })?;
874 optional(node.background.as_ref(), |paint| {
875 validate_paint(paint, &field("background"))
876 })?;
877 if let Some(border) = &node.border {
878 size(&border.width, &field("border.width"), non_negative)?;
879 validate_paint(&border.paint, &field("border.paint"))?;
880 }
881 optional(node.border_radius.as_ref(), |radius| {
882 size(radius, &field("border_radius"), non_negative)
883 })?;
884 for (name, size) in [
885 ("width", &node.width),
886 ("height", &node.height),
887 ("min_width", &node.min_width),
888 ("min_height", &node.min_height),
889 ("max_width", &node.max_width),
890 ("max_height", &node.max_height),
891 ] {
892 optional(size.as_ref(), |size| {
893 length(size, &field(name), non_negative)
894 })?;
895 }
896 if node
897 .aspect_ratio
898 .is_some_and(|ratio| !ASPECT_RATIO_RANGE.contains(&ratio))
899 {
900 return Err(ValueIssue::new(field("aspect_ratio"), ValueProblem::OutOfRange).into());
901 }
902 optional(node.margin.as_ref(), |margin| {
903 insets(margin, &field("margin"), any)
904 })?;
905 optional(node.flex_grow.as_ref(), |grow| {
906 scalar(grow, &field("flex_grow"), flex_factor)
907 })?;
908 optional(node.flex_shrink.as_ref(), |shrink| {
909 scalar(shrink, &field("flex_shrink"), flex_factor)
910 })?;
911 optional(node.flex_basis.as_ref(), |basis| {
912 length(basis, &field("flex_basis"), non_negative)
913 })?;
914 if let Some(inset) = &node.inset {
915 for (name, side) in inset.sides() {
916 optional(side, |side| {
917 length(side, &field(&format!("inset.{name}")), any)
918 })?;
919 }
920 }
921 optional(node.opacity.as_ref(), |opacity| {
922 scalar(opacity, &field("opacity"), unit)
923 })?;
924 optional(node.translate.as_ref(), |translate| {
925 animated(translate, &field("translate"), |offset| {
926 offset.x.in_bounds() && offset.y.in_bounds()
927 })
928 })?;
929 optional(node.scale.as_ref(), |scale| {
930 vec2(scale, &field("scale"), |_| true)
931 })?;
932 optional(node.rotation_degrees.as_ref(), |rotation| {
933 scalar(rotation, &field("rotation_degrees"), any)
934 })
935}
936
937fn validate_grid(node: &LayoutNode, at: &str) -> LayoutChecked {
939 let issue = |name: &str, problem| Err(LayoutIssue::new(format!("{at}.{name}"), problem).into());
940 for (name, tracks, explicit) in [
941 ("grid_template_columns", &node.grid_template_columns, true),
942 ("grid_template_rows", &node.grid_template_rows, true),
943 ("grid_auto_columns", &node.grid_auto_columns, false),
944 ("grid_auto_rows", &node.grid_auto_rows, false),
945 ] {
946 let Some(tracks) = tracks else { continue };
947 if let Some(problem) = track_problem(tracks, explicit) {
948 return issue(name, problem);
949 }
950 }
951 for (name, placement) in [
952 ("grid_column", node.grid_column),
953 ("grid_row", node.grid_row),
954 ] {
955 let in_range = |edge: GridEdge| match edge {
956 GridEdge::Auto => true,
957 GridEdge::Line(line) => line != 0 && (-MAX_GRID_LINE..=MAX_GRID_LINE).contains(&line),
958 GridEdge::Span(count) => (1..=64).contains(&count),
959 };
960 if placement.is_some_and(|placement| !placement.edges().into_iter().all(in_range)) {
961 return issue(name, LayoutProblem::GridLineOutOfRange);
962 }
963 }
964 Ok(())
965}
966
967fn track_problem(tracks: &TrackList, explicit: bool) -> Option<LayoutProblem> {
968 let lengths_valid = tracks
969 .lengths()
970 .all(|length| length.in_bounds() && length.value() >= 0.0);
971 let shares_valid = tracks
972 .shares()
973 .all(|share| share.is_finite() && share > 0.0);
974 if !(lengths_valid && shares_valid) {
975 return Some(LayoutProblem::OutOfRange);
976 }
977 let repeats = tracks.0.iter().filter_map(|component| match component {
978 TrackComponent::Repeat(count, _) => Some(*count),
979 TrackComponent::Single(_) => None,
980 });
981 if !explicit && repeats.clone().next().is_some() {
982 return Some(LayoutProblem::RepeatInAutoTracks);
983 }
984 if repeats
985 .clone()
986 .any(|count| matches!(count, RepeatCount::Count(count) if !(1..=64).contains(&count)))
987 {
988 return Some(LayoutProblem::RepeatCount);
989 }
990 if tracks.track_count() > MAX_GRID_TRACKS {
991 return Some(LayoutProblem::TooManyTracks);
992 }
993 let automatic = repeats
994 .filter(|count| !matches!(count, RepeatCount::Count(_)))
995 .count();
996 if automatic > 1
997 || (automatic == 1
998 && !tracks
999 .sizes()
1000 .all(crate::layout_values::TrackSize::is_fixed))
1001 {
1002 return Some(LayoutProblem::AutoRepeatNeedsFixedTracks);
1003 }
1004 None
1005}
1006
1007fn validate_style(node: &LayoutNode, at: &str, shorter_side: Option<f32>) -> LayoutChecked {
1009 let out_of_range = |name: &str| {
1010 Err(LayoutIssue::new(format!("{at}.{name}"), LayoutProblem::OutOfRange).into())
1011 };
1012 if node
1013 .font_family
1014 .as_ref()
1015 .is_some_and(|family| family.is_empty() || family.len() > MAX_FONT_FAMILY_BYTES)
1016 {
1017 return out_of_range("font_family");
1018 }
1019 optional(node.font_size.as_ref(), |font_size| {
1020 animated(font_size, &format!("{at}.font_size"), |value| {
1021 let fraction = match (*value, shorter_side) {
1023 (LayoutSize::Px(_), None) => 0.0,
1024 (value, Some(side)) => value.fraction(side),
1025 (value, None) => value.value(),
1026 };
1027 value.value().is_finite() && value.value() > 0.0 && fraction <= MAX_LAYOUT_FONT_SIZE
1028 })
1029 })?;
1030 if node.fill.as_ref().is_some_and(|fill| !fill.is_valid()) {
1031 return out_of_range("fill");
1032 }
1033 if node
1034 .line_height
1035 .is_some_and(|height| !LINE_HEIGHT_RANGE.contains(&height))
1036 {
1037 return out_of_range("line_height");
1038 }
1039 if node
1040 .letter_spacing
1041 .is_some_and(|spacing| !LETTER_SPACING_RANGE.contains(&spacing))
1042 {
1043 return out_of_range("letter_spacing");
1044 }
1045 if node
1046 .font_weight
1047 .is_some_and(|weight| !FONT_WEIGHT_RANGE.contains(&weight))
1048 {
1049 return out_of_range("font_weight");
1050 }
1051 if node
1052 .strokes
1053 .as_deref()
1054 .is_some_and(|strokes| !crate::text::valid_strokes(strokes))
1055 {
1056 return out_of_range("strokes");
1057 }
1058 if node
1059 .shadows
1060 .as_deref()
1061 .is_some_and(|shadows| !crate::text::valid_shadows(shadows))
1062 {
1063 return out_of_range("shadows");
1064 }
1065 if !crate::text_animation::valid_animators(&node.text_animators, true) {
1066 return out_of_range("text_animators");
1067 }
1068 if !node
1069 .text_animator_pivot
1070 .is_none_or(crate::text::valid_animator_pivot)
1071 {
1072 return out_of_range("text_animator_pivot");
1073 }
1074 if let Some(fit) = &node.font_size_fit {
1075 let font_size = |value: LayoutSize| {
1076 let fraction = match (value, shorter_side) {
1078 (LayoutSize::Px(_), None) => 0.0,
1079 (value, Some(side)) => value.fraction(side),
1080 (value, None) => value.value(),
1081 };
1082 value.value().is_finite() && value.value() > 0.0 && fraction <= MAX_LAYOUT_FONT_SIZE
1083 };
1084 let ordered = match (fit.min, fit.max, shorter_side) {
1085 (min, Some(max), Some(side)) => min.fraction(side) <= max.fraction(side),
1086 (LayoutSize::Fraction(min), Some(LayoutSize::Fraction(max)), None)
1087 | (LayoutSize::Px(min), Some(LayoutSize::Px(max)), None) => min <= max,
1088 _ => true,
1089 };
1090 if !font_size(fit.min) || !fit.max.is_none_or(font_size) || !ordered {
1091 return out_of_range("font_size_fit");
1092 }
1093 }
1094 if node
1095 .line_clamp
1096 .as_ref()
1097 .is_some_and(|clamp| !clamp.is_valid())
1098 {
1099 return out_of_range("line_clamp");
1100 }
1101 Ok(())
1102}
1103
1104fn insets(animation: &Animated<Insets>, at: &str, check: fn(f32) -> bool) -> Checked {
1105 animated(animation, at, |value| {
1106 value
1107 .sides()
1108 .iter()
1109 .all(|side| side.in_bounds() && check(side.value()))
1110 })
1111}
1112
1113fn size(animation: &Animated<LayoutSize>, at: &str, check: fn(f32) -> bool) -> Checked {
1114 animated(animation, at, |value| {
1115 value.in_bounds() && check(value.value())
1116 })
1117}
1118
1119fn length(
1122 animation: &Animated<LayoutLength>,
1123 at: &str,
1124 check: fn(f32) -> bool,
1125) -> Result<(), GeneratorIssue> {
1126 animated(animation, at, |value| {
1127 value.in_bounds() && check(value.value())
1128 })?;
1129 if let Animated::Keyframes { keyframes } = animation {
1130 let kind = keyframes[0].value.is_percent();
1131 if keyframes.iter().any(|key| key.value.is_percent() != kind) {
1132 return Err(LayoutIssue::new(at, LayoutProblem::LengthKeyframesDiffer).into());
1133 }
1134 }
1135 Ok(())
1136}
1137
1138fn validate_text(
1139 content: &Animated<crate::TextContent>,
1140 at: &str,
1141 base: crate::text_animation::FontSelection<'_>,
1142) -> LayoutChecked {
1143 animated(content, at, |_| true)?;
1144 if let Animated::Keyframes { keyframes } = content
1145 && keyframes
1146 .iter()
1147 .any(|key| key.interpolation != Interpolation::Hold)
1148 {
1149 return Err(LayoutIssue::new(at, LayoutProblem::TextKeyframesInterpolate).into());
1150 }
1151 let not_static = |content: &crate::TextContent| {
1152 content.runs().iter().any(|run| {
1153 !run.class.is_empty()
1154 || run.time.is_some()
1155 || run.style.as_ref().is_some_and(|style| !style.is_static())
1156 })
1157 };
1158 let runs_static = match content {
1159 Animated::Constant { value } => !not_static(value),
1160 Animated::Keyframes { keyframes } => !keyframes.iter().any(|key| not_static(&key.value)),
1161 Animated::Data(_) => true,
1162 };
1163 if !runs_static {
1164 return Err(LayoutIssue::new(at, LayoutProblem::TextRunNotStatic).into());
1165 }
1166 animated(content, at, |content| {
1167 content.len() <= MAX_TEXT_CONTENT_BYTES
1168 && content.runs().iter().all(|run| !run.text.is_empty())
1169 && content.invalid_run_style(base).is_none()
1170 })?;
1171 Ok(())
1172}
1173
1174impl LayoutNode {
1175 fn has_container_field(&self) -> bool {
1177 self.flex_container_field().is_some()
1178 || self.grid_container_field().is_some()
1179 || self.gap.is_some()
1180 || self.row_gap.is_some()
1181 || self.column_gap.is_some()
1182 || self.justify_content.is_some()
1183 || self.align_items.is_some()
1184 || self.align_content.is_some()
1185 }
1186
1187 fn flex_container_field(&self) -> Option<&'static str> {
1189 [
1190 ("flex_direction", self.flex_direction.is_some()),
1191 ("flex_wrap", self.flex_wrap.is_some()),
1192 ]
1193 .into_iter()
1194 .find_map(|(name, present)| present.then_some(name))
1195 }
1196
1197 fn grid_container_field(&self) -> Option<&'static str> {
1199 [
1200 (
1201 "grid_template_columns",
1202 self.grid_template_columns.is_some(),
1203 ),
1204 ("grid_template_rows", self.grid_template_rows.is_some()),
1205 ("grid_auto_columns", self.grid_auto_columns.is_some()),
1206 ("grid_auto_rows", self.grid_auto_rows.is_some()),
1207 ("grid_auto_flow", self.grid_auto_flow.is_some()),
1208 ("justify_items", self.justify_items.is_some()),
1209 ]
1210 .into_iter()
1211 .find_map(|(name, present)| present.then_some(name))
1212 }
1213
1214 fn flex_item_field(&self) -> Option<&'static str> {
1216 [
1217 ("flex_grow", self.flex_grow.is_some()),
1218 ("flex_shrink", self.flex_shrink.is_some()),
1219 ("flex_basis", self.flex_basis.is_some()),
1220 ]
1221 .into_iter()
1222 .find_map(|(name, present)| present.then_some(name))
1223 }
1224
1225 fn grid_item_field(&self) -> Option<&'static str> {
1227 [
1228 ("grid_column", self.grid_column.is_some()),
1229 ("grid_row", self.grid_row.is_some()),
1230 ("justify_self", self.justify_self.is_some()),
1231 ]
1232 .into_iter()
1233 .find_map(|(name, present)| present.then_some(name))
1234 }
1235
1236 fn has_item_field(&self) -> bool {
1238 self.width.is_some()
1239 || self.height.is_some()
1240 || self.min_width.is_some()
1241 || self.min_height.is_some()
1242 || self.max_width.is_some()
1243 || self.max_height.is_some()
1244 || self.aspect_ratio.is_some()
1245 || self.margin.is_some()
1246 || self.flex_item_field().is_some()
1247 || self.grid_item_field().is_some()
1248 || self.align_self.is_some()
1249 || self.position.is_some()
1250 || self.inset.is_some()
1251 }
1252
1253 #[must_use]
1255 pub const fn has_visual(&self) -> bool {
1256 self.opacity.is_some()
1257 || self.translate.is_some()
1258 || self.scale.is_some()
1259 || self.rotation_degrees.is_some()
1260 }
1261
1262 #[must_use]
1265 pub const fn is_isolated(&self) -> bool {
1266 self.has_visual() || matches!(self.overflow, Some(Overflow::Hidden))
1267 }
1268
1269 #[must_use]
1271 pub fn is_animated(&self) -> bool {
1272 let inset = self.inset.as_ref().is_some_and(|inset| {
1273 inset
1274 .sides()
1275 .into_iter()
1276 .any(|(_, value)| keyed_option(value))
1277 });
1278 let shape = self
1279 .shape
1280 .as_ref()
1281 .is_some_and(|shape| shape.items.iter().any(ShapeItem::is_animated));
1282 let border = self
1283 .border
1284 .as_ref()
1285 .is_some_and(|border| keyed(&border.width) || keyed(&border.paint));
1286 [
1287 &self.gap,
1288 &self.row_gap,
1289 &self.column_gap,
1290 &self.border_radius,
1291 &self.font_size,
1292 ]
1293 .into_iter()
1294 .any(|value| keyed_option(value.as_ref()))
1295 || keyed_option(self.padding.as_ref())
1296 || keyed_option(self.background.as_ref())
1297 || border
1298 || [
1299 &self.width,
1300 &self.height,
1301 &self.min_width,
1302 &self.min_height,
1303 &self.max_width,
1304 &self.max_height,
1305 &self.flex_basis,
1306 ]
1307 .into_iter()
1308 .any(|value| keyed_option(value.as_ref()))
1309 || keyed_option(self.margin.as_ref())
1310 || keyed_option(self.flex_grow.as_ref())
1311 || keyed_option(self.flex_shrink.as_ref())
1312 || inset
1313 || keyed_option(self.opacity.as_ref())
1314 || keyed_option(self.translate.as_ref())
1315 || keyed_option(self.scale.as_ref())
1316 || keyed_option(self.rotation_degrees.as_ref())
1317 || keyed_option(self.text.as_ref())
1318 || shape
1319 || crate::text_animation::animators_have_keyframes(&self.text_animators)
1320 || self.children.iter().any(Self::is_animated)
1321 }
1322
1323 pub fn walk(&self, mut visit: impl FnMut(&str, &Self)) {
1325 fn go(node: &LayoutNode, at: &str, visit: &mut impl FnMut(&str, &LayoutNode)) {
1326 visit(at, node);
1327 for (index, child) in node.children.iter().enumerate() {
1328 go(child, &format!("{at}.children[{index}]"), visit);
1329 }
1330 }
1331 go(self, "root", &mut visit);
1332 }
1333
1334 pub(crate) fn for_each_keyed(
1337 &self,
1338 at: &str,
1339 visit: &mut impl FnMut(&str, crate::animation::Keyed<'_>),
1340 ) {
1341 let field = |name: &str| format!("{at}.{name}");
1342 if let Some(text) = &self.text {
1343 visit_keyed(&field("text"), text, visit);
1344 }
1345 if let Some(shape) = &self.shape {
1346 crate::shapes::for_each_keyed_item(&shape.items, &field("shape.items"), visit);
1347 }
1348 crate::text_animation::for_each_keyed_animator(
1349 &self.text_animators,
1350 &field("text_animators"),
1351 visit,
1352 );
1353 for (name, value) in [
1354 ("gap", &self.gap),
1355 ("row_gap", &self.row_gap),
1356 ("column_gap", &self.column_gap),
1357 ("border_radius", &self.border_radius),
1358 ("font_size", &self.font_size),
1359 ] {
1360 visit_option(&field(name), value.as_ref(), visit);
1361 }
1362 visit_option(&field("padding"), self.padding.as_ref(), visit);
1363 visit_option(&field("background"), self.background.as_ref(), visit);
1364 if let Some(border) = &self.border {
1365 visit_keyed(&field("border.width"), &border.width, visit);
1366 visit_keyed(&field("border.paint"), &border.paint, visit);
1367 }
1368 for (name, value) in [
1369 ("width", &self.width),
1370 ("height", &self.height),
1371 ("min_width", &self.min_width),
1372 ("min_height", &self.min_height),
1373 ("max_width", &self.max_width),
1374 ("max_height", &self.max_height),
1375 ("flex_basis", &self.flex_basis),
1376 ] {
1377 visit_option(&field(name), value.as_ref(), visit);
1378 }
1379 visit_option(&field("margin"), self.margin.as_ref(), visit);
1380 visit_option(&field("flex_grow"), self.flex_grow.as_ref(), visit);
1381 visit_option(&field("flex_shrink"), self.flex_shrink.as_ref(), visit);
1382 if let Some(inset) = &self.inset {
1383 for (side, value) in inset.sides() {
1384 visit_option(&field(&format!("inset.{side}")), value, visit);
1385 }
1386 }
1387 visit_option(&field("opacity"), self.opacity.as_ref(), visit);
1388 visit_option(&field("translate"), self.translate.as_ref(), visit);
1389 visit_option(&field("scale"), self.scale.as_ref(), visit);
1390 visit_option(
1391 &field("rotation_degrees"),
1392 self.rotation_degrees.as_ref(),
1393 visit,
1394 );
1395 for (index, child) in self.children.iter().enumerate() {
1396 child.for_each_keyed(&format!("{at}.children[{index}]"), visit);
1397 }
1398 }
1399
1400 #[must_use]
1403 pub fn without_px(&self, shorter_side: f32) -> Self {
1404 let mut node = self.clone();
1405 node.convert_px(shorter_side);
1406 node
1407 }
1408
1409 fn convert_px(&mut self, shorter_side: f32) {
1410 let size = |value: &mut Option<Animated<LayoutSize>>| {
1411 if let Some(value) = value {
1412 *value = value.map(|size| size.without_px(shorter_side));
1413 }
1414 };
1415 let length = |value: &mut Option<Animated<LayoutLength>>| {
1416 if let Some(value) = value {
1417 *value = value.map(|length| length.without_px(shorter_side));
1418 }
1419 };
1420 let insets = |value: &mut Option<Animated<Insets>>| {
1421 if let Some(value) = value {
1422 *value = value.map(|insets| insets.without_px(shorter_side));
1423 }
1424 };
1425 let tracks = |value: &mut Option<TrackList>| {
1426 if let Some(tracks) = value {
1427 *tracks = tracks.without_px(shorter_side);
1428 }
1429 };
1430 tracks(&mut self.grid_template_columns);
1431 tracks(&mut self.grid_template_rows);
1432 tracks(&mut self.grid_auto_columns);
1433 tracks(&mut self.grid_auto_rows);
1434 for value in [
1435 &mut self.gap,
1436 &mut self.row_gap,
1437 &mut self.column_gap,
1438 &mut self.border_radius,
1439 &mut self.font_size,
1440 ] {
1441 size(value);
1442 }
1443 if let Some(fit) = &mut self.font_size_fit {
1444 fit.min = fit.min.without_px(shorter_side);
1445 fit.max = fit.max.map(|max| max.without_px(shorter_side));
1446 }
1447 insets(&mut self.padding);
1448 insets(&mut self.margin);
1449 if let Some(border) = &mut self.border {
1450 border.width = border.width.map(|width| width.without_px(shorter_side));
1451 }
1452 for value in [
1453 &mut self.width,
1454 &mut self.height,
1455 &mut self.min_width,
1456 &mut self.min_height,
1457 &mut self.max_width,
1458 &mut self.max_height,
1459 &mut self.flex_basis,
1460 ] {
1461 length(value);
1462 }
1463 if let Some(inset) = &mut self.inset {
1464 for side in [
1465 &mut inset.left,
1466 &mut inset.top,
1467 &mut inset.right,
1468 &mut inset.bottom,
1469 ] {
1470 length(side);
1471 }
1472 }
1473 if let Some(translate) = &mut self.translate {
1474 *translate = translate.map(|offset| offset.without_px(shorter_side));
1475 }
1476 for child in &mut self.children {
1477 child.convert_px(shorter_side);
1478 }
1479 }
1480}
1481
1482fn visit_option<T: crate::animation::Placed>(
1483 at: &str,
1484 animation: Option<&Animated<T>>,
1485 visit: &mut impl FnMut(&str, crate::animation::Keyed<'_>),
1486) {
1487 if let Some(animation) = animation {
1488 visit_keyed(at, animation, visit);
1489 }
1490}
1491
1492const fn keyed<T>(animation: &Animated<T>) -> bool {
1493 matches!(animation, Animated::Keyframes { .. })
1494}
1495
1496const fn keyed_option<T>(animation: Option<&Animated<T>>) -> bool {
1497 matches!(animation, Some(Animated::Keyframes { .. }))
1498}