dsh-composer-live 0.2.16 → 0.2.18
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/CHANGELOG.md +21 -0
- package/README.md +28 -3
- package/README.zh-CN.md +30 -3
- package/client.js +141 -42
- package/docs/screenshots/demo.gif +0 -0
- package/package.json +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
> 更新日志以中文记录。Changelog entries are written in Chinese.
|
|
4
4
|
|
|
5
|
+
## 0.2.18(2026-11-01)
|
|
6
|
+
|
|
7
|
+
**文档与发布物料更新(功能零变更)——README 双语大修 + 首个动态演示 GIF。**
|
|
8
|
+
|
|
9
|
+
- **新增动态演示 GIF**(`docs/screenshots/demo.gif`,960×540、109 帧、1.8MB):真实逐字打字过程——行内四件套(粗体/行内代码胶囊/斜体/删除线)、列表与任务项、```` ```js ```` 围栏自动补全成代码块并语法高亮,一镜到底。录制脚本 `e2e/capture-demo-gif.mjs`(CDP screencast + trusted 逐字打字通道,随仓库工具链留档,发布白名单不含)。
|
|
10
|
+
- README(中英双语)五处增强:顶部嵌入演示 GIF;徽章更新为「206 单测 · 129 E2E」;新增「实测版本」表(0.1.5-rc.2 / 0.2.0-rc.2 / 0.2.1-rc.5 三代全绿,双环境 E2E 是本插件独有的质量承诺);新增「与其它输入框插件的关系」对比表(composer-plus / composer-enter / prompt-history 互不重叠可共存);新增「反馈」段(issue 入口)。
|
|
11
|
+
- 修正过时数字:单测 188→206、E2E 62→129 场景。
|
|
12
|
+
- npm keywords 增补(live-preview / toolbar / format / paste)。
|
|
13
|
+
|
|
14
|
+
## 0.2.17(2026-10-24)
|
|
15
|
+
|
|
16
|
+
**渲染性能大优化:空闲主线程占用 98% → 0、打字帧率 6fps → 125fps(200 行文档实测)。**
|
|
17
|
+
|
|
18
|
+
- **问题画像**(diag-perf 基准,200 行文档):优化前空闲 10 秒 161 次全量渲染(16 次/秒)共 9.8 秒长任务(**98% 主线程占用**);打字 60 字 140 次渲染、帧中位 175ms(≈6fps);拖选扩选 20 次触发 75 次渲染。
|
|
19
|
+
- **根因**:① MutationObserver 观察整个 `document.body`——页面上其它组件(皮肤中心/费用统计/React 渲染)的任何 DOM 活动都转化为本插件的全量渲染;② `selectionchange` 无合帧直通 render,拖选以指针级频率触发;③ 500ms 兜底轮询每轮全量;④ **每次渲染全量无短路**——3000 字符逐个 `getBoundingClientRect` + 每行 DOM 解析 tokenize + `innerHTML` 整块重建。
|
|
20
|
+
- **修法四件**:① **渲染签名短路**——内容 + 光标行 + 相对几何(相对 overlay 的坐标,滚动天然零重渲染)+ 字体栈 + 主题色全部相同则跳过测量与重建(只更新随精确光标变的工具栏高亮);② **行级测量缓存**——行的字符 rect 只依赖行文本与行起点,key=行文本、布局代(字体/几何/主题)变化整体作废、命中后验证行首字符 x/y(前行动态折行会平移本行)不过则重测,200 行文档从 ~3000 次测量降到 ~300 次验证;③ `selectionchange` rAF 合帧;④ MutationObserver 回调过滤到输入卡内(卡外噪音由 500ms 兜底轮询覆盖)。
|
|
21
|
+
- 顺手清理:`ov.__dshClLineCache` 死代码(v0.1.x 增量渲染时代的清理残留,缓存本体早已不存在);chip 行不再测量(原版测了但渲染侧整行降级无消费方)。
|
|
22
|
+
- 基准对比(diag-perf.mjs 留档):空闲渲染 161→0、长任务 161→0、帧中位 66ms→8ms、heap 110→79MB;打字渲染 140→60(每键恰 1 次)、帧中位 175ms→8ms;扩选渲染 75→1(仅跨行那次)。
|
|
23
|
+
- 已知边界:超大文档(200 行级)连续打字时每次内容变化仍全量重建 overlay(段 HTML 解析+布局,剩余长任务的主要构成,实测中位帧 8ms 可接受);行级 DOM 差量更新属边际收益未做。
|
|
24
|
+
- L0 单测 206 项通过;双环境 129 场景全绿。
|
|
25
|
+
|
|
5
26
|
## 0.2.16(2026-10-24)
|
|
6
27
|
|
|
7
28
|
**选中一段文字加粗/斜体/行内码后,选区后面的字消失(用户实测反馈「翻转头去选择一部分文字用 Ctrl+B,在它后面的有一些字就消失了」)。**
|
package/README.md
CHANGED
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|

|
|
8
8
|

|
|
9
|
-

|
|
10
|
+
|
|
11
|
+

|
|
10
12
|
|
|
11
13
|
dsh-composer-live turns the DSH Web input box into an Open-WebUI-style live editor: you type Markdown, it renders as you type — bold, italic, code blocks with syntax highlighting, lists, quotes, tables — while the draft itself stays plain Markdown source, so what you send is exactly what you typed.
|
|
12
14
|
|
|
@@ -100,6 +102,14 @@ The official composer already provides — and this plugin deliberately does not
|
|
|
100
102
|
- A **Chromium-based browser** (Chrome, Edge, …): the transparency technique relies on `-webkit-text-fill-color`.
|
|
101
103
|
- OS-independent — it is pure DOM/CSS with no native dependencies.
|
|
102
104
|
|
|
105
|
+
**Verified DSH versions** — every release runs the full 129-scenario E2E suite on two live instances covering both supported generations:
|
|
106
|
+
|
|
107
|
+
| DSH version | Status |
|
|
108
|
+
| --- | --- |
|
|
109
|
+
| 0.1.5-rc.2 | ✅ E2E tested |
|
|
110
|
+
| 0.2.0-rc.2 | ✅ E2E tested |
|
|
111
|
+
| 0.2.1-rc.5 | ✅ E2E tested (primary) |
|
|
112
|
+
|
|
103
113
|
## Installation
|
|
104
114
|
|
|
105
115
|
```bash
|
|
@@ -149,11 +159,22 @@ See [docs/architecture.md](./docs/architecture.md) for the full deep dive.
|
|
|
149
159
|
- "Stop generating" is matched by aria-label (English and Chinese enumerated); if upstream renames the label, use the button directly.
|
|
150
160
|
- `web` profile only; Chromium-family browsers only.
|
|
151
161
|
|
|
162
|
+
## Complementary plugins
|
|
163
|
+
|
|
164
|
+
This plugin focuses purely on the **editing experience**. Other composer plugins focus on different things — they do not overlap, and can be installed together:
|
|
165
|
+
|
|
166
|
+
| Plugin | What it does | Overlap with dsh-composer-live |
|
|
167
|
+
| --- | --- | --- |
|
|
168
|
+
| **dsh-composer-live** (this one) | Live Markdown rendering, code blocks, lists/quotes/tables, format toolbars, paste handling | — |
|
|
169
|
+
| dsh-composer-plus | Model picker, reasoning-effort rail, account display in the composer | none — different layer |
|
|
170
|
+
| dsh-client-composer-enter | Swaps Enter/Shift+Enter send behaviour | none — keymap only |
|
|
171
|
+
| dsh-prompt-history | ↑ history recall with prefix search | none — recall, not rendering |
|
|
172
|
+
|
|
152
173
|
## Development
|
|
153
174
|
|
|
154
175
|
```bash
|
|
155
|
-
node test-live.cjs #
|
|
156
|
-
node e2e/run-e2e.mjs #
|
|
176
|
+
node test-live.cjs # 206 unit tests (pure functions, no browser needed)
|
|
177
|
+
node e2e/run-e2e.mjs # 129-scenario × 10-invariant E2E suite against a live instance
|
|
157
178
|
```
|
|
158
179
|
|
|
159
180
|
The E2E runner expects a DSH web instance with this source deployed and derives everything from environment variables: `DSH_CL_PORT` (default 8124) and `DSH_CL_DSH_HOME` (defaults to `DSH_HOME`, then `~/.dsh`) locate the deployed copy for a version check; the auth cookie is fetched automatically. See [e2e/README.md](./e2e/README.md) for the full variable list.
|
|
@@ -176,6 +197,10 @@ It is batched per render frame and merged into a few absolutely-positioned spans
|
|
|
176
197
|
**Will a DSH update break it?**
|
|
177
198
|
Zero service injection plus `data-`-attribute anchoring make it resilient to routine updates (class-name hash churn, client API refactors). When the official composer *architecture itself* changes — as 0.1.1 → 0.1.5 did, textarea → Lexical — the plugin needs a port. This plugin *is* that port: `dsh-composer-md` was its 0.1.x predecessor and is now discontinued.
|
|
178
199
|
|
|
200
|
+
## Feedback
|
|
201
|
+
|
|
202
|
+
Found a bug, a misaligned character, or a DSH version that misbehaves? Please [open an issue](https://github.com/zeusxx/dsh-composer-live/issues) — screenshots plus your DSH version help a lot. Feature ideas (new shortcuts, highlighting languages, block styles) are equally welcome.
|
|
203
|
+
|
|
179
204
|
## License
|
|
180
205
|
|
|
181
206
|
[MIT](./LICENSE)
|
package/README.zh-CN.md
CHANGED
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|

|
|
8
8
|

|
|
9
|
-

|
|
10
|
+
|
|
11
|
+

|
|
10
12
|
|
|
11
13
|
dsh-composer-live 把 DSH Web 的输入框变成 Open WebUI 风格的实时编辑器:你打 Markdown,它边打边渲染——加粗、斜体、带语法高亮的代码块、列表、引用、表格——而草稿本身始终是纯 Markdown 源文本,发送出去的就是你输入的原文。
|
|
12
14
|
|
|
@@ -94,6 +96,16 @@ dsh-composer-live 把 DSH Web 的输入框变成 Open WebUI 风格的实时编
|
|
|
94
96
|
| ↓ | 已闭合块最后一个内容行 | 跳到块后 |
|
|
95
97
|
| Esc | 菜单开着→官方 · 展开态→收起 · 生成中→停止 | 按语境分发 |
|
|
96
98
|
|
|
99
|
+
## 实测版本
|
|
100
|
+
|
|
101
|
+
每个版本发布前都在两个真实实例上跑完整 129 场景 E2E(覆盖两代支持的架构):
|
|
102
|
+
|
|
103
|
+
| DSH 版本 | 状态 |
|
|
104
|
+
| --- | --- |
|
|
105
|
+
| 0.1.5-rc.2 | ✅ E2E 实测通过 |
|
|
106
|
+
| 0.2.0-rc.2 | ✅ E2E 实测通过 |
|
|
107
|
+
| 0.2.1-rc.5 | ✅ E2E 实测通过(主力环境) |
|
|
108
|
+
|
|
97
109
|
## 环境要求
|
|
98
110
|
|
|
99
111
|
- **DSH ≥ 0.1.5-rc.2**,`web` profile——本插件面向 0.1.5 的 Lexical contenteditable 输入框。
|
|
@@ -152,8 +164,8 @@ DSH_HOME=/path/to/your/.dsh dsh plugin --profile web add dsh-composer-live
|
|
|
152
164
|
## 开发
|
|
153
165
|
|
|
154
166
|
```bash
|
|
155
|
-
node test-live.cjs #
|
|
156
|
-
node e2e/run-e2e.mjs #
|
|
167
|
+
node test-live.cjs # 206 项单测(纯函数,无需浏览器)
|
|
168
|
+
node e2e/run-e2e.mjs # 129 场景 × 10 不变量的 E2E 套件(对着运行中的实例测)
|
|
157
169
|
```
|
|
158
170
|
|
|
159
171
|
E2E runner 要求被测实例已部署当前源码,路径全部由环境变量推导:`DSH_CL_PORT`(默认 8124)与 `DSH_CL_DSH_HOME`(默认取 `DSH_HOME`,再默认 `~/.dsh`)定位部署副本做版本对照,鉴权 cookie 自动获取。完整变量表见 [e2e/README.md](./e2e/README.md)。
|
|
@@ -162,6 +174,17 @@ E2E runner 要求被测实例已部署当前源码,路径全部由环境变量
|
|
|
162
174
|
|
|
163
175
|
版本纪律:每次改动 bump `package.json` 并在 [CHANGELOG.md](./CHANGELOG.md) 记一笔。
|
|
164
176
|
|
|
177
|
+
## 与其它输入框插件的关系
|
|
178
|
+
|
|
179
|
+
本插件只做**编辑体验**这一层。其它输入框类插件做的是别的事情——互不重叠,可以同时安装:
|
|
180
|
+
|
|
181
|
+
| 插件 | 做什么 | 与本插件的重叠 |
|
|
182
|
+
| --- | --- | --- |
|
|
183
|
+
| **dsh-composer-live**(本插件) | Markdown 实时渲染、代码块、列表/引用/表格、格式工具栏、粘贴处理 | — |
|
|
184
|
+
| dsh-composer-plus | 输入框里的模型切换、推理力度、账号显示 | 无——不同层面 |
|
|
185
|
+
| dsh-client-composer-enter | 交换 Enter/Shift+Enter 的发送行为 | 无——只改键位映射 |
|
|
186
|
+
| dsh-prompt-history | ↑ 调历史输入(带前缀搜索) | 无——是回忆,不是渲染 |
|
|
187
|
+
|
|
165
188
|
## FAQ
|
|
166
189
|
|
|
167
190
|
**为什么只支持 Chromium 系?**
|
|
@@ -176,6 +199,10 @@ E2E runner 要求被测实例已部署当前源码,路径全部由环境变量
|
|
|
176
199
|
**DSH 升级会弄坏它吗?**
|
|
177
200
|
零服务注入 + `data-` 属性锚定让它对日常升级(类名哈希变化、client API 重构)免疫。当官方输入框**架构本身**变化时——比如 0.1.1 → 0.1.5 从 textarea 换成 Lexical——插件需要重写。本插件正是那次重写的产物:`dsh-composer-md` 是它的 0.1.x 前身,现已停止维护。
|
|
178
201
|
|
|
202
|
+
## 反馈
|
|
203
|
+
|
|
204
|
+
发现 bug、字符错位、或某个 DSH 版本上表现异常?欢迎[提 issue](https://github.com/zeusxx/dsh-composer-live/issues)——附上截图和 DSH 版本号会很有帮助。功能建议(新快捷键、高亮语言、块样式)同样欢迎。
|
|
205
|
+
|
|
179
206
|
## 许可证
|
|
180
207
|
|
|
181
208
|
[MIT](./LICENSE)
|
package/client.js
CHANGED
|
@@ -398,47 +398,99 @@ window.__ModuleLoader__.load({
|
|
|
398
398
|
}
|
|
399
399
|
|
|
400
400
|
/**
|
|
401
|
-
* 逐行逐字符测量编辑器 rect
|
|
402
|
-
* chip
|
|
401
|
+
* 逐行逐字符测量编辑器 rect(v0.2.17 起行级缓存)。返回 lineChars[行] =
|
|
402
|
+
* [{off(行内偏移), x, y, w, h, voff(可见序,\\r 不占位)}];chip 行返回空数组
|
|
403
|
+
* (其所在行整段降级官方显示,测量数据无消费方——原版也测了但没人用)。
|
|
404
|
+
*
|
|
405
|
+
* 缓存(打字路径的核心优化:200 行文档全量测量 ≈3000 次 getBoundingClientRect
|
|
406
|
+
* ≈30-60ms/帧,实测打字掉到 6fps):行的字符 rect 只依赖「行文本 + 行起点 +
|
|
407
|
+
* 字体 + 容器几何」。key = 行文本;布局代(字体栈/容器几何/主题)变化时整体
|
|
408
|
+
* 作废。命中后仍验证行首字符的 x/y——前面的行折行数变化会平移本行起点(文本
|
|
409
|
+
* 没变位置变了),验证不过就重测该行。验证成本 1 次 rect/行(300 行文档从
|
|
410
|
+
* 3000 次测量降到 ~300 次)。同文本多行(空行/重复行)共享 key 互相顶替 →
|
|
411
|
+
* 各自全测,无害。
|
|
403
412
|
*/
|
|
404
|
-
function measureAnchorChars(anchors, lineCount) {
|
|
413
|
+
function measureAnchorChars(anchors, lineCount, cache, layoutGen) {
|
|
414
|
+
const useCache = !!(cache && layoutGen);
|
|
415
|
+
if (useCache && cache.gen !== layoutGen) { cache.gen = layoutGen; cache.lines.clear(); }
|
|
405
416
|
const range = document.createRange();
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
417
|
+
// 第一遍(零测量):把锚流切成分段的「行」(seg = 文本节点内的字符区间),
|
|
418
|
+
// 同时拼出行文本(缓存 key)。行边界 = br/para 锚 + 文本节点内字面 \n。
|
|
419
|
+
const rows = [[]];
|
|
420
|
+
const texts = [""];
|
|
421
|
+
let off = 0; // 行内投影偏移(与原版语义一致:字面 \n 后 = 0 - i - 1,使行内后续字符 off 归零)
|
|
410
422
|
for (const a of anchors) {
|
|
411
|
-
if (a.kind === "br" || a.kind === "para") {
|
|
412
|
-
if (a.kind === "chip") { off++; continue; }
|
|
423
|
+
if (a.kind === "br" || a.kind === "para") { rows.push([]); texts.push(""); off = 0; continue; }
|
|
424
|
+
if (a.kind === "chip") { off++; texts[texts.length - 1] += ""; continue; }
|
|
413
425
|
const node = a.node;
|
|
414
426
|
if (!node || node.nodeType !== Node.TEXT_NODE) { continue; }
|
|
415
427
|
const len = node.nodeValue.length;
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
range.setEnd(node, i + 1);
|
|
427
|
-
const r = range.getBoundingClientRect();
|
|
428
|
-
if (r) lineChars[lineIdx].push({ off: off + i, x: r.left, y: r.top, w: r.width, h: r.height });
|
|
428
|
+
let segStart = 0;
|
|
429
|
+
for (let i = 0; i < len; i++) {
|
|
430
|
+
// 字面 \n 推进行号(与 src.split("\n") 行边界一致——粘贴大段文本正是
|
|
431
|
+
// 「单节点含字面 \n」形态,不推进会 chars 全记第 0 行 → 渲染段全空)。
|
|
432
|
+
if (node.nodeValue.charCodeAt(i) === 10) {
|
|
433
|
+
if (segStart < i) {
|
|
434
|
+
rows[rows.length - 1].push({ node, from: segStart, to: i, base: off + segStart });
|
|
435
|
+
texts[texts.length - 1] += node.nodeValue.slice(segStart, i);
|
|
436
|
+
}
|
|
437
|
+
rows.push([]); texts.push(""); off = 0 - i - 1; segStart = i + 1;
|
|
429
438
|
}
|
|
430
|
-
}
|
|
439
|
+
}
|
|
440
|
+
if (segStart < len) {
|
|
441
|
+
rows[rows.length - 1].push({ node, from: segStart, to: len, base: off + segStart });
|
|
442
|
+
texts[texts.length - 1] += node.nodeValue.slice(segStart);
|
|
443
|
+
}
|
|
431
444
|
off += len;
|
|
432
445
|
}
|
|
446
|
+
// 第二遍:逐行缓存判定 → 命中直接用;miss 全行测量并回填。
|
|
447
|
+
const lineChars = [];
|
|
448
|
+
for (let li = 0; li < lineCount; li++) {
|
|
449
|
+
const row = li < rows.length ? rows[li] : null;
|
|
450
|
+
const text = li < texts.length ? texts[li] : null;
|
|
451
|
+
let chars = null;
|
|
452
|
+
if (useCache && row && row.length) {
|
|
453
|
+
const m = cache.lines.get(text);
|
|
454
|
+
if (m && m.length) {
|
|
455
|
+
const s0 = row[0];
|
|
456
|
+
try {
|
|
457
|
+
range.setStart(s0.node, s0.from);
|
|
458
|
+
range.setEnd(s0.node, s0.from + 1);
|
|
459
|
+
const pr = range.getBoundingClientRect();
|
|
460
|
+
if (pr && Math.abs(pr.top - m[0].y) < 0.5 && Math.abs(pr.left - m[0].x) < 0.5) chars = m;
|
|
461
|
+
} catch (err) { /* 验证失败 → 全行重测 */ }
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
if (!chars) {
|
|
465
|
+
chars = [];
|
|
466
|
+
if (row) {
|
|
467
|
+
// 逐段容错:批量编辑期间 DOM 可能正被 Lexical 重建,个别节点测量
|
|
468
|
+
// 抛错时跳过该段(下一轮渲染自愈),不让整个渲染中断。
|
|
469
|
+
for (const seg of row) {
|
|
470
|
+
try {
|
|
471
|
+
for (let i = seg.from; i < seg.to; i++) {
|
|
472
|
+
range.setStart(seg.node, i);
|
|
473
|
+
range.setEnd(seg.node, i + 1);
|
|
474
|
+
const r = range.getBoundingClientRect();
|
|
475
|
+
if (r) chars.push({ off: seg.base + i - seg.from, x: r.left, y: r.top, w: r.width, h: r.height });
|
|
476
|
+
}
|
|
477
|
+
} catch (err) { /* 跳过该段 */ }
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
if (useCache && chars.length) cache.lines.set(text, chars);
|
|
481
|
+
}
|
|
482
|
+
lineChars.push(chars);
|
|
483
|
+
}
|
|
484
|
+
if (useCache && cache.lines.size > 800) cache.lines.clear(); // 上限防泄漏(长会话删行残留)
|
|
433
485
|
return lineChars;
|
|
434
486
|
}
|
|
435
487
|
|
|
436
488
|
/** 字符锚定渲染主入口:清空 overlay,按测量坐标输出「整块背景 + 定位字符段」。 */
|
|
437
|
-
function renderCharOverlay(ov, input, anchors, lines, states, refs) {
|
|
489
|
+
function renderCharOverlay(ov, input, anchors, lines, states, refs, cache, layoutGen) {
|
|
438
490
|
const ovRect = ov.getBoundingClientRect();
|
|
439
491
|
const ox = ovRect.left, oy = ovRect.top;
|
|
440
492
|
const segLineHeight = getComputedStyle(ov).lineHeight; // 段定位的 half-leading 修正用
|
|
441
|
-
const lineChars = measureAnchorChars(anchors, lines.length);
|
|
493
|
+
const lineChars = measureAnchorChars(anchors, lines.length, cache, layoutGen);
|
|
442
494
|
// 容器内容区(块背景的水平范围——统一宽度消灭按行宽的锯齿)
|
|
443
495
|
const inpRect = input.getBoundingClientRect();
|
|
444
496
|
const ics = getComputedStyle(input);
|
|
@@ -1221,7 +1273,8 @@ window.__ModuleLoader__.load({
|
|
|
1221
1273
|
input.classList.toggle(HOST, editable);
|
|
1222
1274
|
if (!editable) {
|
|
1223
1275
|
ov.innerHTML = "";
|
|
1224
|
-
|
|
1276
|
+
card.__dshClRenderSig = "";
|
|
1277
|
+
card.__dshClLineCache = null;
|
|
1225
1278
|
return;
|
|
1226
1279
|
}
|
|
1227
1280
|
const anchors = buildAnchors(input);
|
|
@@ -1241,6 +1294,34 @@ window.__ModuleLoader__.load({
|
|
|
1241
1294
|
}
|
|
1242
1295
|
}
|
|
1243
1296
|
|
|
1297
|
+
// 度量与主题(v0.2.17 上移到短路点之前:主题色是签名的组成部分)
|
|
1298
|
+
const scrollEl0 = card.querySelector(SCROLL_SEL);
|
|
1299
|
+
const color0 = syncMetrics(input, ov);
|
|
1300
|
+
if (scrollEl0) {
|
|
1301
|
+
scrollEl0.classList.toggle("dsh-cl-light", isLightColor(color0));
|
|
1302
|
+
document.body.classList.toggle("dsh-cl-light", isLightColor(color0));
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
// ===== 渲染签名短路(v0.2.17 性能优化的核心) =====
|
|
1306
|
+
// 视觉输出只依赖:内容(src) + 光标行(围栏高亮) + 几何(相对 overlay——渲染
|
|
1307
|
+
// 输出本身用相对坐标,滚动时字符与 overlay 视口坐标同步变化、差值不变,用
|
|
1308
|
+
// 相对量保证滚动零重渲染)+ 字体栈 + 主题色。全部相同 → 逐字符测量与
|
|
1309
|
+
// innerHTML 重建整体跳过(只更新随精确光标变的工具栏高亮)。idle 轮询 /
|
|
1310
|
+
// selectionchange / 页面 DOM 噪音路径的无效全量渲染由此消除(优化前 200 行
|
|
1311
|
+
// 文档空闲实测 16 次/秒全量 × ~60ms = 98% 主线程占用、打字 6fps)。
|
|
1312
|
+
const irx = input.getBoundingClientRect();
|
|
1313
|
+
const orx = ov.getBoundingClientRect();
|
|
1314
|
+
const renderSig = [src, cursorLine, Math.round(irx.left - orx.left), Math.round(irx.top - orx.top), Math.round(irx.width), card.__dshClFontSig || "", color0].join("\u0000");
|
|
1315
|
+
if (card.__dshClRenderSig === renderSig) {
|
|
1316
|
+
updateToolbarMarks(card, src, caret);
|
|
1317
|
+
card.__dshClCaret = caret;
|
|
1318
|
+
return;
|
|
1319
|
+
}
|
|
1320
|
+
card.__dshClRenderSig = renderSig;
|
|
1321
|
+
if (!card.__dshClLineCache) card.__dshClLineCache = { gen: "", lines: new Map() };
|
|
1322
|
+
// 行测量缓存的布局代:字体/容器几何/主题任一变化 → 行缓存整体作废
|
|
1323
|
+
const layoutGen = [card.__dshClFontSig || "", Math.round(irx.width), Math.round(irx.left - orx.left), color0].join("|");
|
|
1324
|
+
|
|
1244
1325
|
// 编辑器 class(打点在测量前——等宽打点影响布局,先定型再测量):
|
|
1245
1326
|
// - KEEP(chip 段恢复)段落级
|
|
1246
1327
|
// - 等宽「整框」级:文档含已闭合代码块 → input 整框切等宽、渲染全段同栈
|
|
@@ -1257,13 +1338,7 @@ window.__ModuleLoader__.load({
|
|
|
1257
1338
|
const hasCode = states.some((st) => st.inCode);
|
|
1258
1339
|
input.classList.toggle(MONO_ALL, hasCode);
|
|
1259
1340
|
|
|
1260
|
-
//
|
|
1261
|
-
const scrollEl = card.querySelector(SCROLL_SEL);
|
|
1262
|
-
const color = syncMetrics(input, ov);
|
|
1263
|
-
if (scrollEl) {
|
|
1264
|
-
scrollEl.classList.toggle("dsh-cl-light", isLightColor(color));
|
|
1265
|
-
document.body.classList.toggle("dsh-cl-light", isLightColor(color));
|
|
1266
|
-
}
|
|
1341
|
+
// 度量与主题段已于签名短路点之前执行(color 是签名组成部分)
|
|
1267
1342
|
|
|
1268
1343
|
// 字符锚定渲染:逐字符测量编辑器 rect,渲染字符绝对定位画在同一坐标。
|
|
1269
1344
|
// 三类兜底(都回退官方显示——移除透明化,保证任何情况都有文字可读;
|
|
@@ -1279,28 +1354,34 @@ window.__ModuleLoader__.load({
|
|
|
1279
1354
|
input.classList.remove(MONO_ALL);
|
|
1280
1355
|
input.querySelectorAll("." + KEEP).forEach((el) => el.classList.remove(KEEP));
|
|
1281
1356
|
ov.innerHTML = "";
|
|
1357
|
+
card.__dshClRenderSig = ""; // 兜底态不入签名(下一轮重判)
|
|
1282
1358
|
};
|
|
1283
1359
|
const hasContent = input.textContent.replace(//g, "").trim() !== "";
|
|
1284
1360
|
if (hasContent && src.replace(//g, "").trim() === "") {
|
|
1285
1361
|
fallbackToOfficial();
|
|
1286
1362
|
} else {
|
|
1287
1363
|
try {
|
|
1288
|
-
renderCharOverlay(ov, input, anchors, lines, states, anchors.refs || []);
|
|
1364
|
+
renderCharOverlay(ov, input, anchors, lines, states, anchors.refs || [], card.__dshClLineCache, layoutGen);
|
|
1289
1365
|
if (hasContent && ov.querySelectorAll(".dsh-cl-c").length === 0) fallbackToOfficial();
|
|
1290
1366
|
} catch (err) {
|
|
1291
1367
|
fallbackToOfficial();
|
|
1292
1368
|
}
|
|
1293
1369
|
}
|
|
1294
1370
|
|
|
1295
|
-
//
|
|
1371
|
+
// 工具栏高亮(随精确光标位置变化——独立于签名,同行移动也更新)
|
|
1372
|
+
updateToolbarMarks(card, src, caret);
|
|
1373
|
+
card.__dshClSrc = src;
|
|
1374
|
+
card.__dshClCaret = caret;
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
/** 工具栏格式键高亮(依赖精确 caret——与重渲染签名解耦,selectionchange 轻路径用)。 */
|
|
1378
|
+
function updateToolbarMarks(card, src, caret) {
|
|
1296
1379
|
if (card.__dshClBtns && caret != null) {
|
|
1297
1380
|
const marks = decideActiveMarks(src, caret);
|
|
1298
1381
|
for (const kind in card.__dshClBtns) {
|
|
1299
1382
|
card.__dshClBtns[kind].classList.toggle("dsh-cl-active", marks.indexOf(kind) !== -1);
|
|
1300
1383
|
}
|
|
1301
1384
|
}
|
|
1302
|
-
card.__dshClSrc = src;
|
|
1303
|
-
card.__dshClCaret = caret;
|
|
1304
1385
|
}
|
|
1305
1386
|
//#endregion
|
|
1306
1387
|
|
|
@@ -1847,12 +1928,23 @@ window.__ModuleLoader__.load({
|
|
|
1847
1928
|
};
|
|
1848
1929
|
};
|
|
1849
1930
|
|
|
1850
|
-
// MutationObserver 回调 rAF
|
|
1851
|
-
//
|
|
1852
|
-
//
|
|
1931
|
+
// MutationObserver 回调 rAF 合帧 + card 过滤(v0.2.17):每次击键 Lexical
|
|
1932
|
+
// 的 DOM commit 会触发多次 observer 回调(文本+结构),合并到下一帧只跑
|
|
1933
|
+
// 一次;**只认发生在输入卡内的变更**——观察的是整个 body,dsh 页面上
|
|
1934
|
+
// 其它组件(skin-center/cost-meter/React 渲染)的 DOM 活动会高频触发
|
|
1935
|
+
// 回调,不过滤的话页面噪音全部转化为本插件的全量渲染(优化前实测空闲
|
|
1936
|
+
// 16 次/秒)。card 外的变化由 500ms 兜底轮询覆盖(card 重建等场景)。
|
|
1853
1937
|
let obsRaf = 0;
|
|
1854
|
-
const observer = new MutationObserver(() => {
|
|
1938
|
+
const observer = new MutationObserver((muts) => {
|
|
1855
1939
|
if (obsRaf) return;
|
|
1940
|
+
const cardNow = findCard();
|
|
1941
|
+
if (cardNow) {
|
|
1942
|
+
let hit = false;
|
|
1943
|
+
for (let i = 0; i < muts.length; i++) {
|
|
1944
|
+
if (cardNow.contains(muts[i].target)) { hit = true; break; }
|
|
1945
|
+
}
|
|
1946
|
+
if (!hit) return;
|
|
1947
|
+
}
|
|
1856
1948
|
obsRaf = requestAnimationFrame(() => { obsRaf = 0; run(); });
|
|
1857
1949
|
});
|
|
1858
1950
|
observer.observe(document.body, { childList: true, subtree: true, characterData: true });
|
|
@@ -1865,6 +1957,11 @@ window.__ModuleLoader__.load({
|
|
|
1865
1957
|
};
|
|
1866
1958
|
window.addEventListener("resize", onResize);
|
|
1867
1959
|
|
|
1960
|
+
// selectionchange(v0.2.17 加 rAF 合帧):拖选/光标移动时该事件以指针
|
|
1961
|
+
// 级频率触发,直接同步 render 会造成每帧多次全量渲染(优化前拖选 20 次
|
|
1962
|
+
// 扩选实测 75 次渲染)——合帧 + render 内的签名短路(光标同行移动不重
|
|
1963
|
+
// 渲染,仅更新工具栏高亮)。
|
|
1964
|
+
let selRaf = 0;
|
|
1868
1965
|
const onSelChange = () => {
|
|
1869
1966
|
const card = findCard();
|
|
1870
1967
|
if (!card) return;
|
|
@@ -1873,8 +1970,9 @@ window.__ModuleLoader__.load({
|
|
|
1873
1970
|
if (card.__dshClFloat) card.__dshClFloat.classList.remove("dsh-cl-float-on");
|
|
1874
1971
|
return;
|
|
1875
1972
|
}
|
|
1876
|
-
render(card);
|
|
1877
1973
|
if (card.__dshClFloat) updateFloat(card, card.__dshClFloat);
|
|
1974
|
+
if (selRaf) return;
|
|
1975
|
+
selRaf = requestAnimationFrame(() => { selRaf = 0; const c = findCard(); if (c) render(c); });
|
|
1878
1976
|
};
|
|
1879
1977
|
document.addEventListener("selectionchange", onSelChange);
|
|
1880
1978
|
|
|
@@ -1892,6 +1990,7 @@ window.__ModuleLoader__.load({
|
|
|
1892
1990
|
return () => {
|
|
1893
1991
|
delete window.__dshClDebug;
|
|
1894
1992
|
clearInterval(timer);
|
|
1993
|
+
if (selRaf) cancelAnimationFrame(selRaf);
|
|
1895
1994
|
observer.disconnect();
|
|
1896
1995
|
window.removeEventListener("resize", onResize);
|
|
1897
1996
|
document.removeEventListener("selectionchange", onSelChange);
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-composer-live",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.18",
|
|
4
4
|
"description": "DSH Web 0.1.5+ 输入框增强(Lexical contenteditable 架构版):markdown 实时渲染 + 代码块语法高亮/段落级等宽 + 格式工具栏(常驻顶条 + 选区浮动条)+ 70vh 展开 + 大段粘贴包代码块 + Esc 分发。纯浏览器端插件,零依赖,不改官方源码。仿 Open WebUI 输入体验。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -44,7 +44,11 @@
|
|
|
44
44
|
"markdown",
|
|
45
45
|
"composer",
|
|
46
46
|
"input",
|
|
47
|
+
"live-preview",
|
|
47
48
|
"preview",
|
|
49
|
+
"toolbar",
|
|
50
|
+
"format",
|
|
51
|
+
"paste",
|
|
48
52
|
"lexical",
|
|
49
53
|
"syntax-highlighting",
|
|
50
54
|
"open-webui"
|