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.
- package/AI-INSTRUCTOR.md +4 -1
- package/CHANGELOG.md +104 -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.js +10 -10
- 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 +83 -64
- package/dist/extensions/template-lint/lint.js.map +1 -1
- package/dist/extensions/template-lint/skeleton.js +5 -6
- package/dist/extensions/template-lint/skeleton.js.map +1 -1
- package/dist/extensions/template-lint/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.js +6 -11
- package/dist/extensions/template-logic/commands.js.map +1 -1
- package/dist/extensions/template-logic/expression.js +29 -54
- package/dist/extensions/template-logic/expression.js.map +1 -1
- package/dist/extensions/template-logic/images.js +44 -51
- package/dist/extensions/template-logic/images.js.map +1 -1
- package/dist/extensions/template-logic/index.js +16 -24
- package/dist/extensions/template-logic/index.js.map +1 -1
- package/dist/extensions/template-logic/list-commands.js +8 -19
- package/dist/extensions/template-logic/list-commands.js.map +1 -1
- package/dist/extensions/template-logic/renderer.d.ts +8 -0
- package/dist/extensions/template-logic/renderer.js +466 -475
- package/dist/extensions/template-logic/renderer.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.js +183 -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 +6 -0
- package/dist/extensions/text-flow/styles.js +108 -64
- package/dist/extensions/text-flow/styles.js.map +1 -1
- package/dist/helper/archive/archive-fs.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
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.
|
|
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 =
|
|
124
|
-
this.templateDir =
|
|
125
|
-
this.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 =
|
|
118
|
+
this.outputDir = params?.outputDir ? params.outputDir + '/' : '';
|
|
129
119
|
this.archiveParams = {
|
|
130
|
-
mode:
|
|
131
|
-
baseDir:
|
|
132
|
-
workDir:
|
|
133
|
-
cleanupWorkDir:
|
|
134
|
-
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
|
|
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 =
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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 =
|
|
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
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
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
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
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
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
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
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
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
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
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
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
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
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
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
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
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
|
-
|
|
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
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
if (this.params.
|
|
663
|
-
|
|
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);
|