dsh-lan-guard 0.5.0 → 0.7.0
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 +121 -0
- package/README.md +18 -3
- package/README.zh.md +18 -3
- package/lib/client.js +5 -1
- package/lib/client.js.map +1 -1
- package/lib/index.js +512 -13
- package/package.json +1 -1
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) => {
|
|
@@ -3234,6 +3261,470 @@ function injectMobileScrollFix(html) {
|
|
|
3234
3261
|
}
|
|
3235
3262
|
/** Marker proving the mobile turn-rail patch was injected. */
|
|
3236
3263
|
const MOBILE_TURN_RAIL_MARKER = "/*dsh-lan-guard:mobile-turn-rail*/";
|
|
3264
|
+
/** Id of the phone preview card the touch layer renders. */
|
|
3265
|
+
const TURN_RAIL_CARD_ID = "lg-turn-card";
|
|
3266
|
+
/**
|
|
3267
|
+
* The phone-only touch layer for the turn rail.
|
|
3268
|
+
*
|
|
3269
|
+
* The official rail is a HOVER design: the preview bubble is driven by
|
|
3270
|
+
* `onPointerMove` / `onFocus` on each mark, so on a touch screen it can never
|
|
3271
|
+
* be read — a tap goes straight to `onClick` (navigate) and there is no hover
|
|
3272
|
+
* state at all. Measured 2026-10-06 on DSH 0.2.1-alpha.1 / iPhone viewport:
|
|
3273
|
+
* the marks are 28×10px with the pitch locked to 10px inside DSH's own
|
|
3274
|
+
* JavaScript, so "tap the right one" is also a precision problem.
|
|
3275
|
+
*
|
|
3276
|
+
* This layer therefore ADDS a gesture instead of changing the existing one:
|
|
3277
|
+
*
|
|
3278
|
+
* - a plain tap still does exactly what it did (the official click navigates);
|
|
3279
|
+
* - holding a mark for ~320ms opens a readable card with that turn's own
|
|
3280
|
+
* preview text (prompt + response), pulled from the official component by
|
|
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;
|
|
3287
|
+
* - the click that a held touch still emits is swallowed once, so holding never
|
|
3288
|
+
* navigates by accident.
|
|
3289
|
+
*
|
|
3290
|
+
* Every entry point is wrapped, and any failure leaves the rail exactly as the
|
|
3291
|
+
* official code left it. Rendered in DSH's own tokens so light/dark follow.
|
|
3292
|
+
*
|
|
3293
|
+
* @returns the ES5 body of the touch layer; callers embed it in the payload.
|
|
3294
|
+
*/
|
|
3295
|
+
function mobileTurnRailTouchScript() {
|
|
3296
|
+
return `
|
|
3297
|
+
/* --- touch preview layer: hovering is not a gesture a phone has --- */
|
|
3298
|
+
(function(){
|
|
3299
|
+
if(!(S.matchMedia&&S.matchMedia('(pointer: coarse)').matches))return;
|
|
3300
|
+
var CARD_ID="${TURN_RAIL_CARD_ID}";
|
|
3301
|
+
var card=null,titleEl=null,bodyEl=null,jumpEl=null,prevEl=null,nextEl=null,closeEl=null;
|
|
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;
|
|
3309
|
+
function one(sel,root){try{return (root||doc).querySelector(sel)}catch(e){return null}}
|
|
3310
|
+
function navOf(node){try{return node&&node.closest?node.closest(SEL):null}catch(e){return null}}
|
|
3311
|
+
// Official TurnNavigator marks carry data-index; card controls do not.
|
|
3312
|
+
function marks(){return nav?nav.querySelectorAll("button[data-index]"):[]}
|
|
3313
|
+
function el(tag,style,text){
|
|
3314
|
+
var node=doc.createElement(tag);
|
|
3315
|
+
if(style)node.style.cssText=style;
|
|
3316
|
+
if(text)node.textContent=text;
|
|
3317
|
+
return node;
|
|
3318
|
+
}
|
|
3319
|
+
var BTN="border:0;border-radius:9px;font:inherit;font-weight:600;min-height:38px;"
|
|
3320
|
+
+"background:var(--dsw-alias-fill-tsp-secondary,rgba(0,0,0,.06));"
|
|
3321
|
+
+"color:var(--dsw-alias-label-primary,#111);pointer-events:auto;padding:0 10px";
|
|
3322
|
+
function build(){
|
|
3323
|
+
if(card)return;
|
|
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;"
|
|
3330
|
+
+"background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-primary,#111);"
|
|
3331
|
+
+"box-shadow:var(--dsw-elevation-panel,0 10px 30px rgba(0,0,0,.22));"
|
|
3332
|
+
+"border:.5px solid var(--dsw-alias-border-l2,rgba(0,0,0,.14));"
|
|
3333
|
+
+'font:13px/1.45 -apple-system,BlinkMacSystemFont,"PingFang SC","Hiragino Sans GB",sans-serif');
|
|
3334
|
+
card.id=CARD_ID;
|
|
3335
|
+
var head=el("div","display:flex;align-items:flex-start;gap:8px");
|
|
3336
|
+
titleEl=el("div","flex:1;min-width:0;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap");
|
|
3337
|
+
closeEl=el("button",BTN+"min-width:34px;padding:0 8px;flex:none","✕");
|
|
3338
|
+
closeEl.type="button";
|
|
3339
|
+
head.appendChild(titleEl);head.appendChild(closeEl);
|
|
3340
|
+
bodyEl=el("div","margin-top:4px;color:var(--dsw-alias-label-secondary,#666);"
|
|
3341
|
+
+"white-space:pre-wrap;word-break:break-word;overflow:hidden;"
|
|
3342
|
+
+"display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:5");
|
|
3343
|
+
var row=el("div","display:flex;gap:8px;margin-top:8px");
|
|
3344
|
+
prevEl=el("button",BTN+"flex:none;min-width:44px","◀");
|
|
3345
|
+
nextEl=el("button",BTN+"flex:none;min-width:44px","▶");
|
|
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");
|
|
3347
|
+
prevEl.type="button";nextEl.type="button";jumpEl.type="button";
|
|
3348
|
+
row.appendChild(prevEl);row.appendChild(jumpEl);row.appendChild(nextEl);
|
|
3349
|
+
card.appendChild(head);card.appendChild(bodyEl);card.appendChild(row);
|
|
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);
|
|
3353
|
+
closeEl.addEventListener("click",function(ev){ev.stopPropagation();hide()});
|
|
3354
|
+
prevEl.addEventListener("click",function(ev){ev.stopPropagation();step(-1)});
|
|
3355
|
+
nextEl.addEventListener("click",function(ev){ev.stopPropagation();step(1)});
|
|
3356
|
+
jumpEl.addEventListener("click",function(ev){
|
|
3357
|
+
ev.stopPropagation();ev.preventDefault();
|
|
3358
|
+
var m=mark;hide();
|
|
3359
|
+
if(m){try{m.click()}catch(e){}}
|
|
3360
|
+
});
|
|
3361
|
+
}
|
|
3362
|
+
function hide(){
|
|
3363
|
+
armed=false;scrubbing=false;dragScrolling=false;clearTimeout(timer);stopAuto();release();clearTipWatch();tipBaseline="";tipCache={};cacheNav=null;mark=null;
|
|
3364
|
+
if(card)card.style.display="none";
|
|
3365
|
+
try{if(nav)nav.removeAttribute("data-lg-turn-card")}catch(e){}
|
|
3366
|
+
}
|
|
3367
|
+
/** The official bubble is what we read; it must not also float under the finger. */
|
|
3368
|
+
function own(){try{if(nav)nav.setAttribute("data-lg-turn-card","1")}catch(e){}}
|
|
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;
|
|
3416
|
+
if(tip&&tip.children){
|
|
3417
|
+
if(tip.children[0])prompt=tip.children[0].textContent||"";
|
|
3418
|
+
if(tip.children[1])reply=tip.children[1].textContent||"";
|
|
3419
|
+
}
|
|
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";
|
|
3473
|
+
jumpEl.textContent=label||"跳转";
|
|
3474
|
+
card.style.display="block";
|
|
3475
|
+
placeCard();
|
|
3476
|
+
own();
|
|
3477
|
+
}
|
|
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){
|
|
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()):"";
|
|
3539
|
+
mark=node;
|
|
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);
|
|
3547
|
+
}
|
|
3548
|
+
function step(dir){
|
|
3549
|
+
var all=marks(),i=-1,k=0;
|
|
3550
|
+
for(k=0;k<all.length;k++){if(all[k]===mark){i=k;break}}
|
|
3551
|
+
var j=i+dir;
|
|
3552
|
+
if(j>=0&&j<all.length){previewMark(all[j]);return}
|
|
3553
|
+
var sc=nav?nav.firstElementChild:null;
|
|
3554
|
+
if(sc){sc.scrollTop+=dir*30;try{requestAnimationFrame(function(){
|
|
3555
|
+
var l2=marks();if(!l2.length)return;
|
|
3556
|
+
previewMark(dir<0?l2[l2.length-1]:l2[0]);
|
|
3557
|
+
})}catch(e){}}
|
|
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
|
+
}
|
|
3609
|
+
function swallowNextClick(){
|
|
3610
|
+
var handler=function(ev){
|
|
3611
|
+
try{if(card&&card.contains(ev.target))return}catch(e){}
|
|
3612
|
+
try{ev.stopPropagation();ev.preventDefault()}catch(e){}
|
|
3613
|
+
try{doc.removeEventListener("click",handler,true)}catch(e){}
|
|
3614
|
+
};
|
|
3615
|
+
try{doc.addEventListener("click",handler,true)}catch(e){}
|
|
3616
|
+
setTimeout(function(){try{doc.removeEventListener("click",handler,true)}catch(e){}},500);
|
|
3617
|
+
}
|
|
3618
|
+
function open(node,ev){
|
|
3619
|
+
nav=navOf(node)||nav;
|
|
3620
|
+
if(!nav)return;
|
|
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")||""));
|
|
3626
|
+
}
|
|
3627
|
+
function onDown(ev){
|
|
3628
|
+
try{
|
|
3629
|
+
if(card&&card.style.display==="block"&&!card.contains(ev.target))hide();
|
|
3630
|
+
var node=ev.target;
|
|
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;
|
|
3635
|
+
var found=navOf(node);
|
|
3636
|
+
if(!found)return;
|
|
3637
|
+
nav=found;armed=true;scrubbing=false;dragScrolling=false;
|
|
3638
|
+
armY=ev.clientY;lastY=ev.clientY;capture(node,ev);
|
|
3639
|
+
clearTimeout(timer);
|
|
3640
|
+
timer=setTimeout(function(){if(!armed)return;open(node,ev)},320);
|
|
3641
|
+
}catch(e){}
|
|
3642
|
+
}
|
|
3643
|
+
function onMove(ev){
|
|
3644
|
+
try{
|
|
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()}
|
|
3715
|
+
}catch(e){}
|
|
3716
|
+
}
|
|
3717
|
+
doc.addEventListener("touchmove",blockTouch,{capture:true,passive:false});
|
|
3718
|
+
doc.addEventListener("dragstart",blockDrag,true);
|
|
3719
|
+
doc.addEventListener("selectstart",blockDrag,true);
|
|
3720
|
+
doc.addEventListener("pointerdown",onDown,true);
|
|
3721
|
+
doc.addEventListener("pointermove",onMove,true);
|
|
3722
|
+
doc.addEventListener("pointerup",finish,true);
|
|
3723
|
+
doc.addEventListener("pointercancel",cancel,true);
|
|
3724
|
+
log("touch preview scrub layer ready");
|
|
3725
|
+
})();
|
|
3726
|
+
`;
|
|
3727
|
+
}
|
|
3237
3728
|
/**
|
|
3238
3729
|
* Un-hide DSH's own turn-navigation rail on narrow screens (opt-in, default OFF).
|
|
3239
3730
|
*
|
|
@@ -3258,20 +3749,28 @@ const MOBILE_TURN_RAIL_MARKER = "/*dsh-lan-guard:mobile-turn-rail*/";
|
|
|
3258
3749
|
* window is never touched;
|
|
3259
3750
|
* - the selector is attribute-based (`nav[aria-label="轮次导航"]` /
|
|
3260
3751
|
* `"Turn navigation"`) plus one structural fallback, because a CSS-module
|
|
3261
|
-
* class name is hashed;
|
|
3262
|
-
*
|
|
3263
|
-
*
|
|
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;
|
|
3264
3755
|
* - it SELF-CHECKS: if the rail is found but stays invisible while the override
|
|
3265
3756
|
* is applied, the style is removed again and the page is left byte-identical
|
|
3266
3757
|
* to stock (`mobileTurnRail: "reverted"` in the page's patch ledger);
|
|
3267
|
-
* -
|
|
3268
|
-
*
|
|
3269
|
-
*
|
|
3270
|
-
*
|
|
3271
|
-
*
|
|
3272
|
-
*
|
|
3273
|
-
*
|
|
3274
|
-
*
|
|
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`.
|
|
3763
|
+
*
|
|
3764
|
+
* Known limit: the rail's mark pitch is fixed at 10px in JavaScript
|
|
3765
|
+
* (`TURN_SPACING_PX`, `measureElement: () => 10`), so CSS cannot grow the 28×10px
|
|
3766
|
+
* marks into 44px touch targets without making neighbours overlap. That is why
|
|
3767
|
+
* this patch ships a second, phone-only half — {@link mobileTurnRailTouchScript}
|
|
3768
|
+
* — which gives the rail a gesture it can actually be operated with (hold to
|
|
3769
|
+
* preview, steppers to pick the exact turn) instead of relying on precision.
|
|
3770
|
+
*
|
|
3771
|
+
* The rail itself only ever moves inside the chat frame's right gutter: at
|
|
3772
|
+
* `right:4px` / `width:28px` it starts exactly where the message column ends, so
|
|
3773
|
+
* it can never cover text.
|
|
3275
3774
|
*
|
|
3276
3775
|
* `?lgdiag=1` adds a small report panel (`#lgtr`) that survives a phone with no
|
|
3277
3776
|
* attached debugger.
|
|
@@ -3279,7 +3778,7 @@ const MOBILE_TURN_RAIL_MARKER = "/*dsh-lan-guard:mobile-turn-rail*/";
|
|
|
3279
3778
|
* @returns one inline `<script>` element.
|
|
3280
3779
|
*/
|
|
3281
3780
|
function mobileTurnRailScript() {
|
|
3282
|
-
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:
|
|
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>";
|
|
3283
3782
|
}
|
|
3284
3783
|
/**
|
|
3285
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.
|
|
3
|
+
"version": "0.7.0",
|
|
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",
|