@andy.ian/dsh-homing 2.3.5 → 2.3.7

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.
@@ -17,6 +17,15 @@ export const MOBILE_CSS = `html { -webkit-text-size-adjust: 100%; }
17
17
  @media (max-width: 760px) {
18
18
  [class*="_frame"] { min-width: 0; }
19
19
  }
20
+ /* 浮层(额度弹窗、菜单、对话框)先按视口限宽/限高:
21
+ 宽度超过屏幕的弹窗即使能平移也一定有内容看不见,限宽后第一帧就在屏幕内,
22
+ 再配合 JS 的位置修正,避免「先跑到屏幕外再跳回来」。 */
23
+ [role="dialog"], [role="menu"], [role="listbox"], [data-radix-popper-content-wrapper] {
24
+ max-width: calc(100vw - 16px) !important;
25
+ }
26
+ [role="dialog"] {
27
+ max-height: calc(100vh - 32px) !important;
28
+ }
20
29
  `;
21
30
 
22
31
  /**
@@ -362,6 +371,17 @@ export const MOBILE_JS = String.raw`(() => {
362
371
  return link
363
372
  }
364
373
 
374
+ // 我们是在 MutationObserver 回调里改 DOM 的:如果每次都「删掉再加一遍」,
375
+ // 自己的改动会再次触发观察器 → 80ms 一次无限循环,菜单项肉眼可见地一直闪
376
+ //(2026-11-22 手机录屏实测)。
377
+ // 用标记 + 数量校验做幂等:已增强过就原地跳过,保证不再产生新 mutation。
378
+ const MENU_MARKER = 'data-dsh-homing-menu'
379
+ const menuIsEnhanced = (menu) =>
380
+ menu.getAttribute(MENU_MARKER) === '1'
381
+ && menu.querySelectorAll('[data-dsh-homing-download]').length === 1
382
+ && menu.querySelectorAll('[data-dsh-homing-wall]').length === 1
383
+ && menu.querySelectorAll('[data-dsh-homing-restart]').length === 1
384
+
365
385
  const enhanceMenus = () => {
366
386
  const done = new Set()
367
387
  for (const item of document.querySelectorAll('[role="menuitem"]')) {
@@ -369,6 +389,7 @@ export const MOBILE_JS = String.raw`(() => {
369
389
  if (menu === null || done.has(menu)) continue
370
390
  if (!MENU_HINT.test(menu.textContent || '')) continue
371
391
  done.add(menu)
392
+ if (menuIsEnhanced(menu)) continue
372
393
 
373
394
  for (const old of menu.querySelectorAll('[data-dsh-homing-download],[data-dsh-homing-restart],[data-dsh-homing-wall]')) old.remove()
374
395
 
@@ -386,6 +407,8 @@ export const MOBILE_JS = String.raw`(() => {
386
407
  menu.appendChild(download)
387
408
  menu.appendChild(wall)
388
409
  menu.appendChild(restart)
410
+ // 标记必须在本轮 mutation 被观察器处理前写好(同一个任务内完成),下一轮直接跳过
411
+ menu.setAttribute(MENU_MARKER, '1')
389
412
  }
390
413
  }
391
414
 
@@ -397,11 +420,8 @@ export const MOBILE_JS = String.raw`(() => {
397
420
  }
398
421
  }
399
422
 
400
- const menuObserver = new MutationObserver(() => {
401
- if (menuTimer) return
402
- menuTimer = setTimeout(() => { menuTimer = null; enhanceMenus(); pruneMenuItems(); scheduleClamp() }, 80)
403
- })
404
- menuObserver.observe(document.body, { childList: true, subtree: true })
423
+ // 菜单/浮层的 MutationObserver 在「浮层不越界」定义之后统一注册(见下方),
424
+ // 因为新的浮层出现时要在同一个微任务里立刻修正位置。
405
425
 
406
426
  /* ---------- 浮层不越出屏幕 ----------
407
427
  * 额度面板、菜单、对话框大多按「相对触发按钮」定位,窄屏上会有一部分落到
@@ -472,6 +492,40 @@ export const MOBILE_JS = String.raw`(() => {
472
492
  // 调试/测试入口:也可手动触发一次
473
493
  if (window.__dshHomingClampPopovers === undefined) window.__dshHomingClampPopovers = clampPopovers
474
494
 
495
+ /* ---------- DOM 观察器 ----------
496
+ * 两件事:
497
+ * 1) 新浮层出现时,在 MutationObserver 微任务里「同步」修正位置。
498
+ * MutationObserver 回调发生在浏览器绘制之前,所以用户看到的第一帧就是
499
+ * 修正后的位置,不会出现「先在屏幕外冒出来、120ms 后再跳回来」
500
+ * (2026-11-22 录屏里的 OpenCode 额度弹窗就是这个现象)。
501
+ * 2) 会话菜单增强 + prunes(80ms 防抖,避免 DSH 流式输出时频繁扫描)。
502
+ */
503
+ const OBSERVED_POPOVER_SELECTOR = 'body > div, [role="dialog"], [role="menu"], [role="listbox"], [data-radix-popper-content-wrapper]'
504
+ const isPopoverNode = (node) => {
505
+ if (node === null || node === undefined || typeof node.matches !== 'function') return false
506
+ try {
507
+ if (node.matches(OBSERVED_POPOVER_SELECTOR)) return true
508
+ return typeof node.querySelector === 'function' && node.querySelector(OBSERVED_POPOVER_SELECTOR) !== null
509
+ } catch (error) {
510
+ return false
511
+ }
512
+ }
513
+
514
+ const menuObserver = new MutationObserver((records) => {
515
+ let popoverAdded = false
516
+ for (const record of records) {
517
+ const added = record.addedNodes || []
518
+ for (const node of added) {
519
+ if (isPopoverNode(node)) { popoverAdded = true; break }
520
+ }
521
+ if (popoverAdded) break
522
+ }
523
+ if (popoverAdded) clampPopovers()
524
+ if (menuTimer) return
525
+ menuTimer = setTimeout(() => { menuTimer = null; enhanceMenus(); pruneMenuItems(); scheduleClamp() }, 80)
526
+ })
527
+ menuObserver.observe(document.body, { childList: true, subtree: true })
528
+
475
529
  /* ---------- ALIVE_BEACON ----------
476
530
  * 告诉插件"用户正在操作":重启脚本据此判断能否安全重启。
477
531
  * 手机上打字/滑动手势不会修改会话文件,只有这个信标能反映"人在用"。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andy.ian/dsh-homing",
3
- "version": "2.3.5",
3
+ "version": "2.3.7",
4
4
  "type": "module",
5
5
  "description": "把本机 DSH 通过 SSH 反向隧道安全开放到手机浏览器:TLS 端到端(服务器只透传)、账号 + TOTP、局域网与公网双入口,随 DSH 启动。",
6
6
  "keywords": [