refactor(web): 界面工具 - 代码优化,替换重复的复制、打包、项目选择和主题切换实现

删除未再引用的文字扫光组件。复制提示、压缩包读写、项目多选和主题揭示的对外行为保持不变。
This commit is contained in:
ddcat666
2026-10-01 11:40:08 +08:00
parent 22e7331d04
commit 572bc341f0
7 changed files with 264 additions and 425 deletions

View File

@@ -1,6 +1,11 @@
import { clsx, type ClassValue } from "clsx";
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
function joinClassNames(parts: ClassValue[]): string {
const resolved = twMerge(clsx(parts));
return resolved.length > 0 ? resolved : "";
}
export function cn(...values: ClassValue[]): string {
return joinClassNames(values);
}

View File

@@ -1,21 +1,26 @@
import { unzipSync, zipSync } from "fflate";
import { unzipSync as unpack, zipSync as pack } from "fflate";
type ZipFile = {
name: string;
data: BlobPart;
};
type ZipSource = BlobPart;
export async function createZip(files: ZipFile[]) {
const entries = await Promise.all(
files.map(async (file) => {
const data = new Uint8Array(await new Blob([file.data]).arrayBuffer());
return [file.name, data] as const;
}),
);
return new Blob([zipSync(Object.fromEntries(entries), { level: 0 })], { type: "application/zip" });
async function toBytes(data: ZipSource): Promise<Uint8Array> {
const buffer = await new Blob([data]).arrayBuffer();
return new Uint8Array(buffer);
}
export async function readZip(file: Blob) {
const entries = unzipSync(new Uint8Array(await file.arrayBuffer()));
return new Map(Object.entries(entries).map(([name, data]) => [name, new Blob([data])]));
export async function createZip(files: Array<{ name: string; data: ZipSource }>): Promise<Blob> {
const entries: Record<string, Uint8Array> = {};
for (const file of files) {
entries[file.name] = await toBytes(file.data);
}
const archive = pack(entries, { level: 0 });
return new Blob([archive], { type: "application/zip" });
}
export async function readZip(file: Blob): Promise<Map<string, Blob>> {
const opened = unpack(await toBytes(file));
const extracted = new Map<string, Blob>();
for (const [name, bytes] of Object.entries(opened)) {
extracted.set(name, new Blob([bytes]));
}
return extracted;
}