dsh-lan-guard 0.4.6 → 0.5.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 +55 -0
- package/README.md +30 -5
- package/README.zh.md +32 -5
- package/lib/client.js +25 -1
- package/lib/client.js.map +1 -1
- package/lib/index.d.ts +15 -0
- package/lib/index.js +74 -3
- package/package.json +7 -6
package/lib/index.d.ts
CHANGED
|
@@ -119,6 +119,19 @@ interface LanGuardConfigShape {
|
|
|
119
119
|
* clipping overflowing content.
|
|
120
120
|
*/
|
|
121
121
|
mobileScrollFix: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Whether the served index un-hides DSH's own turn-navigation rail on narrow
|
|
124
|
+
* screens (default FALSE — the only off-by-default mobile patch).
|
|
125
|
+
*
|
|
126
|
+
* DSH renders that rail on a phone but hides it with its own container query
|
|
127
|
+
* (`@container (max-width: 900px)`), so the plugin can bring the PC behaviour
|
|
128
|
+
* to the phone with a scoped stylesheet instead of reimplementing it. It stays
|
|
129
|
+
* off by default because it changes a visual DSH deliberately removed, the
|
|
130
|
+
* rail's 24×10px marks are below the touch-target size the rest of this
|
|
131
|
+
* plugin holds itself to, and this cut has not been through on-device
|
|
132
|
+
* acceptance yet. Applies to the next page load.
|
|
133
|
+
*/
|
|
134
|
+
mobileTurnRail: boolean;
|
|
122
135
|
/** Visitor-side gate configuration. */
|
|
123
136
|
auth: AuthConfigShape;
|
|
124
137
|
/** Transport security configuration. */
|
|
@@ -181,6 +194,8 @@ interface LiveSwitches {
|
|
|
181
194
|
mobileCompat(): boolean;
|
|
182
195
|
/** Whether the served index carries the narrow-screen scroll correction. */
|
|
183
196
|
mobileScrollFix(): boolean;
|
|
197
|
+
/** Whether the served index un-hides DSH's own turn-navigation rail on narrow screens. */
|
|
198
|
+
mobileTurnRail(): boolean;
|
|
184
199
|
/** Whether an unnamed device must pair before it is let in. */
|
|
185
200
|
requirePairing(): boolean;
|
|
186
201
|
/** Whether a paired device still needs the operator's approval (F9). */
|
package/lib/index.js
CHANGED
|
@@ -88,6 +88,7 @@ const Config = z.object({
|
|
|
88
88
|
socketWatchdog: z.boolean().default(true).volatile(),
|
|
89
89
|
mobileCompat: z.boolean().default(true).volatile(),
|
|
90
90
|
mobileScrollFix: z.boolean().default(true).volatile(),
|
|
91
|
+
mobileTurnRail: z.boolean().default(false).volatile(),
|
|
91
92
|
auth: z.object({
|
|
92
93
|
enabled: z.boolean().default(true),
|
|
93
94
|
mode: z.union([
|
|
@@ -156,6 +157,7 @@ function liveSwitches(rawConfig, resolved) {
|
|
|
156
157
|
socketWatchdog: () => readField(root.socketWatchdog, resolved.socketWatchdog),
|
|
157
158
|
mobileCompat: () => readField(root.mobileCompat, resolved.mobileCompat),
|
|
158
159
|
mobileScrollFix: () => readField(root.mobileScrollFix, resolved.mobileScrollFix),
|
|
160
|
+
mobileTurnRail: () => readField(root.mobileTurnRail, resolved.mobileTurnRail),
|
|
159
161
|
mode: () => readField(root.auth === void 0 ? void 0 : auth.mode, resolved.auth.mode),
|
|
160
162
|
adminPolicy: () => readField(root.auth === void 0 ? void 0 : auth.adminPolicy, resolved.auth.adminPolicy),
|
|
161
163
|
adminProtection: () => readField(root.auth === void 0 ? void 0 : auth.adminProtection, resolved.auth.adminProtection),
|
|
@@ -176,6 +178,7 @@ function staticSwitches(config) {
|
|
|
176
178
|
socketWatchdog: () => config.socketWatchdog,
|
|
177
179
|
mobileCompat: () => config.mobileCompat,
|
|
178
180
|
mobileScrollFix: () => config.mobileScrollFix,
|
|
181
|
+
mobileTurnRail: () => config.mobileTurnRail,
|
|
179
182
|
mode: () => config.auth.mode,
|
|
180
183
|
adminPolicy: () => config.auth.adminPolicy,
|
|
181
184
|
adminProtection: () => config.auth.adminProtection,
|
|
@@ -297,7 +300,8 @@ function unwrapVolatileInput(input) {
|
|
|
297
300
|
"answerHeartbeat",
|
|
298
301
|
"socketWatchdog",
|
|
299
302
|
"mobileCompat",
|
|
300
|
-
"mobileScrollFix"
|
|
303
|
+
"mobileScrollFix",
|
|
304
|
+
"mobileTurnRail"
|
|
301
305
|
]) {
|
|
302
306
|
const value = result[key];
|
|
303
307
|
if (isVolatileLike(value)) result[key] = value.get();
|
|
@@ -351,6 +355,7 @@ function parseConfig(input, profileDir) {
|
|
|
351
355
|
socketWatchdog: readField(resolved.socketWatchdog, true),
|
|
352
356
|
mobileCompat: readField(resolved.mobileCompat, true),
|
|
353
357
|
mobileScrollFix: readField(resolved.mobileScrollFix, true),
|
|
358
|
+
mobileTurnRail: readField(resolved.mobileTurnRail, false),
|
|
354
359
|
auth: {
|
|
355
360
|
enabled: readField(rawAuth.enabled, true),
|
|
356
361
|
mode: readField(rawAuth.mode, "token_and_password"),
|
|
@@ -670,6 +675,7 @@ var AuthManager = class {
|
|
|
670
675
|
socketWatchdog: true,
|
|
671
676
|
mobileCompat: true,
|
|
672
677
|
mobileScrollFix: true,
|
|
678
|
+
mobileTurnRail: false,
|
|
673
679
|
auth: options.auth,
|
|
674
680
|
tls: {
|
|
675
681
|
mode: "off",
|
|
@@ -3226,6 +3232,65 @@ function injectMobileScrollFix(html) {
|
|
|
3226
3232
|
if (html.includes("/*dsh-lan-guard:mobile-scroll*/")) return html;
|
|
3227
3233
|
return insertAfterHead(html, mobileScrollFixScript());
|
|
3228
3234
|
}
|
|
3235
|
+
/** Marker proving the mobile turn-rail patch was injected. */
|
|
3236
|
+
const MOBILE_TURN_RAIL_MARKER = "/*dsh-lan-guard:mobile-turn-rail*/";
|
|
3237
|
+
/**
|
|
3238
|
+
* Un-hide DSH's own turn-navigation rail on narrow screens (opt-in, default OFF).
|
|
3239
|
+
*
|
|
3240
|
+
* The rail is NOT missing on a phone — it is rendered, virtualised and wired up,
|
|
3241
|
+
* and exactly one official rule hides it:
|
|
3242
|
+
* `@container (max-width: 900px) { .frame { display: none } }` in
|
|
3243
|
+
* `ui-chat/src/client/chat/TurnNavigator.module.css` (the container is the chat
|
|
3244
|
+
* frame, ~327px wide on a 390px phone). Measured 2026-10-06 against
|
|
3245
|
+
* DSH 0.2.1-alpha.1: the `<nav>` is in the DOM with `display:none` and the
|
|
3246
|
+
* virtualiser renders zero marks until something un-hides it; after a
|
|
3247
|
+
* `display:block` override the rail comes up fully working (marks, active mark,
|
|
3248
|
+
* load-and-jump) with no page errors.
|
|
3249
|
+
*
|
|
3250
|
+
* Why a stylesheet and not a reimplementation: the turn data
|
|
3251
|
+
* (`ui-chat`'s `navigation.items()`) is package-internal, so a plugin cannot
|
|
3252
|
+
* rebuild the rail — but it does not have to. Un-hiding reuses the official
|
|
3253
|
+
* component, its history paging, its active-mark follow and its previews.
|
|
3254
|
+
*
|
|
3255
|
+
* Deliberately conservative, in the same spirit as the scroll fix:
|
|
3256
|
+
*
|
|
3257
|
+
* - the override lives in a `@media (max-width: 1023px)` block, so a desktop
|
|
3258
|
+
* window is never touched;
|
|
3259
|
+
* - the selector is attribute-based (`nav[aria-label="轮次导航"]` /
|
|
3260
|
+
* `"Turn navigation"`) plus one structural fallback, because a CSS-module
|
|
3261
|
+
* class name is hashed; both are display-only except the labelled one, which
|
|
3262
|
+
* also nudges the rail into the chat frame's right gutter (`right:2px`,
|
|
3263
|
+
* `width:24px`) so it stops overlapping the message column;
|
|
3264
|
+
* - it SELF-CHECKS: if the rail is found but stays invisible while the override
|
|
3265
|
+
* is applied, the style is removed again and the page is left byte-identical
|
|
3266
|
+
* to stock (`mobileTurnRail: "reverted"` in the page's patch ledger);
|
|
3267
|
+
* - it never touches anything but the rail itself: no inline styles on `html`,
|
|
3268
|
+
* `body` or `#root`, no new buttons, no scroll containers, no listeners.
|
|
3269
|
+
*
|
|
3270
|
+
* Known limit (why this is the "A" cut): the rail's mark pitch is fixed at
|
|
3271
|
+
* 10px in JavaScript (`TURN_SPACING_PX`, `measureElement: () => 10`), so CSS
|
|
3272
|
+
* cannot grow the 24×10px marks into 44px touch targets without making
|
|
3273
|
+
* neighbours overlap. Aiming therefore stays as precise as on the desktop; a
|
|
3274
|
+
* transparent touch layer is the follow-up cut, not this one.
|
|
3275
|
+
*
|
|
3276
|
+
* `?lgdiag=1` adds a small report panel (`#lgtr`) that survives a phone with no
|
|
3277
|
+
* attached debugger.
|
|
3278
|
+
*
|
|
3279
|
+
* @returns one inline `<script>` element.
|
|
3280
|
+
*/
|
|
3281
|
+
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:2px!important;width:24px!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);}catch(e){}})()<\/script>`;
|
|
3283
|
+
}
|
|
3284
|
+
/**
|
|
3285
|
+
* Insert the narrow-screen turn-rail override.
|
|
3286
|
+
*
|
|
3287
|
+
* @param html - the index body as DSH rendered it.
|
|
3288
|
+
* @returns the body with the override inserted.
|
|
3289
|
+
*/
|
|
3290
|
+
function injectMobileTurnRail(html) {
|
|
3291
|
+
if (html.includes("/*dsh-lan-guard:mobile-turn-rail*/")) return html;
|
|
3292
|
+
return insertAfterHead(html, mobileTurnRailScript());
|
|
3293
|
+
}
|
|
3229
3294
|
/**
|
|
3230
3295
|
* The mobile compatibility shims, in one inline script.
|
|
3231
3296
|
*
|
|
@@ -3333,6 +3398,7 @@ function registerIndexPatches(options) {
|
|
|
3333
3398
|
let out = html;
|
|
3334
3399
|
if (options.switches.mobileCompat()) out = injectMobileCompat(out);
|
|
3335
3400
|
if (options.switches.mobileScrollFix()) out = injectMobileScrollFix(out);
|
|
3401
|
+
if (options.switches.mobileTurnRail()) out = injectMobileTurnRail(out);
|
|
3336
3402
|
if (options.switches.socketWatchdog()) out = injectSocketWatchdog(out);
|
|
3337
3403
|
if (options.switches.settingsUnlock()) out = injectSettingsUnlock(out);
|
|
3338
3404
|
return out;
|
|
@@ -3409,7 +3475,8 @@ function sanitizePreferencePatch(patch) {
|
|
|
3409
3475
|
"answerHeartbeat",
|
|
3410
3476
|
"socketWatchdog",
|
|
3411
3477
|
"mobileCompat",
|
|
3412
|
-
"mobileScrollFix"
|
|
3478
|
+
"mobileScrollFix",
|
|
3479
|
+
"mobileTurnRail"
|
|
3413
3480
|
]) {
|
|
3414
3481
|
if (!Object.hasOwn(source, key)) continue;
|
|
3415
3482
|
if (typeof source[key] !== "boolean") throw new PreferenceError(`${key} must be a boolean`);
|
|
@@ -3460,6 +3527,7 @@ function toSettingsPatch(values) {
|
|
|
3460
3527
|
if (values.socketWatchdog !== void 0) patch.socketWatchdog = values.socketWatchdog;
|
|
3461
3528
|
if (values.mobileCompat !== void 0) patch.mobileCompat = values.mobileCompat;
|
|
3462
3529
|
if (values.mobileScrollFix !== void 0) patch.mobileScrollFix = values.mobileScrollFix;
|
|
3530
|
+
if (values.mobileTurnRail !== void 0) patch.mobileTurnRail = values.mobileTurnRail;
|
|
3463
3531
|
if (values.requirePairing !== void 0) auth.requirePairing = values.requirePairing;
|
|
3464
3532
|
if (values.requireApproval !== void 0) auth.requireApproval = values.requireApproval;
|
|
3465
3533
|
if (values.mode !== void 0) auth.mode = values.mode;
|
|
@@ -3597,6 +3665,7 @@ function registerManagementRoutes(options) {
|
|
|
3597
3665
|
socketWatchdog: options.switches.socketWatchdog(),
|
|
3598
3666
|
mobileCompat: options.switches.mobileCompat(),
|
|
3599
3667
|
mobileScrollFix: options.switches.mobileScrollFix(),
|
|
3668
|
+
mobileTurnRail: options.switches.mobileTurnRail(),
|
|
3600
3669
|
mode: options.switches.mode(),
|
|
3601
3670
|
adminPolicy: options.switches.adminPolicy(),
|
|
3602
3671
|
adminProtection: options.switches.adminProtection(),
|
|
@@ -4024,7 +4093,8 @@ function registerManagementRoutes(options) {
|
|
|
4024
4093
|
}));
|
|
4025
4094
|
/**
|
|
4026
4095
|
* Index patches: the remote settings-page unlock, the mobile compatibility
|
|
4027
|
-
* shims
|
|
4096
|
+
* shims, the narrow-screen scroll correction, the narrow-screen turn-rail
|
|
4097
|
+
* override and the client-side socket watchdog.
|
|
4028
4098
|
*
|
|
4029
4099
|
* DSH disables its OFFICIAL settings surface for any page whose address bar
|
|
4030
4100
|
* is not loopback, which is every device arriving through this gateway; the
|
|
@@ -4039,6 +4109,7 @@ function registerManagementRoutes(options) {
|
|
|
4039
4109
|
settingsUnlock: () => options.switches.settingsUnlock(),
|
|
4040
4110
|
mobileCompat: () => options.switches.mobileCompat(),
|
|
4041
4111
|
mobileScrollFix: () => options.switches.mobileScrollFix(),
|
|
4112
|
+
mobileTurnRail: () => options.switches.mobileTurnRail(),
|
|
4042
4113
|
socketWatchdog: () => options.switches.socketWatchdog()
|
|
4043
4114
|
},
|
|
4044
4115
|
logger
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-lan-guard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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",
|
|
@@ -70,7 +70,8 @@
|
|
|
70
70
|
"0.1.7-rc.2": "compatible",
|
|
71
71
|
"0.1.7-rc.1": "compatible",
|
|
72
72
|
"0.2.0-rc.1": "compatible",
|
|
73
|
-
"0.2.0-rc.2": "compatible"
|
|
73
|
+
"0.2.0-rc.2": "compatible",
|
|
74
|
+
"0.2.1-alpha.1": "compatible"
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
},
|
|
@@ -91,10 +92,10 @@
|
|
|
91
92
|
"reverse-proxy"
|
|
92
93
|
],
|
|
93
94
|
"devDependencies": {
|
|
94
|
-
"@deepseek-ai/cordis": "
|
|
95
|
-
"@deepseek-ai/dsh-client-connection": "0.2.
|
|
96
|
-
"@deepseek-ai/dsh-host-webserver": "0.2.
|
|
97
|
-
"@deepseek-ai/schemastery": "
|
|
95
|
+
"@deepseek-ai/cordis": "4.0.5-alpha.1",
|
|
96
|
+
"@deepseek-ai/dsh-client-connection": "0.2.1-alpha.1",
|
|
97
|
+
"@deepseek-ai/dsh-host-webserver": "0.2.1-alpha.1",
|
|
98
|
+
"@deepseek-ai/schemastery": "3.18.5-alpha.1",
|
|
98
99
|
"@types/node": "^26.2.0",
|
|
99
100
|
"@types/qrcode": "^1.5.6",
|
|
100
101
|
"@types/react": "^18.3.31",
|