diff --git a/docs/standards/architecture-current-state.md b/docs/standards/architecture-current-state.md index cc56b98..8cc4883 100644 --- a/docs/standards/architecture-current-state.md +++ b/docs/standards/architecture-current-state.md @@ -22,7 +22,7 @@ - 图片**新写入主通道 = IndexedDB Blob `{__blob}` / key `imgblob__`** (A) `app.js:2143`;`{__cache}`(Cache Storage)为兜底;\`ref_\`(`app.js` 内定义的 `IDB_REF_PREFIX = 'ref_'`)为 legacy 形态 (A)。 - 大图判定:`isBigDataUrl` = `data:` 且 `length > 3000` (A) `app.js:2018`;**画布保存保留阈值** `< 16384` 才原样保留 (A) `app.js:2182`。**两处阈值并存,含义不同**。 - 单测是**源码契约测试**:`tests/` 目录共 **493** 处源码文本钉点(`source.includes` / `source.indexOf` / `/re/.test(source)`),分布在 **20** 个文件(其中 `iwb-v32-web-test.js` 一个就占 **407**)→ **结构性重构会先打红测试**。**该数字已由 `tests/source-text-ratchet-test.js` 的「只减不增」棘轮守门**(2026-10-20 起守卫范围从 1 个文件扩到全目录:新增任何一处源码文本钉点都会打红)。**2026-11-12 复算**(`npm run audit:pins`,v3.24.76):二分 STRUCT **417** / NAME **76**;形态 **POS 403 / NEG 87 / COUNT 3**;难度 **易 62 / 中 316 / 难 115**。钉点减法第一批(v3.24.72)把 **537 → 505**:8 条探针钉点改为「门禁内 spec 是否真的读该计数器」、5 条改为运行时断言(生产态 `window` 上无探针)、10 条改为 DOM 断言(质量档位禁用 / 传输页无三模式按钮 / 模型项 title)、4 条改为运行时对象断言(健康检查两域、策略对象冻结)、其余 9 条有同文件 DOM 等价断言或仅剩 NEG。第二批(v3.24.76)把 **505 → 493**:94-5~7 三条「多标签释放语义」(10 处正则)换成 `tests/iwb-tabs-release.spec.js` 的 3 条真 e2e,剩 1 条「消费方契约」(断言该 spec 在门禁内且 spec 源码真的读两个探针);另 2 条 `wPurgeIntent.add` 钉点改为读 `src/workspace-purge.js`。**这一批一换就查出 3 个真缺陷**(objectURL 从未释放 / 彻底删除留孤儿标签 · session / 刷新后误回收打开标签的图)—— 见 CHANGELOG v3.24.76。 -- `app.js` = 单 IIFE **8,315 行**(**双层预算**:绝对上限 8,315 / 占总源码 ≤ 40%,现 **26.4%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,169 行**(上限 **2,169**,余量 0;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **115** 个模块 / 23,233 行,`sourceModules` 115 项;v3.24.68 新增 `clipboard-graph.js`,v3.24.74 新增 `image-admit.js`,v3.24.75 新增 `image-dedupe.js`,v3.24.76 新增 `workspace-purge.js`,v3.24.79 新增 `generation-provider-ping.js`,v3.24.80 删除无调用的 `createWBFlushViewport` 17 行)。 +- `app.js` = 单 IIFE **8,315 行**(**双层预算**:绝对上限 8,315 / 占总源码 ≤ 40%,现 **26.3%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,169 行**(上限 **2,169**,余量 0;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **115** 个模块 / 23,268 行,`sourceModules` 115 项;v3.24.68 新增 `clipboard-graph.js`,v3.24.74 新增 `image-admit.js`,v3.24.75 新增 `image-dedupe.js`,v3.24.76 新增 `workspace-purge.js`,v3.24.79 新增 `generation-provider-ping.js`,v3.24.80 删除无调用的 `createWBFlushViewport` 17 行)。 - 门禁:`npm run verify` = `verify:ci`(`build` → `node --check app.js` → `node --check dist/app.js` → `check-dist.js` → `lint`(ESLint 正确性规则,`src/` + `app.js`,P4-16a)→ `test:unit` → `test` → `test:facts`)+ `test:e2e` (A) `package.json`。 ## 2. 门禁与环境现状 diff --git a/src/runtime-workbench-logic.js b/src/runtime-workbench-logic.js index 933be2e..ae79789 100644 --- a/src/runtime-workbench-logic.js +++ b/src/runtime-workbench-logic.js @@ -2168,20 +2168,57 @@ }).catch(() => { setNotice({ type: 'err', text: '删除失败' }); return 0 }) } const loadDemo = () => { - CanvasStore.replace([ + const demoNodes = [ { id: 'n0', type: 'ref', x: 60, y: 380, data: { ...DEFAULTS.ref } }, { id: 'n1', type: 'prompt', x: 60, y: 140, data: { text: '一只戴耳机听歌的橘猫,赛博朋克霓虹街景,扁平插画风格,高细节,柔和光影' } }, { id: 'n2', type: 'gen', x: 400, y: 120, data: { ...DEFAULTS.gen } }, { id: 'n3', type: 'out', x: 750, y: 220, data: { ...DEFAULTS.out } }, - ], [ + ] + CanvasStore.replace(demoNodes, [ { id: 'e0', from: 'n0', to: 'n1' }, { id: 'e1', from: 'n1', to: 'n2' }, { id: 'e2', from: 'n2', to: 'n3' }, ], [], { persist: false }) + // v3.26.108:demo 节点原坐标从 x=60 起,会被左停靠栏(52 导航 + 318 面板)整片盖住 ⇒ 用安全区重新适应 + doFit(demoNodes) } - const doFit = (nodeList) => { - if (!nodeList || !nodeList.length) { setViewport({ x: 40, y: 30, scale: 1 }); return } + // 画布安全区(v3.26.108):扣除顶部标签条+画布工具条、左右停靠栏、底部工具栏。 + // 动机:停靠栏是后加的浮层(画布仍 inset:0),旧 fit 只避开 .iwb-navrail/.iwb-lib, + // 结果初始视口把节点放到左栏/顶栏底下 —— 用户看不见,自动化测试也点不到。 + const canvasSafeInsets = () => { + const PAD = 28 + const win = (typeof window !== 'undefined') ? window : null + const doc = win && win.document + if (!doc) return { left: 0, top: 0, right: 0, bottom: 0, pad: PAD } + const num = (v) => { const n = parseFloat(v); return Number.isFinite(n) ? n : 0 } + const cs = win.getComputedStyle(doc.documentElement) + // --iwb-dock-l/-r 由 src/ui-dock.js 维护(含 52px 一级导航;拖宽时实时更新) + // 空串 = 停靠栏组件还没挂载(首帧),此时任何计算都会把节点放进栏底 ⇒ 由 doFit 等它就绪 + const rawL = String(cs.getPropertyValue('--iwb-dock-l') || '').trim() + let left = num(rawL) + const right = num(cs.getPropertyValue('--iwb-dock-r')) + const libEl = doc.querySelector('.iwb-lib') + const libRight = (libEl && libEl.getBoundingClientRect().width > 0) ? libEl.getBoundingClientRect().right : 0 + if (libRight > left) left = libRight + const topbarEl = doc.querySelector('.iwb-canvas-topbar') + const top = topbarEl ? Math.max(0, topbarEl.getBoundingClientRect().bottom) : 0 + const tbEl = doc.querySelector('.iwb-toolbar-bottom') + const bottom = tbEl ? Math.max(0, win.innerHeight - tbEl.getBoundingClientRect().top) : 0 + const pending = (rawL === '') || !topbarEl + return { left, top, right, bottom, pad: PAD, pending } + } + + const doFit = (nodeList, _tries) => { + const ins = canvasSafeInsets() + // 停靠栏/画布工具条在首帧还没挂载(实测 --iwb-dock-l 约 180ms 后才写入): + // 此刻算出的占位是 0,会把节点放到栏底。等它就绪再适应,最多约 400ms,之后按当前值兜底。 + const tries = _tries || 0 + if (ins.pending && tries < 25) { + setTimeout(() => doFit(nodeList, tries + 1), 16) + return + } + if (!nodeList || !nodeList.length) { setViewport({ x: ins.left + ins.pad, y: ins.top + ins.pad, scale: 1 }); return } let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity for (const n of nodeList) { minX = Math.min(minX, n.x); minY = Math.min(minY, n.y) @@ -2190,15 +2227,10 @@ // 标题带在节点外框上方:纳入包围盒,避免适应视图后最上方节点标题顶到画布上边缘 const topNode = nodeList.find((n) => n.y === minY) if (hasNodeTitle(topNode)) minY -= NODE_HEAD_H - // 排除左侧工作台栏(含展开态)与可见的右侧提示词库,避免节点被遮挡 - const railEl = document.querySelector('.iwb-navrail, .iwb-plugin-page') - const railW = railEl ? railEl.getBoundingClientRect().width : 0 - const libEl = document.querySelector('.iwb-lib') - const libW = (libEl && libEl.getBoundingClientRect().width > 0) ? libEl.getBoundingClientRect().width : 0 - const vw = Math.max(120, window.innerWidth - railW - libW - 56) - const vh = window.innerHeight - 56 + const vw = Math.max(120, window.innerWidth - ins.left - ins.right - ins.pad * 2) + const vh = Math.max(120, window.innerHeight - ins.top - ins.bottom - ins.pad * 2) const scale = Math.max(0.01, Math.min(1, Math.min(vw / Math.max(1, maxX - minX), vh / Math.max(1, maxY - minY)))) - setViewport({ x: railW + 28 - minX * scale, y: 28 - minY * scale, scale }) + setViewport({ x: ins.left + ins.pad - minX * scale, y: ins.top + ins.pad - minY * scale, scale }) } return { historyStore, HISTORY_IMG_REF_FIELDS, historyRefUsable, historyRefData, historyRawSnapshot, pushHistory, pushHistoryDebounced, restore, undo, redo, addPromptToLibrary, UNDO_KEYS, updateNode, clearGenResults, deleteNodes, deleteEdge, copyOffset, duplicateNodes, floatbarRefPaste, outResultUrls, stageClip, copyNodes, pasteGraph, readClipboardGraph, pasteCopiedNodes, clearClipboard, cutNodes, groupOf, makeGroup, ungroup, joinGroupOf, renameGroup, duplicateGroup, saveGroupSnapshot, saveSelectionAsGroup, instantiateGroup, loadSavedGroups, findSpot, placeAtDrop, addNode, addPluginNode, addRefFromUrl, refSrcOf, refreshOutputs, deleteOutputs, loadDemo, doFit } diff --git a/src/ui-dock.js b/src/ui-dock.js index fd85745..74fd249 100644 --- a/src/ui-dock.js +++ b/src/ui-dock.js @@ -21,6 +21,7 @@ const el = React.createElement const useState = React.useState const useEffect = React.useEffect + const useLayoutEffect = React.useLayoutEffect || React.useEffect const useRef = React.useRef const MIN_W = 100 @@ -159,7 +160,9 @@ }, [panels]) // 把两侧实际占位宽度写给 CSS(画布不动,只让其它浮层让位) - useEffect(function () { + // v3.26.108:改 useLayoutEffect —— 必须在父组件 useEffect(启动 fit/doFit 读 --iwb-dock-l)之前写入, + // 否则首帧读到的占位是 0,初始视口仍会把节点放到停靠栏底下。 + useLayoutEffect(function () { const r = global.document && global.document.documentElement if (!r) return // 一级导航常驻在窗口最左(52px):左停靠栏整体右移,工具栏居中基准也要含它