dknowc-dsh 1.0.4 → 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 (158) hide show
  1. package/README.md +9 -4
  2. package/package.json +2 -2
  3. package/skills/dknowc-ppt-assistant/README.md +54 -0
  4. package/skills/dknowc-ppt-assistant/SKILL.md +151 -0
  5. package/skills/dknowc-ppt-assistant/THIRD_PARTY_NOTICES.md +36 -0
  6. package/skills/dknowc-ppt-assistant/official-docs/output/.gitkeep +0 -0
  7. package/skills/dknowc-ppt-assistant/official-docs/search-results/.gitkeep +0 -0
  8. package/skills/dknowc-ppt-assistant/projects/.gitkeep +0 -0
  9. package/skills/dknowc-ppt-assistant/references/content-pack.md +55 -0
  10. package/skills/dknowc-ppt-assistant/references/material_usage.md +51 -0
  11. package/skills/dknowc-ppt-assistant/references/sample_effect.html +89 -0
  12. package/skills/dknowc-ppt-assistant/references/sample_search_result.md +48 -0
  13. package/skills/dknowc-ppt-assistant/references/search_intro.md +79 -0
  14. package/skills/dknowc-ppt-assistant/references/style-presets.md +126 -0
  15. package/skills/dknowc-ppt-assistant/references/svg-authoring.md +81 -0
  16. package/skills/dknowc-ppt-assistant/references/upstream-docs/svg-pipeline.md +842 -0
  17. package/skills/dknowc-ppt-assistant/references/upstream-example/01_cover.svg +28 -0
  18. package/skills/dknowc-ppt-assistant/references/upstream-example/02_quote.svg +38 -0
  19. package/skills/dknowc-ppt-assistant/references/upstream-example/03_origin.svg +96 -0
  20. package/skills/dknowc-ppt-assistant/references/upstream-example/README.md +15 -0
  21. package/skills/dknowc-ppt-assistant/references/upstream-example/design_spec.md +408 -0
  22. package/skills/dknowc-ppt-assistant/references/upstream-example/spec_lock.md +78 -0
  23. package/skills/dknowc-ppt-assistant/scripts/adapt_mcp_result.py +279 -0
  24. package/skills/dknowc-ppt-assistant/scripts/check_release.py +106 -0
  25. package/skills/dknowc-ppt-assistant/scripts/compact_svg_coordinates.py +345 -0
  26. package/skills/dknowc-ppt-assistant/scripts/config.py +707 -0
  27. package/skills/dknowc-ppt-assistant/scripts/console_encoding.py +33 -0
  28. package/skills/dknowc-ppt-assistant/scripts/error_helper.py +434 -0
  29. package/skills/dknowc-ppt-assistant/scripts/finalize_svg.py +507 -0
  30. package/skills/dknowc-ppt-assistant/scripts/hyperlink_contract.py +399 -0
  31. package/skills/dknowc-ppt-assistant/scripts/initialize.py +182 -0
  32. package/skills/dknowc-ppt-assistant/scripts/language_tags.py +283 -0
  33. package/skills/dknowc-ppt-assistant/scripts/mcp_direct.py +158 -0
  34. package/skills/dknowc-ppt-assistant/scripts/native_payloads.py +655 -0
  35. package/skills/dknowc-ppt-assistant/scripts/pptx_animation_presets.json +3440 -0
  36. package/skills/dknowc-ppt-assistant/scripts/pptx_animations.py +3965 -0
  37. package/skills/dknowc-ppt-assistant/scripts/pptx_effects.py +143 -0
  38. package/skills/dknowc-ppt-assistant/scripts/pptx_opc_validation.py +346 -0
  39. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/__init__.py +130 -0
  40. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/LICENSE-APACHE-2.0.txt +202 -0
  41. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/LICENSE-OPEN-XML-SDK-MIT.txt +23 -0
  42. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/NOTICE.md +54 -0
  43. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/presetShapeDefinitions.xml +19898 -0
  44. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/presetShapeSemantics.json +1217 -0
  45. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/shape_type_values.txt +187 -0
  46. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/errors.py +39 -0
  47. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/formula.py +336 -0
  48. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/loader.py +364 -0
  49. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/models.py +201 -0
  50. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/registry.py +270 -0
  51. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/semantic_hash.py +456 -0
  52. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/semantics.py +543 -0
  53. package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/xml_safety.py +21 -0
  54. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/__init__.py +21 -0
  55. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/animation_import.py +287 -0
  56. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/chart_to_svg.py +2377 -0
  57. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/chartex_to_svg.py +422 -0
  58. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/color_resolver.py +894 -0
  59. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/converter.py +1143 -0
  60. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/custgeom_to_svg.py +165 -0
  61. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/effect_to_svg.py +410 -0
  62. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/emu_units.py +258 -0
  63. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/fill_to_svg.py +816 -0
  64. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/formula_import.py +611 -0
  65. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/hyperlinks.py +93 -0
  66. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/import_diagnostics.py +37 -0
  67. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/ln_to_svg.py +362 -0
  68. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/normalized_chart_svg.py +1217 -0
  69. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/ooxml_loader.py +506 -0
  70. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/pic_to_svg.py +653 -0
  71. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_authoring.py +894 -0
  72. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_registry_to_svg.py +216 -0
  73. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_svg_markup.py +198 -0
  74. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/prstgeom_to_svg.py +162 -0
  75. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/shape_walker.py +556 -0
  76. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/slide_to_svg.py +2002 -0
  77. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/tbl_to_svg.py +1841 -0
  78. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/transition_import.py +201 -0
  79. package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/txbody_to_svg.py +1433 -0
  80. package/skills/dknowc-ppt-assistant/scripts/pptx_transitions.py +3153 -0
  81. package/skills/dknowc-ppt-assistant/scripts/preset_shape_svg.py +450 -0
  82. package/skills/dknowc-ppt-assistant/scripts/project_utils.py +645 -0
  83. package/skills/dknowc-ppt-assistant/scripts/register_key.mjs +183 -0
  84. package/skills/dknowc-ppt-assistant/scripts/register_template.py +1327 -0
  85. package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +1048 -0
  86. package/skills/dknowc-ppt-assistant/scripts/resource_paths.py +282 -0
  87. package/skills/dknowc-ppt-assistant/scripts/shape_boolean_svg.py +189 -0
  88. package/skills/dknowc-ppt-assistant/scripts/slide_roster.py +44 -0
  89. package/skills/dknowc-ppt-assistant/scripts/svg_finalize/__init__.py +12 -0
  90. package/skills/dknowc-ppt-assistant/scripts/svg_finalize/align_embed_images.py +672 -0
  91. package/skills/dknowc-ppt-assistant/scripts/svg_finalize/crop_images.py +370 -0
  92. package/skills/dknowc-ppt-assistant/scripts/svg_finalize/embed_icons.py +564 -0
  93. package/skills/dknowc-ppt-assistant/scripts/svg_finalize/embed_images.py +288 -0
  94. package/skills/dknowc-ppt-assistant/scripts/svg_finalize/fix_image_aspect.py +389 -0
  95. package/skills/dknowc-ppt-assistant/scripts/svg_finalize/flatten_tspan.py +948 -0
  96. package/skills/dknowc-ppt-assistant/scripts/svg_finalize/svg_rect_to_path.py +346 -0
  97. package/skills/dknowc-ppt-assistant/scripts/svg_quality/__init__.py +15 -0
  98. package/skills/dknowc-ppt-assistant/scripts/svg_quality/checker.py +7791 -0
  99. package/skills/dknowc-ppt-assistant/scripts/svg_quality/cli.py +193 -0
  100. package/skills/dknowc-ppt-assistant/scripts/svg_quality/svg_contracts.py +1121 -0
  101. package/skills/dknowc-ppt-assistant/scripts/svg_quality/xml_support.py +35 -0
  102. package/skills/dknowc-ppt-assistant/scripts/svg_quality_checker.py +59 -0
  103. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/__init__.py +37 -0
  104. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/animation_config.py +1622 -0
  105. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/canvas_contract.py +226 -0
  106. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/__init__.py +1 -0
  107. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/context.py +291 -0
  108. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/converter.py +1980 -0
  109. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/elements.py +5272 -0
  110. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/hyperlinks.py +162 -0
  111. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/paths.py +847 -0
  112. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/styles.py +752 -0
  113. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/text_properties.py +796 -0
  114. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/theme_colors.py +283 -0
  115. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/theme_fonts.py +330 -0
  116. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/utils.py +3555 -0
  117. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/geometry_properties.py +140 -0
  118. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/__init__.py +356 -0
  119. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chart_data.py +1449 -0
  120. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chart_style.py +886 -0
  121. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chart_xml.py +1495 -0
  122. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chartex.py +272 -0
  123. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/fallback_hash.py +161 -0
  124. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula.py +243 -0
  125. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_ast.py +592 -0
  126. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_compiler.py +96 -0
  127. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_omml.py +1049 -0
  128. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_parser.py +2181 -0
  129. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_profile.py +739 -0
  130. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_run_properties.py +234 -0
  131. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/inline_formula.py +311 -0
  132. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/marker_attributes.py +182 -0
  133. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/marker_common.py +806 -0
  134. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/marker_status.py +190 -0
  135. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/table.py +1113 -0
  136. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/workbook.py +216 -0
  137. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/__init__.py +1 -0
  138. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/builder.py +6273 -0
  139. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/cli.py +2059 -0
  140. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/dimensions.py +189 -0
  141. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/discovery.py +120 -0
  142. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/media.py +160 -0
  143. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/narration.py +696 -0
  144. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/notes.py +336 -0
  145. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/slide_xml.py +138 -0
  146. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/template_structure.py +3457 -0
  147. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/template_validation.py +1536 -0
  148. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/semantic_markers.py +240 -0
  149. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/shape_boolean.py +1355 -0
  150. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/text_outline.py +1121 -0
  151. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/tspan_flattener.py +64 -0
  152. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/use_expander.py +577 -0
  153. package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx.py +21 -0
  154. package/skills/dknowc-ppt-assistant/scripts/trusted_search.py +336 -0
  155. package/skills/dknowc-ppt-assistant/scripts/update_spec.py +404 -0
  156. package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +142 -0
  157. package/skills/dknowc-ppt-assistant/workflows/routing.md +38 -0
  158. package/src/index.js +7 -2
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env python3
2
+ """Shared diagnostic contract for unsupported imported object effects."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import json
7
+ from xml.etree import ElementTree as ET
8
+
9
+
10
+ EFFECT_STATUS_ATTR = "data-pptx-effect-status"
11
+ EFFECT_REASON_ATTR = "data-pptx-effect-reason"
12
+ UNSUPPORTED_EFFECT_STATUS = "unsupported"
13
+ _EFFECT_OBJECT_IDENTITY_ATTRS = (
14
+ "data-pptx-object",
15
+ "data-pptx-shape-id",
16
+ "data-pptx-shape-scope",
17
+ )
18
+ _DML_NAMESPACE = "http://schemas.openxmlformats.org/drawingml/2006/main"
19
+ _TEXT_PROPERTY_TAGS = frozenset({
20
+ f"{{{_DML_NAMESPACE}}}defRPr",
21
+ f"{{{_DML_NAMESPACE}}}endParaRPr",
22
+ f"{{{_DML_NAMESPACE}}}rPr",
23
+ })
24
+ _RUN_EFFECT_CONTAINER_TAGS = frozenset({
25
+ f"{{{_DML_NAMESPACE}}}effectLst",
26
+ f"{{{_DML_NAMESPACE}}}effectDag",
27
+ })
28
+
29
+
30
+ def project_effect_status_errors(root: ET.Element) -> list[str]:
31
+ """Return blocking diagnostics for invalid or unsupported effect metadata."""
32
+ errors: set[str] = set()
33
+ parents = {
34
+ child: parent
35
+ for parent in root.iter()
36
+ for child in parent
37
+ }
38
+ for elem in root.iter():
39
+ raw_status = elem.get(EFFECT_STATUS_ATTR)
40
+ raw_reason = elem.get(EFFECT_REASON_ATTR)
41
+ if raw_status is None and raw_reason is None:
42
+ continue
43
+ parent = parents.get(elem)
44
+ if (
45
+ parent is not None
46
+ and parent.get(EFFECT_STATUS_ATTR) == raw_status
47
+ and parent.get(EFFECT_REASON_ATTR) == raw_reason
48
+ and _same_source_object(parent, elem)
49
+ ):
50
+ # Import duplicates the marker on the logical object and carrier
51
+ # so stripping either copy cannot erase the block. Report it once.
52
+ continue
53
+ label = _element_label(elem)
54
+ status = (raw_status or "").strip()
55
+ if status != UNSUPPORTED_EFFECT_STATUS:
56
+ errors.add(
57
+ f'{label} {EFFECT_STATUS_ATTR} must equal '
58
+ f'{UNSUPPORTED_EFFECT_STATUS!r}; got {raw_status!r}'
59
+ )
60
+ continue
61
+ reason = (raw_reason or "").strip()
62
+ if not reason:
63
+ errors.add(
64
+ f'{label} {EFFECT_REASON_ATTR} requires a non-empty reason'
65
+ )
66
+ continue
67
+ errors.add(f'{label} has unsupported source PPTX effect: {reason}')
68
+ return sorted(errors)
69
+
70
+
71
+ def unsupported_effect_metadata(*reasons: str) -> dict[str, str]:
72
+ """Build one canonical import marker without dropping compound reasons."""
73
+ normalized: set[str] = set()
74
+ for reason in reasons:
75
+ reason = reason.strip()
76
+ if not reason:
77
+ raise ValueError("Unsupported PPTX effect reason must not be empty")
78
+ items: object = reason
79
+ if reason.startswith("["):
80
+ try:
81
+ items = json.loads(reason)
82
+ except json.JSONDecodeError:
83
+ pass
84
+ if not isinstance(items, list):
85
+ items = [reason]
86
+ if not all(isinstance(item, str) and item.strip() for item in items):
87
+ raise ValueError("Unsupported PPTX effect reasons must be strings")
88
+ normalized.update(item.strip() for item in items)
89
+ if not normalized:
90
+ raise ValueError("Unsupported PPTX effect reason must not be empty")
91
+ ordered = sorted(normalized)
92
+ encoded = (
93
+ ordered[0]
94
+ if len(ordered) == 1
95
+ else json.dumps(ordered, separators=(",", ":"))
96
+ )
97
+ return {
98
+ EFFECT_STATUS_ATTR: UNSUPPORTED_EFFECT_STATUS,
99
+ EFFECT_REASON_ATTR: encoded,
100
+ }
101
+
102
+
103
+ def txbody_has_run_effects(*text_style_roots: ET.Element | None) -> bool:
104
+ """Return whether rebuilding any supplied text style would lose an effect."""
105
+ for root in text_style_roots:
106
+ if root is None:
107
+ continue
108
+ for properties in root.iter():
109
+ if properties.tag not in _TEXT_PROPERTY_TAGS:
110
+ continue
111
+ for child in properties:
112
+ if child.tag in _RUN_EFFECT_CONTAINER_TAGS and any(
113
+ isinstance(effect.tag, str)
114
+ for effect in child
115
+ ):
116
+ return True
117
+ return False
118
+
119
+
120
+ def _element_label(elem: ET.Element) -> str:
121
+ tag = elem.tag.rsplit("}", 1)[-1]
122
+ elem_id = elem.get("id") or elem.get("data-name")
123
+ if elem_id:
124
+ return f'<{tag} id="{elem_id}">'
125
+ shape_id = elem.get("data-pptx-shape-id")
126
+ if shape_id:
127
+ object_kind = elem.get("data-pptx-object") or "object"
128
+ scope = elem.get("data-pptx-shape-scope") or "unknown"
129
+ return (
130
+ f'<{tag} data-pptx-object="{object_kind}" '
131
+ f'data-pptx-shape-id="{shape_id}" '
132
+ f'data-pptx-shape-scope="{scope}">'
133
+ )
134
+ return f"<{tag}>"
135
+
136
+
137
+ def _same_source_object(parent: ET.Element, child: ET.Element) -> bool:
138
+ """Return whether a parent/child marker describes one imported object."""
139
+ return all(
140
+ child.get(attr) is not None
141
+ and child.get(attr) == parent.get(attr)
142
+ for attr in _EFFECT_OBJECT_IDENTITY_ATTRS
143
+ )
@@ -0,0 +1,346 @@
1
+ #!/usr/bin/env python3
2
+ """Shared, dependency-light OPC package relationship validation."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import posixpath
7
+ import re
8
+ from pathlib import Path
9
+ from urllib.parse import urlsplit
10
+ from xml.etree import ElementTree as ET
11
+
12
+ from hyperlink_contract import (
13
+ HYPERLINK_REL_TYPE,
14
+ SLIDE_JUMP_ACTION,
15
+ SLIDE_REL_TYPE,
16
+ )
17
+
18
+
19
+ PACKAGE_REL_NS = (
20
+ "http://schemas.openxmlformats.org/package/2006/relationships"
21
+ )
22
+ _RELATIONSHIPS_TAG = f"{{{PACKAGE_REL_NS}}}Relationships"
23
+ _RELATIONSHIP_TAG = f"{{{PACKAGE_REL_NS}}}Relationship"
24
+ _DRAWINGML_NS = (
25
+ "http://schemas.openxmlformats.org/drawingml/2006/main"
26
+ )
27
+ _PRESENTATIONML_NS = (
28
+ "http://schemas.openxmlformats.org/presentationml/2006/main"
29
+ )
30
+ _OFFICE_REL_NS = (
31
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
32
+ )
33
+ _OPC_UNRESERVED = frozenset(
34
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"
35
+ )
36
+ _ASCII_LOWER_TRANSLATION = str.maketrans(
37
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
38
+ "abcdefghijklmnopqrstuvwxyz",
39
+ )
40
+
41
+
42
+ def canonical_opc_part_path(path: str) -> str | None:
43
+ """Return an OPC-equivalent package path key, or None when invalid."""
44
+ if (
45
+ not path
46
+ or "\\" in path
47
+ or "?" in path
48
+ or "#" in path
49
+ or path.endswith("/")
50
+ or "//" in path
51
+ or any(ord(char) <= 0x20 for char in path)
52
+ ):
53
+ return None
54
+ output: list[str] = []
55
+ index = 0
56
+ while index < len(path):
57
+ char = path[index]
58
+ if char != "%":
59
+ output.append(char)
60
+ index += 1
61
+ continue
62
+ if (
63
+ index + 2 >= len(path)
64
+ or re.fullmatch(
65
+ r"[0-9A-Fa-f]{2}",
66
+ path[index + 1:index + 3],
67
+ )
68
+ is None
69
+ ):
70
+ return None
71
+ value = int(path[index + 1:index + 3], 16)
72
+ decoded = chr(value)
73
+ if value in {0, ord("/"), ord("\\")}:
74
+ return None
75
+ output.append(
76
+ decoded
77
+ if decoded in _OPC_UNRESERVED
78
+ else f"%{value:02X}"
79
+ )
80
+ index += 3
81
+
82
+ decoded_path = "".join(output)
83
+ if decoded_path.rsplit("/", 1)[-1] in {".", ".."}:
84
+ return None
85
+ normalized = posixpath.normpath(decoded_path)
86
+ if (
87
+ not normalized
88
+ or normalized in {".", ".."}
89
+ or normalized.startswith("/")
90
+ or normalized.startswith("../")
91
+ ):
92
+ return None
93
+ return normalized.translate(_ASCII_LOWER_TRANSLATION)
94
+
95
+
96
+ def _source_part_for_rels(rels_path: str) -> str | None:
97
+ filename = posixpath.basename(rels_path)
98
+ if filename == ".rels" or not filename.endswith(".rels"):
99
+ return None
100
+ source_dir = posixpath.dirname(posixpath.dirname(rels_path))
101
+ source_name = filename.removesuffix(".rels")
102
+ return (
103
+ posixpath.join(source_dir, source_name)
104
+ if source_dir
105
+ else source_name
106
+ )
107
+
108
+
109
+ def resolve_internal_opc_target(
110
+ rels_path: str,
111
+ target: str,
112
+ ) -> str | None:
113
+ """Resolve one valid internal OPC Target to its canonical package key."""
114
+ target_path_query = target.split("#", 1)[0]
115
+ if (
116
+ "\\" in target
117
+ or "?" in target_path_query
118
+ or any(ord(char) <= 0x20 for char in target)
119
+ ):
120
+ return None
121
+ try:
122
+ parsed = urlsplit(target)
123
+ except ValueError:
124
+ return None
125
+ if parsed.scheme or parsed.netloc or parsed.query:
126
+ return None
127
+
128
+ source_part = _source_part_for_rels(rels_path)
129
+ if parsed.path.startswith("/"):
130
+ resolved = parsed.path[1:]
131
+ elif parsed.path:
132
+ base_dir = posixpath.dirname(source_part) if source_part else ""
133
+ resolved = (
134
+ posixpath.join(base_dir, parsed.path)
135
+ if base_dir
136
+ else parsed.path
137
+ )
138
+ elif source_part and "#" in target:
139
+ resolved = source_part
140
+ else:
141
+ return None
142
+ return canonical_opc_part_path(resolved)
143
+
144
+
145
+ def _relationships_path_for_part(part_path: Path) -> Path:
146
+ return part_path.parent / "_rels" / f"{part_path.name}.rels"
147
+
148
+
149
+ def _relationship_attrs_by_id(rels_path: Path) -> dict[str, dict[str, str]]:
150
+ if not rels_path.is_file():
151
+ return {}
152
+ root = ET.parse(rels_path).getroot()
153
+ return {
154
+ elem.attrib["Id"]: dict(elem.attrib)
155
+ for elem in root.findall(_RELATIONSHIP_TAG)
156
+ if elem.attrib.get("Id")
157
+ }
158
+
159
+
160
+ def _presentation_slide_roster(extract_dir: Path) -> set[str]:
161
+ """Return canonical slide parts reachable from ``p:sldIdLst``."""
162
+ presentation = extract_dir / "ppt" / "presentation.xml"
163
+ presentation_rels = _relationships_path_for_part(presentation)
164
+ if not presentation.is_file() or not presentation_rels.is_file():
165
+ return set()
166
+ rels = _relationship_attrs_by_id(presentation_rels)
167
+ root = ET.parse(presentation).getroot()
168
+ roster: set[str] = set()
169
+ rels_rel = presentation_rels.relative_to(extract_dir).as_posix()
170
+ for slide_id in root.findall(
171
+ f"{{{_PRESENTATIONML_NS}}}sldIdLst/"
172
+ f"{{{_PRESENTATIONML_NS}}}sldId"
173
+ ):
174
+ relationship_id = slide_id.attrib.get(f"{{{_OFFICE_REL_NS}}}id")
175
+ relationship = rels.get(relationship_id or "")
176
+ if relationship is None or relationship.get("Type") != SLIDE_REL_TYPE:
177
+ continue
178
+ target = relationship.get("Target", "")
179
+ resolved = resolve_internal_opc_target(rels_rel, target)
180
+ if resolved is not None:
181
+ roster.add(resolved)
182
+ return roster
183
+
184
+
185
+ def verify_hyperlink_relationships(extract_dir: Path) -> list[str]:
186
+ """Return hyperlink/action mismatches and slide jumps outside the roster."""
187
+ roster = _presentation_slide_roster(extract_dir)
188
+ problems: list[str] = []
189
+ source_patterns = (
190
+ "ppt/slides/slide*.xml",
191
+ "ppt/slideLayouts/slideLayout*.xml",
192
+ "ppt/slideMasters/slideMaster*.xml",
193
+ )
194
+ for pattern in source_patterns:
195
+ for part_path in sorted(extract_dir.glob(pattern)):
196
+ rels_path = _relationships_path_for_part(part_path)
197
+ rels = _relationship_attrs_by_id(rels_path)
198
+ part_rel = part_path.relative_to(extract_dir).as_posix()
199
+ rels_rel = rels_path.relative_to(extract_dir).as_posix()
200
+ try:
201
+ root = ET.parse(part_path).getroot()
202
+ except ET.ParseError:
203
+ continue
204
+ for link in root.iter(f"{{{_DRAWINGML_NS}}}hlinkClick"):
205
+ action = (link.attrib.get("action") or "").strip()
206
+ if action == "ppaction://media":
207
+ continue
208
+ relationship_id = (
209
+ link.attrib.get(f"{{{_OFFICE_REL_NS}}}id") or ""
210
+ ).strip()
211
+ if not relationship_id:
212
+ if action == SLIDE_JUMP_ACTION:
213
+ problems.append(
214
+ f"{part_rel} -> <slide jump without relationship id>"
215
+ )
216
+ continue
217
+ relationship = rels.get(relationship_id)
218
+ if relationship is None:
219
+ problems.append(
220
+ f"{part_rel} -> <missing hyperlink relationship "
221
+ f"{relationship_id!r}>"
222
+ )
223
+ continue
224
+ rel_type = relationship.get("Type", "")
225
+ target_mode = relationship.get("TargetMode", "")
226
+ target = relationship.get("Target", "")
227
+ if rel_type == HYPERLINK_REL_TYPE:
228
+ if target_mode.lower() != "external":
229
+ problems.append(
230
+ f"{part_rel} -> <hyperlink relationship "
231
+ f"{relationship_id!r} is not External>"
232
+ )
233
+ if action == SLIDE_JUMP_ACTION:
234
+ problems.append(
235
+ f"{part_rel} -> <slide jump {relationship_id!r} "
236
+ "uses an external hyperlink relationship>"
237
+ )
238
+ continue
239
+ if rel_type == SLIDE_REL_TYPE:
240
+ if target_mode:
241
+ problems.append(
242
+ f"{part_rel} -> <slide relationship "
243
+ f"{relationship_id!r} cannot be External>"
244
+ )
245
+ if action != SLIDE_JUMP_ACTION:
246
+ problems.append(
247
+ f"{part_rel} -> <slide relationship "
248
+ f"{relationship_id!r} lacks hlinksldjump action>"
249
+ )
250
+ resolved = resolve_internal_opc_target(rels_rel, target)
251
+ if resolved is not None and resolved not in roster:
252
+ problems.append(
253
+ f"{part_rel} -> <slide jump {relationship_id!r} "
254
+ f"targets non-roster part {resolved}>"
255
+ )
256
+ continue
257
+ if action == SLIDE_JUMP_ACTION:
258
+ problems.append(
259
+ f"{part_rel} -> <slide jump {relationship_id!r} uses "
260
+ f"relationship type {rel_type!r}>"
261
+ )
262
+ return problems
263
+
264
+
265
+ def verify_internal_relationships(extract_dir: Path) -> list[str]:
266
+ """Return invalid or dangling internal relationships in an OPC package."""
267
+ package_parts: set[str] = set()
268
+ for path in extract_dir.rglob("*"):
269
+ if not path.is_file():
270
+ continue
271
+ key = canonical_opc_part_path(
272
+ path.relative_to(extract_dir).as_posix()
273
+ )
274
+ if key is not None:
275
+ package_parts.add(key)
276
+
277
+ problems: list[str] = []
278
+ for rels_path in sorted(extract_dir.rglob("*.rels")):
279
+ rels_rel = rels_path.relative_to(extract_dir).as_posix()
280
+ try:
281
+ root = ET.parse(rels_path).getroot()
282
+ except ET.ParseError as exc:
283
+ problems.append(
284
+ f"{rels_rel} -> <invalid relationships XML: {exc}>"
285
+ )
286
+ continue
287
+ if root.tag != _RELATIONSHIPS_TAG:
288
+ problems.append(
289
+ f"{rels_rel} -> <invalid Relationships namespace>"
290
+ )
291
+ continue
292
+
293
+ seen_ids: set[str] = set()
294
+ for element in root:
295
+ if element.tag != _RELATIONSHIP_TAG:
296
+ problems.append(
297
+ f"{rels_rel} -> <invalid relationships child "
298
+ f"{element.tag!r}>"
299
+ )
300
+ continue
301
+ relationship_id = (element.attrib.get("Id") or "").strip()
302
+ relationship_type = (
303
+ element.attrib.get("Type") or ""
304
+ ).strip()
305
+ target = (element.attrib.get("Target") or "").strip()
306
+ target_mode = (
307
+ element.attrib.get("TargetMode") or ""
308
+ ).strip()
309
+
310
+ if not relationship_id:
311
+ problems.append(f"{rels_rel} -> <missing relationship Id>")
312
+ elif relationship_id in seen_ids:
313
+ problems.append(
314
+ f"{rels_rel} -> <duplicate relationship Id "
315
+ f"{relationship_id!r}>"
316
+ )
317
+ else:
318
+ seen_ids.add(relationship_id)
319
+ if not relationship_type:
320
+ problems.append(
321
+ f"{rels_rel} -> <missing relationship Type>"
322
+ )
323
+ if not target:
324
+ problems.append(f"{rels_rel} -> <missing Target>")
325
+ continue
326
+ if target_mode and target_mode.lower() not in {
327
+ "internal",
328
+ "external",
329
+ }:
330
+ problems.append(
331
+ f"{rels_rel} -> <invalid TargetMode "
332
+ f"{target_mode!r}>"
333
+ )
334
+ continue
335
+ if target_mode.lower() == "external":
336
+ continue
337
+
338
+ resolved = resolve_internal_opc_target(rels_rel, target)
339
+ if resolved is None:
340
+ problems.append(
341
+ f"{rels_rel} -> <invalid Target {target!r}>"
342
+ )
343
+ elif resolved not in package_parts:
344
+ problems.append(f"{rels_rel} -> {resolved}")
345
+ problems.extend(verify_hyperlink_relationships(extract_dir))
346
+ return problems
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ PPT Master - DrawingML Preset Shapes
4
+
5
+ Shared full-catalog loader, registry, and formula evaluator for PPTX shapes.
6
+
7
+ Usage:
8
+ Import get_preset_registry from pptx_shapes.
9
+
10
+ Examples:
11
+ from pptx_shapes import get_preset_registry
12
+ arrow = get_preset_registry().evaluate("rightArrow", 320, 160)
13
+
14
+ Dependencies:
15
+ None (only uses standard library)
16
+ """
17
+
18
+ from .errors import (
19
+ FormulaEvaluationError,
20
+ FormulaSyntaxError,
21
+ PresetShapeDataError,
22
+ PresetShapeError,
23
+ UnknownGuideError,
24
+ UnknownPresetShapeError,
25
+ )
26
+ from .formula import (
27
+ FULL_CIRCLE,
28
+ OOXML_COORDINATE_MAX,
29
+ OOXML_COORDINATE_MIN,
30
+ OOXML_DEGREE,
31
+ OOXML_LINE_WIDTH_MAX,
32
+ SUPPORTED_OPERATORS,
33
+ FormulaEvaluator,
34
+ build_builtin_guides,
35
+ evaluate_formula,
36
+ validate_ooxml_line_width,
37
+ validate_ooxml_xfrm,
38
+ )
39
+ from .loader import (
40
+ BUNDLED_DEFINITIONS_PATH,
41
+ BUNDLED_DEFINITIONS_SHA256,
42
+ BUNDLED_SHAPE_TYPES_PATH,
43
+ BUNDLED_SHAPE_TYPES_SHA256,
44
+ DRAWINGML_NS,
45
+ EXPECTED_SHAPE_COUNT,
46
+ load_preset_shape_definitions,
47
+ load_shape_type_values,
48
+ )
49
+ from .models import (
50
+ EvaluatedPresetGeometry,
51
+ PresetShapeDefinition,
52
+ )
53
+ from .registry import (
54
+ CONNECTOR_PRESET_TYPES,
55
+ PresetShapeRegistry,
56
+ get_preset_registry,
57
+ )
58
+ from .semantics import (
59
+ BUNDLED_SEMANTICS_PATH,
60
+ SEMANTIC_ASPECTS,
61
+ SEMANTIC_DIRECTIONALITY,
62
+ SEMANTIC_RELATIONSHIPS,
63
+ SEMANTIC_ROLES,
64
+ SEMANTIC_SCOPES,
65
+ SEMANTIC_TEXT_CAPACITIES,
66
+ SEMANTIC_VISUAL_WEIGHTS,
67
+ PresetShapeSemantics,
68
+ get_preset_shape_semantics,
69
+ )
70
+ from .semantic_hash import (
71
+ NATIVE_FALLBACK_SHA256_ATTR,
72
+ resolve_preset_preview_hash,
73
+ svg_native_fallback_fingerprint,
74
+ svg_native_fallback_markup_fingerprint,
75
+ svg_preset_preview_fingerprint,
76
+ svg_text_fingerprint,
77
+ )
78
+ from .xml_safety import RELATIONSHIPS_NS, has_relationship_attributes
79
+
80
+
81
+ __all__ = [
82
+ "BUNDLED_DEFINITIONS_PATH",
83
+ "BUNDLED_DEFINITIONS_SHA256",
84
+ "BUNDLED_SEMANTICS_PATH",
85
+ "BUNDLED_SHAPE_TYPES_PATH",
86
+ "BUNDLED_SHAPE_TYPES_SHA256",
87
+ "CONNECTOR_PRESET_TYPES",
88
+ "DRAWINGML_NS",
89
+ "EXPECTED_SHAPE_COUNT",
90
+ "FULL_CIRCLE",
91
+ "OOXML_COORDINATE_MAX",
92
+ "OOXML_COORDINATE_MIN",
93
+ "OOXML_DEGREE",
94
+ "OOXML_LINE_WIDTH_MAX",
95
+ "NATIVE_FALLBACK_SHA256_ATTR",
96
+ "SUPPORTED_OPERATORS",
97
+ "EvaluatedPresetGeometry",
98
+ "FormulaEvaluationError",
99
+ "FormulaEvaluator",
100
+ "FormulaSyntaxError",
101
+ "PresetShapeDataError",
102
+ "PresetShapeDefinition",
103
+ "PresetShapeError",
104
+ "PresetShapeRegistry",
105
+ "PresetShapeSemantics",
106
+ "RELATIONSHIPS_NS",
107
+ "SEMANTIC_ASPECTS",
108
+ "SEMANTIC_DIRECTIONALITY",
109
+ "SEMANTIC_RELATIONSHIPS",
110
+ "SEMANTIC_ROLES",
111
+ "SEMANTIC_SCOPES",
112
+ "SEMANTIC_TEXT_CAPACITIES",
113
+ "SEMANTIC_VISUAL_WEIGHTS",
114
+ "UnknownGuideError",
115
+ "UnknownPresetShapeError",
116
+ "build_builtin_guides",
117
+ "evaluate_formula",
118
+ "get_preset_registry",
119
+ "get_preset_shape_semantics",
120
+ "has_relationship_attributes",
121
+ "load_preset_shape_definitions",
122
+ "load_shape_type_values",
123
+ "resolve_preset_preview_hash",
124
+ "svg_native_fallback_fingerprint",
125
+ "svg_native_fallback_markup_fingerprint",
126
+ "svg_text_fingerprint",
127
+ "svg_preset_preview_fingerprint",
128
+ "validate_ooxml_line_width",
129
+ "validate_ooxml_xfrm",
130
+ ]