pptx-templates 0.3.6 → 0.3.8

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 CHANGED
@@ -1127,8 +1127,15 @@ longer than the line by characters, and a line height of 1.2 × the font size
1127
1127
  (× the line spacing). Text around the loop, such as a heading above it,
1128
1128
  counts as well. The copies are thrown away; `EXEC` assignments of these trial
1129
1129
  renders are undone, so a counter in the loop counts every entry once.
1130
+ Boxes that are the same apart from their position and name, such as three
1131
+ equal columns, share one measurement. Each box is measured by itself when
1132
+ the loop contains an `HTML` tag or an `errorHandler` is set, since those
1133
+ trial renders have effects beyond their text.
1134
+ Functions in the data run during these trial renders as well, how often
1135
+ depends on the boxes and is not fixed, so they should not count or change
1136
+ anything outside the template: a counter belongs in `EXEC`.
1130
1137
 
1131
- Measuring a slide with 24 entries in three boxes takes about 0.2 seconds.
1138
+ Measuring a slide with 24 entries in three boxes takes about 0.04 seconds.
1132
1139
 
1133
1140
  ### Fonts
1134
1141
 
@@ -1330,6 +1337,8 @@ the render (`strict`, `fixSmartQuotes`, other delimiters, `errorHandler`).
1330
1337
  them is true.
1331
1338
  - The tags are removed from the notes of the output; the rest of the notes
1332
1339
  stays. A paragraph that held nothing but the tag goes as well.
1340
+ - A hidden slide leaves nothing behind in the output file: neither its
1341
+ notes nor its embedded objects.
1333
1342
  - When every slide is hidden, the output has no slides.
1334
1343
 
1335
1344
  ### Why the speaker notes
@@ -1352,6 +1361,9 @@ repeated by `renderDeck`. The condition is evaluated for each copy, with
1352
1361
  ```
1353
1362
 
1354
1363
  keeps the first three copies of the slide and leaves out the rest.
1364
+ Each copy has its own speaker notes and its own copy of the slide's
1365
+ embedded objects (OLE objects, embedded Excel or Word documents, charts
1366
+ with their workbooks).
1355
1367
 
1356
1368
  ### With addSlide
1357
1369
 
package/CHANGELOG.md CHANGED
@@ -6,6 +6,67 @@ semver, with the pre-1.0 convention that **breaking changes bump the minor**.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.3.8] - 2026-11-19
10
+
11
+ ### Changed
12
+
13
+ - `flow()` measures two to four times faster, with the same result:
14
+ `renderDeck` with 24 entries in three columns takes about 0.07 instead
15
+ of 0.15 seconds, with 1,000 entries about 0.8 instead of 3.5 seconds.
16
+ Nodes of the template are cloned without xmldom's slow `cloneNode`,
17
+ boxes that are the same apart from position and name share one
18
+ measurement (not with `HTML` tags or an `errorHandler`), and
19
+ `countFlowPages` no longer packs a .pptx it throws away, nor does
20
+ `renderDeck` unzip the deck again for each slide.
21
+ Functions in the data are called fewer times while measuring; one that
22
+ counts in a variable outside the template sees a different number.
23
+ Counters in `EXEC` are not affected.
24
+
25
+ ### Fixed
26
+
27
+ - `cleanup` (with `removeExistingSlides`, as in `renderDeck`) keeps the
28
+ embeddings and charts of slide masters and layouts. It deleted every
29
+ file in `ppt/embeddings` and `ppt/charts` that was not copied with a
30
+ slide, so OLE objects on a master or layout (e.g. think-cell, an
31
+ embedded logo) and charts there, with their workbooks, pointed at
32
+ missing parts and PowerPoint offered to repair the file. The 0.3.7 fix
33
+ only covered embeddings of slides.
34
+
35
+ ## [0.3.7] - 2026-11-18
36
+
37
+ ### Fixed
38
+
39
+ - A slide with an embedded Office document (Excel worksheet, Word document:
40
+ a `package` relationship, as PowerPoint inserts them) can be copied. Its
41
+ relationship matched every prefix, so the slide was taken for a chart and
42
+ `addSlide`/`renderDeck` failed with `Could not find file
43
+ ppt/charts/chart0.xml`.
44
+ - Embedded documents are copied with their slide. Before, only `oleObject`
45
+ relationships were copied; an embedded worksheet kept pointing at the
46
+ template's file, which `renderDeck` (cleanup) then deleted.
47
+ - Copied OLE objects no longer overwrite each other. The copy was named
48
+ after the slide's relationship id (`oleObjectrId9-created.bin`), which
49
+ repeats from slide to slide: two slides with different objects ended up
50
+ with the same file. Copies are now named after the source with the next
51
+ free number (`oleObject2.bin`, `Microsoft_Excel_Worksheet1.xlsx`), keep
52
+ their extension (`.xlsm`, `.docx`, … were renamed to `.bin`) and the
53
+ content type of the template. Linked objects (`TargetMode="External"`)
54
+ are left as they are instead of failing.
55
+ - A copied `chartEx` chart (waterfall, sunburst, …) no longer overwrites a
56
+ chart of the deck: the chart counter skipped `chartEx` parts, so the copy
57
+ reused `chartEx1.xml`/`style1.xml`/`colors1.xml` and `[Content_Types].xml`
58
+ listed them twice.
59
+ - A deck written by pptx-templates can be loaded again as root and get new
60
+ slides (e.g. the output of `renderDeck`, processed further with
61
+ `addSlide`/`modifyElement`). Its slide parts start at `slide4.xml` or
62
+ higher; new slides were numbered after the slide count, overwrote its
63
+ slides and registered them twice in `[Content_Types].xml`, and PowerPoint
64
+ offered to repair the file.
65
+ - With `removeExistingSlides` and `cleanup` (as in `renderDeck`), the
66
+ speaker notes and rels of the removed template slides are deleted too.
67
+ The notes of a slide left out with `{{HIDE-SLIDE …}}` were still in the
68
+ output file.
69
+
9
70
  ## [0.3.6] - 2026-11-17
10
71
 
11
72
  ### Added
@@ -314,7 +375,9 @@ for that history.
314
375
  into one `.png` part. The fallback now gets the same placeholder PNG that
315
376
  pptxgenjs 3.12 wrote.
316
377
 
317
- [Unreleased]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.6...HEAD
378
+ [Unreleased]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.8...HEAD
379
+ [0.3.8]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.7...v0.3.8
380
+ [0.3.7]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.6...v0.3.7
318
381
  [0.3.6]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.5...v0.3.6
319
382
  [0.3.5]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.4...v0.3.5
320
383
  [0.3.4]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.3...v0.3.4
@@ -0,0 +1,13 @@
1
+ import IArchive from '../../interfaces/iarchive';
2
+ /**
3
+ * Files in `ppt/charts` and `ppt/embeddings` that a slide master or layout
4
+ * of the archive uses, by folder: OLE objects and embedded documents (e.g.
5
+ * think-cell, a logo object on the master), charts, and what these point
6
+ * at in turn (a chart's style, colors and workbook).
7
+ *
8
+ * `cleanup` keeps masters and layouts as they are, but removed every chart
9
+ * and embedding that was not copied with a slide: the relationships of the
10
+ * masters and layouts then pointed at missing parts, and PowerPoint offered
11
+ * to repair the file. `removeUnusedFiles` keeps these files.
12
+ */
13
+ export declare function partsOfMastersAndLayouts(archive: IArchive): Promise<Record<string, string[]>>;
@@ -0,0 +1,84 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.partsOfMastersAndLayouts = partsOfMastersAndLayouts;
16
+ const path_1 = __importDefault(require("path"));
17
+ /** Parts whose relationships the search starts from. */
18
+ const MASTER_DIRS = ['ppt/slideMasters', 'ppt/slideLayouts'];
19
+ /**
20
+ * Folders `ModifyPresentationHelper.removeUnusedFiles` empties of the files
21
+ * it did not copy with a slide, and whose parts masters and layouts use.
22
+ */
23
+ const KEPT_DIRS = ['ppt/charts', 'ppt/embeddings'];
24
+ /**
25
+ * Files in `ppt/charts` and `ppt/embeddings` that a slide master or layout
26
+ * of the archive uses, by folder: OLE objects and embedded documents (e.g.
27
+ * think-cell, a logo object on the master), charts, and what these point
28
+ * at in turn (a chart's style, colors and workbook).
29
+ *
30
+ * `cleanup` keeps masters and layouts as they are, but removed every chart
31
+ * and embedding that was not copied with a slide: the relationships of the
32
+ * masters and layouts then pointed at missing parts, and PowerPoint offered
33
+ * to repair the file. `removeUnusedFiles` keeps these files.
34
+ */
35
+ function partsOfMastersAndLayouts(archive) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const queue = [];
38
+ for (const dir of MASTER_DIRS) {
39
+ for (const file of yield archive.folder(`${dir}/_rels`)) {
40
+ if (file.name.endsWith('.rels'))
41
+ queue.push(file.name);
42
+ }
43
+ }
44
+ const keep = {};
45
+ const seen = new Set();
46
+ while (queue.length) {
47
+ for (const target of yield internalTargets(archive, queue.shift())) {
48
+ const dir = path_1.default.posix.dirname(target);
49
+ if (!KEPT_DIRS.includes(dir) || seen.has(target))
50
+ continue;
51
+ seen.add(target);
52
+ keep[dir] = [...(keep[dir] || []), path_1.default.posix.basename(target)];
53
+ const rels = relsOf(target);
54
+ if (archive.fileExists(rels))
55
+ queue.push(rels);
56
+ }
57
+ }
58
+ return keep;
59
+ });
60
+ }
61
+ /** Archive paths of the parts a .rels file points at, external ones left out. */
62
+ function internalTargets(archive, relsFile) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ // Targets are relative to the part's folder, not to its _rels folder.
65
+ const partDir = path_1.default.posix.dirname(path_1.default.posix.dirname(relsFile));
66
+ const relationships = (yield archive.readXml(relsFile)).getElementsByTagName('Relationship');
67
+ const targets = [];
68
+ for (let i = 0; i < relationships.length; i++) {
69
+ const rel = relationships.item(i);
70
+ if (rel.getAttribute('TargetMode') === 'External')
71
+ continue;
72
+ const target = rel.getAttribute('Target') || '';
73
+ targets.push(target.startsWith('/')
74
+ ? path_1.default.posix.normalize(target.slice(1))
75
+ : path_1.default.posix.normalize(path_1.default.posix.join(partDir, target)));
76
+ }
77
+ return targets;
78
+ });
79
+ }
80
+ /** `ppt/charts/chart1.xml` → `ppt/charts/_rels/chart1.xml.rels`. */
81
+ function relsOf(part) {
82
+ return `${path_1.default.posix.dirname(part)}/_rels/${path_1.default.posix.basename(part)}.rels`;
83
+ }
84
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/master-parts/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAuBA,4DAuBC;AA9CD,gDAAwB;AAGxB,wDAAwD;AACxD,MAAM,WAAW,GAAG,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;AAE7D;;;GAGG;AACH,MAAM,SAAS,GAAG,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;AAEnD;;;;;;;;;;GAUG;AACH,SAAsB,wBAAwB,CAC5C,OAAiB;;QAEjB,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;YAC9B,KAAK,MAAM,IAAI,IAAI,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,GAAG,QAAQ,CAAC,EAAE,CAAC;gBACxD,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;oBAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;QAED,MAAM,IAAI,GAA6B,EAAE,CAAC;QAC1C,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;QAC/B,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;YACpB,KAAK,MAAM,MAAM,IAAI,MAAM,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC;gBACnE,MAAM,GAAG,GAAG,cAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBACvC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;oBAAE,SAAS;gBAC3D,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAA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AC,CAAC,cAAI,CAAC,KAAK,CAAC,SAAS,CAAC,cAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAC3D,CAAC;QACJ,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CAAA;AAED,oEAAoE;AACpE,SAAS,MAAM,CAAC,IAAY;IAC1B,OAAO,GAAG,cAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,cAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * A faster `node.cloneNode(deep)` for xmldom nodes, with the same result.
3
+ *
4
+ * xmldom 0.9 copies the scalar properties of each node with a `for … in`
5
+ * loop over the whole prototype chain (about 80 keys per element), which
6
+ * made cloning most of the time `flow()` takes. This copies the same own
7
+ * scalar properties with `Object.keys` onto a node made by the document's
8
+ * own factory, attaches cloned attributes with `setAttributeNode` and
9
+ * children with `appendChild`, as xmldom does.
10
+ *
11
+ * Elements, attributes and text nodes of XML documents take the fast path.
12
+ * Anything else (comments, CDATA, processing instructions, HTML documents)
13
+ * and any error on the way fall back to xmldom's own `cloneNode`.
14
+ */
15
+ /** `node.cloneNode(deep)`, faster for elements and text of XML documents. */
16
+ export declare const cloneXml: <T>(node: T, deep?: boolean) => T;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ /**
3
+ * A faster `node.cloneNode(deep)` for xmldom nodes, with the same result.
4
+ *
5
+ * xmldom 0.9 copies the scalar properties of each node with a `for … in`
6
+ * loop over the whole prototype chain (about 80 keys per element), which
7
+ * made cloning most of the time `flow()` takes. This copies the same own
8
+ * scalar properties with `Object.keys` onto a node made by the document's
9
+ * own factory, attaches cloned attributes with `setAttributeNode` and
10
+ * children with `appendChild`, as xmldom does.
11
+ *
12
+ * Elements, attributes and text nodes of XML documents take the fast path.
13
+ * Anything else (comments, CDATA, processing instructions, HTML documents)
14
+ * and any error on the way fall back to xmldom's own `cloneNode`.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.cloneXml = void 0;
18
+ const ELEMENT_NODE = 1;
19
+ const TEXT_NODE = 3;
20
+ /** Documents whose factories behave as xmldom's cloneNode (no HTML rules). */
21
+ const isPlainXml = (doc) => !!doc &&
22
+ doc.type !== 'html' &&
23
+ doc.contentType !== 'text/html' &&
24
+ doc.contentType !== 'application/xhtml+xml';
25
+ /** What xmldom's cloneNode copies: own properties that are not objects. */
26
+ const copyScalars = (source, target) => {
27
+ const from = source;
28
+ const to = target;
29
+ for (const key of Object.keys(from)) {
30
+ const value = from[key];
31
+ if (typeof value !== 'object' && value != to[key])
32
+ to[key] = value;
33
+ }
34
+ };
35
+ const cloneAttribute = (doc, attr) => {
36
+ const copy = doc.createAttribute(attr.name);
37
+ copyScalars(attr, copy);
38
+ return copy;
39
+ };
40
+ /** One node without its children, or undefined: use xmldom's cloneNode. */
41
+ const cloneShallow = (doc, node) => {
42
+ if (node.nodeType === TEXT_NODE) {
43
+ const copy = doc.createTextNode(node.data);
44
+ copyScalars(node, copy);
45
+ return copy;
46
+ }
47
+ if (node.nodeType !== ELEMENT_NODE)
48
+ return undefined;
49
+ const copy = doc.createElement(node.tagName);
50
+ copyScalars(node, copy);
51
+ const attrs = node.attributes;
52
+ for (let i = 0; i < attrs.length; i++) {
53
+ copy.setAttributeNode(cloneAttribute(doc, attrs.item(i)));
54
+ }
55
+ return copy;
56
+ };
57
+ const fastClone = (doc, root, deep) => {
58
+ var _a;
59
+ const top = (_a = cloneShallow(doc, root)) !== null && _a !== void 0 ? _a : root.cloneNode(deep);
60
+ if (!deep || root.nodeType !== ELEMENT_NODE)
61
+ return top;
62
+ // depth-first without recursion: [source parent, its copy]
63
+ const stack = [[root, top]];
64
+ while (stack.length) {
65
+ const [source, target] = stack.pop();
66
+ for (let child = source.firstChild; child; child = child.nextSibling) {
67
+ const shallow = cloneShallow(doc, child);
68
+ if (shallow) {
69
+ target.appendChild(shallow);
70
+ if (child.firstChild)
71
+ stack.push([child, shallow]);
72
+ }
73
+ else {
74
+ target.appendChild(child.cloneNode(true));
75
+ }
76
+ }
77
+ }
78
+ return top;
79
+ };
80
+ /** `node.cloneNode(deep)`, faster for elements and text of XML documents. */
81
+ const cloneXml = (node, deep = false) => {
82
+ const dom = node;
83
+ const doc = dom.ownerDocument;
84
+ if (!isPlainXml(doc))
85
+ return dom.cloneNode(deep);
86
+ try {
87
+ return fastClone(doc, dom, deep);
88
+ }
89
+ catch (_a) {
90
+ return dom.cloneNode(deep);
91
+ }
92
+ };
93
+ exports.cloneXml = cloneXml;
94
+ //# sourceMappingURL=clone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clone.js","sourceRoot":"","sources":["../../../src/extensions/template-logic/clone.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAEH,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,SAAS,GAAG,CAAC,CAAC;AAyBpB,8EAA8E;AAC9E,MAAM,UAAU,GAAG,CAAC,GAAuB,EAAsB,EAAE,CACjE,CAAC,CAAC,GAAG;IACL,GAAG,CAAC,IAAI,KAAK,MAAM;IACnB,GAAG,CAAC,WAAW,KAAK,WAAW;IAC/B,GAAG,CAAC,WAAW,KAAK,uBAAuB,CAAC;AAE9C,2EAA2E;AAC3E,MAAM,WAAW,GAAG,CAAC,MAAe,EAAE,MAAe,EAAQ,EAAE;IAC7D,MAAM,IAAI,GAAG,MAA4C,CAAC;IAC1D,MAAM,EAAE,GAAG,MAA4C,CAAC;IACxD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACpC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;QACxB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,EAAE,CAAC,GAAG,CAAC;YAAE,EAAE,CAAC,GAAG,CAAC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;IACnD,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,GAAG,CAAC,SAAS,CAAC,IAAI,CAAiB,CAAC;IAC7C,CAAC;AACH,CAAC,CAAC;AATW,QAAA,QAAQ,YASnB"}
@@ -64,6 +64,15 @@ export declare class TemplateRenderer {
64
64
  * this trial render are undone; the real render repeats them.
65
65
  */
66
66
  private renderCopy;
67
+ /**
68
+ * flow(): boxes with the same key render and measure the same, so one
69
+ * measurement serves all of them: the shape as it is, without its
70
+ * position and its id and name. Undefined where a measuring render has
71
+ * effects beyond its result, which measuring each box repeats: an
72
+ * errorHandler is called per error, and HTML links add a relationship
73
+ * per render. Tags that do not parse are left to the full measurement.
74
+ */
75
+ private flowMeasureKey;
67
76
  /** Shape text bodies and tables, in document order. */
68
77
  private findTargets;
69
78
  private containsTag;
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.TemplateRenderer = exports.TemplateRenderError = void 0;
13
+ const xmldom_1 = require("@xmldom/xmldom");
13
14
  const xml_helper_1 = require("../../helper/xml-helper");
14
15
  const xml_relationship_helper_1 = require("../../helper/xml-relationship-helper");
15
16
  const multitext_helper_1 = require("../../helper/multitext-helper");
@@ -17,6 +18,7 @@ const html_to_multitext_helper_1 = require("../../helper/html-to-multitext-helpe
17
18
  const expression_1 = require("./expression");
18
19
  const commands_1 = require("./commands");
19
20
  const images_1 = require("./images");
21
+ const clone_1 = require("./clone");
20
22
  const text_flow_1 = require("../text-flow");
21
23
  const logger_1 = require("../../helper/logger");
22
24
  /** Tags that open, split or close a block. */
@@ -237,6 +239,7 @@ class TemplateRenderer {
237
239
  return;
238
240
  this.textFlow = new text_flow_1.TextFlow(boxes, {
239
241
  renderCopy: (body, entries) => this.renderCopy(body, entries),
242
+ measureKey: (body) => this.flowMeasureKey(body),
240
243
  styles: () => __awaiter(this, void 0, void 0, function* () { var _a, _b, _c; return (_c = (yield ((_b = (_a = this.context).styles) === null || _b === void 0 ? void 0 : _b.call(_a)))) !== null && _c !== void 0 ? _c : {}; }),
241
244
  }, {
242
245
  fonts: this.options.fonts,
@@ -343,7 +346,7 @@ class TemplateRenderer {
343
346
  */
344
347
  renderCopy(body, entries) {
345
348
  return __awaiter(this, void 0, void 0, function* () {
346
- const copy = body.cloneNode(true);
349
+ const copy = (0, clone_1.cloneXml)(body, true);
347
350
  const saved = {
348
351
  override: this.flowOverride,
349
352
  current: this.currentBody,
@@ -366,6 +369,41 @@ class TemplateRenderer {
366
369
  }
367
370
  });
368
371
  }
372
+ /**
373
+ * flow(): boxes with the same key render and measure the same, so one
374
+ * measurement serves all of them: the shape as it is, without its
375
+ * position and its id and name. Undefined where a measuring render has
376
+ * effects beyond its result, which measuring each box repeats: an
377
+ * errorHandler is called per error, and HTML links add a relationship
378
+ * per render. Tags that do not parse are left to the full measurement.
379
+ */
380
+ flowMeasureKey(body) {
381
+ if (this.options.errorHandler)
382
+ return undefined;
383
+ const text = xml_helper_1.XmlHelper.collectionToArray(body.getElementsByTagName('a:t'))
384
+ .map((t) => t.textContent)
385
+ .join('');
386
+ for (const match of text.matchAll(this.tagPattern)) {
387
+ try {
388
+ const resolved = (0, commands_1.resolveAlias)(match[1], this.aliases, match[0]);
389
+ const command = (0, commands_1.parseCommand)(this.options.fixSmartQuotes ? (0, commands_1.fixSmartQuotes)(resolved) : resolved, match[0]);
390
+ if (command.type === 'HTML')
391
+ return undefined;
392
+ }
393
+ catch (_a) {
394
+ return undefined;
395
+ }
396
+ }
397
+ const shape = (0, clone_1.cloneXml)(body.parentNode, true);
398
+ const childOf = (parent, tagName) => parent && this.childElements(parent, tagName)[0];
399
+ const off = childOf(childOf(childOf(shape, 'p:spPr'), 'a:xfrm'), 'a:off');
400
+ off === null || off === void 0 ? void 0 : off.setAttribute('x', '0');
401
+ off === null || off === void 0 ? void 0 : off.setAttribute('y', '0');
402
+ const cNvPr = childOf(childOf(shape, 'p:nvSpPr'), 'p:cNvPr');
403
+ cNvPr === null || cNvPr === void 0 ? void 0 : cNvPr.removeAttribute('id');
404
+ cNvPr === null || cNvPr === void 0 ? void 0 : cNvPr.removeAttribute('name');
405
+ return new xmldom_1.XMLSerializer().serializeToString(shape);
406
+ }
369
407
  /** Shape text bodies and tables, in document order. */
370
408
  findTargets(element) {
371
409
  const targets = [];
@@ -764,7 +802,7 @@ class TemplateRenderer {
764
802
  paragraphs.push({ source: token.paragraph, nodes: [] });
765
803
  break;
766
804
  case 'node':
767
- current().nodes.push(token.node.cloneNode(true));
805
+ current().nodes.push((0, clone_1.cloneXml)(token.node, true));
768
806
  break;
769
807
  case 'text':
770
808
  current().nodes.push(...this.createRuns(token.run, token.text));
@@ -898,14 +936,14 @@ class TemplateRenderer {
898
936
  });
899
937
  }
900
938
  createParagraph(output) {
901
- const paragraph = output.source.cloneNode(false);
939
+ const paragraph = (0, clone_1.cloneXml)(output.source, false);
902
940
  const pPr = this.childElements(output.source, 'a:pPr')[0];
903
941
  const endParaRPr = this.childElements(output.source, 'a:endParaRPr')[0];
904
942
  if (pPr)
905
- paragraph.appendChild(pPr.cloneNode(true));
943
+ paragraph.appendChild((0, clone_1.cloneXml)(pPr, true));
906
944
  output.nodes.forEach((node) => paragraph.appendChild(node));
907
945
  if (endParaRPr)
908
- paragraph.appendChild(endParaRPr.cloneNode(true));
946
+ paragraph.appendChild((0, clone_1.cloneXml)(endParaRPr, true));
909
947
  return paragraph;
910
948
  }
911
949
  /** Clone a run with new text; line breaks become <a:br/>. */
@@ -922,12 +960,12 @@ class TemplateRenderer {
922
960
  if (index > 0) {
923
961
  const br = doc.createElement('a:br');
924
962
  if (rPr)
925
- br.appendChild(rPr.cloneNode(true));
963
+ br.appendChild((0, clone_1.cloneXml)(rPr, true));
926
964
  nodes.push(br);
927
965
  }
928
966
  if (line === '')
929
967
  return;
930
- const run = template.cloneNode(true);
968
+ const run = (0, clone_1.cloneXml)(template, true);
931
969
  const t = run.getElementsByTagName('a:t')[0];
932
970
  while (t.firstChild)
933
971
  t.removeChild(t.firstChild);
@@ -960,10 +998,10 @@ class TemplateRenderer {
960
998
  htmlParagraphs(body, source, run, html, relations) {
961
999
  const doc = body.ownerDocument;
962
1000
  const host = doc.createElement('p:sp');
963
- const scratch = body.cloneNode(false);
964
- ['a:bodyPr', 'a:lstStyle'].forEach((name) => this.childElements(body, name).forEach((child) => scratch.appendChild(child.cloneNode(true))));
965
- const paragraph = source.cloneNode(false);
966
- paragraph.appendChild(run.cloneNode(true));
1001
+ const scratch = (0, clone_1.cloneXml)(body, false);
1002
+ ['a:bodyPr', 'a:lstStyle'].forEach((name) => this.childElements(body, name).forEach((child) => scratch.appendChild((0, clone_1.cloneXml)(child, true))));
1003
+ const paragraph = (0, clone_1.cloneXml)(source, false);
1004
+ paragraph.appendChild((0, clone_1.cloneXml)(run, true));
967
1005
  scratch.appendChild(paragraph);
968
1006
  host.appendChild(scratch);
969
1007
  // The html pipeline wants a <body>; template values are usually fragments.
@@ -1071,7 +1109,7 @@ class TemplateRenderer {
1071
1109
  });
1072
1110
  const output = [];
1073
1111
  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* () {
1074
- const row = token.row.cloneNode(true);
1112
+ const row = (0, clone_1.cloneXml)(token.row, true);
1075
1113
  const cells = this.childElements(row, 'a:tc');
1076
1114
  for (let c = 0; c < cells.length; c++) {
1077
1115
  const bodyTokens = token.cells[c];