Skip to main content

pax_runtime_api/
constants.rs

1#![allow(unused)]
2//! Compiler-facing type and property spelling constants.
3
4// Runtime API type names used by parser and manifest plumbing.
5pub const NUMERIC: &str = "Numeric";
6pub const SIZE: &str = "Size";
7pub const ROTATION: &str = "Rotation";
8pub const DURATION: &str = "Duration";
9pub const OPACITY: &str = "Opacity";
10pub const DEGREES: &str = "Degrees";
11pub const RADIANS: &str = "Radians";
12pub const PIXELS: &str = "Pixels";
13pub const PERCENT: &str = "Percent";
14pub const MILLISECONDS: &str = "Milliseconds";
15pub const SECONDS: &str = "Seconds";
16pub const FRAMES: &str = "Frames";
17pub const INTEGER: &str = "Integer";
18pub const I64: &str = "I64";
19pub const F64: &str = "F64";
20pub const TRUE: &str = "true";
21pub const COLOR: &str = "Color";
22pub const COLOR_CHANNEL: &str = "ColorChannel";
23
24// Template-node sentinel type IDs.
25pub const TYPE_ID_IF: &str = "IF";
26pub const TYPE_ID_REPEAT: &str = "REPEAT";
27pub const TYPE_ID_SLOT: &str = "SLOT";
28pub const TYPE_ID_COMMENT: &str = "COMMENT";
29
30// Property names that every renderable node may accept.
31pub const COMMON_PROPERTIES: [&str; 20] = [
32    "id",
33    "x",
34    "y",
35    "padding_x",
36    "padding_y",
37    "scale",
38    "scale_x",
39    "scale_y",
40    "skew",
41    "skew_x",
42    "skew_y",
43    "anchor",
44    "anchor_x",
45    "anchor_y",
46    "rotate",
47    "transform",
48    "width",
49    "height",
50    "opacity",
51    "layout_role",
52];
53
54// Multi-axis common-property aliases expanded into their axis-specific forms.
55// These intentionally cover the suffix-based common properties; generic names
56// like `size` would shadow existing component APIs.
57pub const COMMON_PROPERTIES_2D: &[(&str, [&str; 2])] = &[
58    ("scale", ["scale_x", "scale_y"]),
59    ("skew", ["skew_x", "skew_y"]),
60    ("anchor", ["anchor_x", "anchor_y"]),
61];
62
63// Checks whether contextual `into` inference should be attempted for a target type.
64pub fn is_intoable_downstream_type(type_to_check: &str) -> bool {
65    BLESSED_INTOABLE_DOWNSTREAM_TYPES
66        .iter()
67        .any(|bidt| type_to_check.contains(*bidt))
68}
69
70// Only when parsing values for one of the types in this slice
71// will we look ahead and parse for an IntoableLiteral value.
72const BLESSED_INTOABLE_DOWNSTREAM_TYPES: [&'static str; 7] = [
73    "pax_engine::api::Size",
74    "pax_engine::api::Rotation",
75    "pax_engine::api::ColorChannel",
76    "pax_engine::api::Opacity",
77    "pax_engine::api::Stroke",
78    "pax_engine::api::Paint",
79    "pax_engine::api::Fill",
80];
81
82// Common property names paired with their compiler-facing type spellings.
83pub const COMMON_PROPERTIES_TYPE: &[(&str, &str)] = &[
84    ("id", "String"),
85    ("x", "pax_engine::api::Size"),
86    ("y", "pax_engine::api::Size"),
87    ("padding_x", "pax_engine::api::Size"),
88    ("padding_y", "pax_engine::api::Size"),
89    ("scale", "pax_engine::api::Size"),
90    ("scale_x", "pax_engine::api::Size"),
91    ("scale_y", "pax_engine::api::Size"),
92    ("skew", "pax_engine::api::Rotation"),
93    ("skew_x", "pax_engine::api::Rotation"),
94    ("skew_y", "pax_engine::api::Rotation"),
95    ("anchor", "pax_engine::api::Size"),
96    ("anchor_x", "pax_engine::api::Size"),
97    ("anchor_y", "pax_engine::api::Size"),
98    ("rotate", "pax_engine::api::Rotation"),
99    ("transform", "pax_engine::api::Transform2D"),
100    ("width", "pax_engine::api::Size"),
101    ("height", "pax_engine::api::Size"),
102    ("opacity", "pax_engine::api::Opacity"),
103    ("layout_role", "pax_engine::api::LayoutRole"),
104    ("_raycastable", "bool"),
105];