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(template-import): preserve inherited placeholder appearance
hugohe3d78d3640b28a
diff --git a/skills/ppt-master/scripts/mirror_template_materialize.py b/skills/ppt-master/scripts/mirror_template_materialize.pyindex 8e74c3d3..5bd550ac 100644--- a/skills/ppt-master/scripts/mirror_template_materialize.py+++ b/skills/ppt-master/scripts/mirror_template_materialize.py@@ -1402,6 +1402,170 @@ def _copy_text_carrier(source: ET.Element | None) -> ET.Element | None:return carrier+def _visible_placeholder_decoration(element: ET.Element) -> bool:+ """Return whether one non-text placeholder subtree paints any pixels."""+ if _hidden(element):+ return False+ tag = _local_name(element.tag)+ if tag in _NON_VISUAL_TAGS or tag == "text":+ return False+ if tag in {"g", "svg", "a"}:+ return any(_visible_placeholder_decoration(child) for child in element)+ if tag in {"image", "foreignObject", "use"}:+ return _visible_leaf(element)+ if tag in {"line", "polyline"}:+ stroke = _paint_value(element, "stroke")+ return stroke not in {None, "none", "transparent"}+ if tag in {"rect", "path", "polygon", "circle", "ellipse"}:+ fill = _paint_value(element, "fill")+ stroke = _paint_value(element, "stroke")+ filter_value = _paint_value(element, "filter")+ return (+ fill not in {"none", "transparent"}+ or stroke not in {None, "none", "transparent"}+ or filter_value not in {None, "none"}+ )+ return False+++def _placeholder_decorations(source: ET.Element | None) -> list[ET.Element]:+ """Copy direct visual children that decorate one text placeholder."""+ if source is None:+ return []+ decorations = [+ copy.deepcopy(child)+ for child in source+ if _visible_placeholder_decoration(child)+ ]+ for decoration in decorations:+ _merge_group_inheritance(source, decoration)+ _copy_placeholder_native_attributes(source, decorations)+ return decorations+++def _copy_placeholder_native_attributes(+ source: ET.Element,+ geometries: list[ET.Element],+) -> None:+ """Carry one logical placeholder geometry's native identity to its leaf."""+ if len(geometries) == 1:+ decoration = geometries[0]+ native_attributes = {+ "data-pptx-frame",+ "data-pptx-geometry-kind",+ "data-pptx-geometry-reason",+ "data-pptx-geometry-sha256",+ "data-pptx-geometry-status",+ "data-pptx-object",+ "data-pptx-prst",+ }+ for name, value in source.attrib.items():+ if name in native_attributes or name.startswith("data-pptx-av-"):+ if decoration.get(name) is None:+ decoration.set(name, value)+++def _placeholder_geometry(source: ET.Element | None) -> list[ET.Element]:+ """Copy direct source geometry even when it has no visible local paint."""+ if source is None:+ return []+ geometry_tags = {+ "circle",+ "ellipse",+ "line",+ "path",+ "polygon",+ "polyline",+ "rect",+ }+ geometries = [+ copy.deepcopy(child)+ for child in source+ if _local_name(child.tag) in geometry_tags and not _hidden(child)+ ]+ for geometry in geometries:+ _merge_group_inheritance(source, geometry)+ _copy_placeholder_native_attributes(source, geometries)+ return geometries+++def _apply_placeholder_paint(source: ET.Element, target: ET.Element) -> None:+ """Apply inherited paint without replacing Slide-owned geometry."""+ paint_attributes = {+ "color",+ "fill",+ "fill-opacity",+ "fill-rule",+ "filter",+ "mix-blend-mode",+ "opacity",+ "paint-order",+ "shape-rendering",+ "stroke",+ "stroke-dasharray",+ "stroke-dashoffset",+ "stroke-linecap",+ "stroke-linejoin",+ "stroke-miterlimit",+ "stroke-opacity",+ "stroke-width",+ "vector-effect",+ }+ source_style = _parse_style(source.get("style"))+ target_style = _parse_style(target.get("style"))+ for name in paint_attributes:+ value = source.get(name)+ if value is None:+ value = source_style.get(name)+ if value is None:+ continue+ target.set(name, value)+ target_style.pop(name, None)+ if target_style:+ target.set("style", _style_text(target_style))+ else:+ target.attrib.pop("style", None)+++def _resolved_placeholder_decorations(+ source: ET.Element | None,+ layout_guide: ET.Element | None,+ master_guide: ET.Element | None,+) -> list[ET.Element]:+ """Resolve text-placeholder decoration through Slide/Layout/Master."""+ local = _placeholder_decorations(source)+ if local:+ return local++ inherited: list[ET.Element] = []+ for candidate in (layout_guide, master_guide):+ inherited = _placeholder_decorations(candidate)+ if inherited:+ break+ if (+ source is None+ or source.get("data-pptx-placeholder-local-geometry") != "true"+ or len(inherited) != 1+ ):+ return inherited++ source_geometry = _placeholder_geometry(source)+ inherited_tag = _local_name(inherited[0].tag)+ if not source_geometry or inherited_tag not in {+ "circle",+ "ellipse",+ "line",+ "path",+ "polygon",+ "polyline",+ "rect",+ }:+ return inherited+ for geometry in source_geometry:+ _apply_placeholder_paint(inherited[0], geometry)+ return source_geometry++def _normalize_mergeable_tspans(text: ET.Element) -> None:"""Mark the first line of a positional text block for paragraph merging."""tspans = [child for child in text if _local_name(child.tag) == "tspan"]@@ -1495,13 +1659,13 @@ def _slot_wrapper(carrier = _copy_text_carrier(source)if carrier is None:carrier = _blank_text_carrier(plan, layout_guide, master_guide)- if source is not None:- for child in source:- if _local_name(child.tag) == "text" or not _visible_leaf(child):- continue- extra = copy.deepcopy(child)- extra.attrib.pop("data-pptx-placeholder-carrier", None)- extras.append(extra)+ extras = _resolved_placeholder_decorations(+ source,+ layout_guide,+ master_guide,+ )+ for extra in extras:+ extra.attrib.pop("data-pptx-placeholder-carrier", None)wrapper.append(carrier)return wrapper, extrasdiff --git a/skills/ppt-master/scripts/pptx_to_svg/shape_walker.py b/skills/ppt-master/scripts/pptx_to_svg/shape_walker.pyindex 417247df..ca21020f 100644--- a/skills/ppt-master/scripts/pptx_to_svg/shape_walker.py+++ b/skills/ppt-master/scripts/pptx_to_svg/shape_walker.py@@ -73,6 +73,7 @@ class ShapeNode:hidden: bool = Falseplaceholder: PlaceholderInfo | None = Noneinherited_lst_styles: tuple[ET.Element, ...] = ()+ inherited_body_properties: tuple[ET.Element, ...] = ()# GROUP only: children, in z-orderchildren: list["ShapeNode"] = field(default_factory=list)@@ -220,6 +221,10 @@ def _walk_container(tuple[str | None, str | None],list[ET.Element],] | None = None,+ placeholder_body_properties: dict[+ tuple[str | None, str | None],+ list[ET.Element],+ ] | None = None,) -> list[ShapeNode]:"""Walk a p:spTree or p:grpSp subtree. Children kept in document (z) order."""@@ -268,11 +273,18 @@ def _walk_container(inherited_lst_styles = _lookup_placeholder_lst_styles(ph, placeholder_lst_styles,)+ inherited_body_properties: tuple[ET.Element, ...] = ()+ if ph is not None and placeholder_body_properties:+ inherited_body_properties = _lookup_placeholder_body_properties(+ ph,+ placeholder_body_properties,+ )node = ShapeNode(kind=kind, xml=child, xfrm=xfrm,name=name, spid=spid, hidden=hidden, placeholder=ph,inherited_lst_styles=inherited_lst_styles,+ inherited_body_properties=inherited_body_properties,)if kind == GROUP:@@ -280,6 +292,7 @@ def _walk_container(child, xfrm,placeholder_xfrms=placeholder_xfrms,placeholder_lst_styles=placeholder_lst_styles,+ placeholder_body_properties=placeholder_body_properties,)nodes.append(node)@@ -326,6 +339,22 @@ def _lookup_placeholder_lst_styles(return tuple(styles)+def _lookup_placeholder_body_properties(+ ph: PlaceholderInfo,+ table: dict[tuple[str | None, str | None], list[ET.Element]],+) -> tuple[ET.Element, ...]:+ """Find inherited txBody/bodyPr elements for a placeholder."""+ ph_type, ph_idx = _placeholder_identity(ph.type, ph.idx)+ exact = table.get((ph_type, ph_idx), [])+ if exact:+ return tuple(exact)+ for key in ((ph_type, None), (None, ph_idx)):+ candidates = table.get(key, [])+ if candidates:+ return (candidates[0],)+ return ()++def _placeholder_tx_style_key(ph: PlaceholderInfo,) -> tuple[str | None, str | None]:@@ -419,6 +448,37 @@ def _build_placeholder_lst_style_table(return table+def _build_placeholder_body_property_table(+ *parts: ET.Element | None,+) -> dict[tuple[str | None, str | None], list[ET.Element]]:+ """Index placeholder txBody/bodyPr elements in priority order."""+ table: dict[tuple[str | None, str | None], list[ET.Element]] = {}+ for part_xml in parts:+ if part_xml is None:+ continue+ sp_tree = part_xml.find("p:cSld/p:spTree", NS)+ if sp_tree is None:+ continue+ for sp in sp_tree.iter():+ if not isinstance(sp.tag, str) or sp.tag.split("}", 1)[-1] != "sp":+ continue+ ph_elem = sp.find("p:nvSpPr/p:nvPr/p:ph", NS)+ body_pr = sp.find("p:txBody/a:bodyPr", NS)+ if ph_elem is None or body_pr is None:+ continue+ ph_type, ph_idx = _placeholder_identity(+ ph_elem.attrib.get("type"),+ ph_elem.attrib.get("idx"),+ )+ for key in (+ (ph_type, ph_idx),+ (ph_type, None),+ (None, ph_idx),+ ):+ table.setdefault(key, []).append(body_pr)+ return table++def _append_master_tx_styles(table: dict[tuple[str | None, str | None], list[ET.Element]],part_xml: ET.Element,@@ -442,9 +502,9 @@ def walk_sp_tree("""Top-level entry: return shape nodes for a slide / layout / master XML.When ``slide_xml`` is a regular slide, pass its ``layout_xml`` and- ``master_xml`` so placeholders can inherit geometry and text list styles- from the layout/master. Layout and master walks pass neither — their own- placeholders are the source of truth.+ ``master_xml`` so placeholders can inherit geometry, text list styles, and+ body properties from the layout/master. Layout and master walks pass+ neither — their own placeholders are the source of truth."""sp_tree = slide_xml.find("p:cSld/p:spTree", NS)if sp_tree is None:@@ -453,10 +513,15 @@ def walk_sp_tree(placeholder_lst_styles = _build_placeholder_lst_style_table(layout_xml, master_xml,)+ placeholder_body_properties = _build_placeholder_body_property_table(+ layout_xml,+ master_xml,+ )return _walk_container(sp_tree, parent_group_xfrm=None,placeholder_xfrms=placeholder_xfrms or None,placeholder_lst_styles=placeholder_lst_styles or None,+ placeholder_body_properties=placeholder_body_properties or None,)diff --git a/skills/ppt-master/scripts/pptx_to_svg/slide_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/slide_to_svg.pyindex f9234c0c..020ca658 100644--- a/skills/ppt-master/scripts/pptx_to_svg/slide_to_svg.py+++ b/skills/ppt-master/scripts/pptx_to_svg/slide_to_svg.py@@ -23,6 +23,7 @@ animation anchor.from __future__ import annotationsimport base64+import copyimport hashlibimport jsonfrom dataclasses import dataclass, field@@ -351,8 +352,8 @@ def assemble_part_solo(if bg_xml:body_parts.append(bg_xml)- # Walk shapes. Placeholders are visualized as lightweight layout guides in- # layered master/layout SVGs so template slots remain machine-visible.+ # Walk shapes. Layered master/layout SVGs retain each placeholder's source+ # appearance so mirror materialization can recover its editable decoration.for node in walk_sp_tree(part.xml):if _is_placeholder_node(node):chunk = _convert_placeholder_guide(node, ctx, top_level=True)@@ -471,9 +472,13 @@ def _convert_shape(node: ShapeNode, ctx: AssemblyContext, *, top_level: bool) ->ctx.media.update(blip_result.media)# Text body (a:txBody)- tx_body = node.xml.find("p:txBody", NS)+ source_tx_body = node.xml.find("p:txBody", NS)+ tx_body = _effective_placeholder_tx_body(+ source_tx_body,+ node.inherited_body_properties,+ )is_vertical = is_vertical_txbody(tx_body, node.xfrm)- local_has_run_effects = txbody_has_run_effects(tx_body)+ local_has_run_effects = txbody_has_run_effects(source_tx_body)inherited_has_run_effects = txbody_has_run_effects(*node.inherited_lst_styles)@@ -556,10 +561,10 @@ def _convert_shape(node: ShapeNode, ctx: AssemblyContext, *, top_level: bool) ->inner_parts.append(blip_image)if geom_xml:inner_parts.append(geom_xml)- if tx_body is not None and geom is not None:+ if source_tx_body is not None and geom is not None:inner_parts.append(_txbody_metadata(- tx_body,+ source_tx_body,text_result.svg,))@@ -575,6 +580,51 @@ def _convert_shape(node: ShapeNode, ctx: AssemblyContext, *, top_level: bool) ->)+def _effective_placeholder_tx_body(+ tx_body: ET.Element | None,+ inherited_body_properties: tuple[ET.Element, ...],+) -> ET.Element | None:+ """Merge inherited placeholder bodyPr settings into one visible text body."""+ if tx_body is None or not inherited_body_properties:+ return tx_body+ effective = copy.deepcopy(tx_body)+ body_pr = effective.find("a:bodyPr", NS)+ if body_pr is None:+ body_pr = ET.Element(f"{{{NS['a']}}}bodyPr")+ effective.insert(0, body_pr)++ child_groups = (+ {"prstTxWarp"},+ {"noAutofit", "normAutofit", "spAutoFit"},+ {"scene3d"},+ {"sp3d"},+ )+ for inherited in inherited_body_properties:+ for name, value in inherited.attrib.items():+ body_pr.attrib.setdefault(name, value)+ local_names = {+ child.tag.rsplit("}", 1)[-1]+ for child in body_pr+ if isinstance(child.tag, str)+ }+ for group in child_groups:+ if local_names & group:+ continue+ inherited_child = next(+ (+ child+ for child in inherited+ if isinstance(child.tag, str)+ and child.tag.rsplit("}", 1)[-1] in group+ ),+ None,+ )+ if inherited_child is not None:+ body_pr.append(copy.deepcopy(inherited_child))+ local_names.add(inherited_child.tag.rsplit("}", 1)[-1])+ return effective++def _txbody_metadata(tx_body: ET.Element,visible_text_svg: str,@@ -1374,24 +1424,8 @@ def _is_placeholder_node(node: ShapeNode) -> bool:def _convert_placeholder_guide(node: ShapeNode, ctx: AssemblyContext,*, top_level: bool) -> str:- """Emit a lightweight visible guide for template placeholder slots."""- ph = node.placeholder- label_parts = ["ph"]- if ph is not None:- if ph.type:- label_parts.append(ph.type)- if ph.idx:- label_parts.append(f"idx={ph.idx}")- label = " ".join(label_parts)- guide = (- f'<rect x="{fmt_num(node.xfrm.x)}" y="{fmt_num(node.xfrm.y)}" '- f'width="{fmt_num(node.xfrm.w)}" height="{fmt_num(node.xfrm.h)}" '- f'fill="#F8FAFC" fill-opacity="0.18" stroke="#94A3B8" '- f'stroke-dasharray="6 4" stroke-width="1"/>'- f'<text x="{fmt_num(node.xfrm.x + 8)}" y="{fmt_num(node.xfrm.y + 18)}" '- f'font-size="12" fill="#64748B">{_xml_escape(label)}</text>'- )- return _wrap_shape_group(guide, node, ctx, top_level=top_level)+ """Emit the source-authored appearance of one template placeholder."""+ return _convert_node(node, ctx, top_level=top_level)# ---------------------------------------------------------------------------@@ -1430,6 +1464,13 @@ def _wrap_shape_group(attrs.append(f'data-name="{_xml_escape(node.name)}"')if node.placeholder is not None and node.placeholder.type:attrs.append(f'data-ph-type="{_xml_escape(node.placeholder.type)}"')+ if node.placeholder is not None and node.kind == SHAPE:+ sp_pr = node.xml.find("p:spPr", NS)+ if sp_pr is not None and any(+ sp_pr.find(path, NS) is not None+ for path in ("a:xfrm", "a:prstGeom", "a:custGeom")+ ):+ attrs.append('data-pptx-placeholder-local-geometry="true"')if extra_attrs:attrs.extend(extra_attrs)if any(diff --git a/skills/ppt-master/scripts/pptx_to_svg/txbody_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/txbody_to_svg.pyindex 678ecf9a..fb3ffa41 100644--- a/skills/ppt-master/scripts/pptx_to_svg/txbody_to_svg.py+++ b/skills/ppt-master/scripts/pptx_to_svg/txbody_to_svg.py@@ -135,6 +135,10 @@ def convert_txbody(bins = _read_emu_attr(body_pr, "bIns", DEFAULT_INSETS_EMU["b"])anchor = body_pr.attrib.get("anchor", "t") if body_pr is not None else "t"wrap_mode = body_pr.attrib.get("wrap", "square") if body_pr is not None else "square"+ respect_edge_spacing = (+ body_pr is not None+ and body_pr.attrib.get("spcFirstLastPara") in {"1", "true"}+ )inner_x = xfrm.x + linsinner_y = xfrm.y + tins@@ -152,7 +156,19 @@ def convert_txbody(_paragraph_height_from_lines(p, lines)for p, lines in zip(paragraphs, para_lines)]- total_h = sum(para_heights)+ space_before = [paragraph.space_before_px for paragraph in paragraphs]+ space_after = [paragraph.space_after_px for paragraph in paragraphs]+ if not respect_edge_spacing:+ space_before[0] = 0.0+ space_after[-1] = 0.0+ total_h = sum(+ before + height + after+ for before, height, after in zip(+ space_before,+ para_heights,+ space_after,+ )+ )if anchor == "ctr":cursor_y = inner_y + max(0.0, (inner_h - total_h) / 2.0)elif anchor == "b":@@ -162,14 +178,20 @@ def convert_txbody(bottom_y = inner_y + inner_htext_blocks: list[str] = []- for para, lines, height in zip(paragraphs, para_lines, para_heights):- cursor_y += para.space_before_px+ for para, lines, height, before, after in zip(+ paragraphs,+ para_lines,+ para_heights,+ space_before,+ space_after,+ ):+ cursor_y += beforevisible_lines = _clip_lines_to_bottom(para, lines, cursor_y, bottom_y)if visible_lines:text_blocks.append(_emit_paragraph(para, visible_lines, inner_x, inner_w, cursor_y))- cursor_y += height + para.space_after_px+ cursor_y += height + afterif cursor_y >= bottom_y:break