openplayerjs
Version:
HTML5 video and audio player
1,113 lines (1,067 loc) • 359 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["openplayerjs"] = factory();
else
root["openplayerjs"] = factory();
})(this, function() {
return /******/ (function() { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ 633:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
var _typeof = (__webpack_require__(738)["default"]);
function _regeneratorRuntime() {
"use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
module.exports = _regeneratorRuntime = function _regeneratorRuntime() {
return e;
}, module.exports.__esModule = true, module.exports["default"] = module.exports;
var t,
e = {},
r = Object.prototype,
n = r.hasOwnProperty,
o = Object.defineProperty || function (t, e, r) {
t[e] = r.value;
},
i = "function" == typeof Symbol ? Symbol : {},
a = i.iterator || "@@iterator",
c = i.asyncIterator || "@@asyncIterator",
u = i.toStringTag || "@@toStringTag";
function define(t, e, r) {
return Object.defineProperty(t, e, {
value: r,
enumerable: !0,
configurable: !0,
writable: !0
}), t[e];
}
try {
define({}, "");
} catch (t) {
define = function define(t, e, r) {
return t[e] = r;
};
}
function wrap(t, e, r, n) {
var i = e && e.prototype instanceof Generator ? e : Generator,
a = Object.create(i.prototype),
c = new Context(n || []);
return o(a, "_invoke", {
value: makeInvokeMethod(t, r, c)
}), a;
}
function tryCatch(t, e, r) {
try {
return {
type: "normal",
arg: t.call(e, r)
};
} catch (t) {
return {
type: "throw",
arg: t
};
}
}
e.wrap = wrap;
var h = "suspendedStart",
l = "suspendedYield",
f = "executing",
s = "completed",
y = {};
function Generator() {}
function GeneratorFunction() {}
function GeneratorFunctionPrototype() {}
var p = {};
define(p, a, function () {
return this;
});
var d = Object.getPrototypeOf,
v = d && d(d(values([])));
v && v !== r && n.call(v, a) && (p = v);
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
function defineIteratorMethods(t) {
["next", "throw", "return"].forEach(function (e) {
define(t, e, function (t) {
return this._invoke(e, t);
});
});
}
function AsyncIterator(t, e) {
function invoke(r, o, i, a) {
var c = tryCatch(t[r], t, o);
if ("throw" !== c.type) {
var u = c.arg,
h = u.value;
return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
invoke("next", t, i, a);
}, function (t) {
invoke("throw", t, i, a);
}) : e.resolve(h).then(function (t) {
u.value = t, i(u);
}, function (t) {
return invoke("throw", t, i, a);
});
}
a(c.arg);
}
var r;
o(this, "_invoke", {
value: function value(t, n) {
function callInvokeWithMethodAndArg() {
return new e(function (e, r) {
invoke(t, n, e, r);
});
}
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
}
});
}
function makeInvokeMethod(e, r, n) {
var o = h;
return function (i, a) {
if (o === f) throw Error("Generator is already running");
if (o === s) {
if ("throw" === i) throw a;
return {
value: t,
done: !0
};
}
for (n.method = i, n.arg = a;;) {
var c = n.delegate;
if (c) {
var u = maybeInvokeDelegate(c, n);
if (u) {
if (u === y) continue;
return u;
}
}
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
if (o === h) throw o = s, n.arg;
n.dispatchException(n.arg);
} else "return" === n.method && n.abrupt("return", n.arg);
o = f;
var p = tryCatch(e, r, n);
if ("normal" === p.type) {
if (o = n.done ? s : l, p.arg === y) continue;
return {
value: p.arg,
done: n.done
};
}
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
}
};
}
function maybeInvokeDelegate(e, r) {
var n = r.method,
o = e.iterator[n];
if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
var i = tryCatch(o, e.iterator, r.arg);
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
var a = i.arg;
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
}
function pushTryEntry(t) {
var e = {
tryLoc: t[0]
};
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
}
function resetTryEntry(t) {
var e = t.completion || {};
e.type = "normal", delete e.arg, t.completion = e;
}
function Context(t) {
this.tryEntries = [{
tryLoc: "root"
}], t.forEach(pushTryEntry, this), this.reset(!0);
}
function values(e) {
if (e || "" === e) {
var r = e[a];
if (r) return r.call(e);
if ("function" == typeof e.next) return e;
if (!isNaN(e.length)) {
var o = -1,
i = function next() {
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
return next.value = t, next.done = !0, next;
};
return i.next = i;
}
}
throw new TypeError(_typeof(e) + " is not iterable");
}
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
value: GeneratorFunctionPrototype,
configurable: !0
}), o(GeneratorFunctionPrototype, "constructor", {
value: GeneratorFunction,
configurable: !0
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
var e = "function" == typeof t && t.constructor;
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
}, e.mark = function (t) {
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
}, e.awrap = function (t) {
return {
__await: t
};
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
return this;
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
void 0 === i && (i = Promise);
var a = new AsyncIterator(wrap(t, r, n, o), i);
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
return t.done ? t.value : a.next();
});
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
return this;
}), define(g, "toString", function () {
return "[object Generator]";
}), e.keys = function (t) {
var e = Object(t),
r = [];
for (var n in e) r.push(n);
return r.reverse(), function next() {
for (; r.length;) {
var t = r.pop();
if (t in e) return next.value = t, next.done = !1, next;
}
return next.done = !0, next;
};
}, e.values = values, Context.prototype = {
constructor: Context,
reset: function reset(e) {
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
},
stop: function stop() {
this.done = !0;
var t = this.tryEntries[0].completion;
if ("throw" === t.type) throw t.arg;
return this.rval;
},
dispatchException: function dispatchException(e) {
if (this.done) throw e;
var r = this;
function handle(n, o) {
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
}
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
var i = this.tryEntries[o],
a = i.completion;
if ("root" === i.tryLoc) return handle("end");
if (i.tryLoc <= this.prev) {
var c = n.call(i, "catchLoc"),
u = n.call(i, "finallyLoc");
if (c && u) {
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
} else if (c) {
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
} else {
if (!u) throw Error("try statement without catch or finally");
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
}
}
}
},
abrupt: function abrupt(t, e) {
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
var o = this.tryEntries[r];
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
var i = o;
break;
}
}
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
var a = i ? i.completion : {};
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
},
complete: function complete(t, e) {
if ("throw" === t.type) throw t.arg;
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
},
finish: function finish(t) {
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
var r = this.tryEntries[e];
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
}
},
"catch": function _catch(t) {
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
var r = this.tryEntries[e];
if (r.tryLoc === t) {
var n = r.completion;
if ("throw" === n.type) {
var o = n.arg;
resetTryEntry(r);
}
return o;
}
}
throw Error("illegal catch attempt");
},
delegateYield: function delegateYield(e, r, n) {
return this.delegate = {
iterator: values(e),
resultName: r,
nextLoc: n
}, "next" === this.method && (this.arg = t), y;
}
}, e;
}
module.exports = _regeneratorRuntime, module.exports.__esModule = true, module.exports["default"] = module.exports;
/***/ }),
/***/ 738:
/***/ (function(module) {
function _typeof(o) {
"@babel/helpers - typeof";
return module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, module.exports.__esModule = true, module.exports["default"] = module.exports, _typeof(o);
}
module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports;
/***/ }),
/***/ 756:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
// TODO(Babel 8): Remove this file.
var runtime = __webpack_require__(633)();
module.exports = runtime;
// Copied from https://github.com/facebook/regenerator/blob/main/packages/runtime/runtime.js#L736=
try {
regeneratorRuntime = runtime;
} catch (accidentalStrictMode) {
if (typeof globalThis === "object") {
globalThis.regeneratorRuntime = runtime;
} else {
Function("r", "regeneratorRuntime = r")(runtime);
}
}
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ !function() {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function() { return module['default']; } :
/******/ function() { return module; };
/******/ __webpack_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ !function() {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = function(exports, definition) {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ !function() {
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
/******/ }();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ !function() {
/******/ // 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 });
/******/ };
/******/ }();
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry needs to be wrapped in an IIFE because it needs to be in strict mode.
!function() {
"use strict";
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
"default": function() { return /* binding */ player; }
});
;// ./node_modules/@babel/runtime/helpers/esm/typeof.js
function typeof_typeof(o) {
"@babel/helpers - typeof";
return typeof_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, typeof_typeof(o);
}
;// ./node_modules/@babel/runtime/helpers/esm/toPrimitive.js
function toPrimitive(t, r) {
if ("object" != typeof_typeof(t) || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != typeof_typeof(i)) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
;// ./node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
function toPropertyKey(t) {
var i = toPrimitive(t, "string");
return "symbol" == typeof_typeof(i) ? i : i + "";
}
;// ./node_modules/@babel/runtime/helpers/esm/defineProperty.js
function _defineProperty(e, r, t) {
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[r] = t, e;
}
;// ./node_modules/@babel/runtime/helpers/esm/classCallCheck.js
function _classCallCheck(a, n) {
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
}
;// ./node_modules/@babel/runtime/helpers/esm/createClass.js
function _defineProperties(e, r) {
for (var t = 0; t < r.length; t++) {
var o = r[t];
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, toPropertyKey(o.key), o);
}
}
function _createClass(e, r, t) {
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
writable: !1
}), e;
}
// EXTERNAL MODULE: ./node_modules/@babel/runtime/regenerator/index.js
var regenerator = __webpack_require__(756);
var regenerator_default = /*#__PURE__*/__webpack_require__.n(regenerator);
;// ./node_modules/@babel/runtime/helpers/esm/arrayWithHoles.js
function _arrayWithHoles(r) {
if (Array.isArray(r)) return r;
}
;// ./node_modules/@babel/runtime/helpers/esm/iterableToArrayLimit.js
function _iterableToArrayLimit(r, l) {
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (null != t) {
var e,
n,
i,
u,
a = [],
f = !0,
o = !1;
try {
if (i = (t = t.call(r)).next, 0 === l) {
if (Object(t) !== t) return;
f = !1;
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
} catch (r) {
o = !0, n = r;
} finally {
try {
if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
} finally {
if (o) throw n;
}
}
return a;
}
}
;// ./node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js
function _arrayLikeToArray(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
;// ./node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js
function _unsupportedIterableToArray(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
}
}
;// ./node_modules/@babel/runtime/helpers/esm/nonIterableRest.js
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
;// ./node_modules/@babel/runtime/helpers/esm/slicedToArray.js
function _slicedToArray(r, e) {
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
}
;// ./src/js/utils/constants.ts
var NAV = typeof window !== 'undefined' ? window.navigator : null;
var UA = NAV ? NAV.userAgent.toLowerCase() : null;
var IS_IPAD = UA ? /ipad/i.test(UA) && !window.MSStream : false;
var IS_IPHONE = UA ? /iphone/i.test(UA) && !window.MSStream : false;
var IS_IPOD = UA ? /ipod/i.test(UA) && !window.MSStream : false;
var IS_IOS = UA ? /ipad|iphone|ipod/i.test(UA) && !window.MSStream : false;
var IS_ANDROID = UA ? /android/i.test(UA) : false;
var IS_EDGE = NAV ? 'msLaunchUri' in NAV && !('documentMode' in document) : false;
var IS_CHROME = UA ? /chrome/i.test(UA) : false;
var IS_FIREFOX = UA ? /firefox/i.test(UA) : false;
var IS_SAFARI = UA ? /safari/i.test(UA) && !IS_CHROME : false;
var IS_STOCK_ANDROID = UA ? /^mozilla\/\d+\.\d+\s\(linux;\su;/i.test(UA) : false;
var HAS_MSE = typeof window !== 'undefined' ? 'MediaSource' in window : false;
var SUPPORTS_HLS = function SUPPORTS_HLS() {
if (typeof window === 'undefined') {
return false;
}
var mediaSource = window.MediaSource || window.WebKitMediaSource;
var sourceBuffer = window.SourceBuffer || window.WebKitSourceBuffer;
var isTypeSupported = mediaSource && typeof mediaSource.isTypeSupported === 'function' && mediaSource.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"');
var sourceBufferValidAPI = !sourceBuffer || sourceBuffer.prototype && typeof sourceBuffer.prototype.appendBuffer === 'function' && typeof sourceBuffer.prototype.remove === 'function';
return !!isTypeSupported && !!sourceBufferValidAPI && !IS_SAFARI;
};
var DVR_THRESHOLD = 120;
var EVENT_OPTIONS = {
passive: false
};
;// ./src/js/utils/general.ts
function getAbsoluteUrl(url) {
var a = document.createElement('a');
a.href = url;
return a.href;
}
function isVideo(element) {
return element.tagName.toLowerCase() === 'video';
}
function isAudio(element) {
return element.tagName.toLowerCase() === 'audio';
}
function loadScript(url) {
return new Promise(function (resolve, reject) {
var script = document.createElement('script');
script.src = url;
script.async = true;
script.onload = function () {
script.remove();
resolve();
};
script.onerror = function () {
script.remove();
reject(new Error("".concat(url, " could not be loaded")));
};
if (document.head) {
document.head.appendChild(script);
}
});
}
function offset(el) {
var rect = el.getBoundingClientRect();
return {
left: rect.left + (window.pageXOffset || document.documentElement.scrollLeft),
top: rect.top + (window.pageYOffset || document.documentElement.scrollTop)
};
}
function sanitize(html) {
var plainText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var parser = new DOMParser();
var content = parser.parseFromString(html, 'text/html');
var formattedContent = content.body || document.createElement('body');
var scripts = formattedContent.querySelectorAll('script');
for (var i = 0, total = scripts.length; i < total; i++) {
scripts[i].remove();
}
var _clean = function clean(element) {
var nodes = element.children;
for (var _i = 0, _total = nodes.length; _i < _total; _i++) {
var node = nodes[_i];
var attributes = node.attributes;
for (var j = 0, t = attributes.length; j < t; j++) {
var _attributes$j = attributes[j],
name = _attributes$j.name,
value = _attributes$j.value;
var val = value.replace(/\s+/g, '').toLowerCase();
if (['src', 'href', 'xlink:href'].includes(name)) {
if (val.includes('javascript:') || val.includes('data:')) {
node.removeAttribute(name);
}
}
if (name.startsWith('on')) {
node.removeAttribute(name);
}
}
_clean(node);
}
};
_clean(formattedContent);
return plainText ? (formattedContent.textContent || '').replace(/\s{2,}/g, '') : formattedContent.innerHTML;
}
function isXml(input) {
var parsedXml;
if (typeof DOMParser !== 'undefined') {
parsedXml = function parsedXml(text) {
return new DOMParser().parseFromString(text, 'text/xml');
};
} else {
return false;
}
try {
var response = parsedXml(input);
if (response.getElementsByTagName('parsererror').length > 0) {
return false;
}
} catch (e) {
return false;
}
return true;
}
function isJson(item) {
item = typeof item !== 'string' ? JSON.stringify(item) : item;
try {
item = JSON.parse(item);
} catch (e) {
return false;
}
if (_typeof(item) === 'object' && item !== null) {
return true;
}
return false;
}
function addEvent(event, details) {
var detail = {};
if (details && details.detail) {
detail = {
detail: details.detail
};
}
return new CustomEvent(event, detail);
}
;// ./src/js/controls/captions.ts
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = captions_unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
function captions_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return captions_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? captions_arrayLikeToArray(r, a) : void 0; } }
function captions_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
var __classPrivateFieldSet = undefined && undefined.__classPrivateFieldSet || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
};
var __classPrivateFieldGet = undefined && undefined.__classPrivateFieldGet || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _Captions_player, _Captions_button, _Captions_captions, _Captions_menu, _Captions_events, _Captions_mediaTrackList, _Captions_hasTracks, _Captions_currentTrack, _Captions_default, _Captions_controlPosition, _Captions_controlLayer;
var Captions = function () {
function Captions(player, position, layer) {
_classCallCheck(this, Captions);
_Captions_player.set(this, void 0);
_Captions_button.set(this, void 0);
_Captions_captions.set(this, void 0);
_Captions_menu.set(this, void 0);
_Captions_events.set(this, {
button: {},
global: {},
media: {}
});
_Captions_mediaTrackList.set(this, void 0);
_Captions_hasTracks.set(this, void 0);
_Captions_currentTrack.set(this, void 0);
_Captions_default.set(this, 'off');
_Captions_controlPosition.set(this, void 0);
_Captions_controlLayer.set(this, void 0);
__classPrivateFieldSet(this, _Captions_player, player, "f");
__classPrivateFieldSet(this, _Captions_controlPosition, position, "f");
__classPrivateFieldSet(this, _Captions_controlLayer, layer, "f");
this._formatMenuItems = this._formatMenuItems.bind(this);
this._setDefaultTrack = this._setDefaultTrack.bind(this);
this._showCaptions = this._showCaptions.bind(this);
this._hideCaptions = this._hideCaptions.bind(this);
}
return _createClass(Captions, [{
key: "create",
value: function create() {
var _this = this;
var _a;
var _classPrivateFieldGe = __classPrivateFieldGet(this, _Captions_player, "f").getElement(),
textTracks = _classPrivateFieldGe.textTracks;
var _classPrivateFieldGe2 = __classPrivateFieldGet(this, _Captions_player, "f").getOptions(),
labels = _classPrivateFieldGe2.labels,
detachMenus = _classPrivateFieldGe2.detachMenus;
__classPrivateFieldSet(this, _Captions_mediaTrackList, Object.keys(textTracks).map(function (k) {
return textTracks[Number(k)];
}).filter(function (el) {
return ['subtitles', 'captions'].includes(el.kind) && el.language;
}), "f");
__classPrivateFieldSet(this, _Captions_hasTracks, !!__classPrivateFieldGet(this, _Captions_mediaTrackList, "f").length, "f");
if (!__classPrivateFieldGet(this, _Captions_hasTracks, "f")) {
return;
}
__classPrivateFieldSet(this, _Captions_button, document.createElement('button'), "f");
__classPrivateFieldGet(this, _Captions_button, "f").className = "op-controls__captions op-control__".concat(__classPrivateFieldGet(this, _Captions_controlPosition, "f"));
__classPrivateFieldGet(this, _Captions_button, "f").tabIndex = 0;
__classPrivateFieldGet(this, _Captions_button, "f").title = (labels === null || labels === void 0 ? void 0 : labels.toggleCaptions) || '';
__classPrivateFieldGet(this, _Captions_button, "f").setAttribute('aria-controls', __classPrivateFieldGet(this, _Captions_player, "f").id);
__classPrivateFieldGet(this, _Captions_button, "f").setAttribute('aria-pressed', 'false');
__classPrivateFieldGet(this, _Captions_button, "f").setAttribute('aria-label', (labels === null || labels === void 0 ? void 0 : labels.toggleCaptions) || '');
__classPrivateFieldGet(this, _Captions_button, "f").setAttribute('data-active-captions', 'off');
__classPrivateFieldSet(this, _Captions_captions, document.createElement('div'), "f");
__classPrivateFieldGet(this, _Captions_captions, "f").className = 'op-captions';
var target = __classPrivateFieldGet(this, _Captions_player, "f").getContainer();
target.insertBefore(__classPrivateFieldGet(this, _Captions_captions, "f"), target.firstChild);
if (detachMenus) {
__classPrivateFieldGet(this, _Captions_button, "f").classList.add('op-control--no-hover');
__classPrivateFieldSet(this, _Captions_menu, document.createElement('div'), "f");
__classPrivateFieldGet(this, _Captions_menu, "f").className = 'op-settings op-captions__menu';
__classPrivateFieldGet(this, _Captions_menu, "f").setAttribute('aria-hidden', 'true');
__classPrivateFieldGet(this, _Captions_menu, "f").innerHTML = "<div class=\"op-settings__menu\" role=\"menu\" id=\"menu-item-captions\">\n <div class=\"op-settings__submenu-item\" tabindex=\"0\" role=\"menuitemradio\" aria-checked=\"".concat(__classPrivateFieldGet(this, _Captions_default, "f") === 'off' ? 'true' : 'false', "\">\n <div class=\"op-settings__submenu-label op-subtitles__option\" data-value=\"captions-off\">").concat(labels === null || labels === void 0 ? void 0 : labels.off, "</div>\n </div>\n </div>");
var itemContainer = document.createElement('div');
itemContainer.className = "op-controls__container op-control__".concat(__classPrivateFieldGet(this, _Captions_controlPosition, "f"));
itemContainer.append(__classPrivateFieldGet(this, _Captions_button, "f"), __classPrivateFieldGet(this, _Captions_menu, "f"));
__classPrivateFieldGet(this, _Captions_player, "f").getControls().getLayer(__classPrivateFieldGet(this, _Captions_controlLayer, "f")).append(itemContainer);
var _iterator = _createForOfIteratorHelper(__classPrivateFieldGet(this, _Captions_mediaTrackList, "f")),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var track = _step.value;
var item = document.createElement('div');
var label = ((_a = labels === null || labels === void 0 ? void 0 : labels.lang) === null || _a === void 0 ? void 0 : _a[track.language]) || null;
item.className = 'op-settings__submenu-item';
item.tabIndex = 0;
item.setAttribute('role', 'menuitemradio');
item.setAttribute('aria-checked', __classPrivateFieldGet(this, _Captions_default, "f") === track.language ? 'true' : 'false');
item.innerHTML = "<div class=\"op-settings__submenu-label op-subtitles__option\"\n data-value=\"captions-".concat(track.language, "\">\n ").concat(label || track.label, "\n </div>");
__classPrivateFieldGet(this, _Captions_menu, "f").append(item);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
} else {
__classPrivateFieldGet(this, _Captions_player, "f").getControls().getLayer(__classPrivateFieldGet(this, _Captions_controlLayer, "f")).append(__classPrivateFieldGet(this, _Captions_button, "f"));
}
__classPrivateFieldGet(this, _Captions_events, "f").button.click = function (e) {
var _a;
var button = e.target;
if (detachMenus) {
var menus = __classPrivateFieldGet(_this, _Captions_player, "f").getContainer().querySelectorAll('.op-settings');
for (var _i = 0, _Array$from = Array.from(menus); _i < _Array$from.length; _i++) {
var menuItem = _Array$from[_i];
if (menuItem !== __classPrivateFieldGet(_this, _Captions_menu, "f")) {
menuItem.setAttribute('aria-hidden', 'true');
}
}
if (__classPrivateFieldGet(_this, _Captions_menu, "f").getAttribute('aria-hidden') === 'true') {
__classPrivateFieldGet(_this, _Captions_menu, "f").setAttribute('aria-hidden', 'false');
} else {
__classPrivateFieldGet(_this, _Captions_menu, "f").setAttribute('aria-hidden', 'true');
}
} else {
button.setAttribute('aria-pressed', 'true');
if (button.classList.contains('op-controls__captions--on')) {
button.classList.remove('op-controls__captions--on');
button.setAttribute('data-active-captions', 'off');
_this._hideCaptions();
} else {
button.classList.add('op-controls__captions--on');
button.setAttribute('data-active-captions', ((_a = __classPrivateFieldGet(_this, _Captions_currentTrack, "f")) === null || _a === void 0 ? void 0 : _a.language) || 'off');
_this._showCaptions();
}
var _iterator2 = _createForOfIteratorHelper(__classPrivateFieldGet(_this, _Captions_mediaTrackList, "f")),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var _track = _step2.value;
_track.mode = button.getAttribute('data-active-captions') === _track.language ? 'showing' : 'hidden';
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
}
};
__classPrivateFieldGet(this, _Captions_events, "f").button.mouseover = function () {
if (!IS_IOS && !IS_ANDROID && detachMenus) {
var menus = __classPrivateFieldGet(_this, _Captions_player, "f").getContainer().querySelectorAll('.op-settings');
for (var i = 0, total = menus.length; i < total; ++i) {
if (menus[i] !== __classPrivateFieldGet(_this, _Captions_menu, "f")) {
menus[i].setAttribute('aria-hidden', 'true');
}
}
if (__classPrivateFieldGet(_this, _Captions_menu, "f").getAttribute('aria-hidden') === 'true') {
__classPrivateFieldGet(_this, _Captions_menu, "f").setAttribute('aria-hidden', 'false');
}
}
};
__classPrivateFieldGet(this, _Captions_events, "f").button.mouseout = function () {
if (!IS_IOS && !IS_ANDROID && detachMenus) {
var menus = __classPrivateFieldGet(_this, _Captions_player, "f").getContainer().querySelectorAll('.op-settings');
for (var i = 0, total = menus.length; i < total; ++i) {
menus[i].setAttribute('aria-hidden', 'true');
}
if (__classPrivateFieldGet(_this, _Captions_menu, "f").getAttribute('aria-hidden') === 'false') {
__classPrivateFieldGet(_this, _Captions_menu, "f").setAttribute('aria-hidden', 'true');
}
}
};
__classPrivateFieldGet(this, _Captions_button, "f").addEventListener('click', __classPrivateFieldGet(this, _Captions_events, "f").button.click, EVENT_OPTIONS);
__classPrivateFieldGet(this, _Captions_events, "f").global.click = function (e) {
var option = e.target;
if (option.closest("#".concat(__classPrivateFieldGet(_this, _Captions_player, "f").id)) && option.classList.contains('op-subtitles__option')) {
var language = option.getAttribute('data-value').replace('captions-', '');
_this._hideCaptions();
if (language === 'off') {
__classPrivateFieldSet(_this, _Captions_currentTrack, undefined, "f");
}
var _iterator3 = _createForOfIteratorHelper(__classPrivateFieldGet(_this, _Captions_mediaTrackList, "f")),
_step3;
try {
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
var _track2 = _step3.value;
_track2.mode = _track2.language === language ? 'showing' : 'hidden';
if (_track2.language === language) {
__classPrivateFieldSet(_this, _Captions_currentTrack, _track2, "f");
_this._showCaptions();
}
}
} catch (err) {
_iterator3.e(err);
} finally {
_iterator3.f();
}
if (detachMenus) {
if (__classPrivateFieldGet(_this, _Captions_button, "f").classList.contains('op-controls__captions--on')) {
__classPrivateFieldGet(_this, _Captions_button, "f").classList.remove('op-controls__captions--on');
__classPrivateFieldGet(_this, _Captions_button, "f").setAttribute('data-active-captions', 'off');
} else {
__classPrivateFieldGet(_this, _Captions_button, "f").classList.add('op-controls__captions--on');
__classPrivateFieldGet(_this, _Captions_button, "f").setAttribute('data-active-captions', language);
}
var captions = __classPrivateFieldGet(_this, _Captions_menu, "f").querySelectorAll('.op-settings__submenu-item');
for (var _i2 = 0, _Array$from2 = Array.from(captions); _i2 < _Array$from2.length; _i2++) {
var caption = _Array$from2[_i2];
caption.setAttribute('aria-checked', 'false');
}
option.parentElement.setAttribute('aria-checked', 'true');
__classPrivateFieldGet(_this, _Captions_menu, "f").setAttribute('aria-hidden', 'false');
} else {
__classPrivateFieldGet(_this, _Captions_button, "f").setAttribute('data-active-captions', language);
}
var event = addEvent('captionschanged');
__classPrivateFieldGet(_this, _Captions_player, "f").getElement().dispatchEvent(event);
}
};
__classPrivateFieldGet(this, _Captions_events, "f").global.cuechange = function (e) {
var _a;
_this._hideCaptions();
var t = e.target;
if (t.mode !== 'showing' || __classPrivateFieldGet(_this, _Captions_button, "f").getAttribute('data-active-captions') === 'off') {
return;
}
if (t.activeCues && ((_a = t.activeCues) === null || _a === void 0 ? void 0 : _a.length) > 0) {
_this._showCaptions();
}
};
if (detachMenus) {
__classPrivateFieldGet(this, _Captions_button, "f").addEventListener('mouseover', __classPrivateFieldGet(this, _Captions_events, "f").button.mouseover, EVENT_OPTIONS);
__classPrivateFieldGet(this, _Captions_menu, "f").addEventListener('mouseover', __classPrivateFieldGet(this, _Captions_events, "f").button.mouseover, EVENT_OPTIONS);
__classPrivateFieldGet(this, _Captions_menu, "f").addEventListener('mouseout', __classPrivateFieldGet(this, _Captions_events, "f").button.mouseout, EVENT_OPTIONS);
__classPrivateFieldGet(this, _Captions_player, "f").getElement().addEventListener('controlshidden', __classPrivateFieldGet(this, _Captions_events, "f").button.mouseout, EVENT_OPTIONS);
}
document.addEventListener('click', __classPrivateFieldGet(this, _Captions_events, "f").global.click, EVENT_OPTIONS);
var _iterator4 = _createForOfIteratorHelper(__classPrivateFieldGet(this, _Captions_mediaTrackList, "f")),
_step4;
try {
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
var _track3 = _step4.value;
_track3.mode = _track3.mode !== 'showing' ? 'hidden' : _track3.mode;
_track3.addEventListener('cuechange', __classPrivateFieldGet(this, _Captions_events, "f").global.cuechange, EVENT_OPTIONS);
}
} catch (err) {
_iterator4.e(err);
} finally {
_iterator4.f();
}
var targetTrack = __classPrivateFieldGet(this, _Captions_player, "f").getElement().querySelector('track:is([kind="subtitles"],[kind="captions"])[default]');
if (targetTrack) {
var matchTrack = __classPrivateFieldGet(this, _Captions_mediaTrackList, "f").find(function (el) {
return el.language === targetTrack.srclang;
});
if (matchTrack) {
this._setDefaultTrack(matchTrack);
}
}
}
}, {
key: "destroy",
value: function destroy() {
var _classPrivateFieldGe3 = __classPrivateFieldGet(this, _Captions_player, "f").getOptions(),
detachMenus = _classPrivateFieldGe3.detachMenus;
if (!__classPrivateFieldGet(this, _Captions_hasTracks, "f")) {
return;
}
var _iterator5 = _createForOfIteratorHelper(__classPrivateFieldGet(this, _Captions_mediaTrackList, "f")),
_step5;
try {
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
var track = _step5.value;
track.removeEventListener('cuechange', __classPrivateFieldGet(this, _Captions_events, "f").global.cuechange);
}
} catch (err) {
_iterator5.e(err);
} finally {
_iterator5.f();
}
document.removeEventListener('click', __classPrivateFieldGet(this, _Captions_events, "f").global.click);
__classPrivateFieldGet(this, _Captions_button, "f").removeEventListener('click', __classPrivateFieldGet(this, _Captions_events, "f").button.click);
if (detachMenus) {
__classPrivateFieldGet(this, _Captions_button, "f").removeEventListener('mouseover', __classPrivateFieldGet(this, _Captions_events, "f").button.mouseover);
__classPrivateFieldGet(this, _Captions_menu, "f").removeEventListener('mouseover', __classPrivateFieldGet(this, _Captions_events, "f").button.mouseover);
__classPrivateFieldGet(this, _Captions_menu, "f").removeEventListener('mouseout', __classPrivateFieldGet(this, _Captions_events, "f").button.mouseout);
__classPrivateFieldGet(this, _Captions_player, "f").getElement().removeEventListener('controlshidden', __classPrivateFieldGet(this, _Captions_events, "f").button.mouseout);
__classPrivateFieldGet(this, _Captions_menu, "f").remove();
}
__classPrivateFieldGet(this, _Captions_button, "f").remove();
}
}, {
key: "addSettings",
value: function addSettings() {
var _classPrivateFieldGe4 = __classPrivateFieldGet(this, _Captions_player, "f").getOptions(),
detachMenus = _classPrivateFieldGe4.detachMenus,
labels = _classPrivateFieldGe4.labels;
if (detachMenus || __classPrivateFieldGet(this, _Captions_mediaTrackList, "f").length <= 1) {
return {};
}
var subitems = this._formatMenuItems();
return subitems.length > 2 ? {
className: 'op-subtitles__option',
default: __classPrivateFieldGet(this, _Captions_default, "f") || 'off',
key: 'captions',
name: (labels === null || labels === void 0 ? void 0 : labels.captions) || '',
subitems: subitems
} : {};
}
}, {
key: "_formatMenuItems",
value: function _formatMenuItems() {
var _classPrivateFieldGe5 = __classPrivateFieldGet(this, _Captions_player, "f").getOptions(),
labels = _classPrivateFieldGe5.labels,
detachMenus = _classPrivateFieldGe5.detachMenus;
if (__classPrivateFieldGet(this, _Captions_mediaTrackList, "f").length <= 1 && !detachMenus) {
return [];
}
var items = [{
key: 'off',
label: (labels === null || labels === void 0 ? void 0 : labels.off) || ''
}];
var _iterator6 = _createForOfIteratorHelper(__classPrivateFieldGet(this, _Captions_mediaTrackList, "f")),
_step6;
try {
var _loop = function _loop() {
var track = _step6.value;
var label = (labels === null || labels === void 0 ? void 0 : labels.lang) ? labels.lang[track.language] : null;
items = items.filter(function (el) {
return el.key !== track.language;
});
items.push({
key: track.language,
label: label || track.label
});
};
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
_loop();
}
} catch (err) {
_iterator6.e(err);
} finally {
_iterator6.f();
}
return items;
}
}, {
key: "_setDefaultTrack",
value: function _setDefaultTrack(track) {
var _a, _b;
track.mode = 'showing';
__classPrivateFieldSet(this, _Captions_default, track.language, "f");
__classPrivateFieldGet(this, _Captions_button, "f").setAttribute('data-active-captions', __classPrivateFieldGet(this, _Captions_default, "f"));
__classPrivateFieldGet(this, _Captions_button, "f").classList.add('op-controls__captions--on');
__classPrivateFieldGet(this, _Captions_captions, "f").classList.add('op-captions--on');
__classPrivateFieldSet(this, _Captions_currentTrack, track, "f");
var options = document.querySelectorAll('.op-settings__submenu-item') || [];
for (var _i3 = 0, _Array$from3 = Array.from(options); _i3 < _Array$from3.length; _i3++) {
var option = _Array$from3[_i3];
option.setAttribute('aria-checked', 'false');
}
(_b = (_a = document.querySelector(".op-subtitles__option[data-value=\"captions-".concat(track.language, "\"]"))) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.setAttribute('aria-checked', 'true');
}
}, {
key: "_showCaptions",
value: function _showCaptions() {
var _a;
for (var _i4 = 0, _Array$from4 = Array.from(((_a = __classPrivateFieldGet(this, _Captions_currentTrack, "f")) === null || _a === void 0 ? void 0 : _a.activeCues) || []); _i4 < _Array$from4.length; _i4++) {
var cue = _Array$from4[_i4];
var content = (cue === null || cue === void 0 ? void 0 : cue.text) || '';
if (content && __classPrivateFieldGet(this, _Captions_captions, "f")) {
var caption = document.createElement('span');
caption.innerHTML = content;
__classPrivateFieldGet(this, _Captions_captions, "f").prepend(caption);
__classPrivateFieldGet(this, _Captions_captions, "f").classList.add('op-captions--on');
} else {
this._hideCaptions();
}
}
}
}, {
key: "_hideCaptions",
value: function _hideCaptions() {
var _a;
while ((_a = __classPrivateFieldGet(this, _Captions_captions, "f")) === null || _a === void 0 ? void 0 : _a.lastChild) {
__classPrivateFieldGet(this, _Captions_captions, "f").removeChild(__classPrivateFieldGet(this, _Captions_captions, "f").lastChild);
}
}
}]);
}();
_Captions_player = new WeakMap(), _Captions_button = new WeakMap(), _Captions_captions = new WeakMap(), _Captions_menu = new WeakMap(), _Captions_events = new WeakMap(), _Captions_mediaTrackList = new WeakMap(), _Captions_hasTracks = new WeakMap(), _Captions_currentTrack = new WeakMap(), _Captions_default = new WeakMap(), _Captions_controlPosition = new WeakMap(), _Captions_controlLayer = new WeakMap();
/* harmony default export */ var captions = (Captions);
;// ./src/js/controls/fullscreen.ts
var fullscreen_classPrivateFieldSet = undefined && undefined.__classPrivateFieldSet || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return kind === "a" ? f.