pptx-automizer
Version:
A template based pptx generator
66 lines • 3.27 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GenericShape = void 0;
const shape_1 = require("../classes/shape");
const xml_helper_1 = require("../helper/xml-helper");
const hyperlink_processor_1 = require("../helper/hyperlink-processor");
class GenericShape extends shape_1.Shape {
constructor(shape, targetType) {
super(shape, targetType);
}
modify(targetTemplate, targetSlideNumber) {
return __awaiter(this, void 0, void 0, function* () {
yield this.prepare(targetTemplate, targetSlideNumber);
yield this.replaceIntoSlideTree();
return this;
});
}
append(targetTemplate, targetSlideNumber) {
return __awaiter(this, void 0, void 0, function* () {
yield this.prepare(targetTemplate, targetSlideNumber);
yield this.appendToSlideTree();
// If this element contains hyperlinks, copy the hyperlink relationships
yield this.copyHyperlinkRelationships(targetSlideNumber);
return this;
});
}
remove(targetTemplate, targetSlideNumber) {
return __awaiter(this, void 0, void 0, function* () {
yield this.prepare(targetTemplate, targetSlideNumber);
yield this.removeFromSlideTree();
return this;
});
}
prepare(targetTemplate, targetSlideNumber) {
return __awaiter(this, void 0, void 0, function* () {
yield this.setTarget(targetTemplate, targetSlideNumber);
yield this.setTargetElement();
// Get the slide relations XML to pass to callbacks
const slideRelXml = yield xml_helper_1.XmlHelper.getXmlFromArchive(this.targetArchive, this.targetSlideRelFile);
// Pass both the element and the relation to applyCallbacks
// Use the documentElement property to get the root element of the XML document
this.applyCallbacks(this.callbacks, this.targetElement, slideRelXml.documentElement);
});
}
/**
* Copy hyperlink relationships from source slide to target slide
*/
copyHyperlinkRelationships(targetSlideNumber) {
return __awaiter(this, void 0, void 0, function* () {
if (!this.targetElement)
return;
yield hyperlink_processor_1.HyperlinkProcessor.copyMultipleHyperlinks(this.targetElement, this.sourceArchive, this.sourceSlideNumber, this.targetArchive, this.targetSlideRelFile);
});
}
}
exports.GenericShape = GenericShape;
//# sourceMappingURL=generic.js.map