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
feat(quick-generate): preserve explicit template structure
hugohe30b7b384cbf59
diff --git a/skills/ppt-master/scripts/svg_quality/checker.py b/skills/ppt-master/scripts/svg_quality/checker.pyindex 8798ce66..7a555d9a 100644--- a/skills/ppt-master/scripts/svg_quality/checker.py+++ b/skills/ppt-master/scripts/svg_quality/checker.py@@ -288,6 +288,7 @@ try:TemplateStructureError as _TemplateStructureError,_is_authored_preset_atom as _is_authored_preset_atom,load_pptx_structure_lock as _load_pptx_structure_lock,+ parse_optional_layout_slides as _parse_optional_layout_slides,parse_template_slide as _parse_template_structure_slide,parse_template_slides as _parse_template_structure_slides,_structure_subtree_signature as _structure_subtree_signature,@@ -299,6 +300,7 @@ except ImportError:_TemplateStructureError = None_is_authored_preset_atom = None_load_pptx_structure_lock = None+ _parse_optional_layout_slides = None_parse_template_structure_slide = None_parse_template_structure_slides = None_structure_subtree_signature = None@@ -4274,21 +4276,18 @@ class SVGQualityChecker:result: Dict,) -> None:"""Validate the intrinsic structured Master/Layout SVG contract."""- if self.quick_generate:- forbidden_attrs = sorted({- attr- for elem in root.iter()- for attr in _PPTX_STRUCTURE_ATTRS- if elem.get(attr) is not None- })- if forbidden_attrs:- result['errors'].append(- f"{svg_path.name}: Quick Generate uses flat export and "- "forbids Master/Layout/layer/placeholder metadata; remove "- + ', '.join(forbidden_attrs)- )+ has_structure_metadata = any(+ elem.get(attr) is not None+ for elem in root.iter()+ for attr in _PPTX_STRUCTURE_ATTRS+ )+ if self.quick_generate and not has_structure_metadata:return- if not self.template_mode and svg_path.parent.name == 'svg_output':+ if (+ not self.quick_generate+ and not self.template_mode+ and svg_path.parent.name == 'svg_output'+ ):declared_mode = _declared_pptx_structure_mode(self._resolve_project_path(svg_path))@@ -4310,11 +4309,6 @@ class SVGQualityChecker:# The project-level gate emits one actionable migration error.# Avoid burying it under repeated per-page structure failures.return- has_structure_metadata = any(- elem.get(attr) is not None- for elem in root.iter()- for attr in _PPTX_STRUCTURE_ATTRS- )require_structure = bool(self.template_modeor svg_path.parent.name == 'svg_output'@@ -5594,6 +5588,31 @@ class SVGQualityChecker:) -> None:"""Validate the all-page structured lock and reusable contracts."""if self.quick_generate:+ if (+ _parse_optional_layout_slides is None+ or _TemplateStructureError is None+ ):+ self._pptx_structure_issues.append((+ 'error',+ 'Quick PPTX structure inference is unavailable because '+ 'the template_structure module could not be imported.',+ ))+ return+ try:+ specs = _parse_optional_layout_slides(svg_files)+ except _TemplateStructureError as exc:+ self._pptx_structure_issues.append(('error', str(exc)))+ return+ if specs is None:+ return+ self._pptx_structure_issues.extend(+ ('error', message)+ for message in self._shared_fixed_layer_errors(specs)+ )+ self._pptx_structure_issues.extend(+ ('warning', message)+ for message in self._duplicate_layout_key_warnings(specs)+ )returnproject_path = self._resolve_project_path(target_path)standard_project = bool(diff --git a/skills/ppt-master/scripts/svg_quality/cli.py b/skills/ppt-master/scripts/svg_quality/cli.pyindex a19a0d8c..483a7a54 100644--- a/skills/ppt-master/scripts/svg_quality/cli.py+++ b/skills/ppt-master/scripts/svg_quality/cli.py@@ -77,7 +77,8 @@ def print_usage() -> None:print(" --json-output <path> Override the JSON report path")print(" --export Write a plain-text quality report")print(" --output <path> Override the plain-text report path")- print(" --quick-generate Validate lockless flat Quick Generate SVGs;")+ print(" --quick-generate Validate lockless Quick SVGs; infer flat or")+ print(" structured output from the complete roster;")print(" ignore design_spec.md and spec_lock.md.")print(" --canonical-authoring Require compact authoring syntax as written;")print(" the checker never rewrites source SVG.")diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/theme_fonts.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/theme_fonts.pyindex 645c52b1..f4837c2f 100644--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/theme_fonts.py+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/theme_fonts.py@@ -2,7 +2,9 @@from __future__ import annotations+import mathimport re+import statisticsfrom dataclasses import dataclassfrom pathlib import Pathfrom xml.etree import ElementTree as ET@@ -13,7 +15,17 @@ from .utils import font_px_to_hpt, parse_font_familyDML_NS = "http://schemas.openxmlformats.org/drawingml/2006/main"PML_NS = "http://schemas.openxmlformats.org/presentationml/2006/main"_LOCK_ROW_RE = re.compile(r"^-\s+([A-Za-z0-9_]+)\s*:\s*(.+?)\s*$")+_SVG_FONT_SIZE_RE = re.compile(r"^([0-9]+(?:\.[0-9]+)?)(?:px)?$")_CJK_THEME_SCRIPTS = frozenset({"Hans", "Hant", "Jpan", "Hang"})+_TITLE_PLACEHOLDER_TYPES = frozenset({"title", "subtitle"})+_BODY_PLACEHOLDER_TYPES = frozenset({+ "body",+ "date",+ "footer",+ "slide-number",+})+_DEFAULT_MASTER_TITLE_PX = 40.0+_DEFAULT_MASTER_BODY_PX = 24.0class ThemeFontError(RuntimeError):@@ -62,6 +74,79 @@ class MasterTextStyleSpec:return tuple(sizes)+def _inline_style_property(style: str, name: str) -> str | None:+ """Return one inline SVG style declaration value."""+ for declaration in style.split(";"):+ key, separator, value = declaration.partition(":")+ if separator and key.strip().lower() == name:+ return value.strip()+ return None+++def _svg_font_size_px(element: ET.Element) -> float | None:+ """Read one finite positive SVG font size in px."""+ raw = element.get("font-size")+ if raw is None:+ raw = _inline_style_property(element.get("style", ""), "font-size")+ if raw is None:+ return None+ match = _SVG_FONT_SIZE_RE.fullmatch(raw.strip())+ if match is None:+ return None+ value = float(match.group(1))+ return value if math.isfinite(value) and value > 0 else None+++def infer_master_text_style_spec(+ svg_files: list[Path],+) -> tuple[MasterTextStyleSpec, float, float]:+ """Infer structured Master title/body defaults from SVG slot carriers."""+ title_sizes: list[float] = []+ body_sizes: list[float] = []+ placeholder_types = _TITLE_PLACEHOLDER_TYPES | _BODY_PLACEHOLDER_TYPES+ for svg_path in svg_files:+ try:+ root = ET.parse(svg_path).getroot()+ except (OSError, ET.ParseError) as exc:+ raise ThemeFontError(+ f"Cannot infer Master text defaults from {svg_path}: {exc}"+ ) from exc+ for slot in root.iter():+ placeholder = slot.get("data-pptx-placeholder")+ if placeholder not in placeholder_types:+ continue+ target = (+ title_sizes+ if placeholder in _TITLE_PLACEHOLDER_TYPES+ else body_sizes+ )+ for carrier in slot.iter():+ if carrier.get("data-pptx-carrier") != "true":+ continue+ size = _svg_font_size_px(carrier)+ if size is not None:+ target.append(size)++ title_px = (+ float(statistics.median(title_sizes))+ if title_sizes+ else _DEFAULT_MASTER_TITLE_PX+ )+ body_px = (+ float(statistics.median(body_sizes))+ if body_sizes+ else _DEFAULT_MASTER_BODY_PX+ )+ return (+ MasterTextStyleSpec(+ title_hpt=font_px_to_hpt(title_px),+ body_hpt=font_px_to_hpt(body_px),+ ),+ title_px,+ body_px,+ )++def _font_face(font_family: str) -> ThemeFontFace:fonts = parse_font_family(font_family)return ThemeFontFace(diff --git a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.pyindex 6826ea22..bf5acad3 100644--- a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py+++ b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py@@ -5676,9 +5676,9 @@ def create_pptx_with_native_svg(exact source package parts after slide conversion.theme_font_spec: Locked project major/minor fonts for flat/structuredrelease-theme inheritance. Direct diagnostic flat callers may omit it.- master_text_style_spec: Required declared title/body anchors for structured- and release flat slide-master text styles. Direct diagnostic flat- callers may omit it; other routes ignore this value.+ master_text_style_spec: Required declared or inferred title/body anchors+ for structured and release flat slide-master text styles. Direct+ diagnostic flat callers may omit it; other routes ignore this value.theme_color_spec: Locked project color scheme for context-awareflat/structured theme inheritance. Preserve mode ignores this value.source_theme_xml: Complete validated source theme used only by an@@ -5850,8 +5850,8 @@ def create_pptx_with_native_svg()if pptx_structure == "structured" and master_text_style_spec is None:raise ValueError(- "Structured export requires declared typography title/body anchors "- "in master_text_style_spec"+ "Structured export requires declared or inferred typography "+ "title/body anchors in master_text_style_spec")if use_native_shapes and pptx_structure == "structured":template_specs = parse_template_slides(svg_files)diff --git a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/cli.py b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/cli.pyindex efe1216b..2c3c0f02 100644--- a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/cli.py+++ b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/cli.py@@ -95,6 +95,7 @@ from ..drawingml.theme_fonts import (ThemeFontError,ThemeFontFace,ThemeFontSpec,+ infer_master_text_style_spec,load_master_text_style_spec,load_theme_font_spec,)@@ -112,6 +113,7 @@ from .template_structure import (load_native_structure_contract,load_pptx_structure_lock,load_template_source_themes,+ parse_optional_layout_slides,parse_template_slides,structured_layout_definition_files,template_lock_errors,@@ -1432,7 +1434,7 @@ def main(argv: list[str] | None = None) -> int:Examples:%(prog)s projects/ppt169_demo # Default: native pptx -> exports/, svg_output -> backup/<ts>/%(prog)s projects/ppt169_demo -o out.pptx # Explicit path (no backup/)- %(prog)s projects/quick_generate_demo --quick-generate # Lockless flat export with normal postflight+ %(prog)s projects/quick_generate_demo --quick-generate # Lockless inferred structure + postflight%(prog)s <import_workspace> --roundtrip # authoring-svg-flat/ with source restoration# Disable transition / change transition effect@@ -1519,8 +1521,8 @@ Recorded narration:help=('Export a Quick Generate SVG roster from svg_output/ without ''spec_lock.md. Require a matching final quality report, infer one '- 'consistent canvas, use a flat package with converter defaults, '- 'and support normal export capabilities.'+ 'consistent canvas, infer flat versus structured output from the '+ 'complete SVG roster, and support normal export capabilities.'),)parser.add_argument(@@ -1619,7 +1621,9 @@ Recorded narration:help=('PPTX structure strategy for native export. Omitting this flag reads ''spec_lock.md; a legacy lock without pptx_structure.mode defaults to '- 'flat. Flat is the style-reference/free-design/brand-only release mode and '+ 'flat. Quick Generate requires omission and infers flat/structured '+ 'from its complete SVG roster. Flat is the style-reference/free-design/'+ 'brand-only release mode and ''builds one clean project-owned Master plus Blank Layout while keeping ''all SVG objects slide-local; structured is the mirror/layout reuse ''mode and requires complete explicit metadata. baseline, template, '@@ -1839,8 +1843,10 @@ Recorded narration:conflicts: list[str] = []if args.source not in {None, 'output'}:conflicts.append('--source must be omitted or output')- if args.pptx_structure not in {None, 'flat'}:- conflicts.append('--pptx-structure must be omitted or flat')+ if args.pptx_structure is not None:+ conflicts.append(+ '--pptx-structure must be omitted; Quick infers it from svg_output/'+ )if conflicts:print("Error: --quick-generate cannot be combined with: "@@ -1850,7 +1856,6 @@ Recorded narration:return 1if not args.with_notes:args.no_notes = True- args.pptx_structure = 'flat'elif (diagnostic_source or compatibility_export) and not args.roundtrip:if args.pptx_structure not in {None, 'flat'}:print(@@ -1914,7 +1919,9 @@ Recorded narration:_print_structure_contract_error(declared_structure_mode)return 1if pptx_structure is None:- if declared_structure_mode is None:+ if args.quick_generate:+ pass+ elif declared_structure_mode is None:pptx_structure = 'flat'print("Warning: spec_lock.md has no pptx_structure.mode; using flat "@@ -2026,7 +2033,11 @@ Recorded narration:and structure_lock.mode == "structured"and structure_lock.template_reuse_scope == "mirror")- if source_themes_path.exists() and not mirror_source_themes:+ if (+ source_themes_path.exists()+ and not mirror_source_themes+ and not args.quick_generate+ ):print("Error: templates/source_themes.json is allowed only for a ""structured mirror contract",@@ -2108,6 +2119,73 @@ Recorded narration:print("Error: No SVG files found", file=sys.stderr)return 1+ quick_template_specs = None+ if args.quick_generate:+ try:+ quick_template_specs = parse_optional_layout_slides(native_files)+ except TemplateStructureError as exc:+ print(+ "Error: Quick Generate SVG structure inference failed: "+ f"{exc}",+ file=sys.stderr,+ )+ return 1+ pptx_structure = (+ 'structured' if quick_template_specs is not None else 'flat'+ )+ print(+ " Quick PPTX structure: "+ f"{pptx_structure} (inferred from {len(native_files)} SVG page(s))"+ )+ if quick_template_specs is not None:+ try:+ (+ master_text_style_spec,+ quick_title_px,+ quick_body_px,+ ) = infer_master_text_style_spec(native_files)+ except ThemeFontError as exc:+ print(f"Error: {exc}", file=sys.stderr)+ return 1+ print(+ " Quick Master text defaults: "+ f"title {quick_title_px:g}px, body {quick_body_px:g}px "+ "(inferred from structured SVG pages)"+ )+ if source_themes_path.exists():+ if quick_template_specs is None:+ print(+ "Warning: templates/source_themes.json is ignored because "+ "Quick SVG pages declare no structured Master/Layout contract.",+ file=sys.stderr,+ )+ else:+ try:+ available_source_themes = load_template_source_themes(+ project_path / "templates"+ ) or {}+ except TemplateStructureError as exc:+ print(f"Error: {exc}", file=sys.stderr)+ return 1+ used_master_keys = {+ spec.master_key for spec in quick_template_specs+ }+ missing_source_themes = sorted(+ used_master_keys - set(available_source_themes)+ )+ if missing_source_themes:+ print(+ "Error: Quick structured SVG pages reference Master(s) "+ "missing from templates/source_themes.json: "+ + ", ".join(missing_source_themes),+ file=sys.stderr,+ )+ return 1+ source_theme_xml_by_master = {+ master_key: available_source_themes[master_key]+ for master_key in used_master_keys+ }+ref_files = native_filesauthoring_roundtrip_temporary: tempfile.TemporaryDirectory[str] | None = Noneauthoring_roundtrip_report: dict[str, object] | None = None@@ -2280,12 +2358,16 @@ Recorded narration:structured_baseline = Falsebaseline_layout_specs = Nonelayout_definition_files: list[Path] = []+ if pptx_structure == 'structured':+ if quick_template_specs is not None:+ template_specs = quick_template_specs+ else:+ try:+ template_specs = parse_template_slides(native_files)+ except TemplateStructureError as exc:+ print(f"Error: {exc}", file=sys.stderr)+ return 1if pptx_structure == 'structured' and structure_lock is not None:- try:- template_specs = parse_template_slides(native_files)- except TemplateStructureError as exc:- print(f"Error: {exc}", file=sys.stderr)- return 1lock_errors = template_lock_errors(template_specs, structure_lock)if lock_errors:print("Error: PPTX structure does not match spec_lock.md:", file=sys.stderr)diff --git a/skills/ppt-master/scripts/template_preview_pptx.py b/skills/ppt-master/scripts/template_preview_pptx.pyindex e9c3de71..3fff0722 100644--- a/skills/ppt-master/scripts/template_preview_pptx.py+++ b/skills/ppt-master/scripts/template_preview_pptx.py@@ -19,10 +19,8 @@ from __future__ import annotationsimport argparseimport contextlib-import mathimport reimport shutil-import statisticsimport sysimport tempfilefrom collections.abc import Iterator@@ -38,9 +36,8 @@ configure_utf8_stdio()from pptx import Presentation # noqa: E402from svg_to_pptx.drawingml.theme_fonts import ( # noqa: E402- MasterTextStyleSpec,+ infer_master_text_style_spec,)-from svg_to_pptx.drawingml.utils import font_px_to_hpt # noqa: E402from svg_to_pptx.pptx_package.builder import ( # noqa: E402create_pptx_with_native_svg,)@@ -61,18 +58,8 @@ _CANVAS_VIEWBOX_RE = re.compile(r"^canvas_viewbox\s*:\s*[\"']?([^\"'\r\n]+?)[\"']?\s*$",re.MULTILINE,)-_FONT_SIZE_RE = re.compile(r"^([0-9]+(?:\.[0-9]+)?)(?:px)?$")_FILENAME_UNSAFE_RE = re.compile(r"[\\/:*?\"<>|\x00-\x1f]+")_PLACEHOLDER_MARKER_RE = re.compile(r"\{\{([A-Z][A-Z0-9_]*)\}\}")-_TITLE_PLACEHOLDERS = frozenset({"title", "subtitle"})-_BODY_PLACEHOLDERS = frozenset({- "body",- "date",- "footer",- "slide-number",-})-_DEFAULT_TITLE_PX = 40.0-_DEFAULT_BODY_PX = 24.0def _review_marker_text(match: re.Match[str]) -> str:@@ -248,65 +235,6 @@ def _canvas_viewbox(spec_path: Path) -> str | None:return match.group(1).strip() if match else None-def _style_property(style: str, name: str) -> str | None:- """Return one inline CSS declaration value."""- for declaration in style.split(";"):- key, separator, value = declaration.partition(":")- if separator and key.strip().lower() == name:- return value.strip()- return None---def _font_size_px(element: ET.Element) -> float | None:- """Read one finite positive SVG font size in px."""- raw = element.get("font-size")- if raw is None:- raw = _style_property(element.get("style", ""), "font-size")- if raw is None:- return None- match = _FONT_SIZE_RE.fullmatch(raw.strip())- if match is None:- return None- value = float(match.group(1))- return value if math.isfinite(value) and value > 0 else None---def _carrier_sizes(svg_files: list[Path]) -> tuple[list[float], list[float]]:- """Collect authored title/body sizes from semantic placeholder carriers."""- title_sizes: list[float] = []- body_sizes: list[float] = []- for svg_path in svg_files:- root = ET.parse(svg_path).getroot()- for slot in root.iter():- placeholder = slot.get("data-pptx-placeholder")- if placeholder not in _TITLE_PLACEHOLDERS | _BODY_PLACEHOLDERS:- continue- for carrier in slot.iter():- if carrier.get("data-pptx-carrier") != "true":- continue- size = _font_size_px(carrier)- if size is None:- continue- target = title_sizes if placeholder in _TITLE_PLACEHOLDERS else body_sizes- target.append(size)- return title_sizes, body_sizes---def _master_text_style(svg_files: list[Path]) -> tuple[MasterTextStyleSpec, float, float]:- """Build review-only Master text defaults without requiring a project lock."""- title_sizes, body_sizes = _carrier_sizes(svg_files)- title_px = float(statistics.median(title_sizes)) if title_sizes else _DEFAULT_TITLE_PX- body_px = float(statistics.median(body_sizes)) if body_sizes else _DEFAULT_BODY_PX- return (- MasterTextStyleSpec(- title_hpt=font_px_to_hpt(title_px),- body_hpt=font_px_to_hpt(body_px),- ),- title_px,- body_px,- )--def _verify_output(output_path: Path,*,@@ -449,7 +377,9 @@ def main(argv: list[str] | None = None) -> int:f"output already exists: {output_path}; use --force to replace it")output_path.parent.mkdir(parents=True, exist_ok=True)- text_style, title_px, body_px = _master_text_style(all_svg_files)+ text_style, title_px, body_px = infer_master_text_style_spec(+ all_svg_files+ )print("PPT Master - Template Preview PPTX Exporter")print(f" Workspace: {workspace}")