@nimoxie/dsh-ui-tweaks 0.2.7 → 0.2.8

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/DEVELOPMENT.md CHANGED
@@ -247,6 +247,7 @@
247
247
  - [x] 0.2.5(2026-11-19):补位 diff 改为**逐段成 hunk**(同一文件多段改动不再串成一次替换,修真机「删二维码代码 / 加 import 配成一对」);锚点改成「连续相同的最长非空区间 ≥3 行」,空行不再把落点带到第 1 行;任一段没锚定就在标题标「(片段内行号)」。10 项离线单测全过(含空行首行、非空不足 3 行、多段各自命中、部分命中)。
248
248
  - [x] 0.2.6(2026-11-25):更新面板标签改等宽排版 —— 文案统一成 **4 个汉字**(`比对中 …`→`正在比对`、`更新中 …`→`正在更新`、`DSH 不符`→`版本不符`、`Git 直装`→`仓库直装`、`未比对`→`尚未比对`),`.tag` 加 `display:inline-flex` + `box-sizing:border-box` + `min-width:calc(4em + 14px)` + `justify-content:center` + `font-variant-numeric:tabular-nums` 兜底;汉字是方块字,等字数即等宽,**不靠补空格**(比例字体里空格本身也不是半格)。另:兼容门禁悬停提示不再把 `≥` 和 `engines.dsh` 自带的 `>=` 叠成「≥ >=0.2.3-alpha.2」(`dshRequirementText()` 先剥比较符)。
249
249
  - [x] 0.2.7(2026-11-25):收尾鲁棒性 —— 补位 diff 只在能还原绝对路径时才读文件(相对路径会让 host 按自己的 cwd 读到同名错文件,静默给出错行号);坐标索引加 300 条上限、并在 `connection/reset` 时清空;标签等宽加开发期自检(非 4 个汉字就 `console.warn`);`preflight-source` 加 10 分钟 packument 缓存(tarball 可用性仍每次实测),失败码新增 `registry-invalid`。 另修「合成坐标串轮」:无公告回合改用 `SYNTH_SEQ_BASE(9e8) + 轮号` 作 seq(官方地址正则只认非负整数,负数打不开;旧实现统一用 0,同一会话多个无公告回合会互相覆盖)。
250
+ - [x] 0.2.8(2026-11-25):补位 diff 的锚点加**自适应退化** —— 3 行连续匹配失败时依次尝试「2 行且首行 ≥8 字符」「1 行且 ≥24 字符且全文件唯一」,片段被后续回合改动打散后仍能定位,仍不猜;近似卡片的 `header` 背景改用 `color-mix(currentColor 6%)`(原来是 `--dsw-static-neutral-50`,在暗色主题下是白色,真机表现为卡片头部发白);官方 CSS 类名提取失败不再永久缓存(2 秒后重试),并在 `data-plugin-css` 标签找不到时按 `--changes-fill` 特征回退搜索样式表。
250
251
  - 同版修对话区滚动条的偶发拖不动:宿主 `pointer-events:none`(只有 track 收事件,隐层不再吃掉右缘点击)、document 捕获段补 pointerup/pointercancel 兜底(捕获丢失或宿主重建时收尾)、调宽条不可见时整块隐藏而不是摆到 `left:-14`、thumb 位置改按可滚动行程归一化(28px 下限不再导致拖到底差一截)、拖动态补刷新 `trRect`、`ResizeObserver` 在卸载时 `disconnect`。
251
252
  - [ ] `shell` 模式重启不留日志(`ui-tweaks-restart.log` 只有 `relaunch` 分支写),要硬证据就在 `performRestart` 退出前追加一行;「点按钮 → 宿主退出」目前只有 `crash-*-host.log` 作间接证据。
252
253
  - [ ] 窗口记忆「零闪现」只能靠常驻 watcher 进程(代价:常驻 + 卸载残留),**待与用户确认**。
package/lib/client.js CHANGED
@@ -19,7 +19,7 @@ window.__ModuleLoader__.load({
19
19
  const module = { exports: {} };
20
20
  const exports = module.exports;
21
21
 
22
- const BUILD = "0.2.7";
22
+ const BUILD = "0.2.8";
23
23
 
24
24
  /* 每个模块的注册各套一层 guard:失败只记 warn(座位/模块失败模式是「静默消失」,
25
25
  必须主动吭声;但不能让一个模块的异常打断同文件里其它模块的 apply)。 */
@@ -3259,12 +3259,25 @@ window.__ModuleLoader__.load({
3259
3259
  ② 该回合根本没有 workspace/changes 公告。这两处才由本卡补位,外观尽量贴官方:
3260
3260
  类名不硬编码(hash 每版会变),运行时从官方注入的 CSS module <style> 里读出前缀。 */
3261
3261
  var officialClassCache = null;
3262
+ var officialClassFailedAt = 0;
3262
3263
  function officialChangesClasses() {
3263
- if (officialClassCache !== null) { return officialClassCache; }
3264
+ if (officialClassCache) { return officialClassCache; }
3265
+ /* 失败不永久缓存:dev 工具关着时 ChangedFiles 的样式可能晚到(甚至被懒加载),
3266
+ 之前失败即定型,后续所有卡片都退回近似样式。2 秒后允许重试。 */
3267
+ if (officialClassCache === false && Date.now() - officialClassFailedAt < 2000) { return false; }
3264
3268
  officialClassCache = false;
3269
+ officialClassFailedAt = Date.now();
3265
3270
  try {
3266
3271
  var tag = document.querySelector("style[data-plugin-css$=\"ChangedFiles.module.css\"]");
3267
3272
  var text = tag && tag.textContent ? String(tag.textContent) : "";
3273
+ if (!text) {
3274
+ /* 样式标签 id 以后可能改名:退一步在所有插件样式表里找带 --changes-fill 的那份 */
3275
+ var all = document.querySelectorAll("style[data-plugin-css]");
3276
+ for (var ai = 0; ai < all.length; ai++) {
3277
+ var txt = all[ai].textContent ? String(all[ai].textContent) : "";
3278
+ if (txt.indexOf("--changes-fill") >= 0 && txt.indexOf("_card{") >= 0) { text = txt; break; }
3279
+ }
3280
+ }
3268
3281
  var hit = /\.([A-Za-z0-9_-]{4,12})_card\b/.exec(text);
3269
3282
  if (!hit) { return officialClassCache; }
3270
3283
  var k = hit[1];
@@ -3282,7 +3295,7 @@ window.__ModuleLoader__.load({
3282
3295
  /* 读不到官方样式表时的近似样式(只影响观感,不影响结构/交互)。 */
3283
3296
  var CHANGES_FALLBACK_STYLES = {
3284
3297
  card: { marginTop: "4px", border: "0.5px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3))", borderRadius: "var(--dsw-radius-lg, 8px)", background: "var(--dsw-alias-bg-layer-1, transparent)", display: "flex", flexDirection: "column", overflow: "hidden" },
3285
- header: { display: "flex", alignItems: "center", gap: "10px", width: "100%", boxSizing: "border-box", height: "60px", padding: "8px 10px", background: "var(--dsw-static-neutral-50, rgba(128,128,128,.08))", color: "inherit", textAlign: "left", border: "0", cursor: "pointer", font: "inherit" },
3298
+ header: { display: "flex", alignItems: "center", gap: "10px", width: "100%", boxSizing: "border-box", height: "60px", padding: "8px 10px", background: "rgba(128,128,128,.08)", background: "color-mix(in srgb, currentColor 6%, transparent)", color: "inherit", textAlign: "left", border: "0", cursor: "pointer", font: "inherit" },
3286
3299
  tile: { display: "grid", placeItems: "center", width: "40px", height: "40px", flex: "none", borderRadius: "10px", border: "0.5px solid var(--dsw-alias-border-l1, rgba(128,128,128,.25))" },
3287
3300
  titles: { display: "flex", flexDirection: "column", flex: "1", minWidth: "0" },
3288
3301
  title: { fontSize: "13px", fontWeight: 500, lineHeight: "20px", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },
@@ -3779,24 +3792,42 @@ window.__ModuleLoader__.load({
3779
3792
  var needle = fragmentLines(fragment);
3780
3793
  if (needle.length === 0 || fileLines.length === 0) { return null; }
3781
3794
  if (fileLines.length > ANCHOR_MAX_FILE_LINES) { return null; }
3782
- var best = null, j, i;
3783
- for (j = 0; j < needle.length; j++) {
3784
- if (String(needle[j]).trim() === "") { continue; }
3785
- for (i = 0; i < fileLines.length; i++) {
3786
- if (fileLines[i] !== needle[j]) { continue; }
3787
- var len = 0, nonBlank = 0;
3788
- while (i + len < fileLines.length && j + len < needle.length && fileLines[i + len] === needle[j + len]) {
3789
- if (String(needle[j + len]).trim() !== "") { nonBlank += 1; }
3790
- len += 1;
3791
- }
3792
- if (nonBlank >= ANCHOR_MIN_LINES &&
3793
- (!best || nonBlank > best.nonBlank || (nonBlank === best.nonBlank && len > best.len))) {
3794
- best = { nonBlank: nonBlank, len: len, j: j, i: i };
3795
+ function bestRun(minLines) {
3796
+ var best = null, j, i;
3797
+ for (j = 0; j < needle.length; j++) {
3798
+ if (String(needle[j]).trim() === "") { continue; }
3799
+ for (i = 0; i < fileLines.length; i++) {
3800
+ if (fileLines[i] !== needle[j]) { continue; }
3801
+ var len = 0, nonBlank = 0;
3802
+ while (i + len < fileLines.length && j + len < needle.length && fileLines[i + len] === needle[j + len]) {
3803
+ if (String(needle[j + len]).trim() !== "") { nonBlank += 1; }
3804
+ len += 1;
3805
+ }
3806
+ if (nonBlank >= minLines &&
3807
+ (!best || nonBlank > best.nonBlank || (nonBlank === best.nonBlank && len > best.len))) {
3808
+ best = { nonBlank: nonBlank, len: len, j: j, i: i };
3809
+ }
3795
3810
  }
3796
3811
  }
3797
- }
3798
- if (!best) { return null; }
3799
- return best.i - best.j + 1; /* 片段首行对应的文件行号(1 基) */
3812
+ return best;
3813
+ }
3814
+ function occurrencesOf(line) {
3815
+ var n = 0;
3816
+ for (var k = 0; k < fileLines.length; k++) { if (fileLines[k] === line) { n += 1; } }
3817
+ return n;
3818
+ }
3819
+ /* 首选 ≥3 行连续匹配;片段被后续改动打散时退化:
3820
+ 2 行匹配且首行够长(≥8 字符),或 1 行「够长且全文件唯一」(≥24 字符)。
3821
+ 都是精确文本匹配,宁可不定位也不猜。 */
3822
+ var hit = bestRun(ANCHOR_MIN_LINES);
3823
+ if (hit) { return hit.i - hit.j + 1; }
3824
+ hit = bestRun(2);
3825
+ if (hit && String(needle[hit.j]).trim().length >= 8) { return hit.i - hit.j + 1; }
3826
+ hit = bestRun(1);
3827
+ if (hit && String(needle[hit.j]).trim().length >= 24 && occurrencesOf(needle[hit.j]) === 1) {
3828
+ return hit.i - hit.j + 1;
3829
+ }
3830
+ return null; /* 片段首行对应的文件行号(1 基);定位不了返回 null */
3800
3831
  }
3801
3832
  /* 逐个 hunk 定位:拿 hunk 的「新侧」(上下文 + 新增行)在文件里找连续落点,
3802
3833
  命中后 hunk 的起点就是文件行号;旧起点按「同段内此前的行差 + 本文件前面各段的行差」反推。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nimoxie/dsh-ui-tweaks",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "dsh Web UI 微调合集:回合尾「本回合改动」卡在会话释放后仍按官方样式显示(用会话日志重建数据喂给官方卡)、宽表格越界修复、对话区左侧自绘滚动条、动画修复、插件更新检查面板、桌面端窗口记忆(不含 dsh 本体)",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",