pptx-templates 0.3.4 → 0.3.6

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 (47) hide show
  1. package/AI-INSTRUCTOR.md +378 -1
  2. package/CHANGELOG.md +64 -1
  3. package/README.md +1 -0
  4. package/dist/extensions/hide-slide/index.d.ts +44 -0
  5. package/dist/extensions/hide-slide/index.js +244 -0
  6. package/dist/extensions/hide-slide/index.js.map +1 -0
  7. package/dist/extensions/index.d.ts +4 -1
  8. package/dist/extensions/index.js +7 -1
  9. package/dist/extensions/index.js.map +1 -1
  10. package/dist/extensions/template-lint/lint.js +67 -6
  11. package/dist/extensions/template-lint/lint.js.map +1 -1
  12. package/dist/extensions/template-logic/commands.js +5 -0
  13. package/dist/extensions/template-logic/commands.js.map +1 -1
  14. package/dist/extensions/template-logic/expression.d.ts +5 -0
  15. package/dist/extensions/template-logic/expression.js +14 -0
  16. package/dist/extensions/template-logic/expression.js.map +1 -1
  17. package/dist/extensions/template-logic/index.js +6 -0
  18. package/dist/extensions/template-logic/index.js.map +1 -1
  19. package/dist/extensions/template-logic/renderer.d.ts +37 -0
  20. package/dist/extensions/template-logic/renderer.js +236 -5
  21. package/dist/extensions/template-logic/renderer.js.map +1 -1
  22. package/dist/extensions/template-logic/types.d.ts +38 -1
  23. package/dist/extensions/template-render/index.d.ts +18 -0
  24. package/dist/extensions/template-render/index.js +124 -20
  25. package/dist/extensions/template-render/index.js.map +1 -1
  26. package/dist/extensions/text-flow/flow.d.ts +153 -0
  27. package/dist/extensions/text-flow/flow.js +541 -0
  28. package/dist/extensions/text-flow/flow.js.map +1 -0
  29. package/dist/extensions/text-flow/font-file.d.ts +34 -0
  30. package/dist/extensions/text-flow/font-file.js +236 -0
  31. package/dist/extensions/text-flow/font-file.js.map +1 -0
  32. package/dist/extensions/text-flow/fonts.d.ts +19 -0
  33. package/dist/extensions/text-flow/fonts.js +186 -0
  34. package/dist/extensions/text-flow/fonts.js.map +1 -0
  35. package/dist/extensions/text-flow/index.d.ts +8 -0
  36. package/dist/extensions/text-flow/index.js +16 -0
  37. package/dist/extensions/text-flow/index.js.map +1 -0
  38. package/dist/extensions/text-flow/layout.d.ts +59 -0
  39. package/dist/extensions/text-flow/layout.js +140 -0
  40. package/dist/extensions/text-flow/layout.js.map +1 -0
  41. package/dist/extensions/text-flow/slide-styles.d.ts +4 -0
  42. package/dist/extensions/text-flow/slide-styles.js +40 -0
  43. package/dist/extensions/text-flow/slide-styles.js.map +1 -0
  44. package/dist/extensions/text-flow/styles.d.ts +54 -0
  45. package/dist/extensions/text-flow/styles.js +265 -0
  46. package/dist/extensions/text-flow/styles.js.map +1 -0
  47. package/package.json +1 -1
package/AI-INSTRUCTOR.md CHANGED
@@ -713,6 +713,7 @@ pres.addSlide('TextReplace.pptx', 1, (slide) => {
713
713
  | `{{HTML expr}}` | Insert HTML as formatted paragraphs (bold, italic, lists, links, …) through the [HTML converter](https://daborsten.github.io/pptx-templates/text.md) |
714
714
  | `{{LINK expr}}` | Insert a hyperlink. `expr` is a URL or `({ url, label })`. A number as `url` links to that slide of the output |
715
715
  | `{{IMAGE expr}}` | Place a picture where the shape is (see [Images](#images)). Needs `slide.modify` |
716
+ | `{{HIDE-SLIDE expr}}` | In the speaker notes: `renderDeck` leaves the slide out when `expr` is true (see [Hide Slides](https://daborsten.github.io/pptx-templates/hide-slide.md)). Anywhere else it is removed and does nothing |
716
717
 
717
718
  Keywords are case-insensitive. A block can sit inside one paragraph
718
719
  (`Status: {{IF ok}}fine{{ELSE}}broken{{END-IF}}`) or span paragraphs. A
@@ -930,6 +931,10 @@ pres.addSlide('TextReplace.pptx', 1, (slide) => {
930
931
  | `processLineBreaks` | `true` | Turn `\n` in inserted values into line breaks |
931
932
  | `fixSmartQuotes` | `false` | Replace typographic quotes (`“ ” „ ‘ ’ ‚`) with straight ones before parsing, as in docx-templates |
932
933
  | `imageRoot` | | Folder that file paths in `{{IMAGE}}` values are read from (`"images/logo.png"`). Paths cannot leave it |
934
+ | `fonts` | | Font files or folders that [`flow()`](https://daborsten.github.io/pptx-templates/text-flow.md) measures text with, searched before the system fonts |
935
+ | `flowOverflow` | `'warn'` | `'error'`: throw when entries of [`flow()`](https://daborsten.github.io/pptx-templates/text-flow.md) fit into none of its text boxes |
936
+ | `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` |
937
+ | `onFlowPages` | | Called with the number of slides the `flow()` lists of a slide need |
933
938
 
934
939
  ### Rendering a whole deck
935
940
 
@@ -954,6 +959,8 @@ It takes the [options](#options) of `renderTemplate`, plus `slides` to keep
954
959
  only some slides in a new order (`slides: [3, 1]`). A tag that fails rejects
955
960
  with a `TemplateRenderError` whose message starts with the slide number:
956
961
  `slide 2: {{euro(p.preis)}}: Not a function …`.
962
+ A slide whose [`flow()`](https://daborsten.github.io/pptx-templates/text-flow.md) list is longer than its text boxes
963
+ is repeated as often as the list needs.
957
964
 
958
965
  The same from the command line:
959
966
 
@@ -1009,6 +1016,376 @@ To check a template for mistakes before rendering, use the
1009
1016
  linter (`--opening-tag`, `--closing-tag`, or `openingTag`/`closingTag` in
1010
1017
  `pptx-templates.json`), or it checks the wrong tags.
1011
1018
 
1019
+ ## Text Flow
1020
+
1021
+ A list that is too long for one text box often has to continue in a second
1022
+ and a third one, like the columns of a newspaper. Write the same loop into
1023
+ every text box and wrap the list in `flow()`:
1024
+
1025
+ ```text
1026
+ {{FOR item IN flow(items)}}
1027
+ {{item.title}}
1028
+ {{item.text}}
1029
+ {{END-FOR}}
1030
+ ```
1031
+
1032
+ ```ts
1033
+ import { modify } from 'pptx-templates';
1034
+
1035
+ const items = [{ title: 'Apples', text: 'Grown in the valley …' }];
1036
+
1037
+ pres.addSlide('Columns.pptx', 1, (slide) => {
1038
+ slide.modify(modify.renderTemplate({ items }));
1039
+ });
1040
+ ```
1041
+
1042
+ `flow()` fills the text boxes in reading order: the leftmost box first, and
1043
+ of boxes that sit on top of each other the upper one first. An entry is never
1044
+ split: it goes into the first box that still has room for all of its
1045
+ paragraphs. Boxes that are not needed stay empty.
1046
+
1047
+ Nothing has to be configured. How much fits into a box comes from the slide
1048
+ itself: the size of the box and its margins, the font, size and weight of
1049
+ each run, line spacing, space before and after paragraphs, indents and
1050
+ bullets, including what the shape inherits from its layout, master and
1051
+ theme. The boxes may be formatted differently and have different widths.
1052
+
1053
+ ### A fixed number of entries per box
1054
+
1055
+ A second argument limits how many entries a box takes, for example one card
1056
+ per box:
1057
+
1058
+ ```text
1059
+ {{FOR item IN flow(items, 1)}}
1060
+ {{item.title}}
1061
+ {{item.text}}
1062
+ {{END-FOR}}
1063
+ ```
1064
+
1065
+ The height still counts: an entry that does not fit moves on to the next box.
1066
+ The number can differ from box to box (`flow(items, 2)` in the first one,
1067
+ `flow(items, 1)` in the others) and can come from the data
1068
+ (`flow(items, perBox)`). With three such boxes and seven entries,
1069
+ `renderDeck` makes three slides: 1 2 3, 4 5 6, 7.
1070
+
1071
+ ### Cards: one entry in several text boxes
1072
+
1073
+ Sometimes an entry fills more than one text box, such as a column with a
1074
+ project on a CV page: one box for the customer, one for the content with
1075
+ bullets, one for the period, each with a size of its own. Select the shapes
1076
+ of each column in PowerPoint, background and lines included, and group them
1077
+ (Ctrl+G). Then write the loop into every text box of the group:
1078
+
1079
+ ```text
1080
+ {{FOR p IN flow(projects, 1)}}
1081
+ Customer: {{p.customer}}
1082
+ {{END-FOR}}
1083
+ ```
1084
+
1085
+ ```text
1086
+ Content:
1087
+ {{FOR p IN flow(projects, 1)}}
1088
+ {{p.content}}
1089
+ {{END-FOR}}
1090
+ ```
1091
+
1092
+ The flow boxes of one list inside one group form a card, and all boxes of a
1093
+ card show the same entries. An entry goes into a card only if its part fits
1094
+ into every box of the card; otherwise it goes on to the next card. The cards
1095
+ are filled in reading order like single boxes, and `renderDeck` continues on
1096
+ a copy of the slide when they are full. With three cards and seven projects,
1097
+ that makes three slides: 1 2 3, 4 5 6, 7.
1098
+
1099
+ A card that stays empty, such as the last two columns of the last slide, is
1100
+ removed with everything in its group. A box that is not in a group is a card
1101
+ of its own, as before. Without `, 1`, a card takes as many entries as fit
1102
+ into all of its boxes.
1103
+
1104
+ ### Counting instead of measuring
1105
+
1106
+ When every box or card takes a fixed number of entries anyway, the
1107
+ measuring can be switched off with a third argument:
1108
+
1109
+ ```text
1110
+ {{FOR p IN flow(projects, 1, { measure: false })}}
1111
+ Customer: {{p.customer}}
1112
+ {{END-FOR}}
1113
+ ```
1114
+
1115
+ Then `flow()` only counts: one project per card, and once all cards of the
1116
+ slide are filled, the rest continues on copies of the slide. Fonts and box
1117
+ heights play no part. A text that is too long stays in its box and runs
1118
+ over its edge in PowerPoint, instead of moving to the next card. The number
1119
+ of entries per box is required with `{ measure: false }`.
1120
+
1121
+ ### How it measures
1122
+
1123
+ Before the boxes are filled, every entry is rendered once into a copy of each
1124
+ box. Its paragraphs are broken into lines with the advance widths from the
1125
+ font file, the way PowerPoint sets text: at spaces and after hyphens, a word
1126
+ longer than the line by characters, and a line height of 1.2 × the font size
1127
+ (× the line spacing). Text around the loop, such as a heading above it,
1128
+ counts as well. The copies are thrown away; `EXEC` assignments of these trial
1129
+ renders are undone, so a counter in the loop counts every entry once.
1130
+
1131
+ Measuring a slide with 24 entries in three boxes takes about 0.2 seconds.
1132
+
1133
+ ### Fonts
1134
+
1135
+ The fonts are read from the system font folders (Windows, macOS, Linux).
1136
+ Where a font is not installed, a font with the same metrics is used: Liberation
1137
+ Sans or Arimo for Arial, Liberation Serif or Tinos for Times New Roman,
1138
+ Liberation Mono or Cousine for Courier New, Carlito for Calibri, Caladea for
1139
+ Cambria. On a Linux server without the Microsoft fonts, install these (Debian
1140
+ and Ubuntu: `fonts-liberation fonts-crosextra-carlito fonts-crosextra-caladea`).
1141
+
1142
+ Fonts that are in neither place can be given as files or folders:
1143
+
1144
+ ```ts
1145
+ import { modify } from 'pptx-templates';
1146
+
1147
+ const items = [{ title: 'Apples', text: 'Grown in the valley …' }];
1148
+
1149
+ pres.addSlide('Columns.pptx', 1, (slide) => {
1150
+ slide.modify(
1151
+ modify.renderTemplate({ items }, { fonts: ['assets/fonts'] }),
1152
+ );
1153
+ });
1154
+ ```
1155
+
1156
+ If a font cannot be found at all, `flow()` logs a warning and measures with
1157
+ Liberation Sans, Arial or another sans-serif font it finds instead.
1158
+
1159
+ ### Lists longer than one slide
1160
+
1161
+ When the boxes are full, the list continues on a copy of the slide: the same
1162
+ boxes, filled with the next entries. `renderDeck` (and
1163
+ `pptx-templates render`) adds these copies by itself, right after the slide:
1164
+
1165
+ ```ts
1166
+ import fs from 'fs';
1167
+ import { renderDeck } from 'pptx-templates';
1168
+
1169
+ const items = [{ title: 'Apples', text: 'Grown in the valley …' }];
1170
+
1171
+ fs.writeFileSync('output/Columns.pptx', await renderDeck('templates/Columns.pptx', { items }));
1172
+ ```
1173
+
1174
+ Everything else on the slide repeats as well. `flowPage` (1, 2, …) and
1175
+ `flowPages` tell the copies apart:
1176
+
1177
+ ```text
1178
+ Products {{IF flowPage > 1}}(continued){{END-IF}}
1179
+ Page {{flowPage}} of {{flowPages}}
1180
+ ```
1181
+
1182
+ With `addSlide`, the deck is planned before anything is rendered, so ask
1183
+ first how many slides the list needs and add them yourself. `flowPage` (0-based)
1184
+ picks the part of the list each one shows:
1185
+
1186
+ ```ts
1187
+ import { countFlowPages, FlowCache, modify } from 'pptx-templates';
1188
+
1189
+ const items = [{ title: 'Apples', text: 'Grown in the valley …' }];
1190
+ const data = { items };
1191
+
1192
+ const flowCache = new FlowCache();
1193
+ const pages = await countFlowPages('templates/Columns.pptx', 1, data, {
1194
+ flowCache,
1195
+ });
1196
+ for (let page = 0; page < pages; page++) {
1197
+ pres.addSlide('Columns.pptx', 1, (slide) => {
1198
+ slide.modify(modify.renderTemplate(data, { flowPage: page, flowCache }));
1199
+ });
1200
+ }
1201
+ ```
1202
+
1203
+ The `flowCache` is optional. Measuring a long list takes time, and with the
1204
+ cache the copies of the slide share one measurement instead of each
1205
+ measuring the whole list again. Use a `new FlowCache()` per template slide
1206
+ and set of data. `renderDeck` does this by itself.
1207
+
1208
+ `flowRest(list)` returns the entries after the current slide, for example
1209
+ for a note at the bottom:
1210
+
1211
+ ```text
1212
+ {{IF flowRest(items).length}}{{flowRest(items).length}} more on the next slide{{END-IF}}
1213
+ ```
1214
+
1215
+ Rendered without `flowPage` (a single `addSlide`), the entries that need
1216
+ another slide are left out and a warning is logged. An entry too large for
1217
+ every box is left out as well, also by `renderDeck`. `flowOverflow: 'error'`
1218
+ turns these warnings into errors:
1219
+
1220
+ ```ts
1221
+ import { modify } from 'pptx-templates';
1222
+
1223
+ const items = [{ title: 'Apples', text: 'Grown in the valley …' }];
1224
+
1225
+ pres.addSlide('Columns.pptx', 1, (slide) => {
1226
+ slide.modify(
1227
+ modify.renderTemplate({ items }, { flowOverflow: 'error' }),
1228
+ );
1229
+ });
1230
+ ```
1231
+
1232
+ ### Continuing on another slide
1233
+
1234
+ `flowContinue(list)` is `list` without the entries that `flow()` shows on
1235
+ the slides before it in the output of `renderDeck`. A first slide can show
1236
+ as many projects as fit into one text box, and a second slide the rest, one
1237
+ per column:
1238
+
1239
+ ```text
1240
+ {{FOR p IN flow(projects)}}
1241
+ {{p.name}}
1242
+ {{END-FOR}}
1243
+ ```
1244
+
1245
+ ```text
1246
+ {{FOR p IN flow(flowContinue(projects), 1)}}
1247
+ {{p.name}}
1248
+ {{END-FOR}}
1249
+ ```
1250
+
1251
+ Without more, the first slide would repeat until every project is on it.
1252
+ `{{HIDE-SLIDE flowPage > 1}}` in its speaker notes keeps only its first
1253
+ copy (see [Hide Slides](https://daborsten.github.io/pptx-templates/hide-slide.md)); entries of hidden copies count
1254
+ as not shown. The second slide repeats as usual while projects are left.
1255
+
1256
+ - Objects are compared with `===`: the objects of your data count as shown
1257
+ wherever `flow()` showed them. Strings and numbers count only for the
1258
+ same list, `projects` itself or a `flowContinue(projects)`; of equal ones,
1259
+ as many are skipped as were shown. A list built anew in the template
1260
+ (`projects.map(…)`, `filter(…)`) is a different list.
1261
+ - With the `flowPage` option, each slide shows that part of its lists, and
1262
+ `flowContinue()` goes on after it.
1263
+ - `{{HIDE-SLIDE !flowContinue(projects).length}}` leaves the second slide
1264
+ out when the first one shows every project.
1265
+ - Outside `renderDeck`, `flowContinue(list)` is the whole list.
1266
+
1267
+ ### Rules for the template
1268
+
1269
+ - `{{FOR … IN flow(…)}}` and `{{END-FOR}}` each need a paragraph of their own,
1270
+ and the loop must repeat whole paragraphs. A loop inside one paragraph
1271
+ (`{{FOR i IN flow(items)}}{{i}}, {{END-FOR}}`) is rejected.
1272
+ - All boxes of one list write the same list: `flow(items)` in every box. A
1273
+ slide can have several lists, each with its own boxes.
1274
+ - The boxes need a fixed size. "Shrink text on overflow" is measured with the
1275
+ scale PowerPoint stored in the file; "Resize shape to fit text" is ignored,
1276
+ the box keeps its size.
1277
+ - Not supported: vertical text, text that does not wrap, columns inside one
1278
+ text box, and `flow()` in tables.
1279
+ - Use `slide.modify(modify.renderTemplate(…))`. With `modifyElement()`, the
1280
+ layout and master of the slide are not available, and inherited formatting
1281
+ falls back to defaults.
1282
+
1283
+ ### Good to know
1284
+
1285
+ - The measurement follows PowerPoint's rules, and the results were checked
1286
+ against LibreOffice. PowerPoint and LibreOffice can break a line one word
1287
+ apart now and then; where a line is a fraction of a point too wide,
1288
+ `flow()` breaks it, so a box rather ends up a little emptier than
1289
+ overflowing. Leave a little room at the bottom of the boxes if a line more
1290
+ matters.
1291
+ - Hyphenation, kerning and right-to-left or East Asian line breaking rules
1292
+ are not taken into account.
1293
+ - `flow`, `flowRest`, `flowContinue`, `flowPage` and `flowPages` are built in. The same name
1294
+ in your data or in `additionalJsContext` takes precedence.
1295
+ - To count the slides, `renderDeck` and `countFlowPages` render the slide
1296
+ once more. Functions in your data are called again then.
1297
+
1298
+ ## Hide Slides
1299
+
1300
+ Some slides only make sense with the right data: a slide for further
1301
+ projects when there are more than two, a discount slide for VIP customers.
1302
+ Write `{{HIDE-SLIDE condition}}` into the **speaker notes** of the slide,
1303
+ and `renderDeck` leaves the slide out when the condition is true:
1304
+
1305
+ ```text
1306
+ {{HIDE-SLIDE projects.length <= 2}}
1307
+ ```
1308
+
1309
+ ```ts
1310
+ import fs from 'fs';
1311
+ import { renderDeck } from 'pptx-templates';
1312
+
1313
+ const projects = [{ name: 'Portal' }, { name: 'App' }];
1314
+
1315
+ // The slide with the tag in its notes is not in the output
1316
+ fs.writeFileSync(
1317
+ 'output/Projects.pptx',
1318
+ await renderDeck('templates/Projects.pptx', { projects }),
1319
+ );
1320
+ ```
1321
+
1322
+ The condition is an [expression](https://daborsten.github.io/pptx-templates/template-logic.md#expressions) like the
1323
+ one of `{{IF …}}`, with the data, `additionalJsContext` and the options of
1324
+ the render (`strict`, `fixSmartQuotes`, other delimiters, `errorHandler`).
1325
+ `pptx-templates render` on the command line does the same.
1326
+
1327
+ - `{{HIDE-SLIDE}}` without a condition always hides the slide, for example
1328
+ a slide that is still being worked on.
1329
+ - With several tags in the notes, the slide is left out as soon as one of
1330
+ them is true.
1331
+ - The tags are removed from the notes of the output; the rest of the notes
1332
+ stays. A paragraph that held nothing but the tag goes as well.
1333
+ - When every slide is hidden, the output has no slides.
1334
+
1335
+ ### Why the speaker notes
1336
+
1337
+ The tag decides about the whole slide, not about a piece of text, so it
1338
+ belongs to the slide once. The notes exist once per slide and are not part
1339
+ of the design. On the slide itself, in a text box or a table,
1340
+ `{{HIDE-SLIDE …}}` is removed with a warning and does nothing; the
1341
+ [linter](https://daborsten.github.io/pptx-templates/template-lint.md) reports it there as `unsupported-location`.
1342
+ Other tags in the notes are not rendered and stay as they are.
1343
+
1344
+ ### Copies of a flow() slide
1345
+
1346
+ A slide whose [`flow()`](https://daborsten.github.io/pptx-templates/text-flow.md) list needs more than one slide is
1347
+ repeated by `renderDeck`. The condition is evaluated for each copy, with
1348
+ `flowPage` (1, 2, …) and `flowPages`:
1349
+
1350
+ ```text
1351
+ {{HIDE-SLIDE flowPage > 3}}
1352
+ ```
1353
+
1354
+ keeps the first three copies of the slide and leaves out the rest.
1355
+
1356
+ ### With addSlide
1357
+
1358
+ `renderTemplate` renders one slide and cannot take it out of the deck.
1359
+ With your own `addSlide` calls, ask `isSlideHidden` first and skip the
1360
+ slide:
1361
+
1362
+ ```ts
1363
+ import { isSlideHidden, modify } from 'pptx-templates';
1364
+
1365
+ const data = { projects: [{ name: 'Portal' }] };
1366
+
1367
+ if (!(await isSlideHidden('templates/Projects.pptx', 2, data))) {
1368
+ pres.addSlide('Projects.pptx', 2, (slide) => {
1369
+ slide.modify(modify.renderTemplate(data));
1370
+ });
1371
+ }
1372
+ ```
1373
+
1374
+ It takes the options of `renderTemplate`, plus `flowPage` (0-based) and
1375
+ `flowPages` for a condition that depends on them. `addSlide` copies the
1376
+ notes as they are, tag included.
1377
+
1378
+ ### Good to know
1379
+
1380
+ - An error in the condition rejects `renderDeck` with a
1381
+ `TemplateRenderError` that starts with the slide number
1382
+ (`slide 2: {{HIDE-SLIDE check()}}: …`), unless `errorHandler` returns a
1383
+ value for it.
1384
+ - The tag must be in one paragraph of the notes. PowerPoint may split it
1385
+ into several runs (spell check); that is fine.
1386
+ - `flow()` and `flowRest()` in the condition do not distribute anything:
1387
+ `flow(list)` is the whole list there.
1388
+
1012
1389
  ## Shape Geometry
1013
1390
 
1014
1391
  Every shape and picture in PowerPoint has a geometry: a rectangle, an
@@ -1235,7 +1612,7 @@ npx pptx-templates lint --config other.json
1235
1612
  | `unmatched-tag` | error | `END-IF`, `END-FOR`, `ELSE`, `ELSE-IF` without an opening tag, or an `ELSE` after `ELSE` |
1236
1613
  | `unknown-alias` | error | `{{*name}}` without `{{ALIAS name …}}` on the slide |
1237
1614
  | `unsupported-location` | error | `IMAGE` in a table cell, `IMAGE` in a placeholder that inherits its position from the layout, `ELSE` that spans table rows |
1238
- | `unsupported-location` | warning | Tags in slide layouts, masters, speaker notes, charts and SmartArt. `renderTemplate` does not render them, so they stay as they are |
1615
+ | `unsupported-location` | warning | Tags in slide layouts, masters, speaker notes, charts and SmartArt. `renderTemplate` does not render them, so they stay as they are. `{{HIDE-SLIDE …}}` belongs into the speaker notes (checked there like any expression) and is reported everywhere else |
1239
1616
  | `unknown-variable` | warning | A name that is not in `data`/`schema`/`additionalJsContext` and not defined by `FOR`, `EXEC` or an arrow function |
1240
1617
  | `unknown-property` | warning | A property path that does not exist, including methods: `user.name.lenght` on a string |
1241
1618
  | `not-a-list` | warning | `FOR` over a value that is not a list in the data |
package/CHANGELOG.md CHANGED
@@ -6,6 +6,67 @@ semver, with the pre-1.0 convention that **breaking changes bump the minor**.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.3.6] - 2026-11-17
10
+
11
+ ### Added
12
+
13
+ - `{{HIDE-SLIDE condition}}` in the speaker notes of a slide: `renderDeck`
14
+ (and `pptx-templates render`) leaves the slide out when the condition is
15
+ true. Without a condition the slide is always left out; with several tags,
16
+ one true condition is enough. For the copies of a `flow()` slide the
17
+ condition is evaluated per copy, with `flowPage` and `flowPages`. The tag
18
+ is removed from the notes of the output. On the slide itself the tag is
19
+ removed with a warning and does nothing.
20
+ - `isSlideHidden(pptx, slide, data, options)` tells `addSlide` users
21
+ whether to skip a slide.
22
+ - `flowContinue(list)`: the entries of `list` that `flow()` does not show on
23
+ the slides before it in `renderDeck`, hidden copies not counted. A slide
24
+ with `flow(flowContinue(projects), 1)` goes on where an earlier slide's
25
+ `flow(projects)` stopped.
26
+ - The linter checks `{{HIDE-SLIDE …}}` in the speaker notes like any
27
+ expression (syntax, unknown names) and reports it as
28
+ `unsupported-location` anywhere else. `listTemplateCommands` lists it
29
+ with the type `HIDE-SLIDE`.
30
+
31
+ ## [0.3.5] - 2026-11-16
32
+
33
+ ### Added
34
+
35
+ - `flow(list)` in templates: the entries of a list flow through several
36
+ text boxes, column by column. Every box holds the same
37
+ `{{FOR item IN flow(items)}} … {{END-FOR}}`; the boxes are filled in
38
+ reading order, and an entry is never split between two boxes. How much
39
+ fits is measured, not estimated: each entry is rendered into a copy of
40
+ each box and broken into lines with the advance widths from the font
41
+ files, with the box's size and margins and the paragraphs' fonts, sizes,
42
+ spacing, indents and bullets, also where they are inherited from the
43
+ layout, master and theme. Fonts come from the system font folders and
44
+ the new `fonts` option; metric-compatible fonts stand in for missing
45
+ ones (Liberation Sans for Arial, Carlito for Calibri, …).
46
+ A list longer than the boxes continues on copies of the slide:
47
+ `renderDeck` and `pptx-templates render` add them by themselves; with
48
+ `addSlide`, `countFlowPages(pptx, slide, data)` tells how many there
49
+ are and the `flowPage` option picks the part each copy shows.
50
+ `flow(items, 1)` puts at most one entry (or any number) into each box.
51
+ `flowPage` and `flowPages` in the template number the copies,
52
+ `flowRest(list)` returns the entries after the current slide. Without
53
+ `flowPage`, entries that need another slide are logged as a warning, or
54
+ rejected with `flowOverflow: 'error'`.
55
+ - `flow()` cards: the flow boxes of a list inside one PowerPoint group show
56
+ the same entries, so an entry can fill several text boxes (a column of a
57
+ CV page with customer, content and period). An entry goes into a card
58
+ only if it fits into every box of it. Cards left empty on the last slide
59
+ are removed with their group. `flow(list, n, { measure: false })`
60
+ distributes by count only, without measuring the text.
61
+ - `flowCache` option with `new FlowCache()`: the copies of a slide share
62
+ one measurement of a `flow()` list instead of measuring it once per copy
63
+ (40 slides of cards: 4 s instead of 110 s). `renderDeck` uses it by
64
+ itself; with `addSlide`, pass one cache to `countFlowPages` and to every
65
+ `flowPage` render of the slide.
66
+ - The linter and `templateDataSkeleton` know `flow()` and `flowRest()`:
67
+ no "unknown variable" for them, and the entries of `flow(items)` are
68
+ traced to `items[]`.
69
+
9
70
  ## [0.3.4] - 2026-11-15
10
71
 
11
72
  ### Added
@@ -253,7 +314,9 @@ for that history.
253
314
  into one `.png` part. The fallback now gets the same placeholder PNG that
254
315
  pptxgenjs 3.12 wrote.
255
316
 
256
- [Unreleased]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.4...HEAD
317
+ [Unreleased]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.6...HEAD
318
+ [0.3.6]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.5...v0.3.6
319
+ [0.3.5]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.4...v0.3.5
257
320
  [0.3.4]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.3...v0.3.4
258
321
  [0.3.3]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.2...v0.3.3
259
322
  [0.3.2]: https://github.com/DaBorsten/pptx-templates/compare/v0.3.1...v0.3.2
package/README.md CHANGED
@@ -139,6 +139,7 @@ third.
139
139
  | `{{HTML expr}}` | Insert HTML as formatted text: bold, italic, lists, links |
140
140
  | `{{LINK expr}}` | Insert a hyperlink, to a URL or to a slide of the output |
141
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 |
142
143
 
143
144
  Expressions are JavaScript without the dangerous parts: property paths,
144
145
  comparisons, `&&`, `||`, `??`, `? :`, arrow functions
@@ -0,0 +1,44 @@
1
+ import JSZip from 'jszip';
2
+ import { XmlDocument } from '../../types/xml-types';
3
+ import type { RenderTemplateOptions, TemplateData } from '../template-logic/types';
4
+ /** One `{{HIDE-SLIDE …}}` of a slide's notes. */
5
+ export type HideSlideCondition = {
6
+ /** The tag as written, e.g. `{{HIDE-SLIDE !projects.length}}`. */
7
+ tag: string;
8
+ /** The condition; empty: always hide. */
9
+ code: string;
10
+ };
11
+ export type IsSlideHiddenOptions = RenderTemplateOptions & {
12
+ /**
13
+ * How many slides the `flow()` lists of the slide need, for `flowPages`
14
+ * in the condition (`countFlowPages`). Default: 1
15
+ */
16
+ flowPages?: number;
17
+ };
18
+ /** Path of the notes part of `ppt/slides/slide<n>.xml`, if it has notes. */
19
+ export declare const notesPartOf: (zip: JSZip, slide: number) => Promise<string | undefined>;
20
+ /** The `{{HIDE-SLIDE …}}` tags in the speaker notes of a slide. */
21
+ export declare const hideSlideConditions: (zip: JSZip, slide: number, options?: RenderTemplateOptions) => Promise<HideSlideCondition[]>;
22
+ /**
23
+ * Whether one of the conditions is true. `page` is 0-based, as the
24
+ * `flowPage` option; the condition sees it 1-based, as in the slide.
25
+ */
26
+ export declare const evaluateHideConditions: (conditions: HideSlideCondition[], data: TemplateData, options: RenderTemplateOptions, page: number, pages: number) => Promise<boolean>;
27
+ /** A TemplateRenderError of a condition, its message led by the slide. */
28
+ export declare const withSlideNumber: (error: unknown, slide: number) => unknown;
29
+ /**
30
+ * Whether `renderDeck` leaves a slide out: one of the `{{HIDE-SLIDE …}}`
31
+ * tags in its speaker notes is true with this data. For slides added with
32
+ * `addSlide`: skip the `addSlide` call when it returns true.
33
+ *
34
+ * @param pptx Path to a .pptx file or its contents.
35
+ * @param slide 1-based number of the slide in the template.
36
+ */
37
+ export declare const isSlideHidden: (pptx: string | Buffer | Uint8Array | ArrayBuffer, slide: number, data: TemplateData, options?: IsSlideHiddenOptions) => Promise<boolean>;
38
+ /**
39
+ * Removes the `{{HIDE-SLIDE …}}` tags from a notes part; a paragraph that
40
+ * held nothing else goes as well. Returns whether anything changed.
41
+ */
42
+ export declare const stripHideSlideTags: (doc: XmlDocument, options?: RenderTemplateOptions) => boolean;
43
+ /** stripHideSlideTags for every notes part of a deck. */
44
+ export declare const stripHideSlideTagsInDeck: (zip: JSZip, options?: RenderTemplateOptions) => Promise<void>;