feat: Refactor worker.js to use dynamic function dispatch

This commit is contained in:
Harvey Zack committed 2024-06-04 19:12:11 +08:00
1 parent d57a13a2bd
commit 69d99cc478
4 files changed
+15 -7

No files matched your search

@@ -588,7 +588,8 @@ class Danmuku {
// 计算弹幕滚动的距离
const distance = clientWidth + danmu.$ref.clientWidth;
// 计算弹幕的top值
const { top } = await this.postMessage({
const { result: top } = await this.postMessage({
type: "getDanmuTop",
target: {
mode: danmu.mode,
height: danmu.$ref.clientHeight,
@@ -821,6 +822,7 @@ function createWorker() {
return new Worker(URL.createObjectURL(blob));
}
function bilibiliDanmuParseFromUrl(url) {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve)=>{
const res = await fetch(url);
const xml = await res.text();
@@ -836,6 +838,7 @@ function bilibiliDanmuParseFromUrl(url) {
xml,
id: Date.now()
});
// eslint-disable-next-line no-unused-vars
} catch (error) {
const danmus = bilibiliDanmuParseFromXml(xml);
resolve(danmus);
@@ -874,7 +877,7 @@ exports.export = function(dest, destName, get) {
};
},{}],"el0Wt":[function(require,module,exports) {
module.exports = "// modules are defined as an array\n// [ module function, map of requires ]\n//\n// map of requires is short require name -> numeric require\n//\n// anything defined in a previous bundle is accessed via the\n// orig method which is the require for previous bundles\n\n(function (modules, entry, mainEntry, parcelRequireName, globalName) {\n /* eslint-disable no-undef */\n var globalObject =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n /* eslint-enable no-undef */\n\n // Save the require from previous bundle to this closure if any\n var previousRequire =\n typeof globalObject[parcelRequireName] === 'function' &&\n globalObject[parcelRequireName];\n\n var cache = previousRequire.cache || {};\n // Do not use `require` to prevent Webpack from trying to bundle this call\n var nodeRequire =\n typeof module !== 'undefined' &&\n typeof module.require === 'function' &&\n module.require.bind(module);\n\n function newRequire(name, jumped) {\n if (!cache[name]) {\n if (!modules[name]) {\n // if we cannot find the module within our internal map or\n // cache jump to the current global require ie. the last bundle\n // that was added to the page.\n var currentRequire =\n typeof globalObject[parcelRequireName] === 'function' &&\n globalObject[parcelRequireName];\n if (!jumped && currentRequire) {\n return currentRequire(name, true);\n }\n\n // If there are other bundles on this page the require from the\n // previous one is saved to 'previousRequire'. Repeat this as\n // many times as there are bundles until the module is found or\n // we exhaust the require chain.\n if (previousRequire) {\n return previousRequire(name, true);\n }\n\n // Try the node require function if it exists.\n if (nodeRequire && typeof name === 'string') {\n return nodeRequire(name);\n }\n\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n }\n\n localRequire.resolve = resolve;\n localRequire.cache = {};\n\n var module = (cache[name] = new newRequire.Module(name));\n\n modules[name][0].call(\n module.exports,\n localRequire,\n module,\n module.exports,\n this\n );\n }\n\n return cache[name].exports;\n\n function localRequire(x) {\n var res = localRequire.resolve(x);\n return res === false ? {} : newRequire(res);\n }\n\n function resolve(x) {\n var id = modules[name][1][x];\n return id != null ? id : x;\n }\n }\n\n function Module(moduleName) {\n this.id = moduleName;\n this.bundle = newRequire;\n this.exports = {};\n }\n\n newRequire.isParcelRequire = true;\n newRequire.Module = Module;\n newRequire.modules = modules;\n newRequire.cache = cache;\n newRequire.parent = previousRequire;\n newRequire.register = function (id, exports) {\n modules[id] = [\n function (require, module) {\n module.exports = exports;\n },\n {},\n ];\n };\n\n Object.defineProperty(newRequire, 'root', {\n get: function () {\n return globalObject[parcelRequireName];\n },\n });\n\n globalObject[parcelRequireName] = newRequire;\n\n for (var i = 0; i < entry.length; i++) {\n newRequire(entry[i]);\n }\n\n if (mainEntry) {\n // Expose entry point to Node, AMD or browser globals\n // Based on https://github.com/ForbesLindesay/umd/blob/master/template.js\n var mainExports = newRequire(mainEntry);\n\n // CommonJS\n if (typeof exports === 'object' && typeof module !== 'undefined') {\n module.exports = mainExports;\n\n // RequireJS\n } else if (typeof define === 'function' && define.amd) {\n define(function () {\n return mainExports;\n });\n\n // <script>\n } else if (globalName) {\n this[globalName] = mainExports;\n }\n }\n})({\"fHwfs\":[function(require,module,exports) {\nfunction getDanmuTop({ target, visibles, clientWidth, clientHeight, marginBottom, marginTop, antiOverlap }) {\n // 弹幕最大高度\n const maxTop = clientHeight - marginBottom;\n // 过滤同模式的弹幕,即每种模式各不影响\n const danmus = visibles.filter((item)=>item.mode === target.mode && item.top <= maxTop).sort((prev, next)=>prev.top - next.top);\n // 如果没有同模式的弹幕,直接返回\n if (danmus.length === 0) {\n if (target.mode === 2) return maxTop - target.height;\n else return marginTop;\n }\n // 上下各加一个虚拟弹幕,方便计算\n danmus.unshift({\n type: \"top\",\n top: 0,\n left: 0,\n right: 0,\n height:Line truncated
module.exports = "// modules are defined as an array\n// [ module function, map of requires ]\n//\n// map of requires is short require name -> numeric require\n//\n// anything defined in a previous bundle is accessed via the\n// orig method which is the require for previous bundles\n\n(function (modules, entry, mainEntry, parcelRequireName, globalName) {\n /* eslint-disable no-undef */\n var globalObject =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n /* eslint-enable no-undef */\n\n // Save the require from previous bundle to this closure if any\n var previousRequire =\n typeof globalObject[parcelRequireName] === 'function' &&\n globalObject[parcelRequireName];\n\n var cache = previousRequire.cache || {};\n // Do not use `require` to prevent Webpack from trying to bundle this call\n var nodeRequire =\n typeof module !== 'undefined' &&\n typeof module.require === 'function' &&\n module.require.bind(module);\n\n function newRequire(name, jumped) {\n if (!cache[name]) {\n if (!modules[name]) {\n // if we cannot find the module within our internal map or\n // cache jump to the current global require ie. the last bundle\n // that was added to the page.\n var currentRequire =\n typeof globalObject[parcelRequireName] === 'function' &&\n globalObject[parcelRequireName];\n if (!jumped && currentRequire) {\n return currentRequire(name, true);\n }\n\n // If there are other bundles on this page the require from the\n // previous one is saved to 'previousRequire'. Repeat this as\n // many times as there are bundles until the module is found or\n // we exhaust the require chain.\n if (previousRequire) {\n return previousRequire(name, true);\n }\n\n // Try the node require function if it exists.\n if (nodeRequire && typeof name === 'string') {\n return nodeRequire(name);\n }\n\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n }\n\n localRequire.resolve = resolve;\n localRequire.cache = {};\n\n var module = (cache[name] = new newRequire.Module(name));\n\n modules[name][0].call(\n module.exports,\n localRequire,\n module,\n module.exports,\n this\n );\n }\n\n return cache[name].exports;\n\n function localRequire(x) {\n var res = localRequire.resolve(x);\n return res === false ? {} : newRequire(res);\n }\n\n function resolve(x) {\n var id = modules[name][1][x];\n return id != null ? id : x;\n }\n }\n\n function Module(moduleName) {\n this.id = moduleName;\n this.bundle = newRequire;\n this.exports = {};\n }\n\n newRequire.isParcelRequire = true;\n newRequire.Module = Module;\n newRequire.modules = modules;\n newRequire.cache = cache;\n newRequire.parent = previousRequire;\n newRequire.register = function (id, exports) {\n modules[id] = [\n function (require, module) {\n module.exports = exports;\n },\n {},\n ];\n };\n\n Object.defineProperty(newRequire, 'root', {\n get: function () {\n return globalObject[parcelRequireName];\n },\n });\n\n globalObject[parcelRequireName] = newRequire;\n\n for (var i = 0; i < entry.length; i++) {\n newRequire(entry[i]);\n }\n\n if (mainEntry) {\n // Expose entry point to Node, AMD or browser globals\n // Based on https://github.com/ForbesLindesay/umd/blob/master/template.js\n var mainExports = newRequire(mainEntry);\n\n // CommonJS\n if (typeof exports === 'object' && typeof module !== 'undefined') {\n module.exports = mainExports;\n\n // RequireJS\n } else if (typeof define === 'function' && define.amd) {\n define(function () {\n return mainExports;\n });\n\n // <script>\n } else if (globalName) {\n this[globalName] = mainExports;\n }\n }\n})({\"fHwfs\":[function(require,module,exports) {\nfunction getDanmuTop({ target, visibles, clientWidth, clientHeight, marginBottom, marginTop, antiOverlap }) {\n // 弹幕最大高度\n const maxTop = clientHeight - marginBottom;\n // 过滤同模式的弹幕,即每种模式各不影响\n const danmus = visibles.filter((item)=>item.mode === target.mode && item.top <= maxTop).sort((prev, next)=>prev.top - next.top);\n // 如果没有同模式的弹幕,直接返回\n if (danmus.length === 0) {\n if (target.mode === 2) return maxTop - target.height;\n else return marginTop;\n }\n // 上下各加一个虚拟弹幕,方便计算\n danmus.unshift({\n type: \"top\",\n top: 0,\n left: 0,\n right: 0,\n height:Line truncated
},{}],"cI0ih":[function(require,module,exports) {
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
@@ -1 +1 @@
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6CAIwB;AAJxB;;AACA;;AACA;;AAEe,SAAS,uBAAuB,MAAM;IACjD,OAAO,CAAC;QACJ,MAAM,UAAU,IAAI,CAAA,GAAA,uBAAO,AAAD,EAAE,KAAK;QACjC,MAAM,UAAU,IAAI,CAAA,GAAA,uBAAO,AAAD,EAAE,KAAK;QAEjC,IAAI,QAAQ,MAAM,CAAC,OAAO,EACtB,CAAA,GAAA,uBAAO,AAAD,EAAE,KAAK,SAAS,QAAQ,MAAM,CAAC,OAAO;QAGhD,OAAO;YACH,MAAM;YACN,MAAM,QAAQ,IAAI,CAAC,IAAI,CAAC;YACxB,MAAM,QAAQ,IAAI,CAAC,IAAI,CAAC;YACxB,QAAQ,QAAQ,MAAM,CAAC,IAAI,CAAC;YAC5B,MAAM,QAAQ,IAAI,CAAC,IAAI,CAAC;YACxB,MAAM,QAAQ,IAAI,CAAC,IAAI,CAAC;YACxB,OAAO,QAAQ,KAAK,CAAC,IAAI,CAAC;YAC1B,OAAO,QAAQ,KAAK,CAAC,IAAI,CAAC;YAC1B,IAAI,UAAS;gBACT,OAAO,QAAQ,MAAM;YACzB;YACA,IAAI,UAAS;gBACT,OAAO,QAAQ,MAAM;YACzB;YACA,IAAI,UAAS;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AErC,IAAI,OAAO,aAAa,UACpB,OAAO,MAAM,UAAU,IAAI;QAG/B,IAAI,OAAO,aAAa,YAAY,SAAS,QAAQ,CAAC,MAAM;YACxD,MAAM,QAAQ,WAAW,YAAY;YACrC,OAAO,MAAM,eAAe,OAAO,IAAI;QAC3C;QAEA,OAAO,QAAQ,MAAM,CAAC,QAAQ;IAClC;IAEA,YAAY;IACZ,IAAI,OAAO;QACP,MAAM,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,MAAM,SAAS,aAAa,CAAC;QACxD,KAAK,KAAK,CAAC,OAAO,GAAG,QAAQ,OAAO;QACpC,KAAK,OAAO,CAAC,IAAI,GAAG;QACpB,KAAK,SAAS,GAAG;QACjB,OAAO;IACX;IAEA,aAAa;IACb,IAAI,SAAS;QACT,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,GAAG;QAEhC,MAAM,SAAS,EAAE;QAEjB,8BAA8B;QAC9B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAU,OAAO,IAAI,CAAC;QAE5C,sBAAsB;QACtB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;YACjB,IAAI,cAAc,OAAO,MAAM,IAAI,IAAI,MAAM,IAAI,IAAI,cAAc,KAC/D,OAAO,IAAI,CAAC;QAEpB;QAEA,OAAO;IACX;IAEA,0BAA0B;IAC1B,IAAI,WAAW;QACX,MAAM,SAAS,EAAE;QACjB,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,OAAO;QACpC,MAAM,aAAa,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OALine truncated
@@ -514,7 +514,8 @@ export default class Danmuku {
const distance = clientWidth + danmu.$ref.clientWidth;
// 计算弹幕的top值
const { top } = await this.postMessage({
const { result: top } = await this.postMessage({
type: 'getDanmuTop',
target: {
mode: danmu.mode,
height: danmu.$ref.clientHeight,
@@ -129,10 +129,14 @@ function getDanmuTop({ target, visibles, clientWidth, clientHeight, marginBottom
onmessage = (event) => {
const { data } = event;
if (!data.id) return;
const top = getDanmuTop(data);
if (!data.id || !data.type) return;
const fns = { getDanmuTop };
const fn = fns[data.type];
const result = fn(data);
self.postMessage({
top,
result,
id: data.id,
});
};