@kablamo/react-transcript-editor
Version:
A React component to make transcribing audio and video easier and faster.
1,046 lines (839 loc) • 35.5 kB
JavaScript
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 23);
/******/ })
/************************************************************************/
/******/ ({
/***/ 12:
/***/ (function(module, exports) {
module.exports = require("docx");
/***/ }),
/***/ 23:
/***/ (function(module, __webpack_exports__, __webpack_require__) {
;
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// CONCATENATED MODULE: ./packages/export-adapters/txt/index.js
/**
* Convert DraftJS to plain text without timecodes or speaker names
* Text+speaker+timecode
* TODO: have a separate one or some logic to get text without timecodes?
*
* Export looks like
```
00:00:13 F_S12
There is a day. About ten years ago when I asked a friend to hold a baby dinosaur called plea. All
00:00:24 F_S1
that
00:00:24 F_S12
he'd ordered and I was really excited about it because I've always loved about this one has really caught technical features. It had more orders and touch sensors. It had an infra red camera and one of the things that had was a tilt sensor so it. Knew what direction. It was facing. If and when you held it upside down.
00:00:46 U_UKN
I thought.
```
*/
// import { shortTimecode } from '../../util/timecode-converter/';
/* harmony default export */ var txt = (function (blockData) {
// TODO: to export text without speaker or timecodes use line below
// const lines = blockData.blocks.map(paragraph => paragraph.text);
var lines = blockData.blocks.map(function (paragraph) {
// return `${ shortTimecode(paragraph.data.words[0].start) }\t${ paragraph.data.speaker }\n${ paragraph.text }`;
return "".concat(paragraph.text);
});
return lines.join('\n\n');
});
// EXTERNAL MODULE: external "docx"
var external_docx_ = __webpack_require__(12);
// EXTERNAL MODULE: ./packages/util/timecode-converter/index.js + 3 modules
var timecode_converter = __webpack_require__(5);
// CONCATENATED MODULE: ./packages/export-adapters/docx/index.js
/* harmony default export */ var docx = (function (blockData, transcriptTitle) {
// const lines = blockData.blocks.map(x => x.text);
return generateDocxFromDraftJs(blockData, transcriptTitle); // return lines.join('\n\n');
});
function generateDocxFromDraftJs(blockData, transcriptTitle) {
var doc = new external_docx_["Document"]({
creator: 'Test',
description: 'Test Description',
title: transcriptTitle
}); // Transcript Title
// TODO: get title in programmatically - optional value
var textTitle = new external_docx_["TextRun"](transcriptTitle);
var paragraphTitle = new external_docx_["Paragraph"]();
paragraphTitle.addRun(textTitle);
paragraphTitle.heading1().center();
doc.addParagraph(paragraphTitle); // add spacing
var paragraphEmpty = new external_docx_["Paragraph"]();
doc.addParagraph(paragraphEmpty);
blockData.blocks.forEach(function (draftJsParagraph) {
// TODO: use timecode converter module to convert from seconds to timecode
var paragraphSpeakerTimecodes = new external_docx_["Paragraph"](Object(timecode_converter["shortTimecode"])(draftJsParagraph.data.words[0].start));
var speaker = new external_docx_["TextRun"](draftJsParagraph.data.speaker).bold().tab();
var textBreak = new external_docx_["TextRun"]('').break();
paragraphSpeakerTimecodes.addRun(speaker);
doc.addParagraph(paragraphSpeakerTimecodes);
var paragraphText = new external_docx_["Paragraph"](draftJsParagraph.text);
paragraphText.addRun(textBreak);
doc.addParagraph(paragraphText);
});
var packer = new external_docx_["Packer"]();
packer.toBlob(doc).then(function (blob) {
var filename = "".concat(transcriptTitle, ".docx"); // // const type = 'application/octet-stream';
var a = document.createElement('a');
a.href = window.URL.createObjectURL(blob);
a.download = filename;
a.click();
return blob;
});
}
// CONCATENATED MODULE: ./packages/export-adapters/txt-speakers-timecodes/index.js
/**
* Convert DraftJS to plain text with timecodes and speaker names
*
* Example:
```
F_S12 [00:00:13] There is a day. About ten years ago when I asked a friend to hold a baby dinosaur robot upside down. It was a toy called plea. All
```
*
*/
/* harmony default export */ var txt_speakers_timecodes = (function (blockData) {
var lines = blockData.blocks.map(function (block) {
return "".concat(block.data.speaker, " \t [").concat(Object(timecode_converter["shortTimecode"])(block.data.start), "] \t ").concat(block.text);
});
return lines.join('\n\n');
});
// CONCATENATED MODULE: ./packages/export-adapters/draftjs-to-digital-paper-edit/index.js
/**
* Convert DraftJS to Digital Paper Edit format
* More details see
* https://github.com/bbc/digital-paper-edit
*/
/* harmony default export */ var draftjs_to_digital_paper_edit = (function (blockData) {
var result = {
words: [],
paragraphs: []
};
blockData.blocks.forEach(function (block, index) {
if (block.data.words !== undefined) {
// TODO: make sure that when restoring timecodes text attribute in block word data
// should be updated as well
var tmpParagraph = {
id: index,
start: block.data.words[0].start,
//block.data.start,
end: block.data.words[block.data.words.length - 1].end,
speaker: block.data.speaker
};
result.paragraphs.push(tmpParagraph); // using data within a block to get words info
var tmpWords = block.data.words.map(function (word) {
var tmpWord = {
id: word.index,
start: word.start,
end: word.end,
text: null
}; // TODO: need to normalise various stt adapters
// so that when they create draftJs json, word text attribute
// has got consistent naming. `text` and not `punct` or `word`.
if (word.text) {
tmpWord.text = word.text;
} else if (word.punct) {
tmpWord.text = word.punct;
} else if (word.word) {
tmpWord.text = word.punct;
}
return tmpWord;
}); // flattening the list of words
result.words = result.words.concat(tmpWords);
}
});
return result;
});
// EXTERNAL MODULE: external "sbd"
var external_sbd_ = __webpack_require__(30);
var external_sbd_default = /*#__PURE__*/__webpack_require__.n(external_sbd_);
// CONCATENATED MODULE: ./packages/export-adapters/subtitles-generator/presegment-text/text-segmentation/index.js
function textSegmentation(text, honorifics) {
var optionalHonorifics = null;
if (honorifics !== undefined) {
optionalHonorifics = honorifics;
}
var options = {
'newline_boundaries': true,
'html_boundaries': false,
'sanitize': false,
'allowed_tags': false,
//TODO: Here could open HONORIFICS file and pass them in here I think
//abbreviations: list of abbreviations to override the original ones for use with other languages. Don't put dots in abbreviations.
'abbreviations': optionalHonorifics
};
var sentences = external_sbd_default.a.sentences(text, options);
var sentencesWithLineSpaces = sentences.join('\n');
return sentencesWithLineSpaces;
}
/* harmony default export */ var text_segmentation = (textSegmentation);
// CONCATENATED MODULE: ./packages/export-adapters/subtitles-generator/presegment-text/line-break-between-sentences/index.js
function addLineBreakBetweenSentences(text) {
return text.replace(/\n/g, '\n\n');
}
/* harmony default export */ var line_break_between_sentences = (addLineBreakBetweenSentences);
// CONCATENATED MODULE: ./packages/export-adapters/subtitles-generator/presegment-text/util/remove-space-after-carriage-return.js
/**
* Helper function to remove space after carriage return \n in lines
* @param {string} text
*/
function removeSpaceAfterCarriageReturn(text) {
return text.replace(/\n /g, '\n');
}
/* harmony default export */ var remove_space_after_carriage_return = (removeSpaceAfterCarriageReturn);
// CONCATENATED MODULE: ./packages/export-adapters/subtitles-generator/presegment-text/fold/index.js
/*
* Helper function
* folds array of words
* adds `\n`
* foldNumber = char after which to fold. eg 35 char default
* TODO: this could be refactored with smaller helper functions
*/
function foldWordsReturnArray(textArray) {
var foldNumber = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 35;
var counter = 0;
var result = textArray.map(function (word, index, list) {
counter += word.length + 1; //resetting counter when there is a 'paragraph' line break \n\n
if (counter <= foldNumber) {
// if not last word in list
// cover edge case last element in array does not have a next element
if (list[index + 1] !== undefined) {
var nextElementLength = list[index + 1].length; //check if adding next word would make the line go over the char limit foldNumber
if (counter + nextElementLength < foldNumber) {
return word;
} else {
// if it makes it go over, reset counter, return and add line break
counter = 0;
return "".concat(word, "\n");
} //last word in the list
} else {
return word;
} // if not greater then char foldNumber
} else {
counter = 0;
return "".concat(word, "\n");
}
});
return result;
}
/*
* text string of words
* foldNumber = char after which to fold. eg 35 char.
*/
function foldWords(text, foldNumber) {
// split on two line break
var lineArr = text.split('\n\n'); // fold each line on non fold number char count
var foldedWordsInArray = lineArr.map(function (line) {
return foldWordsReturnArray(line.split(' '), foldNumber);
}); // flatten result
var foldedWordsFlatten = foldedWordsInArray.map(function (line) {
return line.join(' ');
}); // remove space after carriage return \n in lines
var result = foldedWordsFlatten.map(function (r) {
return remove_space_after_carriage_return(r);
}); // return text
return result.join('\n\n');
}
/* harmony default export */ var fold = (foldWords);
// CONCATENATED MODULE: ./packages/export-adapters/subtitles-generator/presegment-text/util/remove-space-at-beginning-of-line.js
// Remove preceding empty space a beginning of line
// without removing carriage returns
// https://stackoverflow.com/questions/24282158/javascript-how-to-remove-the-white-space-at-the-start-of-the-string
function removeSpaceAtBeginningOfLine(text) {
return text.map(function (r) {
return r.replace(/^\s+/g, '');
});
}
/* harmony default export */ var remove_space_at_beginning_of_line = (removeSpaceAtBeginningOfLine);
// CONCATENATED MODULE: ./packages/export-adapters/subtitles-generator/presegment-text/divide-into-two-lines/index.js
function divideIntoTwoLines(text) {
var lines = text.split('\n');
var counter = 0;
var result = lines.map(function (l) {
if (l === '') {
return l;
} else {
if (counter === 0) {
counter += 1;
if (l[l.length - 1][0] === '.') {
return l + '\n\n';
}
return l + '\n';
} else if (counter === 1) {
counter = 0;
return l + '\n\n';
}
}
});
result = remove_space_at_beginning_of_line(result); // remove empty lines from list to avoid unwanted space a beginning of line
result = result.filter(function (line) {
return line.length !== 0;
});
result = result.join('').trim();
return result;
}
/* harmony default export */ var divide_into_two_lines = (divideIntoTwoLines);
// CONCATENATED MODULE: ./packages/export-adapters/subtitles-generator/presegment-text/index.js
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
/**
* Takes in array of word object,
* and returns string containing all the text
* @param {array} words - Words
*/
function getTextFromWordsList(words) {
return words.map(function (word) {
return word.text;
}).join(' ');
}
/**
*
* @param {*} textInput - can be either plain text string or an array of word objects
*/
function preSegmentText(textInput) {
var tmpNumberOfCharPerLine = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 35;
var text = textInput;
if (_typeof(textInput) === 'object') {
text = getTextFromWordsList(textInput);
}
var segmentedText = text_segmentation(text); // - 2.Line brek between stentences
var textWithLineBreakBetweenSentences = line_break_between_sentences(segmentedText); // - 3.Fold char limit per line
var foldedText = fold(textWithLineBreakBetweenSentences, tmpNumberOfCharPerLine); // - 4.Divide into two lines
// console.log(foldedText)
var textDividedIntoTwoLines = divide_into_two_lines(foldedText);
return textDividedIntoTwoLines;
}
/* harmony default export */ var presegment_text = (preSegmentText);
// CONCATENATED MODULE: ./packages/export-adapters/subtitles-generator/compose-subtitles/util/escape-text.js
var AMP_REGEX = /&/g;
var LT_REGEX = /</g;
var GT_REGEX = />/g;
var escapeText = function escapeText(str) {
return str.replace(AMP_REGEX, '&').replace(LT_REGEX, '<').replace(GT_REGEX, '>');
};
/* harmony default export */ var escape_text = (escapeText);
// CONCATENATED MODULE: ./packages/export-adapters/subtitles-generator/compose-subtitles/util/format-seconds.js
var formatSeconds = function formatSeconds(seconds) {
return new Date(seconds.toFixed(3) * 1000).toISOString().substr(11, 12);
};
/* harmony default export */ var format_seconds = (formatSeconds);
// CONCATENATED MODULE: ./packages/export-adapters/subtitles-generator/compose-subtitles/premiere.js
var premiere_ttmlGeneratorPremiere = function ttmlGeneratorPremiere(vttJSON) {
var ttmlOut = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n <tt xmlns=\"http://www.w3.org/ns/ttml\"\n xmlns:ttp=\"http://www.w3.org/ns/ttml#parameter\"\n ttp:timeBase=\"media\"\n xmlns:m608=\"http://www.smpte-ra.org/schemas/2052-1/2010/smpte-tt#cea608\"\n xmlns:smpte=\"http://www.smpte-ra.org/schemas/2052-1/2010/smpte-tt\"\n xmlns:ttm=\"http://www.w3.org/ns/ttml#metadata\">\n <head>\n <metadata>\n <smpte:information m608:captionService=\"F1C1CC\" m608:channel=\"cc1\"/>\n </metadata>\n <styling></styling>\n <layout></layout>\n </head>\n <body><div>";
vttJSON.forEach(function (v) {
ttmlOut += "<p begin=\"".concat(format_seconds(parseFloat(v.start)), "\" end=\"").concat(format_seconds(parseFloat(v.end)), "\">").concat(escape_text(v.text).replace(/\n/g, '<br />'), "</p>\n");
});
ttmlOut += '</div>\n</body>\n</tt>';
return ttmlOut;
};
/* harmony default export */ var premiere = (premiere_ttmlGeneratorPremiere);
// EXTERNAL MODULE: external "smpte-timecode"
var external_smpte_timecode_ = __webpack_require__(31);
var external_smpte_timecode_default = /*#__PURE__*/__webpack_require__.n(external_smpte_timecode_);
// CONCATENATED MODULE: ./packages/export-adapters/subtitles-generator/compose-subtitles/util/tc-format.js
// for itt
var tc_format_tcFormat = function tcFormat(frames, FPS) {
var tc = external_smpte_timecode_default()(Math.round(frames), FPS, false);
return tc.toString().replace(/^00/, '01'); // FIXME this breaks on videos longer than 1h!
};
/* harmony default export */ var tc_format = (tc_format_tcFormat);
// CONCATENATED MODULE: ./packages/export-adapters/subtitles-generator/compose-subtitles/itt.js
var itt_ittGenerator = function ittGenerator(vttJSON) {
var lang = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-GB';
var FPS = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 25;
var ittOut = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <tt\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xmlns=\"http://www.w3.org/ns/ttml\"\n xmlns:tt=\"http://www.w3.org/ns/ttml\"\n xmlns:tts=\"http://www.w3.org/ns/ttml#styling\"\n xmlns:ttp=\"http://www.w3.org/ns/ttml#parameter\"\n xml:lang=\"".concat(lang, "\"\n ttp:timeBase=\"smpte\"\n ttp:frameRate=\"").concat(FPS, "\"\n ttp:frameRateMultiplier=\"").concat(FPS === 25 ? '1 1' : '999 1000', "\"\n ttp:dropMode=\"nonDrop\"\n >\n <head>\n <styling>\n <style\n xml:id=\"normal\"\n tts:fontFamily=\"sansSerif\"\n tts:fontWeight=\"normal\"\n tts:fontStyle=\"normal\"\n tts:color=\"white\"\n tts:fontSize=\"100%\"\n />\n </styling>\n <layout>\n <region\n xml:id=\"bottom\"\n tts:origin=\"0% 85%\"\n tts:extent=\"100% 15%\"\n tts:textAlign=\"center\"\n tts:displayAlign=\"after\"\n />\n </layout>\n </head>\n <body style=\"normal\" region=\"bottom\">\n <div begin=\"-01:00:00:00\">");
vttJSON.forEach(function (v) {
ittOut += "<p begin=\"".concat(tc_format(parseFloat(v.start) * FPS, FPS), "\" end=\"").concat(tc_format(parseFloat(v.end) * FPS, FPS), "\">").concat(escape_text(v.text).replace(/\n/g, '<br />'), "</p>\n");
});
ittOut += '</div>\n</body>\n</tt>';
return ittOut;
};
/* harmony default export */ var itt = (itt_ittGenerator);
// CONCATENATED MODULE: ./packages/export-adapters/subtitles-generator/compose-subtitles/ttml.js
var ttml_ttmlGenerator = function ttmlGenerator(vttJSON) {
var ttmlOut = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <tt xmlns=\"http://www.w3.org/ns/ttml\">\n <head></head>\n <body>\n <div>";
vttJSON.forEach(function (v) {
ttmlOut += "<p begin=\"".concat(format_seconds(parseFloat(v.start)), "\" end=\"").concat(format_seconds(parseFloat(v.end)), "\">").concat(escape_text(v.text).replace(/\n/g, '<br />'), "</p>\n");
});
ttmlOut += '</div>\n</body>\n</tt>';
return ttmlOut;
};
/* harmony default export */ var ttml = (ttml_ttmlGenerator);
// CONCATENATED MODULE: ./packages/export-adapters/subtitles-generator/compose-subtitles/srt.js
var srt_srtGenerator = function srtGenerator(vttJSON) {
var srtOut = '';
vttJSON.forEach(function (v, i) {
srtOut += "".concat(i + 1, "\n").concat(format_seconds(parseFloat(v.start)).replace('.', ','), " --> ").concat(format_seconds(parseFloat(v.end)).replace('.', ','), "\n").concat(v.text.trim(), "\n\n");
});
return srtOut;
};
/* harmony default export */ var srt = (srt_srtGenerator);
// CONCATENATED MODULE: ./packages/export-adapters/subtitles-generator/compose-subtitles/vtt.js
var vtt_vttGenerator = function vttGenerator(vttJSON) {
var vttOut = 'WEBVTT\n\n';
vttJSON.forEach(function (v, i) {
vttOut += "".concat(i + 1, "\n").concat(format_seconds(parseFloat(v.start)), " --> ").concat(format_seconds(parseFloat(v.end)), "\n").concat(v.text, "\n\n");
});
return vttOut;
};
/* harmony default export */ var vtt = (vtt_vttGenerator);
// CONCATENATED MODULE: ./packages/export-adapters/subtitles-generator/compose-subtitles/csv.js
function csvGenerator(srtJsonContent) {
var lines = 'N, In, Out, Text\n';
srtJsonContent.forEach(function (srtLineO, index) {
lines += "".concat(index + 1, ","); //need to surround timecodes with "\"" escaped " to escape the , for the milliseconds
lines += "\"".concat(srtLineO.start, "\",\"").concat(srtLineO.end, "\","); // removing line breaks and and removing " as they break the csv.
// wrapping text in escaped " to escape any , for the csv.
// adding carriage return \n to signal end of line in csv
// Preserving line break within srt lines to allow round trip from csv back to srt file in same format.
// by replacing \n with \r\n.
lines += "\"".concat(srtLineO.text.replace(/\n/g, '\r\n'), "\"\n");
});
return lines;
}
/* harmony default export */ var csv = (csvGenerator);
// CONCATENATED MODULE: ./packages/export-adapters/subtitles-generator/index.js
function segmentedTextToList(text) {
var result = text.split('\n\n');
result = result.map(function (line) {
return line.trim();
});
return result;
}
function countWords(text) {
return text.trim().replace(/\n /g, '').replace(/\n/g, ' ').split(' ').length;
}
function addTimecodesToLines(wordsList, lines) {
var startWordCounter = 0;
var endWordCounter = 0;
var results = lines.map(function (line) {
endWordCounter += countWords(line);
var jsonLine = {
text: line.trim()
};
jsonLine.start = wordsList[startWordCounter].start;
jsonLine.end = wordsList[endWordCounter - 1].end;
startWordCounter = endWordCounter;
return jsonLine;
});
return results;
}
function preSegmentTextJson(wordsList, numberOfCharPerLine) {
var result = presegment_text(wordsList, numberOfCharPerLine);
var segmentedTextArray = segmentedTextToList(result);
return addTimecodesToLines(wordsList, segmentedTextArray);
}
function subtitlesComposer(_ref) {
var words = _ref.words,
type = _ref.type,
numberOfCharPerLine = _ref.numberOfCharPerLine;
var subtitlesJson = preSegmentTextJson(words, numberOfCharPerLine);
if (typeof words === 'string') {
return presegment_text(words, numberOfCharPerLine);
}
switch (type) {
case 'premiere':
return premiere(subtitlesJson);
case 'ttml':
return ttml(subtitlesJson);
case 'itt':
return itt(subtitlesJson);
case 'srt':
return srt(subtitlesJson);
case 'vtt':
return vtt(subtitlesJson);
case 'json':
return subtitlesJson;
case 'csv':
return csv(subtitlesJson);
case 'pre-segment-txt':
return presegment_text(words, numberOfCharPerLine);
case 'txt':
return presegment_text(words, numberOfCharPerLine);
default:
return {
ttml: ttml(subtitlesJson),
premiere: premiere(subtitlesJson),
itt: itt(subtitlesJson),
srt: srt(subtitlesJson),
vtt: vtt(subtitlesJson),
json: subtitlesJson
};
}
}
/* harmony default export */ var subtitles_generator = (subtitlesComposer);
// CONCATENATED MODULE: ./packages/export-adapters/index.js
/**
* Adapters for Draft.js conversion
* @param {json} blockData - Draft.js blocks
* @param {string} exportFormat - the type of file supported by the available adapters
*/
var export_adapters_exportAdapter = function exportAdapter(blockData, exportFormat, transcriptTitle) {
switch (exportFormat) {
case 'draftjs':
return {
data: blockData,
ext: 'json'
};
case 'txt':
return {
data: txt(blockData),
ext: 'txt'
};
case 'docx':
return {
data: docx(blockData, transcriptTitle),
ext: 'docx'
};
case 'txtspeakertimecodes':
return {
data: txt_speakers_timecodes(blockData),
ext: 'txt'
};
case 'digitalpaperedit':
return {
data: draftjs_to_digital_paper_edit(blockData),
ext: 'json'
};
case 'srt':
var _draftToDigitalPaperE = draftjs_to_digital_paper_edit(blockData),
words = _draftToDigitalPaperE.words;
var srtContent = subtitles_generator({
words: words,
type: 'srt',
numberOfCharPerLine: 35
});
return {
data: srtContent,
ext: 'srt'
};
case 'premiereTTML':
var _draftToDigitalPaperE2 = draftjs_to_digital_paper_edit(blockData),
words = _draftToDigitalPaperE2.words;
var content = subtitles_generator({
words: words,
type: 'premiere'
});
return {
data: content,
ext: 'ttml'
};
case 'ttml':
var _draftToDigitalPaperE3 = draftjs_to_digital_paper_edit(blockData),
words = _draftToDigitalPaperE3.words;
var content = subtitles_generator({
words: words,
type: 'ttml'
});
return {
data: content,
ext: 'ttml'
};
case 'itt':
var _draftToDigitalPaperE4 = draftjs_to_digital_paper_edit(blockData),
words = _draftToDigitalPaperE4.words;
var content = subtitles_generator({
words: words,
type: 'itt'
});
return {
data: content,
ext: 'itt'
};
case 'csv':
var _draftToDigitalPaperE5 = draftjs_to_digital_paper_edit(blockData),
words = _draftToDigitalPaperE5.words;
var content = subtitles_generator({
words: words,
type: 'csv'
});
return {
data: content,
ext: 'csv'
};
case 'vtt':
var _draftToDigitalPaperE6 = draftjs_to_digital_paper_edit(blockData),
words = _draftToDigitalPaperE6.words;
var content = subtitles_generator({
words: words,
type: 'vtt'
});
return {
data: content,
ext: 'vtt'
};
case 'json-captions':
var _draftToDigitalPaperE7 = draftjs_to_digital_paper_edit(blockData),
words = _draftToDigitalPaperE7.words;
var content = subtitles_generator({
words: words,
type: 'json'
});
return {
data: content,
ext: 'json'
};
case 'pre-segment-txt':
var _draftToDigitalPaperE8 = draftjs_to_digital_paper_edit(blockData),
words = _draftToDigitalPaperE8.words;
var content = subtitles_generator({
words: words,
type: 'pre-segment-txt'
});
return {
data: content,
ext: 'txt'
};
default:
// code block
console.error('Did not recognise the export format');
}
};
/* harmony default export */ var export_adapters = __webpack_exports__["default"] = (export_adapters_exportAdapter);
/***/ }),
/***/ 30:
/***/ (function(module, exports) {
module.exports = require("sbd");
/***/ }),
/***/ 31:
/***/ (function(module, exports) {
module.exports = require("smpte-timecode");
/***/ }),
/***/ 5:
/***/ (function(module, __webpack_exports__, __webpack_require__) {
;
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, "secondsToTimecode", function() { return /* reexport */ src_secondsToTimecode; });
__webpack_require__.d(__webpack_exports__, "timecodeToSeconds", function() { return /* binding */ timecode_converter_timecodeToSeconds; });
__webpack_require__.d(__webpack_exports__, "shortTimecode", function() { return /* binding */ timecode_converter_shortTimecode; });
// CONCATENATED MODULE: ./packages/util/timecode-converter/src/secondsToTimecode.js
/**
* Raised in this comment https://github.com/bbc/react-transcript-editor/pull/9
* abstracted from https://github.com/bbc/newslabs-cdn/blob/master/js/20-bbcnpf.utils.js
* In broadcast VIDEO, timecode is NOT hh:mm:ss:ms, it's hh:mm:ss:ff where ff is frames,
* dependent on the framerate of the media concerned.
* `hh:mm:ss:ff`
*/
/**
* Helper function
* Rounds to the 14milliseconds boundaries
* Time in video can only "exist in" 14milliseconds boundaries.
* This makes it possible for the HTML5 player to be frame accurate.
* @param {*} seconds
* @param {*} fps
*/
var normalisePlayerTime = function normalisePlayerTime(seconds, fps) {
return Number((1.0 / fps * Math.floor(Number((fps * seconds).toPrecision(12)))).toFixed(2));
};
/*
* @param {*} seconds
* @param {*} fps
*/
var secondsToTimecode = function secondsToTimecode(seconds, framePerSeconds) {
// written for PAL non-drop timecode
var fps = 25;
if (framePerSeconds !== undefined) {
fps = framePerSeconds;
}
var normalisedSeconds = normalisePlayerTime(seconds, fps);
var wholeSeconds = Math.floor(normalisedSeconds);
var frames = ((normalisedSeconds - wholeSeconds) * fps).toFixed(2); // prepends zero - example pads 3 to 03
function _padZero(n) {
if (n < 10) return "0".concat(parseInt(n));
return parseInt(n);
}
return "".concat(_padZero(wholeSeconds / 60 / 60 % 60), ":").concat(_padZero(wholeSeconds / 60 % 60), ":").concat(_padZero(wholeSeconds % 60), ":").concat(_padZero(frames));
};
/* harmony default export */ var src_secondsToTimecode = (secondsToTimecode);
// CONCATENATED MODULE: ./packages/util/timecode-converter/src/timecodeToSeconds.js
/**
* Helperf unction
* @param {*} tc
* @param {*} fps
*/
var timecodeToFrames = function timecodeToFrames(tc, fps) {
// TODO make 29.97 fps drop-frame aware - works for 25 only.
var s = tc.split(':');
var frames = parseInt(s[3]);
frames += parseInt(s[2]) * fps;
frames += parseInt(s[1]) * (fps * 60);
frames += parseInt(s[0]) * (fps * 60 * 60);
return frames;
};
/**
* Convert broadcast timecodes to seconds
* @param {*} tc - `hh:mm:ss:ff`
* @param {*} framePerSeconds - defaults to 25 if not provided
*/
var timecodeToSecondsHelper = function timecodeToSecondsHelper(tc, framePerSeconds) {
var fps = 25;
if (framePerSeconds !== undefined) {
fps = framePerSeconds;
}
var frames = timecodeToFrames(tc, fps);
return Number(Number(frames / fps).toFixed(2));
};
/* harmony default export */ var src_timecodeToSeconds = (timecodeToSecondsHelper);
// CONCATENATED MODULE: ./packages/util/timecode-converter/src/padTimeToTimecode.js
var countColon = function countColon(timecode) {
return timecode.split(':').length;
};
var includesFullStop = function includesFullStop(timecode) {
return timecode.includes('.');
};
var isOneDigit = function isOneDigit(str) {
return str.length === 1;
};
var padTimeToTimecode = function padTimeToTimecode(time) {
if (typeof time === 'string') {
switch (countColon(time)) {
case 4:
// is already in timecode format
// hh:mm:ss:ff
return time;
case 2:
// m:ss
if (isOneDigit(time.split(':')[0])) {
return "00:0".concat(time, ":00");
}
return "00:".concat(time, ":00");
case 3:
// hh:mm:ss
return "".concat(time, ":00");
default:
// mm.ss
if (includesFullStop(time)) {
// m.ss
if (isOneDigit(time.split('.')[0])) {
return "00:0".concat(time.split('.')[0], ":").concat(time.split('.')[1], ":00");
}
return "00:".concat(time.replace('.', ':'), ":00");
} // if just int, then it's seconds
// s
if (isOneDigit(time)) {
return "00:00:0".concat(time, ":00");
}
return "00:00:".concat(time, ":00");
} // edge case if it's number return a number coz cannot refactor
// TODO: might need to refactor and move this elsewhere
} else {
return time;
}
};
/* harmony default export */ var src_padTimeToTimecode = (padTimeToTimecode);
// CONCATENATED MODULE: ./packages/util/timecode-converter/index.js
/**
* Wrapping around "time stamps" and timecode conversion modules
* To provide more support for variety of formats.
*/
/**
* @param {*} time
* Can take as input timecodes in the following formats
* - hh:mm:ss:ff
* - mm:ss
* - m:ss
* - ss - seconds --> if it's already in seconds then it just returns seconds
* - hh:mm:ff
* @todo could be refactored with some helper functions for clarity
*/
var timecode_converter_timecodeToSeconds = function timecodeToSeconds(time) {
if (typeof time === 'string') {
var resultPadded = src_padTimeToTimecode(time);
var resultConverted = src_timecodeToSeconds(resultPadded);
return resultConverted;
} // assuming it receive timecode as seconds as string '600'
return parseFloat(time);
};
var timecode_converter_shortTimecode = function shortTimecode(time) {
var timecode = src_secondsToTimecode(time);
return timecode.slice(0, -3);
};
/***/ })
/******/ });
//# sourceMappingURL=exportAdapter.js.map