新增共享 Preview Engine,统一 Web 连续预览、快速分页、Playwright PDF 与 Electron PDF;实现稳定前缀复用和修改位置后的增量分页,保留媒体块按文档顺序串行回填与单次重排。 完善跨端链接与桌面文档工作流:Web 受控处理锚点和 HTTP/HTTPS 外链;Desktop 支持本地路径、file URI、系统协议、多窗口、同文件单例、Markdown 当前或新窗口打开,以及聚焦时外部文件变化提示。 统一四套内置主题名称并默认使用 Typora Github;修复连续预览双滚动条、ECharts 尺寸、PDF 本地链接、围栏代码块 Typora DOM 与重复行内样式;桌面发行链强制完整重建内嵌 Web,避免安装包携带陈旧资源。 发布 Web/Compose 与 Windows NSIS/ZIP:镜像 yixiong/md-to-pdf:v0.5.0 已健康部署;NSIS SHA-256 为 60992D1FDCA513F46346C78478537EB4159D8C0E76B41ECF3CDC25BE77707D92,ZIP SHA-256 为 D74F82293FB67126E583546CBA894569EFC9A0B1B6343FAC648CCC95F1D188D8,本机安装版已升级至 v0.5.0。 验证:全项目 238 项测试通过,类型检查、生产构建和 git diff --check 通过;Web 快速/连续/精确预览、Compose、Desktop 多窗口、窗口状态、文件关联、链接与代码块均完成真实环境验收。
139 lines
3.6 KiB
TypeScript
139 lines
3.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
cssPixelsToMillimeters,
|
|
defaultExportConfig,
|
|
exportConfigSchema,
|
|
getPaperDimensionsMm,
|
|
millimetersToCssPixels,
|
|
millimetersToPdfPoints,
|
|
paperDimensionsMm,
|
|
supportedMermaidLayouts,
|
|
supportedMermaidLooks,
|
|
supportedMermaidThemes,
|
|
supportedPaperFormats
|
|
} from "../src/export-config.js";
|
|
|
|
describe("导出配置", () => {
|
|
it("只保留五种固定纸张尺寸", () => {
|
|
expect(supportedPaperFormats).toEqual([
|
|
"A3",
|
|
"A4",
|
|
"A5",
|
|
"Letter",
|
|
"Legal"
|
|
]);
|
|
expect(paperDimensionsMm).toEqual({
|
|
A3: { width: 297, height: 420 },
|
|
A4: { width: 210, height: 297 },
|
|
A5: { width: 148, height: 210 },
|
|
Letter: { width: 216, height: 279 },
|
|
Legal: { width: 216, height: 356 }
|
|
});
|
|
});
|
|
|
|
it("使用 A4 和 16mm 作为默认纸张配置", () => {
|
|
expect(defaultExportConfig.themeId).toBe("typora-github");
|
|
expect(defaultExportConfig.paper).toEqual({
|
|
format: "A4",
|
|
orientation: "portrait",
|
|
margins: {
|
|
top: "16mm",
|
|
right: "16mm",
|
|
bottom: "16mm",
|
|
left: "16mm"
|
|
}
|
|
});
|
|
expect(exportConfigSchema.safeParse(defaultExportConfig).success).toBe(true);
|
|
});
|
|
|
|
it("提供 Mermaid 官方布局、主题、外观和字体默认值", () => {
|
|
expect(supportedMermaidLayouts).toEqual(["dagre", "elk"]);
|
|
expect(supportedMermaidLooks).toEqual([
|
|
"classic",
|
|
"handDrawn",
|
|
"neo"
|
|
]);
|
|
expect(supportedMermaidThemes).toContain("redux-dark-color");
|
|
expect(defaultExportConfig.mermaid).toEqual({
|
|
layout: "dagre",
|
|
theme: "default",
|
|
look: "classic",
|
|
fontFamily: "Segoe UI, Microsoft YaHei, sans-serif"
|
|
});
|
|
});
|
|
|
|
it("拒绝 Mermaid 未支持的导出配置", () => {
|
|
expect(
|
|
exportConfigSchema.safeParse({
|
|
...defaultExportConfig,
|
|
mermaid: {
|
|
...defaultExportConfig.mermaid,
|
|
layout: "unknown"
|
|
}
|
|
}).success
|
|
).toBe(false);
|
|
expect(
|
|
exportConfigSchema.safeParse({
|
|
...defaultExportConfig,
|
|
mermaid: {
|
|
...defaultExportConfig.mermaid,
|
|
fontFamily: ""
|
|
}
|
|
}).success
|
|
).toBe(false);
|
|
});
|
|
|
|
it("使用统一的 96 CSS px/in 和 72 PDF pt/in 换算物理尺寸", () => {
|
|
expect(millimetersToCssPixels(25.4)).toBeCloseTo(96);
|
|
expect(cssPixelsToMillimeters(96)).toBeCloseTo(25.4);
|
|
expect(millimetersToCssPixels(210)).toBeCloseTo(793.700787);
|
|
expect(millimetersToPdfPoints(210)).toBeCloseTo(595.275591);
|
|
});
|
|
|
|
it("根据方向交换纸张宽高", () => {
|
|
expect(getPaperDimensionsMm("A5", "portrait")).toEqual({
|
|
width: 148,
|
|
height: 210
|
|
});
|
|
expect(getPaperDimensionsMm("A5", "landscape")).toEqual({
|
|
width: 210,
|
|
height: 148
|
|
});
|
|
});
|
|
|
|
it("拒绝旧配置版本和已移除的纸张类型", () => {
|
|
expect(
|
|
exportConfigSchema.safeParse({
|
|
...defaultExportConfig,
|
|
version: 1
|
|
}).success
|
|
).toBe(false);
|
|
expect(
|
|
exportConfigSchema.safeParse({
|
|
...defaultExportConfig,
|
|
paper: {
|
|
...defaultExportConfig.paper,
|
|
format: "Tabloid"
|
|
}
|
|
}).success
|
|
).toBe(false);
|
|
});
|
|
|
|
it("拒绝没有正文可用区域的页边距", () => {
|
|
expect(
|
|
exportConfigSchema.safeParse({
|
|
...defaultExportConfig,
|
|
paper: {
|
|
...defaultExportConfig.paper,
|
|
margins: {
|
|
top: "149mm",
|
|
right: "105mm",
|
|
bottom: "149mm",
|
|
left: "105mm"
|
|
}
|
|
}
|
|
}).success
|
|
).toBe(false);
|
|
});
|
|
});
|