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,216 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ PPT Master - Preset Geometry SVG Adapter
4
+
5
+ Render evaluated DrawingML preset geometry as absolute SVG path layers.
6
+
7
+ Usage:
8
+ Import render_preset_geometry from pptx_to_svg.preset_registry_to_svg.
9
+
10
+ Examples:
11
+ geometry = render_preset_geometry("rightArrow", xfrm)
12
+
13
+ Dependencies:
14
+ None (only uses standard library and local PPT Master modules)
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import math
20
+ from dataclasses import dataclass
21
+ from typing import Mapping
22
+
23
+ from pptx_shapes import get_preset_registry
24
+
25
+ from .emu_units import Xfrm, fmt_num
26
+
27
+
28
+ @dataclass(frozen=True)
29
+ class SvgPresetPath:
30
+ """One visible layer from a DrawingML preset's ``a:pathLst``."""
31
+
32
+ d: str
33
+ fill: str
34
+ stroke: bool
35
+
36
+
37
+ @dataclass(frozen=True)
38
+ class SvgPresetGeometry:
39
+ """A fully evaluated preset preview in slide-absolute SVG coordinates."""
40
+
41
+ paths: tuple[SvgPresetPath, ...]
42
+
43
+
44
+ def render_preset_geometry(
45
+ preset: str,
46
+ xfrm: Xfrm,
47
+ adjustments: Mapping[str, str | int | float] | None = None,
48
+ ) -> SvgPresetGeometry:
49
+ """Evaluate ``preset`` and project every DrawingML path into SVG space."""
50
+
51
+ evaluated = get_preset_registry().evaluate(
52
+ preset,
53
+ xfrm.w,
54
+ xfrm.h,
55
+ adjustments=adjustments,
56
+ )
57
+ layers = tuple(
58
+ SvgPresetPath(
59
+ d=render_evaluated_path(
60
+ path.commands,
61
+ x=xfrm.x,
62
+ y=xfrm.y,
63
+ width=xfrm.w,
64
+ height=xfrm.h,
65
+ coordinate_width=path.coordinate_width,
66
+ coordinate_height=path.coordinate_height,
67
+ ),
68
+ fill=path.fill,
69
+ stroke=path.stroke,
70
+ )
71
+ for path in evaluated.paths
72
+ )
73
+ return SvgPresetGeometry(paths=tuple(layer for layer in layers if layer.d))
74
+
75
+
76
+ def render_evaluated_path(
77
+ commands,
78
+ *,
79
+ x: float,
80
+ y: float,
81
+ width: float,
82
+ height: float,
83
+ coordinate_width: float,
84
+ coordinate_height: float,
85
+ ) -> str:
86
+ scale_x = width / coordinate_width if coordinate_width else 1.0
87
+ scale_y = height / coordinate_height if coordinate_height else 1.0
88
+
89
+ def point(px: float, py: float) -> tuple[float, float]:
90
+ return x + px * scale_x, y + py * scale_y
91
+
92
+ parts: list[str] = []
93
+ current = (x, y)
94
+ subpath_start = current
95
+ for command in commands:
96
+ values = command.parameters
97
+ if command.name == "moveTo":
98
+ current = point(values[0], values[1])
99
+ subpath_start = current
100
+ parts.append(f"M {fmt_num(current[0])} {fmt_num(current[1])}")
101
+ elif command.name == "lnTo":
102
+ current = point(values[0], values[1])
103
+ parts.append(f"L {fmt_num(current[0])} {fmt_num(current[1])}")
104
+ elif command.name == "quadBezTo":
105
+ control = point(values[0], values[1])
106
+ current = point(values[2], values[3])
107
+ parts.append(
108
+ "Q "
109
+ f"{fmt_num(control[0])} {fmt_num(control[1])} "
110
+ f"{fmt_num(current[0])} {fmt_num(current[1])}"
111
+ )
112
+ elif command.name == "cubicBezTo":
113
+ control_1 = point(values[0], values[1])
114
+ control_2 = point(values[2], values[3])
115
+ current = point(values[4], values[5])
116
+ parts.append(
117
+ "C "
118
+ f"{fmt_num(control_1[0])} {fmt_num(control_1[1])} "
119
+ f"{fmt_num(control_2[0])} {fmt_num(control_2[1])} "
120
+ f"{fmt_num(current[0])} {fmt_num(current[1])}"
121
+ )
122
+ elif command.name == "arcTo":
123
+ arc_parts, current = _render_arc(
124
+ current,
125
+ radius_x=values[0],
126
+ radius_y=values[1],
127
+ scale_x=scale_x,
128
+ scale_y=scale_y,
129
+ start_angle=values[2],
130
+ sweep_angle=values[3],
131
+ )
132
+ parts.extend(arc_parts)
133
+ elif command.name == "close":
134
+ parts.append("Z")
135
+ current = subpath_start
136
+ return " ".join(parts)
137
+
138
+
139
+ def _render_arc(
140
+ current: tuple[float, float],
141
+ *,
142
+ radius_x: float,
143
+ radius_y: float,
144
+ scale_x: float = 1.0,
145
+ scale_y: float = 1.0,
146
+ start_angle: float,
147
+ sweep_angle: float,
148
+ ) -> tuple[list[str], tuple[float, float]]:
149
+ """Render one DrawingML arc, splitting full circles for SVG validity.
150
+
151
+ DrawingML resolves the polar angle in the path-local ellipse before the
152
+ path coordinate system is scaled into the shape frame. Applying the
153
+ angle correction to already-scaled radii bends explicit-extent paths such
154
+ as ``cloud`` when the containing shape has a non-square aspect ratio.
155
+ """
156
+
157
+ radius_x = abs(radius_x)
158
+ radius_y = abs(radius_y)
159
+ scaled_radius_x = abs(radius_x * scale_x)
160
+ scaled_radius_y = abs(radius_y * scale_y)
161
+ if (
162
+ radius_x <= 1e-12
163
+ or radius_y <= 1e-12
164
+ or scaled_radius_x <= 1e-12
165
+ or scaled_radius_y <= 1e-12
166
+ or abs(sweep_angle) <= 1e-12
167
+ ):
168
+ return [], current
169
+
170
+ start_radians = _ellipse_parameter_angle(
171
+ start_angle,
172
+ radius_x,
173
+ radius_y,
174
+ )
175
+ center_x = current[0] - scaled_radius_x * math.cos(start_radians)
176
+ center_y = current[1] - scaled_radius_y * math.sin(start_radians)
177
+
178
+ # SVG cannot represent a 360-degree arc with one A command because its
179
+ # start and end points coincide. Chunks of at most 180 degrees also keep
180
+ # the large-arc flag deterministic for every preset definition.
181
+ remaining = sweep_angle
182
+ angle = start_angle
183
+ parts: list[str] = []
184
+ endpoint = current
185
+ half_circle = 180.0 * 60000.0
186
+ while abs(remaining) > 1e-9:
187
+ step = math.copysign(min(abs(remaining), half_circle), remaining)
188
+ angle += step
189
+ end_radians = _ellipse_parameter_angle(angle, radius_x, radius_y)
190
+ endpoint = (
191
+ center_x + scaled_radius_x * math.cos(end_radians),
192
+ center_y + scaled_radius_y * math.sin(end_radians),
193
+ )
194
+ large_arc = 1 if abs(step) > half_circle else 0
195
+ sweep = 1 if step >= 0 else 0
196
+ parts.append(
197
+ "A "
198
+ f"{fmt_num(scaled_radius_x)} {fmt_num(scaled_radius_y)} "
199
+ f"0 {large_arc} {sweep} "
200
+ f"{fmt_num(endpoint[0])} {fmt_num(endpoint[1])}"
201
+ )
202
+ remaining -= step
203
+ return parts, endpoint
204
+
205
+
206
+ def _ellipse_parameter_angle(
207
+ ooxml_angle: float,
208
+ radius_x: float,
209
+ radius_y: float,
210
+ ) -> float:
211
+ """Unskew an OOXML polar angle into an ellipse parameter angle."""
212
+ radians = math.radians(ooxml_angle / 60000.0)
213
+ return math.atan2(
214
+ radius_x * math.sin(radians),
215
+ radius_y * math.cos(radians),
216
+ )
@@ -0,0 +1,198 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ PPT Master - Preset Shape SVG Markup
4
+
5
+ Serialize evaluated DrawingML preset layers for lossless transport or compact
6
+ project authoring.
7
+
8
+ Usage:
9
+ Import serialize_preset_layers from pptx_to_svg.preset_svg_markup.
10
+
11
+ Examples:
12
+ markup = serialize_preset_layers(layers, semantic_attrs, style_attrs)
13
+
14
+ Dependencies:
15
+ None (only uses standard library and local PPT Master modules)
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ from dataclasses import dataclass
21
+ from typing import Mapping, Sequence
22
+ from xml.etree import ElementTree as ET
23
+
24
+ from pptx_shapes import svg_preset_preview_fingerprint
25
+
26
+ from .preset_registry_to_svg import SvgPresetPath
27
+
28
+
29
+ @dataclass(frozen=True)
30
+ class PresetSvgMarkup:
31
+ """Lossless hidden-carrier and visible-preview markup for one preset."""
32
+
33
+ carrier: str
34
+ preview: str
35
+ preview_hash: str
36
+
37
+ @property
38
+ def markup(self) -> str:
39
+ """Return the carrier and preview in canonical document order."""
40
+ return f"{self.carrier}\n{self.preview}"
41
+
42
+
43
+ def serialize_preset_layers(
44
+ layers: Sequence[SvgPresetPath],
45
+ semantic_attrs: Mapping[str, str],
46
+ style_attrs: Mapping[str, str],
47
+ ) -> PresetSvgMarkup:
48
+ """Serialize one preset without duplicating its native PowerPoint object."""
49
+ detail_style_attrs = dict(style_attrs)
50
+ preview_group_attrs = {"data-pptx-part": "geometry-preview"}
51
+ for name in ("filter", "opacity"):
52
+ value = detail_style_attrs.pop(name, None)
53
+ if value is not None:
54
+ preview_group_attrs[name] = value
55
+
56
+ detail_layers: list[str] = []
57
+ for layer in layers:
58
+ attrs = dict(detail_style_attrs)
59
+ apply_preset_path_fill(attrs, layer.fill)
60
+ if not layer.stroke:
61
+ remove_stroke_attrs(attrs)
62
+ attrs["stroke"] = "none"
63
+ attrs["data-pptx-part"] = "geometry-detail"
64
+ detail_layers.append(
65
+ f'<path d="{_xml_escape(layer.d)}"{attrs_to_xml(attrs)}/>'
66
+ )
67
+
68
+ preview = (
69
+ f'<g{attrs_to_xml(preview_group_attrs)}>\n'
70
+ + "\n".join(detail_layers)
71
+ + "\n</g>"
72
+ )
73
+ preview_root = ET.fromstring(
74
+ f'<svg xmlns="http://www.w3.org/2000/svg">{preview}</svg>'
75
+ )
76
+ preview_hash = svg_preset_preview_fingerprint(preview_root)
77
+ carrier_attrs = {
78
+ **style_attrs,
79
+ **semantic_attrs,
80
+ "data-pptx-preview-sha256": preview_hash,
81
+ "data-pptx-part": "geometry",
82
+ "visibility": "hidden",
83
+ "pointer-events": "none",
84
+ }
85
+ combined_path = " ".join(layer.d for layer in layers)
86
+ carrier = (
87
+ f'<path d="{_xml_escape(combined_path)}"'
88
+ f'{attrs_to_xml(carrier_attrs)}/>'
89
+ )
90
+ return PresetSvgMarkup(
91
+ carrier=carrier,
92
+ preview=preview,
93
+ preview_hash=preview_hash,
94
+ )
95
+
96
+
97
+ def serialize_compact_preset_layers(
98
+ layers: Sequence[SvgPresetPath],
99
+ style_attrs: Mapping[str, str],
100
+ ) -> str:
101
+ """Serialize visible preset layers without transport-only duplication.
102
+
103
+ Base paint lives once on the logical authored group and is inherited by
104
+ each path. A path writes only the fill/stroke override required by its
105
+ DrawingML layer. The authored-preset validator regenerates this exact
106
+ markup from the registry, so no serialized fingerprint is needed.
107
+ """
108
+ base_fill = style_attrs.get("fill", "none")
109
+ base_stroke = style_attrs.get("stroke", "none")
110
+ detail_layers: list[str] = []
111
+ for layer in layers:
112
+ attrs: dict[str, str] = {}
113
+ if layer.fill == "none":
114
+ if base_fill != "none":
115
+ attrs["fill"] = "none"
116
+ elif layer.fill != "norm":
117
+ derived_fill = {"fill": base_fill}
118
+ apply_preset_path_fill(derived_fill, layer.fill)
119
+ if derived_fill.get("fill") != base_fill:
120
+ attrs["fill"] = derived_fill["fill"]
121
+ if not layer.stroke and base_stroke != "none":
122
+ attrs["stroke"] = "none"
123
+ detail_layers.append(
124
+ f'<path d="{_xml_escape(layer.d)}"{attrs_to_xml(attrs)}/>'
125
+ )
126
+ return "\n".join(detail_layers)
127
+
128
+
129
+ def apply_preset_path_fill(attrs: dict[str, str], mode: str) -> None:
130
+ """Apply one DrawingML path fill mode to SVG presentation attributes."""
131
+ if mode == "none":
132
+ attrs["fill"] = "none"
133
+ attrs.pop("fill-opacity", None)
134
+ return
135
+ if mode == "norm":
136
+ return
137
+ color = attrs.get("fill", "")
138
+ if not color.startswith("#") or len(color) != 7:
139
+ return
140
+ try:
141
+ channels = tuple(
142
+ int(color[offset:offset + 2], 16)
143
+ for offset in (1, 3, 5)
144
+ )
145
+ except ValueError:
146
+ return
147
+ if mode in {"darken", "darkenLess"}:
148
+ factor = 0.65 if mode == "darken" else 0.82
149
+ adjusted = tuple(round(channel * factor) for channel in channels)
150
+ elif mode in {"lighten", "lightenLess"}:
151
+ amount = 0.4 if mode == "lighten" else 0.2
152
+ adjusted = tuple(
153
+ round(channel + (255 - channel) * amount)
154
+ for channel in channels
155
+ )
156
+ else:
157
+ return
158
+ attrs["fill"] = "#" + "".join(
159
+ f"{channel:02X}" for channel in adjusted
160
+ )
161
+
162
+
163
+ def remove_stroke_attrs(attrs: dict[str, str]) -> None:
164
+ """Remove inherited stroke and marker attributes from one path layer."""
165
+ for name in tuple(attrs):
166
+ if name.startswith("stroke") or name in {"marker-start", "marker-end"}:
167
+ attrs.pop(name, None)
168
+
169
+
170
+ def attrs_to_xml(attrs: Mapping[str, str]) -> str:
171
+ """Serialize SVG attributes in deterministic insertion order."""
172
+ return "".join(
173
+ f' {name}="{_xml_escape(value)}"'
174
+ for name, value in attrs.items()
175
+ )
176
+
177
+
178
+ def _xml_escape(value: str) -> str:
179
+ text = str(value)
180
+ if any(not _is_xml_10_character(character) for character in text):
181
+ raise ValueError("SVG markup contains an XML 1.0-incompatible character")
182
+ return (
183
+ text
184
+ .replace("&", "&amp;")
185
+ .replace("<", "&lt;")
186
+ .replace(">", "&gt;")
187
+ .replace('"', "&quot;")
188
+ )
189
+
190
+
191
+ def _is_xml_10_character(character: str) -> bool:
192
+ codepoint = ord(character)
193
+ return (
194
+ codepoint in {0x09, 0x0A, 0x0D}
195
+ or 0x20 <= codepoint <= 0xD7FF
196
+ or 0xE000 <= codepoint <= 0xFFFD
197
+ or 0x10000 <= codepoint <= 0x10FFFF
198
+ )
@@ -0,0 +1,162 @@
1
+ """DrawingML <a:prstGeom> -> SVG geometry conversion.
2
+
3
+ The visible SVG geometry is accompanied by the source preset name and every
4
+ explicit ``a:avLst`` guide formula. This metadata is rendering-neutral and
5
+ lets the reverse converter distinguish a native PowerPoint shape from an
6
+ arbitrary SVG path without guessing from its appearance.
7
+
8
+ The standard preset catalog is evaluated by the shared data-driven geometry
9
+ engine. Presets outside that locked catalog retain their source semantics on
10
+ an explicitly marked bounding-box fallback; they never masquerade as ``rect``.
11
+
12
+ The evaluated result carries one or more painted SVG path layers plus the
13
+ rendering-neutral metadata used by the reverse converter.
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ from dataclasses import dataclass, field
19
+ from xml.etree import ElementTree as ET
20
+
21
+ from pptx_shapes import get_preset_registry
22
+
23
+ from .emu_units import NS, Xfrm, fmt_num
24
+ from .preset_registry_to_svg import SvgPresetPath, render_preset_geometry
25
+
26
+
27
+ # ---------------------------------------------------------------------------
28
+ # GeomResult
29
+ # ---------------------------------------------------------------------------
30
+
31
+ @dataclass
32
+ class GeomResult:
33
+ """Result of converting a prst preset to SVG.
34
+
35
+ `tag` is the SVG element tag (rect / ellipse / line / polygon / path /
36
+ polyline). `attrs` are absolute SVG coordinates already in slide space.
37
+ `path_d` (when tag == 'path') is the d attribute. The slide assembler
38
+ merges fill/stroke attrs from fill_to_svg/ln_to_svg.
39
+ """
40
+
41
+ tag: str
42
+ attrs: dict[str, str] = field(default_factory=dict)
43
+ # When tag == 'path' use path_d for the d attribute.
44
+ path_d: str | None = None
45
+ # When tag == 'polygon' / 'polyline' use points for the points attribute.
46
+ points: str | None = None
47
+ # Standard presets can contain multiple independently painted path layers.
48
+ layers: tuple[SvgPresetPath, ...] = ()
49
+
50
+
51
+ # ---------------------------------------------------------------------------
52
+ # Explicit fallback for presets outside the locked standard catalog
53
+ # ---------------------------------------------------------------------------
54
+
55
+ def _rect(xfrm: Xfrm) -> GeomResult:
56
+ return GeomResult(
57
+ tag="rect",
58
+ attrs={
59
+ "x": fmt_num(xfrm.x),
60
+ "y": fmt_num(xfrm.y),
61
+ "width": fmt_num(xfrm.w),
62
+ "height": fmt_num(xfrm.h),
63
+ },
64
+ )
65
+
66
+
67
+ # ---------------------------------------------------------------------------
68
+ # Dispatch
69
+ # ---------------------------------------------------------------------------
70
+
71
+ def convert_prst_geom(
72
+ prst: str,
73
+ xfrm: Xfrm,
74
+ sp_pr: ET.Element | None,
75
+ ) -> GeomResult | None:
76
+ """Convert <a:prstGeom prst="..."> to a GeomResult.
77
+
78
+ Every emitted result carries ``data-pptx-prst`` plus one
79
+ ``data-pptx-av-<name>`` attribute per explicit adjustment guide. Unknown
80
+ presets use a visibly neutral bounding-box fallback with diagnostic
81
+ metadata instead of silently changing their semantic type to ``rect``.
82
+
83
+ Returns ``None`` only when the logical frame cannot produce geometry.
84
+ """
85
+ metadata = _preset_metadata(prst, sp_pr)
86
+ registry = get_preset_registry()
87
+ if prst not in registry:
88
+ result = _rect(xfrm)
89
+ result.attrs.update(metadata)
90
+ result.attrs.update({
91
+ "data-pptx-geometry-status": "unsupported",
92
+ "data-pptx-geometry-reason": f"unsupported-preset:{prst}",
93
+ })
94
+ return result
95
+ if xfrm.w < 0 or xfrm.h < 0 or (xfrm.w == 0 and xfrm.h == 0):
96
+ return None
97
+
98
+ try:
99
+ rendered = render_preset_geometry(
100
+ prst,
101
+ xfrm,
102
+ _preset_adjustments(sp_pr),
103
+ )
104
+ except ValueError as exc:
105
+ result = _rect(xfrm)
106
+ result.attrs.update(metadata)
107
+ result.attrs.update({
108
+ "data-pptx-geometry-status": "unsupported",
109
+ "data-pptx-geometry-reason": (
110
+ f"preset-evaluation-error:{type(exc).__name__}"
111
+ ),
112
+ })
113
+ return result
114
+ if not rendered.paths:
115
+ return None
116
+ return GeomResult(
117
+ tag="path",
118
+ attrs=metadata,
119
+ path_d=" ".join(path.d for path in rendered.paths),
120
+ layers=rendered.paths,
121
+ )
122
+
123
+
124
+ def _preset_metadata(
125
+ prst: str,
126
+ prst_geom: ET.Element | None,
127
+ ) -> dict[str, str]:
128
+ """Return rendering-neutral SVG attributes for native preset semantics."""
129
+ attrs = {"data-pptx-prst": prst}
130
+ if prst_geom is None:
131
+ return attrs
132
+
133
+ av_lst = prst_geom.find("a:avLst", NS)
134
+ if av_lst is None:
135
+ return attrs
136
+ for guide in av_lst.findall("a:gd", NS):
137
+ name = guide.attrib.get("name", "")
138
+ if not name:
139
+ continue
140
+ attrs[f"data-pptx-av-{name}"] = guide.attrib.get("fmla", "")
141
+ return attrs
142
+
143
+
144
+ def _preset_adjustments(
145
+ prst_geom: ET.Element | None,
146
+ ) -> dict[str, str]:
147
+ """Return explicit instance adjustment formulas for registry evaluation."""
148
+ if prst_geom is None:
149
+ return {}
150
+ av_lst = prst_geom.find("a:avLst", NS)
151
+ if av_lst is None:
152
+ return {}
153
+ return {
154
+ guide.attrib["name"]: guide.attrib.get("fmla", "")
155
+ for guide in av_lst.findall("a:gd", NS)
156
+ if guide.attrib.get("name")
157
+ }
158
+
159
+
160
+ def supported_presets() -> set[str]:
161
+ """Return the set of recognized prst values for diagnostics."""
162
+ return set(get_preset_registry().names)