mp70-pptx-automizer
Version:
A template based pptx generator
111 lines • 5.08 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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Video = void 0;
const media_helper_1 = require("../../helper/media-helper");
const shape_1 = require("../../classes/shape");
const xml_helper_1 = require("../../helper/xml-helper");
const path_1 = __importDefault(require("path"));
class Video extends shape_1.Shape {
constructor(shape, targetType) {
super(shape, targetType);
this.sourceFile = shape.target.file.replace('../media/', '');
this.relAttribute = 'r:embed';
this.relRootTag = 'a:videoFile';
this.relParent = (element) => element.parentNode.parentNode;
}
getMediaType() {
const videoTypes = {
'mp4': 'video/mp4',
'avi': 'video/x-msvideo',
'mov': 'video/quicktime',
};
const extension = path_1.default.extname(this.sourceFile).toLowerCase().slice(1);
return videoTypes[extension] || 'video/mp4';
}
getRelationshipType() {
return 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/video';
}
modifyOnAddedSlide(targetTemplate, targetSlideNumber) {
return __awaiter(this, void 0, void 0, function* () {
yield this.prepare(targetTemplate, targetSlideNumber);
yield this.updateElementsRelId();
return this;
});
}
modify(targetTemplate, targetSlideNumber) {
return __awaiter(this, void 0, void 0, function* () {
yield this.prepare(targetTemplate, targetSlideNumber);
yield this.setTargetElement();
yield this.updateTargetElementRelId();
this.applyVideoCallbacks();
yield this.replaceIntoSlideTree();
return this;
});
}
append(targetTemplate, targetSlideNumber) {
return __awaiter(this, void 0, void 0, function* () {
yield this.prepare(targetTemplate, targetSlideNumber);
yield this.setTargetElement();
yield this.updateTargetElementRelId();
this.applyVideoCallbacks();
yield this.appendToSlideTree();
return this;
});
}
applyVideoCallbacks() {
this.applyCallbacks(this.callbacks, this.targetElement, this.createdRelation);
}
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);
this.targetNumber = this.targetTemplate.incrementCounter('video');
this.targetFile = media_helper_1.MediaHelper.generateTargetFile(this.targetNumber, this.sourceFile);
yield this.copyFiles();
yield this.appendTypes();
yield this.appendToSlideRels();
});
}
copyFiles() {
return __awaiter(this, void 0, void 0, function* () {
yield media_helper_1.MediaHelper.copyFiles(this.sourceArchive, this.targetArchive, this.sourceFile, this.targetFile);
});
}
appendTypes() {
return __awaiter(this, void 0, void 0, function* () {
yield media_helper_1.MediaHelper.appendTypes(this.targetArchive, this.targetFile, this.getMediaType());
});
}
appendToSlideRels() {
return __awaiter(this, void 0, void 0, function* () {
const result = yield media_helper_1.MediaHelper.appendToSlideRels(this.targetArchive, this.targetType, this.targetSlideNumber, this.targetFile, this.getRelationshipType());
this.createdRid = result.createdRid;
this.createdRelation = result.createdRelation;
});
}
static getAllOnSlide(archive, relsPath) {
return __awaiter(this, void 0, void 0, function* () {
return yield xml_helper_1.XmlHelper.getTargetsByRelationshipType(archive, relsPath, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/video');
});
}
}
exports.Video = Video;
//# sourceMappingURL=video.js.map