feat: 完善 Mermaid 配置与预览缩放

This commit is contained in:
SkyJourney
2026-07-26 23:10:22 +08:00
parent 15dd2acfc0
commit d93728bb8b
25 changed files with 870 additions and 56 deletions
+37 -7
View File
@@ -2,24 +2,32 @@ import { describe, expect, it } from "vitest";
import { defaultExportConfig } from "@md-to-pdf/core";
import {
EXPORT_CONFIG_STORAGE_KEY,
LEGACY_EXPORT_CONFIG_STORAGE_KEY,
loadExportConfig,
parseStoredExportConfig,
saveExportConfig
} from "../src/export-settings";
function createMemoryStorage(initialValue: string | null = null) {
let value = initialValue;
function createMemoryStorage(
initialValue: string | null = null,
legacyValue: string | null = null
) {
const values = new Map<string, string>();
if (initialValue) {
values.set(EXPORT_CONFIG_STORAGE_KEY, initialValue);
}
if (legacyValue) {
values.set(LEGACY_EXPORT_CONFIG_STORAGE_KEY, legacyValue);
}
return {
getItem(key: string) {
return key === EXPORT_CONFIG_STORAGE_KEY ? value : null;
return values.get(key) ?? null;
},
setItem(key: string, nextValue: string) {
if (key === EXPORT_CONFIG_STORAGE_KEY) {
value = nextValue;
}
values.set(key, nextValue);
},
read() {
return value;
return values.get(EXPORT_CONFIG_STORAGE_KEY) ?? null;
}
};
}
@@ -44,6 +52,28 @@ describe("导出设置缓存", () => {
).toEqual(defaultExportConfig);
});
it("将 v2 缓存迁移为 v3 并保留已有设置", () => {
const legacyConfig = {
...defaultExportConfig,
version: 2,
mermaid: undefined,
paper: {
...defaultExportConfig.paper,
format: "A5"
}
};
const storage = createMemoryStorage(
null,
JSON.stringify(legacyConfig)
);
const migrated = loadExportConfig(storage);
expect(migrated.version).toBe(3);
expect(migrated.paper.format).toBe("A5");
expect(migrated.mermaid).toEqual(defaultExportConfig.mermaid);
expect(storage.read()).toContain('"version":3');
});
it("保存并恢复经过校验的配置", () => {
const storage = createMemoryStorage();
const config = {