Skip to content

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(svg-assets): reuse layered vectors in flat authoring views

hugohe3a605f6090e8b
diff --git a/skills/ppt-master/scripts/README.md b/skills/ppt-master/scripts/README.md
index 2dd834cc..d277cdf5 100644
--- a/skills/ppt-master/scripts/README.md
+++ b/skills/ppt-master/scripts/README.md
@@ -149,10 +149,17 @@ for selection and authoring guidance.
Create-template/source normalization (optional; never part of automatic export):
```bash
-python3 scripts/extract_svg_assets.py <svg_dir> --icons-dir <icons_dir> --inplace --id-prefix <prefix> # optional: shrink imported/reference SVGs before AI review
+python3 scripts/extract_svg_assets.py <layered_svg_dir> --icons-dir <icons_dir> --inplace --id-prefix layered
+python3 scripts/extract_svg_assets.py <flat_svg_dir> --icons-dir <icons_dir> --reuse-inventory <layered_inventory.json> --inplace --id-prefix flat
python3 scripts/extract_svg_pictures.py "<svg_file>" --select "<group_id>" --resource-root "<workspace>" --images-dir "<picture_assets_dir>" --inplace # optional create-template normalization: one selected group -> one SVG picture
```
+`extract_svg_assets.py` fingerprints each extracted subtree before generated-ID
+namespacing. Process the layered authoring view first, then pass its inventory to
+the flat view with `--reuse-inventory`; matching flat subtrees reference the
+existing layered asset instead of creating a duplicate file. Only unmatched
+flat-only vectors create new assets.
+
Post-processing and export:
```bash
diff --git a/skills/ppt-master/scripts/docs/svg-pipeline.md b/skills/ppt-master/scripts/docs/svg-pipeline.md
index 912744f6..2cded6a8 100644
--- a/skills/ppt-master/scripts/docs/svg-pipeline.md
+++ b/skills/ppt-master/scripts/docs/svg-pipeline.md
@@ -48,6 +48,25 @@ is owned by [`shared-standards.md`](../../references/shared-standards.md), with
authoring guidance in
[`native-shape-authoring.md`](../../references/native-shape-authoring.md).
+## `extract_svg_assets.py`
+
+Factor large vector subtrees out of lightweight authoring projections and
+replace them with compact `<use data-icon>` references:
+
+```bash
+python3 scripts/extract_svg_assets.py <layered_svg_dir> \
+ --icons-dir <icons_dir> --inplace --id-prefix layered
+python3 scripts/extract_svg_assets.py <flat_svg_dir> \
+ --icons-dir <icons_dir> --reuse-inventory <layered_inventory.json> \
+ --inplace --id-prefix flat
+```
+
+The first pass records a source fingerprint before namespacing each extracted
+asset's internal ids. The second pass reuses a fingerprint-matched asset and
+writes no duplicate SVG file. Unmatched flat-only subtrees still extract
+normally. Use `--clean-stale` on both import-workspace passes to remove stale
+generated files for their respective prefixes.
+
## `extract_svg_pictures.py`
Normalize one deliberately selected complex SVG object into one PowerPoint
diff --git a/skills/ppt-master/scripts/extract_svg_assets.py b/skills/ppt-master/scripts/extract_svg_assets.py
index 13717c35..d2fff9da 100644
--- a/skills/ppt-master/scripts/extract_svg_assets.py
+++ b/skills/ppt-master/scripts/extract_svg_assets.py
@@ -14,10 +14,15 @@ threshold is a readability convenience — it changes which blobs are factored
out, not whether the export stays editable.
Usage:
- python3 scripts/extract_svg_assets.py <svg_dir> [--icons-dir <icons_dir>] [--min-drawables N] [--min-bytes N] [--min-decoration-bytes N] [--inplace] [--clean-stale]
+ python3 scripts/extract_svg_assets.py <svg_dir> [options]
Examples:
- python3 scripts/extract_svg_assets.py import_ws/svg --icons-dir import_ws/icons --inplace --id-prefix layered --clean-stale
+ python3 scripts/extract_svg_assets.py import_ws/svg \
+ --icons-dir import_ws/icons --inplace --id-prefix layered --clean-stale
+ python3 scripts/extract_svg_assets.py import_ws/svg-flat \
+ --icons-dir import_ws/icons \
+ --reuse-inventory import_ws/svg_vector_asset_inventory.json \
+ --inplace --id-prefix flat --clean-stale
python3 scripts/extract_svg_assets.py project/svg_output --inplace --min-drawables 40
Dependencies:
@@ -30,6 +35,7 @@ from __future__ import annotations
import argparse
import copy
+import hashlib
import json
import re
import sys
@@ -128,7 +134,7 @@ def _dependency_elements(root: ET.Element, asset_group: ET.Element) -> list[ET.E
by_id = _id_index(root)
dependencies: list[ET.Element] = []
seen: set[str] = set()
- queue = list(_referenced_ids(asset_group))
+ queue = sorted(_referenced_ids(asset_group))
while queue:
ref_id = queue.pop(0)
@@ -262,6 +268,24 @@ def _asset_svg(
return ET.tostring(svg, encoding="utf-8", xml_declaration=True)
+def _source_sha256(
+ group: ET.Element,
+ dependencies: list[ET.Element],
+ view_box: str | None,
+ width: str | None,
+ height: str | None,
+) -> str:
+ """Fingerprint an extracted subtree before asset-id namespacing."""
+ payload = _asset_svg(
+ copy.deepcopy(group),
+ [copy.deepcopy(dependency) for dependency in dependencies],
+ view_box,
+ width,
+ height,
+ )
+ return hashlib.sha256(payload).hexdigest()
+
+
def _asset_group(nodes: list[ET.Element]) -> ET.Element:
group = ET.Element(f"{{{SVG_NS}}}g")
for node in nodes:
@@ -373,6 +397,57 @@ def _existing_placeholder_entries(
return entries
+def _load_reusable_assets(inventory_path: Path, icons_dir: Path) -> dict[str, dict]:
+ """Load fingerprinted assets from an earlier extraction inventory."""
+ try:
+ payload = json.loads(inventory_path.read_text(encoding="utf-8"))
+ except FileNotFoundError as exc:
+ raise ValueError(f"reuse inventory not found: {inventory_path}") from exc
+ except json.JSONDecodeError as exc:
+ raise ValueError(f"invalid reuse inventory JSON: {inventory_path}: {exc}") from exc
+
+ entries = payload.get("assets")
+ if not isinstance(entries, list):
+ raise ValueError(f"reuse inventory has no assets list: {inventory_path}")
+
+ reusable: dict[str, dict] = {}
+ fingerprinted = 0
+ for entry in entries:
+ if not isinstance(entry, dict):
+ continue
+ source_sha256 = entry.get("source_sha256")
+ asset_sha256 = entry.get("asset_sha256")
+ asset = entry.get("asset")
+ icon = entry.get("icon")
+ if not all(
+ isinstance(value, str) and value
+ for value in (source_sha256, asset_sha256, asset, icon)
+ ):
+ continue
+ fingerprinted += 1
+ asset_path = icons_dir / asset
+ if not asset_path.is_file():
+ raise ValueError(
+ f"reusable asset is missing from the target icons directory: {asset_path}"
+ )
+ actual_asset_sha256 = hashlib.sha256(asset_path.read_bytes()).hexdigest()
+ if actual_asset_sha256 != asset_sha256:
+ raise ValueError(
+ f"reusable asset hash does not match its inventory: {asset_path}"
+ )
+ current = reusable.get(source_sha256)
+ if current is None or asset < str(current["asset"]):
+ reusable[source_sha256] = entry
+
+ extracted_count = payload.get("extracted_count", 0)
+ if isinstance(extracted_count, int) and extracted_count > fingerprinted:
+ raise ValueError(
+ "reuse inventory predates source fingerprints; rerun the source extraction "
+ f"with the current tool: {inventory_path}"
+ )
+ return reusable
+
+
def _rewritten_path(svg_path: Path, rewritten_dir: Path | None, inplace: bool) -> Path:
if inplace:
return svg_path
@@ -390,6 +465,7 @@ def extract_file(
inplace: bool,
id_prefix: str = "",
rewritten_dir: Path | None = None,
+ reusable_assets: dict[str, dict] | None = None,
) -> list[dict]:
"""Extract qualifying groups from one SVG. Returns inventory entries."""
ET.register_namespace("", SVG_NS)
@@ -450,6 +526,33 @@ def extract_file(
for elem in dependency.iter()
if (elem_id := elem.get("id"))
})
+ source_sha256 = _source_sha256(group, dependencies, view_box, width, height)
+ reusable = (reusable_assets or {}).get(source_sha256)
+ if reusable is not None:
+ reused_icon = str(reusable["icon"])
+ reused_asset = str(reusable["asset"])
+ placeholder = ET.Element(f"{{{SVG_NS}}}use")
+ placeholder.set("data-icon", reused_icon)
+ for node in nodes:
+ if node in parent:
+ parent.remove(node)
+ parent.insert(pos, placeholder)
+ entries.append({
+ "svg": svg_path.name,
+ "id": reused_icon,
+ "icon": reused_icon,
+ "asset": reused_asset,
+ "source": "reused-inventory",
+ "source_sha256": source_sha256,
+ "asset_sha256": reusable["asset_sha256"],
+ "reused_from_svg": reusable.get("svg"),
+ "drawable_count": _drawable_count(group),
+ "byte_count": _xml_size(group),
+ "dependencies": dependency_source_ids,
+ "elements": _tag_histogram(group),
+ })
+ continue
+
id_mapping = _collect_id_mapping(asset_id, group, dependencies)
_rewrite_references(group, id_mapping)
for dependency in dependencies:
@@ -471,6 +574,9 @@ def extract_file(
"id": asset_id,
"icon": asset_id,
"asset": f"{asset_id}.svg",
+ "source": "extracted",
+ "source_sha256": source_sha256,
+ "asset_sha256": hashlib.sha256(asset_bytes).hexdigest(),
"drawable_count": _drawable_count(group),
"byte_count": _xml_size(group),
"dependencies": [id_mapping.get(elem_id, elem_id) for elem_id in dependency_source_ids],
@@ -499,10 +605,20 @@ def build_parser() -> argparse.ArgumentParser:
"--inventory",
help="Inventory JSON path (default: <svg_dir>/../<svg_dir-name>_vector_asset_inventory.json)",
)
+ parser.add_argument(
+ "--reuse-inventory",
+ help=(
+ "Reuse fingerprint-matched assets from an earlier extraction inventory; "
+ "only unmatched vector subtrees create new assets"
+ ),
+ )
parser.add_argument(
"--id-prefix",
default="",
- help="Optional prefix for generated asset IDs, useful when processing layered and flat SVG dirs into one icons dir",
+ help=(
+ "Optional prefix for generated asset IDs, useful when processing "
+ "layered and flat SVG dirs into one icons dir"
+ ),
)
parser.add_argument(
"--min-drawables", type=int, default=DEFAULT_MIN_DRAWABLES,
@@ -543,8 +659,20 @@ def main(argv: Optional[list[str]] = None) -> int:
icons_dir = Path(args.icons_dir) if args.icons_dir else svg_dir.parent / "icons"
icons_dir.mkdir(parents=True, exist_ok=True)
+ reusable_assets: dict[str, dict] = {}
+ reuse_inventory_path = Path(args.reuse_inventory) if args.reuse_inventory else None
+ if reuse_inventory_path is not None:
+ try:
+ reusable_assets = _load_reusable_assets(reuse_inventory_path, icons_dir)
+ except ValueError as exc:
+ print(f"[ERROR] {exc}", file=sys.stderr)
+ return 1
rewritten_dir = Path(args.rewritten_dir) if args.rewritten_dir else None
- inventory_path = Path(args.inventory) if args.inventory else svg_dir.parent / f"{svg_dir.name}_vector_asset_inventory.json"
+ inventory_path = (
+ Path(args.inventory)
+ if args.inventory
+ else svg_dir.parent / f"{svg_dir.name}_vector_asset_inventory.json"
+ )
svg_paths = sorted(svg_dir.glob("*.svg"))
inventory: list[dict] = []
@@ -560,12 +688,14 @@ def main(argv: Optional[list[str]] = None) -> int:
args.inplace,
args.id_prefix,
rewritten_dir,
+ reusable_assets,
)
)
except ET.ParseError as exc:
print(f"[WARN] skip unparseable {svg_path.name}: {exc}", file=sys.stderr)
- extracted_count = len(inventory)
+ extracted_count = sum(entry.get("source") == "extracted" for entry in inventory)
+ reused_count = sum(entry.get("source") == "reused-inventory" for entry in inventory)
known_assets = {str(entry["asset"]) for entry in inventory}
inventory.extend(_existing_placeholder_entries(svg_paths, icons_dir, known_assets))
@@ -584,18 +714,28 @@ def main(argv: Optional[list[str]] = None) -> int:
"schema": "vector_asset_inventory.v1",
"svg_dir": str(svg_dir),
"icons_dir": str(icons_dir),
- "rewritten_dir": None if args.inplace else str(_rewritten_path(svg_dir / "_sample.svg", rewritten_dir, False).parent),
+ "rewritten_dir": (
+ None
+ if args.inplace
+ else str(_rewritten_path(svg_dir / "_sample.svg", rewritten_dir, False).parent)
+ ),
+ "reuse_inventory": str(reuse_inventory_path) if reuse_inventory_path is not None else None,
"min_drawables": args.min_drawables,
"min_bytes": args.min_bytes,
"min_decoration_bytes": args.min_decoration_bytes,
"extracted_count": extracted_count,
+ "reused_count": reused_count,
"asset_count": len(inventory),
"stale_removed": stale_removed,
"assets": inventory,
}
inventory_path.parent.mkdir(parents=True, exist_ok=True)
inventory_path.write_text(json.dumps(manifest, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
- print(f"[OK] extracted {extracted_count} new asset(s), inventoried {len(inventory)} asset(s) -> {icons_dir}", file=sys.stderr)
+ print(
+ f"[OK] extracted {extracted_count} new asset(s), reused {reused_count} asset(s), "
+ f"inventoried {len(inventory)} asset reference(s) -> {icons_dir}",
+ file=sys.stderr,
+ )
if stale_removed:
print(f"[OK] removed {len(stale_removed)} stale generated asset(s)", file=sys.stderr)
return 0
diff --git a/skills/ppt-master/workflows/create-template.md b/skills/ppt-master/workflows/create-template.md
index b2d83c43..c64ad3f0 100644
--- a/skills/ppt-master/workflows/create-template.md
+++ b/skills/ppt-master/workflows/create-template.md
@@ -142,15 +142,17 @@ The projection removes opaque text payload, duplicate hidden geometry carriers,
Factor large decorative vector groups out of the lightweight projections so the model-facing SVGs stay readable while export remains native shapes. Never run this in place on the lossless import SVGs:
```bash
-# layered view — primary read surface in every mode
+# layered view — primary read surface and canonical extracted-vector inventory
python3 skills/ppt-master/scripts/extract_svg_assets.py "<import_workspace>/authoring-svg" --icons-dir "<import_workspace>/icons" --inplace --id-prefix layered --min-decoration-bytes 3000 --clean-stale
-# flat view — mirror inspection and optional composition spot checks; the lossless layered/flat sources remain authoritative for mirror
-python3 skills/ppt-master/scripts/extract_svg_assets.py "<import_workspace>/authoring-svg-flat" --icons-dir "<import_workspace>/icons" --inplace --id-prefix flat --min-decoration-bytes 3000 --clean-stale
+# flat view — reuse matching layered assets; only genuinely flat-only vectors create new assets
+python3 skills/ppt-master/scripts/extract_svg_assets.py "<import_workspace>/authoring-svg-flat" --icons-dir "<import_workspace>/icons" --reuse-inventory "<import_workspace>/authoring-svg_vector_asset_inventory.json" --inplace --id-prefix flat --min-decoration-bytes 3000 --clean-stale
```
The projected SVGs in `<import_workspace>/authoring-svg/` / `<import_workspace>/authoring-svg-flat/` are rewritten in place with compact `<use data-icon="..."/>` placeholders. Extracted assets live directly under `<import_workspace>/icons/`; `icons/` must contain only icon/vector assets, not rewritten page SVGs or inventories. The inventory is written beside the processed projection directory. The existing icon embedding path re-inlines the extracted assets before final export, preserving multi-color artwork and non-square viewBox geometry as native SVG shapes. Text-bearing groups are never extracted; text must stay readable/editable in the working SVG. Extraction triggers on either many drawable elements or a large pure-vector XML block, so long single-path illustrations are factored out too. Pure-vector decoration runs inside text-bearing groups use a lower size threshold, allowing card borders and decorative paths to be extracted without hiding text. Referenced defs (`gradient` / `pattern` / `filter` / `clipPath` / `marker`) are copied into each asset and namespaced so the asset is self-contained after re-inline. If both layered and flat views are processed into the same icon directory, keep distinct `--id-prefix` values to avoid asset ID collisions. `--clean-stale` removes only stale generated assets for the current SVG filenames and prefix; it is safe in this import workspace but should not be used against a shared hand-curated icon directory without a specific prefix.
+The layered pass owns the canonical extracted-vector pool. Each new asset records a source fingerprint before generated ID namespacing. The flat pass MUST consume the layered inventory through `--reuse-inventory`: an exact fingerprint match writes only a `<use>` reference to the existing layered asset, while an unmatched flat-only subtree may create one new asset under the `flat` prefix. Do not independently extract the two views into parallel asset sets. With `--clean-stale`, a rerun also removes obsolete generated `flat_*` duplicates while retaining every reused layered reference.
+
**Explicit complex-SVG picture normalization (optional; `standard` / `fidelity` only)**:
When one imported native group is deliberately being retained as one complex