Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- **Issue #216 markdown 剥离不再吞纯下划线串**:下划线强调正则增加守卫,PDF 签名线(如 `Date: ____________`)不再被回溯匹配逐轮缩减,影响 txt/json/csv/xlsx/pptx 输出;真实 `__强调__` 标记仍正常剥离。
- **Issue #216 PDF.js 提取的 Buffer 输入安全**:Node Buffer 先复制为独立 `Uint8Array` 再交给 PDF.js,避免 transfer 共享内存池导致无关数据被 detach。
- **Issue #216 DOCX 多节页面设置与旧式横向合并保留**:段落级 `w:sectPr`(节结束标记)解析为 `paragraph` / `heading` 块的 `sectionBreak.pageLayout` 并在写出时还原,body 末尾节仍走 `metadata.ooxml.pageLayout`,多节文档往返后各节页面几何均保留;含分栏、页眉页脚引用、首页不同等暂不支持的节属性时发出 `DOCX_SECTION_PROPS_PARTIAL`。旧式 `w:hMerge`(restart + 连续 continue)映射为 `cellSpans` 的 `columnSpan`,能完整映射时不再发 `DOCX_TABLE_MERGE_APPROXIMATED`;与 `gridSpan` 混用或结构无法干净映射时仍发出该警告。新增多节往返、hMerge 往返与混用冲突回归测试。
- **Issue #216 PDF 多余空格(加字距碎词与 CJK 伪空格)**:item 拼接层 `shouldSeparatePdfItems` 词间空格阈值从 0.12em 提到 0.22em(近似真实空格宽度 0.25em),加字距排版的字形间隙不再被当成词间空格("E x p a n d e d" 式碎词);新增 `collapseCjkFakeSpaces` 收拢 pdf.js addFakeSpaces 对 0.102em–0.6em 字间位移插入的伪空格——连续 ≥3 个单字 CJK 以单空格相连的链收拢去空格("加 字 距 版"→"加字距版"),两个多字 CJK 词之间的对齐空格保留。拉丁字母加字距碎词的词边界在 pdf.js 合并 item 时已丢失,无法可靠还原,保留原样(上游启发式限制)。新增加字距字形链不拆词、CJK 伪空格收拢、多字词空格保留回归断言。

## [2.4.0] - 2026-07-17

Expand Down
1 change: 1 addition & 0 deletions docs/development/DEVELOPMENT_TASKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@

> 仅保留最近 4 周内的记录;更早的归档到 [docs/archive/DEVELOPMENT_HISTORY.md](docs/archive/DEVELOPMENT_HISTORY.md),逐次发布的细节走 [CHANGELOG.md](CHANGELOG.md)。

- **2026-09-24 (Issue #216 PDF 多余空格:加字距碎词与 CJK 伪空格收拢)**:诊断发现 PDF 提取的多余空格有两个来源——item 拼接层 `shouldSeparatePdfItems` 阈值 0.12em 过低,把加字距排版的字形间隙当成词间空格("E x p a n d e d" 式碎词);pdf.js 内部 addFakeSpaces 对 0.102em–0.6em 字间位移插入 ASCII 伪空格混在 item.str 里,CJK 加字距文本碎成「加 字 距 版」。修复:阈值改为 `height * 0.22`(近似真实空格宽度 0.25em);新增导出 `collapseCjkFakeSpaces`——连续 ≥3 个单字 CJK 以单空格相连的链收拢去空格,两个多字 CJK 词之间的对齐空格保留,`extractTextWithPdfJs` 的 item 映射与 textRuns 映射均经过该收拢。回归断言:加字距字形链(0.18em 间隙)不拆词("Expanded")、`collapseCjkFakeSpaces("加 字 距 版") === "加字距版"`、("逐词 绘制") 保留、("Normal spacing line") 不变。仍受限:拉丁字母加字距碎词的词边界在 pdf.js 合并 item 时已丢失,无法可靠还原,保留原样(上游启发式限制)。`npm test` 50 个脚本在含 / 缺 pdfjs-dist 双向环境下全量通过;空格压测样例 5 项通过 + 1 项已知限制标注;中英混排全链路 20/20 无回归。
- **2026-09-24 (Issue #216 PDF 列表编号、签名下划线与 Buffer 输入安全)**:诊断发现:2 倍行距的条款列表被原 1.6 倍行高阈值拆成单条 list,writer 将每项从 1 重排编号;PDF 签名线(`Date: ____________`)被 markdown 下划线强调正则回溯逐轮缩减(12→8→6),污染 txt/json/csv/xlsx/pptx 输出;Node Buffer 直接传入 PDF.js 时其底层共享内存池被 transfer 整块 detach,污染无关数据。修复:`analyzeSingleColumnLayout` 新增 `lastLineWasListItem` 状态,同类列表项合并放宽到 3 倍行高且要求上一行为列表项,段落打断后不再合并;`stripMarkdownInlineSyntax` 两条下划线正则加 `(?!_)` / `(?<!_)` 守卫,纯下划线串原样保留、真实 `__强调__` 标记仍正常剥离;`coercePdfBytes` 将 Node Buffer 先复制为独立 `Uint8Array` 再交给 PDF.js。回归测试:`layout-offset-regression-test.js` 加列表合并 / 超 3 倍行距不合并 / 段落打断 / 下划线串 round-trip / 真强调剥离断言;`pdf-reader-test.js` 加测试 13(Buffer 输入经提取后共享池哨兵与输入字节均存活,含 pdfjs 缺失环境守卫)。`npm test` 50 个脚本在含 / 缺 pdfjs-dist 双向环境下全量通过;仿真中英混排 PDF 全链路实测 20/20(条款编号恢复 1/2/3/4、签名下划线 12 个保留、pdf→pdf 字节一致)。
- **2026-09-24 (Issue #216 PDF 提取链可靠性、预览与质量诚实性)**:诊断发现 PDF.js 提取成功后被 `document.destroy()` 异常丢弃、Node CMap 传 `file:` URL 提取为空、无正文 PDF 把占位提示导出为正文、备用预览被 CSP `object-src 'none'` 拦截、稀疏英文表单误判为扫描件、质量报告未实测却标高保真。修复:提取后销毁 loading task 且清理失败不丢结果;Node 用原生文件路径加载 CMap/标准字体;无正文返回 `PDF_TEXT_UNAVAILABLE`/`PDF_ENCRYPTED`;`sparse-text-pdf` 标记避免重复 OCR;混合 PDF 仅对无文字页按页 OCR 并按原页号插回(坐标映射回 PDF 点位);PDF→PDF 经路由审计后复制原字节(`PDF_ORIGINAL_PRESERVED`);输入/输出 PDF 预览改本地 PDF.js 逐页渲染;PDF 表格按列坐标定位、DOCX 首行/续行缩进与制表位映射到 PDF;`textFidelity` 未实测标 `unverified`,未确认页号进 `unresolvedPdfPages`,工作台显示警告状态。同日续批:DOCX 多节页面设置经块级 `sectionBreak.pageLayout` 保留(尾部 sectPr 仍走 `metadata.ooxml.pageLayout`,暂不支持的节属性发 `DOCX_SECTION_PROPS_PARTIAL`);旧式 `hMerge` 映射为 `columnSpan`(完整映射不再发 `DOCX_TABLE_MERGE_APPROXIMATED`,混用 gridSpan 等仍警告);OCR 读回补多页门禁(后续页漏检必失败)。仍受限:嵌套表格展平+警告、w:cols 分栏与页眉页脚引用不保留、真实英文文档视觉回归基线待脱敏样例。
- **2026-09-24 (Issue #214 英文文本与表单布局回归)**:TXT 读写保留段内单换行、行首缩进和字段下划线,并将 Markdown 下划线语法识别限制为非单词边界;PDF 仅按真实水平坐标补英文片段空格,检测连续三行以上的双栏内容并按左栏后右栏输出;DOCX 保留页面几何、段落格式/自定义制表位、表格列宽和 `gridSpan` / `vMerge`,DOCX→PDF/HTML 投影保留可表达的页边距、对齐、缩进和列宽;QualityReport 增加 `layoutFidelity`,不可表达的布局发出 lossy warning。增加 `scripts/layout-offset-regression-test.js`,覆盖 TXT、英文 PDF 单栏/双栏、DOCX 表单 DOCX/PDF/HTML 往返。当前无用户脱敏原件,版面回归使用程序生成的合成文档;多节、多栏跨页、旧式 `hMerge`、浮动对象及完整字体主题仍会警告降级。
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"main": "src/web-server.js",
"scripts": {
"start": "node src/web-server.js",
"dev": "node src/web-server.js",
"web": "node src/web-server.js",
"vendor:pdfjs": "node scripts/sync-pdfjs-vendor.js",
"vendor:tesseract": "node scripts/sync-tesseract-vendor.js",
Expand Down
23 changes: 20 additions & 3 deletions public/formats/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,16 @@ function shouldSeparatePdfItems(previous, current) {
// PDF.js often returns one text item per glyph/word and omits literal spaces.
// Only insert one when actual horizontal geometry proves a word gap. Character
// classes alone are not evidence of whitespace: they split English words and IDs.
// The gap threshold approximates a real space advance (~0.25em): letter-spaced
// tracking (usually <=0.2em) must not become a space between every glyph — that
// turned "Expanded tracking" into "E x p a n d e d" (issue #216 续批). Residual
// boundary: tracking wider than ~0.22em is indistinguishable from a word space.
if (previous?.hasHorizontalGeometry && current?.hasPosition) {
const previousEnd = Number(previous.x) + Number(previous.width);
const currentStart = Number(current.x);
const gap = currentStart - previousEnd;
const height = Math.max(Number(previous.height) || 0, Number(current.height) || 0, 12);
return gap > Math.max(1.5, height * 0.12);
return gap > Math.max(1.5, height * 0.22);
}
return false;
}
Expand Down Expand Up @@ -427,6 +431,19 @@ function joinPdfItems(items, separator = " ") {
return output.replace(/[ \t]+/g, " ").replace(/ *\n */g, "\n").trim();
}

// pdf.js 的 addFakeSpaces 对 0.102em-0.6em 的字间位移一律插入 ASCII 伪空格:
// 加字距排版的文本每个字形都命中该区间,CJK 变成“加 字 距 版”式碎字。
// 收拢规则:连续 ≥3 个单字 CJK 以单空格相连必为加字距碎字,去掉内部空格;
// 两个多字词之间的空格可能是表单/标签的对齐间距(如“逐词 绘制”),必须保留。
// 拉丁字母加字距碎词("E x p a n d e d")的词边界在 pdf.js 合并 item 时已丢失,
// 无法可靠还原——保留原样,属上游启发式限制(issue #216 续批)。
const CJK_CHAR_CLASS = "\u3400-\u4DBF\u4E00-\u9FFF\uFA00-\uFAFF";

export function collapseCjkFakeSpaces(text) {
const run = new RegExp(`(?:[${CJK_CHAR_CLASS}] ){2,}[${CJK_CHAR_CLASS}]`, "g");
return String(text).replace(run, (match) => match.replaceAll(" ", ""));
}

async function loadPdfJs() {
if (typeof window !== "undefined") {
const pdfjs = await import("/vendor/pdfjs/pdf.min.mjs");
Expand Down Expand Up @@ -488,7 +505,7 @@ async function extractTextWithPdfJs(content) {
const items = (textContent.items || [])
.filter((item) => typeof item.str === "string" && item.str.length > 0)
.map((item) => ({
str: item.str,
str: collapseCjkFakeSpaces(item.str),
x: item.transform?.[4] ?? 0,
y: item.transform?.[5] ?? 0,
width: Number(item.width) || 0,
Expand All @@ -504,7 +521,7 @@ async function extractTextWithPdfJs(content) {
: "";
// P8-M4:同时收集 FixedLayoutModel 的 textRuns + page size,供 model.fixedLayout 使用。
const textRuns = items.map((item) => ({
text: item.str,
text: collapseCjkFakeSpaces(item.str),
bbox: { x: item.x, y: item.y, w: item.width, h: item.height },
fontName: item.fontName,
fontSize: item.height,
Expand Down
13 changes: 9 additions & 4 deletions public/landing-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ function svgIcon(name) {
function buildHero(host, stats) {
const wrapper = document.createElement("section");
wrapper.id = "hero";
// 注意:eyebrow 中的版本号需与 package.json 的 version 保持一致(当前 2.4.0)
wrapper.className = "landing-hero reveal-on-scroll";
wrapper.innerHTML = `
<div class="landing-hero-glow" aria-hidden="true"></div>
<div class="landing-hero-inner">
<span class="landing-hero-eyebrow">v2.3 · local-first 多格式转换工作台</span>
<span class="landing-hero-eyebrow">v2.4 · local-first 多格式转换工作台</span>
<h2 class="landing-hero-title">把文档跨格式转换变成<br/><span class="landing-hero-accent">可验证、可修复、可解释</span>的工程</h2>
<p class="landing-hero-sub">${stats.inputFormats} 种输入 × ${stats.outputFormats} 种输出 · ${stats.recommendedRoutes} 条推荐路径 · Repair Engine(2/7 动作已实现)· 处理阶段禁联网</p>
<p class="landing-hero-sub"><span class="keep-together">${stats.inputFormats} 种输入 × ${stats.outputFormats} 种输出</span> · <span class="keep-together">${stats.recommendedRoutes} 条推荐路径</span> · <span class="keep-together">Repair Engine(2/7 动作已实现)</span> · <span class="keep-together">处理阶段禁联网</span></p>
<div class="landing-hero-actions">
<button type="button" class="primary-button btn-gradient btn-lg" data-landing-cta>立即体验 ${svgIcon("arrow")}</button>
<a href="#formats" class="landing-cta-ghost">查看路径矩阵</a>
Expand Down Expand Up @@ -198,14 +199,18 @@ function buildCta(host) {

function attachRevealObserver(root) {
const targets = root.querySelectorAll(".reveal-on-scroll");
const revealAll = () => targets.forEach((el) => el.classList.add("is-revealed"));
if (window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
targets.forEach((el) => el.classList.add("is-revealed"));
revealAll();
return;
}
if (typeof IntersectionObserver === "undefined") {
targets.forEach((el) => el.classList.add("is-revealed"));
revealAll();
return;
}
// reveal-armed 门控:只有 observer 真正武装成功后,CSS 才允许隐藏未 reveal 的区块。
// 这样 fullPage 截图、打印或 JS 未执行的嵌入环境下,内容始终保持可见。
root.classList.add("reveal-armed");
const observer = new IntersectionObserver((entries) => {
for (const entry of entries) {
if (entry.isIntersecting) {
Expand Down
72 changes: 68 additions & 4 deletions public/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,11 @@ body[data-active-view="workbench"] .is-landing-only { display: none !important;
outline: none;
}

.compact-field select:hover,
.compact-field input:hover {
border-color: var(--border-strong);
}

.compact-field select:focus,
.compact-field input:focus,
#inputContent:focus,
Expand Down Expand Up @@ -584,6 +589,12 @@ body[data-active-view="workbench"] .is-landing-only { display: none !important;
cursor: not-allowed;
}

.ghost-button:active:not(:disabled):not(.disabled),
.mini-button:active:not(:disabled),
.menu-button:active {
transform: translateY(1px);
}

button:disabled {
cursor: not-allowed;
opacity: 0.62;
Expand Down Expand Up @@ -611,6 +622,14 @@ button:disabled {
color: var(--muted-strong);
font-size: 0.8rem;
font-weight: 800;
transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.auxiliary-actions > summary:hover,
.output-settings > summary:hover {
border-color: var(--accent);
background: var(--accent-soft);
color: var(--accent-strong);
}

.auxiliary-menu {
Expand Down Expand Up @@ -680,6 +699,7 @@ button:disabled {
min-width: 32px;
text-align: right;
font-variant-numeric: tabular-nums;
font-weight: 700;
color: var(--muted-strong);
}

Expand Down Expand Up @@ -721,7 +741,7 @@ button:disabled {
}

.progress-track {
height: 4px;
height: 6px;
overflow: hidden;
border-radius: 999px;
background: #e5e9ee;
Expand All @@ -731,7 +751,7 @@ button:disabled {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--accent);
background: linear-gradient(90deg, var(--accent), var(--accent-strong));
transition: width 0.18s ease;
}

Expand Down Expand Up @@ -767,6 +787,12 @@ button:disabled {
box-shadow: var(--shadow-soft);
}

/* 面板层次:外层工作面板投影略深于内层预览卡片 */
.source-pane,
.result-pane {
box-shadow: var(--shadow);
}

.source-pane {
align-self: stretch;
display: flex;
Expand Down Expand Up @@ -806,7 +832,7 @@ button:disabled {
padding: 14px 18px;
background: var(--surface-raised);
cursor: pointer;
transition: border-color 0.15s ease, background-color 0.15s ease;
transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.drop-zone:hover,
Expand All @@ -817,6 +843,12 @@ button:disabled {
box-shadow: 0 0 0 3px var(--focus);
}

.drop-zone:hover .upload-icon,
.drop-zone:focus-visible .upload-icon,
.drop-zone.is-active .upload-icon {
transform: scale(1.08);
}

.upload-icon {
display: grid;
place-items: center;
Expand All @@ -828,6 +860,7 @@ button:disabled {
color: var(--accent-strong);
font-size: 1.1rem;
font-weight: 900;
transition: transform 0.15s ease;
}

.drop-zone strong,
Expand Down Expand Up @@ -907,7 +940,9 @@ button:disabled {
}

.queue-empty {
padding: 14px 12px;
color: var(--muted);
text-align: center;
}

.queue-item {
Expand Down Expand Up @@ -998,6 +1033,11 @@ button:disabled {
line-height: 1.72;
}

#inputContent::placeholder,
#outputEditor::placeholder {
color: #9aa7b4;
}

#inputContent.is-binary-input {
min-height: 118px;
border-bottom: 1px solid var(--border);
Expand Down Expand Up @@ -1063,6 +1103,7 @@ button:disabled {
color: var(--muted-strong);
font-size: 0.8rem;
font-weight: 800;
transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.output-settings-panel {
Expand Down Expand Up @@ -1109,6 +1150,7 @@ button:disabled {
}

.tab-button {
position: relative;
min-width: 76px;
min-height: 44px;
border: 1px solid transparent;
Expand All @@ -1128,13 +1170,29 @@ button:disabled {
background: rgba(255, 255, 255, 0.6);
}

.tab-button:focus-visible {
outline: 3px solid var(--focus);
outline-offset: 2px;
}

.tab-button.is-active {
border-color: var(--border);
background: #ffffff;
color: var(--accent-strong);
box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.tab-button.is-active::after {
content: "";
position: absolute;
left: 14px;
right: 14px;
bottom: 4px;
height: 2px;
border-radius: 999px;
background: var(--accent);
}

.toggle-label {
display: inline-flex;
align-items: center;
Expand Down Expand Up @@ -1229,10 +1287,16 @@ button:disabled {

.preview-markdown:empty::before,
.text-output-preview:empty::before {
display: block;
display: grid;
place-items: center;
min-height: 200px;
border: 1.5px dashed var(--border-strong);
border-radius: var(--radius);
background: var(--surface-soft);
color: #94a3b8;
font-family: var(--font-ui);
font-size: 0.88rem;
text-align: center;
}

.preview-markdown:empty::before {
Expand Down
Loading
Loading