singerla / pptx-automizer

A template based pptx generator for Node.js
MIT License
63 stars 11 forks source link

All animations are removed whenever an element is removed #78

Closed ljcsilvert closed 10 months ago

ljcsilvert commented 11 months ago

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 commented 11 months ago

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

singerla commented 11 months ago

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.

ljcsilvert commented 11 months ago

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 commented 11 months ago

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! :smile:

ljcsilvert commented 11 months ago

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

singerla commented 11 months ago

I'm happy to help :smile: