pptx-templates 0.3.8 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AI-INSTRUCTOR.md +91 -2
- package/CHANGELOG.md +125 -1
- package/dist/automizer.js +143 -176
- package/dist/automizer.js.map +1 -1
- package/dist/classes/content-type-registry.js +23 -36
- package/dist/classes/content-type-registry.js.map +1 -1
- package/dist/classes/element-importer.js +129 -148
- package/dist/classes/element-importer.js.map +1 -1
- package/dist/classes/has-shapes.js +81 -126
- package/dist/classes/has-shapes.js.map +1 -1
- package/dist/classes/layout.js +47 -67
- package/dist/classes/layout.js.map +1 -1
- package/dist/classes/master.js +70 -89
- package/dist/classes/master.js.map +1 -1
- package/dist/classes/placeholder-normalizer.js +48 -37
- package/dist/classes/placeholder-normalizer.js.map +1 -1
- package/dist/classes/related-content-copier.js +65 -86
- package/dist/classes/related-content-copier.js.map +1 -1
- package/dist/classes/shape.js +79 -110
- package/dist/classes/shape.js.map +1 -1
- package/dist/classes/slide-master-remover.js +108 -130
- package/dist/classes/slide-master-remover.js.map +1 -1
- package/dist/classes/slide-notes-copier.js +24 -41
- package/dist/classes/slide-notes-copier.js.map +1 -1
- package/dist/classes/slide.js +112 -141
- package/dist/classes/slide.js.map +1 -1
- package/dist/classes/template.js +82 -117
- package/dist/classes/template.js.map +1 -1
- package/dist/errors.js +5 -5
- package/dist/errors.js.map +1 -1
- package/dist/extensions/cli/index.js +3 -13
- package/dist/extensions/cli/index.js.map +1 -1
- package/dist/extensions/hide-slide/index.js +48 -46
- package/dist/extensions/hide-slide/index.js.map +1 -1
- package/dist/extensions/master-parts/index.js +36 -49
- package/dist/extensions/master-parts/index.js.map +1 -1
- package/dist/extensions/pptxgenjs-compat/svg-fallback.js +56 -70
- package/dist/extensions/pptxgenjs-compat/svg-fallback.js.map +1 -1
- package/dist/extensions/regexp-escape/index.d.ts +10 -0
- package/dist/extensions/regexp-escape/index.js +15 -0
- package/dist/extensions/regexp-escape/index.js.map +1 -0
- package/dist/extensions/run-merge/index.js +4 -5
- package/dist/extensions/run-merge/index.js.map +1 -1
- package/dist/extensions/shape-geometry/index.d.ts +2 -0
- package/dist/extensions/shape-geometry/index.js +13 -13
- package/dist/extensions/shape-geometry/index.js.map +1 -1
- package/dist/extensions/template-lint/cli.js +49 -41
- package/dist/extensions/template-lint/cli.js.map +1 -1
- package/dist/extensions/template-lint/config.js +18 -10
- package/dist/extensions/template-lint/config.js.map +1 -1
- package/dist/extensions/template-lint/data-model.js +17 -20
- package/dist/extensions/template-lint/data-model.js.map +1 -1
- package/dist/extensions/template-lint/init-cli.js +12 -17
- package/dist/extensions/template-lint/init-cli.js.map +1 -1
- package/dist/extensions/template-lint/lint.js +195 -62
- package/dist/extensions/template-lint/lint.js.map +1 -1
- package/dist/extensions/template-lint/skeleton.js +5 -6
- package/dist/extensions/template-lint/skeleton.js.map +1 -1
- package/dist/extensions/template-lint/usage-cli.js +10 -14
- package/dist/extensions/template-lint/usage-cli.js.map +1 -1
- package/dist/extensions/template-lint/usage.js +8 -9
- package/dist/extensions/template-lint/usage.js.map +1 -1
- package/dist/extensions/template-logic/clone.d.ts +2 -16
- package/dist/extensions/template-logic/clone.js +15 -90
- package/dist/extensions/template-logic/clone.js.map +1 -1
- package/dist/extensions/template-logic/commands.d.ts +8 -0
- package/dist/extensions/template-logic/commands.js +21 -12
- package/dist/extensions/template-logic/commands.js.map +1 -1
- package/dist/extensions/template-logic/expression.d.ts +6 -0
- package/dist/extensions/template-logic/expression.js +56 -54
- package/dist/extensions/template-logic/expression.js.map +1 -1
- package/dist/extensions/template-logic/images.d.ts +14 -0
- package/dist/extensions/template-logic/images.js +277 -49
- package/dist/extensions/template-logic/images.js.map +1 -1
- package/dist/extensions/template-logic/index.js +20 -27
- package/dist/extensions/template-logic/index.js.map +1 -1
- package/dist/extensions/template-logic/list-commands.js +31 -16
- package/dist/extensions/template-logic/list-commands.js.map +1 -1
- package/dist/extensions/template-logic/renderer.d.ts +24 -0
- package/dist/extensions/template-logic/renderer.js +505 -380
- package/dist/extensions/template-logic/renderer.js.map +1 -1
- package/dist/extensions/template-logic/types.d.ts +5 -0
- package/dist/extensions/template-logic/types.js +6 -0
- package/dist/extensions/template-logic/types.js.map +1 -1
- package/dist/extensions/template-render/cli.js +7 -18
- package/dist/extensions/template-render/cli.js.map +1 -1
- package/dist/extensions/template-render/index.js +152 -107
- package/dist/extensions/template-render/index.js.map +1 -1
- package/dist/extensions/template-render/prune.d.ts +14 -0
- package/dist/extensions/template-render/prune.js +131 -0
- package/dist/extensions/template-render/prune.js.map +1 -0
- package/dist/extensions/template-render/zip-text.d.ts +9 -0
- package/dist/extensions/template-render/zip-text.js +27 -0
- package/dist/extensions/template-render/zip-text.js.map +1 -0
- package/dist/extensions/template-render/zip-writer.d.ts +16 -0
- package/dist/extensions/template-render/zip-writer.js +151 -0
- package/dist/extensions/template-render/zip-writer.js.map +1 -0
- package/dist/extensions/text-flow/flow.d.ts +5 -0
- package/dist/extensions/text-flow/flow.js +196 -207
- package/dist/extensions/text-flow/flow.js.map +1 -1
- package/dist/extensions/text-flow/font-file.js +9 -7
- package/dist/extensions/text-flow/font-file.js.map +1 -1
- package/dist/extensions/text-flow/fonts.d.ts +4 -0
- package/dist/extensions/text-flow/fonts.js +45 -22
- package/dist/extensions/text-flow/fonts.js.map +1 -1
- package/dist/extensions/text-flow/layout.js +5 -6
- package/dist/extensions/text-flow/layout.js.map +1 -1
- package/dist/extensions/text-flow/slide-styles.js +18 -22
- package/dist/extensions/text-flow/slide-styles.js.map +1 -1
- package/dist/extensions/text-flow/styles.d.ts +11 -0
- package/dist/extensions/text-flow/styles.js +121 -62
- package/dist/extensions/text-flow/styles.js.map +1 -1
- package/dist/helper/archive/archive-fs.js +102 -138
- package/dist/helper/archive/archive-fs.js.map +1 -1
- package/dist/helper/archive/archive-jszip.js +101 -125
- package/dist/helper/archive/archive-jszip.js.map +1 -1
- package/dist/helper/archive/archive.d.ts +6 -0
- package/dist/helper/archive/archive.js +21 -30
- package/dist/helper/archive/archive.js.map +1 -1
- package/dist/helper/archive/jszip-fast-read.d.ts +19 -0
- package/dist/helper/archive/jszip-fast-read.js +153 -0
- package/dist/helper/archive/jszip-fast-read.js.map +1 -0
- package/dist/helper/compute-src-rect.js +4 -5
- package/dist/helper/compute-src-rect.js.map +1 -1
- package/dist/helper/content-tracker.js +86 -114
- package/dist/helper/content-tracker.js.map +1 -1
- package/dist/helper/count-helper.js +48 -78
- package/dist/helper/count-helper.js.map +1 -1
- package/dist/helper/css-style-parser.js +1 -2
- package/dist/helper/css-style-parser.js.map +1 -1
- package/dist/helper/file-helper.js +30 -48
- package/dist/helper/file-helper.js.map +1 -1
- package/dist/helper/generate/generate-pptxgenjs.js +36 -48
- package/dist/helper/generate/generate-pptxgenjs.js.map +1 -1
- package/dist/helper/html-to-multitext-helper.js +34 -18
- package/dist/helper/html-to-multitext-helper.js.map +1 -1
- package/dist/helper/hyperlink-processor.js +125 -139
- package/dist/helper/hyperlink-processor.js.map +1 -1
- package/dist/helper/jszip-helper.js +23 -32
- package/dist/helper/jszip-helper.js.map +1 -1
- package/dist/helper/layout-index.js +51 -71
- package/dist/helper/layout-index.js.map +1 -1
- package/dist/helper/logger.js +4 -4
- package/dist/helper/logger.js.map +1 -1
- package/dist/helper/media-deduplicator.d.ts +24 -0
- package/dist/helper/media-deduplicator.js +81 -34
- package/dist/helper/media-deduplicator.js.map +1 -1
- package/dist/helper/modify-background-helper.js +46 -46
- package/dist/helper/modify-background-helper.js.map +1 -1
- package/dist/helper/modify-chart-helper.js +597 -591
- package/dist/helper/modify-chart-helper.js.map +1 -1
- package/dist/helper/modify-cleanup-helper.js +112 -112
- package/dist/helper/modify-cleanup-helper.js.map +1 -1
- package/dist/helper/modify-color-helper.js +53 -53
- package/dist/helper/modify-color-helper.js.map +1 -1
- package/dist/helper/modify-helper.js +25 -25
- package/dist/helper/modify-helper.js.map +1 -1
- package/dist/helper/modify-hyperlink-helper.js +143 -154
- package/dist/helper/modify-hyperlink-helper.js.map +1 -1
- package/dist/helper/modify-image-helper.js +121 -132
- package/dist/helper/modify-image-helper.js.map +1 -1
- package/dist/helper/modify-presentation-helper.js +137 -154
- package/dist/helper/modify-presentation-helper.js.map +1 -1
- package/dist/helper/modify-shape-helper.js +262 -262
- package/dist/helper/modify-shape-helper.js.map +1 -1
- package/dist/helper/modify-table-helper.js +84 -84
- package/dist/helper/modify-table-helper.js.map +1 -1
- package/dist/helper/modify-text-helper.js +187 -189
- package/dist/helper/modify-text-helper.js.map +1 -1
- package/dist/helper/modify-xml-helper.js +36 -36
- package/dist/helper/modify-xml-helper.js.map +1 -1
- package/dist/helper/multitext-helper.js +9 -7
- package/dist/helper/multitext-helper.js.map +1 -1
- package/dist/helper/ppt-paths.js +17 -17
- package/dist/helper/ppt-paths.js.map +1 -1
- package/dist/helper/shape-type-detector.js +18 -29
- package/dist/helper/shape-type-detector.js.map +1 -1
- package/dist/helper/text-replace-helper.js +6 -7
- package/dist/helper/text-replace-helper.js.map +1 -1
- package/dist/helper/xml-clone.d.ts +24 -0
- package/dist/helper/xml-clone.js +269 -0
- package/dist/helper/xml-clone.js.map +1 -0
- package/dist/helper/xml-elements.js +17 -20
- package/dist/helper/xml-elements.js.map +1 -1
- package/dist/helper/xml-find.d.ts +4 -0
- package/dist/helper/xml-find.js +48 -0
- package/dist/helper/xml-find.js.map +1 -0
- package/dist/helper/xml-helper.js +99 -134
- package/dist/helper/xml-helper.js.map +1 -1
- package/dist/helper/xml-parse-cache.d.ts +31 -0
- package/dist/helper/xml-parse-cache.js +71 -0
- package/dist/helper/xml-parse-cache.js.map +1 -0
- package/dist/helper/xml-placeholder-helper.js +10 -10
- package/dist/helper/xml-placeholder-helper.js.map +1 -1
- package/dist/helper/xml-relationship-helper.js +120 -144
- package/dist/helper/xml-relationship-helper.js.map +1 -1
- package/dist/helper/xml-serializer.d.ts +2 -0
- package/dist/helper/xml-serializer.js +192 -0
- package/dist/helper/xml-serializer.js.map +1 -0
- package/dist/helper/xml-slide-helper.js +109 -129
- package/dist/helper/xml-slide-helper.js.map +1 -1
- package/dist/helper/xml-template-helper.js +120 -144
- package/dist/helper/xml-template-helper.js.map +1 -1
- package/dist/helper/xmldom-sax-patch.js +52 -2
- package/dist/helper/xmldom-sax-patch.js.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/modify/modify-chart.js +35 -23
- package/dist/modify/modify-chart.js.map +1 -1
- package/dist/modify/modify-table.js +11 -14
- package/dist/modify/modify-table.js.map +1 -1
- package/dist/shapes/chart.js +238 -287
- package/dist/shapes/chart.js.map +1 -1
- package/dist/shapes/diagram.js +73 -104
- package/dist/shapes/diagram.js.map +1 -1
- package/dist/shapes/generic.js +62 -83
- package/dist/shapes/generic.js.map +1 -1
- package/dist/shapes/hyperlink.js +98 -124
- package/dist/shapes/hyperlink.js.map +1 -1
- package/dist/shapes/image.js +112 -151
- package/dist/shapes/image.js.map +1 -1
- package/dist/shapes/ole.js +148 -188
- package/dist/shapes/ole.js.map +1 -1
- package/package.json +3 -4
|
@@ -1,14 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var _a;
|
|
12
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
3
|
const xml_helper_1 = require("./xml-helper");
|
|
14
4
|
const xml_relationship_helper_1 = require("./xml-relationship-helper");
|
|
@@ -17,164 +7,157 @@ const file_helper_1 = require("./file-helper");
|
|
|
17
7
|
const master_parts_1 = require("../extensions/master-parts");
|
|
18
8
|
class ModifyPresentationHelper {
|
|
19
9
|
/**
|
|
20
|
-
*
|
|
21
|
-
* copied to the root template by automizer. We remove all other files.
|
|
10
|
+
* Get Collection of slides
|
|
22
11
|
*/
|
|
23
|
-
static
|
|
24
|
-
return
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
12
|
+
static { this.getSlidesCollection = (xml) => {
|
|
13
|
+
return xml.getElementsByTagName('p:sldId');
|
|
14
|
+
}; }
|
|
15
|
+
static { this.getSlideMastersCollection = (xml) => {
|
|
16
|
+
return xml.getElementsByTagName('p:sldMasterId');
|
|
17
|
+
}; }
|
|
18
|
+
/**
|
|
19
|
+
* Pass an array of slide numbers to define a target sort order.
|
|
20
|
+
* First slide starts by 1.
|
|
21
|
+
* @param order Array of slide numbers, starting by 1
|
|
22
|
+
*/
|
|
23
|
+
static { this.sortSlides = (order) => (xml) => {
|
|
24
|
+
const slides = ModifyPresentationHelper.getSlidesCollection(xml);
|
|
25
|
+
order.map((index, i) => order[i]--);
|
|
26
|
+
xml_helper_1.XmlHelper.sortCollection(slides, order);
|
|
27
|
+
}; }
|
|
28
|
+
/**
|
|
29
|
+
* Pass an array of slide numbers to remove from slide sortation.
|
|
30
|
+
* @param numbers Array of slide numbers, starting by 1
|
|
31
|
+
*/
|
|
32
|
+
static { this.removeSlides = (numbers) => (xml) => {
|
|
33
|
+
const slides = ModifyPresentationHelper.getSlidesCollection(xml);
|
|
34
|
+
numbers.map((index, i) => numbers[i]--);
|
|
35
|
+
for (let i = 0; i <= slides.length; i++) {
|
|
36
|
+
if (numbers.includes(i)) {
|
|
37
|
+
xml_helper_1.XmlHelper.remove(slides[i]);
|
|
28
38
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
}
|
|
40
|
+
}; }
|
|
41
|
+
/**
|
|
42
|
+
* Set ids to prevent corrupted pptx.
|
|
43
|
+
* Must start with 256 and increment by one.
|
|
44
|
+
*/
|
|
45
|
+
static { this.normalizeSlideIds = (xml) => {
|
|
46
|
+
const slides = ModifyPresentationHelper.getSlidesCollection(xml);
|
|
47
|
+
const firstId = 256;
|
|
48
|
+
xml_helper_1.XmlHelper.modifyCollection(slides, (slide, i) => {
|
|
49
|
+
slide.setAttribute('id', String(firstId + i));
|
|
50
|
+
});
|
|
51
|
+
}; }
|
|
52
|
+
/**
|
|
53
|
+
* Smallest id PowerPoint accepts for `p:sldMasterId` / `p:sldLayoutId`
|
|
54
|
+
* (ids below 2^31 trigger the repair prompt; see #85).
|
|
55
|
+
*/
|
|
56
|
+
static { this.MIN_SLIDE_MASTER_ID = 2147483648; }
|
|
57
|
+
/**
|
|
58
|
+
* Update slideMaster ids to prevent corrupted pptx.
|
|
59
|
+
* - Take first slideMaster id from presentation.xml to start (raised to
|
|
60
|
+
* `MIN_SLIDE_MASTER_ID` if it is lower),
|
|
61
|
+
* - then update incremental ids of each p:sldLayoutId in the master part
|
|
62
|
+
* the entry's relationship points at (starting by slideMasterId + 1)
|
|
63
|
+
* - and update next slideMaster id with previous p:sldLayoutId + 1
|
|
64
|
+
*
|
|
65
|
+
* p:sldMasterId-ids and p:sldLayoutId-ids need to be in a row, otherwise
|
|
66
|
+
* PowerPoint will complain on any p:sldLayoutId-id lower than its
|
|
67
|
+
* corresponding slideMaster-id. omg.
|
|
68
|
+
*/
|
|
69
|
+
static { this.normalizeSlideMasterIds = async (xml, i, archive) => {
|
|
70
|
+
const slides = ModifyPresentationHelper.getSlideMastersCollection(xml);
|
|
71
|
+
// The list entries and the master part numbers do not line up once a
|
|
72
|
+
// master has been removed: resolve each entry through its relationship.
|
|
73
|
+
const masterTargets = await xml_relationship_helper_1.XmlRelationshipHelper.getTargetsByRelationshipType(archive, ppt_paths_1.PptPaths.presentationRels, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster');
|
|
74
|
+
let currentId;
|
|
75
|
+
await xml_helper_1.XmlHelper.modifyCollectionAsync(slides, async (slide, i) => {
|
|
76
|
+
const masterTarget = masterTargets.find((target) => target.rId === slide.getAttribute('r:id'));
|
|
77
|
+
const masterId = masterTarget ? masterTarget.number : i + 1;
|
|
78
|
+
if (i === 0) {
|
|
79
|
+
currentId = Math.max(Number(slide.getAttribute('id')) || 0, ModifyPresentationHelper.MIN_SLIDE_MASTER_ID);
|
|
50
80
|
}
|
|
81
|
+
slide.setAttribute('id', String(currentId));
|
|
82
|
+
currentId++;
|
|
83
|
+
const slideMasterXml = await xml_helper_1.XmlHelper.getXmlFromArchive(archive, ppt_paths_1.PptPaths.slideMaster(masterId));
|
|
84
|
+
const slideLayouts = slideMasterXml.getElementsByTagName('p:sldLayoutId');
|
|
85
|
+
xml_helper_1.XmlHelper.modifyCollection(slideLayouts, (slideLayout) => {
|
|
86
|
+
slideLayout.setAttribute('id', String(currentId));
|
|
87
|
+
currentId++;
|
|
88
|
+
});
|
|
51
89
|
});
|
|
90
|
+
}; }
|
|
91
|
+
/**
|
|
92
|
+
* The content tracker's files include all files that have been
|
|
93
|
+
* copied to the root template by automizer. We remove all other files.
|
|
94
|
+
*/
|
|
95
|
+
static async removeUnusedFiles(xml, i, archive) {
|
|
96
|
+
const tracker = archive.contentTracker;
|
|
97
|
+
if (!tracker) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
// Need to skip some dirs until masters and layouts are handled properly.
|
|
101
|
+
// ppt/drawings is tracked for image collection only (see
|
|
102
|
+
// removedUnusedImages); it also holds vml drawings that may belong to
|
|
103
|
+
// masters and layouts, so it is left alone here.
|
|
104
|
+
const skipDirs = [
|
|
105
|
+
'ppt/slideMasters',
|
|
106
|
+
'ppt/slideMasters/_rels',
|
|
107
|
+
'ppt/slideLayouts',
|
|
108
|
+
'ppt/slideLayouts/_rels',
|
|
109
|
+
'ppt/drawings',
|
|
110
|
+
];
|
|
111
|
+
// Masters and layouts stay, so the charts and embeddings they use stay too.
|
|
112
|
+
const ofMasters = await (0, master_parts_1.partsOfMastersAndLayouts)(archive);
|
|
113
|
+
for (const dir in tracker.files) {
|
|
114
|
+
if (skipDirs.includes(dir)) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const requiredFiles = [...tracker.files[dir], ...(ofMasters[dir] || [])];
|
|
118
|
+
await file_helper_1.FileHelper.removeFromDirectory(archive, dir, (file) => {
|
|
119
|
+
return !requiredFiles.includes(file.relativePath);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
52
122
|
}
|
|
53
123
|
/**
|
|
54
124
|
* PPT won't complain about unused items in [Content_Types].xml,
|
|
55
125
|
* but we remove them anyway in case the file mentioned in PartName-
|
|
56
126
|
* attribute does not exist.
|
|
57
127
|
*/
|
|
58
|
-
static removeUnusedContentTypes(xml, i, archive) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
},
|
|
69
|
-
});
|
|
128
|
+
static async removeUnusedContentTypes(xml, i, archive) {
|
|
129
|
+
await xml_helper_1.XmlHelper.removeIf({
|
|
130
|
+
archive,
|
|
131
|
+
file: `[Content_Types].xml`,
|
|
132
|
+
tag: 'Override',
|
|
133
|
+
clause: (xml, element) => {
|
|
134
|
+
const filename = element.getAttribute('PartName').substring(1);
|
|
135
|
+
const exists = file_helper_1.FileHelper.fileExistsInArchive(archive, filename);
|
|
136
|
+
return exists ? false : true;
|
|
137
|
+
},
|
|
70
138
|
});
|
|
71
139
|
}
|
|
72
|
-
static removedUnusedImages(xml, i, archive) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
!keepFiles.includes(info.base));
|
|
92
|
-
});
|
|
140
|
+
static async removedUnusedImages(xml, i, archive) {
|
|
141
|
+
const tracker = archive.contentTracker;
|
|
142
|
+
if (!tracker) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
await tracker.analyzeContents(archive);
|
|
146
|
+
const extensions = ['jpg', 'jpeg', 'png', 'gif', 'svg', 'emf'];
|
|
147
|
+
const keepFiles = [];
|
|
148
|
+
await tracker.collect('ppt/slides', 'image', keepFiles);
|
|
149
|
+
await tracker.collect('ppt/slideMasters', 'image', keepFiles);
|
|
150
|
+
await tracker.collect('ppt/slideLayouts', 'image', keepFiles);
|
|
151
|
+
// Images referenced by copied charts (e.g. scatter point markers) and by
|
|
152
|
+
// their user shapes drawings (e.g. a picture in a chart annotation).
|
|
153
|
+
await tracker.collect('ppt/charts', 'image', keepFiles);
|
|
154
|
+
await tracker.collect('ppt/drawings', 'image', keepFiles);
|
|
155
|
+
await file_helper_1.FileHelper.removeFromDirectory(archive, 'ppt/media', (file) => {
|
|
156
|
+
const info = file_helper_1.FileHelper.getFileInfo(file.name);
|
|
157
|
+
return (extensions.includes(info.extension.toLowerCase()) &&
|
|
158
|
+
!keepFiles.includes(info.base));
|
|
93
159
|
});
|
|
94
160
|
}
|
|
95
161
|
}
|
|
96
|
-
_a = ModifyPresentationHelper;
|
|
97
|
-
/**
|
|
98
|
-
* Get Collection of slides
|
|
99
|
-
*/
|
|
100
|
-
ModifyPresentationHelper.getSlidesCollection = (xml) => {
|
|
101
|
-
return xml.getElementsByTagName('p:sldId');
|
|
102
|
-
};
|
|
103
|
-
ModifyPresentationHelper.getSlideMastersCollection = (xml) => {
|
|
104
|
-
return xml.getElementsByTagName('p:sldMasterId');
|
|
105
|
-
};
|
|
106
|
-
/**
|
|
107
|
-
* Pass an array of slide numbers to define a target sort order.
|
|
108
|
-
* First slide starts by 1.
|
|
109
|
-
* @param order Array of slide numbers, starting by 1
|
|
110
|
-
*/
|
|
111
|
-
ModifyPresentationHelper.sortSlides = (order) => (xml) => {
|
|
112
|
-
const slides = _a.getSlidesCollection(xml);
|
|
113
|
-
order.map((index, i) => order[i]--);
|
|
114
|
-
xml_helper_1.XmlHelper.sortCollection(slides, order);
|
|
115
|
-
};
|
|
116
|
-
/**
|
|
117
|
-
* Pass an array of slide numbers to remove from slide sortation.
|
|
118
|
-
* @param numbers Array of slide numbers, starting by 1
|
|
119
|
-
*/
|
|
120
|
-
ModifyPresentationHelper.removeSlides = (numbers) => (xml) => {
|
|
121
|
-
const slides = _a.getSlidesCollection(xml);
|
|
122
|
-
numbers.map((index, i) => numbers[i]--);
|
|
123
|
-
for (let i = 0; i <= slides.length; i++) {
|
|
124
|
-
if (numbers.includes(i)) {
|
|
125
|
-
xml_helper_1.XmlHelper.remove(slides[i]);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
/**
|
|
130
|
-
* Set ids to prevent corrupted pptx.
|
|
131
|
-
* Must start with 256 and increment by one.
|
|
132
|
-
*/
|
|
133
|
-
ModifyPresentationHelper.normalizeSlideIds = (xml) => {
|
|
134
|
-
const slides = _a.getSlidesCollection(xml);
|
|
135
|
-
const firstId = 256;
|
|
136
|
-
xml_helper_1.XmlHelper.modifyCollection(slides, (slide, i) => {
|
|
137
|
-
slide.setAttribute('id', String(firstId + i));
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
/**
|
|
141
|
-
* Smallest id PowerPoint accepts for `p:sldMasterId` / `p:sldLayoutId`
|
|
142
|
-
* (ids below 2^31 trigger the repair prompt; see #85).
|
|
143
|
-
*/
|
|
144
|
-
ModifyPresentationHelper.MIN_SLIDE_MASTER_ID = 2147483648;
|
|
145
|
-
/**
|
|
146
|
-
* Update slideMaster ids to prevent corrupted pptx.
|
|
147
|
-
* - Take first slideMaster id from presentation.xml to start (raised to
|
|
148
|
-
* `MIN_SLIDE_MASTER_ID` if it is lower),
|
|
149
|
-
* - then update incremental ids of each p:sldLayoutId in the master part
|
|
150
|
-
* the entry's relationship points at (starting by slideMasterId + 1)
|
|
151
|
-
* - and update next slideMaster id with previous p:sldLayoutId + 1
|
|
152
|
-
*
|
|
153
|
-
* p:sldMasterId-ids and p:sldLayoutId-ids need to be in a row, otherwise
|
|
154
|
-
* PowerPoint will complain on any p:sldLayoutId-id lower than its
|
|
155
|
-
* corresponding slideMaster-id. omg.
|
|
156
|
-
*/
|
|
157
|
-
ModifyPresentationHelper.normalizeSlideMasterIds = (xml, i, archive) => __awaiter(void 0, void 0, void 0, function* () {
|
|
158
|
-
const slides = _a.getSlideMastersCollection(xml);
|
|
159
|
-
// The list entries and the master part numbers do not line up once a
|
|
160
|
-
// master has been removed: resolve each entry through its relationship.
|
|
161
|
-
const masterTargets = yield xml_relationship_helper_1.XmlRelationshipHelper.getTargetsByRelationshipType(archive, ppt_paths_1.PptPaths.presentationRels, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster');
|
|
162
|
-
let currentId;
|
|
163
|
-
yield xml_helper_1.XmlHelper.modifyCollectionAsync(slides, (slide, i) => __awaiter(void 0, void 0, void 0, function* () {
|
|
164
|
-
const masterTarget = masterTargets.find((target) => target.rId === slide.getAttribute('r:id'));
|
|
165
|
-
const masterId = masterTarget ? masterTarget.number : i + 1;
|
|
166
|
-
if (i === 0) {
|
|
167
|
-
currentId = Math.max(Number(slide.getAttribute('id')) || 0, _a.MIN_SLIDE_MASTER_ID);
|
|
168
|
-
}
|
|
169
|
-
slide.setAttribute('id', String(currentId));
|
|
170
|
-
currentId++;
|
|
171
|
-
const slideMasterXml = yield xml_helper_1.XmlHelper.getXmlFromArchive(archive, ppt_paths_1.PptPaths.slideMaster(masterId));
|
|
172
|
-
const slideLayouts = slideMasterXml.getElementsByTagName('p:sldLayoutId');
|
|
173
|
-
xml_helper_1.XmlHelper.modifyCollection(slideLayouts, (slideLayout) => {
|
|
174
|
-
slideLayout.setAttribute('id', String(currentId));
|
|
175
|
-
currentId++;
|
|
176
|
-
});
|
|
177
|
-
}));
|
|
178
|
-
});
|
|
179
162
|
exports.default = ModifyPresentationHelper;
|
|
180
163
|
//# sourceMappingURL=modify-presentation-helper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modify-presentation-helper.js","sourceRoot":"","sources":["../../src/helper/modify-presentation-helper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"modify-presentation-helper.js","sourceRoot":"","sources":["../../src/helper/modify-presentation-helper.ts"],"names":[],"mappings":";;AAAA,6CAAyC;AACzC,uEAAkE;AAClE,2CAAuC;AACvC,+CAA2C;AAG3C,6DAAsE;AAEtE,MAAqB,wBAAwB;IAC3C;;OAEG;aACI,wBAAmB,GAAG,CAAC,GAAgB,EAAE,EAAE;QAChD,OAAO,GAAG,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC;IAC7C,CAAC,CAAC;aACK,8BAAyB,GAAG,CAAC,GAAgB,EAAE,EAAE;QACtD,OAAO,GAAG,CAAC,oBAAoB,CAAC,eAAe,CAAC,CAAC;IACnD,CAAC,CAAC;IAEF;;;;OAIG;aACI,eAAU,GAAG,CAAC,KAAe,EAAE,EAAE,CAAC,CAAC,GAAgB,EAAE,EAAE;QAC5D,MAAM,MAAM,GAAG,wBAAwB,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;QACjE,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACpC,sBAAS,CAAC,cAAc,CAAC,MAA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