将Base64对项内的转换代码替换为Uint8Array原生方法(但是太新了,用的应该是core-js内的polyfill)

This commit is contained in:
枫谷剑仙 2025-03-27 21:30:48 +08:00
parent c87cd6fb0b
commit f996de11a0
5 changed files with 37 additions and 39 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,11 +1,11 @@
{
"dependencies": {
"@html2canvas/html2canvas": "^1.6.3",
"@xmldom/xmldom": "^0.9.6",
"@xmldom/xmldom": "^0.9.8",
"@zxing/library": "^0.21.3",
"core-js-bundle": "^3.39.0",
"core-js-bundle": "^3.41.0",
"mime": "^4.0.6",
"opencc-js": "^1.0.5",
"xml-formatter": "^3.6.3"
"xml-formatter": "^3.6.5"
}
}

View File

@ -68,7 +68,6 @@ Blob.prototype.toBase64 = function() {
});
}
/**
* @readonly
* @enum {boolean}
@ -130,7 +129,21 @@ const Base64 = {
const str = decoder.decode(view);
return str;
},
//Base64还原成Uint8Array
bytesToBase64DataUrl: async function(bytes, type = "application/octet-stream") {
return await new Promise((resolve, reject) => {
const reader = Object.assign(new FileReader(), {
onload: () => resolve(reader.result),
onerror: () => reject(reader.error),
});
reader.readAsDataURL(new File([bytes], "", { type }));
});
},
dataUrlToBytes: async function(dataUrl) {
const res = await fetch(dataUrl);
return new Uint8Array(await res.arrayBuffer());
}
/*
//Base64还原成Uint8Array已经被原生的 Uint8Array.fromBase64() 替代。
decodeToUint8Array: function base64DecToArr(sBase64, nBlocksSize) {
function b64ToUint6(nChr) {
return nChr > 64 && nChr < 91
@ -172,7 +185,7 @@ const Base64 = {
return taBytes;
},
//Uint8Array编码成Base64
//Uint8Array编码成Base64,已经被原生的 Uint8Array.prototype.toBase64() 替代。
encodeFromUint8Array: function base64EncArr(aBytes) {
function uint6ToB64(nUint6) {
return nUint6 < 26
@ -215,24 +228,7 @@ const Base64 = {
(nMod3 === 2 ? "" : nMod3 === 1 ? "=" : "==")
);
},
bytesToBase64DataUrl: async function(bytes, type = "application/octet-stream") {
return await new Promise((resolve, reject) => {
const reader = Object.assign(new FileReader(), {
onload: () => resolve(reader.result),
onerror: () => reject(reader.error),
});
reader.readAsDataURL(new File([bytes], "", { type }));
});
},
dataUrlToBytes: async function(dataUrl) {
const res = await fetch(dataUrl);
return new Uint8Array(await res.arrayBuffer());
}
}
//Buffer转16进制字符串
Uint8Array.prototype.toHex1 = function() {
return [...this].map(n=>n.toString(16).padStart(2,'0')).join('');
*/
}
/**

View File

@ -2195,7 +2195,7 @@ function reloadFormationData(event) {
}
//2025年3月27日之后的 Uint16 数组转 Base64
else if (obj.ui16) {
const ui8arr = Base64.decodeToUint8Array(obj.ui16);
const ui8arr = Uint8Array.fromBase64(obj.ui16);
const idArr = ArrayConvert.BufferToNumberArray(ui8arr, Uint16Array, Endian.little);
return idArr;
}
@ -4990,7 +4990,9 @@ function initialize() {
const idArr = searchMonList.originalHeads?.map(head=>head.card.id) ?? [];
if (idArr.length > 0) {
const ui16Arr = ArrayConvert.NumberArrayToBuffer(idArr, Uint16Array, Endian.little);
const b64 = Base64.encodeFromUint8Array(new Uint8Array(ui16Arr.buffer));
console.log(ui16Arr, new Uint8Array(ui16Arr.buffer));
const b64 = (new Uint8Array(ui16Arr.buffer)).toBase64();
const outObj = {
"ui16": b64
};

View File

@ -44231,11 +44231,11 @@ const cachesMap = new Map([
],
[
"script-universal_function.js",
"312ac475579456dbff44887ccaceb658"
"74aa71916cf95d943fab1ce6476ddabb"
],
[
"script.js",
"c6c3de98108ff05bcd1099a8f39907e8"
"651dc95a440c6432688728ba4f0aec32"
],
[
"solo.html",