dsh-scroll-piano 0.3.3 → 0.3.4

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.
Files changed (3) hide show
  1. package/README.md +3 -3
  2. package/lib/client.js +37 -19
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -7,8 +7,8 @@
7
7
  - 聊天区右边缘一条细彩色竖条(开启时淡淡发光),鼠标进入该区间即触发。
8
8
  - 鼠标纵向移动 = 连续刮奏;竖条上有个白点跟随鼠标位置。
9
9
  - 竖条上有**「我的消息」小地图刻度**:你每发一条消息,对应位置一根蓝色小横杠——**按「在整段对话里的位置」定位,与滚动无关**,所以不管你滚到对话多深,自己的消息始终标在那、点得到。
10
- - **气泡只在鼠标贴近某条刻度(±16px)时出现**,内容就是那条消息的正文(最多 3 行)+「点击跳转」提示;**其余位置整个不显示**(不显示音名、不显示 MIDI 数字)。
11
- - **点击气泡** → 平滑滚动,把那条消息滚到视口中央。
10
+ - **气泡只在鼠标贴近某条刻度(±16px)时出现**,内容就是那条消息的正文(最多 3 行);**其余位置整个不显示**(不显示音名、不显示 MIDI 数字)。
11
+ - **点蓝色小横杠 → 跳到那条消息**(平滑滚动、滚到视口中央)。蓝条命中区放大到 18×12px(可视化仍是 7×2 细条,悬停时加宽变亮),比原来 2px 高好点得多;**点气泡也能跳**(两者同一个 `jumpTo`)。
12
12
  - 左下角一枚 `🎵 滚动钢琴 ON/OFF` 胶囊:点开关切换、右侧滑块调音量(设置存 `localStorage`)。
13
13
  - 默认音域 C3–C6(3 个八度),只按半音触发(同音不重复触发)。
14
14
 
@@ -25,7 +25,7 @@
25
25
  | `14:assistant-stepN:M` | AI 消息 → 跳过 |
26
26
  | `12:turn-processN` / `["process",…]` / `9:turn-tailN` | 过程 / 工具调用 / 轮次尾 → 跳过 |
27
27
 
28
- 刻度 y = **消息在滚动内容里的偏移 ÷ 内容总长 × 视口高**(`r.top − 视口top + scrollTop` 得到内容坐标,再归一化),**与 scrollTop 无关**——滚多远都不变,消息不会"滚出屏幕"而看不见。鼠标贴近某条刻度(±16px)就取它 `innerText` 的正文(去掉末尾 `HH:MM` 时间戳)显示,点击时对该元素 `scrollIntoView({ block: "center" })`。**只认这些 `data-*` 属性**——容器类名(`icaHSq_flowItem`、`ST7X_W_scrollBody`)都带 hash,不碰。
28
+ 刻度 y = **消息在滚动内容里的偏移 ÷ 内容总长 × 视口高**(`r.top − 视口top + scrollTop` 得到内容坐标,再归一化),**与 scrollTop 无关**——滚多远都不变,消息不会"滚出屏幕"而看不见。鼠标贴近某条刻度(±16px)就取它 `innerText` 的正文(去掉末尾 `HH:MM` 时间戳)显示;**点那根蓝条**(容器 `click` 事件委托到 `.dshscp_tick`,读 `data-i` 找回消息元素)就 `scrollIntoView({ block: "center" })`。**只认这些 `data-*` 属性**——容器类名(`icaHSq_flowItem`、`ST7X_W_scrollBody`)都带 hash,不碰。
29
29
 
30
30
  ## 触发区:聊天区右边缘,不是窗口右边缘
31
31
 
package/lib/client.js CHANGED
@@ -30,8 +30,10 @@ window.__ModuleLoader__.load({
30
30
  ".dshscp_vol{width:76px;accent-color:var(--dsw-alias-state-business-primary,#5b8def)}",
31
31
  ".dshscp_strip{position:fixed;top:0;right:0;width:3px;height:100%;z-index:2147482000;pointer-events:none;background:linear-gradient(180deg,rgba(91,141,239,.85),rgba(160,120,240,.85));opacity:0;transition:opacity .15s ease}",
32
32
  ".dshscp_stripOn{opacity:.55}",
33
- ".dshscp_ticks{position:fixed;top:0;right:0;width:9px;height:100%;z-index:2147482000;pointer-events:none}",
34
- ".dshscp_tick{position:absolute;right:0;width:7px;height:2px;border-radius:1px;background:rgba(91,141,239,.95);box-shadow:0 0 4px rgba(91,141,239,.7)}",
33
+ ".dshscp_ticks{position:fixed;top:0;right:0;width:20px;height:100%;z-index:2147482000;pointer-events:none}",
34
+ ".dshscp_tick{position:absolute;right:0;width:18px;height:12px;margin-top:-6px;pointer-events:auto;cursor:pointer}",
35
+ ".dshscp_tick::after{content:\"\";position:absolute;right:0;top:50%;transform:translateY(-50%);width:7px;height:2px;border-radius:1px;background:rgba(91,141,239,.95);box-shadow:0 0 4px rgba(91,141,239,.7);transition:all .12s ease}",
36
+ ".dshscp_tick:hover::after{width:16px;box-shadow:0 0 7px rgba(91,141,239,1)}",
35
37
  ".dshscp_marker{position:fixed;right:0;width:7px;height:7px;border-radius:50%;z-index:2147482001;pointer-events:none;background:#fff;box-shadow:0 0 8px rgba(160,120,240,.95);opacity:0;transition:opacity .1s ease}",
36
38
  ".dshscp_markerOn{opacity:1}",
37
39
  ".dshscp_prev{position:fixed;right:18px;z-index:2147482002;pointer-events:none;max-width:min(320px,42vw);padding:7px 10px;border-radius:9px;background:rgba(20,24,32,.95);color:#e6e8ee;box-shadow:0 6px 22px rgba(0,0,0,.45);opacity:0;transition:opacity .1s ease}",
@@ -39,7 +41,6 @@ window.__ModuleLoader__.load({
39
41
  ".dshscp_prevTop{display:flex;align-items:center;gap:8px;margin-bottom:4px}",
40
42
  ".dshscp_prevRole{flex:none;padding:1px 5px;border-radius:4px;background:rgba(91,141,239,.3);color:#bcd4ff;font-size:10px;line-height:14px}",
41
43
  ".dshscp_prevRoleAI{background:rgba(160,120,240,.28);color:#d6c4ff}",
42
- ".dshscp_prevHint{margin-left:auto;flex:none;color:#9aa2b1;font-size:10px;line-height:14px}",
43
44
  ".dshscp_prevText{font-size:12px;line-height:17px;color:#e6e8ee;overflow:hidden;display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;word-break:break-word}"
44
45
  ].join("");
45
46
  const tagId = "dsh-scroll-piano/scroll-piano.css";
@@ -251,6 +252,7 @@ window.__ModuleLoader__.load({
251
252
  const textRef = useRef(null);
252
253
  const ticksRef = useRef(null);
253
254
  const ticksDataRef = useRef([]); // [{y, el}] — 小地图刻度数据(showPreview 靠它找消息)
255
+ const jumpToRef = useRef(() => {});
254
256
  const activeMsgRef = useRef(null);
255
257
 
256
258
  const setOn = useCallback((on) => {
@@ -275,6 +277,26 @@ window.__ModuleLoader__.load({
275
277
  let mo = null;
276
278
  let moTimer = 0;
277
279
  let tickTimer = 0;
280
+ /** 平滑滚动到某条消息(点蓝条 / 点气泡都走这里)。 */
281
+ const jumpTo = (el) => {
282
+ if (!el) return;
283
+ try { el.scrollIntoView({ behavior: "smooth", block: "center" }); }
284
+ catch { try { el.scrollIntoView(); } catch {} }
285
+ activeMsgRef.current = null;
286
+ if (prevRef.current) {
287
+ prevRef.current.classList.remove("dshscp_prevOn");
288
+ prevRef.current.style.pointerEvents = "none";
289
+ }
290
+ if (markerRef.current) markerRef.current.classList.remove("dshscp_markerOn");
291
+ };
292
+ jumpToRef.current = jumpTo;
293
+ /** 点竖条上的蓝色小横杠 → 跳到那条消息(事件委托,刻度是动态增删的)。 */
294
+ const onTickClick = (e) => {
295
+ const t = e.target;
296
+ if (!t || !t.classList || !t.classList.contains("dshscp_tick")) return;
297
+ const idx = parseInt(t.getAttribute("data-i"), 10);
298
+ if (idx >= 0) jumpTo(ticksDataRef.current[idx] && ticksDataRef.current[idx].el);
299
+ };
278
300
  /** 竖条上给「我的消息」打小地图刻度:不管滚到哪,自己的消息始终标在那。 */
279
301
  const refreshTicks = () => {
280
302
  const box = ticksRef.current;
@@ -288,7 +310,10 @@ window.__ModuleLoader__.load({
288
310
  i.className = "dshscp_tick";
289
311
  box.appendChild(i);
290
312
  }
291
- for (let i = 0; i < data.length; i++) box.children[i].style.top = data[i].y + "px";
313
+ for (let i = 0; i < data.length; i++) {
314
+ box.children[i].style.top = data[i].y + "px";
315
+ box.children[i].setAttribute("data-i", String(i));
316
+ }
292
317
  };
293
318
  // 对话增长 / 面板开合会改内容总长 → 节流到 150ms 重算(刻度与 scrollTop 无关,滚动不用重算)
294
319
  const scheduleTicks = () => {
@@ -408,12 +433,14 @@ window.__ModuleLoader__.load({
408
433
  document.addEventListener("pointermove", onMove, { passive: true });
409
434
  document.addEventListener("pointerleave", onLeave);
410
435
  // 不需要监听 scroll:刻度是按「内容偏移/内容总长」算的,与 scrollTop 无关
436
+ if (ticksRef.current) ticksRef.current.addEventListener("click", onTickClick);
411
437
  window.addEventListener("blur", onLeave);
412
438
  window.addEventListener("resize", placeAtChatEdge);
413
439
  placeAtChatEdge();
414
440
  return () => {
415
441
  document.removeEventListener("pointermove", onMove);
416
442
  document.removeEventListener("pointerleave", onLeave);
443
+ if (ticksRef.current) ticksRef.current.removeEventListener("click", onTickClick);
417
444
  window.removeEventListener("blur", onLeave);
418
445
  window.removeEventListener("resize", placeAtChatEdge);
419
446
  if (ro) ro.disconnect();
@@ -423,7 +450,10 @@ window.__ModuleLoader__.load({
423
450
  };
424
451
  }, []);
425
452
 
426
- // 竖条 + 「我的消息」刻度 + 位置圆点 + 预览气泡(气泡可点,点了跳过去)
453
+ /** 点气泡也跳(文字提示已去掉,主入口是点蓝条)。 */
454
+ const onBubbleClick = () => jumpToRef.current(activeMsgRef.current && activeMsgRef.current.el);
455
+
456
+ // 竖条 + 「我的消息」刻度(**点蓝色小横杠跳过去**)+ 位置圆点 + 预览气泡
427
457
  return h(React.Fragment, null,
428
458
  h("div", { ref: stripRef, className: "dshscp_strip" + (settings.on ? " dshscp_stripOn" : "") }),
429
459
  h("div", { ref: ticksRef, className: "dshscp_ticks" }),
@@ -431,22 +461,10 @@ window.__ModuleLoader__.load({
431
461
  h("div", {
432
462
  ref: prevRef,
433
463
  className: "dshscp_prev",
434
- onClick: () => {
435
- const m = activeMsgRef.current;
436
- if (!m || !m.el) return;
437
- try { m.el.scrollIntoView({ behavior: "smooth", block: "center" }); }
438
- catch { try { m.el.scrollIntoView(); } catch {} }
439
- activeMsgRef.current = null;
440
- if (prevRef.current) {
441
- prevRef.current.classList.remove("dshscp_prevOn");
442
- prevRef.current.style.pointerEvents = "none";
443
- }
444
- if (markerRef.current) markerRef.current.classList.remove("dshscp_markerOn");
445
- }
464
+ onClick: onBubbleClick
446
465
  },
447
466
  h("div", { className: "dshscp_prevTop" },
448
- h("span", { ref: roleRef, className: "dshscp_prevRole" }, "你"),
449
- h("span", { className: "dshscp_prevHint" }, "点击跳转")
467
+ h("span", { ref: roleRef, className: "dshscp_prevRole" }, "你")
450
468
  ),
451
469
  h("div", { ref: textRef, className: "dshscp_prevText" })
452
470
  ),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-scroll-piano",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "滚动钢琴:鼠标滑过 DSH 右侧边缘的滚动条竖条时,按纵向位置发出钢琴音(越高音越高,特雷门琴式)。",
5
5
  "type": "module",
6
6
  "license": "MIT",