Skip to content

Commit dda0992

Browse files
committed
feature(hasShapes): assert related content / add base class HasShapes;
1 parent 50faf59 commit dda0992

File tree

8 files changed

+181
-204
lines changed

8 files changed

+181
-204
lines changed
4.19 KB
Binary file not shown.

src/classes/has-shapes.ts

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import { XmlRelationshipHelper } from '../helper/xml-relationship-helper';
2+
import IArchive from '../interfaces/iarchive';
3+
import { PresTemplate } from '../interfaces/pres-template';
4+
import { RootPresTemplate } from '../interfaces/root-pres-template';
5+
import { IPresentationProps } from '../interfaces/ipresentation-props';
6+
import {
7+
AutomizerParams,
8+
ImportElement,
9+
ShapeTargetType,
10+
SlideModificationCallback,
11+
StatusTracker,
12+
} from '../types/types';
13+
import { ContentTracker } from '../helper/content-tracker';
14+
import { vd } from '../helper/general-helper';
15+
16+
export default class HasShapes {
17+
/**
18+
* Source template of slide
19+
* @internal
20+
*/
21+
sourceTemplate: PresTemplate;
22+
/**
23+
* Target template of slide
24+
* @internal
25+
*/
26+
targetTemplate: RootPresTemplate;
27+
/**
28+
* Target number of slide
29+
* @internal
30+
*/
31+
targetNumber: number;
32+
/**
33+
* Source number of slide
34+
* @internal
35+
*/
36+
sourceNumber: number;
37+
/**
38+
* Target archive of slide
39+
* @internal
40+
*/
41+
targetArchive: IArchive;
42+
/**
43+
* Source archive of slide
44+
* @internal
45+
*/
46+
sourceArchive: IArchive;
47+
/**
48+
* Source path of slide
49+
* @internal
50+
*/
51+
sourcePath: string;
52+
/**
53+
* Target path of slide
54+
* @internal
55+
*/
56+
targetPath: string;
57+
/**
58+
* Root template of slide
59+
* @internal
60+
*/
61+
modifications: SlideModificationCallback[];
62+
/**
63+
* Modifications of slide relations
64+
* @internal
65+
*/
66+
relModifications: SlideModificationCallback[];
67+
/**
68+
* Import elements of slide
69+
* @internal
70+
*/
71+
importElements: ImportElement[];
72+
/**
73+
* Rels path of slide
74+
* @internal
75+
*/
76+
relsPath: string;
77+
/**
78+
* Target rels path of slide
79+
* @internal
80+
*/
81+
targetRelsPath: string;
82+
/**
83+
* Root of slide
84+
* @internal
85+
*/
86+
root: IPresentationProps;
87+
status: StatusTracker;
88+
content: ContentTracker;
89+
/**
90+
* List of unsupported tags in slide xml
91+
* @internal
92+
*/
93+
unsupportedTags = [
94+
'p:custDataLst',
95+
// 'mc:AlternateContent',
96+
//'a14:imgProps',
97+
];
98+
targetType: ShapeTargetType;
99+
params: AutomizerParams;
100+
101+
constructor() {}
102+
103+
async checkIntegrity(): Promise<void> {
104+
const params = this.targetTemplate.automizer.params;
105+
106+
const info = params.showIntegrityInfo;
107+
const assert = params.assertRelatedContents;
108+
109+
if (info || assert) {
110+
const masterRels = await new XmlRelationshipHelper().initialize(
111+
this.targetArchive,
112+
`${this.targetType}${this.targetNumber}.xml.rels`,
113+
`ppt/${this.targetType}s/_rels`,
114+
);
115+
await masterRels.assertRelatedContent(this.sourceArchive, info, assert);
116+
}
117+
}
118+
}

src/classes/master.ts

Lines changed: 9 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -32,97 +32,17 @@ import IArchive from '../interfaces/iarchive';
3232
import { vd } from '../helper/general-helper';
3333
import { IMaster } from '../interfaces/imaster';
3434
import { XmlRelationshipHelper } from '../helper/xml-relationship-helper';
35+
import HasShapes from './has-shapes';
3536

36-
export class Master implements IMaster {
37-
/**
38-
* Source template of slide
39-
* @internal
40-
*/
41-
sourceTemplate: PresTemplate;
42-
/**
43-
* Target template of slide
44-
* @internal
45-
*/
46-
targetTemplate: RootPresTemplate;
47-
/**
48-
* Target number of slide
49-
* @internal
50-
*/
51-
targetNumber: number;
52-
/**
53-
* Source number of slide
54-
* @internal
55-
*/
56-
sourceNumber: number;
57-
/**
58-
* Target archive of slide
59-
* @internal
60-
*/
61-
targetArchive: IArchive;
62-
/**
63-
* Source archive of slide
64-
* @internal
65-
*/
66-
sourceArchive: IArchive;
67-
/**
68-
* Source path of slide
69-
* @internal
70-
*/
71-
sourcePath: string;
72-
/**
73-
* Target path of slide
74-
* @internal
75-
*/
76-
targetPath: string;
77-
/**
78-
* Modifications of slide
79-
* @internal
80-
*/
81-
modifications: SlideModificationCallback[];
82-
/**
83-
* Import elements of slide
84-
* @internal
85-
*/
86-
importElements: ImportElement[];
87-
/**
88-
* Rels path of slide
89-
* @internal
90-
*/
91-
relsPath: string;
92-
/**
93-
* Root template of slide
94-
* @internal
95-
*/
96-
rootTemplate: RootPresTemplate;
97-
/**
98-
* Root of slide
99-
* @internal
100-
*/
101-
root: IPresentationProps;
102-
/**
103-
* Target rels path of slide
104-
* @internal
105-
*/
106-
targetRelsPath: string;
107-
status: StatusTracker;
108-
content: ContentTracker;
109-
/**
110-
* List of unsupported tags in slide xml
111-
* @internal
112-
*/
113-
unsupportedTags = [
114-
'p:custDataLst',
115-
'mc:AlternateContent',
116-
//'a14:imgProps',
117-
];
118-
37+
export class Master extends HasShapes implements IMaster {
11938
targetType: ShapeTargetType = 'slideMaster';
12039

12140
constructor(params: {
12241
presentation: IPresentationProps;
12342
template: PresTemplate;
12443
sourceIdentifier: SourceIdentifier;
12544
}) {
45+
super();
12646
this.sourceTemplate = params.template;
12747

12848
// ToDo analogue for slideMasters
@@ -210,15 +130,7 @@ export class Master implements IMaster {
210130
await this.applyModifications();
211131
await this.cleanSlide(this.targetPath);
212132

213-
/**
214-
* ToDo: Integrity checks could be used in many places
215-
* to log warnings in case we have skipped out related contents from copying
216-
* to the target archive.
217-
*
218-
* By now, this is disabled because appendToSlideRels() could leave some
219-
* artifacts from unused relations.
220-
*/
221-
// await this.checkIntegrity();
133+
await this.checkIntegrity();
222134
}
223135

224136
async copyRelatedLayouts(): Promise<Target[]> {
@@ -261,7 +173,11 @@ export class Master implements IMaster {
261173
'../slideMasters/slideMaster',
262174
);
263175
layoutToMaster[0].updateTargetIndex(this.targetNumber);
264-
await layoutTargetHelper.checkTargets(this.sourceArchive);
176+
await layoutTargetHelper.assertRelatedContent(
177+
this.sourceArchive,
178+
false,
179+
true,
180+
);
265181

266182
await this.cleanSlide(
267183
`ppt/slideLayouts/slideLayout${nextSlideLayoutNumber}.xml`,
@@ -276,15 +192,6 @@ export class Master implements IMaster {
276192
return targets;
277193
}
278194

279-
async checkIntegrity(): Promise<void> {
280-
const masterToLayout = await new XmlRelationshipHelper().initialize(
281-
this.targetArchive,
282-
`slideMaster${this.targetNumber}.xml.rels`,
283-
`ppt/slideMasters/_rels`,
284-
);
285-
await masterToLayout.checkTargets(this.sourceArchive);
286-
}
287-
288195
async copyThemeFiles() {
289196
const targets = await XmlHelper.getRelationshipTargetsByPrefix(
290197
this.targetArchive,

src/classes/slide.ts

Lines changed: 5 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -32,102 +32,18 @@ import { last, vd } from '../helper/general-helper';
3232
import { Master } from './master';
3333
import { XmlRelationshipHelper } from '../helper/xml-relationship-helper';
3434
import { IMaster } from '../interfaces/imaster';
35+
import HasShapes from './has-shapes';
3536

36-
export class Slide implements ISlide {
37-
/**
38-
* Source template of slide
39-
* @internal
40-
*/
41-
sourceTemplate: PresTemplate;
42-
/**
43-
* Target template of slide
44-
* @internal
45-
*/
46-
targetTemplate: RootPresTemplate;
47-
/**
48-
* Target number of slide
49-
* @internal
50-
*/
51-
targetNumber: number;
52-
/**
53-
* Source number of slide
54-
* @internal
55-
*/
56-
sourceNumber: number;
57-
/**
58-
* Target archive of slide
59-
* @internal
60-
*/
61-
targetArchive: IArchive;
62-
/**
63-
* Source archive of slide
64-
* @internal
65-
*/
66-
sourceArchive: IArchive;
67-
/**
68-
* Source path of slide
69-
* @internal
70-
*/
71-
sourcePath: string;
72-
/**
73-
* Target path of slide
74-
* @internal
75-
*/
76-
targetPath: string;
77-
/**
78-
* Modifications of slide
79-
* @internal
80-
*/
81-
modifications: SlideModificationCallback[];
82-
/**
83-
* Modifications of slide relations
84-
* @internal
85-
*/
86-
relModifications: SlideModificationCallback[];
87-
/**
88-
* Import elements of slide
89-
* @internal
90-
*/
91-
importElements: ImportElement[];
92-
/**
93-
* Rels path of slide
94-
* @internal
95-
*/
96-
relsPath: string;
97-
/**
98-
* Root template of slide
99-
* @internal
100-
*/
101-
rootTemplate: RootPresTemplate;
102-
/**
103-
* Root of slide
104-
* @internal
105-
*/
106-
root: IPresentationProps;
107-
/**
108-
* Target rels path of slide
109-
* @internal
110-
*/
111-
targetRelsPath: string;
112-
status: StatusTracker;
113-
content: ContentTracker;
114-
/**
115-
* List of unsupported tags in slide xml
116-
* @internal
117-
*/
118-
unsupportedTags = [
119-
'p:custDataLst',
120-
//'mc:AlternateContent',
121-
//'a14:imgProps',
122-
];
123-
37+
export class Slide extends HasShapes implements ISlide {
12438
targetType: ShapeTargetType = 'slide';
12539

12640
constructor(params: {
12741
presentation: IPresentationProps;
12842
template: PresTemplate;
12943
slideIdentifier: SourceIdentifier;
13044
}) {
45+
super();
46+
13147
this.sourceTemplate = params.template;
13248
this.sourceNumber = this.getSlideNumber(
13349
params.template,
@@ -218,6 +134,7 @@ export class Slide implements ISlide {
218134
await this.applyModifications();
219135
await this.applyRelModifications();
220136

137+
await this.checkIntegrity();
221138
await this.cleanSlide();
222139

223140
this.status.increment();

0 commit comments

Comments
 (0)