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(animations): support multi-effect object timelines

hugohe382452f72e3f1
diff --git a/skills/ppt-master/scripts/narration_sync.py b/skills/ppt-master/scripts/narration_sync.py
index 175e214d..9313b556 100644
--- a/skills/ppt-master/scripts/narration_sync.py
+++ b/skills/ppt-master/scripts/narration_sync.py
@@ -55,9 +55,11 @@ from pptx_animations import ( # noqa: E402
ANIMATION_TIMING_OPTION_FIELDS,
animation_seconds_to_milliseconds,
normalize_animation_effect,
+ normalize_animation_trigger,
)
from pptx_transitions import read_slide_transition_xml # noqa: E402
from svg_to_pptx.animation_config import ( # noqa: E402
+ animation_group_effect_entries,
scan_project_targets,
scan_svg_targets,
validate_animation_config_errors,
@@ -112,6 +114,7 @@ class AnimationGroupState:
"""One effective canonical animation row before narration timing."""
group_id: str
+ effect_index: int | None
order: int
source_index: int
duration_ms: int
@@ -531,12 +534,12 @@ def _effective_slide_animation(
"canonical animation stagger",
allow_zero=True,
)
- trigger = slide_animation.get(
- "trigger",
- default_animation.get("trigger", "after-previous"),
+ trigger = normalize_animation_trigger(
+ slide_animation.get(
+ "trigger",
+ default_animation.get("trigger", "after-previous"),
+ )
)
- if not isinstance(trigger, str):
- raise ValueError(f"Canonical animation trigger must be a string: {trigger!r}")
timing_options = {
field: (
slide_animation[field]
@@ -582,16 +585,81 @@ def _animation_playback_duration_ms(
return max(1, round(one_play * float(repeat_count)))
+def _active_group_effect_entries(
+ slide_name: str,
+ group_id: str,
+ group_cfg: dict[str, Any],
+ slide_effect: str | None,
+) -> tuple[tuple[int | None, str, dict[str, Any]], ...]:
+ """Return active legacy or multi-effect rows with stable write locations."""
+ group_path = (
+ f'slides[{json.dumps(slide_name, ensure_ascii=False)}]'
+ f'.groups[{json.dumps(group_id, ensure_ascii=False)}]'
+ )
+ effect_entries = animation_group_effect_entries(
+ group_cfg,
+ path=group_path,
+ )
+ is_multi_effect = 'effects' in group_cfg
+ active: list[tuple[int | None, str, dict[str, Any]]] = []
+ for index, (effect_path, effect_cfg) in enumerate(effect_entries):
+ effect = normalize_animation_effect(
+ effect_cfg.get("effect", slide_effect)
+ )
+ if effect is None:
+ continue
+ active.append((
+ index if is_multi_effect else None,
+ effect_path,
+ effect_cfg,
+ ))
+ return tuple(active)
+
+
def _group_is_animated(
+ slide_name: str,
+ group_id: str,
group_cfg: dict[str, Any],
slide_effect: str | None,
) -> bool:
- if "effect" not in group_cfg:
- return slide_effect is not None
- return normalize_animation_effect(group_cfg["effect"]) is not None
+ return bool(
+ _active_group_effect_entries(
+ slide_name,
+ group_id,
+ group_cfg,
+ slide_effect,
+ )
+ )
+
+
+def _active_group_order_requires_svg(
+ slide_name: str,
+ groups_cfg: dict[str, Any],
+ group_ids: list[str],
+ slide_effect: str | None,
+) -> bool:
+ """Return whether SVG group order is needed to break sequence ambiguity."""
+ if len(group_ids) <= 1:
+ return False
+ order_owners: dict[int, str] = {}
+ for group_id in group_ids:
+ for _effect_index, _effect_path, effect_cfg in _active_group_effect_entries(
+ slide_name,
+ group_id,
+ groups_cfg[group_id],
+ slide_effect,
+ ):
+ order = effect_cfg.get("order")
+ if order is None:
+ return True
+ previous_group = order_owners.setdefault(order, group_id)
+ if previous_group != group_id:
+ return True
+ return False
def _needs_svg_group_resolution(
+ slide_name: str,
settings: SlideAnimationSettings,
groups_cfg: dict[str, Any],
plan_entries: list[TimingPlanEntry] | None,
@@ -601,14 +669,21 @@ def _needs_svg_group_resolution(
group_id
for group_id, group_cfg in groups_cfg.items()
if isinstance(group_cfg, dict)
- and _group_is_animated(group_cfg, settings.effect)
+ and _group_is_animated(
+ slide_name,
+ group_id,
+ group_cfg,
+ settings.effect,
+ )
]
if plan_entries is None:
if settings.effect is not None:
return True
- return (
- len(active_explicit) > 1
- and any("order" not in groups_cfg[group_id] for group_id in active_explicit)
+ return _active_group_order_requires_svg(
+ slide_name,
+ groups_cfg,
+ active_explicit,
+ settings.effect,
)
candidate_ids = list(
@@ -624,11 +699,19 @@ def _needs_svg_group_resolution(
for group_id in candidate_ids
if group_id in groups_cfg
and isinstance(groups_cfg[group_id], dict)
- and _group_is_animated(groups_cfg[group_id], settings.effect)
+ and _group_is_animated(
+ slide_name,
+ group_id,
+ groups_cfg[group_id],
+ settings.effect,
+ )
]
- if len(active_candidates) <= 1:
- return False
- return any("order" not in groups_cfg[group_id] for group_id in active_candidates)
+ return _active_group_order_requires_svg(
+ slide_name,
+ groups_cfg,
+ active_candidates,
+ settings.effect,
+ )
def _resolve_animation_groups(
@@ -652,19 +735,12 @@ def _resolve_animation_groups(
"must be an object"
)
groups_cfg[group_id] = group_cfg
- interactive_ids = sorted(
- group_id
- for group_id, group_cfg in groups_cfg.items()
- if group_cfg.get("trigger_shape") is not None
- and _group_is_animated(group_cfg, settings.effect)
+ use_svg = _needs_svg_group_resolution(
+ slide_name,
+ settings,
+ groups_cfg,
+ plan_entries,
)
- if interactive_ids:
- raise ValueError(
- f'Recorded narration cannot synchronize trigger-shape animations '
- f'on slide "{slide_name}": {", ".join(interactive_ids)}'
- )
-
- use_svg = _needs_svg_group_resolution(settings, groups_cfg, plan_entries)
candidate_ids: list[str]
if use_svg:
svg_path = project_path / "svg_output" / f"{slide_name}.svg"
@@ -706,7 +782,12 @@ def _resolve_animation_groups(
if targets_by_id[group_id].structurally_static
and (
group_id not in groups_cfg
- or _group_is_animated(groups_cfg[group_id], settings.effect)
+ or _group_is_animated(
+ slide_name,
+ group_id,
+ groups_cfg[group_id],
+ settings.effect,
+ )
)
)
if structural_ids:
@@ -722,7 +803,12 @@ def _resolve_animation_groups(
group_cfg = groups_cfg.get(target.group_id, {})
explicitly_animated = (
target.group_id in groups_cfg
- and _group_is_animated(group_cfg, settings.effect)
+ and _group_is_animated(
+ slide_name,
+ target.group_id,
+ group_cfg,
+ settings.effect,
+ )
)
if target.chrome and not explicitly_animated:
continue
@@ -739,53 +825,105 @@ def _resolve_animation_groups(
else:
candidate_ids = list(groups_cfg)
- preliminaries: list[tuple[int, int, str, dict[str, Any]]] = []
+ preliminaries: list[
+ tuple[
+ int,
+ int,
+ int,
+ str,
+ int | None,
+ str,
+ dict[str, Any],
+ str,
+ ]
+ ] = []
for source_index, group_id in enumerate(candidate_ids):
group_cfg = groups_cfg.get(group_id, {})
- if not _group_is_animated(group_cfg, settings.effect):
- continue
- order = group_cfg.get("order", source_index + 1)
- if isinstance(order, bool) or not isinstance(order, int) or order <= 0:
- raise ValueError(
- f'Canonical animation order for "{slide_name}/{group_id}" '
- f"must be a positive integer: {order!r}"
+ effect_entries = _active_group_effect_entries(
+ slide_name,
+ group_id,
+ group_cfg,
+ settings.effect,
+ )
+ for effect_position, (
+ effect_index,
+ effect_path,
+ effect_cfg,
+ ) in enumerate(effect_entries):
+ order = effect_cfg.get("order", source_index + 1)
+ if isinstance(order, bool) or not isinstance(order, int) or order <= 0:
+ raise ValueError(
+ f'Canonical animation order for "{effect_path}" '
+ f"must be a positive integer: {order!r}"
+ )
+ if effect_cfg.get("trigger_shape") is not None:
+ raise ValueError(
+ f'Recorded narration cannot synchronize trigger-shape '
+ f'animation "{effect_path}" on slide "{slide_name}"'
+ )
+ effect_trigger = normalize_animation_trigger(
+ effect_cfg.get("trigger", settings.trigger)
)
- preliminaries.append((order, source_index, group_id, group_cfg))
- preliminaries.sort(key=lambda item: (item[0], item[1]))
+ if effect_trigger == "on-click":
+ raise ValueError(
+ f'Recorded narration cannot synchronize on-click animation '
+ f'"{effect_path}" on slide "{slide_name}"'
+ )
+ preliminaries.append((
+ order,
+ source_index,
+ effect_position,
+ group_id,
+ effect_index,
+ effect_path,
+ effect_cfg,
+ effect_trigger,
+ ))
+ preliminaries.sort(key=lambda item: (item[0], item[1], item[2]))
states: list[AnimationGroupState] = []
- for sequence_index, (order, source_index, group_id, group_cfg) in enumerate(
- preliminaries
- ):
+ for sequence_index, (
+ order,
+ source_index,
+ _effect_position,
+ group_id,
+ effect_index,
+ effect_path,
+ effect_cfg,
+ effect_trigger,
+ ) in enumerate(preliminaries):
duration_ms = animation_seconds_to_milliseconds(
- group_cfg.get("duration", settings.duration_ms / 1000),
- f'canonical animation duration for "{slide_name}/{group_id}"',
+ effect_cfg.get("duration", settings.duration_ms / 1000),
+ f'canonical animation duration for "{effect_path}"',
allow_zero=False,
)
timing_options = dict(settings.timing_options)
timing_options.update(
{
- field: group_cfg[field]
+ field: effect_cfg[field]
for field in ANIMATION_TIMING_OPTION_FIELDS
- if field in group_cfg
+ if field in effect_cfg
}
)
playback_duration_ms = _animation_playback_duration_ms(
duration_ms,
timing_options,
- label=f'canonical animation for "{slide_name}/{group_id}"',
+ label=f'canonical animation for "{effect_path}"',
+ )
+ default_delay = (
+ settings.stagger_ms / 1000
+ if effect_trigger == "after-previous" and sequence_index > 0
+ else 0
)
original_delay_ms = animation_seconds_to_milliseconds(
- group_cfg.get(
- "delay",
- 0 if sequence_index == 0 else settings.stagger_ms / 1000,
- ),
- f'canonical animation delay for "{slide_name}/{group_id}"',
+ effect_cfg.get("delay", default_delay),
+ f'canonical animation delay for "{effect_path}"',
allow_zero=True,
)
states.append(
AnimationGroupState(
group_id=group_id,
+ effect_index=effect_index,
order=order,
source_index=source_index,
duration_ms=playback_duration_ms,
@@ -922,7 +1060,11 @@ def rebuild_animations(
if used_svg:
svg_fallback_slide_count += 1
if timing_plan is None and states:
- positional_slides.append((slide_name, len(states), len(cues)))
+ positional_slides.append((
+ slide_name,
+ len({state.group_id for state in states}),
+ len(cues),
+ ))
state_ids = {state.group_id for state in states}
cue_by_group: dict[str, int | None] = {}
@@ -941,9 +1083,12 @@ def rebuild_animations(
)
cue_by_group[entry.group_id] = entry.cue_number
else:
+ ordered_group_ids = list(
+ dict.fromkeys(state.group_id for state in states)
+ )
cue_by_group = {
- state.group_id: index + 1 if index < len(cues) else None
- for index, state in enumerate(states)
+ group_id: index + 1 if index < len(cues) else None
+ for index, group_id in enumerate(ordered_group_ids)
}
animation_value = derived_slide.setdefault("animation", {})
@@ -960,10 +1105,18 @@ def rebuild_animations(
previous_end_ms = 0
referenced_cues: set[int] = set()
+ seen_groups: set[str] = set()
for state in states:
- cue_number = cue_by_group.get(state.group_id)
+ first_group_effect = state.group_id not in seen_groups
+ seen_groups.add(state.group_id)
+ cue_number = (
+ cue_by_group.get(state.group_id)
+ if first_group_effect
+ else None
+ )
if cue_number is None:
- fallback_count += 1
+ if first_group_effect:
+ fallback_count += 1
delay_ms = state.original_delay_ms
actual_start_ms = previous_end_ms + delay_ms
else:
@@ -987,8 +1140,21 @@ def rebuild_animations(
f'Derived animation group "{slide_name}/{state.group_id}" '
"must be an object"
)
- group_value["order"] = state.order
- group_value["delay"] = _seconds_from_ms(delay_ms)
+ if state.effect_index is None:
+ effect_value = group_value
+ else:
+ group_path = (
+ f'slides[{json.dumps(slide_name, ensure_ascii=False)}]'
+ f'.groups[{json.dumps(state.group_id, ensure_ascii=False)}]'
+ )
+ derived_effect_entries = animation_group_effect_entries(
+ group_value,
+ path=group_path,
+ )
+ effect_value = derived_effect_entries[state.effect_index][1]
+ effect_value["order"] = state.order
+ effect_value["delay"] = _seconds_from_ms(delay_ms)
+ effect_value["trigger"] = "after-previous"
previous_end_ms = actual_start_ms + state.duration_ms
ignored_cue_count += len(cues) - len(referenced_cues)
diff --git a/skills/ppt-master/scripts/pptx_animations.py b/skills/ppt-master/scripts/pptx_animations.py
index 110325fc..fae4d227 100644
--- a/skills/ppt-master/scripts/pptx_animations.py
+++ b/skills/ppt-master/scripts/pptx_animations.py
@@ -402,6 +402,7 @@ class AnimationTarget:
effect: str
duration_ms: int
effect_options: Mapping[str, object]
+ trigger: str = 'after-previous'
trigger_shape_id: int | None = None
repeat_count: float | None = None
repeat_duration_ms: int | None = None
@@ -849,6 +850,7 @@ def _normalize_sound(value: object) -> tuple[str | None, str | None]:
def _normalize_target_mapping(
target: Mapping[str, object],
default_duration_ms: int,
+ default_trigger: str,
) -> AnimationTarget:
allowed = {
'shape_id',
@@ -856,6 +858,7 @@ def _normalize_target_mapping(
'effect',
'duration',
'effect_options',
+ 'trigger',
'trigger_shape_id',
*ANIMATION_TIMING_OPTION_FIELDS,
'after_effect',
@@ -896,6 +899,18 @@ def _normalize_target_mapping(
raise ValueError(
'animation trigger_shape_id must target a different shape'
)
+ target_trigger = (
+ normalize_animation_trigger(target['trigger'])
+ if 'trigger' in target
+ else default_trigger
+ )
+ if trigger_shape_id is not None:
+ if 'trigger' in target and target_trigger != 'on-click':
+ raise ValueError(
+ 'animation target with trigger_shape_id must use '
+ 'trigger "on-click"'
+ )
+ target_trigger = 'on-click'
repeat_count = (
_normalize_repeat_count(target['repeat_count'])
if 'repeat_count' in target
@@ -968,6 +983,7 @@ def _normalize_target_mapping(
effect=effect,
duration_ms=duration_ms,
effect_options=effect_options,
+ trigger=target_trigger,
trigger_shape_id=trigger_shape_id,
repeat_count=repeat_count,
repeat_duration_ms=repeat_duration_ms,
@@ -987,9 +1003,14 @@ def _normalize_target_mapping(
def _normalize_target(
target: Sequence[object] | Mapping[str, object],
default_duration_ms: int,
+ default_trigger: str = 'after-previous',
) -> AnimationTarget:
if isinstance(target, Mapping):
- return _normalize_target_mapping(target, default_duration_ms)
+ return _normalize_target_mapping(
+ target,
+ default_duration_ms,
+ default_trigger,
+ )
if isinstance(target, (str, bytes)) or not isinstance(target, Sequence):
raise ValueError(f'animation target must be a 3- or 4-item sequence: {target!r}')
if len(target) not in (3, 4):
@@ -1014,6 +1035,7 @@ def _normalize_target(
effect=effect,
duration_ms=duration_ms,
effect_options=effect_options,
+ trigger=default_trigger,
)
# Pool used by 'mixed' / 'random' modes. Every entry is a canonical
@@ -1694,17 +1716,7 @@ def _instantiate_animation_row(
direct_conditions[0].attrib.clear()
direct_conditions[0].set(
'delay',
- str(
- target.delay_ms
- if (
- node_type == 'afterEffect'
- or (
- node_type == 'clickEffect'
- and target.trigger_shape_id is not None
- )
- )
- else 0
- ),
+ str(target.delay_ms),
)
if spec['durationScalable']:
@@ -1746,6 +1758,90 @@ def _build_animation_row_xml(
)
+def _main_target_offsets(targets: Sequence[AnimationTarget]) -> list[int]:
+ """Return each regular row's start offset within its click group."""
+ offsets: list[int] = []
+ previous_start_ms = 0
+ previous_duration_ms = 0
+ has_previous = False
+ for target in targets:
+ if target.trigger == 'on-click':
+ start_ms = target.delay_ms
+ elif target.trigger == 'with-previous':
+ start_ms = (
+ previous_start_ms if has_previous else 0
+ ) + target.delay_ms
+ else:
+ start_ms = (
+ previous_start_ms + previous_duration_ms
+ if has_previous
+ else 0
+ ) + target.delay_ms
+ if start_ms > MAX_OOXML_MILLISECONDS:
+ raise ValueError(
+ 'animation sequence offset exceeds the OOXML millisecond '
+ f'limit at target {len(offsets) + 1}: {start_ms}'
+ )
+ offsets.append(start_ms)
+ previous_start_ms = start_ms
+ previous_duration_ms = target.playback_duration_ms
+ has_previous = True
+ return offsets
+
+
+def _build_mixed_main_steps(
+ targets: Sequence[AnimationTarget],
+ next_id: int,
+) -> tuple[str, int]:
+ """Build one mainSeq containing mixed per-row PowerPoint Start modes."""
+ offsets = _main_target_offsets(targets)
+ groups: list[list[tuple[AnimationTarget, int]]] = []
+ for target, offset_ms in zip(targets, offsets):
+ if not groups or target.trigger == 'on-click':
+ groups.append([])
+ groups[-1].append((target, offset_ms))
+
+ rendered_groups: list[str] = []
+ for group in groups:
+ group_id = next_id
+ next_id += 1
+ first_target = group[0][0]
+ if first_target.trigger == 'on-click':
+ group_conditions = '<p:cond delay="indefinite"/>'
+ else:
+ group_conditions = (
+ '<p:cond delay="indefinite"/>'
+ '<p:cond evt="onBegin" delay="0"><p:tn val="2"/></p:cond>'
+ )
+ rendered_rows: list[str] = []
+ for target, offset_ms in group:
+ wrapper_id = next_id
+ row_id = next_id + 1
+ row_xml, next_id = _build_animation_row_xml(
+ target,
+ target.trigger,
+ row_id,
+ next_id + 2,
+ )
+ wrapper_offset_ms = offset_ms - target.delay_ms
+ rendered_rows.append(f'''<p:par>
+ <p:cTn id="{wrapper_id}" fill="hold">
+ <p:stCondLst><p:cond delay="{wrapper_offset_ms}"/></p:stCondLst>
+ <p:childTnLst><p:par>{row_xml}</p:par></p:childTnLst>
+ </p:cTn>
+ </p:par>''')
+ rows_xml = '\n '.join(rendered_rows)
+ rendered_groups.append(f'''<p:par>
+ <p:cTn id="{group_id}" fill="hold">
+ <p:stCondLst>{group_conditions}</p:stCondLst>
+ <p:childTnLst>
+ {rows_xml}
+ </p:childTnLst>
+ </p:cTn>
+ </p:par>''')
+ return '\n '.join(rendered_groups), next_id
+
+
def create_sequence_timing_xml(
targets: list,
duration: float = 0.3,
@@ -1757,9 +1853,10 @@ def create_sequence_timing_xml(
targets: list of (shape_id, delay_ms, animation_name) or
(shape_id, delay_ms, animation_name, duration_seconds) tuples, in
the order they should play. ``delay_ms`` is the gap before
- this element starts in ``after-previous`` mode. For a mapping
- target with ``trigger_shape_id``, it is the delay after that
- shape is clicked; otherwise the other Start modes ignore it.
+ this element starts relative to its Start mode. Mapping targets
+ may set an independent ``trigger``; otherwise they inherit the
+ function-level ``trigger``. A target with ``trigger_shape_id``
+ must use ``on-click`` and runs in an interactive sequence.
duration: per-element animation duration in seconds. Instantaneous
native presets retain their PowerPoint-authored duration.
trigger: PowerPoint-standard Start mode for each element.
@@ -1785,12 +1882,9 @@ def create_sequence_timing_xml(
if not targets:
return ''
normalized_targets = [
- _normalize_target(target, default_dur_ms)
+ _normalize_target(target, default_dur_ms, trigger)
for target in targets
]
- shape_ids = [target.shape_id for target in normalized_targets]
- if len(shape_ids) != len(set(shape_ids)):
- raise ValueError('animation targets must not contain duplicate shape ids')
next_id = 3
main_targets = [
target
@@ -1803,7 +1897,23 @@ def create_sequence_timing_xml(
if target.trigger_shape_id is not None
]
- if trigger == 'on-click':
+ main_triggers = {target.trigger for target in main_targets}
+ main_trigger = (
+ next(iter(main_triggers))
+ if len(main_triggers) == 1
+ else None
+ )
+ needs_per_target_layout = (
+ main_trigger is None
+ or (
+ main_trigger == 'with-previous'
+ and any(target.delay_ms for target in main_targets)
+ )
+ )
+
+ if needs_per_target_layout and main_targets:
+ all_steps, next_id = _build_mixed_main_steps(main_targets, next_id)
+ elif main_trigger == 'on-click':
# Each element is an independent click-driven par directly under
# mainSeq. Three-level nesting per element: outer cTn holds for
# the click via delay="indefinite", innermost cTn owns the
@@ -1815,7 +1925,7 @@ def create_sequence_timing_xml(
leaf_id = next_id + 2
row_xml, next_id = _build_animation_row_xml(
target,
- trigger,
+ main_trigger,
leaf_id,
next_id + 3,
)
@@ -1848,16 +1958,16 @@ def create_sequence_timing_xml(
next_id += 1
inner_steps = []
with_wrapper_id = None
- if trigger == 'with-previous':
+ if main_trigger == 'with-previous':
with_wrapper_id = next_id
next_id += 1
elapsed_ms = 0
for target_index, target in enumerate(main_targets, 1):
- if trigger == 'with-previous':
+ if main_trigger == 'with-previous':
leaf_id = next_id
row_xml, next_id = _build_animation_row_xml(
target,
- trigger,
+ main_trigger,
leaf_id,
next_id + 1,
)
@@ -1874,7 +1984,7 @@ def create_sequence_timing_xml(
leaf_id = next_id + 1
row_xml, next_id = _build_animation_row_xml(
target,
- trigger,
+ main_trigger,
leaf_id,
next_id + 2,
)
@@ -1891,7 +2001,7 @@ def create_sequence_timing_xml(
elapsed_ms += target.delay_ms + target.playback_duration_ms
inner_xml = '\n '.join(inner_steps)
- if trigger == 'with-previous':
+ if main_trigger == 'with-previous':
# Match PowerPoint's native "Start: With Previous" export:
# one delay=0 wrapper begins on slide entry, and all withEffect
# rows live under that wrapper so they truly start in parallel.
@@ -1903,7 +2013,7 @@ def create_sequence_timing_xml(
</p:childTnLst>
</p:cTn>
</p:par>'''
- if trigger in ('with-previous', 'after-previous'):
+ if main_trigger in ('with-previous', 'after-previous'):
# Match PowerPoint's native slide-entry export: the wrapper waits
# for mainSeq to begin, then child nodes resolve their Start modes.
outer_start_conditions = (
@@ -2621,34 +2731,14 @@ def _row_offset_ms(
errors.append(
'object-animation row must have one numeric leaf start condition'
)
- if (
- trigger != 'after-previous'
- and trigger_shape_id is None
- and leaf_delay not in {None, 0}
- ):
- errors.append(
- f'{trigger} object-animation row must have leaf delay="0"'
- )
-
current = parent_map.get(row)
saw_indefinite = False
- saw_main_begin = False
numeric_offset: int | None = None
while current is not None:
if current.tag == _qn(PML_NS, 'cTn'):
conditions = _direct_conditions(current)
if any(condition.get('delay') == 'indefinite' for condition in conditions):
saw_indefinite = True
- if any(
- condition.get('evt') == 'onBegin'
- and condition.get('delay') == '0'
- and any(
- target.get('val') == '2'
- for target in condition.iter(_qn(PML_NS, 'tn'))
- )
- for condition in conditions
- ):
- saw_main_begin = True
if trigger in {'with-previous', 'after-previous'}:
numeric = [
condition.get('delay')
@@ -2673,15 +2763,13 @@ def _row_offset_ms(
errors.append(
'on-click object-animation row is missing an indefinite click wrapper'
)
- if trigger in {'with-previous', 'after-previous'} and not (
- saw_indefinite and saw_main_begin
- ):
- errors.append(f'{trigger} sequence is missing the slide-entry onBegin anchor')
- if trigger == 'after-previous' and numeric_offset is None:
+ if trigger in {'with-previous', 'after-previous'} and not saw_indefinite:
+ errors.append(f'{trigger} sequence is missing its sequence anchor')
+ if trigger in {'with-previous', 'after-previous'} and numeric_offset is None:
errors.append(
- 'after-previous object-animation row is missing its numeric offset wrapper'
+ f'{trigger} object-animation row is missing its numeric offset wrapper'
)
- if trigger == 'after-previous':
+ if trigger in {'with-previous', 'after-previous'}:
absolute_offset = (numeric_offset or 0) + (leaf_delay or 0)
if absolute_offset > MAX_OOXML_MILLISECONDS:
errors.append(
@@ -2691,12 +2779,97 @@ def _row_offset_ms(
return absolute_offset
if trigger_shape_id is not None:
return leaf_delay or 0
- return 0
+ return leaf_delay or 0
+
+
+def _row_matches_powerpoint_behavior(
+ row: ET.Element,
+ *,
+ shape_id: int,
+ effect: str,
+ effect_options: Mapping[str, object],
+ trigger: str,
+ duration_ms: int,
+ repeat_count: float | None,
+ repeat_duration_ms: int | None,
+ auto_reverse: bool,
+ rewind: bool,
+ accelerate: float,
+ decelerate: float,
+ bounce_end: float,
+ restart: str,
+ after_effect: str,
+ after_effect_color: str | None,
+ sound_relationship_id: str | None,
+ sound_name: str | None,
+) -> bool:
+ """Match one read-back row to its reconstructed native behavior tree."""
+ spec = NATIVE_ANIMATIONS[effect]
+ target = AnimationTarget(
+ shape_id=shape_id,
+ delay_ms=0,
+ effect=effect,
+ duration_ms=duration_ms,
+ effect_options=effect_options,
+ trigger=trigger,
+ repeat_count=repeat_count,
+ repeat_duration_ms=repeat_duration_ms,
+ auto_reverse=True if auto_reverse else None,
+ rewind=True if rewind else None,
+ accelerate=accelerate or None,
+ decelerate=decelerate or None,
+ bounce_end=bounce_end or None,
+ restart=restart if row.get('restart') is not None else None,
+ after_effect=after_effect,
+ after_effect_color=after_effect_color,
+ sound_relationship_id=sound_relationship_id,
+ sound_name=sound_name,
+ )
+ option_candidates = [dict(effect_options)]
+ option_candidates.extend(
+ {
+ name: value
+ for name, value in effect_options.items()
+ if name != omitted
+ }
+ for omitted in effect_options
+ )
+ option_candidates.append({})
+ seen: set[tuple[tuple[str, object], ...]] = set()
+ for candidate in option_candidates:
+ candidate_key = tuple(sorted(candidate.items()))
+ if candidate_key in seen:
+ continue
+ seen.add(candidate_key)
+ expected = _animation_row_for_options(effect, candidate)
+ if spec['durationScalable']:
+ _scale_animation_row_duration(
+ expected,
+ base_duration_ms=int(spec['defaultDurationMs']),
+ requested_duration_ms=duration_ms,
+ )
+ _apply_timing_options(expected, target)
+ row_id = row.get('id')
+ expected.set('id', row_id if row_id and row_id.isdigit() else '1')
+ _append_after_effect(
+ expected,
+ target,
+ int(expected.get('id', '1')),
+ )
+ _append_animation_sound(expected, target)
+ if _animation_spec_matches_row(
+ row,
+ {'rowXml': ET.tostring(expected, encoding='unicode')},
+ ):
+ return True
+ return False
def _animation_rows(
slide_root: ET.Element,
errors: list[str],
+ *,
+ require_behavior_signatures: bool = False,
) -> list[AnimationRowSummary]:
parent_map = {
child: parent
@@ -2761,6 +2934,35 @@ def _animation_rows(
or preset_subtype is None
):
continue
+ if (
+ require_behavior_signatures
+ and resolved_effect is not None
+ and duration_ms is not None
+ and not _row_matches_powerpoint_behavior(
+ row,
+ shape_id=shape_id,
+ effect=resolved_effect,
+ effect_options=effect_options,
+ trigger=trigger,
+ duration_ms=duration_ms,
+ repeat_count=repeat_count,
+ repeat_duration_ms=repeat_duration_ms,
+ auto_reverse=auto_reverse,
+ rewind=rewind,
+ accelerate=accelerate,
+ decelerate=decelerate,
+ bounce_end=bounce_end,
+ restart=restart,
+ after_effect=after_effect,
+ after_effect_color=after_effect_color,
+ sound_relationship_id=sound_relationship_id,
+ sound_name=sound_name,
+ )
+ ):
+ errors.append(
+ 'object-animation PowerPoint-authored behavior tree changed '
+ f'for shape {shape_id}'
+ )
rows.append(
AnimationRowSummary(
shape_id=shape_id,
@@ -2980,7 +3182,11 @@ def validate_slide_animation_structure(
if node.get('presetClass') in set(_PRESET_CLASS_BY_CATEGORY.values())
]
if require_supported_effects:
- rows = _animation_rows(slide_root, errors)
+ rows = _animation_rows(
+ slide_root,
+ errors,
+ require_behavior_signatures=True,
+ )
if not rows and animation_nodes:
errors.append('generated object-animation rows could not be read back')
else:
@@ -3012,16 +3218,6 @@ def validate_slide_animation_structure(
'each generated trigger-shape animation must have one '
'interactiveSeq time node'
)
- regular_triggers = {row.trigger for row in regular_rows}
- if len(regular_triggers) > 1:
- errors.append(
- 'one generated main object-animation sequence must use one '
- 'Start mode; found '
- + ', '.join(sorted(regular_triggers))
- )
- row_shape_ids = [row.shape_id for row in rows]
- if len(row_shape_ids) != len(set(row_shape_ids)):
- errors.append('generated object-animation sequence repeats a shape target')
for row in rows:
if (
row.trigger_shape_id is not None
@@ -3064,7 +3260,11 @@ def read_slide_animation_sequence(
require_supported_effects=require_supported_effects,
)
row_errors: list[str] = []
- rows = _animation_rows(root, row_errors)
+ rows = _animation_rows(
+ root,
+ row_errors,
+ require_behavior_signatures=require_supported_effects,
+ )
for error in row_errors:
if error not in errors:
errors.append(error)
@@ -3111,7 +3311,7 @@ def validate_generated_animation_xml(
allow_zero=False,
)
normalized_expected = tuple(
- _normalize_target(target, default_duration_ms)
+ _normalize_target(target, default_duration_ms, trigger)
for target in targets
)
# PowerPoint stores ordinary rows in mainSeq and shape-triggered rows in
@@ -3130,6 +3330,13 @@ def validate_generated_animation_xml(
slide_xml,
require_supported_effects=True,
)
+ data = slide_xml.encode('utf-8') if isinstance(slide_xml, str) else slide_xml
+ actual_root = _select_supported_timing_branch(ET.fromstring(data))
+ actual_row_elements = [
+ row
+ for row in actual_root.iter(_qn(PML_NS, 'cTn'))
+ if row.get('presetClass') in set(_PRESET_CLASS_BY_CATEGORY.values())
+ ]
errors: list[str] = []
if len(summary.rows) != len(expected):
errors.append(
@@ -3139,8 +3346,17 @@ def validate_generated_animation_xml(
expected_main_targets = tuple(
target for target in expected if target.trigger_shape_id is None
)
+ expected_main_triggers = {
+ target.trigger for target in expected_main_targets
+ }
expected_sequence_trigger = (
- trigger if expected_main_targets else ('on-click' if expected else None)
+ (
+ next(iter(expected_main_triggers))
+ if len(expected_main_triggers) == 1
+ else None
+ )
+ if expected_main_targets
+ else ('on-click' if expected else None)
)
if expected and summary.trigger != expected_sequence_trigger:
errors.append(
@@ -3148,28 +3364,19 @@ def validate_generated_animation_xml(
f'expected {expected_sequence_trigger!r}'
)
- expected_offsets: list[int] = []
- elapsed_ms = 0
- previous_duration_ms = 0
- main_index = 0
- for index, target in enumerate(expected):
- if target.trigger_shape_id is not None:
- expected_offsets.append(target.delay_ms)
- elif trigger == 'after-previous':
- if main_index == 0:
- elapsed_ms = target.delay_ms
- else:
- elapsed_ms += previous_duration_ms + target.delay_ms
- if elapsed_ms > MAX_OOXML_MILLISECONDS:
- errors.append(
- 'requested animation sequence offset exceeds the OOXML '
- f'millisecond limit at row {index + 1}: {elapsed_ms}'
- )
- expected_offsets.append(elapsed_ms)
- previous_duration_ms = target.playback_duration_ms
- main_index += 1
- else:
- expected_offsets.append(0)
+ try:
+ main_offsets = iter(_main_target_offsets(expected_main_targets))
+ except ValueError as exc:
+ errors.append(str(exc))
+ main_offsets = iter(())
+ expected_offsets = [
+ (
+ target.delay_ms
+ if target.trigger_shape_id is not None
+ else next(main_offsets, 0)
+ )
+ for target in expected
+ ]
for index, (actual, target) in enumerate(zip(summary.rows, expected), 1):
spec = NATIVE_ANIMATIONS[target.effect]
@@ -3220,13 +3427,43 @@ def validate_generated_animation_xml(
f'animation row {index} expected-option model failed: '
+ '; '.join(option_errors)
)
+ if index <= len(actual_row_elements):
+ actual_row_element = actual_row_elements[index - 1]
+ expected_behavior_row = copy.deepcopy(expected_row)
+ actual_row_id = actual_row_element.get('id')
+ expected_behavior_row.set(
+ 'id',
+ actual_row_id
+ if actual_row_id and actual_row_id.isdigit()
+ else '1',
+ )
+ _append_after_effect(
+ expected_behavior_row,
+ target,
+ int(expected_behavior_row.get('id', '1')),
+ )
+ _append_animation_sound(expected_behavior_row, target)
+ behavior_spec = {
+ 'rowXml': ET.tostring(
+ expected_behavior_row,
+ encoding='unicode',
+ )
+ }
+ if not _animation_spec_matches_row(
+ actual_row_element,
+ behavior_spec,
+ ):
+ errors.append(
+ f'animation row {index} PowerPoint-authored behavior '
+ 'tree changed'
+ )
if actual.shape_id != target.shape_id:
errors.append(
f'animation row {index} targets shape {actual.shape_id}; '
f'expected {target.shape_id}'
)
expected_row_trigger = (
- 'on-click' if target.trigger_shape_id is not None else trigger
+ target.trigger
)
if actual.trigger != expected_row_trigger:
errors.append(
@@ -3581,13 +3818,22 @@ def describe_animation_effect(effect: object) -> dict[str, Any]:
'implied_effect_options': implied_options,
'effect_options': option_contract,
'timing': {
- 'duration': 'positive seconds',
- 'delay': 'non-negative seconds; group scope only',
+ 'duration': (
+ 'positive seconds; legacy group effect or effects[] row'
+ ),
+ 'delay': (
+ 'non-negative seconds; legacy group effect or effects[] row'
+ ),
'stagger': 'non-negative seconds; animation scope only',
'trigger': list(ANIMATION_TRIGGERS),
+ 'trigger_scope': (
+ 'animation default for a legacy group effect; each effects[] '
+ 'row may override it'
+ ),
'trigger_shape': (
- 'other top-level SVG group id; group scope only; maps to '
- 'PowerPoint "On Click of"'
+ 'other top-level SVG group id; legacy group effect or '
+ 'effects[] row; maps to PowerPoint "On Click of" and requires '
+ 'trigger on-click'
),
'repeat_count': 'positive number; mutually exclusive with repeat_duration',
'repeat_duration': 'positive seconds; mutually exclusive with repeat_count',
diff --git a/skills/ppt-master/scripts/svg_to_pptx/animation_config.py b/skills/ppt-master/scripts/svg_to_pptx/animation_config.py
index 6c39c51c..75e5f21a 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/animation_config.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/animation_config.py
@@ -45,6 +45,18 @@ _INHERITANCE_SENSITIVE_ANIMATION_FIELDS = frozenset({
'decelerate',
'bounce_end',
})
+_GROUP_EFFECT_FIELDS = frozenset({
+ 'effect',
+ 'effect_options',
+ 'duration',
+ 'delay',
+ 'order',
+ 'trigger',
+ 'trigger_shape',
+ *ANIMATION_TIMING_OPTION_FIELDS,
+ 'after_effect',
+ 'sound',
+})
_CHROME_ID_TOKENS = frozenset({
'background', 'bg',
'decoration', 'decorations', 'decor',
@@ -258,6 +270,45 @@ def resolve_slide_animation_config(
return resolved
+def animation_group_effect_entries(
+ group_cfg: dict[str, Any],
+ *,
+ path: str,
+) -> tuple[tuple[str, dict[str, Any]], ...]:
+ """Expand one legacy group block or one ordered multi-effect envelope."""
+ if 'effects' not in group_cfg:
+ return ((path, group_cfg),)
+
+ extra_fields = sorted(set(group_cfg) - {'effects'})
+ if extra_fields:
+ rendered = ', '.join(repr(field) for field in extra_fields)
+ raise ValueError(
+ f'animations.json {path} cannot combine "effects" with '
+ f'other group-level field(s): {rendered}'
+ )
+ effects = group_cfg['effects']
+ if not isinstance(effects, list):
+ raise ValueError(f'animations.json {path}.effects must be an array')
+ if not effects:
+ raise ValueError(
+ f'animations.json {path}.effects must contain at least one effect'
+ )
+
+ entries: list[tuple[str, dict[str, Any]]] = []
+ for index, effect_cfg in enumerate(effects):
+ effect_path = f'{path}.effects[{index}]'
+ if not isinstance(effect_cfg, dict):
+ raise ValueError(
+ f'animations.json {effect_path} must be an object'
+ )
+ if 'effect' not in effect_cfg:
+ raise ValueError(
+ f'animations.json {effect_path}.effect is required'
+ )
+ entries.append((effect_path, effect_cfg))
+ return tuple(entries)
+
+
def _animation_parameter_errors(
value: dict[str, Any],
label: str,
@@ -860,77 +911,137 @@ def _animation_group_errors(
errors: list[str] = []
for group_id, group_cfg in groups.items():
- label = f'group "{slide_name}/{group_id}"'
+ path = (
+ f'slides[{json.dumps(str(slide_name), ensure_ascii=False)}]'
+ f'.groups[{json.dumps(str(group_id), ensure_ascii=False)}]'
+ )
if not isinstance(group_cfg, dict):
- errors.append(f'animations.json {label} must be an object')
+ errors.append(f'animations.json {path} must be an object')
continue
- errors.extend(
- _unknown_field_errors(
- group_cfg,
- frozenset({
- 'effect',
- 'effect_options',
- 'duration',
- 'delay',
- 'order',
- 'trigger_shape',
- *ANIMATION_TIMING_OPTION_FIELDS,
- 'after_effect',
- 'sound',
- }),
- label,
- )
- )
-
- if 'effect' in group_cfg:
- effect_error = _animation_effect_error(group_cfg['effect'], label)
- if effect_error:
- errors.append(effect_error)
-
- for field, allow_zero in (('duration', False), ('delay', True)):
- if field not in group_cfg:
- continue
- try:
- animation_seconds_to_milliseconds(
- group_cfg[field],
- f'animations.json {label} animation {field}',
- allow_zero=allow_zero,
+ if 'effects' not in group_cfg:
+ errors.extend(
+ _animation_effect_entry_errors(
+ group_cfg,
+ path,
+ require_effect=False,
+ target_group_id=str(group_id),
)
- except ValueError as exc:
- errors.append(str(exc))
+ )
+ continue
- if 'order' in group_cfg:
- order = group_cfg['order']
- if isinstance(order, bool) or not isinstance(order, int) or order <= 0:
- errors.append(
- f'animations.json {label} animation order must be a positive integer: '
- f'{order!r}'
- )
- if 'trigger_shape' in group_cfg:
- trigger_shape = group_cfg['trigger_shape']
- if not isinstance(trigger_shape, str) or not trigger_shape.strip():
- errors.append(
- f'animations.json {label} trigger_shape must be a '
- f'non-empty group id: {trigger_shape!r}'
- )
- elif trigger_shape == str(group_id):
+ extra_fields = sorted(set(group_cfg) - {'effects'})
+ if extra_fields:
+ rendered = ', '.join(repr(field) for field in extra_fields)
+ errors.append(
+ f'animations.json {path} cannot combine "effects" with '
+ f'other group-level field(s): {rendered}'
+ )
+ effects = group_cfg['effects']
+ if not isinstance(effects, list):
+ errors.append(f'animations.json {path}.effects must be an array')
+ continue
+ if not effects:
+ errors.append(
+ f'animations.json {path}.effects must contain at least one effect'
+ )
+ continue
+ for index, effect_cfg in enumerate(effects):
+ effect_path = f'{path}.effects[{index}]'
+ if not isinstance(effect_cfg, dict):
errors.append(
- f'animations.json {label} trigger_shape must reference '
- 'a different group'
+ f'animations.json {effect_path} must be an object'
)
- if group_cfg.get('effect') == 'none':
- errors.append(
- f'animations.json {label} trigger_shape cannot be used '
- 'with effect "none"'
+ continue
+ errors.extend(
+ _animation_effect_entry_errors(
+ effect_cfg,
+ effect_path,
+ require_effect=True,
+ target_group_id=str(group_id),
)
- errors.extend(
- _animation_parameter_errors(
- group_cfg,
- label,
- inherited_effect='auto',
)
+ return errors
+
+
+def _animation_effect_entry_errors(
+ effect_cfg: dict[str, Any],
+ path: str,
+ *,
+ require_effect: bool,
+ target_group_id: str,
+) -> list[str]:
+ """Validate one legacy group block or one ``effects[]`` row."""
+ errors = _unknown_field_errors(
+ effect_cfg,
+ _GROUP_EFFECT_FIELDS,
+ path,
+ )
+ if require_effect and 'effect' not in effect_cfg:
+ errors.append(f'animations.json {path}.effect is required')
+ elif 'effect' in effect_cfg:
+ effect_error = _animation_effect_error(effect_cfg['effect'], path)
+ if effect_error:
+ errors.append(effect_error)
+
+ for field, allow_zero in (('duration', False), ('delay', True)):
+ if field not in effect_cfg:
+ continue
+ try:
+ animation_seconds_to_milliseconds(
+ effect_cfg[field],
+ f'animations.json {path}.{field}',
+ allow_zero=allow_zero,
+ )
+ except ValueError as exc:
+ errors.append(str(exc))
+
+ if 'order' in effect_cfg:
+ order = effect_cfg['order']
+ if isinstance(order, bool) or not isinstance(order, int) or order <= 0:
+ errors.append(
+ f'animations.json {path}.order must be a positive integer: '
+ f'{order!r}'
+ )
+
+ if 'trigger' in effect_cfg:
+ trigger_error = _animation_trigger_error(effect_cfg['trigger'], path)
+ if trigger_error:
+ errors.append(trigger_error)
+
+ if 'trigger_shape' in effect_cfg:
+ trigger_shape = effect_cfg['trigger_shape']
+ if not isinstance(trigger_shape, str) or not trigger_shape.strip():
+ errors.append(
+ f'animations.json {path}.trigger_shape must be a '
+ f'non-empty group id: {trigger_shape!r}'
+ )
+ elif trigger_shape == target_group_id:
+ errors.append(
+ f'animations.json {path}.trigger_shape must reference '
+ 'a different group'
+ )
+ if effect_cfg.get('effect') == 'none':
+ errors.append(
+ f'animations.json {path}.trigger_shape cannot be used '
+ 'with effect "none"'
+ )
+ if (
+ 'trigger' in effect_cfg
+ and effect_cfg.get('trigger') != 'on-click'
+ ):
+ errors.append(
+ f'animations.json {path}.trigger_shape requires '
+ 'trigger "on-click" when trigger is explicit'
+ )
+
+ errors.extend(
+ _animation_parameter_errors(
+ effect_cfg,
+ path,
+ inherited_effect='auto',
)
+ )
return errors
@@ -969,7 +1080,7 @@ def _bounce_support_error(
def _resolved_animation_parameter_errors(config: dict[str, Any]) -> list[str]:
"""Validate effective animation parameters after sidecar inheritance."""
defaults = config.get('defaults', {})
- default_animation: dict[str, Any] = {'effect': 'auto'}
+ default_animation: dict[str, Any] = {'effect': 'none'}
if isinstance(defaults, dict):
value = defaults.get('animation', {})
if isinstance(value, dict):
@@ -1015,40 +1126,54 @@ def _resolved_animation_parameter_errors(config: dict[str, Any]) -> list[str]:
if not isinstance(groups, dict):
continue
for group_id, group_cfg in groups.items():
- if (
- not isinstance(group_cfg, dict)
- or not _INHERITANCE_SENSITIVE_ANIMATION_FIELDS & set(group_cfg)
- ):
+ if not isinstance(group_cfg, dict):
continue
- inherited_group_animation = {
- field: slide_animation[field]
- for field in (
- 'effect',
- 'effect_options',
- 'duration',
- *ANIMATION_TIMING_OPTION_FIELDS,
- 'after_effect',
- 'sound',
- )
- if field in slide_animation
- }
- group_animation = resolve_slide_animation_config(
- inherited_group_animation,
- group_cfg,
+ path = (
+ f'slides[{json.dumps(str(slide_name), ensure_ascii=False)}]'
+ f'.groups[{json.dumps(str(group_id), ensure_ascii=False)}]'
)
- errors.extend(
- _animation_parameter_errors(
+ try:
+ effect_entries = animation_group_effect_entries(
+ group_cfg,
+ path=path,
+ )
+ except ValueError:
+ continue
+ for effect_path, effect_cfg in effect_entries:
+ if not (
+ _INHERITANCE_SENSITIVE_ANIMATION_FIELDS
+ & set(effect_cfg)
+ ):
+ continue
+ inherited_group_animation = {
+ field: slide_animation[field]
+ for field in (
+ 'effect',
+ 'effect_options',
+ 'duration',
+ *ANIMATION_TIMING_OPTION_FIELDS,
+ 'after_effect',
+ 'sound',
+ )
+ if field in slide_animation
+ }
+ group_animation = resolve_slide_animation_config(
+ inherited_group_animation,
+ effect_cfg,
+ )
+ errors.extend(
+ _animation_parameter_errors(
+ group_animation,
+ effect_path,
+ inherited_effect='none',
+ )
+ )
+ error = _bounce_support_error(
group_animation,
- f'group "{slide_name}/{group_id}"',
- inherited_effect='auto',
+ effect_path,
)
- )
- error = _bounce_support_error(
- group_animation,
- f'group "{slide_name}/{group_id}"',
- )
- if error:
- errors.append(error)
+ if error:
+ errors.append(error)
return errors
@@ -1076,10 +1201,22 @@ def _declared_animation_sounds(
if not isinstance(groups, dict):
continue
for group_id, group_cfg in groups.items():
- if isinstance(group_cfg, dict) and 'sound' in group_cfg:
- sounds.append(
- (f'group "{slide_name}/{group_id}"', group_cfg['sound'])
+ if not isinstance(group_cfg, dict):
+ continue
+ path = (
+ f'slides[{json.dumps(str(slide_name), ensure_ascii=False)}]'
+ f'.groups[{json.dumps(str(group_id), ensure_ascii=False)}]'
+ )
+ try:
+ effect_entries = animation_group_effect_entries(
+ group_cfg,
+ path=path,
)
+ except ValueError:
+ continue
+ for effect_path, effect_cfg in effect_entries:
+ if 'sound' in effect_cfg:
+ sounds.append((effect_path, effect_cfg['sound']))
return tuple(sounds)
@@ -1159,6 +1296,15 @@ def validate_animation_config(
for target in slide_targets
if target.group_id not in ambiguous_ids
}
+ default_animation: dict[str, Any] = {'effect': 'none'}
+ defaults = config.get('defaults', {})
+ if isinstance(defaults, dict):
+ animation_value = defaults.get('animation', {})
+ if isinstance(animation_value, dict):
+ default_animation = resolve_slide_animation_config(
+ default_animation,
+ animation_value,
+ )
slides = config.get('slides', {})
if not isinstance(slides, dict):
return list(dict.fromkeys(warnings))
@@ -1169,6 +1315,13 @@ def validate_animation_config(
if not isinstance(slide_cfg, dict):
continue
+ slide_animation = default_animation
+ animation_value = slide_cfg.get('animation', {})
+ if isinstance(animation_value, dict):
+ slide_animation = resolve_slide_animation_config(
+ default_animation,
+ animation_value,
+ )
slide_targets = targets_by_slide.get(slide_name, [])
duplicate_ids = duplicates_by_slide.get(slide_name, ())
ambiguous_ids = set(duplicate_ids)
@@ -1177,42 +1330,71 @@ def validate_animation_config(
if not isinstance(groups, dict):
continue
for group_id, group_cfg in groups.items():
+ path = (
+ f'slides[{json.dumps(str(slide_name), ensure_ascii=False)}]'
+ f'.groups[{json.dumps(str(group_id), ensure_ascii=False)}]'
+ )
if group_id in ambiguous_ids:
continue
if group_id not in known_groups:
warnings.append(
- f'animations.json references missing group: {slide_name}/{group_id}'
+ f'animations.json {path} references a missing group'
)
continue
target = known_groups[group_id]
- effect = group_cfg.get('effect') if isinstance(group_cfg, dict) else None
- if target.structurally_static and effect != 'none':
- warnings.append(
- 'animations.json references non-animatable structural group: '
- f'{slide_name}/{group_id}'
- )
if not isinstance(group_cfg, dict):
continue
- trigger_shape = group_cfg.get('trigger_shape')
- if not isinstance(trigger_shape, str) or not trigger_shape.strip():
- continue
- if trigger_shape in ambiguous_ids:
- warnings.append(
- 'animations.json trigger_shape references ambiguous group: '
- f'{slide_name}/{trigger_shape}'
+ try:
+ effect_entries = animation_group_effect_entries(
+ group_cfg,
+ path=path,
)
+ except ValueError:
continue
- trigger_target = known_groups.get(trigger_shape)
- if trigger_target is None:
- warnings.append(
- 'animations.json trigger_shape references missing group: '
- f'{slide_name}/{trigger_shape}'
+ if (
+ target.structurally_static
+ and any(
+ normalize_animation_effect(
+ effect_cfg.get(
+ 'effect',
+ slide_animation.get('effect', 'none'),
+ ),
+ allow_none=True,
+ allow_modes=True,
+ )
+ is not None
+ for _effect_path, effect_cfg in effect_entries
)
- elif trigger_target.structurally_static:
+ ):
warnings.append(
- 'animations.json trigger_shape references non-triggerable '
- f'structural group: {slide_name}/{trigger_shape}'
+ f'animations.json {path} references a non-animatable '
+ 'structural group'
)
+ for effect_path, effect_cfg in effect_entries:
+ trigger_shape = effect_cfg.get('trigger_shape')
+ if (
+ not isinstance(trigger_shape, str)
+ or not trigger_shape.strip()
+ ):
+ continue
+ if trigger_shape in ambiguous_ids:
+ warnings.append(
+ f'animations.json {effect_path}.trigger_shape '
+ f'references ambiguous group {trigger_shape!r}'
+ )
+ continue
+ trigger_target = known_groups.get(trigger_shape)
+ if trigger_target is None:
+ warnings.append(
+ f'animations.json {effect_path}.trigger_shape '
+ f'references missing group {trigger_shape!r}'
+ )
+ elif trigger_target.structurally_static:
+ warnings.append(
+ f'animations.json {effect_path}.trigger_shape '
+ f'references non-triggerable structural group '
+ f'{trigger_shape!r}'
+ )
morph_pairs, morph_errors = _resolve_morph_pairs(
list(targets_by_slide),
@@ -1250,7 +1432,7 @@ def build_scaffold(project_path: Path) -> dict[str, Any]:
"""
transition_defaults = {'effect': 'fade', 'duration': 0.4}
animation_defaults = {
- 'effect': 'auto',
+ 'effect': 'none',
'duration': 0.4,
'stagger': 0.5,
'trigger': 'after-previous',
diff --git a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py
index b9c12318..681f602d 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py
@@ -58,6 +58,7 @@ from language_tags import normalize_language_tag
from ..animation_config import (
MorphPair,
+ animation_group_effect_entries,
resolve_morph_pairs,
resolve_slide_animation_config,
)
@@ -4124,6 +4125,7 @@ def _slide_animation_settings(
def _build_sequence_targets(
anim_targets: list[tuple[int, str]],
+ slide_name: str,
slide_cfg: dict[str, Any],
animation: str | None,
animation_cfg: dict[str, Any],
@@ -4139,44 +4141,74 @@ def _build_sequence_targets(
shape_ids_by_group = {
svg_id: sid for sid, svg_id in anim_targets
}
- ordered: list[tuple[int, int, str, dict[str, Any]]] = []
+ ordered: list[tuple[int, int, int, str, str, dict[str, Any]]] = []
for idx, (sid, svg_id) in enumerate(anim_targets):
group_value = groups_cfg.get(svg_id, {})
if not isinstance(group_value, dict):
raise ValueError(
f'animations.json group "{svg_id}" must be an object'
)
- group_cfg = group_value
- raw_effect = group_cfg.get('effect')
- if raw_effect is not None:
- normalized_effect = normalize_animation_effect(
- raw_effect,
- allow_none=True,
- allow_modes=True,
- )
- else:
- normalized_effect = None
- if 'effect' in group_cfg and normalized_effect is None:
- continue
- if animation is None and normalized_effect is None:
- continue
- order_value = group_cfg.get('order')
- order = order_value if order_value is not None else idx + 1
- if isinstance(order, bool) or not isinstance(order, int) or order <= 0:
- raise ValueError(
- f'animations.json group "{svg_id}" order must be a positive integer'
+ group_path = (
+ f'slides[{json.dumps(slide_name, ensure_ascii=False)}]'
+ f'.groups[{json.dumps(svg_id, ensure_ascii=False)}]'
+ )
+ effect_entries = animation_group_effect_entries(
+ group_value,
+ path=group_path,
+ )
+ for effect_idx, (effect_path, effect_cfg) in enumerate(effect_entries):
+ raw_effect = effect_cfg.get('effect')
+ if raw_effect is not None:
+ normalized_effect = normalize_animation_effect(
+ raw_effect,
+ allow_none=True,
+ allow_modes=True,
+ )
+ else:
+ normalized_effect = None
+ if 'effect' in effect_cfg and normalized_effect is None:
+ continue
+ if animation is None and normalized_effect is None:
+ continue
+ order_value = effect_cfg.get('order')
+ order = order_value if order_value is not None else idx + 1
+ if (
+ isinstance(order, bool)
+ or not isinstance(order, int)
+ or order <= 0
+ ):
+ raise ValueError(
+ f'animations.json {effect_path}.order must be '
+ 'a positive integer'
+ )
+ effect_entry = dict(effect_cfg)
+ effect_entry['_shape_id'] = sid
+ effect_entry['_effect'] = normalized_effect
+ effect_entry['_effect_raw'] = raw_effect
+ ordered.append(
+ (
+ order,
+ idx,
+ effect_idx,
+ svg_id,
+ effect_path,
+ effect_entry,
+ )
)
- group_entry = dict(group_cfg)
- group_entry['_shape_id'] = sid
- group_entry['_effect'] = normalized_effect
- group_entry['_effect_raw'] = raw_effect
- ordered.append((order, idx, svg_id, group_entry))
- ordered.sort(key=lambda item: (item[0], item[1]))
+ ordered.sort(key=lambda item: (item[0], item[1], item[2]))
seq_targets: list[dict[str, Any]] = []
resolved_group_modes: list[str | None] = []
- for seq_idx, (_order, _original_idx, _svg_id, group_cfg) in enumerate(ordered):
+ main_sequence_count = 0
+ for seq_idx, (
+ _order,
+ _original_idx,
+ _effect_idx,
+ _svg_id,
+ effect_path,
+ group_cfg,
+ ) in enumerate(ordered):
shape_id = int(group_cfg['_shape_id'])
raw_effect = group_cfg.get('_effect')
resolved_group_modes.append(
@@ -4211,22 +4243,39 @@ def _build_sequence_targets(
)
item_duration = validate_seconds(
group_cfg.get('duration', duration),
- f'animation duration for group "{_svg_id}"',
+ f'animations.json {effect_path}.duration',
allow_zero=False,
)
+ trigger_shape = group_cfg.get('trigger_shape')
+ raw_trigger = group_cfg.get(
+ 'trigger',
+ animation_cfg.get('trigger', 'after-previous'),
+ )
+ resolved_trigger = normalize_animation_trigger(raw_trigger)
+ if trigger_shape is not None:
+ if 'trigger' in group_cfg and resolved_trigger != 'on-click':
+ raise ValueError(
+ f'animations.json {effect_path}.trigger_shape requires '
+ 'trigger "on-click" when trigger is explicit'
+ )
+ resolved_trigger = 'on-click'
default_delay = (
- 0
- if group_cfg.get('trigger_shape') is not None or seq_idx == 0
- else stagger
+ stagger
+ if (
+ trigger_shape is None
+ and resolved_trigger == 'after-previous'
+ and main_sequence_count > 0
+ )
+ else 0
)
delay_seconds = validate_seconds(
group_cfg.get('delay', default_delay),
- f'animation delay for group "{_svg_id}"',
+ f'animations.json {effect_path}.delay',
allow_zero=True,
)
delay_ms = animation_seconds_to_milliseconds(
delay_seconds,
- f'animation delay for group "{_svg_id}"',
+ f'animations.json {effect_path}.delay',
allow_zero=True,
)
inherited_fields = {
@@ -4255,27 +4304,29 @@ def _build_sequence_targets(
'effect': effect,
'effect_options': effect_options,
'duration': item_duration,
+ 'trigger': resolved_trigger,
}
- trigger_shape = group_cfg.get('trigger_shape')
if trigger_shape is not None:
if not isinstance(trigger_shape, str) or not trigger_shape.strip():
raise ValueError(
- f'animations.json group "{_svg_id}" trigger_shape must '
+ f'animations.json {effect_path}.trigger_shape must '
'be a non-empty group id'
)
trigger_shape_id = shape_ids_by_group.get(trigger_shape)
if trigger_shape_id is None:
raise ValueError(
- f'animations.json group "{_svg_id}" trigger_shape '
+ f'animations.json {effect_path}.trigger_shape '
f'references a missing or non-triggerable group: '
f'{trigger_shape}'
)
if trigger_shape_id == shape_id:
raise ValueError(
- f'animations.json group "{_svg_id}" trigger_shape must '
+ f'animations.json {effect_path}.trigger_shape must '
'reference a different group'
)
target_entry['trigger_shape_id'] = trigger_shape_id
+ else:
+ main_sequence_count += 1
target_entry.update(inherited_fields)
if 'sound' in target_entry:
target_entry['_sound_path'] = target_entry.pop('sound')
@@ -5138,25 +5189,41 @@ def create_pptx_with_native_svg(
animation_cli_overrides.get('animation', False)
and animation is None
)
- explicit_animation_groups = (
- frozenset({
- str(group_id)
- for group_id, group_cfg in groups_value.items()
- if isinstance(group_cfg, dict)
- and group_cfg.get('effect') != 'none'
- and (
- slide_animation is not None
- or 'effect' in group_cfg
+ explicit_group_ids: set[str] = set()
+ trigger_group_ids: set[str] = set()
+ if not animation_hard_disabled:
+ for group_id, group_cfg in groups_value.items():
+ if not isinstance(group_cfg, dict):
+ continue
+ group_path = (
+ f'slides['
+ f'{json.dumps(svg_path.stem, ensure_ascii=False)}'
+ f'].groups['
+ f'{json.dumps(str(group_id), ensure_ascii=False)}'
+ f']'
)
- } | {
- group_cfg['trigger_shape']
- for group_cfg in groups_value.values()
- if isinstance(group_cfg, dict)
- and isinstance(group_cfg.get('trigger_shape'), str)
- and group_cfg['trigger_shape'].strip()
- })
- if not animation_hard_disabled
- else frozenset()
+ effect_entries = animation_group_effect_entries(
+ group_cfg,
+ path=group_path,
+ )
+ if any(
+ effect_cfg.get('effect') != 'none'
+ and (
+ slide_animation is not None
+ or 'effect' in effect_cfg
+ )
+ for _effect_path, effect_cfg in effect_entries
+ ):
+ explicit_group_ids.add(str(group_id))
+ for _effect_path, effect_cfg in effect_entries:
+ trigger_shape = effect_cfg.get('trigger_shape')
+ if (
+ isinstance(trigger_shape, str)
+ and trigger_shape.strip()
+ ):
+ trigger_group_ids.add(trigger_shape)
+ explicit_animation_groups = frozenset(
+ explicit_group_ids | trigger_group_ids
)
converter_group_overrides = (
explicit_animation_groups
@@ -5247,6 +5314,7 @@ def create_pptx_with_native_svg(
):
seq_targets, mixed_count = _build_sequence_targets(
anim_targets,
+ svg_path.stem,
slide_cfg,
slide_animation,
slide_animation_cfg,
diff --git a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/cli.py b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/cli.py
index 927ebd15..9d34b037 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/cli.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/cli.py
@@ -79,6 +79,7 @@ from .template_structure import (
template_prototype_errors,
)
from ..animation_config import (
+ animation_group_effect_entries,
load_animation_config,
validate_animation_config,
validate_animation_config_errors,
@@ -728,36 +729,50 @@ def _recorded_narration_on_click_slides(
slide_animation = animation
if not animation_cli_overrides.get('animation') and 'effect' in anim_cfg:
slide_animation = normalize_animation_effect(anim_cfg.get('effect'))
- groups_cfg = _as_dict(slide_cfg.get('groups'))
- has_explicit_animation = any(
- isinstance(group_cfg, dict)
- and 'effect' in group_cfg
- and normalize_animation_effect(group_cfg.get('effect')) is not None
- for group_cfg in groups_cfg.values()
- )
- if slide_animation is None and not has_explicit_animation:
- continue
- has_interactive_animation = any(
- isinstance(group_cfg, dict)
- and isinstance(group_cfg.get('trigger_shape'), str)
- and bool(group_cfg['trigger_shape'].strip())
- and (
- (
- 'effect' in group_cfg
- and normalize_animation_effect(group_cfg.get('effect')) is not None
- )
- or ('effect' not in group_cfg and slide_animation is not None)
- )
- for group_cfg in groups_cfg.values()
- )
- if has_interactive_animation:
- blocked.append(svg_path.stem)
- continue
-
slide_trigger = animation_trigger
- if not animation_cli_overrides.get('animation_trigger') and anim_cfg.get('trigger'):
+ if (
+ not animation_cli_overrides.get('animation_trigger')
+ and anim_cfg.get('trigger')
+ ):
slide_trigger = normalize_animation_trigger(anim_cfg.get('trigger'))
- if slide_trigger == 'on-click':
+
+ groups_cfg = _as_dict(slide_cfg.get('groups'))
+ has_interactive_animation = False
+ for group_id, group_cfg in groups_cfg.items():
+ if not isinstance(group_cfg, dict):
+ continue
+ group_path = (
+ f'slides[{json.dumps(svg_path.stem, ensure_ascii=False)}]'
+ f'.groups[{json.dumps(str(group_id), ensure_ascii=False)}]'
+ )
+ for _effect_path, effect_cfg in animation_group_effect_entries(
+ group_cfg,
+ path=group_path,
+ ):
+ row_effect = (
+ normalize_animation_effect(effect_cfg.get('effect'))
+ if 'effect' in effect_cfg
+ else slide_animation
+ )
+ if row_effect is None:
+ continue
+ row_trigger = (
+ normalize_animation_trigger(effect_cfg.get('trigger'))
+ if effect_cfg.get('trigger')
+ else slide_trigger
+ )
+ if effect_cfg.get('trigger_shape') is not None:
+ has_interactive_animation = True
+ break
+ if row_trigger == 'on-click':
+ has_interactive_animation = True
+ break
+ if has_interactive_animation:
+ break
+
+ if has_interactive_animation or (
+ slide_animation is not None and slide_trigger == 'on-click'
+ ):
blocked.append(svg_path.stem)
return blocked
@@ -834,9 +849,10 @@ Per-element object animation (-a/--animation, native shapes mode):
after-previous (default) cascade on slide entry;
gap = --animation-stagger seconds
mixed (compatible mode name) cycles a larger 16-preset canonical
- PowerPoint pool by group order; random samples from the same pool.
- Use "-a none" to disable
- element builds explicitly.
+ PowerPoint entrance pool by group order; random samples from the
+ same entrance pool. Use explicit canonical keys for emphasis,
+ motion-path, or exit duties. Use "-a none" to disable element
+ builds explicitly.
Speaker notes:
- Automatically reads Markdown notes files from the notes/ directory
@@ -1017,9 +1033,10 @@ Recorded narration:
'(map effect from group id — image-like ids cycle a '
'richer canonical pool for visual variation, fallback '
'cycles entrance_fade/entrance_wipe/entrance_fly/'
- 'entrance_zoom), "mixed" (canonical 16-preset pool), or '
- '"random". Legacy short names remain accepted only for '
- 'compatibility.')
+ 'entrance_zoom), "mixed" (canonical 16-preset entrance '
+ 'pool), or "random" (the same entrance pool). Use '
+ 'explicit keys for emphasis/path/exit. Legacy short '
+ 'names remain accepted only for compatibility.')
parser.add_argument('--animation-duration', type=positive_float, default=None,
help='Per-element object-animation duration in seconds '
'(default: 0.4; instantaneous native presets keep their '