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,361 @@
1
+ """A themed terminal transcript for a presentation."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Callable, Sequence
6
+ from dataclasses import dataclass, field
7
+ from typing import Literal
8
+
9
+ from ...canvas import Stroke
10
+ from ...context import Context
11
+ from ...geometry import RelativePoint
12
+ from ...identity import ViewIdentity
13
+ from ...layout import (
14
+ Layout,
15
+ LayoutChild,
16
+ LayoutContext,
17
+ LayoutPlan,
18
+ Placement,
19
+ ProposedSize,
20
+ )
21
+ from ...theme import CodeTextStyle, Color, ColorStyle, SpacingUnit, Typography
22
+ from ...tokens import DesignToken, TokenResolver
23
+ from ...units import Length, pt, require_length
24
+ from ..code import Code, CodeMarkRegion, CodeMarkRegionStyle
25
+ from ..ellipse import Ellipse
26
+ from ..hstack import HStack
27
+ from ..layout_view import LayoutView
28
+ from ..modifier_views import EdgeInsets, FrameMaximum, unbounded
29
+ from ..rectangle import Rectangle
30
+ from ..text import Text, TextLine, TextSpan
31
+ from ..view import View
32
+ from .semantic_view import StyledSemanticView
33
+
34
+ TerminalRole = Literal["output", "muted", "warning", "error", "success"]
35
+ TerminalChrome = Literal["dots", "title", "none"]
36
+
37
+
38
+ def _lines(value: str) -> list[str]:
39
+ return value.replace("\r\n", "\n").replace("\r", "\n").split("\n")
40
+
41
+
42
+ @dataclass(frozen=True)
43
+ class TerminalCommand:
44
+ """A command with an optional prompt override and build identity."""
45
+
46
+ text: str
47
+ prompt: str | None = None
48
+ key: str | None = None
49
+
50
+ def __post_init__(self) -> None:
51
+ if not isinstance(self.text, str):
52
+ raise TypeError("Terminal command text must be a string")
53
+ if self.prompt is not None:
54
+ _validate_prompt(self.prompt)
55
+
56
+
57
+ def _validate_prompt(prompt: str) -> None:
58
+ if not isinstance(prompt, str):
59
+ raise TypeError("Terminal prompt must be a string")
60
+ if len(_lines(prompt)) != 1:
61
+ raise ValueError("Terminal prompt must be a single line")
62
+
63
+
64
+ @dataclass(frozen=True, init=False)
65
+ class TerminalOutput:
66
+ """Verbatim output with an optional role and one-based line highlights."""
67
+
68
+ lines: tuple[TextLine, ...]
69
+ role: TerminalRole
70
+ highlight_lines: frozenset[int]
71
+ key: str | None
72
+
73
+ def __init__(
74
+ self,
75
+ content: str | TextLine,
76
+ *lines: TextLine,
77
+ role: TerminalRole = "output",
78
+ highlight_lines: tuple[int, ...] = (),
79
+ key: str | None = None,
80
+ ) -> None:
81
+ if isinstance(content, str) and not lines:
82
+ structured = tuple(TextLine(line) for line in _lines(content))
83
+ elif isinstance(content, TextLine) and all(
84
+ isinstance(line, TextLine) for line in lines
85
+ ):
86
+ structured = (content, *lines)
87
+ else:
88
+ raise TypeError("TerminalOutput requires a string or TextLine values")
89
+ if role not in ("output", "muted", "warning", "error", "success"):
90
+ raise ValueError(f"Unknown terminal output role: {role!r}")
91
+ highlights = frozenset(highlight_lines)
92
+ for line in highlight_lines:
93
+ if type(line) is not int or not 1 <= line <= len(structured):
94
+ raise ValueError(
95
+ "Terminal highlight lines must be one-based output line indices"
96
+ )
97
+ object.__setattr__(self, "lines", structured)
98
+ object.__setattr__(self, "role", role)
99
+ object.__setattr__(self, "highlight_lines", highlights)
100
+ object.__setattr__(self, "key", key)
101
+
102
+
103
+ @dataclass(frozen=True, init=False)
104
+ class Terminal(StyledSemanticView["Terminal.Style"]):
105
+ """Display a plain or structured transcript on a themed terminal surface."""
106
+
107
+ @dataclass(frozen=True)
108
+ class Style:
109
+ typography: Typography
110
+ background: ColorStyle = field(default_factory=lambda: Color("#141922"))
111
+ foreground: ColorStyle = field(default_factory=lambda: Color("#E6EDF6"))
112
+ prompt_color: ColorStyle = field(default_factory=lambda: Color("#91A4BF"))
113
+ command_color: ColorStyle = field(default_factory=lambda: Color("#F5F8FC"))
114
+ muted_color: ColorStyle = field(default_factory=lambda: Color("#A7B4C8"))
115
+ warning_color: ColorStyle = field(default_factory=lambda: Color("#F4CC80"))
116
+ error_color: ColorStyle = field(default_factory=lambda: Color("#FF9D96"))
117
+ success_color: ColorStyle = field(default_factory=lambda: Color("#8DDCB0"))
118
+ highlight: ColorStyle = field(default_factory=lambda: Color("#4C3C2D"))
119
+ chrome: TerminalChrome = "dots"
120
+ title_color: ColorStyle = field(default_factory=lambda: Color("#A7B4C8"))
121
+ dots: tuple[ColorStyle, ...] = (
122
+ Color("#FF6259"),
123
+ Color("#FFBE49"),
124
+ Color("#35CA80"),
125
+ )
126
+ padding: Length = pt(16)
127
+ entry_spacing: Length = pt(5)
128
+ header_spacing: Length = pt(10)
129
+ dot_size: Length = pt(9)
130
+ dot_spacing: Length = pt(5)
131
+ corner_radius: Length = pt(9)
132
+ stroke: Stroke | None = None
133
+ header_top_padding: Length = pt(10)
134
+ title_spacing: Length = pt(9)
135
+
136
+ def __post_init__(self) -> None:
137
+ if self.chrome not in ("dots", "title", "none"):
138
+ raise ValueError("Terminal chrome must be 'dots', 'title', or 'none'")
139
+ for value in (
140
+ self.padding,
141
+ self.entry_spacing,
142
+ self.header_spacing,
143
+ self.header_top_padding,
144
+ self.dot_size,
145
+ self.dot_spacing,
146
+ self.title_spacing,
147
+ self.corner_radius,
148
+ ):
149
+ require_length(value)
150
+ if value < pt(0):
151
+ raise ValueError("Terminal style lengths must be nonnegative")
152
+
153
+ @staticmethod
154
+ def _default_style(values: TokenResolver) -> Style:
155
+ spacing = values[SpacingUnit]
156
+ return Terminal.Style(
157
+ values[CodeTextStyle],
158
+ padding=spacing * 4,
159
+ entry_spacing=spacing,
160
+ header_spacing=spacing * 2.5,
161
+ header_top_padding=spacing * 2.5,
162
+ )
163
+
164
+ style_token = DesignToken[Style](
165
+ "component.terminal",
166
+ lambda values: Terminal._default_style(values),
167
+ value_type=Style,
168
+ )
169
+
170
+ entries: tuple[TerminalCommand | TerminalOutput | Code, ...]
171
+ title: str | None
172
+ prompt: str
173
+ width: FrameMaximum | None
174
+ height: FrameMaximum | None
175
+
176
+ def __init__(
177
+ self,
178
+ *entries: str | TerminalCommand | TerminalOutput | Code,
179
+ title: str | None = None,
180
+ prompt: str = "$ ",
181
+ width: FrameMaximum | None = None,
182
+ height: FrameMaximum | None = None,
183
+ ) -> None:
184
+ _validate_prompt(prompt)
185
+ if title is not None and (
186
+ not isinstance(title, str) or len(_lines(title)) != 1
187
+ ):
188
+ raise ValueError("Terminal title must be a single line")
189
+ for name, dimension in (("width", width), ("height", height)):
190
+ if dimension is None or dimension is unbounded:
191
+ continue
192
+ if not isinstance(dimension, Length):
193
+ raise TypeError(f"Terminal {name} must be a Length or unbounded")
194
+ if dimension <= pt(0):
195
+ raise ValueError(f"Terminal {name} must be positive")
196
+ normalized = tuple(
197
+ TerminalOutput(entry) if isinstance(entry, str) else entry
198
+ for entry in entries
199
+ )
200
+ if not all(
201
+ isinstance(entry, (TerminalCommand, TerminalOutput, Code))
202
+ for entry in normalized
203
+ ):
204
+ raise TypeError(
205
+ "Terminal entries must be strings, TerminalCommand, TerminalOutput, or Code"
206
+ )
207
+ object.__setattr__(self, "entries", normalized)
208
+ object.__setattr__(self, "title", title)
209
+ object.__setattr__(self, "prompt", prompt)
210
+ object.__setattr__(self, "width", width)
211
+ object.__setattr__(self, "height", height)
212
+
213
+ def _entry_view(
214
+ self, entry: TerminalCommand | TerminalOutput | Code, style: Style
215
+ ) -> View:
216
+ if isinstance(entry, Code):
217
+ return entry
218
+ if isinstance(entry, TerminalCommand):
219
+ prompt = self.prompt if entry.prompt is None else entry.prompt
220
+ first, *rest = _lines(entry.text)
221
+ lines = (
222
+ TextLine(TextSpan(prompt, foreground_style=style.prompt_color), first),
223
+ *(TextLine(line) for line in rest),
224
+ )
225
+ foreground = style.command_color
226
+ else:
227
+ lines = tuple(
228
+ TextLine(*line.spans, background_style=style.highlight)
229
+ if index in entry.highlight_lines and line.background_style is None
230
+ else line
231
+ for index, line in enumerate(entry.lines, start=1)
232
+ )
233
+ foreground = {
234
+ "output": style.foreground,
235
+ "muted": style.muted_color,
236
+ "warning": style.warning_color,
237
+ "error": style.error_color,
238
+ "success": style.success_color,
239
+ }[entry.role]
240
+ view = Text(lines[0], *lines[1:], flow="verbatim").foreground_style(foreground)
241
+ return view.key(entry.key) if entry.key is not None else view
242
+
243
+ def body(self, context: Context) -> View:
244
+ style = context.environment[self.style_token]
245
+ header_items: list[View] = []
246
+ if style.chrome == "dots" and style.dots:
247
+ dots = (
248
+ Ellipse(fill=color).frame(width=style.dot_size, height=style.dot_size)
249
+ for color in style.dots
250
+ )
251
+ header_items.append(HStack(*dots, spacing=style.dot_spacing))
252
+ if style.chrome != "none" and self.title:
253
+ header_items.append(
254
+ Text(self.title, flow="verbatim").foreground_style(style.title_color)
255
+ )
256
+ header = (
257
+ HStack(*header_items, spacing=style.title_spacing, alignment="center")
258
+ if header_items
259
+ else None
260
+ )
261
+ layout = _TerminalContentLayout(
262
+ has_header=header is not None,
263
+ header_spacing=style.header_spacing,
264
+ entry_spacing=style.entry_spacing,
265
+ fills_width=self.width is not None,
266
+ code_entries=tuple(isinstance(entry, Code) for entry in self.entries),
267
+ )
268
+ panel: View = (
269
+ _TerminalContent(
270
+ layout,
271
+ header,
272
+ *(self._entry_view(entry, style) for entry in self.entries),
273
+ )
274
+ .font(style.typography)
275
+ .foreground_style(style.foreground)
276
+ .with_tokens(
277
+ {
278
+ CodeTextStyle: CodeTextStyle.set(style.typography),
279
+ CodeMarkRegionStyle: CodeMarkRegionStyle.set(
280
+ CodeMarkRegion(style.padding, style.padding, fill_width=True)
281
+ ),
282
+ }
283
+ )
284
+ )
285
+ panel = panel.padding(
286
+ EdgeInsets(
287
+ top=style.header_top_padding if header is not None else style.padding,
288
+ leading=style.padding,
289
+ bottom=style.padding,
290
+ trailing=style.padding,
291
+ )
292
+ )
293
+ if self.width is not None or self.height is not None:
294
+ panel = panel.frame(
295
+ width=self.width if isinstance(self.width, Length) else None,
296
+ height=self.height if isinstance(self.height, Length) else None,
297
+ max_width=unbounded if self.width is unbounded else None,
298
+ max_height=unbounded if self.height is unbounded else None,
299
+ alignment=RelativePoint.top_left,
300
+ )
301
+ return panel.background(
302
+ Rectangle(
303
+ fill=style.background,
304
+ stroke=style.stroke,
305
+ corner_radius=style.corner_radius,
306
+ )
307
+ )
308
+
309
+
310
+ class _TerminalContent(LayoutView):
311
+ def __init__(self, layout: _TerminalContentLayout, *children: View | None) -> None:
312
+ super().__init__(*children)
313
+ object.__setattr__(self, "_layout", layout)
314
+
315
+ _layout: _TerminalContentLayout
316
+
317
+ def resolve_layout(self, lookup: Callable[[str], ViewIdentity]) -> Layout:
318
+ return self._layout
319
+
320
+
321
+ @dataclass(frozen=True)
322
+ class _TerminalContentLayout:
323
+ has_header: bool
324
+ header_spacing: Length
325
+ entry_spacing: Length
326
+ fills_width: bool
327
+ code_entries: tuple[bool, ...]
328
+
329
+ def measure(
330
+ self,
331
+ proposal: ProposedSize,
332
+ children: Sequence[LayoutChild],
333
+ context: LayoutContext,
334
+ ) -> LayoutPlan:
335
+ is_code = (False, *self.code_entries) if self.has_header else self.code_entries
336
+ offered = ProposedSize(proposal.width, stack_axis="vertical")
337
+ intrinsic = ProposedSize(stack_axis="vertical")
338
+ plans = [
339
+ child.measure(intrinsic if code and not self.fills_width else offered)
340
+ for child, code in zip(children, is_code)
341
+ ]
342
+ width = (
343
+ proposal.width
344
+ if self.fills_width and proposal.width is not None
345
+ else max((plan.width for plan in plans), default=pt(0))
346
+ )
347
+ # The header and all entries contribute to an intrinsic panel's width.
348
+ # Give code that resolved width so its marks can reach both edges.
349
+ resolved = ProposedSize(width, stack_axis="vertical")
350
+ placements = []
351
+ y = pt(0)
352
+ for index, (child, plan, code) in enumerate(zip(children, plans, is_code)):
353
+ if code:
354
+ plan = child.measure(resolved)
355
+ placements.append(Placement(child, plan, y=y))
356
+ y += plan.height
357
+ if index == 0 and self.has_header:
358
+ y += self.header_spacing
359
+ elif index + 1 < len(children):
360
+ y += self.entry_spacing
361
+ return LayoutPlan(width, y, tuple(placements))
@@ -0,0 +1,158 @@
1
+ """A vertical timeline for ordered milestones."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+
7
+ from ...context import Context
8
+ from ...geometry import RelativePoint
9
+ from ...theme import (
10
+ AccentColor,
11
+ ColorStyle,
12
+ MutedColor,
13
+ SpacingUnit,
14
+ SurfaceColor,
15
+ Typography,
16
+ )
17
+ from ...tokens import DesignToken, TokenResolver
18
+ from ...units import Length, pt, require_length
19
+ from ..ellipse import Ellipse
20
+ from ..hstack import HStack
21
+ from ..rectangle import Rectangle
22
+ from ..spacer import Spacer
23
+ from ..text import Text, TextLine, TextSpan
24
+ from ..view import View
25
+ from ..vstack import VStack
26
+ from .semantic_view import SemanticView, StyledSemanticView
27
+
28
+
29
+ @dataclass(frozen=True, init=False)
30
+ class Timeline(StyledSemanticView["Timeline.Style"]):
31
+ """Display timeline events in the supplied order.
32
+
33
+ With ``fill_height=True``, spare height is shared among the event gaps.
34
+ A single event stays at the top. Event content and minimum gaps keep their
35
+ natural heights when the proposed height is smaller.
36
+ """
37
+
38
+ @dataclass(frozen=True)
39
+ class Style:
40
+ spacing: Length
41
+ marker_size: Length
42
+ marker_gap: Length
43
+ rail_width: Length
44
+ rail_color: ColorStyle
45
+ marker_color: ColorStyle = AccentColor
46
+ label_color: ColorStyle = AccentColor
47
+ label_font: DesignToken[Typography] | None = None
48
+
49
+ def __post_init__(self) -> None:
50
+ for length in (
51
+ self.spacing,
52
+ self.marker_size,
53
+ self.marker_gap,
54
+ self.rail_width,
55
+ ):
56
+ require_length(length)
57
+ if length < pt(0):
58
+ raise ValueError("Timeline style lengths must be nonnegative")
59
+ if self.marker_size == pt(0):
60
+ raise ValueError("Timeline marker_size must be positive")
61
+
62
+ @property
63
+ def _gutter_width(self) -> Length:
64
+ return max(self.marker_size, self.rail_width)
65
+
66
+ @staticmethod
67
+ def _default_style(values: TokenResolver) -> Style:
68
+ unit = values[SpacingUnit]
69
+ return Timeline.Style(
70
+ spacing=unit * 4,
71
+ marker_size=unit * 2,
72
+ marker_gap=unit * 3,
73
+ rail_width=unit / 2,
74
+ rail_color=values[MutedColor].mix(values[SurfaceColor], 0.6),
75
+ )
76
+
77
+ style_token = DesignToken[Style](
78
+ "component.timeline",
79
+ lambda values: Timeline._default_style(values),
80
+ value_type=Style,
81
+ )
82
+
83
+ events: tuple[TimelineEvent, ...]
84
+ fill_height: bool
85
+
86
+ def __init__(self, *events: TimelineEvent, fill_height: bool = False) -> None:
87
+ if not all(isinstance(event, TimelineEvent) for event in events):
88
+ raise TypeError("Timeline children must be TimelineEvent instances")
89
+ if not isinstance(fill_height, bool):
90
+ raise TypeError("Timeline fill_height must be a bool")
91
+ object.__setattr__(self, "events", events)
92
+ object.__setattr__(self, "fill_height", fill_height)
93
+
94
+ def body(self, context: Context) -> View:
95
+ style = context.environment[self.style_token]
96
+ rows: list[View] = []
97
+ for index, event in enumerate(self.events):
98
+ if index:
99
+ rows.append(
100
+ Spacer(min_length=style.spacing)
101
+ if self.fill_height
102
+ else Spacer(style.spacing)
103
+ )
104
+ rows.append(event)
105
+ if self.fill_height and len(self.events) == 1:
106
+ rows.append(Spacer())
107
+
108
+ content = VStack(*rows, spacing=pt(0))
109
+ if len(self.events) < 2 or style.rail_width == pt(0):
110
+ return content
111
+ rail = (
112
+ Rectangle(fill=style.rail_color)
113
+ .frame(width=style.rail_width)
114
+ .frame(width=style._gutter_width)
115
+ )
116
+ return content.background(rail, alignment=RelativePoint.left)
117
+
118
+
119
+ @dataclass(frozen=True)
120
+ class TimelineEvent(SemanticView):
121
+ """A labeled milestone, with inline text or a view below the label."""
122
+
123
+ label: str
124
+ content: str | View = ""
125
+
126
+ def __post_init__(self) -> None:
127
+ if not isinstance(self.label, str):
128
+ raise TypeError("TimelineEvent.label must be a string")
129
+ if not self.label.strip() or "\n" in self.label or "\r" in self.label:
130
+ raise ValueError("TimelineEvent.label must be a nonempty single line")
131
+ if not isinstance(self.content, (str, View)):
132
+ raise TypeError("TimelineEvent.content must be a string or a View")
133
+
134
+ def body(self, context: Context) -> View:
135
+ style = context.environment[Timeline.style_token]
136
+ label = TextSpan(
137
+ self.label,
138
+ font_style=style.label_font,
139
+ foreground_style=style.label_color,
140
+ )
141
+ copy: View
142
+ if isinstance(self.content, str):
143
+ first, *rest = self.content.split("\n")
144
+ line = TextLine(label, f" {first}") if first else TextLine(label)
145
+ copy = Text(line, *(TextLine(text) for text in rest))
146
+ else:
147
+ copy = VStack(
148
+ Text(TextLine(label)), self.content, spacing=style.marker_gap / 2
149
+ )
150
+
151
+ marker = (
152
+ Ellipse(fill=style.marker_color)
153
+ .frame(width=style.marker_size, height=style.marker_size)
154
+ .frame(width=style._gutter_width)
155
+ )
156
+ return HStack(
157
+ marker, copy.flex(), alignment="cap_center", spacing=style.marker_gap
158
+ )
deckkit/views/slide.py ADDED
@@ -0,0 +1,37 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+
5
+ from ..animation import SlideTimeline
6
+ from ..context import Context
7
+ from .semantic.semantic_view import SemanticView
8
+ from .view import View
9
+
10
+
11
+ class Slide(SemanticView):
12
+ """A theme-overridable top-level presentation view."""
13
+
14
+ @staticmethod
15
+ def from_view(view: View) -> Slide:
16
+ """Create a static slide with the given view as its body."""
17
+ if not isinstance(view, View):
18
+ raise TypeError("Slide.from_view() requires a View")
19
+ return _ViewSlide(view)
20
+
21
+ def timeline(self) -> SlideTimeline:
22
+ """Describe this slide's authored presentation states and triggers."""
23
+ return SlideTimeline.static()
24
+
25
+ def _diagnostic_label(self) -> str | None:
26
+ return type(self).__name__
27
+
28
+
29
+ @dataclass(frozen=True)
30
+ class _ViewSlide(Slide):
31
+ _view: View
32
+
33
+ def body(self, context: Context) -> View:
34
+ return self._view
35
+
36
+ def _diagnostic_label(self) -> str | None:
37
+ return None
@@ -0,0 +1,20 @@
1
+ from dataclasses import dataclass
2
+
3
+ from ..context import Context
4
+ from ..expanded_views import ExpandedMetadata, ExpandedPrimitive
5
+ from .primitive_view import PrimitiveView
6
+
7
+
8
+ @dataclass(frozen=True)
9
+ class SlideNumber(PrimitiveView):
10
+ """Display the current slide number as a live field in PowerPoint."""
11
+
12
+ def expand(self, context: Context, metadata: ExpandedMetadata) -> ExpandedPrimitive:
13
+ from ..variables import _deferred_text, slide_count
14
+
15
+ return _deferred_text(
16
+ context,
17
+ metadata,
18
+ lambda values: str(values.value(slide_count)),
19
+ live_slide_number=True,
20
+ )
@@ -0,0 +1,16 @@
1
+ """Semantic slide structures with theme-overridable compositions."""
2
+
3
+ from .section_slide import SectionSlide
4
+ from .slide_margins import SlideMargin, SlideMargins
5
+ from .slide_with_margins import SlideWithMargins
6
+ from .title_and_content import TitleAndContent
7
+ from .title_and_content_slide import TitleAndContentSlide
8
+
9
+ __all__ = [
10
+ "SectionSlide",
11
+ "SlideMargin",
12
+ "SlideMargins",
13
+ "SlideWithMargins",
14
+ "TitleAndContent",
15
+ "TitleAndContentSlide",
16
+ ]
@@ -0,0 +1,89 @@
1
+ """A theme-overridable section opener."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+
7
+ from ...context import Context
8
+ from ...theme import (
9
+ BodyTextStyle,
10
+ CaptionTextStyle,
11
+ SpacingUnit,
12
+ TitleTextStyle,
13
+ Typography,
14
+ )
15
+ from ...tokens import DesignToken, TokenResolver
16
+ from ...units import Length
17
+ from ..modifier_views import unbounded
18
+ from ..section_number import SectionNumber
19
+ from ..semantic.semantic_view import StyledSemanticView
20
+ from ..slide import Slide
21
+ from ..text import Text
22
+ from ..view import View
23
+ from ..vstack import VStack
24
+ from .slide_margins import SlideMargins
25
+
26
+
27
+ @dataclass(frozen=True, init=False)
28
+ class SectionSlide(Slide, StyledSemanticView["SectionSlide.Style"]):
29
+ """Start a deck section with a title and optional subtitle."""
30
+
31
+ @dataclass(frozen=True)
32
+ class Style:
33
+ title_font: Typography
34
+ subtitle_font: Typography
35
+ number_font: Typography
36
+ spacing: Length
37
+ show_number: bool = True
38
+ number_format: str = "02d"
39
+
40
+ @staticmethod
41
+ def _default_style(values: TokenResolver) -> Style:
42
+ return SectionSlide.Style(
43
+ values[TitleTextStyle],
44
+ values[BodyTextStyle],
45
+ values[CaptionTextStyle],
46
+ values[SpacingUnit] * 2,
47
+ )
48
+
49
+ style_token = DesignToken[Style](
50
+ "component.section-slide",
51
+ lambda values: SectionSlide._default_style(values),
52
+ value_type=Style,
53
+ )
54
+
55
+ title: View
56
+ subtitle: View | None
57
+
58
+ def __init__(
59
+ self, title: str | View, *, subtitle: str | View | None = None
60
+ ) -> None:
61
+ title_view = Text(title) if isinstance(title, str) else title
62
+ subtitle_view = Text(subtitle) if isinstance(subtitle, str) else subtitle
63
+ if not isinstance(title_view, View):
64
+ raise TypeError("SectionSlide.title must be a string or a View")
65
+ if subtitle_view is not None and not isinstance(subtitle_view, View):
66
+ raise TypeError("SectionSlide.subtitle must be a string or a View")
67
+ object.__setattr__(self, "title", title_view)
68
+ object.__setattr__(self, "subtitle", subtitle_view)
69
+
70
+ def _diagnostic_label(self) -> str | None:
71
+ if isinstance(self.title, Text):
72
+ return " ".join(self.title.text.split())
73
+ return super()._diagnostic_label()
74
+
75
+ def body(self, context: Context) -> View:
76
+ style = context.environment[self.style_token]
77
+ return SlideMargins(
78
+ VStack(
79
+ SectionNumber(format=style.number_format).font(style.number_font)
80
+ if style.show_number
81
+ else None,
82
+ self.title.font(style.title_font),
83
+ self.subtitle.font(style.subtitle_font)
84
+ if self.subtitle is not None
85
+ else None,
86
+ alignment="center",
87
+ spacing=style.spacing,
88
+ ).frame(max_width=unbounded, max_height=unbounded)
89
+ )