1use std::collections::HashMap;
4
5#[derive(Debug, Clone)]
7pub struct OrbitAst {
8 pub template: TemplateNode,
9 pub style: StyleNode,
10 pub script: ScriptNode,
11}
12
13#[derive(Debug, Clone)]
15pub enum TemplateNode {
16 Element {
17 tag: String,
18 attributes: HashMap<String, AttributeValue>,
19 events: HashMap<String, String>,
20 children: Vec<TemplateNode>,
21 },
22 Expression(String),
23 Text(String),
24}
25
26#[derive(Debug, Clone)]
28pub enum AttributeValue {
29 Static(String),
30 Dynamic(String), }
32
33#[derive(Debug, Clone)]
35pub struct StyleNode {
36 pub rules: Vec<StyleRule>,
37 pub scoped: bool,
38}
39
40#[derive(Debug, Clone)]
42pub struct StyleRule {
43 pub selector: String,
44 pub declarations: HashMap<String, String>,
45}
46
47#[derive(Debug, Clone)]
49pub struct ScriptNode {
50 pub imports: Vec<String>,
51 pub component_name: String,
52 pub props: Vec<PropDefinition>,
53 pub state: Vec<StateDefinition>,
54 pub methods: Vec<MethodDefinition>,
55 pub lifecycle: Vec<LifecycleHook>,
56}
57
58#[derive(Debug, Clone)]
60pub struct PropDefinition {
61 pub name: String,
62 pub ty: String,
63 pub required: bool,
64 pub default: Option<String>,
65}
66
67#[derive(Debug, Clone)]
69pub struct StateDefinition {
70 pub name: String,
71 pub ty: String,
72 pub initial: Option<String>,
73}
74
75#[derive(Debug, Clone)]
77pub struct MethodDefinition {
78 pub name: String,
79 pub args: Vec<(String, String)>, pub return_type: Option<String>,
81 pub body: String,
82}
83
84#[derive(Debug, Clone)]
86pub struct LifecycleHook {
87 pub hook_type: LifecycleType,
88 pub body: String,
89}
90
91#[derive(Debug, Clone, PartialEq)]
93pub enum LifecycleType {
94 Created,
95 Mounted,
96 Updated,
97 Destroyed,
98}
99
100impl OrbitAst {
101 pub fn new(template: TemplateNode, style: StyleNode, script: ScriptNode) -> Self {
103 Self {
104 template,
105 style,
106 script,
107 }
108 }
109}