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-editor): coalesce staged edits and guard unsaved work
hugohe3f8468ae29c93
diff --git a/skills/ppt-master/scripts/svg_editor/server.py b/skills/ppt-master/scripts/svg_editor/server.pyindex d0efa2d8..af1935dd 100644--- a/skills/ppt-master/scripts/svg_editor/server.py+++ b/skills/ppt-master/scripts/svg_editor/server.py@@ -282,6 +282,42 @@ def _apply_edit_records(root: ET.Element, records: list[dict]) -> tuple[bool, Opreturn True, None+def _edit_signature(record: dict) -> tuple:+ """Identity used to coalesce consecutive staged edits.++ Two edits fold together only when they touch the exact same element and the+ exact same field set (text flag + sorted attr keys). 'Nudge fill 5×'+ collapses to one undo step; 'change fill then font-size' stays two.+ """+ attr_keys = tuple(sorted((record.get('attrs') or {}).keys()))+ return (record.get('element_id'), 'text' in record, attr_keys)+++def _coalesce_into(prev: dict, cur: dict) -> None:+ """Fold cur's new values into prev, keeping prev's original old values.++ Callers guarantee matching signatures, so prev and cur carry the same+ (kind, key) change set; only the 'new' side advances. prev's 'old' is the+ value from before the first edit in the run, which is what undo and the+ edit log should report.+ """+ if 'text' in cur:+ prev['text'] = cur['text']+ if cur.get('attrs'):+ merged = dict(prev.get('attrs') or {})+ merged.update(cur['attrs'])+ prev['attrs'] = merged+ old_by_field = {(c['kind'], c['key']): c['old'] for c in prev['changes']}+ prev['changes'] = [+ {+ 'kind': c['kind'], 'key': c['key'],+ 'old': old_by_field.get((c['kind'], c['key']), c['old']),+ 'new': c['new'],+ }+ for c in cur['changes']+ ]++def create_app(project_dir: str,idle_timeout: int = 900,@@ -644,7 +680,12 @@ def create_app(staged['changes'] = changespending = app.config['PENDING_EDITS'].setdefault(name, [])- pending.append(staged)+ # Coalesce a run of edits to the same element+fields into one undo step+ # so repeated nudges/color tries don't pile up replay work or log noise.+ if pending and _edit_signature(pending[-1]) == _edit_signature(staged):+ _coalesce_into(pending[-1], staged)+ else:+ pending.append(staged)return jsonify({'status': 'ok', 'undo_depth': len(pending)})@app.route('/api/slide/<name>/undo', methods=['POST'])diff --git a/skills/ppt-master/scripts/svg_editor/static/app.js b/skills/ppt-master/scripts/svg_editor/static/app.jsindex 4c712b4d..7cdcb16a 100644--- a/skills/ppt-master/scripts/svg_editor/static/app.js+++ b/skills/ppt-master/scripts/svg_editor/static/app.js@@ -222,6 +222,23 @@var reloadBannerEl = null; // singleton banner element shown when currentSlide mtime driftsvar editStackCount = {}; // {name: staged edit count} — mirrors backend PENDING_EDITSvar savedHintShown = false; // show the "staged edit" hint once per session+ var annotationsDirty = false; // unsaved annotations added/removed this session++ // Staged edits live in server memory until "Apply changes"; the server can+ // still idle-timeout or be killed and drop them. Warn before the tab leaves+ // so the user remembers to apply (browsers show their own generic prompt).+ function hasUnsavedWork() {+ if (annotationsDirty) return true;+ return Object.keys(editStackCount).some(function (k) {+ return editStackCount[k] > 0;+ });+ }+ window.addEventListener("beforeunload", function (e) {+ if (!hasUnsavedWork()) return undefined;+ e.preventDefault();+ e.returnValue = "";+ return "";+ });function currentSlideIndex() {if (!currentSlide) return -1;@@ -848,6 +865,7 @@ids.forEach(function (eid) {slideAnnotations[eid] = text;});+ annotationsDirty = true;refreshAnnotationVisuals();updateAnnotationList();annotationText.value = "";@@ -871,6 +889,7 @@.then(function (res) { return res.json(); }).then(function () {delete slideAnnotations[elementId];+ annotationsDirty = true;refreshAnnotationVisuals();updateAnnotationList();loadSlides();@@ -1007,6 +1026,7 @@modalMessage.textContent = t("modal_success_submit");editStackCount = {};savedHintShown = false;+ annotationsDirty = false;updateUndoButton();var activeSlide = currentSlide;loadSlides().then(function () {diff --git a/skills/ppt-master/workflows/live-preview.md b/skills/ppt-master/workflows/live-preview.mdindex 1bb47d76..29695f02 100644--- a/skills/ppt-master/workflows/live-preview.md+++ b/skills/ppt-master/workflows/live-preview.md@@ -75,7 +75,8 @@ Triggered by the user signals listed in "When to Run".- **UI**: bilingual (EN/中); auto-detects from `navigator.language`, persists in `localStorage`, toggled via the **中 / EN** button on the right panel. Slide navigation: first/prev/next/last buttons at the top of the center panel, plus `←` / `→` / `Home` / `End` (suppressed while typing in the annotation textarea).- **Buttons**: `Add annotation` stages annotation text in memory; `Apply changes` writes staged direct edits plus annotation markers to disk and keeps the service running; `Exit preview` is the only UI action that stops Flask.- **Direct edit (no AI)**: selection mode determines the right-panel surface. Single element = full object inspector (geometry, safe text content, raw SVG attributes except protected fields like `id`, UI `class`, event handlers, and hrefs). SVG `<g>` group = group-level edit surface; select via `Alt/Option` + click or **Select parent group** from a child element. Multi-select = limited batch editor over top-level selected objects only: shared x/y plus `fill` / `stroke` / `opacity`; text style fields (`font-size` / `font-family` / `font-weight` / `text-anchor`) appear only when every selected object is `text`/`tspan`. Preview updates immediately; disk writes wait for **Apply changes**.-- **Undo**: `Ctrl+Z` or the **Undo** button drops the last staged direct edit on the current slide (per-slide LIFO, this session). Applied old→new history is appended to `<project>/.live_edits.jsonl`; un-applied staged edits are in-memory only.+- **Undo**: `Ctrl+Z` or the **Undo** button drops the last staged direct edit on the current slide (per-slide LIFO, this session). Consecutive edits to the *same element and same field set* (e.g. nudging one color or coordinate several times) coalesce into a single undo step, keeping the original pre-edit value; switching element or field starts a new step. Applied old→new history is appended to `<project>/.live_edits.jsonl`; un-applied staged edits are in-memory only.+- **Unsaved-work guard**: staged direct edits and annotation changes (added or removed) live in server memory until **Apply changes**; closing the tab triggers the browser's native "leave site?" prompt while any are unapplied, since an idle timeout or process kill would drop them.- **Re-export is chat-driven**: applying changes updates `svg_output/` only. Refreshing the PPTX (finalize + svg_to_pptx) stays a chat step — the editor never runs the export pipeline.- **Stop conditions**: the service stops when the user clicks **Exit preview** in the browser, asks in chat to stop it, the idle timeout fires, or the process is killed externally.- **Port**: default `5050`; override with `--port <other>`.