1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// ratatui-kit-macros:核心 UI 宏定义,简化终端 UI 组件开发。
//
// ## 主要宏说明
//
// - `#[derive(Props)]`:为组件属性自动生成 Props trait 实现。
// - `element!`:声明式 UI 宏,极大提升终端 UI 组件开发效率。
// - 语法风格类似 React JSX,但为 Rust 语法友好设计。
// - 支持嵌套、props、children、一等控制流渲染。
// - **一等控制流**:子节点块内可直接写 `if/else`、`if let`、`for`、`match`,分支体即子节点;
// 各分支独立 extend,可返回不同元素类型,无需 `.into_any()`。
// - `{ expr }` 可内嵌任意返回 Option/Vec/impl Iterator/Element 的 Rust 表达式。
// - `widget(expr)` / `stateful(widget, state)` 可兼容 ratatui 原生组件(逃生舱)。
// - 适用于声明式构建终端 UI 组件树。
//
// ## element! 宏语法
//
// 例如,声明式构建一个带一等控制流和 ratatui 原生组件的 UI:
//
// ```rust,ignore
// element!(Panel(title: "Demo") {
// if show_title {
// Title(text: "Hello")
// }
// for item in items {
// ListItem(label: item, key: item.id)
// }
// widget(Block::default().borders(Borders::ALL))
// })
// ```
//
// - 控制流分支体直接写子元素;动态/复杂表达式仍可用 `{ expr }`。
// - 通过 `widget(...)` / `stateful(...)` 可直接集成 ratatui 原生组件。
// - 语法风格类似 JSX,但为 Rust 语法友好设计。
// - 适用于声明式构建终端 UI 组件树。
use ElementOrAdapter;
use TokenStream;
use ParsedProps;
use ToTokens;
use DeriveInput;
use crateimpl_layout_style;
/// Derives Ratatui Kit's `Props` implementation for component props.
/// Builds a declarative Ratatui Kit element tree.
///
/// The syntax is JSX-like while staying Rust-friendly: nested components,
/// props, children, `key`, first-class `if`/`if let`/`for`/`match` child
/// control flow, and native Ratatui widget adapters are supported.
///
/// ```rust,ignore
/// element!(Panel(title: "Demo") {
/// if show_title {
/// Title(text: "Hello")
/// } else {
/// Title(text: "Hidden")
/// }
/// for item in items {
/// ListItem(label: item, key: item.id)
/// }
/// widget(Block::default().borders(Borders::ALL))
/// })
/// ```
/// Turns a function into a Ratatui Kit component.
///
/// The generated component owns the props type, preserves hook order, and
/// enables context-aware hooks for ordinary function components.
/// Builds a static route table for `RouterProvider`.
///
/// Routes are matched in declaration order. Put more specific static routes
/// before same-prefix dynamic routes when both could match the same path.
/// Adds layout style fields and helpers to a props struct.
///
/// Use this on named-field props structs for components that should accept
/// layout props such as width, height, margin, offset, gap, direction, and
/// justification.