import { DOCX_STYLE_SLOT_NAMES, type DocxStyleSlotName } from "./slots.js"; function attribute(slot: DocxStyleSlotName) { return `data-docx-slot="${slot}"`; } const transparentPixel = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="; export function createDocxStyleProbeMarkup(): string { return `

一级标题

文档标题

示例作者

二级标题

三级标题

四级标题

五级标题
六级标题

正文 粗体 斜体 删除线 inline() 链接

  1. 有序列表

引用内容

const key = "value"; true title 1 // comment Array @meta value /x/ {}
表头
单元格
样式探针
图注

脚注内容

秘密 加急

示例发文机关

示例发〔2026〕1号 签发人:张三

公文标题

示例发文机关

抄送:示例单位

示例办公室

工作简报

第1期示例单位

简报标题

联系人:示例

示例建设项目

可行性研究报告

送审稿 V1.0

建设单位:示例单位

编制单位:示例单位

正本

示例采购项目

ZB-2026-001

投标文件

技术及商务文件

投标人:示例公司

法定代表人或授权代表:李四

`.trim(); } export function listDocxStyleProbeSlots( markup = createDocxStyleProbeMarkup() ): DocxStyleSlotName[] { const matches = markup.matchAll( /data-docx-slot="([^"]+)"/gu ); return [...matches].map( (match) => match[1] as DocxStyleSlotName ); } export function validateDocxStyleProbeMarkup( markup = createDocxStyleProbeMarkup() ): void { const actual = listDocxStyleProbeSlots(markup); const duplicates = actual.filter( (name, index) => actual.indexOf(name) !== index ); const actualSet = new Set(actual); const missing = DOCX_STYLE_SLOT_NAMES.filter( (name) => !actualSet.has(name) ); const unexpected = actual.filter( (name) => !DOCX_STYLE_SLOT_NAMES.includes(name as DocxStyleSlotName) ); if (duplicates.length || missing.length || unexpected.length) { throw new Error( [ duplicates.length ? `重复槽位:${[...new Set(duplicates)].join("、")}` : "", missing.length ? `缺少槽位:${missing.join("、")}` : "", unexpected.length ? `未知槽位:${[...new Set(unexpected)].join("、")}` : "" ] .filter(Boolean) .join(";") ); } }