pptx-templates 0.3.9 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AI-INSTRUCTOR.md +46 -3
- package/CHANGELOG.md +236 -1
- package/README.md +61 -168
- package/dist/automizer.d.ts +7 -0
- package/dist/automizer.js +168 -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 +130 -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/constants/constants.js.map +1 -1
- package/dist/enums/chart-type.js.map +1 -1
- package/dist/enums/content-type-map.js.map +1 -1
- package/dist/enums/element-type.js.map +1 -1
- package/dist/errors.js +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/index.d.ts +13 -3
- package/dist/extensions/index.js +3 -1
- package/dist/extensions/index.js.map +1 -1
- package/dist/extensions/link-scheme/index.d.ts +12 -0
- package/dist/extensions/link-scheme/index.js +40 -0
- package/dist/extensions/link-scheme/index.js.map +1 -0
- package/dist/extensions/master-parts/index.js +36 -49
- package/dist/extensions/master-parts/index.js.map +1 -1
- package/dist/extensions/pptxgenjs-compat/img-broken-png.js.map +1 -1
- package/dist/extensions/pptxgenjs-compat/index.js.map +1 -1
- package/dist/extensions/pptxgenjs-compat/svg-fallback.js +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.js +33 -11
- package/dist/extensions/shape-geometry/index.js.map +1 -1
- package/dist/extensions/shape-geometry/presets.d.ts +1 -1
- package/dist/extensions/shape-geometry/presets.js.map +1 -1
- package/dist/extensions/shape-geometry/types.js.map +1 -1
- package/dist/extensions/template-lint/cli.js +71 -49
- package/dist/extensions/template-lint/cli.js.map +1 -1
- package/dist/extensions/template-lint/config.js +29 -13
- 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/hints.js.map +1 -1
- package/dist/extensions/template-lint/index.js.map +1 -1
- package/dist/extensions/template-lint/init-cli.d.ts +2 -0
- package/dist/extensions/template-lint/init-cli.js +33 -23
- package/dist/extensions/template-lint/init-cli.js.map +1 -1
- package/dist/extensions/template-lint/lint.d.ts +1 -1
- package/dist/extensions/template-lint/lint.js +83 -64
- 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/types.js.map +1 -1
- package/dist/extensions/template-lint/usage-cli.js +17 -18
- 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-lint/watch.d.ts +2 -0
- package/dist/extensions/template-lint/watch.js +52 -7
- package/dist/extensions/template-lint/watch.js.map +1 -1
- package/dist/extensions/template-logic/clone.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 +1 -1
- package/dist/extensions/template-logic/commands.js +12 -11
- package/dist/extensions/template-logic/commands.js.map +1 -1
- package/dist/extensions/template-logic/expression.d.ts +15 -2
- package/dist/extensions/template-logic/expression.js +143 -63
- package/dist/extensions/template-logic/expression.js.map +1 -1
- package/dist/extensions/template-logic/images.js +58 -55
- package/dist/extensions/template-logic/images.js.map +1 -1
- package/dist/extensions/template-logic/index.js +16 -24
- package/dist/extensions/template-logic/index.js.map +1 -1
- package/dist/extensions/template-logic/list-commands.js +8 -19
- package/dist/extensions/template-logic/list-commands.js.map +1 -1
- package/dist/extensions/template-logic/renderer.d.ts +9 -0
- package/dist/extensions/template-logic/renderer.js +480 -477
- package/dist/extensions/template-logic/renderer.js.map +1 -1
- package/dist/extensions/template-logic/types.d.ts +8 -1
- package/dist/extensions/template-logic/types.js.map +1 -1
- package/dist/extensions/template-render/cli.js +34 -22
- 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.js +183 -207
- package/dist/extensions/text-flow/flow.js.map +1 -1
- package/dist/extensions/text-flow/font-file.d.ts +9 -0
- package/dist/extensions/text-flow/font-file.js +40 -22
- 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 +67 -23
- package/dist/extensions/text-flow/fonts.js.map +1 -1
- package/dist/extensions/text-flow/index.js.map +1 -1
- package/dist/extensions/text-flow/layout.js +8 -9
- 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 +7 -1
- package/dist/extensions/text-flow/styles.js +108 -64
- package/dist/extensions/text-flow/styles.js.map +1 -1
- package/dist/helper/archive/archive-fs.d.ts +11 -0
- package/dist/helper/archive/archive-fs.js +195 -142
- 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 +26 -0
- package/dist/helper/archive/jszip-fast-read.js +166 -0
- package/dist/helper/archive/jszip-fast-read.js.map +1 -0
- package/dist/helper/cell-id-helper.d.ts +1 -0
- package/dist/helper/cell-id-helper.js +6 -2
- package/dist/helper/cell-id-helper.js.map +1 -1
- package/dist/helper/compute-src-rect.js +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.d.ts +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/general-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.d.ts +4 -4
- package/dist/helper/html-to-multitext-helper.js +46 -23
- 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/image-dimensions.js.map +1 -1
- package/dist/helper/jszip-helper.d.ts +1 -1
- package/dist/helper/jszip-helper.js +40 -33
- 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.d.ts +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.d.ts +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-element.js.map +1 -1
- package/dist/helper/modify-hyperlink-helper.js +152 -158
- package/dist/helper/modify-hyperlink-helper.js.map +1 -1
- package/dist/helper/modify-image-helper.d.ts +1 -1
- package/dist/helper/modify-image-helper.js +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 +95 -84
- package/dist/helper/modify-table-helper.js.map +1 -1
- package/dist/helper/modify-text-helper.d.ts +8 -0
- package/dist/helper/modify-text-helper.js +202 -190
- 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 +13 -9
- 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 +8 -8
- package/dist/helper/text-replace-helper.js.map +1 -1
- package/dist/helper/xml/lnLRTB.js.map +1 -1
- package/dist/helper/xml/prstGeom.js.map +1 -1
- package/dist/helper/xml-clone.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 +102 -135
- 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-pretty-print.js.map +1 -1
- package/dist/helper/xml-relationship-helper.js +132 -147
- 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.d.ts +4 -4
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/interfaces/iarchive.js.map +1 -1
- package/dist/interfaces/ichart.js.map +1 -1
- package/dist/interfaces/icounter.js.map +1 -1
- package/dist/interfaces/igenerator.js.map +1 -1
- package/dist/interfaces/iimage.js.map +1 -1
- package/dist/interfaces/ilayout.js.map +1 -1
- package/dist/interfaces/imaster.js.map +1 -1
- package/dist/interfaces/imulti-text.js.map +1 -1
- package/dist/interfaces/ipptxgenjs-slide.js.map +1 -1
- package/dist/interfaces/ipresentation-props.js.map +1 -1
- package/dist/interfaces/ishape-action.js.map +1 -1
- package/dist/interfaces/ishape.js.map +1 -1
- package/dist/interfaces/islide.js.map +1 -1
- package/dist/interfaces/itemplate.js.map +1 -1
- package/dist/interfaces/pres-template.js.map +1 -1
- package/dist/interfaces/root-pres-template.js.map +1 -1
- package/dist/modify/modify-chart.d.ts +4 -4
- package/dist/modify/modify-chart.js +35 -23
- package/dist/modify/modify-chart.js.map +1 -1
- package/dist/modify/modify-table.d.ts +0 -1
- package/dist/modify/modify-table.js +19 -27
- 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.d.ts +14 -0
- package/dist/shapes/diagram.js +167 -103
- 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.d.ts +0 -1
- package/dist/shapes/hyperlink.js +84 -124
- package/dist/shapes/hyperlink.js.map +1 -1
- package/dist/shapes/image.js +118 -149
- package/dist/shapes/image.js.map +1 -1
- package/dist/shapes/ole.js +148 -188
- package/dist/shapes/ole.js.map +1 -1
- package/dist/types/chart-types.js.map +1 -1
- package/dist/types/modify-types.js.map +1 -1
- package/dist/types/shape-types.js.map +1 -1
- package/dist/types/table-types.js.map +1 -1
- package/dist/types/types.d.ts +7 -0
- package/dist/types/types.js.map +1 -1
- package/dist/types/xml-types.js.map +1 -1
- package/dist/vendor/pptxgenjs/README.md +8 -3
- package/dist/vendor/pptxgenjs/index.js +19 -2
- package/package.json +13 -16
|
@@ -1,16 +1,7 @@
|
|
|
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
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.TextFlow = exports.flowArguments = exports.flowPlanEntries = exports.FlowShown = exports.FlowCache = void 0;
|
|
13
|
-
const
|
|
4
|
+
const xml_serializer_1 = require("../../helper/xml-serializer");
|
|
14
5
|
const logger_1 = require("../../helper/logger");
|
|
15
6
|
const fonts_1 = require("./fonts");
|
|
16
7
|
const layout_1 = require("./layout");
|
|
@@ -33,10 +24,9 @@ const isObject = (value) => (typeof value === 'object' && value !== null) || typ
|
|
|
33
24
|
/** The list a `flowContinue()` result was taken from. */
|
|
34
25
|
const continuedFrom = new WeakMap();
|
|
35
26
|
/** The list of the data that `list` stands for. */
|
|
36
|
-
const originOf = (list) =>
|
|
27
|
+
const originOf = (list) => isObject(list) ? (continuedFrom.get(list) ?? list) : undefined;
|
|
37
28
|
const count = (counts, entry) => {
|
|
38
|
-
|
|
39
|
-
counts.set(entry, ((_a = counts.get(entry)) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
29
|
+
counts.set(entry, (counts.get(entry) ?? 0) + 1);
|
|
40
30
|
};
|
|
41
31
|
/**
|
|
42
32
|
* The entries that `flow()` lists of earlier slides of a deck show, for
|
|
@@ -79,9 +69,8 @@ class FlowShown {
|
|
|
79
69
|
const values = this.values.get(origin);
|
|
80
70
|
const used = new Map();
|
|
81
71
|
const result = Array.from(list).filter((entry) => {
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
const skipped = (_c = used.get(entry)) !== null && _c !== void 0 ? _c : 0;
|
|
72
|
+
const shown = (isObject(entry) ? this.objects : values)?.get(entry) ?? 0;
|
|
73
|
+
const skipped = used.get(entry) ?? 0;
|
|
85
74
|
if (skipped >= shown)
|
|
86
75
|
return true;
|
|
87
76
|
used.set(entry, skipped + 1);
|
|
@@ -102,8 +91,7 @@ class FlowShown {
|
|
|
102
91
|
exports.FlowShown = FlowShown;
|
|
103
92
|
/** The entries a plan puts onto one of its pages (0-based). */
|
|
104
93
|
const flowPlanEntries = (plan, page) => {
|
|
105
|
-
|
|
106
|
-
const indexes = new Set([...((_b = (_a = plan.pages[page]) === null || _a === void 0 ? void 0 : _a.values()) !== null && _b !== void 0 ? _b : [])].flat());
|
|
94
|
+
const indexes = new Set([...(plan.pages[page]?.values() ?? [])].flat());
|
|
107
95
|
return [...indexes].sort((a, b) => a - b).map((i) => plan.list[i]);
|
|
108
96
|
};
|
|
109
97
|
exports.flowPlanEntries = flowPlanEntries;
|
|
@@ -111,17 +99,17 @@ const sameList = (a, b) => a.length === b.length && a.every((entry, i) => entry
|
|
|
111
99
|
const TOLERANCE = 0.01;
|
|
112
100
|
const EMU_PER_PT = 12700;
|
|
113
101
|
const childOf = (parent, tagName) => {
|
|
114
|
-
for (let n = parent
|
|
102
|
+
for (let n = parent?.firstChild; n; n = n.nextSibling) {
|
|
115
103
|
if (n.tagName === tagName)
|
|
116
104
|
return n;
|
|
117
105
|
}
|
|
118
106
|
return undefined;
|
|
119
107
|
};
|
|
120
|
-
const emuAttr = (el, name) =>
|
|
108
|
+
const emuAttr = (el, name) => Number(el?.getAttribute(name) ?? 0) / EMU_PER_PT;
|
|
121
109
|
/** The nearest p:grpSp around a shape, if it is grouped. */
|
|
122
110
|
const groupOf = (shape) => {
|
|
123
|
-
const parent = shape
|
|
124
|
-
return
|
|
111
|
+
const parent = shape?.parentNode;
|
|
112
|
+
return parent?.tagName === 'p:grpSp' ? parent : undefined;
|
|
125
113
|
};
|
|
126
114
|
/**
|
|
127
115
|
* A point in the coordinates of `shape`'s parent, mapped onto the slide
|
|
@@ -145,7 +133,6 @@ const toSlide = (shape, point) => {
|
|
|
145
133
|
};
|
|
146
134
|
/** Calls of `flow(…)` (or `flowRest(…)`) in a text. */
|
|
147
135
|
const flowArguments = (text, name = 'flow') => {
|
|
148
|
-
var _a, _b, _c;
|
|
149
136
|
const args = [];
|
|
150
137
|
const pattern = new RegExp(`(^|[^\\w$.])${name}\\s*\\(`, 'g');
|
|
151
138
|
while (pattern.exec(text)) {
|
|
@@ -172,22 +159,27 @@ const flowArguments = (text, name = 'flow') => {
|
|
|
172
159
|
commas.push(i);
|
|
173
160
|
}
|
|
174
161
|
const end = i - 1;
|
|
175
|
-
const source = text.slice(start,
|
|
162
|
+
const source = text.slice(start, commas[0] ?? end).trim();
|
|
176
163
|
const limit = commas.length > 0
|
|
177
|
-
? text.slice(commas[0] + 1,
|
|
164
|
+
? text.slice(commas[0] + 1, commas[1] ?? end).trim()
|
|
178
165
|
: '';
|
|
179
166
|
const options = commas.length > 1
|
|
180
|
-
? text.slice(commas[1] + 1,
|
|
167
|
+
? text.slice(commas[1] + 1, commas[2] ?? end).trim()
|
|
181
168
|
: '';
|
|
182
|
-
args.push(
|
|
169
|
+
args.push({
|
|
170
|
+
source,
|
|
171
|
+
key: source.replace(/\s+/g, ''),
|
|
172
|
+
...(limit ? { limit } : {}),
|
|
173
|
+
...(options ? { options } : {}),
|
|
174
|
+
});
|
|
183
175
|
}
|
|
184
176
|
return args;
|
|
185
177
|
};
|
|
186
178
|
exports.flowArguments = flowArguments;
|
|
187
179
|
const shapeName = (body) => {
|
|
188
180
|
const shape = body.parentNode;
|
|
189
|
-
const cNvPr = shape
|
|
190
|
-
return
|
|
181
|
+
const cNvPr = shape?.getElementsByTagName('p:cNvPr')[0];
|
|
182
|
+
return cNvPr?.getAttribute('name') || 'text box';
|
|
191
183
|
};
|
|
192
184
|
const textOf = (paragraph) => Array.from({ length: paragraph.getElementsByTagName('a:t').length }, (_, i) => paragraph.getElementsByTagName('a:t')[i].textContent).join('');
|
|
193
185
|
/**
|
|
@@ -198,7 +190,6 @@ const textOf = (paragraph) => Array.from({ length: paragraph.getElementsByTagNam
|
|
|
198
190
|
*/
|
|
199
191
|
class TextFlow {
|
|
200
192
|
constructor(boxes, host, options = {}) {
|
|
201
|
-
var _a;
|
|
202
193
|
this.host = host;
|
|
203
194
|
this.options = options;
|
|
204
195
|
/** Flow boxes (their p:txBody) and the source of their flow() argument. */
|
|
@@ -209,7 +200,7 @@ class TextFlow {
|
|
|
209
200
|
this.fingerprints = new Map();
|
|
210
201
|
this.plans = new Map();
|
|
211
202
|
this.resolved = new Map();
|
|
212
|
-
this.serializer =
|
|
203
|
+
this.serializer = { serializeToString: xml_serializer_1.serializeXml };
|
|
213
204
|
boxes.forEach((key, body) => {
|
|
214
205
|
this.keys.set(body, key);
|
|
215
206
|
this.indexes.set(body, this.indexes.size);
|
|
@@ -217,7 +208,7 @@ class TextFlow {
|
|
|
217
208
|
this.fingerprints.set(body, this.fingerprint(body));
|
|
218
209
|
}
|
|
219
210
|
});
|
|
220
|
-
this.fonts = new fonts_1.FontRegistry(
|
|
211
|
+
this.fonts = new fonts_1.FontRegistry(options.fonts ?? []);
|
|
221
212
|
}
|
|
222
213
|
/** The sources of the flow() lists, one per group of boxes. */
|
|
223
214
|
groups() {
|
|
@@ -228,36 +219,32 @@ class TextFlow {
|
|
|
228
219
|
* A `flowRest()` list that is no group's falls back to the only group.
|
|
229
220
|
* Must be awaited before `entries()`/`rest()`, which are synchronous.
|
|
230
221
|
*/
|
|
231
|
-
prepare(
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
this.
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
yield this.plans.get(group);
|
|
256
|
-
});
|
|
222
|
+
async prepare(key, list, limits = new Map(),
|
|
223
|
+
/** Boxes of `flow(list, n, { measure: false })`. */
|
|
224
|
+
unmeasured = new Set()) {
|
|
225
|
+
const groups = this.groups();
|
|
226
|
+
const group = groups.includes(key)
|
|
227
|
+
? key
|
|
228
|
+
: groups.length === 1
|
|
229
|
+
? groups[0]
|
|
230
|
+
: undefined;
|
|
231
|
+
if (group === undefined) {
|
|
232
|
+
throw new Error(`flowRest(${key}): no flow(${key}) on the slide`);
|
|
233
|
+
}
|
|
234
|
+
if (!this.plans.has(group)) {
|
|
235
|
+
const entries = this.toList(list);
|
|
236
|
+
this.plans.set(group, this.plan(group, entries, limits, unmeasured).then((plan) => {
|
|
237
|
+
this.reportOverflow(group, plan);
|
|
238
|
+
this.resolved.set(group, plan);
|
|
239
|
+
this.options.onFlowPlan?.(plan, list);
|
|
240
|
+
this.options.onFlowPages?.(this.pages);
|
|
241
|
+
return plan;
|
|
242
|
+
}));
|
|
243
|
+
}
|
|
244
|
+
await this.plans.get(group);
|
|
257
245
|
}
|
|
258
246
|
/** The entries of `list` that go into the text box `body`. */
|
|
259
247
|
entries(body, list) {
|
|
260
|
-
var _a;
|
|
261
248
|
const key = body && this.keys.get(body);
|
|
262
249
|
if (key === undefined) {
|
|
263
250
|
throw new Error('flow() works only in the loop of a text box, not in a table');
|
|
@@ -267,22 +254,21 @@ class TextFlow {
|
|
|
267
254
|
throw new Error(`flow(${key}) was not prepared`);
|
|
268
255
|
const entries = this.toList(list);
|
|
269
256
|
const page = plan.pages[this.page];
|
|
270
|
-
return (
|
|
257
|
+
return (page?.get(this.indexes.get(body)) ?? []).map((i) => i < entries.length ? entries[i] : plan.list[i]);
|
|
271
258
|
}
|
|
272
259
|
/**
|
|
273
260
|
* The entries of `list` after the rendered slide: on the next slides, or
|
|
274
261
|
* in none (they fit into no box).
|
|
275
262
|
*/
|
|
276
263
|
rest(list) {
|
|
277
|
-
var _a, _b;
|
|
278
264
|
const entries = this.toList(list);
|
|
279
265
|
const plans = [...this.resolved.values()];
|
|
280
|
-
const plan =
|
|
281
|
-
p.list.every((e, i) => e === entries[i]))
|
|
266
|
+
const plan = plans.find((p) => p.list.length === entries.length &&
|
|
267
|
+
p.list.every((e, i) => e === entries[i])) ?? (plans.length === 1 ? plans[0] : undefined);
|
|
282
268
|
if (!plan) {
|
|
283
269
|
throw new Error('flowRest(): no flow() over this list on the slide');
|
|
284
270
|
}
|
|
285
|
-
const end =
|
|
271
|
+
const end = plan.ends[Math.min(this.page, plan.ends.length - 1)] ?? 0;
|
|
286
272
|
return plan.list
|
|
287
273
|
.map((_, i) => i)
|
|
288
274
|
.slice(end)
|
|
@@ -313,20 +299,18 @@ class TextFlow {
|
|
|
313
299
|
emptyGroups() {
|
|
314
300
|
const used = new Map();
|
|
315
301
|
this.keys.forEach((key, body) => {
|
|
316
|
-
var _a, _b;
|
|
317
302
|
const group = groupOf(body.parentNode);
|
|
318
303
|
if (!group)
|
|
319
304
|
return;
|
|
320
305
|
const plan = this.resolved.get(key);
|
|
321
|
-
const page = plan
|
|
322
|
-
const filled = !plan || !!
|
|
323
|
-
used.set(group, (
|
|
306
|
+
const page = plan?.pages[this.page];
|
|
307
|
+
const filled = !plan || !!page?.get(this.indexes.get(body))?.length;
|
|
308
|
+
used.set(group, (used.get(group) ?? false) || filled);
|
|
324
309
|
});
|
|
325
310
|
return [...used].filter(([, filled]) => !filled).map(([group]) => group);
|
|
326
311
|
}
|
|
327
312
|
get page() {
|
|
328
|
-
|
|
329
|
-
return (_a = this.options.flowPage) !== null && _a !== void 0 ? _a : 0;
|
|
313
|
+
return this.options.flowPage ?? 0;
|
|
330
314
|
}
|
|
331
315
|
toList(value) {
|
|
332
316
|
if (value === null || value === undefined)
|
|
@@ -353,79 +337,74 @@ class TextFlow {
|
|
|
353
337
|
* The plan of a list: from the cache if another copy of the slide has
|
|
354
338
|
* distributed the same entries over the same boxes, else computed.
|
|
355
339
|
*/
|
|
356
|
-
plan(key, list, limits, unmeasured) {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
cache.plans.set(signature, plan);
|
|
377
|
-
return plan;
|
|
378
|
-
});
|
|
340
|
+
async plan(key, list, limits, unmeasured) {
|
|
341
|
+
const cache = this.options.flowCache;
|
|
342
|
+
if (!cache)
|
|
343
|
+
return this.computePlan(key, list, limits, unmeasured);
|
|
344
|
+
// Everything the distribution depends on, besides the entries: the
|
|
345
|
+
// boxes, their limits and the paragraphs around the loop, which can
|
|
346
|
+
// differ from copy to copy ({{IF flowPage > 1}}…)
|
|
347
|
+
const parts = [key];
|
|
348
|
+
for (const body of this.bodiesOf(key)) {
|
|
349
|
+
const measured = !unmeasured.has(body);
|
|
350
|
+
const fixed = measured ? await this.host.renderCopy(body, []) : [];
|
|
351
|
+
parts.push(String(this.indexes.get(body)), String(limits.get(body) ?? ''), String(measured), this.fingerprints.get(body), ...fixed.map((p) => this.serializer.serializeToString(p)));
|
|
352
|
+
}
|
|
353
|
+
const signature = parts.join('\n');
|
|
354
|
+
const cached = cache.plans.get(signature);
|
|
355
|
+
if (cached && sameList(cached.list, list))
|
|
356
|
+
return cached;
|
|
357
|
+
const plan = await this.computePlan(key, list, limits, unmeasured);
|
|
358
|
+
cache.plans.set(signature, plan);
|
|
359
|
+
return plan;
|
|
379
360
|
}
|
|
380
|
-
computePlan(key, list, limits, unmeasured) {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
taken.push(next++);
|
|
416
|
-
}
|
|
417
|
-
slot.boxes.forEach((box) => page.set(this.indexes.get(box.body), taken));
|
|
361
|
+
async computePlan(key, list, limits, unmeasured) {
|
|
362
|
+
const bodies = this.bodiesOf(key);
|
|
363
|
+
const styles = await this.host.styles();
|
|
364
|
+
const boxes = [];
|
|
365
|
+
const measurements = new Map();
|
|
366
|
+
for (const body of bodies) {
|
|
367
|
+
boxes.push(unmeasured.has(body)
|
|
368
|
+
? this.unmeasuredBox(body, styles, limits)
|
|
369
|
+
: await this.measureBox(body, list, styles, measurements));
|
|
370
|
+
}
|
|
371
|
+
const slots = this.slotsOf(boxes);
|
|
372
|
+
const pages = [];
|
|
373
|
+
const ends = [];
|
|
374
|
+
let next = 0;
|
|
375
|
+
// Fill the slots, then the same slots on the next slide, … until an
|
|
376
|
+
// entry fits into none of them (or all are placed)
|
|
377
|
+
for (;;) {
|
|
378
|
+
const start = next;
|
|
379
|
+
const page = new Map();
|
|
380
|
+
for (const slot of slots) {
|
|
381
|
+
const taken = [];
|
|
382
|
+
const limit = Math.min(...slot.boxes.map((b) => limits.get(b.body) ?? Infinity));
|
|
383
|
+
while (next < list.length && taken.length < limit) {
|
|
384
|
+
// an entry too large for this slot tries the next one; in a
|
|
385
|
+
// card, its part has to fit into every box
|
|
386
|
+
const fits = slot.boxes.every((box) => !box.measured ||
|
|
387
|
+
(0, layout_1.stackHeight)([
|
|
388
|
+
...box.head,
|
|
389
|
+
...[...taken, next].flatMap((i) => box.entries[i]),
|
|
390
|
+
...box.tail,
|
|
391
|
+
]) <=
|
|
392
|
+
box.geometry.height + TOLERANCE);
|
|
393
|
+
if (!fits)
|
|
394
|
+
break;
|
|
395
|
+
taken.push(next++);
|
|
418
396
|
}
|
|
419
|
-
|
|
420
|
-
if (next === start && pages.length)
|
|
421
|
-
break;
|
|
422
|
-
pages.push(page);
|
|
423
|
-
ends.push(next);
|
|
424
|
-
if (next >= list.length || next === start)
|
|
425
|
-
break;
|
|
397
|
+
slot.boxes.forEach((box) => page.set(this.indexes.get(box.body), taken));
|
|
426
398
|
}
|
|
427
|
-
|
|
428
|
-
|
|
399
|
+
// a slide without progress: the next entry fits into no box
|
|
400
|
+
if (next === start && pages.length)
|
|
401
|
+
break;
|
|
402
|
+
pages.push(page);
|
|
403
|
+
ends.push(next);
|
|
404
|
+
if (next >= list.length || next === start)
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
return { list, pages, ends, names: boxes.map((b) => b.name) };
|
|
429
408
|
}
|
|
430
409
|
/** Entries this render leaves out: a warning, or an error. */
|
|
431
410
|
reportOverflow(key, plan) {
|
|
@@ -456,14 +435,14 @@ class TextFlow {
|
|
|
456
435
|
const shape = box.body.parentNode;
|
|
457
436
|
const group = groupOf(shape);
|
|
458
437
|
const { x, y } = toSlide(shape, box.geometry);
|
|
459
|
-
const slot = slots.get(group
|
|
438
|
+
const slot = slots.get(group ?? box.body);
|
|
460
439
|
if (slot) {
|
|
461
440
|
slot.boxes.push(box);
|
|
462
441
|
slot.x = Math.min(slot.x, x);
|
|
463
442
|
slot.y = Math.min(slot.y, y);
|
|
464
443
|
}
|
|
465
444
|
else {
|
|
466
|
-
slots.set(group
|
|
445
|
+
slots.set(group ?? box.body, { boxes: [box], group, x, y });
|
|
467
446
|
}
|
|
468
447
|
}
|
|
469
448
|
return [...slots.values()].sort((a, b) => Math.abs(a.x - b.x) > 1 ? a.x - b.x : a.y - b.y);
|
|
@@ -479,82 +458,79 @@ class TextFlow {
|
|
|
479
458
|
return {
|
|
480
459
|
body,
|
|
481
460
|
name,
|
|
482
|
-
geometry: geometry
|
|
461
|
+
geometry: geometry ?? { x: 0, y: 0, width: 0, height: 0 },
|
|
483
462
|
head: [],
|
|
484
463
|
tail: [],
|
|
485
464
|
entries: [],
|
|
486
465
|
measured: false,
|
|
487
466
|
};
|
|
488
467
|
}
|
|
489
|
-
measureBox(body, list, slide,
|
|
468
|
+
async measureBox(body, list, slide,
|
|
490
469
|
/** Measurements of this list so far, by measureKey. */
|
|
491
470
|
measurements) {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
const
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
split = k;
|
|
537
|
-
break;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
if (split === undefined) {
|
|
541
|
-
throw new Error(`flow(): in "${name}", put {{FOR …}} and {{END-FOR}} into ` +
|
|
542
|
-
'paragraphs of their own, around whole paragraphs');
|
|
471
|
+
const name = shapeName(body);
|
|
472
|
+
const styles = new styles_1.ShapeStyles(body.parentNode, slide, this.fonts);
|
|
473
|
+
const geometry = styles.geometry();
|
|
474
|
+
if (!geometry) {
|
|
475
|
+
throw new Error(`flow(): "${name}" has no position and size of its own ` +
|
|
476
|
+
'(a placeholder that inherits them is not supported)');
|
|
477
|
+
}
|
|
478
|
+
const unsupported = styles.unsupported();
|
|
479
|
+
if (unsupported)
|
|
480
|
+
throw new Error(`flow(): "${name}" has ${unsupported}, which flow() cannot measure`);
|
|
481
|
+
const key = this.host.measureKey?.(body);
|
|
482
|
+
const known = key === undefined ? undefined : measurements.get(key);
|
|
483
|
+
if (known)
|
|
484
|
+
return { body, name, geometry, ...known, measured: true };
|
|
485
|
+
const measure = (paragraphs) => styles
|
|
486
|
+
.paragraphs(paragraphs)
|
|
487
|
+
.map((p) => (0, layout_1.measureParagraph)(p, geometry.width));
|
|
488
|
+
const xml = (p) => this.serializer.serializeToString(p);
|
|
489
|
+
// Without entries: the paragraphs around the loop. A body left empty
|
|
490
|
+
// keeps one empty paragraph, which is not there once entries are in.
|
|
491
|
+
let fixed = await this.host.renderCopy(body, []);
|
|
492
|
+
if (fixed.length === 1 && !textOf(fixed[0]).trim())
|
|
493
|
+
fixed = [];
|
|
494
|
+
const fixedXml = fixed.map(xml);
|
|
495
|
+
const head = [];
|
|
496
|
+
const tail = [];
|
|
497
|
+
const entries = [];
|
|
498
|
+
let split;
|
|
499
|
+
for (const entry of list) {
|
|
500
|
+
const rendered = await this.host.renderCopy(body, [entry]);
|
|
501
|
+
// the loop's output sits between a common head and a common tail
|
|
502
|
+
if (split === undefined) {
|
|
503
|
+
const renderedXml = rendered.map(xml);
|
|
504
|
+
for (let k = 0; k <= fixed.length; k++) {
|
|
505
|
+
const headMatches = fixedXml
|
|
506
|
+
.slice(0, k)
|
|
507
|
+
.every((x, i) => renderedXml[i] === x);
|
|
508
|
+
const tailLength = fixed.length - k;
|
|
509
|
+
const tailMatches = fixedXml
|
|
510
|
+
.slice(k)
|
|
511
|
+
.every((x, i) => renderedXml[rendered.length - tailLength + i] === x);
|
|
512
|
+
if (headMatches && tailMatches && rendered.length >= fixed.length) {
|
|
513
|
+
split = k;
|
|
514
|
+
break;
|
|
543
515
|
}
|
|
544
|
-
head.push(...fixed.slice(0, split));
|
|
545
|
-
tail.push(...fixed.slice(split));
|
|
546
516
|
}
|
|
547
|
-
|
|
517
|
+
if (split === undefined) {
|
|
518
|
+
throw new Error(`flow(): in "${name}", put {{FOR …}} and {{END-FOR}} into ` +
|
|
519
|
+
'paragraphs of their own, around whole paragraphs');
|
|
520
|
+
}
|
|
521
|
+
head.push(...fixed.slice(0, split));
|
|
522
|
+
tail.push(...fixed.slice(split));
|
|
548
523
|
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
524
|
+
entries.push(measure(rendered.slice(split, rendered.length - (fixed.length - split))));
|
|
525
|
+
}
|
|
526
|
+
const measurement = {
|
|
527
|
+
head: measure(head),
|
|
528
|
+
tail: measure(tail),
|
|
529
|
+
entries,
|
|
530
|
+
};
|
|
531
|
+
if (key !== undefined)
|
|
532
|
+
measurements.set(key, measurement);
|
|
533
|
+
return { body, name, geometry, ...measurement, measured: true };
|
|
558
534
|
}
|
|
559
535
|
}
|
|
560
536
|
exports.TextFlow = TextFlow;
|