deckkit 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 (144) hide show
  1. deckkit/__init__.py +12 -0
  2. deckkit/_bundled_fonts.py +54 -0
  3. deckkit/_diagnostics.py +48 -0
  4. deckkit/_font_assets/SOURCES.txt +9 -0
  5. deckkit/_font_assets/SourceCodePro-Bold.ttf +0 -0
  6. deckkit/_font_assets/SourceCodePro-BoldIt.ttf +0 -0
  7. deckkit/_font_assets/SourceCodePro-It.ttf +0 -0
  8. deckkit/_font_assets/SourceCodePro-LICENSE.txt +93 -0
  9. deckkit/_font_assets/SourceCodePro-Regular.ttf +0 -0
  10. deckkit/_font_assets/SourceSans3-Bold.ttf +0 -0
  11. deckkit/_font_assets/SourceSans3-BoldIt.ttf +0 -0
  12. deckkit/_font_assets/SourceSans3-It.ttf +0 -0
  13. deckkit/_font_assets/SourceSans3-LICENSE.txt +93 -0
  14. deckkit/_font_assets/SourceSans3-Regular.ttf +0 -0
  15. deckkit/_variable_evaluation.py +82 -0
  16. deckkit/animation.py +211 -0
  17. deckkit/annotations.py +161 -0
  18. deckkit/backends/__init__.py +1 -0
  19. deckkit/backends/_font_embedding.py +41 -0
  20. deckkit/backends/_pptx_fonts.py +230 -0
  21. deckkit/backends/_pptx_shadows.py +241 -0
  22. deckkit/backends/_pptx_tables.py +251 -0
  23. deckkit/backends/pptx.py +1225 -0
  24. deckkit/backends/pptx_animation.py +175 -0
  25. deckkit/backends/svg.py +527 -0
  26. deckkit/canvas/__init__.py +40 -0
  27. deckkit/canvas/_geometry.py +49 -0
  28. deckkit/canvas/clipping.py +336 -0
  29. deckkit/canvas/context.py +34 -0
  30. deckkit/canvas/elements.py +306 -0
  31. deckkit/canvas/path.py +250 -0
  32. deckkit/canvas/scene.py +74 -0
  33. deckkit/canvas/style.py +31 -0
  34. deckkit/charts/__init__.py +59 -0
  35. deckkit/charts/axes.py +249 -0
  36. deckkit/charts/chart.py +244 -0
  37. deckkit/charts/content.py +132 -0
  38. deckkit/charts/context.py +45 -0
  39. deckkit/charts/interval.py +166 -0
  40. deckkit/charts/legends.py +82 -0
  41. deckkit/charts/marks.py +410 -0
  42. deckkit/charts/scales.py +205 -0
  43. deckkit/citations.py +200 -0
  44. deckkit/compiler.py +410 -0
  45. deckkit/context.py +72 -0
  46. deckkit/deck.py +168 -0
  47. deckkit/drawables/__init__.py +42 -0
  48. deckkit/drawables/bounds.py +17 -0
  49. deckkit/drawables/connector.py +22 -0
  50. deckkit/drawables/drawable.py +38 -0
  51. deckkit/drawables/ellipse.py +21 -0
  52. deckkit/drawables/group.py +10 -0
  53. deckkit/drawables/image.py +14 -0
  54. deckkit/drawables/line.py +18 -0
  55. deckkit/drawables/path.py +78 -0
  56. deckkit/drawables/rectangle.py +24 -0
  57. deckkit/drawables/rich_text.py +176 -0
  58. deckkit/drawables/table.py +42 -0
  59. deckkit/drawables/text.py +29 -0
  60. deckkit/effects.py +84 -0
  61. deckkit/expanded_views.py +561 -0
  62. deckkit/fonts.py +329 -0
  63. deckkit/geometry.py +48 -0
  64. deckkit/identity.py +72 -0
  65. deckkit/layout.py +398 -0
  66. deckkit/layouts/__init__.py +20 -0
  67. deckkit/layouts/_content.py +27 -0
  68. deckkit/layouts/annotations.py +217 -0
  69. deckkit/layouts/containers.py +202 -0
  70. deckkit/layouts/grid.py +299 -0
  71. deckkit/layouts/modifiers.py +200 -0
  72. deckkit/layouts/primitives.py +213 -0
  73. deckkit/layouts/table.py +139 -0
  74. deckkit/measurement.py +420 -0
  75. deckkit/paint.py +73 -0
  76. deckkit/py.typed +0 -0
  77. deckkit/reconcile.py +119 -0
  78. deckkit/semantic.py +47 -0
  79. deckkit/theme.py +364 -0
  80. deckkit/themes/__init__.py +91 -0
  81. deckkit/themes/clarity.py +98 -0
  82. deckkit/tokens.py +226 -0
  83. deckkit/units.py +73 -0
  84. deckkit/variables.py +212 -0
  85. deckkit/view_expansion.py +185 -0
  86. deckkit/views/__init__.py +100 -0
  87. deckkit/views/_code_source.py +42 -0
  88. deckkit/views/_drawing.py +52 -0
  89. deckkit/views/canvas.py +27 -0
  90. deckkit/views/code.py +481 -0
  91. deckkit/views/code_evolution.py +284 -0
  92. deckkit/views/composite_view.py +19 -0
  93. deckkit/views/divider.py +38 -0
  94. deckkit/views/ellipse.py +38 -0
  95. deckkit/views/grid.py +156 -0
  96. deckkit/views/hstack.py +43 -0
  97. deckkit/views/image.py +43 -0
  98. deckkit/views/layout_view.py +30 -0
  99. deckkit/views/line.py +31 -0
  100. deckkit/views/modifier_views.py +281 -0
  101. deckkit/views/path.py +36 -0
  102. deckkit/views/primitive_view.py +16 -0
  103. deckkit/views/pygments_highlighter.py +67 -0
  104. deckkit/views/rectangle.py +61 -0
  105. deckkit/views/section_number.py +21 -0
  106. deckkit/views/semantic/__init__.py +51 -0
  107. deckkit/views/semantic/before_after.py +109 -0
  108. deckkit/views/semantic/bullet_graph.py +216 -0
  109. deckkit/views/semantic/card.py +129 -0
  110. deckkit/views/semantic/code_block.py +41 -0
  111. deckkit/views/semantic/diff.py +642 -0
  112. deckkit/views/semantic/estimate_interval.py +137 -0
  113. deckkit/views/semantic/figure.py +55 -0
  114. deckkit/views/semantic/item_list.py +171 -0
  115. deckkit/views/semantic/metric.py +74 -0
  116. deckkit/views/semantic/pill.py +69 -0
  117. deckkit/views/semantic/pipeline.py +94 -0
  118. deckkit/views/semantic/pipeline_stage.py +59 -0
  119. deckkit/views/semantic/semantic_view.py +76 -0
  120. deckkit/views/semantic/sparkline.py +164 -0
  121. deckkit/views/semantic/table.py +439 -0
  122. deckkit/views/semantic/terminal.py +361 -0
  123. deckkit/views/semantic/timeline.py +158 -0
  124. deckkit/views/slide.py +37 -0
  125. deckkit/views/slide_number.py +20 -0
  126. deckkit/views/slides/__init__.py +16 -0
  127. deckkit/views/slides/section_slide.py +89 -0
  128. deckkit/views/slides/slide_margins.py +32 -0
  129. deckkit/views/slides/slide_with_margins.py +22 -0
  130. deckkit/views/slides/title_and_content.py +49 -0
  131. deckkit/views/slides/title_and_content_slide.py +55 -0
  132. deckkit/views/spacer.py +45 -0
  133. deckkit/views/stack.py +36 -0
  134. deckkit/views/text.py +142 -0
  135. deckkit/views/view.py +229 -0
  136. deckkit/views/vstack.py +31 -0
  137. deckkit/views/zstack.py +27 -0
  138. deckkit-0.1.0.dist-info/METADATA +123 -0
  139. deckkit-0.1.0.dist-info/RECORD +144 -0
  140. deckkit-0.1.0.dist-info/WHEEL +5 -0
  141. deckkit-0.1.0.dist-info/licenses/LICENSE +21 -0
  142. deckkit-0.1.0.dist-info/licenses/src/deckkit/_font_assets/SourceCodePro-LICENSE.txt +93 -0
  143. deckkit-0.1.0.dist-info/licenses/src/deckkit/_font_assets/SourceSans3-LICENSE.txt +93 -0
  144. deckkit-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,251 @@
1
+ """Lower explicitly requested, compatible tables to native PowerPoint cells."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, replace
6
+ from typing import TYPE_CHECKING, Any
7
+
8
+ from .._diagnostics import SlideLocation
9
+ from ..drawables import (
10
+ Drawable,
11
+ DrawableGroup,
12
+ DrawableLine,
13
+ DrawableRichText,
14
+ DrawableText,
15
+ )
16
+ from ..drawables.table import DrawableTable
17
+
18
+ if TYPE_CHECKING:
19
+ from ..compiler import CompiledSlide
20
+
21
+
22
+ @dataclass(frozen=True)
23
+ class NativeTable(Drawable):
24
+ """A single export item replacing the table's vector layers."""
25
+
26
+ table: DrawableTable
27
+
28
+
29
+ def _incompatible(table: DrawableTable, reason: str) -> ValueError:
30
+ return ValueError(
31
+ f"Native PowerPoint table {table.identity} {reason}. Use pptx='shapes' for this table."
32
+ )
33
+
34
+
35
+ def lower_native_tables(slide: CompiledSlide, location: SlideLocation) -> CompiledSlide:
36
+ """Keep static native tables atomic while the rest of the slide can build."""
37
+ snapshots = [
38
+ {
39
+ node.identity: node
40
+ for node in state.drawable.walk()
41
+ if isinstance(node, DrawableTable)
42
+ }
43
+ for state in slide.states
44
+ ]
45
+ all_tables = {
46
+ identity: table for state in snapshots for identity, table in state.items()
47
+ }
48
+ if not all_tables:
49
+ return slide
50
+ for identity, table in all_tables.items():
51
+ first = snapshots[0].get(identity)
52
+ for step, snapshot in enumerate(snapshots):
53
+ current = snapshot.get(identity)
54
+ with location.context(step):
55
+ if current is not None:
56
+ if current.native_error is not None:
57
+ raise _incompatible(current, current.native_error)
58
+ if (
59
+ current.metadata.opacity != 1
60
+ or current.metadata.shadow is not None
61
+ ):
62
+ raise _incompatible(current, "uses opacity or a shadow")
63
+ if current != first:
64
+ raise _incompatible(table, "changes across slide builds")
65
+ targets: dict[str, int] = {}
66
+ for step, build in enumerate(slide.animation.builds, start=1):
67
+ for effect in build.effects:
68
+ targets.setdefault(effect.identity, step)
69
+ for table in all_tables.values():
70
+ first_step = min(
71
+ (
72
+ targets[node.identity]
73
+ for node in table.walk()
74
+ if node.identity in targets
75
+ ),
76
+ default=None,
77
+ )
78
+ if first_step is not None:
79
+ with location.context(first_step):
80
+ raise _incompatible(table, "contains animated content")
81
+
82
+ def lower(node: Drawable) -> Drawable:
83
+ if isinstance(node, DrawableTable):
84
+ return NativeTable(node.identity, node.bounds, node.metadata, node)
85
+ if isinstance(node, DrawableGroup):
86
+ children = tuple(lower(child) for child in node.children)
87
+ if any(
88
+ before is not after for before, after in zip(node.children, children)
89
+ ):
90
+ return replace(node, children=children)
91
+ return node
92
+
93
+ return replace(
94
+ slide,
95
+ states=tuple(
96
+ replace(state, drawable=lower(state.drawable)) for state in slide.states
97
+ ),
98
+ )
99
+
100
+
101
+ def _border(properties: Any, edge: str, rule: DrawableLine | None) -> None:
102
+ from pptx.dml.line import LineFormat
103
+ from pptx.oxml.ns import qn
104
+ from pptx.oxml.xmlchemy import OxmlElement
105
+
106
+ from .pptx import _apply_stroke
107
+
108
+ # python-pptx exposes LineFormat for shapes, so build a line through it
109
+ # before inserting the same properties under the table cell's edge tag.
110
+ line = OxmlElement("a:ln")
111
+
112
+ class LineParent:
113
+ def get_or_add_ln(self) -> Any:
114
+ return line
115
+
116
+ if rule is None:
117
+ line.append(OxmlElement("a:noFill"))
118
+ else:
119
+ _apply_stroke(
120
+ LineFormat(LineParent()), # type: ignore[no-untyped-call]
121
+ rule.color,
122
+ rule.width,
123
+ rule.dash,
124
+ rule.opacity,
125
+ rule.line_cap,
126
+ rule.line_join,
127
+ )
128
+ line.tag = qn(f"a:ln{edge}")
129
+ properties.insert(0, line)
130
+
131
+
132
+ def _write_cell_text(
133
+ cell: Any, node: DrawableText | DrawableRichText, alignment: Any
134
+ ) -> None:
135
+ from pptx.enum.text import MSO_AUTO_SIZE
136
+ from pptx.util import Pt
137
+
138
+ from .pptx import _apply_font
139
+
140
+ frame = cell.text_frame
141
+ frame.clear()
142
+ frame.auto_size = MSO_AUTO_SIZE.NONE
143
+ frame.word_wrap = True
144
+
145
+ if isinstance(node, DrawableText):
146
+ for i, content in enumerate(node.text.split("\n")):
147
+ paragraph = frame.paragraphs[0] if i == 0 else frame.add_paragraph()
148
+ paragraph.alignment = alignment
149
+ paragraph.space_before = paragraph.space_after = Pt(0)
150
+ paragraph.line_spacing = Pt(node.metrics.line_height.points)
151
+ paragraph.text = content
152
+ _apply_font(
153
+ paragraph.font,
154
+ node.font,
155
+ node.font_size,
156
+ node.color,
157
+ 1,
158
+ None,
159
+ explicit_typeface=node.explicit_typeface,
160
+ )
161
+ else:
162
+ # Preserve the resolved typefaces in mixed-script cells.
163
+ for i, line in enumerate(node.metrics.lines):
164
+ paragraph = frame.paragraphs[0] if i == 0 else frame.add_paragraph()
165
+ paragraph.alignment = alignment
166
+ paragraph.space_before = paragraph.space_after = Pt(0)
167
+ paragraph.line_spacing = Pt(line.height.points)
168
+ for measured in line.runs:
169
+ run = paragraph.add_run()
170
+ run.text = measured.text
171
+ _apply_font(
172
+ run.font,
173
+ measured.font,
174
+ measured.font_size,
175
+ measured.color,
176
+ 1,
177
+ None,
178
+ explicit_typeface=measured.explicit_typeface,
179
+ )
180
+
181
+
182
+ def add_native_table(shapes: Any, node: NativeTable, name: str | None) -> Any:
183
+ from pptx.enum.text import MSO_ANCHOR, PP_ALIGN
184
+ from pptx.util import Pt
185
+
186
+ from .pptx import _color
187
+
188
+ if not hasattr(shapes, "add_table"):
189
+ raise _incompatible(node.table, "is inside a PowerPoint shape group")
190
+ geometry = node.table.geometry
191
+ assert geometry is not None
192
+ x, y, width, height = (
193
+ node.bounds.x,
194
+ node.bounds.y,
195
+ node.bounds.width,
196
+ node.bounds.height,
197
+ )
198
+ shape = shapes.add_table(
199
+ len(geometry.rows),
200
+ len(geometry.widths),
201
+ Pt(x.points),
202
+ Pt(y.points),
203
+ Pt(width.points),
204
+ Pt(height.points),
205
+ )
206
+ shape.name = name or node.identity
207
+ table = shape.table
208
+ table.first_row = True
209
+ table.first_col = table.last_row = table.last_col = False
210
+ table.horz_banding = table.vert_banding = False
211
+ for column, size in zip(table.columns, geometry.widths):
212
+ column.width = Pt(size.points)
213
+
214
+ horizontal = {0.0: PP_ALIGN.LEFT, 0.5: PP_ALIGN.CENTER, 1.0: PP_ALIGN.RIGHT}
215
+ vertical = {0.0: MSO_ANCHOR.TOP, 0.5: MSO_ANCHOR.MIDDLE, 1.0: MSO_ANCHOR.BOTTOM}
216
+ for i, row_geometry in enumerate(geometry.rows):
217
+ row = node.table.children[i]
218
+ table.rows[i].height = Pt(row.bounds.height.points)
219
+ row_grid = row.children[-1]
220
+ for j, (spec, cell_view) in enumerate(
221
+ zip(row_geometry.cells, row_grid.children)
222
+ ):
223
+ cell = table.cell(i, j)
224
+ if spec.alignment.x not in horizontal or spec.alignment.y not in vertical:
225
+ raise _incompatible(
226
+ node.table, f"uses fractional alignment in column {j + 1}"
227
+ )
228
+ (content,) = cell_view.children
229
+ if not isinstance(content, (DrawableText, DrawableRichText)):
230
+ raise _incompatible(node.table, f"uses a custom view in column {j + 1}")
231
+ fill = spec.background or row_geometry.background
232
+ if fill is None:
233
+ cell.fill.background()
234
+ else:
235
+ cell.fill.solid()
236
+ cell.fill.fore_color.rgb = _color(fill)
237
+ cell.vertical_anchor = vertical[spec.alignment.y]
238
+ cell.margin_left = Pt(spec.padding.leading.points)
239
+ cell.margin_right = Pt(spec.padding.trailing.points)
240
+ cell.margin_top = Pt(spec.padding.top.points)
241
+ cell.margin_bottom = Pt(spec.padding.bottom.points)
242
+ _write_cell_text(cell, content, horizontal[spec.alignment.x])
243
+ properties = cell._tc.get_or_add_tcPr()
244
+ for edge, line in (
245
+ ("B", geometry.horizontal_rules[i + 1]),
246
+ ("T", geometry.horizontal_rules[i]),
247
+ ("R", geometry.vertical_rules[j]),
248
+ ("L", geometry.vertical_rules[j - 1] if j else None),
249
+ ):
250
+ _border(properties, edge, line)
251
+ return shape