pptx-templates 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AI-INSTRUCTOR.md +42 -2
- package/CHANGELOG.md +133 -1
- package/README.md +61 -168
- package/dist/automizer.d.ts +7 -0
- package/dist/automizer.js +32 -7
- package/dist/automizer.js.map +1 -1
- package/dist/classes/content-type-registry.js.map +1 -1
- package/dist/classes/element-importer.js +5 -4
- package/dist/classes/element-importer.js.map +1 -1
- package/dist/classes/has-shapes.js.map +1 -1
- package/dist/classes/layout.js.map +1 -1
- package/dist/classes/master.js.map +1 -1
- package/dist/classes/placeholder-normalizer.js.map +1 -1
- package/dist/classes/related-content-copier.js.map +1 -1
- package/dist/classes/shape.js.map +1 -1
- package/dist/classes/slide-master-remover.js.map +1 -1
- package/dist/classes/slide-notes-copier.js.map +1 -1
- package/dist/classes/slide.js.map +1 -1
- package/dist/classes/template.js.map +1 -1
- package/dist/constants/constants.js.map +1 -1
- package/dist/enums/chart-type.js.map +1 -1
- package/dist/enums/content-type-map.js.map +1 -1
- package/dist/enums/element-type.js.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/extensions/cli/index.js.map +1 -1
- package/dist/extensions/hide-slide/index.js.map +1 -1
- package/dist/extensions/index.d.ts +13 -3
- package/dist/extensions/index.js +3 -1
- package/dist/extensions/index.js.map +1 -1
- package/dist/extensions/link-scheme/index.d.ts +12 -0
- package/dist/extensions/link-scheme/index.js +40 -0
- package/dist/extensions/link-scheme/index.js.map +1 -0
- package/dist/extensions/master-parts/index.js.map +1 -1
- package/dist/extensions/pptxgenjs-compat/img-broken-png.js.map +1 -1
- package/dist/extensions/pptxgenjs-compat/index.js.map +1 -1
- package/dist/extensions/pptxgenjs-compat/svg-fallback.js.map +1 -1
- package/dist/extensions/regexp-escape/index.js.map +1 -1
- package/dist/extensions/run-merge/index.js.map +1 -1
- package/dist/extensions/shape-geometry/index.js +23 -1
- package/dist/extensions/shape-geometry/index.js.map +1 -1
- package/dist/extensions/shape-geometry/presets.d.ts +1 -1
- package/dist/extensions/shape-geometry/presets.js.map +1 -1
- package/dist/extensions/shape-geometry/types.js.map +1 -1
- package/dist/extensions/template-lint/cli.js +22 -8
- package/dist/extensions/template-lint/cli.js.map +1 -1
- package/dist/extensions/template-lint/config.js +12 -4
- package/dist/extensions/template-lint/config.js.map +1 -1
- package/dist/extensions/template-lint/data-model.js.map +1 -1
- package/dist/extensions/template-lint/hints.js.map +1 -1
- package/dist/extensions/template-lint/index.js.map +1 -1
- package/dist/extensions/template-lint/init-cli.d.ts +2 -0
- package/dist/extensions/template-lint/init-cli.js +21 -6
- package/dist/extensions/template-lint/init-cli.js.map +1 -1
- package/dist/extensions/template-lint/lint.d.ts +1 -1
- package/dist/extensions/template-lint/lint.js.map +1 -1
- package/dist/extensions/template-lint/skeleton.js.map +1 -1
- package/dist/extensions/template-lint/types.js.map +1 -1
- package/dist/extensions/template-lint/usage-cli.js +7 -4
- package/dist/extensions/template-lint/usage-cli.js.map +1 -1
- package/dist/extensions/template-lint/usage.js.map +1 -1
- package/dist/extensions/template-lint/watch.d.ts +2 -0
- package/dist/extensions/template-lint/watch.js +52 -7
- package/dist/extensions/template-lint/watch.js.map +1 -1
- package/dist/extensions/template-logic/clone.js.map +1 -1
- package/dist/extensions/template-logic/commands.d.ts +1 -1
- package/dist/extensions/template-logic/commands.js +7 -1
- package/dist/extensions/template-logic/commands.js.map +1 -1
- package/dist/extensions/template-logic/expression.d.ts +15 -2
- package/dist/extensions/template-logic/expression.js +114 -9
- package/dist/extensions/template-logic/expression.js.map +1 -1
- package/dist/extensions/template-logic/images.js +15 -5
- package/dist/extensions/template-logic/images.js.map +1 -1
- package/dist/extensions/template-logic/index.js.map +1 -1
- package/dist/extensions/template-logic/list-commands.js.map +1 -1
- package/dist/extensions/template-logic/renderer.d.ts +1 -0
- package/dist/extensions/template-logic/renderer.js +16 -4
- package/dist/extensions/template-logic/renderer.js.map +1 -1
- package/dist/extensions/template-logic/types.d.ts +8 -1
- package/dist/extensions/template-logic/types.js.map +1 -1
- package/dist/extensions/template-render/cli.js +27 -4
- package/dist/extensions/template-render/cli.js.map +1 -1
- package/dist/extensions/template-render/index.js.map +1 -1
- package/dist/extensions/template-render/prune.js.map +1 -1
- package/dist/extensions/template-render/zip-text.js.map +1 -1
- package/dist/extensions/template-render/zip-writer.js.map +1 -1
- package/dist/extensions/text-flow/flow.js.map +1 -1
- package/dist/extensions/text-flow/font-file.d.ts +9 -0
- package/dist/extensions/text-flow/font-file.js +32 -16
- package/dist/extensions/text-flow/font-file.js.map +1 -1
- package/dist/extensions/text-flow/fonts.js +24 -3
- package/dist/extensions/text-flow/fonts.js.map +1 -1
- package/dist/extensions/text-flow/index.js.map +1 -1
- package/dist/extensions/text-flow/layout.js +3 -3
- package/dist/extensions/text-flow/layout.js.map +1 -1
- package/dist/extensions/text-flow/slide-styles.js.map +1 -1
- package/dist/extensions/text-flow/styles.d.ts +1 -1
- package/dist/extensions/text-flow/styles.js.map +1 -1
- package/dist/helper/archive/archive-fs.d.ts +11 -0
- package/dist/helper/archive/archive-fs.js +96 -7
- package/dist/helper/archive/archive-fs.js.map +1 -1
- package/dist/helper/archive/archive-jszip.js.map +1 -1
- package/dist/helper/archive/archive.js.map +1 -1
- package/dist/helper/archive/jszip-fast-read.d.ts +9 -2
- package/dist/helper/archive/jszip-fast-read.js +14 -1
- package/dist/helper/archive/jszip-fast-read.js.map +1 -1
- package/dist/helper/cell-id-helper.d.ts +1 -0
- package/dist/helper/cell-id-helper.js +6 -2
- package/dist/helper/cell-id-helper.js.map +1 -1
- package/dist/helper/compute-src-rect.js.map +1 -1
- package/dist/helper/content-tracker.js.map +1 -1
- package/dist/helper/count-helper.js.map +1 -1
- package/dist/helper/css-style-parser.d.ts +1 -1
- package/dist/helper/css-style-parser.js.map +1 -1
- package/dist/helper/file-helper.js.map +1 -1
- package/dist/helper/general-helper.js.map +1 -1
- package/dist/helper/generate/generate-pptxgenjs.js.map +1 -1
- package/dist/helper/html-to-multitext-helper.d.ts +4 -4
- package/dist/helper/html-to-multitext-helper.js +12 -5
- package/dist/helper/html-to-multitext-helper.js.map +1 -1
- package/dist/helper/hyperlink-processor.js.map +1 -1
- package/dist/helper/image-dimensions.js.map +1 -1
- package/dist/helper/jszip-helper.d.ts +1 -1
- package/dist/helper/jszip-helper.js +18 -2
- package/dist/helper/jszip-helper.js.map +1 -1
- package/dist/helper/layout-index.js.map +1 -1
- package/dist/helper/logger.js.map +1 -1
- package/dist/helper/media-deduplicator.js.map +1 -1
- package/dist/helper/modify-background-helper.js.map +1 -1
- package/dist/helper/modify-chart-helper.d.ts +1 -1
- package/dist/helper/modify-chart-helper.js.map +1 -1
- package/dist/helper/modify-cleanup-helper.js +4 -4
- package/dist/helper/modify-cleanup-helper.js.map +1 -1
- package/dist/helper/modify-color-helper.d.ts +1 -1
- package/dist/helper/modify-color-helper.js.map +1 -1
- package/dist/helper/modify-helper.js.map +1 -1
- package/dist/helper/modify-hyperlink-element.js.map +1 -1
- package/dist/helper/modify-hyperlink-helper.js +9 -4
- package/dist/helper/modify-hyperlink-helper.js.map +1 -1
- package/dist/helper/modify-image-helper.d.ts +1 -1
- package/dist/helper/modify-image-helper.js.map +1 -1
- package/dist/helper/modify-presentation-helper.js.map +1 -1
- package/dist/helper/modify-shape-helper.js.map +1 -1
- package/dist/helper/modify-table-helper.js +12 -1
- package/dist/helper/modify-table-helper.js.map +1 -1
- package/dist/helper/modify-text-helper.d.ts +8 -0
- package/dist/helper/modify-text-helper.js +20 -6
- package/dist/helper/modify-text-helper.js.map +1 -1
- package/dist/helper/modify-xml-helper.js.map +1 -1
- package/dist/helper/multitext-helper.js +4 -2
- package/dist/helper/multitext-helper.js.map +1 -1
- package/dist/helper/ppt-paths.js.map +1 -1
- package/dist/helper/shape-type-detector.js.map +1 -1
- package/dist/helper/text-replace-helper.js +2 -1
- package/dist/helper/text-replace-helper.js.map +1 -1
- package/dist/helper/xml/lnLRTB.js.map +1 -1
- package/dist/helper/xml/prstGeom.js.map +1 -1
- package/dist/helper/xml-clone.js.map +1 -1
- package/dist/helper/xml-elements.js.map +1 -1
- package/dist/helper/xml-find.js.map +1 -1
- package/dist/helper/xml-helper.js +3 -1
- package/dist/helper/xml-helper.js.map +1 -1
- package/dist/helper/xml-parse-cache.js.map +1 -1
- package/dist/helper/xml-placeholder-helper.js.map +1 -1
- package/dist/helper/xml-pretty-print.js.map +1 -1
- package/dist/helper/xml-relationship-helper.js +13 -4
- package/dist/helper/xml-relationship-helper.js.map +1 -1
- package/dist/helper/xml-serializer.js.map +1 -1
- package/dist/helper/xml-slide-helper.js.map +1 -1
- package/dist/helper/xml-template-helper.js.map +1 -1
- package/dist/helper/xmldom-sax-patch.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js.map +1 -1
- package/dist/interfaces/iarchive.js.map +1 -1
- package/dist/interfaces/ichart.js.map +1 -1
- package/dist/interfaces/icounter.js.map +1 -1
- package/dist/interfaces/igenerator.js.map +1 -1
- package/dist/interfaces/iimage.js.map +1 -1
- package/dist/interfaces/ilayout.js.map +1 -1
- package/dist/interfaces/imaster.js.map +1 -1
- package/dist/interfaces/imulti-text.js.map +1 -1
- package/dist/interfaces/ipptxgenjs-slide.js.map +1 -1
- package/dist/interfaces/ipresentation-props.js.map +1 -1
- package/dist/interfaces/ishape-action.js.map +1 -1
- package/dist/interfaces/ishape.js.map +1 -1
- package/dist/interfaces/islide.js.map +1 -1
- package/dist/interfaces/itemplate.js.map +1 -1
- package/dist/interfaces/pres-template.js.map +1 -1
- package/dist/interfaces/root-pres-template.js.map +1 -1
- package/dist/modify/modify-chart.d.ts +4 -4
- package/dist/modify/modify-chart.js.map +1 -1
- package/dist/modify/modify-table.d.ts +0 -1
- package/dist/modify/modify-table.js +10 -15
- package/dist/modify/modify-table.js.map +1 -1
- package/dist/shapes/chart.js.map +1 -1
- package/dist/shapes/diagram.d.ts +14 -0
- package/dist/shapes/diagram.js +100 -5
- package/dist/shapes/diagram.js.map +1 -1
- package/dist/shapes/generic.js.map +1 -1
- package/dist/shapes/hyperlink.d.ts +0 -1
- package/dist/shapes/hyperlink.js +0 -14
- package/dist/shapes/hyperlink.js.map +1 -1
- package/dist/shapes/image.js +10 -2
- package/dist/shapes/image.js.map +1 -1
- package/dist/shapes/ole.js.map +1 -1
- package/dist/types/chart-types.js.map +1 -1
- package/dist/types/modify-types.js.map +1 -1
- package/dist/types/shape-types.js.map +1 -1
- package/dist/types/table-types.js.map +1 -1
- package/dist/types/types.d.ts +7 -0
- package/dist/types/types.js.map +1 -1
- package/dist/types/xml-types.js.map +1 -1
- package/dist/vendor/pptxgenjs/README.md +8 -3
- package/dist/vendor/pptxgenjs/index.js +19 -2
- package/package.json +11 -13
package/AI-INSTRUCTOR.md
CHANGED
|
@@ -947,13 +947,31 @@ are rejected as well:
|
|
|
947
947
|
(also permitted by `allowStringPatterns`).
|
|
948
948
|
- `repeat`, `padStart` and `padEnd` for more than 1,000,000 characters.
|
|
949
949
|
|
|
950
|
+
These checks also apply when such a method is passed on as a callback
|
|
951
|
+
(`list.map(''.match, text)`).
|
|
952
|
+
|
|
953
|
+
Reflection is refused as well: `Object.getPrototypeOf`,
|
|
954
|
+
`Object.setPrototypeOf`, `Object.getOwnPropertyDescriptor(s)`,
|
|
955
|
+
`Object.defineProperty`/`defineProperties` and every `Reflect` method, even
|
|
956
|
+
if you pass `Object` or `Reflect` in. Other `Object` helpers (`keys`,
|
|
957
|
+
`values`, `entries`, `fromEntries`) work.
|
|
958
|
+
|
|
959
|
+
Each evaluation of one expression has a budget: at most 1,000,000 steps
|
|
960
|
+
(arrow function bodies included) and at most 20,000,000 characters or list
|
|
961
|
+
items in the strings and lists it produces. One renderer runs at most
|
|
962
|
+
200,000 `FOR` iterations in total, nested loops included. Going past a limit
|
|
963
|
+
is a render error.
|
|
964
|
+
|
|
950
965
|
#### Templates you did not write
|
|
951
966
|
|
|
952
967
|
The interpreter keeps a template away from Node.js, not away from your data.
|
|
953
968
|
A template can call every method of every value you pass in, so
|
|
954
969
|
`{{items.pop()}}` changes your array and `{{user.delete()}}` calls your
|
|
955
|
-
method.
|
|
956
|
-
|
|
970
|
+
method. renderDeck and `flow()` evaluate a tag more than once, so such a
|
|
971
|
+
change can happen several times. Sort a copy with `toSorted` instead of
|
|
972
|
+
`sort`. The limits above bound the work per expression and per renderer,
|
|
973
|
+
but not the total time of a large deck. For templates from people you do
|
|
974
|
+
not trust:
|
|
957
975
|
|
|
958
976
|
- Pass plain data (JSON-like copies), not model instances, database handles
|
|
959
977
|
or libraries such as lodash.
|
|
@@ -1011,6 +1029,7 @@ pres.addSlide('TextReplace.pptx', 1, (slide) => {
|
|
|
1011
1029
|
| `additionalJsContext` | | Extra helpers and constants. `data` takes precedence |
|
|
1012
1030
|
| `strict` | `false` | Throw on unknown top-level names instead of treating them as `undefined` |
|
|
1013
1031
|
| `allowStringPatterns` | `false` | Let `match`, `matchAll` and `search` take a string pattern (`name.match('^A')`). Only for templates you trust: a crafted pattern can block the process |
|
|
1032
|
+
| `allowedLinkSchemes` | | Schemes `{{LINK}}` and `<a href>` in `{{HTML}}` may use besides `http`, `https`, `mailto` and `tel`, e.g. `['file']`. See [allowed link schemes](https://daborsten.github.io/pptx-templates/hyperlinks.md#allowed-link-schemes) |
|
|
1014
1033
|
| `rejectNullish` | `false` | Throw when an insertion is `null` or `undefined` |
|
|
1015
1034
|
| `errorHandler(error, command)` | | Called when a command fails. Its return value is used instead (inserted text, condition, list, …) |
|
|
1016
1035
|
| `failFast` | `true` | `false`: keep going and throw one error listing all failed commands at the end |
|
|
@@ -2575,6 +2594,27 @@ slide.modifyElement('TextShape', (element: XmlElement, relation?: XmlElement) =>
|
|
|
2575
2594
|
|
|
2576
2595
|
The `addHyperlink` function will automatically detect whether the target is an external URL or an internal slide number and set up the appropriate relationship type and attributes.
|
|
2577
2596
|
|
|
2597
|
+
### Allowed link schemes
|
|
2598
|
+
|
|
2599
|
+
New external links may use `http`, `https`, `mailto` and `tel`. Any other
|
|
2600
|
+
target makes `write()` fail: `javascript:`, `file:`, UNC paths (`\\host\share`),
|
|
2601
|
+
relative paths and app protocols such as `ms-msdt:`. A click on such a link can
|
|
2602
|
+
start a program or send the user's Windows credentials to another host. Links
|
|
2603
|
+
already in a template are copied unchecked.
|
|
2604
|
+
|
|
2605
|
+
Allow more schemes with `allowedLinkSchemes`. `'file'` also allows targets
|
|
2606
|
+
without a scheme:
|
|
2607
|
+
|
|
2608
|
+
```ts
|
|
2609
|
+
const automizer = new Automizer({
|
|
2610
|
+
templateDir: 'templates',
|
|
2611
|
+
allowedLinkSchemes: ['file'],
|
|
2612
|
+
});
|
|
2613
|
+
```
|
|
2614
|
+
|
|
2615
|
+
The check covers `addHyperlink`, `setHyperlinkTarget`, links in MultiText and
|
|
2616
|
+
HTML text, and `{{LINK}}`. Shapes from `slide.generate()` are not checked.
|
|
2617
|
+
|
|
2578
2618
|
### Update or remove existing hyperlinks
|
|
2579
2619
|
|
|
2580
2620
|
Use `modify.setHyperlinkTarget` to change the target of a hyperlink that already exists on a shape. The second argument controls whether the new target is external (default, `true`) or an internal slide link (`false`):
|
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,137 @@ semver, with the pre-1.0 convention that **breaking changes bump the minor**.
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.5.0] - 2026-12-05
|
|
10
|
+
|
|
11
|
+
### Security
|
|
12
|
+
|
|
13
|
+
- **Breaking:** new external hyperlinks only accept `http`, `https`,
|
|
14
|
+
`mailto` and `tel`. `javascript:`, `file:`, UNC paths, relative paths and
|
|
15
|
+
app protocols (`ms-msdt:`, `search-ms:`, …) make `write()` fail; a click on
|
|
16
|
+
them could start a program or leak Windows credentials. Allow more with
|
|
17
|
+
`allowedLinkSchemes: ['file']` on `Automizer` or in the render options.
|
|
18
|
+
Covers `addHyperlink`, `setHyperlinkTarget`, MultiText/HTML links and
|
|
19
|
+
`{{LINK}}`; links already in a template are copied unchecked.
|
|
20
|
+
- fs mode (`archiveType.mode: 'fs'`): a template whose relationships point
|
|
21
|
+
outside the package (`Target="../media/../../../../secret"`) could read any
|
|
22
|
+
file into the output deck or write a file outside the work dir. Such part
|
|
23
|
+
paths are now refused with an `ArchiveError`.
|
|
24
|
+
- Template expressions: `match`, `search`, `matchAll`, `repeat`, `padStart`
|
|
25
|
+
and `padEnd` passed as a callback (`list.map(''.match, text)`) skipped the
|
|
26
|
+
RegExp and string size checks. They are checked now. One evaluation may
|
|
27
|
+
take at most 1,000,000 steps and produce at most 20,000,000 characters or
|
|
28
|
+
list items, and one renderer runs at most 200,000 `FOR` iterations, so a
|
|
29
|
+
template cannot block the process or exhaust its memory.
|
|
30
|
+
- Template tags: an unclosed `{{` no longer makes tag matching quadratic
|
|
31
|
+
(80 KB of text took several seconds). A tag can no longer contain the
|
|
32
|
+
opening tag.
|
|
33
|
+
- `slide.generate()`: an unreachable image URL rejects `write()` instead of
|
|
34
|
+
crashing the Node process, and downloads time out after 30 s. Non-200
|
|
35
|
+
responses are an error instead of being embedded.
|
|
36
|
+
- Template expressions with `Object` or `Reflect` in the data (or in
|
|
37
|
+
`additionalJsContext`, or from `--helpers`) could reach the `Function`
|
|
38
|
+
constructor through property descriptors and run any code.
|
|
39
|
+
`getPrototypeOf`, `setPrototypeOf`, `getOwnPropertyDescriptor(s)`,
|
|
40
|
+
`defineProperty`/`defineProperties` and every `Reflect` method are refused
|
|
41
|
+
now, and so is a forbidden built-in function (`Function`, `call`, an
|
|
42
|
+
unchecked `repeat`, …) returned by a call or passed as an argument.
|
|
43
|
+
- Templates (jszip and fs mode): a part whose zip header gives more than
|
|
44
|
+
1 GiB uncompressed is refused before it is inflated; fs mode also stops
|
|
45
|
+
after 4 GiB in total. A zip bomb with an honest size header filled the
|
|
46
|
+
memory or the disk before.
|
|
47
|
+
- A relationship target with a long run of digits no longer takes seconds
|
|
48
|
+
per `addSlide` (quadratic regex).
|
|
49
|
+
- `pptx-templates init`: a `"data"` path in the config that leads out of the
|
|
50
|
+
config's folder (`../escaped/evil.json`) is refused instead of written.
|
|
51
|
+
Absolute `"data"` and `"schema"` paths are a config error.
|
|
52
|
+
- `{{IMAGE 'path'}}` resolves symlinks before checking that the file is
|
|
53
|
+
inside `imageRoot`; a link in that folder can no longer point elsewhere.
|
|
54
|
+
- Text and hyperlink targets drop U+FFFE, U+FFFF and unpaired surrogates,
|
|
55
|
+
and `{{LINK}}` targets, picture alt texts and hyperlink relationships drop
|
|
56
|
+
control characters, so the written XML stays well-formed.
|
|
57
|
+
- The CLI replaces zero-width and bidi control characters in file names and
|
|
58
|
+
messages, so a file name cannot reorder its line in the output.
|
|
59
|
+
|
|
60
|
+
### Fixed
|
|
61
|
+
|
|
62
|
+
- fs mode: templates with the same file name in different folders, or a
|
|
63
|
+
template edited on disk, are no longer served from a stale cache. Parallel
|
|
64
|
+
instances get their own work dir (`tmp-<uuid>`, removed after output
|
|
65
|
+
unless `cleanupWorkDir: false`) instead of sharing and wiping `tmp`.
|
|
66
|
+
- A picture hyperlink from `slide.generate()` (`addImage({ hyperlink })`)
|
|
67
|
+
keeps its relationship; before, the slide had an `r:id` without a target.
|
|
68
|
+
- `modify.setHyperlinkTarget(n, false)` targets `slide<n>.xml` instead of
|
|
69
|
+
`../slides/<n>`.
|
|
70
|
+
- `ModifyCleanupHelper.removeBackground` no longer removes the outline color
|
|
71
|
+
of a shape without fill.
|
|
72
|
+
- `pptx-templates lint --watch` with a config pattern whose folder does not
|
|
73
|
+
exist yet waits for the folder instead of exiting with "Cannot watch".
|
|
74
|
+
- fs mode on Windows: parallel instances extracting the same template no
|
|
75
|
+
longer fail with `EPERM` on rename.
|
|
76
|
+
- `modify.setText` on a shape whose first paragraph has no run sets the text
|
|
77
|
+
instead of leaving the shape empty.
|
|
78
|
+
- `modify.replaceText`: `$&`, `$'` and `$$` in the replacement are inserted
|
|
79
|
+
as text.
|
|
80
|
+
- Several `modifyElement` calls on one shape run their callbacks in the
|
|
81
|
+
order they were queued (was reversed), and a `removeElement` on the same
|
|
82
|
+
shape is no longer ignored.
|
|
83
|
+
- Chart and cell ranges from the 27th column on get letters (`AA`, `AB`, …);
|
|
84
|
+
before, they were empty (`Sheet1!$$1:$$3`).
|
|
85
|
+
- `setTable` with a row `expand` no longer widens merged cells; rows that
|
|
86
|
+
`setTable` adds no longer inherit the merges of the first row (a merged
|
|
87
|
+
header hid their values).
|
|
88
|
+
- A slide with a linked picture (`TargetMode="External"`) no longer makes
|
|
89
|
+
`write()` fail with "Could not find file ppt/media/https://…".
|
|
90
|
+
- A second `write()`, `stream()` or `getJSZip()` on one instance outputs the
|
|
91
|
+
same presentation instead of appending the slides again.
|
|
92
|
+
- `flow()` with `defTabSz="0"` measures tabs with 72 pt instead of
|
|
93
|
+
producing `NaN`.
|
|
94
|
+
- `{{LINK n}}` requires a whole slide number from 1; `2.5` gave
|
|
95
|
+
`slide2.5.xml`.
|
|
96
|
+
- An empty opening or closing tag is refused.
|
|
97
|
+
- A lint config placeholder named like an `Object` member (`{constructor}`)
|
|
98
|
+
no longer crashes `resolveConfig`.
|
|
99
|
+
- An image imported into a root template that already has `media<n>` (the
|
|
100
|
+
output of an earlier run as root) gets a free name instead of replacing
|
|
101
|
+
that picture on the other slides.
|
|
102
|
+
- `loadMedia()`/`loadMediaBuffer()` with the name of a picture already in
|
|
103
|
+
the output makes `write()` fail instead of silently replacing it; pass a
|
|
104
|
+
prefix.
|
|
105
|
+
- A copied SmartArt keeps its pictures: the `_rels` of its data and drawing
|
|
106
|
+
parts and their images are copied. Its parts are found through the
|
|
107
|
+
shape's relationships, so they need not share a number, and the data part
|
|
108
|
+
points to the new drawing relationship.
|
|
109
|
+
- `modify.setTableStyle` inserts `a:tableStyleId` before `a:extLst`, and
|
|
110
|
+
`modify.addHyperlink` puts `a:hlinkClick` in schema order in `a:rPr`;
|
|
111
|
+
PowerPoint offered to repair such files.
|
|
112
|
+
- `modify.setCornerRadius` keeps the other adjust values of a rounded preset
|
|
113
|
+
(`adj2` of `round2DiagRect`).
|
|
114
|
+
- `flow()` on Windows measures "Arial" with Arial, not Arial Narrow (whose
|
|
115
|
+
typographic family is also "Arial"); about a fifth too much text fit
|
|
116
|
+
into a box. Among faces of one family, the legacy name, normal width and
|
|
117
|
+
the closest weight win.
|
|
118
|
+
- `flow()`: a broken font file no longer allocates gigabytes or throws a
|
|
119
|
+
bare `RangeError`; the error names the file. Cached faces no longer keep
|
|
120
|
+
the whole font file in memory.
|
|
121
|
+
- fs mode: writing the output opens one part at a time instead of all at
|
|
122
|
+
once (`EMFILE` on large decks).
|
|
123
|
+
- `pptx-templates lint`/`usage`: an unreadable deck is reported and the
|
|
124
|
+
other decks are still checked (also with `--json`); the exit code stays 2.
|
|
125
|
+
- `pptx-templates render -o` with the template itself as output is refused;
|
|
126
|
+
the output is written to a temporary file and renamed.
|
|
127
|
+
- CLI options that take a value no longer take the next option as it
|
|
128
|
+
(`--data --watch`), and `--` ends the options.
|
|
129
|
+
- `htmlToMultiText` reports HTML nested too deeply with a clear error
|
|
130
|
+
instead of a `RangeError`.
|
|
131
|
+
- New hyperlink relationships get `rId<n>-created` ids, like every other
|
|
132
|
+
relationship the library creates.
|
|
133
|
+
- The source maps in the package contain the sources (`inlineSources`);
|
|
134
|
+
they pointed to a `src/` folder the package does not ship.
|
|
135
|
+
|
|
136
|
+
- Adding a table column inside a horizontally merged cell (`setTable` with
|
|
137
|
+
`expand` in column mode) now widens the merge when the column is added
|
|
138
|
+
after its third or a later column.
|
|
139
|
+
|
|
9
140
|
## [0.4.0] - 2026-11-24
|
|
10
141
|
|
|
11
142
|
Generating is several times faster, with the same slides. Most of the
|
|
@@ -497,7 +628,8 @@ for that history.
|
|
|
497
628
|
into one `.png` part. The fallback now gets the same placeholder PNG that
|
|
498
629
|
pptxgenjs 3.12 wrote.
|
|
499
630
|
|
|
500
|
-
[Unreleased]: https://github.com/DaBorsten/pptx-templates/compare/v0.
|
|
631
|
+
[Unreleased]: https://github.com/DaBorsten/pptx-templates/compare/v0.5.0...HEAD
|
|
632
|
+
[0.5.0]: https://github.com/DaBorsten/pptx-templates/compare/v0.4.0...v0.5.0
|
|
501
633
|
[0.4.0]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.9...v0.4.0
|
|
502
634
|
[0.3.9]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.8...v0.3.9
|
|
503
635
|
[0.3.8]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.7...v0.3.8
|
package/README.md
CHANGED
|
@@ -7,32 +7,24 @@
|
|
|
7
7
|
**Fill PowerPoint templates with data.** Design the slide in PowerPoint, type
|
|
8
8
|
`{{tags}}` into it, and render it from JavaScript or TypeScript.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
Offer for {{customer.name}} Offer for Ada
|
|
12
|
-
{{FOR item IN items}} → Apples: 1.50 €
|
|
13
|
-
{{item.name}}: {{item.price.toFixed(2)}} € Pears: 2.00 €
|
|
14
|
-
{{END-FOR}}
|
|
15
|
-
```
|
|
10
|
+

|
|
16
11
|
|
|
17
12
|
The library edits your .pptx instead of rebuilding it. Fonts, colors,
|
|
18
|
-
positions, masters and layouts stay exactly as the designer left
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
- **
|
|
26
|
-
project or month into one deck
|
|
27
|
-
- **A linter for templates**: `npx pptx-templates lint` finds broken tags,
|
|
28
|
-
unclosed blocks and misspelled field names before you render, also in CI and
|
|
29
|
-
in watch mode while the deck is open in PowerPoint
|
|
30
|
-
- **Safe expressions**: tags run in a small interpreter, not `eval`, and can't
|
|
13
|
+
positions, masters and layouts stay exactly as the designer left them, and the
|
|
14
|
+
designer can change the template later without touching your code.
|
|
15
|
+
|
|
16
|
+
- **Logic in the slide:** values, `IF`/`ELSE`, `FOR` loops over paragraphs and
|
|
17
|
+
table rows, variables, HTML, links and images, all typed in PowerPoint
|
|
18
|
+
- **A linter for templates:** finds broken tags and misspelled field names
|
|
19
|
+
before you render
|
|
20
|
+
- **Safe expressions:** tags run in a small interpreter, not `eval`, and can't
|
|
31
21
|
reach Node.js
|
|
32
22
|
- **Charts, tables and images from code** when a tag is not enough
|
|
33
23
|
- TypeScript types included, runs on Node.js 20+ and Bun, MIT licensed
|
|
34
24
|
|
|
35
|
-
|
|
25
|
+
**[Read the documentation →](https://daborsten.github.io/pptx-templates/)**
|
|
26
|
+
|
|
27
|
+
## Quick start
|
|
36
28
|
|
|
37
29
|
With npm:
|
|
38
30
|
|
|
@@ -46,24 +38,20 @@ With Bun:
|
|
|
46
38
|
bun add pptx-templates
|
|
47
39
|
```
|
|
48
40
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
**1. Write the template.** Put this into a text box on slide 1 of
|
|
52
|
-
`templates/Offer.pptx` and format it however you like:
|
|
41
|
+
Put this into a text box on slide 1 of `templates/Offer.pptx` and format it
|
|
42
|
+
however you like:
|
|
53
43
|
|
|
54
44
|
```text
|
|
55
45
|
Offer for {{customer.name}}
|
|
56
46
|
{{IF customer.vip}}
|
|
57
47
|
Thank you for being a loyal customer.
|
|
58
|
-
{{ELSE}}
|
|
59
|
-
Have a look at our new offers.
|
|
60
48
|
{{END-IF}}
|
|
61
49
|
{{FOR item IN items}}
|
|
62
|
-
{{
|
|
50
|
+
{{item.name}}: {{item.price.toFixed(2)}} €
|
|
63
51
|
{{END-FOR}}
|
|
64
52
|
```
|
|
65
53
|
|
|
66
|
-
|
|
54
|
+
Render it:
|
|
67
55
|
|
|
68
56
|
```ts
|
|
69
57
|
import Automizer, { modify } from 'pptx-templates';
|
|
@@ -92,80 +80,51 @@ pres.addSlide('offer', 1, (slide) => {
|
|
|
92
80
|
await pres.write('Offer-Ada.pptx');
|
|
93
81
|
```
|
|
94
82
|
|
|
95
|
-
|
|
83
|
+
`output/Offer-Ada.pptx` now reads, with the formatting of your template:
|
|
96
84
|
|
|
97
85
|
```text
|
|
98
86
|
Offer for Ada
|
|
99
87
|
Thank you for being a loyal customer.
|
|
100
|
-
|
|
101
|
-
|
|
88
|
+
Apples: 1.50 €
|
|
89
|
+
Pears: 2.00 €
|
|
102
90
|
```
|
|
103
91
|
|
|
104
|
-
|
|
105
|
-
|
|
92
|
+
Call `addSlide` once per record to get one slide per customer, project or month.
|
|
93
|
+
Slides from several template files can be mixed into one deck. All tags and
|
|
94
|
+
expressions are described in
|
|
95
|
+
[Template Logic](https://daborsten.github.io/pptx-templates/template-logic).
|
|
106
96
|
|
|
107
|
-
|
|
97
|
+
**Using quotes in a tag?** PowerPoint turns `'Ada'` into `‘Ada’` as you type.
|
|
98
|
+
Render with `modify.renderTemplate(data, { fixSmartQuotes: true })`, or turn the
|
|
99
|
+
replacement off:
|
|
108
100
|
|
|
109
|
-
|
|
101
|
+
<details>
|
|
102
|
+
<summary>How to turn off smart quotes in PowerPoint</summary>
|
|
110
103
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
{ name: 'Ada', vip: true },
|
|
114
|
-
{ name: 'Grace', vip: false },
|
|
115
|
-
];
|
|
116
|
-
|
|
117
|
-
for (const customer of customers) {
|
|
118
|
-
pres.addSlide('offer', 1, (slide) => {
|
|
119
|
-
slide.modify(modify.renderTemplate({ customer, items: [] }));
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
await pres.write('All-Offers.pptx');
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
Load several template files and mix their slides to build a full deck: a
|
|
127
|
-
title slide from one file, a chart slide from another, a closing slide from a
|
|
128
|
-
third.
|
|
129
|
-
|
|
130
|
-
## Tags
|
|
104
|
+
*File › Options › Proofing › AutoCorrect Options… › AutoFormat As You Type*,
|
|
105
|
+
then uncheck *"Straight quotes" with “smart quotes”*.
|
|
131
106
|
|
|
132
|
-
|
|
133
|
-
|---|---|
|
|
134
|
-
| `{{expr}}` | Insert a value. `\n` becomes a line break, arrays are joined with `, ` |
|
|
135
|
-
| `{{IF expr}}` … `{{ELSE-IF expr}}` … `{{ELSE}}` … `{{END-IF}}` | Keep the first branch whose condition is true |
|
|
136
|
-
| `{{FOR item IN list}}` … `{{END-FOR}}` | Repeat paragraphs or table rows. `$idx` is the index |
|
|
137
|
-
| `{{EXEC total = 0}}`, `{{! total = total + x}}` | Set variables for the rest of the slide |
|
|
138
|
-
| `{{ALIAS name command}}`, `{{*name}}` | Shorthand for a command you use often |
|
|
139
|
-
| `{{HTML expr}}` | Insert HTML as formatted text: bold, italic, lists, links |
|
|
140
|
-
| `{{LINK expr}}` | Insert a hyperlink, to a URL or to a slide of the output |
|
|
141
|
-
| `{{IMAGE expr}}` | Place a picture where the text box is, optionally cropped to a shape with a border |
|
|
142
|
-
| `{{HIDE-SLIDE expr}}` | In the speaker notes: leave the slide out of the deck when `expr` is true |
|
|
107
|
+

|
|
143
108
|
|
|
144
|
-
|
|
145
|
-
comparisons, `&&`, `||`, `??`, `? :`, arrow functions
|
|
146
|
-
(`items.filter(i => i.active)`), methods of the values (`name.toUpperCase()`)
|
|
147
|
-
and functions you pass in the data.
|
|
109
|
+
</details>
|
|
148
110
|
|
|
149
|
-
|
|
150
|
-
`{{END-FOR}}` closes in the last cell of the same row:
|
|
151
|
-
|
|
152
|
-
| `{{FOR p IN products}}{{p.name}}` | `{{p.price}} €{{END-FOR}}` |
|
|
153
|
-
|---|---|
|
|
111
|
+
## How it compares
|
|
154
112
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
113
|
+
| | pptx-templates | [PptxGenJS](https://github.com/gitbrent/PptxGenJS) | [pptx-automizer](https://github.com/singerla/pptx-automizer) |
|
|
114
|
+
|---|---|---|---|
|
|
115
|
+
| Slide design lives in | the .pptx, edited in PowerPoint | your code | the .pptx |
|
|
116
|
+
| Text logic | tags in the slide: `IF`, `FOR`, … | your code | a callback per shape, simple `{{tag}}` replacement |
|
|
117
|
+
| Repeat table rows from a list | `{{FOR}}` in the row | your code | from code |
|
|
118
|
+
| Template linter | yes | no | no |
|
|
161
119
|
|
|
162
|
-
|
|
120
|
+
Pick PptxGenJS when there is no designed template and the code should draw
|
|
121
|
+
every slide. Pick `pptx-templates` when someone designs the slides in
|
|
122
|
+
PowerPoint and your code only brings the data.
|
|
163
123
|
|
|
164
124
|
## Check templates before you render
|
|
165
125
|
|
|
166
|
-
Templates get edited in PowerPoint, often by people who never run the code.
|
|
167
|
-
|
|
168
|
-
underlined:
|
|
126
|
+
Templates get edited in PowerPoint, often by people who never run the code. The
|
|
127
|
+
linter reports what they broke, slide by slide:
|
|
169
128
|
|
|
170
129
|
```bash
|
|
171
130
|
npx pptx-templates lint templates/*.pptx --data example.json
|
|
@@ -181,101 +140,35 @@ Offer.pptx
|
|
|
181
140
|
1 problem(s): 1 error(s), 0 warning(s)
|
|
182
141
|
```
|
|
183
142
|
|
|
184
|
-
It
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
- `--watch` lints again every time you press Ctrl+S in PowerPoint.
|
|
189
|
-
- The exit code fails a CI job when a template is broken.
|
|
190
|
-
- `npx pptx-templates usage` lists which data fields the tags read, and which
|
|
191
|
-
ones no tag reads.
|
|
192
|
-
- `npx pptx-templates init` writes example data with every field the tags
|
|
193
|
-
read, combined over several decks; run again, it only adds what is missing.
|
|
194
|
-
- `npx pptx-templates render deck.pptx --data data.json -o out.pptx` fills
|
|
195
|
-
every slide with the data, to see the result without writing code
|
|
196
|
-
(`renderDeck()` from code).
|
|
197
|
-
- A `pptx-templates.json` maps many decks to their data, for example one data
|
|
198
|
-
file per language for every customer folder:
|
|
199
|
-
|
|
200
|
-
```json
|
|
201
|
-
{
|
|
202
|
-
"templates": [
|
|
203
|
-
{ "files": "{customer}/cover_{lang}.pptx", "data": "data/cover_{lang}.json" }
|
|
204
|
-
]
|
|
205
|
-
}
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
Both commands are also available from code:
|
|
209
|
-
|
|
210
|
-
```ts
|
|
211
|
-
import { lintTemplate, listTemplateCommands } from 'pptx-templates';
|
|
212
|
-
|
|
213
|
-
const { issues, errorCount } = await lintTemplate('templates/Offer.pptx', {
|
|
214
|
-
data: { customer: { name: 'Ada', vip: true }, items: [] },
|
|
215
|
-
});
|
|
216
|
-
const commands = await listTemplateCommands('templates/Offer.pptx');
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
More in [Template Linter](https://daborsten.github.io/pptx-templates/template-lint).
|
|
143
|
+
It runs in CI, or in watch mode while the deck is open in PowerPoint. See
|
|
144
|
+
[Template Linter](https://daborsten.github.io/pptx-templates/template-lint),
|
|
145
|
+
which also covers the commands that render a deck or write example data without
|
|
146
|
+
any code.
|
|
220
147
|
|
|
221
148
|
## When tags are not enough
|
|
222
149
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
Selection Pane:
|
|
226
|
-
|
|
227
|
-
```ts
|
|
228
|
-
pres.addSlide('offer', 1, (slide) => {
|
|
229
|
-
slide.modifyElement('Title', modify.setText('Offer 2026'));
|
|
230
|
-
slide.modifyElement('Logo', modify.setCornerRadius('10%'));
|
|
231
|
-
});
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
The [`modify.*` helpers](https://daborsten.github.io/pptx-templates/helpers)
|
|
235
|
-
fill [charts](https://daborsten.github.io/pptx-templates/charts) and
|
|
150
|
+
From code you can fill
|
|
151
|
+
[charts](https://daborsten.github.io/pptx-templates/charts) and
|
|
236
152
|
[tables](https://daborsten.github.io/pptx-templates/tables), swap
|
|
237
153
|
[images](https://daborsten.github.io/pptx-templates/images), crop pictures to
|
|
238
154
|
[any preset shape](https://daborsten.github.io/pptx-templates/shape-geometry)
|
|
239
|
-
and move or resize elements
|
|
155
|
+
and move or resize elements with the
|
|
156
|
+
[`modify.*` helpers](https://daborsten.github.io/pptx-templates/helpers).
|
|
157
|
+
For shapes that don't exist in any template,
|
|
240
158
|
[PptxGenJS is built in](https://daborsten.github.io/pptx-templates/generation).
|
|
241
159
|
|
|
242
|
-
## How it compares
|
|
243
|
-
|
|
244
|
-
| | pptx-templates | [PptxGenJS](https://github.com/gitbrent/PptxGenJS) | [pptx-automizer](https://github.com/singerla/pptx-automizer) |
|
|
245
|
-
|---|---|---|---|
|
|
246
|
-
| Slide design lives in | the .pptx, edited in PowerPoint | your code | the .pptx |
|
|
247
|
-
| Text logic | tags in the slide: `IF`, `FOR`, … | your code | a callback per shape, simple `{{tag}}` replacement |
|
|
248
|
-
| Repeat table rows from a list | `{{FOR}}` in the row | your code | from code |
|
|
249
|
-
| Template linter | yes | no | no |
|
|
250
|
-
|
|
251
|
-
Pick PptxGenJS when there is no designed template and the code should draw
|
|
252
|
-
every slide. Pick `pptx-templates` when someone designs the slides in
|
|
253
|
-
PowerPoint and your code only brings the data.
|
|
254
|
-
|
|
255
|
-
## Documentation
|
|
256
|
-
|
|
257
|
-
Guides for every feature and the API reference are at
|
|
258
|
-
**[daborsten.github.io/pptx-templates](https://daborsten.github.io/pptx-templates/)**.
|
|
259
|
-
|
|
260
160
|
Using an AI assistant? Point it to
|
|
261
161
|
[AI-INSTRUCTOR.md](https://github.com/DaBorsten/pptx-templates/blob/main/AI-INSTRUCTOR.md),
|
|
262
|
-
|
|
162
|
+
which ships with the npm package.
|
|
263
163
|
|
|
264
164
|
## Contributing
|
|
265
165
|
|
|
266
|
-
Bug reports, ideas and
|
|
267
|
-
|
|
268
|
-
security
|
|
269
|
-
[security policy](https://github.com/DaBorsten/pptx-templates/blob/main/SECURITY.md)
|
|
270
|
-
instead.
|
|
271
|
-
|
|
272
|
-
## Credits
|
|
273
|
-
|
|
274
|
-
`pptx-templates` is a fork of [pptx-automizer](https://github.com/singerla/pptx-automizer),
|
|
275
|
-
which copies slides and edits the OOXML underneath. The tag syntax comes from
|
|
276
|
-
[docx-templates](https://github.com/guigrpa/docx-templates), so if you fill
|
|
277
|
-
Word templates that way, you already know it.
|
|
166
|
+
[Bug reports, ideas](https://github.com/DaBorsten/pptx-templates/issues/new) and
|
|
167
|
+
pull requests are welcome. Report security problems as described in the
|
|
168
|
+
[security policy](https://github.com/DaBorsten/pptx-templates/blob/main/SECURITY.md).
|
|
278
169
|
|
|
279
|
-
##
|
|
170
|
+
## Credits and license
|
|
280
171
|
|
|
281
|
-
|
|
172
|
+
A fork of [pptx-automizer](https://github.com/singerla/pptx-automizer), with the
|
|
173
|
+
tag syntax of [docx-templates](https://github.com/guigrpa/docx-templates). MIT
|
|
174
|
+
licensed.
|
package/dist/automizer.d.ts
CHANGED
|
@@ -181,7 +181,14 @@ export default class Automizer implements IPresentationProps {
|
|
|
181
181
|
* @returns Promise<NodeJS.ReadableStream>
|
|
182
182
|
*/
|
|
183
183
|
getJSZip(): Promise<JSZip>;
|
|
184
|
+
private finalized;
|
|
185
|
+
/**
|
|
186
|
+
* Runs once: a second write()/stream()/getJSZip() outputs the same
|
|
187
|
+
* presentation instead of appending the queued slides again.
|
|
188
|
+
*/
|
|
184
189
|
finalizePresentation(): Promise<void>;
|
|
190
|
+
private withContext;
|
|
191
|
+
private runFinalize;
|
|
185
192
|
/**
|
|
186
193
|
* Write all masterSlides to archive.
|
|
187
194
|
*/
|
package/dist/automizer.js
CHANGED
|
@@ -41,12 +41,14 @@ const types_1 = require("./types/types");
|
|
|
41
41
|
const template_1 = require("./classes/template");
|
|
42
42
|
const general_helper_1 = require("./helper/general-helper");
|
|
43
43
|
const logger_1 = require("./helper/logger");
|
|
44
|
+
const link_scheme_1 = require("./extensions/link-scheme");
|
|
44
45
|
const master_1 = require("./classes/master");
|
|
45
46
|
const layout_1 = require("./classes/layout");
|
|
46
47
|
const slide_master_remover_1 = require("./classes/slide-master-remover");
|
|
47
48
|
const constants_1 = require("./constants/constants");
|
|
48
49
|
const path_1 = __importDefault(require("path"));
|
|
49
50
|
const fs = __importStar(require("fs"));
|
|
51
|
+
const crypto_1 = require("crypto");
|
|
50
52
|
const xml_helper_1 = require("./helper/xml-helper");
|
|
51
53
|
const modify_presentation_helper_1 = __importDefault(require("./helper/modify-presentation-helper"));
|
|
52
54
|
const content_tracker_1 = require("./helper/content-tracker");
|
|
@@ -119,8 +121,11 @@ class Automizer {
|
|
|
119
121
|
this.archiveParams = {
|
|
120
122
|
mode: params?.archiveType?.mode || 'jszip',
|
|
121
123
|
baseDir: params?.archiveType?.baseDir || __dirname + '/../cache',
|
|
122
|
-
|
|
123
|
-
|
|
124
|
+
// one work dir per instance: parallel fs-mode instances wiped and
|
|
125
|
+
// mixed a shared 'tmp'; a generated dir is removed after output
|
|
126
|
+
workDir: params?.archiveType?.workDir || 'tmp-' + (0, crypto_1.randomUUID)(),
|
|
127
|
+
cleanupWorkDir: params?.archiveType?.cleanupWorkDir ??
|
|
128
|
+
(params?.archiveType?.workDir ? undefined : true),
|
|
124
129
|
decodeText: params?.archiveType?.decodeText,
|
|
125
130
|
};
|
|
126
131
|
this.timer = Date.now();
|
|
@@ -310,7 +315,7 @@ class Automizer {
|
|
|
310
315
|
* @returns Promise<TemplateInfo[]>
|
|
311
316
|
*/
|
|
312
317
|
async setCreationIds() {
|
|
313
|
-
return
|
|
318
|
+
return this.withContext(async () => {
|
|
314
319
|
const templateCreationId = [];
|
|
315
320
|
for (const template of this.templates) {
|
|
316
321
|
const creationIds = template.creationIds || (await template.setCreationIds());
|
|
@@ -499,7 +504,7 @@ class Automizer {
|
|
|
499
504
|
* @returns summary object.
|
|
500
505
|
*/
|
|
501
506
|
async write(location) {
|
|
502
|
-
return
|
|
507
|
+
return this.withContext(async () => {
|
|
503
508
|
await this.finalizePresentation();
|
|
504
509
|
await this.rootTemplate.archive.output(this.getLocation(location, 'output'), this.params);
|
|
505
510
|
const duration = (Date.now() - this.timer) / 1000;
|
|
@@ -522,7 +527,7 @@ class Automizer {
|
|
|
522
527
|
* @returns Promise<NodeJS.ReadableStream>
|
|
523
528
|
*/
|
|
524
529
|
async stream(generatorOptions) {
|
|
525
|
-
return
|
|
530
|
+
return this.withContext(async () => {
|
|
526
531
|
await this.finalizePresentation();
|
|
527
532
|
if (!this.rootTemplate.archive.stream) {
|
|
528
533
|
throw new errors_1.OutputError('Streaming is not implemented for current archive type');
|
|
@@ -535,7 +540,7 @@ class Automizer {
|
|
|
535
540
|
* @returns Promise<NodeJS.ReadableStream>
|
|
536
541
|
*/
|
|
537
542
|
async getJSZip() {
|
|
538
|
-
return
|
|
543
|
+
return this.withContext(async () => {
|
|
539
544
|
await this.finalizePresentation();
|
|
540
545
|
if (!this.rootTemplate.archive.getFinalArchive) {
|
|
541
546
|
throw new errors_1.OutputError('GetFinalArchive is not implemented for current archive type');
|
|
@@ -543,8 +548,24 @@ class Automizer {
|
|
|
543
548
|
return this.rootTemplate.archive.getFinalArchive();
|
|
544
549
|
});
|
|
545
550
|
}
|
|
551
|
+
/**
|
|
552
|
+
* Runs once: a second write()/stream()/getJSZip() outputs the same
|
|
553
|
+
* presentation instead of appending the queued slides again.
|
|
554
|
+
*/
|
|
546
555
|
async finalizePresentation() {
|
|
547
|
-
|
|
556
|
+
// a failed run is not kept: the next call tries again, as before
|
|
557
|
+
this.finalized ??= this.runFinalize().catch((error) => {
|
|
558
|
+
this.finalized = undefined;
|
|
559
|
+
throw error;
|
|
560
|
+
});
|
|
561
|
+
return this.finalized;
|
|
562
|
+
}
|
|
563
|
+
// logger and link-scheme opt-in for everything run inside `fn`
|
|
564
|
+
withContext(fn) {
|
|
565
|
+
return (0, logger_1.runWithLogger)(this.logger, () => (0, link_scheme_1.runWithLinkSchemes)(this.params.allowedLinkSchemes, fn));
|
|
566
|
+
}
|
|
567
|
+
async runFinalize() {
|
|
568
|
+
return this.withContext(async () => {
|
|
548
569
|
await this.writeMasterSlides();
|
|
549
570
|
await this.writeSlides();
|
|
550
571
|
await this.removeSlideMasters();
|
|
@@ -606,6 +627,10 @@ class Automizer {
|
|
|
606
627
|
archiveFilename = file.prefix + file.file;
|
|
607
628
|
}
|
|
608
629
|
archiveFilename = (0, slugify_1.default)(archiveFilename);
|
|
630
|
+
// a silent overwrite would swap the picture on other slides
|
|
631
|
+
if (this.rootTemplate.archive.fileExists(mediaDir + archiveFilename)) {
|
|
632
|
+
throw new errors_1.AutomizerError(`Can't load media: ${mediaDir}${archiveFilename} already exists in the output; pass a prefix to loadMedia()/loadMediaBuffer().`);
|
|
633
|
+
}
|
|
609
634
|
await this.rootTemplate.archive.write(mediaDir + archiveFilename, data);
|
|
610
635
|
await xml_helper_1.XmlHelper.appendImageExtensionToContentType(this.rootTemplate.archive, file.extension);
|
|
611
636
|
}
|