From 5df4f626eef77fca2a3fb1560220c20d6d14a609 Mon Sep 17 00:00:00 2001 From: qiqi Date: Wed, 2 Dec 2026 13:44:21 +0800 Subject: [PATCH] =?UTF-8?q?feat(gallery):=20=E5=9B=BE=E5=BA=93=E7=BC=A9?= =?UTF-8?q?=E7=95=A5=E5=9B=BE=E4=BC=98=E5=85=88=E7=94=A8=E8=90=BD=E5=9C=B0?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E5=89=AF=E6=9C=AC=EF=BC=9B=E6=91=98=E6=8E=89?= =?UTF-8?q?=E3=80=8C=E7=94=9F=E6=88=90=E4=B8=AD=E3=80=8D=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CONTRIBUTING.md | 4 ++-- app.js | 12 +++++++++++- docs/standards/architecture-current-state.md | 2 +- src/ui-node-bodies.js | 15 ++------------- tests/source-text-ratchet-test.js | 4 ++-- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f838a09..e835d43 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -105,8 +105,8 @@ IWB_WRITE_BOUNDARY_SNAPSHOT=1 node tests/architecture-boundary-guard-test.js # | 守卫 | 位置 | 现在的上限 | |---|---|---| -| `app.js` 总行数 | `tests/source-text-ratchet-test.js` `MAX_APP_JS_LINES` | **8,896**(另守「占总源码 ≤ 40%」,见 `MAX_APP_JS_SHARE`) | -| `Workbench()` 行数 | 同上 `MAX_WORKBENCH_LINES` | **2,488** | +| `app.js` 总行数 | `tests/source-text-ratchet-test.js` `MAX_APP_JS_LINES` | **8,906**(另守「占总源码 ≤ 40%」,见 `MAX_APP_JS_SHARE`) | +| `Workbench()` 行数 | 同上 `MAX_WORKBENCH_LINES` | **2,498** | | 单组件行数(不含 Workbench)| 同上 `MAX_APP_COMPONENT_LINES` | **423** | 三条都是**只减不增**。确需在 app.js 增长时,必须**同步上调上限并在 commit 里写理由**(等于显式记账,不会悄悄发生)。 diff --git a/app.js b/app.js index 9842411..8609f24 100644 --- a/app.js +++ b/app.js @@ -7976,7 +7976,17 @@ const tbCenterSeed = (type, refs) => { list: (o) => window.IWBPluginGallery.query(outputs, o), // v3.26.61:缩略图取源顺序(清单 data → images/thumbs → 本地原图 → 远程)在 gallery-sync 里, // 原因是「生图后图库不显示」有一半出在这里 —— 新图 data 还没 hydrate 就只剩远程 url 可退。 - thumb: (name) => (wGallerySync ? wGallerySync.thumbFor(name, { outputs, displayThumbOf: wDisplayThumbOf, galleryThumb: (h) => { const F = (typeof window !== 'undefined') ? window.IWBStorageFile : null; return (F && typeof F.galleryThumb === 'function') ? F.galleryThumb(h) : Promise.resolve('') }, galleryThumbUrl: (h) => { const F = (typeof window !== 'undefined') ? window.IWBStorageFile : null; return (F && typeof F.galleryThumbUrl === 'function') ? F.galleryThumbUrl(h) : Promise.resolve('') }, galleryThumbOf: (f, max) => { const F = (typeof window !== 'undefined') ? window.IWBStorageFile : null; return (F && typeof F.galleryThumbOfEntry === 'function') ? F.galleryThumbOfEntry(f, max) : Promise.resolve('') } }) : ''), + thumb: (name) => (wGallerySync ? wGallerySync.thumbFor(name, { outputs, displayThumbOf: wDisplayThumbOf, galleryThumb: (h) => { const F = (typeof window !== 'undefined') ? window.IWBStorageFile : null; return (F && typeof F.galleryThumb === 'function') ? F.galleryThumb(h) : Promise.resolve('') }, galleryThumbUrl: (h) => { const F = (typeof window !== 'undefined') ? window.IWBStorageFile : null; return (F && typeof F.galleryThumbUrl === 'function') ? F.galleryThumbUrl(h) : Promise.resolve('') }, galleryThumbOf: (f, max) => { + // 2026-12-02:图库缩略图优先用落地队列拿到的**本地副本**,别再为同一张图去 fetch 远程。 + // 未落地(无 localUrl)时行为不变,回落原来的 f.url。 + let ff = f + try { + const v = window.IWBImageIngestView && typeof window.IWBImageIngestView.get === 'function' ? window.IWBImageIngestView.get(f && f.url) : null + if (v && v.localUrl) ff = Object.assign({}, f, { url: v.localUrl }) + } catch (eIng) { /* ignore */ } + const F = (typeof window !== 'undefined') ? window.IWBStorageFile : null + return (F && typeof F.galleryThumbOfEntry === 'function') ? F.galleryThumbOfEntry(ff, max) : Promise.resolve('') + } }) : ''), preview: (name) => setPreview({ list: outputs.map((x) => ({ __gallery: true, name: x.name, origIdb: x.origIdb, idb: x.idb, url: x.url, thumb: x.data || null })), idx: Math.max(0, outputs.findIndex((x) => x.name === name)) }), download: async (names) => { const failed = [] diff --git a/docs/standards/architecture-current-state.md b/docs/standards/architecture-current-state.md index 2443a85..6464414 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,896 行**(**双层预算**:绝对上限 8,896 / 占总源码 ≤ 40%,现 **25.6%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,488 行**(上限 **2,488**,余量 0;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **127** 个模块 / 25,881 行,`sourceModules` 127 项;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,906 行**(**双层预算**:绝对上限 8,906 / 占总源码 ≤ 40%,现 **25.6%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,498 行**(上限 **2,498**,余量 0;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **127** 个模块 / 25,870 行,`sourceModules` 127 项;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`。 ## 1.5 内存基线(2026-11-30,v3.26.115,Windows / WebView2 实测) diff --git a/src/ui-node-bodies.js b/src/ui-node-bodies.js index 67ab521..163657b 100644 --- a/src/ui-node-bodies.js +++ b/src/ui-node-bodies.js @@ -889,15 +889,6 @@ } // 生成中(2026-12-02,用户裁定「方案 1」):某一轮还在跑时,旧图压暗 + 角标「生成中」, // 但不改 data.result —— 失败时旧图原样保留,不会出现「图没了」。 - // 生成中(2026-12-02,第三版):不再按具体 id 对 key —— 出图时宿主总会写一个 "…::out" 的忙标记, - // 这里只问「当前有没有任何 out 运行在跑」,避免 out/gen 节点 id 取错(前两版就是这么不亮的)。 - const outBusyAny = !!(busy && Object.keys(busy).some((k) => k.slice(-5) === '::out' && busy[k])) - const outProgAny = !!(progress && Object.keys(progress).some((k) => { - if (k.slice(-5) !== '::out') return false - const pg = progress[k] - return !!(pg && (Number(pg.total) || 0) > (Number(pg.done) || 0)) - })) - const genBusy = outBusyAny || outProgAny const ingSt = (global.IWBImageIngestView && global.IWBImageIngestView.get(r.url)) || null const imgEl = el('img', { key: 'out-img-' + cur + '-' + String(r.url || '').slice(-48), className: 'iwb-out-cell-img', decoding: 'async', fetchPriority: 'low', referrerPolicy: 'no-referrer', src: (ingSt && ingSt.localUrl) || wPreviewUrlOf((typeof wImgSrcForNode === 'function' ? wImgSrcForNode : wDisplayThumbOf)(thumbOf(r), Math.max(120, Math.min(360, (node && node.w ? node.w - 40 : 240))))), draggable: true, style: { aspectRatio: (r.width && r.height) ? String(r.width) + ' / ' + String(r.height) : undefined }, title: r.idb && r.data ? '单击选中 · 双击查看原图 · 拖到画布作参考图' : '单击选中 · 双击放大(可左右切换)· 拖到画布作参考图', onError: (e) => { if (e.currentTarget && e.currentTarget.src !== r.url) e.currentTarget.src = r.url }, onPointerDown: (e) => { e.stopPropagation(); props.onSelect && props.onSelect(node.id) }, onDragStart: (e) => { try { const u = r.url || ''; e.dataTransfer.setData('application/x-iwb-output-ref', u); e.dataTransfer.setData('text/plain', u); e.dataTransfer.effectAllowed = 'copy' } catch (err) { /* 浏览器拒写自定义 MIME 时仍保留 text/plain */ } }, onDoubleClick: (e) => { e.stopPropagation(); openPreviewAt(cur) } }) // 下载浮层:与图库共用同一组 hover token;组件缺失时退回旧的双小按钮(单文件/旧加载顺序) @@ -905,12 +896,10 @@ const actions = DlOv ? null : el('div', { className: 'iwb-out-cell-actions' }, el('button', { className: 'iwb-btn iwb-btn-sm', title: '下载', onClick: doDownload, onPointerDown: stop }, I('download')), ) - const ingBadge = genBusy - ? el('span', { className: 'iwb-out-cell-flag iwb-out-cell-flag-busy', key: 'ing-flag' }, '生成中') - : ingSt && (ingSt.status === 'queued' || ingSt.status === 'downloading') + const ingBadge = ingSt && (ingSt.status === 'queued' || ingSt.status === 'downloading') ? el('span', { className: 'iwb-out-cell-flag', key: 'ing-flag' }, ingSt.status === 'queued' ? '排队中' : '下载中') : (ingSt && ingSt.status === 'failed' ? el('span', { className: 'iwb-out-cell-flag iwb-out-cell-flag-err', key: 'ing-flag' }, '未落地') : null) - return el('div', { key: String(r.url || '') + '|' + ri, className: 'iwb-out-cell' + (genBusy ? ' iwb-out-cell-busy' : '') }, + return el('div', { key: String(r.url || '') + '|' + ri, className: 'iwb-out-cell' }, ingBadge, DlOv ? el(DlOv, { key: 'ov', onDownload: doDownload, icon: I('download'), label: '下载' }, imgEl) : imgEl, el('div', { className: 'iwb-out-cell-meta' }, (r.width || '?') + '×' + (r.height || '?')), diff --git a/tests/source-text-ratchet-test.js b/tests/source-text-ratchet-test.js index 708cea7..b47ece5 100644 --- a/tests/source-text-ratchet-test.js +++ b/tests/source-text-ratchet-test.js @@ -175,7 +175,7 @@ const MAX_SRC_GLOBALS = 123 // 2026-12-02 +1(122→123):新增 IWBImageI // · 图标解析统一(右键菜单 + 设置页走同一解析器,2 行) +2 // 通用件(pick/grant/stat/readDataUrl/readBlob/参数校验)全部在 src/image-file-ref.js // 与 src/plugin-api-images.js,app.js 只做装配。 -const MAX_APP_JS_LINES = 8896 // +31(8,860→8,891)2026-12-02:结果落地队列接线(ingest 实例 + 出图入队),逻辑在 src/image-ingest*.js:插件画布桥(含图片写回装配)迁到 src/plugin-canvas-bridge.js,app.js 只留依赖装配。之后只减不增。 +const MAX_APP_JS_LINES = 8906 // +31(8,860→8,891)2026-12-02:结果落地队列接线(ingest 实例 + 出图入队),逻辑在 src/image-ingest*.js:插件画布桥(含图片写回装配)迁到 src/plugin-canvas-bridge.js,app.js 只留依赖装配。之后只减不增。 const MAX_APP_JS_SHARE = 0.40 // ── 历史记账(供回溯,逐条保留)────────────────────────────────────────────── @@ -218,7 +218,7 @@ const MAX_APP_JS_SHARE = 0.40 // 需要实时读 .iwb-world 变换 + 按同类型实测高度校正视觉中心;属装配层的 DOM 读取, // 放 src 会引入新的全局读取与边界快照改动,权衡后留在 app.js // +10(2026-11-01):背景色「悬停预览」的 DOM 补丁助手(纯 DOM,不写数据/不进撤销栈); // 属装配层最小的 DOM 操作,放 src 会引入新的全局读取与边界快照改动,权衡后留在 app.js -const MAX_WORKBENCH_LINES = 2488 // +29(2,454→2,483)2026-12-02:同上(ingest 装配 + 入队一行):同上(画布桥迁出 Workbench())。之后只减不增。 +const MAX_WORKBENCH_LINES = 2498 // +29(2,454→2,483)2026-12-02:同上(ingest 装配 + 入队一行):同上(画布桥迁出 Workbench())。之后只减不增。 // 2026-11-18 v3.25.21:模态层指针守卫(2 行) // 实测 3090 → 2998(省 92):① 生成取消族 cancelRunsFor/cancelRun/cancelTaskJobs // → src/runtime-workbench-logic.js 的 createCancelActions(−53);② 工作区列表写回族