doxtr-theme-core 0.1.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Doxtr
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,36 @@
1
+ Metadata-Version: 2.4
2
+ Name: doxtr-theme-core
3
+ Version: 0.1.0
4
+ Summary: Universal theme core foundation (palettes, color DSL, dark mode, fonts, stylebox, brand orchestration) across HTML, PDF, and future renderers.
5
+ Author: Jens Frey
6
+ Project-URL: Homepage, https://github.com/doxtr/doxtr-theme-core
7
+ Project-URL: Repository, https://github.com/doxtr/doxtr-theme-core
8
+ Project-URL: Issues, https://github.com/doxtr/doxtr-theme-core/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Framework :: Sphinx :: Extension
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Topic :: Documentation :: Sphinx
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: sphinx>=7.0
21
+ Requires-Dist: docutils>=0.19
22
+ Dynamic: license-file
23
+
24
+ # doxtr-theme-core
25
+
26
+ Universal multi-target theme foundation for the `doxtr` Sphinx ecosystem.
27
+
28
+ Provides shared primitives for HTML (`doxtr-html-theme-core`), PDF (`doxtr-pdf-theme-core`), brand suites (`doxtr-theme-aubergine`), Confluence, and future EPUB / Swift renderers:
29
+
30
+ - Typed `ThemeSpec`, `ColorPalette`, `FontSpec`, and `BrandConfig` contracts
31
+ - `dd:` dynamic color expression engine + WCAG AA/AAA contrast helpers + CSS token emission
32
+ - Unified light/dark mode state (`doxtr_color_scheme` / `doxtr_dark_mode`) and `_dark` asset swapping
33
+ - Unified font registration (`LaTeX` + `@font-face` CSS stacks)
34
+ - Universal `.. stylebox::` directive (HTML, LaTeX, Confluence)
35
+ - Brand-to-renderer orchestration with automatic `-core` fallback and `-user` renderer compatibility
36
+ - AI authoring agent style guidance (`get_ai_style_guidance`)
@@ -0,0 +1,13 @@
1
+ # doxtr-theme-core
2
+
3
+ Universal multi-target theme foundation for the `doxtr` Sphinx ecosystem.
4
+
5
+ Provides shared primitives for HTML (`doxtr-html-theme-core`), PDF (`doxtr-pdf-theme-core`), brand suites (`doxtr-theme-aubergine`), Confluence, and future EPUB / Swift renderers:
6
+
7
+ - Typed `ThemeSpec`, `ColorPalette`, `FontSpec`, and `BrandConfig` contracts
8
+ - `dd:` dynamic color expression engine + WCAG AA/AAA contrast helpers + CSS token emission
9
+ - Unified light/dark mode state (`doxtr_color_scheme` / `doxtr_dark_mode`) and `_dark` asset swapping
10
+ - Unified font registration (`LaTeX` + `@font-face` CSS stacks)
11
+ - Universal `.. stylebox::` directive (HTML, LaTeX, Confluence)
12
+ - Brand-to-renderer orchestration with automatic `-core` fallback and `-user` renderer compatibility
13
+ - AI authoring agent style guidance (`get_ai_style_guidance`)
@@ -0,0 +1,230 @@
1
+ """Universal theme core for Doxtr (palettes, color DSL, dark mode, fonts, stylebox, brand orchestration)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from .assets import (
8
+ ASSETS_DIR,
9
+ DEFAULT_ICON_NAME,
10
+ DEFAULT_SMALL_ICON_NAME,
11
+ get_core_asset,
12
+ get_core_assets_dir,
13
+ get_default_icon_path,
14
+ )
15
+ from .colors import (
16
+ DOXTR_SEMANTIC_PALETTE,
17
+ DOXTR_SEMANTIC_PALETTE_DARK_DEFAULTS,
18
+ _RE_SAFE_NAME,
19
+ _adapt_colors_in_dict,
20
+ _compute_adaptation_compression,
21
+ _custom_color_operations,
22
+ _get_contrast_ratio,
23
+ _get_luminance,
24
+ _get_luminance_from_floats,
25
+ _hex_to_rgb,
26
+ _normalize_hex_with_alpha,
27
+ _split_hex_opacity,
28
+ adapt_color_to_page,
29
+ compute_dark_palette,
30
+ deep_update,
31
+ enforce_pygments_css_wcag,
32
+ enforce_pygments_latex_wcag,
33
+ ensure_palette_wcag,
34
+ generate_css_tokens,
35
+ get_contrast_ratio,
36
+ get_highest_contrast_color,
37
+ get_safe_filename,
38
+ hex_dark_invert,
39
+ hex_to_cmyk_string,
40
+ hex_to_rgb,
41
+ hex_to_rgb_floats,
42
+ register_color_operation,
43
+ resolve_all_colors,
44
+ resolve_color,
45
+ to_bool,
46
+ )
47
+ from .dark_file_swap import (
48
+ DARK_FILE_SWAP_DIRECTIVES_DEFAULT,
49
+ DARK_FILE_SWAP_EXTENSIONS_DEFAULT,
50
+ register_dark_swap_directive,
51
+ swap_dark_includes,
52
+ swap_dark_sources,
53
+ )
54
+ from .darkmode import (
55
+ get_dark_mode_context,
56
+ get_dark_palette,
57
+ is_dark_mode_active,
58
+ mark_image_dark_ready,
59
+ sync_color_scheme,
60
+ )
61
+ from .directives import (
62
+ StyleBoxConfluencePostTransform,
63
+ StyleBoxDirective,
64
+ StyleBoxHtmlPostTransform,
65
+ )
66
+ from .fonts import (
67
+ VALID_FONT_KEYS,
68
+ auto_discover_fonts,
69
+ collect_font_files,
70
+ generate_css_font_faces,
71
+ generate_font_features,
72
+ get_registered_fonts,
73
+ inject_font_features,
74
+ process_user_font_config,
75
+ register_font_discoverer,
76
+ register_font_families,
77
+ register_font_family,
78
+ register_font_renderer,
79
+ validate_font_files,
80
+ )
81
+ from .guidance import CORE_AI_STYLE_GUIDANCE, format_brand_guidance, get_ai_style_guidance
82
+ from .orchestrator import (
83
+ apply_brand_to_config,
84
+ get_active_theme,
85
+ get_brand_theme,
86
+ list_brand_themes,
87
+ register_brand_theme,
88
+ register_renderer,
89
+ setup_brand_theme,
90
+ )
91
+ from .spec import (
92
+ DEFAULT_CORE_THEME_SPEC,
93
+ BrandConfig,
94
+ ColorPalette,
95
+ FontSpec,
96
+ RendererRegistration,
97
+ ThemeRegistry,
98
+ ThemeSpec,
99
+ )
100
+
101
+ __version__ = "0.1.0"
102
+
103
+ __all__ = [
104
+ "__version__",
105
+ "ASSETS_DIR",
106
+ "DEFAULT_ICON_NAME",
107
+ "DEFAULT_SMALL_ICON_NAME",
108
+ "get_core_assets_dir",
109
+ "get_core_asset",
110
+ "get_default_icon_path",
111
+ "BrandConfig",
112
+ "ColorPalette",
113
+ "DEFAULT_CORE_THEME_SPEC",
114
+ "FontSpec",
115
+ "RendererRegistration",
116
+ "ThemeRegistry",
117
+ "ThemeSpec",
118
+ "DOXTR_SEMANTIC_PALETTE",
119
+ "DOXTR_SEMANTIC_PALETTE_DARK_DEFAULTS",
120
+ "compute_dark_palette",
121
+ "ensure_palette_wcag",
122
+ "enforce_pygments_css_wcag",
123
+ "enforce_pygments_latex_wcag",
124
+ "generate_css_tokens",
125
+ "resolve_color",
126
+ "resolve_all_colors",
127
+ "register_color_operation",
128
+ "get_contrast_ratio",
129
+ "get_highest_contrast_color",
130
+ "hex_dark_invert",
131
+ "hex_to_rgb",
132
+ "hex_to_rgb_floats",
133
+ "hex_to_cmyk_string",
134
+ "adapt_color_to_page",
135
+ "deep_update",
136
+ "to_bool",
137
+ "get_safe_filename",
138
+ "is_dark_mode_active",
139
+ "get_dark_palette",
140
+ "get_dark_mode_context",
141
+ "mark_image_dark_ready",
142
+ "sync_color_scheme",
143
+ "register_dark_swap_directive",
144
+ "swap_dark_sources",
145
+ "swap_dark_includes",
146
+ "DARK_FILE_SWAP_DIRECTIVES_DEFAULT",
147
+ "DARK_FILE_SWAP_EXTENSIONS_DEFAULT",
148
+ "register_font_family",
149
+ "register_font_families",
150
+ "get_registered_fonts",
151
+ "register_font_renderer",
152
+ "register_font_discoverer",
153
+ "generate_css_font_faces",
154
+ "generate_font_features",
155
+ "inject_font_features",
156
+ "process_user_font_config",
157
+ "auto_discover_fonts",
158
+ "collect_font_files",
159
+ "validate_font_files",
160
+ "VALID_FONT_KEYS",
161
+ "StyleBoxDirective",
162
+ "StyleBoxHtmlPostTransform",
163
+ "StyleBoxConfluencePostTransform",
164
+ "CORE_AI_STYLE_GUIDANCE",
165
+ "format_brand_guidance",
166
+ "get_ai_style_guidance",
167
+ "register_brand_theme",
168
+ "get_brand_theme",
169
+ "list_brand_themes",
170
+ "get_active_theme",
171
+ "register_renderer",
172
+ "setup_brand_theme",
173
+ "add_config_value_if_missing",
174
+ "setup",
175
+ ]
176
+
177
+
178
+ def add_config_value_if_missing(
179
+ app: Any, name: str, default: Any, rebuild: str = "env"
180
+ ) -> None:
181
+ """Register a Sphinx config value only if not already registered."""
182
+ values = getattr(getattr(app, "config", None), "values", None)
183
+ if isinstance(values, dict) and name in values:
184
+ return
185
+ try:
186
+ app.add_config_value(name, default, rebuild)
187
+ except Exception:
188
+ pass
189
+
190
+
191
+ def setup(app: Any) -> dict[str, Any]:
192
+ """Sphinx extension entry point for ``doxtr_theme_core``."""
193
+ app.add_directive("stylebox", StyleBoxDirective)
194
+ app.add_post_transform(StyleBoxHtmlPostTransform)
195
+ app.add_post_transform(StyleBoxConfluencePostTransform)
196
+
197
+ add_config_value_if_missing(app, "doxtr_color_scheme", "auto", "env")
198
+ add_config_value_if_missing(app, "doxtr_dark_mode", False, "env")
199
+ add_config_value_if_missing(app, "doxtr_dark_mode_strategy", "auto", "env")
200
+ add_config_value_if_missing(app, "doxtr_dark_mode_strategy_resolved", "invert", "env")
201
+ add_config_value_if_missing(app, "doxtr_dark_text_color", None, "env")
202
+ add_config_value_if_missing(app, "doxtr_semantic_palette", {}, "env")
203
+ add_config_value_if_missing(app, "doxtr_dark_semantic_palette", {}, "env")
204
+ add_config_value_if_missing(app, "doxtr_resolved_semantic_palette", {}, "env")
205
+ add_config_value_if_missing(app, "doxtr_theme_brand", None, "env")
206
+ add_config_value_if_missing(app, "doxtr_active_brand", None, "env")
207
+ add_config_value_if_missing(app, "doxtr_theme_spec", None, "env")
208
+ add_config_value_if_missing(app, "doxtr_html_renderer", None, "env")
209
+ add_config_value_if_missing(app, "doxtr_pdf_renderer", None, "env")
210
+ add_config_value_if_missing(app, "doxtr_autoload_renderers", True, "env")
211
+ add_config_value_if_missing(app, "doxtr_branding", {}, "env")
212
+ add_config_value_if_missing(app, "doxtr_fonts", {}, "env")
213
+ add_config_value_if_missing(app, "doxtr_theme_defaults", {}, "env")
214
+ add_config_value_if_missing(app, "doxtr_enable_dark_file_swap", True, "env")
215
+ add_config_value_if_missing(app, "doxtr_dark_file_swap_directives", {}, "env")
216
+ add_config_value_if_missing(app, "doxtr_dark_file_swap_extensions", None, "env")
217
+ add_config_value_if_missing(app, "doxtr_dark_file_swap_extra_extensions", [], "env")
218
+ add_config_value_if_missing(app, "doxtr_dark_file_swap_exclude", [], "env")
219
+ add_config_value_if_missing(app, "doxtr_image_exclude_patterns", [], "env")
220
+ add_config_value_if_missing(app, "doxtr_wcag_level", 4.5, "env")
221
+ add_config_value_if_missing(app, "doxtr_pygments_wcag_level", None, "env")
222
+ add_config_value_if_missing(app, "doxtr_wcag_color_debug", False, "env")
223
+
224
+ app.connect("config-inited", apply_brand_to_config, priority=800)
225
+
226
+ return {
227
+ "version": __version__,
228
+ "parallel_read_safe": True,
229
+ "parallel_write_safe": True,
230
+ }
@@ -0,0 +1,30 @@
1
+ """Shared asset helpers (default Doxtr documentation icons) for all renderers."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+
7
+ ASSETS_DIR = Path(__file__).resolve().parent / "assets"
8
+ DEFAULT_ICON_NAME = "doxtr_icon.png"
9
+ DEFAULT_SMALL_ICON_NAME = "doxtr_icon_small.png"
10
+
11
+
12
+ def get_core_assets_dir() -> Path:
13
+ """Return the shared ``doxtr_theme_core/assets`` directory path."""
14
+ return ASSETS_DIR
15
+
16
+
17
+ def get_core_asset(name: str) -> Path:
18
+ """Return the resolved path to a named asset inside ``doxtr_theme_core/assets``."""
19
+ base = ASSETS_DIR.resolve()
20
+ candidate = (base / name).resolve()
21
+ if candidate != base and base not in candidate.parents:
22
+ raise FileNotFoundError(f"Invalid shared asset path: {name!r}")
23
+ if not candidate.is_file():
24
+ raise FileNotFoundError(f"Shared asset not found: {candidate}")
25
+ return candidate
26
+
27
+
28
+ def get_default_icon_path(*, small: bool = False) -> Path:
29
+ """Return the default Doxtr icon path (``doxtr_icon_small.png`` or ``doxtr_icon.png``)."""
30
+ return get_core_asset(DEFAULT_SMALL_ICON_NAME if small else DEFAULT_ICON_NAME)