mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-23 22:01:20 -08:00
build all packages
This commit is contained in:
1 parent
dd6a2dafda
commit
86dd34dc37
14 files changed
+391
-54
No files matched your search
@@ -73,17 +73,20 @@
|
||||
} : null;
|
||||
}) : [];
|
||||
}
|
||||
function bilibiliDanmuParseFromUrl(url) {
|
||||
return fetch(url).then(function (res) {
|
||||
return res.text();
|
||||
}).then(function (xmlString) {
|
||||
return bilibiliDanmuParseFromXml(xmlString);
|
||||
});
|
||||
}
|
||||
function bilibiliDanmuParseFromAv(av) {
|
||||
var corsUrl = 'https://cors-anywhere.herokuapp.com/';
|
||||
return fetch("".concat(corsUrl, "https://api.bilibili.com/x/web-interface/view?aid=").concat(av)).then(function (res) {
|
||||
return res.json();
|
||||
}).then(function (res) {
|
||||
if (res.code === 0 && res.data && res.data.cid) {
|
||||
return fetch("".concat(corsUrl, "https://api.bilibili.com/x/v1/dm/list.so?oid=").concat(res.data.cid)).then(function (res) {
|
||||
return res.text();
|
||||
}).then(function (xmlString) {
|
||||
return bilibiliDanmuParseFromXml(xmlString);
|
||||
});
|
||||
return bilibiliDanmuParseFromUrl("".concat(corsUrl, "https://api.bilibili.com/x/v1/dm/list.so?oid=").concat(res.data.cid));
|
||||
}
|
||||
|
||||
throw new Error("Unable to get data: ".concat(JSON.stringify(res)));
|
||||
@@ -154,14 +157,88 @@
|
||||
|
||||
var createClass = _createClass;
|
||||
|
||||
function getDanmuTopByDiff(danmus) {
|
||||
var top = 0;
|
||||
var maxDiff = 0;
|
||||
|
||||
for (var index = 1; index < danmus.length; index += 1) {
|
||||
var item = danmus[index];
|
||||
var prev = danmus[index - 1];
|
||||
var prevTop = prev.top + prev.height;
|
||||
var diff = item.top - prevTop;
|
||||
|
||||
if (diff > maxDiff) {
|
||||
top = prevTop;
|
||||
maxDiff = diff;
|
||||
}
|
||||
}
|
||||
|
||||
return top;
|
||||
}
|
||||
|
||||
function getDanmuTopBySparse(danmus) {
|
||||
var topMap = {};
|
||||
|
||||
for (var index = 0; index < danmus.length; index += 1) {
|
||||
var item = danmus[index];
|
||||
|
||||
if (topMap[item.top]) {
|
||||
topMap[item.top].push(item);
|
||||
} else {
|
||||
topMap[item.top] = [item];
|
||||
}
|
||||
}
|
||||
|
||||
var maxRight = 0;
|
||||
var top = 0;
|
||||
var topMapKeys = Object.keys(topMap);
|
||||
|
||||
for (var _index = 0; _index < topMapKeys.length; _index += 1) {
|
||||
var minRight = danmus[0].width;
|
||||
var topKey = topMapKeys[_index];
|
||||
var danmuArr = topMap[topKey];
|
||||
|
||||
for (var _index2 = 0; _index2 < danmuArr.length; _index2 += 1) {
|
||||
var danmu = danmuArr[_index2];
|
||||
|
||||
if (danmu.right < minRight) {
|
||||
minRight = danmu.right;
|
||||
}
|
||||
}
|
||||
|
||||
if (minRight > maxRight) {
|
||||
maxRight = minRight;
|
||||
|
||||
var _danmuArr = slicedToArray(danmuArr, 1);
|
||||
|
||||
top = _danmuArr[0].top;
|
||||
}
|
||||
}
|
||||
|
||||
if (top === 0) {
|
||||
var randomKey = Math.floor(Math.random() * (2 - topMapKeys.length) + topMapKeys.length - 1);
|
||||
top = topMapKeys[randomKey];
|
||||
}
|
||||
|
||||
return top;
|
||||
}
|
||||
|
||||
function getDanmuTop(danmus) {
|
||||
var top = getDanmuTopByDiff(danmus);
|
||||
|
||||
if (top === 0) {
|
||||
top = getDanmuTopBySparse(danmus);
|
||||
}
|
||||
|
||||
return top;
|
||||
}
|
||||
|
||||
var Danmuku =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function Danmuku(art) {
|
||||
function Danmuku(art, option) {
|
||||
var _this = this;
|
||||
|
||||
var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
classCallCheck(this, Danmuku);
|
||||
|
||||
this.art = art;
|
||||
@@ -169,13 +246,12 @@
|
||||
this.layer = null;
|
||||
this.isStop = false;
|
||||
this.animationFrameTimer = null;
|
||||
this.option = Object.assign({}, Danmuku.option, option);
|
||||
art.constructor.validator(this.option, Danmuku.scheme);
|
||||
art.on('video:play', this.start.bind(this));
|
||||
art.on('video:playing', this.start.bind(this));
|
||||
art.on('video:pause', this.stop.bind(this));
|
||||
art.on('video:waiting', this.stop.bind(this));
|
||||
art.on('destroy', this.stop.bind(this));
|
||||
this.config(option);
|
||||
|
||||
if (typeof this.option.danmus === 'function') {
|
||||
this.option.danmus().then(function (danmus) {
|
||||
@@ -183,6 +259,14 @@
|
||||
|
||||
_this.init();
|
||||
|
||||
art.emit('artplayerPluginDanmu:loaded', danmus);
|
||||
});
|
||||
} else if (typeof this.option.danmus === 'string') {
|
||||
bilibiliDanmuParseFromUrl(this.option.danmus).then(function (danmus) {
|
||||
danmus.forEach(_this.addToQueue.bind(_this));
|
||||
|
||||
_this.init();
|
||||
|
||||
art.emit('artplayerPluginDanmu:loaded', danmus);
|
||||
});
|
||||
} else {
|
||||
@@ -192,6 +276,21 @@
|
||||
}
|
||||
|
||||
createClass(Danmuku, [{
|
||||
key: "config",
|
||||
value: function config(option) {
|
||||
var _this$art$constructor = this.art.constructor,
|
||||
clamp = _this$art$constructor.utils.clamp,
|
||||
validator = _this$art$constructor.validator;
|
||||
this.option = Object.assign({}, Danmuku.option, option);
|
||||
validator(this.option, Danmuku.scheme);
|
||||
this.option.speed = clamp(this.option.speed, 1, 10);
|
||||
this.option.opacity = clamp(this.option.opacity, 0, 1);
|
||||
this.option.size = clamp(this.option.size, 12, 30);
|
||||
this.option.maxlength = clamp(this.option.maxlength, 10, 100);
|
||||
this.option.margin[0] = clamp(this.option.margin[0], 0, 100);
|
||||
this.option.margin[1] = clamp(this.option.margin[1], 0, 100);
|
||||
}
|
||||
}, {
|
||||
key: "init",
|
||||
value: function init() {
|
||||
this.layer = this.art.layers.add({
|
||||
@@ -227,6 +326,11 @@
|
||||
danmu.$ref.style.top = "".concat(this.getDanmuTop(), "px");
|
||||
danmu.$ref.style.transform = "translateX(".concat(-danmu.$restWidth, "px) translateY(0px) translateZ(0px)");
|
||||
danmu.$ref.style.transition = "-webkit-transform ".concat(danmu.$restTime, "s linear 0s");
|
||||
|
||||
if (danmu.border) {
|
||||
danmu.$ref.style.border = "1px solid ".concat(danmu.border);
|
||||
}
|
||||
|
||||
danmu.$state = 'emit';
|
||||
}
|
||||
}, {
|
||||
@@ -278,9 +382,9 @@
|
||||
key: "getDanmuRef",
|
||||
value: function getDanmuRef() {
|
||||
var $player = this.art.template.$player;
|
||||
var _this$art$constructor = this.art.constructor.utils,
|
||||
setStyles = _this$art$constructor.setStyles,
|
||||
append = _this$art$constructor.append;
|
||||
var _this$art$constructor2 = this.art.constructor.utils,
|
||||
setStyles = _this$art$constructor2.setStyles,
|
||||
append = _this$art$constructor2.append;
|
||||
var playerLeft = Danmuku.getRect($player, 'left');
|
||||
var waitDanmu = this.queue.find(function (danmu) {
|
||||
if (danmu.$ref) {
|
||||
@@ -320,9 +424,15 @@
|
||||
}
|
||||
}, {
|
||||
key: "getDanmuTop",
|
||||
value: function getDanmuTop() {
|
||||
value: function getDanmuTop$1() {
|
||||
var $player = this.art.template.$player;
|
||||
var playerHeight = Danmuku.getRect($player, 'height');
|
||||
|
||||
var _Danmuku$getRect4 = Danmuku.getRect($player),
|
||||
playerLeft = _Danmuku$getRect4.left,
|
||||
playerTop = _Danmuku$getRect4.top,
|
||||
playerHeight = _Danmuku$getRect4.height,
|
||||
playerWidth = _Danmuku$getRect4.width;
|
||||
|
||||
var danmus = this.queue.filter(function (danmu) {
|
||||
return danmu.$state === 'emit';
|
||||
});
|
||||
@@ -331,11 +441,41 @@
|
||||
return this.option.margin[0];
|
||||
}
|
||||
|
||||
if (danmus.length === 1) {
|
||||
return this.option.margin[0] + Danmuku.getRect(danmus[0].$ref, 'height');
|
||||
}
|
||||
var danmusBySort = danmus.map(function (danmu) {
|
||||
var _Danmuku$getRect5 = Danmuku.getRect(danmu.$ref),
|
||||
danmuLeft = _Danmuku$getRect5.left,
|
||||
danmuTop = _Danmuku$getRect5.top,
|
||||
danmuWidth = _Danmuku$getRect5.width,
|
||||
danmuHeight = _Danmuku$getRect5.height;
|
||||
|
||||
return 0;
|
||||
var top = danmuTop - playerTop;
|
||||
var left = danmuLeft - playerLeft;
|
||||
var right = playerWidth - left - danmuWidth;
|
||||
return {
|
||||
top: top,
|
||||
left: left,
|
||||
right: right,
|
||||
height: danmuHeight,
|
||||
width: danmuWidth
|
||||
};
|
||||
}).sort(function (prev, next) {
|
||||
return prev.top - next.top;
|
||||
});
|
||||
danmusBySort.unshift({
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
height: this.option.margin[0],
|
||||
width: playerWidth
|
||||
});
|
||||
danmusBySort.push({
|
||||
top: playerHeight - this.option.margin[1],
|
||||
left: 0,
|
||||
right: 0,
|
||||
height: this.option.margin[1],
|
||||
width: playerWidth
|
||||
});
|
||||
return getDanmuTop(danmusBySort);
|
||||
}
|
||||
}, {
|
||||
key: "update",
|
||||
@@ -426,7 +566,7 @@
|
||||
key: "scheme",
|
||||
get: function get() {
|
||||
return {
|
||||
danmus: 'array|function',
|
||||
danmus: 'array|function|string',
|
||||
speed: 'number',
|
||||
opacity: 'number',
|
||||
color: 'string',
|
||||
@@ -446,6 +586,7 @@
|
||||
return {
|
||||
name: 'artplayerPluginDanmu',
|
||||
emit: danmuku.addToQueue.bind(danmuku),
|
||||
config: danmuku.config.bind(danmuku),
|
||||
start: danmuku.start.bind(danmuku),
|
||||
stop: danmuku.stop.bind(danmuku),
|
||||
hide: danmuku.hide.bind(danmuku),
|
||||
@@ -456,6 +597,7 @@
|
||||
|
||||
artplayerPluginDanmu.bilibiliDanmuParseFromXml = bilibiliDanmuParseFromXml;
|
||||
artplayerPluginDanmu.bilibiliDanmuParseFromAv = bilibiliDanmuParseFromAv;
|
||||
artplayerPluginDanmu.bilibiliDanmuParseFromUrl = bilibiliDanmuParseFromUrl;
|
||||
window.artplayerPluginDanmu = artplayerPluginDanmu;
|
||||
|
||||
return artplayerPluginDanmu;
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"artplayer-plugin-danmu.js","sources":["../../node_modules/@babel/runtime/helpers/arrayWithHoles.js","../../node_modules/@babel/runtime/helpers/iterableToArrayLimit.js","../../node_modules/@babel/runtime/helpers/nonIterableRest.js","../../node_modules/@babel/runtime/helpers/slicedToArray.js","../../packages/artplayer-plugin-danmu/src/bilibiliDanmuParse.js","../../node_modules/@babel/runtime/helpers/defineProperty.js","../../node_modules/@babel/runtime/helpers/objectSpread.js","../../node_modules/@babel/runtime/helpers/classCallCheck.js","../../node_modules/@babel/runtime/helpers/createClass.js","../../packages/artplayer-plugin-danmu/src/danmuku.js","../../packages/artplayer-plugin-danmu/src/index.js"],"sourcesContent":["function _arrayWithHoles(arr) {\n if (Array.isArray(arr)) return arr;\n}\n\nmodule.exports = _arrayWithHoles;","function _iterableToArrayLimit(arr, i) {\n var _arr = [];\n var _n = true;\n var _d = false;\n var _e = undefined;\n\n try {\n for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {\n _arr.push(_s.value);\n\n if (i && _arr.length === i) break;\n }\n } catch (err) {\n _d = true;\n _e = err;\n } finally {\n try {\n if (!_n && _i[\"return\"] != null) _i[\"return\"]();\n } finally {\n if (_d) throw _e;\n }\n }\n\n return _arr;\n}\n\nmodule.exports = _iterableToArrayLimit;","function _nonIterableRest() {\n throw new TypeError(\"Invalid attempt to destructure non-iterable instance\");\n}\n\nmodule.exports = _nonIterableRest;","var arrayWithHoles = require(\"./arrayWithHoles\");\n\nvar iterableToArrayLimit = require(\"./iterableToArrayLimit\");\n\nvar nonIterableRest = require(\"./nonIterableRest\");\n\nfunction _slicedToArray(arr, i) {\n return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || nonIterableRest();\n}\n\nmodule.exports = _slicedToArray;","export function bilibiliDanmuParseFromXml(xmlString) {\n if (typeof xmlString !== 'string') return [];\n const srtList = xmlString.match(/<d([\\S ]*?>[\\S ]*?)<\\/d>/gi);\n return srtList.length\n ? srtList.map(item => {\n const [, attrStr, text] = item.match(/<d p=\"(.+)\">(.+)<\\/d>/);\n const attr = attrStr.split(',');\n return attr.length === 8 && text.trim()\n ? {\n text,\n time: Number(attr[0]),\n mode: Number(attr[1]),\n size: Number(attr[2]),\n color: `#${Number(attr[3]).toString(16)}`,\n timestamp: Number(attr[4]),\n pool: Number(attr[5]),\n userID: attr[6],\n rowID: Number(attr[7]),\n }\n : null;\n })\n : [];\n}\n\nexport function bilibiliDanmuParseFromAv(av) {\n const corsUrl = 'https://cors-anywhere.herokuapp.com/';\n return fetch(`${corsUrl}https://api.bilibili.com/x/web-interface/view?aid=${av}`)\n .then(res => res.json())\n .then(res => {\n if (res.code === 0 && res.data && res.data.cid) {\n return fetch(`${corsUrl}https://api.bilibili.com/x/v1/dm/list.so?oid=${res.data.cid}`)\n .then(res => res.text())\n .then(xmlString => {\n return bilibiliDanmuParseFromXml(xmlString);\n });\n }\n throw new Error(`Unable to get data: ${JSON.stringify(res)}`);\n });\n}","function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}\n\nmodule.exports = _defineProperty;","var defineProperty = require(\"./defineProperty\");\n\nfunction _objectSpread(target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i] != null ? arguments[i] : {};\n var ownKeys = Object.keys(source);\n\n if (typeof Object.getOwnPropertySymbols === 'function') {\n ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {\n return Object.getOwnPropertyDescriptor(source, sym).enumerable;\n }));\n }\n\n ownKeys.forEach(function (key) {\n defineProperty(target, key, source[key]);\n });\n }\n\n return target;\n}\n\nmodule.exports = _objectSpread;","function _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}\n\nmodule.exports = _classCallCheck;","function _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.definePrLine truncated
|
||||
{"version":3,"file":"artplayer-plugin-danmu.js","sources":["../../node_modules/@babel/runtime/helpers/arrayWithHoles.js","../../node_modules/@babel/runtime/helpers/iterableToArrayLimit.js","../../node_modules/@babel/runtime/helpers/nonIterableRest.js","../../node_modules/@babel/runtime/helpers/slicedToArray.js","../../packages/artplayer-plugin-danmu/src/bilibiliDanmuParse.js","../../node_modules/@babel/runtime/helpers/defineProperty.js","../../node_modules/@babel/runtime/helpers/objectSpread.js","../../node_modules/@babel/runtime/helpers/classCallCheck.js","../../node_modules/@babel/runtime/helpers/createClass.js","../../packages/artplayer-plugin-danmu/src/getDanmuTop.js","../../packages/artplayer-plugin-danmu/src/danmuku.js","../../packages/artplayer-plugin-danmu/src/index.js"],"sourcesContent":["function _arrayWithHoles(arr) {\n if (Array.isArray(arr)) return arr;\n}\n\nmodule.exports = _arrayWithHoles;","function _iterableToArrayLimit(arr, i) {\n var _arr = [];\n var _n = true;\n var _d = false;\n var _e = undefined;\n\n try {\n for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {\n _arr.push(_s.value);\n\n if (i && _arr.length === i) break;\n }\n } catch (err) {\n _d = true;\n _e = err;\n } finally {\n try {\n if (!_n && _i[\"return\"] != null) _i[\"return\"]();\n } finally {\n if (_d) throw _e;\n }\n }\n\n return _arr;\n}\n\nmodule.exports = _iterableToArrayLimit;","function _nonIterableRest() {\n throw new TypeError(\"Invalid attempt to destructure non-iterable instance\");\n}\n\nmodule.exports = _nonIterableRest;","var arrayWithHoles = require(\"./arrayWithHoles\");\n\nvar iterableToArrayLimit = require(\"./iterableToArrayLimit\");\n\nvar nonIterableRest = require(\"./nonIterableRest\");\n\nfunction _slicedToArray(arr, i) {\n return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || nonIterableRest();\n}\n\nmodule.exports = _slicedToArray;","export function bilibiliDanmuParseFromXml(xmlString) {\n if (typeof xmlString !== 'string') return [];\n const srtList = xmlString.match(/<d([\\S ]*?>[\\S ]*?)<\\/d>/gi);\n return srtList.length\n ? srtList.map(item => {\n const [, attrStr, text] = item.match(/<d p=\"(.+)\">(.+)<\\/d>/);\n const attr = attrStr.split(',');\n return attr.length === 8 && text.trim()\n ? {\n text,\n time: Number(attr[0]),\n mode: Number(attr[1]),\n size: Number(attr[2]),\n color: `#${Number(attr[3]).toString(16)}`,\n timestamp: Number(attr[4]),\n pool: Number(attr[5]),\n userID: attr[6],\n rowID: Number(attr[7]),\n }\n : null;\n })\n : [];\n}\n\nexport function bilibiliDanmuParseFromUrl(url) {\n return fetch(url)\n .then(res => res.text())\n .then(xmlString => {\n return bilibiliDanmuParseFromXml(xmlString);\n });\n}\n\nexport function bilibiliDanmuParseFromAv(av) {\n const corsUrl = 'https://cors-anywhere.herokuapp.com/';\n return fetch(`${corsUrl}https://api.bilibili.com/x/web-interface/view?aid=${av}`)\n .then(res => res.json())\n .then(res => {\n if (res.code === 0 && res.data && res.data.cid) {\n return bilibiliDanmuParseFromUrl(`${corsUrl}https://api.bilibili.com/x/v1/dm/list.so?oid=${res.data.cid}`);\n }\n throw new Error(`Unable to get data: ${JSON.stringify(res)}`);\n });\n}","function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}\n\nmodule.exports = _defineProperty;","var defineProperty = require(\"./defineProperty\");\n\nfunction _objectSpread(target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i] != null ? arguments[i] : {};\n var ownKeys = Object.keys(source);\n\n if (typeof Object.getOwnPropertySymbols === 'function') {\n ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {\n return Object.getOwnPropertyDescriptor(source, sym).enumerable;\n }));\n }\n\n ownKeys.forEach(function (key) {\n defineProperty(target, key, source[key]);\n });\n }\n\n return target;\n}\n\nmodule.exports = _objectSpread;","function _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}\n\nmodule.exports = _classCallCheck;","function _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descLine truncated
|
||||
Reference in new issue
Block a user