dsh-reading-focus 0.8.4 → 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/README.en.md +71 -35
- package/README.md +53 -205
- package/lib/client.js +97 -28
- package/package.json +2 -2
- package/preview.html +97 -28
package/README.en.md
CHANGED
|
@@ -1,67 +1,103 @@
|
|
|
1
|
-
<p align="center"><img src="icon.svg" width="
|
|
1
|
+
<p align="center"><img src="icon.svg" width="88" alt="Reading Focus"></p>
|
|
2
2
|
|
|
3
3
|
<h1 align="center">Reading Focus for DeepSeek Harness</h1>
|
|
4
4
|
|
|
5
|
-
<p align="center">
|
|
5
|
+
<p align="center">Gradient text, a reading ruler, line and block focus, and colour bands for the DeepSeek Harness chat transcript.</p>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
<a href="https://github.com/smallflycar/dsh-reading-focus"><img alt="GitHub" src="https://img.shields.io/badge/GitHub-repo-24292f.svg"></a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/dsh-reading-focus"><img alt="npm" src="https://img.shields.io/npm/v/dsh-reading-focus"></a>
|
|
9
10
|
<a href="https://github.com/smallflycar/dsh-reading-focus/releases"><img alt="Release" src="https://img.shields.io/github/v/release/smallflycar/dsh-reading-focus"></a>
|
|
10
|
-
<a href="LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-2f6fed.svg"></a>
|
|
11
|
-
<img alt="DSH" src="https://img.shields.io/badge/DSH-0.2.2--rc.3%20%7C%200.2.x-4f70d9.svg">
|
|
12
|
-
<a href="README.md"><img alt="中文" src="https://img.shields.io/badge/lang-%E4%B8%AD%E6%96%87-6b7686.svg"></a>
|
|
13
11
|
</p>
|
|
14
12
|
|
|
15
|
-
>
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="README.md">简体中文</a> · <a href="README.en.md">English</a>
|
|
15
|
+
</p>
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## Why this exists
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
- **Reading ruler** — a faint band with two solid edge lines that follows the pointer; medium scroll protection so it stays aligned while scrolling.
|
|
21
|
-
- **Line focus** — the rows under the pointer stay fully transparent while the rest of the page is dimmed.
|
|
22
|
-
- **Block focus** — the current paragraph stays as it is and the rest either fades its text or dims behind a veil.
|
|
23
|
-
- **Colour bands** — alternating blocks separate adjacent passages; code blocks and headings are excluded, tables are banded, and a tool call does not restart the hue cycle.
|
|
19
|
+
I spend more and more of my day in an agent. Its output is long and keeps piling up: an answer runs to a thousand words, and a few turns become screen after screen of transcript. The way I work with it is stop-start as well — send a task, wait, come back and keep reading. Reading that much text is tiring, and attention drifts.
|
|
24
20
|
|
|
25
|
-
|
|
21
|
+
Reading rulers, line focus and colour bands have existed in browsers for a long time, to make long text easier to read. Agent transcripts are longer and denser, and I think they need those aids more, so I brought a few of them into the DSH transcript.
|
|
26
22
|
|
|
27
|
-
##
|
|
23
|
+
## Features
|
|
28
24
|
|
|
29
|
-
|
|
25
|
+
- **Gradient reading** — gradient text that advances line by line, switching hue every two lines.
|
|
26
|
+
- **Reading ruler** — a faint band with a solid line on each edge, following the pointer.
|
|
27
|
+
- **Line focus** — the rows near the pointer stay clear while the rest is dimmed.
|
|
28
|
+
- **Block focus** — the current paragraph stays as it is and the rest fades or dims.
|
|
29
|
+
- **Colour bands** — adjacent passages separated by cycling colour blocks; code and headings stay plain.
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
## Screenshots
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
dsh plugin --profile <profile> add dsh-reading-focus
|
|
33
|
+

|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
dsh plugin --profile <profile> add https://github.com/smallflycar/dsh-reading-focus/releases/download/v0.8.4/dsh-reading-focus-0.8.4.tgz
|
|
35
|
+
*Gradient reading: body text only, advancing line by line.*
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
npm run build && npm run pack
|
|
41
|
-
dsh plugin --profile <profile> add ./dist/dsh-reading-focus-0.8.4.tgz
|
|
37
|
+

|
|
42
38
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
*Colour bands: adjacent passages separated by cycling colours; code and headings stay plain.*
|
|
40
|
+
|
|
41
|
+

|
|
42
|
+
|
|
43
|
+
*Reading ruler: a faint band with a solid line on each edge.*
|
|
44
|
+
|
|
45
|
+

|
|
46
|
+
|
|
47
|
+
*Block focus: the current paragraph stays as it is, the rest fades or dims.*
|
|
48
|
+
|
|
49
|
+
*Screenshots come from the local preview page `preview.html` and are illustrative.*
|
|
50
|
+
|
|
51
|
+
## Install
|
|
46
52
|
|
|
47
|
-
|
|
53
|
+
**DSH Desktop**: open **Settings → Plugins → Add plugin**, enter `dsh-reading-focus`, install, then refresh the page.
|
|
48
54
|
|
|
49
|
-
|
|
55
|
+
**Command line**:
|
|
50
56
|
|
|
51
57
|
```bash
|
|
52
|
-
|
|
53
|
-
npm test # build + 17 assertions (logic, structure, artifact equality)
|
|
54
|
-
npm run test:browser # 19 rendering assertions in headless Chrome
|
|
55
|
-
npm run test:browser:geometry # 7 geometry assertions in headless Chrome
|
|
56
|
-
npm run pack # dist/dsh-reading-focus-<version>.tgz
|
|
58
|
+
dsh plugin --profile <profile> add dsh-reading-focus
|
|
57
59
|
```
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
Requires DSH 0.2.x. You can also install the tarball from the [latest release](https://github.com/smallflycar/dsh-reading-focus/releases/latest).
|
|
60
62
|
|
|
61
63
|
## Compatibility
|
|
62
64
|
|
|
63
|
-
|
|
65
|
+
| DSH version | Reading body | Markdown root | Status |
|
|
66
|
+
| --- | --- | --- | --- |
|
|
67
|
+
| 0.2.3-alpha.1 and later | `xMeOpW_body` | `<hash>_markdown` (e.g. `-TmMFa_markdown`) | ✅ tested on 0.2.3-alpha.2 |
|
|
68
|
+
| 0.2.2 rc line | `xMeOpW_body` | `_markdown_<hash>_<n>` | ✅ |
|
|
69
|
+
| 0.2.1 and earlier | `v5IAXa_body` | `_markdown_<hash>_<n>` | ✅ by structure, not tested |
|
|
70
|
+
|
|
71
|
+
Build hashes inside those class names are build artefacts and have nothing to do with the operating system; the plugin depends on neither the hash nor the order inside a class name:
|
|
72
|
+
|
|
73
|
+
- a reading body is a container whose class token ends in `_body`, that holds a markdown root directly, and that is not inside a non-`assistant-step` flow item (tool rows, command rows);
|
|
74
|
+
- a markdown root is a direct child whose class token contains `markdown`, so both `_markdown_<hash>_<n>` and `<hash>_markdown` are accepted;
|
|
75
|
+
- if a host renames the `body` local too, the plugin falls back to structure: the container of markdown roots inside a chat flow.
|
|
76
|
+
|
|
77
|
+
A DSH patch release, another machine or another OS therefore needs no selector update. The one case that still needs work is the host renaming the `markdown` local or moving markdown roots into another container.
|
|
78
|
+
|
|
79
|
+
## Changelog
|
|
80
|
+
|
|
81
|
+
**0.8.6** — adapts to the class-name change in DSH 0.2.3-alpha.1. That release moved `dsh-client-ui-primitives` into the frontend bundle, so the markdown root went from `_markdown_<hash>_<n>` to `<hash>_markdown` and the old selector found no reading block at all. Both orders and any hash are recognised now, and tool/command rows that also end in `_body` are kept out of the reading body.
|
|
82
|
+
|
|
83
|
+
**0.8.5** — stops hard-coding the body hash; the line-height override anchors on the plugin's own `data-reading-focus-body` marker and is removed together with the override.
|
|
84
|
+
|
|
85
|
+
## Usage
|
|
86
|
+
|
|
87
|
+
1. Open **Settings → Reading Focus** and turn on the switch.
|
|
88
|
+
2. Pick a mode; the panel shows only the controls that apply.
|
|
89
|
+
3. Use **Adjust in the transcript** to tune it while reading.
|
|
90
|
+
4. Everything is saved and restored on the next open.
|
|
91
|
+
|
|
92
|
+
Light and dark themes both work. Code, tables and headings are always left alone.
|
|
93
|
+
|
|
94
|
+
## Notes
|
|
95
|
+
|
|
96
|
+
- Switch between the five modes at any time; no need to reopen the conversation.
|
|
97
|
+
- Bug reports and suggestions are welcome in [Issues](https://github.com/smallflycar/dsh-reading-focus/issues).
|
|
64
98
|
|
|
65
99
|
## License
|
|
66
100
|
|
|
67
101
|
MIT. See [LICENSE](LICENSE).
|
|
102
|
+
|
|
103
|
+
[](https://github.com/deepseek-ai/deepseek-harness)
|
package/README.md
CHANGED
|
@@ -1,255 +1,103 @@
|
|
|
1
|
-
<p align="center"><img src="icon.svg" width="
|
|
1
|
+
<p align="center"><img src="icon.svg" width="88" alt="阅读辅助"></p>
|
|
2
2
|
|
|
3
3
|
<h1 align="center">DSH 阅读辅助</h1>
|
|
4
4
|
|
|
5
|
-
<p align="center"
|
|
5
|
+
<p align="center">在 DeepSeek Harness 的聊天正文里,提供渐变文字、阅读尺、行/段聚焦和色块分段。</p>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
<a href="https://github.com/smallflycar/dsh-reading-focus"><img alt="GitHub" src="https://img.shields.io/badge/GitHub-repo-24292f.svg"></a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/dsh-reading-focus"><img alt="npm" src="https://img.shields.io/npm/v/dsh-reading-focus"></a>
|
|
9
10
|
<a href="https://github.com/smallflycar/dsh-reading-focus/releases"><img alt="Release" src="https://img.shields.io/github/v/release/smallflycar/dsh-reading-focus"></a>
|
|
10
|
-
<a href="LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-2f6fed.svg"></a>
|
|
11
|
-
<img alt="DSH" src="https://img.shields.io/badge/DSH-0.2.2--rc.3%20%7C%200.2.x-4f70d9.svg">
|
|
12
|
-
<img alt="tests" src="https://img.shields.io/badge/tests-17%20unit%20%7C%2019%20browser%20%7C%207%20geometry-2ea043.svg">
|
|
13
|
-
<a href="README.en.md"><img alt="English" src="https://img.shields.io/badge/lang-English-6b7686.svg"></a>
|
|
14
11
|
</p>
|
|
15
12
|
|
|
16
|
-
>
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="README.md">简体中文</a> · <a href="README.en.md">English</a>
|
|
15
|
+
</p>
|
|
17
16
|
|
|
18
17
|
## 为什么做这个
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
我每天在 Agent 里花的时间越来越长。它的输出很长,还会一直往后堆:一条回答上千字,聊几轮就是一整屏接一整屏的记录;用它的节奏又是断断续续的——发任务、等结果、再回来接着读。这种时候读长文容易累,注意力也容易散。
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
- 想读完整段时,让其余内容退到后面,当前段落保持原样;
|
|
24
|
-
- 想一眼看清结构时,用轮换的色块把相邻内容分开;
|
|
25
|
-
- 想给正文上色时,用逐行推进的渐变代替满屏黑字。
|
|
21
|
+
浏览器里早就有阅读尺、行聚焦、色块这类辅助,本来就是为了让长文读起来轻松一点。Agent 的正文更长、更密,我想这个场景更需要它们,所以把其中几种搬进了 DSH 的聊天正文。
|
|
26
22
|
|
|
27
|
-
|
|
23
|
+
## 功能
|
|
28
24
|
|
|
29
|
-
|
|
25
|
+
- **渐变阅读** —— 按视觉行推进的渐变文字,每两行换一次色相。
|
|
26
|
+
- **阅读尺** —— 跟随指针的一条淡色带,上下各一条实线。
|
|
27
|
+
- **多行聚焦** —— 指针附近的几行保持清晰,其余压暗。
|
|
28
|
+
- **段落聚焦** —— 当前段落保持原样,其余文字变淡或压暗。
|
|
29
|
+
- **色块分段** —— 相邻内容用轮换的色块分开,代码和标题保持原样。
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
## 截图
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+

|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
*渐变阅读:只给正文着色,逐行推进。*
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
dsh plugin --profile <profile> add dsh-reading-focus
|
|
39
|
-
```
|
|
37
|
+

|
|
40
38
|
|
|
41
|
-
|
|
39
|
+
*色块分段:相邻内容用轮换的色块分开,代码和标题保持原样。*
|
|
42
40
|
|
|
43
|
-
|
|
44
|
-
dsh plugin --profile <profile> add https://github.com/smallflycar/dsh-reading-focus/releases/download/v0.8.4/dsh-reading-focus-0.8.4.tgz
|
|
45
|
-
```
|
|
41
|
+

|
|
46
42
|
|
|
47
|
-
|
|
43
|
+
*阅读尺:跟随指针的淡色带,上下各一条实线。*
|
|
48
44
|
|
|
49
|
-
|
|
50
|
-
npm run build && npm run pack
|
|
51
|
-
dsh plugin --profile <profile> add ./dist/dsh-reading-focus-0.8.4.tgz
|
|
45
|
+

|
|
52
46
|
|
|
53
|
-
|
|
54
|
-
dsh plugin --profile <profile> add "link:/absolute/path/to/this/repo"
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
安装后在「设置 → 阅读辅助」开启。`link:` 方式改完源码后重新 `npm run build` 并重新加载插件即可。
|
|
58
|
-
|
|
59
|
-
## 界面
|
|
60
|
-
|
|
61
|
-
| | |
|
|
62
|
-
|---|---|
|
|
63
|
-
|  |  |
|
|
64
|
-
| **设置面板**:按「效果 → 参数 → 颜色 → 字体」分节,只显示当前模式用得上的控件 | **渐变阅读**:只给正文着色,逐行交替推进 |
|
|
65
|
-
|  |  |
|
|
66
|
-
| **色块分段**:整段轮换色相,代码块与标题不上色,表格照常分段 | **阅读尺**:上下实线 + 淡色带,跟随指针 |
|
|
67
|
-
|  |  |
|
|
68
|
-
| **段落聚焦**:当前段落保持原样,其余内容变淡或压暗 | **悬浮调节窗**:在正文里实时调节,不打断阅读 |
|
|
47
|
+
*段落聚焦:当前段落保持原样,其余内容变淡或压暗。*
|
|
69
48
|
|
|
70
|
-
|
|
49
|
+
*截图来自仓库自带的本地预览页 `preview.html`,仅作效果示意。*
|
|
71
50
|
|
|
72
|
-
##
|
|
73
|
-
|
|
74
|
-
| 模式 | 中间 | 其余内容 | 可调 |
|
|
75
|
-
|---|---|---|---|
|
|
76
|
-
| 阅读尺 | 淡色带 + 上下实线 | 不变暗 | 线条颜色、覆盖行数 1–6 |
|
|
77
|
-
| 多行聚焦 | 完全透明、正常亮度 | 遮罩压暗 | 遮罩颜色、聚焦行数 1–8 |
|
|
78
|
-
| 段落聚焦 | 当前段落保持原样 | **文字变淡** 或 **遮罩压暗**(可切换) | 遮罩/底色、透明度 |
|
|
79
|
-
| 色块分段 | 轮换的三种色块 | — | 配色方案、浓度;自定义时三个取色器 |
|
|
80
|
-
| 渐变阅读 | 逐行推进的渐变文字 | — | 配色、颜色强度 |
|
|
81
|
-
|
|
82
|
-
## 细节与边界
|
|
51
|
+
## 安装
|
|
83
52
|
|
|
84
|
-
|
|
53
|
+
**DSH Desktop**:打开 **Settings → Plugins → Add plugin**,输入 `dsh-reading-focus`,安装后刷新页面。
|
|
85
54
|
|
|
86
|
-
|
|
55
|
+
**命令行**:
|
|
87
56
|
|
|
57
|
+
```bash
|
|
58
|
+
dsh plugin --profile <profile> add dsh-reading-focus
|
|
88
59
|
```
|
|
89
|
-
第 0 行 底色 → 色A 第 1 行 色A → 底色
|
|
90
|
-
第 2 行 底色 → 色B 第 3 行 色B → 底色 (此后循环)
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
相邻两行的衔接永远落在**两个极值**上——要么都是满饱和的色A/色B,要么都是纯底色——不会停在渐变中段。这一点很重要:换行处若恰好是淡色,颜色就无法把视线从上一行带到下一行。每两行换一次色相(A、B 交替)。
|
|
94
|
-
|
|
95
|
-
只有一个着色字形的行使用进入该行时的颜色,并且不推进模式,所以它不会破坏前后任一衔接点;该行本身不呈现渐变。同一回答中的全部 Markdown 根节点共享行的推进序号,**包括被工具调用隔开的两段**:宿主把工具调用前后的正文渲染成不同的根节点,但打印出来仍是同一段连续阅读,所以颜色会跨过工具卡片继续推进,而不是从底色重新开始。真正的新回答(`data-chat-turn` 变化)仍然从底色重新开始。视觉行由矩形重叠近似分行,混合字号的复杂布局仍可能误判。
|
|
96
|
-
|
|
97
|
-
只有**正文文字**着色:`h1`–`h6` 标题、`code`/`pre` 代码、表格、图片、按钮等控件一律保留原色。大字号标题若参与着色,单个字形就会占满一整段渐变,看起来是渲染异常而不是阅读辅助。链接等不着色内容不保证端点连续。
|
|
98
|
-
|
|
99
|
-
使用浏览器原生的 CSS Custom Highlight,不改变 DOM。启用时优先处理视口附近的回答,同一回答内按前后顺序分帧处理所有已加载、可布局的正文块;每帧最多 400 个步骤、约 4ms 软预算(浏览器调用不可抢占),首次长文处理会耗时且占用内存。已处理块在连接期间缓存,滚动本身不重测;流式变化按块更新,前文行数引起进度变化时复用后文几何重新着色;字体、主题、宽度变化重新测量。浏览器不支持 CSS Custom Highlight 或系统强制颜色启用时提示并保留原色。
|
|
100
|
-
|
|
101
|
-
### 阅读尺与多行聚焦
|
|
102
|
-
|
|
103
|
-
两者都独立锚定当前会话的阅读 pane 与滚动区,不要求鼠标命中正文块;代码、代码标题与复制按钮、横向滚动区、表格、图片和段落间空白都可以跟随。
|
|
104
|
-
|
|
105
|
-
- **阅读尺**由上下两条实线和中间的淡色带组成,宽度优先对齐当前 pane 的宽度控件内侧,否则使用 pane 宽度,并受 pane 与视口裁剪。行高按当前正文真实行高换算整数行,覆盖 1–6 行。
|
|
106
|
-
- **多行聚焦**让指针附近一条横向区域保持完全透明,其余压暗;行数 1–8,按固定 24px 基准行高估计并留少量余量,不随具体字体或鼠标命中的元素变化。
|
|
107
|
-
|
|
108
|
-
两种模式在同会话的宽度手柄、输入区域或任务控件上冻结最后阅读位置;拖动宽度手柄不抢夺原生 pointer capture,松开后按指针位置恢复;离开会话或进入菜单时清除。输入卡与任务卡按计算出的四角半径保护,统计读数合并为一条清晰区域;菜单、列表框与对话框受保护。仅有会话与滚动标记的 pane 支持这些 pointer 模式。
|
|
109
|
-
|
|
110
|
-
### 段落聚焦
|
|
111
|
-
|
|
112
|
-
当前段落保持原样,其余内容有两种呈现方式:
|
|
113
|
-
|
|
114
|
-
- `文字变淡` 用 `CSS.highlights` 的 `::highlight()` 直接改文字颜色,颜色取当前正文色并降低不透明度,深浅主题都自动适配,页面不加任何遮罩;
|
|
115
|
-
- `遮罩压暗` 盖一层压暗遮罩,并给当前段落可选底色。
|
|
116
|
-
|
|
117
|
-
不支持 CSS Custom Highlight 的浏览器自动退回遮罩压暗。指针短暂离开正文(例如划过工具调用行)时保留上一帧,再回到正文立即恢复。
|
|
118
|
-
|
|
119
|
-
### 色块分段
|
|
120
|
-
|
|
121
|
-
可选「整段色块」或「紧凑色带」;两种都把整个列表(包括嵌套列表、序号、多行和项间空白)作为同一色块。颜色按整个回答轮换,被工具调用拆成多段时不会连续出现同一颜色。
|
|
122
|
-
|
|
123
|
-
- **代码块不上色**:`pre`、`[data-code-block-content]` 与 `.md-code-block` 既不参与分段,也作为屏障阻止相邻色块跨过它合并,代码保留自身的表面与语法色。
|
|
124
|
-
- **标题不上色**,与渐变保持一致;**表格**和普通段落一样参与分段。
|
|
125
|
-
- 相同阅读 lane 的相邻同色色块在相接或最多 1px 残余缝隙时合并;不同色的间距不剪切文字。大于 24px 的原始间隙、可识别过程/工具卡和图片不跨越。
|
|
126
|
-
- 透明交互层、空容器和隐藏辅助元素不再仅因有矩形就作为色块屏障;有内容的普通流子节点可作为屏障,与正文重叠时保守不裁正文,明确的图片保留裁剪。
|
|
127
60
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
字号与 DSH 共用同一个变量 `--dsh-content-font-size`,范围 **10–22px**、默认 **14px**——面板里的值和 DSH 设置里的值是同一个。
|
|
131
|
-
|
|
132
|
-
DSH 的行高不是倍数,而是「字号 + 10px」的阶梯(14→24、16→26、18→28)。插件不重写这条阶梯,只提供 **0–12px 的「额外行距」**:
|
|
133
|
-
|
|
134
|
-
- 0 表示完全按 DSH 的行高,插件不写任何覆盖规则;
|
|
135
|
-
- 大于 0 时写入 `calc(24px + var(--dsh-content-font-delta, 0px) + Npx)`,宿主改字号时行距自动跟随;
|
|
136
|
-
- 「恢复默认」**清除插件的覆盖**,把字号交还给 DSH 当前设置,而不是写入 14px。
|
|
137
|
-
|
|
138
|
-
插件关闭期间 DSH 改了字号,重新开启或打开面板时会先读回宿主值。
|
|
139
|
-
|
|
140
|
-
### 设置、窗口与快捷键
|
|
141
|
-
|
|
142
|
-
点击「在正文中实时调节」关闭设置并打开悬浮窗。拖动标题栏移动;× 或窗口内 Esc 只关闭窗口,不关闭效果;在正文上按 Esc 会关闭效果本身,输入框内不拦截快捷键。宿主模态框优先,出现时隐藏效果与悬浮窗。
|
|
143
|
-
|
|
144
|
-
设置(含开关状态)保存在浏览器 localStorage,下次打开按上次的状态恢复。旧版鼠标聚光灯模式会回退到阅读尺,旧版行距配置会换算成「额外行距」,其他偏好保留。
|
|
61
|
+
需要 DSH 0.2.x。也可以从 [Release](https://github.com/smallflycar/dsh-reading-focus/releases/latest) 下载 tarball 安装。
|
|
145
62
|
|
|
146
63
|
## 兼容性
|
|
147
64
|
|
|
148
|
-
|
|
65
|
+
| DSH 版本 | 正文容器 | Markdown 根 | 状态 |
|
|
66
|
+
| --- | --- | --- | --- |
|
|
67
|
+
| 0.2.3-alpha.1 及以后 | `xMeOpW_body` | `哈希_markdown`(如 `-TmMFa_markdown`) | ✅ 0.2.3-alpha.2 实测 |
|
|
68
|
+
| 0.2.2 rc 系列 | `xMeOpW_body` | `_markdown_哈希_序号` | ✅ |
|
|
69
|
+
| 0.2.1 及更早 | `v5IAXa_body` | `_markdown_哈希_序号` | ✅ 结构识别,未实机 |
|
|
149
70
|
|
|
150
|
-
|
|
71
|
+
宿主类名里的哈希是构建产物,和操作系统无关;插件不依赖具体哈希,也不依赖类名里的顺序:
|
|
151
72
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
npm run build # src/*.js → lib/client.js、lib/index.js、preview.html
|
|
156
|
-
npm test # 构建 + 17 项逻辑、结构、产物一致性断言
|
|
157
|
-
npm run test:browser # 无头 Chrome:19 项渲染断言(需要本机 Chrome)
|
|
158
|
-
npm run test:browser:geometry # 无头 Chrome:7 项分段几何断言
|
|
159
|
-
npm run pack # 生成 dist/dsh-reading-focus-<version>.tgz
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
`lib/client.js`、`lib/index.js` 和 `preview.html` 由 `build.mjs`(渲染规则在 `build-lib.mjs`)生成,不要直接编辑。`npm test`、浏览器测试和打包前都会先构建;测试还会逐字比较产物与 `src` 的渲染结果,改了源码没重新生成会直接失败。`preview.html` 和 `docs/screenshots` 是本地夹具,不是真实 GUI 像素证据。
|
|
163
|
-
|
|
164
|
-
测试目录里,`plugin.test.mjs` 覆盖逻辑与产物,`browser-validation.mjs` 覆盖各模式的渲染与交互,`conversation-regression.mjs` 覆盖被工具调用拆段时的分段几何(DPR、间距、隔离与屏障)。
|
|
73
|
+
- 正文容器认「类名以 `_body` 结尾、直子含 Markdown 根、且不在工具行等非 `assistant-step` 流项目里」;
|
|
74
|
+
- Markdown 根认「类名含 `markdown`、且是正文容器的直子」,`_markdown_哈希_序号` 和 `哈希_markdown` 两种都接受;
|
|
75
|
+
- 万一宿主连 `body` 这个局部名都改了,退回结构识别:聊天流里包裹 Markdown 根的容器。
|
|
165
76
|
|
|
77
|
+
所以 DSH 小版本升级、换机器、换系统都不需要重新适配。唯一还需要人工介入的情况是宿主改了 `markdown` 这个局部名,或把 Markdown 根挪进别的容器。
|
|
166
78
|
|
|
167
79
|
## 更新记录
|
|
168
80
|
|
|
169
|
-
0.
|
|
170
|
-
|
|
171
|
-
0.3.7 修正多行模式的绘制层级:会话 composer seat 为 sticky、z-index 9,背景从透明渐变到实色;旧遮罩 z-index 4 因此绘制在其背后,即使几何区域覆盖整个 pane 也不能压暗座位背景。仅多行遮罩提升至 10,其他效果仍为 4,调节窗为 1000;不修改宿主样式。输入卡按 `data-composer-card` 的实际矩形保护;上方任务卡按宿主 `section[data-testid="todo-panel"]` 整体保护,包含背景和展开内容,随尺寸变化重算。下方 `data-composer-dock` 是状态行而非任务卡,不豁免整宽 seat。菜单等仍保留独立保护。任务卡标记属于宿主实现细节,未来版本改变可能失效。
|
|
172
|
-
|
|
173
|
-
0.4.4 渐变进度模型改为「每行独立走完一段、方向交替」,相邻行衔接落在满饱和或纯底色两个极值上,不再停在渐变中段;同时渐变与色块都不再作用于标题、代码块与表格。
|
|
174
|
-
|
|
175
|
-
0.5.0 颜色跨工具调用继续推进:同一回答里被工具卡片隔开的两段正文不再各自从底色重新开始,只有真正的新回答才重置。设置面板标题下显示版本号,便于确认加载的是哪一次构建。
|
|
176
|
-
|
|
177
|
-
0.6.0 一次较大的交互与性能改版:
|
|
178
|
-
|
|
179
|
-
- 色块分段改为按整段回答轮换色相,工具调用把回答拆成多段时不再连续出现同一颜色。
|
|
180
|
-
- 滚动跟随不再复用滚动前的命中目标,遮罩与色块随文字同步移动,不再滞后一拍再跳回。
|
|
181
|
-
- 多行聚焦在鼠标位于输入框或状态栏时不再绘制横杠,改为整体提亮,输入框保持完整。
|
|
182
|
-
- 阅读尺与多行聚焦都按当前正文真实行高换算整数行,字体或行距变化后仍与文字对齐;阅读尺改为可覆盖 1–6 行。
|
|
183
|
-
- 段落聚焦在指针短暂离开正文(例如划过工具调用行)时保持上一帧,不再闪烁消失。
|
|
184
|
-
- 新增正文字号、字重、行距调节,直接写入宿主排版变量,与 DSH 自带设置双向同步。
|
|
185
|
-
- 新增各模式强调色与不透明度调节,提供六个预设色与自定义取色。
|
|
186
|
-
- 移除渐变模式下的「就绪 · 已着色 N 段」状态文字,该面板不再出现调试式读数。
|
|
187
|
-
- 渐变着色不再为每个字形重复读取正文块的边界矩形,进度状态也不再每帧遍历全部段落。
|
|
188
|
-
|
|
189
|
-
0.6.3 把重复的「段落聚焦」和「逐块阅读」合并成一个模式:两者本来就选中同一个块、只是变弱方式不同,现在只保留一张卡片,用「其余内容」在 `文字变淡` 和 `遮罩压暗` 之间切换,各自的调节项随之变化。模式数从 6 减到 5,旧配置里的 `paragraph` 模式与配色自动迁移到合并后的模式。
|
|
190
|
-
|
|
191
|
-
0.6.4 重做设置面板:按「选择效果 / 该效果的参数 / 颜色 / 正文字体」分节,去掉对当前模式无效的控件(「效果强度」只属于渐变阅读);每个颜色槽位有自己的推荐色板——线条用醒目色、压暗遮罩用深色中性、色块用柔和底色,不再共用一套从黄色排起的色板;新增自定义取色与按模式独立的「恢复默认」。
|
|
192
|
-
|
|
193
|
-
0.6.5 阅读尺和多行聚焦在指针移到正文两侧留白时让开,整页恢复可见;用正文列实际边界加 10px 缓冲与 110ms 延迟,拖动宽度手柄不会闪烁。可在设置里改回「保持显示」。
|
|
194
|
-
|
|
195
|
-
0.7.0 设置面板继续收敛:色板按用途缩短(压暗遮罩 4 色、段落底色 4 色、色块 4 色,只有阅读尺保留 6 色);色块分段改为「配色方案 + 浓度」,自定义方案才展开三个取色器;取色换成面板内的色相/饱和/明度滑块;字重改为直接作用于正文段落(此前写在包裹层上,继承无法覆盖渲染器自己的声明,所以拖了没反应);开关状态随其他偏好一起保存,重启后不再需要重新打开。
|
|
196
|
-
|
|
197
|
-
0.7.1 交互再调:渐变阅读的配色改成三条渐变色「胶囊」,直接显示那一组颜色,不再用文字下拉;自定义取色换成点选式色板(三档明度的色相网格 + 中性色),去掉色相/饱和/明度这类专业术语;字号、字重、行距、覆盖行数改为数字输入框加 ▲▼ 按钮,和 DSH 自己设置里的字号控件一致,减少需要拖动的滑块。
|
|
198
|
-
|
|
199
|
-
0.7.2 自定义取色改为色盘:一个圆盘(角度是色相、离圆心远近是饱和)、一个明度滑块、一个透明度滑块和一个可直接输入的十六进制色值;预设色板不再塞满一屏没人要的颜色。去掉字重设置——DSH 的字体粗细由内容语义决定,插件改它只会和宿主打架,而且实测在不同字体下表现不一致。
|
|
200
|
-
|
|
201
|
-
0.7.3 渐变配色胶囊只显示那一组的两个色相(左边一个色、右边一个色),不再把底色黑/白混进去,之前看着像一条黑条。
|
|
202
|
-
|
|
203
|
-
0.7.4 取色器改为在色块下方就地展开,不再是一个会自己消失的浮层;去掉重复的「透明度」——透明度仍然由下面那条「压暗程度 / 浓度」滑块负责,取色器只负责颜色本身。「覆盖行数 / 聚焦行数」改回滑块:它是 1–6 这种小范围整数,拖动比输入更快;字号和行距继续用数字框加 ▲▼。
|
|
204
|
-
|
|
205
|
-
0.7.5 压暗遮罩的默认色改为纯黑(原来是偏蓝的深灰,铺在白底上会发蓝);去掉「上一块 / 下一块」按钮和 Alt+↑/↓ 逐块跳转——鼠标移动本来就会切换当前段落,手动步进没有额外价值;自定义取色的入口改成完整的彩虹圆盘,之前中间留白只剩一圈暗环。
|
|
206
|
-
|
|
207
|
-
0.7.6 色卡圆点不再露出方形底:Chromium 会把 `background` 铺满按钮的方框而不按 `border-radius` 裁剪,导致圆点四角冒出方块、中间还压着一层浅色。改为把颜色画在内部元素上、由它自己裁成圆形,圆点与彩虹盘现在都是干净的圆。
|
|
208
|
-
|
|
209
|
-
0.7.7 透明度不再是无级滑块,改成有意义的档位:压暗程度「轻 / 中 / 重」、淡出程度「轻 / 中 / 重」、色块浓度「淡 / 中 / 明显」、段落底色「淡 / 中 / 浓」。原来的滑块能拖到「完全没效果」或「什么都看不见」,那不叫可调,叫没有边界。每档都落在仍然可用、仍然能读的区间内;段落聚焦因为本来就高亮当前块,使用更轻的一档压暗。
|
|
210
|
-
|
|
211
|
-
0.7.8 多行聚焦去掉「遮罩颜色」:遮罩必须够深才压得暗,能选的颜色其实只剩「多深」这一个维度,和「轻 / 中 / 重」重复;而且浅色遮罩在深色主题下会把周围提亮,与「压暗」相反。压暗统一用黑色,只留三档强度。段落聚焦同理,只保留「压暗程度」和「当前段落底色」——后者是加亮当前块,颜色有意义。
|
|
212
|
-
|
|
213
|
-
0.7.9 纠正上一版的方向:该删的是重复的档位,不是遮罩颜色。「压暗」现在只有一个控件——遮罩颜色,颜色本身带透明度:色板提供从纯黑到浅灰的四档,取色器里的「透明度」在 15%–85% 之间连续调节,越深越不透明就压得越暗。段落聚焦的「当前段落底色」同样把强度并进取色器,不再单独列一档。
|
|
214
|
-
|
|
215
|
-
0.8.0 统一成一条规则:**一个可调项只出现一次,颜色的强度放在颜色自己的取色器里**。于是所有档位按钮取消,改成滑块;带颜色的效果不再有第二个强度控件:
|
|
216
|
-
|
|
217
|
-
| 效果 | 控件 | 强度范围 |
|
|
218
|
-
|---|---|---|
|
|
219
|
-
| 阅读尺 | 线条颜色(取色器内调透明度) | 30%–100% |
|
|
220
|
-
| 多行聚焦 | 遮罩颜色(取色器内调透明度) | 15%–85% |
|
|
221
|
-
| 段落聚焦 · 遮罩压暗 | 遮罩颜色(透明度 15%–70)+ 当前段落底色(5%–40) | 同上 |
|
|
222
|
-
| 段落聚焦 · 文字变淡 | 其余文字透明度(滑块,没有颜色) | 25%–85% |
|
|
223
|
-
| 色块分段 | 配色方案 + 色块浓度(滑块,三个色块共用一层浓度) | 10%–45% |
|
|
224
|
-
|
|
225
|
-
下限保证「调到头也看得见效果」,上限保证「调到头也还读得懂」。
|
|
81
|
+
**0.8.6** —— 适配 DSH 0.2.3-alpha.1 起的类名变化。那一版把 `dsh-client-ui-primitives` 改为随前端 bundle 构建,Markdown 根从 `_markdown_哈希_序号` 变成 `哈希_markdown`,旧选择器因此一个正文块都找不到。现在两种顺序、任意哈希都认;同时区分正文容器与工具行、命令行那类同样以 `_body` 结尾的容器。
|
|
226
82
|
|
|
227
|
-
0.8.
|
|
83
|
+
**0.8.5** —— 不再写死正文容器的哈希;行高覆盖规则改挂在插件自己写的 `data-reading-focus-body` 标记上,清除覆盖时一并移除。
|
|
228
84
|
|
|
229
|
-
|
|
85
|
+
## 使用
|
|
230
86
|
|
|
231
|
-
|
|
87
|
+
1. 打开 **设置 → 阅读辅助**,打开右上角开关。
|
|
88
|
+
2. 选一种效果,下面只出现它用得上的参数。
|
|
89
|
+
3. 想边读边调,点「在正文中实时调节」。
|
|
90
|
+
4. 所有设置都会自动保存,下次打开恢复上次的状态。
|
|
232
91
|
|
|
233
|
-
|
|
234
|
-
- 字号、行距的数字框可以正常打字了。以前每敲一个键就钳制并回写,输「18」会依次变成 12 和 22;现在输入时只在数值合法时预览,失焦或回车才钳制落定,▲▼ 仍然可用。
|
|
235
|
-
- 行距回读不再静默改值。字号 22 / 行距 16 这类合法组合,以前存成比值后会被 1.0–2.0 的旧区间夹成 22;现在可接受区间与面板的 px 范围由同一组常量推导。
|
|
236
|
-
- 色块分段不再涂标题(`h1`–`h6`),表格和段落一样参与分段。
|
|
237
|
-
- `npm test` 与打包前都会先构建;测试逐字比较 `lib/client.js`、`lib/index.js`、`preview.html` 与 `src`,不再只检查几个函数名是否还在。
|
|
238
|
-
- 清理:删除未被任何脚本引用且恒失败的 `test/engine-simulation.mjs`,修好并接入 `test:browser:geometry` 的 `conversation-regression.mjs`(原断言写的是 0.6.0 已取消的同色合并),一次性 Python 像素检查移到 `tools/`,`.gitignore` 覆盖测试产生的浏览器 profile,残留 profile 目录已清理。
|
|
239
|
-
- 排版写入可回收:插件卸载时删除 `#rf-typography` 并还原宿主变量;DSH 自己改字号时面板会跟着更新,不会再拿旧值覆盖。
|
|
240
|
-
- 去掉只写不读的 `state.strength`、未使用的 `RF_BAND_PALETTE`、`shapeCount`、`rfLinePieces` 和未用的 `moved` 变量;渐变与色块模式滚动时不再做无人消费的段落命中测试。
|
|
92
|
+
深浅主题都适配。代码、表格和标题始终保持原样。
|
|
241
93
|
|
|
242
|
-
|
|
94
|
+
## 说明
|
|
243
95
|
|
|
244
|
-
-
|
|
245
|
-
-
|
|
246
|
-
- 旧配置自动迁移:0.8.3 及更早存的比值(或更早的 px)会换算成"相对宿主阶梯的额外值"。例如 18px 字号存了 24/14 的比值(30.86px),迁移后是 28px + 3px,渲染高度不变。
|
|
247
|
-
- 「恢复默认」改成**清除插件的覆盖**,把控制权还给 DSH 当前设置;之前它会直接写入 14px/24px,把用户在 DSH 里改过的字号盖掉。
|
|
248
|
-
- 插件关闭期间 DSH 自己改了字号,重新开启或打开面板时会先读回宿主值;面板提示也改成实际行为(共用字号、行高 = 自动值 + 额外值)。
|
|
249
|
-
- 打包脚本会先创建 `dist/`,干净检出下 `npm run pack` 不再报 `ENOENT`;测试新增两条保护:面板版本必须等于 `package.json` 版本,生成后的 `lib/client.js` 必须能被解析。
|
|
250
|
-
- 仓库整理(0.8.4 发布时):一次性像素检查脚本与旧版本截图移出仓库,不进版本库;新增 `icon.svg`、`docs/screenshots`、双语 README、Issue/PR 模板与 `engines.dsh` 声明。
|
|
96
|
+
- 五种效果可以随时切换,不需要重开对话。
|
|
97
|
+
- 遇到问题或有建议,欢迎在 [Issues](https://github.com/smallflycar/dsh-reading-focus/issues) 里提。
|
|
251
98
|
|
|
252
99
|
## 许可证
|
|
253
100
|
|
|
254
|
-
MIT
|
|
101
|
+
MIT,详见 [LICENSE](LICENSE)。
|
|
255
102
|
|
|
103
|
+
[](https://github.com/deepseek-ai/deepseek-harness)
|
package/lib/client.js
CHANGED
|
@@ -263,26 +263,88 @@ function createGradientController({state,roots,blocks,viewport,notify,flowOf}){
|
|
|
263
263
|
}
|
|
264
264
|
|
|
265
265
|
// Shown in the settings panel so a loaded build can be identified at a glance.
|
|
266
|
-
const RF_VERSION = '0.8.
|
|
266
|
+
const RF_VERSION = '0.8.6';
|
|
267
267
|
// One source of truth for the typography controls. The size range mirrors the host's own text
|
|
268
268
|
// stepper (10-22, default 14). Line height is not a ratio here: the host computes it as
|
|
269
269
|
// `24px + (size - 14)` (the `--dsh-content-font-delta` ladder), so this plugin only adds an
|
|
270
270
|
// optional extra on top of that instead of re-deriving a competing line height.
|
|
271
271
|
const RF_FONT = {sizeMin:10,sizeMax:22,sizeDefault:14,extraMin:0,extraMax:12,lineBase:24,baseSize:14};
|
|
272
|
-
//
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
272
|
+
// The host builds its client CSS as CSS Modules, so every local class carries a build-time hash.
|
|
273
|
+
// Two things changed across the 0.2.x line and neither is a contract:
|
|
274
|
+
// - the body container is `<hash>_body` (0.2.x: `xMeOpW_body`, earlier: `v5IAXa_body`);
|
|
275
|
+
// - the markdown root is `<hash>_markdown` in the current web frontend (`-TmMFa_markdown`), while
|
|
276
|
+
// the 0.2.2-rc.1/rc.3 builds emitted `_markdown_<hash>_<n>` instead.
|
|
277
|
+
// So nothing here spells a hash out: a body is a container whose class token ends in `_body`, and a
|
|
278
|
+
// root is a child whose class token contains `markdown`. Four other `_body` locals live in the same
|
|
279
|
+
// bundle (command rows, turn triggers, ...), so a body inside a non-assistant flow item is rejected;
|
|
280
|
+
// the kind check only applies when the host marks one. See docs/BEHAVIOR.md.
|
|
281
|
+
const RF_ROOT = '[class*="markdown"], [data-reading-focus-preview]';
|
|
282
|
+
const RF_FLOW = '[data-slot="conversation.chat.flow"], [data-chat-turn], [data-chat-flow-kind]';
|
|
283
|
+
// The marker this plugin writes on recognised bodies; the line-height rule anchors on it instead of
|
|
284
|
+
// on a class name. It is removed again when the typography override is cleared.
|
|
285
|
+
const RF_BODY_MARK = 'data-reading-focus-body';
|
|
286
|
+
// Reading bodies are the exact elements the root scan accepted, never "anything with a `_body` token".
|
|
287
|
+
const rfKnownBodies = new WeakSet();
|
|
288
|
+
// Set by rfPrimeBodies: whether the host still names a body container at all.
|
|
289
|
+
let rfBodyFallback = false;
|
|
290
|
+
function rfBodyToken(token) { return token.length > 5 && token.endsWith('_body'); }
|
|
291
|
+
function rfMarkdownToken(token) { return /markdown/i.test(token); }
|
|
292
|
+
function rfHasToken(node, test) {
|
|
293
|
+
if(!node || node.nodeType !== 1) return false;
|
|
294
|
+
const tokens = node.classList;
|
|
295
|
+
for(let i = 0; i < tokens.length; i++) if(test(tokens[i])) return true;
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
function rfIsBody(node) { return !!node && rfKnownBodies.has(node); }
|
|
299
|
+
function rfBodyAncestor(node) {
|
|
300
|
+
for(let el=node;el;el=el.parentElement)if(rfKnownBodies.has(el))return el;
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
// Bodies are the parents that hold markdown roots, so the structure never needs the class hash.
|
|
304
|
+
function rfMarkBodies(rootList) {
|
|
305
|
+
for(const root of rootList) {
|
|
306
|
+
const body = root?.parentElement;
|
|
307
|
+
if(body && !body.hasAttribute(RF_BODY_MARK)) body.setAttribute(RF_BODY_MARK, '');
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// Fall back to structure only when the host no longer names the container at all.
|
|
311
|
+
function rfPrimeBodies(scope) {
|
|
312
|
+
rfBodyFallback = true;
|
|
313
|
+
for(const el of scope.querySelectorAll('[class*="_body"]')) if(rfHasToken(el, rfBodyToken)){rfBodyFallback = false;break;}
|
|
277
314
|
}
|
|
278
315
|
function matchesRoot(node) {
|
|
279
|
-
|
|
316
|
+
if(!node || node.nodeType !== 1) return false;
|
|
317
|
+
if(node.hasAttribute('data-reading-focus-preview')) return true;
|
|
318
|
+
const parent = node.parentElement;
|
|
319
|
+
if(!parent || !rfHasToken(node, rfMarkdownToken)) return false;
|
|
320
|
+
// A reading body is named `*_body` and holds a markdown root. Tool rows, command rows and turn
|
|
321
|
+
// triggers also carry a `_body` local in the same bundle, so the enclosing flow kind decides.
|
|
322
|
+
if(rfHasToken(parent, rfBodyToken)) {
|
|
323
|
+
const kind = parent.closest('[data-chat-flow-kind]');
|
|
324
|
+
if(kind && kind.getAttribute('data-chat-flow-kind') !== 'assistant-step') return false;
|
|
325
|
+
rfKnownBodies.add(parent); return true;
|
|
326
|
+
}
|
|
327
|
+
// The host renamed the `body` local: accept the container of any markdown root inside a flow.
|
|
328
|
+
if(rfBodyFallback && parent.closest(RF_FLOW)){rfKnownBodies.add(parent);return true;}
|
|
329
|
+
return false;
|
|
280
330
|
}
|
|
281
331
|
function queryRoots(node) { return [...node.querySelectorAll(RF_ROOT)].filter(matchesRoot); }
|
|
282
332
|
function closestRoot(node) {
|
|
283
333
|
for(let el=node;el;el=el.parentElement)if(matchesRoot(el))return el;
|
|
284
334
|
return null;
|
|
285
335
|
}
|
|
336
|
+
// First paragraph (or list item) of any reading body: type metrics and the fade colour read it.
|
|
337
|
+
function rfReadingSample(rootList) {
|
|
338
|
+
for(const root of rootList) {
|
|
339
|
+
if(!root?.isConnected) continue;
|
|
340
|
+
const body = root.parentElement;
|
|
341
|
+
if(!body) continue;
|
|
342
|
+
const text = body.querySelector('p, li') || root.querySelector('p, li');
|
|
343
|
+
if(text) return text;
|
|
344
|
+
}
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
function rfRootDocumentSample() { return document.querySelector('[class*="markdown"] p, [class*="markdown"] li'); }
|
|
286
348
|
const RF_BLOCK = 'p,li,h1,h2,h3,h4,h5,h6,blockquote,pre,table';
|
|
287
349
|
const RF_OCCLUDERS = '[data-composer-seat], [data-composer-card], [data-composer-overlay], [data-composer-dock], [data-composer-input], [data-code-block-banner], [data-conversation-region="composer"], [data-slot="conversation.input.dock"], [role="toolbar"], [role="menu"], [role="dialog"], dialog[open], [aria-modal="true"], footer';
|
|
288
350
|
|
|
@@ -393,8 +455,8 @@ function rfVeilColor(state){const key=state.mode==='blocks'?'blocks':'lines';ret
|
|
|
393
455
|
function rfTintColor(state){return rfRgba(rfColorValue(state,'blocks','tintColor','#4e9ee0'),rfColorValue(state,'blocks','tintOpacity',.1));}
|
|
394
456
|
// Block focus fades the text itself: the live text colour at reduced alpha blends with whatever
|
|
395
457
|
// background the theme uses, so no overlay is needed and the result inherits the real colours.
|
|
396
|
-
function rfDimColor(state){
|
|
397
|
-
const sample=
|
|
458
|
+
function rfDimColor(state, rootList){
|
|
459
|
+
const sample=rfReadingSample(rootList) || rfRootDocumentSample();
|
|
398
460
|
const rgb=sample?rfParseColor(getComputedStyle(sample).color):null;
|
|
399
461
|
const base=rgb?rgb.slice(0,3):[230,232,238];
|
|
400
462
|
const alpha=rfColorValue(state,'blocks','dimOpacity',.45);
|
|
@@ -421,8 +483,8 @@ function rfGradientPill(name){
|
|
|
421
483
|
}
|
|
422
484
|
// Read back the size the reading body actually renders, in the same px units the host's own
|
|
423
485
|
// stepper uses, so the panel opens on the host's real value instead of assuming 14px.
|
|
424
|
-
function rfHostFontSize(){
|
|
425
|
-
const body=
|
|
486
|
+
function rfHostFontSize(rootList){
|
|
487
|
+
const body=rfReadingSample(rootList) || rfRootDocumentSample();
|
|
426
488
|
if(!body)return RF_FONT.sizeDefault;
|
|
427
489
|
const size=Number.parseFloat(getComputedStyle(body).fontSize);
|
|
428
490
|
return Number.isFinite(size)&&size>0?size:RF_FONT.sizeDefault;
|
|
@@ -434,7 +496,7 @@ function rfHostLineHeight(size){return RF_FONT.lineBase + (size - RF_FONT.baseSi
|
|
|
434
496
|
// rfTypographyWritten remembers what this plugin last wrote, so a host-side change can be told
|
|
435
497
|
// apart from our own write when the observer fires.
|
|
436
498
|
let rfTypographyWritten='';
|
|
437
|
-
function rfApplyTypography(font,{writeVar=true}={}){
|
|
499
|
+
function rfApplyTypography(font,{writeVar=true,roots=null}={}){
|
|
438
500
|
const target=document.body;
|
|
439
501
|
const px=Number.isFinite(font?.size)?font.size:null;
|
|
440
502
|
const extra=Number.isFinite(font?.extra)?Math.max(0,font.extra):0;
|
|
@@ -444,13 +506,16 @@ function rfApplyTypography(font,{writeVar=true}={}){
|
|
|
444
506
|
if(px!==null&&writeVar){target.style.setProperty('--dsh-content-font-size',px.toFixed(2)+'px');rfTypographyWritten=px.toFixed(2)+'px';}
|
|
445
507
|
// Only an explicit extra spacing overrides the host ladder, and even then it rides the host's own
|
|
446
508
|
// variable: the size delta still applies, so a later font-size change keeps the added room.
|
|
447
|
-
|
|
509
|
+
// The rule targets the bodies this plugin has already recognised, because their class names carry
|
|
510
|
+
// a build hash that differs between host versions.
|
|
511
|
+
if(px!==null&&extra>0){if(roots)rfMarkBodies(roots);const m=`[${RF_BODY_MARK}]`;rules.push(`${m},${m} p,${m} li,:is(${m}>*){line-height:calc(${RF_FONT.lineBase}px + var(--dsh-content-font-delta, 0px) + ${extra}px)}`);}
|
|
448
512
|
probe.textContent=rules.join('\n');
|
|
449
513
|
}
|
|
450
514
|
// The plugin owns that style element and any value it wrote itself: unloading it must not leave
|
|
451
515
|
// the host document permanently re-typeset, and it must not remove a size the host set later.
|
|
452
516
|
function rfClearTypography(){
|
|
453
517
|
document.getElementById('rf-typography')?.remove();
|
|
518
|
+
for(const el of document.querySelectorAll(`[${RF_BODY_MARK}]`))el.removeAttribute(RF_BODY_MARK);
|
|
454
519
|
if(rfTypographyWritten&&document.body.style.getPropertyValue('--dsh-content-font-size')===rfTypographyWritten)document.body.style.removeProperty('--dsh-content-font-size');
|
|
455
520
|
rfTypographyWritten='';
|
|
456
521
|
}
|
|
@@ -604,11 +669,11 @@ function startReadingFocus() {
|
|
|
604
669
|
// the column and the width handles is blank margin, not reading space.
|
|
605
670
|
// A brand-new session has a composer but no message body; the effects have nothing to focus on
|
|
606
671
|
// and must stay off until the first answer exists.
|
|
607
|
-
function hasConversation(scope){return !!scope?.
|
|
672
|
+
function hasConversation(scope){return !!scope?.querySelectorAll && queryRoots(scope).length>0;}
|
|
608
673
|
function textColumn(scope){
|
|
609
|
-
const
|
|
674
|
+
const root=scope?.querySelectorAll?queryRoots(scope)[0]:null;
|
|
675
|
+
const body=root?.parentElement;
|
|
610
676
|
if(body){const r=rect(body);if(r.right-r.left>8)return r;}
|
|
611
|
-
const root=scope?.querySelector?.(RF_ROOT);
|
|
612
677
|
if(root){const r=rect(root);if(r.right-r.left>8)return r;}
|
|
613
678
|
return bandsWidth(scope);
|
|
614
679
|
}
|
|
@@ -830,7 +895,7 @@ function startReadingFocus() {
|
|
|
830
895
|
// uses, so one number means the same thing in both places. `extra` is added to the host's own
|
|
831
896
|
// automatic line height, so 0 means "exactly like DSH".
|
|
832
897
|
const syncFontControls=()=>{const f=state.font;
|
|
833
|
-
const px=Number.isFinite(f.size)?f.size:rfHostFontSize();
|
|
898
|
+
const px=Number.isFinite(f.size)?f.size:rfHostFontSize(roots);
|
|
834
899
|
const extra=Number.isFinite(f.extra)?f.extra:0;
|
|
835
900
|
fontSize.value=String(Math.round(px));fontExtra.value=String(Math.round(extra));};
|
|
836
901
|
const refresh=()=>{
|
|
@@ -897,7 +962,7 @@ function startReadingFocus() {
|
|
|
897
962
|
const px=clamp(Number.isFinite(sizeNum)?Math.round(sizeNum):RF_FONT.sizeDefault,RF_FONT.sizeMin,RF_FONT.sizeMax);
|
|
898
963
|
const extra=clamp(Number.isFinite(extraNum)?Math.round(extraNum):RF_FONT.extraMin,RF_FONT.extraMin,RF_FONT.extraMax);
|
|
899
964
|
state.font={size:px,extra};
|
|
900
|
-
rfApplyTypography(state.font);save();
|
|
965
|
+
rfApplyTypography(state.font,{roots});save();
|
|
901
966
|
if(commit)syncFontControls();
|
|
902
967
|
gradient.invalidate();queue();
|
|
903
968
|
};
|
|
@@ -974,14 +1039,14 @@ function startReadingFocus() {
|
|
|
974
1039
|
}
|
|
975
1040
|
// The host's own settings write the same variable; adopt it when the write was not ours.
|
|
976
1041
|
if(records.some(rec=>rec.type==='attributes'&&rec.target===document.body&&rec.attributeName==='style'))adoptHostTypography();
|
|
977
|
-
if(structure){for(const r of roots)if(!r.isConnected||!matchesRoot(r)){blockCache.delete(r);roots.delete(r);if(activeBody===r){activeBody=null;activeBlock=null;if(!rfPointerMode(state.mode))hovering=false;}}watchRoots();}
|
|
1042
|
+
if(structure){for(const r of roots)if(!r.isConnected||!matchesRoot(r)){blockCache.delete(r);roots.delete(r);if(activeBody===r){activeBody=null;activeBlock=null;if(!rfPointerMode(state.mode))hovering=false;}}watchRoots();if(document.getElementById('rf-typography')?.textContent)rfMarkBodies(roots);}
|
|
978
1043
|
if(changed||structure){
|
|
979
1044
|
occluderCandidates=null;
|
|
980
1045
|
if(structure)invalidate();
|
|
981
1046
|
if(structure&&state.mode==='gradient')gradient.scan();queue(true);queuePanel();
|
|
982
1047
|
}
|
|
983
1048
|
});
|
|
984
|
-
function startObservers(){roots.clear();occluderCandidates=null;queryRoots(document).forEach(el=>roots.add(el));watchRoots();observer.observe(document.body,{subtree:true,childList:true,characterData:true,attributes:true,attributeFilter:['open','aria-modal','role','inert','data-ds-dark-theme','data-conversation-session','hidden','class','style']});}
|
|
1049
|
+
function startObservers(){roots.clear();occluderCandidates=null;rfPrimeBodies(document);queryRoots(document).forEach(el=>roots.add(el));rfMarkBodies(roots);watchRoots();observer.observe(document.body,{subtree:true,childList:true,characterData:true,attributes:true,attributeFilter:['open','aria-modal','role','inert','data-ds-dark-theme','data-conversation-session','hidden','class','style']});}
|
|
985
1050
|
function stopObservers(){observer.disconnect();resizeObserver.disconnect();roots.clear();occluderCandidates=null;}
|
|
986
1051
|
function blocks(root){
|
|
987
1052
|
let cached=blockCache.get(root);
|
|
@@ -1051,7 +1116,7 @@ function startReadingFocus() {
|
|
|
1051
1116
|
if(now-lineHeightFrame>200)lineHeightCache=new Map(),lineHeightFrame=now;
|
|
1052
1117
|
const key=scope||document.documentElement;
|
|
1053
1118
|
if(lineHeightCache.has(key))return lineHeightCache.get(key);
|
|
1054
|
-
const probe=key
|
|
1119
|
+
const probe=rfReadingSample(key?.querySelectorAll?queryRoots(key):[]);
|
|
1055
1120
|
let value=24;
|
|
1056
1121
|
if(probe){const s=getComputedStyle(probe);value=rfLineHeight(s.fontSize,s.lineHeight,probe.getClientRects()[0]?.height);}
|
|
1057
1122
|
else{const s=getComputedStyle(key);value=rfLineHeight(s.fontSize,s.lineHeight,NaN);}
|
|
@@ -1159,7 +1224,7 @@ function startReadingFocus() {
|
|
|
1159
1224
|
// the interruption rather than restarting from base. Roots from a different answer (another
|
|
1160
1225
|
// turn) stay separate, so a new answer does open at base.
|
|
1161
1226
|
function rootGroup(root){
|
|
1162
|
-
const lane=root
|
|
1227
|
+
const lane=rfBodyAncestor(root)||root.parentElement;
|
|
1163
1228
|
if(!lane)return [root];
|
|
1164
1229
|
const scope=flowScope(lane)||lane;
|
|
1165
1230
|
const all=[...scope.querySelectorAll(RF_ROOT)].filter(matchesRoot);
|
|
@@ -1195,11 +1260,14 @@ function startReadingFocus() {
|
|
|
1195
1260
|
}
|
|
1196
1261
|
function sameLane(a,b){return a.scroll===b.scroll&&a.session===b.session&&a.fallback===b.fallback&&a.chain.length===b.chain.length&&a.chain.every((x,i)=>x===b.chain[i]);}
|
|
1197
1262
|
function bandBarriers(rawRects){
|
|
1198
|
-
const selector='[data-turn-process-inline], [data-turn-process], [data-step-process], [data-chat-flow-kind="turn-process"], [data-chat-flow-kind="tool"], [data-chat-flow-kind="received-task"], [data-chat-steering-batch]
|
|
1263
|
+
const selector='[data-turn-process-inline], [data-turn-process], [data-step-process], [data-chat-flow-kind="turn-process"], [data-chat-flow-kind="tool"], [data-chat-flow-kind="received-task"], [data-chat-steering-batch]';
|
|
1199
1264
|
const result=[];
|
|
1200
1265
|
const candidates=new Set(document.querySelectorAll(selector));
|
|
1201
1266
|
for(const el of document.querySelectorAll('[data-chat-flow-kind]:not([data-chat-flow-kind="assistant-step"])'))if(!matchesRoot(el)&&!queryRoots(el).length)candidates.add(el);
|
|
1202
|
-
|
|
1267
|
+
// Bodies come from the recognised roots, so no class hash is assumed here either.
|
|
1268
|
+
const bodies=new Set();
|
|
1269
|
+
for(const root of roots)if(root.parentElement)bodies.add(root.parentElement);
|
|
1270
|
+
for(const body of bodies){for(const el of body.children)if(!matchesRoot(el)&&!queryRoots(el).length)candidates.add(el);for(const el of body.querySelectorAll('img, video, canvas'))candidates.add(el);}
|
|
1203
1271
|
for(const el of candidates){
|
|
1204
1272
|
if(!el.isConnected||el.closest('[data-text-interaction-surface], [hidden], [aria-hidden="true"]'))continue;
|
|
1205
1273
|
const s=getComputedStyle(el),r=rect(el),image=el.matches('img,video,canvas');
|
|
@@ -1329,7 +1397,7 @@ function startReadingFocus() {
|
|
|
1329
1397
|
if(held)block=focusHold.block;
|
|
1330
1398
|
if(!block){focusHold.block=null;clearDim();patchShapes(shapes);return;}
|
|
1331
1399
|
focusHold={block,at:performance.now(),scrollY};
|
|
1332
|
-
if(state.blockStyle!=='veil'&&paintDim(block,rfDimColor(state))){patchShapes(shapes);return;}
|
|
1400
|
+
if(state.blockStyle!=='veil'&&paintDim(block,rfDimColor(state,roots))){patchShapes(shapes);return;}
|
|
1333
1401
|
// Veil presentation, or a browser without CSS Custom Highlight.
|
|
1334
1402
|
clearDim();
|
|
1335
1403
|
const group=activeBody?rootGroup(activeBody):[];
|
|
@@ -1383,7 +1451,8 @@ function startReadingFocus() {
|
|
|
1383
1451
|
clearPointer();return;
|
|
1384
1452
|
}
|
|
1385
1453
|
const targetCut=target?.closest?.(RF_OCCLUDERS);
|
|
1386
|
-
|
|
1454
|
+
const targetBody=rfBodyAncestor(target);
|
|
1455
|
+
if((targetCut&&isHostOccluder(targetCut)) || (targetBody && !closestRoot(target) && targetBody!==target)){hovering=false;return;}
|
|
1387
1456
|
// Read every candidate rectangle first, decide afterwards: interleaving rect reads with the
|
|
1388
1457
|
// elementFromPoint above is what makes a scroll-costly forced layout.
|
|
1389
1458
|
let best=null,dist=Infinity;
|
|
@@ -1392,7 +1461,7 @@ function startReadingFocus() {
|
|
|
1392
1461
|
const rr=rect(root),r=rfIntersect(rr,viewport(root));
|
|
1393
1462
|
if(!r||lastX<r.left-12||lastX>r.right+12)continue;
|
|
1394
1463
|
let top=r.top-12,bottom=r.bottom+12;
|
|
1395
|
-
if(root.parentElement
|
|
1464
|
+
if(root.parentElement && rfIsBody(root.parentElement)){
|
|
1396
1465
|
const prev=root.previousElementSibling,next=root.nextElementSibling;
|
|
1397
1466
|
if(matchesRoot(prev))top=Math.min(top,(rect(prev).bottom+rr.top)/2);
|
|
1398
1467
|
if(matchesRoot(next))bottom=Math.max(bottom,(rr.bottom+rect(next).top)/2);
|
|
@@ -1451,7 +1520,7 @@ function startReadingFocus() {
|
|
|
1451
1520
|
}
|
|
1452
1521
|
const onLayout=()=>{queue(true);queuePanel();};const onResize=()=>{if(state.mode==='gradient')gradient.invalidate();onLayout();};
|
|
1453
1522
|
// Adopt a saved font on load, but never write one that was never customised.
|
|
1454
|
-
if(Object.keys(state.font).length)rfApplyTypography(state.font);document.addEventListener('pointermove',onMove,{passive:true});document.addEventListener('keydown',onKey);window.addEventListener('scroll',onScroll,true);window.addEventListener('resize',onResize);
|
|
1523
|
+
if(Object.keys(state.font).length)rfApplyTypography(state.font,{roots});document.addEventListener('pointermove',onMove,{passive:true});document.addEventListener('keydown',onKey);window.addEventListener('scroll',onScroll,true);window.addEventListener('resize',onResize);
|
|
1455
1524
|
// The on/off choice is a preference like any other: restoring it means the user does not have to
|
|
1456
1525
|
// re-enable the effect after every restart.
|
|
1457
1526
|
if(state.enabled)setEnabled(true);else sync();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-reading-focus",
|
|
3
|
-
"version": "0.8.
|
|
4
|
-
"description": "Reading focus overlays for
|
|
3
|
+
"version": "0.8.6",
|
|
4
|
+
"description": "Reading focus overlays for DeepSeek Harness: gradient text, reading ruler, line and block focus, colour bands. Structure-based, so DSH 0.2.x class-name changes do not break it",
|
|
5
5
|
"author": "dsh-reading-focus contributors",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
package/preview.html
CHANGED
|
@@ -266,26 +266,88 @@ function createGradientController({state,roots,blocks,viewport,notify,flowOf}){
|
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
// Shown in the settings panel so a loaded build can be identified at a glance.
|
|
269
|
-
const RF_VERSION = '0.8.
|
|
269
|
+
const RF_VERSION = '0.8.6';
|
|
270
270
|
// One source of truth for the typography controls. The size range mirrors the host's own text
|
|
271
271
|
// stepper (10-22, default 14). Line height is not a ratio here: the host computes it as
|
|
272
272
|
// `24px + (size - 14)` (the `--dsh-content-font-delta` ladder), so this plugin only adds an
|
|
273
273
|
// optional extra on top of that instead of re-deriving a competing line height.
|
|
274
274
|
const RF_FONT = {sizeMin:10,sizeMax:22,sizeDefault:14,extraMin:0,extraMax:12,lineBase:24,baseSize:14};
|
|
275
|
-
//
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
275
|
+
// The host builds its client CSS as CSS Modules, so every local class carries a build-time hash.
|
|
276
|
+
// Two things changed across the 0.2.x line and neither is a contract:
|
|
277
|
+
// - the body container is `<hash>_body` (0.2.x: `xMeOpW_body`, earlier: `v5IAXa_body`);
|
|
278
|
+
// - the markdown root is `<hash>_markdown` in the current web frontend (`-TmMFa_markdown`), while
|
|
279
|
+
// the 0.2.2-rc.1/rc.3 builds emitted `_markdown_<hash>_<n>` instead.
|
|
280
|
+
// So nothing here spells a hash out: a body is a container whose class token ends in `_body`, and a
|
|
281
|
+
// root is a child whose class token contains `markdown`. Four other `_body` locals live in the same
|
|
282
|
+
// bundle (command rows, turn triggers, ...), so a body inside a non-assistant flow item is rejected;
|
|
283
|
+
// the kind check only applies when the host marks one. See docs/BEHAVIOR.md.
|
|
284
|
+
const RF_ROOT = '[class*="markdown"], [data-reading-focus-preview]';
|
|
285
|
+
const RF_FLOW = '[data-slot="conversation.chat.flow"], [data-chat-turn], [data-chat-flow-kind]';
|
|
286
|
+
// The marker this plugin writes on recognised bodies; the line-height rule anchors on it instead of
|
|
287
|
+
// on a class name. It is removed again when the typography override is cleared.
|
|
288
|
+
const RF_BODY_MARK = 'data-reading-focus-body';
|
|
289
|
+
// Reading bodies are the exact elements the root scan accepted, never "anything with a `_body` token".
|
|
290
|
+
const rfKnownBodies = new WeakSet();
|
|
291
|
+
// Set by rfPrimeBodies: whether the host still names a body container at all.
|
|
292
|
+
let rfBodyFallback = false;
|
|
293
|
+
function rfBodyToken(token) { return token.length > 5 && token.endsWith('_body'); }
|
|
294
|
+
function rfMarkdownToken(token) { return /markdown/i.test(token); }
|
|
295
|
+
function rfHasToken(node, test) {
|
|
296
|
+
if(!node || node.nodeType !== 1) return false;
|
|
297
|
+
const tokens = node.classList;
|
|
298
|
+
for(let i = 0; i < tokens.length; i++) if(test(tokens[i])) return true;
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
function rfIsBody(node) { return !!node && rfKnownBodies.has(node); }
|
|
302
|
+
function rfBodyAncestor(node) {
|
|
303
|
+
for(let el=node;el;el=el.parentElement)if(rfKnownBodies.has(el))return el;
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
// Bodies are the parents that hold markdown roots, so the structure never needs the class hash.
|
|
307
|
+
function rfMarkBodies(rootList) {
|
|
308
|
+
for(const root of rootList) {
|
|
309
|
+
const body = root?.parentElement;
|
|
310
|
+
if(body && !body.hasAttribute(RF_BODY_MARK)) body.setAttribute(RF_BODY_MARK, '');
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
// Fall back to structure only when the host no longer names the container at all.
|
|
314
|
+
function rfPrimeBodies(scope) {
|
|
315
|
+
rfBodyFallback = true;
|
|
316
|
+
for(const el of scope.querySelectorAll('[class*="_body"]')) if(rfHasToken(el, rfBodyToken)){rfBodyFallback = false;break;}
|
|
280
317
|
}
|
|
281
318
|
function matchesRoot(node) {
|
|
282
|
-
|
|
319
|
+
if(!node || node.nodeType !== 1) return false;
|
|
320
|
+
if(node.hasAttribute('data-reading-focus-preview')) return true;
|
|
321
|
+
const parent = node.parentElement;
|
|
322
|
+
if(!parent || !rfHasToken(node, rfMarkdownToken)) return false;
|
|
323
|
+
// A reading body is named `*_body` and holds a markdown root. Tool rows, command rows and turn
|
|
324
|
+
// triggers also carry a `_body` local in the same bundle, so the enclosing flow kind decides.
|
|
325
|
+
if(rfHasToken(parent, rfBodyToken)) {
|
|
326
|
+
const kind = parent.closest('[data-chat-flow-kind]');
|
|
327
|
+
if(kind && kind.getAttribute('data-chat-flow-kind') !== 'assistant-step') return false;
|
|
328
|
+
rfKnownBodies.add(parent); return true;
|
|
329
|
+
}
|
|
330
|
+
// The host renamed the `body` local: accept the container of any markdown root inside a flow.
|
|
331
|
+
if(rfBodyFallback && parent.closest(RF_FLOW)){rfKnownBodies.add(parent);return true;}
|
|
332
|
+
return false;
|
|
283
333
|
}
|
|
284
334
|
function queryRoots(node) { return [...node.querySelectorAll(RF_ROOT)].filter(matchesRoot); }
|
|
285
335
|
function closestRoot(node) {
|
|
286
336
|
for(let el=node;el;el=el.parentElement)if(matchesRoot(el))return el;
|
|
287
337
|
return null;
|
|
288
338
|
}
|
|
339
|
+
// First paragraph (or list item) of any reading body: type metrics and the fade colour read it.
|
|
340
|
+
function rfReadingSample(rootList) {
|
|
341
|
+
for(const root of rootList) {
|
|
342
|
+
if(!root?.isConnected) continue;
|
|
343
|
+
const body = root.parentElement;
|
|
344
|
+
if(!body) continue;
|
|
345
|
+
const text = body.querySelector('p, li') || root.querySelector('p, li');
|
|
346
|
+
if(text) return text;
|
|
347
|
+
}
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
function rfRootDocumentSample() { return document.querySelector('[class*="markdown"] p, [class*="markdown"] li'); }
|
|
289
351
|
const RF_BLOCK = 'p,li,h1,h2,h3,h4,h5,h6,blockquote,pre,table';
|
|
290
352
|
const RF_OCCLUDERS = '[data-composer-seat], [data-composer-card], [data-composer-overlay], [data-composer-dock], [data-composer-input], [data-code-block-banner], [data-conversation-region="composer"], [data-slot="conversation.input.dock"], [role="toolbar"], [role="menu"], [role="dialog"], dialog[open], [aria-modal="true"], footer';
|
|
291
353
|
|
|
@@ -396,8 +458,8 @@ function rfVeilColor(state){const key=state.mode==='blocks'?'blocks':'lines';ret
|
|
|
396
458
|
function rfTintColor(state){return rfRgba(rfColorValue(state,'blocks','tintColor','#4e9ee0'),rfColorValue(state,'blocks','tintOpacity',.1));}
|
|
397
459
|
// Block focus fades the text itself: the live text colour at reduced alpha blends with whatever
|
|
398
460
|
// background the theme uses, so no overlay is needed and the result inherits the real colours.
|
|
399
|
-
function rfDimColor(state){
|
|
400
|
-
const sample=
|
|
461
|
+
function rfDimColor(state, rootList){
|
|
462
|
+
const sample=rfReadingSample(rootList) || rfRootDocumentSample();
|
|
401
463
|
const rgb=sample?rfParseColor(getComputedStyle(sample).color):null;
|
|
402
464
|
const base=rgb?rgb.slice(0,3):[230,232,238];
|
|
403
465
|
const alpha=rfColorValue(state,'blocks','dimOpacity',.45);
|
|
@@ -424,8 +486,8 @@ function rfGradientPill(name){
|
|
|
424
486
|
}
|
|
425
487
|
// Read back the size the reading body actually renders, in the same px units the host's own
|
|
426
488
|
// stepper uses, so the panel opens on the host's real value instead of assuming 14px.
|
|
427
|
-
function rfHostFontSize(){
|
|
428
|
-
const body=
|
|
489
|
+
function rfHostFontSize(rootList){
|
|
490
|
+
const body=rfReadingSample(rootList) || rfRootDocumentSample();
|
|
429
491
|
if(!body)return RF_FONT.sizeDefault;
|
|
430
492
|
const size=Number.parseFloat(getComputedStyle(body).fontSize);
|
|
431
493
|
return Number.isFinite(size)&&size>0?size:RF_FONT.sizeDefault;
|
|
@@ -437,7 +499,7 @@ function rfHostLineHeight(size){return RF_FONT.lineBase + (size - RF_FONT.baseSi
|
|
|
437
499
|
// rfTypographyWritten remembers what this plugin last wrote, so a host-side change can be told
|
|
438
500
|
// apart from our own write when the observer fires.
|
|
439
501
|
let rfTypographyWritten='';
|
|
440
|
-
function rfApplyTypography(font,{writeVar=true}={}){
|
|
502
|
+
function rfApplyTypography(font,{writeVar=true,roots=null}={}){
|
|
441
503
|
const target=document.body;
|
|
442
504
|
const px=Number.isFinite(font?.size)?font.size:null;
|
|
443
505
|
const extra=Number.isFinite(font?.extra)?Math.max(0,font.extra):0;
|
|
@@ -447,13 +509,16 @@ function rfApplyTypography(font,{writeVar=true}={}){
|
|
|
447
509
|
if(px!==null&&writeVar){target.style.setProperty('--dsh-content-font-size',px.toFixed(2)+'px');rfTypographyWritten=px.toFixed(2)+'px';}
|
|
448
510
|
// Only an explicit extra spacing overrides the host ladder, and even then it rides the host's own
|
|
449
511
|
// variable: the size delta still applies, so a later font-size change keeps the added room.
|
|
450
|
-
|
|
512
|
+
// The rule targets the bodies this plugin has already recognised, because their class names carry
|
|
513
|
+
// a build hash that differs between host versions.
|
|
514
|
+
if(px!==null&&extra>0){if(roots)rfMarkBodies(roots);const m=`[${RF_BODY_MARK}]`;rules.push(`${m},${m} p,${m} li,:is(${m}>*){line-height:calc(${RF_FONT.lineBase}px + var(--dsh-content-font-delta, 0px) + ${extra}px)}`);}
|
|
451
515
|
probe.textContent=rules.join('\n');
|
|
452
516
|
}
|
|
453
517
|
// The plugin owns that style element and any value it wrote itself: unloading it must not leave
|
|
454
518
|
// the host document permanently re-typeset, and it must not remove a size the host set later.
|
|
455
519
|
function rfClearTypography(){
|
|
456
520
|
document.getElementById('rf-typography')?.remove();
|
|
521
|
+
for(const el of document.querySelectorAll(`[${RF_BODY_MARK}]`))el.removeAttribute(RF_BODY_MARK);
|
|
457
522
|
if(rfTypographyWritten&&document.body.style.getPropertyValue('--dsh-content-font-size')===rfTypographyWritten)document.body.style.removeProperty('--dsh-content-font-size');
|
|
458
523
|
rfTypographyWritten='';
|
|
459
524
|
}
|
|
@@ -607,11 +672,11 @@ function startReadingFocus() {
|
|
|
607
672
|
// the column and the width handles is blank margin, not reading space.
|
|
608
673
|
// A brand-new session has a composer but no message body; the effects have nothing to focus on
|
|
609
674
|
// and must stay off until the first answer exists.
|
|
610
|
-
function hasConversation(scope){return !!scope?.
|
|
675
|
+
function hasConversation(scope){return !!scope?.querySelectorAll && queryRoots(scope).length>0;}
|
|
611
676
|
function textColumn(scope){
|
|
612
|
-
const
|
|
677
|
+
const root=scope?.querySelectorAll?queryRoots(scope)[0]:null;
|
|
678
|
+
const body=root?.parentElement;
|
|
613
679
|
if(body){const r=rect(body);if(r.right-r.left>8)return r;}
|
|
614
|
-
const root=scope?.querySelector?.(RF_ROOT);
|
|
615
680
|
if(root){const r=rect(root);if(r.right-r.left>8)return r;}
|
|
616
681
|
return bandsWidth(scope);
|
|
617
682
|
}
|
|
@@ -833,7 +898,7 @@ function startReadingFocus() {
|
|
|
833
898
|
// uses, so one number means the same thing in both places. `extra` is added to the host's own
|
|
834
899
|
// automatic line height, so 0 means "exactly like DSH".
|
|
835
900
|
const syncFontControls=()=>{const f=state.font;
|
|
836
|
-
const px=Number.isFinite(f.size)?f.size:rfHostFontSize();
|
|
901
|
+
const px=Number.isFinite(f.size)?f.size:rfHostFontSize(roots);
|
|
837
902
|
const extra=Number.isFinite(f.extra)?f.extra:0;
|
|
838
903
|
fontSize.value=String(Math.round(px));fontExtra.value=String(Math.round(extra));};
|
|
839
904
|
const refresh=()=>{
|
|
@@ -900,7 +965,7 @@ function startReadingFocus() {
|
|
|
900
965
|
const px=clamp(Number.isFinite(sizeNum)?Math.round(sizeNum):RF_FONT.sizeDefault,RF_FONT.sizeMin,RF_FONT.sizeMax);
|
|
901
966
|
const extra=clamp(Number.isFinite(extraNum)?Math.round(extraNum):RF_FONT.extraMin,RF_FONT.extraMin,RF_FONT.extraMax);
|
|
902
967
|
state.font={size:px,extra};
|
|
903
|
-
rfApplyTypography(state.font);save();
|
|
968
|
+
rfApplyTypography(state.font,{roots});save();
|
|
904
969
|
if(commit)syncFontControls();
|
|
905
970
|
gradient.invalidate();queue();
|
|
906
971
|
};
|
|
@@ -977,14 +1042,14 @@ function startReadingFocus() {
|
|
|
977
1042
|
}
|
|
978
1043
|
// The host's own settings write the same variable; adopt it when the write was not ours.
|
|
979
1044
|
if(records.some(rec=>rec.type==='attributes'&&rec.target===document.body&&rec.attributeName==='style'))adoptHostTypography();
|
|
980
|
-
if(structure){for(const r of roots)if(!r.isConnected||!matchesRoot(r)){blockCache.delete(r);roots.delete(r);if(activeBody===r){activeBody=null;activeBlock=null;if(!rfPointerMode(state.mode))hovering=false;}}watchRoots();}
|
|
1045
|
+
if(structure){for(const r of roots)if(!r.isConnected||!matchesRoot(r)){blockCache.delete(r);roots.delete(r);if(activeBody===r){activeBody=null;activeBlock=null;if(!rfPointerMode(state.mode))hovering=false;}}watchRoots();if(document.getElementById('rf-typography')?.textContent)rfMarkBodies(roots);}
|
|
981
1046
|
if(changed||structure){
|
|
982
1047
|
occluderCandidates=null;
|
|
983
1048
|
if(structure)invalidate();
|
|
984
1049
|
if(structure&&state.mode==='gradient')gradient.scan();queue(true);queuePanel();
|
|
985
1050
|
}
|
|
986
1051
|
});
|
|
987
|
-
function startObservers(){roots.clear();occluderCandidates=null;queryRoots(document).forEach(el=>roots.add(el));watchRoots();observer.observe(document.body,{subtree:true,childList:true,characterData:true,attributes:true,attributeFilter:['open','aria-modal','role','inert','data-ds-dark-theme','data-conversation-session','hidden','class','style']});}
|
|
1052
|
+
function startObservers(){roots.clear();occluderCandidates=null;rfPrimeBodies(document);queryRoots(document).forEach(el=>roots.add(el));rfMarkBodies(roots);watchRoots();observer.observe(document.body,{subtree:true,childList:true,characterData:true,attributes:true,attributeFilter:['open','aria-modal','role','inert','data-ds-dark-theme','data-conversation-session','hidden','class','style']});}
|
|
988
1053
|
function stopObservers(){observer.disconnect();resizeObserver.disconnect();roots.clear();occluderCandidates=null;}
|
|
989
1054
|
function blocks(root){
|
|
990
1055
|
let cached=blockCache.get(root);
|
|
@@ -1054,7 +1119,7 @@ function startReadingFocus() {
|
|
|
1054
1119
|
if(now-lineHeightFrame>200)lineHeightCache=new Map(),lineHeightFrame=now;
|
|
1055
1120
|
const key=scope||document.documentElement;
|
|
1056
1121
|
if(lineHeightCache.has(key))return lineHeightCache.get(key);
|
|
1057
|
-
const probe=key
|
|
1122
|
+
const probe=rfReadingSample(key?.querySelectorAll?queryRoots(key):[]);
|
|
1058
1123
|
let value=24;
|
|
1059
1124
|
if(probe){const s=getComputedStyle(probe);value=rfLineHeight(s.fontSize,s.lineHeight,probe.getClientRects()[0]?.height);}
|
|
1060
1125
|
else{const s=getComputedStyle(key);value=rfLineHeight(s.fontSize,s.lineHeight,NaN);}
|
|
@@ -1162,7 +1227,7 @@ function startReadingFocus() {
|
|
|
1162
1227
|
// the interruption rather than restarting from base. Roots from a different answer (another
|
|
1163
1228
|
// turn) stay separate, so a new answer does open at base.
|
|
1164
1229
|
function rootGroup(root){
|
|
1165
|
-
const lane=root
|
|
1230
|
+
const lane=rfBodyAncestor(root)||root.parentElement;
|
|
1166
1231
|
if(!lane)return [root];
|
|
1167
1232
|
const scope=flowScope(lane)||lane;
|
|
1168
1233
|
const all=[...scope.querySelectorAll(RF_ROOT)].filter(matchesRoot);
|
|
@@ -1198,11 +1263,14 @@ function startReadingFocus() {
|
|
|
1198
1263
|
}
|
|
1199
1264
|
function sameLane(a,b){return a.scroll===b.scroll&&a.session===b.session&&a.fallback===b.fallback&&a.chain.length===b.chain.length&&a.chain.every((x,i)=>x===b.chain[i]);}
|
|
1200
1265
|
function bandBarriers(rawRects){
|
|
1201
|
-
const selector='[data-turn-process-inline], [data-turn-process], [data-step-process], [data-chat-flow-kind="turn-process"], [data-chat-flow-kind="tool"], [data-chat-flow-kind="received-task"], [data-chat-steering-batch]
|
|
1266
|
+
const selector='[data-turn-process-inline], [data-turn-process], [data-step-process], [data-chat-flow-kind="turn-process"], [data-chat-flow-kind="tool"], [data-chat-flow-kind="received-task"], [data-chat-steering-batch]';
|
|
1202
1267
|
const result=[];
|
|
1203
1268
|
const candidates=new Set(document.querySelectorAll(selector));
|
|
1204
1269
|
for(const el of document.querySelectorAll('[data-chat-flow-kind]:not([data-chat-flow-kind="assistant-step"])'))if(!matchesRoot(el)&&!queryRoots(el).length)candidates.add(el);
|
|
1205
|
-
|
|
1270
|
+
// Bodies come from the recognised roots, so no class hash is assumed here either.
|
|
1271
|
+
const bodies=new Set();
|
|
1272
|
+
for(const root of roots)if(root.parentElement)bodies.add(root.parentElement);
|
|
1273
|
+
for(const body of bodies){for(const el of body.children)if(!matchesRoot(el)&&!queryRoots(el).length)candidates.add(el);for(const el of body.querySelectorAll('img, video, canvas'))candidates.add(el);}
|
|
1206
1274
|
for(const el of candidates){
|
|
1207
1275
|
if(!el.isConnected||el.closest('[data-text-interaction-surface], [hidden], [aria-hidden="true"]'))continue;
|
|
1208
1276
|
const s=getComputedStyle(el),r=rect(el),image=el.matches('img,video,canvas');
|
|
@@ -1332,7 +1400,7 @@ function startReadingFocus() {
|
|
|
1332
1400
|
if(held)block=focusHold.block;
|
|
1333
1401
|
if(!block){focusHold.block=null;clearDim();patchShapes(shapes);return;}
|
|
1334
1402
|
focusHold={block,at:performance.now(),scrollY};
|
|
1335
|
-
if(state.blockStyle!=='veil'&&paintDim(block,rfDimColor(state))){patchShapes(shapes);return;}
|
|
1403
|
+
if(state.blockStyle!=='veil'&&paintDim(block,rfDimColor(state,roots))){patchShapes(shapes);return;}
|
|
1336
1404
|
// Veil presentation, or a browser without CSS Custom Highlight.
|
|
1337
1405
|
clearDim();
|
|
1338
1406
|
const group=activeBody?rootGroup(activeBody):[];
|
|
@@ -1386,7 +1454,8 @@ function startReadingFocus() {
|
|
|
1386
1454
|
clearPointer();return;
|
|
1387
1455
|
}
|
|
1388
1456
|
const targetCut=target?.closest?.(RF_OCCLUDERS);
|
|
1389
|
-
|
|
1457
|
+
const targetBody=rfBodyAncestor(target);
|
|
1458
|
+
if((targetCut&&isHostOccluder(targetCut)) || (targetBody && !closestRoot(target) && targetBody!==target)){hovering=false;return;}
|
|
1390
1459
|
// Read every candidate rectangle first, decide afterwards: interleaving rect reads with the
|
|
1391
1460
|
// elementFromPoint above is what makes a scroll-costly forced layout.
|
|
1392
1461
|
let best=null,dist=Infinity;
|
|
@@ -1395,7 +1464,7 @@ function startReadingFocus() {
|
|
|
1395
1464
|
const rr=rect(root),r=rfIntersect(rr,viewport(root));
|
|
1396
1465
|
if(!r||lastX<r.left-12||lastX>r.right+12)continue;
|
|
1397
1466
|
let top=r.top-12,bottom=r.bottom+12;
|
|
1398
|
-
if(root.parentElement
|
|
1467
|
+
if(root.parentElement && rfIsBody(root.parentElement)){
|
|
1399
1468
|
const prev=root.previousElementSibling,next=root.nextElementSibling;
|
|
1400
1469
|
if(matchesRoot(prev))top=Math.min(top,(rect(prev).bottom+rr.top)/2);
|
|
1401
1470
|
if(matchesRoot(next))bottom=Math.max(bottom,(rr.bottom+rect(next).top)/2);
|
|
@@ -1454,7 +1523,7 @@ function startReadingFocus() {
|
|
|
1454
1523
|
}
|
|
1455
1524
|
const onLayout=()=>{queue(true);queuePanel();};const onResize=()=>{if(state.mode==='gradient')gradient.invalidate();onLayout();};
|
|
1456
1525
|
// Adopt a saved font on load, but never write one that was never customised.
|
|
1457
|
-
if(Object.keys(state.font).length)rfApplyTypography(state.font);document.addEventListener('pointermove',onMove,{passive:true});document.addEventListener('keydown',onKey);window.addEventListener('scroll',onScroll,true);window.addEventListener('resize',onResize);
|
|
1526
|
+
if(Object.keys(state.font).length)rfApplyTypography(state.font,{roots});document.addEventListener('pointermove',onMove,{passive:true});document.addEventListener('keydown',onKey);window.addEventListener('scroll',onScroll,true);window.addEventListener('resize',onResize);
|
|
1458
1527
|
// The on/off choice is a preference like any other: restoring it means the user does not have to
|
|
1459
1528
|
// re-enable the effect after every restart.
|
|
1460
1529
|
if(state.enabled)setEnabled(true);else sync();
|