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
@@ -2,7 +2,6 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
- var _a;
6
5
  Object.defineProperty(exports, "__esModule", { value: true });
7
6
  const logger_1 = require("./logger");
8
7
  const modify_chart_1 = require("../modify/modify-chart");
@@ -10,633 +9,640 @@ const modify_xml_helper_1 = __importDefault(require("./modify-xml-helper"));
10
9
  const xml_helper_1 = require("./xml-helper");
11
10
  const modify_color_helper_1 = __importDefault(require("./modify-color-helper"));
12
11
  class ModifyChartHelper {
13
- // Prevent a "null" from being written to the xml file.
14
- static parseCellValue(value) {
15
- if (value === null)
16
- return '';
17
- return String(value);
18
- }
19
- }
20
- _a = ModifyChartHelper;
21
- /**
22
- * Set chart data to modify default chart types.
23
- * See `__tests__/modify-existing-chart.test.js`
24
- */
25
- ModifyChartHelper.setChartData = (data) => (element, chart, workbook) => {
26
- const slots = [];
27
- data.series.forEach((series, s) => {
28
- slots.push({
29
- index: s,
30
- series: series,
31
- targetCol: s + 1,
32
- type: 'defaultSeries',
33
- });
34
- });
35
- new modify_chart_1.ModifyChart(chart, workbook, data, slots).modify();
36
- // XmlHelper.dump(chart)
37
- // XmlHelper.dump(workbook.table)
38
- };
39
- /**
40
- * Set chart data to modify vertical line charts.
41
- * See `__tests__/modify-chart-vertical-lines.test.js`
42
- */
43
- ModifyChartHelper.setChartVerticalLines = (data) => (element, chart, workbook) => {
44
- const slots = [];
45
- slots.push({
46
- label: `Y-Values`,
47
- mapData: (point, category) => category.y,
48
- targetCol: 1,
49
- });
50
- data.series.forEach((series, s) => {
51
- slots.push({
52
- index: s,
53
- series: series,
54
- targetCol: s + 2,
55
- type: 'xySeries',
56
- });
57
- });
58
- new modify_chart_1.ModifyChart(chart, workbook, data, slots).modify();
59
- // ModifyChartHelper.setAxisRange({
60
- // axisIndex: 0,
61
- // min: 0,
62
- // max: data.categories.length,
63
- // })(element, chart);
64
- };
65
- /**
66
- * Set chart data to modify scatter charts.
67
- * See `__tests__/modify-chart-scatter.test.js`
68
- */
69
- ModifyChartHelper.setChartScatter = (data) => (element, chart, workbook) => {
70
- const slots = [];
71
- data.series.forEach((series, s) => {
72
- const colId = s * 2;
73
- slots.push({
74
- index: s,
75
- series: series,
76
- targetCol: colId + 1,
77
- type: 'customSeries',
78
- tag: 'c:xVal',
79
- mapData: (point) => point.x,
12
+ /**
13
+ * Set chart data to modify default chart types.
14
+ * See `__tests__/modify-existing-chart.test.js`
15
+ */
16
+ static { this.setChartData = (data) => (element, chart, workbook) => {
17
+ const slots = [];
18
+ data.series.forEach((series, s) => {
19
+ slots.push({
20
+ index: s,
21
+ series: series,
22
+ targetCol: s + 1,
23
+ type: 'defaultSeries',
24
+ });
80
25
  });
26
+ new modify_chart_1.ModifyChart(chart, workbook, data, slots).modify();
27
+ // XmlHelper.dump(chart)
28
+ // XmlHelper.dump(workbook.table)
29
+ }; }
30
+ /**
31
+ * Set chart data to modify vertical line charts.
32
+ * See `__tests__/modify-chart-vertical-lines.test.js`
33
+ */
34
+ static { this.setChartVerticalLines = (data) => (element, chart, workbook) => {
35
+ const slots = [];
81
36
  slots.push({
82
- label: `${series.label}-Y-Value`,
83
- index: s,
84
- series: series,
85
- targetCol: colId + 2,
86
- type: 'customSeries',
87
- tag: 'c:yVal',
88
- mapData: (point) => point.y,
89
- isStrRef: false,
37
+ label: `Y-Values`,
38
+ mapData: (point, category) => category.y,
39
+ targetCol: 1,
90
40
  });
91
- });
92
- new modify_chart_1.ModifyChart(chart, workbook, data, slots).modify();
93
- // XmlHelper.dump(chart)
94
- };
95
- /**
96
- * Set chart data to modify combo charts.
97
- * This type is prepared for
98
- * first series: bar chart (e.g. total)
99
- * other series: vertical lines
100
- * See `__tests__/modify-chart-scatter.test.js`
101
- */
102
- ModifyChartHelper.setChartCombo = (data) => (element, chart, workbook) => {
103
- const slots = [];
104
- slots.push({
105
- index: 0,
106
- series: data.series[0],
107
- targetCol: 1,
108
- type: 'defaultSeries',
109
- });
110
- slots.push({
111
- index: 1,
112
- label: `Y-Values`,
113
- mapData: (point, category) => category.y,
114
- targetCol: 2,
115
- });
116
- data.series.forEach((series, s) => {
117
- if (s > 0)
41
+ data.series.forEach((series, s) => {
118
42
  slots.push({
119
43
  index: s,
120
44
  series: series,
121
45
  targetCol: s + 2,
122
- targetYCol: 2,
123
46
  type: 'xySeries',
124
47
  });
125
- });
126
- new modify_chart_1.ModifyChart(chart, workbook, data, slots).modify();
127
- _a.setAxisRange({
128
- axisIndex: 1,
129
- min: 0,
130
- max: data.categories.length,
131
- })(element, chart);
132
- };
133
- /**
134
- * Set chart data to modify bubble charts.
135
- * See `__tests__/modify-chart-bubbles.test.js`
136
- */
137
- ModifyChartHelper.setChartBubbles = (data) => (element, chart, workbook) => {
138
- const slots = [];
139
- data.series.forEach((series, s) => {
140
- const colId = s * 3;
141
- slots.push({
142
- index: s,
143
- series: series,
144
- targetCol: colId + 1,
145
- type: 'customSeries',
146
- tag: 'c:xVal',
147
- mapData: (point) => point.x,
148
48
  });
149
- slots.push({
150
- label: `${series.label}-Y-Value`,
151
- index: s,
152
- series: series,
153
- targetCol: colId + 2,
154
- type: 'customSeries',
155
- tag: 'c:yVal',
156
- mapData: (point) => point.y,
157
- isStrRef: false,
49
+ new modify_chart_1.ModifyChart(chart, workbook, data, slots).modify();
50
+ // ModifyChartHelper.setAxisRange({
51
+ // axisIndex: 0,
52
+ // min: 0,
53
+ // max: data.categories.length,
54
+ // })(element, chart);
55
+ }; }
56
+ /**
57
+ * Set chart data to modify scatter charts.
58
+ * See `__tests__/modify-chart-scatter.test.js`
59
+ */
60
+ static { this.setChartScatter = (data) => (element, chart, workbook) => {
61
+ const slots = [];
62
+ data.series.forEach((series, s) => {
63
+ const colId = s * 2;
64
+ slots.push({
65
+ index: s,
66
+ series: series,
67
+ targetCol: colId + 1,
68
+ type: 'customSeries',
69
+ tag: 'c:xVal',
70
+ mapData: (point) => point.x,
71
+ });
72
+ slots.push({
73
+ label: `${series.label}-Y-Value`,
74
+ index: s,
75
+ series: series,
76
+ targetCol: colId + 2,
77
+ type: 'customSeries',
78
+ tag: 'c:yVal',
79
+ mapData: (point) => point.y,
80
+ isStrRef: false,
81
+ });
158
82
  });
83
+ new modify_chart_1.ModifyChart(chart, workbook, data, slots).modify();
84
+ // XmlHelper.dump(chart)
85
+ }; }
86
+ /**
87
+ * Set chart data to modify combo charts.
88
+ * This type is prepared for
89
+ * first series: bar chart (e.g. total)
90
+ * other series: vertical lines
91
+ * See `__tests__/modify-chart-scatter.test.js`
92
+ */
93
+ static { this.setChartCombo = (data) => (element, chart, workbook) => {
94
+ const slots = [];
159
95
  slots.push({
160
- label: `${series.label}-Size`,
161
- index: s,
162
- series: series,
163
- targetCol: colId + 3,
164
- type: 'customSeries',
165
- tag: 'c:bubbleSize',
166
- mapData: (point) => point.size,
167
- isStrRef: false,
96
+ index: 0,
97
+ series: data.series[0],
98
+ targetCol: 1,
99
+ type: 'defaultSeries',
168
100
  });
169
- });
170
- new modify_chart_1.ModifyChart(chart, workbook, data, slots).modify();
171
- // XmlHelper.dump(chart)
172
- };
173
- /**
174
- * Set chart data to modify extended chart types.
175
- * See `__tests__/modify-existing-extended-chart.test.js`
176
- */
177
- ModifyChartHelper.setExtendedChartData = (data) => (element, chart, workbook) => {
178
- const slots = [];
179
- data.series.forEach((series, s) => {
180
101
  slots.push({
181
- index: s,
182
- series: series,
183
- targetCol: s + 1,
184
- type: 'extendedSeries',
102
+ index: 1,
103
+ label: `Y-Values`,
104
+ mapData: (point, category) => category.y,
105
+ targetCol: 2,
185
106
  });
186
- });
187
- new modify_chart_1.ModifyChart(chart, workbook, data, slots).modifyExtended();
188
- // XmlHelper.dump(chart);
189
- // XmlHelper.dump(workbook.table)
190
- };
191
- /**
192
- * Read chart workbook data
193
- * See `__tests__/read-chart-data.test.js`
194
- */
195
- ModifyChartHelper.readWorkbookData = (data) => (element, chart, workbook) => {
196
- const getSharedString = (index) => {
197
- var _b;
198
- return (_b = workbook.sharedStrings.getElementsByTagName('si').item(index)) === null || _b === void 0 ? void 0 : _b.textContent;
199
- };
200
- const parseCell = (cell) => {
201
- const type = cell.getAttribute('t');
202
- const cellValue = cell.getElementsByTagName('v').item(0).textContent;
203
- if (type === 's') {
204
- return getSharedString(Number(cellValue));
205
- }
206
- else {
207
- return Number(cellValue);
208
- }
209
- };
210
- const rows = workbook.sheet.getElementsByTagName('row');
211
- for (let r = 0; r < rows.length; r++) {
212
- const row = rows.item(r);
213
- const columns = row.getElementsByTagName('c');
214
- const rowData = [];
215
- for (let c = 0; c < columns.length; c++) {
216
- rowData.push(parseCell(columns.item(c)));
217
- }
218
- data.push(rowData);
219
- }
220
- };
221
- /**
222
- * Read chart info
223
- * See `__tests__/read-chart-data.test.js`
224
- */
225
- ModifyChartHelper.readChartInfo = (info) => (element, chart, _workbook) => {
226
- const series = chart.getElementsByTagName('c:ser');
227
- xml_helper_1.XmlHelper.modifyCollection(series, (tmpSeries, s) => {
228
- const solidFill = tmpSeries.getElementsByTagName('a:solidFill').item(0);
229
- if (!solidFill) {
230
- return;
107
+ data.series.forEach((series, s) => {
108
+ if (s > 0)
109
+ slots.push({
110
+ index: s,
111
+ series: series,
112
+ targetCol: s + 2,
113
+ targetYCol: 2,
114
+ type: 'xySeries',
115
+ });
116
+ });
117
+ new modify_chart_1.ModifyChart(chart, workbook, data, slots).modify();
118
+ ModifyChartHelper.setAxisRange({
119
+ axisIndex: 1,
120
+ min: 0,
121
+ max: data.categories.length,
122
+ })(element, chart);
123
+ }; }
124
+ /**
125
+ * Set chart data to modify bubble charts.
126
+ * See `__tests__/modify-chart-bubbles.test.js`
127
+ */
128
+ static { this.setChartBubbles = (data) => (element, chart, workbook) => {
129
+ const slots = [];
130
+ data.series.forEach((series, s) => {
131
+ const colId = s * 3;
132
+ slots.push({
133
+ index: s,
134
+ series: series,
135
+ targetCol: colId + 1,
136
+ type: 'customSeries',
137
+ tag: 'c:xVal',
138
+ mapData: (point) => point.x,
139
+ });
140
+ slots.push({
141
+ label: `${series.label}-Y-Value`,
142
+ index: s,
143
+ series: series,
144
+ targetCol: colId + 2,
145
+ type: 'customSeries',
146
+ tag: 'c:yVal',
147
+ mapData: (point) => point.y,
148
+ isStrRef: false,
149
+ });
150
+ slots.push({
151
+ label: `${series.label}-Size`,
152
+ index: s,
153
+ series: series,
154
+ targetCol: colId + 3,
155
+ type: 'customSeries',
156
+ tag: 'c:bubbleSize',
157
+ mapData: (point) => point.size,
158
+ isStrRef: false,
159
+ });
160
+ });
161
+ new modify_chart_1.ModifyChart(chart, workbook, data, slots).modify();
162
+ // XmlHelper.dump(chart)
163
+ }; }
164
+ /**
165
+ * Set chart data to modify extended chart types.
166
+ * See `__tests__/modify-existing-extended-chart.test.js`
167
+ */
168
+ static { this.setExtendedChartData = (data) => (element, chart, workbook) => {
169
+ const slots = [];
170
+ data.series.forEach((series, s) => {
171
+ slots.push({
172
+ index: s,
173
+ series: series,
174
+ targetCol: s + 1,
175
+ type: 'extendedSeries',
176
+ });
177
+ });
178
+ new modify_chart_1.ModifyChart(chart, workbook, data, slots).modifyExtended();
179
+ // XmlHelper.dump(chart);
180
+ // XmlHelper.dump(workbook.table)
181
+ }; }
182
+ /**
183
+ * Read chart workbook data
184
+ * See `__tests__/read-chart-data.test.js`
185
+ */
186
+ static { this.readWorkbookData = (data) => (element, chart, workbook) => {
187
+ const getSharedString = (index) => {
188
+ return workbook.sharedStrings.getElementsByTagName('si').item(index)
189
+ ?.textContent;
190
+ };
191
+ const parseCell = (cell) => {
192
+ const type = cell.getAttribute('t');
193
+ const cellValue = cell.getElementsByTagName('v').item(0).textContent;
194
+ if (type === 's') {
195
+ return getSharedString(Number(cellValue));
196
+ }
197
+ else {
198
+ return Number(cellValue);
199
+ }
200
+ };
201
+ const rows = workbook.sheet.getElementsByTagName('row');
202
+ for (let r = 0; r < rows.length; r++) {
203
+ const row = rows.item(r);
204
+ const columns = row.getElementsByTagName('c');
205
+ const rowData = [];
206
+ for (let c = 0; c < columns.length; c++) {
207
+ rowData.push(parseCell(columns.item(c)));
208
+ }
209
+ data.push(rowData);
231
210
  }
232
- const schemeClr = solidFill.getElementsByTagName('a:schemeClr').item(0);
233
- const srgbClr = solidFill.getElementsByTagName('a:srgbClr').item(0);
234
- const colorElement = schemeClr ? schemeClr : srgbClr;
235
- info.series.push({
236
- seriesId: s,
237
- colorType: colorElement.tagName,
238
- colorValue: colorElement.getAttribute('val'),
211
+ }; }
212
+ /**
213
+ * Read chart info
214
+ * See `__tests__/read-chart-data.test.js`
215
+ */
216
+ static { this.readChartInfo = (info) => (element, chart, _workbook) => {
217
+ const series = chart.getElementsByTagName('c:ser');
218
+ xml_helper_1.XmlHelper.modifyCollection(series, (tmpSeries, s) => {
219
+ const solidFill = tmpSeries.getElementsByTagName('a:solidFill').item(0);
220
+ if (!solidFill) {
221
+ return;
222
+ }
223
+ const schemeClr = solidFill.getElementsByTagName('a:schemeClr').item(0);
224
+ const srgbClr = solidFill.getElementsByTagName('a:srgbClr').item(0);
225
+ const colorElement = schemeClr ? schemeClr : srgbClr;
226
+ info.series.push({
227
+ seriesId: s,
228
+ colorType: colorElement.tagName,
229
+ colorValue: colorElement.getAttribute('val'),
230
+ });
239
231
  });
240
- });
241
- const chartTagName = series.item(0).parentNode.nodeName;
242
- info.chartType = chartTagName === null || chartTagName === void 0 ? void 0 : chartTagName.split(':')[1];
243
- };
244
- /**
245
- * Set range and format for chart axis.
246
- * Please notice: It will only work if the value to update is not set to
247
- * "Auto" in powerpoint. Only manually scaled min/max can be altered by this.
248
- * See `__tests__/modify-chart-axis.test.js`
249
- */
250
- ModifyChartHelper.setAxisRange = (range) => (element, chart) => {
251
- const axis = chart.getElementsByTagName('c:valAx')[range.axisIndex || 0];
252
- if (!axis)
253
- return;
254
- _a.setAxisAttribute(axis, 'c:majorUnit', range.majorUnit);
255
- _a.setAxisAttribute(axis, 'c:minorUnit', range.minorUnit);
256
- _a.setAxisAttribute(axis, 'c:numFmt', range.formatCode, 'formatCode');
257
- _a.setAxisAttribute(axis, 'c:numFmt', range.sourceLinked, 'sourceLinked');
258
- const scaling = axis.getElementsByTagName('c:scaling')[0];
259
- _a.setAxisAttribute(scaling, 'c:min', range.min);
260
- _a.setAxisAttribute(scaling, 'c:max', range.max);
261
- };
262
- ModifyChartHelper.setAxisAttribute = (element, tag, value, attribute) => {
263
- if (value === undefined || !element)
264
- return;
265
- const target = element.getElementsByTagName(tag);
266
- if (target.length > 0) {
267
- attribute = attribute || 'val';
268
- if (typeof value === 'boolean') {
269
- modify_xml_helper_1.default.booleanAttribute(attribute, value)(target[0]);
232
+ const chartTagName = series.item(0).parentNode.nodeName;
233
+ info.chartType = chartTagName?.split(':')[1];
234
+ }; }
235
+ /**
236
+ * Set range and format for chart axis.
237
+ * Please notice: It will only work if the value to update is not set to
238
+ * "Auto" in powerpoint. Only manually scaled min/max can be altered by this.
239
+ * See `__tests__/modify-chart-axis.test.js`
240
+ */
241
+ static { this.setAxisRange = (range) => (element, chart) => {
242
+ const axis = chart.getElementsByTagName('c:valAx')[range.axisIndex || 0];
243
+ if (!axis)
244
+ return;
245
+ ModifyChartHelper.setAxisAttribute(axis, 'c:majorUnit', range.majorUnit);
246
+ ModifyChartHelper.setAxisAttribute(axis, 'c:minorUnit', range.minorUnit);
247
+ ModifyChartHelper.setAxisAttribute(axis, 'c:numFmt', range.formatCode, 'formatCode');
248
+ ModifyChartHelper.setAxisAttribute(axis, 'c:numFmt', range.sourceLinked, 'sourceLinked');
249
+ const scaling = axis.getElementsByTagName('c:scaling')[0];
250
+ ModifyChartHelper.setAxisAttribute(scaling, 'c:min', range.min);
251
+ ModifyChartHelper.setAxisAttribute(scaling, 'c:max', range.max);
252
+ }; }
253
+ static { this.setAxisAttribute = (element, tag, value, attribute) => {
254
+ if (value === undefined || !element)
255
+ return;
256
+ const target = element.getElementsByTagName(tag);
257
+ if (target.length > 0) {
258
+ attribute = attribute || 'val';
259
+ if (typeof value === 'boolean') {
260
+ modify_xml_helper_1.default.booleanAttribute(attribute, value)(target[0]);
261
+ }
262
+ else {
263
+ modify_xml_helper_1.default.attribute(attribute, value)(target[0]);
264
+ }
270
265
  }
271
- else {
272
- modify_xml_helper_1.default.attribute(attribute, value)(target[0]);
266
+ }; }
267
+ /**
268
+ * Set legend coordinates to zero. Could be advantageous for pptx users to
269
+ * be able to maximize a legend easily. Legend will still be selectible for
270
+ * a user.
271
+ */
272
+ static { this.minimizeChartLegend = () => (element, chart, workbook) => {
273
+ this.setLegendPosition({
274
+ w: 0.0,
275
+ h: 0.0,
276
+ x: 0.0,
277
+ y: 0.0,
278
+ })(element, chart, workbook);
279
+ }; }
280
+ /**
281
+ * Completely remove a chart legend. Please notice: This will trigger
282
+ * PowerPoint to automatically maximize chart space.
283
+ */
284
+ static { this.removeChartLegend = () => (element, chart) => {
285
+ if (chart.getElementsByTagName('c:legend')) {
286
+ xml_helper_1.XmlHelper.remove(chart.getElementsByTagName('c:legend')[0]);
273
287
  }
274
- }
275
- };
276
- /**
277
- * Set legend coordinates to zero. Could be advantageous for pptx users to
278
- * be able to maximize a legend easily. Legend will still be selectible for
279
- * a user.
280
- */
281
- ModifyChartHelper.minimizeChartLegend = () => (element, chart, workbook) => {
282
- _a.setLegendPosition({
283
- w: 0.0,
284
- h: 0.0,
285
- x: 0.0,
286
- y: 0.0,
287
- })(element, chart, workbook);
288
- };
289
- /**
290
- * Completely remove a chart legend. Please notice: This will trigger
291
- * PowerPoint to automatically maximize chart space.
292
- */
293
- ModifyChartHelper.removeChartLegend = () => (element, chart) => {
294
- if (chart.getElementsByTagName('c:legend')) {
295
- xml_helper_1.XmlHelper.remove(chart.getElementsByTagName('c:legend')[0]);
296
- }
297
- };
298
- /**
299
- * Update the coordinates of a chart legend.
300
- * legendArea coordinates are shares of chart coordinates, e.g.
301
- * "w: 0.5" means "half of chart width"
302
- * @param legendArea
303
- */
304
- ModifyChartHelper.setLegendPosition = (legendArea) => (element, chart) => {
305
- const modifyXmlHelper = new modify_xml_helper_1.default(chart);
306
- modifyXmlHelper.modify({
307
- 'c:legend': {
308
- children: {
309
- 'c:manualLayout': {
310
- children: {
311
- 'c:w': {
312
- modify: [modify_xml_helper_1.default.attribute('val', legendArea.w)],
313
- },
314
- 'c:h': {
315
- modify: [modify_xml_helper_1.default.attribute('val', legendArea.h)],
316
- },
317
- 'c:x': {
318
- modify: [modify_xml_helper_1.default.attribute('val', legendArea.x)],
319
- },
320
- 'c:y': {
321
- modify: [modify_xml_helper_1.default.attribute('val', legendArea.y)],
288
+ }; }
289
+ /**
290
+ * Update the coordinates of a chart legend.
291
+ * legendArea coordinates are shares of chart coordinates, e.g.
292
+ * "w: 0.5" means "half of chart width"
293
+ * @param legendArea
294
+ */
295
+ static { this.setLegendPosition = (legendArea) => (element, chart) => {
296
+ const modifyXmlHelper = new modify_xml_helper_1.default(chart);
297
+ modifyXmlHelper.modify({
298
+ 'c:legend': {
299
+ children: {
300
+ 'c:manualLayout': {
301
+ children: {
302
+ 'c:w': {
303
+ modify: [modify_xml_helper_1.default.attribute('val', legendArea.w)],
304
+ },
305
+ 'c:h': {
306
+ modify: [modify_xml_helper_1.default.attribute('val', legendArea.h)],
307
+ },
308
+ 'c:x': {
309
+ modify: [modify_xml_helper_1.default.attribute('val', legendArea.x)],
310
+ },
311
+ 'c:y': {
312
+ modify: [modify_xml_helper_1.default.attribute('val', legendArea.y)],
313
+ },
322
314
  },
323
315
  },
324
316
  },
325
317
  },
326
- },
327
- });
328
- // XmlHelper.dump(chart.getElementsByTagName('c:legendPos')[0]);
329
- };
330
- /**
331
- * Set the plot area coordinates of a chart.
332
- *
333
- * This modifier requires a 'c:manualLayout' element. It will only appear if
334
- * plot area coordinates are edited manually in ppt before. Recently fresh
335
- * created charts will not have a manualLayout by default.
336
- *
337
- * This is especially useful if you have problems with edgy elements on a
338
- * chart area that do not fit into the given space, e.g. when having a lot
339
- * of data labels. You can increase the chart and decrease the plot area
340
- * to create a margin.
341
- *
342
- * plotArea coordinates are shares of chart coordinates, e.g.
343
- * "w: 0.5" means "half of chart width"
344
- *
345
- * @param plotArea
346
- */
347
- ModifyChartHelper.setPlotArea = (plotArea) => (element, chart) => {
348
- // Each chart has a separate chart xml file. It is required
349
- // to alter everything that's "inside" the chart, e.g. data, legend,
350
- // axis... and: plot area
351
- // ModifyXmlHelper class provides a lot of functions to access
352
- // and edit xml elements.
353
- const modifyXmlHelper = new modify_xml_helper_1.default(chart);
354
- // We need to locate the required xml elements and target them
355
- // with ModifyXmlHelper's help.
356
- // We can therefore log the entire chart.xml to console:
357
- // XmlHelper.dump(chart);
358
- // There needs to be a 'c:manualLayout' element. This will only appear if
359
- // a plot area was edited manually in ppt before. Recently fresh created
360
- // charts will not have a manualLayout by default.
361
- if (!chart
362
- .getElementsByTagName('c:plotArea')[0]
363
- .getElementsByTagName('c:manualLayout')[0]) {
364
- logger_1.log.error("Can't update plot area. No c:manualLayout found.");
365
- return;
366
- }
367
- modifyXmlHelper.modify({
368
- 'c:plotArea': {
369
- children: {
370
- 'c:manualLayout': {
371
- children: {
372
- 'c:w': {
373
- // Finally, we attach ModifyCallbacks to all
374
- // matching elements
375
- modify: [
376
- modify_xml_helper_1.default.attribute('val', plotArea.w),
377
- // ...
378
- ],
379
- },
380
- 'c:h': {
381
- modify: [modify_xml_helper_1.default.attribute('val', plotArea.h)],
382
- },
383
- 'c:x': {
384
- modify: [modify_xml_helper_1.default.attribute('val', plotArea.x)],
385
- },
386
- 'c:y': {
387
- modify: [modify_xml_helper_1.default.attribute('val', plotArea.y)],
318
+ });
319
+ // XmlHelper.dump(chart.getElementsByTagName('c:legendPos')[0]);
320
+ }; }
321
+ /**
322
+ * Set the plot area coordinates of a chart.
323
+ *
324
+ * This modifier requires a 'c:manualLayout' element. It will only appear if
325
+ * plot area coordinates are edited manually in ppt before. Recently fresh
326
+ * created charts will not have a manualLayout by default.
327
+ *
328
+ * This is especially useful if you have problems with edgy elements on a
329
+ * chart area that do not fit into the given space, e.g. when having a lot
330
+ * of data labels. You can increase the chart and decrease the plot area
331
+ * to create a margin.
332
+ *
333
+ * plotArea coordinates are shares of chart coordinates, e.g.
334
+ * "w: 0.5" means "half of chart width"
335
+ *
336
+ * @param plotArea
337
+ */
338
+ static { this.setPlotArea = (plotArea) => (element, chart) => {
339
+ // Each chart has a separate chart xml file. It is required
340
+ // to alter everything that's "inside" the chart, e.g. data, legend,
341
+ // axis... and: plot area
342
+ // ModifyXmlHelper class provides a lot of functions to access
343
+ // and edit xml elements.
344
+ const modifyXmlHelper = new modify_xml_helper_1.default(chart);
345
+ // We need to locate the required xml elements and target them
346
+ // with ModifyXmlHelper's help.
347
+ // We can therefore log the entire chart.xml to console:
348
+ // XmlHelper.dump(chart);
349
+ // There needs to be a 'c:manualLayout' element. This will only appear if
350
+ // a plot area was edited manually in ppt before. Recently fresh created
351
+ // charts will not have a manualLayout by default.
352
+ if (!chart
353
+ .getElementsByTagName('c:plotArea')[0]
354
+ .getElementsByTagName('c:manualLayout')[0]) {
355
+ logger_1.log.error("Can't update plot area. No c:manualLayout found.");
356
+ return;
357
+ }
358
+ modifyXmlHelper.modify({
359
+ 'c:plotArea': {
360
+ children: {
361
+ 'c:manualLayout': {
362
+ children: {
363
+ 'c:w': {
364
+ // Finally, we attach ModifyCallbacks to all
365
+ // matching elements
366
+ modify: [
367
+ modify_xml_helper_1.default.attribute('val', plotArea.w),
368
+ // ...
369
+ ],
370
+ },
371
+ 'c:h': {
372
+ modify: [modify_xml_helper_1.default.attribute('val', plotArea.h)],
373
+ },
374
+ 'c:x': {
375
+ modify: [modify_xml_helper_1.default.attribute('val', plotArea.x)],
376
+ },
377
+ 'c:y': {
378
+ modify: [modify_xml_helper_1.default.attribute('val', plotArea.y)],
379
+ },
388
380
  },
389
381
  },
390
382
  },
391
383
  },
392
- },
393
- });
394
- // We can dump the target node and see if our modification
395
- // took effect.
396
- // XmlHelper.dump(
397
- // chart
398
- // .getElementsByTagName('c:plotArea')[0]
399
- // .getElementsByTagName('c:manualLayout')[0],
400
- // );
401
- // You can also take a look at element xml, which is a child node
402
- // of current slide. It holds general shape properties, but no
403
- // data or so.
404
- // XmlHelper.dump(chart);
405
- // Rough ones might also want to look inside the linked workbook.
406
- // It is located inside an extra xlsx file. We don't need this
407
- // for now.
408
- // XmlHelper.dump(workbook.table)
409
- // XmlHelper.dump(workbook.sheet)
410
- };
411
- /**
412
- * Set a waterfall Total column to last
413
- * you may also optionally specify a different index.
414
- @param TotalColumnIDX
415
- *
416
- */
417
- ModifyChartHelper.setWaterFallColumnTotalToLast = (TotalColumnIDX) => (element, chart) => {
418
- var _b, _c, _d, _e, _f;
419
- const plotArea = chart.getElementsByTagName('cx:plotArea')[0];
420
- const subTotals = (_b = plotArea === null || plotArea === void 0 ? void 0 : plotArea.getElementsByTagName('cx:layoutPr')[0]) === null || _b === void 0 ? void 0 : _b.getElementsByTagName('cx:subtotals')[0];
421
- if (subTotals) {
422
- if (!TotalColumnIDX) {
423
- const GetTotalPoints = (_f = (_e = (_d = (_c = chart
424
- .getElementsByTagName('cx:chartData')[0]) === null || _c === void 0 ? void 0 : _c.getElementsByTagName('cx:data')[0]) === null || _d === void 0 ? void 0 : _d.getElementsByTagName('cx:strDim')[0]) === null || _e === void 0 ? void 0 : _e.getElementsByTagName('cx:lvl')[0]) === null || _f === void 0 ? void 0 : _f.getAttribute('ptCount');
425
- if (GetTotalPoints) {
426
- TotalColumnIDX = Number(GetTotalPoints) - 1;
384
+ });
385
+ // We can dump the target node and see if our modification
386
+ // took effect.
387
+ // XmlHelper.dump(
388
+ // chart
389
+ // .getElementsByTagName('c:plotArea')[0]
390
+ // .getElementsByTagName('c:manualLayout')[0],
391
+ // );
392
+ // You can also take a look at element xml, which is a child node
393
+ // of current slide. It holds general shape properties, but no
394
+ // data or so.
395
+ // XmlHelper.dump(chart);
396
+ // Rough ones might also want to look inside the linked workbook.
397
+ // It is located inside an extra xlsx file. We don't need this
398
+ // for now.
399
+ // XmlHelper.dump(workbook.table)
400
+ // XmlHelper.dump(workbook.sheet)
401
+ }; }
402
+ /**
403
+ * Set a waterfall Total column to last
404
+ * you may also optionally specify a different index.
405
+ @param TotalColumnIDX
406
+ *
407
+ */
408
+ static { this.setWaterFallColumnTotalToLast = (TotalColumnIDX) => (element, chart) => {
409
+ const plotArea = chart.getElementsByTagName('cx:plotArea')[0];
410
+ const subTotals = plotArea
411
+ ?.getElementsByTagName('cx:layoutPr')[0]
412
+ ?.getElementsByTagName('cx:subtotals')[0];
413
+ if (subTotals) {
414
+ if (!TotalColumnIDX) {
415
+ const GetTotalPoints = chart
416
+ .getElementsByTagName('cx:chartData')[0]
417
+ ?.getElementsByTagName('cx:data')[0]
418
+ ?.getElementsByTagName('cx:strDim')[0]
419
+ ?.getElementsByTagName('cx:lvl')[0]
420
+ ?.getAttribute('ptCount');
421
+ if (GetTotalPoints) {
422
+ TotalColumnIDX = Number(GetTotalPoints) - 1;
423
+ }
424
+ }
425
+ if (TotalColumnIDX !== undefined) {
426
+ const stIndexes = Array.from(subTotals.getElementsByTagName('cx:idx'));
427
+ stIndexes.forEach((sTValue, index) => {
428
+ modify_xml_helper_1.default.attribute('val', TotalColumnIDX.toString())(sTValue);
429
+ if (index > 0) {
430
+ subTotals.removeChild(sTValue);
431
+ }
432
+ });
427
433
  }
428
434
  }
429
- if (TotalColumnIDX !== undefined) {
430
- const stIndexes = Array.from(subTotals.getElementsByTagName('cx:idx'));
431
- stIndexes.forEach((sTValue, index) => {
432
- modify_xml_helper_1.default.attribute('val', TotalColumnIDX.toString())(sTValue);
433
- if (index > 0) {
434
- subTotals.removeChild(sTValue);
435
+ }; }
436
+ /**
437
+ * Set the title of a chart. This requires an already existing, manually edited chart title.
438
+ @param newTitle
439
+ *
440
+ */
441
+ static { this.setChartTitle = (newTitle) => (element, chart) => {
442
+ const chartTitle = chart.getElementsByTagName('c:title').item(0);
443
+ const chartTitleText = chartTitle?.getElementsByTagName('a:t').item(0);
444
+ if (chartTitleText) {
445
+ chartTitleText.textContent = xml_helper_1.XmlHelper.sanitizeText(newTitle);
446
+ }
447
+ }; }
448
+ /**
449
+ * Remove datalabels of a chart.
450
+ */
451
+ static { this.removeDataLabels = () => (element, chart) => {
452
+ const dLbls = chart.getElementsByTagName('c:dLbls');
453
+ Array.from(dLbls).forEach((dLbl) => {
454
+ dLbl.parentNode.removeChild(dLbl);
455
+ });
456
+ }; }
457
+ static { this.setPointLabelSuffix = (element, idx, labelStyle) => {
458
+ const doc = element.ownerDocument;
459
+ // Convert c:txPr to c:tx > c:rich so PowerPoint renders text runs.
460
+ const txPr = element.getElementsByTagName('c:txPr')[0];
461
+ if (txPr) {
462
+ const tx = doc.createElement('c:tx');
463
+ const rich = doc.createElement('c:rich');
464
+ while (txPr.firstChild) {
465
+ rich.appendChild(txPr.firstChild);
466
+ }
467
+ tx.appendChild(rich);
468
+ txPr.parentNode.insertBefore(tx, txPr);
469
+ txPr.parentNode.removeChild(txPr);
470
+ }
471
+ const paragraphs = element.getElementsByTagName('a:p');
472
+ if (!paragraphs.length)
473
+ return;
474
+ const p = paragraphs[0];
475
+ // Remove any existing a:r and a:fld elements that may have been
476
+ // carried over from cloning a previously modified c:dLbl.
477
+ const existingRuns = Array.from(p.getElementsByTagName('a:r'));
478
+ existingRuns.forEach((run) => run.parentNode.removeChild(run));
479
+ const existingFlds = Array.from(p.getElementsByTagName('a:fld'));
480
+ existingFlds.forEach((fld) => fld.parentNode.removeChild(fld));
481
+ // Add a:fld element to display the chart value
482
+ const endParaRPr = p.getElementsByTagName('a:endParaRPr')[0];
483
+ const defRPr = p.getElementsByTagName('a:defRPr')[0];
484
+ const fld = doc.createElement('a:fld');
485
+ fld.setAttribute('type', 'VALUE');
486
+ fld.setAttribute('id', '{AABBCCDD-1234-5678-9012-' + String(idx).padStart(12, '0') + '}');
487
+ const fldRPr = doc.createElement('a:rPr');
488
+ fldRPr.setAttribute('lang', 'en-US');
489
+ if (defRPr) {
490
+ Array.from(defRPr.childNodes).forEach((child) => {
491
+ fldRPr.appendChild(child.cloneNode(true));
492
+ });
493
+ Array.from(defRPr.attributes).forEach((attr) => {
494
+ if (attr.name !== 'sz' && attr.name !== 'b') {
495
+ fldRPr.setAttribute(attr.name, attr.value);
435
496
  }
436
497
  });
437
498
  }
438
- }
439
- };
440
- /**
441
- * Set the title of a chart. This requires an already existing, manually edited chart title.
442
- @param newTitle
443
- *
444
- */
445
- ModifyChartHelper.setChartTitle = (newTitle) => (element, chart) => {
446
- const chartTitle = chart.getElementsByTagName('c:title').item(0);
447
- const chartTitleText = chartTitle === null || chartTitle === void 0 ? void 0 : chartTitle.getElementsByTagName('a:t').item(0);
448
- if (chartTitleText) {
449
- chartTitleText.textContent = xml_helper_1.XmlHelper.sanitizeText(newTitle);
450
- }
451
- };
452
- /**
453
- * Remove datalabels of a chart.
454
- */
455
- ModifyChartHelper.removeDataLabels = () => (element, chart) => {
456
- const dLbls = chart.getElementsByTagName('c:dLbls');
457
- Array.from(dLbls).forEach((dLbl) => {
458
- dLbl.parentNode.removeChild(dLbl);
459
- });
460
- };
461
- ModifyChartHelper.setPointLabelSuffix = (element, idx, labelStyle) => {
462
- const doc = element.ownerDocument;
463
- // Convert c:txPr to c:tx > c:rich so PowerPoint renders text runs.
464
- const txPr = element.getElementsByTagName('c:txPr')[0];
465
- if (txPr) {
466
- const tx = doc.createElement('c:tx');
467
- const rich = doc.createElement('c:rich');
468
- while (txPr.firstChild) {
469
- rich.appendChild(txPr.firstChild);
499
+ fld.appendChild(fldRPr);
500
+ const fldT = doc.createElement('a:t');
501
+ fldT.textContent = '[VALUE]';
502
+ fld.appendChild(fldT);
503
+ if (endParaRPr) {
504
+ p.insertBefore(fld, endParaRPr);
470
505
  }
471
- tx.appendChild(rich);
472
- txPr.parentNode.insertBefore(tx, txPr);
473
- txPr.parentNode.removeChild(txPr);
474
- }
475
- const paragraphs = element.getElementsByTagName('a:p');
476
- if (!paragraphs.length)
477
- return;
478
- const p = paragraphs[0];
479
- // Remove any existing a:r and a:fld elements that may have been
480
- // carried over from cloning a previously modified c:dLbl.
481
- const existingRuns = Array.from(p.getElementsByTagName('a:r'));
482
- existingRuns.forEach((run) => run.parentNode.removeChild(run));
483
- const existingFlds = Array.from(p.getElementsByTagName('a:fld'));
484
- existingFlds.forEach((fld) => fld.parentNode.removeChild(fld));
485
- // Add a:fld element to display the chart value
486
- const endParaRPr = p.getElementsByTagName('a:endParaRPr')[0];
487
- const defRPr = p.getElementsByTagName('a:defRPr')[0];
488
- const fld = doc.createElement('a:fld');
489
- fld.setAttribute('type', 'VALUE');
490
- fld.setAttribute('id', '{AABBCCDD-1234-5678-9012-' + String(idx).padStart(12, '0') + '}');
491
- const fldRPr = doc.createElement('a:rPr');
492
- fldRPr.setAttribute('lang', 'en-US');
493
- if (defRPr) {
494
- Array.from(defRPr.childNodes).forEach((child) => {
495
- fldRPr.appendChild(child.cloneNode(true));
496
- });
497
- Array.from(defRPr.attributes).forEach((attr) => {
498
- if (attr.name !== 'sz' && attr.name !== 'b') {
499
- fldRPr.setAttribute(attr.name, attr.value);
500
- }
501
- });
502
- }
503
- fld.appendChild(fldRPr);
504
- const fldT = doc.createElement('a:t');
505
- fldT.textContent = '[VALUE]';
506
- fld.appendChild(fldT);
507
- if (endParaRPr) {
508
- p.insertBefore(fld, endParaRPr);
509
- }
510
- else {
511
- p.appendChild(fld);
512
- }
513
- // Add the suffix a:r
514
- const r = doc.createElement('a:r');
515
- const rPr = doc.createElement('a:rPr');
516
- rPr.setAttribute('lang', 'en-US');
517
- rPr.setAttribute('dirty', '0');
518
- if (labelStyle.suffix.color) {
519
- const color = Object.assign({}, labelStyle.suffix.color);
520
- if (color.value.indexOf('#') === 0) {
521
- color.value = color.value.replace('#', '');
506
+ else {
507
+ p.appendChild(fld);
522
508
  }
523
- const solidFill = doc.createElement('a:solidFill');
524
- const colorEl = doc.createElement('a:' + color.type);
525
- colorEl.setAttribute('val', color.value);
526
- solidFill.appendChild(colorEl);
527
- rPr.appendChild(solidFill);
528
- }
529
- r.appendChild(rPr);
530
- const t = doc.createElement('a:t');
531
- t.textContent = labelStyle.suffix.text;
532
- r.appendChild(t);
533
- const endParaRPr2 = p.getElementsByTagName('a:endParaRPr')[0];
534
- if (endParaRPr2) {
535
- p.insertBefore(r, endParaRPr2);
536
- }
537
- else {
538
- p.appendChild(r);
539
- }
540
- // Prevent line breaks in the data label by setting wrap="none"
541
- const bodyPrs = element.getElementsByTagName('a:bodyPr');
542
- if (bodyPrs.length) {
543
- bodyPrs[0].setAttribute('wrap', 'none');
544
- }
545
- // Preserve the number format of the datalabel if it exists in the series or the current label.
546
- // If it's missing in the current c:dLbl, look into the parent c:dLbls.
547
- if (!element.getElementsByTagName('c:numFmt').length) {
548
- const dLbls = element.parentNode;
549
- if (dLbls && dLbls.nodeName === 'c:dLbls') {
550
- const numFmt = dLbls.getElementsByTagName('c:numFmt')[0];
551
- if (numFmt) {
552
- element.insertBefore(numFmt.cloneNode(true), element.firstChild);
509
+ // Add the suffix a:r
510
+ const r = doc.createElement('a:r');
511
+ const rPr = doc.createElement('a:rPr');
512
+ rPr.setAttribute('lang', 'en-US');
513
+ rPr.setAttribute('dirty', '0');
514
+ if (labelStyle.suffix.color) {
515
+ const color = { ...labelStyle.suffix.color };
516
+ if (color.value.indexOf('#') === 0) {
517
+ color.value = color.value.replace('#', '');
553
518
  }
519
+ const solidFill = doc.createElement('a:solidFill');
520
+ const colorEl = doc.createElement('a:' + color.type);
521
+ colorEl.setAttribute('val', color.value);
522
+ solidFill.appendChild(colorEl);
523
+ rPr.appendChild(solidFill);
554
524
  }
555
- }
556
- };
557
- /**
558
- * Specify a format for DataLabels
559
- @param dataLabel
560
- *
561
- */
562
- ModifyChartHelper.setDataLabelAttributes = (dataLabel) => (element, chart) => {
563
- const modifyXmlHelper = new modify_xml_helper_1.default(chart);
564
- const applyToSeries = typeof dataLabel.applyToSeries === 'number'
565
- ? {
566
- index: dataLabel.applyToSeries,
525
+ r.appendChild(rPr);
526
+ const t = doc.createElement('a:t');
527
+ t.textContent = labelStyle.suffix.text;
528
+ r.appendChild(t);
529
+ const endParaRPr2 = p.getElementsByTagName('a:endParaRPr')[0];
530
+ if (endParaRPr2) {
531
+ p.insertBefore(r, endParaRPr2);
567
532
  }
568
- : {
569
- all: true,
570
- };
571
- modifyXmlHelper.modify({
572
- 'c:ser': Object.assign(Object.assign({}, applyToSeries), { children: {
573
- 'c:dLbls': {
574
- // Modify label attributes only where the template carries
575
- // labels — never fabricate a c:dLbls into a series.
576
- isRequired: false,
577
- children: _a.setDataPointLabelAttributes(dataLabel),
533
+ else {
534
+ p.appendChild(r);
535
+ }
536
+ // Prevent line breaks in the data label by setting wrap="none"
537
+ const bodyPrs = element.getElementsByTagName('a:bodyPr');
538
+ if (bodyPrs.length) {
539
+ bodyPrs[0].setAttribute('wrap', 'none');
540
+ }
541
+ // Preserve the number format of the datalabel if it exists in the series or the current label.
542
+ // If it's missing in the current c:dLbl, look into the parent c:dLbls.
543
+ if (!element.getElementsByTagName('c:numFmt').length) {
544
+ const dLbls = element.parentNode;
545
+ if (dLbls && dLbls.nodeName === 'c:dLbls') {
546
+ const numFmt = dLbls.getElementsByTagName('c:numFmt')[0];
547
+ if (numFmt) {
548
+ element.insertBefore(numFmt.cloneNode(true), element.firstChild);
549
+ }
550
+ }
551
+ }
552
+ }; }
553
+ /**
554
+ * Specify a format for DataLabels
555
+ @param dataLabel
556
+ *
557
+ */
558
+ static { this.setDataLabelAttributes = (dataLabel) => (element, chart) => {
559
+ const modifyXmlHelper = new modify_xml_helper_1.default(chart);
560
+ const applyToSeries = typeof dataLabel.applyToSeries === 'number'
561
+ ? {
562
+ index: dataLabel.applyToSeries,
563
+ }
564
+ : {
565
+ all: true,
566
+ };
567
+ modifyXmlHelper.modify({
568
+ 'c:ser': {
569
+ ...applyToSeries,
570
+ children: {
571
+ 'c:dLbls': {
572
+ // Modify label attributes only where the template carries
573
+ // labels — never fabricate a c:dLbls into a series.
574
+ isRequired: false,
575
+ children: ModifyChartHelper.setDataPointLabelAttributes(dataLabel),
576
+ },
578
577
  },
579
- } }),
580
- });
581
- };
582
- ModifyChartHelper.setDataPointLabelAttributes = (dataLabel) => {
583
- return {
584
- 'c:spPr': {
585
- isRequired: false,
586
- modify: [modify_color_helper_1.default.solidFill(dataLabel.solidFill)],
587
- },
588
- 'c:numFmt': {
589
- isRequired: false,
590
- modify: [
591
- modify_xml_helper_1.default.attribute('formatCode', dataLabel.formatCode),
592
- modify_xml_helper_1.default.booleanAttribute('sourceLinked', dataLabel.sourceLinked),
593
- ],
594
- },
595
- 'c:dLblPos': {
596
- isRequired: false,
597
- modify: [modify_xml_helper_1.default.attribute('val', dataLabel.dLblPos)],
598
- },
599
- 'c:showLegendKey': {
600
- isRequired: false,
601
- modify: [
602
- modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showLegendKey),
603
- ],
604
- },
605
- 'c:showVal': {
606
- isRequired: false,
607
- modify: [modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showVal)],
608
- },
609
- 'c:showCatName': {
610
- isRequired: false,
611
- modify: [
612
- modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showCatName),
613
- ],
614
- },
615
- 'c:showSerName': {
616
- isRequired: false,
617
- modify: [
618
- modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showSerName),
619
- ],
620
- },
621
- 'c:showPercent': {
622
- isRequired: false,
623
- modify: [
624
- modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showPercent),
625
- ],
626
- },
627
- 'c:showBubbleSize': {
628
- isRequired: false,
629
- modify: [
630
- modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showBubbleSize),
631
- ],
632
- },
633
- 'c:showLeaderLines': {
634
- isRequired: false,
635
- modify: [
636
- modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showLeaderLines),
637
- ],
638
- },
639
- };
640
- };
578
+ },
579
+ });
580
+ }; }
581
+ static { this.setDataPointLabelAttributes = (dataLabel) => {
582
+ return {
583
+ 'c:spPr': {
584
+ isRequired: false,
585
+ modify: [modify_color_helper_1.default.solidFill(dataLabel.solidFill)],
586
+ },
587
+ 'c:numFmt': {
588
+ isRequired: false,
589
+ modify: [
590
+ modify_xml_helper_1.default.attribute('formatCode', dataLabel.formatCode),
591
+ modify_xml_helper_1.default.booleanAttribute('sourceLinked', dataLabel.sourceLinked),
592
+ ],
593
+ },
594
+ 'c:dLblPos': {
595
+ isRequired: false,
596
+ modify: [modify_xml_helper_1.default.attribute('val', dataLabel.dLblPos)],
597
+ },
598
+ 'c:showLegendKey': {
599
+ isRequired: false,
600
+ modify: [
601
+ modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showLegendKey),
602
+ ],
603
+ },
604
+ 'c:showVal': {
605
+ isRequired: false,
606
+ modify: [modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showVal)],
607
+ },
608
+ 'c:showCatName': {
609
+ isRequired: false,
610
+ modify: [
611
+ modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showCatName),
612
+ ],
613
+ },
614
+ 'c:showSerName': {
615
+ isRequired: false,
616
+ modify: [
617
+ modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showSerName),
618
+ ],
619
+ },
620
+ 'c:showPercent': {
621
+ isRequired: false,
622
+ modify: [
623
+ modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showPercent),
624
+ ],
625
+ },
626
+ 'c:showBubbleSize': {
627
+ isRequired: false,
628
+ modify: [
629
+ modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showBubbleSize),
630
+ ],
631
+ },
632
+ 'c:showLeaderLines': {
633
+ isRequired: false,
634
+ modify: [
635
+ modify_xml_helper_1.default.booleanAttribute('val', dataLabel.showLeaderLines),
636
+ ],
637
+ },
638
+ };
639
+ }; }
640
+ // Prevent a "null" from being written to the xml file.
641
+ static parseCellValue(value) {
642
+ if (value === null)
643
+ return '';
644
+ return String(value);
645
+ }
646
+ }
641
647
  exports.default = ModifyChartHelper;
642
648
  //# sourceMappingURL=modify-chart-helper.js.map