pptx-templates 0.3.9 → 0.5.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 +46 -3
- package/CHANGELOG.md +236 -1
- package/README.md +61 -168
- package/dist/automizer.d.ts +7 -0
- package/dist/automizer.js +168 -176
- package/dist/automizer.js.map +1 -1
- package/dist/classes/content-type-registry.js +23 -36
- package/dist/classes/content-type-registry.js.map +1 -1
- package/dist/classes/element-importer.js +130 -148
- package/dist/classes/element-importer.js.map +1 -1
- package/dist/classes/has-shapes.js +81 -126
- package/dist/classes/has-shapes.js.map +1 -1
- package/dist/classes/layout.js +47 -67
- package/dist/classes/layout.js.map +1 -1
- package/dist/classes/master.js +70 -89
- package/dist/classes/master.js.map +1 -1
- package/dist/classes/placeholder-normalizer.js +48 -37
- package/dist/classes/placeholder-normalizer.js.map +1 -1
- package/dist/classes/related-content-copier.js +65 -86
- package/dist/classes/related-content-copier.js.map +1 -1
- package/dist/classes/shape.js +79 -110
- package/dist/classes/shape.js.map +1 -1
- package/dist/classes/slide-master-remover.js +108 -130
- package/dist/classes/slide-master-remover.js.map +1 -1
- package/dist/classes/slide-notes-copier.js +24 -41
- package/dist/classes/slide-notes-copier.js.map +1 -1
- package/dist/classes/slide.js +112 -141
- package/dist/classes/slide.js.map +1 -1
- package/dist/classes/template.js +82 -117
- package/dist/classes/template.js.map +1 -1
- package/dist/constants/constants.js.map +1 -1
- package/dist/enums/chart-type.js.map +1 -1
- package/dist/enums/content-type-map.js.map +1 -1
- package/dist/enums/element-type.js.map +1 -1
- package/dist/errors.js +5 -5
- package/dist/errors.js.map +1 -1
- package/dist/extensions/cli/index.js +3 -13
- package/dist/extensions/cli/index.js.map +1 -1
- package/dist/extensions/hide-slide/index.js +48 -46
- package/dist/extensions/hide-slide/index.js.map +1 -1
- package/dist/extensions/index.d.ts +13 -3
- package/dist/extensions/index.js +3 -1
- package/dist/extensions/index.js.map +1 -1
- package/dist/extensions/link-scheme/index.d.ts +12 -0
- package/dist/extensions/link-scheme/index.js +40 -0
- package/dist/extensions/link-scheme/index.js.map +1 -0
- package/dist/extensions/master-parts/index.js +36 -49
- package/dist/extensions/master-parts/index.js.map +1 -1
- package/dist/extensions/pptxgenjs-compat/img-broken-png.js.map +1 -1
- package/dist/extensions/pptxgenjs-compat/index.js.map +1 -1
- package/dist/extensions/pptxgenjs-compat/svg-fallback.js +56 -70
- package/dist/extensions/pptxgenjs-compat/svg-fallback.js.map +1 -1
- package/dist/extensions/regexp-escape/index.d.ts +10 -0
- package/dist/extensions/regexp-escape/index.js +15 -0
- package/dist/extensions/regexp-escape/index.js.map +1 -0
- package/dist/extensions/run-merge/index.js +4 -5
- package/dist/extensions/run-merge/index.js.map +1 -1
- package/dist/extensions/shape-geometry/index.js +33 -11
- package/dist/extensions/shape-geometry/index.js.map +1 -1
- package/dist/extensions/shape-geometry/presets.d.ts +1 -1
- package/dist/extensions/shape-geometry/presets.js.map +1 -1
- package/dist/extensions/shape-geometry/types.js.map +1 -1
- package/dist/extensions/template-lint/cli.js +71 -49
- package/dist/extensions/template-lint/cli.js.map +1 -1
- package/dist/extensions/template-lint/config.js +29 -13
- package/dist/extensions/template-lint/config.js.map +1 -1
- package/dist/extensions/template-lint/data-model.js +17 -20
- package/dist/extensions/template-lint/data-model.js.map +1 -1
- package/dist/extensions/template-lint/hints.js.map +1 -1
- package/dist/extensions/template-lint/index.js.map +1 -1
- package/dist/extensions/template-lint/init-cli.d.ts +2 -0
- package/dist/extensions/template-lint/init-cli.js +33 -23
- package/dist/extensions/template-lint/init-cli.js.map +1 -1
- package/dist/extensions/template-lint/lint.d.ts +1 -1
- package/dist/extensions/template-lint/lint.js +83 -64
- package/dist/extensions/template-lint/lint.js.map +1 -1
- package/dist/extensions/template-lint/skeleton.js +5 -6
- package/dist/extensions/template-lint/skeleton.js.map +1 -1
- package/dist/extensions/template-lint/types.js.map +1 -1
- package/dist/extensions/template-lint/usage-cli.js +17 -18
- package/dist/extensions/template-lint/usage-cli.js.map +1 -1
- package/dist/extensions/template-lint/usage.js +8 -9
- package/dist/extensions/template-lint/usage.js.map +1 -1
- package/dist/extensions/template-lint/watch.d.ts +2 -0
- package/dist/extensions/template-lint/watch.js +52 -7
- package/dist/extensions/template-lint/watch.js.map +1 -1
- package/dist/extensions/template-logic/clone.d.ts +2 -16
- package/dist/extensions/template-logic/clone.js +15 -90
- package/dist/extensions/template-logic/clone.js.map +1 -1
- package/dist/extensions/template-logic/commands.d.ts +1 -1
- package/dist/extensions/template-logic/commands.js +12 -11
- package/dist/extensions/template-logic/commands.js.map +1 -1
- package/dist/extensions/template-logic/expression.d.ts +15 -2
- package/dist/extensions/template-logic/expression.js +143 -63
- package/dist/extensions/template-logic/expression.js.map +1 -1
- package/dist/extensions/template-logic/images.js +58 -55
- package/dist/extensions/template-logic/images.js.map +1 -1
- package/dist/extensions/template-logic/index.js +16 -24
- package/dist/extensions/template-logic/index.js.map +1 -1
- package/dist/extensions/template-logic/list-commands.js +8 -19
- package/dist/extensions/template-logic/list-commands.js.map +1 -1
- package/dist/extensions/template-logic/renderer.d.ts +9 -0
- package/dist/extensions/template-logic/renderer.js +480 -477
- package/dist/extensions/template-logic/renderer.js.map +1 -1
- package/dist/extensions/template-logic/types.d.ts +8 -1
- package/dist/extensions/template-logic/types.js.map +1 -1
- package/dist/extensions/template-render/cli.js +34 -22
- package/dist/extensions/template-render/cli.js.map +1 -1
- package/dist/extensions/template-render/index.js +152 -107
- package/dist/extensions/template-render/index.js.map +1 -1
- package/dist/extensions/template-render/prune.d.ts +14 -0
- package/dist/extensions/template-render/prune.js +131 -0
- package/dist/extensions/template-render/prune.js.map +1 -0
- package/dist/extensions/template-render/zip-text.d.ts +9 -0
- package/dist/extensions/template-render/zip-text.js +27 -0
- package/dist/extensions/template-render/zip-text.js.map +1 -0
- package/dist/extensions/template-render/zip-writer.d.ts +16 -0
- package/dist/extensions/template-render/zip-writer.js +151 -0
- package/dist/extensions/template-render/zip-writer.js.map +1 -0
- package/dist/extensions/text-flow/flow.js +183 -207
- package/dist/extensions/text-flow/flow.js.map +1 -1
- package/dist/extensions/text-flow/font-file.d.ts +9 -0
- package/dist/extensions/text-flow/font-file.js +40 -22
- package/dist/extensions/text-flow/font-file.js.map +1 -1
- package/dist/extensions/text-flow/fonts.d.ts +4 -0
- package/dist/extensions/text-flow/fonts.js +67 -23
- package/dist/extensions/text-flow/fonts.js.map +1 -1
- package/dist/extensions/text-flow/index.js.map +1 -1
- package/dist/extensions/text-flow/layout.js +8 -9
- package/dist/extensions/text-flow/layout.js.map +1 -1
- package/dist/extensions/text-flow/slide-styles.js +18 -22
- package/dist/extensions/text-flow/slide-styles.js.map +1 -1
- package/dist/extensions/text-flow/styles.d.ts +7 -1
- package/dist/extensions/text-flow/styles.js +108 -64
- package/dist/extensions/text-flow/styles.js.map +1 -1
- package/dist/helper/archive/archive-fs.d.ts +11 -0
- package/dist/helper/archive/archive-fs.js +195 -142
- package/dist/helper/archive/archive-fs.js.map +1 -1
- package/dist/helper/archive/archive-jszip.js +101 -125
- package/dist/helper/archive/archive-jszip.js.map +1 -1
- package/dist/helper/archive/archive.d.ts +6 -0
- package/dist/helper/archive/archive.js +21 -30
- package/dist/helper/archive/archive.js.map +1 -1
- package/dist/helper/archive/jszip-fast-read.d.ts +26 -0
- package/dist/helper/archive/jszip-fast-read.js +166 -0
- package/dist/helper/archive/jszip-fast-read.js.map +1 -0
- package/dist/helper/cell-id-helper.d.ts +1 -0
- package/dist/helper/cell-id-helper.js +6 -2
- package/dist/helper/cell-id-helper.js.map +1 -1
- package/dist/helper/compute-src-rect.js +4 -5
- package/dist/helper/compute-src-rect.js.map +1 -1
- package/dist/helper/content-tracker.js +86 -114
- package/dist/helper/content-tracker.js.map +1 -1
- package/dist/helper/count-helper.js +48 -78
- package/dist/helper/count-helper.js.map +1 -1
- package/dist/helper/css-style-parser.d.ts +1 -1
- package/dist/helper/css-style-parser.js +1 -2
- package/dist/helper/css-style-parser.js.map +1 -1
- package/dist/helper/file-helper.js +30 -48
- package/dist/helper/file-helper.js.map +1 -1
- package/dist/helper/general-helper.js.map +1 -1
- package/dist/helper/generate/generate-pptxgenjs.js +36 -48
- package/dist/helper/generate/generate-pptxgenjs.js.map +1 -1
- package/dist/helper/html-to-multitext-helper.d.ts +4 -4
- package/dist/helper/html-to-multitext-helper.js +46 -23
- package/dist/helper/html-to-multitext-helper.js.map +1 -1
- package/dist/helper/hyperlink-processor.js +125 -139
- package/dist/helper/hyperlink-processor.js.map +1 -1
- package/dist/helper/image-dimensions.js.map +1 -1
- package/dist/helper/jszip-helper.d.ts +1 -1
- package/dist/helper/jszip-helper.js +40 -33
- package/dist/helper/jszip-helper.js.map +1 -1
- package/dist/helper/layout-index.js +51 -71
- package/dist/helper/layout-index.js.map +1 -1
- package/dist/helper/logger.js +4 -4
- package/dist/helper/logger.js.map +1 -1
- package/dist/helper/media-deduplicator.d.ts +24 -0
- package/dist/helper/media-deduplicator.js +81 -34
- package/dist/helper/media-deduplicator.js.map +1 -1
- package/dist/helper/modify-background-helper.js +46 -46
- package/dist/helper/modify-background-helper.js.map +1 -1
- package/dist/helper/modify-chart-helper.d.ts +1 -1
- package/dist/helper/modify-chart-helper.js +597 -591
- package/dist/helper/modify-chart-helper.js.map +1 -1
- package/dist/helper/modify-cleanup-helper.js +112 -112
- package/dist/helper/modify-cleanup-helper.js.map +1 -1
- package/dist/helper/modify-color-helper.d.ts +1 -1
- package/dist/helper/modify-color-helper.js +53 -53
- package/dist/helper/modify-color-helper.js.map +1 -1
- package/dist/helper/modify-helper.js +25 -25
- package/dist/helper/modify-helper.js.map +1 -1
- package/dist/helper/modify-hyperlink-element.js.map +1 -1
- package/dist/helper/modify-hyperlink-helper.js +152 -158
- package/dist/helper/modify-hyperlink-helper.js.map +1 -1
- package/dist/helper/modify-image-helper.d.ts +1 -1
- package/dist/helper/modify-image-helper.js +121 -132
- package/dist/helper/modify-image-helper.js.map +1 -1
- package/dist/helper/modify-presentation-helper.js +137 -154
- package/dist/helper/modify-presentation-helper.js.map +1 -1
- package/dist/helper/modify-shape-helper.js +262 -262
- package/dist/helper/modify-shape-helper.js.map +1 -1
- package/dist/helper/modify-table-helper.js +95 -84
- package/dist/helper/modify-table-helper.js.map +1 -1
- package/dist/helper/modify-text-helper.d.ts +8 -0
- package/dist/helper/modify-text-helper.js +202 -190
- package/dist/helper/modify-text-helper.js.map +1 -1
- package/dist/helper/modify-xml-helper.js +36 -36
- package/dist/helper/modify-xml-helper.js.map +1 -1
- package/dist/helper/multitext-helper.js +13 -9
- package/dist/helper/multitext-helper.js.map +1 -1
- package/dist/helper/ppt-paths.js +17 -17
- package/dist/helper/ppt-paths.js.map +1 -1
- package/dist/helper/shape-type-detector.js +18 -29
- package/dist/helper/shape-type-detector.js.map +1 -1
- package/dist/helper/text-replace-helper.js +8 -8
- package/dist/helper/text-replace-helper.js.map +1 -1
- package/dist/helper/xml/lnLRTB.js.map +1 -1
- package/dist/helper/xml/prstGeom.js.map +1 -1
- package/dist/helper/xml-clone.d.ts +24 -0
- package/dist/helper/xml-clone.js +269 -0
- package/dist/helper/xml-clone.js.map +1 -0
- package/dist/helper/xml-elements.js +17 -20
- package/dist/helper/xml-elements.js.map +1 -1
- package/dist/helper/xml-find.d.ts +4 -0
- package/dist/helper/xml-find.js +48 -0
- package/dist/helper/xml-find.js.map +1 -0
- package/dist/helper/xml-helper.js +102 -135
- package/dist/helper/xml-helper.js.map +1 -1
- package/dist/helper/xml-parse-cache.d.ts +31 -0
- package/dist/helper/xml-parse-cache.js +71 -0
- package/dist/helper/xml-parse-cache.js.map +1 -0
- package/dist/helper/xml-placeholder-helper.js +10 -10
- package/dist/helper/xml-placeholder-helper.js.map +1 -1
- package/dist/helper/xml-pretty-print.js.map +1 -1
- package/dist/helper/xml-relationship-helper.js +132 -147
- package/dist/helper/xml-relationship-helper.js.map +1 -1
- package/dist/helper/xml-serializer.d.ts +2 -0
- package/dist/helper/xml-serializer.js +192 -0
- package/dist/helper/xml-serializer.js.map +1 -0
- package/dist/helper/xml-slide-helper.js +109 -129
- package/dist/helper/xml-slide-helper.js.map +1 -1
- package/dist/helper/xml-template-helper.js +120 -144
- package/dist/helper/xml-template-helper.js.map +1 -1
- package/dist/helper/xmldom-sax-patch.js +52 -2
- package/dist/helper/xmldom-sax-patch.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/interfaces/iarchive.js.map +1 -1
- package/dist/interfaces/ichart.js.map +1 -1
- package/dist/interfaces/icounter.js.map +1 -1
- package/dist/interfaces/igenerator.js.map +1 -1
- package/dist/interfaces/iimage.js.map +1 -1
- package/dist/interfaces/ilayout.js.map +1 -1
- package/dist/interfaces/imaster.js.map +1 -1
- package/dist/interfaces/imulti-text.js.map +1 -1
- package/dist/interfaces/ipptxgenjs-slide.js.map +1 -1
- package/dist/interfaces/ipresentation-props.js.map +1 -1
- package/dist/interfaces/ishape-action.js.map +1 -1
- package/dist/interfaces/ishape.js.map +1 -1
- package/dist/interfaces/islide.js.map +1 -1
- package/dist/interfaces/itemplate.js.map +1 -1
- package/dist/interfaces/pres-template.js.map +1 -1
- package/dist/interfaces/root-pres-template.js.map +1 -1
- package/dist/modify/modify-chart.d.ts +4 -4
- package/dist/modify/modify-chart.js +35 -23
- package/dist/modify/modify-chart.js.map +1 -1
- package/dist/modify/modify-table.d.ts +0 -1
- package/dist/modify/modify-table.js +19 -27
- package/dist/modify/modify-table.js.map +1 -1
- package/dist/shapes/chart.js +238 -287
- package/dist/shapes/chart.js.map +1 -1
- package/dist/shapes/diagram.d.ts +14 -0
- package/dist/shapes/diagram.js +167 -103
- package/dist/shapes/diagram.js.map +1 -1
- package/dist/shapes/generic.js +62 -83
- package/dist/shapes/generic.js.map +1 -1
- package/dist/shapes/hyperlink.d.ts +0 -1
- package/dist/shapes/hyperlink.js +84 -124
- package/dist/shapes/hyperlink.js.map +1 -1
- package/dist/shapes/image.js +118 -149
- package/dist/shapes/image.js.map +1 -1
- package/dist/shapes/ole.js +148 -188
- package/dist/shapes/ole.js.map +1 -1
- package/dist/types/chart-types.js.map +1 -1
- package/dist/types/modify-types.js.map +1 -1
- package/dist/types/shape-types.js.map +1 -1
- package/dist/types/table-types.js.map +1 -1
- package/dist/types/types.d.ts +7 -0
- package/dist/types/types.js.map +1 -1
- package/dist/types/xml-types.js.map +1 -1
- package/dist/vendor/pptxgenjs/README.md +8 -3
- package/dist/vendor/pptxgenjs/index.js +19 -2
- package/package.json +13 -16
|
@@ -32,26 +32,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
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 __rest = (this && this.__rest) || function (s, e) {
|
|
45
|
-
var t = {};
|
|
46
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
47
|
-
t[p] = s[p];
|
|
48
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
49
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
50
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
51
|
-
t[p[i]] = s[p[i]];
|
|
52
|
-
}
|
|
53
|
-
return t;
|
|
54
|
-
};
|
|
55
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
56
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
57
37
|
};
|
|
@@ -59,6 +39,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
59
39
|
exports.renderDeck = exports.countFlowPages = void 0;
|
|
60
40
|
const fs_1 = __importDefault(require("fs"));
|
|
61
41
|
const jszip_1 = __importDefault(require("jszip"));
|
|
42
|
+
const archive_jszip_1 = __importDefault(require("../../helper/archive/archive-jszip"));
|
|
43
|
+
const archive_1 = __importDefault(require("../../helper/archive/archive"));
|
|
44
|
+
const ppt_paths_1 = require("../../helper/ppt-paths");
|
|
45
|
+
const prune_1 = require("./prune");
|
|
46
|
+
const zip_writer_1 = require("./zip-writer");
|
|
47
|
+
const zip_text_1 = require("./zip-text");
|
|
62
48
|
const text_flow_1 = require("../text-flow");
|
|
63
49
|
const hide_slide_1 = require("../hide-slide");
|
|
64
50
|
const toBuffer = (pptx) => Buffer.isBuffer(pptx)
|
|
@@ -66,68 +52,93 @@ const toBuffer = (pptx) => Buffer.isBuffer(pptx)
|
|
|
66
52
|
: pptx instanceof ArrayBuffer
|
|
67
53
|
? Buffer.from(pptx)
|
|
68
54
|
: Buffer.from(pptx.buffer, pptx.byteOffset, pptx.byteLength);
|
|
69
|
-
const loadContent = (pptx) =>
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
55
|
+
const loadContent = async (pptx) => typeof pptx === 'string' ? fs_1.default.promises.readFile(pptx) : toBuffer(pptx);
|
|
56
|
+
/** Renders `slides` of a deck into a new deck (renderDeck's engine). */
|
|
57
|
+
async function buildDeck(content,
|
|
58
|
+
/** `content`, loaded: shared by the root and the source template. */
|
|
59
|
+
loaded,
|
|
60
|
+
/** The parse cache of the counting archive, shared with the deck's. */
|
|
61
|
+
parseCache, data, renderOptions, select) {
|
|
62
|
+
// Loaded here, through the package entry: upstream helpers import
|
|
63
|
+
// src/index.ts, so loading automizer.ts or the template logic first (as
|
|
64
|
+
// the CLI does) breaks on the import cycle
|
|
65
|
+
const { default: Automizer, CallbackError, modify, TemplateRenderError, } = await Promise.resolve().then(() => __importStar(require('../../index')));
|
|
66
|
+
const pres = new Automizer({
|
|
67
|
+
removeExistingSlides: true,
|
|
68
|
+
// the template's own slides leave the archive in removeUnreachableParts
|
|
69
|
+
verbosity: 0,
|
|
70
|
+
})
|
|
71
|
+
.loadRoot(content)
|
|
72
|
+
.load(content, 'deck');
|
|
73
|
+
// Loading a zip reads the whole file byte by byte (JSZip); the deck is
|
|
74
|
+
// loaded once, and each archive gets its own list of the same parts
|
|
75
|
+
usePreloaded(pres.rootTemplate.archive, loaded);
|
|
76
|
+
usePreloaded(pres.getTemplate('deck').archive, loaded);
|
|
77
|
+
// the slides counted are the ones the deck gets: parsed once
|
|
78
|
+
shareParseCache(parseCache, pres.rootTemplate.archive);
|
|
79
|
+
shareParseCache(parseCache, pres.getTemplate('deck').archive);
|
|
80
|
+
const available = await pres.getTemplate('deck').getAllSlideNumbers();
|
|
81
|
+
const slides = await select(available);
|
|
82
|
+
const missing = slides
|
|
83
|
+
.map((s) => s.number)
|
|
84
|
+
.filter((n) => !available.includes(n));
|
|
85
|
+
if (missing.length) {
|
|
86
|
+
throw new Error(`The deck has no slide ${missing.join(', ')} (slides: ${available.join(', ')})`);
|
|
87
|
+
}
|
|
88
|
+
for (const { number, page, flowCache, flowShown } of slides) {
|
|
89
|
+
pres.addSlide('deck', number, (slide) => {
|
|
90
|
+
const render = modify.renderTemplate(data, {
|
|
91
|
+
...renderOptions,
|
|
92
|
+
...(flowCache ? { flowCache } : {}),
|
|
93
|
+
...(flowShown ? { flowShown } : {}),
|
|
94
|
+
...(page === undefined ? {} : { flowPage: page }),
|
|
104
95
|
});
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return yield zip.generateAsync({
|
|
114
|
-
type: 'nodebuffer',
|
|
115
|
-
compression: 'DEFLATE',
|
|
96
|
+
slide.modify(async (document, context) => {
|
|
97
|
+
try {
|
|
98
|
+
await render(document, context);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
102
|
+
throw new TemplateRenderError(`slide ${number}: ${message}`);
|
|
103
|
+
}
|
|
116
104
|
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
const zip = await pres.getJSZip();
|
|
109
|
+
await (0, prune_1.removeUnreachableParts)(zip);
|
|
110
|
+
// HIDE-SLIDE has been applied
|
|
111
|
+
await (0, hide_slide_1.stripHideSlideTagsInDeck)(zip, renderOptions);
|
|
112
|
+
return await (0, zip_writer_1.generatePptx)(zip);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
// Automizer wraps callback errors; the tag error is what users need
|
|
116
|
+
if (error instanceof CallbackError && error.cause instanceof Error) {
|
|
117
|
+
throw error.cause;
|
|
117
118
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (error instanceof CallbackError && error.cause instanceof Error) {
|
|
121
|
-
throw error.cause;
|
|
122
|
-
}
|
|
123
|
-
throw error;
|
|
124
|
-
}
|
|
125
|
-
});
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
126
121
|
}
|
|
122
|
+
/** Lets an archive copy parts the cache has parsed already. */
|
|
123
|
+
const shareParseCache = (cache, archive) => {
|
|
124
|
+
if (archive instanceof archive_1.default)
|
|
125
|
+
archive.parseCache = cache;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Lets a not yet opened jszip archive use a copy of `zip` instead of
|
|
129
|
+
* loading its file again. The copy shares the parts, which JSZip never
|
|
130
|
+
* changes in place (zip.file() and zip.remove() replace or drop them).
|
|
131
|
+
*/
|
|
132
|
+
const usePreloaded = (archive, zip) => {
|
|
133
|
+
if (!(archive instanceof archive_jszip_1.default) || archive.archive)
|
|
134
|
+
return;
|
|
135
|
+
const copy = new jszip_1.default();
|
|
136
|
+
Object.keys(zip.files).forEach((name) => (copy.files[name] = zip.files[name]));
|
|
137
|
+
archive.archive = copy;
|
|
138
|
+
};
|
|
127
139
|
/** Whether a slide of the deck calls flow() (cheap text check). */
|
|
128
|
-
const usesFlow = (zip, number) =>
|
|
129
|
-
|
|
130
|
-
const xml = yield ((_a = zip.file(`ppt/slides/slide${number}.xml`)) === null || _a === void 0 ? void 0 : _a.async('string'));
|
|
140
|
+
const usesFlow = async (zip, number) => {
|
|
141
|
+
const xml = await (0, zip_text_1.readText)(zip, ppt_paths_1.PptPaths.slide(number));
|
|
131
142
|
if (!xml)
|
|
132
143
|
return false;
|
|
133
144
|
// Runs joined: a tag can be split across several a:t
|
|
@@ -135,7 +146,7 @@ const usesFlow = (zip, number) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
135
146
|
.map((m) => m[1])
|
|
136
147
|
.join('');
|
|
137
148
|
return /flow\s*\(/.test(text);
|
|
138
|
-
}
|
|
149
|
+
};
|
|
139
150
|
/**
|
|
140
151
|
* How many slides the `flow()` lists of one template slide need with this
|
|
141
152
|
* data: render the slide that many times, with `flowPage: 0`, `1`, ….
|
|
@@ -144,21 +155,52 @@ const usesFlow = (zip, number) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
144
155
|
* @param pptx Path to a .pptx file or its contents.
|
|
145
156
|
* @param slide 1-based number of the slide in the template.
|
|
146
157
|
*/
|
|
147
|
-
const countFlowPages =
|
|
148
|
-
const content =
|
|
149
|
-
return flowPagesOf(content,
|
|
150
|
-
}
|
|
158
|
+
const countFlowPages = async (pptx, slide, data, options = {}) => {
|
|
159
|
+
const content = await loadContent(pptx);
|
|
160
|
+
return flowPagesOf(openCountDeck(content, await jszip_1.default.loadAsync(content)), slide, data, options);
|
|
161
|
+
};
|
|
151
162
|
exports.countFlowPages = countFlowPages;
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
|
|
163
|
+
const openCountDeck = (content, zip) => {
|
|
164
|
+
const archive = new archive_jszip_1.default(content, { mode: 'jszip' });
|
|
165
|
+
// the zip is loaded already
|
|
166
|
+
archive.archive = zip;
|
|
167
|
+
return { zip, archive };
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* countFlowPages with the deck loaded already. Renders the slide by itself,
|
|
171
|
+
* the way slide.modify() gets it in renderDeck (same slide XML, layout,
|
|
172
|
+
* master and theme), without building a deck: the slide is rendered into
|
|
173
|
+
* a copy that is thrown away.
|
|
174
|
+
*/
|
|
175
|
+
const flowPagesOf = async (deck, slide, data, options) => {
|
|
176
|
+
if (!(await usesFlow(deck.zip, slide)))
|
|
155
177
|
return 1;
|
|
178
|
+
// Loaded here, through the package entry (see buildDeck)
|
|
179
|
+
const { modify, TemplateRenderError } = await Promise.resolve().then(() => __importStar(require('../../index')));
|
|
180
|
+
const slidePath = ppt_paths_1.PptPaths.slide(slide);
|
|
181
|
+
const document = deck.archive.parseXml(await (0, zip_text_1.readText)(deck.zip, slidePath));
|
|
156
182
|
let pages = 1;
|
|
157
|
-
|
|
183
|
+
const render = modify.renderTemplate(data, {
|
|
184
|
+
...options,
|
|
158
185
|
// the overflow is what is being counted, not an error
|
|
159
|
-
flowOverflow: 'warn',
|
|
186
|
+
flowOverflow: 'warn',
|
|
187
|
+
flowPage: Number.MAX_SAFE_INTEGER,
|
|
188
|
+
onFlowPages: (count) => (pages = Math.max(pages, count)),
|
|
189
|
+
});
|
|
190
|
+
try {
|
|
191
|
+
await render(document, {
|
|
192
|
+
targetArchive: deck.archive,
|
|
193
|
+
targetPath: slidePath,
|
|
194
|
+
// no pictures: they do not change where the text goes
|
|
195
|
+
countOnly: true,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
200
|
+
throw new TemplateRenderError(`slide ${slide}: ${message}`);
|
|
201
|
+
}
|
|
160
202
|
return pages;
|
|
161
|
-
}
|
|
203
|
+
};
|
|
162
204
|
/**
|
|
163
205
|
* Renders the tags of every slide of a template with one set of data and
|
|
164
206
|
* returns the new .pptx: `renderTemplate` applied to each slide, the masters
|
|
@@ -178,50 +220,53 @@ const flowPagesOf = (content, zip, slide, data, options) => __awaiter(void 0, vo
|
|
|
178
220
|
*
|
|
179
221
|
* @param pptx Path to a .pptx file or its contents.
|
|
180
222
|
*/
|
|
181
|
-
const renderDeck =
|
|
182
|
-
const { slides
|
|
183
|
-
const content =
|
|
184
|
-
const zip =
|
|
185
|
-
|
|
186
|
-
|
|
223
|
+
const renderDeck = async (pptx, data, options = {}) => {
|
|
224
|
+
const { slides, ...renderOptions } = options;
|
|
225
|
+
const content = await loadContent(pptx);
|
|
226
|
+
const zip = await jszip_1.default.loadAsync(content);
|
|
227
|
+
const deck = openCountDeck(content, zip);
|
|
228
|
+
return buildDeck(content, zip, deck.archive.parseCache, data, renderOptions, async (available) => {
|
|
187
229
|
const result = [];
|
|
188
230
|
// The copies of a slide share the measurement of its lists
|
|
189
231
|
const caches = new Map();
|
|
190
232
|
// flowContinue(): the entries of the flow() lists on the slides so far
|
|
191
233
|
const shown = new text_flow_1.FlowShown();
|
|
192
|
-
for (const number of slides
|
|
234
|
+
for (const number of slides ?? available) {
|
|
193
235
|
if (!caches.has(number))
|
|
194
236
|
caches.set(number, new text_flow_1.FlowCache());
|
|
195
237
|
const flowCache = caches.get(number);
|
|
196
238
|
const flowShown = shown.clone();
|
|
197
|
-
const slideOptions =
|
|
239
|
+
const slideOptions = { ...renderOptions, flowShown };
|
|
198
240
|
const exists = available.includes(number);
|
|
199
241
|
// {{HIDE-SLIDE …}} in the notes, evaluated per copy of the slide
|
|
200
242
|
const hide = exists
|
|
201
|
-
?
|
|
243
|
+
? await (0, hide_slide_1.hideSlideConditions)(zip, number, renderOptions)
|
|
202
244
|
: [];
|
|
203
|
-
const hidden = (page, pages) =>
|
|
204
|
-
var _a;
|
|
245
|
+
const hidden = async (page, pages) => {
|
|
205
246
|
try {
|
|
206
|
-
return
|
|
247
|
+
return await (0, hide_slide_1.evaluateHideConditions)(hide, data, slideOptions, renderOptions.flowPage ?? page, pages);
|
|
207
248
|
}
|
|
208
249
|
catch (error) {
|
|
209
250
|
throw (0, hide_slide_1.withSlideNumber)(error, number);
|
|
210
251
|
}
|
|
211
|
-
}
|
|
252
|
+
};
|
|
212
253
|
// Hidden whatever flowPage is: no need to measure its lists
|
|
213
254
|
const perPage = hide.some((c) => /\bflowPages?\b/.test(c.code));
|
|
214
|
-
if (hide.length && !perPage && (
|
|
255
|
+
if (hide.length && !perPage && (await hidden(0, 1)))
|
|
215
256
|
continue;
|
|
216
257
|
// a slide whose flow() lists need more room repeats. Measured also
|
|
217
258
|
// with a fixed flowPage: flowContinue() needs what the slide shows
|
|
218
259
|
const plans = [];
|
|
219
260
|
const counted = exists
|
|
220
|
-
?
|
|
261
|
+
? await flowPagesOf(deck, number, data, {
|
|
262
|
+
...slideOptions,
|
|
263
|
+
flowCache,
|
|
264
|
+
onFlowPlan: (plan, list) => plans.push({ plan, list }),
|
|
265
|
+
})
|
|
221
266
|
: 1;
|
|
222
267
|
const pages = renderOptions.flowPage === undefined ? counted : 1;
|
|
223
268
|
for (let page = 0; page < pages; page++) {
|
|
224
|
-
if (perPage && (
|
|
269
|
+
if (perPage && (await hidden(page, counted)))
|
|
225
270
|
continue;
|
|
226
271
|
result.push({
|
|
227
272
|
number,
|
|
@@ -229,12 +274,12 @@ const renderDeck = (pptx_1, data_1, ...args_1) => __awaiter(void 0, [pptx_1, dat
|
|
|
229
274
|
flowCache,
|
|
230
275
|
flowShown,
|
|
231
276
|
});
|
|
232
|
-
const onSlide =
|
|
277
|
+
const onSlide = renderOptions.flowPage ?? page;
|
|
233
278
|
plans.forEach(({ plan, list }) => shown.add((0, text_flow_1.flowPlanEntries)(plan, onSlide), list));
|
|
234
279
|
}
|
|
235
280
|
}
|
|
236
281
|
return result;
|
|
237
|
-
})
|
|
238
|
-
}
|
|
282
|
+
});
|
|
283
|
+
};
|
|
239
284
|
exports.renderDeck = renderDeck;
|
|
240
285
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/template-render/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,kDAA0B;AAK1B,4CAA+E;AAC/E,8CAKuB;AAUvB,MAAM,QAAQ,GAAG,CAAC,IAAuC,EAAU,EAAE,CACnE,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;IACnB,CAAC,CAAC,IAAI;IACN,CAAC,CAAC,IAAI,YAAY,WAAW;QAC3B,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;QACnB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;AAUnE,MAAM,WAAW,GAAG,CAClB,IAAgD,EAC/B,EAAE,kDACnB,OAAA,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA,GAAA,C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../helper/archive/archive-jszip';\nimport Archive from '../../helper/archive/archive';\nimport { XmlParseCache } from '../../helper/xml-parse-cache';\nimport { PptPaths } from '../../helper/ppt-paths';\nimport { removeUnreachableParts } from './prune';\nimport { generatePptx } from './zip-writer';\nimport { readText } from './zip-text';\nimport type {\n RenderTemplateOptions,\n TemplateData,\n} from '../template-logic/types';\nimport { FlowCache, FlowPlan, flowPlanEntries, FlowShown } from '../text-flow';\nimport {\n evaluateHideConditions,\n hideSlideConditions,\n stripHideSlideTagsInDeck,\n withSlideNumber,\n} from '../hide-slide';\n\nexport type RenderDeckOptions = RenderTemplateOptions & {\n /**\n * 1-based numbers of the slides to keep, in this order. Default: every\n * slide of the deck, in its order.\n */\n slides?: number[];\n};\n\nconst toBuffer = (pptx: Buffer | Uint8Array | ArrayBuffer): Buffer =>\n Buffer.isBuffer(pptx)\n ? pptx\n : pptx instanceof ArrayBuffer\n ? Buffer.from(pptx)\n : Buffer.from(pptx.buffer, pptx.byteOffset, pptx.byteLength);\n\ntype DeckSlide = {\n number: number;\n page?: number;\n flowCache?: FlowCache;\n /** What the slides before it show, for flowContinue(). */\n flowShown?: FlowShown;\n};\n\nconst loadContent = async (\n pptx: string | Buffer | Uint8Array | ArrayBuffer,\n): Promise<Buffer> =>\n typeof pptx === 'string' ? fs.promises.readFile(pptx) : toBuffer(pptx);\n\ntype SelectSlides = (available: number[]) => Promise<DeckSlide[]> | DeckSlide[];\n\n/** Renders `slides` of a deck into a new deck (renderDeck's engine). */\nasync function buildDeck(\n content: Buffer,\n /** `content`, loaded: shared by the root and the source template. */\n loaded: JSZip,\n /** The parse cache of the counting archive, shared with the deck's. */\n parseCache: XmlParseCache,\n data: TemplateData,\n renderOptions: RenderTemplateOptions,\n select: SelectSlides,\n): Promise<Buffer> {\n // Loaded here, through the package entry: upstream helpers import\n // src/index.ts, so loading automizer.ts or the template logic first (as\n // the CLI does) breaks on the import cycle\n const {\n default: Automizer,\n CallbackError,\n modify,\n TemplateRenderError,\n } = await import('../../index');\n const pres = new Automizer({\n removeExistingSlides: true,\n // the template's own slides leave the archive in removeUnreachableParts\n verbosity: 0,\n })\n .loadRoot(content)\n .load(content, 'deck');\n // Loading a zip reads the whole file byte by byte (JSZip); the deck is\n // loaded once, and each archive gets its own list of the same parts\n usePreloaded(pres.rootTemplate.archive, loaded);\n usePreloaded(pres.getTemplate('deck').archive, loaded);\n // the slides counted are the ones the deck gets: parsed once\n shareParseCache(parseCache, pres.rootTemplate.archive);\n shareParseCache(parseCache, pres.getTemplate('deck').archive);\n\n const available = await pres.getTemplate('deck').getAllSlideNumbers();\n const slides = await select(available);\n const missing = slides\n .map((s) => s.number)\n .filter((n) => !available.includes(n));\n if (missing.length) {\n throw new Error(\n `The deck has no slide ${missing.join(', ')} (slides: ${available.join(', ')})`,\n );\n }\n\n for (const { number, page, flowCache, flowShown } of slides) {\n pres.addSlide('deck', number, (slide) => {\n const render = modify.renderTemplate(data, {\n ...renderOptions,\n ...(flowCache ? { flowCache } : {}),\n ...(flowShown ? { flowShown } : {}),\n ...(page === undefined ? {} : { flowPage: page }),\n });\n slide.modify(async (document, context) => {\n try {\n await render(document, context);\n } catch (error) {\n const message =\n error instanceof Error ? error.message : String(error);\n throw new TemplateRenderError(`slide ${number}: ${message}`);\n }\n });\n });\n }\n\n try {\n const zip = await pres.getJSZip();\n await removeUnreachableParts(zip);\n // HIDE-SLIDE has been applied\n await stripHideSlideTagsInDeck(zip, renderOptions);\n return await generatePptx(zip);\n } catch (error) {\n // Automizer wraps callback errors; the tag error is what users need\n if (error instanceof CallbackError && error.cause instanceof Error) {\n throw error.cause;\n }\n throw error;\n }\n}\n\n/** Lets an archive copy parts the cache has parsed already. */\nconst shareParseCache = (cache: XmlParseCache, archive: unknown): void => {\n if (archive instanceof Archive) archive.parseCache = cache;\n};\n\n/**\n * Lets a not yet opened jszip archive use a copy of `zip` instead of\n * loading its file again. The copy shares the parts, which JSZip never\n * changes in place (zip.file() and zip.remove() replace or drop them).\n */\nconst usePreloaded = (archive: unknown, zip: JSZip): void => {\n if (!(archive instanceof ArchiveJszip) || archive.archive) return;\n const copy = new JSZip();\n Object.keys(zip.files).forEach(\n (name) => (copy.files[name] = zip.files[name]),\n );\n archive.archive = copy;\n};\n\n/** Whether a slide of the deck calls flow() (cheap text check). */\nconst usesFlow = async (zip: JSZip, number: number): Promise<boolean> => {\n const xml = await readText(zip, PptPaths.slide(number));\n if (!xml) return false;\n // Runs joined: a tag can be split across several a:t\n const text = [...xml.matchAll(/<a:t(?:\\s[^>]*)?>([^<]*)<\\/a:t>/g)]\n .map((m) => m[1])\n .join('');\n return /flow\\s*\\(/.test(text);\n};\n\n/**\n * How many slides the `flow()` lists of one template slide need with this\n * data: render the slide that many times, with `flowPage: 0`, `1`, ….\n * `renderDeck` does this by itself.\n *\n * @param pptx Path to a .pptx file or its contents.\n * @param slide 1-based number of the slide in the template.\n */\nexport const countFlowPages = async (\n pptx: string | Buffer | Uint8Array | ArrayBuffer,\n slide: number,\n data: TemplateData,\n options: RenderTemplateOptions = {},\n): Promise<number> => {\n const content = await loadContent(pptx);\n return flowPagesOf(\n openCountDeck(content, await JSZip.loadAsync(content)),\n slide,\n data,\n options,\n );\n};\n\n/**\n * The deck opened once for countFlowPages: layouts, masters and themes are\n * parsed once and shared by the counts of all its slides.\n */\ntype CountDeck = { zip: JSZip; archive: ArchiveJszip };\n\nconst openCountDeck = (content: Buffer, zip: JSZip): CountDeck => {\n const archive = new ArchiveJszip(content, { mode: 'jszip' });\n // the zip is loaded already\n archive.archive = zip;\n return { zip, archive };\n};\n\n/**\n * countFlowPages with the deck loaded already. Renders the slide by itself,\n * the way slide.modify() gets it in renderDeck (same slide XML, layout,\n * master and theme), without building a deck: the slide is rendered into\n * a copy that is thrown away.\n */\nconst flowPagesOf = async (\n deck: CountDeck,\n slide: number,\n data: TemplateData,\n options: RenderTemplateOptions,\n): Promise<number> => {\n if (!(await usesFlow(deck.zip, slide))) return 1;\n // Loaded here, through the package entry (see buildDeck)\n const { modify, TemplateRenderError } = await import('../../index');\n const slidePath = PptPaths.slide(slide);\n const document = deck.archive.parseXml(await readText(deck.zip, slidePath));\n let pages = 1;\n const render = modify.renderTemplate(data, {\n ...options,\n // the overflow is what is being counted, not an error\n flowOverflow: 'warn',\n flowPage: Number.MAX_SAFE_INTEGER,\n onFlowPages: (count) => (pages = Math.max(pages, count)),\n });\n try {\n await render(document, {\n targetArchive: deck.archive,\n targetPath: slidePath,\n // no pictures: they do not change where the text goes\n countOnly: true,\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n throw new TemplateRenderError(`slide ${slide}: ${message}`);\n }\n return pages;\n};\n\n/**\n * Renders the tags of every slide of a template with one set of data and\n * returns the new .pptx: `renderTemplate` applied to each slide, the masters\n * and layouts of the template kept as they are.\n *\n * A failing tag rejects with a `TemplateRenderError` whose message starts\n * with the slide number (\"slide 2: {{euro(p.preis)}}: Not a function …\").\n *\n * A slide whose `flow()` lists do not fit is repeated as often as needed,\n * each copy with the next entries (`flowPage` 1, 2, … in the template).\n *\n * A slide with `{{HIDE-SLIDE condition}}` in its speaker notes is left out\n * when the condition is true; the tag itself is removed from the notes.\n *\n * `flowContinue(list)` in a template is `list` without the entries that\n * `flow()` shows on the slides before it, hidden copies not counted.\n *\n * @param pptx Path to a .pptx file or its contents.\n */\nexport const renderDeck = async (\n pptx: string | Buffer | Uint8Array | ArrayBuffer,\n data: TemplateData,\n options: RenderDeckOptions = {},\n): Promise<Buffer> => {\n const { slides, ...renderOptions } = options;\n const content = await loadContent(pptx);\n const zip = await JSZip.loadAsync(content);\n const deck = openCountDeck(content, zip);\n return buildDeck(\n content,\n zip,\n deck.archive.parseCache,\n data,\n renderOptions,\n async (available) => {\n const result: DeckSlide[] = [];\n // The copies of a slide share the measurement of its lists\n const caches = new Map<number, FlowCache>();\n // flowContinue(): the entries of the flow() lists on the slides so far\n const shown = new FlowShown();\n for (const number of slides ?? available) {\n if (!caches.has(number)) caches.set(number, new FlowCache());\n const flowCache = caches.get(number);\n const flowShown = shown.clone();\n const slideOptions = { ...renderOptions, flowShown };\n const exists = available.includes(number);\n // {{HIDE-SLIDE …}} in the notes, evaluated per copy of the slide\n const hide = exists\n ? await hideSlideConditions(zip, number, renderOptions)\n : [];\n const hidden = async (page: number, pages: number) => {\n try {\n return await evaluateHideConditions(\n hide,\n data,\n slideOptions,\n renderOptions.flowPage ?? page,\n pages,\n );\n } catch (error) {\n throw withSlideNumber(error, number);\n }\n };\n // Hidden whatever flowPage is: no need to measure its lists\n const perPage = hide.some((c) => /\\bflowPages?\\b/.test(c.code));\n if (hide.length && !perPage && (await hidden(0, 1))) continue;\n\n // a slide whose flow() lists need more room repeats. Measured also\n // with a fixed flowPage: flowContinue() needs what the slide shows\n const plans: { plan: FlowPlan; list: unknown }[] = [];\n const counted = exists\n ? await flowPagesOf(deck, number, data, {\n ...slideOptions,\n flowCache,\n onFlowPlan: (plan, list) => plans.push({ plan, list }),\n })\n : 1;\n const pages = renderOptions.flowPage === undefined ? counted : 1;\n for (let page = 0; page < pages; page++) {\n if (perPage && (await hidden(page, counted))) continue;\n result.push({\n number,\n page: pages > 1 ? page : undefined,\n flowCache,\n flowShown,\n });\n const onSlide = renderOptions.flowPage ?? page;\n plans.forEach(({ plan, list }) =>\n shown.add(flowPlanEntries(plan, onSlide), list),\n );\n }\n }\n return result;\n },\n );\n};\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import JSZip from 'jszip';
|
|
2
|
+
/**
|
|
3
|
+
* The cleanup of renderDeck: removes every part of the package that no
|
|
4
|
+
* relationship reaches any more, starting from `_rels/.rels`. These are the
|
|
5
|
+
* template's own slides (removeExistingSlides only drops them from the slide
|
|
6
|
+
* list) with their notes, charts, embeddings and pictures.
|
|
7
|
+
*
|
|
8
|
+
* It replaces Automizer's `cleanup` option there, which parses every slide
|
|
9
|
+
* once more to find the pictures it uses; this reads the `.rels` parts as
|
|
10
|
+
* text only. Like `cleanup`, a picture counts as used only where its
|
|
11
|
+
* relationship id appears in the part (a replaced picture leaves its
|
|
12
|
+
* relationship behind).
|
|
13
|
+
*/
|
|
14
|
+
export declare const removeUnreachableParts: (zip: JSZip) => Promise<void>;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeUnreachableParts = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const zip_text_1 = require("./zip-text");
|
|
6
|
+
/**
|
|
7
|
+
* The cleanup of renderDeck: removes every part of the package that no
|
|
8
|
+
* relationship reaches any more, starting from `_rels/.rels`. These are the
|
|
9
|
+
* template's own slides (removeExistingSlides only drops them from the slide
|
|
10
|
+
* list) with their notes, charts, embeddings and pictures.
|
|
11
|
+
*
|
|
12
|
+
* It replaces Automizer's `cleanup` option there, which parses every slide
|
|
13
|
+
* once more to find the pictures it uses; this reads the `.rels` parts as
|
|
14
|
+
* text only. Like `cleanup`, a picture counts as used only where its
|
|
15
|
+
* relationship id appears in the part (a replaced picture leaves its
|
|
16
|
+
* relationship behind).
|
|
17
|
+
*/
|
|
18
|
+
const removeUnreachableParts = async (zip) => {
|
|
19
|
+
const files = new Set(Object.keys(zip.files).filter((name) => !zip.files[name].dir));
|
|
20
|
+
const reachable = new Set(['[Content_Types].xml']);
|
|
21
|
+
const queue = [''];
|
|
22
|
+
while (queue.length) {
|
|
23
|
+
const part = queue.shift();
|
|
24
|
+
const relsPath = relsOf(part);
|
|
25
|
+
if (!files.has(relsPath))
|
|
26
|
+
continue;
|
|
27
|
+
reachable.add(relsPath);
|
|
28
|
+
const rels = await (0, zip_text_1.readText)(zip, relsPath);
|
|
29
|
+
const relations = parseRelationships(rels);
|
|
30
|
+
// the part's own text, read only if it relates to pictures
|
|
31
|
+
let content;
|
|
32
|
+
for (const relation of relations) {
|
|
33
|
+
if (relation.external)
|
|
34
|
+
continue;
|
|
35
|
+
const target = resolveTarget(part, relation.target);
|
|
36
|
+
if (!target || reachable.has(target) || !files.has(target))
|
|
37
|
+
continue;
|
|
38
|
+
if (relation.image && part) {
|
|
39
|
+
content ??= await (0, zip_text_1.readText)(zip, part);
|
|
40
|
+
const id = relation.id;
|
|
41
|
+
if (!content.includes(`"${id}"`) && !content.includes(`'${id}'`)) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
reachable.add(target);
|
|
46
|
+
queue.push(target);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
[...files]
|
|
50
|
+
.filter((file) => !reachable.has(file))
|
|
51
|
+
.forEach((file) => {
|
|
52
|
+
zip.remove(file);
|
|
53
|
+
files.delete(file);
|
|
54
|
+
});
|
|
55
|
+
await removeContentTypeOverrides(zip, files);
|
|
56
|
+
};
|
|
57
|
+
exports.removeUnreachableParts = removeUnreachableParts;
|
|
58
|
+
const attribute = (tag, name) => {
|
|
59
|
+
const match = new RegExp(`\\s${name}\\s*=\\s*("([^"]*)"|'([^']*)')`).exec(tag);
|
|
60
|
+
return match ? decodeEntities(match[2] ?? match[3]) : undefined;
|
|
61
|
+
};
|
|
62
|
+
const decodeEntities = (value) => value.replace(/&(amp|lt|gt|quot|apos|#x[0-9a-f]+|#\d+);/gi, (m, e) => {
|
|
63
|
+
switch (e.toLowerCase()) {
|
|
64
|
+
case 'amp':
|
|
65
|
+
return '&';
|
|
66
|
+
case 'lt':
|
|
67
|
+
return '<';
|
|
68
|
+
case 'gt':
|
|
69
|
+
return '>';
|
|
70
|
+
case 'quot':
|
|
71
|
+
return '"';
|
|
72
|
+
case 'apos':
|
|
73
|
+
return "'";
|
|
74
|
+
default:
|
|
75
|
+
return String.fromCodePoint(e[1].toLowerCase() === 'x'
|
|
76
|
+
? parseInt(e.slice(2), 16)
|
|
77
|
+
: parseInt(e.slice(1), 10));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
const parseRelationships = (xml) => [...xml.matchAll(/<(?:\w+:)?Relationship\b[^>]*>/g)].map(([tag]) => ({
|
|
81
|
+
id: attribute(tag, 'Id') ?? '',
|
|
82
|
+
target: attribute(tag, 'Target') ?? '',
|
|
83
|
+
external: attribute(tag, 'TargetMode') === 'External',
|
|
84
|
+
image: /\/image$/.test(attribute(tag, 'Type') ?? ''),
|
|
85
|
+
}));
|
|
86
|
+
/** `ppt/slides/slide1.xml` → `ppt/slides/_rels/slide1.xml.rels`. */
|
|
87
|
+
const relsOf = (part) => part
|
|
88
|
+
? path_1.posix.join(path_1.posix.dirname(part), '_rels', `${path_1.posix.basename(part)}.rels`)
|
|
89
|
+
: '_rels/.rels';
|
|
90
|
+
/** The part a relationship of `source` points at, as a zip path. */
|
|
91
|
+
const resolveTarget = (source, target) => {
|
|
92
|
+
if (!target)
|
|
93
|
+
return undefined;
|
|
94
|
+
let path = target.split('#')[0];
|
|
95
|
+
try {
|
|
96
|
+
path = decodeURIComponent(path);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// not percent-encoded
|
|
100
|
+
}
|
|
101
|
+
const resolved = path.startsWith('/')
|
|
102
|
+
? path_1.posix.normalize(path.slice(1))
|
|
103
|
+
: path_1.posix.normalize(path_1.posix.join(path_1.posix.dirname(source) || '.', path));
|
|
104
|
+
return resolved.startsWith('../') ? undefined : resolved;
|
|
105
|
+
};
|
|
106
|
+
/** Drops the content types of parts that are not in the package. */
|
|
107
|
+
const removeContentTypeOverrides = async (zip, files) => {
|
|
108
|
+
const xml = await (0, zip_text_1.readText)(zip, '[Content_Types].xml');
|
|
109
|
+
if (xml === undefined)
|
|
110
|
+
return;
|
|
111
|
+
let changed = false;
|
|
112
|
+
const result = xml.replace(/<(?:\w+:)?Override\b[^>]*>/g, (tag) => {
|
|
113
|
+
const name = attribute(tag, 'PartName');
|
|
114
|
+
if (!name)
|
|
115
|
+
return tag;
|
|
116
|
+
let part = name.replace(/^\//, '');
|
|
117
|
+
try {
|
|
118
|
+
part = decodeURIComponent(part);
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// not percent-encoded
|
|
122
|
+
}
|
|
123
|
+
if (files.has(part))
|
|
124
|
+
return tag;
|
|
125
|
+
changed = true;
|
|
126
|
+
return '';
|
|
127
|
+
});
|
|
128
|
+
if (changed)
|
|
129
|
+
zip.file('[Content_Types].xml', result);
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=prune.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prune.js","sourceRoot":"","sources":["../../../src/extensions/template-render/prune.ts"],"names":[],"mappings":";;;AAAA,+BAA6B;AAE7B,yCAAsC;AAEtC;;;;;;;;;;;GAWG;AACI,MAAM,sBAAsB,GAAG,KAAK,EAAE,GAAU,EAAiB,EAAE;IACxE,MAAM,KAAK,GAAG,IAAI,GAAG,CACnB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAC9D,CAAC;IACF,MAAM,SAAS,GAAG,IAAI,GAAG,CAAS,CAAC,qBAAqB,CAAC,CAAC,CAAC;IAC3D,MAAM,KAAK,GAAa,CAAC,EAAE,CAAC,CAAC;IAE7B,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;QACpB,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;QAC3B,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC;YAAE,SAAS;QACnC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACxB,MAAM,IAAI,GAAG,MAAM,IAAA,mBAAQ,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAC3C,MAAM,SAAS,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAC3C,2DAA2D;QAC3D,IAAI,OAA2B,CAAC;QAChC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C,CAAC;AAEF,oEAAoE;AACpE,MAAM,0BAA0B,GAAG,KAAK,EACtC,GAAU,EACV,KAAkB,EACH,EAAE;IACjB,MAAM,GAAG,GAAG,MAAM,IAAA,mBAAQ,EAAC,GAAG,EAAE,qBAAqB,CAAC,CAAC;IACvD,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO;IAC9B,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,6BAA6B,EAAE,CAAC,GAAG,EAAE,EAAE;QAChE,MAAM,IAAI,GAAG,SAAS,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI;YAAE,OAAO,GAAG,CAAC;QACtB,IAAI,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACnC,IAAI,CAAC;YACH,IAAI,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC;QAAC,MAAM,CAAC;YACP,sBAAsB;QACxB,CAAC;QACD,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,OAAO,GAAG,CAAC;QAChC,OAAO,GAAG,IAAI,CAAC;QACf,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;IACH,IAAI,OAAO;QAAE,GAAG,CAAC,IAAI,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACvD,CAAC,CAAC","sourcesContent":["import { posix } from 'path';\nimport JSZip from 'jszip';\nimport { readText } from './zip-text';\n\n/**\n * The cleanup of renderDeck: removes every part of the package that no\n * relationship reaches any more, starting from `_rels/.rels`. These are the\n * template's own slides (removeExistingSlides only drops them from the slide\n * list) with their notes, charts, embeddings and pictures.\n *\n * It replaces Automizer's `cleanup` option there, which parses every slide\n * once more to find the pictures it uses; this reads the `.rels` parts as\n * text only. Like `cleanup`, a picture counts as used only where its\n * relationship id appears in the part (a replaced picture leaves its\n * relationship behind).\n */\nexport const removeUnreachableParts = async (zip: JSZip): Promise<void> => {\n const files = new Set(\n Object.keys(zip.files).filter((name) => !zip.files[name].dir),\n );\n const reachable = new Set<string>(['[Content_Types].xml']);\n const queue: string[] = [''];\n\n while (queue.length) {\n const part = queue.shift();\n const relsPath = relsOf(part);\n if (!files.has(relsPath)) continue;\n reachable.add(relsPath);\n const rels = await readText(zip, relsPath);\n const relations = parseRelationships(rels);\n // the part's own text, read only if it relates to pictures\n let content: string | undefined;\n for (const relation of relations) {\n if (relation.external) continue;\n const target = resolveTarget(part, relation.target);\n if (!target || reachable.has(target) || !files.has(target)) continue;\n if (relation.image && part) {\n content ??= await readText(zip, part);\n const id = relation.id;\n if (!content.includes(`\"${id}\"`) && !content.includes(`'${id}'`)) {\n continue;\n }\n }\n reachable.add(target);\n queue.push(target);\n }\n }\n\n [...files]\n .filter((file) => !reachable.has(file))\n .forEach((file) => {\n zip.remove(file);\n files.delete(file);\n });\n await removeContentTypeOverrides(zip, files);\n};\n\ntype Relationship = {\n id: string;\n target: string;\n external: boolean;\n image: boolean;\n};\n\nconst attribute = (tag: string, name: string): string | undefined => {\n const match = new RegExp(`\\\\s${name}\\\\s*=\\\\s*(\"([^\"]*)\"|'([^']*)')`).exec(\n tag,\n );\n return match ? decodeEntities(match[2] ?? match[3]) : undefined;\n};\n\nconst decodeEntities = (value: string): string =>\n value.replace(/&(amp|lt|gt|quot|apos|#x[0-9a-f]+|#\\d+);/gi, (m, e) => {\n switch (e.toLowerCase()) {\n case 'amp':\n return '&';\n case 'lt':\n return '<';\n case 'gt':\n return '>';\n case 'quot':\n return '\"';\n case 'apos':\n return \"'\";\n default:\n return String.fromCodePoint(\n e[1].toLowerCase() === 'x'\n ? parseInt(e.slice(2), 16)\n : parseInt(e.slice(1), 10),\n );\n }\n });\n\nconst parseRelationships = (xml: string): Relationship[] =>\n [...xml.matchAll(/<(?:\\w+:)?Relationship\\b[^>]*>/g)].map(([tag]) => ({\n id: attribute(tag, 'Id') ?? '',\n target: attribute(tag, 'Target') ?? '',\n external: attribute(tag, 'TargetMode') === 'External',\n image: /\\/image$/.test(attribute(tag, 'Type') ?? ''),\n }));\n\n/** `ppt/slides/slide1.xml` → `ppt/slides/_rels/slide1.xml.rels`. */\nconst relsOf = (part: string): string =>\n part\n ? posix.join(posix.dirname(part), '_rels', `${posix.basename(part)}.rels`)\n : '_rels/.rels';\n\n/** The part a relationship of `source` points at, as a zip path. */\nconst resolveTarget = (source: string, target: string): string | undefined => {\n if (!target) return undefined;\n let path = target.split('#')[0];\n try {\n path = decodeURIComponent(path);\n } catch {\n // not percent-encoded\n }\n const resolved = path.startsWith('/')\n ? posix.normalize(path.slice(1))\n : posix.normalize(posix.join(posix.dirname(source) || '.', path));\n return resolved.startsWith('../') ? undefined : resolved;\n};\n\n/** Drops the content types of parts that are not in the package. */\nconst removeContentTypeOverrides = async (\n zip: JSZip,\n files: Set<string>,\n): Promise<void> => {\n const xml = await readText(zip, '[Content_Types].xml');\n if (xml === undefined) return;\n let changed = false;\n const result = xml.replace(/<(?:\\w+:)?Override\\b[^>]*>/g, (tag) => {\n const name = attribute(tag, 'PartName');\n if (!name) return tag;\n let part = name.replace(/^\\//, '');\n try {\n part = decodeURIComponent(part);\n } catch {\n // not percent-encoded\n }\n if (files.has(part)) return tag;\n changed = true;\n return '';\n });\n if (changed) zip.file('[Content_Types].xml', result);\n};\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import JSZip from 'jszip';
|
|
2
|
+
/**
|
|
3
|
+
* The text of a part of `zip`, or undefined if there is none: what
|
|
4
|
+
* `zip.file(name)?.async('string')` returns. A part loaded from the file
|
|
5
|
+
* and unchanged since is inflated with Node's zlib right away (readFast);
|
|
6
|
+
* JSZip inflates in JavaScript and waits a macrotask per part, which adds
|
|
7
|
+
* up for the many small parts renderDeck reads.
|
|
8
|
+
*/
|
|
9
|
+
export declare const readText: (zip: JSZip, name: string) => Promise<string | undefined>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readText = void 0;
|
|
4
|
+
const jszip_fast_read_1 = require("../../helper/archive/jszip-fast-read");
|
|
5
|
+
/**
|
|
6
|
+
* The text of a part of `zip`, or undefined if there is none: what
|
|
7
|
+
* `zip.file(name)?.async('string')` returns. A part loaded from the file
|
|
8
|
+
* and unchanged since is inflated with Node's zlib right away (readFast);
|
|
9
|
+
* JSZip inflates in JavaScript and waits a macrotask per part, which adds
|
|
10
|
+
* up for the many small parts renderDeck reads.
|
|
11
|
+
*/
|
|
12
|
+
const readText = async (zip, name) => {
|
|
13
|
+
const file = zip.file(name);
|
|
14
|
+
if (!file)
|
|
15
|
+
return undefined;
|
|
16
|
+
const data = file._data;
|
|
17
|
+
if (typeof data === 'string') {
|
|
18
|
+
// set as text (zip.file(name, string)); JSZip returns it as it is
|
|
19
|
+
if (!file._dataBinary) {
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return ((await (0, jszip_fast_read_1.readFastAsync)(file, 'string')) ??
|
|
24
|
+
file.async('string'));
|
|
25
|
+
};
|
|
26
|
+
exports.readText = readText;
|
|
27
|
+
//# sourceMappingURL=zip-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip-text.js","sourceRoot":"","sources":["../../../src/extensions/template-render/zip-text.ts"],"names":[],"mappings":";;;AACA,0EAAqE;AAErE;;;;;;GAMG;AACI,MAAM,QAAQ,GAAG,KAAK,EAC3B,GAAU,EACV,IAAY,EACiB,EAAE;IAC/B,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAC5B,MAAM,IAAI,GAAI,IAAsC,CAAC,KAAK,CAAC;IAC3D,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,kEAAkE;QAClE,IAAI,CAAE,IAA6C,CAAC,WAAW,EAAE,CAAC;YAChE,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,OAAO,CACJ,CAAC,MAAM,IAAA,+BAAa,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAwB;QAC7D,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CACrB,CAAC;AACJ,CAAC,CAAC;AAjBW,QAAA,QAAQ,GAAR,QAAQ,CAiBnB","sourcesContent":["import JSZip from 'jszip';\nimport { readFastAsync } from '../../helper/archive/jszip-fast-read';\n\n/**\n * The text of a part of `zip`, or undefined if there is none: what\n * `zip.file(name)?.async('string')` returns. A part loaded from the file\n * and unchanged since is inflated with Node's zlib right away (readFast);\n * JSZip inflates in JavaScript and waits a macrotask per part, which adds\n * up for the many small parts renderDeck reads.\n */\nexport const readText = async (\n zip: JSZip,\n name: string,\n): Promise<string | undefined> => {\n const file = zip.file(name);\n if (!file) return undefined;\n const data = (file as unknown as { _data: unknown })._data;\n if (typeof data === 'string') {\n // set as text (zip.file(name, string)); JSZip returns it as it is\n if (!(file as unknown as { _dataBinary?: boolean })._dataBinary) {\n return data;\n }\n }\n return (\n ((await readFastAsync(file, 'string')) as string | undefined) ??\n file.async('string')\n );\n};\n"]}
|