77 lines
1.8 KiB
TypeScript
77 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import type { DocxThemeTokenSet } from "@md-to-pdf/docx-theme-engine";
|
|
import {
|
|
DOCX_SLOT_WORD_STYLE_BINDINGS,
|
|
collectDocxTokenFonts,
|
|
createDocxTokenSlotMap,
|
|
resolveTokenFonts
|
|
} from "../src/index.js";
|
|
|
|
const tokens: DocxThemeTokenSet = {
|
|
schemaVersion: 1,
|
|
themeId: "test-theme",
|
|
themeFingerprint: "a".repeat(64),
|
|
mode: "auto",
|
|
basePreset: "general",
|
|
slots: [
|
|
{
|
|
slot: "paragraph",
|
|
source: "computed-css",
|
|
confidence: "exact",
|
|
style: {
|
|
fontCandidates: [
|
|
"Source Han Serif SC",
|
|
"Times New Roman",
|
|
"serif"
|
|
]
|
|
}
|
|
}
|
|
],
|
|
diagnostics: []
|
|
};
|
|
|
|
describe("DOCX 令牌样式映射", () => {
|
|
it("以稳定样式 ID 覆盖标准 Markdown 和结构槽位", () => {
|
|
expect(
|
|
DOCX_SLOT_WORD_STYLE_BINDINGS["heading-1"]
|
|
).toEqual([
|
|
{
|
|
styleId: "Heading1",
|
|
type: "paragraph",
|
|
basedOn: "Normal"
|
|
},
|
|
{
|
|
styleId: "Heading1Char",
|
|
type: "character",
|
|
basedOn: "DefaultParagraphFont"
|
|
}
|
|
]);
|
|
expect(
|
|
DOCX_SLOT_WORD_STYLE_BINDINGS["official-title"]?.[0]
|
|
?.styleId
|
|
).toBe("MdOfficialTitle");
|
|
expect(
|
|
DOCX_SLOT_WORD_STYLE_BINDINGS["tender-representative"]?.[0]
|
|
?.styleId
|
|
).toBe("MdTenderRepresentative");
|
|
});
|
|
|
|
it("按文字系统选择字体并过滤 CSS 通用族名", () => {
|
|
const slot = createDocxTokenSlotMap(tokens).get("paragraph");
|
|
expect(
|
|
resolveTokenFonts(slot?.style, {
|
|
latin: "Arial",
|
|
eastAsia: "SimSun"
|
|
})
|
|
).toEqual({
|
|
latin: "Times New Roman",
|
|
eastAsia: "Source Han Serif SC",
|
|
complexScript: "Times New Roman"
|
|
});
|
|
expect([...collectDocxTokenFonts(tokens)]).toEqual([
|
|
"Source Han Serif SC",
|
|
"Times New Roman"
|
|
]);
|
|
});
|
|
});
|