@kablamo/react-transcript-editor
Version:
A React component to make transcribing audio and video easier and faster.
283 lines (242 loc) • 9.42 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 = 5);
/******/ })
/************************************************************************/
/******/ ({
/***/ 5:
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
// 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=timecodeConverter.js.map