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(scripts): slice suggestions keep the pure key and flag backing panels; title blocks stay animatable; Morph endpoint diagnostic
hugohe3914f83e0e36f
diff --git a/skills/ppt-master/scripts/slice_images.py b/skills/ppt-master/scripts/slice_images.pyindex 5ddc77a8..5e442587 100644--- a/skills/ppt-master/scripts/slice_images.py+++ b/skills/ppt-master/scripts/slice_images.py@@ -69,6 +69,9 @@ _KEY_DRIFT_MAX_TOLERANCE = 48_KEY_DRIFT_MARGIN = 4# At most this many trim pixels on a touched edge count as isolated drift._EDGE_DRIFT_MAX_PIXELS = 8+# Corner sample inset (px) and minimum cell fill for the backing-panel notice.+_PANEL_CORNER_INSET = 2+_PANEL_MIN_FILL = 0.75def _log(msg: str) -> None:@@ -254,6 +257,19 @@ def _pure_chroma_channel(bg: tuple[int, int, int]) -> Optional[int]:return bg.index(255)+def _nearest_pure_key(+ color: tuple[int, int, int],+) -> Optional[tuple[tuple[int, int, int], int]]:+ """Return the pure RGB key a drifted gutter color came from, with its distance."""+ best: Optional[tuple[tuple[int, int, int], int]] = None+ for index in range(3):+ pure = tuple(255 if i == index else 0 for i in range(3))+ distance = max(abs(color[i] - pure[i]) for i in range(3))+ if distance <= _KEY_DRIFT_MAX_TOLERANCE and (best is None or distance < best[1]):+ best = (pure, distance) # type: ignore[assignment]+ return best++def _channel_alpha(channel: Image.Image, bg_value: int) -> Image.Image:"""Return the minimum alpha that can explain one channel over a key."""lut = []@@ -397,6 +413,7 @@ def _keying_findings(alpha: bool,trim_mask: Optional[Image.Image] = None,diff: Optional[Image.Image] = None,+ notices: Optional[list[str]] = None,) -> list[str]:"""Report objective signs that the flat-background key did not take.@@ -408,6 +425,11 @@ def _keying_findings(findings: list[str] = []hex_bg = "#{:02X}{:02X}{:02X}".format(*cell_bg)+ if alpha and trim and alpha_mask is not None and notices is not None:+ notice = _backing_panel_notice(label, alpha_mask, bbox, cell_size)+ if notice:+ notices.append(notice)+if alpha and alpha_mask is not None:px = alpha_mask.load()width, height = alpha_mask.size@@ -463,6 +485,44 @@ def _keying_findings(return findings+def _backing_panel_notice(+ label: str,+ alpha_mask: Image.Image,+ bbox: tuple[int, int, int, int],+ cell_size: tuple[int, int],+) -> Optional[str]:+ """Flag a trimmed element whose corners are opaque: a painted backing panel.++ A cut-out silhouette almost never fills all four corners of its own+ bounding box; a rectangle behind it does. The key cannot see the panel+ (the gutters are clean), so this is advisory, never a strict failure.+ """+ left, top, right, bottom = bbox+ if right - left < 2 * _PANEL_CORNER_INSET + 1 or bottom - top < 2 * _PANEL_CORNER_INSET + 1:+ return None+ cell_width, cell_height = cell_size+ fill_w = (right - left) / cell_width if cell_width else 0.0+ fill_h = (bottom - top) / cell_height if cell_height else 0.0+ if min(fill_w, fill_h) < _PANEL_MIN_FILL:+ return None+ px = alpha_mask.load()+ corners = (+ (left + _PANEL_CORNER_INSET, top + _PANEL_CORNER_INSET),+ (right - 1 - _PANEL_CORNER_INSET, top + _PANEL_CORNER_INSET),+ (left + _PANEL_CORNER_INSET, bottom - 1 - _PANEL_CORNER_INSET),+ (right - 1 - _PANEL_CORNER_INSET, bottom - 1 - _PANEL_CORNER_INSET),+ )+ opaque = sum(1 for x, y in corners if px[x, y] > _BOUNDARY_OPAQUE_ALPHA)+ if opaque < 3:+ return None+ return (+ f"{label}: the trimmed element fills {fill_w:.0%} x {fill_h:.0%} of its "+ f"cell and is opaque in {opaque} of 4 corners; it "+ "may sit on a painted backing panel the key could not remove — look at "+ "the slice, and regenerate with the element alone on the key if so"+ )++def _edge_drift(trim_mask: Optional[Image.Image],diff: Optional[Image.Image],@@ -525,6 +585,14 @@ def _log_keying_findings("larger --tolerance would eat into the elements.")else:+ pure = _nearest_pure_key(dominant)+ if pure is not None:+ # A pure key enables despill and soft-alpha recovery; keep it+ # and widen the tolerance by the measured drift instead.+ pure_rgb, pure_distance = pure+ hex_bg = "#{:02X}{:02X}{:02X}".format(*pure_rgb)+ drift += pure_distance+ outlier += pure_distancesuggested_tolerance = max(tolerance, drift, outlier + _KEY_DRIFT_MARGIN)@@ -590,6 +658,7 @@ def slice_sheet(prepared: list[tuple[int, int, Image.Image, Path]] = []written: list[Path] = []findings: list[str] = []+ notices: list[str] = []idx = 0for r in range(rows):@@ -618,6 +687,7 @@ def slice_sheet(findings.extend(_keying_findings(f"cell ({r},{c})", cell.size, bbox, alpha_mask, cell_bg,trim=trim, alpha=alpha, trim_mask=trim_mask, diff=diff,+ notices=notices,))if trim and trim_mask is not None and alpha_mask is not None and bbox is not None:@@ -654,6 +724,9 @@ def slice_sheet("no output files were written")+ for notice in notices:+ _log(f"[WARN] {notice}")+for r, c, cell, out_path in prepared:cell.save(out_path)written.append(out_path)diff --git a/skills/ppt-master/scripts/svg_to_pptx/animation_config.py b/skills/ppt-master/scripts/svg_to_pptx/animation_config.pyindex bc0d8476..60a6fe48 100644--- a/skills/ppt-master/scripts/svg_to_pptx/animation_config.py+++ b/skills/ppt-master/scripts/svg_to_pptx/animation_config.py@@ -5,6 +5,7 @@ from __future__ import annotationsimport jsonimport mathimport re+import statisticsfrom dataclasses import dataclassfrom pathlib import Path, PureWindowsPathfrom typing import Any@@ -114,6 +115,83 @@ def is_chrome_id(elem_id: str | None) -> bool:return any(t in _CHROME_ID_TOKENS for t in tokens if t)+_TITLE_BLOCK_TOKENS = frozenset({'header', 'footer'})+_FONT_SIZE_RE = re.compile(r'font-size\s*:\s*([0-9.]+)')+++def _font_size_px(elem: ET.Element) -> float | None:+ """Return an element's own font-size in px from its attribute or style."""+ raw = elem.get('font-size')+ if raw is None:+ match = _FONT_SIZE_RE.search(elem.get('style') or '')+ raw = match.group(1) if match else None+ if raw is None:+ return None+ try:+ return float(re.match(r'[0-9.]+', raw.strip()).group(0))+ except (AttributeError, ValueError):+ return None+++def _text_sizes(scope: ET.Element) -> list[float]:+ """Return every declared font-size among text runs under ``scope``."""+ return [+ size+ for elem in scope.iter()+ if _tag_name(elem) in {'text', 'tspan'}+ for size in (_font_size_px(elem),)+ if size is not None+ ]+++def _max_text_size(scope: ET.Element) -> float | None:+ sizes = _text_sizes(scope)+ return max(sizes) if sizes else None+++def _page_reference_size(root: ET.Element) -> float | None:+ """Return the median of the page's distinct text sizes.++ Running labels and page numbers sit below it; a title block sits at or+ above it even when a hero numeral is the page's largest text.+ """+ distinct = sorted(set(_text_sizes(root)))+ return statistics.median(distinct) if distinct else None+++def _holds_page_title(group: ET.Element, reference_size: float | None) -> bool:+ """A header/footer-named group whose text reaches the page's median size+ is the title block, not chrome."""+ if reference_size is None:+ return False+ group_max = _max_text_size(group)+ return group_max is not None and group_max >= reference_size - 1e-6+++def _names_title_block(group_id: str) -> bool:+ tokens = re.split(r'[-_]', group_id.lower())+ return any(t in _TITLE_BLOCK_TOKENS for t in tokens if t)+++def scan_root_primitives(svg_path: Path) -> dict[str, str]:+ """Return id -> description for visible direct-root non-group elements."""+ root = ET.parse(str(svg_path)).getroot()+ primitives: dict[str, str] = {}+ for child in root:+ tag = _tag_name(child)+ if tag in _NON_VISUAL_TAGS or tag == 'g':+ continue+ elem_id = usable_animation_group_id(child.get('id'))+ if elem_id is None:+ continue+ role = child.get('data-pptx-role')+ description = f'<{tag}>'+ if role:+ description += f' with data-pptx-role="{role}"'+ primitives[elem_id] = description+ return primitives++def usable_animation_group_id(raw: str | None) -> str | None:"""Return one nonblank SVG animation anchor verbatim, else ``None``."""return raw if raw and raw.strip() else None@@ -125,6 +203,7 @@ def scan_svg_targets(svg_path: Path) -> tuple[list[GroupTarget], list[str]]:targets: list[GroupTarget] = []anonymous_groups: list[str] = []visual_index = 0+ page_reference_size = _page_reference_size(root)for child in root:tag = _tag_name(child)@@ -152,6 +231,12 @@ def scan_svg_targets(svg_path: Path) -> tuple[list[GroupTarget], list[str]]:chrome = semantic_staticelse:chrome = is_chrome_id(group_id)+ if (+ chrome+ and _names_title_block(group_id)+ and _holds_page_title(child, page_reference_size)+ ):+ chrome = Falsetargets.append(GroupTarget(slide=svg_path.stem,@@ -1512,6 +1597,14 @@ def validate_animation_config(config,)warnings.extend(morph_errors)+ root_primitives_by_slide: dict[str, dict[str, str]] = {}+ if morph_pairs:+ scan_files = svg_files+ if scan_files is None:+ svg_dir = project_path / 'svg_output'+ scan_files = discover_slide_svgs(svg_dir) if svg_dir.is_dir() else []+ for svg_path in scan_files:+ root_primitives_by_slide[svg_path.stem] = scan_root_primitives(svg_path)for pair in morph_pairs:for slide_name, group_id in ((pair.source_slide, pair.source_group_id),@@ -1519,10 +1612,19 @@ def validate_animation_config():target = known_groups_by_slide.get(slide_name, {}).get(group_id)if target is None:- warnings.append(- 'animations.json Morph references missing or ambiguous group: '- f'{slide_name}/{group_id}'- )+ primitive = root_primitives_by_slide.get(slide_name, {}).get(group_id)+ if primitive is not None:+ warnings.append(+ f'animations.json Morph endpoint {slide_name}/{group_id} '+ f'is a root primitive ({primitive}), not a direct-root '+ '<g>; wrap it in a group (drop a static role marker) '+ 'before pairing'+ )+ else:+ warnings.append(+ 'animations.json Morph references missing or ambiguous group: '+ f'{slide_name}/{group_id}'+ )elif target.structurally_static:warnings.append('animations.json Morph references structural group: '