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,216 @@
1
+ """Compact actual-versus-target data graphics."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Iterable
6
+ from dataclasses import dataclass
7
+ from math import isfinite
8
+ from typing import overload
9
+
10
+ from typing_extensions import Self
11
+
12
+ from ...canvas import (
13
+ CanvasContext,
14
+ CanvasElement,
15
+ CanvasScene,
16
+ CanvasSize,
17
+ Line,
18
+ Rect,
19
+ Stroke,
20
+ )
21
+ from ...charts.scales import LinearScale
22
+ from ...context import Context
23
+ from ...drawables import Bounds
24
+ from ...geometry import Point
25
+ from ...theme import (
26
+ AccentColor,
27
+ ColorStyle,
28
+ MutedColor,
29
+ PrimaryColor,
30
+ SpacingUnit,
31
+ SurfaceColor,
32
+ )
33
+ from ...tokens import DesignToken, TokenResolver
34
+ from ...units import Length, pt, require_length
35
+ from ..canvas import Canvas
36
+ from ..modifier_views import unbounded
37
+ from ..view import View
38
+ from .semantic_view import StyledSemanticView
39
+
40
+
41
+ @dataclass(frozen=True)
42
+ class BulletBand:
43
+ """Fill from the preceding band (or the domain start) to this upper bound."""
44
+
45
+ upper: float
46
+ fill: ColorStyle
47
+
48
+ def __post_init__(self) -> None:
49
+ if not isfinite(self.upper):
50
+ raise ValueError("BulletBand upper bound must be finite")
51
+
52
+
53
+ @dataclass(frozen=True, init=False)
54
+ class BulletGraph(StyledSemanticView["BulletGraph.Style"]):
55
+ """Show an actual value as a zero-based bar and a target as a tick."""
56
+
57
+ @dataclass(frozen=True)
58
+ class Style:
59
+ ideal_width: Length
60
+ height: Length
61
+ padding: Length
62
+ track_height: Length
63
+ bar_height: Length
64
+ target_height: Length
65
+ track_fill: ColorStyle | None
66
+ bar_fill: ColorStyle
67
+ target_stroke: Stroke
68
+
69
+ def __post_init__(self) -> None:
70
+ for length in (
71
+ self.ideal_width,
72
+ self.height,
73
+ self.padding,
74
+ self.track_height,
75
+ self.bar_height,
76
+ self.target_height,
77
+ ):
78
+ require_length(length)
79
+ if length < pt(0):
80
+ raise ValueError("BulletGraph style lengths must be nonnegative")
81
+ if self.height == pt(0) or self.ideal_width == pt(0):
82
+ raise ValueError("BulletGraph ideal width and height must be positive")
83
+ if not isinstance(self.target_stroke, Stroke):
84
+ raise TypeError("BulletGraph.target_stroke must be a Stroke")
85
+
86
+ @staticmethod
87
+ def _default_style(values: TokenResolver) -> Style:
88
+ unit = values[SpacingUnit]
89
+ return BulletGraph.Style(
90
+ ideal_width=unit * 27,
91
+ height=unit * 6,
92
+ padding=unit / 2,
93
+ track_height=unit * 3,
94
+ bar_height=unit * 1.5,
95
+ target_height=unit * 4.5,
96
+ track_fill=values[SurfaceColor].mix(values[MutedColor], 0.18),
97
+ bar_fill=AccentColor,
98
+ target_stroke=Stroke(PrimaryColor, unit / 3),
99
+ )
100
+
101
+ style_token = DesignToken[Style](
102
+ "component.bullet-graph",
103
+ lambda values: BulletGraph._default_style(values),
104
+ value_type=Style,
105
+ )
106
+
107
+ actual: float
108
+ target: float
109
+ domain: tuple[float, float]
110
+ bands: tuple[BulletBand, ...]
111
+
112
+ def __init__(
113
+ self,
114
+ actual: float,
115
+ *,
116
+ target: float,
117
+ domain: tuple[float, float],
118
+ bands: Iterable[BulletBand] = (),
119
+ ) -> None:
120
+ lower, upper = domain
121
+ if not all(isfinite(number) for number in (actual, target, lower, upper)):
122
+ raise ValueError("BulletGraph values and domain must be finite")
123
+ if lower >= upper or not lower <= 0 <= upper:
124
+ raise ValueError("BulletGraph domain must be increasing and include zero")
125
+ if not lower <= actual <= upper or not lower <= target <= upper:
126
+ raise ValueError("BulletGraph actual and target must be within its domain")
127
+ resolved_bands = tuple(bands)
128
+ previous = lower
129
+ for band in resolved_bands:
130
+ if not isinstance(band, BulletBand):
131
+ raise TypeError("BulletGraph bands must be BulletBand values")
132
+ if not previous < band.upper <= upper:
133
+ raise ValueError(
134
+ "BulletGraph band bounds must increase within its domain"
135
+ )
136
+ previous = band.upper
137
+ object.__setattr__(self, "actual", actual)
138
+ object.__setattr__(self, "target", target)
139
+ object.__setattr__(self, "domain", (lower, upper))
140
+ object.__setattr__(self, "bands", resolved_bands)
141
+
142
+ # The base method accepts fields from any style dataclass.
143
+ @overload # type: ignore[override]
144
+ def style(self, style: BulletGraph.Style, /) -> Self: ...
145
+
146
+ @overload
147
+ def style(
148
+ self,
149
+ *,
150
+ ideal_width: Length = ...,
151
+ height: Length = ...,
152
+ padding: Length = ...,
153
+ track_height: Length = ...,
154
+ bar_height: Length = ...,
155
+ target_height: Length = ...,
156
+ track_fill: ColorStyle | None = ...,
157
+ bar_fill: ColorStyle = ...,
158
+ target_stroke: Stroke = ...,
159
+ ) -> Self: ...
160
+
161
+ def style(self, *styles: BulletGraph.Style, **changes: object) -> Self:
162
+ """Replace the style or override individual bullet graph fields."""
163
+ return super().style(*styles, **changes)
164
+
165
+ def body(self, context: Context) -> View:
166
+ style = context.environment[self.style_token]
167
+
168
+ def render(canvas: CanvasContext, size: CanvasSize) -> CanvasScene:
169
+ inset = max(style.padding, style.target_stroke.width / 2)
170
+ if size.width <= inset * 2 or size.height == pt(0):
171
+ return CanvasScene()
172
+ position = LinearScale(self.domain, (inset, size.width - inset))
173
+ center = size.height / 2
174
+ track = min(style.track_height, size.height)
175
+ bar = min(style.bar_height, size.height)
176
+ target = min(style.target_height, size.height - style.target_stroke.width)
177
+
178
+ def rectangle(
179
+ start: float, end: float, height: Length, fill: ColorStyle, key: str
180
+ ) -> Rect:
181
+ left, right = sorted((position(start), position(end)))
182
+ return Rect(
183
+ Bounds(left, center - height / 2, right - left, height),
184
+ fill=fill,
185
+ key=key,
186
+ )
187
+
188
+ lower, upper = self.domain
189
+ items: list[CanvasElement] = []
190
+ if track > pt(0):
191
+ if style.track_fill is not None:
192
+ items.append(
193
+ rectangle(lower, upper, track, style.track_fill, "track")
194
+ )
195
+ for i, band in enumerate(self.bands):
196
+ items.append(
197
+ rectangle(lower, band.upper, track, band.fill, f"band-{i}")
198
+ )
199
+ lower = band.upper
200
+ if self.actual != 0 and bar > pt(0):
201
+ items.append(rectangle(0, self.actual, bar, style.bar_fill, "actual"))
202
+ if target > pt(0):
203
+ x = position(self.target)
204
+ items.append(
205
+ Line(
206
+ Point(x, center - target / 2),
207
+ Point(x, center + target / 2),
208
+ style.target_stroke,
209
+ key="target",
210
+ )
211
+ )
212
+ return CanvasScene(*items)
213
+
214
+ return Canvas(render).frame(
215
+ ideal_width=style.ideal_width, max_width=unbounded, height=style.height
216
+ )
@@ -0,0 +1,129 @@
1
+ """A semantic container for grouped content on a surface."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Callable
6
+ from dataclasses import dataclass
7
+ from typing import overload
8
+
9
+ from typing_extensions import Self
10
+
11
+ from ...canvas import Stroke
12
+ from ...context import Context
13
+ from ...effects import ShadowStyle
14
+ from ...geometry import RelativePoint
15
+ from ...theme import (
16
+ Color,
17
+ PrimaryColor,
18
+ RadiusScale,
19
+ SpacingUnit,
20
+ SurfaceColor,
21
+ )
22
+ from ...tokens import DesignToken, TokenResolver
23
+ from ...units import Length
24
+ from ..modifier_views import EdgeInsets, unbounded
25
+ from ..rectangle import Rectangle
26
+ from ..view import View
27
+ from ..zstack import ZStack
28
+ from .semantic_view import StyledSemanticView
29
+
30
+
31
+ @dataclass(frozen=True)
32
+ class Card(StyledSemanticView["Card.Style"]):
33
+ """Place arbitrary content at the top-left edge of a padded surface."""
34
+
35
+ @dataclass(frozen=True)
36
+ class SurfaceStyle:
37
+ """Appearance passed to a custom surface factory."""
38
+
39
+ background: Color
40
+ corner_radius: Length
41
+ stroke: Stroke | None
42
+ shadow: ShadowStyle | None
43
+
44
+ @dataclass(frozen=True)
45
+ class Style:
46
+ """Card layout and appearance, with an optional custom surface."""
47
+
48
+ background: Color
49
+ foreground: Color
50
+ padding: Length | EdgeInsets
51
+ corner_radius: Length
52
+ alignment: RelativePoint = RelativePoint.top_left
53
+ stroke: Stroke | None = None
54
+ shadow: ShadowStyle | None = None
55
+ surface: Callable[[Card.SurfaceStyle], View] | None = None
56
+
57
+ def __post_init__(self) -> None:
58
+ if self.surface is not None and not callable(self.surface):
59
+ raise TypeError("Card.Style.surface must be callable or None")
60
+
61
+ @staticmethod
62
+ def _default_style(values: TokenResolver) -> Style:
63
+ return Card.Style(
64
+ values[SurfaceColor],
65
+ values[PrimaryColor],
66
+ values[SpacingUnit] * 5,
67
+ values[SpacingUnit] * (3 * values[RadiusScale]),
68
+ )
69
+
70
+ style_token = DesignToken[Style](
71
+ "component.card", lambda values: Card._default_style(values), value_type=Style
72
+ )
73
+
74
+ content: View
75
+
76
+ # The base method accepts fields from any style dataclass.
77
+ @overload # type: ignore[override]
78
+ def style(self, style: Card.Style, /) -> Self: ...
79
+
80
+ @overload
81
+ def style(
82
+ self,
83
+ *,
84
+ background: Color = ...,
85
+ foreground: Color = ...,
86
+ padding: Length | EdgeInsets = ...,
87
+ corner_radius: Length = ...,
88
+ alignment: RelativePoint = ...,
89
+ stroke: Stroke | None = ...,
90
+ shadow: ShadowStyle | None = ...,
91
+ surface: Callable[[Card.SurfaceStyle], View] | None = ...,
92
+ ) -> Self: ...
93
+
94
+ def style(self, *styles: Card.Style, **changes: object) -> Self:
95
+ """Replace the whole style or override specific card fields."""
96
+ return super().style(*styles, **changes)
97
+
98
+ def __post_init__(self) -> None:
99
+ if not isinstance(self.content, View):
100
+ raise TypeError("Card.content must be a View")
101
+
102
+ def body(self, context: Context) -> View:
103
+ style = context.environment[self.style_token]
104
+ content = (
105
+ self.content.foreground_style(style.foreground)
106
+ .frame(max_width=unbounded, alignment=style.alignment)
107
+ .padding(style.padding)
108
+ )
109
+ if style.surface is not None:
110
+ # Propose the padded content's size to the decoration.
111
+ custom_surface = style.surface(
112
+ Card.SurfaceStyle(
113
+ style.background, style.corner_radius, style.stroke, style.shadow
114
+ )
115
+ )
116
+ if not isinstance(custom_surface, View):
117
+ raise TypeError("Card.Style.surface must return a View")
118
+ return content.background(custom_surface)
119
+
120
+ surface = Rectangle(
121
+ corner_radius=style.corner_radius,
122
+ fill=style.background,
123
+ stroke=style.stroke,
124
+ )
125
+ return ZStack(
126
+ surface.shadow(style.shadow) if style.shadow is not None else surface,
127
+ content,
128
+ alignment=style.alignment,
129
+ )
@@ -0,0 +1,41 @@
1
+ """A themed container for code text."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+
7
+ from ...context import Context
8
+ from ...theme import ColorStyle
9
+ from ...tokens import DesignToken
10
+ from ..code import Code, CodeMarkRegion, CodeMarkRegionStyle
11
+ from ..modifier_views import _padding_insets
12
+ from ..view import View
13
+ from .card import Card
14
+ from .semantic_view import SemanticView
15
+
16
+
17
+ @dataclass(frozen=True)
18
+ class CodeBlock(SemanticView):
19
+ """Place code on a padded, theme-overridable surface."""
20
+
21
+ content: Code
22
+ background_style: ColorStyle | None = None
23
+
24
+ def __post_init__(self) -> None:
25
+ if not isinstance(self.content, Code):
26
+ raise TypeError("CodeBlock.content must be Code")
27
+
28
+ def body(self, context: Context) -> View:
29
+ card = Card(self.content)
30
+ background = self.background_style
31
+ if isinstance(background, DesignToken):
32
+ background = context.environment[background]
33
+ if background is not None:
34
+ card = card.style(background=background)
35
+ padding = _padding_insets(context.environment[Card.style_token].padding, None)
36
+ return card.with_token(
37
+ CodeMarkRegionStyle,
38
+ CodeMarkRegionStyle.set(
39
+ CodeMarkRegion(padding.leading, padding.trailing, fill_width=True)
40
+ ),
41
+ )