pptx-templates 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AI-INSTRUCTOR.md +2253 -0
- package/CHANGELOG.md +49 -0
- package/LICENSE +23 -0
- package/README.md +86 -2
- package/dist/automizer.d.ts +224 -0
- package/dist/automizer.js +704 -0
- package/dist/automizer.js.map +1 -0
- package/dist/classes/content-type-registry.d.ts +46 -0
- package/dist/classes/content-type-registry.js +170 -0
- package/dist/classes/content-type-registry.js.map +1 -0
- package/dist/classes/element-importer.d.ts +49 -0
- package/dist/classes/element-importer.js +254 -0
- package/dist/classes/element-importer.js.map +1 -0
- package/dist/classes/has-shapes.d.ts +286 -0
- package/dist/classes/has-shapes.js +385 -0
- package/dist/classes/has-shapes.js.map +1 -0
- package/dist/classes/layout.d.ts +42 -0
- package/dist/classes/layout.js +113 -0
- package/dist/classes/layout.js.map +1 -0
- package/dist/classes/master.d.ts +45 -0
- package/dist/classes/master.js +146 -0
- package/dist/classes/master.js.map +1 -0
- package/dist/classes/placeholder-normalizer.d.ts +42 -0
- package/dist/classes/placeholder-normalizer.js +136 -0
- package/dist/classes/placeholder-normalizer.js.map +1 -0
- package/dist/classes/related-content-copier.d.ts +18 -0
- package/dist/classes/related-content-copier.js +114 -0
- package/dist/classes/related-content-copier.js.map +1 -0
- package/dist/classes/shape.d.ts +62 -0
- package/dist/classes/shape.js +194 -0
- package/dist/classes/shape.js.map +1 -0
- package/dist/classes/slide-master-remover.d.ts +44 -0
- package/dist/classes/slide-master-remover.js +201 -0
- package/dist/classes/slide-master-remover.js.map +1 -0
- package/dist/classes/slide-notes-copier.d.ts +26 -0
- package/dist/classes/slide-notes-copier.js +76 -0
- package/dist/classes/slide-notes-copier.js.map +1 -0
- package/dist/classes/slide.d.ts +91 -0
- package/dist/classes/slide.js +286 -0
- package/dist/classes/slide.js.map +1 -0
- package/dist/classes/template.d.ts +137 -0
- package/dist/classes/template.js +311 -0
- package/dist/classes/template.js.map +1 -0
- package/dist/constants/constants.d.ts +11 -0
- package/dist/constants/constants.js +182 -0
- package/dist/constants/constants.js.map +1 -0
- package/dist/enums/chart-type.d.ts +11 -0
- package/dist/enums/chart-type.js +16 -0
- package/dist/enums/chart-type.js.map +1 -0
- package/dist/enums/content-type-map.d.ts +16 -0
- package/dist/enums/content-type-map.js +23 -0
- package/dist/enums/content-type-map.js.map +1 -0
- package/dist/enums/element-type.d.ts +14 -0
- package/dist/enums/element-type.js +20 -0
- package/dist/enums/element-type.js.map +1 -0
- package/dist/errors.d.ts +81 -0
- package/dist/errors.js +100 -0
- package/dist/errors.js.map +1 -0
- package/dist/extensions/index.d.ts +5 -0
- package/dist/extensions/index.js +31 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/pptxgenjs-compat/img-broken-png.d.ts +5 -0
- package/dist/extensions/pptxgenjs-compat/img-broken-png.js +9 -0
- package/dist/extensions/pptxgenjs-compat/img-broken-png.js.map +1 -0
- package/dist/extensions/pptxgenjs-compat/index.d.ts +5 -0
- package/dist/extensions/pptxgenjs-compat/index.js +10 -0
- package/dist/extensions/pptxgenjs-compat/index.js.map +1 -0
- package/dist/extensions/pptxgenjs-compat/svg-fallback.d.ts +14 -0
- package/dist/extensions/pptxgenjs-compat/svg-fallback.js +139 -0
- package/dist/extensions/pptxgenjs-compat/svg-fallback.js.map +1 -0
- package/dist/extensions/template-logic/commands.d.ts +22 -0
- package/dist/extensions/template-logic/commands.js +83 -0
- package/dist/extensions/template-logic/commands.js.map +1 -0
- package/dist/extensions/template-logic/expression.d.ts +61 -0
- package/dist/extensions/template-logic/expression.js +499 -0
- package/dist/extensions/template-logic/expression.js.map +1 -0
- package/dist/extensions/template-logic/images.d.ts +26 -0
- package/dist/extensions/template-logic/images.js +183 -0
- package/dist/extensions/template-logic/images.js.map +1 -0
- package/dist/extensions/template-logic/index.d.ts +14 -0
- package/dist/extensions/template-logic/index.js +64 -0
- package/dist/extensions/template-logic/index.js.map +1 -0
- package/dist/extensions/template-logic/list-commands.d.ts +9 -0
- package/dist/extensions/template-logic/list-commands.js +72 -0
- package/dist/extensions/template-logic/list-commands.js.map +1 -0
- package/dist/extensions/template-logic/renderer.d.ts +85 -0
- package/dist/extensions/template-logic/renderer.js +867 -0
- package/dist/extensions/template-logic/renderer.js.map +1 -0
- package/dist/extensions/template-logic/types.d.ts +62 -0
- package/dist/extensions/template-logic/types.js +3 -0
- package/dist/extensions/template-logic/types.js.map +1 -0
- package/dist/helper/archive/archive-fs.d.ts +45 -0
- package/dist/helper/archive/archive-fs.js +206 -0
- package/dist/helper/archive/archive-fs.js.map +1 -0
- package/dist/helper/archive/archive-jszip.d.ts +31 -0
- package/dist/helper/archive/archive-jszip.js +173 -0
- package/dist/helper/archive/archive-jszip.js.map +1 -0
- package/dist/helper/archive/archive.d.ts +27 -0
- package/dist/helper/archive/archive.js +78 -0
- package/dist/helper/archive/archive.js.map +1 -0
- package/dist/helper/cell-id-helper.d.ts +25 -0
- package/dist/helper/cell-id-helper.js +95 -0
- package/dist/helper/cell-id-helper.js.map +1 -0
- package/dist/helper/compute-src-rect.d.ts +9 -0
- package/dist/helper/compute-src-rect.js +52 -0
- package/dist/helper/compute-src-rect.js.map +1 -0
- package/dist/helper/content-tracker.d.ts +31 -0
- package/dist/helper/content-tracker.js +227 -0
- package/dist/helper/content-tracker.js.map +1 -0
- package/dist/helper/count-helper.d.ts +33 -0
- package/dist/helper/count-helper.js +140 -0
- package/dist/helper/count-helper.js.map +1 -0
- package/dist/helper/css-style-parser.d.ts +52 -0
- package/dist/helper/css-style-parser.js +246 -0
- package/dist/helper/css-style-parser.js.map +1 -0
- package/dist/helper/file-helper.d.ts +36 -0
- package/dist/helper/file-helper.js +150 -0
- package/dist/helper/file-helper.js.map +1 -0
- package/dist/helper/general-helper.d.ts +6 -0
- package/dist/helper/general-helper.js +34 -0
- package/dist/helper/general-helper.js.map +1 -0
- package/dist/helper/generate/generate-pptxgenjs.d.ts +37 -0
- package/dist/helper/generate/generate-pptxgenjs.js +134 -0
- package/dist/helper/generate/generate-pptxgenjs.js.map +1 -0
- package/dist/helper/html-to-multitext-helper.d.ts +84 -0
- package/dist/helper/html-to-multitext-helper.js +490 -0
- package/dist/helper/html-to-multitext-helper.js.map +1 -0
- package/dist/helper/hyperlink-processor.d.ts +54 -0
- package/dist/helper/hyperlink-processor.js +289 -0
- package/dist/helper/hyperlink-processor.js.map +1 -0
- package/dist/helper/image-dimensions.d.ts +21 -0
- package/dist/helper/image-dimensions.js +202 -0
- package/dist/helper/image-dimensions.js.map +1 -0
- package/dist/helper/jszip-helper.d.ts +21 -0
- package/dist/helper/jszip-helper.js +162 -0
- package/dist/helper/jszip-helper.js.map +1 -0
- package/dist/helper/layout-index.d.ts +55 -0
- package/dist/helper/layout-index.js +155 -0
- package/dist/helper/layout-index.js.map +1 -0
- package/dist/helper/logger.d.ts +53 -0
- package/dist/helper/logger.js +73 -0
- package/dist/helper/logger.js.map +1 -0
- package/dist/helper/media-deduplicator.d.ts +42 -0
- package/dist/helper/media-deduplicator.js +88 -0
- package/dist/helper/media-deduplicator.js.map +1 -0
- package/dist/helper/modify-background-helper.d.ts +19 -0
- package/dist/helper/modify-background-helper.js +59 -0
- package/dist/helper/modify-background-helper.js.map +1 -0
- package/dist/helper/modify-chart-helper.d.ts +159 -0
- package/dist/helper/modify-chart-helper.js +642 -0
- package/dist/helper/modify-chart-helper.js.map +1 -0
- package/dist/helper/modify-cleanup-helper.d.ts +69 -0
- package/dist/helper/modify-cleanup-helper.js +343 -0
- package/dist/helper/modify-cleanup-helper.js.map +1 -0
- package/dist/helper/modify-color-helper.d.ts +35 -0
- package/dist/helper/modify-color-helper.js +211 -0
- package/dist/helper/modify-color-helper.js.map +1 -0
- package/dist/helper/modify-helper.d.ts +23 -0
- package/dist/helper/modify-helper.js +61 -0
- package/dist/helper/modify-helper.js.map +1 -0
- package/dist/helper/modify-hyperlink-element.d.ts +9 -0
- package/dist/helper/modify-hyperlink-element.js +34 -0
- package/dist/helper/modify-hyperlink-element.js.map +1 -0
- package/dist/helper/modify-hyperlink-helper.d.ts +42 -0
- package/dist/helper/modify-hyperlink-helper.js +258 -0
- package/dist/helper/modify-hyperlink-helper.js.map +1 -0
- package/dist/helper/modify-image-helper.d.ts +23 -0
- package/dist/helper/modify-image-helper.js +157 -0
- package/dist/helper/modify-image-helper.js.map +1 -0
- package/dist/helper/modify-presentation-helper.d.ts +55 -0
- package/dist/helper/modify-presentation-helper.js +177 -0
- package/dist/helper/modify-presentation-helper.js.map +1 -0
- package/dist/helper/modify-shape-helper.d.ts +111 -0
- package/dist/helper/modify-shape-helper.js +340 -0
- package/dist/helper/modify-shape-helper.js.map +1 -0
- package/dist/helper/modify-table-helper.d.ts +11 -0
- package/dist/helper/modify-table-helper.js +100 -0
- package/dist/helper/modify-table-helper.js.map +1 -0
- package/dist/helper/modify-text-helper.d.ts +62 -0
- package/dist/helper/modify-text-helper.js +244 -0
- package/dist/helper/modify-text-helper.js.map +1 -0
- package/dist/helper/modify-xml-helper.d.ts +52 -0
- package/dist/helper/modify-xml-helper.js +305 -0
- package/dist/helper/modify-xml-helper.js.map +1 -0
- package/dist/helper/multitext-helper.d.ts +116 -0
- package/dist/helper/multitext-helper.js +462 -0
- package/dist/helper/multitext-helper.js.map +1 -0
- package/dist/helper/ppt-paths.d.ts +76 -0
- package/dist/helper/ppt-paths.js +116 -0
- package/dist/helper/ppt-paths.js.map +1 -0
- package/dist/helper/shape-type-detector.d.ts +34 -0
- package/dist/helper/shape-type-detector.js +99 -0
- package/dist/helper/shape-type-detector.js.map +1 -0
- package/dist/helper/text-replace-helper.d.ts +30 -0
- package/dist/helper/text-replace-helper.js +147 -0
- package/dist/helper/text-replace-helper.js.map +1 -0
- package/dist/helper/xml/lnLRTB.d.ts +1 -0
- package/dist/helper/xml/lnLRTB.js +62 -0
- package/dist/helper/xml/lnLRTB.js.map +1 -0
- package/dist/helper/xml/prstGeom.d.ts +1 -0
- package/dist/helper/xml/prstGeom.js +11 -0
- package/dist/helper/xml/prstGeom.js.map +1 -0
- package/dist/helper/xml-elements.d.ts +134 -0
- package/dist/helper/xml-elements.js +538 -0
- package/dist/helper/xml-elements.js.map +1 -0
- package/dist/helper/xml-helper.d.ts +120 -0
- package/dist/helper/xml-helper.js +495 -0
- package/dist/helper/xml-helper.js.map +1 -0
- package/dist/helper/xml-placeholder-helper.d.ts +92 -0
- package/dist/helper/xml-placeholder-helper.js +454 -0
- package/dist/helper/xml-placeholder-helper.js.map +1 -0
- package/dist/helper/xml-pretty-print.d.ts +17 -0
- package/dist/helper/xml-pretty-print.js +88 -0
- package/dist/helper/xml-pretty-print.js.map +1 -0
- package/dist/helper/xml-relationship-helper.d.ts +103 -0
- package/dist/helper/xml-relationship-helper.js +397 -0
- package/dist/helper/xml-relationship-helper.js.map +1 -0
- package/dist/helper/xml-slide-helper.d.ts +107 -0
- package/dist/helper/xml-slide-helper.js +676 -0
- package/dist/helper/xml-slide-helper.js.map +1 -0
- package/dist/helper/xml-template-helper.d.ts +42 -0
- package/dist/helper/xml-template-helper.js +252 -0
- package/dist/helper/xml-template-helper.js.map +1 -0
- package/dist/helper/xmldom-sax-patch.d.ts +18 -0
- package/dist/helper/xmldom-sax-patch.js +58 -0
- package/dist/helper/xmldom-sax-patch.js.map +1 -0
- package/dist/index.d.ts +81 -0
- package/dist/index.js +177 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/iarchive.d.ts +43 -0
- package/dist/interfaces/iarchive.js +3 -0
- package/dist/interfaces/iarchive.js.map +1 -0
- package/dist/interfaces/ichart.d.ts +7 -0
- package/dist/interfaces/ichart.js +3 -0
- package/dist/interfaces/ichart.js.map +1 -0
- package/dist/interfaces/icounter.d.ts +7 -0
- package/dist/interfaces/icounter.js +3 -0
- package/dist/interfaces/icounter.js.map +1 -0
- package/dist/interfaces/igenerator.d.ts +4 -0
- package/dist/interfaces/igenerator.js +3 -0
- package/dist/interfaces/igenerator.js.map +1 -0
- package/dist/interfaces/iimage.d.ts +7 -0
- package/dist/interfaces/iimage.js +3 -0
- package/dist/interfaces/iimage.js.map +1 -0
- package/dist/interfaces/ilayout.d.ts +14 -0
- package/dist/interfaces/ilayout.js +3 -0
- package/dist/interfaces/ilayout.js.map +1 -0
- package/dist/interfaces/imaster.d.ts +15 -0
- package/dist/interfaces/imaster.js +3 -0
- package/dist/interfaces/imaster.js.map +1 -0
- package/dist/interfaces/imulti-text.d.ts +50 -0
- package/dist/interfaces/imulti-text.js +3 -0
- package/dist/interfaces/imulti-text.js.map +1 -0
- package/dist/interfaces/ipptxgenjs-slide.d.ts +40 -0
- package/dist/interfaces/ipptxgenjs-slide.js +3 -0
- package/dist/interfaces/ipptxgenjs-slide.js.map +1 -0
- package/dist/interfaces/ipresentation-props.d.ts +16 -0
- package/dist/interfaces/ipresentation-props.js +3 -0
- package/dist/interfaces/ipresentation-props.js.map +1 -0
- package/dist/interfaces/ishape-action.d.ts +18 -0
- package/dist/interfaces/ishape-action.js +3 -0
- package/dist/interfaces/ishape-action.js.map +1 -0
- package/dist/interfaces/ishape.d.ts +5 -0
- package/dist/interfaces/ishape.js +3 -0
- package/dist/interfaces/ishape.js.map +1 -0
- package/dist/interfaces/islide.d.ts +71 -0
- package/dist/interfaces/islide.js +3 -0
- package/dist/interfaces/islide.js.map +1 -0
- package/dist/interfaces/itemplate.d.ts +9 -0
- package/dist/interfaces/itemplate.js +3 -0
- package/dist/interfaces/itemplate.js.map +1 -0
- package/dist/interfaces/pres-template.d.ts +9 -0
- package/dist/interfaces/pres-template.js +3 -0
- package/dist/interfaces/pres-template.js.map +1 -0
- package/dist/interfaces/root-pres-template.d.ts +38 -0
- package/dist/interfaces/root-pres-template.js +3 -0
- package/dist/interfaces/root-pres-template.js.map +1 -0
- package/dist/modify/modify-chart.d.ts +74 -0
- package/dist/modify/modify-chart.js +753 -0
- package/dist/modify/modify-chart.js.map +1 -0
- package/dist/modify/modify-table.d.ts +64 -0
- package/dist/modify/modify-table.js +435 -0
- package/dist/modify/modify-table.js.map +1 -0
- package/dist/shapes/chart.d.ts +91 -0
- package/dist/shapes/chart.js +437 -0
- package/dist/shapes/chart.js.map +1 -0
- package/dist/shapes/diagram.d.ts +33 -0
- package/dist/shapes/diagram.js +167 -0
- package/dist/shapes/diagram.js.map +1 -0
- package/dist/shapes/generic.d.ts +27 -0
- package/dist/shapes/generic.js +118 -0
- package/dist/shapes/generic.js.map +1 -0
- package/dist/shapes/hyperlink.d.ts +27 -0
- package/dist/shapes/hyperlink.js +193 -0
- package/dist/shapes/hyperlink.js.map +1 -0
- package/dist/shapes/image.d.ts +47 -0
- package/dist/shapes/image.js +244 -0
- package/dist/shapes/image.js.map +1 -0
- package/dist/shapes/ole.d.ts +30 -0
- package/dist/shapes/ole.js +237 -0
- package/dist/shapes/ole.js.map +1 -0
- package/dist/types/chart-types.d.ts +115 -0
- package/dist/types/chart-types.js +3 -0
- package/dist/types/chart-types.js.map +1 -0
- package/dist/types/modify-types.d.ts +128 -0
- package/dist/types/modify-types.js +3 -0
- package/dist/types/modify-types.js.map +1 -0
- package/dist/types/shape-types.d.ts +40 -0
- package/dist/types/shape-types.js +3 -0
- package/dist/types/shape-types.js.map +1 -0
- package/dist/types/table-types.d.ts +38 -0
- package/dist/types/table-types.js +3 -0
- package/dist/types/table-types.js.map +1 -0
- package/dist/types/types.d.ts +317 -0
- package/dist/types/types.js +16 -0
- package/dist/types/types.js.map +1 -0
- package/dist/types/xml-types.d.ts +168 -0
- package/dist/types/xml-types.js +3 -0
- package/dist/types/xml-types.js.map +1 -0
- package/package.json +92 -4
|
@@ -0,0 +1,140 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CountHelper = void 0;
|
|
13
|
+
const xml_helper_1 = require("./xml-helper");
|
|
14
|
+
class CountHelper {
|
|
15
|
+
constructor(name, template) {
|
|
16
|
+
this.name = name;
|
|
17
|
+
this.template = template;
|
|
18
|
+
}
|
|
19
|
+
static increment(name, counters) {
|
|
20
|
+
return CountHelper.getCounterByName(name, counters)._increment();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Lower a counter, e.g. after slides have been removed from the archive.
|
|
24
|
+
*/
|
|
25
|
+
static decrement(name, counters, by = 1) {
|
|
26
|
+
const counter = CountHelper.getCounterByName(name, counters);
|
|
27
|
+
counter.count = Math.max(0, counter.count - by);
|
|
28
|
+
return counter.count;
|
|
29
|
+
}
|
|
30
|
+
static count(name, counters) {
|
|
31
|
+
return CountHelper.getCounterByName(name, counters).get();
|
|
32
|
+
}
|
|
33
|
+
static reset(counters) {
|
|
34
|
+
counters.forEach((counter) => (counter.count = undefined));
|
|
35
|
+
}
|
|
36
|
+
static getCounterByName(name, counters) {
|
|
37
|
+
const counter = counters.find((c) => c.name === name);
|
|
38
|
+
if (counter === undefined) {
|
|
39
|
+
throw new Error(`Counter ${name} not found.`);
|
|
40
|
+
}
|
|
41
|
+
return counter;
|
|
42
|
+
}
|
|
43
|
+
_increment() {
|
|
44
|
+
this.count++;
|
|
45
|
+
return this.count;
|
|
46
|
+
}
|
|
47
|
+
set() {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
this.count = yield this.calculateCount(this.template.archive);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
get() {
|
|
53
|
+
return this.count;
|
|
54
|
+
}
|
|
55
|
+
calculateCount(presentation) {
|
|
56
|
+
switch (this.name) {
|
|
57
|
+
case 'slides':
|
|
58
|
+
return CountHelper.countSlides(presentation);
|
|
59
|
+
case 'masters':
|
|
60
|
+
return CountHelper.countMasters(presentation);
|
|
61
|
+
case 'layouts':
|
|
62
|
+
return CountHelper.countLayouts(presentation);
|
|
63
|
+
case 'themes':
|
|
64
|
+
return CountHelper.countThemes(presentation);
|
|
65
|
+
case 'charts':
|
|
66
|
+
return CountHelper.countCharts(presentation);
|
|
67
|
+
case 'images':
|
|
68
|
+
return CountHelper.countImages(presentation);
|
|
69
|
+
case 'diagrams':
|
|
70
|
+
return CountHelper.countDiagrams(presentation);
|
|
71
|
+
case 'oleObjects':
|
|
72
|
+
return CountHelper.countOleObjects(presentation);
|
|
73
|
+
}
|
|
74
|
+
throw new Error(`No way to count ${this.name}.`);
|
|
75
|
+
}
|
|
76
|
+
static countSlides(presentation) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
const presentationXml = yield xml_helper_1.XmlHelper.getXmlFromArchive(presentation, 'ppt/presentation.xml');
|
|
79
|
+
return presentationXml.getElementsByTagName('p:sldId').length;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
static countMasters(presentation) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
const presentationXml = yield xml_helper_1.XmlHelper.getXmlFromArchive(presentation, 'ppt/presentation.xml');
|
|
85
|
+
return presentationXml.getElementsByTagName('p:sldMasterId').length;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Counts the Override entries of [Content_Types].xml with the given
|
|
90
|
+
* ContentType.
|
|
91
|
+
*/
|
|
92
|
+
static countContentTypeOverrides(presentation, contentType) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
var _a;
|
|
95
|
+
const contentTypesXml = yield xml_helper_1.XmlHelper.getXmlFromArchive(presentation, '[Content_Types].xml');
|
|
96
|
+
const overrides = contentTypesXml.getElementsByTagName('Override');
|
|
97
|
+
let count = 0;
|
|
98
|
+
for (let i = 0; i < overrides.length; i++) {
|
|
99
|
+
if (((_a = overrides.item(i)) === null || _a === void 0 ? void 0 : _a.getAttribute('ContentType')) === contentType) {
|
|
100
|
+
count++;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return count;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
static countLayouts(presentation) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
return CountHelper.countContentTypeOverrides(presentation, 'application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml');
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
static countThemes(presentation) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
return CountHelper.countContentTypeOverrides(presentation, 'application/vnd.openxmlformats-officedocument.theme+xml');
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
static countCharts(presentation) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
return CountHelper.countContentTypeOverrides(presentation, 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml');
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
static countOleObjects(presentation) {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
return CountHelper.countContentTypeOverrides(presentation, 'application/vnd.openxmlformats-officedocument.oleObject');
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
static countImages(presentation) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
const mediaFiles = yield presentation.folder('ppt/media');
|
|
129
|
+
const count = mediaFiles.filter((file) => file.relativePath.indexOf('image') === 0).length;
|
|
130
|
+
return count;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
static countDiagrams(presentation) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
return CountHelper.countContentTypeOverrides(presentation, 'application/vnd.openxmlformats-officedocument.drawingml.diagramData+xml');
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.CountHelper = CountHelper;
|
|
140
|
+
//# sourceMappingURL=count-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"count-helper.js","sourceRoot":"","sources":["../../src/helper/count-helper.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,6CAAyC;AAEzC,MAAa,WAAW;IAKtB,YAAY,IAAY,EAAE,QAA0B;QAClD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,IAAY,EAAE,QAAoB;QACjD,OAAO,WAAW,CAAC,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,UAAU,EAAE,CAAC;IACnE,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,SAAS,CAAC,IAAY,EAAE,QAAoB,EAAE,EAAE,GAAG,CAAC;QACzD,MAAM,OAAO,GAAG,WAAW,CAAC,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC7D,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC;QAChD,OAAO,OAAO,CAAC,KAAK,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,IAAY,EAAE,QAAoB;QAC7C,OAAO,WAAW,CAAC,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,GAAG,EAAE,CAAC;IAC5D,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,QAAoB;QAC/B,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OA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D,OAAO,WAAW,CAAC,yBAAyB,CAC1C,YAAY,EACZ,8EAA8E,CAC/E,CAAC;QACJ,CAAC;KAAA;IAEO,MAAM,CAAO,WAAW,CAAC,YAAsB;;YACrD,OAAO,WAAW,CAAC,yBAAyB,CAC1C,YAAY,EACZ,yDAAyD,CAC1D,CAAC;QACJ,CAAC;KAAA;IAEO,MAAM,CAAO,WAAW,CAAC,YAAsB;;YACrD,OAAO,WAAW,CAAC,yBAAyB,CAC1C,YAAY,EACZ,mEAAmE,CACpE,CAAC;QACJ,CAAC;KAAA;IAEO,MAAM,CAAO,eAAe,CAClC,YAAsB;;YAEtB,OAAO,WAAW,CAAC,yBAAyB,CAC1C,YAAY,EACZ,yDAAyD,CAC1D,CAAC;QACJ,CAAC;KAAA;IAEO,MAAM,CAAO,WAAW,CAAC,YAAsB;;YACrD,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YAC1D,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAC7B,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CACnD,CAAC,MAAM,CAAC;YACT,OAAO,KAAK,CAAC;QACf,CAAC;KAAA;IAEO,MAAM,CAAO,aAAa,CAAC,YAAsB;;YACvD,OAAO,WAAW,CAAC,yBAAyB,CAC1C,YAAY,EACZ,yEAAyE,CAC1E,CAAC;QACJ,CAAC;KAAA;CACF;AA9JD,kCA8JC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parsing of the inline CSS subset that WYSIWYG editors (CKEditor, TinyMCE)
|
|
3
|
+
* emit inside `style="..."` attributes, mapped onto `TextStyle`.
|
|
4
|
+
*
|
|
5
|
+
* Deliberately standalone (no XML/DOM imports) so it can be reused by both the
|
|
6
|
+
* HTML converter and the color helpers without an import cycle.
|
|
7
|
+
*
|
|
8
|
+
* Units: OOXML wants font sizes in 1/100 pt and colors as 6-digit RRGGBB hex
|
|
9
|
+
* without a leading `#`. CSS gives us px, pt, named colors and `rgb()`.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Split an inline `style` attribute into a lowercase property → value map.
|
|
13
|
+
* Tolerates missing trailing semicolons and stray whitespace.
|
|
14
|
+
*/
|
|
15
|
+
export declare const parseInlineCss: (styleAttr: string) => Record<string, string>;
|
|
16
|
+
/**
|
|
17
|
+
* Normalize any CSS color notation to 6-digit RRGGBB hex without `#`.
|
|
18
|
+
* Returns undefined for notations OOXML cannot express as a plain srgbClr
|
|
19
|
+
* (gradients, `currentColor`, `transparent`, …) so callers can skip them
|
|
20
|
+
* instead of writing an invalid value.
|
|
21
|
+
*/
|
|
22
|
+
export declare const normalizeCssColor: (input: string) => string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Convert a CSS font-size to OOXML's 1/100 pt.
|
|
25
|
+
*
|
|
26
|
+
* Supports `px` (96dpi), `pt`, and unitless numbers (treated as px, which is
|
|
27
|
+
* what browsers do for legacy `size` attributes). Relative units (`em`, `rem`,
|
|
28
|
+
* `%`, keywords like `larger`) are intentionally *not* resolved: without the
|
|
29
|
+
* cascade there is no base to resolve them against, and guessing would silently
|
|
30
|
+
* resize text. They return undefined, leaving the size inherited.
|
|
31
|
+
*/
|
|
32
|
+
export declare const parseCssFontSize: (input: string) => number | undefined;
|
|
33
|
+
/** CSS `font-weight` → bold. Numeric weights are bold from 600 up. */
|
|
34
|
+
export declare const parseCssFontWeight: (input: string) => boolean | undefined;
|
|
35
|
+
/** CSS `font-style` → italics. */
|
|
36
|
+
export declare const parseCssFontStyle: (input: string) => boolean | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* CSS `text-decoration` (or `text-decoration-line`) → underline / strike.
|
|
39
|
+
* The shorthand can carry color and style too, so this scans for keywords
|
|
40
|
+
* rather than matching the whole value.
|
|
41
|
+
*/
|
|
42
|
+
export declare const parseCssTextDecoration: (input: string) => {
|
|
43
|
+
isUnderlined?: boolean;
|
|
44
|
+
isStrike?: boolean;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* CSS `font-family` → a single OOXML typeface name. Takes the first family of
|
|
48
|
+
* the stack (OOXML has no fallback list) and strips quotes.
|
|
49
|
+
*/
|
|
50
|
+
export declare const parseCssFontFamily: (input: string) => string | undefined;
|
|
51
|
+
/** CSS `text-align` → OOXML `algn` value. */
|
|
52
|
+
export declare const parseCssTextAlign: (input: string) => "l" | "ctr" | "r" | "just" | undefined;
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Parsing of the inline CSS subset that WYSIWYG editors (CKEditor, TinyMCE)
|
|
4
|
+
* emit inside `style="..."` attributes, mapped onto `TextStyle`.
|
|
5
|
+
*
|
|
6
|
+
* Deliberately standalone (no XML/DOM imports) so it can be reused by both the
|
|
7
|
+
* HTML converter and the color helpers without an import cycle.
|
|
8
|
+
*
|
|
9
|
+
* Units: OOXML wants font sizes in 1/100 pt and colors as 6-digit RRGGBB hex
|
|
10
|
+
* without a leading `#`. CSS gives us px, pt, named colors and `rgb()`.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.parseCssTextAlign = exports.parseCssFontFamily = exports.parseCssTextDecoration = exports.parseCssFontStyle = exports.parseCssFontWeight = exports.parseCssFontSize = exports.normalizeCssColor = exports.parseInlineCss = void 0;
|
|
14
|
+
/** 1px at the CSS reference resolution of 96dpi is 0.75pt. */
|
|
15
|
+
const PX_TO_PT = 0.75;
|
|
16
|
+
/**
|
|
17
|
+
* Named CSS colors. Not the full 148-name set — the basic 16 plus the names
|
|
18
|
+
* that actually turn up in editor palettes and hand-written HTML.
|
|
19
|
+
*/
|
|
20
|
+
const NAMED_COLORS = {
|
|
21
|
+
aqua: '00FFFF',
|
|
22
|
+
black: '000000',
|
|
23
|
+
blue: '0000FF',
|
|
24
|
+
brown: 'A52A2A',
|
|
25
|
+
cyan: '00FFFF',
|
|
26
|
+
darkblue: '00008B',
|
|
27
|
+
darkgray: 'A9A9A9',
|
|
28
|
+
darkgreen: '006400',
|
|
29
|
+
darkgrey: 'A9A9A9',
|
|
30
|
+
darkred: '8B0000',
|
|
31
|
+
fuchsia: 'FF00FF',
|
|
32
|
+
gold: 'FFD700',
|
|
33
|
+
gray: '808080',
|
|
34
|
+
green: '008000',
|
|
35
|
+
grey: '808080',
|
|
36
|
+
indigo: '4B0082',
|
|
37
|
+
lightblue: 'ADD8E6',
|
|
38
|
+
lightgray: 'D3D3D3',
|
|
39
|
+
lightgreen: '90EE90',
|
|
40
|
+
lightgrey: 'D3D3D3',
|
|
41
|
+
lime: '00FF00',
|
|
42
|
+
magenta: 'FF00FF',
|
|
43
|
+
maroon: '800000',
|
|
44
|
+
navy: '000080',
|
|
45
|
+
olive: '808000',
|
|
46
|
+
orange: 'FFA500',
|
|
47
|
+
pink: 'FFC0CB',
|
|
48
|
+
purple: '800080',
|
|
49
|
+
red: 'FF0000',
|
|
50
|
+
silver: 'C0C0C0',
|
|
51
|
+
teal: '008080',
|
|
52
|
+
turquoise: '40E0D0',
|
|
53
|
+
violet: 'EE82EE',
|
|
54
|
+
white: 'FFFFFF',
|
|
55
|
+
yellow: 'FFFF00',
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Split an inline `style` attribute into a lowercase property → value map.
|
|
59
|
+
* Tolerates missing trailing semicolons and stray whitespace.
|
|
60
|
+
*/
|
|
61
|
+
const parseInlineCss = (styleAttr) => {
|
|
62
|
+
const declarations = {};
|
|
63
|
+
if (!styleAttr) {
|
|
64
|
+
return declarations;
|
|
65
|
+
}
|
|
66
|
+
styleAttr.split(';').forEach((declaration) => {
|
|
67
|
+
const separator = declaration.indexOf(':');
|
|
68
|
+
if (separator === -1) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const property = declaration.slice(0, separator).trim().toLowerCase();
|
|
72
|
+
const value = declaration.slice(separator + 1).trim();
|
|
73
|
+
if (property && value) {
|
|
74
|
+
declarations[property] = value;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return declarations;
|
|
78
|
+
};
|
|
79
|
+
exports.parseInlineCss = parseInlineCss;
|
|
80
|
+
/**
|
|
81
|
+
* Normalize any CSS color notation to 6-digit RRGGBB hex without `#`.
|
|
82
|
+
* Returns undefined for notations OOXML cannot express as a plain srgbClr
|
|
83
|
+
* (gradients, `currentColor`, `transparent`, …) so callers can skip them
|
|
84
|
+
* instead of writing an invalid value.
|
|
85
|
+
*/
|
|
86
|
+
const normalizeCssColor = (input) => {
|
|
87
|
+
if (!input) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
const value = input.trim().toLowerCase();
|
|
91
|
+
if (NAMED_COLORS[value]) {
|
|
92
|
+
return NAMED_COLORS[value];
|
|
93
|
+
}
|
|
94
|
+
const hexMatch = value.match(/^#?([0-9a-f]{3,8})$/);
|
|
95
|
+
if (hexMatch) {
|
|
96
|
+
const hex = hexMatch[1];
|
|
97
|
+
if (hex.length === 3 || hex.length === 4) {
|
|
98
|
+
// #abc → aabbcc (a 4th digit is alpha, which srgbClr carries separately)
|
|
99
|
+
return hex
|
|
100
|
+
.slice(0, 3)
|
|
101
|
+
.split('')
|
|
102
|
+
.map((char) => char + char)
|
|
103
|
+
.join('')
|
|
104
|
+
.toUpperCase();
|
|
105
|
+
}
|
|
106
|
+
if (hex.length === 6 || hex.length === 8) {
|
|
107
|
+
return hex.slice(0, 6).toUpperCase();
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
// rgb(1,2,3) / rgba(1,2,3,.5) / rgb(1 2 3 / 50%) — alpha is dropped
|
|
112
|
+
const rgbMatch = value.match(/^rgba?\(([^)]+)\)$/);
|
|
113
|
+
if (rgbMatch) {
|
|
114
|
+
const parts = rgbMatch[1]
|
|
115
|
+
.split(/[,/\s]+/)
|
|
116
|
+
.map((part) => part.trim())
|
|
117
|
+
.filter((part) => part !== '');
|
|
118
|
+
if (parts.length < 3) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
const channels = parts.slice(0, 3).map((part) => {
|
|
122
|
+
const numeric = parseFloat(part);
|
|
123
|
+
if (isNaN(numeric)) {
|
|
124
|
+
return NaN;
|
|
125
|
+
}
|
|
126
|
+
// Percentages are relative to 255
|
|
127
|
+
const absolute = part.endsWith('%') ? (numeric / 100) * 255 : numeric;
|
|
128
|
+
return Math.min(255, Math.max(0, Math.round(absolute)));
|
|
129
|
+
});
|
|
130
|
+
if (channels.some((channel) => isNaN(channel))) {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
return channels
|
|
134
|
+
.map((channel) => channel.toString(16).padStart(2, '0'))
|
|
135
|
+
.join('')
|
|
136
|
+
.toUpperCase();
|
|
137
|
+
}
|
|
138
|
+
return undefined;
|
|
139
|
+
};
|
|
140
|
+
exports.normalizeCssColor = normalizeCssColor;
|
|
141
|
+
/**
|
|
142
|
+
* Convert a CSS font-size to OOXML's 1/100 pt.
|
|
143
|
+
*
|
|
144
|
+
* Supports `px` (96dpi), `pt`, and unitless numbers (treated as px, which is
|
|
145
|
+
* what browsers do for legacy `size` attributes). Relative units (`em`, `rem`,
|
|
146
|
+
* `%`, keywords like `larger`) are intentionally *not* resolved: without the
|
|
147
|
+
* cascade there is no base to resolve them against, and guessing would silently
|
|
148
|
+
* resize text. They return undefined, leaving the size inherited.
|
|
149
|
+
*/
|
|
150
|
+
const parseCssFontSize = (input) => {
|
|
151
|
+
if (!input) {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
const match = input.trim().toLowerCase().match(/^(-?[\d.]+)\s*(px|pt)?$/);
|
|
155
|
+
if (!match) {
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
const numeric = parseFloat(match[1]);
|
|
159
|
+
if (isNaN(numeric) || numeric <= 0) {
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
const points = match[2] === 'pt' ? numeric : numeric * PX_TO_PT;
|
|
163
|
+
return Math.round(points * 100);
|
|
164
|
+
};
|
|
165
|
+
exports.parseCssFontSize = parseCssFontSize;
|
|
166
|
+
/** CSS `font-weight` → bold. Numeric weights are bold from 600 up. */
|
|
167
|
+
const parseCssFontWeight = (input) => {
|
|
168
|
+
const value = input.trim().toLowerCase();
|
|
169
|
+
if (value === 'bold' || value === 'bolder') {
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
if (value === 'normal' || value === 'lighter') {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
const numeric = parseInt(value, 10);
|
|
176
|
+
if (isNaN(numeric)) {
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
return numeric >= 600;
|
|
180
|
+
};
|
|
181
|
+
exports.parseCssFontWeight = parseCssFontWeight;
|
|
182
|
+
/** CSS `font-style` → italics. */
|
|
183
|
+
const parseCssFontStyle = (input) => {
|
|
184
|
+
const value = input.trim().toLowerCase();
|
|
185
|
+
if (value === 'italic' || value === 'oblique') {
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
if (value === 'normal') {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
return undefined;
|
|
192
|
+
};
|
|
193
|
+
exports.parseCssFontStyle = parseCssFontStyle;
|
|
194
|
+
/**
|
|
195
|
+
* CSS `text-decoration` (or `text-decoration-line`) → underline / strike.
|
|
196
|
+
* The shorthand can carry color and style too, so this scans for keywords
|
|
197
|
+
* rather than matching the whole value.
|
|
198
|
+
*/
|
|
199
|
+
const parseCssTextDecoration = (input) => {
|
|
200
|
+
const value = input.trim().toLowerCase();
|
|
201
|
+
const result = {};
|
|
202
|
+
if (value.includes('none')) {
|
|
203
|
+
return { isUnderlined: false, isStrike: false };
|
|
204
|
+
}
|
|
205
|
+
if (value.includes('underline')) {
|
|
206
|
+
result.isUnderlined = true;
|
|
207
|
+
}
|
|
208
|
+
if (value.includes('line-through')) {
|
|
209
|
+
result.isStrike = true;
|
|
210
|
+
}
|
|
211
|
+
return result;
|
|
212
|
+
};
|
|
213
|
+
exports.parseCssTextDecoration = parseCssTextDecoration;
|
|
214
|
+
/**
|
|
215
|
+
* CSS `font-family` → a single OOXML typeface name. Takes the first family of
|
|
216
|
+
* the stack (OOXML has no fallback list) and strips quotes.
|
|
217
|
+
*/
|
|
218
|
+
const parseCssFontFamily = (input) => {
|
|
219
|
+
var _a;
|
|
220
|
+
const first = (_a = input.split(',')[0]) === null || _a === void 0 ? void 0 : _a.trim();
|
|
221
|
+
if (!first) {
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
const unquoted = first.replace(/^["']|["']$/g, '').trim();
|
|
225
|
+
return unquoted === '' ? undefined : unquoted;
|
|
226
|
+
};
|
|
227
|
+
exports.parseCssFontFamily = parseCssFontFamily;
|
|
228
|
+
/** CSS `text-align` → OOXML `algn` value. */
|
|
229
|
+
const parseCssTextAlign = (input) => {
|
|
230
|
+
switch (input.trim().toLowerCase()) {
|
|
231
|
+
case 'left':
|
|
232
|
+
case 'start':
|
|
233
|
+
return 'l';
|
|
234
|
+
case 'center':
|
|
235
|
+
return 'ctr';
|
|
236
|
+
case 'right':
|
|
237
|
+
case 'end':
|
|
238
|
+
return 'r';
|
|
239
|
+
case 'justify':
|
|
240
|
+
return 'just';
|
|
241
|
+
default:
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
exports.parseCssTextAlign = parseCssTextAlign;
|
|
246
|
+
//# sourceMappingURL=css-style-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-style-parser.js","sourceRoot":"","sources":["../../src/helper/css-style-parser.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,8DAA8D;AAC9D,MAAM,QAAQ,GAAG,IAAI,CAAC;AAEtB;;;GAGG;AACH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AC;AACH,CAAC,CAAC;AAjBW,QAAA,iBAAiB,qBAiB5B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { FileInfo, ArchiveParams, AutomizerFile } from '../types/types';
|
|
2
|
+
import IArchive, { ArchivedFolderCallback } from '../interfaces/iarchive';
|
|
3
|
+
import { ContentTypeExtension } from '../enums/content-type-map';
|
|
4
|
+
/**
|
|
5
|
+
* The slice of Slide/Master/Layout/Shape that archive copy helpers need:
|
|
6
|
+
* the two archives a part is copied between.
|
|
7
|
+
*/
|
|
8
|
+
export type ArchiveCopyContext = {
|
|
9
|
+
sourceArchive: IArchive;
|
|
10
|
+
targetArchive: IArchive;
|
|
11
|
+
};
|
|
12
|
+
export declare class FileHelper {
|
|
13
|
+
static importArchive(file: AutomizerFile, params: ArchiveParams): IArchive;
|
|
14
|
+
static removeFromDirectory(archive: IArchive, dir: string, cb: ArchivedFolderCallback): Promise<string[]>;
|
|
15
|
+
static getFileExtension(filename: string): ContentTypeExtension;
|
|
16
|
+
static getFileInfo(filename: string): FileInfo;
|
|
17
|
+
static check(archive: IArchive, file: string): boolean;
|
|
18
|
+
static isArchive(archive: IArchive): void;
|
|
19
|
+
static fileExistsInArchive(archive: IArchive, file: string): boolean;
|
|
20
|
+
static zipCopyWithRelations(context: ArchiveCopyContext, type: string, sourceNumber: number, targetNumber: number): Promise<void>;
|
|
21
|
+
static zipCopyByIndex(context: ArchiveCopyContext, prefix: string, sourceId: number | string, targetId: number | string, suffix?: string): Promise<IArchive>;
|
|
22
|
+
/**
|
|
23
|
+
* Copies a file from one archive to another. The new file can have a different name to the origin.
|
|
24
|
+
* @param {IArchive} sourceArchive - Source archive
|
|
25
|
+
* @param {string} sourceFile - file path and name inside source archive
|
|
26
|
+
* @param {IArchive} targetArchive - Target archive
|
|
27
|
+
* @param {string} targetFile - file path and name inside target archive
|
|
28
|
+
* @return {IArchive} targetArchive as an instance of IArchive
|
|
29
|
+
*/
|
|
30
|
+
static zipCopy(sourceArchive: IArchive, sourceFile: string, targetArchive: IArchive, targetFile?: string): Promise<IArchive>;
|
|
31
|
+
}
|
|
32
|
+
export declare const exists: (dir: string) => boolean;
|
|
33
|
+
export declare const makeDirIfNotExists: (dir: string) => void;
|
|
34
|
+
export declare const makeDir: (dir: string) => void;
|
|
35
|
+
export declare const copyDir: (src: string, dest: string) => Promise<void>;
|
|
36
|
+
export declare const ensureDirectoryExistence: (filePath: string) => void;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ensureDirectoryExistence = exports.copyDir = exports.makeDir = exports.makeDirIfNotExists = exports.exists = exports.FileHelper = void 0;
|
|
16
|
+
const fs_1 = __importDefault(require("fs"));
|
|
17
|
+
const fs_2 = require("fs");
|
|
18
|
+
const path_1 = __importDefault(require("path"));
|
|
19
|
+
const archive_jszip_1 = __importDefault(require("./archive/archive-jszip"));
|
|
20
|
+
const archive_fs_1 = __importDefault(require("./archive/archive-fs"));
|
|
21
|
+
class FileHelper {
|
|
22
|
+
static importArchive(file, params) {
|
|
23
|
+
if (typeof file !== 'object') {
|
|
24
|
+
if (!fs_1.default.existsSync(file)) {
|
|
25
|
+
throw new Error('File not found: ' + file);
|
|
26
|
+
}
|
|
27
|
+
switch (params.mode) {
|
|
28
|
+
case 'jszip':
|
|
29
|
+
return new archive_jszip_1.default(file, params);
|
|
30
|
+
case 'fs':
|
|
31
|
+
return new archive_fs_1.default(file, params);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return new archive_jszip_1.default(file, params);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
static removeFromDirectory(archive, dir, cb) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const removed = [];
|
|
41
|
+
const files = yield archive.folder(dir);
|
|
42
|
+
for (const file of files) {
|
|
43
|
+
if (cb(file)) {
|
|
44
|
+
yield archive.remove(file.name);
|
|
45
|
+
removed.push(file.name);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return removed;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
static getFileExtension(filename) {
|
|
52
|
+
return path_1.default.extname(filename).replace('.', '');
|
|
53
|
+
}
|
|
54
|
+
static getFileInfo(filename) {
|
|
55
|
+
return {
|
|
56
|
+
base: path_1.default.basename(filename),
|
|
57
|
+
dir: path_1.default.dirname(filename),
|
|
58
|
+
isDir: filename[filename.length - 1] === '/',
|
|
59
|
+
extension: path_1.default.extname(filename).replace('.', ''),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
static check(archive, file) {
|
|
63
|
+
FileHelper.isArchive(archive);
|
|
64
|
+
return FileHelper.fileExistsInArchive(archive, file);
|
|
65
|
+
}
|
|
66
|
+
static isArchive(archive) {
|
|
67
|
+
if (archive === undefined) {
|
|
68
|
+
throw new Error('Archive is invalid or empty.');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
static fileExistsInArchive(archive, file) {
|
|
72
|
+
return archive.fileExists(file);
|
|
73
|
+
}
|
|
74
|
+
static zipCopyWithRelations(context, type, sourceNumber, targetNumber) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
const typePlural = type + 's';
|
|
77
|
+
yield FileHelper.zipCopyByIndex(context, `ppt/${typePlural}/${type}`, sourceNumber, targetNumber);
|
|
78
|
+
yield FileHelper.zipCopyByIndex(context, `ppt/${typePlural}/_rels/${type}`, sourceNumber, targetNumber, '.xml.rels');
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
static zipCopyByIndex(context, prefix, sourceId, targetId, suffix) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
suffix = suffix || '.xml';
|
|
84
|
+
return FileHelper.zipCopy(context.sourceArchive, `${prefix}${sourceId}${suffix}`, context.targetArchive, `${prefix}${targetId}${suffix}`);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Copies a file from one archive to another. The new file can have a different name to the origin.
|
|
89
|
+
* @param {IArchive} sourceArchive - Source archive
|
|
90
|
+
* @param {string} sourceFile - file path and name inside source archive
|
|
91
|
+
* @param {IArchive} targetArchive - Target archive
|
|
92
|
+
* @param {string} targetFile - file path and name inside target archive
|
|
93
|
+
* @return {IArchive} targetArchive as an instance of IArchive
|
|
94
|
+
*/
|
|
95
|
+
static zipCopy(sourceArchive, sourceFile, targetArchive, targetFile) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
var _a;
|
|
98
|
+
FileHelper.check(sourceArchive, sourceFile);
|
|
99
|
+
(_a = targetArchive.contentTracker) === null || _a === void 0 ? void 0 : _a.trackFile(targetFile);
|
|
100
|
+
const content = yield sourceArchive
|
|
101
|
+
.read(sourceFile, 'nodebuffer')
|
|
102
|
+
.catch((e) => {
|
|
103
|
+
throw e;
|
|
104
|
+
});
|
|
105
|
+
return targetArchive.write(targetFile || sourceFile, content);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.FileHelper = FileHelper;
|
|
110
|
+
const exists = (dir) => {
|
|
111
|
+
return fs_1.default.existsSync(dir);
|
|
112
|
+
};
|
|
113
|
+
exports.exists = exists;
|
|
114
|
+
const makeDirIfNotExists = (dir) => {
|
|
115
|
+
if (!(0, exports.exists)(dir)) {
|
|
116
|
+
(0, exports.makeDir)(dir);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
exports.makeDirIfNotExists = makeDirIfNotExists;
|
|
120
|
+
const makeDir = (dir) => {
|
|
121
|
+
if (!fs_1.default.existsSync(dir)) {
|
|
122
|
+
fs_1.default.mkdirSync(dir);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
exports.makeDir = makeDir;
|
|
126
|
+
const copyDir = (src, dest) => __awaiter(void 0, void 0, void 0, function* () {
|
|
127
|
+
yield fs_2.promises.mkdir(dest, { recursive: true });
|
|
128
|
+
const entries = yield fs_2.promises.readdir(src, { withFileTypes: true });
|
|
129
|
+
for (const entry of entries) {
|
|
130
|
+
const srcPath = path_1.default.join(src, entry.name);
|
|
131
|
+
const destPath = path_1.default.join(dest, entry.name);
|
|
132
|
+
if (entry.isDirectory()) {
|
|
133
|
+
yield (0, exports.copyDir)(srcPath, destPath);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
yield fs_2.promises.copyFile(srcPath, destPath);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
exports.copyDir = copyDir;
|
|
141
|
+
const ensureDirectoryExistence = (filePath) => {
|
|
142
|
+
const dirname = path_1.default.dirname(filePath);
|
|
143
|
+
if (fs_1.default.existsSync(dirname)) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
(0, exports.ensureDirectoryExistence)(dirname);
|
|
147
|
+
fs_1.default.mkdirSync(dirname);
|
|
148
|
+
};
|
|
149
|
+
exports.ensureDirectoryExistence = ensureDirectoryExistence;
|
|
150
|
+
//# sourceMappingURL=file-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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