pptx-templates 0.3.8 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AI-INSTRUCTOR.md +91 -2
- package/CHANGELOG.md +125 -1
- package/dist/automizer.js +143 -176
- package/dist/automizer.js.map +1 -1
- package/dist/classes/content-type-registry.js +23 -36
- package/dist/classes/content-type-registry.js.map +1 -1
- package/dist/classes/element-importer.js +129 -148
- package/dist/classes/element-importer.js.map +1 -1
- package/dist/classes/has-shapes.js +81 -126
- package/dist/classes/has-shapes.js.map +1 -1
- package/dist/classes/layout.js +47 -67
- package/dist/classes/layout.js.map +1 -1
- package/dist/classes/master.js +70 -89
- package/dist/classes/master.js.map +1 -1
- package/dist/classes/placeholder-normalizer.js +48 -37
- package/dist/classes/placeholder-normalizer.js.map +1 -1
- package/dist/classes/related-content-copier.js +65 -86
- package/dist/classes/related-content-copier.js.map +1 -1
- package/dist/classes/shape.js +79 -110
- package/dist/classes/shape.js.map +1 -1
- package/dist/classes/slide-master-remover.js +108 -130
- package/dist/classes/slide-master-remover.js.map +1 -1
- package/dist/classes/slide-notes-copier.js +24 -41
- package/dist/classes/slide-notes-copier.js.map +1 -1
- package/dist/classes/slide.js +112 -141
- package/dist/classes/slide.js.map +1 -1
- package/dist/classes/template.js +82 -117
- package/dist/classes/template.js.map +1 -1
- package/dist/errors.js +5 -5
- package/dist/errors.js.map +1 -1
- package/dist/extensions/cli/index.js +3 -13
- package/dist/extensions/cli/index.js.map +1 -1
- package/dist/extensions/hide-slide/index.js +48 -46
- package/dist/extensions/hide-slide/index.js.map +1 -1
- package/dist/extensions/master-parts/index.js +36 -49
- package/dist/extensions/master-parts/index.js.map +1 -1
- package/dist/extensions/pptxgenjs-compat/svg-fallback.js +56 -70
- package/dist/extensions/pptxgenjs-compat/svg-fallback.js.map +1 -1
- package/dist/extensions/regexp-escape/index.d.ts +10 -0
- package/dist/extensions/regexp-escape/index.js +15 -0
- package/dist/extensions/regexp-escape/index.js.map +1 -0
- package/dist/extensions/run-merge/index.js +4 -5
- package/dist/extensions/run-merge/index.js.map +1 -1
- package/dist/extensions/shape-geometry/index.d.ts +2 -0
- package/dist/extensions/shape-geometry/index.js +13 -13
- package/dist/extensions/shape-geometry/index.js.map +1 -1
- package/dist/extensions/template-lint/cli.js +49 -41
- package/dist/extensions/template-lint/cli.js.map +1 -1
- package/dist/extensions/template-lint/config.js +18 -10
- package/dist/extensions/template-lint/config.js.map +1 -1
- package/dist/extensions/template-lint/data-model.js +17 -20
- package/dist/extensions/template-lint/data-model.js.map +1 -1
- package/dist/extensions/template-lint/init-cli.js +12 -17
- package/dist/extensions/template-lint/init-cli.js.map +1 -1
- package/dist/extensions/template-lint/lint.js +195 -62
- package/dist/extensions/template-lint/lint.js.map +1 -1
- package/dist/extensions/template-lint/skeleton.js +5 -6
- package/dist/extensions/template-lint/skeleton.js.map +1 -1
- package/dist/extensions/template-lint/usage-cli.js +10 -14
- package/dist/extensions/template-lint/usage-cli.js.map +1 -1
- package/dist/extensions/template-lint/usage.js +8 -9
- package/dist/extensions/template-lint/usage.js.map +1 -1
- package/dist/extensions/template-logic/clone.d.ts +2 -16
- package/dist/extensions/template-logic/clone.js +15 -90
- package/dist/extensions/template-logic/clone.js.map +1 -1
- package/dist/extensions/template-logic/commands.d.ts +8 -0
- package/dist/extensions/template-logic/commands.js +21 -12
- package/dist/extensions/template-logic/commands.js.map +1 -1
- package/dist/extensions/template-logic/expression.d.ts +6 -0
- package/dist/extensions/template-logic/expression.js +56 -54
- package/dist/extensions/template-logic/expression.js.map +1 -1
- package/dist/extensions/template-logic/images.d.ts +14 -0
- package/dist/extensions/template-logic/images.js +277 -49
- package/dist/extensions/template-logic/images.js.map +1 -1
- package/dist/extensions/template-logic/index.js +20 -27
- package/dist/extensions/template-logic/index.js.map +1 -1
- package/dist/extensions/template-logic/list-commands.js +31 -16
- package/dist/extensions/template-logic/list-commands.js.map +1 -1
- package/dist/extensions/template-logic/renderer.d.ts +24 -0
- package/dist/extensions/template-logic/renderer.js +505 -380
- package/dist/extensions/template-logic/renderer.js.map +1 -1
- package/dist/extensions/template-logic/types.d.ts +5 -0
- package/dist/extensions/template-logic/types.js +6 -0
- package/dist/extensions/template-logic/types.js.map +1 -1
- package/dist/extensions/template-render/cli.js +7 -18
- package/dist/extensions/template-render/cli.js.map +1 -1
- package/dist/extensions/template-render/index.js +152 -107
- package/dist/extensions/template-render/index.js.map +1 -1
- package/dist/extensions/template-render/prune.d.ts +14 -0
- package/dist/extensions/template-render/prune.js +131 -0
- package/dist/extensions/template-render/prune.js.map +1 -0
- package/dist/extensions/template-render/zip-text.d.ts +9 -0
- package/dist/extensions/template-render/zip-text.js +27 -0
- package/dist/extensions/template-render/zip-text.js.map +1 -0
- package/dist/extensions/template-render/zip-writer.d.ts +16 -0
- package/dist/extensions/template-render/zip-writer.js +151 -0
- package/dist/extensions/template-render/zip-writer.js.map +1 -0
- package/dist/extensions/text-flow/flow.d.ts +5 -0
- package/dist/extensions/text-flow/flow.js +196 -207
- package/dist/extensions/text-flow/flow.js.map +1 -1
- package/dist/extensions/text-flow/font-file.js +9 -7
- package/dist/extensions/text-flow/font-file.js.map +1 -1
- package/dist/extensions/text-flow/fonts.d.ts +4 -0
- package/dist/extensions/text-flow/fonts.js +45 -22
- package/dist/extensions/text-flow/fonts.js.map +1 -1
- package/dist/extensions/text-flow/layout.js +5 -6
- package/dist/extensions/text-flow/layout.js.map +1 -1
- package/dist/extensions/text-flow/slide-styles.js +18 -22
- package/dist/extensions/text-flow/slide-styles.js.map +1 -1
- package/dist/extensions/text-flow/styles.d.ts +11 -0
- package/dist/extensions/text-flow/styles.js +121 -62
- package/dist/extensions/text-flow/styles.js.map +1 -1
- package/dist/helper/archive/archive-fs.js +102 -138
- package/dist/helper/archive/archive-fs.js.map +1 -1
- package/dist/helper/archive/archive-jszip.js +101 -125
- package/dist/helper/archive/archive-jszip.js.map +1 -1
- package/dist/helper/archive/archive.d.ts +6 -0
- package/dist/helper/archive/archive.js +21 -30
- package/dist/helper/archive/archive.js.map +1 -1
- package/dist/helper/archive/jszip-fast-read.d.ts +19 -0
- package/dist/helper/archive/jszip-fast-read.js +153 -0
- package/dist/helper/archive/jszip-fast-read.js.map +1 -0
- package/dist/helper/compute-src-rect.js +4 -5
- package/dist/helper/compute-src-rect.js.map +1 -1
- package/dist/helper/content-tracker.js +86 -114
- package/dist/helper/content-tracker.js.map +1 -1
- package/dist/helper/count-helper.js +48 -78
- package/dist/helper/count-helper.js.map +1 -1
- package/dist/helper/css-style-parser.js +1 -2
- package/dist/helper/css-style-parser.js.map +1 -1
- package/dist/helper/file-helper.js +30 -48
- package/dist/helper/file-helper.js.map +1 -1
- package/dist/helper/generate/generate-pptxgenjs.js +36 -48
- package/dist/helper/generate/generate-pptxgenjs.js.map +1 -1
- package/dist/helper/html-to-multitext-helper.js +34 -18
- package/dist/helper/html-to-multitext-helper.js.map +1 -1
- package/dist/helper/hyperlink-processor.js +125 -139
- package/dist/helper/hyperlink-processor.js.map +1 -1
- package/dist/helper/jszip-helper.js +23 -32
- package/dist/helper/jszip-helper.js.map +1 -1
- package/dist/helper/layout-index.js +51 -71
- package/dist/helper/layout-index.js.map +1 -1
- package/dist/helper/logger.js +4 -4
- package/dist/helper/logger.js.map +1 -1
- package/dist/helper/media-deduplicator.d.ts +24 -0
- package/dist/helper/media-deduplicator.js +81 -34
- package/dist/helper/media-deduplicator.js.map +1 -1
- package/dist/helper/modify-background-helper.js +46 -46
- package/dist/helper/modify-background-helper.js.map +1 -1
- package/dist/helper/modify-chart-helper.js +597 -591
- package/dist/helper/modify-chart-helper.js.map +1 -1
- package/dist/helper/modify-cleanup-helper.js +112 -112
- package/dist/helper/modify-cleanup-helper.js.map +1 -1
- package/dist/helper/modify-color-helper.js +53 -53
- package/dist/helper/modify-color-helper.js.map +1 -1
- package/dist/helper/modify-helper.js +25 -25
- package/dist/helper/modify-helper.js.map +1 -1
- package/dist/helper/modify-hyperlink-helper.js +143 -154
- package/dist/helper/modify-hyperlink-helper.js.map +1 -1
- package/dist/helper/modify-image-helper.js +121 -132
- package/dist/helper/modify-image-helper.js.map +1 -1
- package/dist/helper/modify-presentation-helper.js +137 -154
- package/dist/helper/modify-presentation-helper.js.map +1 -1
- package/dist/helper/modify-shape-helper.js +262 -262
- package/dist/helper/modify-shape-helper.js.map +1 -1
- package/dist/helper/modify-table-helper.js +84 -84
- package/dist/helper/modify-table-helper.js.map +1 -1
- package/dist/helper/modify-text-helper.js +187 -189
- package/dist/helper/modify-text-helper.js.map +1 -1
- package/dist/helper/modify-xml-helper.js +36 -36
- package/dist/helper/modify-xml-helper.js.map +1 -1
- package/dist/helper/multitext-helper.js +9 -7
- package/dist/helper/multitext-helper.js.map +1 -1
- package/dist/helper/ppt-paths.js +17 -17
- package/dist/helper/ppt-paths.js.map +1 -1
- package/dist/helper/shape-type-detector.js +18 -29
- package/dist/helper/shape-type-detector.js.map +1 -1
- package/dist/helper/text-replace-helper.js +6 -7
- package/dist/helper/text-replace-helper.js.map +1 -1
- package/dist/helper/xml-clone.d.ts +24 -0
- package/dist/helper/xml-clone.js +269 -0
- package/dist/helper/xml-clone.js.map +1 -0
- package/dist/helper/xml-elements.js +17 -20
- package/dist/helper/xml-elements.js.map +1 -1
- package/dist/helper/xml-find.d.ts +4 -0
- package/dist/helper/xml-find.js +48 -0
- package/dist/helper/xml-find.js.map +1 -0
- package/dist/helper/xml-helper.js +99 -134
- package/dist/helper/xml-helper.js.map +1 -1
- package/dist/helper/xml-parse-cache.d.ts +31 -0
- package/dist/helper/xml-parse-cache.js +71 -0
- package/dist/helper/xml-parse-cache.js.map +1 -0
- package/dist/helper/xml-placeholder-helper.js +10 -10
- package/dist/helper/xml-placeholder-helper.js.map +1 -1
- package/dist/helper/xml-relationship-helper.js +120 -144
- package/dist/helper/xml-relationship-helper.js.map +1 -1
- package/dist/helper/xml-serializer.d.ts +2 -0
- package/dist/helper/xml-serializer.js +192 -0
- package/dist/helper/xml-serializer.js.map +1 -0
- package/dist/helper/xml-slide-helper.js +109 -129
- package/dist/helper/xml-slide-helper.js.map +1 -1
- package/dist/helper/xml-template-helper.js +120 -144
- package/dist/helper/xml-template-helper.js.map +1 -1
- package/dist/helper/xmldom-sax-patch.js +52 -2
- package/dist/helper/xmldom-sax-patch.js.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/modify/modify-chart.js +35 -23
- package/dist/modify/modify-chart.js.map +1 -1
- package/dist/modify/modify-table.js +11 -14
- package/dist/modify/modify-table.js.map +1 -1
- package/dist/shapes/chart.js +238 -287
- package/dist/shapes/chart.js.map +1 -1
- package/dist/shapes/diagram.js +73 -104
- package/dist/shapes/diagram.js.map +1 -1
- package/dist/shapes/generic.js +62 -83
- package/dist/shapes/generic.js.map +1 -1
- package/dist/shapes/hyperlink.js +98 -124
- package/dist/shapes/hyperlink.js.map +1 -1
- package/dist/shapes/image.js +112 -151
- package/dist/shapes/image.js.map +1 -1
- package/dist/shapes/ole.js +148 -188
- package/dist/shapes/ole.js.map +1 -1
- package/package.json +3 -4
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -146,9 +137,14 @@ const configTargets = (configFile, cli) => {
|
|
|
146
137
|
if (!resolved.jobs.length) {
|
|
147
138
|
throw new Error(`${configFile}: no file matches its patterns`);
|
|
148
139
|
}
|
|
149
|
-
const options =
|
|
150
|
-
|
|
151
|
-
|
|
140
|
+
const options = {
|
|
141
|
+
...(config.openingTag !== undefined && { openingTag: config.openingTag }),
|
|
142
|
+
...(config.closingTag !== undefined && { closingTag: config.closingTag }),
|
|
143
|
+
...(config.fixSmartQuotes !== undefined && {
|
|
144
|
+
fixSmartQuotes: config.fixSmartQuotes,
|
|
145
|
+
}),
|
|
146
|
+
...cli,
|
|
147
|
+
};
|
|
152
148
|
const byData = new Map();
|
|
153
149
|
const notes = [];
|
|
154
150
|
for (const job of resolved.jobs) {
|
|
@@ -165,8 +161,7 @@ const configTargets = (configFile, cli) => {
|
|
|
165
161
|
return { targets: [...byData.values()], notes };
|
|
166
162
|
};
|
|
167
163
|
/** `pptx-templates init …`; resolves to the exit code. */
|
|
168
|
-
const runInitCommand = (args, io) =>
|
|
169
|
-
var _a, _b;
|
|
164
|
+
const runInitCommand = async (args, io) => {
|
|
170
165
|
let parsed;
|
|
171
166
|
try {
|
|
172
167
|
parsed = parseInitArgs(args);
|
|
@@ -188,7 +183,7 @@ const runInitCommand = (args, io) => __awaiter(void 0, void 0, void 0, function*
|
|
|
188
183
|
return 2;
|
|
189
184
|
}
|
|
190
185
|
}
|
|
191
|
-
const color =
|
|
186
|
+
const color = parsed.color ?? io.color ?? false;
|
|
192
187
|
const paint = (fn, text) => color ? fn(text) : text;
|
|
193
188
|
let targets;
|
|
194
189
|
try {
|
|
@@ -212,7 +207,7 @@ const runInitCommand = (args, io) => __awaiter(void 0, void 0, void 0, function*
|
|
|
212
207
|
for (const target of targets) {
|
|
213
208
|
let skeleton;
|
|
214
209
|
try {
|
|
215
|
-
skeleton =
|
|
210
|
+
skeleton = await (0, lint_1.templateDataSkeleton)(target.decks, target.options);
|
|
216
211
|
}
|
|
217
212
|
catch (error) {
|
|
218
213
|
io.stderr(`${(0, cli_1.printable)(`Cannot read ${target.decks.join(', ')}: ${error.message}`)}\n`);
|
|
@@ -239,6 +234,6 @@ const runInitCommand = (args, io) => __awaiter(void 0, void 0, void 0, function*
|
|
|
239
234
|
io.stderr(paint(cli_1.style.yellow, `${errors} tag error(s) skipped; run pptx-templates lint to see them.\n`));
|
|
240
235
|
}
|
|
241
236
|
return 0;
|
|
242
|
-
}
|
|
237
|
+
};
|
|
243
238
|
exports.runInitCommand = runInitCommand;
|
|
244
239
|
//# sourceMappingURL=init-cli.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-cli.js","sourceRoot":"","sources":["../../../src/extensions/template-lint/init-cli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init-cli.js","sourceRoot":"","sources":["../../../src/extensions/template-lint/init-cli.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,+BAAgD;AAChD,qCAAkE;AAClE,iCAA8C;AAC9C,yCAAqE;AAGxD,QAAA,UAAU,GAAG;;;;;;;;;;;;;8BAaI,oBAAW;;;;;;;;;;;sDAWa,CAAC;AAWvD,MAAM,aAAa,GAAG,CAAC,IAAc,EAAY,EAAE;IACjD,MAAM,MAAM,GAAa,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACjE,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,CA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AAK,CAAC,GAAG,EACT,4CAA4C,IAAA,eAAS,EAAC,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,yDAAyD,CAC1I,CACF,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,EAAE,CAAC;QACX,EAAE,CAAC,MAAM,CACP,KAAK,CACH,WAAK,CAAC,MAAM,EACZ,GAAG,MAAM,+DAA+D,CACzE,CACF,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC,CAAC;AAxFW,QAAA,cAAc,kBAwFzB"}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -18,6 +9,7 @@ const jszip_1 = __importDefault(require("jszip"));
|
|
|
18
9
|
const xmldom_1 = require("@xmldom/xmldom");
|
|
19
10
|
const commands_1 = require("../template-logic/commands");
|
|
20
11
|
const expression_1 = require("../template-logic/expression");
|
|
12
|
+
const types_1 = require("../template-logic/types");
|
|
21
13
|
const data_model_1 = require("./data-model");
|
|
22
14
|
const hints_1 = require("./hints");
|
|
23
15
|
const usage_1 = require("./usage");
|
|
@@ -30,10 +22,21 @@ const BUILTIN_HELPERS = {
|
|
|
30
22
|
flowPage: 1,
|
|
31
23
|
flowPages: 1,
|
|
32
24
|
};
|
|
25
|
+
/** Commands that work in alt text (renderAltTexts). */
|
|
26
|
+
const ALT_TEXT_COMMANDS = [
|
|
27
|
+
'IMAGE',
|
|
28
|
+
'IF',
|
|
29
|
+
'ELSE-IF',
|
|
30
|
+
'ELSE',
|
|
31
|
+
'END-IF',
|
|
32
|
+
'FOR',
|
|
33
|
+
'END-FOR',
|
|
34
|
+
'EXEC',
|
|
35
|
+
];
|
|
33
36
|
const ANY = { kind: 'any' };
|
|
34
37
|
const children = (parent, tagName) => {
|
|
35
38
|
const result = [];
|
|
36
|
-
for (let node = parent
|
|
39
|
+
for (let node = parent?.firstChild; node; node = node.nextSibling) {
|
|
37
40
|
if (node.nodeType === 1 &&
|
|
38
41
|
(!tagName || node.tagName === tagName)) {
|
|
39
42
|
result.push(node);
|
|
@@ -45,12 +48,12 @@ const descendants = (parent, tagName) => Array.from(parent.getElementsByTagName(
|
|
|
45
48
|
const parseXml = (xml) => new xmldom_1.DOMParser().parseFromString(xml, 'application/xml');
|
|
46
49
|
const shapeOf = (node) => {
|
|
47
50
|
for (let n = node.parentNode; n; n = n.parentNode) {
|
|
48
|
-
if (
|
|
51
|
+
if (['p:sp', 'p:pic', 'p:graphicFrame'].includes(n.tagName))
|
|
49
52
|
return n;
|
|
50
53
|
}
|
|
51
54
|
return undefined;
|
|
52
55
|
};
|
|
53
|
-
const shapeName = (shape) =>
|
|
56
|
+
const shapeName = (shape) => shape && descendants(shape, 'p:cNvPr')[0]?.getAttribute('name');
|
|
54
57
|
/** Same rule as renderTemplate's IMAGE placement (`shapeFrame` in images.ts). */
|
|
55
58
|
const hasOwnFrame = (shape) => {
|
|
56
59
|
const xfrm = children(children(shape, 'p:spPr')[0], 'a:xfrm')[0];
|
|
@@ -103,6 +106,16 @@ const containersOf = (doc) => {
|
|
|
103
106
|
});
|
|
104
107
|
};
|
|
105
108
|
visit(doc);
|
|
109
|
+
// {{IMAGE …}} in alt text, rendered after all text (renderAltTexts)
|
|
110
|
+
descendants(doc, 'p:cNvPr').forEach((cNvPr) => {
|
|
111
|
+
const descr = cNvPr.getAttribute('descr');
|
|
112
|
+
if (descr) {
|
|
113
|
+
containers.push({
|
|
114
|
+
kind: 'alt',
|
|
115
|
+
segments: [{ text: descr, paragraph: cNvPr }],
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
});
|
|
106
119
|
return containers;
|
|
107
120
|
};
|
|
108
121
|
const resolvePath = (base, target) => {
|
|
@@ -150,7 +163,6 @@ const OTHER_PARTS = [
|
|
|
150
163
|
];
|
|
151
164
|
class TemplateLinter {
|
|
152
165
|
constructor(options, usage) {
|
|
153
|
-
var _a;
|
|
154
166
|
this.usage = usage;
|
|
155
167
|
this.issues = [];
|
|
156
168
|
this.seen = new Set();
|
|
@@ -159,10 +171,10 @@ class TemplateLinter {
|
|
|
159
171
|
/** Where the command's code starts in `tagText`; -1 if not in it (alias). */
|
|
160
172
|
this.codeStart = -1;
|
|
161
173
|
this.syntax = (0, commands_1.tagSyntax)(options);
|
|
162
|
-
this.fixQuotes =
|
|
174
|
+
this.fixQuotes = options.fixSmartQuotes ?? false;
|
|
163
175
|
this.data = options.data;
|
|
164
176
|
// Built-in helpers count like additionalJsContext: names, not data
|
|
165
|
-
const helpers =
|
|
177
|
+
const helpers = { ...BUILTIN_HELPERS, ...options.additionalJsContext };
|
|
166
178
|
this.extraNames = new Set(Object.keys(helpers));
|
|
167
179
|
this.model = new data_model_1.DataModel(options.data, options.schema, helpers);
|
|
168
180
|
}
|
|
@@ -172,7 +184,17 @@ class TemplateLinter {
|
|
|
172
184
|
if (this.seen.has(key))
|
|
173
185
|
return;
|
|
174
186
|
this.seen.add(key);
|
|
175
|
-
this.issues.push(
|
|
187
|
+
this.issues.push({
|
|
188
|
+
severity: issue.severity,
|
|
189
|
+
rule: issue.rule,
|
|
190
|
+
message: issue.message,
|
|
191
|
+
...(issue.hint && { hint: issue.hint }),
|
|
192
|
+
part,
|
|
193
|
+
...(slide !== undefined && { slide }),
|
|
194
|
+
...(issue.shape !== undefined && { shape: issue.shape }),
|
|
195
|
+
...(issue.tag !== undefined && { tag: issue.tag }),
|
|
196
|
+
...(issue.range && { range: issue.range }),
|
|
197
|
+
});
|
|
176
198
|
}
|
|
177
199
|
enterTag(raw) {
|
|
178
200
|
// Non-breaking spaces count as spaces, as in parseCommand
|
|
@@ -207,9 +229,75 @@ class TemplateLinter {
|
|
|
207
229
|
inner: m[1],
|
|
208
230
|
})).filter((tag) => !(0, commands_1.isTableMarker)(tag.inner));
|
|
209
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Splits off the alt texts the renderer leaves as they are (not
|
|
234
|
+
* isAltTextTemplate): one with a tag in it gets a warning, as the tag
|
|
235
|
+
* most likely was meant to work.
|
|
236
|
+
*/
|
|
237
|
+
altTextTemplates(all, report) {
|
|
238
|
+
// ALIAS definitions in the text, which the renderer knows by then
|
|
239
|
+
const aliases = new Map();
|
|
240
|
+
all
|
|
241
|
+
.filter((container) => container.kind !== 'alt')
|
|
242
|
+
.flatMap((container) => container.segments)
|
|
243
|
+
.flatMap((segment) => this.tagsIn(segment.text))
|
|
244
|
+
.forEach(({ raw, inner }) => {
|
|
245
|
+
try {
|
|
246
|
+
const command = this.parse(inner, aliases, raw);
|
|
247
|
+
if (command.type === 'ALIAS') {
|
|
248
|
+
aliases.set(command.name, command.code);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
catch {
|
|
252
|
+
// reported at the tag
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
const commandType = (inner, raw) => {
|
|
256
|
+
try {
|
|
257
|
+
return this.parse(inner, aliases, raw).type;
|
|
258
|
+
}
|
|
259
|
+
catch {
|
|
260
|
+
return undefined;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
const { opening, closing, pattern } = this.syntax;
|
|
264
|
+
return all.filter((container) => {
|
|
265
|
+
if (container.kind !== 'alt')
|
|
266
|
+
return true;
|
|
267
|
+
const { text, paragraph } = container.segments[0];
|
|
268
|
+
if ((0, commands_1.isAltTextTemplate)(text, pattern, commandType))
|
|
269
|
+
return true;
|
|
270
|
+
const [first] = this.tagsIn(text);
|
|
271
|
+
if (first) {
|
|
272
|
+
report({
|
|
273
|
+
severity: 'warning',
|
|
274
|
+
rule: 'unsupported-location',
|
|
275
|
+
shape: shapeName(shapeOf(paragraph)),
|
|
276
|
+
tag: first.raw,
|
|
277
|
+
message: 'This alt text stays as it is: tags in alt text work only when ' +
|
|
278
|
+
'it holds nothing but tags, with an IMAGE among them',
|
|
279
|
+
hint: `Remove the other text (a description for screen readers goes into ` +
|
|
280
|
+
`${opening}IMAGE ({ data: …, alt: "…" })${closing}), or remove the tag.`,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
return false;
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
/** Alt text that is a template: on a picture or shape. */
|
|
287
|
+
checkAltText(segment, report) {
|
|
288
|
+
const holder = segment.paragraph.parentNode?.parentNode;
|
|
289
|
+
if (holder && !['p:sp', 'p:pic'].includes(holder.tagName)) {
|
|
290
|
+
report({
|
|
291
|
+
severity: 'error',
|
|
292
|
+
rule: 'unsupported-location',
|
|
293
|
+
message: `IMAGE in alt text works on pictures, placeholders and shapes, not on <${holder.tagName}>`,
|
|
294
|
+
hint: 'Write the tag into the alt text of a picture or shape.',
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
210
298
|
lintSlide(part, slide, doc) {
|
|
211
299
|
const report = (issue) => this.report(part, slide, issue);
|
|
212
|
-
const containers = containersOf(doc);
|
|
300
|
+
const containers = this.altTextTemplates(containersOf(doc), report);
|
|
213
301
|
const allTags = containers.flatMap((c) => c.segments.flatMap((s) => this.tagsIn(s.text)));
|
|
214
302
|
// ALIAS and EXEC names apply to the whole render call: collect up front
|
|
215
303
|
const aliases = new Map();
|
|
@@ -230,7 +318,7 @@ class TemplateLinter {
|
|
|
230
318
|
});
|
|
231
319
|
}
|
|
232
320
|
}
|
|
233
|
-
catch
|
|
321
|
+
catch {
|
|
234
322
|
// reported below, at the tag
|
|
235
323
|
}
|
|
236
324
|
});
|
|
@@ -238,19 +326,26 @@ class TemplateLinter {
|
|
|
238
326
|
const stack = [];
|
|
239
327
|
const where = container.kind === 'table' ? 'table' : 'shape';
|
|
240
328
|
container.segments.forEach((segment) => {
|
|
241
|
-
var _a, _b, _c, _d, _e;
|
|
242
329
|
const shape = shapeOf(segment.paragraph);
|
|
243
330
|
const name = shapeName(shape);
|
|
244
|
-
this.checkDelimiters(segment.text, (issue) => report(
|
|
331
|
+
this.checkDelimiters(segment.text, (issue) => report({ ...issue, shape: name }));
|
|
332
|
+
if (container.kind === 'alt') {
|
|
333
|
+
this.checkAltText(segment, (issue) => report({ ...issue, shape: name }));
|
|
334
|
+
}
|
|
245
335
|
for (const { raw, inner } of this.tagsIn(segment.text)) {
|
|
246
336
|
// Without a more precise range, the whole tag is marked
|
|
247
|
-
const tagReport = (issue) => {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
337
|
+
const tagReport = (issue) => report({
|
|
338
|
+
...issue,
|
|
339
|
+
shape: name,
|
|
340
|
+
tag: raw,
|
|
341
|
+
range: issue.range ?? { start: 0, end: raw.length },
|
|
342
|
+
});
|
|
251
343
|
this.enterTag(raw);
|
|
252
|
-
this.location =
|
|
253
|
-
|
|
344
|
+
this.location = {
|
|
345
|
+
part,
|
|
346
|
+
slide,
|
|
347
|
+
...(name !== undefined && { shape: name }),
|
|
348
|
+
};
|
|
254
349
|
let command;
|
|
255
350
|
try {
|
|
256
351
|
command = this.parse(inner, aliases, raw);
|
|
@@ -268,6 +363,16 @@ class TemplateLinter {
|
|
|
268
363
|
});
|
|
269
364
|
continue;
|
|
270
365
|
}
|
|
366
|
+
if (container.kind === 'alt' &&
|
|
367
|
+
!ALT_TEXT_COMMANDS.includes(command.type)) {
|
|
368
|
+
tagReport({
|
|
369
|
+
severity: 'error',
|
|
370
|
+
rule: 'unsupported-location',
|
|
371
|
+
message: `${raw} does not work in alt text; only IMAGE, IF, FOR and EXEC do`,
|
|
372
|
+
hint: 'Put the tag into the text of a shape.',
|
|
373
|
+
});
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
271
376
|
const loopVars = new Map(stack.flatMap((block) => block.vars));
|
|
272
377
|
const paths = new Map([
|
|
273
378
|
...execPaths,
|
|
@@ -296,10 +401,10 @@ class TemplateLinter {
|
|
|
296
401
|
}
|
|
297
402
|
case 'FOR': {
|
|
298
403
|
const expr = check(command.code, false);
|
|
299
|
-
const listPath = this.dataPathOf(expr
|
|
404
|
+
const listPath = this.dataPathOf(expr?.listPath(), paths);
|
|
300
405
|
const entryPath = listPath && [...listPath, '[]'];
|
|
301
406
|
if (listPath)
|
|
302
|
-
|
|
407
|
+
this.usage?.recordList?.(listPath);
|
|
303
408
|
const element = this.loopElement(expr, loopVars, execNames);
|
|
304
409
|
if (!element) {
|
|
305
410
|
tagReport({
|
|
@@ -312,7 +417,7 @@ class TemplateLinter {
|
|
|
312
417
|
}),
|
|
313
418
|
});
|
|
314
419
|
}
|
|
315
|
-
const known = element
|
|
420
|
+
const known = element ?? ANY;
|
|
316
421
|
stack.push({
|
|
317
422
|
type: 'FOR',
|
|
318
423
|
tag: raw,
|
|
@@ -337,7 +442,7 @@ class TemplateLinter {
|
|
|
337
442
|
if (command.type === 'ELSE-IF')
|
|
338
443
|
check(command.code, false);
|
|
339
444
|
const top = stack[stack.length - 1];
|
|
340
|
-
if (
|
|
445
|
+
if (top?.type !== 'IF') {
|
|
341
446
|
tagReport({
|
|
342
447
|
severity: 'error',
|
|
343
448
|
rule: 'unmatched-tag',
|
|
@@ -403,10 +508,10 @@ class TemplateLinter {
|
|
|
403
508
|
break;
|
|
404
509
|
case 'IMAGE': {
|
|
405
510
|
const expr = check(command.code);
|
|
406
|
-
for (const ref of
|
|
511
|
+
for (const ref of expr?.imageSources() ?? []) {
|
|
407
512
|
const imagePath = this.dataPathOf(ref, paths);
|
|
408
513
|
if (imagePath)
|
|
409
|
-
|
|
514
|
+
this.usage?.recordImage?.(imagePath);
|
|
410
515
|
}
|
|
411
516
|
if (segment.cell !== undefined) {
|
|
412
517
|
tagReport({
|
|
@@ -416,14 +521,26 @@ class TemplateLinter {
|
|
|
416
521
|
hint: 'Put the tag into a text box or shape on top of the table.',
|
|
417
522
|
});
|
|
418
523
|
}
|
|
524
|
+
else if (container.kind === 'alt') {
|
|
525
|
+
// Location checked by checkAltText; size and rotation
|
|
526
|
+
// come from the shape it fills
|
|
527
|
+
const fixed = (expr?.imageOptionKeys() ?? []).filter((key) => types_1.FILL_FIXED_OPTIONS.includes(key));
|
|
528
|
+
[...new Set(fixed)].forEach((key) => tagReport({
|
|
529
|
+
severity: 'error',
|
|
530
|
+
rule: 'unsupported-location',
|
|
531
|
+
message: `IMAGE in alt text fills the shape; "${key}" is not supported there`,
|
|
532
|
+
hint: 'Size and rotation come from the shape: remove the option, or resize the shape in PowerPoint.',
|
|
533
|
+
}));
|
|
534
|
+
}
|
|
419
535
|
else if (!hasOwnFrame(shape)) {
|
|
420
536
|
tagReport({
|
|
421
537
|
severity: 'error',
|
|
422
538
|
rule: 'unsupported-location',
|
|
423
539
|
message: 'IMAGE needs a shape with its own position and size; ' +
|
|
424
540
|
'this one inherits them from the layout',
|
|
425
|
-
hint: '
|
|
426
|
-
'
|
|
541
|
+
hint: 'Write the tag into the alt text of the placeholder ' +
|
|
542
|
+
'instead (it then fills the placeholder), move or resize ' +
|
|
543
|
+
'the placeholder once in PowerPoint, or use a text box.',
|
|
427
544
|
});
|
|
428
545
|
}
|
|
429
546
|
break;
|
|
@@ -486,14 +603,26 @@ class TemplateLinter {
|
|
|
486
603
|
};
|
|
487
604
|
const open = rest.indexOf(opening);
|
|
488
605
|
if (open !== -1) {
|
|
489
|
-
report(
|
|
606
|
+
report({
|
|
607
|
+
severity: 'error',
|
|
608
|
+
rule: 'unterminated-tag',
|
|
609
|
+
message: opening === closing
|
|
490
610
|
? `Unpaired "${opening}"; the text stays as it is`
|
|
491
|
-
: `"${opening}" without "${closing}"; the text stays as it is`,
|
|
611
|
+
: `"${opening}" without "${closing}"; the text stays as it is`,
|
|
612
|
+
hint,
|
|
613
|
+
...excerpt(open, opening),
|
|
614
|
+
});
|
|
492
615
|
return;
|
|
493
616
|
}
|
|
494
617
|
const close = rest.indexOf(closing);
|
|
495
618
|
if (close !== -1 && opening !== closing) {
|
|
496
|
-
report(
|
|
619
|
+
report({
|
|
620
|
+
severity: 'error',
|
|
621
|
+
rule: 'unterminated-tag',
|
|
622
|
+
message: `"${closing}" without "${opening}"; the text stays as it is`,
|
|
623
|
+
hint,
|
|
624
|
+
...excerpt(close, closing),
|
|
625
|
+
});
|
|
497
626
|
}
|
|
498
627
|
}
|
|
499
628
|
checkExpression(code, loopVars, execNames, report) {
|
|
@@ -600,7 +729,7 @@ class TemplateLinter {
|
|
|
600
729
|
}
|
|
601
730
|
/** Entry type of a FOR loop; undefined if the data says "not a list". */
|
|
602
731
|
loopElement(expr, loopVars, execNames) {
|
|
603
|
-
const path = expr
|
|
732
|
+
const path = expr?.listPath();
|
|
604
733
|
if (!path || !this.model.enabled)
|
|
605
734
|
return ANY;
|
|
606
735
|
let known = this.lookup(path.name, loopVars, execNames);
|
|
@@ -626,18 +755,19 @@ class TemplateLinter {
|
|
|
626
755
|
try {
|
|
627
756
|
command = this.parse(inner, new Map(), raw);
|
|
628
757
|
}
|
|
629
|
-
catch
|
|
758
|
+
catch {
|
|
630
759
|
return raw;
|
|
631
760
|
}
|
|
632
761
|
if (command.type !== 'HIDE-SLIDE')
|
|
633
762
|
return raw;
|
|
634
763
|
this.enterTag(raw);
|
|
635
764
|
this.enterCode(command.code);
|
|
636
|
-
this.location =
|
|
637
|
-
const report = (issue) => {
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
765
|
+
this.location = { part, ...(slide !== undefined && { slide }) };
|
|
766
|
+
const report = (issue) => this.report(part, slide, {
|
|
767
|
+
...issue,
|
|
768
|
+
tag: raw,
|
|
769
|
+
range: issue.range ?? { start: 0, end: raw.length },
|
|
770
|
+
});
|
|
641
771
|
if (command.code) {
|
|
642
772
|
const expr = this.checkExpression(command.code, new Map(), new Set(), report);
|
|
643
773
|
if (expr)
|
|
@@ -676,14 +806,14 @@ class TemplateLinter {
|
|
|
676
806
|
*
|
|
677
807
|
* @param pptx Path to a .pptx file or its contents.
|
|
678
808
|
*/
|
|
679
|
-
const lintTemplate =
|
|
680
|
-
const issues = (
|
|
809
|
+
const lintTemplate = async (pptx, options = {}) => {
|
|
810
|
+
const issues = (await runLinter(pptx, options)).issues;
|
|
681
811
|
return {
|
|
682
812
|
issues,
|
|
683
813
|
errorCount: issues.filter((i) => i.severity === 'error').length,
|
|
684
814
|
warningCount: issues.filter((i) => i.severity === 'warning').length,
|
|
685
815
|
};
|
|
686
|
-
}
|
|
816
|
+
};
|
|
687
817
|
exports.lintTemplate = lintTemplate;
|
|
688
818
|
/**
|
|
689
819
|
* Which fields of the data the tags of a .pptx read, and - with example
|
|
@@ -693,15 +823,15 @@ exports.lintTemplate = lintTemplate;
|
|
|
693
823
|
*
|
|
694
824
|
* @param pptx Path to a .pptx file or its contents.
|
|
695
825
|
*/
|
|
696
|
-
const templateDataUsage =
|
|
826
|
+
const templateDataUsage = async (pptx, options = {}) => (0, exports.collectDataUsage)([pptx], options);
|
|
697
827
|
exports.templateDataUsage = templateDataUsage;
|
|
698
828
|
/** Data usage of several decks together: `unused` is what none of them reads. */
|
|
699
|
-
const collectDataUsage =
|
|
829
|
+
const collectDataUsage = async (decks, options = {}) => {
|
|
700
830
|
const usage = new usage_1.DataUsageRecorder(options.data, options.schema);
|
|
701
831
|
for (const pptx of decks)
|
|
702
|
-
|
|
832
|
+
await runLinter(pptx, options, usage);
|
|
703
833
|
return usage.result();
|
|
704
|
-
}
|
|
834
|
+
};
|
|
705
835
|
exports.collectDataUsage = collectDataUsage;
|
|
706
836
|
/**
|
|
707
837
|
* Example data for one or more templates: every path their tags read, with
|
|
@@ -710,23 +840,26 @@ exports.collectDataUsage = collectDataUsage;
|
|
|
710
840
|
*
|
|
711
841
|
* @param pptx Path(s) to .pptx files or their contents.
|
|
712
842
|
*/
|
|
713
|
-
const templateDataSkeleton =
|
|
843
|
+
const templateDataSkeleton = async (pptx, options = {}) => {
|
|
714
844
|
const decks = Array.isArray(pptx) ? pptx : [pptx];
|
|
715
845
|
// Without data, every name counts as data, except the helpers
|
|
716
|
-
const lintOptions =
|
|
846
|
+
const lintOptions = {
|
|
847
|
+
...options,
|
|
848
|
+
data: undefined,
|
|
849
|
+
schema: undefined,
|
|
850
|
+
};
|
|
717
851
|
const recorder = new skeleton_1.DataSkeletonRecorder();
|
|
718
852
|
let errorCount = 0;
|
|
719
853
|
for (const deck of decks) {
|
|
720
|
-
const linter =
|
|
854
|
+
const linter = await runLinter(deck, lintOptions, recorder);
|
|
721
855
|
errorCount += linter.issues.filter((i) => i.severity === 'error').length;
|
|
722
856
|
}
|
|
723
857
|
return recorder.result(errorCount);
|
|
724
|
-
}
|
|
858
|
+
};
|
|
725
859
|
exports.templateDataSkeleton = templateDataSkeleton;
|
|
726
|
-
const runLinter = (pptx, options, usage) =>
|
|
727
|
-
var _a;
|
|
860
|
+
const runLinter = async (pptx, options, usage) => {
|
|
728
861
|
const content = typeof pptx === 'string' ? fs_1.default.readFileSync(pptx) : pptx;
|
|
729
|
-
const zip =
|
|
862
|
+
const zip = await jszip_1.default.loadAsync(content);
|
|
730
863
|
const linter = new TemplateLinter(options, usage);
|
|
731
864
|
const slides = Object.keys(zip.files)
|
|
732
865
|
.map((name) => ({
|
|
@@ -740,7 +873,7 @@ const runLinter = (pptx, options, usage) => __awaiter(void 0, void 0, void 0, fu
|
|
|
740
873
|
const slideOfPart = new Map();
|
|
741
874
|
for (const { name, slide } of slides) {
|
|
742
875
|
const relsPath = name.replace(/slides\/(slide\d+\.xml)$/, 'slides/_rels/$1.rels');
|
|
743
|
-
const rels =
|
|
876
|
+
const rels = await zip.file(relsPath)?.async('string');
|
|
744
877
|
if (!rels)
|
|
745
878
|
continue;
|
|
746
879
|
descendants(parseXml(rels), 'Relationship').forEach((rel) => {
|
|
@@ -755,13 +888,13 @@ const runLinter = (pptx, options, usage) => __awaiter(void 0, void 0, void 0, fu
|
|
|
755
888
|
});
|
|
756
889
|
}
|
|
757
890
|
for (const { name, slide } of slides) {
|
|
758
|
-
linter.lintSlide(name, slide, parseXml(
|
|
891
|
+
linter.lintSlide(name, slide, parseXml(await zip.file(name).async('string')));
|
|
759
892
|
}
|
|
760
893
|
const others = Object.keys(zip.files)
|
|
761
894
|
.filter((name) => OTHER_PARTS.some((p) => p.pattern.test(name)))
|
|
762
895
|
.sort((a, b) => a.localeCompare(b, 'en', { numeric: true }));
|
|
763
896
|
for (const name of others) {
|
|
764
|
-
const doc = parseXml(
|
|
897
|
+
const doc = parseXml(await zip.file(name).async('string'));
|
|
765
898
|
if (/^ppt\/notesSlides\//.test(name)) {
|
|
766
899
|
linter.lintNotes(name, slideOfPart.get(name), doc);
|
|
767
900
|
continue;
|
|
@@ -770,5 +903,5 @@ const runLinter = (pptx, options, usage) => __awaiter(void 0, void 0, void 0, fu
|
|
|
770
903
|
linter.lintOtherPart(name, slideOfPart.get(name), texts);
|
|
771
904
|
}
|
|
772
905
|
return linter;
|
|
773
|
-
}
|
|
906
|
+
};
|
|
774
907
|
//# sourceMappingURL=lint.js.map
|