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

fix(live-preview): preserve inline geometry edits

hugohe345483536785a
diff --git a/skills/ppt-master/scripts/svg_editor/server.py b/skills/ppt-master/scripts/svg_editor/server.py
index c7358152..a595880b 100644
--- a/skills/ppt-master/scripts/svg_editor/server.py
+++ b/skills/ppt-master/scripts/svg_editor/server.py
@@ -34,7 +34,7 @@ import urllib.request
import webbrowser
import xml.etree.ElementTree as ET
from pathlib import Path
-from typing import Optional
+from typing import Iterable, Optional
from flask import Flask, jsonify, request, send_from_directory
@@ -89,6 +89,11 @@ from embed_icons import ( # noqa: E402
extract_paths_from_icon,
generate_icon_group,
)
+from svg_to_pptx.geometry_properties import ( # noqa: E402
+ GeometryStyleError,
+ INLINE_GEOMETRY_PROPERTIES,
+ materialize_inline_geometry_properties,
+)
_ICONS_DIR = _SCRIPTS_DIR.parent.parent / 'templates' / 'icons'
_USE_ICON_PATTERN = re.compile(r'<use\s+[^>]*data-icon="[^"]*"[^>]*/>')
@@ -184,6 +189,47 @@ def _inline_icons(content: str) -> tuple[str, list[dict]]:
return new_content, warnings
+def _strip_edited_inline_geometry(
+ elem: ET.Element,
+ attr_names: Iterable[str],
+) -> None:
+ """Remove style declarations superseded by edited geometry attributes."""
+ style = elem.get('style')
+ if not style:
+ return
+ tag = elem.tag.rsplit('}', 1)[-1] if '}' in elem.tag else elem.tag
+ supported = INLINE_GEOMETRY_PROPERTIES.get(tag, frozenset())
+ edited = {
+ str(name).lower()
+ for name in attr_names
+ if str(name).lower() in supported
+ }
+ if not edited:
+ return
+
+ retained = []
+ changed = False
+ for raw_declaration in style.split(';'):
+ declaration = raw_declaration.strip()
+ if not declaration:
+ continue
+ if ':' not in declaration:
+ retained.append(declaration)
+ continue
+ raw_name, _raw_value = declaration.split(':', 1)
+ if raw_name.strip().lower() in edited:
+ changed = True
+ continue
+ retained.append(declaration)
+
+ if not changed:
+ return
+ if retained:
+ elem.set('style', '; '.join(retained))
+ else:
+ elem.attrib.pop('style', None)
+
+
# ---------------------------------------------------------------------------
# Staged-edit value validation (POST /api/slide/<name>/edit).
# The browser may expose raw element attributes, so validation protects only
@@ -290,6 +336,10 @@ def _apply_edit_record(root: ET.Element, record: dict) -> tuple[bool, Optional[s
return ok, reason
attrs = record.get('attrs')
if attrs:
+ target = _find_by_id(root, element_id)
+ if target is None:
+ return False, 'not-found'
+ _strip_edited_inline_geometry(target, attrs.keys())
ok, reason = set_attributes(root, element_id, attrs)
if not ok:
return ok, reason
@@ -578,6 +628,12 @@ def create_app(
logger.warning('slide parse failed: %s: %s', name, exc)
return jsonify({'error': f'Failed to parse SVG: {exc}'}), 500
+ try:
+ materialize_inline_geometry_properties(root)
+ except GeometryStyleError as exc:
+ logger.warning('slide geometry materialization failed: %s: %s', name, exc)
+ return jsonify({'error': f'Invalid inline geometry: {exc}'}), 400
+
assign_temp_ids(root)
if pending_edits:
ok, reason = _apply_edit_records(root, pending_edits)
@@ -712,6 +768,11 @@ def create_app(
except ET.ParseError as exc:
return jsonify({'error': f'Failed to parse SVG: {exc}'}), 500
+ try:
+ materialize_inline_geometry_properties(root)
+ except GeometryStyleError as exc:
+ return jsonify({'error': f'Invalid inline geometry: {exc}'}), 400
+
assign_temp_ids(root)
pending = app.config['PENDING_EDITS'].get(name) or []
ok, reason = _apply_edit_records(root, pending)
@@ -741,6 +802,7 @@ def create_app(
staged['text'] = new_text
if attrs:
old_attrs = {k: target.get(k) for k in attrs}
+ _strip_edited_inline_geometry(target, attrs.keys())
ok, reason = set_attributes(root, element_id, attrs)
if not ok:
return jsonify({'error': f'Attribute edit failed: {reason}'}), (
diff --git a/skills/ppt-master/scripts/svg_editor/static/app.js b/skills/ppt-master/scripts/svg_editor/static/app.js
index c148f338..6327536e 100644
--- a/skills/ppt-master/scripts/svg_editor/static/app.js
+++ b/skills/ppt-master/scripts/svg_editor/static/app.js
@@ -901,7 +901,48 @@
applyElementAttrs(el, sa);
}
+ var INLINE_GEOMETRY_STYLE_PROPERTIES = {
+ rect: new Set(["x", "y", "width", "height", "rx", "ry"]),
+ circle: new Set(["cx", "cy", "r"]),
+ ellipse: new Set(["cx", "cy", "rx", "ry"]),
+ image: new Set(["x", "y", "width", "height"]),
+ svg: new Set(["x", "y", "width", "height"]),
+ use: new Set(["x", "y", "width", "height"])
+ };
+
+ function stripEditedInlineGeometry(el, attrs) {
+ var style = el.getAttribute("style");
+ var supported = INLINE_GEOMETRY_STYLE_PROPERTIES[localName(el)];
+ if (!style || !supported) return;
+ var edited = new Set(Object.keys(attrs || {}).map(function (key) {
+ return String(key).toLowerCase();
+ }).filter(function (key) { return supported.has(key); }));
+ if (edited.size === 0) return;
+
+ var retained = [];
+ var changed = false;
+ style.split(";").forEach(function (rawDeclaration) {
+ var declaration = rawDeclaration.trim();
+ if (!declaration) return;
+ var colon = declaration.indexOf(":");
+ if (colon < 0) {
+ retained.push(declaration);
+ return;
+ }
+ var name = declaration.slice(0, colon).trim().toLowerCase();
+ if (edited.has(name)) {
+ changed = true;
+ return;
+ }
+ retained.push(declaration);
+ });
+ if (!changed) return;
+ if (retained.length > 0) el.setAttribute("style", retained.join("; "));
+ else el.removeAttribute("style");
+ }
+
function applyElementAttrs(el, attrs) {
+ stripEditedInlineGeometry(el, attrs);
if (localName(el) === "g" && el.hasAttribute("data-icon") &&
attrs.x !== undefined && attrs.y !== undefined) {
// The preview expands <use data-icon> into a <g>, but disk still owns
@@ -2620,7 +2661,7 @@
var attrs = {};
attrs[key] = value;
stageEditRequest(eid, { attrs: attrs })
- .then(function () { el.setAttribute(key, value); })
+ .then(function () { applyElementAttrs(el, attrs); })
.catch(function (err) { showError(t("err_edit") + err.message); });
}
@@ -2856,7 +2897,7 @@
var attrs = {};
attrs[key] = value;
return stageEditRequest(el.id, { attrs: attrs }).then(function () {
- el.setAttribute(key, value);
+ applyElementAttrs(el, attrs);
});
});
Promise.all(jobs)