Skip to main content

omni_dev/drive/slides/
types.rs

1//! Tolerant models for the Slides object graph. Unknown fields are ignored.
2use serde::{Deserialize, Serialize};
3
4/// The complete presentation snapshot, including templates and notes.
5#[derive(Debug, Clone, Default, Deserialize, Serialize)]
6#[serde(default, rename_all = "camelCase")]
7pub struct Presentation {
8    /// Drive/Slides presentation identity.
9    pub presentation_id: String,
10    /// Presentation title.
11    pub title: Option<String>,
12    /// Opaque editor-only revision token.
13    pub revision_id: Option<String>,
14    /// Page dimensions in the API's units.
15    pub page_size: Option<serde_json::Value>,
16    /// Ordinary slides, in display order.
17    pub slides: Vec<Page>,
18    /// Layout templates, excluded from replacement.
19    pub layouts: Vec<Page>,
20    /// Master templates, excluded from replacement.
21    pub masters: Vec<Page>,
22}
23
24/// A page with object-addressed elements.
25#[derive(Debug, Clone, Default, Deserialize, Serialize)]
26#[serde(default, rename_all = "camelCase")]
27pub struct Page {
28    /// Stable page identity.
29    pub object_id: String,
30    /// API page type.
31    pub page_type: Option<String>,
32    /// Direct elements on this page.
33    pub page_elements: Vec<PageElement>,
34    /// Notes belonging to an ordinary slide.
35    pub slide_properties: Option<SlideProperties>,
36}
37
38/// Slide-specific relationships.
39#[derive(Debug, Clone, Default, Deserialize, Serialize)]
40#[serde(default, rename_all = "camelCase")]
41pub struct SlideProperties {
42    /// The separately addressed notes page.
43    pub notes_page: Option<Box<Page>>,
44}
45
46/// A page element; future kinds deserialize as an unknown element.
47#[derive(Debug, Clone, Default, Deserialize, Serialize)]
48#[serde(default, rename_all = "camelCase")]
49pub struct PageElement {
50    /// Stable element identity.
51    pub object_id: String,
52    /// Shape text, when this is a shape.
53    pub shape: Option<Shape>,
54    /// Cells, when this is a table.
55    pub table: Option<Table>,
56    /// Presence identifies an image without exposing its content URL.
57    pub image: Option<serde_json::Value>,
58    /// Recursively grouped elements.
59    pub element_group: Option<ElementGroup>,
60}
61
62/// Child elements of a group.
63#[derive(Debug, Clone, Default, Deserialize, Serialize)]
64#[serde(default)]
65pub struct ElementGroup {
66    /// Direct children.
67    pub children: Vec<PageElement>,
68}
69
70/// A shape's text.
71#[derive(Debug, Clone, Default, Deserialize, Serialize)]
72#[serde(default)]
73pub struct Shape {
74    /// All text runs in this shape.
75    pub text: Option<Text>,
76}
77
78/// Text runs are joined within one text object, never across objects.
79#[derive(Debug, Clone, Default, Deserialize, Serialize)]
80#[serde(default, rename_all = "camelCase")]
81pub struct Text {
82    /// Runs and paragraph markers in API order.
83    pub text_elements: Vec<TextElement>,
84}
85impl Text {
86    /// The textual content, preserving split-run continuity.
87    pub fn content(&self) -> String {
88        self.text_elements
89            .iter()
90            .filter_map(|e| e.text_run.as_ref())
91            .map(|r| r.content.as_str())
92            .collect()
93    }
94}
95
96/// A text run or a non-text marker.
97#[derive(Debug, Clone, Default, Deserialize, Serialize)]
98#[serde(default, rename_all = "camelCase")]
99pub struct TextElement {
100    /// Actual text; absent on paragraph markers and auto-text.
101    pub text_run: Option<TextRun>,
102}
103
104/// Content of one text run.
105#[derive(Debug, Clone, Default, Deserialize, Serialize)]
106#[serde(default)]
107pub struct TextRun {
108    /// Unicode text, including its trailing newline when present.
109    pub content: String,
110}
111
112/// A table's rows.
113#[derive(Debug, Clone, Default, Deserialize, Serialize)]
114#[serde(default, rename_all = "camelCase")]
115pub struct Table {
116    /// Rows in API order.
117    pub table_rows: Vec<TableRow>,
118}
119
120/// One table row.
121#[derive(Debug, Clone, Default, Deserialize, Serialize)]
122#[serde(default, rename_all = "camelCase")]
123pub struct TableRow {
124    /// Cells in API order, including merged cells.
125    pub table_cells: Vec<TableCell>,
126}
127
128/// A table cell with its true grid location (important for merged cells).
129#[derive(Debug, Clone, Default, Deserialize, Serialize)]
130#[serde(default, rename_all = "camelCase")]
131pub struct TableCell {
132    /// Cell text.
133    pub text: Option<Text>,
134    /// Explicit grid coordinates; fallback to array position when omitted.
135    pub location: Option<CellLocation>,
136}
137
138/// Zero-based grid coordinates.
139#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq, Eq)]
140#[serde(default, rename_all = "camelCase")]
141pub struct CellLocation {
142    /// Row number.
143    pub row_index: usize,
144    /// Column number.
145    pub column_index: usize,
146}