dknowc-dsh 1.0.3 → 1.1.0
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/README.md +9 -4
- package/package.json +2 -2
- package/skills/dknowc-official-doc-writer/SKILL.md +17 -8
- package/skills/dknowc-official-doc-writer/reference/sample_search_result.md +48 -0
- package/skills/dknowc-official-doc-writer/reference/sample_trace_report.html +75 -0
- package/skills/dknowc-official-doc-writer/reference/search_intro.md +72 -8
- package/skills/dknowc-official-doc-writer/scripts/register.mjs +1 -1
- package/skills/dknowc-ppt-assistant/README.md +54 -0
- package/skills/dknowc-ppt-assistant/SKILL.md +151 -0
- package/skills/dknowc-ppt-assistant/THIRD_PARTY_NOTICES.md +36 -0
- package/skills/dknowc-ppt-assistant/official-docs/output/.gitkeep +0 -0
- package/skills/dknowc-ppt-assistant/official-docs/search-results/.gitkeep +0 -0
- package/skills/dknowc-ppt-assistant/projects/.gitkeep +0 -0
- package/skills/dknowc-ppt-assistant/references/content-pack.md +55 -0
- package/skills/dknowc-ppt-assistant/references/material_usage.md +51 -0
- package/skills/dknowc-ppt-assistant/references/sample_effect.html +89 -0
- package/skills/dknowc-ppt-assistant/references/sample_search_result.md +48 -0
- package/skills/dknowc-ppt-assistant/references/search_intro.md +79 -0
- package/skills/dknowc-ppt-assistant/references/style-presets.md +126 -0
- package/skills/dknowc-ppt-assistant/references/svg-authoring.md +81 -0
- package/skills/dknowc-ppt-assistant/references/upstream-docs/svg-pipeline.md +842 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/01_cover.svg +28 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/02_quote.svg +38 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/03_origin.svg +96 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/README.md +15 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/design_spec.md +408 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/spec_lock.md +78 -0
- package/skills/dknowc-ppt-assistant/scripts/adapt_mcp_result.py +279 -0
- package/skills/dknowc-ppt-assistant/scripts/check_release.py +106 -0
- package/skills/dknowc-ppt-assistant/scripts/compact_svg_coordinates.py +345 -0
- package/skills/dknowc-ppt-assistant/scripts/config.py +707 -0
- package/skills/dknowc-ppt-assistant/scripts/console_encoding.py +33 -0
- package/skills/dknowc-ppt-assistant/scripts/error_helper.py +434 -0
- package/skills/dknowc-ppt-assistant/scripts/finalize_svg.py +507 -0
- package/skills/dknowc-ppt-assistant/scripts/hyperlink_contract.py +399 -0
- package/skills/dknowc-ppt-assistant/scripts/initialize.py +182 -0
- package/skills/dknowc-ppt-assistant/scripts/language_tags.py +283 -0
- package/skills/dknowc-ppt-assistant/scripts/mcp_direct.py +158 -0
- package/skills/dknowc-ppt-assistant/scripts/native_payloads.py +655 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_animation_presets.json +3440 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_animations.py +3965 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_effects.py +143 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_opc_validation.py +346 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/__init__.py +130 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/LICENSE-APACHE-2.0.txt +202 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/LICENSE-OPEN-XML-SDK-MIT.txt +23 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/NOTICE.md +54 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/presetShapeDefinitions.xml +19898 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/presetShapeSemantics.json +1217 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/shape_type_values.txt +187 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/errors.py +39 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/formula.py +336 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/loader.py +364 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/models.py +201 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/registry.py +270 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/semantic_hash.py +456 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/semantics.py +543 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/xml_safety.py +21 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/__init__.py +21 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/animation_import.py +287 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/chart_to_svg.py +2377 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/chartex_to_svg.py +422 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/color_resolver.py +894 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/converter.py +1143 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/custgeom_to_svg.py +165 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/effect_to_svg.py +410 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/emu_units.py +258 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/fill_to_svg.py +816 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/formula_import.py +611 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/hyperlinks.py +93 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/import_diagnostics.py +37 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/ln_to_svg.py +362 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/normalized_chart_svg.py +1217 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/ooxml_loader.py +506 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/pic_to_svg.py +653 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_authoring.py +894 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_registry_to_svg.py +216 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_svg_markup.py +198 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/prstgeom_to_svg.py +162 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/shape_walker.py +556 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/slide_to_svg.py +2002 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/tbl_to_svg.py +1841 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/transition_import.py +201 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/txbody_to_svg.py +1433 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_transitions.py +3153 -0
- package/skills/dknowc-ppt-assistant/scripts/preset_shape_svg.py +450 -0
- package/skills/dknowc-ppt-assistant/scripts/project_utils.py +645 -0
- package/skills/dknowc-ppt-assistant/scripts/register_key.mjs +183 -0
- package/skills/dknowc-ppt-assistant/scripts/register_template.py +1327 -0
- package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +1048 -0
- package/skills/dknowc-ppt-assistant/scripts/resource_paths.py +282 -0
- package/skills/dknowc-ppt-assistant/scripts/shape_boolean_svg.py +189 -0
- package/skills/dknowc-ppt-assistant/scripts/slide_roster.py +44 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/__init__.py +12 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/align_embed_images.py +672 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/crop_images.py +370 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/embed_icons.py +564 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/embed_images.py +288 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/fix_image_aspect.py +389 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/flatten_tspan.py +948 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/svg_rect_to_path.py +346 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/__init__.py +15 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/checker.py +7791 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/cli.py +193 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/svg_contracts.py +1121 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/xml_support.py +35 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality_checker.py +59 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/__init__.py +37 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/animation_config.py +1622 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/canvas_contract.py +226 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/__init__.py +1 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/context.py +291 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/converter.py +1980 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/elements.py +5272 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/hyperlinks.py +162 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/paths.py +847 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/styles.py +752 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/text_properties.py +796 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/theme_colors.py +283 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/theme_fonts.py +330 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/utils.py +3555 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/geometry_properties.py +140 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/__init__.py +356 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chart_data.py +1449 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chart_style.py +886 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chart_xml.py +1495 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chartex.py +272 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/fallback_hash.py +161 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula.py +243 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_ast.py +592 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_compiler.py +96 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_omml.py +1049 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_parser.py +2181 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_profile.py +739 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_run_properties.py +234 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/inline_formula.py +311 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/marker_attributes.py +182 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/marker_common.py +806 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/marker_status.py +190 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/table.py +1113 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/workbook.py +216 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/__init__.py +1 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/builder.py +6273 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/cli.py +2059 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/dimensions.py +189 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/discovery.py +120 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/media.py +160 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/narration.py +696 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/notes.py +336 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/slide_xml.py +138 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/template_structure.py +3457 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/template_validation.py +1536 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/semantic_markers.py +240 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/shape_boolean.py +1355 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/text_outline.py +1121 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/tspan_flattener.py +64 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/use_expander.py +577 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx.py +21 -0
- package/skills/dknowc-ppt-assistant/scripts/trusted_search.py +336 -0
- package/skills/dknowc-ppt-assistant/scripts/update_spec.py +404 -0
- package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +142 -0
- package/skills/dknowc-ppt-assistant/workflows/routing.md +38 -0
- package/skills/dknowc-trusted-consulting/SKILL.md +21 -5
- package/skills/dknowc-trusted-consulting/reference/consult_intro.md +79 -0
- package/skills/dknowc-trusted-consulting/reference/sample_consult_answer.md +31 -0
- package/skills/dknowc-trusted-consulting/reference/sample_trace_report.html +76 -0
- package/skills/dknowc-trusted-consulting/scripts/register_key.mjs +1 -0
- package/skills/dknowc-trusted-search/SKILL.md +30 -2
- package/skills/dknowc-trusted-search/reference/sample_search_result.md +33 -0
- package/skills/dknowc-trusted-search/reference/sample_trace_report.html +450 -0
- package/skills/dknowc-trusted-search/reference/search_intro.md +79 -0
- package/skills/dknowc-trusted-search/scripts/register_key.mjs +1 -0
- package/src/index.js +7 -2
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""Slide dimensions, format detection, EMU conversion, and constants."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from xml.etree import ElementTree as ET
|
|
9
|
+
|
|
10
|
+
from ..canvas_contract import (
|
|
11
|
+
CanvasContractError,
|
|
12
|
+
ProjectViewBox,
|
|
13
|
+
parse_project_viewbox,
|
|
14
|
+
read_project_viewbox,
|
|
15
|
+
require_consistent_project_viewboxes,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
# Import project utility modules
|
|
19
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
20
|
+
try:
|
|
21
|
+
from project_utils import get_project_info
|
|
22
|
+
from config import CANVAS_FORMATS
|
|
23
|
+
except ImportError:
|
|
24
|
+
CANVAS_FORMATS = {
|
|
25
|
+
'ppt169': {'name': 'PPT 16:9', 'dimensions': '1280×720', 'viewbox': '0 0 1280 720'},
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
def get_project_info(path: str) -> dict:
|
|
29
|
+
return {'format': 'unknown', 'name': Path(path).name}
|
|
30
|
+
|
|
31
|
+
# EMU conversion constants
|
|
32
|
+
EMU_PER_INCH = 914400
|
|
33
|
+
EMU_PER_PIXEL = EMU_PER_INCH / 96
|
|
34
|
+
|
|
35
|
+
# XML namespaces
|
|
36
|
+
NAMESPACES = {
|
|
37
|
+
'a': 'http://schemas.openxmlformats.org/drawingml/2006/main',
|
|
38
|
+
'r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
|
|
39
|
+
'p': 'http://schemas.openxmlformats.org/presentationml/2006/main',
|
|
40
|
+
'asvg': 'http://schemas.microsoft.com/office/drawing/2016/SVG/main',
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
# Register namespaces for ElementTree output
|
|
44
|
+
for prefix, uri in NAMESPACES.items():
|
|
45
|
+
ET.register_namespace(prefix, uri)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def get_slide_dimensions(
|
|
49
|
+
canvas_format: str,
|
|
50
|
+
custom_pixels: tuple[int, int] | None = None,
|
|
51
|
+
) -> tuple[int, int]:
|
|
52
|
+
"""Get slide dimensions in EMU units.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
canvas_format: Canvas format key (e.g. 'ppt169').
|
|
56
|
+
custom_pixels: Optional custom pixel dimensions override.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
(width_emu, height_emu) tuple.
|
|
60
|
+
"""
|
|
61
|
+
if custom_pixels:
|
|
62
|
+
width_px, height_px = custom_pixels
|
|
63
|
+
else:
|
|
64
|
+
if canvas_format not in CANVAS_FORMATS:
|
|
65
|
+
canvas_format = 'ppt169'
|
|
66
|
+
|
|
67
|
+
dimensions = CANVAS_FORMATS[canvas_format]['dimensions']
|
|
68
|
+
match = re.match(r'(\d+)[×x](\d+)', dimensions)
|
|
69
|
+
if match:
|
|
70
|
+
width_px = int(match.group(1))
|
|
71
|
+
height_px = int(match.group(2))
|
|
72
|
+
else:
|
|
73
|
+
width_px, height_px = 1280, 720
|
|
74
|
+
|
|
75
|
+
return int(width_px * EMU_PER_PIXEL), int(height_px * EMU_PER_PIXEL)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def get_pixel_dimensions(
|
|
79
|
+
canvas_format: str,
|
|
80
|
+
custom_pixels: tuple[int, int] | None = None,
|
|
81
|
+
) -> tuple[int, int]:
|
|
82
|
+
"""Get canvas pixel dimensions.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
canvas_format: Canvas format key.
|
|
86
|
+
custom_pixels: Optional custom pixel dimensions override.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
(width_px, height_px) tuple.
|
|
90
|
+
"""
|
|
91
|
+
if custom_pixels:
|
|
92
|
+
return custom_pixels
|
|
93
|
+
|
|
94
|
+
if canvas_format not in CANVAS_FORMATS:
|
|
95
|
+
canvas_format = 'ppt169'
|
|
96
|
+
|
|
97
|
+
dimensions = CANVAS_FORMATS[canvas_format]['dimensions']
|
|
98
|
+
match = re.match(r'(\d+)[×x](\d+)', dimensions)
|
|
99
|
+
if match:
|
|
100
|
+
return int(match.group(1)), int(match.group(2))
|
|
101
|
+
return 1280, 720
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def get_viewbox_dimensions(svg_path: Path) -> tuple[float, float]:
|
|
105
|
+
"""Extract pixel dimensions from SVG viewBox.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
svg_path: Path to the SVG file.
|
|
109
|
+
|
|
110
|
+
Returns:
|
|
111
|
+
(width, height) in SVG pixels.
|
|
112
|
+
|
|
113
|
+
Raises:
|
|
114
|
+
CanvasContractError: The root canvas is missing or invalid.
|
|
115
|
+
"""
|
|
116
|
+
return read_project_viewbox(svg_path).pixel_dimensions
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def detect_format_from_svg(svg_path: Path) -> str | None:
|
|
120
|
+
"""Detect canvas format from an SVG file's viewBox.
|
|
121
|
+
|
|
122
|
+
Args:
|
|
123
|
+
svg_path: Path to the SVG file.
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
Canvas format key (e.g. 'ppt169'), or None if not detected.
|
|
127
|
+
"""
|
|
128
|
+
viewbox = read_project_viewbox(svg_path)
|
|
129
|
+
for fmt_key, fmt_info in CANVAS_FORMATS.items():
|
|
130
|
+
expected = parse_project_viewbox(
|
|
131
|
+
fmt_info['viewbox'],
|
|
132
|
+
context=f"registered canvas {fmt_key!r}",
|
|
133
|
+
)
|
|
134
|
+
if viewbox == expected:
|
|
135
|
+
return fmt_key
|
|
136
|
+
return None
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def resolve_svg_canvas(
|
|
140
|
+
svg_files: list[Path],
|
|
141
|
+
*,
|
|
142
|
+
canvas_format: str | None = None,
|
|
143
|
+
expected_viewbox: str | None = None,
|
|
144
|
+
) -> tuple[ProjectViewBox, str | None]:
|
|
145
|
+
"""Resolve one fail-closed canvas for every public/internal SVG."""
|
|
146
|
+
format_viewbox: str | None = None
|
|
147
|
+
if canvas_format is not None:
|
|
148
|
+
if canvas_format not in CANVAS_FORMATS:
|
|
149
|
+
raise CanvasContractError(f"Unsupported canvas format: {canvas_format}")
|
|
150
|
+
format_viewbox = CANVAS_FORMATS[canvas_format]['viewbox']
|
|
151
|
+
|
|
152
|
+
if expected_viewbox is not None and format_viewbox is not None:
|
|
153
|
+
locked = parse_project_viewbox(
|
|
154
|
+
expected_viewbox,
|
|
155
|
+
context="locked canvas viewBox",
|
|
156
|
+
)
|
|
157
|
+
selected = parse_project_viewbox(
|
|
158
|
+
format_viewbox,
|
|
159
|
+
context=f"canvas format {canvas_format!r}",
|
|
160
|
+
)
|
|
161
|
+
if locked != selected:
|
|
162
|
+
raise CanvasContractError(
|
|
163
|
+
f"canvas format {canvas_format!r} ({selected.canonical}) conflicts "
|
|
164
|
+
f"with the locked canvas ({locked.canonical})"
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
required = expected_viewbox if expected_viewbox is not None else format_viewbox
|
|
168
|
+
if expected_viewbox is not None:
|
|
169
|
+
expected_label = "the locked canvas"
|
|
170
|
+
elif canvas_format is not None:
|
|
171
|
+
expected_label = f"canvas format {canvas_format!r}"
|
|
172
|
+
else:
|
|
173
|
+
expected_label = "the first SVG canvas"
|
|
174
|
+
viewbox = require_consistent_project_viewboxes(
|
|
175
|
+
svg_files,
|
|
176
|
+
expected_viewbox=required,
|
|
177
|
+
expected_label=expected_label,
|
|
178
|
+
)
|
|
179
|
+
detected_format = canvas_format
|
|
180
|
+
if detected_format is None:
|
|
181
|
+
for fmt_key, fmt_info in CANVAS_FORMATS.items():
|
|
182
|
+
registered = parse_project_viewbox(
|
|
183
|
+
fmt_info['viewbox'],
|
|
184
|
+
context=f"registered canvas {fmt_key!r}",
|
|
185
|
+
)
|
|
186
|
+
if viewbox == registered:
|
|
187
|
+
detected_format = fmt_key
|
|
188
|
+
break
|
|
189
|
+
return viewbox, detected_format
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""Find SVG and notes files in a project directory."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from slide_roster import discover_slide_svgs
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class NotesFileReadError(RuntimeError):
|
|
12
|
+
"""Report a matched notes file that cannot be decoded or read."""
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def find_svg_files(
|
|
16
|
+
project_path: Path,
|
|
17
|
+
source: str = 'output',
|
|
18
|
+
*,
|
|
19
|
+
allow_fallback: bool = True,
|
|
20
|
+
) -> tuple[list[Path], str]:
|
|
21
|
+
"""Find SVG files in the project.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
project_path: Project directory path.
|
|
25
|
+
source: SVG source directory alias or name.
|
|
26
|
+
- 'output': svg_output (hand-authored source; native default)
|
|
27
|
+
- 'final': svg_final (post-processed preview; diagnostic input)
|
|
28
|
+
- or any subdirectory name
|
|
29
|
+
allow_fallback: Try svg_output and then the project root when the
|
|
30
|
+
requested directory is missing.
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
(list_of_svg_files, actual_directory_name) tuple.
|
|
34
|
+
"""
|
|
35
|
+
dir_map = {
|
|
36
|
+
'output': 'svg_output',
|
|
37
|
+
'final': 'svg_final',
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
dir_name = dir_map.get(source, source)
|
|
41
|
+
svg_dir = project_path / dir_name
|
|
42
|
+
|
|
43
|
+
if not svg_dir.exists():
|
|
44
|
+
if not allow_fallback:
|
|
45
|
+
return [], dir_name
|
|
46
|
+
print(f" Warning: {dir_name} directory does not exist, trying svg_output")
|
|
47
|
+
dir_name = 'svg_output'
|
|
48
|
+
svg_dir = project_path / dir_name
|
|
49
|
+
|
|
50
|
+
if not svg_dir.exists():
|
|
51
|
+
if project_path.is_dir():
|
|
52
|
+
svg_dir = project_path
|
|
53
|
+
dir_name = project_path.name
|
|
54
|
+
else:
|
|
55
|
+
return [], ''
|
|
56
|
+
|
|
57
|
+
return discover_slide_svgs(svg_dir), dir_name
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def find_notes_files(
|
|
61
|
+
project_path: Path,
|
|
62
|
+
svg_files: list[Path] | None = None,
|
|
63
|
+
) -> dict[str, str]:
|
|
64
|
+
"""Find notes files and map them to SVG files.
|
|
65
|
+
|
|
66
|
+
Supports two matching modes (mixed matching supported):
|
|
67
|
+
1. Match by filename (priority): notes/01_cover.md -> 01_cover.svg
|
|
68
|
+
2. Match by index (backward compatible): notes/slide01.md -> 1st SVG
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
project_path: Project directory path.
|
|
72
|
+
svg_files: SVG file list (for filename matching).
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
Dict mapping SVG filename stem to notes content.
|
|
76
|
+
"""
|
|
77
|
+
notes_dir = project_path / 'notes'
|
|
78
|
+
notes: dict[str, str] = {}
|
|
79
|
+
|
|
80
|
+
if not notes_dir.exists():
|
|
81
|
+
return notes
|
|
82
|
+
|
|
83
|
+
svg_stems_mapping: dict[str, int] = {}
|
|
84
|
+
svg_index_mapping: dict[int, str] = {}
|
|
85
|
+
if svg_files:
|
|
86
|
+
for i, svg_path in enumerate(svg_files, 1):
|
|
87
|
+
svg_stems_mapping[svg_path.stem] = i
|
|
88
|
+
svg_index_mapping[i] = svg_path.stem
|
|
89
|
+
|
|
90
|
+
for notes_file in notes_dir.glob('*.md'):
|
|
91
|
+
stem = notes_file.stem
|
|
92
|
+
|
|
93
|
+
# Try index-based matching (backward compat with slide01.md format).
|
|
94
|
+
match = re.search(r'slide[_]?(\d+)', stem)
|
|
95
|
+
mapped_stem = (
|
|
96
|
+
svg_index_mapping.get(int(match.group(1)))
|
|
97
|
+
if match
|
|
98
|
+
else None
|
|
99
|
+
)
|
|
100
|
+
filename_match = stem in svg_stems_mapping
|
|
101
|
+
if mapped_stem is None and not filename_match:
|
|
102
|
+
continue
|
|
103
|
+
|
|
104
|
+
try:
|
|
105
|
+
content = notes_file.read_text(encoding='utf-8').strip()
|
|
106
|
+
except (OSError, UnicodeError) as exc:
|
|
107
|
+
raise NotesFileReadError(
|
|
108
|
+
f"Cannot read matched notes file {notes_file}: {exc}"
|
|
109
|
+
) from exc
|
|
110
|
+
if not content:
|
|
111
|
+
continue
|
|
112
|
+
|
|
113
|
+
if mapped_stem:
|
|
114
|
+
notes[mapped_stem] = content
|
|
115
|
+
|
|
116
|
+
# Filename-based matching overrides index-based matching.
|
|
117
|
+
if filename_match:
|
|
118
|
+
notes[stem] = content
|
|
119
|
+
|
|
120
|
+
return notes
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"""SVG to PNG conversion for Office compatibility mode."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import shutil
|
|
7
|
+
import tempfile
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
# SVG to PNG library detection
|
|
11
|
+
# Prefer CairoSVG (better quality), fall back to svglib
|
|
12
|
+
PNG_RENDERER: str | None = None
|
|
13
|
+
|
|
14
|
+
try:
|
|
15
|
+
import cairosvg
|
|
16
|
+
PNG_RENDERER = 'cairosvg'
|
|
17
|
+
except (ImportError, OSError):
|
|
18
|
+
try:
|
|
19
|
+
from svglib.svglib import svg2rlg
|
|
20
|
+
from reportlab.graphics import renderPM
|
|
21
|
+
PNG_RENDERER = 'svglib'
|
|
22
|
+
except (ImportError, OSError):
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def get_png_renderer_info() -> tuple[str | None, str, str | None]:
|
|
27
|
+
"""Get PNG renderer status information.
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
(renderer_name, status_text, install_hint) tuple.
|
|
31
|
+
"""
|
|
32
|
+
if PNG_RENDERER == 'cairosvg':
|
|
33
|
+
return ('cairosvg', '(full gradient/filter support)', None)
|
|
34
|
+
elif PNG_RENDERER == 'svglib':
|
|
35
|
+
return ('svglib', '(some gradients may be lost)',
|
|
36
|
+
'Install cairosvg for better results: pip install cairosvg')
|
|
37
|
+
else:
|
|
38
|
+
return (None, '(not installed)',
|
|
39
|
+
'Install via: pip install cairosvg or pip install svglib reportlab')
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def convert_svg_to_png(
|
|
43
|
+
svg_path: Path,
|
|
44
|
+
png_path: Path,
|
|
45
|
+
width: int | None = None,
|
|
46
|
+
height: int | None = None,
|
|
47
|
+
) -> bool:
|
|
48
|
+
"""Convert SVG to PNG using the available renderer.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
svg_path: SVG file path.
|
|
52
|
+
png_path: Output PNG file path.
|
|
53
|
+
width: Output width in pixels.
|
|
54
|
+
height: Output height in pixels.
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
Whether the conversion was successful.
|
|
58
|
+
"""
|
|
59
|
+
if PNG_RENDERER is None:
|
|
60
|
+
return False
|
|
61
|
+
|
|
62
|
+
try:
|
|
63
|
+
if PNG_RENDERER == 'cairosvg':
|
|
64
|
+
cairosvg.svg2png(
|
|
65
|
+
url=str(svg_path),
|
|
66
|
+
write_to=str(png_path),
|
|
67
|
+
output_width=width,
|
|
68
|
+
output_height=height,
|
|
69
|
+
)
|
|
70
|
+
return True
|
|
71
|
+
|
|
72
|
+
elif PNG_RENDERER == 'svglib':
|
|
73
|
+
drawing = svg2rlg(str(svg_path))
|
|
74
|
+
if drawing is None:
|
|
75
|
+
print(f" Warning: Unable to parse SVG ({svg_path.name})")
|
|
76
|
+
return False
|
|
77
|
+
renderPM.drawToFile(
|
|
78
|
+
drawing,
|
|
79
|
+
str(png_path),
|
|
80
|
+
fmt="PNG",
|
|
81
|
+
configPIL={'quality': 95},
|
|
82
|
+
)
|
|
83
|
+
return True
|
|
84
|
+
|
|
85
|
+
except Exception as e:
|
|
86
|
+
print(f" Warning: SVG to PNG conversion failed ({svg_path.name}): {e}")
|
|
87
|
+
return False
|
|
88
|
+
|
|
89
|
+
return False
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _cache_key(svg_path: Path, width: int | None, height: int | None) -> str:
|
|
93
|
+
h = hashlib.sha256()
|
|
94
|
+
with open(svg_path, 'rb') as f:
|
|
95
|
+
for chunk in iter(lambda: f.read(65536), b''):
|
|
96
|
+
h.update(chunk)
|
|
97
|
+
return f"{h.hexdigest()}_{width or 0}x{height or 0}_{PNG_RENDERER or 'none'}"
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def convert_svg_to_png_cached(
|
|
101
|
+
svg_path: Path,
|
|
102
|
+
png_path: Path,
|
|
103
|
+
width: int | None = None,
|
|
104
|
+
height: int | None = None,
|
|
105
|
+
cache_dir: Path | None = None,
|
|
106
|
+
) -> bool:
|
|
107
|
+
"""Cache-aware SVG→PNG conversion.
|
|
108
|
+
|
|
109
|
+
Returns True on success (cache hit or fresh render). Cache key bakes in
|
|
110
|
+
SVG content hash + size + renderer name; switching renderers invalidates
|
|
111
|
+
naturally. Failures are never cached.
|
|
112
|
+
"""
|
|
113
|
+
if cache_dir is None:
|
|
114
|
+
return convert_svg_to_png(svg_path, png_path, width, height)
|
|
115
|
+
|
|
116
|
+
if PNG_RENDERER is None:
|
|
117
|
+
return False
|
|
118
|
+
|
|
119
|
+
try:
|
|
120
|
+
key = _cache_key(svg_path, width, height)
|
|
121
|
+
except OSError as e:
|
|
122
|
+
print(f" Warning: Failed to hash SVG ({svg_path.name}): {e}")
|
|
123
|
+
return convert_svg_to_png(svg_path, png_path, width, height)
|
|
124
|
+
|
|
125
|
+
cached = cache_dir / f"{key}.png"
|
|
126
|
+
if cached.is_file():
|
|
127
|
+
try:
|
|
128
|
+
shutil.copy(cached, png_path)
|
|
129
|
+
return True
|
|
130
|
+
except OSError as e:
|
|
131
|
+
print(f" Warning: Cache copy failed, re-rendering ({svg_path.name}): {e}")
|
|
132
|
+
|
|
133
|
+
cache_dir.mkdir(parents=True, exist_ok=True)
|
|
134
|
+
tmp_fd, tmp_name = tempfile.mkstemp(suffix='.png', dir=str(cache_dir))
|
|
135
|
+
tmp_path = Path(tmp_name)
|
|
136
|
+
import os
|
|
137
|
+
os.close(tmp_fd)
|
|
138
|
+
|
|
139
|
+
ok = convert_svg_to_png(svg_path, tmp_path, width, height)
|
|
140
|
+
if not ok:
|
|
141
|
+
try:
|
|
142
|
+
tmp_path.unlink()
|
|
143
|
+
except OSError:
|
|
144
|
+
pass
|
|
145
|
+
return False
|
|
146
|
+
|
|
147
|
+
try:
|
|
148
|
+
os.replace(tmp_path, cached)
|
|
149
|
+
except OSError:
|
|
150
|
+
try:
|
|
151
|
+
tmp_path.unlink()
|
|
152
|
+
except OSError:
|
|
153
|
+
pass
|
|
154
|
+
|
|
155
|
+
try:
|
|
156
|
+
shutil.copy(cached, png_path)
|
|
157
|
+
return True
|
|
158
|
+
except OSError as e:
|
|
159
|
+
print(f" Warning: Cache copy failed ({svg_path.name}): {e}")
|
|
160
|
+
return False
|