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
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.runRenderCommand = exports.loadHelpers = exports.RENDER_USAGE = void 0;
16
+ const fs_1 = __importDefault(require("fs"));
17
+ const path_1 = __importDefault(require("path"));
18
+ const cli_1 = require("../template-lint/cli");
19
+ const index_1 = require("./index");
20
+ exports.RENDER_USAGE = `Usage: pptx-templates render <file.pptx> --data <data.json> -o <out.pptx> [options]
21
+
22
+ Fills the {{…}} tags of every slide of a template with the data and writes
23
+ the result as a new .pptx.
24
+
25
+ Options:
26
+ --data <file.json> The data the tags read (required)
27
+ -o, --out <file.pptx> Where to write the result (required)
28
+ --helpers <file.js> A module whose exports the tags can call, such
29
+ as {{euro(price)}}; passed as additionalJsContext.
30
+ It runs as code: only use files you trust
31
+ --image-root <dir> Folder that picture paths in the data are read
32
+ from, as in {"logo": "images/logo.png"} with
33
+ {{IMAGE logo}} (default: the folder of --data)
34
+ --slides <list> Slides to keep, in this order, e.g. 1,3,2
35
+ (default: all)
36
+ --opening-tag <text> Tag start (default: {{)
37
+ --closing-tag <text> Tag end (default: }})
38
+ --fix-smart-quotes Accept typographic quotes from AutoCorrect
39
+ --color / --no-color Force colors on or off
40
+ -h, --help Show this help
41
+
42
+ Exit code: 0 written, 1 a tag failed to render, 2 invalid call or
43
+ unreadable file.`;
44
+ const parseRenderArgs = (args) => {
45
+ const parsed = { options: {}, help: false };
46
+ for (let i = 0; i < args.length; i++) {
47
+ const arg = args[i];
48
+ const value = () => {
49
+ const next = args[++i];
50
+ if (next === undefined)
51
+ throw new Error(`${arg} needs a value`);
52
+ return next;
53
+ };
54
+ switch (arg) {
55
+ case '-h':
56
+ case '--help':
57
+ parsed.help = true;
58
+ break;
59
+ case '--data':
60
+ parsed.dataFile = value();
61
+ break;
62
+ case '-o':
63
+ case '--out':
64
+ parsed.out = value();
65
+ break;
66
+ case '--helpers':
67
+ parsed.helpers = value();
68
+ break;
69
+ case '--image-root':
70
+ parsed.options.imageRoot = value();
71
+ break;
72
+ case '--slides': {
73
+ const list = value()
74
+ .split(',')
75
+ .map((s) => Number(s.trim()));
76
+ if (!list.length || list.some((n) => !Number.isInteger(n) || n < 1)) {
77
+ throw new Error('--slides needs slide numbers like 1,3,2');
78
+ }
79
+ parsed.options.slides = list;
80
+ break;
81
+ }
82
+ case '--opening-tag':
83
+ parsed.options.openingTag = value();
84
+ break;
85
+ case '--closing-tag':
86
+ parsed.options.closingTag = value();
87
+ break;
88
+ case '--fix-smart-quotes':
89
+ parsed.options.fixSmartQuotes = true;
90
+ break;
91
+ case '--color':
92
+ parsed.color = true;
93
+ break;
94
+ case '--no-color':
95
+ parsed.color = false;
96
+ break;
97
+ default:
98
+ if (arg.startsWith('-'))
99
+ throw new Error(`Unknown option ${arg}`);
100
+ if (parsed.file)
101
+ throw new Error('render takes one .pptx file');
102
+ parsed.file = arg;
103
+ }
104
+ }
105
+ return parsed;
106
+ };
107
+ const readData = (file) => {
108
+ let value;
109
+ try {
110
+ value = JSON.parse(fs_1.default.readFileSync(file, 'utf8'));
111
+ }
112
+ catch (error) {
113
+ throw new Error(`Cannot read data ${file}: ${error.message}`, {
114
+ cause: error,
115
+ });
116
+ }
117
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
118
+ throw new Error(`Cannot read data ${file}: expected a JSON object`);
119
+ }
120
+ return value;
121
+ };
122
+ /** The exports of a helpers module: `module.exports`, or its default export. */
123
+ const loadHelpers = (file) => {
124
+ let mod;
125
+ try {
126
+ // eslint-disable-next-line @typescript-eslint/no-require-imports -- the CLI is CommonJS; require() also loads ESM on current Node
127
+ mod = require(path_1.default.resolve(file));
128
+ }
129
+ catch (error) {
130
+ throw new Error(`Cannot load helpers ${file}: ${error.message}`, { cause: error });
131
+ }
132
+ const exports = mod;
133
+ const value = exports && typeof exports.default === 'object' && exports.default
134
+ ? exports.default
135
+ : exports;
136
+ if (!value || typeof value !== 'object') {
137
+ throw new Error(`Cannot load helpers ${file}: it exports no object`);
138
+ }
139
+ return value;
140
+ };
141
+ exports.loadHelpers = loadHelpers;
142
+ /** `pptx-templates render …`; resolves to the exit code. */
143
+ const runRenderCommand = (args, io) => __awaiter(void 0, void 0, void 0, function* () {
144
+ var _a, _b, _c, _d;
145
+ var _e;
146
+ let parsed;
147
+ try {
148
+ parsed = parseRenderArgs(args);
149
+ }
150
+ catch (error) {
151
+ io.stderr(`${error.message}\n\n${exports.RENDER_USAGE}\n`);
152
+ return 2;
153
+ }
154
+ if (parsed.help) {
155
+ io.stdout(`${exports.RENDER_USAGE}\n`);
156
+ return 0;
157
+ }
158
+ const missing = [
159
+ !parsed.file && 'a .pptx file',
160
+ !parsed.dataFile && '--data',
161
+ !parsed.out && '--out',
162
+ ].filter(Boolean);
163
+ if (missing.length) {
164
+ io.stderr(`Missing ${missing.join(', ')}.\n\n${exports.RENDER_USAGE}\n`);
165
+ return 2;
166
+ }
167
+ const color = (_b = (_a = parsed.color) !== null && _a !== void 0 ? _a : io.color) !== null && _b !== void 0 ? _b : false;
168
+ const paint = (fn, text) => color ? fn(text) : text;
169
+ let data;
170
+ let content;
171
+ try {
172
+ data = readData(parsed.dataFile);
173
+ (_c = (_e = parsed.options).imageRoot) !== null && _c !== void 0 ? _c : (_e.imageRoot = path_1.default.dirname(path_1.default.resolve(parsed.dataFile)));
174
+ if (parsed.helpers) {
175
+ parsed.options.additionalJsContext = (0, exports.loadHelpers)(parsed.helpers);
176
+ }
177
+ content = fs_1.default.readFileSync(parsed.file);
178
+ }
179
+ catch (error) {
180
+ io.stderr(`${(0, cli_1.printable)(error.message)}\n`);
181
+ return 2;
182
+ }
183
+ let result;
184
+ try {
185
+ result = yield (0, index_1.renderDeck)(content, data, parsed.options);
186
+ }
187
+ catch (error) {
188
+ const err = error;
189
+ const isTagError = (err === null || err === void 0 ? void 0 : err.name) === 'TemplateRenderError';
190
+ io.stderr(`${paint(cli_1.style.underline, (0, cli_1.printable)(parsed.file))}\n ${paint((t) => cli_1.style.bold(cli_1.style.red(t)), 'error')} ${(0, cli_1.printable)((_d = err === null || err === void 0 ? void 0 : err.message) !== null && _d !== void 0 ? _d : String(error))}\n`);
191
+ return isTagError ? 1 : 2;
192
+ }
193
+ try {
194
+ fs_1.default.mkdirSync(path_1.default.dirname(path_1.default.resolve(parsed.out)), { recursive: true });
195
+ fs_1.default.writeFileSync(parsed.out, result);
196
+ }
197
+ catch (error) {
198
+ io.stderr(`${(0, cli_1.printable)(`Cannot write ${parsed.out}: ${error.message}`)}\n`);
199
+ return 2;
200
+ }
201
+ io.stdout(`${paint(cli_1.style.bold, 'rendered')} ${(0, cli_1.printable)(parsed.out)} ${paint(cli_1.style.dim, `from ${(0, cli_1.printable)(parsed.file)}`)}\n`);
202
+ return 0;
203
+ });
204
+ exports.runRenderCommand = runRenderCommand;
205
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/extensions/template-render/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,8CAA+D;AAC/D,mCAAwD;AAE3C,QAAA,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;iBAuBX,CAAC;AAYlB,MAAM,eAAe,GAAG,CAAC,IAAc,EAAc,EAAE;IACrD,MAAM,MAAM,GAAe,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACxD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,MAAM,KAAK,GAAG,GAAG,EAAE;YACjB,MAAM,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;YACvB,IAAI,IAAI,KAAK,SAAS;gBAAE,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,gBAAgB,CAAC,CAAC;YAChE,OAAO,IAAI,CAAC;QACd,CAAC,CAAC;QACF,QAAQ,GAAG,EAAE,CAAC;YACZ,KAAK,IAAI,CAAC;YACV,KAAK,QAAQ;gBACX,MAAM,CAAC,I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AC,WAAK,CAAC,GAAG,EAAE,QAAQ,IAAA,eAAS,EAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CACtH,CAAC;IACF,OAAO,CAAC,CAAC;AACX,CAAC,CAAA,CAAC;AAnEW,QAAA,gBAAgB,oBAmE3B"}
@@ -0,0 +1,31 @@
1
+ import type { RenderTemplateOptions, TemplateData } from '../template-logic/types';
2
+ export type RenderDeckOptions = RenderTemplateOptions & {
3
+ /**
4
+ * 1-based numbers of the slides to keep, in this order. Default: every
5
+ * slide of the deck, in its order.
6
+ */
7
+ slides?: number[];
8
+ };
9
+ /**
10
+ * How many slides the `flow()` lists of one template slide need with this
11
+ * data: render the slide that many times, with `flowPage: 0`, `1`, ….
12
+ * `renderDeck` does this by itself.
13
+ *
14
+ * @param pptx Path to a .pptx file or its contents.
15
+ * @param slide 1-based number of the slide in the template.
16
+ */
17
+ export declare const countFlowPages: (pptx: string | Buffer | Uint8Array | ArrayBuffer, slide: number, data: TemplateData, options?: RenderTemplateOptions) => Promise<number>;
18
+ /**
19
+ * Renders the tags of every slide of a template with one set of data and
20
+ * returns the new .pptx: `renderTemplate` applied to each slide, the masters
21
+ * and layouts of the template kept as they are.
22
+ *
23
+ * A failing tag rejects with a `TemplateRenderError` whose message starts
24
+ * with the slide number ("slide 2: {{euro(p.preis)}}: Not a function …").
25
+ *
26
+ * A slide whose `flow()` lists do not fit is repeated as often as needed,
27
+ * each copy with the next entries (`flowPage` 1, 2, … in the template).
28
+ *
29
+ * @param pptx Path to a .pptx file or its contents.
30
+ */
31
+ export declare const renderDeck: (pptx: string | Buffer | Uint8Array | ArrayBuffer, data: TemplateData, options?: RenderDeckOptions) => Promise<Buffer>;
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ var __rest = (this && this.__rest) || function (s, e) {
45
+ var t = {};
46
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
47
+ t[p] = s[p];
48
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
49
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
50
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
51
+ t[p[i]] = s[p[i]];
52
+ }
53
+ return t;
54
+ };
55
+ var __importDefault = (this && this.__importDefault) || function (mod) {
56
+ return (mod && mod.__esModule) ? mod : { "default": mod };
57
+ };
58
+ Object.defineProperty(exports, "__esModule", { value: true });
59
+ exports.renderDeck = exports.countFlowPages = void 0;
60
+ const fs_1 = __importDefault(require("fs"));
61
+ const jszip_1 = __importDefault(require("jszip"));
62
+ const text_flow_1 = require("../text-flow");
63
+ const toBuffer = (pptx) => Buffer.isBuffer(pptx)
64
+ ? pptx
65
+ : pptx instanceof ArrayBuffer
66
+ ? Buffer.from(pptx)
67
+ : Buffer.from(pptx.buffer, pptx.byteOffset, pptx.byteLength);
68
+ const loadContent = (pptx) => __awaiter(void 0, void 0, void 0, function* () { return typeof pptx === 'string' ? fs_1.default.promises.readFile(pptx) : toBuffer(pptx); });
69
+ /** Renders `slides` of a deck into a new deck (renderDeck's engine). */
70
+ const buildDeck = (content, data, renderOptions, select) => __awaiter(void 0, void 0, void 0, function* () {
71
+ // Loaded here, through the package entry: upstream helpers import
72
+ // src/index.ts, so loading automizer.ts or the template logic first (as
73
+ // the CLI does) breaks on the import cycle
74
+ const { default: Automizer, CallbackError, modify, TemplateRenderError, } = yield Promise.resolve().then(() => __importStar(require('../../index')));
75
+ const pres = new Automizer({
76
+ removeExistingSlides: true,
77
+ // drops the template's own slides from the archive, not only the list
78
+ cleanup: true,
79
+ verbosity: 0,
80
+ })
81
+ .loadRoot(content)
82
+ .load(content, 'deck');
83
+ const available = yield pres.getTemplate('deck').getAllSlideNumbers();
84
+ const slides = yield select(available);
85
+ const missing = slides
86
+ .map((s) => s.number)
87
+ .filter((n) => !available.includes(n));
88
+ if (missing.length) {
89
+ throw new Error(`The deck has no slide ${missing.join(', ')} (slides: ${available.join(', ')})`);
90
+ }
91
+ for (const { number, page, flowCache } of slides) {
92
+ pres.addSlide('deck', number, (slide) => {
93
+ const render = modify.renderTemplate(data, Object.assign(Object.assign(Object.assign({}, renderOptions), (flowCache ? { flowCache } : {})), (page === undefined ? {} : { flowPage: page })));
94
+ slide.modify((document, context) => __awaiter(void 0, void 0, void 0, function* () {
95
+ try {
96
+ yield render(document, context);
97
+ }
98
+ catch (error) {
99
+ const message = error instanceof Error ? error.message : String(error);
100
+ throw new TemplateRenderError(`slide ${number}: ${message}`);
101
+ }
102
+ }));
103
+ });
104
+ }
105
+ try {
106
+ const zip = yield pres.getJSZip();
107
+ return yield zip.generateAsync({
108
+ type: 'nodebuffer',
109
+ compression: 'DEFLATE',
110
+ });
111
+ }
112
+ catch (error) {
113
+ // Automizer wraps callback errors; the tag error is what users need
114
+ if (error instanceof CallbackError && error.cause instanceof Error) {
115
+ throw error.cause;
116
+ }
117
+ throw error;
118
+ }
119
+ });
120
+ /** Whether a slide of the deck calls flow() (cheap text check). */
121
+ const usesFlow = (content, number) => __awaiter(void 0, void 0, void 0, function* () {
122
+ var _a;
123
+ const zip = yield jszip_1.default.loadAsync(content);
124
+ const xml = yield ((_a = zip.file(`ppt/slides/slide${number}.xml`)) === null || _a === void 0 ? void 0 : _a.async('string'));
125
+ if (!xml)
126
+ return false;
127
+ // Runs joined: a tag can be split across several a:t
128
+ const text = [...xml.matchAll(/<a:t(?:\s[^>]*)?>([^<]*)<\/a:t>/g)]
129
+ .map((m) => m[1])
130
+ .join('');
131
+ return /flow\s*\(/.test(text);
132
+ });
133
+ /**
134
+ * How many slides the `flow()` lists of one template slide need with this
135
+ * data: render the slide that many times, with `flowPage: 0`, `1`, ….
136
+ * `renderDeck` does this by itself.
137
+ *
138
+ * @param pptx Path to a .pptx file or its contents.
139
+ * @param slide 1-based number of the slide in the template.
140
+ */
141
+ const countFlowPages = (pptx_1, slide_1, data_1, ...args_1) => __awaiter(void 0, [pptx_1, slide_1, data_1, ...args_1], void 0, function* (pptx, slide, data, options = {}) {
142
+ const content = yield loadContent(pptx);
143
+ if (!(yield usesFlow(content, slide)))
144
+ return 1;
145
+ let pages = 1;
146
+ yield buildDeck(content, data, Object.assign(Object.assign({}, options), {
147
+ // the overflow is what is being counted, not an error
148
+ flowOverflow: 'warn', flowPage: Number.MAX_SAFE_INTEGER, onFlowPages: (count) => (pages = Math.max(pages, count)) }), () => [{ number: slide }]);
149
+ return pages;
150
+ });
151
+ exports.countFlowPages = countFlowPages;
152
+ /**
153
+ * Renders the tags of every slide of a template with one set of data and
154
+ * returns the new .pptx: `renderTemplate` applied to each slide, the masters
155
+ * and layouts of the template kept as they are.
156
+ *
157
+ * A failing tag rejects with a `TemplateRenderError` whose message starts
158
+ * with the slide number ("slide 2: {{euro(p.preis)}}: Not a function …").
159
+ *
160
+ * A slide whose `flow()` lists do not fit is repeated as often as needed,
161
+ * each copy with the next entries (`flowPage` 1, 2, … in the template).
162
+ *
163
+ * @param pptx Path to a .pptx file or its contents.
164
+ */
165
+ const renderDeck = (pptx_1, data_1, ...args_1) => __awaiter(void 0, [pptx_1, data_1, ...args_1], void 0, function* (pptx, data, options = {}) {
166
+ const { slides } = options, renderOptions = __rest(options, ["slides"]);
167
+ const content = yield loadContent(pptx);
168
+ return buildDeck(content, data, renderOptions, (available) => __awaiter(void 0, void 0, void 0, function* () {
169
+ const result = [];
170
+ // The copies of a slide share the measurement of its lists
171
+ const caches = new Map();
172
+ for (const number of slides !== null && slides !== void 0 ? slides : available) {
173
+ if (!caches.has(number))
174
+ caches.set(number, new text_flow_1.FlowCache());
175
+ const flowCache = caches.get(number);
176
+ // a slide whose flow() lists need more room repeats
177
+ const pages = available.includes(number) && renderOptions.flowPage === undefined
178
+ ? yield (0, exports.countFlowPages)(content, number, data, Object.assign(Object.assign({}, renderOptions), { flowCache }))
179
+ : 1;
180
+ for (let page = 0; page < pages; page++) {
181
+ result.push({
182
+ number,
183
+ page: pages > 1 ? page : undefined,
184
+ flowCache,
185
+ });
186
+ }
187
+ }
188
+ return result;
189
+ }));
190
+ });
191
+ exports.renderDeck = renderDeck;
192
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/template-render/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,kDAA0B;AAK1B,4CAAyC;AAUzC,MAAM,QAAQ,GAAG,CAAC,IAAuC,EAAU,EAAE,CACnE,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;IACnB,CAAC,CAAC,IAAI;IACN,CAAC,CAAC,IAAI,YAAY,WAAW;QAC3B,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;QACnB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;AAInE,MAAM,WAAW,GAAG,CAClB,IAAgD,EAC/B,EAAE,kDACnB,OAAA,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA,GAAA,CAAC;AAEzE,wEAAwE;AACxE,MAAM,SAAS,GAAG,CAChB,OAAe,EACf,IAAkB,EAClB,aAAoC,EACpC,MAAmE,EAClD,EAAE;IACnB,kEAAkE;IAClE,wEAAwE;IACxE,2CAA2C;IAC3C,MAAM,EACJ,OAAO,EAAE,SAAS,EAClB,aAAa,EACb,MAAM,EACN,mBAAmB,GACpB,GAAG,wDAAa,aAAa,GAAC,CAAC;IAChC,MAAM,IAAI,GAAG,IAAI,SAAS,CAAC;QACzB,oBAAoB,EAAE,IAAI;QAC1B,sEAAsE;QACtE,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,CAAC;KACb,CAAC;SACC,QAAQ,CAAC,OAAO,CAAC;SACjB,IAAI,CAAC,OAAO,EAAE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M,MAAM,IAAI,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,SAAS,EAAE,CAAC;YACzC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;gBAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,qBAAS,EAAE,CAAC,CAAC;YAC7D,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACrC,oDAAoD;YACpD,MAAM,KAAK,GACT,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,aAAa,CAAC,QAAQ,KAAK,SAAS;gBAChE,CAAC,CAAC,MAAM,IAAA,sBAAc,EAAC,OAAO,EAAE,MAAM,EAAE,IAAI,kCACrC,aAAa,KAChB,SAAS,IACT;gBACJ,CAAC,CAAC,CAAC,CAAC;YACR,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC;gBACxC,MAAM,CAAC,IAAI,CAAC;oBACV,MAAM;oBACN,IAAI,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;oBAClC,SAAS;iBACV,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAA,CAAC;AAhCW,QAAA,UAAU,cAgCrB"}
@@ -0,0 +1,128 @@
1
+ import { XmlElement } from '../../types/xml-types';
2
+ import { SlideStyles } from './styles';
3
+ /** What the template renderer provides to `flow()`. */
4
+ export type FlowHost = {
5
+ /**
6
+ * Renders a detached copy of a text body in which `flow()` returns
7
+ * `entries`, without side effects on the slide; returns its paragraphs.
8
+ */
9
+ renderCopy(body: XmlElement, entries: unknown[]): Promise<XmlElement[]>;
10
+ /** Layout, master, theme and presentation defaults of the slide. */
11
+ styles(): Promise<SlideStyles>;
12
+ };
13
+ export type FlowOptions = {
14
+ /** Font files or folders, searched before the system fonts. */
15
+ fonts?: string[];
16
+ /** Entries that fit nowhere: log a warning (default) or throw. */
17
+ flowOverflow?: 'warn' | 'error';
18
+ /**
19
+ * 0-based: which of the slides the list needs is rendered. Without it,
20
+ * the first one, and entries that need more slides count as overflow.
21
+ */
22
+ flowPage?: number;
23
+ /** Called with the number of slides the lists of the slide need. */
24
+ onFlowPages?: (pages: number) => void;
25
+ /** Keeps the distribution for the other copies of the slide. */
26
+ flowCache?: FlowCache;
27
+ };
28
+ /**
29
+ * Where the entries of a list go. It names a box by its position among the
30
+ * flow boxes of the slide, so it holds for every copy of the slide.
31
+ */
32
+ export type FlowPlan = {
33
+ list: unknown[];
34
+ /** Per slide (page): the entries of each box. */
35
+ pages: Map<number, number[]>[];
36
+ /** Per page: the index of the first entry after it. */
37
+ ends: number[];
38
+ /** Names of the boxes, for messages. */
39
+ names: string[];
40
+ };
41
+ /**
42
+ * Measuring a list takes most of the time of `flow()`. A cache passed as
43
+ * `flowCache` to every render of one template slide (`countFlowPages` and
44
+ * the `flowPage` copies) lets them share one measurement. A render whose
45
+ * boxes, limits, text around the loop or list differ measures again. Use
46
+ * one cache per template slide and set of data.
47
+ */
48
+ export declare class FlowCache {
49
+ /** @internal */
50
+ readonly plans: Map<string, FlowPlan>;
51
+ }
52
+ /** A `flow(…)` call: its argument as written, and without whitespace. */
53
+ export type FlowCall = {
54
+ source: string;
55
+ key: string;
56
+ /** Source of the second argument: at most this many entries per box. */
57
+ limit?: string;
58
+ /** Source of the third argument, such as `{ measure: false }`. */
59
+ options?: string;
60
+ };
61
+ /** Calls of `flow(…)` (or `flowRest(…)`) in a text. */
62
+ export declare const flowArguments: (text: string, name?: string) => FlowCall[];
63
+ /**
64
+ * Distributes the entries of a list over the text boxes that call
65
+ * `flow(list)`: the boxes are filled in reading order (left to right, then
66
+ * top to bottom), each entry goes as a whole into the first box that still
67
+ * has room for it. Heights are measured with the fonts' real metrics.
68
+ */
69
+ export declare class TextFlow {
70
+ private readonly host;
71
+ private readonly options;
72
+ /** Flow boxes (their p:txBody) and the source of their flow() argument. */
73
+ private readonly keys;
74
+ /** Position of each flow box among the flow boxes of the slide. */
75
+ private readonly indexes;
76
+ /** Each box as it is in the template: its shape and the groups around. */
77
+ private readonly fingerprints;
78
+ private readonly plans;
79
+ private readonly resolved;
80
+ private readonly fonts;
81
+ private readonly serializer;
82
+ constructor(boxes: Map<XmlElement, string>, host: FlowHost, options?: FlowOptions);
83
+ /** The sources of the flow() lists, one per group of boxes. */
84
+ groups(): string[];
85
+ /**
86
+ * Computes where the entries of `list` go, for the boxes of `flow(key)`.
87
+ * A `flowRest()` list that is no group's falls back to the only group.
88
+ * Must be awaited before `entries()`/`rest()`, which are synchronous.
89
+ */
90
+ prepare(key: string, list: unknown, limits?: Map<import("@xmldom/xmldom").Element, number>,
91
+ /** Boxes of `flow(list, n, { measure: false })`. */
92
+ unmeasured?: Set<import("@xmldom/xmldom").Element>): Promise<void>;
93
+ /** The entries of `list` that go into the text box `body`. */
94
+ entries(body: XmlElement | undefined, list: unknown): unknown[];
95
+ /**
96
+ * The entries of `list` after the rendered slide: on the next slides, or
97
+ * in none (they fit into no box).
98
+ */
99
+ rest(list: unknown): unknown[];
100
+ /** How many slides the lists need (the longest one counts). */
101
+ get pages(): number;
102
+ /**
103
+ * Cards (PowerPoint groups with flow boxes) that stay empty on the
104
+ * rendered slide, such as the last columns of the last slide.
105
+ */
106
+ emptyGroups(): XmlElement[];
107
+ private get page();
108
+ private toList;
109
+ private bodiesOf;
110
+ /** The shape of a box and the transforms of the groups around it. */
111
+ private fingerprint;
112
+ /**
113
+ * The plan of a list: from the cache if another copy of the slide has
114
+ * distributed the same entries over the same boxes, else computed.
115
+ */
116
+ private plan;
117
+ private computePlan;
118
+ /** Entries this render leaves out: a warning, or an error. */
119
+ private reportOverflow;
120
+ /**
121
+ * The slots in reading order: left to right, of slots on top of each
122
+ * other the upper one first. Boxes in one group form one slot.
123
+ */
124
+ private slotsOf;
125
+ /** A box of `{ measure: false }`: only its position counts. */
126
+ private unmeasuredBox;
127
+ private measureBox;
128
+ }