pyreportkit 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. pyreportkit-0.1.0.dist-info/METADATA +187 -0
  2. pyreportkit-0.1.0.dist-info/RECORD +222 -0
  3. pyreportkit-0.1.0.dist-info/WHEEL +5 -0
  4. pyreportkit-0.1.0.dist-info/licenses/LICENSE +21 -0
  5. pyreportkit-0.1.0.dist-info/top_level.txt +1 -0
  6. reportkit/__init__.py +0 -0
  7. reportkit/components/__init__.py +45 -0
  8. reportkit/components/document/__init__.py +6 -0
  9. reportkit/components/document/footer.py +12 -0
  10. reportkit/components/document/header.py +12 -0
  11. reportkit/components/document/page.py +18 -0
  12. reportkit/components/document/report.py +12 -0
  13. reportkit/components/information/__init__.py +4 -0
  14. reportkit/components/information/info_grid.py +23 -0
  15. reportkit/components/information/key_value.py +28 -0
  16. reportkit/components/layout/__init__.py +9 -0
  17. reportkit/components/layout/box.py +10 -0
  18. reportkit/components/layout/column.py +15 -0
  19. reportkit/components/layout/divider.py +10 -0
  20. reportkit/components/layout/grid.py +12 -0
  21. reportkit/components/layout/row.py +15 -0
  22. reportkit/components/layout/section.py +10 -0
  23. reportkit/components/layout/spacer.py +12 -0
  24. reportkit/components/media/__init__.py +4 -0
  25. reportkit/components/media/chart.py +14 -0
  26. reportkit/components/media/image.py +25 -0
  27. reportkit/components/pagination/__init__.py +5 -0
  28. reportkit/components/pagination/page_break.py +10 -0
  29. reportkit/components/pagination/page_count.py +10 -0
  30. reportkit/components/pagination/page_number.py +21 -0
  31. reportkit/components/table/__init__.py +7 -0
  32. reportkit/components/table/cell.py +27 -0
  33. reportkit/components/table/column.py +29 -0
  34. reportkit/components/table/row.py +25 -0
  35. reportkit/components/table/style.py +18 -0
  36. reportkit/components/table/table.py +27 -0
  37. reportkit/components/typography/__init__.py +6 -0
  38. reportkit/components/typography/heading.py +13 -0
  39. reportkit/components/typography/rich_text.py +23 -0
  40. reportkit/components/typography/text.py +12 -0
  41. reportkit/components/typography/text_span.py +24 -0
  42. reportkit/core/__init__.py +4 -0
  43. reportkit/core/component.py +12 -0
  44. reportkit/core/container.py +66 -0
  45. reportkit/core/exceptions.py +0 -0
  46. reportkit/core/factory.py +53 -0
  47. reportkit/core/registry.py +50 -0
  48. reportkit/core/serializer.py +90 -0
  49. reportkit/exporters/__init__.py +0 -0
  50. reportkit/exporters/base.py +17 -0
  51. reportkit/exporters/excel/__init__.py +8 -0
  52. reportkit/exporters/excel/exceptions.py +4 -0
  53. reportkit/exporters/excel/exporter.py +68 -0
  54. reportkit/exporters/excel/renderers/__init__.py +34 -0
  55. reportkit/exporters/excel/renderers/base.py +27 -0
  56. reportkit/exporters/excel/renderers/information.py +55 -0
  57. reportkit/exporters/excel/renderers/layout/__init__.py +7 -0
  58. reportkit/exporters/excel/renderers/layout/columns.py +48 -0
  59. reportkit/exporters/excel/renderers/layout/data.py +46 -0
  60. reportkit/exporters/excel/renderers/layout/page.py +24 -0
  61. reportkit/exporters/excel/renderers/layout/spacing.py +30 -0
  62. reportkit/exporters/excel/renderers/layout/stack.py +13 -0
  63. reportkit/exporters/excel/renderers/media.py +46 -0
  64. reportkit/exporters/excel/renderers/registry.py +22 -0
  65. reportkit/exporters/excel/renderers/table/__init__.py +4 -0
  66. reportkit/exporters/excel/renderers/table/cells.py +17 -0
  67. reportkit/exporters/excel/renderers/table/data.py +38 -0
  68. reportkit/exporters/excel/renderers/table/renderer.py +64 -0
  69. reportkit/exporters/excel/renderers/table/widths.py +29 -0
  70. reportkit/exporters/excel/renderers/text.py +40 -0
  71. reportkit/exporters/excel/styles.py +130 -0
  72. reportkit/exporters/excel/values/__init__.py +5 -0
  73. reportkit/exporters/excel/values/cells.py +60 -0
  74. reportkit/exporters/excel/values/components.py +16 -0
  75. reportkit/exporters/excel/values/formats.py +31 -0
  76. reportkit/exporters/excel/values/numbers.py +19 -0
  77. reportkit/exporters/excel/workbook/__init__.py +5 -0
  78. reportkit/exporters/excel/workbook/data.py +48 -0
  79. reportkit/exporters/excel/workbook/formatted.py +63 -0
  80. reportkit/exporters/excel/workbook/styles.py +27 -0
  81. reportkit/exporters/excel/workbook/workbook.py +65 -0
  82. reportkit/exporters/excel/worksheet/__init__.py +5 -0
  83. reportkit/exporters/excel/worksheet/borders.py +30 -0
  84. reportkit/exporters/excel/worksheet/cells.py +38 -0
  85. reportkit/exporters/excel/worksheet/constants.py +12 -0
  86. reportkit/exporters/excel/worksheet/data.py +51 -0
  87. reportkit/exporters/excel/worksheet/formatted.py +158 -0
  88. reportkit/exporters/excel/worksheet/page.py +23 -0
  89. reportkit/exporters/html/__init__.py +6 -0
  90. reportkit/exporters/html/assets.py +87 -0
  91. reportkit/exporters/html/direction.py +15 -0
  92. reportkit/exporters/html/engine.py +37 -0
  93. reportkit/exporters/html/exporter.py +38 -0
  94. reportkit/exporters/html/page/__init__.py +3 -0
  95. reportkit/exporters/html/page/components.py +47 -0
  96. reportkit/exporters/html/page/margins.py +24 -0
  97. reportkit/exporters/html/page/numbering.py +31 -0
  98. reportkit/exporters/html/page/resolver.py +37 -0
  99. reportkit/exporters/html/page/running.py +30 -0
  100. reportkit/exporters/html/page/styles.py +22 -0
  101. reportkit/exporters/html/page/validator.py +76 -0
  102. reportkit/exporters/html/registry.py +45 -0
  103. reportkit/exporters/html/renderers/__init__.py +37 -0
  104. reportkit/exporters/html/renderers/base.py +20 -0
  105. reportkit/exporters/html/renderers/document/__init__.py +6 -0
  106. reportkit/exporters/html/renderers/document/footer.py +18 -0
  107. reportkit/exporters/html/renderers/document/header.py +18 -0
  108. reportkit/exporters/html/renderers/document/page.py +17 -0
  109. reportkit/exporters/html/renderers/document/report.py +16 -0
  110. reportkit/exporters/html/renderers/information/__init__.py +4 -0
  111. reportkit/exporters/html/renderers/information/info_grid.py +26 -0
  112. reportkit/exporters/html/renderers/information/key_value.py +18 -0
  113. reportkit/exporters/html/renderers/layout/__init__.py +9 -0
  114. reportkit/exporters/html/renderers/layout/box.py +17 -0
  115. reportkit/exporters/html/renderers/layout/column.py +41 -0
  116. reportkit/exporters/html/renderers/layout/divider.py +16 -0
  117. reportkit/exporters/html/renderers/layout/grid.py +48 -0
  118. reportkit/exporters/html/renderers/layout/row.py +35 -0
  119. reportkit/exporters/html/renderers/layout/section.py +17 -0
  120. reportkit/exporters/html/renderers/layout/spacer.py +18 -0
  121. reportkit/exporters/html/renderers/media/__init__.py +3 -0
  122. reportkit/exporters/html/renderers/media/image.py +18 -0
  123. reportkit/exporters/html/renderers/pagination/__init__.py +4 -0
  124. reportkit/exporters/html/renderers/pagination/page_break.py +15 -0
  125. reportkit/exporters/html/renderers/pagination/page_number.py +15 -0
  126. reportkit/exporters/html/renderers/table/__init__.py +4 -0
  127. reportkit/exporters/html/renderers/table/cell.py +77 -0
  128. reportkit/exporters/html/renderers/table/table.py +69 -0
  129. reportkit/exporters/html/renderers/typography/__init__.py +5 -0
  130. reportkit/exporters/html/renderers/typography/heading.py +18 -0
  131. reportkit/exporters/html/renderers/typography/rich_text.py +28 -0
  132. reportkit/exporters/html/renderers/typography/text.py +16 -0
  133. reportkit/exporters/html/static/base.css +45 -0
  134. reportkit/exporters/html/static/information.css +83 -0
  135. reportkit/exporters/html/static/layout.css +81 -0
  136. reportkit/exporters/html/static/media.css +10 -0
  137. reportkit/exporters/html/static/pdf.css +96 -0
  138. reportkit/exporters/html/static/print.css +91 -0
  139. reportkit/exporters/html/static/table.css +222 -0
  140. reportkit/exporters/html/static/tokens.css +68 -0
  141. reportkit/exporters/html/static/typography.css +54 -0
  142. reportkit/exporters/html/styles.py +167 -0
  143. reportkit/exporters/html/templates/components/document/footer.html +3 -0
  144. reportkit/exporters/html/templates/components/document/header.html +3 -0
  145. reportkit/exporters/html/templates/components/document/page.html +8 -0
  146. reportkit/exporters/html/templates/components/document/report.html +3 -0
  147. reportkit/exporters/html/templates/components/information/info_grid.html +6 -0
  148. reportkit/exporters/html/templates/components/information/key_value.html +9 -0
  149. reportkit/exporters/html/templates/components/layout/box.html +3 -0
  150. reportkit/exporters/html/templates/components/layout/column.html +3 -0
  151. reportkit/exporters/html/templates/components/layout/divider.html +1 -0
  152. reportkit/exporters/html/templates/components/layout/grid.html +3 -0
  153. reportkit/exporters/html/templates/components/layout/row.html +3 -0
  154. reportkit/exporters/html/templates/components/layout/section.html +3 -0
  155. reportkit/exporters/html/templates/components/layout/spacer.html +1 -0
  156. reportkit/exporters/html/templates/components/media/image.html +8 -0
  157. reportkit/exporters/html/templates/components/pagination/page_break.html +1 -0
  158. reportkit/exporters/html/templates/components/pagination/page_number.html +4 -0
  159. reportkit/exporters/html/templates/components/table/cell.html +7 -0
  160. reportkit/exporters/html/templates/components/table/table.html +34 -0
  161. reportkit/exporters/html/templates/components/typography/heading.html +1 -0
  162. reportkit/exporters/html/templates/components/typography/rich_text.html +5 -0
  163. reportkit/exporters/html/templates/components/typography/text.html +1 -0
  164. reportkit/exporters/html/templates/document.html +17 -0
  165. reportkit/exporters/html/templates.py +30 -0
  166. reportkit/exporters/json.py +0 -0
  167. reportkit/exporters/pdf/__init__.py +8 -0
  168. reportkit/exporters/pdf/conversion.py +104 -0
  169. reportkit/exporters/pdf/dependencies.py +12 -0
  170. reportkit/exporters/pdf/exceptions.py +4 -0
  171. reportkit/exporters/pdf/exporter.py +16 -0
  172. reportkit/exporters/pdf/resources/__init__.py +4 -0
  173. reportkit/exporters/pdf/resources/fetcher.py +37 -0
  174. reportkit/exporters/pdf/resources/policy.py +60 -0
  175. reportkit/exporters/registry.py +50 -0
  176. reportkit/exporters/word/__init__.py +8 -0
  177. reportkit/exporters/word/document/__init__.py +4 -0
  178. reportkit/exporters/word/document/document.py +74 -0
  179. reportkit/exporters/word/document/engine.py +71 -0
  180. reportkit/exporters/word/exceptions.py +4 -0
  181. reportkit/exporters/word/exporter.py +32 -0
  182. reportkit/exporters/word/renderers/__init__.py +24 -0
  183. reportkit/exporters/word/renderers/base.py +56 -0
  184. reportkit/exporters/word/renderers/information.py +30 -0
  185. reportkit/exporters/word/renderers/layout/__init__.py +6 -0
  186. reportkit/exporters/word/renderers/layout/columns.py +82 -0
  187. reportkit/exporters/word/renderers/layout/page.py +38 -0
  188. reportkit/exporters/word/renderers/layout/spacing.py +33 -0
  189. reportkit/exporters/word/renderers/layout/stack.py +50 -0
  190. reportkit/exporters/word/renderers/media.py +49 -0
  191. reportkit/exporters/word/renderers/registry.py +22 -0
  192. reportkit/exporters/word/renderers/table/__init__.py +3 -0
  193. reportkit/exporters/word/renderers/table/cells.py +39 -0
  194. reportkit/exporters/word/renderers/table/renderer.py +95 -0
  195. reportkit/exporters/word/renderers/table/widths.py +12 -0
  196. reportkit/exporters/word/renderers/text.py +40 -0
  197. reportkit/exporters/word/styles/__init__.py +3 -0
  198. reportkit/exporters/word/styles/text.py +90 -0
  199. reportkit/exporters/word/styles/xml.py +147 -0
  200. reportkit/exporters/word/values.py +36 -0
  201. reportkit/formatting/__init__.py +0 -0
  202. reportkit/formatting/cell.py +12 -0
  203. reportkit/formatting/cells.py +41 -0
  204. reportkit/formatting/values.py +106 -0
  205. reportkit/rendering/__init__.py +0 -0
  206. reportkit/rendering/context.py +31 -0
  207. reportkit/rendering/table.py +56 -0
  208. reportkit/rendering/tracks.py +51 -0
  209. reportkit/rendering/visitor.py +55 -0
  210. reportkit/report.py +0 -0
  211. reportkit/styles/__init__.py +0 -0
  212. reportkit/styles/borders.py +6 -0
  213. reportkit/styles/style.py +117 -0
  214. reportkit/styles/table.py +37 -0
  215. reportkit/styles/theme.py +45 -0
  216. reportkit/styles/tokens.py +29 -0
  217. reportkit/validators/__init__.py +3 -0
  218. reportkit/validators/table/__init__.py +3 -0
  219. reportkit/validators/table/cell.py +38 -0
  220. reportkit/validators/table/column.py +62 -0
  221. reportkit/validators/table/row.py +37 -0
  222. reportkit/validators/table/table.py +63 -0
@@ -0,0 +1,15 @@
1
+ from dataclasses import dataclass
2
+
3
+ from ...core.container import Container
4
+
5
+
6
+ @dataclass
7
+ class Column(Container):
8
+ """
9
+ Arrange child components vertically.
10
+ """
11
+
12
+ align: str | None = None
13
+ justify: str | None = None
14
+ gap: str | None = None
15
+ direction: str | None = None
@@ -0,0 +1,10 @@
1
+ from dataclasses import dataclass
2
+
3
+ from ...core.component import Component
4
+
5
+
6
+ @dataclass
7
+ class Divider(Component):
8
+ """
9
+ Represent a visual separator.
10
+ """
@@ -0,0 +1,12 @@
1
+ from dataclasses import dataclass
2
+
3
+ from ...core.container import Container
4
+
5
+
6
+ @dataclass
7
+ class Grid(Container):
8
+ """
9
+ Arrange child components in a configurable grid.
10
+ """
11
+
12
+ columns: int | str = 1
@@ -0,0 +1,15 @@
1
+ from dataclasses import dataclass
2
+
3
+ from ...core.container import Container
4
+
5
+
6
+ @dataclass
7
+ class Row(Container):
8
+ """
9
+ Arrange child components horizontally.
10
+ """
11
+
12
+ justify: str | None = None
13
+ align: str | None = None
14
+ gap: str | None = None
15
+ wrap: bool = False
@@ -0,0 +1,10 @@
1
+ from dataclasses import dataclass
2
+
3
+ from ...core.container import Container
4
+
5
+
6
+ @dataclass
7
+ class Section(Container):
8
+ """
9
+ Group related report components.
10
+ """
@@ -0,0 +1,12 @@
1
+ from dataclasses import dataclass
2
+
3
+ from ...core.component import Component
4
+
5
+
6
+ @dataclass
7
+ class Spacer(Component):
8
+ """
9
+ Represent empty space between components.
10
+ """
11
+
12
+ height: float = 0
@@ -0,0 +1,4 @@
1
+ from .chart import Chart
2
+ from .image import Image
3
+
4
+ __all__ = ["Chart", "Image"]
@@ -0,0 +1,14 @@
1
+ from dataclasses import dataclass
2
+ from typing import Any
3
+
4
+ from ...core.component import Component
5
+
6
+
7
+ @dataclass
8
+ class Chart(Component):
9
+ """
10
+ Represent a chart component.
11
+ """
12
+
13
+ data: Any = None
14
+ chart_type: str = "bar"
@@ -0,0 +1,25 @@
1
+ from dataclasses import dataclass
2
+
3
+ from ...core.component import Component
4
+
5
+
6
+ @dataclass(kw_only=True)
7
+ class Image(Component):
8
+ """
9
+ Represent an image in a report.
10
+ """
11
+
12
+ src: str
13
+ alt: str = ""
14
+ width: str | None = None
15
+ height: str | None = None
16
+ fit: str = "contain"
17
+
18
+ def __post_init__(self):
19
+ """
20
+ Validate image properties.
21
+ """
22
+ if not isinstance(self.src, str) or not self.src.strip():
23
+ raise ValueError("Image source must be a non-empty string.")
24
+ if self.fit not in {"contain", "cover", "fill", "none", "scale-down"}:
25
+ raise ValueError("Unsupported image fit.")
@@ -0,0 +1,5 @@
1
+ from .page_break import PageBreak
2
+ from .page_count import PageCount
3
+ from .page_number import PageNumber
4
+
5
+ __all__ = ["PageBreak", "PageCount", "PageNumber"]
@@ -0,0 +1,10 @@
1
+ from dataclasses import dataclass
2
+
3
+ from ...core.component import Component
4
+
5
+
6
+ @dataclass(kw_only=True)
7
+ class PageBreak(Component):
8
+ """
9
+ Insert a page break before the next content.
10
+ """
@@ -0,0 +1,10 @@
1
+ from dataclasses import dataclass
2
+
3
+ from ...core.component import Component
4
+
5
+
6
+ @dataclass
7
+ class PageCount(Component):
8
+ """
9
+ Represent the total number of pages.
10
+ """
@@ -0,0 +1,21 @@
1
+ from dataclasses import dataclass
2
+
3
+ from ...core.component import Component
4
+
5
+
6
+ @dataclass(kw_only=True)
7
+ class PageNumber(Component):
8
+ """
9
+ Represent a page numbering placeholder.
10
+ """
11
+
12
+ format: str = "Page {page} of {pages}"
13
+
14
+ def __post_init__(self):
15
+ """
16
+ Validate page number format.
17
+ """
18
+ if not isinstance(self.format, str):
19
+ raise TypeError("Page number format must be a string.")
20
+ if not self.format:
21
+ raise ValueError("Page number format cannot be empty.")
@@ -0,0 +1,7 @@
1
+ from .cell import TableCell
2
+ from .column import TableColumn
3
+ from .row import TableRow
4
+ from .style import TableStyle
5
+ from .table import Table
6
+
7
+ __all__ = ["Table", "TableCell", "TableColumn", "TableRow", "TableStyle"]
@@ -0,0 +1,27 @@
1
+ from dataclasses import dataclass, field
2
+ from typing import Any
3
+
4
+ from ...core.component import Component
5
+ from ...styles.style import Style
6
+ from ...validators.table.cell import TableCellValidator
7
+
8
+
9
+ @dataclass(frozen=True, kw_only=True)
10
+ class TableCell:
11
+ """
12
+ Define one prepared cell: a plain value or a stack of child components; align=None inherits the
13
+ column.
14
+ """
15
+
16
+ value: Any = None
17
+ children: list[Component] = field(default_factory=list)
18
+ align: str | None = None
19
+ colspan: int = 1
20
+ rowspan: int = 1
21
+ style: Style = field(default_factory=Style)
22
+
23
+ def __post_init__(self):
24
+ """
25
+ Validate the cell definition.
26
+ """
27
+ TableCellValidator.validate(self)
@@ -0,0 +1,29 @@
1
+ from dataclasses import dataclass
2
+
3
+ from ...validators.table.column import TableColumnValidator
4
+
5
+
6
+ @dataclass(frozen=True, kw_only=True)
7
+ class TableColumn:
8
+ """
9
+ Define a table column and its presentation options.
10
+ """
11
+
12
+ key: str
13
+ title: str
14
+ subtitle: str | None = None
15
+ width: str | None = None
16
+ align: str = "start"
17
+ header_align: str | None = None
18
+ vertical_align: str = "middle"
19
+ nowrap: bool = False
20
+ format: str | None = None
21
+ decimals: int = 2
22
+ currency: str | None = None
23
+ date_format: str | None = None
24
+
25
+ def __post_init__(self):
26
+ """
27
+ Validate the column definition.
28
+ """
29
+ TableColumnValidator.validate(self)
@@ -0,0 +1,25 @@
1
+ from collections.abc import Mapping
2
+ from dataclasses import dataclass, field
3
+ from typing import Any
4
+
5
+ from ...styles.style import Style
6
+ from ...validators.table.row import TableRowValidator
7
+ from .cell import TableCell
8
+
9
+
10
+ @dataclass(frozen=True, kw_only=True)
11
+ class TableRow:
12
+ """
13
+ Define one prepared row; values may hold plain values or TableCell instances.
14
+ """
15
+
16
+ values: Mapping[str, Any] = field(default_factory=dict)
17
+ kind: str = "data"
18
+ cells: list[TableCell] | None = None
19
+ style: Style = field(default_factory=Style)
20
+
21
+ def __post_init__(self):
22
+ """
23
+ Validate the row definition.
24
+ """
25
+ TableRowValidator.validate(self)
@@ -0,0 +1,18 @@
1
+ from dataclasses import dataclass
2
+
3
+
4
+ @dataclass(frozen=True, kw_only=True)
5
+ class TableStyle:
6
+ """
7
+ Define table presentation and print settings.
8
+ """
9
+
10
+ bordered: bool = True
11
+ striped: bool = False
12
+ hover: bool = False
13
+ compact: bool = False
14
+ ruled: bool = False
15
+ layout: str = "fixed"
16
+ show_header: bool = True
17
+ repeat_header: bool = True
18
+ avoid_row_break: bool = True
@@ -0,0 +1,27 @@
1
+ from collections.abc import Iterable
2
+ from dataclasses import dataclass, field
3
+
4
+ from ...core.component import Component
5
+ from ...validators.table.table import TableValidator
6
+ from .column import TableColumn
7
+ from .row import TableRow
8
+ from .style import TableStyle
9
+
10
+
11
+ @dataclass(kw_only=True)
12
+ class Table(Component):
13
+ """
14
+ Define a table with externally prepared rows; rows may be a lazy iterable.
15
+ """
16
+
17
+ columns: list[TableColumn] = field(default_factory=list)
18
+ rows: Iterable[TableRow] = field(default_factory=list)
19
+ header: str | None = None
20
+ footer: TableRow | None = None
21
+ table_style: TableStyle = field(default_factory=TableStyle)
22
+
23
+ def __post_init__(self):
24
+ """
25
+ Validate the table without consuming its rows.
26
+ """
27
+ TableValidator.validate(self)
@@ -0,0 +1,6 @@
1
+ from .heading import Heading
2
+ from .rich_text import RichText
3
+ from .text import Text
4
+ from .text_span import TextSpan
5
+
6
+ __all__ = ["Heading", "RichText", "Text", "TextSpan"]
@@ -0,0 +1,13 @@
1
+ from dataclasses import dataclass
2
+
3
+ from ...core.component import Component
4
+
5
+
6
+ @dataclass
7
+ class Heading(Component):
8
+ """
9
+ Represent a heading component.
10
+ """
11
+
12
+ value: str = ""
13
+ level: int = 1
@@ -0,0 +1,23 @@
1
+ from dataclasses import dataclass, field
2
+
3
+ from ...core.component import Component
4
+ from .text_span import TextSpan
5
+
6
+
7
+ @dataclass(kw_only=True)
8
+ class RichText(Component):
9
+ """
10
+ Represent text containing multiple styled fragments.
11
+ """
12
+
13
+ spans: list[TextSpan] = field(default_factory=list)
14
+ align: str = "start"
15
+
16
+ def __post_init__(self):
17
+ """
18
+ Validate rich text configuration.
19
+ """
20
+ if not all(isinstance(span, TextSpan) for span in self.spans):
21
+ raise TypeError("RichText spans must contain TextSpan instances.")
22
+ if self.align not in {"start", "center", "end", "left", "right"}:
23
+ raise ValueError("Unsupported text alignment.")
@@ -0,0 +1,12 @@
1
+ from dataclasses import dataclass
2
+
3
+ from ...core.component import Component
4
+
5
+
6
+ @dataclass
7
+ class Text(Component):
8
+ """
9
+ Represent a text component.
10
+ """
11
+
12
+ value: str = ""
@@ -0,0 +1,24 @@
1
+ from dataclasses import dataclass, field
2
+
3
+ from ...styles.style import Style
4
+
5
+
6
+ @dataclass(frozen=True, kw_only=True)
7
+ class TextSpan:
8
+ """
9
+ Represent one styled text fragment.
10
+ """
11
+
12
+ value: str
13
+ style: Style = field(default_factory=Style)
14
+ language: str | None = None
15
+ direction: str | None = None
16
+
17
+ def __post_init__(self):
18
+ """
19
+ Validate text fragment properties.
20
+ """
21
+ if not isinstance(self.value, str):
22
+ raise TypeError("TextSpan value must be a string.")
23
+ if self.direction not in {None, "ltr", "rtl", "auto"}:
24
+ raise ValueError("Unsupported text direction.")
@@ -0,0 +1,4 @@
1
+ from .component import Component
2
+ from .container import Container
3
+
4
+ __all__ = ["Component", "Container"]
@@ -0,0 +1,12 @@
1
+ from dataclasses import dataclass, field
2
+
3
+ from ..styles.style import Style
4
+
5
+
6
+ @dataclass(kw_only=True)
7
+ class Component:
8
+ """
9
+ Base class for all report components.
10
+ """
11
+
12
+ style: Style = field(default_factory=Style)
@@ -0,0 +1,66 @@
1
+ from dataclasses import dataclass, field
2
+
3
+ from .component import Component
4
+
5
+
6
+ @dataclass
7
+ class Container(Component):
8
+ """
9
+ Base component for managing nested report components.
10
+ """
11
+
12
+ children: list[Component] = field(default_factory=list)
13
+
14
+ def __post_init__(self):
15
+ """
16
+ Validate and initialize child components.
17
+ """
18
+ children = self.children
19
+ self.children = []
20
+ self.extend(children)
21
+
22
+ def add(self, component: Component):
23
+ """
24
+ Add a validated child component.
25
+ """
26
+ self._validate_child(component)
27
+ self.children.append(component)
28
+ return self
29
+
30
+ def extend(self, components: list[Component]):
31
+ """
32
+ Add multiple validated child components.
33
+ """
34
+ components = list(components)
35
+ for component in components:
36
+ self._validate_child(component)
37
+ self.children.extend(components)
38
+ return self
39
+
40
+ def _validate_child(self, component: Component):
41
+ """
42
+ Validate child type and prevent circular references.
43
+ """
44
+ if not isinstance(component, Component):
45
+ raise TypeError("Child must be a Component.")
46
+ if component is self:
47
+ raise ValueError("A container cannot contain itself.")
48
+ if isinstance(component, Container) and component._contains(self):
49
+ raise ValueError("Circular component references are not allowed.")
50
+
51
+ def _contains(self, target: Component):
52
+ """
53
+ Check whether a component exists in the descendant tree.
54
+ """
55
+ visited = set()
56
+ stack = list(self.children)
57
+ while stack:
58
+ component = stack.pop()
59
+ if component is target:
60
+ return True
61
+ if id(component) in visited:
62
+ continue
63
+ visited.add(id(component))
64
+ if isinstance(component, Container):
65
+ stack.extend(component.children)
66
+ return False
File without changes
@@ -0,0 +1,53 @@
1
+ from collections.abc import Mapping
2
+ from dataclasses import fields
3
+
4
+ from ..styles.style import Style
5
+ from .component import Component
6
+ from .container import Container
7
+ from .registry import ComponentRegistry
8
+
9
+
10
+ class ComponentFactory:
11
+ """
12
+ Create registered report components from dictionaries.
13
+ """
14
+
15
+ @classmethod
16
+ def create(cls, data: Mapping) -> Component:
17
+ """
18
+ Create a component from its definition.
19
+ """
20
+ if not isinstance(data, Mapping):
21
+ raise TypeError("Component definition must be a mapping.")
22
+
23
+ component_type = data.get("type")
24
+ if not isinstance(component_type, str) or not component_type:
25
+ raise ValueError("Component type must be a non-empty string.")
26
+
27
+ component_class = ComponentRegistry.get(component_type)
28
+ properties = {key: value for key, value in data.items() if key != "type"}
29
+ cls.validate_properties(component_class, properties)
30
+
31
+ if "style" in properties and not isinstance(properties["style"], Style):
32
+ properties["style"] = Style.from_dict(properties["style"])
33
+
34
+ if issubclass(component_class, Container):
35
+ children = properties.get("children", [])
36
+ if not isinstance(children, list):
37
+ raise TypeError("Component children must be a list.")
38
+ properties["children"] = [cls.create(child) for child in children]
39
+ elif "children" in properties:
40
+ raise ValueError(f"Component '{component_type}' does not support children.")
41
+
42
+ return component_class(**properties)
43
+
44
+ @staticmethod
45
+ def validate_properties(component_class: type[Component], properties: dict):
46
+ """
47
+ Validate component properties against its dataclass fields.
48
+ """
49
+ allowed = {field.name for field in fields(component_class)}
50
+ unknown = set(properties) - allowed
51
+
52
+ if unknown:
53
+ raise ValueError( f"Unknown properties for '{component_class.__name__}': {', '.join(sorted(unknown))}")
@@ -0,0 +1,50 @@
1
+ from ..core.component import Component
2
+
3
+
4
+ class ComponentRegistry:
5
+ """
6
+ Register and resolve report component types.
7
+ """
8
+
9
+ _components: dict[str, type[Component]] = {}
10
+
11
+ @classmethod
12
+ def register(cls, name: str, component: type[Component]):
13
+ """
14
+ Register a component type.
15
+ """
16
+ if not isinstance(name, str) or not name:
17
+ raise ValueError("Component name must be a non-empty string.")
18
+
19
+ if not isinstance(component, type) or not issubclass(component, Component):
20
+ raise TypeError("Registered component must inherit from Component.")
21
+
22
+ if name in cls._components:
23
+ raise ValueError(f"Component '{name}' is already registered.")
24
+
25
+ cls._components[name] = component
26
+ return component
27
+
28
+ @classmethod
29
+ def get(cls, name: str) -> type[Component]:
30
+ """
31
+ Resolve a registered component type.
32
+ """
33
+ try:
34
+ return cls._components[name]
35
+ except KeyError:
36
+ raise ValueError(f"Unknown component type: '{name}'.") from None
37
+
38
+ @classmethod
39
+ def unregister(cls, name: str):
40
+ """
41
+ Remove a registered component type.
42
+ """
43
+ cls._components.pop(name, None)
44
+
45
+ @classmethod
46
+ def all(cls) -> dict[str, type[Component]]:
47
+ """
48
+ Return all registered component types.
49
+ """
50
+ return cls._components.copy()