pptx-templates 0.3.3 → 0.3.5

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 (54) hide show
  1. package/AI-INSTRUCTOR.md +318 -3
  2. package/CHANGELOG.md +62 -1
  3. package/README.md +3 -0
  4. package/dist/extensions/cli/index.js +4 -0
  5. package/dist/extensions/cli/index.js.map +1 -1
  6. package/dist/extensions/index.d.ts +3 -0
  7. package/dist/extensions/index.js +6 -1
  8. package/dist/extensions/index.js.map +1 -1
  9. package/dist/extensions/template-lint/lint.d.ts +2 -0
  10. package/dist/extensions/template-lint/lint.js +21 -7
  11. package/dist/extensions/template-lint/lint.js.map +1 -1
  12. package/dist/extensions/template-lint/skeleton.d.ts +9 -1
  13. package/dist/extensions/template-lint/skeleton.js +25 -0
  14. package/dist/extensions/template-lint/skeleton.js.map +1 -1
  15. package/dist/extensions/template-logic/expression.d.ts +11 -0
  16. package/dist/extensions/template-logic/expression.js +44 -0
  17. package/dist/extensions/template-logic/expression.js.map +1 -1
  18. package/dist/extensions/template-logic/images.d.ts +6 -2
  19. package/dist/extensions/template-logic/images.js +62 -12
  20. package/dist/extensions/template-logic/images.js.map +1 -1
  21. package/dist/extensions/template-logic/index.js +6 -0
  22. package/dist/extensions/template-logic/index.js.map +1 -1
  23. package/dist/extensions/template-logic/renderer.d.ts +34 -0
  24. package/dist/extensions/template-logic/renderer.js +217 -6
  25. package/dist/extensions/template-logic/renderer.js.map +1 -1
  26. package/dist/extensions/template-logic/types.d.ts +44 -2
  27. package/dist/extensions/template-render/cli.d.ts +6 -0
  28. package/dist/extensions/template-render/cli.js +205 -0
  29. package/dist/extensions/template-render/cli.js.map +1 -0
  30. package/dist/extensions/template-render/index.d.ts +31 -0
  31. package/dist/extensions/template-render/index.js +192 -0
  32. package/dist/extensions/template-render/index.js.map +1 -0
  33. package/dist/extensions/text-flow/flow.d.ts +128 -0
  34. package/dist/extensions/text-flow/flow.js +462 -0
  35. package/dist/extensions/text-flow/flow.js.map +1 -0
  36. package/dist/extensions/text-flow/font-file.d.ts +34 -0
  37. package/dist/extensions/text-flow/font-file.js +236 -0
  38. package/dist/extensions/text-flow/font-file.js.map +1 -0
  39. package/dist/extensions/text-flow/fonts.d.ts +19 -0
  40. package/dist/extensions/text-flow/fonts.js +186 -0
  41. package/dist/extensions/text-flow/fonts.js.map +1 -0
  42. package/dist/extensions/text-flow/index.d.ts +8 -0
  43. package/dist/extensions/text-flow/index.js +14 -0
  44. package/dist/extensions/text-flow/index.js.map +1 -0
  45. package/dist/extensions/text-flow/layout.d.ts +59 -0
  46. package/dist/extensions/text-flow/layout.js +140 -0
  47. package/dist/extensions/text-flow/layout.js.map +1 -0
  48. package/dist/extensions/text-flow/slide-styles.d.ts +4 -0
  49. package/dist/extensions/text-flow/slide-styles.js +40 -0
  50. package/dist/extensions/text-flow/slide-styles.js.map +1 -0
  51. package/dist/extensions/text-flow/styles.d.ts +54 -0
  52. package/dist/extensions/text-flow/styles.js +265 -0
  53. package/dist/extensions/text-flow/styles.js.map +1 -0
  54. package/package.json +1 -1
package/AI-INSTRUCTOR.md CHANGED
@@ -751,7 +751,26 @@ tables) are not commands: `renderTemplate` leaves them in the text, so
751
751
 
752
752
  ### Images
753
753
 
754
- `{{IMAGE …}}` takes an object like in docx-templates:
754
+ `{{IMAGE …}}` takes the picture itself or an object like in docx-templates.
755
+ The picture can be a `Buffer`, a data URL, or a file path relative to the
756
+ `imageRoot` option, so the template needs no code:
757
+
758
+ ```ts
759
+ import fs from 'fs';
760
+ import { renderDeck } from 'pptx-templates';
761
+
762
+ await renderDeck('templates/Offer.pptx', {
763
+ vip: true,
764
+ logoVip: fs.readFileSync('images/vip.png'), // a Buffer …
765
+ logoStandard: 'images/standard.png', // … or a path below imageRoot
766
+ }, { imageRoot: process.cwd() });
767
+ ```
768
+
769
+ ```text
770
+ {{IF vip}}{{IMAGE logoVip}}{{ELSE}}{{IMAGE logoStandard}}{{END-IF}}
771
+ ```
772
+
773
+ The object form adds size, shape and border:
755
774
 
756
775
  ```ts
757
776
  import fs from 'fs';
@@ -776,8 +795,8 @@ pres.addSlide('TextReplace.pptx', 1, (slide) => {
776
795
 
777
796
  | Property | Effect |
778
797
  |---|---|
779
- | `data` | `Buffer`, `ArrayBuffer`, base64 string or data URL (`data:image/png;base64,…`) |
780
- | `extension` | `.png`, `.jpg`, `.jpeg` or `.gif`. Optional for data URLs |
798
+ | `data` | `Buffer`, `ArrayBuffer`, base64 string, data URL (`data:image/png;base64,…`) or file path below `imageRoot` (`images/logo.png`) |
799
+ | `extension` | `.png`, `.jpg`, `.jpeg` or `.gif`. Optional: taken from a data URL or path, else from the first bytes of the data |
781
800
  | `width`, `height` | Size in cm. With only one of them, the other keeps the aspect ratio. Without both, the picture fits into the shape, keeping its aspect ratio |
782
801
  | `alt` | Alternative text |
783
802
  | `rotation` | Rotation in degrees, clockwise |
@@ -794,6 +813,10 @@ the shape is removed and only the pictures remain.
794
813
 
795
814
  - The shape needs its own position and size. Placeholders that inherit
796
815
  them from the layout are not supported.
816
+ - A string that ends in `.png`, `.jpg`, `.jpeg` or `.gif` is a file path
817
+ (base64 has no dot). It is read from `imageRoot` and cannot leave that
818
+ folder; without `imageRoot` it is an error. `null`, `undefined` and `''`
819
+ place nothing.
797
820
  - `IMAGE` in table cells is not supported.
798
821
  - Identical images are stored only once in the output.
799
822
  - `IMAGE` writes a media file, so it needs `slide.modify(modify.renderTemplate(…))`.
@@ -906,6 +929,53 @@ pres.addSlide('TextReplace.pptx', 1, (slide) => {
906
929
  | `failFast` | `true` | `false`: keep going and throw one error listing all failed commands at the end |
907
930
  | `processLineBreaks` | `true` | Turn `\n` in inserted values into line breaks |
908
931
  | `fixSmartQuotes` | `false` | Replace typographic quotes (`“ ” „ ‘ ’ ‚`) with straight ones before parsing, as in docx-templates |
932
+ | `imageRoot` | | Folder that file paths in `{{IMAGE}}` values are read from (`"images/logo.png"`). Paths cannot leave it |
933
+ | `fonts` | | Font files or folders that [`flow()`](https://daborsten.github.io/pptx-templates/text-flow.md) measures text with, searched before the system fonts |
934
+ | `flowOverflow` | `'warn'` | `'error'`: throw when entries of [`flow()`](https://daborsten.github.io/pptx-templates/text-flow.md) fit into none of its text boxes |
935
+ | `flowPage` | `0` | Which of the slides a [`flow()`](https://daborsten.github.io/pptx-templates/text-flow.md) list needs to render (0-based); see `countFlowPages` |
936
+ | `onFlowPages` | | Called with the number of slides the `flow()` lists of a slide need |
937
+
938
+ ### Rendering a whole deck
939
+
940
+ When every slide of a template is filled with the same data, `renderDeck`
941
+ saves the `addSlide` loop: it renders the tags of each slide and returns the
942
+ new .pptx as a `Buffer`. Masters, layouts and the slide order stay as they
943
+ are in the template.
944
+
945
+ ```ts
946
+ import fs from 'fs';
947
+ import { renderDeck } from 'pptx-templates';
948
+
949
+ const pptx = await renderDeck(
950
+ 'templates/Offer.pptx',
951
+ { customer: { name: 'Ada', vip: true }, items: [] },
952
+ { additionalJsContext: { euro: (n: number) => `${n.toFixed(2)} €` } },
953
+ );
954
+ fs.writeFileSync('output/Offer-Ada.pptx', pptx);
955
+ ```
956
+
957
+ It takes the [options](#options) of `renderTemplate`, plus `slides` to keep
958
+ only some slides in a new order (`slides: [3, 1]`). A tag that fails rejects
959
+ with a `TemplateRenderError` whose message starts with the slide number:
960
+ `slide 2: {{euro(p.preis)}}: Not a function …`.
961
+ A slide whose [`flow()`](https://daborsten.github.io/pptx-templates/text-flow.md) list is longer than its text boxes
962
+ is repeated as often as the list needs.
963
+
964
+ The same from the command line:
965
+
966
+ ```bash
967
+ npx pptx-templates render templates/Offer.pptx --data data.json -o output/Offer-Ada.pptx
968
+ npx pptx-templates render templates/Offer.pptx --data data.json --helpers helpers.js -o out.pptx --slides 3,1
969
+ ```
970
+
971
+ Picture paths in the data (`{ "logo": "images/logo.png" }` with
972
+ `{{IMAGE logo}}`) are read relative to the folder of the data file;
973
+ `--image-root <dir>` sets another folder.
974
+
975
+ `--helpers` loads a JavaScript module whose exports the tags can call, such
976
+ as `module.exports = { euro: (n) => n.toFixed(2) + ' €' }`. It runs as code,
977
+ so only pass files you trust. The exit code is `0` when the file was written,
978
+ `1` when a tag failed and `2` for an invalid call or an unreadable file.
909
979
 
910
980
  ### Listing the commands of a template
911
981
 
@@ -945,6 +1015,250 @@ To check a template for mistakes before rendering, use the
945
1015
  linter (`--opening-tag`, `--closing-tag`, or `openingTag`/`closingTag` in
946
1016
  `pptx-templates.json`), or it checks the wrong tags.
947
1017
 
1018
+ ## Text Flow
1019
+
1020
+ A list that is too long for one text box often has to continue in a second
1021
+ and a third one, like the columns of a newspaper. Write the same loop into
1022
+ every text box and wrap the list in `flow()`:
1023
+
1024
+ ```text
1025
+ {{FOR item IN flow(items)}}
1026
+ {{item.title}}
1027
+ {{item.text}}
1028
+ {{END-FOR}}
1029
+ ```
1030
+
1031
+ ```ts
1032
+ import { modify } from 'pptx-templates';
1033
+
1034
+ const items = [{ title: 'Apples', text: 'Grown in the valley …' }];
1035
+
1036
+ pres.addSlide('Columns.pptx', 1, (slide) => {
1037
+ slide.modify(modify.renderTemplate({ items }));
1038
+ });
1039
+ ```
1040
+
1041
+ `flow()` fills the text boxes in reading order: the leftmost box first, and
1042
+ of boxes that sit on top of each other the upper one first. An entry is never
1043
+ split: it goes into the first box that still has room for all of its
1044
+ paragraphs. Boxes that are not needed stay empty.
1045
+
1046
+ Nothing has to be configured. How much fits into a box comes from the slide
1047
+ itself: the size of the box and its margins, the font, size and weight of
1048
+ each run, line spacing, space before and after paragraphs, indents and
1049
+ bullets, including what the shape inherits from its layout, master and
1050
+ theme. The boxes may be formatted differently and have different widths.
1051
+
1052
+ ### A fixed number of entries per box
1053
+
1054
+ A second argument limits how many entries a box takes, for example one card
1055
+ per box:
1056
+
1057
+ ```text
1058
+ {{FOR item IN flow(items, 1)}}
1059
+ {{item.title}}
1060
+ {{item.text}}
1061
+ {{END-FOR}}
1062
+ ```
1063
+
1064
+ The height still counts: an entry that does not fit moves on to the next box.
1065
+ The number can differ from box to box (`flow(items, 2)` in the first one,
1066
+ `flow(items, 1)` in the others) and can come from the data
1067
+ (`flow(items, perBox)`). With three such boxes and seven entries,
1068
+ `renderDeck` makes three slides: 1 2 3, 4 5 6, 7.
1069
+
1070
+ ### Cards: one entry in several text boxes
1071
+
1072
+ Sometimes an entry fills more than one text box, such as a column with a
1073
+ project on a CV page: one box for the customer, one for the content with
1074
+ bullets, one for the period, each with a size of its own. Select the shapes
1075
+ of each column in PowerPoint, background and lines included, and group them
1076
+ (Ctrl+G). Then write the loop into every text box of the group:
1077
+
1078
+ ```text
1079
+ {{FOR p IN flow(projects, 1)}}
1080
+ Customer: {{p.customer}}
1081
+ {{END-FOR}}
1082
+ ```
1083
+
1084
+ ```text
1085
+ Content:
1086
+ {{FOR p IN flow(projects, 1)}}
1087
+ {{p.content}}
1088
+ {{END-FOR}}
1089
+ ```
1090
+
1091
+ The flow boxes of one list inside one group form a card, and all boxes of a
1092
+ card show the same entries. An entry goes into a card only if its part fits
1093
+ into every box of the card; otherwise it goes on to the next card. The cards
1094
+ are filled in reading order like single boxes, and `renderDeck` continues on
1095
+ a copy of the slide when they are full. With three cards and seven projects,
1096
+ that makes three slides: 1 2 3, 4 5 6, 7.
1097
+
1098
+ A card that stays empty, such as the last two columns of the last slide, is
1099
+ removed with everything in its group. A box that is not in a group is a card
1100
+ of its own, as before. Without `, 1`, a card takes as many entries as fit
1101
+ into all of its boxes.
1102
+
1103
+ ### Counting instead of measuring
1104
+
1105
+ When every box or card takes a fixed number of entries anyway, the
1106
+ measuring can be switched off with a third argument:
1107
+
1108
+ ```text
1109
+ {{FOR p IN flow(projects, 1, { measure: false })}}
1110
+ Customer: {{p.customer}}
1111
+ {{END-FOR}}
1112
+ ```
1113
+
1114
+ Then `flow()` only counts: one project per card, and once all cards of the
1115
+ slide are filled, the rest continues on copies of the slide. Fonts and box
1116
+ heights play no part. A text that is too long stays in its box and runs
1117
+ over its edge in PowerPoint, instead of moving to the next card. The number
1118
+ of entries per box is required with `{ measure: false }`.
1119
+
1120
+ ### How it measures
1121
+
1122
+ Before the boxes are filled, every entry is rendered once into a copy of each
1123
+ box. Its paragraphs are broken into lines with the advance widths from the
1124
+ font file, the way PowerPoint sets text: at spaces and after hyphens, a word
1125
+ longer than the line by characters, and a line height of 1.2 × the font size
1126
+ (× the line spacing). Text around the loop, such as a heading above it,
1127
+ counts as well. The copies are thrown away; `EXEC` assignments of these trial
1128
+ renders are undone, so a counter in the loop counts every entry once.
1129
+
1130
+ Measuring a slide with 24 entries in three boxes takes about 0.2 seconds.
1131
+
1132
+ ### Fonts
1133
+
1134
+ The fonts are read from the system font folders (Windows, macOS, Linux).
1135
+ Where a font is not installed, a font with the same metrics is used: Liberation
1136
+ Sans or Arimo for Arial, Liberation Serif or Tinos for Times New Roman,
1137
+ Liberation Mono or Cousine for Courier New, Carlito for Calibri, Caladea for
1138
+ Cambria. On a Linux server without the Microsoft fonts, install these (Debian
1139
+ and Ubuntu: `fonts-liberation fonts-crosextra-carlito fonts-crosextra-caladea`).
1140
+
1141
+ Fonts that are in neither place can be given as files or folders:
1142
+
1143
+ ```ts
1144
+ import { modify } from 'pptx-templates';
1145
+
1146
+ const items = [{ title: 'Apples', text: 'Grown in the valley …' }];
1147
+
1148
+ pres.addSlide('Columns.pptx', 1, (slide) => {
1149
+ slide.modify(
1150
+ modify.renderTemplate({ items }, { fonts: ['assets/fonts'] }),
1151
+ );
1152
+ });
1153
+ ```
1154
+
1155
+ If a font cannot be found at all, `flow()` logs a warning and measures with
1156
+ Liberation Sans, Arial or another sans-serif font it finds instead.
1157
+
1158
+ ### Lists longer than one slide
1159
+
1160
+ When the boxes are full, the list continues on a copy of the slide: the same
1161
+ boxes, filled with the next entries. `renderDeck` (and
1162
+ `pptx-templates render`) adds these copies by itself, right after the slide:
1163
+
1164
+ ```ts
1165
+ import fs from 'fs';
1166
+ import { renderDeck } from 'pptx-templates';
1167
+
1168
+ const items = [{ title: 'Apples', text: 'Grown in the valley …' }];
1169
+
1170
+ fs.writeFileSync('output/Columns.pptx', await renderDeck('templates/Columns.pptx', { items }));
1171
+ ```
1172
+
1173
+ Everything else on the slide repeats as well. `flowPage` (1, 2, …) and
1174
+ `flowPages` tell the copies apart:
1175
+
1176
+ ```text
1177
+ Products {{IF flowPage > 1}}(continued){{END-IF}}
1178
+ Page {{flowPage}} of {{flowPages}}
1179
+ ```
1180
+
1181
+ With `addSlide`, the deck is planned before anything is rendered, so ask
1182
+ first how many slides the list needs and add them yourself. `flowPage` (0-based)
1183
+ picks the part of the list each one shows:
1184
+
1185
+ ```ts
1186
+ import { countFlowPages, FlowCache, modify } from 'pptx-templates';
1187
+
1188
+ const items = [{ title: 'Apples', text: 'Grown in the valley …' }];
1189
+ const data = { items };
1190
+
1191
+ const flowCache = new FlowCache();
1192
+ const pages = await countFlowPages('templates/Columns.pptx', 1, data, {
1193
+ flowCache,
1194
+ });
1195
+ for (let page = 0; page < pages; page++) {
1196
+ pres.addSlide('Columns.pptx', 1, (slide) => {
1197
+ slide.modify(modify.renderTemplate(data, { flowPage: page, flowCache }));
1198
+ });
1199
+ }
1200
+ ```
1201
+
1202
+ The `flowCache` is optional. Measuring a long list takes time, and with the
1203
+ cache the copies of the slide share one measurement instead of each
1204
+ measuring the whole list again. Use a `new FlowCache()` per template slide
1205
+ and set of data. `renderDeck` does this by itself.
1206
+
1207
+ `flowRest(list)` returns the entries after the current slide, for example
1208
+ for a note at the bottom:
1209
+
1210
+ ```text
1211
+ {{IF flowRest(items).length}}{{flowRest(items).length}} more on the next slide{{END-IF}}
1212
+ ```
1213
+
1214
+ Rendered without `flowPage` (a single `addSlide`), the entries that need
1215
+ another slide are left out and a warning is logged. An entry too large for
1216
+ every box is left out as well, also by `renderDeck`. `flowOverflow: 'error'`
1217
+ turns these warnings into errors:
1218
+
1219
+ ```ts
1220
+ import { modify } from 'pptx-templates';
1221
+
1222
+ const items = [{ title: 'Apples', text: 'Grown in the valley …' }];
1223
+
1224
+ pres.addSlide('Columns.pptx', 1, (slide) => {
1225
+ slide.modify(
1226
+ modify.renderTemplate({ items }, { flowOverflow: 'error' }),
1227
+ );
1228
+ });
1229
+ ```
1230
+
1231
+ ### Rules for the template
1232
+
1233
+ - `{{FOR … IN flow(…)}}` and `{{END-FOR}}` each need a paragraph of their own,
1234
+ and the loop must repeat whole paragraphs. A loop inside one paragraph
1235
+ (`{{FOR i IN flow(items)}}{{i}}, {{END-FOR}}`) is rejected.
1236
+ - All boxes of one list write the same list: `flow(items)` in every box. A
1237
+ slide can have several lists, each with its own boxes.
1238
+ - The boxes need a fixed size. "Shrink text on overflow" is measured with the
1239
+ scale PowerPoint stored in the file; "Resize shape to fit text" is ignored,
1240
+ the box keeps its size.
1241
+ - Not supported: vertical text, text that does not wrap, columns inside one
1242
+ text box, and `flow()` in tables.
1243
+ - Use `slide.modify(modify.renderTemplate(…))`. With `modifyElement()`, the
1244
+ layout and master of the slide are not available, and inherited formatting
1245
+ falls back to defaults.
1246
+
1247
+ ### Good to know
1248
+
1249
+ - The measurement follows PowerPoint's rules, and the results were checked
1250
+ against LibreOffice. PowerPoint and LibreOffice can break a line one word
1251
+ apart now and then; where a line is a fraction of a point too wide,
1252
+ `flow()` breaks it, so a box rather ends up a little emptier than
1253
+ overflowing. Leave a little room at the bottom of the boxes if a line more
1254
+ matters.
1255
+ - Hyphenation, kerning and right-to-left or East Asian line breaking rules
1256
+ are not taken into account.
1257
+ - `flow`, `flowRest`, `flowPage` and `flowPages` are built in. The same name
1258
+ in your data or in `additionalJsContext` takes precedence.
1259
+ - To count the slides, `renderDeck` and `countFlowPages` render the slide
1260
+ once more. Functions in your data are called again then.
1261
+
948
1262
  ## Shape Geometry
949
1263
 
950
1264
  Every shape and picture in PowerPoint has a geometry: a rectangle, an
@@ -1324,6 +1638,7 @@ The placeholders:
1324
1638
  | only test it: `{{IF user.vip}}` | `true` |
1325
1639
  | call a number method or calculate with it: `{{item.price.toFixed(2)}}`, `{{total * 2}}` | `1` |
1326
1640
  | loop over it or call a list method: `{{FOR i IN items}}`, `{{tags.join(', ')}}` | a list with one entry |
1641
+ | place it as a picture: `{{IMAGE logo}}`, `{{IMAGE ({ data: logo })}}` | `null`, and the path is listed in `images` |
1327
1642
 
1328
1643
  Loops and EXEC names are traced back to the data as in
1329
1644
  [data usage](#data-usage). Names that are called (`{{money(total)}}`) are
package/CHANGELOG.md CHANGED
@@ -6,6 +6,65 @@ semver, with the pre-1.0 convention that **breaking changes bump the minor**.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.3.5] - 2026-11-16
10
+
11
+ ### Added
12
+
13
+ - `flow(list)` in templates: the entries of a list flow through several
14
+ text boxes, column by column. Every box holds the same
15
+ `{{FOR item IN flow(items)}} … {{END-FOR}}`; the boxes are filled in
16
+ reading order, and an entry is never split between two boxes. How much
17
+ fits is measured, not estimated: each entry is rendered into a copy of
18
+ each box and broken into lines with the advance widths from the font
19
+ files, with the box's size and margins and the paragraphs' fonts, sizes,
20
+ spacing, indents and bullets, also where they are inherited from the
21
+ layout, master and theme. Fonts come from the system font folders and
22
+ the new `fonts` option; metric-compatible fonts stand in for missing
23
+ ones (Liberation Sans for Arial, Carlito for Calibri, …).
24
+ A list longer than the boxes continues on copies of the slide:
25
+ `renderDeck` and `pptx-templates render` add them by themselves; with
26
+ `addSlide`, `countFlowPages(pptx, slide, data)` tells how many there
27
+ are and the `flowPage` option picks the part each copy shows.
28
+ `flow(items, 1)` puts at most one entry (or any number) into each box.
29
+ `flowPage` and `flowPages` in the template number the copies,
30
+ `flowRest(list)` returns the entries after the current slide. Without
31
+ `flowPage`, entries that need another slide are logged as a warning, or
32
+ rejected with `flowOverflow: 'error'`.
33
+ - `flow()` cards: the flow boxes of a list inside one PowerPoint group show
34
+ the same entries, so an entry can fill several text boxes (a column of a
35
+ CV page with customer, content and period). An entry goes into a card
36
+ only if it fits into every box of it. Cards left empty on the last slide
37
+ are removed with their group. `flow(list, n, { measure: false })`
38
+ distributes by count only, without measuring the text.
39
+ - `flowCache` option with `new FlowCache()`: the copies of a slide share
40
+ one measurement of a `flow()` list instead of measuring it once per copy
41
+ (40 slides of cards: 4 s instead of 110 s). `renderDeck` uses it by
42
+ itself; with `addSlide`, pass one cache to `countFlowPages` and to every
43
+ `flowPage` render of the slide.
44
+ - The linter and `templateDataSkeleton` know `flow()` and `flowRest()`:
45
+ no "unknown variable" for them, and the entries of `flow(items)` are
46
+ traced to `items[]`.
47
+
48
+ ## [0.3.4] - 2026-11-15
49
+
50
+ ### Added
51
+
52
+ - `renderDeck` and `pptx-templates render`: fill the tags of every slide of
53
+ a template with one set of data and get the new .pptx, without writing the
54
+ `addSlide` loop. `slides` (`--slides 3,1`) keeps only some slides, in that
55
+ order; `--helpers` loads a module whose exports the tags can call. A
56
+ failing tag names its slide (`slide 2: {{euro(p.preis)}}: …`); the command
57
+ exits with `1` then.
58
+ - `{{IMAGE logo}}`: the value can be the picture itself (a Buffer, a data
59
+ URL or a file path) instead of `{ data, extension }`. A path such as
60
+ `"images/logo.png"` is read from the new `imageRoot` option and cannot
61
+ leave that folder; `pptx-templates render` uses the folder of the data
62
+ file, `--image-root` another one. `extension` is optional everywhere: the
63
+ type comes from the first bytes of the data.
64
+ - `templateDataSkeleton` lists the paths `{{IMAGE}}` places in `images`
65
+ (also `({ data: x })` and both sides of `a ? b : c`) and gives them
66
+ `null` instead of their path as text.
67
+
9
68
  ## [0.3.3] - 2026-11-14
10
69
 
11
70
  ### Added
@@ -233,7 +292,9 @@ for that history.
233
292
  into one `.png` part. The fallback now gets the same placeholder PNG that
234
293
  pptxgenjs 3.12 wrote.
235
294
 
236
- [Unreleased]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.3...HEAD
295
+ [Unreleased]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.5...HEAD
296
+ [0.3.5]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.4...v0.3.5
297
+ [0.3.4]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.3...v0.3.4
237
298
  [0.3.3]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.2...v0.3.3
238
299
  [0.3.2]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.1...v0.3.2
239
300
  [0.3.1]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.0...v0.3.1
package/README.md CHANGED
@@ -190,6 +190,9 @@ misspelled field names (`user.nmae` → *did you mean "name"?*).
190
190
  ones no tag reads.
191
191
  - `npx pptx-templates init` writes example data with every field the tags
192
192
  read, combined over several decks; run again, it only adds what is missing.
193
+ - `npx pptx-templates render deck.pptx --data data.json -o out.pptx` fills
194
+ every slide with the data, to see the result without writing code
195
+ (`renderDeck()` from code).
193
196
  - A `pptx-templates.json` maps many decks to their data, for example one data
194
197
  file per language for every customer folder:
195
198
 
@@ -17,12 +17,14 @@ exports.runCli = void 0;
17
17
  const cli_1 = require("../template-lint/cli");
18
18
  const init_cli_1 = require("../template-lint/init-cli");
19
19
  const usage_cli_1 = require("../template-lint/usage-cli");
20
+ const cli_2 = require("../template-render/cli");
20
21
  const USAGE = `Usage: pptx-templates <command> [options]
21
22
 
22
23
  Commands:
23
24
  lint <file.pptx>... Check the {{…}} tags of templates
24
25
  usage <file.pptx>... Show which data fields the tags read, and which not
25
26
  init <file.pptx>... Write example data with every field the tags read
27
+ render <file.pptx> Fill the tags with data and write a new .pptx
26
28
 
27
29
  Run pptx-templates <command> --help for the options of a command.`;
28
30
  const runCli = (args, io) => __awaiter(void 0, void 0, void 0, function* () {
@@ -33,6 +35,8 @@ const runCli = (args, io) => __awaiter(void 0, void 0, void 0, function* () {
33
35
  return (0, usage_cli_1.runUsageCommand)(rest, io);
34
36
  if (command === 'init')
35
37
  return (0, init_cli_1.runInitCommand)(rest, io);
38
+ if (command === 'render')
39
+ return (0, cli_2.runRenderCommand)(rest, io);
36
40
  if (command === '-h' || command === '--help') {
37
41
  io.stdout(`${USAGE}\n`);
38
42
  return 0;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/cli/index.ts"],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: {
6
6
  };
7
7
  export * from './template-logic';
8
8
  export * from './template-lint';
9
+ export { renderDeck, countFlowPages } from './template-render';
10
+ export type { RenderDeckOptions } from './template-render';
11
+ export { FlowCache } from './text-flow';
9
12
  export { ShapePresets } from './shape-geometry';
10
13
  export type { ShapePreset, RoundedShapePreset, CornerRadius, ShapeAdjustments, ImageBorder, } from './shape-geometry';
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.ShapePresets = exports.extensionModifiers = void 0;
17
+ exports.ShapePresets = exports.FlowCache = exports.countFlowPages = exports.renderDeck = exports.extensionModifiers = void 0;
18
18
  /**
19
19
  * Fork extensions (not part of upstream singerla/pptx-automizer).
20
20
  *
@@ -32,6 +32,11 @@ exports.extensionModifiers = {
32
32
  };
33
33
  __exportStar(require("./template-logic"), exports);
34
34
  __exportStar(require("./template-lint"), exports);
35
+ var template_render_1 = require("./template-render");
36
+ Object.defineProperty(exports, "renderDeck", { enumerable: true, get: function () { return template_render_1.renderDeck; } });
37
+ Object.defineProperty(exports, "countFlowPages", { enumerable: true, get: function () { return template_render_1.countFlowPages; } });
38
+ var text_flow_1 = require("./text-flow");
39
+ Object.defineProperty(exports, "FlowCache", { enumerable: true, get: function () { return text_flow_1.FlowCache; } });
35
40
  var shape_geometry_2 = require("./shape-geometry");
36
41
  Object.defineProperty(exports, "ShapePresets", { enumerable: true, get: function () { return shape_geometry_2.ShapePresets; } });
37
42
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;GAMG;AACH,qDAAkD;AAClD,qDAAgE;AAEhE,iEAAiE;AACpD,QAAA,kBAAkB,GAAG;IAChC,cAAc,EAAd,+BAAc;IACd,WAAW,EAAX,4BAAW;IACX,eAAe,EAAf,gCAAe;CAChB,CAAC;AAEF,mDAAiC;AACjC,kDAAgC;AAChC,mDAAgD;AAAvC,8GAAA,YAAY,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;GAMG;AACH,qDAAkD;AAClD,qDAAgE;AAEhE,iEAAiE;AACpD,QAAA,kBAAkB,GAAG;IAChC,cAAc,EAAd,+BAAc;IACd,WAAW,EAAX,4BAAW;IACX,eAAe,EAAf,gCAAe;CAChB,CAAC;AAEF,mDAAiC;AACjC,kDAAgC;AAChC,qDAA+D;AAAtD,6GAAA,UAAU,OAAA;AAAE,iHAAA,cAAc,OAAA;AAEnC,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,mDAAgD;AAAvC,8GAAA,YAAY,OAAA"}
@@ -13,6 +13,8 @@ export type UsageSink = {
13
13
  record(keys: string[], whole: boolean, location: DataUsageLocation, use?: PathUse): void;
14
14
  /** `{{FOR x IN keys}}` iterates over this path. */
15
15
  recordList?(keys: string[]): void;
16
+ /** `{{IMAGE keys}}` places the value at this path as a picture. */
17
+ recordImage?(keys: string[]): void;
16
18
  };
17
19
  /**
18
20
  * Checks the template tags of a .pptx before rendering: syntax errors,
@@ -22,6 +22,13 @@ const data_model_1 = require("./data-model");
22
22
  const hints_1 = require("./hints");
23
23
  const usage_1 = require("./usage");
24
24
  const skeleton_1 = require("./skeleton");
25
+ /** Helpers renderTemplate provides itself (see text-flow). */
26
+ const BUILTIN_HELPERS = {
27
+ flow: (list) => list,
28
+ flowRest: () => [],
29
+ flowPage: 1,
30
+ flowPages: 1,
31
+ };
25
32
  const ANY = { kind: 'any' };
26
33
  const children = (parent, tagName) => {
27
34
  const result = [];
@@ -141,7 +148,7 @@ const OTHER_PARTS = [
141
148
  ];
142
149
  class TemplateLinter {
143
150
  constructor(options, usage) {
144
- var _a, _b;
151
+ var _a;
145
152
  this.usage = usage;
146
153
  this.issues = [];
147
154
  this.seen = new Set();
@@ -152,8 +159,10 @@ class TemplateLinter {
152
159
  this.syntax = (0, commands_1.tagSyntax)(options);
153
160
  this.fixQuotes = (_a = options.fixSmartQuotes) !== null && _a !== void 0 ? _a : false;
154
161
  this.data = options.data;
155
- this.extraNames = new Set(Object.keys((_b = options.additionalJsContext) !== null && _b !== void 0 ? _b : {}));
156
- this.model = new data_model_1.DataModel(options.data, options.schema, options.additionalJsContext);
162
+ // Built-in helpers count like additionalJsContext: names, not data
163
+ const helpers = Object.assign(Object.assign({}, BUILTIN_HELPERS), options.additionalJsContext);
164
+ this.extraNames = new Set(Object.keys(helpers));
165
+ this.model = new data_model_1.DataModel(options.data, options.schema, helpers);
157
166
  }
158
167
  report(part, slide, issue) {
159
168
  // The same finding in the same shape once is enough (e.g. in loops)
@@ -227,7 +236,7 @@ class TemplateLinter {
227
236
  const stack = [];
228
237
  const where = container.kind === 'table' ? 'table' : 'shape';
229
238
  container.segments.forEach((segment) => {
230
- var _a, _b;
239
+ var _a, _b, _c, _d, _e;
231
240
  const shape = shapeOf(segment.paragraph);
232
241
  const name = shapeName(shape);
233
242
  this.checkDelimiters(segment.text, (issue) => report(Object.assign(Object.assign({}, issue), { shape: name })));
@@ -285,7 +294,7 @@ class TemplateLinter {
285
294
  }
286
295
  case 'FOR': {
287
296
  const expr = check(command.code, false);
288
- const listPath = this.dataPathOf(expr === null || expr === void 0 ? void 0 : expr.path(), paths);
297
+ const listPath = this.dataPathOf(expr === null || expr === void 0 ? void 0 : expr.listPath(), paths);
289
298
  const entryPath = listPath && [...listPath, '[]'];
290
299
  if (listPath)
291
300
  (_b = (_a = this.usage) === null || _a === void 0 ? void 0 : _a.recordList) === null || _b === void 0 ? void 0 : _b.call(_a, listPath);
@@ -383,7 +392,12 @@ class TemplateLinter {
383
392
  case 'ALIAS':
384
393
  break;
385
394
  case 'IMAGE': {
386
- check(command.code);
395
+ const expr = check(command.code);
396
+ for (const ref of (_c = expr === null || expr === void 0 ? void 0 : expr.imageSources()) !== null && _c !== void 0 ? _c : []) {
397
+ const imagePath = this.dataPathOf(ref, paths);
398
+ if (imagePath)
399
+ (_e = (_d = this.usage) === null || _d === void 0 ? void 0 : _d.recordImage) === null || _e === void 0 ? void 0 : _e.call(_d, imagePath);
400
+ }
387
401
  if (segment.cell !== undefined) {
388
402
  tagReport({
389
403
  severity: 'error',
@@ -576,7 +590,7 @@ class TemplateLinter {
576
590
  }
577
591
  /** Entry type of a FOR loop; undefined if the data says "not a list". */
578
592
  loopElement(expr, loopVars, execNames) {
579
- const path = expr === null || expr === void 0 ? void 0 : expr.path();
593
+ const path = expr === null || expr === void 0 ? void 0 : expr.listPath();
580
594
  if (!path || !this.model.enabled)
581
595
  return ANY;
582
596
  let known = this.lookup(path.name, loopVars, execNames);