Compare commits

...
50 Commits
Author SHA1 Message Date
qiqi 1277a4398a chore(release): 3.26.39 发布记录 + 站点
Verify (Gitea) / gate (build · unit · facts) (push) Canceled after 1m30s
2026-11-22 22:20:36 +08:00
qiqi a0a696a2e6 docs: 锚点对齐 v3.26.39 2026-11-22 22:16:19 +08:00
qiqi 5e2f9dd876 release: v3.26.39(插入落点居中/封面插入/拖拽禁选)+ promptlib 1.6.18 2026-11-22 22:15:16 +08:00
qiqi 9739764d2f fix(promptlib): 插入提示词/封面落到画布中心 + 1.6.17 同步 2026-11-22 22:09:32 +08:00
qiqi 3483cc4174 docs: 插件开发规范(结构/能力/节点/设置页/样式/测试/发布)+ 官网 /dev/ 开发页
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 1m15s
2026-11-22 21:56:03 +08:00
qiqi 61dbd0abe8 chore(release): 3.26.38 发布记录 + 站点
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 1m26s
2026-11-22 21:33:32 +08:00
qiqi 95ccb8ec29 docs: 锚点对齐 v3.26.38 2026-11-22 21:30:39 +08:00
qiqi 843291cd66 release: v3.26.38(插件拖拽/交互修复 + 标注覆盖保留原图 + 踩坑文档) 2026-11-22 21:29:45 +08:00
qiqi e2b7c9919a test(promptlib): canvasWrite 插入断言 + 1.6.16 同步 2026-11-22 21:20:13 +08:00
qiqi de85aff6df test(promptlib): 指针拖拽插入断言 + 1.6.15 同步 2026-11-22 21:09:25 +08:00
qiqi 10d97e74d8 fix(canvas): 拖入后保持选中(对齐风格库),去掉多余的未选中状态 2026-11-22 21:04:58 +08:00
qiqi cce51e6ccd fix(canvas): blur 类型断言,CI typecheck 通过 2026-11-22 20:51:06 +08:00
qiqi 3565b5aec2 fix(canvas): 拖入节点后清理残留手势状态(首次点击不再被当成收尾) 2026-11-22 20:50:06 +08:00
qiqi a4550d5654 fix(nodes): 未编辑态的 readonly 文本不拦截指针(单击选节点)+ promptlib 1.6.14 2026-11-22 20:42:11 +08:00
qiqi 76115bcce8 test(promptlib): 双击详情 + 保存回详情的行为断言 2026-11-22 20:36:46 +08:00
qiqi ea219d92c4 feat(plugins): 拖入节点一律不选中 + promptlib 1.6.12 同步 2026-11-22 20:34:56 +08:00
qiqi 84df19fb59 fix(plugins): 模板节点拖入后不选中(避免输入框拦截拖动)+ 1.6.11 同步 2026-11-22 20:26:45 +08:00
qiqi af1070ec78 chore(plugins): promptlib 1.6.10(悬停缩放/封面点击修复)同步 2026-11-22 20:23:16 +08:00
qiqi f2be2a7a9f chore(plugins): promptlib 1.6.9 拖拽预览同步 2026-11-22 20:18:51 +08:00
qiqi b597ee4d69 chore(plugins): promptlib 1.6.8(拖拽/悬停反馈修复)同步 2026-11-22 20:13:57 +08:00
qiqi e60c2798db feat(plugins): 模板节点 outKind 直连 + 拖拽长按反馈 + 连线约定文档 2026-11-22 20:09:58 +08:00
qiqi 0bd85f24cc chore(release): 3.26.37 发布记录 + 站点
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 1m0s
2026-11-22 19:59:19 +08:00
qiqi 7700a4a26a docs: 锚点对齐 v3.26.37 2026-11-22 19:56:54 +08:00
qiqi a40c038785 release: v3.26.37(promptlib 1.6.6 变量/节点/备份/设置) 2026-11-22 19:56:04 +08:00
qiqi 64d40b7ac6 chore(plugins): promptlib 1.6.6 同步(节点封面修复) 2026-11-22 19:54:55 +08:00
qiqi c9c07e340c fix(plugins): 自包含样式去掉写死黑色(主题契约) + 1.6.5 同步 2026-11-22 19:50:52 +08:00
qiqi 3b304b3e3c chore(plugins): promptlib 1.6.5(节点封面 + CSS 自包含)同步 2026-11-22 19:49:39 +08:00
qiqi 8e19e7322f fix(plugins): pluginFilePut 解包 dataURL 取 bytes 字段(封面文件化生效)+ promptlib 1.6.4 2026-11-22 19:40:45 +08:00
qiqi 61597deb2b chore(plugins): promptlib 设置页修复同步 2026-11-22 17:27:46 +08:00
qiqi 35c8e725c4 feat(plugins): promptlib 设置页内嵌到宿主设置 + 1.6.0 同步 2026-11-22 17:26:44 +08:00
qiqi 3cb25875b3 feat(plugins): open_data_subpath 命令 + promptlib 设置页(分组/备份/数据位置)1.5.12 2026-11-22 17:25:10 +08:00
qiqi 404aa08cc6 feat(plugins): 提示词备份文件读写模块 + promptlib 1.5.9 同步 2026-11-22 17:14:47 +08:00
qiqi 4bdf6d0313 fix(plugins): 拖拽模板节点使用 plugin:promptlib:ptpl 类型 + 1.5.8 同步 2026-11-22 17:10:14 +08:00
qiqi 0c11b45af5 feat(plugins): 拖拽提示词按变量分流到模板节点 + promptlib 1.5.7 同步 2026-11-22 17:05:56 +08:00
qiqi 3e28796a15 chore(plugins): promptlib 1.5.6 同步 2026-11-22 16:58:40 +08:00
qiqi 39f123c5f3 chore(plugins): promptlib 1.5.5 同步 2026-11-22 16:53:46 +08:00
qiqi 636582bba6 chore(plugins): promptlib 1.5.3 同步(封面/加载/点击修复) 2026-11-22 16:48:05 +08:00
qiqi 5ccc6c879e fix(plugins): 暂时回退提示词插件到稳定版 1.4.10(1.5.0 点击详情回归待修复) 2026-11-22 16:33:47 +08:00
qiqi a46d874d33 wip(plugins): promptlib 1.5.0 变量/模板节点 + 封面走 promptlib 文件方法 2026-11-22 16:27:57 +08:00
qiqi c9b8bdf27c docs: 锚点对齐 v3.26.36 2026-11-22 16:16:07 +08:00
qiqi be982e4027 feat(plugins): files 能力 + zip 模块 + 提示词插件 1.5.0 数据迁移 v3.26.36 2026-11-22 16:15:29 +08:00
qiqi 412b907126 feat(plugins): zip 打包/解包模块(路径白名单 + 上限 + 重名拒绝)+ 测试 2026-11-22 16:09:56 +08:00
qiqi 0489d94461 feat(plugins): 新增 files 能力(plugin-data/<id>/files 沙箱 + 白名单/配额策略 + 测试) 2026-11-22 16:07:58 +08:00
qiqi d6271cde14 docs(plugins): ai-chat 明确为开发者直装(DEV_ONLY_IDS + README 状态)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 53s
2026-11-22 15:14:35 +08:00
qiqi eda67df9bf chore(plugins): style-source 1.3.3 token 化(深色气泡/警示色走主题 token)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 1m3s
2026-11-22 15:09:35 +08:00
qiqi f55f9403f5 docs: 发版锚点自动化写入规范(CONTRIBUTING / rulebook) 2026-11-22 15:00:28 +08:00
qiqi 23df59188e chore: 3.26.35 发布记录(release page/releases.json)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 39s
2026-11-22 14:59:35 +08:00
qiqi e5d0b5171b docs: 锚点对齐 v3.26.35+fca7b85(publish 自动) 2026-11-22 14:58:48 +08:00
qiqi fca7b856d4 chore: 发版脚本自动对齐文档锚点 v3.26.35 2026-11-22 14:55:10 +08:00
qiqi df3de3ce91 docs: 锚点对齐 v3.26.34
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 1m39s
2026-11-22 14:53:18 +08:00
46 changed files with 3010 additions and 160 deletions

No files matched your search

+52
View File
@@ -14,6 +14,58 @@
> 3. 核验正式地址版本 → 之后才移动 `stable` / `stable-verified-<日期>` 标签、更新本 CHANGELOG、写 GitHub Release(`gh release create`)。
> 测试发现问题 → 改 → 再 `deploy:test`,正式环境不受影响。回滚点 `git reset --hard stable`。
## v3.26.39(2026-11-22)修正插件插入落点与封面插入
- promptlib 1.6.18:拖拽落点按节点宽高居中到鼠标;详情「插入模板节点/插入画布/插入图片」落到画布可视中心;拖拽期间禁用文本选择。
- 宿主:新增 CanvasGeometry.promptCenterSpot,提示词/封面插入不再被左侧面板遮挡。
- 修复详情「插入图片」:封面文件先解析为 dataURL 再插入。
## v3.26.38(2026-11-22)插件节点交互修复 + 标注覆盖保留原图
### 提示词库(promptlib 1.6.16)
- 拖拽改为指针拖拽(对齐风格库):不再用原生 HTML5 DnD,修掉“拖入后第一次点不动/选中文本、需先点空白”的顽疾。
- 拖拽跟手幽灵卡片(封面 + 名称 + 模板/文本节点提示)。
- 节点创建走 canvasWrite.createNode + canvas.screenToWorld,落地即选中、可直接拖动。
- 双击卡片查看详情;详情 → 编辑 → 保存回到详情。
- 封面卡高度恢复;悬停缩放改内层背景层(不再闪烁);封面不拦截指针。
- 未选中时模板变量输入框不拦截指针;只读正文不拦截指针(单击=选中节点,双击=编辑)。
### 宿主
- canvasWrite.setNodeImage 覆盖前备份原图到 data.orig;节点右键新增「还原替换前原图」。
- 新增 docs/standards/plugin-node-drag.md:插件节点拖入/能力/指针交互踩坑记录。
### 已知问题
- 标注插件「覆盖」后原图需通过右键「还原替换前原图」找回;若旧节点在本次更新前已被覆盖,无备份。
## v3.26.37(2026-11-22)提示词库 1.6.6:变量 / 模板节点 / 备份 / 设置内嵌
### 提示词库(promptlib 1.6.6)
- 变量:`{变量}` 自动检测、编辑器可改标签/默认值/说明、实时预览;正文上方「+ 插入变量」按光标插入并选中变量名。
- 模板节点:封面缩略图 + 变量行 + 未填提示 + 「封面作参考图」开关;拖拽卡片按是否有变量自动分流(模板节点 / 文本节点)。
- 设置内嵌到「设置 → 插件 → 提示词库」:分组管理(改名/排序/删除)、数据备份(导出/导入 JSON)、数据位置。
- 封面文件化:封面从 JSON 内联迁移到 `plugin-data/promptlib/files/`(262KB → 约 15KB)。
- 插件 CSS 自包含:宿主基础样式按作用域复制进插件,宿主改全局样式不再覆盖插件。
### 客户端
- 修复 `pluginFilePut` 解包 dataURL 时取错字段(封面转文件一直失败)。
- 新增 `open_data_subpath` 命令(仅允许打开资料目录下的子路径)。
## v3.26.36(2026-11-22)插件文件能力(为提示词插件自持数据铺路)
### 新增
- `files` 能力:`plugin-data/<id>/files/` 沙箱,单文件 8MB / 总量 64MB,文件名白名单 + 原子写;策略独立成 `src/plugin-files-policy.js` 并有单测。
- zip 打包/解包模块 `src/plugin-archive.js`(路径白名单、解压上限、重名拒绝),含行为测试。
### 说明
- 仅新增能力,不改现有插件行为;提示词插件 1.5.0 将用它把数据迁到插件目录。
## v3.26.35(2026-11-22)发版脚本自动对齐文档锚点
### 工程
- 新增 `scripts/set-doc-anchor.js`:把 `main = <sha>` 与 `线上 vX.Y.Z+<sha>` 写成「最近一次 bump 版本的提交」。
- `publish-update.sh` 收尾自动执行:写锚点 → `sync-facts` → 本地提交(推送仍随版本)。以后不再需要手工改两次锚点。
- 安全护栏:HEAD 里的版本号与本地不一致(即 bump 未提交)时**跳过**并提示,避免写错提交。
## v3.26.34(2026-11-22)缩略图瘦身 + app.js 减负 + 两条守护测试
### 性能/磁盘
+3 -3
View File
@@ -41,7 +41,7 @@ build esbuild 打包到 dist/(单 dist/app.js = src/ 模块按序
node --check app.js 与 dist/app.js 语法
check-dist.js 产物体检
lint ESLint(src/ + app.js,正确性规则)
test:unit 114 个单测文件(jsdom 契约测试;2026-11-07 新增 sync-facts-guard(事实一致性)/ _helpers/source(统一源文本);2026-11-12 新增 provider-ping(测速 no-cors 兜底))
test:unit 116 个单测文件(jsdom 契约测试;2026-11-07 新增 sync-facts-guard(事实一致性)/ _helpers/source(统一源文本);2026-11-12 新增 provider-ping(测速 no-cors 兜底))
test relay-task-graph-fixture + iwb-v32-web-test
test:facts 事实基线守门(见 §5)
typecheck 渐进类型检查(tsc --noEmit;范围 = src/*.js,不含 app.js)
@@ -137,7 +137,7 @@ IWB_WRITE_BOUNDARY_SNAPSHOT=1 node tests/architecture-boundary-guard-test.js #
| **新增模块必须登记** `scripts/build.js` 的 `sourceModules`(顺序即加载序,别排序) | `tests/architecture-boundary-guard-test.js` | 打红 |
| **`src/` 不得反向依赖 app.js 的 window 全局** | 同上 | 打红 |
| **改动计数类事实**(模块数 / 耦合面项数 / spec 数)**必须同步**事实基线文档 | `tests/architecture-facts-guard-test.js` | 打红 |
| **发版后必须同步事实基线锚点**(第 4 行的 `main = <SHA>`) | 同上 | 打红。查 SHA 的正确方法见 `PUBLISHING.md` 第 1 步 |
| **事实基线锚点**(第 4 行 `main = <SHA>`)由 `publish-update.sh` **自动对齐并提交**(`scripts/set-doc-anchor.js`);手工改仍可用 | 同上 | 打红(若 bump 未提交,脚本会 WARN 跳过) |
| **新增测试文件必须真的进门禁**(否则是「孤儿测试」= 假覆盖率) | `tests/architecture-facts-guard-test.js` 第 9 组 | 打红。确需手工探针请登记 `ALLOW_ORPHAN` 并写原因 |
| **插件运行时完整性 fail-closed**:缺 `integrity` 即拒绝加载 | `tests/plugin-integrity-test.js` | 打红 |
| **新增节点类型必须先登记 `NODE_H`** | `tests/architecture-boundary-guard-test.js` | 节点**刷新即消失**(静默!) |
@@ -190,7 +190,7 @@ release: vX.Y.Z 发版
**手动发布**,CI 只验证不部署。详见 [`PUBLISHING.md`](PUBLISHING.md)。要点:
1. bump `package.json` 版本 → **同步事实基线锚点**(否则 `test:facts` 打红)
1. bump `package.json` 版本并**提交**(锚点由随后的 `publish-update.sh` 自动写并提交;bump 未提交时脚本会 WARN 跳过)
2. `npm run verify`(含全量 e2e)
3. 提交 + 推送 + 打标签(`vX.Y.Z` / `stable-vX.Y.Z` / `stable` / `stable-verified-<日期>`)
4. `npm run deploy:test` → 测试站实测 → `npm run deploy` → 正式站
+24 -5
View File
@@ -5631,6 +5631,12 @@ const tbCenterSeed = (type, refs) => {
return String(pr.name || pr.id || '') + ' · ' + (k ? String(k.name || k.id) : '无分组')
} catch (e) { return '' }
}
// 覆盖式替换图片前备份原图:优先保留已有 orig,其次 data,最后 url。返回 updateNode patch。
function origImagePatch(prev, dataUrl) {
const orig = (prev && prev.orig) || (prev && typeof prev.data === 'string' && /^data:/i.test(prev.data) ? prev.data : '') || (prev && typeof prev.url === 'string' ? prev.url : '')
return orig ? { data: String(dataUrl), url: '', orig } : { data: String(dataUrl), url: '' }
}
function Workbench() {
// runtime-workbench-logic 模块的 app.js 模块级依赖:渲染前注入一次(常量/纯函数,无陈旧值风险)
if (IWWorkbenchLogic && !IWWorkbenchLogic.__iwbInjected) {
@@ -5789,9 +5795,8 @@ const tbCenterSeed = (type, refs) => {
},
setNodeImage: (id, dataUrl) => {
if (!/^data:/i.test(String(dataUrl || ''))) return false
if (!refs.nodes.some((x) => x.id === id)) return false
updateNode(id, { data: String(dataUrl), url: '' })
return true
const t = refs.nodes.find((x) => x.id === id); if (!t) return false
updateNode(id, origImagePatch(t.data || {}, String(dataUrl))); return true
},
}
return () => { wPluginCanvasBridge = null }
@@ -8211,7 +8216,7 @@ const tbCenterSeed = (type, refs) => {
},
insert: (text, name) => {
const id = uid('n')
const spot = findSpot('prompt')
const spot = CanvasGeometry.promptCenterSpot(wPluginCanvasBridge, 280, 120) || findSpot('prompt')
commitCanvas(refs.nodes.concat([{ id, type: 'prompt', x: spot.x, y: spot.y, data: { text: text || '', title: name || '' } }]), undefined, undefined)
setSel([id])
setNotice({ type: 'ok', text: '已插入提示词:' + (name || '') })
@@ -8221,7 +8226,7 @@ const tbCenterSeed = (type, refs) => {
insertImage: (cover, name) => wPromptInsertImage({
insertRefNode: (data, nm, w) => {
const id = uid('n')
const spot = findSpot('ref')
const spot = CanvasGeometry.promptCenterSpot(wPluginCanvasBridge, w || 280, 180) || findSpot('ref')
commitCanvas(refs.nodes.concat([{ id, type: 'ref', x: spot.x, y: spot.y, w: w || 280, data: { data: data, name: nm } }]), undefined, undefined)
setSel([id])
setNotice({ type: 'ok', text: '已插入封面图片' })
@@ -8662,6 +8667,7 @@ const tbCenterSeed = (type, refs) => {
const items = []
if (isImageProducer(tgt)) items.push(el('button', { key: 'run', className: 'iwb-ctx-item', onClick: () => { runProducer(tgt.id); setCtxMenu(null) } }, I('run'), el('span', { className: 'iwb-btn-text' }, tgt.type === 'layer' ? '运行该分层' : '运行该生图')))
if (tgt.type === 'llm') items.push(el('button', { key: 'pol', className: 'iwb-ctx-item', onClick: () => { runLLM(tgt.id); setCtxMenu(null) } }, I('llm'), el('span', { className: 'iwb-btn-text' }, '▶ 润色')))
if (tgt.type === 'ref' && tgt.data && typeof tgt.data.orig === 'string' && tgt.data.orig) items.push(el('button', { key: 'restore-orig', className: 'iwb-ctx-item', onClick: () => { pushHistory(); updateNode(tgt.id, { data: tgt.data.orig, url: '', orig: '' }); setCtxMenu(null) } }, I('undo'), el('span', { className: 'iwb-btn-text' }, '还原替换前原图')))
if (tgt.type === 'prompt' && (tgt.data.text || '').trim()) items.push(el('button', { key: 'fav', className: 'iwb-ctx-item', onClick: () => { addPromptToLibrary(tgt.id); setCtxMenu(null) } }, I('star'), el('span', { className: 'iwb-btn-text' }, '添加该提示词')))
items.push(el('button', { key: 'bgc', className: 'iwb-ctx-item', onClick: (e) => { const rc = e && e.currentTarget ? e.currentTarget.getBoundingClientRect() : null; setCtxMenu(null); if (UiGenCfgModule && UiGenCfgModule.openNodeBgPalette) UiGenCfgModule.openNodeBgPalette({ current: (tgt.data && tgt.data.bg) || '', anchorRect: rc, onPreview: (bg) => previewNodeBg([tgt.id], bg), onPreviewEnd: endNodeBgPreview, onPick: (bg) => updateNode(tgt.id, { bg }) }) } }, I('palette'), el('span', { className: 'iwb-btn-text' }, '背景色')), el('button', { key: 'ren', className: 'iwb-ctx-item', onClick: () => { setCtxMenu(null); wRenameNodeDialog(tgt, td, updateNode) } }, I('edit'), el('span', { className: 'iwb-btn-text' }, '重命名节点')), el('button', { key: 'del', className: 'iwb-ctx-item iwb-ctx-danger', onClick: () => { deleteNodes([tgt.id]); setCtxMenu(null) } }, I('x'), el('span', { className: 'iwb-btn-text' }, '删除该节点')))
// 子菜单默认向上展开(底对齐入口):两组入口都在一级菜单下半区,向下会顶出视口
@@ -8867,6 +8873,19 @@ items.push(el('button', { key: 'bgc', className: 'iwb-ctx-item', onClick: (e) =>
gallery: () => ((typeof window !== 'undefined' && window.IWBPluginGallery) ? window.IWBPluginGallery.api() : {}),
grouplib: () => ((typeof window !== 'undefined' && window.IWBPluginGroupLib) ? window.IWBPluginGroupLib.api() : {}),
promptlib: () => ((typeof window !== 'undefined' && window.IWBPluginPromptLib) ? window.IWBPluginPromptLib.api() : {}),
// 插件文件能力(v3.26.36):沙箱目录 plugin-data/<id>/files,供插件自持图片
files: (ctx) => {
const F = (typeof window !== 'undefined' && window.IWBStorageFile) ? window.IWBStorageFile.pluginFiles : null
const need = () => { if (!F) throw new Error('文件能力未就绪(资料目录尚未初始化)'); return F }
return {
put: (name, dataUrl) => need().put(ctx.id, name, dataUrl),
get: (name) => need().get(ctx.id, name),
list: () => need().list(ctx.id),
remove: (name) => need().remove(ctx.id, name),
stat: () => need().stat(ctx.id),
dir: () => need().dir(ctx.id),
}
},
commands: (ctx) => {
const owned = []
return {
+5 -5
View File
@@ -1,7 +1,7 @@
# 现状架构与性能事实基线(image-workbench-web)
> **本文档是什么**:现状**事实快照**,不是规范。用途:任何性能 / 内存 / 存储相关改动,先对齐这里的现实,避免把已经调好的东西改坏。
> 日期 **2026-10-20**(**2026-11-16 复算 · v3.24.85**)| 基线(**最近一次 bump 版本的提交**,不是主干 HEAD)`main = 4b70e40`(线上 `v3.26.34+4b70e40` —— **未上线**(本地测试中):左右停靠栏配色对齐主色调(新增 `--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 = 5e2f9dd`(线上 `v3.26.39+5e2f9dd` —— **未上线**(本地测试中):左右停靠栏配色对齐主色调(新增 `--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`(现 **105** 个模块 / 14,607 行,`sourceModules` 105 项;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`(现 **108** 个模块 / 14,607 行,`sourceModules` 108 项;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` 不引用模块全局)。**105 个模块中 59 个导出**被 `app.js` 读取;其余为未接线 / 仅测试 / 零引用(见下)。
- **判定法**:`global.X =` / `root.X =` 判「导出」;跨文件裸引用判「读」;排除自合并(`src/runtime-constants.js:9`)。`app.js` 是**唯一生产消费者**(无 HTML 入口;`sw.js` 不引用模块全局)。**108 个模块中 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 耦合面(**86** 项)与 `sourceModules` 顺序(**105** 项);命名例外由第 5 组冻结,新增非 `IWB` 前缀导出即打红。
- **耦合面已冻结**:`tests/architecture-boundary-guard-test.js`(进 `npm run test:unit` 末环)冻结 app.js↔src 耦合面(**86** 项)与 `sourceModules` 顺序(**108** 项);命名例外由第 5 组冻结,新增非 `IWB` 前缀导出即打红。
## 12. 易踩的坑
@@ -254,7 +254,7 @@
**信任模型(必须明示)**:形态 A 的插件是**可信代码**(与核心同权限、无沙箱);启停与设置是 UX 与可维护性手段,**不是安全边界**(同 §13.27 教训:前端开关一定可被绕过)。
**守门与快照**:`tests/architecture-boundary-guard-test.js` 冻结「app.js ↔ src 耦合面」(**86** 项)与 `sourceModules` 顺序(**105** 项);新增模块、新增耦合、新增 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 耦合面」(**86** 项)与 `sourceModules` 顺序(**108** 项);新增模块、新增耦合、新增 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 规则三的同一失败模式)。
+2
View File
@@ -644,6 +644,8 @@ B-② 撤销/重做后图片真能解码显示,`naturalWidth=768`)· e2e `te
5. **守门若依赖 git 历史(父提交 / 多提交比对),CI 必须用 `fetch-depth: 0`**。GitHub Actions 默认 `depth=1`(浅克隆)⇒ 父提交不可读 ⇒ 门禁要么崩、要么给出**错误的期望值**(实测踩过:`git show HEAD^` 报 `invalid object name`,守门误报失败)。本仓 CI 两个 job 均已设 `fetch-depth: 0`(仓库打包后仅 ~3MB,取全历史成本可忽略)。
另:门禁自身**仍要做浅克隆检测**(`git rev-parse --is-shallow-repository`)并**降级为只校验版本**、打印 SKIP 而非打红 —— 这样在别处的浅克隆环境不会产生「无法解释的红」。(2026-10-20 实测:守门上线后 CI 首次运行即因浅克隆失败,改用 `fetch-depth: 0` + 降级判据后恢复。)
6. **锚点同步已自动化(2026-11-22)**:`scripts/publish-update.sh` 收尾调用 `scripts/set-doc-anchor.js`,把锚点写成「最近一次 bump 版本的提交」并**本地提交**(`docs: 锚点对齐 vX.Y.Z+<sha>(publish 自动)`)。护栏:`git show HEAD:package.json` 的版本与本地不一致(bump 未提交)时打印 WARN 并跳过,避免写错提交。手工改锚点仍然有效。
**验证方式**:`tests/architecture-facts-guard-test.js` 第 7 组(`npm run test:facts`)· 负例:把锚点改回旧 SHA ⇒ 打红并给出应填的 SHA。
## §13.37 源码文本钉点:全目录只减不增(2026-10-20)
+166
View File
@@ -0,0 +1,166 @@
# Image Workbench 插件开发规范
> 版本:v1(2026-11-22)。面向官方与第三方插件;示例以 promptlib(提示词库)与 style-source(风格库)为准。
> 相关文档:plugin-node-drag.md(节点拖入/指针交互踩坑)、plugin-node-outkind.md(下游连线声明)、plugin-theme.md(主题契约)。
## 1. 目录与基本结构
插件是「一个目录 + 一个 IIFE 入口」,由宿主在启用时动态加载并调用 register。
my-plugin/
package.json # 版本 + ibwPlugin 元数据
src/index.js # 入口(IIFE,末尾 IWBPluginHost.register)
styles.css # 样式(必须自包含)
README.md
package.json:
{
"name": "@iwb-plugin/my-plugin",
"version": "1.0.0",
"ibwPlugin": { "id": "my-plugin", "entry": "src/index.js", "apiVersion": 1 }
}
入口骨架:
;(function (global) {
'use strict'
if (!global.IWBPluginHost) return
global.IWBPluginHost.register({
id: 'my-plugin',
name: '我的插件',
version: '1.0.0',
capabilities: ['panels', 'canvas', 'canvasWrite'],
settings: { panel: { type: 'custom', label: '设置', render: renderSettings } },
mount: mount,
unmount: unmount,
}, function (ctx) {
// setup:注册面板/节点/命令
return { dispose () {} }
})
})(typeof window !== 'undefined' ? window : globalThis)
## 2. 能力(capabilities)与 ctx 映射
只申请用到的能力;能力名与 ctx 键不同:
| capability | ctx 键 | 用途 |
|---|---|---|
| panels | ctx.ui | 侧栏/独立面板注册 |
| promptlib | ctx.promptlib | 提示词库数据 + 文件 + 备份 |
| nodeTypes | ctx.nodes | 画布节点类型注册 |
| canvas | ctx.canvas | 只读:getNodes / getSelectedNode / screenToWorld |
| canvasWrite | ctx.canvasWrite | 写入:createNode / createImageNode / setNodeImage |
| nodeActions | ctx.nodeActions | 节点右键/气泡动作 |
| commands | ctx.commands | 命令面板 |
| settings | ctx.settings | KV 配置 |
| data | ctx.data | 插件数据文件 |
**注意**:createNode 在 ctx.canvasWrite,不在 ctx.canvas。调错只会提示“宿主不支持”。
## 3. 面板
ctx.ui.registerPanel({
id: 'my-panel',
title: '我的插件',
mount (host) { /* 渲染到 host */ },
unmount (host) { /* 清理定时器/监听 */ }
})
- mount 只调用一次,内部自己管理重渲染。
- 面板宽度可变:使用栅格/瀑布流,不要写死 px 宽度。
- 面板内所有 DOM 事件在 unmount 时移除。
## 4. 节点类型
ctx.nodes.register({
id: 'tpl',
title: '模板节点',
defaults: { outKind: 'prompt' },
ports: { in: false, out: true },
height: 360,
render (node, props, host) { /* 首次建 DOM,之后 sync */ }
})
宿主会生成类型 plugin:<插件id>:<变体id>。
**必须遵守**:
1. 输出文本/提示词 → data.outKind = 'prompt'(注册默认值、拖入数据、旧节点在 render 里自愈)。
2. 拖入画布用指针拖拽,不用原生 HTML5 DnD:
pointerdown → pointermove(>5px) 幽灵卡片
→ pointerup → ctx.canvas.screenToWorld(x,y)
→ ctx.canvasWrite.createNode('tpl', wx, wy, data)
3. 输入框:未选中时 pointer-events: none,选中后才可编辑;只读 textarea 同样处理。
4. 单击 = 选中/拖动,双击 = 编辑;不要用单击打开详情。
5. 节点 render 必须可增量 sync,避免整块重建(输入框会丢焦点)。
## 5. 数据与文件
- 小数据:ctx.promptlib(或 ctx.data)JSON,单文件 < 1MB。
- 大文件(封面/图片):ctx.promptlib.filePut/fileGet/fileList,落地在 plugin-data/<id>/files/。
- dataUrlToBytes() 返回 { mime, bytes },不是 Uint8Array。
- 备份:提供导出/导入 JSON;导入按 id 合并,提供“覆盖同 id”选项。
- 迁移:旧格式在 setup 里做一次性迁移,失败要提示而不是静默丢数据。
## 6. 设置页面
宿主设置页内嵌渲染,不弹独立页面:
settings: {
panel: { type: 'custom', label: '分组与备份', render: renderSettings }
}
render 返回 DOM;宿主负责挂载/卸载。设置页适合放:
- 分组管理(新建/改名/排序/删除)
- 数据备份(导出/导入)
- 数据位置(打开数据目录)
- 插件级开关/默认值
## 7. 样式规范
1. **自包含**:宿主基础样式会变;用到的宿主类按作用域复制一份(.iwb-myplugin …)。
2. 统一前缀:面板/节点类名 my-plugin-*,避免与宿主 .iwb-* 冲突。
3. 颜色走 CSS 变量:var(--iwb-text)、--iwb-panel、--iwb-border、--iwb-plugin-accent。
4. 动画克制:只做 hover/press 反馈;不使用持续浮动动画。
5. 深色主题:不写死 #fff/#000;主题契约测试会扫描。
6. 悬停放大只缩放内层背景,不缩放卡片本体(避免命中区域漂移/闪烁)。
7. 图片/封面 pointer-events: none,点击永远落到卡片。
## 8. 错误处理与提示
- 所有用户可见错误用 ctx.promptlib.notify / ctx.ui.toast,文案给“下一步怎么办”。
- 异步链必须有 catch;不要吞掉错误后静默。
- 崩溃日志:window.onerror 由宿主统一采集,插件不要自己覆盖。
- 定时器/监听在 unmount/dispose 清理,避免面板切换后重复执行。
## 9. 测试与门禁
提交前至少:
node scripts/validate-plugins.js # manifest/能力/入口校验
node scripts/theme-contract-test.js # 主题变量
node tests/plugin-<id>-render-test.js # jsdom 渲染/交互
jsdom 可覆盖:面板渲染、节点 render/sync、拖拽插入(stub screenToWorld/createNode)、双击详情、保存回详情、封面 img。
## 10. 发布与市场
1. 改 package.json version 与入口 version(两处一致)。
2. node scripts/sync-plugins-from-repo.js(同步到客户端 plugins/)
3. node scripts/gen-market.js(生成 market/ 与 zip)
4. 上传 market 到 NAS(tar + scp + 解压)
5. 客户端发版:set-version → CHANGELOG → 锚点 → verify:ci → build → publish-update → releases/site → tag/push
## 11. 常见坑(务必先读)
- 原生 HTML5 拖放:WKWebView 吞 pointerup,节点落地后第一次点击异常 → 用指针拖拽。
- ctx.canvas 没有 createNode → 用 ctx.canvasWrite。
- 输入框拦截拖动 → 未选中时 pointer-events:none。
- 只读 textarea 仍可选中文本 → pointer-events:none。
- dataUrlToBytes 返回对象 → 取 .bytes。
- 封面直接存 dataURL 会让 JSON 膨胀 → 迁移到文件,只存 { img }。
- 插件节点不声明 outKind → 只能中继,无法直连生图。
+55
View File
@@ -0,0 +1,55 @@
# 插件节点:拖入、渲染与指针交互踩坑记录(promptlib 实战)
> 来源:提示词库 1.6.x 接入画布节点时连续踩到的问题。新增「带变量的插件节点」前先读一遍。
## 1. 拖入画布:不要用原生 HTML5 drag&drop
**现象**:节点拖进画布后,第一次点击要么选中文本、要么拖不动;点一下空白再点节点才正常。
**原因**:WKWebView 在原生拖放期间吞掉 pointerup/mouseup,落点节点带着焦点/手势残留。宿主很难在 drop 后完全复位。
**正确做法**(对齐风格库):自己实现指针拖拽:
pointerdown → pointermove(>5px) → 出现跟手幽灵卡片
pointerup → ctx.canvas.screenToWorld(x, y) → ctx.canvasWrite.createNode(type, x, y, data)
- 不要 draggable=true,不要 dataTransfer
- 不要 preventDefault() pointerdown(会吞掉 click/dblclick)
- 卡片加 user-select:none,避免拖拽选中标题文字
## 2. 宿主能力是拆开的:canvas / canvasWrite
| 能力 | 方法 |
|---|---|
| ctx.canvas | 只读:getNodes / getSelectedNode / screenToWorld |
| ctx.canvasWrite | 写入:createNode / createImageNode / setNodeImage |
createNode **不在** ctx.canvas 上;调错只会得到“宿主不支持”的提示。manifest 的 capabilities 要同时声明 canvas 与 canvasWrite。
## 3. 新建节点交给宿主创建,不要手工 commit
宿主 addPluginNode 会:拼 plugin:<id>:<variant> 类型、按变体宽度、**先选中再提交**。手工 commitCanvas 容易漏选中/漏默认值,还会让第一次点击变成“先选中”。
## 4. 连线能力:声明 outKind
节点要直连生图/润色/文本/组合,必须 data.outKind = 'prompt'(注册默认值 + 拖入数据 + 旧节点自愈三处),详见 plugin-node-outkind.md。
## 5. 输入框与拖动
- 节点内的 <input> 会让宿主只选中、不拖动(宿主把 input 视为可交互控件)
- 未选中时给输入框 pointer-events: none,让点击/拖动落到节点本体;选中后再允许输入
- 只读 <textarea> 也要 pointer-events: none,否则单击会选中文本
## 6. 插件样式必须自包含
宿主基础样式会变。插件需要把用到的宿主类按作用域复制一份(.iwb-promptlib …),不要假设宿主类名/结构长期稳定。
## 7. 文件与 dataURL
- dataUrlToBytes() 返回 { mime, bytes },不是 Uint8Array
- 封面等大字段迁移到 plugin-data/<id>/files/,JSON 只留 { img: 文件名 }
- 读文件走 ctx.promptlib.fileGet(能力声明 promptlib),不要依赖 ctx.files
## 8. 图片被覆盖后如何保留原图
宿主 canvasWrite.setNodeImage 覆盖前会把原图备份到 data.orig;右键节点可「还原替换前原图」。插件侧覆盖时不要自己清除 data.orig。
+34
View File
@@ -0,0 +1,34 @@
# 插件节点的下游连线声明(outKind)
> 适用:任何需要在画布上输出「一段文本/提示词」的插件节点(示例:风格库样式节点、提示词库模板节点)。
## 1. 为什么需要声明
宿主的连线白名单(`src/canvas-geometry.js`)按**节点语义**判断能否连到下游(生图 / 润色 / 文本 / 组合 / 连接)。
插件节点的 `type` 是运行时注册的 `plugin:<插件id>:<变体id>`,宿主静态表里没有,无法预知它输出什么。
因此约定一个显式声明:
```js
node.data.outKind = 'prompt' // 这一路输出的是提示词
```
声明后,该节点在连线规则里**等同内置提示词节点**:可直接连到生图 / 润色 / 文本 / 组合 / 连接;
不声明则只能通过「中继」节点转接。
## 2. 怎么声明(插件侧)
三处都要覆盖,缺一处就会出现「新拖的能连、旧节点不能连」:
1. **注册默认值**(所有 `ctx.canvas.createNode` 路径生效):
```js
ctx.nodes.register({ id: 'ptpl', defaults: { outKind: 'prompt' }, … })
```
2. **宿主拖拽落点**:拖拽 payload 里带 `outKind`,宿主创建节点时写入 `data.outKind`。
3. **旧节点自愈**:节点 `render` 时若 `data.outKind !== 'prompt'`,调 `props.onUpdate(id, { outKind: 'prompt' })` 补一次。
## 3. 宿主侧约束
- 白名单数组(`canvas-geometry.js` 的 7 条规则)是**宿主所有**,插件不得修改;插件只声明语义。
- `outKind` 目前只支持 `'prompt'`;新增语义(如图片、分组)需先在宿主补规则并写测试。
- 声明缺失时行为保持旧状(只能中继),不会破坏已有画布。
+4
View File
@@ -62,3 +62,7 @@
## 相关规范
- 原生浮层(面板内嵌浏览器 / 画布网页节点)的生命周期见 `docs/standards/native-overlay-lifecycle.md`(先 park 再 close,禁止把隐藏放进定时器)。
## 相关规范
- 插件节点要直连下游(生图/润色/文本…)需声明 `data.outKind = 'prompt'`,见 `docs/standards/plugin-node-outkind.md`。
+2 -2
View File
@@ -1,7 +1,7 @@
{
"name": "image-workbench-web",
"private": true,
"version": "3.26.34",
"version": "3.26.39",
"description": "Browser-based node canvas image workbench",
"scripts": {
"build": "node scripts/build.js && node scripts/copy-plugins.js",
@@ -10,7 +10,7 @@
"app:build": "tauri build",
"lint": "eslint src app.js",
"test": "node tests/relay-task-graph-fixture-test.js && node tests/plugin-style-node-test.js && node tests/inherit-text-test.js",
"test:unit": "node tests/theme-plugin-tokens-test.js && node tests/image-prompt-cover-test.js && node tests/unit-test.js && node tests/canvas-actions-test.js && node tests/canvas-performance-test.js && node tests/canvas-drag-performance-test.js && node tests/resize-observer-performance-test.js && node tests/node-drag-jank-test.js && node tests/edge-graph-performance-test.js && node tests/persistence-export-images-test.js && node tests/settings-hotkeys-size-presets-test.js && node tests/custom-size-validation-test.js && node tests/image-node-performance-test.js && node tests/drag-frame-performance-test.js && node tests/canvas-edge-memo-test.js && node tests/canvas-node-transform-test.js && node tests/canvas-dot-zoom-test.js && node tests/duplicate-ws-fresh-source-test.js && node tests/single-canvas-shell-test.js && node tests/navigation-layout-test.js && node tests/home-canvas-library-test.js && node tests/left-resource-layout-test.js && node tests/interface-hierarchy-test.js && node tests/three-page-layout-test.js && node tests/page-chrome-regression-test.js && node tests/task-cache-test.js && node tests/storage-config-shape-test.js && node tests/storage-zip-test.js && node tests/canvas-node-factory-test.js && node tests/runtime-error-test.js && node tests/runtime-lifecycle-test.js && node tests/runtime-fetch-test.js && node tests/runtime-channel-test.js && node tests/runtime-boundary-test.js && node tests/runtime-record-test.js && node tests/runtime-recovery-test.js && node tests/runtime-diagnostic-record-test.js && node tests/runtime-metrics-test.js && node tests/runtime-run-context-test.js && node tests/runtime-execution-context-test.js && node tests/storage-gc-canvas-refs-test.js && node tests/storage-health-test.js && node tests/generation-state-test.js && node tests/canvas-store-test.js && node tests/storage-result-test.js && node tests/storage-local-test.js && node tests/storage-domain-test.js && node tests/storage-runtime-test.js && node tests/storage-indexeddb-test.js && node tests/generation-scheduler-test.js && node tests/gallery-query-test.js && node tests/gallery-hydration-test.js && node tests/image-blob-store-test.js && node tests/image-preview-derive-test.js && node tests/image-format-test.js && node tests/clipboard-graph-test.js && node tests/clipboard-graph-fallback-test.js && node tests/image-admit-test.js && node tests/image-dedupe-test.js && node tests/clipboard-kind-test.js && node tests/clipboard-paste-test.js && node tests/clipboard-copy-test.js && node tests/paste-once-test.js && node tests/list-e2e-specs-test.js && node tests/desktop-csp-loopback-test.js && node tests/architecture-boundary-guard-test.js && node tests/plugin-host-test.js && node tests/plugin-data-test.js && node tests/plugin-loader-test.js && node tests/plugin-bundle-test.js && node tests/plugin-install-test.js && node tests/plugin-gallery-render-test.js && node tests/plugin-gallery-recovery-test.js && node tests/plugin-gallery-ux-test.js && node tests/plugin-grouplib-render-test.js && node tests/plugin-promptlib-render-test.js && node tests/image-compress-test.js && node tests/storage-fallback-indexeddb-test.js && node tests/canvas-normalize-test.js && node tests/canvas-geometry-test.js && node tests/canvas-history-test.js && node tests/canvas-ops-test.js && node tests/canvas-text-test.js && node tests/history-store-test.js && node tests/plugin-integrity-test.js && node tests/workspace-sessions-store-test.js && node tests/workspace-list-test.js && node tests/workspace-purge-test.js && node tests/provider-ping-test.js && node tests/runtime-diagnostics-hotpath-test.js && node tests/storage-log-failure-test.js && node tests/storage-convergence-test.js && node tests/swallow-wiring-test.js && node tests/workbench-logic-test.js && node tests/storage-autobackup-test.js && node tests/storage-outputs-mutate-test.js && node tests/sync-facts-guard-test.js && node tests/e2e-fixed-waits-ratchet-test.js && node tests/shell-render-behavior-test.js && node tests/canvas-meta-notice-behavior-test.js && node tests/source-text-ratchet-test.js && node tests/plugin-theme-contract-test.js && node tests/prompt-md-roundtrip-test.js && node tests/generation-results-store-test.js && node tests/out-groups-order-test.js && node tests/native-overlay-park-test.js && node tests/ui-dock-sanitize-test.js && node tests/ui-minimap-fit-test.js && node tests/ui-workbench-hooks-test.js",
"test:unit": "node tests/plugin-archive-test.js && node tests/plugin-files-policy-test.js && node tests/theme-plugin-tokens-test.js && node tests/image-prompt-cover-test.js && node tests/unit-test.js && node tests/canvas-actions-test.js && node tests/canvas-performance-test.js && node tests/canvas-drag-performance-test.js && node tests/resize-observer-performance-test.js && node tests/node-drag-jank-test.js && node tests/edge-graph-performance-test.js && node tests/persistence-export-images-test.js && node tests/settings-hotkeys-size-presets-test.js && node tests/custom-size-validation-test.js && node tests/image-node-performance-test.js && node tests/drag-frame-performance-test.js && node tests/canvas-edge-memo-test.js && node tests/canvas-node-transform-test.js && node tests/canvas-dot-zoom-test.js && node tests/duplicate-ws-fresh-source-test.js && node tests/single-canvas-shell-test.js && node tests/navigation-layout-test.js && node tests/home-canvas-library-test.js && node tests/left-resource-layout-test.js && node tests/interface-hierarchy-test.js && node tests/three-page-layout-test.js && node tests/page-chrome-regression-test.js && node tests/task-cache-test.js && node tests/storage-config-shape-test.js && node tests/storage-zip-test.js && node tests/canvas-node-factory-test.js && node tests/runtime-error-test.js && node tests/runtime-lifecycle-test.js && node tests/runtime-fetch-test.js && node tests/runtime-channel-test.js && node tests/runtime-boundary-test.js && node tests/runtime-record-test.js && node tests/runtime-recovery-test.js && node tests/runtime-diagnostic-record-test.js && node tests/runtime-metrics-test.js && node tests/runtime-run-context-test.js && node tests/runtime-execution-context-test.js && node tests/storage-gc-canvas-refs-test.js && node tests/storage-health-test.js && node tests/generation-state-test.js && node tests/canvas-store-test.js && node tests/storage-result-test.js && node tests/storage-local-test.js && node tests/storage-domain-test.js && node tests/storage-runtime-test.js && node tests/storage-indexeddb-test.js && node tests/generation-scheduler-test.js && node tests/gallery-query-test.js && node tests/gallery-hydration-test.js && node tests/image-blob-store-test.js && node tests/image-preview-derive-test.js && node tests/image-format-test.js && node tests/clipboard-graph-test.js && node tests/clipboard-graph-fallback-test.js && node tests/image-admit-test.js && node tests/image-dedupe-test.js && node tests/clipboard-kind-test.js && node tests/clipboard-paste-test.js && node tests/clipboard-copy-test.js && node tests/paste-once-test.js && node tests/list-e2e-specs-test.js && node tests/desktop-csp-loopback-test.js && node tests/architecture-boundary-guard-test.js && node tests/plugin-host-test.js && node tests/plugin-data-test.js && node tests/plugin-loader-test.js && node tests/plugin-bundle-test.js && node tests/plugin-install-test.js && node tests/plugin-gallery-render-test.js && node tests/plugin-gallery-recovery-test.js && node tests/plugin-gallery-ux-test.js && node tests/plugin-grouplib-render-test.js && node tests/plugin-promptlib-render-test.js && node tests/image-compress-test.js && node tests/storage-fallback-indexeddb-test.js && node tests/canvas-normalize-test.js && node tests/canvas-geometry-test.js && node tests/canvas-history-test.js && node tests/canvas-ops-test.js && node tests/canvas-text-test.js && node tests/history-store-test.js && node tests/plugin-integrity-test.js && node tests/workspace-sessions-store-test.js && node tests/workspace-list-test.js && node tests/workspace-purge-test.js && node tests/provider-ping-test.js && node tests/runtime-diagnostics-hotpath-test.js && node tests/storage-log-failure-test.js && node tests/storage-convergence-test.js && node tests/swallow-wiring-test.js && node tests/workbench-logic-test.js && node tests/storage-autobackup-test.js && node tests/storage-outputs-mutate-test.js && node tests/sync-facts-guard-test.js && node tests/e2e-fixed-waits-ratchet-test.js && node tests/shell-render-behavior-test.js && node tests/canvas-meta-notice-behavior-test.js && node tests/source-text-ratchet-test.js && node tests/plugin-theme-contract-test.js && node tests/prompt-md-roundtrip-test.js && node tests/generation-results-store-test.js && node tests/out-groups-order-test.js && node tests/native-overlay-park-test.js && node tests/ui-dock-sanitize-test.js && node tests/ui-minimap-fit-test.js && node tests/ui-workbench-hooks-test.js",
"test:diagnostics": "node tests/runtime-diagnostics-hotpath-test.js",
"test:facts": "node tests/architecture-facts-guard-test.js && node tests/release-records-test.js",
"plugins:gc": "node scripts/plugins-publish.mjs --gc",
+6 -6
View File
@@ -44,10 +44,10 @@
"dir": "promptlib",
"main": "main.js",
"style": "styles.css",
"version": "1.4.10",
"version": "1.6.18",
"files": {
"main.js": "75dc31dc6270aa10e73c90eeb09bb349a949d17c39940574e28f12c5e463ceaf",
"styles.css": "cc71e071379c84131e525afeaa5757674f499da195ccb42536c019a3ef5d8473"
"main.js": "0efdfbbfe7e9318610bb94330c0a3c361a0aa38f2b3a44c243c872f0e02a09e8",
"styles.css": "1fdad04e2ffe1c8ba2a991a88072f780b65238096f9ccd1b5adba671ff2c9cb3"
}
},
{
@@ -64,9 +64,9 @@
},
{
"id": "style-source",
"file": "plugin-style-source.ee7168565a44.js",
"version": "1.3.2",
"integrity": "sha256-7nFoVlpE1J2q8wD2LVx6EG5g+6KankiI/4v9mr0uMXg="
"file": "plugin-style-source.05c108f8a63c.js",
"version": "1.3.3",
"integrity": "sha256-BcEI+KY8wcXrscHRi0reEOlxoO50+xNUgtt1l+ZzH4Q="
},
{
"id": "white-bg-800",
+1109 -68
View File
File diff suppressed because it is too large. Load diff
+3 -3
View File
@@ -1,7 +1,7 @@
{
"id": "promptlib",
"name": "提示词库",
"version": "1.4.10",
"version": "1.6.18",
"apiVersion": 1,
"main": "main.js",
"style": "styles.css",
@@ -13,7 +13,7 @@
"提示词"
],
"files": {
"main.js": "75dc31dc6270aa10e73c90eeb09bb349a949d17c39940574e28f12c5e463ceaf",
"styles.css": "cc71e071379c84131e525afeaa5757674f499da195ccb42536c019a3ef5d8473"
"main.js": "0efdfbbfe7e9318610bb94330c0a3c361a0aa38f2b3a44c243c872f0e02a09e8",
"styles.css": "1fdad04e2ffe1c8ba2a991a88072f780b65238096f9ccd1b5adba671ff2c9cb3"
}
}
+252
View File
@@ -137,3 +137,255 @@
.iwb-promptlib .iwb-plp-card { display: inline-block; width: 100%; margin: 0 0 8px; break-inside: avoid; -webkit-column-break-inside: avoid; aspect-ratio: auto; }
.iwb-promptlib .iwb-plp-cover { width: 100%; height: auto; object-fit: contain; }
.iwb-promptlib .iwb-plp-card.no-cover { aspect-ratio: 1 / 1; }
/* v1.5.0:模板节点 + 变量标记 */
.iwb-plp-vdot{position:absolute;right:8px;top:8px;width:7px;height:7px;border-radius:50%;background:var(--iwb-plp-accent, #7c4dff);box-shadow:0 0 0 2px var(--iwb-plp-dot-ring, rgba(255,255,255,.75))}
.iwb-plp-node{display:flex;flex-direction:column;gap:6px;padding:8px 10px;font-size:12px;color:var(--iwb-text,#1c2333)}
.iwb-plp-nhead{display:flex;align-items:center;gap:8px}
.iwb-plp-nthumb{width:44px;height:44px;border-radius:8px;object-fit:cover;flex:0 0 auto}
.iwb-plp-ntitle{font-weight:600;font-size:12.5px;line-height:1.3;overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}
.iwb-plp-nvars{display:flex;flex-direction:column;gap:4px}
.iwb-plp-nrow{display:flex;align-items:center;gap:6px;height:26px}
.iwb-plp-nk{width:64px;flex:0 0 64px;color:var(--iwb-text2,#5b6472);font-size:11.5px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.iwb-plp-nin{flex:1;height:24px;font-size:11.5px}
.iwb-plp-nref{display:flex;align-items:center;gap:6px;font-size:11.5px;color:var(--iwb-text2,#5b6472);border-top:1px dashed var(--iwb-border,#e3e5e9);padding-top:6px}
.iwb-plp-nref em{font-style:normal;color:var(--iwb-text2,#8b929c)}
.iwb-plp-nprev{margin-top:2px;border-top:1px dashed var(--iwb-border,#e3e5e9);padding-top:6px;color:var(--iwb-text2,#5b6472);font-size:11.5px;line-height:1.6;max-height:88px;overflow:hidden}
/* v1.5.0:变量编辑器 / 详情变量 */
.iwb-plp-emid{flex:1;min-width:0;display:flex;flex-direction:column;gap:8px}
.iwb-plp-vars{border:1px solid var(--iwb-border,#e3e5e9);border-radius:10px;padding:8px 10px;display:flex;flex-direction:column;gap:6px;background:var(--iwb-plugin-surface,#fff)}
.iwb-plp-vhead{display:flex;align-items:center;gap:8px;font-size:11.5px;color:var(--iwb-text2,#5b6472)}
.iwb-plp-vhint{color:var(--iwb-text2,#8b929c);font-size:11px}
.iwb-plp-vchips{display:flex;flex-wrap:wrap;gap:6px}
.iwb-plp-vchip{display:inline-flex;align-items:center;gap:4px;padding:1px 7px;border-radius:6px;background:color-mix(in srgb, var(--iwb-plp-accent, #7c4dff) 10%, transparent);color:var(--iwb-plp-accent, #5a4bd0);font-size:11.5px}
.iwb-plp-vx{font-style:normal;cursor:pointer;color:var(--iwb-plp-accent, #8b7ff0);font-weight:700}
.iwb-plp-vrows{display:flex;flex-direction:column;gap:5px}
.iwb-plp-vrow{display:flex;align-items:center;gap:8px}
.iwb-plp-vk{width:92px;flex:0 0 92px;font-size:11.5px;color:var(--iwb-text2,#5b6472);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.iwb-plp-vin{flex:1;height:26px;font-size:11.5px}
.iwb-plp-vprev{margin-top:2px;border-top:1px dashed var(--iwb-border,#e3e5e9);padding-top:6px;font-size:11.5px;line-height:1.6;color:var(--iwb-text2,#5b6472);max-height:72px;overflow:auto;white-space:pre-wrap}
.iwb-plp-dvars{display:flex;flex-direction:column;gap:5px;border:1px solid var(--iwb-border,#e3e5e9);border-radius:10px;padding:8px 10px}
/* v1.5.6:模板节点参照风格节点 —— 封面 + 名称 + 变量,正文不再铺开 */
.iwb-plp-nthumb{width:56px;height:56px;border-radius:8px;object-fit:cover;flex:0 0 auto}
.iwb-plp-ntitlebox{min-width:0;display:flex;flex-direction:column;gap:2px}
.iwb-plp-ntitle{font-weight:600;font-size:12.5px;line-height:1.3;overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}
.iwb-plp-nmeta{font-size:10.5px;color:var(--iwb-text2,#8b929c)}
.iwb-plp-nempty{font-size:11px;color:var(--iwb-text2,#8b929c);padding:2px 0}
.iwb-plp-nwarn{font-size:11px;line-height:1.5;color:var(--iwb-warn,#d97706)}
/* v1.5.10:设置页 */
.iwb-plp-settings{display:flex;flex-direction:column;gap:18px}
.iwb-plp-ssec{border:1px solid var(--iwb-border,#e3e5e9);border-radius:12px;padding:12px 14px;display:flex;flex-direction:column;gap:8px}
.iwb-plp-stitle{font-weight:600;font-size:12.5px}
.iwb-plp-sgroups{display:flex;flex-direction:column;border:1px solid var(--iwb-border,#eef0f2);border-radius:10px;overflow:hidden}
.iwb-plp-sgrow{display:flex;align-items:center;gap:8px;padding:7px 10px;border-top:1px solid var(--iwb-border,#f1f3f5)}
.iwb-plp-sgrow:first-child{border-top:0}
.iwb-plp-sgrip{width:12px;height:12px;background:radial-gradient(var(--iwb-text2,#c2c7cf) 1px,transparent 1px);background-size:4px 4px;border-radius:3px;flex:0 0 auto}
.iwb-plp-sgname{width:170px;height:26px;font-size:12px}
.iwb-plp-sgcount{font-size:11.5px;color:var(--iwb-text2,#8b929c);width:56px}
.iwb-plp-sadd{display:flex;gap:8px;align-items:center}
.iwb-plp-sbtns{display:flex;gap:8px;align-items:center}
.iwb-plp-sopt{display:flex;gap:8px;align-items:center;font-size:12px;color:var(--iwb-text2,#4d5668)}
.iwb-plp-settings{max-height:calc(100vh - 230px);overflow:auto;padding-right:4px}
/* v1.6.2:正文上方工具行 */
.iwb-plp-etool{display:flex;align-items:center;gap:8px}
.iwb-plp-insvar{border:1px solid var(--iwb-plp-accent,#d9d3ff);background:color-mix(in srgb,var(--iwb-plp-accent,#7c4dff) 8%,transparent);color:var(--iwb-plp-accent,#5a4bd0);font-weight:600}
/* v1.6.5:宿主基础样式的插件作用域副本 —— 宿主改全局样式不再影响插件 */
.iwb-promptlib .iwb-grow {
flex: 1;
}
.iwb-promptlib .iwb-row {
display: flex; gap: 6px; align-items: center;
}
.iwb-promptlib .iwb-hint {
font-size: 10px; color: var(--iwb-text2); margin-top: 4px;
}
.iwb-promptlib .iwb-toolbar-title {
font-weight: 700; font-size: 13px; margin-right: 2px;
}
.iwb-plp-mask {
position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 300; display: flex; align-items: center; justify-content: center;
}
.iwb-plp-dialog {
width: 680px; max-width: calc(100vw - 60px); max-height: 82vh; background: var(--iwb-panel); border: 1px solid var(--iwb-border2); border-radius: 14px; display: flex; flex-direction: column; overflow: hidden;
}
.iwb-plp-dialog-head {
display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--iwb-border);
}
.iwb-plp-dialog-body {
padding: 14px 16px; overflow: auto; display: flex; flex-direction: column; gap: 10px; max-height: 62vh;
}
.iwb-promptlib .iwb-lib-body {
flex: 1; overflow: hidden; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px;
}
.iwb-promptlib .iwb-lib-fixed {
flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px;
}
.iwb-promptlib .iwb-lib-scroll {
flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding-right: 2px;
}
.iwb-promptlib .iwb-lib-chips-scroll::-webkit-scrollbar {
display: none;
}
.iwb-promptlib .iwb-lib-chips-scroll > .iwb-chip:last-child {
margin-right: 18px;
}
.iwb-promptlib .iwb-lib-searchscope-back {
display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; padding: 0; border: none; border-radius: 999px; background: transparent; color: var(--iwb-text2); font-size: 13px; line-height: 1; cursor: pointer;
}
.iwb-promptlib .iwb-lib-searchscope-back:hover {
background: color-mix(in srgb, var(--iwb-text) 12%, transparent); color: var(--iwb-text);
}
.iwb-promptlib .iwb-chip {
flex: 0 0 auto; display: inline-flex; align-items: center; gap: 4px; background: var(--iwb-layer); border: 1px solid var(--iwb-border); border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--iwb-text2); cursor: pointer; white-space: nowrap; transition: all 0.15s;
}
.iwb-promptlib .iwb-chip:hover {
color: var(--iwb-text); border-color: var(--iwb-border2);
}
.iwb-promptlib .iwb-chip-active {
background: var(--iwb-panel); border-color: var(--iwb-border2); color: var(--iwb-text); font-weight: 600;
}
.iwb-promptlib .iwb-chip-active:hover {
color: var(--iwb-text);
}
.iwb-promptlib .iwb-chip-count {
font-size: 10px; opacity: 0.8;
}
.iwb-promptlib .iwb-chip-add {
font-weight: 700;
}
.iwb-promptlib .iwb-pcard .iwb-btn:hover {
opacity: 1; color: var(--iwb-text); background: transparent;
}
.iwb-promptlib .iwb-pcard .iwb-btn-starred {
color: var(--iwb-text); opacity: 1;
}
.iwb-promptlib .iwb-pcard {
border: 1px solid var(--iwb-border); border-radius: 8px; padding: 8px 10px; background: var(--iwb-panel);
}
.iwb-promptlib .iwb-tag {
display: inline-block; background: color-mix(in srgb, var(--iwb-text) 7%, transparent); color: var(--iwb-text2); border-radius: 4px; font-size: 10px; padding: 1px 6px; margin: 3px 4px 0 0;
}
.iwb-plp-dialog-sm {
width: 460px;
}
.iwb-promptlib .iwb-pcard {
cursor: grab;
}
.iwb-promptlib .iwb-pcard:active {
cursor: grabbing;
}
.iwb-promptlib .iwb-btn-primary .iwb-ic {
width: 15px; height: 15px;
}
.iwb-promptlib .iwb-btn:hover {
border-color: var(--iwb-brand); color: var(--iwb-brand);
}
.iwb-promptlib .iwb-btn:active {
transform: translateY(1px);
}
.iwb-promptlib .iwb-btn:focus-visible {
outline: 2px solid color-mix(in srgb, var(--iwb-brand) 60%, transparent); outline-offset: 1px;
}
.iwb-promptlib .iwb-btn:disabled {
opacity: 0.45; cursor: not-allowed; transform: none;
}
.iwb-promptlib .iwb-btn-primary {
background: var(--iwb-brand); border-color: var(--iwb-brand); color: var(--iwb-on-brand);
}
.iwb-promptlib .iwb-btn-primary:hover {
background: color-mix(in srgb, var(--iwb-brand) 85%, var(--iwb-text)); border-color: var(--iwb-brand); color: var(--iwb-on-brand);
}
.iwb-promptlib .iwb-btn-sm {
padding: 3px 7px; font-size: 11px;
}
.iwb-promptlib .iwb-btn-danger {
color: var(--iwb-err);
}
.iwb-promptlib .iwb-btn-danger:hover {
border-color: var(--iwb-err); color: var(--iwb-err);
}
.iwb-promptlib .iwb-ctxmenu {
position: fixed; min-width: 196px; max-width: 240px; max-height: calc(100vh - 24px); overflow-y: auto; padding: 6px; background: var(--iwb-layer); border: 1px solid var(--iwb-border); border-radius: 12px; box-shadow: 0 12px 32px rgba(0,0,0,0.28), 0 2px 8px rgba(0,0,0,0.16); z-index: 91; display: flex; flex-direction: column; gap: 2px;
}
.iwb-promptlib .iwb-ctx-title {
font-size: 10px; font-weight: 700; color: var(--iwb-text2); letter-spacing: 1px; padding: 6px 10px 2px; text-transform: uppercase;
}
.iwb-promptlib .iwb-ctx-item {
display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; border: none; border-radius: 8px; background: transparent; color: var(--iwb-text); font-size: 12.5px; cursor: pointer; text-align: left;
}
.iwb-promptlib .iwb-ctx-item .iwb-ic {
width: 14px; height: 14px; flex: 0 0 auto; color: var(--iwb-text2);
}
.iwb-promptlib .iwb-ctx-item:hover:not(:disabled) {
background: color-mix(in srgb, var(--iwb-brand) 12%, transparent); color: var(--iwb-text);
}
.iwb-promptlib .iwb-ctx-item:hover:not(:disabled) .iwb-ic {
color: var(--iwb-brand);
}
.iwb-promptlib .iwb-ctx-item:disabled {
opacity: 0.38; cursor: default;
}
.iwb-promptlib .iwb-ctx-item.iwb-ctx-danger {
color: var(--iwb-err);
}
.iwb-promptlib .iwb-ctx-item.iwb-ctx-danger .iwb-ic {
color: var(--iwb-err);
}
.iwb-promptlib .iwb-ctx-item.iwb-ctx-danger:hover:not(:disabled) {
background: color-mix(in srgb, var(--iwb-err) 10%, transparent); color: var(--iwb-err);
}
.iwb-promptlib .iwb-ctx-sep {
height: 1px; margin: 4px 6px; background: var(--iwb-border); flex: 0 0 auto;
}
.iwb-promptlib .iwb-drawer-spacer {
flex: 1 1 auto;
}
.iwb-plp-dialog .iwb-section-sub {
margin-top: 2px;
}
.iwb-plp-mask.iwb-mask-ghost .iwb-settings-modal {
box-shadow: 0 24px 60px rgba(0,0,0,.32);
}
/* v1.6.7:卡片长按可拖的视觉反馈 */
.iwb-plp-card{cursor:grab}
.iwb-plp-card.is-armed{border-color:var(--iwb-plp-accent,#7c4dff);box-shadow:0 0 0 2px color-mix(in srgb,var(--iwb-plp-accent,#7c4dff) 20%,transparent)}
.iwb-plp-card.is-dragging{opacity:.55;transform:scale(.98);cursor:grabbing}
/* v1.6.8:卡片悬停放大 + 按下/拖拽反馈 */
.iwb-plp-card{transition:transform .14s ease, box-shadow .14s ease, border-color .14s ease, opacity .14s ease}
.iwb-plp-card:hover{transform:scale(1.03);box-shadow:0 8px 22px rgba(0,0,0,.14);z-index:2}
.iwb-plp-card.is-pressed{border-color:var(--iwb-plp-accent,#7c4dff);box-shadow:0 0 0 2px color-mix(in srgb,var(--iwb-plp-accent,#7c4dff) 22%,transparent)}
.iwb-plp-card.is-dragging{opacity:.55;transform:scale(.98)}
/* v1.6.9:拖拽虚拟卡片(跟手预览) */
.iwb-plp-dragghost{width:168px;display:flex;align-items:center;gap:8px;padding:8px 10px;background:var(--iwb-panel,#fff);border:2px solid var(--iwb-plp-accent,#7c4dff);border-radius:11px;box-shadow:0 12px 28px rgba(0,0,0,.22);font-size:12px;pointer-events:none;z-index:99999}
.iwb-plp-ghostcov{width:38px;height:38px;border-radius:8px;object-fit:cover;flex:0 0 auto;background:var(--iwb-plugin-inset,#eef0f2)}
.iwb-plp-ghosttxt{min-width:0;display:flex;flex-direction:column;gap:2px}
.iwb-plp-ghostname{font-weight:600;color:var(--iwb-text,#1c2333);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.iwb-plp-ghosthint{font-size:10.5px;color:var(--iwb-plp-accent,#5a4bd0)}
/* v1.6.10:悬停放大改为「内层背景层缩放」——卡片命中区域不变,渐变卡不再闪烁 */
.iwb-plp-bg{position:absolute;inset:0;overflow:hidden;border-radius:inherit;transition:transform .16s ease;will-change:transform;backface-visibility:hidden}
.iwb-plp-card:hover .iwb-plp-bg{transform:scale(1.045)}
.iwb-plp-card:hover{border-color:var(--iwb-border2,#b9bfca);box-shadow:0 8px 22px rgba(0,0,0,.14)}
/* 取消卡片本体的缩放/层级切换(闪烁与边缘点击丢失的来源) */
.iwb-plp-card{transform:none}
.iwb-plp-card:hover{transform:none;z-index:auto}
.iwb-plp-card.is-dragging{opacity:.55}
.iwb-plp-bg,.iwb-plp-cover{pointer-events:none}
/* v1.6.11:封面卡瀑布流高度由图片决定 —— 背景层必须是普通流,不能绝对定位(否则卡塌成一条线) */
.iwb-plp-bg{position:relative;inset:auto;width:100%}
.iwb-plp-card.no-cover .iwb-plp-bg{position:absolute;inset:0}
.iwb-plp-bg .iwb-plp-cover{width:100%;height:auto;object-fit:contain;display:block}
/* v1.6.13:未选中时变量输入框不拦截指针 —— 单击节点=选中/可拖动;选中后再点输入框编辑 */
.iwb-plp-node:not(.is-selected) input{pointer-events:none}
.iwb-plp-card{user-select:none}
body.iwb-plp-dragging, body.iwb-plp-dragging *{user-select:none!important;-webkit-user-select:none!important}
@@ -138,7 +138,7 @@
position: fixed; z-index: 2147483000; left: 0; top: 0; pointer-events: none;
padding: 5px 10px; border-radius: 6px; font-size: 12px; line-height: 1.2;
font-family: inherit; white-space: nowrap;
background: rgba(22, 26, 34, .88); color: #fff;
background: color-mix(in srgb, var(--iwb-text, #1c2333) 88%, transparent); color: var(--iwb-on-brand, #fff);
border: 1px dashed rgba(255, 255, 255, .55);
transform: translate(-2px, -2px);
}
@@ -283,7 +283,7 @@
position: absolute; left: 50%; bottom: 46px; z-index: 20;
transform: translateX(-50%) translateY(6px);
max-width: 88%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
background: rgba(22, 26, 34, .9); color: #fff;
background: color-mix(in srgb, var(--iwb-text, #1c2333) 90%, transparent); color: var(--iwb-on-brand, #fff);
font-size: var(--fs-md, 12px); padding: 6px 12px; border-radius: 14px;
opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease;
}
@@ -338,7 +338,7 @@
.iwb-ssn-row > input:focus { outline: none; border-color: var(--iwb-brand, #1677ff); }
.iwb-ssn-row > input::placeholder { color: var(--iwb-text2, #6b7280); opacity: .6; }
.iwb-ssn-foot { display: flex; align-items: center; gap: 6px; font-size: 10.5px; color: var(--iwb-text2, #6b7280); }
.iwb-ssn-warn { color: #d97706; }
.iwb-ssn-warn { color: var(--iwb-warn, #d97706); }
.iwb-ssn-empty { padding: 6px 2px; font-size: 11px; color: var(--iwb-text2, #6b7280); line-height: 1.6; }
`
@@ -1384,7 +1384,7 @@
global.IWBPluginHost.register({
id: 'style-source',
name: '风格库',
version: '1.3.2',
version: '1.3.3',
apiVersion: 1,
capabilities: ['panels', 'canvas', 'canvasWrite', 'nodeTypes'],
settings: {
+3
View File
@@ -69,6 +69,8 @@ const sourceModules = [
'storage-outputs.js',
'storage-backup.js',
'storage-zip.js',
'plugin-archive.js',
'plugin-promptlib-backup.js',
'runtime-constants.js',
'canvas-store.js',
'generation-scheduler.js',
@@ -131,6 +133,7 @@ const sourceModules = [
'ui-connect-menu.js',
'ui-gen-config-panel.js',
'canvas-webview.js',
'plugin-files-policy.js',
'image-prompt-cover.js',
]
+1
View File
@@ -90,6 +90,7 @@ const html = `<!doctype html>
<a href="/">首页</a>
<a href="/download/" class="on">下载</a>
<a href="/plugins/">插件</a>
<a href="/dev/">开发</a>
<a href="https://git.maqiart.eu.org/malongan/image-workbench-desktop" target="_blank" rel="noopener">源码</a>
</div>
<div class="right">
+76
View File
@@ -28,6 +28,7 @@ const nav = (active) => [
' <a href="/"' + (active === 'home' ? ' class="on"' : '') + '>首页</a>',
' <a href="/download/"' + (active === 'download' ? ' class="on"' : '') + '>下载</a>',
' <a href="/plugins/"' + (active === 'plugins' ? ' class="on"' : '') + '>插件</a>',
' <a href="/dev/"' + (active === 'dev' ? ' class="on"' : '') + '>开发</a>',
' <a href="https://git.maqiart.eu.org/malongan/image-workbench-desktop" target="_blank" rel="noopener">源码</a>',
' </div>',
' <div class="right">',
@@ -83,6 +84,69 @@ const tags = []
for (const p of plugins) for (const t of (p.tags || [])) if (tags.indexOf(t) < 0) tags.push(t)
const tagChips = tags.map((t) => '<button class="tag" data-tag="' + esc(t) + '" style="cursor:pointer;padding:5px 12px">' + esc(t) + '</button>').join('\n ')
function mdToHtml (md) {
const esc2 = (s) => String(s).replace(/[&<>]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;' }[c]))
const inline = (s) => esc2(s)
.replace(/`([^`]+)`/g, '<code>$1</code>')
.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>')
const lines = String(md).split('\n')
const out = []
let i = 0
let inCode = false
let code = []
let inList = ''
const closeList = () => { if (inList) { out.push('</' + inList + '>'); inList = '' } }
while (i < lines.length) {
const line = lines[i]
if (line.trim().indexOf('```') === 0) {
if (!inCode) { inCode = true; code = [] } else {
inCode = false
out.push('<pre><code>' + esc2(code.join('\n')) + '</code></pre>')
}
i++; continue
}
if (inCode) { code.push(line); i++; continue }
if (!line.trim()) { closeList(); i++; continue }
if (/^---+$/.test(line.trim())) { closeList(); out.push('<hr>'); i++; continue }
const h = line.match(/^(#{1,4})\s+(.*)$/)
if (h) { closeList(); out.push('<h' + h[1].length + '>' + inline(h[2]) + '</h' + h[1].length + '>'); i++; continue }
if (line.trim().indexOf('|') === 0) {
const rows = []
while (i < lines.length && lines[i].trim().indexOf('|') === 0) rows.push(lines[i++])
const cells = rows.map((r) => r.trim().replace(/^\||\|$/g, '').split('|').map((c) => c.trim()))
if (cells.length > 1) {
out.push('<table><thead><tr>' + cells[0].map((c) => '<th>' + inline(c) + '</th>').join('') + '</tr></thead><tbody>')
for (let r = 2; r < cells.length; r++) out.push('<tr>' + cells[r].map((c) => '<td>' + inline(c) + '</td>').join('') + '</tr>')
out.push('</tbody></table>')
}
continue
}
if (/^ \S/.test(line)) {
closeList()
const block = []
while (i < lines.length && (/^ /.test(lines[i]) || !lines[i].trim())) { block.push(lines[i].replace(/^ /, '')); i++ }
while (block.length && !block[block.length - 1].trim()) block.pop()
out.push('<pre><code>' + esc2(block.join('\n')) + '</code></pre>')
continue
}
const li = line.match(/^\s*[-*]\s+(.*)$/)
if (li) {
if (inList !== 'ul') { closeList(); out.push('<ul>'); inList = 'ul' }
out.push('<li>' + inline(li[1]) + '</li>'); i++; continue
}
const ol = line.match(/^\s*\d+\.\s+(.*)$/)
if (ol) {
if (inList !== 'ol') { closeList(); out.push('<ol>'); inList = 'ol' }
out.push('<li>' + inline(ol[1]) + '</li>'); i++; continue
}
closeList(); out.push('<p>' + inline(line) + '</p>'); i++
}
closeList()
if (inCode) out.push('<pre><code>' + esc2(code.join('\n')) + '</code></pre>')
return out.join('\n')
}
function render(tpl, map) {
let out = fs.readFileSync(path.join(site, tpl), 'utf8')
for (const k of Object.keys(map)) out = out.split('<!--' + k + '-->').join(map[k])
@@ -113,4 +177,16 @@ pluginsPage = pluginsPage.replace('/assets/style.css', '/assets/style.css?v=' +
fs.writeFileSync(path.join(site, 'plugins', 'index.html'), pluginsPage)
fs.writeFileSync(path.join(site, 'plugins-index.json'), JSON.stringify(market, null, 2) + '\n')
// 插件开发规范(由 docs/standards/plugin-development.md 生成)
const devMdPath = path.join(root, 'docs', 'standards', 'plugin-development.md')
if (fs.existsSync(devMdPath)) {
const devPage = render('_dev.tpl.html', {
NAV: nav('dev'),
FOOTER: footer,
DEV_CONTENT: mdToHtml(fs.readFileSync(devMdPath, 'utf8')),
}).replace('/assets/style.css', '/assets/style.css?v=' + STAMP)
fs.mkdirSync(path.join(site, 'dev'), { recursive: true })
fs.writeFileSync(path.join(site, 'dev', 'index.html'), devPage)
}
console.log('站点已生成:首页 / 插件页(' + plugins.length + ' 个插件,' + tags.length + ' 个标签,版本 v' + V + ')')
+21
View File
@@ -110,5 +110,26 @@ console.log("latest.json -> v" + v + " platforms: " + Object.keys(j.platforms).
$SCP /tmp/iwb-latest.json "$NAS_HOST:$NAS_DIR/updates/latest.json"
ssh -i "$SSH_KEY" -o BatchMode=yes "$NAS_HOST" "chmod -R a+rX $NAS_DIR"
# == 自动对齐文档锚点 ==
# 规则:main = <sha> 必须是「最近一次 bump 版本的提交」。以前每次发版要手工改两次锚点,
# 现在由发布脚本收尾:写锚点 + 同步 facts + 本地提交(推送仍随版本一起做)。
if git rev-parse --git-dir >/dev/null 2>&1; then
HEAD_V=$(git show HEAD:package.json 2>/dev/null | node -e 'let t="";process.stdin.on("data",d=>t+=d).on("end",()=>{try{console.log(JSON.parse(t).version)}catch(e){console.log("")}})') || true
if [ "$HEAD_V" != "$V" ]; then
echo "WARN 版本号尚未提交(HEAD=${HEAD_V} 本地=${V}):跳过锚点自动对齐,请先提交再发布"
else
BUMP_SHA=$(git log -1 --format=%h -- package.json || true)
if [ -n "$BUMP_SHA" ]; then
node scripts/set-doc-anchor.js "$V" "$BUMP_SHA" || true
node scripts/sync-facts.js --write >/dev/null 2>&1 || true
if ! git diff --quiet -- docs/standards/architecture-current-state.md CONTRIBUTING.md 2>/dev/null; then
git add docs/standards/architecture-current-state.md CONTRIBUTING.md 2>/dev/null || true
GIT_AUTHOR_NAME=qiqi GIT_AUTHOR_EMAIL=qiqi@local GIT_COMMITTER_NAME=qiqi GIT_COMMITTER_EMAIL=qiqi@local git commit -q -m "docs: 锚点对齐 v${V}+${BUMP_SHA}(publish 自动)" || true
echo "== 文档锚点已自动对齐并本地提交:${BUMP_SHA}(随版本一起 push)"
fi
fi
fi
fi
echo "== 完成:https://download.maqiart.eu.org/updates/latest.json"
curl -s -m 15 https://download.maqiart.eu.org/updates/latest.json | head -c 200; echo
+31
View File
@@ -0,0 +1,31 @@
#!/usr/bin/env node
/* set-doc-anchor.js —— 把架构文档的基线锚点写成「最近一次 bump 版本的提交」
*
* 用法:node scripts/set-doc-anchor.js <version> <sha>
* 只改 docs/standards/architecture-current-state.md 的两处:
* main = <sha>
* 线上 `vX.Y.Z+<sha>`
* 返回:0=已更新 / 2=没有变化 / 1=文件缺失
*/
const fs = require('fs')
const path = require('path')
const ver = String(process.argv[2] || '')
const sha = String(process.argv[3] || '')
const file = path.join(__dirname, '..', 'docs', 'standards', 'architecture-current-state.md')
if (!ver || !sha) { console.error('用法: set-doc-anchor.js <version> <sha>'); process.exit(1) }
if (!fs.existsSync(file)) { console.error('缺少 ' + file); process.exit(1) }
const bt = String.fromCharCode(96)
const before = fs.readFileSync(file, 'utf8')
let after = before.replace(
new RegExp(bt + 'main = [0-9a-f]+' + bt),
bt + 'main = ' + sha + bt,
)
after = after.replace(
new RegExp('线上 ' + bt + 'v[0-9.]+[^' + bt + ']*' + bt),
'线上 ' + bt + 'v' + ver + '+' + sha + bt,
)
if (after === before) { console.log('anchor unchanged (' + sha + ')'); process.exit(2) }
fs.writeFileSync(file, after)
console.log('anchor -> ' + sha + ' (v' + ver + ')')
+5
View File
@@ -19,6 +19,11 @@ const IDS = ['batch-export', 'blank-canvas', 'browser', 'gallery', 'grouplib', '
// 若不同步成目录,插件自带样式会被静默忽略(v1.0.3 grouplib 换行样式的坑)。
const FOLDER_IDS = ['gallery']
// 刻意不随客户端/市场发布的插件(开发者直装):
// ai-chat —— 依赖本机 Magpie(3425) + 需宿主 CSP 放行,上架会让多数用户装上连不上。
// 详见 ../iwb-plugins-desktop/ai-chat/README.md「状态」一节。
const DEV_ONLY_IDS = ['ai-chat']
const sha = (buf) => crypto.createHash('sha256').update(buf).digest()
const shaHex = (buf) => sha(buf).toString('hex')
const sri = (buf) => 'sha256-' + sha(buf).toString('base64')
+30
View File
@@ -0,0 +1,30 @@
<!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">
<style>
.devdoc{max-width:860px;margin:0 auto;padding:40px 0 72px;color:var(--ink,#1b1f24);font-size:15px;line-height:1.75}
.devdoc h1{font-size:38px;line-height:1.2;margin:8px 0 18px}
.devdoc h2{font-size:24px;margin:38px 0 10px;padding-top:10px;border-top:1px solid var(--line,#e6e8ec)}
.devdoc h3{font-size:18px;margin:26px 0 8px}
.devdoc p{margin:10px 0}
.devdoc ul,.devdoc ol{margin:10px 0 10px 22px}
.devdoc li{margin:4px 0}
.devdoc code{background:#f3f4f6;border-radius:5px;padding:1px 5px;font-size:13px}
.devdoc pre{background:#111418;color:#e6e8ec;border-radius:10px;padding:14px 16px;overflow:auto;font-size:13px;line-height:1.6}
.devdoc pre code{background:none;color:inherit;padding:0}
.devdoc table{border-collapse:collapse;width:100%;margin:14px 0;font-size:14px}
.devdoc th,.devdoc td{border:1px solid var(--line,#e6e8ec);padding:7px 10px;text-align:left;vertical-align:top}
.devdoc th{background:#f7f8fa}
.devdoc blockquote{border-left:3px solid #d6dae1;margin:12px 0;padding:2px 14px;color:#5b6472}
.devdoc a{color:#2b6cff}
</style>
</head><body>
<!--NAV-->
<main>
<div class="wrap"><article class="devdoc">
<!--DEV_CONTENT-->
</article></div>
</main>
<!--FOOTER-->
</body></html>
+194
View File
@@ -0,0 +1,194 @@
<!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.26.39-mwrxcd5p">
<style>
.devdoc{max-width:860px;margin:0 auto;padding:40px 0 72px;color:var(--ink,#1b1f24);font-size:15px;line-height:1.75}
.devdoc h1{font-size:38px;line-height:1.2;margin:8px 0 18px}
.devdoc h2{font-size:24px;margin:38px 0 10px;padding-top:10px;border-top:1px solid var(--line,#e6e8ec)}
.devdoc h3{font-size:18px;margin:26px 0 8px}
.devdoc p{margin:10px 0}
.devdoc ul,.devdoc ol{margin:10px 0 10px 22px}
.devdoc li{margin:4px 0}
.devdoc code{background:#f3f4f6;border-radius:5px;padding:1px 5px;font-size:13px}
.devdoc pre{background:#111418;color:#e6e8ec;border-radius:10px;padding:14px 16px;overflow:auto;font-size:13px;line-height:1.6}
.devdoc pre code{background:none;color:inherit;padding:0}
.devdoc table{border-collapse:collapse;width:100%;margin:14px 0;font-size:14px}
.devdoc th,.devdoc td{border:1px solid var(--line,#e6e8ec);padding:7px 10px;text-align:left;vertical-align:top}
.devdoc th{background:#f7f8fa}
.devdoc blockquote{border-left:3px solid #d6dae1;margin:12px 0;padding:2px 14px;color:#5b6472}
.devdoc a{color:#2b6cff}
</style>
</head><body>
<nav><div class="wrap inner">
<a class="brand" href="/"><span class="dot">IW</span>Image Workbench</a>
<div class="links">
<a href="/">首页</a>
<a href="/download/">下载</a>
<a href="/plugins/">插件</a>
<a href="/dev/" class="on">开发</a>
<a href="https://git.maqiart.eu.org/malongan/image-workbench-desktop" target="_blank" rel="noopener">源码</a>
</div>
<div class="right">
<a class="btn" href="/plugins/">插件市场</a>
<a class="btn primary" href="/download/">下载 v3.26.39</a>
</div>
</div></nav>
<main>
<div class="wrap"><article class="devdoc">
<h1>Image Workbench 插件开发规范</h1>
<p>&gt; 版本:v1(2026-11-22)。面向官方与第三方插件;示例以 promptlib(提示词库)与 style-source(风格库)为准。</p>
<p>&gt; 相关文档:plugin-node-drag.md(节点拖入/指针交互踩坑)、plugin-node-outkind.md(下游连线声明)、plugin-theme.md(主题契约)。</p>
<h2>1. 目录与基本结构</h2>
<p>插件是「一个目录 + 一个 IIFE 入口」,由宿主在启用时动态加载并调用 register。</p>
<pre><code>my-plugin/
package.json # 版本 + ibwPlugin 元数据
src/index.js # 入口(IIFE,末尾 IWBPluginHost.register)
styles.css # 样式(必须自包含)
README.md</code></pre>
<p>package.json:</p>
<pre><code>{
"name": "@iwb-plugin/my-plugin",
"version": "1.0.0",
"ibwPlugin": { "id": "my-plugin", "entry": "src/index.js", "apiVersion": 1 }
}</code></pre>
<p>入口骨架:</p>
<pre><code>;(function (global) {
'use strict'
if (!global.IWBPluginHost) return
global.IWBPluginHost.register({
id: 'my-plugin',
name: '我的插件',
version: '1.0.0',
capabilities: ['panels', 'canvas', 'canvasWrite'],
settings: { panel: { type: 'custom', label: '设置', render: renderSettings } },
mount: mount,
unmount: unmount,
}, function (ctx) {
// setup:注册面板/节点/命令
return { dispose () {} }
})
})(typeof window !== 'undefined' ? window : globalThis)</code></pre>
<h2>2. 能力(capabilities)与 ctx 映射</h2>
<p>只申请用到的能力;能力名与 ctx 键不同:</p>
<table><thead><tr><th>capability</th><th>ctx 键</th><th>用途</th></tr></thead><tbody>
<tr><td>panels</td><td>ctx.ui</td><td>侧栏/独立面板注册</td></tr>
<tr><td>promptlib</td><td>ctx.promptlib</td><td>提示词库数据 + 文件 + 备份</td></tr>
<tr><td>nodeTypes</td><td>ctx.nodes</td><td>画布节点类型注册</td></tr>
<tr><td>canvas</td><td>ctx.canvas</td><td>只读:getNodes / getSelectedNode / screenToWorld</td></tr>
<tr><td>canvasWrite</td><td>ctx.canvasWrite</td><td>写入:createNode / createImageNode / setNodeImage</td></tr>
<tr><td>nodeActions</td><td>ctx.nodeActions</td><td>节点右键/气泡动作</td></tr>
<tr><td>commands</td><td>ctx.commands</td><td>命令面板</td></tr>
<tr><td>settings</td><td>ctx.settings</td><td>KV 配置</td></tr>
<tr><td>data</td><td>ctx.data</td><td>插件数据文件</td></tr>
</tbody></table>
<p><strong>注意</strong>:createNode 在 ctx.canvasWrite,不在 ctx.canvas。调错只会提示“宿主不支持”。</p>
<h2>3. 面板</h2>
<pre><code>ctx.ui.registerPanel({
id: 'my-panel',
title: '我的插件',
mount (host) { /* 渲染到 host */ },
unmount (host) { /* 清理定时器/监听 */ }
})</code></pre>
<ul>
<li>mount 只调用一次,内部自己管理重渲染。</li>
<li>面板宽度可变:使用栅格/瀑布流,不要写死 px 宽度。</li>
<li>面板内所有 DOM 事件在 unmount 时移除。</li>
</ul>
<h2>4. 节点类型</h2>
<pre><code>ctx.nodes.register({
id: 'tpl',
title: '模板节点',
defaults: { outKind: 'prompt' },
ports: { in: false, out: true },
height: 360,
render (node, props, host) { /* 首次建 DOM,之后 sync */ }
})</code></pre>
<p>宿主会生成类型 plugin:&lt;插件id&gt;:&lt;变体id&gt;。</p>
<p><strong>必须遵守</strong>:</p>
<ol>
<li>输出文本/提示词 → data.outKind = 'prompt'(注册默认值、拖入数据、旧节点在 render 里自愈)。</li>
<li>拖入画布用指针拖拽,不用原生 HTML5 DnD:</li>
</ol>
<pre><code>pointerdown → pointermove(&gt;5px) 幽灵卡片
→ pointerup → ctx.canvas.screenToWorld(x,y)
→ ctx.canvasWrite.createNode('tpl', wx, wy, data)</code></pre>
<ol>
<li>输入框:未选中时 pointer-events: none,选中后才可编辑;只读 textarea 同样处理。</li>
<li>单击 = 选中/拖动,双击 = 编辑;不要用单击打开详情。</li>
<li>节点 render 必须可增量 sync,避免整块重建(输入框会丢焦点)。</li>
</ol>
<h2>5. 数据与文件</h2>
<ul>
<li>小数据:ctx.promptlib(或 ctx.data)JSON,单文件 &lt; 1MB。</li>
<li>大文件(封面/图片):ctx.promptlib.filePut/fileGet/fileList,落地在 plugin-data/&lt;id&gt;/files/。</li>
<li>dataUrlToBytes() 返回 { mime, bytes },不是 Uint8Array。</li>
<li>备份:提供导出/导入 JSON;导入按 id 合并,提供“覆盖同 id”选项。</li>
<li>迁移:旧格式在 setup 里做一次性迁移,失败要提示而不是静默丢数据。</li>
</ul>
<h2>6. 设置页面</h2>
<p>宿主设置页内嵌渲染,不弹独立页面:</p>
<pre><code>settings: {
panel: { type: 'custom', label: '分组与备份', render: renderSettings }
}</code></pre>
<p>render 返回 DOM;宿主负责挂载/卸载。设置页适合放:</p>
<ul>
<li>分组管理(新建/改名/排序/删除)</li>
<li>数据备份(导出/导入)</li>
<li>数据位置(打开数据目录)</li>
<li>插件级开关/默认值</li>
</ul>
<h2>7. 样式规范</h2>
<ol>
<li><strong>自包含</strong>:宿主基础样式会变;用到的宿主类按作用域复制一份(.iwb-myplugin …)。</li>
<li>统一前缀:面板/节点类名 my-plugin-*,避免与宿主 .iwb-* 冲突。</li>
<li>颜色走 CSS 变量:var(--iwb-text)、--iwb-panel、--iwb-border、--iwb-plugin-accent。</li>
<li>动画克制:只做 hover/press 反馈;不使用持续浮动动画。</li>
<li>深色主题:不写死 #fff/#000;主题契约测试会扫描。</li>
<li>悬停放大只缩放内层背景,不缩放卡片本体(避免命中区域漂移/闪烁)。</li>
<li>图片/封面 pointer-events: none,点击永远落到卡片。</li>
</ol>
<h2>8. 错误处理与提示</h2>
<ul>
<li>所有用户可见错误用 ctx.promptlib.notify / ctx.ui.toast,文案给“下一步怎么办”。</li>
<li>异步链必须有 catch;不要吞掉错误后静默。</li>
<li>崩溃日志:window.onerror 由宿主统一采集,插件不要自己覆盖。</li>
<li>定时器/监听在 unmount/dispose 清理,避免面板切换后重复执行。</li>
</ul>
<h2>9. 测试与门禁</h2>
<p>提交前至少:</p>
<pre><code>node scripts/validate-plugins.js # manifest/能力/入口校验
node scripts/theme-contract-test.js # 主题变量
node tests/plugin-&lt;id&gt;-render-test.js # jsdom 渲染/交互</code></pre>
<p>jsdom 可覆盖:面板渲染、节点 render/sync、拖拽插入(stub screenToWorld/createNode)、双击详情、保存回详情、封面 img。</p>
<h2>10. 发布与市场</h2>
<ol>
<li>改 package.json version 与入口 version(两处一致)。</li>
<li>node scripts/sync-plugins-from-repo.js(同步到客户端 plugins/)</li>
<li>node scripts/gen-market.js(生成 market/ 与 zip)</li>
<li>上传 market 到 NAS(tar + scp + 解压)</li>
<li>客户端发版:set-version → CHANGELOG → 锚点 → verify:ci → build → publish-update → releases/site → tag/push</li>
</ol>
<h2>11. 常见坑(务必先读)</h2>
<ul>
<li>原生 HTML5 拖放:WKWebView 吞 pointerup,节点落地后第一次点击异常 → 用指针拖拽。</li>
<li>ctx.canvas 没有 createNode → 用 ctx.canvasWrite。</li>
<li>输入框拦截拖动 → 未选中时 pointer-events:none。</li>
<li>只读 textarea 仍可选中文本 → pointer-events:none。</li>
<li>dataUrlToBytes 返回对象 → 取 .bytes。</li>
<li>封面直接存 dataURL 会让 JSON 膨胀 → 迁移到文件,只存 { img }。</li>
<li>插件节点不声明 outKind → 只能中继,无法直连生图。</li>
</ul>
</article></div>
</main>
<footer><div class="wrap">
<div class="cols">
<div><div style="color:#fff;font-weight:640;margin-bottom:8px">Image Workbench</div>
<div style="font-size:13px;line-height:1.8">本地优先的 AI 生图无限画布。图片、提示词与模型配置全部留在你自己的电脑里。</div></div>
<div><h4>产品</h4><a href="/">首页</a><a href="/download/">下载</a><a href="/plugins/">插件市场</a></div>
<div><h4>资源</h4><a href="https://git.maqiart.eu.org/malongan/image-workbench-desktop" target="_blank" rel="noopener">源码仓库</a><a href="https://git.maqiart.eu.org/malongan/iwb-plugins-desktop" target="_blank" rel="noopener">插件仓库</a><a href="/updates/latest.json" target="_blank" rel="noopener">更新源</a></div>
<div><h4>说明</h4><a href="/download/">安装步骤</a><a href="/plugins/">插件安装</a></div>
</div>
<div class="copy"><span>© 2026 Image Workbench</span><span>数据保存在本地 · 不上传任何图片</span></div>
</div></footer>
</body></html>
+21 -4
View File
@@ -39,6 +39,7 @@
<a href="/">首页</a>
<a href="/download/" class="on">下载</a>
<a href="/plugins/">插件</a>
<a href="/dev/">开发</a>
<a href="https://git.maqiart.eu.org/malongan/image-workbench-desktop" target="_blank" rel="noopener">源码</a>
</div>
<div class="right">
@@ -54,13 +55,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.26.34 · 8.4 MB · .dmg<div class="hash">sha256 8107ee30acb00c46…</div></div>
<a class="btn" href="/updates/darwin-aarch64/image-workbench_3.26.34_aarch64.dmg?h=8107ee30acb0">下载</a>
<div class="meta">版本 3.26.39 · 8.4 MB · .dmg<div class="hash">sha256 15e9c10f31caea3a…</div></div>
<a class="btn" href="/updates/darwin-aarch64/image-workbench_3.26.39_aarch64.dmg?h=15e9c10f31ca">下载</a>
</div>
<div class="row">
<div class="name">macOS · Intel<div class="hint">x86_64</div></div>
<div class="meta">版本 3.26.34 · 8.8 MB · .dmg<div class="hash">sha256 f1c49824bcbab663…</div></div>
<a class="btn" href="/updates/darwin-x86_64/image-workbench_3.26.34_x64.dmg?h=f1c49824bcba">下载</a>
<div class="meta">版本 3.26.39 · 8.8 MB · .dmg<div class="hash">sha256 1016831ad95f21be…</div></div>
<a class="btn" href="/updates/darwin-x86_64/image-workbench_3.26.39_x64.dmg?h=1016831ad95f">下载</a>
</div>
<div class="row">
<div class="name">Windows · x64<div class="hint">需要 WebView2</div></div>
@@ -94,6 +95,22 @@
</ol>
<h2>历史版本</h2>
<div class="row">
<div class="name">3.26.39<div class="hint">Intel 版:同一版本</div></div>
<div class="meta">2026-11-22<div class="hint">macOS · Apple Silicon / macOS · Intel</div></div>
</div>
<div class="row">
<div class="name">3.26.38<div class="hint">Intel 版:同一版本</div></div>
<div class="meta">2026-11-22<div class="hint">macOS · Apple Silicon / macOS · Intel</div></div>
</div>
<div class="row">
<div class="name">3.26.37<div class="hint">Intel 版:同一版本</div></div>
<div class="meta">2026-11-22<div class="hint">macOS · Apple Silicon / macOS · Intel</div></div>
</div>
<div class="row">
<div class="name">3.26.35<div class="hint">Intel 版:同一改进</div></div>
<div class="meta">2026-11-22<div class="hint">macOS · Apple Silicon / macOS · Intel</div></div>
</div>
<div class="row">
<div class="name">3.26.34<div class="hint">Intel 版:同一优化</div></div>
<div class="meta">2026-11-22<div class="hint">macOS · Apple Silicon / macOS · Intel</div></div>
+9 -8
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.26.34-mwrhcagv">
<link rel="stylesheet" href="/assets/style.css?v=3.26.39-mwrxcd5p">
</head><body>
<nav><div class="wrap inner">
<a class="brand" href="/"><span class="dot">IW</span>Image Workbench</a>
@@ -10,23 +10,24 @@
<a href="/" class="on">首页</a>
<a href="/download/">下载</a>
<a href="/plugins/">插件</a>
<a href="/dev/">开发</a>
<a href="https://git.maqiart.eu.org/malongan/image-workbench-desktop" target="_blank" rel="noopener">源码</a>
</div>
<div class="right">
<a class="btn" href="/plugins/">插件市场</a>
<a class="btn primary" href="/download/">下载 v3.26.34</a>
<a class="btn primary" href="/download/">下载 v3.26.39</a>
</div>
</div></nav>
<main>
<section class="hero hero-art">
<div class="hero-bg"><img src="/assets/painting.jpg?v=3.26.34-mwrhcagv" alt=""></div>
<div class="hero-bg"><img src="/assets/painting.jpg?v=3.26.39-mwrxcd5p" alt=""></div>
<div class="hero-veil"></div>
<div class="wrap">
<span class="kicker">v3.26.34 · macOS / Windows · 数据在本地</span>
<span class="kicker">v3.26.39 · macOS / Windows · 数据在本地</span>
<h1>本地优先的<br>AI 生图无限画布</h1>
<p class="sub">用节点把「参考图 → 提示词 → 批量生成 → 图库」串成一条生产线。<br>图片、提示词、模型配置全部留在你自己的电脑里,插件按需安装。</p>
<div class="cta">
<a class="btn primary lg" href="/download/">下载 v3.26.34</a>
<a class="btn primary lg" href="/download/">下载 v3.26.39</a>
<a class="btn lg" href="/plugins/">浏览 11 个插件</a>
</div>
<div class="meta">支持 macOS 12+ 与 Windows 10 1803+ · 安装包约 7 MB · 无需登录</div>
@@ -82,7 +83,7 @@
</div>
<div class="pcard" data-name="提示词库 promptlib 右栏提示词列表:搜索/分组/收藏/新建编辑/插入画布/复制(数据由客户端提供) 资源 提示词" data-tags="资源,提示词">
<div class="head"><span class="av" style="background:#eef2f6">📖</span>
<div><div class="nm">提示词库</div><div class="ver">v1.4.10 · 官方</div></div></div>
<div><div class="nm">提示词库</div><div class="ver">v1.6.18 · 官方</div></div></div>
<div class="desc">右栏提示词列表:搜索/分组/收藏/新建编辑/插入画布/复制(数据由客户端提供)</div>
<div class="tags"><span class="tag">资源</span><span class="tag">提示词</span></div>
</div>
@@ -93,8 +94,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.26.34_aarch64.dmg?h=8107ee30acb0"><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.26.34_x64.dmg?h=f1c49824bcba"><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.26.39_aarch64.dmg?h=15e9c10f31ca"><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.26.39_x64.dmg?h=1016831ad95f"><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>
+21 -21
View File
@@ -1,6 +1,6 @@
{
"version": 2,
"updatedAt": "2026-11-21T16:18:40.867Z",
"updatedAt": "2026-11-22T14:17:37.777Z",
"plugins": [
{
"id": "batch-export",
@@ -180,26 +180,26 @@
"资源",
"提示词"
],
"version": "1.4.10",
"version": "1.6.18",
"apiVersion": 1,
"bundle": "plugins/promptlib-1.4.10.zip",
"bundleSize": 49682,
"bundleSha256": "d5ffef4a9c6b5efe359e071476b76f015d6ae2e5a5982dfca461069c21cf0d96",
"bundle": "plugins/promptlib-1.6.18.zip",
"bundleSize": 122581,
"bundleSha256": "7397f802ad45110ecdc18cefe908921a8305e46580af0cad5de379f4058817e9",
"files": [
{
"path": "manifest.json",
"sha256": "4b8375d1b21bc2ffc29ea93959e7f990751351362f71ae37e1b46ed2e040d99b",
"sha256": "fdcee6bb4051a656186937fdd424139c282c45d4b3c8c47c0e4d0c426ec9c0f8",
"size": 541
},
{
"path": "main.js",
"sha256": "75dc31dc6270aa10e73c90eeb09bb349a949d17c39940574e28f12c5e463ceaf",
"size": 39307
"sha256": "0efdfbbfe7e9318610bb94330c0a3c361a0aa38f2b3a44c243c872f0e02a09e8",
"size": 98119
},
{
"path": "styles.css",
"sha256": "cc71e071379c84131e525afeaa5757674f499da195ccb42536c019a3ef5d8473",
"size": 9524
"sha256": "1fdad04e2ffe1c8ba2a991a88072f780b65238096f9ccd1b5adba671ff2c9cb3",
"size": 23611
}
]
},
@@ -280,27 +280,27 @@
"提示词",
"风格"
],
"version": "1.3.2",
"version": "1.3.3",
"apiVersion": 1,
"bundle": "plugins/style-source-1.3.2.zip",
"bundleSize": 70494,
"bundleSha256": "d5bc793cb78c7593d6dcdacc5a8664cfc50dfc0e7c78b6094dc99cc875de9619",
"bundle": "plugins/style-source-1.3.3.zip",
"bundleSize": 70634,
"bundleSha256": "a727fa70f7b195f11a4daed2febb3c5ad073da016ed292856b24127b2ba4d8c6",
"files": [
{
"path": "manifest.json",
"sha256": "3b49a8e5eba8e5e1a247dd1cdf90a34a426ee3a4442a683369afc8bbde654099",
"sha256": "d864e4943ae14764a0dcca27ebe89d877f90ff0350663a86f4d91470ed1cf2e2",
"size": 355
},
{
"path": "main.js",
"sha256": "ee7168565a44d49daaf300f62d5c7a106e60fba29a9e4888ff8bfd9abd2e3178",
"size": 69925
"sha256": "05c108f8a63cc1c5ebb1c1d18b4ade10e971a0ee74fb135482db7597e6731f84",
"size": 70065
}
],
"file": "plugins/plugin-style-source.ee7168565a44.js",
"size": 69925,
"sha256": "ee7168565a44d49daaf300f62d5c7a106e60fba29a9e4888ff8bfd9abd2e3178",
"integrity": "sha256-7nFoVlpE1J2q8wD2LVx6EG5g+6KankiI/4v9mr0uMXg="
"file": "plugins/plugin-style-source.05c108f8a63c.js",
"size": 70065,
"sha256": "05c108f8a63cc1c5ebb1c1d18b4ade10e971a0ee74fb135482db7597e6731f84",
"integrity": "sha256-BcEI+KY8wcXrscHRi0reEOlxoO50+xNUgtt1l+ZzH4Q="
},
{
"id": "white-bg-800",
+5 -4
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.26.34-mwrhcagv">
<link rel="stylesheet" href="/assets/style.css?v=3.26.39-mwrxcd5p">
</head><body>
<nav><div class="wrap inner">
<a class="brand" href="/"><span class="dot">IW</span>Image Workbench</a>
@@ -9,11 +9,12 @@
<a href="/">首页</a>
<a href="/download/">下载</a>
<a href="/plugins/" class="on">插件</a>
<a href="/dev/">开发</a>
<a href="https://git.maqiart.eu.org/malongan/image-workbench-desktop" target="_blank" rel="noopener">源码</a>
</div>
<div class="right">
<a class="btn" href="/plugins/">插件市场</a>
<a class="btn primary" href="/download/">下载 v3.26.34</a>
<a class="btn primary" href="/download/">下载 v3.26.39</a>
</div>
</div></nav>
<main>
@@ -76,7 +77,7 @@
</div>
<div class="pcard" data-name="提示词库 promptlib 右栏提示词列表:搜索/分组/收藏/新建编辑/插入画布/复制(数据由客户端提供) 资源 提示词" data-tags="资源,提示词">
<div class="head"><span class="av" style="background:#eef2f6">📖</span>
<div><div class="nm">提示词库</div><div class="ver">v1.4.10 · 官方</div></div></div>
<div><div class="nm">提示词库</div><div class="ver">v1.6.18 · 官方</div></div></div>
<div class="desc">右栏提示词列表:搜索/分组/收藏/新建编辑/插入画布/复制(数据由客户端提供)</div>
<div class="tags"><span class="tag">资源</span><span class="tag">提示词</span></div>
</div>
@@ -94,7 +95,7 @@
</div>
<div class="pcard" data-name="风格库 style-source 风格提示词库与一键套用 提示词 风格" data-tags="提示词,风格">
<div class="head"><span class="av" style="background:#fdf0e6">🎨</span>
<div><div class="nm">风格库</div><div class="ver">v1.3.2 · 官方</div></div></div>
<div><div class="nm">风格库</div><div class="ver">v1.3.3 · 官方</div></div></div>
<div class="desc">风格提示词库与一键套用</div>
<div class="tags"><span class="tag">提示词</span><span class="tag">风格</span></div>
</div>
+85 -1
View File
@@ -1,8 +1,92 @@
{
"app": "Image Workbench",
"subtitle": "本地优先的 AI 生图无限画布 · 桌面版(Tauri v2)",
"updatedAt": "2026-11-22T06:52:38.439Z",
"updatedAt": "2026-11-22T14:20:35.743Z",
"releases": [
{
"version": "3.26.39",
"date": "2026-11-22",
"notes": "Intel 版:同一版本",
"platforms": {
"darwin-aarch64": {
"file": "updates/darwin-aarch64/image-workbench_3.26.39_aarch64.dmg",
"size": 8789132,
"sha256": "15e9c10f31caea3a3d217db2d47e4cc07ed200153795cec462d02634cd35f31c",
"h": "15e9c10f31ca",
"kind": "dmg"
},
"darwin-x86_64": {
"file": "updates/darwin-x86_64/image-workbench_3.26.39_x64.dmg",
"size": 9179272,
"sha256": "1016831ad95f21be55b1410c16a8bb51f29fe0799c6bd8980fadf0369424f3ff",
"h": "1016831ad95f",
"kind": "dmg"
}
}
},
{
"version": "3.26.38",
"date": "2026-11-22",
"notes": "Intel 版:同一版本",
"platforms": {
"darwin-aarch64": {
"file": "updates/darwin-aarch64/image-workbench_3.26.38_aarch64.dmg",
"size": 8795617,
"sha256": "d7cce4643590125a77983264cfe895043675c66f125aa44ab7d0980ae9e43e52",
"h": "d7cce4643590",
"kind": "dmg"
},
"darwin-x86_64": {
"file": "updates/darwin-x86_64/image-workbench_3.26.38_x64.dmg",
"size": 9179980,
"sha256": "d2854862f7371306c0e78c54523928d08ff883cfc474939052f396f553c7ee90",
"h": "d2854862f737",
"kind": "dmg"
}
}
},
{
"version": "3.26.37",
"date": "2026-11-22",
"notes": "Intel 版:同一版本",
"platforms": {
"darwin-aarch64": {
"file": "updates/darwin-aarch64/image-workbench_3.26.37_aarch64.dmg",
"size": 8790278,
"sha256": "66abb4cfd7714ac331865d85d5dcdaa600f096045a8e92d06d8e0879b1308ea4",
"h": "66abb4cfd771",
"kind": "dmg"
},
"darwin-x86_64": {
"file": "updates/darwin-x86_64/image-workbench_3.26.37_x64.dmg",
"size": 9184844,
"sha256": "c560d101175247d304303b664e613fa61cef6fbcb5e7f1dab4fbac291c16dc03",
"h": "c560d1011752",
"kind": "dmg"
}
}
},
{
"version": "3.26.35",
"date": "2026-11-22",
"notes": "Intel 版:同一改进",
"platforms": {
"darwin-aarch64": {
"file": "updates/darwin-aarch64/image-workbench_3.26.35_aarch64.dmg",
"size": 8780534,
"sha256": "d01c2ea7c517d749570aa0a637a4ebdc1ad9c0db899cfb014d41961d39ae9575",
"h": "d01c2ea7c517",
"kind": "dmg"
},
"darwin-x86_64": {
"file": "updates/darwin-x86_64/image-workbench_3.26.35_x64.dmg",
"size": 9184387,
"sha256": "293a063d86ffe6393debae952b3a20d3198743c115229dd4a67e7cdb71d5dcd2",
"h": "293a063d86ff",
"kind": "dmg"
}
}
},
{
"version": "3.26.34",
"date": "2026-11-22",
+1 -1
View File
@@ -1983,7 +1983,7 @@ dependencies = [
[[package]]
name = "image-workbench"
version = "3.26.34"
version = "3.26.39"
dependencies = [
"arboard",
"base64 0.22.1",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "image-workbench"
version = "3.26.34"
version = "3.26.39"
description = "无限画布 · 生图工作台桌面版"
authors = ["malongan"]
license = ""
+34 -1
View File
@@ -241,6 +241,39 @@ fn copy_tree(src: String, dst: String) -> Result<u64, String> {
}
// 打开应用数据目录(设置里的「打开数据目录」按钮用;macOS 访达 / Windows 资源管理器 / Linux xdg-open)
#[tauri::command]
fn open_data_subpath(app: AppHandle, rel: String) -> Result<String, String> {
// 只允许打开「资料目录」下的子路径:rel 由宿主/插件传入,必须做规范化 + 前缀校验,
// 否则等于给插件一个任意路径的打开权限。
let recorded = app
.path()
.app_config_dir()
.ok()
.and_then(|c| std::fs::read_to_string(c.join("data-dir.txt")).ok())
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty());
let base = match recorded {
Some(p) => std::path::PathBuf::from(p),
None => app.path().app_data_dir().map_err(|e| e.to_string())?,
};
let base = base.canonicalize().map_err(|e| e.to_string())?;
let target = base.join(rel.trim_start_matches('/')).canonicalize().map_err(|e| e.to_string())?;
if !target.starts_with(&base) { return Err("路径不在资料目录内".into()); }
std::fs::create_dir_all(&target).map_err(|e| e.to_string())?;
let path = target.to_string_lossy().to_string();
#[cfg(target_os = "macos")]
let cmd = "open";
#[cfg(target_os = "windows")]
let cmd = "explorer";
#[cfg(target_os = "linux")]
let cmd = "xdg-open";
std::process::Command::new(cmd)
.arg(&path)
.spawn()
.map_err(|e| e.to_string())?;
Ok(path)
}
#[tauri::command]
fn open_app_data_dir(app: AppHandle) -> Result<String, String> {
// 资料目录(用户选的那个)优先;没设置过才退回应用私有目录
@@ -889,7 +922,7 @@ 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, open_data_subpath, 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) {
+1 -1
View File
@@ -1,7 +1,7 @@
{
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
"productName": "image-workbench",
"version": "3.26.34",
"version": "3.26.39",
"identifier": "com.malongan.imageworkbench",
"build": {
"frontendDist": "../dist",
+11 -1
View File
@@ -349,5 +349,15 @@
return { x: Math.round(x), y: Math.round(y) }
}
global.IWBCanvasGeometry = Object.freeze({ connectReasonOf, distToSeg, wantsDefaultSpot, parseWorldTransform, clientToWorld, snapToFreeSpot, placeBeside, pruneMeasured, seedFromTopLeft, clampIntoBounds, lodLowOf, lodModeOf, zoomStep, LOD_NODE_PX, LOD_PLAIN_SCALE, ZOOM_STEP, ZOOM_MIN, ZOOM_MAX, create })
// 插件「插入画布」落到可视区域中心(findSpot 会把节点丢左上角,常被左侧面板遮住)。
const promptCenterSpot = (bridge, w, h) => {
try {
const c = typeof document !== 'undefined' ? document.querySelector('.iwb-canvas') : null
if (!c || !bridge || typeof bridge.screenToWorld !== 'function') return null
const r = c.getBoundingClientRect()
const p = bridge.screenToWorld(r.left + r.width / 2, r.top + r.height / 2)
return p ? { x: p.x - (w || 0) / 2, y: p.y - (h || 0) / 2 } : null
} catch (e) { return null }
}
global.IWBCanvasGeometry = Object.freeze({ connectReasonOf, distToSeg, wantsDefaultSpot, promptCenterSpot, parseWorldTransform, clientToWorld, snapToFreeSpot, placeBeside, pruneMeasured, seedFromTopLeft, clampIntoBounds, lodLowOf, lodModeOf, zoomStep, LOD_NODE_PX, LOD_PLAIN_SCALE, ZOOM_STEP, ZOOM_MIN, ZOOM_MAX, create })
})(typeof window !== 'undefined' ? window : globalThis)
+20
View File
@@ -39,6 +39,14 @@
}
}
function fileOp (name) {
return function () {
const F = (typeof global !== 'undefined' && global.IWBStorageFile) ? global.IWBStorageFile.pluginFiles : null
if (!F || typeof F[name] !== 'function') return Promise.reject(new Error('文件能力未就绪'))
const args = Array.prototype.slice.call(arguments)
try { return Promise.resolve(F[name].apply(F, ['promptlib'].concat(args))) } catch (e) { return Promise.reject(e) }
}
}
const API = {
list: call('list'),
save: call('save'),
@@ -49,6 +57,18 @@
putCover: call('putCover'),
coverUrl: call('coverUrl'),
removeCover: call('removeCover'),
// v3.26.36:封面等插件文件的沙箱读写(挂在 promptlib 能力上,避免新增能力权限面)
// 文件沙箱(v3.26.36):直接调宿主 pluginFiles,不占 app.js 行数;插件 id 固定 promptlib。
filePut: fileOp('put'),
fileGet: fileOp('get'),
fileList: fileOp('list'),
fileRemove: fileOp('remove'),
fileStat: fileOp('stat'),
fileDir: function () { const F = (typeof global !== 'undefined' && global.IWBStorageFile) ? global.IWBStorageFile.pluginFiles : null; return F ? F.dir('promptlib') : Promise.reject(new Error('文件能力未就绪')) },
openPath: function (rel) { const T = (typeof global !== 'undefined') ? global.__TAURI__ : null; if (!T || !T.core) return Promise.reject(new Error('桌面能力不可用')); return T.core.invoke('open_data_subpath', { rel: String(rel || '') }) },
// 备份文件读写(宿主的另存为/打开对话框)
exportText: function (name, text) { const B = (typeof global !== 'undefined') ? global.IWBPromptlibBackup : null; return (B && typeof B.saveText === 'function') ? B.saveText(text, name) : Promise.reject(new Error('备份能力未就绪')) },
importText: function () { const B = (typeof global !== 'undefined') ? global.IWBPromptlibBackup : null; return (B && typeof B.pickText === 'function') ? B.pickText() : Promise.reject(new Error('备份能力未就绪')) },
onChanged: function (fn) {
if (typeof fn !== 'function') return function () {}
listeners.push(fn)
+206
View File
@@ -0,0 +1,206 @@
/* plugin-archive.js —— 插件包 ZIP 打包/解包(浏览器侧)
*
* 为什么要有这一层:
* - 插件包是**外部输入**:ZIP 里可能藏 ../、绝对路径、反斜杠、超限条目(zip 炸弹)。
* 直接把它交给 storage-zip 读写,会把「能不能解」和「该不该解」混在一起;
* 本模块只做准入判断,ZIP 编解码仍全部复用 src/storage-zip.js。
* - 打包与解包共用同一套校验,避免「写的时候放行、读的时候才拦」造成半成品包。
*
* 插件包布局(只允许这几种路径):
* - data.json / meta.json 顶层元数据
* - images/<name>.(jpg|jpeg|png|webp) 图片资源(images/ 下不再允许子目录)
*
* ⚠️ 重名检测不能只看 wOpenZipBlob 的 files 映射:它是普通对象,同名条目会被
* 后一个静默覆盖。所以先用 wZipParseEntries 读中央目录做名字/声明大小/重名预检,
* 再用 wOpenZipBlob 逐条读字节并复核**实际**大小(声明大小可伪造,不能当唯一防线)。
*/
;(function (global) {
'use strict'
const MAX_FILES = 500
const MAX_FILE_BYTES = 16 * 1024 * 1024
const MAX_TOTAL_BYTES = 64 * 1024 * 1024
// 名字过长会写坏 ZIP 的 16 位名称长度字段,也超出常见文件系统上限,直接拒绝。
// 名字被白名单限制为 ASCII,所以字符数即字节数。
const MAX_NAME_LENGTH = 255
const SAFE_NAME_RE = /^[A-Za-z0-9._/-]+$/
const IMAGE_EXT_RE = /\.(?:jpe?g|png|webp)$/i
const IMAGE_DIR = 'images/'
const TOP_FILES = ['data.json', 'meta.json']
// 上限必须可被调用方/测试读取:这些数字就是信任边界,散落在函数里容易被改错。
const limits = Object.freeze({
maxFiles: MAX_FILES,
maxFileBytes: MAX_FILE_BYTES,
maxTotalBytes: MAX_TOTAL_BYTES,
})
function isDirectory (name) {
return name.charAt(name.length - 1) === '/'
}
// 名字是唯一进入 ZIP 的路径,按「明显穿越 → 字符 → 路径段 → 白名单前缀」顺序校验。
// 顺序是刻意的:先报「反斜杠 / .. / 绝对路径」,错误消息才能指向真正原因,
// 而不是笼统地报一句"含非法字符"。
function validateName (name) {
if (typeof name !== 'string' || name.length === 0) throw new Error('文件名必须是非空字符串')
if (name.indexOf('\\') !== -1) throw new Error('文件名不能包含反斜杠:' + name)
for (let i = 0; i < name.length; i++) {
const code = name.charCodeAt(i)
if (code < 0x20 || code === 0x7f) throw new Error('文件名不能包含控制字符:' + JSON.stringify(name))
}
if (name.charAt(0) === '/') throw new Error('文件名不能是绝对路径:' + name)
if (!SAFE_NAME_RE.test(name)) throw new Error('文件名含非法字符(只允许字母数字、-、_、.、/):' + name)
if (name.length > MAX_NAME_LENGTH) {
throw new Error('文件名过长(最多 ' + MAX_NAME_LENGTH + ' 个字符):' + name.slice(0, 64) + '...')
}
const dir = isDirectory(name)
const body = dir ? name.slice(0, -1) : name
if (body.length === 0) throw new Error('文件名不能为空:' + name)
for (const part of body.split('/')) {
if (part === '..') throw new Error('文件名不能包含 .. 路径段:' + name)
if (part === '.' || part === '') throw new Error('文件名包含非法路径段:' + name)
}
if (dir) {
// 只接受 images/ 这一种目录条目;其余目录没有业务含义,放行只会扩大攻击面。
if (body !== 'images') throw new Error('ZIP 只允许 images/ 目录条目:' + name)
return { name, dir: true }
}
if (TOP_FILES.indexOf(name) !== -1) return { name, dir: false }
if (name.indexOf(IMAGE_DIR) !== 0) throw new Error('文件名不在允许的路径内(仅 data.json、meta.json、images/):' + name)
const rest = name.slice(IMAGE_DIR.length)
if (rest.indexOf('/') !== -1) throw new Error('images/ 下不允许再建子目录:' + name)
if (!IMAGE_EXT_RE.test(rest)) throw new Error('图片只允许 .jpg/.jpeg/.png/.webp 后缀:' + name)
return { name, dir: false }
}
function encodeData (data, name) {
if (typeof data === 'string') return new global.TextEncoder().encode(data)
// 用 brand check 而不是 instanceof:模块可能被放在 iframe/vm 等不同 realm 里,
// 跨 realm 的 Uint8Array 用 instanceof 判断会误杀正常输入。
if (Object.prototype.toString.call(data) === '[object Uint8Array]') {
return new global.Uint8Array(data.buffer, data.byteOffset, data.byteLength)
}
throw new Error('文件内容必须是 Uint8Array 或 string:' + name)
}
function storage () {
const S = global.IWBStorageZip
if (!S) throw new Error('ZIP 能力不可用(IWBStorageZip 未加载)')
return S
}
function assertBlob (blob) {
if (!blob || typeof blob.arrayBuffer !== 'function' || typeof blob.size !== 'number') {
throw new Error('解包输入必须是 Blob')
}
}
async function zip (files) {
if (!Array.isArray(files)) throw new Error('打包输入必须是文件数组')
if (files.length > MAX_FILES) throw new Error('文件数超过上限(最多 ' + MAX_FILES + ' 个):' + files.length)
const seen = new Set()
const items = []
let total = 0
// 先把整批文件校验完再动写入器:校验失败时不要留下写了一半的 ZIP。
for (const f of files) {
if (!f || typeof f !== 'object') throw new Error('文件项必须是 { name, data } 对象')
const checked = validateName(f.name)
if (checked.dir) throw new Error('打包列表不能包含目录条目:' + checked.name)
if (seen.has(checked.name)) throw new Error('ZIP 中存在重名条目:' + checked.name)
seen.add(checked.name)
const bytes = encodeData(f.data, checked.name)
if (bytes.byteLength > MAX_FILE_BYTES) throw new Error('单个文件超过上限(16MB):' + checked.name)
total += bytes.byteLength
if (total > MAX_TOTAL_BYTES) throw new Error('文件总大小超过上限(64MB):' + checked.name)
items.push({ name: checked.name, bytes })
}
const S = storage()
if (typeof S.wCreateStoreZip !== 'function') throw new Error('ZIP 写入能力不可用(IWBStorageZip.wCreateStoreZip 缺失)')
const zw = S.wCreateStoreZip()
if (!zw || typeof zw.add !== 'function' || typeof zw.finish !== 'function') throw new Error('ZIP 写入器不可用')
for (const item of items) {
// 每个文件单独一个 Blob:storage-zip 会把 Blob 原样作为 ZIP part,字节不必堆进 JS 堆。
await zw.add(item.name, new global.Blob([item.bytes]))
}
const blob = zw.finish()
if (!blob || typeof blob.arrayBuffer !== 'function') throw new Error('ZIP 写入失败:没有产出 Blob')
return blob
}
// 中央目录预检。返回 null 表示当前客户端没有 wZipParseEntries ——
// 此时只能退化为 files 映射校验(该映射会吞掉重名,属于已知降级)。
async function scanEntries (S, blob) {
if (typeof S.wZipParseEntries !== 'function') return null
let parsed
try {
parsed = S.wZipParseEntries(await blob.arrayBuffer())
} catch (e) {
throw new Error('ZIP 解析失败:' + ((e && e.message) || e))
}
const entries = (parsed && parsed.entries) || []
if (entries.length > MAX_FILES) {
throw new Error('ZIP 条目数超过上限(最多 ' + MAX_FILES + ' 个):' + entries.length)
}
const names = []
const seen = new Set()
let declaredTotal = 0
for (const e of entries) {
const checked = validateName(e && e.name)
if (checked.dir) continue
// 声明大小先卡一道:明显超限的炸弹包不必等读出全部字节才报错。
const rawSize = Number(e.rawSize) || 0
if (rawSize > MAX_FILE_BYTES) throw new Error('解包后单个文件超过上限(16MB):' + checked.name)
declaredTotal += rawSize
if (declaredTotal > MAX_TOTAL_BYTES) throw new Error('解包后总大小超过上限(64MB):' + checked.name)
if (seen.has(checked.name)) throw new Error('ZIP 中存在重名条目:' + checked.name)
seen.add(checked.name)
names.push(checked.name)
}
return names
}
async function unzip (blob) {
assertBlob(blob)
const S = storage()
if (typeof S.wOpenZipBlob !== 'function') throw new Error('ZIP 读取能力不可用(IWBStorageZip.wOpenZipBlob 缺失)')
const parsedNames = await scanEntries(S, blob)
let opened
try {
opened = await S.wOpenZipBlob(blob)
} catch (e) {
throw new Error('ZIP 解析失败:' + ((e && e.message) || e))
}
const map = opened && opened.files
if (!map || typeof map !== 'object') throw new Error('ZIP 打开失败:没有文件表')
let names = parsedNames
if (!names) {
// 降级路径:没有中央目录解析能力时,只能按 files 映射的键校验。
names = Object.keys(map)
if (names.length > MAX_FILES) throw new Error('ZIP 条目数超过上限(最多 ' + MAX_FILES + ' 个):' + names.length)
for (const name of names) validateName(name)
}
const out = []
let total = 0
for (const name of names) {
const entry = (typeof opened.file === 'function') ? opened.file(name) : map[name]
if (!entry || typeof entry.async !== 'function') throw new Error('ZIP 条目读取失败:' + name)
let bytes
try {
bytes = await entry.async('uint8array')
} catch (e) {
throw new Error('ZIP 条目解压失败(' + name + '):' + ((e && e.message) || e))
}
if (!bytes || typeof bytes.byteLength !== 'number') throw new Error('ZIP 条目内容非法:' + name)
// 中央目录里的 rawSize 可以伪造,真实字节数必须再复核一次(zip 炸弹的最终防线)。
if (bytes.byteLength > MAX_FILE_BYTES) throw new Error('解包后单个文件超过上限(16MB):' + name)
total += bytes.byteLength
if (total > MAX_TOTAL_BYTES) throw new Error('解包后总大小超过上限(64MB):' + name)
// 复制一份再交付,避免返回值与 ZIP 内部大 buffer 长期共享(也防止调用方改写源字节)。
out.push({ name, data: new global.Uint8Array(bytes) })
}
return out
}
global.IWBPluginArchive = Object.freeze({ zip, unzip, limits })
})(typeof window !== 'undefined' ? window : globalThis)
+40
View File
@@ -0,0 +1,40 @@
/* plugin-files-policy.js —— 插件文件能力的纯策略(v3.26.36)
*
* 为什么单独成模块:文件名白名单与配额是安全边界,必须能在 Node 里单测;
* storage-file 里只留 IO,策略在这里,避免「安全靠人工」。
*/
;(function (global) {
'use strict'
var LIMITS = Object.freeze({
FILE_MAX: 8 * 1024 * 1024, // 单文件 8MB(640px 封面约 40~90KB,留足余量)
TOTAL_MAX: 64 * 1024 * 1024, // 单插件总量 64MB
})
var NAME_RE = /^[a-z0-9][a-z0-9_-]{0,63}\.(jpg|jpeg|png|webp)$/i
// 文件名只允许:字母数字 / - / _ + 图片后缀;禁止路径分隔、点段与控制字符。
function fileOk (name) {
var s = String(name == null ? '' : name)
if (!s || s.length > 72) return false
if (!NAME_RE.test(s)) return false
if (s.indexOf('..') >= 0) return false
if (s.indexOf('/') >= 0) return false
if (s.indexOf(String.fromCharCode(92)) >= 0) return false
for (var i = 0; i < s.length; i++) { if (s.charCodeAt(i) < 32) return false }
return true
}
// 配额:total 为现有总量;replacing 为同名旧文件大小(覆盖时不重复计)。
function quotaOk (total, incoming, replacing, limits) {
var L = limits || LIMITS
var inc = Number(incoming) || 0
var rep = Number(replacing) || 0
var cur = Math.max(0, Number(total) || 0)
if (inc <= 0) return { ok: false, reason: 'empty' }
if (inc > L.FILE_MAX) return { ok: false, reason: 'file-too-large', limit: L.FILE_MAX }
if (cur - rep + inc > L.TOTAL_MAX) return { ok: false, reason: 'total-too-large', limit: L.TOTAL_MAX }
return { ok: true }
}
global.IWBPluginFilesPolicy = { LIMITS: LIMITS, fileOk: fileOk, quotaOk: quotaOk }
})(typeof window !== 'undefined' ? window : globalThis)
+2 -2
View File
@@ -4,8 +4,8 @@
const API_VERSION = 1
const ID_PATTERN = /^[a-z][a-z0-9-]{2,31}$/
const REQUIRED_FIELDS = ['id', 'name', 'version', 'apiVersion', 'capabilities']
const CAPABILITIES = ['panels', 'commands', 'nodeTypes', 'generationHooks', 'providers', 'canvas', 'canvasWrite', 'nodeActions', 'gallery', 'grouplib', 'promptlib']
const CAPABILITY_API_KEYS = { panels: 'ui', commands: 'commands', nodeTypes: 'nodes', generationHooks: 'generation', providers: 'providers', canvas: 'canvas', canvasWrite: 'canvas', nodeActions: 'nodeActions', gallery: 'gallery', grouplib: 'grouplib', promptlib: 'promptlib' }
const CAPABILITIES = ['panels', 'commands', 'nodeTypes', 'generationHooks', 'providers', 'canvas', 'canvasWrite', 'nodeActions', 'gallery', 'grouplib', 'promptlib', 'files']
const CAPABILITY_API_KEYS = { panels: 'ui', commands: 'commands', nodeTypes: 'nodes', generationHooks: 'generation', providers: 'providers', canvas: 'canvas', canvasWrite: 'canvas', nodeActions: 'nodeActions', gallery: 'gallery', grouplib: 'grouplib', promptlib: 'promptlib' , files: 'files'}
function createPluginHost(options) {
const opt = options || {}
+41
View File
@@ -0,0 +1,41 @@
/* plugin-promptlib-backup.js —— 提示词插件备份文件的读写(v3.26.37)
*
* 插件跑在 WebView 里没有文件权限:导出/导入必须经宿主的「另存为/打开」对话框。
* 这里只做文件 IO,内容格式(哪些条目、如何合并)由插件决定。
*/
;(function (global) {
'use strict'
function tauri () { return (typeof global.__TAURI__ !== 'undefined') ? global.__TAURI__ : null }
async function saveText (text, name) {
const T = tauri()
if (!T || !T.dialog || !T.fs) return { ok: false, error: '桌面版文件对话框不可用' }
try {
const path = await T.dialog.save({
defaultPath: String(name || 'promptlib-backup.json'),
filters: [{ name: '提示词备份', extensions: ['json'] }],
})
if (!path) return { ok: false, canceled: true }
await T.fs.writeTextFile(path, String(text || ''))
return { ok: true, path: path }
} catch (e) { return { ok: false, error: String((e && e.message) || e) } }
}
async function pickText () {
const T = tauri()
if (!T || !T.dialog || !T.fs) return { ok: false, error: '桌面版文件对话框不可用' }
try {
const picked = await T.dialog.open({
multiple: false,
filters: [{ name: '提示词备份', extensions: ['json'] }],
})
const path = Array.isArray(picked) ? picked[0] : picked
if (!path) return { ok: false, canceled: true }
const text = await T.fs.readTextFile(path)
return { ok: true, text: text, path: path }
} catch (e) { return { ok: false, error: String((e && e.message) || e) } }
}
global.IWBPromptlibBackup = { saveText: saveText, pickText: pickText }
})(typeof window !== 'undefined' ? window : globalThis)
+43 -2
View File
@@ -887,6 +887,14 @@
commitCanvas(refs.nodes.concat(moved), refs.edges.concat(es), refs.groups.concat(gs))
} else {
setSel([])
// 拖入后清掉宿主的临时手势状态:原生拖放期间鼠标事件被浏览器吞掉,
// pointerup 可能没走到画布,refs.bodyDown/box 会残留 ⇒ 第一次点击节点被当成「收尾」。
try {
refs.bodyDown = null; refs.groupDown = null; refs.drag = null; refs.box = null; refs.pan = null
const ae = /** @type {any} */ (document.activeElement)
if (ae && typeof ae.blur === 'function') ae.blur()
if (window.getSelection) window.getSelection().removeAllRanges()
} catch (e) { /* ignore */ }
setNotice({ type: 'ok', text: '✓ 已导入 ' + ns.length + ' 个节点 / ' + es.length + ' 条连线' })
commitCanvas(ns, es, gs)
}
@@ -1089,11 +1097,44 @@
try {
const obj = JSON.parse(promptPayload)
const id = uid('n')
const node = { id, type: 'prompt', x: Math.round(wx - 132), y: Math.round(wy - 20), data: { text: obj.text || '', title: obj.name || '' } }
// 有变量 → 模板节点(可填值、可作参考图);没有变量 → 普通文本节点(最轻)
const hasVars = Array.isArray(obj.vars) && obj.vars.length > 0
const node = hasVars
? {
id, type: 'plugin:' + String(obj.pluginId || 'promptlib') + ':ptpl', x: Math.round(wx - 210), y: Math.round(wy - 20), w: 420,
data: {
promptId: '', name: obj.name || '提示词模板', tpl: obj.text || '',
vdefs: Array.isArray(obj.vdefs) ? obj.vdefs : [],
vars: {}, cover: obj.cover || '', refOn: false, text: obj.text || '', outKind: 'prompt',
},
}
: { id, type: 'prompt', x: Math.round(wx - 132), y: Math.round(wy - 20), data: { text: obj.text || '', title: obj.name || '' } }
pushHistory() // 拖拽入画布新增节点:入撤销历史(鼠标落点保留)
commitCanvas(refs.nodes.concat([node]), undefined, undefined)
// 与风格库一致:新节点直接选中(未选中时第一次点击会被当成“先选中”而拖不动)
setSel([id])
setNotice({ type: 'ok', text: '已插入提示词:' + (obj.name || '') })
// 拖放结束后浏览器可能还会给新节点补一次 focus/click(落在 readonly textarea 上会进入编辑态),
// 导致「第一次点节点」变成选文本/输入框、拖不动。延时几次强制 blur + 取消选择,覆盖这段尾巴。
const settleDrop = () => {
try {
const ae = /** @type {any} */ (document.activeElement)
if (ae && ae !== document.body && typeof ae.blur === 'function') ae.blur()
if (window.getSelection) window.getSelection().removeAllRanges()
setSel([id])
} catch (e) { /* ignore */ }
}
setTimeout(settleDrop, 0)
setTimeout(settleDrop, 80)
setTimeout(settleDrop, 240)
// 原生拖放期间浏览器的鼠标事件被吞掉,pointerup 不会走到画布:
// refs.bodyDown/box 等临时手势会残留,导致「第一次点节点」被当成收尾(点不动/选中文本)。
try {
refs.bodyDown = null; refs.groupDown = null; refs.drag = null; refs.box = null; refs.pan = null
const ae = /** @type {any} */ (document.activeElement)
if (ae && typeof ae.blur === 'function') ae.blur()
if (window.getSelection) window.getSelection().removeAllRanges()
} catch (e) { /* ignore */ }
setNotice({ type: 'ok', text: (hasVars ? '已插入提示词模板:' : '已插入提示词:') + (obj.name || '') })
return
} catch (err) { /* 非本应用拖入 */ }
}
+88 -1
View File
@@ -571,6 +571,92 @@
} catch (e) { return [] }
}
// ---- 插件文件(v3.26.36):<资料目录>/plugin-data/<id>/files/ ----
// 与插件 JSON 数据分离:文件放目录、JSON 只存文件名(内容哈希命名)。
// 安全:文件名白名单(禁路径分隔/点段)、单文件 8MB、单插件总量 64MB、原子写。
const PFILE_DIR = 'files'
const PFILE_MAX = 8 * 1024 * 1024
const PFILE_TOTAL = 64 * 1024 * 1024
const PFILE_NAME_RE = /^[a-z0-9][a-z0-9_-]{0,63}\.(jpg|jpeg|png|webp)$/i
function pluginFileNameOk (name) {
const P = global.IWBPluginFilesPolicy
if (P && typeof P.fileOk === 'function') return P.fileOk(name)
const s0 = String(name || '')
if (!PFILE_NAME_RE.test(s0)) return false
if (s0.indexOf('..') >= 0 || s0.indexOf('/') >= 0 || s0.indexOf(String.fromCharCode(92)) >= 0) return false
return true
}
async function pluginFilesDir (id) {
const p = await join(await pluginDataDir(), safePluginId(id), PFILE_DIR)
try { await fs().mkdir(p, { recursive: true }) } catch (e) { /* 已存在 */ }
return p
}
async function pluginFilePut (id, name, dataUrl) {
try {
if (!pluginFileNameOk(name)) return { ok: false, error: '非法文件名(只允许小写字母/数字/-/_ + jpg/png/webp)' }
const decoded = dataUrlToBytes(String(dataUrl || ''))
const bytes = decoded && decoded.bytes
if (!bytes || !bytes.length) return { ok: false, error: '图片数据为空' }
const stat = await pluginFileStat(id)
const existing = stat.files.find((f) => f.name === name)
const P = global.IWBPluginFilesPolicy
const q = P ? P.quotaOk(stat.bytes, bytes.length, existing ? existing.size : 0) : null
if (q && !q.ok) {
if (q.reason === 'file-too-large') return { ok: false, error: '单张图片超过 8MB' }
if (q.reason === 'total-too-large') return { ok: false, error: '插件数据总量超过 64MB,请先清理' }
return { ok: false, error: '图片数据为空' }
}
if (!P) {
if (bytes.length > PFILE_MAX) return { ok: false, error: '单张图片超过 8MB' }
if (stat.bytes - (existing ? existing.size : 0) + bytes.length > PFILE_TOTAL) return { ok: false, error: '插件数据总量超过 64MB,请先清理' }
}
const dir0 = await pluginFilesDir(id)
const target = await join(dir0, name)
const tmp = target + '.tmp'
await fs().writeFile(tmp, bytes)
try { await fs().rename(tmp, target) } catch (e) {
try { await fs().remove(target) } catch (e2) { /* ignore */ }
await fs().rename(tmp, target)
}
return { ok: true, name: name, size: bytes.length }
} catch (e) { return { ok: false, error: String((e && e.message) || e) } }
}
async function pluginFileGet (id, name) {
try {
if (!pluginFileNameOk(name)) return { ok: false, error: '非法文件名' }
const u8 = await fs().readFile(await join(await pluginFilesDir(id), name))
if (!u8 || !u8.length) return { ok: false, error: '文件不存在' }
return { ok: true, url: bytesToDataUrl(sniffMime(u8) || 'image/jpeg', u8), size: u8.length }
} catch (e) { return { ok: false, error: '文件不存在' } }
}
async function pluginFileList (id) {
try {
const entries = await fs().readDir(await pluginFilesDir(id))
const out = []
for (const e of entries) {
if (!e || e.isDirectory || !pluginFileNameOk(e.name)) continue
let size = 0
try { const u8 = await fs().readFile(await join(await pluginFilesDir(id), e.name)); size = u8 ? u8.length : 0 } catch (err) { size = 0 }
out.push({ name: e.name, size: size })
}
out.sort((a, b) => a.name.localeCompare(b.name))
return out
} catch (e) { return [] }
}
async function pluginFileRemove (id, name) {
try {
if (!pluginFileNameOk(name)) return { ok: false, error: '非法文件名' }
await fs().remove(await join(await pluginFilesDir(id), name))
return { ok: true }
} catch (e) { return { ok: false, error: '删除失败' } }
}
async function pluginFileStat (id) {
try {
const files = await pluginFileList(id)
return { ok: true, files: files, bytes: files.reduce((n, f) => n + (f.size || 0), 0), count: files.length }
} catch (e) { return { ok: false, files: [], bytes: 0, count: 0 } }
}
async function loadInto() {
// data.json 不存在 ⇒ 把当前 WebView 里的数据迁过去(只做一次)
const target = await join(dir, DATA_FILE)
@@ -1160,12 +1246,13 @@
enabled, ready: init, flush, runtime, pickDir, switchTo, migrateTo, gcImages, rotateTrash, galleryThumb, readDisplayThumb, readDisplayThumbUrl, writeDisplayThumb, writeDisplayThumbBlob, pruneThumbs, cleanupLegacy, maintain,
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 },
pluginFiles: { put: pluginFilePut, get: pluginFileGet, list: pluginFileList, remove: pluginFileRemove, stat: pluginFileStat, dir: pluginFilesDir },
storage: () => storage,
kv: () => kv,
dir: () => dir,
setDir: async (next) => { dir = String(next || ''); await flush();},
stats: () => ({ dir, keys: Object.keys(mem).length, images: Object.keys(assets).length }),
__internals: { snapshot, loadInto, sha16, extOf, dataUrlToBytes, bytesToDataUrl },
__internals: { snapshot, loadInto, sha16, extOf, dataUrlToBytes, bytesToDataUrl, pluginFileNameOk },
}
// 关窗/收托盘前强制刷盘(beforeunload 在桌面端不保证,但能救一次是一次)
// 落盘兜底:桌面端点关闭是「收进托盘」,beforeunload 不一定触发;
+3
View File
@@ -2475,3 +2475,6 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s
.iwb-mk-row:hover { background: color-mix(in srgb, var(--iwb-text) 3%, transparent); transform: none; box-shadow: none; }
.iwb-mk-row-actions .iwb-btn { transform: none; box-shadow: none; transition: background .12s ease; }
.iwb-mk-row-actions .iwb-btn:hover { transform: none; box-shadow: none; background: color-mix(in srgb, var(--iwb-text) 10%, var(--iwb-panel)); }
/* v3.26.38:未进入编辑态的节点正文不参与指针/文本选择 —— 单击=选中节点,双击=编辑 */
.iwb-node textarea[readonly], .iwb-node input[readonly] { pointer-events: none; }
+3
View File
@@ -41,6 +41,8 @@
"storage-outputs.js",
"storage-backup.js",
"storage-zip.js",
"plugin-archive.js",
"plugin-promptlib-backup.js",
"runtime-constants.js",
"canvas-store.js",
"generation-scheduler.js",
@@ -103,5 +105,6 @@
"ui-connect-menu.js",
"ui-gen-config-panel.js",
"canvas-webview.js",
"plugin-files-policy.js",
"image-prompt-cover.js"
]
+226
View File
@@ -0,0 +1,226 @@
'use strict'
// src/plugin-archive.js 的行为测试。
//
// 为什么测试要这么细:插件包来自外部,ZIP 解包是这个功能的**信任边界**。
// 路径穿越、非法后缀、重名条目、超限条目(zip 炸弹)只要漏一个,
// 用户点一次"导入插件"就可能把文件写到插件目录之外,或把内存/磁盘打爆。
//
// 用 vm 加载真实模块(IIFE 挂 window),并先加载 src/storage-zip.js ——
// 测试不 mock ZIP 编解码,测的就是线上真实走的那条链路。
// ⚠️ 跨 realm:模块在 vm 里创建对象/数组,原型与本文件不同,
// 所以内容比较统一走 JSON,不能用 deepStrictEqual。
const assert = require('assert')
const fs = require('fs')
const path = require('path')
const vm = require('vm')
const root = path.resolve(__dirname, '..')
const sandbox = {
console: { log() {}, warn() {}, error() {} },
TextEncoder, TextDecoder, Blob, DataView, Uint8Array, Uint32Array,
Response, DecompressionStream, Date, Error, Math, String, Number, Array, Object, JSON, Promise, Set, Map, Boolean, isNaN, parseInt,
}
vm.runInNewContext(fs.readFileSync(path.join(root, 'src', 'storage-zip.js'), 'utf8'), sandbox)
vm.runInNewContext(fs.readFileSync(path.join(root, 'src', 'plugin-archive.js'), 'utf8'), sandbox)
const Z = sandbox.IWBStorageZip
const A = sandbox.IWBPluginArchive
assert.ok(Z, '应加载 IWBStorageZip(storage-zip.js 是被测模块的真实依赖)')
assert.ok(A, '应导出 IWBPluginArchive')
const eqJson = (a, b, msg) => assert.strictEqual(JSON.stringify(a), JSON.stringify(b), msg)
const eqBytes = (a, b, msg) => eqJson(Array.from(a), Array.from(b), msg)
// 绕过 IWBPluginArchive.zip 的校验,直接用底层写入器造"恶意 ZIP":
// 只有这样才能验证 unzip 自身的防线(真实攻击者也不会经过我们的 zip())。
const rawZip = async (entries) => {
const w = Z.wCreateStoreZip()
for (const [name, data] of entries) await w.add(name, new Blob([data]))
return w.finish()
}
const expectReject = async (fn, pattern, label) => {
let err = null
try { await fn() } catch (e) { err = e }
assert.ok(err, label + ':应 reject,实际却成功了')
assert.ok(pattern.test(String(err && err.message)),
label + ':错误消息应匹配 ' + pattern + ',实际:' + (err && err.message))
}
// 篡改中央目录里的"原始大小"字段:用一个几字节的小 ZIP 模拟声明 16MB/64MB 的炸弹包。
// 这类包不需要真的把大字节读进内存,正好用来单独验证上限判断。
const patchCentralRawSize = async (blob, size) => {
const buf = await blob.arrayBuffer()
const dv = new DataView(buf)
const u8 = new Uint8Array(buf)
const eocd = u8.length - 22
const count = dv.getUint16(eocd + 10, true)
let p = dv.getUint32(eocd + 16, true)
for (let i = 0; i < count; i++) {
assert.strictEqual(dv.getUint32(p, true), 0x02014b50, '中央目录签名应正确')
dv.setUint32(p + 24, size, true) // 中央目录条目 +24 = 原始大小
const nameLen = dv.getUint16(p + 28, true)
const extraLen = dv.getUint16(p + 30, true)
const commentLen = dv.getUint16(p + 32, true)
p += 46 + nameLen + extraLen + commentLen
}
return new Blob([buf])
}
;(async () => {
// ── 1. 导出面与上限常量 ────────────────────────────────────────────────
{
assert.strictEqual(typeof A.zip, 'function', '应导出 zip')
assert.strictEqual(typeof A.unzip, 'function', '应导出 unzip')
assert.ok(A.limits && Object.isFrozen(A.limits), 'limits 应是冻结对象,防止运行期被改松')
assert.strictEqual(A.limits.maxFiles, 500, '条目上限应为 500')
assert.strictEqual(A.limits.maxFileBytes, 16 * 1024 * 1024, '单文件上限应为 16MB')
assert.strictEqual(A.limits.maxTotalBytes, 64 * 1024 * 1024, '总大小上限应为 64MB')
}
// ── 2. 往返:zip → unzip,字节逐一致(含中文内容)────────────────────
{
const binary = new Uint8Array(256)
for (let i = 0; i < binary.length; i++) binary[i] = i
const blob = await A.zip([
{ name: 'data.json', data: JSON.stringify({ title: '中文标题', n: 1 }) },
{ name: 'meta.json', data: '{"version":1}' },
{ name: 'images/a.jpg', data: binary },
])
assert.ok(blob && typeof blob.arrayBuffer === 'function', '应产出 Blob')
assert.strictEqual(blob.type, 'application/zip', 'ZIP 的 MIME 应为 application/zip')
const out = await A.unzip(blob)
eqJson(out.map((x) => x.name), ['data.json', 'meta.json', 'images/a.jpg'], '条目名与顺序应保持')
assert.strictEqual(new TextDecoder().decode(out[0].data), '{"title":"中文标题","n":1}',
'字符串内容按 UTF-8 写入、应原样读回(中文不能乱码)')
eqBytes(out[2].data, binary, '二进制内容应逐字节一致')
assert.strictEqual(Object.prototype.toString.call(out[0].data), '[object Uint8Array]', 'data 应是 Uint8Array')
}
// ── 3. 路径穿越 / 绝对路径 / 反斜杠:打包与解包都必须拒绝 ─────────────
{
const cases = [
['../evil.js', /\.\.|路径段/],
['/abs', /绝对路径/],
['images/../../x', /\.\.|路径段/],
['images\\a.jpg', /反斜杠/],
]
for (const [name, pattern] of cases) {
await expectReject(
() => A.zip([{ name, data: new Uint8Array([1]) }]),
pattern, 'zip 应拒绝 ' + name
)
await expectReject(
async () => A.unzip(await rawZip([[name, new Uint8Array([1])]])),
pattern, 'unzip 应拒绝 ' + name
)
}
}
// ── 4. 非法后缀 / 非白名单路径 / 中文文件名 ───────────────────────────
// 白名单只允许 ASCII 字母数字与 - _ . /,所以中文文件名也应被拒绝
// (中文可以出现在 data.json 的**内容**里,但不能出现在路径里)。
{
await expectReject(
() => A.zip([{ name: 'images/a.gif', data: new Uint8Array([1]) }]),
/后缀.*images\/a\.gif/, 'zip 应拒绝 .gif'
)
await expectReject(
async () => A.unzip(await rawZip([['images/a.gif', new Uint8Array([1])]])),
/后缀.*images\/a\.gif/, 'unzip 应拒绝 .gif'
)
for (const name of ['other/a.jpg', 'data.json.bak', 'images/nested/a.jpg', 'images/中文.jpg', 'images/a']) {
await expectReject(
() => A.zip([{ name, data: new Uint8Array([1]) }]),
/允许的|子目录|后缀|非法字符/, 'zip 应拒绝白名单外名字 ' + name
)
}
}
// ── 5. 重名条目:不能让后一个静默覆盖前一个 ───────────────────────────
// wOpenZipBlob 内部用普通对象存 files,重名会覆盖;所以 unzip 必须先用
// 中央目录预检。这条测试就是防止以后有人把预检"优化"掉。
{
await expectReject(
() => A.zip([
{ name: 'images/dup.jpg', data: new Uint8Array([1]) },
{ name: 'images/dup.jpg', data: new Uint8Array([2]) },
]),
/重名.*images\/dup\.jpg/, 'zip 应拒绝重名'
)
const dup = await rawZip([
['images/dup.jpg', new Uint8Array([1])],
['images/dup.jpg', new Uint8Array([2])],
])
await expectReject(() => A.unzip(dup), /重名.*images\/dup\.jpg/, 'unzip 应拒绝重名条目')
}
// ── 6. 条目数 > 500(打包与解包)──────────────────────────────────────
{
const tooMany = []
for (let i = 0; i < 501; i++) tooMany.push({ name: 'images/n' + i + '.jpg', data: new Uint8Array([1]) })
await expectReject(() => A.zip(tooMany), /500|文件数/, 'zip 应拒绝 501 个文件')
const tooManyRaw = []
for (let i = 0; i < 501; i++) tooManyRaw.push(['images/n' + i + '.jpg', new Uint8Array([1])])
await expectReject(
async () => A.unzip(await rawZip(tooManyRaw)),
/条目数.*500/, 'unzip 应拒绝 501 个条目'
)
}
// ── 7. 单文件 > 16MB:打包侧用真实长度;解包侧用伪造的声明长度 ─────────
{
const oversized = new Uint8Array(A.limits.maxFileBytes + 1)
await expectReject(
() => A.zip([{ name: 'images/big.jpg', data: oversized }]),
/16MB.*images\/big\.jpg/, 'zip 应拒绝 >16MB 的单文件'
)
const one = await rawZip([['images/a.jpg', new Uint8Array([1, 2, 3])]])
const fakeSingle = await patchCentralRawSize(one, A.limits.maxFileBytes + 1)
await expectReject(
async () => A.unzip(fakeSingle),
/16MB.*images\/a\.jpg/, 'unzip 应按声明大小拒绝 >16MB 的单条目(防 zip 炸弹)'
)
}
// ── 8. 总解压 > 64MB(声明值伪造,避免测试真的分配 64MB)─────────────
{
const five = []
for (let i = 0; i < 5; i++) five.push(['images/t' + i + '.jpg', new Uint8Array([1])])
const blob = await rawZip(five)
// 5 × 13MB = 65MB:每个都在 16MB 以内,只有总和超限 → 专门打总大小那条判断。
const fakeTotal = await patchCentralRawSize(blob, 13 * 1024 * 1024)
await expectReject(() => A.unzip(fakeTotal), /总大小.*64MB/, 'unzip 应拒绝解压后总大小 >64MB')
}
// ── 9. 合法目录条目被跳过;非法输入/类型要显式报错 ───────────────────
{
const withDir = await rawZip([
['images/', new Uint8Array(0)],
['images/a.png', new Uint8Array([7, 8])],
])
const out = await A.unzip(withDir)
eqJson(out.map((x) => x.name), ['images/a.png'], 'images/ 目录条目应被跳过,不计入文件')
eqBytes(out[0].data, new Uint8Array([7, 8]), '目录后的文件内容应正常读出')
await expectReject(() => A.zip('not-an-array'), /数组/, 'zip 应拒绝非数组输入')
await expectReject(
() => A.zip([{ name: 'data.json', data: 123 }]),
/Uint8Array 或 string/, 'zip 应拒绝非 Uint8Array/string 的内容'
)
await expectReject(() => A.unzip('not-a-blob'), /Blob/, 'unzip 应拒绝非 Blob 输入')
await expectReject(() => A.unzip(new Blob([new Uint8Array(32)])), /ZIP/, 'unzip 应拒绝非 ZIP 字节')
}
console.log('plugin archive checks passed(往返 + 路径穿越 + 白名单后缀 + 重名 + 条目数/单文件/总大小上限)')
// ⚠️ 显式退出:vm/Blob 可能让事件循环挂着(沿用 storage-zip-test 的处理)。
process.exit(0)
})().catch((e) => {
console.error('plugin archive checks FAILED:', e && e.message)
process.exit(1)
})
+34
View File
@@ -0,0 +1,34 @@
// 插件文件能力的安全策略(v3.26.36):文件名白名单 + 配额。
// 这两条是安全边界,破坏即等于允许路径穿越或塞满磁盘,必须由 CI 守住。
const assert = require('assert')
const path = require('path')
const sandbox = {}
new Function('window', require('fs').readFileSync(path.join(__dirname, '..', 'src', 'plugin-files-policy.js'), 'utf8'))(sandbox)
const P = sandbox.IWBPluginFilesPolicy
assert.ok(P && typeof P.fileOk === 'function', '应导出 fileOk')
// ---- 文件名白名单 ----
for (const ok of ['a.jpg', 'a1b2c3.jpg', 'cover_2026-11-22.png', 'x.webp', 'A.JPEG']) {
assert.strictEqual(P.fileOk(ok), true, '应允许:' + ok)
}
for (const bad of [
'', '.jpg', 'a.gif', 'a.txt', 'a.jpg/png', '../x.jpg', 'a/b.jpg', '../../etc/passwd',
'a' + String.fromCharCode(92) + 'b.jpg', 'a.jpg ', ' a.jpg', 'a.jpg' + String.fromCharCode(0),
'a'.repeat(80) + '.jpg', 'x.jpg?1', 'x.jpg#a', '图片.jpg',
]) {
assert.strictEqual(P.fileOk(bad), false, '应拒绝:' + JSON.stringify(bad))
}
// ---- 配额 ----
const L = P.LIMITS
assert.ok(L.FILE_MAX > 0 && L.TOTAL_MAX >= L.FILE_MAX)
assert.deepStrictEqual(P.quotaOk(0, 1024), { ok: true })
assert.strictEqual(P.quotaOk(0, 0).ok, false, '空文件应拒绝')
assert.strictEqual(P.quotaOk(0, L.FILE_MAX + 1).reason, 'file-too-large')
assert.strictEqual(P.quotaOk(L.TOTAL_MAX - 10, 1024).reason, 'total-too-large')
// 覆盖同名文件:旧大小不重复计
assert.strictEqual(P.quotaOk(L.TOTAL_MAX - 100, 1024, 4096).ok, true)
assert.strictEqual(P.quotaOk(L.TOTAL_MAX - 100, 1024, 0).ok, false)
console.log('plugin files policy checks passed(白名单/路径穿越/配额/覆盖计费)')
+1 -1
View File
@@ -13,7 +13,7 @@ vm.runInNewContext(source, sandbox)
const host0 = sandbox.IWBPluginHost
assert.ok(Number.isInteger(host0.apiVersion) && host0.apiVersion >= 1, 'apiVersion 必须是正整数')
assert.ok(Array.isArray(host0.capabilities) && host0.capabilities.length >= 7, '能力清单应非空')
assert.strictEqual(host0.capabilities.slice().sort().join(','), 'canvas,canvasWrite,commands,gallery,generationHooks,grouplib,nodeActions,nodeTypes,panels,promptlib,providers')
assert.strictEqual(host0.capabilities.slice().sort().join(','), 'canvas,canvasWrite,commands,files,gallery,generationHooks,grouplib,nodeActions,nodeTypes,panels,promptlib,providers')
const manifest = (over) => Object.assign({ id: 'demo-plugin', name: 'Demo', version: '1.0.0', apiVersion: 1, capabilities: [] }, over)
const stateOf = (ids) => {
+32 -15
View File
@@ -33,7 +33,7 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms))
{ id: 'q3', name: '未分组的一条', text: '没有分组的', tags: [], group: '' },
]
let groups = [{ id: '小红书', name: '小红书' }, { id: '收藏', name: '收藏' }]
const calls = { save: 0, insert: [], copy: [], notify: [] }
const calls = { save: 0, insert: [], copy: [], notify: [], create: [] }
let panel = null
const ctx = {
@@ -46,6 +46,13 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms))
notify: (t, ty) => { calls.notify.push([t, ty]) },
onChanged: () => () => {},
},
canvasWrite: {
createNode: (type, x, y, data) => { calls.create.push({ type, x, y, data }); return 'n1' },
},
canvas: {
screenToWorld: (x, y) => ({ x, y }),
},
}
registered.f(ctx)
assert.ok(panel && typeof panel.mount === 'function', '应注册面板')
@@ -84,26 +91,33 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms))
const back = host.querySelector('.iwb-chip-active')
assert.ok(back && back.textContent.indexOf('小红书') === 0, '「×」清空后应回到「小红书」,实际 ' + (back && back.textContent))
// 拖拽 payload
// v1.6.15:改为指针拖拽插入(与风格库一致),不再走 HTML5 dataTransfer
const canvasEl = window.document.createElement('div')
canvasEl.className = 'iwb-canvas'
window.document.body.appendChild(canvasEl)
canvasEl.getBoundingClientRect = () => ({ left: 0, top: 0, right: 800, bottom: 600, width: 800, height: 600 })
const card = cards()[0]
const store = {}
const dragEvt = new window.Event('dragstart', { bubbles: true })
dragEvt.dataTransfer = { setData: (k, v) => { store[k] = v }, effectAllowed: '' }
card.dispatchEvent(dragEvt)
assert.ok(store['application/x-iwb-promptid'], '拖拽应带提示词 id')
assert.strictEqual(JSON.parse(store['application/x-iwb-prompt']).text, '生成小红书封面图', '拖拽应带正文 payload')
card.dispatchEvent(new window.MouseEvent('pointerdown', { bubbles: true, clientX: 40, clientY: 40, button: 0 }))
window.dispatchEvent(new window.MouseEvent('pointermove', { bubbles: true, clientX: 70, clientY: 70 }))
window.dispatchEvent(new window.MouseEvent('pointermove', { bubbles: true, clientX: 300, clientY: 200 }))
assert.ok(window.document.querySelector('.iwb-plp-dragghost'), '拖动时应出现幽灵卡片')
window.dispatchEvent(new window.MouseEvent('pointerup', { bubbles: true, clientX: 300, clientY: 200 }))
await wait(20)
assert.strictEqual(calls.create.length, 1, '拖入画布应调用 createNode')
assert.strictEqual(calls.create[0].type, 'prompt', '无变量应插入普通提示词节点')
assert.strictEqual(calls.create[0].data.text, '生成小红书封面图', '插入应带正文')
// v1.1.0:单击卡片 → 详情(只读),再点「编辑」→ 浮层
card.dispatchEvent(new window.MouseEvent('click', { bubbles: true }))
// v1.6.12:双击卡片 → 详情(只读),再点「编辑」→ 浮层
card.dispatchEvent(new window.MouseEvent('dblclick', { bubbles: true }))
await wait(40)
const dlg = window.document.querySelector('.iwb-plp-dialog')
assert.ok(dlg && dlg.querySelector('.iwb-plp-dtext'), '单击卡片应打开详情弹窗(长文区)')
assert.ok(dlg && dlg.querySelector('.iwb-plp-dtext'), '双击卡片应打开详情弹窗(长文区)')
const editBtn = Array.from(dlg.querySelectorAll('.iwb-plp-dhead button')).find((b) => b.textContent === '编辑')
assert.ok(editBtn, '详情页应有「编辑」按钮')
editBtn.dispatchEvent(new window.MouseEvent('click', { bubbles: true }))
await wait(40)
const editor = window.document.querySelector('.iwb-plp-dialog-edit')
assert.ok(editor, '单击卡片应打开编辑浮层')
assert.ok(editor, '详情里点编辑应打开编辑浮层')
const nameIn = editor.querySelector('input.iwb-input')
nameIn.value = '小红书封面(改)'
const saveBtn = Array.from(editor.querySelectorAll('button')).find((b) => b.textContent === '保存')
@@ -114,9 +128,12 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms))
assert.strictEqual(prompts.find((p) => p.id === 'q3' || p.id === 'q1').name.length > 0, true)
assert.strictEqual(window.document.querySelector('.iwb-plp-dialog-edit'), null, '保存后编辑弹窗应关闭')
// v1.6.12:保存后自动回到详情(新行为)—— 关掉它,避免影响后续断言
window.document.querySelectorAll('.iwb-modal-mask').forEach((m) => m.remove())
// 插入画布按钮(+ 图标,title 含「插入到画布」)
// 再点一次卡片 → 详情弹窗 → 底部「插入画布」
cards()[0].dispatchEvent(new window.MouseEvent('click', { bubbles: true }))
cards()[0].dispatchEvent(new window.MouseEvent('dblclick', { bubbles: true }))
await wait(40)
const dlg2 = window.document.querySelector('.iwb-plp-dialog')
const insBtn = dlg2 ? Array.from(dlg2.querySelectorAll('.iwb-plp-dfooter button')).find((b) => b.textContent === '插入画布') : null
@@ -140,7 +157,7 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms))
// 2) 插入封面图片:详情底部出现「插入图片」,点击后调用 insertImage 并关闭弹窗
const inserted = []
ctx.promptlib.insertImage = async (cover, name) => { inserted.push([cover, name]); return { ok: true } }
window.document.querySelector('#host .iwb-plp-card').dispatchEvent(new window.MouseEvent('click', { bubbles: true }))
window.document.querySelector('#host .iwb-plp-card').dispatchEvent(new window.MouseEvent('dblclick', { bubbles: true }))
await wait(40)
const dlgA = window.document.querySelector('.iwb-plp-dialog')
const imgBtn = dlgA && Array.from(dlgA.querySelectorAll('.iwb-plp-dfooter button')).find((b) => b.textContent === '插入图片')
@@ -151,7 +168,7 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms))
assert.strictEqual(window.document.querySelector('.iwb-plp-dialog'), null, '插入图片后弹窗应关闭')
// 3) 弹窗拖动 + 缩放:标题栏拖动改变 left,右下角拖拽改变 width(且不小于 640)
window.document.querySelector('#host .iwb-plp-card').dispatchEvent(new window.MouseEvent('click', { bubbles: true }))
window.document.querySelector('#host .iwb-plp-card').dispatchEvent(new window.MouseEvent('dblclick', { bubbles: true }))
await wait(40)
const dlgB = window.document.querySelector('.iwb-plp-dialog')
assert.ok(dlgB, '应打开详情弹窗')