pptx-templates 0.0.0-stage → 0.1.1
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 +2253 -0
- package/CHANGELOG.md +56 -0
- package/LICENSE +23 -0
- package/README.md +84 -2
- package/dist/automizer.d.ts +224 -0
- package/dist/automizer.js +704 -0
- package/dist/automizer.js.map +1 -0
- package/dist/classes/content-type-registry.d.ts +46 -0
- package/dist/classes/content-type-registry.js +170 -0
- package/dist/classes/content-type-registry.js.map +1 -0
- package/dist/classes/element-importer.d.ts +49 -0
- package/dist/classes/element-importer.js +254 -0
- package/dist/classes/element-importer.js.map +1 -0
- package/dist/classes/has-shapes.d.ts +286 -0
- package/dist/classes/has-shapes.js +385 -0
- package/dist/classes/has-shapes.js.map +1 -0
- package/dist/classes/layout.d.ts +42 -0
- package/dist/classes/layout.js +113 -0
- package/dist/classes/layout.js.map +1 -0
- package/dist/classes/master.d.ts +45 -0
- package/dist/classes/master.js +146 -0
- package/dist/classes/master.js.map +1 -0
- package/dist/classes/placeholder-normalizer.d.ts +42 -0
- package/dist/classes/placeholder-normalizer.js +136 -0
- package/dist/classes/placeholder-normalizer.js.map +1 -0
- package/dist/classes/related-content-copier.d.ts +18 -0
- package/dist/classes/related-content-copier.js +114 -0
- package/dist/classes/related-content-copier.js.map +1 -0
- package/dist/classes/shape.d.ts +62 -0
- package/dist/classes/shape.js +194 -0
- package/dist/classes/shape.js.map +1 -0
- package/dist/classes/slide-master-remover.d.ts +44 -0
- package/dist/classes/slide-master-remover.js +201 -0
- package/dist/classes/slide-master-remover.js.map +1 -0
- package/dist/classes/slide-notes-copier.d.ts +26 -0
- package/dist/classes/slide-notes-copier.js +76 -0
- package/dist/classes/slide-notes-copier.js.map +1 -0
- package/dist/classes/slide.d.ts +91 -0
- package/dist/classes/slide.js +286 -0
- package/dist/classes/slide.js.map +1 -0
- package/dist/classes/template.d.ts +137 -0
- package/dist/classes/template.js +311 -0
- package/dist/classes/template.js.map +1 -0
- package/dist/constants/constants.d.ts +11 -0
- package/dist/constants/constants.js +182 -0
- package/dist/constants/constants.js.map +1 -0
- package/dist/enums/chart-type.d.ts +11 -0
- package/dist/enums/chart-type.js +16 -0
- package/dist/enums/chart-type.js.map +1 -0
- package/dist/enums/content-type-map.d.ts +16 -0
- package/dist/enums/content-type-map.js +23 -0
- package/dist/enums/content-type-map.js.map +1 -0
- package/dist/enums/element-type.d.ts +14 -0
- package/dist/enums/element-type.js +20 -0
- package/dist/enums/element-type.js.map +1 -0
- package/dist/errors.d.ts +81 -0
- package/dist/errors.js +100 -0
- package/dist/errors.js.map +1 -0
- package/dist/extensions/index.d.ts +5 -0
- package/dist/extensions/index.js +31 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/pptxgenjs-compat/img-broken-png.d.ts +5 -0
- package/dist/extensions/pptxgenjs-compat/img-broken-png.js +9 -0
- package/dist/extensions/pptxgenjs-compat/img-broken-png.js.map +1 -0
- package/dist/extensions/pptxgenjs-compat/index.d.ts +5 -0
- package/dist/extensions/pptxgenjs-compat/index.js +10 -0
- package/dist/extensions/pptxgenjs-compat/index.js.map +1 -0
- package/dist/extensions/pptxgenjs-compat/svg-fallback.d.ts +14 -0
- package/dist/extensions/pptxgenjs-compat/svg-fallback.js +139 -0
- package/dist/extensions/pptxgenjs-compat/svg-fallback.js.map +1 -0
- package/dist/extensions/run-merge/index.d.ts +13 -0
- package/dist/extensions/run-merge/index.js +89 -0
- package/dist/extensions/run-merge/index.js.map +1 -0
- package/dist/extensions/template-logic/commands.d.ts +22 -0
- package/dist/extensions/template-logic/commands.js +83 -0
- package/dist/extensions/template-logic/commands.js.map +1 -0
- package/dist/extensions/template-logic/expression.d.ts +61 -0
- package/dist/extensions/template-logic/expression.js +499 -0
- package/dist/extensions/template-logic/expression.js.map +1 -0
- package/dist/extensions/template-logic/images.d.ts +26 -0
- package/dist/extensions/template-logic/images.js +183 -0
- package/dist/extensions/template-logic/images.js.map +1 -0
- package/dist/extensions/template-logic/index.d.ts +14 -0
- package/dist/extensions/template-logic/index.js +64 -0
- package/dist/extensions/template-logic/index.js.map +1 -0
- package/dist/extensions/template-logic/list-commands.d.ts +9 -0
- package/dist/extensions/template-logic/list-commands.js +72 -0
- package/dist/extensions/template-logic/list-commands.js.map +1 -0
- package/dist/extensions/template-logic/renderer.d.ts +85 -0
- package/dist/extensions/template-logic/renderer.js +867 -0
- package/dist/extensions/template-logic/renderer.js.map +1 -0
- package/dist/extensions/template-logic/types.d.ts +62 -0
- package/dist/extensions/template-logic/types.js +3 -0
- package/dist/extensions/template-logic/types.js.map +1 -0
- package/dist/helper/archive/archive-fs.d.ts +45 -0
- package/dist/helper/archive/archive-fs.js +206 -0
- package/dist/helper/archive/archive-fs.js.map +1 -0
- package/dist/helper/archive/archive-jszip.d.ts +31 -0
- package/dist/helper/archive/archive-jszip.js +173 -0
- package/dist/helper/archive/archive-jszip.js.map +1 -0
- package/dist/helper/archive/archive.d.ts +27 -0
- package/dist/helper/archive/archive.js +78 -0
- package/dist/helper/archive/archive.js.map +1 -0
- package/dist/helper/cell-id-helper.d.ts +25 -0
- package/dist/helper/cell-id-helper.js +95 -0
- package/dist/helper/cell-id-helper.js.map +1 -0
- package/dist/helper/compute-src-rect.d.ts +9 -0
- package/dist/helper/compute-src-rect.js +52 -0
- package/dist/helper/compute-src-rect.js.map +1 -0
- package/dist/helper/content-tracker.d.ts +31 -0
- package/dist/helper/content-tracker.js +227 -0
- package/dist/helper/content-tracker.js.map +1 -0
- package/dist/helper/count-helper.d.ts +33 -0
- package/dist/helper/count-helper.js +140 -0
- package/dist/helper/count-helper.js.map +1 -0
- package/dist/helper/css-style-parser.d.ts +52 -0
- package/dist/helper/css-style-parser.js +246 -0
- package/dist/helper/css-style-parser.js.map +1 -0
- package/dist/helper/file-helper.d.ts +36 -0
- package/dist/helper/file-helper.js +150 -0
- package/dist/helper/file-helper.js.map +1 -0
- package/dist/helper/general-helper.d.ts +6 -0
- package/dist/helper/general-helper.js +34 -0
- package/dist/helper/general-helper.js.map +1 -0
- package/dist/helper/generate/generate-pptxgenjs.d.ts +37 -0
- package/dist/helper/generate/generate-pptxgenjs.js +134 -0
- package/dist/helper/generate/generate-pptxgenjs.js.map +1 -0
- package/dist/helper/html-to-multitext-helper.d.ts +84 -0
- package/dist/helper/html-to-multitext-helper.js +490 -0
- package/dist/helper/html-to-multitext-helper.js.map +1 -0
- package/dist/helper/hyperlink-processor.d.ts +54 -0
- package/dist/helper/hyperlink-processor.js +289 -0
- package/dist/helper/hyperlink-processor.js.map +1 -0
- package/dist/helper/image-dimensions.d.ts +21 -0
- package/dist/helper/image-dimensions.js +202 -0
- package/dist/helper/image-dimensions.js.map +1 -0
- package/dist/helper/jszip-helper.d.ts +21 -0
- package/dist/helper/jszip-helper.js +162 -0
- package/dist/helper/jszip-helper.js.map +1 -0
- package/dist/helper/layout-index.d.ts +55 -0
- package/dist/helper/layout-index.js +155 -0
- package/dist/helper/layout-index.js.map +1 -0
- package/dist/helper/logger.d.ts +53 -0
- package/dist/helper/logger.js +73 -0
- package/dist/helper/logger.js.map +1 -0
- package/dist/helper/media-deduplicator.d.ts +42 -0
- package/dist/helper/media-deduplicator.js +88 -0
- package/dist/helper/media-deduplicator.js.map +1 -0
- package/dist/helper/modify-background-helper.d.ts +19 -0
- package/dist/helper/modify-background-helper.js +59 -0
- package/dist/helper/modify-background-helper.js.map +1 -0
- package/dist/helper/modify-chart-helper.d.ts +159 -0
- package/dist/helper/modify-chart-helper.js +642 -0
- package/dist/helper/modify-chart-helper.js.map +1 -0
- package/dist/helper/modify-cleanup-helper.d.ts +69 -0
- package/dist/helper/modify-cleanup-helper.js +343 -0
- package/dist/helper/modify-cleanup-helper.js.map +1 -0
- package/dist/helper/modify-color-helper.d.ts +35 -0
- package/dist/helper/modify-color-helper.js +211 -0
- package/dist/helper/modify-color-helper.js.map +1 -0
- package/dist/helper/modify-helper.d.ts +23 -0
- package/dist/helper/modify-helper.js +61 -0
- package/dist/helper/modify-helper.js.map +1 -0
- package/dist/helper/modify-hyperlink-element.d.ts +9 -0
- package/dist/helper/modify-hyperlink-element.js +34 -0
- package/dist/helper/modify-hyperlink-element.js.map +1 -0
- package/dist/helper/modify-hyperlink-helper.d.ts +42 -0
- package/dist/helper/modify-hyperlink-helper.js +258 -0
- package/dist/helper/modify-hyperlink-helper.js.map +1 -0
- package/dist/helper/modify-image-helper.d.ts +23 -0
- package/dist/helper/modify-image-helper.js +157 -0
- package/dist/helper/modify-image-helper.js.map +1 -0
- package/dist/helper/modify-presentation-helper.d.ts +55 -0
- package/dist/helper/modify-presentation-helper.js +177 -0
- package/dist/helper/modify-presentation-helper.js.map +1 -0
- package/dist/helper/modify-shape-helper.d.ts +111 -0
- package/dist/helper/modify-shape-helper.js +340 -0
- package/dist/helper/modify-shape-helper.js.map +1 -0
- package/dist/helper/modify-table-helper.d.ts +11 -0
- package/dist/helper/modify-table-helper.js +100 -0
- package/dist/helper/modify-table-helper.js.map +1 -0
- package/dist/helper/modify-text-helper.d.ts +62 -0
- package/dist/helper/modify-text-helper.js +244 -0
- package/dist/helper/modify-text-helper.js.map +1 -0
- package/dist/helper/modify-xml-helper.d.ts +52 -0
- package/dist/helper/modify-xml-helper.js +305 -0
- package/dist/helper/modify-xml-helper.js.map +1 -0
- package/dist/helper/multitext-helper.d.ts +116 -0
- package/dist/helper/multitext-helper.js +462 -0
- package/dist/helper/multitext-helper.js.map +1 -0
- package/dist/helper/ppt-paths.d.ts +76 -0
- package/dist/helper/ppt-paths.js +116 -0
- package/dist/helper/ppt-paths.js.map +1 -0
- package/dist/helper/shape-type-detector.d.ts +34 -0
- package/dist/helper/shape-type-detector.js +99 -0
- package/dist/helper/shape-type-detector.js.map +1 -0
- package/dist/helper/text-replace-helper.d.ts +30 -0
- package/dist/helper/text-replace-helper.js +149 -0
- package/dist/helper/text-replace-helper.js.map +1 -0
- package/dist/helper/xml/lnLRTB.d.ts +1 -0
- package/dist/helper/xml/lnLRTB.js +62 -0
- package/dist/helper/xml/lnLRTB.js.map +1 -0
- package/dist/helper/xml/prstGeom.d.ts +1 -0
- package/dist/helper/xml/prstGeom.js +11 -0
- package/dist/helper/xml/prstGeom.js.map +1 -0
- package/dist/helper/xml-elements.d.ts +134 -0
- package/dist/helper/xml-elements.js +538 -0
- package/dist/helper/xml-elements.js.map +1 -0
- package/dist/helper/xml-helper.d.ts +120 -0
- package/dist/helper/xml-helper.js +495 -0
- package/dist/helper/xml-helper.js.map +1 -0
- package/dist/helper/xml-placeholder-helper.d.ts +92 -0
- package/dist/helper/xml-placeholder-helper.js +454 -0
- package/dist/helper/xml-placeholder-helper.js.map +1 -0
- package/dist/helper/xml-pretty-print.d.ts +17 -0
- package/dist/helper/xml-pretty-print.js +88 -0
- package/dist/helper/xml-pretty-print.js.map +1 -0
- package/dist/helper/xml-relationship-helper.d.ts +103 -0
- package/dist/helper/xml-relationship-helper.js +397 -0
- package/dist/helper/xml-relationship-helper.js.map +1 -0
- package/dist/helper/xml-slide-helper.d.ts +107 -0
- package/dist/helper/xml-slide-helper.js +676 -0
- package/dist/helper/xml-slide-helper.js.map +1 -0
- package/dist/helper/xml-template-helper.d.ts +42 -0
- package/dist/helper/xml-template-helper.js +252 -0
- package/dist/helper/xml-template-helper.js.map +1 -0
- package/dist/helper/xmldom-sax-patch.d.ts +18 -0
- package/dist/helper/xmldom-sax-patch.js +58 -0
- package/dist/helper/xmldom-sax-patch.js.map +1 -0
- package/dist/index.d.ts +81 -0
- package/dist/index.js +177 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/iarchive.d.ts +43 -0
- package/dist/interfaces/iarchive.js +3 -0
- package/dist/interfaces/iarchive.js.map +1 -0
- package/dist/interfaces/ichart.d.ts +7 -0
- package/dist/interfaces/ichart.js +3 -0
- package/dist/interfaces/ichart.js.map +1 -0
- package/dist/interfaces/icounter.d.ts +7 -0
- package/dist/interfaces/icounter.js +3 -0
- package/dist/interfaces/icounter.js.map +1 -0
- package/dist/interfaces/igenerator.d.ts +4 -0
- package/dist/interfaces/igenerator.js +3 -0
- package/dist/interfaces/igenerator.js.map +1 -0
- package/dist/interfaces/iimage.d.ts +7 -0
- package/dist/interfaces/iimage.js +3 -0
- package/dist/interfaces/iimage.js.map +1 -0
- package/dist/interfaces/ilayout.d.ts +14 -0
- package/dist/interfaces/ilayout.js +3 -0
- package/dist/interfaces/ilayout.js.map +1 -0
- package/dist/interfaces/imaster.d.ts +15 -0
- package/dist/interfaces/imaster.js +3 -0
- package/dist/interfaces/imaster.js.map +1 -0
- package/dist/interfaces/imulti-text.d.ts +50 -0
- package/dist/interfaces/imulti-text.js +3 -0
- package/dist/interfaces/imulti-text.js.map +1 -0
- package/dist/interfaces/ipptxgenjs-slide.d.ts +40 -0
- package/dist/interfaces/ipptxgenjs-slide.js +3 -0
- package/dist/interfaces/ipptxgenjs-slide.js.map +1 -0
- package/dist/interfaces/ipresentation-props.d.ts +16 -0
- package/dist/interfaces/ipresentation-props.js +3 -0
- package/dist/interfaces/ipresentation-props.js.map +1 -0
- package/dist/interfaces/ishape-action.d.ts +18 -0
- package/dist/interfaces/ishape-action.js +3 -0
- package/dist/interfaces/ishape-action.js.map +1 -0
- package/dist/interfaces/ishape.d.ts +5 -0
- package/dist/interfaces/ishape.js +3 -0
- package/dist/interfaces/ishape.js.map +1 -0
- package/dist/interfaces/islide.d.ts +71 -0
- package/dist/interfaces/islide.js +3 -0
- package/dist/interfaces/islide.js.map +1 -0
- package/dist/interfaces/itemplate.d.ts +9 -0
- package/dist/interfaces/itemplate.js +3 -0
- package/dist/interfaces/itemplate.js.map +1 -0
- package/dist/interfaces/pres-template.d.ts +9 -0
- package/dist/interfaces/pres-template.js +3 -0
- package/dist/interfaces/pres-template.js.map +1 -0
- package/dist/interfaces/root-pres-template.d.ts +38 -0
- package/dist/interfaces/root-pres-template.js +3 -0
- package/dist/interfaces/root-pres-template.js.map +1 -0
- package/dist/modify/modify-chart.d.ts +74 -0
- package/dist/modify/modify-chart.js +753 -0
- package/dist/modify/modify-chart.js.map +1 -0
- package/dist/modify/modify-table.d.ts +64 -0
- package/dist/modify/modify-table.js +435 -0
- package/dist/modify/modify-table.js.map +1 -0
- package/dist/shapes/chart.d.ts +91 -0
- package/dist/shapes/chart.js +437 -0
- package/dist/shapes/chart.js.map +1 -0
- package/dist/shapes/diagram.d.ts +33 -0
- package/dist/shapes/diagram.js +167 -0
- package/dist/shapes/diagram.js.map +1 -0
- package/dist/shapes/generic.d.ts +27 -0
- package/dist/shapes/generic.js +118 -0
- package/dist/shapes/generic.js.map +1 -0
- package/dist/shapes/hyperlink.d.ts +27 -0
- package/dist/shapes/hyperlink.js +193 -0
- package/dist/shapes/hyperlink.js.map +1 -0
- package/dist/shapes/image.d.ts +47 -0
- package/dist/shapes/image.js +244 -0
- package/dist/shapes/image.js.map +1 -0
- package/dist/shapes/ole.d.ts +30 -0
- package/dist/shapes/ole.js +237 -0
- package/dist/shapes/ole.js.map +1 -0
- package/dist/types/chart-types.d.ts +115 -0
- package/dist/types/chart-types.js +3 -0
- package/dist/types/chart-types.js.map +1 -0
- package/dist/types/modify-types.d.ts +128 -0
- package/dist/types/modify-types.js +3 -0
- package/dist/types/modify-types.js.map +1 -0
- package/dist/types/shape-types.d.ts +40 -0
- package/dist/types/shape-types.js +3 -0
- package/dist/types/shape-types.js.map +1 -0
- package/dist/types/table-types.d.ts +38 -0
- package/dist/types/table-types.js +3 -0
- package/dist/types/table-types.js.map +1 -0
- package/dist/types/types.d.ts +317 -0
- package/dist/types/types.js +16 -0
- package/dist/types/types.js.map +1 -0
- package/dist/types/xml-types.d.ts +168 -0
- package/dist/types/xml-types.js +3 -0
- package/dist/types/xml-types.js.map +1 -0
- package/package.json +92 -4
|
@@ -0,0 +1,704 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
const slide_1 = require("./classes/slide");
|
|
49
|
+
const types_1 = require("./types/types");
|
|
50
|
+
const template_1 = require("./classes/template");
|
|
51
|
+
const general_helper_1 = require("./helper/general-helper");
|
|
52
|
+
const logger_1 = require("./helper/logger");
|
|
53
|
+
const master_1 = require("./classes/master");
|
|
54
|
+
const layout_1 = require("./classes/layout");
|
|
55
|
+
const slide_master_remover_1 = require("./classes/slide-master-remover");
|
|
56
|
+
const constants_1 = require("./constants/constants");
|
|
57
|
+
const path_1 = __importDefault(require("path"));
|
|
58
|
+
const fs = __importStar(require("fs"));
|
|
59
|
+
const xml_helper_1 = require("./helper/xml-helper");
|
|
60
|
+
const modify_presentation_helper_1 = __importDefault(require("./helper/modify-presentation-helper"));
|
|
61
|
+
const content_tracker_1 = require("./helper/content-tracker");
|
|
62
|
+
const content_type_map_1 = require("./enums/content-type-map");
|
|
63
|
+
const errors_1 = require("./errors");
|
|
64
|
+
const slugify_1 = __importDefault(require("slugify"));
|
|
65
|
+
/**
|
|
66
|
+
* Valid media file extensions based on ContentTypeMap.
|
|
67
|
+
* Used to validate file extensions before processing.
|
|
68
|
+
*/
|
|
69
|
+
const VALID_MEDIA_EXTENSIONS = Object.keys(content_type_map_1.ContentTypeMap);
|
|
70
|
+
/**
|
|
71
|
+
* Validates that a file extension is a supported media type.
|
|
72
|
+
* @param extension - The file extension to validate (without leading dot)
|
|
73
|
+
* @param filename - The original filename (for error message)
|
|
74
|
+
* @throws {Error} If the extension is not supported
|
|
75
|
+
*/
|
|
76
|
+
function validateMediaExtension(extension, filename) {
|
|
77
|
+
if (!VALID_MEDIA_EXTENSIONS.includes(extension.toLowerCase())) {
|
|
78
|
+
throw new errors_1.AutomizerError(`Unsupported media extension '${extension}' for file '${filename}'. ` +
|
|
79
|
+
`Supported extensions: ${VALID_MEDIA_EXTENSIONS.join(', ')}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Extracts and validates file extension.
|
|
84
|
+
* @param filename - The filename to extract extension from
|
|
85
|
+
* @returns The validated extension
|
|
86
|
+
* @throws {Error} If filename has no extension or extension is not supported
|
|
87
|
+
*/
|
|
88
|
+
function getValidatedExtension(filename) {
|
|
89
|
+
const extension = path_1.default
|
|
90
|
+
.extname(filename)
|
|
91
|
+
.replace('.', '');
|
|
92
|
+
if (!extension) {
|
|
93
|
+
throw new errors_1.AutomizerError(`Filename must include extension: ${filename}. Example: 'logo.png'`);
|
|
94
|
+
}
|
|
95
|
+
validateMediaExtension(extension, filename);
|
|
96
|
+
return extension;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Automizer
|
|
100
|
+
*
|
|
101
|
+
* The basic class for `pptx-templates` package.
|
|
102
|
+
* This class will be exported as `Automizer` by `index.ts`.
|
|
103
|
+
*/
|
|
104
|
+
class Automizer {
|
|
105
|
+
/**
|
|
106
|
+
* Creates an instance of `pptx-templates`.
|
|
107
|
+
* @param [params]
|
|
108
|
+
*/
|
|
109
|
+
constructor(params) {
|
|
110
|
+
var _a, _b, _c, _d, _f, _g, _h;
|
|
111
|
+
/**
|
|
112
|
+
* Templates of automizer
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
this.templates = [];
|
|
116
|
+
this.modifyPresentation = [];
|
|
117
|
+
/**
|
|
118
|
+
* Masters queued for removal (`removeMaster`), by number.
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
this.mastersToRemove = [];
|
|
122
|
+
this.params = params;
|
|
123
|
+
this.logger = (_a = params.logger) !== null && _a !== void 0 ? _a : new logger_1.ConsoleLogger((_b = params.verbosity) !== null && _b !== void 0 ? _b : 1);
|
|
124
|
+
this.templateDir = (params === null || params === void 0 ? void 0 : params.templateDir) ? params.templateDir + '/' : '';
|
|
125
|
+
this.templateFallbackDir = (params === null || params === void 0 ? void 0 : params.templateFallbackDir)
|
|
126
|
+
? params.templateFallbackDir + '/'
|
|
127
|
+
: '';
|
|
128
|
+
this.outputDir = (params === null || params === void 0 ? void 0 : params.outputDir) ? params.outputDir + '/' : '';
|
|
129
|
+
this.archiveParams = {
|
|
130
|
+
mode: ((_c = params === null || params === void 0 ? void 0 : params.archiveType) === null || _c === void 0 ? void 0 : _c.mode) || 'jszip',
|
|
131
|
+
baseDir: ((_d = params === null || params === void 0 ? void 0 : params.archiveType) === null || _d === void 0 ? void 0 : _d.baseDir) || __dirname + '/../cache',
|
|
132
|
+
workDir: ((_f = params === null || params === void 0 ? void 0 : params.archiveType) === null || _f === void 0 ? void 0 : _f.workDir) || 'tmp',
|
|
133
|
+
cleanupWorkDir: (_g = params === null || params === void 0 ? void 0 : params.archiveType) === null || _g === void 0 ? void 0 : _g.cleanupWorkDir,
|
|
134
|
+
decodeText: (_h = params === null || params === void 0 ? void 0 : params.archiveType) === null || _h === void 0 ? void 0 : _h.decodeText,
|
|
135
|
+
};
|
|
136
|
+
this.timer = Date.now();
|
|
137
|
+
this.setStatusTracker(params === null || params === void 0 ? void 0 : params.statusTracker);
|
|
138
|
+
this.content = new content_tracker_1.ContentTracker();
|
|
139
|
+
if (params.rootTemplate) {
|
|
140
|
+
let file = params.rootTemplate;
|
|
141
|
+
if (typeof file !== 'object') {
|
|
142
|
+
file = this.getLocation(file, 'template');
|
|
143
|
+
}
|
|
144
|
+
this.rootTemplate = new template_1.OutputTemplate(file, this.archiveParams, this);
|
|
145
|
+
}
|
|
146
|
+
if (params.presTemplates) {
|
|
147
|
+
this.params.presTemplates.forEach((file, i) => {
|
|
148
|
+
let name;
|
|
149
|
+
if (typeof file !== 'object') {
|
|
150
|
+
name = file;
|
|
151
|
+
file = this.getLocation(file, 'template');
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
name = `${i}.pptx`;
|
|
155
|
+
}
|
|
156
|
+
const archiveParams = Object.assign(Object.assign({}, this.archiveParams), { name });
|
|
157
|
+
this.templates.push(new template_1.SourceTemplate(file, archiveParams));
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
setStatusTracker(statusTracker) {
|
|
162
|
+
const defaultStatusTracker = (status) => {
|
|
163
|
+
this.logger.info(status.info + ' (' + status.share + '%)');
|
|
164
|
+
};
|
|
165
|
+
this.status = {
|
|
166
|
+
current: 0,
|
|
167
|
+
max: 0,
|
|
168
|
+
share: 0,
|
|
169
|
+
info: undefined,
|
|
170
|
+
increment: () => {
|
|
171
|
+
this.status.current++;
|
|
172
|
+
const nextShare = this.status.max > 0
|
|
173
|
+
? Math.round((this.status.current / this.status.max) * 100)
|
|
174
|
+
: 0;
|
|
175
|
+
if (this.status.share !== nextShare) {
|
|
176
|
+
this.status.share = nextShare;
|
|
177
|
+
this.status.next(this.status);
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
next: statusTracker || defaultStatusTracker,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
|
|
185
|
+
*/
|
|
186
|
+
presentation() {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
var _a;
|
|
189
|
+
if (((_a = this.params) === null || _a === void 0 ? void 0 : _a.useCreationIds) === true) {
|
|
190
|
+
yield this.setCreationIds();
|
|
191
|
+
}
|
|
192
|
+
return this;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Load a pptx file and set it as root template.
|
|
197
|
+
* @param file - Filename, path to the template or Buffer containing the file.
|
|
198
|
+
* Filenames and paths will be prefixed with 'templateDir'
|
|
199
|
+
* @returns Instance of Automizer
|
|
200
|
+
*/
|
|
201
|
+
loadRoot(file) {
|
|
202
|
+
return this.loadTemplate(file);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Load a template pptx file.
|
|
206
|
+
* @param file - Filename, path to the template or Buffer containing the file.
|
|
207
|
+
* Filenames and paths will be prefixed with 'templateDir'
|
|
208
|
+
* @param name - Optional short name for a template loaded from a file. If skipped, the template will be named by its location.
|
|
209
|
+
* if the file is a Buffer the name is required.
|
|
210
|
+
* @returns Instance of Automizer
|
|
211
|
+
*/
|
|
212
|
+
load(file, name) {
|
|
213
|
+
if (!name && typeof file !== 'object') {
|
|
214
|
+
name = name === undefined ? file : name;
|
|
215
|
+
}
|
|
216
|
+
else if (typeof file === 'object' && !name) {
|
|
217
|
+
throw new Error('Name is required when loading a template from a Buffer');
|
|
218
|
+
}
|
|
219
|
+
return this.loadTemplate(file, name);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Loads a pptx file either as a root template as a template file.
|
|
223
|
+
* A name can be specified to give templates an alias.
|
|
224
|
+
* @param location
|
|
225
|
+
* @param [name]
|
|
226
|
+
* @returns template
|
|
227
|
+
*/
|
|
228
|
+
loadTemplate(file, name) {
|
|
229
|
+
if (typeof file !== 'object') {
|
|
230
|
+
file = this.getLocation(file, 'template');
|
|
231
|
+
}
|
|
232
|
+
const alreadyLoaded = this.templates.find((template) => template.name === name);
|
|
233
|
+
if (alreadyLoaded) {
|
|
234
|
+
return this;
|
|
235
|
+
}
|
|
236
|
+
const importParams = Object.assign(Object.assign({}, this.archiveParams), { name });
|
|
237
|
+
const newTemplate = template_1.Template.import(file, importParams, this);
|
|
238
|
+
if (newTemplate instanceof template_1.SourceTemplate) {
|
|
239
|
+
this.templates.push(newTemplate);
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
this.rootTemplate = newTemplate;
|
|
243
|
+
}
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Load media files to output presentation.
|
|
248
|
+
* @returns Instance of Automizer
|
|
249
|
+
* @param filename Filename or path to the media file.
|
|
250
|
+
* @param dir Specify custom path for media instead of mediaDir from AutomizerParams.
|
|
251
|
+
*/
|
|
252
|
+
loadMedia(filename, dir, prefix) {
|
|
253
|
+
const files = general_helper_1.GeneralHelper.arrayify(filename);
|
|
254
|
+
if (!this.rootTemplate) {
|
|
255
|
+
throw new errors_1.AutomizerError("Can't load media, you need to load a root template first");
|
|
256
|
+
}
|
|
257
|
+
files.forEach((file) => {
|
|
258
|
+
const directory = dir || this.params.mediaDir;
|
|
259
|
+
const filepath = path_1.default.join(directory, file);
|
|
260
|
+
const extension = getValidatedExtension(file);
|
|
261
|
+
try {
|
|
262
|
+
fs.accessSync(filepath, fs.constants.F_OK);
|
|
263
|
+
}
|
|
264
|
+
catch (_e) {
|
|
265
|
+
throw new errors_1.AutomizerError(`Can't load media: ${filepath} does not exist.`);
|
|
266
|
+
}
|
|
267
|
+
this.rootTemplate.mediaFiles.push({
|
|
268
|
+
source: 'path',
|
|
269
|
+
file,
|
|
270
|
+
directory,
|
|
271
|
+
filepath,
|
|
272
|
+
extension,
|
|
273
|
+
prefix,
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
return this;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Load media files from buffers to output presentation.
|
|
280
|
+
* @returns Instance of Automizer
|
|
281
|
+
* @param filename Filename(s) to use (must include extension).
|
|
282
|
+
* @param buffer Buffer(s) containing the media data.
|
|
283
|
+
* @param prefix Optional prefix to prepend to filename in archive.
|
|
284
|
+
*/
|
|
285
|
+
loadMediaBuffer(filename, buffer, prefix) {
|
|
286
|
+
const files = general_helper_1.GeneralHelper.arrayify(filename);
|
|
287
|
+
const buffers = general_helper_1.GeneralHelper.arrayify(buffer);
|
|
288
|
+
if (!this.rootTemplate) {
|
|
289
|
+
throw new errors_1.AutomizerError("Can't load media, you need to load a root template first");
|
|
290
|
+
}
|
|
291
|
+
if (files.length !== buffers.length) {
|
|
292
|
+
throw new errors_1.AutomizerError(`Mismatched arrays: ${files.length} filename(s) but ${buffers.length} buffer(s)`);
|
|
293
|
+
}
|
|
294
|
+
files.forEach((file, index) => {
|
|
295
|
+
const buf = buffers[index];
|
|
296
|
+
if (!Buffer.isBuffer(buf)) {
|
|
297
|
+
throw new errors_1.AutomizerError(`Invalid buffer for file: ${file}`);
|
|
298
|
+
}
|
|
299
|
+
if (buf.length === 0) {
|
|
300
|
+
throw new errors_1.AutomizerError(`Empty buffer provided for file: ${file}`);
|
|
301
|
+
}
|
|
302
|
+
const extension = getValidatedExtension(file);
|
|
303
|
+
this.rootTemplate.mediaFiles.push({
|
|
304
|
+
source: 'buffer',
|
|
305
|
+
file,
|
|
306
|
+
buffer: buf,
|
|
307
|
+
extension,
|
|
308
|
+
prefix,
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
return this;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Parses all loaded templates and collects creationIds for slides and
|
|
315
|
+
* elements. This will make finding templates and elements independent
|
|
316
|
+
* of slide number and element name.
|
|
317
|
+
* @returns Promise<TemplateInfo[]>
|
|
318
|
+
*/
|
|
319
|
+
setCreationIds() {
|
|
320
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
321
|
+
return (0, logger_1.runWithLogger)(this.logger, () => __awaiter(this, void 0, void 0, function* () {
|
|
322
|
+
const templateCreationId = [];
|
|
323
|
+
for (const template of this.templates) {
|
|
324
|
+
const creationIds = template.creationIds || (yield template.setCreationIds());
|
|
325
|
+
template.useCreationIds = this.params.useCreationIds;
|
|
326
|
+
templateCreationId.push({
|
|
327
|
+
name: template.name,
|
|
328
|
+
slides: creationIds,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
return templateCreationId;
|
|
332
|
+
}));
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Get some info about the imported templates
|
|
337
|
+
* @returns Promise<PresentationInfo>
|
|
338
|
+
*/
|
|
339
|
+
getInfo() {
|
|
340
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
341
|
+
const creationIds = yield this.setCreationIds();
|
|
342
|
+
const info = {
|
|
343
|
+
templateByName: (tplName) => {
|
|
344
|
+
return creationIds.find((template) => template.name === tplName);
|
|
345
|
+
},
|
|
346
|
+
slidesByTemplate: (tplName) => {
|
|
347
|
+
var _a;
|
|
348
|
+
return ((_a = info.templateByName(tplName)) === null || _a === void 0 ? void 0 : _a.slides) || [];
|
|
349
|
+
},
|
|
350
|
+
slideByNumber: (tplName, slideNumber) => {
|
|
351
|
+
return info
|
|
352
|
+
.slidesByTemplate(tplName)
|
|
353
|
+
.find((slide) => slide.number === slideNumber);
|
|
354
|
+
},
|
|
355
|
+
elementByName: (tplName, slideNumber, elementName) => {
|
|
356
|
+
var _a;
|
|
357
|
+
return (_a = info
|
|
358
|
+
.slideByNumber(tplName, slideNumber)) === null || _a === void 0 ? void 0 : _a.elements.find((element) => elementName === element.name);
|
|
359
|
+
},
|
|
360
|
+
};
|
|
361
|
+
return info;
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Add a slide from one of the imported templates by slide number or creationId.
|
|
366
|
+
* @param name - Name or alias of the template; must have been loaded with `Automizer.load()`
|
|
367
|
+
* @param slideIdentifier - Number or creationId of slide in template presentation
|
|
368
|
+
* @param callback - Executed after slide was added. The newly created slide will be passed to the callback as first argument.
|
|
369
|
+
* @returns Instance of Automizer
|
|
370
|
+
*/
|
|
371
|
+
addSlide(name, slideIdentifier, callback) {
|
|
372
|
+
if (this.rootTemplate === undefined) {
|
|
373
|
+
throw new Error('You have to set a root template first.');
|
|
374
|
+
}
|
|
375
|
+
const template = this.getTemplate(name);
|
|
376
|
+
const newSlide = new slide_1.Slide({
|
|
377
|
+
presentation: this,
|
|
378
|
+
template,
|
|
379
|
+
slideIdentifier,
|
|
380
|
+
});
|
|
381
|
+
if (this.params.autoImportSlideMasters) {
|
|
382
|
+
newSlide.useSlideLayout();
|
|
383
|
+
}
|
|
384
|
+
if (callback !== undefined) {
|
|
385
|
+
newSlide.root = this;
|
|
386
|
+
callback(newSlide);
|
|
387
|
+
}
|
|
388
|
+
this.rootTemplate.slides.push(newSlide);
|
|
389
|
+
return this;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Copy and modify a master and the associated layouts from template to output.
|
|
393
|
+
*
|
|
394
|
+
* @param name
|
|
395
|
+
* @param sourceIdentifier
|
|
396
|
+
* @param callback
|
|
397
|
+
*/
|
|
398
|
+
addMaster(name, sourceIdentifier, callback) {
|
|
399
|
+
const key = sourceIdentifier + '@' + name;
|
|
400
|
+
if (this.rootTemplate.masters.find((master) => master.key === key)) {
|
|
401
|
+
this.logger.info('Already imported ' + key);
|
|
402
|
+
return this;
|
|
403
|
+
}
|
|
404
|
+
const template = this.getTemplate(name);
|
|
405
|
+
const newMaster = new master_1.Master({
|
|
406
|
+
presentation: this,
|
|
407
|
+
template,
|
|
408
|
+
sourceIdentifier,
|
|
409
|
+
});
|
|
410
|
+
if (callback !== undefined) {
|
|
411
|
+
newMaster.root = this;
|
|
412
|
+
callback(newMaster);
|
|
413
|
+
}
|
|
414
|
+
this.rootTemplate.masters.push(newMaster);
|
|
415
|
+
return this;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Modify a slide master that is already part of the root template, in
|
|
419
|
+
* place: no copy is made, the master keeps its number and every slide
|
|
420
|
+
* using it keeps using it. The callback gets the same
|
|
421
|
+
* `modifyElement` / `addElement` / `removeElement` vocabulary as
|
|
422
|
+
* `addMaster`. Deferred: applied on write, before the slides are
|
|
423
|
+
* written, in call order with `addMaster` imports.
|
|
424
|
+
*
|
|
425
|
+
* @param masterNumber - 1-based number of the master in the root
|
|
426
|
+
* template as loaded (`ppt/slideMasters/slideMaster<n>.xml`). Imported
|
|
427
|
+
* masters are modified through their `addMaster` callback instead.
|
|
428
|
+
* @param callback - Receives the master; queue element actions on it.
|
|
429
|
+
*/
|
|
430
|
+
modifyMaster(masterNumber, callback) {
|
|
431
|
+
if (this.rootTemplate === undefined) {
|
|
432
|
+
throw new Error('You have to set a root template first.');
|
|
433
|
+
}
|
|
434
|
+
const key = master_1.Master.getKey(masterNumber, constants_1.ROOT_TEMPLATE_ALIAS);
|
|
435
|
+
let master = this.rootTemplate.masters.find((candidate) => candidate.key === key);
|
|
436
|
+
if (!master) {
|
|
437
|
+
master = new master_1.Master({
|
|
438
|
+
presentation: this,
|
|
439
|
+
template: this.rootTemplate.asSourceTemplate(),
|
|
440
|
+
sourceIdentifier: masterNumber,
|
|
441
|
+
inPlace: true,
|
|
442
|
+
});
|
|
443
|
+
master.root = this;
|
|
444
|
+
this.rootTemplate.masters.push(master);
|
|
445
|
+
}
|
|
446
|
+
callback(master);
|
|
447
|
+
return this;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Modify a slide layout that is already part of the root template, in
|
|
451
|
+
* place (see `modifyMaster`).
|
|
452
|
+
*
|
|
453
|
+
* @param layoutNumber - 1-based number of the layout in the root template
|
|
454
|
+
* as loaded (`ppt/slideLayouts/slideLayout<n>.xml`).
|
|
455
|
+
* @param callback - Receives the layout; queue element actions on it.
|
|
456
|
+
*/
|
|
457
|
+
modifyLayout(layoutNumber, callback) {
|
|
458
|
+
if (this.rootTemplate === undefined) {
|
|
459
|
+
throw new Error('You have to set a root template first.');
|
|
460
|
+
}
|
|
461
|
+
let layout = this.rootTemplate.layouts.find((candidate) => candidate.sourceNumber === layoutNumber);
|
|
462
|
+
if (!layout) {
|
|
463
|
+
layout = new layout_1.Layout({
|
|
464
|
+
presentation: this,
|
|
465
|
+
template: this.rootTemplate.asSourceTemplate(),
|
|
466
|
+
sourceIdentifier: layoutNumber,
|
|
467
|
+
inPlace: true,
|
|
468
|
+
});
|
|
469
|
+
layout.root = this;
|
|
470
|
+
this.rootTemplate.layouts.push(layout);
|
|
471
|
+
}
|
|
472
|
+
callback(layout);
|
|
473
|
+
return this;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Remove a slide master from the output together with its layouts, its
|
|
477
|
+
* theme (unless another part still uses it) and all entries referring
|
|
478
|
+
* to them. Deferred: applied on write after all slides have been
|
|
479
|
+
* written. Fails if a slide of the output still uses one of the
|
|
480
|
+
* master's layouts — switch those slides with `useSlideLayout()` first
|
|
481
|
+
* (or drop the root template's slides with `removeExistingSlides`).
|
|
482
|
+
*
|
|
483
|
+
* @param masterNumber - 1-based number of the master in the root
|
|
484
|
+
* template as loaded (`ppt/slideMasters/slideMaster<n>.xml`).
|
|
485
|
+
*/
|
|
486
|
+
removeMaster(masterNumber) {
|
|
487
|
+
if (this.rootTemplate === undefined) {
|
|
488
|
+
throw new Error('You have to set a root template first.');
|
|
489
|
+
}
|
|
490
|
+
if (!this.mastersToRemove.includes(masterNumber)) {
|
|
491
|
+
this.mastersToRemove.push(masterNumber);
|
|
492
|
+
}
|
|
493
|
+
return this;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Searches this.templates to find template by given name.
|
|
497
|
+
* @internal
|
|
498
|
+
* @param name Alias name if given to loaded template.
|
|
499
|
+
* @returns template
|
|
500
|
+
*/
|
|
501
|
+
getTemplate(name) {
|
|
502
|
+
const template = this.templates.find((t) => t.name === name);
|
|
503
|
+
if (template === undefined) {
|
|
504
|
+
throw new Error(`Template not found: ${name}`);
|
|
505
|
+
}
|
|
506
|
+
return template;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Write all imports and modifications to a file.
|
|
510
|
+
* @param location - Filename or path for the file. Will be prefixed with 'outputDir'
|
|
511
|
+
* @returns summary object.
|
|
512
|
+
*/
|
|
513
|
+
write(location) {
|
|
514
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
515
|
+
return (0, logger_1.runWithLogger)(this.logger, () => __awaiter(this, void 0, void 0, function* () {
|
|
516
|
+
yield this.finalizePresentation();
|
|
517
|
+
yield this.rootTemplate.archive.output(this.getLocation(location, 'output'), this.params);
|
|
518
|
+
const duration = (Date.now() - this.timer) / 1000;
|
|
519
|
+
return {
|
|
520
|
+
status: 'finished',
|
|
521
|
+
duration,
|
|
522
|
+
file: location,
|
|
523
|
+
filename: path_1.default.basename(location),
|
|
524
|
+
templates: this.templates.length,
|
|
525
|
+
slides: this.rootTemplate.count('slides'),
|
|
526
|
+
charts: this.rootTemplate.count('charts'),
|
|
527
|
+
images: this.rootTemplate.count('images'),
|
|
528
|
+
masters: this.rootTemplate.count('masters'),
|
|
529
|
+
};
|
|
530
|
+
}));
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Create a ReadableStream from output pptx file.
|
|
535
|
+
* @param generatorOptions - JSZipGeneratorOptions for nodebuffer Output type
|
|
536
|
+
* @returns Promise<NodeJS.ReadableStream>
|
|
537
|
+
*/
|
|
538
|
+
stream(generatorOptions) {
|
|
539
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
540
|
+
return (0, logger_1.runWithLogger)(this.logger, () => __awaiter(this, void 0, void 0, function* () {
|
|
541
|
+
yield this.finalizePresentation();
|
|
542
|
+
if (!this.rootTemplate.archive.stream) {
|
|
543
|
+
throw new errors_1.OutputError('Streaming is not implemented for current archive type');
|
|
544
|
+
}
|
|
545
|
+
return this.rootTemplate.archive.stream(this.params, generatorOptions);
|
|
546
|
+
}));
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Pass final JSZip instance.
|
|
551
|
+
* @returns Promise<NodeJS.ReadableStream>
|
|
552
|
+
*/
|
|
553
|
+
getJSZip() {
|
|
554
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
555
|
+
return (0, logger_1.runWithLogger)(this.logger, () => __awaiter(this, void 0, void 0, function* () {
|
|
556
|
+
yield this.finalizePresentation();
|
|
557
|
+
if (!this.rootTemplate.archive.getFinalArchive) {
|
|
558
|
+
throw new errors_1.OutputError('GetFinalArchive is not implemented for current archive type');
|
|
559
|
+
}
|
|
560
|
+
return this.rootTemplate.archive.getFinalArchive();
|
|
561
|
+
}));
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
finalizePresentation() {
|
|
565
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
566
|
+
return (0, logger_1.runWithLogger)(this.logger, () => __awaiter(this, void 0, void 0, function* () {
|
|
567
|
+
yield this.writeMasterSlides();
|
|
568
|
+
yield this.writeSlides();
|
|
569
|
+
yield this.removeSlideMasters();
|
|
570
|
+
yield this.writeMediaFiles();
|
|
571
|
+
yield this.normalizePresentation();
|
|
572
|
+
yield this.applyModifyPresentationCallbacks();
|
|
573
|
+
this.content.reset();
|
|
574
|
+
}));
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Write all masterSlides to archive.
|
|
579
|
+
*/
|
|
580
|
+
writeMasterSlides() {
|
|
581
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
582
|
+
var _a;
|
|
583
|
+
for (const slide of this.rootTemplate.masters) {
|
|
584
|
+
yield this.rootTemplate.appendMasterSlide(slide);
|
|
585
|
+
}
|
|
586
|
+
for (const layout of (_a = this.rootTemplate.layouts) !== null && _a !== void 0 ? _a : []) {
|
|
587
|
+
yield this.rootTemplate.appendLayout(layout);
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Remove the masters queued by `removeMaster()`. Runs after the slides
|
|
593
|
+
* are written, so layout switches have been applied when the "still in
|
|
594
|
+
* use" check runs.
|
|
595
|
+
*/
|
|
596
|
+
removeSlideMasters() {
|
|
597
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
598
|
+
if (!this.mastersToRemove.length) {
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
const remover = new slide_master_remover_1.SlideMasterRemover(this.rootTemplate);
|
|
602
|
+
for (const masterNumber of this.mastersToRemove) {
|
|
603
|
+
yield remover.remove(masterNumber);
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Write all slides to archive.
|
|
609
|
+
*/
|
|
610
|
+
writeSlides() {
|
|
611
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
612
|
+
yield this.rootTemplate.countExistingSlides();
|
|
613
|
+
this.status.max = this.rootTemplate.slides.length;
|
|
614
|
+
yield this.rootTemplate.runExternalGenerator();
|
|
615
|
+
for (const slide of this.rootTemplate.slides) {
|
|
616
|
+
yield this.rootTemplate.appendSlide(slide);
|
|
617
|
+
}
|
|
618
|
+
yield this.rootTemplate.cleanupExternalGenerator();
|
|
619
|
+
if (this.params.removeExistingSlides) {
|
|
620
|
+
yield this.rootTemplate.truncate();
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Write all media files to archive.
|
|
626
|
+
*/
|
|
627
|
+
writeMediaFiles() {
|
|
628
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
629
|
+
const mediaDir = 'ppt/media/';
|
|
630
|
+
for (const file of this.rootTemplate.mediaFiles) {
|
|
631
|
+
const data = (0, types_1.getMediaBuffer)(file, fs.readFileSync);
|
|
632
|
+
let archiveFilename = file.file;
|
|
633
|
+
if (file.prefix) {
|
|
634
|
+
archiveFilename = file.prefix + file.file;
|
|
635
|
+
}
|
|
636
|
+
archiveFilename = (0, slugify_1.default)(archiveFilename);
|
|
637
|
+
yield this.rootTemplate.archive.write(mediaDir + archiveFilename, data);
|
|
638
|
+
yield xml_helper_1.XmlHelper.appendImageExtensionToContentType(this.rootTemplate.archive, file.extension);
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Applies all callbacks in this.modifyPresentation-array.
|
|
644
|
+
* The callback array can be pushed by this.modify()
|
|
645
|
+
*/
|
|
646
|
+
applyModifyPresentationCallbacks() {
|
|
647
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
648
|
+
yield xml_helper_1.XmlHelper.modifyXmlInArchive(this.rootTemplate.archive, `ppt/presentation.xml`, this.modifyPresentation);
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Apply some callbacks to restore archive/xml structure
|
|
653
|
+
* and prevent corrupted pptx files.
|
|
654
|
+
*
|
|
655
|
+
* TODO: Use every imported image only once
|
|
656
|
+
* TODO: Check for lost relations
|
|
657
|
+
*/
|
|
658
|
+
normalizePresentation() {
|
|
659
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
660
|
+
this.modify(modify_presentation_helper_1.default.normalizeSlideIds);
|
|
661
|
+
this.modify(modify_presentation_helper_1.default.normalizeSlideMasterIds);
|
|
662
|
+
if (this.params.cleanup) {
|
|
663
|
+
if (this.params.removeExistingSlides) {
|
|
664
|
+
this.modify(modify_presentation_helper_1.default.removeUnusedFiles);
|
|
665
|
+
}
|
|
666
|
+
this.modify(modify_presentation_helper_1.default.removedUnusedImages);
|
|
667
|
+
this.modify(modify_presentation_helper_1.default.removeUnusedContentTypes);
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
modify(cb) {
|
|
672
|
+
this.modifyPresentation.push(cb);
|
|
673
|
+
return this;
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Applies path prefix to given location string.
|
|
677
|
+
* @param location path and/or filename
|
|
678
|
+
* @param [type] template or output
|
|
679
|
+
* @returns location
|
|
680
|
+
*/
|
|
681
|
+
getLocation(location, type) {
|
|
682
|
+
switch (type) {
|
|
683
|
+
case 'template':
|
|
684
|
+
if (fs.existsSync(this.templateDir + location)) {
|
|
685
|
+
return this.templateDir + location;
|
|
686
|
+
}
|
|
687
|
+
else if (fs.existsSync(this.templateFallbackDir + location)) {
|
|
688
|
+
return this.templateFallbackDir + location;
|
|
689
|
+
}
|
|
690
|
+
else {
|
|
691
|
+
throw new errors_1.TemplateNotFoundError(location, [
|
|
692
|
+
this.templateDir,
|
|
693
|
+
this.templateFallbackDir,
|
|
694
|
+
]);
|
|
695
|
+
}
|
|
696
|
+
case 'output':
|
|
697
|
+
return this.outputDir + location;
|
|
698
|
+
default:
|
|
699
|
+
return location;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
exports.default = Automizer;
|
|
704
|
+
//# sourceMappingURL=automizer.js.map
|