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(pptx-to-svg): close theme color mapping contracts
hugohe34124d7ed16c9
diff --git a/skills/ppt-master/references/shared-standards.md b/skills/ppt-master/references/shared-standards.mdindex 4b945cd2..dfdc3fe1 100644--- a/skills/ppt-master/references/shared-standards.md+++ b/skills/ppt-master/references/shared-standards.md@@ -772,6 +772,27 @@ percentage-literal, or out-of-range channels, extra attributes, namespacealiases, and interleaved text stop import instead of receiving zero defaults orbeing clamped into another color. This route is `Native-normalized` because theSVG retains the displayed sRGB color rather than the source color-space model.+Theme palette import is closed around the DrawingML color-scheme contract. A+loaded theme part must have an `a:theme` root, exactly one direct+`a:themeElements`, and exactly one direct `a:clrScheme`. The scheme has only its+required `name` attribute and the 12 required slots in schema order: `dk1`,+`lt1`, `dk2`, `lt2`, `accent1..6`, `hlink`, and `folHlink`. Each attribute-free+slot contains exactly one concrete `a:srgbClr`, `a:sysClr`, `a:prstClr`,+`a:hslClr`, or `a:scrgbClr` child accepted by the registered base-color and+modifier contracts above. The resolved slot must be opaque because the current+palette model stores RGB only. Missing, duplicate, reordered, ambiguous,+non-opaque, or extension-bearing schemes stop import instead of being reduced+to the first recognizable color.++A loaded slide master likewise has a `p:sldMaster` root and exactly one direct,+empty `p:clrMap`. Its exact 12-attribute source set is `bg1`, `tx1`, `bg2`,+`tx2`, `accent1..6`, `hlink`, and `folHlink`; every value is one of the 12 theme+slots above. Missing or extra mappings, unknown/case-altered targets, text, and+extension children stop import rather than falling back to aliases. A+theme-only palette with no master still uses the registered `bg`/`tx` aliases.+Theme slot colors normalize to static SVG paint, so this route is+`Native-normalized` rather than preserving the source color model or mapping+record.Imported base colors apply only the following DrawingML modifier subset, indocument order:diff --git a/skills/ppt-master/scripts/pptx_to_svg/color_resolver.py b/skills/ppt-master/scripts/pptx_to_svg/color_resolver.pyindex 8c3b6436..fe1ea33f 100644--- a/skills/ppt-master/scripts/pptx_to_svg/color_resolver.py+++ b/skills/ppt-master/scripts/pptx_to_svg/color_resolver.py@@ -101,6 +101,38 @@ SCHEME_ALIASES = {"bg1": "lt1", "bg2": "lt2","tx1": "dk1", "tx2": "dk2",}+_THEME_SCHEME_SLOTS = (+ "dk1",+ "lt1",+ "dk2",+ "lt2",+ "accent1",+ "accent2",+ "accent3",+ "accent4",+ "accent5",+ "accent6",+ "hlink",+ "folHlink",+)+_COLOR_MAP_SOURCES = (+ "bg1",+ "tx1",+ "bg2",+ "tx2",+ "accent1",+ "accent2",+ "accent3",+ "accent4",+ "accent5",+ "accent6",+ "hlink",+ "folHlink",+)+_THEME_COLOR_TAGS = frozenset({+ f"{{{NS['a']}}}{name}"+ for name in ("srgbClr", "sysClr", "prstClr", "hslClr", "scrgbClr")+})_SRGB_HEX_RE = re.compile(r"[0-9A-Fa-f]{6}")_OOXML_INTEGER_RE = re.compile(r"[+-]?[0-9]+")_OOXML_INT_MIN = -(2**31)@@ -186,34 +218,96 @@ class ColorPalette:self.scheme: dict[str, str] = {}self.clr_map: dict[str, str] = {}if theme is not None:- self._load_scheme(theme.xml)+ self._load_scheme(theme)if master is not None:- self._load_clr_map(master.xml)-- def _load_scheme(self, theme_root: ET.Element) -> None:- clr_scheme = theme_root.find(".//a:clrScheme", NS)- if clr_scheme is None:- return- for child in list(clr_scheme):- if not isinstance(child.tag, str):- continue- name = child.tag.split("}", 1)[-1]- srgb = child.find("a:srgbClr", NS)- sys_clr = child.find("a:sysClr", NS)- if srgb is not None and srgb.attrib.get("val"):- self.scheme[name] = srgb.attrib["val"].upper()- elif sys_clr is not None:- last = sys_clr.attrib.get("lastClr")- if last:- self.scheme[name] = last.upper()-- def _load_clr_map(self, master_root: ET.Element) -> None:- clr_map = master_root.find("p:clrMap", NS)- if clr_map is None:- return- # Each attribute on clrMap is a remap: bg1="lt1" tx1="dk1" ...- for attr, val in clr_map.attrib.items():- self.clr_map[attr] = val+ self._load_clr_map(master)++ def _load_scheme(self, theme: PartRef) -> None:+ theme_root = theme.xml+ if theme_root.tag != f"{{{NS['a']}}}theme":+ raise ValueError(f"{theme.path}: expected a:theme root")++ theme_elements = theme_root.findall("a:themeElements", NS)+ if len(theme_elements) != 1:+ raise ValueError(+ f"{theme.path}: expected exactly one direct a:themeElements"+ )+ clr_schemes = theme_elements[0].findall("a:clrScheme", NS)+ if len(clr_schemes) != 1:+ raise ValueError(+ f"{theme.path}: expected exactly one direct a:clrScheme"+ )+ clr_scheme = clr_schemes[0]+ children = list(clr_scheme)+ expected_tags = [+ f"{{{NS['a']}}}{name}" for name in _THEME_SCHEME_SLOTS+ ]+ if (+ set(clr_scheme.attrib) != {"name"}+ or (clr_scheme.text or "").strip()+ or [child.tag for child in children] != expected_tags+ or any((child.tail or "").strip() for child in children)+ ):+ raise ValueError(+ f"{theme.path}: invalid DrawingML color scheme structure"+ )++ for name, slot in zip(_THEME_SCHEME_SLOTS, children):+ color_children = list(slot)+ if (+ slot.attrib+ or (slot.text or "").strip()+ or len(color_children) != 1+ or color_children[0].tag not in _THEME_COLOR_TAGS+ or (color_children[0].tail or "").strip()+ ):+ raise ValueError(+ f"{theme.path}: invalid DrawingML theme color slot {name!r}"+ )+ try:+ hex_, alpha = resolve_color(color_children[0], None)+ except ValueError as exc:+ raise ValueError(+ f"{theme.path}: invalid DrawingML theme color slot "+ f"{name!r}: {exc}"+ ) from exc+ if hex_ is None:+ raise ValueError(+ f"{theme.path}: unresolved DrawingML theme color slot {name!r}"+ )+ if alpha != 1.0:+ raise ValueError(+ f"{theme.path}: non-opaque DrawingML theme color slot {name!r}"+ )+ self.scheme[name] = hex_[1:]++ def _load_clr_map(self, master: PartRef) -> None:+ master_root = master.xml+ if master_root.tag != f"{{{NS['p']}}}sldMaster":+ raise ValueError(f"{master.path}: expected p:sldMaster root")+ clr_maps = master_root.findall("p:clrMap", NS)+ if len(clr_maps) != 1:+ raise ValueError(+ f"{master.path}: expected exactly one direct p:clrMap"+ )+ clr_map = clr_maps[0]+ children = list(clr_map)+ if (+ set(clr_map.attrib) != set(_COLOR_MAP_SOURCES)+ or children+ or (clr_map.text or "").strip()+ ):+ raise ValueError(+ f"{master.path}: invalid DrawingML color map structure"+ )+ for source in _COLOR_MAP_SOURCES:+ target = clr_map.attrib[source]+ if target not in _THEME_SCHEME_SLOTS:+ raise ValueError(+ f"{master.path}: invalid DrawingML color map target "+ f"{source}={target!r}"+ )+ self.clr_map[source] = targetdef resolve_scheme(self, name: str) -> str | None:"""scheme name (e.g. 'accent1', 'bg1') -> 'RRGGBB'. None on miss."""diff --git a/skills/ppt-master/scripts/test_svg_quality_checker.py b/skills/ppt-master/scripts/test_svg_quality_checker.pyindex aaa2e9c2..28a97ed4 100644--- a/skills/ppt-master/scripts/test_svg_quality_checker.py+++ b/skills/ppt-master/scripts/test_svg_quality_checker.py@@ -50,7 +50,7 @@ from pptx_to_svg.preset_registry_to_svg import render_preset_geometryfrom pptx_to_svg.preset_svg_markup import serialize_preset_layersfrom pptx_to_svg.ln_to_svg import _build_arrow_marker, resolve_strokefrom pptx_to_svg.converter import ConvertOptions, convert_pptx_to_svg-from pptx_to_svg.ooxml_loader import parse_ooxml_boolean+from pptx_to_svg.ooxml_loader import PartRef, parse_ooxml_booleanfrom pptx_to_svg.txbody_to_svg import convert_txbody, convert_vertical_txbodyfrom svg_to_pptx.animation_config import (build_group_listing,@@ -3006,6 +3006,174 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):('#445566', 1.0),)+ def test_native_theme_palette_uses_closed_scheme_and_map_contracts(self):+ a_ns = 'http://schemas.openxmlformats.org/drawingml/2006/main'+ p_ns = 'http://schemas.openxmlformats.org/presentationml/2006/main'+ slots = (+ ('dk1', '<a:sysClr val="windowText" lastClr="112233"/>'),+ ('lt1', '<a:srgbClr val="FFFFFF"/>'),+ ('dk2', '<a:prstClr val="dkBlue"/>'),+ ('lt2', '<a:hslClr hue="0" sat="0" lum="50000"/>'),+ (+ 'accent1',+ '<a:scrgbClr r="50000" g="50000" b="50000"/>',+ ),+ ('accent2', '<a:srgbClr val="445566"/>'),+ ('accent3', '<a:srgbClr val="778899"/>'),+ ('accent4', '<a:srgbClr val="AABBCC"/>'),+ ('accent5', '<a:srgbClr val="DDEEFF"/>'),+ ('accent6', '<a:srgbClr val="123456"/>'),+ ('hlink', '<a:srgbClr val="0000FF"/>'),+ ('folHlink', '<a:srgbClr val="800080"/>'),+ )+ map_values = {+ 'bg1': 'accent1',+ 'tx1': 'dk1',+ 'bg2': 'lt2',+ 'tx2': 'dk2',+ 'accent1': 'accent1',+ 'accent2': 'accent2',+ 'accent3': 'accent3',+ 'accent4': 'accent4',+ 'accent5': 'accent5',+ 'accent6': 'accent6',+ 'hlink': 'hlink',+ 'folHlink': 'folHlink',+ }++ def theme_part(+ slot_values=slots,+ *,+ scheme_attrs='name="Audit"',+ scheme_suffix='',+ theme_elements_count=1,+ ):+ slot_xml = ''.join(+ f'<a:{name}>{color}</a:{name}>'+ for name, color in slot_values+ )+ scheme = (+ f'<a:clrScheme {scheme_attrs}>{slot_xml}'+ f'{scheme_suffix}</a:clrScheme>'+ )+ elements = ''.join(+ f'<a:themeElements>{scheme}</a:themeElements>'+ for _ in range(theme_elements_count)+ )+ return PartRef(+ 'ppt/theme/theme1.xml',+ ET.fromstring(+ f'<a:theme xmlns:a="{a_ns}" name="Audit">'+ f'{elements}</a:theme>'+ ),+ )++ def master_part(attrs=map_values, *, payload=''):+ attr_xml = ' '.join(+ f'{name}="{value}"' for name, value in attrs.items()+ )+ return PartRef(+ 'ppt/slideMasters/slideMaster1.xml',+ ET.fromstring(+ f'<p:sldMaster xmlns:p="{p_ns}" xmlns:a="{a_ns}">'+ f'<p:clrMap {attr_xml}>{payload}</p:clrMap>'+ '</p:sldMaster>'+ ),+ )++ palette = ColorPalette(master_part(), theme_part())+ self.assertEqual(palette.resolve_scheme('bg1'), 'BCBCBC')+ self.assertEqual(palette.resolve_scheme('dk1'), '112233')+ self.assertEqual(palette.resolve_scheme('dk2'), '00008B')+ self.assertEqual(palette.resolve_scheme('lt2'), '808080')++ invalid_themes = (+ (+ theme_part(theme_elements_count=0),+ 'exactly one direct a:themeElements',+ ),+ (+ theme_part(theme_elements_count=2),+ 'exactly one direct a:themeElements',+ ),+ (+ theme_part(slots[:-1]),+ 'color scheme structure',+ ),+ (+ theme_part((slots[1], slots[0], *slots[2:])),+ 'color scheme structure',+ ),+ (+ theme_part(+ (+ slots[0],+ (+ 'lt1',+ '<a:srgbClr val="FFFFFF"/>'+ '<a:srgbClr val="000000"/>',+ ),+ *slots[2:],+ )+ ),+ "theme color slot 'lt1'",+ ),+ (+ theme_part(scheme_attrs='name="Audit" future="x"'),+ 'color scheme structure',+ ),+ (+ theme_part(scheme_suffix='<a:extLst/>'),+ 'color scheme structure',+ ),+ (+ theme_part(+ (+ *slots[:4],+ (+ 'accent1',+ '<a:srgbClr val="112233">'+ '<a:alpha val="50000"/></a:srgbClr>',+ ),+ *slots[5:],+ )+ ),+ "non-opaque DrawingML theme color slot 'accent1'",+ ),+ )+ for invalid_theme, expected in invalid_themes:+ with self.subTest(invalid_theme=expected):+ with self.assertRaisesRegex(ValueError, expected):+ ColorPalette(None, invalid_theme)++ invalid_maps = (+ (+ {name: value for name, value in map_values.items()+ if name != 'bg1'},+ '',+ 'color map structure',+ ),+ (+ {**map_values, 'future': 'dk1'},+ '',+ 'color map structure',+ ),+ (+ {**map_values, 'bg1': 'BG1'},+ '',+ 'color map target',+ ),+ (+ map_values,+ '<a:extLst/>',+ 'color map structure',+ ),+ )+ for attrs, payload, expected in invalid_maps:+ with self.subTest(invalid_map=expected, payload=payload):+ with self.assertRaisesRegex(ValueError, expected):+ ColorPalette(master_part(attrs, payload=payload), None)+def test_native_system_color_requires_registered_fallback(self):invalid_colors = (('<a:sysClr lastClr="112233"/>', 'system color structure'),