pptx-templates 0.3.9 → 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.
Files changed (216) hide show
  1. package/AI-INSTRUCTOR.md +4 -1
  2. package/CHANGELOG.md +104 -1
  3. package/dist/automizer.js +143 -176
  4. package/dist/automizer.js.map +1 -1
  5. package/dist/classes/content-type-registry.js +23 -36
  6. package/dist/classes/content-type-registry.js.map +1 -1
  7. package/dist/classes/element-importer.js +129 -148
  8. package/dist/classes/element-importer.js.map +1 -1
  9. package/dist/classes/has-shapes.js +81 -126
  10. package/dist/classes/has-shapes.js.map +1 -1
  11. package/dist/classes/layout.js +47 -67
  12. package/dist/classes/layout.js.map +1 -1
  13. package/dist/classes/master.js +70 -89
  14. package/dist/classes/master.js.map +1 -1
  15. package/dist/classes/placeholder-normalizer.js +48 -37
  16. package/dist/classes/placeholder-normalizer.js.map +1 -1
  17. package/dist/classes/related-content-copier.js +65 -86
  18. package/dist/classes/related-content-copier.js.map +1 -1
  19. package/dist/classes/shape.js +79 -110
  20. package/dist/classes/shape.js.map +1 -1
  21. package/dist/classes/slide-master-remover.js +108 -130
  22. package/dist/classes/slide-master-remover.js.map +1 -1
  23. package/dist/classes/slide-notes-copier.js +24 -41
  24. package/dist/classes/slide-notes-copier.js.map +1 -1
  25. package/dist/classes/slide.js +112 -141
  26. package/dist/classes/slide.js.map +1 -1
  27. package/dist/classes/template.js +82 -117
  28. package/dist/classes/template.js.map +1 -1
  29. package/dist/errors.js +5 -5
  30. package/dist/errors.js.map +1 -1
  31. package/dist/extensions/cli/index.js +3 -13
  32. package/dist/extensions/cli/index.js.map +1 -1
  33. package/dist/extensions/hide-slide/index.js +48 -46
  34. package/dist/extensions/hide-slide/index.js.map +1 -1
  35. package/dist/extensions/master-parts/index.js +36 -49
  36. package/dist/extensions/master-parts/index.js.map +1 -1
  37. package/dist/extensions/pptxgenjs-compat/svg-fallback.js +56 -70
  38. package/dist/extensions/pptxgenjs-compat/svg-fallback.js.map +1 -1
  39. package/dist/extensions/regexp-escape/index.d.ts +10 -0
  40. package/dist/extensions/regexp-escape/index.js +15 -0
  41. package/dist/extensions/regexp-escape/index.js.map +1 -0
  42. package/dist/extensions/run-merge/index.js +4 -5
  43. package/dist/extensions/run-merge/index.js.map +1 -1
  44. package/dist/extensions/shape-geometry/index.js +10 -10
  45. package/dist/extensions/shape-geometry/index.js.map +1 -1
  46. package/dist/extensions/template-lint/cli.js +49 -41
  47. package/dist/extensions/template-lint/cli.js.map +1 -1
  48. package/dist/extensions/template-lint/config.js +18 -10
  49. package/dist/extensions/template-lint/config.js.map +1 -1
  50. package/dist/extensions/template-lint/data-model.js +17 -20
  51. package/dist/extensions/template-lint/data-model.js.map +1 -1
  52. package/dist/extensions/template-lint/init-cli.js +12 -17
  53. package/dist/extensions/template-lint/init-cli.js.map +1 -1
  54. package/dist/extensions/template-lint/lint.js +83 -64
  55. package/dist/extensions/template-lint/lint.js.map +1 -1
  56. package/dist/extensions/template-lint/skeleton.js +5 -6
  57. package/dist/extensions/template-lint/skeleton.js.map +1 -1
  58. package/dist/extensions/template-lint/usage-cli.js +10 -14
  59. package/dist/extensions/template-lint/usage-cli.js.map +1 -1
  60. package/dist/extensions/template-lint/usage.js +8 -9
  61. package/dist/extensions/template-lint/usage.js.map +1 -1
  62. package/dist/extensions/template-logic/clone.d.ts +2 -16
  63. package/dist/extensions/template-logic/clone.js +15 -90
  64. package/dist/extensions/template-logic/clone.js.map +1 -1
  65. package/dist/extensions/template-logic/commands.js +6 -11
  66. package/dist/extensions/template-logic/commands.js.map +1 -1
  67. package/dist/extensions/template-logic/expression.js +29 -54
  68. package/dist/extensions/template-logic/expression.js.map +1 -1
  69. package/dist/extensions/template-logic/images.js +44 -51
  70. package/dist/extensions/template-logic/images.js.map +1 -1
  71. package/dist/extensions/template-logic/index.js +16 -24
  72. package/dist/extensions/template-logic/index.js.map +1 -1
  73. package/dist/extensions/template-logic/list-commands.js +8 -19
  74. package/dist/extensions/template-logic/list-commands.js.map +1 -1
  75. package/dist/extensions/template-logic/renderer.d.ts +8 -0
  76. package/dist/extensions/template-logic/renderer.js +466 -475
  77. package/dist/extensions/template-logic/renderer.js.map +1 -1
  78. package/dist/extensions/template-render/cli.js +7 -18
  79. package/dist/extensions/template-render/cli.js.map +1 -1
  80. package/dist/extensions/template-render/index.js +152 -107
  81. package/dist/extensions/template-render/index.js.map +1 -1
  82. package/dist/extensions/template-render/prune.d.ts +14 -0
  83. package/dist/extensions/template-render/prune.js +131 -0
  84. package/dist/extensions/template-render/prune.js.map +1 -0
  85. package/dist/extensions/template-render/zip-text.d.ts +9 -0
  86. package/dist/extensions/template-render/zip-text.js +27 -0
  87. package/dist/extensions/template-render/zip-text.js.map +1 -0
  88. package/dist/extensions/template-render/zip-writer.d.ts +16 -0
  89. package/dist/extensions/template-render/zip-writer.js +151 -0
  90. package/dist/extensions/template-render/zip-writer.js.map +1 -0
  91. package/dist/extensions/text-flow/flow.js +183 -207
  92. package/dist/extensions/text-flow/flow.js.map +1 -1
  93. package/dist/extensions/text-flow/font-file.js +9 -7
  94. package/dist/extensions/text-flow/font-file.js.map +1 -1
  95. package/dist/extensions/text-flow/fonts.d.ts +4 -0
  96. package/dist/extensions/text-flow/fonts.js +45 -22
  97. package/dist/extensions/text-flow/fonts.js.map +1 -1
  98. package/dist/extensions/text-flow/layout.js +5 -6
  99. package/dist/extensions/text-flow/layout.js.map +1 -1
  100. package/dist/extensions/text-flow/slide-styles.js +18 -22
  101. package/dist/extensions/text-flow/slide-styles.js.map +1 -1
  102. package/dist/extensions/text-flow/styles.d.ts +6 -0
  103. package/dist/extensions/text-flow/styles.js +108 -64
  104. package/dist/extensions/text-flow/styles.js.map +1 -1
  105. package/dist/helper/archive/archive-fs.js +102 -138
  106. package/dist/helper/archive/archive-fs.js.map +1 -1
  107. package/dist/helper/archive/archive-jszip.js +101 -125
  108. package/dist/helper/archive/archive-jszip.js.map +1 -1
  109. package/dist/helper/archive/archive.d.ts +6 -0
  110. package/dist/helper/archive/archive.js +21 -30
  111. package/dist/helper/archive/archive.js.map +1 -1
  112. package/dist/helper/archive/jszip-fast-read.d.ts +19 -0
  113. package/dist/helper/archive/jszip-fast-read.js +153 -0
  114. package/dist/helper/archive/jszip-fast-read.js.map +1 -0
  115. package/dist/helper/compute-src-rect.js +4 -5
  116. package/dist/helper/compute-src-rect.js.map +1 -1
  117. package/dist/helper/content-tracker.js +86 -114
  118. package/dist/helper/content-tracker.js.map +1 -1
  119. package/dist/helper/count-helper.js +48 -78
  120. package/dist/helper/count-helper.js.map +1 -1
  121. package/dist/helper/css-style-parser.js +1 -2
  122. package/dist/helper/css-style-parser.js.map +1 -1
  123. package/dist/helper/file-helper.js +30 -48
  124. package/dist/helper/file-helper.js.map +1 -1
  125. package/dist/helper/generate/generate-pptxgenjs.js +36 -48
  126. package/dist/helper/generate/generate-pptxgenjs.js.map +1 -1
  127. package/dist/helper/html-to-multitext-helper.js +34 -18
  128. package/dist/helper/html-to-multitext-helper.js.map +1 -1
  129. package/dist/helper/hyperlink-processor.js +125 -139
  130. package/dist/helper/hyperlink-processor.js.map +1 -1
  131. package/dist/helper/jszip-helper.js +23 -32
  132. package/dist/helper/jszip-helper.js.map +1 -1
  133. package/dist/helper/layout-index.js +51 -71
  134. package/dist/helper/layout-index.js.map +1 -1
  135. package/dist/helper/logger.js +4 -4
  136. package/dist/helper/logger.js.map +1 -1
  137. package/dist/helper/media-deduplicator.d.ts +24 -0
  138. package/dist/helper/media-deduplicator.js +81 -34
  139. package/dist/helper/media-deduplicator.js.map +1 -1
  140. package/dist/helper/modify-background-helper.js +46 -46
  141. package/dist/helper/modify-background-helper.js.map +1 -1
  142. package/dist/helper/modify-chart-helper.js +597 -591
  143. package/dist/helper/modify-chart-helper.js.map +1 -1
  144. package/dist/helper/modify-cleanup-helper.js +112 -112
  145. package/dist/helper/modify-cleanup-helper.js.map +1 -1
  146. package/dist/helper/modify-color-helper.js +53 -53
  147. package/dist/helper/modify-color-helper.js.map +1 -1
  148. package/dist/helper/modify-helper.js +25 -25
  149. package/dist/helper/modify-helper.js.map +1 -1
  150. package/dist/helper/modify-hyperlink-helper.js +143 -154
  151. package/dist/helper/modify-hyperlink-helper.js.map +1 -1
  152. package/dist/helper/modify-image-helper.js +121 -132
  153. package/dist/helper/modify-image-helper.js.map +1 -1
  154. package/dist/helper/modify-presentation-helper.js +137 -154
  155. package/dist/helper/modify-presentation-helper.js.map +1 -1
  156. package/dist/helper/modify-shape-helper.js +262 -262
  157. package/dist/helper/modify-shape-helper.js.map +1 -1
  158. package/dist/helper/modify-table-helper.js +84 -84
  159. package/dist/helper/modify-table-helper.js.map +1 -1
  160. package/dist/helper/modify-text-helper.js +187 -189
  161. package/dist/helper/modify-text-helper.js.map +1 -1
  162. package/dist/helper/modify-xml-helper.js +36 -36
  163. package/dist/helper/modify-xml-helper.js.map +1 -1
  164. package/dist/helper/multitext-helper.js +9 -7
  165. package/dist/helper/multitext-helper.js.map +1 -1
  166. package/dist/helper/ppt-paths.js +17 -17
  167. package/dist/helper/ppt-paths.js.map +1 -1
  168. package/dist/helper/shape-type-detector.js +18 -29
  169. package/dist/helper/shape-type-detector.js.map +1 -1
  170. package/dist/helper/text-replace-helper.js +6 -7
  171. package/dist/helper/text-replace-helper.js.map +1 -1
  172. package/dist/helper/xml-clone.d.ts +24 -0
  173. package/dist/helper/xml-clone.js +269 -0
  174. package/dist/helper/xml-clone.js.map +1 -0
  175. package/dist/helper/xml-elements.js +17 -20
  176. package/dist/helper/xml-elements.js.map +1 -1
  177. package/dist/helper/xml-find.d.ts +4 -0
  178. package/dist/helper/xml-find.js +48 -0
  179. package/dist/helper/xml-find.js.map +1 -0
  180. package/dist/helper/xml-helper.js +99 -134
  181. package/dist/helper/xml-helper.js.map +1 -1
  182. package/dist/helper/xml-parse-cache.d.ts +31 -0
  183. package/dist/helper/xml-parse-cache.js +71 -0
  184. package/dist/helper/xml-parse-cache.js.map +1 -0
  185. package/dist/helper/xml-placeholder-helper.js +10 -10
  186. package/dist/helper/xml-placeholder-helper.js.map +1 -1
  187. package/dist/helper/xml-relationship-helper.js +120 -144
  188. package/dist/helper/xml-relationship-helper.js.map +1 -1
  189. package/dist/helper/xml-serializer.d.ts +2 -0
  190. package/dist/helper/xml-serializer.js +192 -0
  191. package/dist/helper/xml-serializer.js.map +1 -0
  192. package/dist/helper/xml-slide-helper.js +109 -129
  193. package/dist/helper/xml-slide-helper.js.map +1 -1
  194. package/dist/helper/xml-template-helper.js +120 -144
  195. package/dist/helper/xml-template-helper.js.map +1 -1
  196. package/dist/helper/xmldom-sax-patch.js +52 -2
  197. package/dist/helper/xmldom-sax-patch.js.map +1 -1
  198. package/dist/index.js +4 -2
  199. package/dist/index.js.map +1 -1
  200. package/dist/modify/modify-chart.js +35 -23
  201. package/dist/modify/modify-chart.js.map +1 -1
  202. package/dist/modify/modify-table.js +11 -14
  203. package/dist/modify/modify-table.js.map +1 -1
  204. package/dist/shapes/chart.js +238 -287
  205. package/dist/shapes/chart.js.map +1 -1
  206. package/dist/shapes/diagram.js +73 -104
  207. package/dist/shapes/diagram.js.map +1 -1
  208. package/dist/shapes/generic.js +62 -83
  209. package/dist/shapes/generic.js.map +1 -1
  210. package/dist/shapes/hyperlink.js +98 -124
  211. package/dist/shapes/hyperlink.js.map +1 -1
  212. package/dist/shapes/image.js +112 -151
  213. package/dist/shapes/image.js.map +1 -1
  214. package/dist/shapes/ole.js +148 -188
  215. package/dist/shapes/ole.js.map +1 -1
  216. package/package.json +3 -4
package/AI-INSTRUCTOR.md CHANGED
@@ -1386,7 +1386,10 @@ as not shown. The second slide repeats as usual while projects are left.
1386
1386
  - `flow`, `flowRest`, `flowContinue`, `flowPage` and `flowPages` are built in. The same name
1387
1387
  in your data or in `additionalJsContext` takes precedence.
1388
1388
  - To count the slides, `renderDeck` and `countFlowPages` render the slide
1389
- once more. Functions in your data are called again then.
1389
+ once more. Functions in your data are called again then. Pictures of
1390
+ `{{IMAGE}}` are not loaded for the count, since they do not change where
1391
+ the text goes: a missing image file is reported when the slide itself is
1392
+ rendered, not by `countFlowPages`.
1390
1393
 
1391
1394
  ## Hide Slides
1392
1395
 
package/CHANGELOG.md CHANGED
@@ -6,6 +6,108 @@ semver, with the pre-1.0 convention that **breaking changes bump the minor**.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.4.0] - 2026-11-24
10
+
11
+ Generating is several times faster, with the same slides. Most of the
12
+ speed-ups are in code every `Automizer` run uses (reading, parsing and
13
+ writing parts, copying XML nodes, finding duplicate pictures), not only in
14
+ `renderDeck`. Compared with 0.3.9, the content of every part is the same;
15
+ the bytes of a `renderDeck` deck differ: parts it does not change are taken
16
+ over from the template as they are instead of parsed and written again,
17
+ pictures are stored instead of deflated (about 1 % larger), and parts no
18
+ relationship reaches are left out.
19
+
20
+ ### Changed
21
+
22
+ - **Behavior change:** `countFlowPages` loads no `{{IMAGE}}` picture. The
23
+ value is still evaluated, so an error in the expression is still
24
+ reported, but a missing file, a path outside `imageRoot`, an unknown
25
+ image format, `IMAGE` in a table cell or two `IMAGE` tags in one alt
26
+ text are reported only when the slide is rendered, not by
27
+ `countFlowPages`. `renderDeck` renders every slide it counts, so it
28
+ reports the same errors as before; an `errorHandler` gets them once
29
+ instead of twice on a `flow()` slide.
30
+ - `renderDeck` is more than twice as fast, with the same slides: a deck
31
+ of 8 template slides, three of them with `flow()` lists that make 2 to 4
32
+ slides each, takes about 0.1 instead of 0.23 seconds.
33
+ - `renderDeck` and `countFlowPages` count the slides a `flow()` slide
34
+ needs by rendering that slide by itself, instead of building a whole
35
+ deck for each such slide. The count is the same.
36
+ - The system font folders are listed once per process, not on every
37
+ render with `flow()` (on Windows a `stat` for each of hundreds of
38
+ fonts). Fonts installed while the process runs are found after a
39
+ restart. The `fonts` folders passed in the options are still listed on
40
+ every render, so font files added to them are found right away.
41
+ - `renderDeck` drops the parts no relationship reaches any more (the
42
+ template's own slides with their notes, charts, embeddings and
43
+ pictures) from the `.rels` parts, instead of parsing every slide once
44
+ more for Automizer's `cleanup`. A picture whose relationship the slide
45
+ does not use is still dropped.
46
+ - `renderDeck` packs the .pptx with Node's zlib instead of JSZip's
47
+ JavaScript deflate. Stored pictures stay stored, as PowerPoint saves
48
+ them, and so do the pictures `{{IMAGE}}` adds (JSZip deflated them for
49
+ about 1 % less).
50
+ - `renderDeck` loads the template once instead of three times (JSZip
51
+ reads the whole file byte by byte on every load).
52
+ - Identical pictures are found by comparing only pictures of the same
53
+ size: each run read and hashed every picture of the template before.
54
+ With 3 MB of pictures in the template, a deck takes 0.1 instead of
55
+ 0.5 seconds.
56
+ - `flow()` tokenizes a box once for all the entries it measures, and
57
+ neither its trial renders nor counting the slides load `{{IMAGE}}`
58
+ pictures.
59
+ - `renderDeck` is about 40 % faster again, with the same output byte for
60
+ byte. A deck of 25 template slides (360 text boxes with tags, 30
61
+ pictures of 0.5 MB, 10 `flow()` slides that make 35 slides) takes 0.28
62
+ instead of 0.5 seconds; the same deck with pptx-automizer 0.9.4 (tags
63
+ replaced with `replaceText`, pictures swapped, lists split by hand,
64
+ nothing measured) takes 1.3 to 1.9 seconds.
65
+ - The build targets ES2022 instead of ES6, so `async`/`await` runs
66
+ natively instead of through generators (Node 20 is required already).
67
+ - Parts are read without JSZip's pipeline where the result is the same:
68
+ parts of the template inflated with Node's zlib, parts written during
69
+ the run taken as they were given. JSZip inflated in JavaScript and
70
+ passed every 16 KB through a chain of workers. Parts above 1 MB are
71
+ inflated on Node's thread pool, so they do not block the event loop.
72
+ A part that inflates to more than its zip header says (a corrupt file
73
+ or a zip bomb) is rejected before it fills the memory; JSZip rejected
74
+ it only after inflating all of it.
75
+ - A part parsed before is copied instead of parsed again (a slide added
76
+ several times, the many identical `.rels` parts). A part parsed once
77
+ keeps only a checksum; the copies kept are limited to 4 million
78
+ characters of XML per archive (about 150 MB at most).
79
+ - XML is written by a serializer of its own, with the output of
80
+ xmldom's, about a third faster.
81
+ - Copying XML nodes is about three times as fast (properties copied by
82
+ name instead of by `Object.keys`), and so is finding elements by tag
83
+ name; the unsupported tags of a slide are found in one pass.
84
+ - xmldom checks each element and attribute name against a long Unicode
85
+ pattern; the result is now kept per name.
86
+ - The .pptx is deflated on Node's thread pool, several parts at a time.
87
+ - `flow()` looks up the list styles of a paragraph level once per box
88
+ instead of once per paragraph, and the font of a run once per box.
89
+ - The system fonts are read only when the `fonts` folders have no exact
90
+ match (same family, bold and italic) for a font the slide uses. Before,
91
+ the first render with `flow()` in a process read every system font.
92
+ - A picture `{{IMAGE}}` adds is hashed once instead of twice.
93
+ - `@xmldom/xmldom` is pinned to exactly 0.9.12 instead of `^0.9.12`. The
94
+ library's own XML serializer and node copy produce xmldom 0.9.12's
95
+ output; a newer xmldom comes with a release of this library once that
96
+ output is checked against it.
97
+
98
+ ### Fixed
99
+
100
+ - `renderDeck`: a `{{HIDE-SLIDE …}}` tag that spell check had split inside
101
+ the keyword (`{{HI` and `DE-SLIDE …}}` in two runs) stayed in the speaker
102
+ notes of a slide that is shown. The slide itself was hidden or shown
103
+ correctly.
104
+
105
+ ### Removed
106
+
107
+ - The dependency `regexp.escape`, which installed 91 packages. Tag
108
+ delimiters are escaped by a small function in the library instead, with
109
+ the same matches.
110
+
9
111
  ## [0.3.9] - 2026-11-22
10
112
 
11
113
  ### Added
@@ -395,7 +497,8 @@ for that history.
395
497
  into one `.png` part. The fallback now gets the same placeholder PNG that
396
498
  pptxgenjs 3.12 wrote.
397
499
 
398
- [Unreleased]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.9...HEAD
500
+ [Unreleased]: https://github.com/DaBorsten/pptx-templates/compare/v0.4.0...HEAD
501
+ [0.4.0]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.9...v0.4.0
399
502
  [0.3.9]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.8...v0.3.9
400
503
  [0.3.8]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.7...v0.3.8
401
504
  [0.3.7]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.6...v0.3.7
package/dist/automizer.js CHANGED
@@ -32,15 +32,6 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
45
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
46
37
  };
@@ -107,7 +98,6 @@ class Automizer {
107
98
  * @param [params]
108
99
  */
109
100
  constructor(params) {
110
- var _a, _b, _c, _d, _f, _g, _h;
111
101
  /**
112
102
  * Templates of automizer
113
103
  * @internal
@@ -120,21 +110,21 @@ class Automizer {
120
110
  */
121
111
  this.mastersToRemove = [];
122
112
  this.params = params;
123
- this.logger = (_a = params.logger) !== null && _a !== void 0 ? _a : new logger_1.ConsoleLogger((_b = params.verbosity) !== null && _b !== void 0 ? _b : 1);
124
- this.templateDir = (params === null || params === void 0 ? void 0 : params.templateDir) ? params.templateDir + '/' : '';
125
- this.templateFallbackDir = (params === null || params === void 0 ? void 0 : params.templateFallbackDir)
113
+ this.logger = params.logger ?? new logger_1.ConsoleLogger(params.verbosity ?? 1);
114
+ this.templateDir = params?.templateDir ? params.templateDir + '/' : '';
115
+ this.templateFallbackDir = params?.templateFallbackDir
126
116
  ? params.templateFallbackDir + '/'
127
117
  : '';
128
- this.outputDir = (params === null || params === void 0 ? void 0 : params.outputDir) ? params.outputDir + '/' : '';
118
+ this.outputDir = params?.outputDir ? params.outputDir + '/' : '';
129
119
  this.archiveParams = {
130
- mode: ((_c = params === null || params === void 0 ? void 0 : params.archiveType) === null || _c === void 0 ? void 0 : _c.mode) || 'jszip',
131
- baseDir: ((_d = params === null || params === void 0 ? void 0 : params.archiveType) === null || _d === void 0 ? void 0 : _d.baseDir) || __dirname + '/../cache',
132
- workDir: ((_f = params === null || params === void 0 ? void 0 : params.archiveType) === null || _f === void 0 ? void 0 : _f.workDir) || 'tmp',
133
- cleanupWorkDir: (_g = params === null || params === void 0 ? void 0 : params.archiveType) === null || _g === void 0 ? void 0 : _g.cleanupWorkDir,
134
- decodeText: (_h = params === null || params === void 0 ? void 0 : params.archiveType) === null || _h === void 0 ? void 0 : _h.decodeText,
120
+ mode: params?.archiveType?.mode || 'jszip',
121
+ baseDir: params?.archiveType?.baseDir || __dirname + '/../cache',
122
+ workDir: params?.archiveType?.workDir || 'tmp',
123
+ cleanupWorkDir: params?.archiveType?.cleanupWorkDir,
124
+ decodeText: params?.archiveType?.decodeText,
135
125
  };
136
126
  this.timer = Date.now();
137
- this.setStatusTracker(params === null || params === void 0 ? void 0 : params.statusTracker);
127
+ this.setStatusTracker(params?.statusTracker);
138
128
  this.content = new content_tracker_1.ContentTracker();
139
129
  if (params.rootTemplate) {
140
130
  let file = params.rootTemplate;
@@ -153,7 +143,10 @@ class Automizer {
153
143
  else {
154
144
  name = `${i}.pptx`;
155
145
  }
156
- const archiveParams = Object.assign(Object.assign({}, this.archiveParams), { name });
146
+ const archiveParams = {
147
+ ...this.archiveParams,
148
+ name,
149
+ };
157
150
  this.templates.push(new template_1.SourceTemplate(file, archiveParams));
158
151
  });
159
152
  }
@@ -183,14 +176,11 @@ class Automizer {
183
176
  /**
184
177
 
185
178
  */
186
- presentation() {
187
- return __awaiter(this, void 0, void 0, function* () {
188
- var _a;
189
- if (((_a = this.params) === null || _a === void 0 ? void 0 : _a.useCreationIds) === true) {
190
- yield this.setCreationIds();
191
- }
192
- return this;
193
- });
179
+ async presentation() {
180
+ if (this.params?.useCreationIds === true) {
181
+ await this.setCreationIds();
182
+ }
183
+ return this;
194
184
  }
195
185
  /**
196
186
  * Load a pptx file and set it as root template.
@@ -233,7 +223,10 @@ class Automizer {
233
223
  if (alreadyLoaded) {
234
224
  return this;
235
225
  }
236
- const importParams = Object.assign(Object.assign({}, this.archiveParams), { name });
226
+ const importParams = {
227
+ ...this.archiveParams,
228
+ name,
229
+ };
237
230
  const newTemplate = template_1.Template.import(file, importParams, this);
238
231
  if (newTemplate instanceof template_1.SourceTemplate) {
239
232
  this.templates.push(newTemplate);
@@ -316,50 +309,45 @@ class Automizer {
316
309
  * of slide number and element name.
317
310
  * @returns Promise<TemplateInfo[]>
318
311
  */
319
- setCreationIds() {
320
- return __awaiter(this, void 0, void 0, function* () {
321
- return (0, logger_1.runWithLogger)(this.logger, () => __awaiter(this, void 0, void 0, function* () {
322
- const templateCreationId = [];
323
- for (const template of this.templates) {
324
- const creationIds = template.creationIds || (yield template.setCreationIds());
325
- template.useCreationIds = this.params.useCreationIds;
326
- templateCreationId.push({
327
- name: template.name,
328
- slides: creationIds,
329
- });
330
- }
331
- return templateCreationId;
332
- }));
312
+ async setCreationIds() {
313
+ return (0, logger_1.runWithLogger)(this.logger, async () => {
314
+ const templateCreationId = [];
315
+ for (const template of this.templates) {
316
+ const creationIds = template.creationIds || (await template.setCreationIds());
317
+ template.useCreationIds = this.params.useCreationIds;
318
+ templateCreationId.push({
319
+ name: template.name,
320
+ slides: creationIds,
321
+ });
322
+ }
323
+ return templateCreationId;
333
324
  });
334
325
  }
335
326
  /**
336
327
  * Get some info about the imported templates
337
328
  * @returns Promise<PresentationInfo>
338
329
  */
339
- getInfo() {
340
- return __awaiter(this, void 0, void 0, function* () {
341
- const creationIds = yield this.setCreationIds();
342
- const info = {
343
- templateByName: (tplName) => {
344
- return creationIds.find((template) => template.name === tplName);
345
- },
346
- slidesByTemplate: (tplName) => {
347
- var _a;
348
- return ((_a = info.templateByName(tplName)) === null || _a === void 0 ? void 0 : _a.slides) || [];
349
- },
350
- slideByNumber: (tplName, slideNumber) => {
351
- return info
352
- .slidesByTemplate(tplName)
353
- .find((slide) => slide.number === slideNumber);
354
- },
355
- elementByName: (tplName, slideNumber, elementName) => {
356
- var _a;
357
- return (_a = info
358
- .slideByNumber(tplName, slideNumber)) === null || _a === void 0 ? void 0 : _a.elements.find((element) => elementName === element.name);
359
- },
360
- };
361
- return info;
362
- });
330
+ async getInfo() {
331
+ const creationIds = await this.setCreationIds();
332
+ const info = {
333
+ templateByName: (tplName) => {
334
+ return creationIds.find((template) => template.name === tplName);
335
+ },
336
+ slidesByTemplate: (tplName) => {
337
+ return info.templateByName(tplName)?.slides || [];
338
+ },
339
+ slideByNumber: (tplName, slideNumber) => {
340
+ return info
341
+ .slidesByTemplate(tplName)
342
+ .find((slide) => slide.number === slideNumber);
343
+ },
344
+ elementByName: (tplName, slideNumber, elementName) => {
345
+ return info
346
+ .slideByNumber(tplName, slideNumber)
347
+ ?.elements.find((element) => elementName === element.name);
348
+ },
349
+ };
350
+ return info;
363
351
  }
364
352
  /**
365
353
  * Add a slide from one of the imported templates by slide number or creationId.
@@ -510,24 +498,22 @@ class Automizer {
510
498
  * @param location - Filename or path for the file. Will be prefixed with 'outputDir'
511
499
  * @returns summary object.
512
500
  */
513
- write(location) {
514
- return __awaiter(this, void 0, void 0, function* () {
515
- return (0, logger_1.runWithLogger)(this.logger, () => __awaiter(this, void 0, void 0, function* () {
516
- yield this.finalizePresentation();
517
- yield this.rootTemplate.archive.output(this.getLocation(location, 'output'), this.params);
518
- const duration = (Date.now() - this.timer) / 1000;
519
- return {
520
- status: 'finished',
521
- duration,
522
- file: location,
523
- filename: path_1.default.basename(location),
524
- templates: this.templates.length,
525
- slides: this.rootTemplate.count('slides'),
526
- charts: this.rootTemplate.count('charts'),
527
- images: this.rootTemplate.count('images'),
528
- masters: this.rootTemplate.count('masters'),
529
- };
530
- }));
501
+ async write(location) {
502
+ return (0, logger_1.runWithLogger)(this.logger, async () => {
503
+ await this.finalizePresentation();
504
+ await this.rootTemplate.archive.output(this.getLocation(location, 'output'), this.params);
505
+ const duration = (Date.now() - this.timer) / 1000;
506
+ return {
507
+ status: 'finished',
508
+ duration,
509
+ file: location,
510
+ filename: path_1.default.basename(location),
511
+ templates: this.templates.length,
512
+ slides: this.rootTemplate.count('slides'),
513
+ charts: this.rootTemplate.count('charts'),
514
+ images: this.rootTemplate.count('images'),
515
+ masters: this.rootTemplate.count('masters'),
516
+ };
531
517
  });
532
518
  }
533
519
  /**
@@ -535,118 +521,101 @@ class Automizer {
535
521
  * @param generatorOptions - JSZipGeneratorOptions for nodebuffer Output type
536
522
  * @returns Promise<NodeJS.ReadableStream>
537
523
  */
538
- stream(generatorOptions) {
539
- return __awaiter(this, void 0, void 0, function* () {
540
- return (0, logger_1.runWithLogger)(this.logger, () => __awaiter(this, void 0, void 0, function* () {
541
- yield this.finalizePresentation();
542
- if (!this.rootTemplate.archive.stream) {
543
- throw new errors_1.OutputError('Streaming is not implemented for current archive type');
544
- }
545
- return this.rootTemplate.archive.stream(this.params, generatorOptions);
546
- }));
524
+ async stream(generatorOptions) {
525
+ return (0, logger_1.runWithLogger)(this.logger, async () => {
526
+ await this.finalizePresentation();
527
+ if (!this.rootTemplate.archive.stream) {
528
+ throw new errors_1.OutputError('Streaming is not implemented for current archive type');
529
+ }
530
+ return this.rootTemplate.archive.stream(this.params, generatorOptions);
547
531
  });
548
532
  }
549
533
  /**
550
534
  * Pass final JSZip instance.
551
535
  * @returns Promise<NodeJS.ReadableStream>
552
536
  */
553
- getJSZip() {
554
- return __awaiter(this, void 0, void 0, function* () {
555
- return (0, logger_1.runWithLogger)(this.logger, () => __awaiter(this, void 0, void 0, function* () {
556
- yield this.finalizePresentation();
557
- if (!this.rootTemplate.archive.getFinalArchive) {
558
- throw new errors_1.OutputError('GetFinalArchive is not implemented for current archive type');
559
- }
560
- return this.rootTemplate.archive.getFinalArchive();
561
- }));
537
+ async getJSZip() {
538
+ return (0, logger_1.runWithLogger)(this.logger, async () => {
539
+ await this.finalizePresentation();
540
+ if (!this.rootTemplate.archive.getFinalArchive) {
541
+ throw new errors_1.OutputError('GetFinalArchive is not implemented for current archive type');
542
+ }
543
+ return this.rootTemplate.archive.getFinalArchive();
562
544
  });
563
545
  }
564
- finalizePresentation() {
565
- return __awaiter(this, void 0, void 0, function* () {
566
- return (0, logger_1.runWithLogger)(this.logger, () => __awaiter(this, void 0, void 0, function* () {
567
- yield this.writeMasterSlides();
568
- yield this.writeSlides();
569
- yield this.removeSlideMasters();
570
- yield this.writeMediaFiles();
571
- yield this.normalizePresentation();
572
- yield this.applyModifyPresentationCallbacks();
573
- this.content.reset();
574
- }));
546
+ async finalizePresentation() {
547
+ return (0, logger_1.runWithLogger)(this.logger, async () => {
548
+ await this.writeMasterSlides();
549
+ await this.writeSlides();
550
+ await this.removeSlideMasters();
551
+ await this.writeMediaFiles();
552
+ await this.normalizePresentation();
553
+ await this.applyModifyPresentationCallbacks();
554
+ this.content.reset();
575
555
  });
576
556
  }
577
557
  /**
578
558
  * Write all masterSlides to archive.
579
559
  */
580
- writeMasterSlides() {
581
- return __awaiter(this, void 0, void 0, function* () {
582
- var _a;
583
- for (const slide of this.rootTemplate.masters) {
584
- yield this.rootTemplate.appendMasterSlide(slide);
585
- }
586
- for (const layout of (_a = this.rootTemplate.layouts) !== null && _a !== void 0 ? _a : []) {
587
- yield this.rootTemplate.appendLayout(layout);
588
- }
589
- });
560
+ async writeMasterSlides() {
561
+ for (const slide of this.rootTemplate.masters) {
562
+ await this.rootTemplate.appendMasterSlide(slide);
563
+ }
564
+ for (const layout of this.rootTemplate.layouts ?? []) {
565
+ await this.rootTemplate.appendLayout(layout);
566
+ }
590
567
  }
591
568
  /**
592
569
  * Remove the masters queued by `removeMaster()`. Runs after the slides
593
570
  * are written, so layout switches have been applied when the "still in
594
571
  * use" check runs.
595
572
  */
596
- removeSlideMasters() {
597
- return __awaiter(this, void 0, void 0, function* () {
598
- if (!this.mastersToRemove.length) {
599
- return;
600
- }
601
- const remover = new slide_master_remover_1.SlideMasterRemover(this.rootTemplate);
602
- for (const masterNumber of this.mastersToRemove) {
603
- yield remover.remove(masterNumber);
604
- }
605
- });
573
+ async removeSlideMasters() {
574
+ if (!this.mastersToRemove.length) {
575
+ return;
576
+ }
577
+ const remover = new slide_master_remover_1.SlideMasterRemover(this.rootTemplate);
578
+ for (const masterNumber of this.mastersToRemove) {
579
+ await remover.remove(masterNumber);
580
+ }
606
581
  }
607
582
  /**
608
583
  * Write all slides to archive.
609
584
  */
610
- writeSlides() {
611
- return __awaiter(this, void 0, void 0, function* () {
612
- yield this.rootTemplate.countExistingSlides();
613
- this.status.max = this.rootTemplate.slides.length;
614
- yield this.rootTemplate.runExternalGenerator();
615
- for (const slide of this.rootTemplate.slides) {
616
- yield this.rootTemplate.appendSlide(slide);
617
- }
618
- yield this.rootTemplate.cleanupExternalGenerator();
619
- if (this.params.removeExistingSlides) {
620
- yield this.rootTemplate.truncate();
621
- }
622
- });
585
+ async writeSlides() {
586
+ await this.rootTemplate.countExistingSlides();
587
+ this.status.max = this.rootTemplate.slides.length;
588
+ await this.rootTemplate.runExternalGenerator();
589
+ for (const slide of this.rootTemplate.slides) {
590
+ await this.rootTemplate.appendSlide(slide);
591
+ }
592
+ await this.rootTemplate.cleanupExternalGenerator();
593
+ if (this.params.removeExistingSlides) {
594
+ await this.rootTemplate.truncate();
595
+ }
623
596
  }
624
597
  /**
625
598
  * Write all media files to archive.
626
599
  */
627
- writeMediaFiles() {
628
- return __awaiter(this, void 0, void 0, function* () {
629
- const mediaDir = 'ppt/media/';
630
- for (const file of this.rootTemplate.mediaFiles) {
631
- const data = (0, types_1.getMediaBuffer)(file, fs.readFileSync);
632
- let archiveFilename = file.file;
633
- if (file.prefix) {
634
- archiveFilename = file.prefix + file.file;
635
- }
636
- archiveFilename = (0, slugify_1.default)(archiveFilename);
637
- yield this.rootTemplate.archive.write(mediaDir + archiveFilename, data);
638
- yield xml_helper_1.XmlHelper.appendImageExtensionToContentType(this.rootTemplate.archive, file.extension);
600
+ async writeMediaFiles() {
601
+ const mediaDir = 'ppt/media/';
602
+ for (const file of this.rootTemplate.mediaFiles) {
603
+ const data = (0, types_1.getMediaBuffer)(file, fs.readFileSync);
604
+ let archiveFilename = file.file;
605
+ if (file.prefix) {
606
+ archiveFilename = file.prefix + file.file;
639
607
  }
640
- });
608
+ archiveFilename = (0, slugify_1.default)(archiveFilename);
609
+ await this.rootTemplate.archive.write(mediaDir + archiveFilename, data);
610
+ await xml_helper_1.XmlHelper.appendImageExtensionToContentType(this.rootTemplate.archive, file.extension);
611
+ }
641
612
  }
642
613
  /**
643
614
  * Applies all callbacks in this.modifyPresentation-array.
644
615
  * The callback array can be pushed by this.modify()
645
616
  */
646
- applyModifyPresentationCallbacks() {
647
- return __awaiter(this, void 0, void 0, function* () {
648
- yield xml_helper_1.XmlHelper.modifyXmlInArchive(this.rootTemplate.archive, `ppt/presentation.xml`, this.modifyPresentation);
649
- });
617
+ async applyModifyPresentationCallbacks() {
618
+ await xml_helper_1.XmlHelper.modifyXmlInArchive(this.rootTemplate.archive, `ppt/presentation.xml`, this.modifyPresentation);
650
619
  }
651
620
  /**
652
621
  * Apply some callbacks to restore archive/xml structure
@@ -655,18 +624,16 @@ class Automizer {
655
624
  * TODO: Use every imported image only once
656
625
  * TODO: Check for lost relations
657
626
  */
658
- normalizePresentation() {
659
- return __awaiter(this, void 0, void 0, function* () {
660
- this.modify(modify_presentation_helper_1.default.normalizeSlideIds);
661
- this.modify(modify_presentation_helper_1.default.normalizeSlideMasterIds);
662
- if (this.params.cleanup) {
663
- if (this.params.removeExistingSlides) {
664
- this.modify(modify_presentation_helper_1.default.removeUnusedFiles);
665
- }
666
- this.modify(modify_presentation_helper_1.default.removedUnusedImages);
667
- this.modify(modify_presentation_helper_1.default.removeUnusedContentTypes);
627
+ async normalizePresentation() {
628
+ this.modify(modify_presentation_helper_1.default.normalizeSlideIds);
629
+ this.modify(modify_presentation_helper_1.default.normalizeSlideMasterIds);
630
+ if (this.params.cleanup) {
631
+ if (this.params.removeExistingSlides) {
632
+ this.modify(modify_presentation_helper_1.default.removeUnusedFiles);
668
633
  }
669
- });
634
+ this.modify(modify_presentation_helper_1.default.removedUnusedImages);
635
+ this.modify(modify_presentation_helper_1.default.removeUnusedContentTypes);
636
+ }
670
637
  }
671
638
  modify(cb) {
672
639
  this.modifyPresentation.push(cb);