Skip to content

Commit 4a67c00

Browse files
committed
chore(all): improve type recognition; more robust multi relations; placeholder assignment
1 parent c4f7fff commit 4a67c00

File tree

10 files changed

+567
-87
lines changed

10 files changed

+567
-87
lines changed

__tests__/read-shape-type.test.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import Automizer, { XmlElement, XmlHelper } from '../src/index';
2+
import { ModifyShapeHelper } from '../src';
3+
4+
test('read shape type info', async () => {
5+
const automizer = new Automizer({
6+
templateDir: `${__dirname}/pptx-templates`,
7+
outputDir: `${__dirname}/pptx-output`,
8+
});
9+
10+
const pres = automizer
11+
.loadRoot(`RootTemplate.pptx`)
12+
.load(`EmptySlide.pptx`, 'empty')
13+
.load(`ShapeTypesCollection.pptx`, 'collection');
14+
15+
pres.addSlide('collection', 1, async (slide) => {
16+
slide.modifyElement(
17+
'VecorShape (Box with arrow)',
18+
(element: XmlElement) => {
19+
const type = ModifyShapeHelper.getElementVisualType(element);
20+
expect(type).toBe('vectorShape');
21+
},
22+
);
23+
24+
slide.modifyElement('Line (Arrow)', (element: XmlElement) => {
25+
const type = ModifyShapeHelper.getElementVisualType(element);
26+
expect(type).toBe('vectorLine');
27+
});
28+
29+
slide.modifyElement('Table', (element: XmlElement) => {
30+
const type = ModifyShapeHelper.getElementVisualType(element);
31+
expect(type).toBe('table');
32+
});
33+
34+
slide.modifyElement('Textfield', (element: XmlElement) => {
35+
// XmlHelper.dump(element)
36+
const type = ModifyShapeHelper.getElementVisualType(element);
37+
expect(type).toBe('textField');
38+
});
39+
40+
slide.modifyElement('SmartArt (Diagram)', (element: XmlElement) => {
41+
const type = ModifyShapeHelper.getElementVisualType(element);
42+
expect(type).toBe('smartArt');
43+
});
44+
45+
slide.modifyElement('Image', (element: XmlElement) => {
46+
const type = ModifyShapeHelper.getElementVisualType(element);
47+
expect(type).toBe('picture');
48+
});
49+
50+
slide.modifyElement('Chart', (element: XmlElement) => {
51+
const type = ModifyShapeHelper.getElementVisualType(element);
52+
expect(type).toBe('chart');
53+
});
54+
55+
slide.modifyElement('Pictogram', (element: XmlElement) => {
56+
const type = ModifyShapeHelper.getElementVisualType(element);
57+
expect(type).toBe('svgImage');
58+
});
59+
60+
slide.modifyElement('SVG Image', (element: XmlElement) => {
61+
// XmlHelper.dump(element);
62+
const type = ModifyShapeHelper.getElementVisualType(element);
63+
expect(type).toBe('svgImage');
64+
});
65+
});
66+
67+
await pres.write(`read-shape-type.test.pptx`);
68+
});

src/classes/has-shapes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,13 @@ export default class HasShapes {
485485
this.targetType,
486486
);
487487
break;
488+
case ElementType.Diagram:
489+
await new Diagram(info, this.targetType)[info.mode](
490+
this.targetTemplate,
491+
this.targetNumber,
492+
this.targetType,
493+
);
494+
break;
488495
case ElementType.OLEObject:
489496
await new OLEObject(info, this.targetType, this.sourceArchive)[
490497
info.mode

src/classes/shape.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ export class Shape {
178178
this.targetSlideFile,
179179
);
180180

181-
182181
const targetElements = await this.getElementsByRid(
183182
targetSlideXml,
184183
this.sourceRid,
@@ -194,6 +193,10 @@ export class Shape {
194193
}
195194
});
196195

196+
// if(cb && typeof cb === 'function') {
197+
// XmlHelper.dump(targetSlideXml)
198+
// }
199+
197200
XmlHelper.writeXmlToArchive(
198201
this.targetArchive,
199202
this.targetSlideFile,

0 commit comments

Comments
 (0)