Skip to content

Commit

Permalink
feature(master): add modifier for slide master background color #86
Browse files Browse the repository at this point in the history
  • Loading branch information
singerla committed Mar 14, 2024
1 parent b4b7b21 commit d3bc762
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
27 changes: 27 additions & 0 deletions __tests__/modify-master-background-color.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Automizer from '../src/automizer';
import { ModifyTextHelper } from '../src';
import ModifyBackgroundHelper from '../src/helper/modify-background-helper';

test('Auto-import source slideLayout and -master and modify background color', async () => {
const automizer = new Automizer({
templateDir: `${__dirname}/pptx-templates`,
outputDir: `${__dirname}/pptx-output`,
autoImportSlideMasters: true,
});

const pres = await automizer
.loadRoot(`EmptyTemplate.pptx`)
.load('SlideMasterBackgrounds.pptx')
.addMaster(`SlideMasterBackgrounds.pptx`, 1, async (master) => {
master.modify(
ModifyBackgroundHelper.setSolidFill({
type: 'srgbClr',
value: 'aaccbb',
}),
);
})
.addSlide(`SlideMasterBackgrounds.pptx`, 3)
.write(`modify-master-background-color.test.pptx`);

expect(pres.masters).toBe(2);
});
13 changes: 11 additions & 2 deletions src/dev.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Automizer from './index';
import { vd } from './helper/general-helper';
import ModifyBackgroundHelper from './helper/modify-background-helper';

const run = async () => {
const automizer = new Automizer({
Expand All @@ -12,7 +12,16 @@ const run = async () => {
.loadRoot(`RootTemplate.pptx`)
.load(`SlideMasterBackgrounds.pptx`);

pres.addSlide(`SlideMasterBackgrounds.pptx`, 2, async (slide) => {
pres.addMaster(`SlideMasterBackgrounds.pptx`, 1, async (master) => {
master.modify(
ModifyBackgroundHelper.setSolidFill({
type: 'srgbClr',
value: 'aaccbb',
}),
);
});

pres.addSlide(`SlideMasterBackgrounds.pptx`, 3, async (slide) => {
console.log('test');
});

Expand Down
19 changes: 19 additions & 0 deletions src/helper/modify-background-helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { XmlDocument } from '../types/xml-types';
import ModifyColorHelper from './modify-color-helper';
import { Color } from '../types/modify-types';

export default class ModifyBackgroundHelper {
/**
* Set solid fill of modified shape
*/
static setSolidFill =
(color: Color) =>
(slideMasterXml: XmlDocument): void => {
const bgPr = slideMasterXml.getElementsByTagName('p:bgPr')?.item(0);
if (bgPr) {
ModifyColorHelper.solidFill(color)(bgPr);
} else {
throw 'No background properties for slideMaster';
}
};
}
5 changes: 2 additions & 3 deletions src/helper/modify-shape-helper.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { ReplaceText, ReplaceTextOptions } from '../types/modify-types';
import { ShapeCoordinates } from '../types/shape-types';
import { GeneralHelper, vd } from './general-helper';
import { GeneralHelper } from './general-helper';
import TextReplaceHelper from './text-replace-helper';
import ModifyTextHelper from './modify-text-helper';
import { HelperElement, XmlDocument, XmlElement } from '../types/xml-types';
import { XmlHelper } from './xml-helper';
import { XmlElement } from '../types/xml-types';

const map = {
x: { tag: 'a:off', attribute: 'x' },
Expand Down

0 comments on commit d3bc762

Please sign in to comment.