diff --git a/CHANGELOG.md b/CHANGELOG.md index 9149d95..a4d8713 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/development/DEVELOPMENT_TASKS.md b/docs/development/DEVELOPMENT_TASKS.md index 2ab85aa..cb47af4 100644 --- a/docs/development/DEVELOPMENT_TASKS.md +++ b/docs/development/DEVELOPMENT_TASKS.md @@ -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` 两条下划线正则加 `(?!_)` / `(? Math.max(1.5, height * 0.12); + return gap > Math.max(1.5, height * 0.22); } return false; } @@ -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"); @@ -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, @@ -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, @@ -1113,6 +1130,13 @@ export function readPdf({ content, title = "pdf", fileName = "", format = "pdf" // 加密识别(issue #104):payload 标志或结构探测;仅在毫无可信文本时启用文案 const encrypted = Boolean(pdfJsPayload?.encrypted) || (strings.length === 0 && isLikelyEncryptedPdf(source)); + // PDF.js 成功解析出页面、但整篇没有任何文本 run:典型扫描件/图片型 PDF + // (也可能全为空白页)。与核心解析器的"二进制噪声不可信"区分开——后者意味着 + // 解析失败,前者意味着文档根本没有文本层,UI 应引导 OCR 而非报"不可读"。 + const payloadPageNumbers = (Array.isArray(pdfJsPayload?.pages) ? pdfJsPayload.pages : []) + .map((page) => page?.pageNumber) + .filter((number) => Number.isSafeInteger(number) && number > 0); + const pdfJsParsedButTextless = !encrypted && strings.length === 0 && payloadPageNumbers.length > 0; const blocks = []; if (strings.length > 0) { blocks.push(createHeading(1, strings[0])); @@ -1130,6 +1154,13 @@ export function readPdf({ content, title = "pdf", fileName = "", format = "pdf" "PDF_ENCRYPTED", "PDF is password-protected; text extraction requires the password and was skipped." )); + } else if (pdfJsParsedButTextless) { + warnings.push(createWarning( + "unsupported", + "PDF_NO_TEXT_RUNS", + `PDF.js parsed ${payloadPageNumbers.length} page(s) but none contain extractable text runs; the document is likely scanned or image-only (or the pages are blank). Convert with OCR enabled to recover editable text.`, + { pageCount: payloadPageNumbers.length, pagesWithoutText: payloadPageNumbers, ocrRecommended: true } + )); } else { warnings.push(createWarning( "unsupported", @@ -1148,7 +1179,13 @@ export function readPdf({ content, title = "pdf", fileName = "", format = "pdf" metadata: withWarnings({ pdf: { extraction: pdfJsPayload - ? "pdfjs-text-content" + ? strings.length > 0 + ? "pdfjs-text-content" + : encrypted + ? "no-text-encrypted" + : pdfJsParsedButTextless + ? "pdfjs-no-text" + : "pdfjs-text-content" : strings.length > 0 ? "literal-text-operators" : encrypted @@ -1160,6 +1197,7 @@ export function readPdf({ content, title = "pdf", fileName = "", format = "pdf" engine: pdfJsPayload?.engine || "core-mvp", textItemCount: strings.length, pageCount: pdfJsPayload?.pages?.length || undefined, + ...(pdfJsParsedButTextless ? { pagesWithoutText: payloadPageNumbers } : {}), ...(encrypted ? { encrypted: true } : {}), fileName, }, diff --git a/public/landing-view.js b/public/landing-view.js index 85ce108..64509b1 100644 --- a/public/landing-view.js +++ b/public/landing-view.js @@ -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 = `
- v2.3 · local-first 多格式转换工作台 + v2.4 · local-first 多格式转换工作台

把文档跨格式转换变成
可验证、可修复、可解释的工程

-

${stats.inputFormats} 种输入 × ${stats.outputFormats} 种输出 · ${stats.recommendedRoutes} 条推荐路径 · Repair Engine(2/7 动作已实现)· 处理阶段禁联网

+

${stats.inputFormats} 种输入 × ${stats.outputFormats} 种输出 · ${stats.recommendedRoutes} 条推荐路径 · Repair Engine(2/7 动作已实现) · 处理阶段禁联网

查看路径矩阵 @@ -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) { diff --git a/public/styles.css b/public/styles.css index cad8076..4ad6616 100644 --- a/public/styles.css +++ b/public/styles.css @@ -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, @@ -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; @@ -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 { @@ -680,6 +699,7 @@ button:disabled { min-width: 32px; text-align: right; font-variant-numeric: tabular-nums; + font-weight: 700; color: var(--muted-strong); } @@ -721,7 +741,7 @@ button:disabled { } .progress-track { - height: 4px; + height: 6px; overflow: hidden; border-radius: 999px; background: #e5e9ee; @@ -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; } @@ -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; @@ -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, @@ -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; @@ -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, @@ -907,7 +940,9 @@ button:disabled { } .queue-empty { + padding: 14px 12px; color: var(--muted); + text-align: center; } .queue-item { @@ -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); @@ -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 { @@ -1109,6 +1150,7 @@ button:disabled { } .tab-button { + position: relative; min-width: 76px; min-height: 44px; border: 1px solid transparent; @@ -1128,6 +1170,11 @@ 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; @@ -1135,6 +1182,17 @@ button:disabled { 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; @@ -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 { diff --git a/public/styles/landing.css b/public/styles/landing.css index 23bfba2..e41ebb4 100644 --- a/public/styles/landing.css +++ b/public/styles/landing.css @@ -13,13 +13,13 @@ } .landing-section { - padding: 80px 24px; + padding: calc(var(--space-8) * 2) var(--space-6); max-width: 1200px; margin: 0 auto; } .landing-section-heading { - margin-bottom: 40px; + margin-bottom: var(--space-8); max-width: 720px; } @@ -41,6 +41,7 @@ font-size: var(--text-3xl); line-height: 1.2; font-weight: 700; + letter-spacing: -0.01em; color: var(--text); } @@ -61,7 +62,8 @@ /* Hero ----------------------------------------------------------- */ .landing-hero { position: relative; - padding: 96px 24px 64px; + /* 垂直节奏收紧:96/64 → 72/48,视觉重心上移,首屏留白减少 */ + padding: calc(var(--space-8) * 2.25) var(--space-6) calc(var(--space-8) * 1.5); max-width: 1200px; margin: 0 auto; overflow: hidden; @@ -97,7 +99,7 @@ font-size: var(--text-sm); font-weight: 600; letter-spacing: 0.05em; - margin-bottom: var(--space-6); + margin-bottom: var(--space-4); } .landing-hero-title { @@ -122,11 +124,17 @@ } .landing-hero-sub { - margin: var(--space-6) 0 var(--space-8); + margin: var(--space-5) 0 var(--space-6); font-size: var(--text-lg); line-height: 1.7; color: var(--muted-strong); max-width: 720px; + text-wrap: balance; +} + +/* 副标题按语义分组整体换行,避免「处理阶段禁联网」被拆开留下单字孤行 */ +.landing-hero-sub .keep-together { + white-space: nowrap; } .landing-hero-actions { @@ -134,7 +142,7 @@ flex-wrap: wrap; gap: var(--space-3); align-items: center; - margin-bottom: var(--space-8); + margin-bottom: var(--space-6); } @@ -180,6 +188,12 @@ font-size: var(--text-xs); font-weight: 500; backdrop-filter: blur(8px); + transition: border-color var(--duration-fast) ease, background var(--duration-fast) ease; +} + +.landing-hero-badges li:hover { + border-color: rgba(15, 118, 110, 0.42); + background: rgba(255, 255, 255, 0.92); } /* Features -------------------------------------------------------- */ @@ -205,6 +219,11 @@ border-color: rgba(15, 118, 110, 0.45); } +.landing-feature-card:hover .landing-feature-icon { + transform: translateY(-2px); + background: linear-gradient(135deg, rgba(13, 148, 136, 0.22), rgba(56, 189, 248, 0.26)); +} + .landing-feature-icon { display: inline-flex; align-items: center; @@ -215,6 +234,7 @@ background: linear-gradient(135deg, rgba(13, 148, 136, 0.14), rgba(56, 189, 248, 0.18)); color: var(--accent-strong); margin-bottom: var(--space-4); + transition: transform var(--duration-base) ease, background var(--duration-base) ease; } .landing-feature-card h4 { @@ -247,12 +267,14 @@ border-radius: var(--radius-lg); background: rgba(255, 255, 255, 0.9); border: 1px solid rgba(148, 163, 184, 0.22); - transition: background var(--duration-base) ease, border-color var(--duration-base) ease; + transition: background var(--duration-base) ease, border-color var(--duration-base) ease, box-shadow var(--duration-base) ease, transform var(--duration-base) ease; } .landing-format-row:hover { background: #ffffff; border-color: rgba(15, 118, 110, 0.35); + box-shadow: 0 12px 30px -22px rgba(15, 118, 110, 0.4); + transform: translateY(-1px); } .landing-format-input { @@ -325,6 +347,13 @@ border-radius: var(--radius-lg); background: rgba(255, 255, 255, 0.92); border: 1px solid rgba(148, 163, 184, 0.22); + transition: transform var(--duration-base) ease, box-shadow var(--duration-base) ease, border-color var(--duration-base) ease; +} + +.landing-workflow-step:hover { + transform: translateY(-2px); + border-color: rgba(15, 118, 110, 0.35); + box-shadow: 0 14px 30px -24px rgba(15, 118, 110, 0.4); } .landing-workflow-index { @@ -356,14 +385,26 @@ /* CTA ------------------------------------------------------------- */ .landing-cta { + position: relative; + overflow: hidden; text-align: center; - padding: 80px 24px 96px; + padding: calc(var(--space-8) * 2) var(--space-6) calc(var(--space-8) * 2.5); background: linear-gradient(180deg, rgba(15, 118, 110, 0.05) 0%, rgba(15, 118, 110, 0.12) 100%); + border: 1px solid rgba(15, 118, 110, 0.16); border-radius: var(--radius-xl); - margin: 40px auto 80px; + margin: var(--space-8) auto calc(var(--space-8) * 2); max-width: 1100px; } +/* 顶部品牌渐变条,与主按钮共用同一渐变 token */ +.landing-cta::before { + content: ""; + position: absolute; + inset: 0 0 auto; + height: 3px; + background: var(--btn-gradient-primary); +} + .landing-cta h3 { margin: 0 0 var(--space-3); font-size: var(--text-2xl); @@ -380,10 +421,16 @@ /* Scroll reveal --------------------------------------------------- */ +/* reveal-armed 门控:只有 JS 成功武装 IntersectionObserver 后, + 未 reveal 的区块才会被隐藏;fullPage 截图、打印、JS 未执行等 + 场景下所有内容默认可见。 */ .reveal-on-scroll { + transition: opacity var(--duration-slow) ease, transform var(--duration-slow) ease; +} + +.reveal-armed .reveal-on-scroll:not(.is-revealed) { opacity: 0; transform: translateY(16px); - transition: opacity 0.6s ease, transform 0.6s ease; } .reveal-on-scroll.is-revealed { @@ -391,6 +438,14 @@ transform: translateY(0); } +@media print { + .reveal-armed .reveal-on-scroll:not(.is-revealed) { + opacity: 1; + transform: none; + transition: none; + } +} + /* Animations ------------------------------------------------------ */ @keyframes landingGradientShift { 0% { background-position: 0% 50%; } @@ -409,17 +464,27 @@ animation: none !important; transition: none !important; } + .reveal-armed .reveal-on-scroll, .reveal-on-scroll { - opacity: 1; - transform: none; + opacity: 1 !important; + transform: none !important; } } /* Responsive ------------------------------------------------------ */ @media (max-width: 820px) { - .landing-section { padding: 56px 18px; } - .landing-hero { padding: 72px 18px 48px; } + .landing-section { padding: calc(var(--space-8) * 1.5) var(--space-4); } + .landing-hero { padding: calc(var(--space-8) * 1.75) var(--space-4) calc(var(--space-8) * 1.25); } .landing-section-heading h3 { font-size: 26px; } - .landing-format-row { grid-template-columns: 1fr; gap: 10px; } - .landing-cta { margin: 24px 12px 60px; padding: 56px 18px 64px; } + .landing-format-row { grid-template-columns: 1fr; gap: var(--space-2); } + .landing-cta { + margin: var(--space-6) var(--space-3) calc(var(--space-8) * 1.75); + padding: calc(var(--space-8) * 1.5) var(--space-4) calc(var(--space-8) * 1.75); + } +} + +/* 锚点跳转(如「查看路径矩阵」)时给目标区块留出顶部呼吸空间 */ +.landing-section, +.landing-hero { + scroll-margin-top: var(--space-4); } diff --git a/public/styles/preview.css b/public/styles/preview.css index b0c76d2..72aae7b 100644 --- a/public/styles/preview.css +++ b/public/styles/preview.css @@ -114,6 +114,29 @@ color: #cbd5e1; } +/* Primary actions — 暗色顶栏/空状态下保持品牌渐变与对比度 */ +.preview-tool-button.btn-gradient { + background: var(--btn-gradient-primary); + color: #ffffff; + font-weight: 600; +} + +.preview-tool-button.btn-gradient:hover:not(:disabled) { + background: var(--btn-gradient-primary); + filter: brightness(1.08); + box-shadow: 0 6px 18px rgba(13, 148, 136, 0.4); +} + +.preview-tool-button.btn-gradient:focus-visible, +.preview-empty .btn-gradient:focus-visible { + outline: 3px solid var(--focus); + outline-offset: 2px; +} + +.preview-empty .btn-gradient { + background: var(--btn-gradient-primary); +} + .preview-stage { display: flex; align-items: stretch; diff --git a/scripts/layout-offset-regression-test.js b/scripts/layout-offset-regression-test.js index fdb67a5..359c966 100644 --- a/scripts/layout-offset-regression-test.js +++ b/scripts/layout-offset-regression-test.js @@ -1,6 +1,6 @@ import assert from "node:assert/strict"; -import { analyzePageLayout } from "../public/formats/pdf.js"; +import { analyzePageLayout, collapseCjkFakeSpaces } from "../public/formats/pdf.js"; import { readText, writeText } from "../public/formats/plain-text.js"; import { readDocx } from "../public/formats/docx.js"; import { writeDocx } from "../public/formats/docx-output.js"; @@ -32,6 +32,25 @@ const measuredEnglish = analyzePageLayout([ ]); assert.equal(measuredEnglish.map((block) => block.text).join(" "), "North Star"); +// Letter-spaced glyphs (expanded tracking, ~0.18em gaps) must not be split into +// space-separated letters: only a real word-space-width gap inserts a space. +const trackingItems = []; +let trackingX = 60; +for (const ch of "Expanded") { + trackingItems.push({ str: ch, x: trackingX, y: 500, width: 6, height: 11, hasPosition: true, hasHorizontalGeometry: true }); + trackingX += 8; // 6pt glyph advance + 2pt tracking (0.18em) +} +const trackingBlocks = analyzePageLayout(trackingItems); +assert.equal(trackingBlocks[0].text, "Expanded"); + +// pdf.js inserts fake ASCII spaces for 0.102em-0.6em inter-glyph gaps, shredding +// letter-spaced CJK into "加 字 距 版"; chains of >=3 single CJK chars joined by +// single spaces are always fake tracking and must be collapsed, while a single +// space between multi-char CJK words (form alignment, e.g. "逐词 绘制") is kept. +assert.equal(collapseCjkFakeSpaces("加 字 距 版"), "加字距版"); +assert.equal(collapseCjkFakeSpaces("逐词 绘制"), "逐词 绘制"); +assert.equal(collapseCjkFakeSpaces("Normal spacing line"), "Normal spacing line"); + // A repeated two-column page is read down the left column, then down the right. const columnItems = [ ["Account ID", "ACCT-102"],