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
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.TemplateRenderer = exports.TemplateRenderError = void 0;
|
|
13
|
-
const
|
|
4
|
+
const xml_serializer_1 = require("../../helper/xml-serializer");
|
|
5
|
+
const xml_find_1 = require("../../helper/xml-find");
|
|
14
6
|
const xml_helper_1 = require("../../helper/xml-helper");
|
|
15
7
|
const xml_relationship_helper_1 = require("../../helper/xml-relationship-helper");
|
|
16
8
|
const multitext_helper_1 = require("../../helper/multitext-helper");
|
|
@@ -21,6 +13,7 @@ const images_1 = require("./images");
|
|
|
21
13
|
const clone_1 = require("./clone");
|
|
22
14
|
const text_flow_1 = require("../text-flow");
|
|
23
15
|
const logger_1 = require("../../helper/logger");
|
|
16
|
+
const link_scheme_1 = require("../link-scheme");
|
|
24
17
|
/** Tags that open, split or close a block. */
|
|
25
18
|
const BLOCK_TYPES = [
|
|
26
19
|
'if',
|
|
@@ -102,20 +95,19 @@ class Scope {
|
|
|
102
95
|
}
|
|
103
96
|
/** Own variables, to undo the EXECs of a trial render. */
|
|
104
97
|
snapshot() {
|
|
105
|
-
return
|
|
98
|
+
return { ...this.vars };
|
|
106
99
|
}
|
|
107
100
|
restore(snapshot) {
|
|
108
101
|
Object.keys(this.vars).forEach((key) => delete this.vars[key]);
|
|
109
102
|
Object.assign(this.vars, snapshot);
|
|
110
103
|
}
|
|
111
104
|
assignExisting(name, value) {
|
|
112
|
-
var _a, _b;
|
|
113
105
|
if (this.writable &&
|
|
114
106
|
Object.prototype.hasOwnProperty.call(this.vars, name)) {
|
|
115
107
|
this.vars[name] = value;
|
|
116
108
|
return true;
|
|
117
109
|
}
|
|
118
|
-
return
|
|
110
|
+
return this.parent?.assignExisting(name, value) ?? false;
|
|
119
111
|
}
|
|
120
112
|
}
|
|
121
113
|
class TemplateRenderError extends Error {
|
|
@@ -125,11 +117,13 @@ class TemplateRenderError extends Error {
|
|
|
125
117
|
}
|
|
126
118
|
}
|
|
127
119
|
exports.TemplateRenderError = TemplateRenderError;
|
|
120
|
+
/** FOR iterations one renderer may run; nesting multiplies, so cap the total. */
|
|
121
|
+
const MAX_LOOP_ITERATIONS = 200_000;
|
|
128
122
|
class TemplateRenderer {
|
|
129
123
|
constructor(data, options = {}, context = {}) {
|
|
130
|
-
var _a, _b, _c, _d;
|
|
131
124
|
this.options = options;
|
|
132
125
|
this.context = context;
|
|
126
|
+
this.loopIterations = 0;
|
|
133
127
|
this.aliases = new Map();
|
|
134
128
|
this.errors = [];
|
|
135
129
|
this.links = new Map();
|
|
@@ -141,6 +135,8 @@ class TemplateRenderer {
|
|
|
141
135
|
this.flowLimits = new Map();
|
|
142
136
|
/** flow(list, n, options): the options per box, as an expression. */
|
|
143
137
|
this.flowOptions = new Map();
|
|
138
|
+
/** flow(): each box tokenized once, for all its measuring copies. */
|
|
139
|
+
this.copySources = new Map();
|
|
144
140
|
/** Rendering an alt text (renderAltTexts). */
|
|
145
141
|
this.inAltText = false;
|
|
146
142
|
this.hideSlideWarned = false;
|
|
@@ -148,8 +144,8 @@ class TemplateRenderer {
|
|
|
148
144
|
this.opening = syntax.opening;
|
|
149
145
|
this.tagPattern = syntax.pattern;
|
|
150
146
|
this.evaluation = {
|
|
151
|
-
strict:
|
|
152
|
-
allowStringPatterns:
|
|
147
|
+
strict: options.strict ?? false,
|
|
148
|
+
allowStringPatterns: options.allowStringPatterns ?? false,
|
|
153
149
|
};
|
|
154
150
|
// Built-in helpers; additionalJsContext and data can shadow them.
|
|
155
151
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
@@ -158,45 +154,43 @@ class TemplateRenderer {
|
|
|
158
154
|
flow: (list) => this.flowEntries(list),
|
|
159
155
|
flowRest: (list) => this.flowRest(list),
|
|
160
156
|
// the entries no earlier slide of the deck shows (renderDeck)
|
|
161
|
-
flowContinue: (list) =>
|
|
157
|
+
flowContinue: (list) => (options.flowShown ?? new text_flow_1.FlowShown()).continue(list),
|
|
162
158
|
// 1-based number of this slide among the slides a list needs
|
|
163
|
-
flowPage: (
|
|
159
|
+
flowPage: (options.flowPage ?? 0) + 1,
|
|
164
160
|
get flowPages() {
|
|
165
|
-
|
|
166
|
-
return (_b = (_a = self.textFlow) === null || _a === void 0 ? void 0 : _a.pages) !== null && _b !== void 0 ? _b : 1;
|
|
161
|
+
return self.textFlow?.pages ?? 1;
|
|
167
162
|
},
|
|
168
163
|
}, undefined, false);
|
|
169
|
-
const jsContext = new Scope(
|
|
170
|
-
this.root = new Scope({}, new Scope(data
|
|
164
|
+
const jsContext = new Scope(options.additionalJsContext ?? {}, builtins, false);
|
|
165
|
+
this.root = new Scope({}, new Scope(data ?? {}, jsContext, false));
|
|
171
166
|
}
|
|
172
|
-
render(element) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
this.
|
|
183
|
-
if (target.tagName === 'a:tbl') {
|
|
184
|
-
yield this.renderTable(target);
|
|
185
|
-
}
|
|
186
|
-
else if (this.containsTag(target)) {
|
|
187
|
-
const bodyTokens = this.tokenizeBody(target);
|
|
188
|
-
yield this.writeBody(target, bodyTokens, this.parse(bodyTokens.tokens, textControl), this.root);
|
|
189
|
-
yield this.placePendingImages(target);
|
|
190
|
-
}
|
|
167
|
+
async render(element) {
|
|
168
|
+
this.collectAliases(element);
|
|
169
|
+
const targets = this.findTargets(element);
|
|
170
|
+
this.setupFlow(targets);
|
|
171
|
+
// Collected before the text is rendered: alt text written while
|
|
172
|
+
// rendering (IMAGE … alt from the data) is content, not a template
|
|
173
|
+
const altTexts = this.altTextHolders(element);
|
|
174
|
+
for (const target of targets) {
|
|
175
|
+
this.currentBody = target.tagName === 'p:txBody' ? target : undefined;
|
|
176
|
+
if (target.tagName === 'a:tbl') {
|
|
177
|
+
await this.renderTable(target);
|
|
191
178
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
throw new TemplateRenderError(`Template rendering failed with ${this.errors.length} error(s):\n` +
|
|
197
|
-
this.errors.map((e) => `- ${e}`).join('\n'));
|
|
179
|
+
else if (this.containsTag(target)) {
|
|
180
|
+
const bodyTokens = this.tokenizeBody(target);
|
|
181
|
+
await this.writeBody(target, bodyTokens, this.parse(bodyTokens.tokens, textControl), this.root);
|
|
182
|
+
await this.placePendingImages(target);
|
|
198
183
|
}
|
|
199
|
-
}
|
|
184
|
+
}
|
|
185
|
+
// flow() cards left without an entry (the last slide of a list)
|
|
186
|
+
this.textFlow
|
|
187
|
+
?.emptyGroups()
|
|
188
|
+
.forEach((group) => group.parentNode?.removeChild(group));
|
|
189
|
+
await this.renderAltTexts(altTexts.filter((cNvPr) => isWithin(cNvPr, element)));
|
|
190
|
+
if (this.errors.length) {
|
|
191
|
+
throw new TemplateRenderError(`Template rendering failed with ${this.errors.length} error(s):\n` +
|
|
192
|
+
this.errors.map((e) => `- ${e}`).join('\n'));
|
|
193
|
+
}
|
|
200
194
|
}
|
|
201
195
|
/** `{{HIDE-SLIDE …}}` outside the speaker notes: removed, not applied. */
|
|
202
196
|
warnHideSlide(tag) {
|
|
@@ -215,7 +209,7 @@ class TemplateRenderer {
|
|
|
215
209
|
targets
|
|
216
210
|
.filter((t) => t.tagName === 'p:txBody' && this.containsTag(t))
|
|
217
211
|
.forEach((body) => {
|
|
218
|
-
const text =
|
|
212
|
+
const text = (0, xml_find_1.elementsByTagName)(body, 'a:t')
|
|
219
213
|
.map((t) => t.textContent)
|
|
220
214
|
.join('');
|
|
221
215
|
const keys = new Set();
|
|
@@ -256,7 +250,7 @@ class TemplateRenderer {
|
|
|
256
250
|
this.textFlow = new text_flow_1.TextFlow(boxes, {
|
|
257
251
|
renderCopy: (body, entries) => this.renderCopy(body, entries),
|
|
258
252
|
measureKey: (body) => this.flowMeasureKey(body),
|
|
259
|
-
styles: () =>
|
|
253
|
+
styles: async () => (await this.context.styles?.()) ?? {},
|
|
260
254
|
}, {
|
|
261
255
|
fonts: this.options.fonts,
|
|
262
256
|
flowOverflow: this.options.flowOverflow,
|
|
@@ -310,84 +304,90 @@ class TemplateRenderer {
|
|
|
310
304
|
evaluate: (scope, options) => {
|
|
311
305
|
if (this.flowOverride)
|
|
312
306
|
return expr.evaluate(scope, options);
|
|
313
|
-
return (() =>
|
|
307
|
+
return (async () => {
|
|
314
308
|
for (const list of lists) {
|
|
315
309
|
let value = list.expr.evaluate(scope, options);
|
|
316
310
|
if (isThenable(value))
|
|
317
|
-
value =
|
|
318
|
-
|
|
311
|
+
value = await value;
|
|
312
|
+
await this.textFlow.prepare(list.key, value, await this.flowLimitValues(scope, options), await this.flowUnmeasured(scope, options));
|
|
319
313
|
}
|
|
320
314
|
return expr.evaluate(scope, options);
|
|
321
|
-
})
|
|
315
|
+
})();
|
|
322
316
|
},
|
|
323
317
|
};
|
|
324
318
|
}
|
|
325
319
|
/** flow(list, n): the number `n` of each box that has one. */
|
|
326
|
-
flowLimitValues(scope, options) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
`must be a whole number of at least 1, not ${String(value)}`);
|
|
337
|
-
}
|
|
338
|
-
limits.set(body, limit);
|
|
320
|
+
async flowLimitValues(scope, options) {
|
|
321
|
+
const limits = new Map();
|
|
322
|
+
for (const [body, expr] of this.flowLimits) {
|
|
323
|
+
let value = expr.evaluate(scope, options);
|
|
324
|
+
if (isThenable(value))
|
|
325
|
+
value = await value;
|
|
326
|
+
const limit = Number(value);
|
|
327
|
+
if (!Number.isInteger(limit) || limit < 1) {
|
|
328
|
+
throw new Error(`flow(…, ${expr.source}): the number of entries per text box ` +
|
|
329
|
+
`must be a whole number of at least 1, not ${String(value)}`);
|
|
339
330
|
}
|
|
340
|
-
|
|
341
|
-
}
|
|
331
|
+
limits.set(body, limit);
|
|
332
|
+
}
|
|
333
|
+
return limits;
|
|
342
334
|
}
|
|
343
335
|
/** flow(list, n, { measure: false }): the boxes that are not measured. */
|
|
344
|
-
flowUnmeasured(scope, options) {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
`such as { measure: false }, not ${String(value)}`);
|
|
354
|
-
}
|
|
355
|
-
if (value.measure === false) {
|
|
356
|
-
unmeasured.add(body);
|
|
357
|
-
}
|
|
336
|
+
async flowUnmeasured(scope, options) {
|
|
337
|
+
const unmeasured = new Set();
|
|
338
|
+
for (const [body, expr] of this.flowOptions) {
|
|
339
|
+
let value = expr.evaluate(scope, options);
|
|
340
|
+
if (isThenable(value))
|
|
341
|
+
value = await value;
|
|
342
|
+
if (value === null || typeof value !== 'object') {
|
|
343
|
+
throw new Error(`flow(…, …, ${expr.source}): the options must be an object, ` +
|
|
344
|
+
`such as { measure: false }, not ${String(value)}`);
|
|
358
345
|
}
|
|
359
|
-
|
|
360
|
-
|
|
346
|
+
if (value.measure === false) {
|
|
347
|
+
unmeasured.add(body);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return unmeasured;
|
|
361
351
|
}
|
|
362
352
|
/**
|
|
363
353
|
* Renders a detached copy of a text body with flow() returning `entries`
|
|
364
354
|
* and returns its paragraphs. EXEC assignments and collected errors of
|
|
365
355
|
* this trial render are undone; the real render repeats them.
|
|
366
356
|
*/
|
|
367
|
-
renderCopy(body, entries) {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
357
|
+
async renderCopy(body, entries) {
|
|
358
|
+
// Tokens and blocks of the box are only read while writing, so one
|
|
359
|
+
// tokenized copy serves every entry. Each render writes into a body
|
|
360
|
+
// with the box's properties and a paragraph for writeBody to replace.
|
|
361
|
+
let source = this.copySources.get(body);
|
|
362
|
+
if (!source) {
|
|
363
|
+
const tokens = this.tokenizeBody((0, clone_1.cloneXml)(body, true));
|
|
364
|
+
source = { tokens, blocks: this.parse(tokens.tokens, textControl) };
|
|
365
|
+
this.copySources.set(body, source);
|
|
366
|
+
}
|
|
367
|
+
const copy = (0, clone_1.cloneXml)(body, false);
|
|
368
|
+
this.childElements(body)
|
|
369
|
+
.filter((child) => child.tagName !== 'a:p')
|
|
370
|
+
.forEach((child) => copy.appendChild((0, clone_1.cloneXml)(child, true)));
|
|
371
|
+
copy.appendChild(body.ownerDocument.createElement('a:p'));
|
|
372
|
+
const saved = {
|
|
373
|
+
override: this.flowOverride,
|
|
374
|
+
current: this.currentBody,
|
|
375
|
+
errors: this.errors.length,
|
|
376
|
+
vars: this.root.snapshot(),
|
|
377
|
+
};
|
|
378
|
+
this.flowOverride = () => entries;
|
|
379
|
+
this.currentBody = copy;
|
|
380
|
+
try {
|
|
381
|
+
await this.writeBody(copy, source.tokens, source.blocks, this.root);
|
|
382
|
+
return this.childElements(copy, 'a:p');
|
|
383
|
+
}
|
|
384
|
+
finally {
|
|
385
|
+
this.pendingImages.delete(copy);
|
|
386
|
+
this.flowOverride = saved.override;
|
|
387
|
+
this.currentBody = saved.current;
|
|
388
|
+
this.errors.length = saved.errors;
|
|
389
|
+
this.root.restore(saved.vars);
|
|
390
|
+
}
|
|
391
391
|
}
|
|
392
392
|
/**
|
|
393
393
|
* flow(): boxes with the same key render and measure the same, so one
|
|
@@ -400,7 +400,7 @@ class TemplateRenderer {
|
|
|
400
400
|
flowMeasureKey(body) {
|
|
401
401
|
if (this.options.errorHandler)
|
|
402
402
|
return undefined;
|
|
403
|
-
const text =
|
|
403
|
+
const text = (0, xml_find_1.elementsByTagName)(body, 'a:t')
|
|
404
404
|
.map((t) => t.textContent)
|
|
405
405
|
.join('');
|
|
406
406
|
for (const match of text.matchAll(this.tagPattern)) {
|
|
@@ -410,19 +410,19 @@ class TemplateRenderer {
|
|
|
410
410
|
if (command.type === 'HTML')
|
|
411
411
|
return undefined;
|
|
412
412
|
}
|
|
413
|
-
catch
|
|
413
|
+
catch {
|
|
414
414
|
return undefined;
|
|
415
415
|
}
|
|
416
416
|
}
|
|
417
417
|
const shape = (0, clone_1.cloneXml)(body.parentNode, true);
|
|
418
418
|
const childOf = (parent, tagName) => parent && this.childElements(parent, tagName)[0];
|
|
419
419
|
const off = childOf(childOf(childOf(shape, 'p:spPr'), 'a:xfrm'), 'a:off');
|
|
420
|
-
off
|
|
421
|
-
off
|
|
420
|
+
off?.setAttribute('x', '0');
|
|
421
|
+
off?.setAttribute('y', '0');
|
|
422
422
|
const cNvPr = childOf(childOf(shape, 'p:nvSpPr'), 'p:cNvPr');
|
|
423
|
-
cNvPr
|
|
424
|
-
cNvPr
|
|
425
|
-
return
|
|
423
|
+
cNvPr?.removeAttribute('id');
|
|
424
|
+
cNvPr?.removeAttribute('name');
|
|
425
|
+
return (0, xml_serializer_1.serializeXml)(shape);
|
|
426
426
|
}
|
|
427
427
|
/** Shape text bodies and tables, in document order. */
|
|
428
428
|
findTargets(element) {
|
|
@@ -443,13 +443,12 @@ class TemplateRenderer {
|
|
|
443
443
|
return targets;
|
|
444
444
|
}
|
|
445
445
|
containsTag(element) {
|
|
446
|
-
|
|
447
|
-
return ((_a = element.textContent) !== null && _a !== void 0 ? _a : '').includes(this.opening);
|
|
446
|
+
return (element.textContent ?? '').includes(this.opening);
|
|
448
447
|
}
|
|
449
448
|
/** ALIAS definitions apply everywhere, so collect them up front. */
|
|
450
449
|
collectAliases(element) {
|
|
451
|
-
|
|
452
|
-
const text =
|
|
450
|
+
(0, xml_find_1.elementsByTagName)(element, 'a:p').forEach((paragraph) => {
|
|
451
|
+
const text = (0, xml_find_1.elementsByTagName)(paragraph, 'a:t')
|
|
453
452
|
.map((t) => t.textContent)
|
|
454
453
|
.join('');
|
|
455
454
|
for (const match of text.matchAll(this.tagPattern)) {
|
|
@@ -457,7 +456,7 @@ class TemplateRenderer {
|
|
|
457
456
|
try {
|
|
458
457
|
command = (0, commands_1.parseCommand)(match[1], match[0]);
|
|
459
458
|
}
|
|
460
|
-
catch
|
|
459
|
+
catch {
|
|
461
460
|
continue; // reported where the tag is rendered
|
|
462
461
|
}
|
|
463
462
|
if (command.type === 'ALIAS') {
|
|
@@ -638,7 +637,10 @@ class TemplateRenderer {
|
|
|
638
637
|
}
|
|
639
638
|
compileStatements(source, tag) {
|
|
640
639
|
try {
|
|
641
|
-
return (0, expression_1.parseStatements)(source).map((statement) => (
|
|
640
|
+
return (0, expression_1.parseStatements)(source).map((statement) => ({
|
|
641
|
+
...statement,
|
|
642
|
+
expr: this.withFlow(statement.expr, tag),
|
|
643
|
+
}));
|
|
642
644
|
}
|
|
643
645
|
catch (error) {
|
|
644
646
|
if (!this.handlesErrors)
|
|
@@ -662,26 +664,24 @@ class TemplateRenderer {
|
|
|
662
664
|
* async. Errors go to errorHandler, are collected (failFast: false) or
|
|
663
665
|
* reject the render.
|
|
664
666
|
*/
|
|
665
|
-
value(tag, fn) {
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
667
|
+
async value(tag, fn) {
|
|
668
|
+
try {
|
|
669
|
+
let result = fn();
|
|
670
|
+
if (isThenable(result))
|
|
671
|
+
result = await result;
|
|
672
|
+
return result;
|
|
673
|
+
}
|
|
674
|
+
catch (error) {
|
|
675
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
676
|
+
if (this.options.errorHandler) {
|
|
677
|
+
return this.options.errorHandler(err, tag);
|
|
672
678
|
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
return this.options.errorHandler(err, tag);
|
|
677
|
-
}
|
|
678
|
-
if (this.options.failFast === false) {
|
|
679
|
-
this.errors.push(this.withTag(tag, err.message));
|
|
680
|
-
return undefined;
|
|
681
|
-
}
|
|
682
|
-
throw this.tagged(err, tag);
|
|
679
|
+
if (this.options.failFast === false) {
|
|
680
|
+
this.errors.push(this.withTag(tag, err.message));
|
|
681
|
+
return undefined;
|
|
683
682
|
}
|
|
684
|
-
|
|
683
|
+
throw this.tagged(err, tag);
|
|
684
|
+
}
|
|
685
685
|
}
|
|
686
686
|
/*
|
|
687
687
|
* Parsing & evaluating blocks (shared by text bodies and table rows)
|
|
@@ -692,7 +692,7 @@ class TemplateRenderer {
|
|
|
692
692
|
const current = () => (stack.length ? stack[stack.length - 1].body : root);
|
|
693
693
|
items.forEach((item) => {
|
|
694
694
|
const tag = control(item);
|
|
695
|
-
const directive = tag
|
|
695
|
+
const directive = tag?.directive;
|
|
696
696
|
if (!directive || !BLOCK_TYPES.includes(directive.type)) {
|
|
697
697
|
current().push({ kind: 'item', item });
|
|
698
698
|
return;
|
|
@@ -724,7 +724,7 @@ class TemplateRenderer {
|
|
|
724
724
|
}
|
|
725
725
|
case 'elseif':
|
|
726
726
|
case 'else': {
|
|
727
|
-
if (
|
|
727
|
+
if (top?.block.kind !== 'if') {
|
|
728
728
|
throw new TemplateRenderError(`${tag.tag} without a matching {{IF …}}`);
|
|
729
729
|
}
|
|
730
730
|
const branches = top.block.branches;
|
|
@@ -743,7 +743,7 @@ class TemplateRenderer {
|
|
|
743
743
|
case 'endif':
|
|
744
744
|
case 'endfor': {
|
|
745
745
|
const expected = directive.type === 'endif' ? 'if' : 'for';
|
|
746
|
-
if (
|
|
746
|
+
if (top?.block.kind !== expected) {
|
|
747
747
|
throw new TemplateRenderError(`${tag.tag} without a matching ${expected.toUpperCase()}` +
|
|
748
748
|
(top ? ` (open: ${top.tag})` : ''));
|
|
749
749
|
}
|
|
@@ -757,41 +757,42 @@ class TemplateRenderer {
|
|
|
757
757
|
}
|
|
758
758
|
return root;
|
|
759
759
|
}
|
|
760
|
-
evaluate(blocks, scope, emit) {
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
break;
|
|
773
|
-
}
|
|
760
|
+
async evaluate(blocks, scope, emit) {
|
|
761
|
+
for (const block of blocks) {
|
|
762
|
+
if (block.kind === 'item') {
|
|
763
|
+
await emit(block.item, scope);
|
|
764
|
+
}
|
|
765
|
+
else if (block.kind === 'if') {
|
|
766
|
+
for (const branch of block.branches) {
|
|
767
|
+
const pass = !branch.expr ||
|
|
768
|
+
(await this.value(branch.tag, () => branch.expr.evaluate(scope, this.evaluation)));
|
|
769
|
+
if (pass) {
|
|
770
|
+
await this.evaluate(branch.body, scope, emit);
|
|
771
|
+
break;
|
|
774
772
|
}
|
|
775
773
|
}
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
return this.toList(
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
$idx: idx,
|
|
789
|
-
}, scope);
|
|
790
|
-
yield this.evaluate(block.body, loopScope, emit);
|
|
774
|
+
}
|
|
775
|
+
else {
|
|
776
|
+
const value = await this.value(block.tag, () => {
|
|
777
|
+
const list = block.expr.evaluate(scope, this.evaluation);
|
|
778
|
+
if (isThenable(list))
|
|
779
|
+
return list.then((v) => this.toList(v, block.expr));
|
|
780
|
+
return this.toList(list, block.expr);
|
|
781
|
+
});
|
|
782
|
+
const entries = Array.isArray(value) ? value : [];
|
|
783
|
+
for (let idx = 0; idx < entries.length; idx++) {
|
|
784
|
+
if (++this.loopIterations > MAX_LOOP_ITERATIONS) {
|
|
785
|
+
throw new TemplateRenderError(`More than ${MAX_LOOP_ITERATIONS} FOR iterations ("${block.expr.source}")`);
|
|
791
786
|
}
|
|
787
|
+
const loopScope = new Scope({
|
|
788
|
+
[block.variable]: entries[idx],
|
|
789
|
+
[`$${block.variable}`]: entries[idx],
|
|
790
|
+
$idx: idx,
|
|
791
|
+
}, scope);
|
|
792
|
+
await this.evaluate(block.body, loopScope, emit);
|
|
792
793
|
}
|
|
793
794
|
}
|
|
794
|
-
}
|
|
795
|
+
}
|
|
795
796
|
}
|
|
796
797
|
toList(value, expr) {
|
|
797
798
|
if (value === null || value === undefined)
|
|
@@ -804,132 +805,128 @@ class TemplateRenderer {
|
|
|
804
805
|
/*
|
|
805
806
|
* Writing text bodies
|
|
806
807
|
*/
|
|
807
|
-
writeBody(body, bodyTokens, blocks, scope) {
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
break;
|
|
833
|
-
}
|
|
834
|
-
}));
|
|
835
|
-
let kept = paragraphs.filter((p) => p.raw ||
|
|
836
|
-
!(bodyTokens.controlOnly.has(p.source) || p.continuation) ||
|
|
837
|
-
p.nodes.some((n) => n.tagName !== 'a:r' || this.runText(n).trim() !== ''));
|
|
838
|
-
// A text body needs at least one paragraph.
|
|
839
|
-
if (!kept.length)
|
|
840
|
-
kept = [{ source: firstSource, nodes: [] }];
|
|
841
|
-
sourceParagraphs.forEach((p) => body.removeChild(p));
|
|
842
|
-
kept.forEach((p) => { var _a; return body.appendChild((_a = p.raw) !== null && _a !== void 0 ? _a : this.createParagraph(p)); });
|
|
808
|
+
async writeBody(body, bodyTokens, blocks, scope) {
|
|
809
|
+
const sourceParagraphs = this.childElements(body, 'a:p');
|
|
810
|
+
const first = sourceParagraphs[0];
|
|
811
|
+
if (!first)
|
|
812
|
+
return;
|
|
813
|
+
// The source paragraph, not its clone in a repeated table row: that is
|
|
814
|
+
// the one `controlOnly` knows.
|
|
815
|
+
const firstSource = bodyTokens.first ?? first;
|
|
816
|
+
const paragraphs = [{ source: firstSource, nodes: [] }];
|
|
817
|
+
const current = () => paragraphs[paragraphs.length - 1];
|
|
818
|
+
await this.evaluate(blocks, scope, async (token, tokenScope) => {
|
|
819
|
+
switch (token.kind) {
|
|
820
|
+
case 'break':
|
|
821
|
+
paragraphs.push({ source: token.paragraph, nodes: [] });
|
|
822
|
+
break;
|
|
823
|
+
case 'node':
|
|
824
|
+
current().nodes.push((0, clone_1.cloneXml)(token.node, true));
|
|
825
|
+
break;
|
|
826
|
+
case 'text':
|
|
827
|
+
current().nodes.push(...this.createRuns(token.run, token.text));
|
|
828
|
+
break;
|
|
829
|
+
case 'tag':
|
|
830
|
+
await this.emitTag(token, tokenScope, body, paragraphs);
|
|
831
|
+
break;
|
|
832
|
+
}
|
|
843
833
|
});
|
|
834
|
+
let kept = paragraphs.filter((p) => p.raw ||
|
|
835
|
+
!(bodyTokens.controlOnly.has(p.source) || p.continuation) ||
|
|
836
|
+
p.nodes.some((n) => n.tagName !== 'a:r' || this.runText(n).trim() !== ''));
|
|
837
|
+
// A text body needs at least one paragraph.
|
|
838
|
+
if (!kept.length)
|
|
839
|
+
kept = [{ source: firstSource, nodes: [] }];
|
|
840
|
+
sourceParagraphs.forEach((p) => body.removeChild(p));
|
|
841
|
+
kept.forEach((p) => body.appendChild(p.raw ?? this.createParagraph(p)));
|
|
844
842
|
}
|
|
845
|
-
emitTag(token, scope, body, paragraphs) {
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
843
|
+
async emitTag(token, scope, body, paragraphs) {
|
|
844
|
+
const { directive, tag, run } = token;
|
|
845
|
+
const current = paragraphs[paragraphs.length - 1];
|
|
846
|
+
const evaluate = (expr) => this.value(tag, () => expr.evaluate(scope, this.evaluation));
|
|
847
|
+
switch (directive.type) {
|
|
848
|
+
case 'insert': {
|
|
849
|
+
const value = await this.value(tag, async () => {
|
|
850
|
+
const result = await directive.expr.evaluate(scope, this.evaluation);
|
|
851
|
+
if (this.options.rejectNullish &&
|
|
852
|
+
(result === null || result === undefined)) {
|
|
853
|
+
throw new Error(`"${directive.expr.source}" is ${result}`);
|
|
854
|
+
}
|
|
855
|
+
return result;
|
|
856
|
+
});
|
|
857
|
+
current.nodes.push(...this.createRuns(run, this.format(value)));
|
|
858
|
+
break;
|
|
859
|
+
}
|
|
860
|
+
case 'hideslide':
|
|
861
|
+
this.warnHideSlide(directive.tag);
|
|
862
|
+
break;
|
|
863
|
+
case 'exec':
|
|
864
|
+
await this.runExec(directive.statements, scope, tag);
|
|
865
|
+
break;
|
|
866
|
+
case 'html': {
|
|
867
|
+
const html = this.format(await evaluate(directive.expr));
|
|
868
|
+
if (!html)
|
|
866
869
|
break;
|
|
867
|
-
|
|
868
|
-
|
|
870
|
+
const generated = this.htmlParagraphs(body, current.source, run, html, await this.relations());
|
|
871
|
+
generated.forEach((raw) => paragraphs.push({ source: current.source, nodes: [], raw }));
|
|
872
|
+
paragraphs.push({
|
|
873
|
+
source: current.source,
|
|
874
|
+
nodes: [],
|
|
875
|
+
continuation: true,
|
|
876
|
+
});
|
|
877
|
+
break;
|
|
878
|
+
}
|
|
879
|
+
case 'link': {
|
|
880
|
+
const value = await evaluate(directive.expr);
|
|
881
|
+
if (value === null || value === undefined || value === '')
|
|
869
882
|
break;
|
|
870
|
-
|
|
871
|
-
const
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
883
|
+
const runs = await this.value(tag, async () => {
|
|
884
|
+
const { link, label } = this.toLink(value);
|
|
885
|
+
const relations = await this.relations();
|
|
886
|
+
if (!relations) {
|
|
887
|
+
throw new Error('LINK needs the slide relationships');
|
|
888
|
+
}
|
|
889
|
+
const relId = this.linkRelation(relations, link);
|
|
890
|
+
const created = this.createRuns(run, label);
|
|
891
|
+
created
|
|
892
|
+
.filter((n) => n.tagName === 'a:r')
|
|
893
|
+
.forEach((r) => this.setHyperlink(r, relId, link.internal));
|
|
894
|
+
return created;
|
|
895
|
+
});
|
|
896
|
+
if (Array.isArray(runs))
|
|
897
|
+
current.nodes.push(...runs);
|
|
898
|
+
break;
|
|
899
|
+
}
|
|
900
|
+
case 'image': {
|
|
901
|
+
const value = await evaluate(directive.expr);
|
|
902
|
+
if (value === null || value === undefined || value === '')
|
|
881
903
|
break;
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
const value = yield evaluate(directive.expr);
|
|
885
|
-
if (value === null || value === undefined || value === '')
|
|
886
|
-
break;
|
|
887
|
-
const runs = yield this.value(tag, () => __awaiter(this, void 0, void 0, function* () {
|
|
888
|
-
const { link, label } = this.toLink(value);
|
|
889
|
-
const relations = yield this.relations();
|
|
890
|
-
if (!relations) {
|
|
891
|
-
throw new Error('LINK needs the slide relationships');
|
|
892
|
-
}
|
|
893
|
-
const relId = this.linkRelation(relations, link);
|
|
894
|
-
const created = this.createRuns(run, label);
|
|
895
|
-
created
|
|
896
|
-
.filter((n) => n.tagName === 'a:r')
|
|
897
|
-
.forEach((r) => this.setHyperlink(r, relId, link.internal));
|
|
898
|
-
return created;
|
|
899
|
-
}));
|
|
900
|
-
if (Array.isArray(runs))
|
|
901
|
-
current.nodes.push(...runs);
|
|
904
|
+
// a measuring copy (flowOverride) never places its pictures
|
|
905
|
+
if (this.flowOverride || this.context.countOnly)
|
|
902
906
|
break;
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
'modifyElement() callbacks cannot add media files');
|
|
915
|
-
}
|
|
916
|
-
return (0, images_1.loadImage)(value, this.options.imageRoot);
|
|
917
|
-
}));
|
|
918
|
-
if (!image || typeof image !== 'object' || !('content' in image))
|
|
919
|
-
break;
|
|
920
|
-
const pending = (_a = this.pendingImages.get(body)) !== null && _a !== void 0 ? _a : [];
|
|
921
|
-
pending.push(image);
|
|
922
|
-
this.pendingImages.set(body, pending);
|
|
907
|
+
const image = await this.value(tag, async () => {
|
|
908
|
+
if (body.tagName !== 'p:txBody') {
|
|
909
|
+
throw new Error('IMAGE is not supported inside table cells');
|
|
910
|
+
}
|
|
911
|
+
if (!(await this.imageTarget())) {
|
|
912
|
+
throw new Error('IMAGE needs slide.modify(modify.renderTemplate(…)); ' +
|
|
913
|
+
'modifyElement() callbacks cannot add media files');
|
|
914
|
+
}
|
|
915
|
+
return (0, images_1.loadImage)(value, this.options.imageRoot);
|
|
916
|
+
});
|
|
917
|
+
if (!image || typeof image !== 'object' || !('content' in image))
|
|
923
918
|
break;
|
|
924
|
-
|
|
919
|
+
const pending = this.pendingImages.get(body) ?? [];
|
|
920
|
+
pending.push(image);
|
|
921
|
+
this.pendingImages.set(body, pending);
|
|
922
|
+
break;
|
|
925
923
|
}
|
|
926
|
-
}
|
|
924
|
+
}
|
|
927
925
|
}
|
|
928
926
|
imageTarget() {
|
|
929
|
-
|
|
930
|
-
(_a = this.imageTargetPromise) !== null && _a !== void 0 ? _a : (this.imageTargetPromise = this.context.images
|
|
927
|
+
this.imageTargetPromise ??= this.context.images
|
|
931
928
|
? this.context.images()
|
|
932
|
-
: Promise.resolve(undefined)
|
|
929
|
+
: Promise.resolve(undefined);
|
|
933
930
|
return this.imageTargetPromise;
|
|
934
931
|
}
|
|
935
932
|
/**
|
|
@@ -946,128 +943,117 @@ class TemplateRenderer {
|
|
|
946
943
|
try {
|
|
947
944
|
return (0, commands_1.parseCommand)((0, commands_1.resolveAlias)(inner, this.aliases, tag), tag).type;
|
|
948
945
|
}
|
|
949
|
-
catch
|
|
946
|
+
catch {
|
|
950
947
|
return undefined;
|
|
951
948
|
}
|
|
952
949
|
};
|
|
953
|
-
return
|
|
954
|
-
var _a;
|
|
955
|
-
return (0, commands_1.isAltTextTemplate)((_a = cNvPr.getAttribute('descr')) !== null && _a !== void 0 ? _a : '', this.tagPattern, commandType);
|
|
956
|
-
});
|
|
950
|
+
return (0, xml_find_1.elementsByTagName)(element, 'p:cNvPr').filter((cNvPr) => (0, commands_1.isAltTextTemplate)(cNvPr.getAttribute('descr') ?? '', this.tagPattern, commandType));
|
|
957
951
|
}
|
|
958
|
-
renderAltTexts(holders) {
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
if (!ALT_TEXT_TYPES.includes(directive.type)) {
|
|
974
|
-
throw this.tagged(new Error('only IMAGE, IF, ELSE-IF, ELSE, FOR and EXEC work in alt text'), match[0]);
|
|
975
|
-
}
|
|
976
|
-
return { tag: match[0], directive };
|
|
977
|
-
});
|
|
978
|
-
blocks = this.parse(tags, (tag) => tag);
|
|
979
|
-
}
|
|
980
|
-
catch (error) {
|
|
981
|
-
yield this.fail(first, error);
|
|
982
|
-
continue;
|
|
983
|
-
}
|
|
984
|
-
const images = [];
|
|
985
|
-
const saved = { body: this.currentBody, altText: this.inAltText };
|
|
986
|
-
this.currentBody = (_b = this.textFlow) === null || _b === void 0 ? void 0 : _b.boxOfCard(shape);
|
|
987
|
-
this.inAltText = true;
|
|
988
|
-
try {
|
|
989
|
-
yield this.evaluate(blocks, this.root, (_a, scope_1) => __awaiter(this, [_a, scope_1], void 0, function* ({ tag, directive }, scope) {
|
|
990
|
-
if (directive.type === 'exec') {
|
|
991
|
-
yield this.runExec(directive.statements, scope, tag);
|
|
992
|
-
}
|
|
993
|
-
else if (directive.type === 'image') {
|
|
994
|
-
const value = yield this.value(tag, () => directive.expr.evaluate(scope, this.evaluation));
|
|
995
|
-
if (value !== null && value !== undefined && value !== '') {
|
|
996
|
-
images.push({ tag, value });
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
}));
|
|
1000
|
-
}
|
|
1001
|
-
finally {
|
|
1002
|
-
this.currentBody = saved.body;
|
|
1003
|
-
this.inAltText = saved.altText;
|
|
1004
|
-
}
|
|
1005
|
-
if (!images.length)
|
|
1006
|
-
continue;
|
|
1007
|
-
const { tag, value } = images[0];
|
|
1008
|
-
if (images.length > 1) {
|
|
1009
|
-
const error = new Error(`the alt text yields ${images.length} pictures; a shape holds one`);
|
|
1010
|
-
yield this.fail(images[1].tag, error);
|
|
1011
|
-
continue;
|
|
1012
|
-
}
|
|
1013
|
-
const image = yield this.value(tag, () => __awaiter(this, void 0, void 0, function* () {
|
|
1014
|
-
if (!(yield this.imageTarget())) {
|
|
1015
|
-
throw new Error('IMAGE needs slide.modify(modify.renderTemplate(…)); ' +
|
|
1016
|
-
'modifyElement() callbacks cannot add media files');
|
|
952
|
+
async renderAltTexts(holders) {
|
|
953
|
+
for (const cNvPr of holders) {
|
|
954
|
+
const descr = cNvPr.getAttribute('descr');
|
|
955
|
+
const shape = cNvPr.parentNode?.parentNode;
|
|
956
|
+
const matches = [...descr.matchAll(this.tagPattern)];
|
|
957
|
+
const first = matches[0][0];
|
|
958
|
+
let blocks;
|
|
959
|
+
// The tag never reaches the output, also not after an error
|
|
960
|
+
// (errorHandler, continueOnError)
|
|
961
|
+
cNvPr.removeAttribute('descr');
|
|
962
|
+
try {
|
|
963
|
+
const tags = matches.map((match) => {
|
|
964
|
+
const directive = this.parseDirective(match[1], match[0]);
|
|
965
|
+
if (!ALT_TEXT_TYPES.includes(directive.type)) {
|
|
966
|
+
throw this.tagged(new Error('only IMAGE, IF, ELSE-IF, ELSE, FOR and EXEC work in alt text'), match[0]);
|
|
1017
967
|
}
|
|
1018
|
-
return
|
|
1019
|
-
})
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
968
|
+
return { tag: match[0], directive };
|
|
969
|
+
});
|
|
970
|
+
blocks = this.parse(tags, (tag) => tag);
|
|
971
|
+
}
|
|
972
|
+
catch (error) {
|
|
973
|
+
await this.fail(first, error);
|
|
974
|
+
continue;
|
|
975
|
+
}
|
|
976
|
+
const images = [];
|
|
977
|
+
const saved = { body: this.currentBody, altText: this.inAltText };
|
|
978
|
+
this.currentBody = this.textFlow?.boxOfCard(shape);
|
|
979
|
+
this.inAltText = true;
|
|
980
|
+
try {
|
|
981
|
+
await this.evaluate(blocks, this.root, async ({ tag, directive }, scope) => {
|
|
982
|
+
if (directive.type === 'exec') {
|
|
983
|
+
await this.runExec(directive.statements, scope, tag);
|
|
984
|
+
}
|
|
985
|
+
else if (directive.type === 'image') {
|
|
986
|
+
const value = await this.value(tag, () => directive.expr.evaluate(scope, this.evaluation));
|
|
987
|
+
if (value !== null && value !== undefined && value !== '') {
|
|
988
|
+
images.push({ tag, value });
|
|
989
|
+
}
|
|
1028
990
|
}
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
finally {
|
|
994
|
+
this.currentBody = saved.body;
|
|
995
|
+
this.inAltText = saved.altText;
|
|
996
|
+
}
|
|
997
|
+
if (!images.length || this.context.countOnly)
|
|
998
|
+
continue;
|
|
999
|
+
const { tag, value } = images[0];
|
|
1000
|
+
if (images.length > 1) {
|
|
1001
|
+
const error = new Error(`the alt text yields ${images.length} pictures; a shape holds one`);
|
|
1002
|
+
await this.fail(images[1].tag, error);
|
|
1003
|
+
continue;
|
|
1004
|
+
}
|
|
1005
|
+
const image = await this.value(tag, async () => {
|
|
1006
|
+
if (!(await this.imageTarget())) {
|
|
1007
|
+
throw new Error('IMAGE needs slide.modify(modify.renderTemplate(…)); ' +
|
|
1008
|
+
'modifyElement() callbacks cannot add media files');
|
|
1029
1009
|
}
|
|
1030
|
-
|
|
1031
|
-
|
|
1010
|
+
return (0, images_1.loadImage)(value, this.options.imageRoot);
|
|
1011
|
+
});
|
|
1012
|
+
if (!image || typeof image !== 'object' || !('content' in image))
|
|
1013
|
+
continue;
|
|
1014
|
+
const loaded = image;
|
|
1015
|
+
try {
|
|
1016
|
+
const holder = await (0, images_1.fillWithImage)(await this.imageTarget(), shape, loaded);
|
|
1017
|
+
if (loaded.spec.alt) {
|
|
1018
|
+
holder
|
|
1019
|
+
.getElementsByTagName('p:cNvPr')[0]
|
|
1020
|
+
?.setAttribute('descr', xml_helper_1.XmlHelper.sanitizeAttr(loaded.spec.alt));
|
|
1032
1021
|
}
|
|
1033
1022
|
}
|
|
1034
|
-
|
|
1023
|
+
catch (error) {
|
|
1024
|
+
await this.fail(tag, error);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1035
1027
|
}
|
|
1036
1028
|
/** An error at `tag`, handled as in value(): errorHandler, collected or thrown. */
|
|
1037
|
-
fail(tag, error) {
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
throw error;
|
|
1041
|
-
});
|
|
1029
|
+
async fail(tag, error) {
|
|
1030
|
+
await this.value(tag, () => {
|
|
1031
|
+
throw error;
|
|
1042
1032
|
});
|
|
1043
1033
|
}
|
|
1044
|
-
runExec(statements, scope, tag) {
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
}
|
|
1051
|
-
});
|
|
1034
|
+
async runExec(statements, scope, tag) {
|
|
1035
|
+
for (const statement of statements) {
|
|
1036
|
+
const value = await this.value(tag, () => statement.expr.evaluate(scope, this.evaluation));
|
|
1037
|
+
if (statement.assign)
|
|
1038
|
+
scope.assign(statement.assign, value);
|
|
1039
|
+
}
|
|
1052
1040
|
}
|
|
1053
1041
|
/** Pictures go where the shape is; a shape left without text is removed. */
|
|
1054
|
-
placePendingImages(body) {
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
}
|
|
1070
|
-
});
|
|
1042
|
+
async placePendingImages(body) {
|
|
1043
|
+
const images = this.pendingImages.get(body);
|
|
1044
|
+
if (!images?.length)
|
|
1045
|
+
return;
|
|
1046
|
+
this.pendingImages.delete(body);
|
|
1047
|
+
const shape = body.parentNode;
|
|
1048
|
+
const text = (0, xml_find_1.elementsByTagName)(body, 'a:t')
|
|
1049
|
+
.map((t) => t.textContent)
|
|
1050
|
+
.join('');
|
|
1051
|
+
try {
|
|
1052
|
+
await (0, images_1.placeImages)(await this.imageTarget(), shape, images, text.trim() === '');
|
|
1053
|
+
}
|
|
1054
|
+
catch (error) {
|
|
1055
|
+
throw this.tagged(error, 'IMAGE');
|
|
1056
|
+
}
|
|
1071
1057
|
}
|
|
1072
1058
|
createParagraph(output) {
|
|
1073
1059
|
const paragraph = (0, clone_1.cloneXml)(output.source, false);
|
|
@@ -1099,10 +1085,26 @@ class TemplateRenderer {
|
|
|
1099
1085
|
}
|
|
1100
1086
|
if (line === '')
|
|
1101
1087
|
return;
|
|
1102
|
-
|
|
1103
|
-
const
|
|
1104
|
-
|
|
1105
|
-
|
|
1088
|
+
// the template's own text is not copied: <a:t> gets the new text
|
|
1089
|
+
const run = (0, clone_1.cloneXml)(template, false);
|
|
1090
|
+
let t;
|
|
1091
|
+
for (let child = template.firstChild; child; child = child.nextSibling) {
|
|
1092
|
+
const isText = !t && child.nodeType === 1 && child.tagName === 'a:t';
|
|
1093
|
+
const copy = (0, clone_1.cloneXml)(child, !isText);
|
|
1094
|
+
if (isText)
|
|
1095
|
+
t = copy;
|
|
1096
|
+
run.appendChild(copy);
|
|
1097
|
+
}
|
|
1098
|
+
if (!t) {
|
|
1099
|
+
// no <a:t> of its own: as before (a nested one, or the error)
|
|
1100
|
+
const copy = (0, clone_1.cloneXml)(template, true);
|
|
1101
|
+
t = copy.getElementsByTagName('a:t')[0];
|
|
1102
|
+
while (t.firstChild)
|
|
1103
|
+
t.removeChild(t.firstChild);
|
|
1104
|
+
t.appendChild(doc.createTextNode(xml_helper_1.XmlHelper.sanitizeText(line)));
|
|
1105
|
+
nodes.push(copy);
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1106
1108
|
t.appendChild(doc.createTextNode(xml_helper_1.XmlHelper.sanitizeText(line)));
|
|
1107
1109
|
nodes.push(run);
|
|
1108
1110
|
});
|
|
@@ -1119,10 +1121,9 @@ class TemplateRenderer {
|
|
|
1119
1121
|
* HTML and hyperlinks
|
|
1120
1122
|
*/
|
|
1121
1123
|
relations() {
|
|
1122
|
-
|
|
1123
|
-
(_a = this.relationsPromise) !== null && _a !== void 0 ? _a : (this.relationsPromise = this.context.relations
|
|
1124
|
+
this.relationsPromise ??= this.context.relations
|
|
1124
1125
|
? this.context.relations()
|
|
1125
|
-
: Promise.resolve(undefined)
|
|
1126
|
+
: Promise.resolve(undefined);
|
|
1126
1127
|
return this.relationsPromise;
|
|
1127
1128
|
}
|
|
1128
1129
|
/**
|
|
@@ -1142,12 +1143,11 @@ class TemplateRenderer {
|
|
|
1142
1143
|
const document = /<body[\s>]/i.test(html)
|
|
1143
1144
|
? html
|
|
1144
1145
|
: `<html><body>${html}</body></html>`;
|
|
1145
|
-
new multitext_helper_1.MultiTextHelper(host, relations).run(new html_to_multitext_helper_1.HtmlToMultiTextHelper().run(document));
|
|
1146
|
+
(0, link_scheme_1.runWithLinkSchemes)(this.options.allowedLinkSchemes, () => new multitext_helper_1.MultiTextHelper(host, relations).run(new html_to_multitext_helper_1.HtmlToMultiTextHelper().run(document)));
|
|
1146
1147
|
return this.childElements(scratch, 'a:p');
|
|
1147
1148
|
}
|
|
1148
1149
|
toLink(value) {
|
|
1149
|
-
|
|
1150
|
-
const spec = typeof value === 'object'
|
|
1150
|
+
const spec = value !== null && typeof value === 'object'
|
|
1151
1151
|
? value
|
|
1152
1152
|
: { url: value };
|
|
1153
1153
|
const url = spec.url;
|
|
@@ -1155,8 +1155,13 @@ class TemplateRenderer {
|
|
|
1155
1155
|
throw new Error('LINK needs a url, e.g. {{LINK ({ url, label })}}');
|
|
1156
1156
|
}
|
|
1157
1157
|
const internal = typeof url === 'number';
|
|
1158
|
+
if (internal && !(Number.isInteger(url) && url >= 1)) {
|
|
1159
|
+
throw new Error(`LINK to slide ${url}: a slide number is a whole number from 1`);
|
|
1160
|
+
}
|
|
1161
|
+
if (!internal)
|
|
1162
|
+
(0, link_scheme_1.assertLinkScheme)(String(url), this.options.allowedLinkSchemes);
|
|
1158
1163
|
const target = internal ? `../slides/slide${url}.xml` : String(url);
|
|
1159
|
-
const label = this.format(
|
|
1164
|
+
const label = this.format(spec.label ?? url);
|
|
1160
1165
|
return { link: { target, internal }, label };
|
|
1161
1166
|
}
|
|
1162
1167
|
linkRelation(relations, link) {
|
|
@@ -1171,7 +1176,7 @@ class TemplateRenderer {
|
|
|
1171
1176
|
const rel = root.ownerDocument.createElement('Relationship');
|
|
1172
1177
|
rel.setAttribute('Id', id);
|
|
1173
1178
|
rel.setAttribute('Type', link.internal ? REL_TYPE_SLIDE : REL_TYPE_HYPERLINK);
|
|
1174
|
-
rel.setAttribute('Target', link.target);
|
|
1179
|
+
rel.setAttribute('Target', xml_helper_1.XmlHelper.sanitizeAttr(link.target));
|
|
1175
1180
|
if (!link.internal)
|
|
1176
1181
|
rel.setAttribute('TargetMode', 'External');
|
|
1177
1182
|
root.appendChild(rel);
|
|
@@ -1196,74 +1201,72 @@ class TemplateRenderer {
|
|
|
1196
1201
|
/*
|
|
1197
1202
|
* Tables: blocks left open inside a cell span (and repeat) table rows.
|
|
1198
1203
|
*/
|
|
1199
|
-
renderTable(table) {
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
const
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
hasContent
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
return bodyTokens;
|
|
1234
|
-
});
|
|
1235
|
-
// Without an opener, all closers end blocks this row still belongs to
|
|
1236
|
-
if (!openers.length)
|
|
1237
|
-
closers.push(...leading.splice(0));
|
|
1238
|
-
const isControlRow = !hasContent && (openers.length || closers.length);
|
|
1239
|
-
rowTokens.push(...leading, ...openers);
|
|
1240
|
-
if (!isControlRow)
|
|
1241
|
-
rowTokens.push({ row, cells });
|
|
1242
|
-
rowTokens.push(...closers);
|
|
1243
|
-
});
|
|
1244
|
-
const output = [];
|
|
1245
|
-
yield this.evaluate(this.parse(rowTokens, (t) => t.directive ? { tag: t.tag, directive: t.directive } : undefined), this.root, (token, scope) => __awaiter(this, void 0, void 0, function* () {
|
|
1246
|
-
const row = (0, clone_1.cloneXml)(token.row, true);
|
|
1247
|
-
const cells = this.childElements(row, 'a:tc');
|
|
1248
|
-
for (let c = 0; c < cells.length; c++) {
|
|
1249
|
-
const bodyTokens = token.cells[c];
|
|
1250
|
-
const body = this.childElements(cells[c], 'a:txBody')[0];
|
|
1251
|
-
if (!bodyTokens || !body)
|
|
1252
|
-
continue;
|
|
1253
|
-
yield this.writeBody(body, bodyTokens, this.parse(bodyTokens.tokens, textControl), scope);
|
|
1254
|
-
}
|
|
1255
|
-
output.push(row);
|
|
1256
|
-
}));
|
|
1257
|
-
const anchor = rows[rows.length - 1].nextSibling;
|
|
1258
|
-
rows.forEach((row) => table.removeChild(row));
|
|
1259
|
-
output.forEach((row, r) => {
|
|
1260
|
-
table.insertBefore(row, anchor);
|
|
1261
|
-
const rowId = row.getElementsByTagName('a16:rowId')[0];
|
|
1262
|
-
if (rowId)
|
|
1263
|
-
rowId.setAttribute('val', String(10000 + r));
|
|
1204
|
+
async renderTable(table) {
|
|
1205
|
+
if (!this.containsTag(table))
|
|
1206
|
+
return;
|
|
1207
|
+
const rows = this.childElements(table, 'a:tr');
|
|
1208
|
+
const rowTokens = [];
|
|
1209
|
+
rows.forEach((row) => {
|
|
1210
|
+
const openers = [];
|
|
1211
|
+
// Closers before the row's first opener end a block from an earlier
|
|
1212
|
+
// row; they must not close the block this row opens.
|
|
1213
|
+
const leading = [];
|
|
1214
|
+
const closers = [];
|
|
1215
|
+
let hasContent = false;
|
|
1216
|
+
const cells = this.childElements(row, 'a:tc').map((cell) => {
|
|
1217
|
+
const body = this.childElements(cell, 'a:txBody')[0];
|
|
1218
|
+
if (!body)
|
|
1219
|
+
return undefined;
|
|
1220
|
+
const bodyTokens = this.tokenizeBody(body);
|
|
1221
|
+
const rowLevel = this.extractRowLevelTags(bodyTokens.tokens);
|
|
1222
|
+
rowLevel.closers.forEach((t) => (openers.length ? closers : leading).push({
|
|
1223
|
+
tag: t.tag,
|
|
1224
|
+
directive: t.directive,
|
|
1225
|
+
}));
|
|
1226
|
+
rowLevel.openers.forEach((t) => openers.push({ tag: t.tag, directive: t.directive }));
|
|
1227
|
+
const extracted = new Set([
|
|
1228
|
+
...rowLevel.openers,
|
|
1229
|
+
...rowLevel.closers,
|
|
1230
|
+
]);
|
|
1231
|
+
bodyTokens.tokens = bodyTokens.tokens.filter((t) => !extracted.has(t));
|
|
1232
|
+
hasContent =
|
|
1233
|
+
hasContent ||
|
|
1234
|
+
bodyTokens.tokens.some((t) => (t.kind === 'tag' && CONTENT_TYPES.includes(t.directive.type)) ||
|
|
1235
|
+
(t.kind === 'text' && t.text.trim() !== '') ||
|
|
1236
|
+
(t.kind === 'node' && t.node.tagName === 'a:fld'));
|
|
1237
|
+
return bodyTokens;
|
|
1264
1238
|
});
|
|
1265
|
-
|
|
1239
|
+
// Without an opener, all closers end blocks this row still belongs to
|
|
1240
|
+
if (!openers.length)
|
|
1241
|
+
closers.push(...leading.splice(0));
|
|
1242
|
+
const isControlRow = !hasContent && (openers.length || closers.length);
|
|
1243
|
+
rowTokens.push(...leading, ...openers);
|
|
1244
|
+
if (!isControlRow)
|
|
1245
|
+
rowTokens.push({ row, cells });
|
|
1246
|
+
rowTokens.push(...closers);
|
|
1247
|
+
});
|
|
1248
|
+
const output = [];
|
|
1249
|
+
await this.evaluate(this.parse(rowTokens, (t) => t.directive ? { tag: t.tag, directive: t.directive } : undefined), this.root, async (token, scope) => {
|
|
1250
|
+
const row = (0, clone_1.cloneXml)(token.row, true);
|
|
1251
|
+
const cells = this.childElements(row, 'a:tc');
|
|
1252
|
+
for (let c = 0; c < cells.length; c++) {
|
|
1253
|
+
const bodyTokens = token.cells[c];
|
|
1254
|
+
const body = this.childElements(cells[c], 'a:txBody')[0];
|
|
1255
|
+
if (!bodyTokens || !body)
|
|
1256
|
+
continue;
|
|
1257
|
+
await this.writeBody(body, bodyTokens, this.parse(bodyTokens.tokens, textControl), scope);
|
|
1258
|
+
}
|
|
1259
|
+
output.push(row);
|
|
1260
|
+
});
|
|
1261
|
+
const anchor = rows[rows.length - 1].nextSibling;
|
|
1262
|
+
rows.forEach((row) => table.removeChild(row));
|
|
1263
|
+
output.forEach((row, r) => {
|
|
1264
|
+
table.insertBefore(row, anchor);
|
|
1265
|
+
const rowId = row.getElementsByTagName('a16:rowId')[0];
|
|
1266
|
+
if (rowId)
|
|
1267
|
+
rowId.setAttribute('val', String(10000 + r));
|
|
1266
1268
|
});
|
|
1269
|
+
this.updateFrameHeight(table, output);
|
|
1267
1270
|
}
|
|
1268
1271
|
/** Block tags that are not closed (or opened) within the same cell. */
|
|
1269
1272
|
extractRowLevelTags(tokens) {
|
|
@@ -1289,12 +1292,13 @@ class TemplateRenderer {
|
|
|
1289
1292
|
return { openers: stack, closers };
|
|
1290
1293
|
}
|
|
1291
1294
|
updateFrameHeight(table, rows) {
|
|
1292
|
-
var _a;
|
|
1293
1295
|
let frame = table.parentNode;
|
|
1294
1296
|
while (frame && frame.tagName !== 'p:graphicFrame') {
|
|
1295
1297
|
frame = frame.parentNode;
|
|
1296
1298
|
}
|
|
1297
|
-
const ext =
|
|
1299
|
+
const ext = frame
|
|
1300
|
+
?.getElementsByTagName('p:xfrm')[0]
|
|
1301
|
+
?.getElementsByTagName('a:ext')[0];
|
|
1298
1302
|
if (!ext)
|
|
1299
1303
|
return;
|
|
1300
1304
|
const height = rows.reduce((sum, row) => sum + Number(row.getAttribute('h') || 0), 0);
|
|
@@ -1316,8 +1320,7 @@ class TemplateRenderer {
|
|
|
1316
1320
|
return children;
|
|
1317
1321
|
}
|
|
1318
1322
|
runText(run) {
|
|
1319
|
-
|
|
1320
|
-
return (_b = (_a = run.getElementsByTagName('a:t')[0]) === null || _a === void 0 ? void 0 : _a.textContent) !== null && _b !== void 0 ? _b : '';
|
|
1323
|
+
return (0, xml_find_1.firstElementByTagName)(run, 'a:t')?.textContent ?? '';
|
|
1321
1324
|
}
|
|
1322
1325
|
}
|
|
1323
1326
|
exports.TemplateRenderer = TemplateRenderer;
|