Skip to main content

euv_ui/component/markdown/
struct.rs

1use super::*;
2
3/// Resolved VS Code `Eva Light Bold` / `Eva Dark Bold` color palette for `EuvCodeBlock` and Markdown syntax chrome.
4#[derive(Clone, Copy, Data, Debug, Eq, PartialEq)]
5pub struct CodeThemePalette {
6    /// Theme name (`"Eva Light Bold"` or `"Eva Dark Bold"`).
7    pub(crate) theme_name: &'static str,
8    /// Editor surface background.
9    #[get(type(copy))]
10    pub(crate) background: Color,
11    /// Header / tab bar background.
12    #[get(type(copy))]
13    pub(crate) header_bg: Color,
14    /// Crisp container border color.
15    #[get(type(copy))]
16    pub(crate) border: Color,
17    /// Default code foreground.
18    #[get(type(copy))]
19    pub(crate) foreground: Color,
20    /// Line number gutter foreground.
21    #[get(type(copy))]
22    pub(crate) line_number: Color,
23    /// Highlighted line background.
24    #[get(type(copy))]
25    pub(crate) line_highlight: Color,
26    /// Comment token color.
27    #[get(type(copy))]
28    pub(crate) comment: Color,
29    /// Storage keyword / modifier token color.
30    #[get(type(copy))]
31    pub(crate) keyword: Color,
32    /// Control-flow keyword token color.
33    #[get(type(copy))]
34    pub(crate) control: Color,
35    /// Operator token color.
36    #[get(type(copy))]
37    pub(crate) operator: Color,
38    /// String literal token color.
39    #[get(type(copy))]
40    pub(crate) string: Color,
41    /// Numeric literal token color.
42    #[get(type(copy))]
43    pub(crate) number: Color,
44    /// Language constant / boolean token color.
45    #[get(type(copy))]
46    pub(crate) constant: Color,
47    /// Function / macro / attribute token color.
48    #[get(type(copy))]
49    pub(crate) function: Color,
50    /// User type / trait / struct token color.
51    #[get(type(copy))]
52    pub(crate) ty: Color,
53    /// Built-in primitive / numeric type token color.
54    #[get(type(copy))]
55    pub(crate) primitive: Color,
56    /// Property / heading token color.
57    #[get(type(copy))]
58    pub(crate) property: Color,
59    /// Punctuation token color.
60    #[get(type(copy))]
61    pub(crate) punctuation: Color,
62    /// Inline code chip background.
63    #[get(type(copy))]
64    pub(crate) inline_code_bg: Color,
65    /// Inline code chip foreground.
66    #[get(type(copy))]
67    pub(crate) inline_code_fg: Color,
68    /// Blockquote surface background.
69    #[get(type(copy))]
70    pub(crate) quote_bg: Color,
71    /// Blockquote left accent border.
72    #[get(type(copy))]
73    pub(crate) quote_border: Color,
74    /// Hyperlink foreground color.
75    #[get(type(copy))]
76    pub(crate) link: Color,
77    /// Diff insertion foreground color.
78    #[get(type(copy))]
79    pub(crate) diff_add: Color,
80    /// Diff deletion foreground color.
81    #[get(type(copy))]
82    pub(crate) diff_del: Color,
83}
84
85/// Single syntax-highlighted span within a source code line.
86#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
87pub struct CodeSpan {
88    /// Raw text slice of the token.
89    pub(crate) text: String,
90    /// Semantic token classification.
91    #[get(type(copy))]
92    pub(crate) kind: CodeTokenKind,
93}
94
95/// Single item inside an `EuvMarkdownList` supporting nesting, child Markdown blocks, and interactive GFM checkboxes.
96#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
97pub struct EuvMarkdownListItem {
98    /// Item text (may include inline Markdown syntax).
99    pub(crate) text: String,
100    /// Nesting indentation level (`0` = top level).
101    #[get(type(copy))]
102    pub(crate) depth: usize,
103    /// Optional GFM task checklist state (`Some(true)` checked, `Some(false)` unchecked, `None` normal item).
104    #[get(skip)]
105    pub(crate) checked: Option<bool>,
106    /// Optional recursively parsed child Markdown blocks (for example indented fenced code blocks or nested callouts).
107    #[new(skip)]
108    pub(crate) children: Vec<EuvMarkdownBlock>,
109}
110
111/// Single term and definition entry inside an `EuvMarkdownDefList`.
112#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
113pub struct EuvMarkdownDefItem {
114    /// Defined term header.
115    pub(crate) term: String,
116    /// One or more definition descriptions for the term.
117    pub(crate) definitions: Vec<String>,
118}
119
120/// Single parsed footnote definition rendered at the bottom of `EuvMarkdown`.
121#[derive(Clone, Data, Debug, Eq, New, PartialEq)]
122pub struct EuvMarkdownFootnote {
123    /// Footnote identifier (e.g. `"1"` or `"perf"`).
124    pub(crate) id: String,
125    /// Footnote Markdown description text.
126    pub(crate) content: String,
127}
128
129/// VS Code `Eva Light Bold` / `Eva Dark Bold` syntax-highlighted native code block with H+V scrolling, line numbers, fullscreen modal, selectable text, and animated copy action.
130#[derive(Clone, CustomDebug, Data, New, Props)]
131pub struct EuvCodeBlock {
132    /// Source code text to display and highlight.
133    pub(crate) code: String,
134    /// Active theme tokens controlling Light (`Eva Light Bold`) vs Dark (`Eva Dark Bold`) palette selection.
135    #[get(type(copy))]
136    pub(crate) tokens: ThemeTokens,
137    /// Optional language tag (e.g. `"rust"`, `"typescript"`, `"json"`, `"bash"`). Auto-detected when empty.
138    #[new(skip)]
139    #[prop(custom)]
140    pub(crate) language: String,
141    /// Optional filename displayed in the header bar (e.g. `"src/main.rs"`).
142    #[new(skip)]
143    #[get(skip)]
144    #[prop(custom)]
145    pub(crate) filename: Option<String>,
146    /// Whether to display the left line-number gutter (`true` by default for multi-line blocks or via builder).
147    #[new(skip)]
148    #[get(type(copy))]
149    pub(crate) show_line_numbers: bool,
150    /// Optional 1-based line numbers rendered with Eva line-highlight tint.
151    #[new(skip)]
152    #[prop(custom)]
153    pub(crate) highlight_lines: Vec<usize>,
154    /// Maximum inline viewport height in logical pixels used by `Fixed` and `AutoExpandWidth` modes (`0.0` defaults to `360.0`).
155    #[new(skip)]
156    #[get(type(copy))]
157    #[prop(custom)]
158    pub(crate) max_height: f32,
159    /// Inline width and height sizing mode (`EuvCodeBlockSizeMode::AutoExpand` by default).
160    #[new(skip)]
161    #[get(type(copy))]
162    #[prop(custom)]
163    pub(crate) size_mode: EuvCodeBlockSizeMode,
164    /// Optional text selection and copy mode for code lines (`None` defaults to `TextSelectMode::SelectAndCopy`).
165    #[new(skip)]
166    #[get(skip)]
167    #[prop(custom)]
168    pub(crate) text_select: Option<TextSelectMode>,
169    /// Optional callback invoked with the raw code when the user clicks Copy.
170    #[new(skip)]
171    #[debug(skip)]
172    #[get(skip)]
173    #[prop(custom)]
174    pub(crate) on_copy: Option<MarkdownStrCallback>,
175}
176
177/// Native Markdown heading component (`H1`–`H6`) with typographic scale and optional accent rule.
178#[derive(Clone, Data, Debug, New, Props)]
179pub struct EuvMarkdownHeading {
180    /// Heading level (`1..=6`).
181    #[get(type(copy))]
182    pub(crate) level: u8,
183    /// Heading text content.
184    pub(crate) text: String,
185    /// Active theme tokens.
186    #[get(type(copy))]
187    pub(crate) tokens: ThemeTokens,
188    /// Optional explicit text selection and copy mode (`None` inherits from ancestors, defaulting to `TextSelectMode::None`).
189    #[new(skip)]
190    #[get(skip)]
191    #[prop(custom)]
192    pub(crate) text_select: Option<TextSelectMode>,
193}
194
195/// Native Markdown inline code pill styled with exact VS Code Eva inline-code colors.
196#[derive(Clone, Data, Debug, New, Props)]
197pub struct EuvMarkdownInlineCode {
198    /// Inline code snippet.
199    pub(crate) code: String,
200    /// Active theme tokens.
201    #[get(type(copy))]
202    pub(crate) tokens: ThemeTokens,
203}
204
205/// Native Markdown display math block (`$$...$$`) with rich Unicode mathematical formatting.
206#[derive(Clone, Data, Debug, New, Props)]
207pub struct EuvMarkdownMath {
208    /// Raw LaTeX/math expression body.
209    pub(crate) expression: String,
210    /// Active theme tokens.
211    #[get(type(copy))]
212    pub(crate) tokens: ThemeTokens,
213    /// Optional explicit text selection and copy mode (`None` inherits from ancestors, defaulting to `TextSelectMode::None`).
214    #[new(skip)]
215    #[get(skip)]
216    #[prop(custom)]
217    pub(crate) text_select: Option<TextSelectMode>,
218}
219
220/// Native Markdown rich inline paragraph supporting bold, italic, bold-italic, strikethrough, highlight, sup/sub, inline code, math, footnotes, images, links, hard breaks, and `<kbd>` caps.
221#[derive(Clone, CustomDebug, Data, New, Props)]
222pub struct EuvMarkdownParagraph {
223    /// Parsed inline spans to flow cleanly inside the paragraph.
224    pub(crate) inlines: Vec<EuvMarkdownInline>,
225    /// Active theme tokens.
226    #[get(type(copy))]
227    pub(crate) tokens: ThemeTokens,
228    /// Optional explicit text selection and copy mode (`None` inherits from ancestors, defaulting to `TextSelectMode::None`).
229    #[new(skip)]
230    #[get(skip)]
231    #[prop(custom)]
232    pub(crate) text_select: Option<TextSelectMode>,
233    /// Optional relative asset base prefix used when resolving local image URLs (e.g. `"./"` or `"../"`).
234    #[new(skip)]
235    #[prop(custom)]
236    pub(crate) asset_base: String,
237    /// Optional callback invoked when a user taps a Markdown hyperlink.
238    #[new(skip)]
239    #[debug(skip)]
240    #[get(skip)]
241    #[prop(custom)]
242    pub(crate) on_link: Option<MarkdownStrCallback>,
243}
244
245/// Native Markdown blockquote and GitHub-flavored Alert callout (`NOTE`, `TIP`, `IMPORTANT`, `WARNING`, `CAUTION`).
246#[derive(Clone, CustomDebug, Data, New, Props)]
247pub struct EuvMarkdownQuote {
248    /// Semantic quote or alert variant.
249    #[get(type(copy))]
250    pub(crate) kind: EuvMarkdownAlertKind,
251    /// Text lines rendered inside the quote body.
252    pub(crate) lines: Vec<String>,
253    /// Active theme tokens.
254    #[get(type(copy))]
255    pub(crate) tokens: ThemeTokens,
256    /// Optional custom callout header title (for example from `::: warning Title`).
257    #[new(skip)]
258    #[get(skip)]
259    #[prop(custom)]
260    pub(crate) title: Option<String>,
261    /// Pre-parsed nested child Markdown blocks rendered inside the callout body.
262    #[new(skip)]
263    #[prop(custom)]
264    pub(crate) children: Vec<EuvMarkdownBlock>,
265    /// Inline sizing mode forwarded to nested `EuvCodeBlock` blocks inside the callout.
266    #[new(skip)]
267    #[get(type(copy))]
268    #[prop(custom)]
269    pub(crate) code_block_size_mode: EuvCodeBlockSizeMode,
270    /// Optional explicit text selection and copy mode (`None` inherits from ancestors, defaulting to `TextSelectMode::None`).
271    #[new(skip)]
272    #[get(skip)]
273    #[prop(custom)]
274    pub(crate) text_select: Option<TextSelectMode>,
275    /// Optional relative asset base prefix forwarded to inline images inside the callout.
276    #[new(skip)]
277    #[prop(custom)]
278    pub(crate) asset_base: String,
279    /// Optional link-click callback propagated to paragraphs inside the callout.
280    #[new(skip)]
281    #[debug(skip)]
282    #[get(skip)]
283    #[prop(custom)]
284    pub(crate) on_link: Option<MarkdownStrCallback>,
285    /// Optional copy callback propagated to nested `EuvCodeBlock` blocks inside the callout.
286    #[new(skip)]
287    #[debug(skip)]
288    #[get(skip)]
289    #[prop(custom)]
290    pub(crate) on_copy: Option<MarkdownStrCallback>,
291    /// Optional task-toggle callback propagated to nested checklists inside the callout.
292    #[new(skip)]
293    #[debug(skip)]
294    #[get(skip)]
295    #[prop(custom)]
296    pub(crate) on_toggle_task: Option<Rc<dyn Fn(usize, bool)>>,
297}
298
299/// Native Markdown unordered, ordered, nested, and interactive GFM task-checklist component.
300#[derive(Clone, CustomDebug, Data, New, Props)]
301pub struct EuvMarkdownList {
302    /// Whether list items render with ordinal numbering (`1.`, `2.`, ...).
303    #[get(type(copy))]
304    pub(crate) ordered: bool,
305    /// List items to render.
306    pub(crate) items: Vec<EuvMarkdownListItem>,
307    /// Active theme tokens.
308    #[get(type(copy))]
309    pub(crate) tokens: ThemeTokens,
310    /// Starting ordinal index for ordered lists (`0` defaults to `1`).
311    #[new(skip)]
312    #[get(type(copy))]
313    #[prop(custom)]
314    pub(crate) start: usize,
315    /// Inline sizing mode forwarded to nested `EuvCodeBlock` blocks inside list items.
316    #[new(skip)]
317    #[get(type(copy))]
318    #[prop(custom)]
319    pub(crate) code_block_size_mode: EuvCodeBlockSizeMode,
320    /// Optional explicit text selection and copy mode (`None` inherits from ancestors, defaulting to `TextSelectMode::None`).
321    #[new(skip)]
322    #[get(skip)]
323    #[prop(custom)]
324    pub(crate) text_select: Option<TextSelectMode>,
325    /// Optional relative asset base prefix forwarded to inline images inside list items.
326    #[new(skip)]
327    #[prop(custom)]
328    pub(crate) asset_base: String,
329    /// Optional link-click handler for hyperlinks inside list items.
330    #[new(skip)]
331    #[debug(skip)]
332    #[get(skip)]
333    #[prop(custom)]
334    pub(crate) on_link: Option<MarkdownStrCallback>,
335    /// Optional copy callback propagated to nested `EuvCodeBlock` blocks inside list items.
336    #[new(skip)]
337    #[debug(skip)]
338    #[get(skip)]
339    #[prop(custom)]
340    pub(crate) on_copy: Option<MarkdownStrCallback>,
341    /// Optional callback invoked with `(item_index, next_checked)` when toggling a task item.
342    #[new(skip)]
343    #[debug(skip)]
344    #[get(skip)]
345    #[prop(custom)]
346    pub(crate) on_toggle_task: Option<Rc<dyn Fn(usize, bool)>>,
347}
348
349/// Native GFM Markdown table with column alignment (`Left`, `Center`, `Right`), horizontal scroll on narrow viewports, tinted header, and zebra striping.
350#[derive(Clone, CustomDebug, Data, New, Props)]
351pub struct EuvMarkdownTable {
352    /// Column header titles.
353    pub(crate) headers: Vec<String>,
354    /// Column horizontal alignments.
355    pub(crate) alignments: Vec<EuvMarkdownAlign>,
356    /// Data rows.
357    pub(crate) rows: Vec<Vec<String>>,
358    /// Active theme tokens.
359    #[get(type(copy))]
360    pub(crate) tokens: ThemeTokens,
361    /// Optional explicit text selection and copy mode (`None` inherits from ancestors, defaulting to `TextSelectMode::None`).
362    #[new(skip)]
363    #[get(skip)]
364    #[prop(custom)]
365    pub(crate) text_select: Option<TextSelectMode>,
366    /// Optional relative asset base prefix forwarded to inline images inside table cells.
367    #[new(skip)]
368    #[prop(custom)]
369    pub(crate) asset_base: String,
370    /// Optional link-click handler for links inside table cells.
371    #[new(skip)]
372    #[debug(skip)]
373    #[get(skip)]
374    #[prop(custom)]
375    pub(crate) on_link: Option<MarkdownStrCallback>,
376}
377
378/// Native Markdown definition list rendering bold terms and indented descriptions.
379#[derive(Clone, CustomDebug, Data, New, Props)]
380pub struct EuvMarkdownDefList {
381    /// Term and definition entries.
382    pub(crate) items: Vec<EuvMarkdownDefItem>,
383    /// Active theme tokens.
384    #[get(type(copy))]
385    pub(crate) tokens: ThemeTokens,
386    /// Optional explicit text selection and copy mode (`None` inherits from ancestors, defaulting to `TextSelectMode::None`).
387    #[new(skip)]
388    #[get(skip)]
389    #[prop(custom)]
390    pub(crate) text_select: Option<TextSelectMode>,
391    /// Optional relative asset base prefix forwarded to inline images inside definitions.
392    #[new(skip)]
393    #[prop(custom)]
394    pub(crate) asset_base: String,
395    /// Optional link-click handler for links inside definitions.
396    #[new(skip)]
397    #[debug(skip)]
398    #[get(skip)]
399    #[prop(custom)]
400    pub(crate) on_link: Option<MarkdownStrCallback>,
401}
402
403/// Native Markdown footnotes footer section rendering numbered `[^id]` entries.
404#[derive(Clone, CustomDebug, Data, New, Props)]
405pub struct EuvMarkdownFootnotes {
406    /// Ordered footnote entries.
407    pub(crate) footnotes: Vec<EuvMarkdownFootnote>,
408    /// Active theme tokens.
409    #[get(type(copy))]
410    pub(crate) tokens: ThemeTokens,
411    /// Optional explicit text selection and copy mode (`None` inherits from ancestors, defaulting to `TextSelectMode::None`).
412    #[new(skip)]
413    #[get(skip)]
414    #[prop(custom)]
415    pub(crate) text_select: Option<TextSelectMode>,
416    /// Optional relative asset base prefix forwarded to inline images inside footnotes.
417    #[new(skip)]
418    #[prop(custom)]
419    pub(crate) asset_base: String,
420    /// Optional link-click handler for links inside footnotes.
421    #[new(skip)]
422    #[debug(skip)]
423    #[get(skip)]
424    #[prop(custom)]
425    pub(crate) on_link: Option<MarkdownStrCallback>,
426}
427
428/// Native Markdown thematic horizontal divider (`---`).
429#[derive(Clone, Copy, Data, Debug, New, Props)]
430pub struct EuvMarkdownDivider {
431    /// Active theme tokens.
432    #[get(type(copy))]
433    pub(crate) tokens: ThemeTokens,
434}
435
436/// Native Markdown image figure loading and rendering real decoded RGBA8 pixels with optional alt caption.
437#[derive(Clone, Data, Debug, New, Props)]
438pub struct EuvMarkdownImage {
439    /// Accessible alt / caption text.
440    pub(crate) alt: String,
441    /// Image URL or local asset path.
442    pub(crate) url: String,
443    /// Active theme tokens.
444    #[get(type(copy))]
445    pub(crate) tokens: ThemeTokens,
446    /// Optional relative asset base prefix used when resolving local image URLs (e.g. `"./"` or `"../"`).
447    #[new(skip)]
448    #[prop(custom)]
449    pub(crate) asset_base: String,
450}
451
452/// Native Markdown collapsible `<details><summary>` disclosure block supporting rich nested Markdown content.
453#[derive(Clone, CustomDebug, Data, New, Props)]
454pub struct EuvMarkdownDetails {
455    /// Always-visible disclosure header.
456    pub(crate) summary: String,
457    /// Collapsible content lines.
458    pub(crate) body: Vec<String>,
459    /// Reactive expanded state signal.
460    #[get(type(copy))]
461    pub(crate) open: Signal<bool>,
462    /// Active theme tokens.
463    #[get(type(copy))]
464    pub(crate) tokens: ThemeTokens,
465    /// Optional explicit text selection and copy mode (`None` inherits from ancestors, defaulting to `TextSelectMode::None`).
466    #[new(skip)]
467    #[get(skip)]
468    #[prop(custom)]
469    pub(crate) text_select: Option<TextSelectMode>,
470    /// Optional relative asset base prefix forwarded to nested Markdown blocks.
471    #[new(skip)]
472    #[prop(custom)]
473    pub(crate) asset_base: String,
474    /// Default inline sizing mode forwarded to fenced `EuvCodeBlock` blocks inside expanded details (`EuvCodeBlockSizeMode::AutoExpand` by default).
475    #[new(skip)]
476    #[get(type(copy))]
477    #[prop(custom)]
478    pub(crate) code_block_size_mode: EuvCodeBlockSizeMode,
479    /// Optional link-click handler inside expanded details.
480    #[new(skip)]
481    #[debug(skip)]
482    #[get(skip)]
483    #[prop(custom)]
484    pub(crate) on_link: Option<MarkdownStrCallback>,
485    /// Optional code copy handler inside expanded details.
486    #[new(skip)]
487    #[debug(skip)]
488    #[get(skip)]
489    #[prop(custom)]
490    pub(crate) on_copy: Option<MarkdownStrCallback>,
491    /// Optional task toggle handler inside expanded details.
492    #[new(skip)]
493    #[debug(skip)]
494    #[get(skip)]
495    #[prop(custom)]
496    pub(crate) on_toggle_task: Option<Rc<dyn Fn(usize, bool)>>,
497}
498
499/// Complete GitHub-Flavored & Extended Markdown native document renderer composing every Markdown component, native vector `EuvMermaid`, and Eva-themed `EuvCodeBlock`.
500#[derive(Clone, CustomDebug, Data, New, Props)]
501pub struct EuvMarkdown {
502    /// Raw Markdown source text.
503    pub(crate) source: String,
504    /// Active theme tokens.
505    #[get(type(copy))]
506    pub(crate) tokens: ThemeTokens,
507    /// Optional unified container/text style override (supports `text_select` via `style! { text_select: ... }`).
508    #[new(skip)]
509    #[get(skip)]
510    #[prop(custom)]
511    pub(crate) style: Option<Style>,
512    /// Optional explicit text selection and copy mode (`None` inherits from `style` or ancestors, defaulting to `TextSelectMode::None`).
513    #[new(skip)]
514    #[get(skip)]
515    #[prop(custom)]
516    pub(crate) text_select: Option<TextSelectMode>,
517    /// Optional relative asset base prefix used when resolving local Markdown image URLs (e.g. `"./"` or `"../"`).
518    #[new(skip)]
519    #[prop(custom)]
520    pub(crate) asset_base: String,
521    /// Default inline sizing mode forwarded to fenced `EuvCodeBlock` blocks (`EuvCodeBlockSizeMode::AutoExpand` by default).
522    #[new(skip)]
523    #[get(type(copy))]
524    #[prop(custom)]
525    pub(crate) code_block_size_mode: EuvCodeBlockSizeMode,
526    /// Optional link-click handler receiving the destination URL.
527    #[new(skip)]
528    #[debug(skip)]
529    #[get(skip)]
530    #[prop(custom)]
531    pub(crate) on_link: Option<MarkdownStrCallback>,
532    /// Optional code-block copy handler receiving the copied code.
533    #[new(skip)]
534    #[debug(skip)]
535    #[get(skip)]
536    #[prop(custom)]
537    pub(crate) on_copy: Option<MarkdownStrCallback>,
538    /// Optional interactive task-checkbox toggle handler receiving `(index, checked)`.
539    #[new(skip)]
540    #[debug(skip)]
541    #[get(skip)]
542    #[prop(custom)]
543    pub(crate) on_toggle_task: Option<Rc<dyn Fn(usize, bool)>>,
544}