@blackbelt-technology/pi-dashboard-document-converter 0.5.4
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.
- package/.pi/skills/document-converter/SKILL.md +79 -0
- package/README.md +106 -0
- package/engine/.dockerignore +4 -0
- package/engine/Dockerfile +75 -0
- package/engine/IMAGE_VERSION +1 -0
- package/engine/README.md +65 -0
- package/engine/VENDOR.md +40 -0
- package/engine/build-image.sh +29 -0
- package/engine/document_converter/LICENSE +21 -0
- package/engine/document_converter/__init__.py +365 -0
- package/engine/document_converter/__main__.py +5 -0
- package/engine/document_converter/asciidoc_converter.py +534 -0
- package/engine/document_converter/cli.py +751 -0
- package/engine/document_converter/code_renderer.py +356 -0
- package/engine/document_converter/converter.py +928 -0
- package/engine/document_converter/cover_page.py +448 -0
- package/engine/document_converter/diagram_resizer.py +311 -0
- package/engine/document_converter/diagram_sizing.py +357 -0
- package/engine/document_converter/docx_reader.py +627 -0
- package/engine/document_converter/field_updater.py +277 -0
- package/engine/document_converter/font_manager.py +850 -0
- package/engine/document_converter/frontmatter_parser.py +644 -0
- package/engine/document_converter/graphviz_renderer.py +354 -0
- package/engine/document_converter/image_extractor.py +281 -0
- package/engine/document_converter/image_style.py +237 -0
- package/engine/document_converter/logo_manager.py +1021 -0
- package/engine/document_converter/manifest_manager.py +288 -0
- package/engine/document_converter/mermaid_renderer.py +371 -0
- package/engine/document_converter/meta_mapper.py +398 -0
- package/engine/document_converter/pandoc_styles.py +222 -0
- package/engine/document_converter/pdf_converter.py +735 -0
- package/engine/document_converter/pdf_server.py +283 -0
- package/engine/document_converter/plantuml_renderer.py +460 -0
- package/engine/document_converter/plantuml_server.py +273 -0
- package/engine/document_converter/pyproject.toml +80 -0
- package/engine/document_converter/round_trip.py +312 -0
- package/engine/document_converter/spacing_applier.py +332 -0
- package/engine/document_converter/spacing_config.py +323 -0
- package/engine/document_converter/style_extractor.py +420 -0
- package/engine/document_converter/svg_embedder.py +294 -0
- package/engine/document_converter/system_variables.py +158 -0
- package/engine/document_converter/table_formatter.py +450 -0
- package/engine/document_converter/template_extractor.py +1334 -0
- package/engine/document_converter/template_manager.py +427 -0
- package/engine/document_converter/textbox_extractor.py +551 -0
- package/engine/document_converter/toc_generator.py +559 -0
- package/engine/document_converter/toc_style.py +290 -0
- package/engine/document_converter/tree_renderer.py +328 -0
- package/engine/document_converter/utils.py +134 -0
- package/engine/document_converter/variable_manager.py +394 -0
- package/engine/engine_cli.py +371 -0
- package/engine/frontmatter_filler/doc-meta.sample.yaml +106 -0
- package/engine/frontmatter_filler/fill.py +517 -0
- package/engine/markdown_table_profiler/profile.py +442 -0
- package/engine/nano-banana-styles.yaml +59 -0
- package/engine/tests/test_styled_diagrams.py +109 -0
- package/package.json +32 -0
- package/src/__tests__/engine.test.ts +72 -0
- package/src/__tests__/facade.test.ts +120 -0
- package/src/__tests__/integration.test.ts +101 -0
- package/src/__tests__/ocr.test.ts +34 -0
- package/src/__tests__/provenance.test.ts +89 -0
- package/src/__tests__/routing.test.ts +40 -0
- package/src/engine.ts +187 -0
- package/src/errors.ts +43 -0
- package/src/index.ts +179 -0
- package/src/ocr.ts +43 -0
- package/src/provenance.ts +79 -0
- package/src/routing.ts +49 -0
- package/src/schema.json +69 -0
- package/src/schema.ts +107 -0
- package/src/types.ts +90 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"""Image style configuration module.
|
|
2
|
+
|
|
3
|
+
Provides dataclasses and functions for configuring image positioning and sizing.
|
|
4
|
+
"""
|
|
5
|
+
import re
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class ImageStyleConfig:
|
|
12
|
+
"""Configuration for image styling.
|
|
13
|
+
|
|
14
|
+
Attributes:
|
|
15
|
+
position: Image position (left, center, right, stretch).
|
|
16
|
+
width: Width specification (pixels, percentage, or 'original').
|
|
17
|
+
height: Height specification (pixels, percentage, or 'original').
|
|
18
|
+
wrap_distance: Distance for text wrapping in points.
|
|
19
|
+
alt: Alternative text for the image.
|
|
20
|
+
caption: Caption text for the image.
|
|
21
|
+
"""
|
|
22
|
+
position: str = "center" # left, center, right, stretch
|
|
23
|
+
width: Optional[str] = None # e.g., "400px", "80%", "original"
|
|
24
|
+
height: Optional[str] = None # e.g., "300px", "60%", "original"
|
|
25
|
+
wrap_distance: int = 12 # Points
|
|
26
|
+
alt: Optional[str] = None
|
|
27
|
+
caption: Optional[str] = None
|
|
28
|
+
|
|
29
|
+
@classmethod
|
|
30
|
+
def from_dict(cls, style_dict: Dict[str, Any]) -> 'ImageStyleConfig':
|
|
31
|
+
"""Create ImageStyleConfig from a dictionary.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
style_dict: Dictionary with style properties.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
ImageStyleConfig with values from dict.
|
|
38
|
+
"""
|
|
39
|
+
return cls(
|
|
40
|
+
position=style_dict.get('position', 'center'),
|
|
41
|
+
width=style_dict.get('width'),
|
|
42
|
+
height=style_dict.get('height'),
|
|
43
|
+
wrap_distance=style_dict.get('wrap_distance', 12),
|
|
44
|
+
alt=style_dict.get('alt'),
|
|
45
|
+
caption=style_dict.get('caption'),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
def merge(self, override: 'ImageStyleConfig') -> 'ImageStyleConfig':
|
|
49
|
+
"""Merge this config with an override config.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
override: ImageStyleConfig with override values.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
New ImageStyleConfig with merged values.
|
|
56
|
+
"""
|
|
57
|
+
default = ImageStyleConfig()
|
|
58
|
+
return ImageStyleConfig(
|
|
59
|
+
position=override.position if override.position != default.position else self.position,
|
|
60
|
+
width=override.width if override.width is not None else self.width,
|
|
61
|
+
height=override.height if override.height is not None else self.height,
|
|
62
|
+
wrap_distance=override.wrap_distance if override.wrap_distance != default.wrap_distance else self.wrap_distance,
|
|
63
|
+
alt=override.alt if override.alt is not None else self.alt,
|
|
64
|
+
caption=override.caption if override.caption is not None else self.caption,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# Default image style configuration
|
|
69
|
+
DEFAULT_IMAGE_STYLE = ImageStyleConfig()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def parse_dimension(value: str, container_width: int = 0, original_dim: int = 0) -> Optional[int]:
|
|
73
|
+
"""Parse a dimension specification into pixels.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
value: Dimension string (e.g., "400px", "80%", "original").
|
|
77
|
+
container_width: Container width for percentage calculations.
|
|
78
|
+
original_dim: Original dimension for 'original' keyword.
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
Dimension in pixels, or None if invalid.
|
|
82
|
+
"""
|
|
83
|
+
if value is None:
|
|
84
|
+
return None
|
|
85
|
+
|
|
86
|
+
value = str(value).strip().lower()
|
|
87
|
+
|
|
88
|
+
if value == 'original':
|
|
89
|
+
return original_dim if original_dim > 0 else None
|
|
90
|
+
|
|
91
|
+
# Percentage
|
|
92
|
+
if value.endswith('%'):
|
|
93
|
+
try:
|
|
94
|
+
percent = float(value[:-1])
|
|
95
|
+
if container_width > 0:
|
|
96
|
+
return int(container_width * percent / 100)
|
|
97
|
+
except ValueError:
|
|
98
|
+
pass
|
|
99
|
+
return None
|
|
100
|
+
|
|
101
|
+
# Pixels
|
|
102
|
+
if value.endswith('px'):
|
|
103
|
+
try:
|
|
104
|
+
return int(value[:-2])
|
|
105
|
+
except ValueError:
|
|
106
|
+
pass
|
|
107
|
+
return None
|
|
108
|
+
|
|
109
|
+
# Plain number (assume pixels)
|
|
110
|
+
try:
|
|
111
|
+
return int(float(value))
|
|
112
|
+
except ValueError:
|
|
113
|
+
pass
|
|
114
|
+
|
|
115
|
+
return None
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def calculate_dimensions(
|
|
119
|
+
original_width: int,
|
|
120
|
+
original_height: int,
|
|
121
|
+
target_width: Optional[int],
|
|
122
|
+
target_height: Optional[int]
|
|
123
|
+
) -> Tuple[int, int]:
|
|
124
|
+
"""Calculate final dimensions preserving aspect ratio.
|
|
125
|
+
|
|
126
|
+
Args:
|
|
127
|
+
original_width: Original image width.
|
|
128
|
+
original_height: Original image height.
|
|
129
|
+
target_width: Target width (or None for auto).
|
|
130
|
+
target_height: Target height (or None for auto).
|
|
131
|
+
|
|
132
|
+
Returns:
|
|
133
|
+
Tuple of (width, height) in pixels.
|
|
134
|
+
"""
|
|
135
|
+
if original_width <= 0 or original_height <= 0:
|
|
136
|
+
return (target_width or 0, target_height or 0)
|
|
137
|
+
|
|
138
|
+
aspect_ratio = original_width / original_height
|
|
139
|
+
|
|
140
|
+
# Both specified - use as-is
|
|
141
|
+
if target_width and target_height:
|
|
142
|
+
return (target_width, target_height)
|
|
143
|
+
|
|
144
|
+
# Only width specified - calculate height
|
|
145
|
+
if target_width:
|
|
146
|
+
return (target_width, int(target_width / aspect_ratio))
|
|
147
|
+
|
|
148
|
+
# Only height specified - calculate width
|
|
149
|
+
if target_height:
|
|
150
|
+
return (int(target_height * aspect_ratio), target_height)
|
|
151
|
+
|
|
152
|
+
# Neither specified - use original
|
|
153
|
+
return (original_width, original_height)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def parse_inline_image_style(img_ref: str) -> Optional[ImageStyleConfig]:
|
|
157
|
+
"""Parse inline image style from markdown image syntax.
|
|
158
|
+
|
|
159
|
+
Supports syntax like: {position=center width=400px}
|
|
160
|
+
|
|
161
|
+
Args:
|
|
162
|
+
img_ref: The image reference string.
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
ImageStyleConfig if style attributes found, None otherwise.
|
|
166
|
+
"""
|
|
167
|
+
# Look for style block at end: {key=value key=value}
|
|
168
|
+
match = re.search(r'\{([^}]+)\}\s*$', img_ref)
|
|
169
|
+
if not match:
|
|
170
|
+
return None
|
|
171
|
+
|
|
172
|
+
style_str = match.group(1)
|
|
173
|
+
style_dict: Dict[str, Any] = {}
|
|
174
|
+
|
|
175
|
+
# Parse key=value pairs
|
|
176
|
+
for pair in re.findall(r'(\w+)=([^\s}]+)', style_str):
|
|
177
|
+
key, value = pair
|
|
178
|
+
style_dict[key] = value
|
|
179
|
+
|
|
180
|
+
if style_dict:
|
|
181
|
+
return ImageStyleConfig.from_dict(style_dict)
|
|
182
|
+
return None
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def parse_image_style_block(content: str) -> List[Tuple[ImageStyleConfig, int]]:
|
|
186
|
+
"""Parse image-style code blocks from content.
|
|
187
|
+
|
|
188
|
+
Finds HTML comments in format: <!-- image-style: key=value, key=value -->
|
|
189
|
+
|
|
190
|
+
Args:
|
|
191
|
+
content: The document content to parse.
|
|
192
|
+
|
|
193
|
+
Returns:
|
|
194
|
+
List of tuples (ImageStyleConfig, position) for each style block found.
|
|
195
|
+
"""
|
|
196
|
+
blocks = []
|
|
197
|
+
|
|
198
|
+
# Pattern to match image-style comments
|
|
199
|
+
pattern = r'<!--\s*image-style:\s*(.+?)\s*-->'
|
|
200
|
+
|
|
201
|
+
for match in re.finditer(pattern, content):
|
|
202
|
+
style_str = match.group(1)
|
|
203
|
+
position = match.start()
|
|
204
|
+
|
|
205
|
+
# Parse key=value pairs
|
|
206
|
+
style_dict: Dict[str, Any] = {}
|
|
207
|
+
for pair in re.findall(r'(\w+)=([^,\s]+)', style_str):
|
|
208
|
+
key, value = pair
|
|
209
|
+
# Convert types
|
|
210
|
+
if value.lower() == 'true':
|
|
211
|
+
style_dict[key] = True
|
|
212
|
+
elif value.lower() == 'false':
|
|
213
|
+
style_dict[key] = False
|
|
214
|
+
elif value.isdigit():
|
|
215
|
+
style_dict[key] = int(value)
|
|
216
|
+
else:
|
|
217
|
+
style_dict[key] = value
|
|
218
|
+
|
|
219
|
+
config = ImageStyleConfig.from_dict(style_dict)
|
|
220
|
+
blocks.append((config, position))
|
|
221
|
+
|
|
222
|
+
return blocks
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def extract_image_style(frontmatter: Dict[str, Any]) -> Optional[ImageStyleConfig]:
|
|
226
|
+
"""Extract image style configuration from frontmatter.
|
|
227
|
+
|
|
228
|
+
Args:
|
|
229
|
+
frontmatter: Parsed frontmatter dictionary.
|
|
230
|
+
|
|
231
|
+
Returns:
|
|
232
|
+
ImageStyleConfig if image_style is present, None otherwise.
|
|
233
|
+
"""
|
|
234
|
+
image_style_dict = frontmatter.get('image_style')
|
|
235
|
+
if image_style_dict and isinstance(image_style_dict, dict):
|
|
236
|
+
return ImageStyleConfig.from_dict(image_style_dict)
|
|
237
|
+
return None
|