pptx-templates 0.3.8 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AI-INSTRUCTOR.md +91 -2
- package/CHANGELOG.md +125 -1
- package/dist/automizer.js +143 -176
- package/dist/automizer.js.map +1 -1
- package/dist/classes/content-type-registry.js +23 -36
- package/dist/classes/content-type-registry.js.map +1 -1
- package/dist/classes/element-importer.js +129 -148
- package/dist/classes/element-importer.js.map +1 -1
- package/dist/classes/has-shapes.js +81 -126
- package/dist/classes/has-shapes.js.map +1 -1
- package/dist/classes/layout.js +47 -67
- package/dist/classes/layout.js.map +1 -1
- package/dist/classes/master.js +70 -89
- package/dist/classes/master.js.map +1 -1
- package/dist/classes/placeholder-normalizer.js +48 -37
- package/dist/classes/placeholder-normalizer.js.map +1 -1
- package/dist/classes/related-content-copier.js +65 -86
- package/dist/classes/related-content-copier.js.map +1 -1
- package/dist/classes/shape.js +79 -110
- package/dist/classes/shape.js.map +1 -1
- package/dist/classes/slide-master-remover.js +108 -130
- package/dist/classes/slide-master-remover.js.map +1 -1
- package/dist/classes/slide-notes-copier.js +24 -41
- package/dist/classes/slide-notes-copier.js.map +1 -1
- package/dist/classes/slide.js +112 -141
- package/dist/classes/slide.js.map +1 -1
- package/dist/classes/template.js +82 -117
- package/dist/classes/template.js.map +1 -1
- package/dist/errors.js +5 -5
- package/dist/errors.js.map +1 -1
- package/dist/extensions/cli/index.js +3 -13
- package/dist/extensions/cli/index.js.map +1 -1
- package/dist/extensions/hide-slide/index.js +48 -46
- package/dist/extensions/hide-slide/index.js.map +1 -1
- package/dist/extensions/master-parts/index.js +36 -49
- package/dist/extensions/master-parts/index.js.map +1 -1
- package/dist/extensions/pptxgenjs-compat/svg-fallback.js +56 -70
- package/dist/extensions/pptxgenjs-compat/svg-fallback.js.map +1 -1
- package/dist/extensions/regexp-escape/index.d.ts +10 -0
- package/dist/extensions/regexp-escape/index.js +15 -0
- package/dist/extensions/regexp-escape/index.js.map +1 -0
- package/dist/extensions/run-merge/index.js +4 -5
- package/dist/extensions/run-merge/index.js.map +1 -1
- package/dist/extensions/shape-geometry/index.d.ts +2 -0
- package/dist/extensions/shape-geometry/index.js +13 -13
- package/dist/extensions/shape-geometry/index.js.map +1 -1
- package/dist/extensions/template-lint/cli.js +49 -41
- package/dist/extensions/template-lint/cli.js.map +1 -1
- package/dist/extensions/template-lint/config.js +18 -10
- package/dist/extensions/template-lint/config.js.map +1 -1
- package/dist/extensions/template-lint/data-model.js +17 -20
- package/dist/extensions/template-lint/data-model.js.map +1 -1
- package/dist/extensions/template-lint/init-cli.js +12 -17
- package/dist/extensions/template-lint/init-cli.js.map +1 -1
- package/dist/extensions/template-lint/lint.js +195 -62
- package/dist/extensions/template-lint/lint.js.map +1 -1
- package/dist/extensions/template-lint/skeleton.js +5 -6
- package/dist/extensions/template-lint/skeleton.js.map +1 -1
- package/dist/extensions/template-lint/usage-cli.js +10 -14
- package/dist/extensions/template-lint/usage-cli.js.map +1 -1
- package/dist/extensions/template-lint/usage.js +8 -9
- package/dist/extensions/template-lint/usage.js.map +1 -1
- package/dist/extensions/template-logic/clone.d.ts +2 -16
- package/dist/extensions/template-logic/clone.js +15 -90
- package/dist/extensions/template-logic/clone.js.map +1 -1
- package/dist/extensions/template-logic/commands.d.ts +8 -0
- package/dist/extensions/template-logic/commands.js +21 -12
- package/dist/extensions/template-logic/commands.js.map +1 -1
- package/dist/extensions/template-logic/expression.d.ts +6 -0
- package/dist/extensions/template-logic/expression.js +56 -54
- package/dist/extensions/template-logic/expression.js.map +1 -1
- package/dist/extensions/template-logic/images.d.ts +14 -0
- package/dist/extensions/template-logic/images.js +277 -49
- package/dist/extensions/template-logic/images.js.map +1 -1
- package/dist/extensions/template-logic/index.js +20 -27
- package/dist/extensions/template-logic/index.js.map +1 -1
- package/dist/extensions/template-logic/list-commands.js +31 -16
- package/dist/extensions/template-logic/list-commands.js.map +1 -1
- package/dist/extensions/template-logic/renderer.d.ts +24 -0
- package/dist/extensions/template-logic/renderer.js +505 -380
- package/dist/extensions/template-logic/renderer.js.map +1 -1
- package/dist/extensions/template-logic/types.d.ts +5 -0
- package/dist/extensions/template-logic/types.js +6 -0
- package/dist/extensions/template-logic/types.js.map +1 -1
- package/dist/extensions/template-render/cli.js +7 -18
- package/dist/extensions/template-render/cli.js.map +1 -1
- package/dist/extensions/template-render/index.js +152 -107
- package/dist/extensions/template-render/index.js.map +1 -1
- package/dist/extensions/template-render/prune.d.ts +14 -0
- package/dist/extensions/template-render/prune.js +131 -0
- package/dist/extensions/template-render/prune.js.map +1 -0
- package/dist/extensions/template-render/zip-text.d.ts +9 -0
- package/dist/extensions/template-render/zip-text.js +27 -0
- package/dist/extensions/template-render/zip-text.js.map +1 -0
- package/dist/extensions/template-render/zip-writer.d.ts +16 -0
- package/dist/extensions/template-render/zip-writer.js +151 -0
- package/dist/extensions/template-render/zip-writer.js.map +1 -0
- package/dist/extensions/text-flow/flow.d.ts +5 -0
- package/dist/extensions/text-flow/flow.js +196 -207
- package/dist/extensions/text-flow/flow.js.map +1 -1
- package/dist/extensions/text-flow/font-file.js +9 -7
- package/dist/extensions/text-flow/font-file.js.map +1 -1
- package/dist/extensions/text-flow/fonts.d.ts +4 -0
- package/dist/extensions/text-flow/fonts.js +45 -22
- package/dist/extensions/text-flow/fonts.js.map +1 -1
- package/dist/extensions/text-flow/layout.js +5 -6
- package/dist/extensions/text-flow/layout.js.map +1 -1
- package/dist/extensions/text-flow/slide-styles.js +18 -22
- package/dist/extensions/text-flow/slide-styles.js.map +1 -1
- package/dist/extensions/text-flow/styles.d.ts +11 -0
- package/dist/extensions/text-flow/styles.js +121 -62
- package/dist/extensions/text-flow/styles.js.map +1 -1
- package/dist/helper/archive/archive-fs.js +102 -138
- package/dist/helper/archive/archive-fs.js.map +1 -1
- package/dist/helper/archive/archive-jszip.js +101 -125
- package/dist/helper/archive/archive-jszip.js.map +1 -1
- package/dist/helper/archive/archive.d.ts +6 -0
- package/dist/helper/archive/archive.js +21 -30
- package/dist/helper/archive/archive.js.map +1 -1
- package/dist/helper/archive/jszip-fast-read.d.ts +19 -0
- package/dist/helper/archive/jszip-fast-read.js +153 -0
- package/dist/helper/archive/jszip-fast-read.js.map +1 -0
- package/dist/helper/compute-src-rect.js +4 -5
- package/dist/helper/compute-src-rect.js.map +1 -1
- package/dist/helper/content-tracker.js +86 -114
- package/dist/helper/content-tracker.js.map +1 -1
- package/dist/helper/count-helper.js +48 -78
- package/dist/helper/count-helper.js.map +1 -1
- package/dist/helper/css-style-parser.js +1 -2
- package/dist/helper/css-style-parser.js.map +1 -1
- package/dist/helper/file-helper.js +30 -48
- package/dist/helper/file-helper.js.map +1 -1
- package/dist/helper/generate/generate-pptxgenjs.js +36 -48
- package/dist/helper/generate/generate-pptxgenjs.js.map +1 -1
- package/dist/helper/html-to-multitext-helper.js +34 -18
- package/dist/helper/html-to-multitext-helper.js.map +1 -1
- package/dist/helper/hyperlink-processor.js +125 -139
- package/dist/helper/hyperlink-processor.js.map +1 -1
- package/dist/helper/jszip-helper.js +23 -32
- package/dist/helper/jszip-helper.js.map +1 -1
- package/dist/helper/layout-index.js +51 -71
- package/dist/helper/layout-index.js.map +1 -1
- package/dist/helper/logger.js +4 -4
- package/dist/helper/logger.js.map +1 -1
- package/dist/helper/media-deduplicator.d.ts +24 -0
- package/dist/helper/media-deduplicator.js +81 -34
- package/dist/helper/media-deduplicator.js.map +1 -1
- package/dist/helper/modify-background-helper.js +46 -46
- package/dist/helper/modify-background-helper.js.map +1 -1
- package/dist/helper/modify-chart-helper.js +597 -591
- package/dist/helper/modify-chart-helper.js.map +1 -1
- package/dist/helper/modify-cleanup-helper.js +112 -112
- package/dist/helper/modify-cleanup-helper.js.map +1 -1
- package/dist/helper/modify-color-helper.js +53 -53
- package/dist/helper/modify-color-helper.js.map +1 -1
- package/dist/helper/modify-helper.js +25 -25
- package/dist/helper/modify-helper.js.map +1 -1
- package/dist/helper/modify-hyperlink-helper.js +143 -154
- package/dist/helper/modify-hyperlink-helper.js.map +1 -1
- package/dist/helper/modify-image-helper.js +121 -132
- package/dist/helper/modify-image-helper.js.map +1 -1
- package/dist/helper/modify-presentation-helper.js +137 -154
- package/dist/helper/modify-presentation-helper.js.map +1 -1
- package/dist/helper/modify-shape-helper.js +262 -262
- package/dist/helper/modify-shape-helper.js.map +1 -1
- package/dist/helper/modify-table-helper.js +84 -84
- package/dist/helper/modify-table-helper.js.map +1 -1
- package/dist/helper/modify-text-helper.js +187 -189
- package/dist/helper/modify-text-helper.js.map +1 -1
- package/dist/helper/modify-xml-helper.js +36 -36
- package/dist/helper/modify-xml-helper.js.map +1 -1
- package/dist/helper/multitext-helper.js +9 -7
- package/dist/helper/multitext-helper.js.map +1 -1
- package/dist/helper/ppt-paths.js +17 -17
- package/dist/helper/ppt-paths.js.map +1 -1
- package/dist/helper/shape-type-detector.js +18 -29
- package/dist/helper/shape-type-detector.js.map +1 -1
- package/dist/helper/text-replace-helper.js +6 -7
- package/dist/helper/text-replace-helper.js.map +1 -1
- package/dist/helper/xml-clone.d.ts +24 -0
- package/dist/helper/xml-clone.js +269 -0
- package/dist/helper/xml-clone.js.map +1 -0
- package/dist/helper/xml-elements.js +17 -20
- package/dist/helper/xml-elements.js.map +1 -1
- package/dist/helper/xml-find.d.ts +4 -0
- package/dist/helper/xml-find.js +48 -0
- package/dist/helper/xml-find.js.map +1 -0
- package/dist/helper/xml-helper.js +99 -134
- package/dist/helper/xml-helper.js.map +1 -1
- package/dist/helper/xml-parse-cache.d.ts +31 -0
- package/dist/helper/xml-parse-cache.js +71 -0
- package/dist/helper/xml-parse-cache.js.map +1 -0
- package/dist/helper/xml-placeholder-helper.js +10 -10
- package/dist/helper/xml-placeholder-helper.js.map +1 -1
- package/dist/helper/xml-relationship-helper.js +120 -144
- package/dist/helper/xml-relationship-helper.js.map +1 -1
- package/dist/helper/xml-serializer.d.ts +2 -0
- package/dist/helper/xml-serializer.js +192 -0
- package/dist/helper/xml-serializer.js.map +1 -0
- package/dist/helper/xml-slide-helper.js +109 -129
- package/dist/helper/xml-slide-helper.js.map +1 -1
- package/dist/helper/xml-template-helper.js +120 -144
- package/dist/helper/xml-template-helper.js.map +1 -1
- package/dist/helper/xmldom-sax-patch.js +52 -2
- package/dist/helper/xmldom-sax-patch.js.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/modify/modify-chart.js +35 -23
- package/dist/modify/modify-chart.js.map +1 -1
- package/dist/modify/modify-table.js +11 -14
- package/dist/modify/modify-table.js.map +1 -1
- package/dist/shapes/chart.js +238 -287
- package/dist/shapes/chart.js.map +1 -1
- package/dist/shapes/diagram.js +73 -104
- package/dist/shapes/diagram.js.map +1 -1
- package/dist/shapes/generic.js +62 -83
- package/dist/shapes/generic.js.map +1 -1
- package/dist/shapes/hyperlink.js +98 -124
- package/dist/shapes/hyperlink.js.map +1 -1
- package/dist/shapes/image.js +112 -151
- package/dist/shapes/image.js.map +1 -1
- package/dist/shapes/ole.js +148 -188
- package/dist/shapes/ole.js.map +1 -1
- package/package.json +3 -4
|
@@ -1,16 +1,7 @@
|
|
|
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.TextFlow = exports.flowArguments = exports.flowPlanEntries = exports.FlowShown = exports.FlowCache = void 0;
|
|
13
|
-
const
|
|
4
|
+
const xml_serializer_1 = require("../../helper/xml-serializer");
|
|
14
5
|
const logger_1 = require("../../helper/logger");
|
|
15
6
|
const fonts_1 = require("./fonts");
|
|
16
7
|
const layout_1 = require("./layout");
|
|
@@ -33,10 +24,9 @@ const isObject = (value) => (typeof value === 'object' && value !== null) || typ
|
|
|
33
24
|
/** The list a `flowContinue()` result was taken from. */
|
|
34
25
|
const continuedFrom = new WeakMap();
|
|
35
26
|
/** The list of the data that `list` stands for. */
|
|
36
|
-
const originOf = (list) =>
|
|
27
|
+
const originOf = (list) => isObject(list) ? (continuedFrom.get(list) ?? list) : undefined;
|
|
37
28
|
const count = (counts, entry) => {
|
|
38
|
-
|
|
39
|
-
counts.set(entry, ((_a = counts.get(entry)) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
29
|
+
counts.set(entry, (counts.get(entry) ?? 0) + 1);
|
|
40
30
|
};
|
|
41
31
|
/**
|
|
42
32
|
* The entries that `flow()` lists of earlier slides of a deck show, for
|
|
@@ -79,9 +69,8 @@ class FlowShown {
|
|
|
79
69
|
const values = this.values.get(origin);
|
|
80
70
|
const used = new Map();
|
|
81
71
|
const result = Array.from(list).filter((entry) => {
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
const skipped = (_c = used.get(entry)) !== null && _c !== void 0 ? _c : 0;
|
|
72
|
+
const shown = (isObject(entry) ? this.objects : values)?.get(entry) ?? 0;
|
|
73
|
+
const skipped = used.get(entry) ?? 0;
|
|
85
74
|
if (skipped >= shown)
|
|
86
75
|
return true;
|
|
87
76
|
used.set(entry, skipped + 1);
|
|
@@ -102,8 +91,7 @@ class FlowShown {
|
|
|
102
91
|
exports.FlowShown = FlowShown;
|
|
103
92
|
/** The entries a plan puts onto one of its pages (0-based). */
|
|
104
93
|
const flowPlanEntries = (plan, page) => {
|
|
105
|
-
|
|
106
|
-
const indexes = new Set([...((_b = (_a = plan.pages[page]) === null || _a === void 0 ? void 0 : _a.values()) !== null && _b !== void 0 ? _b : [])].flat());
|
|
94
|
+
const indexes = new Set([...(plan.pages[page]?.values() ?? [])].flat());
|
|
107
95
|
return [...indexes].sort((a, b) => a - b).map((i) => plan.list[i]);
|
|
108
96
|
};
|
|
109
97
|
exports.flowPlanEntries = flowPlanEntries;
|
|
@@ -111,17 +99,17 @@ const sameList = (a, b) => a.length === b.length && a.every((entry, i) => entry
|
|
|
111
99
|
const TOLERANCE = 0.01;
|
|
112
100
|
const EMU_PER_PT = 12700;
|
|
113
101
|
const childOf = (parent, tagName) => {
|
|
114
|
-
for (let n = parent
|
|
102
|
+
for (let n = parent?.firstChild; n; n = n.nextSibling) {
|
|
115
103
|
if (n.tagName === tagName)
|
|
116
104
|
return n;
|
|
117
105
|
}
|
|
118
106
|
return undefined;
|
|
119
107
|
};
|
|
120
|
-
const emuAttr = (el, name) =>
|
|
108
|
+
const emuAttr = (el, name) => Number(el?.getAttribute(name) ?? 0) / EMU_PER_PT;
|
|
121
109
|
/** The nearest p:grpSp around a shape, if it is grouped. */
|
|
122
110
|
const groupOf = (shape) => {
|
|
123
|
-
const parent = shape
|
|
124
|
-
return
|
|
111
|
+
const parent = shape?.parentNode;
|
|
112
|
+
return parent?.tagName === 'p:grpSp' ? parent : undefined;
|
|
125
113
|
};
|
|
126
114
|
/**
|
|
127
115
|
* A point in the coordinates of `shape`'s parent, mapped onto the slide
|
|
@@ -145,7 +133,6 @@ const toSlide = (shape, point) => {
|
|
|
145
133
|
};
|
|
146
134
|
/** Calls of `flow(…)` (or `flowRest(…)`) in a text. */
|
|
147
135
|
const flowArguments = (text, name = 'flow') => {
|
|
148
|
-
var _a, _b, _c;
|
|
149
136
|
const args = [];
|
|
150
137
|
const pattern = new RegExp(`(^|[^\\w$.])${name}\\s*\\(`, 'g');
|
|
151
138
|
while (pattern.exec(text)) {
|
|
@@ -172,22 +159,27 @@ const flowArguments = (text, name = 'flow') => {
|
|
|
172
159
|
commas.push(i);
|
|
173
160
|
}
|
|
174
161
|
const end = i - 1;
|
|
175
|
-
const source = text.slice(start,
|
|
162
|
+
const source = text.slice(start, commas[0] ?? end).trim();
|
|
176
163
|
const limit = commas.length > 0
|
|
177
|
-
? text.slice(commas[0] + 1,
|
|
164
|
+
? text.slice(commas[0] + 1, commas[1] ?? end).trim()
|
|
178
165
|
: '';
|
|
179
166
|
const options = commas.length > 1
|
|
180
|
-
? text.slice(commas[1] + 1,
|
|
167
|
+
? text.slice(commas[1] + 1, commas[2] ?? end).trim()
|
|
181
168
|
: '';
|
|
182
|
-
args.push(
|
|
169
|
+
args.push({
|
|
170
|
+
source,
|
|
171
|
+
key: source.replace(/\s+/g, ''),
|
|
172
|
+
...(limit ? { limit } : {}),
|
|
173
|
+
...(options ? { options } : {}),
|
|
174
|
+
});
|
|
183
175
|
}
|
|
184
176
|
return args;
|
|
185
177
|
};
|
|
186
178
|
exports.flowArguments = flowArguments;
|
|
187
179
|
const shapeName = (body) => {
|
|
188
180
|
const shape = body.parentNode;
|
|
189
|
-
const cNvPr = shape
|
|
190
|
-
return
|
|
181
|
+
const cNvPr = shape?.getElementsByTagName('p:cNvPr')[0];
|
|
182
|
+
return cNvPr?.getAttribute('name') || 'text box';
|
|
191
183
|
};
|
|
192
184
|
const textOf = (paragraph) => Array.from({ length: paragraph.getElementsByTagName('a:t').length }, (_, i) => paragraph.getElementsByTagName('a:t')[i].textContent).join('');
|
|
193
185
|
/**
|
|
@@ -198,7 +190,6 @@ const textOf = (paragraph) => Array.from({ length: paragraph.getElementsByTagNam
|
|
|
198
190
|
*/
|
|
199
191
|
class TextFlow {
|
|
200
192
|
constructor(boxes, host, options = {}) {
|
|
201
|
-
var _a;
|
|
202
193
|
this.host = host;
|
|
203
194
|
this.options = options;
|
|
204
195
|
/** Flow boxes (their p:txBody) and the source of their flow() argument. */
|
|
@@ -209,7 +200,7 @@ class TextFlow {
|
|
|
209
200
|
this.fingerprints = new Map();
|
|
210
201
|
this.plans = new Map();
|
|
211
202
|
this.resolved = new Map();
|
|
212
|
-
this.serializer =
|
|
203
|
+
this.serializer = { serializeToString: xml_serializer_1.serializeXml };
|
|
213
204
|
boxes.forEach((key, body) => {
|
|
214
205
|
this.keys.set(body, key);
|
|
215
206
|
this.indexes.set(body, this.indexes.size);
|
|
@@ -217,7 +208,7 @@ class TextFlow {
|
|
|
217
208
|
this.fingerprints.set(body, this.fingerprint(body));
|
|
218
209
|
}
|
|
219
210
|
});
|
|
220
|
-
this.fonts = new fonts_1.FontRegistry(
|
|
211
|
+
this.fonts = new fonts_1.FontRegistry(options.fonts ?? []);
|
|
221
212
|
}
|
|
222
213
|
/** The sources of the flow() lists, one per group of boxes. */
|
|
223
214
|
groups() {
|
|
@@ -228,36 +219,32 @@ class TextFlow {
|
|
|
228
219
|
* A `flowRest()` list that is no group's falls back to the only group.
|
|
229
220
|
* Must be awaited before `entries()`/`rest()`, which are synchronous.
|
|
230
221
|
*/
|
|
231
|
-
prepare(
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
this.
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
yield this.plans.get(group);
|
|
256
|
-
});
|
|
222
|
+
async prepare(key, list, limits = new Map(),
|
|
223
|
+
/** Boxes of `flow(list, n, { measure: false })`. */
|
|
224
|
+
unmeasured = new Set()) {
|
|
225
|
+
const groups = this.groups();
|
|
226
|
+
const group = groups.includes(key)
|
|
227
|
+
? key
|
|
228
|
+
: groups.length === 1
|
|
229
|
+
? groups[0]
|
|
230
|
+
: undefined;
|
|
231
|
+
if (group === undefined) {
|
|
232
|
+
throw new Error(`flowRest(${key}): no flow(${key}) on the slide`);
|
|
233
|
+
}
|
|
234
|
+
if (!this.plans.has(group)) {
|
|
235
|
+
const entries = this.toList(list);
|
|
236
|
+
this.plans.set(group, this.plan(group, entries, limits, unmeasured).then((plan) => {
|
|
237
|
+
this.reportOverflow(group, plan);
|
|
238
|
+
this.resolved.set(group, plan);
|
|
239
|
+
this.options.onFlowPlan?.(plan, list);
|
|
240
|
+
this.options.onFlowPages?.(this.pages);
|
|
241
|
+
return plan;
|
|
242
|
+
}));
|
|
243
|
+
}
|
|
244
|
+
await this.plans.get(group);
|
|
257
245
|
}
|
|
258
246
|
/** The entries of `list` that go into the text box `body`. */
|
|
259
247
|
entries(body, list) {
|
|
260
|
-
var _a;
|
|
261
248
|
const key = body && this.keys.get(body);
|
|
262
249
|
if (key === undefined) {
|
|
263
250
|
throw new Error('flow() works only in the loop of a text box, not in a table');
|
|
@@ -267,22 +254,21 @@ class TextFlow {
|
|
|
267
254
|
throw new Error(`flow(${key}) was not prepared`);
|
|
268
255
|
const entries = this.toList(list);
|
|
269
256
|
const page = plan.pages[this.page];
|
|
270
|
-
return (
|
|
257
|
+
return (page?.get(this.indexes.get(body)) ?? []).map((i) => i < entries.length ? entries[i] : plan.list[i]);
|
|
271
258
|
}
|
|
272
259
|
/**
|
|
273
260
|
* The entries of `list` after the rendered slide: on the next slides, or
|
|
274
261
|
* in none (they fit into no box).
|
|
275
262
|
*/
|
|
276
263
|
rest(list) {
|
|
277
|
-
var _a, _b;
|
|
278
264
|
const entries = this.toList(list);
|
|
279
265
|
const plans = [...this.resolved.values()];
|
|
280
|
-
const plan =
|
|
281
|
-
p.list.every((e, i) => e === entries[i]))
|
|
266
|
+
const plan = plans.find((p) => p.list.length === entries.length &&
|
|
267
|
+
p.list.every((e, i) => e === entries[i])) ?? (plans.length === 1 ? plans[0] : undefined);
|
|
282
268
|
if (!plan) {
|
|
283
269
|
throw new Error('flowRest(): no flow() over this list on the slide');
|
|
284
270
|
}
|
|
285
|
-
const end =
|
|
271
|
+
const end = plan.ends[Math.min(this.page, plan.ends.length - 1)] ?? 0;
|
|
286
272
|
return plan.list
|
|
287
273
|
.map((_, i) => i)
|
|
288
274
|
.slice(end)
|
|
@@ -293,6 +279,19 @@ class TextFlow {
|
|
|
293
279
|
const counts = [...this.resolved.values()].map((p) => p.pages.length);
|
|
294
280
|
return Math.max(1, ...counts);
|
|
295
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* The flow box of the card `shape` is in: a box in the nearest group
|
|
284
|
+
* around `shape` that has one. Its entries are the card's entries.
|
|
285
|
+
*/
|
|
286
|
+
boxOfCard(shape) {
|
|
287
|
+
for (let group = groupOf(shape); group; group = groupOf(group)) {
|
|
288
|
+
for (const body of this.keys.keys()) {
|
|
289
|
+
if (groupOf(body.parentNode) === group)
|
|
290
|
+
return body;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
296
295
|
/**
|
|
297
296
|
* Cards (PowerPoint groups with flow boxes) that stay empty on the
|
|
298
297
|
* rendered slide, such as the last columns of the last slide.
|
|
@@ -300,20 +299,18 @@ class TextFlow {
|
|
|
300
299
|
emptyGroups() {
|
|
301
300
|
const used = new Map();
|
|
302
301
|
this.keys.forEach((key, body) => {
|
|
303
|
-
var _a, _b;
|
|
304
302
|
const group = groupOf(body.parentNode);
|
|
305
303
|
if (!group)
|
|
306
304
|
return;
|
|
307
305
|
const plan = this.resolved.get(key);
|
|
308
|
-
const page = plan
|
|
309
|
-
const filled = !plan || !!
|
|
310
|
-
used.set(group, (
|
|
306
|
+
const page = plan?.pages[this.page];
|
|
307
|
+
const filled = !plan || !!page?.get(this.indexes.get(body))?.length;
|
|
308
|
+
used.set(group, (used.get(group) ?? false) || filled);
|
|
311
309
|
});
|
|
312
310
|
return [...used].filter(([, filled]) => !filled).map(([group]) => group);
|
|
313
311
|
}
|
|
314
312
|
get page() {
|
|
315
|
-
|
|
316
|
-
return (_a = this.options.flowPage) !== null && _a !== void 0 ? _a : 0;
|
|
313
|
+
return this.options.flowPage ?? 0;
|
|
317
314
|
}
|
|
318
315
|
toList(value) {
|
|
319
316
|
if (value === null || value === undefined)
|
|
@@ -340,79 +337,74 @@ class TextFlow {
|
|
|
340
337
|
* The plan of a list: from the cache if another copy of the slide has
|
|
341
338
|
* distributed the same entries over the same boxes, else computed.
|
|
342
339
|
*/
|
|
343
|
-
plan(key, list, limits, unmeasured) {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
cache.plans.set(signature, plan);
|
|
364
|
-
return plan;
|
|
365
|
-
});
|
|
340
|
+
async plan(key, list, limits, unmeasured) {
|
|
341
|
+
const cache = this.options.flowCache;
|
|
342
|
+
if (!cache)
|
|
343
|
+
return this.computePlan(key, list, limits, unmeasured);
|
|
344
|
+
// Everything the distribution depends on, besides the entries: the
|
|
345
|
+
// boxes, their limits and the paragraphs around the loop, which can
|
|
346
|
+
// differ from copy to copy ({{IF flowPage > 1}}…)
|
|
347
|
+
const parts = [key];
|
|
348
|
+
for (const body of this.bodiesOf(key)) {
|
|
349
|
+
const measured = !unmeasured.has(body);
|
|
350
|
+
const fixed = measured ? await this.host.renderCopy(body, []) : [];
|
|
351
|
+
parts.push(String(this.indexes.get(body)), String(limits.get(body) ?? ''), String(measured), this.fingerprints.get(body), ...fixed.map((p) => this.serializer.serializeToString(p)));
|
|
352
|
+
}
|
|
353
|
+
const signature = parts.join('\n');
|
|
354
|
+
const cached = cache.plans.get(signature);
|
|
355
|
+
if (cached && sameList(cached.list, list))
|
|
356
|
+
return cached;
|
|
357
|
+
const plan = await this.computePlan(key, list, limits, unmeasured);
|
|
358
|
+
cache.plans.set(signature, plan);
|
|
359
|
+
return plan;
|
|
366
360
|
}
|
|
367
|
-
computePlan(key, list, limits, unmeasured) {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
taken.push(next++);
|
|
403
|
-
}
|
|
404
|
-
slot.boxes.forEach((box) => page.set(this.indexes.get(box.body), taken));
|
|
361
|
+
async computePlan(key, list, limits, unmeasured) {
|
|
362
|
+
const bodies = this.bodiesOf(key);
|
|
363
|
+
const styles = await this.host.styles();
|
|
364
|
+
const boxes = [];
|
|
365
|
+
const measurements = new Map();
|
|
366
|
+
for (const body of bodies) {
|
|
367
|
+
boxes.push(unmeasured.has(body)
|
|
368
|
+
? this.unmeasuredBox(body, styles, limits)
|
|
369
|
+
: await this.measureBox(body, list, styles, measurements));
|
|
370
|
+
}
|
|
371
|
+
const slots = this.slotsOf(boxes);
|
|
372
|
+
const pages = [];
|
|
373
|
+
const ends = [];
|
|
374
|
+
let next = 0;
|
|
375
|
+
// Fill the slots, then the same slots on the next slide, … until an
|
|
376
|
+
// entry fits into none of them (or all are placed)
|
|
377
|
+
for (;;) {
|
|
378
|
+
const start = next;
|
|
379
|
+
const page = new Map();
|
|
380
|
+
for (const slot of slots) {
|
|
381
|
+
const taken = [];
|
|
382
|
+
const limit = Math.min(...slot.boxes.map((b) => limits.get(b.body) ?? Infinity));
|
|
383
|
+
while (next < list.length && taken.length < limit) {
|
|
384
|
+
// an entry too large for this slot tries the next one; in a
|
|
385
|
+
// card, its part has to fit into every box
|
|
386
|
+
const fits = slot.boxes.every((box) => !box.measured ||
|
|
387
|
+
(0, layout_1.stackHeight)([
|
|
388
|
+
...box.head,
|
|
389
|
+
...[...taken, next].flatMap((i) => box.entries[i]),
|
|
390
|
+
...box.tail,
|
|
391
|
+
]) <=
|
|
392
|
+
box.geometry.height + TOLERANCE);
|
|
393
|
+
if (!fits)
|
|
394
|
+
break;
|
|
395
|
+
taken.push(next++);
|
|
405
396
|
}
|
|
406
|
-
|
|
407
|
-
if (next === start && pages.length)
|
|
408
|
-
break;
|
|
409
|
-
pages.push(page);
|
|
410
|
-
ends.push(next);
|
|
411
|
-
if (next >= list.length || next === start)
|
|
412
|
-
break;
|
|
397
|
+
slot.boxes.forEach((box) => page.set(this.indexes.get(box.body), taken));
|
|
413
398
|
}
|
|
414
|
-
|
|
415
|
-
|
|
399
|
+
// a slide without progress: the next entry fits into no box
|
|
400
|
+
if (next === start && pages.length)
|
|
401
|
+
break;
|
|
402
|
+
pages.push(page);
|
|
403
|
+
ends.push(next);
|
|
404
|
+
if (next >= list.length || next === start)
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
return { list, pages, ends, names: boxes.map((b) => b.name) };
|
|
416
408
|
}
|
|
417
409
|
/** Entries this render leaves out: a warning, or an error. */
|
|
418
410
|
reportOverflow(key, plan) {
|
|
@@ -443,14 +435,14 @@ class TextFlow {
|
|
|
443
435
|
const shape = box.body.parentNode;
|
|
444
436
|
const group = groupOf(shape);
|
|
445
437
|
const { x, y } = toSlide(shape, box.geometry);
|
|
446
|
-
const slot = slots.get(group
|
|
438
|
+
const slot = slots.get(group ?? box.body);
|
|
447
439
|
if (slot) {
|
|
448
440
|
slot.boxes.push(box);
|
|
449
441
|
slot.x = Math.min(slot.x, x);
|
|
450
442
|
slot.y = Math.min(slot.y, y);
|
|
451
443
|
}
|
|
452
444
|
else {
|
|
453
|
-
slots.set(group
|
|
445
|
+
slots.set(group ?? box.body, { boxes: [box], group, x, y });
|
|
454
446
|
}
|
|
455
447
|
}
|
|
456
448
|
return [...slots.values()].sort((a, b) => Math.abs(a.x - b.x) > 1 ? a.x - b.x : a.y - b.y);
|
|
@@ -466,82 +458,79 @@ class TextFlow {
|
|
|
466
458
|
return {
|
|
467
459
|
body,
|
|
468
460
|
name,
|
|
469
|
-
geometry: geometry
|
|
461
|
+
geometry: geometry ?? { x: 0, y: 0, width: 0, height: 0 },
|
|
470
462
|
head: [],
|
|
471
463
|
tail: [],
|
|
472
464
|
entries: [],
|
|
473
465
|
measured: false,
|
|
474
466
|
};
|
|
475
467
|
}
|
|
476
|
-
measureBox(body, list, slide,
|
|
468
|
+
async measureBox(body, list, slide,
|
|
477
469
|
/** Measurements of this list so far, by measureKey. */
|
|
478
470
|
measurements) {
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
split = k;
|
|
524
|
-
break;
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
if (split === undefined) {
|
|
528
|
-
throw new Error(`flow(): in "${name}", put {{FOR …}} and {{END-FOR}} into ` +
|
|
529
|
-
'paragraphs of their own, around whole paragraphs');
|
|
471
|
+
const name = shapeName(body);
|
|
472
|
+
const styles = new styles_1.ShapeStyles(body.parentNode, slide, this.fonts);
|
|
473
|
+
const geometry = styles.geometry();
|
|
474
|
+
if (!geometry) {
|
|
475
|
+
throw new Error(`flow(): "${name}" has no position and size of its own ` +
|
|
476
|
+
'(a placeholder that inherits them is not supported)');
|
|
477
|
+
}
|
|
478
|
+
const unsupported = styles.unsupported();
|
|
479
|
+
if (unsupported)
|
|
480
|
+
throw new Error(`flow(): "${name}" has ${unsupported}, which flow() cannot measure`);
|
|
481
|
+
const key = this.host.measureKey?.(body);
|
|
482
|
+
const known = key === undefined ? undefined : measurements.get(key);
|
|
483
|
+
if (known)
|
|
484
|
+
return { body, name, geometry, ...known, measured: true };
|
|
485
|
+
const measure = (paragraphs) => styles
|
|
486
|
+
.paragraphs(paragraphs)
|
|
487
|
+
.map((p) => (0, layout_1.measureParagraph)(p, geometry.width));
|
|
488
|
+
const xml = (p) => this.serializer.serializeToString(p);
|
|
489
|
+
// Without entries: the paragraphs around the loop. A body left empty
|
|
490
|
+
// keeps one empty paragraph, which is not there once entries are in.
|
|
491
|
+
let fixed = await this.host.renderCopy(body, []);
|
|
492
|
+
if (fixed.length === 1 && !textOf(fixed[0]).trim())
|
|
493
|
+
fixed = [];
|
|
494
|
+
const fixedXml = fixed.map(xml);
|
|
495
|
+
const head = [];
|
|
496
|
+
const tail = [];
|
|
497
|
+
const entries = [];
|
|
498
|
+
let split;
|
|
499
|
+
for (const entry of list) {
|
|
500
|
+
const rendered = await this.host.renderCopy(body, [entry]);
|
|
501
|
+
// the loop's output sits between a common head and a common tail
|
|
502
|
+
if (split === undefined) {
|
|
503
|
+
const renderedXml = rendered.map(xml);
|
|
504
|
+
for (let k = 0; k <= fixed.length; k++) {
|
|
505
|
+
const headMatches = fixedXml
|
|
506
|
+
.slice(0, k)
|
|
507
|
+
.every((x, i) => renderedXml[i] === x);
|
|
508
|
+
const tailLength = fixed.length - k;
|
|
509
|
+
const tailMatches = fixedXml
|
|
510
|
+
.slice(k)
|
|
511
|
+
.every((x, i) => renderedXml[rendered.length - tailLength + i] === x);
|
|
512
|
+
if (headMatches && tailMatches && rendered.length >= fixed.length) {
|
|
513
|
+
split = k;
|
|
514
|
+
break;
|
|
530
515
|
}
|
|
531
|
-
head.push(...fixed.slice(0, split));
|
|
532
|
-
tail.push(...fixed.slice(split));
|
|
533
516
|
}
|
|
534
|
-
|
|
517
|
+
if (split === undefined) {
|
|
518
|
+
throw new Error(`flow(): in "${name}", put {{FOR …}} and {{END-FOR}} into ` +
|
|
519
|
+
'paragraphs of their own, around whole paragraphs');
|
|
520
|
+
}
|
|
521
|
+
head.push(...fixed.slice(0, split));
|
|
522
|
+
tail.push(...fixed.slice(split));
|
|
535
523
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
524
|
+
entries.push(measure(rendered.slice(split, rendered.length - (fixed.length - split))));
|
|
525
|
+
}
|
|
526
|
+
const measurement = {
|
|
527
|
+
head: measure(head),
|
|
528
|
+
tail: measure(tail),
|
|
529
|
+
entries,
|
|
530
|
+
};
|
|
531
|
+
if (key !== undefined)
|
|
532
|
+
measurements.set(key, measurement);
|
|
533
|
+
return { body, name, geometry, ...measurement, measured: true };
|
|
545
534
|
}
|
|
546
535
|
}
|
|
547
536
|
exports.TextFlow = TextFlow;
|