mirror of
https://github.com/lqtmcstudio/QZMusic_PC.git
synced 2026-07-01 14:44:28 +08:00
fork(fix): Clone AMLL 并修复 BUG
- 将AMLL Clone到本以地进行修复和优化(emm虽然这很不优雅但是暂时无时间做子模块和Fork) - 修复在当前播放歌词行不可见的视口Seek会出现滚动偏移的问题
This commit is contained in:
39
amll-local/packages/lyric/src/formats/eqrc/utils.ts
Normal file
39
amll-local/packages/lyric/src/formats/eqrc/utils.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
/// <reference types="node" />
|
||||
/**
|
||||
* @module utils
|
||||
* @description
|
||||
*
|
||||
* 包含一些工具函数。
|
||||
*/
|
||||
|
||||
/**
|
||||
* 将十六进制字符串转换为 Uint8Array。
|
||||
*/
|
||||
export function hexToUint8Array(hex: string): Uint8Array {
|
||||
if (typeof Buffer !== "undefined") {
|
||||
return Buffer.from(hex, "hex");
|
||||
}
|
||||
|
||||
if (hex.length % 2 !== 0) {
|
||||
throw new Error("无效的十六进制字符串: 长度必须是偶数");
|
||||
}
|
||||
|
||||
const bytes = new Uint8Array(hex.length / 2);
|
||||
for (let i = 0; i < hex.length; i += 2) {
|
||||
bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 Uint8Array 转换为十六进制字符串。
|
||||
*/
|
||||
export function uint8ArrayToHex(bytes: Uint8Array): string {
|
||||
if (typeof Buffer !== "undefined") {
|
||||
return Buffer.from(bytes).toString("hex");
|
||||
}
|
||||
|
||||
return Array.from(bytes)
|
||||
.map((b) => b.toString(16).padStart(2, "0"))
|
||||
.join("");
|
||||
}
|
||||
Reference in New Issue
Block a user