dsh-browser-cdp 1.7.3 → 1.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dsh-plugin.json +1 -1
- package/lib/client.js +91 -10
- package/package.json +2 -2
package/dsh-plugin.json
CHANGED
package/lib/client.js
CHANGED
|
@@ -364,6 +364,57 @@ function claimFamilyHostIfOrphaned(slots, isHeld, label, log) {
|
|
|
364
364
|
};
|
|
365
365
|
}
|
|
366
366
|
|
|
367
|
+
//#endregion
|
|
368
|
+
//#region src/client/fab-pos.ts
|
|
369
|
+
const clamp01 = (v) => Math.max(0, Math.min(1, v));
|
|
370
|
+
const isFin = (v) => typeof v === "number" && Number.isFinite(v);
|
|
371
|
+
/** 除法结果的归一化兜底:±Infinity 夹到 1/0,NaN 视为无效。 */
|
|
372
|
+
const divClamp = (px, vpSize) => {
|
|
373
|
+
const q = px / vpSize;
|
|
374
|
+
if (q === Infinity) return 1;
|
|
375
|
+
if (q === -Infinity) return 0;
|
|
376
|
+
if (!Number.isFinite(q)) return null;
|
|
377
|
+
return clamp01(q);
|
|
378
|
+
};
|
|
379
|
+
/**
|
|
380
|
+
* 读入 localStorage 存量形状并归一为比例态:
|
|
381
|
+
* - {fx,fy} 均有限 → 夹回 [0,1] 直用;
|
|
382
|
+
* - 否则 {x,y} 均有限(旧像素格式)→ 按当前视口除法换算(±Infinity 夹 1/0,NaN 拒);
|
|
383
|
+
* - 其余(非对象/数组/字段缺失/脏值)→ null,由调用方走默认位。
|
|
384
|
+
*/
|
|
385
|
+
function normalizeStored(raw, vp) {
|
|
386
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
387
|
+
const r = raw;
|
|
388
|
+
if (isFin(r.fx) && isFin(r.fy)) return {
|
|
389
|
+
fx: clamp01(r.fx),
|
|
390
|
+
fy: clamp01(r.fy)
|
|
391
|
+
};
|
|
392
|
+
if (!isFin(r.x) || !isFin(r.y)) return null;
|
|
393
|
+
const fx = divClamp(r.x, vp.vw);
|
|
394
|
+
const fy = divClamp(r.y, vp.vh);
|
|
395
|
+
if (fx === null || fy === null) return null;
|
|
396
|
+
return {
|
|
397
|
+
fx,
|
|
398
|
+
fy
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
/** 像素 → 比例,4 位小数舍入;像素本身可为 clamp 后越内值(先夹再存)。 */
|
|
402
|
+
function toRatio(pos, vp) {
|
|
403
|
+
const fx = divClamp(pos.x, vp.vw);
|
|
404
|
+
const fy = divClamp(pos.y, vp.vh);
|
|
405
|
+
return {
|
|
406
|
+
fx: fx === null ? 0 : fx,
|
|
407
|
+
fy: fy === null ? 0 : fy
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
/** 比例 → 像素(不做 clamp——落位后由接线层既有 clamp 收边)。 */
|
|
411
|
+
function fromRatio(r, vp) {
|
|
412
|
+
return {
|
|
413
|
+
x: Math.round(clamp01(r.fx) * vp.vw),
|
|
414
|
+
y: Math.round(clamp01(r.fy) * vp.vh)
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
|
|
367
418
|
//#endregion
|
|
368
419
|
//#region src/client/fam-write.ts
|
|
369
420
|
const defaultSleep = (ms) => new Promise((resolve) => {
|
|
@@ -3324,28 +3375,51 @@ function mountFloatingWatch(ctx) {
|
|
|
3324
3375
|
const DRAG_PANEL_KEY = "dsh.ego.watch.panelPos";
|
|
3325
3376
|
const FAB_W = 48, FAB_H = 48;
|
|
3326
3377
|
const PANEL_W = 408, PANEL_GAP = 8;
|
|
3327
|
-
const
|
|
3378
|
+
const vpFab = () => ({
|
|
3379
|
+
vw: window.innerWidth,
|
|
3380
|
+
vh: window.innerHeight,
|
|
3381
|
+
w: FAB_W,
|
|
3382
|
+
h: FAB_H
|
|
3383
|
+
});
|
|
3384
|
+
const vpPanel = () => ({
|
|
3385
|
+
vw: window.innerWidth,
|
|
3386
|
+
vh: window.innerHeight,
|
|
3387
|
+
w: PANEL_W,
|
|
3388
|
+
h: 520
|
|
3389
|
+
});
|
|
3390
|
+
const loadRatio = (key, vp) => {
|
|
3328
3391
|
try {
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3392
|
+
return normalizeStored(JSON.parse(localStorage.getItem(key) || "null"), vp);
|
|
3393
|
+
} catch {
|
|
3394
|
+
return null;
|
|
3395
|
+
}
|
|
3333
3396
|
};
|
|
3334
|
-
let
|
|
3397
|
+
let ratio = loadRatio(DRAG_KEY, vpFab());
|
|
3398
|
+
let pos = ratio ? fromRatio(ratio, vpFab()) : {
|
|
3335
3399
|
x: window.innerWidth - 18 - FAB_W,
|
|
3336
3400
|
y: window.innerHeight - 104 - FAB_H
|
|
3337
3401
|
};
|
|
3338
|
-
let
|
|
3402
|
+
let panelRatio = loadRatio(DRAG_PANEL_KEY, vpPanel());
|
|
3403
|
+
let panelPos = panelRatio ? fromRatio(panelRatio, vpPanel()) : null;
|
|
3339
3404
|
const clampFab = () => {
|
|
3340
3405
|
const vw = window.innerWidth, vh = window.innerHeight;
|
|
3341
3406
|
pos.x = Math.max(4, Math.min(vw - FAB_W - 4, pos.x));
|
|
3342
3407
|
pos.y = Math.max(4, Math.min(vh - FAB_H - 4, pos.y));
|
|
3343
3408
|
};
|
|
3344
|
-
|
|
3409
|
+
/** Paint current pixel state: clamp, mirror into ratio, write style.
|
|
3410
|
+
* Used by drags (which set pos directly) — never re-derives from ratio. */
|
|
3411
|
+
const paintFab = () => {
|
|
3345
3412
|
clampFab();
|
|
3413
|
+
ratio = toRatio(pos, vpFab());
|
|
3346
3414
|
fab.style.left = pos.x + "px";
|
|
3347
3415
|
fab.style.top = pos.y + "px";
|
|
3348
3416
|
};
|
|
3417
|
+
/** Full re-layout from the stored ratio (init + viewport resize): the ball
|
|
3418
|
+
* keeps its corner at any window size, then clamps back on-screen. */
|
|
3419
|
+
const placeFab = () => {
|
|
3420
|
+
if (ratio) pos = fromRatio(ratio, vpFab());
|
|
3421
|
+
paintFab();
|
|
3422
|
+
};
|
|
3349
3423
|
const placePanel = () => {
|
|
3350
3424
|
panel.style.left = panelPos.x + "px";
|
|
3351
3425
|
panel.style.top = panelPos.y + "px";
|
|
@@ -3369,6 +3443,10 @@ function mountFloatingWatch(ctx) {
|
|
|
3369
3443
|
};
|
|
3370
3444
|
placeFab();
|
|
3371
3445
|
if (panelPos) placePanel();
|
|
3446
|
+
window.addEventListener("resize", () => {
|
|
3447
|
+
placeFab();
|
|
3448
|
+
if (!panel.hidden) snapPanelToFab();
|
|
3449
|
+
});
|
|
3372
3450
|
let suppressFabClick = false;
|
|
3373
3451
|
/**
|
|
3374
3452
|
* Make `el` drag the FAB or the panel (`which` = 'fab' | 'panel').
|
|
@@ -3405,7 +3483,7 @@ function mountFloatingWatch(ctx) {
|
|
|
3405
3483
|
const s = state();
|
|
3406
3484
|
s.x = bx + dx;
|
|
3407
3485
|
s.y = by + dy;
|
|
3408
|
-
which === "fab" ?
|
|
3486
|
+
which === "fab" ? paintFab() : placePanel();
|
|
3409
3487
|
}
|
|
3410
3488
|
};
|
|
3411
3489
|
const up = (e) => {
|
|
@@ -3418,7 +3496,10 @@ function mountFloatingWatch(ctx) {
|
|
|
3418
3496
|
if (dragged) {
|
|
3419
3497
|
if (which === "fab") suppressFabClick = true;
|
|
3420
3498
|
try {
|
|
3421
|
-
|
|
3499
|
+
const r = toRatio(state(), which === "fab" ? vpFab() : vpPanel());
|
|
3500
|
+
if (which === "fab") ratio = r;
|
|
3501
|
+
else panelRatio = r;
|
|
3502
|
+
localStorage.setItem(which === "fab" ? DRAG_KEY : DRAG_PANEL_KEY, JSON.stringify(r));
|
|
3422
3503
|
} catch {}
|
|
3423
3504
|
}
|
|
3424
3505
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-browser-cdp",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.4",
|
|
4
4
|
"description": "dsh-browser-cdp: DSH browser plugin — attach to a running Chrome/Edge over CDP (no bundled browser needed); structured browser-automation tools (30+ bcdp_*) that drive the vendored ego runtime through ctx.subprocess, plus a realtime watch panel (live SSE screencast + direct mouse interaction + download capture + human-verification notice). Web shell: floating watch panel without dsh-better-sidebar, sidebar tab with it. Headless/TUI hosts: tools-only. [DSH 0.1.7-rc.1 ~ 0.2.1-rc.1 line (exact rc enumeration): declarative settings via Config .volatile() fields; for DSH 0.1.2-rc.1 ~ 0.1.5-rc.3 use the 0.17.x line]",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -104,6 +104,6 @@
|
|
|
104
104
|
},
|
|
105
105
|
"publishConfig": {
|
|
106
106
|
"registry": "https://registry.npmjs.org",
|
|
107
|
-
"tag": "
|
|
107
|
+
"tag": "dsh-0.2.1"
|
|
108
108
|
}
|
|
109
109
|
}
|