doxtr-theme-core 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.
- doxtr_theme_core/__init__.py +230 -0
- doxtr_theme_core/assets/doxtr_icon.png +0 -0
- doxtr_theme_core/assets/doxtr_icon_small.png +0 -0
- doxtr_theme_core/assets.py +30 -0
- doxtr_theme_core/colors.py +1114 -0
- doxtr_theme_core/dark_file_swap.py +253 -0
- doxtr_theme_core/darkmode.py +98 -0
- doxtr_theme_core/directives.py +104 -0
- doxtr_theme_core/fonts.py +450 -0
- doxtr_theme_core/guidance.py +62 -0
- doxtr_theme_core/orchestrator.py +319 -0
- doxtr_theme_core/spec.py +197 -0
- doxtr_theme_core-0.1.0.dist-info/METADATA +36 -0
- doxtr_theme_core-0.1.0.dist-info/RECORD +18 -0
- doxtr_theme_core-0.1.0.dist-info/WHEEL +5 -0
- doxtr_theme_core-0.1.0.dist-info/entry_points.txt +2 -0
- doxtr_theme_core-0.1.0.dist-info/licenses/LICENSE +21 -0
- doxtr_theme_core-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -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
|
+
}
|
|
Binary file
|
|
Binary file
|
|
@@ -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)
|