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-editor): add drag-to-move, arrow nudge, and overlap picker

hugohe301e290bcf20a
diff --git a/skills/ppt-master/scripts/svg_editor/annotations.py b/skills/ppt-master/scripts/svg_editor/annotations.py
index d9284fc1..7a02353c 100644
--- a/skills/ppt-master/scripts/svg_editor/annotations.py
+++ b/skills/ppt-master/scripts/svg_editor/annotations.py
@@ -14,6 +14,8 @@ Dependencies:
"""
import xml.etree.ElementTree as ET
+import re
+from copy import deepcopy
from typing import Optional
SVG_NS = 'http://www.w3.org/2000/svg'
@@ -50,6 +52,154 @@ def _find_by_id(root: ET.Element, element_id: str) -> Optional[ET.Element]:
return None
+def _find_with_parent(
+ root: ET.Element, element_id: str,
+) -> tuple[Optional[ET.Element], Optional[ET.Element]]:
+ """Find an element and its parent by id."""
+ for parent in root.iter():
+ for child in list(parent):
+ if child.get('id') == element_id:
+ return child, parent
+ return None, None
+
+
+def _local_name(elem: ET.Element) -> str:
+ return elem.tag.split('}', 1)[1] if '}' in elem.tag else elem.tag
+
+
+def _first_number(value: Optional[str]) -> Optional[float]:
+ if value is None:
+ return None
+ match = re.search(r'-?\d+(?:\.\d+)?', value)
+ return float(match.group(0)) if match else None
+
+
+def _format_number(value: float) -> str:
+ text = f'{value:.3f}'.rstrip('0').rstrip('.')
+ return text or '0'
+
+
+def _tspan_baseline(text_el: ET.Element, tspan_el: ET.Element) -> Optional[tuple[float, float]]:
+ cur_x = _first_number(text_el.get('x'))
+ cur_y = _first_number(text_el.get('y'))
+ for child in list(text_el):
+ if _local_name(child) != 'tspan':
+ continue
+ x_val = _first_number(child.get('x'))
+ y_val = _first_number(child.get('y'))
+ dx_val = _first_number(child.get('dx'))
+ dy_val = _first_number(child.get('dy'))
+ if x_val is not None:
+ cur_x = x_val
+ elif dx_val is not None:
+ cur_x = (cur_x or 0.0) + dx_val
+ if y_val is not None:
+ cur_y = y_val
+ elif dy_val is not None:
+ cur_y = (cur_y or 0.0) + dy_val
+ if child is tspan_el:
+ break
+ if cur_x is None or cur_y is None:
+ return None
+ return cur_x, cur_y
+
+
+def _adjust_following_tspan_dy(
+ text_el: ET.Element,
+ target: ET.Element,
+) -> None:
+ """Keep later line-break tspans visually stable when one sibling is removed."""
+ children = list(text_el)
+ try:
+ idx = children.index(target)
+ except ValueError:
+ return
+ if idx + 1 >= len(children):
+ return
+ next_el = children[idx + 1]
+ if _local_name(next_el) != 'tspan' or next_el.get('y') is not None or next_el.get('dy') is None:
+ return
+ next_baseline = _tspan_baseline(text_el, next_el)
+ if next_baseline is None:
+ return
+ prev_y: Optional[float] = None
+ for prior in reversed(children[:idx]):
+ if _local_name(prior) != 'tspan':
+ continue
+ prior_baseline = _tspan_baseline(text_el, prior)
+ if prior_baseline is not None:
+ prev_y = prior_baseline[1]
+ break
+ if prev_y is None:
+ prev_y = _first_number(text_el.get('y')) or 0.0
+ next_el.set('dy', _format_number(next_baseline[1] - prev_y))
+
+
+def _copy_text_attrs(src: ET.Element, dst: ET.Element, skip: set[str]) -> None:
+ for key, value in src.attrib.items():
+ if key not in skip:
+ dst.set(key, value)
+
+
+def promote_tspan_to_text(
+ root: ET.Element,
+ element_id: str,
+ x: str,
+ y: str,
+) -> tuple[bool, Optional[str]]:
+ """Promote a moved direct-child <tspan> into an independent <text>.
+
+ Writing vertical movement into ``dy`` changes the baseline for following
+ tspans. Promotion preserves the edited line as its own object whose final
+ position lives in x/y, while adjacent lines remain anchored in the parent.
+ """
+ target, text_el = _find_with_parent(root, element_id)
+ if target is None or text_el is None:
+ return False, 'not-found'
+ if _local_name(target) != 'tspan' or _local_name(text_el) != 'text':
+ return False, 'not-tspan'
+
+ grandparent: Optional[ET.Element] = None
+ for candidate in root.iter():
+ if text_el in list(candidate):
+ grandparent = candidate
+ break
+ if grandparent is None:
+ return False, 'parent-not-found'
+
+ _adjust_following_tspan_dy(text_el, target)
+
+ new_text = ET.Element(f'{{{SVG_NS}}}text')
+ _copy_text_attrs(text_el, new_text, {'id', 'x', 'y', 'dx', 'dy'})
+ _copy_text_attrs(target, new_text, {'id', 'x', 'y', 'dx', 'dy', 'transform'})
+ new_text.set('id', element_id)
+ new_text.set('x', x)
+ new_text.set('y', y)
+
+ if len(list(target)) == 0:
+ new_text.text = ''.join(target.itertext())
+ else:
+ new_text.text = target.text
+ for child in list(target):
+ new_text.append(deepcopy(child))
+
+ target_index = list(text_el).index(target)
+ tail = target.tail
+ text_el.remove(target)
+ if tail:
+ if target_index == 0:
+ text_el.text = (text_el.text or '') + tail
+ else:
+ prev = list(text_el)[target_index - 1]
+ prev.tail = (prev.tail or '') + tail
+
+ parent_index = list(grandparent).index(text_el)
+ grandparent.insert(parent_index + 1, new_text)
+ if not (text_el.text or '').strip() and len(list(text_el)) == 0:
+ grandparent.remove(text_el)
+ return True, None
+
+
def parse_annotations(root: ET.Element) -> list[dict]:
"""Extract all annotations from an SVG element tree."""
annotations = []
@@ -145,7 +295,10 @@ def set_attributes(
if not is_editable_attr(key):
return False, f'attr-not-allowed:{key}'
for key, value in attrs.items():
- elem.set(key, str(value))
+ if value is None:
+ elem.attrib.pop(key, None)
+ else:
+ elem.set(key, str(value))
return True, None
diff --git a/skills/ppt-master/scripts/svg_editor/server.py b/skills/ppt-master/scripts/svg_editor/server.py
index af1935dd..a5649eda 100644
--- a/skills/ppt-master/scripts/svg_editor/server.py
+++ b/skills/ppt-master/scripts/svg_editor/server.py
@@ -19,6 +19,7 @@ Dependencies:
import argparse
import atexit
+import html
import json
import logging
import os
@@ -53,6 +54,7 @@ from annotations import ( # noqa: E402
assign_temp_ids,
is_editable_attr,
parse_annotations,
+ promote_tspan_to_text,
set_annotation,
set_attributes,
set_text,
@@ -78,6 +80,11 @@ _LIST_CACHE_LOCK = threading.Lock()
_LIST_CACHE: dict = {} # path -> (mtime, annotation_count_on_disk)
+def _xml_attr(value: object) -> str:
+ """Escape a value for safe insertion into generated preview SVG markup."""
+ return html.escape(str(value), quote=True)
+
+
def _cache_get(cache: dict, lock: threading.Lock, path: str, mtime: float):
with lock:
entry = cache.get(path)
@@ -181,8 +188,17 @@ def _inline_icons(content: str) -> tuple[str, list[dict]]:
replacement = generate_icon_group(attrs, elements, style, base_size)
id_match = re.search(r'\bid="([^"]+)"', use_str)
if id_match:
+ preview_attrs = [
+ f'id="{_xml_attr(id_match.group(1))}"',
+ f'data-icon="{_xml_attr(icon_name)}"',
+ ]
+ for key in ('x', 'y', 'width', 'height'):
+ if key in attrs:
+ preview_attrs.append(f'data-use-{key}="{_xml_attr(attrs[key])}"')
+ if 'transform' in attrs:
+ preview_attrs.append('data-use-has-transform="1"')
replacement = replacement.replace(
- '<g ', f'<g id="{id_match.group(1)}" data-icon="{icon_name}" ', 1,
+ '<g ', f'<g {" ".join(preview_attrs)} ', 1,
)
new_content = new_content[:match.start()] + replacement + new_content[match.end():]
return new_content, warnings
@@ -219,6 +235,10 @@ def _validate_edit_attrs(attrs: dict, existing_attrs: set[str]) -> Optional[str]
return f'attribute not editable: {key}'
if key not in existing_attrs and key != 'transform' and key not in _ADDABLE_BATCH_ATTRS:
return f'attribute does not exist on element: {key}'
+ if value is None:
+ if key not in existing_attrs:
+ return f'attribute does not exist on element: {key}'
+ continue
if not isinstance(value, str):
return f'value must be a string: {key}'
if len(value) > _MAX_ATTR_VALUE_LEN:
@@ -262,6 +282,18 @@ def _apply_edit_record(root: ET.Element, record: dict) -> tuple[bool, Optional[s
element_id = record.get('element_id')
if not isinstance(element_id, str):
return False, 'invalid-record'
+ promote = record.get('promote_tspan')
+ if promote:
+ if not isinstance(promote, dict):
+ return False, 'invalid-promote'
+ ok, reason = promote_tspan_to_text(
+ root,
+ element_id,
+ str(promote.get('x') or ''),
+ str(promote.get('y') or ''),
+ )
+ if not ok:
+ return ok, reason
if 'text' in record:
ok, reason = set_text(root, element_id, str(record.get('text') or ''))
if not ok:
@@ -290,7 +322,8 @@ def _edit_signature(record: dict) -> tuple:
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)
+ promote_keys = tuple(sorted((record.get('promote_tspan') or {}).keys()))
+ return (record.get('element_id'), 'text' in record, attr_keys, promote_keys)
def _coalesce_into(prev: dict, cur: dict) -> None:
@@ -307,6 +340,8 @@ def _coalesce_into(prev: dict, cur: dict) -> None:
merged = dict(prev.get('attrs') or {})
merged.update(cur['attrs'])
prev['attrs'] = merged
+ if cur.get('promote_tspan'):
+ prev['promote_tspan'] = cur['promote_tspan']
old_by_field = {(c['kind'], c['key']): c['old'] for c in prev['changes']}
prev['changes'] = [
{
@@ -624,7 +659,8 @@ def create_app(
new_text = data.get('text')
attrs = data.get('attrs')
- if new_text is None and not attrs:
+ promote = data.get('promote_tspan')
+ if new_text is None and not attrs and not promote:
return jsonify({'error': 'Nothing to edit (no text or attrs)'}), 400
if new_text is not None:
@@ -633,6 +669,13 @@ def create_app(
if attrs is not None:
if not isinstance(attrs, dict):
return jsonify({'error': 'attrs must be an object'}), 400
+ if promote is not None:
+ if not isinstance(promote, dict):
+ return jsonify({'error': 'promote_tspan must be an object'}), 400
+ for key in ('x', 'y'):
+ value = promote.get(key)
+ if not isinstance(value, str) or not re.fullmatch(r'-?\d+(?:\.\d+)?', value):
+ return jsonify({'error': f'invalid promote_tspan.{key}'}), 400
try:
tree = ET.parse(str(svg_file))
@@ -677,6 +720,27 @@ def create_app(
for k, v in attrs.items():
changes.append({'kind': 'attr', 'key': k, 'old': old_attrs[k], 'new': v})
staged['attrs'] = attrs
+ if promote:
+ tag = target.tag.split('}', 1)[1] if '}' in target.tag else target.tag
+ old_state = {
+ 'tag': tag,
+ 'x': target.get('x'),
+ 'y': target.get('y'),
+ 'dy': target.get('dy'),
+ 'transform': target.get('transform'),
+ }
+ ok, reason = promote_tspan_to_text(root, element_id, promote['x'], promote['y'])
+ if not ok:
+ return jsonify({'error': f'Tspan promotion failed: {reason}'}), (
+ 404 if reason == 'not-found' else 400
+ )
+ changes.append({
+ 'kind': 'structure',
+ 'key': 'promote-tspan',
+ 'old': old_state,
+ 'new': {'tag': 'text', 'x': promote['x'], 'y': promote['y']},
+ })
+ staged['promote_tspan'] = promote
staged['changes'] = changes
pending = app.config['PENDING_EDITS'].setdefault(name, [])
diff --git a/skills/ppt-master/scripts/svg_editor/static/app.js b/skills/ppt-master/scripts/svg_editor/static/app.js
index 7cdcb16a..d80182b8 100644
--- a/skills/ppt-master/scripts/svg_editor/static/app.js
+++ b/skills/ppt-master/scripts/svg_editor/static/app.js
@@ -50,6 +50,7 @@
btn_undo: "Undo",
undo_done: "Reverted last staged edit",
undo_empty: "No staged edit to undo",
+ overlap_caption: "Overlapping here — pick one",
err_empty_svg: "Slide loaded but the canvas is empty. The SVG may be malformed or missing a root <svg> element.",
warn_icon_inline: "{count} icon(s) failed to render: {names}",
warn_svg_no_dims: "SVG is missing width/height attributes. Please ask the AI to strictly follow shared-standards.md §4 and include width & height in the SVG root element.",
@@ -111,6 +112,7 @@
btn_undo: "撤销",
undo_done: "已撤销上一条暂存修改",
undo_empty: "没有可撤销的暂存修改",
+ overlap_caption: "此处重叠元素——点击选择",
err_empty_svg: "幻灯片已加载但画布为空。SVG 可能损坏或缺少根 <svg> 元素。",
warn_icon_inline: "{count} 个图标渲染失败:{names}",
warn_svg_no_dims: "SVG 缺少 width/height 属性,预览可能异常。请让 AI 严格遵守 shared-standards.md §4 规范,在 SVG 根元素中补全 width 和 height。",
@@ -621,6 +623,322 @@
var suppressNextSvgClick = false;
var RUBBER_BAND_THRESHOLD = 5;
+ // ---- Drag-to-move (direct geometry edit on the canvas) ----
+ // Pressing on an already-selected element drags the whole selection. Frames
+ // only update the preview; one staged edit per element is written on release,
+ // reusing attrsForMove + stageEditRequest (and backend coalescing).
+ var dragStart = null; // {x, y} screen coords at mousedown on a selection
+ var dragMoved = false; // crossed the move threshold this gesture
+ var dragEls = []; // top-level selected elements being moved
+ var dragStartAttrs = {}; // {id: startGeometryAttrs} for drift-free preview
+
+ function hitSelectedAncestor(target) {
+ // Walk up from the pressed node to the first element already in the
+ // selection, so a press on a selected shape (or its inner preview
+ // children) starts a drag regardless of how it was selected.
+ var svg = svgContent.querySelector("svg");
+ var node = target;
+ while (node && node !== svg && node.nodeType === 1) {
+ if (node.id && selectedElementIds.has(node.id)) return node;
+ node = node.parentNode;
+ }
+ return null;
+ }
+
+ function screenDeltaToLocal(el, dxScreen, dyScreen) {
+ // Map a screen-pixel delta into the coordinate space computeRenderBox /
+ // attrsForMove use for THIS element (its getCTM() output space). Using the
+ // element's own getCTM ∘ getScreenCTM⁻¹ is robust to how a browser splits
+ // the viewBox scale between getCTM and getScreenCTM, and naturally accounts
+ // for each element's own group transform (correct under multi-select).
+ var sctm = el.getScreenCTM ? el.getScreenCTM() : null;
+ var ctm = el.getCTM ? el.getCTM() : null;
+ if (!sctm || !ctm) return { x: dxScreen, y: dyScreen };
+ try {
+ var n = ctm.multiply(sctm.inverse()); // linear part: screen → local delta
+ var lx = n.a * dxScreen + n.c * dyScreen;
+ var ly = n.b * dxScreen + n.d * dyScreen;
+ // Singular CTM → SVGMatrix.inverse() throws, DOMMatrix yields NaN.
+ // Either way, fall back to the raw delta rather than wedge the drag.
+ if (!isFinite(lx) || !isFinite(ly)) return { x: dxScreen, y: dyScreen };
+ return { x: lx, y: ly };
+ } catch (err) {
+ return { x: dxScreen, y: dyScreen };
+ }
+ }
+
+ function beginDrag() {
+ dragEls = topLevelSelectedElements(Array.from(selectedElementIds));
+ dragStartAttrs = {};
+ dragEls.forEach(function (el) {
+ // attrsForMove(el, 0, 0) returns the element's current geometry in the
+ // exact attribute shape a move writes (x/y, cx/cy, … or transform);
+ // restoring it before each frame keeps the preview drift-free.
+ try { dragStartAttrs[el.id] = attrsForMove(el, 0, 0); }
+ catch (err) { dragStartAttrs[el.id] = null; }
+ });
+ document.body.classList.add("svg-dragging");
+ }
+
+ function applyAttrSnapshot(el, sa) {
+ if (!sa) return;
+ applyElementAttrs(el, sa);
+ }
+
+ function applyElementAttrs(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
+ // the source <use>. Keep the browser geometry in sync while the staged
+ // edit writes x/y back to the real placeholder instead of persisting a
+ // transform.
+ var m = ownMatrix(el);
+ el.setAttribute("transform", "matrix(" + [
+ formatCoord(m.a), formatCoord(m.b), formatCoord(m.c),
+ formatCoord(m.d), formatCoord(parseFloat(attrs.x)),
+ formatCoord(parseFloat(attrs.y))
+ ].join(",") + ")");
+ el.setAttribute("data-use-x", attrs.x);
+ el.setAttribute("data-use-y", attrs.y);
+ }
+ Object.keys(attrs).forEach(function (k) {
+ if (localName(el) === "g" && el.hasAttribute("data-icon") &&
+ (k === "x" || k === "y" || k === "transform")) return;
+ if (attrs[k] === null || attrs[k] === undefined) el.removeAttribute(k);
+ else el.setAttribute(k, attrs[k]);
+ });
+ }
+
+ function localName(el) {
+ return el && el.tagName ? el.tagName.toLowerCase() : "";
+ }
+
+ function markCommittedAttrs(el, attrs) {
+ if (attrs && attrs.transform === null &&
+ localName(el) === "g" && el.hasAttribute("data-icon")) {
+ el.removeAttribute("data-use-has-transform");
+ }
+ }
+
+ function payloadForCurrentElementState(el, payload) {
+ if (!payload || !payload.attrs || payload.attrs.transform !== null ||
+ localName(el) !== "g" || !el.hasAttribute("data-icon") ||
+ el.hasAttribute("data-use-has-transform")) {
+ return payload;
+ }
+ var attrs = Object.assign({}, payload.attrs);
+ delete attrs.transform;
+ return Object.assign({}, payload, { attrs: attrs });
+ }
+
+ function restoreDragStart(el) {
+ applyAttrSnapshot(el, dragStartAttrs[el.id]);
+ }
+
+ function applyMoveLocal(el, dxScreen, dyScreen) {
+ // Each element converts the shared screen delta into its own local space,
+ // so a selection spanning differently-transformed groups still tracks the
+ // pointer. Restore-then-apply keeps every frame relative to the start.
+ restoreDragStart(el);
+ var d = screenDeltaToLocal(el, dxScreen, dyScreen);
+ var attrs;
+ try { attrs = attrsForMove(el, d.x, d.y); }
+ catch (err) { attrs = null; }
+ if (!attrs) return null;
+ applyElementAttrs(el, attrs);
+ return attrs;
+ }
+
+ function updateDragPreview(dxScreen, dyScreen) {
+ dragEls.forEach(function (el) { applyMoveLocal(el, dxScreen, dyScreen); });
+ if (dragEls.length === 1) refreshGeoInputs(dragEls[0], elementPropsEl);
+ }
+
+ function commitDrag(dxScreen, dyScreen) {
+ var single = dragEls.length === 1;
+ dragEls.forEach(function (el) {
+ // Capture the pre-drag snapshot in the closure: endDrag() clears
+ // dragStartAttrs synchronously after this call, before the staging
+ // promise can reject, so the rollback can't rely on the global.
+ var startAttrs = dragStartAttrs[el.id];
+ var attrs = applyMoveLocal(el, dxScreen, dyScreen);
+ if (!attrs) return;
+ var payload = payloadForMovedElement(el, attrs);
+ stageEditRequest(el.id, payload).then(function () {
+ if (payload.attrs) markCommittedAttrs(el, payload.attrs);
+ if (payload.promote_tspan) {
+ var promoted = promoteTspanDom(el, payload.promote_tspan);
+ if (promoted && single) refreshGeoInputs(promoted, elementPropsEl);
+ }
+ }).catch(function (err) {
+ // Optimistic preview already moved the element; roll it back so the
+ // canvas never shows a move the server never staged.
+ applyAttrSnapshot(el, startAttrs);
+ if (single) refreshGeoInputs(el, elementPropsEl);
+ showError(t("err_edit") + err.message);
+ });
+ });
+ }
+
+ function endDrag() {
+ dragStart = null;
+ dragMoved = false;
+ dragEls = [];
+ dragStartAttrs = {};
+ document.body.classList.remove("svg-dragging");
+ }
+
+ // Per-element nudge staging is serialized: a held arrow key fires many
+ // keydowns, each sending an *absolute* position. Without ordering, the
+ // unlocked backend could coalesce them out of order and leave the staged
+ // value behind the on-screen one. So at most one nudge stage per element is
+ // in flight; extra keypresses only update the preview and the queued target,
+ // and the next send reads the current DOM position (= the latest).
+ var nudgeFlight = {}; // key -> bool: a nudge stage is in flight
+ var nudgeQueued = {}; // key -> {el, single, slide, attrs}: latest target awaiting send
+ var nudgeLastOk = {}; // key -> attrs: last position the server confirmed
+
+ function nudgeKey(slide, el) { return slide + "|" + el.id; }
+
+ function sendNudge(key, el, single, slide, payload) {
+ if (!payload) return;
+ payload = payloadForCurrentElementState(el, payload);
+ nudgeFlight[key] = true;
+ stageEditRequest(el.id, payload, slide).then(function () {
+ if (payload.attrs) nudgeLastOk[key] = payload.attrs;
+ if (payload.attrs) markCommittedAttrs(el, payload.attrs);
+ nudgeFlight[key] = false;
+ var q = nudgeQueued[key];
+ if (q) { delete nudgeQueued[key]; sendNudge(key, q.el, q.single, q.slide, q.payload); }
+ }).catch(function (err) {
+ nudgeFlight[key] = false;
+ delete nudgeQueued[key];
+ // Re-sync the preview to the last confirmed position so it can't show
+ // a move the server never staged (only meaningful on the live slide).
+ if (payload.promote_tspan && el.__promotionRollback) {
+ var restored = el.__promotionRollback();
+ if (single && restored) refreshGeoInputs(restored, elementPropsEl);
+ } else if (nudgeLastOk[key] && slide === currentSlide && el.isConnected) {
+ applyAttrSnapshot(el, nudgeLastOk[key]);
+ if (single) refreshGeoInputs(el, elementPropsEl);
+ }
+ showError(t("err_edit") + err.message);
+ });
+ }
+
+ function stageNudge(el, single, slide, payload) {
+ var key = nudgeKey(slide, el);
+ if (nudgeFlight[key]) {
+ nudgeQueued[key] = { el: el, single: single, slide: slide, payload: payload };
+ return;
+ }
+ sendNudge(key, el, single, slide, payload);
+ }
+
+ function nudgeSelection(dxScreen, dyScreen) {
+ // Keyboard arrow micro-move: same geometry path as drag. The DOM updates
+ // immediately; staging is serialized per element (see sendNudge), and
+ // consecutive same-direction nudges coalesce into one undo step.
+ var els = topLevelSelectedElements(Array.from(selectedElementIds));
+ if (els.length === 0) return;
+ var slide = currentSlide;
+ var single = els.length === 1;
+ var lastSingleEl = null;
+ els.forEach(function (el) {
+ var key = nudgeKey(slide, el);
+ if (!nudgeFlight[key] && !nudgeQueued[key]) {
+ // Fresh burst: re-capture the pre-move baseline from the current
+ // DOM, so a failed nudge rolls back to *this* burst's start rather
+ // than a stale position left by an earlier drag/edit/undo.
+ try { nudgeLastOk[key] = attrsForMove(el, 0, 0); }
+ catch (err) { delete nudgeLastOk[key]; }
+ }
+ var d = screenDeltaToLocal(el, dxScreen, dyScreen);
+ var attrs;
+ try { attrs = attrsForMove(el, d.x, d.y); } catch (err) { attrs = null; }
+ if (!attrs) return;
+ applyElementAttrs(el, attrs);
+ var payload = payloadForMovedElement(el, attrs);
+ if (payload.promote_tspan) {
+ el = promoteTspanDom(el, payload.promote_tspan) || el;
+ }
+ lastSingleEl = el;
+ stageNudge(el, single, slide, payload);
+ });
+ if (single && lastSingleEl) refreshGeoInputs(lastSingleEl, elementPropsEl);
+ }
+
+ // ---- Overlap picker (right-click → list every selectable element here) ----
+ // Left-click stays a fast "select the topmost" gesture; right-click is the
+ // opt-in disambiguator for stacked elements, so it never pops on normal use.
+ var overlapPickerEl = null;
+
+ function collectSelectableAt(clientX, clientY) {
+ var svg = svgContent.querySelector("svg");
+ if (!svg || !document.elementsFromPoint) return [];
+ var out = [];
+ var seen = {};
+ document.elementsFromPoint(clientX, clientY).forEach(function (node) {
+ if (!svg.contains(node) || node === svg) return;
+ if (node.closest && node.closest("defs, style, title, desc")) return;
+ // Resolve to the disk-backed selectable entity, mirroring the click
+ // handler: prefer an enclosing data-icon group, else nearest id.
+ var picked = (node.closest && node.closest("[data-icon][id]")) ||
+ (node.closest && node.closest("[id]"));
+ if (!picked || picked === svg || !picked.id || seen[picked.id]) return;
+ seen[picked.id] = true;
+ out.push(picked);
+ });
+ return out; // top → bottom in paint order
+ }
+
+ function closeOverlapPicker() {
+ if (!overlapPickerEl) return;
+ var svg = svgContent.querySelector("svg");
+ if (svg) {
+ svg.querySelectorAll(".overlap-hover").forEach(function (e) {
+ e.classList.remove("overlap-hover");
+ });
+ }
+ overlapPickerEl.remove();
+ overlapPickerEl = null;
+ }
+
+ function showOverlapPicker(clientX, clientY, candidates) {
+ closeOverlapPicker();
+ var menu = document.createElement("div");
+ menu.id = "overlap-picker";
+ var cap = document.createElement("div");
+ cap.className = "overlap-caption";
+ cap.textContent = t("overlap_caption");
+ menu.appendChild(cap);
+ candidates.forEach(function (el) {
+ var item = document.createElement("div");
+ item.className = "overlap-item";
+ var tag = el.tagName.toLowerCase();
+ var txt = (tag === "text" || tag === "tspan")
+ ? (el.textContent || "").trim().slice(0, 28) : "";
+ item.innerHTML = '<span class="overlap-tag">&lt;' + escapeHtml(tag) +
+ '&gt;</span><span class="overlap-id">' + escapeHtml(el.id) + '</span>' +
+ (txt ? '<span class="overlap-txt">' + escapeHtml(txt) + '</span>' : '');
+ item.addEventListener("mouseenter", function () { el.classList.add("overlap-hover"); });
+ item.addEventListener("mouseleave", function () { el.classList.remove("overlap-hover"); });
+ item.addEventListener("click", function (ev) {
+ ev.stopPropagation();
+ selectElement(el, ev.ctrlKey || ev.metaKey);
+ closeOverlapPicker();
+ });
+ menu.appendChild(item);
+ });
+ document.body.appendChild(menu);
+ // Keep the menu inside the viewport.
+ var x = Math.min(clientX, window.innerWidth - menu.offsetWidth - 8);
+ var y = Math.min(clientY, window.innerHeight - menu.offsetHeight - 8);
+ menu.style.left = Math.max(8, x) + "px";
+ menu.style.top = Math.max(8, y) + "px";
+ overlapPickerEl = menu;
+ }
+
function initRubberBand() {
var overlay = document.getElementById("rubber-band-overlay");
var container = document.getElementById("svg-container");
@@ -629,6 +947,15 @@
// Only left mouse button
if (e.button !== 0) return;
+ // Pressing on an already-selected element arms a drag of the whole
+ // selection instead of a rubber band. Selecting stays a separate
+ // click, so the background is never dragged by accident.
+ if (hitSelectedAncestor(e.target)) {
+ dragStart = { x: e.clientX, y: e.clientY };
+ dragMoved = false;
+ return;
+ }
+
// Always start tracking — rubber band only activates when
// mousemove exceeds the threshold. This allows clicking on any
// element (including SVG background rects) to still trigger
@@ -638,6 +965,19 @@
});
document.addEventListener("mousemove", function (e) {
+ if (dragStart) {
+ var ddx = e.clientX - dragStart.x;
+ var ddy = e.clientY - dragStart.y;
+ if (!dragMoved && Math.sqrt(ddx * ddx + ddy * ddy) < RUBBER_BAND_THRESHOLD) {
+ return; // below threshold — still a click, let selection stand
+ }
+ if (!dragMoved) {
+ dragMoved = true;
+ beginDrag();
+ }
+ updateDragPreview(ddx, ddy);
+ return;
+ }
if (!rubberBandStart) return;
var dx = e.clientX - rubberBandStart.x;
@@ -672,6 +1012,17 @@
});
document.addEventListener("mouseup", function (e) {
+ if (dragStart) {
+ if (dragMoved) {
+ commitDrag(e.clientX - dragStart.x, e.clientY - dragStart.y);
+ // Swallow the click that follows the drag-release so it does
+ // not re-trigger selection on the dropped element.
+ suppressNextSvgClick = true;
+ window.setTimeout(function () { suppressNextSvgClick = false; }, 50);
+ }
+ endDrag();
+ return;
+ }
if (!rubberBandStart) return;
overlay.classList.remove("active");
@@ -712,6 +1063,26 @@
rubberBandStart = null;
});
+
+ // Right-click → list every selectable element under the pointer, so
+ // stacked/overlapping shapes can be reached without blind cycling.
+ container.addEventListener("contextmenu", function (e) {
+ var svg = svgContent.querySelector("svg");
+ if (!svg) return;
+ var cands = collectSelectableAt(e.clientX, e.clientY);
+ if (cands.length === 0) return; // nothing here → native menu
+ e.preventDefault();
+ if (cands.length === 1) { selectElement(cands[0], false); return; }
+ showOverlapPicker(e.clientX, e.clientY, cands);
+ });
+
+ // Dismiss the picker on any press outside it (item clicks stop their own
+ // propagation, so this never fires before a selection is made).
+ document.addEventListener("mousedown", function (e) {
+ if (overlapPickerEl && !overlapPickerEl.contains(e.target)) {
+ closeOverlapPicker();
+ }
+ });
}
function cancelRubberBand() {
@@ -723,6 +1094,8 @@
var ov = document.getElementById("rubber-band-overlay");
if (ov) ov.classList.remove("active");
suppressNextSvgClick = false;
+ endDrag();
+ closeOverlapPicker();
}
function selectByRubberBand(screenRect) {
@@ -808,15 +1181,30 @@
updateSelectionPanel();
}
- // Escape: clear selection (skip if textarea is focused)
+ // Escape: close the overlap picker first if open, else clear selection.
if (e.key === "Escape") {
if (document.activeElement === annotationText) return;
+ if (overlapPickerEl) { closeOverlapPicker(); return; }
clearSelection();
}
// Slide navigation: ArrowLeft/Right + Home/End (skip while typing)
if (document.activeElement === annotationText) return;
if (e.ctrlKey || e.metaKey || e.altKey) return;
+
+ // Arrow keys nudge the selection (1px, Shift = 10px) instead of
+ // navigating slides whenever something is selected.
+ if (selectedElementIds.size > 0 &&
+ (e.key === "ArrowLeft" || e.key === "ArrowRight" ||
+ e.key === "ArrowUp" || e.key === "ArrowDown")) {
+ e.preventDefault();
+ var step = e.shiftKey ? 10 : 1;
+ var nx = e.key === "ArrowLeft" ? -step : e.key === "ArrowRight" ? step : 0;
+ var ny = e.key === "ArrowUp" ? -step : e.key === "ArrowDown" ? step : 0;
+ nudgeSelection(nx, ny);
+ return;
+ }
+
if (slideNames.length === 0) return;
if (e.key === "ArrowLeft") {
@@ -1017,7 +1405,10 @@
modalConfirm.style.display = "none";
modalCancel.style.display = "none";
- fetch("/api/save-all", { method: "POST" })
+ // Wait for any just-fired direct edits (drag/nudge) to land first, or
+ // save-all could race ahead and leave their edits as a fresh pending set.
+ drainDirectEdits()
+ .then(function () { return fetch("/api/save-all", { method: "POST" }); })
.then(function (res) { return res.json(); })
.then(function (data) {
if (data.error) {
@@ -1039,6 +1430,8 @@
})
.catch(function (err) {
modalMessage.textContent = t("err_save") + err;
+ modalConfirm.style.display = "";
+ modalCancel.style.display = "";
});
});
@@ -1198,7 +1591,7 @@
// Editable property panel for a single selected element: computed geometry,
// text content where safe, and the element's own SVG attributes.
function renderEditableProps(el) {
- var tag = el.tagName.toLowerCase();
+ var tag = localName(el);
var isGroup = tag === "g";
var html = '<div class="prop-caption">' +
escapeHtml(isGroup ? t("label_group_edit") : t("label_direct_edit")) + '</div>';
@@ -1262,7 +1655,7 @@
function nearestParentGroup(el) {
var node = el ? el.parentElement : null;
while (node && node !== svgContent) {
- if (node.tagName && node.tagName.toLowerCase() === "g" && node.id) return node;
+ if (node.tagName && localName(node) === "g" && node.id) return node;
node = node.parentElement;
}
return null;
@@ -1424,20 +1817,181 @@
return String(next) + parsed.unit;
}
+ function parentDelta(dx, dy, el) {
+ var pm = parentCTM(el);
+ var det = pm.a * pm.d - pm.b * pm.c;
+ if (Math.abs(det) < 1e-9) return null;
+ return {
+ x: (pm.d * dx - pm.c * dy) / det,
+ y: (-pm.b * dx + pm.a * dy) / det
+ };
+ }
+
+ function firstNumber(value) {
+ var m = String(value || "").match(/-?\d+(?:\.\d+)?/);
+ return m ? parseFloat(m[0]) : null;
+ }
+
+ function formatCoord(value) {
+ return String(Math.round(value * 1000) / 1000);
+ }
+
+ function tspanBaseline(tspan) {
+ var text = tspan && tspan.parentElement;
+ if (!text || localName(text) !== "text") return null;
+ var curX = firstNumber(text.getAttribute("x"));
+ var curY = firstNumber(text.getAttribute("y"));
+ var children = Array.from(text.children);
+ for (var i = 0; i < children.length; i++) {
+ var child = children[i];
+ if (localName(child) !== "tspan") continue;
+ var x = firstNumber(child.getAttribute("x"));
+ var y = firstNumber(child.getAttribute("y"));
+ var dx = firstNumber(child.getAttribute("dx"));
+ var dy = firstNumber(child.getAttribute("dy"));
+ if (x !== null) curX = x;
+ else if (dx !== null) curX = (curX || 0) + dx;
+ if (y !== null) curY = y;
+ else if (dy !== null) curY = (curY || 0) + dy;
+ if (child === tspan) break;
+ }
+ if (curX === null || curY === null) return null;
+ return { x: curX, y: curY };
+ }
+
+ function tspanPromotionPayload(tspan) {
+ if (localName(tspan) !== "tspan") return null;
+ var base = tspanBaseline(tspan);
+ if (!base) return null;
+ var own = ownMatrix(tspan);
+ var close = function (a, b) { return Math.abs(a - b) < 1e-6; };
+ if (!close(own.a, 1) || !close(own.b, 0) ||
+ !close(own.c, 0) || !close(own.d, 1)) return null;
+ return {
+ x: formatCoord(base.x + own.e),
+ y: formatCoord(base.y + own.f)
+ };
+ }
+
+ function copyTextAttrs(src, dst, skip) {
+ Array.from(src.attributes || []).forEach(function (attr) {
+ if (skip[attr.name]) return;
+ dst.setAttribute(attr.name, attr.value);
+ });
+ }
+
+ function adjustedDyValue(oldValue, nextY, prevY) {
+ var parsed = splitNumberUnit(oldValue);
+ if (!parsed) return formatCoord(nextY - prevY);
+ return formatCoord(nextY - prevY) + parsed.unit;
+ }
+
+ function promoteTspanDom(tspan, promoted) {
+ var text = tspan && tspan.parentElement;
+ if (!text || localName(tspan) !== "tspan" || localName(text) !== "text") return null;
+ var next = tspan.nextElementSibling;
+ var nextBase = next && localName(next) === "tspan" ? tspanBaseline(next) : null;
+ var prev = tspan.previousElementSibling;
+ var prevBase = prev && localName(prev) === "tspan" ? tspanBaseline(prev) : null;
+ var parentBaseY = firstNumber(text.getAttribute("y")) || 0;
+
+ var newText = document.createElementNS(tspan.namespaceURI, "text");
+ copyTextAttrs(text, newText, { id: true, x: true, y: true, dx: true, dy: true });
+ copyTextAttrs(tspan, newText, {
+ id: true, x: true, y: true, dx: true, dy: true, transform: true
+ });
+ newText.setAttribute("id", tspan.id);
+ newText.setAttribute("x", promoted.x);
+ newText.setAttribute("y", promoted.y);
+
+ Array.from(tspan.childNodes || []).forEach(function (node) {
+ newText.appendChild(node.cloneNode(true));
+ });
+ if (newText.childNodes.length === 0) {
+ newText.textContent = tspan.textContent || "";
+ }
+
+ var textParent = text.parentNode;
+ var textNext = text.nextSibling;
+ var textClone = text.cloneNode(true);
+ newText.__promotionRollback = function () {
+ if (newText.parentNode) newText.parentNode.removeChild(newText);
+ if (text.parentNode) text.parentNode.removeChild(text);
+ if (textParent) {
+ if (textNext && textNext.parentNode === textParent) {
+ textParent.insertBefore(textClone, textNext);
+ } else {
+ textParent.appendChild(textClone);
+ }
+ }
+ selectedElementIds.delete(newText.id);
+ selectedElementIds.add(tspan.id);
+ markSelection();
+ return textClone.querySelector("#" + CSS.escape(tspan.id)) || textClone;
+ };
+
+ text.parentNode.insertBefore(newText, text.nextSibling);
+ text.removeChild(tspan);
+ if (next && nextBase && !next.hasAttribute("y") && next.hasAttribute("dy")) {
+ next.setAttribute("dy", adjustedDyValue(
+ next.getAttribute("dy"),
+ nextBase.y,
+ prevBase ? prevBase.y : parentBaseY
+ ));
+ }
+ if (!(text.textContent || "").trim() && text.children.length === 0) {
+ text.parentNode.removeChild(text);
+ }
+ selectedElementIds.delete(tspan.id);
+ selectedElementIds.add(newText.id);
+ markSelection();
+ return newText;
+ }
+
+ function payloadForMovedElement(el, attrs) {
+ var promoted = tspanPromotionPayload(el);
+ if (promoted) return { promote_tspan: promoted };
+ return { attrs: attrs };
+ }
+
function canUseRawGeometry(el) {
var own = ownMatrix(el);
- var parent = parentCTM(el);
var close = function (a, b) { return Math.abs(a - b) < 1e-6; };
- return close(own.a, 1) && close(own.b, 0) && close(own.c, 0) &&
- close(own.d, 1) && close(own.e, 0) && close(own.f, 0) &&
- close(parent.a, 1) && close(parent.b, 0) && close(parent.c, 0) &&
- close(parent.d, 1) && close(parent.e, 0) && close(parent.f, 0);
+ if (close(own.b, 0) && close(own.c, 0)) {
+ if (close(own.a, 1) && close(own.d, 1)) return "translate";
+ if (localName(el) === "use") return "use-transform";
+ if (["rect", "image"].indexOf(localName(el)) !== -1) return "box-transform";
+ }
+ return "";
}
function rawMoveAttrs(el, dx, dy) {
- if (!canUseRawGeometry(el)) return null;
- var tag = el.tagName.toLowerCase();
+ if (localName(el) === "g" && el.hasAttribute("data-icon") &&
+ el.hasAttribute("data-use-x") && el.hasAttribute("data-use-y")) {
+ var iconOwn = ownMatrix(el);
+ var close = function (a, b) { return Math.abs(a - b) < 1e-6; };
+ if (close(iconOwn.b, 0) && close(iconOwn.c, 0)) {
+ var iconDelta = parentDelta(dx, dy, el);
+ if (iconDelta) {
+ var iconAttrs = {
+ x: formatCoord(iconOwn.e + iconDelta.x),
+ y: formatCoord(iconOwn.f + iconDelta.y)
+ };
+ if (el.hasAttribute("data-use-has-transform")) {
+ iconAttrs.transform = null;
+ }
+ return iconAttrs;
+ }
+ }
+ }
+
+ var rawMode = canUseRawGeometry(el);
+ if (!rawMode) return null;
+ var d = parentDelta(dx, dy, el);
+ if (!d) return null;
+ var tag = localName(el);
var attrs = {};
+ var own = ownMatrix(el);
var add = function (key, delta) {
if (!el.hasAttribute(key)) return false;
var next = shiftedAttrValue(el, key, delta);
@@ -1445,15 +1999,58 @@
attrs[key] = next;
return true;
};
+ var fmt = function (value) {
+ return String(Math.round(value * 1000) / 1000);
+ };
+ var bakeTranslate = function (xKey, yKey) {
+ if (!el.hasAttribute(xKey) || !el.hasAttribute(yKey)) return false;
+ if (rawMode === "use-transform") {
+ attrs[xKey] = fmt(own.e + d.x);
+ attrs[yKey] = fmt(own.f + d.y);
+ attrs.transform = null;
+ return true;
+ }
+ var nx = shiftedAttrValue(el, xKey, own.e + d.x);
+ var ny = shiftedAttrValue(el, yKey, own.f + d.y);
+ if (nx === null || ny === null) return false;
+ attrs[xKey] = nx;
+ attrs[yKey] = ny;
+ if (el.hasAttribute("transform")) attrs.transform = null;
+ return true;
+ };
+ var bakeBox = function () {
+ if (!el.hasAttribute("x") || !el.hasAttribute("y") ||
+ !el.hasAttribute("width") || !el.hasAttribute("height")) return false;
+ var x = splitNumberUnit(el.getAttribute("x"));
+ var y = splitNumberUnit(el.getAttribute("y"));
+ var w = splitNumberUnit(el.getAttribute("width"));
+ var h = splitNumberUnit(el.getAttribute("height"));
+ if (!x || !y || !w || !h || x.unit !== y.unit ||
+ x.unit !== w.unit || x.unit !== h.unit) return false;
+ attrs.x = fmt(own.a * x.num + own.e + d.x) + x.unit;
+ attrs.y = fmt(own.d * y.num + own.f + d.y) + y.unit;
+ attrs.width = fmt(Math.abs(own.a) * w.num) + w.unit;
+ attrs.height = fmt(Math.abs(own.d) * h.num) + h.unit;
+ attrs.transform = null;
+ return true;
+ };
- if (["rect", "image", "use", "text", "tspan"].indexOf(tag) !== -1) {
- return add("x", dx) && add("y", dy) ? attrs : null;
+ if (rawMode === "box-transform") {
+ return bakeBox() ? attrs : null;
+ }
+ if (["rect", "image", "use", "text"].indexOf(tag) !== -1) {
+ return bakeTranslate("x", "y") ? attrs : null;
}
if (tag === "circle" || tag === "ellipse") {
- return add("cx", dx) && add("cy", dy) ? attrs : null;
+ return bakeTranslate("cx", "cy") ? attrs : null;
}
if (tag === "line") {
- return add("x1", dx) && add("x2", dx) && add("y1", dy) && add("y2", dy) ? attrs : null;
+ if (add("x1", own.e + d.x) && add("x2", own.e + d.x) &&
+ add("y1", own.f + d.y) && add("y2", own.f + d.y)) {
+ if (el.hasAttribute("transform")) attrs.transform = null;
+ return attrs;
+ }
+ return null;
}
return null;
}
@@ -1576,12 +2173,16 @@
}
attrs = { transform: tstr };
}
- stageEditRequest(eid, { attrs: attrs })
+ var payload = mode === "move" ? payloadForMovedElement(el, attrs) : { attrs: attrs };
+ stageEditRequest(eid, payload)
.then(function () {
- Object.keys(attrs).forEach(function (key) {
- el.setAttribute(key, attrs[key]);
- });
- refreshGeoInputs(el, panel);
+ if (payload.promote_tspan) {
+ el = promoteTspanDom(el, payload.promote_tspan) || el;
+ } else {
+ applyElementAttrs(el, attrs);
+ markCommittedAttrs(el, attrs);
+ }
+ refreshGeoInputs(el, panel);
})
.catch(function (err) { showError(t("err_edit") + err.message); });
};
@@ -1606,22 +2207,45 @@
.catch(function (err) { showError(t("err_edit") + err.message); });
}
- function stageEditRequest(eid, payload) {
+ // Tracks every in-flight direct-edit POST so Apply changes can wait for them
+ // to land before /save-all (otherwise a just-sent edit could arrive after the
+ // save and resurrect a pending edit).
+ var inFlightEdits = new Set();
+
+ function drainDirectEdits() {
+ if (inFlightEdits.size === 0) return Promise.resolve();
+ return Promise.allSettled(Array.from(inFlightEdits)).then(function (results) {
+ var failed = results.find(function (r) { return r.status === "rejected"; });
+ if (failed) throw (failed.reason || new Error("direct edit failed"));
+ return drainDirectEdits();
+ });
+ }
+
+ function stageEditRequest(eid, payload, slideName) {
+ // Pin the slide at call time: a queued nudge may fire after the user has
+ // navigated, and must still POST to the slide it was made on, not the
+ // global currentSlide.
+ var slide = slideName || currentSlide;
var body = { element_id: eid };
if (payload.text !== undefined) body.text = payload.text;
if (payload.attrs !== undefined) body.attrs = payload.attrs;
- return fetch("/api/slide/" + encodeURIComponent(currentSlide) + "/edit", {
+ if (payload.promote_tspan !== undefined) body.promote_tspan = payload.promote_tspan;
+ var p = fetch("/api/slide/" + encodeURIComponent(slide) + "/edit", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body)
}).then(jsonOrThrow).then(function (data) {
if (data && data.undo_depth !== undefined) {
- editStackCount[currentSlide] = data.undo_depth;
- updateUndoButton();
+ editStackCount[slide] = data.undo_depth;
+ if (slide === currentSlide) updateUndoButton();
}
maybeShowSavedHint();
return data;
});
+ inFlightEdits.add(p);
+ var done = function () { inFlightEdits.delete(p); };
+ p.then(done, done);
+ return p;
}
function renderMultiSelectSummary(ids) {
@@ -1760,10 +2384,13 @@
var attrs;
try { attrs = attrsForMove(el, dx, dy); } catch (e) { attrs = null; }
if (!attrs) return;
- jobs.push(stageEditRequest(el.id, { attrs: attrs }).then(function () {
- Object.keys(attrs).forEach(function (key) {
- el.setAttribute(key, attrs[key]);
- });
+ var payload = payloadForMovedElement(el, attrs);
+ jobs.push(stageEditRequest(el.id, payload).then(function () {
+ if (payload.promote_tspan) promoteTspanDom(el, payload.promote_tspan);
+ else {
+ applyElementAttrs(el, attrs);
+ markCommittedAttrs(el, attrs);
+ }
}));
});
diff --git a/skills/ppt-master/scripts/svg_editor/static/style.css b/skills/ppt-master/scripts/svg_editor/static/style.css
index 381cac38..c43711b3 100644
--- a/skills/ppt-master/scripts/svg_editor/static/style.css
+++ b/skills/ppt-master/scripts/svg_editor/static/style.css
@@ -248,6 +248,14 @@ html, body {
.svg-selected {
outline: 2px solid #4a9eff !important;
outline-offset: 2px;
+ cursor: move;
+}
+
+/* While a drag is in progress, keep the move cursor everywhere so it does not
+ flicker to the hovered element's cursor as the pointer crosses other shapes. */
+body.svg-dragging,
+body.svg-dragging * {
+ cursor: move !important;
}
.svg-annotated {
@@ -851,6 +859,56 @@ input.prop-edit-multi-geo {
z-index: 11;
}
+/* --- Overlap picker (right-click list of stacked elements) --- */
+#overlap-picker {
+ position: fixed;
+ z-index: 1100;
+ min-width: 180px;
+ max-width: 340px;
+ max-height: 60vh;
+ overflow-y: auto;
+ background: #1f2430;
+ border: 1px solid #3a4252;
+ border-radius: 6px;
+ box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
+ padding: 4px;
+ font-size: 12px;
+}
+
+.overlap-caption {
+ padding: 4px 8px 6px;
+ color: #8b94a7;
+ font-size: 11px;
+}
+
+.overlap-item {
+ display: flex;
+ align-items: baseline;
+ gap: 6px;
+ padding: 5px 8px;
+ border-radius: 4px;
+ cursor: pointer;
+ white-space: nowrap;
+}
+
+.overlap-item:hover {
+ background: #2d3545;
+}
+
+.overlap-tag { color: #4a9eff; }
+.overlap-id { color: #e6e9ef; }
+.overlap-txt {
+ color: #8b94a7;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
+
+/* Element highlighted while hovering its row in the overlap picker. */
+.overlap-hover {
+ outline: 2px solid #f59e0b !important;
+ outline-offset: 2px;
+}
+
/* ======================== UTILITY ======================== */
.visually-hidden {
position: absolute;
diff --git a/skills/ppt-master/scripts/svg_finalize/embed_icons.py b/skills/ppt-master/scripts/svg_finalize/embed_icons.py
index f4360727..b915c11f 100644
--- a/skills/ppt-master/scripts/svg_finalize/embed_icons.py
+++ b/skills/ppt-master/scripts/svg_finalize/embed_icons.py
@@ -182,6 +182,13 @@ def parse_use_element(use_match: str) -> dict[str, str | float]:
if fill_match:
attrs['fill'] = fill_match.group(1)
+ # Live preview direct edits may write an absolute transform matrix back to
+ # the placeholder. Preserve it so the expanded icon matches the edited
+ # browser geometry instead of falling back to the original x/y placement.
+ transform_match = re.search(r'transform="([^"]+)"', use_match)
+ if transform_match:
+ attrs['transform'] = transform_match.group(1)
+
# Extract optional stroke-width override (stroke-style icons only).
# Tabler-outline ships at stroke-width=2; passing 1.5 reads thin, 3 reads bold.
stroke_width_match = re.search(r'stroke-width="([^"]+)"', use_match)
@@ -214,7 +221,11 @@ def generate_icon_group(attrs: dict[str, str | float], elements: list[str], styl
scale_x = width / base_size
scale_y = height / base_size
- if abs(scale_x - 1) < 1e-6 and abs(scale_y - 1) < 1e-6:
+ if attrs.get('transform'):
+ # This transform is authoritative: the editor computes it from the
+ # expanded <g>, so composing it with x/y would apply placement twice.
+ transform = str(attrs['transform'])
+ elif abs(scale_x - 1) < 1e-6 and abs(scale_y - 1) < 1e-6:
transform = f'translate({x}, {y})'
elif abs(scale_x - scale_y) < 1e-6:
transform = f'translate({x}, {y}) scale({scale_x})'
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml_elements.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml_elements.py
index 22ade270..9304543e 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml_elements.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml_elements.py
@@ -17,7 +17,7 @@ from .drawingml_utils import (
rect_to_dml_xfrm,
parse_hex_color, resolve_url_id, get_effective_filter_id,
parse_font_family, is_cjk_char, estimate_text_width,
- _xml_escape,
+ parse_transform_matrix, _xml_escape,
)
from .drawingml_styles import (
build_solid_fill, build_gradient_fill,
@@ -1143,6 +1143,28 @@ def convert_text(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
box_w = text_width + padding * 2
box_h = text_height + padding
+ text_transform = elem.get('transform', '')
+ if text_transform and 'rotate' not in text_transform and not ctx.use_transform_matrix:
+ try:
+ a, b, c, d, e, f = parse_transform_matrix(text_transform)
+ except Exception:
+ a, b, c, d, e, f = 1.0, 0.0, 0.0, 1.0, 0.0, 0.0
+ # A pure-translate transform on a text element (hand-authored, or written
+ # by a live-preview move) was otherwise ignored here, drifting the text.
+ # Absorb the translation into the frame position; a scaling transform
+ # would also need to scale font size / line metrics, so leave
+ # non-translate transforms alone.
+ if (
+ abs(a - 1.0) < 1e-9 and abs(b) < 1e-9
+ and abs(c) < 1e-9 and abs(d - 1.0) < 1e-9
+ ):
+ sx = ctx.scale_x or 1.0
+ sy = ctx.scale_y or 1.0
+ raw_box_x = (box_x - ctx.translate_x) / sx
+ raw_box_y = (box_y - ctx.translate_y) / sy
+ box_x = ctx.translate_x + sx * (a * raw_box_x + e)
+ box_y = ctx.translate_y + sy * (d * raw_box_y + f)
+
# Letter spacing
spc_attr = ''
letter_spacing = _get_attr(elem, 'letter-spacing', ctx)
@@ -1159,7 +1181,6 @@ def convert_text(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
# box so its center lands where SVG would place the rotated visual center —
# otherwise rotated y-axis labels etc. drift to the wrong location.
text_rot = 0
- text_transform = elem.get('transform', '')
if text_transform:
rot_match = re.search(
r'rotate\(\s*([-\d.]+)(?:[\s,]+([-\d.]+)[\s,]+([-\d.]+))?',
diff --git a/skills/ppt-master/workflows/live-preview.md b/skills/ppt-master/workflows/live-preview.md
index 29695f02..a61205ed 100644
--- a/skills/ppt-master/workflows/live-preview.md
+++ b/skills/ppt-master/workflows/live-preview.md
@@ -75,6 +75,9 @@ 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**.
+- **Drag to move**: press and drag an already-selected element on the canvas to reposition it (selection stays a separate click, so the background is never dragged by accident); the whole selection moves together under multi-select. The pointer delta is mapped through each element's own CTM, so moves track the cursor regardless of viewport scale or group transforms. Each release stages one direct edit per moved element (the same `x`/`y`-or-`transform` write the geometry inputs produce), previewed live and written only on **Apply changes**; dragging on empty canvas is still rubber-band selection. A failed stage rolls the canvas back to the pre-drag position.
+- **Arrow-key nudge**: with one or more elements selected, `↑ ↓ ← →` moves the selection 1px and `Shift + arrow` moves 10px (suppressed while typing in the annotation box). Arrow keys navigate slides only when nothing is selected. Same staging/coalescing path as drag, so a burst of nudges collapses to one undo step.
+- **Overlap picker**: right-click anywhere on the canvas to list every selectable element under the pointer (top→bottom), so stacked shapes can be reached without blind cycling. Left-click is unchanged (selects the topmost). Hovering a row highlights that element; clicking it selects it; `Esc` or an outside click closes the list. With exactly one element under the pointer, right-click selects it directly.
- **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.