propresenter-parser
Version:
Parses ProPresenter 4, 5, and 6 files to extract the data, and can build ProPresenter 5 and 6 files
272 lines (271 loc) • 11 kB
JavaScript
"use strict";
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.v5Builder = void 0;
const fast_xml_parser_1 = require("fast-xml-parser");
const js_base64_1 = require("js-base64");
const shared_model_1 = require("../shared.model");
const Utils = __importStar(require("../utils"));
class v5Builder {
constructor(options) {
this.defaultTransitionObj = {
'@transitionType': shared_model_1.IProTransitionType.None,
'@transitionDuration': 1,
'@motionEnabled': 0,
'@motionDuration': 20,
'@motionSpeed': 100,
};
this.xmlBuilder = new fast_xml_parser_1.XMLBuilder({
attributeNamePrefix: '@',
format: true,
ignoreAttributes: false,
processEntities: false,
suppressUnpairedNode: false,
unpairedTags: [
'arrangements',
'timeCues',
'mediaTracks',
'bibleReference',
'cues',
'_-RVProTransitionObject-_transitionObject',
'_-RVRect3D-_position',
'NSColor',
'NSNumber',
'NSMutableString',
],
});
this.options = options;
const defaultProperties = {
album: '',
artist: '',
author: '',
category: 'Song',
ccliDisplay: false,
notes: '',
publisher: '',
height: 720,
width: 1280,
};
this.options.properties = Object.assign(Object.assign({}, defaultProperties), this.options.properties);
const defaultSlideTextFormatting = {
textColor: { r: 255, g: 255, b: 255 },
textPadding: 20,
};
this.options.slideTextFormatting = Object.assign(Object.assign({}, defaultSlideTextFormatting), this.options.slideTextFormatting);
}
build() {
var _a, _b;
const documentObj = {
RVPresentationDocument: {
'@CCLIArtistCredits': this.options.properties.artist,
'@CCLICopyrightInfo': (_a = this.options.properties.copyrightYear) !== null && _a !== void 0 ? _a : '',
'@CCLIDisplay': this.options.properties.ccliDisplay ? 1 : 0,
'@CCLILicenseNumber': (_b = this.options.properties.ccliNumber) !== null && _b !== void 0 ? _b : '',
'@CCLIPublisher': this.options.properties.publisher,
'@CCLISongTitle': this.options.properties.title,
'@album': this.options.properties.album,
'@artist': this.options.properties.artist,
'@author': this.options.properties.author,
'@category': this.options.properties.category,
'@notes': this.options.properties.notes,
'@lastDateUsed': Utils.getIsoDateString(),
'@height': this.options.properties.height,
'@width': this.options.properties.width,
'@backgroundColor': '0 0 0 1',
'@creatorCode': 0,
'@chordChartPath': '',
'@docType': 0,
'@drawingBackgroundColor': 0,
'@resourcesDirectory': '',
'@usedCount': 0,
'@versionNumber': 500,
timeline: {
'@timeOffSet': 0,
'@selectedMediaTrackIndex': 0,
'@unitOfMeasure': 60,
'@duration': 0,
'@loop': 0,
timeCues: {
'@containerClass': 'NSMutableArray',
},
mediaTracks: {
'@containerClass': 'NSMutableArray',
},
},
bibleReference: {
'@containerClass': 'NSMutableDictionary',
},
'_-RVProTransitionObject-_transitionObject': this.getTransitions(),
groups: {
'@containerClass': 'NSMutableArray',
RVSlideGrouping: this.buildSlideGroups(),
},
arrangements: {
'@containerClass': 'NSMutableArray',
RVSongArrangement: [],
},
},
};
return this.xmlBuilder.build(documentObj).trim();
}
getTransitions() {
if (this.options.transitions) {
const transitionsCopy = Object.assign({}, this.defaultTransitionObj);
transitionsCopy['@transitionDuration'] = this.options.transitions.duration;
transitionsCopy['@transitionType'] = this.options.transitions.type;
return transitionsCopy;
}
return this.defaultTransitionObj;
}
buildSlideGroups() {
var _a;
const xmlSlideGroups = [];
for (let i = 0; i < this.options.slideGroups.length; i++) {
const group = this.options.slideGroups[i];
xmlSlideGroups.push({
'@name': group.label,
'@uuid': Utils.getUniqueID(),
'@color': Utils.normalizeColorToRgbaString((_a = group.groupColor) !== null && _a !== void 0 ? _a : '0 0 0 0'),
'@serialization-array-index': i,
slides: {
'@containerClass': 'NSMutableArray',
RVDisplaySlide: this.buildSlidesForGroup(group),
},
});
}
return xmlSlideGroups;
}
buildSlidesForGroup(thisGroup) {
var _a, _b;
const xmlSlides = [];
for (let i = 0; i < thisGroup.slides.length; i++) {
const slide = thisGroup.slides[i];
let highlightColor = '0 0 0 0';
let label = '';
let text;
if (typeof slide === 'string') {
text = slide;
}
else {
highlightColor = Utils.normalizeColorToRgbaString((_a = slide.slideColor) !== null && _a !== void 0 ? _a : highlightColor);
label = (_b = slide.label) !== null && _b !== void 0 ? _b : '';
text = slide.text;
}
xmlSlides.push({
'@backgroundColor': '0 0 0 0',
'@enabled': 1,
'@highlightColor': highlightColor,
'@hotKey': '',
'@label': label,
'@notes': '',
'@slideType': 1,
'@sort_index': i,
'@UUID': Utils.getUniqueID(),
'@drawingBackgroundColor': 0,
'@chordChartPath': '',
'@serialization-array-index': i,
cues: {
'@containerClass': 'NSMutableArray',
},
displayElements: {
'@containerClass': 'NSMutableArray',
RVTextElement: [this.buildTextElement(text)],
},
'_-RVProTransitionObject-_transitionObject': this.defaultTransitionObj,
});
}
return xmlSlides;
}
buildTextElement(text) {
const rtfText = Utils.formatRtf(text, this.options.slideTextFormatting.fontName, this.options.slideTextFormatting.textSize, Utils.normalizeColorToRgbObj(this.options.slideTextFormatting.textColor));
return {
'@displayDelay': 0,
'@displayName': 'Default',
'@locked': 0,
'@persistent': 0,
'@typeID': 0,
'@fromTemplate': 0,
'@bezelRadius': 0,
'@drawingFill': 0,
'@drawingShadow': 1,
'@drawingStroke': 0,
'@fillColor': '1 1 1 1',
'@rotation': 0,
'@source': '',
'@adjustsHeightToFit': 0,
'@verticalAlignment': 0,
'@RTFData': js_base64_1.Base64.encode(rtfText),
'@revealType': 0,
'@serialization-array-index': 0,
stroke: {
'@containerClass': 'NSMutableDictionary',
NSColor: {
'@serialization-native-value': '0 0 0 1',
'@serialization-dictionary-key': 'RVShapeElementStrokeColorKey',
},
NSNumber: {
'@serialization-native-value': 1,
'@serialization-dictionary-key': 'RVShapeElementStrokeWidthKey',
},
},
'_-D-_serializedShadow': {
'@containerClass': 'NSMutableDictionary',
NSMutableString: {
'@serialization-native-value': `{3.4641016, -2}`,
'@serialization-dictionary-key': 'shadowOffset',
},
NSNumber: {
'@serialization-native-value': 4,
'@serialization-dictionary-key': 'shadowBlurRadius',
},
NSColor: {
'@serialization-native-value': '0 0 0 1',
'@serialization-dictionary-key': 'shadowColor',
},
},
'_-RVRect3D-_position': this.getElementPosition(),
};
}
getElementPosition() {
return {
'@x': this.options.slideTextFormatting.textPadding,
'@y': this.options.slideTextFormatting.textPadding,
'@z': 0,
'@width': this.options.properties.width - this.options.slideTextFormatting.textPadding * 2,
'@height': this.options.properties.height - this.options.slideTextFormatting.textPadding * 2,
};
}
}
exports.v5Builder = v5Builder;