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.
Files changed (173) hide show
  1. package/README.md +9 -4
  2. package/package.json +2 -2
  3. package/skills/dknowc-official-doc-writer/SKILL.md +17 -8
  4. package/skills/dknowc-official-doc-writer/reference/sample_search_result.md +48 -0
  5. package/skills/dknowc-official-doc-writer/reference/sample_trace_report.html +75 -0
  6. package/skills/dknowc-official-doc-writer/reference/search_intro.md +72 -8
  7. package/skills/dknowc-official-doc-writer/scripts/register.mjs +1 -1
  8. package/skills/dknowc-ppt-assistant/README.md +54 -0
  9. package/skills/dknowc-ppt-assistant/SKILL.md +151 -0
  10. package/skills/dknowc-ppt-assistant/THIRD_PARTY_NOTICES.md +36 -0
  11. package/skills/dknowc-ppt-assistant/official-docs/output/.gitkeep +0 -0
  12. package/skills/dknowc-ppt-assistant/official-docs/search-results/.gitkeep +0 -0
  13. package/skills/dknowc-ppt-assistant/projects/.gitkeep +0 -0
  14. package/skills/dknowc-ppt-assistant/references/content-pack.md +55 -0
  15. package/skills/dknowc-ppt-assistant/references/material_usage.md +51 -0
  16. package/skills/dknowc-ppt-assistant/references/sample_effect.html +89 -0
  17. package/skills/dknowc-ppt-assistant/references/sample_search_result.md +48 -0
  18. package/skills/dknowc-ppt-assistant/references/search_intro.md +79 -0
  19. package/skills/dknowc-ppt-assistant/references/style-presets.md +126 -0
  20. package/skills/dknowc-ppt-assistant/references/svg-authoring.md +81 -0
  21. package/skills/dknowc-ppt-assistant/references/upstream-docs/svg-pipeline.md +842 -0
  22. package/skills/dknowc-ppt-assistant/references/upstream-example/01_cover.svg +28 -0
  23. package/skills/dknowc-ppt-assistant/references/upstream-example/02_quote.svg +38 -0
  24. package/skills/dknowc-ppt-assistant/references/upstream-example/03_origin.svg +96 -0
  25. package/skills/dknowc-ppt-assistant/references/upstream-example/README.md +15 -0
  26. package/skills/dknowc-ppt-assistant/references/upstream-example/design_spec.md +408 -0
  27. package/skills/dknowc-ppt-assistant/references/upstream-example/spec_lock.md +78 -0
  28. package/skills/dknowc-ppt-assistant/scripts/adapt_mcp_result.py +279 -0
  29. package/skills/dknowc-ppt-assistant/scripts/check_release.py +106 -0
  30. package/skills/dknowc-ppt-assistant/scripts/compact_svg_coordinates.py +345 -0
  31. package/skills/dknowc-ppt-assistant/scripts/config.py +707 -0
  32. package/skills/dknowc-ppt-assistant/scripts/console_encoding.py +33 -0
  33. package/skills/dknowc-ppt-assistant/scripts/error_helper.py +434 -0
  34. package/skills/dknowc-ppt-assistant/scripts/finalize_svg.py +507 -0
  35. package/skills/dknowc-ppt-assistant/scripts/hyperlink_contract.py +399 -0
  36. package/skills/dknowc-ppt-assistant/scripts/initialize.py +182 -0
  37. package/skills/dknowc-ppt-assistant/scripts/language_tags.py +283 -0
  38. package/skills/dknowc-ppt-assistant/scripts/mcp_direct.py +158 -0
  39. package/skills/dknowc-ppt-assistant/scripts/native_payloads.py +655 -0
  40. package/skills/dknowc-ppt-assistant/scripts/pptx_animation_presets.json +3440 -0
  41. package/skills/dknowc-ppt-assistant/scripts/pptx_animations.py +3965 -0
  42. package/skills/dknowc-ppt-assistant/scripts/pptx_effects.py +143 -0
  43. package/skills/dknowc-ppt-assistant/scripts/pptx_opc_validation.py +346 -0
  44. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/__init__.py +130 -0
  45. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/LICENSE-APACHE-2.0.txt +202 -0
  46. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/LICENSE-OPEN-XML-SDK-MIT.txt +23 -0
  47. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/NOTICE.md +54 -0
  48. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/presetShapeDefinitions.xml +19898 -0
  49. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/presetShapeSemantics.json +1217 -0
  50. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/shape_type_values.txt +187 -0
  51. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/errors.py +39 -0
  52. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/formula.py +336 -0
  53. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/loader.py +364 -0
  54. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/models.py +201 -0
  55. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/registry.py +270 -0
  56. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/semantic_hash.py +456 -0
  57. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/semantics.py +543 -0
  58. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/xml_safety.py +21 -0
  59. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/__init__.py +21 -0
  60. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/animation_import.py +287 -0
  61. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/chart_to_svg.py +2377 -0
  62. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/chartex_to_svg.py +422 -0
  63. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/color_resolver.py +894 -0
  64. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/converter.py +1143 -0
  65. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/custgeom_to_svg.py +165 -0
  66. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/effect_to_svg.py +410 -0
  67. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/emu_units.py +258 -0
  68. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/fill_to_svg.py +816 -0
  69. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/formula_import.py +611 -0
  70. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/hyperlinks.py +93 -0
  71. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/import_diagnostics.py +37 -0
  72. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/ln_to_svg.py +362 -0
  73. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/normalized_chart_svg.py +1217 -0
  74. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/ooxml_loader.py +506 -0
  75. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/pic_to_svg.py +653 -0
  76. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_authoring.py +894 -0
  77. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_registry_to_svg.py +216 -0
  78. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_svg_markup.py +198 -0
  79. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/prstgeom_to_svg.py +162 -0
  80. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/shape_walker.py +556 -0
  81. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/slide_to_svg.py +2002 -0
  82. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/tbl_to_svg.py +1841 -0
  83. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/transition_import.py +201 -0
  84. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/txbody_to_svg.py +1433 -0
  85. package/skills/dknowc-ppt-assistant/scripts/pptx_transitions.py +3153 -0
  86. package/skills/dknowc-ppt-assistant/scripts/preset_shape_svg.py +450 -0
  87. package/skills/dknowc-ppt-assistant/scripts/project_utils.py +645 -0
  88. package/skills/dknowc-ppt-assistant/scripts/register_key.mjs +183 -0
  89. package/skills/dknowc-ppt-assistant/scripts/register_template.py +1327 -0
  90. package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +1048 -0
  91. package/skills/dknowc-ppt-assistant/scripts/resource_paths.py +282 -0
  92. package/skills/dknowc-ppt-assistant/scripts/shape_boolean_svg.py +189 -0
  93. package/skills/dknowc-ppt-assistant/scripts/slide_roster.py +44 -0
  94. package/skills/dknowc-ppt-assistant/scripts/svg_finalize/__init__.py +12 -0
  95. package/skills/dknowc-ppt-assistant/scripts/svg_finalize/align_embed_images.py +672 -0
  96. package/skills/dknowc-ppt-assistant/scripts/svg_finalize/crop_images.py +370 -0
  97. package/skills/dknowc-ppt-assistant/scripts/svg_finalize/embed_icons.py +564 -0
  98. package/skills/dknowc-ppt-assistant/scripts/svg_finalize/embed_images.py +288 -0
  99. package/skills/dknowc-ppt-assistant/scripts/svg_finalize/fix_image_aspect.py +389 -0
  100. package/skills/dknowc-ppt-assistant/scripts/svg_finalize/flatten_tspan.py +948 -0
  101. package/skills/dknowc-ppt-assistant/scripts/svg_finalize/svg_rect_to_path.py +346 -0
  102. package/skills/dknowc-ppt-assistant/scripts/svg_quality/__init__.py +15 -0
  103. package/skills/dknowc-ppt-assistant/scripts/svg_quality/checker.py +7791 -0
  104. package/skills/dknowc-ppt-assistant/scripts/svg_quality/cli.py +193 -0
  105. package/skills/dknowc-ppt-assistant/scripts/svg_quality/svg_contracts.py +1121 -0
  106. package/skills/dknowc-ppt-assistant/scripts/svg_quality/xml_support.py +35 -0
  107. package/skills/dknowc-ppt-assistant/scripts/svg_quality_checker.py +59 -0
  108. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/__init__.py +37 -0
  109. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/animation_config.py +1622 -0
  110. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/canvas_contract.py +226 -0
  111. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/__init__.py +1 -0
  112. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/context.py +291 -0
  113. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/converter.py +1980 -0
  114. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/elements.py +5272 -0
  115. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/hyperlinks.py +162 -0
  116. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/paths.py +847 -0
  117. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/styles.py +752 -0
  118. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/text_properties.py +796 -0
  119. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/theme_colors.py +283 -0
  120. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/theme_fonts.py +330 -0
  121. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/utils.py +3555 -0
  122. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/geometry_properties.py +140 -0
  123. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/__init__.py +356 -0
  124. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chart_data.py +1449 -0
  125. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chart_style.py +886 -0
  126. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chart_xml.py +1495 -0
  127. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chartex.py +272 -0
  128. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/fallback_hash.py +161 -0
  129. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula.py +243 -0
  130. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_ast.py +592 -0
  131. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_compiler.py +96 -0
  132. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_omml.py +1049 -0
  133. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_parser.py +2181 -0
  134. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_profile.py +739 -0
  135. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_run_properties.py +234 -0
  136. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/inline_formula.py +311 -0
  137. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/marker_attributes.py +182 -0
  138. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/marker_common.py +806 -0
  139. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/marker_status.py +190 -0
  140. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/table.py +1113 -0
  141. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/workbook.py +216 -0
  142. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/__init__.py +1 -0
  143. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/builder.py +6273 -0
  144. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/cli.py +2059 -0
  145. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/dimensions.py +189 -0
  146. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/discovery.py +120 -0
  147. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/media.py +160 -0
  148. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/narration.py +696 -0
  149. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/notes.py +336 -0
  150. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/slide_xml.py +138 -0
  151. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/template_structure.py +3457 -0
  152. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/template_validation.py +1536 -0
  153. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/semantic_markers.py +240 -0
  154. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/shape_boolean.py +1355 -0
  155. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/text_outline.py +1121 -0
  156. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/tspan_flattener.py +64 -0
  157. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/use_expander.py +577 -0
  158. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx.py +21 -0
  159. package/skills/dknowc-ppt-assistant/scripts/trusted_search.py +336 -0
  160. package/skills/dknowc-ppt-assistant/scripts/update_spec.py +404 -0
  161. package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +142 -0
  162. package/skills/dknowc-ppt-assistant/workflows/routing.md +38 -0
  163. package/skills/dknowc-trusted-consulting/SKILL.md +21 -5
  164. package/skills/dknowc-trusted-consulting/reference/consult_intro.md +79 -0
  165. package/skills/dknowc-trusted-consulting/reference/sample_consult_answer.md +31 -0
  166. package/skills/dknowc-trusted-consulting/reference/sample_trace_report.html +76 -0
  167. package/skills/dknowc-trusted-consulting/scripts/register_key.mjs +1 -0
  168. package/skills/dknowc-trusted-search/SKILL.md +30 -2
  169. package/skills/dknowc-trusted-search/reference/sample_search_result.md +33 -0
  170. package/skills/dknowc-trusted-search/reference/sample_trace_report.html +450 -0
  171. package/skills/dknowc-trusted-search/reference/search_intro.md +79 -0
  172. package/skills/dknowc-trusted-search/scripts/register_key.mjs +1 -0
  173. package/src/index.js +7 -2
@@ -0,0 +1,282 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ PPT Master - Shared SVG Resource Helpers
4
+
5
+ Centralizes project-relative resource lookup and nested-SVG closure validation
6
+ used by the checker, finalizer, and SVG-to-PPTX exporter.
7
+
8
+ Usage:
9
+ Imported by scripts; not intended as a standalone CLI.
10
+
11
+ Examples:
12
+ from resource_paths import resolve_external_image_reference
13
+ from resource_paths import svg_image_payload_error
14
+
15
+ Dependencies:
16
+ None
17
+ """
18
+
19
+ from __future__ import annotations
20
+
21
+ import base64
22
+ import binascii
23
+ import re
24
+ from pathlib import Path
25
+ from urllib.parse import unquote, unquote_to_bytes, urlsplit
26
+ from xml.etree import ElementTree as ET
27
+
28
+
29
+ SVG_WORK_DIR_NAMES = frozenset({'svg_output', 'svg_final', 'svg-flat', 'svg_flat'})
30
+ SVG_FINAL_CANDIDATE_PREFIX = '.svg_final.candidate-'
31
+ TEMPLATE_SOURCE_DIR_NAME = 'templates'
32
+ TEMPLATE_SPEC_FILENAME = 'design_spec.md'
33
+ _SVG_NAMESPACE = 'http://www.w3.org/2000/svg'
34
+ _SVG_URL_REFERENCE_RE = re.compile(r'url\(\s*([^)]+?)\s*\)', re.IGNORECASE)
35
+ _SVG_CSS_URL_ATTRIBUTES = frozenset({
36
+ 'background',
37
+ 'background-image',
38
+ 'clip-path',
39
+ 'color-profile',
40
+ 'cursor',
41
+ 'fill',
42
+ 'filter',
43
+ 'marker',
44
+ 'marker-end',
45
+ 'marker-mid',
46
+ 'marker-start',
47
+ 'mask',
48
+ 'stroke',
49
+ 'style',
50
+ })
51
+ _SVG_DIRECT_RESOURCE_ATTRIBUTES = frozenset({'poster', 'src'})
52
+ _SVG_DATA_URI_DEPTH_LIMIT = 8
53
+ _SVG_EXTERNAL_DOCTYPE_RE = re.compile(
54
+ br'<!DOCTYPE\b[^>]*\b(?:PUBLIC|SYSTEM)\b',
55
+ re.IGNORECASE | re.DOTALL,
56
+ )
57
+ _XML_STYLESHEET_HREF_RE = re.compile(
58
+ r'\bhref\s*=\s*([\'"])(.*?)\1',
59
+ re.IGNORECASE | re.DOTALL,
60
+ )
61
+
62
+
63
+ def project_root_for_svg_path(svg_path: Path) -> Path:
64
+ """Infer the project root from an SVG file path or SVG directory path."""
65
+ path = Path(svg_path)
66
+ base = path if path.is_dir() else path.parent
67
+ if (
68
+ base.name in SVG_WORK_DIR_NAMES
69
+ or base.name.startswith(SVG_FINAL_CANDIDATE_PREFIX)
70
+ ):
71
+ return base.parent
72
+ if (
73
+ base.name == TEMPLATE_SOURCE_DIR_NAME
74
+ and (base / TEMPLATE_SPEC_FILENAME).is_file()
75
+ ):
76
+ return base.parent
77
+ return base
78
+
79
+
80
+ def global_icons_dir() -> Path:
81
+ """Return the skill-level icon library directory."""
82
+ return Path(__file__).resolve().parent.parent / 'templates' / 'icons'
83
+
84
+
85
+ def icon_search_dirs_for_project(project_path: Path) -> tuple[Path, Path | None]:
86
+ """Return project-first icon dirs plus the global fallback when needed."""
87
+ global_dir = global_icons_dir()
88
+ project_icons_dir = Path(project_path) / 'icons'
89
+ if project_icons_dir.is_dir():
90
+ return project_icons_dir, global_dir
91
+ return global_dir, None
92
+
93
+
94
+ def icon_search_dirs_for_svg(svg_path: Path) -> tuple[Path, Path | None]:
95
+ """Return icon dirs for an SVG file path or SVG directory path."""
96
+ return icon_search_dirs_for_project(project_root_for_svg_path(svg_path))
97
+
98
+
99
+ def _decode_svg_data_uri(raw: str) -> tuple[bytes | None, str | None]:
100
+ """Decode an SVG data URI; return ``(None, None)`` for other media."""
101
+ value = raw.strip().strip('\'"')
102
+ if not value.lower().startswith('data:'):
103
+ return None, None
104
+ header, separator, payload = value.partition(',')
105
+ media_type = header[5:].split(';', 1)[0].strip().lower()
106
+ if media_type != 'image/svg+xml':
107
+ return None, None
108
+ if not separator:
109
+ return None, 'invalid embedded SVG data URI'
110
+ is_base64 = any(
111
+ token.strip().lower() == 'base64'
112
+ for token in header.split(';')[1:]
113
+ )
114
+ try:
115
+ decoded = (
116
+ base64.b64decode(payload, validate=True)
117
+ if is_base64
118
+ else unquote_to_bytes(payload)
119
+ )
120
+ except (ValueError, binascii.Error):
121
+ return None, 'invalid embedded SVG data URI'
122
+ return decoded, None
123
+
124
+
125
+ def _svg_reference_error(raw: str, depth: int) -> str | None:
126
+ """Return an external or recursively embedded SVG resource error."""
127
+ value = raw.strip().strip('\'"')
128
+ if not value:
129
+ return 'empty resource reference'
130
+ if value.startswith('#'):
131
+ return None
132
+ if not value.lower().startswith('data:'):
133
+ return f'unpackaged external resource {value!r}'
134
+
135
+ nested_svg, decode_error = _decode_svg_data_uri(value)
136
+ if decode_error is not None:
137
+ return decode_error
138
+ if nested_svg is None:
139
+ return None
140
+ if depth >= _SVG_DATA_URI_DEPTH_LIMIT:
141
+ return 'embedded SVG resource nesting exceeds the safety limit'
142
+ nested_error = _svg_image_payload_error(nested_svg, depth + 1)
143
+ if nested_error is None:
144
+ return None
145
+ return f'embedded SVG resource is not closed: {nested_error}'
146
+
147
+
148
+ def _xml_stylesheet_error(raw_bytes: bytes, depth: int) -> str | None:
149
+ """Return an external XML stylesheet processing-instruction error."""
150
+ parser = ET.XMLPullParser(events=('pi',))
151
+ try:
152
+ parser.feed(raw_bytes)
153
+ parser.close()
154
+ except ET.ParseError:
155
+ return None
156
+ for _event, instruction in parser.read_events():
157
+ text = (instruction.text or '').strip()
158
+ if not text.lower().startswith('xml-stylesheet'):
159
+ continue
160
+ match = _XML_STYLESHEET_HREF_RE.search(text)
161
+ if match is None:
162
+ return 'XML stylesheet processing instruction lacks href'
163
+ reference_error = _svg_reference_error(match.group(2), depth)
164
+ if reference_error is not None:
165
+ return f'XML stylesheet is not closed: {reference_error}'
166
+ return None
167
+
168
+
169
+ def _svg_image_payload_error(raw_bytes: bytes, depth: int) -> str | None:
170
+ """Return why one SVG image payload is not a closed packaged resource."""
171
+ if _SVG_EXTERNAL_DOCTYPE_RE.search(raw_bytes):
172
+ return 'unpackaged external XML doctype'
173
+ try:
174
+ root = ET.fromstring(raw_bytes)
175
+ except ET.ParseError as exc:
176
+ return f'invalid SVG XML: {exc}'
177
+ if root.tag != f'{{{_SVG_NAMESPACE}}}svg':
178
+ return 'root must use the SVG namespace'
179
+
180
+ stylesheet_error = _xml_stylesheet_error(raw_bytes, depth)
181
+ if stylesheet_error is not None:
182
+ return stylesheet_error
183
+ for elem in root.iter():
184
+ tag = str(elem.tag).rsplit('}', 1)[-1]
185
+ for raw_name, raw_value in elem.attrib.items():
186
+ name = raw_name.rsplit('}', 1)[-1]
187
+ if name == 'href' and tag != 'a':
188
+ reference_error = _svg_reference_error(raw_value, depth)
189
+ if reference_error is not None:
190
+ return reference_error
191
+ elif name in _SVG_DIRECT_RESOURCE_ATTRIBUTES:
192
+ reference_error = _svg_reference_error(raw_value, depth)
193
+ if reference_error is not None:
194
+ return reference_error
195
+ elif name == 'data' and tag == 'object':
196
+ reference_error = _svg_reference_error(raw_value, depth)
197
+ if reference_error is not None:
198
+ return reference_error
199
+ elif name == 'srcset' and raw_value.strip():
200
+ return 'srcset resource lists are not closed SVG resources'
201
+
202
+ if name not in _SVG_CSS_URL_ATTRIBUTES:
203
+ continue
204
+ for match in _SVG_URL_REFERENCE_RE.finditer(raw_value):
205
+ reference_error = _svg_reference_error(match.group(1), depth)
206
+ if reference_error is not None:
207
+ return f'url() resource is not closed: {reference_error}'
208
+
209
+ if tag != 'style':
210
+ continue
211
+ style_text = ''.join(elem.itertext())
212
+ if re.search(r'@import\b', style_text, flags=re.IGNORECASE):
213
+ return 'unpackaged CSS import'
214
+ for match in _SVG_URL_REFERENCE_RE.finditer(style_text):
215
+ reference_error = _svg_reference_error(match.group(1), depth)
216
+ if reference_error is not None:
217
+ return f'url() resource is not closed: {reference_error}'
218
+ return None
219
+
220
+
221
+ def svg_image_payload_error(raw_bytes: bytes) -> str | None:
222
+ """Return why a nested SVG image is not a closed packaged resource."""
223
+ return _svg_image_payload_error(raw_bytes, 0)
224
+
225
+
226
+ def svg_data_uri_payload_error(raw: str) -> str | None:
227
+ """Return why an inline SVG image data URI is not a closed resource."""
228
+ nested_svg, decode_error = _decode_svg_data_uri(raw)
229
+ if decode_error is not None:
230
+ return decode_error
231
+ if nested_svg is None:
232
+ return None
233
+ nested_error = _svg_image_payload_error(nested_svg, 0)
234
+ if nested_error is None:
235
+ return None
236
+ return f'inline SVG data URI is not closed: {nested_error}'
237
+
238
+
239
+ def external_image_reference_candidates(svg_dir: Path, href: str) -> list[Path]:
240
+ """Return candidate paths for a non-data-URI SVG image href."""
241
+ parsed = urlsplit(href)
242
+ if parsed.scheme and parsed.scheme not in {'file'}:
243
+ return []
244
+ decoded = unquote(
245
+ parsed.path
246
+ if parsed.scheme
247
+ else href.split('?', 1)[0].split('#', 1)[0]
248
+ )
249
+ svg_dir = Path(svg_dir)
250
+ project_root = project_root_for_svg_path(svg_dir).resolve()
251
+ candidates = [
252
+ svg_dir / decoded,
253
+ project_root / decoded,
254
+ project_root / 'images' / decoded,
255
+ project_root / 'templates' / decoded,
256
+ ]
257
+ safe_candidates: list[Path] = []
258
+ for candidate in candidates:
259
+ resolved = candidate.resolve()
260
+ try:
261
+ resolved.relative_to(project_root)
262
+ except ValueError:
263
+ continue
264
+ if resolved not in safe_candidates:
265
+ safe_candidates.append(resolved)
266
+ return safe_candidates
267
+
268
+
269
+ def resolve_external_image_reference(svg_dir: Path, href: str) -> Path | None:
270
+ """Resolve an SVG image href to an existing file, or return None."""
271
+ for candidate in external_image_reference_candidates(svg_dir, href):
272
+ if candidate.is_file():
273
+ return candidate
274
+ return None
275
+
276
+
277
+ def unresolved_external_image_reference_path(svg_dir: Path, href: str) -> Path:
278
+ """Return the first candidate path for diagnostics when resolution fails."""
279
+ candidates = external_image_reference_candidates(svg_dir, href)
280
+ if candidates:
281
+ return candidates[0].resolve()
282
+ return (Path(svg_dir) / href).resolve()
@@ -0,0 +1,189 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ PPT Master - Shape Boolean SVG Fragment Tool
4
+
5
+ Combine closed SVG shapes or resolvable text outlines and print the resulting
6
+ canonical SVG path fragment to stdout. Result geometry is in SVG-root coordinate
7
+ space: replace the operands at their original z-order under the final semantic
8
+ or structured parent, never under the old transformed ancestor. The source SVG
9
+ is read-only; this tool never rewrites the page.
10
+
11
+ Usage:
12
+ python3 scripts/shape_boolean_svg.py render SVG_FILE \
13
+ --operation OPERATION --source ID --source ID --id OUTPUT_ID
14
+
15
+ Examples:
16
+ python3 scripts/shape_boolean_svg.py render slide.svg \
17
+ --operation intersect --source circle --source card --id overlap
18
+ python3 scripts/shape_boolean_svg.py render slide.svg \
19
+ --operation subtract --source body --source cutout --id result \
20
+ --fill "#2563EB" --stroke none
21
+ python3 scripts/shape_boolean_svg.py render cover.svg \
22
+ --operation subtract --source scrim --source chapter-number --id reveal
23
+
24
+ Dependencies:
25
+ skia-pathops, local PPT Master modules, and uharfbuzz for text operands
26
+ """
27
+
28
+ from __future__ import annotations
29
+
30
+ import argparse
31
+ import math
32
+ import sys
33
+ from pathlib import Path
34
+ from typing import Sequence
35
+
36
+ from console_encoding import configure_utf8_stdio
37
+
38
+
39
+ configure_utf8_stdio()
40
+
41
+
42
+ def build_parser() -> argparse.ArgumentParser:
43
+ parser = argparse.ArgumentParser(
44
+ description=(
45
+ "Print the Boolean result of closed SVG shapes or resolvable text "
46
+ "outlines as canonical SVG path fragments in SVG-root coordinate "
47
+ "space. Insert the result at the original z-order under the final "
48
+ "semantic or structured parent, never under the old transformed "
49
+ "ancestor. The source file is never modified."
50
+ ),
51
+ formatter_class=argparse.RawDescriptionHelpFormatter,
52
+ )
53
+ subparsers = parser.add_subparsers(dest="command", required=True)
54
+
55
+ render_parser = subparsers.add_parser(
56
+ "render",
57
+ help="Print SVG-root-coordinate Boolean-result paths to stdout.",
58
+ )
59
+ render_parser.add_argument(
60
+ "svg_file",
61
+ type=Path,
62
+ help="Source SVG containing the operand elements.",
63
+ )
64
+ render_parser.add_argument(
65
+ "--operation",
66
+ required=True,
67
+ choices=("union", "combine", "fragment", "intersect", "subtract"),
68
+ help="PowerPoint-compatible merge-shapes operation.",
69
+ )
70
+ render_parser.add_argument(
71
+ "--source",
72
+ action="append",
73
+ required=True,
74
+ dest="source_ids",
75
+ metavar="ID",
76
+ help=(
77
+ "Operand element id in merge order; repeat at least twice. "
78
+ "The first operand is primary for subtract and style inheritance."
79
+ ),
80
+ )
81
+ render_parser.add_argument(
82
+ "--id",
83
+ required=True,
84
+ dest="output_id",
85
+ help="Stable id for the result, or the base id for fragment results.",
86
+ )
87
+ render_parser.add_argument(
88
+ "--font-dir",
89
+ action="append",
90
+ default=[],
91
+ dest="font_dirs",
92
+ type=Path,
93
+ metavar="PATH",
94
+ help=(
95
+ "Additional font directory for text operands; repeat as needed. "
96
+ "Explicit directories are searched before system font directories."
97
+ ),
98
+ )
99
+ render_parser.add_argument(
100
+ "--fill",
101
+ help="Override the primary shape's solid SVG fill, or use none.",
102
+ )
103
+ render_parser.add_argument(
104
+ "--fill-opacity",
105
+ type=float,
106
+ help="Override fill opacity from 0 to 1.",
107
+ )
108
+ render_parser.add_argument(
109
+ "--stroke",
110
+ help="Override the primary shape's solid SVG stroke, or use none.",
111
+ )
112
+ render_parser.add_argument(
113
+ "--stroke-width",
114
+ type=float,
115
+ help="Override stroke width in SVG page units.",
116
+ )
117
+ render_parser.add_argument(
118
+ "--stroke-opacity",
119
+ type=float,
120
+ help="Override stroke opacity from 0 to 1.",
121
+ )
122
+ return parser
123
+
124
+
125
+ def main(argv: Sequence[str] | None = None) -> int:
126
+ parser = build_parser()
127
+ args = parser.parse_args(argv)
128
+
129
+ try:
130
+ style = _style_from_args(args)
131
+ _validate_render_args(args)
132
+ from svg_to_pptx.shape_boolean import (
133
+ render_boolean_svg_fragments,
134
+ )
135
+
136
+ fragment = render_boolean_svg_fragments(
137
+ args.svg_file,
138
+ operation=args.operation,
139
+ source_ids=args.source_ids,
140
+ output_id=args.output_id,
141
+ style=style or None,
142
+ font_dirs=args.font_dirs,
143
+ )
144
+ except (OSError, RuntimeError, ValueError) as exc:
145
+ print(f"Error: {exc}", file=sys.stderr)
146
+ return 1
147
+
148
+ print(fragment)
149
+ return 0
150
+
151
+
152
+ def _validate_render_args(args: argparse.Namespace) -> None:
153
+ if len(args.source_ids) < 2:
154
+ raise ValueError("--source must be repeated at least twice")
155
+ if len(set(args.source_ids)) != len(args.source_ids):
156
+ raise ValueError("--source ids must be unique")
157
+ if not args.output_id.strip():
158
+ raise ValueError("--id must not be empty")
159
+ for font_dir in args.font_dirs:
160
+ if not font_dir.is_dir():
161
+ raise ValueError(f"--font-dir is not a directory: {font_dir}")
162
+
163
+
164
+ def _style_from_args(args: argparse.Namespace) -> dict[str, str]:
165
+ style: dict[str, str] = {}
166
+ if args.fill is not None:
167
+ style["fill"] = args.fill
168
+ if args.fill_opacity is not None:
169
+ _validate_opacity("--fill-opacity", args.fill_opacity)
170
+ style["fill-opacity"] = str(args.fill_opacity)
171
+ if args.stroke is not None:
172
+ style["stroke"] = args.stroke
173
+ if args.stroke_width is not None:
174
+ if not math.isfinite(args.stroke_width) or args.stroke_width < 0:
175
+ raise ValueError("--stroke-width must be greater than or equal to 0")
176
+ style["stroke-width"] = str(args.stroke_width)
177
+ if args.stroke_opacity is not None:
178
+ _validate_opacity("--stroke-opacity", args.stroke_opacity)
179
+ style["stroke-opacity"] = str(args.stroke_opacity)
180
+ return style
181
+
182
+
183
+ def _validate_opacity(option: str, value: float) -> None:
184
+ if not math.isfinite(value) or not 0 <= value <= 1:
185
+ raise ValueError(f"{option} must be between 0 and 1")
186
+
187
+
188
+ if __name__ == "__main__":
189
+ raise SystemExit(main())
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ PPT Master - Slide Roster Helpers
4
+
5
+ Orders slide SVG filenames by numeric segments for consistent page rosters.
6
+
7
+ Usage:
8
+ Imported by export, validation, preview, animation, and narration tools.
9
+
10
+ Examples:
11
+ discover_slide_svgs(Path("projects/demo/svg_output"))
12
+
13
+ Dependencies:
14
+ None (only uses standard library)
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import re
20
+ from pathlib import Path
21
+
22
+
23
+ _NUMBER_RE = re.compile(r"(\d+)")
24
+
25
+
26
+ def _slide_filename_sort_key(
27
+ path: Path,
28
+ ) -> tuple[tuple[tuple[int, int | str], ...], str]:
29
+ """Order numeric filename segments by value, then break ties by name."""
30
+ name = path.name
31
+ folded = name.casefold()
32
+ segments = tuple(
33
+ (0, int(segment)) if segment.isdigit() else (1, segment)
34
+ for segment in _NUMBER_RE.split(folded)
35
+ )
36
+ return segments, name
37
+
38
+
39
+ def discover_slide_svgs(directory: Path) -> list[Path]:
40
+ """Return direct child SVG files in numeric filename order."""
41
+ return sorted(
42
+ directory.glob("*.svg"),
43
+ key=_slide_filename_sort_key,
44
+ )
@@ -0,0 +1,12 @@
1
+ """svg_finalize — shared self-containment + DrawingML-compat utilities.
2
+
3
+ Used by two consumers:
4
+
5
+ 1. finalize_svg.py — writes svg_output/ → svg_final/ on disk
6
+ 2. svg_to_pptx (use_expander, tspan_flattener) — reuses these modules
7
+ in memory during native pptx conversion
8
+
9
+ Deleting any module here is likely to break native pptx output, not just
10
+ svg_final/. See scripts/docs/svg-pipeline.md for the full per-module consumer
11
+ table.
12
+ """