propresenter-parser
Version:
Parses ProPresenter 4, 5, and 6 files to extract the data, and can build ProPresenter 5 and 6 files
127 lines (126 loc) • 5.8 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.v4Parser = void 0;
const fast_xml_parser_1 = require("fast-xml-parser");
const js_base64_1 = require("js-base64");
const Utils = __importStar(require("../utils"));
class v4Parser {
parse(fileContent) {
const alwaysArray = [
'RVPresentationDocument.timeline.timeCues',
'RVPresentationDocument.timeline.mediaTracks',
'RVPresentationDocument.slides.RVDisplaySlide',
'RVPresentationDocument.slides.RVDisplaySlide.displayElements.RVTextElement',
];
const xmlParser = new fast_xml_parser_1.XMLParser({
ignoreAttributes: false,
attributeNamePrefix: '@',
parseAttributeValue: true,
isArray: (_name, jPath) => alwaysArray.includes(jPath),
});
const parsedDoc = xmlParser.parse(fileContent);
if (parsedDoc.RVPresentationDocument['@versionNumber'] !== 400) {
throw new Error(`Expected a ProPresenter 4 file with versionNumber="400" but got versionNumber="${parsedDoc.RVPresentationDocument['@versionNumber']}"`);
}
const properties = this.getProperties(parsedDoc.RVPresentationDocument);
const slides = this.getSlides(parsedDoc.RVPresentationDocument.slides.RVDisplaySlide);
return {
properties,
slides,
};
}
getProperties(doc) {
var _a, _b, _c, _d, _e;
return {
CCLIArtistCredits: (_a = doc['@CCLIArtistCredits']) !== null && _a !== void 0 ? _a : '',
CCLICopyrightInfo: (_b = doc['@CCLICopyrightInfo']) !== null && _b !== void 0 ? _b : '',
CCLIDisplay: Boolean(doc['@CCLIDisplay']),
CCLILicenseNumber: (_c = doc['@CCLILicenseNumber']) !== null && _c !== void 0 ? _c : '',
CCLIPublisher: (_d = doc['@CCLIPublisher']) !== null && _d !== void 0 ? _d : '',
CCLISongTitle: (_e = doc['@CCLISongTitle']) !== null && _e !== void 0 ? _e : '',
album: doc['@album'],
artist: doc['@artist'],
author: doc['@author'],
backgroundColor: Utils.normalizeColorToRgbObj(doc['@backgroundColor']),
category: doc['@category'],
creatorCode: doc['@creatorCode'],
docType: doc['@docType'] == null ? null : doc['@docType'],
drawingBackgroundColor: doc['@drawingBackgroundColor'] == null ? false : Boolean(doc['@drawingBackgroundColor']),
height: doc['@height'],
lastDateUsed: new Date(doc['@lastDateUsed']),
notes: doc['@notes'],
resourcesDirectory: doc['@resourcesDirectory'],
usedCount: doc['@usedCount'],
versionNumber: doc['@versionNumber'],
width: doc['@width'],
};
}
getSlides(displaySlides) {
const slidesList = [];
for (const slide of displaySlides) {
let textElements = [];
if (slide.displayElements.RVTextElement) {
textElements = slide.displayElements.RVTextElement.map((txt) => {
const decodedContent = js_base64_1.Base64.decode(txt['@RTFData']);
const textProps = Utils.getTextPropsFromRtf(decodedContent);
return {
position: {
x: txt['_-RVRect3D-_position']['@x'],
y: txt['_-RVRect3D-_position']['@y'],
z: txt['_-RVRect3D-_position']['@z'],
height: txt['_-RVRect3D-_position']['@height'],
width: txt['_-RVRect3D-_position']['@width'],
},
rawRtfContent: decodedContent,
textContent: Utils.stripRtf(decodedContent),
color: textProps.color,
font: textProps.font,
size: textProps.size,
};
});
}
slidesList.push({
label: slide['@label'],
id: slide['@UUID'],
backgroundColor: Utils.normalizeColorToRgbObj(slide['@backgroundColor']),
highlightColor: Utils.normalizeColorToRgbObj(slide['@highlightColor']),
textElements,
});
}
return slidesList;
}
}
exports.v4Parser = v4Parser;