feat: 实现动态 DOCX 模板与样式映射

This commit is contained in:
SkyJourney
2026-07-30 14:10:43 +08:00
parent fe5d67fb6d
commit fa159d916f
41 changed files with 3610 additions and 7 deletions
+46 -1
View File
@@ -10,7 +10,8 @@ import {
docxCapabilitySchema,
docxMediaCapturePlanSchema,
docxExportErrorResponseSchema,
docxExportRequestSchema
docxExportRequestSchema,
docxThemeStyleSchema
} from "../src/index.js";
describe("DOCX 共享协议", () => {
@@ -165,3 +166,47 @@ describe("DOCX 共享协议", () => {
).toBe(false);
});
});
describe("DOCX 主题样式协议", () => {
it("接受预设和受限样式覆盖", () => {
expect(
docxThemeStyleSchema.parse({
preset: "formal",
body: {
fonts: {
latin: "Times New Roman",
eastAsia: "SimSun"
},
sizePt: 12,
lineSpacing: 1.5
},
headings: {
sizesPt: [22, 18, 16, 14, 12, 10.5],
color: "#1f2937"
},
table: {
borderColor: "#d1d5db",
cellMarginMm: 1.5
}
})
).toMatchObject({
preset: "formal",
body: { sizePt: 12, lineSpacing: 1.5 }
});
});
it("拒绝危险字体名称和越界样式值", () => {
expect(() =>
docxThemeStyleSchema.parse({
preset: "general",
body: {
fonts: {
latin: "Arial; DROP",
eastAsia: "宋体"
},
sizePt: 200
}
})
).toThrow();
});
});