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.
Files changed (294) hide show
  1. package/AI-INSTRUCTOR.md +46 -3
  2. package/CHANGELOG.md +236 -1
  3. package/README.md +61 -168
  4. package/dist/automizer.d.ts +7 -0
  5. package/dist/automizer.js +168 -176
  6. package/dist/automizer.js.map +1 -1
  7. package/dist/classes/content-type-registry.js +23 -36
  8. package/dist/classes/content-type-registry.js.map +1 -1
  9. package/dist/classes/element-importer.js +130 -148
  10. package/dist/classes/element-importer.js.map +1 -1
  11. package/dist/classes/has-shapes.js +81 -126
  12. package/dist/classes/has-shapes.js.map +1 -1
  13. package/dist/classes/layout.js +47 -67
  14. package/dist/classes/layout.js.map +1 -1
  15. package/dist/classes/master.js +70 -89
  16. package/dist/classes/master.js.map +1 -1
  17. package/dist/classes/placeholder-normalizer.js +48 -37
  18. package/dist/classes/placeholder-normalizer.js.map +1 -1
  19. package/dist/classes/related-content-copier.js +65 -86
  20. package/dist/classes/related-content-copier.js.map +1 -1
  21. package/dist/classes/shape.js +79 -110
  22. package/dist/classes/shape.js.map +1 -1
  23. package/dist/classes/slide-master-remover.js +108 -130
  24. package/dist/classes/slide-master-remover.js.map +1 -1
  25. package/dist/classes/slide-notes-copier.js +24 -41
  26. package/dist/classes/slide-notes-copier.js.map +1 -1
  27. package/dist/classes/slide.js +112 -141
  28. package/dist/classes/slide.js.map +1 -1
  29. package/dist/classes/template.js +82 -117
  30. package/dist/classes/template.js.map +1 -1
  31. package/dist/constants/constants.js.map +1 -1
  32. package/dist/enums/chart-type.js.map +1 -1
  33. package/dist/enums/content-type-map.js.map +1 -1
  34. package/dist/enums/element-type.js.map +1 -1
  35. package/dist/errors.js +5 -5
  36. package/dist/errors.js.map +1 -1
  37. package/dist/extensions/cli/index.js +3 -13
  38. package/dist/extensions/cli/index.js.map +1 -1
  39. package/dist/extensions/hide-slide/index.js +48 -46
  40. package/dist/extensions/hide-slide/index.js.map +1 -1
  41. package/dist/extensions/index.d.ts +13 -3
  42. package/dist/extensions/index.js +3 -1
  43. package/dist/extensions/index.js.map +1 -1
  44. package/dist/extensions/link-scheme/index.d.ts +12 -0
  45. package/dist/extensions/link-scheme/index.js +40 -0
  46. package/dist/extensions/link-scheme/index.js.map +1 -0
  47. package/dist/extensions/master-parts/index.js +36 -49
  48. package/dist/extensions/master-parts/index.js.map +1 -1
  49. package/dist/extensions/pptxgenjs-compat/img-broken-png.js.map +1 -1
  50. package/dist/extensions/pptxgenjs-compat/index.js.map +1 -1
  51. package/dist/extensions/pptxgenjs-compat/svg-fallback.js +56 -70
  52. package/dist/extensions/pptxgenjs-compat/svg-fallback.js.map +1 -1
  53. package/dist/extensions/regexp-escape/index.d.ts +10 -0
  54. package/dist/extensions/regexp-escape/index.js +15 -0
  55. package/dist/extensions/regexp-escape/index.js.map +1 -0
  56. package/dist/extensions/run-merge/index.js +4 -5
  57. package/dist/extensions/run-merge/index.js.map +1 -1
  58. package/dist/extensions/shape-geometry/index.js +33 -11
  59. package/dist/extensions/shape-geometry/index.js.map +1 -1
  60. package/dist/extensions/shape-geometry/presets.d.ts +1 -1
  61. package/dist/extensions/shape-geometry/presets.js.map +1 -1
  62. package/dist/extensions/shape-geometry/types.js.map +1 -1
  63. package/dist/extensions/template-lint/cli.js +71 -49
  64. package/dist/extensions/template-lint/cli.js.map +1 -1
  65. package/dist/extensions/template-lint/config.js +29 -13
  66. package/dist/extensions/template-lint/config.js.map +1 -1
  67. package/dist/extensions/template-lint/data-model.js +17 -20
  68. package/dist/extensions/template-lint/data-model.js.map +1 -1
  69. package/dist/extensions/template-lint/hints.js.map +1 -1
  70. package/dist/extensions/template-lint/index.js.map +1 -1
  71. package/dist/extensions/template-lint/init-cli.d.ts +2 -0
  72. package/dist/extensions/template-lint/init-cli.js +33 -23
  73. package/dist/extensions/template-lint/init-cli.js.map +1 -1
  74. package/dist/extensions/template-lint/lint.d.ts +1 -1
  75. package/dist/extensions/template-lint/lint.js +83 -64
  76. package/dist/extensions/template-lint/lint.js.map +1 -1
  77. package/dist/extensions/template-lint/skeleton.js +5 -6
  78. package/dist/extensions/template-lint/skeleton.js.map +1 -1
  79. package/dist/extensions/template-lint/types.js.map +1 -1
  80. package/dist/extensions/template-lint/usage-cli.js +17 -18
  81. package/dist/extensions/template-lint/usage-cli.js.map +1 -1
  82. package/dist/extensions/template-lint/usage.js +8 -9
  83. package/dist/extensions/template-lint/usage.js.map +1 -1
  84. package/dist/extensions/template-lint/watch.d.ts +2 -0
  85. package/dist/extensions/template-lint/watch.js +52 -7
  86. package/dist/extensions/template-lint/watch.js.map +1 -1
  87. package/dist/extensions/template-logic/clone.d.ts +2 -16
  88. package/dist/extensions/template-logic/clone.js +15 -90
  89. package/dist/extensions/template-logic/clone.js.map +1 -1
  90. package/dist/extensions/template-logic/commands.d.ts +1 -1
  91. package/dist/extensions/template-logic/commands.js +12 -11
  92. package/dist/extensions/template-logic/commands.js.map +1 -1
  93. package/dist/extensions/template-logic/expression.d.ts +15 -2
  94. package/dist/extensions/template-logic/expression.js +143 -63
  95. package/dist/extensions/template-logic/expression.js.map +1 -1
  96. package/dist/extensions/template-logic/images.js +58 -55
  97. package/dist/extensions/template-logic/images.js.map +1 -1
  98. package/dist/extensions/template-logic/index.js +16 -24
  99. package/dist/extensions/template-logic/index.js.map +1 -1
  100. package/dist/extensions/template-logic/list-commands.js +8 -19
  101. package/dist/extensions/template-logic/list-commands.js.map +1 -1
  102. package/dist/extensions/template-logic/renderer.d.ts +9 -0
  103. package/dist/extensions/template-logic/renderer.js +480 -477
  104. package/dist/extensions/template-logic/renderer.js.map +1 -1
  105. package/dist/extensions/template-logic/types.d.ts +8 -1
  106. package/dist/extensions/template-logic/types.js.map +1 -1
  107. package/dist/extensions/template-render/cli.js +34 -22
  108. package/dist/extensions/template-render/cli.js.map +1 -1
  109. package/dist/extensions/template-render/index.js +152 -107
  110. package/dist/extensions/template-render/index.js.map +1 -1
  111. package/dist/extensions/template-render/prune.d.ts +14 -0
  112. package/dist/extensions/template-render/prune.js +131 -0
  113. package/dist/extensions/template-render/prune.js.map +1 -0
  114. package/dist/extensions/template-render/zip-text.d.ts +9 -0
  115. package/dist/extensions/template-render/zip-text.js +27 -0
  116. package/dist/extensions/template-render/zip-text.js.map +1 -0
  117. package/dist/extensions/template-render/zip-writer.d.ts +16 -0
  118. package/dist/extensions/template-render/zip-writer.js +151 -0
  119. package/dist/extensions/template-render/zip-writer.js.map +1 -0
  120. package/dist/extensions/text-flow/flow.js +183 -207
  121. package/dist/extensions/text-flow/flow.js.map +1 -1
  122. package/dist/extensions/text-flow/font-file.d.ts +9 -0
  123. package/dist/extensions/text-flow/font-file.js +40 -22
  124. package/dist/extensions/text-flow/font-file.js.map +1 -1
  125. package/dist/extensions/text-flow/fonts.d.ts +4 -0
  126. package/dist/extensions/text-flow/fonts.js +67 -23
  127. package/dist/extensions/text-flow/fonts.js.map +1 -1
  128. package/dist/extensions/text-flow/index.js.map +1 -1
  129. package/dist/extensions/text-flow/layout.js +8 -9
  130. package/dist/extensions/text-flow/layout.js.map +1 -1
  131. package/dist/extensions/text-flow/slide-styles.js +18 -22
  132. package/dist/extensions/text-flow/slide-styles.js.map +1 -1
  133. package/dist/extensions/text-flow/styles.d.ts +7 -1
  134. package/dist/extensions/text-flow/styles.js +108 -64
  135. package/dist/extensions/text-flow/styles.js.map +1 -1
  136. package/dist/helper/archive/archive-fs.d.ts +11 -0
  137. package/dist/helper/archive/archive-fs.js +195 -142
  138. package/dist/helper/archive/archive-fs.js.map +1 -1
  139. package/dist/helper/archive/archive-jszip.js +101 -125
  140. package/dist/helper/archive/archive-jszip.js.map +1 -1
  141. package/dist/helper/archive/archive.d.ts +6 -0
  142. package/dist/helper/archive/archive.js +21 -30
  143. package/dist/helper/archive/archive.js.map +1 -1
  144. package/dist/helper/archive/jszip-fast-read.d.ts +26 -0
  145. package/dist/helper/archive/jszip-fast-read.js +166 -0
  146. package/dist/helper/archive/jszip-fast-read.js.map +1 -0
  147. package/dist/helper/cell-id-helper.d.ts +1 -0
  148. package/dist/helper/cell-id-helper.js +6 -2
  149. package/dist/helper/cell-id-helper.js.map +1 -1
  150. package/dist/helper/compute-src-rect.js +4 -5
  151. package/dist/helper/compute-src-rect.js.map +1 -1
  152. package/dist/helper/content-tracker.js +86 -114
  153. package/dist/helper/content-tracker.js.map +1 -1
  154. package/dist/helper/count-helper.js +48 -78
  155. package/dist/helper/count-helper.js.map +1 -1
  156. package/dist/helper/css-style-parser.d.ts +1 -1
  157. package/dist/helper/css-style-parser.js +1 -2
  158. package/dist/helper/css-style-parser.js.map +1 -1
  159. package/dist/helper/file-helper.js +30 -48
  160. package/dist/helper/file-helper.js.map +1 -1
  161. package/dist/helper/general-helper.js.map +1 -1
  162. package/dist/helper/generate/generate-pptxgenjs.js +36 -48
  163. package/dist/helper/generate/generate-pptxgenjs.js.map +1 -1
  164. package/dist/helper/html-to-multitext-helper.d.ts +4 -4
  165. package/dist/helper/html-to-multitext-helper.js +46 -23
  166. package/dist/helper/html-to-multitext-helper.js.map +1 -1
  167. package/dist/helper/hyperlink-processor.js +125 -139
  168. package/dist/helper/hyperlink-processor.js.map +1 -1
  169. package/dist/helper/image-dimensions.js.map +1 -1
  170. package/dist/helper/jszip-helper.d.ts +1 -1
  171. package/dist/helper/jszip-helper.js +40 -33
  172. package/dist/helper/jszip-helper.js.map +1 -1
  173. package/dist/helper/layout-index.js +51 -71
  174. package/dist/helper/layout-index.js.map +1 -1
  175. package/dist/helper/logger.js +4 -4
  176. package/dist/helper/logger.js.map +1 -1
  177. package/dist/helper/media-deduplicator.d.ts +24 -0
  178. package/dist/helper/media-deduplicator.js +81 -34
  179. package/dist/helper/media-deduplicator.js.map +1 -1
  180. package/dist/helper/modify-background-helper.js +46 -46
  181. package/dist/helper/modify-background-helper.js.map +1 -1
  182. package/dist/helper/modify-chart-helper.d.ts +1 -1
  183. package/dist/helper/modify-chart-helper.js +597 -591
  184. package/dist/helper/modify-chart-helper.js.map +1 -1
  185. package/dist/helper/modify-cleanup-helper.js +112 -112
  186. package/dist/helper/modify-cleanup-helper.js.map +1 -1
  187. package/dist/helper/modify-color-helper.d.ts +1 -1
  188. package/dist/helper/modify-color-helper.js +53 -53
  189. package/dist/helper/modify-color-helper.js.map +1 -1
  190. package/dist/helper/modify-helper.js +25 -25
  191. package/dist/helper/modify-helper.js.map +1 -1
  192. package/dist/helper/modify-hyperlink-element.js.map +1 -1
  193. package/dist/helper/modify-hyperlink-helper.js +152 -158
  194. package/dist/helper/modify-hyperlink-helper.js.map +1 -1
  195. package/dist/helper/modify-image-helper.d.ts +1 -1
  196. package/dist/helper/modify-image-helper.js +121 -132
  197. package/dist/helper/modify-image-helper.js.map +1 -1
  198. package/dist/helper/modify-presentation-helper.js +137 -154
  199. package/dist/helper/modify-presentation-helper.js.map +1 -1
  200. package/dist/helper/modify-shape-helper.js +262 -262
  201. package/dist/helper/modify-shape-helper.js.map +1 -1
  202. package/dist/helper/modify-table-helper.js +95 -84
  203. package/dist/helper/modify-table-helper.js.map +1 -1
  204. package/dist/helper/modify-text-helper.d.ts +8 -0
  205. package/dist/helper/modify-text-helper.js +202 -190
  206. package/dist/helper/modify-text-helper.js.map +1 -1
  207. package/dist/helper/modify-xml-helper.js +36 -36
  208. package/dist/helper/modify-xml-helper.js.map +1 -1
  209. package/dist/helper/multitext-helper.js +13 -9
  210. package/dist/helper/multitext-helper.js.map +1 -1
  211. package/dist/helper/ppt-paths.js +17 -17
  212. package/dist/helper/ppt-paths.js.map +1 -1
  213. package/dist/helper/shape-type-detector.js +18 -29
  214. package/dist/helper/shape-type-detector.js.map +1 -1
  215. package/dist/helper/text-replace-helper.js +8 -8
  216. package/dist/helper/text-replace-helper.js.map +1 -1
  217. package/dist/helper/xml/lnLRTB.js.map +1 -1
  218. package/dist/helper/xml/prstGeom.js.map +1 -1
  219. package/dist/helper/xml-clone.d.ts +24 -0
  220. package/dist/helper/xml-clone.js +269 -0
  221. package/dist/helper/xml-clone.js.map +1 -0
  222. package/dist/helper/xml-elements.js +17 -20
  223. package/dist/helper/xml-elements.js.map +1 -1
  224. package/dist/helper/xml-find.d.ts +4 -0
  225. package/dist/helper/xml-find.js +48 -0
  226. package/dist/helper/xml-find.js.map +1 -0
  227. package/dist/helper/xml-helper.js +102 -135
  228. package/dist/helper/xml-helper.js.map +1 -1
  229. package/dist/helper/xml-parse-cache.d.ts +31 -0
  230. package/dist/helper/xml-parse-cache.js +71 -0
  231. package/dist/helper/xml-parse-cache.js.map +1 -0
  232. package/dist/helper/xml-placeholder-helper.js +10 -10
  233. package/dist/helper/xml-placeholder-helper.js.map +1 -1
  234. package/dist/helper/xml-pretty-print.js.map +1 -1
  235. package/dist/helper/xml-relationship-helper.js +132 -147
  236. package/dist/helper/xml-relationship-helper.js.map +1 -1
  237. package/dist/helper/xml-serializer.d.ts +2 -0
  238. package/dist/helper/xml-serializer.js +192 -0
  239. package/dist/helper/xml-serializer.js.map +1 -0
  240. package/dist/helper/xml-slide-helper.js +109 -129
  241. package/dist/helper/xml-slide-helper.js.map +1 -1
  242. package/dist/helper/xml-template-helper.js +120 -144
  243. package/dist/helper/xml-template-helper.js.map +1 -1
  244. package/dist/helper/xmldom-sax-patch.js +52 -2
  245. package/dist/helper/xmldom-sax-patch.js.map +1 -1
  246. package/dist/index.d.ts +4 -4
  247. package/dist/index.js +4 -2
  248. package/dist/index.js.map +1 -1
  249. package/dist/interfaces/iarchive.js.map +1 -1
  250. package/dist/interfaces/ichart.js.map +1 -1
  251. package/dist/interfaces/icounter.js.map +1 -1
  252. package/dist/interfaces/igenerator.js.map +1 -1
  253. package/dist/interfaces/iimage.js.map +1 -1
  254. package/dist/interfaces/ilayout.js.map +1 -1
  255. package/dist/interfaces/imaster.js.map +1 -1
  256. package/dist/interfaces/imulti-text.js.map +1 -1
  257. package/dist/interfaces/ipptxgenjs-slide.js.map +1 -1
  258. package/dist/interfaces/ipresentation-props.js.map +1 -1
  259. package/dist/interfaces/ishape-action.js.map +1 -1
  260. package/dist/interfaces/ishape.js.map +1 -1
  261. package/dist/interfaces/islide.js.map +1 -1
  262. package/dist/interfaces/itemplate.js.map +1 -1
  263. package/dist/interfaces/pres-template.js.map +1 -1
  264. package/dist/interfaces/root-pres-template.js.map +1 -1
  265. package/dist/modify/modify-chart.d.ts +4 -4
  266. package/dist/modify/modify-chart.js +35 -23
  267. package/dist/modify/modify-chart.js.map +1 -1
  268. package/dist/modify/modify-table.d.ts +0 -1
  269. package/dist/modify/modify-table.js +19 -27
  270. package/dist/modify/modify-table.js.map +1 -1
  271. package/dist/shapes/chart.js +238 -287
  272. package/dist/shapes/chart.js.map +1 -1
  273. package/dist/shapes/diagram.d.ts +14 -0
  274. package/dist/shapes/diagram.js +167 -103
  275. package/dist/shapes/diagram.js.map +1 -1
  276. package/dist/shapes/generic.js +62 -83
  277. package/dist/shapes/generic.js.map +1 -1
  278. package/dist/shapes/hyperlink.d.ts +0 -1
  279. package/dist/shapes/hyperlink.js +84 -124
  280. package/dist/shapes/hyperlink.js.map +1 -1
  281. package/dist/shapes/image.js +118 -149
  282. package/dist/shapes/image.js.map +1 -1
  283. package/dist/shapes/ole.js +148 -188
  284. package/dist/shapes/ole.js.map +1 -1
  285. package/dist/types/chart-types.js.map +1 -1
  286. package/dist/types/modify-types.js.map +1 -1
  287. package/dist/types/shape-types.js.map +1 -1
  288. package/dist/types/table-types.js.map +1 -1
  289. package/dist/types/types.d.ts +7 -0
  290. package/dist/types/types.js.map +1 -1
  291. package/dist/types/xml-types.js.map +1 -1
  292. package/dist/vendor/pptxgenjs/README.md +8 -3
  293. package/dist/vendor/pptxgenjs/index.js +19 -2
  294. 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 xmldom_1 = require("@xmldom/xmldom");
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) => { var _a; return isObject(list) ? ((_a = continuedFrom.get(list)) !== null && _a !== void 0 ? _a : list) : undefined; };
27
+ const originOf = (list) => isObject(list) ? (continuedFrom.get(list) ?? list) : undefined;
37
28
  const count = (counts, entry) => {
38
- var _a;
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
- var _a, _b, _c;
83
- const shown = (_b = (_a = (isObject(entry) ? this.objects : values)) === null || _a === void 0 ? void 0 : _a.get(entry)) !== null && _b !== void 0 ? _b : 0;
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
- var _a, _b;
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 === null || parent === void 0 ? void 0 : parent.firstChild; n; n = n.nextSibling) {
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) => { var _a; return Number((_a = el === null || el === void 0 ? void 0 : el.getAttribute(name)) !== null && _a !== void 0 ? _a : 0) / EMU_PER_PT; };
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 === null || shape === void 0 ? void 0 : shape.parentNode;
124
- return (parent === null || parent === void 0 ? void 0 : parent.tagName) === 'p:grpSp' ? parent : undefined;
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, (_a = commas[0]) !== null && _a !== void 0 ? _a : end).trim();
162
+ const source = text.slice(start, commas[0] ?? end).trim();
176
163
  const limit = commas.length > 0
177
- ? text.slice(commas[0] + 1, (_b = commas[1]) !== null && _b !== void 0 ? _b : end).trim()
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, (_c = commas[2]) !== null && _c !== void 0 ? _c : end).trim()
167
+ ? text.slice(commas[1] + 1, commas[2] ?? end).trim()
181
168
  : '';
182
- args.push(Object.assign(Object.assign({ source, key: source.replace(/\s+/g, '') }, (limit ? { limit } : {})), (options ? { options } : {})));
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 === null || shape === void 0 ? void 0 : shape.getElementsByTagName('p:cNvPr')[0];
190
- return (cNvPr === null || cNvPr === void 0 ? void 0 : cNvPr.getAttribute('name')) || 'text box';
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 = new xmldom_1.XMLSerializer();
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((_a = options.fonts) !== null && _a !== void 0 ? _a : []);
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(key_1, list_1) {
232
- return __awaiter(this, arguments, void 0, function* (key, list, limits = new Map(),
233
- /** Boxes of `flow(list, n, { measure: false })`. */
234
- unmeasured = new Set()) {
235
- const groups = this.groups();
236
- const group = groups.includes(key)
237
- ? key
238
- : groups.length === 1
239
- ? groups[0]
240
- : undefined;
241
- if (group === undefined) {
242
- throw new Error(`flowRest(${key}): no flow(${key}) on the slide`);
243
- }
244
- if (!this.plans.has(group)) {
245
- const entries = this.toList(list);
246
- this.plans.set(group, this.plan(group, entries, limits, unmeasured).then((plan) => {
247
- var _a, _b, _c, _d;
248
- this.reportOverflow(group, plan);
249
- this.resolved.set(group, plan);
250
- (_b = (_a = this.options).onFlowPlan) === null || _b === void 0 ? void 0 : _b.call(_a, plan, list);
251
- (_d = (_c = this.options).onFlowPages) === null || _d === void 0 ? void 0 : _d.call(_c, this.pages);
252
- return plan;
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 ((_a = page === null || page === void 0 ? void 0 : page.get(this.indexes.get(body))) !== null && _a !== void 0 ? _a : []).map((i) => i < entries.length ? entries[i] : plan.list[i]);
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 = (_a = plans.find((p) => p.list.length === entries.length &&
281
- p.list.every((e, i) => e === entries[i]))) !== null && _a !== void 0 ? _a : (plans.length === 1 ? plans[0] : undefined);
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 = (_b = plan.ends[Math.min(this.page, plan.ends.length - 1)]) !== null && _b !== void 0 ? _b : 0;
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 === null || plan === void 0 ? void 0 : plan.pages[this.page];
322
- const filled = !plan || !!((_a = page === null || page === void 0 ? void 0 : page.get(this.indexes.get(body))) === null || _a === void 0 ? void 0 : _a.length);
323
- used.set(group, ((_b = used.get(group)) !== null && _b !== void 0 ? _b : false) || filled);
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
- var _a;
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
- return __awaiter(this, void 0, void 0, function* () {
358
- var _a;
359
- const cache = this.options.flowCache;
360
- if (!cache)
361
- return this.computePlan(key, list, limits, unmeasured);
362
- // Everything the distribution depends on, besides the entries: the
363
- // boxes, their limits and the paragraphs around the loop, which can
364
- // differ from copy to copy ({{IF flowPage > 1}}…)
365
- const parts = [key];
366
- for (const body of this.bodiesOf(key)) {
367
- const measured = !unmeasured.has(body);
368
- const fixed = measured ? yield this.host.renderCopy(body, []) : [];
369
- parts.push(String(this.indexes.get(body)), String((_a = limits.get(body)) !== null && _a !== void 0 ? _a : ''), String(measured), this.fingerprints.get(body), ...fixed.map((p) => this.serializer.serializeToString(p)));
370
- }
371
- const signature = parts.join('\n');
372
- const cached = cache.plans.get(signature);
373
- if (cached && sameList(cached.list, list))
374
- return cached;
375
- const plan = yield this.computePlan(key, list, limits, unmeasured);
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
- return __awaiter(this, void 0, void 0, function* () {
382
- const bodies = this.bodiesOf(key);
383
- const styles = yield this.host.styles();
384
- const boxes = [];
385
- const measurements = new Map();
386
- for (const body of bodies) {
387
- boxes.push(unmeasured.has(body)
388
- ? this.unmeasuredBox(body, styles, limits)
389
- : yield this.measureBox(body, list, styles, measurements));
390
- }
391
- const slots = this.slotsOf(boxes);
392
- const pages = [];
393
- const ends = [];
394
- let next = 0;
395
- // Fill the slots, then the same slots on the next slide, … until an
396
- // entry fits into none of them (or all are placed)
397
- for (;;) {
398
- const start = next;
399
- const page = new Map();
400
- for (const slot of slots) {
401
- const taken = [];
402
- const limit = Math.min(...slot.boxes.map((b) => { var _a; return (_a = limits.get(b.body)) !== null && _a !== void 0 ? _a : Infinity; }));
403
- while (next < list.length && taken.length < limit) {
404
- // an entry too large for this slot tries the next one; in a
405
- // card, its part has to fit into every box
406
- const fits = slot.boxes.every((box) => !box.measured ||
407
- (0, layout_1.stackHeight)([
408
- ...box.head,
409
- ...[...taken, next].flatMap((i) => box.entries[i]),
410
- ...box.tail,
411
- ]) <=
412
- box.geometry.height + TOLERANCE);
413
- if (!fits)
414
- break;
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
- // a slide without progress: the next entry fits into no box
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
- return { list, pages, ends, names: boxes.map((b) => b.name) };
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 !== null && group !== void 0 ? group : box.body);
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 !== null && group !== void 0 ? group : box.body, { boxes: [box], group, x, y });
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 !== null && geometry !== void 0 ? geometry : { x: 0, y: 0, width: 0, height: 0 },
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
- return __awaiter(this, void 0, void 0, function* () {
493
- var _a, _b;
494
- const name = shapeName(body);
495
- const styles = new styles_1.ShapeStyles(body.parentNode, slide, this.fonts);
496
- const geometry = styles.geometry();
497
- if (!geometry) {
498
- throw new Error(`flow(): "${name}" has no position and size of its own ` +
499
- '(a placeholder that inherits them is not supported)');
500
- }
501
- const unsupported = styles.unsupported();
502
- if (unsupported)
503
- throw new Error(`flow(): "${name}" has ${unsupported}, which flow() cannot measure`);
504
- const key = (_b = (_a = this.host).measureKey) === null || _b === void 0 ? void 0 : _b.call(_a, body);
505
- const known = key === undefined ? undefined : measurements.get(key);
506
- if (known)
507
- return Object.assign(Object.assign({ body, name, geometry }, known), { measured: true });
508
- const measure = (paragraphs) => styles
509
- .paragraphs(paragraphs)
510
- .map((p) => (0, layout_1.measureParagraph)(p, geometry.width));
511
- const xml = (p) => this.serializer.serializeToString(p);
512
- // Without entries: the paragraphs around the loop. A body left empty
513
- // keeps one empty paragraph, which is not there once entries are in.
514
- let fixed = yield this.host.renderCopy(body, []);
515
- if (fixed.length === 1 && !textOf(fixed[0]).trim())
516
- fixed = [];
517
- const fixedXml = fixed.map(xml);
518
- const head = [];
519
- const tail = [];
520
- const entries = [];
521
- let split;
522
- for (const entry of list) {
523
- const rendered = yield this.host.renderCopy(body, [entry]);
524
- // the loop's output sits between a common head and a common tail
525
- if (split === undefined) {
526
- const renderedXml = rendered.map(xml);
527
- for (let k = 0; k <= fixed.length; k++) {
528
- const headMatches = fixedXml
529
- .slice(0, k)
530
- .every((x, i) => renderedXml[i] === x);
531
- const tailLength = fixed.length - k;
532
- const tailMatches = fixedXml
533
- .slice(k)
534
- .every((x, i) => renderedXml[rendered.length - tailLength + i] === x);
535
- if (headMatches && tailMatches && rendered.length >= fixed.length) {
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
- entries.push(measure(rendered.slice(split, rendered.length - (fixed.length - split))));
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
- const measurement = {
550
- head: measure(head),
551
- tail: measure(tail),
552
- entries,
553
- };
554
- if (key !== undefined)
555
- measurements.set(key, measurement);
556
- return Object.assign(Object.assign({ body, name, geometry }, measurement), { measured: true });
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;