idconvert/backend/export/models.py

149 lines
3.0 KiB
Python

from __future__ import annotations
from dataclasses import dataclass, field
from typing import Any, Dict, List, Optional, Union
@dataclass
class IDExportRun:
text: str
style: Optional[str]
bold: bool
italic: bool
color_hex: Optional[str]
font: Optional[str]
size_pt: Optional[float]
@dataclass
class IDExportParagraph:
style: str
text: str
runs: List[IDExportRun] = field(default_factory=list)
@dataclass
class IDExportTextFrame:
id: str
thread_id: str
thread_position: int
x_pt: float
y_pt: float
width_pt: float
height_pt: float
column_count: int
paragraphs: List[IDExportParagraph] = field(default_factory=list)
type: str = 'text_frame'
@dataclass
class IDExportImageFrame:
id: str
x_pt: float
y_pt: float
width_pt: float
height_pt: float
image_name: str
image_data_b64: Optional[str]
fit_mode: str
type: str = 'image_frame'
@dataclass
class IDExportShape:
id: str
x_pt: float
y_pt: float
width_pt: float
height_pt: float
shape_type: str # 'rect' | 'ellipse' | 'line'
fill_hex: Optional[str]
stroke_hex: Optional[str]
stroke_weight_pt: float
type: str = 'shape'
@dataclass
class IDExportTableCell:
text: str
style: Optional[str]
col_span: int
row_span: int
background_hex: Optional[str]
text_color_hex: Optional[str]
@dataclass
class IDExportTableRow:
is_header: bool
cells: List[IDExportTableCell] = field(default_factory=list)
@dataclass
class IDExportTable:
id: str
x_pt: float
y_pt: float
width_pt: float
column_widths_pt: List[float]
rows: List[IDExportTableRow] = field(default_factory=list)
type: str = 'table'
@dataclass
class IDExportPageNumber:
id: str
x_pt: float
y_pt: float
font: Optional[str]
size_pt: float
color_hex: str
alignment: str
type: str = 'page_number'
@dataclass
class IDExportParagraphStyle:
name: str
font: Optional[str] = None
size_pt: Optional[float] = None
leading_pt: Optional[float] = None
space_before_pt: float = 0.0
space_after_pt: float = 0.0
alignment: str = 'left'
color_hex: Optional[str] = None
bold: bool = False
italic: bool = False
@dataclass
class IDExportCharacterStyle:
name: str
font: Optional[str] = None
bold: bool = False
italic: bool = False
color_hex: Optional[str] = None
@dataclass
class IDExportPage:
page_number: Union[int, str]
width_pt: float
height_pt: float
items: List[Any] = field(default_factory=list)
@dataclass
class IDExportDocument:
name: str
page_width_pt: float
page_height_pt: float
page_count: int
facing_pages: bool
paragraph_styles: List[IDExportParagraphStyle]
character_styles: List[IDExportCharacterStyle]
colors: Dict[str, str]
fonts_used: List[Dict[str, str]]
pages: List[IDExportPage]
page_number_style: Optional[IDExportPageNumber] = None