pptx-templates 0.0.0-stage → 0.1.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 +2253 -0
- package/CHANGELOG.md +49 -0
- package/LICENSE +23 -0
- package/README.md +86 -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/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 +147 -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,162 @@
|
|
|
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
|
+
exports.compressFolder = exports.extractToFolder = void 0;
|
|
49
|
+
const logger_1 = require("./logger");
|
|
50
|
+
const fs_1 = __importStar(require("fs"));
|
|
51
|
+
const promises_1 = require("stream/promises");
|
|
52
|
+
const path_1 = __importDefault(require("path"));
|
|
53
|
+
const jszip_1 = __importDefault(require("jszip"));
|
|
54
|
+
// Thanks to https://github.com/DesignByOnyx
|
|
55
|
+
// see https://github.com/Stuk/jszip/issues/386 for more info
|
|
56
|
+
/**
|
|
57
|
+
* Returns a flat list of all files and subfolders for a directory (recursively).
|
|
58
|
+
* @param {string} dir
|
|
59
|
+
* @returns {Promise<string[]>}
|
|
60
|
+
*/
|
|
61
|
+
const getFilePathsRecursively = (dir) => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
+
// returns a flat array of absolute paths of all files recursively contained in the dir
|
|
63
|
+
const list = yield fs_1.promises.readdir(dir);
|
|
64
|
+
const statPromises = list.map((file) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
const fullPath = path_1.default.resolve(dir, file);
|
|
66
|
+
const stat = yield fs_1.promises.stat(fullPath);
|
|
67
|
+
if (stat && stat.isDirectory()) {
|
|
68
|
+
return getFilePathsRecursively(fullPath);
|
|
69
|
+
}
|
|
70
|
+
return fullPath;
|
|
71
|
+
}));
|
|
72
|
+
return (yield Promise.all(statPromises)).flat();
|
|
73
|
+
});
|
|
74
|
+
/**
|
|
75
|
+
* Creates an in-memory zip stream from a folder in the file system
|
|
76
|
+
* @param {string} dir
|
|
77
|
+
* @returns {JSZip}
|
|
78
|
+
*/
|
|
79
|
+
const createZipFromFolder = (dir) => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
+
const absRoot = path_1.default.resolve(dir);
|
|
81
|
+
const filePaths = yield getFilePathsRecursively(dir);
|
|
82
|
+
return filePaths.reduce((z, filePath) => {
|
|
83
|
+
const relative = filePath.replace(absRoot, '');
|
|
84
|
+
// create folder trees manually :(
|
|
85
|
+
const zipFolder = path_1.default
|
|
86
|
+
.dirname(relative)
|
|
87
|
+
.split(path_1.default.sep)
|
|
88
|
+
.reduce((zf, dirName) => zf.folder(dirName), z);
|
|
89
|
+
zipFolder.file(path_1.default.basename(filePath), fs_1.default.createReadStream(filePath));
|
|
90
|
+
return z;
|
|
91
|
+
}, new jszip_1.default());
|
|
92
|
+
});
|
|
93
|
+
const S_IFMT = 0xf000;
|
|
94
|
+
const S_IFLNK = 0xa000;
|
|
95
|
+
const isSymlinkEntry = (entry) => { var _a;
|
|
96
|
+
// unixPermissions is typed number | string | null; octal strings included
|
|
97
|
+
return (Number((_a = entry.unixPermissions) !== null && _a !== void 0 ? _a : 0) & S_IFMT) === S_IFLNK; };
|
|
98
|
+
/**
|
|
99
|
+
* Extracts a zip file into a folder in the file system.
|
|
100
|
+
*
|
|
101
|
+
* Every entry must stay inside destDir: absolute and path-traversal
|
|
102
|
+
* ("zip slip") entry names are rejected, and symlink entries are skipped
|
|
103
|
+
* (never created). The archive is held in memory while extracting, one
|
|
104
|
+
* entry decompressed at a time - fine for .pptx-sized files, but unlike
|
|
105
|
+
* the streaming extract-zip this replaces, peak memory grows with the
|
|
106
|
+
* compressed archive size. Relevant here because ArchiveFs (fs mode)
|
|
107
|
+
* targets large decks; revisit with a streaming unzip if that ever bites.
|
|
108
|
+
* @param {string} srcFile
|
|
109
|
+
* @param {string} destDir
|
|
110
|
+
*/
|
|
111
|
+
const extractToFolder = (srcFile, destDir) => __awaiter(void 0, void 0, void 0, function* () {
|
|
112
|
+
const root = path_1.default.resolve(destDir);
|
|
113
|
+
yield fs_1.promises.mkdir(root, { recursive: true });
|
|
114
|
+
const zip = yield new jszip_1.default().loadAsync(yield fs_1.promises.readFile(srcFile));
|
|
115
|
+
for (const entry of Object.values(zip.files)) {
|
|
116
|
+
if (path_1.default.isAbsolute(entry.name) ||
|
|
117
|
+
entry.name.startsWith('/') ||
|
|
118
|
+
entry.name.startsWith('\\') ||
|
|
119
|
+
/^[a-zA-Z]:/.test(entry.name)) {
|
|
120
|
+
throw new Error('Zip entry has an absolute path: ' + entry.name);
|
|
121
|
+
}
|
|
122
|
+
const dest = path_1.default.resolve(root, entry.name);
|
|
123
|
+
if (dest !== root && !dest.startsWith(root + path_1.default.sep)) {
|
|
124
|
+
throw new Error('Zip entry resolves outside target directory: ' + entry.name);
|
|
125
|
+
}
|
|
126
|
+
if (isSymlinkEntry(entry)) {
|
|
127
|
+
logger_1.log.warn('Skipping symlink entry in zip file: ' + entry.name);
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (entry.dir) {
|
|
131
|
+
yield fs_1.promises.mkdir(dest, { recursive: true });
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
// some zips omit directory entries, so ensure the parent dir exists
|
|
135
|
+
yield fs_1.promises.mkdir(path_1.default.dirname(dest), { recursive: true });
|
|
136
|
+
yield fs_1.promises.writeFile(dest, yield entry.async('nodebuffer'));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
exports.extractToFolder = extractToFolder;
|
|
141
|
+
/**
|
|
142
|
+
* Compresses a folder to the specified zip file.
|
|
143
|
+
* @param {string} srcDir
|
|
144
|
+
* @param {string} destFile
|
|
145
|
+
*/
|
|
146
|
+
const compressFolder = (srcDir, destFile, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
147
|
+
const start = Date.now();
|
|
148
|
+
try {
|
|
149
|
+
const zip = yield createZipFromFolder(srcDir);
|
|
150
|
+
// pipeline settles on completion or on an error from either stream, so
|
|
151
|
+
// callers (e.g. ArchiveFs.output) only continue - and clean up the
|
|
152
|
+
// source folder - once the zip is fully written
|
|
153
|
+
yield (0, promises_1.pipeline)(zip.generateNodeStream(Object.assign({ streamFiles: true }, options)), fs_1.default.createWriteStream(destFile));
|
|
154
|
+
logger_1.log.info('Zip written successfully:', Date.now() - start, 'ms');
|
|
155
|
+
}
|
|
156
|
+
catch (ex) {
|
|
157
|
+
logger_1.log.error('Error creating zip', ex);
|
|
158
|
+
throw ex;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
exports.compressFolder = compressFolder;
|
|
162
|
+
//# sourceMappingURL=jszip-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jszip-helper.js","sourceRoot":"","sources":["../../src/helper/jszip-helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAA+B;AAC/B,yCAAyC;AACzC,8CAA2C;AAC3C,gDAAwB;AACxB,kDAA0B;AAE1B,4CAA4C;AAC5C,6DAA6D;AAE7D;;;;GAIG;AACH,MAAM,uBAAuB,GAAG,CAAO,GAAW,EAAqB,EAAE;IACvE,uFAAuF;IACvF,MAAM,IAAI,GAAG,MAAM,aAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACpC,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,CAAO,IAAI,EAA8B,EAAE;QACvE,MAAM,QAAQ,GAAG,cAAI,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACzC,MAAM,IAAI,GAAG,MAAM,aAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACtC,IAAI,IAAI,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;YAC/B,OAAO,uBAAuB,CAAC,QAAQ,CAAC,CAAC;QAC3C,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAA,CAAC,CAAC;IAEH,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,EAAc,CAAC;AAC9D,CAAC,CAAA,CAAC;AAEF;;;;G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AC,KAAK,CAAC,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YACzD,MAAM,aAAG,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;AACH,CAAC,CAAA,CAAC;AAvCW,QAAA,eAAe,mBAuC1B;AAEF;;;;GAIG;AACI,MAAM,cAAc,GAAG,CAC5B,MAAc,EACd,QAAgB,EAChB,OAAkD,EAClD,EAAE;IACF,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACzB,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,mBAAmB,CAAC,MAAM,CAAC,CAAC;QAC9C,uEAAuE;QACvE,mEAAmE;QACnE,gDAAgD;QAChD,MAAM,IAAA,mBAAQ,EACZ,GAAG,CAAC,kBAAkB,iBAAG,WAAW,EAAE,IAAI,IAAK,OAAO,EAAG,EACzD,YAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAC/B,CAAC;QACF,YAAG,CAAC,IAAI,CAAC,2BAA2B,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,IAAI,CAAC,CAAC;IAClE,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACZ,YAAG,CAAC,KAAK,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAC;QACpC,MAAM,EAAE,CAAC;IACX,CAAC;AACH,CAAC,CAAA,CAAC;AApBW,QAAA,cAAc,kBAoBzB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import IArchive from '../interfaces/iarchive';
|
|
2
|
+
import { RootPresTemplate } from '../interfaces/root-pres-template';
|
|
3
|
+
import { SlideLayoutSelector } from '../types/types';
|
|
4
|
+
/**
|
|
5
|
+
* One layout of the output presentation, as resolved by `LayoutIndex`.
|
|
6
|
+
*/
|
|
7
|
+
export type SlideLayoutInfo = {
|
|
8
|
+
/** 1-based number of `ppt/slideLayouts/slideLayout<n>.xml` in the output */
|
|
9
|
+
layoutNumber: number;
|
|
10
|
+
/** `p:cSld@name` of the layout — the name PowerPoint's layout gallery shows */
|
|
11
|
+
layoutName: string;
|
|
12
|
+
/** 1-based number of `ppt/slideMasters/slideMaster<n>.xml` in the output */
|
|
13
|
+
masterNumber: number;
|
|
14
|
+
/**
|
|
15
|
+
* Name of the master as PowerPoint shows it: the master's own
|
|
16
|
+
* `p:cSld@name` if set, otherwise the name of its theme (`a:theme@name`).
|
|
17
|
+
*/
|
|
18
|
+
masterName: string;
|
|
19
|
+
/**
|
|
20
|
+
* `'root'` for a layout that came with the root template, otherwise the
|
|
21
|
+
* alias of the template it was imported from.
|
|
22
|
+
*/
|
|
23
|
+
template: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Name index over the masters and layouts of the output presentation
|
|
27
|
+
* (root template as loaded plus everything imported so far), built from
|
|
28
|
+
* `ppt/presentation.xml` → master rels → layouts at write time. Backs
|
|
29
|
+
* `slide.useSlideLayout({ layout, master?, template? })` (#136).
|
|
30
|
+
*/
|
|
31
|
+
export declare class LayoutIndex {
|
|
32
|
+
/**
|
|
33
|
+
* The layouts currently in the output, in master and layout order.
|
|
34
|
+
*/
|
|
35
|
+
static read(root: RootPresTemplate): Promise<SlideLayoutInfo[]>;
|
|
36
|
+
static build(root: RootPresTemplate): Promise<SlideLayoutInfo[]>;
|
|
37
|
+
/**
|
|
38
|
+
* The master's own `p:cSld@name` if it has one, else its theme's name.
|
|
39
|
+
*/
|
|
40
|
+
static readMasterName(archive: IArchive, masterNumber: number): Promise<string>;
|
|
41
|
+
static readCSldName(archive: IArchive, path: string): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* All layouts matching the selector: equal layout name, and — if given —
|
|
44
|
+
* equal master name and origin template.
|
|
45
|
+
*/
|
|
46
|
+
static select(layouts: SlideLayoutInfo[], selector: SlideLayoutSelector): SlideLayoutInfo[];
|
|
47
|
+
/**
|
|
48
|
+
* Exactly one layout matching the selector; throws
|
|
49
|
+
* `SlideLayoutNotFoundError` for no match or more than one.
|
|
50
|
+
*/
|
|
51
|
+
static resolve(layouts: SlideLayoutInfo[], selector: SlideLayoutSelector): SlideLayoutInfo;
|
|
52
|
+
static describeSelector(selector: SlideLayoutSelector): string;
|
|
53
|
+
static describeLayout(layout: SlideLayoutInfo): string;
|
|
54
|
+
static describeLayouts(layouts: SlideLayoutInfo[]): string;
|
|
55
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LayoutIndex = void 0;
|
|
13
|
+
const errors_1 = require("../errors");
|
|
14
|
+
const constants_1 = require("../constants/constants");
|
|
15
|
+
const ppt_paths_1 = require("./ppt-paths");
|
|
16
|
+
const xml_helper_1 = require("./xml-helper");
|
|
17
|
+
const xml_relationship_helper_1 = require("./xml-relationship-helper");
|
|
18
|
+
const REL_TYPE_SLIDE_MASTER = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster';
|
|
19
|
+
/**
|
|
20
|
+
* Per-output cache; a change in the master or layout count invalidates it.
|
|
21
|
+
* Keyed by the root template instance, so concurrent Automizer instances
|
|
22
|
+
* never share state.
|
|
23
|
+
*/
|
|
24
|
+
const indexByRoot = new WeakMap();
|
|
25
|
+
/**
|
|
26
|
+
* Name index over the masters and layouts of the output presentation
|
|
27
|
+
* (root template as loaded plus everything imported so far), built from
|
|
28
|
+
* `ppt/presentation.xml` → master rels → layouts at write time. Backs
|
|
29
|
+
* `slide.useSlideLayout({ layout, master?, template? })` (#136).
|
|
30
|
+
*/
|
|
31
|
+
class LayoutIndex {
|
|
32
|
+
/**
|
|
33
|
+
* The layouts currently in the output, in master and layout order.
|
|
34
|
+
*/
|
|
35
|
+
static read(root) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const key = `${root.count('masters')}:${root.count('layouts')}`;
|
|
38
|
+
const cached = indexByRoot.get(root);
|
|
39
|
+
if ((cached === null || cached === void 0 ? void 0 : cached.key) === key) {
|
|
40
|
+
return cached.layouts;
|
|
41
|
+
}
|
|
42
|
+
const layouts = yield LayoutIndex.build(root);
|
|
43
|
+
indexByRoot.set(root, { key, layouts });
|
|
44
|
+
return layouts;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
static build(root) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
var _a;
|
|
50
|
+
const archive = root.archive;
|
|
51
|
+
const layouts = [];
|
|
52
|
+
const presentation = yield xml_helper_1.XmlHelper.getXmlFromArchive(archive, ppt_paths_1.PptPaths.presentation);
|
|
53
|
+
const masterTargets = yield xml_relationship_helper_1.XmlRelationshipHelper.getTargetsByRelationshipType(archive, ppt_paths_1.PptPaths.presentationRels, REL_TYPE_SLIDE_MASTER);
|
|
54
|
+
const masterIds = presentation.getElementsByTagName('p:sldMasterId');
|
|
55
|
+
for (let i = 0; i < masterIds.length; i++) {
|
|
56
|
+
const rId = masterIds.item(i).getAttribute('r:id');
|
|
57
|
+
const masterTarget = masterTargets.find((target) => target.rId === rId);
|
|
58
|
+
if (!masterTarget) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const masterNumber = masterTarget.number;
|
|
62
|
+
const masterName = yield LayoutIndex.readMasterName(archive, masterNumber);
|
|
63
|
+
const layoutTargets = yield xml_relationship_helper_1.XmlRelationshipHelper.getRelationshipTargetsByPrefix(archive, ppt_paths_1.PptPaths.slideMasterRels(masterNumber), '../slideLayouts/slideLayout');
|
|
64
|
+
for (const layoutTarget of layoutTargets) {
|
|
65
|
+
const layoutNumber = layoutTarget.number;
|
|
66
|
+
const layoutName = yield LayoutIndex.readCSldName(archive, ppt_paths_1.PptPaths.slideLayout(layoutNumber));
|
|
67
|
+
const imported = (_a = root.contentMap) === null || _a === void 0 ? void 0 : _a.find((map) => map.type === 'slideLayout' && map.targetId === layoutNumber);
|
|
68
|
+
layouts.push({
|
|
69
|
+
layoutNumber,
|
|
70
|
+
layoutName,
|
|
71
|
+
masterNumber,
|
|
72
|
+
masterName,
|
|
73
|
+
template: imported ? imported.key : constants_1.ROOT_TEMPLATE_ALIAS,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return layouts;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The master's own `p:cSld@name` if it has one, else its theme's name.
|
|
82
|
+
*/
|
|
83
|
+
static readMasterName(archive, masterNumber) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
var _a, _b;
|
|
86
|
+
const ownName = yield LayoutIndex.readCSldName(archive, ppt_paths_1.PptPaths.slideMaster(masterNumber));
|
|
87
|
+
if (ownName) {
|
|
88
|
+
return ownName;
|
|
89
|
+
}
|
|
90
|
+
const themeTargets = yield xml_relationship_helper_1.XmlRelationshipHelper.getRelationshipTargetsByPrefix(archive, ppt_paths_1.PptPaths.slideMasterRels(masterNumber), '../theme/theme');
|
|
91
|
+
if (!themeTargets.length) {
|
|
92
|
+
return '';
|
|
93
|
+
}
|
|
94
|
+
const theme = yield xml_helper_1.XmlHelper.getXmlFromArchive(archive, ppt_paths_1.PptPaths.theme(themeTargets[0].number));
|
|
95
|
+
return (_b = (_a = theme.getElementsByTagName('a:theme').item(0)) === null || _a === void 0 ? void 0 : _a.getAttribute('name')) !== null && _b !== void 0 ? _b : '';
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
static readCSldName(archive, path) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
var _a, _b;
|
|
101
|
+
const xml = yield xml_helper_1.XmlHelper.getXmlFromArchive(archive, path);
|
|
102
|
+
return (_b = (_a = xml.getElementsByTagName('p:cSld').item(0)) === null || _a === void 0 ? void 0 : _a.getAttribute('name')) !== null && _b !== void 0 ? _b : '';
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* All layouts matching the selector: equal layout name, and — if given —
|
|
107
|
+
* equal master name and origin template.
|
|
108
|
+
*/
|
|
109
|
+
static select(layouts, selector) {
|
|
110
|
+
return layouts.filter((layout) => layout.layoutName === selector.layout &&
|
|
111
|
+
(selector.master === undefined ||
|
|
112
|
+
layout.masterName === selector.master) &&
|
|
113
|
+
(selector.template === undefined ||
|
|
114
|
+
layout.template === selector.template));
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Exactly one layout matching the selector; throws
|
|
118
|
+
* `SlideLayoutNotFoundError` for no match or more than one.
|
|
119
|
+
*/
|
|
120
|
+
static resolve(layouts, selector) {
|
|
121
|
+
const matches = LayoutIndex.select(layouts, selector);
|
|
122
|
+
if (matches.length === 1) {
|
|
123
|
+
return matches[0];
|
|
124
|
+
}
|
|
125
|
+
if (matches.length === 0) {
|
|
126
|
+
throw new errors_1.SlideLayoutNotFoundError(`Slide layout ${LayoutIndex.describeSelector(selector)} not found. ` +
|
|
127
|
+
`Available layouts: ${LayoutIndex.describeLayouts(layouts)}`, { selector, candidates: [] });
|
|
128
|
+
}
|
|
129
|
+
throw new errors_1.SlideLayoutNotFoundError(`Slide layout ${LayoutIndex.describeSelector(selector)} is ambiguous: ` +
|
|
130
|
+
`${LayoutIndex.describeLayouts(matches)}. ` +
|
|
131
|
+
`Add "master" (or "template") to the selector.`, { selector, candidates: matches });
|
|
132
|
+
}
|
|
133
|
+
static describeSelector(selector) {
|
|
134
|
+
const parts = [`layout "${selector.layout}"`];
|
|
135
|
+
if (selector.master !== undefined) {
|
|
136
|
+
parts.push(`master "${selector.master}"`);
|
|
137
|
+
}
|
|
138
|
+
if (selector.template !== undefined) {
|
|
139
|
+
parts.push(`template "${selector.template}"`);
|
|
140
|
+
}
|
|
141
|
+
return parts.join(', ');
|
|
142
|
+
}
|
|
143
|
+
static describeLayout(layout) {
|
|
144
|
+
return (`"${layout.masterName} / ${layout.layoutName}" ` +
|
|
145
|
+
`(slideLayout${layout.layoutNumber}, ${layout.template})`);
|
|
146
|
+
}
|
|
147
|
+
static describeLayouts(layouts) {
|
|
148
|
+
if (!layouts.length) {
|
|
149
|
+
return '(none)';
|
|
150
|
+
}
|
|
151
|
+
return layouts.map(LayoutIndex.describeLayout).join(', ');
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.LayoutIndex = LayoutIndex;
|
|
155
|
+
//# sourceMappingURL=layout-index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout-index.js","sourceRoot":"","sources":["../../src/helper/layout-index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sCAAqD;AAIrD,sDAA6D;AAC7D,2CAAuC;AACvC,6CAAyC;AACzC,uEAAkE;AAGlE,MAAM,qBAAqB,GACzB,iFAAiF,CAAC;AA0BpF;;;;GAIG;AACH,MAAM,WAAW,GAAG,IAAI,OAAO,EAAiC,CAAC;AAEjE;;;;;GAKG;AACH,MAAa,WAAW;IACtB;;OAEG;IACH,MAAM,CAAO,IAAI,CAAC,IAAsB;;YACtC,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EAA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AU,IAAI;YAChD,eAAe,MAAM,CAAC,YAAY,KAAK,MAAM,CAAC,QAAQ,GAAG,CAC1D,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,eAAe,CAAC,OAA0B;QAC/C,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YACpB,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,OAAO,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC;CACF;AAtLD,kCAsLC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logging verbosity:
|
|
3
|
+
* 0: errors only
|
|
4
|
+
* 1: errors and warnings (default)
|
|
5
|
+
* 2: everything, including info and debug output
|
|
6
|
+
*/
|
|
7
|
+
export type Verbosity = 0 | 1 | 2;
|
|
8
|
+
/**
|
|
9
|
+
* Minimal logging interface used by pptx-templates.
|
|
10
|
+
* Inject a custom implementation via `AutomizerParams.logger`
|
|
11
|
+
* to route library output into your own logging stack.
|
|
12
|
+
*/
|
|
13
|
+
export interface ILogger {
|
|
14
|
+
error(message: unknown, ...details: unknown[]): void;
|
|
15
|
+
warn(message: unknown, ...details: unknown[]): void;
|
|
16
|
+
info(message: unknown, ...details: unknown[]): void;
|
|
17
|
+
debug(message: unknown, ...details: unknown[]): void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Default logger. Writes to the console, filtered by verbosity.
|
|
21
|
+
* Errors are always written; warnings at verbosity >= 1;
|
|
22
|
+
* info and debug output at verbosity 2.
|
|
23
|
+
*/
|
|
24
|
+
export declare class ConsoleLogger implements ILogger {
|
|
25
|
+
verbosity: Verbosity;
|
|
26
|
+
constructor(verbosity?: Verbosity);
|
|
27
|
+
error(message: unknown, ...details: unknown[]): void;
|
|
28
|
+
warn(message: unknown, ...details: unknown[]): void;
|
|
29
|
+
info(message: unknown, ...details: unknown[]): void;
|
|
30
|
+
debug(message: unknown, ...details: unknown[]): void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Discards all output. Inject via `AutomizerParams.logger` to keep
|
|
34
|
+
* the library completely silent, e.g. when embedded in a server.
|
|
35
|
+
*/
|
|
36
|
+
export declare class NullLogger implements ILogger {
|
|
37
|
+
error(): void;
|
|
38
|
+
warn(): void;
|
|
39
|
+
info(): void;
|
|
40
|
+
debug(): void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Runs `fn` with `logger` as the active logger for everything (a)waited
|
|
44
|
+
* inside it. Used by Automizer to scope its configured logger to its own
|
|
45
|
+
* pipeline; safe to nest.
|
|
46
|
+
*/
|
|
47
|
+
export declare const runWithLogger: <T>(logger: ILogger, fn: () => T) => T;
|
|
48
|
+
/**
|
|
49
|
+
* Logging facade for library internals: delegates to the logger of the
|
|
50
|
+
* Automizer instance whose call tree we are in, or to a default
|
|
51
|
+
* ConsoleLogger outside any instance context.
|
|
52
|
+
*/
|
|
53
|
+
export declare const log: ILogger;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.log = exports.runWithLogger = exports.NullLogger = exports.ConsoleLogger = void 0;
|
|
4
|
+
const async_hooks_1 = require("async_hooks");
|
|
5
|
+
/**
|
|
6
|
+
* Default logger. Writes to the console, filtered by verbosity.
|
|
7
|
+
* Errors are always written; warnings at verbosity >= 1;
|
|
8
|
+
* info and debug output at verbosity 2.
|
|
9
|
+
*/
|
|
10
|
+
class ConsoleLogger {
|
|
11
|
+
constructor(verbosity = 1) {
|
|
12
|
+
this.verbosity = verbosity;
|
|
13
|
+
}
|
|
14
|
+
error(message, ...details) {
|
|
15
|
+
console.error('[pptx-templates]', message, ...details);
|
|
16
|
+
}
|
|
17
|
+
warn(message, ...details) {
|
|
18
|
+
if (this.verbosity >= 1) {
|
|
19
|
+
console.warn('[pptx-templates]', message, ...details);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
info(message, ...details) {
|
|
23
|
+
if (this.verbosity >= 2) {
|
|
24
|
+
console.info('[pptx-templates]', message, ...details);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
debug(message, ...details) {
|
|
28
|
+
if (this.verbosity >= 2) {
|
|
29
|
+
console.debug('[pptx-templates]', message, ...details);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.ConsoleLogger = ConsoleLogger;
|
|
34
|
+
/**
|
|
35
|
+
* Discards all output. Inject via `AutomizerParams.logger` to keep
|
|
36
|
+
* the library completely silent, e.g. when embedded in a server.
|
|
37
|
+
*/
|
|
38
|
+
class NullLogger {
|
|
39
|
+
error() { }
|
|
40
|
+
warn() { }
|
|
41
|
+
info() { }
|
|
42
|
+
debug() { }
|
|
43
|
+
}
|
|
44
|
+
exports.NullLogger = NullLogger;
|
|
45
|
+
// Static helpers log without holding an Automizer instance, and public
|
|
46
|
+
// modifier signatures cannot carry a logger. The instance configured on an
|
|
47
|
+
// Automizer is therefore scoped to its async call tree via AsyncLocalStorage:
|
|
48
|
+
// each Automizer wraps its entry points in runWithLogger(), so two instances
|
|
49
|
+
// running concurrently each log through their own logger.
|
|
50
|
+
const activeLogger = new async_hooks_1.AsyncLocalStorage();
|
|
51
|
+
// Fallback for calls outside any Automizer entry point.
|
|
52
|
+
const defaultLogger = new ConsoleLogger();
|
|
53
|
+
/**
|
|
54
|
+
* Runs `fn` with `logger` as the active logger for everything (a)waited
|
|
55
|
+
* inside it. Used by Automizer to scope its configured logger to its own
|
|
56
|
+
* pipeline; safe to nest.
|
|
57
|
+
*/
|
|
58
|
+
const runWithLogger = (logger, fn) => {
|
|
59
|
+
return activeLogger.run(logger, fn);
|
|
60
|
+
};
|
|
61
|
+
exports.runWithLogger = runWithLogger;
|
|
62
|
+
/**
|
|
63
|
+
* Logging facade for library internals: delegates to the logger of the
|
|
64
|
+
* Automizer instance whose call tree we are in, or to a default
|
|
65
|
+
* ConsoleLogger outside any instance context.
|
|
66
|
+
*/
|
|
67
|
+
exports.log = {
|
|
68
|
+
error: (message, ...details) => { var _a; return ((_a = activeLogger.getStore()) !== null && _a !== void 0 ? _a : defaultLogger).error(message, ...details); },
|
|
69
|
+
warn: (message, ...details) => { var _a; return ((_a = activeLogger.getStore()) !== null && _a !== void 0 ? _a : defaultLogger).warn(message, ...details); },
|
|
70
|
+
info: (message, ...details) => { var _a; return ((_a = activeLogger.getStore()) !== null && _a !== void 0 ? _a : defaultLogger).info(message, ...details); },
|
|
71
|
+
debug: (message, ...details) => { var _a; return ((_a = activeLogger.getStore()) !== null && _a !== void 0 ? _a : defaultLogger).debug(message, ...details); },
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/helper/logger.ts"],"names":[],"mappings":";;;AAAA,6CAAgD;AAsBhD;;;;GAIG;AACH,MAAa,aAAa;IAGxB,YAAY,YAAuB,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,OAAgB,EAAE,GAAG,OAAkB;QAC3C,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC;IACzD,CAAC;IAED,IAAI,CAAC,OAAgB,EAAE,GAAG,OAAkB;QAC1C,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,EAAE,CAAC;YACxB,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;IAED,IAAI,CAAC,OAAgB,EAAE,GAAG,OAAkB;QAC1C,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,EAAE,CAAC;YACxB,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,OAAO,EAAE,GAAG,OA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E,GAAG,OAAO,EAAE,EAAE,WAC5B,OAAA,CAAC,MAAA,YAAY,CAAC,QAAQ,EAAE,mCAAI,aAAa,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,CAAA,EAAA;IACtE,KAAK,EAAE,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE,EAAE,WAC7B,OAAA,CAAC,MAAA,YAAY,CAAC,QAAQ,EAAE,mCAAI,aAAa,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,CAAA,EAAA;CACxE,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import IArchive from '../interfaces/iarchive';
|
|
2
|
+
/**
|
|
3
|
+
* PowerPoint stores each distinct media file once and lets any number of
|
|
4
|
+
* relations point to the same part. pptx-templates used to copy an imported
|
|
5
|
+
* image for every shape referencing it, so the same template image on ten
|
|
6
|
+
* slides ended up ten times in ppt/media, bloating the output (see #145).
|
|
7
|
+
*
|
|
8
|
+
* This is a checksum index of the media files an output archive contains.
|
|
9
|
+
* An import can look up its file contents here and re-use an identical file
|
|
10
|
+
* instead of adding another copy. Relations are per shape and unaffected by
|
|
11
|
+
* sharing a target, and media files are never modified in place - a media
|
|
12
|
+
* file is either copied from a template or added by `Automizer.addMedia()`.
|
|
13
|
+
*
|
|
14
|
+
* One instance per root template; media files of source templates are
|
|
15
|
+
* irrelevant, only what ends up in the output is indexed.
|
|
16
|
+
*/
|
|
17
|
+
export declare class MediaDeduplicator {
|
|
18
|
+
archive: IArchive;
|
|
19
|
+
/**
|
|
20
|
+
* Checksum of a media file mapped to its filename inside ppt/media.
|
|
21
|
+
*/
|
|
22
|
+
private files;
|
|
23
|
+
private indexed;
|
|
24
|
+
constructor(archive: IArchive);
|
|
25
|
+
/**
|
|
26
|
+
* Find a media file with identical contents in the output archive.
|
|
27
|
+
* @param content Contents of the media file about to be copied
|
|
28
|
+
* @returns Filename inside ppt/media, or undefined if it is a new file
|
|
29
|
+
*/
|
|
30
|
+
find(content: Buffer): Promise<string | undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* Add a media file that has been copied into the output archive.
|
|
33
|
+
*/
|
|
34
|
+
add(content: Buffer, filename: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Index the media files the output archive already contains, e.g. the ones
|
|
37
|
+
* coming with the root template. Runs on first use only.
|
|
38
|
+
*/
|
|
39
|
+
private indexExistingFiles;
|
|
40
|
+
private readExistingFiles;
|
|
41
|
+
static checksum(content: Buffer): string;
|
|
42
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MediaDeduplicator = void 0;
|
|
13
|
+
const crypto_1 = require("crypto");
|
|
14
|
+
const ppt_paths_1 = require("./ppt-paths");
|
|
15
|
+
/**
|
|
16
|
+
* PowerPoint stores each distinct media file once and lets any number of
|
|
17
|
+
* relations point to the same part. pptx-templates used to copy an imported
|
|
18
|
+
* image for every shape referencing it, so the same template image on ten
|
|
19
|
+
* slides ended up ten times in ppt/media, bloating the output (see #145).
|
|
20
|
+
*
|
|
21
|
+
* This is a checksum index of the media files an output archive contains.
|
|
22
|
+
* An import can look up its file contents here and re-use an identical file
|
|
23
|
+
* instead of adding another copy. Relations are per shape and unaffected by
|
|
24
|
+
* sharing a target, and media files are never modified in place - a media
|
|
25
|
+
* file is either copied from a template or added by `Automizer.addMedia()`.
|
|
26
|
+
*
|
|
27
|
+
* One instance per root template; media files of source templates are
|
|
28
|
+
* irrelevant, only what ends up in the output is indexed.
|
|
29
|
+
*/
|
|
30
|
+
class MediaDeduplicator {
|
|
31
|
+
constructor(archive) {
|
|
32
|
+
/**
|
|
33
|
+
* Checksum of a media file mapped to its filename inside ppt/media.
|
|
34
|
+
*/
|
|
35
|
+
this.files = new Map();
|
|
36
|
+
this.archive = archive;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Find a media file with identical contents in the output archive.
|
|
40
|
+
* @param content Contents of the media file about to be copied
|
|
41
|
+
* @returns Filename inside ppt/media, or undefined if it is a new file
|
|
42
|
+
*/
|
|
43
|
+
find(content) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
yield this.indexExistingFiles();
|
|
46
|
+
return this.files.get(MediaDeduplicator.checksum(content));
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Add a media file that has been copied into the output archive.
|
|
51
|
+
*/
|
|
52
|
+
add(content, filename) {
|
|
53
|
+
const checksum = MediaDeduplicator.checksum(content);
|
|
54
|
+
if (!this.files.has(checksum)) {
|
|
55
|
+
this.files.set(checksum, filename);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Index the media files the output archive already contains, e.g. the ones
|
|
60
|
+
* coming with the root template. Runs on first use only.
|
|
61
|
+
*/
|
|
62
|
+
indexExistingFiles() {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
if (!this.indexed) {
|
|
65
|
+
this.indexed = this.readExistingFiles();
|
|
66
|
+
}
|
|
67
|
+
return this.indexed;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
readExistingFiles() {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const mediaFiles = yield this.archive.folder(ppt_paths_1.PptPaths.mediaDir);
|
|
73
|
+
for (const mediaFile of mediaFiles) {
|
|
74
|
+
// Directory entries have no filename to relate to
|
|
75
|
+
if (!mediaFile.relativePath || mediaFile.relativePath.endsWith('/')) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const content = (yield this.archive.read(mediaFile.name, 'nodebuffer'));
|
|
79
|
+
this.add(content, mediaFile.relativePath);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
static checksum(content) {
|
|
84
|
+
return (0, crypto_1.createHash)('sha1').update(content).digest('hex');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.MediaDeduplicator = MediaDeduplicator;
|
|
88
|
+
//# sourceMappingURL=media-deduplicator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-deduplicator.js","sourceRoot":"","sources":["../../src/helper/media-deduplicator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAoC;AAEpC,2CAAuC;AAEvC;;;;;;;;;;;;;;GAcG;AACH,MAAa,iBAAiB;IAU5B,YAAY,OAAiB;QAP7B;;WAEG;QACK,UAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;QAKxC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACG,IAAI,CAAC,OAAe;;YACxB,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAChC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;QAC7D,CAAC;KAAA;IAED;;OAEG;IACH,GAAG,CAAC,OAAe,EAAE,QAAgB;QACnC,MAAM,QAAQ,GAAG,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACrD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAA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