"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.formatTime = formatTime;
exports.isVideoChild = isVideoChild;
exports.mergeAndSortChildren = mergeAndSortChildren;
exports.deprecatedWarning = deprecatedWarning;
exports.throttle = throttle;
exports.mediaProperties = void 0;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireDefault(require("react"));
// NaN is the only value in javascript which is not equal to itself.
// eslint-disable-next-line no-self-compare
var isNaN = Number.isNaN || function (value) {
return value !== value;
};
/**
* @file format-time.js
*
* Format seconds as a time string, H:MM:SS or M:SS
* Supplying a guide (in seconds) will force a number of leading zeros
* to cover the length of the guide
*
* @param {Number} seconds Number of seconds to be turned into a string
* @param {Number} guide Number (in seconds) to model the string after
* @return {String} Time formatted as H:MM:SS or M:SS
* @private
* @function formatTime
*/
function formatTime() {
var seconds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
var guide = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : seconds;
var s = Math.floor(seconds % 60);
var m = Math.floor(seconds / 60 % 60);
var h = Math.floor(seconds / 3600);
var gm = Math.floor(guide / 60 % 60);
var gh = Math.floor(guide / 3600); // handle invalid times
if (isNaN(seconds) || seconds === Infinity) {
// '-' is false for all relational operators (e.g. <, >=) so this setting
// will add the minimum number of fields specified by the guide
h = '-';
m = '-';
s = '-';
} // Check if we need to show hours
h = h > 0 || gh > 0 ? "".concat(h, ":") : ''; // If hours are showing, we may need to add a leading zero.
// Always show at least one digit of minutes.
m = "".concat((h || gm >= 10) && m < 10 ? "0".concat(m) : m, ":"); // Check if leading zero is need for seconds
s = s < 10 ? "0".concat(s) : s;
return h + m + s;
} // Check if the element belongs to a video element
// only accept , ,
//
// elements
function isVideoChild(c) {
if (c.props && c.props.isVideoChild) {
return true;
}
return c.type === 'source' || c.type === 'track';
}
var find = function find(elements, func) {
return elements.filter(func)[0];
}; // check if two components are the same type
var isTypeEqual = function isTypeEqual(component1, component2) {
var type1 = component1.type;
var type2 = component2.type;
if (typeof type1 === 'string' || typeof type2 === 'string') {
return type1 === type2;
}
if (typeof type1 === 'function' && typeof type2 === 'function') {
return type1.displayName === type2.displayName;
}
return false;
}; // merge default children
// sort them by `order` property
// filter them by `disabled` property
function mergeAndSortChildren(defaultChildren, _children, _parentProps) {
var defaultOrder = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
var children = _react["default"].Children.toArray(_children);
var order = _parentProps.order,
parentProps = (0, _objectWithoutProperties2["default"])(_parentProps, ["order"]); // ignore order from parent
return children.filter(function (e) {
return !e.props.disabled;
}) // filter the disabled components
.concat(defaultChildren.filter(function (c) {
return !find(children, function (component) {
return isTypeEqual(component, c);
});
})).map(function (element) {
var defaultComponent = find(defaultChildren, function (c) {
return isTypeEqual(c, element);
});
var defaultProps = defaultComponent ? defaultComponent.props : {};
var props = (0, _objectSpread2["default"])({}, parentProps, defaultProps, element.props);
var e = _react["default"].cloneElement(element, props, element.props.children);
return e;
}).sort(function (a, b) {
return (a.props.order || defaultOrder) - (b.props.order || defaultOrder);
});
}
/**
* Temporary utility for generating the warnings
*/
function deprecatedWarning(oldMethodCall, newMethodCall) {
// eslint-disable-next-line no-console
console.warn("WARNING: ".concat(oldMethodCall, " will be deprecated soon! Please use ").concat(newMethodCall, " instead."));
}
function throttle(callback, limit) {
var _arguments = arguments;
var wait = false;
return function () {
if (!wait) {
// eslint-disable-next-line prefer-rest-params
callback.apply(void 0, (0, _toConsumableArray2["default"])(_arguments));
wait = true;
setTimeout(function () {
wait = false;
}, limit);
}
};
}
var mediaProperties = ['error', 'src', 'srcObject', 'currentSrc', 'crossOrigin', 'networkState', 'preload', 'buffered', 'readyState', 'seeking', 'currentTime', 'duration', 'paused', 'defaultPlaybackRate', 'playbackRate', 'played', 'seekable', 'ended', 'autoplay', 'loop', 'mediaGroup', 'controller', 'controls', 'volume', 'muted', 'defaultMuted', 'audioTracks', 'videoTracks', 'textTracks', 'width', 'height', 'videoWidth', 'videoHeight', 'poster'];
exports.mediaProperties = mediaProperties;