dsh-lan-guard 0.6.0 → 0.7.1

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/lib/index.js CHANGED
@@ -2077,6 +2077,33 @@ function buildUpstreamResponseHeaders(headers, relayCookieNames = []) {
2077
2077
  * @param statusMessage - upstream status message.
2078
2078
  * @returns the raw head bytes to write to the visitor's socket.
2079
2079
  */
2080
+ /**
2081
+ * Mark an HTML document uncacheable when the upstream offers no policy of its own.
2082
+ *
2083
+ * DSH's index ships without `cache-control`, `etag` or `last-modified`, so a
2084
+ * browser is free to reuse the document it rendered before a `dsh web` restart.
2085
+ * That stale document references `?rev=<hash>` bundle URLs, and DSH answers a
2086
+ * stale rev with 404 — the app then boots into "Failed to load plugins" (a blank
2087
+ * white page on mobile Safari) until the site data is cleared. Measured
2088
+ * 2026-10-07: rewriting every `rev` in the served index to a dead value produced
2089
+ * three 404s on `/plugins/` and an app that never mounted.
2090
+ *
2091
+ * Only applied when the response is HTML and the upstream set no cache policy,
2092
+ * so an explicit upstream directive is never overridden.
2093
+ *
2094
+ * @param headers - the outgoing response headers.
2095
+ * @returns the same headers, or a copy carrying `cache-control: no-store`.
2096
+ */
2097
+ function withDocumentNoStore(headers) {
2098
+ if (Object.keys(headers).some((name) => name.toLowerCase() === "cache-control")) return headers;
2099
+ const raw = Object.entries(headers).find(([name]) => name.toLowerCase() === "content-type")?.[1];
2100
+ const text = Array.isArray(raw) ? raw.join(",") : raw;
2101
+ if (typeof text !== "string" || !text.toLowerCase().includes("text/html")) return headers;
2102
+ return {
2103
+ ...headers,
2104
+ "cache-control": "no-store"
2105
+ };
2106
+ }
2080
2107
  function buildUpgradeResponseHead(headers, statusCode, statusMessage) {
2081
2108
  const lines = [`HTTP/1.1 ${statusCode} ${statusMessage}`];
2082
2109
  const allowed = new Set(UPGRADE_RESPONSE_HEADERS);
@@ -2586,7 +2613,7 @@ async function startProxy(options) {
2586
2613
  forwardHttp(req, res, target, false);
2587
2614
  return;
2588
2615
  }
2589
- res.writeHead(status, upstreamRes.statusMessage === "" ? void 0 : upstreamRes.statusMessage, buildUpstreamResponseHeaders(upstreamRes.headers, RELAY_COOKIE_NAMES));
2616
+ res.writeHead(status, upstreamRes.statusMessage === "" ? void 0 : upstreamRes.statusMessage, withDocumentNoStore(buildUpstreamResponseHeaders(upstreamRes.headers, RELAY_COOKIE_NAMES)));
2590
2617
  upstreamRes.pipe(res);
2591
2618
  });
2592
2619
  upstreamReq.on("error", (error) => {
@@ -3251,12 +3278,12 @@ const TURN_RAIL_CARD_ID = "lg-turn-card";
3251
3278
  * - a plain tap still does exactly what it did (the official click navigates);
3252
3279
  * - holding a mark for ~320ms opens a readable card with that turn's own
3253
3280
  * preview text (prompt + response), pulled from the official component by
3254
- * focusing the mark — which is precisely what hovering does on the desktop,
3255
- * only it survives the finger lifting;
3256
- * - the card carries ◀ / ▶ steppers and one big jump button, so the turn you
3257
- * want never depends on hitting a 10px tick;
3258
- * - dragging (which scrolls the rail natively, `touch-action: pan-y`) or moving
3259
- * more than 12px cancels the long press, so scrolling is untouched;
3281
+ * dispatching its own pointermove signal — the same signal desktop hover uses;
3282
+ * - once the hold has entered scrub mode, sliding up/down continuously selects
3283
+ * the mark under the finger and refreshes the card, like desktop hover;
3284
+ * lingering at either rail edge auto-scrolls through virtualised marks;
3285
+ * - a quick drag before the hold timer expires manually scrolls the rail, so
3286
+ * ordinary rail scrolling remains available while the scrub gesture owns touch;
3260
3287
  * - the click that a held touch still emits is swallowed once, so holding never
3261
3288
  * navigates by accident.
3262
3289
  *
@@ -3272,10 +3299,17 @@ function mobileTurnRailTouchScript() {
3272
3299
  if(!(S.matchMedia&&S.matchMedia('(pointer: coarse)').matches))return;
3273
3300
  var CARD_ID="${TURN_RAIL_CARD_ID}";
3274
3301
  var card=null,titleEl=null,bodyEl=null,jumpEl=null,prevEl=null,nextEl=null,closeEl=null;
3275
- var nav=null,mark=null,armed=false,armY=0,timer=0,lastY=0;
3302
+ var nav=null,mark=null,armed=false,scrubbing=false,dragScrolling=false;
3303
+ var armY=0,lastY=0,timer=0,pointerId=null,captureNode=null,scrubDir=0,scrubRaf=0;
3304
+ // React may commit the official tooltip after several frames on iOS while a
3305
+ // finger is moving continuously. Observe that DOM instead of assuming two
3306
+ // animation frames are enough, and keep a small bounded polling fallback.
3307
+ var tipObserver=null,navObserver=null,markObserver=null,tipNode=null,tipPoll=0,settleTimer=0;
3308
+ var tipBaseline="",tipGeneration=0,tipCache={},cacheNav=null;
3276
3309
  function one(sel,root){try{return (root||doc).querySelector(sel)}catch(e){return null}}
3277
3310
  function navOf(node){try{return node&&node.closest?node.closest(SEL):null}catch(e){return null}}
3278
- function marks(){return nav?nav.querySelectorAll("button"):[]}
3311
+ // Official TurnNavigator marks carry data-index; card controls do not.
3312
+ function marks(){return nav?nav.querySelectorAll("button[data-index]"):[]}
3279
3313
  function el(tag,style,text){
3280
3314
  var node=doc.createElement(tag);
3281
3315
  if(style)node.style.cssText=style;
@@ -3287,8 +3321,12 @@ function mobileTurnRailTouchScript() {
3287
3321
  +"color:var(--dsw-alias-label-primary,#111);pointer-events:auto;padding:0 10px";
3288
3322
  function build(){
3289
3323
  if(card)return;
3290
- card=el("div",'position:fixed;left:12px;right:44px;top:76px;z-index:2147483645;display:none;'
3291
- +"box-sizing:border-box;padding:10px 12px 12px;border-radius:14px;pointer-events:none;"
3324
+ // Anchor in the official rail, not document.body: iOS Chrome/WebKit can
3325
+ // choose a surprising coordinate space for a body-level fixed layer after
3326
+ // an edge gesture. The rail itself is already on-screen, so right:100% is
3327
+ // a stable leftward anchor. Width and top are clamped in placeCard().
3328
+ card=el("div",'position:absolute;right:calc(100% + 8px);top:0;min-width:0;z-index:10;display:none;'
3329
+ +"box-sizing:border-box;max-height:calc(100vh - 24px);overflow-y:auto;padding:10px 12px 12px;border-radius:14px;pointer-events:none;"
3292
3330
  +"background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-primary,#111);"
3293
3331
  +"box-shadow:var(--dsw-elevation-panel,0 10px 30px rgba(0,0,0,.22));"
3294
3332
  +"border:.5px solid var(--dsw-alias-border-l2,rgba(0,0,0,.14));"
@@ -3305,11 +3343,13 @@ function mobileTurnRailTouchScript() {
3305
3343
  var row=el("div","display:flex;gap:8px;margin-top:8px");
3306
3344
  prevEl=el("button",BTN+"flex:none;min-width:44px","◀");
3307
3345
  nextEl=el("button",BTN+"flex:none;min-width:44px","▶");
3308
- jumpEl=el("button",BTN+"flex:1;background:var(--dsw-alias-state-business-primary,#3964fe);color:#fff");
3346
+ jumpEl=el("button",BTN+"flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;background:var(--dsw-alias-state-business-primary,#3964fe);color:#fff");
3309
3347
  prevEl.type="button";nextEl.type="button";jumpEl.type="button";
3310
3348
  row.appendChild(prevEl);row.appendChild(jumpEl);row.appendChild(nextEl);
3311
3349
  card.appendChild(head);card.appendChild(bodyEl);card.appendChild(row);
3312
- (doc.body||doc.documentElement).appendChild(card);
3350
+ // nav is the on-screen official rail. Keeping the card in this local
3351
+ // containing block avoids iOS Chrome's body-level fixed positioning path.
3352
+ if(nav)nav.appendChild(card);else (doc.body||doc.documentElement).appendChild(card);
3313
3353
  closeEl.addEventListener("click",function(ev){ev.stopPropagation();hide()});
3314
3354
  prevEl.addEventListener("click",function(ev){ev.stopPropagation();step(-1)});
3315
3355
  nextEl.addEventListener("click",function(ev){ev.stopPropagation();step(1)});
@@ -3320,51 +3360,252 @@ function mobileTurnRailTouchScript() {
3320
3360
  });
3321
3361
  }
3322
3362
  function hide(){
3323
- armed=false;mark=null;
3363
+ armed=false;scrubbing=false;dragScrolling=false;clearTimeout(timer);stopAuto();release();clearTipWatch();tipBaseline="";tipCache={};cacheNav=null;mark=null;
3324
3364
  if(card)card.style.display="none";
3325
3365
  try{if(nav)nav.removeAttribute("data-lg-turn-card")}catch(e){}
3326
3366
  }
3327
3367
  /** The official bubble is what we read; it must not also float under the finger. */
3328
3368
  function own(){try{if(nav)nav.setAttribute("data-lg-turn-card","1")}catch(e){}}
3329
- function paint(){
3330
- if(!card||!mark)return;
3331
- var label="";
3332
- try{label=mark.getAttribute("aria-label")||""}catch(e){}
3333
- var tip=nav?one('[role="tooltip"]',nav):null;
3334
- var prompt="",reply="";
3369
+ /**
3370
+ * Place inside the visible rail's local coordinate system, then clamp vertically
3371
+ * using the card's actual rect. This is intentionally independent of body-level
3372
+ * fixed positioning / visual viewport offsets, which differ in iOS Chrome.
3373
+ */
3374
+ function placeCard(){
3375
+ if(!card||!nav)return;
3376
+ var nr=nav.getBoundingClientRect(),vw=S.innerWidth||320,vh=S.innerHeight||568,safe=12;
3377
+ // right:calc(100% + 8px) means the card's right edge sits 8px left of
3378
+ // the rail. Limit its width so its left edge still has the safe margin.
3379
+ var width=Math.min(320,Math.max(0,nr.left-safe-8));
3380
+ card.style.width=width+"px";
3381
+ var target=lastY<vh*0.45?Math.round(vh*0.45):76;
3382
+ card.style.top=Math.round(target-nr.top)+"px";
3383
+ card.style.transform="translate3d(0,0,0)";
3384
+ try{requestAnimationFrame(fitCard)}catch(e){fitCard()}
3385
+ }
3386
+ function fitCard(){
3387
+ if(!card||card.style.display==="none"||!nav)return;
3388
+ var vh=S.innerHeight||568,safe=12,r=card.getBoundingClientRect(),dy=0;
3389
+ if(r.top<safe)dy=safe-r.top;
3390
+ else if(r.bottom>vh-safe)dy=vh-safe-r.bottom;
3391
+ if(dy){
3392
+ var top=Number.parseFloat(card.style.top)||0;
3393
+ card.style.top=Math.round(top+dy)+"px";
3394
+ }
3395
+ }
3396
+ function previewReady(node){
3397
+ // In the real rail React adds markPreview in the same commit that updates
3398
+ // the tooltip. Do not copy a previous mark's still-mounted tooltip during
3399
+ // the gap. The lightweight fake DOM used by unit tests has no className,
3400
+ // so it is deliberately treated as already committed.
3401
+ try{
3402
+ if(typeof node.className!=="string")return true;
3403
+ return node.className.indexOf("markPreview")>=0||node.getAttribute("aria-current")==="true";
3404
+ }catch(e){return true}
3405
+ }
3406
+ function clearTipWatch(){
3407
+ if(tipPoll){clearTimeout(tipPoll);tipPoll=0}
3408
+ if(settleTimer){clearTimeout(settleTimer);settleTimer=0}
3409
+ try{if(tipObserver)tipObserver.disconnect()}catch(e){}
3410
+ try{if(navObserver)navObserver.disconnect()}catch(e){}
3411
+ try{if(markObserver)markObserver.disconnect()}catch(e){}
3412
+ tipObserver=null;navObserver=null;markObserver=null;tipNode=null;
3413
+ }
3414
+ function readTip(){
3415
+ var prompt="",reply="",tip=nav?one('[role="tooltip"]',nav):null;
3335
3416
  if(tip&&tip.children){
3336
3417
  if(tip.children[0])prompt=tip.children[0].textContent||"";
3337
3418
  if(tip.children[1])reply=tip.children[1].textContent||"";
3338
3419
  }
3339
- titleEl.textContent=prompt||label||"轮次";
3340
- bodyEl.textContent=reply;
3341
- bodyEl.style.display=reply?"block":"none";
3420
+ return {prompt:prompt,reply:reply,tip:tip};
3421
+ }
3422
+ function tipKey(text){return (text.prompt||"")+"\\n"+(text.reply||"")}
3423
+ function cacheKey(node){
3424
+ try{return node.getAttribute("data-index")||node.getAttribute("aria-label")||""}catch(e){return ""}
3425
+ }
3426
+ function cachedTip(node){
3427
+ var key=cacheKey(node);
3428
+ return key&&tipCache[key]?tipCache[key]:null;
3429
+ }
3430
+ function storeTip(node,text){
3431
+ var key=cacheKey(node);
3432
+ if(key&&(text.prompt||text.reply))tipCache[key]={prompt:text.prompt,reply:text.reply};
3433
+ }
3434
+ function signalPreview(node){
3435
+ if(!node)return;
3436
+ try{
3437
+ var r=node.getBoundingClientRect();
3438
+ if(typeof S.PointerEvent==="function"){
3439
+ // pointerover is the PC path that marks the rail as being worked; the
3440
+ // following mouse move is intentionally the same signal DSH uses for
3441
+ // its desktop hover preview, not a synthetic click or navigation.
3442
+ node.dispatchEvent(new S.PointerEvent("pointerover",{
3443
+ bubbles:true,cancelable:false,pointerType:"mouse",clientX:r.left+r.width/2,clientY:r.top+r.height/2
3444
+ }));
3445
+ node.dispatchEvent(new S.PointerEvent("pointermove",{
3446
+ bubbles:true,cancelable:false,pointerType:"mouse",clientX:r.left+r.width/2,clientY:r.top+r.height/2
3447
+ }));
3448
+ }else if(typeof S.Event==="function"){
3449
+ node.dispatchEvent(new S.Event("pointermove",{bubbles:true}));
3450
+ }
3451
+ }catch(e){}
3452
+ }
3453
+ /** Render the current mark. A pending tooltip must never show an old turn's text. */
3454
+ function paint(includeTip,allowSame){
3455
+ if(!card||!mark)return;
3456
+ var label="",prompt="",reply="",ready=false,cached=cachedTip(mark);
3457
+ try{label=mark.getAttribute("aria-label")||""}catch(e){}
3458
+ if(includeTip&&previewReady(mark)){
3459
+ var text=readTip(),key=tipKey(text);
3460
+ if((text.prompt||text.reply)&&(allowSame||key!==tipBaseline)){
3461
+ storeTip(mark,text);prompt=text.prompt;reply=text.reply;ready=true;
3462
+ }
3463
+ }
3464
+ // A previously confirmed summary belongs to this exact rail mark, so it is
3465
+ // safe to show immediately when a fast drag revisits it. Never reuse a
3466
+ // previous mark's text: cache is keyed by data-index and cleared on close.
3467
+ if(!ready&&cached){prompt=cached.prompt;reply=cached.reply;ready=true}
3468
+ // aria-label belongs to the CTA only. It is not a summary, so never use it
3469
+ // as the floating title: that caused the visible "Jump to turn 75" duplicate.
3470
+ titleEl.textContent=ready?(prompt||"本轮对话"):'正在读取本轮摘要…';
3471
+ bodyEl.textContent=ready?reply:"";
3472
+ bodyEl.style.display=ready&&reply?"block":"none";
3342
3473
  jumpEl.textContent=label||"跳转";
3343
- var vh=S.innerHeight||0;card.style.top=(lastY<vh*0.45?Math.round(vh*0.45):76)+"px";
3344
3474
  card.style.display="block";
3475
+ placeCard();
3345
3476
  own();
3346
3477
  }
3347
- function focusMark(node){
3478
+ function watchTip(node,generation){
3479
+ clearTipWatch();
3480
+ var tries=0;
3481
+ function live(){return tipGeneration===generation&&mark===node&&card&&card.style.display!=="none"}
3482
+ function refresh(allowSame){if(live())paint(true,allowSame)}
3483
+ function attach(tip){
3484
+ if(tip===tipNode)return;
3485
+ try{if(tipObserver)tipObserver.disconnect()}catch(e){}
3486
+ tipNode=tip;tipObserver=null;
3487
+ if(!tip||typeof S.MutationObserver!=="function")return;
3488
+ try{
3489
+ tipObserver=new S.MutationObserver(function(){refresh(false)});
3490
+ tipObserver.observe(tip,{childList:true,subtree:true,characterData:true});
3491
+ }catch(e){tipObserver=null}
3492
+ }
3493
+ function retry(){
3494
+ if(!live())return;
3495
+ // Re-signal the official PC preview path: on iOS React can coalesce a
3496
+ // burst of touch moves, whereas this current-mark signal is idempotent.
3497
+ signalPreview(node);
3498
+ attach(nav?one('[role="tooltip"]',nav):null);
3499
+ // If two turns genuinely share identical text, accept it after a short
3500
+ // grace period rather than leaving the card pending forever.
3501
+ refresh(tries>=7);
3502
+ // About 3.6 seconds: enough for an unloaded historical turn plus a
3503
+ // coalesced WebKit React commit, still bounded so an open card cannot keep
3504
+ // a permanent background timer alive.
3505
+ if(++tries<80)tipPoll=setTimeout(retry,45);
3506
+ }
3507
+ if(nav&&typeof S.MutationObserver==="function"){
3508
+ try{
3509
+ navObserver=new S.MutationObserver(function(){
3510
+ if(live()){attach(one('[role="tooltip"]',nav));refresh(false)}
3511
+ });
3512
+ // The official tooltip is a direct nav child; do not observe the card
3513
+ // itself or our own title/body writes would create an observer loop.
3514
+ navObserver.observe(nav,{childList:true});
3515
+ }catch(e){navObserver=null}
3516
+ try{
3517
+ markObserver=new S.MutationObserver(function(){refresh(false)});
3518
+ markObserver.observe(node,{attributes:true,attributeFilter:["class","aria-current"]});
3519
+ }catch(e){markObserver=null}
3520
+ }
3521
+ retry();
3522
+ }
3523
+ /**
3524
+ * Ask the OFFICIAL component to render its preview without focusing the mark.
3525
+ *
3526
+ * focus({preventScroll:true}) looks harmless in Chromium, but iOS Chrome
3527
+ * is WebKit: WebKit can still scroll a focused right-edge button into view,
3528
+ * shifting the visual viewport right and leaving the left edge off-screen.
3529
+ * The desktop component already accepts pointermove as its hover signal,
3530
+ * so dispatch that bubbling event instead. It produces the same tooltip text
3531
+ * without asking the browser to move focus or scroll anything into view.
3532
+ */
3533
+ function previewMark(node){
3348
3534
  if(!node)return;
3535
+ // Only a transition from an already-previewed mark has stale text to guard
3536
+ // against. On the first hold there is no older turn, so accept the official
3537
+ // tooltip as soon as React renders it instead of needlessly waiting.
3538
+ tipBaseline=mark?tipKey(readTip()):"";
3349
3539
  mark=node;
3350
- try{node.focus({preventScroll:true})}catch(e){try{node.focus()}catch(e2){}}
3351
- paint();
3352
- // React commits the official tooltip on a later frame; re-read once it has.
3353
- try{requestAnimationFrame(function(){requestAnimationFrame(function(){
3354
- if(card&&card.style.display!=="none"&&mark===node)paint()
3355
- })})}catch(e){}
3540
+ var generation=++tipGeneration;
3541
+ signalPreview(node);
3542
+ // Do not copy the old tooltip while React is between preview commits. The
3543
+ // blue jump button is safe to update immediately because it is this mark's
3544
+ // aria-label; title/body wait for the actual official tooltip update.
3545
+ paint(false,false);
3546
+ watchTip(node,generation);
3356
3547
  }
3357
3548
  function step(dir){
3358
3549
  var all=marks(),i=-1,k=0;
3359
3550
  for(k=0;k<all.length;k++){if(all[k]===mark){i=k;break}}
3360
3551
  var j=i+dir;
3361
- if(j>=0&&j<all.length){focusMark(all[j]);return}
3552
+ if(j>=0&&j<all.length){previewMark(all[j]);return}
3362
3553
  var sc=nav?nav.firstElementChild:null;
3363
3554
  if(sc){sc.scrollTop+=dir*30;try{requestAnimationFrame(function(){
3364
3555
  var l2=marks();if(!l2.length)return;
3365
- focusMark(dir<0?l2[l2.length-1]:l2[0]);
3556
+ previewMark(dir<0?l2[l2.length-1]:l2[0]);
3366
3557
  })}catch(e){}}
3367
3558
  }
3559
+ function railScroller(){return nav?nav.firstElementChild:null}
3560
+ function markAt(y){
3561
+ var all=marks(),best=null,distance=Infinity,i=0;
3562
+ for(i=0;i<all.length;i++){
3563
+ var r=all[i].getBoundingClientRect();
3564
+ if(y>=r.top&&y<=r.bottom)return all[i];
3565
+ var d=Math.abs(y-(r.top+r.bottom)/2);
3566
+ if(d<distance){distance=d;best=all[i]}
3567
+ }
3568
+ return best;
3569
+ }
3570
+ function scrollRail(delta){
3571
+ var sc=railScroller();
3572
+ if(!sc)return;
3573
+ sc.scrollTop=Math.max(0,(sc.scrollTop||0)+delta);
3574
+ }
3575
+ function capture(node,ev){
3576
+ captureNode=node;
3577
+ pointerId=typeof ev.pointerId==="number"?ev.pointerId:null;
3578
+ try{if(pointerId!==null&&typeof node.setPointerCapture==="function")node.setPointerCapture(pointerId)}catch(e){}
3579
+ }
3580
+ function release(){
3581
+ try{if(captureNode&&pointerId!==null&&typeof captureNode.releasePointerCapture==="function")captureNode.releasePointerCapture(pointerId)}catch(e){}
3582
+ captureNode=null;pointerId=null;
3583
+ }
3584
+ function stopAuto(){
3585
+ scrubDir=0;
3586
+ if(scrubRaf){clearTimeout(scrubRaf);scrubRaf=0}
3587
+ }
3588
+ function autoScroll(){
3589
+ if(!scrubbing||!scrubDir){scrubRaf=0;return}
3590
+ var sc=railScroller();
3591
+ if(sc){
3592
+ var before=sc.scrollTop||0;
3593
+ sc.scrollTop=Math.max(0,before+scrubDir*10);
3594
+ if((sc.scrollTop||0)===before){stopAuto();return}
3595
+ var next=markAt(lastY);
3596
+ if(next&&next!==mark)previewMark(next);
3597
+ }
3598
+ scrubRaf=setTimeout(autoScroll,16)
3599
+ }
3600
+ function updateAuto(y){
3601
+ if(!nav)return;
3602
+ var r=nav.getBoundingClientRect(),edge=30,dir=0;
3603
+ if(y<r.top+edge)dir=-1;
3604
+ else if(y>r.bottom-edge)dir=1;
3605
+ if(dir===scrubDir)return;
3606
+ stopAuto();scrubDir=dir;
3607
+ if(dir)scrubRaf=setTimeout(autoScroll,16)
3608
+ }
3368
3609
  function swallowNextClick(){
3369
3610
  var handler=function(ev){
3370
3611
  try{if(card&&card.contains(ev.target))return}catch(e){}
@@ -3372,41 +3613,115 @@ function mobileTurnRailTouchScript() {
3372
3613
  try{doc.removeEventListener("click",handler,true)}catch(e){}
3373
3614
  };
3374
3615
  try{doc.addEventListener("click",handler,true)}catch(e){}
3375
- setTimeout(function(){try{doc.removeEventListener("click",handler,true)}catch(e){}},900);
3616
+ setTimeout(function(){try{doc.removeEventListener("click",handler,true)}catch(e){}},500);
3376
3617
  }
3377
- function open(node){
3618
+ function open(node,ev){
3378
3619
  nav=navOf(node)||nav;
3379
3620
  if(!nav)return;
3380
- lastY=armY;
3381
- build();
3382
- focusMark(node);
3383
- swallowNextClick();
3384
- log("turn preview: "+(node.getAttribute("aria-label")||""));
3621
+ if(cacheNav!==nav){cacheNav=nav;tipCache={}}
3622
+ armed=false;scrubbing=true;dragScrolling=false;
3623
+ lastY=typeof ev.clientY==="number"?ev.clientY:armY;
3624
+ build();previewMark(node);capture(node,ev);
3625
+ log("turn scrub start: "+(node.getAttribute("aria-label")||""));
3385
3626
  }
3386
3627
  function onDown(ev){
3387
3628
  try{
3388
3629
  if(card&&card.style.display==="block"&&!card.contains(ev.target))hide();
3389
3630
  var node=ev.target;
3390
- if(!node||node.tagName!=="BUTTON")return;
3631
+ // Card controls live inside nav for stable iOS positioning; they are not
3632
+ // rail marks and must keep their ordinary click behaviour.
3633
+ if(card&&card.contains(node))return;
3634
+ if(!node||node.tagName!=="BUTTON"||node.getAttribute("data-index")===null)return;
3391
3635
  var found=navOf(node);
3392
3636
  if(!found)return;
3393
- nav=found;armed=true;armY=ev.clientY;lastY=ev.clientY;
3637
+ nav=found;armed=true;scrubbing=false;dragScrolling=false;
3638
+ armY=ev.clientY;lastY=ev.clientY;capture(node,ev);
3394
3639
  clearTimeout(timer);
3395
- timer=setTimeout(function(){if(!armed)return;armed=false;open(node)},320);
3640
+ timer=setTimeout(function(){if(!armed)return;open(node,ev)},320);
3396
3641
  }catch(e){}
3397
3642
  }
3398
3643
  function onMove(ev){
3399
3644
  try{
3400
- if(!armed)return;
3401
- if(Math.abs(ev.clientY-armY)>16){armed=false;clearTimeout(timer)}
3645
+ if(pointerId!==null&&typeof ev.pointerId==="number"&&ev.pointerId!==pointerId)return;
3646
+ var y=ev.clientY;
3647
+ if(armed){
3648
+ if(Math.abs(y-armY)<=16)return;
3649
+ armed=false;dragScrolling=true;clearTimeout(timer);
3650
+ }
3651
+ if(dragScrolling){
3652
+ try{ev.preventDefault()}catch(e){}
3653
+ scrollRail(lastY-y);lastY=y;return;
3654
+ }
3655
+ if(!scrubbing)return;
3656
+ try{ev.preventDefault()}catch(e){}
3657
+ lastY=y;
3658
+ var next=markAt(y);
3659
+ if(next&&next!==mark)previewMark(next);
3660
+ updateAuto(y);
3661
+ }catch(e){}
3662
+ }
3663
+ function finish(ev){
3664
+ try{
3665
+ if(pointerId!==null&&typeof ev.pointerId==="number"&&ev.pointerId!==pointerId)return;
3666
+ clearTimeout(timer);
3667
+ if(scrubbing||dragScrolling)swallowNextClick();
3668
+ // One final PC-style signal after the finger settles gives a coalesced
3669
+ // WebKit preview commit a stable target instead of another moving mark.
3670
+ if(scrubbing&&mark){
3671
+ signalPreview(mark);
3672
+ settleTimer=setTimeout(function(){
3673
+ if(card&&card.style.display!=="none"&&mark)signalPreview(mark);
3674
+ },120);
3675
+ }
3676
+ armed=false;scrubbing=false;dragScrolling=false;stopAuto();release();
3677
+ }catch(e){}
3678
+ }
3679
+ function cancel(){
3680
+ // iOS cancels the pointer stream when it decides to run a native gesture
3681
+ // (a text selection or a system drag). The click it then emits still belongs
3682
+ // to the gesture we owned, and it can land on whatever is underneath — on a
3683
+ // phone that is how a drag could reach the composer's attach control. Swallow
3684
+ // it exactly as pointerup does; a plain tap never reaches this branch.
3685
+ if(scrubbing||dragScrolling)swallowNextClick();
3686
+ armed=false;scrubbing=false;dragScrolling=false;clearTimeout(timer);stopAuto();release();
3687
+ }
3688
+ /**
3689
+ * A drag that begins on the rail can end as a file drop somewhere else, and
3690
+ * DSH's attachment view reacts to any drag carrying a Files payload with its upload
3691
+ * affordance. Refuse the drag at its source; events outside the rail are left
3692
+ * alone so normal selection and dragging keep working.
3693
+ */
3694
+ /**
3695
+ * touch-action alone was not enough on WebKit: with the finger on a mark the
3696
+ * browser could still take the vertical drag after its slop threshold, which
3697
+ * pans the page and can fire pull-to-refresh mid-scrub. A non-passive
3698
+ * touchmove listener lets us refuse that outright for the duration of a
3699
+ * gesture that began on the rail. Touches anywhere else are never touched, and
3700
+ * a multi-finger touch is left alone so pinch still works.
3701
+ */
3702
+ function blockTouch(ev){
3703
+ try{
3704
+ if(pointerId===null)return;
3705
+ if(ev.touches&&ev.touches.length>1)return;
3706
+ if(!(armed||scrubbing||dragScrolling))return;
3707
+ if(!navOf(ev.target))return;
3708
+ ev.preventDefault();
3709
+ }catch(e){}
3710
+ }
3711
+ function blockDrag(ev){
3712
+ try{
3713
+ var node=ev.target;
3714
+ if(node&&navOf(node)){ev.preventDefault();ev.stopPropagation()}
3402
3715
  }catch(e){}
3403
3716
  }
3404
- function cancel(){armed=false;clearTimeout(timer)}
3717
+ doc.addEventListener("touchmove",blockTouch,{capture:true,passive:false});
3718
+ doc.addEventListener("dragstart",blockDrag,true);
3719
+ doc.addEventListener("selectstart",blockDrag,true);
3405
3720
  doc.addEventListener("pointerdown",onDown,true);
3406
3721
  doc.addEventListener("pointermove",onMove,true);
3407
- doc.addEventListener("pointerup",cancel,true);
3722
+ doc.addEventListener("pointerup",finish,true);
3408
3723
  doc.addEventListener("pointercancel",cancel,true);
3409
- log("touch preview layer ready");
3724
+ log("touch preview scrub layer ready");
3410
3725
  })();
3411
3726
  `;
3412
3727
  }
@@ -3434,14 +3749,17 @@ function mobileTurnRailTouchScript() {
3434
3749
  * window is never touched;
3435
3750
  * - the selector is attribute-based (`nav[aria-label="轮次导航"]` /
3436
3751
  * `"Turn navigation"`) plus one structural fallback, because a CSS-module
3437
- * class name is hashed; both are display-only except the labelled one, which
3438
- * also nudges the rail into the chat frame's right gutter (`right:2px`,
3439
- * `width:24px`) so it stops overlapping the message column;
3752
+ * class name is hashed; the labelled rule nudges the rail into the chat
3753
+ * frame's right gutter (`right:4px`, `width:28px`) so it does not overlap the
3754
+ * message column;
3440
3755
  * - it SELF-CHECKS: if the rail is found but stays invisible while the override
3441
3756
  * is applied, the style is removed again and the page is left byte-identical
3442
3757
  * to stock (`mobileTurnRail: "reverted"` in the page's patch ledger);
3443
- * - it never touches anything but the rail itself: no inline styles on `html`,
3444
- * `body` or `#root`, no new buttons, no scroll containers, no listeners.
3758
+ * - its only custom interaction is the coarse-pointer card/scrub layer: it
3759
+ * listens inside the official rail, sends the same pointermove signal the
3760
+ * desktop hover handler consumes, and delegates actual navigation back to
3761
+ * the official mark click. It never adds a second conversation scroller or
3762
+ * changes `html`, `body`, or `#root`.
3445
3763
  *
3446
3764
  * Known limit: the rail's mark pitch is fixed at 10px in JavaScript
3447
3765
  * (`TURN_SPACING_PX`, `measureElement: () => 10`), so CSS cannot grow the 28×10px
@@ -3460,7 +3778,7 @@ function mobileTurnRailTouchScript() {
3460
3778
  * @returns one inline `<script>` element.
3461
3779
  */
3462
3780
  function mobileTurnRailScript() {
3463
- return `<script>${MOBILE_TURN_RAIL_MARKER}(function(){try{var S=self,doc=document;var flags=globalThis.${PATCHES_GLOBAL};if(flags&&flags.mobileTurnRail===true)return;globalThis.${PATCHES_GLOBAL}=Object.assign({},flags,{mobileTurnRail:true});var diag=false;try{diag=/[?&]lgdiag/.test((S.location&&S.location.search)||"")}catch(e){}var lines=[];function log(s){lines.push(s);if(!diag)return;try{var p=doc.getElementById("lgtr");if(!p){p=doc.createElement("pre");p.id="lgtr";p.style.cssText="position:fixed;left:0;bottom:0;right:0;max-height:30%;z-index:2147483646;background:rgba(0,0,0,.9);color:#7cf;font:10px/1.3 monospace;padding:6px;margin:0;overflow:auto;white-space:pre-wrap;pointer-events:none";(doc.body||doc.documentElement).appendChild(p)}p.textContent="[lan-guard 轮次导航诊断]"+String.fromCharCode(10)+lines.join(String.fromCharCode(10))}catch(e){}}var SEL="nav[aria-label=\\"轮次导航\\"],nav[aria-label=\\"Turn navigation\\"]";if(!doc.getElementById("lg-turn-rail")){var st=doc.createElement("style");st.id="lg-turn-rail";st.appendChild(doc.createTextNode("@media (max-width: 1023px){"+SEL+"{display:block!important;right:4px!important;width:28px!important;touch-action:pan-y;-webkit-touch-callout:none}"+"nav[aria-label=\\"轮次导航\\"] button::before,nav[aria-label=\\"Turn navigation\\"] button::before{height:3px!important}"+"nav[aria-label=\\"轮次导航\\"][data-lg-turn-card] [role=\\"tooltip\\"],nav[aria-label=\\"Turn navigation\\"][data-lg-turn-card] [role=\\"tooltip\\"]{display:none!important}"+"div:has(>div [data-chat-flow])>div>nav{display:block!important}"+"}"));(doc.head||doc.documentElement).appendChild(st)}var narrow=false;try{narrow=!!(S.matchMedia&&S.matchMedia("(max-width: 1023px)").matches)}catch(e){}log("narrow="+narrow);var tries=0,misses=0,done=false;function rail(){try{return doc.querySelector(SEL)}catch(e){return null}}function visible(n){try{var cs=getComputedStyle(n),r=n.getBoundingClientRect();return cs.display!=="none"&&r.width>1&&r.height>1}catch(e){return false}}function revert(){try{var s=doc.getElementById("lg-turn-rail");if(s&&s.parentNode)s.parentNode.removeChild(s)}catch(e){}globalThis.${PATCHES_GLOBAL}=Object.assign({},globalThis.${PATCHES_GLOBAL},{mobileTurnRail:"reverted"});}function run(){if(done)return;if(!narrow){done=true;return}var n=rail();if(!n){if(++tries>8){log("no turn rail yet (style kept for the next session)");done=true}return}if(visible(n)){var r=n.getBoundingClientRect();log("turn rail visible "+Math.round(r.width)+"x"+Math.round(r.height)+" at x"+Math.round(r.x));done=true;return}if(++misses>=3){log("override lost -> reverted (stock page)");revert();done=true}}log("style installed");run();var t=setInterval(function(){if(done){clearInterval(t);return}run()},1500);try{` + mobileTurnRailTouchScript() + "}catch(e){}}catch(e){}})()<\/script>";
3781
+ return `<script>${MOBILE_TURN_RAIL_MARKER}(function(){try{var S=self,doc=document;var flags=globalThis.${PATCHES_GLOBAL};if(flags&&flags.mobileTurnRail===true)return;globalThis.${PATCHES_GLOBAL}=Object.assign({},flags,{mobileTurnRail:true});var diag=false;try{diag=/[?&]lgdiag/.test((S.location&&S.location.search)||"")}catch(e){}var lines=[];function log(s){lines.push(s);if(!diag)return;try{var p=doc.getElementById("lgtr");if(!p){p=doc.createElement("pre");p.id="lgtr";p.style.cssText="position:fixed;left:0;bottom:0;right:0;max-height:30%;z-index:2147483646;background:rgba(0,0,0,.9);color:#7cf;font:10px/1.3 monospace;padding:6px;margin:0;overflow:auto;white-space:pre-wrap;pointer-events:none";(doc.body||doc.documentElement).appendChild(p)}p.textContent="[lan-guard 轮次导航诊断]"+String.fromCharCode(10)+lines.join(String.fromCharCode(10))}catch(e){}}var SEL="nav[aria-label=\\"轮次导航\\"],nav[aria-label=\\"Turn navigation\\"]";if(!doc.getElementById("lg-turn-rail")){var st=doc.createElement("style");st.id="lg-turn-rail";st.appendChild(doc.createTextNode("@media (max-width: 1023px){"+SEL+"{display:block!important;right:4px!important;width:28px!important;touch-action:none!important;-webkit-touch-callout:none;-webkit-user-drag:none;user-select:none;-webkit-user-select:none;overscroll-behavior:contain!important}"+"nav[aria-label=\\"轮次导航\\"] *,nav[aria-label=\\"Turn navigation\\"] *{touch-action:none!important;overscroll-behavior:contain!important}"+"html,body{overscroll-behavior-y:none!important}"+"nav[aria-label=\\"轮次导航\\"] button[data-index]::before,nav[aria-label=\\"Turn navigation\\"] button[data-index]::before{height:3px!important}"+"nav[aria-label=\\"轮次导航\\"][data-lg-turn-card] [role=\\"tooltip\\"],nav[aria-label=\\"Turn navigation\\"][data-lg-turn-card] [role=\\"tooltip\\"]{visibility:hidden!important;opacity:0!important;pointer-events:none!important}"+"nav[aria-label=\\"轮次导航\\"][data-lg-turn-card] button[class*=\\"_markP\\"]::before,nav[aria-label=\\"Turn navigation\\"][data-lg-turn-card] button[class*=\\"_markP\\"]::before{transform:translateY(-50%) scaleX(1)!important;background:var(--dsw-alias-state-business-primary,#3964fe)!important;opacity:1!important}"+"div:has(>div [data-chat-flow])>div>nav{display:block!important}"+"}"));(doc.head||doc.documentElement).appendChild(st)}var narrow=false;try{narrow=!!(S.matchMedia&&S.matchMedia("(max-width: 1023px)").matches)}catch(e){}log("narrow="+narrow);var tries=0,misses=0,done=false;function rail(){try{return doc.querySelector(SEL)}catch(e){return null}}function visible(n){try{var cs=getComputedStyle(n),r=n.getBoundingClientRect();return cs.display!=="none"&&r.width>1&&r.height>1}catch(e){return false}}function revert(){try{var s=doc.getElementById("lg-turn-rail");if(s&&s.parentNode)s.parentNode.removeChild(s)}catch(e){}globalThis.${PATCHES_GLOBAL}=Object.assign({},globalThis.${PATCHES_GLOBAL},{mobileTurnRail:"reverted"});}function run(){if(done)return;if(!narrow){done=true;return}var n=rail();if(!n){if(++tries>8){log("no turn rail yet (style kept for the next session)");done=true}return}if(visible(n)){var r=n.getBoundingClientRect();log("turn rail visible "+Math.round(r.width)+"x"+Math.round(r.height)+" at x"+Math.round(r.x));done=true;return}if(++misses>=3){log("override lost -> reverted (stock page)");revert();done=true}}log("style installed");run();var t=setInterval(function(){if(done){clearInterval(t);return}run()},1500);try{` + mobileTurnRailTouchScript() + "}catch(e){}}catch(e){}})()<\/script>";
3464
3782
  }
3465
3783
  /**
3466
3784
  * Insert the narrow-screen turn-rail override.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-lan-guard",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "DSH web plugin: expose the official desktop Web UI to the local network through a gated reverse proxy, without touching DSH's own loopback binding.",
5
5
  "license": "MIT",
6
6
  "type": "module",