Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All animations are removed whenever an element is removed #78

Closed
ljcsilvert opened this issue Oct 26, 2023 · 6 comments
Closed

All animations are removed whenever an element is removed #78

ljcsilvert opened this issue Oct 26, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@ljcsilvert
Copy link

Hello,

I've noticed that whenever I want to remove an element that has an animation on it, Powerpoint makes me repair the pptx and remove all of the animations in the slide.
Do I do something wrong here? Is there already a workaround for this issue?
Otherwise, would it be possible to reorganize the animations while removing the element?

I have this issue with this code for example:

const title = (pres: Automizer, title?: string, subtitle?: string) => {
  pres.addSlide('title.pptx', 1, (slide) => {
    if (title)
      slide.modifyElement('title', [
        modify.replaceText([{ replace: 'title', by: { title } }]),
      ])
    if (subtitle)
      slide.modifyElement('subtitle', [
        modify.replaceText([{ replace: 'subtitle', by: { subtitle } }]),
      ])

    if (!title) slide.removeElement('title')
    if (!subtitle) slide.removeElement('subtitle')
  })
}

My temporary solution would be to have a slightly different template for each time I have to remove an element, but it's not handy nor maintainable.

@singerla
Copy link
Owner

Hi! I'm sorry, animations are not yet supported. I'll take a look!

@singerla
Copy link
Owner

singerla commented Oct 26, 2023

Huh, that's complicated...

There is <p:bldLst>and <p:timing> that needs to get in sync with removeElement... The latter is nested deeply and I have no idea how this will look when there are lots of animations on a slide.

What about slide.hideElement? This function does not exist yet, but I could imagine there is only hidden that needs to be update:

<p:sp>
  <p:nvSpPr>
    <p:cNvPr id="11" name="Drum" hidden="1">
      <a:extLst>
        ///

What do yo think? This will be the same effect as ALT+F10 and toggle the eye-symbol right besides a shape.

singerla added a commit that referenced this issue Oct 26, 2023
@ljcsilvert
Copy link
Author

I thought about that but I didn't saw the function in the documentation but yes it would work that would be great :)
Do you think it would be possible to implement the function soon? :)

@singerla
Copy link
Owner

This should do the job:

  pres.addSlide('animations', 1, (slide) => {
    slide.modifyElement('Drum', (shape) => {
      // You need to update the 'hidden' attribute with a callback: 
      shape.getElementsByTagName('p:cNvPr').item(0).setAttribute('hidden', '1');
      // XmlHelper.dump(shape);
    });
  });

Feel free to create a helper & PR from this! 😄

@ljcsilvert
Copy link
Author

It works really well thank you a lot you're the best 😀
I'll try to do a PR :)

@singerla
Copy link
Owner

I'm happy to help 😄

@singerla singerla added the enhancement New feature or request label Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants