AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He
fix(mirror): bound zero-axis connectors and collinear groups from source frames
hugohe35832c3a8ca77
diff --git a/skills/ppt-master/scripts/mirror_template_materialize.py b/skills/ppt-master/scripts/mirror_template_materialize.pyindex 7035841c..4745173d 100644--- a/skills/ppt-master/scripts/mirror_template_materialize.py+++ b/skills/ppt-master/scripts/mirror_template_materialize.py@@ -56,6 +56,7 @@ from native_payloads import (serialize_native_payload_store,)from pptx_shapes import (+ CONNECTOR_PRESET_TYPES,NATIVE_FALLBACK_SHA256_ATTR,svg_native_fallback_fingerprint,svg_preset_preview_fingerprint,@@ -68,6 +69,7 @@ from svg_authoring_view import (semantic_subtree_sha256,)from svg_finalize.flatten_tspan import flatten_text_with_tspans+from svg_to_pptx.drawingml.utils import parse_transform_matrix, transform_pointfrom svg_to_pptx.pptx_package.template_structure import (SOURCE_THEMES_FILENAME,SOURCE_THEMES_SCHEMA,@@ -1642,6 +1644,93 @@ def _frame(element: ET.Element | None) -> tuple[float, float, float, float] | Noreturn values+def _source_bounds(+ element: ET.Element,+ stroke_width: float = 1.0,+) -> tuple[float, float, float, float] | None:+ """Bound a known source frame or native group's children without editing it."""+ raw = (element.get("data-pptx-frame") or "").replace(",", " ").split()+ if len(raw) != 4:+ return None+ try:+ x, y, width, height = (float(value) for value in raw)+ except ValueError:+ return None+ if (+ not all(math.isfinite(value) for value in (x, y, width, height))+ or width < 0 or height < 0+ or (width == 0 and height == 0)+ ):+ return None++ # Only the validation zone is padded; native frames and geometry stay exact.+ for child in element.iter():+ raw_stroke = _paint_value(child, "stroke-width")+ if raw_stroke is not None:+ try:+ value = float(raw_stroke)+ except ValueError:+ continue+ if math.isfinite(value):+ stroke_width = max(stroke_width, value)+ if width == 0:+ x -= stroke_width / 2+ width = stroke_width+ if height == 0:+ y -= stroke_width / 2+ height = stroke_width+ if element.get("data-pptx-object") == "group":+ child_bounds = [+ _source_bounds(child, stroke_width)+ for child in element if _visible_leaf(child)+ ]+ if not child_bounds or any(bounds is None for bounds in child_bounds):+ return None+ x = min(bounds[0] for bounds in child_bounds)+ y = min(bounds[1] for bounds in child_bounds)+ width = max(bounds[0] + bounds[2] for bounds in child_bounds) - x+ height = max(bounds[1] + bounds[3] for bounds in child_bounds) - y+ matrix = parse_transform_matrix(element.get("transform", ""))+ corners = [+ transform_point(matrix, px, py)+ for px in (x, x + width)+ for py in (y, y + height)+ ]+ left = min(point[0] for point in corners)+ top = min(point[1] for point in corners)+ return (+ left, top,+ max(point[0] for point in corners) - left,+ max(point[1] for point in corners) - top,+ )+++def _root_group_bounds(+ element: ET.Element,+ canvas_width: float,+ canvas_height: float,+) -> tuple[float, float, float, float] | None:+ bounds = _frame(element)+ if bounds is not None:+ return bounds+ if (+ element.get("data-pptx-object") not in {"connector", "group"}+ and element.get("data-pptx-prst") not in CONNECTOR_PRESET_TYPES+ ):+ return None+ bounds = _source_bounds(element)+ if bounds is None:+ return None+ # The page clips edge strokes; bounds describe their on-canvas module zone.+ x, y, width, height = bounds+ left, top = max(0.0, x), max(0.0, y)+ right = min(canvas_width, x + width)+ bottom = min(canvas_height, y + height)+ if right <= left or bottom <= top:+ return None+ return left, top, right - left, bottom - top++def _element_by_ref(root: ET.Element, source_ref: str) -> ET.Element | None:matches = [element@@ -2503,7 +2592,7 @@ def _compose_template(atoms[0].set("id", item.get("id"))item = atoms[0]if _local_name(item.tag) == "g" and _visible_leaf(item):- bounds = _frame(item)+ bounds = _root_group_bounds(item, width, height)if bounds is None:raise MirrorMaterializationError(f"Slide {slide['index']} root group "diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.pyindex 3ee9f0ac..c9bdb21d 100644--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py@@ -948,10 +948,15 @@ def _parse_preset_geometry_metadata(elem.get('data-pptx-object') == 'connector'or prst in CONNECTOR_PRESET_TYPES)- if is_connector:+ is_native_group = (+ elem.tag.rsplit('}', 1)[-1] == 'g'+ and elem.get('data-pptx-object') == 'group'+ )+ if is_connector or is_native_group:if frame[2] < 0 or frame[3] < 0 or (frame[2] == 0 and frame[3] == 0):+ kind = 'Connector' if is_connector else 'Group'raise ValueError(- 'Connector data-pptx-frame dimensions must be non-negative '+ f'{kind} data-pptx-frame dimensions must be non-negative 'f'and not both zero, got {raw_frame!r}')elif frame[2] <= 0 or frame[3] <= 0:diff --git a/skills/ppt-master/scripts/tests/test_template_flow_batch3.py b/skills/ppt-master/scripts/tests/test_template_flow_batch3.pyindex e2c228d9..dad3dd0b 100644--- a/skills/ppt-master/scripts/tests/test_template_flow_batch3.py+++ b/skills/ppt-master/scripts/tests/test_template_flow_batch3.py@@ -115,6 +115,65 @@ class TemplateFlowBatch3Tests(unittest.TestCase):self.assertEqual(line.tag, f'{{{SVG_NS}}}path')self.assertEqual(line.get('d'), 'M 0 80 L 1280 80')+ def _compose_slide(self, content: str) -> ET.Element:+ empty = ET.fromstring(f'<svg xmlns="{SVG_NS}"/>')+ return mirror._compose_template(+ native={'slideSize': {'width_px': 1280, 'height_px': 720}},+ master={'key': 'm', 'name': 'Master'},+ layout={'key': 'l', 'name': 'Layout', 'showMasterShapes': True},+ master_root=empty, layout_root=empty,+ slide={'index': 1, 'showInheritedShapes': True},+ slide_root=ET.fromstring(f'<svg xmlns="{SVG_NS}">{content}</svg>'),+ slot_plans=[],+ )++ def test_a_mirror_bounds_zero_axis_connectors_and_collinear_groups(self) -> None:+ result = self._compose_slide(+ '<g id="rule" data-pptx-object="connector" '+ 'data-pptx-prst="straightConnector1" data-pptx-frame="100 200 400 0">'+ '<path d="M 100 200 L 500 200" stroke="#000000" stroke-width="4" '+ 'fill="none"/></g>'+ '<g id="rules" data-pptx-object="group" data-pptx-frame="96 300 744 0">'+ '<g data-pptx-object="connector" data-pptx-prst="line" '+ 'data-pptx-frame="96 300 429 0"><path d="M 96 300 L 525 300" '+ 'stroke="#000000" stroke-width="2" fill="none"/></g>'+ '<g data-pptx-object="connector" data-pptx-prst="line" '+ 'data-pptx-frame="546 300 294 0"><path d="M 546 300 L 840 300" '+ 'stroke="#000000" stroke-width="2" fill="none"/></g></g>'+ )+ by_id = {e.get('id'): e for e in result.iter() if e.get('id')}+ self.assertEqual(by_id['rule'].get('data-pptx-bounds'), '100 198 400 4')+ self.assertEqual(by_id['rule'].get('data-pptx-frame'), '100 200 400 0')+ self.assertEqual(by_id['rules'].get('data-pptx-bounds'), '96 299 744 2')+ self.assertEqual(by_id['rules'].get('data-pptx-frame'), '96 300 744 0')++ def test_a_mirror_still_rejects_unknown_degenerate_groups(self) -> None:+ for frame in ('', ' data-pptx-frame="100 200 0 0"'):+ with self.subTest(frame=frame), self.assertRaisesRegex(+ mirror.MirrorMaterializationError, 'no positive source frame'+ ):+ self._compose_slide(+ f'<g id="lost" data-pptx-object="group"{frame}>'+ '<path d="M 100 200 L 500 200" stroke="#000000" '+ 'fill="none"/></g>'+ )++ def test_a_export_accepts_native_group_with_one_zero_axis(self) -> None:+ from svg_to_pptx.drawingml.elements import (+ _parse_preset_geometry_metadata,+ )++ group = ET.fromstring(+ f'<g xmlns="{SVG_NS}" data-pptx-object="group" '+ 'data-pptx-frame="96 300 744 0"/>'+ )+ self.assertEqual(+ _parse_preset_geometry_metadata(group)[2], (96.0, 300.0, 744.0, 0.0)+ )+ group.set('data-pptx-frame', '96 300 0 0')+ with self.assertRaisesRegex(ValueError, 'not both zero'):+ _parse_preset_geometry_metadata(group)+def test_a_type_b_has_actionable_rejection(self) -> None:stderr = io.StringIO()with contextlib.redirect_stderr(stderr):