@li-canghai/dsh-paper 0.8.3 → 0.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client-parts/01-pure-helpers.js +93 -2
- package/lib/client.js +543 -187
- package/lib/pdf-page.js +95 -13
- package/package.json +2 -2
|
@@ -2655,9 +2655,100 @@
|
|
|
2655
2655
|
// 写不进去就算了:下次打开退回默认值,不该为此打断阅读。
|
|
2656
2656
|
}
|
|
2657
2657
|
}
|
|
2658
|
-
/**
|
|
2658
|
+
/**
|
|
2659
|
+
* 字体族清单。**按语言分开两份**(用户裁定:原文是英文,不该被中文字体名接管)。
|
|
2660
|
+
*
|
|
2661
|
+
* 🔴 为什么要分:界面上那三个按钮改的是**当前档位**那一套排版,而双语/并排档里
|
|
2662
|
+
* 原文段与译文段同时在场。共用一份清单时,中文档选的「宋体」会原样落到英文段上 ——
|
|
2663
|
+
* 宋体没有拉丁字形,浏览器只能回退,读者的选择于是看起来「没生效」。
|
|
2664
|
+
*
|
|
2665
|
+
* 🔴 「系统默认」是**栈本身**为空,不是名字叫 'system-ui':空栈表示不写 font-family,
|
|
2666
|
+
* 由浏览器用自己那套默认字体渲染(Chrome 在中文 Windows 上是宋体 / 雅黑)。
|
|
2667
|
+
* 写死 system-ui 反而会剥夺用户改浏览器默认字体的能力,那是另一回事。
|
|
2668
|
+
*
|
|
2669
|
+
* 固定清单,不给自由输入 —— 允许任意字符串等于允许读者把正文变成豆腐块,
|
|
2670
|
+
* 而浏览器又不提供"列出系统字体"的接口(字体枚举要用户授权且各浏览器行为不一)。
|
|
2671
|
+
*/
|
|
2672
|
+
const SRC_FONT_FAMILIES = Object.freeze([
|
|
2673
|
+
Object.freeze({ value: 'system', label: '系统默认', stack: '' }),
|
|
2674
|
+
Object.freeze({ value: 'serif', label: '衬线', stack: "Georgia,'Times New Roman',Times,'Source Serif Pro',Charter,serif" }),
|
|
2675
|
+
Object.freeze({ value: 'sans', label: '无衬线', stack: "'Helvetica Neue',Helvetica,Arial,'Segoe UI',system-ui,sans-serif" }),
|
|
2676
|
+
Object.freeze({ value: 'mono', label: '等宽', stack: "'JetBrains Mono','SF Mono',Consolas,'Liberation Mono',Menlo,monospace" }),
|
|
2677
|
+
Object.freeze({ value: 'kai', label: '手写', stack: "'Iowan Old Style',Charter,'Segoe Print','Bradley Hand',cursive" }),
|
|
2678
|
+
])
|
|
2679
|
+
const ZH_FONT_FAMILIES = Object.freeze([
|
|
2680
|
+
Object.freeze({ value: 'system', label: '系统默认', stack: '' }),
|
|
2681
|
+
Object.freeze({ value: 'serif', label: '宋体', stack: "'Noto Serif SC','Source Han Serif SC','Songti SC',SimSun,Georgia,serif" }),
|
|
2682
|
+
Object.freeze({ value: 'sans', label: '黑体', stack: "'Noto Sans SC','Source Han Sans SC','PingFang SC','Microsoft YaHei',system-ui,sans-serif" }),
|
|
2683
|
+
// ⚠️ 楷体在 Windows 上的注册名是 STKaiti(simkai.ttf 实际注册的族名),
|
|
2684
|
+
// 'Kaiti SC' 是 macOS 的写法;两个都列,再补中文名兜底。
|
|
2685
|
+
Object.freeze({ value: 'kai', label: '楷体', stack: "'Kaiti SC','STKaiti',KaiTi,'楷体','Noto Serif SC',serif" }),
|
|
2686
|
+
])
|
|
2687
|
+
/** 某一侧的字体清单。side 是 'src' / 'zh'。 */
|
|
2688
|
+
function fontFamiliesOf(side) {
|
|
2689
|
+
return side === 'src' ? SRC_FONT_FAMILIES : ZH_FONT_FAMILIES
|
|
2690
|
+
}
|
|
2691
|
+
/**
|
|
2692
|
+
* 把存下来的 family 解析成某一侧真正要用的栈。**每侧各用各的清单**:
|
|
2693
|
+
* 旧数据里译文存的 'serif' 拿到原文那侧仍然叫 'serif',但栈换成了拉丁字体。
|
|
2694
|
+
* 认不出的值回落该侧的第一项(系统默认)—— 与"缺字段回默认"同一口径。
|
|
2695
|
+
*/
|
|
2696
|
+
function fontStackOf(side, value) {
|
|
2697
|
+
const list = fontFamiliesOf(side)
|
|
2698
|
+
const entry = list.find(item => item.value === value)
|
|
2699
|
+
return (entry === undefined ? list[0] : entry).stack
|
|
2700
|
+
}
|
|
2701
|
+
/** 字体族取值校验。认不出的回落该侧的默认档 —— 每侧清单不同,校验也要按侧来。 */
|
|
2702
|
+
function fontOf(side, value) {
|
|
2703
|
+
return fontFamiliesOf(side).some(entry => entry.value === value) ? value : fontFamiliesOf(side)[0].value
|
|
2704
|
+
}
|
|
2705
|
+
|
|
2706
|
+
/**
|
|
2707
|
+
* 排版偏好(字号 / 行距 / 字体族),**原文与译文各一套**。
|
|
2708
|
+
*
|
|
2709
|
+
* 🔴 **全局一份、不按论文分**(D152 原意不变):它答的是"我习惯怎么读",不是"这一篇怎么看"。
|
|
2710
|
+
*
|
|
2711
|
+
* 🔴 **旧格式要能读**。拆包之前存的是 `{ size, height }`(只有一套),读者机器上可能就躺着
|
|
2712
|
+
* 这么一个对象。读成"译文那套",原文整组用默认值 —— 升级不丢读者已经调好的字号。
|
|
2713
|
+
* 反过来说:把旧字段直接丢弃、整块回落默认,等于悄悄把人家调了半天的字号重置掉。
|
|
2714
|
+
*
|
|
2715
|
+
* @returns {{src: {size: number, height: number, family: string}, zh: {size: number, height: number, family: string}}}
|
|
2716
|
+
*/
|
|
2659
2717
|
function readTypePref() { return readPref(TYPE_PREF_KEY) }
|
|
2660
|
-
function
|
|
2718
|
+
function typePref() {
|
|
2719
|
+
const raw = readTypePref()
|
|
2720
|
+
const pick = (side, group, fallback) => {
|
|
2721
|
+
const source = group !== null && typeof group === 'object' ? group : null
|
|
2722
|
+
// 旧格式没有 src/zh 分组,size/height 直接躺在顶层。
|
|
2723
|
+
const legacy = source === null && fallback === 'legacy' ? raw : null
|
|
2724
|
+
const sizeOf = value => clampType(value, MIN_FONT_SIZE, MAX_FONT_SIZE, DEFAULT_FONT_SIZE)
|
|
2725
|
+
const heightOf = value => clampType(value, MIN_LINE_HEIGHT, MAX_LINE_HEIGHT, DEFAULT_LINE_HEIGHT)
|
|
2726
|
+
if (legacy !== null) {
|
|
2727
|
+
// 旧数据没有 family 字段。原文那侧回「系统默认」,译文那侧回宋体 ——
|
|
2728
|
+
// 两侧清单不同,同一个字面量在两边指向的不是同一套字体。
|
|
2729
|
+
return { size: sizeOf(legacy.size), height: heightOf(legacy.height), family: side === 'src' ? 'system' : 'serif' }
|
|
2730
|
+
}
|
|
2731
|
+
return {
|
|
2732
|
+
size: sizeOf(source?.size),
|
|
2733
|
+
height: heightOf(source?.height),
|
|
2734
|
+
family: fontOf(side, source?.family),
|
|
2735
|
+
}
|
|
2736
|
+
}
|
|
2737
|
+
return {
|
|
2738
|
+
src: pick('src', raw?.src, 'default'),
|
|
2739
|
+
// 🔴 顶层旧字段只喂给译文那套:它是拆包前唯一存在的那一套。
|
|
2740
|
+
zh: pick('zh', raw?.zh, 'legacy'),
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
/**
|
|
2744
|
+
* 写一套排版偏好。
|
|
2745
|
+
*
|
|
2746
|
+
* 🔴 **每次都要写全**,不能只写改动的那一组:`writePref` 是整键覆盖,
|
|
2747
|
+
* 只写 `{zh}` 会把 `src` 从磁盘上抹掉 —— 读者改完译文再刷新,原文那套就没了。
|
|
2748
|
+
*
|
|
2749
|
+
* @param {object} next 完整的三组值。
|
|
2750
|
+
*/
|
|
2751
|
+
function writeTypePref(next) { writePref(TYPE_PREF_KEY, next) }
|
|
2661
2752
|
/**
|
|
2662
2753
|
* 视图档位的取值校验(D152)。只认下拉里真有的档 —— 手改过的 localStorage 不该让选择框
|
|
2663
2754
|
* 落在一个不存在的值上(那时正文按 zh 渲染、选择框却显示别的,看着像「设置没生效」)。
|
package/lib/client.js
CHANGED
|
@@ -144,7 +144,9 @@ function createLibraryModel() {
|
|
|
144
144
|
// 正文富渲染用宿主自带的 MarkdownText(micromark + KaTeX:GFM 表格/列表/围栏代码、
|
|
145
145
|
// 行内 $…$ 与行间 $$…$$ 公式)。该包在 PLATFORM_MODULES 里,取法与 react 完全一样,
|
|
146
146
|
// 所以客户端半不引任何第三方依赖、不加构建步骤。
|
|
147
|
-
|
|
147
|
+
// 下拉一律用宿主 primitives 的 Menu(见 selectControlOf 的说明),与 MarkdownText 同一个
|
|
148
|
+
// PLATFORM_MODULES 模块,取法完全一样:客户端半不引第三方依赖、不加构建步骤。
|
|
149
|
+
const { MarkdownText, Menu, MenuItemButton } = require('@deepseek-ai/dsh-client-ui-primitives')
|
|
148
150
|
|
|
149
151
|
// BEGIN CLIENT PARTS
|
|
150
152
|
// 侧栏标题下的 MinerU 状态文案。三态:还没拿到 /state 时说"检查中",拿到后只看
|
|
@@ -2804,9 +2806,100 @@ function createLibraryModel() {
|
|
|
2804
2806
|
// 写不进去就算了:下次打开退回默认值,不该为此打断阅读。
|
|
2805
2807
|
}
|
|
2806
2808
|
}
|
|
2807
|
-
/**
|
|
2809
|
+
/**
|
|
2810
|
+
* 字体族清单。**按语言分开两份**(用户裁定:原文是英文,不该被中文字体名接管)。
|
|
2811
|
+
*
|
|
2812
|
+
* 🔴 为什么要分:界面上那三个按钮改的是**当前档位**那一套排版,而双语/并排档里
|
|
2813
|
+
* 原文段与译文段同时在场。共用一份清单时,中文档选的「宋体」会原样落到英文段上 ——
|
|
2814
|
+
* 宋体没有拉丁字形,浏览器只能回退,读者的选择于是看起来「没生效」。
|
|
2815
|
+
*
|
|
2816
|
+
* 🔴 「系统默认」是**栈本身**为空,不是名字叫 'system-ui':空栈表示不写 font-family,
|
|
2817
|
+
* 由浏览器用自己那套默认字体渲染(Chrome 在中文 Windows 上是宋体 / 雅黑)。
|
|
2818
|
+
* 写死 system-ui 反而会剥夺用户改浏览器默认字体的能力,那是另一回事。
|
|
2819
|
+
*
|
|
2820
|
+
* 固定清单,不给自由输入 —— 允许任意字符串等于允许读者把正文变成豆腐块,
|
|
2821
|
+
* 而浏览器又不提供"列出系统字体"的接口(字体枚举要用户授权且各浏览器行为不一)。
|
|
2822
|
+
*/
|
|
2823
|
+
const SRC_FONT_FAMILIES = Object.freeze([
|
|
2824
|
+
Object.freeze({ value: 'system', label: '系统默认', stack: '' }),
|
|
2825
|
+
Object.freeze({ value: 'serif', label: '衬线', stack: "Georgia,'Times New Roman',Times,'Source Serif Pro',Charter,serif" }),
|
|
2826
|
+
Object.freeze({ value: 'sans', label: '无衬线', stack: "'Helvetica Neue',Helvetica,Arial,'Segoe UI',system-ui,sans-serif" }),
|
|
2827
|
+
Object.freeze({ value: 'mono', label: '等宽', stack: "'JetBrains Mono','SF Mono',Consolas,'Liberation Mono',Menlo,monospace" }),
|
|
2828
|
+
Object.freeze({ value: 'kai', label: '手写', stack: "'Iowan Old Style',Charter,'Segoe Print','Bradley Hand',cursive" }),
|
|
2829
|
+
])
|
|
2830
|
+
const ZH_FONT_FAMILIES = Object.freeze([
|
|
2831
|
+
Object.freeze({ value: 'system', label: '系统默认', stack: '' }),
|
|
2832
|
+
Object.freeze({ value: 'serif', label: '宋体', stack: "'Noto Serif SC','Source Han Serif SC','Songti SC',SimSun,Georgia,serif" }),
|
|
2833
|
+
Object.freeze({ value: 'sans', label: '黑体', stack: "'Noto Sans SC','Source Han Sans SC','PingFang SC','Microsoft YaHei',system-ui,sans-serif" }),
|
|
2834
|
+
// ⚠️ 楷体在 Windows 上的注册名是 STKaiti(simkai.ttf 实际注册的族名),
|
|
2835
|
+
// 'Kaiti SC' 是 macOS 的写法;两个都列,再补中文名兜底。
|
|
2836
|
+
Object.freeze({ value: 'kai', label: '楷体', stack: "'Kaiti SC','STKaiti',KaiTi,'楷体','Noto Serif SC',serif" }),
|
|
2837
|
+
])
|
|
2838
|
+
/** 某一侧的字体清单。side 是 'src' / 'zh'。 */
|
|
2839
|
+
function fontFamiliesOf(side) {
|
|
2840
|
+
return side === 'src' ? SRC_FONT_FAMILIES : ZH_FONT_FAMILIES
|
|
2841
|
+
}
|
|
2842
|
+
/**
|
|
2843
|
+
* 把存下来的 family 解析成某一侧真正要用的栈。**每侧各用各的清单**:
|
|
2844
|
+
* 旧数据里译文存的 'serif' 拿到原文那侧仍然叫 'serif',但栈换成了拉丁字体。
|
|
2845
|
+
* 认不出的值回落该侧的第一项(系统默认)—— 与"缺字段回默认"同一口径。
|
|
2846
|
+
*/
|
|
2847
|
+
function fontStackOf(side, value) {
|
|
2848
|
+
const list = fontFamiliesOf(side)
|
|
2849
|
+
const entry = list.find(item => item.value === value)
|
|
2850
|
+
return (entry === undefined ? list[0] : entry).stack
|
|
2851
|
+
}
|
|
2852
|
+
/** 字体族取值校验。认不出的回落该侧的默认档 —— 每侧清单不同,校验也要按侧来。 */
|
|
2853
|
+
function fontOf(side, value) {
|
|
2854
|
+
return fontFamiliesOf(side).some(entry => entry.value === value) ? value : fontFamiliesOf(side)[0].value
|
|
2855
|
+
}
|
|
2856
|
+
|
|
2857
|
+
/**
|
|
2858
|
+
* 排版偏好(字号 / 行距 / 字体族),**原文与译文各一套**。
|
|
2859
|
+
*
|
|
2860
|
+
* 🔴 **全局一份、不按论文分**(D152 原意不变):它答的是"我习惯怎么读",不是"这一篇怎么看"。
|
|
2861
|
+
*
|
|
2862
|
+
* 🔴 **旧格式要能读**。拆包之前存的是 `{ size, height }`(只有一套),读者机器上可能就躺着
|
|
2863
|
+
* 这么一个对象。读成"译文那套",原文整组用默认值 —— 升级不丢读者已经调好的字号。
|
|
2864
|
+
* 反过来说:把旧字段直接丢弃、整块回落默认,等于悄悄把人家调了半天的字号重置掉。
|
|
2865
|
+
*
|
|
2866
|
+
* @returns {{src: {size: number, height: number, family: string}, zh: {size: number, height: number, family: string}}}
|
|
2867
|
+
*/
|
|
2808
2868
|
function readTypePref() { return readPref(TYPE_PREF_KEY) }
|
|
2809
|
-
function
|
|
2869
|
+
function typePref() {
|
|
2870
|
+
const raw = readTypePref()
|
|
2871
|
+
const pick = (side, group, fallback) => {
|
|
2872
|
+
const source = group !== null && typeof group === 'object' ? group : null
|
|
2873
|
+
// 旧格式没有 src/zh 分组,size/height 直接躺在顶层。
|
|
2874
|
+
const legacy = source === null && fallback === 'legacy' ? raw : null
|
|
2875
|
+
const sizeOf = value => clampType(value, MIN_FONT_SIZE, MAX_FONT_SIZE, DEFAULT_FONT_SIZE)
|
|
2876
|
+
const heightOf = value => clampType(value, MIN_LINE_HEIGHT, MAX_LINE_HEIGHT, DEFAULT_LINE_HEIGHT)
|
|
2877
|
+
if (legacy !== null) {
|
|
2878
|
+
// 旧数据没有 family 字段。原文那侧回「系统默认」,译文那侧回宋体 ——
|
|
2879
|
+
// 两侧清单不同,同一个字面量在两边指向的不是同一套字体。
|
|
2880
|
+
return { size: sizeOf(legacy.size), height: heightOf(legacy.height), family: side === 'src' ? 'system' : 'serif' }
|
|
2881
|
+
}
|
|
2882
|
+
return {
|
|
2883
|
+
size: sizeOf(source?.size),
|
|
2884
|
+
height: heightOf(source?.height),
|
|
2885
|
+
family: fontOf(side, source?.family),
|
|
2886
|
+
}
|
|
2887
|
+
}
|
|
2888
|
+
return {
|
|
2889
|
+
src: pick('src', raw?.src, 'default'),
|
|
2890
|
+
// 🔴 顶层旧字段只喂给译文那套:它是拆包前唯一存在的那一套。
|
|
2891
|
+
zh: pick('zh', raw?.zh, 'legacy'),
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
/**
|
|
2895
|
+
* 写一套排版偏好。
|
|
2896
|
+
*
|
|
2897
|
+
* 🔴 **每次都要写全**,不能只写改动的那一组:`writePref` 是整键覆盖,
|
|
2898
|
+
* 只写 `{zh}` 会把 `src` 从磁盘上抹掉 —— 读者改完译文再刷新,原文那套就没了。
|
|
2899
|
+
*
|
|
2900
|
+
* @param {object} next 完整的三组值。
|
|
2901
|
+
*/
|
|
2902
|
+
function writeTypePref(next) { writePref(TYPE_PREF_KEY, next) }
|
|
2810
2903
|
/**
|
|
2811
2904
|
* 视图档位的取值校验(D152)。只认下拉里真有的档 —— 手改过的 localStorage 不该让选择框
|
|
2812
2905
|
* 落在一个不存在的值上(那时正文按 zh 渲染、选择框却显示别的,看着像「设置没生效」)。
|
|
@@ -3753,6 +3846,33 @@ button.paper-select>span{min-width:0;overflow:hidden;text-overflow:ellipsis;whit
|
|
|
3753
3846
|
.paper-reader-inject{flex:0 0 auto;padding:5px 8px}
|
|
3754
3847
|
.paper-reader-dual{flex:0 0 auto;padding:5px 8px}
|
|
3755
3848
|
.paper-reader-head .paper-seg .paper-btn{padding:5px 8px}
|
|
3849
|
+
/* ---- 顶栏三个排版按钮(D195)----
|
|
3850
|
+
位置:阅读视图分段控件的右边(读者裁定「就笔记的右边」)。
|
|
3851
|
+
🔴 三个都是 flex:0 0 auto:分段控件自己带 overflow-x:auto,挤的时候由它让位,
|
|
3852
|
+
排版按钮绝不能被压扁或者掉到第二行 —— 它们显示的是当前值,压扁就读不出来了。 */
|
|
3853
|
+
/* 三个按钮 + 它们的弹层包在一个 holder 里。holder 自己**不定位**(不设 position),
|
|
3854
|
+
只吃顶栏的 flex 排布;弹层的包含块因此是 .paper-reader-head(它带 position:relative)。
|
|
3855
|
+
🔴 这正是拿掉 per-button 定位的理由,见 typePopover 的注释。 */
|
|
3856
|
+
.paper-type-row-holder{display:flex;align-items:center;gap:8px;flex:0 0 auto;min-width:0}
|
|
3857
|
+
.paper-type-trigger{display:inline-flex;align-items:center;gap:4px;padding:5px 8px;flex:0 0 auto}
|
|
3858
|
+
.paper-type-glyph{font-size:10px;font-weight:700;opacity:.62;letter-spacing:.02em}
|
|
3859
|
+
/* 弹层:铺满顶栏整行的宽度,永远在容器内。
|
|
3860
|
+
🔴 不用固定像素宽度 —— 侧栏最窄 300px,220px 的弹层挂在任何一个按钮上都有一端溢出
|
|
3861
|
+
(锚左沿则最右那个越界,锚右沿则最左那个越界,用户实测「都看不到了」)。
|
|
3862
|
+
left/right 都归零就与容器同宽,多窄都完整可见。 */
|
|
3863
|
+
.paper-type-pop{position:absolute;top:calc(100% - 2px);left:0;right:0;z-index:var(--paper-layer-sticky);
|
|
3864
|
+
padding:10px;border:1px solid var(--paper-border);border-radius:10px;
|
|
3865
|
+
background:var(--paper-card);box-shadow:0 8px 24px rgba(0,0,0,.18)}
|
|
3866
|
+
/* 弹层里的行:标签定宽、控件吃满剩余。行距/字号的数值回显右对齐,改的时候不跳。 */
|
|
3867
|
+
.paper-type-row{display:flex;align-items:center;gap:8px;font-size:12px;color:var(--paper-muted);margin:0}
|
|
3868
|
+
.paper-type-row>span:first-child{flex:0 0 32px}
|
|
3869
|
+
.paper-type-row input[type=range]{flex:1;min-width:0}
|
|
3870
|
+
.paper-type-value{flex:0 0 34px;text-align:right;color:var(--paper-text);font-variant-numeric:tabular-nums}
|
|
3871
|
+
.paper-type-select{flex:1;min-width:0}
|
|
3872
|
+
/* 双语档才出现的「原 / 译」切换:比阅读视图那条窄得多,按内容排、不等分。
|
|
3873
|
+
⚠️ 它复用 .paper-seg 的滑动高亮块,所以要显式给出项数 —— 两档就是 2。 */
|
|
3874
|
+
.paper-type-side{flex:0 0 auto;--paper-seg-count:2}
|
|
3875
|
+
.paper-type-side>button{flex:0 0 auto;padding:5px 7px}
|
|
3756
3876
|
/* 🔴 这里是 src(英文正文)档,不是 pdf(原页位图)档。位图档渲染的是
|
|
3757
3877
|
.paper-pdf-* 那一套,树里根本没有 .paper-reader-raw —— 把这条挂到 pdf 上等于死规则,
|
|
3758
3878
|
而 src 档里每一行都是 raw:true,会被下面 .paper-reader-raw{color:var(--paper-muted)}
|
|
@@ -3771,18 +3891,48 @@ button.paper-select>span{min-width:0;overflow:hidden;text-overflow:ellipsis;whit
|
|
|
3771
3891
|
.paper-reader-split .paper-reader-body-zh .paper-reader-block{border-left:2px solid var(--paper-accent);padding-left:8px}
|
|
3772
3892
|
/* ---- P6 阅读页排版(对照 EasyRead 的 design.md §版面)----
|
|
3773
3893
|
🔴 版心(35em ≈ 630px)**做不到**:侧栏宽度由宿主定(300px 起、上限视口 70%)。
|
|
3774
|
-
|
|
3775
|
-
正文用宋体(中文长读比黑体舒服),暖白纸色底、墨色字,不用纯黑纯白。
|
|
3776
|
-
|
|
3894
|
+
能做的是字号、行距与字体族 —— 三者都由顶栏那三个排版按钮以下面的 CSS 变量下发。
|
|
3895
|
+
正文用宋体(中文长读比黑体舒服),暖白纸色底、墨色字,不用纯黑纯白。
|
|
3896
|
+
|
|
3897
|
+
🔴 **原文与译文各一套**(D195):读者裁定「选到哪个档,就改哪个档的排版」。
|
|
3898
|
+
两套值由 inline style 落在 .paper-reader-layout 上,下面按 data-pane 分派:
|
|
3899
|
+
原文档 → 整档用 src 那套;译文档 → 整档用 zh 那套;双语档 → 原文段用 src、译文段用 zh。
|
|
3900
|
+
⚠️ 兜底必须与源码常量同口径(DEFAULT_FONT_SIZE / DEFAULT_LINE_HEIGHT),
|
|
3901
|
+
client-css.test.js 会拿源码里的常量来对,改常量时这里不改就会红。 ---- */
|
|
3902
|
+
.paper-reader{--reader-src-font-size:18px;--reader-src-line-height:1.7;
|
|
3903
|
+
--reader-zh-font-size:18px;--reader-zh-line-height:1.7;
|
|
3777
3904
|
--reader-paper:#f6f3ec;--reader-ink:#23211d}
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
.paper-reader-layout
|
|
3905
|
+
/* 🔴 字体族**故意不给兜底值**。读者选「系统默认」时那侧的 --reader-*-font-family 根本
|
|
3906
|
+
不下发,而 font-family:var(--reader-*-font-family) 在变量未定义时整条声明在计算值阶段
|
|
3907
|
+
失效 —— 正文于是不设字族,用浏览器自己那套默认字体,正是这一档要的语义。
|
|
3908
|
+
一旦在这里补一个兜底栈,"系统默认"就退化成"宋体",读者改了浏览器默认字体也看不出来。 */
|
|
3909
|
+
/* 🔴 分派这一层只认 data-pane,不看内容语言:档位是读者亲手选的,语言是翻译结果的副作用。
|
|
3910
|
+
双语档里原文段与译文段同在 .paper-reader-body-zh 里(.paper-reader-body-src 那列只在
|
|
3911
|
+
已退役的并排档渲染),所以双语档必须按 .paper-reader-raw 再分一次。 */
|
|
3912
|
+
.paper-reader-layout{font-size:var(--reader-zh-font-size);line-height:var(--reader-zh-line-height)}
|
|
3913
|
+
[data-pane="src"] .paper-reader-layout{font-size:var(--reader-src-font-size);line-height:var(--reader-src-line-height);
|
|
3914
|
+
font-family:var(--reader-src-font-family)}
|
|
3915
|
+
[data-pane="zh"] .paper-reader-layout{font-size:var(--reader-zh-font-size);line-height:var(--reader-zh-line-height);
|
|
3916
|
+
font-family:var(--reader-zh-font-family)}
|
|
3917
|
+
[data-pane="bi"] .paper-reader-layout{font-size:var(--reader-zh-font-size);line-height:var(--reader-zh-line-height);
|
|
3918
|
+
font-family:var(--reader-zh-font-family)}
|
|
3919
|
+
[data-pane="bi"] .paper-reader-layout .paper-reader-raw{font-size:var(--reader-src-font-size);
|
|
3920
|
+
line-height:var(--reader-src-line-height);font-family:var(--reader-src-font-family)}
|
|
3921
|
+
/* 🔴 宿主的 .markdown 用 font: **简写**把字号、行距、**字族**一起定死在 --dsw-font-markdown-base
|
|
3922
|
+
(ui-primitives/markdown/MarkdownText.module.css:8)。它又是 CSS Module 的哈希类名,
|
|
3923
|
+
点名打不到,而继承链在那一层就断了 —— 我们的三个排版变量根本传不进正文。
|
|
3924
|
+
它是块的**唯一直接子节点**,所以从我们的块往下一层把这几项接回去。
|
|
3925
|
+
color 同理:宿主那条 .markdown{color:var(--dsw-alias-label-primary)} 也盖掉了双语的分层。
|
|
3926
|
+
⚠️ font-family 那一项曾经漏过(用户实测「切换字体无反应,换了还是宋体」):
|
|
3927
|
+
当时只补了字号与行距,于是三个滑杆里两个能用、一个不能用。简写里的每一项都要接。
|
|
3928
|
+
🔴 选择器里那个 [data-dsh-paper] **不是**装饰:主题插件会覆盖正文的字族,例如
|
|
3929
|
+
dsh-claude-style 的 typography.css 用
|
|
3930
|
+
body[data-dsh-claude-style] [data-dsh-claude-part~="markdown"]{font-family:…}
|
|
3931
|
+
抢走整块的字族。那条是 (0,2,1),本规则只写两个类名时是 (0,2,0) —— 低一档就必然输,
|
|
3932
|
+
于是字号、行距都跟着读者走,唯独字体纹丝不动(用户实测:变量下发正确、档位也正确,
|
|
3933
|
+
块上的计算字族却是主题插件那套)。这里多挂自己 DOM 根上的属性把特异性提到 (0,3,0),
|
|
3934
|
+
超过主题插件又不依赖它的类名。 */
|
|
3935
|
+
[data-dsh-paper] .paper-reader-layout .paper-reader-block > *{font-size:inherit;line-height:inherit;font-family:inherit;color:inherit}
|
|
3786
3936
|
/* 每个块是一份独立的 MarkdownText,宿主的 .markdown p{margin:16px 0} 于是每两块之间白送
|
|
3787
3937
|
32px,再叠上本层的 gap:10px = 42px —— 这就是「行距太开」。首末子节点归零,间距交回 gap。 */
|
|
3788
3938
|
.paper-reader-layout .paper-reader-block > * > :first-child{margin-top:0}
|
|
@@ -3795,19 +3945,23 @@ button.paper-select>span{min-width:0;overflow:hidden;text-overflow:ellipsis;whit
|
|
|
3795
3945
|
.paper-reader-layout .paper-reader-block{margin-top:0;margin-bottom:0;min-width:0;overflow-wrap:anywhere;content-visibility:auto;contain-intrinsic-size:auto 180px}
|
|
3796
3946
|
.paper-reader-block .katex{white-space:normal;text-align:left}
|
|
3797
3947
|
.paper-reader-block .katex-display{max-width:100%;overflow-x:auto;overflow-y:hidden}
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3948
|
+
/* 字体族由上面 [data-pane] 那几条按档位下发,这里只剩对齐。
|
|
3949
|
+
⚠️ 别再往这条规则里写 font-family:档位分派在上层,写在这儿会把双语档原文段的
|
|
3950
|
+
字体盖回宋体 —— 而那一层正是读者能单独设字体的地方。 */
|
|
3951
|
+
.paper-reader-body-zh .paper-reader-block{text-align:justify}
|
|
3952
|
+
/* 双语档的原文段左对齐:它是英文,两端对齐会把含公式的行拉出大洞(用户报过)。
|
|
3953
|
+
⚠️ 这条不能并进上面那条 —— 上面是 justify,这里是 left,同级选择器后写的赢。 */
|
|
3801
3954
|
.paper-reader-body-zh .paper-reader-raw{text-align:left}
|
|
3802
3955
|
/* 原文那一列小一号、灰一级,左侧一条细线 —— 与译文明显分层。 */
|
|
3803
|
-
.paper-reader-body-src{font-size:calc(var(--reader-font-size) - 2px);color:var(--paper-muted)
|
|
3804
|
-
font-family:'Source Serif Pro',Charter,Georgia,serif}
|
|
3956
|
+
.paper-reader-body-src{font-size:calc(var(--reader-src-font-size) - 2px);color:var(--paper-muted)}
|
|
3805
3957
|
.paper-reader-body-src .paper-reader-block{border-left:2px solid var(--paper-border);padding-left:8px}
|
|
3806
3958
|
/* ---- D149 双语分层(用户裁定,照他给的参考图:原文大而亮、译文小一号 + 次级色)----
|
|
3807
3959
|
⚠️ 只作用于**双语档**。译文档里译文是唯一内容,必须保持主字号 + 主色 ——
|
|
3808
3960
|
把这两条放宽一格,译文 tab 的正文就整体降级了。
|
|
3809
3961
|
⚠️ 主色用 inherit:--reader-ink 只声明过、没有任何规则用过它(T16 留下的空变量)。
|
|
3810
3962
|
⚠️ 字号只降到 div 上:译文的小标题是 h3/h4,各自已有自己的字号,不该再被降一档。 */
|
|
3963
|
+
/* ⚠️ 这一条**只给颜色**,不给 font-size:原文段在双语档里是主层,字号由它自己那套
|
|
3964
|
+
(--reader-src-font-size)决定,在这里再降一档等于读者选的字号被偷偷改掉。 */
|
|
3811
3965
|
[data-pane="bi"] .paper-reader-raw{color:inherit}
|
|
3812
3966
|
/* ---- D149 双语分层:译文那一层(次级色 + 小一号 + 左侧竖条)----
|
|
3813
3967
|
🔴 三条必须写在**同一条规则**里。同一个选择器出现两次时,测试里的 ruleOf 只取第一条,
|
|
@@ -3820,7 +3974,7 @@ button.paper-select>span{min-width:0;overflow:hidden;text-overflow:ellipsis;whit
|
|
|
3820
3974
|
[data-pane="bi"] .paper-reader-body-zh .paper-reader-block:not(.paper-reader-raw){
|
|
3821
3975
|
color:var(--paper-muted);border-left:2px solid var(--paper-border);padding-left:8px}
|
|
3822
3976
|
[data-pane="bi"] .paper-reader-body-zh div.paper-reader-block:not(.paper-reader-raw){
|
|
3823
|
-
font-size:calc(var(--reader-font-size) - 3px)}
|
|
3977
|
+
font-size:calc(var(--reader-zh-font-size) - 3px)}
|
|
3824
3978
|
/* ---- 目录抽屉 ---- */
|
|
3825
3979
|
.paper-reader-drawer{display:flex;flex-direction:column;gap:8px;padding:10px;
|
|
3826
3980
|
background:var(--paper-card);box-shadow:var(--paper-shadow)}
|
|
@@ -3994,11 +4148,7 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
3994
4148
|
契约这条不猜。 */
|
|
3995
4149
|
.paper-lib{display:flex;flex-direction:row;height:100%;max-height:100%;min-height:0;position:relative;overflow:hidden;font-size:13px}
|
|
3996
4150
|
.paper-import-control{position:relative;display:flex}
|
|
3997
|
-
|
|
3998
|
-
.paper-import-menu>.paper-btn{justify-content:flex-start;border-color:transparent}
|
|
3999
|
-
.paper-import-control>.paper-btn{background:var(--paper-accent);border-color:var(--paper-accent);color:var(--paper-on-accent)}
|
|
4000
|
-
.paper-import-control>.paper-btn:hover{background:var(--paper-accent);filter:brightness(1.1)}
|
|
4001
|
-
.paper-import-control>.paper-btn .paper-library-icon{color:inherit}
|
|
4151
|
+
|
|
4002
4152
|
.paper-lib-head>.paper-btn:hover{background:var(--paper-hover)}
|
|
4003
4153
|
.paper-lib .paper-btn,.paper-lib .paper-input{border-radius:6px;font:inherit;font-size:12px;padding:4px 8px;min-height:28px}
|
|
4004
4154
|
.paper-lib .paper-rename{display:flex;flex-direction:column;gap:6px}
|
|
@@ -4188,11 +4338,6 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
4188
4338
|
.paper-info-label{flex:0 0 56px;color:var(--paper-muted);text-align:right}
|
|
4189
4339
|
.paper-info-value{min-width:0;flex:1;overflow-wrap:anywhere}
|
|
4190
4340
|
.paper-detail-files{border-top:1px solid var(--paper-border);margin-top:4px}
|
|
4191
|
-
.paper-menu{position:fixed;z-index:var(--paper-layer-float);min-width:132px;padding:5px;display:flex;flex-direction:column;gap:1px;overflow-y:auto;overscroll-behavior:contain;background:var(--paper-bg);box-shadow:var(--paper-shadow-pop)}
|
|
4192
|
-
.paper-menu button{flex:0 0 auto;border:0;background:transparent;color:var(--paper-text);text-align:left;padding:7px 9px;border-radius:var(--paper-radius-sm);cursor:pointer;font:inherit;white-space:normal;overflow-wrap:anywhere}
|
|
4193
|
-
.paper-menu button:hover{background:var(--paper-hover)}
|
|
4194
|
-
.paper-menu button.active{background:var(--paper-accent-soft);color:var(--paper-accent)}
|
|
4195
|
-
.paper-menu-label{flex:0 0 auto;padding:6px 9px 3px;color:var(--paper-muted);font-size:11px;font-weight:600;letter-spacing:.02em}
|
|
4196
4341
|
/* 🔴 height:100% 只给**主栏**那份(它带 data-dsh-paper)。
|
|
4197
4342
|
右栏阅读区那个 section 的类名**也叫 paper-reader**:全局加高度会把它钉成一屏高、
|
|
4198
4343
|
内容溢出自己的盒子 —— 后果不只是"盒子小",而是把「顶栏 sticky」的**包含块**压成一屏,
|
|
@@ -4250,7 +4395,6 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
4250
4395
|
@keyframes paper-surface-in{from{opacity:0;transform:translateY(4px) scale(.98)}to{opacity:1;transform:none}}
|
|
4251
4396
|
@media (prefers-reduced-motion:reduce){
|
|
4252
4397
|
:is([data-dsh-paper],.paper-config){--paper-t-feedback:0.01ms;--paper-t-surface:0.01ms;--paper-t-open:0.01ms;--paper-t-exit:0.01ms;--paper-t-slide:0.01ms}
|
|
4253
|
-
.paper-menu,.paper-import-menu{animation:none}
|
|
4254
4398
|
}
|
|
4255
4399
|
`
|
|
4256
4400
|
|
|
@@ -4868,8 +5012,8 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
4868
5012
|
const publishReaderBridge = patch => {
|
|
4869
5013
|
if (!boundDocumentId || visibleRef.current) bridgeSet({ ...patch, ...(boundDocumentId ? { documentId: boundDocumentId } : {}) })
|
|
4870
5014
|
}
|
|
4871
|
-
//
|
|
4872
|
-
const [selectMenu, setSelectMenu] = React.useState(
|
|
5015
|
+
// 打开中的下拉:存的是**它的 aria-label**(一个面板同一时刻只有一张开着)。
|
|
5016
|
+
const [selectMenu, setSelectMenu] = React.useState('')
|
|
4873
5017
|
const [state, setState] = React.useState(null)
|
|
4874
5018
|
const [path, setPath] = React.useState('')
|
|
4875
5019
|
const [query, setQuery] = React.useState('')
|
|
@@ -4987,16 +5131,30 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
4987
5131
|
// 术语页的文本。**按需拉**(切到那一页才拉):术语表是全局一份,
|
|
4988
5132
|
// 进阅读器就拉等于每次打开论文都白读一次盘,而多数人从不打开抽屉。
|
|
4989
5133
|
const [termsText, setTermsText] = React.useState('')
|
|
4990
|
-
//
|
|
4991
|
-
// 行距按**十分之一**存(滑杆是整数,1.9 存成 19),与 --reader
|
|
5134
|
+
// 排版:字号 / 行距 / 字体族,**原文与译文各一套**(D195)。
|
|
5135
|
+
// 行距按**十分之一**存(滑杆是整数,1.9 存成 19),与 --reader-*-line-height 同一口径。
|
|
4992
5136
|
// 🔴 初值用**惰性初始化**只读一次 localStorage:每轮渲染都读会把本轮刚写进去的值再读回来,
|
|
4993
5137
|
// 看着一样,但只要写失败(配额满、隐私模式)就会当场跳回默认值。
|
|
4994
|
-
const [
|
|
4995
|
-
|
|
4996
|
-
)
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5138
|
+
const [readerType, setReaderType] = React.useState(() => typePref())
|
|
5139
|
+
// 三个排版弹层里当前开着哪一个('' = 都关着)。互斥:点另一个直接换过去。
|
|
5140
|
+
const [typePop, setTypePop] = React.useState('')
|
|
5141
|
+
// 排版按钮与它的弹层。点外部关闭这条要用它判「点到的是不是自己人」。
|
|
5142
|
+
const typePopRef = React.useRef(null)
|
|
5143
|
+
// 双语档下三个按钮改的是原文那套还是译文那套('src' / 'zh')。
|
|
5144
|
+
// 🔴 只影响**双语档**:原文档与译文档的归属是确定的,不给第二个选择。
|
|
5145
|
+
const [typeSide, setTypeSide] = React.useState('zh')
|
|
5146
|
+
/**
|
|
5147
|
+
* 改一套排版并落盘。
|
|
5148
|
+
*
|
|
5149
|
+
* 🔴 **一次写全三组**:writePref 是整键覆盖,只写改动那一组会把另一组从磁盘抹掉。
|
|
5150
|
+
* 🔴 先算 next 再写,不在 setState 回调里写 localStorage —— React 的严格模式会
|
|
5151
|
+
* 把 updater 跑两遍,那是两次写盘。
|
|
5152
|
+
*/
|
|
5153
|
+
const patchType = (side, patch) => {
|
|
5154
|
+
const next = { src: { ...readerType.src }, zh: { ...readerType.zh }, [side]: { ...readerType[side], ...patch } }
|
|
5155
|
+
setReaderType(next)
|
|
5156
|
+
writeTypePref(next)
|
|
5157
|
+
}
|
|
5000
5158
|
// ---- 边注讨论(T20) ----
|
|
5001
5159
|
const [threads, setThreads] = React.useState([])
|
|
5002
5160
|
const [question, setQuestion] = React.useState('')
|
|
@@ -6102,6 +6260,196 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
6102
6260
|
? '当前版本不支持并排(宿主没有分栏接口)。'
|
|
6103
6261
|
: '没能并排:右栏宽度不足或已经开了两格;拖宽右栏后再试。')
|
|
6104
6262
|
}
|
|
6263
|
+
/**
|
|
6264
|
+
* 三个排版按钮跟着**当前档位**走(D195,读者裁定「选到哪就显示那个档的字体设置」)。
|
|
6265
|
+
*
|
|
6266
|
+
* | 档位 | 改的是哪一套 |
|
|
6267
|
+
* | --- | --- |
|
|
6268
|
+
* | 原文(src) | 原文那套,不给选择 |
|
|
6269
|
+
* | 译文(zh) | 译文那套,不给选择 |
|
|
6270
|
+
* | 双语(bi) | 由 typeSide 决定,前面另给一个「原 / 译」小切换 |
|
|
6271
|
+
* | PDF / 笔记 | 沿用上一次的单语言档(typeSide),**不跳变** |
|
|
6272
|
+
*
|
|
6273
|
+
* 🔴 PDF 与笔记档不参与归属判断:PDF 是位图、笔记是批注面板,它们没有"正文语言"。
|
|
6274
|
+
* 让它们各自记一套等于多出两个永远没人改的存储槽。
|
|
6275
|
+
*/
|
|
6276
|
+
const typeSideOf = () => (paneView === 'src' ? 'src' : paneView === 'zh' ? 'zh' : typeSide)
|
|
6277
|
+
/** 双语档才给的「原 / 译」小切换:切它会同时改 typeSide 与三个按钮显示的值。 */
|
|
6278
|
+
const typeSideSwitch = () => {
|
|
6279
|
+
if (paneView !== 'bi') return null
|
|
6280
|
+
const values = ['src', 'zh']
|
|
6281
|
+
const index = Math.max(0, values.indexOf(typeSideOf()))
|
|
6282
|
+
return h('div', {
|
|
6283
|
+
className: 'paper-seg paper-type-side',
|
|
6284
|
+
role: 'tablist',
|
|
6285
|
+
'aria-label': '改哪一套排版',
|
|
6286
|
+
// 🔴 滑块的下标必须和项数一起给。只给项数时 --paper-seg-index 取默认值 0,
|
|
6287
|
+
// 白块就永远停在「原」上 —— 而「译」的文字照样变深(那走的是 aria-selected 的
|
|
6288
|
+
// color/font-weight),于是症状是「颜色变了,块还在原字上」(用户实测报过)。
|
|
6289
|
+
// 另两处分段控件(档位、阅读状态)都是这么给的两个变量,这里曾经漏了一个。
|
|
6290
|
+
style: {
|
|
6291
|
+
'--paper-seg-count': String(values.length),
|
|
6292
|
+
'--paper-seg-index': String(index),
|
|
6293
|
+
},
|
|
6294
|
+
}, values.map(value => h('button', {
|
|
6295
|
+
className: 'paper-btn', type: 'button', role: 'tab', key: value,
|
|
6296
|
+
'aria-selected': typeSideOf() === value,
|
|
6297
|
+
'aria-label': value === 'src' ? '改原文那套排版' : '改译文那套排版',
|
|
6298
|
+
title: value === 'src' ? '改原文那套排版' : '改译文那套排版',
|
|
6299
|
+
onClick: () => setTypeSide(value),
|
|
6300
|
+
}, value === 'src' ? '原' : '译')))
|
|
6301
|
+
}
|
|
6302
|
+
/**
|
|
6303
|
+
* 一个排版按钮 + 它自己的弹层。
|
|
6304
|
+
*
|
|
6305
|
+
* 🔴 三个弹层**互斥**(读者裁定):点另一个直接换过去,点空白或 Esc 关闭,再点同一个收起。
|
|
6306
|
+
* 同时开两个会在 300px 的侧栏里叠成一片,谁也看不清。
|
|
6307
|
+
*
|
|
6308
|
+
* @param {string} key 弹层标识(size / height / family)。
|
|
6309
|
+
* @param {string} label 按钮上的文字,直接显示**当前值**。
|
|
6310
|
+
* @param {string} title 悬停说明。
|
|
6311
|
+
* @param {object} pop 弹层内容。
|
|
6312
|
+
*/
|
|
6313
|
+
/**
|
|
6314
|
+
* 点外部关闭排版弹层。
|
|
6315
|
+
*
|
|
6316
|
+
* 🔴 **不能用铺满视口的透明遮罩**(第一版就是),它会盖住整条顶栏 —— 「原 / 译」
|
|
6317
|
+
* 切换、并排、注入、五个视图档位统统点不动,用户实测报「原/译按钮点击无反应」。
|
|
6318
|
+
* 遮罩的本意是"点空白处关闭",代价却是"整条顶栏都变成空白"。
|
|
6319
|
+
* 改成在 document 上听一次捕获阶段的 pointerdown:点在弹层或任一排版按钮之外才关。
|
|
6320
|
+
*/
|
|
6321
|
+
React.useEffect(() => {
|
|
6322
|
+
// 🔴 字体档交给 Menu 自己关。它 portal 到 document.body,压根不在
|
|
6323
|
+
// .paper-type-row-holder 子树里,于是下面这个「点在外面」的判据把菜单项本身
|
|
6324
|
+
// 也当成外面:捕获阶段的 pointerdown 先 setTypePop(''),菜单连同里面的按钮
|
|
6325
|
+
// 当场卸载,后面的 click 就没有目标了 —— 症状正是「点楷体毫无反应,菜单还开着」
|
|
6326
|
+
// (用户实测:加的探针一行都没打出来,说明 onSelect 从未被调用)。
|
|
6327
|
+
// Menu 自己就监听 document 的 pointerdown 并区分内外,这一档不必也不该再插手。
|
|
6328
|
+
if (typePop === '' || typePop === 'family') return undefined
|
|
6329
|
+
const away = event => {
|
|
6330
|
+
const node = event?.target
|
|
6331
|
+
if (node !== null && typeof node?.closest === 'function' && node.closest('.paper-type-row-holder') !== null) return
|
|
6332
|
+
setTypePop('')
|
|
6333
|
+
}
|
|
6334
|
+
document.addEventListener('pointerdown', away, true)
|
|
6335
|
+
return () => document.removeEventListener('pointerdown', away, true)
|
|
6336
|
+
}, [typePop])
|
|
6337
|
+
/**
|
|
6338
|
+
* 一个排版按钮。**弹层不挂在按钮上**,见 typePopover 的说明。
|
|
6339
|
+
*
|
|
6340
|
+
* @param {string} key 弹层标识(size / height / family)。
|
|
6341
|
+
* @param {string} label 按钮上的文字,直接显示**当前值**。
|
|
6342
|
+
* @param {string} title 悬停说明,也是弹层的 aria-label。
|
|
6343
|
+
*/
|
|
6344
|
+
const typeButton = (key, label, title) => {
|
|
6345
|
+
const open = typePop === key
|
|
6346
|
+
return h('button', {
|
|
6347
|
+
className: 'paper-btn paper-type-trigger' + (open ? ' active' : ''),
|
|
6348
|
+
type: 'button', key,
|
|
6349
|
+
'aria-label': title,
|
|
6350
|
+
'aria-expanded': open,
|
|
6351
|
+
title,
|
|
6352
|
+
onClick: () => setTypePop(open ? '' : key),
|
|
6353
|
+
}, h('span', { className: 'paper-type-glyph' }, 'Aa'), label)
|
|
6354
|
+
}
|
|
6355
|
+
/**
|
|
6356
|
+
* 字体那一档的触发按钮。**与上面两个同构**:同样的类名、同样的 Aa 起头、同样把当前值
|
|
6357
|
+
* 写成文字。它点开的是宿主的 Menu(见 typeFamily),但按钮本身不该长成别的东西 ——
|
|
6358
|
+
* 三个排版按钮并排,其中两个是 .paper-btn 一个是 .paper-input 的话,一眼就看得出破绽。
|
|
6359
|
+
*/
|
|
6360
|
+
const typeFamilyTrigger = (side, open) => h('button', {
|
|
6361
|
+
className: 'paper-btn paper-type-trigger' + (open ? ' active' : ''),
|
|
6362
|
+
type: 'button',
|
|
6363
|
+
'aria-label': '字体',
|
|
6364
|
+
'aria-haspopup': 'menu',
|
|
6365
|
+
'aria-expanded': open,
|
|
6366
|
+
title: '字体',
|
|
6367
|
+
onClick: () => setTypePop(open ? '' : 'family'),
|
|
6368
|
+
}, h('span', { className: 'paper-type-glyph' }, 'Aa'),
|
|
6369
|
+
(fontFamiliesOf(side).find(entry => entry.value === readerType[side].family)?.label ?? fontFamiliesOf(side)[0].label))
|
|
6370
|
+
/**
|
|
6371
|
+
* 当前开着的那个滑杆弹层(字号 / 行距)。**挂在顶栏这一行上,不挂在按钮上。**
|
|
6372
|
+
*
|
|
6373
|
+
* 🔴 为什么不跟按钮走(用户实测截图报「都看不到了」):弹层 220px 宽,挂在某个按钮上
|
|
6374
|
+
* 就只能在那个按钮的坐标里选锚点 ——
|
|
6375
|
+
* · 锚左沿(left:0)时,最右的那个一点开就朝右伸出侧栏被裁掉;
|
|
6376
|
+
* · 锚右沿(right:0)时,最左的「字号」反过来朝左溢出,一样看不见。
|
|
6377
|
+
* 侧栏最窄 300px,220px 的弹层无论锚哪一端都盖不住整排按钮的跨度。
|
|
6378
|
+
*
|
|
6379
|
+
* 挂在顶栏行上就没有这个两难:left:0; right:0 铺满整行,永远在容器里面,
|
|
6380
|
+
* 侧栏多窄都完整可见。代价是弹层比按钮宽,但那正是它该有的样子 ——
|
|
6381
|
+
* 这个弹层里放的是**一个滑杆 + 它的数值**,不是按钮的下拉菜单。
|
|
6382
|
+
*
|
|
6383
|
+
* 字体那一档不是滑杆,它是选项列表,所以走宿主的 Menu(见 typeFamily)——
|
|
6384
|
+
* 由 Menu 自己 portal 到 body,同样不受侧栏裁剪。
|
|
6385
|
+
*/
|
|
6386
|
+
const typePopover = () => {
|
|
6387
|
+
if (typePop === '' || typePop === 'family' || typeControlsHidden()) return null
|
|
6388
|
+
const side = typeSideOf()
|
|
6389
|
+
const spec = {
|
|
6390
|
+
size: { title: '字号', body: typeSlider(side, 'size', MIN_FONT_SIZE, MAX_FONT_SIZE, 1, '字号') },
|
|
6391
|
+
height: { title: '行距', body: typeSlider(side, 'height', MIN_LINE_HEIGHT, MAX_LINE_HEIGHT, 1, '行距', 10) },
|
|
6392
|
+
}[typePop]
|
|
6393
|
+
if (spec === undefined) return null
|
|
6394
|
+
return h('div', {
|
|
6395
|
+
className: 'paper-type-panel paper-type-pop', role: 'dialog', 'aria-label': spec.title,
|
|
6396
|
+
onKeyDown: event => { if (event?.key === 'Escape') setTypePop('') },
|
|
6397
|
+
}, spec.body)
|
|
6398
|
+
}
|
|
6399
|
+
/** 字号 / 行距共用的滑杆。步长与区间取自源码常量,不在这里写死数字。 */
|
|
6400
|
+
const typeSlider = (side, field, min, max, step, unit, scale = 1) => {
|
|
6401
|
+
const current = readerType[side][field]
|
|
6402
|
+
return h('label', { className: 'paper-type-row' },
|
|
6403
|
+
h('span', null, unit),
|
|
6404
|
+
h('input', {
|
|
6405
|
+
type: 'range', min: String(min), max: String(max), step: String(step),
|
|
6406
|
+
value: String(current),
|
|
6407
|
+
'aria-label': unit,
|
|
6408
|
+
onChange: event => {
|
|
6409
|
+
const raw = Number(event?.target?.value)
|
|
6410
|
+
if (!Number.isFinite(raw)) return
|
|
6411
|
+
patchType(side, { [field]: Math.round(Math.min(max, Math.max(min, raw))) })
|
|
6412
|
+
},
|
|
6413
|
+
}),
|
|
6414
|
+
h('span', { className: 'paper-type-value' }, scale === 10 ? (current / 10).toFixed(1) : String(current)))
|
|
6415
|
+
}
|
|
6416
|
+
/**
|
|
6417
|
+
* 字体族下拉。三档固定清单,取值校验在 fontOf 那一层。
|
|
6418
|
+
*
|
|
6419
|
+
* 🔴 用宿主的 Menu,不是原生 select(用户实测截图:原生那份是系统画的直角白底蓝条,
|
|
6420
|
+
* 与侧栏、与同一排的字号/行距滑杆都不是一套东西)。三档正好对应 Menu 的单选形态:
|
|
6421
|
+
* selectedId 打勾,portal 让浮层挂到 body —— 顶栏这一行在窄侧栏里放不下 220px 的卡。
|
|
6422
|
+
*/
|
|
6423
|
+
const typeFamily = side => h(Menu, {
|
|
6424
|
+
open: typePop === 'family',
|
|
6425
|
+
onClose: () => setTypePop(''),
|
|
6426
|
+
items: fontFamiliesOf(side).map(entry => ({ id: entry.value, label: entry.label })),
|
|
6427
|
+
selectedId: readerType[side].family,
|
|
6428
|
+
onSelect: id => { setTypePop(''); patchType(side, { family: fontOf(side, id) }) },
|
|
6429
|
+
portal: true,
|
|
6430
|
+
minWidthFromAnchor: true,
|
|
6431
|
+
anchor: typeFamilyTrigger(side, typePop === 'family'),
|
|
6432
|
+
})
|
|
6433
|
+
/**
|
|
6434
|
+
* 三个排版按钮整体。双语档时前面多一个「原 / 译」切换。
|
|
6435
|
+
*
|
|
6436
|
+
* 🔴 **PDF 档不渲染**(用户裁定):那一档是原页位图,位图上的字由 PDF 自己排版,
|
|
6437
|
+
* 我们的字号 / 行距 / 字体一个都不作用于它。摆在顶栏上就是个点了没反应的假控件。
|
|
6438
|
+
* 笔记档同理 —— 它是批注面板,不是正文。两档都不渲染,不是置灰:
|
|
6439
|
+
* 灰按钮仍然占位,而这两档本来就不该有"能调但调不了"的暗示。
|
|
6440
|
+
*/
|
|
6441
|
+
/** 这一档要不要出排版控件(PDF 是位图、笔记是批注面板,都不出)。 */
|
|
6442
|
+
const typeControlsHidden = () => isPdfPane(paneView) || paneView === 'notes'
|
|
6443
|
+
const typeControls = () => {
|
|
6444
|
+
if (typeControlsHidden()) return null
|
|
6445
|
+
const side = typeSideOf()
|
|
6446
|
+
return [
|
|
6447
|
+
typeSideSwitch(),
|
|
6448
|
+
typeButton('size', `${readerType[side].size}px`, '字号'),
|
|
6449
|
+
typeButton('height', (readerType[side].height / 10).toFixed(1), '行距'),
|
|
6450
|
+
typeFamily(side),
|
|
6451
|
+
].filter(item => item !== null && item !== undefined && item !== false)
|
|
6452
|
+
}
|
|
6105
6453
|
/** 阅读视图共用一组分段按钮,选择结果按全局偏好保存。 */
|
|
6106
6454
|
const paneSegmented = () => h('div', {
|
|
6107
6455
|
className: 'paper-seg paper-reader-view',
|
|
@@ -7407,10 +7755,24 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
7407
7755
|
// ---- 阅读页顶栏(P6)的派生量 ----
|
|
7408
7756
|
// 「注入」按当前会话的 desired 集算 —— 与列表卡片上那个按钮同一口径,不另立概念。
|
|
7409
7757
|
const readerInjected = readerId !== '' && desired.has(readerId)
|
|
7410
|
-
//
|
|
7758
|
+
// 正文排版:每个档位六个变量(字号 / 行距 / 字体族 × 原文 / 译文)一次性下发。
|
|
7759
|
+
// 🔴 六组**一起**给:按 data-pane 分派的那几条 CSS 直接读变量,缺一个就会在切到
|
|
7760
|
+
// 那个档位时退化成 CSS 里的兜底值,看着像"改了没生效"。
|
|
7761
|
+
// 🔴 栈为空(「系统默认」档)时**不下发这个变量**。CSS 里那几条分派规则写的是
|
|
7762
|
+
// font-family:var(--reader-*-font-family),变量未定义时整条声明在计算值阶段失效,
|
|
7763
|
+
// 于是不写 font-family —— 正是让浏览器用自己那套默认字体。若下发空串,
|
|
7764
|
+
// font-family:'' 是无效值,同样失效,但语义不如"干脆不给"明确。
|
|
7765
|
+
const fontStyleOf = side => {
|
|
7766
|
+
const stack = fontStackOf(side, readerType[side].family)
|
|
7767
|
+
return stack === '' ? {} : { ['--reader-' + side + '-font-family']: stack }
|
|
7768
|
+
}
|
|
7411
7769
|
const readerTypeStyle = {
|
|
7412
|
-
'--reader-font-size': `${
|
|
7413
|
-
'--reader-line-height': String(
|
|
7770
|
+
'--reader-src-font-size': `${readerType.src.size}px`,
|
|
7771
|
+
'--reader-src-line-height': String(readerType.src.height / 10),
|
|
7772
|
+
'--reader-zh-font-size': `${readerType.zh.size}px`,
|
|
7773
|
+
'--reader-zh-line-height': String(readerType.zh.height / 10),
|
|
7774
|
+
...fontStyleOf('src'),
|
|
7775
|
+
...fontStyleOf('zh'),
|
|
7414
7776
|
}
|
|
7415
7777
|
// 抽屉正文。三个页各自的文本都从**已经下发的数据**里取,不为它多打一次请求。
|
|
7416
7778
|
const drawerOutline = typeof reader?.outlineText === 'string' ? reader.outlineText : ''
|
|
@@ -7485,9 +7847,8 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
7485
7847
|
await deleteDocuments(pickedIds)
|
|
7486
7848
|
}
|
|
7487
7849
|
const pickSelect = (label, value, options, onPick, extra) =>
|
|
7488
|
-
selectControlOf(setSelectMenu, label, value, options, onPick, extra)
|
|
7850
|
+
selectControlOf(selectMenu, setSelectMenu, label, value, options, onPick, extra)
|
|
7489
7851
|
return h('div', { 'data-dsh-paper': true },
|
|
7490
|
-
selectMenu === null ? null : renderSelectMenu(selectMenu, setSelectMenu),
|
|
7491
7852
|
// 🔴 P6:侧栏**不再显示或编辑任何设置**(用户裁定「要设置的地方都进入插件」)。
|
|
7492
7853
|
// 原来这里挂着「MinerU:已配置/未配置」—— 那是状态,但紧挨着它就该有设置入口,
|
|
7493
7854
|
// 而宿主**没有**给插件"打开设置页"的导航 API(查过 ui-settings / ui-commands /
|
|
@@ -7682,6 +8043,13 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
7682
8043
|
onClick: () => setDrawerOpen(!drawerOpen),
|
|
7683
8044
|
}, '☰'),
|
|
7684
8045
|
paneSegmented(),
|
|
8046
|
+
// 三个排版按钮(D195):紧跟在视图档位之后、「并排」之前(读者裁定)。
|
|
8047
|
+
// 它跟着当前档位显示值;PDF 与笔记档整体不渲染。
|
|
8048
|
+
// 🔴 按钮与弹层包在同一个 holder 里:弹层相对**整行**定位(见 typePopover),
|
|
8049
|
+
// 而不是相对某个按钮 —— 后者在 300px 侧栏里必有一端溢出。
|
|
8050
|
+
!typeControlsHidden() && h('div', { className: 'paper-type-row-holder' },
|
|
8051
|
+
typeControls(),
|
|
8052
|
+
typePopover()),
|
|
7685
8053
|
// 并排(D183):把这一篇在右栏另一格再开一份,左原文右译文对照读。
|
|
7686
8054
|
// 🔴 只在主格显示:副格再点它只会揭示已有的那格,多一个按钮不多一个能力。
|
|
7687
8055
|
paneRole === 'main' && h('button', {
|
|
@@ -8312,8 +8680,8 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
8312
8680
|
const [busy, setBusy] = React.useState(false)
|
|
8313
8681
|
const [error, setError] = React.useState('')
|
|
8314
8682
|
const [notice, setNotice] = React.useState('')
|
|
8315
|
-
//
|
|
8316
|
-
const [selectMenu, setSelectMenu] = React.useState(
|
|
8683
|
+
// 打开中的下拉:存它的 aria-label(见 selectControlOf)。
|
|
8684
|
+
const [selectMenu, setSelectMenu] = React.useState('')
|
|
8317
8685
|
React.useEffect(() => {
|
|
8318
8686
|
if (api === undefined) return undefined
|
|
8319
8687
|
let alive = true
|
|
@@ -8351,7 +8719,7 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
8351
8719
|
// 分组顺序按 provider 首次出现的顺序,组内保持宿主给的顺序 —— 不动宿主的排序。
|
|
8352
8720
|
const modelGroups = groupModelsByProvider(models.models)
|
|
8353
8721
|
const pickSelect = (label, value, options, onPick, extra) =>
|
|
8354
|
-
selectControlOf(setSelectMenu, label, value, options, onPick, extra)
|
|
8722
|
+
selectControlOf(selectMenu, setSelectMenu, label, value, options, onPick, extra)
|
|
8355
8723
|
return h('div', { className: 'paper-mineru' },
|
|
8356
8724
|
h('div', { className: 'paper-mineru-title' }, '解析'),
|
|
8357
8725
|
h('label', { className: 'paper-translate-row' },
|
|
@@ -8454,7 +8822,7 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
8454
8822
|
{ disabled: busy }),
|
|
8455
8823
|
notice === '' ? null : h('div', { className: 'paper-notice', role: 'status' }, notice),
|
|
8456
8824
|
error === '' ? null : h('div', { className: 'paper-error', role: 'alert' }, error),
|
|
8457
|
-
|
|
8825
|
+
)
|
|
8458
8826
|
}
|
|
8459
8827
|
|
|
8460
8828
|
/**
|
|
@@ -8683,126 +9051,74 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
8683
9051
|
strokeWidth: '1.6', strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': 'true', focusable: 'false',
|
|
8684
9052
|
}, h('path', { d: CHEVRON_PATH[direction] ?? CHEVRON_PATH.down }))
|
|
8685
9053
|
|
|
9054
|
+
|
|
8686
9055
|
/**
|
|
8687
|
-
*
|
|
8688
|
-
*
|
|
8689
|
-
* 三个面板(文献库主栏 / 阅读器 / 翻译设置)共用这一份,各自只持有自己的浮层状态。
|
|
8690
|
-
*/
|
|
8691
|
-
/**
|
|
8692
|
-
* 浮层:同一时刻只有一张,点外面收起。
|
|
8693
|
-
*
|
|
8694
|
-
* 原来两处各写一套 —— 主栏下拉挂了全局 click 监听,右栏那套什么都没挂(点别处不关),
|
|
8695
|
-
* 「添加论文」菜单只认自己的 Escape。这里收成一份注册表:打开 B 先关掉 A,点浮层与触发器
|
|
8696
|
-
* 之外的地方收起来。dwell(悬停 120ms 才展开)没有做:这些触发器都是点击打开的,鼠标
|
|
8697
|
-
* 经过工具栏时不该弹出菜单。
|
|
9056
|
+
* 选项表 → Menu 的 items。同名但不同来源的条目(同一个模型挂在多个 provider 下)
|
|
9057
|
+
* 用 `type:'label'` 起分组标题,那是 Menu 自己的装饰行,不可选中。
|
|
8698
9058
|
*/
|
|
8699
|
-
const
|
|
8700
|
-
const registerPopover = close => {
|
|
8701
|
-
if (popoverRegistry.close !== null && popoverRegistry.close !== close) popoverRegistry.close()
|
|
8702
|
-
popoverRegistry.close = close
|
|
8703
|
-
}
|
|
8704
|
-
const dismissPopover = () => {
|
|
8705
|
-
const close = popoverRegistry.close
|
|
8706
|
-
popoverRegistry.close = null
|
|
8707
|
-
if (typeof close === 'function') close()
|
|
8708
|
-
}
|
|
8709
|
-
if (typeof document !== 'undefined' && typeof document.addEventListener === 'function' && popoverRegistry.listening === false) {
|
|
8710
|
-
popoverRegistry.listening = true
|
|
8711
|
-
document.addEventListener('pointerdown', event => {
|
|
8712
|
-
if (popoverRegistry.close === null) return
|
|
8713
|
-
const target = event?.target
|
|
8714
|
-
// 触发器与浮层自己:让它们的 onClick 处理(触发器是 toggle,浮层自己会关)。
|
|
8715
|
-
if (typeof target?.closest === 'function' && target.closest('.paper-select,.paper-import-control,.paper-menu,.paper-import-menu')) return
|
|
8716
|
-
dismissPopover()
|
|
8717
|
-
}, true)
|
|
8718
|
-
}
|
|
8719
|
-
const openSelect = (setMenu, event, options, value, onPick) => {
|
|
8720
|
-
event.preventDefault()
|
|
8721
|
-
event.stopPropagation()
|
|
8722
|
-
const rect = event.currentTarget?.getBoundingClientRect?.()
|
|
9059
|
+
const menuItemsOf = options => {
|
|
8723
9060
|
const items = []
|
|
8724
9061
|
let group = ''
|
|
8725
|
-
for (const option of options) {
|
|
9062
|
+
for (const [index, option] of options.entries()) {
|
|
8726
9063
|
if (option.group !== undefined && option.group !== group) {
|
|
8727
9064
|
group = option.group
|
|
8728
|
-
items.push({ label: group,
|
|
9065
|
+
items.push({ type: 'label', id: 'group:' + group, text: group })
|
|
8729
9066
|
}
|
|
8730
|
-
items.push({
|
|
8731
|
-
label: option.label,
|
|
8732
|
-
checked: String(option.value) === String(value),
|
|
8733
|
-
run: () => { if (String(option.value) !== String(value)) onPick(option.value) },
|
|
8734
|
-
})
|
|
9067
|
+
items.push({ id: 'option:' + index, label: option.label, disabled: option.disabled === true })
|
|
8735
9068
|
}
|
|
8736
|
-
|
|
8737
|
-
|
|
8738
|
-
|
|
8739
|
-
|
|
8740
|
-
|
|
8741
|
-
|
|
8742
|
-
|
|
8743
|
-
|
|
8744
|
-
|
|
8745
|
-
|
|
8746
|
-
|
|
8747
|
-
|
|
8748
|
-
|
|
8749
|
-
|
|
8750
|
-
|
|
8751
|
-
|
|
8752
|
-
|
|
8753
|
-
|
|
8754
|
-
|
|
8755
|
-
|
|
8756
|
-
|
|
8757
|
-
|
|
8758
|
-
|
|
8759
|
-
|
|
8760
|
-
|
|
8761
|
-
|
|
8762
|
-
|
|
8763
|
-
|
|
8764
|
-
|
|
8765
|
-
|
|
8766
|
-
|
|
8767
|
-
|
|
8768
|
-
|
|
8769
|
-
|
|
8770
|
-
|
|
8771
|
-
|
|
8772
|
-
|
|
8773
|
-
|
|
8774
|
-
|
|
8775
|
-
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
|
|
8779
|
-
|
|
8780
|
-
|
|
8781
|
-
|
|
8782
|
-
|
|
8783
|
-
|
|
8784
|
-
|
|
8785
|
-
|
|
8786
|
-
|
|
8787
|
-
|
|
8788
|
-
|
|
8789
|
-
style: {
|
|
8790
|
-
// 首帧的近似位置(测量前的兜底);真正的摆位在 ref 里按实测宽高修正。
|
|
8791
|
-
left: Math.max(0, Math.min(menu.x, (typeof window === 'undefined' ? menu.x : window.innerWidth)
|
|
8792
|
-
- Math.max(150, (menu.minWidth ?? 0) + 16))) + 'px',
|
|
8793
|
-
top: menu.y + 'px',
|
|
8794
|
-
maxWidth: 'calc(100vw - 16px)',
|
|
8795
|
-
...(menu.minWidth ? { minWidth: Math.max(132, menu.minWidth) + 'px' } : {}),
|
|
8796
|
-
},
|
|
8797
|
-
}, (menu.items ?? []).map((item, index) => item.heading === true
|
|
8798
|
-
? h('div', { className: 'paper-menu-label', key: 'h:' + index }, item.label)
|
|
8799
|
-
: h('button', {
|
|
8800
|
-
key: item.label + ':' + index,
|
|
8801
|
-
type: 'button',
|
|
8802
|
-
className: item.checked === true ? 'active' : '',
|
|
8803
|
-
disabled: item.disabled === true,
|
|
8804
|
-
onClick: () => { setMenu(null); void item.run() },
|
|
8805
|
-
}, item.label)))
|
|
9069
|
+
return items
|
|
9070
|
+
}
|
|
9071
|
+
/**
|
|
9072
|
+
* 一个下拉,用宿主的 Menu 渲染(D198)。
|
|
9073
|
+
*
|
|
9074
|
+
* 🔴 原来是自己画的:按钮 + `openSelect` 摆位 + `renderSelectMenu` 出浮层。那套要自己
|
|
9075
|
+
* 处理视口边界、翻转方向、滚动上限、点外关闭、键盘走位,每一项都容易漏(摆位那条就漏
|
|
9076
|
+
* 过一次:十条长路径的集合列表顶穿屏幕底部,后面几项点都点不到)。宿主 `Menu` 这些都做过了,
|
|
9077
|
+
* 而且 `portal` 直接把浮层挂到 `document.body` —— 侧栏再窄也裁不到它。
|
|
9078
|
+
*
|
|
9079
|
+
* 值仍然按**渲染顺序下标**回传:`onSelect` 给的是 item id,把它映回第几个选项,
|
|
9080
|
+
* 调用方拿到的还是自己的值,不必关心列表长什么样。
|
|
9081
|
+
*
|
|
9082
|
+
* @param {string} label 无障碍名,也是测试找这个控件的把手。
|
|
9083
|
+
* @param {*} value 当前值(与选项的 value 严格按字符串比对)。
|
|
9084
|
+
* @param {Array<{value:*, label:string, group?:string, disabled?:boolean}>} options 选项表。
|
|
9085
|
+
* @param {(value:*) => void} onPick 选中回调;选中的是与当前值相同的项时不回调。
|
|
9086
|
+
* @param {object} [extra] `className`/`style`/`disabled`/`title`,与原来的用法一致。
|
|
9087
|
+
*/
|
|
9088
|
+
const selectControlOf = (open, setOpen, label, value, options, onPick, extra = {}) => {
|
|
9089
|
+
const items = menuItemsOf(options)
|
|
9090
|
+
const current = options.findIndex(option => String(option.value) === String(value))
|
|
9091
|
+
const shown = options[current]?.label ?? ''
|
|
9092
|
+
return h(Menu, {
|
|
9093
|
+
open: open === label,
|
|
9094
|
+
onClose: () => setOpen(''),
|
|
9095
|
+
items,
|
|
9096
|
+
selectedId: current < 0 ? undefined : 'option:' + current,
|
|
9097
|
+
onSelect: id => {
|
|
9098
|
+
setOpen('')
|
|
9099
|
+
const index = Number(String(id).slice('option:'.length))
|
|
9100
|
+
const option = options[index]
|
|
9101
|
+
if (option === undefined) return
|
|
9102
|
+
if (String(option.value) !== String(value)) onPick(option.value)
|
|
9103
|
+
},
|
|
9104
|
+
// 浮层挂到 body:祖先的 overflow 一律裁不到它(侧栏最窄 300px 时的老问题)。
|
|
9105
|
+
portal: true,
|
|
9106
|
+
minWidthFromAnchor: true,
|
|
9107
|
+
anchor: h('button', {
|
|
9108
|
+
className: 'paper-input paper-select' + (extra.className === undefined ? '' : ' ' + extra.className),
|
|
9109
|
+
type: 'button',
|
|
9110
|
+
'aria-label': label,
|
|
9111
|
+
'aria-haspopup': 'menu',
|
|
9112
|
+
'aria-expanded': open === label,
|
|
9113
|
+
...(extra.title === undefined ? {} : { title: extra.title }),
|
|
9114
|
+
...(extra.style === undefined ? {} : { style: extra.style }),
|
|
9115
|
+
...(extra.disabled === undefined ? {} : { disabled: extra.disabled }),
|
|
9116
|
+
onClick: () => setOpen(open === label ? '' : label),
|
|
9117
|
+
}, h('span', null, shown),
|
|
9118
|
+
h('span', { className: 'paper-select-caret', 'aria-hidden': 'true' }, chevronIcon('down'))),
|
|
9119
|
+
})
|
|
9120
|
+
}
|
|
9121
|
+
|
|
8806
9122
|
function paperIdFromAddress(address) {
|
|
8807
9123
|
return typeof address === 'string' && address.startsWith(PAPER_RESOURCE) ? address.slice(PAPER_RESOURCE.length).split(/[?#]/)[0] : ''
|
|
8808
9124
|
}
|
|
@@ -9550,7 +9866,6 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
9550
9866
|
const timer = setInterval(refreshQueue, 2000)
|
|
9551
9867
|
return () => clearInterval(timer)
|
|
9552
9868
|
}, [refreshQueue])
|
|
9553
|
-
// 点外面收起浮层由模块级的 popoverRegistry 统一负责(见 registerPopover)。
|
|
9554
9869
|
|
|
9555
9870
|
const items = Array.isArray(library?.items) ? library.items : []
|
|
9556
9871
|
const view = library?.library ?? {}
|
|
@@ -10155,16 +10470,77 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
10155
10470
|
{ label: entry.item?.pinned === true ? '取消置顶' : '置顶', run: () => paperAction(entry.documentId, { action: 'pin', pinned: entry.item?.pinned !== true }) },
|
|
10156
10471
|
{ label: entry.item?.trashed === true ? '从回收站恢复' : '移入回收站', run: () => paperAction(entry.documentId, { action: entry.item?.trashed === true ? 'restore' : 'trash' }) },
|
|
10157
10472
|
]
|
|
10473
|
+
/**
|
|
10474
|
+
* 右键菜单(光标处开)。
|
|
10475
|
+
*
|
|
10476
|
+
* 用宿主 Menu 的 `anchorPoint` + `portal`:坐标不来自某个元素,而是光标位置,
|
|
10477
|
+
* Menu 会把根 span 钉在那一格再让浮层按 CSS anchor 定位。`contextual` 负责
|
|
10478
|
+
* 「右键不关闭、按行对齐分隔线」这些右键菜单才有的行为。
|
|
10479
|
+
*/
|
|
10158
10480
|
const openMenuAt = (event, menuItems) => {
|
|
10159
10481
|
event.preventDefault()
|
|
10160
10482
|
event.stopPropagation()
|
|
10161
10483
|
setMenu({ x: event.clientX, y: event.clientY, items: menuItems })
|
|
10162
10484
|
}
|
|
10485
|
+
const contextMenu = () => menu === null ? null : h(Menu, {
|
|
10486
|
+
open: true,
|
|
10487
|
+
onClose: () => setMenu(null),
|
|
10488
|
+
contextual: true,
|
|
10489
|
+
portal: true,
|
|
10490
|
+
autoFocus: true,
|
|
10491
|
+
anchorPoint: { x: menu.x, y: menu.y },
|
|
10492
|
+
anchor: null,
|
|
10493
|
+
items: menu.items.map((item, index) => item.heading === true
|
|
10494
|
+
? { type: 'label', id: 'label:' + index, text: item.label }
|
|
10495
|
+
: { id: 'item:' + index, label: item.label, disabled: item.disabled === true }),
|
|
10496
|
+
onSelect: id => {
|
|
10497
|
+
const item = menu.items[Number(String(id).slice('item:'.length))]
|
|
10498
|
+
setMenu(null)
|
|
10499
|
+
if (item !== undefined) void item.run()
|
|
10500
|
+
},
|
|
10501
|
+
})
|
|
10163
10502
|
|
|
10164
|
-
//
|
|
10503
|
+
// 下拉实现是模块级的(selectControlOf),这里只绑上本面板「哪一张开着」的状态。
|
|
10504
|
+
const [openSelect, setOpenSelect] = React.useState('')
|
|
10165
10505
|
const selectControl = (label, value, options, onPick, extra) =>
|
|
10166
|
-
selectControlOf(
|
|
10506
|
+
selectControlOf(openSelect, setOpenSelect, label, value, options, onPick, extra)
|
|
10167
10507
|
|
|
10508
|
+
/**
|
|
10509
|
+
* 「添加论文」菜单。
|
|
10510
|
+
*
|
|
10511
|
+
* 🔴 目标集合在**打开的那一刻**捕获(`importCollection`):用户很可能是先点开这个菜单、
|
|
10512
|
+
* 再换分类、然后才点「浏览文件」,那时 pick 已经变了,而"添加到哪儿"要按点开时看到的算。
|
|
10513
|
+
* 这条行为原来就有,换 Menu 之后不变。
|
|
10514
|
+
*/
|
|
10515
|
+
const addMenu = () => h(Menu, {
|
|
10516
|
+
open: addOpen,
|
|
10517
|
+
onClose: () => setAddOpen(false),
|
|
10518
|
+
portal: true,
|
|
10519
|
+
autoFocus: true,
|
|
10520
|
+
minWidthFromAnchor: true,
|
|
10521
|
+
items: [
|
|
10522
|
+
{ id: 'browse', label: '浏览文件' },
|
|
10523
|
+
{ id: 'folder', label: '打开文件夹' },
|
|
10524
|
+
{ id: 'bib', label: '导入书目文件' },
|
|
10525
|
+
{ type: 'separator', id: 'sep' },
|
|
10526
|
+
{ id: 'cancel', label: '取消' },
|
|
10527
|
+
],
|
|
10528
|
+
onSelect: id => {
|
|
10529
|
+
if (id === 'cancel') { setAddOpen(false); return }
|
|
10530
|
+
if (id === 'browse') { void addFromPicker(); return }
|
|
10531
|
+
if (id === 'folder') { void scanFolder(); return }
|
|
10532
|
+
setAddOpen(false)
|
|
10533
|
+
setBibliographyDialog({ mode: 'import', collectionId: pick.kind === 'collection' ? pick.name : undefined })
|
|
10534
|
+
},
|
|
10535
|
+
anchor: h('button', {
|
|
10536
|
+
className: 'paper-btn', type: 'button', disabled: busy,
|
|
10537
|
+
'aria-expanded': addOpen, 'aria-haspopup': 'menu',
|
|
10538
|
+
onClick: () => {
|
|
10539
|
+
setImportCollection(pick.kind === 'collection' ? pick.name : null)
|
|
10540
|
+
setAddOpen(!addOpen)
|
|
10541
|
+
},
|
|
10542
|
+
}, '添加论文', h(LibraryIcon, { kind: 'add' })),
|
|
10543
|
+
})
|
|
10168
10544
|
// 图标不从这里传:分类的图标**由语义唯一决定**(selection.kind / view 名 → LibraryIcon),
|
|
10169
10545
|
// 曾经额外带一个 icon 字符串参数,那些 Unicode 字形(▤ ▱ ⌕ ⌫)与 SVG 混在同一列里,
|
|
10170
10546
|
// 字族不同、重心也不同,排下来一眼就能看出不是一套。
|
|
@@ -10342,20 +10718,7 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
10342
10718
|
label: mode_ === 'title' ? '标题' : mode_ === 'opened' ? '最近打开' : '最近加入' })),
|
|
10343
10719
|
value => void categoryAction({ action: 'sort', sort: value }),
|
|
10344
10720
|
{ style: { flex: '0 0 96px' } }),
|
|
10345
|
-
|
|
10346
|
-
h('button', {
|
|
10347
|
-
className: 'paper-btn', type: 'button', disabled: busy, 'aria-expanded': addOpen, 'aria-haspopup': 'menu',
|
|
10348
|
-
onClick: () => {
|
|
10349
|
-
setImportCollection(pick.kind === 'collection' ? pick.name : null)
|
|
10350
|
-
if (addOpen) setAddOpen(false)
|
|
10351
|
-
else { registerPopover(() => setAddOpen(false)); setAddOpen(true) }
|
|
10352
|
-
}
|
|
10353
|
-
}, '添加论文', h(LibraryIcon, { kind: 'add' })),
|
|
10354
|
-
addOpen ? h('div', { className: 'paper-import-menu', role: 'menu', 'aria-label': '添加论文方式', onKeyDown: event => { const { key: pressed } = event; if (pressed === 'Escape') setAddOpen(false) } },
|
|
10355
|
-
h('button', { className: 'paper-btn', role: 'menuitem', onClick: () => void addFromPicker() }, '浏览文件'),
|
|
10356
|
-
h('button', { className: 'paper-btn', role: 'menuitem', onClick: () => void scanFolder() }, '打开文件夹'),
|
|
10357
|
-
h('button', { className: 'paper-btn', role: 'menuitem', onClick: () => { setAddOpen(false); setBibliographyDialog({ mode: 'import', collectionId: pick.kind === 'collection' ? pick.name : undefined }) } }, '导入书目文件'),
|
|
10358
|
-
h('button', { className: 'paper-btn', role: 'menuitem', onClick: () => setAddOpen(false) }, '取消')) : null),
|
|
10721
|
+
addMenu(),
|
|
10359
10722
|
h('button', { className: 'paper-btn', disabled: busy || !shown.length, onClick: () => setBibliographyDialog({ mode: 'export', documentIds: picked.length ? picked : selectedId ? [selectedId] : shown.map(row => row.documentId) }) }, '导出书目'),
|
|
10360
10723
|
h('button', { className: 'paper-btn', disabled: busy, onClick: () => setBibliographyDialog({ mode: 'styles' }) }, '引用样式'),
|
|
10361
10724
|
// 一键补全书目:全库范围,只碰缺作者/年份/DOI 的论文。写入条件由服务端把关。
|
|
@@ -10865,8 +11228,6 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
10865
11228
|
h('button', { className: 'paper-btn danger', type: 'button', disabled: busy, onClick: () => void confirmScan() }, '确认扫描'),
|
|
10866
11229
|
h('button', { className: 'paper-btn', type: 'button', onClick: () => setRisk(null) }, '取消')))
|
|
10867
11230
|
|
|
10868
|
-
const menuNode = () => renderSelectMenu(menu, setMenu)
|
|
10869
|
-
|
|
10870
11231
|
// Keep collections visible. A narrow work area puts details below the list.
|
|
10871
11232
|
// 🔴 同阅读页:opt-in 宿主的 overlay 契约,文献库自己内部滚动,不再把宿主整页顶滚(D180)。
|
|
10872
11233
|
return h('div', { className: 'paper-lib' + (narrow ? ' stacked' : '') + (selected ? ' has-selection' : ''), 'data-dsh-paper': true, 'data-conversation-composer-overlay': '', 'aria-busy': loading, ref: widthRef },
|
|
@@ -10877,7 +11238,7 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
10877
11238
|
bibliographyDialog ? h(BibliographyDialog, { ...bibliographyDialog, onClose: () => setBibliographyDialog(null), onChanged: load }) : null,
|
|
10878
11239
|
searchDraft ? searchDialog() : null,
|
|
10879
11240
|
h('datalist', { id: 'paper-existing-tags' }, allTags.map(tag => h('option', { key: tag, value: tag }))),
|
|
10880
|
-
|
|
11241
|
+
contextMenu())
|
|
10881
11242
|
}
|
|
10882
11243
|
|
|
10883
11244
|
function apply(ctx) {
|
|
@@ -11136,9 +11497,6 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
11136
11497
|
// 「浏览文件」的回执文案(D182),test/add-report.test.js 直接断言。
|
|
11137
11498
|
exports.addReport = addReport
|
|
11138
11499
|
// 滑动多选与批量动作的纯函数,供 test/batch-ui.test.js 直接断言。
|
|
11139
|
-
// 浮层注册表(唯一打开 + 点外收起):测试直接驱动它,不必挂组件。
|
|
11140
|
-
exports.registerPopover = registerPopover
|
|
11141
|
-
exports.dismissPopover = dismissPopover
|
|
11142
11500
|
exports.rangeIds = rangeIds
|
|
11143
11501
|
exports.unionIds = unionIds
|
|
11144
11502
|
exports.toggleId = toggleId
|
|
@@ -11222,8 +11580,6 @@ h4.paper-reader-block{font-size:13px;font-weight:650}
|
|
|
11222
11580
|
exports.progressText = progressText
|
|
11223
11581
|
exports.rowMetaText = rowMetaText
|
|
11224
11582
|
exports.LIBRARY_BUCKETS = LIBRARY_BUCKETS
|
|
11225
|
-
// 浮层摆位单独导出:它靠 ref 回调在挂载后测量,React 替身不跑 ref,只有直接调用才测得到。
|
|
11226
|
-
exports.placeSelectMenu = placeSelectMenu
|
|
11227
11583
|
exports.outlineEntries = outlineEntries
|
|
11228
11584
|
exports.markScrollTarget = markScrollTarget
|
|
11229
11585
|
// 全局文献库(T21)的纯函数:分组与排序,供 test/library-view.test.js 直接断言。
|
package/lib/pdf-page.js
CHANGED
|
@@ -303,7 +303,18 @@ const MAX_MATCHED_DISTANCE = 200
|
|
|
303
303
|
* · {@link GUTTER_TOLERANCE} —— 沟里被别的行压住的比例上限。通栏标题、满宽图注会横穿
|
|
304
304
|
* 栏间沟;只按「完全为空」判,带通栏标题的双栏页就再也找不到栏了。
|
|
305
305
|
*/
|
|
306
|
+
/**
|
|
307
|
+
* 兜底档的栏间沟门槛。
|
|
308
|
+
*
|
|
309
|
+
* 🔴 1.6 这个门槛把**真实存在的窄沟**挡在门外:全库 53 页实测,最窄的一道真实栏间沟
|
|
310
|
+
* 只有 1.03 个行高(IEEE 1981 双栏,左栏右沿 484、右栏左沿 498,沟宽 14.1,行高 14.13)。
|
|
311
|
+
* 那种页面上一道沟都切不出来,阅读顺序退化成一维 y 序,DOM 里左右两栏逐行交替 ——
|
|
312
|
+
* 用户从左栏往下拖,右栏几十行跟着涂蓝。
|
|
313
|
+
*
|
|
314
|
+
* 兜底档只在严格档一道栏都切不出来时启用,且**不进递归**(见 orderRegion)。
|
|
315
|
+
*/
|
|
306
316
|
const COLUMN_GUTTER_UNITS = 1.6
|
|
317
|
+
const RELAXED_GUTTER_UNITS = 0.9
|
|
307
318
|
const ROW_GUTTER_UNITS = 0.55
|
|
308
319
|
const GUTTER_TOLERANCE = 0.12
|
|
309
320
|
|
|
@@ -339,15 +350,23 @@ function lineReadingOrder(lines) {
|
|
|
339
350
|
if (lines.length <= 1) return lines
|
|
340
351
|
const heights = lines.map(line => line.box[3] - line.box[1]).filter(height => height > 0).sort((a, b) => a - b)
|
|
341
352
|
const unit = heights.length > 0 ? heights[heights.length >> 1] : 0
|
|
342
|
-
return unit > 0 ? orderRegion(lines, unit) : [...lines].sort(readingTop)
|
|
353
|
+
return unit > 0 ? orderRegion(lines, unit, true) : [...lines].sort(readingTop)
|
|
343
354
|
}
|
|
344
355
|
|
|
345
356
|
/** 一个局部版面的递归切分:能切栏就切栏,否则切段,否则按 y。 */
|
|
346
|
-
function orderRegion(lines, unit) {
|
|
357
|
+
function orderRegion(lines, unit, allowRelaxed = false) {
|
|
347
358
|
if (lines.length <= 1) return lines
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
359
|
+
// 🔴 **严格优先,放宽兜底,且放宽只给顶层。**
|
|
360
|
+
//
|
|
361
|
+
// 放宽档把居中元素(标题折行、作者行、ISSN 页脚)排除出遮挡,于是窄沟也能成立;
|
|
362
|
+
// 但它同样会在**已经切好的一栏内部**凭空切出假栏 —— 全库实测,无条件放宽时
|
|
363
|
+
// 5 页改善、7 页变差,其中把 L:1 R:1 的干净页面切成 L:2 R:3。
|
|
364
|
+
// 所以:先按原门槛严格切;切不出来才退到放宽档,且**栏内不再放宽**。
|
|
365
|
+
const strict = splitAxis(lines, unit, 0, COLUMN_GUTTER_UNITS, false)
|
|
366
|
+
if (strict !== null) return columnOrder(lines, strict, unit, false)
|
|
367
|
+
const relaxed = allowRelaxed ? splitAxis(lines, unit, 0, RELAXED_GUTTER_UNITS, true) : null
|
|
368
|
+
if (relaxed !== null) return columnOrder(lines, relaxed, unit, true)
|
|
369
|
+
const rows = splitAxis(lines, unit, 1, ROW_GUTTER_UNITS, false)
|
|
351
370
|
if (rows !== null) return sliceByCuts(lines, 1, rows.map(gap => (gap.from + gap.to) / 2)).flatMap(row => orderRegion(row, unit))
|
|
352
371
|
return [...lines].sort(readingTop)
|
|
353
372
|
}
|
|
@@ -382,7 +401,7 @@ function sliceByCuts(lines, axis, cuts) {
|
|
|
382
401
|
* @param {number} unit 行高
|
|
383
402
|
* @returns {object[]} 按阅读顺序
|
|
384
403
|
*/
|
|
385
|
-
function columnOrder(lines, gaps, unit) {
|
|
404
|
+
function columnOrder(lines, gaps, unit, relaxed = false) {
|
|
386
405
|
// 🔴 **跨栏**的意思是"横穿整道沟",不是"碰到沟"。只按切割中线判会把**探进沟里**但没
|
|
387
406
|
// 穿过去的那一行也算成跨栏 —— 实测夹具里左栏段落右沿到 420、沟是 300–514,它只是
|
|
388
407
|
// 探进沟里 120,却被当成跨栏行抽走,于是整页顺序错位。判据必须是两端都在沟外。
|
|
@@ -413,10 +432,33 @@ function columnOrder(lines, gaps, unit) {
|
|
|
413
432
|
* 单栏页上由此得到的"沟"两侧必有一侧没有整行(正文横跨整页),于是被这条判据挡掉,
|
|
414
433
|
* 不会把单栏页切成两半。
|
|
415
434
|
*/
|
|
416
|
-
function splitAxis(lines, unit, axis, units) {
|
|
417
|
-
const gaps = freeIntervals(lines, axis, unit)
|
|
435
|
+
function splitAxis(lines, unit, axis, units, relaxed = false) {
|
|
436
|
+
const gaps = freeIntervals(lines, axis, unit, relaxed)
|
|
418
437
|
.filter(([from, to]) => to - from >= unit * units)
|
|
419
|
-
.filter(([from, to]) =>
|
|
438
|
+
.filter(([from, to]) => {
|
|
439
|
+
// 严格档沿用原判据(两侧各至少一行):**改造前的行为要逐字节保留**,
|
|
440
|
+
// 否则放宽一档的收益会被严格档的收紧抵消掉(全库实测:收紧后 2 页改善、5 页变差)。
|
|
441
|
+
// 兜底档才要求两侧都有足够的行 —— 那一档的门槛低得多,一个落单的词就能切出假栏。
|
|
442
|
+
const need = relaxed ? Math.max(3, Math.ceil(lines.length * 0.15)) : 1
|
|
443
|
+
const left = lines.filter(line => line.box[axis + 2] <= from)
|
|
444
|
+
const right = lines.filter(line => line.box[axis] >= to)
|
|
445
|
+
if (left.length < need || right.length < need) return false
|
|
446
|
+
// 🔴 兜底档还要求两侧各有**真正的正文行**,不能只是孤字。
|
|
447
|
+
// 实测(4aeb3d6f 第 1 页):x=484–492 处挂着一个孤字 "1"(宽 8、高 11),
|
|
448
|
+
// 它一侧的行数达标,可那一侧其实只有一个字符 —— 于是切出一道假沟,
|
|
449
|
+
// 把一个完整的右栏劈成两段,DOM 段数 0 → 1。
|
|
450
|
+
//
|
|
451
|
+
// 判据用**行的宽度**而不是高度合计:宽度直接说明"这一侧排着正文",
|
|
452
|
+
// 高度合计会被一列落单词堆出来,也容易被孤零零的一行撑够。
|
|
453
|
+
// 门槛取中位行宽的 40%:真正的栏里至少有一行排到这个宽度,孤字永远到不了。
|
|
454
|
+
if (!relaxed) return true
|
|
455
|
+
const widthsOf = side => side.map(line => line.box[axis + 2] - line.box[axis]).filter(width => width > 0).sort((a, b) => a - b)
|
|
456
|
+
const allWidths = widthsOf(lines)
|
|
457
|
+
const typicalWidth = allWidths.length > 0 ? allWidths[allWidths.length >> 1] : 0
|
|
458
|
+
if (!(typicalWidth > 0)) return false
|
|
459
|
+
const hasBody = side => side.some(line => line.box[axis + 2] - line.box[axis] >= typicalWidth * 0.4)
|
|
460
|
+
return hasBody(left) && hasBody(right)
|
|
461
|
+
})
|
|
420
462
|
// 🔴 每层只切**一道**最宽的沟。递归会在每一栏内部继续找下一道,所以多栏页面照样
|
|
421
463
|
// 切得出来;但同一层切好几刀时,一道被落单的字劈开的沟会被当成两道,中间凭空多出
|
|
422
464
|
// 一栏(只装那一个字),两侧正文反而落到更远的栏里。
|
|
@@ -444,7 +486,7 @@ function splitAxis(lines, unit, axis, units) {
|
|
|
444
486
|
* @param {number} unit 行高
|
|
445
487
|
* @returns {Array<[number, number]>} 按位置升序的空白区间
|
|
446
488
|
*/
|
|
447
|
-
function freeIntervals(lines, axis, unit) {
|
|
489
|
+
function freeIntervals(lines, axis, unit, relaxed = false) {
|
|
448
490
|
const across = axis === 0 ? 1 : 0
|
|
449
491
|
const from = Math.min(...lines.map(line => line.box[axis]))
|
|
450
492
|
const to = Math.max(...lines.map(line => line.box[axis + 2]))
|
|
@@ -503,6 +545,25 @@ function freeIntervals(lines, axis, unit) {
|
|
|
503
545
|
const widths = textWidths.length > 0 ? textWidths : widthsOf(() => true)
|
|
504
546
|
const typical = widths.length > 0 ? widths[widths.length >> 1] : 0
|
|
505
547
|
const spanning = line => typical > 0 && line.box[axis + 2] - line.box[axis] >= typical * 1.5
|
|
548
|
+
// 🔴 **居中元素不算挡路**(兜底档才有)。
|
|
549
|
+
//
|
|
550
|
+
// 实测(Robert G. Keys 1981 第 1 页):标题折行 "Processing"、作者 "ROBERT G. KEYS"、
|
|
551
|
+
// 页脚 ISSN 号三行横跨栏间沟,合起来在沟上盖了 58.8 高 —— 正好等于沟上全部覆盖量。
|
|
552
|
+
// 它们既不属于左栏也不属于右栏,可又都**不够宽**,逃不过通栏豁免(中位行宽 410、
|
|
553
|
+
// 门槛 615,它们只有 174 / 129 / 317),于是整道沟被判死。
|
|
554
|
+
//
|
|
555
|
+
// 判据:宽度不到通栏、且中点贴近版面中线。两条都要,缺一条就会把**贴着中线起排的
|
|
556
|
+
// 正文行**也算进来 —— 那会真的把沟让开,属于放行过多。
|
|
557
|
+
const midway = (from + to) / 2
|
|
558
|
+
const centred = line => {
|
|
559
|
+
const width = line.box[axis + 2] - line.box[axis]
|
|
560
|
+
// 🔴 **下界不能省**:一个落在页面中线上的孤字(实测宽度 8,中位行宽 191)也会满足
|
|
561
|
+
// "贴近中线 + 不够通栏"两条,被豁免掉之后反而在它身上切出一道假沟,把一个本来
|
|
562
|
+
// 干净的页面切成两栏。真正的居中元素(标题、作者行)至少占正文宽度的一大截。
|
|
563
|
+
// 上界:够宽就已经是通栏行了,不需要这条豁免。
|
|
564
|
+
if (!(typical > 0) || !(width >= typical * 0.3) || !(width < typical * 1.5)) return false
|
|
565
|
+
return Math.abs((line.box[axis] + line.box[axis + 2]) / 2 - midway) <= typical * 0.35
|
|
566
|
+
}
|
|
506
567
|
for (const line of lines) {
|
|
507
568
|
const start = line.box[axis]
|
|
508
569
|
const end = line.box[axis + 2]
|
|
@@ -511,13 +572,34 @@ function freeIntervals(lines, axis, unit) {
|
|
|
511
572
|
bump(start, weight)
|
|
512
573
|
bump(end, -weight)
|
|
513
574
|
}
|
|
514
|
-
|
|
575
|
+
// 🔴 兜底档另算一条**只累加正文行**的投影:居中元素排除在外。
|
|
576
|
+
// 严格档直接用上面那条原有投影,行为与改造前逐字节一致 —— 放宽只在真的切不出栏时发生。
|
|
577
|
+
const relaxedDeltas = new Map()
|
|
578
|
+
if (relaxed) {
|
|
579
|
+
const relaxedBump = (key, value) => relaxedDeltas.set(key, (relaxedDeltas.get(key) ?? 0) + value)
|
|
580
|
+
relaxedBump(from, 0)
|
|
581
|
+
relaxedBump(to, 0)
|
|
582
|
+
for (const line of lines) {
|
|
583
|
+
const start = line.box[axis]
|
|
584
|
+
const end = line.box[axis + 2]
|
|
585
|
+
const weight = line.box[across + 2] - line.box[across]
|
|
586
|
+
if (!(end > start) || !(weight > 0) || spanning(line) || centred(line)) continue
|
|
587
|
+
relaxedBump(start, weight)
|
|
588
|
+
relaxedBump(end, -weight)
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
const positions = relaxed
|
|
592
|
+
? [...new Set([...deltas.keys(), ...relaxedDeltas.keys()])].sort((a, b) => a - b)
|
|
593
|
+
: [...deltas.keys()].sort((a, b) => a - b)
|
|
515
594
|
const raw = []
|
|
516
595
|
let depth = 0
|
|
596
|
+
let relaxedDepth = 0
|
|
517
597
|
for (let i = 0; i < positions.length - 1; i += 1) {
|
|
518
|
-
depth += deltas.get(positions[i])
|
|
598
|
+
depth += deltas.get(positions[i]) ?? 0
|
|
599
|
+
if (relaxed) relaxedDepth += relaxedDeltas.get(positions[i]) ?? 0
|
|
519
600
|
// 容差而不是 0:depth 是浮点累加量,见上面 epsilon 的说明。
|
|
520
|
-
|
|
601
|
+
// 兜底档看**排除居中元素之后**的覆盖:那才是真正的正文遮挡。
|
|
602
|
+
if ((relaxed ? relaxedDepth : depth) > epsilon) continue
|
|
521
603
|
const start = positions[i]
|
|
522
604
|
const end = positions[i + 1]
|
|
523
605
|
if (end > start) raw.push([start, end])
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@li-canghai/dsh-paper",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.6",
|
|
4
4
|
"description": "PDF transcription with stable block ids, folder scanning up to two sub-levels, and session-scoped paper context with drag-select batch injection and removal for DSH.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -59,4 +59,4 @@
|
|
|
59
59
|
]
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
}
|
|
62
|
+
}
|