dknowc-dsh 1.0.4 → 1.1.1

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 (162) 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/skills/dknowc-trusted-search/SKILL.md +8 -7
  159. package/skills/dknowc-trusted-search/scripts/adapt_mcp_result.py +19 -37
  160. package/skills/dknowc-trusted-search/scripts/deep_query.py +117 -137
  161. package/skills/dknowc-trusted-search/scripts/render_trace_html.py +27 -22
  162. package/src/index.js +7 -2
@@ -0,0 +1,422 @@
1
+ """Extract native ChartEx payloads from PPTX chart parts.
2
+
3
+ The parser is deliberately closed around the seven ChartEx data models that
4
+ the native writer already emits. Data topology and caches must be complete;
5
+ unmodeled chart chrome, labels, axes, binning options, and style details are
6
+ allowed to normalize during editable native reconstruction.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import math
12
+ import re
13
+ from typing import Any
14
+ from xml.etree import ElementTree as ET
15
+
16
+ from svg_to_pptx.native_objects.chart_data import validate_chart_payload
17
+ from svg_to_pptx.native_objects.marker_common import CHART_COLOR_STYLE_REL_TYPE
18
+
19
+ from .color_resolver import COLOR_TAGS, ColorPalette, resolve_color
20
+ from .emu_units import NS, Xfrm
21
+ from .ooxml_loader import OoxmlPackage, PartRef
22
+
23
+
24
+ CHARTEX_URI = "http://schemas.microsoft.com/office/drawing/2014/chartex"
25
+
26
+ CX_NS = {
27
+ **NS,
28
+ "cx": CHARTEX_URI,
29
+ }
30
+
31
+ _INT_TOKEN_RE = re.compile(r"[0-9]+")
32
+ _HIERARCHY_LAYOUTS = {"sunburst", "treemap"}
33
+ _FLAT_LAYOUTS = {"funnel", "waterfall"}
34
+ _LEGEND_POSITIONS = {"b", "l", "r", "t"}
35
+
36
+
37
+ class UnsupportedChartEx(RuntimeError):
38
+ """A ChartEx part cannot map to the current native authoring schema."""
39
+
40
+ def __init__(self, status: str) -> None:
41
+ super().__init__(status)
42
+ self.status = status
43
+
44
+
45
+ def extract_native_chartex_payload(
46
+ graphic_data: ET.Element | None,
47
+ xfrm: Xfrm,
48
+ slide_part: PartRef,
49
+ pkg: OoxmlPackage,
50
+ palette: ColorPalette | None = None,
51
+ ) -> dict[str, Any]:
52
+ """Return a writer-valid payload for one supported ChartEx reference.
53
+
54
+ ``UnsupportedChartEx.status`` is suitable for
55
+ ``data-pptx-replacement-status`` when the reference, relationship, data
56
+ topology, or cache is unusable.
57
+ Style-part failures never reject an otherwise valid data payload.
58
+ """
59
+ if graphic_data is None:
60
+ raise UnsupportedChartEx("unsupported-chart-reference")
61
+ if xfrm.rot or xfrm.flip_h or xfrm.flip_v:
62
+ raise UnsupportedChartEx("unsupported-native-transform")
63
+
64
+ chart_ref = graphic_data.find("cx:chart", CX_NS)
65
+ if chart_ref is None:
66
+ raise UnsupportedChartEx("unsupported-chart-reference")
67
+ rid = chart_ref.attrib.get(f"{{{NS['r']}}}id")
68
+ if not rid:
69
+ raise UnsupportedChartEx("unsupported-chart-reference")
70
+
71
+ chart_path = slide_part.resolve_rel(rid)
72
+ if not chart_path:
73
+ raise UnsupportedChartEx("unsupported-chart-relationship")
74
+ chart_part = pkg.load_part(chart_path)
75
+ if chart_part is None:
76
+ raise UnsupportedChartEx("unsupported-chart-part")
77
+
78
+ try:
79
+ payload = _payload_from_chartex_xml(chart_part.xml, xfrm)
80
+ colors = _resolved_chart_colors(chart_part, pkg, palette)
81
+ if colors:
82
+ payload["style"] = {"colors": colors}
83
+ validate_chart_payload(payload)
84
+ except UnsupportedChartEx:
85
+ raise
86
+ except RuntimeError as exc:
87
+ raise UnsupportedChartEx("unsupported-chartex-schema") from exc
88
+ except (AttributeError, OverflowError, TypeError, ValueError) as exc:
89
+ raise UnsupportedChartEx("unsupported-chartex-parse") from exc
90
+ return payload
91
+
92
+
93
+ def _payload_from_chartex_xml(
94
+ chart_root: ET.Element,
95
+ xfrm: Xfrm,
96
+ ) -> dict[str, Any]:
97
+ if chart_root.tag != f"{{{CHARTEX_URI}}}chartSpace":
98
+ raise UnsupportedChartEx("unsupported-chartex-part")
99
+
100
+ chart_data = _one_child(chart_root, "chartData", "unsupported-chartex-structure")
101
+ chart = _one_child(chart_root, "chart", "unsupported-chartex-structure")
102
+ plot_area = _one_child(chart, "plotArea", "unsupported-chartex-structure")
103
+ region = _one_child(plot_area, "plotAreaRegion", "unsupported-chartex-structure")
104
+
105
+ data_by_id = _data_parts(chart_data)
106
+ series_nodes = _children(region, "series")
107
+ if not series_nodes:
108
+ raise UnsupportedChartEx("unsupported-chartex-series")
109
+
110
+ chart_type = _chart_type(series_nodes)
111
+ payload: dict[str, Any] = {
112
+ **_bounds_payload(xfrm),
113
+ "type": chart_type,
114
+ }
115
+
116
+ referenced_data_ids: list[int]
117
+ if chart_type in _HIERARCHY_LAYOUTS:
118
+ data_id = _series_data_id(series_nodes[0])
119
+ data = _require_data(data_by_id, data_id)
120
+ raw_levels = _string_dimension(data, expected_levels=None)
121
+ values = _numeric_dimension(data, "size")
122
+ if not raw_levels or any(len(level) != len(values) for level in raw_levels):
123
+ raise UnsupportedChartEx("unsupported-chartex-cache")
124
+ # ChartEx serializes the innermost level first; the authoring schema
125
+ # and workbook writer use the natural outermost-to-innermost order.
126
+ payload["levels"] = list(reversed(raw_levels))
127
+ payload["values"] = values
128
+ if chart_type == "treemap":
129
+ parent_labels = _treemap_parent_labels(series_nodes[0])
130
+ if parent_labels is not None:
131
+ payload["parent_label_layout"] = parent_labels
132
+ referenced_data_ids = [data_id]
133
+ elif chart_type == "histogram":
134
+ data_id = _series_data_id(series_nodes[0])
135
+ data = _require_data(data_by_id, data_id)
136
+ _reject_dimensions(data, allowed={"numDim"})
137
+ payload["values"] = _numeric_dimension(data, "val")
138
+ referenced_data_ids = [data_id]
139
+ elif chart_type in {"funnel", "pareto", "waterfall"}:
140
+ data_id = _series_data_id(series_nodes[0])
141
+ data = _require_data(data_by_id, data_id)
142
+ categories = _string_dimension(data, expected_levels=1)[0]
143
+ values = _numeric_dimension(data, "val")
144
+ if len(categories) != len(values):
145
+ raise UnsupportedChartEx("unsupported-chartex-cache")
146
+ payload["categories"] = categories
147
+ payload["values"] = values
148
+ if chart_type == "waterfall":
149
+ payload["subtotals"] = _waterfall_subtotals(series_nodes[0])
150
+ referenced_data_ids = [data_id]
151
+ elif chart_type == "box_whisker":
152
+ items: list[dict[str, Any]] = []
153
+ referenced_data_ids = []
154
+ for index, series in enumerate(series_nodes, start=1):
155
+ data_id = _series_data_id(series)
156
+ if data_id in referenced_data_ids:
157
+ raise UnsupportedChartEx("unsupported-chartex-data-id")
158
+ data = _require_data(data_by_id, data_id)
159
+ categories = _string_dimension(data, expected_levels=1)[0]
160
+ values = _numeric_dimension(data, "val")
161
+ if len(categories) != len(values):
162
+ raise UnsupportedChartEx("unsupported-chartex-cache")
163
+ items.append({
164
+ "categories": categories,
165
+ "name": _series_name(series, index),
166
+ "values": values,
167
+ })
168
+ referenced_data_ids.append(data_id)
169
+ payload["series"] = items
170
+ else: # pragma: no cover - _chart_type is closed, keep the invariant explicit.
171
+ raise UnsupportedChartEx("unsupported-chartex-type")
172
+
173
+ if set(referenced_data_ids) != set(data_by_id):
174
+ raise UnsupportedChartEx("unsupported-chartex-data-id")
175
+
176
+ legend = chart.find("cx:legend", CX_NS)
177
+ if legend is not None:
178
+ payload["show_legend"] = True
179
+ position = legend.attrib.get("pos")
180
+ if position in _LEGEND_POSITIONS:
181
+ payload["legend_position"] = position
182
+ return payload
183
+
184
+
185
+ def _chart_type(series_nodes: list[ET.Element]) -> str:
186
+ layouts = [series.attrib.get("layoutId", "") for series in series_nodes]
187
+ if len(series_nodes) == 1 and layouts[0] in _HIERARCHY_LAYOUTS | _FLAT_LAYOUTS:
188
+ return layouts[0]
189
+ if layouts and all(layout == "boxWhisker" for layout in layouts):
190
+ return "box_whisker"
191
+ if len(series_nodes) == 1 and layouts == ["clusteredColumn"]:
192
+ if series_nodes[0].find("cx:layoutPr/cx:binning", CX_NS) is None:
193
+ raise UnsupportedChartEx("unsupported-chartex-series")
194
+ return "histogram"
195
+ if len(series_nodes) == 2 and layouts == ["clusteredColumn", "paretoLine"]:
196
+ primary, line = series_nodes
197
+ if (
198
+ primary.find("cx:layoutPr/cx:aggregation", CX_NS) is None
199
+ or line.attrib.get("ownerIdx") != "0"
200
+ or line.find("cx:dataId", CX_NS) is not None
201
+ ):
202
+ raise UnsupportedChartEx("unsupported-chartex-series")
203
+ return "pareto"
204
+ raise UnsupportedChartEx("unsupported-chartex-type")
205
+
206
+
207
+ def _data_parts(chart_data: ET.Element) -> dict[int, ET.Element]:
208
+ result: dict[int, ET.Element] = {}
209
+ for data in _children(chart_data, "data"):
210
+ data_id = _nonnegative_int(data.attrib.get("id"), "unsupported-chartex-data-id")
211
+ if data_id in result:
212
+ raise UnsupportedChartEx("unsupported-chartex-data-id")
213
+ result[data_id] = data
214
+ if not result:
215
+ raise UnsupportedChartEx("unsupported-chartex-data-id")
216
+ return result
217
+
218
+
219
+ def _series_data_id(series: ET.Element) -> int:
220
+ data_ids = _children(series, "dataId")
221
+ if len(data_ids) != 1:
222
+ raise UnsupportedChartEx("unsupported-chartex-data-id")
223
+ return _nonnegative_int(
224
+ data_ids[0].attrib.get("val"),
225
+ "unsupported-chartex-data-id",
226
+ )
227
+
228
+
229
+ def _require_data(data_by_id: dict[int, ET.Element], data_id: int) -> ET.Element:
230
+ data = data_by_id.get(data_id)
231
+ if data is None:
232
+ raise UnsupportedChartEx("unsupported-chartex-data-id")
233
+ return data
234
+
235
+
236
+ def _string_dimension(
237
+ data: ET.Element,
238
+ *,
239
+ expected_levels: int | None,
240
+ ) -> list[list[str]]:
241
+ _reject_dimensions(data, allowed={"strDim", "numDim"})
242
+ dimensions = [
243
+ child
244
+ for child in _children(data, "strDim")
245
+ if child.attrib.get("type") == "cat"
246
+ ]
247
+ if len(dimensions) != 1 or len(_children(data, "strDim")) != 1:
248
+ raise UnsupportedChartEx("unsupported-chartex-dimension")
249
+ levels = _children(dimensions[0], "lvl")
250
+ if not levels or (expected_levels is not None and len(levels) != expected_levels):
251
+ raise UnsupportedChartEx("unsupported-chartex-dimension")
252
+ return [_level_values(level, numeric=False) for level in levels]
253
+
254
+
255
+ def _numeric_dimension(data: ET.Element, dim_type: str) -> list[int | float]:
256
+ dimensions = [
257
+ child
258
+ for child in _children(data, "numDim")
259
+ if child.attrib.get("type") == dim_type
260
+ ]
261
+ if len(dimensions) != 1 or len(_children(data, "numDim")) != 1:
262
+ raise UnsupportedChartEx("unsupported-chartex-dimension")
263
+ levels = _children(dimensions[0], "lvl")
264
+ if len(levels) != 1:
265
+ raise UnsupportedChartEx("unsupported-chartex-dimension")
266
+ return _level_values(levels[0], numeric=True)
267
+
268
+
269
+ def _reject_dimensions(data: ET.Element, *, allowed: set[str]) -> None:
270
+ for child in data:
271
+ name = _local_name(child.tag)
272
+ if name.endswith("Dim") and name not in allowed:
273
+ raise UnsupportedChartEx("unsupported-chartex-dimension")
274
+
275
+
276
+ def _level_values(
277
+ level: ET.Element,
278
+ *,
279
+ numeric: bool,
280
+ ) -> list[Any]:
281
+ point_count = _nonnegative_int(
282
+ level.attrib.get("ptCount"),
283
+ "unsupported-chartex-cache",
284
+ )
285
+ points: dict[int, Any] = {}
286
+ for point in _children(level, "pt"):
287
+ point_index = _nonnegative_int(
288
+ point.attrib.get("idx"),
289
+ "unsupported-chartex-cache",
290
+ )
291
+ if point_index >= point_count or point_index in points or list(point):
292
+ raise UnsupportedChartEx("unsupported-chartex-cache")
293
+ raw_value = point.text or ""
294
+ points[point_index] = (
295
+ _numeric_value(raw_value)
296
+ if numeric
297
+ else raw_value
298
+ )
299
+ if (
300
+ len(points) != point_count
301
+ or any(index not in points for index in range(point_count))
302
+ ):
303
+ raise UnsupportedChartEx("unsupported-chartex-cache")
304
+ return [points[index] for index in range(point_count)]
305
+
306
+
307
+ def _numeric_value(raw_value: str) -> int | float:
308
+ if not raw_value.strip():
309
+ raise UnsupportedChartEx("unsupported-chartex-cache")
310
+ try:
311
+ number = float(raw_value)
312
+ except (OverflowError, ValueError):
313
+ raise UnsupportedChartEx("unsupported-chartex-cache") from None
314
+ if not math.isfinite(number):
315
+ raise UnsupportedChartEx("unsupported-chartex-cache")
316
+ return int(number) if number.is_integer() else number
317
+
318
+
319
+ def _waterfall_subtotals(series: ET.Element) -> list[int]:
320
+ subtotals: list[int] = []
321
+ for item in series.findall("cx:layoutPr/cx:subtotals/cx:idx", CX_NS):
322
+ subtotals.append(
323
+ _nonnegative_int(item.attrib.get("val"), "unsupported-chartex-cache")
324
+ )
325
+ return subtotals
326
+
327
+
328
+ def _treemap_parent_labels(series: ET.Element) -> str | None:
329
+ parent = series.find("cx:layoutPr/cx:parentLabelLayout", CX_NS)
330
+ if parent is None:
331
+ return None
332
+ value = parent.attrib.get("val")
333
+ return value if value in {"banner", "none", "overlapping"} else None
334
+
335
+
336
+ def _series_name(series: ET.Element, index: int) -> str:
337
+ value = series.findtext("cx:tx/cx:txData/cx:v", default="", namespaces=CX_NS)
338
+ return value or f"Series {index}"
339
+
340
+
341
+ def _resolved_chart_colors(
342
+ chart_part: PartRef,
343
+ pkg: OoxmlPackage,
344
+ palette: ColorPalette | None,
345
+ ) -> list[str]:
346
+ """Resolve the base color cycle; any style failure normalizes silently."""
347
+ try:
348
+ targets = [
349
+ info.get("target")
350
+ for info in chart_part.rels.values()
351
+ if info.get("type") == CHART_COLOR_STYLE_REL_TYPE
352
+ and not info.get("external")
353
+ and info.get("target")
354
+ ]
355
+ if len(targets) != 1:
356
+ return []
357
+ colors_part = pkg.load_part(str(targets[0]))
358
+ if colors_part is None:
359
+ return []
360
+ color_nodes = [
361
+ child
362
+ for child in colors_part.xml
363
+ if _namespace(child.tag) == NS["a"]
364
+ and _local_name(child.tag) in COLOR_TAGS
365
+ ]
366
+ if not color_nodes:
367
+ return []
368
+ colors: list[str] = []
369
+ for color_node in color_nodes:
370
+ color, _alpha = resolve_color(color_node, palette)
371
+ if color is None:
372
+ return []
373
+ colors.append(color)
374
+ return colors
375
+ except (AttributeError, OverflowError, RuntimeError, TypeError, ValueError):
376
+ return []
377
+
378
+
379
+ def _one_child(parent: ET.Element, name: str, status: str) -> ET.Element:
380
+ children = _children(parent, name)
381
+ if len(children) != 1:
382
+ raise UnsupportedChartEx(status)
383
+ return children[0]
384
+
385
+
386
+ def _children(parent: ET.Element, name: str) -> list[ET.Element]:
387
+ return [
388
+ child
389
+ for child in parent
390
+ if child.tag == f"{{{CHARTEX_URI}}}{name}"
391
+ ]
392
+
393
+
394
+ def _nonnegative_int(raw_value: str | None, status: str) -> int:
395
+ if raw_value is None or _INT_TOKEN_RE.fullmatch(raw_value) is None:
396
+ raise UnsupportedChartEx(status)
397
+ value = int(raw_value)
398
+ if value < 0:
399
+ raise UnsupportedChartEx(status)
400
+ return value
401
+
402
+
403
+ def _bounds_payload(xfrm: Xfrm) -> dict[str, int | float]:
404
+ return {
405
+ "height": _round_payload_number(xfrm.h),
406
+ "width": _round_payload_number(xfrm.w),
407
+ "x": _round_payload_number(xfrm.x),
408
+ "y": _round_payload_number(xfrm.y),
409
+ }
410
+
411
+
412
+ def _round_payload_number(value: float) -> int | float:
413
+ rounded = round(float(value), 3)
414
+ return int(rounded) if rounded.is_integer() else rounded
415
+
416
+
417
+ def _namespace(tag: str) -> str:
418
+ return tag[1:].split("}", 1)[0] if tag.startswith("{") else ""
419
+
420
+
421
+ def _local_name(tag: str) -> str:
422
+ return tag.rsplit("}", 1)[-1] if "}" in tag else tag