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.
- deckkit/__init__.py +12 -0
- deckkit/_bundled_fonts.py +54 -0
- deckkit/_diagnostics.py +48 -0
- deckkit/_font_assets/SOURCES.txt +9 -0
- deckkit/_font_assets/SourceCodePro-Bold.ttf +0 -0
- deckkit/_font_assets/SourceCodePro-BoldIt.ttf +0 -0
- deckkit/_font_assets/SourceCodePro-It.ttf +0 -0
- deckkit/_font_assets/SourceCodePro-LICENSE.txt +93 -0
- deckkit/_font_assets/SourceCodePro-Regular.ttf +0 -0
- deckkit/_font_assets/SourceSans3-Bold.ttf +0 -0
- deckkit/_font_assets/SourceSans3-BoldIt.ttf +0 -0
- deckkit/_font_assets/SourceSans3-It.ttf +0 -0
- deckkit/_font_assets/SourceSans3-LICENSE.txt +93 -0
- deckkit/_font_assets/SourceSans3-Regular.ttf +0 -0
- deckkit/_variable_evaluation.py +82 -0
- deckkit/animation.py +211 -0
- deckkit/annotations.py +161 -0
- deckkit/backends/__init__.py +1 -0
- deckkit/backends/_font_embedding.py +41 -0
- deckkit/backends/_pptx_fonts.py +230 -0
- deckkit/backends/_pptx_shadows.py +241 -0
- deckkit/backends/_pptx_tables.py +251 -0
- deckkit/backends/pptx.py +1225 -0
- deckkit/backends/pptx_animation.py +175 -0
- deckkit/backends/svg.py +527 -0
- deckkit/canvas/__init__.py +40 -0
- deckkit/canvas/_geometry.py +49 -0
- deckkit/canvas/clipping.py +336 -0
- deckkit/canvas/context.py +34 -0
- deckkit/canvas/elements.py +306 -0
- deckkit/canvas/path.py +250 -0
- deckkit/canvas/scene.py +74 -0
- deckkit/canvas/style.py +31 -0
- deckkit/charts/__init__.py +59 -0
- deckkit/charts/axes.py +249 -0
- deckkit/charts/chart.py +244 -0
- deckkit/charts/content.py +132 -0
- deckkit/charts/context.py +45 -0
- deckkit/charts/interval.py +166 -0
- deckkit/charts/legends.py +82 -0
- deckkit/charts/marks.py +410 -0
- deckkit/charts/scales.py +205 -0
- deckkit/citations.py +200 -0
- deckkit/compiler.py +410 -0
- deckkit/context.py +72 -0
- deckkit/deck.py +168 -0
- deckkit/drawables/__init__.py +42 -0
- deckkit/drawables/bounds.py +17 -0
- deckkit/drawables/connector.py +22 -0
- deckkit/drawables/drawable.py +38 -0
- deckkit/drawables/ellipse.py +21 -0
- deckkit/drawables/group.py +10 -0
- deckkit/drawables/image.py +14 -0
- deckkit/drawables/line.py +18 -0
- deckkit/drawables/path.py +78 -0
- deckkit/drawables/rectangle.py +24 -0
- deckkit/drawables/rich_text.py +176 -0
- deckkit/drawables/table.py +42 -0
- deckkit/drawables/text.py +29 -0
- deckkit/effects.py +84 -0
- deckkit/expanded_views.py +561 -0
- deckkit/fonts.py +329 -0
- deckkit/geometry.py +48 -0
- deckkit/identity.py +72 -0
- deckkit/layout.py +398 -0
- deckkit/layouts/__init__.py +20 -0
- deckkit/layouts/_content.py +27 -0
- deckkit/layouts/annotations.py +217 -0
- deckkit/layouts/containers.py +202 -0
- deckkit/layouts/grid.py +299 -0
- deckkit/layouts/modifiers.py +200 -0
- deckkit/layouts/primitives.py +213 -0
- deckkit/layouts/table.py +139 -0
- deckkit/measurement.py +420 -0
- deckkit/paint.py +73 -0
- deckkit/py.typed +0 -0
- deckkit/reconcile.py +119 -0
- deckkit/semantic.py +47 -0
- deckkit/theme.py +364 -0
- deckkit/themes/__init__.py +91 -0
- deckkit/themes/clarity.py +98 -0
- deckkit/tokens.py +226 -0
- deckkit/units.py +73 -0
- deckkit/variables.py +212 -0
- deckkit/view_expansion.py +185 -0
- deckkit/views/__init__.py +100 -0
- deckkit/views/_code_source.py +42 -0
- deckkit/views/_drawing.py +52 -0
- deckkit/views/canvas.py +27 -0
- deckkit/views/code.py +481 -0
- deckkit/views/code_evolution.py +284 -0
- deckkit/views/composite_view.py +19 -0
- deckkit/views/divider.py +38 -0
- deckkit/views/ellipse.py +38 -0
- deckkit/views/grid.py +156 -0
- deckkit/views/hstack.py +43 -0
- deckkit/views/image.py +43 -0
- deckkit/views/layout_view.py +30 -0
- deckkit/views/line.py +31 -0
- deckkit/views/modifier_views.py +281 -0
- deckkit/views/path.py +36 -0
- deckkit/views/primitive_view.py +16 -0
- deckkit/views/pygments_highlighter.py +67 -0
- deckkit/views/rectangle.py +61 -0
- deckkit/views/section_number.py +21 -0
- deckkit/views/semantic/__init__.py +51 -0
- deckkit/views/semantic/before_after.py +109 -0
- deckkit/views/semantic/bullet_graph.py +216 -0
- deckkit/views/semantic/card.py +129 -0
- deckkit/views/semantic/code_block.py +41 -0
- deckkit/views/semantic/diff.py +642 -0
- deckkit/views/semantic/estimate_interval.py +137 -0
- deckkit/views/semantic/figure.py +55 -0
- deckkit/views/semantic/item_list.py +171 -0
- deckkit/views/semantic/metric.py +74 -0
- deckkit/views/semantic/pill.py +69 -0
- deckkit/views/semantic/pipeline.py +94 -0
- deckkit/views/semantic/pipeline_stage.py +59 -0
- deckkit/views/semantic/semantic_view.py +76 -0
- deckkit/views/semantic/sparkline.py +164 -0
- deckkit/views/semantic/table.py +439 -0
- deckkit/views/semantic/terminal.py +361 -0
- deckkit/views/semantic/timeline.py +158 -0
- deckkit/views/slide.py +37 -0
- deckkit/views/slide_number.py +20 -0
- deckkit/views/slides/__init__.py +16 -0
- deckkit/views/slides/section_slide.py +89 -0
- deckkit/views/slides/slide_margins.py +32 -0
- deckkit/views/slides/slide_with_margins.py +22 -0
- deckkit/views/slides/title_and_content.py +49 -0
- deckkit/views/slides/title_and_content_slide.py +55 -0
- deckkit/views/spacer.py +45 -0
- deckkit/views/stack.py +36 -0
- deckkit/views/text.py +142 -0
- deckkit/views/view.py +229 -0
- deckkit/views/vstack.py +31 -0
- deckkit/views/zstack.py +27 -0
- deckkit-0.1.0.dist-info/METADATA +123 -0
- deckkit-0.1.0.dist-info/RECORD +144 -0
- deckkit-0.1.0.dist-info/WHEEL +5 -0
- deckkit-0.1.0.dist-info/licenses/LICENSE +21 -0
- deckkit-0.1.0.dist-info/licenses/src/deckkit/_font_assets/SourceCodePro-LICENSE.txt +93 -0
- deckkit-0.1.0.dist-info/licenses/src/deckkit/_font_assets/SourceSans3-LICENSE.txt +93 -0
- deckkit-0.1.0.dist-info/top_level.txt +1 -0
deckkit/theme.py
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Callable, Mapping
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from math import isfinite
|
|
6
|
+
from types import MappingProxyType
|
|
7
|
+
from typing import TYPE_CHECKING, Any, ClassVar, TypeVar, Union, cast
|
|
8
|
+
|
|
9
|
+
from typing_extensions import TypeAlias
|
|
10
|
+
|
|
11
|
+
from .fonts import Font
|
|
12
|
+
from .tokens import DesignToken, TokenAssignment, TokenResolver
|
|
13
|
+
from .units import Length, pt, require_length
|
|
14
|
+
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
from .context import Context
|
|
17
|
+
from .views import View
|
|
18
|
+
from .views.semantic import SemanticView
|
|
19
|
+
|
|
20
|
+
F = TypeVar("F", bound=Callable[..., object])
|
|
21
|
+
_SEMANTIC_COMPONENT = "__deckkit_semantic_component__"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def semantic_renderer(component_type: type[object]) -> Callable[[F], F]:
|
|
25
|
+
"""Register a theme method as the renderer for a semantic component type."""
|
|
26
|
+
if not isinstance(component_type, type):
|
|
27
|
+
raise TypeError("Semantic renderer targets must be component types")
|
|
28
|
+
|
|
29
|
+
def decorate(renderer: F) -> F:
|
|
30
|
+
setattr(renderer, _SEMANTIC_COMPONENT, component_type)
|
|
31
|
+
return renderer
|
|
32
|
+
|
|
33
|
+
return decorate
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass(frozen=True)
|
|
37
|
+
class Typography:
|
|
38
|
+
"""A typography role's font face, physical size and line spacing.
|
|
39
|
+
|
|
40
|
+
Font weight/style are selected by the font file, without synthetic styling.
|
|
41
|
+
An explicit line height takes precedence over the line-spacing multiplier.
|
|
42
|
+
Fallback faces are tried in order when the primary face lacks glyphs.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
font: Font
|
|
46
|
+
size: Length
|
|
47
|
+
line_spacing: float = 1.1
|
|
48
|
+
line_height: Length | None = None
|
|
49
|
+
fallback_fonts: tuple[Font, ...] = ()
|
|
50
|
+
|
|
51
|
+
def __post_init__(self) -> None:
|
|
52
|
+
if not isinstance(self.font, Font):
|
|
53
|
+
raise TypeError(
|
|
54
|
+
"Typography.font must be a Font request; configure files on FileFontResolver"
|
|
55
|
+
)
|
|
56
|
+
if not isinstance(self.fallback_fonts, tuple) or not all(
|
|
57
|
+
isinstance(font, Font) for font in self.fallback_fonts
|
|
58
|
+
):
|
|
59
|
+
raise TypeError(
|
|
60
|
+
"Typography.fallback_fonts must be a tuple of Font requests"
|
|
61
|
+
)
|
|
62
|
+
require_length(self.size)
|
|
63
|
+
if self.size <= pt(0):
|
|
64
|
+
raise ValueError("Font size must be positive")
|
|
65
|
+
if not isfinite(self.line_spacing) or self.line_spacing <= 0:
|
|
66
|
+
raise ValueError("Line spacing must be finite and positive")
|
|
67
|
+
if self.line_height is not None:
|
|
68
|
+
require_length(self.line_height)
|
|
69
|
+
if self.line_height <= pt(0):
|
|
70
|
+
raise ValueError("Line height must be positive")
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@dataclass(frozen=True, init=False)
|
|
74
|
+
class Color:
|
|
75
|
+
"""A normalized RGB color, distinct from a semantic color token.
|
|
76
|
+
|
|
77
|
+
Channels are stored as floats from zero through one. Construct with normalized
|
|
78
|
+
channels or an RGB hex string; rendering converts back to hex only at the
|
|
79
|
+
backend boundary.
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
red: float
|
|
83
|
+
green: float
|
|
84
|
+
blue: float
|
|
85
|
+
|
|
86
|
+
def __init__(
|
|
87
|
+
self,
|
|
88
|
+
red: float | str,
|
|
89
|
+
green: float | None = None,
|
|
90
|
+
blue: float | None = None,
|
|
91
|
+
) -> None:
|
|
92
|
+
if isinstance(red, str):
|
|
93
|
+
if green is not None or blue is not None:
|
|
94
|
+
raise TypeError("Hex Color construction does not accept RGB channels")
|
|
95
|
+
parsed = type(self).from_hex(red)
|
|
96
|
+
channels = (parsed.red, parsed.green, parsed.blue)
|
|
97
|
+
else:
|
|
98
|
+
if green is None or blue is None:
|
|
99
|
+
raise TypeError("RGB Color construction requires all three channels")
|
|
100
|
+
channels = (float(red), float(green), float(blue))
|
|
101
|
+
if any(not isfinite(channel) or not 0 <= channel <= 1 for channel in channels):
|
|
102
|
+
raise ValueError(
|
|
103
|
+
"Color channels must be finite values from zero through one"
|
|
104
|
+
)
|
|
105
|
+
object.__setattr__(self, "red", channels[0])
|
|
106
|
+
object.__setattr__(self, "green", channels[1])
|
|
107
|
+
object.__setattr__(self, "blue", channels[2])
|
|
108
|
+
|
|
109
|
+
@classmethod
|
|
110
|
+
def from_hex(cls, value: str) -> Color:
|
|
111
|
+
"""Parse ``#RRGGBB`` into normalized RGB channels."""
|
|
112
|
+
if not isinstance(value, str) or not value.startswith("#") or len(value) != 7:
|
|
113
|
+
raise ValueError("Color hex values must use #RRGGBB notation")
|
|
114
|
+
try:
|
|
115
|
+
channels = tuple(
|
|
116
|
+
int(value[index : index + 2], 16) / 255 for index in (1, 3, 5)
|
|
117
|
+
)
|
|
118
|
+
except ValueError:
|
|
119
|
+
raise ValueError("Color hex values must use #RRGGBB notation") from None
|
|
120
|
+
result = object.__new__(cls)
|
|
121
|
+
object.__setattr__(result, "red", channels[0])
|
|
122
|
+
object.__setattr__(result, "green", channels[1])
|
|
123
|
+
object.__setattr__(result, "blue", channels[2])
|
|
124
|
+
return result
|
|
125
|
+
|
|
126
|
+
def to_hex(self) -> str:
|
|
127
|
+
"""Return a canonical uppercase ``#RRGGBB`` representation."""
|
|
128
|
+
channels = (self.red, self.green, self.blue)
|
|
129
|
+
return "#" + "".join(f"{round(channel * 255):02X}" for channel in channels)
|
|
130
|
+
|
|
131
|
+
@property
|
|
132
|
+
def hex(self) -> str:
|
|
133
|
+
"""Compatibility shorthand for :meth:`to_hex`."""
|
|
134
|
+
return self.to_hex()
|
|
135
|
+
|
|
136
|
+
def interpolate(self, other: Color, amount: float) -> Color:
|
|
137
|
+
"""Interpolate between two colors in normalized sRGB component space."""
|
|
138
|
+
if not isinstance(other, Color):
|
|
139
|
+
raise TypeError("Color interpolation requires another Color")
|
|
140
|
+
if not isfinite(amount) or not 0 <= amount <= 1:
|
|
141
|
+
raise ValueError("Color interpolation amount must be from zero through one")
|
|
142
|
+
return Color(
|
|
143
|
+
self.red + (other.red - self.red) * amount,
|
|
144
|
+
self.green + (other.green - self.green) * amount,
|
|
145
|
+
self.blue + (other.blue - self.blue) * amount,
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
def mix(self, other: Color, amount: float = 0.5) -> Color:
|
|
149
|
+
"""Alias for :meth:`interpolate`, convenient in token computations."""
|
|
150
|
+
return self.interpolate(other, amount)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
ColorStyle: TypeAlias = Union[DesignToken[Color], Color]
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
@dataclass(frozen=True)
|
|
157
|
+
class CodeTokenStyle:
|
|
158
|
+
"""Optional text-style overrides associated with a code token scope."""
|
|
159
|
+
|
|
160
|
+
foreground_style: ColorStyle | None = None
|
|
161
|
+
background_style: ColorStyle | None = None
|
|
162
|
+
font_style: DesignToken[Typography] | None = None
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _positive_length(value: Length) -> None:
|
|
166
|
+
require_length(value)
|
|
167
|
+
if value <= pt(0):
|
|
168
|
+
raise ValueError("Design-token length must be positive")
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _positive_number(value: float) -> None:
|
|
172
|
+
if not isfinite(value) or value <= 0:
|
|
173
|
+
raise ValueError("Design-token scale must be finite and positive")
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
# Foundational tokens. Themes normally override only a small selection of these;
|
|
177
|
+
# semantic and component tokens below recompute from them.
|
|
178
|
+
BaseFont = DesignToken[Font]("font.base", value_type=Font)
|
|
179
|
+
CodeFont = DesignToken[Font](
|
|
180
|
+
"font.code", lambda values: values[BaseFont], value_type=Font
|
|
181
|
+
)
|
|
182
|
+
BaseFontSize = DesignToken[Length](
|
|
183
|
+
"type.base-size", value_type=Length, validate=_positive_length
|
|
184
|
+
)
|
|
185
|
+
TypeScale = DesignToken[float](
|
|
186
|
+
"type.scale", lambda values: 1.0, value_type=(int, float), validate=_positive_number
|
|
187
|
+
)
|
|
188
|
+
LineSpacing = DesignToken[float](
|
|
189
|
+
"type.line-spacing",
|
|
190
|
+
lambda values: 1.1,
|
|
191
|
+
value_type=(int, float),
|
|
192
|
+
validate=_positive_number,
|
|
193
|
+
)
|
|
194
|
+
SpacingUnit = DesignToken[Length](
|
|
195
|
+
"spacing.unit", value_type=Length, validate=_positive_length
|
|
196
|
+
)
|
|
197
|
+
RadiusScale = DesignToken[float](
|
|
198
|
+
"radius.scale",
|
|
199
|
+
lambda values: 1.0,
|
|
200
|
+
value_type=(int, float),
|
|
201
|
+
validate=_positive_number,
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
PrimaryColor = DesignToken[Color]("color.primary", value_type=Color)
|
|
205
|
+
MutedColor = DesignToken[Color]("color.muted", value_type=Color)
|
|
206
|
+
SurfaceColor = DesignToken[Color]("color.surface", value_type=Color)
|
|
207
|
+
AccentColor = DesignToken[Color]("color.accent", value_type=Color)
|
|
208
|
+
OnAccentColor = DesignToken[Color]("color.on-accent", value_type=Color)
|
|
209
|
+
|
|
210
|
+
BodyTextStyle = DesignToken[Typography](
|
|
211
|
+
"text.body",
|
|
212
|
+
lambda values: Typography(
|
|
213
|
+
values[BaseFont], values[BaseFontSize], values[LineSpacing]
|
|
214
|
+
),
|
|
215
|
+
value_type=Typography,
|
|
216
|
+
)
|
|
217
|
+
TitleTextStyle = DesignToken[Typography](
|
|
218
|
+
"text.title",
|
|
219
|
+
lambda values: Typography(
|
|
220
|
+
values[BaseFont],
|
|
221
|
+
values[BaseFontSize] * (1.6 * values[TypeScale]),
|
|
222
|
+
values[LineSpacing],
|
|
223
|
+
),
|
|
224
|
+
value_type=Typography,
|
|
225
|
+
)
|
|
226
|
+
CaptionTextStyle = DesignToken[Typography](
|
|
227
|
+
"text.caption",
|
|
228
|
+
lambda values: Typography(
|
|
229
|
+
values[BaseFont],
|
|
230
|
+
values[BaseFontSize] * (0.8 * values[TypeScale]),
|
|
231
|
+
values[LineSpacing],
|
|
232
|
+
),
|
|
233
|
+
value_type=Typography,
|
|
234
|
+
)
|
|
235
|
+
ChartTickTextStyle = DesignToken[Typography](
|
|
236
|
+
"chart.text.tick",
|
|
237
|
+
lambda values: Typography(
|
|
238
|
+
values[BaseFont],
|
|
239
|
+
values[BaseFontSize] * (0.7 * values[TypeScale]),
|
|
240
|
+
values[LineSpacing],
|
|
241
|
+
),
|
|
242
|
+
value_type=Typography,
|
|
243
|
+
)
|
|
244
|
+
ChartAxisTitleTextStyle = DesignToken[Typography](
|
|
245
|
+
"chart.text.axis-title",
|
|
246
|
+
lambda values: Typography(
|
|
247
|
+
values[BaseFont],
|
|
248
|
+
values[BaseFontSize] * (0.8 * values[TypeScale]),
|
|
249
|
+
values[LineSpacing],
|
|
250
|
+
),
|
|
251
|
+
value_type=Typography,
|
|
252
|
+
)
|
|
253
|
+
ChartLegendTextStyle = DesignToken[Typography](
|
|
254
|
+
"chart.text.legend",
|
|
255
|
+
lambda values: values[ChartTickTextStyle],
|
|
256
|
+
value_type=Typography,
|
|
257
|
+
)
|
|
258
|
+
ChartDataLabelTextStyle = DesignToken[Typography](
|
|
259
|
+
"chart.text.data-label",
|
|
260
|
+
lambda values: values[ChartTickTextStyle],
|
|
261
|
+
value_type=Typography,
|
|
262
|
+
)
|
|
263
|
+
MetricTextStyle = DesignToken[Typography](
|
|
264
|
+
"text.metric",
|
|
265
|
+
lambda values: Typography(
|
|
266
|
+
values[BaseFont],
|
|
267
|
+
values[BaseFontSize] * (2.3 * values[TypeScale]),
|
|
268
|
+
values[LineSpacing],
|
|
269
|
+
),
|
|
270
|
+
value_type=Typography,
|
|
271
|
+
)
|
|
272
|
+
CodeTextStyle = DesignToken[Typography](
|
|
273
|
+
"text.code",
|
|
274
|
+
lambda values: Typography(
|
|
275
|
+
values[CodeFont],
|
|
276
|
+
values[BaseFontSize] * (0.9 * values[TypeScale]),
|
|
277
|
+
values[LineSpacing],
|
|
278
|
+
),
|
|
279
|
+
value_type=Typography,
|
|
280
|
+
)
|
|
281
|
+
TextStyle = DesignToken[Typography](
|
|
282
|
+
"environment.text-style",
|
|
283
|
+
lambda values: values[BodyTextStyle],
|
|
284
|
+
value_type=Typography,
|
|
285
|
+
)
|
|
286
|
+
ForegroundColor = DesignToken[Color](
|
|
287
|
+
"environment.foreground-color",
|
|
288
|
+
lambda values: values[PrimaryColor],
|
|
289
|
+
value_type=Color,
|
|
290
|
+
)
|
|
291
|
+
ChartAxisColor = DesignToken[Color](
|
|
292
|
+
"chart.color.axis", lambda values: values[MutedColor], value_type=Color
|
|
293
|
+
)
|
|
294
|
+
ChartGridColor = DesignToken[Color](
|
|
295
|
+
"chart.color.grid",
|
|
296
|
+
lambda values: values[MutedColor].mix(values[SurfaceColor], 0.65),
|
|
297
|
+
value_type=Color,
|
|
298
|
+
)
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
class Theme:
|
|
302
|
+
"""Root configuration for an extensible graph of design tokens."""
|
|
303
|
+
|
|
304
|
+
code_styles: ClassVar[Mapping[str, CodeTokenStyle]] = MappingProxyType({})
|
|
305
|
+
_semantic_renderers: ClassVar[Mapping[type[object], Callable[..., object]]] = (
|
|
306
|
+
MappingProxyType({})
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
def __init_subclass__(cls, **kwargs: Any) -> None:
|
|
310
|
+
super().__init_subclass__(**kwargs)
|
|
311
|
+
renderers: dict[type[object], Callable[..., object]] = {}
|
|
312
|
+
for base in reversed(cls.__mro__[1:]):
|
|
313
|
+
renderers.update(getattr(base, "_semantic_renderers", {}))
|
|
314
|
+
for value in cls.__dict__.values():
|
|
315
|
+
component_type = getattr(value, _SEMANTIC_COMPONENT, None)
|
|
316
|
+
if component_type is not None:
|
|
317
|
+
renderers[component_type] = cast(Callable[..., object], value)
|
|
318
|
+
cls._semantic_renderers = MappingProxyType(renderers)
|
|
319
|
+
|
|
320
|
+
def __init__(
|
|
321
|
+
self,
|
|
322
|
+
overrides: Mapping[DesignToken[Any], TokenAssignment[Any]] | None = None,
|
|
323
|
+
) -> None:
|
|
324
|
+
self._token_overrides = MappingProxyType(dict(overrides or {}))
|
|
325
|
+
|
|
326
|
+
def token_overrides(self) -> dict[DesignToken[Any], TokenAssignment[Any]]:
|
|
327
|
+
"""Return root values for the open-ended design-token graph."""
|
|
328
|
+
return dict(self._token_overrides)
|
|
329
|
+
|
|
330
|
+
def token_resolver(self) -> TokenResolver:
|
|
331
|
+
"""Create the root token-resolution scope for this theme."""
|
|
332
|
+
return TokenResolver(self.token_overrides())
|
|
333
|
+
|
|
334
|
+
def code_style(self, language: str | None, token: str | None) -> CodeTokenStyle:
|
|
335
|
+
"""Resolve cascading language and token scopes to presentation roles."""
|
|
336
|
+
token_parts = token.split(".") if token else []
|
|
337
|
+
keys = ["plain"]
|
|
338
|
+
keys.extend(
|
|
339
|
+
".".join(token_parts[:end]) for end in range(1, len(token_parts) + 1)
|
|
340
|
+
)
|
|
341
|
+
if language:
|
|
342
|
+
keys.append(language)
|
|
343
|
+
keys.extend(
|
|
344
|
+
f"{language}.{'.'.join(token_parts[:end])}"
|
|
345
|
+
for end in range(1, len(token_parts) + 1)
|
|
346
|
+
)
|
|
347
|
+
result = CodeTokenStyle()
|
|
348
|
+
for key in keys:
|
|
349
|
+
override = self.code_styles.get(key)
|
|
350
|
+
if override is not None:
|
|
351
|
+
result = CodeTokenStyle(
|
|
352
|
+
override.foreground_style or result.foreground_style,
|
|
353
|
+
override.background_style or result.background_style,
|
|
354
|
+
override.font_style or result.font_style,
|
|
355
|
+
)
|
|
356
|
+
return result
|
|
357
|
+
|
|
358
|
+
def render_semantic(self, component: SemanticView, context: Context) -> View | None:
|
|
359
|
+
"""Optionally override a component; None selects its default composition."""
|
|
360
|
+
for component_type in type(component).__mro__:
|
|
361
|
+
renderer = self._semantic_renderers.get(component_type)
|
|
362
|
+
if renderer is not None:
|
|
363
|
+
return cast("View", renderer(self, component, context))
|
|
364
|
+
return None
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Extensible design tokens, theme contracts, and bundled design systems."""
|
|
2
|
+
|
|
3
|
+
from ..theme import (
|
|
4
|
+
AccentColor,
|
|
5
|
+
BaseFont,
|
|
6
|
+
BaseFontSize,
|
|
7
|
+
BodyTextStyle,
|
|
8
|
+
CaptionTextStyle,
|
|
9
|
+
ChartAxisColor,
|
|
10
|
+
ChartAxisTitleTextStyle,
|
|
11
|
+
ChartDataLabelTextStyle,
|
|
12
|
+
ChartGridColor,
|
|
13
|
+
ChartLegendTextStyle,
|
|
14
|
+
ChartTickTextStyle,
|
|
15
|
+
CodeFont,
|
|
16
|
+
CodeTextStyle,
|
|
17
|
+
CodeTokenStyle,
|
|
18
|
+
Color,
|
|
19
|
+
ColorStyle,
|
|
20
|
+
ForegroundColor,
|
|
21
|
+
LineSpacing,
|
|
22
|
+
MetricTextStyle,
|
|
23
|
+
MutedColor,
|
|
24
|
+
OnAccentColor,
|
|
25
|
+
PrimaryColor,
|
|
26
|
+
RadiusScale,
|
|
27
|
+
SpacingUnit,
|
|
28
|
+
SurfaceColor,
|
|
29
|
+
TextStyle,
|
|
30
|
+
Theme,
|
|
31
|
+
TitleTextStyle,
|
|
32
|
+
TypeScale,
|
|
33
|
+
Typography,
|
|
34
|
+
semantic_renderer,
|
|
35
|
+
)
|
|
36
|
+
from ..tokens import (
|
|
37
|
+
Alias,
|
|
38
|
+
DesignToken,
|
|
39
|
+
MissingTokenError,
|
|
40
|
+
TokenAssignment,
|
|
41
|
+
TokenDependencyCycle,
|
|
42
|
+
TokenError,
|
|
43
|
+
TokenResolver,
|
|
44
|
+
Transform,
|
|
45
|
+
Value,
|
|
46
|
+
)
|
|
47
|
+
from .clarity import ClarityTheme
|
|
48
|
+
|
|
49
|
+
__all__ = [
|
|
50
|
+
"AccentColor",
|
|
51
|
+
"Alias",
|
|
52
|
+
"BaseFont",
|
|
53
|
+
"BaseFontSize",
|
|
54
|
+
"BodyTextStyle",
|
|
55
|
+
"CaptionTextStyle",
|
|
56
|
+
"ChartAxisColor",
|
|
57
|
+
"ChartAxisTitleTextStyle",
|
|
58
|
+
"ChartDataLabelTextStyle",
|
|
59
|
+
"ChartGridColor",
|
|
60
|
+
"ChartLegendTextStyle",
|
|
61
|
+
"ChartTickTextStyle",
|
|
62
|
+
"ClarityTheme",
|
|
63
|
+
"CodeFont",
|
|
64
|
+
"CodeTextStyle",
|
|
65
|
+
"CodeTokenStyle",
|
|
66
|
+
"Color",
|
|
67
|
+
"ColorStyle",
|
|
68
|
+
"DesignToken",
|
|
69
|
+
"ForegroundColor",
|
|
70
|
+
"LineSpacing",
|
|
71
|
+
"MetricTextStyle",
|
|
72
|
+
"MissingTokenError",
|
|
73
|
+
"MutedColor",
|
|
74
|
+
"OnAccentColor",
|
|
75
|
+
"PrimaryColor",
|
|
76
|
+
"RadiusScale",
|
|
77
|
+
"SpacingUnit",
|
|
78
|
+
"SurfaceColor",
|
|
79
|
+
"TextStyle",
|
|
80
|
+
"Theme",
|
|
81
|
+
"TitleTextStyle",
|
|
82
|
+
"TokenAssignment",
|
|
83
|
+
"TokenDependencyCycle",
|
|
84
|
+
"TokenError",
|
|
85
|
+
"TokenResolver",
|
|
86
|
+
"Transform",
|
|
87
|
+
"TypeScale",
|
|
88
|
+
"Typography",
|
|
89
|
+
"Value",
|
|
90
|
+
"semantic_renderer",
|
|
91
|
+
]
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from dataclasses import replace
|
|
5
|
+
from types import MappingProxyType
|
|
6
|
+
from typing import Any, ClassVar
|
|
7
|
+
|
|
8
|
+
from .._bundled_fonts import SOURCE_CODE, SOURCE_SANS
|
|
9
|
+
from ..fonts import Font
|
|
10
|
+
from ..theme import (
|
|
11
|
+
AccentColor,
|
|
12
|
+
BaseFont,
|
|
13
|
+
BaseFontSize,
|
|
14
|
+
ChartGridColor,
|
|
15
|
+
CodeFont,
|
|
16
|
+
CodeTokenStyle,
|
|
17
|
+
Color,
|
|
18
|
+
LineSpacing,
|
|
19
|
+
MutedColor,
|
|
20
|
+
OnAccentColor,
|
|
21
|
+
PrimaryColor,
|
|
22
|
+
RadiusScale,
|
|
23
|
+
SpacingUnit,
|
|
24
|
+
SurfaceColor,
|
|
25
|
+
Theme,
|
|
26
|
+
TypeScale,
|
|
27
|
+
)
|
|
28
|
+
from ..tokens import DesignToken, TokenAssignment
|
|
29
|
+
from ..units import pt
|
|
30
|
+
from ..views.semantic import BeforeAfter, Pipeline
|
|
31
|
+
from ..views.slides.slide_margins import SlideMargin
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class ClarityTheme(Theme):
|
|
35
|
+
"""An editorial theme with quiet surfaces, dark ink and a teal accent."""
|
|
36
|
+
|
|
37
|
+
code_styles: ClassVar[Mapping[str, CodeTokenStyle]] = MappingProxyType(
|
|
38
|
+
{
|
|
39
|
+
"comment": CodeTokenStyle(foreground_style=MutedColor),
|
|
40
|
+
"keyword": CodeTokenStyle(foreground_style=AccentColor),
|
|
41
|
+
"literal.string": CodeTokenStyle(foreground_style=Color("#745137")),
|
|
42
|
+
"literal.number": CodeTokenStyle(foreground_style=Color("#745137")),
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
def __init__(
|
|
47
|
+
self,
|
|
48
|
+
overrides: Mapping[DesignToken[Any], TokenAssignment[Any]] | None = None,
|
|
49
|
+
*,
|
|
50
|
+
font: Font | None = None,
|
|
51
|
+
code_font: Font | None = None,
|
|
52
|
+
accent: Color | str | None = None,
|
|
53
|
+
) -> None:
|
|
54
|
+
values: dict[DesignToken[Any], TokenAssignment[Any]] = {
|
|
55
|
+
BaseFont: BaseFont.set(SOURCE_SANS),
|
|
56
|
+
CodeFont: CodeFont.set(SOURCE_CODE),
|
|
57
|
+
BaseFontSize: BaseFontSize.set(pt(22)),
|
|
58
|
+
TypeScale: TypeScale.set(1.1),
|
|
59
|
+
LineSpacing: LineSpacing.set(1.1),
|
|
60
|
+
SpacingUnit: SpacingUnit.set(pt(4)),
|
|
61
|
+
RadiusScale: RadiusScale.set(0.55),
|
|
62
|
+
SlideMargin: SlideMargin.transform(lambda tokens: tokens[SpacingUnit] * 12),
|
|
63
|
+
PrimaryColor: PrimaryColor.set(Color("#132722")),
|
|
64
|
+
MutedColor: MutedColor.set(Color("#4D6059")),
|
|
65
|
+
SurfaceColor: SurfaceColor.set(Color("#E8EEEA")),
|
|
66
|
+
AccentColor: AccentColor.set(Color("#00675B")),
|
|
67
|
+
OnAccentColor: OnAccentColor.set(Color("#FFFFFF")),
|
|
68
|
+
ChartGridColor: ChartGridColor.transform(
|
|
69
|
+
lambda tokens: tokens[MutedColor].mix(tokens[SurfaceColor], 0.82)
|
|
70
|
+
),
|
|
71
|
+
BeforeAfter.style_token: BeforeAfter.style_token.transform(
|
|
72
|
+
lambda tokens: replace(
|
|
73
|
+
tokens.inherited(BeforeAfter.style_token),
|
|
74
|
+
label_width=tokens[SpacingUnit] * 26,
|
|
75
|
+
label_height=tokens[SpacingUnit] * 10,
|
|
76
|
+
before_foreground=tokens[MutedColor],
|
|
77
|
+
after_background=tokens[SurfaceColor].mix(
|
|
78
|
+
tokens[AccentColor], 0.09
|
|
79
|
+
),
|
|
80
|
+
after_foreground=tokens[PrimaryColor],
|
|
81
|
+
)
|
|
82
|
+
),
|
|
83
|
+
Pipeline.style_token: Pipeline.style_token.transform(
|
|
84
|
+
lambda tokens: replace(
|
|
85
|
+
tokens.inherited(Pipeline.style_token),
|
|
86
|
+
connector=tokens[MutedColor],
|
|
87
|
+
)
|
|
88
|
+
),
|
|
89
|
+
}
|
|
90
|
+
values.update(overrides or {})
|
|
91
|
+
if font is not None:
|
|
92
|
+
values[BaseFont] = BaseFont.set(font)
|
|
93
|
+
if code_font is not None:
|
|
94
|
+
values[CodeFont] = CodeFont.set(code_font)
|
|
95
|
+
if accent is not None:
|
|
96
|
+
color = accent if isinstance(accent, Color) else Color(accent)
|
|
97
|
+
values[AccentColor] = AccentColor.set(color)
|
|
98
|
+
super().__init__(values)
|