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,213 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Sequence
4
+ from dataclasses import dataclass
5
+
6
+ from ..canvas import CanvasContext, CanvasRenderer, CanvasSize, scene_from
7
+ from ..context import Environment
8
+ from ..layout import (
9
+ CAP_CENTER,
10
+ FIRST_BASELINE,
11
+ LAST_BASELINE,
12
+ LayoutChild,
13
+ LayoutContext,
14
+ LayoutPlan,
15
+ ProposedSize,
16
+ StackAxis,
17
+ )
18
+ from ..measurement import StyledTextLine, TextFlow, layout_styled_text
19
+ from ..units import Length, pt
20
+ from ._content import content
21
+
22
+
23
+ @dataclass(frozen=True)
24
+ class TextLayout:
25
+ styled_lines: tuple[StyledTextLine, ...]
26
+ flow: TextFlow = "wrapped"
27
+ font_sample: str = ""
28
+
29
+ def measure(
30
+ self,
31
+ proposal: ProposedSize,
32
+ children: Sequence[LayoutChild],
33
+ context: LayoutContext,
34
+ ) -> LayoutPlan:
35
+ measured_text = layout_styled_text(
36
+ context.measurer,
37
+ context.font_resolver,
38
+ self.styled_lines,
39
+ proposal.width if proposal.width is not None else pt(1_000_000_000),
40
+ self.flow,
41
+ font_sample=self.font_sample,
42
+ )
43
+ guides = {}
44
+ if measured_text.lines:
45
+ first, last = measured_text.lines[0], measured_text.lines[-1]
46
+ cap_height = max(
47
+ (
48
+ run.metrics.cap_height
49
+ for run in first.runs
50
+ if run.metrics.cap_height is not None
51
+ ),
52
+ default=None,
53
+ )
54
+ guides = {
55
+ FIRST_BASELINE: first.baseline,
56
+ LAST_BASELINE: measured_text.height - last.height + last.baseline,
57
+ CAP_CENTER: first.baseline - cap_height / 2
58
+ if cap_height is not None
59
+ else first.height / 2,
60
+ }
61
+ return content(
62
+ measured_text.width,
63
+ measured_text.height,
64
+ measured_text=measured_text,
65
+ line_width=measured_text.width,
66
+ vertical_guides=guides,
67
+ )
68
+
69
+
70
+ @dataclass(frozen=True)
71
+ class ShapeLayout:
72
+ def measure(
73
+ self,
74
+ proposal: ProposedSize,
75
+ children: Sequence[LayoutChild],
76
+ context: LayoutContext,
77
+ ) -> LayoutPlan:
78
+ return content(proposal.width or pt(0), proposal.height or pt(0))
79
+
80
+
81
+ @dataclass(frozen=True)
82
+ class DrawingLayout:
83
+ environment: Environment
84
+ intrinsic_size: tuple[Length, Length] | None = None
85
+
86
+ def measure(
87
+ self,
88
+ proposal: ProposedSize,
89
+ children: Sequence[LayoutChild],
90
+ context: LayoutContext,
91
+ ) -> LayoutPlan:
92
+ width, height = self.intrinsic_size or (
93
+ proposal.width or pt(0),
94
+ proposal.height or pt(0),
95
+ )
96
+ return content(
97
+ width,
98
+ height,
99
+ canvas_context=CanvasContext(
100
+ self.environment, context.measurer, context.font_resolver
101
+ ),
102
+ )
103
+
104
+
105
+ @dataclass(frozen=True)
106
+ class DividerLayout:
107
+ environment: Environment
108
+ thickness: Length
109
+ orientation: StackAxis | None
110
+
111
+ def measure(
112
+ self,
113
+ proposal: ProposedSize,
114
+ children: Sequence[LayoutChild],
115
+ context: LayoutContext,
116
+ ) -> LayoutPlan:
117
+ orientation = self.orientation
118
+ if orientation is None:
119
+ orientation = (
120
+ "vertical" if proposal.stack_axis == "horizontal" else "horizontal"
121
+ )
122
+ width, height = (
123
+ (proposal.width or pt(0), self.thickness)
124
+ if orientation == "horizontal"
125
+ else (self.thickness, proposal.height or pt(0))
126
+ )
127
+ return content(
128
+ width,
129
+ height,
130
+ orientation=orientation,
131
+ canvas_context=CanvasContext(
132
+ self.environment, context.measurer, context.font_resolver
133
+ ),
134
+ )
135
+
136
+
137
+ @dataclass(frozen=True)
138
+ class SpacerLayout:
139
+ length: Length | None
140
+ minimum: Length
141
+
142
+ def measure(
143
+ self,
144
+ proposal: ProposedSize,
145
+ children: Sequence[LayoutChild],
146
+ context: LayoutContext,
147
+ ) -> LayoutPlan:
148
+ def extent(value: Length | None) -> Length:
149
+ return (
150
+ self.length
151
+ if self.length is not None
152
+ else max(self.minimum, value or pt(0))
153
+ )
154
+
155
+ width = pt(0) if proposal.stack_axis == "vertical" else extent(proposal.width)
156
+ height = (
157
+ pt(0) if proposal.stack_axis == "horizontal" else extent(proposal.height)
158
+ )
159
+ return content(width, height)
160
+
161
+
162
+ @dataclass(frozen=True)
163
+ class CanvasLayout:
164
+ renderer: CanvasRenderer
165
+ environment: Environment
166
+
167
+ def measure(
168
+ self,
169
+ proposal: ProposedSize,
170
+ children: Sequence[LayoutChild],
171
+ context: LayoutContext,
172
+ ) -> LayoutPlan:
173
+ width, height = proposal.width or pt(0), proposal.height or pt(0)
174
+ canvas_context = CanvasContext(
175
+ self.environment, context.measurer, context.font_resolver
176
+ )
177
+ scene = scene_from(self.renderer(canvas_context, CanvasSize(width, height)))
178
+ return content(
179
+ width,
180
+ height,
181
+ anchors=scene.measured_anchors(canvas_context),
182
+ canvas_context=canvas_context,
183
+ canvas_scene=scene,
184
+ )
185
+
186
+
187
+ @dataclass(frozen=True)
188
+ class ImageLayout:
189
+ width: Length
190
+ height: Length
191
+ fit: str = "contain"
192
+
193
+ def measure(
194
+ self,
195
+ proposal: ProposedSize,
196
+ children: Sequence[LayoutChild],
197
+ context: LayoutContext,
198
+ ) -> LayoutPlan:
199
+ if (
200
+ self.fit == "cover"
201
+ and proposal.width is not None
202
+ and proposal.height is not None
203
+ ):
204
+ return content(proposal.width, proposal.height)
205
+ width_scale = proposal.width / self.width if proposal.width is not None else 1
206
+ height_scale = (
207
+ proposal.height / self.height if proposal.height is not None else 1
208
+ )
209
+ scale = min(width_scale, height_scale, 1)
210
+ return content(
211
+ self.width * scale,
212
+ self.height * scale,
213
+ )
@@ -0,0 +1,139 @@
1
+ """Measure one grid across a table's independently keyed rows."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Sequence
6
+ from dataclasses import dataclass
7
+
8
+ from ..canvas import Stroke
9
+ from ..drawables.table import TableRowGeometry
10
+ from ..layout import (
11
+ LayoutChild,
12
+ LayoutContext,
13
+ LayoutPlan,
14
+ Placement,
15
+ ProposedSize,
16
+ )
17
+ from ..units import Length, pt
18
+ from .grid import ColumnWidth, _CellArea, _measure_grid_row, _resolve_column_widths
19
+
20
+
21
+ @dataclass(frozen=True)
22
+ class _RowProposal(ProposedSize):
23
+ columns: tuple[Length, ...] = ()
24
+
25
+
26
+ @dataclass(frozen=True)
27
+ class TableRowLayout:
28
+ row: TableRowGeometry
29
+ columns: tuple[Length | ColumnWidth, ...]
30
+
31
+ def measure(
32
+ self,
33
+ proposal: ProposedSize,
34
+ children: Sequence[LayoutChild],
35
+ context: LayoutContext,
36
+ ) -> LayoutPlan:
37
+ cells = self.row.cells
38
+ if not isinstance(proposal, _RowProposal):
39
+ natural, minimums = [], []
40
+ for child, cell, column in zip(children, cells, self.columns):
41
+ horizontal = cell.padding.horizontal
42
+ if isinstance(column, Length):
43
+ natural.append(column)
44
+ minimums.append(horizontal)
45
+ elif cell.plain_text:
46
+ natural.append(horizontal + child.measure(ProposedSize()).width)
47
+ minimums.append(
48
+ horizontal + child.measure(ProposedSize(width=pt(0))).width
49
+ )
50
+ elif column.ideal is not None:
51
+ # An explicit ideal also supports views with no intrinsic width.
52
+ natural.append(column.ideal)
53
+ minimums.append(horizontal)
54
+ else:
55
+ preferred = horizontal + child.measure(ProposedSize()).width
56
+ natural.append(preferred)
57
+ minimums.append(preferred)
58
+ return LayoutPlan(
59
+ sum(natural, pt(0)),
60
+ pt(0),
61
+ properties={"natural": tuple(natural), "minimums": tuple(minimums)},
62
+ )
63
+
64
+ x = pt(0)
65
+ areas = []
66
+ for cell, width in zip(cells, proposal.columns):
67
+ padding = cell.padding
68
+ areas.append(
69
+ _CellArea(
70
+ x,
71
+ width,
72
+ cell.alignment,
73
+ padding.leading,
74
+ padding.top,
75
+ padding.horizontal,
76
+ padding.vertical,
77
+ )
78
+ )
79
+ x += width
80
+ return _measure_grid_row(children, areas, x)
81
+
82
+
83
+ @dataclass(frozen=True)
84
+ class TableLayout:
85
+ columns: tuple[Length | ColumnWidth, ...]
86
+ numeric: tuple[bool, ...]
87
+ rows: tuple[TableRowGeometry, ...]
88
+ horizontal_rules: tuple[Stroke | None, ...]
89
+ vertical_rules: tuple[Stroke | None, ...]
90
+ native: bool
91
+ native_error: str | None
92
+
93
+ def measure(
94
+ self,
95
+ proposal: ProposedSize,
96
+ children: Sequence[LayoutChild],
97
+ context: LayoutContext,
98
+ ) -> LayoutPlan:
99
+ # Each row's composite provides a key scope around its grid.
100
+ ideal_rows = [
101
+ child.measure(ProposedSize()).placements[0].plan for child in children
102
+ ]
103
+ widths = self._column_widths(ideal_rows, proposal)
104
+ row_proposal = _RowProposal(width=sum(widths, pt(0)), columns=tuple(widths))
105
+ y = pt(0)
106
+ placements = []
107
+ for child in children:
108
+ plan = child.measure(row_proposal)
109
+ placements.append(Placement(child, plan, y=y))
110
+ y += plan.height
111
+ assert row_proposal.width is not None
112
+ return LayoutPlan(
113
+ row_proposal.width,
114
+ y,
115
+ tuple(placements),
116
+ properties={"column_widths": tuple(widths)},
117
+ )
118
+
119
+ def _column_widths(
120
+ self, rows: list[LayoutPlan], proposal: ProposedSize
121
+ ) -> list[Length]:
122
+ natural: list[tuple[Length, ...]] = [row.properties["natural"] for row in rows]
123
+ required: list[tuple[Length, ...]] = [
124
+ row.properties["minimums"] for row in rows
125
+ ]
126
+ preferred = [max(row[i] for row in natural) for i in range(len(self.columns))]
127
+ minimums = [max(row[i] for row in required) for i in range(len(self.columns))]
128
+ for i, column in enumerate(self.columns):
129
+ if self.numeric[i] and isinstance(column, ColumnWidth):
130
+ # Keep numbers intact while allowing their headers to wrap.
131
+ minimums[i] = max(
132
+ [minimums[i]]
133
+ + [
134
+ widths[i]
135
+ for row, widths in zip(self.rows[1:], natural[1:])
136
+ if row.cells[i].plain_text
137
+ ]
138
+ )
139
+ return _resolve_column_widths(self.columns, preferred, minimums, proposal)