Compare commits

...
3 Commits
Author SHA1 Message Date
qiqi 2860faacbb fix(images): 缩略图 MIME 魔数嗅探 + 取消在用 objectURL 撤销 + 缩略图回收(v3.25.78/79)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 25s
2026-11-21 07:41:18 +08:00
qiqi f02b3dcec2 feat(settings): 设置窗可拖动 + 外观实时预览(v3.25.76)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 32s
2026-11-21 07:24:33 +08:00
qiqi f6d104fd95 feat(shell): 状态栏内存显示 + 修外观网格设置(v3.25.74)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 30s
2026-11-21 07:05:24 +08:00
25 changed files with 570 additions and 129 deletions

No files matched your search

+56
View File
@@ -14,6 +14,62 @@
> 3. 核验正式地址版本 → 之后才移动 `stable` / `stable-verified-<日期>` 标签、更新本 CHANGELOG、写 GitHub Release(`gh release create`)。
> 测试发现问题 → 改 → 再 `deploy:test`,正式环境不受影响。回滚点 `git reset --hard stable`。
## v3.25.79(2026-11-21)修缩略图 MIME 错配导致的黑块
### 根因
- 3.25.73 起的缩略图写盘把 **WebP 字节写进 `_768.jpg`**,读回时按扩展名声明成 `image/jpeg`。WebKit 对 MIME 与内容不符的 blob 有时直接渲染成黑块,双击看原图又正常。
### 修复
- 读缩略图时用**魔数**判断真实格式(JPEG/PNG/WebP/GIF),不再只看扩展名;写盘按真实类型选择 `.webp` / `.jpg`。
- 缩略图 objectURL 的 LRU 不再 `revoke`(可能正在被画布上的 `<img>` 使用,撤销即黑块)。
## v3.25.78(2026-11-21)修图片节点偶发黑块
### 问题
- 画布上部分图片节点显示为**黑块**,双击后才出现图片。
### 根因
- 参考图/出图格用了 `loading="lazy"`。画布是 transform 缩放的超大图层,WebKit 对容器内「懒加载」图片的触发条件不稳定 ⇒ 图片一直没发起加载,节点只剩占位底色;双击触发重渲染/滚动后才加载。
### 修复
- 画布内图片改为**立即加载**(节点本身已有视口裁剪,不需要浏览器级懒加载);保留 `decoding="async"`。
- 参考图 `<img>` 增加 `onError` 回退原图(缩略图坏了不至于空白)。
## v3.25.77(2026-11-21)修外观实时预览 + 设置遮罩透明
### 修复
- **实时预览没生效**:预览调用 `A.apply(appearance)`,但 `normalize()` 只认整份配置(`config.canvas.appearance`)⇒ 每次改控件实际应用的是**默认外观**。现改为传整份 draft。
- **设置遮罩挡住画布**:设置面板的遮罩改为透明(`.iwb-mask-ghost`),调外观能直接看到画布变化;点空白处仍可关闭。
## v3.25.76(2026-11-21)设置窗口可拖动 + 外观实时预览
### 新增
- 设置窗口支持**拖动标题栏移动**(不脱出屏幕),不再固定居中挡住画布。
- 外观页调整**实时反映到画布**:改颜色/网格样式/间距/圆角等立刻可见;关闭未保存会自动回滚到已保存外观。
### 说明
- 实时预览只写 CSS 变量 + 通知画布重渲染(网格贴图按新参数重建),不改配置文件;点「保存配置」才落盘。
## v3.25.75(2026-11-21)外观面板重构 + 网格线样式
### 新增
- 背景网格支持**点 / 线 / 空白**三选一(参考 infinite-canvas 的「网格样式」);线型下颜色/粗细标签自动改名。
- 主题下拉合并了配色模式与全部预设(默认 / 护眼深色 / 高对比 / 纸质 / 自定义),一处切换。
### 重构(用户裁定:保留节点组、合并主题、恢复按钮放组头)
- 外观分成 4 组:主题 / 画布 / 连线 / 节点;每组组头右侧「恢复本组默认」。
- 统一两栏网格:标签 120px 右对齐 + 控件左对齐,行高 40px、组间距 22px。
- 颜色行统一为「色块 + hex + ▾」,对比度警告收进行尾(不再整行黄字)。
- 配置新增 `canvas.appearance.gridStyle`(dots/lines/blank,老配置 gridOn=false 自动视为 blank)。
## v3.25.74(2026-11-21)状态栏内存显示 + 网格设置修复
### 新增
- 画布顶栏状态区显示**当前进程内存**(`内存 xxxMB`,4s 轮询;窗口隐藏时降到 8s)。Rust 新增命令 `app_memory_mb`(macOS/Linux 读 ps RSS,Windows 读 WorkingSet64)。
### 修复
- **外观设置里的网格三项失效**:网格点大小 / 网格间距 / 显示网格 之前不生效(3.25.70 改贴图网格时把参数写死成 28px/1.2)。现在网格每次渲染读取 CSS 变量(`--iwb-grid-gap/-size/-dot/-on`),与外观面板联动。
## v3.25.73(2026-11-21)缩略图三改(参考 basketikun/infinite-canvas)
### 背景
+57 -5
View File
@@ -5850,6 +5850,23 @@ const tbCenterSeed = (type, refs) => {
}, [])
const [thumbRev, setThumbRev] = React.useState(0) // v3.87.7:显示缩略图就绪后触发一次 re-render(必须在 Workbench 内)
useEffect(() => { wThumbBump = () => setThumbRev((v) => v + 1); return () => { wThumbBump = null } }, [])
// 缩略图回收(v3.25.78):启动 8 秒后按 300MB 上限清理最老的缩略图,不抢首帧
useEffect(() => {
const timer = setTimeout(() => {
try {
const F = wStoreMod()
if (F && typeof F.pruneThumbs === 'function') F.pruneThumbs(300).catch(() => { /* ignore */ })
} catch (e) { /* ignore */ }
}, 8000)
return () => clearTimeout(timer)
}, [])
// 外观实时预览(v3.25.76):设置面板每改一个外观项都会派发该事件,
// 这里只 bump 一次渲染,让网格贴图按新的间距/颜色/样式重新生成。
useEffect(() => {
const onAppearance = () => { try { setThumbRev((v) => v + 1) } catch (e) { /* ignore */ } }
window.addEventListener('iwb:appearance', onAppearance)
return () => window.removeEventListener('iwb:appearance', onAppearance)
}, [])
// 2026-11-14:插件节点体(render)异步注册完成后重画一次 —— 否则存档里的插件节点会一直停在
// 首帧的兜底体(hint + 纯文本),看起来像「样式节点只剩一段文本」。
const [typesRev, setTypesRev] = React.useState(0)
@@ -7618,13 +7635,28 @@ const tbCenterSeed = (type, refs) => {
const importCanvasFile = (file, fromDrop, dropX, dropY) => IWWorkbenchLogic.importCanvasFile({ canvasSize, commitCanvas, pushHistory, refs, setNotice, setSel }, file, fromDrop, dropX, dropY)
// 网格样式:优先用 src/canvas-grid.js 的贴图(平移只走 transform,不重绘点阵)
// v3.25.74:改为读取外观设置(网格点大小/间距/颜色/开关)—— 之前硬编码 28/1.2,
// 导致设置里的「网格点大小 / 网格间距 / 显示网格」全部失效(用户反馈)。
const readGridOpts = () => {
if (typeof getComputedStyle !== 'function' || typeof document === 'undefined') return { base: 22, dot: 1.4, color: 'rgba(120,128,140,0.55)', on: true }
try {
const cs = getComputedStyle(document.documentElement)
const gap = parseFloat(cs.getPropertyValue('--iwb-grid-gap')) || 22
const dot = parseFloat(cs.getPropertyValue('--iwb-grid-size')) || 1.4
const col = (cs.getPropertyValue('--iwb-grid-dot') || '').trim() || 'rgba(120,128,140,0.55)'
const onv = parseFloat(cs.getPropertyValue('--iwb-grid-on'))
const style = (document.documentElement.getAttribute('data-iwb-grid') || 'dots')
return { base: Math.max(8, gap), dot: Math.max(0.5, dot), color: col, on: !(onv === 0) && style !== 'blank', style }
} catch (e) { return { base: 22, dot: 1.4, color: 'rgba(120,128,140,0.55)', on: true } }
}
refs.gridOpts = readGridOpts()
const gridStyleOf = (x, y, scale) => {
const o = refs.gridOpts || { base: 22, dot: 1.4, color: 'rgba(120,128,140,0.55)', on: true }
if (!o.on) return { display: 'none' }
const G = (typeof window !== 'undefined') ? window.IWBCanvasGrid : null
const st = G && typeof G.styleOf === 'function'
? G.styleOf(x, y, scale, { base: 28, dot: 1.2, color: 'rgba(120,128,140,0.55)' })
: null
const st = G && typeof G.styleOf === 'function' ? G.styleOf(x, y, scale, o) : null
if (st) return st
return { backgroundSize: (28 * scale) + 'px ' + (28 * scale) + 'px', backgroundPosition: x + 'px ' + y + 'px' }
return { backgroundSize: (o.base * scale) + 'px ' + (o.base * scale) + 'px', backgroundPosition: x + 'px ' + y + 'px' }
}
// v3.25.68(借鉴 tldraw 的相机机制):手势期间只改 .iwb-world 的 transform,
@@ -7638,7 +7670,8 @@ const tbCenterSeed = (type, refs) => {
const grid = root.querySelector('.iwb-grid')
const G = (typeof window !== 'undefined') ? window.IWBCanvasGrid : null
if (grid && G && typeof G.applyTo === 'function') {
G.applyTo(grid, x, y, scale, { base: 28, dot: 1.2, color: 'rgba(120,128,140,0.55)' })
const o = refs.gridOpts || { base: 22, dot: 1.4, color: 'rgba(120,128,140,0.55)', on: true }
if (!o.on) { grid.style.display = 'none' } else { grid.style.display = '' ; G.applyTo(grid, x, y, scale, o) }
} else if (grid) {
grid.style.backgroundSize = (28 * scale) + 'px ' + (28 * scale) + 'px'
grid.style.backgroundPosition = x + 'px ' + y + 'px'
@@ -7780,6 +7813,24 @@ const tbCenterSeed = (type, refs) => {
const visibleIds = new Set(nodes.filter(nodeVisible).map((n) => n.id))
try { wSetScaleNow(viewport.scale) } catch (e) { /* ignore */ }
// 进程内存(v3.25.74):状态栏显示,便于对比优化前后的内存占用(4s 轮询,窗口隐藏时不拉)
const [memMb, setMemMb] = React.useState(0)
useEffect(() => {
let alive = true
let timer = null
const tick = () => {
if (!alive) return
if (typeof document !== 'undefined' && document.hidden) { timer = setTimeout(tick, 8000); return }
Promise.resolve().then(() => {
const T = (typeof window !== 'undefined') ? window.__TAURI__ : null
const inv = T && T.core && T.core.invoke
if (typeof inv !== 'function') return 0
return inv('app_memory_mb').catch(() => 0)
}).then((v) => { if (!alive) return; const n = Number(v) || 0; if (n > 0) setMemMb(n) }).catch(() => {}).then(() => { if (alive) timer = setTimeout(tick, 4000) })
}
timer = setTimeout(tick, 1200)
return () => { alive = false; if (timer) clearTimeout(timer) }
}, [])
const scaleText = Math.round(viewport.scale * 100) + '%'
const saveText = saveState === 'saving' ? '正在保存' : saveState === 'saved' ? '保存成功' : saveState === 'error' ? '保存失败' : ''
const connecting = !!conn
@@ -8095,6 +8146,7 @@ const tbCenterSeed = (type, refs) => {
setSettingOpen,
saveState,
saveText,
memMb,
notice,
busy,
progress,
+5 -5
View File
@@ -1,7 +1,7 @@
# 现状架构与性能事实基线(image-workbench-web)
> **本文档是什么**:现状**事实快照**,不是规范。用途:任何性能 / 内存 / 存储相关改动,先对齐这里的现实,避免把已经调好的东西改坏。
> 日期 **2026-10-20**(**2026-11-16 复算 · v3.24.85**)| 基线(**最近一次 bump 版本的提交**,不是主干 HEAD)`main = b37a1ff`(线上 `v3.25.73+b37a1ff` —— **未上线**(本地测试中):左右停靠栏配色对齐主色调(新增 `--iwb-dock-bg` 进灰阶 ramp + 头部深一档 + `.iwb-pcard` 补白底)+ 修 `Cargo.toml`/`Cargo.lock` 版本漂移,四处统一到 3.25.58)。上一条 3.25.30:线上实际运行提交是 docs 提交 `7df9dc4`,bump 提交为 `4be78c0`;2026-11-16 已发**测试站 + 正式站**,三地址一致 + `IWB_VERIFY_STRICT=1` 通过。v3.24.85 是「代码体检收口」(棘轮收回 Workbench 3090→2998 + 图库索引 4 条绕过锁的写路径收口到 `mutate` + 文档数字校准),`stable` / `stable-v3.24.85` / `stable-verified-2026-11-16` 均指向 `7df9dc4`。上一条 —— 2026-11-14 发**测试站 + 正式站** `https://test.image-workbench-web.pages.dev`:**v3.24.84 修「生图节点连了 3 条上游只出 1 个任务」**(任务 id 与去重基准改用新字段 `ownerNodeId`=本节点自己,不再用随继承冒泡的 `sourceNodeId` ⇒ 连几条线就几个任务;`relay` 仍归约到真实文本来源,同一来源多路径抵达只算一次)。上一条 v3.24.83:**修「插件节点冷启动退化成一段文本」**(插件节点体是异步注册的,`registerNodeType` 在 `render` 由无变有时自增 `NODE_TYPES_REV`,`NodeCard` 比它 ⇒ 注册那一刻重建一次;`canvas-normalize` 按命名规则把 `plugin:<id>:<variant>` 认作已知类型,不再降级成 `plugin` 并写回存档);配套插件 `style-source` 1.3.2 把节点体样式改为**脚本执行时注入**(此前只在面板 `mount()` 注入 ⇒ 从存档直接进画布时节点无样式、缩略图按原图铺满)。上一条 v3.24.82 同批:提示词/文本节点**显示上游继承文本**(自己 `data.text` 为空时把上游那段话显示在框里,改一个字即接管,另有「恢复跟随」清空回跟随;多路上游按 Y 轴取第一条)+ 修 `nodeRefsOf` 的 textout 分支只认 llm/batch/combine 上游导致「样式 → 文本 → 分层」丢参考图;再上一条 v3.24.81:① 插件节点可自定义节点体(`render(node, props, host)` 画真实 DOM,宿主不每帧重建 ⇒ 输入框不失焦);② 节点自带参考图(`data.refOn/refUrl` ⇒ 任务图里补伪参考图,坐标取节点自身 ⇒ 仍参与「图片按 X 轴排序」);③ 连线白名单按 `data.outKind === 'prompt'` 归一化,7 条规则一次放行,内置节点行为逐字不变。上一条 v3.24.80 = 离开页面的兜底保存不递增 rev(2026-11-14 07:20 补发 —— 首发 11-13 23:25 撞 Cloudflare Workers API 事故 `503 no healthy upstream`,期间正式站保持在 `v3.24.79+8598a57` 未动)。v3.24.83 的 bump 提交即 `0a27a42`(v3.24.82 为 `ef6cf42`、v3.24.81 为 `dba71e3`);主干 HEAD 会继续前进,见 [`RELEASES.md`](../RELEASES.md))| 历史分支 `refactor/architecture` / `feat/multi-canvas-tabs` / `refactor/state-store` 已于 2026-10-20 清理(内容均已并入 main,归档标签 `archive/*`),本文**计数类事实**已按 main HEAD 复算。
> 日期 **2026-10-20**(**2026-11-16 复算 · v3.24.85**)| 基线(**最近一次 bump 版本的提交**,不是主干 HEAD)`main = f02b3dc`(线上 `v3.25.79+f02b3dc` —— **未上线**(本地测试中):左右停靠栏配色对齐主色调(新增 `--iwb-dock-bg` 进灰阶 ramp + 头部深一档 + `.iwb-pcard` 补白底)+ 修 `Cargo.toml`/`Cargo.lock` 版本漂移,四处统一到 3.25.58)。上一条 3.25.30:线上实际运行提交是 docs 提交 `7df9dc4`,bump 提交为 `4be78c0`;2026-11-16 已发**测试站 + 正式站**,三地址一致 + `IWB_VERIFY_STRICT=1` 通过。v3.24.85 是「代码体检收口」(棘轮收回 Workbench 3090→2998 + 图库索引 4 条绕过锁的写路径收口到 `mutate` + 文档数字校准),`stable` / `stable-v3.24.85` / `stable-verified-2026-11-16` 均指向 `7df9dc4`。上一条 —— 2026-11-14 发**测试站 + 正式站** `https://test.image-workbench-web.pages.dev`:**v3.24.84 修「生图节点连了 3 条上游只出 1 个任务」**(任务 id 与去重基准改用新字段 `ownerNodeId`=本节点自己,不再用随继承冒泡的 `sourceNodeId` ⇒ 连几条线就几个任务;`relay` 仍归约到真实文本来源,同一来源多路径抵达只算一次)。上一条 v3.24.83:**修「插件节点冷启动退化成一段文本」**(插件节点体是异步注册的,`registerNodeType` 在 `render` 由无变有时自增 `NODE_TYPES_REV`,`NodeCard` 比它 ⇒ 注册那一刻重建一次;`canvas-normalize` 按命名规则把 `plugin:<id>:<variant>` 认作已知类型,不再降级成 `plugin` 并写回存档);配套插件 `style-source` 1.3.2 把节点体样式改为**脚本执行时注入**(此前只在面板 `mount()` 注入 ⇒ 从存档直接进画布时节点无样式、缩略图按原图铺满)。上一条 v3.24.82 同批:提示词/文本节点**显示上游继承文本**(自己 `data.text` 为空时把上游那段话显示在框里,改一个字即接管,另有「恢复跟随」清空回跟随;多路上游按 Y 轴取第一条)+ 修 `nodeRefsOf` 的 textout 分支只认 llm/batch/combine 上游导致「样式 → 文本 → 分层」丢参考图;再上一条 v3.24.81:① 插件节点可自定义节点体(`render(node, props, host)` 画真实 DOM,宿主不每帧重建 ⇒ 输入框不失焦);② 节点自带参考图(`data.refOn/refUrl` ⇒ 任务图里补伪参考图,坐标取节点自身 ⇒ 仍参与「图片按 X 轴排序」);③ 连线白名单按 `data.outKind === 'prompt'` 归一化,7 条规则一次放行,内置节点行为逐字不变。上一条 v3.24.80 = 离开页面的兜底保存不递增 rev(2026-11-14 07:20 补发 —— 首发 11-13 23:25 撞 Cloudflare Workers API 事故 `503 no healthy upstream`,期间正式站保持在 `v3.24.79+8598a57` 未动)。v3.24.83 的 bump 提交即 `0a27a42`(v3.24.82 为 `ef6cf42`、v3.24.81 为 `dba71e3`);主干 HEAD 会继续前进,见 [`RELEASES.md`](../RELEASES.md))| 历史分支 `refactor/architecture` / `feat/multi-canvas-tabs` / `refactor/state-store` 已于 2026-10-20 清理(内容均已并入 main,归档标签 `archive/*`),本文**计数类事实**已按 main HEAD 复算。
<!-- 2026-10-28 P1 拆分批 1:新增 src/generation-task-graph.js(5 个任务图纯函数自 app.js 迁出)
⇒ 模块数 60→61、耦合面 51→52、sourceModules 60→61。耦合面只**新增** IWBWTaskGraph,无删除。
2026-10-28 P1 拆分批 2:新增 src/storage-config-shape.js(9 个配置形状纯函数自 app.js 迁出)
@@ -22,7 +22,7 @@
- 图片**新写入主通道 = IndexedDB Blob `{__blob}` / key `imgblob_<hash>_<len>`** (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,508 行**(**双层预算**:绝对上限 8,700 / 占总源码 ≤ 40%,现 **36.8%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,998 行**(上限 **3,030**,余量 32;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **98** 个模块 / 14,607 行,`sourceModules` 98 项;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,508 行**(**双层预算**:绝对上限 8,700 / 占总源码 ≤ 40%,现 **36.8%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,998 行**(上限 **3,030**,余量 32;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **99** 个模块 / 14,607 行,`sourceModules` 99 项;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. 门禁与环境现状
@@ -167,7 +167,7 @@
- 同一张图被 3 个节点引用、hydrate 成 3 个不同 objectURL 时,preview/display 缓存各自 miss → 重复解码(与 F2 相邻)。
- **F10|`refs.genScheduler` 是桩** (A) → 未接线,暂无运行时影响(P3)。
- **F11|已建但未接线的模块层(2026-10-17 接线审计;2026-10-18 复核更正)** (A)
- **判定法**:`global.X =` / `root.X =` 判「导出」;跨文件裸引用判「读」;排除自合并(`src/runtime-constants.js:9`)。`app.js` 是**唯一生产消费者**(无 HTML 入口;`sw.js` 不引用模块全局)。**98 个模块中 59 个导出**被 `app.js` 读取;其余为未接线 / 仅测试 / 零引用(见下)。
- **判定法**:`global.X =` / `root.X =` 判「导出」;跨文件裸引用判「读」;排除自合并(`src/runtime-constants.js:9`)。`app.js` 是**唯一生产消费者**(无 HTML 入口;`sw.js` 不引用模块全局)。**99 个模块中 59 个导出**被 `app.js` 读取;其余为未接线 / 仅测试 / 零引用(见下)。
- **仅被测试引用(9 模块 + 2 导出)**:`canvas-domain`、`generation-retry`、`generation-service`、`runtime-recovery-runner`、`runtime-state-bridge`、`runtime-store`、`storage-reconcile`、`storage-result`、`workspace-service`;导出 `IWBStorageHealthFactory`、`IWBPluginHostFactory`。(`storage-result` 是**存储层共享结果类型**,被 6 个存储模块读取,**非死代码**;`runtime-store` 为状态模型 epic 地基。)
- **app.js 零引用(1 模块 + 3 导出)**:模块 `generation-controller`;导出 `IWBRuntimeMetricsFactory`、`IWBStorageRuntimeFactory`、`IWBUIComponents`。`canvas-relations` 已随 `06cf211` 删除(本文档早前把它列为"唯一可删者",实际已删)。零引用证据 = `grep -rn "<名字>" .`(排除 `node_modules|dist|vendor|test-results`)**只命中其自身赋值行**。
- **半接线 / 未接线**:`IWBRuntimeStateBridge` **无 app.js 引用(仅测试)**;`IWBRuntimeRunContext` **已接线**(`runNode` 读取运行上下文);`IWBGenerationController` 是完整但**从未被调用**的工厂;`ModularWorkspaceStore`(`app.js` 内)是 `storage-workspace` 的**预留接线 seam**(当前无下游使用,保留);`window.IWBImageFolder` 自注册后读回(装载路径)。
@@ -183,7 +183,7 @@
| `storage-reconcile` | 存储对账(`createReconciler`/`check`) | 内联对账 | 存储层收口 |
| `runtime-recovery-runner` | 执行恢复候选(`candidate`/`valid`/`run`) | 内联恢复 | 断点恢复 |
| `canvas-domain` | 画布域模型(`commit`/`updateNode`/`deleteNodes`…) | `CanvasStore` 那一套 | Workbench 解耦(P2-9) |
- **耦合面已冻结**:`tests/architecture-boundary-guard-test.js`(进 `npm run test:unit` 末环)冻结 app.js↔src 耦合面(**83** 项)与 `sourceModules` 顺序(**98** 项);命名例外由第 5 组冻结,新增非 `IWB` 前缀导出即打红。
- **耦合面已冻结**:`tests/architecture-boundary-guard-test.js`(进 `npm run test:unit` 末环)冻结 app.js↔src 耦合面(**83** 项)与 `sourceModules` 顺序(**99** 项);命名例外由第 5 组冻结,新增非 `IWB` 前缀导出即打红。
## 12. 易踩的坑
@@ -254,7 +254,7 @@
**信任模型(必须明示)**:形态 A 的插件是**可信代码**(与核心同权限、无沙箱);启停与设置是 UX 与可维护性手段,**不是安全边界**(同 §13.27 教训:前端开关一定可被绕过)。
**守门与快照**:`tests/architecture-boundary-guard-test.js` 冻结「app.js ↔ src 耦合面」(**83** 项)与 `sourceModules` 顺序(**98** 项);新增模块、新增耦合、新增 dev 探针都**必须有意重生成对应快照**(`IWB_WRITE_BOUNDARY_SNAPSHOT=1`)。契约与行为的可执行验证在 `tests/plugin-host-test.js`(宿主单测)与 `tests/_plugin-host-probe.spec.js`(真实浏览器探针,`_` 前缀 + `iwb-dev-probe`,不进 34 门禁)。
**守门与快照**:`tests/architecture-boundary-guard-test.js` 冻结「app.js ↔ src 耦合面」(**83** 项)与 `sourceModules` 顺序(**99** 项);新增模块、新增耦合、新增 dev 探针都**必须有意重生成对应快照**(`IWB_WRITE_BOUNDARY_SNAPSHOT=1`)。契约与行为的可执行验证在 `tests/plugin-host-test.js`(宿主单测)与 `tests/_plugin-host-probe.spec.js`(真实浏览器探针,`_` 前缀 + `iwb-dev-probe`,不进 34 门禁)。
**关键陷阱**:`normalizeNodes`(现位于 `src/canvas-normalize.js`)会**静默丢弃**不在 `NODE_H` 里的节点类型 ⇒ 新增节点类型必须先登记 `NODE_H`,否则节点一刷新就消失(§13.27 规则三的同一失败模式)。
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "image-workbench-web",
"private": true,
"version": "3.25.73",
"version": "3.25.79",
"description": "Browser-based node canvas image workbench",
"scripts": {
"build": "node scripts/build.js && node scripts/copy-plugins.js",
+1
View File
@@ -95,6 +95,7 @@ const sourceModules = [
'canvas-grid.js',
'image-display-thumb.js',
'image-thumb-pick.js',
'ui-modal-drag.js',
'ui-nav-rail.js',
'ui-plugin-page.js',
'ui-hotkey-help.js',
+16 -4
View File
@@ -54,13 +54,13 @@
<h2>下载</h2>
<div class="row">
<div class="name">macOS · Apple Silicon<div class="hint">M1 / M2 / M3 / M4</div></div>
<div class="meta">版本 3.25.73 · 8.4 MB · .dmg<div class="hash">sha256 33aec504660626e6…</div></div>
<a class="btn" href="/updates/darwin-aarch64/image-workbench_3.25.73_aarch64.dmg?h=33aec5046606">下载</a>
<div class="meta">版本 3.25.79 · 8.4 MB · .dmg<div class="hash">sha256 c812625edf06724a…</div></div>
<a class="btn" href="/updates/darwin-aarch64/image-workbench_3.25.79_aarch64.dmg?h=c812625edf06">下载</a>
</div>
<div class="row">
<div class="name">macOS · Intel<div class="hint">x86_64</div></div>
<div class="meta">版本 3.25.73 · 8.8 MB · .dmg<div class="hash">sha256 bac66718c4e19233…</div></div>
<a class="btn" href="/updates/darwin-x86_64/image-workbench_3.25.73_x64.dmg?h=bac66718c4e1">下载</a>
<div class="meta">版本 3.25.79 · 8.8 MB · .dmg<div class="hash">sha256 770f63ee92ba992c…</div></div>
<a class="btn" href="/updates/darwin-x86_64/image-workbench_3.25.79_x64.dmg?h=770f63ee92ba">下载</a>
</div>
<div class="row">
<div class="name">Windows · x64<div class="hint">需要 WebView2</div></div>
@@ -94,6 +94,18 @@
</ol>
<h2>历史版本</h2>
<div class="row">
<div class="name">3.25.79<div class="hint">Intel 版:同一修复</div></div>
<div class="meta">2026-11-21<div class="hint">macOS · Apple Silicon / macOS · Intel</div></div>
</div>
<div class="row">
<div class="name">3.25.76<div class="hint">Intel 版:同一批改动</div></div>
<div class="meta">2026-11-21<div class="hint">macOS · Apple Silicon / macOS · Intel</div></div>
</div>
<div class="row">
<div class="name">3.25.74<div class="hint">Intel 版:同一批改动</div></div>
<div class="meta">2026-11-21<div class="hint">macOS · Apple Silicon / macOS · Intel</div></div>
</div>
<div class="row">
<div class="name">3.25.73<div class="hint">Intel 版:同一批缩略图改造</div></div>
<div class="meta">2026-11-21<div class="hint">macOS · Apple Silicon / macOS · Intel</div></div>
+7 -7
View File
@@ -2,7 +2,7 @@
<html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>Image Workbench · 本地优先的 AI 生图工作台</title>
<meta name="description" content="本地优先的 AI 生图无限画布:节点式工作流、插件按需安装、数据全部留在本机。">
<link rel="stylesheet" href="/assets/style.css?v=3.25.73-mwpksain">
<link rel="stylesheet" href="/assets/style.css?v=3.25.79-mwpmhqoh">
</head><body>
<nav><div class="wrap inner">
<a class="brand" href="/"><span class="dot">IW</span>Image Workbench</a>
@@ -14,19 +14,19 @@
</div>
<div class="right">
<a class="btn" href="/plugins/">插件市场</a>
<a class="btn primary" href="/download/">下载 v3.25.73</a>
<a class="btn primary" href="/download/">下载 v3.25.79</a>
</div>
</div></nav>
<main>
<section class="hero hero-art">
<div class="hero-bg"><img src="/assets/painting.jpg?v=3.25.73-mwpksain" alt=""></div>
<div class="hero-bg"><img src="/assets/painting.jpg?v=3.25.79-mwpmhqoh" alt=""></div>
<div class="hero-veil"></div>
<div class="wrap">
<span class="kicker">v3.25.73 · macOS / Windows · 数据在本地</span>
<span class="kicker">v3.25.79 · macOS / Windows · 数据在本地</span>
<h1>本地优先的<br>AI 生图无限画布</h1>
<p class="sub">用节点把「参考图 → 提示词 → 批量生成 → 图库」串成一条生产线。<br>图片、提示词、模型配置全部留在你自己的电脑里,插件按需安装。</p>
<div class="cta">
<a class="btn primary lg" href="/download/">下载 v3.25.73</a>
<a class="btn primary lg" href="/download/">下载 v3.25.79</a>
<a class="btn lg" href="/plugins/">浏览 11 个插件</a>
</div>
<div class="meta">支持 macOS 12+ 与 Windows 10 1803+ · 安装包约 7 MB · 无需登录</div>
@@ -93,8 +93,8 @@
<section class="section"><div class="wrap">
<h2>下载 Image Workbench</h2>
<p class="lead">选你的平台。装过一次之后,以后在应用内「设置 → 通用 → 版本与更新」就能一键升级。</p>
<div class="dl"><a href="/updates/darwin-aarch64/image-workbench_3.25.73_aarch64.dmg?h=33aec5046606"><div class="n">macOS · Apple Silicon</div><div class="s">M1 / M2 / M3 / M4 · 8.4 MB · .dmg</div></a>
<a href="/updates/darwin-x86_64/image-workbench_3.25.73_x64.dmg?h=bac66718c4e1"><div class="n">macOS · Intel</div><div class="s">x86_64 · 8.8 MB · .dmg</div></a>
<div class="dl"><a href="/updates/darwin-aarch64/image-workbench_3.25.79_aarch64.dmg?h=c812625edf06"><div class="n">macOS · Apple Silicon</div><div class="s">M1 / M2 / M3 / M4 · 8.4 MB · .dmg</div></a>
<a href="/updates/darwin-x86_64/image-workbench_3.25.79_x64.dmg?h=770f63ee92ba"><div class="n">macOS · Intel</div><div class="s">x86_64 · 8.8 MB · .dmg</div></a>
<div class="none"><div class="n">Windows · x64</div><div class="s">暂未提供</div></div></div>
<div style="margin-top:20px;color:#9ca3af;font-size:12.5px">安装包未做 Apple 公证 / Windows 代码签名,首次打开需手动放行一次,细节见 <a href="/download/" style="text-decoration:underline">下载页</a>。</div>
</div></section>
+2 -2
View File
@@ -1,7 +1,7 @@
<!doctype html>
<html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>插件市场 · Image Workbench</title>
<link rel="stylesheet" href="/assets/style.css?v=3.25.73-mwpksain">
<link rel="stylesheet" href="/assets/style.css?v=3.25.79-mwpmhqoh">
</head><body>
<nav><div class="wrap inner">
<a class="brand" href="/"><span class="dot">IW</span>Image Workbench</a>
@@ -13,7 +13,7 @@
</div>
<div class="right">
<a class="btn" href="/plugins/">插件市场</a>
<a class="btn primary" href="/download/">下载 v3.25.73</a>
<a class="btn primary" href="/download/">下载 v3.25.79</a>
</div>
</div></nav>
<main>
+64 -1
View File
@@ -1,8 +1,71 @@
{
"app": "Image Workbench",
"subtitle": "本地优先的 AI 生图无限画布 · 桌面版(Tauri v2)",
"updatedAt": "2026-11-20T22:53:31.469Z",
"updatedAt": "2026-11-20T23:41:18.454Z",
"releases": [
{
"version": "3.25.79",
"date": "2026-11-21",
"notes": "Intel 版:同一修复",
"platforms": {
"darwin-aarch64": {
"file": "updates/darwin-aarch64/image-workbench_3.25.79_aarch64.dmg",
"size": 8779601,
"sha256": "c812625edf06724a75d73c19f7d7ed34dfd1b1a8593c6348dc1be441b3443548",
"h": "c812625edf06",
"kind": "dmg"
},
"darwin-x86_64": {
"file": "updates/darwin-x86_64/image-workbench_3.25.79_x64.dmg",
"size": 9176984,
"sha256": "770f63ee92ba992cfa02de415ffec6bb91413a148c22a5bfc14ba6032e3e4422",
"h": "770f63ee92ba",
"kind": "dmg"
}
}
},
{
"version": "3.25.76",
"date": "2026-11-21",
"notes": "Intel 版:同一批改动",
"platforms": {
"darwin-aarch64": {
"file": "updates/darwin-aarch64/image-workbench_3.25.76_aarch64.dmg",
"size": 8774580,
"sha256": "33d667a2a7d9a59655ba56d426b6bfa79810d9654f4dba61c3b9ab6101b5bbdf",
"h": "33d667a2a7d9",
"kind": "dmg"
},
"darwin-x86_64": {
"file": "updates/darwin-x86_64/image-workbench_3.25.76_x64.dmg",
"size": 9176270,
"sha256": "983f4219909e5a6071bb09f3b78d1f751dc67a7b01ffbc99ccabfd741d7018d0",
"h": "983f4219909e",
"kind": "dmg"
}
}
},
{
"version": "3.25.74",
"date": "2026-11-21",
"notes": "Intel 版:同一批改动",
"platforms": {
"darwin-aarch64": {
"file": "updates/darwin-aarch64/image-workbench_3.25.74_aarch64.dmg",
"size": 8772912,
"sha256": "9ce709ca908c0b52fe060d5624aa9a414fc3764779006742a7accaea645d4e11",
"h": "9ce709ca908c",
"kind": "dmg"
},
"darwin-x86_64": {
"file": "updates/darwin-x86_64/image-workbench_3.25.74_x64.dmg",
"size": 9175077,
"sha256": "01b7d26aa36fa308543758bcadcde1ed2fdc874391d529df0e51138279785ce3",
"h": "01b7d26aa36f",
"kind": "dmg"
}
}
},
{
"version": "3.25.73",
"date": "2026-11-21",
+1 -1
View File
@@ -1983,7 +1983,7 @@ dependencies = [
[[package]]
name = "image-workbench"
version = "3.25.73"
version = "3.25.79"
dependencies = [
"arboard",
"base64 0.22.1",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "image-workbench"
version = "3.25.73"
version = "3.25.79"
description = "无限画布 · 生图工作台桌面版"
authors = ["malongan"]
license = ""
+44 -1
View File
@@ -149,6 +149,48 @@ fn build_tray(app: &AppHandle) -> tauri::Result<()> {
// 把「资料目录」加进本次运行的 fs scope。
// 为什么需要它:tauri-plugin-fs 的路径白名单是**运行时**的,重启就没了;而资料目录是用户
// 在设置里选的、存在应用配置里 ⇒ 启动时由这里重新授权一次,之后 fs 插件的读写才允许。
/// 当前进程的常驻内存(MB)。用于状态栏显示,方便对比性能改动前后的内存占用。
/// macOS/Linux 用 ps 读 RSS;Windows 用 PowerShell 读 WorkingSet64(作为兜底,轮询间隔 4s 可接受)。
#[tauri::command]
fn app_memory_mb() -> u64 {
let pid = std::process::id();
#[cfg(unix)]
{
let out = std::process::Command::new("ps")
.args(["-o", "rss=", "-p", &pid.to_string()])
.output();
if let Ok(o) = out {
if o.status.success() {
let txt = String::from_utf8_lossy(&o.stdout);
if let Ok(kb) = txt.trim().parse::<u64>() {
return kb / 1024;
}
}
}
0
}
#[cfg(windows)]
{
let script = format!("(Get-Process -Id {}).WorkingSet64", pid);
let out = std::process::Command::new("powershell")
.args(["-NoProfile", "-NonInteractive", "-Command", &script])
.output();
if let Ok(o) = out {
if o.status.success() {
let txt = String::from_utf8_lossy(&o.stdout);
if let Ok(bytes) = txt.trim().parse::<u64>() {
return bytes / (1024 * 1024);
}
}
}
0
}
#[cfg(not(any(unix, windows)))]
{
0
}
}
#[tauri::command]
fn grant_dir(app: AppHandle, dir: String, record: Option<bool>) -> Result<String, String> {
let p = std::path::PathBuf::from(&dir);
@@ -847,7 +889,8 @@ pub fn run() {
.plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_updater::Builder::new().build())
.invoke_handler(tauri::generate_handler![open_app_data_dir, grant_dir, copy_tree, check_update, install_update, clipboard_read_image, clipboard_write_image, clipboard_write_text, clipboard_read_text, open_external_url, open_browser_window, browser_control, browser_state, canvas_webview_ensure, canvas_webview_bounds, canvas_webview_navigate, canvas_webview_action, canvas_webview_state, canvas_webview_close_all, canvas_webview_metrics, notify_desktop])
.invoke_handler(tauri::generate_handler![open_app_data_dir, grant_dir, copy_tree, check_update, install_update, clipboard_read_image, clipboard_write_image, clipboard_write_text, clipboard_read_text, open_external_url, open_browser_window, browser_control, browser_state, canvas_webview_ensure, canvas_webview_bounds, canvas_webview_navigate, canvas_webview_action, canvas_webview_state, canvas_webview_close_all, canvas_webview_metrics, notify_desktop,
app_memory_mb])
.setup(|app| {
if cfg!(debug_assertions) {
app.handle().plugin(
+1 -1
View File
@@ -1,7 +1,7 @@
{
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
"productName": "image-workbench",
"version": "3.25.73",
"version": "3.25.79",
"identifier": "com.malongan.imageworkbench",
"build": {
"frontendDist": "../dist",
+17 -8
View File
@@ -16,10 +16,11 @@
const cache = new Map() // key: gap|dot|color → dataURL
function createTile (gap, dot, color) {
function createTile (gap, dot, color, style) {
if (typeof document === 'undefined') return null
const g = Math.max(4, Math.round(gap))
const key = g + '|' + dot + '|' + color
const st = (style === 'lines') ? 'lines' : 'dots'
const key = g + '|' + dot + '|' + color + '|' + st
const hit = cache.get(key)
if (hit) return hit
try {
@@ -29,9 +30,16 @@
const ctx = cv.getContext('2d')
if (!ctx) return null
ctx.fillStyle = color
ctx.beginPath()
ctx.arc(g / 2, g / 2, Math.max(0.5, dot), 0, Math.PI * 2)
ctx.fill()
if (st === 'lines') {
// 网格线:画右/下两条 1px 线,平铺后即连续网格(v3.25.75)
const w = Math.max(1, Math.round(Math.min(2, dot * 0.6)))
ctx.fillRect(g - w, 0, w, g)
ctx.fillRect(0, g - w, g, w)
} else {
ctx.beginPath()
ctx.arc(g / 2, g / 2, Math.max(0.5, dot), 0, Math.PI * 2)
ctx.fill()
}
const url = cv.toDataURL('image/png')
if (cache.size > 24) cache.clear()
cache.set(key, url)
@@ -44,7 +52,7 @@
const o = opts || {}
const base = Math.max(4, Number(o.base) || 28)
const gap = Math.max(4, base * (Number(scale) > 0 ? Number(scale) : 1))
const url = createTile(gap, o.dot || 1.2, o.color || 'rgba(120,128,140,0.55)')
const url = createTile(gap, o.dot || 1.2, o.color || 'rgba(120,128,140,0.55)', o.style)
if (!url) return null
return {
backgroundImage: 'url(' + url + ')',
@@ -59,12 +67,13 @@
const o = opts || {}
const base = Math.max(4, Number(o.base) || 28)
const gap = Math.max(4, base * (Number(scale) > 0 ? Number(scale) : 1))
const url = createTile(gap, o.dot || 1.2, o.color || 'rgba(120,128,140,0.55)')
const url = createTile(gap, o.dot || 1.2, o.color || 'rgba(120,128,140,0.55)', o.style)
if (url) {
if (el.dataset.gap !== String(gap)) {
if (el.dataset.gap !== String(gap) || el.dataset.style !== String(o.style || 'dots')) {
el.style.backgroundImage = 'url(' + url + ')'
el.style.backgroundSize = gap + 'px ' + gap + 'px'
el.dataset.gap = String(gap)
el.dataset.style = String(o.style || 'dots')
}
el.style.transform = 'translate(' + (x % gap) + 'px, ' + (y % gap) + 'px)'
}
+74 -11
View File
@@ -897,14 +897,37 @@
}
// 画布显示缩略图(768px)落盘:重启后直接命中,不用重新解码 4K 原图
// v3.25.78:缩略图可能是 webp(新)或 jpg(老),按扩展名决定 MIME。
// 旧代码把 WebP 字节写进 _768.jpg 名字里 ⇒ dataURL 声明成 image/jpeg,属于格式错配。
// v3.25.78:缩略图文件名曾把 WebP 写成 .jpg(老 bug),所以 MIME 必须按**魔数**判断,
// 不能只看扩展名,否则 <img> 拿到错 MIME 的 blob 可能渲染成黑块。
function sniffMime (u8) {
try {
if (!u8 || u8.length < 12) return ''
if (u8[0] === 0xFF && u8[1] === 0xD8 && u8[2] === 0xFF) return 'image/jpeg'
if (u8[0] === 0x89 && u8[1] === 0x50 && u8[2] === 0x4E && u8[3] === 0x47) return 'image/png'
if (u8[0] === 0x52 && u8[1] === 0x49 && u8[2] === 0x46 && u8[3] === 0x46 &&
u8[8] === 0x57 && u8[9] === 0x45 && u8[10] === 0x42 && u8[11] === 0x50) return 'image/webp'
if (u8[0] === 0x47 && u8[1] === 0x49 && u8[2] === 0x46) return 'image/gif'
} catch (e) { /* ignore */ }
return ''
}
async function thumbFileOf (hash) {
const base = await join(dir, IMG_DIR, 'thumbs', String(hash) + '_768')
for (const ext of ['.webp', '.jpg']) {
try { if (await fs().exists(base + ext)) return { path: base + ext, mime: ext === '.webp' ? 'image/webp' : 'image/jpeg' } } catch (e) { /* ignore */ }
}
return null
}
async function readDisplayThumb(hash) {
try {
if (!enabled() || !dir || !hash) return ''
const abs = await join(dir, IMG_DIR, 'thumbs', String(hash) + '_768.jpg')
if (!(await fs().exists(abs))) return ''
const u8 = await fs().readFile(abs)
const f = await thumbFileOf(hash)
if (!f) return ''
const u8 = await fs().readFile(f.path)
if (!u8 || !u8.length) return ''
return bytesToDataUrl('image/jpeg', u8)
return bytesToDataUrl(sniffMime(u8) || f.mime, u8)
} catch (e) { return '' }
}
// v3.25.73:缩略图以 Blob + objectURL 交给显示层(避免 dataURL 常驻 JS 堆)
@@ -914,21 +937,61 @@
if (!enabled() || !dir || !hash) return ''
const hit = thumbUrlCache.get(String(hash))
if (hit) return hit
const abs = await join(dir, IMG_DIR, 'thumbs', String(hash) + '_768.jpg')
if (!(await fs().exists(abs))) return ''
const u8 = await fs().readFile(abs)
const f = await thumbFileOf(hash)
if (!f) return ''
const u8 = await fs().readFile(f.path)
if (!u8 || !u8.length) return ''
const url = URL.createObjectURL(new Blob([u8], { type: 'image/jpeg' }))
const url = URL.createObjectURL(new Blob([u8], { type: sniffMime(u8) || f.mime }))
thumbUrlCache.set(String(hash), url)
if (thumbUrlCache.size > 400) { const k = thumbUrlCache.keys().next().value; try { URL.revokeObjectURL(thumbUrlCache.get(k)) } catch (e) {} ; thumbUrlCache.delete(k) }
// 不 revoke:这个 URL 可能正在被画布上的 <img> 使用,撤销会变成黑块/破图。
if (thumbUrlCache.size > 600) { const k = thumbUrlCache.keys().next().value; try { thumbUrlCache.delete(k) } catch (e) { /* ignore */ } }
return url
} catch (e) { return '' }
}
// v3.25.78:缩略图没有回收机制,历史上会无限增长(实测 470 个 / 67MB)。
// 这里按总大小封顶(默认 300MB,超了删最老的 20%),缩略图可再生,删掉不影响数据。
async function pruneThumbs (maxMB) {
try {
if (!enabled() || !dir) return 0
const cap = Math.max(50, Number(maxMB) || 300) * 1024 * 1024
const tdir = await join(dir, IMG_DIR, 'thumbs')
if (!(await fs().exists(tdir))) return 0
const names = await fs().readDir(tdir)
const files = []
let total = 0
for (const e of names) {
const name = e && (e.name || e)
if (!name || !/_768\.(webp|jpg)$/i.test(String(name))) continue
const abs = await join(tdir, String(name))
try {
const st = await fs().stat(abs)
const size = (st && st.size) || 0
total += size
files.push({ abs, size, mtime: (st && st.mtime) ? new Date(st.mtime).getTime() : 0 })
} catch (err) { /* ignore */ }
}
if (total <= cap) return 0
files.sort((a, b) => a.mtime - b.mtime)
const target = cap * 0.8
let removed = 0
for (const f of files) {
if (total <= target) break
try { await fs().remove(f.abs); total -= f.size; removed++ } catch (e) { /* ignore */ }
}
return removed
} catch (e) { return 0 }
}
async function writeDisplayThumbBlob(hash, blob) {
try {
if (!enabled() || !dir || !hash || !blob) return false
const abs = await join(dir, IMG_DIR, 'thumbs', String(hash) + '_768.jpg')
const isWebp = String(blob.type || '').indexOf('webp') >= 0
const abs = await join(dir, IMG_DIR, 'thumbs', String(hash) + '_768' + (isWebp ? '.webp' : '.jpg'))
if (await fs().exists(abs)) return true
try {
const other = await join(dir, IMG_DIR, 'thumbs', String(hash) + '_768' + (isWebp ? '.jpg' : '.webp'))
if (await fs().exists(other)) return true
} catch (e) { /* ignore */ }
await fs().mkdir(await join(dir, IMG_DIR, 'thumbs'), { recursive: true })
const buf = new Uint8Array(await blob.arrayBuffer())
await fs().writeFile(abs, buf)
@@ -1034,7 +1097,7 @@
}
global.IWBStorageFile = {
enabled, ready: init, flush, runtime, pickDir, switchTo, migrateTo, gcImages, rotateTrash, galleryThumb, readDisplayThumb, readDisplayThumbUrl, writeDisplayThumb, writeDisplayThumbBlob,
enabled, ready: init, flush, runtime, pickDir, switchTo, migrateTo, gcImages, rotateTrash, galleryThumb, readDisplayThumb, readDisplayThumbUrl, writeDisplayThumb, writeDisplayThumbBlob, pruneThumbs,
plugins: { manifest: pluginManifest, read: pluginRead, write: pluginWrite, remove: pluginRemove, dir: pluginDir, listLocal: pluginListLocal, listDirs: pluginListDirs, readFile: pluginReadFile, writeFile: pluginWriteFile, writeBinary: pluginWriteBinary, mkdir: pluginMkdir, removeDir: pluginRemoveDir, renameDir: pluginRenameDir, existsDir: pluginExistsDir },
pluginData: { read: pluginDataRead, write: pluginDataWrite, remove: pluginDataRemove, list: pluginDataList },
storage: () => storage,
+1
View File
@@ -62,6 +62,7 @@
onClick: () => { setSettingTabReq('diag'); setSettingOpen(true) },
}, '内存 ' + memUi.usedMB + '/' + memUi.limitMB + 'MB ' + Math.round((memUi.ratio || 0) * 100) + '%') : null,
saveState !== 'idle' ? el('span', { className: 'iwb-status-item iwb-status-save iwb-status-' + (saveState === 'error' ? 'err' : 'ok') }, saveState === 'saving' ? el('span', { className: 'iwb-save-spinner' }, null) : null, saveText) : null,
(props.memMb && props.memMb > 0) ? el('span', { className: 'iwb-status-item iwb-status-mem', title: '当前进程常驻内存(含画布图片缓存)' }, '内存 ' + props.memMb + 'MB') : null,
notice ? el('span', { className: 'iwb-status-item iwb-status-' + (notice.type === 'err' ? 'err' : 'ok') }, notice.text) : null,
(() => {
const activeKeys = Object.keys(busy).filter((k) => busy[k])
+106 -71
View File
@@ -14,7 +14,7 @@
const DEFAULTS = Object.freeze({
canvasBgLight: '#d9dbde', canvasBgDark: '#6f6f6f',
gridDotLight: '#c9ccd6', gridDotDark: '#8f8f8f', gridSize: 1.4, gridGap: 22, gridOn: true,
gridDotLight: '#c9ccd6', gridDotDark: '#8f8f8f', gridSize: 1.4, gridGap: 22, gridOn: true, gridStyle: 'dots',
edgeColorLight: '#b9bfca', edgeColorDark: '#7a7a7a',
edgeWidth: 1.8, edgeDash: 'dashed',
edgeHotLight: '#6b7280', edgeHotDark: '#ffffff',
@@ -49,6 +49,11 @@
gridSize: clamp(c.gridSize, 0.8, 2.6, DEFAULTS.gridSize),
gridGap: clamp(c.gridGap, 16, 40, DEFAULTS.gridGap),
gridOn: c.gridOn !== false,
gridStyle: (function () {
const st = String(c.gridStyle || '')
if (st === 'dots' || st === 'lines' || st === 'blank') return st
return (c.gridOn === false) ? 'blank' : 'dots'
})(),
edgeColorLight: hex('edgeColorLight'), edgeColorDark: hex('edgeColorDark'),
edgeWidth: clamp(c.edgeWidth, 1, 4, DEFAULTS.edgeWidth),
edgeDash: DASH[c.edgeDash] ? c.edgeDash : DEFAULTS.edgeDash,
@@ -73,7 +78,9 @@
set('--iwb-grid-dot', dark ? a.gridDotDark : a.gridDotLight)
set('--iwb-grid-size', a.gridSize + 'px')
set('--iwb-grid-gap', a.gridGap + 'px')
set('--iwb-grid-on', a.gridOn ? '1' : '0')
const gs = a.gridStyle || 'dots'
set('--iwb-grid-on', (gs !== 'blank' && a.gridOn !== false) ? '1' : '0')
try { root.setAttribute('data-iwb-grid', gs) } catch (e) { /* ignore */ }
set('--iwb-edge', dark ? a.edgeColorDark : a.edgeColorLight)
set('--iwb-edge-w', a.edgeWidth + 'px')
set('--iwb-edge-dash', DASH[a.edgeDash] || DASH.dashed)
@@ -201,6 +208,10 @@
{ name: '纸质', values: { canvasBgLight: '#efe7d7', canvasBgDark: '#3b3227', gridDotLight: '#d8cbb4', gridDotDark: '#5a4c3d', edgeColorLight: '#b9a88c', edgeColorDark: '#a2917a', edgeDash: 'solid', accent: '#8a6f4a', edgeHotLight: '#8a6f4a', edgeHotDark: '#e0c9a0', nodeBgLight: '#faf6ee', nodeBgDark: '#4a4034', nodeBorderLight: '#ddd0b8', nodeBorderDark: '#6b5c49' } },
]
// ── 外观面板(v3.25.75 重构)───────────────────────────────────────────────
// 用户反馈:分组混乱、颜色字段看不出可点、网格三项无效、对比度警告刷屏。
// 现在:4 个分组(主题 / 画布 / 连线 / 节点),统一两栏网格(标签 120px + 控件),
// 每组组头右侧「恢复本组默认」;颜色统一为「色块 + hex + ▾」;警告收进行尾。
function AppearanceTab (props) {
const draft = (props && props.draft) || {}
const setDraft = (props && props.setDraft) || function () {}
@@ -211,14 +222,56 @@
const set = (patch) => setDraft((d) => Object.assign({}, d, {
canvas: Object.assign({}, d.canvas, { appearance: Object.assign({}, normalize(d), patch) }),
}))
const setMany = (patch) => set(patch)
const resetGroup = (keys) => { const p = {}; for (const k of keys) p[k] = DEFAULTS[k]; set(p) }
const warnEdge = (edge, bg) => {
const r = contrast(edge, bg)
return r < 1.5 ? el('div', { className: 'iwb-hint iwb-hint-warn' }, '连线与画布底色对比度仅 ' + r.toFixed(1) + ':1,可能看不清') : null
}
const importRef = React.useRef(null)
const Row = function (label, control, note) {
return el('div', { className: 'iwb-appear-row' + (note ? ' iwb-appear-row-note' : '') },
el('span', { className: 'iwb-appear-label', title: label }, label),
el('div', { className: 'iwb-appear-ctrl' }, control),
note ? el('span', { className: 'iwb-appear-note' }, note) : null)
}
const Group = function (title, rows, keys) {
return el('section', { className: 'iwb-appear-group' },
el('div', { className: 'iwb-appear-ghead' },
el('span', { className: 'iwb-appear-gtitle' }, title),
keys ? el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => resetGroup(keys) }, '恢复本组默认') : null),
rows)
}
const Seg = function (val, onChange, items) {
return el('div', { className: 'iwb-seg' }, (items || []).map((item) => el('button', {
key: item.value,
type: 'button',
className: 'iwb-seg-item' + (val === item.value ? ' on' : ''),
onClick: () => onChange(item.value),
}, item.label)))
}
const warnOf = function (edge, bg) {
const r = contrast(edge, bg)
return r < 1.5 ? ('⚠ 对比度 ' + r.toFixed(1) + ':1,可能看不清') : ''
}
// 主题下拉:配色模式 + 全部预设合并(用户裁定:合并)
const themeOptions = [{ value: 'theme:light', label: '亮色(节点灰底 + 内容白)' }, { value: 'theme:dark', label: '暗色' }, { value: 'theme:system', label: '跟随系统' }]
const presetOptions = PRESETS.map((p) => ({ value: 'preset:' + p.name, label: '预设 · ' + p.name }))
.concat(value.presets.map((p, i) => ({ value: 'preset-c:' + i, label: '预设 · ' + p.name })))
const onThemePick = (raw) => {
if (raw.indexOf('theme:') === 0) {
const t = raw.slice(6)
const v = (t === 'dark' || t === 'system') ? t : 'light'
setTheme(v); applyTheme(v); return
}
if (raw.indexOf('preset-c:') === 0) {
const p = value.presets[Number(raw.slice(9)) || 0]
if (p && p.values) set(normalize({ canvas: { appearance: p.values } }))
return
}
if (raw.indexOf('preset:') === 0) {
const name = raw.slice(7)
const p = PRESETS.find((x) => x.name === name)
if (p) set(Object.assign({}, DEFAULTS, p.values))
}
}
const exportPresets = () => {
try {
const doc = { version: 1, appearance: Object.assign({}, value, { presets: undefined }) }
@@ -245,25 +298,14 @@
} catch (e) { /* ignore */ }
}
return el('div', null,
el('div', { className: 'iwb-section-sub' }, '界面主题'),
el('div', { className: 'iwb-row' },
el('span', { className: 'iwb-label' }, '配色模式'),
el('select', {
className: 'iwb-input', title: '界面配色(亮色保证文字清晰)', value: theme,
onChange: (e) => { const t = e.target.value; const v = (t === 'dark' || t === 'system') ? t : 'light'; setTheme(v); applyTheme(v) },
},
el('option', { value: 'light' }, '亮色(默认:节点灰底 + 内容白)'),
el('option', { value: 'dark' }, '暗色'),
el('option', { value: 'system' }, '跟随系统'),
)),
el('div', { className: 'iwb-section-sub' }, '预设'),
el('div', { className: 'iwb-appear-presets' },
PRESETS.map((p) => el('button', { key: p.name, className: 'iwb-btn iwb-btn-sm', onClick: () => setMany(Object.assign({}, DEFAULTS, p.values)), title: '套用「' + p.name + '」' }, p.name)),
value.presets.map((p, i) => el('button', { key: 'c' + i, className: 'iwb-btn iwb-btn-sm', onClick: () => set(normalize({ canvas: { appearance: p.values } })), title: '套用自定义预设' }, p.name || ('自定义 ' + (i + 1)))),
),
el('div', { className: 'iwb-row' },
const themeGroup = Group('主题', [
Row('主题', el('select', {
className: 'iwb-input iwb-appear-select', value: 'theme:' + theme,
onChange: (e) => onThemePick(e.target.value),
}, themeOptions.concat(presetOptions).map((o) => el('option', { key: o.value, value: o.value }, o.label))),
'切换配色模式或直接套用预设'),
Row('主题色', el(ColorPicker, { value: value.accent, onChange: (v) => set({ accent: v }) }), '按钮 / 端口 / 选中框'),
Row('预设', el('div', { className: 'iwb-appear-btns' },
el('button', {
className: 'iwb-btn iwb-btn-sm',
onClick: () => {
@@ -273,55 +315,48 @@
set({ presets: value.presets.concat([{ name: String(name).slice(0, 20), values: snap }]).slice(0, 12) })
},
}, '保存当前为预设'),
el('button', { className: 'iwb-btn iwb-btn-sm', onClick: exportPresets }, '导出外观'),
el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => importRef.current && importRef.current.click() }, '导入外观'),
el('input', { ref: importRef, type: 'file', accept: 'application/json', style: { display: 'none' }, onChange: (e) => { const f = e.target.files && e.target.files[0]; if (f) importFile(f); e.target.value = '' } }),
),
el('button', { className: 'iwb-btn iwb-btn-sm', onClick: exportPresets }, '导出'),
el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => importRef.current && importRef.current.click() }, '导入'),
el('input', { ref: importRef, type: 'file', accept: 'application/json', style: { display: 'none' }, onChange: (e) => { const f = e.target.files && e.target.files[0]; if (f) importFile(f) } }))),
], null)
el('div', { className: 'iwb-section-sub' }, '画布'),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '底色(亮)'), el(ColorPicker, { value: value.canvasBgLight, onChange: (v) => set({ canvasBgLight: v }) })),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '底色(暗)'), el(ColorPicker, { value: value.canvasBgDark, onChange: (v) => set({ canvasBgDark: v }) })),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '网格点(亮)'), el(ColorPicker, { value: value.gridDotLight, onChange: (v) => set({ gridDotLight: v }) })),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '网格点(暗)'), el(ColorPicker, { value: value.gridDotDark, onChange: (v) => set({ gridDotDark: v }) })),
el(NumberRow, { label: '网格点大小', value: value.gridSize, min: 0.8, max: 2.6, step: 0.1, unit: 'px', onChange: (v) => set({ gridSize: v }) }),
el(NumberRow, { label: '网格间距', value: value.gridGap, min: 16, max: 40, step: 1, unit: 'px', onChange: (v) => set({ gridGap: v }) }),
el('label', { className: 'iwb-check' }, el('input', { type: 'checkbox', checked: value.gridOn, onChange: (e) => set({ gridOn: e.target.checked }) }, null), ' 显示网格'),
el('div', { className: 'iwb-row' }, el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => resetGroup(['canvasBgLight', 'canvasBgDark', 'gridDotLight', 'gridDotDark', 'gridSize', 'gridGap', 'gridOn']) }, '恢复本组默认')),
const canvasGroup = Group('画布', [
Row('网格样式', Seg(value.gridStyle, (v) => set({ gridStyle: v, gridOn: v !== 'blank' }), [
{ value: 'dots', label: '点' }, { value: 'lines', label: '线' }, { value: 'blank', label: '空白' },
]), '空白 = 不显示背景网格'),
Row('底色(亮)', el(ColorPicker, { value: value.canvasBgLight, onChange: (v) => set({ canvasBgLight: v }) })),
Row('底色(暗)', el(ColorPicker, { value: value.canvasBgDark, onChange: (v) => set({ canvasBgDark: v }) })),
Row(value.gridStyle === 'lines' ? '网格线色(亮)' : '网格点(亮)', el(ColorPicker, { value: value.gridDotLight, onChange: (v) => set({ gridDotLight: v }) })),
Row(value.gridStyle === 'lines' ? '网格线色(暗)' : '网格点(暗)', el(ColorPicker, { value: value.gridDotDark, onChange: (v) => set({ gridDotDark: v }) })),
Row(value.gridStyle === 'lines' ? '网格线粗细' : '网格点大小', el('input', { type: 'range', min: 0.8, max: 2.6, step: 0.1, value: value.gridSize, className: 'iwb-appear-range', onChange: (e) => set({ gridSize: Number(e.target.value) }) }),
String(value.gridSize) + 'px'),
Row('网格间距', el('input', { type: 'range', min: 16, max: 40, step: 1, value: value.gridGap, className: 'iwb-appear-range', onChange: (e) => set({ gridGap: Number(e.target.value) }) }),
String(value.gridGap) + 'px'),
], ['canvasBgLight', 'canvasBgDark', 'gridDotLight', 'gridDotDark', 'gridSize', 'gridGap', 'gridOn', 'gridStyle'])
el('div', { className: 'iwb-section-sub' }, '连线'),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '默认色(亮)'), el(ColorPicker, { value: value.edgeColorLight, onChange: (v) => set({ edgeColorLight: v }) })),
warnEdge(value.edgeColorLight, value.canvasBgLight),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '默认色(暗)'), el(ColorPicker, { value: value.edgeColorDark, onChange: (v) => set({ edgeColorDark: v }) })),
warnEdge(value.edgeColorDark, value.canvasBgDark),
el(NumberRow, { label: '默认粗细', value: value.edgeWidth, min: 1, max: 4, step: 0.1, unit: 'px', onChange: (v) => set({ edgeWidth: v }) }),
el('div', { className: 'iwb-row' },
el('span', { className: 'iwb-label' }, '线型'),
el('select', { className: 'iwb-input', value: value.edgeDash, onChange: (e) => set({ edgeDash: e.target.value }) },
el('option', { value: 'solid' }, '实线'),
el('option', { value: 'dashed' }, '虚线'),
el('option', { value: 'dotted' }, '点线'),
)),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '高亮色(亮)'), el(ColorPicker, { value: value.edgeHotLight, onChange: (v) => set({ edgeHotLight: v }) })),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '高亮色(暗)'), el(ColorPicker, { value: value.edgeHotDark, onChange: (v) => set({ edgeHotDark: v }) })),
el('div', { className: 'iwb-hint' }, '高亮色只用于选中节点的上下游连线、悬停连线与临时连线;默认连线永远用上面的「默认色」。'),
el('div', { className: 'iwb-row' }, el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => resetGroup(['edgeColorLight', 'edgeColorDark', 'edgeWidth', 'edgeDash', 'edgeHotLight', 'edgeHotDark']) }, '恢复本组默认')),
const edgeGroup = Group('连线', [
Row('默认色(亮)', el(ColorPicker, { value: value.edgeColorLight, onChange: (v) => set({ edgeColorLight: v }) }), warnOf(value.edgeColorLight, value.canvasBgLight)),
Row('默认色(暗)', el(ColorPicker, { value: value.edgeColorDark, onChange: (v) => set({ edgeColorDark: v }) }), warnOf(value.edgeColorDark, value.canvasBgDark)),
Row('粗细', el('input', { type: 'range', min: 1, max: 4, step: 0.1, value: value.edgeWidth, className: 'iwb-appear-range', onChange: (e) => set({ edgeWidth: Number(e.target.value) }) }), String(value.edgeWidth) + 'px'),
Row('线型', el('select', { className: 'iwb-input iwb-appear-select', value: value.edgeDash, onChange: (e) => set({ edgeDash: e.target.value }) },
el('option', { value: 'solid' }, '实线'), el('option', { value: 'dashed' }, '虚线'), el('option', { value: 'dotted' }, '点线'))),
Row('高亮色(亮)', el(ColorPicker, { value: value.edgeHotLight, onChange: (v) => set({ edgeHotLight: v }) }), '仅选中/悬停/临时连线'),
Row('高亮色(暗)', el(ColorPicker, { value: value.edgeHotDark, onChange: (v) => set({ edgeHotDark: v }) })),
], ['edgeColorLight', 'edgeColorDark', 'edgeWidth', 'edgeDash', 'edgeHotLight', 'edgeHotDark'])
el('div', { className: 'iwb-section-sub' }, '节点'),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '节点底色(亮)'), el(ColorPicker, { value: value.nodeBgLight, onChange: (v) => set({ nodeBgLight: v }) })),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '节点底色(暗)'), el(ColorPicker, { value: value.nodeBgDark, onChange: (v) => set({ nodeBgDark: v }) })),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '边框色(亮)'), el(ColorPicker, { value: value.nodeBorderLight, onChange: (v) => set({ nodeBorderLight: v }) })),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '边框色(暗)'), el(ColorPicker, { value: value.nodeBorderDark, onChange: (v) => set({ nodeBorderDark: v }) })),
el(NumberRow, { label: '节点圆角', value: value.nodeRadius, min: 6, max: 20, step: 1, unit: 'px', onChange: (v) => set({ nodeRadius: v }) }),
el(NumberRow, { label: '选中描边', value: value.nodeSelWidth, min: 1, max: 4, step: 0.5, unit: 'px', onChange: (v) => set({ nodeSelWidth: v }) }),
el('div', { className: 'iwb-row' }, el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => resetGroup(['nodeBgLight', 'nodeBgDark', 'nodeBorderLight', 'nodeBorderDark', 'nodeRadius', 'nodeSelWidth']) }, '恢复本组默认')),
el('div', { className: 'iwb-section-sub' }, '主题色'),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '按钮 / 端口 / 选中框'), el(ColorPicker, { value: value.accent, onChange: (v) => set({ accent: v }) })),
el('div', { className: 'iwb-hint' }, '主题色同时用于亮色与暗色主题;作用在按钮、端口、选中框与进度动画上。连线用上面的「连线」分组。'),
const nodeGroup = Group('节点', [
Row('节点底色(亮)', el(ColorPicker, { value: value.nodeBgLight, onChange: (v) => set({ nodeBgLight: v }) })),
Row('节点底色(暗)', el(ColorPicker, { value: value.nodeBgDark, onChange: (v) => set({ nodeBgDark: v }) })),
Row('边框色(亮)', el(ColorPicker, { value: value.nodeBorderLight, onChange: (v) => set({ nodeBorderLight: v }) })),
Row('边框色(暗)', el(ColorPicker, { value: value.nodeBorderDark, onChange: (v) => set({ nodeBorderDark: v }) })),
Row('节点圆角', el('input', { type: 'range', min: 6, max: 20, step: 1, value: value.nodeRadius, className: 'iwb-appear-range', onChange: (e) => set({ nodeRadius: Number(e.target.value) }) }), String(value.nodeRadius) + 'px'),
Row('选中描边', el('input', { type: 'range', min: 1, max: 4, step: 0.5, value: value.nodeSelWidth, className: 'iwb-appear-range', onChange: (e) => set({ nodeSelWidth: Number(e.target.value) }) }), String(value.nodeSelWidth) + 'px'),
], ['nodeBgLight', 'nodeBgDark', 'nodeBorderLight', 'nodeBorderDark', 'nodeRadius', 'nodeSelWidth'])
return el('div', { className: 'iwb-appear' },
themeGroup, canvasGroup, edgeGroup, nodeGroup,
el('div', { className: 'iwb-row', style: { marginTop: 12 } },
el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => setMany(Object.assign({}, DEFAULTS, { presets: value.presets })) }, '全部恢复默认')),
)
el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => set(Object.assign({}, DEFAULTS, { presets: value.presets })) }, '全部恢复默认')))
}
g.IWBUIApearance = Object.freeze({ DEFAULTS, PRESETS, DASH, normalize, apply, contrast, ColorPicker, AppearanceTab })
+64
View File
@@ -0,0 +1,64 @@
/* ui-modal-drag.js —— 弹窗拖动 + 外观实时预览(v3.25.76)
*
* 为什么单独成模块:src 里单组件行数有上限(SettingsModal 已接近上限),
* 这两个都是与具体弹窗无关的通用行为,抽出来也便于别处复用。
*/
;(function (global) {
'use strict'
const React = global.React || {}
const el = (t, p, ...c) => React.createElement(t, p, ...c)
// 拖动标题栏移动弹窗;位置限制在视口内(至少留 120×60 可见)
function useDraggableModal () {
const [pos, setPos] = React.useState(null)
const dragRef = React.useRef(null)
const onHeadPointerDown = (e) => {
if (e.button !== 0) return
const host = e.currentTarget && e.currentTarget.closest ? e.currentTarget.closest('.iwb-modal') : null
if (!host) return
const r = host.getBoundingClientRect()
dragRef.current = { x: e.clientX, y: e.clientY, left: r.left, top: r.top }
const move = (ev) => {
const d = dragRef.current
if (!d) return
const left = Math.max(8, Math.min((global.innerWidth || 1200) - 120, d.left + (ev.clientX - d.x)))
const top = Math.max(8, Math.min((global.innerHeight || 800) - 60, d.top + (ev.clientY - d.y)))
setPos({ left, top })
}
const up = () => {
dragRef.current = null
global.removeEventListener('pointermove', move)
global.removeEventListener('pointerup', up)
}
global.addEventListener('pointermove', move)
global.addEventListener('pointerup', up)
e.preventDefault()
}
const style = pos ? { position: 'fixed', left: pos.left + 'px', top: pos.top + 'px', margin: 0, transform: 'none' } : undefined
return { pos, style, onHeadPointerDown }
}
// 外观实时预览:draft 变化 → 立刻写 CSS 变量 + 通知画布重渲染;关闭未保存则回滚
function useAppearancePreview (opts) {
const o = opts || {}
const savedRef = React.useRef(o.savedConfig || o.config || null)
const themeRef = React.useRef(o.dark ? 'dark' : 'light')
React.useEffect(() => { themeRef.current = o.dark ? 'dark' : 'light' }, [o.dark])
React.useEffect(() => {
if (!o.enabled) return
const A = global.IWBUIApearance
if (!A || typeof A.apply !== 'function') return
try { A.apply(o.config, !!(o.dark)) } catch (e) { /* ignore */ }
try { global.dispatchEvent(new Event('iwb:appearance')) } catch (e) { /* ignore */ }
}, [o.enabled, o.dark, o.config])
React.useEffect(() => () => {
const A = global.IWBUIApearance
if (!A || typeof A.apply !== 'function') return
try { A.apply(savedRef.current, themeRef.current === 'dark') } catch (e) { /* ignore */ }
try { global.dispatchEvent(new Event('iwb:appearance')) } catch (e) { /* ignore */ }
}, [])
return { markSaved: () => { savedRef.current = o.config || null } }
}
global.IWBUIModalDrag = { useDraggableModal, useAppearancePreview }
})(typeof window !== 'undefined' ? window : globalThis)
+3 -3
View File
@@ -692,7 +692,7 @@
return el('div', { className: 'iwb-node-body iwb-ref-body' },
hasImg
? el('div', { className: 'iwb-ref-show' },
el('img', { className: 'iwb-ref-single', loading: 'lazy', decoding: 'async', fetchPriority: 'low', src: wPreviewUrlOf((typeof wImgSrcForNode === 'function' ? wImgSrcForNode : wDisplayThumbOf)(wThumbSrc(src), Math.min(320, (props.node && props.node.w) || 280))), alt: '图片', draggable: false, title: '双击放大 · 单击可拖动' }),
el('img', { className: 'iwb-ref-single', decoding: 'async', fetchPriority: 'low', src: wPreviewUrlOf((typeof wImgSrcForNode === 'function' ? wImgSrcForNode : wDisplayThumbOf)(wThumbSrc(src), Math.min(320, (props.node && props.node.w) || 280))), alt: '图片', draggable: false, onError: (e) => { try { const ov = wThumbSrc(src); if (ov && e.currentTarget && e.currentTarget.src !== ov) e.currentTarget.src = ov } catch (err) { /* ignore */ } }, title: '双击放大 · 单击可拖动' }),
(typeof d.url === 'string' && d.url) ? el('div', { className: 'iwb-ref-url-current', title: d.url }, 'URL 图片') : null,
)
: el('div', { className: 'iwb-ref-emptybox', title: '单击选中 · 双击上传图片', onDoubleClick: (e) => { e.stopPropagation(); if (refFileInput) refFileInput.click() } },
@@ -830,7 +830,7 @@
// React 会按下标复用同一个 DOM 节点,先显示上一张、再等新图解码 ⇒ 肉眼看到「闪一下旧图/空图」。
// url 稳定 ⇒ 节点复用(不重建、不重新解码);url 变了才新建,内容永远对得上。
return el('div', { key: String(r.url || '') + '|' + ri, className: 'iwb-out-cell' },
el('img', { key: 'out-img-' + cur + '-' + String(r.url || '').slice(-48), className: 'iwb-out-cell-img', loading: 'lazy', decoding: 'async', fetchPriority: 'low', referrerPolicy: 'no-referrer', src: wPreviewUrlOf((typeof wImgSrcForNode === 'function' ? wImgSrcForNode : wDisplayThumbOf)(thumbOf(r), Math.max(120, Math.min(360, (node && node.w ? node.w - 40 : 240))))), draggable: false, 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 }, onClick: () => openPreviewAt(cur) }),
el('img', { key: 'out-img-' + cur + '-' + String(r.url || '').slice(-48), className: 'iwb-out-cell-img', decoding: 'async', fetchPriority: 'low', referrerPolicy: 'no-referrer', src: wPreviewUrlOf((typeof wImgSrcForNode === 'function' ? wImgSrcForNode : wDisplayThumbOf)(thumbOf(r), Math.max(120, Math.min(360, (node && node.w ? node.w - 40 : 240))))), draggable: false, 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 }, onClick: () => openPreviewAt(cur) }),
el('div', { className: 'iwb-out-cell-meta' }, (r.width || '?') + '×' + (r.height || '?')),
el('div', { className: 'iwb-out-cell-actions' },
el('button', { className: 'iwb-btn iwb-btn-sm', title: '插入为参考图节点', onClick: () => props.onCopyRef && props.onCopyRef(r.url), onPointerDown: stop }, I('copy')),
@@ -1152,7 +1152,7 @@
if (src) {
return el('div', { className: 'iwb-node-body iwb-node-body-lod iwb-lod-lite iwb-lod-img' },
// 缩略图不参与点击(节点本体负责选中/拖动),所以不挂事件;alt 留空由 CSS 兜底尺寸
el('img', { className: 'iwb-lod-thumb', src: wDisplayThumbOf(src), loading: 'lazy', decoding: 'async', draggable: false, alt: '' }),
el('img', { className: 'iwb-lod-thumb', src: wDisplayThumbOf(src), decoding: 'async', draggable: false, alt: '' }),
)
}
return el('div', { className: 'iwb-node-body iwb-node-body-lod iwb-lod-lite iwb-lod-img' }, null)
+10 -4
View File
@@ -559,11 +559,17 @@ function SettingsModal(props) {
isDesk() ? null : autoBackupSection,
)
// 可拖动窗口 + 外观实时预览(实现见 src/ui-modal-drag.js)
const MD = (typeof window !== 'undefined') ? window.IWBUIModalDrag : null
const dragKit = (MD && MD.useDraggableModal) ? MD.useDraggableModal() : null
const appearanceKit = (MD && MD.useAppearancePreview) ? MD.useAppearancePreview({ enabled: tab === 'appearance', config: draft, dark: theme === 'dark', savedConfig: props.config || null }) : null
const winStyle = dragKit ? dragKit.style : undefined
const onHeadPointerDown = dragKit ? dragKit.onHeadPointerDown : null
// 顺序:通用放最前(最常用:目录/外观/图片图库/生成),其它按使用频率排
const tabs = [['general', '通用'], ['appearance', '外观'], ['gen', '生图服务'], ['llm', 'LLM 服务'], ['img', '图片传输'], ['sizes', '尺寸预设'], ['hotkeys', '快捷键'], ['backup', '备份与还原'], ['diag', '诊断'], ['plugins', '插件']]
return el('div', { className: 'iwb-modal-mask', onWheel: (e) => e.stopPropagation(), onPointerDown: (e) => { if (e.target === e.currentTarget) props.onClose() } },
el('div', { className: 'iwb-modal iwb-settings-modal' },
el('div', { className: 'iwb-modal-head' },
return el('div', { className: 'iwb-modal-mask iwb-mask-ghost', onWheel: (e) => e.stopPropagation(), onPointerDown: (e) => { if (e.target === e.currentTarget) props.onClose() } },
el('div', { className: 'iwb-modal iwb-settings-modal' + ((dragKit && dragKit.pos) ? ' iwb-modal-floating' : ''), style: winStyle },
el('div', { className: 'iwb-modal-head iwb-modal-draghead', onPointerDown: onHeadPointerDown, title: '按住拖动窗口' },
el('span', { className: 'iwb-toolbar-title' }, '⚙️ 设置'),
el('button', { className: 'iwb-btn iwb-btn-sm', title: '关闭', onClick: props.onClose }, I('x')),
),
@@ -584,7 +590,7 @@ function SettingsModal(props) {
),
),
el('div', { className: 'iwb-modal-foot' },
el('button', { className: 'iwb-btn iwb-btn-primary', disabled: saving, onClick: save }, saving ? '保存中…' : '保存配置'),
el('button', { className: 'iwb-btn iwb-btn-primary', disabled: saving, onClick: () => { try { if (appearanceKit) appearanceKit.markSaved() } catch (e) { /* ignore */ } ; if (save) save() } }, saving ? '保存中…' : '保存配置'),
),
),
)
+34 -1
View File
@@ -2095,7 +2095,9 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s
.iwb-cpick { position: relative; display: inline-flex; align-items: center; gap: 8px; }
.iwb-cpick-swatch { display: inline-flex; align-items: center; justify-content: center; min-width: 92px; height: 28px; padding: 0 10px; border-radius: 6px; border: 1px solid var(--iwb-border); cursor: pointer; font-size: 11px; letter-spacing: .04em; }
.iwb-cpick-swatch:hover { border-color: var(--iwb-border2); }
.iwb-cpick-hex { mix-blend-mode: difference; }
.iwb-cpick-hex { font-variant-numeric: tabular-nums; } /* v3.25.75:去掉 mix-blend-mode(浅色底上文字糊成一团) */
.iwb-cpick-swatch::after { content: '▾'; margin-left: 6px; opacity: .7; font-size: 10px; } /* 提示可点开取色 */
.iwb-cpick-swatch { min-width: 104px; }
.iwb-cpick-pop { position: absolute; z-index: 80; top: calc(100% + 8px); left: 0; width: 236px; padding: 10px; border-radius: 10px; background: var(--iwb-panel); border: 1px solid var(--iwb-border); box-shadow: var(--sh-md); }
.iwb-cpick-box { position: relative; height: 132px; border-radius: 6px; cursor: crosshair; }
.iwb-cpick-dot { position: absolute; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.4); pointer-events: none; }
@@ -2305,3 +2307,34 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s
/* v3.25.69:低缩放 LOD 已移除(用户反馈跨阈值时卡顿;改由 content-visibility 缩小绘制面) */
/* v3.25.69:屏幕外节点不参与绘制(配合已有视口裁剪,进一步缩小每次重绘的像素面) */
/* ── 外观面板(v3.25.75 重构):4 组 + 两栏网格 ─────────────────────────── */
.iwb-appear { display: flex; flex-direction: column; gap: 22px; }
.iwb-appear-group { display: flex; flex-direction: column; gap: 4px; }
.iwb-appear-ghead { display: flex; align-items: center; justify-content: space-between; padding: 0 0 6px; border-bottom: 1px solid var(--iwb-border); margin-bottom: 6px; }
.iwb-appear-gtitle { font-size: 13px; font-weight: 700; color: var(--iwb-text); }
.iwb-appear-row { display: grid; grid-template-columns: 120px minmax(0, 1fr) auto; align-items: center; gap: 10px; min-height: 40px; }
.iwb-appear-label { font-size: 12px; color: var(--iwb-text2); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iwb-appear-ctrl { display: flex; align-items: center; gap: 8px; min-width: 0; }
.iwb-appear-ctrl > .iwb-input, .iwb-appear-ctrl > select { max-width: 360px; }
.iwb-appear-note { font-size: 11px; color: var(--iwb-text2); white-space: nowrap; }
.iwb-appear-note:first-letter { color: var(--iwb-warn, #c88a14); }
.iwb-appear-select { max-width: 360px; }
.iwb-appear-range { flex: 0 1 260px; }
.iwb-appear-btns { display: flex; gap: 6px; flex-wrap: wrap; }
/* 分段控件(网格样式:点 / 线 / 空白) */
.iwb-seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 9px; background: var(--iwb-layer); border: 1px solid var(--iwb-border); }
.iwb-seg-item { border: 0; background: transparent; color: var(--iwb-text2); font-size: 12px; padding: 5px 14px; border-radius: 7px; cursor: pointer; }
.iwb-seg-item:hover { color: var(--iwb-text); }
.iwb-seg-item.on { background: var(--iwb-panel); color: var(--iwb-text); box-shadow: 0 1px 2px rgba(0,0,0,.12); font-weight: 700; }
@media (max-width: 720px) { .iwb-appear-row { grid-template-columns: 92px minmax(0, 1fr); } .iwb-appear-note { display: none; } }
/* 设置窗口可拖动(v3.25.76):拖标题栏移动,位置不受居中约束 */
.iwb-modal-draghead { cursor: move; user-select: none; }
.iwb-modal-draghead:active { cursor: grabbing; }
.iwb-modal-floating { box-shadow: 0 24px 60px rgba(0,0,0,.32); }
/* 设置面板专用透明遮罩(v3.25.77):去掉灰蒙层,调外观时能直接看到画布变化。
仍保留点击空白处关闭面板的行为。 */
.iwb-modal-mask.iwb-mask-ghost { background: transparent; }
.iwb-modal-mask.iwb-mask-ghost .iwb-settings-modal { box-shadow: 0 24px 60px rgba(0,0,0,.32); }
+2 -1
View File
@@ -9,6 +9,7 @@ const grid = fs.readFileSync(path.join(__dirname, '..', 'src', 'canvas-grid.js')
assert.ok(source.includes('gridStyleOf('), '网格样式必须经 gridStyleOf 计算')
assert.ok(source.includes('IWBCanvasGrid'), '必须接入 canvas-grid 模块')
assert.ok(grid.includes('function styleOf') && grid.includes('function applyTo'), '模块需提供 styleOf/applyTo')
assert.ok(source.includes("backgroundSize: (28 * scale) + 'px ' + (28 * scale) + 'px'"), 'jsdom/无模块时需回落到渐变公式')
assert.ok(source.includes("--iwb-grid-gap"), '网格必须读取外观设置变量(v3.25.74)')
assert.ok(source.includes("backgroundSize: (o.base * scale)"), 'jsdom/无模块时需回落到渐变公式')
assert.ok(!source.includes("backgroundPosition: viewport.x + 'px ' + viewport.y + 'px'"), '渲染期不得再按帧写 backgroundPosition')
console.log('canvas dot zoom checks passed')
+1
View File
@@ -67,6 +67,7 @@
"canvas-grid.js",
"image-display-thumb.js",
"image-thumb-pick.js",
"ui-modal-drag.js",
"ui-nav-rail.js",
"ui-plugin-page.js",
"ui-hotkey-help.js",
+1 -1
View File
@@ -149,7 +149,7 @@ const MAX_SRC_COMPONENT_LINES = 531
// ② 同时守「app.js 占总源码 ≤ 40%」(2026-11-12 实测 38.4%)—— app.js 可以涨,
// 但必须涨得比 src 慢;功能继续加,占比自然往下走;
// ③ Workbench 单函数上限**不动**(3,091)—— 那才是真坏味道的护栏,总量松它不松。
const MAX_APP_JS_LINES = 8985 // 2026-11-21 v3.25.73:缩略图按需切原图 + 稳定 key 装配(规则本体已抽到 src/image-thumb-pick.js,这里只留薄封装)
const MAX_APP_JS_LINES = 9035 // 2026-11-21 v3.25.78:缩略图回收调度(3 行,逻辑在 src/storage-file.js)
const MAX_APP_JS_SHARE = 0.40
// ── 历史记账(供回溯,逐条保留)──────────────────────────────────────────────
+1
View File
@@ -10,6 +10,7 @@ interface Window {
// 桌面壳 / 外观(v3.25.14)
IWBUIShell?: any
IWBUIApearance?: any
IWBUIModalDrag?: any
// 存储
IWBStorageLocal?: any
IWBStorageRuntime?: any