xgplayer 3.1.0-alpha.0 → 3.1.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/dist/index.min.css +1 -1
  3. package/dist/index.min.js +1 -1
  4. package/dist/index.min.js.map +1 -1
  5. package/es/constant.d.ts +0 -4
  6. package/es/constant.js +4 -1
  7. package/es/defaultConfig.js +2 -0
  8. package/es/error.js +2 -2
  9. package/es/index.d.ts +2 -1
  10. package/es/index.js +4 -3
  11. package/es/index.umd.d.ts +60 -1
  12. package/es/index.umd.js +29 -1
  13. package/es/lang/i18n.js +4 -4
  14. package/es/mediaProxy.d.ts +8 -0
  15. package/es/mediaProxy.js +13 -8
  16. package/es/player.d.ts +119 -14
  17. package/es/player.js +669 -163
  18. package/es/plugin/basePlugin.d.ts +6 -3
  19. package/es/plugin/basePlugin.js +6 -5
  20. package/es/plugin/index.d.ts +2 -1
  21. package/es/plugin/plugin.d.ts +0 -1
  22. package/es/plugin/plugin.js +11 -11
  23. package/es/plugin/pluginsManager.d.ts +14 -0
  24. package/es/plugin/pluginsManager.js +32 -16
  25. package/es/plugin/resizeObserver.js +1 -1
  26. package/es/plugins/common/iconPlugin.js +1 -0
  27. package/es/plugins/common/optionList.js +10 -10
  28. package/es/plugins/common/optionsIcon.js +13 -9
  29. package/es/plugins/common/thumbnail.d.ts +0 -1
  30. package/es/plugins/common/thumbnail.js +3 -24
  31. package/es/plugins/controls/index.css +132 -0
  32. package/es/plugins/controls/index.js +189 -0
  33. package/es/plugins/cssFullScreen/index.js +2 -1
  34. package/es/plugins/danmu/danmuIcon.js +1 -0
  35. package/es/plugins/danmu/danmuPanel.js +2 -2
  36. package/es/plugins/danmu/index.js +4 -4
  37. package/es/plugins/definition/index.js +2 -2
  38. package/es/plugins/download/index.js +3 -3
  39. package/es/plugins/dynamicBg/index.js +5 -5
  40. package/es/plugins/enter/index.js +2 -2
  41. package/es/plugins/error/index.js +2 -1
  42. package/es/plugins/fpsDetect/index.js +2 -1
  43. package/es/plugins/fullscreen/backicon.js +3 -3
  44. package/es/plugins/fullscreen/index.js +2 -2
  45. package/es/plugins/gapJump/index.js +2 -1
  46. package/es/plugins/heatmap/index.css +25 -0
  47. package/es/plugins/heatmap/index.d.ts +70 -0
  48. package/es/plugins/heatmap/index.js +306 -0
  49. package/es/plugins/heatmap/index.scss +28 -0
  50. package/es/plugins/keyboard/index.js +3 -3
  51. package/es/plugins/logger/index.js +11 -11
  52. package/es/plugins/miniScreen/index.js +6 -6
  53. package/es/plugins/miniScreen/miniScreenIcon.js +1 -0
  54. package/es/plugins/mobile/index.js +14 -14
  55. package/es/plugins/pc/index.js +3 -3
  56. package/es/plugins/pip/index.d.ts +11 -1
  57. package/es/plugins/pip/index.js +112 -13
  58. package/es/plugins/play/index.js +2 -1
  59. package/es/plugins/playNext/index.js +2 -1
  60. package/es/plugins/playbackRate/index.js +2 -1
  61. package/es/plugins/poster/index.css +4 -0
  62. package/es/plugins/poster/index.js +12 -10
  63. package/es/plugins/poster/index.scss +4 -0
  64. package/es/plugins/progress/index.js +35 -33
  65. package/es/plugins/progress/innerList.js +11 -9
  66. package/es/plugins/progress/miniProgress.js +1 -0
  67. package/es/plugins/progressPreview/dotsApi.js +5 -5
  68. package/es/plugins/progressPreview/index.d.ts +2 -2
  69. package/es/plugins/progressPreview/index.js +29 -29
  70. package/es/plugins/prompt/index.js +5 -5
  71. package/es/plugins/replay/index.js +3 -3
  72. package/es/plugins/rotate/index.js +2 -2
  73. package/es/plugins/screenShot/index.d.ts +1 -0
  74. package/es/plugins/screenShot/index.js +8 -3
  75. package/es/plugins/start/index.js +13 -13
  76. package/es/plugins/stats/index.js +1 -1
  77. package/es/plugins/testspeed/index.js +2 -2
  78. package/es/plugins/time/index.js +34 -31
  79. package/es/plugins/time/timesegments.js +7 -7
  80. package/es/plugins/track/index.js +6 -6
  81. package/es/plugins/volume/index.js +15 -15
  82. package/es/plugins/waitingTimeoutJump/index.js +2 -1
  83. package/es/presets/default-en.d.ts +2 -1
  84. package/es/presets/default-en.js +6 -4
  85. package/es/presets/default.d.ts +3 -2
  86. package/es/presets/default.js +6 -4
  87. package/es/stateClassMap.d.ts +1 -0
  88. package/es/stateClassMap.js +1 -0
  89. package/es/utils/database.js +107 -0
  90. package/es/utils/util.d.ts +300 -282
  91. package/es/utils/util.js +352 -145
  92. package/es/utils/xgplayerTimeRange.d.ts +7 -0
  93. package/es/utils/xgplayerTimeRange.js +25 -0
  94. package/es/version.js +1 -1
  95. package/package.json +3 -10
  96. package/es/simple.umd.d.ts +0 -2
  97. package/es/utils/throttle.d.ts +0 -12
  98. package/es/utils/throttle.js +0 -132
package/es/utils/util.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { typeof as _typeof, toConsumableArray as _toConsumableArray } from "../_virtual/_rollupPluginBabelHelpers.js";
2
2
  import XG_DEBUG from "./debug.js";
3
- function createDom() {
3
+ import XgplayerTimeRange from "./xgplayerTimeRange.js";
4
+ var util = {};
5
+ util.createDom = function() {
4
6
  var el = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "div";
5
7
  var tpl = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
6
8
  var attrs = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
@@ -20,8 +22,8 @@ function createDom() {
20
22
  }
21
23
  });
22
24
  return dom;
23
- }
24
- function createDomFromHtml(html) {
25
+ };
26
+ util.createDomFromHtml = function(html) {
25
27
  var attrs = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
26
28
  var classname = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "";
27
29
  try {
@@ -31,7 +33,7 @@ function createDomFromHtml(html) {
31
33
  doc = null;
32
34
  if (dom.length > 0) {
33
35
  dom = dom[0];
34
- classname && addClass(dom, classname);
36
+ classname && util.addClass(dom, classname);
35
37
  if (attrs) {
36
38
  Object.keys(attrs).forEach(function(key) {
37
39
  dom.setAttribute(key, attrs[key]);
@@ -41,11 +43,11 @@ function createDomFromHtml(html) {
41
43
  }
42
44
  return null;
43
45
  } catch (err) {
44
- XG_DEBUG.logError("createDomFromHtml", err);
46
+ XG_DEBUG.logError("util.createDomFromHtml", err);
45
47
  return null;
46
48
  }
47
- }
48
- function hasClass(el, className) {
49
+ };
50
+ util.hasClass = function(el, className) {
49
51
  if (!el || !className) {
50
52
  return false;
51
53
  }
@@ -57,8 +59,8 @@ function hasClass(el, className) {
57
59
  var orgClassName = el.className && _typeof(el.className) === "object" ? el.getAttribute("class") : el.className;
58
60
  return orgClassName && !!orgClassName.match(new RegExp("(\\s|^)" + className + "(\\s|$)"));
59
61
  }
60
- }
61
- function addClass(el, className) {
62
+ };
63
+ util.addClass = function(el, className) {
62
64
  if (!el || !className) {
63
65
  return;
64
66
  }
@@ -67,7 +69,7 @@ function addClass(el, className) {
67
69
  item && el.classList.add(item);
68
70
  });
69
71
  } catch (e) {
70
- if (!hasClass(el, className)) {
72
+ if (!util.hasClass(el, className)) {
71
73
  if (el.className && _typeof(el.className) === "object") {
72
74
  el.setAttribute("class", el.getAttribute("class") + " " + className);
73
75
  } else {
@@ -75,8 +77,8 @@ function addClass(el, className) {
75
77
  }
76
78
  }
77
79
  }
78
- }
79
- function removeClass(el, className) {
80
+ };
81
+ util.removeClass = function(el, className) {
80
82
  if (!el || !className) {
81
83
  return;
82
84
  }
@@ -85,7 +87,7 @@ function removeClass(el, className) {
85
87
  item && el.classList.remove(item);
86
88
  });
87
89
  } catch (e) {
88
- if (hasClass(el, className)) {
90
+ if (util.hasClass(el, className)) {
89
91
  className.split(/\s+/g).forEach(function(item) {
90
92
  var reg = new RegExp("(\\s|^)" + item + "(\\s|$)");
91
93
  if (el.className && _typeof(el.className) === "object") {
@@ -96,26 +98,26 @@ function removeClass(el, className) {
96
98
  });
97
99
  }
98
100
  }
99
- }
100
- function toggleClass(el, className) {
101
+ };
102
+ util.toggleClass = function(el, className) {
101
103
  if (!el) {
102
104
  return;
103
105
  }
104
106
  className.split(/\s+/g).forEach(function(item) {
105
- if (hasClass(el, item)) {
106
- removeClass(el, item);
107
+ if (util.hasClass(el, item)) {
108
+ util.removeClass(el, item);
107
109
  } else {
108
- addClass(el, item);
110
+ util.addClass(el, item);
109
111
  }
110
112
  });
111
- }
112
- function classNames() {
113
+ };
114
+ util.classNames = function() {
113
115
  var _arguments = arguments;
114
116
  var classname = [];
115
117
  var _loop = function _loop2(i2) {
116
- if (typeOf(_arguments[i2]) === "String") {
118
+ if (util.typeOf(_arguments[i2]) === "String") {
117
119
  classname.push(_arguments[i2]);
118
- } else if (typeOf(_arguments[i2]) === "Object") {
120
+ } else if (util.typeOf(_arguments[i2]) === "Object") {
119
121
  Object.keys(_arguments[i2]).map(function(key) {
120
122
  if (_arguments[i2][key]) {
121
123
  classname.push(key);
@@ -127,25 +129,25 @@ function classNames() {
127
129
  _loop(i);
128
130
  }
129
131
  return classname.join(" ");
130
- }
131
- function findDom() {
132
+ };
133
+ util.findDom = function() {
132
134
  var el = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : document;
133
135
  var sel = arguments.length > 1 ? arguments[1] : void 0;
134
136
  var dom;
135
137
  try {
136
138
  dom = el.querySelector(sel);
137
139
  } catch (e) {
138
- XG_DEBUG.logError("export function findDom", e);
140
+ XG_DEBUG.logError("util.findDom", e);
139
141
  if (sel.indexOf("#") === 0) {
140
142
  dom = el.getElementById(sel.slice(1));
141
143
  }
142
144
  }
143
145
  return dom;
144
- }
145
- function getCss(dom, key) {
146
+ };
147
+ util.getCss = function(dom, key) {
146
148
  return dom.currentStyle ? dom.currentStyle[key] : document.defaultView.getComputedStyle(dom, false)[key];
147
- }
148
- function padStart(str, length, pad) {
149
+ };
150
+ util.padStart = function(str, length, pad) {
149
151
  var charstr = String(pad);
150
152
  var len = length >> 0;
151
153
  var maxlen = Math.ceil(len / charstr.length);
@@ -155,18 +157,18 @@ function padStart(str, length, pad) {
155
157
  chars.push(charstr);
156
158
  }
157
159
  return chars.join("").substring(0, len - r.length) + r;
158
- }
159
- function format(time) {
160
+ };
161
+ util.format = function(time) {
160
162
  if (window.isNaN(time)) {
161
163
  return "";
162
164
  }
163
165
  time = Math.round(time);
164
- var hour = padStart(Math.floor(time / 3600), 2, 0);
165
- var minute = padStart(Math.floor((time - hour * 3600) / 60), 2, 0);
166
- var second = padStart(Math.floor(time - hour * 3600 - minute * 60), 2, 0);
166
+ var hour = util.padStart(Math.floor(time / 3600), 2, 0);
167
+ var minute = util.padStart(Math.floor((time - hour * 3600) / 60), 2, 0);
168
+ var second = util.padStart(Math.floor(time - hour * 3600 - minute * 60), 2, 0);
167
169
  return (hour === "00" ? [minute, second] : [hour, minute, second]).join(":");
168
- }
169
- function event(e) {
170
+ };
171
+ util.event = function(e) {
170
172
  if (e.touches) {
171
173
  var touch = e.touches[0] || e.changedTouches[0];
172
174
  e.clientX = touch.clientX || 0;
@@ -175,44 +177,44 @@ function event(e) {
175
177
  e.offsetY = touch.pageY - touch.target.offsetTop;
176
178
  }
177
179
  e._target = e.target || e.srcElement;
178
- }
179
- function typeOf(obj) {
180
+ };
181
+ util.typeOf = function(obj) {
180
182
  return Object.prototype.toString.call(obj).match(/([^\s.*]+)(?=]$)/g)[0];
181
- }
182
- function deepCopy(dst, src) {
183
- if (typeOf(src) === "Object" && typeOf(dst) === "Object") {
183
+ };
184
+ util.deepCopy = function(dst, src) {
185
+ if (util.typeOf(src) === "Object" && util.typeOf(dst) === "Object") {
184
186
  Object.keys(src).forEach(function(key) {
185
- if (typeOf(src[key]) === "Object" && !(src[key] instanceof Node)) {
187
+ if (util.typeOf(src[key]) === "Object" && !(src[key] instanceof Node)) {
186
188
  if (dst[key] === void 0 || dst[key] === void 0) {
187
189
  dst[key] = src[key];
188
190
  } else {
189
- deepCopy(dst[key], src[key]);
191
+ util.deepCopy(dst[key], src[key]);
190
192
  }
191
- } else if (typeOf(src[key]) === "Array") {
192
- dst[key] = typeOf(dst[key]) === "Array" ? dst[key].concat(src[key]) : src[key];
193
+ } else if (util.typeOf(src[key]) === "Array") {
194
+ dst[key] = util.typeOf(dst[key]) === "Array" ? dst[key].concat(src[key]) : src[key];
193
195
  } else {
194
196
  dst[key] = src[key];
195
197
  }
196
198
  });
197
199
  return dst;
198
200
  }
199
- }
200
- function deepMerge(dst, src) {
201
+ };
202
+ util.deepMerge = function(dst, src) {
201
203
  Object.keys(src).map(function(key) {
202
- if (typeOf(src[key]) === "Array" && typeOf(dst[key]) === "Array") {
203
- if (typeOf(dst[key]) === "Array") {
204
+ if (util.typeOf(src[key]) === "Array" && util.typeOf(dst[key]) === "Array") {
205
+ if (util.typeOf(dst[key]) === "Array") {
204
206
  var _dst$key;
205
207
  (_dst$key = dst[key]).push.apply(_dst$key, _toConsumableArray(src[key]));
206
208
  }
207
- } else if (typeOf(dst[key]) === typeOf(src[key]) && dst[key] !== null && typeOf(dst[key]) === "Object" && !(src[key] instanceof window.Node)) {
208
- deepMerge(dst[key], src[key]);
209
+ } else if (util.typeOf(dst[key]) === util.typeOf(src[key]) && dst[key] !== null && util.typeOf(dst[key]) === "Object" && !(src[key] instanceof window.Node)) {
210
+ util.deepMerge(dst[key], src[key]);
209
211
  } else {
210
212
  src[key] !== null && (dst[key] = src[key]);
211
213
  }
212
214
  });
213
215
  return dst;
214
- }
215
- function getBgImage(el) {
216
+ };
217
+ util.getBgImage = function(el) {
216
218
  var url = (el.currentStyle || window.getComputedStyle(el, null)).backgroundImage;
217
219
  if (!url || url === "none") {
218
220
  return "";
@@ -220,8 +222,8 @@ function getBgImage(el) {
220
222
  var a = document.createElement("a");
221
223
  a.href = url.replace(/url\("|"\)/g, "");
222
224
  return a.href;
223
- }
224
- function copyDom(dom) {
225
+ };
226
+ util.copyDom = function(dom) {
225
227
  if (dom && dom.nodeType === 1) {
226
228
  var back = document.createElement(dom.tagName);
227
229
  Array.prototype.forEach.call(dom.attributes, function(node) {
@@ -234,52 +236,52 @@ function copyDom(dom) {
234
236
  } else {
235
237
  return "";
236
238
  }
237
- }
238
- function setInterval(context, eventName, intervalFunc, frequency) {
239
+ };
240
+ util.setInterval = function(context, eventName, intervalFunc, frequency) {
239
241
  if (!context._interval[eventName]) {
240
242
  context._interval[eventName] = window.setInterval(intervalFunc.bind(context), frequency);
241
243
  }
242
- }
243
- function clearInterval(context, eventName) {
244
+ };
245
+ util.clearInterval = function(context, eventName) {
244
246
  clearInterval(context._interval[eventName]);
245
247
  context._interval[eventName] = null;
246
- }
247
- function setTimeout(context, fun, time) {
248
+ };
249
+ util.setTimeout = function(context, fun, time) {
248
250
  if (!context._timers) {
249
251
  context._timers = [];
250
252
  }
251
- var id = window.setTimeout(function() {
253
+ var id = setTimeout(function() {
252
254
  fun();
253
- clearTimeout(context, id);
255
+ util.clearTimeout(context, id);
254
256
  }, time);
255
257
  context._timers.push(id);
256
258
  return id;
257
- }
258
- function clearTimeout(context, id) {
259
+ };
260
+ util.clearTimeout = function(context, id) {
259
261
  var _timers = context._timers;
260
- if (typeOf(_timers) === "Array") {
262
+ if (util.typeOf(_timers) === "Array") {
261
263
  for (var i = 0; i < _timers.length; i++) {
262
264
  if (_timers[i] === id) {
263
265
  _timers.splice(i, 1);
264
- window.clearTimeout(id);
266
+ clearTimeout(id);
265
267
  break;
266
268
  }
267
269
  }
268
270
  } else {
269
- window.clearTimeout(id);
271
+ clearTimeout(id);
270
272
  }
271
- }
272
- function clearAllTimers(context) {
273
+ };
274
+ util.clearAllTimers = function(context) {
273
275
  var _timers = context._timers;
274
- if (typeOf(_timers) === "Array") {
276
+ if (util.typeOf(_timers) === "Array") {
275
277
  _timers.map(function(item) {
276
278
  clearTimeout(item);
277
279
  });
278
280
  context._timerIds = [];
279
281
  }
280
- }
281
- function createImgBtn(name, imgUrl, width, height) {
282
- var btn = createDom("xg-".concat(name), "", {}, "xgplayer-".concat(name, "-img"));
282
+ };
283
+ util.createImgBtn = function(name, imgUrl, width, height) {
284
+ var btn = util.createDom("xg-".concat(name), "", {}, "xgplayer-".concat(name, "-img"));
283
285
  btn.style.backgroundImage = 'url("'.concat(imgUrl, '")');
284
286
  if (width && height) {
285
287
  var w, h, unit;
@@ -303,8 +305,8 @@ function createImgBtn(name, imgUrl, width, height) {
303
305
  }
304
306
  }
305
307
  return btn;
306
- }
307
- function Hex2RGBA(hex, alpha) {
308
+ };
309
+ util.Hex2RGBA = function(hex, alpha) {
308
310
  var rgb = [];
309
311
  if (/^\#[0-9A-F]{3}$/i.test(hex)) {
310
312
  var sixHex = "#";
@@ -321,35 +323,35 @@ function Hex2RGBA(hex, alpha) {
321
323
  } else {
322
324
  return "rgba(255, 255, 255, 0.1)";
323
325
  }
324
- }
325
- function getFullScreenEl() {
326
+ };
327
+ util.getFullScreenEl = function() {
326
328
  return document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement;
327
- }
328
- function checkIsFunction(fun) {
329
+ };
330
+ util.checkIsFunction = function(fun) {
329
331
  return fun && typeof fun === "function";
330
- }
331
- function checkIsObject(obj) {
332
+ };
333
+ util.checkIsObject = function(obj) {
332
334
  return obj !== null && _typeof(obj) === "object";
333
- }
334
- function hide(dom) {
335
+ };
336
+ util.hide = function(dom) {
335
337
  dom.style.display = "none";
336
- }
337
- function show(dom, display) {
338
+ };
339
+ util.show = function(dom, display) {
338
340
  dom.style.display = display || "block";
339
- }
340
- function isUndefined(val) {
341
+ };
342
+ util.isUndefined = function(val) {
341
343
  if (typeof val === "undefined" || val === null) {
342
344
  return true;
343
345
  }
344
- }
345
- function isNotNull(val) {
346
+ };
347
+ util.isNotNull = function(val) {
346
348
  return !(val === void 0 || val === null);
347
- }
348
- function setStyleFromCsstext(dom, text) {
349
+ };
350
+ util.setStyleFromCsstext = function(dom, text) {
349
351
  if (!text) {
350
352
  return;
351
353
  }
352
- if (typeOf(text) === "String") {
354
+ if (util.typeOf(text) === "String") {
353
355
  var styleArr = text.replace(/\s+/g, "").split(";");
354
356
  styleArr.map(function(item) {
355
357
  if (item) {
@@ -364,7 +366,7 @@ function setStyleFromCsstext(dom, text) {
364
366
  dom.style[key] = text[key];
365
367
  });
366
368
  }
367
- }
369
+ };
368
370
  function checkIsIn(key, list) {
369
371
  for (var i = 0, len = list.length; i < len; i++) {
370
372
  if (key.indexOf(list[i]) > -1) {
@@ -373,7 +375,7 @@ function checkIsIn(key, list) {
373
375
  }
374
376
  return false;
375
377
  }
376
- function filterStyleFromText(dom) {
378
+ util.filterStyleFromText = function(dom) {
377
379
  var list = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : ["width", "height", "top", "left", "bottom", "right", "position", "z-index", "padding", "margin", "transform"];
378
380
  var _cssText = dom.style.cssText;
379
381
  if (!_cssText) {
@@ -399,8 +401,8 @@ function filterStyleFromText(dom) {
399
401
  dom.style[key] = remain[key];
400
402
  });
401
403
  return ret;
402
- }
403
- function getStyleFromCsstext(dom) {
404
+ };
405
+ util.getStyleFromCsstext = function(dom) {
404
406
  var _cssText = dom.style.cssText;
405
407
  if (!_cssText) {
406
408
  return {};
@@ -416,22 +418,80 @@ function getStyleFromCsstext(dom) {
416
418
  }
417
419
  });
418
420
  return ret;
419
- }
420
- function stopPropagation(e) {
421
+ };
422
+ util.preloadImg = function(url) {
423
+ var onload = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : function() {
424
+ };
425
+ var onerror = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : function() {
426
+ };
427
+ if (!url) {
428
+ return;
429
+ }
430
+ var img = new window.Image();
431
+ img.onload = function(e) {
432
+ img = null;
433
+ onload && onload(e);
434
+ };
435
+ img.onerror = function(e) {
436
+ img = null;
437
+ onerror && onerror(e);
438
+ };
439
+ img.src = url;
440
+ };
441
+ util.stopPropagation = function(e) {
421
442
  if (e) {
422
443
  e.stopPropagation();
423
444
  }
424
- }
425
- function scrollTop() {
445
+ };
446
+ util.scrollTop = function() {
426
447
  return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
427
- }
428
- function scrollLeft() {
448
+ };
449
+ util.scrollLeft = function() {
429
450
  return window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0;
430
- }
431
- function checkTouchSupport() {
451
+ };
452
+ util.checkTouchSupport = function() {
432
453
  return "ontouchstart" in window;
433
- }
434
- function getEventPos(e) {
454
+ };
455
+ util.getBuffered2 = function(vbuffered) {
456
+ var maxHoleDuration = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0.5;
457
+ var buffered = [];
458
+ for (var i = 0; i < vbuffered.length; i++) {
459
+ buffered.push({
460
+ start: vbuffered.start(i) < 0.5 ? 0 : vbuffered.start(i),
461
+ end: vbuffered.end(i)
462
+ });
463
+ }
464
+ buffered.sort(function(a, b) {
465
+ var diff = a.start - b.start;
466
+ if (diff) {
467
+ return diff;
468
+ } else {
469
+ return b.end - a.end;
470
+ }
471
+ });
472
+ var buffered2 = [];
473
+ if (maxHoleDuration) {
474
+ for (var _i = 0; _i < buffered.length; _i++) {
475
+ var buf2len = buffered2.length;
476
+ if (buf2len) {
477
+ var buf2end = buffered2[buf2len - 1].end;
478
+ if (buffered[_i].start - buf2end < maxHoleDuration) {
479
+ if (buffered[_i].end > buf2end) {
480
+ buffered2[buf2len - 1].end = buffered[_i].end;
481
+ }
482
+ } else {
483
+ buffered2.push(buffered[_i]);
484
+ }
485
+ } else {
486
+ buffered2.push(buffered[_i]);
487
+ }
488
+ }
489
+ } else {
490
+ buffered2 = buffered;
491
+ }
492
+ return new XgplayerTimeRange(buffered2);
493
+ };
494
+ util.getEventPos = function(e) {
435
495
  var zoom = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
436
496
  if (e.touches && e.touches.length > 0) {
437
497
  e = e.touches[0];
@@ -446,15 +506,15 @@ function getEventPos(e) {
446
506
  pageX: e.pageX / zoom,
447
507
  pageY: e.pageY / zoom
448
508
  };
449
- }
450
- function requestAnimationFrame(callback) {
509
+ };
510
+ util.requestAnimationFrame = function(callback) {
451
511
  var _fun = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame;
452
512
  if (_fun) {
453
513
  return _fun(callback);
454
514
  }
455
- }
456
- function getHostFromUrl(url) {
457
- if (typeOf(url) !== "String") {
515
+ };
516
+ util.getHostFromUrl = function(url) {
517
+ if (util.typeOf(url) !== "String") {
458
518
  return "";
459
519
  }
460
520
  var results = url.split("/");
@@ -463,21 +523,21 @@ function getHostFromUrl(url) {
463
523
  domain = results[2];
464
524
  }
465
525
  return domain;
466
- }
467
- function cancelAnimationFrame(frameId) {
526
+ };
527
+ util.cancelAnimationFrame = function(frameId) {
468
528
  var _fun = window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.cancelRequestAnimationFrame;
469
529
  _fun && _fun(frameId);
470
- }
471
- function isMSE(video) {
530
+ };
531
+ util.isMSE = function(video) {
472
532
  if (!video || !(video instanceof HTMLMediaElement)) {
473
533
  return false;
474
534
  }
475
535
  return /^blob/.test(video.currentSrc) || /^blob/.test(video.src);
476
- }
477
- function isBlob(url) {
536
+ };
537
+ util.isBlob = function(url) {
478
538
  return typeof url === "string" && /^blob/.test(url);
479
- }
480
- function generateSessionId() {
539
+ };
540
+ util.generateSessionId = function() {
481
541
  var did = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
482
542
  var d = new Date().getTime();
483
543
  try {
@@ -495,18 +555,18 @@ function generateSessionId() {
495
555
  return (c === "x" ? r : r & 3 | 8).toString(16);
496
556
  });
497
557
  return uuid;
498
- }
499
- function createEvent(eventName) {
500
- var event2;
558
+ };
559
+ util.createEvent = function(eventName) {
560
+ var event;
501
561
  if (typeof window.Event === "function") {
502
- event2 = new Event(eventName);
562
+ event = new Event(eventName);
503
563
  } else {
504
- event2 = document.createEvent("Event");
505
- event2.initEvent(eventName, true, true);
564
+ event = document.createEvent("Event");
565
+ event.initEvent(eventName, true, true);
506
566
  }
507
- return event2;
508
- }
509
- function adjustTimeByDuration(time, duration, isEnded) {
567
+ return event;
568
+ };
569
+ util.adjustTimeByDuration = function(time, duration, isEnded) {
510
570
  if (!duration || !time) {
511
571
  return time;
512
572
  }
@@ -514,30 +574,47 @@ function adjustTimeByDuration(time, duration, isEnded) {
514
574
  return duration;
515
575
  }
516
576
  return time;
517
- }
518
- function createPositionBar(className, root) {
519
- var dom = createDom("xg-bar", "", {
577
+ };
578
+ util.createPositionBar = function(className, root) {
579
+ var dom = util.createDom("xg-bar", "", {
520
580
  "data-index": -1
521
581
  }, className);
522
582
  root.appendChild(dom);
523
583
  return dom;
524
- }
525
- function getTransformStyle() {
584
+ };
585
+ util.getTransformStyle = function() {
526
586
  var pos = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
527
587
  x: 0,
528
588
  y: 0,
529
589
  scale: 1,
530
590
  rotate: 0
531
591
  };
532
- return "scale(".concat(pos.scale || 1, ") translate(").concat(pos.x || 0, "%, ").concat(pos.y || 0, "%) rotate(").concat(pos.rotate || 0, "deg)");
533
- }
534
- function convertDeg(val) {
592
+ var transformValue = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
593
+ var styles = {
594
+ scale: "".concat(pos.scale || 1),
595
+ translate: "".concat(pos.x || 0, "%, ").concat(pos.y || 0, "%"),
596
+ rotate: "".concat(pos.rotate || 0, "deg")
597
+ };
598
+ var stylesKeys = Object.keys(styles);
599
+ stylesKeys.forEach(function(key) {
600
+ var reg = new RegExp("".concat(key, "\\([^\\(]+\\)"), "g");
601
+ var fn = "".concat(key, "(").concat(styles[key], ")");
602
+ if (reg.test(transformValue)) {
603
+ reg.lastIndex = -1;
604
+ transformValue = transformValue.replace(reg, fn);
605
+ } else {
606
+ transformValue += "".concat(fn, " ");
607
+ }
608
+ });
609
+ return transformValue;
610
+ };
611
+ util.convertDeg = function(val) {
535
612
  if (Math.abs(val) <= 1) {
536
613
  return val * 360;
537
614
  }
538
615
  return val % 360;
539
- }
540
- function getIndexByTime(time, segments) {
616
+ };
617
+ util.getIndexByTime = function(time, segments) {
541
618
  var _len = segments.length;
542
619
  var _index = -1;
543
620
  if (_len < 1) {
@@ -556,14 +633,14 @@ function getIndexByTime(time, segments) {
556
633
  }
557
634
  }
558
635
  return _index;
559
- }
560
- function getOffsetCurrentTime(currentTime, segments) {
636
+ };
637
+ util.getOffsetCurrentTime = function(currentTime, segments) {
561
638
  var index = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : -1;
562
639
  var _index = -1;
563
640
  if (index >= 0 && index < segments.length) {
564
641
  _index = index;
565
642
  } else {
566
- _index = getIndexByTime(currentTime, segments);
643
+ _index = util.getIndexByTime(currentTime, segments);
567
644
  }
568
645
  if (_index < 0) {
569
646
  return -1;
@@ -578,8 +655,8 @@ function getOffsetCurrentTime(currentTime, segments) {
578
655
  return end;
579
656
  }
580
657
  return -1;
581
- }
582
- function getCurrentTimeByOffset(offsetTime, segments) {
658
+ };
659
+ util.getCurrentTimeByOffset = function(offsetTime, segments) {
583
660
  var _index = -1;
584
661
  if (!segments || segments.length < 0) {
585
662
  return offsetTime;
@@ -599,6 +676,136 @@ function getCurrentTimeByOffset(offsetTime, segments) {
599
676
  }
600
677
  }
601
678
  return offsetTime;
679
+ };
680
+ function isObject(value) {
681
+ var type = _typeof(value);
682
+ return value !== null && (type === "object" || type === "function");
683
+ }
684
+ function debounce(func, wait, options) {
685
+ var lastArgs, lastThis, maxWait, result, timerId, lastCallTime;
686
+ var lastInvokeTime = 0;
687
+ var leading = false;
688
+ var maxing = false;
689
+ var trailing = true;
690
+ var useRAF = !wait && wait !== 0 && typeof window.requestAnimationFrame === "function";
691
+ if (typeof func !== "function") {
692
+ throw new TypeError("Expected a function");
693
+ }
694
+ wait = +wait || 0;
695
+ if (isObject(options)) {
696
+ leading = !!options.leading;
697
+ maxing = "maxWait" in options;
698
+ maxWait = maxing ? Math.max(+options.maxWait || 0, wait) : maxWait;
699
+ trailing = "trailing" in options ? !!options.trailing : trailing;
700
+ }
701
+ function invokeFunc(time) {
702
+ var args = lastArgs;
703
+ var thisArg = lastThis;
704
+ lastArgs = lastThis = void 0;
705
+ lastInvokeTime = time;
706
+ result = func.apply(thisArg, args);
707
+ return result;
708
+ }
709
+ function startTimer(pendingFunc, wait2) {
710
+ if (useRAF) {
711
+ window.cancelAnimationFrame(timerId);
712
+ return window.requestAnimationFrame(pendingFunc);
713
+ }
714
+ return setTimeout(pendingFunc, wait2);
715
+ }
716
+ function cancelTimer(id) {
717
+ if (useRAF) {
718
+ return window.cancelAnimationFrame(id);
719
+ }
720
+ clearTimeout(id);
721
+ }
722
+ function leadingEdge(time) {
723
+ lastInvokeTime = time;
724
+ timerId = startTimer(timerExpired, wait);
725
+ return leading ? invokeFunc(time) : result;
726
+ }
727
+ function remainingWait(time) {
728
+ var timeSinceLastCall = time - lastCallTime;
729
+ var timeSinceLastInvoke = time - lastInvokeTime;
730
+ var timeWaiting = wait - timeSinceLastCall;
731
+ return maxing ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
732
+ }
733
+ function shouldInvoke(time) {
734
+ var timeSinceLastCall = time - lastCallTime;
735
+ var timeSinceLastInvoke = time - lastInvokeTime;
736
+ return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
737
+ }
738
+ function timerExpired() {
739
+ var time = Date.now();
740
+ if (shouldInvoke(time)) {
741
+ return trailingEdge(time);
742
+ }
743
+ timerId = startTimer(timerExpired, remainingWait(time));
744
+ }
745
+ function trailingEdge(time) {
746
+ timerId = void 0;
747
+ if (trailing && lastArgs) {
748
+ return invokeFunc(time);
749
+ }
750
+ lastArgs = lastThis = void 0;
751
+ return result;
752
+ }
753
+ function cancel() {
754
+ if (timerId !== void 0) {
755
+ cancelTimer(timerId);
756
+ }
757
+ lastInvokeTime = 0;
758
+ lastArgs = lastCallTime = lastThis = timerId = void 0;
759
+ }
760
+ function flush() {
761
+ return timerId === void 0 ? result : trailingEdge(Date.now());
762
+ }
763
+ function pending() {
764
+ return timerId !== void 0;
765
+ }
766
+ function debounced() {
767
+ var time = Date.now();
768
+ var isInvoking = shouldInvoke(time);
769
+ for (var _len2 = arguments.length, args = new Array(_len2), _key = 0; _key < _len2; _key++) {
770
+ args[_key] = arguments[_key];
771
+ }
772
+ lastArgs = args;
773
+ lastThis = this;
774
+ lastCallTime = time;
775
+ if (isInvoking) {
776
+ if (timerId === void 0) {
777
+ return leadingEdge(lastCallTime);
778
+ }
779
+ if (maxing) {
780
+ timerId = startTimer(timerExpired, wait);
781
+ return invokeFunc(lastCallTime);
782
+ }
783
+ }
784
+ if (timerId === void 0) {
785
+ timerId = startTimer(timerExpired, wait);
786
+ }
787
+ return result;
788
+ }
789
+ debounced.cancel = cancel;
790
+ debounced.flush = flush;
791
+ debounced.pending = pending;
792
+ return debounced;
793
+ }
794
+ function throttle(func, wait, options) {
795
+ var leading = true;
796
+ var trailing = true;
797
+ if (typeof func !== "function") {
798
+ throw new TypeError("Expected a function");
799
+ }
800
+ if (isObject(options)) {
801
+ leading = "leading" in options ? !!options.leading : leading;
802
+ trailing = "trailing" in options ? !!options.trailing : trailing;
803
+ }
804
+ return debounce(func, wait, {
805
+ leading,
806
+ trailing,
807
+ maxWait: wait
808
+ });
602
809
  }
603
810
  function getLang() {
604
811
  var lang = (document.documentElement.getAttribute("lang") || navigator.language || "zh-cn").toLocaleLowerCase();
@@ -617,4 +824,4 @@ function checkIsCurrentVideo(element, playerId, key) {
617
824
  }
618
825
  return false;
619
826
  }
620
- export { Hex2RGBA, addClass, adjustTimeByDuration, cancelAnimationFrame, checkIsCurrentVideo, checkIsFunction, checkIsObject, checkTouchSupport, classNames, clearAllTimers, clearInterval, clearTimeout, convertDeg, copyDom, createDom, createDomFromHtml, createEvent, createImgBtn, createPositionBar, deepCopy, deepMerge, event, filterStyleFromText, findDom, format, generateSessionId, getBgImage, getCss, getCurrentTimeByOffset, getEventPos, getFullScreenEl, getHostFromUrl, getIndexByTime, getLang, getOffsetCurrentTime, getStyleFromCsstext, getTransformStyle, hasClass, hide, isBlob, isMSE, isNotNull, isUndefined, padStart, removeClass, requestAnimationFrame, scrollLeft, scrollTop, setInterval, setStyleFromCsstext, setTimeout, show, stopPropagation, toggleClass, typeOf };
827
+ export { checkIsCurrentVideo, debounce, util as default, getLang, throttle };